예제 #1
0
        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));
        }
        protected virtual decimal ConvertValue(decimal value, string from, string to)
        {
            if (from == to)
            {
                return(value);
            }

            bool   reverse = false;
            INUnit unit    = INUnit.UK.ByGlobal.Find(Base, from, to);

            if (unit == null)
            {
                unit    = INUnit.UK.ByGlobal.Find(Base, to, from);
                reverse = true;
            }

            if (unit == null)
            {
                throw new PXException(IN.Messages.ConversionNotFound, from, to);
            }

            decimal result = INUnitAttribute.ConvertValue(value, unit, INPrecision.NOROUND, reverse);

            return(decimal.Round(result, 6, MidpointRounding.AwayFromZero));
        }
        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;
        }
예제 #4
0
        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;
                }
            }
        }
        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;
            }
        }
예제 #6
0
        /// <summary>
        /// Verifies whether or not the system can convert the InventoryItem's <c>UOM</c> to the one defined in the Sales Price screen.
        /// If <c>arSalesPriceRow != null</c> means that the price from Sale Price applies.
        /// If <c>arSalesPriceRow.UOM != uom</c> means that the <c>UOM</c> conversion applies.
        /// </summary>
        /// <param name="cache">PXCache instance.</param>
        /// <param name="arSalesPriceRow"><c>ARSalesPrice</c> instance.</param>
        /// <param name="inventoryID">Inventory Item ID.</param>
        /// <param name="uom">Unit of measure required.</param>
        /// <returns>Returns an errorCode status.</returns>
        private static string CheckInventoryItemUOM(PXCache cache, ARSalesPrice arSalesPriceRow, int?inventoryID, string uom)
        {
            string errorCode = ID.PriceErrorCode.OK;

            if (arSalesPriceRow != null && arSalesPriceRow.UOM != uom)
            {
                try
                {
                    decimal value      = 0m;
                    decimal salesprice = INUnitAttribute.ConvertFromBase(cache, inventoryID, arSalesPriceRow.UOM, value, INPrecision.NOROUND);
                }
                catch (PXException e)
                {
                    //The error code that can be thrown by ConvertFromBase routine is PX.Objects.IN.Messages.MissingUnitConversion, though,
                    //the error message is captured in case it does not match it for unknown reasons.
                    errorCode = e.Message;

                    //At this point it's ensured that e.Message corresponds to MissingUnitConversion,
                    //changing the errorCode value to a more explanatory message.
                    if (e.Message.IndexOf(PX.Objects.IN.Messages.MissingUnitConversion) != -1)
                    {
                        errorCode = ID.PriceErrorCode.UOM_INCONSISTENCY;
                    }
                }
            }

            return(errorCode);
        }
예제 #7
0
        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;
                }
            }
        }
예제 #8
0
 public decimal GetQuantityInBaseUOMs(ARTran tran)
 {
     return(INUnitAttribute.ConvertToBase(
                this.Caches[typeof(ARTran)],
                tran.InventoryID,
                tran.UOM,
                (tran.Qty ?? 0),
                INPrecision.QUANTITY));
 }
예제 #9
0
        public virtual void INTran_ReceiptedQty_FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
        {
            INTran row = (INTran)e.Row;

            if (row == null)
            {
                return;
            }
            e.ReturnValue = INUnitAttribute.ConvertFromBase <INTran.inventoryID, INTran.uOM>(sender, e.Row, row.ReceiptedBaseQty.GetValueOrDefault(), 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);
        }
예제 #11
0
        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);
            }
        }
 private static void ConvertUOM(PXCache cache, int?inventoryID, string sourceUom, string destinationUom, bool viceVersa, ref decimal cost)
 {
     if (sourceUom != destinationUom && cost != 0)
     {
         INUnit conversion = INUnit.UK.ByInventory.FindDirty(cache.Graph, inventoryID, viceVersa ? sourceUom : destinationUom);
         if (conversion == null)
         {
             throw new PXUnitConversionException();
         }
         cost = INUnitAttribute.Convert(cache, conversion, cost, INPrecision.UNITCOST, viceVersa);
     }
 }
