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
38 my $itm = $input->param('itm');
39 my $bi = $input->param('bi');
40 my $biblionumber = $input->param('biblionumber');
41 my $branches = GetBranches;
43 my $idata = itemdatanum($itm);
44 my $data = GetBiblioItemData($bi);
46 my $homebranch = $branches->{ $idata->{'homebranch'} }->{'branchname'};
47 my $holdingbranch = $branches->{ $idata->{'holdingbranch'} }->{'branchname'};
49 my $lastmove = lastmove($itm);
53 if ( not $lastmove ) {
54 $count = issuessince( $itm, 0 );
56 $lastdate = $lastmove->{'datearrived'};
57 $count = issuessince( $itm, $lastdate );
62 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
64 template_name => "circ/bookcount.tt",
68 flagsrequired => { circulate => "circulate_remaining_permissions" },
73 my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;
74 for my $library ( @$libraries ) {
75 $library->{selected} = 1 if $library->{branchcode} eq C4::Context->userenv->{branch};
76 $library->{issues} = issuesat($itm, $library->{branchcode});
77 $library->{seen} = lastseenat( $itm, $library->{branchcode} ) || undef;
81 biblionumber => $biblionumber,
82 title => $data->{'title'},
83 author => $data->{'author'},
84 barcode => $idata->{'barcode'},
85 biblioitemnumber => $bi,
86 homebranch => $homebranch,
87 holdingbranch => $holdingbranch,
88 lastdate => $lastdate ? $lastdate : 0,
90 libraries => $libraries,
93 output_html_with_http_headers $input, $cookie, $template->output;
97 my ($itemnumber) = @_;
98 my $sth = C4::Context->dbh->prepare("SELECT * FROM items WHERE itemnumber=?");
99 $sth->execute($itemnumber);
100 return $sth->fetchrow_hashref;
104 my ($itemnumber) = @_;
105 my $dbh = C4::Context->dbh;
106 my $sth = $dbh->prepare(
107 "SELECT max(branchtransfers.datearrived) FROM branchtransfers WHERE branchtransfers.itemnumber=?"
109 $sth->execute($itemnumber);
110 my ($date) = $sth->fetchrow_array;
111 return 0 unless $date;
112 $sth = $dbh->prepare(
113 "SELECT * FROM branchtransfers WHERE branchtransfers.itemnumber=? and branchtransfers.datearrived=?"
115 $sth->execute( $itemnumber, $date );
116 my ($data) = $sth->fetchrow_hashref;
117 return 0 unless $data;
122 my ( $itemnumber, $date ) = @_;
123 my $dbh = C4::Context->dbh;
125 $dbh->prepare("SELECT SUM(count) FROM (
126 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? and timestamp > ?
128 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? and timestamp > ?
130 $sth->execute( $itemnumber, $date, $itemnumber, $date );
131 return $sth->fetchrow_arrayref->[0];
135 my ( $itemnumber, $brcd ) = @_;
136 my $dbh = C4::Context->dbh;
137 my $sth = $dbh->prepare(
138 "SELECT SUM(count) FROM (
139 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? AND branchcode = ?
141 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? AND branchcode = ?
144 $sth->execute( $itemnumber, $brcd, $itemnumber, $brcd );
145 return $sth->fetchrow_array;
149 my ( $itm, $brc ) = @_;
150 my $dbh = C4::Context->dbh;
151 my $sth = $dbh->prepare(
152 "SELECT MAX(tstamp) FROM (
153 SELECT MAX(timestamp) AS tstamp FROM issues WHERE itemnumber = ? AND branchcode = ?
155 SELECT MAX(timestamp) AS tstamp FROM old_issues WHERE itemnumber = ? AND branchcode = ?
158 $sth->execute( $itm, $brc, $itm, $brc );
159 my ($date1) = $sth->fetchrow_array;
160 $sth = $dbh->prepare(
161 "SELECT MAX(transfer) FROM (SELECT max(datearrived) AS transfer FROM branchtransfers WHERE itemnumber=? AND tobranch = ?
163 SELECT max(datesent) AS transfer FROM branchtransfers WHERE itemnumber=? AND frombranch = ?
166 $sth->execute( $itm, $brc, $itm, $brc );
167 my ($date2) = $sth->fetchrow_array;
169 my $date = ( $date1 lt $date2 ) ? $date2 : $date1 ;