New XML API
[koha.git] / reports / 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 CGI;
25
26 use C4::Auth;
27 use C4::Date;
28 use C4::Biblio;
29 use C4::Search;
30 use C4::Interface::CGI::Output;
31 use C4::Date;
32 my $input = new CGI;
33 my $type=$input->param('type');
34
35 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
36
37 my ($template, $loggedinuser, $cookie)
38       = get_template_and_user({template_name => "reports/overdue.tmpl",
39                                          query => $input,
40                                          type => "intranet",
41                                          authnotrequired => 0,
42                                          flagsrequired => {borrowers => 1},
43                                          debug => 1,
44                                          });
45 my $duedate;
46 my $bornum;
47 my $itemnumber;
48 my $barcode;
49 my $data1;
50 my $data2;
51 my $data3;
52 my $name;
53 my $categorycode;
54 my $phone;
55 my $email;
56 my $biblionumber;
57 my $title;
58 my $author;
59 my @datearr = localtime(time());
60 my $todaysdate = (1900+$datearr[5]).'-'.sprintf ("%0.2d", ($datearr[4]+1)).'-'.sprintf ("%0.2d", $datearr[3]);
61 my $dateformatted= sprintf ("%0.2d", $datearr[3]).'-'.sprintf ("%0.2d", ($datearr[4]+1)).'-'.(1900+$datearr[5]);
62 my $dbh = C4::Context->dbh;
63 my $count=0;
64 my @results;
65 my @kohafields;
66 my @values;
67 my @relations;
68 my $sort;
69 my @and_or;
70 push @kohafields, "date_due","date_due";
71 push @values,$todaysdate,"0000-00-00";
72 push @relations ,"\@attr 2=1","\@attr 2=5"; ## 
73 push @and_or,"\@and";
74         ($count,@results)=ZEBRAsearch_kohafields(\@kohafields,\@values,\@relations,$sort,\@and_or);
75
76
77
78 my @overduedata;
79 foreach my $xml(@results) {
80 my @kohafields; ## just parse the fields required
81 push @kohafields,"title","author","biblionumber","itemnumber","barcode","date_due","borrowernumber";
82 my ($biblio,@itemrecords) = XMLmarc2koha($dbh,$xml,"",@kohafields);
83  foreach my $data(@itemrecords){
84    if ($data->{'date_due'} lt $todaysdate && $data->{'date_due'} gt "0000-00-00" ){
85   $duedate=format_date($data->{'date_due'});
86   $bornum=$data->{'borrowernumber'};
87   $itemnumber=$data->{'itemnumber'};
88   $biblionumber=$data->{'biblionumber'};
89   $barcode=$data->{'barcode'};
90
91   my $sth1=$dbh->prepare("select concat(firstname,' ',surname),phone,emailaddress,categorycode from borrowers where borrowernumber=?");
92   $sth1->execute($bornum);
93   $data1=$sth1->fetchrow_hashref;
94   $name=$data1->{'concat(firstname,\' \',surname)'};
95   $phone=$data1->{'phone'};
96   $categorycode=$data1->{'categorycode'};
97   $email=$data1->{'emailaddress'};
98   $sth1->finish;
99
100  
101
102
103
104   $title=$biblio->{'title'};
105   $author=$biblio->{'author'};
106    push (@overduedata, {        duedate      => format_date($duedate),
107                         bornum       => $bornum,
108                         itemnum      => $itemnumber,
109                         name         => $name,
110                         categorycode         => $categorycode,
111                         phone        => $phone,
112                         email        => $email,
113                         biblionumber => $biblionumber,
114
115                         barcode         =>$barcode,
116                         title        => $title,
117                         author       => $author });
118   }## if overdue
119
120   }##foreach item
121 }## for each biblio
122
123 $template->param(               dateformatted      => $dateformatted, count=>$count,
124                 overdueloop       => \@overduedata );
125
126 output_html_with_http_headers $input, $cookie, $template->output;