Beispiel #1
0
        private void SetOutgoingRecords(tblLot tblLot, ChileLotProduction production)
        {
            foreach (var previousInput in OldContext.tblOutgoings.Where(o => o.NewLot == tblLot.Lot).ToList())
            {
                OldContext.tblOutgoings.DeleteObject(previousInput);
            }

            foreach (var item in production.PickedInventory.Items)
            {
                var sourceLotNumber = LotNumberBuilder.BuildLotNumber(item);
                var packaging       = OldContextHelper.GetPackaging(item.PackagingProduct);

                OldContext.tblOutgoings.AddObject(new tblOutgoing
                {
                    EmployeeID = tblLot.EmployeeID,
                    EntryDate  = DateTime.UtcNow.ConvertUTCToLocal().RoundMillisecondsForSQL(),

                    Lot     = sourceLotNumber,
                    NewLot  = tblLot.Lot,
                    TTypeID = (int?)TransType.DeHy,

                    PkgID    = packaging.PkgID,
                    Tote     = item.ToteKey,
                    Quantity = item.Quantity,
                    NetWgt   = packaging.NetWgt,
                    TtlWgt   = item.Quantity * packaging.NetWgt,
                    LocID    = item.FromLocation.LocID.Value,
                    TrtmtID  = 0
                });
            }
        }
Beispiel #2
0
        private void AddOutgoingRecords(tblAdjust adjustment, IEnumerable <InventoryAdjustmentItem> items)
        {
            foreach (var item in items)
            {
                var lotNumber = LotNumberBuilder.BuildLotNumber(item);
                var location  = OldContextHelper.GetLocation(item.Location);
                var treatment = OldContextHelper.GetTreatment(item.Treatment);

                var packaging = item.PackagingProduct;
                if (item.Lot.PackagingLot != null)
                {
                    packaging = item.Lot.PackagingLot.PackagingProduct;
                }
                var tblPackaging = OldContextHelper.GetPackaging(packaging);

                var outgoing = new tblOutgoing
                {
                    AdjustID   = adjustment.AdjustID,
                    EmployeeID = adjustment.EmployeeID,
                    EntryDate  = DateTime.UtcNow.ConvertUTCToLocal().RoundMillisecondsForSQL(),

                    Lot      = lotNumber,
                    TTypeID  = (int?)TransType.InvAdj,
                    PkgID    = tblPackaging.PkgID,
                    Tote     = item.ToteKey,
                    Quantity = -item.QuantityAdjustment,
                    NetWgt   = tblPackaging.NetWgt,
                    TtlWgt   = -item.QuantityAdjustment * tblPackaging.NetWgt,
                    LocID    = location.LocID,
                    TrtmtID  = treatment.TrtmtID
                };
                adjustment.tblOutgoings.Add(outgoing);
            }
        }
Beispiel #3
0
            public void Will_create_new_tblLotHistory_record_if_setting_lot_hold_status_results_in_a_LotStat_change()
            {
                //Arrange
                var chileLot = RVCUnitOfWork.ChileLotRepository.Filter(c => c.Lot.Hold == null && c.Lot.QualityStatus == LotQualityStatus.Released).FirstOrDefault();

                if (chileLot == null)
                {
                    throw new Exception("Could not find Accepted ChileLot without hold.");
                }
                var lotNumber = LotNumberBuilder.BuildLotNumber(chileLot);
                var expectedLotAttributeHistories = new RioAccessSQLEntities().tblLotAttributeHistories.Count(h => h.Lot == lotNumber) + 1;

                //Act
                var result = Service.SetLotHoldStatus(new SetLotHoldStatusParameters
                {
                    UserToken = TestUser.UserName,
                    LotKey    = chileLot.ToLotKey(),
                    Hold      = new LotHold
                    {
                        HoldType    = LotHoldType.HoldForCustomer,
                        Description = "HOLDIT!"
                    }
                });
                var lotString = GetKeyFromConsoleString(ConsoleOutput.UpdatedLot);

                //Assert
                result.AssertSuccess();
                MockKillSwitch.Verify(k => k.Engage(), Times.Never());

                Assert.AreEqual(lotNumber, int.Parse(lotString));
                Assert.AreEqual(expectedLotAttributeHistories, new RioAccessSQLEntities().tblLotAttributeHistories.Count(h => h.Lot == lotNumber));
            }
