public virtual RollupQty CalculateRollupQty <T>(T row, IQuantify budget, decimal?quantity) where T : IBqlTable, IQuantify
        {
            string  UOM       = null;
            decimal rollupQty = 0;

            if (budget == null)
            {
                //Budget does not exist for given Inventory and <Other> is not present.
            }
            else
            {
                if (budget.InventoryID == PMInventorySelectorAttribute.EmptyInventoryID)
                {
                    //<Other> item is present. Update only if UOMs are convertable.
                    decimal convertedQty;
                    if (IN.INUnitAttribute.TryConvertGlobalUnits(graph, row.UOM, budget.UOM, quantity.GetValueOrDefault(), IN.INPrecision.QUANTITY, out convertedQty))
                    {
                        rollupQty = convertedQty;
                        UOM       = budget.UOM;
                    }
                }
                else
                {
                    UOM = budget.UOM;

                    //Item matches. Convert to UOM of ProjectStatus.
                    if (budget.UOM != row.UOM && !string.IsNullOrEmpty(budget.UOM) && !string.IsNullOrEmpty(row.UOM))
                    {
                        if (PXAccess.FeatureInstalled <FeaturesSet.multipleUnitMeasure>())
                        {
                            decimal inBase = IN.INUnitAttribute.ConvertToBase(graph.Caches[typeof(T)], row.InventoryID, row.UOM, quantity ?? 0, IN.INPrecision.QUANTITY);
                            try
                            {
                                rollupQty = IN.INUnitAttribute.ConvertFromBase(graph.Caches[typeof(T)], row.InventoryID, budget.UOM, inBase, IN.INPrecision.QUANTITY);
                            }
                            catch (PX.Objects.IN.PXUnitConversionException ex)
                            {
                                IN.InventoryItem item = PXSelectorAttribute.Select(graph.Caches[typeof(T)], row, "inventoryID") as IN.InventoryItem;
                                string           msg  = PXMessages.LocalizeFormatNoPrefixNLA(Messages.UnitConversionNotDefinedForItemOnBudgetUpdate, item?.BaseUnit, budget.UOM, item?.InventoryCD);

                                throw new PXException(msg, ex);
                            }
                        }
                        else
                        {
                            rollupQty = IN.INUnitAttribute.ConvertGlobalUnits(graph, row.UOM, budget.UOM, quantity ?? 0, IN.INPrecision.QUANTITY);
                        }
                    }
                    else if (!string.IsNullOrEmpty(budget.UOM))
                    {
                        rollupQty = quantity ?? 0;
                    }
                }
            }

            return(new RollupQty(UOM, rollupQty));
        }
Esempio n. 2
0
        private decimal CalculateRollupQty <T>(T row, IQuantify budget, decimal quantity) where T : IBqlTable, IQuantify
        {
            if (string.IsNullOrEmpty(budget.UOM) || string.IsNullOrEmpty(row.UOM) || quantity == 0)
            {
                return(0);
            }

            if (budget.UOM == row.UOM)
            {
                return(quantity);
            }

            decimal result = 0;

            if (budget.InventoryID == PMInventorySelectorAttribute.EmptyInventoryID)
            {
                //<Other> item is present. Update only if UOMs are convertable.
                decimal convertedQty;
                if (IN.INUnitAttribute.TryConvertGlobalUnits(graph, row.UOM, budget.UOM, quantity, IN.INPrecision.QUANTITY, out convertedQty))
                {
                    result = convertedQty;
                }
            }
            else
            {
                //Item matches. Convert to UOM of Project Budget.
                if (PXAccess.FeatureInstalled <FeaturesSet.multipleUnitMeasure>())
                {
                    decimal inBase = IN.INUnitAttribute.ConvertToBase(graph.Caches[typeof(T)], row.InventoryID, row.UOM, quantity, IN.INPrecision.QUANTITY);
                    try
                    {
                        result = IN.INUnitAttribute.ConvertFromBase(graph.Caches[typeof(T)], row.InventoryID, budget.UOM, inBase, IN.INPrecision.QUANTITY);
                    }
                    catch (IN.PXUnitConversionException ex)
                    {
                        IN.InventoryItem item = PXSelectorAttribute.Select(graph.Caches[typeof(T)], row, "inventoryID") as IN.InventoryItem;
                        string           msg  = PXMessages.LocalizeFormatNoPrefixNLA(Messages.UnitConversionNotDefinedForItemOnBudgetUpdate, item?.BaseUnit, budget.UOM, item?.InventoryCD);

                        throw new PXException(msg, ex);
                    }
                }
                else
                {
                    result = IN.INUnitAttribute.ConvertGlobalUnits(graph, row.UOM, budget.UOM, quantity, IN.INPrecision.QUANTITY);
                }
            }
            return(result);
        }
 public virtual RollupQty CalculateRollupQty <T>(T row, IQuantify budget) where T : IBqlTable, IQuantify
 {
     return(CalculateRollupQty(row, budget, row.Qty));
 }
Esempio n. 4
0
 public virtual decimal CalculateRollupQty <T>(T row, IQuantify budget, decimal?quantity) where T : IBqlTable, IQuantify
 {
     return(CalculateRollupQty(row, budget, quantity.GetValueOrDefault()));
 }