Commit 2156ed43 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix(membership): phone validation on edit + missing spouse fee API

- Add phone_mobile format validation in MemberController::update()
  (was only validated in store(), allowing invalid data via edit)
- Add missing SpouseController::calculateFee() method that the route
  /api/spouses/calculate-fee pointed to (returned 500)
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent ff5bbeed
......@@ -668,6 +668,12 @@ class MemberController extends Controller
}
}
if (isset($update['phone_mobile']) && $update['phone_mobile'] !== null) {
if (!preg_match('/^01[0125]\d{8}$/', $update['phone_mobile'])) {
return $this->redirect('/members/' . $id . '/edit')->withError('رقم المحمول غير صالح — يجب أن يكون 11 رقم ويبدأ بـ 01');
}
}
if (isset($update['referred_by_representative_id'])) {
$update['referred_by_representative_id'] = $update['referred_by_representative_id'] !== null && $update['referred_by_representative_id'] !== '' ? (int) $update['referred_by_representative_id'] : null;
}
......
......@@ -387,4 +387,20 @@ class SpouseController extends Controller
return $this->redirect("/members/{$memberId}")->withSuccess('تم إزالة الزوج/الزوجة');
}
public function calculateFee(Request $request): Response
{
$memberId = (int) $request->post('member_id', 0);
if (!$memberId) {
return $this->json(['error' => 'member_id مطلوب']);
}
$spouseData = [
'nationality' => trim((string) $request->post('nationality', 'مصري')),
'marriage_date' => trim((string) $request->post('marriage_date', '')) ?: null,
];
$result = SpouseFeeCalculator::calculate($memberId, $spouseData);
return $this->json($result);
}
}
\ No newline at end of file
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