Commit 3f3e7b24 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Programs default active + auto-create default group on program creation

- Fix setup wizard CHECK violation: tax_percentage type 'number' → 'integer'
- Programs now default to 'active' status (not 'draft')
- Auto-create first group when program is created via TrainingProgramService
- Enable auto_create_groups_enabled setting in wizard for overflow auto-creation
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent b157adba
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace App\Domain\Training\Services; namespace App\Domain\Training\Services;
use App\Domain\Shared\Exceptions\DomainException; use App\Domain\Shared\Exceptions\DomainException;
use App\Domain\Training\Models\TrainingGroup;
use App\Domain\Training\Models\TrainingProgram; use App\Domain\Training\Models\TrainingProgram;
use App\Models\User; use App\Models\User;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
...@@ -19,13 +20,38 @@ public function create(array $data, User $actor): TrainingProgram ...@@ -19,13 +20,38 @@ public function create(array $data, User $actor): TrainingProgram
$slug = Str::limit($slug, 85, '') . '-' . Str::random(4); $slug = Str::limit($slug, 85, '') . '-' . Str::random(4);
} }
return TrainingProgram::create(array_merge($data, [ $program = TrainingProgram::create(array_merge($data, [
'slug' => $slug, 'slug' => $slug,
'created_by' => $actor->id, 'created_by' => $actor->id,
])); ]));
$this->createDefaultGroup($program, $actor);
return $program;
}); });
} }
private function createDefaultGroup(TrainingProgram $program, User $actor): TrainingGroup
{
$programName = $program->name_ar ?: $program->name;
return TrainingGroup::create([
'academy_id' => $program->academy_id,
'training_program_id' => $program->id,
'branch_id' => $program->branch_id,
'name' => "Group {$program->name} 1",
'name_ar' => "مجموعة {$programName} 1",
'max_capacity' => $program->max_participants,
'current_count' => 0,
'waitlist_count' => 0,
'status' => 'active',
'status_changed_at' => now(),
'start_date' => $program->program_start_date ?? now()->toDateString(),
'end_date' => $program->program_end_date,
'created_by' => $actor->id,
]);
}
public function update(TrainingProgram $program, array $data): TrainingProgram public function update(TrainingProgram $program, array $data): TrainingProgram
{ {
return DB::transaction(function () use ($program, $data) { return DB::transaction(function () use ($program, $data) {
......
...@@ -162,7 +162,7 @@ public function confirm(): void ...@@ -162,7 +162,7 @@ public function confirm(): void
'program_duration_weeks' => (int) $this->programDurationWeeks, 'program_duration_weeks' => (int) $this->programDurationWeeks,
'min_participants' => (int) $this->minParticipants, 'min_participants' => (int) $this->minParticipants,
'max_participants' => (int) $this->maxParticipants, 'max_participants' => (int) $this->maxParticipants,
'status' => 'draft', 'status' => 'active',
]; ];
app(TrainingProgramService::class)->create($data, auth()->user()); app(TrainingProgramService::class)->create($data, auth()->user());
......
...@@ -46,7 +46,7 @@ class ProgramForm extends Component ...@@ -46,7 +46,7 @@ class ProgramForm extends Component
public string $renewal_policy = 'manual_renew'; public string $renewal_policy = 'manual_renew';
public string $cancellation_policy = ''; public string $cancellation_policy = '';
public string $refund_policy = ''; public string $refund_policy = '';
public string $status = 'draft'; public string $status = 'active';
public bool $featured = false; public bool $featured = false;
// Pricing // Pricing
......
...@@ -989,7 +989,7 @@ public function completeSetup(): void ...@@ -989,7 +989,7 @@ public function completeSetup(): void
// Step 9: Financial & Pricing // Step 9: Financial & Pricing
$settingsService->set('currency_code', $this->defaultCurrency, 'financial', 'string'); $settingsService->set('currency_code', $this->defaultCurrency, 'financial', 'string');
$settingsService->set('tax_enabled', $this->taxEnabled ? '1' : '0', 'financial', 'boolean'); $settingsService->set('tax_enabled', $this->taxEnabled ? '1' : '0', 'financial', 'boolean');
$settingsService->set('tax_percentage', (string) $this->taxPercentage, 'financial', 'number'); $settingsService->set('tax_percentage', (string) $this->taxPercentage, 'financial', 'integer');
$settingsService->set('invoice_prefix', $this->invoicePrefix, 'financial', 'string'); $settingsService->set('invoice_prefix', $this->invoicePrefix, 'financial', 'string');
$settingsService->set('receipt_prefix', $this->receiptPrefix, 'financial', 'string'); $settingsService->set('receipt_prefix', $this->receiptPrefix, 'financial', 'string');
$settingsService->set('payment_due_days', (string) $this->paymentDueDays, 'financial', 'integer'); $settingsService->set('payment_due_days', (string) $this->paymentDueDays, 'financial', 'integer');
...@@ -1012,6 +1012,7 @@ public function completeSetup(): void ...@@ -1012,6 +1012,7 @@ public function completeSetup(): void
$settingsService->set('minor_age_threshold', (string) $this->minorAgeThreshold, 'enrollment', 'integer'); $settingsService->set('minor_age_threshold', (string) $this->minorAgeThreshold, 'enrollment', 'integer');
$settingsService->set('allow_waitlist', $this->allowWaitlist ? '1' : '0', 'enrollment', 'boolean'); $settingsService->set('allow_waitlist', $this->allowWaitlist ? '1' : '0', 'enrollment', 'boolean');
$settingsService->set('freeze_max_days', (string) $this->freezeMaxDays, 'enrollment', 'integer'); $settingsService->set('freeze_max_days', (string) $this->freezeMaxDays, 'enrollment', 'integer');
$settingsService->set('auto_create_groups_enabled', '1', 'enrollment', 'boolean');
$settingsService->set('email_enabled', $this->emailEnabled ? '1' : '0', 'notifications', 'boolean'); $settingsService->set('email_enabled', $this->emailEnabled ? '1' : '0', 'notifications', 'boolean');
$settingsService->set('sms_enabled', $this->smsEnabled ? '1' : '0', 'notifications', 'boolean'); $settingsService->set('sms_enabled', $this->smsEnabled ? '1' : '0', 'notifications', 'boolean');
......
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