From 3f038d959228f87983f1ce355b95bbf453100605 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 30 May 2018 10:44:41 -0400 Subject: [PATCH] load pnco --- reload/pnco/extract.sql | 32 +++++++++++++++++++++ reload/pnco/load.cmd | 2 ++ reload/pnco/srce.json | 60 ++++++++++++++++++++++++++++++++++++++++ reports/loan_balance.sql | 12 ++++++++ 4 files changed, 106 insertions(+) create mode 100644 reload/pnco/extract.sql create mode 100644 reload/pnco/load.cmd create mode 100644 reload/pnco/srce.json create mode 100644 reports/loan_balance.sql diff --git a/reload/pnco/extract.sql b/reload/pnco/extract.sql new file mode 100644 index 0000000..fee80bf --- /dev/null +++ b/reload/pnco/extract.sql @@ -0,0 +1,32 @@ +--transactions with date in download format for constraint +--transactions with date in download format for constraint +COPY +( +SELECT + r."Loan#" + ,to_char(r."Post Date",'mm/dd/yyyy') "Post Date" + ,to_char(r."Effective Date",'mm/dd/yyyy') "Effective Date" + ,r."Reference #" + ,r."Description" + ,r."Advances" + ,r."Adjustments" + ,r."Payments" + ,r."Loan Balance" +FROM + tps.trans + JOIN LATERAL jsonb_populate_record(NULL::tps.pnco, rec) r ON TRUE +WHERE + srce = 'PNCO' +) +TO 'C:\users\ptrowbridge\downloads\pnco.csv' WITH (format csv, header TRUE) + +--source +SELECT DEFN FROM TPS.SRCE WHERE SRCE = 'PNCO' + +--mapdef +SELECT jsonb_agg(row_to_json(x)::jsonb) FROM (SELECT srce, target "name", regex, seq "sequence" FROM tps.map_rm WHERE srce = 'PNCO') x + +--map values +SELECT jsonb_agg(row_to_JSON(x)::jsonb) FROM (SELECT srce "source", target "map", retval ret_val, "map" mapped FROM tps.map_rv WHERE srce = 'PNCO') X + + diff --git a/reload/pnco/load.cmd b/reload/pnco/load.cmd new file mode 100644 index 0000000..b2a09e4 --- /dev/null +++ b/reload/pnco/load.cmd @@ -0,0 +1,2 @@ +curl -H "Content-Type: application/json" -X POST -d@./srce.json http://localhost:81/srce_set +curl -v -F upload=@//mnt/c/Users/ptrowbridge/Downloads/pnco.csv http://localhost:81/import?srce=PNCO \ No newline at end of file diff --git a/reload/pnco/srce.json b/reload/pnco/srce.json new file mode 100644 index 0000000..28b948a --- /dev/null +++ b/reload/pnco/srce.json @@ -0,0 +1,60 @@ +{ + "name": "PNCO", + "source": "client_file", + "loading_function": "csv", + "constraint": [ + "{Post Date}", + "{Effective Date}", + "{Loan#}", + "{Reference #}" + ], + "schemas": { + "default": [ + { + "path": "{Loan#}", + "type": "text", + "column_name":"Loan#" + }, + { + "path": "{Post Date}", + "type": "date", + "column_name":"Post Date" + }, + { + "path": "{Effective Date}", + "type": "date", + "column_name":"Effective Date" + }, + { + "path": "{Reference #}", + "type": "text", + "column_name":"Reference #" + }, + { + "path": "{Description}", + "type": "text", + "column_name":"Description" + }, + { + "path": "{Advances}", + "type": "numeric", + "column_name":"Advances" + }, + { + "path": "{Adjustments}", + "type": "numeric", + "column_name":"Adjustments" + }, + { + "path": "{Payments}", + "type": "numeric", + "column_name":"Payments" + }, + { + "path": "{Loan Balance}", + "type": "numeric", + "column_name":"Loan Balance" + } + ] + } +} \ No newline at end of file diff --git a/reports/loan_balance.sql b/reports/loan_balance.sql new file mode 100644 index 0000000..8ad0496 --- /dev/null +++ b/reports/loan_balance.sql @@ -0,0 +1,12 @@ +\timing +SELECT + r.*, + SUM(r."Advances"+r."Adjustments"-r."Payments") OVER (PARTITION BY "Loan#" ORDER BY r."Post Date" asc, r."Reference #" asc) +FROM + tpsv.pnco_default r +WHERE + "Loan#" = '606780191' +ORDER BY + r."Loan#" + ,r."Post Date" ASC + ,r."Reference #" ASC \ No newline at end of file