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 under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #use warnings; FIXME - Bug 2505
32 use C4
::Branch
; # GetBranches
33 use C4
::Biblio
; # GetBiblioItemData
34 use C4
::Dates qw
/format_date/;
37 my $itm = $input->param('itm');
38 my $bi = $input->param('bi');
39 my $biblionumber = $input->param('biblionumber');
40 my $branches = GetBranches
;
42 my $idata = itemdatanum
($itm);
43 my $data = GetBiblioItemData
($bi);
45 my $homebranch = $branches->{ $idata->{'homebranch'} }->{'branchname'};
46 my $holdingbranch = $branches->{ $idata->{'holdingbranch'} }->{'branchname'};
48 my $lastmove = lastmove
($itm);
52 if ( not $lastmove ) {
53 $count = issuessince
( $itm, 0 );
55 $lastdate = $lastmove->{'datearrived'};
56 $count = issuessince
( $itm, $lastdate );
61 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
63 template_name
=> "circ/bookcount.tmpl",
67 flagsrequired
=> { circulate
=> "circulate_remaining_permissions" },
72 my $branchloop = GetBranchesLoop
(C4
::Context
->userenv->{branch
});
73 foreach (@
$branchloop) {
74 my $date = lastseenat
( $itm, $_->{value
} );
75 my ($datechunk, $timechunk) = slashdate
($date);
76 $_->{issues
} = issuesat
($itm, $_->{value
});
77 $_->{seen
} = $datechunk;
78 $_->{seentime
} = $timechunk;
82 biblionumber
=> $biblionumber,
83 title
=> $data->{'title'},
84 author
=> $data->{'author'},
85 barcode
=> $idata->{'barcode'},
86 biblioitemnumber
=> $bi,
87 homebranch
=> $homebranch,
88 holdingbranch
=> $holdingbranch,
89 lastdate
=> $lastdate ? format_date
($lastdate) : 0,
91 branchloop
=> $branchloop,
94 output_html_with_http_headers
$input, $cookie, $template->output;
98 my ($itemnumber) = @_;
99 my $sth = C4
::Context
->dbh->prepare("SELECT * FROM items WHERE itemnumber=?");
100 $sth->execute($itemnumber);
101 return $sth->fetchrow_hashref;
105 my ($itemnumber) = @_;
106 my $dbh = C4
::Context
->dbh;
107 my $sth = $dbh->prepare(
108 "SELECT max(branchtransfers.datearrived) FROM branchtransfers WHERE branchtransfers.itemnumber=?"
110 $sth->execute($itemnumber);
111 my ($date) = $sth->fetchrow_array;
112 return 0 unless $date;
113 $sth = $dbh->prepare(
114 "SELECT * FROM branchtransfers WHERE branchtransfers.itemnumber=? and branchtransfers.datearrived=?"
116 $sth->execute( $itemnumber, $date );
117 my ($data) = $sth->fetchrow_hashref;
118 return 0 unless $data;
123 my ( $itemnumber, $date ) = @_;
124 my $dbh = C4
::Context
->dbh;
126 $dbh->prepare("SELECT SUM(count) FROM (
127 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? and timestamp > ?
129 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? and timestamp > ?
131 $sth->execute( $itemnumber, $date, $itemnumber, $date );
132 return $sth->fetchrow_arrayref->[0];
136 my ( $itemnumber, $brcd ) = @_;
137 my $dbh = C4
::Context
->dbh;
138 my $sth = $dbh->prepare(
139 "SELECT SUM(count) FROM (
140 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? AND branchcode = ?
142 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? AND branchcode = ?
145 $sth->execute( $itemnumber, $brcd, $itemnumber, $brcd );
146 return $sth->fetchrow_array;
150 my ( $itm, $brc ) = @_;
151 my $dbh = C4
::Context
->dbh;
152 my $sth = $dbh->prepare(
153 "SELECT MAX(tstamp) FROM (
154 SELECT MAX(timestamp) AS tstamp FROM issues WHERE itemnumber = ? AND branchcode = ?
156 SELECT MAX(timestamp) AS tstamp FROM old_issues WHERE itemnumber = ? AND branchcode = ?
159 $sth->execute( $itm, $brc, $itm, $brc );
160 my ($date1) = $sth->fetchrow_array;
161 $sth = $dbh->prepare(
162 "SELECT MAX(transfer) FROM (SELECT max(datearrived) AS transfer FROM branchtransfers WHERE itemnumber=? AND tobranch = ?
164 SELECT max(datesent) AS transfer FROM branchtransfers WHERE itemnumber=? AND frombranch = ?
167 $sth->execute( $itm, $brc, $itm, $brc );
168 my ($date2) = $sth->fetchrow_array;
170 my $date = ( $date1 lt $date2 ) ?
$date2 : $date1 ;
174 #####################################################
175 # return date and time from timestamp