internal static LotAttribute SetValues(this LotAttribute lotAttribute, ILotKey lotKey = null, IAttributeNameKey attributeNameKey = null, double?value = null, bool?computed = null)
        {
            if (lotKey != null)
            {
                lotAttribute.Lot             = null;
                lotAttribute.LotDateCreated  = lotKey.LotKey_DateCreated;
                lotAttribute.LotDateSequence = lotKey.LotKey_DateSequence;
                lotAttribute.LotTypeId       = lotKey.LotKey_LotTypeId;
            }

            if (attributeNameKey != null)
            {
                lotAttribute.AttributeName      = null;
                lotAttribute.AttributeShortName = attributeNameKey.AttributeNameKey_ShortName;
            }

            if (value != null)
            {
                lotAttribute.AttributeValue = (double)value;
            }

            if (computed != null)
            {
                lotAttribute.Computed = computed.Value;
            }

            return(lotAttribute);
        }
        public ModifyInventoryParameters(ILotKey lotKey, IPackagingProductKey packagingProductKey, ILocationKey locationKey, IInventoryTreatmentKey inventoryTreatmentKey, string toteKey, int adjustQuantity)
        {
            if (lotKey == null)
            {
                throw new ArgumentNullException("lotKey");
            }
            if (packagingProductKey == null)
            {
                throw new ArgumentNullException("packagingProductKey");
            }
            if (locationKey == null)
            {
                throw new ArgumentNullException("locationKey");
            }
            if (inventoryTreatmentKey == null)
            {
                throw new ArgumentNullException("inventoryTreatmentKey");
            }

            InventoryKey          = new InventoryKey(lotKey, packagingProductKey, locationKey, inventoryTreatmentKey, toteKey);
            LotKey                = lotKey.ToLotKey();
            PackagingProductKey   = packagingProductKey.ToPackagingProductKey();
            LocationKey           = locationKey.ToLocationKey();
            InventoryTreatmentKey = inventoryTreatmentKey.ToInventoryTreatmentKey();

            ModifyQuantity = adjustQuantity;
        }
Esempio n. 3
0
 public InventoryTransactionParameters(IEmployeeKey employeeKey, DateTime timeStamp, InventoryTransactionType transactionType, string sourceReference, ILotKey destinationLotKey = null)
 {
     EmployeeKey       = employeeKey;
     TimeStamp         = timeStamp;
     TransactionType   = transactionType;
     Description       = InventoryTransactionsHelper.GetDescription(transactionType);
     SourceReference   = sourceReference;
     DestinationLotKey = destinationLotKey;
 }
Esempio n. 4
0
        internal static Expression <Func <ProductionBatch, bool> > ByLotKey(ILotKey lotKey)
        {
            if (lotKey == null)
            {
                throw new ArgumentNullException("lotKey");
            }

            return(b => b.LotDateCreated == lotKey.LotKey_DateCreated && b.LotDateSequence == lotKey.LotKey_DateSequence && b.LotTypeId == lotKey.LotKey_LotTypeId);
        }
Esempio n. 5
0
        public PackScheduleKey GetLotPackScheduleKey(ILotKey lotKey)
        {
            PackScheduleKey packScheduleKey;

            if (LotPackScheduleKeys.TryGetValue(new LotKey(lotKey), out packScheduleKey))
            {
                return(packScheduleKey);
            }
            return(null);
        }
