From f203c7010a8a00a94b4a2e9d3c2c300608ede8db Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 19 Oct 2017 13:10:36 -0400 Subject: [PATCH] add calc columns to collateral --- col_balance.pgsql | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/col_balance.pgsql b/col_balance.pgsql index ee2ada9..09e726a 100644 --- a/col_balance.pgsql +++ b/col_balance.pgsql @@ -1,17 +1,21 @@ SELECT - id, - rec->>'id', - r.*, - CASE "Schedule#" + id + ,rec->>'id' + ,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 (ORDER BY "PostDate" ASC, rec->>'id' ASC) + END + SUM("Sales"+"Credits & Adjustments"-"Gross Collections") OVER (ORDER BY "PostDate" ASC, rec->>'id' 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 tps.trans LEFT JOIN LATERAL jsonb_populate_record(null::tps.pncl, rec) r ON TRUE WHERE - rec @> '{"Schedule#":"01AR"}' + srce = 'PNCL' + AND "PostDate" >= '2017-10-12' + --rec @> '{"Schedule#":"03IN Finished Goods"}' ORDER BY r."PostDate" asc \ No newline at end of file