View | Details | Raw Unified | Return to bug 26963
Collapse All | Expand All

(-)a/Koha/Item.pm (-8 / +66 lines)
Lines 550-555 sub can_be_transferred { Link Here
550
        $limittype => $limittype eq 'itemtype'
550
        $limittype => $limittype eq 'itemtype'
551
                        ? $self->effective_itemtype : $self->ccode
551
                        ? $self->effective_itemtype : $self->ccode
552
    })->count ? 0 : 1;
552
    })->count ? 0 : 1;
553
554
}
555
556
=head3 _can_pickup_at
557
558
$item->_can_pickup_at({ to => $to_libraries, from => $from_library })
559
Checks if an item can be transferred to given libraries.
560
561
This feature is controlled by two system preferences:
562
UseBranchTransferLimits to enable / disable the feature
563
BranchTransferLimitsType to use either an itemnumber or ccode as an identifier
564
                         for setting the limitations
565
566
Takes HASHref that can have the following parameters:
567
    MANDATORY PARAMETERS:
568
    $to   : Array of Koha::Libraries
569
    OPTIONAL PARAMETERS:
570
    $from : Koha::Library  # if not given, item holdingbranch
571
                           # will be used instead
572
573
Returns arry of Koha::Libraries that item can be transferred to $to_library and
574
are pickup_locations
575
576
If checking only one library please use $item->can_be_transferred.
577
578
=cut
579
580
sub _can_pickup_at {
581
    my ($self, $params ) = @_;
582
583
    my $to   = $params->{to};
584
    my $from = $params->{from};
585
    $from = defined $from ? $from->branchcode : $self->holdingbranch;
586
587
    my @pickup_locations;
588
    my @destination_codes;
589
    foreach my $lib (@$to){
590
        next unless $lib->pickup_location;
591
        push @destination_codes, $lib->branchcode;
592
        push @pickup_locations, $lib;
593
    }
594
595
    return \@pickup_locations unless C4::Context->preference('UseBranchTransferLimits');
596
597
    my $limittype = C4::Context->preference('BranchTransferLimitsType');
598
    my $limiter = $limittype eq 'itemtype' ? $self->effective_itemtype : $self->ccode;
599
600
    my $limits = Koha::Item::Transfer::Limits->search({
601
                fromBranch => $from,
602
                $limittype => $limiter
603
            });
604
    my @limits = $limits->get_column('toBranch');
605
    return \@pickup_locations unless @limits;
606
607
    my @can_transfer = Koha::Libraries->search({
608
        pickup_location => 1,
609
        branchcode => {
610
            -in => \@destination_codes,
611
            -not_in => \@limits,
612
        }
613
    });
614
    return \@can_transfer;
553
}
615
}
554
616
555
=head3 pickup_locations
617
=head3 pickup_locations
Lines 596-609 sub pickup_locations { Link Here
596
        })->as_list;
658
        })->as_list;
597
    }
659
    }
598
660
599
    my @pickup_locations;
661
    my $pickup_locations = $self->_can_pickup_at({
600
    foreach my $library (@libs) {
662
        to => \@libs
601
        if ($library->pickup_location && $self->can_be_transferred({ to => $library })) {
663
    });
602
            push @pickup_locations, $library;
603
        }
604
    }
605
664
606
    return \@pickup_locations;
665
    return $pickup_locations;
607
}
666
}
608
667
609
=head3 article_request_type
668
=head3 article_request_type
610
- 

Return to bug 26963