예제 #13
0
        public virtual void UpdateBasePrice(PX.Objects.IN.INUpdateBasePrice.UpdateBasePriceRecord item)
        {
            using (PXConnectionScope cs = new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    DateTime updateTime     = DateTime.Now;
                    string   uom            = item.BaseUnit;
                    decimal? salesPrice     = item.PendingBasePrice;
                    decimal? lastSalesPrice = item.BasePrice;

                    //So that UI reflects the change:
                    item.BasePrice            = item.PendingBasePrice;
                    item.BasePriceDate        = item.PendingBasePriceDate;
                    item.PendingBasePrice     = 0;
                    item.PendingBasePriceDate = null;

                    PXDatabase.Update <InventoryItem>(
                        new PXDataFieldAssign("BasePrice", PXDbType.DirectExpression, "PendingBasePrice"),
                        new PXDataFieldAssign("BasePriceDate", PXDbType.DirectExpression, "PendingBasePriceDate"),
                        new PXDataFieldAssign("PendingBasePrice", PXDbType.Decimal, 0m),
                        new PXDataFieldAssign("PendingBasePriceDate", PXDbType.DateTime, null),
                        new PXDataFieldAssign("LastBasePrice", PXDbType.DirectExpression, "BasePrice"),
                        new PXDataFieldAssign("LastModifiedDateTime", PXDbType.DateTime, updateTime),
                        new PXDataFieldRestrict("InventoryID", PXDbType.Int, item.InventoryID)
                        );

                    if (SalesPriceUpdateUnit == SalesPriceUpdateUnitType.SalesUnit)
                    {
                        uom            = item.SalesUnit;
                        salesPrice     = INUnitAttribute.ConvertFromBase(this.Caches[typeof(PX.Objects.IN.INUpdateBasePrice.UpdateBasePriceRecord)], item.InventoryID, item.SalesUnit, item.PendingBasePrice.Value, INPrecision.UNITCOST);
                        lastSalesPrice = INUnitAttribute.ConvertFromBase(this.Caches[typeof(PX.Objects.IN.INUpdateBasePrice.UpdateBasePriceRecord)], item.InventoryID, item.SalesUnit, item.BasePrice.Value, INPrecision.UNITCOST);
                    }

                    PXDatabase.Update <ARSalesPrice>(
                        new PXDataFieldAssign("SalesPrice", PXDbType.Decimal, salesPrice),
                        new PXDataFieldAssign("LastDate", PXDbType.DirectExpression, "EffectiveDate"),
                        new PXDataFieldAssign("PendingPrice", PXDbType.Decimal, 0m),
                        new PXDataFieldAssign("EffectiveDate", PXDbType.DateTime, null),
                        new PXDataFieldAssign("LastPrice", PXDbType.Decimal, lastSalesPrice),
                        new PXDataFieldAssign("LastModifiedDateTime", PXDbType.DateTime, updateTime),
                        new PXDataFieldRestrict("InventoryID", PXDbType.Int, item.InventoryID),
                        new PXDataFieldRestrict("CustPriceClassID", PXDbType.VarChar, AR.ARPriceClass.EmptyPriceClass),
                        new PXDataFieldRestrict("CuryID", PXDbType.VarChar, Company.Current.BaseCuryID),
                        new PXDataFieldRestrict("UOM", PXDbType.VarChar, uom)
                        );


                    ts.Complete();
                }
            }
        }
