Commit d4305ece authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix: programs created as draft + receptionist can't find academy-wide groups

1. ProgramForm now passes status to service — programs default 'active'
   (the property was set but never included in the data array, so the DB
   default 'draft' won)

2. Receptionist wizard now finds groups with branch_id=NULL (academy-wide
   programs) alongside branch-specific ones. Previously only exact branch
   match was checked, hiding programs created without a branch.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent a6c8abb9
......@@ -188,6 +188,7 @@ public function save(TrainingProgramService $service): void
'slug' => $this->slug ?: null,
'activity_id' => $this->activity_id,
'branch_id' => $this->branch_id,
'status' => $this->status,
'description' => $this->description ?: null,
'description_ar' => $this->description_ar ?: null,
'skill_level' => $this->skill_level,
......
......@@ -112,7 +112,9 @@ private function runPreflightChecks(): void
}
$hasPrograms = TrainingProgram::where('status', 'active')
->whereHas('groups', fn ($q) => $q->where('branch_id', $this->branchId)->whereIn('status', ['active', 'forming']))
->whereHas('groups', fn ($q) => $q->where(function ($sub) {
$sub->where('branch_id', $this->branchId)->orWhereNull('branch_id');
})->whereIn('status', ['active', 'forming']))
->exists();
if (!$hasPrograms) {
$errors[] = 'لا توجد برامج متاحة بها مجموعات نشطة في هذا الفرع';
......@@ -647,7 +649,9 @@ public function render()
if ($this->selected_activity_id) {
$programs = TrainingProgram::where('activity_id', $this->selected_activity_id)
->where('status', 'active')
->whereHas('groups', fn ($q) => $q->where('branch_id', $this->branchId)->whereIn('status', ['active', 'forming']))
->whereHas('groups', fn ($q) => $q->where(function ($sub) {
$sub->where('branch_id', $this->branchId)->orWhereNull('branch_id');
})->whereIn('status', ['active', 'forming']))
->orderBy('name_ar')
->get();
}
......
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