UpdateDataBase for smart-rules modification

Members.pm :
Adding IsMemberBlocked
Circulation.pm :
Using IsMemberBlocked in order to implement finedays

Signed-off-by: Galen Charlton <gmcharlt@gmail.com>
This commit is contained in:
Henri-Damien LAURENT 2009-08-24 22:10:22 +02:00
parent 3c741d2376
commit 780cda46a2
3 changed files with 99 additions and 4 deletions

View file

@ -532,7 +532,6 @@ sub itemissues {
$data->{'date_due'} = ($data->{'wthdrawn'} eq '1') ? 'Cancelled' : 'Available';
}
$sth2->finish;
# Find the last 3 people who borrowed this item.
$sth2 = $dbh->prepare(
@ -552,12 +551,10 @@ sub itemissues {
} # if
} # for
$sth2->finish;
$results[$i] = $data;
$i++;
}
$sth->finish;
return (@results);
}
@ -731,7 +728,16 @@ sub CanBookBeIssued {
}
}
#
my ($blocktype, $count) = C4::Members::IsMemberBlocked($borrower->{'borrowernumber'});
if($blocktype == -1){
## remaining overdue documents
$issuingimpossible{USERBLOCKEDREMAINING} = $count;
}elsif($blocktype == 1){
## blocked because of overdue return
$issuingimpossible{USERBLOCKEDOVERDUE} = $count;
}
#
# JB34 CHECKS IF BORROWERS DONT HAVE ISSUE TOO MANY BOOKS
#
my $toomany = TooMany( $borrower, $item->{biblionumber}, $item );

View file

@ -63,6 +63,7 @@ BEGIN {
&PutPatronImage
&RmPatronImage
&IsMemberBlocked
&GetMemberAccountRecords
&GetBorNotifyAcctRecord
@ -511,6 +512,72 @@ LEFT JOIN categories on borrowers.categorycode=categories.categorycode
return undef;
}
=head2 IsMemberBlocked
=over 4
my $blocked = IsMemberBlocked( $borrowernumber );
return the status, and the number of day or documents, depends his punishment
return :
-1 if the user have overdue returns
1 if the user is punished X days
0 if the user is authorised to loan
=back
=cut
sub IsMemberBlocked {
my $borrowernumber = shift;
my $dbh = C4::Context->dbh;
# if he have late issues
my $sth = $dbh->prepare(
"SELECT COUNT(*) as latedocs
FROM issues
WHERE borrowernumber = ?
AND date_due < now()"
);
$sth->execute($borrowernumber);
my $latedocs = $sth->fetchrow_hashref->{'latedocs'};
return (-1, $latedocs) if $latedocs > 0;
my $strsth=qq{
SELECT
ADDDATE(returndate, finedays * DATEDIFF(returndate,date_due) ) AS blockingdate,
DATEDIFF(ADDDATE(returndate, finedays * DATEDIFF(returndate,date_due)),NOW()) AS blockedcount
FROM old_issues
};
# or if he must wait to loan
if(C4::Context->preference("item-level_itypes")){
$strsth.=
qq{ LEFT JOIN items ON (items.itemnumber=old_issues.itemnumber)
LEFT JOIN issuingrules ON (issuingrules.itemtype=items.itype)}
}else{
$strsth .=
qq{ LEFT JOIN items ON (items.itemnumber=old_issues.itemnumber)
LEFT JOIN biblioitems ON (biblioitems.biblioitemnumber=items.biblioitemnumber)
LEFT JOIN issuingrules ON (issuingrules.itemtype=biblioitems.itemtype) };
}
$strsth.=
qq{ WHERE finedays IS NOT NULL
AND date_due < returndate
AND borrowernumber = ?
ORDER BY blockingdate DESC, blockedcount DESC
LIMIT 1};
$sth=$dbh->prepare($strsth);
$sth->execute($borrowernumber);
my $row = $sth->fetchrow_hashref;
my $blockeddate = $row->{'blockeddate'};
my $blockedcount = $row->{'blockedcount'};
return (1, $blockedcount) if $blockedcount > 0;
return 0
}
=head2 GetMemberIssuesAndFines
($overdue_count, $issue_count, $total_fines) = &GetMemberIssuesAndFines($borrowernumber);

View file

@ -0,0 +1,22 @@
#! /usr/bin/perl
use strict;
use warnings;
use C4::Context;
my $dbh=C4::Context->dbh;
$dbh->do("ALTER TABLE issuingrules ADD
COLUMN `finedays` int(11) default NULL AFTER `fine`,
COLUMN `renewalsallowed` smallint(6) default NULL,
COLUMN `reservesallowed` smallint(6) default NULL,
");
$sth = $dbh->prepare("SELECT itemtype, renewalsallowed FROM itemtypes");
$sth->execute();
my $sthupd = $dbh->prepare("UPDATE issuingrules SET renewalsallowed = ? WHERE itemtype = ?");
while(my $row = $sth->fetchrow_hashref){
$sthupd->execute($row->{renewalsallowed}, $row->{itemtype});
}
$dbh->do('ALTER TABLE itemtypes DROP COLUMN `renewalsallowed`;');
print "Upgrade done (Adding finedays renewalsallowed, and reservesallowed fields in issuingrules table)\n";