Beispiel #4
0
        public override void Synchronize(Func <NotebookKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }

            var notebookKey = getInput();
            var notebook    = UnitOfWork.NotebookRepository.FindByKey(notebookKey, n => n.Notes);

            if (notebook == null)
            {
                throw new Exception(string.Format("Notebook[{0}] not found.", notebookKey));
            }

            var productionBatch = UnitOfWork.ProductionBatchRepository.Filter(b => b.InstructionNotebookDateCreated == notebook.Date && b.InstructionNotebookSequence == notebook.Sequence).FirstOrDefault();

            if (productionBatch != null)
            {
                var lotNumber = LotNumberBuilder.BuildLotNumber(productionBatch);
                new SyncTblBatchInstr(OldContext).Synchronize(notebook, lotNumber);
                OldContext.SaveChanges();

                Console.WriteLine(ConsoleOutput.UpdatedBatchInstructions, lotNumber);
                return;
            }

            var contract = UnitOfWork.ContractRepository.GetContractForSynch(notebookKey);

            if (contract != null)
            {
                new SyncContract(UnitOfWork).Synchronize(contract, false);
            }
        }
Beispiel #5
0
        public override void Synchronize(Func <LotKey> getInput)
        {
            var lotNumber = LotNumberBuilder.BuildLotNumber(getInput());

            new DeleteTblLotHelper(OldContext).DeleteLots(lotNumber);
            OldContext.SaveChanges();
            Console.WriteLine(ConsoleOutput.DeletedTblLot, lotNumber);
        }
        public override void Synchronize(Func <LotKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }
            var productionBatchKey = getInput();

            var productionBatch = UnitOfWork.ProductionBatchRepository.FindByKey(productionBatchKey,
                                                                                 b => b.Production.Results,
                                                                                 b => b.Production.ResultingChileLot.Lot,
                                                                                 b => b.PackSchedule.PackagingProduct.Product,
                                                                                 b => b.PackSchedule.ChileProduct.Product,
                                                                                 b => b.PackSchedule.ProductionLineLocation,
                                                                                 b => b.PackSchedule.ProductionBatches.Select(p => p.Production.PickedInventory));

            if (productionBatch == null)
            {
                throw new Exception(string.Format("ProductionBatch[{0}] not found.", productionBatchKey));
            }

            var lotNumber = LotNumberBuilder.BuildLotNumber(productionBatch);
            var lot       = OldContext.tblLots.FirstOrDefault(l => l.Lot == lotNumber);

            if (lot == null)
            {
                throw new Exception(string.Format("tblLot[{0}] not found.", lotNumber));
            }
            UpdateLot(lot, productionBatch);

            var oldPackSchedule = OldContext.tblPackSches.FirstOrDefault(p => p.PackSchID == productionBatch.PackSchedule.PackSchID);

            if (oldPackSchedule == null)
            {
                throw new Exception(string.Format("tblPackSch[{0}] could not be found.", productionBatch.PackSchedule.PackSchID));
            }
            oldPackSchedule.Serialized = SerializablePackSchedule.Serialize(productionBatch.PackSchedule);

            var serialized = new SerializedData(OldContext);

            serialized[SerializableType.ChileLotProduction, lotNumber] = new SerializableEmployeeIdentifiable(productionBatch.Production);
            if (productionBatch.Production.Results != null)
            {
                serialized[SerializableType.LotProductionResults, lotNumber] = new SerializableEmployeeIdentifiable(productionBatch.Production.Results);
            }

            OldContext.SaveChanges();

            Console.Write(ConsoleOutput.UpdatedLot, lot.Lot);
        }
Beispiel #7
0
        public void UpdateOldLotAttributes(ILotKey lotKey, List <LotAttribute> newLotAttributes)
        {
            var lotNumber = LotNumberBuilder.BuildLotNumber(lotKey);
            var oldLot    = _oldContext.tblLots
                            .Include(l => l.tblLotAttributeHistory)
                            .FirstOrDefault(l => l.Lot == lotNumber);

            if (oldLot == null)
            {
                throw new Exception(string.Format("Could not find tblLot[{0}]", lotNumber));
            }

            SyncProductionBatchPickedInventoryHelper.SetLotBatchAttributes(oldLot, newLotAttributes);
            LotSyncHelper.SetLotAttributes(oldLot, newLotAttributes);
        }
