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;
18 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
20 # set the version for version checking
24 @EXPORT = qw(&renewstatus &renewbook &calc_charges);
25 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
27 # your exported package globals go here,
28 # as well as any optionally exported functions
30 @EXPORT_OK = qw($Var1 %Hashit);
33 # non-exported package globals go here
34 use vars qw(@more $stuff);
36 # initalize package globals, first exported ones
41 # then the others (which are still accessible as $Some::Module::stuff)
45 # all file-scoped lexicals must be created before
46 # the functions below that use them.
48 # file-private lexicals go here
52 # here's a file-private function as a closure,
53 # callable as &$priv_func; it cannot be prototyped.
58 # make all your functions, whether exported or not;
66 # check renewal status
67 my ($env,$bornum,$itemno)=@_;
71 my $q1 = "select * from issues
72 where (borrowernumber = '$bornum')
73 and (itemnumber = '$itemno')
74 and returndate is null";
75 my $sth1 = $dbh->prepare($q1);
77 if (my $data1 = $sth1->fetchrow_hashref) {
78 my $q2 = "select renewalsallowed from items,biblioitems,itemtypes
79 where (items.itemnumber = '$itemno')
80 and (items.biblioitemnumber = biblioitems.biblioitemnumber)
81 and (biblioitems.itemtype = itemtypes.itemtype)";
82 my $sth2 = $dbh->prepare($q2);
84 if (my $data2=$sth2->fetchrow_hashref) {
85 $renews = $data2->{'renewalsallowed'};
87 if ($renews > $data1->{'renewals'}) {
99 # mark book as renewed
100 my ($env,$bornum,$itemno,$datedue)=@_;
102 if ($datedue eq "" ) {
103 #debug_msg($env, "getting date");
105 my $query= "Select * from biblioitems,items,itemtypes
106 where (items.itemnumber = '$itemno')
107 and (biblioitems.biblioitemnumber = items.biblioitemnumber)
108 and (biblioitems.itemtype = itemtypes.itemtype)";
109 my $sth=$dbh->prepare($query);
111 if (my $data=$sth->fetchrow_hashref) {
112 $loanlength = $data->{'loanlength'}
116 my $datedu = time + ($loanlength * 86400);
117 my @datearr = localtime($datedu);
118 $datedue = (1900+$datearr[5])."-".($datearr[4]+1)."-".$datearr[3];
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);
134 UpdateStats($env,$env->{'branchcode'},'renew','','',$itemno);
135 my ($charge,$type)=calc_charges($env, $itemno, $bornum);
137 my $accountno=getnextacctno($env,$bornum,$dbh);
138 my $item=getiteminformation($env, $itemno);
139 my $account="Insert into accountlines
140 (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
142 ('$bornum','$accountno',now(),$charge,'Renewal of Rental Item $item->{'title'} $item->{'barcode'}','Rent',$charge,'$itemno')";
143 $sth=$dbh->prepare($account);
155 # calculate charges due
156 my ($env, $itemno, $bornum)=@_;
160 my $q1 = "select itemtypes.itemtype,rentalcharge from
161 items,biblioitems,itemtypes
162 where (items.itemnumber ='$itemno')
163 and (biblioitems.biblioitemnumber = items.biblioitemnumber)
164 and (biblioitems.itemtype = itemtypes.itemtype)";
165 my $sth1= $dbh->prepare($q1);
167 if (my $data1=$sth1->fetchrow_hashref) {
168 $item_type = $data1->{'itemtype'};
169 $charge = $data1->{'rentalcharge'};
170 my $q2 = "select rentaldiscount from
171 borrowers,categoryitem
172 where (borrowers.borrowernumber = '$bornum')
173 and (borrowers.categorycode = categoryitem.categorycode)
174 and (categoryitem.itemtype = '$item_type')";
175 my $sth2=$dbh->prepare($q2);
177 if (my$data2=$sth2->fetchrow_hashref) {
178 my $discount = $data2->{'rentaldiscount'};
179 $charge = ($charge *(100 - $discount)) / 100;
185 # print "item $item_type";
186 return ($charge,$item_type);
190 END { } # module clean-up code here (global destructor)