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

xdsgjdfdhf

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