From 26ae3aaccbda5a44455293a8e6982305ced46869 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Thu, 28 Aug 2008 22:20:45 +0000 Subject: [PATCH] Fix [ 2081237 ] PaymentAvailable Oracle-XE function wrong --- .../oracle/functions/C_Payment_Available.sql | 4 +- .../277_BF2081237_C_Payment_Available.sql | 62 +++++++++++++++++++ .../277_BF2081237_C_Payment_Available.sql | 1 + 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100755 migration/352a-trunk/277_BF2081237_C_Payment_Available.sql create mode 100755 migration/352a-trunk/postgresql/277_BF2081237_C_Payment_Available.sql diff --git a/db/ddlutils/oracle/functions/C_Payment_Available.sql b/db/ddlutils/oracle/functions/C_Payment_Available.sql index 84e77971db..9cb1494a5d 100644 --- a/db/ddlutils/oracle/functions/C_Payment_Available.sql +++ b/db/ddlutils/oracle/functions/C_Payment_Available.sql @@ -35,7 +35,7 @@ BEGIN FROM C_Payment WHERE C_Payment_ID=p_C_Payment_ID AND C_Charge_ID > 0; IF (v_Amt IS NOT NULL) THEN - RETURN v_Amt; + RETURN 0; END IF; -- Get Currency @@ -59,4 +59,4 @@ BEGIN v_AvailableAmt := ROUND(NVL(v_AvailableAmt,0), 2); RETURN v_AvailableAmt; END paymentAvailable; -/ \ No newline at end of file +/ diff --git a/migration/352a-trunk/277_BF2081237_C_Payment_Available.sql b/migration/352a-trunk/277_BF2081237_C_Payment_Available.sql new file mode 100755 index 0000000000..9cb1494a5d --- /dev/null +++ b/migration/352a-trunk/277_BF2081237_C_Payment_Available.sql @@ -0,0 +1,62 @@ +CREATE OR REPLACE FUNCTION paymentAvailable +( + p_C_Payment_ID IN NUMBER +) +RETURN NUMBER +/************************************************************************* + * 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. + ************************************************************************* + * $Id: C_Payment_Available.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $ + *** + * Title: Calculate Available Payment Amount in Payment Currency + * Description: + * similar to C_Invoice_Open + ************************************************************************/ +AS + v_Currency_ID NUMBER(10); + v_AvailableAmt NUMBER := 0; + v_IsReceipt C_Payment.IsReceipt%TYPE; + v_Amt NUMBER := 0; + CURSOR Cur_Alloc IS + SELECT a.AD_Client_ID, a.AD_Org_ID, al.Amount, a.C_Currency_ID, a.DateTrx + FROM C_AllocationLine al + INNER JOIN C_AllocationHdr a ON (al.C_AllocationHdr_ID=a.C_AllocationHdr_ID) + WHERE al.C_Payment_ID = p_C_Payment_ID + AND a.IsActive='Y'; + -- AND al.C_Invoice_ID IS NOT NULL; +BEGIN + -- Charge - fully allocated + SELECT MAX(PayAmt) + INTO v_Amt + FROM C_Payment + WHERE C_Payment_ID=p_C_Payment_ID AND C_Charge_ID > 0; + IF (v_Amt IS NOT NULL) THEN + RETURN 0; + END IF; + + -- Get Currency + SELECT C_Currency_ID, PayAmt, IsReceipt + INTO v_Currency_ID, v_AvailableAmt, v_IsReceipt + FROM C_Payment_v -- corrected for AP/AR + WHERE C_Payment_ID = p_C_Payment_ID; +-- DBMS_OUTPUT.PUT_LINE('== C_Payment_ID=' || p_C_Payment_ID || ', PayAmt=' || v_AvailableAmt || ', Receipt=' || v_IsReceipt); + + -- Calculate Allocated Amount + FOR a IN Cur_Alloc LOOP + v_Amt := currencyConvert(a.Amount, a.C_Currency_ID, v_Currency_ID, a.DateTrx, null, a.AD_Client_ID, a.AD_Org_ID); + v_AvailableAmt := v_AvailableAmt - v_Amt; +-- DBMS_OUTPUT.PUT_LINE(' Allocation=' || a.Amount || ' - Available=' || v_AvailableAmt); + END LOOP; + -- Ignore Rounding + IF (v_AvailableAmt BETWEEN -0.00999 AND 0.00999) THEN + v_AvailableAmt := 0; + END IF; + -- Round to penny + v_AvailableAmt := ROUND(NVL(v_AvailableAmt,0), 2); + RETURN v_AvailableAmt; +END paymentAvailable; +/ diff --git a/migration/352a-trunk/postgresql/277_BF2081237_C_Payment_Available.sql b/migration/352a-trunk/postgresql/277_BF2081237_C_Payment_Available.sql new file mode 100755 index 0000000000..44206201d7 --- /dev/null +++ b/migration/352a-trunk/postgresql/277_BF2081237_C_Payment_Available.sql @@ -0,0 +1 @@ +-- just for oracle