Fixed a little bug so that flags get recalculated after an item is issued.
[koha.git] / overdue.pl
1 #!/usr/bin/perl
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA  02111-1307 USA
20
21 use strict;
22 use C4::Output;
23 use CGI;
24 use C4::Database;
25
26 my $input = new CGI;
27 print $input->header;
28 my $type=$input->param('type');
29 print startpage();
30 print startmenu('report');
31
32 my $duedate;
33 my $bornum;
34 my $itemnum;
35 my $data1;
36 my $data2;
37 my $data3;
38 my $name;
39 my $phone;
40 my $email;
41 my $biblionumber;
42 my $title;
43 my $author;
44 my @datearr = localtime(time());
45 my $todaysdate = (1900+$datearr[5]).'-'.sprintf ("%0.2d", ($datearr[4]+1)).'-'.sprintf ("%0.2d", $datearr[3]);
46
47 print "<FONT SIZE=6><em>Items Overdue as of $todaysdate</em></FONT><br><P>";
48
49 print << "EOF";
50 <TABLE  cellspacing=0 cellpadding=5 border=0 align=center>
51 <TR VALIGN=TOP>
52 <TD  bgcolor="99cc33" background="/koha/images/background-mem.gif" colspan ><b>Due Date</b></td>
53 <TD  bgcolor="99cc33" background="/koha/images/background-mem.gif" colspan ><b>Patron</b></td>
54 <TD  bgcolor="99cc33" background="/koha/images/background-mem.gif"><b>Phone</b></td>
55 <TD  bgcolor="99cc33" background="/koha/images/background-mem.gif"><b>Title</b></td>
56 <TD  bgcolor="99cc33" background="/koha/images/background-mem.gif"><b>Author</b></td>
57 </tr>
58 EOF
59
60 my $dbh=C4Connect;
61
62 my $query="select date_due,borrowernumber,itemnumber from issues where isnull(returndate) && date_due<'$todaysdate' order by date_due,borrowernumber";
63 my $sth=$dbh->prepare($query);
64 $sth->execute;
65 while (my $data=$sth->fetchrow_hashref) {
66   $duedate=$data->{'date_due'};
67   $bornum=$data->{'borrowernumber'};
68   $itemnum=$data->{'itemnumber'};
69   
70   my $query="select concat(firstname,' ',surname),phone,emailaddress from borrowers where borrowernumber='$bornum'";
71   my $sth1=$dbh->prepare($query);
72   $sth1->execute;
73   $data1=$sth1->fetchrow_hashref;
74   $name=$data1->{'concat(firstname,\' \',surname)'};
75   $phone=$data1->{'phone'};
76   $email=$data1->{'emailaddress'};
77   $sth1->finish;
78
79   my $query="select biblionumber from items where itemnumber='$itemnum'";
80   my $sth2=$dbh->prepare($query);
81   $sth2->execute;
82   $data2=$sth2->fetchrow_hashref;
83   $biblionumber=$data2->{'biblionumber'};
84   $sth2->finish;
85
86   my $query="select title,author from biblio where biblionumber='$biblionumber'";
87   my $sth3=$dbh->prepare($query);
88   $sth3->execute;
89   $data3=$sth3->fetchrow_hashref;
90   $title=$data3->{'title'};
91   $author=$data3->{'author'};
92   $sth3->finish;
93
94   if (!$email){
95     print "<tr><td>$duedate</td><td>$name</td><td>$phone</td><td>$title</td><td>$author</td></tr>";
96   } else {
97     print "<tr><td>$duedate</td><td><a href=\"mailto:$email?subject=Overdue: $title\">$name</a></td><td>$phone</td><td>$title</td><td>$author</td></tr>";
98   }
99 }
100
101 $sth->finish;
102 $dbh->disconnect;
103
104 print "</table>";
105
106 print endmenu('report');
107 print endpage();