From e4a813304d587765aff69811c3e58f5100aba3d8 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 19 Sep 2018 00:58:06 -0400 Subject: [PATCH] accomodate periods --- schema/suggested_date/periods.sql | 41 +++++++++++++++++++++++++++++++ schema/tables/gl.sql | 9 ++++++- schema/tables/perd.sql | 5 ++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 schema/suggested_date/periods.sql create mode 100644 schema/tables/perd.sql diff --git a/schema/suggested_date/periods.sql b/schema/suggested_date/periods.sql new file mode 100644 index 0000000..8a66161 --- /dev/null +++ b/schema/suggested_date/periods.sql @@ -0,0 +1,41 @@ +WITH +--startign month +m as ( + SELECT + * + FROM + ( + VALUES + (1,1,1) + ,(2,2,1) + ,(3,3,1) + ,(4,4,2) + ,(5,5,2) + ,(6,6,2) + ,(7,7,3) + ,(8,8,3) + ,(9,9,3) + ,(10,10,4) + ,(11,11,4) + ,(12,12,4) + ) X (cm,fm,fq) +) +INSERT INTO + evt.fspr +SELECT + --TO_CHAR(gs.d,'YYYY.MM.DD')::ltree t1 + ( + --year + to_char(extract(year from gs.d),'FM0000') + --quarter + ||'.'||to_char(m.fq,'FM00') + --month + ||'.'||to_char(m.fm,'FM00') + --day + ||'.'||to_char(extract(day from gs.d),'FM00') + )::ltree t2 + ,tstzrange(gs.d,gs.d + '1 month'::interval) r +FROM + generate_series('2018-01-01 00:00'::timestamptz,'2099-12-01 00:00'::timestamptz,'1 month') gs(d) + INNER JOIN m ON + m.cm = extract(month from gs.d) \ No newline at end of file diff --git a/schema/tables/gl.sql b/schema/tables/gl.sql index c8b3808..2a055aa 100644 --- a/schema/tables/gl.sql +++ b/schema/tables/gl.sql @@ -3,7 +3,11 @@ CREATE TABLE evt.gl ( id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY ,bprid INT REFERENCES evt.bpr (id) - ,account text REFERENCES evt.acct (acct) + ,acct text REFERENCES evt.acct (acct) + ,pstmp timestamptz DEFAULT CURRENT_TIMESTAMP + --populates by trigger join to evt.fspr + ,tstmp timestamptz + ,fspr ltree REFERENCES evt.fspr (id); ,amount numeric (12,2) ,glline INT ,bprkeys JSONB @@ -11,6 +15,9 @@ CREATE TABLE evt.gl ( COMMENT ON COLUMN evt.gl.id IS 'gl id'; COMMENT ON COLUMN evt.gl.bprid IS 'id of initial basic pecuniary record'; COMMENT ON COLUMN evt.gl.acct IS 'account code'; +COMMENT ON COLUMN evt.gl.pstmp IS 'post time stamp'; +COMMENT ON COLUMN evt.gl.tstmp IS 'transaction time stamp'; +COMMENT ON COLUMN evt.gl.fspr IS 'fiscal period'; COMMENT ON COLUMN evt.gl.amount IS 'amount'; COMMENT ON COLUMN evt.gl.glline IS 'gl line number'; COMMENT ON COLUMN evt.gl.bprkeys IS 'extract from initial basic pecuniary record'; \ No newline at end of file diff --git a/schema/tables/perd.sql b/schema/tables/perd.sql new file mode 100644 index 0000000..b967650 --- /dev/null +++ b/schema/tables/perd.sql @@ -0,0 +1,5 @@ +------------------------fiscal periods------------------------ +CREATE TABLE evt.fspr ( + id ltree + ,dur tstzrange +) \ No newline at end of file