|
Lines 427-438
sub TooMany {
Link Here
|
| 427 |
); |
427 |
); |
| 428 |
|
428 |
|
| 429 |
|
429 |
|
|
|
430 |
my $patron = Koha::Patrons->find($borrower->{borrowernumber}); |
| 430 |
# if a rule is found and has a loan limit set, count |
431 |
# if a rule is found and has a loan limit set, count |
| 431 |
# how many loans the patron already has that meet that |
432 |
# how many loans the patron already has that meet that |
| 432 |
# rule |
433 |
# rule |
| 433 |
if (defined($maxissueqty_rule) and $maxissueqty_rule->rule_value ne "") { |
434 |
if (defined($maxissueqty_rule) and $maxissueqty_rule->rule_value ne "") { |
| 434 |
|
435 |
|
| 435 |
my $patron = Koha::Patrons->find($borrower->{borrowernumber}); |
|
|
| 436 |
my $checkouts = $patron->checkouts->search( {}, { prefetch => 'item' } ); |
436 |
my $checkouts = $patron->checkouts->search( {}, { prefetch => 'item' } ); |
| 437 |
if ( $maxissueqty_rule->branchcode ) { |
437 |
if ( $maxissueqty_rule->branchcode ) { |
| 438 |
if ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) { |
438 |
if ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) { |
|
Lines 517-554
sub TooMany {
Link Here
|
| 517 |
# Now count total loans against the limit for the branch |
517 |
# Now count total loans against the limit for the branch |
| 518 |
my $branch_borrower_circ_rule = GetBranchBorrowerCircRule($branch, $cat_borrower); |
518 |
my $branch_borrower_circ_rule = GetBranchBorrowerCircRule($branch, $cat_borrower); |
| 519 |
if (defined($branch_borrower_circ_rule->{patron_maxissueqty}) and $branch_borrower_circ_rule->{patron_maxissueqty} ne '') { |
519 |
if (defined($branch_borrower_circ_rule->{patron_maxissueqty}) and $branch_borrower_circ_rule->{patron_maxissueqty} ne '') { |
| 520 |
my @bind_params = (); |
520 |
my $checkouts = $patron->checkouts->search({}, { prefetch => 'item' }); |
| 521 |
my $branch_count_query = q| |
521 |
if ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) { |
| 522 |
SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts |
522 |
$checkouts = $checkouts->search({ 'me.branchcode' => $branch }); |
| 523 |
FROM issues |
|
|
| 524 |
JOIN items USING (itemnumber) |
| 525 |
WHERE borrowernumber = ? |
| 526 |
|; |
| 527 |
push @bind_params, $borrower->{borrowernumber}; |
| 528 |
|
| 529 |
if (C4::Context->preference('CircControl') eq 'PickupLibrary') { |
| 530 |
$branch_count_query .= " AND issues.branchcode = ? "; |
| 531 |
push @bind_params, $branch; |
| 532 |
} elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') { |
523 |
} elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') { |
| 533 |
; # if branch is the patron's home branch, then count all loans by patron |
524 |
; # if branch is the patron's home branch, then count all loans by patron |
| 534 |
} else { |
525 |
} else { |
| 535 |
$branch_count_query .= " AND items.homebranch = ? "; |
526 |
$checkouts = $checkouts->search({ 'item.homebranch' => $branch }); |
| 536 |
push @bind_params, $branch; |
|
|
| 537 |
} |
527 |
} |
| 538 |
my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $branch_count_query, {}, @bind_params ); |
528 |
|
|
|
529 |
my $checkout_count = $checkouts->count; |
| 530 |
my $onsite_checkout_count = $checkouts->search({ onsite_checkout => 1 })->count; |
| 539 |
my $max_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxissueqty}; |
531 |
my $max_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxissueqty}; |
| 540 |
my $max_onsite_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxonsiteissueqty} || undef; |
532 |
my $max_onsite_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxonsiteissueqty} || undef; |
| 541 |
|
533 |
|
| 542 |
my $qty_over = _check_max_qty({ |
534 |
my $qty_over = _check_max_qty( |
| 543 |
checkout_count => $checkout_count, |
535 |
{ |
| 544 |
onsite_checkout_count => $onsite_checkout_count, |
536 |
checkout_count => $checkout_count, |
| 545 |
onsite_checkout => $onsite_checkout, |
537 |
onsite_checkout_count => $onsite_checkout_count, |
| 546 |
max_checkouts_allowed => $max_checkouts_allowed, |
538 |
onsite_checkout => $onsite_checkout, |
| 547 |
max_onsite_checkouts_allowed => $max_onsite_checkouts_allowed, |
539 |
max_checkouts_allowed => $max_checkouts_allowed, |
| 548 |
switch_onsite_checkout => $switch_onsite_checkout |
540 |
max_onsite_checkouts_allowed => $max_onsite_checkouts_allowed, |
| 549 |
}); |
541 |
switch_onsite_checkout => $switch_onsite_checkout |
|
|
542 |
} |
| 543 |
); |
| 550 |
return $qty_over if defined $qty_over; |
544 |
return $qty_over if defined $qty_over; |
| 551 |
|
|
|
| 552 |
} |
545 |
} |
| 553 |
|
546 |
|
| 554 |
if ( not defined( $maxissueqty_rule ) and not defined($branch_borrower_circ_rule->{patron_maxissueqty}) ) { |
547 |
if ( not defined( $maxissueqty_rule ) and not defined($branch_borrower_circ_rule->{patron_maxissueqty}) ) { |
| 555 |
- |
|
|