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);
|
||||
RETURN v_TotalOpenAmt;
|
||||
-- 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;
|
||||
|
@ -106,13 +115,14 @@ BEGIN
|
|||
END IF;
|
||||
-- DBMS_OUTPUT.PUT_LINE('== Total=' || v_TotalOpenAmt);
|
||||
|
||||
-- Ignore Rounding
|
||||
IF (v_TotalOpenAmt BETWEEN -0.00999 AND 0.00999) THEN
|
||||
v_TotalOpenAmt := 0;
|
||||
END IF;
|
||||
-- Ignore Rounding
|
||||
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);
|
||||
RETURN v_TotalOpenAmt;
|
||||
-- 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
|
||||
|
@ -22,7 +22,9 @@ SELECT s.ad_client_id,
|
|||
JOIN m_product mp ON ms.m_product_id = mp.m_product_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_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
|
||||
|
@ -61,7 +64,9 @@ SELECT s.ad_client_id,
|
|||
JOIN m_product mp ON ms.m_product_id = mp.m_product_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_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,156 +1,141 @@
|
|||
CREATE OR REPLACE VIEW rv_c_invoiceline
|
||||
AS
|
||||
SELECT il.ad_client_id,
|
||||
il.ad_org_id,
|
||||
il.isactive,
|
||||
il.created,
|
||||
il.createdby,
|
||||
il.updated,
|
||||
il.updatedby,
|
||||
il.c_invoiceline_id,
|
||||
i.c_invoice_id,
|
||||
i.salesrep_id,
|
||||
i.c_bpartner_id,
|
||||
i.c_bp_group_id,
|
||||
il.m_product_id,
|
||||
p.m_product_category_id,
|
||||
i.dateinvoiced,
|
||||
i.dateacct,
|
||||
i.issotrx,
|
||||
i.c_doctype_id,
|
||||
i.docstatus,
|
||||
i.ispaid,
|
||||
il.c_campaign_id,
|
||||
il.c_project_id,
|
||||
il.c_activity_id,
|
||||
il.c_projectphase_id,
|
||||
il.c_projecttask_id,
|
||||
il.qtyinvoiced * i.multiplier AS qtyinvoiced,
|
||||
il.qtyentered * i.multiplier AS qtyentered,
|
||||
il.m_attributesetinstance_id,
|
||||
productattribute(il.m_attributesetinstance_id) AS productattribute,
|
||||
pasi.m_attributeset_id,
|
||||
pasi.m_lot_id,
|
||||
pasi.guaranteedate,
|
||||
pasi.lot,
|
||||
pasi.serno,
|
||||
il.pricelist,
|
||||
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,
|
||||
il.ad_orgtrx_id,
|
||||
il.a_processed,
|
||||
il.c_charge_id,
|
||||
il.c_orderline_id,
|
||||
il.c_tax_id,
|
||||
il.c_uom_id AS c_invoiceline_c_uom_id,
|
||||
il.description AS c_invoiceline_description,
|
||||
il.isdescription,
|
||||
il.isprinted,
|
||||
il.line,
|
||||
il.linenetamt AS c_invoiceline_linenetamt,
|
||||
il.linetotalamt,
|
||||
il.m_inoutline_id,
|
||||
il.m_rmaline_id,
|
||||
il.processed,
|
||||
il.ref_invoiceline_id,
|
||||
il.rramt,
|
||||
il.rrstartdate,
|
||||
il.s_resourceassignment_id,
|
||||
il.taxamt,
|
||||
il.user1_id,
|
||||
il.user2_id,
|
||||
p.ad_org_id AS m_product_ad_org_id,
|
||||
p.classification,
|
||||
p.copyfrom AS m_product_copyfrom,
|
||||
p.created AS m_product_created,
|
||||
p.createdby AS m_product_createdby,
|
||||
p.c_revenuerecognition_id,
|
||||
p.c_subscriptiontype_id,
|
||||
p.c_taxcategory_id,
|
||||
p.c_uom_id AS m_productline_c_uom_id,
|
||||
p.description AS m_product_description,
|
||||
p.descriptionurl,
|
||||
p.discontinued,
|
||||
p.discontinuedat,
|
||||
p.documentnote,
|
||||
p.group1,
|
||||
p.group2,
|
||||
p.guaranteedays,
|
||||
p.guaranteedaysmin,
|
||||
p.help,
|
||||
p.imageurl,
|
||||
p.isactive AS m_product_isactive,
|
||||
p.isdropship,
|
||||
p.isexcludeautodelivery,
|
||||
p.isinvoiceprintdetails,
|
||||
p.ispicklistprintdetails,
|
||||
p.ispurchased,
|
||||
p.isselfservice,
|
||||
p.issold,
|
||||
p.isstocked,
|
||||
p.issummary AS m_product_issummary,
|
||||
p.isverified,
|
||||
p.iswebstorefeatured,
|
||||
p.lowlevel,
|
||||
p.m_attributeset_id AS m_product_m_attributeset_id,
|
||||
p.m_freightcategory_id,
|
||||
p.m_locator_id,
|
||||
p.m_product_id AS m_product_m_product_id,
|
||||
p.processing AS m_product_processing,
|
||||
p.producttype,
|
||||
p.r_mailtext_id,
|
||||
p.salesrep_id AS m_product_salesrep_id,
|
||||
p.s_expensetype_id,
|
||||
p.shelfdepth,
|
||||
p.shelfheight,
|
||||
p.shelfwidth,
|
||||
p.sku,
|
||||
p.s_resource_id,
|
||||
p.unitsperpack,
|
||||
p.unitsperpallet,
|
||||
p.updated AS m_product_updated,
|
||||
p.updatedby AS m_product_updatedby,
|
||||
p.versionno,
|
||||
p.volume,
|
||||
p.weight,
|
||||
pasi.ad_org_id AS m_asi_ad_org_id,
|
||||
pasi.created AS m_attributesetinstance_created,
|
||||
pasi.createdby AS m_asi_createdby,
|
||||
pasi.description AS m_asi_description,
|
||||
pasi.isactive AS m_attributesetinstance_isacti,
|
||||
pasi.serno AS m_attributesetinstance_serno,
|
||||
pasi.updated AS m_attributesetinstance_updated,
|
||||
pasi.updatedby AS m_asi_updatedby
|
||||
FROM rv_c_invoice i
|
||||
JOIN c_invoiceline il
|
||||
ON i.c_invoice_id = il.c_invoice_id
|
||||
LEFT JOIN m_product p
|
||||
ON il.m_product_id = p.m_product_id
|
||||
LEFT JOIN m_attributesetinstance pasi
|
||||
ON il.m_attributesetinstance_id = pasi.m_attributesetinstance_id
|
||||
CREATE OR REPLACE VIEW rv_c_invoiceline AS
|
||||
SELECT il.ad_client_id,
|
||||
il.ad_org_id,
|
||||
il.isactive,
|
||||
il.created,
|
||||
il.createdby,
|
||||
il.updated,
|
||||
il.updatedby,
|
||||
il.c_invoiceline_id,
|
||||
i.c_invoice_id,
|
||||
i.salesrep_id,
|
||||
i.c_bpartner_id,
|
||||
i.c_bp_group_id,
|
||||
il.m_product_id,
|
||||
p.m_product_category_id,
|
||||
i.dateinvoiced,
|
||||
i.dateacct,
|
||||
i.issotrx,
|
||||
i.c_doctype_id,
|
||||
i.docstatus,
|
||||
i.ispaid,
|
||||
il.c_campaign_id,
|
||||
il.c_project_id,
|
||||
il.c_activity_id,
|
||||
il.c_projectphase_id,
|
||||
il.c_projecttask_id,
|
||||
il.qtyinvoiced * i.multiplier AS qtyinvoiced,
|
||||
il.qtyentered * i.multiplier AS qtyentered,
|
||||
il.m_attributesetinstance_id,
|
||||
productattribute(il.m_attributesetinstance_id) AS productattribute,
|
||||
pasi.m_attributeset_id,
|
||||
pasi.m_lot_id,
|
||||
pasi.guaranteedate,
|
||||
pasi.lot,
|
||||
pasi.serno,
|
||||
il.pricelist,
|
||||
il.priceactual,
|
||||
il.pricelimit,
|
||||
il.priceentered,
|
||||
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,
|
||||
il.c_orderline_id,
|
||||
il.c_tax_id,
|
||||
il.c_uom_id AS c_invoiceline_c_uom_id,
|
||||
il.description AS c_invoiceline_description,
|
||||
il.isdescription,
|
||||
il.isprinted,
|
||||
il.line,
|
||||
il.linenetamt AS c_invoiceline_linenetamt,
|
||||
il.linetotalamt,
|
||||
il.m_inoutline_id,
|
||||
il.m_rmaline_id,
|
||||
il.processed,
|
||||
il.ref_invoiceline_id,
|
||||
il.rramt,
|
||||
il.rrstartdate,
|
||||
il.s_resourceassignment_id,
|
||||
il.taxamt,
|
||||
il.user1_id,
|
||||
il.user2_id,
|
||||
p.ad_org_id AS m_product_ad_org_id,
|
||||
p.classification,
|
||||
p.copyfrom AS m_product_copyfrom,
|
||||
p.created AS m_product_created,
|
||||
p.createdby AS m_product_createdby,
|
||||
p.c_revenuerecognition_id,
|
||||
p.c_subscriptiontype_id,
|
||||
p.c_taxcategory_id,
|
||||
p.c_uom_id AS m_productline_c_uom_id,
|
||||
p.description AS m_product_description,
|
||||
p.descriptionurl,
|
||||
p.discontinued,
|
||||
p.discontinuedat,
|
||||
p.documentnote,
|
||||
p.group1,
|
||||
p.group2,
|
||||
p.guaranteedays,
|
||||
p.guaranteedaysmin,
|
||||
p.help,
|
||||
p.imageurl,
|
||||
p.isactive AS m_product_isactive,
|
||||
p.isdropship,
|
||||
p.isexcludeautodelivery,
|
||||
p.isinvoiceprintdetails,
|
||||
p.ispicklistprintdetails,
|
||||
p.ispurchased,
|
||||
p.isselfservice,
|
||||
p.issold,
|
||||
p.isstocked,
|
||||
p.issummary AS m_product_issummary,
|
||||
p.isverified,
|
||||
p.iswebstorefeatured,
|
||||
p.lowlevel,
|
||||
p.m_attributeset_id AS m_product_m_attributeset_id,
|
||||
p.m_freightcategory_id,
|
||||
p.m_locator_id,
|
||||
p.m_product_id AS m_product_m_product_id,
|
||||
p.processing AS m_product_processing,
|
||||
p.producttype,
|
||||
p.r_mailtext_id,
|
||||
p.salesrep_id AS m_product_salesrep_id,
|
||||
p.s_expensetype_id,
|
||||
p.shelfdepth,
|
||||
p.shelfheight,
|
||||
p.shelfwidth,
|
||||
p.sku,
|
||||
p.s_resource_id,
|
||||
p.unitsperpack,
|
||||
p.unitsperpallet,
|
||||
p.updated AS m_product_updated,
|
||||
p.updatedby AS m_product_updatedby,
|
||||
p.versionno,
|
||||
p.volume,
|
||||
p.weight,
|
||||
pasi.ad_org_id AS m_asi_ad_org_id,
|
||||
pasi.created AS m_attributesetinstance_created,
|
||||
pasi.createdby AS m_asi_createdby,
|
||||
pasi.description AS m_asi_description,
|
||||
pasi.isactive AS m_attributesetinstance_isacti,
|
||||
pasi.serno AS m_attributesetinstance_serno,
|
||||
pasi.updated AS m_attributesetinstance_updated,
|
||||
pasi.updatedby AS m_asi_updatedby
|
||||
FROM rv_c_invoice i
|
||||
JOIN c_invoiceline il
|
||||
ON i.c_invoice_id = il.c_invoice_id
|
||||
LEFT JOIN m_product p
|
||||
ON il.m_product_id = p.m_product_id
|
||||
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 M_Product_PO po ON (il.M_Product_ID=po.M_Product_ID)
|
||||
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,158 +1,153 @@
|
|||
DROP VIEW rv_openitem;
|
||||
|
||||
CREATE OR REPLACE VIEW rv_openitem
|
||||
AS
|
||||
SELECT i.ad_org_id,
|
||||
i.ad_client_id,
|
||||
i.documentno,
|
||||
i.c_invoice_id,
|
||||
i.c_order_id,
|
||||
i.c_bpartner_id,
|
||||
i.issotrx,
|
||||
i.dateinvoiced,
|
||||
i.dateacct,
|
||||
p.netdays,
|
||||
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,
|
||||
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,
|
||||
NULL AS c_invoicepayschedule_id,
|
||||
i.invoicecollectiontype,
|
||||
i.c_campaign_id,
|
||||
i.c_project_id,
|
||||
i.c_activity_id,
|
||||
i.c_invoice_ad_orgtrx_id AS ad_orgtrx_id,
|
||||
i.ad_user_id,
|
||||
i.c_bpartner_location_id,
|
||||
i.c_charge_id,
|
||||
i.c_doctype_id,
|
||||
i.c_doctypetarget_id,
|
||||
i.c_dunninglevel_id,
|
||||
i.chargeamt,
|
||||
i.c_payment_id,
|
||||
i.created,
|
||||
i.createdby,
|
||||
i.dateordered,
|
||||
i.dateprinted,
|
||||
i.description,
|
||||
i.docaction,
|
||||
i.docstatus,
|
||||
i.dunninggrace,
|
||||
i.generateto,
|
||||
i.isactive,
|
||||
i.isapproved,
|
||||
i.isdiscountprinted,
|
||||
i.isindispute,
|
||||
i.ispaid,
|
||||
i.isprinted,
|
||||
i.c_invoice_isselfservice AS isselfservice,
|
||||
i.istaxincluded,
|
||||
i.istransferred,
|
||||
i.m_pricelist_id,
|
||||
i.m_rma_id,
|
||||
i.paymentrule,
|
||||
i.poreference,
|
||||
i.posted,
|
||||
i.processedon,
|
||||
i.processing,
|
||||
i.ref_invoice_id,
|
||||
i.reversal_id,
|
||||
i.salesrep_id,
|
||||
i.sendemail,
|
||||
i.totallines,
|
||||
i.updated,
|
||||
i.updatedby,
|
||||
i.user1_id,
|
||||
i.user2_id
|
||||
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,
|
||||
i.ad_client_id,
|
||||
i.documentno,
|
||||
i.c_invoice_id,
|
||||
i.c_order_id,
|
||||
i.c_bpartner_id,
|
||||
i.issotrx,
|
||||
i.dateinvoiced,
|
||||
i.dateacct,
|
||||
daysbetween(ips.duedate, i.dateinvoiced) AS netdays,
|
||||
ips.duedate,
|
||||
daysbetween(getdate(), ips.duedate) AS daysdue,
|
||||
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,
|
||||
i.c_currency_id,
|
||||
i.c_conversiontype_id,
|
||||
i.c_paymentterm_id,
|
||||
i.ispayschedulevalid,
|
||||
ips.c_invoicepayschedule_id,
|
||||
i.invoicecollectiontype,
|
||||
i.c_campaign_id,
|
||||
i.c_project_id,
|
||||
i.c_activity_id,
|
||||
i.c_invoice_ad_orgtrx_id AS ad_orgtrx_id,
|
||||
i.ad_user_id,
|
||||
i.c_bpartner_location_id,
|
||||
i.c_charge_id,
|
||||
i.c_doctype_id,
|
||||
i.c_doctypetarget_id,
|
||||
i.c_dunninglevel_id,
|
||||
i.chargeamt,
|
||||
i.c_payment_id,
|
||||
i.created,
|
||||
i.createdby,
|
||||
i.dateordered,
|
||||
i.dateprinted,
|
||||
i.description,
|
||||
i.docaction,
|
||||
i.docstatus,
|
||||
i.dunninggrace,
|
||||
i.generateto,
|
||||
i.isactive,
|
||||
i.isapproved,
|
||||
i.isdiscountprinted,
|
||||
i.isindispute,
|
||||
i.ispaid,
|
||||
i.isprinted,
|
||||
i.c_invoice_isselfservice AS isselfservice,
|
||||
i.istaxincluded,
|
||||
i.istransferred,
|
||||
i.m_pricelist_id,
|
||||
i.m_rma_id,
|
||||
i.paymentrule,
|
||||
i.poreference,
|
||||
i.posted,
|
||||
i.processedon,
|
||||
i.processing,
|
||||
i.ref_invoice_id,
|
||||
i.reversal_id,
|
||||
i.salesrep_id,
|
||||
i.sendemail,
|
||||
i.totallines,
|
||||
i.updated,
|
||||
i.updatedby,
|
||||
i.user1_id,
|
||||
i.user2_id
|
||||
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'
|
||||
CREATE OR REPLACE VIEW rv_openitem AS
|
||||
SELECT i.ad_org_id,
|
||||
i.ad_client_id,
|
||||
i.documentno,
|
||||
i.c_invoice_id,
|
||||
i.c_order_id,
|
||||
i.c_bpartner_id,
|
||||
i.issotrx,
|
||||
i.dateinvoiced,
|
||||
i.dateacct,
|
||||
p.netdays,
|
||||
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,
|
||||
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,
|
||||
NULL AS c_invoicepayschedule_id,
|
||||
i.invoicecollectiontype,
|
||||
i.c_campaign_id,
|
||||
i.c_project_id,
|
||||
i.c_activity_id,
|
||||
i.c_invoice_ad_orgtrx_id AS ad_orgtrx_id,
|
||||
i.ad_user_id,
|
||||
i.c_bpartner_location_id,
|
||||
i.c_charge_id,
|
||||
i.c_doctype_id,
|
||||
i.c_doctypetarget_id,
|
||||
i.c_dunninglevel_id,
|
||||
i.chargeamt,
|
||||
i.c_payment_id,
|
||||
i.created,
|
||||
i.createdby,
|
||||
i.dateordered,
|
||||
i.dateprinted,
|
||||
i.description,
|
||||
i.docaction,
|
||||
i.docstatus,
|
||||
i.dunninggrace,
|
||||
i.generateto,
|
||||
i.isactive,
|
||||
i.isapproved,
|
||||
i.isdiscountprinted,
|
||||
i.isindispute,
|
||||
i.ispaid,
|
||||
i.isprinted,
|
||||
i.c_invoice_isselfservice AS isselfservice,
|
||||
i.istaxincluded,
|
||||
i.istransferred,
|
||||
i.m_pricelist_id,
|
||||
i.m_rma_id,
|
||||
i.paymentrule,
|
||||
i.poreference,
|
||||
i.posted,
|
||||
i.processedon,
|
||||
i.processing,
|
||||
i.ref_invoice_id,
|
||||
i.reversal_id,
|
||||
i.salesrep_id,
|
||||
i.sendemail,
|
||||
i.totallines,
|
||||
i.updated,
|
||||
i.updatedby,
|
||||
i.user1_id,
|
||||
i.user2_id
|
||||
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,
|
||||
i.ad_client_id,
|
||||
i.documentno,
|
||||
i.c_invoice_id,
|
||||
i.c_order_id,
|
||||
i.c_bpartner_id,
|
||||
i.issotrx,
|
||||
i.dateinvoiced,
|
||||
i.dateacct,
|
||||
daysbetween(ips.duedate, i.dateinvoiced) AS netdays,
|
||||
ips.duedate,
|
||||
daysbetween(getdate(), ips.duedate) AS daysdue,
|
||||
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,
|
||||
i.c_currency_id,
|
||||
i.c_conversiontype_id,
|
||||
i.c_paymentterm_id,
|
||||
i.ispayschedulevalid,
|
||||
ips.c_invoicepayschedule_id,
|
||||
i.invoicecollectiontype,
|
||||
i.c_campaign_id,
|
||||
i.c_project_id,
|
||||
i.c_activity_id,
|
||||
i.c_invoice_ad_orgtrx_id AS ad_orgtrx_id,
|
||||
i.ad_user_id,
|
||||
i.c_bpartner_location_id,
|
||||
i.c_charge_id,
|
||||
i.c_doctype_id,
|
||||
i.c_doctypetarget_id,
|
||||
i.c_dunninglevel_id,
|
||||
i.chargeamt,
|
||||
i.c_payment_id,
|
||||
i.created,
|
||||
i.createdby,
|
||||
i.dateordered,
|
||||
i.dateprinted,
|
||||
i.description,
|
||||
i.docaction,
|
||||
i.docstatus,
|
||||
i.dunninggrace,
|
||||
i.generateto,
|
||||
i.isactive,
|
||||
i.isapproved,
|
||||
i.isdiscountprinted,
|
||||
i.isindispute,
|
||||
i.ispaid,
|
||||
i.isprinted,
|
||||
i.c_invoice_isselfservice AS isselfservice,
|
||||
i.istaxincluded,
|
||||
i.istransferred,
|
||||
i.m_pricelist_id,
|
||||
i.m_rma_id,
|
||||
i.paymentrule,
|
||||
i.poreference,
|
||||
i.posted,
|
||||
i.processedon,
|
||||
i.processing,
|
||||
i.ref_invoice_id,
|
||||
i.reversal_id,
|
||||
i.salesrep_id,
|
||||
i.sendemail,
|
||||
i.totallines,
|
||||
i.updated,
|
||||
i.updatedby,
|
||||
i.user1_id,
|
||||
i.user2_id
|
||||
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'
|
||||
;
|
||||
|
||||
|
|
|
@ -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'
|
||||
i.IsPayScheduleValid<>'Y'
|
||||
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,178 +1,167 @@
|
|||
DROP VIEW rv_orderdetail;
|
||||
|
||||
CREATE OR REPLACE VIEW rv_orderdetail
|
||||
AS
|
||||
SELECT l.ad_client_id,
|
||||
l.ad_org_id,
|
||||
l.isactive,
|
||||
l.created,
|
||||
l.createdby,
|
||||
l.updated,
|
||||
l.updatedby,
|
||||
o.c_order_id,
|
||||
o.docstatus,
|
||||
o.docaction,
|
||||
o.c_doctype_id,
|
||||
o.isapproved,
|
||||
o.iscreditapproved,
|
||||
o.salesrep_id,
|
||||
o.bill_bpartner_id,
|
||||
o.bill_location_id,
|
||||
o.bill_user_id,
|
||||
o.isdropship,
|
||||
l.c_bpartner_id,
|
||||
l.c_bpartner_location_id,
|
||||
o.ad_user_id,
|
||||
o.poreference,
|
||||
o.c_currency_id,
|
||||
o.issotrx,
|
||||
l.c_campaign_id,
|
||||
l.c_project_id,
|
||||
l.c_activity_id,
|
||||
l.c_projectphase_id,
|
||||
l.c_projecttask_id,
|
||||
l.c_orderline_id,
|
||||
l.dateordered,
|
||||
l.datepromised,
|
||||
l.m_product_id,
|
||||
l.m_warehouse_id,
|
||||
l.m_attributesetinstance_id,
|
||||
productattribute(l.m_attributesetinstance_id) AS productattribute,
|
||||
pasi.m_attributeset_id,
|
||||
pasi.m_lot_id,
|
||||
pasi.guaranteedate,
|
||||
pasi.lot,
|
||||
pasi.serno,
|
||||
l.c_uom_id,
|
||||
l.qtyentered,
|
||||
l.qtyordered,
|
||||
l.qtyreserved,
|
||||
l.qtydelivered,
|
||||
l.qtyinvoiced,
|
||||
l.priceactual,
|
||||
l.priceentered,
|
||||
l.qtyordered - l.qtydelivered AS qtytodeliver,
|
||||
l.qtyordered - l.qtyinvoiced AS qtytoinvoice,
|
||||
( 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,
|
||||
o.ad_org_id AS c_order_ad_org_id,
|
||||
o.ad_orgtrx_id AS c_order_ad_orgtrx_id,
|
||||
o.amountrefunded,
|
||||
o.amounttendered,
|
||||
o.c_activity_id AS c_order_c_activity_id,
|
||||
o.c_bpartner_id AS c_order_c_bpartner_id,
|
||||
o.c_bpartner_location_id AS c_order_c_bpartner_loc_id,
|
||||
o.c_campaign_id AS c_order_c_compaign_id,
|
||||
o.c_cashline_id,
|
||||
o.c_cashplanline_id,
|
||||
o.c_charge_id AS c_order_c_charge_id,
|
||||
o.c_conversiontype_id,
|
||||
o.c_doctypetarget_id,
|
||||
o.chargeamt,
|
||||
o.copyfrom,
|
||||
o.c_payment_id,
|
||||
o.c_paymentterm_id,
|
||||
o.c_pos_id,
|
||||
o.c_project_id AS c_order_c_project_id,
|
||||
o.created AS c_order_created,
|
||||
o.createdby AS c_order_createdby,
|
||||
o.dateacct,
|
||||
o.dateordered AS c_order_dateordered,
|
||||
o.dateprinted,
|
||||
o.datepromised AS c_order_datepromised,
|
||||
o.deliveryrule,
|
||||
o.deliveryviarule,
|
||||
o.description AS c_order_description,
|
||||
o.documentno,
|
||||
o.dropship_bpartner_id,
|
||||
o.dropship_location_id,
|
||||
o.dropship_user_id,
|
||||
o.freightamt AS c_order_freightamt,
|
||||
o.freightcostrule,
|
||||
o.grandtotal,
|
||||
o.invoicerule,
|
||||
o.isactive AS c_order_isactive,
|
||||
o.isdelivered,
|
||||
o.isdiscountprinted,
|
||||
o.isinvoiced,
|
||||
o.ispayschedulevalid,
|
||||
o.isprinted,
|
||||
o.isselected,
|
||||
o.isselfservice,
|
||||
o.istaxincluded,
|
||||
o.istransferred,
|
||||
o.link_order_id,
|
||||
o.m_freightcategory_id,
|
||||
o.m_pricelist_id,
|
||||
o.m_shipper_id AS c_order_m_shipper_id,
|
||||
o.m_warehouse_id AS c_order_m_warehouse_id,
|
||||
o.ordertype,
|
||||
o.pay_bpartner_id,
|
||||
o.pay_location_id,
|
||||
o.paymentrule,
|
||||
o.posted,
|
||||
o.priorityrule,
|
||||
o.processed AS c_order_processed,
|
||||
o.processedon,
|
||||
o.promotioncode,
|
||||
o.ref_order_id,
|
||||
o.sendemail,
|
||||
o.totallines,
|
||||
o.updated AS c_order_updated,
|
||||
o.updatedby AS c_order_updatedby,
|
||||
o.user1_id AS c_order_user1_id,
|
||||
o.user2_id AS c_order_user2_id,
|
||||
o.volume,
|
||||
o.weight,
|
||||
l.ad_orgtrx_id AS c_orderline_ad_orgtrx_id,
|
||||
l.c_charge_id AS c_orderline_c_charge_id,
|
||||
l.c_currency_id AS c_orderline_c_currency_id,
|
||||
l.c_tax_id,
|
||||
l.datedelivered,
|
||||
l.dateinvoiced,
|
||||
l.description AS c_orderline_description,
|
||||
l.discount AS c_orderline_discount,
|
||||
l.freightamt AS c_orderline_freightamt,
|
||||
l.isdescription,
|
||||
l.line,
|
||||
l.linenetamt,
|
||||
l.link_orderline_id,
|
||||
l.m_promotion_id,
|
||||
l.m_shipper_id AS c_orderline_m_shipper_id,
|
||||
l.pricecost,
|
||||
l.pricelimit,
|
||||
l.pricelist,
|
||||
l.processed AS c_orderline_processed,
|
||||
l.ref_orderline_id,
|
||||
l.rramt,
|
||||
l.rrstartdate,
|
||||
l.s_resourceassignment_id,
|
||||
l.user1_id AS c_orderline_user1_id,
|
||||
l.user2_id AS c_orderline_user2_id,
|
||||
pasi.ad_org_id AS m_asi_ad_org_id,
|
||||
pasi.created AS m_asi_created,
|
||||
pasi.createdby AS m_asi_createdby,
|
||||
pasi.description AS m_asi_description,
|
||||
pasi.isactive AS m_asi_isactive,
|
||||
pasi.updated AS m_asi_updated,
|
||||
pasi.updatedby AS m_asi_updatedby
|
||||
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
|
||||
CREATE OR REPLACE VIEW rv_orderdetail AS
|
||||
SELECT l.ad_client_id,
|
||||
l.ad_org_id,
|
||||
l.isactive,
|
||||
l.created,
|
||||
l.createdby,
|
||||
l.updated,
|
||||
l.updatedby,
|
||||
o.c_order_id,
|
||||
o.docstatus,
|
||||
o.docaction,
|
||||
o.c_doctype_id,
|
||||
o.isapproved,
|
||||
o.iscreditapproved,
|
||||
o.salesrep_id,
|
||||
o.bill_bpartner_id,
|
||||
o.bill_location_id,
|
||||
o.bill_user_id,
|
||||
o.isdropship,
|
||||
l.c_bpartner_id,
|
||||
l.c_bpartner_location_id,
|
||||
o.ad_user_id,
|
||||
o.poreference,
|
||||
o.c_currency_id,
|
||||
o.issotrx,
|
||||
l.c_campaign_id,
|
||||
l.c_project_id,
|
||||
l.c_activity_id,
|
||||
l.c_projectphase_id,
|
||||
l.c_projecttask_id,
|
||||
l.c_orderline_id,
|
||||
l.dateordered,
|
||||
l.datepromised,
|
||||
l.m_product_id,
|
||||
l.m_warehouse_id,
|
||||
l.m_attributesetinstance_id,
|
||||
productattribute(l.m_attributesetinstance_id) AS productattribute,
|
||||
pasi.m_attributeset_id,
|
||||
pasi.m_lot_id,
|
||||
pasi.guaranteedate,
|
||||
pasi.lot,
|
||||
pasi.serno,
|
||||
l.c_uom_id,
|
||||
l.qtyentered,
|
||||
l.qtyordered,
|
||||
l.qtyreserved,
|
||||
l.qtydelivered,
|
||||
l.qtyinvoiced,
|
||||
l.priceactual,
|
||||
l.priceentered,
|
||||
l.qtyordered - l.qtydelivered AS qtytodeliver,
|
||||
l.qtyordered - l.qtyinvoiced AS qtytoinvoice,
|
||||
(l.qtyordered - l.qtyinvoiced) * l.priceactual AS netamttoinvoice,
|
||||
l.qtylostsales,
|
||||
l.qtylostsales * l.priceactual AS amtlostsales,
|
||||
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,
|
||||
o.amounttendered,
|
||||
o.c_activity_id AS c_order_c_activity_id,
|
||||
o.c_bpartner_id AS c_order_c_bpartner_id,
|
||||
o.c_bpartner_location_id AS c_order_c_bpartner_loc_id,
|
||||
o.c_campaign_id AS c_order_c_compaign_id,
|
||||
o.c_cashline_id,
|
||||
o.c_cashplanline_id,
|
||||
o.c_charge_id AS c_order_c_charge_id,
|
||||
o.c_conversiontype_id,
|
||||
o.c_doctypetarget_id,
|
||||
o.chargeamt,
|
||||
o.copyfrom,
|
||||
o.c_payment_id,
|
||||
o.c_paymentterm_id,
|
||||
o.c_pos_id,
|
||||
o.c_project_id AS c_order_c_project_id,
|
||||
o.created AS c_order_created,
|
||||
o.createdby AS c_order_createdby,
|
||||
o.dateacct,
|
||||
o.dateordered AS c_order_dateordered,
|
||||
o.dateprinted,
|
||||
o.datepromised AS c_order_datepromised,
|
||||
o.deliveryrule,
|
||||
o.deliveryviarule,
|
||||
o.description AS c_order_description,
|
||||
o.documentno,
|
||||
o.dropship_bpartner_id,
|
||||
o.dropship_location_id,
|
||||
o.dropship_user_id,
|
||||
o.freightamt AS c_order_freightamt,
|
||||
o.freightcostrule,
|
||||
o.grandtotal,
|
||||
o.invoicerule,
|
||||
o.isactive AS c_order_isactive,
|
||||
o.isdelivered,
|
||||
o.isdiscountprinted,
|
||||
o.isinvoiced,
|
||||
o.ispayschedulevalid,
|
||||
o.isprinted,
|
||||
o.isselected,
|
||||
o.isselfservice,
|
||||
o.istaxincluded,
|
||||
o.istransferred,
|
||||
o.link_order_id,
|
||||
o.m_freightcategory_id,
|
||||
o.m_pricelist_id,
|
||||
o.m_shipper_id AS c_order_m_shipper_id,
|
||||
o.m_warehouse_id AS c_order_m_warehouse_id,
|
||||
o.ordertype,
|
||||
o.pay_bpartner_id,
|
||||
o.pay_location_id,
|
||||
o.paymentrule,
|
||||
o.posted,
|
||||
o.priorityrule,
|
||||
o.processed AS c_order_processed,
|
||||
o.processedon,
|
||||
o.promotioncode,
|
||||
o.ref_order_id,
|
||||
o.sendemail,
|
||||
o.totallines,
|
||||
o.updated AS c_order_updated,
|
||||
o.updatedby AS c_order_updatedby,
|
||||
o.user1_id AS c_order_user1_id,
|
||||
o.user2_id AS c_order_user2_id,
|
||||
o.volume,
|
||||
o.weight,
|
||||
l.ad_orgtrx_id AS c_orderline_ad_orgtrx_id,
|
||||
l.c_charge_id AS c_orderline_c_charge_id,
|
||||
l.c_currency_id AS c_orderline_c_currency_id,
|
||||
l.c_tax_id,
|
||||
l.datedelivered,
|
||||
l.dateinvoiced,
|
||||
l.description AS c_orderline_description,
|
||||
l.discount AS c_orderline_discount,
|
||||
l.freightamt AS c_orderline_freightamt,
|
||||
l.isdescription,
|
||||
l.line,
|
||||
l.linenetamt,
|
||||
l.link_orderline_id,
|
||||
l.m_promotion_id,
|
||||
l.m_shipper_id AS c_orderline_m_shipper_id,
|
||||
l.pricecost,
|
||||
l.pricelimit,
|
||||
l.pricelist,
|
||||
l.processed AS c_orderline_processed,
|
||||
l.ref_orderline_id,
|
||||
l.rramt,
|
||||
l.rrstartdate,
|
||||
l.s_resourceassignment_id,
|
||||
l.user1_id AS c_orderline_user1_id,
|
||||
l.user2_id AS c_orderline_user2_id,
|
||||
pasi.ad_org_id AS m_asi_ad_org_id,
|
||||
pasi.created AS m_asi_created,
|
||||
pasi.createdby AS m_asi_createdby,
|
||||
pasi.description AS m_asi_description,
|
||||
pasi.isactive AS m_asi_isactive,
|
||||
pasi.updated AS m_asi_updated,
|
||||
pasi.updatedby AS m_asi_updatedby
|
||||
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,
|
||||
|
@ -112,14 +121,15 @@ BEGIN
|
|||
END IF;
|
||||
-- DBMS_OUTPUT.PUT_LINE('== Total=' || v_TotalOpenAmt);
|
||||
|
||||
-- Ignore Rounding
|
||||
IF (v_TotalOpenAmt BETWEEN -0.00999 AND 0.00999) THEN
|
||||
v_TotalOpenAmt := 0;
|
||||
END IF;
|
||||
-- Ignore Rounding
|
||||
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);
|
||||
RETURN v_TotalOpenAmt;
|
||||
-- Round to currency precision
|
||||
v_TotalOpenAmt := ROUND(COALESCE(v_TotalOpenAmt,0), v_Precision);
|
||||
|
||||
RETURN v_TotalOpenAmt;
|
||||
END;
|
||||
$BODY$
|
||||
LANGUAGE 'plpgsql' ;
|
||||
|
|
|
@ -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
|
||||
|
@ -22,7 +22,9 @@ SELECT s.ad_client_id,
|
|||
JOIN m_product mp ON ms.m_product_id = mp.m_product_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_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
|
||||
|
@ -61,7 +64,9 @@ SELECT s.ad_client_id,
|
|||
JOIN m_product mp ON ms.m_product_id = mp.m_product_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_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 M_Product_PO po ON (il.M_Product_ID=po.M_Product_ID)
|
||||
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