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.");
                }
            }
                    );
        }
Ejemplo n.º 2
0
        public double getQtyAllocated(Int64 ixFacility, Int64 ixCompany, Int64 ixMaterial)
        {
            double qtyAllocated            = 0;
            var    ordersInFacilityCompany = _outboundorderlinesRepository.OutboundOrdersDb().Where(x =>
                                                                                                    x.ixFacility == ixFacility &&
                                                                                                    x.ixCompany == ixCompany &&
                                                                                                    x.ixStatus == _statusesRepository.IndexDb().Where(s => s.sStatus == "Active").Select(s => s.ixStatus).FirstOrDefault()
                                                                                                    ).Select(x => new { ixOutboundOrder = x.ixOutboundOrder });

            if (_outboundorderlinesRepository.IndexDb().Where(x => x.ixMaterial == ixMaterial && ((x.ixStatus == _statusesRepository.IndexDb().Where(s => s.sStatus == "Allocated").Select(s => s.ixStatus).FirstOrDefault()) || (x.ixStatus == _statusesRepository.IndexDb().Where(s => s.sStatus == "Partially Allocated").Select(s => s.ixStatus).FirstOrDefault()))).Select(x => new { x.ixOutboundOrder, x.ixOutboundOrderLine, x.ixMaterial })
                .Join(ordersInFacilityCompany, ol => ol.ixOutboundOrder, o => o.ixOutboundOrder, (ol, o) => new { Ol = ol, O = o })
                .Select(q => q.Ol.ixOutboundOrderLine).Any()
                )
            {
                var orderLines = _outboundorderlinesRepository.IndexDb().Where(x => x.ixMaterial == ixMaterial && ((x.ixStatus == _statusesRepository.IndexDb().Where(s => s.sStatus == "Allocated").Select(s => s.ixStatus).FirstOrDefault()) || (x.ixStatus == _statusesRepository.IndexDb().Where(s => s.sStatus == "Partially Allocated").Select(s => s.ixStatus).FirstOrDefault()))).Select(x => new { x.ixOutboundOrder, x.ixOutboundOrderLine, x.ixMaterial })
                                 .Join(ordersInFacilityCompany, ol => ol.ixOutboundOrder, o => o.ixOutboundOrder, (ol, o) => new { Ol = ol, O = o })
                                 .Select(q => new { ixOutboundOrderLine = q.Ol.ixOutboundOrderLine });

                if (
                    _outboundorderlinesinventoryallocationRepository.IndexDb().Where(a => a.ixStatus == _statusesRepository.IndexDb().Where(s => s.sStatus == "Active").Select(s => s.ixStatus).FirstOrDefault())
                    .Select(a => a.nBaseUnitQuantityAllocated).Any()
                    )
                {
                    qtyAllocated = _outboundorderlinesinventoryallocationRepository.IndexDb().Where(a => a.ixStatus == _statusesRepository.IndexDb().Where(s => s.sStatus == "Active").Select(s => s.ixStatus).FirstOrDefault())
                                   .Join(orderLines, al => al.ixOutboundOrderLine, ol => ol.ixOutboundOrderLine, (al, ol) => new { Al = al, Ol = ol })
                                   .Select(ol => ol.Al.nBaseUnitQuantityAllocated).Sum();

                    return(qtyAllocated);
                }
                else
                {
                    return(0.0);
                }
            }
            else
            {
                return(0.0);
            }
        }
Ejemplo n.º 3
0
 public IQueryable <OutboundOrderLinesInventoryAllocation> IndexDb() => _outboundorderlinesinventoryallocationRepository.IndexDb();