Beispiel #8
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);
        }
        public static tblLot GetLot(this RioAccessSQLEntities oldContext, ILotKey lotKey, bool throwIfNotFound = true)
        {
            var lotNumber = LotNumberBuilder.BuildLotNumber(lotKey);
            var oldLot    = oldContext.tblLots.Where(l => l.Lot == lotNumber).Select(l => new
            {
                lot = l,
                l.tblLotAttributeHistory
            }).FirstOrDefault();

            if (oldLot == null && throwIfNotFound)
            {
                throw new Exception(string.Format("Lot[{0}] not found in old context.", lotNumber));
            }

            return(oldLot == null ? null : oldLot.lot);
        }
Beispiel #10
0
        public override void Synchronize(Func <LotKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }
            var lotKey = getInput();

            var productionBatch = UnitOfWork.ProductionBatchRepository.FindByKey(lotKey,
                                                                                 b => b.PackSchedule.WorkType,
                                                                                 b => b.Production.PickedInventory.Items.Select(i => i.PackagingProduct.Product),
                                                                                 b => b.Production.PickedInventory.Items.Select(i => i.FromLocation),
                                                                                 b => b.Production.PickedInventory.Items.Select(i => i.Lot.Attributes),
                                                                                 b => b.Production.PickedInventory.Items.Select(i => i.Lot.PackagingLot.PackagingProduct.Product),
                                                                                 b => b.Production.ResultingChileLot.Lot.Attributes.Select(a => a.AttributeName),
                                                                                 b => b.Production.ResultingChileLot.ChileProduct.Ingredients.Select(i => i.AdditiveType),
                                                                                 b => b.Production.Results.ProductionLineLocation,
                                                                                 b => b.Production.Results.ResultItems.Select(i => i.PackagingProduct.Product),
                                                                                 b => b.Production.Results.ResultItems.Select(i => i.Location));

            var lotNumber = LotNumberBuilder.BuildLotNumber(lotKey);
            var lotSelect = OldContext.tblLots
                            .Where(l => l.Lot == lotNumber)
                            .Select(l => new
            {
                Lot = l,
                l.inputBatchItems,
                l.tblOutgoingInputs,
                l.tblBOMs,
                l.tblIncomings,
                l.tblLotAttributeHistory
            })
                            .FirstOrDefault();

            if (lotSelect == null)
            {
                throw new Exception(string.Format("Lot[{0}] not found in old context.", lotNumber));
            }

            new SyncProductionBatchPickedInventoryHelper(UnitOfWork, OldContext).SetBOMBatchItems(productionBatch, lotSelect.Lot);
            new SyncProductionResultsHelper(OldContextHelper).SetResults(productionBatch, lotSelect.Lot);

            OldContext.SaveChanges();
            Console.Write(ConsoleOutput.SyncProductionResults, lotNumber);
        }
Beispiel #11
0
            public void Will_not_create_new_tblLotHistory_record_if_new_defect_does_not_result_in_a_LotStat_change()
            {
                //Arrange
                ChileLot chileLot;

                using (var oldContext = new RioAccessSQLEntities())
                {
                    chileLot = oldContext.tblLots
                               .Where(l => l.LotStat == (int)LotStat.See_Desc)
                               .Select(l => l.Lot)
                               .ToList()
                               .Select(l =>
                    {
                        var lotKey = LotNumberParser.ParseLotNumber(l);
                        var lot    = RVCUnitOfWork.ChileLotRepository.FindByKey(lotKey, c => c.Lot.LotDefects.Select(d => d.Resolution));
                        return(lot.Lot.QualityStatus == LotQualityStatus.Released ? lot : null);
                    })
                               .FirstOrDefault(c => c != null);
                }

                if (chileLot == null)
                {
                    throw new Exception("Could not find test ChileLot.");
                }
                var lotNumber = LotNumberBuilder.BuildLotNumber(chileLot);
                var expectedLotAttributeHistories = new RioAccessSQLEntities().tblLotAttributeHistories.Count(h => h.Lot == lotNumber);

                //Act
                var result = Service.CreateLotDefect(new CreateLotDefectParameters
                {
                    UserToken   = TestUser.UserName,
                    LotKey      = chileLot.ToLotKey(),
                    DefectType  = DefectTypeEnum.InHouseContamination,
                    Description = "unmapped defect"
                });
                var lotString = GetKeyFromConsoleString(ConsoleOutput.UpdatedLot);

                //Assert
                result.AssertSuccess();
                MockKillSwitch.Verify(k => k.Engage(), Times.Never());

                Assert.AreEqual(lotNumber, int.Parse(lotString));
                Assert.AreEqual(expectedLotAttributeHistories, new RioAccessSQLEntities().tblLotAttributeHistories.Count(h => h.Lot == lotNumber));
            }
