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>.
26 use C4::Output qw( output_and_exit output_html_with_http_headers );
27 use C4::Auth qw( get_template_and_user );
32 my $itm = $input->param('itm');
33 my $biblionumber = $input->param('biblionumber');
35 my $biblio = Koha::Biblios->find( $biblionumber );
36 my $item = Koha::Items->find( $itm );
39 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
41 template_name => "circ/bookcount.tt",
44 flagsrequired => { circulate => "circulate_remaining_permissions" },
48 output_and_exit( $input, $cookie, $template, 'unknown_biblio')
50 output_and_exit( $input, $cookie, $template, 'unknown_item')
55 my $lastmove = lastmove($itm);
56 if ( not $lastmove ) {
57 $count = issuessince( $itm, 0 );
59 $lastdate = $lastmove->{'datearrived'};
60 $count = issuessince( $itm, $lastdate );
63 my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;
64 for my $library ( @$libraries ) {
65 $library->{selected} = 1 if $library->{branchcode} eq C4::Context->userenv->{branch};
66 $library->{issues} = issuesat($itm, $library->{branchcode});
67 $library->{seen} = lastseenat( $itm, $library->{branchcode} ) || undef;
72 biblionumber => $biblionumber,
73 title => $biblio->title,
74 author => $biblio->author,
75 barcode => $item->barcode,
76 homebranch => $item->homebranch,
77 holdingbranch => $item->holdingbranch,
78 lastdate => $lastdate ? $lastdate : 0,
80 libraries => $libraries,
83 output_html_with_http_headers $input, $cookie, $template->output;
87 my ($itemnumber) = @_;
88 my $dbh = C4::Context->dbh;
89 my $sth = $dbh->prepare(
90 "SELECT max(branchtransfers.datearrived) FROM branchtransfers WHERE branchtransfers.itemnumber=?"
92 $sth->execute($itemnumber);
93 my ($date) = $sth->fetchrow_array;
94 return 0 unless $date;
96 "SELECT * FROM branchtransfers WHERE branchtransfers.itemnumber=? and branchtransfers.datearrived=?"
98 $sth->execute( $itemnumber, $date );
99 my ($data) = $sth->fetchrow_hashref;
100 return 0 unless $data;
105 my ( $itemnumber, $date ) = @_;
106 my $dbh = C4::Context->dbh;
108 $dbh->prepare("SELECT SUM(count) FROM (
109 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? and timestamp > ?
111 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? and timestamp > ?
113 $sth->execute( $itemnumber, $date, $itemnumber, $date );
114 return $sth->fetchrow_arrayref->[0];
118 my ( $itemnumber, $brcd ) = @_;
119 my $dbh = C4::Context->dbh;
120 my $sth = $dbh->prepare(
121 "SELECT SUM(count) FROM (
122 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? AND branchcode = ?
124 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? AND branchcode = ?
127 $sth->execute( $itemnumber, $brcd, $itemnumber, $brcd );
128 return $sth->fetchrow_array;
132 my ( $itm, $brc ) = @_;
133 my $dbh = C4::Context->dbh;
134 my $sth = $dbh->prepare(
135 "SELECT MAX(tstamp) FROM (
136 SELECT MAX(timestamp) AS tstamp FROM issues WHERE itemnumber = ? AND branchcode = ?
138 SELECT MAX(timestamp) AS tstamp FROM old_issues WHERE itemnumber = ? AND branchcode = ?
141 $sth->execute( $itm, $brc, $itm, $brc );
142 my ($date1) = $sth->fetchrow_array;
143 $sth = $dbh->prepare(
144 "SELECT MAX(transfer) FROM (SELECT max(datearrived) AS transfer FROM branchtransfers WHERE itemnumber=? AND tobranch = ?
146 SELECT max(datesent) AS transfer FROM branchtransfers WHERE itemnumber=? AND frombranch = ?
149 $sth->execute( $itm, $brc, $itm, $brc );
150 my ($date2) = $sth->fetchrow_array;
152 my $date = ( $date1 lt $date2 ) ? $date2 : $date1 ;