Computes, per source document, how much quantity per item has already been committed to non-deleted downstream documents referencing it — used so that selecting the same source into a second (or later) document only adds what's still outstanding, instead of duplicating the full original quantity.
Summary
Functions
Returns %{source_uuid => %{item_uuid => Decimal}} — for each uuid in
source_uuids, the quantity already committed against it, summed across all
non-deleted rows of schema whose source_refs contain a ref whose "type"
is in ref_types and whose "uuid" matches.
Merges a {ref_type, source_uuid} ref carrying imported_lines
(%{item_uuid => Decimal}) into existing_refs. If a ref for that
{ref_type, source_uuid} pair already exists, its "lines" map is summed
with imported_lines in place — never skipped, never replaced — so the
ref's "lines" always reflects the running cumulative total ever pulled
from that source into this document.
Functions
Returns %{source_uuid => %{item_uuid => Decimal}} — for each uuid in
source_uuids, the quantity already committed against it, summed across all
non-deleted rows of schema whose source_refs contain a ref whose "type"
is in ref_types and whose "uuid" matches.
For refs recorded with a "lines" breakdown, uses that breakdown exactly.
For legacy refs without one, falls back to attributing the document's own
aggregate lines (keyed by line_quantity_field) to that ref — a safe
overcount for the rare pre-existing multi-source merge.
Merges a {ref_type, source_uuid} ref carrying imported_lines
(%{item_uuid => Decimal}) into existing_refs. If a ref for that
{ref_type, source_uuid} pair already exists, its "lines" map is summed
with imported_lines in place — never skipped, never replaced — so the
ref's "lines" always reflects the running cumulative total ever pulled
from that source into this document.