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/;
31 $debug = $ENV{DEBUG} || 0;
35 my $order = $input->param('order');
36 my $startdate=$input->param('from');
37 my $enddate=$input->param('to');
38 my $ratio=$input->param('ratio');
40 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
42 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
44 template_name => "circ/reserveratios.tmpl",
48 flagsrequired => { circulate => 1 },
66 my @datearr = localtime( time() );
69 ( 1900 + $datearr[5] ) . '-'
70 . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) . '-'
71 . sprintf( "%0.2d", $datearr[3] );
73 # Find yesterday for the default shelf pull start and end dates
74 # A defualt of the prior years's holds is a reasonable way to pull holds
75 my @datearr_yesterday = localtime( time() - 86400*365 );
77 ( 1900 + $datearr_yesterday[5] ) . '-'
78 . sprintf( "%0.2d", ( $datearr_yesterday[4] + 1 ) ) . '-'
79 . sprintf( "%0.2d", $datearr_yesterday[3] );
81 # Predefine the start and end dates if they are not already defined
82 $startdate =~ s/^\s+//;
83 $startdate =~ s/\s+$//;
86 # Check if null, should string match, if so set start and end date to yesterday
87 if (!defined($startdate) or $startdate eq "") {
88 $startdate = format_date($yesterdaysdate);
90 if (!defined($enddate) or $enddate eq "") {
91 $enddate = format_date($todaysdate);
93 if (!defined($ratio) or $ratio eq "" or $ratio !~ /^\s*\d+\s*$/ ) {
97 $ratio = 1; # prevent division by zero
100 my $dbh = C4::Context->dbh;
101 my ($sqlorderby, $sqldatewhere) = ("","");
102 $debug and warn format_date_in_iso($startdate) . "\n" . format_date_in_iso($enddate);
103 $sqldatewhere .= " AND reservedate >= " . $dbh->quote(format_date_in_iso($startdate)) if ($startdate) ;
104 $sqldatewhere .= " AND reservedate <= " . $dbh->quote(format_date_in_iso($enddate)) if ($enddate) ;
106 if ($order eq "biblio") {
107 $sqlorderby = " order by biblio.title, holdingbranch, listcall, l_location ";
108 } elsif ($order eq "callnumber") {
109 $sqlorderby = " order by listcall, holdingbranch, l_location ";
110 } elsif ($order eq "itemcount") {
111 $sqlorderby = " order by itemcount, reservecount ";
112 } elsif ($order eq "itype") {
113 $sqlorderby = " order by l_itype, holdingbranch, listcall ";
114 } elsif ($order eq "location") {
115 $sqlorderby = " order by l_location, holdingbranch, listcall ";
116 } elsif ($order eq "reservecount") {
117 $sqlorderby = " order by reservecount DESC ";
118 } elsif ($order eq "branch") {
119 $sqlorderby = " order by holdingbranch, l_location, listcall ";
121 $sqlorderby = " order by reservecount DESC ";
125 reserves.borrowernumber as borrowernumber,
126 reserves.biblionumber,
127 reserves.branchcode as branch,
129 items.itemcallnumber,
131 GROUP_CONCAT(DISTINCT items.itemcallnumber
132 ORDER BY items.itemnumber SEPARATOR '<br>') as listcall,
133 GROUP_CONCAT(DISTINCT holdingbranch
134 ORDER BY items.itemnumber SEPARATOR '<br>') as listbranch,
135 GROUP_CONCAT(DISTINCT items.location
136 ORDER BY items.itemnumber SEPARATOR '<br>') as l_location,
137 GROUP_CONCAT(DISTINCT items.itype
138 ORDER BY items.itemnumber SEPARATOR '<br>') as l_itype,
143 count(DISTINCT reserves.borrowernumber) as reservecount,
144 count(DISTINCT items.itemnumber) as itemcount
146 LEFT JOIN items ON items.biblionumber=reserves.biblionumber
147 LEFT JOIN biblio ON reserves.biblionumber=biblio.biblionumber
149 notforloan = 0 AND damaged = 0 AND itemlost = 0 AND wthdrawn = 0
154 if (C4::Context->preference('IndependantBranches')){
155 $strsth .= " AND items.holdingbranch=? ";
157 $strsth .= " GROUP BY reserves.biblionumber " . $sqlorderby;
158 my $sth = $dbh->prepare($strsth);
160 if (C4::Context->preference('IndependantBranches')){
161 $sth->execute(C4::Context->userenv->{'branch'});
167 while ( my $data = $sth->fetchrow_hashref ) {
169 my $ratiocalc = int(10 * $data->{reservecount} / $data->{itemcount} / $ratio )/10;
173 reservedate => format_date( $data->{reservedate} ),
174 priority => $data->{priority},
175 name => $data->{borrower},
176 title => $data->{title},
177 author => $data->{author},
178 notes => $data->{notes},
179 itemnum => $data->{itemnumber},
180 biblionumber => $data->{biblionumber},
181 holdingbranch => $data->{holdingbranch},
182 listbranch => $data->{listbranch},
183 branch => $data->{branch},
184 itemcallnumber => $data->{itemcallnumber},
185 location => $data->{l_location},
186 itype => $data->{l_itype},
187 reservecount => $data->{reservecount},
188 itemcount => $data->{itemcount},
189 ratiocalc => $ratiocalc,
190 ratio_ge_one => $ratiocalc ge 1.0 ? 1 : "",
191 listcall => $data->{listcall}
200 todaysdate => format_date($todaysdate),
204 reserveloop => \@reservedata,
205 "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
206 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
209 output_html_with_http_headers $input, $cookie, $template->output;