public InventoryUnitsPostValidator(VolumeAndWeight volumeAndWeight, IInventoryLocationsRepository inventorylocationsRepository, IMaterialsRepository materialsRepository)
        {
            _volumeAndWeight = volumeAndWeight;
            _inventorylocationsRepository = inventorylocationsRepository;
            _materialsRepository          = materialsRepository;

            RuleFor(u => u.nBaseUnitQuantity)
            .GreaterThanOrEqualTo(0)
            .WithMessage("The base unit quantity must be a positive number.");

            When(iu => _materialsRepository.GetPost(iu.ixMaterial).bTrackSerialNumber, () =>
            {
                RuleFor(iu => iu.sSerialNumber)
                .NotEmpty()
                .WithMessage("The material is serial tracked. Please enter a serial number.");
            }
                 );

            When(iu => _materialsRepository.GetPost(iu.ixMaterial).bTrackSerialNumber, () =>
            {
                RuleFor(iu => iu.nBaseUnitQuantity)
                .LessThanOrEqualTo(1)
                .WithMessage("The material is serial tracked. The base unit quantity must be 0 or 1");
            }
                 );

            When(iu => _materialsRepository.GetPost(iu.ixMaterial).bTrackBatchNumber, () =>
            {
                RuleFor(iu => iu.sBatchNumber)
                .NotEmpty()
                .WithMessage("The material is batch tracked. Please enter a batch.");
            }
                 );

            When(iu => _materialsRepository.GetPost(iu.ixMaterial).bTrackExpiry, () =>
            {
                RuleFor(iu => iu.dtExpireAt)
                .NotEmpty()
                .WithMessage("The material is expiry tracked. Please enter an expiry date.");
            }
                 );


            When(inventoryUnit => !_volumeAndWeight.inventoryUnitWillFitLocation(inventoryUnit, _inventorylocationsRepository.GetPost(inventoryUnit.ixInventoryLocation)), () =>
            {
                RuleFor(u => u.ixInventoryLocation)
                .Empty()
                .WithMessage("The inventory will not fit into the selected location.");
            }
                 );
        }
