From eb462af86c77c6af007bb9a99e94c410a856b6b9 Mon Sep 17 00:00:00 2001 From: tspc Date: Tue, 27 Apr 2010 23:30:29 +0000 Subject: [PATCH] Merge bug fixes from release to trunk merge 12158, 12159 Revision: 12158 http://adempiere.svn.sourceforge.net/adempiere/?rev=12158&view=rev Fix [2819386] PaymentTerm DueDate Bug - thanks to Armen Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2819386 Revision: 12159 http://adempiere.svn.sourceforge.net/adempiere/?rev=12159&view=rev Fix [2793048] trunc function different on db/ddlutils and seed Synchronize ddlutils version with current versions in DB Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2793048 Regards, Tony --- .../functions/C_PaymentTerm_DueDate.sql | 4 +- db/ddlutils/postgresql/functions/trunc.sql | 6 +-- migration/354a-trunk/oracle/725_BF2819386.sql | 1 + .../354a-trunk/postgresql/725_BF2819386.sql | 49 +++++++++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 migration/354a-trunk/oracle/725_BF2819386.sql create mode 100644 migration/354a-trunk/postgresql/725_BF2819386.sql diff --git a/db/ddlutils/postgresql/functions/C_PaymentTerm_DueDate.sql b/db/ddlutils/postgresql/functions/C_PaymentTerm_DueDate.sql index 3e6384aaef..ddc956e955 100644 --- a/db/ddlutils/postgresql/functions/C_PaymentTerm_DueDate.sql +++ b/db/ddlutils/postgresql/functions/C_PaymentTerm_DueDate.sql @@ -1,4 +1,4 @@ -CREATE OR REPLACE FUNCTION "adempiere"."paymenttermduedate" (in paymentterm_id numeric, in docdate timestamptz) RETURNS timestamptz AS +CREATE OR REPLACE FUNCTION paymenttermduedate (in paymentterm_id numeric, in docdate timestamptz) RETURNS timestamptz AS $BODY$ /************************************************************************* * The contents of this file are subject to the Compiere License. You may @@ -32,7 +32,7 @@ BEGIN -- Due 15th of following month IF (p.IsDueFixed = 'Y') THEN FirstDay := TRUNC(DocDate, 'MM'); - NoDays := EXTRACT(epoch FROM TRUNC(DocDate) - FirstDay); + NoDays := EXTRACT(day FROM TRUNC(DocDate) - FirstDay); DueDate := FirstDay + (p.FixMonthDay-1); -- starting on 1st DueDate := ADD_MONTHS(DueDate, p.FixMonthOffset); IF (NoDays > p.FixMonthCutoff) THEN diff --git a/db/ddlutils/postgresql/functions/trunc.sql b/db/ddlutils/postgresql/functions/trunc.sql index c16adeda01..9771bf7e47 100644 --- a/db/ddlutils/postgresql/functions/trunc.sql +++ b/db/ddlutils/postgresql/functions/trunc.sql @@ -20,14 +20,14 @@ *Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.of */ CREATE OR REPLACE FUNCTION trunc(datetime TIMESTAMP WITH TIME ZONE) -RETURNS DATE AS $$ +RETURNS TIMESTAMP WITH TIME ZONE AS $$ BEGIN RETURN CAST(datetime AS DATE); END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION trunc(datetime TIMESTAMP WITH TIME ZONE, format varchar) -RETURNS TIMESTAMP WITH TIME ZONE AS $$ +RETURNS DATE AS $$ BEGIN IF format = 'Q' THEN RETURN CAST(DATE_Trunc('quarter',datetime) as DATE); @@ -50,4 +50,4 @@ RETURNS INTEGER AS $$ BEGIN RETURN EXTRACT(DAY FROM i); END; -$$ LANGUAGE plpgsql; \ No newline at end of file +$$ LANGUAGE plpgsql; diff --git a/migration/354a-trunk/oracle/725_BF2819386.sql b/migration/354a-trunk/oracle/725_BF2819386.sql new file mode 100644 index 0000000000..8d61dca7e9 --- /dev/null +++ b/migration/354a-trunk/oracle/725_BF2819386.sql @@ -0,0 +1 @@ +-- just for postgresql diff --git a/migration/354a-trunk/postgresql/725_BF2819386.sql b/migration/354a-trunk/postgresql/725_BF2819386.sql new file mode 100644 index 0000000000..ddc956e955 --- /dev/null +++ b/migration/354a-trunk/postgresql/725_BF2819386.sql @@ -0,0 +1,49 @@ +CREATE OR REPLACE FUNCTION paymenttermduedate (in paymentterm_id numeric, in docdate timestamptz) RETURNS timestamptz AS +$BODY$ +/************************************************************************* + * The contents of this file are subject to the Compiere License. You may + * obtain a copy of the License at http://www.compiere.org/license.html + * Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either + * express or implied. See the License for details. Code: Compiere ERP+CRM + * Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved. + * + * converted to postgreSQL by Karsten Thiemann (Schaeffer AG), + * kthiemann@adempiere.org + ************************************************************************* + * Title: Get Due timestamp with time zone + * Description: + * Returns the due timestamp with time zone + * Test: + * select paymenttermDueDate(106, now()) from Test; => now()+30 days + ************************************************************************/ +DECLARE + Days NUMERIC := 0; + DueDate timestamp with time zone := TRUNC(DocDate); + -- + FirstDay timestamp with time zone; + NoDays NUMERIC; + p RECORD; +BEGIN + FOR p IN + SELECT * + FROM C_PaymentTerm + WHERE C_PaymentTerm_ID = PaymentTerm_ID + LOOP -- for convineance only + -- Due 15th of following month + IF (p.IsDueFixed = 'Y') THEN + FirstDay := TRUNC(DocDate, 'MM'); + NoDays := EXTRACT(day FROM TRUNC(DocDate) - FirstDay); + DueDate := FirstDay + (p.FixMonthDay-1); -- starting on 1st + DueDate := ADD_MONTHS(DueDate, p.FixMonthOffset); + IF (NoDays > p.FixMonthCutoff) THEN + DueDate := ADD_MONTHS(DueDate, 1); + END IF; + ELSE + DueDate := TRUNC(DocDate) + p.NetDays; + END IF; + END LOOP; + RETURN DueDate; +END; +$BODY$ +LANGUAGE 'plpgsql' +;