3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use constant PULL_INTERVAL => 2;
31 use DateTime::Duration;
34 my $startdate = $input->param('from');
35 my $enddate = $input->param('to');
37 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
39 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
41 template_name => "circ/pendingreserves.tt",
45 flagsrequired => { circulate => "circulate_remaining_permissions" },
50 my $today = dt_from_string;
53 $startdate =~ s/^\s+//;
54 $startdate =~ s/\s+$//;
55 $startdate = eval{dt_from_string( $startdate )};
57 unless ( $startdate ){
58 # changed from delivered range of 10 years-yesterday to 2 days ago-today
59 # Find two days ago for the default shelf pull start date, unless HoldsToPullStartDate sys pref is set.
60 $startdate = $today - DateTime::Duration->new( days => C4::Context->preference('HoldsToPullStartDate') || PULL_INTERVAL );
66 $enddate = eval{dt_from_string( $enddate )};
69 #similarly: calculate end date with ConfirmFutureHolds (days)
70 $enddate = $today + DateTime::Duration->new( days => C4::Context->preference('ConfirmFutureHolds') || 0 );
74 my $dbh = C4::Context->dbh;
75 my $sqldatewhere = "";
76 my $startdate_iso = output_pref({ dt => $startdate, dateformat => 'iso', dateonly => 1 });
77 my $enddate_iso = output_pref({ dt => $enddate, dateformat => 'iso', dateonly => 1 });
79 $debug and warn $startdate_iso. "\n" . $enddate_iso;
81 my @query_params = ();
84 $sqldatewhere .= " AND reservedate >= ?";
85 push @query_params, $startdate_iso;
88 $sqldatewhere .= " AND reservedate <= ?";
89 push @query_params, $enddate_iso;
92 my $item_type = C4::Context->preference('item-level_itypes') ? "items.itype" : "biblioitems.itemtype";
95 "SELECT min(reservedate) as l_reservedate,
96 reserves.borrowernumber as borrowernumber,
97 GROUP_CONCAT(DISTINCT items.holdingbranch
98 ORDER BY items.itemnumber SEPARATOR '|') l_holdingbranch,
99 reserves.biblionumber,
100 reserves.branchcode as l_branch,
101 GROUP_CONCAT(DISTINCT $item_type
102 ORDER BY items.itemnumber SEPARATOR '|') l_item_type,
103 GROUP_CONCAT(DISTINCT items.location
104 ORDER BY items.itemnumber SEPARATOR '|') l_location,
105 GROUP_CONCAT(DISTINCT items.itemcallnumber
106 ORDER BY items.itemnumber SEPARATOR '<br/>') l_itemcallnumber,
107 GROUP_CONCAT(DISTINCT items.enumchron
108 ORDER BY items.itemnumber SEPARATOR '<br/>') l_enumchron,
109 GROUP_CONCAT(DISTINCT items.copynumber
110 ORDER BY items.itemnumber SEPARATOR '<br/>') l_copynumber,
113 count(DISTINCT items.itemnumber) as icount,
114 count(DISTINCT reserves.borrowernumber) as rcount,
118 LEFT JOIN items ON items.biblionumber=reserves.biblionumber
119 LEFT JOIN biblio ON reserves.biblionumber=biblio.biblionumber
120 LEFT JOIN biblioitems ON biblio.biblionumber=biblioitems.biblionumber
121 LEFT JOIN branchtransfers ON items.itemnumber=branchtransfers.itemnumber
122 LEFT JOIN issues ON items.itemnumber=issues.itemnumber
123 LEFT JOIN borrowers ON reserves.borrowernumber=borrowers.borrowernumber
125 reserves.found IS NULL
127 AND (reserves.itemnumber IS NULL OR reserves.itemnumber = items.itemnumber)
128 AND items.itemnumber NOT IN (SELECT itemnumber FROM branchtransfers where datearrived IS NULL)
129 AND items.itemnumber NOT IN (select itemnumber FROM reserves where found IS NOT NULL)
130 AND issues.itemnumber IS NULL
131 AND reserves.priority <> 0
132 AND reserves.suspend = 0
133 AND notforloan = 0 AND damaged = 0 AND itemlost = 0 AND withdrawn = 0
135 # GROUP BY reserves.biblionumber allows only items that are not checked out, else multiples occur when
136 # multiple patrons have a hold on an item
139 if (C4::Context->preference('IndependentBranches')){
140 $strsth .= " AND items.holdingbranch=? ";
141 push @query_params, C4::Context->userenv->{'branch'};
143 $strsth .= " GROUP BY reserves.biblionumber ORDER BY biblio.title ";
145 my $sth = $dbh->prepare($strsth);
146 $sth->execute(@query_params);
148 while ( my $data = $sth->fetchrow_hashref ) {
149 my $record = Koha::Biblios->find($data->{biblionumber});
151 $data->{subtitle} = [ $record->subtitles ];
155 reservedate => $data->{l_reservedate},
156 firstname => $data->{firstname} || '',
157 surname => $data->{surname},
158 title => $data->{title},
159 subtitle => $data->{subtitle},
160 author => $data->{author},
161 borrowernumber => $data->{borrowernumber},
162 biblionumber => $data->{biblionumber},
163 holdingbranches => [split('\|', $data->{l_holdingbranch})],
164 branch => $data->{l_branch},
165 itemcallnumber => $data->{l_itemcallnumber},
166 enumchron => $data->{l_enumchron},
167 copyno => $data->{l_copynumber},
168 count => $data->{icount},
169 rcount => $data->{rcount},
170 pullcount => $data->{icount} <= $data->{rcount} ? $data->{icount} : $data->{rcount},
171 itemTypes => [split('\|', $data->{l_item_type})],
172 locations => [split('\|', $data->{l_location})],
179 todaysdate => $today,
182 reserveloop => \@reservedata,
183 "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
184 HoldsToPullStartDate => C4::Context->preference('HoldsToPullStartDate') || PULL_INTERVAL,
185 HoldsToPullEndDate => C4::Context->preference('ConfirmFutureHolds') || 0,
188 output_html_with_http_headers $input, $cookie, $template->output;