Exemple #1
0
 internal static ChileLot SetLotType(this ChileLot chileLot, LotTypeEnum?lotType = null)
 {
     if (chileLot == null)
     {
         throw new ArgumentNullException("chileLot");
     }
     chileLot.LotTypeEnum = lotType ?? LotTypeTestHelper.GetRandomChileLotType();
     return(chileLot);
 }
Exemple #2
0
        public static bool ChileLotAttributeOutOfRange(ChileLot chileLot, params DefectTypeEnum[] defectTypes)
        {
            var allDefectTypes = defectTypes == null || !defectTypes.Any();
            var defectRanges   = chileLot.ChileProduct.ProductAttributeRanges.Where(r => (allDefectTypes || defectTypes.Contains(r.AttributeName.DefectType)));

            return(GetAttributeDefects(chileLot.Lot.Attributes.ToDictionary(a => a.ToAttributeNameKey().KeyValue, a => a.AttributeValue),
                                       defectRanges.ToDictionary(r => r.ToAttributeNameKey().KeyValue, r => (IAttributeRange)r))
                   .Any());
        }
Exemple #3
0
        private static string GetUnresolvedDefectsString(ChileLot chileLot)
        {
            var defects = "";

            CheckAndAddDefectString(chileLot, DefectTypeEnum.ProductSpec, ref defects);
            CheckAndAddDefectString(chileLot, DefectTypeEnum.BacterialContamination, ref defects);
            CheckAndAddDefectString(chileLot, DefectTypeEnum.InHouseContamination, ref defects);
            CheckAndAddDefectString(chileLot, DefectTypeEnum.ActionableDefect, ref defects);
            return(string.IsNullOrWhiteSpace(defects) ? "none" : defects);
        }
Exemple #4
0
        internal static ChileLot NullProduction(this ChileLot chileLot)
        {
            if (chileLot == null)
            {
                throw new ArgumentNullException("chileLot");
            }

            chileLot.Production = null;

            return(chileLot);
        }
Exemple #5
0
        internal static ChileLot SetProduct(this ChileLot chileLot, IChileProductKey chileProductKey)
        {
            if (chileLot == null)
            {
                throw new ArgumentNullException("chileLot");
            }

            chileLot.ChileProduct   = null;
            chileLot.ChileProductId = chileProductKey.ChileProductKey_ProductId;

            return(chileLot);
        }
Exemple #6
0
 internal static ChileLot SetDerivedLot(this ChileLot chileLot)
 {
     if (chileLot == null)
     {
         throw new ArgumentNullException("chileLot");
     }
     if (chileLot.Lot != null)
     {
         chileLot.Lot.AdditiveLot  = null;
         chileLot.Lot.PackagingLot = null;
     }
     return(chileLot);
 }
Exemple #7
0
 private static void CheckAndAddDefectString(ChileLot chileLot, DefectTypeEnum defectType, ref string defectString)
 {
     if (LotStatusHelper.LotHasUnresolvedDefects(chileLot.Lot, defectType))
     {
         if (string.IsNullOrWhiteSpace(defectString))
         {
             defectString += defectType.ToString();
         }
         else
         {
             defectString += ", " + defectType.ToString();
         }
     }
 }
Exemple #8
0
        public static bool ChileLotAllProductSpecsEntered(ChileLot chileLot)
        {
            var lotAttributes = chileLot.Lot.Attributes.ToDictionary(a => a.ToAttributeNameKey());

            return(chileLot.ChileProduct.ProductAttributeRanges.All(r =>
            {
                LotAttribute attribute;
                if (lotAttributes.TryGetValue(r.ToAttributeNameKey(), out attribute))
                {
                    return !r.AttributeName.ActualValueRequired || !attribute.Computed;
                }
                return false;
            }));
        }
Exemple #9
0
        public static LotQualityStatus DetermineLotQualityStatus(ChileLot chileLot, bool productSpecComplete)
        {
            if (chileLot == null)
            {
                throw new ArgumentNullException("chileLot");
            }

            if (LotHasUnresolvedDefects(chileLot.Lot, DefectTypeEnum.BacterialContamination))
            {
                return(LotQualityStatus.Contaminated);
            }

            return(productSpecComplete ? LotQualityStatus.Released : LotQualityStatus.Pending);
        }
            protected ChileLot CreateChileLot(LotDTO oldLot, Lot newLot, ChileProduct chileProduct, IEnumerable <AttributeName> attributeNames, ref List <LotAttributeDefect> attributeDefects)
            {
                var newChileLot = new ChileLot
                {
                    LotDateCreated  = newLot.LotDateCreated,
                    LotDateSequence = newLot.LotDateSequence,
                    LotTypeId       = newLot.LotTypeId,
                    Lot             = newLot,

                    ChileProductId = chileProduct.Id,
                    ChileProduct   = chileProduct,
                };

                return(SetLotStatuses(oldLot, newChileLot, attributeNames, ref attributeDefects) ? newChileLot : null);
            }
