4 #written 7/3/2002 by Finlay
5 #script to display reports
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
32 use C4::Branch; # GetBranches
33 use C4::Biblio; # GetBiblioItemData
34 use C4::Dates qw/format_date/;
37 my $itm = $input->param('itm');
38 my $bi = $input->param('bi');
39 my $biblionumber = $input->param('biblionumber');
40 my $branches = GetBranches;
42 my $idata = itemdatanum($itm);
43 my $data = GetBiblioItemData($bi);
45 my $homebranch = $branches->{ $idata->{'homebranch'} }->{'branchname'};
46 my $holdingbranch = $branches->{ $idata->{'holdingbranch'} }->{'branchname'};
48 my ( $lastmove, $message ) = lastmove($itm);
52 if ( not $lastmove ) {
53 # $lastdate = $message;
54 $count = issuessince( $itm, 0 );
57 $lastdate = $lastmove->{'datearrived'};
58 $count = issuessince( $itm, $lastdate );
63 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
65 template_name => "circ/bookcount.tmpl",
69 flagsrequired => { circulate => "circulate_remaining_permissions" },
76 foreach my $branchcode ( keys %$branches ) {
78 $linebranch{issues} = issuesat( $itm, $branchcode );
79 my $date = lastseenat( $itm, $branchcode );
80 $linebranch{seen} = slashdate($date);
81 $linebranch{branchname} = $branches->{$branchcode}->{'branchname'};
82 push( @branchloop, \%linebranch );
88 biblionumber => $biblionumber,
89 title => $data->{'title'},
90 author => $data->{'author'},
91 barcode => $idata->{'barcode'},
92 biblioitemnumber => $bi,
93 homebranch => $homebranch,
94 holdingbranch => $holdingbranch,
95 lastdate => $lastdate ? format_date($lastdate) : $message,
97 branchloop => \@branchloop,
100 output_html_with_http_headers $input, $cookie, $template->output;
104 my ($itemnumber) = @_;
105 my $dbh = C4::Context->dbh;
106 my $sth = $dbh->prepare("select * from items where itemnumber=?");
107 $sth->execute($itemnumber);
108 my $data = $sth->fetchrow_hashref;
114 my ($itemnumber) = @_;
115 my $dbh = C4::Context->dbh;
118 "select max(branchtransfers.datearrived) from branchtransfers where branchtransfers.itemnumber=?"
120 $sth->execute($itemnumber);
121 my ($date) = $sth->fetchrow_array;
122 return ( 0, "Item has no branch transfers record" ) if not $date;
125 "Select * from branchtransfers where branchtransfers.itemnumber=? and branchtransfers.datearrived=?"
127 $sth->execute( $itemnumber, $date );
128 my ($data) = $sth->fetchrow_hashref;
129 return ( 0, "Item has no branch transfers record" ) if not $data;
131 return ( $data, "" );
135 my ( $itemnumber, $date ) = @_;
136 my $dbh = C4::Context->dbh;
138 $dbh->prepare("SELECT SUM(count) FROM (
139 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? and timestamp > ?
141 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? and timestamp > ?
143 $sth->execute( $itemnumber, $date, $itemnumber, $date );
144 my $count = $sth->fetchrow_arrayref->[0];
150 my ( $itemnumber, $brcd ) = @_;
151 my $dbh = C4::Context->dbh;
153 $dbh->prepare("SELECT SUM(count) FROM (
154 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? and branchcode = ?
156 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? and branchcode = ?
158 $sth->execute( $itemnumber, $brcd, $itemnumber, $brcd );
159 my ($count) = $sth->fetchrow_array;
165 my ( $itm, $brc ) = @_;
166 my $dbh = C4::Context->dbh;
168 $dbh->prepare("SELECT MAX(tstamp) FROM (
169 SELECT MAX(timestamp) AS tstamp FROM issues WHERE itemnumber = ? and branchcode = ?
171 SELECT MAX(timestamp) AS tstamp FROM old_issues WHERE itemnumber = ? and branchcode = ?
173 $sth->execute( $itm, $brc, $itm, $brc );
174 my ($date1) = $sth->fetchrow_array;
178 "Select max(datearrived) from branchtransfers where itemnumber=? and tobranch = ?"
180 $sth->execute( $itm, $brc );
181 my ($date2) = $sth->fetchrow_array;
184 #FIXME: MJR thinks unsafe
192 if ( $date1 < $date2 ) {
201 #####################################################
208 my ( $yr, $mo, $da, $hr, $mi ) = (
209 substr( $date, 0, 4 ),
210 substr( $date, 4, 2 ),
211 substr( $date, 6, 2 ),
212 substr( $date, 8, 2 ),
213 substr( $date, 10, 2 )
215 return "$hr:$mi " . format_date("$yr-$mo-$da");