1 package C4::Circulation::Fines; #asummes C4/Circulation/Fines
3 #requires DBI.pm to be installed
10 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
12 # set the version for version checking
16 @EXPORT = qw(&Getoverdues &CalcFine &BorType &UpdateFine &ReplacementCost);
17 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
19 # your exported package globals go here,
20 # as well as any optionally exported functions
22 @EXPORT_OK = qw($Var1 %Hashit);
25 # non-exported package globals go here
26 use vars qw(@more $stuff);
28 # initalize package globals, first exported ones
34 # then the others (which are still accessible as $Some::Module::stuff)
38 # all file-scoped lexicals must be created before
39 # the functions below that use them.
41 # file-private lexicals go here
45 # here's a file-private function as a closure,
46 # callable as &$priv_func; it cannot be prototyped.
51 # make all your functions, whether exported or not;
56 my $query="Select * from issues where date_due < now() and returndate is
57 NULL order by borrowernumber";
58 my $sth=$dbh->prepare($query);
62 while (my $data=$sth->fetchrow_hashref){
73 my ($itemnumber,$bortype,$difference)=@_;
75 my $query="Select * from items,biblioitems,itemtypes,categoryitem where items.itemnumber=$itemnumber
76 and items.biblioitemnumber=biblioitems.biblioitemnumber and
77 biblioitems.itemtype=itemtypes.itemtype and
78 categoryitem.itemtype=itemtypes.itemtype and
79 categoryitem.categorycode='$bortype' and (items.itemlost <> 1 or items.itemlost is NULL)";
80 my $sth=$dbh->prepare($query);
83 my $data=$sth->fetchrow_hashref;
87 if ($difference == $data->{'firstremind'}){
88 $amount=$data->{'fine'};
89 $printout="First Notice";
91 my $second=$data->{'firstremind'}+$data->{'chargeperiod'};
92 if ($difference == $second){
93 $amount=$data->{'fine'}*2;
94 $printout="Second Notice";
96 if ($difference == $data->{'accountsent'} && $data->{'fine'} > 0){
98 $printout="Final Notice";
101 return($amount,$data->{'chargename'},$printout);
105 my ($itemnum,$bornum,$amount,$type,$due)=@_;
107 my $query="Select * from accountlines where itemnumber=$itemnum and
108 borrowernumber=$bornum and (accounttype='FU' or accounttype='O' or
109 accounttype='F' or accounttype='M') and description like '%$due%'";
110 my $sth=$dbh->prepare($query);
114 if (my $data=$sth->fetchrow_hashref){
115 # print "in accounts ...";
116 if ($data->{'amount'} != $amount){
119 my $diff=$amount - $data->{'amount'};
120 my $out=$data->{'amountoutstanding'}+$diff;
121 my $query2="update accountlines set date=now(), amount=$amount,
122 amountoutstanding=$out,accounttype='FU' where
123 borrowernumber=$data->{'borrowernumber'} and itemnumber=$data->{'itemnumber'}
124 and (accounttype='FU' or accounttype='O') and description like '%$due%'";
125 my $sth2=$dbh->prepare($query2);
129 # print "no update needed $data->{'amount'}"
132 my $query2="select title from biblio,items where items.itemnumber=$itemnum
133 and biblio.biblionumber=items.biblionumber";
134 my $sth4=$dbh->prepare($query2);
136 my $title=$sth4->fetchrow_hashref;
138 # print "not in account";
139 my $query2="Select max(accountno) from accountlines";
140 my $sth3=$dbh->prepare($query2);
142 my @accountno=$sth3->fetchrow_array;
145 $title->{'title'}=~ s/\'/\\\'/g;
146 $query2="Insert into accountlines
147 (borrowernumber,itemnumber,date,amount,
148 description,accounttype,amountoutstanding,accountno) values
149 ($bornum,$itemnum,now(),$amount,'$type $title->{'title'} $due','FU',
150 $amount,$accountno[0])";
151 my $sth2=$dbh->prepare($query2);
160 my ($borrowernumber)=@_;
162 my $query="Select * from borrowers,categories where
163 borrowernumber=$borrowernumber and
164 borrowers.categorycode=categories.categorycode";
165 my $sth=$dbh->prepare($query);
167 my $data=$sth->fetchrow_hashref;
176 my $query="Select replacementprice from items where itemnumber='$itemnum'";
177 my $sth=$dbh->prepare($query);
179 my $data=$sth->fetchrow_hashref;
182 return($data->{'replacementprice'});
185 END { } # module clean-up code here (global destructor)