Lines 166-175
Top level function that turns reserves into tmp_holdsqueue and hold_fill_targets
Link Here
|
166 |
=cut |
166 |
=cut |
167 |
|
167 |
|
168 |
sub CreateQueue { |
168 |
sub CreateQueue { |
|
|
169 |
my $params = shift; |
170 |
my $unallocated = $params->{unallocated}; |
169 |
my $dbh = C4::Context->dbh; |
171 |
my $dbh = C4::Context->dbh; |
170 |
|
172 |
|
171 |
$dbh->do("DELETE FROM tmp_holdsqueue"); # clear the old table for new info |
173 |
unless( $unallocated ){ |
172 |
$dbh->do("DELETE FROM hold_fill_targets"); |
174 |
$dbh->do("DELETE FROM tmp_holdsqueue"); # clear the old table for new info |
|
|
175 |
$dbh->do("DELETE FROM hold_fill_targets"); |
176 |
} |
173 |
|
177 |
|
174 |
my $total_bibs = 0; |
178 |
my $total_bibs = 0; |
175 |
my $total_requests = 0; |
179 |
my $total_requests = 0; |
Lines 199-204
sub CreateQueue {
Link Here
|
199 |
{ biblio_id => $biblionumber, |
203 |
{ biblio_id => $biblionumber, |
200 |
branches_to_use => $branches_to_use, |
204 |
branches_to_use => $branches_to_use, |
201 |
transport_cost_matrix => $transport_cost_matrix, |
205 |
transport_cost_matrix => $transport_cost_matrix, |
|
|
206 |
unallocated => $unallocated |
202 |
} |
207 |
} |
203 |
); |
208 |
); |
204 |
|
209 |
|
Lines 237-246
sub GetBibsWithPendingHoldRequests {
Link Here
|
237 |
|
242 |
|
238 |
=head2 GetPendingHoldRequestsForBib |
243 |
=head2 GetPendingHoldRequestsForBib |
239 |
|
244 |
|
240 |
my $requests = GetPendingHoldRequestsForBib($biblionumber); |
245 |
my $requests = GetPendingHoldRequestsForBib({ biblionumber => $biblionumber, unallocated => $unallocated }); |
241 |
|
246 |
|
242 |
Returns an arrayref of hashrefs to pending, unfilled hold requests |
247 |
Returns an arrayref of hashrefs to pending, unfilled hold requests |
243 |
on the bib identified by $biblionumber. The following keys |
248 |
on the bib identified by $biblionumber. Optionally returns only unallocated holds. The following keys |
244 |
are present in each hashref: |
249 |
are present in each hashref: |
245 |
|
250 |
|
246 |
biblionumber |
251 |
biblionumber |
Lines 257-263
The arrayref is sorted in order of increasing priority.
Link Here
|
257 |
=cut |
262 |
=cut |
258 |
|
263 |
|
259 |
sub GetPendingHoldRequestsForBib { |
264 |
sub GetPendingHoldRequestsForBib { |
260 |
my $biblionumber = shift; |
265 |
my $params = shift; |
|
|
266 |
my $biblionumber = $params->{biblionumber}; |
267 |
my $unallocated = $params->{unallocated}; |
261 |
|
268 |
|
262 |
my $dbh = C4::Context->dbh; |
269 |
my $dbh = C4::Context->dbh; |
263 |
|
270 |
|
Lines 269-276
sub GetPendingHoldRequestsForBib {
Link Here
|
269 |
AND found IS NULL |
276 |
AND found IS NULL |
270 |
AND priority > 0 |
277 |
AND priority > 0 |
271 |
AND reservedate <= CURRENT_DATE() |
278 |
AND reservedate <= CURRENT_DATE() |
272 |
AND suspend = 0 |
279 |
AND suspend = 0 "; |
273 |
ORDER BY priority"; |
280 |
$request_query .= "AND reserve_id NOT IN (SELECT reserve_id FROM tmp_holdsqueue " if $unallocated; |
|
|
281 |
$request_query .= "ORDER BY priority"; |
274 |
my $sth = $dbh->prepare($request_query); |
282 |
my $sth = $dbh->prepare($request_query); |
275 |
$sth->execute($biblionumber); |
283 |
$sth->execute($biblionumber); |
276 |
|
284 |
|
Lines 328-337
sub GetItemsAvailableToFillHoldRequestsForBib {
Link Here
|
328 |
AND itemnumber IS NOT NULL |
336 |
AND itemnumber IS NOT NULL |
329 |
AND (found IS NOT NULL OR priority = 0) |
337 |
AND (found IS NOT NULL OR priority = 0) |
330 |
) |
338 |
) |
|
|
339 |
AND items.itemnumber NOT IN ( |
340 |
SELECT itemnumber |
341 |
FROM tmp_holdsqueue |
342 |
WHERE biblionumber = ? |
343 |
) |
331 |
AND items.biblionumber = ? |
344 |
AND items.biblionumber = ? |
332 |
AND branchtransfers.itemnumber IS NULL"; |
345 |
AND branchtransfers.itemnumber IS NULL"; |
333 |
|
346 |
|
334 |
my @params = ($biblionumber, $biblionumber); |
347 |
my @params = ($biblionumber, $biblionumber, $biblionumber); |
335 |
if ($branches_to_use && @$branches_to_use) { |
348 |
if ($branches_to_use && @$branches_to_use) { |
336 |
$items_query .= " AND holdingbranch IN (" . join (",", map { "?" } @$branches_to_use) . ")"; |
349 |
$items_query .= " AND holdingbranch IN (" . join (",", map { "?" } @$branches_to_use) . ")"; |
337 |
push @params, @$branches_to_use; |
350 |
push @params, @$branches_to_use; |
Lines 885-891
sub least_cost_branch {
Link Here
|
885 |
biblio_id => $biblio_id, |
898 |
biblio_id => $biblio_id, |
886 |
[ branches_to_use => $branches_to_use, |
899 |
[ branches_to_use => $branches_to_use, |
887 |
transport_cost_matrix => $transport_cost_matrix, |
900 |
transport_cost_matrix => $transport_cost_matrix, |
888 |
delete => $delete, ] |
901 |
delete => $delete, |
|
|
902 |
unallocated => $unallocated, ] |
889 |
} |
903 |
} |
890 |
); |
904 |
); |
891 |
|
905 |
|
Lines 916-921
It return a hashref containing:
Link Here
|
916 |
|
930 |
|
917 |
=item I<delete> tells the method to delete prior entries on the related tables for the biblio_id. |
931 |
=item I<delete> tells the method to delete prior entries on the related tables for the biblio_id. |
918 |
|
932 |
|
|
|
933 |
=item I<unallocated> tells the method to limit the holds to those not in the holds queue, should not |
934 |
be passed at the same time as delete. |
935 |
|
919 |
=back |
936 |
=back |
920 |
|
937 |
|
921 |
Note: All the optional parameters will be calculated in the method if omitted. They |
938 |
Note: All the optional parameters will be calculated in the method if omitted. They |
Lines 936-942
sub update_queue_for_biblio {
Link Here
|
936 |
$dbh->do("DELETE FROM hold_fill_targets WHERE biblionumber=$biblio_id"); |
953 |
$dbh->do("DELETE FROM hold_fill_targets WHERE biblionumber=$biblio_id"); |
937 |
} |
954 |
} |
938 |
|
955 |
|
939 |
my $hold_requests = GetPendingHoldRequestsForBib($biblio_id); |
956 |
my $hold_requests = GetPendingHoldRequestsForBib({ biblionumber => $biblio_id, unallocated => $args->{unallocated} }); |
940 |
$result->{requests} = scalar( @{$hold_requests} ); |
957 |
$result->{requests} = scalar( @{$hold_requests} ); |
941 |
# No need to check anything else if there are no holds to fill |
958 |
# No need to check anything else if there are no holds to fill |
942 |
return $result unless $result->{requests}; |
959 |
return $result unless $result->{requests}; |