|
Lines 438-446
sub TooMany {
Link Here
|
| 438 |
my $branch = _GetCircControlBranch( $item, $patron ); |
438 |
my $branch = _GetCircControlBranch( $item, $patron ); |
| 439 |
my $type = $item->effective_itemtype; |
439 |
my $type = $item->effective_itemtype; |
| 440 |
|
440 |
|
| 441 |
my ( $type_object, $parent_type, $parent_maxissueqty_rule ); |
441 |
my $type_object = Koha::ItemTypes->find($type); |
| 442 |
$type_object = Koha::ItemTypes->find($type); |
442 |
my $parent_type = $type_object->parent_type if $type_object; |
| 443 |
$parent_type = $type_object->parent_type if $type_object; |
|
|
| 444 |
my $child_types = Koha::ItemTypes->search( { parent_type => $type } ); |
443 |
my $child_types = Koha::ItemTypes->search( { parent_type => $type } ); |
| 445 |
|
444 |
|
| 446 |
# Find any children if we are a parent_type; |
445 |
# Find any children if we are a parent_type; |
|
Lines 448-453
sub TooMany {
Link Here
|
| 448 |
# given branch, patron category, and item type, determine |
447 |
# given branch, patron category, and item type, determine |
| 449 |
# applicable issuing rule |
448 |
# applicable issuing rule |
| 450 |
|
449 |
|
|
|
450 |
my $parent_maxissueqty_rule; |
| 451 |
$parent_maxissueqty_rule = Koha::CirculationRules->get_effective_rule( |
451 |
$parent_maxissueqty_rule = Koha::CirculationRules->get_effective_rule( |
| 452 |
{ |
452 |
{ |
| 453 |
categorycode => $cat_borrower, |
453 |
categorycode => $cat_borrower, |
|
Lines 499-508
sub TooMany {
Link Here
|
| 499 |
$checkouts = $checkouts->search( undef, { prefetch => 'item' } ); |
499 |
$checkouts = $checkouts->search( undef, { prefetch => 'item' } ); |
| 500 |
|
500 |
|
| 501 |
my $sum_checkouts; |
501 |
my $sum_checkouts; |
| 502 |
my $rule_itemtype = $maxissueqty_rule->itemtype; |
|
|
| 503 |
|
502 |
|
| 504 |
my @types; |
503 |
my @types; |
| 505 |
unless ( $rule_itemtype || $parent_maxissueqty_rule ) { |
504 |
unless ( $maxissueqty_rule->itemtype || $parent_maxissueqty_rule ) { |
| 506 |
|
505 |
|
| 507 |
# matching rule has the default item type, so count only |
506 |
# matching rule has the default item type, so count only |
| 508 |
# those existing loans that don't fall under a more |
507 |
# those existing loans that don't fall under a more |
|
Lines 516-522
sub TooMany {
Link Here
|
| 516 |
} |
515 |
} |
| 517 |
)->get_column('itemtype'); |
516 |
)->get_column('itemtype'); |
| 518 |
} else { |
517 |
} else { |
| 519 |
if ($parent_maxissueqty_rule) { |
518 |
if ( defined $parent_maxissueqty_rule ) { |
| 520 |
|
519 |
|
| 521 |
# if we have a parent item type then we count loans of the |
520 |
# if we have a parent item type then we count loans of the |
| 522 |
# specific item type or its siblings or parent |
521 |
# specific item type or its siblings or parent |
|
Lines 538-544
sub TooMany {
Link Here
|
| 538 |
while ( my $c = $checkouts->next ) { |
537 |
while ( my $c = $checkouts->next ) { |
| 539 |
my $itemtype = $c->item->effective_itemtype; |
538 |
my $itemtype = $c->item->effective_itemtype; |
| 540 |
|
539 |
|
| 541 |
unless ( $rule_itemtype || $parent_maxissueqty_rule ) { |
540 |
unless ( $maxissueqty_rule->itemtype || $parent_maxissueqty_rule ) { |
| 542 |
next if grep { $_ eq $itemtype } @types; |
541 |
next if grep { $_ eq $itemtype } @types; |
| 543 |
} else { |
542 |
} else { |
| 544 |
next unless grep { $_ eq $itemtype } @types; |
543 |
next unless grep { $_ eq $itemtype } @types; |
|
Lines 565-573
sub TooMany {
Link Here
|
| 565 |
}; |
564 |
}; |
| 566 |
|
565 |
|
| 567 |
# If parent rules exists |
566 |
# If parent rules exists |
| 568 |
if ( defined($parent_maxissueqty_rule) and defined( $parent_maxissueqty_rule->rule_value ) ) { |
567 |
if ( defined $parent_maxissueqty_rule ) { |
| 569 |
$checkout_rules->{max_checkouts_allowed} = |
568 |
$checkout_rules->{max_checkouts_allowed} = $parent_maxissueqty_rule->rule_value; |
| 570 |
$parent_maxissueqty_rule ? $parent_maxissueqty_rule->rule_value : undef; |
|
|
| 571 |
my $qty_over = _check_max_qty($checkout_rules); |
569 |
my $qty_over = _check_max_qty($checkout_rules); |
| 572 |
return $qty_over if defined $qty_over; |
570 |
return $qty_over if defined $qty_over; |
| 573 |
|
571 |
|
|
Lines 576-582
sub TooMany {
Link Here
|
| 576 |
&& defined( $maxissueqty_rule->itemtype ) ) |
574 |
&& defined( $maxissueqty_rule->itemtype ) ) |
| 577 |
{ |
575 |
{ |
| 578 |
$checkout_rules->{checkout_count} = $checkout_count_type; |
576 |
$checkout_rules->{checkout_count} = $checkout_count_type; |
| 579 |
$checkout_rules->{max_checkouts_allowed} = $maxissueqty_rule ? $maxissueqty_rule->rule_value : undef; |
577 |
$checkout_rules->{max_checkouts_allowed} = $maxissueqty_rule->rule_value; |
| 580 |
my $qty_over = _check_max_qty($checkout_rules); |
578 |
my $qty_over = _check_max_qty($checkout_rules); |
| 581 |
return $qty_over if defined $qty_over; |
579 |
return $qty_over if defined $qty_over; |
| 582 |
} |
580 |
} |
|
Lines 623-629
sub TooMany {
Link Here
|
| 623 |
return $qty_over if defined $qty_over; |
621 |
return $qty_over if defined $qty_over; |
| 624 |
} |
622 |
} |
| 625 |
|
623 |
|
| 626 |
if ( not defined($maxissueqty_rule) and not defined( $branch_borrower_circ_rule->{patron_maxissueqty} ) ) { |
624 |
unless ( defined $maxissueqty_rule || defined $branch_borrower_circ_rule->{patron_maxissueqty} ) { |
| 627 |
return { reason => 'NO_RULE_DEFINED', max_allowed => 0 }; |
625 |
return { reason => 'NO_RULE_DEFINED', max_allowed => 0 }; |
| 628 |
} |
626 |
} |
| 629 |
|
627 |
|
|
Lines 643-649
sub _check_max_qty {
Link Here
|
| 643 |
my $onsite_circulation_rule = $params->{onsite_circulation_rule}; |
641 |
my $onsite_circulation_rule = $params->{onsite_circulation_rule}; |
| 644 |
|
642 |
|
| 645 |
if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) { |
643 |
if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) { |
| 646 |
if ( $max_onsite_checkouts_allowed eq '' ) { return; } |
644 |
return if $max_onsite_checkouts_allowed eq ''; |
| 647 |
if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed ) { |
645 |
if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed ) { |
| 648 |
return { |
646 |
return { |
| 649 |
reason => 'TOO_MANY_ONSITE_CHECKOUTS', |
647 |
reason => 'TOO_MANY_ONSITE_CHECKOUTS', |
|
Lines 654-660
sub _check_max_qty {
Link Here
|
| 654 |
} |
652 |
} |
| 655 |
} |
653 |
} |
| 656 |
if ( C4::Context->preference('ConsiderOnSiteCheckoutsAsNormalCheckouts') ) { |
654 |
if ( C4::Context->preference('ConsiderOnSiteCheckoutsAsNormalCheckouts') ) { |
| 657 |
if ( $max_checkouts_allowed eq '' ) { return; } |
655 |
return if $max_checkouts_allowed eq ''; |
| 658 |
my $delta = $switch_onsite_checkout ? 1 : 0; |
656 |
my $delta = $switch_onsite_checkout ? 1 : 0; |
| 659 |
if ( $checkout_count >= $max_checkouts_allowed + $delta ) { |
657 |
if ( $checkout_count >= $max_checkouts_allowed + $delta ) { |
| 660 |
return { |
658 |
return { |
|
Lines 665-671
sub _check_max_qty {
Link Here
|
| 665 |
}; |
663 |
}; |
| 666 |
} |
664 |
} |
| 667 |
} elsif ( not $onsite_checkout ) { |
665 |
} elsif ( not $onsite_checkout ) { |
| 668 |
if ( $max_checkouts_allowed eq '' ) { return; } |
666 |
return if $max_checkouts_allowed eq ''; |
| 669 |
if ( $checkout_count - $onsite_checkout_count >= $max_checkouts_allowed ) { |
667 |
if ( $checkout_count - $onsite_checkout_count >= $max_checkouts_allowed ) { |
| 670 |
return { |
668 |
return { |
| 671 |
reason => 'TOO_MANY_CHECKOUTS', |
669 |
reason => 'TOO_MANY_CHECKOUTS', |
|
Lines 1520-1542
sub checkHighHolds {
Link Here
|
| 1520 |
|
1518 |
|
| 1521 |
my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $patron ); |
1519 |
my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $patron ); |
| 1522 |
|
1520 |
|
| 1523 |
my $rule = Koha::CirculationRules->get_effective_rule_value( |
1521 |
# overrides decreaseLoanHighHoldsDuration syspref |
|
|
1522 |
my $duration = Koha::CirculationRules->get_effective_rule_value( |
| 1524 |
{ |
1523 |
{ |
| 1525 |
categorycode => $patron->categorycode, |
1524 |
categorycode => $patron->categorycode, |
| 1526 |
itemtype => $item->effective_itemtype, |
1525 |
itemtype => $item->effective_itemtype, |
| 1527 |
branchcode => $branchcode, |
1526 |
branchcode => $branchcode, |
| 1528 |
rule_name => 'decreaseloanholds', |
1527 |
rule_name => 'decreaseloanholds', |
| 1529 |
} |
1528 |
} |
| 1530 |
); |
1529 |
) || C4::Context->preference('decreaseLoanHighHoldsDuration'); |
| 1531 |
|
|
|
| 1532 |
my $duration; |
| 1533 |
if ( defined($rule) && $rule ne '' ) { |
| 1534 |
|
1530 |
|
| 1535 |
# overrides decreaseLoanHighHoldsDuration syspref |
|
|
| 1536 |
$duration = $rule; |
| 1537 |
} else { |
| 1538 |
$duration = C4::Context->preference('decreaseLoanHighHoldsDuration') || 0; |
| 1539 |
} |
| 1540 |
my $reduced_datedue = $calendar->addDuration( $issuedate, $duration ); |
1531 |
my $reduced_datedue = $calendar->addDuration( $issuedate, $duration ); |
| 1541 |
$reduced_datedue->set_hour( $orig_due->hour ); |
1532 |
$reduced_datedue->set_hour( $orig_due->hour ); |
| 1542 |
$reduced_datedue->set_minute( $orig_due->minute ); |
1533 |
$reduced_datedue->set_minute( $orig_due->minute ); |
|
Lines 2097-2123
wildcards.
Link Here
|
| 2097 |
sub GetBranchBorrowerCircRule { |
2088 |
sub GetBranchBorrowerCircRule { |
| 2098 |
my ( $branchcode, $categorycode ) = @_; |
2089 |
my ( $branchcode, $categorycode ) = @_; |
| 2099 |
|
2090 |
|
| 2100 |
# Initialize default values |
2091 |
my $rules = Koha::CirculationRules->get_effective_rules( |
| 2101 |
my $rules = { |
2092 |
{ |
|
|
2093 |
categorycode => $categorycode, |
| 2094 |
itemtype => undef, |
| 2095 |
branchcode => $branchcode, |
| 2096 |
rules => [ 'patron_maxissueqty', 'patron_maxonsiteissueqty' ] |
| 2097 |
} |
| 2098 |
) // {}; |
| 2099 |
|
| 2100 |
# Initialize default values and return |
| 2101 |
return { |
| 2102 |
patron_maxissueqty => undef, |
2102 |
patron_maxissueqty => undef, |
| 2103 |
patron_maxonsiteissueqty => undef, |
2103 |
patron_maxonsiteissueqty => undef, |
|
|
2104 |
%{$rules} |
| 2104 |
}; |
2105 |
}; |
| 2105 |
|
|
|
| 2106 |
# Search for rules! |
| 2107 |
foreach my $rule_name (qw( patron_maxissueqty patron_maxonsiteissueqty )) { |
| 2108 |
my $rule = Koha::CirculationRules->get_effective_rule( |
| 2109 |
{ |
| 2110 |
categorycode => $categorycode, |
| 2111 |
itemtype => undef, |
| 2112 |
branchcode => $branchcode, |
| 2113 |
rule_name => $rule_name, |
| 2114 |
} |
| 2115 |
); |
| 2116 |
|
| 2117 |
$rules->{$rule_name} = $rule->rule_value if defined $rule; |
| 2118 |
} |
| 2119 |
|
| 2120 |
return $rules; |
| 2121 |
} |
2106 |
} |
| 2122 |
|
2107 |
|
| 2123 |
=head2 GetBranchItemRule |
2108 |
=head2 GetBranchItemRule |
|
Lines 2909-2920
sub _calculate_new_debar_dt {
Link Here
|
| 2909 |
] |
2894 |
] |
| 2910 |
} |
2895 |
} |
| 2911 |
); |
2896 |
); |
| 2912 |
my $finedays = $issuing_rule ? $issuing_rule->{finedays} : undef; |
2897 |
return unless $issuing_rule->{finedays}; |
| 2913 |
my $unit = $issuing_rule ? $issuing_rule->{lengthunit} : undef; |
2898 |
my $finedays = $issuing_rule->{finedays}; |
|
|
2899 |
my $unit = $issuing_rule->{lengthunit}; |
| 2914 |
my $chargeable_units = C4::Overdues::get_chargeable_units( $unit, $dt_due, $return_date, $branchcode ); |
2900 |
my $chargeable_units = C4::Overdues::get_chargeable_units( $unit, $dt_due, $return_date, $branchcode ); |
| 2915 |
|
2901 |
|
| 2916 |
return unless $finedays; |
|
|
| 2917 |
|
| 2918 |
# finedays is in days, so hourly loans must multiply by 24 |
2902 |
# finedays is in days, so hourly loans must multiply by 24 |
| 2919 |
# thus 1 hour late equals 1 day suspension * finedays rate |
2903 |
# thus 1 hour late equals 1 day suspension * finedays rate |
| 2920 |
$finedays = $finedays * 24 if ( $unit eq 'hours' ); |
2904 |
$finedays = $finedays * 24 if ( $unit eq 'hours' ); |
|
Lines 3493-3499
sub AddRenewal {
Link Here
|
| 3493 |
# a maximum value has been set in the circ rules |
3477 |
# a maximum value has been set in the circ rules |
| 3494 |
my $unseen_renewals = $issue->unseen_renewals; |
3478 |
my $unseen_renewals = $issue->unseen_renewals; |
| 3495 |
if ( C4::Context->preference('UnseenRenewals') ) { |
3479 |
if ( C4::Context->preference('UnseenRenewals') ) { |
| 3496 |
my $rule = Koha::CirculationRules->get_effective_rule( |
3480 |
my $unseen_renewals_allowed = Koha::CirculationRules->get_effective_rule_value( |
| 3497 |
{ |
3481 |
{ |
| 3498 |
categorycode => $patron->categorycode, |
3482 |
categorycode => $patron->categorycode, |
| 3499 |
itemtype => $item_object->effective_itemtype, |
3483 |
itemtype => $item_object->effective_itemtype, |
|
Lines 3501-3507
sub AddRenewal {
Link Here
|
| 3501 |
rule_name => 'unseen_renewals_allowed' |
3485 |
rule_name => 'unseen_renewals_allowed' |
| 3502 |
} |
3486 |
} |
| 3503 |
); |
3487 |
); |
| 3504 |
if ( !$seen && $rule && looks_like_number( $rule->rule_value ) ) { |
3488 |
if ( !$seen && $unseen_renewals_allowed && looks_like_number($unseen_renewals_allowed) ) { |
| 3505 |
$unseen_renewals++; |
3489 |
$unseen_renewals++; |
| 3506 |
push @{$confirmations}, 'UNSEEN'; |
3490 |
push @{$confirmations}, 'UNSEEN'; |
| 3507 |
} else { |
3491 |
} else { |
|
Lines 3907-3913
sub GetIssuingCharges {
Link Here
|
| 3907 |
# FIXME This should follow CircControl |
3891 |
# FIXME This should follow CircControl |
| 3908 |
my $branch = C4::Context::mybranch(); |
3892 |
my $branch = C4::Context::mybranch(); |
| 3909 |
$patron //= Koha::Patrons->find($borrowernumber); |
3893 |
$patron //= Koha::Patrons->find($borrowernumber); |
| 3910 |
my $discount = Koha::CirculationRules->get_effective_rule( |
3894 |
my $discount = Koha::CirculationRules->get_effective_rule_value( |
| 3911 |
{ |
3895 |
{ |
| 3912 |
categorycode => $patron->categorycode, |
3896 |
categorycode => $patron->categorycode, |
| 3913 |
branchcode => $branch, |
3897 |
branchcode => $branch, |
|
Lines 3916-3922
sub GetIssuingCharges {
Link Here
|
| 3916 |
} |
3900 |
} |
| 3917 |
); |
3901 |
); |
| 3918 |
if ($discount) { |
3902 |
if ($discount) { |
| 3919 |
$charge = ( $charge * ( 100 - $discount->rule_value ) ) / 100; |
3903 |
$charge = ( $charge * ( 100 - $discount ) ) / 100; |
| 3920 |
} |
3904 |
} |
| 3921 |
$charge = sprintf '%.2f', $charge; # ensure no fractions of a penny returned |
3905 |
$charge = sprintf '%.2f', $charge; # ensure no fractions of a penny returned |
| 3922 |
} |
3906 |
} |