drop bunch of fiels

This commit is contained in:
Paul Trowbridge 2018-02-05 23:04:36 -05:00
parent 545ba4e2b5
commit de095017b1
12 changed files with 0 additions and 3436 deletions

Binary file not shown.

View File

@ -1,12 +0,0 @@
event log
collection of dissimilar items
-> trigger based on insert adds to GL
-> gl adds to balance based on GL trigger
? how is fiscal period determined
log gl format
* the gl array is an array of object
* each gl line is initially a full json object
* extract demanded fields (account, amount) and delete from the json but retain the rest as the supporting items

View File

@ -1,33 +0,0 @@
WITH
x AS (
SELECT
$$
{"vendor":"Drug Mart","date":"2017-08-20","instrument":"Discover Card","item":[{"item":"Green Chili","amount":1.49},{"item":"Black Beans","amount":1.6},{"item":"Distilled Water","amount":7.12},{"item":"Fruit Preservative","amount":3.99},{"item":"Watch Battery","amount":3.79},{"item":"Sales Tax","amount":"0.26"}],"account":[{"account":"food","offset":"dcard","amount":1.49},{"account":"food","offset":"dcard","amount":1.6},{"account":"food","offset":"dcard","amount":7.12},{"account":"food","offset":"dcard","amount":3.99},{"account":"stuff","offset":"dcard","amount":3.79},{"account":"taxes","offset":"dcard","amount":"0.26"}]}
$$::jsonb j
),
acct AS (
SELECT
rs.*,
row_number() over() rn
FROM
x
JOIN LATERAL jsonb_to_recordset(x.j->'account') rs(account text,"offset" text, amount numeric) ON TRUE
),
item as (
SELECT
rs.*,
row_number() over() rn
FROM
x
JOIN LATERAL jsonb_to_recordset(x.j->'item') rs(item text, amount numeric) ON TRUE
)
SELECT
item.*,
acct.*,
r.*
FROM
item
INNER JOIN acct ON
acct.rn = item.rn
CROSS JOIN x
JOIN LATERAL jsonb_to_record(x.j) r(vendor text, "date" date, instrument text) ON TRUE

View File

@ -1,34 +0,0 @@
--this is a dynamic approach that dumps all keys into the json except several that are required which it extracts
WITH
expand_gl AS (
SELECT
id,
ARRAY['GL',rn::text] json_path,
post_stmp,
(a.i->>'amt')::numeric amount,
a.i->>'account' account,
j.rec->'header'->>'date' tran_date,
j.rec->'header'->>'vendor' vendor,
(a.i - '{amt,account,date}'::text[])||j.rec->'header' as therest
FROM
evt.log j
LEFT JOIN LATERAL JSONB_ARRAY_ELEMENTS(j.rec->'GL') WITH ORDINALITY a(i, rn) ON TRUE
)
,gl_agg AS (
SELECT
id
, tran_date
, vendor
, SUM(amount) amt
, ROUND(SUM(amount) FILTER (WHERE account = 'dcard'),2) dr
FROM
expand_gl
GROUP BY
id
, tran_date
, vendor
ORDER BY
id asc
)
SELECT id, tran_date, vendor, amt, dr, sum(dr) over(ORDER BY id) FROM gl_agg

View File

@ -1,72 +0,0 @@
DO $f$
DECLARE _j jsonb;
DECLARE _m text;
BEGIN
_j := $${"header":{"vendor":"Target","date":"10/12/2017","instrument":"Discover Card","module":"hdrio","total":47.74,"location":"Stow, OH","transaction":"purchase","offset":"dcard"},"item":[{"vend item":"HERBAL","amt":7.99,"account":"home supplies","item":"shampoo","reason":"hygiene"},{"vend item":"HERBAL","amt":7.99,"account":"home supplies","item":"conditioner","reason":"hygiene"},{"vend item":"BUILDING SET","amt":28.74,"account":"recreation","item":"legos","reason":"toys","qty":6,"uom":"ea"},{"vend item":"OH TAX","amt":3.02,"account":"sales tax","item":"sales tax","reason":"sales tax","rate":"0.0675"}]}$$;
WITH
j AS (
SELECT
_j jb
)
--------build a duplicating cross join table------------------
,os AS (
SELECT
flag,
sign,
x.offs
FROM
j
JOIN LATERAL
(
VALUES
('ITEM',1,null),
('OFFSET',-1,j.jb->'header'->>'offset')
) x (flag, sign, offs) ON TRUE
)
------------do the cross join against all the item elements-------------------
,build AS (
SELECT
array['item',rn::text]::text jpath
,COALESCE(os.offs,ae.e->>'account') acct
,(ae.e->>'amt')::numeric * os.sign amount
FROM
j
LEFT JOIN LATERAL JSONB_ARRAY_ELEMENTS(J.JB->'item') WITH ORDINALITY ae(e,rn) ON TRUE
CROSS JOIN os
ORDER BY
ae.rn ASC,
os.flag ASC
)
-------------re-aggregate the items into a single array point called 'gl'---------------
,agg AS (
SELECT
jsonb_build_object('gl',jsonb_agg(row_to_json(b))) gl
FROM
build b
)
------------take the new 'gl' with array key-value pair and combine it with the original---------------
SELECT
jsonb_pretty(agg.gl||j.jb)
INTO
_m
FROM
agg
CROSS JOIN j;
RAISE NOTICE '%', _m;
END
$f$

View File

@ -1,10 +0,0 @@
the journal module is fine forvbasic items, but when entering recipts, a single item has two entries but they are hard to match up. this could be solved by creating a separate schema module that has a head, item, the glbsub items for each main item.
is there a way to do this such that subsequent usage can identify any component of the json with one access path?
or should each push to evt.log pre-implement the down-stream transformation to avoid this?
So the main json structure woudl have a header-item, but then there woudl also be a GL array of items that are assoiated with teh othe header-item lines but not under them as heirarchy items
The gl key then woudl be a header-item combination and coudl have a debit credit off of each of those
based on inital experience with manually loading receipts, may be good to setup a receipt module that automatically sets up the offset and reverses the sign, maybe a preview of the json

View File

@ -1,6 +0,0 @@
{
"party":"Lowe's",
"reason":"ceiling paint",
"reason":"rollers",
"reason":"plastic sheet"
}

View File

@ -1,8 +0,0 @@
[core]
engine = pg
# plan_file = sqitch.plan
# top_dir = .
# [engine "pg"]
# target = db:pg:
# registry = sqitch
# client = psql

View File

@ -1,4 +0,0 @@
%syntax-version=1.0.0
%project=tps_etl
%uri=https://github.com/fleetside72/tps_etl

Binary file not shown.

View File

@ -1,16 +0,0 @@
SELECT
jsonb_pretty(
$$
{
"path":"C:\\users\\ptrowbridge\\downloads\\transsearchcsv.csv"
,"srce":"PNCC"
,"stamp":"2017-10-24 08:32:06.599067-04"
,"inserted":{
"keys":[
1,2,3,4,5,6,7
]
,"summary":""
}
}
$$::jsonb
)

File diff suppressed because one or more lines are too long