Lines 451-497
sub TooMany {
Link Here
|
451 |
$checkouts = $patron->checkouts; # if branch is the patron's home branch, then count all loans by patron |
451 |
$checkouts = $patron->checkouts; # if branch is the patron's home branch, then count all loans by patron |
452 |
} else { |
452 |
} else { |
453 |
$checkouts = $patron->checkouts->search( |
453 |
$checkouts = $patron->checkouts->search( |
454 |
{ 'item.homebranch' => $maxissueqty_rule->branchcode }, |
454 |
{ 'item.homebranch' => $maxissueqty_rule->branchcode } ); |
455 |
{ prefetch => 'item' } ); |
|
|
456 |
} |
455 |
} |
457 |
} else { |
456 |
} else { |
458 |
$checkouts = $patron->checkouts; # if rule is not branch specific then count all loans by patron |
457 |
$checkouts = $patron->checkouts; # if rule is not branch specific then count all loans by patron |
459 |
} |
458 |
} |
|
|
459 |
$checkouts = $checkouts->search(undef, { prefetch => 'item' }); |
460 |
|
460 |
my $sum_checkouts; |
461 |
my $sum_checkouts; |
461 |
my $rule_itemtype = $maxissueqty_rule->itemtype; |
462 |
my $rule_itemtype = $maxissueqty_rule->itemtype; |
462 |
while ( my $c = $checkouts->next ) { |
|
|
463 |
my $itemtype = $c->item->effective_itemtype; |
464 |
my @types; |
465 |
unless ( $rule_itemtype ) { |
466 |
# matching rule has the default item type, so count only |
467 |
# those existing loans that don't fall under a more |
468 |
# specific rule |
469 |
@types = Koha::CirculationRules->search( |
470 |
{ |
471 |
branchcode => $maxissueqty_rule->branchcode, |
472 |
categorycode => [ $maxissueqty_rule->categorycode, $cat_borrower ], |
473 |
itemtype => { '!=' => undef }, |
474 |
rule_name => 'maxissueqty' |
475 |
} |
476 |
)->get_column('itemtype'); |
477 |
|
463 |
|
478 |
next if grep {$_ eq $itemtype} @types; |
464 |
my @types; |
479 |
} else { |
465 |
unless ( $rule_itemtype ) { |
480 |
my @types; |
466 |
# matching rule has the default item type, so count only |
481 |
if ( $parent_maxissueqty_rule ) { |
467 |
# those existing loans that don't fall under a more |
|
|
468 |
# specific rule |
469 |
@types = Koha::CirculationRules->search( |
470 |
{ |
471 |
branchcode => $maxissueqty_rule->branchcode, |
472 |
categorycode => [ $maxissueqty_rule->categorycode, $cat_borrower ], |
473 |
itemtype => { '!=' => undef }, |
474 |
rule_name => 'maxissueqty' |
475 |
} |
476 |
)->get_column('itemtype'); |
477 |
} else { |
478 |
if ( $parent_maxissueqty_rule ) { |
482 |
# if we have a parent item type then we count loans of the |
479 |
# if we have a parent item type then we count loans of the |
483 |
# specific item type or its siblings or parent |
480 |
# specific item type or its siblings or parent |
484 |
my $children = Koha::ItemTypes->search({ parent_type => $parent_type }); |
481 |
my $children = Koha::ItemTypes->search({ parent_type => $parent_type }); |
485 |
@types = $children->get_column('itemtype'); |
482 |
@types = $children->get_column('itemtype'); |
486 |
push @types, $parent_type; |
483 |
push @types, $parent_type; |
487 |
} elsif ( $child_types ) { |
484 |
} elsif ( $child_types ) { |
488 |
# If we are a parent type, we need to count all child types and our own type |
485 |
# If we are a parent type, we need to count all child types and our own type |
489 |
@types = $child_types->get_column('itemtype'); |
486 |
@types = $child_types->get_column('itemtype'); |
490 |
push @types, $type; # And don't forget to count our own types |
487 |
push @types, $type; # And don't forget to count our own types |
491 |
} else { push @types, $type; } # Otherwise only count the specific itemtype |
488 |
} else { |
|
|
489 |
# Otherwise only count the specific itemtype |
490 |
push @types, $type; |
491 |
} |
492 |
} |
493 |
|
494 |
while ( my $c = $checkouts->next ) { |
495 |
my $itemtype = $c->item->effective_itemtype; |
492 |
|
496 |
|
|
|
497 |
unless ( $rule_itemtype ) { |
498 |
next if grep {$_ eq $itemtype} @types; |
499 |
} else { |
493 |
next unless grep {$_ eq $itemtype} @types; |
500 |
next unless grep {$_ eq $itemtype} @types; |
494 |
} |
501 |
} |
|
|
502 |
|
495 |
$sum_checkouts->{total}++; |
503 |
$sum_checkouts->{total}++; |
496 |
$sum_checkouts->{onsite_checkouts}++ if $c->onsite_checkout; |
504 |
$sum_checkouts->{onsite_checkouts}++ if $c->onsite_checkout; |
497 |
$sum_checkouts->{itemtype}->{$itemtype}++; |
505 |
$sum_checkouts->{itemtype}->{$itemtype}++; |
498 |
- |
|
|