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/;
32 use Date::Calc qw/Today Add_Delta_YMD/;
37 $debug = $ENV{DEBUG} || 0;
41 my $order = $input->param('order');
42 my $startdate=$input->param('from');
43 my $enddate=$input->param('to');
45 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
47 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
49 template_name => "circ/pendingreserves.tmpl",
53 flagsrequired => { circulate => 1 },
71 my ( $year, $month, $day ) = Today();
72 my $todaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", $year, $month, $day);
73 my $yesterdaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YMD($year, $month, $day, 0, 0, -1));
74 # Find 10 years ago for the default shelf pull start and end dates
75 # A default of the prior day's holds is a reasonable way to pull holds
76 my $pastdate = sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YMD($year, $month, $day, -10, 0, 0));
78 # Predefine the start and end dates if they are not already defined
79 $startdate =~ s/^\s+//;
80 $startdate =~ s/\s+$//;
83 # Check if null, should string match, if so set start and end date to yesterday
84 if (!defined($startdate) or $startdate eq "") {
85 $startdate = format_date($pastdate);
87 if (!defined($enddate) or $enddate eq "") {
88 $enddate = format_date($yesterdaysdate);
92 my $dbh = C4::Context->dbh;
93 my ($sqlorderby, $sqldatewhere) = ("","");
94 $debug and warn format_date_in_iso($startdate) . "\n" . format_date_in_iso($enddate);
95 $sqldatewhere .= " AND reservedate >= " . $dbh->quote(format_date_in_iso($startdate)) if ($startdate) ;
96 $sqldatewhere .= " AND reservedate <= " . $dbh->quote(format_date_in_iso($enddate)) if ($enddate) ;
99 if ($order eq "biblio") {
100 $sqlorderby = " order by biblio.title ";
101 } elsif ($order eq "itype") {
102 $sqlorderby = " order by l_itype, location, l_itemcallnumber ";
103 } elsif ($order eq "location") {
104 $sqlorderby = " order by location, l_itemcallnumber, holdingbranch ";
105 } elsif ($order eq "date") {
106 $sqlorderby = " order by l_reservedate, location, l_itemcallnumber ";
107 } elsif ($order eq "library") {
108 $sqlorderby = " order by holdingbranch, l_itemcallnumber, location ";
109 } elsif ($order eq "call") {
110 $sqlorderby = " order by l_itemcallnumber, holdingbranch, location ";
112 $sqlorderby = " order by biblio.title ";
115 "SELECT min(reservedate) as l_reservedate,
116 reserves.borrowernumber as borrowernumber,
117 GROUP_CONCAT(DISTINCT items.holdingbranch
118 ORDER BY items.itemnumber SEPARATOR '<br>') l_holdingbranch,
119 reserves.biblionumber,
121 GROUP_CONCAT(DISTINCT reserves.branchcode
122 ORDER BY items.itemnumber SEPARATOR ', ') l_branch,
123 items.holdingbranch as branch,
124 items.itemcallnumber,
125 GROUP_CONCAT(DISTINCT items.itype
126 ORDER BY items.itemnumber SEPARATOR '<br>') l_itype,
127 GROUP_CONCAT(DISTINCT items.location
128 ORDER BY items.itemnumber SEPARATOR '<br>') l_location,
129 GROUP_CONCAT(DISTINCT items.itemcallnumber
130 ORDER BY items.itemnumber SEPARATOR '<br>') l_itemcallnumber,
135 max(priority) as priority,
139 count(DISTINCT items.itemnumber) as icount,
140 count(DISTINCT reserves.borrowernumber) as rcount
142 LEFT JOIN items ON items.biblionumber=reserves.biblionumber
143 LEFT JOIN biblio ON reserves.biblionumber=biblio.biblionumber
144 LEFT JOIN branchtransfers ON items.itemnumber=branchtransfers.itemnumber
146 reserves.found IS NULL
148 AND items.itemnumber NOT IN (SELECT itemnumber FROM branchtransfers where datearrived IS NULL)
149 AND items.itemnumber NOT IN (SELECT itemnumber FROM issues)
150 AND reserves.priority <> 0
151 AND reserves.itemnumber is NULL
152 AND notforloan = 0 AND damaged = 0 AND itemlost = 0 AND wthdrawn = 0
154 # GROUP BY reserves.biblionumber allows only items that are not checked out, else multiples occur when
155 # multiple patrons have a hold on an item
158 if (C4::Context->preference('IndependantBranches')){
159 $strsth .= " AND items.holdingbranch=? ";
161 $strsth .= " GROUP BY reserves.biblionumber " . $sqlorderby;
162 my $sth = $dbh->prepare($strsth);
164 if (C4::Context->preference('IndependantBranches')){
165 $sth->execute(C4::Context->userenv->{'branch'});
173 while ( my $data = $sth->fetchrow_hashref ) {
174 $this=$data->{biblionumber}.":".$data->{borrowernumber};
179 reservedate => format_date( $data->{l_reservedate} ),
180 priority => $data->{priority},
181 name => $data->{l_patron},
182 title => $data->{title},
183 author => $data->{author},
184 borrowernumber => $data->{borrowernumber},
185 itemnum => $data->{itemnumber},
186 phone => $data->{phone},
187 email => $data->{email},
188 biblionumber => $data->{biblionumber},
189 statusw => ( $data->{found} eq "W" ),
190 statusf => ( $data->{found} eq "F" ),
191 holdingbranch => $data->{l_holdingbranch},
192 branch => $data->{l_branch},
193 itemcallnumber => $data->{l_itemcallnumber},
194 notes => $data->{notes},
195 notificationdate => $data->{notificationdate},
196 reminderdate => $data->{reminderdate},
197 count => $data->{icount},
198 rcount => $data->{rcount},
199 pullcount => $data->{icount} <= $data->{rcount} ? $data->{icount} : $data->{rcount},
200 itype => $data->{l_itype},
201 location => $data->{l_location}
209 # *** I doubt any of this is needed now with the above fixes *** -d.u.
211 #$strsth=~ s/AND reserves.itemnumber is NULL/AND reserves.itemnumber is NOT NULL/;
212 #$strsth=~ s/LEFT JOIN items ON items.biblionumber=reserves.biblionumber/LEFT JOIN items ON items.biblionumber=reserves.itemnumber/;
213 #$sth = $dbh->prepare($strsth);
214 #if (C4::Context->preference('IndependantBranches')){
215 # $sth->execute(C4::Context->userenv->{'branch'});
220 #while ( my $data = $sth->fetchrow_hashref ) {
221 # $this=$data->{biblionumber}.":".$data->{borrowernumber};
226 # reservedate => format_date( $data->{l_reservedate} ),
227 # priority => $data->{priority},
228 # name => $data->{l_patron},
229 # title => $data->{title},
230 # author => $data->{author},
231 # borrowernumber => $data->{borrowernumber},
232 # itemnum => $data->{itemnumber},
233 # phone => $data->{phone},
234 # email => $data->{email},
235 # biblionumber => $data->{biblionumber},
236 # statusw => ( $data->{found} eq "W" ),
237 # statusf => ( $data->{found} eq "F" ),
238 # holdingbranch => $data->{l_holdingbranch},
239 # branch => $data->{l_branch},
240 # itemcallnumber => $data->{l_itemcallnumber},
241 # notes => $data->{notes},
242 # notificationdate => $data->{notificationdate},
243 # reminderdate => $data->{reminderdate},
244 # count => $data->{icount},
245 # rcount => $data->{rcount},
246 # pullcount => $data->{icount} <= $data->{rcount} ? $data->{icount} : $data->{rcount},
247 # itype => $data->{l_itype},
248 # location => $data->{l_location},
258 todaysdate => format_date($todaysdate),
261 reserveloop => \@reservedata,
262 "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
263 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
266 output_html_with_http_headers $input, $cookie, $template->output;