private SerializablePackSchedule(PackSchedule packSchedule) { PkgID = null; var productCode = packSchedule.PackagingProduct.Product.ProductCode; if (!string.IsNullOrEmpty(productCode)) { int result; if (int.TryParse(productCode, out result)) { PkgID = result; } } EmployeeKey = new EmployeeKey(packSchedule); TimeStamp = packSchedule.TimeStamp; TargetParameters = new BatchTargetParameters(packSchedule.DefaultBatchTargetParameters); Batches = packSchedule.ProductionBatches.Select(b => new Batch { LotKey = new LotKey(b), EmployeeKey = new EmployeeKey(b), TimeStamp = b.TimeStamp, TargetParameters = new BatchTargetParameters(b.TargetParameters), PickedInventory = new PickedInventory { EmployeeKey = new EmployeeKey(b.Production.PickedInventory), TimeStamp = b.Production.PickedInventory.TimeStamp } }).ToList(); }
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 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 static double GetAverage(this PackSchedule packSchedule, IAttributeNameKey attributeName) { return(packSchedule.ProductionBatches.SelectMany(b => b.Production.ResultingChileLot.Lot.Attributes).Where(a => a.AttributeShortName == attributeName.AttributeNameKey_ShortName) .Select(a => a.AttributeValue) .DefaultIfEmpty(0.0) .Average()); }
public static WorkTypeKey GetWorkTypeKey(this PackSchedule packSchedule) { if (packSchedule == null) { throw new ArgumentNullException("packSchedule"); } return(new WorkTypeKey(packSchedule)); }
public static ChileProductKey GetChileProductKey(this PackSchedule packSchedule) { if (packSchedule == null) { throw new ArgumentNullException("packSchedule"); } return(new ChileProductKey(packSchedule)); }
public static string BuildChileProductKey(this PackSchedule packSchedule) { if (packSchedule == null) { throw new ArgumentNullException("packSchedule"); } return(new ChileProductKey(packSchedule).ToString()); }
internal static void SetTargetParameters(this PackSchedule packSchedule, double asta, double scan, double scoville, double weight) { if (packSchedule == null) { throw new ArgumentNullException("packSchedule"); } packSchedule.DefaultBatchTargetParameters.BatchTargetWeight = weight; packSchedule.DefaultBatchTargetParameters.BatchTargetAsta = asta; packSchedule.DefaultBatchTargetParameters.BatchTargetScan = scan; packSchedule.DefaultBatchTargetParameters.BatchTargetScoville = scoville; }
internal static PackSchedule SetPackagingProduct(this PackSchedule packSchedule, IPackagingProductKey packagingProductKey) { if (packSchedule == null) { throw new ArgumentNullException("packSchedule"); } packSchedule.PackagingProduct = null; packSchedule.PackagingProductId = packagingProductKey.PackagingProductKey_ProductId; return(packSchedule); }
internal static PackSchedule SetCustomerKey(this PackSchedule packSchedule, ICustomerKey customerKey) { if (packSchedule == null) { throw new ArgumentNullException("packSchedule"); } packSchedule.Customer = null; packSchedule.CustomerId = customerKey == null ? (int?)null : customerKey.CustomerKey_Id; return(packSchedule); }
internal static PackSchedule SetProductionLine(this PackSchedule packSchedule, ILocationKey productionLine) { if (packSchedule == null) { throw new ArgumentNullException("packSchedule"); } packSchedule.ProductionLineLocation = null; packSchedule.ProductionLineLocationId = productionLine.LocationKey_Id; return(packSchedule); }
internal static PackSchedule SetChileProduct(this PackSchedule packSchedule, IChileProductKey chileProductKey) { if (packSchedule == null) { throw new ArgumentNullException("packSchedule"); } packSchedule.ChileProduct = null; packSchedule.ChileProductId = chileProductKey.ChileProductKey_ProductId; return(packSchedule); }
private tblPackSch CreateNewPackSchedule(PackSchedule packSchedule, bool useSuppliedPSNum) { var packSchId = packSchedule.TimeStamp.ConvertLocalToUTC().RoundMillisecondsForSQL(); var tblPackSch = new tblPackSch { SerializedKey = packSchedule.ToPackScheduleKey(), PackSchID = packSchId, PSNum = useSuppliedPSNum && packSchedule.PSNum != null ? packSchedule.PSNum.Value : OldContext.tblPackSches.Select(p => p.PSNum).Where(p => p != null).DefaultIfEmpty(0).Max().Value + 1, PSStatus = 1, SetTrtmtID = 0 }; SynchronizePackScheduleHelper.SynchronizeOldContextPackSchedule(tblPackSch, packSchedule); return(tblPackSch); }
internal static PackSchedule SetWorkType(this PackSchedule packSchedule, IWorkTypeKey workTypeKey) { if (packSchedule == null) { throw new ArgumentNullException("packSchedule"); } if (workTypeKey == null) { throw new ArgumentNullException("workTypeKey"); } packSchedule.WorkType = null; packSchedule.WorkTypeId = workTypeKey.WorkTypeKey_WorkTypeId; return(packSchedule); }
public UpdatePackScheduleParameters(PackSchedule packSchedule) { PackScheduleKey = new PackScheduleKey(packSchedule); BatchTargetWeight = packSchedule.DefaultBatchTargetParameters.BatchTargetWeight; BatchTargetAsta = packSchedule.DefaultBatchTargetParameters.BatchTargetAsta; BatchTargetScan = packSchedule.DefaultBatchTargetParameters.BatchTargetScan; BatchTargetScoville = packSchedule.DefaultBatchTargetParameters.BatchTargetScoville; WorkTypeKey = new WorkTypeKey(packSchedule); ChileProductKey = new WorkTypeKey(packSchedule); PackagingProductKey = new WorkTypeKey(packSchedule); ScheduledProductionDate = packSchedule.ScheduledProductionDate; ProductionDeadline = packSchedule.ProductionDeadline; ProductionLineKey = new LocationKey(packSchedule); SummaryOfWork = packSchedule.SummaryOfWork; CustomerKey = packSchedule.CustomerId == null ? null : new CustomerKey(packSchedule); OrderNumber = packSchedule.OrderNumber; }
internal static void AssertAsExpected(this ICreatePackScheduleParameters parameters, PackSchedule packSchedule) { Assert.AreEqual(parameters.UserToken, packSchedule.Employee.UserName); Assert.AreEqual(parameters.WorkTypeKey, new WorkTypeKey(packSchedule).KeyValue); Assert.AreEqual(parameters.ChileProductKey, new ChileProductKey(packSchedule).KeyValue); Assert.AreEqual(parameters.PackagingProductKey, new PackagingProductKey(packSchedule).KeyValue); Assert.AreEqual(parameters.ProductionLineKey, new LocationKey(packSchedule).KeyValue); Assert.AreEqual(parameters.ScheduledProductionDate, packSchedule.ScheduledProductionDate); Assert.AreEqual(parameters.ProductionDeadline, packSchedule.ProductionDeadline); Assert.AreEqual(parameters.SummaryOfWork, packSchedule.SummaryOfWork); if (parameters.CustomerKey == null) { Assert.IsNull(packSchedule.CustomerId); Assert.IsNull(packSchedule.Customer); } else { Assert.AreEqual(parameters.CustomerKey, new CustomerKey(packSchedule).KeyValue); } Assert.AreEqual(parameters.OrderNumber, packSchedule.OrderNumber); parameters.AssertAsExpected(packSchedule.DefaultBatchTargetParameters); }
public static void SynchronizeOldContextPackSchedule(tblPackSch oldPackSchedule, PackSchedule newPackSchedule) { int chileProdId; if (!Int32.TryParse(newPackSchedule.ChileProduct.Product.ProductCode, out chileProdId)) { throw new Exception(String.Format("Could not parse chile ProdID[{0}]", newPackSchedule.ChileProduct.Product.ProductCode)); } oldPackSchedule.EmployeeID = newPackSchedule.EmployeeId; oldPackSchedule.ProductionDeadline = newPackSchedule.ProductionDeadline.GetDate(); oldPackSchedule.PackSchDate = newPackSchedule.ScheduledProductionDate.Date; oldPackSchedule.ProdID = chileProdId; oldPackSchedule.PackSchDesc = newPackSchedule.SummaryOfWork; oldPackSchedule.BatchTypeID = (int?)BatchTypeIDHelper.GetBatchTypeID(newPackSchedule.WorkType.Description); oldPackSchedule.ProductionLine = GetProductionLine(newPackSchedule.ProductionLineLocation.Description); oldPackSchedule.TargetWgt = (decimal?)newPackSchedule.DefaultBatchTargetParameters.BatchTargetWeight; oldPackSchedule.TgtAsta = (decimal?)newPackSchedule.DefaultBatchTargetParameters.BatchTargetAsta; oldPackSchedule.TgtScan = (decimal?)newPackSchedule.DefaultBatchTargetParameters.BatchTargetScan; oldPackSchedule.TgtScov = (decimal?)newPackSchedule.DefaultBatchTargetParameters.BatchTargetScoville; oldPackSchedule.OrderNumber = newPackSchedule.OrderNumber; oldPackSchedule.Company_IA = newPackSchedule.Customer == null ? null : newPackSchedule.Customer.Company.Name; if (oldPackSchedule.tblLots != null) { foreach (var lot in oldPackSchedule.tblLots) { lot.ProdID = oldPackSchedule.ProdID; lot.ProductionDate = oldPackSchedule.PackSchDate; lot.BatchTypeID = oldPackSchedule.BatchTypeID; lot.Company_IA = oldPackSchedule.Company_IA; lot.ProductionLine = oldPackSchedule.ProductionLine; } } oldPackSchedule.Serialized = SerializablePackSchedule.Serialize(newPackSchedule); }
internal static void AssertAsExpected(this IUpdatePackScheduleParameters parameters, PackSchedule packSchedule) { ((ICreatePackScheduleParameters)parameters).AssertAsExpected(packSchedule); }
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 ChileLotProduction CreateChileLotProduction(LotKey lotKey, ProductionBatchDTO oldBatch, PackSchedule newPackSchedule, DateTime timeStamp, int employeeId) { _loadCount.AddRead(EntityTypes.ChileLotProduction); var chileLot = _newContextHelper.GetChileLot(lotKey); if (chileLot == null) { Log(new CallbackParameters(CallbackReason.OutputChileLotNotLoaded) { Batch = oldBatch }); return(null); } var pickedInventory = CreateNewPickedInventory(oldBatch); LotProductionResults productionResults; _productionResultHelper.CreateNewProductionResult(newPackSchedule, chileLot, oldBatch.ResultLot, out productionResults); if (productionResults != null) { _loadCount.AddRead(EntityTypes.LotProductionResults); productionResults.ResultItems = _productionResultHelper.CreateNewProductionResultItems(productionResults, oldBatch.ResultLot) .Where(r => { _loadCount.AddRead(EntityTypes.LotProductionResultItem); return(r.Result == ProductionResultHelper.CreateNewProductionResultItemResult.Success); }) .Select(i => i.ResultItem).ToList(); } var deserializedProduction = _serializedData.GetDeserialized <SerializableEmployeeIdentifiable>(SerializableType.ChileLotProduction, oldBatch.ResultLot.Lot.ToString()); pickedInventory.Archived = productionResults != null; return(new ChileLotProduction { TimeStamp = deserializedProduction == null ? timeStamp : deserializedProduction.TimeStamp, EmployeeId = deserializedProduction == null ? employeeId : deserializedProduction.EmployeeKey.EmployeeKeyId, LotDateCreated = chileLot.LotDateCreated, LotDateSequence = chileLot.LotDateSequence, LotTypeId = chileLot.LotTypeId, PickedInventoryDateCreated = pickedInventory.DateCreated, PickedInventorySequence = pickedInventory.Sequence, ProductionType = ProductionType.ProductionBatch, PickedInventory = pickedInventory, Results = productionResults }); }
public static bool DeserializeIntoPackSchedule(PackSchedule packSchedule, string serializedPackSchedule, out int?pkgID) { pkgID = null; var deserialized = Deserialize(serializedPackSchedule); if (deserialized == null) { return(false); } var employeeKeyParser = new EmployeeKey(); var lotKeyParser = new LotKey(); pkgID = deserialized.PkgID; IEmployeeKey employeeKey; if (employeeKeyParser.TryParse(deserialized.EmployeeKey, out employeeKey)) { packSchedule.EmployeeId = employeeKey.EmployeeKey_Id; } packSchedule.TimeStamp = deserialized.TimeStamp; packSchedule.DefaultBatchTargetParameters = new ProductionBatchTargetParameters(deserialized.TargetParameters); packSchedule.ProductionBatches = deserialized.Batches.Select(b => { var lotKey = lotKeyParser.Parse(b.LotKey); var batchEmployeeKey = employeeKeyParser.Parse(b.EmployeeKey); var pickedEmployeeKey = employeeKeyParser.Parse(b.PickedInventory.EmployeeKey); var productionBatch = new ProductionBatch { EmployeeId = batchEmployeeKey.EmployeeKey_Id, TimeStamp = b.TimeStamp, LotDateCreated = lotKey.LotKey_DateCreated, LotDateSequence = lotKey.LotKey_DateSequence, LotTypeId = lotKey.LotKey_LotTypeId, PackScheduleDateCreated = packSchedule.DateCreated, PackScheduleSequence = packSchedule.SequentialNumber, ProductionHasBeenCompleted = false, TargetParameters = new ProductionBatchTargetParameters(b.TargetParameters), Production = new ChileLotProduction { EmployeeId = batchEmployeeKey.EmployeeKey_Id, TimeStamp = b.TimeStamp, LotDateCreated = lotKey.LotKey_DateCreated, LotDateSequence = lotKey.LotKey_DateSequence, LotTypeId = lotKey.LotKey_LotTypeId, ProductionType = ProductionType.ProductionBatch, PickedInventory = new Models.PickedInventory { EmployeeId = pickedEmployeeKey.EmployeeKey_Id, TimeStamp = b.PickedInventory.TimeStamp, PickedReason = PickedReason.Production, Archived = false, Items = new List <PickedInventoryItem>() } } }; return(productionBatch); }).ToList(); return(true); }
public static string Serialize(PackSchedule packSchedule) { return(JsonConvert.SerializeObject(new SerializablePackSchedule(packSchedule), Formatting.None)); }