working on overdues
This commit is contained in:
parent
86f9b372a2
commit
df3241c8cf
3 changed files with 130 additions and 16 deletions
|
@ -13,7 +13,7 @@ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
|
|||
$VERSION = 0.01;
|
||||
|
||||
@ISA = qw(Exporter);
|
||||
@EXPORT = qw(&Getoverdues);
|
||||
@EXPORT = qw(&Getoverdues &CalcFine &BorType &UpdateFine);
|
||||
%EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
|
||||
|
||||
# your exported package globals go here,
|
||||
|
@ -53,13 +53,105 @@ my $priv_func = sub {
|
|||
|
||||
sub Getoverdues{
|
||||
my $dbh=C4Connect;
|
||||
my $query="Select count(*) from issues where date_due >= now()";
|
||||
my $query="Select * from issues where date_due < now() and returndate is
|
||||
NULL order by borrowernumber";
|
||||
my $sth=$dbh->prepare($query);
|
||||
$sth->execute;
|
||||
my $count=$sth->fetchrow_hashref;
|
||||
my $i=0;
|
||||
my @results;
|
||||
while (my $data=$sth->fetchrow_hashref){
|
||||
$results[$i]=$data;
|
||||
$i++;
|
||||
}
|
||||
$sth->finish;
|
||||
$dbh->disconnect;
|
||||
return($count->{'count(*)'});
|
||||
# print @results;
|
||||
return($i,\@results);
|
||||
}
|
||||
|
||||
sub CalcFine {
|
||||
my ($itemnumber,$bortype,$difference)=@_;
|
||||
my $dbh=C4Connect;
|
||||
my $query="Select * from items,biblioitems,itemtypes where items.itemnumber=$itemnumber
|
||||
and items.biblioitemnumber=biblioitems.biblioitemnumber and
|
||||
biblioitems.itemtype=itemtypes.itemtype";
|
||||
my $sth=$dbh->prepare($query);
|
||||
# print $query;
|
||||
$sth->execute;
|
||||
my $data=$sth->fetchrow_hashref;
|
||||
$sth->finish;
|
||||
my $amount=0;
|
||||
if ($data->{'itemtype'} eq 'NF'){
|
||||
if ($difference >= 7){
|
||||
my $temp=$difference % 7;
|
||||
$difference=$difference - $temp;
|
||||
$amount=($difference / 7) * 1.00;
|
||||
}
|
||||
} elsif ($data->{'itemtype'} eq 'VID'){
|
||||
if ($difference > 2){
|
||||
$difference=$difference-2;
|
||||
$amount=.50 * difference;
|
||||
}
|
||||
}
|
||||
$dbh->disconnect;
|
||||
return($amount);
|
||||
}
|
||||
|
||||
sub UpdateFine {
|
||||
my ($itemnum,$bornum,$amount)=@_;
|
||||
my $dbh=C4Connect;
|
||||
my $query="Select * from accountlines where itemnumber=$itemnum and
|
||||
borrowernumber=$bornum and accounttype='F'";
|
||||
my $sth=$dbh->prepare($query);
|
||||
$sth->execute;
|
||||
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);
|
||||
$sth2->execute;
|
||||
$sth2->finish;
|
||||
|
||||
} else {
|
||||
print "no update needed $data->{'amount'}"
|
||||
}
|
||||
} else {
|
||||
print "not in account";
|
||||
my $query2="Select max(accountno) from accountlines";
|
||||
my $sth3=$dbh->prepare($query2);
|
||||
$sth3->execute;
|
||||
my @accountno=$sth3->fetchrow_array;
|
||||
$sth3->finish;
|
||||
$accountno[0]++;
|
||||
$query2="Insert into accountlines
|
||||
(borrowernumber,itemnumber,date,amount,
|
||||
description,accounttype,amountoutstanding,accountno) values
|
||||
($bornum,$itemnum,now(),$amount,'Overdue Item','F',
|
||||
$amount,$accountno[0])";
|
||||
my $sth2=$dbh->prepare($query2);
|
||||
$sth2->execute;
|
||||
$sth2->finish;
|
||||
}
|
||||
$sth->finish;
|
||||
$dbh->disconnect;
|
||||
}
|
||||
|
||||
sub BorType {
|
||||
my ($borrowernumber)=@_;
|
||||
my $dbh=C4Connect;
|
||||
my $query="Select borrowers.categorycode,description from borrowers,categories where
|
||||
borrowernumber=$borrowernumber and
|
||||
borrowers.categorycode=categories.categorycode";
|
||||
my $sth=$dbh->prepare($query);
|
||||
$sth->execute;
|
||||
my $data=$sth->fetchrow_hashref;
|
||||
$sth->finish;
|
||||
$dbh->disconnect;
|
||||
return($data);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,10 +3,11 @@
|
|||
#script to keep total of number of issues;
|
||||
|
||||
use C4::Output;
|
||||
use C4::Stats;
|
||||
use C4::Circulation::Fines;
|
||||
use CGI;
|
||||
|
||||
my $input=new CGI;
|
||||
print $input->header;
|
||||
my $count=Overdues();
|
||||
my ($count,@data)=Getoverdues();
|
||||
print $count;
|
||||
print $data[0]->{'date_due'};
|
||||
|
|
41
fines.pl
41
fines.pl
|
@ -1,17 +1,38 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use C4::Database;
|
||||
use C4::Stats;
|
||||
#script to keep total of number of issues;
|
||||
|
||||
#script to total up fines and alter accounts
|
||||
#should be run nightly with a cron job or the like
|
||||
#written by chris@katipo.co.nz 30/12/99
|
||||
|
||||
my $dbh=C4Connect;
|
||||
use C4::Circulation::Fines;
|
||||
use Date::Manip;
|
||||
|
||||
my $count=Overdues;
|
||||
my ($count,$data)=Getoverdues();
|
||||
print $count;
|
||||
my $count2=0;
|
||||
#$count=1000;
|
||||
my $date=Date_DaysSince999(12,30,1999);
|
||||
my $bornum;
|
||||
my $borrower;
|
||||
my $max=25;
|
||||
for (my $i=0;$i<$count;$i++){
|
||||
my @dates=split('-',$data->[$i]->{'date_due'});
|
||||
my $date2=Date_DaysSince999($dates[1],$date[2],$dates[0]);
|
||||
if ($date2 <= $date){
|
||||
$count2++;
|
||||
my $difference=$date-$date2;
|
||||
if ($bornum != $data->[$i]->{'borrowernumber'}){
|
||||
$bornum=$data->[$i]->{'borrowernumber'};
|
||||
$borrower=BorType($bornum);
|
||||
}
|
||||
|
||||
|
||||
$dbh->disconnect;
|
||||
if ($borrower->{'description'} !~ /Staff/ && $borrower->{'description'} !~ /Branch/){
|
||||
my ($amount)=CalcFine($data->[$i]->{'itemnumber'},$borrower->{'description'},$difference);
|
||||
if ($amount > $max){
|
||||
$amount=25;
|
||||
}
|
||||
UpdateFine($data->[$i]->{'itemnumber'},$bornum,$amount);
|
||||
print "$amount\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
print "\n $count2\n";
|
||||
|
|
Loading…
Reference in a new issue