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 226-231
sub GetBibsWithPendingHoldRequests {
Link Here
|
226 |
AND priority > 0 |
231 |
AND priority > 0 |
227 |
AND reservedate <= CURRENT_DATE() |
232 |
AND reservedate <= CURRENT_DATE() |
228 |
AND suspend = 0 |
233 |
AND suspend = 0 |
|
|
234 |
AND reserve_id NOT IN (SELECT reserve_id FROM hold_fill_targets) |
229 |
"; |
235 |
"; |
230 |
my $sth = $dbh->prepare($bib_query); |
236 |
my $sth = $dbh->prepare($bib_query); |
231 |
|
237 |
|
Lines 237-246
sub GetBibsWithPendingHoldRequests {
Link Here
|
237 |
|
243 |
|
238 |
=head2 GetPendingHoldRequestsForBib |
244 |
=head2 GetPendingHoldRequestsForBib |
239 |
|
245 |
|
240 |
my $requests = GetPendingHoldRequestsForBib($biblionumber); |
246 |
my $requests = GetPendingHoldRequestsForBib({ biblionumber => $biblionumber, unallocated => $unallocated }); |
241 |
|
247 |
|
242 |
Returns an arrayref of hashrefs to pending, unfilled hold requests |
248 |
Returns an arrayref of hashrefs to pending, unfilled hold requests |
243 |
on the bib identified by $biblionumber. The following keys |
249 |
on the bib identified by $biblionumber. Optionally returns only unallocated holds. The following keys |
244 |
are present in each hashref: |
250 |
are present in each hashref: |
245 |
|
251 |
|
246 |
biblionumber |
252 |
biblionumber |
Lines 257-263
The arrayref is sorted in order of increasing priority.
Link Here
|
257 |
=cut |
263 |
=cut |
258 |
|
264 |
|
259 |
sub GetPendingHoldRequestsForBib { |
265 |
sub GetPendingHoldRequestsForBib { |
260 |
my $biblionumber = shift; |
266 |
my $params = shift; |
|
|
267 |
my $biblionumber = $params->{biblionumber}; |
268 |
my $unallocated = $params->{unallocated}; |
261 |
|
269 |
|
262 |
my $dbh = C4::Context->dbh; |
270 |
my $dbh = C4::Context->dbh; |
263 |
|
271 |
|
Lines 269-276
sub GetPendingHoldRequestsForBib {
Link Here
|
269 |
AND found IS NULL |
277 |
AND found IS NULL |
270 |
AND priority > 0 |
278 |
AND priority > 0 |
271 |
AND reservedate <= CURRENT_DATE() |
279 |
AND reservedate <= CURRENT_DATE() |
272 |
AND suspend = 0 |
280 |
AND suspend = 0 "; |
273 |
ORDER BY priority"; |
281 |
$request_query .= "AND reserve_id NOT IN (SELECT reserve_id FROM hold_fill_targets) " if $unallocated; |
|
|
282 |
$request_query .= "ORDER BY priority"; |
274 |
my $sth = $dbh->prepare($request_query); |
283 |
my $sth = $dbh->prepare($request_query); |
275 |
$sth->execute($biblionumber); |
284 |
$sth->execute($biblionumber); |
276 |
|
285 |
|
Lines 328-337
sub GetItemsAvailableToFillHoldRequestsForBib {
Link Here
|
328 |
AND itemnumber IS NOT NULL |
337 |
AND itemnumber IS NOT NULL |
329 |
AND (found IS NOT NULL OR priority = 0) |
338 |
AND (found IS NOT NULL OR priority = 0) |
330 |
) |
339 |
) |
|
|
340 |
AND items.itemnumber NOT IN ( |
341 |
SELECT itemnumber |
342 |
FROM tmp_holdsqueue |
343 |
WHERE biblionumber = ? |
344 |
) |
331 |
AND items.biblionumber = ? |
345 |
AND items.biblionumber = ? |
332 |
AND branchtransfers.itemnumber IS NULL"; |
346 |
AND branchtransfers.itemnumber IS NULL"; |
333 |
|
347 |
|
334 |
my @params = ($biblionumber, $biblionumber); |
348 |
my @params = ($biblionumber, $biblionumber, $biblionumber); |
335 |
if ($branches_to_use && @$branches_to_use) { |
349 |
if ($branches_to_use && @$branches_to_use) { |
336 |
$items_query .= " AND holdingbranch IN (" . join (",", map { "?" } @$branches_to_use) . ")"; |
350 |
$items_query .= " AND holdingbranch IN (" . join (",", map { "?" } @$branches_to_use) . ")"; |
337 |
push @params, @$branches_to_use; |
351 |
push @params, @$branches_to_use; |
Lines 870-876
sub least_cost_branch {
Link Here
|
870 |
biblio_id => $biblio_id, |
884 |
biblio_id => $biblio_id, |
871 |
[ branches_to_use => $branches_to_use, |
885 |
[ branches_to_use => $branches_to_use, |
872 |
transport_cost_matrix => $transport_cost_matrix, |
886 |
transport_cost_matrix => $transport_cost_matrix, |
873 |
delete => $delete, ] |
887 |
delete => $delete, |
|
|
888 |
unallocated => $unallocated, ] |
874 |
} |
889 |
} |
875 |
); |
890 |
); |
876 |
|
891 |
|
Lines 901-906
It return a hashref containing:
Link Here
|
901 |
|
916 |
|
902 |
=item I<delete> tells the method to delete prior entries on the related tables for the biblio_id. |
917 |
=item I<delete> tells the method to delete prior entries on the related tables for the biblio_id. |
903 |
|
918 |
|
|
|
919 |
=item I<unallocated> tells the method to limit the holds to those not in the holds queue, should not |
920 |
be passed at the same time as delete. |
921 |
|
904 |
=back |
922 |
=back |
905 |
|
923 |
|
906 |
Note: All the optional parameters will be calculated in the method if omitted. They |
924 |
Note: All the optional parameters will be calculated in the method if omitted. They |
Lines 921-927
sub update_queue_for_biblio {
Link Here
|
921 |
$dbh->do("DELETE FROM hold_fill_targets WHERE biblionumber=$biblio_id"); |
939 |
$dbh->do("DELETE FROM hold_fill_targets WHERE biblionumber=$biblio_id"); |
922 |
} |
940 |
} |
923 |
|
941 |
|
924 |
my $hold_requests = GetPendingHoldRequestsForBib($biblio_id); |
942 |
my $hold_requests = GetPendingHoldRequestsForBib({ biblionumber => $biblio_id, unallocated => $args->{unallocated} }); |
925 |
$result->{requests} = scalar( @{$hold_requests} ); |
943 |
$result->{requests} = scalar( @{$hold_requests} ); |
926 |
# No need to check anything else if there are no holds to fill |
944 |
# No need to check anything else if there are no holds to fill |
927 |
return $result unless $result->{requests}; |
945 |
return $result unless $result->{requests}; |