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 InboundOrderLinesService(IInboundOrderLinesRepository inboundorderlinesRepository) { _inboundorderlinesRepository = inboundorderlinesRepository; }