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
13 use C4::Interface::RenewalsCDK;
14 use C4::Circulation::Issues;
15 use C4::Circulation::Main;
20 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
22 # set the version for version checking
26 @EXPORT = qw(&renewstatus &renewbook &bulkrenew);
27 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
29 # your exported package globals go here,
30 # as well as any optionally exported functions
32 @EXPORT_OK = qw($Var1 %Hashit);
35 # non-exported package globals go here
36 use vars qw(@more $stuff);
38 # initalize package globals, first exported ones
43 # then the others (which are still accessible as $Some::Module::stuff)
47 # all file-scoped lexicals must be created before
48 # the functions below that use them.
50 # file-private lexicals go here
54 # here's a file-private function as a closure,
55 # callable as &$priv_func; it cannot be prototyped.
60 # make all your functions, whether exported or not;
68 # check renewal status
69 my ($env,$dbh,$bornum,$itemno)=@_;
72 my $q1 = "select * from issues
73 where (borrowernumber = '$bornum')
74 and (itemnumber = '$itemno')
75 and returndate is null";
76 my $sth1 = $dbh->prepare($q1);
78 if (my $data1 = $sth1->fetchrow_hashref) {
79 my $q2 = "select renewalsallowed from items,biblioitems,itemtypes
80 where (items.itemnumber = '$itemno')
81 and (items.biblioitemnumber = biblioitems.biblioitemnumber)
82 and (biblioitems.itemtype = itemtypes.itemtype)";
83 my $sth2 = $dbh->prepare($q2);
85 if (my $data2=$sth2->fetchrow_hashref) {
86 $renews = $data2->{'renewalsallowed'};
88 if ($renews > $data1->{'renewals'}) {
99 # mark book as renewed
100 my ($env,$dbh,$bornum,$itemno,$datedue)=@_;
101 if ($datedue eq "" ) {
103 my $query= "Select * from biblioitems,items,itemtypes
104 where (items.itemnumber = '$itemno')
105 and (biblioitems.biblioitemnumber = items.biblioitemnumber)
106 and (biblioitems.itemtype = itemtypes.itemtype)";
107 my $sth=$dbh->prepare($query);
109 if (my $data=$sth->fetchrow_hashref) {
110 $loanlength = $data->{'loanlength'}
114 my $datedu = time + ($loanlength * 86400);
115 my @datearr = localtime($datedu);
116 $datedue = (1900+$datearr[5])."-".($datearr[4]+1)."-".$datearr[3];
118 my @date = split("-",$datedue);
119 my $odatedue = (@date[2]+0)."-".(@date[1]+0)."-".@date[0];
120 my $issquery = "select * from issues where borrowernumber='$bornum' and
121 itemnumber='$itemno' and returndate is null";
122 my $sth=$dbh->prepare($issquery);
124 my $issuedata=$sth->fetchrow_hashref;
126 my $renews = $issuedata->{'renewals'} +1;
127 my $updquery = "update issues
128 set date_due = '$datedue', renewals = '$renews'
129 where borrowernumber='$bornum' and
130 itemnumber='$itemno' and returndate is null";
131 my $sth=$dbh->prepare($updquery);
139 my ($env,$dbh,$bornum,$amount,$borrower,$odues) = @_;
140 my $query = "select * from issues
141 where borrowernumber = '$bornum' and returndate is null order by date_due";
142 my $sth = $dbh->prepare($query);
150 while (my $issrec = $sth->fetchrow_hashref) {
151 my $itemdata = C4::Search::itemnodata($env,$dbh,$issrec->{'itemnumber'});
152 my @date = split("-",$issrec->{'date_due'});
153 #my $line = $issrec->{'date_due'}." ";
154 my $line = @date[2]."-".@date[1]."-".@date[0]." ";
155 my $renewstatus = renewstatus($env,$dbh,$bornum,$issrec->{'itemnumber'});
156 my ($resbor,$resrec) = C4::Circulation::Main::checkreserve($env,
157 $dbh,$issrec->{'itemnumber'});
161 } elsif ($renewstatus == 0) {
163 $rstatuses[$x] = "N";
166 $rstatuses[$x] = "Y";
168 $line = $line.fmtdec($env,$issrec->{'renewals'},"20")." ";
169 $line = $line.$itemdata->{'barcode'}." ".$itemdata->{'itemtype'}." ".$itemdata->{'title'};
171 #debug_msg($env,$line);
172 $issues[$x] = $issrec;
173 $barcodes[$x] = $itemdata->{'barcode'};
175 if ($issrec->{'renewals'} > 0) {
178 $renewdef[$x] = $rdef;
184 my $renews = C4::Interface::RenewalsCDK::renew_window($env,
185 \@items,$borrower,$amount,$odues);
189 my @renew_errors = "";
190 while ($x < $isscnt) {
191 if (@$renews[$x] == 1) {
192 my $issrec = $issues[$x];
193 if ($rstatuses[$x] eq "Y") {
194 renewbook($env,$dbh,$issrec->{'borrowernumber'},$issrec->{'itemnumber'},"");
195 my $charge = C4::Circulation::Issues::calc_charges($env,$dbh,
196 $issrec->{'itemnumber'},$issrec->{'borrowernumber'});
198 C4::Circulation::Issues::createcharge($env,$dbh,
199 $issrec->{'itemnumber'},$issrec->{'borrowernumber'},$charge);
201 &UpdateStats($env,$env->{'branchcode'},'renew',$charge,'',$issrec->{'itemnumber'});
202 } elsif ($rstatuses[$x] eq "N") {
203 C4::InterfaceCDK::info_msg($env,
204 "</S>$barcodes[$x] - can't renew");
206 C4::InterfaceCDK::info_msg($env,
207 "</S>$barcodes[$x] - on reserve");
214 END { } # module clean-up code here (global destructor)