From e1cd77a258d707c5efa67e73e9fb2465cbbb75b1 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. Go to Circulation rules page in Koha 2. Observe checkout type column in the rule matrix 3. Test circulation rules matrix by setting, modifying and deleting rules. 4. Test default checkout, hold and return policy settings. 5. 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 | 422 ++++++++++-------- 2 files changed, 383 insertions(+), 190 deletions(-) diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index 941abdae73..d76b3da288 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, @@ -125,7 +128,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, } } ); @@ -147,6 +169,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, } } @@ -157,6 +198,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 => { patron_maxissueqty => undef, } @@ -180,7 +232,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, } } ); @@ -245,6 +316,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'); @@ -320,6 +392,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, } ); @@ -328,6 +401,7 @@ elsif ($op eq 'add') { elsif ($op eq "set-branch-defaults") { my $categorycode = $input->param('categorycode'); my $patron_maxissueqty = strip_non_numeric($input->param('patron_maxissueqty')); + my $patron_maxonsiteissueqty = strip_non_numeric($input->param('patron_maxonsiteissueqty')); my $holdallowed = $input->param('holdallowed'); my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy'); my $returnbranch = $input->param('returnbranch'); @@ -351,11 +425,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( { @@ -372,11 +457,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( { @@ -390,6 +486,7 @@ elsif ($op eq "set-branch-defaults") { elsif ($op eq "add-branch-cat") { my $categorycode = $input->param('categorycode'); my $patron_maxissueqty = strip_non_numeric($input->param('patron_maxissueqty')); + my $patron_maxonsiteissueqty = strip_non_numeric($input->param('patron_maxonsiteissueqty')); my $max_holds = $input->param('max_holds'); $max_holds =~ s/\s//g; $max_holds = undef if $max_holds !~ /^\d+/; @@ -400,46 +497,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") { @@ -549,7 +694,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 60b0d19eac..fadf6c91a9 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.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' %] @@ -88,6 +95,7 @@ Patron category Item type + Checkout type Actions Note Current checkouts allowed @@ -125,178 +133,191 @@ [% SET c = '' UNLESS c.defined %] [% FOREACH i IN itemtypes %] [% SET i = '' UNLESS i.defined %] - [% SET note = all_rules.$c.$i.note %] - [% SET maxissueqty = all_rules.$c.$i.maxissueqty %] - [% SET issuelength = all_rules.$c.$i.issuelength %] - [% SET lengthunit = all_rules.$c.$i.lengthunit %] - [% SET hardduedate = all_rules.$c.$i.hardduedate %] - [% SET hardduedatecompare = all_rules.$c.$i.hardduedatecompare %] - [% SET fine = all_rules.$c.$i.fine %] - [% SET chargeperiod = all_rules.$c.$i.chargeperiod %] - [% SET chargeperiod_charge_at = all_rules.$c.$i.chargeperiod_charge_at %] - [% SET firstremind = all_rules.$c.$i.firstremind %] - [% SET overduefinescap = all_rules.$c.$i.overduefinescap %] - [% SET cap_fine_to_replacement_price = all_rules.$c.$i.cap_fine_to_replacement_price %] - [% SET finedays = all_rules.$c.$i.finedays %] - [% SET maxsuspensiondays = all_rules.$c.$i.maxsuspensiondays %] - [% SET suspension_chargeperiod = all_rules.$c.$i.suspension_chargeperiod %] - [% SET renewalsallowed = all_rules.$c.$i.renewalsallowed %] - [% SET renewalperiod = all_rules.$c.$i.renewalperiod %] - [% SET norenewalbefore = all_rules.$c.$i.norenewalbefore %] - [% SET auto_renew = all_rules.$c.$i.auto_renew %] - [% SET no_auto_renewal_after = all_rules.$c.$i.no_auto_renewal_after %] - [% SET no_auto_renewal_after_hard_limit = all_rules.$c.$i.no_auto_renewal_after_hard_limit %] - [% SET reservesallowed = all_rules.$c.$i.reservesallowed %] - [% SET holds_per_day = all_rules.$c.$i.holds_per_day %] - [% SET holds_per_record = all_rules.$c.$i.holds_per_record %] - [% SET onshelfholds = all_rules.$c.$i.onshelfholds %] - [% SET opacitemholds = all_rules.$c.$i.opacitemholds %] - [% SET article_requests = all_rules.$c.$i.article_requests %] - [% SET rentaldiscount = all_rules.$c.$i.rentaldiscount %] - - [% SET show_rule = maxissueqty || issuelength || lengthunit || hardduedate || hardduedatebefore || hardduedateexact || fine || chargeperiod || chargeperiod_charge_at || firstremind || overduefinescap || cap_fine_to_replacement_price || finedays || maxsuspensiondays || suspension_chargeperiod || renewalsallowed || renewalsallowed || norenewalbefore || auto_renew || no_auto_renewal_after || no_auto_renewal_after_hard_limit || reservesallowed || holds_per_day || holds_per_record || onshelfholds || opacitemholds || article_requests || article_requests %] - [% IF show_rule %] - [% SET row_count = row_count + 1 %] - - - [% IF c == undef %] - All - [% ELSE %] - [% Categories.GetName(c) | html %] - [% END %] - - - [% IF i == undef %] - All - [% ELSE %] - [% ItemTypes.GetDescription(i) | html %] - [% END %] - - - Edit - Delete - - - [% IF note.defined && note != '' %] - View note - [% ELSE %] [% END %] - - - [% IF maxissueqty.defined && maxissueqty != '' %] - [% maxissueqty | html %] - [% ELSE %] - Unlimited - [% END %] - - [% issuelength | html %] - - [% IF ( lengthunit == 'days' ) %] - Days - [% ELSIF ( lengthunit == 'hours') %] - Hours - [% ELSE %] - Undefined - [% END %] - - - [% IF ( hardduedate ) %] - [% IF ( hardduedatecompare == '-1' ) %] - before [% hardduedate | $KohaDates %] - - [% ELSIF ( hardduedatecompare == '0' ) %] - on [% hardduedate | $KohaDates %] - - [% ELSIF ( hardduedatecompare == '1' ) %] - after [% hardduedate | $KohaDates %] - - [% END %] - [% ELSE %] - None defined - [% END %] - - [% fine | html %] - [% chargeperiod | html %] - [% IF chargeperiod_charge_at %]Start of interval[% ELSE %]End of interval[% END %] - [% firstremind | html %] - [% overduefinescap FILTER format("%.2f") %] - - [% IF cap_fine_to_replacement_price %] - - [% ELSE %] - - [% END %] - - [% finedays | html %] - [% maxsuspensiondays | html %] - [% suspension_chargeperiod | html %] - [% renewalsallowed | html %] - [% renewalperiod | html %] - [% norenewalbefore | html %] - - [% IF auto_renew %] - Yes - [% ELSE %] - No - [% END %] - - [% no_auto_renewal_after | html %] - [% no_auto_renewal_after_hard_limit | $KohaDates %] - - [% IF reservesallowed.defined && reservesallowed != '' %] - [% reservesallowed | html %] - [% ELSE %] - Unlimited - [% END %] - - - [% IF holds_per_day.defined && holds_per_day != '' %] - [% holds_per_day | html %] - [% ELSE %] - Unlimited - [% END %] - - - [% IF holds_per_record.defined && holds_per_record != '' %] - [% holds_per_record | html %] - [% ELSE %] - Unlimited - [% END %] - - - [% IF onshelfholds == 1 %] - Yes - [% ELSIF onshelfholds == 2 %] - If all unavailable - [% ELSE %] - If any unavailable - [% END %] - - - [% IF opacitemholds == 'F'%] - Force - [% ELSIF opacitemholds == 'Y'%] - Allow - [% ELSE %] - Don't allow - [% END %] - - - [% IF article_requests == 'no' %] - No - [% ELSIF article_requests == 'yes' %] - Yes - [% ELSIF article_requests == 'bib_only' %] - Record only - [% ELSIF article_requests == 'item_only' %] - Item only - [% END %] - - [% rentaldiscount | html %] - - Edit - Delete - - + [% FOREACH ct IN checkout_types %] + [% SET ct = '' UNLESS ct.defined %] + [% SET note = all_rules.$c.$i.$ct.note %] + [% SET maxissueqty = all_rules.$c.$i.$ct.maxissueqty %] + [% SET issuelength = all_rules.$c.$i.$ct.issuelength %] + [% SET lengthunit = all_rules.$c.$i.$ct.lengthunit %] + [% SET hardduedate = all_rules.$c.$i.$ct.hardduedate %] + [% SET hardduedatecompare = all_rules.$c.$i.$ct.hardduedatecompare %] + [% SET fine = all_rules.$c.$i.$ct.fine %] + [% SET chargeperiod = all_rules.$c.$i.$ct.chargeperiod %] + [% SET chargeperiod_charge_at = all_rules.$c.$i.$ct.chargeperiod_charge_at %] + [% SET firstremind = all_rules.$c.$i.$ct.firstremind %] + [% SET overduefinescap = all_rules.$c.$i.$ct.overduefinescap %] + [% SET cap_fine_to_replacement_price = all_rules.$c.$i.$ct.cap_fine_to_replacement_price %] + [% SET finedays = all_rules.$c.$i.$ct.finedays %] + [% SET maxsuspensiondays = all_rules.$c.$i.$ct.maxsuspensiondays %] + [% SET suspension_chargeperiod = all_rules.$c.$i.$ct.suspension_chargeperiod %] + [% SET renewalsallowed = all_rules.$c.$i.$ct.renewalsallowed %] + [% SET renewalperiod = all_rules.$c.$i.$ct.renewalperiod %] + [% SET norenewalbefore = all_rules.$c.$i.$ct.norenewalbefore %] + [% SET auto_renew = all_rules.$c.$i.$ct.auto_renew %] + [% SET no_auto_renewal_after = all_rules.$c.$i.$ct.no_auto_renewal_after %] + [% SET no_auto_renewal_after_hard_limit = all_rules.$c.$i.$ct.no_auto_renewal_after_hard_limit %] + [% SET reservesallowed = all_rules.$c.$i.$ct.reservesallowed %] + [% SET holds_per_day = all_rules.$c.$i.$ct.holds_per_day %] + [% SET holds_per_record = all_rules.$c.$i.$ct.holds_per_record %] + [% SET onshelfholds = all_rules.$c.$i.$ct.onshelfholds %] + [% SET opacitemholds = all_rules.$c.$i.$ct.opacitemholds %] + [% SET article_requests = all_rules.$c.$i.$ct.article_requests %] + [% SET rentaldiscount = all_rules.$c.$i.$ct.rentaldiscount %] + [% SET show_rule = maxissueqty || issuelength || lengthunit || hardduedate || hardduedatebefore || hardduedateexact || fine || chargeperiod || chargeperiod_charge_at || firstremind || overduefinescap || cap_fine_to_replacement_price || finedays || maxsuspensiondays || suspension_chargeperiod || renewalsallowed || renewalsallowed || norenewalbefore || auto_renew || no_auto_renewal_after || no_auto_renewal_after_hard_limit || reservesallowed || holds_per_day || holds_per_record || onshelfholds || opacitemholds || article_requests || article_requests %] + [% IF show_rule %] + [% SET row_count = row_count + 1 %] + + + [% IF c == undef %] + All + [% ELSE %] + [% Categories.GetName(c) | html %] + [% END %] + + + [% IF i == undef %] + All + [% ELSE %] + [% ItemTypes.GetDescription(i) | html %] + [% END %] + + + [% IF ct == undef %] + All + [% ELSE %] + [% IF ct == 'CHECKOUT' %] + Normal checkout + [% ELSIF ct == 'ONSITE' %] + On-site checkout + [% END %] + [% END %] + + + Edit + Delete + + + [% IF note.defined && note != '' %] + View note + [% ELSE %] [% END %] + + + [% IF maxissueqty.defined && maxissueqty != '' %] + [% maxissueqty | html %] + [% ELSE %] + Unlimited + [% END %] + + [% issuelength | html %] + + [% IF ( lengthunit == 'days' ) %] + Days + [% ELSIF ( lengthunit == 'hours') %] + Hours + [% ELSE %] + Undefined + [% END %] + + + [% IF ( hardduedate ) %] + [% IF ( hardduedatecompare == '-1' ) %] + before [% hardduedate | $KohaDates %] + + [% ELSIF ( hardduedatecompare == '0' ) %] + on [% hardduedate | $KohaDates %] + + [% ELSIF ( hardduedatecompare == '1' ) %] + after [% hardduedate | $KohaDates %] + + [% END %] + [% ELSE %] + None defined + [% END %] + + [% fine | html %] + [% chargeperiod | html %] + [% IF chargeperiod_charge_at %]Start of interval[% ELSE %]End of interval[% END %] + [% firstremind | html %] + [% overduefinescap FILTER format("%.2f") %] + + [% IF cap_fine_to_replacement_price %] + + [% ELSE %] + + [% END %] + + [% finedays | html %] + [% maxsuspensiondays | html %] + [% suspension_chargeperiod | html %] + [% renewalsallowed | html %] + [% renewalperiod | html %] + [% norenewalbefore | html %] + + [% IF auto_renew %] + Yes + [% ELSE %] + No + [% END %] + + [% no_auto_renewal_after | html %] + [% no_auto_renewal_after_hard_limit | $KohaDates %] + + [% IF reservesallowed.defined && reservesallowed != '' %] + [% reservesallowed | html %] + [% ELSE %] + Unlimited + [% END %] + + + [% IF holds_per_day.defined && holds_per_day != '' %] + [% holds_per_day | html %] + [% ELSE %] + Unlimited + [% END %] + + + [% IF holds_per_record.defined && holds_per_record != '' %] + [% holds_per_record | html %] + [% ELSE %] + Unlimited + [% END %] + + + [% IF onshelfholds == 1 %] + Yes + [% ELSIF onshelfholds == 2 %] + If all unavailable + [% ELSE %] + If any unavailable + [% END %] + + + [% IF opacitemholds == 'F'%] + Force + [% ELSIF opacitemholds == 'Y'%] + Allow + [% ELSE %] + Don't allow + [% END %] + + + [% IF article_requests == 'no' %] + No + [% ELSIF article_requests == 'yes' %] + Yes + [% ELSIF article_requests == 'bib_only' %] + Record only + [% ELSIF article_requests == 'item_only' %] + Item only + [% END %] + + [% rentaldiscount | html %] + + Edit + Delete + + + [% END %] [% END %] [% END %] [% END %] @@ -317,6 +338,13 @@ [% END %] + + + @@ -404,6 +432,7 @@ Patron category Item type + Checkout type   Note Current checkouts allowed @@ -449,6 +478,7 @@   Total current checkouts allowed + Total current on-site checkouts allowed Maximum total holds allowed (count) Hold policy Hold pickup library match @@ -458,16 +488,20 @@ Defaults - [% SET patron_maxissueqty = CirculationRules.Search( current_branch, undef, undef, 'patron_maxissueqty' ) %] + [% SET patron_maxissueqty = CirculationRules.Search( current_branch, undef, undef, Checkouts.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.type.onsite_checkout, 'patron_maxissueqty' ) %] + + + + [% SET rule_value = CirculationRules.Search( current_branch, undef , undef, undef, 'max_holds' ) %] - [% SET hold_fulfillment_policy = CirculationRules.Search( current_branch, undef, undef, 'hold_fulfillment_policy' ) %] + [% SET hold_fulfillment_policy = CirculationRules.Search( current_branch, undef, undef, undef, 'hold_fulfillment_policy' ) %]