예제 #14
0
        /// <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 override void Persist()
        {
            foreach (INTran tran in transactions.Select())
            {
                INTran trtran = PXSelect <INTran, Where <INTran.tranType, Equal <Current <INTran.origTranType> >,
                                                         And <INTran.refNbr, Equal <Current <INTran.origRefNbr> >,
                                                              And <INTran.lineNbr, Equal <Current <INTran.origLineNbr> >,
                                                                   And <INTran.tranType, Equal <INTranType.transfer> > > > > > .SelectSingleBound(this, new object[] { tran });

                if (receipt.Current.Hold != true && trtran != null && trtran.BaseQty != tran.BaseQty)
                {
                    decimal qty  = INUnitAttribute.ConvertFromBase(transactions.Cache, tran.InventoryID, tran.UOM, trtran.BaseQty ?? 0m, INPrecision.QUANTITY);
                    INTran  copy = (INTran)transactions.Cache.CreateCopy(tran);
                    transactions.Update(copy);
                    transactions.Cache.RaiseExceptionHandling <INTran.qty>(tran, tran.Qty, new PXSetPropertyException(CS.Messages.Entry_EQ, qty));
                }
            }

            base.Persist();
        }
            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);
        }
예제 #18
0
        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);
        }
예제 #19
0
        private static void UpdateSchedulesFromCompletedPO(PXGraph graph, PXSelect <FSSODetSplit> fsSODetSplit, PXSelect <INItemPlan> initemplan, FSSODetSplit parentschedule, PXSelect <FSServiceOrder> fsServiceOrder, INItemPlan demand)
        {
            graph.FieldDefaulting.AddHandler <FSSODetSplit.locationID>((sender, e) =>
            {
                if (e.Row != null && ((FSSODetSplit)e.Row).RequireLocation != true)
                {
                    e.NewValue = null;
                    e.Cancel   = true;
                }
            });

            FSSODetSplit newschedule = PXCache <FSSODetSplit> .CreateCopy(parentschedule);

            ClearScheduleReferences(ref newschedule);

            newschedule.LotSerialNbr = demand.LotSerialNbr;
            newschedule.SiteID       = demand.SiteID;

            newschedule.BaseQty         = parentschedule.BaseQty - parentschedule.BaseReceivedQty;
            newschedule.Qty             = INUnitAttribute.ConvertFromBase(fsSODetSplit.Cache, newschedule.InventoryID, newschedule.UOM, (decimal)newschedule.BaseQty, INPrecision.QUANTITY);
            newschedule.BaseReceivedQty = 0m;
            newschedule.ReceivedQty     = 0m;

            //creating new plan
            INItemPlan newPlan = PXCache <INItemPlan> .CreateCopy(demand);

            newPlan.PlanID           = null;
            newPlan.SupplyPlanID     = null;
            newPlan.DemandPlanID     = null;
            newPlan.PlanQty          = newschedule.BaseQty;
            newPlan.VendorID         = null;
            newPlan.VendorLocationID = null;
            newPlan.FixedSource      = INReplenishmentSource.None;
            newPlan.PlanType         = (fsServiceOrder.Current != null && fsServiceOrder.Current.Hold == true) ? INPlanConstants.Plan69 : INPlanConstants.Plan60;
            newPlan = (INItemPlan)initemplan.Cache.Insert(newPlan);

            newschedule.PlanID = newPlan.PlanID;
            fsSODetSplit.Cache.Insert(newschedule);
        }
예제 #20
0
        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;
                }
            }
        }
        protected virtual void SOSalesPrice_LastPrice_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
        {
            SOSalesPrice row = e.Row as SOSalesPrice;

            if (row != null)
            {
                InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <SOSalesPrice.inventoryID> > > > .Select(this, row.InventoryID);

                if (item != null)
                {
                    if (IsBaseCurrency)
                    {
                        if (row.UOM == item.BaseUnit)
                        {
                            e.NewValue = item.LastBasePrice;
                        }
                        else
                        {
                            e.NewValue = INUnitAttribute.ConvertFromBase(sender, item.InventoryID, item.SalesUnit, item.LastBasePrice.Value, INPrecision.UNITCOST);
                        }
                    }
                }
            }
        }
