pipekit/config/modules/vchr.sql
Paul Trowbridge d0e72e270f Add the CMS AP subledger modules (avtx, vchr, open)
Completes the AP source layer: GP was covered by the pm* modules, but the
CMS side had only cms.vend. These three are what
SQL/fiscal/analysis/open_ap_aging.db2.sql actually joins.

  avtx  966,553  A/P voucher transaction events   incremental on AVTSTM
  vchr  792,348  vouchers entered, period to date full
  open  538,544  open payables; FHCBAL is live    full

AVTX is the artrn analog -- the per-event apply detail. It matters
because the AR aging in /opt/clean reconstructs balances from
application events rather than a single settle_date, so AP needs an
applications fact too, not just documents.

Grains verified exactly unique before drafting: AVTX
(avtco#,avtvh#,avttx#) 966,553/966,553; VCHR
(idcom#,idvch#,idbnk#,idfisy,idfisp) 792,348/792,348; OPEN
(fhcom#,fhvch#,fhpyy,fhpper) 538,544/538,544. All three reconcile
IN SYNC.

vchr and open stay full: no change signal, only business dates, and
FHCBAL is a live mutable balance.

Two things worth knowing for the next DB2 module:

- pipekit maps DB2 TIMESTMP to Postgres text, so a watermark resolver
  doing COALESCE(MAX(ts), TIMESTAMP '...') fails on mismatched types.
  Cast explicitly. cms.gtran was already the precedent.
- Watermarks resolve at engine step 2 but --create-dest builds the
  table at step 3b, so a watermark reading its own dest table fails on
  the first run. Pre-create the table or seed with a constant.

Note LGDAT.AP* is a dead end -- APVH has 14 rows, APVD has 22. CMS AP
does not live in AP-prefixed files.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 01:05:34 -04:00

40 lines
1.2 KiB
SQL

SELECT
RTRIM("IDBNK#") AS idbnk#,
RTRIM(IDA5) AS ida5,
"IDCOM#" AS idcom#,
"IDVCH#" AS idvch#,
"IDMCH#" AS idmch#,
RTRIM(IDIDAT) AS ididat,
IDGROS AS idgros,
IDDISC AS iddisc,
IDDISP AS iddisp,
RTRIM(IDDSDT) AS iddsdt,
RTRIM(IDA1) AS ida1,
RTRIM("IDVEN#") AS idven#,
RTRIM(IDVDES) AS idvdes,
RTRIM("IDINV#") AS idinv#,
RTRIM(IDA8) AS ida8,
IDFISP AS idfisp,
IDGSTA AS idgsta,
IDGSTX AS idgstx,
IDFISY AS idfisy,
"IDADR#" AS idadr#,
CASE WHEN IDDATE IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE IDDATE END AS iddate,
CASE WHEN IDDDAT IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE IDDDAT END AS idddat,
CASE WHEN IDIRDT IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE IDIRDT END AS idirdt,
RTRIM(IDCVRS) AS idcvrs,
RTRIM(IDCMT1) AS idcmt1,
RTRIM(IDCMT2) AS idcmt2,
RTRIM(IDCMT3) AS idcmt3,
IDMISA AS idmisa,
CASE WHEN IDUDDT IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE IDUDDT END AS iduddt,
RTRIM(IDFUT1) AS idfut1,
RTRIM(IDFUT2) AS idfut2,
IDFUT3 AS idfut3,
IDFUT4 AS idfut4,
RTRIM(IDFUT5) AS idfut5,
RTRIM(IDFUT6) AS idfut6,
RTRIM(IDFUT7) AS idfut7,
RTRIM(IDFUT8) AS idfut8
FROM LGDAT.VCHR