Commit d6f1c86b authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix group print crash + add delete button with full cascade

- GroupSchedulePrintController used $this->authorize() but Laravel 13's base Controller has no AuthorizesRequests trait — switched to Gate::authorize()
- Added deleteGroup() to GroupList with full cascade: sessions (attendance auto-cascades), schedules, enrollments, waitlists, then the group itself
- Delete button with wire:confirm for Arabic confirmation prompt, gated behind groups.delete permission
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent d4305ece
...@@ -3,13 +3,13 @@ ...@@ -3,13 +3,13 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Domain\Training\Models\TrainingGroup; use App\Domain\Training\Models\TrainingGroup;
use Illuminate\Http\Request; use Illuminate\Support\Facades\Gate;
class GroupSchedulePrintController extends Controller class GroupSchedulePrintController extends Controller
{ {
public function __invoke(TrainingGroup $group) public function __invoke(TrainingGroup $group)
{ {
$this->authorize('groups.list'); Gate::authorize('groups.list');
$group->load(['program', 'schedules', 'enrollments' => function ($q) { $group->load(['program', 'schedules', 'enrollments' => function ($q) {
$q->where('status', 'active')->with('participant'); $q->where('status', 'active')->with('participant');
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
use App\Domain\Training\Models\TrainingProgram; use App\Domain\Training\Models\TrainingProgram;
use App\Domain\Training\Services\TrainingGroupService; use App\Domain\Training\Services\TrainingGroupService;
use App\Domain\Shared\Exceptions\DomainException; use App\Domain\Shared\Exceptions\DomainException;
use Illuminate\Support\Facades\DB;
use Livewire\Attributes\Layout; use Livewire\Attributes\Layout;
use Livewire\Attributes\Title; use Livewire\Attributes\Title;
use Livewire\Attributes\Url; use Livewire\Attributes\Url;
...@@ -71,6 +72,28 @@ public function changeStatus(string $uuid, string $newStatus, TrainingGroupServi ...@@ -71,6 +72,28 @@ public function changeStatus(string $uuid, string $newStatus, TrainingGroupServi
} }
} }
public function deleteGroup(string $uuid): void
{
$this->authorize('groups.delete');
$group = TrainingGroup::where('uuid', $uuid)->firstOrFail();
try {
DB::transaction(function () use ($group) {
// Sessions cascade-delete their attendance records automatically
$group->sessions()->forceDelete();
$group->schedules()->delete();
$group->enrollments()->forceDelete();
$group->waitlists()->delete();
$group->forceDelete();
});
session()->flash('success', __('تم حذف المجموعة وجميع البيانات المرتبطة بها'));
} catch (\Throwable $e) {
session()->flash('error', __('فشل حذف المجموعة: ') . $e->getMessage());
}
}
public function render() public function render()
{ {
$branchId = $this->getActiveBranchId(); $branchId = $this->getActiveBranchId();
......
...@@ -92,6 +92,11 @@ class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:rin ...@@ -92,6 +92,11 @@ class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:rin
class="text-green-600 hover:text-green-800 text-sm">{{ __('تعديل') }}</a> class="text-green-600 hover:text-green-800 text-sm">{{ __('تعديل') }}</a>
@endcan @endcan
<a href="{{ route('groups.print', $group) }}" target="_blank" class="text-green-600 hover:text-green-700 active:text-green-800 text-sm transition-colors">{{ __('طباعة') }}</a> <a href="{{ route('groups.print', $group) }}" target="_blank" class="text-green-600 hover:text-green-700 active:text-green-800 text-sm transition-colors">{{ __('طباعة') }}</a>
@can('groups.delete')
<button wire:click="deleteGroup('{{ $group->uuid }}')"
wire:confirm="{{ __('هل أنت متأكد من حذف هذه المجموعة؟ سيتم حذف جميع الجداول والحصص والتسجيلات المرتبطة بها نهائيًا.') }}"
class="text-red-600 hover:text-red-800 text-sm">{{ __('حذف') }}</button>
@endcan
</div> </div>
</td> </td>
</tr> </tr>
......
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