First to Site
Release 3.4

Duplicate Client Job Number Validation

Three-layer validation preventing duplicate active client job numbers on project create in 3.4.0

Overview

v3.4.0 added validation at three layers to prevent creating a project with an ftsClientNumber (Client Job No.) that already exists on another active project.

What "Active" Means

A project is active if deletedAt IS NULL AND its status tag is not cancelled. Soft-deleted or cancelled projects are excluded - their job numbers can be reused.

Validation Layers

1. Entity Constraint

A custom #[UniqueActiveFtsClientNumber] attribute on the ftsClientNumber property in Project.php. The corresponding UniqueActiveFtsClientNumberValidator calls the repository to check for duplicates. It only fires for new projects ($project->getId() === null), skipping edits.

2. API Pre-Submit Check

A new endpoint GET /api/project/client-job-number/{job_no}/{project_id?} in ProjectController.php supports AJAX pre-submit validation. The frontend calls this before form submission and shows a modal warning if duplicates exist.

3. Service-Layer Safety Net

ProjectCreationService.php calls $this->validator->validate($project) before persist/flush, throwing ValidationException on violations - a server-side safety net for the Ordering Portal flow.

Frontend Integration

The EasyAdmin frontend (custom-ea.js) was refactored to chain validateFtsClientNumber before validateProjectSpi on form submission, intercepting duplicates before the form reaches the server.

Files Touched

FileChange
Entity/Project.phpModified - constraint attribute added
Library/Validator/Constraints/UniqueActiveFtsClientNumber.phpAdded - constraint class
Library/Validator/Constraints/UniqueActiveFtsClientNumberValidator.phpAdded - validator logic
Repository/ProjectRepository.phpModified - findActiveDuplicatesByFtsClientNumber()
Controller/Api/ProjectController.phpModified - AJAX check endpoint
Service/Ordering/ProjectCreationService.phpModified - pre-persist validation
assets/custom-ea.jsModified - frontend validation chain

Changelog Reference

  • fix: prevent duplicate active client job numbers on project create (#652)