コード例 #1
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);
        }
        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;
        }
コード例 #3
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);
        }
コード例 #5
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();
                }
            }
        }
コード例 #6
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();
        }
コード例 #8
0
            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);
        }
コード例 #10
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);
        }
コード例 #11
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);
        }
        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 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;
                        }
                    }
                }
            }
        }
コード例 #14
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);
        }
コード例 #15
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();
                }
            }
        }