IDEMPIERE-1856 Amount in database functions and views are hardcoded to round to 2 decimal points
This commit is contained in:
parent
036f065d70
commit
1abe2ca2ba
|
@ -33,6 +33,8 @@ SELECT C_InvoicePaySchedule_ID, DueAmt FROM C_InvoicePaySchedule WHERE C_Invoice
|
|||
************************************************************************/
|
||||
AS
|
||||
v_Currency_ID NUMBER(10);
|
||||
v_Precision NUMBER := 0;
|
||||
v_Min NUMBER := 0;
|
||||
v_TotalOpenAmt NUMBER := 0;
|
||||
v_PaidAmt NUMBER := 0;
|
||||
v_Remaining NUMBER := 0;
|
||||
|
@ -70,6 +72,13 @@ BEGIN
|
|||
END;
|
||||
-- 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
|
||||
FOR a IN Cur_Alloc LOOP
|
||||
v_Temp := a.Amount + a.DisCountAmt + a.WriteOffAmt;
|
||||
|
@ -104,12 +113,13 @@ BEGIN
|
|||
-- DBMS_OUTPUT.PUT_LINE('== Total=' || v_TotalOpenAmt);
|
||||
|
||||
-- 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;
|
||||
END IF;
|
||||
|
||||
-- Round to penny
|
||||
v_TotalOpenAmt := ROUND(COALESCE(v_TotalOpenAmt,0), 2);
|
||||
-- Round to currency precision
|
||||
v_TotalOpenAmt := ROUND(COALESCE(v_TotalOpenAmt,0), v_Precision);
|
||||
|
||||
RETURN v_TotalOpenAmt;
|
||||
END invoiceOpen;
|
||||
/
|
||||
|
|
|
@ -34,6 +34,8 @@ SELECT C_InvoicePaySchedule_ID, DueAmt FROM C_InvoicePaySchedule WHERE C_Invoice
|
|||
************************************************************************/
|
||||
AS
|
||||
v_Currency_ID NUMBER(10);
|
||||
v_Precision NUMBER := 0;
|
||||
v_Min NUMBER := 0;
|
||||
v_TotalOpenAmt NUMBER := 0;
|
||||
v_PaidAmt NUMBER := 0;
|
||||
v_Remaining NUMBER := 0;
|
||||
|
@ -73,6 +75,13 @@ BEGIN
|
|||
END;
|
||||
-- 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
|
||||
FOR a IN Cur_Alloc LOOP
|
||||
v_Temp := a.Amount + a.DisCountAmt + a.WriteOffAmt;
|
||||
|
@ -107,12 +116,13 @@ BEGIN
|
|||
-- DBMS_OUTPUT.PUT_LINE('== Total=' || v_TotalOpenAmt);
|
||||
|
||||
-- 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;
|
||||
END IF;
|
||||
|
||||
-- Round to penny
|
||||
v_TotalOpenAmt := ROUND(COALESCE(v_TotalOpenAmt,0), 2);
|
||||
-- Round to currency precision
|
||||
v_TotalOpenAmt := ROUND(COALESCE(v_TotalOpenAmt,0), v_Precision);
|
||||
|
||||
RETURN v_TotalOpenAmt;
|
||||
END InvoiceopenToDate;
|
||||
/
|
||||
|
|
|
@ -33,6 +33,8 @@ RETURN NUMBER
|
|||
*
|
||||
************************************************************************/
|
||||
AS
|
||||
v_Precision NUMBER := 0;
|
||||
v_Min NUMBER := 0;
|
||||
v_MultiplierAP NUMBER := 1;
|
||||
v_PaymentAmt NUMBER := 0;
|
||||
CURSOR Cur_Alloc IS
|
||||
|
@ -44,6 +46,13 @@ AS
|
|||
WHERE al.C_Invoice_ID = p_C_Invoice_ID
|
||||
AND a.IsActive='Y';
|
||||
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
|
||||
IF (p_MultiplierAP IS NOT NULL) THEN
|
||||
v_MultiplierAP := p_MultiplierAP;
|
||||
|
@ -54,7 +63,15 @@ BEGIN
|
|||
+ 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);
|
||||
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;
|
||||
/
|
|
@ -34,6 +34,8 @@ RETURN NUMBER
|
|||
*
|
||||
************************************************************************/
|
||||
AS
|
||||
v_Precision NUMBER := 0;
|
||||
v_Min NUMBER := 0;
|
||||
v_MultiplierAP NUMBER := 1;
|
||||
v_PaymentAmt NUMBER := 0;
|
||||
CURSOR Cur_Alloc IS
|
||||
|
@ -46,6 +48,13 @@ AS
|
|||
AND a.IsActive='Y'
|
||||
AND a.DateAcct <= p_DateAcct;
|
||||
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
|
||||
IF (p_MultiplierAP IS NOT NULL) THEN
|
||||
v_MultiplierAP := p_MultiplierAP;
|
||||
|
@ -56,7 +65,15 @@ BEGIN
|
|||
+ 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);
|
||||
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;
|
||||
/
|
||||
|
|
|
@ -24,6 +24,8 @@ RETURN NUMBER
|
|||
************************************************************************/
|
||||
|
||||
AS
|
||||
v_Precision NUMBER := 0;
|
||||
v_Min NUMBER := 0;
|
||||
Discount NUMBER := 0;
|
||||
CURSOR Cur_PT IS
|
||||
SELECT *
|
||||
|
@ -34,6 +36,13 @@ AS
|
|||
Add1Date NUMBER := 0;
|
||||
Add2Date NUMBER := 0;
|
||||
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
|
||||
IF (Amount IS NULL OR PaymentTerm_ID IS NULL OR DocDate IS NULL) THEN
|
||||
RETURN 0;
|
||||
|
@ -60,7 +69,15 @@ BEGIN
|
|||
Discount := Amount * p.Discount2 / 100;
|
||||
END IF;
|
||||
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;
|
||||
/
|
|
@ -26,6 +26,8 @@ RETURN NUMBER
|
|||
|
||||
************************************************************************/
|
||||
AS
|
||||
v_Precision NUMBER := 0;
|
||||
v_Min NUMBER := 0;
|
||||
v_AllocatedAmt NUMBER := 0;
|
||||
v_PayAmt NUMBER;
|
||||
CURSOR Cur_Alloc IS
|
||||
|
@ -36,6 +38,13 @@ AS
|
|||
AND a.IsActive='Y';
|
||||
-- AND al.C_Invoice_ID IS NOT NULL;
|
||||
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
|
||||
SELECT MAX(PayAmt)
|
||||
INTO v_PayAmt
|
||||
|
@ -50,8 +59,15 @@ BEGIN
|
|||
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);
|
||||
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;
|
||||
END paymentAllocated;
|
||||
/
|
|
@ -18,6 +18,8 @@ RETURN NUMBER
|
|||
************************************************************************/
|
||||
AS
|
||||
v_Currency_ID NUMBER(10);
|
||||
v_Precision NUMBER := 0;
|
||||
v_Min NUMBER := 0;
|
||||
v_AvailableAmt NUMBER := 0;
|
||||
v_IsReceipt C_Payment.IsReceipt%TYPE;
|
||||
v_Amt NUMBER := 0;
|
||||
|
@ -45,18 +47,28 @@ BEGIN
|
|||
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);
|
||||
|
||||
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
|
||||
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
|
||||
IF (v_AvailableAmt > -v_Min AND v_AvailableAmt < v_Min) THEN
|
||||
v_AvailableAmt := 0;
|
||||
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;
|
||||
END paymentAvailable;
|
||||
/
|
||||
|
|
|
@ -11,11 +11,11 @@ SELECT il.AD_Client_ID, il.AD_Org_ID,
|
|||
i.C_BPartner_ID, il.M_Product_ID,
|
||||
i.DocumentNo, i.DateInvoiced, i.DateAcct,
|
||||
i.IsSOTrx, i.DocStatus,
|
||||
ROUND(i.Multiplier*LineNetAmt, 2) AS LineNetAmt,
|
||||
ROUND(i.Multiplier*PriceList*QtyInvoiced, 2) 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,
|
||||
ROUND(i.Multiplier*PriceList*QtyInvoiced-LineNetAmt,2) AS LineDiscountAmt,
|
||||
CASE WHEN COALESCE(il.PriceLimit,0)=0 THEN 0 ELSE ROUND(i.Multiplier*LineNetAmt-PriceLimit*QtyInvoiced,2) END AS LineOverLimitAmt,
|
||||
currencyRound(i.Multiplier*LineNetAmt,i.C_Currency_ID,'N') AS LineNetAmt,
|
||||
currencyRound(i.Multiplier*PriceList*QtyInvoiced,i.C_Currency_ID,'N') AS LineListAmt,
|
||||
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,
|
||||
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 currencyRound(i.Multiplier*il.LineNetAmt-il.PriceLimit*il.QtyInvoiced,i.C_Currency_ID,'N') END AS LineOverLimitAmt,
|
||||
il.QtyInvoiced, il.QtyEntered,
|
||||
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
|
||||
|
|
|
@ -13,7 +13,7 @@ SELECT s.ad_client_id,
|
|||
sum(ms.qtyonhand - ms.qtyreserved) AS qtyavailable,
|
||||
sum(ms.qtyonhand) AS qtyonhand,
|
||||
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,
|
||||
mw.m_warehouse_id,
|
||||
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_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_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
|
||||
GROUP BY s.ad_client_id,
|
||||
s.ad_org_id,
|
||||
|
@ -36,7 +38,8 @@ SELECT s.ad_client_id,
|
|||
mw.m_warehouse_id,
|
||||
mpr.m_pricelist_version_id,
|
||||
org.name,
|
||||
mp.name
|
||||
mp.name,
|
||||
mpl.C_Currency_ID
|
||||
UNION
|
||||
SELECT r.ad_client_id,
|
||||
r.ad_org_id,
|
||||
|
@ -52,7 +55,7 @@ SELECT s.ad_client_id,
|
|||
sum(ms.qtyonhand - ms.qtyreserved) AS qtyavailable,
|
||||
sum(ms.qtyonhand) AS qtyonhand,
|
||||
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,
|
||||
mw.m_warehouse_id,
|
||||
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_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_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
|
||||
GROUP BY r.ad_client_id,
|
||||
r.ad_org_id,
|
||||
|
@ -75,4 +80,5 @@ SELECT s.ad_client_id,
|
|||
mw.m_warehouse_id,
|
||||
mpr.m_pricelist_version_id,
|
||||
org.name,
|
||||
mp.name;
|
||||
mp.name,
|
||||
mpl.C_Currency_ID;
|
|
@ -1,6 +1,5 @@
|
|||
CREATE OR REPLACE VIEW rv_c_invoiceline
|
||||
AS
|
||||
SELECT il.ad_client_id,
|
||||
CREATE OR REPLACE VIEW rv_c_invoiceline AS
|
||||
SELECT il.ad_client_id,
|
||||
il.ad_org_id,
|
||||
il.isactive,
|
||||
il.created,
|
||||
|
@ -38,29 +37,16 @@ AS
|
|||
il.priceactual,
|
||||
il.pricelimit,
|
||||
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.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 ( 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,
|
||||
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 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,
|
||||
currencyRound(i.multiplier * il.linenetamt,i.C_Currency_ID,'N') AS linenetamt,
|
||||
currencyRound(i.multiplier * il.pricelist * il.qtyinvoiced,i.C_Currency_ID,'N') AS linelistamt,
|
||||
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,
|
||||
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 currencyRound(i.multiplier * il.linenetamt - il.pricelimit * il.qtyinvoiced,i.C_Currency_ID,'N') END AS
|
||||
lineoverlimitamt,
|
||||
il.ad_orgtrx_id,
|
||||
il.a_processed,
|
||||
il.c_charge_id,
|
||||
|
@ -145,7 +131,7 @@ AS
|
|||
pasi.serno AS m_attributesetinstance_serno,
|
||||
pasi.updated AS m_attributesetinstance_updated,
|
||||
pasi.updatedby AS m_asi_updatedby
|
||||
FROM rv_c_invoice i
|
||||
FROM rv_c_invoice i
|
||||
JOIN c_invoiceline il
|
||||
ON i.c_invoice_id = il.c_invoice_id
|
||||
LEFT JOIN m_product p
|
||||
|
@ -153,4 +139,3 @@ AS
|
|||
LEFT JOIN m_attributesetinstance pasi
|
||||
ON il.m_attributesetinstance_id = pasi.m_attributesetinstance_id
|
||||
;
|
||||
|
||||
|
|
|
@ -11,14 +11,15 @@ SELECT il.AD_Client_ID, il.AD_Org_ID,
|
|||
SUM(LineLimitAmt) AS LineLimitAmt,
|
||||
SUM(LineDiscountAmt) AS LineDiscountAmt,
|
||||
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,
|
||||
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
|
||||
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit,
|
||||
SUM(QtyInvoiced) AS QtyInvoiced, IsSOTrx
|
||||
100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
|
||||
SUM(QtyInvoiced) AS QtyInvoiced, il.IsSOTrx
|
||||
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,
|
||||
firstOf(il.DateInvoiced, 'Q'), IsSOTrx;
|
||||
firstOf(il.DateInvoiced, 'Q'), il.IsSOTrx, i.C_Currency_ID;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -11,16 +11,17 @@ SELECT il.AD_Client_ID, il.AD_Org_ID,
|
|||
SUM(LineLimitAmt) AS LineLimitAmt,
|
||||
SUM(LineDiscountAmt) AS LineDiscountAmt,
|
||||
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,
|
||||
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
|
||||
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)
|
||||
WHERE il.IsSOTrx='Y'
|
||||
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;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -3,21 +3,22 @@ CREATE OR REPLACE VIEW RV_C_INVOICE_DAY
|
|||
LINELISTAMT, LINELIMITAMT, LINEDISCOUNTAMT, LINEDISCOUNT, LINEOVERLIMITAMT,
|
||||
LINEOVERLIMIT, ISSOTRX)
|
||||
AS
|
||||
SELECT AD_Client_ID, AD_Org_ID, SalesRep_ID,
|
||||
firstOf(DateInvoiced, 'DD') AS DateInvoiced, -- DD Day, DY Week, MM Month
|
||||
SELECT il.AD_Client_ID, il.AD_Org_ID, il.SalesRep_ID,
|
||||
firstOf(il.DateInvoiced, 'DD') AS DateInvoiced, -- DD Day, DY Week, MM Month
|
||||
SUM(LineNetAmt) AS LineNetAmt,
|
||||
SUM(LineListAmt) AS LineListAmt,
|
||||
SUM(LineLimitAmt) AS LineLimitAmt,
|
||||
SUM(LineDiscountAmt) AS LineDiscountAmt,
|
||||
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,
|
||||
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
|
||||
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit,
|
||||
IsSOTrx
|
||||
FROM RV_C_InvoiceLine
|
||||
GROUP BY AD_Client_ID, AD_Org_ID, SalesRep_ID,
|
||||
firstOf(DateInvoiced, 'DD'), IsSOTrx;
|
||||
100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
|
||||
il.IsSOTrx
|
||||
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.SalesRep_ID,
|
||||
firstOf(il.DateInvoiced, 'DD'), il.IsSOTrx, i.C_Currency_ID;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -3,21 +3,22 @@ CREATE OR REPLACE VIEW RV_C_INVOICE_MONTH
|
|||
LINELISTAMT, LINELIMITAMT, LINEDISCOUNTAMT, LINEDISCOUNT, LINEOVERLIMITAMT,
|
||||
LINEOVERLIMIT, ISSOTRX)
|
||||
AS
|
||||
SELECT AD_Client_ID, AD_Org_ID, SalesRep_ID,
|
||||
firstOf(DateInvoiced, 'MM') AS DateInvoiced, -- DD Day, DY Week, MM Month
|
||||
SELECT il.AD_Client_ID, il.AD_Org_ID, il.SalesRep_ID,
|
||||
firstOf(il.DateInvoiced, 'MM') AS DateInvoiced, -- DD Day, DY Week, MM Month
|
||||
SUM(LineNetAmt) AS LineNetAmt,
|
||||
SUM(LineListAmt) AS LineListAmt,
|
||||
SUM(LineLimitAmt) AS LineLimitAmt,
|
||||
SUM(LineDiscountAmt) AS LineDiscountAmt,
|
||||
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,
|
||||
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
|
||||
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit,
|
||||
IsSOTrx
|
||||
FROM RV_C_InvoiceLine
|
||||
GROUP BY AD_Client_ID, AD_Org_ID, SalesRep_ID,
|
||||
firstOf(DateInvoiced, 'MM'), IsSOTrx;
|
||||
100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
|
||||
il.IsSOTrx
|
||||
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.SalesRep_ID,
|
||||
firstOf(il.DateInvoiced, 'MM'), il.IsSOTrx, i.C_Currency_ID;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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.LineDiscountAmt) AS LineDiscountAmt,
|
||||
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,
|
||||
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
|
||||
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit,
|
||||
SUM(QtyInvoiced) AS QtyInvoiced, IsSOTrx
|
||||
100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
|
||||
SUM(QtyInvoiced) AS QtyInvoiced, il.IsSOTrx
|
||||
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,
|
||||
firstOf(il.DateInvoiced, 'MM'), IsSOTrx;
|
||||
firstOf(il.DateInvoiced, 'MM'), il.IsSOTrx, i.C_Currency_ID;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -10,14 +10,15 @@ SELECT il.AD_Client_ID, il.AD_Org_ID, il.M_Product_ID,
|
|||
SUM(il.LineLimitAmt) AS LineLimitAmt,
|
||||
SUM(il.LineDiscountAmt) AS LineDiscountAmt,
|
||||
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,
|
||||
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
|
||||
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit,
|
||||
SUM(QtyInvoiced) AS QtyInvoiced, IsSOTrx
|
||||
100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
|
||||
SUM(QtyInvoiced) AS QtyInvoiced, il.IsSOTrx
|
||||
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,
|
||||
firstOf(il.DateInvoiced, 'MM'), IsSOTrx;
|
||||
firstOf(il.DateInvoiced, 'MM'), il.IsSOTrx, i.C_Currency_ID;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -10,14 +10,15 @@ SELECT il.AD_Client_ID, il.AD_Org_ID, il.M_Product_ID,
|
|||
SUM(il.LineLimitAmt) AS LineLimitAmt,
|
||||
SUM(il.LineDiscountAmt) AS LineDiscountAmt,
|
||||
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,
|
||||
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
|
||||
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit,
|
||||
SUM(QtyInvoiced) AS QtyInvoiced, IsSOTrx
|
||||
100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
|
||||
SUM(QtyInvoiced) AS QtyInvoiced, il.IsSOTrx
|
||||
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,
|
||||
firstOf(il.DateInvoiced, 'Q'), IsSOTrx;
|
||||
firstOf(il.DateInvoiced, 'Q'), il.IsSOTrx, i.C_Currency_ID;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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.LineDiscountAmt) AS LineDiscountAmt,
|
||||
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,
|
||||
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
|
||||
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit,
|
||||
SUM(QtyInvoiced) AS QtyInvoiced, IsSOTrx
|
||||
100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
|
||||
SUM(QtyInvoiced) AS QtyInvoiced, il.IsSOTrx
|
||||
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,
|
||||
firstOf(il.DateInvoiced, 'DY'), IsSOTrx;
|
||||
firstOf(il.DateInvoiced, 'DY'), il.IsSOTrx, i.C_Currency_ID;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -6,21 +6,22 @@ AS
|
|||
SELECT il.AD_Client_ID, il.AD_Org_ID,
|
||||
po.C_BPartner_ID, il.M_Product_Category_ID,
|
||||
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(LineLimitAmt) AS LineLimitAmt,
|
||||
SUM(LineDiscountAmt) AS LineDiscountAmt,
|
||||
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,
|
||||
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
|
||||
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)
|
||||
WHERE il.IsSOTrx='Y'
|
||||
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;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -3,21 +3,22 @@ CREATE OR REPLACE VIEW RV_C_INVOICE_WEEK
|
|||
LINELISTAMT, LINELIMITAMT, LINEDISCOUNTAMT, LINEDISCOUNT, LINEOVERLIMITAMT,
|
||||
LINEOVERLIMIT, ISSOTRX)
|
||||
AS
|
||||
SELECT AD_Client_ID, AD_Org_ID, SalesRep_ID,
|
||||
firstOf(DateInvoiced, 'DY') AS DateInvoiced, -- DD Day, DY Week, MM Month
|
||||
SELECT il.AD_Client_ID, il.AD_Org_ID, il.SalesRep_ID,
|
||||
firstOf(il.DateInvoiced, 'DY') AS DateInvoiced, -- DD Day, DY Week, MM Month
|
||||
SUM(LineNetAmt) AS LineNetAmt,
|
||||
SUM(LineListAmt) AS LineListAmt,
|
||||
SUM(LineLimitAmt) AS LineLimitAmt,
|
||||
SUM(LineDiscountAmt) AS LineDiscountAmt,
|
||||
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,
|
||||
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
|
||||
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit,
|
||||
IsSOTrx
|
||||
FROM RV_C_InvoiceLine
|
||||
GROUP BY AD_Client_ID, AD_Org_ID, SalesRep_ID,
|
||||
firstOf(DateInvoiced, 'DY'), IsSOTrx;
|
||||
100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
|
||||
il.IsSOTrx
|
||||
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.SalesRep_ID,
|
||||
firstOf(il.DateInvoiced, 'DY'), il.IsSOTrx, i.C_Currency_ID;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
DROP VIEW rv_openitem;
|
||||
|
||||
CREATE OR REPLACE VIEW rv_openitem
|
||||
AS
|
||||
SELECT i.ad_org_id,
|
||||
CREATE OR REPLACE VIEW rv_openitem AS
|
||||
SELECT i.ad_org_id,
|
||||
i.ad_client_id,
|
||||
i.documentno,
|
||||
i.c_invoice_id,
|
||||
|
@ -15,7 +14,7 @@ AS
|
|||
paymenttermduedate(i.c_paymentterm_id, i.dateinvoiced) AS duedate,
|
||||
paymenttermduedays(i.c_paymentterm_id, i.dateinvoiced, getdate()) AS daysdue,
|
||||
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,
|
||||
invoicepaid(i.c_invoice_id, i.c_currency_id, 1) AS paidamt,
|
||||
invoiceopen(i.c_invoice_id, 0) AS openamt,
|
||||
|
@ -71,14 +70,13 @@ AS
|
|||
i.updatedby,
|
||||
i.user1_id,
|
||||
i.user2_id
|
||||
FROM rv_c_invoice i
|
||||
FROM rv_c_invoice i
|
||||
JOIN c_paymentterm p
|
||||
ON i.c_paymentterm_id = p.c_paymentterm_id
|
||||
WHERE invoiceopen(i.c_invoice_id, 0) <> 0
|
||||
AND i.ispayschedulevalid <> 'Y'
|
||||
AND i.docstatus IN ( 'CO', 'CL' )
|
||||
UNION
|
||||
SELECT i.ad_org_id,
|
||||
WHERE invoiceopen(i.c_invoice_id, 0) <> 0 AND i.ispayschedulevalid <> 'Y' AND i.docstatus IN ('CO',
|
||||
'CL')
|
||||
UNION
|
||||
SELECT i.ad_org_id,
|
||||
i.ad_client_id,
|
||||
i.documentno,
|
||||
i.c_invoice_id,
|
||||
|
@ -147,12 +145,9 @@ AS
|
|||
i.updatedby,
|
||||
i.user1_id,
|
||||
i.user2_id
|
||||
FROM rv_c_invoice i
|
||||
FROM rv_c_invoice i
|
||||
JOIN c_invoicepayschedule ips
|
||||
ON i.c_invoice_id = ips.c_invoice_id
|
||||
WHERE invoiceopen(i.c_invoice_id, ips.c_invoicepayschedule_id) <> 0
|
||||
AND i.ispayschedulevalid = 'Y'
|
||||
AND i.docstatus IN ( 'CO', 'CL' )
|
||||
AND ips.isvalid = 'Y'
|
||||
WHERE invoiceopen(i.c_invoice_id, ips.c_invoicepayschedule_id) <> 0 AND i.ispayschedulevalid = 'Y' AND i.docstatus IN ('CO',
|
||||
'CL') AND ips.isvalid = 'Y'
|
||||
;
|
||||
|
||||
|
|
|
@ -14,20 +14,19 @@ SELECT i.AD_Org_ID, i.AD_Client_ID,
|
|||
paymentTermDueDate(i.C_PaymentTerm_ID, i.DateInvoiced) AS DueDate,
|
||||
paymentTermDueDays(i.C_PaymentTerm_ID, i.DateInvoiced, getdate()) AS DaysDue,
|
||||
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,
|
||||
--invoicePaid(i.C_Invoice_ID, i.C_Currency_ID, 1) AS PaidAmt,
|
||||
--invoiceOpen(i.C_Invoice_ID,0) AS OpenAmt,
|
||||
i.C_Currency_ID, i.C_ConversionType_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
|
||||
FROM RV_C_Invoice i
|
||||
INNER JOIN C_PaymentTerm p ON (i.C_PaymentTerm_ID=p.C_PaymentTerm_ID)
|
||||
WHERE -- i.IsPaid='N'
|
||||
--invoiceOpen(i.C_Invoice_ID,0) <> 0 AND
|
||||
i.IsPayScheduleValid<>'Y'
|
||||
AND i.DocStatus<>'DR'
|
||||
AND i.DocStatus IN ('CO','CL')
|
||||
UNION
|
||||
SELECT i.AD_Org_ID, i.AD_Client_ID,
|
||||
|
@ -39,8 +38,8 @@ SELECT i.AD_Org_ID, i.AD_Client_ID,
|
|||
ips.DiscountDate,
|
||||
ips.DiscountAmt,
|
||||
ips.DueAmt AS GrandTotal,
|
||||
-- invoicePaid(i.C_Invoice_ID, i.C_Currency_ID, 1) AS PaidAmt,
|
||||
-- invoiceOpen(i.C_Invoice_ID, ips.C_InvoicePaySchedule_ID) AS OpenAmt,
|
||||
--invoicePaid(i.C_Invoice_ID, i.C_Currency_ID, 1) AS PaidAmt,
|
||||
--invoiceOpen(i.C_Invoice_ID, ips.C_InvoicePaySchedule_ID) AS OpenAmt,
|
||||
i.C_Currency_ID, i.C_ConversionType_ID,
|
||||
i.C_PaymentTerm_ID,
|
||||
i.IsPayScheduleValid, ips.C_InvoicePaySchedule_ID, i.InvoiceCollectionType,
|
||||
|
@ -50,7 +49,6 @@ FROM RV_C_Invoice i
|
|||
WHERE -- i.IsPaid='N'
|
||||
--invoiceOpen(i.C_Invoice_ID,ips.C_InvoicePaySchedule_ID) <> 0 AND
|
||||
i.IsPayScheduleValid='Y'
|
||||
AND i.DocStatus<>'DR'
|
||||
AND i.DocStatus IN ('CO','CL')
|
||||
AND ips.IsValid='Y';
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
DROP VIEW rv_orderdetail;
|
||||
|
||||
CREATE OR REPLACE VIEW rv_orderdetail
|
||||
AS
|
||||
SELECT l.ad_client_id,
|
||||
CREATE OR REPLACE VIEW rv_orderdetail AS
|
||||
SELECT l.ad_client_id,
|
||||
l.ad_org_id,
|
||||
l.isactive,
|
||||
l.created,
|
||||
|
@ -53,21 +52,12 @@ AS
|
|||
l.priceentered,
|
||||
l.qtyordered - l.qtydelivered AS qtytodeliver,
|
||||
l.qtyordered - l.qtyinvoiced AS qtytoinvoice,
|
||||
( l.qtyordered - l.qtyinvoiced ) * l.priceactual AS netamttoinvoice,
|
||||
(l.qtyordered - l.qtyinvoiced) * l.priceactual AS netamttoinvoice,
|
||||
l.qtylostsales,
|
||||
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.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,
|
||||
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 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,
|
||||
o.ad_org_id AS c_order_ad_org_id,
|
||||
o.ad_orgtrx_id AS c_order_ad_orgtrx_id,
|
||||
o.amountrefunded,
|
||||
|
@ -169,10 +159,9 @@ AS
|
|||
pasi.isactive AS m_asi_isactive,
|
||||
pasi.updated AS m_asi_updated,
|
||||
pasi.updatedby AS m_asi_updatedby
|
||||
FROM c_order o
|
||||
FROM c_order o
|
||||
JOIN c_orderline l
|
||||
ON o.c_order_id = l.c_order_id
|
||||
LEFT JOIN m_attributesetinstance pasi
|
||||
ON l.m_attributesetinstance_id = pasi.m_attributesetinstance_id
|
||||
;
|
||||
|
||||
|
|
|
@ -44,6 +44,8 @@ AS
|
|||
$BODY$
|
||||
DECLARE
|
||||
v_Currency_ID numeric(10);
|
||||
v_Precision NUMERIC := 0;
|
||||
v_Min NUMERIC := 0;
|
||||
v_TotalOpenAmt numeric := 0;
|
||||
v_PaidAmt numeric := 0;
|
||||
v_Remaining numeric := 0;
|
||||
|
@ -67,6 +69,13 @@ BEGIN
|
|||
END;
|
||||
-- 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
|
||||
FOR allocationline IN
|
||||
SELECT a.AD_Client_ID, a.AD_Org_ID,
|
||||
|
@ -113,12 +122,13 @@ BEGIN
|
|||
-- DBMS_OUTPUT.PUT_LINE('== Total=' || v_TotalOpenAmt);
|
||||
|
||||
-- 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;
|
||||
END IF;
|
||||
|
||||
-- Round to penny
|
||||
v_TotalOpenAmt := ROUND(COALESCE(v_TotalOpenAmt,0), 2);
|
||||
-- Round to currency precision
|
||||
v_TotalOpenAmt := ROUND(COALESCE(v_TotalOpenAmt,0), v_Precision);
|
||||
|
||||
RETURN v_TotalOpenAmt;
|
||||
END;
|
||||
$BODY$
|
||||
|
|
|
@ -33,11 +33,20 @@ RETURNS numeric AS $body$
|
|||
*
|
||||
************************************************************************/
|
||||
DECLARE
|
||||
v_Precision NUMERIC := 0;
|
||||
v_Min NUMERIC := 0;
|
||||
v_MultiplierAP NUMERIC := 1;
|
||||
v_PaymentAmt NUMERIC := 0;
|
||||
ar RECORD;
|
||||
|
||||
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
|
||||
IF (p_MultiplierAP IS NOT NULL) THEN
|
||||
v_MultiplierAP := p_MultiplierAP;
|
||||
|
@ -56,8 +65,16 @@ BEGIN
|
|||
+ 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);
|
||||
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;
|
||||
|
||||
$body$ LANGUAGE plpgsql;
|
||||
|
|
|
@ -45,10 +45,19 @@ RETURNS numeric
|
|||
AS
|
||||
$BODY$
|
||||
DECLARE
|
||||
v_Precision NUMERIC := 0;
|
||||
v_Min NUMERIC := 0;
|
||||
v_MultiplierAP numeric := 1;
|
||||
v_PaymentAmt numeric := 0;
|
||||
allocation record;
|
||||
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
|
||||
IF (p_MultiplierAP IS NOT NULL) THEN
|
||||
v_MultiplierAP := p_MultiplierAP;
|
||||
|
@ -64,8 +73,16 @@ BEGIN
|
|||
+ 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);
|
||||
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;
|
||||
$BODY$
|
||||
LANGUAGE 'plpgsql' ;
|
||||
|
|
|
@ -25,6 +25,8 @@ RETURNS NUMERIC AS $body$
|
|||
************************************************************************/
|
||||
|
||||
DECLARE
|
||||
v_Precision NUMERIC := 0;
|
||||
v_Min NUMERIC := 0;
|
||||
Discount NUMERIC := 0;
|
||||
Discount1Date timestamp with time zone;
|
||||
Discount2Date timestamp with time zone;
|
||||
|
@ -32,6 +34,13 @@ DECLARE
|
|||
Add2Date NUMERIC := 0;
|
||||
p RECORD;
|
||||
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
|
||||
IF (Amount IS NULL OR PaymentTerm_ID IS NULL OR DocDate IS NULL) THEN
|
||||
RETURN 0;
|
||||
|
@ -59,8 +68,16 @@ BEGIN
|
|||
Discount := Amount * p.Discount2 / 100;
|
||||
END IF;
|
||||
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;
|
||||
|
||||
$body$ LANGUAGE plpgsql;
|
||||
|
|
|
@ -28,10 +28,19 @@ RETURNS NUMERIC AS $body$
|
|||
|
||||
************************************************************************/
|
||||
DECLARE
|
||||
v_Precision NUMERIC := 0;
|
||||
v_Min NUMERIC := 0;
|
||||
v_AllocatedAmt NUMERIC := 0;
|
||||
v_PayAmt NUMERIC;
|
||||
r RECORD;
|
||||
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
|
||||
SELECT
|
||||
INTO v_PayAmt MAX(PayAmt)
|
||||
|
@ -53,8 +62,15 @@ BEGIN
|
|||
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);
|
||||
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;
|
||||
END;
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@ RETURNS NUMERIC AS $body$
|
|||
************************************************************************/
|
||||
DECLARE
|
||||
v_Currency_ID NUMERIC(10);
|
||||
v_Precision NUMERIC := 0;
|
||||
v_Min NUMERIC := 0;
|
||||
v_AvailableAmt NUMERIC := 0;
|
||||
v_IsReceipt C_Payment.IsReceipt%TYPE;
|
||||
v_Amt NUMERIC := 0;
|
||||
|
@ -41,6 +43,13 @@ BEGIN
|
|||
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);
|
||||
|
||||
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
|
||||
FOR r IN
|
||||
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;
|
||||
-- DBMS_OUTPUT.PUT_LINE(' Allocation=' || a.Amount || ' - Available=' || v_AvailableAmt);
|
||||
END LOOP;
|
||||
|
||||
-- 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;
|
||||
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;
|
||||
END;
|
||||
|
||||
|
|
|
@ -11,11 +11,11 @@ SELECT il.AD_Client_ID, il.AD_Org_ID,
|
|||
i.C_BPartner_ID, il.M_Product_ID,
|
||||
i.DocumentNo, i.DateInvoiced, i.DateAcct,
|
||||
i.IsSOTrx, i.DocStatus,
|
||||
ROUND(i.Multiplier*LineNetAmt, 2) AS LineNetAmt,
|
||||
ROUND(i.Multiplier*PriceList*QtyInvoiced, 2) 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,
|
||||
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,
|
||||
currencyRound(i.Multiplier*LineNetAmt,i.C_Currency_ID,'N') AS LineNetAmt,
|
||||
currencyRound(i.Multiplier*PriceList*QtyInvoiced,i.C_Currency_ID,'N') AS LineListAmt,
|
||||
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,
|
||||
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 currencyRound(i.Multiplier*il.LineNetAmt-il.PriceLimit*il.QtyInvoiced,i.C_Currency_ID,'N') END AS LineOverLimitAmt,
|
||||
il.QtyInvoiced, il.QtyEntered,
|
||||
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
|
||||
|
|
|
@ -13,7 +13,7 @@ SELECT s.ad_client_id,
|
|||
sum(ms.qtyonhand - ms.qtyreserved) AS qtyavailable,
|
||||
sum(ms.qtyonhand) AS qtyonhand,
|
||||
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,
|
||||
mw.m_warehouse_id,
|
||||
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_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_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
|
||||
GROUP BY s.ad_client_id,
|
||||
s.ad_org_id,
|
||||
|
@ -36,7 +38,8 @@ SELECT s.ad_client_id,
|
|||
mw.m_warehouse_id,
|
||||
mpr.m_pricelist_version_id,
|
||||
org.name,
|
||||
mp.name
|
||||
mp.name,
|
||||
mpl.C_Currency_ID
|
||||
UNION
|
||||
SELECT r.ad_client_id,
|
||||
r.ad_org_id,
|
||||
|
@ -52,7 +55,7 @@ SELECT s.ad_client_id,
|
|||
sum(ms.qtyonhand - ms.qtyreserved) AS qtyavailable,
|
||||
sum(ms.qtyonhand) AS qtyonhand,
|
||||
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,
|
||||
mw.m_warehouse_id,
|
||||
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_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_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
|
||||
GROUP BY r.ad_client_id,
|
||||
r.ad_org_id,
|
||||
|
@ -75,4 +80,5 @@ SELECT s.ad_client_id,
|
|||
mw.m_warehouse_id,
|
||||
mpr.m_pricelist_version_id,
|
||||
org.name,
|
||||
mp.name;
|
||||
mp.name,
|
||||
mpl.C_Currency_ID;
|
|
@ -37,15 +37,15 @@ SELECT il.ad_client_id,
|
|||
il.priceactual,
|
||||
il.pricelimit,
|
||||
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.pricelimit = 0 THEN 0 ELSE round((il.priceactual - il.pricelimit) / il.pricelimit * 100, 2) END AS margin,
|
||||
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 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,
|
||||
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
|
||||
currencyRound(i.multiplier * il.linenetamt,i.C_Currency_ID,'N') AS linenetamt,
|
||||
currencyRound(i.multiplier * il.pricelist * il.qtyinvoiced,i.C_Currency_ID,'N') AS linelistamt,
|
||||
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,
|
||||
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
|
||||
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 currencyRound(i.multiplier * il.linenetamt - il.pricelimit * il.qtyinvoiced,i.C_Currency_ID,'N') END AS
|
||||
lineoverlimitamt,
|
||||
il.ad_orgtrx_id,
|
||||
il.a_processed,
|
||||
|
|
|
@ -11,14 +11,15 @@ SELECT il.AD_Client_ID, il.AD_Org_ID,
|
|||
SUM(LineLimitAmt) AS LineLimitAmt,
|
||||
SUM(LineDiscountAmt) AS LineDiscountAmt,
|
||||
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,
|
||||
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
|
||||
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit,
|
||||
SUM(QtyInvoiced) AS QtyInvoiced, IsSOTrx
|
||||
100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
|
||||
SUM(QtyInvoiced) AS QtyInvoiced, il.IsSOTrx
|
||||
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,
|
||||
firstOf(il.DateInvoiced, 'Q'), IsSOTrx;
|
||||
firstOf(il.DateInvoiced, 'Q'), il.IsSOTrx, i.C_Currency_ID;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -11,16 +11,17 @@ SELECT il.AD_Client_ID, il.AD_Org_ID,
|
|||
SUM(LineLimitAmt) AS LineLimitAmt,
|
||||
SUM(LineDiscountAmt) AS LineDiscountAmt,
|
||||
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,
|
||||
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
|
||||
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)
|
||||
WHERE il.IsSOTrx='Y'
|
||||
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;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -3,21 +3,22 @@ CREATE OR REPLACE VIEW RV_C_INVOICE_DAY
|
|||
LINELISTAMT, LINELIMITAMT, LINEDISCOUNTAMT, LINEDISCOUNT, LINEOVERLIMITAMT,
|
||||
LINEOVERLIMIT, ISSOTRX)
|
||||
AS
|
||||
SELECT AD_Client_ID, AD_Org_ID, SalesRep_ID,
|
||||
firstOf(DateInvoiced, 'DD') AS DateInvoiced, -- DD Day, DY Week, MM Month
|
||||
SELECT il.AD_Client_ID, il.AD_Org_ID, il.SalesRep_ID,
|
||||
firstOf(il.DateInvoiced, 'DD') AS DateInvoiced, -- DD Day, DY Week, MM Month
|
||||
SUM(LineNetAmt) AS LineNetAmt,
|
||||
SUM(LineListAmt) AS LineListAmt,
|
||||
SUM(LineLimitAmt) AS LineLimitAmt,
|
||||
SUM(LineDiscountAmt) AS LineDiscountAmt,
|
||||
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,
|
||||
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
|
||||
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit,
|
||||
IsSOTrx
|
||||
FROM RV_C_InvoiceLine
|
||||
GROUP BY AD_Client_ID, AD_Org_ID, SalesRep_ID,
|
||||
firstOf(DateInvoiced, 'DD'), IsSOTrx;
|
||||
100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
|
||||
il.IsSOTrx
|
||||
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.SalesRep_ID,
|
||||
firstOf(il.DateInvoiced, 'DD'), il.IsSOTrx, i.C_Currency_ID;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -3,21 +3,22 @@ CREATE OR REPLACE VIEW RV_C_INVOICE_MONTH
|
|||
LINELISTAMT, LINELIMITAMT, LINEDISCOUNTAMT, LINEDISCOUNT, LINEOVERLIMITAMT,
|
||||
LINEOVERLIMIT, ISSOTRX)
|
||||
AS
|
||||
SELECT AD_Client_ID, AD_Org_ID, SalesRep_ID,
|
||||
firstOf(DateInvoiced, 'MM') AS DateInvoiced, -- DD Day, DY Week, MM Month
|
||||
SELECT il.AD_Client_ID, il.AD_Org_ID, il.SalesRep_ID,
|
||||
firstOf(il.DateInvoiced, 'MM') AS DateInvoiced, -- DD Day, DY Week, MM Month
|
||||
SUM(LineNetAmt) AS LineNetAmt,
|
||||
SUM(LineListAmt) AS LineListAmt,
|
||||
SUM(LineLimitAmt) AS LineLimitAmt,
|
||||
SUM(LineDiscountAmt) AS LineDiscountAmt,
|
||||
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,
|
||||
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
|
||||
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit,
|
||||
IsSOTrx
|
||||
FROM RV_C_InvoiceLine
|
||||
GROUP BY AD_Client_ID, AD_Org_ID, SalesRep_ID,
|
||||
firstOf(DateInvoiced, 'MM'), IsSOTrx;
|
||||
100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
|
||||
il.IsSOTrx
|
||||
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.SalesRep_ID,
|
||||
firstOf(il.DateInvoiced, 'MM'), il.IsSOTrx, i.C_Currency_ID;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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.LineDiscountAmt) AS LineDiscountAmt,
|
||||
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,
|
||||
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
|
||||
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit,
|
||||
SUM(QtyInvoiced) AS QtyInvoiced, IsSOTrx
|
||||
100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
|
||||
SUM(QtyInvoiced) AS QtyInvoiced, il.IsSOTrx
|
||||
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,
|
||||
firstOf(il.DateInvoiced, 'MM'), IsSOTrx;
|
||||
firstOf(il.DateInvoiced, 'MM'), il.IsSOTrx, i.C_Currency_ID;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -10,14 +10,15 @@ SELECT il.AD_Client_ID, il.AD_Org_ID, il.M_Product_ID,
|
|||
SUM(il.LineLimitAmt) AS LineLimitAmt,
|
||||
SUM(il.LineDiscountAmt) AS LineDiscountAmt,
|
||||
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,
|
||||
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
|
||||
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit,
|
||||
SUM(QtyInvoiced) AS QtyInvoiced, IsSOTrx
|
||||
100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
|
||||
SUM(QtyInvoiced) AS QtyInvoiced, il.IsSOTrx
|
||||
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,
|
||||
firstOf(il.DateInvoiced, 'MM'), IsSOTrx;
|
||||
firstOf(il.DateInvoiced, 'MM'), il.IsSOTrx, i.C_Currency_ID;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -10,14 +10,15 @@ SELECT il.AD_Client_ID, il.AD_Org_ID, il.M_Product_ID,
|
|||
SUM(il.LineLimitAmt) AS LineLimitAmt,
|
||||
SUM(il.LineDiscountAmt) AS LineDiscountAmt,
|
||||
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,
|
||||
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
|
||||
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit,
|
||||
SUM(QtyInvoiced) AS QtyInvoiced, IsSOTrx
|
||||
100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
|
||||
SUM(QtyInvoiced) AS QtyInvoiced, il.IsSOTrx
|
||||
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,
|
||||
firstOf(il.DateInvoiced, 'Q'), IsSOTrx;
|
||||
firstOf(il.DateInvoiced, 'Q'), il.IsSOTrx, i.C_Currency_ID;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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.LineDiscountAmt) AS LineDiscountAmt,
|
||||
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,
|
||||
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
|
||||
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit,
|
||||
SUM(QtyInvoiced) AS QtyInvoiced, IsSOTrx
|
||||
100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
|
||||
SUM(QtyInvoiced) AS QtyInvoiced, il.IsSOTrx
|
||||
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,
|
||||
firstOf(il.DateInvoiced, 'DY'), IsSOTrx;
|
||||
firstOf(il.DateInvoiced, 'DY'), il.IsSOTrx, i.C_Currency_ID;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -6,21 +6,22 @@ AS
|
|||
SELECT il.AD_Client_ID, il.AD_Org_ID,
|
||||
po.C_BPartner_ID, il.M_Product_Category_ID,
|
||||
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(LineLimitAmt) AS LineLimitAmt,
|
||||
SUM(LineDiscountAmt) AS LineDiscountAmt,
|
||||
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,
|
||||
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
|
||||
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)
|
||||
WHERE il.IsSOTrx='Y'
|
||||
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;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -3,21 +3,22 @@ CREATE OR REPLACE VIEW RV_C_INVOICE_WEEK
|
|||
LINELISTAMT, LINELIMITAMT, LINEDISCOUNTAMT, LINEDISCOUNT, LINEOVERLIMITAMT,
|
||||
LINEOVERLIMIT, ISSOTRX)
|
||||
AS
|
||||
SELECT AD_Client_ID, AD_Org_ID, SalesRep_ID,
|
||||
firstOf(DateInvoiced, 'DY') AS DateInvoiced, -- DD Day, DY Week, MM Month
|
||||
SELECT il.AD_Client_ID, il.AD_Org_ID, il.SalesRep_ID,
|
||||
firstOf(il.DateInvoiced, 'DY') AS DateInvoiced, -- DD Day, DY Week, MM Month
|
||||
SUM(LineNetAmt) AS LineNetAmt,
|
||||
SUM(LineListAmt) AS LineListAmt,
|
||||
SUM(LineLimitAmt) AS LineLimitAmt,
|
||||
SUM(LineDiscountAmt) AS LineDiscountAmt,
|
||||
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,
|
||||
CASE WHEN SUM(LineNetAmt)=0 THEN 0 ELSE
|
||||
100-ROUND((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,2) END AS LineOverLimit,
|
||||
IsSOTrx
|
||||
FROM RV_C_InvoiceLine
|
||||
GROUP BY AD_Client_ID, AD_Org_ID, SalesRep_ID,
|
||||
firstOf(DateInvoiced, 'DY'), IsSOTrx;
|
||||
100-currencyRound((SUM(LineNetAmt)-SUM(LineOverLimitAmt))/SUM(LineNetAmt)*100,i.C_Currency_ID,'N') END AS LineOverLimit,
|
||||
il.IsSOTrx
|
||||
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.SalesRep_ID,
|
||||
firstOf(il.DateInvoiced, 'DY'), il.IsSOTrx, i.C_Currency_ID;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ SELECT i.ad_org_id,
|
|||
paymenttermduedate(i.c_paymentterm_id, i.dateinvoiced) AS duedate,
|
||||
paymenttermduedays(i.c_paymentterm_id, i.dateinvoiced, getdate()) AS daysdue,
|
||||
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,
|
||||
invoicepaid(i.c_invoice_id, i.c_currency_id, 1) AS paidamt,
|
||||
invoiceopen(i.c_invoice_id, 0) AS openamt,
|
||||
|
|
|
@ -14,7 +14,7 @@ SELECT i.AD_Org_ID, i.AD_Client_ID,
|
|||
paymentTermDueDate(i.C_PaymentTerm_ID, i.DateInvoiced) AS DueDate,
|
||||
paymentTermDueDays(i.C_PaymentTerm_ID, i.DateInvoiced, getdate()) AS DaysDue,
|
||||
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,
|
||||
--invoicePaid(i.C_Invoice_ID, i.C_Currency_ID, 1) AS PaidAmt,
|
||||
--invoiceOpen(i.C_Invoice_ID,0) AS OpenAmt,
|
||||
|
|
|
@ -55,8 +55,8 @@ SELECT l.ad_client_id,
|
|||
(l.qtyordered - l.qtyinvoiced) * l.priceactual AS netamttoinvoice,
|
||||
l.qtylostsales,
|
||||
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.pricelimit = 0 THEN 0 ELSE round((l.priceactual - l.pricelimit) / l.pricelimit * 100, 2) END AS margin,
|
||||
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 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,
|
||||
o.ad_org_id AS c_order_ad_org_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
Loading…
Reference in New Issue