Commit e7aa9385 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix(waiver): stop transferring source dependents to target member

The waiver system was incorrectly moving spouses, children, and
temporary members from the source to the target. The target member
enters their own new dependents — source dependents should be archived
with the source member, not transferred.

Also removed transfer of subscriptions, installments, fines, documents,
and payment requests since debt check ensures those are cleared before
execution anyway.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent aa012626
...@@ -918,57 +918,45 @@ final class WaiverProcessor ...@@ -918,57 +918,45 @@ final class WaiverProcessor
} }
/** /**
* Transfer active data from source member to target member. * Archive source member's active data after waiver.
* Called AFTER snapshot is taken so the archive preserves original state. * Dependents belong to the source — they do NOT transfer to the target.
* Payments and paid subscriptions stay with the archived source (historical record). * The target member already has their own dependents entered during the waiver process.
* Only pending obligations and active dependents move to the new owner. * Financial obligations should already be cleared (debt check runs before execution).
*/ */
private static function transferActiveData($db, int $sourceId, int $targetId): void private static function transferActiveData($db, int $sourceId, int $targetId): void
{ {
$ts = date('Y-m-d H:i:s'); $ts = date('Y-m-d H:i:s');
// Dependents (only active/non-archived) // Archive source's dependents — they do NOT move to the target member
$db->query( $db->query(
"UPDATE spouses SET member_id = ?, updated_at = ? WHERE member_id = ? AND is_archived = 0", "UPDATE spouses SET is_archived = 1, status = 'archived', updated_at = ? WHERE member_id = ? AND is_archived = 0",
[$targetId, $ts, $sourceId] [$ts, $sourceId]
); );
$db->query( $db->query(
"UPDATE children SET member_id = ?, updated_at = ? WHERE member_id = ? AND is_archived = 0", "UPDATE children SET is_archived = 1, status = 'archived', updated_at = ? WHERE member_id = ? AND is_archived = 0",
[$targetId, $ts, $sourceId] [$ts, $sourceId]
); );
$db->query( $db->query(
"UPDATE temporary_members SET member_id = ?, updated_at = ? WHERE member_id = ? AND is_archived = 0", "UPDATE temporary_members SET is_archived = 1, status = 'archived', updated_at = ? WHERE member_id = ? AND is_archived = 0",
[$targetId, $ts, $sourceId] [$ts, $sourceId]
); );
// Subscriptions: only pending/overdue move (paid/exempt are historical → stay with archived source) // Cancel any remaining pending subscriptions on source (should already be paid/cleared)
$db->query( $db->query(
"UPDATE subscriptions SET member_id = ? WHERE member_id = ? AND status IN ('pending','overdue')", "UPDATE subscriptions SET status = 'cancelled', updated_at = ? WHERE member_id = ? AND status IN ('pending','overdue')",
[$targetId, $sourceId] [$ts, $sourceId]
); );
// Active installment plans move to new owner // Archive documents with the source member
$db->query( $db->query(
"UPDATE installment_plans SET member_id = ? WHERE member_id = ? AND status = 'active'", "UPDATE documents SET is_archived = 1, updated_at = ? WHERE member_id = ? AND is_archived = 0",
[$targetId, $sourceId] [$ts, $sourceId]
); );
// Unpaid fines move to new owner // Void any pending payment requests (debts should be cleared already)
$db->query( $db->query(
"UPDATE fines SET member_id = ? WHERE member_id = ? AND status IN ('imposed','appealed')", "UPDATE payment_requests SET is_voided = 1, updated_at = ? WHERE member_id = ? AND status = 'pending' AND is_voided = 0",
[$targetId, $sourceId] [$ts, $sourceId]
);
// Documents (active ones)
$db->query(
"UPDATE documents SET member_id = ? WHERE member_id = ? AND is_archived = 0",
[$targetId, $sourceId]
);
// Payment requests (pending ones move to new owner)
$db->query(
"UPDATE payment_requests SET member_id = ? WHERE member_id = ? AND is_voided = 0",
[$targetId, $sourceId]
); );
} }
} }
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