1 package C4::Circulation::Renewals2; #assumes C4/Circulation/Renewals2.pm
3 #package to deal with Renewals
4 #written 7/11/99 by olwen@katipo.co.nz
6 #modified by chris@katipo.co.nz
8 #need to update stats with renewals
11 # Copyright 2000-2002 Katipo Communications
13 # This file is part of Koha.
15 # Koha is free software; you can redistribute it and/or modify it under the
16 # terms of the GNU General Public License as published by the Free Software
17 # Foundation; either version 2 of the License, or (at your option) any later
20 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
21 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
22 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License along with
25 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
26 # Suite 330, Boston, MA 02111-1307 USA
34 use C4::Circulation::Circ2;
36 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
38 # set the version for version checking
42 @EXPORT = qw(&renewstatus &renewbook &calc_charges);
43 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
45 # your exported package globals go here,
46 # as well as any optionally exported functions
48 @EXPORT_OK = qw($Var1 %Hashit);
51 # non-exported package globals go here
52 use vars qw(@more $stuff);
54 # initalize package globals, first exported ones
59 # then the others (which are still accessible as $Some::Module::stuff)
63 # all file-scoped lexicals must be created before
64 # the functions below that use them.
66 # file-private lexicals go here
70 # here's a file-private function as a closure,
71 # callable as &$priv_func; it cannot be prototyped.
76 # make all your functions, whether exported or not;
84 # check renewal status
85 my ($env,$bornum,$itemno)=@_;
89 my $q1 = "select * from issues
90 where (borrowernumber = '$bornum')
91 and (itemnumber = '$itemno')
92 and returndate is null";
93 my $sth1 = $dbh->prepare($q1);
95 if (my $data1 = $sth1->fetchrow_hashref) {
96 my $q2 = "select renewalsallowed from items,biblioitems,itemtypes
97 where (items.itemnumber = '$itemno')
98 and (items.biblioitemnumber = biblioitems.biblioitemnumber)
99 and (biblioitems.itemtype = itemtypes.itemtype)";
100 my $sth2 = $dbh->prepare($q2);
102 if (my $data2=$sth2->fetchrow_hashref) {
103 $renews = $data2->{'renewalsallowed'};
105 if ($renews > $data1->{'renewals'}) {
117 # mark book as renewed
118 my ($env,$bornum,$itemno,$datedue)=@_;
120 if ($datedue eq "" ) {
121 #debug_msg($env, "getting date");
123 my $query= "Select * from biblioitems,items,itemtypes
124 where (items.itemnumber = '$itemno')
125 and (biblioitems.biblioitemnumber = items.biblioitemnumber)
126 and (biblioitems.itemtype = itemtypes.itemtype)";
127 my $sth=$dbh->prepare($query);
129 if (my $data=$sth->fetchrow_hashref) {
130 $loanlength = $data->{'loanlength'}
134 my $datedu = time + ($loanlength * 86400);
135 my @datearr = localtime($datedu);
136 $datedue = (1900+$datearr[5])."-".($datearr[4]+1)."-".$datearr[3];
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 $sth=$dbh->prepare($updquery);
152 UpdateStats($env,$env->{'branchcode'},'renew','','',$itemno);
153 my ($charge,$type)=calc_charges($env, $itemno, $bornum);
155 my $accountno=getnextacctno($env,$bornum,$dbh);
156 my $item=getiteminformation($env, $itemno);
157 my $account="Insert into accountlines
158 (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
160 ('$bornum','$accountno',now(),$charge,'Renewal of Rental Item $item->{'title'} $item->{'barcode'}','Rent',$charge,'$itemno')";
161 $sth=$dbh->prepare($account);
173 # calculate charges due
174 my ($env, $itemno, $bornum)=@_;
178 my $q1 = "select itemtypes.itemtype,rentalcharge from
179 items,biblioitems,itemtypes
180 where (items.itemnumber ='$itemno')
181 and (biblioitems.biblioitemnumber = items.biblioitemnumber)
182 and (biblioitems.itemtype = itemtypes.itemtype)";
183 my $sth1= $dbh->prepare($q1);
185 if (my $data1=$sth1->fetchrow_hashref) {
186 $item_type = $data1->{'itemtype'};
187 $charge = $data1->{'rentalcharge'};
188 my $q2 = "select rentaldiscount from
189 borrowers,categoryitem
190 where (borrowers.borrowernumber = '$bornum')
191 and (borrowers.categorycode = categoryitem.categorycode)
192 and (categoryitem.itemtype = '$item_type')";
193 my $sth2=$dbh->prepare($q2);
195 if (my$data2=$sth2->fetchrow_hashref) {
196 my $discount = $data2->{'rentaldiscount'};
197 $charge = ($charge *(100 - $discount)) / 100;
203 # print "item $item_type";
204 return ($charge,$item_type);
208 END { } # module clean-up code here (global destructor)