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
16 use C4::Circulation::Circ2;
19 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
21 # set the version for version checking
25 @EXPORT = qw(&renewstatus &renewbook &calc_charges);
26 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
28 # your exported package globals go here,
29 # as well as any optionally exported functions
31 @EXPORT_OK = qw($Var1 %Hashit);
34 # non-exported package globals go here
35 use vars qw(@more $stuff);
37 # initalize package globals, first exported ones
42 # then the others (which are still accessible as $Some::Module::stuff)
46 # all file-scoped lexicals must be created before
47 # the functions below that use them.
49 # file-private lexicals go here
53 # here's a file-private function as a closure,
54 # callable as &$priv_func; it cannot be prototyped.
59 # make all your functions, whether exported or not;
67 # check renewal status
68 my ($env,$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'}) {
100 # mark book as renewed
101 my ($env,$bornum,$itemno,$datedue)=@_;
103 if ($datedue eq "" ) {
104 #debug_msg($env, "getting date");
106 my $query= "Select * from biblioitems,items,itemtypes
107 where (items.itemnumber = '$itemno')
108 and (biblioitems.biblioitemnumber = items.biblioitemnumber)
109 and (biblioitems.itemtype = itemtypes.itemtype)";
110 my $sth=$dbh->prepare($query);
112 if (my $data=$sth->fetchrow_hashref) {
113 $loanlength = $data->{'loanlength'}
117 my $datedu = time + ($loanlength * 86400);
118 my @datearr = localtime($datedu);
119 $datedue = (1900+$datearr[5])."-".($datearr[4]+1)."-".$datearr[3];
121 my $issquery = "select * from issues where borrowernumber='$bornum' and
122 itemnumber='$itemno' and returndate is null";
123 my $sth=$dbh->prepare($issquery);
125 my $issuedata=$sth->fetchrow_hashref;
127 my $renews = $issuedata->{'renewals'} +1;
128 my $updquery = "update issues
129 set date_due = '$datedue', renewals = '$renews'
130 where borrowernumber='$bornum' and
131 itemnumber='$itemno' and returndate is null";
132 $sth=$dbh->prepare($updquery);
135 UpdateStats($env,$env->{'branchcode'},'renew','','',$itemno);
136 my ($charge,$type)=calc_charges($env, $itemno, $bornum);
138 my $accountno=getnextacctno($env,$bornum,$dbh);
139 my $item=getiteminformation($env, $itemno);
140 my $account="Insert into accountlines
141 (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
143 ('$bornum','$accountno',now(),$charge,'Renewal of Rental Item $item->{'title'} $item->{'barcode'}','Rent',$charge,'$itemno')";
144 $sth=$dbh->prepare($account);
156 # calculate charges due
157 my ($env, $itemno, $bornum)=@_;
161 my $q1 = "select itemtypes.itemtype,rentalcharge from
162 items,biblioitems,itemtypes
163 where (items.itemnumber ='$itemno')
164 and (biblioitems.biblioitemnumber = items.biblioitemnumber)
165 and (biblioitems.itemtype = itemtypes.itemtype)";
166 my $sth1= $dbh->prepare($q1);
168 if (my $data1=$sth1->fetchrow_hashref) {
169 $item_type = $data1->{'itemtype'};
170 $charge = $data1->{'rentalcharge'};
171 my $q2 = "select rentaldiscount from
172 borrowers,categoryitem
173 where (borrowers.borrowernumber = '$bornum')
174 and (borrowers.categorycode = categoryitem.categorycode)
175 and (categoryitem.itemtype = '$item_type')";
176 my $sth2=$dbh->prepare($q2);
178 if (my$data2=$sth2->fetchrow_hashref) {
179 my $discount = $data2->{'rentaldiscount'};
180 $charge = ($charge *(100 - $discount)) / 100;
186 # print "item $item_type";
187 return ($charge,$item_type);
191 END { } # module clean-up code here (global destructor)