5 #written 7/3/2002 by Finlay
6 #script to display reports
9 # Copyright 2000-2002 Katipo Communications
11 # This file is part of Koha.
13 # Koha is free software; you can redistribute it and/or modify it under the
14 # terms of the GNU General Public License as published by the Free Software
15 # Foundation; either version 2 of the License, or (at your option) any later
18 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License along with
23 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
24 # Suite 330, Boston, MA 02111-1307 USA
30 use C4::Circulation::Circ2;
37 # get all the data ....
40 my $secondary='#ffffcc';
43 my $itm = $input->param('itm');
44 my $bi = $input->param('bi');
45 my $bib = $input->param('bib');
46 my $branches = getbranches(\%env);
48 my $idata = itemdatanum($itm);
49 my $data = bibitemdata($bi);
51 my $homebranch = $branches->{$idata->{'homebranch'}}->{'branchname'};
52 my $holdingbranch = $branches->{$idata->{'holdingbranch'}}->{'branchname'};
54 my ($lastmove, $message) = lastmove($itm);
60 $count = issuessince($itm , 0);
62 $lastdate = $lastmove->{'datearrived'};
63 $count = issuessince($itm ,$lastdate);
68 my ($template, $loggedinuser, $cookie)
69 = get_template_and_user({template_name => "bookcount.tmpl",
73 flagsrequired => {borrowers => 1},
81 foreach my $branchcode (keys %$branches) {
83 $linebranch{issues} = issuesat($itm, $branchcode);
84 my $date = lastseenat($itm, $branchcode);
85 $linebranch{seen} = slashdate($date);
86 $linebranch{branchname}=$branches->{$branchcode}->{'branchname'};
87 push(@branchloop,\%linebranch);
90 $template->param( bib => $bib,
91 title => $data->{'title'},
92 author => $data->{'author'},
93 barcode => $idata->{'barcode'},
94 homebranch =>$homebranch,
95 holdingbranch => $holdingbranch,
96 lastdate => format_date($lastdate),
98 branchloop => \@branchloop);
100 print "Content-Type: text/html\n\n", $template->output;
102 ##############################################
103 # This stuff should probably go into C4::Search
109 my $dbh = C4::Context->dbh;
110 my $sth=$dbh->prepare("select * from items where itemnumber=?");
111 $sth->execute($itemnumber);
112 my $data=$sth->fetchrow_hashref;
119 my $dbh = C4::Context->dbh;
120 my $sth =$dbh->prepare("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;
124 $sth=$dbh->prepare("Select * from branchtransfers where branchtransfers.itemnumber=? and branchtransfers.datearrived=?");
125 $sth->execute($itemnumber,$date);
126 my ($data) = $sth->fetchrow_hashref;
127 return(0, "Item has no branch transfers record") if not $data;
133 my ($itemnumber, $date)=@_;
134 my $dbh = C4::Context->dbh;
135 my $sth=$dbh->prepare("Select count(*) from issues where issues.itemnumber=? and issues.timestamp > ?");
136 $sth->execute($itemnumber,$date);
137 my $count=$sth->fetchrow_hashref;
139 return($count->{'count(*)'});
143 my ($itemnumber, $brcd)=@_;
144 my $dbh = C4::Context->dbh;
145 my $sth=$dbh->prepare("Select count(*) from issues where itemnumber=? and branchcode = ?");
146 $sth->execute($itemnumber,$brcd);
147 my ($count)=$sth->fetchrow_array;
154 my $dbh = C4::Context->dbh;
155 my $sth=$dbh->prepare("Select max(timestamp) from issues where itemnumber=? and branchcode = ?");
156 $sth->execute($itm,$brc);
157 my ($date1)=$sth->fetchrow_array;
159 $sth=$dbh->prepare("Select max(datearrived) from branchtransfers where itemnumber=? and tobranch = ?");
160 $sth->execute($itm,$brc);
161 my ($date2)=$sth->fetchrow_array;
163 #FIXME: MJR thinks unsafe
168 if ($date1 < $date2) {
177 #####################################################
184 my ($yr, $mo, $da, $hr, $mi) = (substr($date, 0, 4), substr($date, 4, 2), substr($date, 6, 2), substr($date, 8, 2), substr($date, 10, 2));
185 return "$hr:$mi " . format_date("$yr-$mo-$da");