Beispiel #12
0
        private tblLot GetOrCreateLot(Lot lot)
        {
            var oldLot = _oldContext.GetLot(lot, false);

            if (oldLot == null)
            {
                var        lotNumber = LotNumberBuilder.BuildLotNumber(lot);
                tblProduct product   = null;
                switch (lot.LotTypeEnum.ToProductType())
                {
                case ProductTypeEnum.Additive:
                    var additiveProduct = _unitOfWork.AdditiveProductRepository.FindByKey(lot.AdditiveLot.ToAdditiveProductKey(), p => p.Product);
                    product = _oldContextHelper.GetProduct(additiveProduct.Product.ProductCode);
                    break;

                case ProductTypeEnum.Chile:
                    var chileProduct = _unitOfWork.ChileProductRepository.FindByKey(lot.ChileLot.ToChileProductKey(), p => p.Product);
                    product = _oldContextHelper.GetProduct(chileProduct.Product.ProductCode);
                    break;

                case ProductTypeEnum.Packaging:
                    var packagingProduct = _unitOfWork.PackagingProductRepository.FindByKey(lot.PackagingLot.ToPackagingProductKey(), p => p.Product);
                    product = GetOrCreatePackagingProduct(packagingProduct, lot, lot.TimeStamp);
                    break;
                }

                oldLot = new tblLot
                {
                    Lot        = lotNumber,
                    EmployeeID = lot.EmployeeId,
                    EntryDate  = DateTime.UtcNow.ConvertUTCToLocal().RoundMillisecondsForSQL(),

                    PTypeID   = lot.LotTypeId,
                    ProdID    = product.ProdID,
                    Julian    = lotNumber.Julian,
                    TargetWgt = 0,
                    Notes     = "Old Context Synchronization"
                };

                _oldContext.tblLots.AddObject(oldLot);
            }

            return(oldLot);
        }
Beispiel #13
0
            public void Set_LotAttributes_for_AdditiveLot()
            {
                //Arrange
                var additiveLot = RVCUnitOfWork.AdditiveLotRepository.Filter(l => true, l => l.Lot.Attributes)
                                  .OrderByDescending(a => a.LotDateCreated).FirstOrDefault();

                if (additiveLot == null)
                {
                    Assert.Inconclusive("AdditiveLot for testing not found.");
                }
                var expectedScan = additiveLot.Lot.Attributes.Where(a => a.AttributeShortName == StaticAttributeNames.Scan.ShortName).Select(a => a.AttributeValue).DefaultIfEmpty(0).Max() + 1;

                //Act
                var result = Service.SetLotAttributes(new SetLotAttributeParameters
                {
                    UserToken  = TestUser.UserName,
                    LotKey     = additiveLot.ToLotKey(),
                    Attributes = new Dictionary <string, IAttributeValueParameters>
                    {
                        {
                            StaticAttributeNames.Scan.ToAttributeNameKey(), new AttributeValueParameters
                            {
                                AttributeInfo = new AttributeInfoParameters
                                {
                                    Value = expectedScan,
                                    Date  = additiveLot.LotDateCreated.AddDays(1)
                                }
                            }
                        }
                    }
                });

                //Assert
                result.AssertSuccess();
                using (var oldContext = new RioAccessSQLEntities())
                {
                    var lotNumber = LotNumberBuilder.BuildLotNumber(additiveLot);
                    var lot       = oldContext.tblLots.FirstOrDefault(l => l.Lot == lotNumber);
                    Assert.AreEqual(expectedScan, lot.Scan);
                }
            }