예제 #22
0
        public List <PXResult <INItemPlan, INPlanType> > ProcessPOReceipt(PXGraph graph, IEnumerable <PXResult <INItemPlan, INPlanType> > list, string POReceiptType, string POReceiptNbr)
        {
            var serviceOrder = new PXSelect <FSServiceOrder>(graph);

            if (!graph.Views.Caches.Contains(typeof(FSServiceOrder)))
            {
                graph.Views.Caches.Add(typeof(FSServiceOrder));
            }
            var soDetSplit = new PXSelect <FSSODetSplit>(graph);

            if (!graph.Views.Caches.Contains(typeof(FSSODetSplit)))
            {
                graph.Views.Caches.Add(typeof(FSSODetSplit));
            }
            var initemplan = new PXSelect <INItemPlan>(graph);

            List <PXResult <INItemPlan, INPlanType> > returnList = new List <PXResult <INItemPlan, INPlanType> >();

            Base.FieldVerifying.AddHandler <FSSODetSplit.lotSerialNbr>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });

            List <FSSODetSplit> splitsToDeletePlanID = new List <FSSODetSplit>();

            List <FSSODetSplit> insertedSchedules = new List <FSSODetSplit>();
            List <INItemPlan>   deletedPlans      = new List <INItemPlan>();



            foreach (PXResult <INItemPlan, INPlanType> res in list)
            {
                bool       includeInReturnList = true;
                INItemPlan plan = PXCache <INItemPlan> .CreateCopy(res);

                INPlanType plantype = res;

                //avoid ReadItem()
                if (initemplan.Cache.GetStatus(plan) != PXEntryStatus.Inserted)
                {
                    initemplan.Cache.SetStatus(plan, PXEntryStatus.Notchanged);
                }

                //Original Schedule Marked for PO / Allocated on Remote Whse
                //FSSODetSplit schedule = PXSelect<FSSODetSplit, Where<FSSODetSplit.planID, Equal<Required<FSSODetSplit.planID>>, And<FSSODetSplit.completed, Equal<False>>>>.Select(this, plan.DemandPlanID);
                FSSODetSplit schedule = PXSelect <FSSODetSplit, Where <FSSODetSplit.planID, Equal <Required <FSSODetSplit.planID> > > > .Select(graph, plan.DemandPlanID);

                if (schedule != null && (schedule.Completed == false || soDetSplit.Cache.GetStatus(schedule) == PXEntryStatus.Updated))
                {
                    includeInReturnList = false;
                    schedule            = PXCache <FSSODetSplit> .CreateCopy(schedule);

                    schedule.BaseReceivedQty += plan.PlanQty;
                    schedule.ReceivedQty      = INUnitAttribute.ConvertFromBase(soDetSplit.Cache, schedule.InventoryID, schedule.UOM, (decimal)schedule.BaseReceivedQty, INPrecision.QUANTITY);

                    soDetSplit.Cache.Update(schedule);

                    INItemPlan origplan = PXSelect <INItemPlan, Where <INItemPlan.planID, Equal <Required <INItemPlan.planID> > > > .Select(graph, plan.DemandPlanID);

                    if (origplan != null)
                    {
                        origplan.PlanQty = schedule.BaseQty - schedule.BaseReceivedQty;
                        initemplan.Cache.Update(origplan);
                    }

                    //select Allocated line if any, exclude allocated on Remote Whse
                    PXSelectBase <INItemPlan> cmd = new PXSelectJoin <INItemPlan, InnerJoin <FSSODetSplit, On <FSSODetSplit.planID, Equal <INItemPlan.planID> > >, Where <INItemPlan.demandPlanID, Equal <Required <INItemPlan.demandPlanID> >, And <FSSODetSplit.isAllocated, Equal <True>, And <FSSODetSplit.siteID, Equal <Required <FSSODetSplit.siteID> > > > > >(graph);
                    if (!string.IsNullOrEmpty(plan.LotSerialNbr))
                    {
                        cmd.WhereAnd <Where <INItemPlan.lotSerialNbr, Equal <Required <INItemPlan.lotSerialNbr> > > >();
                    }
                    PXResult <INItemPlan> allocres = cmd.Select(plan.DemandPlanID, plan.SiteID, plan.LotSerialNbr);

                    if (allocres != null)
                    {
                        schedule = PXResult.Unwrap <FSSODetSplit>(allocres);
                        soDetSplit.Cache.SetStatus(schedule, PXEntryStatus.Notchanged);
                        schedule = PXCache <FSSODetSplit> .CreateCopy(schedule);

                        schedule.BaseQty      += plan.PlanQty;
                        schedule.Qty           = INUnitAttribute.ConvertFromBase(soDetSplit.Cache, schedule.InventoryID, schedule.UOM, (decimal)schedule.BaseQty, INPrecision.QUANTITY);
                        schedule.POReceiptType = POReceiptType;
                        schedule.POReceiptNbr  = POReceiptNbr;

                        soDetSplit.Cache.Update(schedule);

                        INItemPlan allocplan = PXCache <INItemPlan> .CreateCopy(res);

                        allocplan.PlanQty += plan.PlanQty;

                        initemplan.Cache.Update(allocplan);

                        plantype = PXCache <INPlanType> .CreateCopy(plantype);

                        plantype.ReplanOnEvent = null;
                        plantype.DeleteOnEvent = true;
                    }
                    else
                    {
                        serviceOrder.Current = (FSServiceOrder)PXParentAttribute.SelectParent(soDetSplit.Cache, schedule, typeof(FSServiceOrder));
                        schedule             = PXCache <FSSODetSplit> .CreateCopy(schedule);

                        long?oldPlanID = schedule.PlanID;
                        ClearScheduleReferences(ref schedule);

                        plantype.ReplanOnEvent = INPlanConstants.PlanF1;
                        schedule.IsAllocated   = false;
                        schedule.LotSerialNbr  = plan.LotSerialNbr;
                        schedule.POCreate      = false;
                        schedule.POSource      = null;
                        schedule.POReceiptType = POReceiptType;
                        schedule.POReceiptNbr  = POReceiptNbr;
                        schedule.SiteID        = plan.SiteID;
                        schedule.VendorID      = null;

                        schedule.BaseReceivedQty = 0m;
                        schedule.ReceivedQty     = 0m;
                        schedule.BaseQty         = plan.PlanQty;
                        schedule.Qty             = INUnitAttribute.ConvertFromBase(soDetSplit.Cache, schedule.InventoryID, schedule.UOM, (decimal)schedule.BaseQty, INPrecision.QUANTITY);

                        //update SupplyPlanID in existing item plans (replenishment)
                        foreach (PXResult <INItemPlan> demand_res in PXSelect <INItemPlan,
                                                                               Where <INItemPlan.supplyPlanID, Equal <Required <INItemPlan.supplyPlanID> > > > .Select(graph, oldPlanID))
                        {
                            INItemPlan demand_plan = PXCache <INItemPlan> .CreateCopy(demand_res);

                            initemplan.Cache.SetStatus(demand_plan, PXEntryStatus.Notchanged);
                            demand_plan.SupplyPlanID = plan.PlanID;
                            initemplan.Cache.Update(demand_plan);
                        }

                        schedule.PlanID = plan.PlanID;

                        schedule = (FSSODetSplit)soDetSplit.Cache.Insert(schedule);
                        insertedSchedules.Add(schedule);
                    }
                }
                else if (plan.DemandPlanID == null)
                {
                    //Original schedule Marked for PO
                    //TODO: verify this is sufficient for Original SO marked for TR.
                    schedule = PXSelect <FSSODetSplit, Where <FSSODetSplit.planID, Equal <Required <FSSODetSplit.planID> >, And <FSSODetSplit.completed, Equal <False> > > > .Select(graph, plan.PlanID);

                    if (schedule != null)
                    {
                        includeInReturnList = false;
                        soDetSplit.Cache.SetStatus(schedule, PXEntryStatus.Notchanged);
                        schedule = PXCache <FSSODetSplit> .CreateCopy(schedule);

                        schedule.Completed   = true;
                        schedule.POCompleted = true;
                        splitsToDeletePlanID.Add(schedule);
                        soDetSplit.Cache.Update(schedule);

                        INItemPlan origplan = PXSelect <INItemPlan, Where <INItemPlan.planID, Equal <Required <INItemPlan.planID> > > > .Select(graph, plan.PlanID);

                        deletedPlans.Add(origplan);

                        initemplan.Cache.Delete(origplan);
                    }
                }

                if (includeInReturnList == true)
                {
                    returnList.Add(res);
                }
                else
                {
                    if (plantype.ReplanOnEvent != null)
                    {
                        plan.PlanType     = plantype.ReplanOnEvent;
                        plan.SupplyPlanID = null;
                        plan.DemandPlanID = null;
                        initemplan.Cache.Update(plan);
                    }
                    else if (plantype.DeleteOnEvent == true)
                    {
                        initemplan.Delete(plan);
                    }
                }
            }

            //Create new schedules for partially received schedules marked for PO.
            FSSODetSplit prevSplit = null;

            foreach (FSSODetSplit newsplit in insertedSchedules)
            {
                if (prevSplit != null && prevSplit.SrvOrdType == newsplit.SrvOrdType && prevSplit.RefNbr == newsplit.RefNbr &&
                    prevSplit.LineNbr == newsplit.LineNbr && prevSplit.InventoryID == newsplit.InventoryID &&
                    prevSplit.SubItemID == newsplit.SubItemID && prevSplit.ParentSplitLineNbr == newsplit.ParentSplitLineNbr &&
                    prevSplit.LotSerialNbr != null && newsplit.LotSerialNbr != null)
                {
                    continue;
                }

                FSSODetSplit parentschedule = PXSelect <FSSODetSplit, Where <FSSODetSplit.srvOrdType, Equal <Required <FSSODetSplit.srvOrdType> >,
                                                                             And <FSSODetSplit.refNbr, Equal <Required <FSSODetSplit.refNbr> >,
                                                                                  And <FSSODetSplit.lineNbr, Equal <Required <FSSODetSplit.lineNbr> >,
                                                                                       And <FSSODetSplit.splitLineNbr, Equal <Required <FSSODetSplit.parentSplitLineNbr> > > > > > > .Select(graph, newsplit.SrvOrdType, newsplit.RefNbr, newsplit.LineNbr, newsplit.ParentSplitLineNbr);

                if (parentschedule != null && parentschedule.Completed == true && parentschedule.POCompleted == true && parentschedule.BaseQty > parentschedule.BaseReceivedQty &&
                    deletedPlans.Exists(x => x.PlanID == parentschedule.PlanID))
                {
                    serviceOrder.Current = (FSServiceOrder)PXParentAttribute.SelectParent(soDetSplit.Cache, parentschedule, typeof(FSServiceOrder));

                    parentschedule = PXCache <FSSODetSplit> .CreateCopy(parentschedule);

                    INItemPlan demand = PXCache <INItemPlan> .CreateCopy(deletedPlans.First(x => x.PlanID == parentschedule.PlanID));

                    UpdateSchedulesFromCompletedPO(graph, soDetSplit, initemplan, parentschedule, serviceOrder, demand);
                }

                prevSplit = newsplit;
            }

            //Added because of MySql AutoIncrement counters behavior
            foreach (FSSODetSplit split in splitsToDeletePlanID)
            {
                FSSODetSplit schedule = (FSSODetSplit)soDetSplit.Cache.Locate(split);
                if (schedule != null)
                {
                    schedule.PlanID = null;
                    soDetSplit.Cache.Update(schedule);
                }
            }


            return(returnList);
        }
