Lines 41-47
Koha::Library::FloatLimits - Koha Library::FloatLimit object set class
Link Here
|
41 |
|
41 |
|
42 |
sub lowest_ratio_library { |
42 |
sub lowest_ratio_library { |
43 |
my ( $self, $item, $branchcode ) = @_; |
43 |
my ( $self, $item, $branchcode ) = @_; |
44 |
|
|
|
45 |
my $schema = Koha::Database->new->schema; |
44 |
my $schema = Koha::Database->new->schema; |
46 |
|
45 |
|
47 |
my @float_limits = $schema->resultset('LibraryFloatLimit')->search( |
46 |
my @float_limits = $schema->resultset('LibraryFloatLimit')->search( |
Lines 51-56
sub lowest_ratio_library {
Link Here
|
51 |
} |
50 |
} |
52 |
)->all; |
51 |
)->all; |
53 |
|
52 |
|
|
|
53 |
# check the items return policy |
54 |
my $hbr = Koha::CirculationRules->get_return_branch_policy($item); |
55 |
|
56 |
# if item only floats in the library group we must eliminate all other candidates |
57 |
if ( $hbr && $hbr eq 'returnbylibrarygroup' ) { |
58 |
my $current_library = Koha::Libraries->find($branchcode); |
59 |
my $float_libraries = $current_library->get_float_libraries; |
60 |
|
61 |
if ( $float_libraries->count > 0 ) { |
62 |
my @allowed_branchcodes = $float_libraries->get_column('branchcode'); |
63 |
my %allowed_branches = map { $_ => 1 } @allowed_branchcodes; |
64 |
@float_limits = grep { $allowed_branches{ $_->get_column('branchcode') } } @float_limits; |
65 |
} |
66 |
} |
67 |
|
54 |
return unless @float_limits; |
68 |
return unless @float_limits; |
55 |
|
69 |
|
56 |
my @candidates; |
70 |
my @candidates; |
Lines 154-160
sub lowest_ratio_library {
Link Here
|
154 |
} |
168 |
} |
155 |
|
169 |
|
156 |
# sort the branches by lowest ratio in the event of a tie choose a random branch |
170 |
# sort the branches by lowest ratio in the event of a tie choose a random branch |
157 |
@candidates = sort { $a->{ratio} <=> $b->{ratio} || rand() <=> rand() } @candidates; |
171 |
@candidates = sort { |
|
|
172 |
$a->{ratio} <=> $b->{ratio} || # Primary: lowest ratio |
173 |
( $a->{branchcode} eq $branchcode ? -1 : 0 ) - ( $b->{branchcode} eq $branchcode ? -1 : 0 ) |
174 |
|| # Prefer current branch if tied |
175 |
rand() <=> rand() # Random if tied and neither is current branch |
176 |
} @candidates; |
158 |
|
177 |
|
159 |
my $UseBranchTransferLimits = C4::Context->preference("UseBranchTransferLimits"); |
178 |
my $UseBranchTransferLimits = C4::Context->preference("UseBranchTransferLimits"); |
160 |
my $BranchTransferLimitsType = |
179 |
my $BranchTransferLimitsType = |
Lines 162-173
sub lowest_ratio_library {
Link Here
|
162 |
|
181 |
|
163 |
my $transfer_branch; |
182 |
my $transfer_branch; |
164 |
for my $candidate (@candidates) { |
183 |
for my $candidate (@candidates) { |
|
|
184 |
|
165 |
if ($UseBranchTransferLimits) { |
185 |
if ($UseBranchTransferLimits) { |
166 |
my $allowed = C4::Circulation::IsBranchTransferAllowed( |
186 |
my $allowed = C4::Circulation::IsBranchTransferAllowed( |
167 |
$candidate->{branchcode}, |
187 |
$candidate->{branchcode}, |
168 |
$branchcode, |
188 |
$branchcode, |
169 |
$item->$BranchTransferLimitsType |
189 |
$item->$BranchTransferLimitsType |
170 |
); |
190 |
); |
|
|
191 |
|
171 |
$transfer_branch = Koha::Libraries->find( $candidate->{branchcode} ) if $allowed; |
192 |
$transfer_branch = Koha::Libraries->find( $candidate->{branchcode} ) if $allowed; |
172 |
last; |
193 |
last; |
173 |
} else { |
194 |
} else { |
174 |
- |
|
|