public OutboundCarrierManifestPickupsPostValidator( IOutboundShipmentsRepository outboundshipmentsRepository , IOutboundOrdersRepository outboundordersRepository , CommonLookUpsRepository commonLookUps , IOutboundOrderLinesRepository outboundorderlinesRepository , IOutboundOrderLinesInventoryAllocationRepository outboundorderlinesinventoryallocationRepository ) { //We have to check that all the outbound shipments are completely picked (Allocated qtys) _outboundshipmentsRepository = outboundshipmentsRepository; _outboundordersRepository = outboundordersRepository; _commonLookUps = commonLookUps; _outboundorderlinesRepository = outboundorderlinesRepository; _outboundorderlinesinventoryallocationRepository = outboundorderlinesinventoryallocationRepository; var ixStatusActive = _commonLookUps.getStatuses().Where(s => s.sStatus == "Active").Select(s => s.ixStatus).FirstOrDefault(); RuleFor(x => x.ixOutboundCarrierManifest) .Custom((ixOutboundCarrierManifest, context) => { var outboundshipments = _outboundshipmentsRepository.IndexDb().Where(sh => sh.ixOutboundCarrierManifest == ixOutboundCarrierManifest && sh.ixStatus == ixStatusActive) .Select(sh => sh.ixOutboundShipment).ToList(); var outboundorders = _outboundordersRepository.IndexDb().Where(o => o.ixStatus == ixStatusActive) .Join(outboundshipments, o => o.ixOutboundShipment, sh => sh, (o, sh) => new { O = o, Sh = sh }) .Select(x => x.O.ixOutboundOrder).ToList(); var outboundorderlines = _outboundorderlinesRepository.IndexDb() .Join(outboundorders, ol => ol.ixOutboundOrder, o => o, (ol, o) => new { Ol = ol, O = o }) .Select(x => x.Ol.ixOutboundOrderLine).ToList(); var outboundorderlinesNotCompletelyPicked = _outboundorderlinesinventoryallocationRepository.IndexDb() .Join(outboundorderlines, ola => ola.ixOutboundOrderLine, ol => ol, (ola, ol) => new { Ola = ola, Ol = ol }) .Where(x => x.Ola.nBaseUnitQuantityPicked < x.Ola.nBaseUnitQuantityAllocated).Select(x => x.Ola.ixOutboundOrderLine).ToList(); if (outboundorderlinesNotCompletelyPicked.Count() > 0) { string errorList = ""; outboundorderlinesNotCompletelyPicked .ToList() .ForEach(e => errorList += e.ToString() + ", "); errorList = errorList.TrimEnd(' '); errorList = errorList.TrimEnd(','); context.AddFailure($"The following outbound order lines have not been completely picked: {errorList}. Please complete the picking first."); } } ); }
public void allocateBatch(Int64 ixPickBatch, String UserName) { //We check that the batch is not already allocated and activated - if so we do nothing var pickBatch = _pickbatchesRepository.Get(ixPickBatch); if (pickBatch.Statuses.sStatus == "Inactive") { //We get the orders associated with the batch var ordersInBatch = _outboundordersRepository.IndexDb().Where(x => x.ixPickBatch == ixPickBatch && x.Statuses.sStatus == "Active").Select(x => new { x.ixOutboundOrder, x.ixFacility, x.ixCompany }); ordersInBatch.ToList().ForEach(x => { var linesInOrders = _outboundorderlinesRepository.IndexDb().Where(l => l.ixOutboundOrder == x.ixOutboundOrder && l.Statuses.sStatus == "Active").Select(l => new { l.ixOutboundOrderLine, l.ixMaterial, l.nBaseUnitQuantityOrdered }); linesInOrders .ToList().ForEach(l => { var qtyAvailableToAllocate = getQtyAvailable(x.ixFacility, x.ixCompany, l.ixMaterial) - getQtyAllocated(x.ixFacility, x.ixCompany, l.ixMaterial); if (qtyAvailableToAllocate > 0) { OutboundOrderLinesInventoryAllocationPost outboundOrderLineInventoryAllocation = new OutboundOrderLinesInventoryAllocationPost(); outboundOrderLineInventoryAllocation.ixOutboundOrderLine = l.ixOutboundOrderLine; var orderLine = _outboundorderlinesRepository.GetPost(l.ixOutboundOrderLine); if (qtyAvailableToAllocate >= l.nBaseUnitQuantityOrdered) { outboundOrderLineInventoryAllocation.nBaseUnitQuantityAllocated = l.nBaseUnitQuantityOrdered; orderLine.ixStatus = _statusesRepository.IndexDb().Where(s => s.sStatus == "Allocated").Select(s => s.ixStatus).FirstOrDefault(); orderLine.UserName = UserName; _outboundorderlinesService.Edit(orderLine); } else { outboundOrderLineInventoryAllocation.nBaseUnitQuantityAllocated = qtyAvailableToAllocate; orderLine.ixStatus = _statusesRepository.IndexDb().Where(s => s.sStatus == "Partially Allocated").Select(s => s.ixStatus).FirstOrDefault(); orderLine.UserName = UserName; _outboundorderlinesService.Edit(orderLine); } outboundOrderLineInventoryAllocation.ixStatus = _statusesRepository.IndexDb().Where(s => s.sStatus == "Active").Select(s => s.ixStatus).FirstOrDefault(); outboundOrderLineInventoryAllocation.UserName = UserName; _outboundorderlinesinventoryallocationService.Create(outboundOrderLineInventoryAllocation); } } ); } ); } }
public Task Edit(PickBatchesPost pickbatchesPost) { // Additional validations // Pre-process // Process this._pickbatchesRepository.RegisterEdit(pickbatchesPost); try { this._pickbatchesRepository.Commit(); } catch (Exception ex) { this._pickbatchesRepository.Rollback(); // Log exception throw; } // Post-process //Custom Code Start | Added Code Block if (pickbatchesPost.ixStatus == _commonLookUps.getStatuses().Where(s => s.sStatus == "Complete").Select(s => s.ixStatus).FirstOrDefault()) { // We check if the shipment associated with the orders on the batch has been manifested. If not we try and find an active manifest else we create a new one and add the shipment to it var outboundShipments = _outboundordersRepository.IndexDb().Where(x => x.ixPickBatch == pickbatchesPost.ixPickBatch).Select(x => x.ixOutboundShipment).ToList(); var outboundShipmentsNotManifested = _outboundshipmentsService.IndexDb().Where(x => x.ixOutboundCarrierManifest == null) .Join(outboundShipments, os => os.ixOutboundShipment, o => o, (os, o) => new { Os = os, O = o }) .Select(s => s.Os.ixOutboundShipment).ToList(); outboundShipmentsNotManifested.ForEach(x => { var outboundShipment = _outboundshipmentsService.GetPost(x); if ( _outboundcarriermanifestsService.IndexDb().Where(m => m.ixFacility == outboundShipment.ixFacility && m.ixCarrier == outboundShipment.ixCarrier && m.ixStatus == _commonLookUps.getStatuses().Where(s => s.sStatus == "Active").Select(s => s.ixStatus).FirstOrDefault() ).Any()) { var ixOutboundCarrierManifest = _outboundcarriermanifestsService.IndexDb().Where(m => m.ixFacility == outboundShipment.ixFacility && m.ixCarrier == outboundShipment.ixCarrier && m.ixStatus == _commonLookUps.getStatuses().Where(s => s.sStatus == "Active").Select(s => s.ixStatus).FirstOrDefault() ).Select(m => m.ixOutboundCarrierManifest).FirstOrDefault(); outboundShipment.ixOutboundCarrierManifest = ixOutboundCarrierManifest; outboundShipment.UserName = pickbatchesPost.UserName; _outboundshipmentsService.Edit(outboundShipment); } else { OutboundCarrierManifestsPost outboundCarrierManifestsPost = new OutboundCarrierManifestsPost(); outboundCarrierManifestsPost.ixFacility = outboundShipment.ixFacility; outboundCarrierManifestsPost.ixCarrier = outboundShipment.ixCarrier; outboundCarrierManifestsPost.ixPickupInventoryLocation = _shipping.getTrailerDoorSuggestion(outboundShipment.ixFacility); outboundCarrierManifestsPost.ixStatus = _commonLookUps.getStatuses().Where(s => s.sStatus == "Active").Select(s => s.ixStatus).FirstOrDefault(); outboundCarrierManifestsPost.dtScheduledPickupAt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day) + _outboundshipmentsService.CarriersDb().Where(c => c.ixCarrier == outboundShipment.ixCarrier).Select(c => c.dtScheduledPickupTime).FirstOrDefault(); outboundCarrierManifestsPost.UserName = pickbatchesPost.UserName; var ixOutboundCarrierManifest = _outboundcarriermanifestsService.Create(outboundCarrierManifestsPost).Result; outboundShipment.ixOutboundCarrierManifest = ixOutboundCarrierManifest; outboundShipment.UserName = pickbatchesPost.UserName; _outboundshipmentsService.Edit(outboundShipment); } } ); } //Custom Code End return(Task.CompletedTask); }
public IQueryable <OutboundOrders> IndexDb() => _outboundordersRepository.IndexDb();
public Int64 getDropLocationForPickBatch(Int64 ixPickBatch) { return(_outboundordersRepository.IndexDb().Where(x => x.ixPickBatch == ixPickBatch).Select(x => x.OutboundShipments.OutboundCarrierManifests.ixPickupInventoryLocation).Distinct().FirstOrDefault() ?? 0); }