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 $itm = $dbh->quote("$itemnumber");
111 my $query = "select * from items where itemnumber=$itm";
112 my $sth=$dbh->prepare($query);
114 my $data=$sth->fetchrow_hashref;
121 my $dbh = C4::Context->dbh;
122 my $var1 = $dbh->quote($itemnumber);
123 my $sth =$dbh->prepare("select max(branchtransfers.datearrived) from branchtransfers where branchtransfers.itemnumber=$var1");
125 my ($date) = $sth->fetchrow_array;
126 return(0, "Item has no branch transfers record") if not $date;
127 my $var2 = $dbh->quote($date);
128 $sth=$dbh->prepare("Select * from branchtransfers where branchtransfers.itemnumber=$var1 and branchtransfers.datearrived=$var2");
130 my ($data) = $sth->fetchrow_hashref;
131 return(0, "Item has no branch transfers record") if not $data;
137 my ($itemnumber, $date)=@_;
138 my $dbh = C4::Context->dbh;
139 my $itm = $dbh->quote($itemnumber);
140 my $dat = $dbh->quote($date);
141 my $sth=$dbh->prepare("Select count(*) from issues where issues.itemnumber=$itm and issues.timestamp > $dat");
143 my $count=$sth->fetchrow_hashref;
145 return($count->{'count(*)'});
149 my ($itemnumber, $brcd)=@_;
150 my $dbh = C4::Context->dbh;
151 my $itm = $dbh->quote($itemnumber);
152 my $brc = $dbh->quote($brcd);
153 my $query = "Select count(*) from issues where itemnumber=$itm and branchcode = $brc";
154 my $sth=$dbh->prepare($query);
156 my ($count)=$sth->fetchrow_array;
162 my ($itemnumber, $brcd)=@_;
163 my $dbh = C4::Context->dbh;
164 my $itm = $dbh->quote($itemnumber);
165 my $brc = $dbh->quote($brcd);
166 my $query = "Select max(timestamp) from issues where itemnumber=$itm and branchcode = $brc";
167 my $sth=$dbh->prepare($query);
169 my ($date1)=$sth->fetchrow_array;
171 $query = "Select max(datearrived) from branchtransfers where itemnumber=$itm and tobranch = $brc";
172 # FIXME - There's already a $sth in this scope.
173 my $sth=$dbh->prepare($query);
175 my ($date2)=$sth->fetchrow_array;
181 if ($date1 < $date2) {
190 #####################################################
197 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));
198 return "$hr:$mi " . format_date("$yr-$mo-$da");