Continuing work on Z39.50 search tool. Daemon now forks up to 12 processes
[koha.git] / fines.pl
1 #!/usr/bin/perl
2
3 #script to calculate fines
4
5
6 use C4::Circulation::Fines;
7 use Date::Manip;
8
9 open (FILE,'>/tmp/fines') || die;
10 my ($count,$data)=Getoverdues();
11 #print $count;
12 my $count2=0;
13 #$count=1000;
14 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime(time);
15 $mon++;
16 $year=$year+1900;
17 #my $date=Date_DaysSince999($mon,$mday,$year);
18 my $date=Date_DaysSince999(2,20,2000);
19 my $bornum;
20 my $borrower;
21 my $total=0;
22 my $max=5;
23 my $bornum2;
24 for (my $i=0;$i<$count;$i++){
25   my @dates=split('-',$data->[$i]->{'date_due'});
26     my $date2=Date_DaysSince999($dates[1],$dates[2],$dates[0]);    
27     my $due="$dates[2]/$dates[1]/$dates[0]";
28     if ($date2 <= $date){
29       $count2++;
30       my $difference=$date-$date2;
31       if ($bornum != $data->[$i]->{'borrowernumber'}){
32         
33         $bornum=$data->[$i]->{'borrowernumber'};
34         $borrower=BorType($bornum);
35       }
36
37
38           my ($amount,$type,$printout)=CalcFine($data->[$i]->{'itemnumber'},$borrower->{'categorycode'},$difference);      
39           if ($amount > $max){
40             $amount=$max;
41           }
42           if ($amount > 0){
43             UpdateFine($data->[$i]->{'itemnumber'},$bornum,$amount,$type,$due);
44             if ($bornum2 == $data->[$i]->{'borrowernumber'}){
45               $total=$total+$amount;
46             } else {
47               print FILE "\"$borrower->{'cardnumber'}\"\,\"$borrower->{'phone'}\"\,\"Overdue or Extd Rental$total\"\,\"$borrower->{'homebranch'}\"\n";
48               $total=$amount;
49             }
50             if ($amount ==5){
51 #             marklost();
52             }
53               print "$printout\t$borrower->{'cardnumber'}\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'}\n";
54           } else {
55 #           print "0 fine\n";
56           }
57
58     }
59     $bornum2=$data->[$i]->{'borrowernumber'};
60 }
61 close FILE;