protected virtual void SOSalesPrice_CuryID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
        {
            SOSalesPrice row = e.Row as SOSalesPrice;

            if (row != null)
            {
                if (Filter.Current != null)
                {
                    row.CuryID = Filter.Current.CuryID;
                }
            }
        }
        protected virtual void SOSalesPrice_SalesPrice_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            SOSalesPrice row = e.Row as SOSalesPrice;

            if (sender.GetStatus(row) == PXEntryStatus.Updated)
            {
                if (row.SalesPrice != Convert.ToDecimal(e.OldValue))
                {
                    row.LastPrice = Convert.ToDecimal(e.OldValue);
                    row.LastDate  = Accessinfo.BusinessDate;
                }
            }
        }
        protected virtual void SOSalesPrice_LastDate_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)
                {
                    e.NewValue = item.BasePriceDate;
                }
            }
        }
        private static SalesPriceItem FindSalesPrice(PXCache sender, int inventoryID, string curyID, string UOM, DateTime date)
        {
            SOSalesPrice item = PXSelect <SOSalesPrice, Where <SOSalesPrice.inventoryID, Equal <Required <SOSalesPrice.inventoryID> >,
                                                               And <SOSalesPrice.curyID, Equal <SOSalesPrice.curyID>,
                                                                    And <SOSalesPrice.uOM, Equal <SOSalesPrice.uOM> > > > > .Select(sender.Graph, inventoryID, curyID, UOM);

            string uomFound = null;

            if (item == null || item.LastDate == null)
            {
                item = PXSelect <SOSalesPrice, Where <SOSalesPrice.inventoryID, Equal <Required <SOSalesPrice.inventoryID> >,
                                                      And <SOSalesPrice.curyID, Equal <SOSalesPrice.curyID> > > > .Select(sender.Graph, inventoryID, curyID);

                if (item == null || item.LastDate == null)
                {
                    return(null);
                }
                else
                {
                    uomFound = item.UOM;
                }
            }
            else
            {
                uomFound = UOM;
            }


            if (date < item.LastDate.Value)
            {
                return(new SalesPriceItem(uomFound, item.LastPrice.Value));
            }
            else
            {
                return(new SalesPriceItem(uomFound, item.SalesPrice.Value));
            }
        }
        protected virtual void SOSalesPrice_SalesPrice_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.BasePrice;
                        }
                        else
                        {
                            e.NewValue = INUnitAttribute.ConvertFromBase(sender, item.InventoryID, item.SalesUnit, item.BasePrice.Value, INPrecision.UNITCOST);
                        }
                    }
                }
            }
        }
        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());
                        }
                    }
                }
            }
        }