1 package C4::Circulation::Renewals; #assumes C4/Circulation/Renewals
3 #package to deal with Renewals
4 #written 7/11/99 by olwen@katipo.co.nz
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
30 use C4::Interface::RenewalsCDK;
31 use C4::Circulation::Issues;
32 use C4::Circulation::Main;
33 # FIXME - C4::Circulation::Main and C4::Circulation::Renewals
34 # use each other, so functions get redefined.
39 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
41 # set the version for version checking
45 @EXPORT = qw(&renewstatus &renewbook &bulkrenew);
46 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
48 # your exported package globals go here,
49 # as well as any optionally exported functions
51 @EXPORT_OK = qw($Var1 %Hashit);
54 # non-exported package globals go here
55 use vars qw(@more $stuff);
57 # initalize package globals, first exported ones
62 # then the others (which are still accessible as $Some::Module::stuff)
66 # all file-scoped lexicals must be created before
67 # the functions below that use them.
69 # file-private lexicals go here
73 # here's a file-private function as a closure,
74 # callable as &$priv_func; it cannot be prototyped.
79 # make all your functions, whether exported or not;
87 # check renewal status
88 my ($env,$dbh,$bornum,$itemno)=@_;
91 my $q1 = "select * from issues
92 where (borrowernumber = '$bornum')
93 and (itemnumber = '$itemno')
94 and returndate is null";
95 my $sth1 = $dbh->prepare($q1);
97 if (my $data1 = $sth1->fetchrow_hashref) {
98 my $q2 = "select renewalsallowed from items,biblioitems,itemtypes
99 where (items.itemnumber = '$itemno')
100 and (items.biblioitemnumber = biblioitems.biblioitemnumber)
101 and (biblioitems.itemtype = itemtypes.itemtype)";
102 my $sth2 = $dbh->prepare($q2);
104 if (my $data2=$sth2->fetchrow_hashref) {
105 $renews = $data2->{'renewalsallowed'};
107 if ($renews > $data1->{'renewals'}) {
118 # mark book as renewed
119 my ($env,$dbh,$bornum,$itemno,$datedue)=@_;
120 if ($datedue eq "" ) {
122 my $query= "Select * from biblioitems,items,itemtypes
123 where (items.itemnumber = '$itemno')
124 and (biblioitems.biblioitemnumber = items.biblioitemnumber)
125 and (biblioitems.itemtype = itemtypes.itemtype)";
126 my $sth=$dbh->prepare($query);
128 if (my $data=$sth->fetchrow_hashref) {
129 $loanlength = $data->{'loanlength'}
133 my $datedu = time + ($loanlength * 86400);
134 my @datearr = localtime($datedu);
135 $datedue = (1900+$datearr[5])."-".($datearr[4]+1)."-".$datearr[3];
137 my @date = split("-",$datedue);
138 my $odatedue = (@date[2]+0)."-".(@date[1]+0)."-".@date[0];
139 my $issquery = "select * from issues where borrowernumber='$bornum' and
140 itemnumber='$itemno' and returndate is null";
141 my $sth=$dbh->prepare($issquery);
143 my $issuedata=$sth->fetchrow_hashref;
145 my $renews = $issuedata->{'renewals'} +1;
146 my $updquery = "update issues
147 set date_due = '$datedue', renewals = '$renews'
148 where borrowernumber='$bornum' and
149 itemnumber='$itemno' and returndate is null";
150 my $sth=$dbh->prepare($updquery);
158 my ($env,$dbh,$bornum,$amount,$borrower,$odues) = @_;
159 my $query = "select * from issues
160 where borrowernumber = '$bornum' and returndate is null order by date_due";
161 my $sth = $dbh->prepare($query);
169 while (my $issrec = $sth->fetchrow_hashref) {
170 my $itemdata = C4::Search::itemnodata($env,$dbh,$issrec->{'itemnumber'});
171 my @date = split("-",$issrec->{'date_due'});
172 #my $line = $issrec->{'date_due'}." ";
173 my $line = @date[2]."-".@date[1]."-".@date[0]." ";
174 my $renewstatus = renewstatus($env,$dbh,$bornum,$issrec->{'itemnumber'});
175 my ($resbor,$resrec) = C4::Circulation::Main::checkreserve($env,
176 $dbh,$issrec->{'itemnumber'});
180 } elsif ($renewstatus == 0) {
182 $rstatuses[$x] = "N";
185 $rstatuses[$x] = "Y";
187 $line = $line.fmtdec($env,$issrec->{'renewals'},"20")." ";
188 $line = $line.$itemdata->{'barcode'}." ".$itemdata->{'itemtype'}." ".$itemdata->{'title'};
190 #debug_msg($env,$line);
191 $issues[$x] = $issrec;
192 $barcodes[$x] = $itemdata->{'barcode'};
194 if ($issrec->{'renewals'} > 0) {
197 $renewdef[$x] = $rdef;
203 my $renews = C4::Interface::RenewalsCDK::renew_window($env,
204 \@items,$borrower,$amount,$odues);
208 my @renew_errors = "";
209 while ($x < $isscnt) {
210 if (@$renews[$x] == 1) {
211 my $issrec = $issues[$x];
212 if ($rstatuses[$x] eq "Y") {
213 renewbook($env,$dbh,$issrec->{'borrowernumber'},$issrec->{'itemnumber'},"");
214 my $charge = C4::Circulation::Issues::calc_charges($env,$dbh,
215 $issrec->{'itemnumber'},$issrec->{'borrowernumber'});
217 C4::Circulation::Issues::createcharge($env,$dbh,
218 $issrec->{'itemnumber'},$issrec->{'borrowernumber'},$charge);
220 &UpdateStats($env,$env->{'branchcode'},'renew',$charge,'',$issrec->{'itemnumber'});
221 } elsif ($rstatuses[$x] eq "N") {
222 C4::InterfaceCDK::info_msg($env,
223 "</S>$barcodes[$x] - can't renew");
225 C4::InterfaceCDK::info_msg($env,
226 "</S>$barcodes[$x] - on reserve");
233 END { } # module clean-up code here (global destructor)