Commit e0e2fdd8 authored by Fares's avatar Fares

fix(transfers): include date_of_birth when creating dependent children

The children table requires date_of_birth (NOT NULL). The dependent
creation loop now derives DOB from national_id via NationalIdParser,
falling back to a placeholder if neither is available.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 67907b67
......@@ -184,26 +184,45 @@ final class TransferProcessor
if (!empty($depsData['spouses'])) {
foreach ($depsData['spouses'] as $sp) {
if (empty($sp['full_name_ar'])) continue;
$db->insert('spouses', [
$spNid = $sp['national_id'] ?? null;
$spDob = null;
if ($spNid && strlen($spNid) === 14) {
$spParsed = NationalIdParser::parse($spNid);
if ($spParsed['is_valid']) $spDob = $spParsed['dob'];
}
$spouseRow = [
'member_id' => $newMemberId,
'full_name_ar' => $sp['full_name_ar'],
'national_id' => $sp['national_id'] ?? null,
'national_id' => $spNid,
'status' => 'active',
'is_archived' => 0,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
]);
];
if ($spDob) $spouseRow['date_of_birth'] = $spDob;
$db->insert('spouses', $spouseRow);
}
}
if (!empty($depsData['children'])) {
foreach ($depsData['children'] as $ch) {
if (empty($ch['full_name_ar'])) continue;
$chNid = $ch['national_id'] ?? null;
$chDob = $ch['date_of_birth'] ?? null;
$chGender = $ch['gender'] ?? 'male';
if (!$chDob && $chNid && strlen($chNid) === 14) {
$chParsed = NationalIdParser::parse($chNid);
if ($chParsed['is_valid']) {
$chDob = $chParsed['dob'];
$chGender = $chParsed['gender'] ?? $chGender;
}
}
$db->insert('children', [
'member_id' => $newMemberId,
'full_name_ar' => $ch['full_name_ar'],
'national_id' => $ch['national_id'] ?? null,
'gender' => $ch['gender'] ?? 'male',
'national_id' => $chNid,
'date_of_birth' => $chDob ?? '1900-01-01',
'gender' => $chGender,
'classification' => 'active',
'status' => 'active',
'is_archived' => 0,
......
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