1 package C4::Circulation::Fines; #asummes C4/Circulation/Fines
3 #requires DBI.pm to be installed
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
28 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
30 # set the version for version checking
34 @EXPORT = qw(&Getoverdues &CalcFine &BorType &UpdateFine &ReplacementCost);
35 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
37 # your exported package globals go here,
38 # as well as any optionally exported functions
40 @EXPORT_OK = qw($Var1 %Hashit);
43 # non-exported package globals go here
44 use vars qw(@more $stuff);
46 # initalize package globals, first exported ones
52 # then the others (which are still accessible as $Some::Module::stuff)
56 # all file-scoped lexicals must be created before
57 # the functions below that use them.
59 # file-private lexicals go here
63 # here's a file-private function as a closure,
64 # callable as &$priv_func; it cannot be prototyped.
69 # make all your functions, whether exported or not;
74 my $query="Select * from issues where date_due < now() and returndate is
75 NULL order by borrowernumber";
76 my $sth=$dbh->prepare($query);
80 while (my $data=$sth->fetchrow_hashref){
91 my ($itemnumber,$bortype,$difference)=@_;
93 my $query="Select * from items,biblioitems,itemtypes,categoryitem where items.itemnumber=$itemnumber
94 and items.biblioitemnumber=biblioitems.biblioitemnumber and
95 biblioitems.itemtype=itemtypes.itemtype and
96 categoryitem.itemtype=itemtypes.itemtype and
97 categoryitem.categorycode='$bortype' and (items.itemlost <> 1 or items.itemlost is NULL)";
98 my $sth=$dbh->prepare($query);
101 my $data=$sth->fetchrow_hashref;
105 if ($difference == $data->{'firstremind'}){
106 $amount=$data->{'fine'};
107 $printout="First Notice";
109 my $second=$data->{'firstremind'}+$data->{'chargeperiod'};
110 if ($difference == $second){
111 $amount=$data->{'fine'}*2;
112 $printout="Second Notice";
114 if ($difference == $data->{'accountsent'} && $data->{'fine'} > 0){
116 $printout="Final Notice";
119 return($amount,$data->{'chargename'},$printout);
123 my ($itemnum,$bornum,$amount,$type,$due)=@_;
125 my $query="Select * from accountlines where itemnumber=$itemnum and
126 borrowernumber=$bornum and (accounttype='FU' or accounttype='O' or
127 accounttype='F' or accounttype='M') and description like '%$due%'";
128 my $sth=$dbh->prepare($query);
132 if (my $data=$sth->fetchrow_hashref){
133 # print "in accounts ...";
134 if ($data->{'amount'} != $amount){
137 my $diff=$amount - $data->{'amount'};
138 my $out=$data->{'amountoutstanding'}+$diff;
139 my $query2="update accountlines set date=now(), amount=$amount,
140 amountoutstanding=$out,accounttype='FU' where
141 borrowernumber=$data->{'borrowernumber'} and itemnumber=$data->{'itemnumber'}
142 and (accounttype='FU' or accounttype='O') and description like '%$due%'";
143 my $sth2=$dbh->prepare($query2);
147 # print "no update needed $data->{'amount'}"
150 my $query2="select title from biblio,items where items.itemnumber=$itemnum
151 and biblio.biblionumber=items.biblionumber";
152 my $sth4=$dbh->prepare($query2);
154 my $title=$sth4->fetchrow_hashref;
156 # print "not in account";
157 my $query2="Select max(accountno) from accountlines";
158 my $sth3=$dbh->prepare($query2);
160 my @accountno=$sth3->fetchrow_array;
163 $title->{'title'}=~ s/\'/\\\'/g;
164 $query2="Insert into accountlines
165 (borrowernumber,itemnumber,date,amount,
166 description,accounttype,amountoutstanding,accountno) values
167 ($bornum,$itemnum,now(),$amount,'$type $title->{'title'} $due','FU',
168 $amount,$accountno[0])";
169 my $sth2=$dbh->prepare($query2);
178 my ($borrowernumber)=@_;
180 my $query="Select * from borrowers,categories where
181 borrowernumber=$borrowernumber and
182 borrowers.categorycode=categories.categorycode";
183 my $sth=$dbh->prepare($query);
185 my $data=$sth->fetchrow_hashref;
194 my $query="Select replacementprice from items where itemnumber='$itemnum'";
195 my $sth=$dbh->prepare($query);
197 my $data=$sth->fetchrow_hashref;
200 return($data->{'replacementprice'});
203 END { } # module clean-up code here (global destructor)