Exemple #11
0
        public static IResult UpdateChileLotStatus(ChileLot chileLot, List <AttributeName> attributeNames)
        {
            if (chileLot == null)
            {
                throw new ArgumentNullException("chileLot");
            }
            if (attributeNames == null)
            {
                throw new ArgumentNullException("attributeNames");
            }

            chileLot.AllAttributesAreLoBac     = DetermineChileLotIsLoBac(chileLot, attributeNames);
            chileLot.Lot.ProductSpecComplete   = ChileLotAllProductSpecsEntered(chileLot);
            chileLot.Lot.ProductSpecOutOfRange = ChileLotAttributeOutOfRange(chileLot);
            chileLot.Lot.QualityStatus         = PreserveQualityStatus(chileLot.Lot.QualityStatus, DetermineLotQualityStatus(chileLot, chileLot.Lot.ProductSpecComplete));

            return(new SuccessResult());
        }
            private bool SetLotStatuses(LotDTO oldLot, ChileLot newChileLot, IEnumerable <AttributeName> attributeNames, ref List <LotAttributeDefect> attributeDefects)
            {
                newChileLot.AllAttributesAreLoBac = LotStatusHelper.DetermineChileLotIsLoBac(newChileLot, attributeNames);
                newChileLot.Lot.ProductionStatus  = oldLot._BatchStatID < 3 ? LotProductionStatus.Batched : LotProductionStatus.Produced;
                LotMother.SetLotHoldStatus(oldLot.LotStat, newChileLot.Lot);
                newChileLot.Lot.ProductSpecComplete   = LotStatusHelper.ChileLotAllProductSpecsEntered(newChileLot);
                newChileLot.Lot.ProductSpecOutOfRange = LotStatusHelper.ChileLotAttributeOutOfRange(newChileLot);

                if (!SetLotQualityStatus(oldLot.LotStat, newChileLot.Lot, ref attributeDefects))
                {
                    LotMother.Log(new CallbackParameters(oldLot, CallbackReason.ChileLotStatusConflict)
                    {
                        ChileLot = newChileLot
                    });
                    return(false);
                }

                return(true);
            }
Exemple #13
0
        internal static ChileLot SetLotKey(this ChileLot chileLot, ILotKey lotKey = null)
        {
            if (chileLot == null)
            {
                throw new ArgumentNullException("chileLot");
            }

            if (lotKey != null)
            {
                if (chileLot.Lot != null)
                {
                    chileLot.Lot.LotDateCreated  = lotKey.LotKey_DateCreated;
                    chileLot.Lot.LotDateSequence = lotKey.LotKey_DateSequence;
                    chileLot.Lot.LotTypeId       = lotKey.LotKey_LotTypeId;
                }
                chileLot.LotDateCreated  = lotKey.LotKey_DateCreated;
                chileLot.LotDateSequence = lotKey.LotKey_DateSequence;
                chileLot.LotTypeId       = lotKey.LotKey_LotTypeId;
            }

            return(chileLot);
        }
Exemple #14
0
 public static LotQualityStatus DetermineLotQualityStatus(ChileLot chileLot)
 {
     return(DetermineLotQualityStatus(chileLot, ChileLotAllProductSpecsEntered(chileLot)));
 }
Exemple #15
0
 public static IEnumerable <LotQualityStatus> GetValidLotQualityStatuses(ChileLot chileLot)
 {
     return(GetValidLotQualityStatuses(chileLot.Lot.QualityStatus, chileLot.Lot.ProductSpecComplete, LotHasUnresolvedDefects(chileLot.Lot, DefectTypeEnum.ActionableDefect), LotHasUnresolvedDefects(chileLot.Lot, DefectTypeEnum.BacterialContamination)));
 }
        public IResult Execute(ChileLot chileLot, List <PickedInventoryItem> pickedItems, DateTime timestamp)
        {
            if (chileLot == null)
            {
                throw new ArgumentNullException("chileLot");
            }
            if (pickedItems == null)
            {
                throw new ArgumentNullException("pickedItems");
            }

            var actualsRequired = new HashSet <AttributeNameKey>(_lotUnitOfWork.AttributeNameRepository
                                                                 .All().Where(a => a.ActualValueRequired)
                                                                 .ToList()
                                                                 .Select(a => a.ToAttributeNameKey()));

            foreach (var item in pickedItems)
            {
                item.PackagingProduct = _lotUnitOfWork.PackagingProductRepository.FindByKey(item.ToPackagingProductKey());
                item.Lot = _lotUnitOfWork.LotRepository.FindByKey(item.ToLotKey(), i => i.Attributes.Select(a => a.AttributeName));
            }

            var weightedAverages = CalculateAttributeWeightedAveragesCommand.Execute(pickedItems);

            if (!weightedAverages.Success)
            {
                return(weightedAverages);
            }

            var attributesToRemove = chileLot.Lot.Attributes.ToList();
            var attributesToSet    = weightedAverages.ResultingObject.Where(a => !actualsRequired.Contains(a.Key.Attribute.ToAttributeNameKey())).ToList();

            foreach (var weightedAttribute in attributesToSet)
            {
                var namePredicate = weightedAttribute.Key.AttributeNameKey.FindByPredicate.Compile();
                var lotAttribute  = attributesToRemove.FirstOrDefault(a => namePredicate(a.AttributeName));
                if (lotAttribute != null)
                {
                    attributesToRemove.Remove(lotAttribute);
                }
                else
                {
                    lotAttribute = new LotAttribute
                    {
                        LotDateCreated     = chileLot.LotDateCreated,
                        LotDateSequence    = chileLot.LotDateSequence,
                        LotTypeId          = chileLot.LotTypeId,
                        AttributeShortName = weightedAttribute.Key.AttributeNameKey.AttributeNameKey_ShortName,
                        Computed           = true
                    };
                    chileLot.Lot.Attributes.Add(lotAttribute);
                }

                if (lotAttribute.Computed)
                {
                    lotAttribute.AttributeValue = weightedAttribute.Value;
                    lotAttribute.EmployeeId     = chileLot.Production.PickedInventory.EmployeeId;
                    lotAttribute.AttributeDate  = (lotAttribute.TimeStamp = timestamp).Date;
                }
            }

            foreach (var attribute in attributesToRemove.Where(a => a.Computed))
            {
                _lotUnitOfWork.LotAttributeRepository.Remove(attribute);
            }

            return(new SuccessResult());
        }