Esempio n. 6
0
        private IResult UpdateOrCreateLotAttribute(ILotKey chileLotKey, AttributeNameKey attributeNameKey, IAttributeValueParameters newAttribute, ref List <LotAttribute> unaccountedAttributes)
        {
            var existingAttribute = false;
            var lotAttribute      = unaccountedAttributes.FirstOrDefault(a => a.AttributeName != null && attributeNameKey.FindByPredicate.Invoke(a.AttributeName));

            if (lotAttribute != null)
            {
                existingAttribute = true;
                unaccountedAttributes.Remove(lotAttribute);
            }
            else
            {
                var attributeName = _parameters.AttributeNames.FirstOrDefault(a => attributeNameKey.FindByPredicate.Invoke(a));
                if (attributeName == null)
                {
                    return(new InvalidResult(string.Format(UserMessages.AttributeNameNotFound, attributeNameKey.KeyValue)));
                }

                lotAttribute = _lotUnitOfWork.LotAttributeRepository.Add(new LotAttribute
                {
                    LotDateCreated  = chileLotKey.LotKey_DateCreated,
                    LotDateSequence = chileLotKey.LotKey_DateSequence,
                    LotTypeId       = chileLotKey.LotKey_LotTypeId,

                    AttributeShortName = attributeNameKey.AttributeNameKey_ShortName,
                    AttributeName      = attributeName
                });
            }

            var newValueInSpec = false;

            if (!existingAttribute ||
                (Math.Abs(lotAttribute.AttributeValue - newAttribute.AttributeInfo.Value) > EPSILON) ||
                lotAttribute.AttributeDate != newAttribute.AttributeInfo.Date)
            {
                var updateResult = UpdateLotAttribute(lotAttribute, newAttribute, out newValueInSpec);
                if (!updateResult.Success)
                {
                    return(updateResult);
                }
            }

            if (newValueInSpec || newAttribute.Resolution != null)
            {
                var resolveOpenDefectsResult = ResolveOpenDefectsForAttribute(lotAttribute, newAttribute);
                if (!resolveOpenDefectsResult.Success)
                {
                    return(resolveOpenDefectsResult);
                }
            }

            return(new SuccessResult());
        }
        internal static Inventory ConstrainByKeys(this Inventory inventory, ILotKey lotKey = null, IPackagingProductKey packagingProductKey = null, ILocationKey locationKey = null, IInventoryTreatmentKey treatment = null, IFacilityKey facility = null, string toteKey = null)
        {
            if (inventory == null)
            {
                throw new ArgumentNullException("inventory");
            }

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

            if (packagingProductKey != null)
            {
                inventory.PackagingProduct   = null;
                inventory.PackagingProductId = packagingProductKey.PackagingProductKey_ProductId;
            }

            if (locationKey != null)
            {
                inventory.Location   = null;
                inventory.LocationId = locationKey.LocationKey_Id;
            }

            if (treatment != null)
            {
                inventory.Treatment   = null;
                inventory.TreatmentId = treatment.InventoryTreatmentKey_Id;
            }

            if (facility != null)
            {
                if (inventory.Location == null)
                {
                    throw new ArgumentNullException("warehouseLocation is null. Maybe you tried constraining by both the LocationKey and FacilityKey. Can't do that. Pick one or the other. -RI");
                }
                inventory.Location.Facility   = null;
                inventory.Location.FacilityId = facility.FacilityKey_Id;
            }

            if (toteKey != null)
            {
                inventory.ToteKey = toteKey;
            }

            return(inventory);
        }
Esempio n. 8
0
        public void UpdateOldLotAttributes(ILotKey lotKey, List <LotAttribute> newLotAttributes)
        {
            var lotNumber = LotNumberBuilder.BuildLotNumber(lotKey);
            var oldLot    = _oldContext.tblLots
                            .Include(l => l.tblLotAttributeHistory)
                            .FirstOrDefault(l => l.Lot == lotNumber);

            if (oldLot == null)
            {
                throw new Exception(string.Format("Could not find tblLot[{0}]", lotNumber));
            }

            SyncProductionBatchPickedInventoryHelper.SetLotBatchAttributes(oldLot, newLotAttributes);
            LotSyncHelper.SetLotAttributes(oldLot, newLotAttributes);
        }
            internal LotPackagingKeyValueQuantity(ILotKey lot, IPackagingProductKey packaging, int quantity)
            {
                var lotKey = new LotKey(lot);

                LotKeyValue            = lotKey.KeyValue;
                LotPredicateExpression = lotKey.FindByPredicate;
                LotPredicate           = lotKey.FindByPredicate.Compile();

                var packagingKey = new PackagingProductKey(packaging);

                PackagingKeyValue            = packagingKey.KeyValue;
                PackagingPredicateExpression = packagingKey.FindByPredicate;
                PackagingPredicate           = packagingKey.FindByPredicate.Compile();

                Quantity = quantity;
            }
        internal IResult <IEnumerable <ILotInputTraceReturn> > Execute(ILotKey lotKey)
        {
            var key       = lotKey.ToLotKey();
            var lotSelect = _lotUnitOfWork.LotRepository.FilterByKey(key).Select(_selectInputs).FirstOrDefault();

            if (lotSelect == null)
            {
                return(new InvalidResult <IEnumerable <ILotInputTraceReturn> >(null, string.Format(UserMessages.LotNotFound, key)));
            }

            var traceResults = new List <ILotInputTraceReturn>();

            Trace(ref traceResults, lotSelect, lotSelect.LotKey.LotKey);

            return(new SuccessResult <IEnumerable <ILotInputTraceReturn> >(traceResults));
        }
        public static tblLot GetLot(this RioAccessSQLEntities oldContext, ILotKey lotKey, bool throwIfNotFound = true)
        {
            var lotNumber = LotNumberBuilder.BuildLotNumber(lotKey);
            var oldLot    = oldContext.tblLots.Where(l => l.Lot == lotNumber).Select(l => new
            {
                lot = l,
                l.tblLotAttributeHistory
            }).FirstOrDefault();

            if (oldLot == null && throwIfNotFound)
            {
                throw new Exception(string.Format("Lot[{0}] not found in old context.", lotNumber));
            }

            return(oldLot == null ? null : oldLot.lot);
        }
