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",
48 flagsrequired
=> { circulate
=> "circulate_remaining_permissions" },
53 output_and_exit
( $input, $cookie, $template, 'unknown_biblio')
55 output_and_exit
( $input, $cookie, $template, 'unknown_item')
60 my $lastmove = lastmove
($itm);
61 if ( not $lastmove ) {
62 $count = issuessince
( $itm, 0 );
64 $lastdate = $lastmove->{'datearrived'};
65 $count = issuessince
( $itm, $lastdate );
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
=> $biblio->title,
78 author
=> $biblio->author,
79 barcode
=> $item->barcode,
80 homebranch
=> $item->homebranch,
81 holdingbranch
=> $item->holdingbranch,
82 lastdate
=> $lastdate ?
$lastdate : 0,
84 libraries
=> $libraries,
87 output_html_with_http_headers
$input, $cookie, $template->output;
91 my ($itemnumber) = @_;
92 my $dbh = C4
::Context
->dbh;
93 my $sth = $dbh->prepare(
94 "SELECT max(branchtransfers.datearrived) FROM branchtransfers WHERE branchtransfers.itemnumber=?"
96 $sth->execute($itemnumber);
97 my ($date) = $sth->fetchrow_array;
98 return 0 unless $date;
100 "SELECT * FROM branchtransfers WHERE branchtransfers.itemnumber=? and branchtransfers.datearrived=?"
102 $sth->execute( $itemnumber, $date );
103 my ($data) = $sth->fetchrow_hashref;
104 return 0 unless $data;
109 my ( $itemnumber, $date ) = @_;
110 my $dbh = C4
::Context
->dbh;
112 $dbh->prepare("SELECT SUM(count) FROM (
113 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? and timestamp > ?
115 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? and timestamp > ?
117 $sth->execute( $itemnumber, $date, $itemnumber, $date );
118 return $sth->fetchrow_arrayref->[0];
122 my ( $itemnumber, $brcd ) = @_;
123 my $dbh = C4
::Context
->dbh;
124 my $sth = $dbh->prepare(
125 "SELECT SUM(count) FROM (
126 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? AND branchcode = ?
128 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? AND branchcode = ?
131 $sth->execute( $itemnumber, $brcd, $itemnumber, $brcd );
132 return $sth->fetchrow_array;
136 my ( $itm, $brc ) = @_;
137 my $dbh = C4
::Context
->dbh;
138 my $sth = $dbh->prepare(
139 "SELECT MAX(tstamp) FROM (
140 SELECT MAX(timestamp) AS tstamp FROM issues WHERE itemnumber = ? AND branchcode = ?
142 SELECT MAX(timestamp) AS tstamp FROM old_issues WHERE itemnumber = ? AND branchcode = ?
145 $sth->execute( $itm, $brc, $itm, $brc );
146 my ($date1) = $sth->fetchrow_array;
147 $sth = $dbh->prepare(
148 "SELECT MAX(transfer) FROM (SELECT max(datearrived) AS transfer FROM branchtransfers WHERE itemnumber=? AND tobranch = ?
150 SELECT max(datesent) AS transfer FROM branchtransfers WHERE itemnumber=? AND frombranch = ?
153 $sth->execute( $itm, $brc, $itm, $brc );
154 my ($date2) = $sth->fetchrow_array;
156 my $date = ( $date1 lt $date2 ) ?
$date2 : $date1 ;