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 "") {
97 my $dbh = C4::Context->dbh;
98 my ($sqlorderby, $sqldatewhere) = ("","");
99 $debug and warn format_date_in_iso($startdate) . "\n" . format_date_in_iso($enddate);
100 $sqldatewhere .= " AND reservedate >= " . $dbh->quote(format_date_in_iso($startdate)) if ($startdate) ;
101 $sqldatewhere .= " AND reservedate <= " . $dbh->quote(format_date_in_iso($enddate)) if ($enddate) ;
103 if ($order eq "biblio") {
104 $sqlorderby = " order by biblio.title, holdingbranch, listcall, l_location ";
105 } elsif ($order eq "callnumber") {
106 $sqlorderby = " order by listcall, holdingbranch, l_location ";
107 } elsif ($order eq "itemcount") {
108 $sqlorderby = " order by itemcount, reservecount ";
109 } elsif ($order eq "itype") {
110 $sqlorderby = " order by l_itype, holdingbranch, listcall ";
111 } elsif ($order eq "location") {
112 $sqlorderby = " order by l_location, holdingbranch, listcall ";
113 } elsif ($order eq "reservecount") {
114 $sqlorderby = " order by reservecount DESC ";
115 } elsif ($order eq "branch") {
116 $sqlorderby = " order by holdingbranch, l_location, listcall ";
118 $sqlorderby = " order by reservecount DESC ";
122 reserves.borrowernumber as borrowernumber,
123 reserves.biblionumber,
124 reserves.branchcode as branch,
126 items.itemcallnumber,
128 GROUP_CONCAT(DISTINCT items.itemcallnumber
129 ORDER BY items.itemnumber SEPARATOR '<br>') as listcall,
130 GROUP_CONCAT(DISTINCT holdingbranch
131 ORDER BY items.itemnumber SEPARATOR '<br>') as listbranch,
132 GROUP_CONCAT(DISTINCT items.location
133 ORDER BY items.itemnumber SEPARATOR '<br>') as l_location,
134 GROUP_CONCAT(DISTINCT items.itype
135 ORDER BY items.itemnumber SEPARATOR '<br>') as l_itype,
140 count(DISTINCT reserves.borrowernumber) as reservecount,
141 count(DISTINCT items.itemnumber) as itemcount
143 LEFT JOIN items ON items.biblionumber=reserves.biblionumber
144 LEFT JOIN biblio ON reserves.biblionumber=biblio.biblionumber
146 notforloan = 0 AND damaged = 0 AND itemlost = 0 AND wthdrawn = 0
151 if (C4::Context->preference('IndependantBranches')){
152 $strsth .= " AND items.holdingbranch=? ";
154 $strsth .= " GROUP BY reserves.biblionumber " . $sqlorderby;
155 my $sth = $dbh->prepare($strsth);
157 if (C4::Context->preference('IndependantBranches')){
158 $sth->execute(C4::Context->userenv->{'branch'});
164 while ( my $data = $sth->fetchrow_hashref ) {
166 my $ratiocalc = int(10 * $data->{reservecount} / $data->{itemcount} / $ratio )/10;
170 reservedate => format_date( $data->{reservedate} ),
171 priority => $data->{priority},
172 name => $data->{borrower},
173 title => $data->{title},
174 author => $data->{author},
175 notes => $data->{notes},
176 itemnum => $data->{itemnumber},
177 biblionumber => $data->{biblionumber},
178 holdingbranch => $data->{holdingbranch},
179 listbranch => $data->{listbranch},
180 branch => $data->{branch},
181 itemcallnumber => $data->{itemcallnumber},
182 location => $data->{l_location},
183 itype => $data->{l_itype},
184 reservecount => $data->{reservecount},
185 itemcount => $data->{itemcount},
186 ratiocalc => $ratiocalc,
187 ratio_ge_one => $ratiocalc ge 1.0 ? 1 : "",
188 listcall => $data->{listcall}
197 todaysdate => format_date($todaysdate),
201 reserveloop => \@reservedata,
202 "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
203 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
206 output_html_with_http_headers $input, $cookie, $template->output;