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,
95 intranetcolorstylesheet =>
96 C4::Context->preference("intranetcolorstylesheet"),
97 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
98 IntranetNav => C4::Context->preference("IntranetNav"),
101 output_html_with_http_headers $input, $cookie, $template->output;
105 my ($itemnumber) = @_;
106 my $dbh = C4::Context->dbh;
107 my $sth = $dbh->prepare("select * from items where itemnumber=?");
108 $sth->execute($itemnumber);
109 my $data = $sth->fetchrow_hashref;
115 my ($itemnumber) = @_;
116 my $dbh = C4::Context->dbh;
119 "select max(branchtransfers.datearrived) from branchtransfers where branchtransfers.itemnumber=?"
121 $sth->execute($itemnumber);
122 my ($date) = $sth->fetchrow_array;
123 return ( 0, "Item has no branch transfers record" ) if not $date;
126 "Select * from branchtransfers where branchtransfers.itemnumber=? and branchtransfers.datearrived=?"
128 $sth->execute( $itemnumber, $date );
129 my ($data) = $sth->fetchrow_hashref;
130 return ( 0, "Item has no branch transfers record" ) if not $data;
132 return ( $data, "" );
136 my ( $itemnumber, $date ) = @_;
137 my $dbh = C4::Context->dbh;
140 "Select count(*) from issues where issues.itemnumber=? and issues.timestamp > ?"
142 $sth->execute( $itemnumber, $date );
143 my $count = $sth->fetchrow_hashref;
145 return ( $count->{'count(*)'} );
149 my ( $itemnumber, $brcd ) = @_;
150 my $dbh = C4::Context->dbh;
153 "Select count(*) from issues where itemnumber=? and branchcode = ?");
154 $sth->execute( $itemnumber, $brcd );
155 my ($count) = $sth->fetchrow_array;
161 my ( $itm, $brc ) = @_;
162 my $dbh = C4::Context->dbh;
165 "Select max(timestamp) from issues where itemnumber=? and branchcode = ?"
167 $sth->execute( $itm, $brc );
168 my ($date1) = $sth->fetchrow_array;
172 "Select max(datearrived) from branchtransfers where itemnumber=? and tobranch = ?"
174 $sth->execute( $itm, $brc );
175 my ($date2) = $sth->fetchrow_array;
178 #FIXME: MJR thinks unsafe
183 if ( $date1 < $date2 ) {
192 #####################################################
199 my ( $yr, $mo, $da, $hr, $mi ) = (
200 substr( $date, 0, 4 ),
201 substr( $date, 4, 2 ),
202 substr( $date, 6, 2 ),
203 substr( $date, 8, 2 ),
204 substr( $date, 10, 2 )
206 return "$hr:$mi " . format_date("$yr-$mo-$da");