IDEMPIERE-1856 Amount in database functions and views are hardcoded to round to 2 decimal points

This commit is contained in:
Elaine Tan 2014-03-26 12:18:20 +08:00
parent 036f065d70
commit 1abe2ca2ba
47 changed files with 3765 additions and 669 deletions

View File

@ -33,6 +33,8 @@ SELECT C_InvoicePaySchedule_ID, DueAmt FROM C_InvoicePaySchedule WHERE C_Invoice
************************************************************************/ ************************************************************************/
AS AS
v_Currency_ID NUMBER(10); v_Currency_ID NUMBER(10);
v_Precision NUMBER := 0;
v_Min NUMBER := 0;
v_TotalOpenAmt NUMBER := 0; v_TotalOpenAmt NUMBER := 0;
v_PaidAmt NUMBER := 0; v_PaidAmt NUMBER := 0;
v_Remaining NUMBER := 0; v_Remaining NUMBER := 0;
@ -70,6 +72,13 @@ BEGIN
END; END;
-- DBMS_OUTPUT.PUT_LINE('== C_Invoice_ID=' || p_C_Invoice_ID || ', Total=' || v_TotalOpenAmt || ', AP=' || v_MultiplierAP || ', CM=' || v_MultiplierCM); -- DBMS_OUTPUT.PUT_LINE('== C_Invoice_ID=' || p_C_Invoice_ID || ', Total=' || v_TotalOpenAmt || ', AP=' || v_MultiplierAP || ', CM=' || v_MultiplierCM);
SELECT StdPrecision
INTO v_Precision
FROM C_Currency
WHERE C_Currency_ID = v_Currency_ID;
SELECT POWER(1/10,v_Precision) INTO v_Min FROM DUAL;
-- Calculate Allocated Amount -- Calculate Allocated Amount
FOR a IN Cur_Alloc LOOP FOR a IN Cur_Alloc LOOP
v_Temp := a.Amount + a.DisCountAmt + a.WriteOffAmt; v_Temp := a.Amount + a.DisCountAmt + a.WriteOffAmt;
@ -104,12 +113,13 @@ BEGIN
-- DBMS_OUTPUT.PUT_LINE('== Total=' || v_TotalOpenAmt); -- DBMS_OUTPUT.PUT_LINE('== Total=' || v_TotalOpenAmt);
-- Ignore Rounding -- Ignore Rounding
IF (v_TotalOpenAmt BETWEEN -0.00999 AND 0.00999) THEN IF (v_TotalOpenAmt > -v_Min AND v_TotalOpenAmt < v_Min) THEN
v_TotalOpenAmt := 0; v_TotalOpenAmt := 0;
END IF; END IF;
-- Round to penny -- Round to currency precision
v_TotalOpenAmt := ROUND(COALESCE(v_TotalOpenAmt,0), 2); v_TotalOpenAmt := ROUND(COALESCE(v_TotalOpenAmt,0), v_Precision);
RETURN v_TotalOpenAmt; RETURN v_TotalOpenAmt;
END invoiceOpen; END invoiceOpen;
/ /

View File

@ -34,6 +34,8 @@ SELECT C_InvoicePaySchedule_ID, DueAmt FROM C_InvoicePaySchedule WHERE C_Invoice
************************************************************************/ ************************************************************************/
AS AS
v_Currency_ID NUMBER(10); v_Currency_ID NUMBER(10);
v_Precision NUMBER := 0;
v_Min NUMBER := 0;
v_TotalOpenAmt NUMBER := 0; v_TotalOpenAmt NUMBER := 0;
v_PaidAmt NUMBER := 0; v_PaidAmt NUMBER := 0;
v_Remaining NUMBER := 0; v_Remaining NUMBER := 0;
@ -73,6 +75,13 @@ BEGIN
END; END;
-- DBMS_OUTPUT.PUT_LINE('== C_Invoice_ID=' || p_C_Invoice_ID || ', Total=' || v_TotalOpenAmt || ', AP=' || v_MultiplierAP || ', CM=' || v_MultiplierCM); -- DBMS_OUTPUT.PUT_LINE('== C_Invoice_ID=' || p_C_Invoice_ID || ', Total=' || v_TotalOpenAmt || ', AP=' || v_MultiplierAP || ', CM=' || v_MultiplierCM);
SELECT StdPrecision
INTO v_Precision
FROM C_Currency
WHERE C_Currency_ID = v_Currency_ID;
SELECT POWER(1/10,v_Precision) INTO v_Min FROM DUAL;
-- Calculate Allocated Amount -- Calculate Allocated Amount
FOR a IN Cur_Alloc LOOP FOR a IN Cur_Alloc LOOP
v_Temp := a.Amount + a.DisCountAmt + a.WriteOffAmt; v_Temp := a.Amount + a.DisCountAmt + a.WriteOffAmt;
@ -107,12 +116,13 @@ BEGIN
-- DBMS_OUTPUT.PUT_LINE('== Total=' || v_TotalOpenAmt); -- DBMS_OUTPUT.PUT_LINE('== Total=' || v_TotalOpenAmt);
-- Ignore Rounding -- Ignore Rounding
IF (v_TotalOpenAmt BETWEEN -0.00999 AND 0.00999) THEN IF (v_TotalOpenAmt > -v_Min AND v_TotalOpenAmt < v_Min) THEN
v_TotalOpenAmt := 0; v_TotalOpenAmt := 0;
END IF; END IF;
-- Round to penny -- Round to currency precision
v_TotalOpenAmt := ROUND(COALESCE(v_TotalOpenAmt,0), 2); v_TotalOpenAmt := ROUND(COALESCE(v_TotalOpenAmt,0), v_Precision);
RETURN v_TotalOpenAmt; RETURN v_TotalOpenAmt;
END InvoiceopenToDate; END InvoiceopenToDate;
/ /

View File

@ -33,6 +33,8 @@ RETURN NUMBER
* *
************************************************************************/ ************************************************************************/
AS AS
v_Precision NUMBER := 0;
v_Min NUMBER := 0;
v_MultiplierAP NUMBER := 1; v_MultiplierAP NUMBER := 1;
v_PaymentAmt NUMBER := 0; v_PaymentAmt NUMBER := 0;
CURSOR Cur_Alloc IS CURSOR Cur_Alloc IS
@ -44,6 +46,13 @@ AS
WHERE al.C_Invoice_ID = p_C_Invoice_ID WHERE al.C_Invoice_ID = p_C_Invoice_ID
AND a.IsActive='Y'; AND a.IsActive='Y';
BEGIN BEGIN
SELECT StdPrecision
INTO v_Precision
FROM C_Currency
WHERE C_Currency_ID = p_C_Currency_ID;
SELECT POWER(1/10,v_Precision) INTO v_Min FROM DUAL;
-- Default -- Default
IF (p_MultiplierAP IS NOT NULL) THEN IF (p_MultiplierAP IS NOT NULL) THEN
v_MultiplierAP := p_MultiplierAP; v_MultiplierAP := p_MultiplierAP;
@ -54,7 +63,15 @@ BEGIN
+ currencyConvert(a.Amount + a.DisCountAmt + a.WriteOffAmt, + currencyConvert(a.Amount + a.DisCountAmt + a.WriteOffAmt,
a.C_Currency_ID, p_C_Currency_ID, a.DateTrx, null, a.AD_Client_ID, a.AD_Org_ID); a.C_Currency_ID, p_C_Currency_ID, a.DateTrx, null, a.AD_Client_ID, a.AD_Org_ID);
END LOOP; END LOOP;
--
RETURN ROUND(NVL(v_PaymentAmt,0), 2) * v_MultiplierAP; -- Ignore Rounding
IF (v_PaymentAmt > -v_Min AND v_PaymentAmt < v_Min) THEN
v_PaymentAmt := 0;
END IF;
-- Round to currency precision
v_PaymentAmt := ROUND(COALESCE(v_PaymentAmt,0), v_Precision);
RETURN v_PaymentAmt * v_MultiplierAP;
END invoicePaid; END invoicePaid;
/ /

View File

@ -34,6 +34,8 @@ RETURN NUMBER
* *
************************************************************************/ ************************************************************************/
AS AS
v_Precision NUMBER := 0;
v_Min NUMBER := 0;
v_MultiplierAP NUMBER := 1; v_MultiplierAP NUMBER := 1;
v_PaymentAmt NUMBER := 0; v_PaymentAmt NUMBER := 0;
CURSOR Cur_Alloc IS CURSOR Cur_Alloc IS
@ -46,6 +48,13 @@ AS
AND a.IsActive='Y' AND a.IsActive='Y'
AND a.DateAcct <= p_DateAcct; AND a.DateAcct <= p_DateAcct;
BEGIN BEGIN
SELECT StdPrecision
INTO v_Precision
FROM C_Currency
WHERE C_Currency_ID = p_C_Currency_ID;
SELECT POWER(1/10,v_Precision) INTO v_Min FROM DUAL;
-- Default -- Default
IF (p_MultiplierAP IS NOT NULL) THEN IF (p_MultiplierAP IS NOT NULL) THEN
v_MultiplierAP := p_MultiplierAP; v_MultiplierAP := p_MultiplierAP;
@ -56,7 +65,15 @@ BEGIN
+ Currencyconvert(a.Amount + a.DisCountAmt + a.WriteOffAmt, + Currencyconvert(a.Amount + a.DisCountAmt + a.WriteOffAmt,
a.C_Currency_ID, p_C_Currency_ID, a.DateTrx, NULL, a.AD_Client_ID, a.AD_Org_ID); a.C_Currency_ID, p_C_Currency_ID, a.DateTrx, NULL, a.AD_Client_ID, a.AD_Org_ID);
END LOOP; END LOOP;
--
RETURN ROUND(NVL(v_PaymentAmt,0), 2) * v_MultiplierAP; -- Ignore Rounding
IF (v_PaymentAmt > -v_Min AND v_PaymentAmt < v_Min) THEN
v_PaymentAmt := 0;
END IF;
-- Round to currency precision
v_PaymentAmt := ROUND(COALESCE(v_PaymentAmt,0), v_Precision);
RETURN v_PaymentAmt * v_MultiplierAP;
END InvoicepaidToDate; END InvoicepaidToDate;
/ /

View File

@ -24,6 +24,8 @@ RETURN NUMBER
************************************************************************/ ************************************************************************/
AS AS
v_Precision NUMBER := 0;
v_Min NUMBER := 0;
Discount NUMBER := 0; Discount NUMBER := 0;
CURSOR Cur_PT IS CURSOR Cur_PT IS
SELECT * SELECT *
@ -34,6 +36,13 @@ AS
Add1Date NUMBER := 0; Add1Date NUMBER := 0;
Add2Date NUMBER := 0; Add2Date NUMBER := 0;
BEGIN BEGIN
SELECT StdPrecision
INTO v_Precision
FROM C_Currency
WHERE C_Currency_ID = Currency_ID;
SELECT POWER(1/10,v_Precision) INTO v_Min FROM DUAL;
-- No Data - No Discount -- No Data - No Discount
IF (Amount IS NULL OR PaymentTerm_ID IS NULL OR DocDate IS NULL) THEN IF (Amount IS NULL OR PaymentTerm_ID IS NULL OR DocDate IS NULL) THEN
RETURN 0; RETURN 0;
@ -60,7 +69,15 @@ BEGIN
Discount := Amount * p.Discount2 / 100; Discount := Amount * p.Discount2 / 100;
END IF; END IF;
END LOOP; END LOOP;
--
RETURN ROUND(NVL(Discount,0), 2); -- fixed rounding -- Ignore Rounding
IF (Discount > -v_Min AND Discount < v_Min) THEN
Discount := 0;
END IF;
-- Round to currency precision
Discount := ROUND(COALESCE(Discount,0), v_Precision);
RETURN Discount;
END paymentTermDiscount; END paymentTermDiscount;
/ /

