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);
        }
        private tblLot CreateNewLot(LotNumberResult lotNumber, ProductionBatch productionBatch)
        {
            var chileProduct   = OldContextHelper.GetProduct(productionBatch.PackSchedule.ChileProduct);
            var productionLine = OldContextHelper.GetProductionLine(productionBatch.PackSchedule.ProductionLineLocation);
            var batchTypeId    = BatchTypeIDHelper.GetBatchTypeID(productionBatch.PackSchedule.WorkType.Description);

            return(new tblLot
            {
                Lot = lotNumber,
                EmployeeID = productionBatch.Production.ResultingChileLot.Lot.EmployeeId,
                EntryDate = productionBatch.Production.ResultingChileLot.Lot.TimeStamp.ConvertUTCToLocal().RoundMillisecondsForSQL(),

                Notes = productionBatch.Production.ResultingChileLot.Lot.Notes,

                PTypeID = productionBatch.LotTypeId,
                Julian = lotNumber.Julian,
                BatchNum = productionBatch.LotDateSequence,
                ProdID = chileProduct.ProdID,

                PackSchID = productionBatch.PackSchedule.PackSchID,
                BatchTypeID = (int?)batchTypeId,
                Company_IA = productionBatch.PackSchedule.Customer == null ? null : productionBatch.PackSchedule.Customer.Company.Name,

                ProductionDate = productionBatch.PackSchedule.ScheduledProductionDate,
                ProductionLine = productionLine,
                BatchProdctnOrder = 0,     //Seems constant in old context - RI 2014/4/16

                SetTrtmtID = 0,
                LotStat = 0,
                BatchStatID = (int?)BatchStatID.Scheduled,
                TargetWgt = (decimal?)productionBatch.TargetParameters.BatchTargetWeight,
                TgtAsta = (decimal?)productionBatch.TargetParameters.BatchTargetAsta,
                TgtScan = (decimal?)productionBatch.TargetParameters.BatchTargetScan,
                TgtScov = (decimal?)productionBatch.TargetParameters.BatchTargetScoville,
            });
        }
예제 #3
0
        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);
        }