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;
71 biblionumber => $biblionumber,
72 title => $biblio->title,
73 author => $biblio->author,
74 barcode => $item->barcode,
75 homebranch => $item->homebranch,
76 holdingbranch => $item->holdingbranch,
77 lastdate => $lastdate ? $lastdate : 0,
79 libraries => $libraries,
82 output_html_with_http_headers $input, $cookie, $template->output;
86 my ($itemnumber) = @_;
87 my $dbh = C4::Context->dbh;
88 my $sth = $dbh->prepare(
89 "SELECT max(branchtransfers.datearrived) FROM branchtransfers WHERE branchtransfers.itemnumber=?"
91 $sth->execute($itemnumber);
92 my ($date) = $sth->fetchrow_array;
93 return 0 unless $date;
95 "SELECT * FROM branchtransfers WHERE branchtransfers.itemnumber=? and branchtransfers.datearrived=?"
97 $sth->execute( $itemnumber, $date );
98 my ($data) = $sth->fetchrow_hashref;
99 return 0 unless $data;
104 my ( $itemnumber, $date ) = @_;
105 my $dbh = C4::Context->dbh;
107 $dbh->prepare("SELECT SUM(count) FROM (
108 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? and timestamp > ?
110 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? and timestamp > ?
112 $sth->execute( $itemnumber, $date, $itemnumber, $date );
113 return $sth->fetchrow_arrayref->[0];
117 my ( $itemnumber, $brcd ) = @_;
118 my $dbh = C4::Context->dbh;
119 my $sth = $dbh->prepare(
120 "SELECT SUM(count) FROM (
121 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? AND branchcode = ?
123 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? AND branchcode = ?
126 $sth->execute( $itemnumber, $brcd, $itemnumber, $brcd );
127 return $sth->fetchrow_array;
131 my ( $itm, $brc ) = @_;
132 my $dbh = C4::Context->dbh;
133 my $sth = $dbh->prepare(
134 "SELECT MAX(tstamp) FROM (
135 SELECT MAX(timestamp) AS tstamp FROM issues WHERE itemnumber = ? AND branchcode = ?
137 SELECT MAX(timestamp) AS tstamp FROM old_issues WHERE itemnumber = ? AND branchcode = ?
140 $sth->execute( $itm, $brc, $itm, $brc );
141 my ($date1) = $sth->fetchrow_array;
142 $sth = $dbh->prepare(
143 "SELECT MAX(transfer) FROM (SELECT max(datearrived) AS transfer FROM branchtransfers WHERE itemnumber=? AND tobranch = ?
145 SELECT max(datesent) AS transfer FROM branchtransfers WHERE itemnumber=? AND frombranch = ?
148 $sth->execute( $itm, $brc, $itm, $brc );
149 my ($date2) = $sth->fetchrow_array;
151 my $date = ( $date1 lt $date2 ) ? $date2 : $date1 ;