Commit a4fa3aed authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix(subscriptions): remove deceased/separated dependents from current year subscriptions

- Child/spouse death now auto-completes on creation (no manual "complete" click needed),
  which immediately archives the deceased and deletes their pending/overdue subscription rows
- Child separation (TransferProcessor) now deletes the separated child's unpaid subscription
  rows from the parent's membership when the transfer completes
- Spouse separation also removes their subscription rows
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent fdf6b018
...@@ -301,7 +301,9 @@ class DeathController extends Controller ...@@ -301,7 +301,9 @@ class DeathController extends Controller
return $this->redirect("/death/{$case->id}")->withSuccess('تم تسجيل حالة الوفاة وإرسالها لمراجعة مجلس الإدارة'); return $this->redirect("/death/{$case->id}")->withSuccess('تم تسجيل حالة الوفاة وإرسالها لمراجعة مجلس الإدارة');
} }
return $this->redirect("/death/{$case->id}")->withSuccess('تم تسجيل حالة الوفاة'); // Auto-complete child/spouse death (no fee, no further steps needed)
// This archives the deceased and removes their subscriptions immediately
return $this->complete($request, (string) $case->id);
} }
public function show(Request $request, string $id): Response public function show(Request $request, string $id): Response
......
...@@ -204,7 +204,7 @@ final class TransferProcessor ...@@ -204,7 +204,7 @@ final class TransferProcessor
null null
); );
// 6. Update source dependents — archive them from parent // 6. Update source dependents — archive them from parent + remove unpaid subscriptions
if ($request['child_id']) { if ($request['child_id']) {
$db->update('children', [ $db->update('children', [
'status' => 'separated', 'status' => 'separated',
...@@ -213,6 +213,10 @@ final class TransferProcessor ...@@ -213,6 +213,10 @@ final class TransferProcessor
'archived_at' => date('Y-m-d H:i:s'), 'archived_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'),
], '`id` = ?', [(int) $request['child_id']]); ], '`id` = ?', [(int) $request['child_id']]);
$db->query(
"DELETE FROM subscriptions WHERE member_id = ? AND person_type = 'child' AND person_id = ? AND status IN ('pending','overdue')",
[(int) $request['source_member_id'], (int) $request['child_id']]
);
} elseif ($request['spouse_id']) { } elseif ($request['spouse_id']) {
$db->update('spouses', [ $db->update('spouses', [
'status' => 'separated', 'status' => 'separated',
...@@ -220,6 +224,10 @@ final class TransferProcessor ...@@ -220,6 +224,10 @@ final class TransferProcessor
'archived_at' => date('Y-m-d H:i:s'), 'archived_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'),
], '`id` = ?', [(int) $request['spouse_id']]); ], '`id` = ?', [(int) $request['spouse_id']]);
$db->query(
"DELETE FROM subscriptions WHERE member_id = ? AND person_type = 'spouse' AND person_id = ? AND status IN ('pending','overdue')",
[(int) $request['source_member_id'], (int) $request['spouse_id']]
);
} }
// Child separation: create dependents specified on the form // Child separation: create dependents specified on the form
......
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