Ejemplo n.º 1
0
        /// <summary>
        /// Override the parent method to add additional conditions to control the quantity round-up logic.
        /// </summary>
        protected override AMMultiLevelBomData CreateDetailRow(AMBomMatl amBomMatl, AMBomOper amBomOper, AMBomItem amBomItem, InventoryItem inventoryItem, AMBomItem parentBomItem,
                                                               int lineID, int level, decimal totalQtyReq, AMMultiLevelBomFilter filter, string levelBomid, string levelRevisionID)
        {
            var itemExt = inventoryItem.GetExtension <JAMS.AEF.InventoryItemAMExtension>();

            var qtyRequired = amBomMatl.QtyReq.GetValueOrDefault() * (1 + amBomMatl.ScrapFactor.GetValueOrDefault()) *
                              (amBomMatl.BatchSize.GetValueOrDefault() == 0m ? 1m : 1 / amBomMatl.BatchSize.GetValueOrDefault());

            var totalQtyRequired = amBomMatl.QtyReq.GetValueOrDefault() * (1 + amBomMatl.ScrapFactor.GetValueOrDefault()) *
                                   (amBomMatl.BatchSize.GetValueOrDefault() == 0m ? 1m : totalQtyReq / amBomMatl.BatchSize.GetValueOrDefault());

            var baseTotalQtyRequired = amBomMatl.BaseQty.GetValueOrDefault() * (1 + amBomMatl.ScrapFactor.GetValueOrDefault()) *
                                       (amBomMatl.BatchSize.GetValueOrDefault() == 0m ? 1m : totalQtyReq / amBomMatl.BatchSize.GetValueOrDefault());

            // Add one custom field to determine the round-up logic.
            AMMultiLevelBomFilterExt filterExt = filter.GetExtension <AMMultiLevelBomFilterExt>();

            if (filterExt.UsrEnblItemRoundUp == true)
            {
                qtyRequired          = itemExt.AMQtyRoundUp == false ? qtyRequired : Math.Ceiling(qtyRequired);
                totalQtyRequired     = itemExt.AMQtyRoundUp == false ? totalQtyRequired : Math.Ceiling(totalQtyRequired);
                baseTotalQtyRequired = itemExt.AMQtyRoundUp == false ? baseTotalQtyRequired : Math.Ceiling(baseTotalQtyRequired);
            }

            var row = new AMMultiLevelBomData
            {
                ParentBOMID       = parentBomItem.BOMID,
                RevisionID        = parentBomItem.RevisionID,
                LineID            = lineID,
                Level             = level,
                InventoryID       = amBomMatl.InventoryID,
                Descr             = amBomMatl.Descr,
                ParentInventoryID = parentBomItem.InventoryID,
                ParentSubItemID   = parentBomItem.SubItemID,
                ParentDescr       = parentBomItem.Descr,
                SubItemID         = amBomMatl.SubItemID,
                UOM                  = amBomMatl.UOM,
                ScrapFactor          = amBomMatl.ScrapFactor.GetValueOrDefault(),
                BatchSize            = amBomMatl.BatchSize.GetValueOrDefault(),
                BOMQtyReq            = amBomMatl.QtyReq.GetValueOrDefault(),
                BaseQtyReq           = amBomMatl.BaseQty.GetValueOrDefault(),
                QtyReq               = qtyRequired,
                TotalQtyReq          = totalQtyRequired,
                BaseTotalQtyReq      = baseTotalQtyRequired,
                UnitCost             = amBomMatl.UnitCost.GetValueOrDefault(),
                ExtCost              = qtyRequired * amBomMatl.UnitCost.GetValueOrDefault(),
                TotalExtCost         = totalQtyRequired * amBomMatl.UnitCost.GetValueOrDefault(),
                LineBOMID            = amBomMatl.BOMID,
                LineRevisionID       = amBomMatl.RevisionID,
                OperationID          = amBomOper.OperationID,
                OperationCD          = amBomOper.OperationCD,
                EffStartDate         = parentBomItem.EffStartDate,
                EffEndDate           = parentBomItem.EffEndDate,
                SiteID               = parentBomItem.SiteID,
                Status               = parentBomItem.Status,
                LineStatus           = amBomItem.Status,
                MaterialStatus       = amBomItem.Status,
                OperationDescription = amBomOper.Descr,
                WcID                 = amBomOper.WcID,
                IsHeaderRecord       = false,
                SortOrder            = amBomMatl.SortOrder
            };

            var materialSiteID = amBomMatl.SiteID ?? amBomItem.SiteID;

            if (filter.IgnoreReplenishmentSettings.GetValueOrDefault() ||
                JAMS.AM.InventoryHelper.GetReplenishmentSource(this, row.InventoryID, materialSiteID) == INReplenishmentSource.Manufactured)
            {
                levelBomid      = amBomMatl.CompBOMID;
                levelRevisionID = amBomMatl.CompBOMRevisionID;

                if (!string.IsNullOrWhiteSpace(levelBomid) && !string.IsNullOrWhiteSpace(levelRevisionID))
                {
                    AMBomItem bomItem = null;

                    if (Filter.Current.IncludeBomsOnHold.GetValueOrDefault())
                    {
                        bomItem = PXSelect <AMBomItem, Where <AMBomItem.bOMID, Equal <Required <AMBomItem.bOMID> >,
                                                              And <AMBomItem.revisionID, Equal <Required <AMBomItem.revisionID> >,
                                                                   And2 <Where <AMBomItem.status, Equal <AMBomStatus.hold>,
                                                                                Or <AMBomItem.status, Equal <AMBomStatus.active> > >,
                                                                         And <Where <Required <AMBomItem.effStartDate>, Between <AMBomItem.effStartDate, AMBomItem.effEndDate>,
                                                                                     Or <Where <AMBomItem.effStartDate, LessEqual <Required <AMBomItem.effStartDate> >,
                                                                                                And <AMBomItem.effEndDate, IsNull> > > > > > > > >
                                  .Select(this, levelBomid, levelRevisionID, Filter.Current.BOMDate.GetValueOrDefault(), Filter.Current.BOMDate.GetValueOrDefault());
                    }
                    else
                    {
                        bomItem = PXSelect <AMBomItem, Where <AMBomItem.bOMID, Equal <Required <AMBomItem.bOMID> >,
                                                              And <AMBomItem.revisionID, Equal <Required <AMBomItem.revisionID> >,
                                                                   And <AMBomItem.status, Equal <AMBomStatus.active>,
                                                                        And <Where <Required <AMBomItem.effStartDate>, Between <AMBomItem.effStartDate, AMBomItem.effEndDate>,
                                                                                    Or <Where <AMBomItem.effStartDate, LessEqual <Required <AMBomItem.effStartDate> >,
                                                                                               And <AMBomItem.effEndDate, IsNull> > > > > > > > >
                                  .Select(this, levelBomid, levelRevisionID, Filter.Current.BOMDate.GetValueOrDefault(), Filter.Current.BOMDate.GetValueOrDefault());
                    }

                    if (bomItem == null)
                    {
                        PXTrace.WriteWarning(JAMS.AM.Messages.GetLocal(JAMS.AM.Messages.ComponentBOMRevisionNotActive, levelBomid, levelRevisionID, inventoryItem.InventoryCD));
                        return(row);
                    }
                }

                if (!string.IsNullOrWhiteSpace(levelBomid) && string.IsNullOrWhiteSpace(levelRevisionID))
                {
                    var compBomItem = filter.IncludeBomsOnHold == false
                                      ? PrimaryBomIDManager.GetActiveRevisionBomItemByDate(this, levelBomid, filter.BOMDate.GetValueOrDefault())
                                      : PrimaryBomIDManager.GetNotArchivedRevisionBomItemByDate(this, levelBomid, filter.BOMDate.GetValueOrDefault());

                    if (compBomItem == null)
                    {
                        PXTrace.WriteWarning(JAMS.AM.Messages.GetLocal(JAMS.AM.Messages.NoActiveRevisionForBom, parentBomItem.BOMID));
                        return(row);
                    }

                    levelRevisionID = compBomItem.RevisionID;
                }

                if (string.IsNullOrWhiteSpace(levelBomid))
                {
                    var bomItem = filter.IncludeBomsOnHold == false
                                  ? PrimaryBomIDManager.GetActiveRevisionBomItemByDate(this, new PrimaryBomIDManager(this).GetPrimaryAllLevels(row.InventoryID,
                                                                                                                                               materialSiteID, row.SubItemID), filter.BOMDate.GetValueOrDefault())
                                  : PrimaryBomIDManager.GetNotArchivedRevisionBomItemByDate(this, new PrimaryBomIDManager(this).GetPrimaryAllLevels(row.InventoryID,
                                                                                                                                                    materialSiteID, row.SubItemID), filter.BOMDate.GetValueOrDefault());

                    if (bomItem == null)
                    {
                        PXTrace.WriteWarning(JAMS.AM.Messages.GetLocal(JAMS.AM.Messages.NoActiveRevisionForBom, parentBomItem.BOMID));
                        return(row);
                    }

                    levelBomid      = bomItem.BOMID;
                    levelRevisionID = bomItem.RevisionID;
                }

                row.ManufacturingBOMID      = levelBomid;
                row.ManufacturingRevisionID = levelRevisionID;
            }

            return(row);
        }
