[Koha-patches] [PATCH] [3.0.x](bug #2929) permit to define "fine days" in issuing rules
Nahuel ANGELINETTI
nahuel.angelinetti at biblibre.com
Tue Jan 27 15:38:24 CET 2009
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.
---
C4/Circulation.pm | 9 +++
C4/Members.pm | 57 ++++++++++++++++++++
admin/smart-rules.pl | 9 ++--
installer/data/mysql/kohastructure.sql | 1 +
installer/data/mysql/updatedatabase30.pl | 8 +++
.../prog/en/modules/admin/smart-rules.tmpl | 9 +++-
.../prog/en/modules/circ/circulation.tmpl | 10 +++-
kohaversion.pl | 2 +-
8 files changed, 98 insertions(+), 7 deletions(-)
diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index d3ea550..2b92ae5 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -698,6 +698,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 09f9a08..54c177f 100644
--- a/C4/Members.pm
+++ b/C4/Members.pm
@@ -2084,6 +2084,63 @@ 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
+ $sth = $dbh->prepare(
+ "SELECT
+ MAX(ADDDATE(returndate, finedays * DATEDIFF(returndate,date_due) )) AS blockingdate,
+ DATEDIFF(MAX(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 returndate DESC"
+ );
+ $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 558bd42..6e9f371 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 2363c9d..c8d00c4 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 b15ac9d..8f148cd 100644
--- a/installer/data/mysql/updatedatabase30.pl
+++ b/installer/data/mysql/updatedatabase30.pl
@@ -140,6 +140,14 @@ ENDOFSQL3
SetVersion ($DBversion);
}
+
+$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);
+}
+
=item DropAllForeignKeys($table)
Drop all foreign keys of the table $table
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 643cb97..5f51d86 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,13 +65,14 @@ $(document).ready(function() {
<th>Patron Category</th>
<th>Item Type</th>
<th>Fine Amount</th>
+ <th>Fine Days</th>
<th>Fine Grace Period</th>
<th>Fine Charging Interval</th>
<th>Current Checkouts Allowed</th>
<th>Loan Period</th><th> </th>
</tr>
<!-- TMPL_LOOP NAME="rules" -->
- <tr>
+<!-- <tr> -->
<td><!-- TMPL_IF NAME="default_humancategorycode" -->
<em>Default</em>
<!-- TMPL_ELSE -->
@@ -85,6 +86,11 @@ $(document).ready(function() {
<!-- /TMPL_IF -->
</td>
<td>$<!-- TMPL_VAR NAME="fine" --></td>
+ <td>
+ <!-- TMPL_IF NAME="finedays" -->
+ <!-- TMPL_VAR NAME="finedays" --> day(s)
+ <!-- /TMPL_IF -->
+ </td>
<td><!-- TMPL_IF NAME="firstremind" --><!-- TMPL_VAR NAME="firstremind" --> day(s)<!-- /TMPL_IF --></td>
<td><!-- TMPL_IF NAME="chargeperiod" --><!-- TMPL_VAR NAME="chargeperiod" --> day(s)<!-- /TMPL_IF --></td>
<td><!-- TMPL_IF NAME="unlimited_maxissueqty" -->
@@ -117,6 +123,7 @@ $(document).ready(function() {
</select>
</td>
<td>$<input name="fine" size="4" /></td>
+ <td><input name="finedays" size="2" /> day(s)</td>
<td><input name="firstremind" size="2" /> day(s)</td>
<td><input name="chargeperiod" size="2" /> day(s)</td>
<td><input name="maxissueqty" size="3" /></td>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl
index f2227d8..ec9cf09 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl
@@ -198,7 +198,15 @@ $.tablesorter.addParser({
<!-- TMPL_IF NAME="NOTSAMEBRANCH" -->
<li>This item belongs to <!-- TMPL_VAR NAME="itemhomebranch" --> and cannot be issued from this location.</li>
- <!-- /TMPL_IF -->
+ <!-- /TMPL_IF -->
+
+ <!-- TMPL_IF NAME="USERBLOCKEDREMAINING" -->
+ <li>The patron is blocked because of <!-- TMPL_VAR NAME="USERBLOCKEDREMAINING" --> remaining overdue documents.</li>
+ <!-- /TMPL_IF -->
+ <!-- TMPL_IF NAME="USERBLOCKEDOVERDUE" -->
+ <li>The patron is blocked for <!-- TMPL_VAR NAME="USERBLOCKEDOVERDUE" --> more day(s) because of overdue returns</li>
+ <!-- /TMPL_IF -->
+
</ul>
<!-- TMPL_IF NAME="memberofinstution" -->
diff --git a/kohaversion.pl b/kohaversion.pl
index 29ead65..9250d64 100644
--- a/kohaversion.pl
+++ b/kohaversion.pl
@@ -10,7 +10,7 @@
use strict;
sub kohaversion {
- our $VERSION = '3.00.01.004';
+ our $VERSION = '3.00.01.005';
# version needs to be set this way
# so that it can be picked up by Makefile.PL
# during install
--
1.5.6.3
More information about the Koha-patches
mailing list