Commit 67907b67 authored by Fares's avatar Fares

fix(transfers): handle missing date_of_birth when completing transfer

When creating the new member record, date_of_birth may be NULL on the
child record. Now attempts to derive DOB and gender from national_id
via NationalIdParser before falling back to a placeholder.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 705bbcbe
......@@ -8,6 +8,7 @@ use App\Core\EventBus;
use App\Core\Logger;
use App\Modules\Archive\Services\ArchiveService;
use App\Modules\Members\Services\MemberNumberGenerator;
use App\Modules\Members\Services\NationalIdParser;
use App\Modules\Transfers\Models\TransferRequest;
final class TransferProcessor
......@@ -106,14 +107,26 @@ final class TransferProcessor
}
// 4. Create new member record with SAME membership number
// Derive date_of_birth and gender from national_id if not directly available
$dob = $recipientData['date_of_birth'] ?? $subjectData['date_of_birth'] ?? null;
$gender = $recipientData['gender'] ?? $subjectData['gender'] ?? null;
$nid = $recipientData['national_id'] ?? $subjectData['national_id'] ?? null;
if ((!$dob || !$gender) && $nid && strlen($nid) === 14) {
$parsed = NationalIdParser::parse($nid);
if ($parsed['is_valid']) {
$dob = $dob ?: $parsed['dob'];
$gender = $gender ?: $parsed['gender'];
}
}
$newMemberData = [
'full_name_ar' => $recipientData['full_name_ar'] ?? $subjectData['full_name_ar'] ?? $subjectName,
'full_name_en' => $recipientData['full_name_en'] ?? $subjectData['full_name_en'] ?? null,
'national_id' => $recipientData['national_id'] ?? $subjectData['national_id'] ?? null,
'national_id' => $nid,
'passport_number' => $subjectData['passport_number'] ?? null,
'id_type' => $subjectData['id_type'] ?? 'national_id',
'date_of_birth' => $recipientData['date_of_birth'] ?? $subjectData['date_of_birth'],
'gender' => $recipientData['gender'] ?? $subjectData['gender'],
'date_of_birth' => $dob ?? '1900-01-01',
'gender' => $gender ?? 'male',
'nationality' => $recipientData['nationality'] ?? $subjectData['nationality'] ?? 'مصري',
'branch_id' => (int) $sourceMember['branch_id'],
'membership_type' => 'working',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment