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>.
36 my $itm = $input->param('itm');
37 my $biblionumber = $input->param('biblionumber');
39 my $biblio = Koha::Biblios->find( $biblionumber );
40 my $item = Koha::Items->find( $itm );
43 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
45 template_name => "circ/bookcount.tt",
49 flagsrequired => { circulate => "circulate_remaining_permissions" },
54 output_and_exit( $input, $cookie, $template, 'unknown_biblio')
56 output_and_exit( $input, $cookie, $template, 'unknown_item')
61 my $lastmove = lastmove($itm);
62 if ( not $lastmove ) {
63 $count = issuessince( $itm, 0 );
65 $lastdate = $lastmove->{'datearrived'};
66 $count = issuessince( $itm, $lastdate );
69 my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;
70 for my $library ( @$libraries ) {
71 $library->{selected} = 1 if $library->{branchcode} eq C4::Context->userenv->{branch};
72 $library->{issues} = issuesat($itm, $library->{branchcode});
73 $library->{seen} = lastseenat( $itm, $library->{branchcode} ) || undef;
77 biblionumber => $biblionumber,
78 title => $biblio->title,
79 author => $biblio->author,
80 barcode => $item->barcode,
81 homebranch => $item->homebranch,
82 holdingbranch => $item->holdingbranch,
83 lastdate => $lastdate ? $lastdate : 0,
85 libraries => $libraries,
88 output_html_with_http_headers $input, $cookie, $template->output;
92 my ($itemnumber) = @_;
93 my $dbh = C4::Context->dbh;
94 my $sth = $dbh->prepare(
95 "SELECT max(branchtransfers.datearrived) FROM branchtransfers WHERE branchtransfers.itemnumber=?"
97 $sth->execute($itemnumber);
98 my ($date) = $sth->fetchrow_array;
99 return 0 unless $date;
100 $sth = $dbh->prepare(
101 "SELECT * FROM branchtransfers WHERE branchtransfers.itemnumber=? and branchtransfers.datearrived=?"
103 $sth->execute( $itemnumber, $date );
104 my ($data) = $sth->fetchrow_hashref;
105 return 0 unless $data;
110 my ( $itemnumber, $date ) = @_;
111 my $dbh = C4::Context->dbh;
113 $dbh->prepare("SELECT SUM(count) FROM (
114 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? and timestamp > ?
116 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? and timestamp > ?
118 $sth->execute( $itemnumber, $date, $itemnumber, $date );
119 return $sth->fetchrow_arrayref->[0];
123 my ( $itemnumber, $brcd ) = @_;
124 my $dbh = C4::Context->dbh;
125 my $sth = $dbh->prepare(
126 "SELECT SUM(count) FROM (
127 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? AND branchcode = ?
129 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? AND branchcode = ?
132 $sth->execute( $itemnumber, $brcd, $itemnumber, $brcd );
133 return $sth->fetchrow_array;
137 my ( $itm, $brc ) = @_;
138 my $dbh = C4::Context->dbh;
139 my $sth = $dbh->prepare(
140 "SELECT MAX(tstamp) FROM (
141 SELECT MAX(timestamp) AS tstamp FROM issues WHERE itemnumber = ? AND branchcode = ?
143 SELECT MAX(timestamp) AS tstamp FROM old_issues WHERE itemnumber = ? AND branchcode = ?
146 $sth->execute( $itm, $brc, $itm, $brc );
147 my ($date1) = $sth->fetchrow_array;
148 $sth = $dbh->prepare(
149 "SELECT MAX(transfer) FROM (SELECT max(datearrived) AS transfer FROM branchtransfers WHERE itemnumber=? AND tobranch = ?
151 SELECT max(datesent) AS transfer FROM branchtransfers WHERE itemnumber=? AND frombranch = ?
154 $sth->execute( $itm, $brc, $itm, $brc );
155 my ($date2) = $sth->fetchrow_array;
157 my $date = ( $date1 lt $date2 ) ? $date2 : $date1 ;