Commit b9239f68 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix proration settings never saving or taking effect

Two bugs:
1. save() wrote bare key "allow_proration" but ProrationService reads
   dotted "enrollment.allow_proration" — now always writes "{group}.{key}"
2. loadAllSettings() tried to read bare keys but DB had dotted keys from
   seeder — now strips group prefix on read so UI always sees bare keys

Result: toggle saves correctly, ProrationService reads the live value,
mid-month enrollment now shows prorated fee (e.g. day 16 = 15/30 × fee).
Co-Authored-By: 's avatarClaude Sonnet 4.6 <noreply@anthropic.com>
parent 160e9785
...@@ -201,7 +201,11 @@ public function loadAllSettings(): void ...@@ -201,7 +201,11 @@ public function loadAllSettings(): void
$records = SystemSetting::withoutGlobalScope('academy') $records = SystemSetting::withoutGlobalScope('academy')
->where('academy_id', $academyId) ->where('academy_id', $academyId)
->get() ->get()
->mapWithKeys(fn ($s) => [$s->key => $s->value]) ->mapWithKeys(function ($s) {
// Strip group prefix so UI can use bare keys (e.g. "enrollment.allow_proration" → "allow_proration")
$bareKey = str_contains($s->key, '.') ? substr($s->key, strpos($s->key, '.') + 1) : $s->key;
return [$bareKey => $s->value];
})
->toArray(); ->toArray();
// Merge defaults with stored values // Merge defaults with stored values
...@@ -227,7 +231,8 @@ public function save(SettingsService $service): void ...@@ -227,7 +231,8 @@ public function save(SettingsService $service): void
default => 'string', default => 'string',
}; };
$service->set($key, $value, $group, $type); // Always store as dotted key so services can read "group.key"
$service->set("{$group}.{$key}", $value, $group, $type);
} }
session()->flash('success', __('تم حفظ الإعدادات بنجاح')); session()->flash('success', __('تم حفظ الإعدادات بنجاح'));
......
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