Feature request: [ 1614574 ] Port sqlj functions to pl/pgsql
Adds testcase for Acct_Balance. Fixes some errors.
This commit is contained in:
parent
f66c8ad49f
commit
e81fab8bb6
|
@ -39,7 +39,7 @@
|
|||
* D | Debit | Debit Balance Account
|
||||
* C | Credit | Credit Balance Account
|
||||
*/
|
||||
CREATE OR REPLACE FUNCTION adempiere.acctBalance(
|
||||
CREATE OR REPLACE FUNCTION acctBalance(
|
||||
IN NUMERIC, -- $1 account id
|
||||
IN NUMERIC, -- $2 amount debit
|
||||
IN NUMERIC -- $3 amount credit
|
||||
|
@ -53,10 +53,10 @@ $$
|
|||
SELECT t.AccountType, t.AccountSign
|
||||
INTO accType, accSign
|
||||
FROM C_ElementValue AS t WHERE t.C_ElementValue_ID = $1;
|
||||
IF accSign = "N" AND accType NOT IN ("A", "E") THEN
|
||||
IF accSign = 'N' AND accType NOT IN ('A', 'E') THEN
|
||||
--If account sign is natural and account type not asset or expense
|
||||
--mark sign to be credit.
|
||||
accSign := "C";
|
||||
accSign := 'C';
|
||||
END IF;
|
||||
END IF;
|
||||
IF accSign = 'C' THEN
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
|
||||
CREATE TABLE C_ElementValue (
|
||||
C_ElementValue_ID NUMERIC PRIMARY KEY,
|
||||
AccountType CHAR(1),
|
||||
AccountSign CHAR(1)
|
||||
);
|
||||
|
||||
INSERT INTO C_ElementValue VALUES(1., 'A', 'N');
|
||||
INSERT INTO C_ElementValue VALUES(2., 'L', 'N');
|
||||
INSERT INTO C_ElementValue VALUES(3., 'R', 'N');
|
||||
INSERT INTO C_ElementValue VALUES(4., 'E', 'N');
|
||||
INSERT INTO C_ElementValue VALUES(5., 'O', 'N');
|
||||
INSERT INTO C_ElementValue VALUES(6., 'M', 'N');
|
||||
INSERT INTO C_ElementValue VALUES(7., 'M', 'C');
|
||||
INSERT INTO C_ElementValue VALUES(8., 'M', 'C');
|
||||
INSERT INTO C_ElementValue VALUES(9., 'M', 'D');
|
||||
INSERT INTO C_ElementValue VALUES(10., 'M', 'D');
|
||||
|
||||
SELECT 1 AS TestNo, acctbalance(1,40.50,50.50), 10.00 AS ExpectedValue;
|
||||
SELECT 2 AS TestNo, acctbalance(2,40.50,50.50), -10.00 AS ExpectedValue;
|
||||
SELECT 3 AS TestNo, acctbalance(3,40.50,50.50), -10.00 AS ExpectedValue;
|
||||
SELECT 4 AS TestNo, acctbalance(4,40.50,50.50), 10.00 AS ExpectedValue;
|
||||
SELECT 5 AS TestNo, acctbalance(5,40.50,50.50), -10.00 AS ExpectedValue;
|
||||
SELECT 6 AS TestNo, acctbalance(6,40.50,50.50), -10.00 AS ExpectedValue;
|
||||
SELECT 7 AS TestNo, acctbalance(7,40.50,50.50), -10.00 AS ExpectedValue;
|
||||
SELECT 8 AS TestNo, acctbalance(8,40.50,50.50), -10.00 AS ExpectedValue;
|
||||
SELECT 9 AS TestNo, acctbalance(9,40.50,50.50), 10.00 AS ExpectedValue;
|
||||
SELECT 10 AS TestNo, acctbalance(10,40.50,50.50), 10.00 AS ExpectedValue;
|
||||
|
||||
SELECT 11 AS TestNo, acctbalance(null,40.50,50.50), 10.00 AS ExpectedValue;
|
||||
SELECT 12 AS TestNo, acctbalance(10,null,50.50), 50.50 AS ExpectedValue;
|
||||
SELECT 13 AS TestNo, acctbalance(10,50.50,null), -50.50 AS ExpectedValue;
|
||||
DROP TABLE C_ElementValue;
|
Loading…
Reference in New Issue