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');
39 my $run_report=$input->param('run_report');
40 my $report_page=$input->param('report_page');
42 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
44 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
46 template_name
=> "circ/pendingreserves.tmpl",
50 flagsrequired
=> { circulate
=> "circulate_remaining_permissions" },
68 my ( $year, $month, $day ) = Today
();
69 my $todaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", $year, $month, $day);
70 my $yesterdaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YMD
($year, $month, $day, 0, 0, -1));
71 #changed from delivered range of 10 years-yesterday to 2 days ago-today
72 # Find two days ago for the default shelf pull start and end dates
73 my $pastdate = sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YMD
($year, $month, $day, 0, 0, -2));
75 # Predefine the start and end dates if they are not already defined
76 $startdate =~ s/^\s+//;
77 $startdate =~ s/\s+$//;
80 # Check if null, should string match, if so set start and end date to yesterday
81 if (!defined($startdate) or $startdate eq "") {
82 $startdate = format_date
($pastdate);
84 if (!defined($enddate) or $enddate eq "") {
85 $enddate = format_date
($todaysdate);
90 my ($prev_results, $next_results, $next_or_previous) = (0,0,0);
92 my $dbh = C4
::Context
->dbh;
93 my ($sqlorderby, $sqldatewhere, $sqllimitoffset) = ("","","");
94 $debug and warn format_date_in_iso
($startdate) . "\n" . format_date_in_iso
($enddate);
95 my @query_params = ();
97 $sqldatewhere .= " AND reservedate >= ?";
98 push @query_params, format_date_in_iso
($startdate);
101 $sqldatewhere .= " AND reservedate <= ?";
102 push @query_params, format_date_in_iso
($enddate);
105 $sqllimitoffset = " LIMIT 251";
107 $sqllimitoffset .= " OFFSET=?";
108 push @query_params, ($report_page * 250);
111 if ($order eq "biblio") {
112 $sqlorderby = " ORDER BY biblio.title ";
113 } elsif ($order eq "itype") {
114 $sqlorderby = " ORDER BY l_itype, location, l_itemcallnumber ";
115 } elsif ($order eq "location") {
116 $sqlorderby = " ORDER BY location, l_itemcallnumber, holdingbranch ";
117 } elsif ($order eq "date") {
118 $sqlorderby = " ORDER BY l_reservedate, location, l_itemcallnumber ";
119 } elsif ($order eq "library") {
120 $sqlorderby = " ORDER BY holdingbranch, l_itemcallnumber, location ";
121 } elsif ($order eq "call") {
122 $sqlorderby = " ORDER BY l_itemcallnumber, holdingbranch, location ";
124 $sqlorderby = " ORDER BY biblio.title ";
127 "SELECT min(reservedate) as l_reservedate,
128 reserves.borrowernumber as borrowernumber,
129 GROUP_CONCAT(DISTINCT items.holdingbranch
130 ORDER BY items.itemnumber SEPARATOR '<br/>') l_holdingbranch,
131 reserves.biblionumber,
133 GROUP_CONCAT(DISTINCT reserves.branchcode
134 ORDER BY items.itemnumber SEPARATOR ', ') l_branch,
135 items.holdingbranch as branch,
136 items.itemcallnumber,
137 GROUP_CONCAT(DISTINCT items.itype
138 ORDER BY items.itemnumber SEPARATOR '<br/>') l_itype,
139 GROUP_CONCAT(DISTINCT items.location
140 ORDER BY items.itemnumber SEPARATOR '<br/>') l_location,
141 GROUP_CONCAT(DISTINCT items.itemcallnumber
142 ORDER BY items.itemnumber SEPARATOR '<br/>') l_itemcallnumber,
147 max(priority) as priority,
151 count(DISTINCT items.itemnumber) as icount,
152 count(DISTINCT reserves.borrowernumber) as rcount
154 LEFT JOIN items ON items.biblionumber=reserves.biblionumber
155 LEFT JOIN biblio ON reserves.biblionumber=biblio.biblionumber
156 LEFT JOIN branchtransfers ON items.itemnumber=branchtransfers.itemnumber
157 LEFT JOIN issues ON items.itemnumber=issues.itemnumber
159 reserves.found IS NULL
161 AND items.itemnumber NOT IN (SELECT itemnumber FROM branchtransfers where datearrived IS NULL)
162 AND issues.itemnumber IS NULL
163 AND reserves.priority <> 0
164 AND notforloan = 0 AND damaged = 0 AND itemlost = 0 AND wthdrawn = 0
166 # GROUP BY reserves.biblionumber allows only items that are not checked out, else multiples occur when
167 # multiple patrons have a hold on an item
170 if (C4
::Context
->preference('IndependantBranches')){
171 $strsth .= " AND items.holdingbranch=? ";
172 push @query_params, C4
::Context
->userenv->{'branch'};
174 $strsth .= " GROUP BY reserves.biblionumber " . $sqlorderby;
176 my $sth = $dbh->prepare($strsth);
177 $sth->execute(@query_params);
181 while ( my $data = $sth->fetchrow_hashref ) {
182 $this=$data->{biblionumber
}.":".$data->{borrowernumber
};
187 reservedate
=> format_date
( $data->{l_reservedate
} ),
188 priority
=> $data->{priority
},
189 name
=> $data->{l_patron
},
190 title
=> $data->{title
},
191 author
=> $data->{author
},
192 borrowernumber
=> $data->{borrowernumber
},
193 itemnum
=> $data->{itemnumber
},
194 phone
=> $data->{phone
},
195 email
=> $data->{email
},
196 biblionumber
=> $data->{biblionumber
},
197 statusw
=> ( $data->{found
} eq "W" ),
198 statusf
=> ( $data->{found
} eq "F" ),
199 holdingbranch
=> $data->{l_holdingbranch
},
200 branch
=> $data->{l_branch
},
201 itemcallnumber
=> $data->{l_itemcallnumber
},
202 notes
=> $data->{notes
},
203 notificationdate
=> $data->{notificationdate
},
204 reminderdate
=> $data->{reminderdate
},
205 count
=> $data->{icount
},
206 rcount
=> $data->{rcount
},
207 pullcount
=> $data->{icount
} <= $data->{rcount
} ?
$data->{icount
} : $data->{rcount
},
208 itype
=> $data->{l_itype
},
209 location
=> $data->{l_location
}
218 if ($report_page > 0) {
219 $prev_results = $report_page - 1;
221 if ( scalar(@reservedata) > 250 ) {
222 $next_results = $report_page + 1;
223 pop(@reservedata); # .. we retrieved 251 results
225 if ($prev_results || $next_results) {
226 $next_or_previous = 1;
229 # *** I doubt any of this is needed now with the above fixes *** -d.u.
231 #$strsth=~ s/AND reserves.itemnumber is NULL/AND reserves.itemnumber is NOT NULL/;
232 #$strsth=~ s/LEFT JOIN items ON items.biblionumber=reserves.biblionumber/LEFT JOIN items ON items.biblionumber=reserves.itemnumber/;
233 #$sth = $dbh->prepare($strsth);
234 #if (C4::Context->preference('IndependantBranches')){
235 # $sth->execute(C4::Context->userenv->{'branch'});
240 #while ( my $data = $sth->fetchrow_hashref ) {
241 # $this=$data->{biblionumber}.":".$data->{borrowernumber};
246 # reservedate => format_date( $data->{l_reservedate} ),
247 # priority => $data->{priority},
248 # name => $data->{l_patron},
249 # title => $data->{title},
250 # author => $data->{author},
251 # borrowernumber => $data->{borrowernumber},
252 # itemnum => $data->{itemnumber},
253 # phone => $data->{phone},
254 # email => $data->{email},
255 # biblionumber => $data->{biblionumber},
256 # statusw => ( $data->{found} eq "W" ),
257 # statusf => ( $data->{found} eq "F" ),
258 # holdingbranch => $data->{l_holdingbranch},
259 # branch => $data->{l_branch},
260 # itemcallnumber => $data->{l_itemcallnumber},
261 # notes => $data->{notes},
262 # notificationdate => $data->{notificationdate},
263 # reminderdate => $data->{reminderdate},
264 # count => $data->{icount},
265 # rcount => $data->{rcount},
266 # pullcount => $data->{icount} <= $data->{rcount} ? $data->{icount} : $data->{rcount},
267 # itype => $data->{l_itype},
268 # location => $data->{l_location},
279 todaysdate
=> format_date
($todaysdate),
282 run_report
=> $run_report,
283 report_page
=> $report_page,
284 prev_results
=> $prev_results,
285 next_results
=> $next_results,
286 next_or_previous
=> $next_or_previous,
287 reserveloop
=> \
@reservedata,
288 "BiblioDefaultView".C4
::Context
->preference("BiblioDefaultView") => 1,
289 DHTMLcalendar_dateformat
=> C4
::Dates
->DHTMLcalendar(),
290 dateformat
=> C4
::Context
->preference("dateformat"),
293 output_html_with_http_headers
$input, $cookie, $template->output;