Browse Source

Recatgorises borowers, should only be run once after data is loaded in

master
chris 25 years ago
parent
commit
da7110eac2
  1. 19
      C4/Circulation/Fines.pm
  2. 2
      fines.pl
  3. 196
      fixborrower.pl

19
C4/Circulation/Fines.pm

@ -72,26 +72,21 @@ sub Getoverdues{
sub CalcFine {
my ($itemnumber,$bortype,$difference)=@_;
my $dbh=C4Connect;
my $query="Select * from items,biblioitems,itemtypes where items.itemnumber=$itemnumber
my $query="Select * from items,biblioitems,itemtypes,categoryitem where items.itemnumber=$itemnumber
and items.biblioitemnumber=biblioitems.biblioitemnumber and
biblioitems.itemtype=itemtypes.itemtype";
biblioitems.itemtype=itemtypes.itemtype and
categoryitem.itemtype=itemtypes.itemtype and
categoryitem.categorycode='$bortype'";
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;
if ($difference >= $data->{'startcharge'}){
my $temp=$difference % $data->{'chargeperiod'};
$difference=$difference - $temp;
$amount=($difference / 7) * 1.00;
}
} elsif ($data->{'itemtype'} eq 'VID'){
if ($difference > 2){
$difference=$difference-2;
$amount=.50 * difference;
}
$amount=($difference / $data->{'chargeperiod'}) * $data->{'fine'};
}
$dbh->disconnect;
return($amount);

2
fines.pl

@ -26,7 +26,7 @@ for (my $i=0;$i<$count;$i++){
}
if ($borrower->{'description'} !~ /Staff/ && $borrower->{'description'} !~ /Branch/){
my ($amount)=CalcFine($data->[$i]->{'itemnumber'},$borrower->{'description'},$difference);
my ($amount)=CalcFine($data->[$i]->{'itemnumber'},$borrower->{'categorycode'},$difference);
if ($amount > $max){
$amount=25;
}

196
fixborrower.pl

@ -0,0 +1,196 @@
#!/usr/bin/perl
use C4::Database;
use strict;
my $dbh=C4Connect;
my $query = "Select * from categories where categorycode like 'L%' or categorycode like 'F%'
or categorycode like 'S%' or categorycode like 'O%' or categorycode like 'H%' and categorycode <>'HR'
and categorycode <> 'ST'";
my $sth=$dbh->prepare($query);
$sth->execute;
while (my $data=$sth->fetchrow_hashref){
#update borrowers corresponding
#update categories
my $temp=substr($data->{'categorycode'},0,1);
$query="update borrowers set area='$temp' where categorycode='$data->{'categorycode'}'";
my $sth2=$dbh->prepare($query);
$sth2->execute;
$sth2->finish;
$temp=substr($data->{'categorycode'},1,1);
$query="update borrowers set categorycode='$temp' where categorycode='$data->{'categorycode'}'";
$sth2=$dbh->prepare($query);
$sth2->execute;
$sth2->finish;
$query="delete from categories where categorycode='$data->{'categorycode'}'";
$sth2=$dbh->prepare($query);
$sth2->execute;
$sth2->finish;
}
my $query = "Select * from categories where categorycode = 'ST'";
my $sth=$dbh->prepare($query);
$sth->execute;
while (my $data=$sth->fetchrow_hashref){
#update borrowers corresponding
#update categories
$query="update borrowers set area='' where categorycode='$data->{'categorycode'}'";
my $sth2=$dbh->prepare($query);
$sth2->execute;
$sth2->finish;
$query="update borrowers set categorycode='W' where categorycode='$data->{'categorycode'}'";
$sth2=$dbh->prepare($query);
$sth2->execute;
$sth2->finish;
$query="delete from categories where categorycode='$data->{'categorycode'}'";
$sth2=$dbh->prepare($query);
$sth2->execute;
$sth2->finish;
}
my $query = "Select * from categories where categorycode = 'BR' or categorycode='CO' or categorycode='IS'";
my $sth=$dbh->prepare($query);
$sth->execute;
while (my $data=$sth->fetchrow_hashref){
#update borrowers corresponding
#update categories
$query="update borrowers set area='' where categorycode='$data->{'categorycode'}'";
my $sth2=$dbh->prepare($query);
$sth2->execute;
$sth2->finish;
$query="update borrowers set categorycode='I' where categorycode='$data->{'categorycode'}'";
$sth2=$dbh->prepare($query);
$sth2->execute;
$sth2->finish;
$query="delete from categories where categorycode='$data->{'categorycode'}'";
$sth2=$dbh->prepare($query);
$sth2->execute;
$sth2->finish;
}
my $query = "Select * from categories where categorycode = 'TD' or categorycode='TR'";
my $sth=$dbh->prepare($query);
$sth->execute;
while (my $data=$sth->fetchrow_hashref){
#update borrowers corresponding
#update categories
$query="update borrowers set area='X' where categorycode='$data->{'categorycode'}'";
my $sth2=$dbh->prepare($query);
$sth2->execute;
$sth2->finish;
$query="update borrowers set categorycode='A' where categorycode='$data->{'categorycode'}'";
$sth2=$dbh->prepare($query);
$sth2->execute;
$sth2->finish;
$query="delete from categories where categorycode='$data->{'categorycode'}'";
$sth2=$dbh->prepare($query);
$sth2->execute;
$sth2->finish;
}
my $query = "Select * from categories where categorycode = 'HR'";
my $sth=$dbh->prepare($query);
$sth->execute;
while (my $data=$sth->fetchrow_hashref){
#update borrowers corresponding
#update categories
$query="update borrowers set area='K' where categorycode='$data->{'categorycode'}'";
my $sth2=$dbh->prepare($query);
$sth2->execute;
$sth2->finish;
$query="update borrowers set categorycode='A' where categorycode='$data->{'categorycode'}'";
$sth2=$dbh->prepare($query);
$sth2->execute;
$sth2->finish;
$query="delete from categories where categorycode='$data->{'categorycode'}'";
$sth2=$dbh->prepare($query);
$sth2->execute;
$sth2->finish;
}
my $query = "Select * from categories where categorycode = 'IL'";
my $sth=$dbh->prepare($query);
$sth->execute;
while (my $data=$sth->fetchrow_hashref){
#update borrowers corresponding
#update categories
$query="update borrowers set area='Z' where categorycode='$data->{'categorycode'}'";
my $sth2=$dbh->prepare($query);
$sth2->execute;
$sth2->finish;
$query="update borrowers set categorycode='L' where categorycode='$data->{'categorycode'}'";
$sth2=$dbh->prepare($query);
$sth2->execute;
$sth2->finish;
$query="delete from categories where categorycode='$data->{'categorycode'}'";
$sth2=$dbh->prepare($query);
$sth2->execute;
$sth2->finish;
}
my $query = "Select * from categories where categorycode = 'TB'";
my $sth=$dbh->prepare($query);
$sth->execute;
while (my $data=$sth->fetchrow_hashref){
#update borrowers corresponding
#update categories
$query="update borrowers set area='' where categorycode='$data->{'categorycode'}'";
my $sth2=$dbh->prepare($query);
$sth2->execute;
$sth2->finish;
$query="update borrowers set categorycode='P' where categorycode='$data->{'categorycode'}'";
$sth2=$dbh->prepare($query);
$sth2->execute;
$sth2->finish;
$query="delete from categories where categorycode='$data->{'categorycode'}'";
$sth2=$dbh->prepare($query);
$sth2->execute;
$sth2->finish;
}
$sth->finish;
$query="insert into categories values ('A','Adult',5,99,0,'A',0,0,0,99,1)";
$sth=$dbh->prepare($query);
$sth->execute;
$sth->finish;
$query="insert into categories values ('E','Senior Citizen',5,99,0,'A',0,0,0,99,1)";
$sth=$dbh->prepare($query);
$sth->execute;
$sth->finish;
$query="insert into categories values ('C','Child',5,16,0,'A',0,0,0,99,1)";
$sth=$dbh->prepare($query);
$sth->execute;
$sth->finish;
$query="insert into categories values ('B','Housebound',5,99,0,'E',0,0,0,99,1)";
$sth=$dbh->prepare($query);
$sth->execute;
$sth->finish;
$query="insert into categories values ('F','Family',5,99,0,'A',0,0,0,99,1)";
$sth=$dbh->prepare($query);
$sth->execute;
$sth->finish;
$query="insert into categories values ('W','Workers',5,99,0,'A',0,0,0,99,1)";
$sth=$dbh->prepare($query);
$sth->execute;
$sth->finish;
$query="insert into categories values ('I','Institution',5,99,0,'A',0,0,0,99,1)";
$sth=$dbh->prepare($query);
$sth->execute;
$sth->finish;
$query="insert into categories values ('P','Privileged',5,99,0,'A',0,0,0,99,1)";
$sth=$dbh->prepare($query);
$sth->execute;
$sth->finish;
$query="insert into categories values ('L','Library',5,99,0,'A',0,0,0,99,1)";
$sth=$dbh->prepare($query);
$sth->execute;
$sth->finish;
$dbh->disconnect;
Loading…
Cancel
Save