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;
36 # get all the data ....
39 my $secondary='#ffffcc';
42 my $itm = $input->param('itm');
43 my $bi = $input->param('bi');
44 my $bib = $input->param('bib');
45 my $branches = getbranches(\%env);
47 my $idata = itemdatanum($itm);
48 my $data = bibitemdata($bi);
50 my $homebranch = $branches->{$idata->{'homebranch'}}->{'branchname'};
51 my $holdingbranch = $branches->{$idata->{'holdingbranch'}}->{'branchname'};
53 my ($lastmove, $message) = lastmove($itm);
59 $count = issuessince($itm , 0);
61 $lastdate = $lastmove->{'datearrived'};
62 $count = issuessince($itm ,$lastdate);
67 my ($template, $loggedinuser, $cookie)
68 = get_template_and_user({template_name => "bookcount.tmpl",
72 flagsrequired => {borrowers => 1},
80 foreach my $branchcode (keys %$branches) {
82 $linebranch{issues} = issuesat($itm, $branchcode);
83 my $date = lastseenat($itm, $branchcode);
84 $linebranch{seen} = slashdate($date);
85 $linebranch{branchname}=$branches->{$branchcode}->{'branchname'};
86 push(@branchloop,\%linebranch);
89 $template->param( bib => $bib,
90 title => $data->{'title'},
91 author => $data->{'author'},
92 barcode => $idata->{'barcode'},
93 homebranch =>$homebranch,
94 holdingbranch => $holdingbranch,
95 lastdate => $lastdate,
97 branchloop => \@branchloop);
99 print "Content-Type: text/html\n\n", $template->output;
101 ##############################################
102 # This stuff should probably go into C4::Search
108 my $dbh = C4::Context->dbh;
109 my $itm = $dbh->quote("$itemnumber");
110 my $query = "select * from items where itemnumber=$itm";
111 my $sth=$dbh->prepare($query);
113 my $data=$sth->fetchrow_hashref;
120 my $dbh = C4::Context->dbh;
121 my $var1 = $dbh->quote($itemnumber);
122 my $sth =$dbh->prepare("select max(branchtransfers.datearrived) from branchtransfers where branchtransfers.itemnumber=$var1");
124 my ($date) = $sth->fetchrow_array;
125 return(0, "Item has no branch transfers record") if not $date;
126 my $var2 = $dbh->quote($date);
127 $sth=$dbh->prepare("Select * from branchtransfers where branchtransfers.itemnumber=$var1 and branchtransfers.datearrived=$var2");
129 my ($data) = $sth->fetchrow_hashref;
130 return(0, "Item has no branch transfers record") if not $data;
136 my ($itemnumber, $date)=@_;
137 my $dbh = C4::Context->dbh;
138 my $itm = $dbh->quote($itemnumber);
139 my $dat = $dbh->quote($date);
140 my $sth=$dbh->prepare("Select count(*) from issues where issues.itemnumber=$itm and issues.timestamp > $dat");
142 my $count=$sth->fetchrow_hashref;
144 return($count->{'count(*)'});
148 my ($itemnumber, $brcd)=@_;
149 my $dbh = C4::Context->dbh;
150 my $itm = $dbh->quote($itemnumber);
151 my $brc = $dbh->quote($brcd);
152 my $query = "Select count(*) from issues where itemnumber=$itm and branchcode = $brc";
153 my $sth=$dbh->prepare($query);
155 my ($count)=$sth->fetchrow_array;
161 my ($itemnumber, $brcd)=@_;
162 my $dbh = C4::Context->dbh;
163 my $itm = $dbh->quote($itemnumber);
164 my $brc = $dbh->quote($brcd);
165 my $query = "Select max(timestamp) from issues where itemnumber=$itm and branchcode = $brc";
166 my $sth=$dbh->prepare($query);
168 my ($date1)=$sth->fetchrow_array;
170 $query = "Select max(datearrived) from branchtransfers where itemnumber=$itm and tobranch = $brc";
171 # FIXME - There's already a $sth in this scope.
172 my $sth=$dbh->prepare($query);
174 my ($date2)=$sth->fetchrow_array;
180 if ($date1 < $date2) {
189 #####################################################
196 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));
197 return "$hr:$mi $da/$mo/$yr";