From 18226dcc30b015d87aba53b451217a7b1e16f8f3 Mon Sep 17 00:00:00 2001 From: kontro Date: Fri, 2 Feb 2007 18:38:47 +0000 Subject: [PATCH] Feature request: [ 1614574 ] Port sqlj functions to pl/pgsql Contribution made by Gavin Dunse. To be tested. --- .../functions/C_BPartner_RemitLocation.sql | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 db/ddlutils/postgresql/functions/C_BPartner_RemitLocation.sql diff --git a/db/ddlutils/postgresql/functions/C_BPartner_RemitLocation.sql b/db/ddlutils/postgresql/functions/C_BPartner_RemitLocation.sql new file mode 100644 index 0000000000..e0d739a01b --- /dev/null +++ b/db/ddlutils/postgresql/functions/C_BPartner_RemitLocation.sql @@ -0,0 +1,50 @@ +/* + *This file is part of Adempiere ERP Bazaar + *http://www.adempiere.org + * + *Copyright (C) 2007 Gavin Dunse + *Copyright (C) 1999-2006 ComPiere, inc + * + *This program is free software; you can redistribute it and/or + *modify it under the terms of the GNU General Public License + *as published by the Free Software Foundation; either version 2 + *of the License, or (at your option) any later version. + * + *This program is distributed in the hope that it will be useful, + *but WITHOUT ANY WARRANTY; without even the implied warranty of + *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *GNU General Public License for more details. + * + *You should have received a copy of the GNU General Public License + *along with this program; if not, write to the Free Software + *Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.of + */ + +/* + * Return the first RemitTo C_Location_ID of a Business Partner + */ + +CREATE OR REPLACE FUNCTION bpartnerRemitLocation ( + IN NUMERIC -- $1 C_BPartner_ID +) RETURNS NUMERIC AS +$$ + DECLARE + clocationid NUMERIC; + BEGIN + SELECT t.C_Location_ID + INTO clocationid + FROM C_BPartner_Location + AS t + WHERE t.C_BPartner_ID=$1 + AND t.C_Location_ID IS NOT NULL + ORDER BY t.IsRemitTo DESC; + /* Limit not needed as first row is only returned - LIMIT 1; */ + IF FOUND THEN + RETURN clocationid; + ELSE + RETURN -1; + /* RAISE EXCEPTION 'Some error'*/ + /* RETURN NULL */ + END IF; + END; +$$ LANGUAGE plpgsql;