From 3708d8f606b7841689d1e4d1817bd35a16c7d033 Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Wed, 28 Jun 2017 13:50:20 +0000 Subject: [PATCH] Bug 8137: Add Default checkout limit by patron category with priority. This patch add the ability to make a 'Default checkout limit by patron category' rule has priority. When a rule has priority, it overrides all others for the same categorycode. For "normal" rule, the behavior is the same than before (like a default rule if no one is specified at branch level). Rule with priority can only be created on the circulation and fine rules page for *all libraries*. The goal is to allow librarian to limit the total number of checkouts by patron category for all libraries. test plan: - Create a rule with 4 checkouts allowed in default checkout limit table for a patron category and make it has priority, - create more permissive rules for all other branches (at least 5 checkouts allowed), - Checkout items of different branches for a patron with the same category, - Patron should be limited to 4 checkouts https://bugs.koha-community.org/show_bug.cgi?id=8137 Rebased: 2018-03-14, by: Alex Arnaud Rebased: 2020-07-23, by: Arthur Suzuki --- C4/Circulation.pm | 19 +++++++++------- admin/smart-rules.pl | 6 +++++ .../Bug_8137-add-column-has_priority.sql | 5 +++++ .../prog/en/modules/admin/smart-rules.tt | 15 +++++++++++++ t/db_dependent/Circulation/Branch.t | 26 +++++++++++++++++++++- 5 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/Bug_8137-add-column-has_priority.sql diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 2fe1dcdede..5baa143ff6 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -516,14 +516,17 @@ sub TooMany { |; push @bind_params, $borrower->{borrowernumber}; - if (C4::Context->preference('CircControl') eq 'PickupLibrary') { - $branch_count_query .= " AND issues.branchcode = ? "; - push @bind_params, $branch; - } elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') { - ; # if branch is the patron's home branch, then count all loans by patron - } else { - $branch_count_query .= " AND items.homebranch = ? "; - push @bind_params, $branch; + # Only for specific or default branches. + unless ($branch_borrower_circ_rule->{has_priority}) { + if (C4::Context->preference('CircControl') eq 'PickupLibrary') { + $branch_count_query .= " AND issues.branchcode = ? "; + push @bind_params, $branch; + } elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') { + ; # if branch is the patron's home branch, then count all loans by patron + } else { + $branch_count_query .= " AND items.homebranch = ? "; + push @bind_params, $branch; + } } my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $branch_count_query, {}, @bind_params ); my $max_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxissueqty}; diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index 0a33493623..7e1a30a0b2 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -408,6 +408,8 @@ elsif ($op eq "add-branch-cat") { my $max_holds = $input->param('max_holds'); $max_holds =~ s/\s//g; $max_holds = undef if $max_holds !~ /^\d+/; + my $has_priority = $input->param('has_priority'); + $has_priority = $has_priority ? 1 : 0; if ($branch eq "*") { if ($categorycode eq "*") { @@ -423,6 +425,7 @@ elsif ($op eq "add-branch-cat") { } ); } else { + Koha::CirculationRules->set_rules( { categorycode => $categorycode, @@ -431,6 +434,7 @@ elsif ($op eq "add-branch-cat") { max_holds => $max_holds, patron_maxissueqty => $patron_maxissueqty, patron_maxonsiteissueqty => $patron_maxonsiteissueqty, + has_priority => $has_priority, } } ); @@ -444,6 +448,7 @@ elsif ($op eq "add-branch-cat") { max_holds => $max_holds, patron_maxissueqty => $patron_maxissueqty, patron_maxonsiteissueqty => $patron_maxonsiteissueqty, + has_priority => $has_priority, } } ); @@ -456,6 +461,7 @@ elsif ($op eq "add-branch-cat") { max_holds => $max_holds, patron_maxissueqty => $patron_maxissueqty, patron_maxonsiteissueqty => $patron_maxonsiteissueqty, + has_priority => $has_priority, } } ); diff --git a/installer/data/mysql/atomicupdate/Bug_8137-add-column-has_priority.sql b/installer/data/mysql/atomicupdate/Bug_8137-add-column-has_priority.sql new file mode 100644 index 0000000000..fc7c42fcc0 --- /dev/null +++ b/installer/data/mysql/atomicupdate/Bug_8137-add-column-has_priority.sql @@ -0,0 +1,5 @@ +ALTER TABLE default_borrower_circ_rules ADD has_priority INT(1) DEFAULT 0; +ALTER TABLE default_borrower_circ_rules DROP foreign key borrower_borrower_circ_rules_ibfk_1; +ALTER TABLE default_borrower_circ_rules DROP primary key; +ALTER TABLE default_borrower_circ_rules ADD primary key(categorycode, has_priority); +ALTER TABLE default_borrower_circ_rules ADD CONSTRAINT borrower_borrower_circ_rules_ibfk_1 FOREIGN KEY (categorycode) REFERENCES categories (categorycode) ON DELETE CASCADE ON UPDATE CASCADE; \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt index cfea9b6cec..bd866fc92a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -648,6 +648,10 @@

If the total amount loanable for a given patron category is left blank, no limit applies, except possibly for a limit you define for a specific item type.

+

+ Has priority: If checked, the rule will override those for all branches. Else + it behaves like a default one: used if no rule existe for the coresponding branch. +

@@ -657,6 +661,7 @@ Total current checkouts allowed Total current on-site checkouts allowed Total holds allowed + [% UNLESS humanbranch %]Has priority[% END %]   [% FOREACH c IN categorycodes %] @@ -695,6 +700,11 @@ Unlimited [% END %] + [% UNLESS humanbranch %] + + + + [% END %] Delete @@ -713,6 +723,11 @@ + [% UNLESS humanbranch %] + + + + [% END %]