Lines 425-440
sub TooMany {
Link Here
|
425 |
my $branch = _GetCircControlBranch($item_object->unblessed,$borrower); |
425 |
my $branch = _GetCircControlBranch($item_object->unblessed,$borrower); |
426 |
my $type = $item_object->effective_itemtype; |
426 |
my $type = $item_object->effective_itemtype; |
427 |
|
427 |
|
428 |
my ($type_object, $parent_type, $parent_maxissueqty_rule); |
428 |
my $type_object = Koha::ItemTypes->find( $type ); |
429 |
$type_object = Koha::ItemTypes->find( $type ); |
429 |
my $parent_type = $type_object->parent_type if $type_object; |
430 |
$parent_type = $type_object->parent_type if $type_object; |
|
|
431 |
my $child_types = Koha::ItemTypes->search({ parent_type => $type }); |
430 |
my $child_types = Koha::ItemTypes->search({ parent_type => $type }); |
432 |
# Find any children if we are a parent_type; |
431 |
# Find any children if we are a parent_type; |
433 |
|
432 |
|
434 |
# given branch, patron category, and item type, determine |
433 |
# given branch, patron category, and item type, determine |
435 |
# applicable issuing rule |
434 |
# applicable issuing rule |
436 |
|
435 |
|
437 |
$parent_maxissueqty_rule = Koha::CirculationRules->get_effective_rule( |
436 |
# If the parent rule is for default type we discount it |
|
|
437 |
my $parent_maxissueqty; |
438 |
$parent_maxissueqty = Koha::CirculationRules->get_effective_rule_value( |
438 |
{ |
439 |
{ |
439 |
categorycode => $cat_borrower, |
440 |
categorycode => $cat_borrower, |
440 |
itemtype => $parent_type, |
441 |
itemtype => $parent_type, |
Lines 442-451
sub TooMany {
Link Here
|
442 |
rule_name => 'maxissueqty', |
443 |
rule_name => 'maxissueqty', |
443 |
} |
444 |
} |
444 |
) if $parent_type; |
445 |
) if $parent_type; |
445 |
# If the parent rule is for default type we discount it |
|
|
446 |
$parent_maxissueqty_rule = undef if $parent_maxissueqty_rule && !defined $parent_maxissueqty_rule->itemtype; |
447 |
|
446 |
|
448 |
my $maxissueqty_rule = Koha::CirculationRules->get_effective_rule( |
447 |
my $maxissueqty = Koha::CirculationRules->get_effective_rule_value( |
449 |
{ |
448 |
{ |
450 |
categorycode => $cat_borrower, |
449 |
categorycode => $cat_borrower, |
451 |
itemtype => $type, |
450 |
itemtype => $type, |
Lines 454-460
sub TooMany {
Link Here
|
454 |
} |
453 |
} |
455 |
); |
454 |
); |
456 |
|
455 |
|
457 |
my $maxonsiteissueqty_rule = Koha::CirculationRules->get_effective_rule( |
456 |
my $maxonsiteissueqty = Koha::CirculationRules->get_effective_rule_value( |
458 |
{ |
457 |
{ |
459 |
categorycode => $cat_borrower, |
458 |
categorycode => $cat_borrower, |
460 |
itemtype => $type, |
459 |
itemtype => $type, |
Lines 468-486
sub TooMany {
Link Here
|
468 |
# if a rule is found and has a loan limit set, count |
467 |
# if a rule is found and has a loan limit set, count |
469 |
# how many loans the patron already has that meet that |
468 |
# how many loans the patron already has that meet that |
470 |
# rule |
469 |
# rule |
471 |
if (defined($maxissueqty_rule) and $maxissueqty_rule->rule_value ne "") { |
470 |
if (defined $maxissueqty and $maxissueqty ne "") { |
472 |
|
471 |
|
473 |
my $checkouts; |
472 |
my $checkouts; |
474 |
if ( $maxissueqty_rule->branchcode ) { |
473 |
if ( $branch ) { |
475 |
if ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) { |
474 |
if ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) { |
476 |
$checkouts = $patron->checkouts->search( |
475 |
$checkouts = $patron->checkouts->search( |
477 |
{ 'me.branchcode' => $maxissueqty_rule->branchcode } ); |
476 |
{ 'me.branchcode' => $branch } ); |
478 |
} elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') { |
477 |
} elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') { |
479 |
$checkouts = $patron->checkouts; # if branch is the patron's home branch, then count all loans by patron |
478 |
$checkouts = $patron->checkouts; # if branch is the patron's home branch, then count all loans by patron |
480 |
} else { |
479 |
} else { |
481 |
my $branch_type = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch'; |
480 |
my $branch_type = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch'; |
482 |
$checkouts = $patron->checkouts->search( |
481 |
$checkouts = $patron->checkouts->search( { "item.$branch_type" => $branch } ); |
483 |
{ "item.$branch_type" => $maxissueqty_rule->branchcode } ); |
|
|
484 |
} |
482 |
} |
485 |
} else { |
483 |
} else { |
486 |
$checkouts = $patron->checkouts; # if rule is not branch specific then count all loans by patron |
484 |
$checkouts = $patron->checkouts; # if rule is not branch specific then count all loans by patron |
Lines 488-510
sub TooMany {
Link Here
|
488 |
$checkouts = $checkouts->search(undef, { prefetch => 'item' }); |
486 |
$checkouts = $checkouts->search(undef, { prefetch => 'item' }); |
489 |
|
487 |
|
490 |
my $sum_checkouts; |
488 |
my $sum_checkouts; |
491 |
my $rule_itemtype = $maxissueqty_rule->itemtype; |
|
|
492 |
|
489 |
|
493 |
my @types; |
490 |
my @types; |
494 |
unless ( $rule_itemtype ) { |
491 |
unless ( $type ) { |
495 |
# matching rule has the default item type, so count only |
492 |
# matching rule has the default item type, so count only |
496 |
# those existing loans that don't fall under a more |
493 |
# those existing loans that don't fall under a more |
497 |
# specific rule |
494 |
# specific rule |
498 |
@types = Koha::CirculationRules->search( |
495 |
@types = Koha::CirculationRules->search( |
499 |
{ |
496 |
{ |
500 |
branchcode => $maxissueqty_rule->branchcode, |
497 |
branchcode => $branch, |
501 |
categorycode => [ $maxissueqty_rule->categorycode, $cat_borrower ], |
498 |
categorycode => $cat_borrower, |
502 |
itemtype => { '!=' => undef }, |
499 |
itemtype => { '!=' => undef }, |
503 |
rule_name => 'maxissueqty' |
500 |
rule_name => 'maxissueqty' |
504 |
} |
501 |
} |
505 |
)->get_column('itemtype'); |
502 |
)->get_column('itemtype'); |
506 |
} else { |
503 |
} else { |
507 |
if ( $parent_maxissueqty_rule ) { |
504 |
if ( $parent_maxissueqty ) { |
508 |
# if we have a parent item type then we count loans of the |
505 |
# if we have a parent item type then we count loans of the |
509 |
# specific item type or its siblings or parent |
506 |
# specific item type or its siblings or parent |
510 |
my $children = Koha::ItemTypes->search({ parent_type => $parent_type }); |
507 |
my $children = Koha::ItemTypes->search({ parent_type => $parent_type }); |
Lines 523-529
sub TooMany {
Link Here
|
523 |
while ( my $c = $checkouts->next ) { |
520 |
while ( my $c = $checkouts->next ) { |
524 |
my $itemtype = $c->item->effective_itemtype; |
521 |
my $itemtype = $c->item->effective_itemtype; |
525 |
|
522 |
|
526 |
unless ( $rule_itemtype ) { |
523 |
unless ( $type ) { |
527 |
next if grep {$_ eq $itemtype} @types; |
524 |
next if grep {$_ eq $itemtype} @types; |
528 |
} else { |
525 |
} else { |
529 |
next unless grep {$_ eq $itemtype} @types; |
526 |
next unless grep {$_ eq $itemtype} @types; |
Lines 542-561
sub TooMany {
Link Here
|
542 |
checkout_count => $checkout_count, |
539 |
checkout_count => $checkout_count, |
543 |
onsite_checkout_count => $onsite_checkout_count, |
540 |
onsite_checkout_count => $onsite_checkout_count, |
544 |
onsite_checkout => $onsite_checkout, |
541 |
onsite_checkout => $onsite_checkout, |
545 |
max_checkouts_allowed => $maxissueqty_rule ? $maxissueqty_rule->rule_value : undef, |
542 |
max_checkouts_allowed => $maxissueqty,, |
546 |
max_onsite_checkouts_allowed => $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : undef, |
543 |
max_onsite_checkouts_allowed => $maxonsiteissueqty, |
547 |
switch_onsite_checkout => $switch_onsite_checkout, |
544 |
switch_onsite_checkout => $switch_onsite_checkout, |
548 |
}; |
545 |
}; |
549 |
# If parent rules exists |
546 |
# If parent rules exists |
550 |
if ( defined($parent_maxissueqty_rule) and defined($parent_maxissueqty_rule->rule_value) ){ |
547 |
if ( defined $parent_maxissueqty ){ |
551 |
$checkout_rules->{max_checkouts_allowed} = $parent_maxissueqty_rule ? $parent_maxissueqty_rule->rule_value : undef; |
548 |
$checkout_rules->{max_checkouts_allowed} = $parent_maxissueqty; |
552 |
my $qty_over = _check_max_qty($checkout_rules); |
549 |
my $qty_over = _check_max_qty($checkout_rules); |
553 |
return $qty_over if defined $qty_over; |
550 |
return $qty_over if defined $qty_over; |
554 |
|
551 |
|
555 |
# If the parent rule is less than or equal to the child, we only need check the parent |
552 |
# If the parent rule is less than or equal to the child, we only need check the parent |
556 |
if( $maxissueqty_rule->rule_value < $parent_maxissueqty_rule->rule_value && defined($maxissueqty_rule->itemtype) ) { |
553 |
if( $maxissueqty < $parent_maxissueqty && defined($type) ) { |
557 |
$checkout_rules->{checkout_count} = $checkout_count_type; |
554 |
$checkout_rules->{checkout_count} = $checkout_count_type; |
558 |
$checkout_rules->{max_checkouts_allowed} = $maxissueqty_rule ? $maxissueqty_rule->rule_value : undef; |
555 |
$checkout_rules->{max_checkouts_allowed} = $maxissueqty; |
559 |
my $qty_over = _check_max_qty($checkout_rules); |
556 |
my $qty_over = _check_max_qty($checkout_rules); |
560 |
return $qty_over if defined $qty_over; |
557 |
return $qty_over if defined $qty_over; |
561 |
} |
558 |
} |
Lines 599-605
sub TooMany {
Link Here
|
599 |
return $qty_over if defined $qty_over; |
596 |
return $qty_over if defined $qty_over; |
600 |
} |
597 |
} |
601 |
|
598 |
|
602 |
if ( not defined( $maxissueqty_rule ) and not defined($branch_borrower_circ_rule->{patron_maxissueqty}) ) { |
599 |
unless ( defined $maxissueqty || defined $branch_borrower_circ_rule->{patron_maxissueqty} ) { |
603 |
return { reason => 'NO_RULE_DEFINED', max_allowed => 0 }; |
600 |
return { reason => 'NO_RULE_DEFINED', max_allowed => 0 }; |
604 |
} |
601 |
} |
605 |
|
602 |
|
Lines 1903-1930
wildcards.
Link Here
|
1903 |
|
1900 |
|
1904 |
sub GetBranchBorrowerCircRule { |
1901 |
sub GetBranchBorrowerCircRule { |
1905 |
my ( $branchcode, $categorycode ) = @_; |
1902 |
my ( $branchcode, $categorycode ) = @_; |
1906 |
|
1903 |
return Koha::CirculationRules->get_effective_rules( |
1907 |
# Initialize default values |
1904 |
{ |
1908 |
my $rules = { |
1905 |
categorycode => $categorycode, |
1909 |
patron_maxissueqty => undef, |
1906 |
itemtype => undef, |
1910 |
patron_maxonsiteissueqty => undef, |
1907 |
branchcode => $branchcode, |
1911 |
}; |
1908 |
rules => ['patron_maxissueqty', 'patron_maxonsiteissueqty'] |
1912 |
|
1909 |
} |
1913 |
# Search for rules! |
1910 |
); |
1914 |
foreach my $rule_name (qw( patron_maxissueqty patron_maxonsiteissueqty )) { |
|
|
1915 |
my $rule = Koha::CirculationRules->get_effective_rule( |
1916 |
{ |
1917 |
categorycode => $categorycode, |
1918 |
itemtype => undef, |
1919 |
branchcode => $branchcode, |
1920 |
rule_name => $rule_name, |
1921 |
} |
1922 |
); |
1923 |
|
1924 |
$rules->{$rule_name} = $rule->rule_value if defined $rule; |
1925 |
} |
1926 |
|
1927 |
return $rules; |
1928 |
} |
1911 |
} |
1929 |
|
1912 |
|
1930 |
=head2 GetBranchItemRule |
1913 |
=head2 GetBranchItemRule |