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
36 my $itm = $input->param('itm');
37 my $bi = $input->param('bi');
38 my $biblionumber = $input->param('biblioitemnumber');
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;
136 "Select count(*) from issues where issues.itemnumber=? and issues.timestamp > ?"
138 $sth->execute( $itemnumber, $date );
139 my $count = $sth->fetchrow_hashref;
141 return ( $count->{'count(*)'} );
145 my ( $itemnumber, $brcd ) = @_;
146 my $dbh = C4::Context->dbh;
149 "Select count(*) from issues where itemnumber=? and branchcode = ?");
150 $sth->execute( $itemnumber, $brcd );
151 my ($count) = $sth->fetchrow_array;
157 my ( $itm, $brc ) = @_;
158 my $dbh = C4::Context->dbh;
161 "Select max(timestamp) from issues where itemnumber=? and branchcode = ?"
163 $sth->execute( $itm, $brc );
164 my ($date1) = $sth->fetchrow_array;
168 "Select max(datearrived) from branchtransfers where itemnumber=? and tobranch = ?"
170 $sth->execute( $itm, $brc );
171 my ($date2) = $sth->fetchrow_array;
174 #FIXME: MJR thinks unsafe
179 if ( $date1 < $date2 ) {
188 #####################################################
195 my ( $yr, $mo, $da, $hr, $mi ) = (
196 substr( $date, 0, 4 ),
197 substr( $date, 4, 2 ),
198 substr( $date, 6, 2 ),
199 substr( $date, 8, 2 ),
200 substr( $date, 10, 2 )
202 return "$hr:$mi " . format_date("$yr-$mo-$da");