From e85b2e4f94ccbcc62bbe516d6ce1fdab9e626cfa Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 3 Jun 2016 11:26:11 -0300 Subject: [PATCH] Bug 14048: Add a refund rules setting form in smart-rules This patch introduces the CRUD UI for managing the refund lost item fee rules on the general 'Circulation and fines rules' page. Verify that rules can be added and changed. Rules are correctly associated to the chosen branch (or the general default rule). To test: - Apply the patch - Open smart-rules.pl => SUCCESS: The text and refund rules section correctly refers to default global rules. The policy can be set to Yes and No, and works as expected. - Pick a specific branch => SUCCESS: The rule refers to the specific branch => SUCCESS: It detects the default rule is picked => SUCCESS: On changing the rules values are correctly retrieved if entering again to the page. => SUCCESS: The 'Use default' text is suffixed with the correct value set by the user in the 'All libraries' scenario. => Sign off :-D Sponsored-by: DoverNet Sponsored-by: South-East Kansas Library System Sponsored-by: SWITCH Library Consortium Signed-off-by: Nick Clemens Signed-off-by: Jason Robb Signed-off-by: Jennifer Schmidt Signed-off-by: Margaret Thrasher Signed-off-by: Jonathan Druart Signed-off-by: Jesse Weaver --- admin/smart-rules.pl | 34 ++++++++ .../prog/en/modules/admin/smart-rules.tt | 81 +++++++++++++++++++ 2 files changed, 115 insertions(+) diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index 11a56373c6..9d2d0fdf10 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -30,6 +30,9 @@ use Koha::DateUtils; use Koha::Database; use Koha::IssuingRule; use Koha::IssuingRules; +use Koha::Logger; +use Koha::RefundLostItemFeeRule; +use Koha::RefundLostItemFeeRules; use Koha::Libraries; my $input = CGI->new; @@ -423,6 +426,37 @@ elsif ($op eq "add-branch-item") { } } } +elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) { + + my $refund = $input->param('refund'); + + if ( $refund eq '*' ) { + if ( $branch ne '*' ) { + # only do something for $refund eq '*' if branch-specific + eval { + # Delete it so it picks the default + Koha::RefundLostItemFeeRules->find({ + branchcode => $branch + })->delete; + }; + } + } else { + my $refundRule = + Koha::RefundLostItemFeeRules->find({ + branchcode => $branch + }) // Koha::RefundLostItemFeeRule->new; + $refundRule->set({ + branchcode => $branch, + refund => $refund + })->store; + } +} + +my $refundLostItemFeeRule = Koha::RefundLostItemFeeRules->find({ branchcode => $branch }); +$template->param( + refundLostItemFeeRule => $refundLostItemFeeRule, + defaultRefundRule => Koha::RefundLostItemFeeRules->_default_rule +); my $branches = GetBranches(); my @branchloop; 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 fea01f3dd2..8d197afb3b 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 @@ -2,6 +2,7 @@ Koha › Administration › Circulation and fine rules [% INCLUDE 'doc-head-close.inc' %] [% INCLUDE 'calendar.inc' %] +[% USE Branches %]