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);
124 my @datearr = localtime( time() );
126 ( 1900 + $datearr[5] ) . '-'
127 . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) . '-'
128 . sprintf( "%0.2d", $datearr[3] );
131 $bornamefilter =~s/\*/\%/g;
132 $bornamefilter =~s/\?/\_/g;
134 my $strsth="select date_due,concat(surname,' ', firstname) as borrower,
135 borrowers.phone, borrowers.email,issues.itemnumber, items.barcode, biblio.title, biblio.author,borrowers.borrowernumber,biblio.biblionumber
137 LEFT JOIN borrowers ON (issues.borrowernumber=borrowers.borrowernumber )
138 LEFT JOIN items ON (issues.itemnumber=items.itemnumber)
139 LEFT JOIN biblioitems ON (biblioitems.biblioitemnumber=items.biblioitemnumber)
140 LEFT JOIN biblio ON (biblio.biblionumber=items.biblionumber )
141 where isnull(returndate) ";
142 $strsth.= " && date_due<'".$todaysdate."' " unless ($showall);
143 $strsth.=" && (borrowers.firstname like '".$bornamefilter."%' or borrowers.surname like '".$bornamefilter."%' or borrowers.cardnumber like '".$bornamefilter."%')" if($bornamefilter) ;
144 $strsth.=" && borrowers.categorycode = '".$borcatfilter."' " if($borcatfilter) ;
145 $strsth.=" && biblioitems.itemtype = '".$itemtypefilter."' " if($itemtypefilter) ;
146 $strsth.=" && borrowers.flags = '".$borflagsfilter."' " if ($borflagsfilter ne " ") ;
147 $strsth.=" && issues.branchcode = '".$branchfilter."' " if($branchfilter) ;
148 if ($order eq "borrower"){
149 $strsth.=" order by borrower,date_due " ;
150 } elsif ($order eq "title"){
151 $strsth.=" order by title,date_due,borrower ";
152 } elsif ($order eq "barcode"){
153 $strsth.=" order by items.barcode,date_due,borrower ";
154 }elsif ($order eq "borrower desc"){
155 $strsth.=" order by borrower desc,date_due " ;
156 } elsif ($order eq "title desc"){
157 $strsth.=" order by title desc,date_due,borrower ";
158 } elsif ($order eq "barcode desc"){
159 $strsth.=" order by items.barcode desc,date_due,borrower ";
160 } elsif ($order eq "date_due desc"){
161 $strsth.=" order by date_due desc,borrower ";
163 $strsth.=" order by date_due,borrower ";
165 my $sth=$dbh->prepare($strsth);
166 #warn "overdue.pl : query string ".$strsth;
170 while (my $data=$sth->fetchrow_hashref) {
171 $duedate=$data->{'date_due'};
172 $duedate = format_date($duedate);
173 $itemnum=$data->{'itemnumber'};
175 $name=$data->{'borrower'};
176 $phone=$data->{'phone'};
177 $email=$data->{'email'};
179 $title=$data->{'title'};
180 $author=$data->{'author'};
181 push (@overduedata, {
183 borrowernumber => $data->{borrowernumber},
184 barcode => $data->{barcode},
189 biblionumber => $data->{'biblionumber'},
191 author => $author });
195 todaysdate => $todaysdate,
196 overdueloop => \@overduedata
199 output_html_with_http_headers $input, $cookie, $template->output;