Commit 6159c91e authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix divorce module: eligibility date, child fees, rule correction, full cycle

- Fix DIVORCE_CHILD_UNDER_12 rule: 15% → 5% per bylaws
- Fix eligibility: use spouse's join_date (not member's created_at) for 5-year check
- Add suggested percentage based on spouse_order (50% first, 75% second)
- Implement children transfer with age-based fees on completion
- Board approval now includes children selection with fee preview
- Complete action transfers selected children to new membership
- Show view displays spouse order, join date, children assignment details
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 2c199906
......@@ -76,12 +76,13 @@ class DivorceController extends Controller
return $this->redirect("/divorce/create/{$memberId}")->withError('قسيمة الطلاق مطلوبة');
}
// Validate basic eligibility
$feeCalc = DivorceFeeCalculator::calculate((int) $memberId, $spouseId, $divorceDate);
if (!($feeCalc['success'] ?? false)) {
return $this->redirect("/divorce/create/{$memberId}")->withError($feeCalc['error'] ?? 'خطأ');
}
$spouse = $db->selectOne("SELECT * FROM spouses WHERE id = ?", [$spouseId]);
$case = DivorceCase::create([
'member_id' => (int) $memberId,
'spouse_id' => $spouseId,
......@@ -90,7 +91,7 @@ class DivorceController extends Controller
'spouse_qualification_id' => $qualificationId,
'divorce_case_type' => $feeCalc['case_type'],
'request_date' => date('Y-m-d'),
'membership_acquisition_date' => substr($member['created_at'] ?? '', 0, 10),
'membership_acquisition_date' => substr($spouse['join_date'] ?? $spouse['created_at'] ?? '', 0, 10),
'years_of_membership' => $feeCalc['years_of_membership'],
'has_children_on_membership' => $feeCalc['has_children'] ? 1 : 0,
'status' => 'board_review',
......@@ -127,19 +128,36 @@ class DivorceController extends Controller
$percentageFee = bcdiv(bcmul($membershipValue, $feePercentage, 4), '100', 2);
$formFee = DivorceFeeCalculator::getFormFee();
$annualSub = DivorceFeeCalculator::getAnnualSubscription();
$totalFee = bcadd(bcadd($percentageFee, $formFee, 2), $annualSub, 2);
// Children transfer fees (if any selected)
$childrenSelected = $request->post('children', []);
$childFeeTotal = '0.00';
$childrenAssignment = [];
if (!empty($childrenSelected) && is_array($childrenSelected)) {
$childCalc = DivorceFeeCalculator::calculateChildFees((int) $case['member_id'], $membershipValue);
foreach ($childCalc['children'] as $child) {
if (in_array((string) $child['id'], $childrenSelected, true)) {
$childFeeTotal = bcadd($childFeeTotal, $child['fee'], 2);
$childrenAssignment[] = $child;
}
}
}
$totalFee = bcadd(bcadd(bcadd($percentageFee, $formFee, 2), $annualSub, 2), $childFeeTotal, 2);
$db->update('divorce_cases', [
'fee_percentage' => $feePercentage,
'fee_amount' => $percentageFee,
'form_fee' => $formFee,
'fee_percentage' => $feePercentage,
'fee_amount' => $percentageFee,
'form_fee' => $formFee,
'annual_subscription_fee' => $annualSub,
'total_fee' => $totalFee,
'board_decision_number' => $boardDecisionNumber ?: null,
'board_decision_date' => $boardDecisionDate ?: null,
'board_notes' => $boardNotes ?: null,
'status' => 'board_approved',
'updated_at' => date('Y-m-d H:i:s'),
'total_fee' => $totalFee,
'board_decision_number' => $boardDecisionNumber ?: null,
'board_decision_date' => $boardDecisionDate ?: null,
'board_notes' => $boardNotes ?: null,
'children_assignment_json' => !empty($childrenAssignment) ? json_encode($childrenAssignment, JSON_UNESCAPED_UNICODE) : null,
'status' => 'board_approved',
'updated_at' => date('Y-m-d H:i:s'),
], '`id` = ?', [(int) $id]);
// Auto-send payment request to cashier
......@@ -149,9 +167,12 @@ class DivorceController extends Controller
'رسوم الطلاق: ' . money($percentageFee),
'رسوم استمارة (570): ' . money($formFee),
'اشتراك سنوي: ' . money($annualSub),
'═══════════════════════════',
'الإجمالي: ' . money($totalFee),
];
if (bccomp($childFeeTotal, '0', 2) > 0) {
$breakdown[] = 'رسوم ضم أبناء: ' . money($childFeeTotal) . ' (' . count($childrenAssignment) . ' أبناء)';
}
$breakdown[] = '═══════════════════════════';
$breakdown[] = 'الإجمالي: ' . money($totalFee);
PaymentRequestService::createRequest([
'member_id' => (int) $case['member_id'],
......@@ -196,7 +217,8 @@ class DivorceController extends Controller
$db = App::getInstance()->db();
$case = $db->selectOne(
"SELECT dc.*, m.full_name_ar as member_name, m.membership_number, m.membership_value,
s.full_name_ar as spouse_name, q.name_ar as qualification_name
s.full_name_ar as spouse_name, s.spouse_order, s.join_date as spouse_join_date,
q.name_ar as qualification_name
FROM divorce_cases dc
JOIN members m ON m.id = dc.member_id
JOIN spouses s ON s.id = dc.spouse_id
......@@ -206,7 +228,25 @@ class DivorceController extends Controller
);
if (!$case) return $this->redirect('/divorce')->withError('الحالة غير موجودة');
return $this->view('Divorce.Views.show', ['case' => $case]);
$children = [];
$childFees = null;
$suggestedPercentage = null;
if ($case['status'] === 'board_review') {
$feeCalc = DivorceFeeCalculator::calculate((int) $case['member_id'], (int) $case['spouse_id'], $case['divorce_date']);
if ($feeCalc['success'] ?? false) {
$suggestedPercentage = $feeCalc['suggested_percentage'] ?? null;
}
$childFees = DivorceFeeCalculator::calculateChildFees((int) $case['member_id'], $case['membership_value'] ?? '0');
$children = $childFees['children'] ?? [];
}
return $this->view('Divorce.Views.show', [
'case' => $case,
'children' => $children,
'childFees' => $childFees,
'suggestedPercentage' => $suggestedPercentage,
]);
}
public function pay(Request $request, string $id): Response
......@@ -267,6 +307,7 @@ class DivorceController extends Controller
$spouse = $db->selectOne("SELECT * FROM spouses WHERE id = ?", [(int) $case['spouse_id']]);
$member = $db->selectOne("SELECT * FROM members WHERE id = ?", [(int) $case['member_id']]);
// Create new independent member from spouse data
$newMemberId = $db->insert('members', [
'full_name_ar' => $spouse['full_name_ar'],
'full_name_en' => $spouse['full_name_en'] ?? null,
......@@ -293,7 +334,27 @@ class DivorceController extends Controller
$newNumber = MemberNumberGenerator::assign($newMemberId);
// Archive spouse on original member
$db->update('spouses', ['status' => 'divorced', 'is_archived' => 1, 'archived_at' => date('Y-m-d H:i:s')], '`id` = ?', [(int) $case['spouse_id']]);
$db->update('spouses', [
'status' => 'divorced',
'is_archived' => 1,
'archived_at' => date('Y-m-d H:i:s'),
], '`id` = ?', [(int) $case['spouse_id']]);
// Transfer children if assigned
$childrenTransferred = 0;
if (!empty($case['children_assignment_json'])) {
$assignedChildren = json_decode($case['children_assignment_json'], true);
if (is_array($assignedChildren)) {
$childIds = array_column($assignedChildren, 'id');
foreach ($childIds as $childId) {
$db->query(
"UPDATE children SET member_id = ?, updated_at = NOW() WHERE id = ? AND member_id = ?",
[$newMemberId, (int) $childId, (int) $case['member_id']]
);
$childrenTransferred++;
}
}
}
// Update case with new membership references
$db->update('divorce_cases', [
......@@ -310,12 +371,22 @@ class DivorceController extends Controller
$db->commit();
EventBus::dispatch('divorce.completed', ['case_id' => (int) $id, 'new_member_id' => $newMemberId, 'new_number' => $newNumber]);
EventBus::dispatch('divorce.completed', [
'case_id' => (int) $id,
'new_member_id' => $newMemberId,
'new_number' => $newNumber,
'children_transferred' => $childrenTransferred,
]);
$msg = 'تم إتمام حالة الطلاق — رقم العضوية الجديد: ' . $newNumber;
if ($childrenTransferred > 0) {
$msg .= ' — تم نقل ' . $childrenTransferred . ' أبناء';
}
return $this->redirect("/divorce/{$id}")->withSuccess('تم إتمام حالة الطلاق — رقم العضوية الجديد: ' . $newNumber);
return $this->redirect("/divorce/{$id}")->withSuccess($msg);
} catch (\Throwable $e) {
$db->rollBack();
return $this->redirect("/divorce/{$id}")->withError('فشل: ' . $e->getMessage());
}
}
}
\ No newline at end of file
}
......@@ -32,9 +32,86 @@ final class DivorceFeeCalculator
return bcadd($rate, $dev, 2);
}
public static function getSuggestedPercentage(int $spouseOrder, string $caseType): array
{
if ($caseType === 'same_form') {
$data = RuleEngine::get('DIVORCE_SAME_FORM_FEE');
return [
'percentage' => $data['percentage'] ?? '10.00',
'label' => 'قُبلا في استمارة واحدة — 10%',
];
}
if ($spouseOrder <= 1) {
$data = RuleEngine::get('DIVORCE_JOINED_AFTER_FEE');
return [
'percentage' => $data['percentage'] ?? '50.00',
'label' => 'الزوج/ة الأولى — 50%',
];
}
return [
'percentage' => '75.00',
'label' => 'الزوج/ة الثانية — 75%',
];
}
public static function calculateChildFees(int $memberId, string $membershipValue): array
{
$db = App::getInstance()->db();
$children = $db->select(
"SELECT id, full_name_ar, date_of_birth, age_years FROM children WHERE member_id = ? AND is_archived = 0 AND status = 'active'",
[$memberId]
);
if (empty($children)) return ['children' => [], 'total_fee' => '0.00'];
$results = [];
$totalFee = '0.00';
foreach ($children as $child) {
$age = self::calculateAge($child['date_of_birth']);
$bracket = self::getAgeBracket($age);
$percentage = self::getChildPercentage($bracket['rule_code']);
$fee = bcdiv(bcmul($membershipValue, $percentage, 4), '100', 2);
$results[] = [
'id' => (int) $child['id'],
'name' => $child['full_name_ar'],
'age' => $age,
'bracket_label' => $bracket['label'],
'percentage' => $percentage,
'fee' => $fee,
];
$totalFee = bcadd($totalFee, $fee, 2);
}
return ['children' => $results, 'total_fee' => $totalFee];
}
private static function calculateAge(string $dateOfBirth): int
{
$birth = new \DateTime($dateOfBirth);
$now = new \DateTime();
return (int) $birth->diff($now)->y;
}
private static function getAgeBracket(int $age): array
{
if ($age < 12) return ['rule_code' => 'DIVORCE_CHILD_UNDER_12', 'label' => 'أقل من 12 سنة'];
if ($age < 16) return ['rule_code' => 'DIVORCE_CHILD_12_TO_16', 'label' => '12 إلى أقل من 16 سنة'];
if ($age < 18) return ['rule_code' => 'DIVORCE_CHILD_16_TO_18', 'label' => '16 إلى أقل من 18 سنة'];
return ['rule_code' => 'DIVORCE_CHILD_OVER_18', 'label' => 'فوق 18 سنة'];
}
private static function getChildPercentage(string $ruleCode): string
{
$data = RuleEngine::get($ruleCode);
return $data['percentage'] ?? '0.00';
}
/**
* Validate eligibility and determine case type (without calculating final fee —
* the board sets the percentage).
* Validate eligibility and determine case type.
*/
public static function calculate(int $memberId, int $spouseId, string $divorceDate): array
{
......@@ -55,44 +132,50 @@ final class DivorceFeeCalculator
return ['success' => false, 'error' => "انتهت مهلة تقديم الطلب ({$maxYears} سنة من تاريخ الطلاق)"];
}
// Determine case type
$memberCreated = $member['created_at'] ?? $member['form_date'];
// Use SPOUSE's join_date for the 5-year calculation (not member's created_at)
$spouseJoinDate = $spouse['join_date'] ?? $spouse['created_at'];
$membershipValue = $member['membership_value'] ?? '0.00';
// Check children
// Check children on this membership
$childCount = (int) ($db->selectOne(
"SELECT COUNT(*) as cnt FROM children WHERE member_id = ? AND is_archived = 0",
[$memberId]
)['cnt'] ?? 0);
$hasChildren = $childCount > 0;
// Check 5-year minimum (waived if children)
// Check 5-year minimum from spouse's join date (waived if children)
$minYearsData = RuleEngine::get('DIVORCE_MIN_MEMBERSHIP_YEARS');
$minYears = $minYearsData['min_years'] ?? 5;
$waivedIfChildren = $minYearsData['waived_if_children'] ?? true;
$yearsMembership = (int) ((time() - strtotime($memberCreated)) / (365.25 * 86400));
$yearsMembership = (int) ((time() - strtotime($spouseJoinDate)) / (365.25 * 86400));
if ($yearsMembership < $minYears && !($waivedIfChildren && $hasChildren)) {
return ['success' => false, 'error' => "الحد الأدنى لسنوات العضوية {$minYears} سنوات (يُعفى في حالة وجود أبناء)"];
return ['success' => false, 'error' => "الحد الأدنى لسنوات العضوية {$minYears} سنوات من تاريخ انضمام الزوج/ة (يُعفى في حالة وجود أبناء)"];
}
// Determine case type
// Determine case type based on join dates
$caseType = 'joined_after';
$memberCreatedDate = substr($memberCreated, 0, 10);
$memberCreated = substr($member['created_at'] ?? $member['form_date'] ?? '', 0, 10);
$spouseJoinDateStr = substr($spouseJoinDate, 0, 10);
if ($memberCreatedDate === $spouseJoinDateStr) {
if ($memberCreated === $spouseJoinDateStr) {
$caseType = 'same_form';
}
// Spouse order determines suggested fee (50% first, 75% second)
$spouseOrder = (int) ($spouse['spouse_order'] ?? 1);
$suggested = self::getSuggestedPercentage($spouseOrder, $caseType);
return [
'success' => true,
'case_type' => $caseType,
'membership_value' => $membershipValue,
'years_of_membership' => $yearsMembership,
'has_children' => $hasChildren,
'child_count' => $childCount,
'success' => true,
'case_type' => $caseType,
'membership_value' => $membershipValue,
'years_of_membership' => $yearsMembership,
'has_children' => $hasChildren,
'child_count' => $childCount,
'spouse_order' => $spouseOrder,
'suggested_percentage' => $suggested['percentage'],
'suggested_label' => $suggested['label'],
];
}
}
\ No newline at end of file
}
......@@ -27,8 +27,10 @@ $statusLabel = $statusLabels[$case['status']] ?? $case['status'];
<div style="display:flex;justify-content:space-between;align-items:start;">
<table style="width:100%;max-width:600px;font-size:14px;">
<tr><td style="padding:6px 0;color:#6B7280;width:35%;">العضو الأصلي</td><td style="padding:6px 0;"><a href="/members/<?= (int) $case['member_id'] ?>" style="color:#0D7377;font-weight:600;"><?= e($case['member_name']) ?></a> — رقم <?= e($case['membership_number']) ?></td></tr>
<tr><td style="padding:6px 0;color:#6B7280;">الزوج/ة</td><td style="padding:6px 0;font-weight:600;"><?= e($case['spouse_name']) ?></td></tr>
<tr><td style="padding:6px 0;color:#6B7280;">الزوج/ة</td><td style="padding:6px 0;font-weight:600;"><?= e($case['spouse_name']) ?> <span style="font-size:12px;color:#6B7280;">(<?= ((int) ($case['spouse_order'] ?? 1)) === 1 ? 'الزوجة الأولى' : 'الزوجة الثانية' ?>)</span></td></tr>
<tr><td style="padding:6px 0;color:#6B7280;">تاريخ الطلاق</td><td style="padding:6px 0;"><?= e($case['divorce_date']) ?></td></tr>
<tr><td style="padding:6px 0;color:#6B7280;">تاريخ انضمام الزوج/ة</td><td style="padding:6px 0;"><?= e($case['spouse_join_date'] ?? $case['membership_acquisition_date'] ?? '—') ?></td></tr>
<tr><td style="padding:6px 0;color:#6B7280;">سنوات العضوية</td><td style="padding:6px 0;font-weight:600;"><?= (int) ($case['years_of_membership'] ?? 0) ?> سنة</td></tr>
<?php if (!empty($case['qualification_name'])): ?>
<tr><td style="padding:6px 0;color:#6B7280;">المؤهل</td><td style="padding:6px 0;font-weight:600;"><?= e($case['qualification_name']) ?></td></tr>
<?php endif; ?>
......@@ -36,6 +38,8 @@ $statusLabel = $statusLabels[$case['status']] ?? $case['status'];
<tr><td style="padding:6px 0;color:#6B7280;">قسيمة الطلاق</td><td style="padding:6px 0;"><a href="/<?= e($case['divorce_certificate_path']) ?>" target="_blank" style="color:#2563EB;">عرض المستند</a></td></tr>
<?php endif; ?>
<tr><td style="padding:6px 0;color:#6B7280;">قيمة العضوية</td><td style="padding:6px 0;font-weight:700;color:#0D7377;"><?= money($case['membership_value'] ?? '0') ?></td></tr>
<tr><td style="padding:6px 0;color:#6B7280;">نوع الحالة</td><td style="padding:6px 0;"><?= \App\Modules\Divorce\Models\DivorceCase::getCaseTypeLabel($case['divorce_case_type'] ?? '') ?></td></tr>
<tr><td style="padding:6px 0;color:#6B7280;">أبناء على العضوية</td><td style="padding:6px 0;"><?= $case['has_children_on_membership'] ? '<span style="color:#059669;font-weight:600;">نعم</span>' : 'لا' ?></td></tr>
<tr><td style="padding:6px 0;color:#6B7280;">الحالة</td><td style="padding:6px 0;font-weight:700;color:<?= $statusColor ?>;"><?= $statusLabel ?></td></tr>
<?php if ($case['spouse_new_membership_number']): ?>
<tr><td style="padding:6px 0;color:#6B7280;">رقم العضوية الجديد</td><td style="padding:6px 0;"><a href="/members/<?= (int) $case['spouse_new_member_id'] ?>" style="font-weight:800;font-size:20px;color:#0D7377;"><?= e($case['spouse_new_membership_number']) ?></a></td></tr>
......@@ -75,15 +79,36 @@ $statusLabel = $statusLabels[$case['status']] ?? $case['status'];
<div class="card" style="margin-bottom:20px;border:2px solid #F59E0B;">
<div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;background:#FEF3C7;">
<h3 style="margin:0;color:#D97706;font-size:15px;">قرار مجلس الأمناء</h3>
<p style="margin:5px 0 0;font-size:12px;color:#6B7280;">حدد النسبة من قيمة العضوية التي ستدفعها المطلقة حسب المؤهل</p>
<p style="margin:5px 0 0;font-size:12px;color:#6B7280;">حدد النسبة من قيمة العضوية التي ستُدفع حسب اللائحة</p>
</div>
<div style="padding:20px;">
<form method="POST" action="/divorce/<?= (int) $case['id'] ?>/board-approve">
<?= csrf_field() ?>
<!-- Suggested percentage info -->
<?php if ($suggestedPercentage): ?>
<div style="background:#EFF6FF;border:1px solid #2563EB;border-radius:8px;padding:12px;margin-bottom:15px;">
<strong style="color:#2563EB;font-size:13px;">النسبة المقترحة حسب اللائحة:</strong>
<div style="margin-top:5px;font-size:14px;">
<?php
$spouseOrder = (int) ($case['spouse_order'] ?? 1);
$caseType = $case['divorce_case_type'] ?? 'joined_after';
?>
<?php if ($caseType === 'same_form'): ?>
<span style="font-weight:700;color:#2563EB;">10%</span> — قُبلا في استمارة واحدة
<?php elseif ($spouseOrder <= 1): ?>
<span style="font-weight:700;color:#2563EB;">50%</span> — الزوج/ة الأولى
<?php else: ?>
<span style="font-weight:700;color:#2563EB;">75%</span> — الزوج/ة الثانية
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:15px;margin-bottom:15px;">
<div class="form-group">
<label class="form-label">النسبة من قيمة العضوية (%) <span style="color:#DC2626;">*</span></label>
<input type="number" name="fee_percentage" class="form-input" required min="0" max="100" step="0.01" style="font-size:18px;font-weight:700;" placeholder="مثال: 50">
<input type="number" name="fee_percentage" class="form-input" required min="0" max="100" step="0.01" style="font-size:18px;font-weight:700;" placeholder="مثال: 50" value="<?= e($suggestedPercentage ?? '') ?>">
<small style="color:#6B7280;">قيمة العضوية: <?= money($case['membership_value'] ?? '0') ?></small>
</div>
<div class="form-group">
......@@ -95,6 +120,45 @@ $statusLabel = $statusLabels[$case['status']] ?? $case['status'];
<input type="date" name="board_decision_date" class="form-input" value="<?= e(date('Y-m-d')) ?>">
</div>
</div>
<!-- Children assignment -->
<?php if (!empty($children)): ?>
<div style="background:#FEF3C7;border:1px solid #F59E0B;border-radius:8px;padding:15px;margin-bottom:15px;">
<h4 style="margin:0 0 10px;color:#D97706;font-size:14px;">ضم الأبناء للعضوية المستقلة</h4>
<p style="font-size:12px;color:#6B7280;margin-bottom:10px;">حدد الأبناء المراد نقلهم — الرسوم تُحسب حسب العمر وفقاً للائحة</p>
<table style="width:100%;font-size:13px;border-collapse:collapse;">
<thead>
<tr style="background:#FDE68A;">
<th style="padding:8px;text-align:right;">ضم</th>
<th style="padding:8px;text-align:right;">الاسم</th>
<th style="padding:8px;text-align:right;">العمر</th>
<th style="padding:8px;text-align:right;">الفئة</th>
<th style="padding:8px;text-align:right;">النسبة</th>
<th style="padding:8px;text-align:left;">الرسوم</th>
</tr>
</thead>
<tbody>
<?php foreach ($children as $child): ?>
<tr style="border-bottom:1px solid #E5E7EB;">
<td style="padding:8px;"><input type="checkbox" name="children[]" value="<?= (int) $child['id'] ?>" checked></td>
<td style="padding:8px;font-weight:600;"><?= e($child['name']) ?></td>
<td style="padding:8px;"><?= (int) $child['age'] ?> سنة</td>
<td style="padding:8px;font-size:11px;color:#6B7280;"><?= e($child['bracket_label']) ?></td>
<td style="padding:8px;font-weight:600;color:#D97706;"><?= e($child['percentage']) ?>%</td>
<td style="padding:8px;font-weight:700;direction:ltr;text-align:left;"><?= money($child['fee']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr style="background:#FDE68A;">
<td colspan="5" style="padding:8px;font-weight:700;">إجمالي رسوم الأبناء</td>
<td style="padding:8px;font-weight:800;direction:ltr;text-align:left;"><?= money($childFees['total_fee'] ?? '0') ?></td>
</tr>
</tfoot>
</table>
</div>
<?php endif; ?>
<div class="form-group" style="margin-bottom:15px;">
<label class="form-label">ملاحظات المجلس</label>
<textarea name="board_notes" class="form-textarea" rows="2"></textarea>
......@@ -152,6 +216,22 @@ $statusLabel = $statusLabels[$case['status']] ?? $case['status'];
<td style="padding:8px 0;color:#6B7280;">اشتراك سنوي</td>
<td style="padding:8px 0;font-weight:600;direction:ltr;text-align:left;"><?= money($case['annual_subscription_fee'] ?? '0') ?></td>
</tr>
<?php
$assignedChildren = !empty($case['children_assignment_json']) ? json_decode($case['children_assignment_json'], true) : [];
if (!empty($assignedChildren)):
$childTotal = '0.00';
foreach ($assignedChildren as $ac) { $childTotal = bcadd($childTotal, $ac['fee'], 2); }
?>
<tr style="border-top:1px solid #E5E7EB;">
<td style="padding:8px 0;color:#6B7280;">رسوم ضم أبناء (<?= count($assignedChildren) ?> أبناء)</td>
<td style="padding:8px 0;font-weight:600;direction:ltr;text-align:left;"><?= money($childTotal) ?></td>
</tr>
<tr><td colspan="2" style="padding:4px 0;font-size:11px;color:#6B7280;">
<?php foreach ($assignedChildren as $ac): ?>
<?= e($ac['name']) ?> (<?= (int) $ac['age'] ?> سنة — <?= e($ac['percentage']) ?>% = <?= money($ac['fee']) ?>)<br>
<?php endforeach; ?>
</td></tr>
<?php endif; ?>
<tr style="border-top:2px solid #0D7377;">
<td style="padding:12px 0;font-weight:700;font-size:16px;">الإجمالي المطلوب</td>
<td style="padding:12px 0;font-weight:800;font-size:22px;color:#DC2626;direction:ltr;text-align:left;"><?= money($case['total_fee'] ?? '0') ?></td>
......@@ -189,10 +269,18 @@ $statusLabel = $statusLabels[$case['status']] ?? $case['status'];
<!-- Complete button -->
<div class="card" style="padding:20px;margin-bottom:20px;background:#F0FDF4;border:2px solid #059669;">
<h4 style="margin:0 0 10px;color:#059669;">إتمام حالة الطلاق</h4>
<p style="font-size:13px;color:#6B7280;margin-bottom:15px;">سيتم إنشاء عضوية جديدة مستقلة وأرشفة الزوج/ة من العضوية الأصلية.</p>
<p style="font-size:13px;color:#6B7280;margin-bottom:5px;">سيتم إنشاء عضوية جديدة مستقلة وأرشفة الزوج/ة من العضوية الأصلية.</p>
<?php
$completionChildren = !empty($case['children_assignment_json']) ? json_decode($case['children_assignment_json'], true) : [];
if (!empty($completionChildren)):
?>
<p style="font-size:13px;color:#059669;font-weight:600;margin-bottom:15px;">سيتم نقل <?= count($completionChildren) ?> أبناء إلى العضوية الجديدة:
<?php foreach ($completionChildren as $cc): ?><span style="background:#D1FAE5;padding:2px 6px;border-radius:4px;margin:0 2px;font-size:12px;"><?= e($cc['name']) ?></span><?php endforeach; ?>
</p>
<?php endif; ?>
<form method="POST" action="/divorce/<?= (int) $case['id'] ?>/complete">
<?= csrf_field() ?>
<button type="submit" class="btn btn-primary" onclick="return confirm('سيتم إنشاء عضوية جديدة مستقلة. متأكد؟')">إتمام حالة الطلاق وإنشاء العضوية</button>
<button type="submit" class="btn btn-primary" onclick="return confirm('سيتم إنشاء عضوية جديدة مستقلة<?= !empty($completionChildren) ? ' ونقل الأبناء' : '' ?>. متأكد؟')">إتمام حالة الطلاق وإنشاء العضوية</button>
</form>
</div>
<?php endif; ?>
......@@ -221,23 +309,39 @@ document.addEventListener('DOMContentLoaded', function() {
var formFee = <?= json_encode((float) ($__formFeeData['amount'] ?? '570')) ?>;
var annualSub = <?= json_encode((float) ($__childRate['base_amount'] ?? '222') + (float) ($__devFeeData['amount'] ?? '35')) ?>;
percInput.addEventListener('input', function() {
var perc = parseFloat(this.value) || 0;
function updatePreview() {
var perc = parseFloat(percInput.value) || 0;
var percFee = (membershipValue * perc / 100);
var total = percFee + formFee + annualSub;
var childFee = 0;
document.querySelectorAll('input[name="children[]"]:checked').forEach(function(cb) {
var row = cb.closest('tr');
var feeCell = row.querySelector('td:last-child');
if (feeCell) {
var txt = feeCell.textContent.replace(/[^\d.]/g, '');
childFee += parseFloat(txt) || 0;
}
});
var total = percFee + formFee + annualSub + childFee;
var preview = document.getElementById('fee-preview');
var content = document.getElementById('fee-preview-content');
if (perc > 0) {
preview.style.display = 'block';
content.innerHTML =
'رسوم الطلاق (' + perc + '% × ' + membershipValue.toLocaleString() + '): <strong>' + percFee.toLocaleString() + ' ج.م</strong><br>' +
var html = 'رسوم الطلاق (' + perc + '% × ' + membershipValue.toLocaleString() + '): <strong>' + percFee.toLocaleString() + ' ج.م</strong><br>' +
'رسوم استمارة: <strong>' + formFee.toLocaleString() + ' ج.م</strong><br>' +
'اشتراك سنوي: <strong>' + annualSub.toLocaleString() + ' ج.م</strong><br>' +
'<hr style="margin:5px 0;border-color:#059669;"><strong style="font-size:16px;color:#DC2626;">الإجمالي: ' + total.toLocaleString() + ' ج.م</strong>';
'اشتراك سنوي: <strong>' + annualSub.toLocaleString() + ' ج.م</strong><br>';
if (childFee > 0) html += 'رسوم ضم أبناء: <strong>' + childFee.toLocaleString() + ' ج.م</strong><br>';
html += '<hr style="margin:5px 0;border-color:#059669;"><strong style="font-size:16px;color:#DC2626;">الإجمالي: ' + total.toLocaleString() + ' ج.م</strong>';
content.innerHTML = html;
} else {
preview.style.display = 'none';
}
}
percInput.addEventListener('input', updatePreview);
document.querySelectorAll('input[name="children[]"]').forEach(function(cb) {
cb.addEventListener('change', updatePreview);
});
updatePreview();
});
</script>
<?php $__template->endSection(); ?>
<?php
declare(strict_types=1);
return [
'up' => "UPDATE business_rules SET current_value_json = '{\"percentage\": \"5.00\"}', updated_at = NOW() WHERE rule_code = 'DIVORCE_CHILD_UNDER_12'",
'down' => "UPDATE business_rules SET current_value_json = '{\"percentage\": \"15.00\"}', updated_at = NOW() WHERE rule_code = 'DIVORCE_CHILD_UNDER_12'",
];
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