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
31 # find Koha's Perl modules
32 # test carefully before changing this
34 eval { require "$FindBin::Bin/kohalib.pl" };
44 open (FILE,'>/tmp/fines') || die;
46 # it looks like $count is just a counter, would it be
47 # better to rely on the length of the array @$data and turn the
48 # for loop below into a foreach loop?
51 my ($data)=Getoverdues();
52 print scalar(@$data) if $DEBUG;
53 my $overdueItemsCounted=0 if $DEBUG;
55 # FIXME - There's got to be a better way to figure out what day
57 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime(time);
61 my $date=Date_DaysSince1BC($mon,$mday,$year);
63 print $date if $DEBUG;
68 # $total isn't used anywhere else in the file,
73 # get the maxfine parameter
74 my $maxFine=C4::Context->preference("MaxFine") || 999999999;
77 # This should be rewritten to be a foreach loop
78 # Also, this loop is really long, and could be better grokked if broken
79 # into a number of smaller, separate functions
81 for (my $i=0;$i<scalar(@$data);$i++){
82 my @dates=split('-',$data->[$i]->{'date_due'});
83 my $date2=Date_DaysSince1BC($dates[1],$dates[2],$dates[0]);
84 my $due="$dates[2]/$dates[1]/$dates[0]";
85 my $borrower=BorType($data->[$i]->{'borrowernumber'});
87 $overdueItemsCounted++ if $DEBUG;
88 my $difference=$date-$date2;
89 my ($amount,$type,$printout)=
91 $borrower->{'categorycode'},
93 if ($amount > $maxFine){
97 UpdateFine($data->[$i]->{'itemnumber'},$data->[$i]->{'borrowernumber'},$amount,$type,$due);
98 if ($borrower->{'categorycode'} eq 'C'){ # FIXME
99 my $dbh = C4::Context->dbh;
100 my $sth=$dbh->prepare("Select * from borrowers where borrowernumber=?");
101 $sth->execute($borrower->{'guarantor'});
102 my $tdata=$sth->fetchrow_hashref;
104 $borrower->{'phone'}=$tdata->{'phone'};
106 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;
108 if ($difference >= C4::Context->preference("NoReturnSetLost")){
109 my $borrower=BorType($data->[$i]->{'borrowernumber'});
110 if ($borrower->{'cardnumber'} ne ''){
111 my $cost=ReplacementCost($data->[$i]->{'itemnumber'});
112 my $dbh = C4::Context->dbh;
113 my $accountno=C4::Accounts::getnextacctno($data->[$i]->{'borrowernumber'});
114 my $item=GetBiblioFromItemNumber($data->[$i]->{'itemnumber'});
115 if ($item->{'itemlost'} ne '1' && $item->{'itemlost'} ne '2' ){
116 # FIXME this should be a separate function
117 my $sth=$dbh->prepare("INSERT INTO accountlines
118 (borrowernumber,itemnumber,accountno,date,amount,
119 description,accounttype,amountoutstanding) VALUES
120 (?,?,?,now(),?,?,'L',?)");
121 $sth->execute($data->[$i]->{'borrowernumber'},$data->[$i]->{'itemnumber'},
122 $accountno,$cost,"Lost item $item->{'title'} $item->{'barcode'} $due",$cost);
124 ModItem({ itemlost => 2 }, undef, $data->[$i]->{'itemnumber'});
132 my $numOverdueItems=scalar(@$data);
135 Number of Overdue Items counted $overdueItemsCounted
136 Number of Overdue Items reported $numOverdueItems