예제 #23
0
        /// <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);
        }
예제 #24
0
        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);
                }
            }
        }
        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));
        }
        protected virtual void ARSalesPrice_SalesPrice_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            ARSalesPrice row = e.Row as ARSalesPrice;

            if (row != null && MinGrossProfitValidation != MinGrossProfitValidationType.None && row.EffectiveDate != null)
            {
                var r = (PXResult <InventoryItem, INItemCost>)
                        PXSelectJoin <InventoryItem,
                                      LeftJoin <INItemCost, On <INItemCost.inventoryID, Equal <InventoryItem.inventoryID> > >,
                                      Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .SelectWindowed(this, 0, 1, row.InventoryID);

                InventoryItem item = r;
                INItemCost    cost = r;
                if (item != null)
                {
                    decimal newValue = (decimal)e.NewValue;
                    if (row.UOM != item.BaseUnit)
                    {
                        try
                        {
                            newValue = INUnitAttribute.ConvertFromBase(sender, item.InventoryID, row.UOM, newValue, INPrecision.UNITCOST);
                        }
                        catch (PXUnitConversionException)
                        {
                            sender.RaiseExceptionHandling <ARSalesPrice.salesPrice>(row, e.NewValue, new PXSetPropertyException(SO.Messages.FailedToConvertToBaseUnits, PXErrorLevel.Warning));
                            return;
                        }
                    }

                    decimal minPrice = PXPriceCostAttribute.MinPrice(item, cost);
                    if (row.CuryID != Company.Current.BaseCuryID)
                    {
                        ARSetup arsetup = PXSetup <ARSetup> .Select(this);

                        if (string.IsNullOrEmpty(arsetup.DefaultRateTypeID))
                        {
                            throw new PXException(SO.Messages.DefaultRateNotSetup);
                        }

                        minPrice = ConvertAmt(Company.Current.BaseCuryID, row.CuryID, arsetup.DefaultRateTypeID, row.EffectiveDate.Value, minPrice);
                    }


                    if (newValue < minPrice)
                    {
                        switch (MinGrossProfitValidation)
                        {
                        case MinGrossProfitValidationType.Warning:
                            sender.RaiseExceptionHandling <ARSalesPrice.salesPrice>(row, e.NewValue, new PXSetPropertyException(SO.Messages.GrossProfitValidationFailed, PXErrorLevel.Warning));
                            break;

                        case MinGrossProfitValidationType.SetToMin:
                            e.NewValue = minPrice;
                            sender.RaiseExceptionHandling <ARSalesPrice.salesPrice>(row, e.NewValue, new PXSetPropertyException(SO.Messages.GrossProfitValidationFailedAndPriceFixed, PXErrorLevel.Warning));
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }
예제 #27
0
        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);
                        }
                    }
                }
            }
        }
        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);
        }
