Commit 4461e7e6 authored by Mahmoud Aglan's avatar Mahmoud Aglan

xdsgjdfdhf

parent 6e46794f
...@@ -11,6 +11,7 @@ use App\Core\EventBus; ...@@ -11,6 +11,7 @@ use App\Core\EventBus;
use App\Modules\Children\Models\Child; use App\Modules\Children\Models\Child;
use App\Modules\Children\Services\ChildFeeCalculator; use App\Modules\Children\Services\ChildFeeCalculator;
use App\Modules\Members\Services\NationalIdParser; use App\Modules\Members\Services\NationalIdParser;
use App\Modules\Rules\Services\RuleEngine;
class ChildController extends Controller class ChildController extends Controller
...@@ -83,31 +84,32 @@ class ChildController extends Controller ...@@ -83,31 +84,32 @@ class ChildController extends Controller
$childAge = (int) ($data['age_years'] ?? 0); $childAge = (int) ($data['age_years'] ?? 0);
// Children 16+ require NID $nidRequiredAge = (int) (RuleEngine::getValue('CHILD_NID_REQUIRED_AGE', 'value') ?? 16);
if ($childAge >= 16 && $nid === '') { if ($childAge >= $nidRequiredAge && $nid === '') {
$errors[] = 'الأبناء فوق 16 سنة يجب أن يكون لديهم رقم قومي'; $errors[] = 'الأبناء فوق ' . $nidRequiredAge . ' سنة يجب أن يكون لديهم رقم قومي';
} }
// Age gap validation $minAgeGap = (int) (RuleEngine::getValue('CHILD_MIN_AGE_GAP', 'value') ?? 15);
$maxAgeGap = (int) (RuleEngine::getValue('CHILD_MAX_AGE_GAP', 'value') ?? 60);
if (!empty($data['date_of_birth']) && !empty($member['date_of_birth'])) { if (!empty($data['date_of_birth']) && !empty($member['date_of_birth'])) {
$memberAge = age_from_dob($member['date_of_birth']); $memberAge = age_from_dob($member['date_of_birth']);
$ageGap = $memberAge['years'] - $childAge; $ageGap = $memberAge['years'] - $childAge;
if ($ageGap < 15) { if ($ageGap < $minAgeGap) {
$errors[] = 'الحد الأدنى لفرق السن بين العضو والابن 15 سنة'; $errors[] = 'الحد الأدنى لفرق السن بين العضو والابن ' . $minAgeGap . ' سنة';
} }
if ($ageGap > 60) { if ($ageGap > $maxAgeGap) {
$errors[] = 'الحد الأقصى لفرق السن بين العضو والابن 60 سنة'; $errors[] = 'الحد الأقصى لفرق السن بين العضو والابن ' . $maxAgeGap . ' سنة';
} }
} }
// Stepchild age check $stepchildMaxAge = (int) (RuleEngine::getValue('STEPCHILD_MAX_AGE', 'value') ?? 25);
if (($data['relationship'] ?? '') === 'stepchild' && $childAge >= 25) { $childMaxAge = (int) (RuleEngine::getValue('CHILD_MAX_AGE', 'value') ?? RuleEngine::getValue('CHILD_AUTO_DELETE_AGE', 'value') ?? 25);
$errors[] = 'أبناء الزوج/الزوجة لا يمكن أن يتجاوز عمرهم 25 سنة'; if (($data['relationship'] ?? '') === 'stepchild' && $childAge >= $stepchildMaxAge) {
$errors[] = 'أبناء الزوج/الزوجة لا يمكن أن يتجاوز عمرهم ' . $stepchildMaxAge . ' سنة';
} }
// Check age 25+ not accepted if ($childAge >= $childMaxAge && ($data['relationship'] ?? '') !== 'stepchild') {
if ($childAge >= 25 && ($data['relationship'] ?? '') !== 'stepchild') { $errors[] = 'لا يمكن إضافة أبناء فوق ' . $childMaxAge . ' سنة';
$errors[] = 'لا يمكن إضافة أبناء فوق 25 سنة';
} }
if (!empty($errors)) { if (!empty($errors)) {
......
...@@ -38,8 +38,8 @@ final class PricingEngine ...@@ -38,8 +38,8 @@ final class PricingEngine
public static function calculateChildFee(string $membershipValue, int $childAge, int $childOrder): array public static function calculateChildFee(string $membershipValue, int $childAge, int $childOrder): array
{ {
$maxIncluded = RuleEngine::getValue('CHILD_INCLUDED_MAX_COUNT', 'value') ?? 3; $maxIncluded = (int) (RuleEngine::getValue('INITIAL_FREE_CHILDREN_COUNT', 'value') ?? RuleEngine::getValue('CHILD_INCLUDED_MAX_COUNT', 'value') ?? 2);
$maxIncludedAge = RuleEngine::getValue('CHILD_INCLUDED_MAX_AGE', 'value') ?? 18; $maxIncludedAge = (int) (RuleEngine::getValue('CHILD_INCLUDED_MAX_AGE', 'value') ?? 18);
if ($childAge < $maxIncludedAge && $childOrder <= $maxIncluded) { if ($childAge < $maxIncludedAge && $childOrder <= $maxIncluded) {
return ['fee' => '0.00', 'rule_applied' => 'included', 'percentage' => '0.00', 'classification' => 'included']; return ['fee' => '0.00', 'rule_applied' => 'included', 'percentage' => '0.00', 'classification' => 'included'];
......
...@@ -11,6 +11,7 @@ use App\Core\EventBus; ...@@ -11,6 +11,7 @@ use App\Core\EventBus;
use App\Modules\Spouses\Models\Spouse; use App\Modules\Spouses\Models\Spouse;
use App\Modules\Spouses\Services\SpouseFeeCalculator; use App\Modules\Spouses\Services\SpouseFeeCalculator;
use App\Modules\Members\Services\NationalIdParser; use App\Modules\Members\Services\NationalIdParser;
use App\Modules\Rules\Services\RuleEngine;
class SpouseController extends Controller class SpouseController extends Controller
...@@ -122,9 +123,9 @@ class SpouseController extends Controller ...@@ -122,9 +123,9 @@ class SpouseController extends Controller
$data['age_months'] = $age['months']; $data['age_months'] = $age['months'];
} }
// ── Minimum age check (18+) ── $spouseMinAge = (int) (RuleEngine::getValue('SPOUSE_MIN_AGE', 'value') ?? 18);
if ((int) ($data['age_years'] ?? 0) < 18) { if ((int) ($data['age_years'] ?? 0) < $spouseMinAge) {
$errors[] = 'الحد الأدنى للسن 18 سنة'; $errors[] = 'الحد الأدنى للسن ' . $spouseMinAge . ' سنة';
} }
if (!empty($errors)) { if (!empty($errors)) {
......
...@@ -5,6 +5,7 @@ namespace App\Modules\Spouses\Models; ...@@ -5,6 +5,7 @@ namespace App\Modules\Spouses\Models;
use App\Core\Model; use App\Core\Model;
use App\Core\App; use App\Core\App;
use App\Modules\Rules\Services\RuleEngine;
class Spouse extends Model class Spouse extends Model
{ {
...@@ -109,9 +110,10 @@ class Spouse extends Model ...@@ -109,9 +110,10 @@ class Spouse extends Model
*/ */
public static function getMaxSpouses(string $memberGender): int public static function getMaxSpouses(string $memberGender): int
{ {
// Female member: max 1 husband if ($memberGender === 'female') {
// Male member: max 4 wives (as per regulations) return (int) (RuleEngine::getValue('MAX_SPOUSES_FEMALE_MEMBER', 'value') ?? 1);
return $memberGender === 'female' ? 1 : 4; }
return (int) (RuleEngine::getValue('MAX_SPOUSES_MALE_MEMBER', 'value') ?? 4);
} }
/** /**
......
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