Just added an order clause to getitemtypes
[koha.git] / overdue.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 # Copyright 2000-2002 Katipo Communications
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA  02111-1307 USA
21
22 use strict;
23 use C4::Context;
24 use C4::Output;
25 use CGI;
26 use HTML::Template;
27
28 my $input = new CGI;
29 my $type=$input->param('type');
30
31 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
32 my ($template, $loggedinuser, $cookie)
33         = get_template_and_user({template_name => "overdue.tmpl",
34                      query => $query,
35                      type => "intranet",
36                      authnotrequired => 0,
37                      flagsrequired => {catalogue => 1},
38                      debug => 1,
39                      });
40 my $duedate;
41 my $bornum;
42 my $itemnum;
43 my $data1;
44 my $data2;
45 my $data3;
46 my $name;
47 my $phone;
48 my $email;
49 my $biblionumber;
50 my $title;
51 my $author;
52 my @datearr = localtime(time());
53 my $todaysdate = (1900+$datearr[5]).'-'.sprintf ("%0.2d", ($datearr[4]+1)).'-'.sprintf ("%0.2d", $datearr[3]);
54
55 my $dbh = C4::Context->dbh;
56
57 my $query="select date_due,borrowernumber,itemnumber from issues where isnull(returndate) && date_due<'$todaysdate' order by date_due,borrowernumber";
58 my $sth=$dbh->prepare($query);
59 $sth->execute;
60
61 my @overduedata;
62 while (my $data=$sth->fetchrow_hashref) {
63   $duedate=$data->{'date_due'};
64   $bornum=$data->{'borrowernumber'};
65   $itemnum=$data->{'itemnumber'};
66
67   my $query="select concat(firstname,' ',surname),phone,emailaddress from borrowers where borrowernumber='$bornum'";
68   my $sth1=$dbh->prepare($query);
69   $sth1->execute;
70   $data1=$sth1->fetchrow_hashref;
71   $name=$data1->{'concat(firstname,\' \',surname)'};
72   $phone=$data1->{'phone'};
73   $email=$data1->{'emailaddress'};
74   $sth1->finish;
75
76   # FIXME - There's already a $query in this scope.
77   my $query="select biblionumber from items where itemnumber='$itemnum'";
78   my $sth2=$dbh->prepare($query);
79   $sth2->execute;
80   $data2=$sth2->fetchrow_hashref;
81   $biblionumber=$data2->{'biblionumber'};
82   $sth2->finish;
83
84   # FIXME - There's already a $query in this scope.
85   my $query="select title,author from biblio where biblionumber='$biblionumber'";
86   my $sth3=$dbh->prepare($query);
87   $sth3->execute;
88   $data3=$sth3->fetchrow_hashref;
89   $title=$data3->{'title'};
90   $author=$data3->{'author'};
91   $sth3->finish;
92   push (@overduedata, { duedate      => $duedate,
93                         bornum       => $bornum,
94                         itemnum      => $itemnum,
95                         name         => $name,
96                         phone        => $phone,
97                         email        => $email,
98                         biblionumber => $biblionumber,
99                         title        => $title,
100                         author       => $author });
101
102 }
103
104 $sth->finish;
105
106 $template->param( startmenureport => join ('', startmenu('report')),
107                 endmenureport     => join ('', endmenu('report')),
108                 todaysdate        => $todaysdate,
109                 overdueloop       => \@overduedata );
110
111 print "Content-Type: text/html\n\n", $template->output;