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 with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA 02111-1307 USA
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, $message ) = lastmove($itm);
52 if ( not $lastmove ) {
53 # $lastdate = $message;
54 $count = issuessince( $itm, 0 );
56 $lastdate = $lastmove->{'datearrived'};
57 $count = issuessince( $itm, $lastdate );
62 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
64 template_name => "circ/bookcount.tmpl",
68 flagsrequired => { circulate => "circulate_remaining_permissions" },
73 my $branchloop = GetBranchesLoop(C4::Context->userenv->{branch});
74 foreach (@$branchloop) {
75 my $date = lastseenat( $itm, $_->{value} );
76 my ($datechunk, $timechunk) = slashdate($date);
77 $_->{issues} = issuesat($itm, $_->{value});
78 $_->{seen} = $datechunk;
79 $_->{seentime} = $timechunk;
85 biblionumber => $biblionumber,
86 title => $data->{'title'},
87 author => $data->{'author'},
88 barcode => $idata->{'barcode'},
89 biblioitemnumber => $bi,
90 homebranch => $homebranch,
91 holdingbranch => $holdingbranch,
92 lastdate => $lastdate ? format_date($lastdate) : $message,
94 branchloop => $branchloop,
97 output_html_with_http_headers $input, $cookie, $template->output;
101 my ($itemnumber) = @_;
102 my $sth = C4::Context->dbh->prepare("SELECT * FROM items WHERE itemnumber=?");
103 $sth->execute($itemnumber);
104 return $sth->fetchrow_hashref;
108 my ($itemnumber) = @_;
109 my $dbh = C4::Context->dbh;
110 my $sth = $dbh->prepare(
111 "SELECT max(branchtransfers.datearrived) FROM branchtransfers WHERE branchtransfers.itemnumber=?"
113 $sth->execute($itemnumber);
114 my ($date) = $sth->fetchrow_array;
115 return ( 0, "Item has no branch transfers record" ) if not $date;
116 $sth = $dbh->prepare(
117 "SELECT * FROM branchtransfers WHERE branchtransfers.itemnumber=? and branchtransfers.datearrived=?"
119 $sth->execute( $itemnumber, $date );
120 my ($data) = $sth->fetchrow_hashref;
121 return ( 0, "Item has no branch transfers record" ) if not $data;
122 return ( $data, "" );
126 my ( $itemnumber, $date ) = @_;
127 my $dbh = C4::Context->dbh;
129 $dbh->prepare("SELECT SUM(count) FROM (
130 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? and timestamp > ?
132 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? and timestamp > ?
134 $sth->execute( $itemnumber, $date, $itemnumber, $date );
135 return $sth->fetchrow_arrayref->[0];
139 my ( $itemnumber, $brcd ) = @_;
140 my $dbh = C4::Context->dbh;
141 my $sth = $dbh->prepare(
142 "SELECT SUM(count) FROM (
143 SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? AND branchcode = ?
145 SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? AND branchcode = ?
148 $sth->execute( $itemnumber, $brcd, $itemnumber, $brcd );
149 return $sth->fetchrow_array;
153 my ( $itm, $brc ) = @_;
154 my $dbh = C4::Context->dbh;
155 my $sth = $dbh->prepare(
156 "SELECT MAX(tstamp) FROM (
157 SELECT MAX(timestamp) AS tstamp FROM issues WHERE itemnumber = ? AND branchcode = ?
159 SELECT MAX(timestamp) AS tstamp FROM old_issues WHERE itemnumber = ? AND branchcode = ?
162 $sth->execute( $itm, $brc, $itm, $brc );
163 my ($date1) = $sth->fetchrow_array;
164 $sth = $dbh->prepare(
165 "SELECT max(datearrived) FROM branchtransfers WHERE itemnumber=? AND tobranch = ?"
167 $sth->execute( $itm, $brc );
168 my ($date2) = $sth->fetchrow_array;
170 my $date = ( $date1 lt $date2 ) ? $date2 : $date1 ;
174 #####################################################
175 # return date and time from timestamp
179 # warn "slashdate($date)...";