|
Lines 168-177
Top level function that turns reserves into tmp_holdsqueue and hold_fill_targets
Link Here
|
| 168 |
=cut |
168 |
=cut |
| 169 |
|
169 |
|
| 170 |
sub CreateQueue { |
170 |
sub CreateQueue { |
|
|
171 |
my $params = shift; |
| 172 |
my $unallocated = $params->{unallocated}; |
| 171 |
my $dbh = C4::Context->dbh; |
173 |
my $dbh = C4::Context->dbh; |
| 172 |
|
174 |
|
| 173 |
$dbh->do("DELETE FROM tmp_holdsqueue"); # clear the old table for new info |
175 |
unless( $unallocated ){ |
| 174 |
$dbh->do("DELETE FROM hold_fill_targets"); |
176 |
$dbh->do("DELETE FROM tmp_holdsqueue"); # clear the old table for new info |
|
|
177 |
$dbh->do("DELETE FROM hold_fill_targets"); |
| 178 |
} |
| 175 |
|
179 |
|
| 176 |
my $total_bibs = 0; |
180 |
my $total_bibs = 0; |
| 177 |
my $total_requests = 0; |
181 |
my $total_requests = 0; |
|
Lines 201-206
sub CreateQueue {
Link Here
|
| 201 |
{ biblio_id => $biblionumber, |
205 |
{ biblio_id => $biblionumber, |
| 202 |
branches_to_use => $branches_to_use, |
206 |
branches_to_use => $branches_to_use, |
| 203 |
transport_cost_matrix => $transport_cost_matrix, |
207 |
transport_cost_matrix => $transport_cost_matrix, |
|
|
208 |
unallocated => $unallocated |
| 204 |
} |
209 |
} |
| 205 |
); |
210 |
); |
| 206 |
|
211 |
|
|
Lines 228-233
sub GetBibsWithPendingHoldRequests {
Link Here
|
| 228 |
AND priority > 0 |
233 |
AND priority > 0 |
| 229 |
AND reservedate <= CURRENT_DATE() |
234 |
AND reservedate <= CURRENT_DATE() |
| 230 |
AND suspend = 0 |
235 |
AND suspend = 0 |
|
|
236 |
AND reserve_id NOT IN (SELECT reserve_id FROM hold_fill_targets) |
| 231 |
"; |
237 |
"; |
| 232 |
my $sth = $dbh->prepare($bib_query); |
238 |
my $sth = $dbh->prepare($bib_query); |
| 233 |
|
239 |
|
|
Lines 239-248
sub GetBibsWithPendingHoldRequests {
Link Here
|
| 239 |
|
245 |
|
| 240 |
=head2 GetPendingHoldRequestsForBib |
246 |
=head2 GetPendingHoldRequestsForBib |
| 241 |
|
247 |
|
| 242 |
my $requests = GetPendingHoldRequestsForBib($biblionumber); |
248 |
my $requests = GetPendingHoldRequestsForBib({ biblionumber => $biblionumber, unallocated => $unallocated }); |
| 243 |
|
249 |
|
| 244 |
Returns an arrayref of hashrefs to pending, unfilled hold requests |
250 |
Returns an arrayref of hashrefs to pending, unfilled hold requests |
| 245 |
on the bib identified by $biblionumber. The following keys |
251 |
on the bib identified by $biblionumber. Optionally returns only unallocated holds. The following keys |
| 246 |
are present in each hashref: |
252 |
are present in each hashref: |
| 247 |
|
253 |
|
| 248 |
biblionumber |
254 |
biblionumber |
|
Lines 259-265
The arrayref is sorted in order of increasing priority.
Link Here
|
| 259 |
=cut |
265 |
=cut |
| 260 |
|
266 |
|
| 261 |
sub GetPendingHoldRequestsForBib { |
267 |
sub GetPendingHoldRequestsForBib { |
| 262 |
my $biblionumber = shift; |
268 |
my $params = shift; |
|
|
269 |
my $biblionumber = $params->{biblionumber}; |
| 270 |
my $unallocated = $params->{unallocated}; |
| 263 |
|
271 |
|
| 264 |
my $dbh = C4::Context->dbh; |
272 |
my $dbh = C4::Context->dbh; |
| 265 |
|
273 |
|
|
Lines 271-278
sub GetPendingHoldRequestsForBib {
Link Here
|
| 271 |
AND found IS NULL |
279 |
AND found IS NULL |
| 272 |
AND priority > 0 |
280 |
AND priority > 0 |
| 273 |
AND reservedate <= CURRENT_DATE() |
281 |
AND reservedate <= CURRENT_DATE() |
| 274 |
AND suspend = 0 |
282 |
AND suspend = 0 "; |
| 275 |
ORDER BY priority"; |
283 |
$request_query .= "AND reserve_id NOT IN (SELECT reserve_id FROM hold_fill_targets) " if $unallocated; |
|
|
284 |
$request_query .= "ORDER BY priority"; |
| 276 |
my $sth = $dbh->prepare($request_query); |
285 |
my $sth = $dbh->prepare($request_query); |
| 277 |
$sth->execute($biblionumber); |
286 |
$sth->execute($biblionumber); |
| 278 |
|
287 |
|
|
Lines 330-339
sub GetItemsAvailableToFillHoldRequestsForBib {
Link Here
|
| 330 |
AND itemnumber IS NOT NULL |
339 |
AND itemnumber IS NOT NULL |
| 331 |
AND (found IS NOT NULL OR priority = 0) |
340 |
AND (found IS NOT NULL OR priority = 0) |
| 332 |
) |
341 |
) |
|
|
342 |
AND items.itemnumber NOT IN ( |
| 343 |
SELECT itemnumber |
| 344 |
FROM tmp_holdsqueue |
| 345 |
WHERE biblionumber = ? |
| 346 |
) |
| 333 |
AND items.biblionumber = ? |
347 |
AND items.biblionumber = ? |
| 334 |
AND branchtransfers.itemnumber IS NULL"; |
348 |
AND branchtransfers.itemnumber IS NULL"; |
| 335 |
|
349 |
|
| 336 |
my @params = ($biblionumber, $biblionumber); |
350 |
my @params = ($biblionumber, $biblionumber, $biblionumber); |
| 337 |
if ($branches_to_use && @$branches_to_use) { |
351 |
if ($branches_to_use && @$branches_to_use) { |
| 338 |
$items_query .= " AND holdingbranch IN (" . join (",", map { "?" } @$branches_to_use) . ")"; |
352 |
$items_query .= " AND holdingbranch IN (" . join (",", map { "?" } @$branches_to_use) . ")"; |
| 339 |
push @params, @$branches_to_use; |
353 |
push @params, @$branches_to_use; |
|
Lines 1120-1126
sub least_cost_branch {
Link Here
|
| 1120 |
biblio_id => $biblio_id, |
1134 |
biblio_id => $biblio_id, |
| 1121 |
[ branches_to_use => $branches_to_use, |
1135 |
[ branches_to_use => $branches_to_use, |
| 1122 |
transport_cost_matrix => $transport_cost_matrix, |
1136 |
transport_cost_matrix => $transport_cost_matrix, |
| 1123 |
delete => $delete, ] |
1137 |
delete => $delete, |
|
|
1138 |
unallocated => $unallocated, ] |
| 1124 |
} |
1139 |
} |
| 1125 |
); |
1140 |
); |
| 1126 |
|
1141 |
|
|
Lines 1151-1156
It return a hashref containing:
Link Here
|
| 1151 |
|
1166 |
|
| 1152 |
=item I<delete> tells the method to delete prior entries on the related tables for the biblio_id. |
1167 |
=item I<delete> tells the method to delete prior entries on the related tables for the biblio_id. |
| 1153 |
|
1168 |
|
|
|
1169 |
=item I<unallocated> tells the method to limit the holds to those not in the holds queue, should not |
| 1170 |
be passed at the same time as delete. |
| 1171 |
|
| 1154 |
=back |
1172 |
=back |
| 1155 |
|
1173 |
|
| 1156 |
Note: All the optional parameters will be calculated in the method if omitted. They |
1174 |
Note: All the optional parameters will be calculated in the method if omitted. They |
|
Lines 1171-1177
sub update_queue_for_biblio {
Link Here
|
| 1171 |
$dbh->do("DELETE FROM hold_fill_targets WHERE biblionumber=$biblio_id"); |
1189 |
$dbh->do("DELETE FROM hold_fill_targets WHERE biblionumber=$biblio_id"); |
| 1172 |
} |
1190 |
} |
| 1173 |
|
1191 |
|
| 1174 |
my $hold_requests = GetPendingHoldRequestsForBib($biblio_id); |
1192 |
my $hold_requests = GetPendingHoldRequestsForBib({ biblionumber => $biblio_id, unallocated => $args->{unallocated} }); |
| 1175 |
$result->{requests} = scalar( @{$hold_requests} ); |
1193 |
$result->{requests} = scalar( @{$hold_requests} ); |
| 1176 |
# No need to check anything else if there are no holds to fill |
1194 |
# No need to check anything else if there are no holds to fill |
| 1177 |
return $result unless $result->{requests}; |
1195 |
return $result unless $result->{requests}; |