View | Details | Raw Unified | Return to bug 29346
Collapse All | Expand All

(-)a/C4/HoldsQueue.pm (-19 / +97 lines)
Lines 44-49 BEGIN { Link Here
44
        TransportCostMatrix
44
        TransportCostMatrix
45
        UpdateTransportCostMatrix
45
        UpdateTransportCostMatrix
46
        GetPendingHoldRequestsForBib
46
        GetPendingHoldRequestsForBib
47
        load_branches_to_pull_from
48
        update_queue_for_biblio
47
     );
49
     );
48
}
50
}
49
51
Lines 204-230 sub CreateQueue { Link Here
204
    my $bibs_with_pending_requests = GetBibsWithPendingHoldRequests();
206
    my $bibs_with_pending_requests = GetBibsWithPendingHoldRequests();
205
207
206
    foreach my $biblionumber (@$bibs_with_pending_requests) {
208
    foreach my $biblionumber (@$bibs_with_pending_requests) {
209
207
        $total_bibs++;
210
        $total_bibs++;
208
        my $hold_requests   = GetPendingHoldRequestsForBib($biblionumber);
209
        my $available_items = GetItemsAvailableToFillHoldRequestsForBib($biblionumber, $branches_to_use);
210
        $total_requests        += scalar(@$hold_requests);
211
        $total_available_items += scalar(@$available_items);
212
211
213
        my $item_map = MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix);
212
        my $result = update_queue_for_biblio(
214
        $item_map  or next;
213
            {   biblio_id             => $biblionumber,
215
        my $item_map_size = scalar(keys %$item_map)
214
                branches_to_use       => $branches_to_use,
216
          or next;
215
                transport_cost_matrix => $transport_cost_matrix,
216
            }
217
        );
217
218
218
        $num_items_mapped += $item_map_size;
219
        $total_requests        += $result->{requests};
219
        CreatePicklistFromItemMap($item_map);
220
        $total_available_items += $result->{available_items};
220
        AddToHoldTargetMap($item_map);
221
        $num_items_mapped      += $result->{mapped_items};
221
        if (($item_map_size < scalar(@$hold_requests  )) and
222
            ($item_map_size < scalar(@$available_items))) {
223
            # DOUBLE CHECK, but this is probably OK - unfilled item-level requests
224
            # FIXME
225
            #warn "unfilled requests for $biblionumber";
226
            #warn Dumper($hold_requests), Dumper($available_items), Dumper($item_map);
227
        }
228
    }
222
    }
229
}
223
}
230
224
Lines 855-859 sub least_cost_branch { Link Here
855
    # return $branch[0] if @branch == 1;
849
    # return $branch[0] if @branch == 1;
856
}
850
}
857
851
852
=head3 update_queue_for_biblio
853
854
    my $result = update_queue_for_biblio(
855
        {
856
            biblio_id             => $biblio_id,
857
          [ branches_to_use       => $branches_to_use,
858
            transport_cost_matrix => $transport_cost_matrix,
859
            delete                => $delete, ]
860
        }
861
    );
862
863
Given a I<biblio_id>, this method calculates and sets the holds queue entries
864
for the biblio's holds, and the hold fill targets (items).
865
866
=head4 Return value
867
868
It return a hashref containing:
869
870
=over
871
872
=item I<requests>: the pending holds count for the biblio.
873
874
=item I<available_items> the count of items that are available to fill holds for the biblio.
875
876
=item I<mapped_items> the total items that got mapped.
877
878
=back
879
880
=head4 Optional parameters
881
882
=over
883
884
=item I<branches_to_use> a list of branchcodes to be used to restrict which items can be used.
885
886
=item I<transport_cost_matrix> is the output of C<TransportCostMatrix>.
887
888
=item I<delete> tells the method to delete prior entries on the related tables for the biblio_id.
889
890
=back
891
892
Note: All the optional parameters will be calculated in the method if omitted. They
893
are allowed to be passed to avoid calculating them many times inside loops.
894
895
=cut
896
897
sub update_queue_for_biblio {
898
    my ($args) = @_;
899
900
    my $biblio_id = $args->{biblio_id};
901
902
    my $branches_to_use = $args->{branches_to_use} // load_branches_to_pull_from( C4::Context->preference('UseTransportCostMatrix') );
903
    my $transport_cost_matrix;
904
905
    if ( !exists $args->{transport_cost_matrix}
906
        && C4::Context->preference('UseTransportCostMatrix') ) {
907
        $transport_cost_matrix = TransportCostMatrix();
908
    } else {
909
        $transport_cost_matrix = $args->{transport_cost_matrix};
910
    }
911
912
    if ( $args->{delete} ) {
913
        my $dbh = C4::Context->dbh;
914
915
        $dbh->do("DELETE FROM tmp_holdsqueue WHERE biblionumber=$biblio_id");
916
        $dbh->do("DELETE FROM hold_fill_targets WHERE biblionumber=$biblio_id");
917
    }
918
919
    my $hold_requests   = GetPendingHoldRequestsForBib($biblio_id);
920
    my $available_items = GetItemsAvailableToFillHoldRequestsForBib( $biblio_id, $branches_to_use );
921
922
    my $result = {
923
        requests        => scalar( @{$hold_requests} ),
924
        available_items => scalar( @{$available_items} ),
925
    };
926
927
    my $item_map = MapItemsToHoldRequests( $hold_requests, $available_items, $branches_to_use, $transport_cost_matrix );
928
    $result->{mapped_items} = scalar( keys %{$item_map} );
929
930
    if ($item_map) {
931
        CreatePicklistFromItemMap($item_map);
932
        AddToHoldTargetMap($item_map);
933
    }
934
935
    return $result;
936
}
858
937
859
1;
938
1;
860
- 

Return to bug 29346