Esempio n. 12
0
        internal static Lot SetLotKey(this Lot lot, ILotKey lotKey)
        {
            if (lot == null)
            {
                throw new ArgumentNullException("lot");
            }

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

            return(lot);
        }
Esempio n. 13
0
        internal IResult <IProductionPacketReturn> Execute(ILotKey lotKey, DateTime currentDate)
        {
            var productionBatchKey = new LotKey(lotKey);
            var select             = ProductionBatchProjectors.SplitSelectProductionPacketFromBatch(_productionUnitOfWork, currentDate.Date, productionBatchKey);
            var productionPacket   = _productionUnitOfWork.ProductionBatchRepository
                                     .Filter(productionBatchKey.GetPredicate <ProductionBatch>())
                                     .SplitSelect(select)
                                     .ToList();

            if (productionPacket.Count != 1)
            {
                return(new InvalidResult <IProductionPacketReturn>(null, string.Format(UserMessages.ProductionBatchNotFound, productionBatchKey)));
            }

            return(Process(productionPacket.Single()));
        }
        internal static void ConstrainByLotKey(this PackagingLot packagingLot, ILotKey lotKey)
        {
            if (packagingLot == null)
            {
                throw new ArgumentNullException("packagingLot");
            }
            if (lotKey == null)
            {
                throw new ArgumentNullException("lotKey");
            }

            packagingLot.Lot             = null;
            packagingLot.LotDateCreated  = lotKey.LotKey_DateCreated;
            packagingLot.LotDateSequence = lotKey.LotKey_DateSequence;
            packagingLot.LotTypeId       = lotKey.LotKey_LotTypeId;
        }
        private Inventory CreateInventory(ViewInventoryLoadSelected inventory, ILotKey lotKey)
        {
            if (inventory.Quantity < 1)
            {
                Log(new CallbackParameters(CallbackReason.QuantityLessThanOne)
                {
                    Inventory = inventory
                });
                return(null);
            }

            var warehouseLocation = NewContextHelper.GetLocation(inventory.LocID);

            if (warehouseLocation == null)
            {
                Log(new CallbackParameters(CallbackReason.WarehouseLocationNotLoaded)
                {
                    Inventory = inventory
                });
                return(null);
            }

            var packagingProduct = GetInventoryPackaging(inventory);

            if (packagingProduct == null)
            {
                Log(new CallbackParameters(CallbackReason.PackagingNotLoaded)
                {
                    Inventory = inventory
                });
                return(null);
            }

            return(new Inventory
            {
                LotDateCreated = lotKey.LotKey_DateCreated,
                LotDateSequence = lotKey.LotKey_DateSequence,
                LotTypeId = lotKey.LotKey_LotTypeId,

                PackagingProductId = packagingProduct.Id,
                LocationId = warehouseLocation.Id,
                TreatmentId = inventory.TrtmtID,
                ToteKey = inventory.Tote ?? "",

                Quantity = (int)inventory.Quantity
            });
        }
        internal static AdditiveLot SetLotKey(this AdditiveLot additiveLot, ILotKey lotKey)
        {
            if (additiveLot == null)
            {
                throw new ArgumentNullException("additiveLot");
            }
            if (lotKey == null)
            {
                throw new ArgumentNullException("lotKey");
            }

            additiveLot.Lot             = null;
            additiveLot.LotDateCreated  = lotKey.LotKey_DateCreated;
            additiveLot.LotDateSequence = lotKey.LotKey_DateSequence;
            additiveLot.LotTypeId       = lotKey.LotKey_LotTypeId;
            return(additiveLot);
        }
        internal IResult Execute(ILotKey lotKey)
        {
            if (lotKey == null)
            {
                throw new ArgumentNullException("lotKey");
            }

            var chileLot = _lotUnitOfWork.ChileLotRepository.FindByKey(new LotKey(lotKey), LotStatusHelper.ChileLotIncludePaths);

            if (chileLot != null)
            {
                var attributeNames = _lotUnitOfWork.AttributeNameRepository.Filter(a => true, a => a.ValidTreatments).ToList();
                LotStatusHelper.UpdateChileLotStatus(chileLot, attributeNames);
            }

            return(new SuccessResult());
        }
Esempio n. 18
0
        internal static LotDefect SetValues(this LotDefect lotDefect, ILotKey lotKey = null, DefectTypeEnum?defectType = null)
        {
            if (lotKey != null)
            {
                lotDefect.Lot             = null;
                lotDefect.LotDateCreated  = lotKey.LotKey_DateCreated;
                lotDefect.LotDateSequence = lotKey.LotKey_DateSequence;
                lotDefect.LotTypeId       = lotKey.LotKey_LotTypeId;
            }

            if (defectType != null)
            {
                lotDefect.DefectType = (DefectTypeEnum)defectType;
            }

            return(lotDefect);
        }
Esempio n. 19
0
        public static string ToMaterialType(this ILotKey lot)
        {
            switch ((LotTypeEnum)lot.LotKey_LotTypeId)
            {
            case LotTypeEnum.Raw:
            case LotTypeEnum.DeHydrated:
            case LotTypeEnum.WIP:
            case LotTypeEnum.FinishedGood:
                return("Base");

            case LotTypeEnum.Additive:
                return("Ingredient");

            case LotTypeEnum.Packaging:
                return("Packaging");
            }
            return("");
        }
        internal static LotAttributeDefect SetValues(this LotAttributeDefect defect, ILotKey lotKey = null, IAttributeNameKey attributeNameKey = null, DefectTypeEnum?defectType = null, double?value = null, double?rangeMin = null, double?rangeMax = null)
        {
            if (lotKey != null)
            {
                if (defect.LotDefect != null)
                {
                    defect.LotDefect.SetValues(lotKey);
                }

                defect.LotDateCreated  = lotKey.LotKey_DateCreated;
                defect.LotDateSequence = lotKey.LotKey_DateSequence;
                defect.LotTypeId       = lotKey.LotKey_LotTypeId;
            }

            if (attributeNameKey != null)
            {
                defect.AttributeName      = null;
                defect.AttributeShortName = attributeNameKey.AttributeNameKey_ShortName;
            }

            if (defectType != null)
            {
                defect.LotDefect.DefectType = (DefectTypeEnum)defectType;
            }

            if (value != null)
            {
                defect.OriginalAttributeValue = (double)value;
            }

            if (rangeMin != null)
            {
                defect.OriginalAttributeMinLimit = (double)rangeMin;
            }

            if (rangeMax != null)
            {
                defect.OriginalAttributeMaxLimit = (double)rangeMax;
            }

            return(defect);
        }
