Lines 475-521
sub TooMany {
Link Here
|
475 |
$checkouts = $patron->checkouts; # if branch is the patron's home branch, then count all loans by patron |
475 |
$checkouts = $patron->checkouts; # if branch is the patron's home branch, then count all loans by patron |
476 |
} else { |
476 |
} else { |
477 |
$checkouts = $patron->checkouts->search( |
477 |
$checkouts = $patron->checkouts->search( |
478 |
{ 'item.homebranch' => $maxissueqty_rule->branchcode }, |
478 |
{ 'item.homebranch' => $maxissueqty_rule->branchcode } ); |
479 |
{ prefetch => 'item' } ); |
|
|
480 |
} |
479 |
} |
481 |
} else { |
480 |
} else { |
482 |
$checkouts = $patron->checkouts; # if rule is not branch specific then count all loans by patron |
481 |
$checkouts = $patron->checkouts; # if rule is not branch specific then count all loans by patron |
483 |
} |
482 |
} |
|
|
483 |
$checkouts = $checkouts->search(undef, { prefetch => 'item' }); |
484 |
|
484 |
my $sum_checkouts; |
485 |
my $sum_checkouts; |
485 |
my $rule_itemtype = $maxissueqty_rule->itemtype; |
486 |
my $rule_itemtype = $maxissueqty_rule->itemtype; |
486 |
while ( my $c = $checkouts->next ) { |
|
|
487 |
my $itemtype = $c->item->effective_itemtype; |
488 |
my @types; |
489 |
unless ( $rule_itemtype ) { |
490 |
# matching rule has the default item type, so count only |
491 |
# those existing loans that don't fall under a more |
492 |
# specific rule |
493 |
@types = Koha::CirculationRules->search( |
494 |
{ |
495 |
branchcode => $maxissueqty_rule->branchcode, |
496 |
categorycode => [ $maxissueqty_rule->categorycode, $cat_borrower ], |
497 |
itemtype => { '!=' => undef }, |
498 |
rule_name => 'maxissueqty' |
499 |
} |
500 |
)->get_column('itemtype'); |
501 |
|
487 |
|
502 |
next if grep {$_ eq $itemtype} @types; |
488 |
my @types; |
503 |
} else { |
489 |
unless ( $rule_itemtype ) { |
504 |
my @types; |
490 |
# matching rule has the default item type, so count only |
505 |
if ( $parent_maxissueqty_rule ) { |
491 |
# those existing loans that don't fall under a more |
|
|
492 |
# specific rule |
493 |
@types = Koha::CirculationRules->search( |
494 |
{ |
495 |
branchcode => $maxissueqty_rule->branchcode, |
496 |
categorycode => [ $maxissueqty_rule->categorycode, $cat_borrower ], |
497 |
itemtype => { '!=' => undef }, |
498 |
rule_name => 'maxissueqty' |
499 |
} |
500 |
)->get_column('itemtype'); |
501 |
} else { |
502 |
if ( $parent_maxissueqty_rule ) { |
506 |
# 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 |
507 |
# specific item type or its siblings or parent |
504 |
# specific item type or its siblings or parent |
508 |
my $children = Koha::ItemTypes->search({ parent_type => $parent_type }); |
505 |
my $children = Koha::ItemTypes->search({ parent_type => $parent_type }); |
509 |
@types = $children->get_column('itemtype'); |
506 |
@types = $children->get_column('itemtype'); |
510 |
push @types, $parent_type; |
507 |
push @types, $parent_type; |
511 |
} elsif ( $child_types ) { |
508 |
} elsif ( $child_types ) { |
512 |
# If we are a parent type, we need to count all child types and our own type |
509 |
# If we are a parent type, we need to count all child types and our own type |
513 |
@types = $child_types->get_column('itemtype'); |
510 |
@types = $child_types->get_column('itemtype'); |
514 |
push @types, $type; # And don't forget to count our own types |
511 |
push @types, $type; # And don't forget to count our own types |
515 |
} else { push @types, $type; } # Otherwise only count the specific itemtype |
512 |
} else { |
|
|
513 |
# Otherwise only count the specific itemtype |
514 |
push @types, $type; |
515 |
} |
516 |
} |
517 |
|
518 |
while ( my $c = $checkouts->next ) { |
519 |
my $itemtype = $c->item->effective_itemtype; |
516 |
|
520 |
|
|
|
521 |
unless ( $rule_itemtype ) { |
522 |
next if grep {$_ eq $itemtype} @types; |
523 |
} else { |
517 |
next unless grep {$_ eq $itemtype} @types; |
524 |
next unless grep {$_ eq $itemtype} @types; |
518 |
} |
525 |
} |
|
|
526 |
|
519 |
$sum_checkouts->{total}++; |
527 |
$sum_checkouts->{total}++; |
520 |
$sum_checkouts->{onsite_checkouts}++ if $c->onsite_checkout; |
528 |
$sum_checkouts->{onsite_checkouts}++ if $c->onsite_checkout; |
521 |
$sum_checkouts->{itemtype}->{$itemtype}++; |
529 |
$sum_checkouts->{itemtype}->{$itemtype}++; |
522 |
- |
|
|