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
33 use C4::Circulation::Circ2;
35 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
37 # set the version for version checking
41 @EXPORT = qw(&renewstatus &renewbook &calc_charges);
42 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
44 # your exported package globals go here,
45 # as well as any optionally exported functions
47 @EXPORT_OK = qw($Var1 %Hashit);
50 # non-exported package globals go here
51 use vars qw(@more $stuff);
53 # initalize package globals, first exported ones
58 # then the others (which are still accessible as $Some::Module::stuff)
62 # all file-scoped lexicals must be created before
63 # the functions below that use them.
65 # file-private lexicals go here
69 # here's a file-private function as a closure,
70 # callable as &$priv_func; it cannot be prototyped.
75 # make all your functions, whether exported or not;
83 # check renewal status
84 my ($env,$bornum,$itemno)=@_;
85 my $dbh = C4::Context->dbh;
88 my $q1 = "select * from issues
89 where (borrowernumber = '$bornum')
90 and (itemnumber = '$itemno')
91 and returndate is null";
92 my $sth1 = $dbh->prepare($q1);
94 if (my $data1 = $sth1->fetchrow_hashref) {
95 my $q2 = "select renewalsallowed from items,biblioitems,itemtypes
96 where (items.itemnumber = '$itemno')
97 and (items.biblioitemnumber = biblioitems.biblioitemnumber)
98 and (biblioitems.itemtype = itemtypes.itemtype)";
99 my $sth2 = $dbh->prepare($q2);
101 if (my $data2=$sth2->fetchrow_hashref) {
102 $renews = $data2->{'renewalsallowed'};
104 if ($renews > $data1->{'renewals'}) {
115 # mark book as renewed
116 my ($env,$bornum,$itemno,$datedue)=@_;
117 my $dbh = C4::Context->dbh;
118 if ($datedue eq "" ) {
119 #debug_msg($env, "getting date");
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 $issquery = "select * from issues where borrowernumber='$bornum' and
137 itemnumber='$itemno' and returndate is null";
138 my $sth=$dbh->prepare($issquery);
140 my $issuedata=$sth->fetchrow_hashref;
142 my $renews = $issuedata->{'renewals'} +1;
143 my $updquery = "update issues
144 set date_due = '$datedue', renewals = '$renews'
145 where borrowernumber='$bornum' and
146 itemnumber='$itemno' and returndate is null";
147 $sth=$dbh->prepare($updquery);
150 UpdateStats($env,$env->{'branchcode'},'renew','','',$itemno);
151 my ($charge,$type)=calc_charges($env, $itemno, $bornum);
153 my $accountno=getnextacctno($env,$bornum,$dbh);
154 my $item=getiteminformation($env, $itemno);
155 my $account="Insert into accountlines
156 (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
158 ('$bornum','$accountno',now(),$charge,'Renewal of Rental Item $item->{'title'} $item->{'barcode'}','Rent',$charge,'$itemno')";
159 $sth=$dbh->prepare($account);
168 # FIXME - This is very similar to
169 # &C4::Circulation::Issues::calc_charges and
170 # &C4::Circulation::Circ2::calc_charges.
171 # Pick one and stick with it.
173 # calculate charges due
174 my ($env, $itemno, $bornum)=@_;
176 my $dbh = C4::Context->dbh;
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;
202 # print "item $item_type";
203 return ($charge,$item_type);
207 END { } # module clean-up code here (global destructor)