diff options
author | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-06-12 17:13:50 +0000 |
---|---|---|
committer | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-06-12 17:13:50 +0000 |
commit | 12c908bf37942a9ac65da380ea24fe3003bafc2a (patch) | |
tree | d3aee22b7810001f5c41e335986bc0d6ac4e37a9 /sql/modules | |
parent | d0b988e4428f7ce8e5cd8cf79f6f4d2ddbf75ccf (diff) |
Committing Aurynn's changes to Reconciliation logic
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1268 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'sql/modules')
-rw-r--r-- | sql/modules/Reconciliaton.sql | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/sql/modules/Reconciliaton.sql b/sql/modules/Reconciliaton.sql index 161d9369..2700a2fb 100644 --- a/sql/modules/Reconciliaton.sql +++ b/sql/modules/Reconciliaton.sql @@ -4,7 +4,7 @@ CREATE TABLE pending_reports ( scn int, their_balance INT, our_balance INT, - code INT, + errorcode INT, user TEXT, corrections INT NOT NULL DEFAULT 0 clear_time TIMESTAMP NOT NULL, @@ -223,7 +223,7 @@ CREATE OR REPLACE FUNCTION reconciliation_report_approve (in_report_id INT) retu $$ language 'plpgsql'; -CREATE OR REPLACE FUNCTION reconciliation_new_report () returns INT as $$ +CREATE OR REPLACE FUNCTION reconciliation_new_report_id () returns INT as $$ SELECT nextval('pending_report_report_id_seq'); @@ -343,4 +343,42 @@ create or replace function reconciliation_pending_transactions (in_report_id INT END LOOP; END; -$$ language plpgsql;
\ No newline at end of file +$$ language plpgsql; + +CREATE OR REPLACE FUNCTION reconciliation_report (in_report_id INT) RETURNS setof pending_reports as $$ + + DECLARE + row pending_reports; + BEGIN + FOR row IN select * from pending_reports where report_id = in_report_id LOOP + + RETURN NEXT row; + + END LOOP; + END; + +$$ language 'plpgsql'; + +CREATE OR REPLACE FUNCTION reconciliation_get_total (in_report_id INT) returns setof pending_reports AS $$ + + DECLARE + row pending_reports; + BEGIN + + SELECT INTO row FROM pending_reports + WHERE ledger_id IS NULL + and report_id = in_report_id + AND scn = -1; + + IF NOT FOUND THEN -- I think this is a fairly major error condition + + RAISE EXCEPTION "No Bank Total found." + + ELSE + + return row; + + END IF; + END; + +$$ language 'plpgsql'; |