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 );
42 if ( !defined $biblio or !defined $item ) {
43 print $input->redirect("/cgi-bin/koha/errors/400.pl");
46 my $lastmove = lastmove
($itm);
50 if ( not $lastmove ) {
51 $count = issuessince
( $itm, 0 );
53 $lastdate = $lastmove->{'datearrived'};
54 $count = issuessince
( $itm, $lastdate );
59 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
61 template_name
=> "circ/bookcount.tt",
65 flagsrequired
=> { circulate
=> "circulate_remaining_permissions" },
70 my $libraries = Koha
::Libraries
->search({}, { order_by
=> ['branchname'] })->unblessed;
71 for my $library ( @
$libraries ) {
72 $library->{selected
} = 1 if $library->{branchcode
} eq C4
::Context
->userenv->{branch
};
73 $library->{issues
} = issuesat
($itm, $library->{branchcode
});
74 $library->{seen
} = lastseenat
( $itm, $library->{branchcode
} ) || undef;
78 biblionumber
=> $biblionumber,
79 title
=> $biblio->title,
80 author
=> $biblio->author,
81 barcode
=> $item->barcode,
82 homebranch
=> $item->homebranch,
83 holdingbranch
=> $item->holdingbranch,
84 lastdate
=> $lastdate ?
$lastdate : 0,
86 libraries
=> $libraries,
89 output_html_with_http_headers
$input, $cookie, $template->output;
93 my ($itemnumber) = @_;
94 my $dbh = C4
::Context
->dbh;
95 my $sth = $dbh->prepare(
96 "SELECT max(branchtransfers.datearrived) FROM branchtransfers WHERE branchtransfers.itemnumber=?"
98 $sth->execute($itemnumber);
99 my ($date) = $sth->fetchrow_array;
100 return 0 unless $date;
101 $sth = $dbh->prepare(
102 "SELECT * FROM branchtransfers WHERE branchtransfers.itemnumber=? and branchtransfers.datearrived=?"
104 $sth->execute( $itemnumber, $date );
105 my ($data) = $sth->fetchrow_hashref;
106 return 0 unless $data;
111 my ( $itemnumber, $date ) = @_;
112 my $dbh = C4
::Context
->dbh;
114 $dbh->prepare("SELECT SUM(count) FROM (
115 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? and timestamp > ?
117 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? and timestamp > ?
119 $sth->execute( $itemnumber, $date, $itemnumber, $date );
120 return $sth->fetchrow_arrayref->[0];
124 my ( $itemnumber, $brcd ) = @_;
125 my $dbh = C4
::Context
->dbh;
126 my $sth = $dbh->prepare(
127 "SELECT SUM(count) FROM (
128 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? AND branchcode = ?
130 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? AND branchcode = ?
133 $sth->execute( $itemnumber, $brcd, $itemnumber, $brcd );
134 return $sth->fetchrow_array;
138 my ( $itm, $brc ) = @_;
139 my $dbh = C4
::Context
->dbh;
140 my $sth = $dbh->prepare(
141 "SELECT MAX(tstamp) FROM (
142 SELECT MAX(timestamp) AS tstamp FROM issues WHERE itemnumber = ? AND branchcode = ?
144 SELECT MAX(timestamp) AS tstamp FROM old_issues WHERE itemnumber = ? AND branchcode = ?
147 $sth->execute( $itm, $brc, $itm, $brc );
148 my ($date1) = $sth->fetchrow_array;
149 $sth = $dbh->prepare(
150 "SELECT MAX(transfer) FROM (SELECT max(datearrived) AS transfer FROM branchtransfers WHERE itemnumber=? AND tobranch = ?
152 SELECT max(datesent) AS transfer FROM branchtransfers WHERE itemnumber=? AND frombranch = ?
155 $sth->execute( $itm, $brc, $itm, $brc );
156 my ($date2) = $sth->fetchrow_array;
158 my $date = ( $date1 lt $date2 ) ?
$date2 : $date1 ;