Kumara - predecessor to Koha
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
4.1 KiB

package C4::Circulation::Fines; #asummes C4/Circulation/Fines
#requires DBI.pm to be installed
#uses DBD:Pg
use strict;
require Exporter;
use DBI;
use C4::Database;
# set the version for version checking
$VERSION = 0.01;
@ISA = qw(Exporter);
@EXPORT = qw(&Getoverdues &CalcFine &BorType &UpdateFine);
%EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
# your exported package globals go here,
# as well as any optionally exported functions
@EXPORT_OK = qw($Var1 %Hashit);
# non-exported package globals go here
use vars qw(@more $stuff);
# initalize package globals, first exported ones
my $Var1 = '';
my %Hashit = ();
# then the others (which are still accessible as $Some::Module::stuff)
my $stuff = '';
my @more = ();
# all file-scoped lexicals must be created before
# the functions below that use them.
# file-private lexicals go here
my $priv_var = '';
my %secret_hash = ();
# here's a file-private function as a closure,
# callable as &$priv_func; it cannot be prototyped.
my $priv_func = sub {
# stuff goes here.
# make all your functions, whether exported or not;
sub Getoverdues{
my $dbh=C4Connect;
my $query="Select * from issues where date_due < now() and returndate is
NULL order by borrowernumber";
my $sth=$dbh->prepare($query);
my $i=0;
my @results;
while (my $data=$sth->fetchrow_hashref){
# print @results;
sub CalcFine {
my ($itemnumber,$bortype,$difference)=@_;
my $dbh=C4Connect;
my $query="Select * from items,biblioitems,itemtypes,categoryitem where items.itemnumber=$itemnumber
and items.biblioitemnumber=biblioitems.biblioitemnumber and
biblioitems.itemtype=itemtypes.itemtype and
categoryitem.itemtype=itemtypes.itemtype and
categoryitem.categorycode='$bortype' and items.itemlost <> 1";
my $sth=$dbh->prepare($query);
# print $query;
my $data=$sth->fetchrow_hashref;
my $amount=0;
if ($difference >= $data->{'startcharge'}){
if ($data->{'chargeperiod'} != 0){
my $temp=$difference % $data->{'chargeperiod'};
$difference=$difference - $temp;
$amount=($difference / $data->{'chargeperiod'}) * $data->{'fine'};
sub UpdateFine {
my ($itemnum,$bornum,$amount)=@_;
my $dbh=C4Connect;
my $query="Select * from accountlines where itemnumber=$itemnum and
borrowernumber=$bornum and accounttype='FU'";
my $sth=$dbh->prepare($query);
if (my $data=$sth->fetchrow_hashref){
print "in accounts ...";
if ($data->{'amount'} != $amount){
print "updating";
my $diff=$amount - $data->{'amount'};
my $out=$data->{'amountoutstanding'}+$diff;
my $query2="update accountlines set date=now(), amount=$amount,
amountoutstanding=$out where accountno=$data->{'accountno'}";
my $sth2=$dbh->prepare($query2);
} else {
print "no update needed $data->{'amount'}"
} else {
print "not in account";
my $query2="Select max(accountno) from accountlines";
my $sth3=$dbh->prepare($query2);
my @accountno=$sth3->fetchrow_array;
$query2="Insert into accountlines
description,accounttype,amountoutstanding,accountno) values
($bornum,$itemnum,now(),$amount,'Overdue Item','FU',
my $sth2=$dbh->prepare($query2);
sub BorType {
my ($borrowernumber)=@_;
my $dbh=C4Connect;
my $query="Select borrowers.categorycode,description from borrowers,categories where
borrowernumber=$borrowernumber and
my $sth=$dbh->prepare($query);
my $data=$sth->fetchrow_hashref;
END { } # module clean-up code here (global destructor)