3 #written 7/3/2002 by Finlay
4 #script to display reports
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 #use warnings; FIXME - Bug 2505
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('biblionumber');
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 = lastmove
($itm);
52 if ( not $lastmove ) {
53 $count = issuessince
( $itm, 0 );
55 $lastdate = $lastmove->{'datearrived'};
56 $count = issuessince
( $itm, $lastdate );
61 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
63 template_name
=> "circ/bookcount.tt",
67 flagsrequired
=> { circulate
=> "circulate_remaining_permissions" },
72 my $branchloop = GetBranchesLoop
(C4
::Context
->userenv->{branch
});
73 foreach (@
$branchloop) {
74 $_->{issues
} = issuesat
($itm, $_->{value
});
75 $_->{seen
} = lastseenat
( $itm, $_->{value
} ) || undef;
79 biblionumber
=> $biblionumber,
80 title
=> $data->{'title'},
81 author
=> $data->{'author'},
82 barcode
=> $idata->{'barcode'},
83 biblioitemnumber
=> $bi,
84 homebranch
=> $homebranch,
85 holdingbranch
=> $holdingbranch,
86 lastdate
=> $lastdate ?
$lastdate : 0,
88 branchloop
=> $branchloop,
91 output_html_with_http_headers
$input, $cookie, $template->output;
95 my ($itemnumber) = @_;
96 my $sth = C4
::Context
->dbh->prepare("SELECT * FROM items WHERE itemnumber=?");
97 $sth->execute($itemnumber);
98 return $sth->fetchrow_hashref;
102 my ($itemnumber) = @_;
103 my $dbh = C4
::Context
->dbh;
104 my $sth = $dbh->prepare(
105 "SELECT max(branchtransfers.datearrived) FROM branchtransfers WHERE branchtransfers.itemnumber=?"
107 $sth->execute($itemnumber);
108 my ($date) = $sth->fetchrow_array;
109 return 0 unless $date;
110 $sth = $dbh->prepare(
111 "SELECT * FROM branchtransfers WHERE branchtransfers.itemnumber=? and branchtransfers.datearrived=?"
113 $sth->execute( $itemnumber, $date );
114 my ($data) = $sth->fetchrow_hashref;
115 return 0 unless $data;
120 my ( $itemnumber, $date ) = @_;
121 my $dbh = C4
::Context
->dbh;
123 $dbh->prepare("SELECT SUM(count) FROM (
124 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? and timestamp > ?
126 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? and timestamp > ?
128 $sth->execute( $itemnumber, $date, $itemnumber, $date );
129 return $sth->fetchrow_arrayref->[0];
133 my ( $itemnumber, $brcd ) = @_;
134 my $dbh = C4
::Context
->dbh;
135 my $sth = $dbh->prepare(
136 "SELECT SUM(count) FROM (
137 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? AND branchcode = ?
139 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? AND branchcode = ?
142 $sth->execute( $itemnumber, $brcd, $itemnumber, $brcd );
143 return $sth->fetchrow_array;
147 my ( $itm, $brc ) = @_;
148 my $dbh = C4
::Context
->dbh;
149 my $sth = $dbh->prepare(
150 "SELECT MAX(tstamp) FROM (
151 SELECT MAX(timestamp) AS tstamp FROM issues WHERE itemnumber = ? AND branchcode = ?
153 SELECT MAX(timestamp) AS tstamp FROM old_issues WHERE itemnumber = ? AND branchcode = ?
156 $sth->execute( $itm, $brc, $itm, $brc );
157 my ($date1) = $sth->fetchrow_array;
158 $sth = $dbh->prepare(
159 "SELECT MAX(transfer) FROM (SELECT max(datearrived) AS transfer FROM branchtransfers WHERE itemnumber=? AND tobranch = ?
161 SELECT max(datesent) AS transfer FROM branchtransfers WHERE itemnumber=? AND frombranch = ?
164 $sth->execute( $itm, $brc, $itm, $brc );
165 my ($date2) = $sth->fetchrow_array;
167 my $date = ( $date1 lt $date2 ) ?
$date2 : $date1 ;