Beispiel #14
0
        public override void Synchronize(Func <LotKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }
            var lotNumber = LotNumberBuilder.BuildLotNumber(getInput());

            var tblLot = OldContext.tblLots
                         .Include
                         (
                l => l.inputBatchItems,
                l => l.tblBatchInstr,
                l => l.tblBOMs,
                l => l.tblLotAttributeHistory,
                l => l.tblIncomings,
                l => l.tblOutgoingInputs,
                l => l.tblPackSch
                         )
                         .FirstOrDefault(l => l.Lot == lotNumber);

            if (tblLot == null)
            {
                throw new Exception(string.Format("tblLot[{0}] not found.", lotNumber));
            }

            if (tblLot.tblPackSch == null)
            {
                throw new Exception(string.Format("tblPackSch record for tblLot[{0}] not found.", lotNumber));
            }

            var newPackSchedule = UnitOfWork.PackScheduleRepository.SelectPackScheduleForSynch(new PackSchIdKey(tblLot.tblPackSch.PackSchID));

            SynchronizePackScheduleHelper.SynchronizeOldContextPackSchedule(tblLot.tblPackSch, newPackSchedule);

            new DeleteTblLotHelper(OldContext).DeleteLot(tblLot);

            OldContext.SaveChanges();

            Console.WriteLine(ConsoleOutput.RemovedProductionBatch, lotNumber);
        }
            private ProductionBatch GetUnfinishedBatch()
            {
                ProductionBatch unfinishedBatch;

                using (var oldContext = new RioAccessSQLEntities())
                {
                    unfinishedBatch = RVCUnitOfWork.ProductionBatchRepository
                                      .Filter(b => b.Production.Results == null)
                                      .ToList()
                                      .FirstOrDefault(b =>
                    {
                        var lot = LotNumberBuilder.BuildLotNumber(b);
                        return(!oldContext.tblLots.Any(l => l.Lot == lot));
                    });
                }
                if (unfinishedBatch == null)
                {
                    Assert.Inconclusive("No ProductionBatch with null Results found.");
                }
                return(unfinishedBatch);
            }
        private tblIncoming CreateIncoming(LotProductionResultItem resultItem)
        {
            var entryDate = resultItem.ProductionResults.DateTimeEntered.ConvertUTCToLocal().RoundMillisecondsForSQL();
            var packaging = _oldContextHelper.GetPackaging(resultItem.PackagingProduct);
            var location  = _oldContextHelper.GetLocation(resultItem.Location);

            return(new tblIncoming
            {
                EntryDate = entryDate,
                Lot = LotNumberBuilder.BuildLotNumber(resultItem),
                TTypeID = (int?)TransType.Production,
                PkgID = packaging.PkgID,
                VarietyID = 0,
                Quantity = resultItem.Quantity,
                NetWgt = packaging.NetWgt,
                TtlWgt = packaging.NetWgt * resultItem.Quantity,
                LocID = location.LocID,
                TrtmtID = resultItem.TreatmentId,
                EmployeeID = resultItem.ProductionResults.EmployeeId
            });
        }
Beispiel #17
0
        private static Dictionary <int, Tuple <DateTime, int> > GetEmployeeIdentifiableByLot(PackScheduleDTO packSchedule)
        {
            if (packSchedule == null || string.IsNullOrWhiteSpace(packSchedule.Serialized))
            {
                return(new Dictionary <int, Tuple <DateTime, int> >());
            }

            try
            {
                var lotKeyParser = new LotKey();
                var employeeKey  = new EmployeeKey();
                return(SerializablePackSchedule.Deserialize(packSchedule.Serialized).Batches.ToDictionary(b =>
                {
                    var lotKey = lotKeyParser.Parse(b.LotKey);
                    return LotNumberBuilder.BuildLotNumber(lotKey).LotNumber;
                }, b => new Tuple <DateTime, int>(b.TimeStamp, employeeKey.Parse(b.EmployeeKey).EmployeeKey_Id)));
            }
            catch (Exception ex)
            {
                throw new Exception("Error parsing PackSchedule deserialized data.", ex);
            }
        }
