4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
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
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.
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
27 use C4::Dates qw/format_date/;
30 my $type = $input->param('type');
31 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
32 my $order = $input->param('order');
33 my $showall = $input->param('showall');
35 my $bornamefilter = $input->param('borname');
36 my $borcatfilter = $input->param('borcat');
37 my $itemtypefilter = $input->param('itemtype');
38 my $borflagsfilter = $input->param('borflags') || " ";
39 my $branchfilter = $input->param('branch');
41 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
43 template_name => "circ/overdue.tmpl",
47 flagsrequired => { reports => 1, circulate => 1 },
51 my $dbh = C4::Context->dbh;
54 $req = $dbh->prepare( "select categorycode, description from categories order by description");
57 while (my ($catcode, $description) =$req->fetchrow) {
58 my $selected = 1 if $catcode eq $borcatfilter;
59 my %row =(value => $catcode,
60 selected => $selected,
61 catname => $description,
63 push @borcatloop, \%row;
66 $req = $dbh->prepare( "select itemtype, description from itemtypes order by description");
69 while (my ($itemtype, $description) =$req->fetchrow) {
70 my $selected = 1 if $itemtype eq $itemtypefilter;
71 my %row =(value => $itemtype,
72 selected => $selected,
73 itemtypename => $description,
75 push @itemtypeloop, \%row;
77 my $onlymine=C4::Context->preference('IndependantBranches') &&
78 C4::Context->userenv &&
79 C4::Context->userenv->{flags}!=1 &&
80 C4::Context->userenv->{branch};
81 my $branches = GetBranches($onlymine);
84 push @selectflags, " ";#
85 push @selectflags,"gonenoaddress";#
86 push @selectflags,"debarred";#
87 push @selectflags,"lost";#
88 my $CGIflags=CGI::scrolling_list( -name => 'borflags',
90 -values => \@selectflags,
94 foreach my $thisbranch ( sort keys %$branches ) {
97 branchname => $branches->{$thisbranch}->{'branchname'},
98 selected => (C4::Context->userenv && $branches->{$thisbranch}->{'branchcode'} eq C4::Context->userenv->{'branch'})
100 push @branchloop, \%row;
102 $branchfilter=C4::Context->userenv->{'branch'} if ($onlymine && !$branchfilter);
104 $template->param( branchloop => \@branchloop );
105 $template->param(borcatloop=> \@borcatloop,
106 itemtypeloop => \@itemtypeloop,
107 branchloop=> \@branchloop,
108 CGIflags => $CGIflags,
109 borname => $bornamefilter,
111 showall => $showall);
125 my @datearr = localtime( time() );
127 ( 1900 + $datearr[5] ) . '-'
128 . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) . '-'
129 . sprintf( "%0.2d", $datearr[3] );
132 $bornamefilter =~s/\*/\%/g;
133 $bornamefilter =~s/\?/\_/g;
135 my $strsth="select date_due,concat(surname,' ', firstname) as borrower,
136 borrowers.phone, borrowers.email,issues.itemnumber, items.barcode, biblio.title, biblio.author,borrowers.borrowernumber
138 LEFT JOIN borrowers ON (issues.borrowernumber=borrowers.borrowernumber )
139 LEFT JOIN items ON (issues.itemnumber=items.itemnumber)
140 LEFT JOIN biblioitems ON (biblioitems.biblioitemnumber=items.biblioitemnumber)
141 LEFT JOIN biblio ON (biblio.biblionumber=items.biblionumber )
142 where isnull(returndate) ";
143 $strsth.= " && date_due<'".$todaysdate."' " unless ($showall);
144 $strsth.=" && (borrowers.firstname like '".$bornamefilter."%' or borrowers.surname like '".$bornamefilter."%' or borrowers.cardnumber like '".$bornamefilter."%')" if($bornamefilter) ;
145 $strsth.=" && borrowers.categorycode = '".$borcatfilter."' " if($borcatfilter) ;
146 $strsth.=" && biblioitems.itemtype = '".$itemtypefilter."' " if($itemtypefilter) ;
147 $strsth.=" && borrowers.flags = '".$borflagsfilter."' " if ($borflagsfilter ne " ") ;
148 $strsth.=" && issues.branchcode = '".$branchfilter."' " if($branchfilter) ;
149 if ($order eq "borrower"){
150 $strsth.=" order by borrower,date_due " ;
151 } elsif ($order eq "title"){
152 $strsth.=" order by title,date_due,borrower ";
153 } elsif ($order eq "barcode"){
154 $strsth.=" order by items.barcode,date_due,borrower ";
155 }elsif ($order eq "borrower desc"){
156 $strsth.=" order by borrower desc,date_due " ;
157 } elsif ($order eq "title desc"){
158 $strsth.=" order by title desc,date_due,borrower ";
159 } elsif ($order eq "barcode desc"){
160 $strsth.=" order by items.barcode desc,date_due,borrower ";
161 } elsif ($order eq "date_due desc"){
162 $strsth.=" order by date_due desc,borrower ";
164 $strsth.=" order by date_due,borrower ";
166 my $sth=$dbh->prepare($strsth);
167 #warn "overdue.pl : query string ".$strsth;
171 while (my $data=$sth->fetchrow_hashref) {
172 $duedate=$data->{'date_due'};
173 $duedate = format_date($duedate);
174 $itemnum=$data->{'itemnumber'};
176 $name=$data->{'borrower'};
177 $phone=$data->{'phone'};
178 $email=$data->{'email'};
180 $title=$data->{'title'};
181 $author=$data->{'author'};
182 push (@overduedata, { duedate => $duedate,
183 bornum => $data->{borrowernumber},
184 barcode => $data->{barcode},
189 biblionumber => $biblionumber,
191 author => $author });
196 todaysdate => $todaysdate,
197 overdueloop => \@overduedata
200 output_html_with_http_headers $input, $cookie, $template->output;