Lines 373-381
sub transferbook {
Link Here
|
373 |
|
373 |
|
374 |
|
374 |
|
375 |
sub TooMany { |
375 |
sub TooMany { |
376 |
my $borrower = shift; |
376 |
my $borrower = shift; |
377 |
my $biblionumber = shift; |
377 |
my $biblionumber = shift; |
378 |
my $item = shift; |
378 |
my $item = shift; |
379 |
my $params = shift; |
379 |
my $params = shift; |
380 |
my $onsite_checkout = $params->{onsite_checkout} || 0; |
380 |
my $onsite_checkout = $params->{onsite_checkout} || 0; |
381 |
my $switch_onsite_checkout = $params->{switch_onsite_checkout} || 0; |
381 |
my $switch_onsite_checkout = $params->{switch_onsite_checkout} || 0; |
Lines 388-395
sub TooMany {
Link Here
|
388 |
? $item->{'itype'} # item-level |
388 |
? $item->{'itype'} # item-level |
389 |
: $item->{'itemtype'}; # biblio-level |
389 |
: $item->{'itemtype'}; # biblio-level |
390 |
|
390 |
|
|
|
391 |
my ($type_object, $parent_type, $parent_maxissueqty_rule); |
392 |
$type_object = Koha::ItemTypes->find( $type ); |
393 |
$parent_type = $type_object->parent_type if $type_object; |
394 |
my $child_types = Koha::ItemTypes->search( parent_type => $type ); |
395 |
# Find any children if we are a parent_type; |
396 |
|
391 |
# given branch, patron category, and item type, determine |
397 |
# given branch, patron category, and item type, determine |
392 |
# applicable issuing rule |
398 |
# applicable issuing rule |
|
|
399 |
|
400 |
$parent_maxissueqty_rule = Koha::CirculationRules->get_effective_rule( |
401 |
{ |
402 |
categorycode => $cat_borrower, |
403 |
itemtype => $parent_type, |
404 |
branchcode => $branch, |
405 |
rule_name => 'maxissueqty', |
406 |
} |
407 |
) if $parent_type; |
408 |
# If the parent rule is for default type we discount it |
409 |
$parent_maxissueqty_rule = undef if $parent_maxissueqty_rule && $parent_maxissueqty_rule->itemtype eq '*'; |
410 |
|
393 |
my $maxissueqty_rule = Koha::CirculationRules->get_effective_rule( |
411 |
my $maxissueqty_rule = Koha::CirculationRules->get_effective_rule( |
394 |
{ |
412 |
{ |
395 |
categorycode => $cat_borrower, |
413 |
categorycode => $cat_borrower, |
Lines 398-403
sub TooMany {
Link Here
|
398 |
rule_name => 'maxissueqty', |
416 |
rule_name => 'maxissueqty', |
399 |
} |
417 |
} |
400 |
); |
418 |
); |
|
|
419 |
|
420 |
|
401 |
my $maxonsiteissueqty_rule = Koha::CirculationRules->get_effective_rule( |
421 |
my $maxonsiteissueqty_rule = Koha::CirculationRules->get_effective_rule( |
402 |
{ |
422 |
{ |
403 |
categorycode => $cat_borrower, |
423 |
categorycode => $cat_borrower, |
Lines 412-420
sub TooMany {
Link Here
|
412 |
# how many loans the patron already has that meet that |
432 |
# how many loans the patron already has that meet that |
413 |
# rule |
433 |
# rule |
414 |
if (defined($maxissueqty_rule) and defined($maxissueqty_rule->rule_value)) { |
434 |
if (defined($maxissueqty_rule) and defined($maxissueqty_rule->rule_value)) { |
|
|
435 |
|
415 |
my @bind_params; |
436 |
my @bind_params; |
416 |
my $count_query = q| |
437 |
my $count_query = ""; |
417 |
SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts |
438 |
|
|
|
439 |
if (C4::Context->preference('item-level_itypes')) { |
440 |
$count_query .= q|SELECT COALESCE( SUM( IF(items.itype = '| .$type . q|',1,0) ), 0) as type_total, COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts|; |
441 |
} else{ |
442 |
$count_query .= q|SELECT COALESCE(SUM( IF(biblioitems.itype = '| .$type . q|',1,0) ), 0) as type_total, COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts|; |
443 |
} |
444 |
|
445 |
$count_query .= q| |
418 |
FROM issues |
446 |
FROM issues |
419 |
JOIN items USING (itemnumber) |
447 |
JOIN items USING (itemnumber) |
420 |
|; |
448 |
|; |
Lines 444-458
sub TooMany {
Link Here
|
444 |
push @bind_params, $maxissueqty_rule->categorycode; |
472 |
push @bind_params, $maxissueqty_rule->categorycode; |
445 |
push @bind_params, $cat_borrower; |
473 |
push @bind_params, $cat_borrower; |
446 |
} else { |
474 |
} else { |
447 |
# rule has specific item type, so count loans of that |
475 |
my @types; |
448 |
# specific item type |
476 |
if ( $parent_maxissueqty_rule ) { |
|
|
477 |
# if we have a parent item type then we count loans of the |
478 |
# specific item type or its siblings or parent |
479 |
push @types, $parent_type; |
480 |
my $children = Koha::ItemTypes->search({ parent_type => $parent_type }); |
481 |
while ( my $child = $children->next ){ |
482 |
push @types, $child->itemtype; |
483 |
} |
484 |
} elsif ( $child_types ) { |
485 |
# If we are a parent type, we need to count all child types and our own type |
486 |
while ( my $child = $child_types->next ){ |
487 |
push @types, $child->itemtype; |
488 |
} |
489 |
push @types, $type; # And don't forget to count our own types |
490 |
} else { push @types, $type; } # Otherwise only count the specific itemtype |
491 |
my $types_param = ( '?,' ) x @types; |
492 |
$types_param =~ s/,$//; |
449 |
if (C4::Context->preference('item-level_itypes')) { |
493 |
if (C4::Context->preference('item-level_itypes')) { |
450 |
$count_query .= " WHERE items.itype = ? "; |
494 |
$count_query .= " WHERE items.itype IN (" . $types_param . ")"; |
451 |
} else { |
495 |
} else { |
452 |
$count_query .= " JOIN biblioitems USING (biblionumber) |
496 |
$count_query .= " JOIN biblioitems USING (biblionumber) |
453 |
WHERE biblioitems.itemtype= ? "; |
497 |
WHERE biblioitems.itemtype IN (" . $types_param . ")"; |
454 |
} |
498 |
} |
455 |
push @bind_params, $type; |
499 |
push @bind_params, @types; |
456 |
} |
500 |
} |
457 |
|
501 |
|
458 |
$count_query .= " AND borrowernumber = ? "; |
502 |
$count_query .= " AND borrowernumber = ? "; |
Lines 470-507
sub TooMany {
Link Here
|
470 |
} |
514 |
} |
471 |
} |
515 |
} |
472 |
|
516 |
|
473 |
my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params ); |
517 |
my ( $checkout_count_type, $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params ); |
474 |
|
518 |
|
475 |
my $max_checkouts_allowed = $maxissueqty_rule ? $maxissueqty_rule->rule_value : undef; |
|
|
476 |
my $max_onsite_checkouts_allowed = $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : undef; |
519 |
my $max_onsite_checkouts_allowed = $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : undef; |
477 |
|
520 |
|
478 |
if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) { |
521 |
# If parent rules exists |
479 |
if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed ) { |
522 |
if ( defined($parent_maxissueqty_rule) and defined($parent_maxissueqty_rule->rule_value) ){ |
480 |
return { |
523 |
my $max_checkouts_allowed = $parent_maxissueqty_rule->rule_value; |
481 |
reason => 'TOO_MANY_ONSITE_CHECKOUTS', |
524 |
|
482 |
count => $onsite_checkout_count, |
525 |
my $qty_over = _check_max_qty({ |
483 |
max_allowed => $max_onsite_checkouts_allowed, |
526 |
checkout_count => $checkout_count, |
484 |
} |
527 |
onsite_checkout_count => $onsite_checkout_count, |
485 |
} |
528 |
onsite_checkout => $onsite_checkout, |
486 |
} |
529 |
max_checkouts_allowed => $max_checkouts_allowed, |
487 |
if ( C4::Context->preference('ConsiderOnSiteCheckoutsAsNormalCheckouts') ) { |
530 |
max_onsite_checkouts_allowed => $max_onsite_checkouts_allowed, |
488 |
my $delta = $switch_onsite_checkout ? 1 : 0; |
531 |
switch_onsite_checkout => $switch_onsite_checkout |
489 |
if ( $checkout_count >= $max_checkouts_allowed + $delta ) { |
532 |
}); |
490 |
return { |
533 |
return $qty_over if defined $qty_over; |
491 |
reason => 'TOO_MANY_CHECKOUTS', |
534 |
|
492 |
count => $checkout_count, |
535 |
|
493 |
max_allowed => $max_checkouts_allowed, |
536 |
# If the parent rule is less than or equal to the child, we only need check the parent |
494 |
}; |
537 |
if( $maxissueqty_rule->rule_value < $parent_maxissueqty_rule->rule_value && defined($maxissueqty_rule->itemtype) ) { |
495 |
} |
538 |
my $max_checkouts_allowed = $maxissueqty_rule->rule_value; |
496 |
} elsif ( not $onsite_checkout ) { |
539 |
my $qty_over = _check_max_qty({ |
497 |
if ( $checkout_count - $onsite_checkout_count >= $max_checkouts_allowed ) { |
540 |
checkout_count => $checkout_count_type, |
498 |
return { |
541 |
onsite_checkout_count => $onsite_checkout_count, |
499 |
reason => 'TOO_MANY_CHECKOUTS', |
542 |
onsite_checkout => $onsite_checkout, |
500 |
count => $checkout_count - $onsite_checkout_count, |
543 |
max_checkouts_allowed => $max_checkouts_allowed, |
501 |
max_allowed => $max_checkouts_allowed, |
544 |
max_onsite_checkouts_allowed => $max_onsite_checkouts_allowed, |
502 |
}; |
545 |
switch_onsite_checkout => $switch_onsite_checkout |
503 |
} |
546 |
}); |
|
|
547 |
return $qty_over if defined $qty_over; |
548 |
} |
549 |
|
550 |
} else { |
551 |
my $max_checkouts_allowed = $maxissueqty_rule->rule_value; |
552 |
my $qty_over = _check_max_qty({ |
553 |
checkout_count => $checkout_count, |
554 |
onsite_checkout_count => $onsite_checkout_count, |
555 |
onsite_checkout => $onsite_checkout, |
556 |
max_checkouts_allowed => $max_checkouts_allowed, |
557 |
max_onsite_checkouts_allowed => $max_onsite_checkouts_allowed, |
558 |
switch_onsite_checkout => $switch_onsite_checkout |
559 |
}); |
560 |
return $qty_over if defined $qty_over; |
504 |
} |
561 |
} |
|
|
562 |
|
563 |
|
505 |
} |
564 |
} |
506 |
|
565 |
|
507 |
# Now count total loans against the limit for the branch |
566 |
# Now count total loans against the limit for the branch |
Lines 527-561
sub TooMany {
Link Here
|
527 |
} |
586 |
} |
528 |
my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $branch_count_query, {}, @bind_params ); |
587 |
my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $branch_count_query, {}, @bind_params ); |
529 |
my $max_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxissueqty}; |
588 |
my $max_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxissueqty}; |
530 |
my $max_onsite_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxonsiteissueqty}; |
589 |
my $max_onsite_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxonsiteissueqty} || undef; |
531 |
|
590 |
|
532 |
if ( $onsite_checkout and $max_onsite_checkouts_allowed ne '' ) { |
591 |
my $qty_over = _check_max_qty({ |
533 |
if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed ) { |
592 |
checkout_count => $checkout_count, |
534 |
return { |
593 |
onsite_checkout_count => $onsite_checkout_count, |
535 |
reason => 'TOO_MANY_ONSITE_CHECKOUTS', |
594 |
onsite_checkout => $onsite_checkout, |
536 |
count => $onsite_checkout_count, |
595 |
max_checkouts_allowed => $max_checkouts_allowed, |
537 |
max_allowed => $max_onsite_checkouts_allowed, |
596 |
max_onsite_checkouts_allowed => $max_onsite_checkouts_allowed, |
538 |
} |
597 |
switch_onsite_checkout => $switch_onsite_checkout |
539 |
} |
598 |
}); |
540 |
} |
599 |
return $qty_over if defined $qty_over; |
541 |
if ( C4::Context->preference('ConsiderOnSiteCheckoutsAsNormalCheckouts') ) { |
600 |
|
542 |
my $delta = $switch_onsite_checkout ? 1 : 0; |
|
|
543 |
if ( $checkout_count >= $max_checkouts_allowed + $delta ) { |
544 |
return { |
545 |
reason => 'TOO_MANY_CHECKOUTS', |
546 |
count => $checkout_count, |
547 |
max_allowed => $max_checkouts_allowed, |
548 |
}; |
549 |
} |
550 |
} elsif ( not $onsite_checkout ) { |
551 |
if ( $checkout_count - $onsite_checkout_count >= $max_checkouts_allowed ) { |
552 |
return { |
553 |
reason => 'TOO_MANY_CHECKOUTS', |
554 |
count => $checkout_count - $onsite_checkout_count, |
555 |
max_allowed => $max_checkouts_allowed, |
556 |
}; |
557 |
} |
558 |
} |
559 |
} |
601 |
} |
560 |
|
602 |
|
561 |
if ( not defined( $maxissueqty_rule ) and not defined($branch_borrower_circ_rule->{patron_maxissueqty}) ) { |
603 |
if ( not defined( $maxissueqty_rule ) and not defined($branch_borrower_circ_rule->{patron_maxissueqty}) ) { |
Lines 566-571
sub TooMany {
Link Here
|
566 |
return; |
608 |
return; |
567 |
} |
609 |
} |
568 |
|
610 |
|
|
|
611 |
sub _check_max_qty { |
612 |
my $params = shift; |
613 |
my $checkout_count = $params->{checkout_count}; |
614 |
my $onsite_checkout_count = $params->{onsite_checkout_count}; |
615 |
my $onsite_checkout = $params->{onsite_checkout}; |
616 |
my $max_checkouts_allowed = $params->{max_checkouts_allowed}; |
617 |
my $max_onsite_checkouts_allowed = $params->{max_onsite_checkouts_allowed}; |
618 |
my $switch_onsite_checkout = $params->{switch_onsite_checkout}; |
619 |
|
620 |
if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) { |
621 |
if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed ) { |
622 |
return { |
623 |
reason => 'TOO_MANY_ONSITE_CHECKOUTS', |
624 |
count => $onsite_checkout_count, |
625 |
max_allowed => $max_onsite_checkouts_allowed, |
626 |
} |
627 |
} |
628 |
} |
629 |
if ( C4::Context->preference('ConsiderOnSiteCheckoutsAsNormalCheckouts') ) { |
630 |
my $delta = $switch_onsite_checkout ? 1 : 0; |
631 |
if ( $checkout_count >= $max_checkouts_allowed + $delta ) { |
632 |
return { |
633 |
reason => 'TOO_MANY_CHECKOUTS', |
634 |
count => $checkout_count, |
635 |
max_allowed => $max_checkouts_allowed, |
636 |
}; |
637 |
} |
638 |
} elsif ( not $onsite_checkout ) { |
639 |
if ( $checkout_count - $onsite_checkout_count >= $max_checkouts_allowed ) { |
640 |
return { |
641 |
reason => 'TOO_MANY_CHECKOUTS', |
642 |
count => $checkout_count - $onsite_checkout_count, |
643 |
max_allowed => $max_checkouts_allowed, |
644 |
}; |
645 |
} |
646 |
} |
647 |
|
648 |
return; |
649 |
} |
650 |
|
569 |
=head2 CanBookBeIssued |
651 |
=head2 CanBookBeIssued |
570 |
|
652 |
|
571 |
( $issuingimpossible, $needsconfirmation, [ $alerts ] ) = CanBookBeIssued( $patron, |
653 |
( $issuingimpossible, $needsconfirmation, [ $alerts ] ) = CanBookBeIssued( $patron, |