Beispiel #18
0
            public void Will_create_new_tblLotHistory_record_if_new_defect_results_in_a_LotStat_change()
            {
                //Arrange
                var attributeLotStats   = StaticAttributeNames.GetAttributesWithAssociatedLotStats().Select(a => a.AttributeNameKey_ShortName).ToArray();
                var lotAttributeDefects = RVCUnitOfWork.LotAttributeDefectRepository.All();
                var chileLot            = RVCUnitOfWork.ChileLotRepository.Filter(c =>
                                                                                  c.Lot.Hold == null &&
                                                                                  c.Lot.QualityStatus == LotQualityStatus.Released &&
                                                                                  c.Lot.ProductSpecOutOfRange &&
                                                                                  lotAttributeDefects.Where(d => d.LotDateCreated == c.LotDateCreated && d.LotDateSequence == c.LotDateSequence && d.LotTypeId == c.LotTypeId && d.LotDefect.Resolution == null)
                                                                                  .All(d => attributeLotStats.All(a => a != d.AttributeShortName))
                                                                                  ).FirstOrDefault();

                if (chileLot == null)
                {
                    Assert.Inconclusive("Could not find ChileLot valid for testing.");
                }
                var lotNumber = LotNumberBuilder.BuildLotNumber(chileLot);
                var expectedLotAttributeHistories = new RioAccessSQLEntities().tblLotAttributeHistories.Count(h => h.Lot == lotNumber) + 1;

                //Act
                var result = Service.CreateLotDefect(new CreateLotDefectParameters
                {
                    UserToken   = TestUser.UserName,
                    LotKey      = new LotKey(chileLot),
                    DefectType  = DefectTypeEnum.InHouseContamination,
                    Description = "dark specs"
                });
                var lotString = GetKeyFromConsoleString(ConsoleOutput.UpdatedLot);

                //Assert
                result.AssertSuccess();
                MockKillSwitch.Verify(k => k.Engage(), Times.Never());
                Assert.AreEqual(lotNumber, int.Parse(lotString));
                Assert.AreEqual(expectedLotAttributeHistories, new RioAccessSQLEntities().tblLotAttributeHistories.Count(h => h.Lot == lotNumber));
            }