예제 #29
0
        public virtual void UpdateSalesPrice(ARSalesPrice item)
        {
            using (PXConnectionScope cs = new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    DateTime updateTime = DateTime.Now;

                    //FOR UI:
                    item.LastPrice       = item.SalesPrice;
                    item.SalesPrice      = item.PendingPrice;
                    item.LastBreakQty    = item.BreakQty;
                    item.BreakQty        = item.PendingBreakQty;
                    item.LastDate        = item.EffectiveDate;
                    item.EffectiveDate   = null;
                    item.PendingPrice    = 0;
                    item.PendingBreakQty = 0;
                    item.LastTaxID       = item.TaxID;
                    item.TaxID           = item.PendingTaxID;
                    item.PendingTaxID    = null;


                    PXDatabase.Update <ARSalesPrice>(
                        new PXDataFieldAssign("LastPrice", PXDbType.Decimal, item.LastPrice),
                        new PXDataFieldAssign("LastTaxID", PXDbType.NVarChar, item.LastTaxID),
                        new PXDataFieldAssign("LastBreakQty", PXDbType.Decimal, item.LastBreakQty),
                        new PXDataFieldAssign("SalesPrice", PXDbType.Decimal, item.SalesPrice),
                        new PXDataFieldAssign("TaxID", PXDbType.NVarChar, item.TaxID),
                        new PXDataFieldAssign("BreakQty", PXDbType.Decimal, item.BreakQty),
                        new PXDataFieldAssign("LastDate", PXDbType.DateTime, item.LastDate),
                        new PXDataFieldAssign("PendingPrice", PXDbType.Decimal, 0m),
                        new PXDataFieldAssign("PendingTaxID", PXDbType.Decimal, null),
                        new PXDataFieldAssign("EffectiveDate", PXDbType.DateTime, null),
                        new PXDataFieldAssign("PendingBreakQty", PXDbType.Decimal, 0m),
                        new PXDataFieldAssign("LastModifiedDateTime", PXDbType.DateTime, updateTime),

                        new PXDataFieldRestrict("RecordID", PXDbType.Int, item.RecordID),
                        PXDataFieldRestrict.OperationSwitchAllowed
                        );

                    PXDatabase.Update <ARSalesPrice>(
                        new PXDataFieldAssign("SalesPrice", PXDbType.Decimal, item.SalesPrice),
                        new PXDataFieldAssign("LastDate", PXDbType.DateTime, item.LastDate),
                        new PXDataFieldAssign("LastModifiedDateTime", PXDbType.DateTime, updateTime),
                        new PXDataFieldRestrict("InventoryID", PXDbType.Int, item.InventoryID),
                        item.IsCustClassPrice == true
                                                                                ? new PXDataFieldRestrict("CustPriceClassID", PXDbType.NVarChar, item.CustPriceClassID)
                                                                                : new PXDataFieldRestrict("CustomerID", PXDbType.Int, item.CustomerID),
                        new PXDataFieldRestrict("CuryID", PXDbType.NVarChar, item.CuryID),
                        new PXDataFieldRestrict("UOM", PXDbType.NVarChar, item.UOM),
                        new PXDataFieldRestrict("IsPromotionalPrice", PXDbType.Bit, false),
                        new PXDataFieldRestrict("BreakQty", PXDbType.Decimal, item.BreakQty),
                        new PXDataFieldRestrict("RecordID", PXDbType.Int, 4, item.RecordID, PXComp.NE)
                        );

                    InventoryItem ii = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, item.InventoryID);

                    string uom = PXAccess.FeatureInstalled <FeaturesSet.distributionModule>() && sosetup.Current.SalesPriceUpdateUnit == SalesPriceUpdateUnitType.SalesUnit ? ii.SalesUnit : ii.BaseUnit;
                    if (item.UOM == uom && item.CuryID == Company.Current.BaseCuryID && item.CustPriceClassID == AR.ARPriceClass.EmptyPriceClass && item.BreakQty == 0 && item.PendingBreakQty == 0 && item.IsPromotionalPrice == false)
                    {
                        decimal price     = PXAccess.FeatureInstalled <FeaturesSet.distributionModule>() && sosetup.Current.SalesPriceUpdateUnit == SalesPriceUpdateUnitType.SalesUnit ? INUnitAttribute.ConvertFromBase(Inventory.Cache, ii.InventoryID, ii.SalesUnit, item.SalesPrice ?? 0m, INPrecision.UNITCOST) : item.SalesPrice ?? 0m;
                        decimal lastPrice = PXAccess.FeatureInstalled <FeaturesSet.distributionModule>() && sosetup.Current.SalesPriceUpdateUnit == SalesPriceUpdateUnitType.SalesUnit ? INUnitAttribute.ConvertFromBase(Inventory.Cache, ii.InventoryID, ii.SalesUnit, item.LastPrice ?? 0m, INPrecision.UNITCOST) : item.LastPrice ?? 0m;
                        PXDatabase.Update <InventoryItem>(
                            new PXDataFieldAssign("BasePrice", PXDbType.Decimal, price),
                            new PXDataFieldAssign("BasePriceDate", PXDbType.DateTime, item.LastDate),
                            new PXDataFieldAssign("PendingBasePrice", PXDbType.Decimal, 0m),
                            new PXDataFieldAssign("PendingBasePriceDate", PXDbType.DateTime, null),
                            new PXDataFieldAssign("LastBasePrice", PXDbType.Decimal, lastPrice),
                            new PXDataFieldAssign("LastModifiedDateTime", PXDbType.DateTime, updateTime),
                            new PXDataFieldRestrict("InventoryID", PXDbType.Int, item.InventoryID)
                            );
                    }


                    ts.Complete();
                }
            }
        }
        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());
                        }
                    }
                }
            }
        }