@@ -, +, @@ system by patron category in the "Checkout limit by patron category". ( Should we rename this section? ) number of holds that patron has. Lets make that number 'X'. --- C4/Reserves.pm | 19 +++++---- admin/smart-rules.pl | 48 ++++++++++++++++++++-- .../prog/en/modules/admin/smart-rules.tt | 9 ++-- t/db_dependent/Holds.t | 30 +++++++++----- 4 files changed, 81 insertions(+), 25 deletions(-) --- a/C4/Reserves.pm +++ a/C4/Reserves.pm @@ -48,6 +48,7 @@ use Koha::IssuingRules; use Koha::Items; use Koha::ItemTypes; use Koha::Patrons; +use Koha::CirculationRules; use List::MoreUtils qw( firstidx any ); use Carp; @@ -412,26 +413,30 @@ sub CanItemBeReserved { } # Now we need to check hold limits by patron category - my $schema = Koha::Database->new()->schema(); - my $rule = $schema->resultset('BranchBorrowerCircRule')->find( + my $rule = Koha::CirculationRules->find( { - branchcode => $branchcode, categorycode => $borrower->{categorycode}, + branchcode => $branchcode, + itemtype => undef, + rule_name => 'max_holds', } ); - $rule ||= $schema->resultset('DefaultBorrowerCircRule')->find( + $rule ||= Koha::CirculationRules->find( { - categorycode => $borrower->{categorycode} + categorycode => $borrower->{categorycode}, + branchcode => undef,, + itemtype => undef, + rule_name => 'max_holds', } ); - if ( $rule && defined $rule->max_holds ) { + if ( $rule ) { my $total_holds_count = Koha::Holds->search( { borrowernumber => $borrower->{borrowernumber} } )->count(); - return { status => 'tooManyReserves', limit => $rule->max_holds } if $total_holds_count >= $rule->max_holds; + return { status => 'tooManyReserves', limit => $rule->rule_value} if $total_holds_count >= $rule->rule_value; } my $circ_control_branch = --- a/admin/smart-rules.pl +++ a/admin/smart-rules.pl @@ -32,6 +32,7 @@ use Koha::Logger; use Koha::RefundLostItemFeeRule; use Koha::RefundLostItemFeeRules; use Koha::Libraries; +use Koha::CirculationRules; use Koha::Patron::Categories; use Koha::Caches; @@ -97,6 +98,15 @@ elsif ($op eq 'delete-branch-cat') { AND categorycode = ?"); $sth_delete->execute($branch, $categorycode); } + Koha::CirculationRules->set_rule( + { + branchcode => $branch, + categorycode => $categorycode, + itemtype => undef, + rule_name => 'max_holds', + rule_value => undef, + } + ); } elsif ($op eq 'delete-branch-item') { my $itemtype = $input->param('itemtype'); @@ -287,10 +297,20 @@ elsif ($op eq "add-branch-cat") { $sth_search->execute(); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $max_holds ); + $sth_update->execute( $maxissueqty, $maxonsiteissueqty ); } else { - $sth_insert->execute( $maxissueqty, $maxonsiteissueqty, $max_holds ); + $sth_insert->execute( $maxissueqty, $maxonsiteissueqty ); } + + Koha::CirculationRules->set_rule( + { + branchcode => undef, + categorycode => undef, + itemtype => undef, + rule_name => 'max_holds', + rule_value => $max_holds, + } + ); } else { my $sth_search = $dbh->prepare("SELECT count(*) AS total FROM default_borrower_circ_rules @@ -310,10 +330,20 @@ elsif ($op eq "add-branch-cat") { $sth_search->execute($categorycode); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $max_holds, $categorycode ); + $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $categorycode ); } else { - $sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty, $max_holds ); + $sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty ); } + + Koha::CirculationRules->set_rule( + { + branchcode => undef, + categorycode => $categorycode, + itemtype => undef, + rule_name => 'max_holds', + rule_value => $max_holds, + } + ); } } elsif ($categorycode eq "*") { my $sth_search = $dbh->prepare("SELECT count(*) AS total @@ -363,6 +393,16 @@ elsif ($op eq "add-branch-cat") { } else { $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty, $max_holds); } + + Koha::CirculationRules->set_rule( + { + branchcode => $branch, + categorycode => $categorycode, + itemtype => undef, + rule_name => 'max_holds', + rule_value => $max_holds, + } + ); } } elsif ($op eq "add-branch-item") { --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -1,6 +1,7 @@ [% USE raw %] [% USE Asset %] [% USE Branches %] +[% USE CirculationRules %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %]