private bool SetDeterminedPackaging(PackSchedule packSchedule, PackScheduleDTO oldPackSchedule) { int? pkgId; tblPackaging packaging; var packagingResult = _packagingHelper.DeterminePackaging(oldPackSchedule, out pkgId, out packaging); if (packagingResult != PackSchedulePackagingHelper.PackagingResult.FromSinglePickedPackaging) { Log(new CallbackParameters(packagingResult.ToCallbackReason()) { PackSchedule = oldPackSchedule, Packaging = packaging }); } if (pkgId == null) { return(false); } var packagingProduct = _newContextHelper.GetPackagingProduct(pkgId); if (packagingProduct == null) { Log(new CallbackParameters(CallbackReason.PackagingNotLoaded) { PackSchedule = oldPackSchedule, PkgID = pkgId }); return(false); } packSchedule.PackagingProductId = packagingProduct.Id; return(true); }
private bool ProcessUnserializedPackSchedule(PackSchedule packSchedule, PackScheduleDTO oldPackSchedule) { if (!oldPackSchedule.BatchItems.Any()) { Log(new CallbackParameters(CallbackReason.NoBatchItems) { PackSchedule = oldPackSchedule }); return(false); } var batchTypeId = GetSingleBatchTypeID(oldPackSchedule); if (batchTypeId == null) { Log(new CallbackParameters(CallbackReason.NoSingleBatchType) { PackSchedule = oldPackSchedule }); return(false); } packSchedule.WorkTypeId = WorkTypeFactory.BuildWorkTypeFromBatchTypeID(batchTypeId.Value).Id; if (!SetDeterminedPackaging(packSchedule, oldPackSchedule)) { return(false); } packSchedule.ProductionBatches = new List <ProductionBatch>(); return(true); }
private int?GetSingleBatchTypeID(PackScheduleDTO oldPackSchedule) { if (oldPackSchedule.BatchLots != null && oldPackSchedule.BatchLots.Any()) { var batchTypeIds = oldPackSchedule.BatchLots.Select(b => b.BatchTypeID).Distinct().Where(t => t != null).ToList(); if (batchTypeIds.Count == 1) { return(batchTypeIds[0]); } } return(null); }
private bool ProcessSerializedPackSchedule(PackSchedule packSchedule, PackScheduleDTO oldPackSchedule, out bool isSerialized) { isSerialized = true; int?pkgID; if (!SerializablePackSchedule.DeserializeIntoPackSchedule(packSchedule, oldPackSchedule.Serialized, out pkgID)) { isSerialized = false; return(false); } int?batchTypeId; if (oldPackSchedule.BatchLots != null && oldPackSchedule.BatchLots.Any()) { batchTypeId = GetSingleBatchTypeID(oldPackSchedule); if (batchTypeId == null) { Log(new CallbackParameters(CallbackReason.NoSingleBatchType) { PackSchedule = oldPackSchedule }); return(false); } } else { batchTypeId = oldPackSchedule.BatchTypeID.Value; } packSchedule.WorkTypeId = WorkTypeFactory.BuildWorkTypeFromBatchTypeID(batchTypeId.Value).Id; var packagingProduct = _newContextHelper.GetPackagingProduct(pkgID); if (packagingProduct != null) { packSchedule.PackagingProductId = packagingProduct.Id; } else if (!SetDeterminedPackaging(packSchedule, oldPackSchedule)) { return(false); } var productionBatches = packSchedule.ProductionBatches.ToList(); productionBatches.RemoveAll(batch => { var lotKey = new LotKey(batch); var lotNumber = LotNumberParser.BuildLotNumber(lotKey); List <DateTime?> ids; if (_batchItemPackSchIds.TryGetValue(lotNumber, out ids)) { if (ids.Any()) { if (ids.Any(i => i != oldPackSchedule.PackSchID)) { Log(new CallbackParameters(CallbackReason.MismatchedBatchItemPackSchID) { PackSchedule = oldPackSchedule, BatchNumber = lotNumber }); } return(true); } } _loadCount.AddRead(EntityTypes.ProductionBatch); _loadCount.AddRead(EntityTypes.Notebook); _loadCount.AddRead(EntityTypes.PickedInventory); _loadCount.AddRead(EntityTypes.ChileLot); _loadCount.AddRead(EntityTypes.Lot); if (!_newContextHelper.LotLoaded(lotKey)) { Log(new CallbackParameters(CallbackReason.BatchLotNotLoaded) { PackSchedule = oldPackSchedule, LotKey = lotKey }); return(true); } var dateCreated = batch.LotDateCreated.Date; var sequence = PickedInventoryKeyHelper.Singleton.GetNextSequence(dateCreated); batch.Production.PickedInventoryDateCreated = batch.Production.PickedInventory.DateCreated = dateCreated; batch.Production.PickedInventorySequence = batch.Production.PickedInventory.Sequence = sequence; var notebook = _notebookFactory.BirthNext(batch.TimeStamp); batch.InstructionNotebook = notebook; batch.InstructionNotebookDateCreated = notebook.Date; batch.InstructionNotebookSequence = notebook.Sequence; var deserializedProduction = _serializedData.GetDeserialized <SerializableEmployeeIdentifiable>(SerializableType.ChileLotProduction, lotNumber.ToString()); if (deserializedProduction != null) { batch.Production.EmployeeId = deserializedProduction.EmployeeKey.EmployeeKeyId; batch.Production.TimeStamp = deserializedProduction.TimeStamp; } return(false); }); packSchedule.ProductionBatches = productionBatches; return(true); }
private static Dictionary <int, Tuple <DateTime, int> > GetEmployeeIdentifiableByLot(PackScheduleDTO packSchedule) { if (packSchedule == null || string.IsNullOrWhiteSpace(packSchedule.Serialized)) { return(new Dictionary <int, Tuple <DateTime, int> >()); } try { var lotKeyParser = new LotKey(); var employeeKey = new EmployeeKey(); return(SerializablePackSchedule.Deserialize(packSchedule.Serialized).Batches.ToDictionary(b => { var lotKey = lotKeyParser.Parse(b.LotKey); return LotNumberBuilder.BuildLotNumber(lotKey).LotNumber; }, b => new Tuple <DateTime, int>(b.TimeStamp, employeeKey.Parse(b.EmployeeKey).EmployeeKey_Id))); } catch (Exception ex) { throw new Exception("Error parsing PackSchedule deserialized data.", ex); } }