pgsql/investigations/ar-cash.sql
[Pman.Xtuple] / pgsql / x-dragon-gl-precision.sql
1 -- not wide enough?
2
3
4 -- this was a mistake!!! - we should never had made gl 3 decimal places - it makes a nightmare everywhere..
5
6 alter table glseries alter column glseries_amount  TYPE numeric(12,2);
7  --View: api.journalentry
8
9 DROP VIEW api.journalentry;
10    alter table gltrans alter column gltrans_amount  TYPE numeric(12,2);
11
12 CREATE OR REPLACE VIEW api.journalentry AS 
13  SELECT curr_symbol.curr_abbr AS currency, c.gltrans_amount AS amount, c.gltrans_date AS dist_date, c.gltrans_docnumber AS doc_number, formatglaccount(da.accnt_id) AS debit, formatglaccount(ca.accnt_id) AS credit, c.gltrans_notes AS notes
14    FROM gltrans d, gltrans c, accnt da, accnt ca, curr_symbol
15   WHERE d.gltrans_sequence = c.gltrans_sequence AND d.gltrans_accnt_id = da.accnt_id AND c.gltrans_accnt_id = ca.accnt_id AND d.gltrans_amount < 0::numeric AND c.gltrans_amount > 0::numeric AND d.gltrans_doctype = 'JE'::text AND c.gltrans_doctype = 'JE'::text AND curr_symbol.curr_id = basecurrid()
16   ORDER BY d.gltrans_date DESC;
17
18 ALTER TABLE api.journalentry
19   OWNER TO admin;
20 GRANT ALL ON TABLE api.journalentry TO admin;
21 GRANT ALL ON TABLE api.journalentry TO xtrole;
22 COMMENT ON VIEW api.journalentry
23   IS 'Journal Entry';
24
25
26 -- Rule: "_DELETE" ON api.journalentry
27
28 -- DROP RULE "_DELETE" ON api.journalentry;
29
30 CREATE OR REPLACE RULE "_DELETE" AS
31     ON DELETE TO api.journalentry DO INSTEAD NOTHING;
32
33 -- Rule: "_INSERT" ON api.journalentry
34
35 -- DROP RULE "_INSERT" ON api.journalentry;
36
37 CREATE OR REPLACE RULE "_INSERT" AS
38     ON INSERT TO api.journalentry DO INSTEAD  SELECT insertgltransaction('G/L'::text, 'JE'::text, new.doc_number, new.notes, getglaccntid(new.credit), getglaccntid(new.debit), (-1), currtobase(getcurrid(new.currency::text), new.amount, new.dist_date), new.dist_date) AS insertgltransaction;
39
40 -- Rule: "_UPDATE" ON api.journalentry
41
42 -- DROP RULE "_UPDATE" ON api.journalentry;
43
44 CREATE OR REPLACE RULE "_UPDATE" AS
45     ON UPDATE TO api.journalentry DO INSTEAD NOTHING;
46 --