Lines 60-68
sub lowest_ratio_library {
Link Here
|
60 |
my $branch = $limit->get_column('branchcode'); |
60 |
my $branch = $limit->get_column('branchcode'); |
61 |
my $float_limit_val = $limit->get_column('float_limit'); |
61 |
my $float_limit_val = $limit->get_column('float_limit'); |
62 |
|
62 |
|
63 |
#don't try to transfer something to where it already is |
|
|
64 |
next if $branch eq $branchcode; |
65 |
|
66 |
my $item_count; |
63 |
my $item_count; |
67 |
|
64 |
|
68 |
if ($use_item_level) { |
65 |
if ($use_item_level) { |
Lines 98-105
sub lowest_ratio_library {
Link Here
|
98 |
join => 'branchtransfers', |
95 |
join => 'branchtransfers', |
99 |
where => { |
96 |
where => { |
100 |
'branchtransfers.frombranch' => $branch, |
97 |
'branchtransfers.frombranch' => $branch, |
101 |
'branchtransfers.datearrived' => undef, |
98 |
'branchtransfers.datearrived' => undef, # Still in transit |
102 |
'branchtransfers.datecancelled' => undef, |
99 |
'branchtransfers.datecancelled' => undef, #Not cancelled |
103 |
}, |
100 |
}, |
104 |
distinct => 1 |
101 |
distinct => 1 |
105 |
} |
102 |
} |
Lines 147-156
sub lowest_ratio_library {
Link Here
|
147 |
$item_count = $at_branch_count + $in_transit_to_count - $in_transit_from_count; |
144 |
$item_count = $at_branch_count + $in_transit_to_count - $in_transit_from_count; |
148 |
} |
145 |
} |
149 |
|
146 |
|
150 |
#don't transfer to branches that are already at their float limit |
|
|
151 |
next if $item_count >= $float_limit_val; |
152 |
|
153 |
my $ratio = $item_count / $float_limit_val; |
147 |
my $ratio = $item_count / $float_limit_val; |
|
|
148 |
|
154 |
push @candidates, { |
149 |
push @candidates, { |
155 |
branchcode => $branch, |
150 |
branchcode => $branch, |
156 |
ratio => $ratio, |
151 |
ratio => $ratio, |
Lines 158-169
sub lowest_ratio_library {
Link Here
|
158 |
}; |
153 |
}; |
159 |
} |
154 |
} |
160 |
|
155 |
|
161 |
@candidates = sort { $a->{ratio} <=> $b->{ratio} || $b->{float_limit} <=> $a->{float_limit} } @candidates; |
156 |
# 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; |
162 |
|
158 |
|
163 |
my $UseBranchTransferLimits = C4::Context->preference("UseBranchTransferLimits"); |
159 |
my $UseBranchTransferLimits = C4::Context->preference("UseBranchTransferLimits"); |
164 |
my $BranchTransferLimitsType = |
160 |
my $BranchTransferLimitsType = |
165 |
C4::Context->preference("BranchTransferLimitsType") eq 'itemtype' ? 'effective_itemtype' : 'ccode'; |
161 |
C4::Context->preference("BranchTransferLimitsType") eq 'itemtype' ? 'effective_itemtype' : 'ccode'; |
166 |
|
162 |
|
|
|
163 |
my $transfer_branch; |
167 |
for my $candidate (@candidates) { |
164 |
for my $candidate (@candidates) { |
168 |
if ($UseBranchTransferLimits) { |
165 |
if ($UseBranchTransferLimits) { |
169 |
my $allowed = C4::Circulation::IsBranchTransferAllowed( |
166 |
my $allowed = C4::Circulation::IsBranchTransferAllowed( |
Lines 171-182
sub lowest_ratio_library {
Link Here
|
171 |
$branchcode, |
168 |
$branchcode, |
172 |
$item->$BranchTransferLimitsType |
169 |
$item->$BranchTransferLimitsType |
173 |
); |
170 |
); |
174 |
return Koha::Libraries->find( $candidate->{branchcode} ) if $allowed; |
171 |
$transfer_branch = Koha::Libraries->find( $candidate->{branchcode} ) if $allowed; |
|
|
172 |
last; |
175 |
} else { |
173 |
} else { |
176 |
return Koha::Libraries->find( $candidate->{branchcode} ); |
174 |
$transfer_branch = Koha::Libraries->find( $candidate->{branchcode} ); |
|
|
175 |
last; |
177 |
} |
176 |
} |
178 |
} |
177 |
} |
179 |
return; |
178 |
|
|
|
179 |
return $transfer_branch; |
180 |
} |
180 |
} |
181 |
|
181 |
|
182 |
=head3 _type |
182 |
=head3 _type |