|
Lines 368-374
sub GetItemsAvailableToFillHoldRequestsForBib {
Link Here
|
| 368 |
sub MapItemsToHoldRequests { |
368 |
sub MapItemsToHoldRequests { |
| 369 |
my ($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix) = @_; |
369 |
my ($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix) = @_; |
| 370 |
|
370 |
|
| 371 |
|
|
|
| 372 |
# handle trival cases |
371 |
# handle trival cases |
| 373 |
return unless scalar(@$hold_requests) > 0; |
372 |
return unless scalar(@$hold_requests) > 0; |
| 374 |
return unless scalar(@$available_items) > 0; |
373 |
return unless scalar(@$available_items) > 0; |
|
Lines 378-383
sub MapItemsToHoldRequests {
Link Here
|
| 378 |
grep { defined($_->{itemnumber}) } |
377 |
grep { defined($_->{itemnumber}) } |
| 379 |
@$hold_requests; |
378 |
@$hold_requests; |
| 380 |
|
379 |
|
|
|
380 |
map { $_->{_object} = Koha::Items->find( $_->{itemnumber} ) } @$available_items; |
| 381 |
my $libraries = {}; |
| 382 |
map { $libraries->{$_->id} = $_ } Koha::Libraries->search(); |
| 383 |
|
| 381 |
# group available items by itemnumber |
384 |
# group available items by itemnumber |
| 382 |
my %items_by_itemnumber = map { $_->{itemnumber} => $_ } @$available_items; |
385 |
my %items_by_itemnumber = map { $_->{itemnumber} => $_ } @$available_items; |
| 383 |
|
386 |
|
|
Lines 408-414
sub MapItemsToHoldRequests {
Link Here
|
| 408 |
|| ( $item->{holdallowed} == 1 |
411 |
|| ( $item->{holdallowed} == 1 |
| 409 |
&& $item->{homebranch} ne $request->{borrowerbranch} ); |
412 |
&& $item->{homebranch} ne $request->{borrowerbranch} ); |
| 410 |
|
413 |
|
| 411 |
next unless Koha::Items->find( $item->{itemnumber} )->can_be_transferred( { to => scalar Koha::Libraries->find( $request->{branchcode} ) } ); |
414 |
next unless $item->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } ); |
| 412 |
|
415 |
|
| 413 |
my $local_holds_priority_item_branchcode = |
416 |
my $local_holds_priority_item_branchcode = |
| 414 |
$item->{$LocalHoldsPriorityItemControl}; |
417 |
$item->{$LocalHoldsPriorityItemControl}; |
|
Lines 464-470
sub MapItemsToHoldRequests {
Link Here
|
| 464 |
and ( !$request->{itemtype} # If hold itemtype is set, item's itemtype must match |
467 |
and ( !$request->{itemtype} # If hold itemtype is set, item's itemtype must match |
| 465 |
|| $items_by_itemnumber{ $request->{itemnumber} }->{itype} eq $request->{itemtype} ) |
468 |
|| $items_by_itemnumber{ $request->{itemnumber} }->{itype} eq $request->{itemtype} ) |
| 466 |
) |
469 |
) |
| 467 |
and Koha::Items->find( $request->{itemnumber} )->can_be_transferred( { to => scalar Koha::Libraries->find( $request->{branchcode} ) } ) |
470 |
and $items_by_itemnumber{ $request->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } ) |
| 468 |
|
471 |
|
| 469 |
) |
472 |
) |
| 470 |
{ |
473 |
{ |
|
Lines 512-518
sub MapItemsToHoldRequests {
Link Here
|
| 512 |
my $holding_branch_items = $items_by_branch{$pickup_branch}; |
515 |
my $holding_branch_items = $items_by_branch{$pickup_branch}; |
| 513 |
if ( $holding_branch_items ) { |
516 |
if ( $holding_branch_items ) { |
| 514 |
foreach my $item (@$holding_branch_items) { |
517 |
foreach my $item (@$holding_branch_items) { |
| 515 |
next unless Koha::Items->find( $item->{itemnumber} )->can_be_transferred( { to => scalar Koha::Libraries->find( $request->{branchcode} ) } ); |
518 |
next unless $items_by_itemnumber{ $item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } ); |
| 516 |
|
519 |
|
| 517 |
if ( |
520 |
if ( |
| 518 |
$request->{borrowerbranch} eq $item->{homebranch} |
521 |
$request->{borrowerbranch} eq $item->{homebranch} |
|
Lines 536-542
sub MapItemsToHoldRequests {
Link Here
|
| 536 |
my $holding_branch_items = $items_by_branch{$holdingbranch}; |
539 |
my $holding_branch_items = $items_by_branch{$holdingbranch}; |
| 537 |
foreach my $item (@$holding_branch_items) { |
540 |
foreach my $item (@$holding_branch_items) { |
| 538 |
next if $request->{borrowerbranch} ne $item->{homebranch}; |
541 |
next if $request->{borrowerbranch} ne $item->{homebranch}; |
| 539 |
next unless Koha::Items->find( $item->{itemnumber} )->can_be_transferred( { to => scalar Koha::Libraris->find( $request->{branchcode} ) } ); |
542 |
next unless $items_by_itemnumber{ $item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } ); |
| 540 |
|
543 |
|
| 541 |
# Don't fill item level holds that contravene the hold pickup policy at this time |
544 |
# Don't fill item level holds that contravene the hold pickup policy at this time |
| 542 |
next unless $item->{hold_fulfillment_policy} eq 'any' |
545 |
next unless $item->{hold_fulfillment_policy} eq 'any' |
|
Lines 573-579
sub MapItemsToHoldRequests {
Link Here
|
| 573 |
foreach my $item (@$holding_branch_items) { |
576 |
foreach my $item (@$holding_branch_items) { |
| 574 |
next if $pickup_branch ne $item->{homebranch}; |
577 |
next if $pickup_branch ne $item->{homebranch}; |
| 575 |
next if ( $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch} ); |
578 |
next if ( $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch} ); |
| 576 |
next unless Koha::Items->find( $item->{itemnumber} )->can_be_transferred( { to => scalar Koha::Libraries->find( $request->{branchcode} ) } ); |
579 |
next unless $items_by_itemnumber{ $item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } ); |
| 577 |
|
580 |
|
| 578 |
# Don't fill item level holds that contravene the hold pickup policy at this time |
581 |
# Don't fill item level holds that contravene the hold pickup policy at this time |
| 579 |
next unless $item->{hold_fulfillment_policy} eq 'any' |
582 |
next unless $item->{hold_fulfillment_policy} eq 'any' |
|
Lines 602-608
sub MapItemsToHoldRequests {
Link Here
|
| 602 |
next unless ( !$request->{itemtype} |
605 |
next unless ( !$request->{itemtype} |
| 603 |
|| $current_item->{itype} eq $request->{itemtype} ); |
606 |
|| $current_item->{itype} eq $request->{itemtype} ); |
| 604 |
|
607 |
|
| 605 |
next unless Koha::Items->find( $current_item->{itemnumber} )->can_be_transferred( { to => scalar Koha::Libraries->find( $request->{branchcode} ) } ); |
608 |
next unless $items_by_itemnumber{ $current_item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } ); |
| 606 |
|
609 |
|
| 607 |
$itemnumber = $current_item->{itemnumber}; |
610 |
$itemnumber = $current_item->{itemnumber}; |
| 608 |
last; # quit this loop as soon as we have a suitable item |
611 |
last; # quit this loop as soon as we have a suitable item |
|
Lines 628-634
sub MapItemsToHoldRequests {
Link Here
|
| 628 |
next unless ( !$request->{itemtype} |
631 |
next unless ( !$request->{itemtype} |
| 629 |
|| $item->{itype} eq $request->{itemtype} ); |
632 |
|| $item->{itype} eq $request->{itemtype} ); |
| 630 |
|
633 |
|
| 631 |
next unless Koha::Items->find( $item->{itemnumber} )->can_be_transferred( { to => scalar Koha::Libraries->find( $request->{branchcode} ) } ); |
634 |
next unless $items_by_itemnumber{ $item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } ); |
| 632 |
|
635 |
|
| 633 |
$itemnumber = $item->{itemnumber}; |
636 |
$itemnumber = $item->{itemnumber}; |
| 634 |
$holdingbranch = $branch; |
637 |
$holdingbranch = $branch; |
| 635 |
- |
|
|