3 # This script loops through each overdue item, determines the fine,
4 # and updates the total amount of fines due by each user. It relies on
5 # the existence of /tmp/fines, which is created by ???
6 # Doesnt really rely on it, it relys on being able to write to /tmp/
7 # It creates the fines file
9 # This script is meant to be run nightly out of cron.
11 # Copyright 2000-2002 Katipo Communications
13 # This file is part of Koha.
15 # Koha is free software; you can redistribute it and/or modify it under the
16 # terms of the GNU General Public License as published by the Free Software
17 # Foundation; either version 2 of the License, or (at your option) any later
20 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
21 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
22 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License along with
25 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
26 # Suite 330, Boston, MA 02111-1307 USA
36 open (FILE,'>/tmp/fines') || die;
38 # it looks like $count is just a counter, would it be
39 # better to rely on the length of the array @$data and turn the
40 # for loop below into a foreach loop?
43 my ($data)=Getoverdues();
44 print scalar(@$data) if $DEBUG;
45 my $overdueItemsCounted=0 if $DEBUG;
47 # FIXME - There's got to be a better way to figure out what day
49 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime(time);
53 my $date=Date_DaysSince1BC($mon,$mday,$year);
55 print $date if $DEBUG;
60 # $total isn't used anywhere else in the file,
65 # get the maxfine parameter
66 my $maxFine=C4::Context->preference("MaxFine") || 999999999;
69 # This should be rewritten to be a foreach loop
70 # Also, this loop is really long, and could be better grokked if broken
71 # into a number of smaller, separate functions
73 for (my $i=0;$i<scalar(@$data);$i++){
74 my @dates=split('-',$data->[$i]->{'date_due'});
75 my $date2=Date_DaysSince1BC($dates[1],$dates[2],$dates[0]);
76 my $due="$dates[2]/$dates[1]/$dates[0]";
77 my $borrower=BorType($data->[$i]->{'borrowernumber'});
79 $overdueItemsCounted++ if $DEBUG;
80 my $difference=$date-$date2;
81 my ($amount,$type,$printout)=
83 $borrower->{'categorycode'},
85 if ($amount > $maxFine){
89 UpdateFine($data->[$i]->{'itemnumber'},$data->[$i]->{'borrowernumber'},$amount,$type,$due);
90 if ($borrower->{'categorycode'} eq 'C'){ # FIXME
91 my $dbh = C4::Context->dbh;
92 my $sth=$dbh->prepare("Select * from borrowers where borrowernumber=?");
93 $sth->execute($borrower->{'guarantor'});
94 my $tdata=$sth->fetchrow_hashref;
96 $borrower->{'phone'}=$tdata->{'phone'};
98 print "$printout\t$borrower->{'cardnumber'}\t$borrower->{'categorycode'}\t$borrower->{'firstname'}\t$borrower->{'surname'}\t$data->[$i]->{'date_due'}\t$type\t$difference\t$borrower->{'emailaddress'}\t$borrower->{'phone'}\t$borrower->{'streetaddress'}\t$borrower->{'city'}\t$amount\n" if $DEBUG;
100 if ($difference >= C4::Context->preference("NoReturnSetLost")){
101 my $borrower=BorType($data->[$i]->{'borrowernumber'});
102 if ($borrower->{'cardnumber'} ne ''){
103 my $cost=ReplacementCost($data->[$i]->{'itemnumber'});
104 my $dbh = C4::Context->dbh;
105 my $accountno=C4::Accounts::getnextacctno($data->[$i]->{'borrowernumber'});
106 my $item=GetBiblioFromItemNumber($data->[$i]->{'itemnumber'});
107 if ($item->{'itemlost'} ne '1' && $item->{'itemlost'} ne '2' ){
108 # FIXME this should be a separate function
109 my $sth=$dbh->prepare("INSERT INTO accountlines
110 (borrowernumber,itemnumber,accountno,date,amount,
111 description,accounttype,amountoutstanding) VALUES
112 (?,?,?,now(),?,?,'L',?)");
113 $sth->execute($data->[$i]->{'borrowernumber'},$data->[$i]->{'itemnumber'},
114 $accountno,$cost,"Lost item $item->{'title'} $item->{'barcode'} $due",$cost);
116 $sth=$dbh->prepare("UPDATE items SET itemlost=2 WHERE itemnumber=?");
117 $sth->execute($data->[$i]->{'itemnumber'});
126 my $numOverdueItems=scalar(@$data);
129 Number of Overdue Items counted $overdueItemsCounted
130 Number of Overdue Items reported $numOverdueItems