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