|
Lines 422-436
sub TooMany {
Link Here
|
| 422 |
my $branch = _GetCircControlBranch($item, $patron); |
422 |
my $branch = _GetCircControlBranch($item, $patron); |
| 423 |
my $type = $item->effective_itemtype; |
423 |
my $type = $item->effective_itemtype; |
| 424 |
|
424 |
|
| 425 |
my ($type_object, $parent_type, $parent_maxissueqty_rule); |
425 |
my $type_object = Koha::ItemTypes->find( $type ); |
| 426 |
$type_object = Koha::ItemTypes->find( $type ); |
426 |
my $parent_type = $type_object->parent_type if $type_object; |
| 427 |
$parent_type = $type_object->parent_type if $type_object; |
|
|
| 428 |
my $child_types = Koha::ItemTypes->search({ parent_type => $type }); |
427 |
my $child_types = Koha::ItemTypes->search({ parent_type => $type }); |
| 429 |
# Find any children if we are a parent_type; |
428 |
# Find any children if we are a parent_type; |
| 430 |
|
429 |
|
| 431 |
# given branch, patron category, and item type, determine |
430 |
# given branch, patron category, and item type, determine |
| 432 |
# applicable issuing rule |
431 |
# applicable issuing rule |
| 433 |
|
432 |
|
|
|
433 |
# If the parent rule is for default type we discount it |
| 434 |
my $parent_maxissueqty_rule; |
| 434 |
$parent_maxissueqty_rule = Koha::CirculationRules->get_effective_rule( |
435 |
$parent_maxissueqty_rule = Koha::CirculationRules->get_effective_rule( |
| 435 |
{ |
436 |
{ |
| 436 |
categorycode => $cat_borrower, |
437 |
categorycode => $cat_borrower, |
|
Lines 463-469
sub TooMany {
Link Here
|
| 463 |
# if a rule is found and has a loan limit set, count |
464 |
# if a rule is found and has a loan limit set, count |
| 464 |
# how many loans the patron already has that meet that |
465 |
# how many loans the patron already has that meet that |
| 465 |
# rule |
466 |
# rule |
| 466 |
if (defined($maxissueqty_rule) and $maxissueqty_rule->rule_value ne "") { |
467 |
if (defined $maxissueqty_rule and $maxissueqty_rule->rule_value ne "") { |
| 467 |
|
468 |
|
| 468 |
my $checkouts; |
469 |
my $checkouts; |
| 469 |
if ( $maxissueqty_rule->branchcode ) { |
470 |
if ( $maxissueqty_rule->branchcode ) { |
|
Lines 474-481
sub TooMany {
Link Here
|
| 474 |
$checkouts = $patron->checkouts; # if branch is the patron's home branch, then count all loans by patron |
475 |
$checkouts = $patron->checkouts; # if branch is the patron's home branch, then count all loans by patron |
| 475 |
} else { |
476 |
} else { |
| 476 |
my $branch_type = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch'; |
477 |
my $branch_type = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch'; |
| 477 |
$checkouts = $patron->checkouts->search( |
478 |
$checkouts = $patron->checkouts->search( { "item.$branch_type" => $maxissueqty_rule->branchcode } ); |
| 478 |
{ "item.$branch_type" => $maxissueqty_rule->branchcode } ); |
|
|
| 479 |
} |
479 |
} |
| 480 |
} else { |
480 |
} else { |
| 481 |
$checkouts = $patron->checkouts; # if rule is not branch specific then count all loans by patron |
481 |
$checkouts = $patron->checkouts; # if rule is not branch specific then count all loans by patron |
|
Lines 483-492
sub TooMany {
Link Here
|
| 483 |
$checkouts = $checkouts->search(undef, { prefetch => 'item' }); |
483 |
$checkouts = $checkouts->search(undef, { prefetch => 'item' }); |
| 484 |
|
484 |
|
| 485 |
my $sum_checkouts; |
485 |
my $sum_checkouts; |
| 486 |
my $rule_itemtype = $maxissueqty_rule->itemtype; |
|
|
| 487 |
|
486 |
|
| 488 |
my @types; |
487 |
my @types; |
| 489 |
unless ( $rule_itemtype || $parent_maxissueqty_rule ) { |
488 |
unless ( $maxissueqty_rule->itemtype || $parent_maxissueqty_rule ) { |
| 490 |
# matching rule has the default item type, so count only |
489 |
# matching rule has the default item type, so count only |
| 491 |
# those existing loans that don't fall under a more |
490 |
# those existing loans that don't fall under a more |
| 492 |
# specific rule |
491 |
# specific rule |
|
Lines 499-505
sub TooMany {
Link Here
|
| 499 |
} |
498 |
} |
| 500 |
)->get_column('itemtype'); |
499 |
)->get_column('itemtype'); |
| 501 |
} else { |
500 |
} else { |
| 502 |
if ( $parent_maxissueqty_rule ) { |
501 |
if ( defined $parent_maxissueqty_rule ) { |
| 503 |
# if we have a parent item type then we count loans of the |
502 |
# if we have a parent item type then we count loans of the |
| 504 |
# specific item type or its siblings or parent |
503 |
# specific item type or its siblings or parent |
| 505 |
my $children = Koha::ItemTypes->search({ parent_type => $parent_type }); |
504 |
my $children = Koha::ItemTypes->search({ parent_type => $parent_type }); |
|
Lines 518-524
sub TooMany {
Link Here
|
| 518 |
while ( my $c = $checkouts->next ) { |
517 |
while ( my $c = $checkouts->next ) { |
| 519 |
my $itemtype = $c->item->effective_itemtype; |
518 |
my $itemtype = $c->item->effective_itemtype; |
| 520 |
|
519 |
|
| 521 |
unless ( $rule_itemtype || $parent_maxissueqty_rule ) { |
520 |
unless ( $maxissueqty_rule->itemtype || $parent_maxissueqty_rule ) { |
| 522 |
next if grep {$_ eq $itemtype} @types; |
521 |
next if grep {$_ eq $itemtype} @types; |
| 523 |
} else { |
522 |
} else { |
| 524 |
next unless grep {$_ eq $itemtype} @types; |
523 |
next unless grep {$_ eq $itemtype} @types; |
|
Lines 544-558
sub TooMany {
Link Here
|
| 544 |
onsite_circulation_rule => $maxonsiteissueqty_rule, |
543 |
onsite_circulation_rule => $maxonsiteissueqty_rule, |
| 545 |
}; |
544 |
}; |
| 546 |
# If parent rules exists |
545 |
# If parent rules exists |
| 547 |
if ( defined($parent_maxissueqty_rule) and defined($parent_maxissueqty_rule->rule_value) ){ |
546 |
if ( defined $parent_maxissueqty_rule ) { |
| 548 |
$checkout_rules->{max_checkouts_allowed} = $parent_maxissueqty_rule ? $parent_maxissueqty_rule->rule_value : undef; |
547 |
$checkout_rules->{max_checkouts_allowed} = $parent_maxissueqty_rule->rule_value; |
| 549 |
my $qty_over = _check_max_qty($checkout_rules); |
548 |
my $qty_over = _check_max_qty($checkout_rules); |
| 550 |
return $qty_over if defined $qty_over; |
549 |
return $qty_over if defined $qty_over; |
| 551 |
|
550 |
|
| 552 |
# If the parent rule is less than or equal to the child, we only need check the parent |
551 |
# If the parent rule is less than or equal to the child, we only need check the parent |
| 553 |
if( $maxissueqty_rule->rule_value < $parent_maxissueqty_rule->rule_value && defined($maxissueqty_rule->itemtype) ) { |
552 |
if( |
|
|
553 |
$maxissueqty_rule->rule_value < $parent_maxissueqty_rule->rule_value |
| 554 |
&& defined($maxissueqty_rule->itemtype) |
| 555 |
) { |
| 554 |
$checkout_rules->{checkout_count} = $checkout_count_type; |
556 |
$checkout_rules->{checkout_count} = $checkout_count_type; |
| 555 |
$checkout_rules->{max_checkouts_allowed} = $maxissueqty_rule ? $maxissueqty_rule->rule_value : undef; |
557 |
$checkout_rules->{max_checkouts_allowed} = $maxissueqty_rule->rule_value; |
| 556 |
my $qty_over = _check_max_qty($checkout_rules); |
558 |
my $qty_over = _check_max_qty($checkout_rules); |
| 557 |
return $qty_over if defined $qty_over; |
559 |
return $qty_over if defined $qty_over; |
| 558 |
} |
560 |
} |
|
Lines 564-570
sub TooMany {
Link Here
|
| 564 |
|
566 |
|
| 565 |
# Now count total loans against the limit for the branch |
567 |
# Now count total loans against the limit for the branch |
| 566 |
my $branch_borrower_circ_rule = GetBranchBorrowerCircRule($branch, $cat_borrower); |
568 |
my $branch_borrower_circ_rule = GetBranchBorrowerCircRule($branch, $cat_borrower); |
| 567 |
if (defined($branch_borrower_circ_rule->{patron_maxissueqty}) and $branch_borrower_circ_rule->{patron_maxissueqty} ne '') { |
569 |
if ( |
|
|
570 |
defined($branch_borrower_circ_rule->{patron_maxissueqty}) |
| 571 |
and $branch_borrower_circ_rule->{patron_maxissueqty} ne '' |
| 572 |
) { |
| 568 |
my $checkouts; |
573 |
my $checkouts; |
| 569 |
if ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) { |
574 |
if ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) { |
| 570 |
$checkouts = $patron->checkouts->search( |
575 |
$checkouts = $patron->checkouts->search( |
|
Lines 597-603
sub TooMany {
Link Here
|
| 597 |
return $qty_over if defined $qty_over; |
602 |
return $qty_over if defined $qty_over; |
| 598 |
} |
603 |
} |
| 599 |
|
604 |
|
| 600 |
if ( not defined( $maxissueqty_rule ) and not defined($branch_borrower_circ_rule->{patron_maxissueqty}) ) { |
605 |
unless ( defined $maxissueqty_rule || defined $branch_borrower_circ_rule->{patron_maxissueqty} ) { |
| 601 |
return { reason => 'NO_RULE_DEFINED', max_allowed => 0 }; |
606 |
return { reason => 'NO_RULE_DEFINED', max_allowed => 0 }; |
| 602 |
} |
607 |
} |
| 603 |
|
608 |
|
|
Lines 617-623
sub _check_max_qty {
Link Here
|
| 617 |
my $onsite_circulation_rule = $params->{onsite_circulation_rule}; |
622 |
my $onsite_circulation_rule = $params->{onsite_circulation_rule}; |
| 618 |
|
623 |
|
| 619 |
if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) { |
624 |
if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) { |
| 620 |
if ( $max_onsite_checkouts_allowed eq '' ) { return; } |
625 |
return if $max_onsite_checkouts_allowed eq ''; |
| 621 |
if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed ) { |
626 |
if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed ) { |
| 622 |
return { |
627 |
return { |
| 623 |
reason => 'TOO_MANY_ONSITE_CHECKOUTS', |
628 |
reason => 'TOO_MANY_ONSITE_CHECKOUTS', |
|
Lines 628-634
sub _check_max_qty {
Link Here
|
| 628 |
} |
633 |
} |
| 629 |
} |
634 |
} |
| 630 |
if ( C4::Context->preference('ConsiderOnSiteCheckoutsAsNormalCheckouts') ) { |
635 |
if ( C4::Context->preference('ConsiderOnSiteCheckoutsAsNormalCheckouts') ) { |
| 631 |
if ( $max_checkouts_allowed eq '' ) { return; } |
636 |
return if $max_checkouts_allowed eq ''; |
| 632 |
my $delta = $switch_onsite_checkout ? 1 : 0; |
637 |
my $delta = $switch_onsite_checkout ? 1 : 0; |
| 633 |
if ( $checkout_count >= $max_checkouts_allowed + $delta ) { |
638 |
if ( $checkout_count >= $max_checkouts_allowed + $delta ) { |
| 634 |
return { |
639 |
return { |
|
Lines 640-649
sub _check_max_qty {
Link Here
|
| 640 |
} |
645 |
} |
| 641 |
} |
646 |
} |
| 642 |
elsif ( not $onsite_checkout ) { |
647 |
elsif ( not $onsite_checkout ) { |
| 643 |
if ( $max_checkouts_allowed eq '' ) { return; } |
648 |
return if $max_checkouts_allowed eq ''; |
| 644 |
if ( |
649 |
if ( |
| 645 |
$checkout_count - $onsite_checkout_count >= $max_checkouts_allowed ) |
650 |
$checkout_count - $onsite_checkout_count >= $max_checkouts_allowed |
| 646 |
{ |
651 |
) { |
| 647 |
return { |
652 |
return { |
| 648 |
reason => 'TOO_MANY_CHECKOUTS', |
653 |
reason => 'TOO_MANY_CHECKOUTS', |
| 649 |
count => $checkout_count - $onsite_checkout_count, |
654 |
count => $checkout_count - $onsite_checkout_count, |
|
Lines 1470-1491
sub checkHighHolds {
Link Here
|
| 1470 |
|
1475 |
|
| 1471 |
my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $patron ); |
1476 |
my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $patron ); |
| 1472 |
|
1477 |
|
| 1473 |
my $rule = Koha::CirculationRules->get_effective_rule_value( |
1478 |
# overrides decreaseLoanHighHoldsDuration syspref |
|
|
1479 |
my $duration = Koha::CirculationRules->get_effective_rule_value( |
| 1474 |
{ |
1480 |
{ |
| 1475 |
categorycode => $patron->categorycode, |
1481 |
categorycode => $patron->categorycode, |
| 1476 |
itemtype => $item->effective_itemtype, |
1482 |
itemtype => $item->effective_itemtype, |
| 1477 |
branchcode => $branchcode, |
1483 |
branchcode => $branchcode, |
| 1478 |
rule_name => 'decreaseloanholds', |
1484 |
rule_name => 'decreaseloanholds', |
| 1479 |
} |
1485 |
} |
| 1480 |
); |
1486 |
) || C4::Context->preference('decreaseLoanHighHoldsDuration'); |
| 1481 |
|
1487 |
|
| 1482 |
my $duration; |
|
|
| 1483 |
if ( defined($rule) && $rule ne '' ){ |
| 1484 |
# overrides decreaseLoanHighHoldsDuration syspref |
| 1485 |
$duration = $rule; |
| 1486 |
} else { |
| 1487 |
$duration = C4::Context->preference('decreaseLoanHighHoldsDuration'); |
| 1488 |
} |
| 1489 |
my $reduced_datedue = $calendar->addDuration( $issuedate, $duration ); |
1488 |
my $reduced_datedue = $calendar->addDuration( $issuedate, $duration ); |
| 1490 |
$reduced_datedue->set_hour($orig_due->hour); |
1489 |
$reduced_datedue->set_hour($orig_due->hour); |
| 1491 |
$reduced_datedue->set_minute($orig_due->minute); |
1490 |
$reduced_datedue->set_minute($orig_due->minute); |
|
Lines 1974-2000
wildcards.
Link Here
|
| 1974 |
sub GetBranchBorrowerCircRule { |
1973 |
sub GetBranchBorrowerCircRule { |
| 1975 |
my ( $branchcode, $categorycode ) = @_; |
1974 |
my ( $branchcode, $categorycode ) = @_; |
| 1976 |
|
1975 |
|
| 1977 |
# Initialize default values |
1976 |
return Koha::CirculationRules->get_effective_rules( |
| 1978 |
my $rules = { |
1977 |
{ |
| 1979 |
patron_maxissueqty => undef, |
1978 |
categorycode => $categorycode, |
| 1980 |
patron_maxonsiteissueqty => undef, |
1979 |
itemtype => undef, |
| 1981 |
}; |
1980 |
branchcode => $branchcode, |
| 1982 |
|
1981 |
rules => ['patron_maxissueqty', 'patron_maxonsiteissueqty'] |
| 1983 |
# Search for rules! |
1982 |
} |
| 1984 |
foreach my $rule_name (qw( patron_maxissueqty patron_maxonsiteissueqty )) { |
1983 |
); |
| 1985 |
my $rule = Koha::CirculationRules->get_effective_rule( |
|
|
| 1986 |
{ |
| 1987 |
categorycode => $categorycode, |
| 1988 |
itemtype => undef, |
| 1989 |
branchcode => $branchcode, |
| 1990 |
rule_name => $rule_name, |
| 1991 |
} |
| 1992 |
); |
| 1993 |
|
| 1994 |
$rules->{$rule_name} = $rule->rule_value if defined $rule; |
| 1995 |
} |
| 1996 |
|
| 1997 |
return $rules; |
| 1998 |
} |
1984 |
} |
| 1999 |
|
1985 |
|
| 2000 |
=head2 GetBranchItemRule |
1986 |
=head2 GetBranchItemRule |
|
Lines 2731-2741
sub _calculate_new_debar_dt {
Link Here
|
| 2731 |
] |
2717 |
] |
| 2732 |
} |
2718 |
} |
| 2733 |
); |
2719 |
); |
| 2734 |
my $finedays = $issuing_rule ? $issuing_rule->{finedays} : undef; |
2720 |
return unless $issuing_rule->{finedays}; |
| 2735 |
my $unit = $issuing_rule ? $issuing_rule->{lengthunit} : undef; |
2721 |
my $finedays = $issuing_rule->{finedays}; |
|
|
2722 |
my $unit = $issuing_rule->{lengthunit}; |
| 2736 |
my $chargeable_units = C4::Overdues::get_chargeable_units($unit, $dt_due, $return_date, $branchcode); |
2723 |
my $chargeable_units = C4::Overdues::get_chargeable_units($unit, $dt_due, $return_date, $branchcode); |
| 2737 |
|
2724 |
|
| 2738 |
return unless $finedays; |
|
|
| 2739 |
|
2725 |
|
| 2740 |
# finedays is in days, so hourly loans must multiply by 24 |
2726 |
# finedays is in days, so hourly loans must multiply by 24 |
| 2741 |
# thus 1 hour late equals 1 day suspension * finedays rate |
2727 |
# thus 1 hour late equals 1 day suspension * finedays rate |
|
Lines 3293-3306
sub AddRenewal {
Link Here
|
| 3293 |
# a maximum value has been set in the circ rules |
3279 |
# a maximum value has been set in the circ rules |
| 3294 |
my $unseen_renewals = $issue->unseen_renewals; |
3280 |
my $unseen_renewals = $issue->unseen_renewals; |
| 3295 |
if (C4::Context->preference('UnseenRenewals')) { |
3281 |
if (C4::Context->preference('UnseenRenewals')) { |
| 3296 |
my $rule = Koha::CirculationRules->get_effective_rule( |
3282 |
my $unseen_renewals_allowed = Koha::CirculationRules->get_effective_rule_value( |
| 3297 |
{ categorycode => $patron->categorycode, |
3283 |
{ categorycode => $patron->categorycode, |
| 3298 |
itemtype => $item_object->effective_itemtype, |
3284 |
itemtype => $item_object->effective_itemtype, |
| 3299 |
branchcode => $circ_library->branchcode, |
3285 |
branchcode => $circ_library->branchcode, |
| 3300 |
rule_name => 'unseen_renewals_allowed' |
3286 |
rule_name => 'unseen_renewals_allowed' |
| 3301 |
} |
3287 |
} |
| 3302 |
); |
3288 |
); |
| 3303 |
if (!$seen && $rule && looks_like_number($rule->rule_value)) { |
3289 |
if (!$seen && $unseen_renewals_allowed && looks_like_number($unseen_renewals_allowed)) { |
| 3304 |
$unseen_renewals++; |
3290 |
$unseen_renewals++; |
| 3305 |
} else { |
3291 |
} else { |
| 3306 |
# If the renewal is seen, unseen should revert to 0 |
3292 |
# If the renewal is seen, unseen should revert to 0 |
|
Lines 3665-3678
sub GetIssuingCharges {
Link Here
|
| 3665 |
# FIXME This should follow CircControl |
3651 |
# FIXME This should follow CircControl |
| 3666 |
my $branch = C4::Context::mybranch(); |
3652 |
my $branch = C4::Context::mybranch(); |
| 3667 |
$patron //= Koha::Patrons->find( $borrowernumber ); |
3653 |
$patron //= Koha::Patrons->find( $borrowernumber ); |
| 3668 |
my $discount = Koha::CirculationRules->get_effective_rule({ |
3654 |
my $discount = Koha::CirculationRules->get_effective_rule_value({ |
| 3669 |
categorycode => $patron->categorycode, |
3655 |
categorycode => $patron->categorycode, |
| 3670 |
branchcode => $branch, |
3656 |
branchcode => $branch, |
| 3671 |
itemtype => $item_type, |
3657 |
itemtype => $item_type, |
| 3672 |
rule_name => 'rentaldiscount' |
3658 |
rule_name => 'rentaldiscount' |
| 3673 |
}); |
3659 |
}); |
| 3674 |
if ($discount) { |
3660 |
if ($discount) { |
| 3675 |
$charge = ( $charge * ( 100 - $discount->rule_value ) ) / 100; |
3661 |
$charge = ( $charge * ( 100 - $discount ) ) / 100; |
| 3676 |
} |
3662 |
} |
| 3677 |
$charge = sprintf '%.2f', $charge; # ensure no fractions of a penny returned |
3663 |
$charge = sprintf '%.2f', $charge; # ensure no fractions of a penny returned |
| 3678 |
} |
3664 |
} |