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 my @query_params = ();
92 $sqldatewhere .= " AND reservedate >= ?";
93 push @query_params, format_date_in_iso
($startdate);
96 $sqldatewhere .= " AND reservedate <= ?";
97 push @query_params, format_date_in_iso
($enddate);
100 if ($order eq "biblio") {
101 $sqlorderby = " ORDER BY biblio.title, holdingbranch, listcall, l_location ";
102 } elsif ($order eq "callnumber") {
103 $sqlorderby = " ORDER BY listcall, holdingbranch, l_location ";
104 } elsif ($order eq "itemcount") {
105 $sqlorderby = " ORDER BY itemcount, reservecount ";
106 } elsif ($order eq "itype") {
107 $sqlorderby = " ORDER BY l_itype, holdingbranch, listcall ";
108 } elsif ($order eq "location") {
109 $sqlorderby = " ORDER BY l_location, holdingbranch, listcall ";
110 } elsif ($order eq "reservecount") {
111 $sqlorderby = " ORDER BY reservecount DESC ";
112 } elsif ($order eq "branch") {
113 $sqlorderby = " ORDER BY holdingbranch, l_location, listcall ";
115 $sqlorderby = " ORDER BY reservecount DESC ";
119 reserves.borrowernumber as borrowernumber,
120 reserves.biblionumber,
121 reserves.branchcode as branch,
123 items.itemcallnumber,
125 GROUP_CONCAT(DISTINCT items.itemcallnumber
126 ORDER BY items.itemnumber SEPARATOR '<br/>') as listcall,
127 GROUP_CONCAT(DISTINCT holdingbranch
128 ORDER BY items.itemnumber SEPARATOR '<br/>') as listbranch,
129 GROUP_CONCAT(DISTINCT items.location
130 ORDER BY items.itemnumber SEPARATOR '<br/>') as l_location,
131 GROUP_CONCAT(DISTINCT items.itype
132 ORDER BY items.itemnumber SEPARATOR '<br/>') as l_itype,
137 count(DISTINCT reserves.borrowernumber) as reservecount,
138 count(DISTINCT items.itemnumber) as itemcount
140 LEFT JOIN items ON items.biblionumber=reserves.biblionumber
141 LEFT JOIN biblio ON reserves.biblionumber=biblio.biblionumber
143 notforloan = 0 AND damaged = 0 AND itemlost = 0 AND wthdrawn = 0
148 if (C4
::Context
->preference('IndependantBranches')){
149 $strsth .= " AND items.holdingbranch=? ";
150 push @query_params, C4
::Context
->userenv->{'branch'};
153 $strsth .= " GROUP BY reserves.biblionumber " . $sqlorderby;
154 my $sth = $dbh->prepare($strsth);
155 $sth->execute(@query_params);
158 while ( my $data = $sth->fetchrow_hashref ) {
160 my $ratiocalc = int(10 * $data->{reservecount
} / $data->{itemcount} / $ratio )/10;
164 reservedate
=> format_date
( $data->{reservedate
} ),
165 priority
=> $data->{priority
},
166 name
=> $data->{borrower
},
167 title
=> $data->{title
},
168 author
=> $data->{author
},
169 notes
=> $data->{notes
},
170 itemnum
=> $data->{itemnumber
},
171 biblionumber
=> $data->{biblionumber
},
172 holdingbranch
=> $data->{holdingbranch
},
173 listbranch
=> $data->{listbranch
},
174 branch
=> $data->{branch
},
175 itemcallnumber
=> $data->{itemcallnumber
},
176 location
=> $data->{l_location
},
177 itype
=> $data->{l_itype
},
178 reservecount
=> $data->{reservecount
},
179 itemcount
=> $data->{itemcount
},
180 ratiocalc
=> $ratiocalc,
181 ratio_ge_one
=> $ratiocalc ge 1.0 ?
1 : "",
182 listcall
=> $data->{listcall
}
191 todaysdate
=> format_date
($todaysdate),
195 reserveloop
=> \
@reservedata,
196 "BiblioDefaultView".C4
::Context
->preference("BiblioDefaultView") => 1,
197 DHTMLcalendar_dateformat
=> C4
::Dates
->DHTMLcalendar(),
200 output_html_with_http_headers
$input, $cookie, $template->output;