protected void AddUsage(PXCache sender, int?contractID, int?inventoryID, decimal?used, string UOM) { if (contractID != null && inventoryID != null) { Contract contract = PXSelect <Contract, Where <Contract.contractID, Equal <Required <Contract.contractID> > > > .Select(this, contractID); //update all revisions starting from last active foreach (ContractDetailExt targetItem in PXSelectJoin <ContractDetailExt, InnerJoin <ContractItem, On <ContractItem.contractItemID, Equal <ContractDetailExt.contractItemID> >, InnerJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <ContractItem.recurringItemID> > > >, Where <ContractDetailExt.contractID, Equal <Required <ContractDetailExt.contractID> >, And <ContractDetailExt.revID, GreaterEqual <Required <ContractDetailExt.revID> >, And <ContractItem.recurringItemID, Equal <Required <ContractItem.recurringItemID> > > > > > .Select(this, contractID, contract.LastActiveRevID, inventoryID)) { decimal inTargetUnit = used ?? 0; if (!string.IsNullOrEmpty(UOM)) { inTargetUnit = INUnitAttribute.ConvertToBase(sender, inventoryID, UOM, used ?? 0, INPrecision.QUANTITY); } ContractDetailAcum item = new ContractDetailAcum(); item.ContractDetailID = targetItem.ContractDetailID; item = ContractDetails.Insert(item); item.Used += inTargetUnit; item.UsedTotal += inTargetUnit; } } }
protected virtual void ARSalesPrice_SalesPrice_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e) { ARSalesPrice row = e.Row as ARSalesPrice; if (row != null) { InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <ARSalesPrice.inventoryID> > > > .Select(this, row.InventoryID); if (item != null) { if (row.CuryID == Company.Current.BaseCuryID) { if (row.UOM == item.BaseUnit) { e.NewValue = item.BasePrice; } else { e.NewValue = INUnitAttribute.ConvertToBase(sender, item.InventoryID, row.UOM ?? item.SalesUnit, item.BasePrice.Value, INPrecision.UNITCOST); } } } } else { e.NewValue = 0m; } }
public static decimal? AdjustUnitCost(PXCache sender, UnitCostItem ucItem, int? inventoryID, CurrencyInfo currencyinfo, string UOM, decimal? currentUnitCost) { if (ucItem != null) { decimal unitCost = ucItem.Cost; if (currencyinfo != null && ucItem.CuryID != currencyinfo.CuryID) { PXCurrencyAttribute.CuryConvCury(sender, currencyinfo, ucItem.Cost, out unitCost); } if (UOM == null) { return null; } if (ucItem.UOM != UOM) { decimal salesPriceInBase = INUnitAttribute.ConvertFromBase(sender, inventoryID, ucItem.UOM, unitCost, INPrecision.UNITCOST); unitCost = INUnitAttribute.ConvertToBase(sender, inventoryID, UOM, salesPriceInBase, INPrecision.UNITCOST); } if (unitCost == 0m && currentUnitCost != null && currentUnitCost != 0m) return currentUnitCost; else return unitCost; } return null; }
protected virtual void CROpportunityProducts_CuryUnitCost_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e) { if (e.Row == null) { return; } CROpportunityProducts crOpportunityProductsRow = (CROpportunityProducts)e.Row; FSxCROpportunityProducts fsxCROpportunityProductsRow = cache.GetExtension <FSxCROpportunityProducts>(crOpportunityProductsRow); if (string.IsNullOrEmpty(crOpportunityProductsRow.UOM) == false && crOpportunityProductsRow.InventoryID != null && crOpportunityProductsRow.POCreate == true) { object unitcost; cache.RaiseFieldDefaulting <CROpportunityProducts.unitCost>(e.Row, out unitcost); if (unitcost != null && (decimal)unitcost != 0m) { decimal newval = INUnitAttribute.ConvertToBase <CROpportunityProducts.inventoryID, CROpportunityProducts.uOM>(cache, crOpportunityProductsRow, (decimal)unitcost, INPrecision.NOROUND); IPXCurrencyHelper currencyHelper = Base.FindImplementation <IPXCurrencyHelper>(); if (currencyHelper != null) { currencyHelper.CuryConvCury((decimal)unitcost, out newval); } else { CM.PXDBCurrencyAttribute.CuryConvCury(cache, crOpportunityProductsRow, newval, out newval, true); } e.NewValue = Math.Round(newval, CommonSetupDecPl.PrcCst, MidpointRounding.AwayFromZero); e.Cancel = true; } } }
public static UnitCostPair CalculateCuryUnitCost <unitCostField, inventoryIDField, uomField>(PXCache cache, object row, bool raiseUnitCostDefaulting, decimal?unitCost) where unitCostField : IBqlField where inventoryIDField : IBqlField where uomField : IBqlField { decimal curyUnitCost = 0m; if (raiseUnitCostDefaulting == true) { object unitCostObj; cache.RaiseFieldDefaulting <unitCostField>(row, out unitCostObj); unitCost = (decimal?)unitCostObj; } if (unitCost != null && unitCost != 0m) { decimal valueConvertedToBase = INUnitAttribute.ConvertToBase <inventoryIDField, uomField>(cache, row, unitCost.Value, INPrecision.NOROUND); IPXCurrencyHelper currencyHelper = cache.Graph.FindImplementation <IPXCurrencyHelper>(); if (currencyHelper != null) { currencyHelper.CuryConvCury(unitCost.Value, out valueConvertedToBase); } else { CM.PXDBCurrencyAttribute.CuryConvCury(cache, row, valueConvertedToBase, out valueConvertedToBase, true); } curyUnitCost = Math.Round(valueConvertedToBase, CommonSetupDecPl.PrcCst, MidpointRounding.AwayFromZero); } return(new UnitCostPair(curyUnitCost, unitCost)); }
public decimal GetQuantityInBaseUOMs(ARTran tran) { return(INUnitAttribute.ConvertToBase( this.Caches[typeof(ARTran)], tran.InventoryID, tran.UOM, (tran.Qty ?? 0), INPrecision.QUANTITY)); }
/// <summary> /// Calculates Sales Price. /// </summary> /// <param name="sender">Cache</param> /// <param name="inventoryID">Inventory</param> /// <param name="curyID">Currency</param> /// <param name="UOM">Unit of measure</param> /// <param name="date">Date</param> /// <param name="alwaysFromBaseCurrency">If true sales price is always calculated (converted) from Base Currency.</param> /// <returns>Sales Price.</returns> public static decimal?CalculateSalesPrice(PXCache sender, int inventoryID, string curyID, string UOM, DateTime date, bool alwaysFromBaseCurrency) { InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(sender.Graph, inventoryID); decimal?salesPrice = null; #region Search for Sales Price in PriceList if (alwaysFromBaseCurrency == false) { SalesPriceItem spItem = FindSalesPrice(sender, inventoryID, curyID, UOM, date); if (spItem != null) { if (spItem.UOM != UOM) { decimal salesPriceInBase = INUnitAttribute.ConvertToBase(sender, inventoryID, spItem.UOM, spItem.Price, INPrecision.UNITCOST); salesPrice = INUnitAttribute.ConvertFromBase(sender, inventoryID, UOM, salesPriceInBase, INPrecision.UNITCOST); } else { salesPrice = spItem.Price; } } } #endregion if (salesPrice == null) { #region Calculate from Base Price if (item.BasePriceDate != null) { decimal salesPriceInBase; if (date < item.BasePriceDate.Value) { //use last price PXCurrencyAttribute.CuryConvCury(sender, null, item.LastBasePrice.Value, out salesPriceInBase); } else { //use current price PXCurrencyAttribute.CuryConvCury(sender, null, item.BasePrice.Value, out salesPriceInBase); } salesPrice = INUnitAttribute.ConvertFromBase(sender, inventoryID, UOM, salesPriceInBase, INPrecision.UNITCOST); } #endregion } return(salesPrice); }
protected virtual void DefaultUnitCost(PXCache sender, PXFieldUpdatedEventArgs e) { object UnitCost; sender.RaiseFieldDefaulting <INTran.unitCost>(e.Row, out UnitCost); if (UnitCost != null && (decimal)UnitCost != 0m) { decimal?unitcost = INUnitAttribute.ConvertToBase <INTran.inventoryID>(sender, e.Row, ((INTran)e.Row).UOM, (decimal)UnitCost, INPrecision.UNITCOST); sender.SetValueExt <INTran.unitCost>(e.Row, unitcost); } }
/// <summary> /// Calculates Unit Cost. /// </summary> /// <param name="sender">Cache</param> /// <param name="inventoryID">Inventory</param> /// <param name="curyID">Currency</param> /// <param name="UOM">Unit of measure</param> /// <param name="date">Date</param> /// <returns>Unit Cost</returns> public static decimal?CalculateUnitCost(PXCache sender, int?vendorID, int?vendorLocationID, int?inventoryID, CurrencyInfo currencyinfo, string UOM, decimal?quantity, DateTime date, decimal?currentUnitCost, bool alwaysFromBaseCurrency = false) { InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(sender.Graph, inventoryID); UnitCostItem ucItem = FindUnitCost(sender, vendorID, vendorLocationID, inventoryID, alwaysFromBaseCurrency ? currencyinfo.BaseCuryID : currencyinfo.CuryID, Math.Abs(quantity ?? 0m), UOM, date); if (ucItem != null) { decimal unitCost = ucItem.Cost; if (ucItem.CuryID != currencyinfo.CuryID) { PXCurrencyAttribute.CuryConvCury(sender, currencyinfo, ucItem.Cost, out unitCost); } if (UOM == null) { return(null); } if (ucItem.UOM != UOM) { decimal salesPriceInBase = INUnitAttribute.ConvertFromBase(sender, inventoryID, ucItem.UOM, unitCost, INPrecision.UNITCOST); unitCost = INUnitAttribute.ConvertToBase(sender, inventoryID, UOM, salesPriceInBase, INPrecision.UNITCOST); } if (unitCost == 0m && currentUnitCost != null && currentUnitCost != 0m) { return(currentUnitCost); } else { return(unitCost); } } if (currentUnitCost != null && currentUnitCost != 0m) { return(currentUnitCost); } else { return(null); } }
public decimal Convert <InventoryIDField, CuryInfoIDField>(PXGraph graph, object inventoryRow, object curyRow, string uom) where InventoryIDField : IBqlField where CuryInfoIDField : IBqlField { ItemCost price = this; if (price == null || price.Cost == 0 || price.Item == null || inventoryRow == null || curyRow == null) { return(0); } decimal result = price.Cost; if (ConvertCury) { PXCache curyCache = graph.Caches[curyRow.GetType()]; PXCurrencyAttribute.CuryConvCury <CuryInfoIDField>(curyCache, curyRow, price.BaseCost, out result, true); } if (price.UOM != uom && !string.IsNullOrEmpty(uom)) { if (inventoryRow == null) { return(0); } PXCache invCache = graph.Caches[inventoryRow.GetType()]; decimal baseUOM = price.UOM != price.Item.BaseUnit ? INUnitAttribute.ConvertFromBase <InventoryIDField>(invCache, inventoryRow, price.UOM, result, INPrecision.UNITCOST) : result; result = uom != price.Item.BaseUnit ? INUnitAttribute.ConvertToBase <InventoryIDField>(invCache, inventoryRow, uom, baseUOM, INPrecision.UNITCOST) : baseUOM; } return(result); }
/// <summary> /// Calculates Sales Price. /// </summary> /// <param name="sender">Cache</param> /// <param name="inventoryID">Inventory</param> /// <param name="curyID">Currency</param> /// <param name="UOM">Unit of measure</param> /// <param name="date">Date</param> /// <param name="alwaysFromBaseCurrency">If true sales price is always calculated (converted) from Base Currency.</param> /// <returns>Sales Price.</returns> public static decimal?CalculateSalesPrice(PXCache sender, string custPriceClass, int?customerID, int?inventoryID, CurrencyInfo currencyinfo, decimal?quantity, string UOM, DateTime date, bool alwaysFromBaseCurrency) { //InventoryItem item = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.Select(sender.Graph, inventoryID); SalesPriceItem spItem; try { spItem = FindSalesPrice(sender, custPriceClass, customerID, inventoryID, alwaysFromBaseCurrency ? currencyinfo.BaseCuryID : currencyinfo.CuryID, Math.Abs(quantity ?? 0m), UOM, date); } catch (PXUnitConversionException) { return(null); } if (spItem != null) { decimal salesPrice = spItem.Price; if (spItem.CuryID != currencyinfo.CuryID) { PXCurrencyAttribute.CuryConvCury(sender, currencyinfo, spItem.Price, out salesPrice); } if (UOM == null) { return(null); } if (spItem.UOM != UOM) { decimal salesPriceInBase = INUnitAttribute.ConvertFromBase(sender, inventoryID, spItem.UOM, salesPrice, INPrecision.UNITCOST); salesPrice = INUnitAttribute.ConvertToBase(sender, inventoryID, UOM, salesPriceInBase, INPrecision.UNITCOST); } return(salesPrice); } return(null); }
public static Decimal ConvertUOM(PXGraph graph, InventoryItem item, string uom, decimal cost, string destinationUOM) { if (item == null) { return(0); } if (destinationUOM == uom) { return(cost); } PXCache invCache = graph.Caches[typeof(InventoryItem)]; Decimal baseCost = uom != item.BaseUnit ? INUnitAttribute.ConvertFromBase <InventoryItem.inventoryCD>(invCache, item, uom, cost, INPrecision.UNITCOST) : cost; return (destinationUOM != item.BaseUnit ? INUnitAttribute.ConvertToBase <InventoryItem.inventoryCD>(invCache, item, destinationUOM, baseCost, INPrecision.UNITCOST) : baseCost); }
public static void AddUsage(PXCache cache, int?contractID, int?inventoryID, decimal used, string UOM) { if (contractID != null && inventoryID != null && used != 0) { decimal inTargetUnit = INUnitAttribute.ConvertToBase(cache, inventoryID, UOM, used, INPrecision.QUANTITY); //update all revisions starting from last active foreach (ContractDetailAcum item in PXSelectJoin <ContractDetailExt, InnerJoin <Contract, On <ContractDetailExt.contractID, Equal <Contract.contractID> >, InnerJoin <ContractItem, On <ContractItem.contractItemID, Equal <ContractDetailExt.contractItemID> >, InnerJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <ContractItem.recurringItemID> > > > >, Where <ContractDetailExt.contractID, Equal <Required <ContractDetailExt.contractID> >, And <ContractDetailExt.revID, GreaterEqual <Contract.lastActiveRevID>, And <ContractItem.recurringItemID, Equal <Required <ContractItem.recurringItemID> > > > > > .Select(cache.Graph, contractID, inventoryID) .RowCast <ContractDetailExt>() .Select(detail => PXCache <ContractDetailAcum> .Insert(cache.Graph, new ContractDetailAcum { ContractDetailID = detail.ContractDetailID }))) { item.Used += inTargetUnit; item.UsedTotal += inTargetUnit; } } }
public static UnitCostItem FindUnitCost(PXCache sender, int? vendorID, int? vendorLocationID, int? inventoryID, string baseCuryID, string curyID, decimal? quantity, string UOM, DateTime date) { PXSelectBase<APVendorPrice> unitCost = new PXSelect<APVendorPrice, Where<APVendorPrice.inventoryID, Equal<Required<APVendorPrice.inventoryID>>, And<APVendorPrice.vendorID, Equal<Required<APVendorPrice.vendorID>>, And<APVendorPrice.curyID, Equal<Required<APVendorPrice.curyID>>, And<APVendorPrice.uOM, Equal<Required<APVendorPrice.uOM>>, And<Where2<Where<APVendorPrice.breakQty, LessEqual<Required<APVendorPrice.breakQty>>>, And<Where2<Where<APVendorPrice.effectiveDate, LessEqual<Required<APVendorPrice.effectiveDate>>, And<APVendorPrice.expirationDate, GreaterEqual<Required<APVendorPrice.expirationDate>>>>, Or2<Where<APVendorPrice.effectiveDate, LessEqual<Required<APVendorPrice.effectiveDate>>, And<APVendorPrice.expirationDate, IsNull>>, Or<Where<APVendorPrice.expirationDate, GreaterEqual<Required<APVendorPrice.expirationDate>>, And<APVendorPrice.effectiveDate, IsNull, Or<APVendorPrice.effectiveDate, IsNull, And<APVendorPrice.expirationDate, IsNull>>>>>>>>>>>>>>, OrderBy<Desc<APVendorPrice.isPromotionalPrice, Desc<APVendorPrice.vendorID, Desc<APVendorPrice.breakQty>>>>>(sender.Graph); PXSelectBase<APVendorPrice> unitCostBaseUOM = new PXSelectJoin<APVendorPrice, InnerJoin<InventoryItem, On<InventoryItem.inventoryID, Equal<APVendorPrice.inventoryID>, And<InventoryItem.baseUnit, Equal<APVendorPrice.uOM>>>>, Where<APVendorPrice.inventoryID, Equal<Required<APVendorPrice.inventoryID>>, And<APVendorPrice.vendorID, Equal<Required<APVendorPrice.vendorID>>, And<APVendorPrice.curyID, Equal<Required<APVendorPrice.curyID>>, And<Where2<Where<APVendorPrice.breakQty, LessEqual<Required<APVendorPrice.breakQty>>>, And<Where2<Where<APVendorPrice.effectiveDate, LessEqual<Required<APVendorPrice.effectiveDate>>, And<APVendorPrice.expirationDate, GreaterEqual<Required<APVendorPrice.expirationDate>>>>, Or2<Where<APVendorPrice.effectiveDate, LessEqual<Required<APVendorPrice.effectiveDate>>, And<APVendorPrice.expirationDate, IsNull>>, Or<Where<APVendorPrice.expirationDate, GreaterEqual<Required<APVendorPrice.expirationDate>>, And<APVendorPrice.effectiveDate, IsNull, Or<APVendorPrice.effectiveDate, IsNull, And<APVendorPrice.expirationDate, IsNull>>>>>>>>>>>>>, OrderBy<Desc<APVendorPrice.isPromotionalPrice, Desc<APVendorPrice.vendorID, Desc<APVendorPrice.breakQty>>>>>(sender.Graph); APVendorPrice item = unitCost.SelectWindowed(0, 1, inventoryID, vendorID, curyID, UOM, quantity, date, date, date, date); string uomFound = null; if (item == null) { decimal baseUnitQty = INUnitAttribute.ConvertToBase(sender, inventoryID, UOM, (decimal)quantity, INPrecision.QUANTITY); item = unitCostBaseUOM.Select(inventoryID, vendorID, curyID, baseUnitQty, date, date, date, date); if (item == null) { /*InventoryItem inventoryItem = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.Select(sender.Graph, inventoryID); if (inventoryItem != null && inventoryItem.BasePrice != null) { return new UnitCostItem(inventoryItem.BaseUnit, (inventoryItem.BasePrice ?? 0m), baseCuryID); } else*/ return null; } else { uomFound = item.UOM; } } else { uomFound = UOM; } if (item == null) { return null; } return new UnitCostItem(uomFound, (item.SalesPrice ?? 0), item.CuryID); }
public static SalesPriceItem FindSalesPrice(PXCache sender, string custPriceClass, int?customerID, int?inventoryID, string curyID, decimal?quantity, string UOM, DateTime date) { PXSelectBase <ARSalesPrice> salesPrice = new PXSelect <ARSalesPrice, Where <ARSalesPrice.inventoryID, Equal <Required <ARSalesPrice.inventoryID> >, And2 <Where2 <Where <ARSalesPrice.priceType, Equal <Required <ARSalesPrice.priceType> >, And <ARSalesPrice.priceCode, Equal <Required <ARSalesPrice.priceCode> > > >, Or <Where <ARSalesPrice.priceType, Equal <Required <ARSalesPrice.priceType> >, And <ARSalesPrice.priceCode, Equal <Required <ARSalesPrice.priceCode> > > > > >, And <ARSalesPrice.curyID, Equal <Required <ARSalesPrice.curyID> >, And <ARSalesPrice.uOM, Equal <Required <ARSalesPrice.uOM> >, And <Where2 <Where <ARSalesPrice.breakQty, LessEqual <Required <ARSalesPrice.breakQty> > >, And <Where2 <Where <ARSalesPrice.effectiveDate, LessEqual <Required <ARSalesPrice.effectiveDate> >, And <ARSalesPrice.expirationDate, Greater <Required <ARSalesPrice.expirationDate> > > >, Or2 <Where <ARSalesPrice.effectiveDate, LessEqual <Required <ARSalesPrice.effectiveDate> >, And <ARSalesPrice.expirationDate, IsNull> >, Or <Where <ARSalesPrice.expirationDate, Greater <Required <ARSalesPrice.expirationDate> >, And <ARSalesPrice.effectiveDate, IsNull> > > > > > > > > > > >, OrderBy <Asc <ARSalesPrice.priceType, Desc <ARSalesPrice.isPromotionalPrice, Desc <ARSalesPrice.breakQty> > > > >(sender.Graph); PXSelectBase <ARSalesPrice> selectWithBaseUOM = new PXSelectJoin <ARSalesPrice, InnerJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <ARSalesPrice.inventoryID>, And <InventoryItem.baseUnit, Equal <ARSalesPrice.uOM> > > >, Where <ARSalesPrice.inventoryID, Equal <Required <ARSalesPrice.inventoryID> >, And2 <Where2 <Where <ARSalesPrice.priceType, Equal <Required <ARSalesPrice.priceType> >, And <ARSalesPrice.priceCode, Equal <Required <ARSalesPrice.priceCode> > > >, Or <Where <ARSalesPrice.priceType, Equal <Required <ARSalesPrice.priceType> >, And <ARSalesPrice.priceCode, Equal <Required <ARSalesPrice.priceCode> > > > > >, And <ARSalesPrice.curyID, Equal <Required <ARSalesPrice.curyID> >, And <ARSalesPrice.uOM, Equal <Required <ARSalesPrice.uOM> >, And <Where2 <Where <ARSalesPrice.breakQty, LessEqual <Required <ARSalesPrice.breakQty> > >, And <Where2 <Where <ARSalesPrice.effectiveDate, LessEqual <Required <ARSalesPrice.effectiveDate> >, And <ARSalesPrice.expirationDate, Greater <Required <ARSalesPrice.expirationDate> > > >, Or2 <Where <ARSalesPrice.effectiveDate, LessEqual <Required <ARSalesPrice.effectiveDate> >, And <ARSalesPrice.expirationDate, IsNull> >, Or <Where <ARSalesPrice.expirationDate, Greater <Required <ARSalesPrice.expirationDate> >, And <ARSalesPrice.effectiveDate, IsNull> > > > > > > > > > > >, OrderBy <Desc <ARSalesPrice.customerID, Desc <ARSalesPrice.isPromotionalPrice, Desc <ARSalesPrice.breakQty> > > > >(sender.Graph); ARSalesPrice item = salesPrice.SelectWindowed(0, 1, inventoryID, PriceTypes.Customer, PriceCodeInfo.CustomerPrefix + customerID, PriceTypes.CustomerPriceClass, PriceCodeInfo.CustomerPriceClassPrefix + custPriceClass, curyID, UOM, quantity, date, date, date, date); string uomFound = null; if (item == null) { decimal baseUnitQty = INUnitAttribute.ConvertToBase(sender, inventoryID, UOM, (decimal)quantity, INPrecision.QUANTITY); item = selectWithBaseUOM.Select(inventoryID, PriceTypes.Customer, PriceCodeInfo.CustomerPrefix + customerID, PriceTypes.CustomerPriceClass, PriceCodeInfo.CustomerPriceClassPrefix + custPriceClass, curyID, UOM, quantity, date, date, date, date); if (item == null) { item = salesPrice.SelectWindowed(0, 1, inventoryID, PriceTypes.Customer, PriceCodeInfo.CustomerPrefix + customerID, PriceTypes.CustomerPriceClass, PriceCodeInfo.CustomerPriceClassPrefix + AR.ARPriceClass.EmptyPriceClass, curyID, UOM, quantity, date, date, date, quantity, date); if (item == null) { item = selectWithBaseUOM.Select(inventoryID, PriceTypes.Customer, PriceCodeInfo.CustomerPrefix + customerID, PriceTypes.CustomerPriceClass, PriceCodeInfo.CustomerPriceClassPrefix + AR.ARPriceClass.EmptyPriceClass, curyID, UOM, quantity, date, date, date, quantity, date); if (item == null) { return(null); } else { uomFound = item.UOM; } } else { uomFound = UOM; } } else { uomFound = item.UOM; } } else { uomFound = UOM; } return(new SalesPriceItem(uomFound, (item.SalesPrice ?? 0), item.CuryID)); }
public virtual void UpdateCostAndPrice(List <DocLineExt> docLines) { if (docLines.Count == 0) { return; } FSServiceOrder fsServiceOrderRow = docLines[0].fsServiceOrder; FSSrvOrdType fsSrvOrdTypeRow = docLines[0].fsSrvOrdType; FSPostDoc fsPostDocRow = docLines[0].fsPostDoc; FSAppointment fsAppointmentRow = docLines[0].fsAppointment; if (fsSrvOrdTypeRow.BillingType != ID.SrvOrdType_BillingType.COST_AS_COST) { return; } PMTran pmTranRow; INTran inTranRow, inTranRowUpd; decimal curyUnitCost = 0m; List <PXResult <INTran> > inTranRowsList = null; DocLineExt docLineExtRow = docLines.Where(x => x.fsPostDoc.INDocLineRef != null).FirstOrDefault(); if (docLineExtRow != null && docLineExtRow.fsPostDoc != null && docLineExtRow.fsPostDoc.INDocLineRef != null) { inTranRow = (INTran)docLineExtRow.fsPostDoc.INDocLineRef; inTranRowsList = PXSelect <INTran, Where < INTran.docType, Equal <Required <INTran.docType> >, And < INTran.refNbr, Equal <Required <INTran.refNbr> > > > > .Select(new PXGraph(), inTranRow.DocType, inTranRow.RefNbr) .ToList(); } if (inTranRowsList.Count() > 0) { foreach (DocLineExt docLineExt in docLines) { pmTranRow = (PMTran)docLineExt.fsPostDoc.DocLineRef; inTranRow = (INTran)docLineExt.fsPostDoc.INDocLineRef; if (pmTranRow != null && inTranRow != null) { inTranRowUpd = inTranRowsList.RowCast <INTran>() .Where(x => x.DocType == inTranRow.DocType && x.RefNbr == inTranRow.RefNbr && x.LineNbr == inTranRow.LineNbr) .FirstOrDefault(); if (inTranRowUpd != null) { IPXCurrencyHelper currencyHelper = Base.FindImplementation <IPXCurrencyHelper>(); curyUnitCost = INUnitAttribute.ConvertToBase <PMTran.inventoryID, PMTran.uOM>(Base.Transactions.Cache, pmTranRow, (decimal)inTranRowUpd.UnitCost, INPrecision.NOROUND); if (currencyHelper != null) { currencyHelper.CuryConvCury((decimal)(inTranRowUpd.UnitCost), out curyUnitCost); } else { CM.PXDBCurrencyAttribute.CuryConvCury(Base.Transactions.Cache, Base.BaseCuryInfo.Current, curyUnitCost, out curyUnitCost, true); } pmTranRow.TranCuryUnitRate = Math.Round(curyUnitCost, CommonSetupDecPl.PrcCst, MidpointRounding.AwayFromZero); Base.Transactions.Update(pmTranRow); } } } } }
protected virtual void SOSalesPrice_RowPersisting(PXCache sender, PXRowPersistingEventArgs e) { SOSalesPrice row = (SOSalesPrice)e.Row; #region Validations if (row.PendingPrice != null && row.EffectiveDate == null) { if (sender.RaiseExceptionHandling <SOSalesPrice.effectiveDate>(e.Row, null, new PXSetPropertyException(ErrorMessages.FieldIsEmpty))) { throw new PXRowPersistingException(typeof(SOSalesPrice.effectiveDate).Name, null, ErrorMessages.FieldIsEmpty); } } #endregion if (IsBaseCurrency) { InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <SOSalesPrice.inventoryID> > > > .Select(this, row.InventoryID); if (sender.GetStatus(e.Row) == PXEntryStatus.Inserted || sender.GetStatus(e.Row) == PXEntryStatus.Updated) { if (Setup.Current.SalesPriceUpdateUnit == SalesPriceUpdateUnitType.BaseUnit) { if (row.UOM == item.BaseUnit) { List <PXDataFieldParam> updatedFields = new List <PXDataFieldParam>(); updatedFields.Add(new PXDataFieldAssign("LastBasePrice", PXDbType.DirectExpression, "=BasePrice")); updatedFields.Add(new PXDataFieldAssign("BasePrice", PXDbType.Decimal, row.SalesPrice)); if (row.PendingPrice != null) { updatedFields.Add(new PXDataFieldAssign("PendingBasePrice", PXDbType.Decimal, row.PendingPrice)); updatedFields.Add(new PXDataFieldAssign("PendingBasePriceDate", PXDbType.DateTime, row.EffectiveDate)); } updatedFields.Add(new PXDataFieldRestrict("InventoryID", PXDbType.Int, item.InventoryID)); PXDatabase.Update <InventoryItem>(updatedFields.ToArray()); } } else { if (row.UOM == item.SalesUnit) { List <PXDataFieldParam> updatedFields = new List <PXDataFieldParam>(); updatedFields.Add(new PXDataFieldAssign("LastBasePrice", PXDbType.DirectExpression, "=BasePrice")); decimal basePrice = INUnitAttribute.ConvertToBase(sender, item.InventoryID, row.UOM, row.SalesPrice.Value, INPrecision.UNITCOST); updatedFields.Add(new PXDataFieldAssign("BasePrice", PXDbType.Decimal, basePrice)); if (row.PendingPrice != null) { decimal pendingBasePrice = INUnitAttribute.ConvertToBase(sender, item.InventoryID, row.UOM, row.PendingPrice.Value, INPrecision.UNITCOST); updatedFields.Add(new PXDataFieldAssign("PendingBasePrice", PXDbType.Decimal, pendingBasePrice)); updatedFields.Add(new PXDataFieldAssign("PendingBasePriceDate", PXDbType.DateTime, row.EffectiveDate)); } updatedFields.Add(new PXDataFieldRestrict("InventoryID", PXDbType.Int, item.InventoryID)); PXDatabase.Update <InventoryItem>(updatedFields.ToArray()); } } } } }
protected virtual void DefaultUnitCost(PXCache sender, PXFieldUpdatedEventArgs e) { if (adjustment.Current != null && adjustment.Current.OrigModule == INRegister.origModule.PI) { return; } object UnitCost = null; InventoryItem item = (InventoryItem)PXSelectorAttribute.Select <INTran.inventoryID>(sender, e.Row); if (item.ValMethod == INValMethod.Specific && string.IsNullOrEmpty(((INTran)e.Row).LotSerialNbr) == false) { INCostStatus status = PXSelectJoin <INCostStatus, LeftJoin <INLocation, On <INLocation.locationID, Equal <Current <INTran.locationID> > >, InnerJoin <INCostSubItemXRef, On <INCostSubItemXRef.costSubItemID, Equal <INCostStatus.costSubItemID> > > >, Where <INCostStatus.inventoryID, Equal <Current <INTran.inventoryID> >, And2 <Where <INLocation.isCosted, Equal <boolFalse>, And <INCostStatus.costSiteID, Equal <Current <INTran.siteID> >, Or <INCostStatus.costSiteID, Equal <Current <INTran.locationID> > > > >, And <INCostSubItemXRef.subItemID, Equal <Current <INTran.subItemID> >, And <INCostStatus.lotSerialNbr, Equal <Current <INTran.lotSerialNbr> > > > > > > .SelectSingleBound(this, new object[] { e.Row }); if (status != null && status.QtyOnHand != 0m) { UnitCost = PXDBPriceCostAttribute.Round((decimal)(status.TotalCost / status.QtyOnHand)); } } else if (item.ValMethod == INValMethod.FIFO && string.IsNullOrEmpty(((INTran)e.Row).OrigRefNbr) == false) { INCostStatus status = PXSelectJoin <INCostStatus, LeftJoin <INLocation, On <INLocation.locationID, Equal <Current <INTran.locationID> > >, InnerJoin <INCostSubItemXRef, On <INCostSubItemXRef.costSubItemID, Equal <INCostStatus.costSubItemID> > > >, Where <INCostStatus.inventoryID, Equal <Current <INTran.inventoryID> >, And2 <Where <INLocation.isCosted, Equal <boolFalse>, And <INCostStatus.costSiteID, Equal <Current <INTran.siteID> >, Or <INCostStatus.costSiteID, Equal <Current <INTran.locationID> > > > >, And <INCostSubItemXRef.subItemID, Equal <Current <INTran.subItemID> >, And <INCostStatus.receiptNbr, Equal <Current <INTran.origRefNbr> > > > > > > .SelectSingleBound(this, new object[] { e.Row }); if (status != null && status.QtyOnHand != 0m) { UnitCost = PXDBPriceCostAttribute.Round((decimal)(status.TotalCost / status.QtyOnHand)); } } else { if (item.ValMethod == INValMethod.Average) { sender.RaiseFieldDefaulting <INTran.avgCost>(e.Row, out UnitCost); } if (UnitCost == null || (decimal)UnitCost == 0m) { sender.RaiseFieldDefaulting <INTran.unitCost>(e.Row, out UnitCost); } } decimal?qty = (decimal?)sender.GetValue <INTran.qty>(e.Row); if (UnitCost != null && ((decimal)UnitCost != 0m || qty < 0m)) { if ((decimal)UnitCost < 0m) { sender.RaiseFieldDefaulting <INTran.unitCost>(e.Row, out UnitCost); } decimal?unitcost = INUnitAttribute.ConvertToBase <INTran.inventoryID>(sender, e.Row, ((INTran)e.Row).UOM, (decimal)UnitCost, INPrecision.UNITCOST); //suppress trancost recalculation for cost only adjustments if (qty == 0m) { sender.SetValue <INTran.unitCost>(e.Row, unitcost); } else { sender.SetValueExt <INTran.unitCost>(e.Row, unitcost); } } }
/// <summary> /// Returns true if for the Customer and/or Customer Price Class there is a price defined for the item. /// </summary> private static string CheckPriceByPriceType(PXCache cache, string custPriceClass, int?customerID, int?inventoryID, string baseCuryID, string curyID, decimal?quantity, string uom, DateTime date, string type, ref string errorCode) { // These BQLs are necessary to evaluate if the item has a price defined for a Customer o Customer Price Class specified PXSelectBase <ARSalesPrice> salesPrice = new PXSelect <ARSalesPrice, Where < ARSalesPrice.inventoryID, Equal <Required <ARSalesPrice.inventoryID> >, And2 < Where2 < Where < ARSalesPrice.priceType, Equal <PriceTypes.customer>, And <ARSalesPrice.customerID, Equal <Required <ARSalesPrice.customerID> >, And <Required <ARSalesPrice.custPriceClassID>, IsNull> > >, Or2 < Where < ARSalesPrice.priceType, Equal <PriceTypes.customerPriceClass>, And <ARSalesPrice.custPriceClassID, Equal <Required <ARSalesPrice.custPriceClassID> >, And <Required <ARSalesPrice.customerID>, IsNull> > >, Or < Where < ARSalesPrice.priceType, Equal <PriceTypes.basePrice>, And <Required <ARSalesPrice.customerID>, IsNull, And <Required <ARSalesPrice.custPriceClassID>, IsNull> > > > > >, And <ARSalesPrice.curyID, Equal <Required <ARSalesPrice.curyID> >, And < Where2 < Where < ARSalesPrice.breakQty, LessEqual <Required <ARSalesPrice.breakQty> > >, And < Where2 < Where < ARSalesPrice.effectiveDate, LessEqual <Required <ARSalesPrice.effectiveDate> >, And <ARSalesPrice.expirationDate, GreaterEqual <Required <ARSalesPrice.expirationDate> > > >, Or2 < Where < ARSalesPrice.effectiveDate, LessEqual <Required <ARSalesPrice.effectiveDate> >, And <ARSalesPrice.expirationDate, IsNull> >, Or < Where < ARSalesPrice.expirationDate, GreaterEqual <Required <ARSalesPrice.expirationDate> >, And <ARSalesPrice.effectiveDate, IsNull, Or <ARSalesPrice.effectiveDate, IsNull, And <ARSalesPrice.expirationDate, IsNull> > > > > > > > > > > > >, OrderBy < Asc <ARSalesPrice.priceType, Desc <ARSalesPrice.isPromotionalPrice, Desc <ARSalesPrice.breakQty> > > > >(cache.Graph); PXSelectBase <ARSalesPrice> selectWithBaseUOM = new PXSelectJoin <ARSalesPrice, InnerJoin <InventoryItem, On < InventoryItem.inventoryID, Equal <ARSalesPrice.inventoryID>, And <InventoryItem.baseUnit, Equal <ARSalesPrice.uOM> > > >, Where < ARSalesPrice.inventoryID, Equal <Required <ARSalesPrice.inventoryID> >, And2 < Where2 < Where < ARSalesPrice.priceType, Equal <PriceTypes.customer>, And <ARSalesPrice.customerID, Equal <Required <ARSalesPrice.customerID> >, And <Required <ARSalesPrice.custPriceClassID>, IsNull> > >, Or2 < Where < ARSalesPrice.priceType, Equal <PriceTypes.customerPriceClass>, And <ARSalesPrice.custPriceClassID, Equal <Required <ARSalesPrice.custPriceClassID> >, And <Required <ARSalesPrice.customerID>, IsNull> > >, Or < Where < ARSalesPrice.priceType, Equal <PriceTypes.basePrice>, And <Required <ARSalesPrice.customerID>, IsNull, And <Required <ARSalesPrice.custPriceClassID>, IsNull> > > > > >, And < ARSalesPrice.curyID, Equal <Required <ARSalesPrice.curyID> >, And < Where2 < Where < ARSalesPrice.breakQty, LessEqual <Required <ARSalesPrice.breakQty> > >, And < Where2 < Where < ARSalesPrice.effectiveDate, LessEqual <Required <ARSalesPrice.effectiveDate> >, And <ARSalesPrice.expirationDate, GreaterEqual <Required <ARSalesPrice.expirationDate> > > >, Or2 < Where < ARSalesPrice.effectiveDate, LessEqual <Required <ARSalesPrice.effectiveDate> >, And <ARSalesPrice.expirationDate, IsNull> >, Or < Where < ARSalesPrice.expirationDate, GreaterEqual <Required <ARSalesPrice.expirationDate> >, And <ARSalesPrice.effectiveDate, IsNull, Or <ARSalesPrice.effectiveDate, IsNull, And <ARSalesPrice.expirationDate, IsNull> > > > > > > > > > > > >, OrderBy < Asc <ARSalesPrice.priceType, Desc <ARSalesPrice.isPromotionalPrice, Desc <ARSalesPrice.breakQty> > > > >(cache.Graph); string priceType = null; ARSalesPrice item; switch (type) { case ID.PriceType.CUSTOMER: item = salesPrice.SelectWindowed(0, 1, inventoryID, customerID, null, custPriceClass, customerID, customerID, custPriceClass, curyID, quantity, date, date, date, date); errorCode = CheckInventoryItemUOM(cache, item, inventoryID, uom); if (item == null && errorCode == ID.PriceErrorCode.OK) { decimal baseUnitQty = INUnitAttribute.ConvertToBase(cache, inventoryID, uom, (decimal)quantity, INPrecision.QUANTITY); item = selectWithBaseUOM.Select(inventoryID, customerID, null, custPriceClass, customerID, customerID, custPriceClass, curyID, baseUnitQty, date, date, date, date); } if (item != null && errorCode == ID.PriceErrorCode.OK) { priceType = ID.PriceType.CUSTOMER; } break; case ID.PriceType.PRICE_CLASS: item = salesPrice.SelectWindowed(0, 1, inventoryID, customerID, custPriceClass, custPriceClass, null, customerID, custPriceClass, curyID, quantity, date, date, date, date); errorCode = CheckInventoryItemUOM(cache, item, inventoryID, uom); if (item == null && errorCode == ID.PriceErrorCode.OK) { decimal baseUnitQty = INUnitAttribute.ConvertToBase(cache, inventoryID, uom, (decimal)quantity, INPrecision.QUANTITY); item = selectWithBaseUOM.Select(inventoryID, customerID, custPriceClass, custPriceClass, null, customerID, custPriceClass, curyID, baseUnitQty, date, date, date, date); } if (item != null && errorCode == ID.PriceErrorCode.OK) { priceType = ID.PriceType.PRICE_CLASS; } break; default: item = salesPrice.SelectWindowed(0, 1, inventoryID, customerID, custPriceClass, custPriceClass, customerID, null, null, curyID, quantity, date, date, date, date); errorCode = CheckInventoryItemUOM(cache, item, inventoryID, uom); if (item == null) { decimal baseUnitQty = INUnitAttribute.ConvertToBase(cache, inventoryID, uom, (decimal)quantity, INPrecision.QUANTITY); item = selectWithBaseUOM.Select(inventoryID, customerID, custPriceClass, custPriceClass, customerID, null, null, curyID, baseUnitQty, date, date, date, date); if (item == null) { priceType = ID.PriceType.DEFAULT; } } if (item != null && errorCode == ID.PriceErrorCode.OK) { priceType = ID.PriceType.BASE; } break; } return(priceType); }