diff options
author | tetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46> | 2006-11-22 14:35:40 +0000 |
---|---|---|
committer | tetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46> | 2006-11-22 14:35:40 +0000 |
commit | baf9b5c9910ec3c5349a870d13e6f602f9e23d13 (patch) | |
tree | c0f86b04c3abd8be99c6d7ff061483c4032466f1 /sql/legacy | |
parent | 1ff34a79a44c4be7c1aec04696cd116eecd45535 (diff) |
Adjusting del_exchangerate to work with current defaults table layout
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@681 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'sql/legacy')
-rw-r--r-- | sql/legacy/Pg-upgrade-2.6.18-2.6.19.sql | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/sql/legacy/Pg-upgrade-2.6.18-2.6.19.sql b/sql/legacy/Pg-upgrade-2.6.18-2.6.19.sql index 44d015a8..a7f4a3f1 100644 --- a/sql/legacy/Pg-upgrade-2.6.18-2.6.19.sql +++ b/sql/legacy/Pg-upgrade-2.6.18-2.6.19.sql @@ -287,6 +287,62 @@ SELECT 'appname', 'LedgerSMB'::text; DROP TABLE old_defaults; +CREATE OR REPLACE FUNCTION del_exchangerate() RETURNS TRIGGER AS ' + +declare + t_transdate date; + t_curr char(3); + t_id int; + d_curr text; + +begin + + select into d_curr substr(value,1,3) from defaults where setting_key = ''curr''; + + if TG_RELNAME = ''ar'' then + select into t_curr, t_transdate curr, transdate from ar where id = old.id; + end if; + if TG_RELNAME = ''ap'' then + select into t_curr, t_transdate curr, transdate from ap where id = old.id; + end if; + if TG_RELNAME = ''oe'' then + select into t_curr, t_transdate curr, transdate from oe where id = old.id; + end if; + + if d_curr != t_curr then + + select into t_id a.id from acc_trans ac + join ar a on (a.id = ac.trans_id) + where a.curr = t_curr + and ac.transdate = t_transdate + + except select a.id from ar a where a.id = old.id + + union + + select a.id from acc_trans ac + join ap a on (a.id = ac.trans_id) + where a.curr = t_curr + and ac.transdate = t_transdate + + except select a.id from ap a where a.id = old.id + + union + + select o.id from oe o + where o.curr = t_curr + and o.transdate = t_transdate + + except select o.id from oe o where o.id = old.id; + + if not found then + delete from exchangerate where curr = t_curr and transdate = t_transdate; + end if; + end if; +return old; + +end; +' language 'plpgsql'; CREATE OR REPLACE FUNCTION add_custom_field (VARCHAR, VARCHAR, VARCHAR) RETURNS BOOL AS |