From f106a61be3bc7274c0263c6280b96e22ea270df6 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Sat, 3 Oct 2020 20:14:15 +0200 Subject: [PATCH] IDEMPIERE-4083 currency rate by document or by transaction Fix wrong pl/sql functions --- .../functions/currencyConvertInvoice.sql | 2 +- .../functions/currencyConvertPayment.sql | 2 +- .../oracle/202010031940_IDEMPIERE-4083.sql | 86 +++++++++++++++++++ .../202010031940_IDEMPIERE-4083.sql | 6 ++ 4 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 migration/i7.1z/oracle/202010031940_IDEMPIERE-4083.sql create mode 100644 migration/i7.1z/postgresql/202010031940_IDEMPIERE-4083.sql diff --git a/db/ddlutils/oracle/functions/currencyConvertInvoice.sql b/db/ddlutils/oracle/functions/currencyConvertInvoice.sql index bdae52737f..2400ac2470 100644 --- a/db/ddlutils/oracle/functions/currencyConvertInvoice.sql +++ b/db/ddlutils/oracle/functions/currencyConvertInvoice.sql @@ -3,7 +3,7 @@ CREATE OR REPLACE FUNCTION currencyConvertInvoice( p_currency_to_id in number, p_amt in number DEFAULT NULL, p_conversiondate in date DEFAULT NULL) - RETURNS number + RETURN number AS v_GrandTotal NUMBER; v_ConversionType_ID NUMBER; diff --git a/db/ddlutils/oracle/functions/currencyConvertPayment.sql b/db/ddlutils/oracle/functions/currencyConvertPayment.sql index b6ca912939..c34bc09193 100644 --- a/db/ddlutils/oracle/functions/currencyConvertPayment.sql +++ b/db/ddlutils/oracle/functions/currencyConvertPayment.sql @@ -1,7 +1,7 @@ CREATE OR REPLACE FUNCTION currencyConvertPayment ( p_C_Payment_ID IN NUMBER, - p_CurTo_ID IN NUMBER, + p_Currency_To_id IN NUMBER, p_Amt IN NUMBER DEFAULT NULL, p_conversionDate IN DATE DEFAULT NULL ) diff --git a/migration/i7.1z/oracle/202010031940_IDEMPIERE-4083.sql b/migration/i7.1z/oracle/202010031940_IDEMPIERE-4083.sql new file mode 100644 index 0000000000..4a926435b6 --- /dev/null +++ b/migration/i7.1z/oracle/202010031940_IDEMPIERE-4083.sql @@ -0,0 +1,86 @@ +-- IDEMPIERE-4083 currency rate by document or by transaction +-- Fix wrong pl/sql functions + +CREATE OR REPLACE FUNCTION currencyConvertInvoice( + p_c_invoice_id in number, + p_currency_to_id in number, + p_amt in number DEFAULT NULL, + p_conversiondate in date DEFAULT NULL) + RETURN number +AS + v_GrandTotal NUMBER; + v_ConversionType_ID NUMBER; + v_Client_ID NUMBER; + v_Org_ID NUMBER; + v_Currency_ID NUMBER; + v_CurrencyRate NUMBER; + v_DateAcct DATE; + v_BaseCurrency_ID NUMBER; + v_IsOverrideCurrencyRate CHAR(1); +BEGIN + SELECT AD_Client_ID, AD_Org_ID, DateAcct, C_Currency_ID, C_ConversionType_ID, CurrencyRate, GrandTotal, IsOverrideCurrencyRate + INTO v_Client_ID, v_Org_ID, v_DateAcct, v_Currency_ID, v_ConversionType_ID, v_CurrencyRate, v_GrandTotal, v_IsOverrideCurrencyRate + FROM C_Invoice + WHERE C_Invoice_ID=p_C_Invoice_ID; + + SELECT sc.C_Currency_ID + INTO v_BaseCurrency_ID + FROM AD_ClientInfo ci + JOIN C_AcctSchema sc ON ci.C_AcctSchema1_ID=sc.C_AcctSchema_ID + WHERE ci.AD_Client_ID=v_Client_ID; + + IF v_BaseCurrency_ID=p_Currency_To_id AND Coalesce(v_CurrencyRate,0) > 0 AND v_Currency_ID != p_Currency_To_id AND v_IsOverrideCurrencyRate='Y' THEN + RETURN currencyRound(Coalesce(p_Amt,v_GrandTotal)*v_CurrencyRate, p_Currency_To_id, null); + END IF; + + RETURN currencyConvert(Coalesce(p_Amt,v_GrandTotal), v_Currency_ID, p_Currency_To_id, Coalesce(p_conversionDate,v_DateAcct), v_ConversionType_ID, v_Client_ID, v_Org_ID); +END currencyConvertInvoice; +/ + +CREATE OR REPLACE FUNCTION currencyConvertPayment +( + p_C_Payment_ID IN NUMBER, + p_Currency_To_id IN NUMBER, + p_Amt IN NUMBER DEFAULT NULL, + p_conversionDate IN DATE DEFAULT NULL +) +RETURN NUMBER +AS + v_Rate NUMBER; + v_PayAmt NUMBER; + v_ConversionType_ID NUMBER; + v_Client_ID NUMBER; + v_Org_ID NUMBER; + v_Currency_ID NUMBER; + v_CurrencyRate NUMBER; + v_ConvertedAmt NUMBER; + v_DateAcct DATE; + v_BaseCurrency_ID NUMBER; + v_IsOverrideCurrencyRate Char(1); +BEGIN + SELECT AD_Client_ID, AD_Org_ID, DateAcct, C_Currency_ID, C_ConversionType_ID, CurrencyRate, ConvertedAmt, PayAmt, IsOverrideCurrencyRate + INTO v_Client_ID, v_Org_ID, v_DateAcct, v_Currency_ID, v_ConversionType_ID, v_CurrencyRate, v_ConvertedAmt, v_PayAmt, v_IsOverrideCurrencyRate + FROM C_Payment + WHERE C_Payment_ID=p_C_Payment_ID; + + SELECT sc.C_Currency_ID + INTO v_BaseCurrency_ID + FROM AD_ClientInfo ci + JOIN C_AcctSchema sc ON ci.C_AcctSchema1_ID=sc.C_AcctSchema_ID + WHERE ci.AD_Client_ID=v_Client_ID; + + IF v_BaseCurrency_ID=p_Currency_To_id AND Coalesce(v_CurrencyRate,0) > 0 AND Coalesce(v_ConvertedAmt,0) != 0 AND v_Currency_ID != p_Currency_To_id AND v_IsOverrideCurrencyRate='Y' THEN + IF p_Amt IS NULL THEN + RETURN v_ConvertedAmt; + ELSE + RETURN currencyRound(p_Amt*v_CurrencyRate, p_Currency_To_id, null); + END IF; + END IF; + + RETURN currencyConvert(Coalesce(p_Amt,v_PayAmt), v_Currency_ID, p_Currency_To_id, Coalesce(p_conversionDate,v_DateAcct), v_ConversionType_ID, v_Client_ID, v_Org_ID); +END currencyConvertPayment; +/ + +SELECT register_migration_script('202010031940_IDEMPIERE-4083.sql') FROM dual +; + diff --git a/migration/i7.1z/postgresql/202010031940_IDEMPIERE-4083.sql b/migration/i7.1z/postgresql/202010031940_IDEMPIERE-4083.sql new file mode 100644 index 0000000000..2e7e214360 --- /dev/null +++ b/migration/i7.1z/postgresql/202010031940_IDEMPIERE-4083.sql @@ -0,0 +1,6 @@ +-- IDEMPIERE-4083 currency rate by document or by transaction +-- placeholder - this is just for oracle + +SELECT register_migration_script('202010031940_IDEMPIERE-4083.sql') FROM dual +; +