<link field="hold_pickup_lib" reltype="has_a" key="id" map="" class="aou"/>
<link field="hold_request_lib" reltype="has_a" key="id" map="" class="aou"/>
<link field="circ_mod" reltype="has_a" key="code" map="" class="ccm"/>
- <link field="copy_location" reltype="has_a" key="id" map="" class="acqpl"/>
+ <link field="copy_location" reltype="has_a" key="id" map="" class="acpl"/>
</links>
<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
<actions>
return unless ($cp && $org);
if ($hold) {
- return action::hold_request->db_Main->selectrow_hashref(
+ my $row = action::hold_request->db_Main->selectrow_hashref(
'SELECT proximity AS prox FROM action.hold_copy_map WHERE hold = ? and target_copy = ?',
{},
"$hold",
"$cp"
- )->{prox} || action::hold_request->db_Main->selectrow_hashref(
+ );
+ return $row->{prox} if $row;
+
+ $log->debug("Calculating copy proximity with: action.hold_copy_calculated_proximity($hold,$cp,$org)", DEBUG);
+ $row = action::hold_request->db_Main->selectrow_hashref(
'SELECT action.hold_copy_calculated_proximity(?,?,?) AS prox',
{},
"$hold",
"$cp",
"$org"
- )->{prox};
+ );
+
+ return $row->{prox} if $row;
}
$cp = asset::copy->retrieve($cp) unless (ref($cp));
id BIGSERIAL PRIMARY KEY,
hold INT NOT NULL REFERENCES action.hold_request (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
target_copy BIGINT NOT NULL, -- REFERENCES asset.copy (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, -- XXX could be an serial.issuance
+ proximity NUMERIC,
CONSTRAINT copy_once_per_hold UNIQUE (hold,target_copy)
);
-- CREATE INDEX acm_hold_idx ON action.hold_copy_map (hold);
SELECT * INTO acl FROM asset.copy_location WHERE id = acp.location;
-- First, gather the baseline proximity of "here" to pickup lib
- SELECT prox INTO baseline_prox FROM actor.org_unit_proximity WHERE from_org = context_ou AND to_org = ahr.pickup_lib;
+ SELECT prox INTO baseline_prox FROM actor.org_unit_proximity WHERE from_org = acp.circ_lib AND to_org = ahr.pickup_lib;
-- Find any absolute adjustments, and set the baseline prox to that
SELECT adj.* INTO aoupa
FROM actor.org_unit_proximity_adjustment adj
- LEFT JOIN actor.org_unit_anscestors_distance(acp.circ_lib) acp_cl ON (acp_cl.id = adj.item_circ_lib)
- LEFT JOIN actor.org_unit_anscestors_distance(acn.owning_lib) acn_ol ON (acn_ol.id = adj.item_owning_lib)
- LEFT JOIN actor.org_unit_anscestors_distance(acl.owning_lib) acl_ol ON (acn_ol.id = adj.copy_location)
- LEFT JOIN actor.org_unit_anscestors_distance(ahr.pickup_lib) ahr_pl ON (ahr_pl.id = adj.hold_pickup_lib)
- LEFT JOIN actor.org_unit_anscestors_distance(ahr.request_lib) ahr_rl ON (ahr_rl.id = adj.hold_request_lib)
+ LEFT JOIN actor.org_unit_ancestors_distance(acp.circ_lib) acp_cl ON (acp_cl.id = adj.item_circ_lib)
+ LEFT JOIN actor.org_unit_ancestors_distance(acn.owning_lib) acn_ol ON (acn_ol.id = adj.item_owning_lib)
+ LEFT JOIN actor.org_unit_ancestors_distance(acl.owning_lib) acl_ol ON (acn_ol.id = adj.copy_location)
+ LEFT JOIN actor.org_unit_ancestors_distance(ahr.pickup_lib) ahr_pl ON (ahr_pl.id = adj.hold_pickup_lib)
+ LEFT JOIN actor.org_unit_ancestors_distance(ahr.request_lib) ahr_rl ON (ahr_rl.id = adj.hold_request_lib)
WHERE (adj.circ_mod IS NULL OR adj.circ_mod = acp.circ_modifier) AND absolute_adjustment
ORDER BY
COALESCE(acp_cl.distance,999)
FOR aoupa IN
SELECT adj.*
FROM actor.org_unit_proximity_adjustment adj
- LEFT JOIN actor.org_unit_anscestors_distance(acp.circ_lib) acp_cl ON (acp_cl.id = adj.item_circ_lib)
- LEFT JOIN actor.org_unit_anscestors_distance(acn.owning_lib) acn_ol ON (acn_ol.id = adj.item_owning_lib)
- LEFT JOIN actor.org_unit_anscestors_distance(acl.owning_lib) acl_ol ON (acn_ol.id = adj.copy_location)
- LEFT JOIN actor.org_unit_anscestors_distance(ahr.pickup_lib) ahr_pl ON (ahr_pl.id = adj.hold_pickup_lib)
- LEFT JOIN actor.org_unit_anscestors_distance(ahr.request_lib) ahr_rl ON (ahr_rl.id = adj.hold_request_lib)
+ LEFT JOIN actor.org_unit_ancestors_distance(acp.circ_lib) acp_cl ON (acp_cl.id = adj.item_circ_lib)
+ LEFT JOIN actor.org_unit_ancestors_distance(acn.owning_lib) acn_ol ON (acn_ol.id = adj.item_owning_lib)
+ LEFT JOIN actor.org_unit_ancestors_distance(acl.owning_lib) acl_ol ON (acn_ol.id = adj.copy_location)
+ LEFT JOIN actor.org_unit_ancestors_distance(ahr.pickup_lib) ahr_pl ON (ahr_pl.id = adj.hold_pickup_lib)
+ LEFT JOIN actor.org_unit_ancestors_distance(ahr.request_lib) ahr_rl ON (ahr_rl.id = adj.hold_request_lib)
WHERE (adj.circ_mod IS NULL OR adj.circ_mod = acp.circ_modifier) AND NOT absolute_adjustment
LOOP
baseline_prox := baseline_prox + aoupa.prox_adjustment;
SELECT * INTO acl FROM asset.copy_location WHERE id = acp.location;
-- First, gather the baseline proximity of "here" to pickup lib
- SELECT prox INTO baseline_prox FROM actor.org_unit_proximity WHERE from_org = context_ou AND to_org = ahr.pickup_lib;
+ SELECT prox INTO baseline_prox FROM actor.org_unit_proximity WHERE from_org = acp.circ_lib AND to_org = ahr.pickup_lib;
-- Find any absolute adjustments, and set the baseline prox to that
SELECT adj.* INTO aoupa
FROM actor.org_unit_proximity_adjustment adj
- LEFT JOIN actor.org_unit_anscestors_distance(acp.circ_lib) acp_cl ON (acp_cl.id = adj.item_circ_lib)
- LEFT JOIN actor.org_unit_anscestors_distance(acn.owning_lib) acn_ol ON (acn_ol.id = adj.item_owning_lib)
- LEFT JOIN actor.org_unit_anscestors_distance(acl.owning_lib) acl_ol ON (acn_ol.id = adj.copy_location)
- LEFT JOIN actor.org_unit_anscestors_distance(ahr.pickup_lib) ahr_pl ON (ahr_pl.id = adj.hold_pickup_lib)
- LEFT JOIN actor.org_unit_anscestors_distance(ahr.request_lib) ahr_rl ON (ahr_rl.id = adj.hold_request_lib)
+ LEFT JOIN actor.org_unit_ancestors_distance(acp.circ_lib) acp_cl ON (acp_cl.id = adj.item_circ_lib)
+ LEFT JOIN actor.org_unit_ancestors_distance(acn.owning_lib) acn_ol ON (acn_ol.id = adj.item_owning_lib)
+ LEFT JOIN actor.org_unit_ancestors_distance(acl.owning_lib) acl_ol ON (acn_ol.id = adj.copy_location)
+ LEFT JOIN actor.org_unit_ancestors_distance(ahr.pickup_lib) ahr_pl ON (ahr_pl.id = adj.hold_pickup_lib)
+ LEFT JOIN actor.org_unit_ancestors_distance(ahr.request_lib) ahr_rl ON (ahr_rl.id = adj.hold_request_lib)
WHERE (adj.circ_mod IS NULL OR adj.circ_mod = acp.circ_modifier) AND absolute_adjustment
ORDER BY
COALESCE(acp_cl.distance,999)
FOR aoupa IN
SELECT adj.*
FROM actor.org_unit_proximity_adjustment adj
- LEFT JOIN actor.org_unit_anscestors_distance(acp.circ_lib) acp_cl ON (acp_cl.id = adj.item_circ_lib)
- LEFT JOIN actor.org_unit_anscestors_distance(acn.owning_lib) acn_ol ON (acn_ol.id = adj.item_owning_lib)
- LEFT JOIN actor.org_unit_anscestors_distance(acl.owning_lib) acl_ol ON (acn_ol.id = adj.copy_location)
- LEFT JOIN actor.org_unit_anscestors_distance(ahr.pickup_lib) ahr_pl ON (ahr_pl.id = adj.hold_pickup_lib)
- LEFT JOIN actor.org_unit_anscestors_distance(ahr.request_lib) ahr_rl ON (ahr_rl.id = adj.hold_request_lib)
+ LEFT JOIN actor.org_unit_ancestors_distance(acp.circ_lib) acp_cl ON (acp_cl.id = adj.item_circ_lib)
+ LEFT JOIN actor.org_unit_ancestors_distance(acn.owning_lib) acn_ol ON (acn_ol.id = adj.item_owning_lib)
+ LEFT JOIN actor.org_unit_ancestors_distance(acl.owning_lib) acl_ol ON (acn_ol.id = adj.copy_location)
+ LEFT JOIN actor.org_unit_ancestors_distance(ahr.pickup_lib) ahr_pl ON (ahr_pl.id = adj.hold_pickup_lib)
+ LEFT JOIN actor.org_unit_ancestors_distance(ahr.request_lib) ahr_rl ON (ahr_rl.id = adj.hold_request_lib)
WHERE (adj.circ_mod IS NULL OR adj.circ_mod = acp.circ_modifier) AND NOT absolute_adjustment
LOOP
baseline_prox := baseline_prox + aoupa.prox_adjustment;
FOREIGN KEY (circ_mod) REFERENCES config.circ_modifier (code)
DEFERRABLE INITIALLY DEFERRED;
+ALTER TABLE action.hold_copy_map ADD COLUMN proximity NUMERIC;
+
COMMIT;