Beispiel #19
0
        private tblLot SyncDehydratedReceived(ChileMaterialsReceived received)
        {
            var lotNumber = LotNumberBuilder.BuildLotNumber(received);
            var product   = OldContextHelper.GetProduct(received.ChileProduct);

            var oldLot = OldContextHelper.OldContext.tblLots
                         .Include(l => l.tblIncomings)
                         .FirstOrDefault(l => l.Lot == lotNumber.LotNumber)
                         ?? AddNewLot(received, lotNumber);

            oldLot.ProdID         = product.ProdID;
            oldLot.LoadNum        = received.LoadNumber;
            oldLot.Company_IA     = received.Supplier.Name;
            oldLot.PurchOrder     = received.ChileLot.Lot.PurchaseOrderNumber;
            oldLot.ShipperNum     = received.ChileLot.Lot.ShipperNumber;
            oldLot.ProductionDate = received.DateReceived;
            oldLot.Produced       = received.DateReceived;
            oldLot.Pellets        = received.ChileMaterialsReceivedType == ChileMaterialsReceivedType.Other;

            var varieties = OldContextHelper.OldContext.tblVarieties.ToList();

            SyncIncomingRecords(received, oldLot, varieties);
            return(oldLot);
        }
            public void Deletes_tblLot_and_associated_records()
            {
                //Arrange
                var productionDate = new DateTime(2020, 3, 29);
                int?newSequence    = null;

                while (newSequence == null)
                {
                    var existingLots = RVCUnitOfWork.ChileLotRepository.Filter(l => l.LotDateCreated == productionDate && l.LotTypeId == (int)LotTypeEnum.WIP);
                    var sequence     = existingLots.Select(l => l.LotDateSequence).DefaultIfEmpty(0).Max();
                    if (sequence < 99)
                    {
                        newSequence = sequence + 1;
                    }
                    else
                    {
                        productionDate = productionDate.AddDays(1);
                    }
                }

                const int pickedQuantity    = 10;
                var       chileProduct      = RVCUnitOfWork.ChileProductRepository.Filter(c => c.ChileState == ChileStateEnum.WIP).First();
                var       productionLine    = RVCUnitOfWork.LocationRepository.Filter(l => l.LocationType == LocationType.ProductionLine).First();
                var       pickedInventory   = RVCUnitOfWork.InventoryRepository.Filter(i => i.Lot.Hold == null && i.Lot.QualityStatus == LotQualityStatus.Released && i.Quantity > pickedQuantity && i.Location.Facility.Name.Contains("rincon")).First();
                var       warehouseLocation = RVCUnitOfWork.LocationRepository.Filter(l => l.LocID != null).First();
                var       packagingProduct  = RVCUnitOfWork.PackScheduleRepository.All().First();

                var createResult = Service.CreateMillAndWetdown(new CreateMillAndWetdownParameters
                {
                    UserToken = TestUser.UserName,

                    ProductionDate  = productionDate,
                    LotSequence     = newSequence.Value,
                    ChileProductKey = chileProduct.ToChileProductKey(),

                    ShiftKey          = "SHIFTY",
                    ProductionLineKey = productionLine.ToLocationKey(),
                    ProductionBegin   = productionDate.AddDays(-1),
                    ProductionEnd     = productionDate.AddHours(12),
                    PickedItems       = new[]
                    {
                        new MillAndWetdownPickedItemParameters
                        {
                            InventoryKey = pickedInventory.ToInventoryKey(),
                            Quantity     = pickedQuantity
                        }
                    },
                    ResultItems = new[]
                    {
                        new MillAndWetdownResultItemParameters
                        {
                            PackagingProductKey = packagingProduct.ToPackagingProductKey(),
                            LocationKey         = warehouseLocation.ToLocationKey(),
                            Quantity            = 10
                        }
                    }
                });

                createResult.AssertSuccess();
                MockKillSwitch.Verify(k => k.Engage(), Times.Never());

                var newLot = LotNumberBuilder.BuildLotNumber(KeyParserHelper.ParseResult <ILotKey>(createResult.ResultingObject).ResultingObject).LotNumber;

                Assert.IsNotNull(new RioAccessSQLEntities().tblLots.FirstOrDefault(t => t.Lot == newLot));

                //Act
                var deleteResult = Service.DeleteMillAndWetdown(createResult.ResultingObject);

                //Assert
                deleteResult.AssertSuccess();
                var lotString = GetKeyFromConsoleString(ConsoleOutput.DeletedTblLot);

                MockKillSwitch.Verify(k => k.Engage(), Times.Never());

                newLot = int.Parse(lotString);
                Assert.IsNull(new RioAccessSQLEntities().tblLots.FirstOrDefault(t => t.Lot == newLot));
            }
            public void Updates_tblBatchItems_and_KillSwitch_will_not_have_been_engaged_on_success()
            {
                //Arrange
                var productionBatch = RVCUnitOfWork.ProductionBatchRepository
                                      .Filter(b =>
                                              b.Production.ResultingChileLot.Lot.Inventory.Any(i => i.Quantity > 0) && b.Production.PickedInventory.Items.Any() &&
                                              b.Production.PickedInventory.Items.All(i => i.Quantity > 2) &&
                                              b.Production.PickedInventory.Items.Distinct().Count() == b.Production.PickedInventory.Items.Count(),
                                              b => b.Production.PickedInventory.Items,
                                              b => b.Production.Results.ResultItems)
                                      .FirstOrDefault();

                if (productionBatch == null)
                {
                    Assert.Inconclusive("Could not find suitable ProductionBatch for testing.");
                }

                var pickedModifications = productionBatch.Production.PickedInventory.Items.Select(i => new
                {
                    ExpectedQuantity = i.Quantity - 1,
                    Parameter        = new SetPickedInventoryItemParameters
                    {
                        InventoryKey = new InventoryKey(i),
                        Quantity     = -1
                    }
                }).ToList();
                var productionLine = RVCUnitOfWork.LocationRepository
                                     .Filter(l => l.LocationType == LocationType.ProductionLine && l != productionBatch.Production.Results.ProductionLineLocation).First();

                var startTimestamp = new DateTime(2014, 1, 1, 2, 3, 45, 670);
                var parameters     = new UpdateProductionResultsParameters
                {
                    UserToken                = TestUser.UserName,
                    ProductionResultKey      = new LotKey(productionBatch),
                    ProductionShiftKey       = "TestShiftKey",
                    ProductionLine           = productionLine,
                    ProductionStartTimestamp = startTimestamp,
                    ProductionEndTimestamp   = startTimestamp.AddDays(1),
                    InventoryItems           = productionBatch.Production.Results.ResultItems.Select(i => new BatchResultItemParameters
                    {
                        PackagingKey          = new PackagingProductKey(i),
                        LocationKey           = new LocationKey(i),
                        InventoryTreatmentKey = new InventoryTreatmentKey(i),
                        Quantity = i.Quantity + 1
                    }).ToList(),
                    PickedInventoryItemChanges = pickedModifications.Select(m => m.Parameter).ToList()
                };

                //Act
                var result = Service.UpdateProductionBatchResults(parameters);

                result.AssertSuccess();
                var lotString = GetKeyFromConsoleString(ConsoleOutput.SyncProductionResults);

                //Assert
                MockKillSwitch.Verify(k => k.Engage(), Times.Never());

                var newLot = int.Parse(lotString);

                using (var context = new RioAccessSQLEntities())
                {
                    var lotSelect = context.tblLots.Where(l => l.Lot == newLot)
                                    .Select(l => new
                    {
                        l,
                        l.inputBatchItems
                    }).First();
                    var tblLot = lotSelect.l;

                    Assert.AreEqual(parameters.ProductionShiftKey, tblLot.Shift);
                    Assert.AreEqual(ProductionLineParser.GetProductionLineNumber(parameters.ProductionLine), tblLot.ProductionLine);
                    parameters.ProductionStartTimestamp.AssertUTCSameAsMST(tblLot.BatchBegTime.Value);
                    parameters.ProductionEndTimestamp.AssertUTCSameAsMST(tblLot.BatchEndTime.Value);

                    var batchItems = tblLot.inputBatchItems.ToList();
                    Assert.AreEqual(pickedModifications.Count, batchItems.Count);
                    foreach (var item in pickedModifications)
                    {
                        var batchItem = batchItems.Single(i => i.Lot == LotNumberBuilder.BuildLotNumber(new InventoryKey().Parse(item.Parameter.InventoryKey)));
                        Assert.AreEqual(item.ExpectedQuantity, batchItem.Quantity);
                    }
                }
            }
            public void Creates_tblBatch_records_and_KillSwitch_will_not_have_been_engaged_on_success()
            {
                //Arrange
                var productionBatch = RVCUnitOfWork.ProductionBatchRepository.Filter(b => !b.ProductionHasBeenCompleted).FirstOrDefault();

                if (productionBatch == null)
                {
                    Assert.Inconclusive("No unproduced production batch found to pick for.");
                }

                const int pickChile      = 2;
                var       chileInventory = RVCUnitOfWork.InventoryRepository
                                           .Filter(i => i.LotTypeId == (int)LotTypeEnum.FinishedGood && i.Quantity >= pickChile &&
                                                   i.Lot.QualityStatus == LotQualityStatus.Released && i.Lot.Hold == null &&
                                                   i.Location.Active && !i.Location.Locked && i.Location.Facility.Id == GlobalKeyHelpers.RinconFacilityKey.FacilityKey_Id &&
                                                   i.Lot.Attributes.Any(a => a.AttributeShortName == Constants.ChileAttributeKeys.Asta))
                                           .FirstOrDefault();

                if (chileInventory == null)
                {
                    Assert.Inconclusive("No chile inventory found in an active location.");
                }

                const int pickDextrose = 3;
                var       dextrose     = RVCUnitOfWork.InventoryRepository.Filter(i =>
                                                                                  i.Lot.QualityStatus == LotQualityStatus.Released &&
                                                                                  i.Lot.AdditiveLot.AdditiveProduct.AdditiveTypeId == (int)SyncProductionBatchPickedInventoryHelper.Ingredient.Dextrose &&
                                                                                  i.Location.Active && !i.Location.Locked && i.Quantity >= pickDextrose)
                                         .FirstOrDefault();

                if (dextrose == null)
                {
                    Assert.Inconclusive("No dextrose inventory found in an active location.");
                }

                //Act
                var pickedItems = new List <IPickedInventoryItemParameters>
                {
                    new SetPickedInventoryItemParameters
                    {
                        InventoryKey = chileInventory.ToInventoryKey(),
                        Quantity     = pickChile
                    },
                    new SetPickedInventoryItemParameters
                    {
                        InventoryKey = dextrose.ToInventoryKey(),
                        Quantity     = pickDextrose
                    }
                };
                var result = Service.SetPickedInventoryForProductionBatch(productionBatch.ToLotKey(), new SetPickedInventoryParameters
                {
                    UserToken            = TestUser.UserName,
                    PickedInventoryItems = pickedItems
                });

                //Assert
                result.AssertSuccess();
                MockKillSwitch.Verify(k => k.Engage(), Times.Never());

                var lotNumber = int.Parse(GetKeyFromConsoleString(ConsoleOutput.SetPickedItemsForLot));

                using (var oldContext = new RioAccessSQLEntities())
                {
                    var batchItems = oldContext.tblLots.Where(l => l.Lot == lotNumber).Select(l => l.inputBatchItems).First().ToList();
                    Assert.AreEqual(pickedItems.Count, batchItems.Count);
                    foreach (var picked in pickedItems)
                    {
                        lotNumber = LotNumberBuilder.BuildLotNumber(new InventoryKey().Parse(picked.InventoryKey)).LotNumber;
                        Assert.AreEqual(picked.Quantity, batchItems.First(b => b.Lot == lotNumber).Quantity);
                    }
                }
            }