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