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
26 use C4::Dates qw/format_date format_date_in_iso/;
27 use Date::Calc qw/Today Add_Delta_YM/;
32 $debug = $ENV{DEBUG} || 0;
36 my $order = $input->param('order');
37 my $startdate=$input->param('from');
38 my $enddate=$input->param('to');
39 my $ratio=$input->param('ratio');
41 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
43 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
45 template_name => "circ/reserveratios.tmpl",
49 flagsrequired => { circulate => 1 },
67 my ( $year, $month, $day ) = Today();
68 my $todaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", $year, $month, $day);
69 # Find yesterday for the default shelf pull start and end dates
70 # A default of the prior years's holds is a reasonable way to pull holds
71 my $datelastyear = sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YM($year, $month, $day, -1, 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($datelastyear);
82 if (!defined($enddate) or $enddate eq "") {
83 $enddate = format_date($todaysdate);
85 if (!defined($ratio) or $ratio eq "" or $ratio !~ /^\s*\d+\s*$/ ) {
89 $ratio = 1; # prevent division by zero
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) ;
98 if ($order eq "biblio") {
99 $sqlorderby = " order by biblio.title, holdingbranch, listcall, l_location ";
100 } elsif ($order eq "callnumber") {
101 $sqlorderby = " order by listcall, holdingbranch, l_location ";
102 } elsif ($order eq "itemcount") {
103 $sqlorderby = " order by itemcount, reservecount ";
104 } elsif ($order eq "itype") {
105 $sqlorderby = " order by l_itype, holdingbranch, listcall ";
106 } elsif ($order eq "location") {
107 $sqlorderby = " order by l_location, holdingbranch, listcall ";
108 } elsif ($order eq "reservecount") {
109 $sqlorderby = " order by reservecount DESC ";
110 } elsif ($order eq "branch") {
111 $sqlorderby = " order by holdingbranch, l_location, listcall ";
113 $sqlorderby = " order by reservecount DESC ";
117 reserves.borrowernumber as borrowernumber,
118 reserves.biblionumber,
119 reserves.branchcode as branch,
121 items.itemcallnumber,
123 GROUP_CONCAT(DISTINCT items.itemcallnumber
124 ORDER BY items.itemnumber SEPARATOR '<br>') as listcall,
125 GROUP_CONCAT(DISTINCT holdingbranch
126 ORDER BY items.itemnumber SEPARATOR '<br>') as listbranch,
127 GROUP_CONCAT(DISTINCT items.location
128 ORDER BY items.itemnumber SEPARATOR '<br>') as l_location,
129 GROUP_CONCAT(DISTINCT items.itype
130 ORDER BY items.itemnumber SEPARATOR '<br>') as l_itype,
135 count(DISTINCT reserves.borrowernumber) as reservecount,
136 count(DISTINCT items.itemnumber) as itemcount
138 LEFT JOIN items ON items.biblionumber=reserves.biblionumber
139 LEFT JOIN biblio ON reserves.biblionumber=biblio.biblionumber
141 notforloan = 0 AND damaged = 0 AND itemlost = 0 AND wthdrawn = 0
146 if (C4::Context->preference('IndependantBranches')){
147 $strsth .= " AND items.holdingbranch=? ";
149 $strsth .= " GROUP BY reserves.biblionumber " . $sqlorderby;
150 my $sth = $dbh->prepare($strsth);
152 if (C4::Context->preference('IndependantBranches')){
153 $sth->execute(C4::Context->userenv->{'branch'});
159 while ( my $data = $sth->fetchrow_hashref ) {
161 my $ratiocalc = int(10 * $data->{reservecount} / $data->{itemcount} / $ratio )/10;
165 reservedate => format_date( $data->{reservedate} ),
166 priority => $data->{priority},
167 name => $data->{borrower},
168 title => $data->{title},
169 author => $data->{author},
170 notes => $data->{notes},
171 itemnum => $data->{itemnumber},
172 biblionumber => $data->{biblionumber},
173 holdingbranch => $data->{holdingbranch},
174 listbranch => $data->{listbranch},
175 branch => $data->{branch},
176 itemcallnumber => $data->{itemcallnumber},
177 location => $data->{l_location},
178 itype => $data->{l_itype},
179 reservecount => $data->{reservecount},
180 itemcount => $data->{itemcount},
181 ratiocalc => $ratiocalc,
182 ratio_ge_one => $ratiocalc ge 1.0 ? 1 : "",
183 listcall => $data->{listcall}
192 todaysdate => format_date($todaysdate),
196 reserveloop => \@reservedata,
197 "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
198 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
201 output_html_with_http_headers $input, $cookie, $template->output;