diff options
author | tetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46> | 2006-11-22 14:36:36 +0000 |
---|---|---|
committer | tetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46> | 2006-11-22 14:36:36 +0000 |
commit | e9a1500790f0a41e9fd27a7e2a556e7d78646d9e (patch) | |
tree | d7238ad663b92abfee6bdd4b3f707c23bf158656 /sql/legacy | |
parent | 009726fc8d3de1044b964195809bc6946de816b6 (diff) |
Adjust del_exchangerate to work with current defaults table layout
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/branches/1.2@682 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 |