View File

@ -26,6 +26,8 @@ RETURN NUMBER
************************************************************************/ ************************************************************************/
AS AS
v_Precision NUMBER := 0;
v_Min NUMBER := 0;
v_AllocatedAmt NUMBER := 0; v_AllocatedAmt NUMBER := 0;
v_PayAmt NUMBER; v_PayAmt NUMBER;
CURSOR Cur_Alloc IS CURSOR Cur_Alloc IS
@ -36,6 +38,13 @@ AS
AND a.IsActive='Y'; AND a.IsActive='Y';
-- AND al.C_Invoice_ID IS NOT NULL; -- AND al.C_Invoice_ID IS NOT NULL;
BEGIN BEGIN
SELECT StdPrecision
INTO v_Precision
FROM C_Currency
WHERE C_Currency_ID = p_C_Currency_ID;
SELECT POWER(1/10,v_Precision) INTO v_Min FROM DUAL;
-- Charge - nothing available -- Charge - nothing available
SELECT MAX(PayAmt) SELECT MAX(PayAmt)
INTO v_PayAmt INTO v_PayAmt
@ -50,8 +59,15 @@ BEGIN
v_AllocatedAmt := v_AllocatedAmt v_AllocatedAmt := v_AllocatedAmt
+ currencyConvert(a.Amount, a.C_Currency_ID, p_C_Currency_ID, a.DateTrx, null, a.AD_Client_ID, a.AD_Org_ID); + currencyConvert(a.Amount, a.C_Currency_ID, p_C_Currency_ID, a.DateTrx, null, a.AD_Client_ID, a.AD_Org_ID);
END LOOP; END LOOP;
-- Round to penny
v_AllocatedAmt := ROUND(NVL(v_AllocatedAmt,0), 2); -- Ignore Rounding
IF (v_AllocatedAmt > -v_Min AND v_AllocatedAmt < v_Min) THEN
v_AllocatedAmt := 0;
END IF;
-- Round to currency precision
v_AllocatedAmt := ROUND(COALESCE(v_AllocatedAmt,0), v_Precision);
RETURN v_AllocatedAmt; RETURN v_AllocatedAmt;
END paymentAllocated; END paymentAllocated;
/ /

View File

@ -18,6 +18,8 @@ RETURN NUMBER
************************************************************************/ ************************************************************************/
AS AS
v_Currency_ID NUMBER(10); v_Currency_ID NUMBER(10);
v_Precision NUMBER := 0;
v_Min NUMBER := 0;
v_AvailableAmt NUMBER := 0; v_AvailableAmt NUMBER := 0;
v_IsReceipt C_Payment.IsReceipt%TYPE; v_IsReceipt C_Payment.IsReceipt%TYPE;
v_Amt NUMBER := 0; v_Amt NUMBER := 0;
@ -45,18 +47,28 @@ BEGIN
WHERE C_Payment_ID = p_C_Payment_ID; 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); -- DBMS_OUTPUT.PUT_LINE('== C_Payment_ID=' || p_C_Payment_ID || ', PayAmt=' || v_AvailableAmt || ', Receipt=' || v_IsReceipt);
SELECT StdPrecision
INTO v_Precision
FROM C_Currency
WHERE C_Currency_ID = v_Currency_ID;
SELECT POWER(1/10,v_Precision) INTO v_Min FROM DUAL;
-- Calculate Allocated Amount -- Calculate Allocated Amount
FOR a IN Cur_Alloc LOOP 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_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; v_AvailableAmt := v_AvailableAmt - v_Amt;
-- DBMS_OUTPUT.PUT_LINE(' Allocation=' || a.Amount || ' - Available=' || v_AvailableAmt); -- DBMS_OUTPUT.PUT_LINE(' Allocation=' || a.Amount || ' - Available=' || v_AvailableAmt);
END LOOP; END LOOP;
-- Ignore Rounding -- Ignore Rounding
IF (v_AvailableAmt BETWEEN -0.00999 AND 0.00999) THEN IF (v_AvailableAmt > -v_Min AND v_AvailableAmt < v_Min) THEN
v_AvailableAmt := 0; v_AvailableAmt := 0;
END IF; END IF;
-- Round to penny
v_AvailableAmt := ROUND(NVL(v_AvailableAmt,0), 2); -- Round to currency precision
v_AvailableAmt := ROUND(COALESCE(v_AvailableAmt,0), v_Precision);
RETURN v_AvailableAmt; RETURN v_AvailableAmt;
END paymentAvailable; END paymentAvailable;
/ /

View File

@ -11,11 +11,11 @@ SELECT il.AD_Client_ID, il.AD_Org_ID,
i.C_BPartner_ID, il.M_Product_ID, i.C_BPartner_ID, il.M_Product_ID,
i.DocumentNo, i.DateInvoiced, i.DateAcct, i.DocumentNo, i.DateInvoiced, i.DateAcct,
i.IsSOTrx, i.DocStatus, i.IsSOTrx, i.DocStatus,
ROUND(i.Multiplier*LineNetAmt, 2) AS LineNetAmt, currencyRound(i.Multiplier*LineNetAmt,i.C_Currency_ID,'N') AS LineNetAmt,
ROUND(i.Multiplier*PriceList*QtyInvoiced, 2) AS LineListAmt, currencyRound(i.Multiplier*PriceList*QtyInvoiced,i.C_Currency_ID,'N') AS LineListAmt,
CASE WHEN COALESCE(il.PriceLimit, 0)=0 THEN ROUND(i.Multiplier*LineNetAmt,2) ELSE ROUND(i.Multiplier*PriceLimit*QtyInvoiced,2) END AS LineLimitAmt, CASE WHEN COALESCE(il.PriceLimit, 0)=0 THEN currencyRound(i.Multiplier*LineNetAmt,i.C_Currency_ID,'N') ELSE currencyRound(i.Multiplier*il.PriceLimit*il.QtyInvoiced,i.C_Currency_ID,'N') END AS LineLimitAmt,
ROUND(i.Multiplier*PriceList*QtyInvoiced-LineNetAmt,2) AS LineDiscountAmt, currencyRound(i.Multiplier*il.PriceList*il.QtyInvoiced-il.LineNetAmt,i.C_Currency_ID,'N') AS LineDiscountAmt,
CASE WHEN COALESCE(il.PriceLimit,0)=0 THEN 0 ELSE ROUND(i.Multiplier*LineNetAmt-PriceLimit*QtyInvoiced,2) END AS LineOverLimitAmt, CASE WHEN COALESCE(il.PriceLimit,0)=0 THEN 0 ELSE currencyRound(i.Multiplier*il.LineNetAmt-il.PriceLimit*il.QtyInvoiced,i.C_Currency_ID,'N') END AS LineOverLimitAmt,
il.QtyInvoiced, il.QtyEntered, il.QtyInvoiced, il.QtyEntered,
il.Line, il.C_OrderLine_ID, il.C_UOM_ID, il.Line, il.C_OrderLine_ID, il.C_UOM_ID,
il.C_Campaign_ID, il.C_Project_ID, il.C_Activity_ID, il.C_ProjectPhase_ID, il.C_ProjectTask_ID il.C_Campaign_ID, il.C_Project_ID, il.C_Activity_ID, il.C_ProjectPhase_ID, il.C_ProjectTask_ID

View File

@ -13,7 +13,7 @@ SELECT s.ad_client_id,
sum(ms.qtyonhand - ms.qtyreserved) AS qtyavailable, sum(ms.qtyonhand - ms.qtyreserved) AS qtyavailable,
sum(ms.qtyonhand) AS qtyonhand, sum(ms.qtyonhand) AS qtyonhand,
sum(ms.qtyreserved) AS qtyreserved, sum(ms.qtyreserved) AS qtyreserved,
ROUND(MAX(mpr.pricestd),0) AS pricestd, currencyRound(MAX(mpr.pricestd),mpl.C_Currency_ID,'N') AS pricestd,
mpr.m_pricelist_version_id, mpr.m_pricelist_version_id,
mw.m_warehouse_id, mw.m_warehouse_id,
org.name AS orgname org.name AS orgname
@ -23,6 +23,8 @@ SELECT s.ad_client_id,
JOIN m_locator ml ON ms.m_locator_id = ml.m_locator_id JOIN m_locator ml ON ms.m_locator_id = ml.m_locator_id
JOIN m_warehouse mw ON ml.m_warehouse_id = mw.m_warehouse_id JOIN m_warehouse mw ON ml.m_warehouse_id = mw.m_warehouse_id
JOIN m_productprice mpr ON ms.m_product_id = mpr.m_product_id JOIN m_productprice mpr ON ms.m_product_id = mpr.m_product_id
JOIN m_pricelist_version mplv ON mplv.m_pricelist_version_id = mpr.m_pricelist_version_id
JOIN m_pricelist mpl ON mplv.m_pricelist_id = mpl.m_pricelist_id
JOIN ad_org org ON org.ad_org_id = mw.ad_org_id JOIN ad_org org ON org.ad_org_id = mw.ad_org_id
GROUP BY s.ad_client_id, GROUP BY s.ad_client_id,
s.ad_org_id, s.ad_org_id,
@ -36,7 +38,8 @@ SELECT s.ad_client_id,
mw.m_warehouse_id, mw.m_warehouse_id,
mpr.m_pricelist_version_id, mpr.m_pricelist_version_id,
org.name, org.name,
mp.name mp.name,
mpl.C_Currency_ID
UNION UNION
SELECT r.ad_client_id, SELECT r.ad_client_id,
r.ad_org_id, r.ad_org_id,
@ -52,7 +55,7 @@ SELECT s.ad_client_id,
sum(ms.qtyonhand - ms.qtyreserved) AS qtyavailable, sum(ms.qtyonhand - ms.qtyreserved) AS qtyavailable,
sum(ms.qtyonhand) AS qtyonhand, sum(ms.qtyonhand) AS qtyonhand,
sum(ms.qtyreserved) AS qtyreserved, sum(ms.qtyreserved) AS qtyreserved,
ROUND(MAX(mpr.pricestd),0) AS pricestd, currencyRound(MAX(mpr.pricestd),mpl.C_Currency_ID,'N') AS pricestd,
mpr.m_pricelist_version_id, mpr.m_pricelist_version_id,
mw.m_warehouse_id, mw.m_warehouse_id,
org.name AS orgname org.name AS orgname
@ -62,6 +65,8 @@ SELECT s.ad_client_id,
JOIN m_locator ml ON ms.m_locator_id = ml.m_locator_id JOIN m_locator ml ON ms.m_locator_id = ml.m_locator_id
JOIN m_warehouse mw ON ml.m_warehouse_id = mw.m_warehouse_id JOIN m_warehouse mw ON ml.m_warehouse_id = mw.m_warehouse_id
JOIN m_productprice mpr ON ms.m_product_id = mpr.m_product_id JOIN m_productprice mpr ON ms.m_product_id = mpr.m_product_id
JOIN m_pricelist_version mplv ON mplv.m_pricelist_version_id = mpr.m_pricelist_version_id
JOIN m_pricelist mpl ON mplv.m_pricelist_id = mpl.m_pricelist_id
JOIN ad_org org ON org.ad_org_id = mw.ad_org_id JOIN ad_org org ON org.ad_org_id = mw.ad_org_id
GROUP BY r.ad_client_id, GROUP BY r.ad_client_id,
r.ad_org_id, r.ad_org_id,
@ -75,4 +80,5 @@ SELECT s.ad_client_id,
mw.m_warehouse_id, mw.m_warehouse_id,
mpr.m_pricelist_version_id, mpr.m_pricelist_version_id,
org.name, org.name,
mp.name; mp.name,
mpl.C_Currency_ID;

View File

