The Epicor example InvcDtl.OurShipQty * InvcDtl.MtlUnitCost should give you the right cost. Also the Epicor Fields already account for the InvcDtl.PricePerCode logic:
InvcDtl.PricePerCode
Indicates the pricing per quantity. It can be “E” = per each, “C” = per hundred, “M” = per thousand. Used to calculate the extended unit price for the line item. The logic is to divide the InvcDtl.ShipQty by the appropriate “per” value and then multiply by unit price. Use the OrderDtl.PricePerCode as default if referenced to an order else use Part.PricePerCode as a default. If Part record does not exist then default as “E”.
That formula would be your “Cost”. The Total Cost is Calculated using the INVENTORY QTY and IUM NOT SALES InvcDtl.MtlUnitCost would be based of your “Inventory UOM”
Now to get your NetUnitPrice you would do something like:
-------------------------------------------------
-- NetUnitPrice
-- ->,>>>,>>>,>>9.999
-------------------------------------------------
IIF(InvcDtl.SellingShipQty <> 0, (NetTotalPrice - TotalCost) / InvcDtl.SellingShipQty, 0)
@utaylor here are some more Notes I had of formulas:
=================================================
- MAINQuery
=================================================
-------------------------------------------------
-- MaterialCost
-- ->,>>>,>>>,>>9.999
-------------------------------------------------
InvcDtl.SellingShipQty * InvcDtl.MtlUnitCost
-------------------------------------------------
-- LaborCost
-- ->,>>>,>>>,>>9.999
-------------------------------------------------
InvcDtl.SellingShipQty * InvcDtl.LbrUnitCost
-------------------------------------------------
-- BurdenCost
-- ->,>>>,>>>,>>9.999
-------------------------------------------------
InvcDtl.SellingShipQty * InvcDtl.BurUnitCost
-------------------------------------------------
-- SubcontractCost
-- ->,>>>,>>>,>>9.999
-------------------------------------------------
InvcDtl.SellingShipQty * InvcDtl.SubUnitCost
-------------------------------------------------
-- MaterialBurdenCost
-- ->,>>>,>>>,>>9.999
-------------------------------------------------
InvcDtl.SellingShipQty * InvcDtl.MtlBurUnitCost
-------------------------------------------------
-- TotalCost
-- ->,>>>,>>>,>>9.999
-------------------------------------------------
(LaborCost + BurdenCost + MaterialCost + SubcontractCost + MaterialBurdenCost)
-------------------------------------------------
-- TotalTaxAmt
-- ->,>>>,>>>,>>9.999
-------------------------------------------------
ISNULL(InvcDtlTaxesSubQuery.Calculated_TotalTaxAmt, 0)
-------------------------------------------------
-- TotalMiscCharges
-- ->,>>>,>>>,>>9.999
-------------------------------------------------
ISNULL(InvcDtlMiscChargesSubQuery.Calculated_TotalMiscCharge, 0)
-------------------------------------------------
-- NetTotalPrice
-- ->,>>>,>>>,>>9.999
-------------------------------------------------
InvcDtl.ExtPrice - InvcDtl.Discount
(CASE WHEN InvcHead.DeferredRevenue = 1 OR InvcHead.CreditMemo = 1
THEN TotalMiscCharges
ELSE
InvcDtl.ExtPrice + TotalMiscCharges
END)
| ACCOUNTS TARGETED
ISNULL(TranGLC.GLAccount, '') + ISNULL(InvcDtlMiscChargesSubQuery.TranGLCMisc_GLAccount, '')
| SALES TOTAL
CASE WHEN InvcHead.DeferredRevenue = 1 OR InvcHead.CreditMemo = 1 THEN TotalMiscCharges
ELSE
InvcDtl.ExtPrice + TotalMiscCharges
END
| ACTUALAPPLYPERIOD
ISNULL(Erp.FiscalPeriod(InvcHead.Company, TranGLC.TranDate), InvcHead.FiscalPeriod)
-------------------------------------------------
-- NetProfitMarginAmt
-- ->,>>>,>>>,>>9.999
-------------------------------------------------
NetTotalPrice - TotalCost
-------------------------------------------------
-- NetProfitMarginPct
-- ->>>>9.99
-------------------------------------------------
IIF(NetTotalPrice <> 0, (NetProfitMarginAmt / NetTotalPrice) * 100, 0)
-------------------------------------------------
-- NetUnitPrice
-- ->,>>>,>>>,>>9.999
-------------------------------------------------
IIF(InvcDtl.SellingShipQty <> 0, (NetTotalPrice - TotalCost) / InvcDtl.SellingShipQty, 0)
-------------------------------------------------
-- GrossTotalPrice
-- ->,>>>,>>>,>>9.999
-------------------------------------------------
InvcDtl.ExtPrice + InvcDtl.TotalMiscChrg - InvcDtl.Discount - InvcDtl.AdvanceBillCredit + TotalTaxAmt
-------------------------------------------------
-- GrossProfitMarginAmt
-- ->,>>>,>>>,>>9.999
-------------------------------------------------
GrossTotalPrice - TotalCost
-------------------------------------------------
-- GrossProfitMarginPct
-- ->>>>9.99
-------------------------------------------------
IIF(GrossTotalPrice <> 0, (GrossProfitMarginAmt / GrossTotalPrice) * 100, 0)
-------------------------------------------------
-- ActShippingQty
-- ->>>>9.99
-------------------------------------------------
CASE
WHEN InvcHead.InvoiceSuffix = 'CM' OR InvcHead.InvoiceSuffix = 'UR' THEN
InvcDtl.SellingShipQty * -1
ELSE
InvcDtl.SellingShipQty
END
-------------------------------------------------
-- xLineQuantity
-- ->>>>9.99
-------------------------------------------------
(case when InvcHead.InvoiceType in ('ADV','DEP') then (case when InvcDtl.DocExtPrice<0 then -1 else 1 end)
else InvcDtl.SellingShipQty
end)*(case when InvcHead.CreditMemo=1 then -1 else 1 end)
-------------------------------------------------
-- xLineQuantityUnit
-- ->>>>9.99
-------------------------------------------------
(case when InvcHead.InvoiceType in ('ADV','DEP') then 'EA'
else InvcDtl.SalesUM
end)
-------------------------------------------------
-- xLineExtensionAmt
-- ->>>>9.99
-------------------------------------------------
(InvcDtl.DocExtPrice - InvcDtl.DocDiscount + InvcDtl.DocTotalMiscChrg)*(case when InvcHead.CreditMemo=1 then -1 else 1 end)
-------------------------------------------------
-- xACTUALUNITPrice xPriceAmt
-- ->>>>9.99
-------------------------------------------------
(case when InvcHead.InvoiceType in ('ADV','DEP') then abs(InvcDtl.DocExtPrice - InvcDtl.DocDiscount + InvcDtl.DocTotalMiscChrg)
else abs(InvcDtl.DocUnitPrice)
end)
-------------------------------------------------
-- xBaseQty
-- ->>>>9.99
-------------------------------------------------
(case when InvcHead.InvoiceType in ('ADV','DEP') then 1
else (case when InvcDtl.PricePerCode = 'E' then 1
when InvcDtl.PricePerCode = 'C' then 100
when InvcDtl.PricePerCode = 'M' then 1000
end)
end)
-------------------------------------------------
-- SalesTotalNoTax
-- ->>>>9.99
-------------------------------------------------
InvcDtl.ExtPrice + InvcDtl.TotalMiscChrg - InvcDtl.Discount - InvcDtl.AdvanceBillCredit
REFERENCES:
(((case when (OrderDtl.PricePerCode = 'M') then ((((case when
(OrderRel.SellingReqQty - OrderRel.SellingJobShippedQty - OrderRel.SellingStockShippedQty) > 0 then
(OrderRel.SellingReqQty - OrderRel.SellingJobShippedQty - OrderRel.SellingStockShippedQty) else 0 end))/ 1000)
* OrderDtl.DocUnitPrice * (1 - (OrderDtl.DiscountPercent / 100))) else ((case when (OrderDtl.PricePerCode = 'C')
then ((((case when (OrderRel.SellingReqQty - OrderRel.SellingJobShippedQty - OrderRel.SellingStockShippedQty) > 0 then (OrderRel.SellingReqQty - OrderRel.SellingJobShippedQty - OrderRel.SellingStockShippedQty) else 0 end))/ 100) * OrderDtl.DocUnitPrice * (1 - (OrderDtl.DiscountPercent / 100))) else ((((case when (OrderRel.SellingReqQty - OrderRel.SellingJobShippedQty - OrderRel.SellingStockShippedQty) > 0 then (OrderRel.SellingReqQty - OrderRel.SellingJobShippedQty - OrderRel.SellingStockShippedQty) else 0 end))/ 1) * OrderDtl.DocUnitPrice * (1 - (OrderDtl.DiscountPercent / 100))) end)) end))) as [Calculated_OpenValue],
* ISNULL(OrderDtl.UnitPrice, 0)) as [Calculated_ExtendedAmt],
((CASE
WHEN OrderDtl.PricePerCode = 'M' THEN (ISNULL(ShipDtl.SellingInventoryShipQty,0)+ ISNULL(ShipDtl.OurJobShipQty,0)) / 1000
WHEN OrderDtl.PricePerCode = 'C' THEN (ISNULL(ShipDtl.SellingInventoryShipQty,0)+ ISNULL(ShipDtl.OurJobShipQty,0)) / 100
ELSE (ISNULL(ShipDtl.SellingInventoryShipQty,0)+ ISNULL(ShipDtl.OurJobShipQty,0))
END)