From 6e0795c168ee7ce792377e1b2cc8682c132a68b0 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 4 Oct 2021 09:14:16 -0300 Subject: [PATCH] Bug 27945: Add max_daily_article_requests circulation rule Signed-off-by: Tomas Cohen Arazi --- Koha/CirculationRules.pm | 4 ++ admin/smart-rules.pl | 69 +++++++++++++++++++ .../data/mysql/atomicupdate/bug_27945.pl | 16 +++++ .../prog/en/modules/admin/smart-rules.tt | 56 +++++++++++++++ 4 files changed, 145 insertions(+) create mode 100755 installer/data/mysql/atomicupdate/bug_27945.pl diff --git a/Koha/CirculationRules.pm b/Koha/CirculationRules.pm index 9e23449ac1..f614c6e5a7 100644 --- a/Koha/CirculationRules.pm +++ b/Koha/CirculationRules.pm @@ -76,6 +76,10 @@ our $RULE_KINDS = { article_requests => { scope => [ 'branchcode', 'categorycode', 'itemtype' ], }, + max_daily_article_requests => { + scope => [ 'branchcode', 'categorycode' ], + }, + auto_renew => { scope => [ 'branchcode', 'categorycode', 'itemtype' ], }, diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index 7da7497d3a..cc4370a44f 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -457,6 +457,75 @@ elsif ($op eq "add-branch-cat") { ); } } +elsif ( $op eq "add-max-daily-article-requests" ) { + my $categorycode = $input->param('categorycode'); + my $max_daily_article_requests = strip_non_numeric( scalar $input->param('max_daily_article_requests') ); + + if ( $branch eq "*" ) { + if ( $categorycode eq "*" ) { + Koha::CirculationRules->set_rules( + { categorycode => undef, + branchcode => undef, + rules => { max_daily_article_requests => $max_daily_article_requests, } + } + ); + } else { + Koha::CirculationRules->set_rules( + { categorycode => $categorycode, + branchcode => undef, + rules => { max_daily_article_requests => $max_daily_article_requests, } + } + ); + } + } elsif ( $categorycode eq "*" ) { + Koha::CirculationRules->set_rules( + { categorycode => undef, + branchcode => $branch, + rules => { max_daily_article_requests => $max_daily_article_requests, } + } + ); + } else { + Koha::CirculationRules->set_rules( + { categorycode => $categorycode, + branchcode => $branch, + rules => { max_daily_article_requests => $max_daily_article_requests, } + } + ); + } +} elsif ( $op eq 'del-max-daily-article-requests' ) { + my $categorycode = $input->param('categorycode'); + if ( $branch eq "*" ) { + if ( $categorycode eq "*" ) { + Koha::CirculationRules->set_rules( + { branchcode => undef, + categorycode => undef, + rules => { max_daily_article_requests => undef, } + } + ); + } else { + Koha::CirculationRules->set_rules( + { categorycode => $categorycode, + branchcode => undef, + rules => { max_daily_article_requests => undef, } + } + ); + } + } elsif ( $categorycode eq "*" ) { + Koha::CirculationRules->set_rules( + { branchcode => $branch, + categorycode => undef, + rules => { max_daily_article_requests => undef, } + } + ); + } else { + Koha::CirculationRules->set_rules( + { categorycode => $categorycode, + branchcode => $branch, + rules => { max_daily_article_requests => undef, } + } + ); + } +} elsif ($op eq "add-branch-item") { my $itemtype = $input->param('itemtype'); my $holdallowed = $input->param('holdallowed'); diff --git a/installer/data/mysql/atomicupdate/bug_27945.pl b/installer/data/mysql/atomicupdate/bug_27945.pl new file mode 100755 index 0000000000..2be48d80c9 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_27945.pl @@ -0,0 +1,16 @@ +use Modern::Perl; + +return { + bug_number => "27945", + description => "Add max_daily_article_requests circulation rule", + up => sub { + my ($args) = @_; + my ($dbh) = @$args{qw(dbh)}; + + # Do you stuffs here + $dbh->do(q{ + INSERT IGNORE INTO circulation_rules (branchcode, categorycode, itemtype, rule_name, rule_value) + VALUES (NULL, NULL, NULL, 'max_daily_article_requests', NULL); + }); + }, + } 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 172e546f8a..3e8a47e94b 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,6 +787,62 @@ [% END %] + [% IF Koha.Preference('ArticleRequests') %] +
+ [% IF humanbranch %] +

Article requests limits for [% Branches.GetName( humanbranch ) | html %]

+ [% ELSE %] +

Default article requests limits

+ [% END %] +

Specify the maximum number simultaneous current article requests a patron of a given category can have.

+
+ + + + + + + + + [% FOREACH c IN categorycodes %] + [% NEXT UNLESS c %] + [% SET max_daily_article_requests = CirculationRules.Search( branchcode, c, undef, 'max_daily_article_requests' ) %] + + [% IF ( max_daily_article_requests.defined && max_daily_article_requests != '' ) %] + + + + + + + [% END %] + [% END %] + + + + + +
Patron categoryTotal article requests 
+ [% Categories.GetName(c) | html %] + + [% IF max_daily_article_requests.defined && max_daily_article_requests != '' %] + [% max_daily_article_requests | html %] + [% ELSE %] + Unlimited + [% END %] + + Delete +
+ +
+
+
+ [% END %] +
[% IF current_branch == '*' %]

Default lost item fee refund on return policy

-- 2.32.0