diff --git a/app/Http/Controllers/Api/WorkerAuthController.php b/app/Http/Controllers/Api/WorkerAuthController.php index 17e79f1..ab9d800 100644 --- a/app/Http/Controllers/Api/WorkerAuthController.php +++ b/app/Http/Controllers/Api/WorkerAuthController.php @@ -1246,7 +1246,7 @@ private function cleanVisaData(array $visaDataInput): array $rawEntryPermitNo = $visaDataInput['entry_permit_no'] ?? $visaDataInput['file_number'] ?? $visaDataInput['id_number'] ?? $visaDataInput['number'] ?? null; $rawIssueDate = $visaDataInput['issue_date'] ?? null; $rawValidUntil = $visaDataInput['valid_until'] ?? $visaDataInput['expiry_date'] ?? null; - $rawUidNo = $visaDataInput['uid_no'] ?? null; + $rawUidNo = $visaDataInput['uid_no'] ?? $visaDataInput['id_number'] ?? null; $rawFullName = $visaDataInput['full_name'] ?? $visaDataInput['name'] ?? null; $rawNationality = $visaDataInput['nationality'] ?? null; $rawPlaceOfBirth = $visaDataInput['place_of_birth'] ?? null; diff --git a/app/Http/Controllers/Api/WorkerProfileController.php b/app/Http/Controllers/Api/WorkerProfileController.php index 9161643..5eded75 100644 --- a/app/Http/Controllers/Api/WorkerProfileController.php +++ b/app/Http/Controllers/Api/WorkerProfileController.php @@ -768,7 +768,7 @@ private function cleanVisaData(array $visaDataInput): array $rawEntryPermitNo = $visaDataInput['entry_permit_no'] ?? $visaDataInput['file_number'] ?? $visaDataInput['id_number'] ?? $visaDataInput['number'] ?? null; $rawIssueDate = $visaDataInput['issue_date'] ?? null; $rawValidUntil = $visaDataInput['valid_until'] ?? $visaDataInput['expiry_date'] ?? null; - $rawUidNo = $visaDataInput['uid_no'] ?? null; + $rawUidNo = $visaDataInput['uid_no'] ?? $visaDataInput['id_number'] ?? null; $rawFullName = $visaDataInput['full_name'] ?? $visaDataInput['name'] ?? null; $rawNationality = $visaDataInput['nationality'] ?? null; $rawPlaceOfBirth = $visaDataInput['place_of_birth'] ?? null; diff --git a/database/migrations/2026_06_24_145817_standardize_visa_ocr_data_in_worker_documents.php b/database/migrations/2026_06_24_145817_standardize_visa_ocr_data_in_worker_documents.php new file mode 100644 index 0000000..114f01e --- /dev/null +++ b/database/migrations/2026_06_24_145817_standardize_visa_ocr_data_in_worker_documents.php @@ -0,0 +1,89 @@ +where('type', 'visa')->get(); + foreach ($visaDocuments as $doc) { + $ocrData = json_decode($doc->ocr_data, true); + if (is_array($ocrData)) { + $cleaned = $this->cleanVisaData($ocrData); + \DB::table('worker_documents')->where('id', $doc->id)->update([ + 'ocr_data' => json_encode($cleaned) + ]); + } + } + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // Cleaning up or reverting structure is not strictly necessary or possible + // since we map legacy fields to modern ones. + } + + private function cleanVisaData(array $visaDataInput): array + { + $rawVisaType = $visaDataInput['visa_type'] ?? null; + $rawEntryPermitNo = $visaDataInput['entry_permit_no'] ?? $visaDataInput['file_number'] ?? $visaDataInput['id_number'] ?? $visaDataInput['number'] ?? null; + $rawIssueDate = $visaDataInput['issue_date'] ?? null; + $rawValidUntil = $visaDataInput['valid_until'] ?? $visaDataInput['expiry_date'] ?? null; + $rawUidNo = $visaDataInput['uid_no'] ?? $visaDataInput['id_number'] ?? null; + $rawFullName = $visaDataInput['full_name'] ?? $visaDataInput['name'] ?? null; + $rawNationality = $visaDataInput['nationality'] ?? null; + $rawPlaceOfBirth = $visaDataInput['place_of_birth'] ?? null; + $rawDateOfBirth = $visaDataInput['date_of_birth'] ?? $visaDataInput['dob'] ?? null; + $rawPassportNo = $visaDataInput['passport_no'] ?? $visaDataInput['passport_number'] ?? null; + $rawProfession = $visaDataInput['profession'] ?? null; + $rawSponsorName = $visaDataInput['sponsor_name'] ?? null; + $rawOcrAccuracy = $visaDataInput['ocr_accuracy'] ?? null; + + // Clean sponsor + $sponsorData = $visaDataInput['sponsor'] ?? []; + if (is_string($sponsorData)) { + $sponsorNameFromObj = $sponsorData; + $sponsorAddress = ''; + $sponsorPhone = ''; + } else { + $sponsorNameFromObj = $sponsorData['name'] ?? $sponsorData['sponsor_name'] ?? $sponsorData['full_name'] ?? ''; + $sponsorAddress = $sponsorData['address'] ?? ''; + $sponsorPhone = $sponsorData['phone'] ?? $sponsorData['mobile'] ?? $sponsorData['mobile_number'] ?? $sponsorData['phone_number'] ?? ''; + } + if (empty($rawSponsorName)) { + $rawSponsorName = $sponsorNameFromObj; + } + + return [ + 'document_type' => 'uae_visa', + 'country' => 'United Arab Emirates', + 'visa_type' => $rawVisaType ?: 'ENTRY PERMIT', + 'entry_permit_no' => $rawEntryPermitNo ?: '', + 'issue_date' => $rawIssueDate ?: '', + 'valid_until' => $rawValidUntil ?: '', + 'uid_no' => $rawUidNo ?: '', + 'full_name' => $rawFullName ?: '', + 'nationality' => $rawNationality ?: '', + 'place_of_birth' => $rawPlaceOfBirth ?: '', + 'date_of_birth' => $rawDateOfBirth ?: '', + 'passport_no' => $rawPassportNo ?: '', + 'profession' => $rawProfession ?: '', + 'sponsor_name' => $rawSponsorName ?: '', + 'ocr_accuracy' => $rawOcrAccuracy !== null ? (int)$rawOcrAccuracy : 99, + 'sponsor' => [ + 'name' => $sponsorNameFromObj ?: '', + 'address' => $sponsorAddress ?: '', + 'phone' => $sponsorPhone ?: '', + ] + ]; + } +}; diff --git a/public/swagger.json b/public/swagger.json index 172e042..d245244 100644 --- a/public/swagger.json +++ b/public/swagger.json @@ -1102,92 +1102,85 @@ }, "visa": { "type": "object", - "description": "Optional JSON object containing extracted visa details.", + "description": "Standardized UAE Visa metadata.", "properties": { - "accompanied_by": { - "type": "string" + "document_type": { + "type": "string", + "example": "uae_visa" }, "country": { "type": "string", "example": "United Arab Emirates" }, - "date_of_birth": { + "visa_type": { "type": "string", - "example": "25-JUN-1999" - }, - "document_type": { - "type": "string", - "example": "uae_visa" + "example": "ENTRY PERMIT" }, "entry_permit_no": { "type": "string", "example": "77003098 / 2019 / 204" }, - "expiry_date": { - "type": "string", - "example": "2024-02-15" - }, - "file_number": { - "type": "string" - }, - "full_name": { - "type": "string", - "example": "Mr.MUHAMMAD NADEEM RASHEED" - }, - "id_number": { - "type": "string" - }, "issue_date": { "type": "string", "example": "2022-02-16" }, - "name": { - "type": "string" - }, - "nationality": { + "valid_until": { "type": "string", - "example": "PAKISTAN" - }, - "ocr_accuracy": { - "type": "number", - "format": "float", - "example": 99 - }, - "passport_no": { - "type": "string", - "example": "EN9458281" - }, - "passport_number": { - "type": "string" - }, - "place_of_birth": { - "type": "string", - "example": "SIALKOT PAK" - }, - "place_of_issue": { - "type": "string" - }, - "profession": { - "type": "string", - "example": "SALES REPRESENTATIVE" - }, - "sponsor": { - "type": "string" - }, - "sponsor_name": { - "type": "string" + "example": "2024-02-15" }, "uid_no": { "type": "string", "example": "207404887" }, - "valid_until": { + "full_name": { "type": "string", - "example": "04-MAR-2019" + "example": "Mr.MUHAMMAD NADEEM RASHEED" }, - "visa_type": { + "nationality": { "type": "string", - "example": "ENTRY PERMIT" + "example": "PAKISTAN" + }, + "place_of_birth": { + "type": "string", + "example": "SIALKOT PAK" + }, + "date_of_birth": { + "type": "string", + "example": "25-JUN-1999" + }, + "passport_no": { + "type": "string", + "example": "EN9458281" + }, + "profession": { + "type": "string", + "example": "SALES REPRESENTATIVE" + }, + "sponsor_name": { + "type": "string", + "example": "Sponsor Name" + }, + "ocr_accuracy": { + "type": "number", + "format": "float", + "example": 97.4 + }, + "sponsor": { + "type": "object", + "properties": { + "name": { + "type": "string", + "example": "Sponsor Name" + }, + "address": { + "type": "string", + "example": "Dubai Marina, Dubai" + }, + "phone": { + "type": "string", + "example": "2977725" + } + } } } } @@ -6648,82 +6641,108 @@ "type": "string", "example": "uploads/licenses/1234567890_emirates_id.pdf" }, + "license_expiry": { + "type": "string", + "nullable": true, + "example": "2026-05-03" + }, + "validity": { + "type": "string", + "example": "Valid" + }, + "joined_at": { + "type": "string", + "format": "date-time" + }, "fcm_token": { "type": "string", "example": "fcm_token_example" }, - "document_type": { - "type": "string", - "example": "dubai_commercial_license" - }, - "country": { - "type": "string", - "example": "United Arab Emirates" - }, - "authority": { - "type": "string", - "example": "Dubai Economy and Tourism" - }, - "license_no": { - "type": "string", - "example": "828302" - }, - "company_name": { - "type": "string", - "example": "MSJ INTERNATIONAL TECHNICAL SERVICES L.L.C" - }, - "business_name": { - "type": "string", - "example": "MSJ INTERNATIONAL TECHNICAL SERVICES L.L.C" - }, - "license_category": { - "type": "string", - "example": "Dep. of Economic Development" - }, - "legal_type": { - "type": "string", - "example": "Limited Liability Company Single Owner(LLC- - SO)" - }, - "issue_date": { - "type": "string", - "example": "06/03/2019" - }, - "expiry_date": { - "type": "string", - "example": "05/03/2026" - }, - "main_license_no": { - "type": "string", - "example": "828302" - }, - "register_no": { - "type": "string", - "example": "1656486" - }, - "dcci_no": { - "type": "string", - "example": "317412" - }, - "members": { - "type": "array", - "items": { - "type": "object", - "properties": { - "person_no": { - "type": "string", - "example": "752967" - }, - "name": { - "type": "string", - "example": "Lo lo wallus issued in" - }, - "nationality": { - "type": "string", - "example": "India" - }, - "role": { - "type": "string", - "example": "Shares Owner Who" + "license": { + "type": "object", + "properties": { + "license_number": { + "type": "string", + "example": "828302" + }, + "organization_name": { + "type": "string", + "example": "MSJ INTERNATIONAL TECHNICAL SERVICES L.L.C" + }, + "expiry_date": { + "type": "string", + "example": "2026-05-03" + }, + "document_type": { + "type": "string", + "example": "dubai_commercial_license" + }, + "country": { + "type": "string", + "example": "United Arab Emirates" + }, + "authority": { + "type": "string", + "example": "Dubai Economy and Tourism" + }, + "license_no": { + "type": "string", + "example": "828302" + }, + "company_name": { + "type": "string", + "example": "MSJ INTERNATIONAL TECHNICAL SERVICES L.L.C" + }, + "business_name": { + "type": "string", + "example": "MSJ INTERNATIONAL TECHNICAL SERVICES L.L.C" + }, + "license_category": { + "type": "string", + "example": "Dep. of Economic Development" + }, + "legal_type": { + "type": "string", + "example": "Limited Liability Company Single Owner(LLC- - SO)" + }, + "issue_date": { + "type": "string", + "example": "06/03/2019" + }, + "main_license_no": { + "type": "string", + "example": "828302" + }, + "register_no": { + "type": "string", + "example": "1656486" + }, + "dcci_no": { + "type": "string", + "example": "317412" + }, + "members": { + "type": "array", + "items": { + "type": "object", + "properties": { + "person_no": { + "type": "string", + "example": "752967" + }, + "name": { + "type": "string", + "example": "Lo lo wallus issued in" + }, + "nationality": { + "type": "string", + "example": "India" + }, + "role": { + "type": "string", + "example": "Shares Owner Who" + } + } } } } diff --git a/resources/js/Pages/Employer/Workers/Show.jsx b/resources/js/Pages/Employer/Workers/Show.jsx index bd5ff46..850c46c 100644 --- a/resources/js/Pages/Employer/Workers/Show.jsx +++ b/resources/js/Pages/Employer/Workers/Show.jsx @@ -676,7 +676,8 @@ export default function Show({ worker }) { )} - {visaDoc.ocr_data ? (() => { +