private tblIncoming CreateIncoming(tblLot oldLot, Inventory inventory) { var packaging = OldContextHelper.GetPackaging(inventory.PackagingProduct); var treatment = OldContextHelper.GetTreatment(inventory); var transType = TransType.Other; switch (inventory.LotTypeEnum.ToProductType()) { case ProductTypeEnum.Additive: transType = TransType.Ingredients; break; case ProductTypeEnum.Packaging: transType = TransType.Packaging; break; } return(new tblIncoming { EmployeeID = oldLot.EmployeeID, EntryDate = oldLot.EntryDate.Value, TTypeID = (int?)transType, Lot = oldLot.Lot, Quantity = inventory.Quantity, PkgID = packaging.PkgID, LocID = inventory.Location.LocID.Value, TrtmtID = treatment.TrtmtID, Tote = inventory.ToteKey, Company_IA = oldLot.Company_IA, NetWgt = packaging.NetWgt, TtlWgt = inventory.Quantity * packaging.NetWgt, }); }
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); } }
private void SetIncomingRecords(tblLot tblLot, IEnumerable <LotProductionResultItem> resultItems) { foreach (var item in tblLot.tblIncomings.ToList()) { OldContext.tblIncomings.DeleteObject(item); } foreach (var item in resultItems) { var packaging = OldContextHelper.GetPackaging(item.PackagingProduct); tblLot.tblIncomings.Add(new tblIncoming { EmployeeID = tblLot.EmployeeID, EntryDate = tblLot.EntryDate.Value, Lot = tblLot.Lot, TTypeID = (int?)TransType.MnW, PkgID = packaging.PkgID, Quantity = item.Quantity, NetWgt = packaging.NetWgt, TtlWgt = item.Quantity * packaging.NetWgt, LocID = item.Location.LocID.Value, TrtmtID = 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 }); } }
public SyncProductionResultsHelper(OldContextHelper oldContextHelper) { if (oldContextHelper == null) { throw new ArgumentNullException("oldContextHelper"); } _oldContextHelper = oldContextHelper; }
public override void Synchronize(Func <TreatmentOrderKey> getInput) { if (getInput == null) { throw new ArgumentNullException("getInput"); } var treatmentOrderKey = getInput(); var treatmentOrder = UnitOfWork.TreatmentOrderRepository.FindByKey(treatmentOrderKey, o => o.InventoryShipmentOrder.PickedInventory.Items.Select(i => i.CurrentLocation)); if (treatmentOrder == null) { throw new Exception(string.Format("Could not find TreatmentOrder[{0}].", treatmentOrderKey)); } var oldOrder = OldContext.tblMoves.Where(m => m.MoveNum == treatmentOrder.InventoryShipmentOrder.MoveNum) .Select(m => new { tblMove = m, details = m.tblMoveDetails.Select(d => d.tblPackaging) }).FirstOrDefault(); if (oldOrder == null) { throw new Exception(string.Format("Could not find tblMove[{0}].", treatmentOrder.InventoryShipmentOrder.MoveNum)); } var oldTreatment = OldContextHelper.GetTreatment(treatmentOrder); var firstItem = treatmentOrder.InventoryShipmentOrder.PickedInventory.Items.FirstOrDefault(); if (firstItem == null) { throw new Exception("No PickedInventoryItems in TreatmentOrder."); } foreach (var oldDetail in oldOrder.tblMove.tblMoveDetails) { OldContext.tblOutgoings.AddObject(CreateOutgoing(treatmentOrder, oldDetail)); oldDetail.TrtmtID = oldTreatment.TrtmtID; oldDetail.LocID = firstItem.CurrentLocation.LocID.Value; OldContext.tblOutgoings.AddObject(CreateOutgoing(treatmentOrder, oldDetail, -1)); } oldOrder.tblMove.Returned = treatmentOrder.Returned.ConvertUTCToLocal(); oldOrder.tblMove.Status = (int?)tblOrderStatus.Treated; OldContext.SaveChanges(); Console.Write(ConsoleOutput.ReceivedTreatmentOrder, oldOrder.tblMove.MoveNum); }
private void SyncIncomingRecords(ChileMaterialsReceived received, tblLot tblLot, ICollection <tblVariety> varieties) { foreach (var incoming in tblLot.tblIncomings.ToList()) { OldContext.tblIncomings.DeleteObject(incoming); } var treatment = OldContextHelper.GetTreatment(received); var varietyId = varieties.Select(v => v.VarietyID).DefaultIfEmpty(0).Max() + 1; foreach (var item in received.Items) { var packaging = OldContextHelper.GetPackaging(item.PackagingProduct); var variety = varieties.FirstOrDefault(v => v.Variety == item.ChileVariety); if (variety == null) { variety = new tblVariety { VarietyID = varietyId++, Variety = item.ChileVariety, EntryDate = DateTime.Now, InActive = false, SortOrder = varietyId.ToString() }; OldContextHelper.OldContext.tblVarieties.AddObject(variety); varieties.Add(variety); } tblLot.tblIncomings.Add(new tblIncoming { EmployeeID = tblLot.EmployeeID, EntryDate = tblLot.EntryDate.Value, TTypeID = (int?)(received.ChileMaterialsReceivedType == ChileMaterialsReceivedType.Dehydrated ? TransType.DeHy : TransType.Other), Quantity = item.Quantity, TrtmtID = treatment.TrtmtID, Tote = item.ToteKey, VarietyID = variety.VarietyID, Company_IA = tblLot.Company_IA, LocID = item.Location.LocID.Value, DehyLocale = item.GrowerCode, PkgID = packaging.PkgID, NetWgt = packaging.NetWgt, TtlWgt = item.Quantity * packaging.NetWgt }); } }
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 void SetPickedInventory(InventoryShipmentOrder newOrder, tblMove oldOrder, ref bool commitNewContext) { var MDetail = OldContext.tblMoveDetails.Any() ? OldContext.tblMoveDetails.Max(m => m.MDetail).AddSeconds(1) : DateTime.UtcNow.ConvertUTCToLocal(); var oldDetailsToRemove = oldOrder.tblMoveDetails.ToList(); foreach (var newItem in newOrder.PickedInventory.Items) { var oldItem = oldDetailsToRemove.FirstOrDefault(d => d.MDetail == newItem.DetailID) ?? oldDetailsToRemove.FirstOrDefault(); if (oldItem == null) { oldItem = new tblMoveDetail { MDetail = MDetail }; OldContext.tblMoveDetails.AddObject(oldItem); MDetail = MDetail.AddSeconds(1); } else { oldDetailsToRemove.Remove(oldItem); } oldItem.MoveNum = newOrder.MoveNum.Value; oldItem.Lot = LotNumberParser.BuildLotNumber(newItem); oldItem.TTypeID = (int?)newOrder.OrderType.ToTransType(); oldItem.PkgID = OldContextHelper.GetPackaging(newItem.PackagingProduct).PkgID; oldItem.Quantity = newItem.Quantity; oldItem.NetWgt = (decimal?)newItem.PackagingProduct.Weight; oldItem.TtlWgt = (decimal?)(newItem.Quantity * newItem.PackagingProduct.Weight); oldItem.LocID = newItem.FromLocation.LocID.Value; oldItem.Move2 = newItem.CurrentLocation.LocID.Value; oldItem.TrtmtID = OldContextHelper.GetTreatment(newItem).TrtmtID; oldItem.EmployeeID = newOrder.PickedInventory.EmployeeId; oldItem.CustProductCode = newItem.CustomerProductCode; oldItem.CustLot = newItem.CustomerLotCode; if (newItem.DetailID != oldItem.MDetail) { commitNewContext = true; newItem.DetailID = oldItem.MDetail; } } foreach (var o in oldDetailsToRemove) { OldContext.tblMoveDetails.DeleteObject(o); } }
public void Creates_new_tblProduct_record_when_receiving_packaging_if_record_does_not_exist() { //Arrange var oldContext = new RioAccessSQLEntities(); var helper = new OldContextHelper(oldContext); var packagings = TestHelper.Context.PackagingProducts.Select(p => new { Packaging = p, p.Product }).ToList(); tblPackaging tblPackaging; var packaging = packagings.FirstOrDefault(p => helper.GetProductFromPackagingId(p.Product.ProductCode, out tblPackaging) == null); if (packaging == null) { Assert.Inconclusive("No suitable Packaging product for testing."); } var location = RVCUnitOfWork.LocationRepository.Filter(l => l.LocID != null).First(); var parameters = new ReceiveInventoryParameters { UserToken = TestUser.UserName, LotType = LotTypeEnum.Additive, ProductKey = new ProductKey((IProductKey)RVCUnitOfWork.AdditiveProductRepository.All().First()), PackagingReceivedKey = new PackagingProductKey(packaging.Packaging), Items = new List <ReceiveInventoryItemParameters> { new ReceiveInventoryItemParameters { Quantity = 1, PackagingProductKey = new PackagingProductKey(packaging.Packaging), WarehouseLocationKey = new LocationKey(location), TreatmentKey = new InventoryTreatmentKey(RVCUnitOfWork.InventoryTreatmentRepository.All().First()), ToteKey = "" }, } }; //Act var result = Service.ReceiveInventory(parameters); result.AssertSuccess(); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); Assert.IsNotNull(oldContext.tblPackagings.Single(p => p.Packaging == packaging.Product.Name)); }
private void SetPickOrder(InventoryShipmentOrder newOrder, tblMove oldOrder) { var MOrderDetail = OldContext.tblMoveOrderDetails.Any() ? OldContext.tblMoveOrderDetails.Max(m => m.MOrderDetail).AddSeconds(1) : DateTime.UtcNow.ConvertUTCToLocal(); var oldDetailsToRemove = oldOrder.tblMoveOrderDetails.ToList(); foreach (var newItem in newOrder.InventoryPickOrder.Items) { var oldItem = oldDetailsToRemove.FirstOrDefault(); if (oldItem == null) { oldItem = new tblMoveOrderDetail { MOrderDetail = MOrderDetail }; OldContext.tblMoveOrderDetails.AddObject(oldItem); MOrderDetail = MOrderDetail.AddSeconds(1); } else { oldDetailsToRemove.Remove(oldItem); } oldItem.MoveNum = newOrder.MoveNum.Value; oldItem.Quantity = newItem.Quantity; oldItem.ProdID = OldContextHelper.GetProduct(newItem.Product.ProductCode).ProdID; oldItem.PkgID = OldContextHelper.GetPackaging(newItem.PackagingProduct).PkgID; oldItem.NetWgt = (decimal?)newItem.PackagingProduct.Weight; oldItem.TtlWgt = (decimal?)(newItem.PackagingProduct.Weight * newItem.Quantity); oldItem.TrtmtID = OldContextHelper.GetTreatment(newItem).TrtmtID; oldItem.EmployeeID = null; oldItem.CustProductCode = newItem.CustomerProductCode; oldItem.CustLot = newItem.CustomerLotCode; oldItem.CustomerID = newItem.Customer != null ? newItem.Customer.Company.Name : null; } foreach (var o in oldDetailsToRemove) { OldContext.tblMoveOrderDetails.DeleteObject(o); } }
private tblMove Synchronize(IKey <InventoryShipmentOrder> orderKey, bool createdNew, out bool commitNewContext) { var order = UnitOfWork.InventoryShipmentOrderRepository.FindByKey(orderKey, o => o.DestinationFacility, o => o.SourceFacility, o => o.InventoryPickOrder.Items.Select(i => i.Product), o => o.InventoryPickOrder.Items.Select(i => i.Customer.Company), o => o.InventoryPickOrder.Items.Select(i => i.PackagingProduct.Product), o => o.PickedInventory.Items.Select(i => i.PackagingProduct.Product), o => o.PickedInventory.Items.Select(i => i.FromLocation), o => o.PickedInventory.Items.Select(i => i.CurrentLocation), o => o.ShipmentInformation); var oldOrder = GetOrCreateOldContextOrder(order, createdNew, out commitNewContext); if (order.OrderType == InventoryShipmentOrderTypeEnum.TreatmentOrder) { var treatmentOrder = UnitOfWork.TreatmentOrderRepository.FindBy(FindTreatmentOrder(orderKey)); oldOrder.Serialized = SerializableMove.Serialize(treatmentOrder); } else { oldOrder.Serialized = SerializableMove.Serialize(order); } oldOrder.EmployeeID = order.EmployeeId; oldOrder.C2WHID = order.DestinationFacility.WHID ?? OldContextHelper.GetWarehouse(order.DestinationFacility.Name).WHID; oldOrder.WHID = order.SourceFacility.WHID ?? OldContextHelper.GetWarehouse(order.SourceFacility.Name).WHID; SyncSetShipmentInformation.SetOrderShipment(order, oldOrder); SetPickOrder(order, oldOrder); if (!order.PickedInventory.Archived) { SetPickedInventory(order, oldOrder, ref commitNewContext); } return(oldOrder); }
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); }
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, }); }
private tblOutgoing CreateOutgoing(InventoryShipmentOrder order, PickedInventoryItem item, Location location, int quantity, bool forMove) { return(new tblOutgoing { EntryDate = DateTime.UtcNow.ConvertUTCToLocal().RoundMillisecondsForSQL(), Lot = LotNumberParser.BuildLotNumber(item), TTypeID = (int?)order.OrderType.ToTransType(), PkgID = OldContextHelper.GetPackaging(item.PackagingProduct).PkgID, Tote = item.ToteKey, Quantity = quantity, NetWgt = (decimal?)item.PackagingProduct.Weight, TtlWgt = (decimal?)(quantity * item.PackagingProduct.Weight), LocID = (int)location.LocID, TrtmtID = OldContextHelper.GetTreatment(item).TrtmtID, EmployeeID = order.EmployeeId, BOMID = 0, BatchLot = 0, MoveNum = forMove ? order.MoveNum : null, MDetail = forMove ? item.DetailID : null, OrderNum = !forMove ? order.MoveNum : null, ODetail = !forMove ? item.DetailID : null, CustProductCode = item.CustomerProductCode }); }
private void SynchronizeOldContract(Contract contract, tblContract oldContract) { var warehouse = OldContextHelper.GetWarehouse(contract.DefaultPickFromFacility.Name); if (warehouse == null) { throw new Exception(string.Format("Could not find tblWarehouse with WhouseAbbr[{0}].", contract.DefaultPickFromFacility.Name)); } oldContract.EmployeeID = contract.EmployeeId; oldContract.KDate = contract.ContractDate; oldContract.BegDate = contract.TermBegin; oldContract.EndDate = contract.TermEnd; oldContract.Contact_IA = contract.ContactName; oldContract.Company_IA = contract.Customer.Company.Name; oldContract.Address1_IA = contract.ContactAddress.AddressLine1; oldContract.Address2_IA = contract.ContactAddress.AddressLine2; oldContract.Address3_IA = contract.ContactAddress.AddressLine3; oldContract.City_IA = contract.ContactAddress.City; oldContract.State_IA = contract.ContactAddress.State; oldContract.Zip_IA = contract.ContactAddress.PostalCode; oldContract.Country_IA = contract.ContactAddress.Country; oldContract.Broker = contract.Broker.Name; oldContract.PmtTerms = contract.PaymentTerms; oldContract.PONum = contract.CustomerPurchaseOrder; oldContract.KType = contract.ContractType.ToString(); oldContract.KStatus = contract.ContractStatus.ToString(); oldContract.FOB = contract.FOB; oldContract.Comments = contract.Comments.Notes.AggregateNotes(); oldContract.Notes2Print = contract.NotesToPrint; oldContract.WHID = warehouse.WHID; oldContract.Serialized = SerializableContract.Serialize(contract); var existingDetails = oldContract.tblContractDetails != null?oldContract.tblContractDetails.ToList() : new List <tblContractDetail>(); var kDetailId = OldContext.tblContractDetails.Any() ? OldContext.tblContractDetails.Max(d => d.KDetailID) : DateTime.UtcNow.ConvertUTCToLocal(); foreach (var item in contract.ContractItems) { var detail = item.KDetailID == null ? null : existingDetails.FirstOrDefault(d => d.KDetailID == item.KDetailID.Value); if (detail == null) { kDetailId = kDetailId.AddSeconds(1); detail = new tblContractDetail { KDetailID = kDetailId, ContractID = oldContract.ContractID }; OldContext.tblContractDetails.AddObject(detail); item.KDetailID = kDetailId; _commitNewContext = true; } else { existingDetails.Remove(detail); } detail.ProdID = OldContextHelper.GetProduct(item.ChileProduct).ProdID; detail.PkgID = OldContextHelper.GetPackaging(item.PackagingProduct).PkgID; detail.Quantity = item.Quantity; detail.TrtmtID = OldContextHelper.GetTreatment(item).TrtmtID; detail.Price = (decimal?)item.PriceBase; detail.FreightP = (decimal?)item.PriceFreight; detail.TrtnmntP = (decimal?)item.PriceTreatment; detail.WHCostP = (decimal?)item.PriceWarehouse; detail.Rebate = (decimal?)item.PriceRebate; detail.CustProductCode = item.CustomerProductCode; detail.Spec = item.UseCustomerSpec ? "Cust" : "RVC"; detail.TtlWgt = (decimal?)(item.Quantity * item.PackagingProduct.Weight); } foreach (var detail in existingDetails) { OldContext.tblContractDetails.DeleteObject(detail); } }
private void SyncOrderItems(SalesOrder salesOrder, tblOrder tblOrder) { var detailsToDelete = tblOrder.tblOrderDetails.ToList(); var nowODetail = DateTime.UtcNow.ConvertUTCToLocal().RoundMillisecondsForSQL(); var oDetail = OldContext.tblOrderDetails.Any() ? OldContext.tblOrderDetails.Max(o => o.ODetail) : nowODetail; if (oDetail < nowODetail) { oDetail = nowODetail; } var nowEntryDate = DateTime.UtcNow.ConvertUTCToLocal().RoundMillisecondsForSQL(); var lastEntryDate = OldContext.tblStagedFGs.Select(f => f.EntryDate).DefaultIfEmpty(nowEntryDate).Max(); if (lastEntryDate < nowEntryDate) { lastEntryDate = nowEntryDate; } foreach (var orderItem in salesOrder.SalesOrderItems) { var detail = detailsToDelete.FirstOrDefault(d => d.ODetail == orderItem.ODetail); if (detail != null) { detailsToDelete.Remove(detail); } else { oDetail = oDetail.AddSeconds(1); detail = new tblOrderDetail { ODetail = oDetail, s_GUID = Guid.NewGuid(), tblStagedFGs = new EntityCollection <tblStagedFG>() }; tblOrder.tblOrderDetails.Add(detail); orderItem.ODetail = detail.ODetail; _commitNewContext = true; } var product = OldContextHelper.GetProduct(orderItem.InventoryPickOrderItem.Product.ProductCode); var packaging = OldContextHelper.GetPackaging(orderItem.InventoryPickOrderItem.PackagingProduct); var treatment = OldContextHelper.GetTreatment(orderItem.InventoryPickOrderItem); detail.OrderNum = orderItem.Order.InventoryShipmentOrder.MoveNum.Value; detail.ProdID = product.ProdID; detail.PkgID = packaging.PkgID; detail.Quantity = orderItem.InventoryPickOrderItem.Quantity; detail.TrtmtID = treatment.TrtmtID; detail.Price = (decimal?)orderItem.PriceBase; detail.FreightP = (decimal?)orderItem.PriceFreight; detail.TrtnmntP = (decimal?)orderItem.PriceTreatment; detail.WHCostP = (decimal?)orderItem.PriceWarehouse; detail.Rebate = (decimal?)orderItem.PriceRebate; detail.KDetailID = orderItem.ContractItem == null ? null : orderItem.ContractItem.KDetailID; detail.CustProductCode = orderItem.InventoryPickOrderItem.CustomerProductCode; detail.CustLot = orderItem.InventoryPickOrderItem.CustomerLotCode; SyncPickedItems(tblOrder, orderItem, ref lastEntryDate, detail); } foreach (var detail in detailsToDelete) { foreach (var staged in detail.tblStagedFGs) { OldContext.tblStagedFGs.DeleteObject(staged); } OldContext.tblOrderDetails.DeleteObject(detail); } }
public void Updates_tblLot_product_reference() { //Arrange var pickedInventoryItems = RVCUnitOfWork.PickedInventoryItemRepository.All(); var production = RVCUnitOfWork.ChileLotProductionRepository.Filter(p => p.ProductionType == ProductionType.MillAndWetdown && p.PickedInventory.Items.Any() && p.Results.ResultItems.Any() && !pickedInventoryItems.Any(i => i.LotDateCreated == p.LotDateCreated && i.LotDateSequence == p.LotDateSequence && i.LotTypeId == p.LotTypeId), c => c.ResultingChileLot.ChileProduct, c => c.PickedInventory.Items, c => c.Results.ResultItems) .FirstOrDefault(); if (production == null) { Assert.Inconclusive("No suitable Mill and Wetdown record found for testing."); } var chileProduct = RVCUnitOfWork.ChileProductRepository .Filter(p => p.ChileState == production.ResultingChileLot.ChileProduct.ChileState && p.Id != production.ResultingChileLot.ChileProductId, c => c.Product) .FirstOrDefault(); if (chileProduct == null) { Assert.Inconclusive("No suitable Chile Product record found for testing."); } //Act var result = Service.UpdateMillAndWetdown(new UpdateMillAndWetdownParameters { UserToken = TestUser.UserName, LotKey = production.ToLotKey(), ChileProductKey = chileProduct.ToChileProductKey(), ShiftKey = "UpdateTest", ProductionLineKey = production.Results.ToLocationKey(), ProductionBegin = production.Results.ProductionBegin, ProductionEnd = production.Results.ProductionEnd, PickedItems = production.PickedInventory.Items.Select(i => new MillAndWetdownPickedItemParameters { InventoryKey = i.ToInventoryKey(), Quantity = i.Quantity }).ToArray(), ResultItems = production.Results.ResultItems.Select(i => new MillAndWetdownResultItemParameters { PackagingProductKey = i.ToPackagingProductKey(), LocationKey = i.ToLocationKey(), Quantity = i.Quantity }).ToArray() }); result.AssertSuccess(); var lotString = GetKeyFromConsoleString(ConsoleOutput.UpdatedLot); //Assert MockKillSwitch.Verify(k => k.Engage(), Times.Never()); using (var context = new RioAccessSQLEntities()) { var product = new OldContextHelper(context).GetProduct(chileProduct); var lot = int.Parse(lotString); Assert.AreEqual(product.ProdID, context.tblLots.FirstOrDefault(t => t.Lot == lot).ProdID); } }
public void Creates_LotKey_as_expected() { //Arrange var oldContext = new RioAccessSQLEntities(); var helper = new OldContextHelper(oldContext); var packagings = TestHelper.Context.PackagingProducts.Select(p => new { Packaging = p, p.Product }).ToList(); tblPackaging tblPackaging; var packaging = packagings.FirstOrDefault(p => helper.GetProductFromPackagingId(p.Product.ProductCode, out tblPackaging) == null); if (packaging == null) { Assert.Inconclusive("No suitable Packaging product for testing."); } var location = RVCUnitOfWork.LocationRepository.Filter(l => l.LocID != null).First(); var lotDate = DateTime.Now.Date; var lotSequence = 42; var parameters = new ReceiveInventoryParameters { UserToken = TestUser.UserName, LotType = LotTypeEnum.Additive, LotDate = lotDate, LotSequence = lotSequence, ProductKey = new ProductKey((IProductKey)RVCUnitOfWork.AdditiveProductRepository.All().First()), PackagingReceivedKey = new PackagingProductKey(packaging.Packaging), Items = new List <ReceiveInventoryItemParameters> { new ReceiveInventoryItemParameters { Quantity = 1, PackagingProductKey = new PackagingProductKey(packaging.Packaging), WarehouseLocationKey = new LocationKey(location), TreatmentKey = new InventoryTreatmentKey(RVCUnitOfWork.InventoryTreatmentRepository.All().First()), ToteKey = "" }, } }; //Act var result = Service.ReceiveInventory(parameters); result.AssertSuccess(); var lotString = GetKeyFromConsoleString(ConsoleOutput.ReceivedInventory); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var newLot = int.Parse(lotString); var lotKey = LotNumberParser.ParseLotNumber(newLot); Assert.AreEqual((int)LotTypeEnum.Additive, lotKey.LotKey_LotTypeId); Assert.AreEqual(lotDate, lotKey.LotKey_DateCreated); Assert.AreEqual(lotSequence, lotKey.LotKey_DateSequence); var tblLot = oldContext.tblLots.FirstOrDefault(a => a.Lot == newLot); Assert.IsNotNull(tblLot); Assert.IsNotNull(oldContext.tblPackagings.Single(p => p.Packaging == packaging.Product.Name)); }
public RinconDetail(PickedInventoryItem newItem, tblRincon rincon, OldContextHelper oldContextHelper) { _newItem = newItem; _rincon = rincon; _oldContextHelper = oldContextHelper; }
private void SyncPickedItems(tblOrder tblOrder, SalesOrderItem orderItem, ref DateTime lastEntryDate, tblOrderDetail detail) { var stagedToDelete = detail.tblStagedFGs.ToDictionary(s => s.EntryDate); foreach (var picked in orderItem.PickedItems ?? new List <SalesOrderPickedItem>()) { tblStagedFG staged; if (picked.PickedInventoryItem.DetailID != null && stagedToDelete.TryGetValue(picked.PickedInventoryItem.DetailID.Value, out staged)) { stagedToDelete.Remove(staged.EntryDate); } else { lastEntryDate = lastEntryDate.AddSeconds(1); staged = new tblStagedFG { EntryDate = lastEntryDate, s_GUID = Guid.NewGuid() }; detail.tblStagedFGs.Add(staged); picked.PickedInventoryItem.DetailID = staged.EntryDate; _commitNewContext = true; } var packaging = OldContextHelper.GetPackaging(picked.PickedInventoryItem.PackagingProduct); var treatment = OldContextHelper.GetTreatment(picked.PickedInventoryItem); staged.OrderNum = tblOrder.OrderNum; staged.ODetail = detail.ODetail; staged.Lot = LotNumberParser.BuildLotNumber(picked.PickedInventoryItem); staged.TTypeID = (int?)TransType.Batching; //To match logic found in Access (apnd_PickProdTemp) - RI 2016-3-15 staged.PkgID = packaging.PkgID; staged.Quantity = picked.PickedInventoryItem.Quantity; staged.NetWgt = packaging.NetWgt; staged.TtlWgt = picked.PickedInventoryItem.Quantity * packaging.NetWgt; staged.LocID = picked.PickedInventoryItem.CurrentLocation.LocID.Value; staged.TrtmtID = treatment.TrtmtID; staged.EmployeeID = picked.PickedInventoryItem.PickedInventory.EmployeeId; staged.CustProductCode = picked.PickedInventoryItem.CustomerProductCode; staged.CustLot = picked.PickedInventoryItem.CustomerLotCode; staged.AstaCalc = null; var asta = picked.PickedInventoryItem.Lot.Attributes.FirstOrDefault(a => a.AttributeShortName == GlobalKeyHelpers.AstaAttributeNameKey.AttributeNameKey_ShortName); if (asta != null) { var productionEnd = asta.AttributeDate; if (picked.PickedInventoryItem.Lot.ChileLot != null && picked.PickedInventoryItem.Lot.ChileLot.Production != null && picked.PickedInventoryItem.Lot.ChileLot.Production.Results != null) { productionEnd = picked.PickedInventoryItem.Lot.ChileLot.Production.Results.ProductionEnd; } staged.AstaCalc = AstaCalculator.CalculateAsta(asta.AttributeValue, asta.AttributeDate, productionEnd, DateTime.UtcNow); } staged.LoBac = false; if (picked.PickedInventoryItem.Lot.ChileLot != null) { staged.LoBac = picked.PickedInventoryItem.Lot.ChileLot.AllAttributesAreLoBac; } } foreach (var staged in stagedToDelete.Values) { OldContext.tblStagedFGs.DeleteObject(staged); } }
public SyncLotHelper(RioAccessSQLEntities oldContext, ILotUnitOfWork unitOfWork, OldContextHelper oldContextHelper) { _oldContext = oldContext; _unitOfWork = unitOfWork; _oldContextHelper = oldContextHelper; }
public override void Synchronize(Func <SyncSalesQuoteParameters> getInput) { var parameters = getInput(); var key = parameters.SalesQuoteKey; var salesQuote = UnitOfWork.SalesQuoteRepository.FindByKey(key, q => q.SourceFacility, q => q.Customer.Company, q => q.Broker, q => q.ShipmentInformation, q => q.Items.Select(i => i.Product), q => q.Items.Select(i => i.PackagingProduct.Product), q => q.Items.Select(i => i.Treatment)); if (salesQuote == null) { throw new Exception(string.Format("Could not find SalesQuote[{0}].", key)); } var commitNewContext = false; tblQuote tblQuote; if (salesQuote.QuoteNum == null || parameters.New) { var quoteNum = (salesQuote.TimeStamp.Year * 100) - 1; quoteNum = OldContext.tblQuotes.Select(q => q.QuoteNum) .Where(q => q > quoteNum) .DefaultIfEmpty(quoteNum) .Max() + 1; tblQuote = new tblQuote { QuoteNum = quoteNum, TTypeID = 19, Status = 1, PreSample = false, s_GUID = Guid.NewGuid(), EmployeeID = salesQuote.EmployeeId, EntryDate = salesQuote.TimeStamp.ConvertUTCToLocal().RoundMillisecondsForSQL() }; OldContext.tblQuotes.AddObject(tblQuote); salesQuote.QuoteNum = quoteNum; commitNewContext = true; } else { tblQuote = OldContext.tblQuotes .Include(q => q.tblQuoteDetails) .FirstOrDefault(q => q.QuoteNum == salesQuote.QuoteNum); if (tblQuote == null) { throw new Exception(string.Format("Could not find tblQuote[{0}]", salesQuote.QuoteNum)); } } tblQuote.Date = salesQuote.QuoteDate; tblQuote.DateRecd = salesQuote.DateReceived; tblQuote.From = salesQuote.CalledBy; tblQuote.TakenBy = salesQuote.TakenBy; tblQuote.WHID = salesQuote.SourceFacility == null ? null : salesQuote.SourceFacility.WHID; tblQuote.Company_IA = salesQuote.Customer == null ? null : salesQuote.Customer.Company.Name; tblQuote.Broker = salesQuote.Broker == null ? null : salesQuote.Broker.Name; tblQuote.PalletOR = (decimal?)salesQuote.ShipmentInformation.PalletWeight; tblQuote.PalletQty = salesQuote.ShipmentInformation.PalletQuantity; tblQuote.FreightBillType = salesQuote.ShipmentInformation.FreightBillType; tblQuote.ShipVia = salesQuote.ShipmentInformation.ShipmentMethod; tblQuote.Driver = salesQuote.ShipmentInformation.DriverName; tblQuote.Carrier = salesQuote.ShipmentInformation.CarrierName; tblQuote.TrlNbr = salesQuote.ShipmentInformation.TrailerLicenseNumber; tblQuote.ContSeal = salesQuote.ShipmentInformation.ContainerSeal; tblQuote.DelDueDate = salesQuote.ShipmentInformation.RequiredDeliveryDate.ConvertUTCToLocal().RoundMillisecondsForSQL(); tblQuote.SchdShipDate = salesQuote.ShipmentInformation.ShipmentDate.ConvertUTCToLocal().RoundMillisecondsForSQL(); tblQuote.CCompany = salesQuote.SoldTo.Name; tblQuote.CAddress1 = salesQuote.SoldTo.Address.AddressLine1; tblQuote.CAddress2 = salesQuote.SoldTo.Address.AddressLine2; tblQuote.CAddress3 = salesQuote.SoldTo.Address.AddressLine3; tblQuote.CCity = salesQuote.SoldTo.Address.City; tblQuote.CState = salesQuote.SoldTo.Address.State; tblQuote.CZip = salesQuote.SoldTo.Address.PostalCode; tblQuote.CCountry = salesQuote.SoldTo.Address.Country; tblQuote.SCompany = salesQuote.ShipmentInformation.ShipTo.Name; tblQuote.SPhone = salesQuote.ShipmentInformation.ShipTo.Phone; tblQuote.SAddress1 = salesQuote.ShipmentInformation.ShipTo.Address.AddressLine1; tblQuote.SAddress2 = salesQuote.ShipmentInformation.ShipTo.Address.AddressLine2; tblQuote.SAddress3 = salesQuote.ShipmentInformation.ShipTo.Address.AddressLine3; tblQuote.SCity = salesQuote.ShipmentInformation.ShipTo.Address.City; tblQuote.SState = salesQuote.ShipmentInformation.ShipTo.Address.State; tblQuote.SZip = salesQuote.ShipmentInformation.ShipTo.Address.PostalCode; tblQuote.SCountry = salesQuote.ShipmentInformation.ShipTo.Address.Country; tblQuote.Company = salesQuote.ShipmentInformation.FreightBill.Name; tblQuote.Phone = salesQuote.ShipmentInformation.FreightBill.Phone; tblQuote.Email = salesQuote.ShipmentInformation.FreightBill.EMail; tblQuote.Address1 = salesQuote.ShipmentInformation.FreightBill.Address.AddressLine1; tblQuote.Address2 = salesQuote.ShipmentInformation.FreightBill.Address.AddressLine2; tblQuote.Address3 = salesQuote.ShipmentInformation.FreightBill.Address.AddressLine3; tblQuote.City = salesQuote.ShipmentInformation.FreightBill.Address.City; tblQuote.State = salesQuote.ShipmentInformation.FreightBill.Address.State; tblQuote.Zip = salesQuote.ShipmentInformation.FreightBill.Address.PostalCode; tblQuote.Country = salesQuote.ShipmentInformation.FreightBill.Address.Country; var QDetail = OldContext.tblQuoteDetails.Select(d => d.QDetail).DefaultIfEmpty(DateTime.Now).Max(); var detailsToRemove = tblQuote.tblQuoteDetails.ToDictionary(d => d.QDetail); foreach (var item in salesQuote.Items) { tblQuoteDetail detail; if (item.QDetailID != null) { if (detailsToRemove.TryGetValue(item.QDetailID.Value, out detail)) { detailsToRemove.Remove(item.QDetailID.Value); } else { throw new Exception(string.Format("Could not find tblQuoteDetail[{0}]", item.QDetailID)); } } else { QDetail = QDetail.AddSeconds(1).RoundMillisecondsForSQL(); detail = new tblQuoteDetail { QDetail = QDetail, QuoteNum = tblQuote.QuoteNum, s_GUID = Guid.NewGuid() }; OldContext.tblQuoteDetails.AddObject(detail); item.QDetailID = detail.QDetail; commitNewContext = true; } var product = OldContextHelper.GetProduct(item.Product.ProductCode); var packaging = OldContextHelper.GetPackaging(item.PackagingProduct); var treatment = OldContextHelper.GetTreatment(item.Treatment); detail.ProdID = product.ProdID; detail.PkgID = packaging.PkgID; detail.TrtmtID = treatment.TrtmtID; detail.Quantity = item.Quantity; detail.Price = (decimal?)item.PriceBase; detail.FreightP = (decimal?)item.PriceFreight; detail.TrtnmntP = (decimal?)item.PriceTreatment; detail.WHCostP = (decimal?)item.PriceWarehouse; detail.Rebate = (decimal?)item.PriceRebate; detail.CustProductCode = item.CustomerProductCode; } foreach (var detail in detailsToRemove.Values) { OldContext.tblQuoteDetails.DeleteObject(detail); } OldContext.SaveChanges(); if (commitNewContext) { UnitOfWork.Commit(); } Console.WriteLine(ConsoleOutput.SyncTblQuote, tblQuote.QuoteNum); }
protected SyncCommandBase(TUnitOfWork unitOfWork) { UnitOfWork = unitOfWork; OldContextHelper = new OldContextHelper(new RioAccessSQLEntities()); }