From 02e6b761b471a909099ce0bdb861d9f1bbe95a9f Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 30 May 2018 13:27:01 -0400 Subject: [PATCH] loan pncl --- reload/pncl/extract.sql | 17 +++++++++-------- reload/pncl/srce.json | 4 ++-- reports/colateral_balalance.sql | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 reports/colateral_balalance.sql diff --git a/reload/pncl/extract.sql b/reload/pncl/extract.sql index 0d3a6d7..d9b58d1 100644 --- a/reload/pncl/extract.sql +++ b/reload/pncl/extract.sql @@ -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) diff --git a/reload/pncl/srce.json b/reload/pncl/srce.json index fffd0de..718196a 100644 --- a/reload/pncl/srce.json +++ b/reload/pncl/srce.json @@ -15,8 +15,8 @@ }, { "type": "date", - "column_name": "PostDate", - "path": "{PostDate}" + "column_name": "Post Date", + "path": "{Post Date}" }, { "type": "text", diff --git a/reports/colateral_balalance.sql b/reports/colateral_balalance.sql new file mode 100644 index 0000000..b25b144 --- /dev/null +++ b/reports/colateral_balalance.sql @@ -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 \ No newline at end of file