loan pncl

This commit is contained in:
Paul Trowbridge 2018-05-30 13:27:01 -04:00
parent 9d5a69c891
commit 02e6b761b4
3 changed files with 30 additions and 10 deletions

View File

@ -7,19 +7,20 @@ SELECT
,to_char(r."PostDate",'mm/dd/yyyy') "Post Date" ,to_char(r."PostDate",'mm/dd/yyyy') "Post Date"
,r."Assn#" ,r."Assn#"
,r."Coll#" ,r."Coll#"
,r."AdvanceRate" ,COALESCE(r."AdvanceRate",0) "AdvanceRate"
,r."Sales" ,COALESCE(r."Sales",0) "Sales"
,r."Credits & Adjustments" ,COALESCE(r."Credits & Adjustments",0) "Credits & Adjustments"
,r."Gross Collections" ,COALESCE(r."Gross Collections",0) "Gross Collections"
,r."CollateralBalance" ,COALESCE(r."CollateralBalance",0) "CollateralBalance"
,r."MaxEligible" ,COALESCE(r."MaxEligible",0) "MaxEligible"
,r."Ineligible Amount" ,COALESCE(r."Ineligible Amount",0) "Ineligible Amount"
,r."Reserve Amount" ,COALESCE(r."Reserve Amount",0) "Reserve Amount"
FROM FROM
tps.trans tps.trans
JOIN LATERAL jsonb_populate_record(NULL::tps.pncl, rec) r ON TRUE JOIN LATERAL jsonb_populate_record(NULL::tps.pncl, rec) r ON TRUE
WHERE WHERE
srce = 'PNCL' srce = 'PNCL'
--and case when rec->>'Credits & Adjustments' is null then 'null' else '' end <> 'null'
) )
TO 'C:\users\ptrowbridge\downloads\pncl.csv' WITH (format csv, header TRUE) TO 'C:\users\ptrowbridge\downloads\pncl.csv' WITH (format csv, header TRUE)

View File

@ -0,0 +1,19 @@
SELECT
r.*
,CASE "Schedule#"
WHEN '02IN Raw Material' THEN 13097563.42
WHEN '03IN Finished Goods' THEN 35790696.52
ELSE 0
END + SUM("Sales"+"Credits & Adjustments"-"Gross Collections") OVER (PARTITION BY "Schedule#" ORDER BY "Schedule#" ASC, "Post Date" ASC) running_bal
,(LEAST("CollateralBalance" - "Ineligible Amount","MaxEligible")*("AdvanceRate"/100))::NUMERIC(20,2) qualified_collateral
,(("CollateralBalance" - "Ineligible Amount")*("AdvanceRate"/100))::NUMERIC(20,2) qualified_collateral_nl
FROM
tpsv.pncl_default r
WHERE
--AND rec @> '{"Schedule#":"01AR"}'
--AND rec @> '{"Schedule#":"02IN Raw Material"}'
"Schedule#" = '03IN Finished Goods'
ORDER BY
"Schedule#" asc
,r."Post Date" asc