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>
39 lines
1.0 KiB
SQL
39 lines
1.0 KiB
SQL
SELECT
|
|
"AVTCO#" AS avtco#,
|
|
"AVTVH#" AS avtvh#,
|
|
"AVTTX#" AS avttx#,
|
|
CASE WHEN AVTTDT IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE AVTTDT END AS avttdt,
|
|
RTRIM(AVTTYP) AS avttyp,
|
|
RTRIM(AVT1099) AS avt1099,
|
|
AVTSTM AS avtstm,
|
|
AVTFIS AS avtfis,
|
|
AVTAMT AS avtamt,
|
|
RTRIM(AVTCCD) AS avtccd,
|
|
AVTVAM AS avtvam,
|
|
RTRIM(AVTVCC) AS avtvcc,
|
|
AVTDIS AS avtdis,
|
|
AVTEXC AS avtexc,
|
|
AVTCHC AS avtchc,
|
|
RTRIM(AVTCHB) AS avtchb,
|
|
AVTCHQ AS avtchq,
|
|
RTRIM(AVTEFT) AS avteft,
|
|
AVTOBL AS avtobl,
|
|
RTRIM(AVTUSR) AS avtusr,
|
|
AVTEXCP AS avtexcp,
|
|
AVTHQEXCP AS avthqexcp,
|
|
AVTEXCM AS avtexcm,
|
|
AVTOEX AS avtoex,
|
|
CASE WHEN AVTIRDT IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE AVTIRDT END AS avtirdt,
|
|
AVTDSNT AS avtdsnt,
|
|
AVTGSTD AS avtgstd,
|
|
RTRIM(AVTFUT1) AS avtfut1,
|
|
RTRIM(AVTFUT2) AS avtfut2,
|
|
AVTFUT3 AS avtfut3,
|
|
AVTFUT4 AS avtfut4,
|
|
RTRIM(AVTFUT5) AS avtfut5,
|
|
RTRIM(AVTFUT6) AS avtfut6,
|
|
RTRIM(AVTFUT7) AS avtfut7,
|
|
RTRIM(AVTFUT8) AS avtfut8
|
|
FROM LGDAT.AVTX
|
|
WHERE AVTSTM > '{avtx_wm}'
|