From 7d817de89ec2eb883fdcad190ed713c906bc9262 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Mon, 20 Apr 2020 07:47:11 +0000 Subject: [PATCH] Bug 25089: (OLD GUI) Add checkout_type to smart-rules To test: 1. First apply all the patches tagged with (OLD GUI) prefix in commit title 2. Go to Circulation rules page in Koha 3. Observe checkout type column in the rule matrix 4. Test circulation rules matrix by setting, modifying and deleting rules. 5. Test default checkout, hold and return policy settings. 6. Test default checkout, hold policy by patron category settings. Sponsored-by: The National Library of Finland --- admin/smart-rules.pl | 151 +++++++++++++++++- .../prog/en/modules/admin/smart-rules.tt | 87 +++++++--- 2 files changed, 216 insertions(+), 22 deletions(-) diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index 37f378d1c3..7e3bc086e2 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -75,6 +75,8 @@ $cache->clear_from_cache( Koha::CirculationRules::GUESSED_ITEMTYPES_KEY ); if ($op eq 'delete') { my $itemtype = $input->param('itemtype'); my $categorycode = $input->param('categorycode'); + my $checkout_type = $input->param('checkout_type'); + $debug and warn "deleting $1 $2 $branch"; Koha::CirculationRules->set_rules( @@ -82,6 +84,7 @@ if ($op eq 'delete') { categorycode => $categorycode eq '*' ? undef : $categorycode, branchcode => $branch eq '*' ? undef : $branch, itemtype => $itemtype eq '*' ? undef : $itemtype, + checkout_type => $checkout_type eq '*' ? undef : $checkout_type, rules => { maxissueqty => undef, rentaldiscount => undef, @@ -126,7 +129,26 @@ elsif ($op eq 'delete-branch-cat') { categorycode => undef, rules => { max_holds => undef, - patron_maxissueqty => undef, + } + } + ); + Koha::CirculationRules->set_rules( + { + branchcode => undef, + categorycode => undef, + checkout_type => $Koha::Checkouts::type->{checkout}, + rules => { + patron_maxissueqty => undef, + } + } + ); + Koha::CirculationRules->set_rules( + { + branchcode => undef, + categorycode => undef, + checkout_type => $Koha::Checkouts::type->{onsite_checkout}, + rules => { + patron_maxissueqty => undef, } } ); @@ -148,6 +170,25 @@ elsif ($op eq 'delete-branch-cat') { branchcode => undef, rules => { max_holds => undef, + } + } + ); + Koha::CirculationRules->set_rules( + { + categorycode => $categorycode, + branchcode => undef, + checkout_type => $Koha::Checkouts::type->{checkout}, + rules => { + patron_maxissueqty => undef, + } + } + ); + Koha::CirculationRules->set_rules( + { + categorycode => $categorycode, + branchcode => undef, + checkout_type => $Koha::Checkouts::type->{onsite_checkout}, + rules => { patron_maxissueqty => undef, } } @@ -158,6 +199,17 @@ elsif ($op eq 'delete-branch-cat') { { branchcode => $branch, categorycode => undef, + checkout_type => $Koha::Checkouts::type->{checkout}, + rules => { + patron_maxissueqty => undef, + } + } + ); + Koha::CirculationRules->set_rules( + { + branchcode => $branch, + categorycode => undef, + checkout_type => $Koha::Checkouts::type->{onsite_checkout}, rules => { max_holds => undef, patron_maxissueqty => undef, @@ -182,7 +234,26 @@ elsif ($op eq 'delete-branch-cat') { branchcode => $branch, rules => { max_holds => undef, - patron_maxissueqty => undef, + } + } + ); + Koha::CirculationRules->set_rules( + { + categorycode => $categorycode, + branchcode => $branch, + checkout_type => $Koha::Checkouts::type->{checkout}, + rules => { + patron_maxissueqty => undef, + } + } + ); + Koha::CirculationRules->set_rules( + { + categorycode => $categorycode, + branchcode => $branch, + checkout_type => $Koha::Checkouts::type->{onsite_checkout}, + rules => { + patron_maxissueqty => undef, } } ); @@ -247,6 +318,7 @@ elsif ($op eq 'add') { my $br = $branch; # branch my $bor = $input->param('categorycode'); # borrower category my $itemtype = $input->param('itemtype'); # item type + my $checkout_type = $input->param('checkout_type'); my $fine = $input->param('fine'); my $finedays = $input->param('finedays'); my $maxsuspensiondays = $input->param('maxsuspensiondays') || ''; @@ -322,6 +394,7 @@ elsif ($op eq 'add') { categorycode => $bor eq '*' ? undef : $bor, itemtype => $itemtype eq '*' ? undef : $itemtype, branchcode => $br eq '*' ? undef : $br, + checkout_type => $checkout_type eq '*' ? undef : $checkout_type, rules => $rules, } ); @@ -330,6 +403,7 @@ elsif ($op eq 'add') { elsif ($op eq "set-branch-defaults") { my $categorycode = $input->param('categorycode'); my $patron_maxissueqty = strip_non_numeric( scalar $input->param('patron_maxissueqty') ); + my $patron_maxonsiteissueqty = strip_non_numeric( scalar $input->param('patron_maxonsiteissueqty') ); my $holdallowed = $input->param('holdallowed'); my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy'); my $returnbranch = $input->param('returnbranch'); @@ -353,11 +427,22 @@ elsif ($op eq "set-branch-defaults") { { categorycode => undef, branchcode => undef, + checkout_type => $Koha::Checkouts::type->{checkout}, rules => { patron_maxissueqty => $patron_maxissueqty, } } ); + Koha::CirculationRules->set_rules( + { + categorycode => undef, + branchcode => undef, + checkout_type => $Koha::Checkouts::type->{onsite_checkout}, + rules => { + patron_maxissueqty => $patron_maxonsiteissueqty, + } + } + ); } else { Koha::CirculationRules->set_rules( { @@ -374,11 +459,22 @@ elsif ($op eq "set-branch-defaults") { { categorycode => undef, branchcode => $branch, + checkout_type => $Koha::Checkouts::type->{checkout}, rules => { patron_maxissueqty => $patron_maxissueqty, } } ); + Koha::CirculationRules->set_rules( + { + categorycode => undef, + branchcode => $branch, + checkout_type => $Koha::Checkouts::type->{onsite_checkout}, + rules => { + patron_maxissueqty => $patron_maxonsiteissueqty, + } + } + ); } Koha::CirculationRules->set_rule( { @@ -392,6 +488,7 @@ elsif ($op eq "set-branch-defaults") { elsif ($op eq "add-branch-cat") { my $categorycode = $input->param('categorycode'); my $patron_maxissueqty = strip_non_numeric( scalar $input->param('patron_maxissueqty') ); + my $patron_maxonsiteissueqty = strip_non_numeric( scalar $input->param('patron_maxonsiteissueqty') ); my $max_holds = $input->param('max_holds'); $max_holds =~ s/\s//g; $max_holds = undef if $max_holds !~ /^\d+/; @@ -402,46 +499,94 @@ elsif ($op eq "add-branch-cat") { { categorycode => undef, branchcode => undef, + checkout_type => $Koha::Checkouts::type->{checkout}, rules => { max_holds => $max_holds, patron_maxissueqty => $patron_maxissueqty, } } ); + Koha::CirculationRules->set_rules( + { + categorycode => undef, + branchcode => undef, + checkout_type => $Koha::Checkouts::type->{onsite_checkout}, + rules => { + max_holds => $max_holds, + patron_maxissueqty => $patron_maxonsiteissueqty, + } + } + ); } else { Koha::CirculationRules->set_rules( { categorycode => $categorycode, branchcode => undef, + checkout_type => $Koha::Checkouts::type->{checkout}, rules => { max_holds => $max_holds, patron_maxissueqty => $patron_maxissueqty, } } ); + Koha::CirculationRules->set_rules( + { + categorycode => $categorycode, + branchcode => undef, + checkout_type => $Koha::Checkouts::type->{onsite_checkout}, + rules => { + max_holds => $max_holds, + patron_maxissueqty => $patron_maxonsiteissueqty, + } + } + ); } } elsif ($categorycode eq "*") { Koha::CirculationRules->set_rules( { categorycode => undef, branchcode => $branch, + checkout_type => $Koha::Checkouts::type->{checkout}, rules => { max_holds => $max_holds, patron_maxissueqty => $patron_maxissueqty, } } ); + Koha::CirculationRules->set_rules( + { + categorycode => undef, + branchcode => $branch, + checkout_type => $Koha::Checkouts::type->{onsite_checkout}, + rules => { + max_holds => $max_holds, + patron_maxissueqty => $patron_maxonsiteissueqty, + } + } + ); } else { Koha::CirculationRules->set_rules( { categorycode => $categorycode, branchcode => $branch, + checkout_type => $Koha::Checkouts::type->{checkout}, rules => { max_holds => $max_holds, patron_maxissueqty => $patron_maxissueqty, } } ); + Koha::CirculationRules->set_rules( + { + categorycode => $categorycode, + branchcode => $branch, + checkout_type => $Koha::Checkouts::type->{onsite_checkout}, + rules => { + max_holds => $max_holds, + patron_maxissueqty => $patron_maxonsiteissueqty, + } + } + ); } } elsif ($op eq "add-branch-item") { @@ -551,7 +696,7 @@ my $definedbranch = $all_rules->count ? 1 : 0; my $rules = {}; while ( my $r = $all_rules->next ) { $r = $r->unblessed; - $rules->{ $r->{categorycode} // '' }->{ $r->{itemtype} // '' }->{ $r->{rule_name} } = $r->{rule_value}; + $rules->{ $r->{categorycode} // '' }->{ $r->{itemtype} // '' }->{ $r->{checkout_type} // '' }->{ $r->{rule_name} } = $r->{rule_value}; } $template->param(show_branch_cat_rule_form => 1); 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 0326bf6cb1..88919074c7 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 @@ -5,6 +5,7 @@ [% USE Branches %] [% USE Categories %] [% USE ItemTypes %] +[% USE Checkouts %] [% USE CirculationRules %] [% SET footerjs = 1 %] @@ -22,6 +23,12 @@ [% END %] [% itemtypes.push(undef) %] +[% SET checkout_types = [] %] +[% FOREACH ct IN Checkouts.checkout_type %] + [% checkout_types.push( ct.value ) %] +[% END %] +[% checkout_types.push(undef) %] + [% INCLUDE 'doc-head-open.inc' %] Koha › Administration › Circulation and fine rules [% INCLUDE 'doc-head-close.inc' %] @@ -86,6 +93,7 @@ + @@ -122,10 +130,12 @@ [% SET row_count = 0 %] - [% FOREACH c IN categorycodes %] - [% SET c = '' UNLESS c.defined %] - [% FOREACH i IN itemtypes %] + [% FOREACH ct IN checkout_types %] + [% FOREACH c IN categorycodes %] + [% SET c = '' UNLESS c.defined %] + [% FOREACH i IN itemtypes %] [% SET i = '' UNLESS i.defined %] + [% SET ct = '' UNLESS ct.defined %] [% SET note = all_rules.$c.$i.note %] [% SET maxissueqty = all_rules.$c.$i.maxissueqty %] [% SET issuelength = all_rules.$c.$i.issuelength %] @@ -160,6 +170,17 @@ [% IF show_rule %] [% SET row_count = row_count + 1 %] + [% END %] + [% END %] [% END %] [% END %] + + @@ -470,6 +500,7 @@ + @@ -479,16 +510,20 @@ + + [% FOREACH c IN categorycodes %] [% NEXT UNLESS c %] - [% SET patron_maxissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxissueqty' ) %] - [% SET max_holds = CirculationRules.Search( branchcode, c, undef, 'max_holds' ) %] + [% SET patron_maxissueqty = CirculationRules.Search( branchcode, c, undef, Checkouts.checkout_type.checkout, 'patron_maxissueqty' ) %] + [% SET patron_maxonsiteissueqty = CirculationRules.Search( branchcode, c, undef, Checkouts.checkout_type.onsite_checkout, 'patron_maxissueqty' ) %] + [% SET max_holds = CirculationRules.Search( branchcode, c, undef, undef, 'max_holds' ) %] [% IF ( patron_maxissueqty.defined && patron_maxissueqty != '' ) || ( max_holds.defined && max_holds != '' ) %] @@ -664,6 +701,13 @@ Unlimited [% END %] + + @@ -806,9 +851,9 @@ [% FOREACH i IN itemtypeloop %] - [% SET holdallowed = CirculationRules.Search( branchcode, undef, i.itemtype, 'holdallowed' ) %] - [% SET hold_fulfillment_policy = CirculationRules.Search( branchcode, undef, i.itemtype, 'hold_fulfillment_policy' ) %] - [% SET returnbranch = CirculationRules.Search( branchcode, undef, i.itemtype, 'returnbranch' ) %] + [% SET holdallowed = CirculationRules.Search( branchcode, undef, i.itemtype, undef, 'holdallowed' ) %] + [% SET hold_fulfillment_policy = CirculationRules.Search( branchcode, undef, i.itemtype, undef, 'hold_fulfillment_policy' ) %] + [% SET returnbranch = CirculationRules.Search( branchcode, undef, i.itemtype, undef, 'returnbranch' ) %] [% IF holdallowed || hold_fulfillment_policy || returnbranch %] @@ -979,11 +1024,11 @@ itm = $(this).text(); itm = itm.replace(/^\s*|\s*$/g,''); var current_column = $("#edit_row td:eq("+i+")"); - if ( i == 3 ) { + if ( i == 4 ) { // specific processing for the Note column var note = $(this).find("a[name='viewnote']").data("content"); $(current_column).find("input[type='text']").val(note); - } else if ( i == 8 ) { + } else if ( i == 9 ) { // specific processing for the Hard due date column var select_value = $(this).find("input[type='hidden'][name='hardduedatecomparebackup']").val(); var input_value = ''; @@ -994,7 +1039,7 @@ } $(current_column).find("input[type='text']").val(input_value); $(current_column).find("select").val(select_value); - } else if ( i == 14 ) { + } else if ( i == 15 ) { // specific processing for cap_fine_to_replacement_price var cap_fine_to_replacement_price = $(this).find("input[type='checkbox']"); $('#cap_fine_to_replacement_price').prop('checked', cap_fine_to_replacement_price.is(':checked') ); @@ -1009,17 +1054,20 @@ $(this).attr('selected', 'selected'); } }); - if ( i == 0 || i == 1 ) { + if ( i == 0 || i == 1 || i == 2 ) { // Disable the 2 first columns, we cannot update them. var val = $(current_column).find("select option:selected").val(); var name = "categorycode"; if ( i == 1 ) { name="itemtype"; } + if ( i == 2 ) { + name="checkout_type"; + } // Remove potential previous input added $(current_column).find("input").remove(); $(current_column).append(""); - } else if ( i == 5 || i == 25 || i == 26 || i == 27 ) { + } else if ( i == 6 || i == 25 || i == 26 || i == 27 ) { // If the value is not an integer for // - "Current checkouts allowed" // - "Holds allowed (total)" @@ -1035,6 +1083,7 @@ }); $("#default-circulation-rules tr:last td:eq(0) select").prop('disabled', true); $("#default-circulation-rules tr:last td:eq(1) select").prop('disabled', true); + $("#default-circulation-rules tr:last td:eq(2) select").prop('disabled', true); return false; }); $(".clear_edit").on("click",function(e){ -- 2.17.1
Checkout type Patron category Item type Actions
+ [% IF ct == undef %] + All + [% ELSE %] + [% IF ct == 'CHECKOUT' %] + Normal checkout + [% ELSIF ct == 'ONSITE' %] + On-site checkout + [% END %] + [% END %] + [% IF c == undef %] All @@ -176,7 +197,7 @@ Edit - Delete + Delete [% IF note.defined && note != '' %] @@ -309,9 +330,17 @@
+ +
Checkout type Patron category Item type  
  Total current checkouts allowedTotal current on-site checkouts allowed Maximum total holds allowed (count) Hold policy Hold pickup library match
Defaults - [% SET patron_maxissueqty = CirculationRules.Search( current_branch, undef, undef, 'patron_maxissueqty' ) %] + [% SET patron_maxissueqty = CirculationRules.Search( current_branch, undef, undef, Checkouts.checkout_type.checkout, 'patron_maxissueqty' ) %] - [% SET rule_value = CirculationRules.Search( current_branch, undef , undef, 'max_holds' ) %] + [% SET patron_maxissueqty = CirculationRules.Search( current_branch, undef, undef, Checkouts.checkout_type.onsite_checkout, 'patron_maxissueqty' ) %] + + + [% SET rule_value = CirculationRules.Search( current_branch, undef , undef, undef, 'max_holds' ) %]
Patron category Total current checkouts allowedTotal current on-site checkouts allowed Total holds allowed  
+ [% IF patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' %] + [% patron_maxonsiteissueqty | html %] + [% ELSE %] + Unlimited + [% END %] + [% IF max_holds.defined && max_holds != '' %] [% max_holds | html %] @@ -687,6 +731,7 @@