public PackagingResult DeterminePackaging(PackScheduleEntityObjectMother.PackScheduleDTO packSchedule, out int?packageId, out tblPackaging defaultUsed) { defaultUsed = null; var result = _DeterminePackaging(packSchedule, out packageId); if (packageId == null && _packaging != null) { if (_packaging.TryGetValue(result, out defaultUsed)) { packageId = defaultUsed.PkgID; } } return(result); }
public static ProductionLineResult DetermineProductionLine(PackScheduleEntityObjectMother.PackScheduleDTO packSchedule, out int?line) { line = null; if (packSchedule.ProductionLine != null) { line = packSchedule.ProductionLine; return(ProductionLineResult.FromPackSchedule); } var lines = packSchedule.BatchLots.Where(b => b.ProductionLine != null).Select(b => b.ProductionLine).Distinct().ToList(); if (lines.Count == 1) { line = lines.Single(); return(ProductionLineResult.DeterminedFromResultingLots); } if (packSchedule.PackSchDesc != null) { if (packSchedule.PackSchDesc.ToUpper().Contains("LINE #3")) { line = 3; return(ProductionLineResult.DeterminedFromDescription); } } switch (packSchedule.BatchTypeID) { case 2: line = 3; return(ProductionLineResult.DeterminedFromBatchType); case 3: line = 4; return(ProductionLineResult.DeterminedFromBatchType); case 4: line = 5; return(ProductionLineResult.DeterminedFromBatchType); default: return(ProductionLineResult.CouldNotDetermine); } }
private static PackagingResult _DeterminePackaging(PackScheduleEntityObjectMother.PackScheduleDTO packSchedule, out int?packageId) { packageId = null; var pickedPackagingItems = packSchedule.BatchItems.Where(b => b.SourceLot.PTypeID == (int?)LotTypeEnum.Packaging).ToList(); if (pickedPackagingItems.Count == 1) { packageId = pickedPackagingItems.Single().SourceLot.Product.PkgID; return(PackagingResult.FromSinglePickedPackaging); } if (pickedPackagingItems.Count > 1) { packageId = pickedPackagingItems.GroupBy(b => b.SourceLot.Product.Packaging) .OrderByDescending(g => (g.Key.NetWgt ?? 0) * (g.Sum(b => b.Quantity ?? 0))) .First().Key.PkgID; return(PackagingResult.ResolvedFromMultiplePickedPackaging); } var resultingLotIncoming = packSchedule.BatchLots.SelectMany(b => b.Incoming).ToList(); if (resultingLotIncoming.Any()) { packageId = resultingLotIncoming.GroupBy(i => i.PkgID).OrderByDescending(g => g.Sum(i => i.TtlWgt ?? 0)).First().Key; return(PackagingResult.DeterminedFromResultingLotIncoming); } var resultingLotInventory = packSchedule.BatchLots.SelectMany(b => b.Inventory).ToList(); if (resultingLotInventory.Any()) { packageId = resultingLotInventory.GroupBy(i => i.PkgID).OrderByDescending(g => g.Sum(i => i.NetWgt)).First().Key; return(PackagingResult.DeterminedFromResultingLotInventory); } if (!string.IsNullOrWhiteSpace(packSchedule.PackSchDesc)) { var desc = packSchedule.PackSchDesc.ToUpper(); if (desc.Contains("TOTE")) { return(PackagingResult.ToteInDescription); } if (desc.Contains("DRUM")) { return(packSchedule.Product.Mesh == 20 ? PackagingResult.DrumInDescriptionMesh20 : PackagingResult.DrumInDescriptionNotMesh20); } if (desc.Contains("BAG")) { return(PackagingResult.BagInDescription); } if (desc.Contains("BOX")) { return(PackagingResult.BoxInDescription); } if (desc.Contains("RELABEL")) { packageId = PackageIdFromMostInventoryPicked(packSchedule); return(PackagingResult.DeterminedFromRelabelInputsFromDescription); } } if (BatchTypeIDHelper.GetBatchTypeID(packSchedule.BatchTypeID.Value) == BatchTypeID.ReLabel) { packageId = PackageIdFromMostInventoryPicked(packSchedule); return(PackagingResult.DeterminedFromRelabelInputs); } if (BatchTypeIDHelper.GetBatchTypeID(packSchedule.BatchTypeID.Value) == BatchTypeID.Rework) { packageId = PackageIdFromMostInventoryPicked(packSchedule); return(PackagingResult.DeterminedFromReworkInputs); } return(PackagingResult.CouldNotDetermine); }
private static int PackageIdFromMostInventoryPicked(PackScheduleEntityObjectMother.PackScheduleDTO packSchedule) { return(packSchedule.BatchItems.GroupBy(b => b.Packaging) .OrderByDescending(g => (g.Key.NetWgt ?? 0) * g.Sum(b => b.Quantity ?? 0)) .First().Key.PkgID); }