Ejemplo n.º 2
0
        // <summary>
        /// Get the total BOM/Operations material cost.
        /// Copy standard method and add one more parameter to control qty round-up.
        /// </summary>
        protected virtual OperationCosts GetMaterialCost(AMBomCost currentAMBomCost, IEnumerable <PXResult <AMBomMatl, InventoryItem> > material, bool isMultLevel, out List <string> materialMessage, bool roundup = true)
        {
            materialMessage = new List <string>();

            if (currentAMBomCost == null || string.IsNullOrWhiteSpace(currentAMBomCost.BOMID) || material == null)
            {
                return(null);
            }

            var operationMaterialCosts = new OperationCosts();

            foreach (var result in material)
            {
                var matlRec       = (AMBomMatl)result;
                var inventoryItem = (InventoryItem)result;

                if (matlRec?.BOMID == null || inventoryItem?.InventoryCD == null)
                {
                    continue;
                }

                decimal?unitcost   = null;
                var     matlSiteID = matlRec.SiteID ?? currentAMBomCost.SiteID;
                if (isMultLevel)
                {
                    var bomManager = new PrimaryBomIDManager(this);
                    var bomItem    = PrimaryBomIDManager.GetNotArchivedRevisionBomItem(this, bomManager.GetPrimaryAllLevels(inventoryItem,
                                                                                                                            JAMS.AM.InventoryHelper.CacheQueryINItemSite(ItemSiteRecs.Cache, matlRec.InventoryID, matlSiteID),
                                                                                                                            matlRec.SubItemID));
                    unitcost = GetCurrentBomCost(bomItem?.BOMID, bomItem?.RevisionID);
                }

                if (unitcost == null)
                {
                    unitcost = GetUnitCost(inventoryItem, matlSiteID);
                }

                var inUnit = (INUnit)PXSelectorAttribute.Select <AMBomMatl.uOM>(this.Caches <AMBomMatl>(), matlRec) ??
                             (INUnit)PXSelect <INUnit, Where <INUnit.inventoryID, Equal <Required <INUnit.inventoryID> >,
                                                              And <INUnit.fromUnit, Equal <Required <INUnit.fromUnit> > > > > .Select(this, matlRec.InventoryID, matlRec.UOM);

                if (inUnit == null)
                {
                    materialMessage.Add(JAMS.AM.Messages.GetLocal(JAMS.AM.Messages.InvalidUOMForMaterialonBOM, matlRec.UOM.TrimIfNotNullEmpty(), inventoryItem.InventoryCD, matlRec.BOMID, matlRec.RevisionID));
                    continue;
                }

                if (UomHelper.TryConvertToBaseCost <AMBomMatl.inventoryID>(BomMatlRecs.Cache, matlRec, matlRec.UOM, unitcost.GetValueOrDefault(), out var matlUnitCost))
                {
                    unitcost = matlUnitCost.GetValueOrDefault();
                }

                var itemExt = inventoryItem.GetExtension <JAMS.AEF.InventoryItemAMExtension>();

                var totalQtyRequired = matlRec.QtyReq.GetValueOrDefault() *
                                       (1 + (Settings.Current.IncMatScrp.GetValueOrDefault() ? matlRec.ScrapFactor.GetValueOrDefault() : 0m)) * (matlRec.BatchSize.GetValueOrDefault() == 0m
                                       ? 1m
                                       : currentAMBomCost.LotSize.GetValueOrDefault() / matlRec.BatchSize.GetValueOrDefault());

                // Use new parameter to determine the qty request round-up per Peter's request.
                if (roundup == true)
                {
                    totalQtyRequired = itemExt.AMQtyRoundUp == false ? totalQtyRequired : Math.Ceiling(totalQtyRequired);
                }

                var matlCost = totalQtyRequired * unitcost.GetValueOrDefault();

                operationMaterialCosts.Add(matlRec.OperationID, matlCost, true);

                if (Settings.Current.UpdateMaterial.GetValueOrDefault())
                {
                    UpdateMaterialUnitCost(matlRec, unitcost);
                }
            }

            return(operationMaterialCosts);
        }