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
31 use C4::Interface::RenewalsCDK;
32 use C4::Circulation::Issues;
33 use C4::Circulation::Main;
38 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
40 # set the version for version checking
44 @EXPORT = qw(&renewstatus &renewbook &bulkrenew);
45 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
47 # your exported package globals go here,
48 # as well as any optionally exported functions
50 @EXPORT_OK = qw($Var1 %Hashit);
53 # non-exported package globals go here
54 use vars qw(@more $stuff);
56 # initalize package globals, first exported ones
61 # then the others (which are still accessible as $Some::Module::stuff)
65 # all file-scoped lexicals must be created before
66 # the functions below that use them.
68 # file-private lexicals go here
72 # here's a file-private function as a closure,
73 # callable as &$priv_func; it cannot be prototyped.
78 # make all your functions, whether exported or not;
86 # check renewal status
87 my ($env,$dbh,$bornum,$itemno)=@_;
90 my $q1 = "select * from issues
91 where (borrowernumber = '$bornum')
92 and (itemnumber = '$itemno')
93 and returndate is null";
94 my $sth1 = $dbh->prepare($q1);
96 if (my $data1 = $sth1->fetchrow_hashref) {
97 my $q2 = "select renewalsallowed from items,biblioitems,itemtypes
98 where (items.itemnumber = '$itemno')
99 and (items.biblioitemnumber = biblioitems.biblioitemnumber)
100 and (biblioitems.itemtype = itemtypes.itemtype)";
101 my $sth2 = $dbh->prepare($q2);
103 if (my $data2=$sth2->fetchrow_hashref) {
104 $renews = $data2->{'renewalsallowed'};
106 if ($renews > $data1->{'renewals'}) {
117 # mark book as renewed
118 my ($env,$dbh,$bornum,$itemno,$datedue)=@_;
119 if ($datedue eq "" ) {
121 my $query= "Select * from biblioitems,items,itemtypes
122 where (items.itemnumber = '$itemno')
123 and (biblioitems.biblioitemnumber = items.biblioitemnumber)
124 and (biblioitems.itemtype = itemtypes.itemtype)";
125 my $sth=$dbh->prepare($query);
127 if (my $data=$sth->fetchrow_hashref) {
128 $loanlength = $data->{'loanlength'}
132 my $datedu = time + ($loanlength * 86400);
133 my @datearr = localtime($datedu);
134 $datedue = (1900+$datearr[5])."-".($datearr[4]+1)."-".$datearr[3];
136 my @date = split("-",$datedue);
137 my $odatedue = (@date[2]+0)."-".(@date[1]+0)."-".@date[0];
138 my $issquery = "select * from issues where borrowernumber='$bornum' and
139 itemnumber='$itemno' and returndate is null";
140 my $sth=$dbh->prepare($issquery);
142 my $issuedata=$sth->fetchrow_hashref;
144 my $renews = $issuedata->{'renewals'} +1;
145 my $updquery = "update issues
146 set date_due = '$datedue', renewals = '$renews'
147 where borrowernumber='$bornum' and
148 itemnumber='$itemno' and returndate is null";
149 my $sth=$dbh->prepare($updquery);
157 my ($env,$dbh,$bornum,$amount,$borrower,$odues) = @_;
158 my $query = "select * from issues
159 where borrowernumber = '$bornum' and returndate is null order by date_due";
160 my $sth = $dbh->prepare($query);
168 while (my $issrec = $sth->fetchrow_hashref) {
169 my $itemdata = C4::Search::itemnodata($env,$dbh,$issrec->{'itemnumber'});
170 my @date = split("-",$issrec->{'date_due'});
171 #my $line = $issrec->{'date_due'}." ";
172 my $line = @date[2]."-".@date[1]."-".@date[0]." ";
173 my $renewstatus = renewstatus($env,$dbh,$bornum,$issrec->{'itemnumber'});
174 my ($resbor,$resrec) = C4::Circulation::Main::checkreserve($env,
175 $dbh,$issrec->{'itemnumber'});
179 } elsif ($renewstatus == 0) {
181 $rstatuses[$x] = "N";
184 $rstatuses[$x] = "Y";
186 $line = $line.fmtdec($env,$issrec->{'renewals'},"20")." ";
187 $line = $line.$itemdata->{'barcode'}." ".$itemdata->{'itemtype'}." ".$itemdata->{'title'};
189 #debug_msg($env,$line);
190 $issues[$x] = $issrec;
191 $barcodes[$x] = $itemdata->{'barcode'};
193 if ($issrec->{'renewals'} > 0) {
196 $renewdef[$x] = $rdef;
202 my $renews = C4::Interface::RenewalsCDK::renew_window($env,
203 \@items,$borrower,$amount,$odues);
207 my @renew_errors = "";
208 while ($x < $isscnt) {
209 if (@$renews[$x] == 1) {
210 my $issrec = $issues[$x];
211 if ($rstatuses[$x] eq "Y") {
212 renewbook($env,$dbh,$issrec->{'borrowernumber'},$issrec->{'itemnumber'},"");
213 my $charge = C4::Circulation::Issues::calc_charges($env,$dbh,
214 $issrec->{'itemnumber'},$issrec->{'borrowernumber'});
216 C4::Circulation::Issues::createcharge($env,$dbh,
217 $issrec->{'itemnumber'},$issrec->{'borrowernumber'},$charge);
219 &UpdateStats($env,$env->{'branchcode'},'renew',$charge,'',$issrec->{'itemnumber'});
220 } elsif ($rstatuses[$x] eq "N") {
221 C4::InterfaceCDK::info_msg($env,
222 "</S>$barcodes[$x] - can't renew");
224 C4::InterfaceCDK::info_msg($env,
225 "</S>$barcodes[$x] - on reserve");
232 END { } # module clean-up code here (global destructor)