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
21 # Modification by D.Ulm, actually works (as long as indep. branches not turned on)
22 # Someone let me know what indep. branches is supposed to do and I'll make that part work too
24 # The reserve pull lists *works* as long as not for indepencdant branches, I can fix!
31 use C4::Dates qw/format_date format_date_in_iso/;
36 $debug = $ENV{DEBUG} || 0;
40 my $order = $input->param('order');
41 my $startdate=$input->param('from');
42 my $enddate=$input->param('to');
44 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
46 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
48 template_name => "circ/pendingreserves.tmpl",
52 flagsrequired => { circulate => 1 },
70 my @datearr = localtime( time() );
72 ( 1900 + $datearr[5] ) . '-'
73 . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) . '-'
74 . sprintf( "%0.2d", $datearr[3] );
76 # Find yesterday for the default shelf pull end dates
77 # A defualt of the prior day's holds is a reasonable way to pull holds
78 my @datearr_yesterday = localtime( time() - 86400 );
80 ( 1900 + $datearr_yesterday[5] ) . '-'
81 . sprintf( "%0.2d", ( $datearr_yesterday[4] + 1 ) ) . '-'
82 . sprintf( "%0.2d", $datearr_yesterday[3] );
83 # Find 10 years ago for the default shelf pull start and end dates
84 # A defualt of the prior day's holds is a reasonable way to pull holds
85 my @datearr_past = localtime( time() - 86400*365*10 );
87 ( 1900 + $datearr_past[5] ) . '-'
88 . sprintf( "%0.2d", ( $datearr_past[4] + 1 ) ) . '-'
89 . sprintf( "%0.2d", $datearr_past[3] );
91 # Predefine the start and end dates if they are not already defined
92 $startdate =~ s/^\s+//;
93 $startdate =~ s/\s+$//;
96 # Check if null, should string match, if so set start and end date to yesterday
97 if (!defined($startdate) or $startdate eq "") {
98 $startdate = format_date($pastdate);
100 if (!defined($enddate) or $enddate eq "") {
101 $enddate = format_date($yesterdaysdate);
105 my $dbh = C4::Context->dbh;
106 my ($sqlorderby, $sqldatewhere) = ("","");
107 $debug and warn format_date_in_iso($startdate) . "\n" . format_date_in_iso($enddate);
108 $sqldatewhere .= " AND reservedate >= " . $dbh->quote(format_date_in_iso($startdate)) if ($startdate) ;
109 $sqldatewhere .= " AND reservedate <= " . $dbh->quote(format_date_in_iso($enddate)) if ($enddate) ;
112 if ($order eq "biblio") {
113 $sqlorderby = " order by biblio.title ";
114 } elsif ($order eq "itype") {
115 $sqlorderby = " order by l_itype, location, l_itemcallnumber ";
116 } elsif ($order eq "location") {
117 $sqlorderby = " order by location, l_itemcallnumber, holdingbranch ";
118 } elsif ($order eq "date") {
119 $sqlorderby = " order by l_reservedate, location, l_itemcallnumber ";
120 } elsif ($order eq "library") {
121 $sqlorderby = " order by holdingbranch, l_itemcallnumber, location ";
122 } elsif ($order eq "call") {
123 $sqlorderby = " order by l_itemcallnumber, holdingbranch, location ";
125 $sqlorderby = " order by biblio.title ";
128 "SELECT min(reservedate) as l_reservedate,
129 reserves.borrowernumber as borrowernumber,
130 GROUP_CONCAT(DISTINCT items.holdingbranch
131 ORDER BY items.itemnumber SEPARATOR '<br>') l_holdingbranch,
132 reserves.biblionumber,
134 GROUP_CONCAT(DISTINCT reserves.branchcode
135 ORDER BY items.itemnumber SEPARATOR ', ') l_branch,
136 items.holdingbranch as branch,
137 items.itemcallnumber,
138 GROUP_CONCAT(DISTINCT items.itype
139 ORDER BY items.itemnumber SEPARATOR '<br>') l_itype,
140 GROUP_CONCAT(DISTINCT items.location
141 ORDER BY items.itemnumber SEPARATOR '<br>') l_location,
142 GROUP_CONCAT(DISTINCT items.itemcallnumber
143 ORDER BY items.itemnumber SEPARATOR '<br>') l_itemcallnumber,
148 max(priority) as priority,
152 count(DISTINCT items.itemnumber) as icount,
153 count(DISTINCT reserves.borrowernumber) as rcount
155 LEFT JOIN items ON items.biblionumber=reserves.biblionumber
156 LEFT JOIN biblio ON reserves.biblionumber=biblio.biblionumber
157 LEFT JOIN branchtransfers ON items.itemnumber=branchtransfers.itemnumber
159 reserves.found IS NULL
161 AND items.itemnumber NOT IN (SELECT itemnumber FROM branchtransfers where datearrived IS NULL)
162 AND items.itemnumber NOT IN (SELECT itemnumber FROM issues)
163 AND reserves.priority <> 0
164 AND reserves.itemnumber is NULL
165 AND notforloan = 0 AND damaged = 0 AND itemlost = 0 AND wthdrawn = 0
167 # GROUP BY reserves.biblionumber allows only items that are not checked out, else multiples occur when
168 # multiple patrons have a hold on an item
171 if (C4::Context->preference('IndependantBranches')){
172 $strsth .= " AND items.holdingbranch=? ";
174 $strsth .= " GROUP BY reserves.biblionumber " . $sqlorderby;
175 my $sth = $dbh->prepare($strsth);
177 if (C4::Context->preference('IndependantBranches')){
178 $sth->execute(C4::Context->userenv->{'branch'});
186 while ( my $data = $sth->fetchrow_hashref ) {
187 $this=$data->{biblionumber}.":".$data->{borrowernumber};
192 reservedate => format_date( $data->{l_reservedate} ),
193 priority => $data->{priority},
194 name => $data->{l_patron},
195 title => $data->{title},
196 author => $data->{author},
197 borrowernumber => $data->{borrowernumber},
198 itemnum => $data->{itemnumber},
199 phone => $data->{phone},
200 email => $data->{email},
201 biblionumber => $data->{biblionumber},
202 statusw => ( $data->{found} eq "W" ),
203 statusf => ( $data->{found} eq "F" ),
204 holdingbranch => $data->{l_holdingbranch},
205 branch => $data->{l_branch},
206 itemcallnumber => $data->{l_itemcallnumber},
207 notes => $data->{notes},
208 notificationdate => $data->{notificationdate},
209 reminderdate => $data->{reminderdate},
210 count => $data->{icount},
211 rcount => $data->{rcount},
212 pullcount => $data->{icount} <= $data->{rcount} ? $data->{icount} : $data->{rcount},
213 itype => $data->{l_itype},
214 location => $data->{l_location}
222 # *** I doubt any of this is needed now with the above fixes *** -d.u.
224 #$strsth=~ s/AND reserves.itemnumber is NULL/AND reserves.itemnumber is NOT NULL/;
225 #$strsth=~ s/LEFT JOIN items ON items.biblionumber=reserves.biblionumber/LEFT JOIN items ON items.biblionumber=reserves.itemnumber/;
226 #$sth = $dbh->prepare($strsth);
227 #if (C4::Context->preference('IndependantBranches')){
228 # $sth->execute(C4::Context->userenv->{'branch'});
233 #while ( my $data = $sth->fetchrow_hashref ) {
234 # $this=$data->{biblionumber}.":".$data->{borrowernumber};
239 # reservedate => format_date( $data->{l_reservedate} ),
240 # priority => $data->{priority},
241 # name => $data->{l_patron},
242 # title => $data->{title},
243 # author => $data->{author},
244 # borrowernumber => $data->{borrowernumber},
245 # itemnum => $data->{itemnumber},
246 # phone => $data->{phone},
247 # email => $data->{email},
248 # biblionumber => $data->{biblionumber},
249 # statusw => ( $data->{found} eq "W" ),
250 # statusf => ( $data->{found} eq "F" ),
251 # holdingbranch => $data->{l_holdingbranch},
252 # branch => $data->{l_branch},
253 # itemcallnumber => $data->{l_itemcallnumber},
254 # notes => $data->{notes},
255 # notificationdate => $data->{notificationdate},
256 # reminderdate => $data->{reminderdate},
257 # count => $data->{icount},
258 # rcount => $data->{rcount},
259 # pullcount => $data->{icount} <= $data->{rcount} ? $data->{icount} : $data->{rcount},
260 # itype => $data->{l_itype},
261 # location => $data->{l_location},
271 todaysdate => format_date($todaysdate),
274 reserveloop => \@reservedata,
275 "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
276 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
279 output_html_with_http_headers $input, $cookie, $template->output;