From 0060634c36f0775ce7784724e3c8f87e5372b564 Mon Sep 17 00:00:00 2001 From: Nahuel ANGELINETTI Date: Wed, 28 Jan 2009 10:37:02 +0100 Subject: [PATCH] (bug #2929) permit to define "fine days" in issuing rules This patch add a function un C4::Members that check if a user is allowed to loan a document. Add a control in issuing. Add a column in issuingrules table. And add the needed control in admin to set the fine days rules. Signed-off-by: Henri-Damien LAURENT --- C4/Circulation.pm | 9 +++ C4/Members.pm | 77 +++++++++++++++++++ admin/smart-rules.pl | 9 ++- installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase30.pl | 6 ++ .../prog/en/modules/admin/smart-rules.tmpl | 7 ++ 6 files changed, 105 insertions(+), 4 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 85b848ce86..5c136b2382 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -701,6 +701,15 @@ 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 # diff --git a/C4/Members.pm b/C4/Members.pm index ec7ffe50a8..a5ad00317e 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -75,6 +75,8 @@ BEGIN { &GetBorrowersWithIssuesHistoryOlderThan &GetExpiryDate + + &IsMemberBlocked ); #Modify data @@ -2091,6 +2093,81 @@ sub DebarMember { } +=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'}; + $sth->finish(); + + return (-1, $latedocs) if $latedocs > 0; + + # or if he must wait to loan + if(C4::Context->preference("item-level_itypes")){ + $sth = $dbh->prepare( + "SELECT + ADDDATE(returndate, finedays * DATEDIFF(returndate,date_due) ) AS blockingdate, + DATEDIFF(ADDDATE(returndate, finedays * DATEDIFF(returndate,date_due)),NOW()) AS blockedcount + FROM old_issues + LEFT JOIN items ON (items.itemnumber=old_issues.itemnumber) + LEFT JOIN issuingrules ON (issuingrules.itemtype=items.itype) + WHERE finedays IS NOT NULL + AND date_due < returndate + AND borrowernumber = ? + ORDER BY blockingdate DESC + LIMIT 1" + ); + }else{ + $sth = $dbh->prepare( + "SELECT + ADDDATE(returndate, finedays * DATEDIFF(returndate,date_due) ) AS blockingdate, + DATEDIFF(ADDDATE(returndate, finedays * DATEDIFF(returndate,date_due)),NOW()) AS blockedcount + FROM old_issues + 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) + WHERE finedays IS NOT NULL + AND date_due < returndate + AND borrowernumber = ? + ORDER BY blockingdate DESC + LIMIT 1" + ); + } + $sth->execute($borrowernumber); + my $row = $sth->fetchrow_hashref; + my $blockeddate = $row->{'blockeddate'}; + my $blockedcount = $row->{'blockedcount'}; + $sth->finish(); + + return (1, $blockedcount) if $blockedcount > 0; + + return 0 +} + END { } # module clean-up code here (global destructor) 1; diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index 558bd42813..6e9f37181e 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -77,13 +77,14 @@ elsif ($op eq 'delete-branch-cat') { # save the values entered elsif ($op eq 'add') { my $sth_search = $dbh->prepare("SELECT COUNT(*) AS total FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=?"); - my $sth_insert = $dbh->prepare("INSERT INTO issuingrules (branchcode, categorycode, itemtype, maxissueqty, issuelength, fine, firstremind, chargeperiod) VALUES(?,?,?,?,?,?,?,?)"); - my $sth_update=$dbh->prepare("UPDATE issuingrules SET fine=?, firstremind=?, chargeperiod=?, maxissueqty=?, issuelength=? WHERE branchcode=? AND categorycode=? AND itemtype=?"); + my $sth_insert = $dbh->prepare("INSERT INTO issuingrules (branchcode, categorycode, itemtype, maxissueqty, issuelength, fine, finedays, firstremind, chargeperiod) VALUES(?,?,?,?,?,?,?,?,?)"); + my $sth_update=$dbh->prepare("UPDATE issuingrules SET fine=?, finedays=?, firstremind=?, chargeperiod=?, maxissueqty=?, issuelength=? WHERE branchcode=? AND categorycode=? AND itemtype=?"); my $br = $branch; # branch my $bor = $input->param('categorycode'); # borrower category my $cat = $input->param('itemtype'); # item type my $fine = $input->param('fine'); + my $finedays = $input->param('finedays'); my $firstremind = $input->param('firstremind'); my $chargeperiod = $input->param('chargeperiod'); my $maxissueqty = $input->param('maxissueqty'); @@ -95,9 +96,9 @@ elsif ($op eq 'add') { $sth_search->execute($br,$bor,$cat); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute($fine, $firstremind, $chargeperiod, $maxissueqty,$issuelength,$br,$bor,$cat); + $sth_update->execute($fine, $finedays, $firstremind, $chargeperiod, $maxissueqty,$issuelength,$br,$bor,$cat); } else { - $sth_insert->execute($br,$bor,$cat,$maxissueqty,$issuelength,$fine,$firstremind,$chargeperiod); + $sth_insert->execute($br,$bor,$cat,$maxissueqty,$issuelength,$fine,$finedays,$firstremind,$chargeperiod); } } elsif ($op eq "add-branch-cat") { diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 2363c9dd6f..c8d00c4e79 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1081,6 +1081,7 @@ CREATE TABLE `issuingrules` ( `rentaldiscount` decimal(28,6) default NULL, `reservecharge` decimal(28,6) default NULL, `fine` decimal(28,6) default NULL, + `finedays` int(11) default NULL, `firstremind` int(11) default NULL, `chargeperiod` int(11) default NULL, `accountsent` int(11) default NULL, diff --git a/installer/data/mysql/updatedatabase30.pl b/installer/data/mysql/updatedatabase30.pl index acfcf58e3a..dd171583de 100644 --- a/installer/data/mysql/updatedatabase30.pl +++ b/installer/data/mysql/updatedatabase30.pl @@ -146,6 +146,12 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowNotForLoanOverride', '0', 'if ON, enables the librarian to choose when they want to check out a notForLoan regular item',NULL,'YesNo') ENDOFNOTFORLOANOVERRIDE print "Upgrade to $DBversion done (Adding AllowNotForLoanOverride System preference)\n"; +} + +$DBversion = "3.00.01.005"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE issuingrules ADD COLUMN `finedays` int(11) default NULL AFTER `fine`"); + print "Upgrade to $DBversion done (Adding a field in issuingrules table)\n"; SetVersion ($DBversion); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl index 643cb97bb1..a7ba2ccf97 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl @@ -65,6 +65,7 @@ $(document).ready(function() { Patron Category Item Type Fine Amount + Fine Days Fine Grace Period Fine Charging Interval Current Checkouts Allowed @@ -85,6 +86,11 @@ $(document).ready(function() { $ + + + day(s) + + day(s) day(s) @@ -117,6 +123,7 @@ $(document).ready(function() { $ + day(s) day(s) day(s) -- 2.39.5