From 9d6ffaf60d642e104ccbff5aceab18f73a1b639e Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Sun, 31 Dec 2006 08:33:37 +0000 Subject: [PATCH] * Sync with 3.1.3 --- db/ddlutils/data/AD_ENTITYTYPE.xml | 4 +- .../functions/C_PaymentTerm_DueDays.sql | 64 +++++++++++++++++-- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/db/ddlutils/data/AD_ENTITYTYPE.xml b/db/ddlutils/data/AD_ENTITYTYPE.xml index 3f6cfcb6fd..7bfa365997 100644 --- a/db/ddlutils/data/AD_ENTITYTYPE.xml +++ b/db/ddlutils/data/AD_ENTITYTYPE.xml @@ -1,9 +1,9 @@ - + - + diff --git a/db/ddlutils/oracle/functions/C_PaymentTerm_DueDays.sql b/db/ddlutils/oracle/functions/C_PaymentTerm_DueDays.sql index 057c216271..e645915843 100644 --- a/db/ddlutils/oracle/functions/C_PaymentTerm_DueDays.sql +++ b/db/ddlutils/oracle/functions/C_PaymentTerm_DueDays.sql @@ -20,11 +20,18 @@ RETURN NUMBER * Grace days are not considered! * If record is not found it assumes due immediately * - * Test: SELECT C_PaymentTerm_DueDays(103, '01-DEC-2000', '15-DEC-2000') FROM DUAL + * Test: SELECT paymentTermDueDays(103, '01-DEC-2000', '15-DEC-2000') FROM DUAL + * + * Contributor(s): Carlos Ruiz - globalqss - match with SQLJ version ************************************************************************/ AS Days NUMBER := 0; - DueDate DATE := TRUNC(DocDate); + DueDate DATE := NULL; + calDueDate DATE; + FixMonthOffset C_PaymentTerm.FixMonthOffset%TYPE; + MaxDayCut NUMBER; + MaxDay NUMBER; + v_PayDate DATE; -- CURSOR Cur_PT IS SELECT * @@ -33,10 +40,20 @@ AS FirstDay DATE; NoDays NUMBER; BEGIN + + IF PaymentTerm_ID = 0 OR DocDate IS NULL THEN + RETURN 0; + END IF; + + v_PayDate := PayDate; + IF v_PayDate IS NULL THEN + v_PayDate := TRUNC(SYSDATE); + END IF; + FOR p IN Cur_PT LOOP -- for convineance only -- DBMS_OUTPUT.PUT_LINE(p.Name || ' - Doc = ' || TO_CHAR(DocDate)); -- Due 15th of following month - IF (p.IsDueFixed = 'Y') THEN + IF (p.IsDueFixed = 'Y') THEN -- DBMS_OUTPUT.PUT_LINE(p.Name || ' - Day = ' || p.FixMonthDay); FirstDay := TRUNC(DocDate, 'MM'); NoDays := TRUNC(DocDate) - FirstDay; @@ -45,14 +62,49 @@ BEGIN IF (NoDays > p.FixMonthCutoff) THEN DueDate := ADD_MONTHS(DueDate, 1); END IF; + + calDueDate := TRUNC(DocDate); + MaxDayCut := TO_NUMBER (TO_CHAR (LAST_DAY (calDueDate), 'dd')); + IF p.FixMonthCutoff > MaxDayCut THEN + calDueDate := LAST_DAY(TRUNC(calDueDate)); + ELSE + -- set day fixmonthcutoff on duedate + calDueDate := TO_DATE ( SUBSTR (TO_CHAR (TRUNC (calDueDate), 'yyyymmdd'), 1, 6) + || LPAD (TO_CHAR (p.FixMonthCutoff), 2, '0'), + 'yyyymmdd' + ); + END IF; + FixMonthOffset := p.FixMonthOffset; + IF DocDate > calDueDate THEN + FixMonthOffset := FixMonthOffset + 1; + END IF; + calDueDate := ADD_MONTHS(calDueDate, FixMonthOffset); + MaxDay := TO_NUMBER (TO_CHAR (LAST_DAY (calDueDate), 'dd')); + IF (p.FixMonthDay > MaxDay) -- 32 -> 28 + OR (p.FixMonthDay >= 30 AND MaxDay > p.FixMonthDay) THEN -- 30 -> 31 + calDueDate := TO_DATE ( SUBSTR (TO_CHAR (TRUNC (calDueDate), 'yyyymmdd'), 1, 6) + || LPAD (TO_CHAR (MaxDay), 2, '0'), + 'yyyymmdd' + ); + ELSE + calDueDate := TO_DATE ( SUBSTR (TO_CHAR (TRUNC (calDueDate), 'yyyymmdd'), 1, 6) + || LPAD (TO_CHAR (p.FixMonthDay), 2, '0'), + 'yyyymmdd' + ); + END IF; + DueDate := calDueDate; ELSE -- DBMS_OUTPUT.PUT_LINE('Net = ' || p.NetDays); DueDate := TRUNC(DocDate) + p.NetDays; END IF; END LOOP; --- DBMS_OUTPUT.PUT_LINE('Due = ' || TO_CHAR(DueDate) || ', Pay = ' || TO_CHAR(PayDate)); +-- DBMS_OUTPUT.PUT_LINE('Due = ' || TO_CHAR(DueDate) || ', Pay = ' || TO_CHAR(v_PayDate)); - Days := TRUNC(PayDate) - DueDate; + IF DueDate IS NULL THEN + RETURN 0; + END IF; + + Days := TRUNC(v_PayDate) - DueDate; RETURN Days; END paymentTermDueDays; -/ \ No newline at end of file +/