5 #written 7/3/2002 by Finlay
6 #script to display reports
8 # Copyright 2000-2002 Katipo Communications
10 # This file is part of Koha.
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA 02111-1307 USA
28 use C4::Circulation::Circ2;
32 use C4::Branch; # GetBranches
33 use C4::Biblio; # GetBiblioItemData
37 my $itm = $input->param('itm');
38 my $bi = $input->param('bi');
39 my $biblionumber = $input->param('biblioitemnumber');
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 ) {
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 => 1 },
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 );
86 biblionumber => $biblionumber,
87 title => $data->{'title'},
88 author => $data->{'author'},
89 barcode => $idata->{'barcode'},
90 biblioitemnumber => $bi,
91 homebranch => $homebranch,
92 holdingbranch => $holdingbranch,
93 lastdate => format_date($lastdate),
95 branchloop => \@branchloop,
96 intranetcolorstylesheet =>
97 C4::Context->preference("intranetcolorstylesheet"),
98 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
99 IntranetNav => C4::Context->preference("IntranetNav"),
102 output_html_with_http_headers $input, $cookie, $template->output;
106 my ($itemnumber) = @_;
107 my $dbh = C4::Context->dbh;
108 my $sth = $dbh->prepare("select * from items where itemnumber=?");
109 $sth->execute($itemnumber);
110 my $data = $sth->fetchrow_hashref;
116 my ($itemnumber) = @_;
117 my $dbh = C4::Context->dbh;
120 "select max(branchtransfers.datearrived) from branchtransfers where branchtransfers.itemnumber=?"
122 $sth->execute($itemnumber);
123 my ($date) = $sth->fetchrow_array;
124 return ( 0, "Item has no branch transfers record" ) if not $date;
127 "Select * from branchtransfers where branchtransfers.itemnumber=? and branchtransfers.datearrived=?"
129 $sth->execute( $itemnumber, $date );
130 my ($data) = $sth->fetchrow_hashref;
131 return ( 0, "Item has no branch transfers record" ) if not $data;
133 return ( $data, "" );
137 my ( $itemnumber, $date ) = @_;
138 my $dbh = C4::Context->dbh;
141 "Select count(*) from issues where issues.itemnumber=? and issues.timestamp > ?"
143 $sth->execute( $itemnumber, $date );
144 my $count = $sth->fetchrow_hashref;
146 return ( $count->{'count(*)'} );
150 my ( $itemnumber, $brcd ) = @_;
151 my $dbh = C4::Context->dbh;
154 "Select count(*) from issues where itemnumber=? and branchcode = ?");
155 $sth->execute( $itemnumber, $brcd );
156 my ($count) = $sth->fetchrow_array;
162 my ( $itm, $brc ) = @_;
163 my $dbh = C4::Context->dbh;
166 "Select max(timestamp) from issues where itemnumber=? and branchcode = ?"
168 $sth->execute( $itm, $brc );
169 my ($date1) = $sth->fetchrow_array;
173 "Select max(datearrived) from branchtransfers where itemnumber=? and tobranch = ?"
175 $sth->execute( $itm, $brc );
176 my ($date2) = $sth->fetchrow_array;
179 #FIXME: MJR thinks unsafe
184 if ( $date1 < $date2 ) {
193 #####################################################
200 my ( $yr, $mo, $da, $hr, $mi ) = (
201 substr( $date, 0, 4 ),
202 substr( $date, 4, 2 ),
203 substr( $date, 6, 2 ),
204 substr( $date, 8, 2 ),
205 substr( $date, 10, 2 )
207 return "$hr:$mi " . format_date("$yr-$mo-$da");