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/;
28 use Date::Calc qw/Today Add_Delta_YM/;
31 my $order = $input->param('order');
32 my $startdate=$input->param('from');
33 my $enddate=$input->param('to');
34 my $ratio=$input->param('ratio');
36 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
38 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
40 template_name => "circ/reserveratios.tmpl",
44 flagsrequired => { circulate => 1 },
62 my ( $year, $month, $day ) = Today();
63 my $todaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", $year, $month, $day);
64 # Find yesterday for the default shelf pull start and end dates
65 # A default of the prior years's holds is a reasonable way to pull holds
66 my $datelastyear = sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YM($year, $month, $day, -1, 0));
68 # Predefine the start and end dates if they are not already defined
69 $startdate =~ s/^\s+//;
70 $startdate =~ s/\s+$//;
73 # Check if null, should string match, if so set start and end date to yesterday
74 if (!defined($startdate) or $startdate eq "") {
75 $startdate = format_date($datelastyear);
77 if (!defined($enddate) or $enddate eq "") {
78 $enddate = format_date($todaysdate);
80 if (!defined($ratio) or $ratio eq "" or $ratio !~ /^\s*\d+\s*$/ ) {
84 $ratio = 1; # prevent division by zero
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) ;
93 if ($order eq "biblio") {
94 $sqlorderby = " order by biblio.title, holdingbranch, listcall, l_location ";
95 } elsif ($order eq "callnumber") {
96 $sqlorderby = " order by listcall, holdingbranch, l_location ";
97 } elsif ($order eq "itemcount") {
98 $sqlorderby = " order by itemcount, reservecount ";
99 } elsif ($order eq "itype") {
100 $sqlorderby = " order by l_itype, holdingbranch, listcall ";
101 } elsif ($order eq "location") {
102 $sqlorderby = " order by l_location, holdingbranch, listcall ";
103 } elsif ($order eq "reservecount") {
104 $sqlorderby = " order by reservecount DESC ";
105 } elsif ($order eq "branch") {
106 $sqlorderby = " order by holdingbranch, l_location, listcall ";
108 $sqlorderby = " order by reservecount DESC ";
112 reserves.borrowernumber as borrowernumber,
113 reserves.biblionumber,
114 reserves.branchcode as branch,
116 items.itemcallnumber,
118 GROUP_CONCAT(DISTINCT items.itemcallnumber
119 ORDER BY items.itemnumber SEPARATOR '<br>') as listcall,
120 GROUP_CONCAT(DISTINCT holdingbranch
121 ORDER BY items.itemnumber SEPARATOR '<br>') as listbranch,
122 GROUP_CONCAT(DISTINCT items.location
123 ORDER BY items.itemnumber SEPARATOR '<br>') as l_location,
124 GROUP_CONCAT(DISTINCT items.itype
125 ORDER BY items.itemnumber SEPARATOR '<br>') as l_itype,
130 count(DISTINCT reserves.borrowernumber) as reservecount,
131 count(DISTINCT items.itemnumber) as itemcount
133 LEFT JOIN items ON items.biblionumber=reserves.biblionumber
134 LEFT JOIN biblio ON reserves.biblionumber=biblio.biblionumber
136 notforloan = 0 AND damaged = 0 AND itemlost = 0 AND wthdrawn = 0
141 if (C4::Context->preference('IndependantBranches')){
142 $strsth .= " AND items.holdingbranch=? ";
144 $strsth .= " GROUP BY reserves.biblionumber " . $sqlorderby;
145 my $sth = $dbh->prepare($strsth);
147 if (C4::Context->preference('IndependantBranches')){
148 $sth->execute(C4::Context->userenv->{'branch'});
154 while ( my $data = $sth->fetchrow_hashref ) {
156 my $ratiocalc = int(10 * $data->{reservecount} / $data->{itemcount} / $ratio )/10;
160 reservedate => format_date( $data->{reservedate} ),
161 priority => $data->{priority},
162 name => $data->{borrower},
163 title => $data->{title},
164 author => $data->{author},
165 notes => $data->{notes},
166 itemnum => $data->{itemnumber},
167 biblionumber => $data->{biblionumber},
168 holdingbranch => $data->{holdingbranch},
169 listbranch => $data->{listbranch},
170 branch => $data->{branch},
171 itemcallnumber => $data->{itemcallnumber},
172 location => $data->{l_location},
173 itype => $data->{l_itype},
174 reservecount => $data->{reservecount},
175 itemcount => $data->{itemcount},
176 ratiocalc => $ratiocalc,
177 ratio_ge_one => $ratiocalc ge 1.0 ? 1 : "",
178 listcall => $data->{listcall}
187 todaysdate => format_date($todaysdate),
191 reserveloop => \@reservedata,
192 "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
193 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
196 output_html_with_http_headers $input, $cookie, $template->output;