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 }); }
private PickedInventory CreateNewPickedInventory(ProductionBatchDTO batch) { _loadCount.AddRead(EntityTypes.PickedInventory); var dateCreated = batch.BatchItems.Min(b => b.EntryDate.Date); var sequence = PickedInventoryKeyHelper.Singleton.GetNextSequence(dateCreated); var latest = batch.BatchItems.OrderByDescending(b => b.EntryDate).First(); var pickedInventory = new PickedInventory { DateCreated = dateCreated, Sequence = sequence, EmployeeId = latest.EmployeeID.Value, TimeStamp = latest.EntryDate.ConvertLocalToUTC(), Archived = false, PickedReason = PickedReason.Production }; pickedInventory.Items = CreatePickedInventoryItems(pickedInventory, batch.BatchItems).ToList(); return(pickedInventory); }