@ -1,5 +1,4 @@
CREATE OR REPLACE VIEW rv_c_invoiceline CREATE OR REPLACE VIEW rv_c_invoiceline AS
AS
SELECT il.ad_client_id, SELECT il.ad_client_id,
il.ad_org_id, il.ad_org_id,
il.isactive, il.isactive,
@ -38,29 +37,16 @@ AS
il.priceactual, il.priceactual,
il.pricelimit, il.pricelimit,
il.priceentered, il.priceentered,
CASE CASE WHEN il.pricelist = 0 THEN 0 ELSE currencyRound((il.pricelist - il.priceactual) / il.pricelist * 100,i.C_Currency_ID,'N') END AS discount,
WHEN il.pricelist = 0 THEN 0 CASE WHEN il.pricelimit = 0 THEN 0 ELSE currencyRound((il.priceactual - il.pricelimit) / il.pricelimit * 100,i.C_Currency_ID,'N') END AS margin,
ELSE round(( il.pricelist - il.priceactual ) / il.pricelist * 100, 2) CASE WHEN il.pricelimit = 0 THEN 0 ELSE (il.priceactual - il.pricelimit) * il.qtyinvoiced END AS marginamt,
END AS discount, currencyRound(i.multiplier * il.linenetamt,i.C_Currency_ID,'N') AS linenetamt,
CASE currencyRound(i.multiplier * il.pricelist * il.qtyinvoiced,i.C_Currency_ID,'N') AS linelistamt,
WHEN il.pricelimit = 0 THEN 0 CASE WHEN COALESCE(il.pricelimit, 0) = 0 THEN currencyRound(i.multiplier * il.linenetamt,i.C_Currency_ID,'N') ELSE currencyRound(i.multiplier * il.pricelimit * il.qtyinvoiced,i.C_Currency_ID,'N') END
ELSE round(( il.priceactual - il.pricelimit ) / il.pricelimit * 100, 2) AS linelimitamt,
END AS margin, currencyRound(i.multiplier * il.pricelist * il.qtyinvoiced - il.linenetamt,i.C_Currency_ID,'N') AS linediscountamt,
CASE CASE WHEN COALESCE(il.pricelimit, 0) = 0 THEN 0 ELSE currencyRound(i.multiplier * il.linenetamt - il.pricelimit * il.qtyinvoiced,i.C_Currency_ID,'N') END AS
WHEN il.pricelimit = 0 THEN 0 lineoverlimitamt,
ELSE ( il.priceactual - il.pricelimit ) * il.qtyinvoiced
END AS marginamt,
round(i.multiplier * il.linenetamt, 2) AS linenetamt,
round(i.multiplier * il.pricelist * il.qtyinvoiced, 2) AS linelistamt,
CASE
WHEN COALESCE(il.pricelimit, 0) = 0 THEN round(i.multiplier * il.linenetamt, 2)
ELSE round(i.multiplier * il.pricelimit * il.qtyinvoiced, 2)
END AS linelimitamt,
round(i.multiplier * il.pricelist * il.qtyinvoiced - il.linenetamt, 2) AS linediscountamt,
CASE
WHEN COALESCE(il.pricelimit, 0) = 0 THEN 0
ELSE round(i.multiplier * il.linenetamt - il.pricelimit * il.qtyinvoiced, 2)
END AS lineoverlimitamt,
il.ad_orgtrx_id, il.ad_orgtrx_id,
il.a_processed, il.a_processed,
il.c_charge_id, il.c_charge_id,
@ -153,4 +139,3 @@ AS
LEFT JOIN m_attributesetinstance pasi LEFT JOIN m_attributesetinstance pasi
ON il.m_attributesetinstance_id = pasi.m_attributesetinstance_id ON il.m_attributesetinstance_id = pasi.m_attributesetinstance_id
; ;

View File