Пример #2
0
        public ReceivingPostValidator(IReceivingRepository receivingRepository, VolumeAndWeight volumeAndWeight, IHandlingUnitsRepository handlingunitsRepository, IInventoryUnitsRepository inventoryunitsRepository, IMaterialsRepository materialsRepository, IInventoryLocationsRepository inventorylocationsRepository, IInboundOrderLinesRepository inboundorderlinesRepository)
        {
            _receivingRepository          = receivingRepository;
            _handlingunitsRepository      = handlingunitsRepository;
            _inventoryunitsRepository     = inventoryunitsRepository;
            _materialsRepository          = materialsRepository;
            _inventorylocationsRepository = inventorylocationsRepository;
            _volumeAndWeight             = volumeAndWeight;
            _inboundorderlinesRepository = inboundorderlinesRepository;

            //InventoryUnitsPost _inventoryUnit = new InventoryUnitsPost();

            RuleFor(rec => rec.sReceipt)
            .NotEmpty()
            .WithMessage("Please enter a handling unit identifier.");

            When(rec => rec.sReceipt.Trim() != "" && !_handlingunitsRepository.IndexDb().Where(x => x.sHandlingUnit == rec.sReceipt.Trim()).Any(), () =>
            {
                RuleFor(u => u.ixHandlingUnitType)
                .NotEqual(0)
                .NotEmpty()
                .WithMessage("This is a new handling unit, please select a handling unit type.");
            }
                 );

            When(rec => (rec.ixMaterialHandlingUnitConfiguration ?? 0) > 0, () =>
            {
                RuleFor(u => u.nHandlingUnitQuantity)
                .NotEmpty()
                .WithMessage("When using a material handling unit configuration, you must enter a Handling Unit Quantity greater than 0.");
            }
                 );

            //When(rec => rec.sSerialNumber.Trim() != "", () =>
            //{
            //    RuleFor(u => u.nBaseUnitQuantityReceived)
            //    .Equal(1)
            //    .WithMessage("When entering a serial number, the Base Unit Quantity Received must be 1.");
            //}
            //);

            RuleFor(u => u.nBaseUnitQuantityReceived)
            .GreaterThanOrEqualTo(0)
            .WithMessage("The Base Unit Quantity Received must be a positive number.");

            When(rec => _materialsRepository.GetPost(rec.ixMaterial).bTrackSerialNumber, () =>
            {
                RuleFor(iu => iu.sSerialNumber)
                .NotEmpty()
                .WithMessage("The material is serial tracked. Please enter a serial number.");
            }
                 );

            When(rec => _materialsRepository.GetPost(rec.ixMaterial).bTrackSerialNumber, () =>
            {
                RuleFor(iu => iu.nBaseUnitQuantityReceived)
                .LessThanOrEqualTo(1)
                .WithMessage("The material is serial tracked. The base unit quantity must be 0 or 1");
            }
                 );

            When(rec => _materialsRepository.GetPost(rec.ixMaterial).bTrackBatchNumber, () =>
            {
                RuleFor(iu => iu.sBatchNumber)
                .NotEmpty()
                .WithMessage("The material is batch tracked. Please enter a batch.");
            }
                 );

            When(rec => _materialsRepository.GetPost(rec.ixMaterial).bTrackExpiry, () =>
            {
                RuleFor(iu => iu.dtExpireAt)
                .NotEmpty()
                .WithMessage("The material is expiry tracked. Please enter an expiry date.");
            }
                 );

            // When(rec => !_volumeAndWeight.inventoryUnitWillFitLocation(new InventoryUnitsPost
            //     { ixFacility = _receivingRepository.InboundOrdersDb().Where(x => x.ixInboundOrder == rec.ixInboundOrder).Select(x => x.ixFacility).FirstOrDefault(),
            //       ixCompany = _receivingRepository.InboundOrdersDb().Where(x => x.ixInboundOrder == rec.ixInboundOrder).Select(x => x.ixCompany).FirstOrDefault(),
            //       ixMaterial = rec.ixMaterial,
            //       ixInventoryState = _inventoryunitsRepository.InventoryStatesDb().Where(x => x.sInventoryState == "")
            // }, _inventorylocationsRepository.GetPost(rec.ixInventoryLocation)), () =>
            //{
            //    RuleFor(u => u.ixInventoryLocation)
            //    .Empty()
            //    .WithMessage("The inventory will not fit into the selected location.");
            //}
            // );

            When(rec => _inboundorderlinesRepository.IndexDb().Where(x => x.ixInboundOrder == rec.ixInboundOrder && x.ixMaterial == rec.ixMaterial).Select(x => x.nBaseUnitQuantityExpected - x.nBaseUnitQuantityReceived).Sum() < rec.nBaseUnitQuantityReceived, () =>
            {
                RuleFor(r => r.nBaseUnitQuantityReceived)
                .LessThan(0)
                .WithMessage("The Base Unit Quantity Received exceeds the open quantity on the inbound order.");
            }
                 );
        }
 public MaterialsPost GetPost(Int64 ixMaterial) => _materialsRepository.GetPost(ixMaterial);
        public InboundOrderLinesPostValidator(IReceivingRepository receivingRepository, VolumeAndWeight volumeAndWeight, IHandlingUnitsRepository handlingunitsRepository, IInventoryUnitsRepository inventoryunitsRepository, IMaterialsRepository materialsRepository, IInventoryLocationsRepository inventorylocationsRepository)
        {
            _receivingRepository          = receivingRepository;
            _handlingunitsRepository      = handlingunitsRepository;
            _inventoryunitsRepository     = inventoryunitsRepository;
            _materialsRepository          = materialsRepository;
            _inventorylocationsRepository = inventorylocationsRepository;
            _volumeAndWeight = volumeAndWeight;

            //InventoryUnitsPost _inventoryUnit = new InventoryUnitsPost();

            When(rec => (rec.ixMaterialHandlingUnitConfiguration ?? 0) > 0, () =>
            {
                RuleFor(u => u.nHandlingUnitQuantity)
                .NotEmpty()
                .WithMessage("When using a material handling unit configuration, you must enter a Handling Unit Quantity greater than 0.");
            }
                 );

            //When(rec => rec.sSerialNumber.Trim() != "", () =>
            //{
            //    RuleFor(u => u.nBaseUnitQuantityExpected)
            //    .Equal(1)
            //    .WithMessage("When entering a serial number, the Base Unit Quantity Expected must be 1.");
            //}
            //);

            RuleFor(u => u.nBaseUnitQuantityExpected)
            .GreaterThanOrEqualTo(0)
            .WithMessage("The Base Unit Quantity Expected must be a positive number.");

            When(rec => _materialsRepository.GetPost(rec.ixMaterial).bTrackSerialNumber, () =>
            {
                RuleFor(iu => iu.sSerialNumber)
                .NotEmpty()
                .WithMessage("The material is serial tracked. Please enter a serial number.");
            }
                 );

            When(rec => _materialsRepository.GetPost(rec.ixMaterial).bTrackSerialNumber, () =>
            {
                RuleFor(iu => iu.nBaseUnitQuantityExpected)
                .LessThanOrEqualTo(1)
                .WithMessage("The material is serial tracked. The base unit quantity must be 0 or 1");
            }
                 );

            When(rec => _materialsRepository.GetPost(rec.ixMaterial).bTrackBatchNumber, () =>
            {
                RuleFor(iu => iu.sBatchNumber)
                .NotEmpty()
                .WithMessage("The material is batch tracked. Please enter a batch.");
            }
                 );

            When(rec => _materialsRepository.GetPost(rec.ixMaterial).bTrackExpiry, () =>
            {
                RuleFor(iu => iu.dtExpireAt)
                .NotEmpty()
                .WithMessage("The material is expiry tracked. Please enter an expiry date.");
            }
                 );
        }