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
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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!
27 #use warnings; FIXME - Bug 2505
32 use C4
::Dates qw
/format_date format_date_in_iso/;
34 use Date
::Calc qw
/Today Add_Delta_YMD/;
37 my $order = $input->param('order');
38 my $startdate=$input->param('from');
39 my $enddate=$input->param('to');
40 my $run_report=$input->param('run_report');
41 my $report_page=$input->param('report_page');
43 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
45 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
47 template_name
=> "circ/pendingreserves.tmpl",
51 flagsrequired
=> { circulate
=> "circulate_remaining_permissions" },
69 my ( $year, $month, $day ) = Today
();
70 my $todaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", $year, $month, $day);
71 my $yesterdaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YMD
($year, $month, $day, 0, 0, -1));
72 #changed from delivered range of 10 years-yesterday to 2 days ago-today
73 # Find two days ago for the default shelf pull start and end dates
74 my $pastdate = sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YMD
($year, $month, $day, 0, 0, -2));
76 # Predefine the start and end dates if they are not already defined
77 $startdate =~ s/^\s+//;
78 $startdate =~ s/\s+$//;
81 # Check if null, should string match, if so set start and end date to yesterday
82 if (!defined($startdate) or $startdate eq "") {
83 $startdate = format_date
($pastdate);
85 if (!defined($enddate) or $enddate eq "") {
86 $enddate = format_date
($todaysdate);
91 my ($prev_results, $next_results, $next_or_previous) = (0,0,0);
93 my $dbh = C4
::Context
->dbh;
94 my ($sqlorderby, $sqldatewhere, $sqllimitoffset) = ("","","");
95 $debug and warn format_date_in_iso
($startdate) . "\n" . format_date_in_iso
($enddate);
96 my @query_params = ();
98 $sqldatewhere .= " AND reservedate >= ?";
99 push @query_params, format_date_in_iso
($startdate);
102 $sqldatewhere .= " AND reservedate <= ?";
103 push @query_params, format_date_in_iso
($enddate);
106 $sqllimitoffset = " LIMIT 251";
108 $sqllimitoffset .= " OFFSET=?";
109 push @query_params, ($report_page * 250);
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
158 LEFT JOIN issues ON items.itemnumber=issues.itemnumber
160 reserves.found IS NULL
162 AND items.itemnumber NOT IN (SELECT itemnumber FROM branchtransfers where datearrived IS NULL)
163 AND issues.itemnumber IS NULL
164 AND reserves.priority <> 0
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=? ";
173 push @query_params, C4
::Context
->userenv->{'branch'};
175 $strsth .= " GROUP BY reserves.biblionumber " . $sqlorderby;
177 my $sth = $dbh->prepare($strsth);
178 $sth->execute(@query_params);
182 while ( my $data = $sth->fetchrow_hashref ) {
183 $this=$data->{biblionumber
}.":".$data->{borrowernumber
};
188 reservedate
=> format_date
( $data->{l_reservedate
} ),
189 priority
=> $data->{priority
},
190 name
=> $data->{l_patron
},
191 title
=> $data->{title
},
192 author
=> $data->{author
},
193 borrowernumber
=> $data->{borrowernumber
},
194 itemnum
=> $data->{itemnumber
},
195 phone
=> $data->{phone
},
196 email
=> $data->{email
},
197 biblionumber
=> $data->{biblionumber
},
198 statusw
=> ( $data->{found
} eq "W" ),
199 statusf
=> ( $data->{found
} eq "F" ),
200 holdingbranch
=> $data->{l_holdingbranch
},
201 branch
=> $data->{l_branch
},
202 itemcallnumber
=> $data->{l_itemcallnumber
},
203 notes
=> $data->{notes
},
204 notificationdate
=> $data->{notificationdate
},
205 reminderdate
=> $data->{reminderdate
},
206 count
=> $data->{icount
},
207 rcount
=> $data->{rcount
},
208 pullcount
=> $data->{icount
} <= $data->{rcount
} ?
$data->{icount
} : $data->{rcount
},
209 itype
=> $data->{l_itype
},
210 location
=> $data->{l_location
}
219 if ($report_page > 0) {
220 $prev_results = $report_page - 1;
222 if ( scalar(@reservedata) > 250 ) {
223 $next_results = $report_page + 1;
224 pop(@reservedata); # .. we retrieved 251 results
226 if ($prev_results || $next_results) {
227 $next_or_previous = 1;
230 # *** I doubt any of this is needed now with the above fixes *** -d.u.
232 #$strsth=~ s/AND reserves.itemnumber is NULL/AND reserves.itemnumber is NOT NULL/;
233 #$strsth=~ s/LEFT JOIN items ON items.biblionumber=reserves.biblionumber/LEFT JOIN items ON items.biblionumber=reserves.itemnumber/;
234 #$sth = $dbh->prepare($strsth);
235 #if (C4::Context->preference('IndependantBranches')){
236 # $sth->execute(C4::Context->userenv->{'branch'});
241 #while ( my $data = $sth->fetchrow_hashref ) {
242 # $this=$data->{biblionumber}.":".$data->{borrowernumber};
247 # reservedate => format_date( $data->{l_reservedate} ),
248 # priority => $data->{priority},
249 # name => $data->{l_patron},
250 # title => $data->{title},
251 # author => $data->{author},
252 # borrowernumber => $data->{borrowernumber},
253 # itemnum => $data->{itemnumber},
254 # phone => $data->{phone},
255 # email => $data->{email},
256 # biblionumber => $data->{biblionumber},
257 # statusw => ( $data->{found} eq "W" ),
258 # statusf => ( $data->{found} eq "F" ),
259 # holdingbranch => $data->{l_holdingbranch},
260 # branch => $data->{l_branch},
261 # itemcallnumber => $data->{l_itemcallnumber},
262 # notes => $data->{notes},
263 # notificationdate => $data->{notificationdate},
264 # reminderdate => $data->{reminderdate},
265 # count => $data->{icount},
266 # rcount => $data->{rcount},
267 # pullcount => $data->{icount} <= $data->{rcount} ? $data->{icount} : $data->{rcount},
268 # itype => $data->{l_itype},
269 # location => $data->{l_location},
280 todaysdate
=> format_date
($todaysdate),
283 run_report
=> $run_report,
284 report_page
=> $report_page,
285 prev_results
=> $prev_results,
286 next_results
=> $next_results,
287 next_or_previous
=> $next_or_previous,
288 reserveloop
=> \
@reservedata,
289 "BiblioDefaultView".C4
::Context
->preference("BiblioDefaultView") => 1,
290 DHTMLcalendar_dateformat
=> C4
::Dates
->DHTMLcalendar(),
291 dateformat
=> C4
::Context
->preference("dateformat"),
294 output_html_with_http_headers
$input, $cookie, $template->output;