Commit 02200eda authored by Mahmoud Aglan's avatar Mahmoud Aglan

feat(subscriptions): add SUB_ALL_YEARS_FROM_START toggle for full coverage

When enabled, all active members and dependents get subscriptions from
2023/2024 (system start) regardless of their actual join date. Toggle
via business_rules table — set enabled:false to revert to join-date logic.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 653f50e9
......@@ -255,6 +255,13 @@ final class SubscriptionDataMigration
private function createMissingSubscriptions(bool $dryRun): void
{
// When ON: everyone owes from system start (2023/2024) regardless of join date
$allFromStart = false;
try {
$rule = \App\Modules\Rules\Services\RuleEngine::get('SUB_ALL_YEARS_FROM_START');
$allFromStart = !empty($rule['enabled']);
} catch (\Throwable $e) {}
$members = $this->db->select(
"SELECT id, full_name_ar, created_at, membership_type
FROM members WHERE status = 'active' AND is_archived = 0 AND membership_type NOT IN ('honorary', 'seasonal')"
......@@ -262,7 +269,7 @@ final class SubscriptionDataMigration
foreach ($members as $member) {
$memberId = (int)$member['id'];
$memberJoinFY = max($this->dateToFY($member['created_at']), $this->firstFYStart);
$memberJoinFY = $allFromStart ? $this->firstFYStart : max($this->dateToFY($member['created_at']), $this->firstFYStart);
$this->stats['members_processed']++;
// Member subscription
......@@ -278,7 +285,7 @@ final class SubscriptionDataMigration
[$memberId]
);
foreach ($spouses as $sp) {
$startFY = max($this->dateToFY($sp['effective_date']), $memberJoinFY);
$startFY = $allFromStart ? $this->firstFYStart : max($this->dateToFY($sp['effective_date']), $memberJoinFY);
$this->ensureSubscriptionsExist(
$memberId, 'spouse', (int)$sp['id'], $sp['full_name_ar'],
$startFY, $dryRun
......@@ -292,7 +299,7 @@ final class SubscriptionDataMigration
[$memberId]
);
foreach ($children as $ch) {
$startFY = max($this->dateToFY($ch['effective_date']), $memberJoinFY);
$startFY = $allFromStart ? $this->firstFYStart : max($this->dateToFY($ch['effective_date']), $memberJoinFY);
$this->ensureSubscriptionsExist(
$memberId, 'child', (int)$ch['id'], $ch['full_name_ar'],
$startFY, $dryRun
......@@ -306,7 +313,7 @@ final class SubscriptionDataMigration
[$memberId]
);
foreach ($temps as $t) {
$startFY = max($this->dateToFY($t['effective_date']), $memberJoinFY);
$startFY = $allFromStart ? $this->firstFYStart : max($this->dateToFY($t['effective_date']), $memberJoinFY);
$this->ensureSubscriptionsExist(
$memberId, 'temporary', (int)$t['id'], $t['full_name_ar'],
$startFY, $dryRun
......
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