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
15 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
17 # set the version for version checking
21 @EXPORT = qw(&renewstatus &renewbook &calc_charges);
22 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
24 # your exported package globals go here,
25 # as well as any optionally exported functions
27 @EXPORT_OK = qw($Var1 %Hashit);
30 # non-exported package globals go here
31 use vars qw(@more $stuff);
33 # initalize package globals, first exported ones
38 # then the others (which are still accessible as $Some::Module::stuff)
42 # all file-scoped lexicals must be created before
43 # the functions below that use them.
45 # file-private lexicals go here
49 # here's a file-private function as a closure,
50 # callable as &$priv_func; it cannot be prototyped.
55 # make all your functions, whether exported or not;
63 # check renewal status
64 my ($env,$bornum,$itemno)=@_;
68 my $q1 = "select * from issues
69 where (borrowernumber = '$bornum')
70 and (itemnumber = '$itemno')
71 and returndate is null";
72 my $sth1 = $dbh->prepare($q1);
74 if (my $data1 = $sth1->fetchrow_hashref) {
75 my $q2 = "select renewalsallowed from items,biblioitems,itemtypes
76 where (items.itemnumber = '$itemno')
77 and (items.biblioitemnumber = biblioitems.biblioitemnumber)
78 and (biblioitems.itemtype = itemtypes.itemtype)";
79 my $sth2 = $dbh->prepare($q2);
81 if (my $data2=$sth2->fetchrow_hashref) {
82 $renews = $data2->{'renewalsallowed'};
84 if ($renews > $data1->{'renewals'}) {
96 # mark book as renewed
97 my ($env,$bornum,$itemno,$datedue)=@_;
99 if ($datedue eq "" ) {
100 #debug_msg($env, "getting date");
102 my $query= "Select * from biblioitems,items,itemtypes
103 where (items.itemnumber = '$itemno')
104 and (biblioitems.biblioitemnumber = items.biblioitemnumber)
105 and (biblioitems.itemtype = itemtypes.itemtype)";
106 my $sth=$dbh->prepare($query);
108 if (my $data=$sth->fetchrow_hashref) {
109 $loanlength = $data->{'loanlength'}
113 my $datedu = time + ($loanlength * 86400);
114 my @datearr = localtime($datedu);
115 $datedue = (1900+$datearr[5])."-".($datearr[4]+1)."-".$datearr[3];
117 my $issquery = "select * from issues where borrowernumber='$bornum' and
118 itemnumber='$itemno' and returndate is null";
119 my $sth=$dbh->prepare($issquery);
121 my $issuedata=$sth->fetchrow_hashref;
123 my $renews = $issuedata->{'renewals'} +1;
124 my $updquery = "update issues
125 set date_due = '$datedue', renewals = '$renews'
126 where borrowernumber='$bornum' and
127 itemnumber='$itemno' and returndate is null";
128 my $sth=$dbh->prepare($updquery);
131 UpdateStats($env,$env->{'branchcode'},'renew','','',$itemno);
138 # calculate charges due
139 my ($env, $itemno, $bornum)=@_;
143 my $q1 = "select itemtypes.itemtype,rentalcharge from
144 items,biblioitems,itemtypes
145 where (items.itemnumber ='$itemno')
146 and (biblioitems.biblioitemnumber = items.biblioitemnumber)
147 and (biblioitems.itemtype = itemtypes.itemtype)";
148 my $sth1= $dbh->prepare($q1);
150 if (my $data1=$sth1->fetchrow_hashref) {
151 $item_type = $data1->{'itemtype'};
152 $charge = $data1->{'rentalcharge'};
153 my $q2 = "select rentaldiscount from
154 borrowers,categoryitem
155 where (borrowers.borrowernumber = '$bornum')
156 and (borrowers.categorycode = categoryitem.categorycode)
157 and (categoryitem.itemtype = '$item_type')";
158 my $sth2=$dbh->prepare($q2);
160 if (my$data2=$sth2->fetchrow_hashref) {
161 my $discount = $data2->{'rentaldiscount'};
162 $charge = ($charge *(100 - $discount)) / 100;
168 # print "item $item_type";
169 return ($charge,$item_type);
173 END { } # module clean-up code here (global destructor)