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::Biblio; # GetBiblioItemData
37 my $itm = $input->param('itm');
38 my $bi = $input->param('bi');
39 my $biblionumber = $input->param('biblionumber');
41 my $idata = itemdatanum($itm);
42 my $data = GetBiblioItemData($bi);
44 my $lastmove = lastmove($itm);
48 if ( not $lastmove ) {
49 $count = issuessince( $itm, 0 );
51 $lastdate = $lastmove->{'datearrived'};
52 $count = issuessince( $itm, $lastdate );
57 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
59 template_name => "circ/bookcount.tt",
63 flagsrequired => { circulate => "circulate_remaining_permissions" },
68 my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;
69 for my $library ( @$libraries ) {
70 $library->{selected} = 1 if $library->{branchcode} eq C4::Context->userenv->{branch};
71 $library->{issues} = issuesat($itm, $library->{branchcode});
72 $library->{seen} = lastseenat( $itm, $library->{branchcode} ) || undef;
76 biblionumber => $biblionumber,
77 title => $data->{'title'},
78 author => $data->{'author'},
79 barcode => $idata->{'barcode'},
80 biblioitemnumber => $bi,
81 homebranch => $idata->{homebranch},
82 holdingbranch => $idata->{holdingbranch},
83 lastdate => $lastdate ? $lastdate : 0,
85 libraries => $libraries,
88 output_html_with_http_headers $input, $cookie, $template->output;
92 my ($itemnumber) = @_;
93 my $sth = C4::Context->dbh->prepare("SELECT * FROM items WHERE itemnumber=?");
94 $sth->execute($itemnumber);
95 return $sth->fetchrow_hashref;
99 my ($itemnumber) = @_;
100 my $dbh = C4::Context->dbh;
101 my $sth = $dbh->prepare(
102 "SELECT max(branchtransfers.datearrived) FROM branchtransfers WHERE branchtransfers.itemnumber=?"
104 $sth->execute($itemnumber);
105 my ($date) = $sth->fetchrow_array;
106 return 0 unless $date;
107 $sth = $dbh->prepare(
108 "SELECT * FROM branchtransfers WHERE branchtransfers.itemnumber=? and branchtransfers.datearrived=?"
110 $sth->execute( $itemnumber, $date );
111 my ($data) = $sth->fetchrow_hashref;
112 return 0 unless $data;
117 my ( $itemnumber, $date ) = @_;
118 my $dbh = C4::Context->dbh;
120 $dbh->prepare("SELECT SUM(count) FROM (
121 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? and timestamp > ?
123 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? and timestamp > ?
125 $sth->execute( $itemnumber, $date, $itemnumber, $date );
126 return $sth->fetchrow_arrayref->[0];
130 my ( $itemnumber, $brcd ) = @_;
131 my $dbh = C4::Context->dbh;
132 my $sth = $dbh->prepare(
133 "SELECT SUM(count) FROM (
134 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? AND branchcode = ?
136 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? AND branchcode = ?
139 $sth->execute( $itemnumber, $brcd, $itemnumber, $brcd );
140 return $sth->fetchrow_array;
144 my ( $itm, $brc ) = @_;
145 my $dbh = C4::Context->dbh;
146 my $sth = $dbh->prepare(
147 "SELECT MAX(tstamp) FROM (
148 SELECT MAX(timestamp) AS tstamp FROM issues WHERE itemnumber = ? AND branchcode = ?
150 SELECT MAX(timestamp) AS tstamp FROM old_issues WHERE itemnumber = ? AND branchcode = ?
153 $sth->execute( $itm, $brc, $itm, $brc );
154 my ($date1) = $sth->fetchrow_array;
155 $sth = $dbh->prepare(
156 "SELECT MAX(transfer) FROM (SELECT max(datearrived) AS transfer FROM branchtransfers WHERE itemnumber=? AND tobranch = ?
158 SELECT max(datesent) AS transfer FROM branchtransfers WHERE itemnumber=? AND frombranch = ?
161 $sth->execute( $itm, $brc, $itm, $brc );
162 my ($date2) = $sth->fetchrow_array;
164 my $date = ( $date1 lt $date2 ) ? $date2 : $date1 ;