Esempio n. 21
0
        private IEnumerable <LotProductionResultItem> CreateLotProductionResultItems(ILotKey lotKey, IEnumerable <IncomingDTO> incomings)
        {
            var itemSequence = 0;

            foreach (var incoming in incomings)
            {
                _loadCount.AddRead(EntityTypes.LotProductionResultItem);

                var packaging = _newContextHelper.GetPackagingProduct(incoming.PkgID);
                if (packaging == null)
                {
                    Log(new CallbackParameters(CallbackReason.IncomingPackagingNotLoaded)
                    {
                        Incoming = incoming
                    });
                    continue;
                }

                var warehouseLocation = _newContextHelper.GetLocation(incoming.LocID);
                if (warehouseLocation == null)
                {
                    Log(new CallbackParameters(CallbackReason.IncomingWarehouseLocationNotLoaded)
                    {
                        Incoming = incoming
                    });
                    continue;
                }

                yield return(new LotProductionResultItem
                {
                    LotDateCreated = lotKey.LotKey_DateCreated,
                    LotDateSequence = lotKey.LotKey_DateSequence,
                    LotTypeId = lotKey.LotKey_LotTypeId,
                    ResultItemSequence = ++itemSequence,

                    Quantity = (int)incoming.Quantity,
                    PackagingProductId = packaging.Id,
                    LocationId = warehouseLocation.Id,
                    TreatmentId = _newContextHelper.NoTreatment.Id
                });
            }
        }
        internal static ChileLotProduction Set(this ChileLotProduction production, ILotKey lotKey, ProductionType?productionType = null)
        {
            if (production == null)
            {
                throw new ArgumentNullException("production");
            }

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

            if (productionType != null)
            {
                production.ProductionType = productionType.Value;
            }

            return(production);
        }
Esempio n. 23
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);
        }
Esempio n. 24
0
        public static LotNumberResult BuildLotNumber(ILotKey lotKey)
        {
            var date            = lotKey.LotKey_DateCreated;
            var julianString    = string.Format("{0:00}{1:000}", date.Year % 100, date.DayOfYear);
            var lotNumberString = string.Format("{0}{1}{2:00}", lotKey.LotKey_LotTypeId, julianString, lotKey.LotKey_DateSequence);

            int julian;

            if (!int.TryParse(julianString, out julian))
            {
                throw new FormatException(string.Format("Could not parse [{0}] into integer.", julianString));
            }

            int lotNumber;

            if (!int.TryParse(lotNumberString, out lotNumber))
            {
                throw new FormatException(string.Format("Could not parse [{0}] into integer.", lotNumberString));
            }

            return(new LotNumberResult(lotNumber, julian));
        }
Esempio n. 25
0
 internal static IEnumerable <Expression <Func <ProductionBatch, ProductionPacketReturn> > > SplitSelectProductionPacketFromBatch(IInventoryUnitOfWork inventoryUnitOfWork, DateTime currentDate, ILotKey batchKey)
 {
     return(PackScheduleProjectors.SplitSelectProductionPacket(inventoryUnitOfWork, currentDate, batchKey)
            .Select(b => Projector <ProductionBatch> .To(a => b.Invoke(a.PackSchedule))));
 }
Esempio n. 26
0
        internal static InventoryAdjustmentItem ConstrainByKeys(this InventoryAdjustmentItem item, IInventoryAdjustmentKey adjustmentKey, ILotKey lotKey = null)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (adjustmentKey != null)
            {
                item.InventoryAdjustment = null;
                item.AdjustmentDate      = adjustmentKey.InventoryAdjustmentKey_AdjustmentDate;
                item.Sequence            = adjustmentKey.InventoryAdjustmentKey_Sequence;
            }

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

            return(item);
        }
        private ChileMaterialsReceivedItem CreateItemReceived(IGrouping <ChileMaterialsItemReceivedKeys, tblIncoming> oldItems, ILotKey lotKey, int newSequence)
        {
            _loadCount.AddRead(EntityTypes.ChileMaterialsReceivedItem);

            if (oldItems.Any(i => i.Quantity == null))
            {
                return(null);
            }
            var quantity = (int)oldItems.Sum(i => i.Quantity);

            var warehouseLocation = _newContextHelper.GetLocation(oldItems.Key.LocID);

            if (warehouseLocation == null)
            {
                Log(new CallbackParameters(CallbackReason.WarehouseLocationNotLoaded)
                {
                    Items = oldItems
                });
                return(null);
            }

            var packagingProduct = _newContextHelper.GetPackagingProduct(oldItems.Key.PkgID);

            if (packagingProduct == null)
            {
                Log(new CallbackParameters(CallbackReason.PackagingNotLoaded)
                {
                    Items = oldItems
                });
                return(null);
            }

            return(new ChileMaterialsReceivedItem
            {
                LotDateCreated = lotKey.LotKey_DateCreated,
                LotDateSequence = lotKey.LotKey_DateSequence,
                LotTypeId = lotKey.LotKey_LotTypeId,
                ItemSequence = newSequence,

                ToteKey = oldItems.Key.Tote,
                Quantity = quantity,

                LocationId = warehouseLocation.Id,
                PackagingProductId = packagingProduct.Id,
                GrowerCode = oldItems.Key.DehyLocale,
                ChileVariety = oldItems.Key.Variety
            });
        }
