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"
,r."Assn#"
,r."Coll#"
,r."AdvanceRate"
,r."Sales"
,r."Credits & Adjustments"
,r."Gross Collections"
,r."CollateralBalance"
,r."MaxEligible"
,r."Ineligible Amount"
,r."Reserve Amount"
,COALESCE(r."AdvanceRate",0) "AdvanceRate"
,COALESCE(r."Sales",0) "Sales"
,COALESCE(r."Credits & Adjustments",0) "Credits & Adjustments"
,COALESCE(r."Gross Collections",0) "Gross Collections"
,COALESCE(r."CollateralBalance",0) "CollateralBalance"
,COALESCE(r."MaxEligible",0) "MaxEligible"
,COALESCE(r."Ineligible Amount",0) "Ineligible Amount"
,COALESCE(r."Reserve Amount",0) "Reserve Amount"
FROM
tps.trans
JOIN LATERAL jsonb_populate_record(NULL::tps.pncl, rec) r ON TRUE
WHERE
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)

View File

@ -15,8 +15,8 @@
},
{
"type": "date",
"column_name": "PostDate",
"path": "{PostDate}"
"column_name": "Post Date",
"path": "{Post Date}"
},
{
"type": "text",

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