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
31 use C4
::Branch
; # GetBranches
32 use C4
::Biblio
; # GetBiblioItemData
33 use C4
::Dates qw
/format_date/;
36 my $itm = $input->param('itm');
37 my $bi = $input->param('bi');
38 my $biblionumber = $input->param('biblionumber');
39 my $branches = GetBranches
;
41 my $idata = itemdatanum
($itm);
42 my $data = GetBiblioItemData
($bi);
44 my $homebranch = $branches->{ $idata->{'homebranch'} }->{'branchname'};
45 my $holdingbranch = $branches->{ $idata->{'holdingbranch'} }->{'branchname'};
47 my ( $lastmove, $message ) = lastmove
($itm);
51 if ( not $lastmove ) {
53 $count = issuessince
( $itm, 0 );
56 $lastdate = $lastmove->{'datearrived'};
57 $count = issuessince
( $itm, $lastdate );
62 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
64 template_name
=> "circ/bookcount.tmpl",
68 flagsrequired
=> { circulate
=> 1 },
75 foreach my $branchcode ( keys %$branches ) {
77 $linebranch{issues
} = issuesat
( $itm, $branchcode );
78 my $date = lastseenat
( $itm, $branchcode );
79 $linebranch{seen
} = slashdate
($date);
80 $linebranch{branchname
} = $branches->{$branchcode}->{'branchname'};
81 push( @branchloop, \
%linebranch );
85 biblionumber
=> $biblionumber,
86 title
=> $data->{'title'},
87 author
=> $data->{'author'},
88 barcode
=> $idata->{'barcode'},
89 biblioitemnumber
=> $bi,
90 homebranch
=> $homebranch,
91 holdingbranch
=> $holdingbranch,
92 lastdate
=> format_date
($lastdate),
94 branchloop
=> \
@branchloop,
97 output_html_with_http_headers
$input, $cookie, $template->output;
101 my ($itemnumber) = @_;
102 my $dbh = C4
::Context
->dbh;
103 my $sth = $dbh->prepare("select * from items where itemnumber=?");
104 $sth->execute($itemnumber);
105 my $data = $sth->fetchrow_hashref;
111 my ($itemnumber) = @_;
112 my $dbh = C4
::Context
->dbh;
115 "select max(branchtransfers.datearrived) from branchtransfers where branchtransfers.itemnumber=?"
117 $sth->execute($itemnumber);
118 my ($date) = $sth->fetchrow_array;
119 return ( 0, "Item has no branch transfers record" ) if not $date;
122 "Select * from branchtransfers where branchtransfers.itemnumber=? and branchtransfers.datearrived=?"
124 $sth->execute( $itemnumber, $date );
125 my ($data) = $sth->fetchrow_hashref;
126 return ( 0, "Item has no branch transfers record" ) if not $data;
128 return ( $data, "" );
132 my ( $itemnumber, $date ) = @_;
133 my $dbh = C4
::Context
->dbh;
135 $dbh->prepare("SELECT SUM(count) FROM (
136 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? and timestamp > ?
138 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? and timestamp > ?
140 $sth->execute( $itemnumber, $date, $itemnumber, $date );
141 my $count = $sth->fetchrow_arrayref->[0];
147 my ( $itemnumber, $brcd ) = @_;
148 my $dbh = C4
::Context
->dbh;
150 $dbh->prepare("SELECT SUM(count) FROM (
151 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? and branchcode = ?
153 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? and branchcode = ?
155 $sth->execute( $itemnumber, $brcd, $itemnumber, $brcd );
156 my ($count) = $sth->fetchrow_array;
162 my ( $itm, $brc ) = @_;
163 my $dbh = C4
::Context
->dbh;
165 $dbh->prepare("SELECT MAX(tstamp) FROM (
166 SELECT MAX(timestamp) AS tstamp FROM issues WHERE itemnumber = ? and branchcode = ?
168 SELECT MAX(timestamp) AS tstamp FROM old_issues WHERE itemnumber = ? and branchcode = ?
170 $sth->execute( $itm, $brc, $itm, $brc );
171 my ($date1) = $sth->fetchrow_array;
175 "Select max(datearrived) from branchtransfers where itemnumber=? and tobranch = ?"
177 $sth->execute( $itm, $brc );
178 my ($date2) = $sth->fetchrow_array;
181 #FIXME: MJR thinks unsafe
189 if ( $date1 < $date2 ) {
198 #####################################################
205 my ( $yr, $mo, $da, $hr, $mi ) = (
206 substr( $date, 0, 4 ),
207 substr( $date, 4, 2 ),
208 substr( $date, 6, 2 ),
209 substr( $date, 8, 2 ),
210 substr( $date, 10, 2 )
212 return "$hr:$mi " . format_date
("$yr-$mo-$da");