Esempio n. 28
0
 public LotAttributeKey(ILotKey lotKey, IAttributeNameKey attributeNameKey) : this(lotKey.LotKey_DateCreated, lotKey.LotKey_DateSequence, lotKey.LotKey_LotTypeId, attributeNameKey.AttributeNameKey_ShortName)
 {
 }
 public static Expression <Func <LotAttributeDefect, bool> > FilterByLotKey(ILotKey lotKey)
 {
     return(d => d.LotDateCreated == lotKey.LotKey_DateCreated && d.LotDateSequence == lotKey.LotKey_DateSequence && d.LotTypeId == lotKey.LotKey_LotTypeId);
 }
Esempio n. 30
0
        private LotProductionResults CreateLotProductionResults(ILotKey lotKey, LotDTO lot, out bool usedDefaultProductionLine, out DateTime entryDate)
        {
            usedDefaultProductionLine = false;
            entryDate = new DateTime();

            _loadCount.AddRead(EntityTypes.LotProductionResults);

            var employeeId = lot.EmployeeID ?? _newContextHelper.DefaultEmployee.EmployeeId;

            if (lot.EmployeeID == null)
            {
                Log(new CallbackParameters(CallbackReason.DefaultEmployee)
                {
                    Lot        = lot,
                    EmployeeId = employeeId
                });
            }

            if (lot.EntryDate == null)
            {
                Log(new CallbackParameters(CallbackReason.NullEntryDate)
                {
                    Lot = lot
                });
                return(null);
            }
            entryDate = lot.EntryDate.Value.ConvertLocalToUTC();

            var productionLineNumber = 1;

            if (lot.ProductionLine == null)
            {
                usedDefaultProductionLine = true;
            }
            else
            {
                productionLineNumber = lot.ProductionLine.Value;
            }

            var productionLine = _newContextHelper.GetProductionLine(productionLineNumber);

            if (productionLine == null)
            {
                Log(new CallbackParameters(CallbackReason.ProductionLineNotLoaded)
                {
                    Lot = lot,
                    ProductionLineNumber = productionLineNumber
                });
                return(null);
            }

            DateTime productionBegin;

            if (lot.BatchBegTime == null)
            {
                if (lot.ProductionDate == null)
                {
                    Log(new CallbackParameters(CallbackReason.ProductionBeginCouldNotBeDetermined)
                    {
                        Lot = lot
                    });
                    return(null);
                }

                Log(new CallbackParameters(CallbackReason.ProductionBeginFromProductionDate)
                {
                    Lot = lot
                });
                productionBegin = lot.ProductionDate.Value.ConvertLocalToUTC();
            }
            else
            {
                productionBegin = lot.BatchBegTime.Value.ConvertLocalToUTC();
            }

            DateTime productionEnd;

            if (lot.BatchEndTime == null)
            {
                if (lot.ProductionDate == null)
                {
                    Log(new CallbackParameters(CallbackReason.ProductionEndTimeCouldNotBeDetermined)
                    {
                        Lot = lot
                    });
                    return(null);
                }

                Log(new CallbackParameters(CallbackReason.ProductionEndTimeFromProductionDate)
                {
                    Lot = lot
                });
                productionEnd = lot.ProductionDate.Value.ConvertLocalToUTC();
            }
            else
            {
                productionEnd = lot.BatchEndTime.Value.ConvertLocalToUTC();
            }

            return(new LotProductionResults
            {
                EmployeeId = employeeId,
                TimeStamp = entryDate,

                LotDateCreated = lotKey.LotKey_DateCreated,
                LotDateSequence = lotKey.LotKey_DateSequence,
                LotTypeId = lotKey.LotKey_LotTypeId,

                ProductionLineLocationId = productionLine.Id,

                ShiftKey = lot.Shift,
                ProductionBegin = productionBegin,
                ProductionEnd = productionEnd,
                DateTimeEntered = entryDate,

                ProductionLineLocation = productionLine,

                ResultItems = CreateLotProductionResultItems(lotKey, lot.tblIncomings).ToList()
            });
        }