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;
34 # get all the data ....
37 my $secondary='#ffffcc';
40 my $itm = $input->param('itm');
41 my $bi = $input->param('bi');
42 my $bib = $input->param('bib');
43 my $branches = getbranches(\%env);
45 my $idata = itemdatanum($itm);
46 my $data = bibitemdata($bi);
48 my $homebranch = $branches->{$idata->{'homebranch'}}->{'branchname'};
49 my $holdingbranch = $branches->{$idata->{'holdingbranch'}}->{'branchname'};
51 my ($lastmove, $message) = lastmove($itm);
57 $count = issuessince($itm , 0);
59 $lastdate = $lastmove->{'datearrived'};
60 $count = issuessince($itm ,$lastdate);
64 my $template = gettemplate("bookcount.tmpl");
68 foreach my $branchcode (keys %$branches) {
70 $linebranch{issues} = issuesat($itm, $branchcode);
71 my $date = lastseenat($itm, $branchcode);
72 $linebranch{seen} = slashdate($date);
73 $linebranch{branchname}=$branches->{$branchcode}->{'branchname'};
74 push(@branchloop,\%linebranch);
77 $template->param( bib => $bib,
78 title => $data->{'title'},
79 author => $data->{'author'},
80 barcode => $idata->{'barcode'},
81 homebranch =>$homebranch,
82 holdingbranch => $holdingbranch,
83 lastdate => $lastdate,
85 branchloop => \@branchloop);
87 print "Content-Type: text/html\n\n", $template->output;
89 ##############################################
90 # This stuff should probably go into C4::Search
96 my $dbh = C4::Context->dbh;
97 my $itm = $dbh->quote("$itemnumber");
98 my $query = "select * from items where itemnumber=$itm";
99 my $sth=$dbh->prepare($query);
101 my $data=$sth->fetchrow_hashref;
108 my $dbh = C4::Context->dbh;
109 my $var1 = $dbh->quote($itemnumber);
110 my $sth =$dbh->prepare("select max(branchtransfers.datearrived) from branchtransfers where branchtransfers.itemnumber=$var1");
112 my ($date) = $sth->fetchrow_array;
113 return(0, "Item has no branch transfers record") if not $date;
114 my $var2 = $dbh->quote($date);
115 $sth=$dbh->prepare("Select * from branchtransfers where branchtransfers.itemnumber=$var1 and branchtransfers.datearrived=$var2");
117 my ($data) = $sth->fetchrow_hashref;
118 return(0, "Item has no branch transfers record") if not $data;
124 my ($itemnumber, $date)=@_;
125 my $dbh = C4::Context->dbh;
126 my $itm = $dbh->quote($itemnumber);
127 my $dat = $dbh->quote($date);
128 my $sth=$dbh->prepare("Select count(*) from issues where issues.itemnumber=$itm and issues.timestamp > $dat");
130 my $count=$sth->fetchrow_hashref;
132 return($count->{'count(*)'});
136 my ($itemnumber, $brcd)=@_;
137 my $dbh = C4::Context->dbh;
138 my $itm = $dbh->quote($itemnumber);
139 my $brc = $dbh->quote($brcd);
140 my $query = "Select count(*) from issues where itemnumber=$itm and branchcode = $brc";
141 my $sth=$dbh->prepare($query);
143 my ($count)=$sth->fetchrow_array;
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 max(timestamp) from issues where itemnumber=$itm and branchcode = $brc";
154 my $sth=$dbh->prepare($query);
156 my ($date1)=$sth->fetchrow_array;
158 $query = "Select max(datearrived) from branchtransfers where itemnumber=$itm and tobranch = $brc";
159 # FIXME - There's already a $sth in this scope.
160 my $sth=$dbh->prepare($query);
162 my ($date2)=$sth->fetchrow_array;
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 $da/$mo/$yr";