|
Lines 432-439
sub TooMany {
Link Here
|
| 432 |
# applicable issuing rule |
432 |
# applicable issuing rule |
| 433 |
|
433 |
|
| 434 |
# If the parent rule is for default type we discount it |
434 |
# If the parent rule is for default type we discount it |
| 435 |
my $parent_maxissueqty; |
435 |
my $parent_maxissueqty_rule; |
| 436 |
$parent_maxissueqty = Koha::CirculationRules->get_effective_rule_value( |
436 |
$parent_maxissueqty_rule = Koha::CirculationRules->get_effective_rule( |
| 437 |
{ |
437 |
{ |
| 438 |
categorycode => $cat_borrower, |
438 |
categorycode => $cat_borrower, |
| 439 |
itemtype => $parent_type, |
439 |
itemtype => $parent_type, |
|
Lines 441-448
sub TooMany {
Link Here
|
| 441 |
rule_name => 'maxissueqty', |
441 |
rule_name => 'maxissueqty', |
| 442 |
} |
442 |
} |
| 443 |
) if $parent_type; |
443 |
) if $parent_type; |
|
|
444 |
# If the parent rule is for default type we discount it |
| 445 |
$parent_maxissueqty_rule = undef if $parent_maxissueqty_rule && !defined $parent_maxissueqty_rule->itemtype; |
| 444 |
|
446 |
|
| 445 |
my $maxissueqty = Koha::CirculationRules->get_effective_rule_value( |
447 |
my $maxissueqty_rule = Koha::CirculationRules->get_effective_rule( |
| 446 |
{ |
448 |
{ |
| 447 |
categorycode => $cat_borrower, |
449 |
categorycode => $cat_borrower, |
| 448 |
itemtype => $type, |
450 |
itemtype => $type, |
|
Lines 451-457
sub TooMany {
Link Here
|
| 451 |
} |
453 |
} |
| 452 |
); |
454 |
); |
| 453 |
|
455 |
|
| 454 |
my $maxonsiteissueqty = Koha::CirculationRules->get_effective_rule_value( |
456 |
my $maxonsiteissueqty_rule = Koha::CirculationRules->get_effective_rule( |
| 455 |
{ |
457 |
{ |
| 456 |
categorycode => $cat_borrower, |
458 |
categorycode => $cat_borrower, |
| 457 |
itemtype => $type, |
459 |
itemtype => $type, |
|
Lines 463-480
sub TooMany {
Link Here
|
| 463 |
# if a rule is found and has a loan limit set, count |
465 |
# if a rule is found and has a loan limit set, count |
| 464 |
# how many loans the patron already has that meet that |
466 |
# how many loans the patron already has that meet that |
| 465 |
# rule |
467 |
# rule |
| 466 |
if (defined $maxissueqty and $maxissueqty ne "") { |
468 |
if (defined $maxissueqty_rule and $maxissueqty_rule->rule_value ne "") { |
| 467 |
|
469 |
|
| 468 |
my $checkouts; |
470 |
my $checkouts; |
| 469 |
if ( $branch ) { |
471 |
if ( $maxissueqty_rule->branchcode ) { |
| 470 |
if ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) { |
472 |
if ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) { |
| 471 |
$checkouts = $patron->checkouts->search( |
473 |
$checkouts = $patron->checkouts->search( |
| 472 |
{ 'me.branchcode' => $branch } ); |
474 |
{ 'me.branchcode' => $maxissueqty_rule->branchcode } ); |
| 473 |
} elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') { |
475 |
} elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') { |
| 474 |
$checkouts = $patron->checkouts; # if branch is the patron's home branch, then count all loans by patron |
476 |
$checkouts = $patron->checkouts; # if branch is the patron's home branch, then count all loans by patron |
| 475 |
} else { |
477 |
} else { |
| 476 |
my $branch_type = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch'; |
478 |
my $branch_type = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch'; |
| 477 |
$checkouts = $patron->checkouts->search( { "item.$branch_type" => $branch } ); |
479 |
$checkouts = $patron->checkouts->search( { "item.$branch_type" => $maxissueqty_rule->branchcode } ); |
| 478 |
} |
480 |
} |
| 479 |
} else { |
481 |
} else { |
| 480 |
$checkouts = $patron->checkouts; # if rule is not branch specific then count all loans by patron |
482 |
$checkouts = $patron->checkouts; # if rule is not branch specific then count all loans by patron |
|
Lines 484-503
sub TooMany {
Link Here
|
| 484 |
my $sum_checkouts; |
486 |
my $sum_checkouts; |
| 485 |
|
487 |
|
| 486 |
my @types; |
488 |
my @types; |
| 487 |
unless ( $type ) { |
489 |
unless ( $maxissueqty_rule->itemtype ) { |
| 488 |
# matching rule has the default item type, so count only |
490 |
# matching rule has the default item type, so count only |
| 489 |
# those existing loans that don't fall under a more |
491 |
# those existing loans that don't fall under a more |
| 490 |
# specific rule |
492 |
# specific rule |
| 491 |
@types = Koha::CirculationRules->search( |
493 |
@types = Koha::CirculationRules->search( |
| 492 |
{ |
494 |
{ |
| 493 |
branchcode => $branch, |
495 |
branchcode => $maxissueqty_rule->branchcode, |
| 494 |
categorycode => $cat_borrower, |
496 |
categorycode => [ $maxissueqty_rule->categorycode, $cat_borrower ], |
| 495 |
itemtype => { '!=' => undef }, |
497 |
itemtype => { '!=' => undef }, |
| 496 |
rule_name => 'maxissueqty' |
498 |
rule_name => 'maxissueqty' |
| 497 |
} |
499 |
} |
| 498 |
)->get_column('itemtype'); |
500 |
)->get_column('itemtype'); |
| 499 |
} else { |
501 |
} else { |
| 500 |
if ( $parent_maxissueqty ) { |
502 |
if ( defined $parent_maxissueqty_rule ) { |
| 501 |
# if we have a parent item type then we count loans of the |
503 |
# if we have a parent item type then we count loans of the |
| 502 |
# specific item type or its siblings or parent |
504 |
# specific item type or its siblings or parent |
| 503 |
my $children = Koha::ItemTypes->search({ parent_type => $parent_type }); |
505 |
my $children = Koha::ItemTypes->search({ parent_type => $parent_type }); |
|
Lines 516-522
sub TooMany {
Link Here
|
| 516 |
while ( my $c = $checkouts->next ) { |
518 |
while ( my $c = $checkouts->next ) { |
| 517 |
my $itemtype = $c->item->effective_itemtype; |
519 |
my $itemtype = $c->item->effective_itemtype; |
| 518 |
|
520 |
|
| 519 |
unless ( $type ) { |
521 |
unless ( $maxissueqty_rule->itemtype ) { |
| 520 |
next if grep {$_ eq $itemtype} @types; |
522 |
next if grep {$_ eq $itemtype} @types; |
| 521 |
} else { |
523 |
} else { |
| 522 |
next unless grep {$_ eq $itemtype} @types; |
524 |
next unless grep {$_ eq $itemtype} @types; |
|
Lines 535-554
sub TooMany {
Link Here
|
| 535 |
checkout_count => $checkout_count, |
537 |
checkout_count => $checkout_count, |
| 536 |
onsite_checkout_count => $onsite_checkout_count, |
538 |
onsite_checkout_count => $onsite_checkout_count, |
| 537 |
onsite_checkout => $onsite_checkout, |
539 |
onsite_checkout => $onsite_checkout, |
| 538 |
max_checkouts_allowed => $maxissueqty,, |
540 |
max_checkouts_allowed => $maxissueqty_rule ? $maxissueqty_rule->rule_value : undef, |
| 539 |
max_onsite_checkouts_allowed => $maxonsiteissueqty, |
541 |
max_onsite_checkouts_allowed => $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : undef, |
| 540 |
switch_onsite_checkout => $switch_onsite_checkout, |
542 |
switch_onsite_checkout => $switch_onsite_checkout, |
| 541 |
}; |
543 |
}; |
| 542 |
# If parent rules exists |
544 |
# If parent rules exists |
| 543 |
if ( defined $parent_maxissueqty ){ |
545 |
if ( defined $parent_maxissueqty_rule ) { |
| 544 |
$checkout_rules->{max_checkouts_allowed} = $parent_maxissueqty; |
546 |
$checkout_rules->{max_checkouts_allowed} = $parent_maxissueqty_rule->rule_value; |
| 545 |
my $qty_over = _check_max_qty($checkout_rules); |
547 |
my $qty_over = _check_max_qty($checkout_rules); |
| 546 |
return $qty_over if defined $qty_over; |
548 |
return $qty_over if defined $qty_over; |
| 547 |
|
549 |
|
| 548 |
# If the parent rule is less than or equal to the child, we only need check the parent |
550 |
# If the parent rule is less than or equal to the child, we only need check the parent |
| 549 |
if( $maxissueqty < $parent_maxissueqty && defined($type) ) { |
551 |
if( |
|
|
552 |
$maxissueqty_rule->rule_value < $parent_maxissueqty_rule->rule_value |
| 553 |
&& defined($maxissueqty_rule->itemtype) |
| 554 |
) { |
| 550 |
$checkout_rules->{checkout_count} = $checkout_count_type; |
555 |
$checkout_rules->{checkout_count} = $checkout_count_type; |
| 551 |
$checkout_rules->{max_checkouts_allowed} = $maxissueqty; |
556 |
$checkout_rules->{max_checkouts_allowed} = $maxissueqty_rule->rule_value; |
| 552 |
my $qty_over = _check_max_qty($checkout_rules); |
557 |
my $qty_over = _check_max_qty($checkout_rules); |
| 553 |
return $qty_over if defined $qty_over; |
558 |
return $qty_over if defined $qty_over; |
| 554 |
} |
559 |
} |
|
Lines 560-566
sub TooMany {
Link Here
|
| 560 |
|
565 |
|
| 561 |
# Now count total loans against the limit for the branch |
566 |
# Now count total loans against the limit for the branch |
| 562 |
my $branch_borrower_circ_rule = GetBranchBorrowerCircRule($branch, $cat_borrower); |
567 |
my $branch_borrower_circ_rule = GetBranchBorrowerCircRule($branch, $cat_borrower); |
| 563 |
if (defined($branch_borrower_circ_rule->{patron_maxissueqty}) and $branch_borrower_circ_rule->{patron_maxissueqty} ne '') { |
568 |
if ( |
|
|
569 |
defined($branch_borrower_circ_rule->{patron_maxissueqty}) |
| 570 |
and $branch_borrower_circ_rule->{patron_maxissueqty} ne '' |
| 571 |
) { |
| 564 |
my $checkouts; |
572 |
my $checkouts; |
| 565 |
if ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) { |
573 |
if ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) { |
| 566 |
$checkouts = $patron->checkouts->search( |
574 |
$checkouts = $patron->checkouts->search( |
|
Lines 592-598
sub TooMany {
Link Here
|
| 592 |
return $qty_over if defined $qty_over; |
600 |
return $qty_over if defined $qty_over; |
| 593 |
} |
601 |
} |
| 594 |
|
602 |
|
| 595 |
unless ( defined $maxissueqty || defined $branch_borrower_circ_rule->{patron_maxissueqty} ) { |
603 |
unless ( defined $maxissueqty_rule || defined $branch_borrower_circ_rule->{patron_maxissueqty} ) { |
| 596 |
return { reason => 'NO_RULE_DEFINED', max_allowed => 0 }; |
604 |
return { reason => 'NO_RULE_DEFINED', max_allowed => 0 }; |
| 597 |
} |
605 |
} |
| 598 |
|
606 |
|
|
Lines 610-616
sub _check_max_qty {
Link Here
|
| 610 |
my $switch_onsite_checkout = $params->{switch_onsite_checkout}; |
618 |
my $switch_onsite_checkout = $params->{switch_onsite_checkout}; |
| 611 |
|
619 |
|
| 612 |
if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) { |
620 |
if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) { |
| 613 |
if ( $max_onsite_checkouts_allowed eq '' ) { return; } |
621 |
return if $max_onsite_checkouts_allowed eq ''; |
| 614 |
if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed ) { |
622 |
if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed ) { |
| 615 |
return { |
623 |
return { |
| 616 |
reason => 'TOO_MANY_ONSITE_CHECKOUTS', |
624 |
reason => 'TOO_MANY_ONSITE_CHECKOUTS', |
|
Lines 620-626
sub _check_max_qty {
Link Here
|
| 620 |
} |
628 |
} |
| 621 |
} |
629 |
} |
| 622 |
if ( C4::Context->preference('ConsiderOnSiteCheckoutsAsNormalCheckouts') ) { |
630 |
if ( C4::Context->preference('ConsiderOnSiteCheckoutsAsNormalCheckouts') ) { |
| 623 |
if ( $max_checkouts_allowed eq '' ) { return; } |
631 |
return if $max_checkouts_allowed eq ''; |
| 624 |
my $delta = $switch_onsite_checkout ? 1 : 0; |
632 |
my $delta = $switch_onsite_checkout ? 1 : 0; |
| 625 |
if ( $checkout_count >= $max_checkouts_allowed + $delta ) { |
633 |
if ( $checkout_count >= $max_checkouts_allowed + $delta ) { |
| 626 |
return { |
634 |
return { |
|
Lines 631-640
sub _check_max_qty {
Link Here
|
| 631 |
} |
639 |
} |
| 632 |
} |
640 |
} |
| 633 |
elsif ( not $onsite_checkout ) { |
641 |
elsif ( not $onsite_checkout ) { |
| 634 |
if ( $max_checkouts_allowed eq '' ) { return; } |
642 |
return if $max_checkouts_allowed eq ''; |
| 635 |
if ( |
643 |
if ( |
| 636 |
$checkout_count - $onsite_checkout_count >= $max_checkouts_allowed ) |
644 |
$checkout_count - $onsite_checkout_count >= $max_checkouts_allowed |
| 637 |
{ |
645 |
) { |
| 638 |
return { |
646 |
return { |
| 639 |
reason => 'TOO_MANY_CHECKOUTS', |
647 |
reason => 'TOO_MANY_CHECKOUTS', |
| 640 |
count => $checkout_count - $onsite_checkout_count, |
648 |
count => $checkout_count - $onsite_checkout_count, |
|
Lines 1416-1437
sub checkHighHolds {
Link Here
|
| 1416 |
|
1424 |
|
| 1417 |
my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $patron ); |
1425 |
my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $patron ); |
| 1418 |
|
1426 |
|
| 1419 |
my $rule = Koha::CirculationRules->get_effective_rule_value( |
1427 |
# overrides decreaseLoanHighHoldsDuration syspref |
|
|
1428 |
my $duration = Koha::CirculationRules->get_effective_rule_value( |
| 1420 |
{ |
1429 |
{ |
| 1421 |
categorycode => $patron->categorycode, |
1430 |
categorycode => $patron->categorycode, |
| 1422 |
itemtype => $item->effective_itemtype, |
1431 |
itemtype => $item->effective_itemtype, |
| 1423 |
branchcode => $branchcode, |
1432 |
branchcode => $branchcode, |
| 1424 |
rule_name => 'decreaseloanholds', |
1433 |
rule_name => 'decreaseloanholds', |
| 1425 |
} |
1434 |
} |
| 1426 |
); |
1435 |
) || C4::Context->preference('decreaseLoanHighHoldsDuration'); |
| 1427 |
|
1436 |
|
| 1428 |
my $duration; |
|
|
| 1429 |
if ( defined($rule) && $rule ne '' ){ |
| 1430 |
# overrides decreaseLoanHighHoldsDuration syspref |
| 1431 |
$duration = $rule; |
| 1432 |
} else { |
| 1433 |
$duration = C4::Context->preference('decreaseLoanHighHoldsDuration'); |
| 1434 |
} |
| 1435 |
my $reduced_datedue = $calendar->addDuration( $issuedate, $duration ); |
1437 |
my $reduced_datedue = $calendar->addDuration( $issuedate, $duration ); |
| 1436 |
$reduced_datedue->set_hour($orig_due->hour); |
1438 |
$reduced_datedue->set_hour($orig_due->hour); |
| 1437 |
$reduced_datedue->set_minute($orig_due->minute); |
1439 |
$reduced_datedue->set_minute($orig_due->minute); |
|
Lines 1919-1924
wildcards.
Link Here
|
| 1919 |
|
1921 |
|
| 1920 |
sub GetBranchBorrowerCircRule { |
1922 |
sub GetBranchBorrowerCircRule { |
| 1921 |
my ( $branchcode, $categorycode ) = @_; |
1923 |
my ( $branchcode, $categorycode ) = @_; |
|
|
1924 |
|
| 1922 |
return Koha::CirculationRules->get_effective_rules( |
1925 |
return Koha::CirculationRules->get_effective_rules( |
| 1923 |
{ |
1926 |
{ |
| 1924 |
categorycode => $categorycode, |
1927 |
categorycode => $categorycode, |
|
Lines 2690-2700
sub _calculate_new_debar_dt {
Link Here
|
| 2690 |
] |
2693 |
] |
| 2691 |
} |
2694 |
} |
| 2692 |
); |
2695 |
); |
| 2693 |
my $finedays = $issuing_rule ? $issuing_rule->{finedays} : undef; |
2696 |
return unless $issuing_rule->{finedays}; |
| 2694 |
my $unit = $issuing_rule ? $issuing_rule->{lengthunit} : undef; |
2697 |
my $finedays = $issuing_rule->{finedays}; |
|
|
2698 |
my $unit = $issuing_rule->{lengthunit}; |
| 2695 |
my $chargeable_units = C4::Overdues::get_chargeable_units($unit, $dt_due, $return_date, $branchcode); |
2699 |
my $chargeable_units = C4::Overdues::get_chargeable_units($unit, $dt_due, $return_date, $branchcode); |
| 2696 |
|
2700 |
|
| 2697 |
return unless $finedays; |
|
|
| 2698 |
|
2701 |
|
| 2699 |
# finedays is in days, so hourly loans must multiply by 24 |
2702 |
# finedays is in days, so hourly loans must multiply by 24 |
| 2700 |
# thus 1 hour late equals 1 day suspension * finedays rate |
2703 |
# thus 1 hour late equals 1 day suspension * finedays rate |
|
Lines 3217-3230
sub AddRenewal {
Link Here
|
| 3217 |
# a maximum value has been set in the circ rules |
3220 |
# a maximum value has been set in the circ rules |
| 3218 |
my $unseen_renewals = $issue->unseen_renewals; |
3221 |
my $unseen_renewals = $issue->unseen_renewals; |
| 3219 |
if (C4::Context->preference('UnseenRenewals')) { |
3222 |
if (C4::Context->preference('UnseenRenewals')) { |
| 3220 |
my $rule = Koha::CirculationRules->get_effective_rule( |
3223 |
my $unseen_renewals_allowed = Koha::CirculationRules->get_effective_rule_value( |
| 3221 |
{ categorycode => $patron->categorycode, |
3224 |
{ categorycode => $patron->categorycode, |
| 3222 |
itemtype => $item_object->effective_itemtype, |
3225 |
itemtype => $item_object->effective_itemtype, |
| 3223 |
branchcode => $circ_library->branchcode, |
3226 |
branchcode => $circ_library->branchcode, |
| 3224 |
rule_name => 'unseen_renewals_allowed' |
3227 |
rule_name => 'unseen_renewals_allowed' |
| 3225 |
} |
3228 |
} |
| 3226 |
); |
3229 |
); |
| 3227 |
if (!$seen && $rule && looks_like_number($rule->rule_value)) { |
3230 |
if (!$seen && $unseen_renewals_allowed && looks_like_number($unseen_renewals_allowed)) { |
| 3228 |
$unseen_renewals++; |
3231 |
$unseen_renewals++; |
| 3229 |
} else { |
3232 |
} else { |
| 3230 |
# If the renewal is seen, unseen should revert to 0 |
3233 |
# If the renewal is seen, unseen should revert to 0 |
|
Lines 3583-3596
sub GetIssuingCharges {
Link Here
|
| 3583 |
# FIXME This should follow CircControl |
3586 |
# FIXME This should follow CircControl |
| 3584 |
my $branch = C4::Context::mybranch(); |
3587 |
my $branch = C4::Context::mybranch(); |
| 3585 |
$patron //= Koha::Patrons->find( $borrowernumber ); |
3588 |
$patron //= Koha::Patrons->find( $borrowernumber ); |
| 3586 |
my $discount = Koha::CirculationRules->get_effective_rule({ |
3589 |
my $discount = Koha::CirculationRules->get_effective_rule_value({ |
| 3587 |
categorycode => $patron->categorycode, |
3590 |
categorycode => $patron->categorycode, |
| 3588 |
branchcode => $branch, |
3591 |
branchcode => $branch, |
| 3589 |
itemtype => $item_type, |
3592 |
itemtype => $item_type, |
| 3590 |
rule_name => 'rentaldiscount' |
3593 |
rule_name => 'rentaldiscount' |
| 3591 |
}); |
3594 |
}); |
| 3592 |
if ($discount) { |
3595 |
if ($discount) { |
| 3593 |
$charge = ( $charge * ( 100 - $discount->rule_value ) ) / 100; |
3596 |
$charge = ( $charge * ( 100 - $discount ) ) / 100; |
| 3594 |
} |
3597 |
} |
| 3595 |
$charge = sprintf '%.2f', $charge; # ensure no fractions of a penny returned |
3598 |
$charge = sprintf '%.2f', $charge; # ensure no fractions of a penny returned |
| 3596 |
} |
3599 |
} |