From 62c340f06a4b9804751009e5cfa83bc850836cc7 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 8 Nov 2021 15:32:36 -0300 Subject: [PATCH] Bug 27946: Add article request fee to circulation rules This patch adds a new circulation rule: article requests fee. It can be set per library and category. To test: 1. Try setting sdifferent numeric values, change, and delete them => SUCCESS: Things work as expected 2. Make sure rules are loaded correctly when re-entering the circ rules page => SUCCESS: All good 3. Verify the data on the DB is stored as it should on each of your tests: $ koha-mysql kohadev > SELECT * FROM circulation_rules \ WHERE rule_name='article_request_fee'; => SUCCESS: All good (remember NULL => 'All' in the UI) 4. Sign off :-D Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize Signed-off-by: Fridolin Somers --- Koha/CirculationRules.pm | 3 + admin/smart-rules.pl | 27 ++++++++ .../prog/en/modules/admin/smart-rules.tt | 69 ++++++++++++++++++- 3 files changed, 98 insertions(+), 1 deletion(-) diff --git a/Koha/CirculationRules.pm b/Koha/CirculationRules.pm index eb66f5f1a0..d2a97d480d 100644 --- a/Koha/CirculationRules.pm +++ b/Koha/CirculationRules.pm @@ -76,6 +76,9 @@ our $RULE_KINDS = { article_requests => { scope => [ 'branchcode', 'categorycode', 'itemtype' ], }, + article_request_fee => { + scope => [ 'branchcode', 'categorycode' ], + }, open_article_requests_limit => { scope => [ 'branchcode', 'categorycode' ], }, diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index 31ed87a83a..8f429ec6ae 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -531,6 +531,33 @@ elsif ( $op eq "add-open-article-requests-limit" ) { ); } } +elsif ( $op eq "set-article-request-fee" ) { + + my $category = $input->param('article_request_fee_category'); + my $fee = strip_non_numeric( scalar $input->param('article_request_fee') ); + + Koha::Exceptions::Exception->throw("No value passed for article request fee") + if not defined $fee # There is a JS check for that + || $fee eq ''; + + Koha::CirculationRules->set_rules( + { categorycode => ( $category eq '*' ) ? undef : $category, + branchcode => ( $branch eq '*' ) ? undef : $branch, + rules => { article_request_fee => $fee }, + } + ); + +} elsif ( $op eq 'del-article-request-fee' ) { + + my $category = $input->param('article_request_fee_category'); + + Koha::CirculationRules->set_rules( + { categorycode => ( $category eq '*' ) ? undef : $category, + branchcode => ( $branch eq '*' ) ? undef : $branch, + rules => { article_request_fee => undef }, + } + ); +} elsif ($op eq "add-branch-item") { my $itemtype = $input->param('itemtype'); my $holdallowed = $input->param('holdallowed'); 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 2d24283cbc..ca0a7fd39f 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 @@ -787,7 +787,7 @@ [% END %] - [% IF Koha.Preference('ArticleRequests') %] +[% IF Koha.Preference('ArticleRequests') %]
[% IF humanbranch %]

Daily open article requests limit for [% Branches.GetName( humanbranch ) | html %]

@@ -841,7 +841,66 @@
+
+ [% IF humanbranch %] +

Article request fees for [% Branches.GetName( humanbranch ) | html %]

+ [% ELSE %] +

Default article request fees

[% END %] +

Specify the article request fee for a given patron category.

+
+ + + + + + + + + [% FOREACH c IN categorycodes %] + [% SET c = '*' UNLESS c.defined AND c != '' %] + + [% SET article_request_fee = CirculationRules.Search( current_branch, c, undef, 'article_request_fee' ) %] + + [% IF ( article_request_fee.defined && article_request_fee != '' ) %] + + + + + + [% END %] + [% END %] + + + + + +
Patron categoryFee 
+ [% IF c == '*' %] + All + [% ELSE %] + [% Categories.GetName(c) | html %] + [% END %] + + [% IF article_request_fee.defined && article_request_fee != '' %] + [% article_request_fee | html %] + [% ELSE %] + 0 + [% END %] + + Delete +
+ +
+
+
+ +[% END %]
[% IF current_branch == '*' %] @@ -1237,6 +1296,14 @@ } return true; }); + + $("#set-article-request-fee").on("submit", function(){ + if (! $("input[name='article_request_fee'").val().length){ + alert("Please set a valid value for the fee"); + return false; + } + return true; + }); }); [% END %] -- 2.39.5