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>.
31 use C4::Biblio; # GetBiblioItemData
36 my $itm = $input->param('itm');
37 my $bi = $input->param('bi');
38 my $biblionumber = $input->param('biblionumber');
40 my $idata = itemdatanum($itm);
41 my $data = GetBiblioItemData($bi);
43 my $lastmove = lastmove($itm);
47 if ( not $lastmove ) {
48 $count = issuessince( $itm, 0 );
50 $lastdate = $lastmove->{'datearrived'};
51 $count = issuessince( $itm, $lastdate );
56 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
58 template_name => "circ/bookcount.tt",
62 flagsrequired => { circulate => "circulate_remaining_permissions" },
67 my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;
68 for my $library ( @$libraries ) {
69 $library->{selected} = 1 if $library->{branchcode} eq C4::Context->userenv->{branch};
70 $library->{issues} = issuesat($itm, $library->{branchcode});
71 $library->{seen} = lastseenat( $itm, $library->{branchcode} ) || undef;
75 biblionumber => $biblionumber,
76 title => $data->{'title'},
77 author => $data->{'author'},
78 barcode => $idata->{'barcode'},
79 biblioitemnumber => $bi,
80 homebranch => $idata->{homebranch},
81 holdingbranch => $idata->{holdingbranch},
82 lastdate => $lastdate ? $lastdate : 0,
84 libraries => $libraries,
87 output_html_with_http_headers $input, $cookie, $template->output;
91 my ($itemnumber) = @_;
92 my $sth = C4::Context->dbh->prepare("SELECT * FROM items WHERE itemnumber=?");
93 $sth->execute($itemnumber);
94 return $sth->fetchrow_hashref;
98 my ($itemnumber) = @_;
99 my $dbh = C4::Context->dbh;
100 my $sth = $dbh->prepare(
101 "SELECT max(branchtransfers.datearrived) FROM branchtransfers WHERE branchtransfers.itemnumber=?"
103 $sth->execute($itemnumber);
104 my ($date) = $sth->fetchrow_array;
105 return 0 unless $date;
106 $sth = $dbh->prepare(
107 "SELECT * FROM branchtransfers WHERE branchtransfers.itemnumber=? and branchtransfers.datearrived=?"
109 $sth->execute( $itemnumber, $date );
110 my ($data) = $sth->fetchrow_hashref;
111 return 0 unless $data;
116 my ( $itemnumber, $date ) = @_;
117 my $dbh = C4::Context->dbh;
119 $dbh->prepare("SELECT SUM(count) FROM (
120 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? and timestamp > ?
122 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? and timestamp > ?
124 $sth->execute( $itemnumber, $date, $itemnumber, $date );
125 return $sth->fetchrow_arrayref->[0];
129 my ( $itemnumber, $brcd ) = @_;
130 my $dbh = C4::Context->dbh;
131 my $sth = $dbh->prepare(
132 "SELECT SUM(count) FROM (
133 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? AND branchcode = ?
135 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? AND branchcode = ?
138 $sth->execute( $itemnumber, $brcd, $itemnumber, $brcd );
139 return $sth->fetchrow_array;
143 my ( $itm, $brc ) = @_;
144 my $dbh = C4::Context->dbh;
145 my $sth = $dbh->prepare(
146 "SELECT MAX(tstamp) FROM (
147 SELECT MAX(timestamp) AS tstamp FROM issues WHERE itemnumber = ? AND branchcode = ?
149 SELECT MAX(timestamp) AS tstamp FROM old_issues WHERE itemnumber = ? AND branchcode = ?
152 $sth->execute( $itm, $brc, $itm, $brc );
153 my ($date1) = $sth->fetchrow_array;
154 $sth = $dbh->prepare(
155 "SELECT MAX(transfer) FROM (SELECT max(datearrived) AS transfer FROM branchtransfers WHERE itemnumber=? AND tobranch = ?
157 SELECT max(datesent) AS transfer FROM branchtransfers WHERE itemnumber=? AND frombranch = ?
160 $sth->execute( $itm, $brc, $itm, $brc );
161 my ($date2) = $sth->fetchrow_array;
163 my $date = ( $date1 lt $date2 ) ? $date2 : $date1 ;