# Now count total loans against the limit for the branch
my $branch_borrower_circ_rule = GetBranchBorrowerCircRule($branch, $cat_borrower);
- if (defined($branch_borrower_circ_rule->{patron_maxissueqty})) {
+ if (defined($branch_borrower_circ_rule->{patron_maxissueqty}) and $branch_borrower_circ_rule->{patron_maxissueqty} ne '') {
my @bind_params = ();
my $branch_count_query = q|
SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts
my $max_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxissueqty};
my $max_onsite_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxonsiteissueqty};
- if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) {
+ if ( $onsite_checkout and $max_onsite_checkouts_allowed ne '' ) {
if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed ) {
return {
reason => 'TOO_MANY_ONSITE_CHECKOUTS',
sub GetBranchBorrowerCircRule {
my ( $branchcode, $categorycode ) = @_;
- # Set search prededences
- my @params = (
- {
- branchcode => $branchcode,
- categorycode => $categorycode,
- itemtype => undef,
- },
- {
- branchcode => $branchcode,
- categorycode => undef,
- itemtype => undef,
- },
- {
- branchcode => undef,
- categorycode => $categorycode,
- itemtype => undef,
- },
- {
- branchcode => undef,
- categorycode => undef,
- itemtype => undef,
- },
- );
-
# Initialize default values
my $rules = {
patron_maxissueqty => undef,
# Search for rules!
foreach my $rule_name (qw( patron_maxissueqty patron_maxonsiteissueqty )) {
- foreach my $params (@params) {
- my $rule = Koha::CirculationRules->search(
- {
- rule_name => $rule_name,
- %$params,
- }
- )->next();
-
- if ( $rule ) {
- $rules->{$rule_name} = $rule->rule_value;
- last;
+ my $rule = Koha::CirculationRules->get_effective_rule(
+ {
+ categorycode => $categorycode,
+ itemtype => undef,
+ branchcode => $branchcode,
+ rule_name => $rule_name,
}
- }
+ );
+
+ $rules->{$rule_name} = $rule->rule_value if defined $rule;
}
return $rules;