@ -11,14 +11,15 @@ SELECT il.AD_Client_ID, il.AD_Org_ID,
SUM(LineLimitAmt) AS LineLimitAmt, SUM(LineLimitAmt) AS LineLimitAmt,
SUM(LineDiscountAmt) AS LineDiscountAmt, SUM(LineDiscountAmt) AS LineDiscountAmt,
CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE
ROUND((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,2) END AS LineDiscount, currencyRound((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,i.C_Currency_ID,'N') END AS LineDiscount,
SUM(LineOverLimitAmt) AS LineOverLimitAmt, SUM(LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit, 100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
SUM(QtyInvoiced) AS QtyInvoiced, IsSOTrx SUM(QtyInvoiced) AS QtyInvoiced, il.IsSOTrx
FROM RV_C_InvoiceLine il FROM RV_C_InvoiceLine il
INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID)
GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.C_BPartner_ID, il.M_Product_Category_ID, GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.C_BPartner_ID, il.M_Product_Category_ID,
firstOf(il.DateInvoiced, 'Q'), IsSOTrx; firstOf(il.DateInvoiced, 'Q'), il.IsSOTrx, i.C_Currency_ID;

View File

@ -11,16 +11,17 @@ SELECT il.AD_Client_ID, il.AD_Org_ID,
SUM(LineLimitAmt) AS LineLimitAmt, SUM(LineLimitAmt) AS LineLimitAmt,
SUM(LineDiscountAmt) AS LineDiscountAmt, SUM(LineDiscountAmt) AS LineDiscountAmt,
CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE
ROUND((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,2) END AS LineDiscount, currencyRound((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,i.C_Currency_ID,'N') END AS LineDiscount,
SUM(LineOverLimitAmt) AS LineOverLimitAmt, SUM(LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit, 100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
SUM(QtyInvoiced) AS QtyInvoiced SUM(QtyInvoiced) AS QtyInvoiced
FROM RV_C_InvoiceLine il FROM RV_C_InvoiceLine il
INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID)
INNER JOIN M_Product_PO po ON (il.M_Product_ID=po.M_Product_ID) INNER JOIN M_Product_PO po ON (il.M_Product_ID=po.M_Product_ID)
WHERE il.IsSOTrx='Y' WHERE il.IsSOTrx='Y'
GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.C_BPartner_ID, po.C_BPartner_ID, GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.C_BPartner_ID, po.C_BPartner_ID,
firstOf(il.DateInvoiced, 'Q'); firstOf(il.DateInvoiced, 'Q'), i.C_Currency_ID;

View File

@ -3,21 +3,22 @@ CREATE OR REPLACE VIEW RV_C_INVOICE_DAY
LINELISTAMT, LINELIMITAMT, LINEDISCOUNTAMT, LINEDISCOUNT, LINEOVERLIMITAMT, LINELISTAMT, LINELIMITAMT, LINEDISCOUNTAMT, LINEDISCOUNT, LINEOVERLIMITAMT,
LINEOVERLIMIT, ISSOTRX) LINEOVERLIMIT, ISSOTRX)
AS AS
SELECT AD_Client_ID, AD_Org_ID, SalesRep_ID, SELECT il.AD_Client_ID, il.AD_Org_ID, il.SalesRep_ID,
firstOf(DateInvoiced, 'DD') AS DateInvoiced, -- DD Day, DY Week, MM Month firstOf(il.DateInvoiced, 'DD') AS DateInvoiced, -- DD Day, DY Week, MM Month
SUM(LineNetAmt) AS LineNetAmt, SUM(LineNetAmt) AS LineNetAmt,
SUM(LineListAmt) AS LineListAmt, SUM(LineListAmt) AS LineListAmt,
SUM(LineLimitAmt) AS LineLimitAmt, SUM(LineLimitAmt) AS LineLimitAmt,
SUM(LineDiscountAmt) AS LineDiscountAmt, SUM(LineDiscountAmt) AS LineDiscountAmt,
CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE
ROUND((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,2) END AS LineDiscount, currencyRound((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,i.C_Currency_ID,'N') END AS LineDiscount,
SUM(LineOverLimitAmt) AS LineOverLimitAmt, SUM(LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit, 100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
IsSOTrx il.IsSOTrx
FROM RV_C_InvoiceLine FROM RV_C_InvoiceLine il
GROUP BY AD_Client_ID, AD_Org_ID, SalesRep_ID, INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID)
firstOf(DateInvoiced, 'DD'), IsSOTrx; GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.SalesRep_ID,
firstOf(il.DateInvoiced, 'DD'), il.IsSOTrx, i.C_Currency_ID;

View File

@ -3,21 +3,22 @@ CREATE OR REPLACE VIEW RV_C_INVOICE_MONTH
LINELISTAMT, LINELIMITAMT, LINEDISCOUNTAMT, LINEDISCOUNT, LINEOVERLIMITAMT, LINELISTAMT, LINELIMITAMT, LINEDISCOUNTAMT, LINEDISCOUNT, LINEOVERLIMITAMT,
LINEOVERLIMIT, ISSOTRX) LINEOVERLIMIT, ISSOTRX)
AS AS
SELECT AD_Client_ID, AD_Org_ID, SalesRep_ID, SELECT il.AD_Client_ID, il.AD_Org_ID, il.SalesRep_ID,
firstOf(DateInvoiced, 'MM') AS DateInvoiced, -- DD Day, DY Week, MM Month firstOf(il.DateInvoiced, 'MM') AS DateInvoiced, -- DD Day, DY Week, MM Month
SUM(LineNetAmt) AS LineNetAmt, SUM(LineNetAmt) AS LineNetAmt,
SUM(LineListAmt) AS LineListAmt, SUM(LineListAmt) AS LineListAmt,
SUM(LineLimitAmt) AS LineLimitAmt, SUM(LineLimitAmt) AS LineLimitAmt,
SUM(LineDiscountAmt) AS LineDiscountAmt, SUM(LineDiscountAmt) AS LineDiscountAmt,
CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE
ROUND((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,2) END AS LineDiscount, currencyRound((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,i.C_Currency_ID,'N') END AS LineDiscount,
SUM(LineOverLimitAmt) AS LineOverLimitAmt, SUM(LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit, 100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
IsSOTrx il.IsSOTrx
FROM RV_C_InvoiceLine FROM RV_C_InvoiceLine il
GROUP BY AD_Client_ID, AD_Org_ID, SalesRep_ID, INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID)
firstOf(DateInvoiced, 'MM'), IsSOTrx; GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.SalesRep_ID,
firstOf(il.DateInvoiced, 'MM'), il.IsSOTrx, i.C_Currency_ID;

View File

@ -10,14 +10,15 @@ SELECT il.AD_Client_ID, il.AD_Org_ID, il.M_Product_Category_ID,
SUM(il.LineLimitAmt) AS LineLimitAmt, SUM(il.LineLimitAmt) AS LineLimitAmt,
SUM(il.LineDiscountAmt) AS LineDiscountAmt, SUM(il.LineDiscountAmt) AS LineDiscountAmt,
CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE
ROUND((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,2) END AS LineDiscount, currencyRound((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,i.C_Currency_ID,'N') END AS LineDiscount,
SUM(LineOverLimitAmt) AS LineOverLimitAmt, SUM(LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit, 100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
SUM(QtyInvoiced) AS QtyInvoiced, IsSOTrx SUM(QtyInvoiced) AS QtyInvoiced, il.IsSOTrx
FROM RV_C_InvoiceLine il FROM RV_C_InvoiceLine il
INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID)
GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.M_Product_Category_ID, GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.M_Product_Category_ID,
firstOf(il.DateInvoiced, 'MM'), IsSOTrx; firstOf(il.DateInvoiced, 'MM'), il.IsSOTrx, i.C_Currency_ID;

View File

@ -10,14 +10,15 @@ SELECT il.AD_Client_ID, il.AD_Org_ID, il.M_Product_ID,
SUM(il.LineLimitAmt) AS LineLimitAmt, SUM(il.LineLimitAmt) AS LineLimitAmt,
SUM(il.LineDiscountAmt) AS LineDiscountAmt, SUM(il.LineDiscountAmt) AS LineDiscountAmt,
CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE
ROUND((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,2) END AS LineDiscount, currencyRound((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,i.C_Currency_ID,'N') END AS LineDiscount,
SUM(LineOverLimitAmt) AS LineOverLimitAmt, SUM(LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit, 100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
SUM(QtyInvoiced) AS QtyInvoiced, IsSOTrx SUM(QtyInvoiced) AS QtyInvoiced, il.IsSOTrx
FROM RV_C_InvoiceLine il FROM RV_C_InvoiceLine il
INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID)
GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.M_Product_ID, GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.M_Product_ID,
firstOf(il.DateInvoiced, 'MM'), IsSOTrx; firstOf(il.DateInvoiced, 'MM'), il.IsSOTrx, i.C_Currency_ID;

View File

@ -10,14 +10,15 @@ SELECT il.AD_Client_ID, il.AD_Org_ID, il.M_Product_ID,
SUM(il.LineLimitAmt) AS LineLimitAmt, SUM(il.LineLimitAmt) AS LineLimitAmt,
SUM(il.LineDiscountAmt) AS LineDiscountAmt, SUM(il.LineDiscountAmt) AS LineDiscountAmt,
CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE
ROUND((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,2) END AS LineDiscount, currencyRound((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,i.C_Currency_ID,'N') END AS LineDiscount,
SUM(LineOverLimitAmt) AS LineOverLimitAmt, SUM(LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit, 100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
SUM(QtyInvoiced) AS QtyInvoiced, IsSOTrx SUM(QtyInvoiced) AS QtyInvoiced, il.IsSOTrx
FROM RV_C_InvoiceLine il FROM RV_C_InvoiceLine il
INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID)
GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.M_Product_ID, GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.M_Product_ID,
firstOf(il.DateInvoiced, 'Q'), IsSOTrx; firstOf(il.DateInvoiced, 'Q'), il.IsSOTrx, i.C_Currency_ID;

View File

@ -10,14 +10,15 @@ SELECT il.AD_Client_ID, il.AD_Org_ID, il.M_Product_Category_ID,
SUM(il.LineLimitAmt) AS LineLimitAmt, SUM(il.LineLimitAmt) AS LineLimitAmt,
SUM(il.LineDiscountAmt) AS LineDiscountAmt, SUM(il.LineDiscountAmt) AS LineDiscountAmt,
CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE
ROUND((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,2) END AS LineDiscount, currencyRound((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,i.C_Currency_ID,'N') END AS LineDiscount,
SUM(LineOverLimitAmt) AS LineOverLimitAmt, SUM(LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit, 100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
SUM(QtyInvoiced) AS QtyInvoiced, IsSOTrx SUM(QtyInvoiced) AS QtyInvoiced, il.IsSOTrx
FROM RV_C_InvoiceLine il FROM RV_C_InvoiceLine il
INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID)
GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.M_Product_Category_ID, GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.M_Product_Category_ID,
firstOf(il.DateInvoiced, 'DY'), IsSOTrx; firstOf(il.DateInvoiced, 'DY'), il.IsSOTrx, i.C_Currency_ID;

View File

@ -6,21 +6,22 @@ AS
SELECT il.AD_Client_ID, il.AD_Org_ID, SELECT il.AD_Client_ID, il.AD_Org_ID,
po.C_BPartner_ID, il.M_Product_Category_ID, po.C_BPartner_ID, il.M_Product_Category_ID,
firstOf(il.DateInvoiced, 'MM') AS DateInvoiced, -- DD Day, DY Week, MM Month firstOf(il.DateInvoiced, 'MM') AS DateInvoiced, -- DD Day, DY Week, MM Month
SUM(LineNetAmt) AS LineNetAmt, SUM(il.LineNetAmt) AS LineNetAmt,
SUM(LineListAmt) AS LineListAmt, SUM(LineListAmt) AS LineListAmt,
SUM(LineLimitAmt) AS LineLimitAmt, SUM(LineLimitAmt) AS LineLimitAmt,
SUM(LineDiscountAmt) AS LineDiscountAmt, SUM(LineDiscountAmt) AS LineDiscountAmt,
CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE
ROUND((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,2) END AS LineDiscount, currencyRound((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,i.C_Currency_ID,'N') END AS LineDiscount,
SUM(LineOverLimitAmt) AS LineOverLimitAmt, SUM(LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit, 100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
SUM(QtyInvoiced) AS QtyInvoiced SUM(QtyInvoiced) AS QtyInvoiced
FROM RV_C_InvoiceLine il FROM RV_C_InvoiceLine il
INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID)
INNER JOIN M_Product_PO po ON (il.M_Product_ID=po.M_Product_ID) INNER JOIN M_Product_PO po ON (il.M_Product_ID=po.M_Product_ID)
WHERE il.IsSOTrx='Y' WHERE il.IsSOTrx='Y'
GROUP BY il.AD_Client_ID, il.AD_Org_ID, po.C_BPartner_ID, il.M_Product_Category_ID, GROUP BY il.AD_Client_ID, il.AD_Org_ID, po.C_BPartner_ID, il.M_Product_Category_ID,
firstOf(il.DateInvoiced, 'MM'); firstOf(il.DateInvoiced, 'MM'), i.C_Currency_ID;

View File

@ -3,21 +3,22 @@ CREATE OR REPLACE VIEW RV_C_INVOICE_WEEK
LINELISTAMT, LINELIMITAMT, LINEDISCOUNTAMT, LINEDISCOUNT, LINEOVERLIMITAMT, LINELISTAMT, LINELIMITAMT, LINEDISCOUNTAMT, LINEDISCOUNT, LINEOVERLIMITAMT,
LINEOVERLIMIT, ISSOTRX) LINEOVERLIMIT, ISSOTRX)
AS AS
SELECT AD_Client_ID, AD_Org_ID, SalesRep_ID, SELECT il.AD_Client_ID, il.AD_Org_ID, il.SalesRep_ID,
firstOf(DateInvoiced, 'DY') AS DateInvoiced, -- DD Day, DY Week, MM Month firstOf(il.DateInvoiced, 'DY') AS DateInvoiced, -- DD Day, DY Week, MM Month
SUM(LineNetAmt) AS LineNetAmt, SUM(LineNetAmt) AS LineNetAmt,
SUM(LineListAmt) AS LineListAmt, SUM(LineListAmt) AS LineListAmt,
SUM(LineLimitAmt) AS LineLimitAmt, SUM(LineLimitAmt) AS LineLimitAmt,
SUM(LineDiscountAmt) AS LineDiscountAmt, SUM(LineDiscountAmt) AS LineDiscountAmt,
CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE
ROUND((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,2) END AS LineDiscount, currencyRound((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,i.C_Currency_ID,'N') END AS LineDiscount,
SUM(LineOverLimitAmt) AS LineOverLimitAmt, SUM(LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit, 100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
IsSOTrx il.IsSOTrx
FROM RV_C_InvoiceLine FROM RV_C_InvoiceLine il
GROUP BY AD_Client_ID, AD_Org_ID, SalesRep_ID, INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID)
firstOf(DateInvoiced, 'DY'), IsSOTrx; GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.SalesRep_ID,
firstOf(il.DateInvoiced, 'DY'), il.IsSOTrx, i.C_Currency_ID;

View File

@ -1,7 +1,6 @@
DROP VIEW rv_openitem; DROP VIEW rv_openitem;
CREATE OR REPLACE VIEW rv_openitem CREATE OR REPLACE VIEW rv_openitem AS
AS
SELECT i.ad_org_id, SELECT i.ad_org_id,
i.ad_client_id, i.ad_client_id,
i.documentno, i.documentno,
@ -15,7 +14,7 @@ AS
paymenttermduedate(i.c_paymentterm_id, i.dateinvoiced) AS duedate, paymenttermduedate(i.c_paymentterm_id, i.dateinvoiced) AS duedate,
paymenttermduedays(i.c_paymentterm_id, i.dateinvoiced, getdate()) AS daysdue, paymenttermduedays(i.c_paymentterm_id, i.dateinvoiced, getdate()) AS daysdue,
adddays(i.dateinvoiced, p.discountdays) AS discountdate, adddays(i.dateinvoiced, p.discountdays) AS discountdate,
round(i.grandtotal * p.discount / 100, 2) AS discountamt, currencyRound(i.grandtotal * p.discount / 100,i.C_Currency_ID,'N') AS discountamt,
i.grandtotal, i.grandtotal,
invoicepaid(i.c_invoice_id, i.c_currency_id, 1) AS paidamt, invoicepaid(i.c_invoice_id, i.c_currency_id, 1) AS paidamt,
invoiceopen(i.c_invoice_id, 0) AS openamt, invoiceopen(i.c_invoice_id, 0) AS openamt,
@ -74,9 +73,8 @@ AS
FROM rv_c_invoice i FROM rv_c_invoice i
JOIN c_paymentterm p JOIN c_paymentterm p
ON i.c_paymentterm_id = p.c_paymentterm_id ON i.c_paymentterm_id = p.c_paymentterm_id
WHERE invoiceopen(i.c_invoice_id, 0) <> 0 WHERE invoiceopen(i.c_invoice_id, 0) <> 0 AND i.ispayschedulevalid <> 'Y' AND i.docstatus IN ('CO',
AND i.ispayschedulevalid <> 'Y' 'CL')
AND i.docstatus IN ( 'CO', 'CL' )
UNION UNION
SELECT i.ad_org_id, SELECT i.ad_org_id,
i.ad_client_id, i.ad_client_id,
@ -150,9 +148,6 @@ AS
FROM rv_c_invoice i FROM rv_c_invoice i
JOIN c_invoicepayschedule ips JOIN c_invoicepayschedule ips
ON i.c_invoice_id = ips.c_invoice_id ON i.c_invoice_id = ips.c_invoice_id
WHERE invoiceopen(i.c_invoice_id, ips.c_invoicepayschedule_id) <> 0 WHERE invoiceopen(i.c_invoice_id, ips.c_invoicepayschedule_id) <> 0 AND i.ispayschedulevalid = 'Y' AND i.docstatus IN ('CO',
AND i.ispayschedulevalid = 'Y' 'CL') AND ips.isvalid = 'Y'
AND i.docstatus IN ( 'CO', 'CL' )
AND ips.isvalid = 'Y'
; ;

View File

@ -14,20 +14,19 @@ SELECT i.AD_Org_ID, i.AD_Client_ID,
paymentTermDueDate(i.C_PaymentTerm_ID, i.DateInvoiced) AS DueDate, paymentTermDueDate(i.C_PaymentTerm_ID, i.DateInvoiced) AS DueDate,
paymentTermDueDays(i.C_PaymentTerm_ID, i.DateInvoiced, getdate()) AS DaysDue, paymentTermDueDays(i.C_PaymentTerm_ID, i.DateInvoiced, getdate()) AS DaysDue,
addDays(i.DateInvoiced,p.DiscountDays) AS DiscountDate, addDays(i.DateInvoiced,p.DiscountDays) AS DiscountDate,
ROUND(i.GrandTotal*p.Discount/100,2) AS DiscountAmt, currencyRound(i.GrandTotal*p.Discount/100,i.C_Currency_ID,'N') AS DiscountAmt,
i.GrandTotal, i.GrandTotal,
--invoicePaid(i.C_Invoice_ID, i.C_Currency_ID, 1) AS PaidAmt, --invoicePaid(i.C_Invoice_ID, i.C_Currency_ID, 1) AS PaidAmt,
--invoiceOpen(i.C_Invoice_ID,0) AS OpenAmt, --invoiceOpen(i.C_Invoice_ID,0) AS OpenAmt,
i.C_Currency_ID, i.C_ConversionType_ID, i.C_Currency_ID, i.C_ConversionType_ID,
i.C_PaymentTerm_ID, i.C_PaymentTerm_ID,
i.IsPayScheduleValid, cast(null as number) AS C_InvoicePaySchedule_ID, i.InvoiceCollectionType, i.IsPayScheduleValid, cast(null as numeric) AS C_InvoicePaySchedule_ID, i.InvoiceCollectionType,
i.C_Campaign_ID, i.C_Project_ID, i.C_Activity_ID i.C_Campaign_ID, i.C_Project_ID, i.C_Activity_ID
FROM RV_C_Invoice i FROM RV_C_Invoice i
INNER JOIN C_PaymentTerm p ON (i.C_PaymentTerm_ID=p.C_PaymentTerm_ID) INNER JOIN C_PaymentTerm p ON (i.C_PaymentTerm_ID=p.C_PaymentTerm_ID)
WHERE -- i.IsPaid='N' WHERE -- i.IsPaid='N'
--invoiceOpen(i.C_Invoice_ID,0) <> 0 AND --invoiceOpen(i.C_Invoice_ID,0) <> 0 AND
i.IsPayScheduleValid<>'Y' i.IsPayScheduleValid<>'Y'
AND i.DocStatus<>'DR'
AND i.DocStatus IN ('CO','CL') AND i.DocStatus IN ('CO','CL')
UNION UNION
SELECT i.AD_Org_ID, i.AD_Client_ID, SELECT i.AD_Org_ID, i.AD_Client_ID,
@ -50,7 +49,6 @@ FROM RV_C_Invoice i
WHERE -- i.IsPaid='N' WHERE -- i.IsPaid='N'
--invoiceOpen(i.C_Invoice_ID,ips.C_InvoicePaySchedule_ID) <> 0 AND --invoiceOpen(i.C_Invoice_ID,ips.C_InvoicePaySchedule_ID) <> 0 AND
i.IsPayScheduleValid='Y' i.IsPayScheduleValid='Y'
AND i.DocStatus<>'DR'
AND i.DocStatus IN ('CO','CL') AND i.DocStatus IN ('CO','CL')
AND ips.IsValid='Y'; AND ips.IsValid='Y';

View File

@ -1,7 +1,6 @@
DROP VIEW rv_orderdetail; DROP VIEW rv_orderdetail;
CREATE OR REPLACE VIEW rv_orderdetail CREATE OR REPLACE VIEW rv_orderdetail AS
AS
SELECT l.ad_client_id, SELECT l.ad_client_id,
l.ad_org_id, l.ad_org_id,
l.isactive, l.isactive,
@ -56,18 +55,9 @@ AS
(l.qtyordered - l.qtyinvoiced) * l.priceactual AS netamttoinvoice, (l.qtyordered - l.qtyinvoiced) * l.priceactual AS netamttoinvoice,
l.qtylostsales, l.qtylostsales,
l.qtylostsales * l.priceactual AS amtlostsales, l.qtylostsales * l.priceactual AS amtlostsales,
CASE CASE WHEN l.pricelist = 0 THEN 0 ELSE currencyRound((l.pricelist - l.priceactual) / l.pricelist * 100,o.C_Currency_ID,'N') END AS discount,
WHEN l.pricelist = 0 THEN 0 CASE WHEN l.pricelimit = 0 THEN 0 ELSE currencyRound((l.priceactual - l.pricelimit) / l.pricelimit * 100,o.C_Currency_ID,'N') END AS margin,
ELSE round(( l.pricelist - l.priceactual ) / l.pricelist * 100, 2) CASE WHEN l.pricelimit = 0 THEN 0 ELSE (l.priceactual - l.pricelimit) * l.qtydelivered END AS marginamt,
END AS discount,
CASE
WHEN l.pricelimit = 0 THEN 0
ELSE round(( l.priceactual - l.pricelimit ) / l.pricelimit * 100, 2)
END AS margin,
CASE
WHEN l.pricelimit = 0 THEN 0
ELSE ( l.priceactual - l.pricelimit ) * l.qtydelivered
END AS marginamt,
o.ad_org_id AS c_order_ad_org_id, o.ad_org_id AS c_order_ad_org_id,
o.ad_orgtrx_id AS c_order_ad_orgtrx_id, o.ad_orgtrx_id AS c_order_ad_orgtrx_id,
o.amountrefunded, o.amountrefunded,
@ -175,4 +165,3 @@ AS
LEFT JOIN m_attributesetinstance pasi LEFT JOIN m_attributesetinstance pasi
ON l.m_attributesetinstance_id = pasi.m_attributesetinstance_id ON l.m_attributesetinstance_id = pasi.m_attributesetinstance_id
; ;

View File

@ -44,6 +44,8 @@ AS
$BODY$ $BODY$
DECLARE DECLARE
v_Currency_ID numeric(10); v_Currency_ID numeric(10);
v_Precision NUMERIC := 0;
v_Min NUMERIC := 0;
v_TotalOpenAmt numeric := 0; v_TotalOpenAmt numeric := 0;
v_PaidAmt numeric := 0; v_PaidAmt numeric := 0;
v_Remaining numeric := 0; v_Remaining numeric := 0;
@ -67,6 +69,13 @@ BEGIN
END; END;
-- DBMS_OUTPUT.PUT_LINE('== C_Invoice_ID=' || p_C_Invoice_ID || ', Total=' || v_TotalOpenAmt || ', AP=' || v_MultiplierAP || ', CM=' || v_MultiplierCM); -- DBMS_OUTPUT.PUT_LINE('== C_Invoice_ID=' || p_C_Invoice_ID || ', Total=' || v_TotalOpenAmt || ', AP=' || v_MultiplierAP || ', CM=' || v_MultiplierCM);
SELECT StdPrecision
INTO v_Precision
FROM C_Currency
WHERE C_Currency_ID = v_Currency_ID;
SELECT 1/10^v_Precision INTO v_Min;
-- Calculate Allocated Amount -- Calculate Allocated Amount
FOR allocationline IN FOR allocationline IN
SELECT a.AD_Client_ID, a.AD_Org_ID, SELECT a.AD_Client_ID, a.AD_Org_ID,
@ -113,12 +122,13 @@ BEGIN
-- DBMS_OUTPUT.PUT_LINE('== Total=' || v_TotalOpenAmt); -- DBMS_OUTPUT.PUT_LINE('== Total=' || v_TotalOpenAmt);
-- Ignore Rounding -- Ignore Rounding
IF (v_TotalOpenAmt BETWEEN -0.00999 AND 0.00999) THEN IF (v_TotalOpenAmt > -v_Min AND v_TotalOpenAmt < v_Min) THEN
v_TotalOpenAmt := 0; v_TotalOpenAmt := 0;
END IF; END IF;
-- Round to penny -- Round to currency precision
v_TotalOpenAmt := ROUND(COALESCE(v_TotalOpenAmt,0), 2); v_TotalOpenAmt := ROUND(COALESCE(v_TotalOpenAmt,0), v_Precision);
RETURN v_TotalOpenAmt; RETURN v_TotalOpenAmt;
END; END;
$BODY$ $BODY$

View File

@ -33,11 +33,20 @@ RETURNS numeric AS $body$
* *
************************************************************************/ ************************************************************************/
DECLARE DECLARE
v_Precision NUMERIC := 0;
v_Min NUMERIC := 0;
v_MultiplierAP NUMERIC := 1; v_MultiplierAP NUMERIC := 1;
v_PaymentAmt NUMERIC := 0; v_PaymentAmt NUMERIC := 0;
ar RECORD; ar RECORD;
BEGIN BEGIN
SELECT StdPrecision
INTO v_Precision
FROM C_Currency
WHERE C_Currency_ID = p_C_Currency_ID;
SELECT 1/10^v_Precision INTO v_Min;
-- Default -- Default
IF (p_MultiplierAP IS NOT NULL) THEN IF (p_MultiplierAP IS NOT NULL) THEN
v_MultiplierAP := p_MultiplierAP; v_MultiplierAP := p_MultiplierAP;
@ -56,8 +65,16 @@ BEGIN
+ currencyConvert(ar.Amount + ar.DisCountAmt + ar.WriteOffAmt, + currencyConvert(ar.Amount + ar.DisCountAmt + ar.WriteOffAmt,
ar.C_Currency_ID, p_C_Currency_ID, ar.DateTrx, null, ar.AD_Client_ID, ar.AD_Org_ID); ar.C_Currency_ID, p_C_Currency_ID, ar.DateTrx, null, ar.AD_Client_ID, ar.AD_Org_ID);
END LOOP; END LOOP;
--
RETURN ROUND(COALESCE(v_PaymentAmt,0), 2) * v_MultiplierAP; -- Ignore Rounding
IF (v_PaymentAmt > -v_Min AND v_PaymentAmt < v_Min) THEN
v_PaymentAmt := 0;
END IF;
-- Round to currency precision
v_PaymentAmt := ROUND(COALESCE(v_PaymentAmt,0), v_Precision);
RETURN v_PaymentAmt * v_MultiplierAP;
END; END;
$body$ LANGUAGE plpgsql; $body$ LANGUAGE plpgsql;

View File

@ -45,10 +45,19 @@ RETURNS numeric
AS AS
$BODY$ $BODY$
DECLARE DECLARE
v_Precision NUMERIC := 0;
v_Min NUMERIC := 0;
v_MultiplierAP numeric := 1; v_MultiplierAP numeric := 1;
v_PaymentAmt numeric := 0; v_PaymentAmt numeric := 0;
allocation record; allocation record;
BEGIN BEGIN
SELECT StdPrecision
INTO v_Precision
FROM C_Currency
WHERE C_Currency_ID = p_C_Currency_ID;
SELECT 1/10^v_Precision INTO v_Min;
-- Default -- Default
IF (p_MultiplierAP IS NOT NULL) THEN IF (p_MultiplierAP IS NOT NULL) THEN
v_MultiplierAP := p_MultiplierAP; v_MultiplierAP := p_MultiplierAP;
@ -64,8 +73,16 @@ BEGIN
+ Currencyconvert(allocation.Amount + allocation.DisCountAmt + allocation.WriteOffAmt, + Currencyconvert(allocation.Amount + allocation.DisCountAmt + allocation.WriteOffAmt,
allocation.C_Currency_ID, p_C_Currency_ID, allocation.DateTrx, NULL, allocation.AD_Client_ID, allocation.AD_Org_ID); allocation.C_Currency_ID, p_C_Currency_ID, allocation.DateTrx, NULL, allocation.AD_Client_ID, allocation.AD_Org_ID);
END LOOP; END LOOP;
--
RETURN ROUND(COALESCE(v_PaymentAmt,0), 2) * v_MultiplierAP; -- Ignore Rounding
IF (v_PaymentAmt > -v_Min AND v_PaymentAmt < v_Min) THEN
v_PaymentAmt := 0;
END IF;
-- Round to currency precision
v_PaymentAmt := ROUND(COALESCE(v_PaymentAmt,0), v_Precision);
RETURN v_PaymentAmt * v_MultiplierAP;
END; END;
$BODY$ $BODY$
LANGUAGE 'plpgsql' ; LANGUAGE 'plpgsql' ;

View File

@ -25,6 +25,8 @@ RETURNS NUMERIC AS $body$
************************************************************************/ ************************************************************************/
DECLARE DECLARE
v_Precision NUMERIC := 0;
v_Min NUMERIC := 0;
Discount NUMERIC := 0; Discount NUMERIC := 0;
Discount1Date timestamp with time zone; Discount1Date timestamp with time zone;
Discount2Date timestamp with time zone; Discount2Date timestamp with time zone;
@ -32,6 +34,13 @@ DECLARE
Add2Date NUMERIC := 0; Add2Date NUMERIC := 0;
p RECORD; p RECORD;
BEGIN BEGIN
SELECT StdPrecision
INTO v_Precision
FROM C_Currency
WHERE C_Currency_ID = Currency_ID;
SELECT 1/10^v_Precision INTO v_Min;
-- No Data - No Discount -- No Data - No Discount
IF (Amount IS NULL OR PaymentTerm_ID IS NULL OR DocDate IS NULL) THEN IF (Amount IS NULL OR PaymentTerm_ID IS NULL OR DocDate IS NULL) THEN
RETURN 0; RETURN 0;
@ -59,8 +68,16 @@ BEGIN
Discount := Amount * p.Discount2 / 100; Discount := Amount * p.Discount2 / 100;
END IF; END IF;
END LOOP; END LOOP;
--
RETURN ROUND(COALESCE(Discount,0), 2); -- fixed rounding -- Ignore Rounding
IF (Discount > -v_Min AND Discount < v_Min) THEN
Discount := 0;
END IF;
-- Round to currency precision
Discount := ROUND(COALESCE(Discount,0), v_Precision);
RETURN Discount;
END; END;
$body$ LANGUAGE plpgsql; $body$ LANGUAGE plpgsql;

View File

@ -28,10 +28,19 @@ RETURNS NUMERIC AS $body$
************************************************************************/ ************************************************************************/
DECLARE DECLARE
v_Precision NUMERIC := 0;
v_Min NUMERIC := 0;
v_AllocatedAmt NUMERIC := 0; v_AllocatedAmt NUMERIC := 0;
v_PayAmt NUMERIC; v_PayAmt NUMERIC;
r RECORD; r RECORD;
BEGIN BEGIN
SELECT StdPrecision
INTO v_Precision
FROM C_Currency
WHERE C_Currency_ID = p_C_Currency_ID;
SELECT 1/10^v_Precision INTO v_Min;
-- Charge - nothing available -- Charge - nothing available
SELECT SELECT
INTO v_PayAmt MAX(PayAmt) INTO v_PayAmt MAX(PayAmt)
@ -53,8 +62,15 @@ BEGIN
v_AllocatedAmt := v_AllocatedAmt v_AllocatedAmt := v_AllocatedAmt
+ currencyConvert(r.Amount, r.C_Currency_ID, p_C_Currency_ID, r.DateTrx, null, r.AD_Client_ID, r.AD_Org_ID); + currencyConvert(r.Amount, r.C_Currency_ID, p_C_Currency_ID, r.DateTrx, null, r.AD_Client_ID, r.AD_Org_ID);
END LOOP; END LOOP;
-- Round to penny
v_AllocatedAmt := ROUND(COALESCE(v_AllocatedAmt,0), 2); -- Ignore Rounding
IF (v_AllocatedAmt > -v_Min AND v_AllocatedAmt < v_Min) THEN
v_AllocatedAmt := 0;
END IF;
-- Round to currency precision
v_AllocatedAmt := ROUND(COALESCE(v_AllocatedAmt,0), v_Precision);
RETURN v_AllocatedAmt; RETURN v_AllocatedAmt;
END; END;

View File

@ -19,6 +19,8 @@ RETURNS NUMERIC AS $body$
************************************************************************/ ************************************************************************/
DECLARE DECLARE
v_Currency_ID NUMERIC(10); v_Currency_ID NUMERIC(10);
v_Precision NUMERIC := 0;
v_Min NUMERIC := 0;
v_AvailableAmt NUMERIC := 0; v_AvailableAmt NUMERIC := 0;
v_IsReceipt C_Payment.IsReceipt%TYPE; v_IsReceipt C_Payment.IsReceipt%TYPE;
v_Amt NUMERIC := 0; v_Amt NUMERIC := 0;
@ -41,6 +43,13 @@ BEGIN
WHERE C_Payment_ID = p_C_Payment_ID; 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); -- DBMS_OUTPUT.PUT_LINE('== C_Payment_ID=' || p_C_Payment_ID || ', PayAmt=' || v_AvailableAmt || ', Receipt=' || v_IsReceipt);
SELECT StdPrecision
INTO v_Precision
FROM C_Currency
WHERE C_Currency_ID = v_Currency_ID;
SELECT 1/10^v_Precision INTO v_Min;
-- Calculate Allocated Amount -- Calculate Allocated Amount
FOR r IN FOR r IN
SELECT a.AD_Client_ID, a.AD_Org_ID, al.Amount, a.C_Currency_ID, a.DateTrx SELECT a.AD_Client_ID, a.AD_Org_ID, al.Amount, a.C_Currency_ID, a.DateTrx
@ -53,12 +62,15 @@ BEGIN
v_AvailableAmt := v_AvailableAmt - v_Amt; v_AvailableAmt := v_AvailableAmt - v_Amt;
-- DBMS_OUTPUT.PUT_LINE(' Allocation=' || a.Amount || ' - Available=' || v_AvailableAmt); -- DBMS_OUTPUT.PUT_LINE(' Allocation=' || a.Amount || ' - Available=' || v_AvailableAmt);
END LOOP; END LOOP;
-- Ignore Rounding -- Ignore Rounding
IF (v_AvailableAmt BETWEEN -0.00999 AND 0.00999) THEN IF (v_AvailableAmt > -v_Min AND v_AvailableAmt < v_Min) THEN
v_AvailableAmt := 0; v_AvailableAmt := 0;
END IF; END IF;
-- Round to penny
v_AvailableAmt := ROUND(COALESCE(v_AvailableAmt,0), 2); -- Round to currency precision
v_AvailableAmt := ROUND(COALESCE(v_AvailableAmt,0), v_Precision);
RETURN v_AvailableAmt; RETURN v_AvailableAmt;
END; END;

View File

@ -11,11 +11,11 @@ SELECT il.AD_Client_ID, il.AD_Org_ID,
i.C_BPartner_ID, il.M_Product_ID, i.C_BPartner_ID, il.M_Product_ID,
i.DocumentNo, i.DateInvoiced, i.DateAcct, i.DocumentNo, i.DateInvoiced, i.DateAcct,
i.IsSOTrx, i.DocStatus, i.IsSOTrx, i.DocStatus,
ROUND(i.Multiplier*LineNetAmt, 2) AS LineNetAmt, currencyRound(i.Multiplier*LineNetAmt,i.C_Currency_ID,'N') AS LineNetAmt,
ROUND(i.Multiplier*PriceList*QtyInvoiced, 2) AS LineListAmt, currencyRound(i.Multiplier*PriceList*QtyInvoiced,i.C_Currency_ID,'N') AS LineListAmt,
CASE WHEN COALESCE(il.PriceLimit, 0)=0 THEN ROUND(i.Multiplier*LineNetAmt,2) ELSE ROUND(i.Multiplier*il.PriceLimit*il.QtyInvoiced,2) END AS LineLimitAmt, CASE WHEN COALESCE(il.PriceLimit, 0)=0 THEN currencyRound(i.Multiplier*LineNetAmt,i.C_Currency_ID,'N') ELSE currencyRound(i.Multiplier*il.PriceLimit*il.QtyInvoiced,i.C_Currency_ID,'N') END AS LineLimitAmt,
ROUND(i.Multiplier*il.PriceList*il.QtyInvoiced-il.LineNetAmt,2) AS LineDiscountAmt, currencyRound(i.Multiplier*il.PriceList*il.QtyInvoiced-il.LineNetAmt,i.C_Currency_ID,'N') AS LineDiscountAmt,
CASE WHEN COALESCE(il.PriceLimit,0)=0 THEN 0 ELSE ROUND(i.Multiplier*il.LineNetAmt-il.PriceLimit*il.QtyInvoiced,2) END AS LineOverLimitAmt, CASE WHEN COALESCE(il.PriceLimit,0)=0 THEN 0 ELSE currencyRound(i.Multiplier*il.LineNetAmt-il.PriceLimit*il.QtyInvoiced,i.C_Currency_ID,'N') END AS LineOverLimitAmt,
il.QtyInvoiced, il.QtyEntered, il.QtyInvoiced, il.QtyEntered,
il.Line, il.C_OrderLine_ID, il.C_UOM_ID, il.Line, il.C_OrderLine_ID, il.C_UOM_ID,
il.C_Campaign_ID, il.C_Project_ID, il.C_Activity_ID, il.C_ProjectPhase_ID, il.C_ProjectTask_ID il.C_Campaign_ID, il.C_Project_ID, il.C_Activity_ID, il.C_ProjectPhase_ID, il.C_ProjectTask_ID

View File

@ -13,7 +13,7 @@ SELECT s.ad_client_id,
sum(ms.qtyonhand - ms.qtyreserved) AS qtyavailable, sum(ms.qtyonhand - ms.qtyreserved) AS qtyavailable,
sum(ms.qtyonhand) AS qtyonhand, sum(ms.qtyonhand) AS qtyonhand,
sum(ms.qtyreserved) AS qtyreserved, sum(ms.qtyreserved) AS qtyreserved,
ROUND(MAX(mpr.pricestd),0) AS pricestd, currencyRound(MAX(mpr.pricestd),mpl.C_Currency_ID,'N') AS pricestd,
mpr.m_pricelist_version_id, mpr.m_pricelist_version_id,
mw.m_warehouse_id, mw.m_warehouse_id,
org.name AS orgname org.name AS orgname
@ -23,6 +23,8 @@ SELECT s.ad_client_id,
JOIN m_locator ml ON ms.m_locator_id = ml.m_locator_id JOIN m_locator ml ON ms.m_locator_id = ml.m_locator_id
JOIN m_warehouse mw ON ml.m_warehouse_id = mw.m_warehouse_id JOIN m_warehouse mw ON ml.m_warehouse_id = mw.m_warehouse_id
JOIN m_productprice mpr ON ms.m_product_id = mpr.m_product_id JOIN m_productprice mpr ON ms.m_product_id = mpr.m_product_id
JOIN m_pricelist_version mplv ON mplv.m_pricelist_version_id = mpr.m_pricelist_version_id
JOIN m_pricelist mpl ON mplv.m_pricelist_id = mpl.m_pricelist_id
JOIN ad_org org ON org.ad_org_id = mw.ad_org_id JOIN ad_org org ON org.ad_org_id = mw.ad_org_id
GROUP BY s.ad_client_id, GROUP BY s.ad_client_id,
s.ad_org_id, s.ad_org_id,
@ -36,7 +38,8 @@ SELECT s.ad_client_id,
mw.m_warehouse_id, mw.m_warehouse_id,
mpr.m_pricelist_version_id, mpr.m_pricelist_version_id,
org.name, org.name,
mp.name mp.name,
mpl.C_Currency_ID
UNION UNION
SELECT r.ad_client_id, SELECT r.ad_client_id,
r.ad_org_id, r.ad_org_id,
@ -52,7 +55,7 @@ SELECT s.ad_client_id,
sum(ms.qtyonhand - ms.qtyreserved) AS qtyavailable, sum(ms.qtyonhand - ms.qtyreserved) AS qtyavailable,
sum(ms.qtyonhand) AS qtyonhand, sum(ms.qtyonhand) AS qtyonhand,
sum(ms.qtyreserved) AS qtyreserved, sum(ms.qtyreserved) AS qtyreserved,
ROUND(MAX(mpr.pricestd),0) AS pricestd, currencyRound(MAX(mpr.pricestd),mpl.C_Currency_ID,'N') AS pricestd,
mpr.m_pricelist_version_id, mpr.m_pricelist_version_id,
mw.m_warehouse_id, mw.m_warehouse_id,
org.name AS orgname org.name AS orgname
@ -62,6 +65,8 @@ SELECT s.ad_client_id,
JOIN m_locator ml ON ms.m_locator_id = ml.m_locator_id JOIN m_locator ml ON ms.m_locator_id = ml.m_locator_id
JOIN m_warehouse mw ON ml.m_warehouse_id = mw.m_warehouse_id JOIN m_warehouse mw ON ml.m_warehouse_id = mw.m_warehouse_id
JOIN m_productprice mpr ON ms.m_product_id = mpr.m_product_id JOIN m_productprice mpr ON ms.m_product_id = mpr.m_product_id
JOIN m_pricelist_version mplv ON mplv.m_pricelist_version_id = mpr.m_pricelist_version_id
JOIN m_pricelist mpl ON mplv.m_pricelist_id = mpl.m_pricelist_id
JOIN ad_org org ON org.ad_org_id = mw.ad_org_id JOIN ad_org org ON org.ad_org_id = mw.ad_org_id
GROUP BY r.ad_client_id, GROUP BY r.ad_client_id,
r.ad_org_id, r.ad_org_id,
@ -75,4 +80,5 @@ SELECT s.ad_client_id,
mw.m_warehouse_id, mw.m_warehouse_id,
mpr.m_pricelist_version_id, mpr.m_pricelist_version_id,
org.name, org.name,
mp.name; mp.name,
mpl.C_Currency_ID;

View File

@ -37,15 +37,15 @@ SELECT il.ad_client_id,
il.priceactual, il.priceactual,
il.pricelimit, il.pricelimit,
il.priceentered, il.priceentered,
CASE WHEN il.pricelist = 0 THEN 0 ELSE round((il.pricelist - il.priceactual) / il.pricelist * 100, 2) END AS discount, CASE WHEN il.pricelist = 0 THEN 0 ELSE currencyRound((il.pricelist - il.priceactual) / il.pricelist * 100,i.C_Currency_ID,'N') END AS discount,
CASE WHEN il.pricelimit = 0 THEN 0 ELSE round((il.priceactual - il.pricelimit) / il.pricelimit * 100, 2) END AS margin, CASE WHEN il.pricelimit = 0 THEN 0 ELSE currencyRound((il.priceactual - il.pricelimit) / il.pricelimit * 100,i.C_Currency_ID,'N') END AS margin,
CASE WHEN il.pricelimit = 0 THEN 0 ELSE (il.priceactual - il.pricelimit) * il.qtyinvoiced END AS marginamt, CASE WHEN il.pricelimit = 0 THEN 0 ELSE (il.priceactual - il.pricelimit) * il.qtyinvoiced END AS marginamt,
round(i.multiplier * il.linenetamt, 2) AS linenetamt, currencyRound(i.multiplier * il.linenetamt,i.C_Currency_ID,'N') AS linenetamt,
round(i.multiplier * il.pricelist * il.qtyinvoiced, 2) AS linelistamt, currencyRound(i.multiplier * il.pricelist * il.qtyinvoiced,i.C_Currency_ID,'N') AS linelistamt,
CASE WHEN COALESCE(il.pricelimit, 0) = 0 THEN round(i.multiplier * il.linenetamt, 2) ELSE round(i.multiplier * il.pricelimit * il.qtyinvoiced, 2) END CASE WHEN COALESCE(il.pricelimit, 0) = 0 THEN currencyRound(i.multiplier * il.linenetamt,i.C_Currency_ID,'N') ELSE currencyRound(i.multiplier * il.pricelimit * il.qtyinvoiced,i.C_Currency_ID,'N') END
AS linelimitamt, AS linelimitamt,
round(i.multiplier * il.pricelist * il.qtyinvoiced - il.linenetamt, 2) AS linediscountamt, currencyRound(i.multiplier * il.pricelist * il.qtyinvoiced - il.linenetamt,i.C_Currency_ID,'N') AS linediscountamt,
CASE WHEN COALESCE(il.pricelimit, 0) = 0 THEN 0 ELSE round(i.multiplier * il.linenetamt - il.pricelimit * il.qtyinvoiced, 2) END AS CASE WHEN COALESCE(il.pricelimit, 0) = 0 THEN 0 ELSE currencyRound(i.multiplier * il.linenetamt - il.pricelimit * il.qtyinvoiced,i.C_Currency_ID,'N') END AS
lineoverlimitamt, lineoverlimitamt,
il.ad_orgtrx_id, il.ad_orgtrx_id,
il.a_processed, il.a_processed,

View File

@ -11,14 +11,15 @@ SELECT il.AD_Client_ID, il.AD_Org_ID,
SUM(LineLimitAmt) AS LineLimitAmt, SUM(LineLimitAmt) AS LineLimitAmt,
SUM(LineDiscountAmt) AS LineDiscountAmt, SUM(LineDiscountAmt) AS LineDiscountAmt,
CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE
ROUND((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,2) END AS LineDiscount, currencyRound((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,i.C_Currency_ID,'N') END AS LineDiscount,
SUM(LineOverLimitAmt) AS LineOverLimitAmt, SUM(LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit, 100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
SUM(QtyInvoiced) AS QtyInvoiced, IsSOTrx SUM(QtyInvoiced) AS QtyInvoiced, il.IsSOTrx
FROM RV_C_InvoiceLine il FROM RV_C_InvoiceLine il
INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID)
GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.C_BPartner_ID, il.M_Product_Category_ID, GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.C_BPartner_ID, il.M_Product_Category_ID,
firstOf(il.DateInvoiced, 'Q'), IsSOTrx; firstOf(il.DateInvoiced, 'Q'), il.IsSOTrx, i.C_Currency_ID;

View File

@ -11,16 +11,17 @@ SELECT il.AD_Client_ID, il.AD_Org_ID,
SUM(LineLimitAmt) AS LineLimitAmt, SUM(LineLimitAmt) AS LineLimitAmt,
SUM(LineDiscountAmt) AS LineDiscountAmt, SUM(LineDiscountAmt) AS LineDiscountAmt,
CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE
ROUND((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,2) END AS LineDiscount, currencyRound((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,i.C_Currency_ID,'N') END AS LineDiscount,
SUM(LineOverLimitAmt) AS LineOverLimitAmt, SUM(LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit, 100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
SUM(QtyInvoiced) AS QtyInvoiced SUM(QtyInvoiced) AS QtyInvoiced
FROM RV_C_InvoiceLine il FROM RV_C_InvoiceLine il
INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID)
INNER JOIN M_Product_PO po ON (il.M_Product_ID=po.M_Product_ID) INNER JOIN M_Product_PO po ON (il.M_Product_ID=po.M_Product_ID)
WHERE il.IsSOTrx='Y' WHERE il.IsSOTrx='Y'
GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.C_BPartner_ID, po.C_BPartner_ID, GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.C_BPartner_ID, po.C_BPartner_ID,
firstOf(il.DateInvoiced, 'Q'); firstOf(il.DateInvoiced, 'Q'), i.C_Currency_ID;

View File

@ -3,21 +3,22 @@ CREATE OR REPLACE VIEW RV_C_INVOICE_DAY
LINELISTAMT, LINELIMITAMT, LINEDISCOUNTAMT, LINEDISCOUNT, LINEOVERLIMITAMT, LINELISTAMT, LINELIMITAMT, LINEDISCOUNTAMT, LINEDISCOUNT, LINEOVERLIMITAMT,
LINEOVERLIMIT, ISSOTRX) LINEOVERLIMIT, ISSOTRX)
AS AS
SELECT AD_Client_ID, AD_Org_ID, SalesRep_ID, SELECT il.AD_Client_ID, il.AD_Org_ID, il.SalesRep_ID,
firstOf(DateInvoiced, 'DD') AS DateInvoiced, -- DD Day, DY Week, MM Month firstOf(il.DateInvoiced, 'DD') AS DateInvoiced, -- DD Day, DY Week, MM Month
SUM(LineNetAmt) AS LineNetAmt, SUM(LineNetAmt) AS LineNetAmt,
SUM(LineListAmt) AS LineListAmt, SUM(LineListAmt) AS LineListAmt,
SUM(LineLimitAmt) AS LineLimitAmt, SUM(LineLimitAmt) AS LineLimitAmt,
SUM(LineDiscountAmt) AS LineDiscountAmt, SUM(LineDiscountAmt) AS LineDiscountAmt,
CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE
ROUND((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,2) END AS LineDiscount, currencyRound((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,i.C_Currency_ID,'N') END AS LineDiscount,
SUM(LineOverLimitAmt) AS LineOverLimitAmt, SUM(LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit, 100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
IsSOTrx il.IsSOTrx
FROM RV_C_InvoiceLine FROM RV_C_InvoiceLine il
GROUP BY AD_Client_ID, AD_Org_ID, SalesRep_ID, INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID)
firstOf(DateInvoiced, 'DD'), IsSOTrx; GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.SalesRep_ID,
firstOf(il.DateInvoiced, 'DD'), il.IsSOTrx, i.C_Currency_ID;

View File

@ -3,21 +3,22 @@ CREATE OR REPLACE VIEW RV_C_INVOICE_MONTH
LINELISTAMT, LINELIMITAMT, LINEDISCOUNTAMT, LINEDISCOUNT, LINEOVERLIMITAMT, LINELISTAMT, LINELIMITAMT, LINEDISCOUNTAMT, LINEDISCOUNT, LINEOVERLIMITAMT,
LINEOVERLIMIT, ISSOTRX) LINEOVERLIMIT, ISSOTRX)
AS AS
SELECT AD_Client_ID, AD_Org_ID, SalesRep_ID, SELECT il.AD_Client_ID, il.AD_Org_ID, il.SalesRep_ID,
firstOf(DateInvoiced, 'MM') AS DateInvoiced, -- DD Day, DY Week, MM Month firstOf(il.DateInvoiced, 'MM') AS DateInvoiced, -- DD Day, DY Week, MM Month
SUM(LineNetAmt) AS LineNetAmt, SUM(LineNetAmt) AS LineNetAmt,
SUM(LineListAmt) AS LineListAmt, SUM(LineListAmt) AS LineListAmt,
SUM(LineLimitAmt) AS LineLimitAmt, SUM(LineLimitAmt) AS LineLimitAmt,
SUM(LineDiscountAmt) AS LineDiscountAmt, SUM(LineDiscountAmt) AS LineDiscountAmt,
CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE
ROUND((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,2) END AS LineDiscount, currencyRound((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,i.C_Currency_ID,'N') END AS LineDiscount,
SUM(LineOverLimitAmt) AS LineOverLimitAmt, SUM(LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit, 100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
IsSOTrx il.IsSOTrx
FROM RV_C_InvoiceLine FROM RV_C_InvoiceLine il
GROUP BY AD_Client_ID, AD_Org_ID, SalesRep_ID, INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID)
firstOf(DateInvoiced, 'MM'), IsSOTrx; GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.SalesRep_ID,
firstOf(il.DateInvoiced, 'MM'), il.IsSOTrx, i.C_Currency_ID;

View File

@ -10,14 +10,15 @@ SELECT il.AD_Client_ID, il.AD_Org_ID, il.M_Product_Category_ID,
SUM(il.LineLimitAmt) AS LineLimitAmt, SUM(il.LineLimitAmt) AS LineLimitAmt,
SUM(il.LineDiscountAmt) AS LineDiscountAmt, SUM(il.LineDiscountAmt) AS LineDiscountAmt,
CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE
ROUND((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,2) END AS LineDiscount, currencyRound((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,i.C_Currency_ID,'N') END AS LineDiscount,
SUM(LineOverLimitAmt) AS LineOverLimitAmt, SUM(LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit, 100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
SUM(QtyInvoiced) AS QtyInvoiced, IsSOTrx SUM(QtyInvoiced) AS QtyInvoiced, il.IsSOTrx
FROM RV_C_InvoiceLine il FROM RV_C_InvoiceLine il
INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID)
GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.M_Product_Category_ID, GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.M_Product_Category_ID,
firstOf(il.DateInvoiced, 'MM'), IsSOTrx; firstOf(il.DateInvoiced, 'MM'), il.IsSOTrx, i.C_Currency_ID;

View File

@ -10,14 +10,15 @@ SELECT il.AD_Client_ID, il.AD_Org_ID, il.M_Product_ID,
SUM(il.LineLimitAmt) AS LineLimitAmt, SUM(il.LineLimitAmt) AS LineLimitAmt,
SUM(il.LineDiscountAmt) AS LineDiscountAmt, SUM(il.LineDiscountAmt) AS LineDiscountAmt,
CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE
ROUND((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,2) END AS LineDiscount, currencyRound((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,i.C_Currency_ID,'N') END AS LineDiscount,
SUM(LineOverLimitAmt) AS LineOverLimitAmt, SUM(LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit, 100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
SUM(QtyInvoiced) AS QtyInvoiced, IsSOTrx SUM(QtyInvoiced) AS QtyInvoiced, il.IsSOTrx
FROM RV_C_InvoiceLine il FROM RV_C_InvoiceLine il
INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID)
GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.M_Product_ID, GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.M_Product_ID,
firstOf(il.DateInvoiced, 'MM'), IsSOTrx; firstOf(il.DateInvoiced, 'MM'), il.IsSOTrx, i.C_Currency_ID;

View File

@ -10,14 +10,15 @@ SELECT il.AD_Client_ID, il.AD_Org_ID, il.M_Product_ID,
SUM(il.LineLimitAmt) AS LineLimitAmt, SUM(il.LineLimitAmt) AS LineLimitAmt,
SUM(il.LineDiscountAmt) AS LineDiscountAmt, SUM(il.LineDiscountAmt) AS LineDiscountAmt,
CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE
ROUND((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,2) END AS LineDiscount, currencyRound((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,i.C_Currency_ID,'N') END AS LineDiscount,
SUM(LineOverLimitAmt) AS LineOverLimitAmt, SUM(LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit, 100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
SUM(QtyInvoiced) AS QtyInvoiced, IsSOTrx SUM(QtyInvoiced) AS QtyInvoiced, il.IsSOTrx
FROM RV_C_InvoiceLine il FROM RV_C_InvoiceLine il
INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID)
GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.M_Product_ID, GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.M_Product_ID,
firstOf(il.DateInvoiced, 'Q'), IsSOTrx; firstOf(il.DateInvoiced, 'Q'), il.IsSOTrx, i.C_Currency_ID;

View File

@ -10,14 +10,15 @@ SELECT il.AD_Client_ID, il.AD_Org_ID, il.M_Product_Category_ID,
SUM(il.LineLimitAmt) AS LineLimitAmt, SUM(il.LineLimitAmt) AS LineLimitAmt,
SUM(il.LineDiscountAmt) AS LineDiscountAmt, SUM(il.LineDiscountAmt) AS LineDiscountAmt,
CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE
ROUND((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,2) END AS LineDiscount, currencyRound((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,i.C_Currency_ID,'N') END AS LineDiscount,
SUM(LineOverLimitAmt) AS LineOverLimitAmt, SUM(LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit, 100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
SUM(QtyInvoiced) AS QtyInvoiced, IsSOTrx SUM(QtyInvoiced) AS QtyInvoiced, il.IsSOTrx
FROM RV_C_InvoiceLine il FROM RV_C_InvoiceLine il
INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID)
GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.M_Product_Category_ID, GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.M_Product_Category_ID,
firstOf(il.DateInvoiced, 'DY'), IsSOTrx; firstOf(il.DateInvoiced, 'DY'), il.IsSOTrx, i.C_Currency_ID;

View File

@ -6,21 +6,22 @@ AS
SELECT il.AD_Client_ID, il.AD_Org_ID, SELECT il.AD_Client_ID, il.AD_Org_ID,
po.C_BPartner_ID, il.M_Product_Category_ID, po.C_BPartner_ID, il.M_Product_Category_ID,
firstOf(il.DateInvoiced, 'MM') AS DateInvoiced, -- DD Day, DY Week, MM Month firstOf(il.DateInvoiced, 'MM') AS DateInvoiced, -- DD Day, DY Week, MM Month
SUM(LineNetAmt) AS LineNetAmt, SUM(il.LineNetAmt) AS LineNetAmt,
SUM(LineListAmt) AS LineListAmt, SUM(LineListAmt) AS LineListAmt,
SUM(LineLimitAmt) AS LineLimitAmt, SUM(LineLimitAmt) AS LineLimitAmt,
SUM(LineDiscountAmt) AS LineDiscountAmt, SUM(LineDiscountAmt) AS LineDiscountAmt,
CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE
ROUND((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,2) END AS LineDiscount, currencyRound((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,i.C_Currency_ID,'N') END AS LineDiscount,
SUM(LineOverLimitAmt) AS LineOverLimitAmt, SUM(LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit, 100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
SUM(QtyInvoiced) AS QtyInvoiced SUM(QtyInvoiced) AS QtyInvoiced
FROM RV_C_InvoiceLine il FROM RV_C_InvoiceLine il
INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID)
INNER JOIN M_Product_PO po ON (il.M_Product_ID=po.M_Product_ID) INNER JOIN M_Product_PO po ON (il.M_Product_ID=po.M_Product_ID)
WHERE il.IsSOTrx='Y' WHERE il.IsSOTrx='Y'
GROUP BY il.AD_Client_ID, il.AD_Org_ID, po.C_BPartner_ID, il.M_Product_Category_ID, GROUP BY il.AD_Client_ID, il.AD_Org_ID, po.C_BPartner_ID, il.M_Product_Category_ID,
firstOf(il.DateInvoiced, 'MM'); firstOf(il.DateInvoiced, 'MM'), i.C_Currency_ID;

View File

@ -3,21 +3,22 @@ CREATE OR REPLACE VIEW RV_C_INVOICE_WEEK
LINELISTAMT, LINELIMITAMT, LINEDISCOUNTAMT, LINEDISCOUNT, LINEOVERLIMITAMT, LINELISTAMT, LINELIMITAMT, LINEDISCOUNTAMT, LINEDISCOUNT, LINEOVERLIMITAMT,
LINEOVERLIMIT, ISSOTRX) LINEOVERLIMIT, ISSOTRX)
AS AS
SELECT AD_Client_ID, AD_Org_ID, SalesRep_ID, SELECT il.AD_Client_ID, il.AD_Org_ID, il.SalesRep_ID,
firstOf(DateInvoiced, 'DY') AS DateInvoiced, -- DD Day, DY Week, MM Month firstOf(il.DateInvoiced, 'DY') AS DateInvoiced, -- DD Day, DY Week, MM Month
SUM(LineNetAmt) AS LineNetAmt, SUM(LineNetAmt) AS LineNetAmt,
SUM(LineListAmt) AS LineListAmt, SUM(LineListAmt) AS LineListAmt,
SUM(LineLimitAmt) AS LineLimitAmt, SUM(LineLimitAmt) AS LineLimitAmt,
SUM(LineDiscountAmt) AS LineDiscountAmt, SUM(LineDiscountAmt) AS LineDiscountAmt,
CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineListAmt)=0 THEN 0 ELSE
ROUND((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,2) END AS LineDiscount, currencyRound((SUM(LineListAmt)-SUM(LineNetAmt))/SUM(LineListAmt)*100,i.C_Currency_ID,'N') END AS LineDiscount,
SUM(LineOverLimitAmt) AS LineOverLimitAmt, SUM(LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit, 100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
IsSOTrx il.IsSOTrx
FROM RV_C_InvoiceLine FROM RV_C_InvoiceLine il
GROUP BY AD_Client_ID, AD_Org_ID, SalesRep_ID, INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID)
firstOf(DateInvoiced, 'DY'), IsSOTrx; GROUP BY il.AD_Client_ID, il.AD_Org_ID, il.SalesRep_ID,
firstOf(il.DateInvoiced, 'DY'), il.IsSOTrx, i.C_Currency_ID;

View File

@ -14,7 +14,7 @@ SELECT i.ad_org_id,
paymenttermduedate(i.c_paymentterm_id, i.dateinvoiced) AS duedate, paymenttermduedate(i.c_paymentterm_id, i.dateinvoiced) AS duedate,
paymenttermduedays(i.c_paymentterm_id, i.dateinvoiced, getdate()) AS daysdue, paymenttermduedays(i.c_paymentterm_id, i.dateinvoiced, getdate()) AS daysdue,
adddays(i.dateinvoiced, p.discountdays) AS discountdate, adddays(i.dateinvoiced, p.discountdays) AS discountdate,
round(i.grandtotal * p.discount / 100, 2) AS discountamt, currencyRound(i.grandtotal * p.discount / 100,i.C_Currency_ID,'N') AS discountamt,
i.grandtotal, i.grandtotal,
invoicepaid(i.c_invoice_id, i.c_currency_id, 1) AS paidamt, invoicepaid(i.c_invoice_id, i.c_currency_id, 1) AS paidamt,
invoiceopen(i.c_invoice_id, 0) AS openamt, invoiceopen(i.c_invoice_id, 0) AS openamt,

View File

@ -14,7 +14,7 @@ SELECT i.AD_Org_ID, i.AD_Client_ID,
paymentTermDueDate(i.C_PaymentTerm_ID, i.DateInvoiced) AS DueDate, paymentTermDueDate(i.C_PaymentTerm_ID, i.DateInvoiced) AS DueDate,
paymentTermDueDays(i.C_PaymentTerm_ID, i.DateInvoiced, getdate()) AS DaysDue, paymentTermDueDays(i.C_PaymentTerm_ID, i.DateInvoiced, getdate()) AS DaysDue,
addDays(i.DateInvoiced,p.DiscountDays) AS DiscountDate, addDays(i.DateInvoiced,p.DiscountDays) AS DiscountDate,
ROUND(i.GrandTotal*p.Discount/100,2) AS DiscountAmt, currencyRound(i.GrandTotal*p.Discount/100,i.C_Currency_ID,'N') AS DiscountAmt,
i.GrandTotal, i.GrandTotal,
--invoicePaid(i.C_Invoice_ID, i.C_Currency_ID, 1) AS PaidAmt, --invoicePaid(i.C_Invoice_ID, i.C_Currency_ID, 1) AS PaidAmt,
--invoiceOpen(i.C_Invoice_ID,0) AS OpenAmt, --invoiceOpen(i.C_Invoice_ID,0) AS OpenAmt,

View File

@ -55,8 +55,8 @@ SELECT l.ad_client_id,
(l.qtyordered - l.qtyinvoiced) * l.priceactual AS netamttoinvoice, (l.qtyordered - l.qtyinvoiced) * l.priceactual AS netamttoinvoice,
l.qtylostsales, l.qtylostsales,
l.qtylostsales * l.priceactual AS amtlostsales, l.qtylostsales * l.priceactual AS amtlostsales,
CASE WHEN l.pricelist = 0 THEN 0 ELSE round((l.pricelist - l.priceactual) / l.pricelist * 100, 2) END AS discount, CASE WHEN l.pricelist = 0 THEN 0 ELSE currencyRound((l.pricelist - l.priceactual) / l.pricelist * 100,o.C_Currency_ID,'N') END AS discount,
CASE WHEN l.pricelimit = 0 THEN 0 ELSE round((l.priceactual - l.pricelimit) / l.pricelimit * 100, 2) END AS margin, CASE WHEN l.pricelimit = 0 THEN 0 ELSE currencyRound((l.priceactual - l.pricelimit) / l.pricelimit * 100,o.C_Currency_ID,'N') END AS margin,
CASE WHEN l.pricelimit = 0 THEN 0 ELSE (l.priceactual - l.pricelimit) * l.qtydelivered END AS marginamt, CASE WHEN l.pricelimit = 0 THEN 0 ELSE (l.priceactual - l.pricelimit) * l.qtydelivered END AS marginamt,
o.ad_org_id AS c_order_ad_org_id, o.ad_org_id AS c_order_ad_org_id,
o.ad_orgtrx_id AS c_order_ad_orgtrx_id, o.ad_orgtrx_id AS c_order_ad_orgtrx_id,

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff