[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Koha-cvs] koha C4/Circulation/Fines.pm misc/fines.pl [rel_3_0]
From: |
Bruno Toumi |
Subject: |
[Koha-cvs] koha C4/Circulation/Fines.pm misc/fines.pl [rel_3_0] |
Date: |
Mon, 09 Oct 2006 12:33:08 +0000 |
CVSROOT: /sources/koha
Module name: koha
Branch: rel_3_0
Changes by: Bruno Toumi <btoumi> 06/10/09 12:33:08
Modified files:
C4/Circulation : Fines.pm
Added files:
misc : fines.pl
Log message:
add new file fines.pl with new method to calcul the fines
add ,modify some functions in fines.pm
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Circulation/Fines.pm?cvsroot=koha&only_with_tag=rel_3_0&r1=1.14&r2=1.14.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/misc/fines.pl?cvsroot=koha&only_with_tag=rel_3_0&rev=1.1.2.1
Patches:
Index: C4/Circulation/Fines.pm
===================================================================
RCS file: /sources/koha/koha/C4/Circulation/Fines.pm,v
retrieving revision 1.14
retrieving revision 1.14.2.1
diff -u -b -r1.14 -r1.14.2.1
--- C4/Circulation/Fines.pm 12 Jul 2006 09:15:26 -0000 1.14
+++ C4/Circulation/Fines.pm 9 Oct 2006 12:33:07 -0000 1.14.2.1
@@ -1,6 +1,6 @@
package C4::Circulation::Fines;
-# $Id: Fines.pm,v 1.14 2006/07/12 09:15:26 rangi Exp $
+# $Id: Fines.pm,v 1.14.2.1 2006/10/09 12:33:07 btoumi Exp $
# Copyright 2000-2002 Katipo Communications
#
@@ -23,8 +23,10 @@
require Exporter;
use DBI;
use C4::Context;
+use Date::Manip qw/UnixDate/;
use vars qw($VERSION @ISA @EXPORT);
+
# set the version for version checking
$VERSION = 0.01;
@@ -48,8 +50,26 @@
=cut
@ISA = qw(Exporter);
address@hidden = qw(&Getoverdues &CalcFine &BorType &UpdateFine &ReplacementCost
- GetFine, ReplacementCost2);
address@hidden = qw( &BorType
+ &CalcFine
+ &Getoverdues
+ &GetIssuingRules
+ &CheckAccountLineLevelInfo
+ &CheckAccountLineItemInfo
+ &CheckExistantNotifyid
+ &GetIssuesIteminfo
+ &GetNextIdNotify
+ &GetMaxAccountno
+ &GetOverdueDelays
+ &GetFine
+ &GetItems
+ &GetNotifyId
+ &GetNextIdNotify
+ &UpdateAccountLines
+ &UpdateFine
+ &CreateItemAccountLine
+ &ReplacementCost
+ &ReplacementCost2);
=item Getoverdues
@@ -70,7 +90,7 @@
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare(
"Select * from issues where date_due < now() and returndate is
- NULL order by borrowernumber"
+ NULL order by borrowernumber "
);
$sth->execute;
@@ -138,82 +158,175 @@
#'
sub CalcFine {
- my ( $itemnumber, $bortype, $difference ) = @_;
+ my ( $itemnumber, $bortype, $difference , $dues ) = @_;
my $dbh = C4::Context->dbh;
+ my $data = GetIssuingRules($itemnumber,$bortype);
+ my $amount = 0;
+ my $printout;
+ my $countspecialday=&GetSpecialHolidays($dues,$itemnumber);
+ my
$countrepeatableday=&GetRepeatableHolidays($dues,$itemnumber,$difference);
+ my $countalldayclosed = $countspecialday + $countrepeatableday;
+ my $daycount = $difference - $countalldayclosed;
+ my $daycounttotal = $daycount - $data->{'firstremind'};
+ if ($data->{'firstremind'} < $daycount)
+ {
+ $amount = $daycounttotal*$data->{'fine'};
+ }
+ return ( $amount, $data->{'chargename'}, $printout ,$daycounttotal ,$daycount
);
+}
- # Look up the categoryitem record for this book's item type and the
- # given borrwer type.
- # The reason this query is so messy is that it's a messy question:
- # given the barcode, we can find the book's items record. This gives
- # us the biblioitems record, which gives us a set of categoryitem
- # records. Then we select the one that corresponds to the desired
- # borrower type.
-
- # FIXME - Is it really necessary to get absolutely everything from
- # all four tables? It looks as if this code only wants
- # firstremind, chargeperiod, accountsent, and chargename from the
- # categoryitem table.
- my $sth = $dbh->prepare(
-"SELECT * FROM items,biblioitems,itemtypes,issuingrules
- WHERE items.itemnumber=?
- AND items.biblioitemnumber=biblioitems.biblioitemnumber
- AND biblioitems.itemtype=itemtypes.itemtype
- AND issuingrules.itemtype=itemtypes.itemtype
- AND issuingrules.categorycode=? AND (items.itemlost <> 1 OR items.itemlost
is NULL)"
- );
+=item GetSpecialHolidays
- # print $query;
- $sth->execute( $itemnumber, $bortype );
- my $data = $sth->fetchrow_hashref;
+&GetSpecialHolidays($date_dues,$itemnumber);
+
+return number of special days between date of the day and date due
+
+C<$date_dues> is the envisaged date of book return.
+
+C<$itemnumber> is the book's item number.
+=cut
+
+sub GetSpecialHolidays{
+my ($date_dues,$itemnumber) = @_;
+# calcul the today date
+my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime(time);
+$mon++;
+$year=$year+1900;
+my $today=$year."-".$mon."-".$mday;
+$today=UnixDate($today, "%Y-%m-%d");
+# return the holdingbranch
+my $iteminfo=GetIssuesIteminfo($itemnumber);
+# use sql request to find all date between date_due and today
+my $dbh = C4::Context->dbh;
+my $query=qq|SELECT DATE_FORMAT(concat(year,'-',month,'-',day),'%Y-%m-%d')as
date
+FROM `special_holidays`
+WHERE DATE_FORMAT(concat(year,'-',month,'-',day),'%Y-%m-%d') >= ?
+AND DATE_FORMAT(concat(year,'-',month,'-',day),'%Y-%m-%d') <= ?
+AND branchcode=?
+|;
+my @result=GetWdayFromItemnumber($itemnumber);
+my @result_date;
+my $wday;
+my $dateinsec;
+my $sth = $dbh->prepare($query);
+$sth->execute($date_dues,$today,$iteminfo->{'branchcode'});
+
+while ( my $special_date=$sth->fetchrow_hashref){
+ push (@result_date,$special_date);
+}
+
+my $specialdaycount=scalar(@result_date);
+
+ for (my $i=0;$i<scalar(@result_date);$i++){
+ $dateinsec=UnixDate($result_date[$i]->{'date'},"%o");
+ (undef,undef,undef,undef,undef,undef,$wday,undef,undef)
=localtime($dateinsec);
+ for (my $j=0;$j<scalar(@result);$j++){
+ if ($wday == ($result[$j]->{'weekday'})){
+ $specialdaycount --;
+ }
+ }
+ }
+
+return $specialdaycount;
+}
- # FIXME - Error-checking: the item might be lost, or there
- # might not be an entry in 'categoryitem' for this item type
- # or borrower type.
- $sth->finish;
- my $amount = 0;
- my $printout;
- # Is it time to send out the first reminder?
- # FIXME - I'm not sure the "=="s are correct here. Let's say that
- # $data->{firstremind} is today, but 'fines2.pl' doesn't run for
- # some reason (the cron daemon died, the server crashed, the
- # sysadmin had the machine down for maintenance, or whatever).
- #
- # Then the next day, the book is $data->{firstremind}+1 days
- # overdue. But this function returns $amount == 0, $printout ==
- # undef, on the assumption that 'fines2.pl' ran the previous day. So
- # the first thing the patron gets is a second notice, but that's a
- # week after the server crash, so people may not connect the two
- # events.
- if ( $difference == $data->{'firstremind'} ) {
-
- # Yes. Set the fine as listed.
- $amount = $data->{'fine'};
- $printout = "First Notice";
- }
-
- # Is it time to send out a second reminder?
- my $second = $data->{'firstremind'} + $data->{'chargeperiod'};
- if ( $difference == $second ) {
-
- # Yes. The fine is double.
- $amount = $data->{'fine'} * 2;
- $printout = "Second Notice";
- }
-
- # Is it time to send the account to a collection agency?
- # FIXME - At least, I *think* that's what this code is doing.
- if ( $difference == $data->{'accountsent'} && $data->{'fine'} > 0 ) {
-
- # Yes. Set the fine at 5 local monetary units.
- # FIXME - This '5' shouldn't be hard-wired.
- $amount = 5;
- $printout = "Final Notice";
+
+
+
+=item GetRepeatableHolidays
+
+&GetRepeatableHolidays($date_dues, $itemnumber, $difference,);
+
+return number of day closed between date of the day and date due
+
+C<$date_dues> is the envisaged date of book return.
+
+C<$itemnumber> is item number.
+
+C<$difference> numbers of between day date of the day and date due
+
+=cut
+
+sub GetRepeatableHolidays{
+my ($date_dues,$itemnumber,$difference) = @_;
+my $dateinsec=UnixDate($date_dues,"%o");
+my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
=localtime($dateinsec);
+my @result=GetWdayFromItemnumber($itemnumber);
+my @dayclosedcount;
+my $j;
+
+for (my $i=0;$i<scalar(@result);$i++){
+ my $k=$wday;
+
+ for ( $j=0;$j<$difference;$j++){
+ if ($result[$i]->{'weekday'} == $k)
+ {
+ push ( @dayclosedcount ,$k);
+ }
+ $k++;
+ ($k=0) if($k eq 7);
}
- return ( $amount, $data->{'chargename'}, $printout );
+ }
+return scalar(@dayclosedcount);
+}
+
+
+=item GetWayFromItemnumber
+
+&Getwdayfromitemnumber($itemnumber);
+
+return the different week day from repeatable_holidays table
+
+C<$itemnumber> is item number.
+
+=cut
+
+sub GetWdayFromItemnumber{
+my($itemnumber)address@hidden;
+my $iteminfo=GetIssuesIteminfo($itemnumber);
+my @result;
+my $dbh = C4::Context->dbh;
+my $query = qq|SELECT weekday
+ FROM repeatable_holidays
+ WHERE branchcode=?
+|;
+my $sth = $dbh->prepare($query);
+ # print $query;
+my @result;
+$sth->execute($iteminfo->{'branchcode'});
+while ( my $weekday=$sth->fetchrow_hashref){
+ push (@result,$weekday);
+ }
+return @result;
+}
+
+
+=item GetIssuesIteminfo
+
+&GetIssuesIteminfo($itemnumber);
+
+return all data from issues about item
+
+C<$itemnumber> is item number.
+
+=cut
+
+sub GetIssuesIteminfo{
+my($itemnumber)address@hidden;
+my $dbh = C4::Context->dbh;
+my $query = qq|SELECT *
+ FROM issues
+ WHERE itemnumber=?
+|;
+my $sth = $dbh->prepare($query);
+$sth->execute($itemnumber);
+my ($issuesinfo)=$sth->fetchrow_hashref;
+return $issuesinfo;
}
+
=item UpdateFine
&UpdateFine($itemnumber, $borrowernumber, $amount, $type, $description);
@@ -299,14 +412,16 @@
my $title = $sth4->fetchrow_hashref;
$sth4->finish;
- # print "not in account";
- my $sth3 = $dbh->prepare("Select max(accountno) from accountlines");
- $sth3->execute;
-
- # FIXME - Make $accountno a scalar.
- my @accountno = $sth3->fetchrow_array;
- $sth3->finish;
- $accountno[0]++;
+# # print "not in account";
+# my $sth3 = $dbh->prepare("Select max(accountno) from accountlines");
+# $sth3->execute;
+#
+# # FIXME - Make $accountno a scalar.
+# my @accountno = $sth3->fetchrow_array;
+# $sth3->finish;
+# $accountno[0]++;
+ my $accountno=GetMaxAccountno();
+ $accountno++;
my $sth2 = $dbh->prepare(
"Insert into accountlines
(borrowernumber,itemnumber,date,amount,
@@ -315,7 +430,7 @@
);
$sth2->execute( $bornum, $itemnum, $amount,
"$type $title->{'title'} $due",
- $amount, $accountno[0] );
+ $amount, $accountno );
$sth2->finish;
}
$sth->finish;
@@ -371,6 +486,19 @@
return ( $data->{'replacementprice'} );
}
+=item GetFine
+
+$data->{'sum(amountoutstanding)'} = &GetFine($itemnum,$bornum);
+
+return the total of fine
+
+C<$itemnum> is item number
+
+C<$bornum> is the borrowernumber
+
+=cut
+
+
sub GetFine {
my ( $itemnum, $bornum ) = @_;
my $dbh = C4::Context->dbh();
@@ -385,12 +513,76 @@
return ( $data->{'sum(amountoutstanding)'} );
}
+
+
+
+=item GetIssuingRules
+
+$data = &GetIssuingRules($itemnumber,$categorycode);
+
+Looks up for all issuingrules an item info
+
+C<$itemnumber> is a reference-to-hash whose keys are all of the fields
+from the borrowers and categories tables of the Koha database. Thus,
+
+C<$categorycode> contains information about borrowers category
+
+C<$data> contains all information about both the borrower and
+category he or she belongs to.
+=cut
+
+sub GetIssuingRules {
+ my ($itemnumber,$categorycode)address@hidden;
+ my $dbh = C4::Context->dbh();
+ my $query=qq|SELECT *
+ FROM items,biblioitems,itemtypes,issuingrules
+ WHERE items.itemnumber=?
+ AND items.biblioitemnumber=biblioitems.biblioitemnumber
+ AND biblioitems.itemtype=itemtypes.itemtype
+ AND issuingrules.itemtype=itemtypes.itemtype
+ AND issuingrules.categorycode=?
+ AND (items.itemlost <> 1
+ OR items.itemlost is NULL)|;
+ my $sth = $dbh->prepare($query);
+ # print $query;
+ $sth->execute($itemnumber,$categorycode);
+ my ($data) = $sth->fetchrow_hashref;
+ $sth->finish;
+return ($data);
+
+}
+
+=item GetMaxAccountno
+
+ $accountno = &GetMaxAccountno();
+
+Looks up for Next Account number.
+
+=cut
+
+#'
+sub GetMaxAccountno {
+ my $dbh = C4::Context->dbh;
+ my $query=qq|SELECT max(accountno)
+ FROM accountlines|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute();
+ my $accountnomax = $sth->fetchrow_array;
+ $sth->finish;
+ return ($accountnomax);
+}
+
+
+
sub ReplacementCost2 {
my ( $itemnum, $bornum ) = @_;
my $dbh = C4::Context->dbh();
- my $query = "SELECT amountoutstanding FROM accountlines
- where accounttype like 'L' AND amountoutstanding > 0 AND
- itemnumber = ? AND borrowernumber= ?";
+ my $query = "SELECT amountoutstanding
+ FROM accountlines
+ WHERE accounttype like 'L'
+ AND amountoutstanding > 0
+ AND itemnumber = ?
+ AND borrowernumber= ?";
my $sth = $dbh->prepare($query);
$sth->execute( $itemnum, $bornum );
my $data = $sth->fetchrow_hashref();
@@ -398,6 +590,339 @@
$dbh->disconnect();
return ( $data->{'amountoutstanding'} );
}
+
+
+=item GetNextIdNotify
+
+($result) = &GetNextIdNotify($reference);
+
+Returns the new file number
+
+C<$result> contains the next file number
+
+C<$reference> contains the beggining of file number
+
+=cut
+
+
+
+sub GetNextIdNotify {
+my ($reference)address@hidden;
+my $query=qq|SELECT max(notify_id)
+ FROM accountlines
+ WHERE notify_id like \"$reference%\"
+ |;
+# AND borrowernumber=?|;
+my $dbh = C4::Context->dbh;
+my $sth=$dbh->prepare($query);
+$sth->execute();
+my $result=$sth->fetchrow;
+$sth->finish;
+my $count;
+ if ($result eq '')
+ {
+ ($result=$reference."01") ;
+ }else
+ {
+ $count=substr($result,6)+1;
+
+ if($count<10){
+ ($count = "0".$count);
+ }
+ $result=$reference.$count;
+ }
+return $result;
+}
+
+
+
+
+
+
+=item GetNotifyId
+
+($notify_id) = &GetNotifyId($borrowernumber,$itemnumber);
+
+Returns the file number per borrower and itemnumber
+
+C<$borrowernumber> is a reference-to-hash whose keys are all of the fields
+from the items tables of the Koha database. Thus,
+
+C<$itemnumber> contains the borrower categorycode
+
+C<$notify_id> contains the file number for the borrower number nad item number
+
+=cut
+ sub GetNotifyId {
+ my ($borrowernumber,$itemnumber)address@hidden;
+ my $query=qq|SELECT notify_id
+ FROM accountlines
+ WHERE borrowernumber=?
+ AND itemnumber=?
+ AND (accounttype='FU' or accounttype='O')|;
+ my $dbh = C4::Context->dbh;
+ my $sth=$dbh->prepare($query);
+ $sth->execute($borrowernumber,$itemnumber);
+ my ($notify_id)=$sth->fetchrow;
+ $sth->finish;
+ return ($notify_id);
+
+ }
+
+=item CreateItemAccountLine
+
+() =
&CreateItemAccountLine($borrowernumber,$itemnumber,$date,$amount,$description,$accounttype,$amountoutstanding,$timestamp,$notify_id,$level);
+
+update the account lines with file number or with file level
+
+C<$items> is a reference-to-hash whose keys are all of the fields
+from the items tables of the Koha database. Thus,
+
+C<$itemnumber> contains the item number
+
+C<$borrowernumber> contains the borrower number
+
+C<$date> contains the date of the day
+
+C<$amount> contains item price
+
+C<$description> contains the descritpion of accounttype
+
+C<$accounttype> contains the account type
+
+C<$amountoutstanding> contains the $amountoutstanding
+
+C<$timestamp> contains the timestamp with time and the date of the day
+
+C<$notify_id> contains the file number
+
+C<$level> contains the file level
+
+
+=cut
+
+ sub CreateItemAccountLine {
+ my
($borrowernumber,$itemnumber,$date,$amount,$description,$accounttype,$amountoutstanding,$timestamp,$notify_id,$level)address@hidden;
+ my $accountno=GetMaxAccountno();
+ $accountno++;
+
+ my $query= qq|INSERT into accountlines
+
(borrowernumber,accountno,itemnumber,date,amount,description,accounttype,amountoutstanding,timestamp,notify_id,notify_level)
+ VALUES
+ (?,?,?,?,?,?,?,?,?,?,?)|;
+ my $dbh = C4::Context->dbh;
+ my $sth=$dbh->prepare($query);
+
$sth->execute($borrowernumber,$accountno,$itemnumber,$date,$amount,$description,$accounttype,$amountoutstanding,$timestamp,$notify_id,$level);
+ $sth->finish;
+ }
+
+=item UpdateAccountLines
+
+() = &UpdateAccountLines($notify_id,$notify_level,$borrowernumber,$itemnumber);
+
+update the account lines with file number or with file level
+
+C<$items> is a reference-to-hash whose keys are all of the fields
+from the items tables of the Koha database. Thus,
+
+C<$itemnumber> contains the item number
+
+C<$notify_id> contains the file number
+
+C<$notify_level> contains the file level
+
+C<$borrowernumber> contains the borrowernumber
+
+=cut
+sub UpdateAccountLines {
+my ($notify_id,$notify_level,$borrowernumber,$itemnumber)address@hidden;
+my $query;
+if ($notify_id eq '')
+{
+
+ $query=qq|UPDATE accountlines
+ SET notify_level=?
+ WHERE borrowernumber=? AND itemnumber=?
+ AND (accounttype='FU' or accounttype='O')|;
+}else
+{
+ $query=qq|UPDATE accountlines
+ SET notify_id=?, notify_level=?
+ WHERE borrowernumber=?
+ AND itemnumber=?
+ AND (accounttype='FU' or accounttype='O')|;
+}
+ my $dbh = C4::Context->dbh;
+ my $sth=$dbh->prepare($query);
+
+if ($notify_id eq '')
+{
+ $sth->execute($notify_level,$borrowernumber,$itemnumber);
+}else
+{
+ $sth->execute($notify_id,$notify_level,$borrowernumber,$itemnumber);
+}
+ $sth->finish;
+
+}
+
+
+=item GetItems
+
+($items) = &GetItems($itemnumber);
+
+Returns the list of all delays from overduerules.
+
+C<$items> is a reference-to-hash whose keys are all of the fields
+from the items tables of the Koha database. Thus,
+
+C<$itemnumber> contains the borrower categorycode
+
+=cut
+
+sub GetItems {
+ my($itemnumber) = @_;
+ my $query=qq|SELECT *
+ FROM items
+ WHERE itemnumber=?|;
+ my $dbh = C4::Context->dbh;
+ my $sth=$dbh->prepare($query);
+ $sth->execute($itemnumber);
+ my ($items)=$sth->fetchrow_hashref;
+ $sth->finish;
+ return($items);
+}
+
+=item GetOverdueDelays
+
+(@delays) = &GetOverdueDelays($categorycode);
+
+Returns the list of all delays from overduerules.
+
+C<@delays> it's an array contains the three delays from overduerules table
+
+C<$categorycode> contains the borrower categorycode
+
+=cut
+
+sub GetOverdueDelays {
+ my($category) = @_;
+ my $dbh = C4::Context->dbh;
+ my $query=qq|SELECT delay1,delay2,delay3
+ FROM overduerules
+ WHERE categorycode=?|;
+ my $sth=$dbh->prepare($query);
+ $sth->execute($category);
+ my (@delays)=$sth->fetchrow_array;
+ $sth->finish;
+ return(@delays);
+}
+
+=item CheckAccountLineLevelInfo
+
+($exist) =
&CheckAccountLineLevelInfo($borrowernumber,$itemnumber,$accounttype,notify_level);
+
+Check and Returns the list of all overdue books.
+
+C<$exist> contains number of line in accounlines
+with the same .biblionumber,itemnumber,accounttype,and notify_level
+
+C<$borrowernumber> contains the borrower number
+
+C<$itemnumber> contains item number
+
+C<$accounttype> contains account type
+
+C<$notify_level> contains the accountline level
+
+
+=cut
+
+sub CheckAccountLineLevelInfo {
+ my($borrowernumber,$itemnumber,$level) = @_;
+ my $dbh = C4::Context->dbh;
+ my $query= qq|SELECT count(*)
+ FROM accountlines
+ WHERE borrowernumber =?
+ AND itemnumber = ?
+ AND notify_level=?|;
+ my $sth=$dbh->prepare($query);
+ $sth->execute($borrowernumber,$itemnumber,$level);
+ my ($exist)=$sth->fetchrow;
+ $sth->finish;
+ return($exist);
+}
+
+=item CheckExistantNotifyid
+
+ ($exist) =
&CheckExistantNotifyid($borrowernumber,$itemnumber,$accounttype,$notify_id);
+
+Check and Returns the notify id if exist else return 0.
+
+C<$exist> contains a notify_id
+
+C<$borrowernumber> contains the borrower number
+
+C<$date_due> contains the date of item return
+
+
+=cut
+
+sub CheckExistantNotifyid {
+ my($borrowernumber,$date_due) = @_;
+ my $dbh = C4::Context->dbh;
+ my $query = qq|SELECT notify_id FROM issues,accountlines
+ WHERE accountlines.borrowernumber =?
+ AND issues.itemnumber= accountlines.itemnumber
+ AND date_due = ?|;
+ my $sth=$dbh->prepare($query);
+ $sth->execute($borrowernumber,$date_due);
+ my ($exist)=$sth->fetchrow;
+ $sth->finish;
+ if ($exist eq '')
+ {
+ return(0);
+ }else
+ {
+ return($exist);
+ }
+}
+
+=item CheckAccountLineItemInfo
+
+ ($exist) =
&CheckAccountLineItemInfo($borrowernumber,$itemnumber,$accounttype,$notify_id);
+
+Check and Returns the list of all overdue items from the same file
number(notify_id).
+
+C<$exist> contains number of line in accounlines
+with the same .biblionumber,itemnumber,accounttype,notify_id
+
+C<$borrowernumber> contains the borrower number
+
+C<$itemnumber> contains item number
+
+C<$accounttype> contains account type
+
+C<$notify_id> contains the file number
+
+
+=cut
+sub CheckAccountLineItemInfo {
+ my($borrowernumber,$itemnumber,$accounttype,$notify_id) = @_;
+ my $dbh = C4::Context->dbh;
+ my $query = qq|SELECT count(*) FROM accountlines
+ WHERE borrowernumber =?
+ AND itemnumber = ?
+ AND accounttype= ?
+ AND notify_id = ?|;
+ my $sth=$dbh->prepare($query);
+ $sth->execute($borrowernumber,$itemnumber,$accounttype,$notify_id);
+ my ($exist)=$sth->fetchrow;
+ $sth->finish;
+ return($exist);
+ }
+
+
1;
__END__
Index: misc/fines.pl
===================================================================
RCS file: misc/fines.pl
diff -N misc/fines.pl
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ misc/fines.pl 9 Oct 2006 12:33:08 -0000 1.1.2.1
@@ -0,0 +1,166 @@
+#!/usr/bin/perl
+
+# This script loops through each overdue item, determines the fine,
+# and updates the total amount of fines due by each user. It relies on
+# the existence of /tmp/fines, which is created by ???
+# Doesnt really rely on it, it relys on being able to write to /tmp/
+# It creates the fines file
+#
+# This script is meant to be run nightly out of cron.
+
+# Copyright 2000-2002 Katipo Communications
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+
+# $Id: fines.pl,v 1.1.2.1 2006/10/09 12:33:08 btoumi Exp $
+
+use C4::Context;
+use C4::Search;
+use C4::Circulation::Circ2;
+use C4::Circulation::Fines;
+use Date::Manip qw/Date_DaysSince1BC/;
+use C4::Biblio;
+
+open (FILE,'>/tmp/fines') || die;
+# FIXME
+# it looks like $count is just a counter, would it be
+# better to rely on the length of the array @$data and turn the
+# for loop below into a foreach loop?
+#
+my ($numOverdueItems,$data)=Getoverdues();
+print $numOverdueItems if $DEBUG;
+my $overdueItemsCounted=0 if $DEBUG;
+# FIXME - There's got to be a better way to figure out what day
+# today is.
+my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime(time);
+$mon++;
+$year=$year+1900;
+my $date=Date_DaysSince1BC($mon,$mday,$year);
+print $date if $DEBUG;
+if ($mon < '10' ){
+$mon="0".$mon;
+}
+if ($mday < '10' ){
+$mday="0".$mday;
+}
+my $reference = $year."".$mon;
+my $bornum;
+
+for (my $i=0;$i<$numOverdueItems;$i++){
+ my @dates=split('-',$data->[$i]->{'date_due'});
+ my $date2=Date_DaysSince1BC($dates[1],$dates[2],$dates[0]);
+ my $datedue=$data->[$i]->{'date_due'};
+ my $due="$dates[2]/$dates[1]/$dates[0]";
+ my $borrower=BorType($data->[$i]->{'borrowernumber'});
+ my $starter;
+
+ if ($date2 <= $date){
+ $overdueItemsCounted++ if $DEBUG;
+ my $difference=$date-$date2;
+ my ($amount,$type,$printout,$daycounttotal,$daycount)=
+ CalcFine($data->[$i]->{'itemnumber'},
+ $borrower->{'categorycode'},
+ $difference,
+ $datedue);
+ my
($delays1,$delays2,$delays3)=GetOverdueDelays($borrower->{'categorycode'});
+ my
$issuingrules=GetIssuingRules($data->[$i]->{'itemnumber'},$borrower->{'categorycode'});
+ ;
+
+ if (borrowers->{'category_type'} ne 'I'){
+ #DELAYS 1##########################################
+ if ($amount > 0 && $daycount >= $delays1 && $daycount < $delays2){
+
UpdateFine($data->[$i]->{'itemnumber'},$data->[$i]->{'borrowernumber'},$amount,$type,$due);
+ my
$getnotifyid=CheckExistantNotifyid($borrower->{'borrowernumber'},$datedue);
+ my
$update=CheckAccountLineLevelInfo($borrower->{'borrowernumber'},$data->[$i]->{'itemnumber'},1);
+ if ($update eq '0'){
+ if ($getnotifyid eq '0'){
+
$starter=GetNextIdNotify($reference,$borrower->{'borrowernumber'});
+
+ }
+ else{
+ $starter=$getnotifyid;
+ }
+
+ }
+
UpdateAccountLines($starter,1,$borrower->{'borrowernumber'},$data->[$i]->{'itemnumber'});
+ }
+ ###############################################
+
+ if ($daycount>=$delays2) {
+ $amount=$issuingrules->{'fine'} * ($delays2);
+
UpdateFine($data->[$i]->{'itemnumber'},$data->[$i]->{'borrowernumber'},$amount,$type,$due);
+
+ }
+
+ #DELAYS 2#################################
+
+ if ($daycount >= $delays2 && $daycount <= $delays3){
+ my
$update=CheckAccountLineLevelInfo($borrower->{'borrowernumber'},$data->[$i]->{'itemnumber'},2);
+ if ($update eq '0'){
+
UpdateAccountLines(undef,2,$borrower->{'borrowernumber'},$data->[$i]->{'itemnumber'});
+ }
+ }
+ ###############################################
+
+ #DELAYS 3###################################
+ if ($daycount >= $delays3){
+ my
$update=CheckAccountLineLevelInfo($borrower->{'borrowernumber'},$data->[$i]->{'itemnumber'},3);
+ if ($update eq '0'){
+
UpdateAccountLines(undef,3,$borrower->{'borrowernumber'},$data->[$i]->{'itemnumber'});
+ }
+ my $items=GetItems($data->[$i]->{'itemnumber'});
+ my $todaydate=$year."-".$mon."-".$mday;
+ my $description="Item Price";
+ my $typeaccount="IP";
+ my $level="3";
+ my
$notifyid=GetNotifyId($borrower->{'borrowernumber'},$data->[$i]->{'itemnumber'});
+ my $timestamp=$todaydate." ".$hour."\:".$min."\:".$sec;
+ my
$create=CheckAccountLineItemInfo($borrower->{'borrowernumber'},$data->[$i]->{'itemnumber'},$typeaccount,$notifyid);
+ if ($create eq '0'){
+
CreateItemAccountLine($borrower->{'borrowernumber'},$data->[$i]->{'itemnumber'},$todaydate,$items->{'price'},$description,$typeaccount,
+ $items->{'price'},$timestamp,$notifyid,$level);
+ }
+ }
+ ###############################################
+ }
+
+
+
+if ($borrower->{'category_type'} eq 'C'){
+ my $query=qq| SELECT *
+ FROM borrowers
+ WHERE borrowernumber=?|;
+ my $dbh = C4::Context->dbh;
+ my $sth=$dbh->prepare($query);
+ $sth->execute($borrower->{'guarantorid'});
+ my $tdata=$sth->fetchrow_hashref;
+ $sth->finish;
+ $borrower->{'phone'}=$tdata->{'phone'};
+ }
+ print
"$printout\t$borrower->{'cardnumber'}\t$borrower->{'category_type'}\t$borrower->{'firstname'}\t$borrower->{'surname'}\t$data->[$i]->{'date_due'}\t$type\t$difference\t$borrower->{'email'}\t$borrower->{'phone'}\t$borrower->{'address'}\t$borrower->{'city'}\t$amount\n";
+ }
+}
+
+if ($DEBUG) {
+ print <<EOM
+
+Number of Overdue Items counted $overdueItemsCounted
+Number of Overdue Items reported $numOverdueItems
+
+EOM
+}
+
+close FILE;
- [Koha-cvs] koha C4/Circulation/Fines.pm misc/fines.pl [rel_3_0],
Bruno Toumi <=