|
Lines 182-191
Top level function that turns reserves into tmp_holdsqueue and hold_fill_targets
Link Here
|
| 182 |
=cut |
182 |
=cut |
| 183 |
|
183 |
|
| 184 |
sub CreateQueue { |
184 |
sub CreateQueue { |
|
|
185 |
my $params = shift; |
| 186 |
my $unallocated = $params->{unallocated}; |
| 185 |
my $dbh = C4::Context->dbh; |
187 |
my $dbh = C4::Context->dbh; |
| 186 |
|
188 |
|
| 187 |
$dbh->do("DELETE FROM tmp_holdsqueue"); # clear the old table for new info |
189 |
unless( $unallocated ){ |
| 188 |
$dbh->do("DELETE FROM hold_fill_targets"); |
190 |
$dbh->do("DELETE FROM tmp_holdsqueue"); # clear the old table for new info |
|
|
191 |
$dbh->do("DELETE FROM hold_fill_targets"); |
| 192 |
} |
| 189 |
|
193 |
|
| 190 |
my $total_bibs = 0; |
194 |
my $total_bibs = 0; |
| 191 |
my $total_requests = 0; |
195 |
my $total_requests = 0; |
|
Lines 215-220
sub CreateQueue {
Link Here
|
| 215 |
{ biblio_id => $biblionumber, |
219 |
{ biblio_id => $biblionumber, |
| 216 |
branches_to_use => $branches_to_use, |
220 |
branches_to_use => $branches_to_use, |
| 217 |
transport_cost_matrix => $transport_cost_matrix, |
221 |
transport_cost_matrix => $transport_cost_matrix, |
|
|
222 |
unallocated => $unallocated |
| 218 |
} |
223 |
} |
| 219 |
); |
224 |
); |
| 220 |
|
225 |
|
|
Lines 253-262
sub GetBibsWithPendingHoldRequests {
Link Here
|
| 253 |
|
258 |
|
| 254 |
=head2 GetPendingHoldRequestsForBib |
259 |
=head2 GetPendingHoldRequestsForBib |
| 255 |
|
260 |
|
| 256 |
my $requests = GetPendingHoldRequestsForBib($biblionumber); |
261 |
my $requests = GetPendingHoldRequestsForBib({ biblionumber => $biblionumber, unallocated => $unallocated }); |
| 257 |
|
262 |
|
| 258 |
Returns an arrayref of hashrefs to pending, unfilled hold requests |
263 |
Returns an arrayref of hashrefs to pending, unfilled hold requests |
| 259 |
on the bib identified by $biblionumber. The following keys |
264 |
on the bib identified by $biblionumber. Optionally returns only unallocated holds. The following keys |
| 260 |
are present in each hashref: |
265 |
are present in each hashref: |
| 261 |
|
266 |
|
| 262 |
biblionumber |
267 |
biblionumber |
|
Lines 273-279
The arrayref is sorted in order of increasing priority.
Link Here
|
| 273 |
=cut |
278 |
=cut |
| 274 |
|
279 |
|
| 275 |
sub GetPendingHoldRequestsForBib { |
280 |
sub GetPendingHoldRequestsForBib { |
| 276 |
my $biblionumber = shift; |
281 |
my $params = shift; |
|
|
282 |
my $biblionumber = $params->{biblionumber}; |
| 283 |
my $unallocated = $params->{unallocated}; |
| 277 |
|
284 |
|
| 278 |
my $dbh = C4::Context->dbh; |
285 |
my $dbh = C4::Context->dbh; |
| 279 |
|
286 |
|
|
Lines 285-292
sub GetPendingHoldRequestsForBib {
Link Here
|
| 285 |
AND found IS NULL |
292 |
AND found IS NULL |
| 286 |
AND priority > 0 |
293 |
AND priority > 0 |
| 287 |
AND reservedate <= CURRENT_DATE() |
294 |
AND reservedate <= CURRENT_DATE() |
| 288 |
AND suspend = 0 |
295 |
AND suspend = 0 "; |
| 289 |
ORDER BY priority"; |
296 |
$request_query .= "AND reserve_id NOT IN (SELECT reserve_id FROM tmp_holdsqueue " if $unallocated; |
|
|
297 |
$request_query .= "ORDER BY priority"; |
| 290 |
my $sth = $dbh->prepare($request_query); |
298 |
my $sth = $dbh->prepare($request_query); |
| 291 |
$sth->execute($biblionumber); |
299 |
$sth->execute($biblionumber); |
| 292 |
|
300 |
|
|
Lines 343-351
sub GetItemsAvailableToFillHoldRequestsForBib {
Link Here
|
| 343 |
AND itemnumber IS NOT NULL |
351 |
AND itemnumber IS NOT NULL |
| 344 |
AND (found IS NOT NULL OR priority = 0) |
352 |
AND (found IS NOT NULL OR priority = 0) |
| 345 |
) |
353 |
) |
|
|
354 |
AND items.itemnumber NOT IN ( |
| 355 |
SELECT itemnumber |
| 356 |
FROM tmp_holdsqueue |
| 357 |
WHERE biblionumber = ? |
| 358 |
) |
| 346 |
AND items.biblionumber = ?"; |
359 |
AND items.biblionumber = ?"; |
| 347 |
|
360 |
|
| 348 |
my @params = ($biblionumber, $biblionumber); |
361 |
my @params = ($biblionumber, $biblionumber, $biblionumber); |
| 349 |
if ($branches_to_use && @$branches_to_use) { |
362 |
if ($branches_to_use && @$branches_to_use) { |
| 350 |
$items_query .= " AND holdingbranch IN (" . join (",", map { "?" } @$branches_to_use) . ")"; |
363 |
$items_query .= " AND holdingbranch IN (" . join (",", map { "?" } @$branches_to_use) . ")"; |
| 351 |
push @params, @$branches_to_use; |
364 |
push @params, @$branches_to_use; |
|
Lines 891-897
sub least_cost_branch {
Link Here
|
| 891 |
biblio_id => $biblio_id, |
904 |
biblio_id => $biblio_id, |
| 892 |
[ branches_to_use => $branches_to_use, |
905 |
[ branches_to_use => $branches_to_use, |
| 893 |
transport_cost_matrix => $transport_cost_matrix, |
906 |
transport_cost_matrix => $transport_cost_matrix, |
| 894 |
delete => $delete, ] |
907 |
delete => $delete, |
|
|
908 |
unallocated => $unallocated, ] |
| 895 |
} |
909 |
} |
| 896 |
); |
910 |
); |
| 897 |
|
911 |
|
|
Lines 922-927
It return a hashref containing:
Link Here
|
| 922 |
|
936 |
|
| 923 |
=item I<delete> tells the method to delete prior entries on the related tables for the biblio_id. |
937 |
=item I<delete> tells the method to delete prior entries on the related tables for the biblio_id. |
| 924 |
|
938 |
|
|
|
939 |
=item I<unallocated> tells the method to limit the holds to those not in the holds queue, should not |
| 940 |
be passed at the same time as delete. |
| 941 |
|
| 925 |
=back |
942 |
=back |
| 926 |
|
943 |
|
| 927 |
Note: All the optional parameters will be calculated in the method if omitted. They |
944 |
Note: All the optional parameters will be calculated in the method if omitted. They |
|
Lines 942-948
sub update_queue_for_biblio {
Link Here
|
| 942 |
$dbh->do("DELETE FROM hold_fill_targets WHERE biblionumber=$biblio_id"); |
959 |
$dbh->do("DELETE FROM hold_fill_targets WHERE biblionumber=$biblio_id"); |
| 943 |
} |
960 |
} |
| 944 |
|
961 |
|
| 945 |
my $hold_requests = GetPendingHoldRequestsForBib($biblio_id); |
962 |
my $hold_requests = GetPendingHoldRequestsForBib({ biblionumber => $biblio_id, unallocated => $args->{unallocated} }); |
| 946 |
$result->{requests} = scalar( @{$hold_requests} ); |
963 |
$result->{requests} = scalar( @{$hold_requests} ); |
| 947 |
# No need to check anything else if there are no holds to fill |
964 |
# No need to check anything else if there are no holds to fill |
| 948 |
return $result unless $result->{requests}; |
965 |
return $result unless $result->{requests}; |