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" };
40 use Date::Calc qw/Date_to_Days/;
46 my $libname=C4::Context->preference('LibraryName');
47 my $dbname= C4::Context->config('database');
49 my $today = C4::Dates->new();
50 my $datestr = $today->output('iso');
51 my $today_days= Date_to_Days(split(/-/,$today->output('iso')));
52 my $filename= $dbname;
54 $filename = $fldir . '/'. $filename . $datestr . ".log";
55 open (FILE,">$filename") || die "Can't open LOG";
56 print FILE "cardnumber\tcategory\tsurname\tfirstname\temail\tphone\taddress\tcitystate\tbarcode\tdate_due\ttype\titemnumber\tdays_overdue\tfine\n";
61 my $data=Getoverdues();
62 my $overdueItemsCounted=0 ;
65 for (my $i=0;$i<scalar(@$data);$i++){
66 my $datedue=C4::Dates->new($data->[$i]->{'date_due'},'iso');
67 my $datedue_days = Date_to_Days(split(/-/,$datedue->output('iso')));
68 my $due_str=$datedue->output();
69 my $borrower=BorType($data->[$i]->{'borrowernumber'});
71 if ( C4::Context->preference('CircControl') eq 'ItemHomeLibrary' ) {
72 $branchcode = $data->[$i]->{'homebranch'};
73 } elsif ( C4::Context->preference('CircControl') eq 'PatronLibrary' ) {
74 $branchcode = $borrower->{'branchcode'};
76 # CircControl must be PickupLibrary. (branchcode comes from issues table here).
77 $branchcode = $data->[$i]->{'branchcode'};
79 my $calendar = C4::Calendar->new( branchcode => $branchcode );
81 my $isHoliday = $calendar->isHoliday( split( '/', C4::Dates->new()->output('metric') ) );
83 if ($datedue_days <= $today_days){
84 $overdueItemsCounted++ if $DEBUG;
85 my $difference=$today_days - $datedue_days;
86 my ($amount,$type,$printout,$daycounttotal,$daycount)=
87 CalcFine($data->[$i], $borrower->{'categorycode'}, $branchcode,undef,undef, $datedue ,$today);
88 my ($delays1,$delays2,$delays3)=GetOverdueDelays($borrower->{'categorycode'});
90 # Don't update the fine if today is a holiday.
91 # This ensures that dropbox mode will remove the correct amount of fine.
92 if( (C4::Context->preference('finesMode') eq 'production') && ! $isHoliday ) {
93 # FIXME - $type is always null, afaict.
94 UpdateFine($data->[$i]->{'itemnumber'},$data->[$i]->{'borrowernumber'},$amount,$type,$due_str) if( $amount > 0 ) ;
96 print FILE "$printout\t$borrower->{'cardnumber'}\t$borrower->{'categorycode'}\t$borrower->{'surname'}\t$borrower->{'firstname'}\t$borrower->{'email'}\t$borrower->{'phone'}\t$borrower->{'address'}\t$borrower->{'city'}\t$data->[$i]->{'barcode'}\t$data->[$i]->{'date_due'}\t$type\t$data->[$i]->{'itemnumber'}\t$daycounttotal\t$amount\n";
100 my $numOverdueItems=scalar(@$data);
104 Number of Overdue Items counted $overdueItemsCounted
105 Number of Overdue Items reported $numOverdueItems