37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Enums\Permission;
|
|
use App\Models\Appointment;
|
|
use App\Services\Tenant\TenantContext;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\View\View;
|
|
|
|
class StaffDashboardController extends Controller
|
|
{
|
|
public function __invoke(Request $request, TenantContext $tenant): View
|
|
{
|
|
$business = $tenant->require();
|
|
$staff = $request->user()->staffProfiles()
|
|
->where('businessId', $business->id)
|
|
->with('role.permissions')
|
|
->first();
|
|
|
|
abort_unless($staff, 403);
|
|
|
|
$isOwner = $staff->hasPermission(Permission::ViewAllStaffAppointments);
|
|
$today = Carbon::now($business->timezone);
|
|
$appointments = Appointment::query()
|
|
->where('businessId', $business->id)
|
|
->when(! $isOwner, fn ($query) => $query->where('staffId', $staff->id))
|
|
->whereBetween('startAt', [$today->copy()->startOfDay()->utc(), $today->copy()->endOfDay()->utc()])
|
|
->with(['customer', 'staff.user', 'services.service'])
|
|
->orderBy('startAt')
|
|
->get();
|
|
|
|
return view('staff.dashboard', compact('business', 'staff', 'appointments', 'isOwner'));
|
|
}
|
|
}
|