Lines 423-438
sub TooMany {
Link Here
|
423 |
my $branch = _GetCircControlBranch($item, $patron); |
423 |
my $branch = _GetCircControlBranch($item, $patron); |
424 |
my $type = $item->effective_itemtype; |
424 |
my $type = $item->effective_itemtype; |
425 |
|
425 |
|
426 |
my ($type_object, $parent_type, $parent_maxissueqty_rule); |
426 |
my $type_object = Koha::ItemTypes->find( $type ); |
427 |
$type_object = Koha::ItemTypes->find( $type ); |
427 |
my $parent_type = $type_object->parent_type if $type_object; |
428 |
$parent_type = $type_object->parent_type if $type_object; |
|
|
429 |
my $child_types = Koha::ItemTypes->search({ parent_type => $type }); |
428 |
my $child_types = Koha::ItemTypes->search({ parent_type => $type }); |
430 |
# Find any children if we are a parent_type; |
429 |
# Find any children if we are a parent_type; |
431 |
|
430 |
|
432 |
# given branch, patron category, and item type, determine |
431 |
# given branch, patron category, and item type, determine |
433 |
# applicable issuing rule |
432 |
# applicable issuing rule |
434 |
|
433 |
|
435 |
$parent_maxissueqty_rule = Koha::CirculationRules->get_effective_rule( |
434 |
# If the parent rule is for default type we discount it |
|
|
435 |
my $parent_maxissueqty; |
436 |
$parent_maxissueqty = Koha::CirculationRules->get_effective_rule_value( |
436 |
{ |
437 |
{ |
437 |
categorycode => $cat_borrower, |
438 |
categorycode => $cat_borrower, |
438 |
itemtype => $parent_type, |
439 |
itemtype => $parent_type, |
Lines 440-449
sub TooMany {
Link Here
|
440 |
rule_name => 'maxissueqty', |
441 |
rule_name => 'maxissueqty', |
441 |
} |
442 |
} |
442 |
) if $parent_type; |
443 |
) if $parent_type; |
443 |
# If the parent rule is for default type we discount it |
|
|
444 |
$parent_maxissueqty_rule = undef if $parent_maxissueqty_rule && !defined $parent_maxissueqty_rule->itemtype; |
445 |
|
444 |
|
446 |
my $maxissueqty_rule = Koha::CirculationRules->get_effective_rule( |
445 |
my $maxissueqty = Koha::CirculationRules->get_effective_rule_value( |
447 |
{ |
446 |
{ |
448 |
categorycode => $cat_borrower, |
447 |
categorycode => $cat_borrower, |
449 |
itemtype => $type, |
448 |
itemtype => $type, |
Lines 452-458
sub TooMany {
Link Here
|
452 |
} |
451 |
} |
453 |
); |
452 |
); |
454 |
|
453 |
|
455 |
my $maxonsiteissueqty_rule = Koha::CirculationRules->get_effective_rule( |
454 |
my $maxonsiteissueqty = Koha::CirculationRules->get_effective_rule_value( |
456 |
{ |
455 |
{ |
457 |
categorycode => $cat_borrower, |
456 |
categorycode => $cat_borrower, |
458 |
itemtype => $type, |
457 |
itemtype => $type, |
Lines 464-482
sub TooMany {
Link Here
|
464 |
# if a rule is found and has a loan limit set, count |
463 |
# if a rule is found and has a loan limit set, count |
465 |
# how many loans the patron already has that meet that |
464 |
# how many loans the patron already has that meet that |
466 |
# rule |
465 |
# rule |
467 |
if (defined($maxissueqty_rule) and $maxissueqty_rule->rule_value ne "") { |
466 |
if (defined $maxissueqty and $maxissueqty ne "") { |
468 |
|
467 |
|
469 |
my $checkouts; |
468 |
my $checkouts; |
470 |
if ( $maxissueqty_rule->branchcode ) { |
469 |
if ( $branch ) { |
471 |
if ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) { |
470 |
if ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) { |
472 |
$checkouts = $patron->checkouts->search( |
471 |
$checkouts = $patron->checkouts->search( |
473 |
{ 'me.branchcode' => $maxissueqty_rule->branchcode } ); |
472 |
{ 'me.branchcode' => $branch } ); |
474 |
} elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') { |
473 |
} elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') { |
475 |
$checkouts = $patron->checkouts; # if branch is the patron's home branch, then count all loans by patron |
474 |
$checkouts = $patron->checkouts; # if branch is the patron's home branch, then count all loans by patron |
476 |
} else { |
475 |
} else { |
477 |
my $branch_type = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch'; |
476 |
my $branch_type = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch'; |
478 |
$checkouts = $patron->checkouts->search( |
477 |
$checkouts = $patron->checkouts->search( { "item.$branch_type" => $branch } ); |
479 |
{ "item.$branch_type" => $maxissueqty_rule->branchcode } ); |
|
|
480 |
} |
478 |
} |
481 |
} else { |
479 |
} else { |
482 |
$checkouts = $patron->checkouts; # if rule is not branch specific then count all loans by patron |
480 |
$checkouts = $patron->checkouts; # if rule is not branch specific then count all loans by patron |
Lines 484-506
sub TooMany {
Link Here
|
484 |
$checkouts = $checkouts->search(undef, { prefetch => 'item' }); |
482 |
$checkouts = $checkouts->search(undef, { prefetch => 'item' }); |
485 |
|
483 |
|
486 |
my $sum_checkouts; |
484 |
my $sum_checkouts; |
487 |
my $rule_itemtype = $maxissueqty_rule->itemtype; |
|
|
488 |
|
485 |
|
489 |
my @types; |
486 |
my @types; |
490 |
unless ( $rule_itemtype ) { |
487 |
unless ( $type ) { |
491 |
# matching rule has the default item type, so count only |
488 |
# matching rule has the default item type, so count only |
492 |
# those existing loans that don't fall under a more |
489 |
# those existing loans that don't fall under a more |
493 |
# specific rule |
490 |
# specific rule |
494 |
@types = Koha::CirculationRules->search( |
491 |
@types = Koha::CirculationRules->search( |
495 |
{ |
492 |
{ |
496 |
branchcode => $maxissueqty_rule->branchcode, |
493 |
branchcode => $branch, |
497 |
categorycode => [ $maxissueqty_rule->categorycode, $cat_borrower ], |
494 |
categorycode => $cat_borrower, |
498 |
itemtype => { '!=' => undef }, |
495 |
itemtype => { '!=' => undef }, |
499 |
rule_name => 'maxissueqty' |
496 |
rule_name => 'maxissueqty' |
500 |
} |
497 |
} |
501 |
)->get_column('itemtype'); |
498 |
)->get_column('itemtype'); |
502 |
} else { |
499 |
} else { |
503 |
if ( $parent_maxissueqty_rule ) { |
500 |
if ( $parent_maxissueqty ) { |
504 |
# if we have a parent item type then we count loans of the |
501 |
# if we have a parent item type then we count loans of the |
505 |
# specific item type or its siblings or parent |
502 |
# specific item type or its siblings or parent |
506 |
my $children = Koha::ItemTypes->search({ parent_type => $parent_type }); |
503 |
my $children = Koha::ItemTypes->search({ parent_type => $parent_type }); |
Lines 519-525
sub TooMany {
Link Here
|
519 |
while ( my $c = $checkouts->next ) { |
516 |
while ( my $c = $checkouts->next ) { |
520 |
my $itemtype = $c->item->effective_itemtype; |
517 |
my $itemtype = $c->item->effective_itemtype; |
521 |
|
518 |
|
522 |
unless ( $rule_itemtype ) { |
519 |
unless ( $type ) { |
523 |
next if grep {$_ eq $itemtype} @types; |
520 |
next if grep {$_ eq $itemtype} @types; |
524 |
} else { |
521 |
} else { |
525 |
next unless grep {$_ eq $itemtype} @types; |
522 |
next unless grep {$_ eq $itemtype} @types; |
Lines 538-557
sub TooMany {
Link Here
|
538 |
checkout_count => $checkout_count, |
535 |
checkout_count => $checkout_count, |
539 |
onsite_checkout_count => $onsite_checkout_count, |
536 |
onsite_checkout_count => $onsite_checkout_count, |
540 |
onsite_checkout => $onsite_checkout, |
537 |
onsite_checkout => $onsite_checkout, |
541 |
max_checkouts_allowed => $maxissueqty_rule ? $maxissueqty_rule->rule_value : undef, |
538 |
max_checkouts_allowed => $maxissueqty,, |
542 |
max_onsite_checkouts_allowed => $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : undef, |
539 |
max_onsite_checkouts_allowed => $maxonsiteissueqty, |
543 |
switch_onsite_checkout => $switch_onsite_checkout, |
540 |
switch_onsite_checkout => $switch_onsite_checkout, |
544 |
}; |
541 |
}; |
545 |
# If parent rules exists |
542 |
# If parent rules exists |
546 |
if ( defined($parent_maxissueqty_rule) and defined($parent_maxissueqty_rule->rule_value) ){ |
543 |
if ( defined $parent_maxissueqty ){ |
547 |
$checkout_rules->{max_checkouts_allowed} = $parent_maxissueqty_rule ? $parent_maxissueqty_rule->rule_value : undef; |
544 |
$checkout_rules->{max_checkouts_allowed} = $parent_maxissueqty; |
548 |
my $qty_over = _check_max_qty($checkout_rules); |
545 |
my $qty_over = _check_max_qty($checkout_rules); |
549 |
return $qty_over if defined $qty_over; |
546 |
return $qty_over if defined $qty_over; |
550 |
|
547 |
|
551 |
# If the parent rule is less than or equal to the child, we only need check the parent |
548 |
# If the parent rule is less than or equal to the child, we only need check the parent |
552 |
if( $maxissueqty_rule->rule_value < $parent_maxissueqty_rule->rule_value && defined($maxissueqty_rule->itemtype) ) { |
549 |
if( $maxissueqty < $parent_maxissueqty && defined($type) ) { |
553 |
$checkout_rules->{checkout_count} = $checkout_count_type; |
550 |
$checkout_rules->{checkout_count} = $checkout_count_type; |
554 |
$checkout_rules->{max_checkouts_allowed} = $maxissueqty_rule ? $maxissueqty_rule->rule_value : undef; |
551 |
$checkout_rules->{max_checkouts_allowed} = $maxissueqty; |
555 |
my $qty_over = _check_max_qty($checkout_rules); |
552 |
my $qty_over = _check_max_qty($checkout_rules); |
556 |
return $qty_over if defined $qty_over; |
553 |
return $qty_over if defined $qty_over; |
557 |
} |
554 |
} |
Lines 595-601
sub TooMany {
Link Here
|
595 |
return $qty_over if defined $qty_over; |
592 |
return $qty_over if defined $qty_over; |
596 |
} |
593 |
} |
597 |
|
594 |
|
598 |
if ( not defined( $maxissueqty_rule ) and not defined($branch_borrower_circ_rule->{patron_maxissueqty}) ) { |
595 |
unless ( defined $maxissueqty || defined $branch_borrower_circ_rule->{patron_maxissueqty} ) { |
599 |
return { reason => 'NO_RULE_DEFINED', max_allowed => 0 }; |
596 |
return { reason => 'NO_RULE_DEFINED', max_allowed => 0 }; |
600 |
} |
597 |
} |
601 |
|
598 |
|
Lines 1922-1949
wildcards.
Link Here
|
1922 |
|
1919 |
|
1923 |
sub GetBranchBorrowerCircRule { |
1920 |
sub GetBranchBorrowerCircRule { |
1924 |
my ( $branchcode, $categorycode ) = @_; |
1921 |
my ( $branchcode, $categorycode ) = @_; |
1925 |
|
1922 |
return Koha::CirculationRules->get_effective_rules( |
1926 |
# Initialize default values |
1923 |
{ |
1927 |
my $rules = { |
1924 |
categorycode => $categorycode, |
1928 |
patron_maxissueqty => undef, |
1925 |
itemtype => undef, |
1929 |
patron_maxonsiteissueqty => undef, |
1926 |
branchcode => $branchcode, |
1930 |
}; |
1927 |
rules => ['patron_maxissueqty', 'patron_maxonsiteissueqty'] |
1931 |
|
1928 |
} |
1932 |
# Search for rules! |
1929 |
); |
1933 |
foreach my $rule_name (qw( patron_maxissueqty patron_maxonsiteissueqty )) { |
|
|
1934 |
my $rule = Koha::CirculationRules->get_effective_rule( |
1935 |
{ |
1936 |
categorycode => $categorycode, |
1937 |
itemtype => undef, |
1938 |
branchcode => $branchcode, |
1939 |
rule_name => $rule_name, |
1940 |
} |
1941 |
); |
1942 |
|
1943 |
$rules->{$rule_name} = $rule->rule_value if defined $rule; |
1944 |
} |
1945 |
|
1946 |
return $rules; |
1947 |
} |
1930 |
} |
1948 |
|
1931 |
|
1949 |
=head2 GetBranchItemRule |
1932 |
=head2 GetBranchItemRule |