Example #1
0
        private tblLot GetOrCreateLot(ChileLotProduction production, out bool newLot)
        {
            newLot = false;
            var lotNumber = LotNumberBuilder.BuildLotNumber(production);
            var tblLot    = OldContext.tblLots
                            .Include(l => l.tblIncomings, l => l.tblOutgoings)
                            .FirstOrDefault(l => l.Lot == lotNumber);

            if (tblLot == null)
            {
                tblLot = new tblLot
                {
                    Lot        = lotNumber,
                    EmployeeID = production.ResultingChileLot.Lot.EmployeeId,
                    EntryDate  = production.ResultingChileLot.Lot.TimeStamp.ConvertUTCToLocal().RoundMillisecondsForSQL(),

                    PTypeID  = production.LotTypeId,
                    Julian   = lotNumber.Julian,
                    BatchNum = production.LotDateSequence,

                    Shift             = production.Results.ShiftKey,
                    Notes             = "Old Context Synchronization",
                    BatchProdctnOrder = 0,
                    SetTrtmtID        = 0,
                    BatchStatID       = (int?)BatchStatID.Produced,
                    TargetWgt         = 0, //looks like default value set in old context - RI 2014/2/17,
                    tblOutgoings      = new EntityCollection <tblOutgoing>(),
                    tblIncomings      = new EntityCollection <tblIncoming>()
                };
                OldContext.tblLots.AddObject(tblLot);
                newLot = true;
            }

            var product        = OldContextHelper.GetProduct(production.ResultingChileLot.ChileProduct);
            var productionLine = OldContextHelper.GetProductionLine(production.Results.ProductionLineLocation).Value;
            var productionDate = production.LotDateCreated.Date;
            var batchBegTime   = production.Results.ProductionBegin.ConvertUTCToLocal().RoundMillisecondsForSQL();
            var batchEndTime   = production.Results.ProductionEnd.ConvertUTCToLocal().RoundMillisecondsForSQL();

            tblLot.ProdID         = product.ProdID;
            tblLot.ProductionLine = productionLine;
            tblLot.BatchBegTime   = batchBegTime;
            tblLot.BatchEndTime   = batchEndTime;
            tblLot.ProductionDate = productionDate;
            tblLot.Produced       = productionDate;

            return(tblLot);
        }
        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,
            });
        }