Commit c492f45a authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix(members): correct installment panel formula and add live preview

- Installment panel in member show page now uses flat simple interest:
  remaining × (rate/100) × (months/12) instead of hardcoded 22% × 30mo
- Live breakdown table updates in real-time as user changes down payment
  or months: shows سعر العضوية, المقدم, المبلغ المتبقي, الفائدة,
  الإجمالي مع الفائدة, القسط الشهري
- Pass installInterestRate and installMaxMonths from RuleEngine to show view
- Fix pay-membership action to respect RuleEngine max months (not hardcoded 30)
Co-Authored-By: 's avatarClaude Sonnet 4.6 <noreply@anthropic.com>
parent b7d24084
...@@ -255,6 +255,9 @@ class MemberController extends Controller ...@@ -255,6 +255,9 @@ class MemberController extends Controller
); );
} }
$instRateData = RuleEngine::get('INSTALLMENT_INTEREST_RATE');
$instMonthsData = RuleEngine::get('INSTALLMENT_MAX_MONTHS');
return $this->view('Members.Views.show', [ return $this->view('Members.Views.show', [
'member' => $member, 'member' => $member,
'branchName' => $branch['name_ar'] ?? '—', 'branchName' => $branch['name_ar'] ?? '—',
...@@ -276,6 +279,8 @@ class MemberController extends Controller ...@@ -276,6 +279,8 @@ class MemberController extends Controller
'installmentPlan' => $member->status === 'pending_cheques' 'installmentPlan' => $member->status === 'pending_cheques'
? $db->selectOne("SELECT id, number_of_months FROM installment_plans WHERE member_id = ? AND status = 'active' ORDER BY id DESC LIMIT 1", [(int) $id]) ? $db->selectOne("SELECT id, number_of_months FROM installment_plans WHERE member_id = ? AND status = 'active' ORDER BY id DESC LIMIT 1", [(int) $id])
: null, : null,
'installInterestRate' => (float) ($instRateData['percentage'] ?? 22),
'installMaxMonths' => (int) ($instMonthsData['months'] ?? 30),
]); ]);
} }
...@@ -367,7 +372,9 @@ class MemberController extends Controller ...@@ -367,7 +372,9 @@ class MemberController extends Controller
if (bccomp($amount, '0.01', 2) < 0) return $this->redirect('/members/' . $id)->withError('المبلغ غير صالح'); if (bccomp($amount, '0.01', 2) < 0) return $this->redirect('/members/' . $id)->withError('المبلغ غير صالح');
$months = ($paymentType === 'down_payment') ? min(30, max(1, (int) $request->post('installment_months', 30))) : null; $instMaxMonthsData = RuleEngine::get('INSTALLMENT_MAX_MONTHS');
$instMaxMonths = (int) ($instMaxMonthsData['months'] ?? 30);
$months = ($paymentType === 'down_payment') ? min($instMaxMonths, max(1, (int) $request->post('installment_months', $instMaxMonths))) : null;
// Cancel any pending individual addition_fee requests — the collective payment subsumes them // Cancel any pending individual addition_fee requests — the collective payment subsumes them
$pendingAdditions = $db->select( $pendingAdditions = $db->select(
......
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