Commit ec96e7ed authored by Administrator's avatar Administrator

Update 3 files via Son of Anton

parent ef7860c0
...@@ -16,22 +16,18 @@ class Spouse extends Model ...@@ -16,22 +16,18 @@ class Spouse extends Model
protected static array $fillable = [ protected static array $fillable = [
'member_id', 'spouse_order', 'full_name_ar', 'full_name_en', 'member_id', 'spouse_order', 'full_name_ar', 'full_name_en',
'national_id', 'passport_number', 'date_of_birth', 'age_years', 'age_months', 'national_id', 'passport_number', 'date_of_birth',
'gender', 'nationality', 'religion', 'qualification_id', 'age_years', 'age_months', 'gender', 'nationality', 'religion',
'occupation', 'work_address', 'work_phone', 'mobile', 'qualification_id', 'occupation', 'work_address', 'work_phone', 'mobile',
'marriage_date', 'join_date', 'classification', 'marriage_date', 'join_date', 'classification', 'addition_fee',
'addition_fee', 'fee_receipt_number', 'status', 'photo_path', 'fee_receipt_number', 'status', 'photo_path',
]; ];
public static function getForMember(int $memberId): array public static function getForMember(int $memberId): array
{ {
$db = App::getInstance()->db(); $db = App::getInstance()->db();
return $db->select( return $db->select(
"SELECT s.*, q.name_ar as qualification_name "SELECT * FROM spouses WHERE member_id = ? AND is_archived = 0 ORDER BY spouse_order ASC",
FROM spouses s
LEFT JOIN qualifications q ON q.id = s.qualification_id
WHERE s.member_id = ? AND s.is_archived = 0
ORDER BY s.spouse_order ASC",
[$memberId] [$memberId]
); );
} }
...@@ -51,45 +47,30 @@ class Spouse extends Model ...@@ -51,45 +47,30 @@ class Spouse extends Model
return self::countActiveForMember($memberId) + 1; return self::countActiveForMember($memberId) + 1;
} }
public static function nidExistsForOtherMember(string $nid, int $excludeMemberId, ?int $excludeSpouseId = null): ?array public static function nidExistsElsewhere(string $nid, ?int $excludeSpouseId = null): ?array
{ {
$db = App::getInstance()->db(); $db = App::getInstance()->db();
// Check members table
$memberDup = $db->selectOne( $memberDup = $db->selectOne(
"SELECT id, full_name_ar, membership_number FROM members WHERE national_id = ? AND id != ? AND is_archived = 0", "SELECT id, full_name_ar, membership_number FROM members WHERE national_id = ? AND is_archived = 0",
[$nid, $excludeMemberId] [$nid]
); );
if ($memberDup) { if ($memberDup) return ['type' => 'member', 'data' => $memberDup];
return ['type' => 'member', 'data' => $memberDup];
}
// Check spouses table $sql = "SELECT s.id, s.full_name_ar, m.membership_number FROM spouses s JOIN members m ON m.id = s.member_id WHERE s.national_id = ? AND s.is_archived = 0";
$sql = "SELECT s.id, s.full_name_ar, s.member_id, m.membership_number
FROM spouses s
JOIN members m ON m.id = s.member_id
WHERE s.national_id = ? AND s.is_archived = 0";
$params = [$nid]; $params = [$nid];
if ($excludeSpouseId) { if ($excludeSpouseId) {
$sql .= " AND s.id != ?"; $sql .= " AND s.id != ?";
$params[] = $excludeSpouseId; $params[] = $excludeSpouseId;
} }
$spouseDup = $db->selectOne($sql, $params); $spouseDup = $db->selectOne($sql, $params);
if ($spouseDup) { if ($spouseDup) return ['type' => 'spouse', 'data' => $spouseDup];
return ['type' => 'spouse', 'data' => $spouseDup];
}
// Check children table
$childDup = $db->selectOne( $childDup = $db->selectOne(
"SELECT c.id, c.full_name_ar, c.member_id, m.membership_number "SELECT c.id, c.full_name_ar, m.membership_number FROM children c JOIN members m ON m.id = c.member_id WHERE c.national_id = ? AND c.is_archived = 0",
FROM children c
JOIN members m ON m.id = c.member_id
WHERE c.national_id = ? AND c.is_archived = 0",
[$nid] [$nid]
); );
if ($childDup) { if ($childDup) return ['type' => 'child', 'data' => $childDup];
return ['type' => 'child', 'data' => $childDup];
}
return null; return null;
} }
...@@ -97,9 +78,9 @@ class Spouse extends Model ...@@ -97,9 +78,9 @@ class Spouse extends Model
public function getClassificationLabel(): string public function getClassificationLabel(): string
{ {
return match ($this->classification) { return match ($this->classification) {
'working' => 'عضو عامل', 'working' => 'عامل',
'dependent' => 'عضو تابع', 'seasonal' => 'موسمي',
default => $this->classification, default => $this->classification ?? 'عامل',
}; };
} }
...@@ -108,24 +89,28 @@ class Spouse extends Model ...@@ -108,24 +89,28 @@ class Spouse extends Model
return match ($this->status) { return match ($this->status) {
'active' => 'نشط', 'active' => 'نشط',
'inactive' => 'غير نشط', 'inactive' => 'غير نشط',
'separated' => 'منفصل', 'divorced' => 'مطلق/ة',
'deceased' => 'متوفى', 'deceased' => 'متوفى/ة',
default => $this->status, 'transferred' => 'منقول/ة',
default => $this->status ?? '',
}; };
} }
public function getMemberName(): string /**
* Get the max number of spouses allowed based on member gender.
*/
public static function getMaxSpouses(string $memberGender): int
{ {
$db = App::getInstance()->db(); // Female member: max 1 husband
$row = $db->selectOne("SELECT full_name_ar FROM members WHERE id = ?", [$this->member_id]); // Male member: max 4 wives (as per regulations)
return $row['full_name_ar'] ?? '—'; return $memberGender === 'female' ? 1 : 4;
} }
public function getQualificationName(): string /**
* Get the required spouse gender based on member gender.
*/
public static function getRequiredSpouseGender(string $memberGender): string
{ {
if (!$this->qualification_id) return '—'; return $memberGender === 'female' ? 'male' : 'female';
$db = App::getInstance()->db();
$row = $db->selectOne("SELECT name_ar FROM qualifications WHERE id = ?", [$this->qualification_id]);
return $row['name_ar'] ?? '—';
} }
} }
\ No newline at end of file
This diff is collapsed.
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