[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[3331] trunk/sql/modules/Company.sql
- Subject: SF.net SVN: ledger-smb:[3331] trunk/sql/modules/Company.sql
- From: ..hidden..
- Date: Sat, 25 Jun 2011 11:00:35 +0000
Revision: 3331
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3331&view=rev
Author: einhverfr
Date: 2011-06-25 11:00:35 +0000 (Sat, 25 Jun 2011)
Log Message:
-----------
Bank account saving no longer duplicates
Modified Paths:
--------------
trunk/sql/modules/Company.sql
Modified: trunk/sql/modules/Company.sql
===================================================================
--- trunk/sql/modules/Company.sql 2011-06-25 10:35:16 UTC (rev 3330)
+++ trunk/sql/modules/Company.sql 2011-06-25 11:00:35 UTC (rev 3331)
@@ -744,15 +744,24 @@
$$ LANGUAGE PLPGSQL;
CREATE OR REPLACE FUNCTION eca__save_bank_account
-(in_entity_id int, in_credit_id int, in_bic text, in_iban text)
+(in_entity_id int, in_credit_id int, in_bic text, in_iban text,
+in_bank_account_id int)
RETURNS int AS
$$
DECLARE out_id int;
BEGIN
- INSERT INTO entity_bank_account(entity_id, bic, iban)
- VALUES(in_entity_id, in_bic, in_iban);
+ UPDATE entity_bank_account
+ SET bic = in_bic,
+ iban = in_iban
+ WHERE id = in_bank_account_id;
- SELECT CURRVAL('entity_bank_account_id_seq') INTO out_id ;
+ IF FOUND THEN
+ out_id = in_bank_account_id;
+ ELSE
+ INSERT INTO entity_bank_account(entity_id, bic, iban)
+ VALUES(in_entity_id, in_bic, in_iban);
+ SELECT CURRVAL('entity_bank_account_id_seq') INTO out_id ;
+ END IF;
IF in_credit_id IS NOT NULL THEN
UPDATE entity_credit_account SET bank_account = out_id
@@ -764,15 +773,23 @@
$$ LANGUAGE PLPGSQL;
CREATE OR REPLACE FUNCTION entity__save_bank_account
-(in_entity_id int, in_bic text, in_iban text)
+(in_entity_id int, in_bic text, in_iban text, in_bank_account_id int)
RETURNS int AS
$$
DECLARE out_id int;
BEGIN
- INSERT INTO entity_bank_account(entity_id, bic, iban)
- VALUES(in_entity_id, in_bic, in_iban);
+ UPDATE entity_bank_account
+ SET bic = in_bic,
+ iban = in_iban
+ WHERE id = in_bank_account_id;
- SELECT CURRVAL('entity_bank_account_id_seq') INTO out_id ;
+ IF FOUND THEN
+ out_id = in_bank_account_id;
+ ELSE
+ INSERT INTO entity_bank_account(entity_id, bic, iban)
+ VALUES(in_entity_id, in_bic, in_iban);
+ SELECT CURRVAL('entity_bank_account_id_seq') INTO out_id ;
+ END IF;
RETURN out_id;
END;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.