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>.
35 my $itm = $input->param('itm');
36 my $biblionumber = $input->param('biblionumber');
38 my $biblio = Koha::Biblios->find( $biblionumber );
39 my $item = Koha::Items->find( $itm );
42 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
44 template_name => "circ/bookcount.tt",
47 flagsrequired => { circulate => "circulate_remaining_permissions" },
51 output_and_exit( $input, $cookie, $template, 'unknown_biblio')
53 output_and_exit( $input, $cookie, $template, 'unknown_item')
58 my $lastmove = lastmove($itm);
59 if ( not $lastmove ) {
60 $count = issuessince( $itm, 0 );
62 $lastdate = $lastmove->{'datearrived'};
63 $count = issuessince( $itm, $lastdate );
66 my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;
67 for my $library ( @$libraries ) {
68 $library->{selected} = 1 if $library->{branchcode} eq C4::Context->userenv->{branch};
69 $library->{issues} = issuesat($itm, $library->{branchcode});
70 $library->{seen} = lastseenat( $itm, $library->{branchcode} ) || undef;
74 biblionumber => $biblionumber,
75 title => $biblio->title,
76 author => $biblio->author,
77 barcode => $item->barcode,
78 homebranch => $item->homebranch,
79 holdingbranch => $item->holdingbranch,
80 lastdate => $lastdate ? $lastdate : 0,
82 libraries => $libraries,
85 output_html_with_http_headers $input, $cookie, $template->output;
89 my ($itemnumber) = @_;
90 my $dbh = C4::Context->dbh;
91 my $sth = $dbh->prepare(
92 "SELECT max(branchtransfers.datearrived) FROM branchtransfers WHERE branchtransfers.itemnumber=?"
94 $sth->execute($itemnumber);
95 my ($date) = $sth->fetchrow_array;
96 return 0 unless $date;
98 "SELECT * FROM branchtransfers WHERE branchtransfers.itemnumber=? and branchtransfers.datearrived=?"
100 $sth->execute( $itemnumber, $date );
101 my ($data) = $sth->fetchrow_hashref;
102 return 0 unless $data;
107 my ( $itemnumber, $date ) = @_;
108 my $dbh = C4::Context->dbh;
110 $dbh->prepare("SELECT SUM(count) FROM (
111 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? and timestamp > ?
113 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? and timestamp > ?
115 $sth->execute( $itemnumber, $date, $itemnumber, $date );
116 return $sth->fetchrow_arrayref->[0];
120 my ( $itemnumber, $brcd ) = @_;
121 my $dbh = C4::Context->dbh;
122 my $sth = $dbh->prepare(
123 "SELECT SUM(count) FROM (
124 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? AND branchcode = ?
126 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? AND branchcode = ?
129 $sth->execute( $itemnumber, $brcd, $itemnumber, $brcd );
130 return $sth->fetchrow_array;
134 my ( $itm, $brc ) = @_;
135 my $dbh = C4::Context->dbh;
136 my $sth = $dbh->prepare(
137 "SELECT MAX(tstamp) FROM (
138 SELECT MAX(timestamp) AS tstamp FROM issues WHERE itemnumber = ? AND branchcode = ?
140 SELECT MAX(timestamp) AS tstamp FROM old_issues WHERE itemnumber = ? AND branchcode = ?
143 $sth->execute( $itm, $brc, $itm, $brc );
144 my ($date1) = $sth->fetchrow_array;
145 $sth = $dbh->prepare(
146 "SELECT MAX(transfer) FROM (SELECT max(datearrived) AS transfer FROM branchtransfers WHERE itemnumber=? AND tobranch = ?
148 SELECT max(datesent) AS transfer FROM branchtransfers WHERE itemnumber=? AND frombranch = ?
151 $sth->execute( $itm, $brc, $itm, $brc );
152 my ($date2) = $sth->fetchrow_array;
154 my $date = ( $date1 lt $date2 ) ? $date2 : $date1 ;