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);
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
80 items.itemlost is NULL)";
81 my $sth=$dbh->prepare($query);
84 my $data=$sth->fetchrow_hashref;
88 if ($difference == $data->{'firstremind'}){
89 $amount=$data->{'fine'};
90 $printout="First Notice";
92 my $second=$data->{'firstremind'}+$data->{'chargeperiod'};
93 if ($difference == $second){
94 $amount=$data->{'fine'}*2;
95 $printout="Second Notice";
97 if ($difference == $data->{'accountsent'} && $data->{'fine'} > 0){
99 $printout="Final Notice";
102 return($amount,$data->{'chargename'},$printout);
106 my ($itemnum,$bornum,$amount,$type,$due)=@_;
108 my $query="Select * from accountlines where itemnumber=$itemnum and
109 borrowernumber=$bornum and (accounttype='FU' or accounttype='O' or
110 accounttype='F' or accounttype='M') and description like '%$due%'";
111 my $sth=$dbh->prepare($query);
115 if (my $data=$sth->fetchrow_hashref){
116 # print "in accounts ...";
117 if ($data->{'amount'} != $amount){
120 my $diff=$amount - $data->{'amount'};
121 my $out=$data->{'amountoutstanding'}+$diff;
122 my $query2="update accountlines set date=now(), amount=$amount,
123 amountoutstanding=$out,accounttype='FU' where
124 borrowernumber=$data->{'borrowernumber'} and itemnumber=$data->{'itemnumber'}
125 and (accounttype='FU' or accounttype='O');";
126 my $sth2=$dbh->prepare($query2);
130 # print "no update needed $data->{'amount'}"
133 my $query2="select title from biblio,items where items.itemnumber=$itemnum
134 and biblio.biblionumber=items.biblionumber";
135 my $sth4=$dbh->prepare($query2);
137 my $title=$sth4->fetchrow_hashref;
139 # print "not in account";
140 my $query2="Select max(accountno) from accountlines";
141 my $sth3=$dbh->prepare($query2);
143 my @accountno=$sth3->fetchrow_array;
146 $title->{'title'}=~ s/\'/\\\'/g;
147 $query2="Insert into accountlines
148 (borrowernumber,itemnumber,date,amount,
149 description,accounttype,amountoutstanding,accountno) values
150 ($bornum,$itemnum,now(),$amount,'$type $title->{'title'} $due','FU',
151 $amount,$accountno[0])";
152 my $sth2=$dbh->prepare($query2);
161 my ($borrowernumber)=@_;
163 my $query="Select * from borrowers,categories where
164 borrowernumber=$borrowernumber and
165 borrowers.categorycode=categories.categorycode";
166 my $sth=$dbh->prepare($query);
168 my $data=$sth->fetchrow_hashref;
175 END { } # module clean-up code here (global destructor)