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/;
33 use Date::Calc qw/Today Add_Delta_YMD/;
36 my $order = $input->param('order');
37 my $startdate=$input->param('from');
38 my $enddate=$input->param('to');
40 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
42 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
44 template_name => "circ/pendingreserves.tmpl",
48 flagsrequired => { circulate => 1 },
66 my ( $year, $month, $day ) = Today();
67 my $todaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", $year, $month, $day);
68 my $yesterdaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YMD($year, $month, $day, 0, 0, -1));
69 # Find 10 years ago for the default shelf pull start and end dates
70 # A default of the prior day's holds is a reasonable way to pull holds
71 my $pastdate = sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YMD($year, $month, $day, -10, 0, 0));
73 # Predefine the start and end dates if they are not already defined
74 $startdate =~ s/^\s+//;
75 $startdate =~ s/\s+$//;
78 # Check if null, should string match, if so set start and end date to yesterday
79 if (!defined($startdate) or $startdate eq "") {
80 $startdate = format_date($pastdate);
82 if (!defined($enddate) or $enddate eq "") {
83 $enddate = format_date($yesterdaysdate);
87 my $dbh = C4::Context->dbh;
88 my ($sqlorderby, $sqldatewhere) = ("","");
89 $debug and warn format_date_in_iso($startdate) . "\n" . format_date_in_iso($enddate);
90 $sqldatewhere .= " AND reservedate >= " . $dbh->quote(format_date_in_iso($startdate)) if ($startdate) ;
91 $sqldatewhere .= " AND reservedate <= " . $dbh->quote(format_date_in_iso($enddate)) if ($enddate) ;
94 if ($order eq "biblio") {
95 $sqlorderby = " order by biblio.title ";
96 } elsif ($order eq "itype") {
97 $sqlorderby = " order by l_itype, location, l_itemcallnumber ";
98 } elsif ($order eq "location") {
99 $sqlorderby = " order by location, l_itemcallnumber, holdingbranch ";
100 } elsif ($order eq "date") {
101 $sqlorderby = " order by l_reservedate, location, l_itemcallnumber ";
102 } elsif ($order eq "library") {
103 $sqlorderby = " order by holdingbranch, l_itemcallnumber, location ";
104 } elsif ($order eq "call") {
105 $sqlorderby = " order by l_itemcallnumber, holdingbranch, location ";
107 $sqlorderby = " order by biblio.title ";
110 "SELECT min(reservedate) as l_reservedate,
111 reserves.borrowernumber as borrowernumber,
112 GROUP_CONCAT(DISTINCT items.holdingbranch
113 ORDER BY items.itemnumber SEPARATOR '<br>') l_holdingbranch,
114 reserves.biblionumber,
116 GROUP_CONCAT(DISTINCT reserves.branchcode
117 ORDER BY items.itemnumber SEPARATOR ', ') l_branch,
118 items.holdingbranch as branch,
119 items.itemcallnumber,
120 GROUP_CONCAT(DISTINCT items.itype
121 ORDER BY items.itemnumber SEPARATOR '<br>') l_itype,
122 GROUP_CONCAT(DISTINCT items.location
123 ORDER BY items.itemnumber SEPARATOR '<br>') l_location,
124 GROUP_CONCAT(DISTINCT items.itemcallnumber
125 ORDER BY items.itemnumber SEPARATOR '<br>') l_itemcallnumber,
130 max(priority) as priority,
134 count(DISTINCT items.itemnumber) as icount,
135 count(DISTINCT reserves.borrowernumber) as rcount
137 LEFT JOIN items ON items.biblionumber=reserves.biblionumber
138 LEFT JOIN biblio ON reserves.biblionumber=biblio.biblionumber
139 LEFT JOIN branchtransfers ON items.itemnumber=branchtransfers.itemnumber
141 reserves.found IS NULL
143 AND items.itemnumber NOT IN (SELECT itemnumber FROM branchtransfers where datearrived IS NULL)
144 AND items.itemnumber NOT IN (SELECT itemnumber FROM issues)
145 AND reserves.priority <> 0
146 AND reserves.itemnumber is NULL
147 AND notforloan = 0 AND damaged = 0 AND itemlost = 0 AND wthdrawn = 0
149 # GROUP BY reserves.biblionumber allows only items that are not checked out, else multiples occur when
150 # multiple patrons have a hold on an item
153 if (C4::Context->preference('IndependantBranches')){
154 $strsth .= " AND items.holdingbranch=? ";
156 $strsth .= " GROUP BY reserves.biblionumber " . $sqlorderby;
157 my $sth = $dbh->prepare($strsth);
159 if (C4::Context->preference('IndependantBranches')){
160 $sth->execute(C4::Context->userenv->{'branch'});
168 while ( my $data = $sth->fetchrow_hashref ) {
169 $this=$data->{biblionumber}.":".$data->{borrowernumber};
174 reservedate => format_date( $data->{l_reservedate} ),
175 priority => $data->{priority},
176 name => $data->{l_patron},
177 title => $data->{title},
178 author => $data->{author},
179 borrowernumber => $data->{borrowernumber},
180 itemnum => $data->{itemnumber},
181 phone => $data->{phone},
182 email => $data->{email},
183 biblionumber => $data->{biblionumber},
184 statusw => ( $data->{found} eq "W" ),
185 statusf => ( $data->{found} eq "F" ),
186 holdingbranch => $data->{l_holdingbranch},
187 branch => $data->{l_branch},
188 itemcallnumber => $data->{l_itemcallnumber},
189 notes => $data->{notes},
190 notificationdate => $data->{notificationdate},
191 reminderdate => $data->{reminderdate},
192 count => $data->{icount},
193 rcount => $data->{rcount},
194 pullcount => $data->{icount} <= $data->{rcount} ? $data->{icount} : $data->{rcount},
195 itype => $data->{l_itype},
196 location => $data->{l_location}
204 # *** I doubt any of this is needed now with the above fixes *** -d.u.
206 #$strsth=~ s/AND reserves.itemnumber is NULL/AND reserves.itemnumber is NOT NULL/;
207 #$strsth=~ s/LEFT JOIN items ON items.biblionumber=reserves.biblionumber/LEFT JOIN items ON items.biblionumber=reserves.itemnumber/;
208 #$sth = $dbh->prepare($strsth);
209 #if (C4::Context->preference('IndependantBranches')){
210 # $sth->execute(C4::Context->userenv->{'branch'});
215 #while ( my $data = $sth->fetchrow_hashref ) {
216 # $this=$data->{biblionumber}.":".$data->{borrowernumber};
221 # reservedate => format_date( $data->{l_reservedate} ),
222 # priority => $data->{priority},
223 # name => $data->{l_patron},
224 # title => $data->{title},
225 # author => $data->{author},
226 # borrowernumber => $data->{borrowernumber},
227 # itemnum => $data->{itemnumber},
228 # phone => $data->{phone},
229 # email => $data->{email},
230 # biblionumber => $data->{biblionumber},
231 # statusw => ( $data->{found} eq "W" ),
232 # statusf => ( $data->{found} eq "F" ),
233 # holdingbranch => $data->{l_holdingbranch},
234 # branch => $data->{l_branch},
235 # itemcallnumber => $data->{l_itemcallnumber},
236 # notes => $data->{notes},
237 # notificationdate => $data->{notificationdate},
238 # reminderdate => $data->{reminderdate},
239 # count => $data->{icount},
240 # rcount => $data->{rcount},
241 # pullcount => $data->{icount} <= $data->{rcount} ? $data->{icount} : $data->{rcount},
242 # itype => $data->{l_itype},
243 # location => $data->{l_location},
253 todaysdate => format_date($todaysdate),
256 reserveloop => \@reservedata,
257 "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
258 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
261 output_html_with_http_headers $input, $cookie, $template->output;