Lines 31-36
use C4::Biblio;
Link Here
|
31 |
use Koha::DateUtils; |
31 |
use Koha::DateUtils; |
32 |
use Koha::Items; |
32 |
use Koha::Items; |
33 |
use Koha::Patrons; |
33 |
use Koha::Patrons; |
|
|
34 |
use Koha::Libraries; |
34 |
|
35 |
|
35 |
use List::Util qw(shuffle); |
36 |
use List::Util qw(shuffle); |
36 |
use List::MoreUtils qw(any); |
37 |
use List::MoreUtils qw(any); |
Lines 361-366
sub GetItemsAvailableToFillHoldRequestsForBib {
Link Here
|
361 |
} @items ]; |
362 |
} @items ]; |
362 |
} |
363 |
} |
363 |
|
364 |
|
|
|
365 |
=head2 _checkHoldPolicy |
366 |
|
367 |
_checkHoldPolicy($item, $request) |
368 |
|
369 |
check if item agrees with hold policies |
370 |
|
371 |
=cut |
372 |
|
373 |
sub _checkHoldPolicy { |
374 |
my ($item, $request) = @_; |
375 |
|
376 |
return 0 unless $item->{holdallowed}; |
377 |
return 0 if $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch}; |
378 |
|
379 |
my $library = Koha::Libraries->find($item->{homebranch}); |
380 |
|
381 |
return 0 if $item->{'holdallowed'} == 3 && !$library->validate_hold_sibling({branchcode => $request->{borrowerbranch}}); |
382 |
|
383 |
my $hold_fulfillment_policy = $item->{hold_fulfillment_policy}; |
384 |
|
385 |
return 0 if $hold_fulfillment_policy eq 'holdgroup' && !$library->validate_hold_sibling({branchcode => $request->{branchcode}}); |
386 |
return 0 if $hold_fulfillment_policy eq 'homebranch' && $request->{branchcode} ne $item->$hold_fulfillment_policy; |
387 |
return 0 if $hold_fulfillment_policy eq 'holdingbranch' && $request->{branchcode} ne $item->$hold_fulfillment_policy; |
388 |
|
389 |
my $patronLibrary = Koha::Libraries->find($request->{borrowerbranch}); |
390 |
|
391 |
return 0 if $hold_fulfillment_policy eq 'patrongroup' && !patronLibrary->validate_hold_sibling({branchcode => $request->{branchcode}}); |
392 |
|
393 |
return 1; |
394 |
|
395 |
} |
396 |
|
364 |
=head2 MapItemsToHoldRequests |
397 |
=head2 MapItemsToHoldRequests |
365 |
|
398 |
|
366 |
MapItemsToHoldRequests($hold_requests, $available_items, $branches, $transport_cost_matrix) |
399 |
MapItemsToHoldRequests($hold_requests, $available_items, $branches, $transport_cost_matrix) |
Lines 409-419
sub MapItemsToHoldRequests {
Link Here
|
409 |
|
442 |
|
410 |
my $local_hold_match; |
443 |
my $local_hold_match; |
411 |
foreach my $item (@$available_items) { |
444 |
foreach my $item (@$available_items) { |
412 |
next |
445 |
next if $item->{_object}->exclude_from_local_holds_priority; |
413 |
if ( !$item->{holdallowed} ) |
446 |
|
414 |
|| ( $item->{holdallowed} == 1 |
447 |
next unless _checkHoldPolicy($item, $request); |
415 |
&& $item->{homebranch} ne $request->{borrowerbranch} ) |
|
|
416 |
|| $item->{_object}->exclude_from_local_holds_priority; |
417 |
|
448 |
|
418 |
next if $request->{itemnumber} && $request->{itemnumber} != $item->{itemnumber}; |
449 |
next if $request->{itemnumber} && $request->{itemnumber} != $item->{itemnumber}; |
419 |
|
450 |
|
Lines 468-479
sub MapItemsToHoldRequests {
Link Here
|
468 |
if ( |
499 |
if ( |
469 |
exists $items_by_itemnumber{ $request->{itemnumber} } |
500 |
exists $items_by_itemnumber{ $request->{itemnumber} } |
470 |
and not exists $allocated_items{ $request->{itemnumber} } |
501 |
and not exists $allocated_items{ $request->{itemnumber} } |
471 |
and ( # Don't fill item level holds that contravene the hold pickup policy at this time |
502 |
and _checkHoldPolicy($items_by_itemnumber{ $request->{itemnumber} }, $request) # Don't fill item level holds that contravene the hold pickup policy at this time |
472 |
( $items_by_itemnumber{ $request->{itemnumber} }->{hold_fulfillment_policy} eq 'any' ) |
|
|
473 |
|| ( $request->{branchcode} eq $items_by_itemnumber{ $request->{itemnumber} }->{ $items_by_itemnumber{ $request->{itemnumber} }->{hold_fulfillment_policy} } ) |
474 |
and ( !$request->{itemtype} # If hold itemtype is set, item's itemtype must match |
503 |
and ( !$request->{itemtype} # If hold itemtype is set, item's itemtype must match |
475 |
|| $items_by_itemnumber{ $request->{itemnumber} }->{itype} eq $request->{itemtype} ) |
504 |
|| $items_by_itemnumber{ $request->{itemnumber} }->{itype} eq $request->{itemtype} ) |
476 |
) |
505 |
|
477 |
and $items_by_itemnumber{ $request->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } ) |
506 |
and $items_by_itemnumber{ $request->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } ) |
478 |
|
507 |
|
479 |
) |
508 |
) |
Lines 527-534
sub MapItemsToHoldRequests {
Link Here
|
527 |
|
556 |
|
528 |
if ( |
557 |
if ( |
529 |
$request->{borrowerbranch} eq $item->{homebranch} |
558 |
$request->{borrowerbranch} eq $item->{homebranch} |
530 |
&& ( ( $item->{hold_fulfillment_policy} eq 'any' ) # Don't fill item level holds that contravene the hold pickup policy at this time |
559 |
&& _checkHoldPolicy($item, $request) # Don't fill item level holds that contravene the hold pickup policy at this time |
531 |
|| $request->{branchcode} eq $item->{ $item->{hold_fulfillment_policy} } ) |
|
|
532 |
&& ( !$request->{itemtype} # If hold itemtype is set, item's itemtype must match |
560 |
&& ( !$request->{itemtype} # If hold itemtype is set, item's itemtype must match |
533 |
|| ( $request->{itemnumber} && ( $items_by_itemnumber{ $request->{itemnumber} }->{itype} eq $request->{itemtype} ) ) ) |
561 |
|| ( $request->{itemnumber} && ( $items_by_itemnumber{ $request->{itemnumber} }->{itype} eq $request->{itemtype} ) ) ) |
534 |
) |
562 |
) |
Lines 550-557
sub MapItemsToHoldRequests {
Link Here
|
550 |
next unless $items_by_itemnumber{ $item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } ); |
578 |
next unless $items_by_itemnumber{ $item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } ); |
551 |
|
579 |
|
552 |
# Don't fill item level holds that contravene the hold pickup policy at this time |
580 |
# Don't fill item level holds that contravene the hold pickup policy at this time |
553 |
next unless $item->{hold_fulfillment_policy} eq 'any' |
581 |
next unless _checkHoldPolicy($item, $request); |
554 |
|| $request->{branchcode} eq $item->{ $item->{hold_fulfillment_policy} }; |
|
|
555 |
|
582 |
|
556 |
# If hold itemtype is set, item's itemtype must match |
583 |
# If hold itemtype is set, item's itemtype must match |
557 |
next unless ( !$request->{itemtype} |
584 |
next unless ( !$request->{itemtype} |
Lines 583-589
sub MapItemsToHoldRequests {
Link Here
|
583 |
$holdingbranch ||= $branch; |
610 |
$holdingbranch ||= $branch; |
584 |
foreach my $item (@$holding_branch_items) { |
611 |
foreach my $item (@$holding_branch_items) { |
585 |
next if $pickup_branch ne $item->{homebranch}; |
612 |
next if $pickup_branch ne $item->{homebranch}; |
586 |
next if ( $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch} ); |
613 |
next unless _checkHoldPolicy($item, $request); |
587 |
next unless $items_by_itemnumber{ $item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } ); |
614 |
next unless $items_by_itemnumber{ $item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } ); |
588 |
|
615 |
|
589 |
# Don't fill item level holds that contravene the hold pickup policy at this time |
616 |
# Don't fill item level holds that contravene the hold pickup policy at this time |
Lines 601-623
sub MapItemsToHoldRequests {
Link Here
|
601 |
} |
628 |
} |
602 |
|
629 |
|
603 |
# Now try items from the least cost branch based on the transport cost matrix or StaticHoldsQueueWeight |
630 |
# Now try items from the least cost branch based on the transport cost matrix or StaticHoldsQueueWeight |
604 |
unless ( $itemnumber ) { |
631 |
unless ( $itemnumber || !$holdingbranch) { |
605 |
foreach my $current_item ( @{ $items_by_branch{$holdingbranch} } ) { |
632 |
foreach my $current_item ( @{ $items_by_branch{$holdingbranch} } ) { |
606 |
if ( $holdingbranch && ( $current_item->{holdallowed} == 2 || $request->{borrowerbranch} eq $current_item->{homebranch} ) ) { |
633 |
next unless _checkHoldPolicy($current_item, $request); # Don't fill item level holds that contravene the hold pickup policy at this time |
607 |
|
|
|
608 |
# Don't fill item level holds that contravene the hold pickup policy at this time |
609 |
next unless $current_item->{hold_fulfillment_policy} eq 'any' |
610 |
|| $request->{branchcode} eq $current_item->{ $current_item->{hold_fulfillment_policy} }; |
611 |
|
634 |
|
612 |
# If hold itemtype is set, item's itemtype must match |
635 |
# If hold itemtype is set, item's itemtype must match |
613 |
next unless ( !$request->{itemtype} |
636 |
next unless ( !$request->{itemtype} |
614 |
|| $current_item->{itype} eq $request->{itemtype} ); |
637 |
|| $current_item->{itype} eq $request->{itemtype} ); |
615 |
|
638 |
|
616 |
next unless $items_by_itemnumber{ $current_item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } ); |
639 |
next unless $items_by_itemnumber{ $current_item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } ); |
617 |
|
640 |
|
618 |
$itemnumber = $current_item->{itemnumber}; |
641 |
$itemnumber = $current_item->{itemnumber}; |
619 |
last; # quit this loop as soon as we have a suitable item |
642 |
last; # quit this loop as soon as we have a suitable item |
620 |
} |
|
|
621 |
} |
643 |
} |
622 |
} |
644 |
} |
623 |
|
645 |
|
Lines 629-639
sub MapItemsToHoldRequests {
Link Here
|
629 |
or next; |
651 |
or next; |
630 |
|
652 |
|
631 |
foreach my $item (@$holding_branch_items) { |
653 |
foreach my $item (@$holding_branch_items) { |
632 |
next if ( $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch} ); |
|
|
633 |
|
634 |
# Don't fill item level holds that contravene the hold pickup policy at this time |
654 |
# Don't fill item level holds that contravene the hold pickup policy at this time |
635 |
next unless $item->{hold_fulfillment_policy} eq 'any' |
655 |
next unless _checkHoldPolicy($item, $request); |
636 |
|| $request->{branchcode} eq $item->{ $item->{hold_fulfillment_policy} }; |
|
|
637 |
|
656 |
|
638 |
# If hold itemtype is set, item's itemtype must match |
657 |
# If hold itemtype is set, item's itemtype must match |
639 |
next unless ( !$request->{itemtype} |
658 |
next unless ( !$request->{itemtype} |
640 |
- |
|
|