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;
73 my $dbh = C4::Context->dbh;
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){
90 my ($itemnumber,$bortype,$difference)=@_;
91 my $dbh = C4::Context->dbh;
92 my $query="Select * from items,biblioitems,itemtypes,categoryitem where items.itemnumber=$itemnumber
93 and items.biblioitemnumber=biblioitems.biblioitemnumber and
94 biblioitems.itemtype=itemtypes.itemtype and
95 categoryitem.itemtype=itemtypes.itemtype and
96 categoryitem.categorycode='$bortype' and (items.itemlost <> 1 or items.itemlost is NULL)";
97 my $sth=$dbh->prepare($query);
100 my $data=$sth->fetchrow_hashref;
104 if ($difference == $data->{'firstremind'}){
105 $amount=$data->{'fine'};
106 $printout="First Notice";
108 my $second=$data->{'firstremind'}+$data->{'chargeperiod'};
109 if ($difference == $second){
110 $amount=$data->{'fine'}*2;
111 $printout="Second Notice";
113 if ($difference == $data->{'accountsent'} && $data->{'fine'} > 0){
115 $printout="Final Notice";
117 return($amount,$data->{'chargename'},$printout);
121 my ($itemnum,$bornum,$amount,$type,$due)=@_;
122 my $dbh = C4::Context->dbh;
123 my $query="Select * from accountlines where itemnumber=$itemnum and
124 borrowernumber=$bornum and (accounttype='FU' or accounttype='O' or
125 accounttype='F' or accounttype='M') and description like '%$due%'";
126 my $sth=$dbh->prepare($query);
130 if (my $data=$sth->fetchrow_hashref){
131 # print "in accounts ...";
132 if ($data->{'amount'} != $amount){
135 my $diff=$amount - $data->{'amount'};
136 my $out=$data->{'amountoutstanding'}+$diff;
137 my $query2="update accountlines set date=now(), amount=$amount,
138 amountoutstanding=$out,accounttype='FU' where
139 borrowernumber=$data->{'borrowernumber'} and itemnumber=$data->{'itemnumber'}
140 and (accounttype='FU' or accounttype='O') and description like '%$due%'";
141 my $sth2=$dbh->prepare($query2);
145 # print "no update needed $data->{'amount'}"
148 my $query2="select title from biblio,items where items.itemnumber=$itemnum
149 and biblio.biblionumber=items.biblionumber";
150 my $sth4=$dbh->prepare($query2);
152 my $title=$sth4->fetchrow_hashref;
154 # print "not in account";
155 # FIXME - There's already a $query2 in this scope.
156 my $query2="Select max(accountno) from accountlines";
157 my $sth3=$dbh->prepare($query2);
159 my @accountno=$sth3->fetchrow_array;
162 $title->{'title'}=~ s/\'/\\\'/g;
163 $query2="Insert into accountlines
164 (borrowernumber,itemnumber,date,amount,
165 description,accounttype,amountoutstanding,accountno) values
166 ($bornum,$itemnum,now(),$amount,'$type $title->{'title'} $due','FU',
167 $amount,$accountno[0])";
168 my $sth2=$dbh->prepare($query2);
176 my ($borrowernumber)=@_;
177 my $dbh = C4::Context->dbh;
178 my $query="Select * from borrowers,categories where
179 borrowernumber=$borrowernumber and
180 borrowers.categorycode=categories.categorycode";
181 my $sth=$dbh->prepare($query);
183 my $data=$sth->fetchrow_hashref;
190 my $dbh = C4::Context->dbh;
191 my $query="Select replacementprice from items where itemnumber='$itemnum'";
192 my $sth=$dbh->prepare($query);
194 my $data=$sth->fetchrow_hashref;
196 return($data->{'replacementprice'});
199 END { } # module clean-up code here (global destructor)