Deploy Ladill Frontdesk / deploy (push) Failing after 26s
Enables staff roster, PIN/code kiosk flow, attendance reports, evacuation staff roll call, webhooks, branch mismatch warnings, and a linked-user My presence portal. Co-authored-by: Cursor <cursoragent@cursor.com>
116 lines
5.2 KiB
PHP
116 lines
5.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Frontdesk;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Frontdesk\Concerns\ScopesToAccount;
|
|
use App\Models\Employee;
|
|
use App\Models\EmployeePresence;
|
|
use App\Models\Visit;
|
|
use App\Services\Frontdesk\OrganizationResolver;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\View\View;
|
|
|
|
class DashboardController extends Controller
|
|
{
|
|
use ScopesToAccount;
|
|
|
|
public function index(Request $request): View
|
|
{
|
|
$this->authorizeAbility($request, 'dashboard.view');
|
|
$owner = $this->ownerRef($request);
|
|
$organization = $this->organization($request);
|
|
|
|
$visitQuery = Visit::owned($owner)->where('organization_id', $organization->id);
|
|
$this->scopeToBranch($request, $visitQuery);
|
|
|
|
$branchScope = app(OrganizationResolver::class)->branchScope($this->member($request));
|
|
$cacheKey = "fd:dashboard:{$owner}:{$organization->id}:".($branchScope ?? 'all');
|
|
|
|
$stats = Cache::remember($cacheKey, 60, function () use ($visitQuery, $owner, $organization, $branchScope) {
|
|
$today = (clone $visitQuery)->where(function ($q) {
|
|
$q->whereDate('checked_in_at', today())
|
|
->orWhereDate('scheduled_at', today());
|
|
});
|
|
|
|
$employeeIds = Employee::owned($owner)
|
|
->where('organization_id', $organization->id)
|
|
->where('active', true);
|
|
if ($branchScope !== null) {
|
|
$employeeIds->where('branch_id', $branchScope);
|
|
}
|
|
$employeeIds = $employeeIds->pluck('id');
|
|
|
|
$presenceQuery = EmployeePresence::query()->whereIn('employee_id', $employeeIds);
|
|
|
|
return [
|
|
'visitors_today' => (clone $today)->count(),
|
|
'currently_inside' => (clone $visitQuery)->currentlyInside()->count(),
|
|
'staff_on_site' => (clone $presenceQuery)->where('status', EmployeePresence::STATUS_ON_SITE)->count(),
|
|
'staff_stepped_out' => (clone $presenceQuery)->where('status', EmployeePresence::STATUS_STEPPED_OUT)->count(),
|
|
'expected_arrivals' => (clone $visitQuery)->whereIn('status', [
|
|
Visit::STATUS_EXPECTED,
|
|
Visit::STATUS_SCHEDULED,
|
|
Visit::STATUS_OVERDUE,
|
|
])->whereDate('scheduled_at', today())->count(),
|
|
'waiting' => (clone $visitQuery)->where('status', Visit::STATUS_WAITING)->count(),
|
|
'overdue' => (clone $visitQuery)->where('status', Visit::STATUS_OVERDUE)->count(),
|
|
'checked_out_today' => (clone $visitQuery)->where('status', Visit::STATUS_CHECKED_OUT)
|
|
->whereDate('checked_out_at', today())->count(),
|
|
'deliveries_today' => (clone $visitQuery)->where('visitor_type', 'delivery')
|
|
->whereDate('checked_in_at', today())->count(),
|
|
'contractors_today' => (clone $visitQuery)->where('visitor_type', 'contractor')
|
|
->whereDate('checked_in_at', today())->count(),
|
|
'pending_approvals' => (clone $visitQuery)->where('status', Visit::STATUS_WAITING)
|
|
->whereNull('checked_in_at')
|
|
->where(function ($q) {
|
|
$q->whereJsonContains('contractor_details', ['_awaiting_approval' => true])
|
|
->orWhereJsonContains('delivery_details', ['_awaiting_approval' => true]);
|
|
})->count(),
|
|
];
|
|
});
|
|
|
|
$currentVisitors = (clone $visitQuery)->currentlyInside()
|
|
->with(['visitor', 'host'])
|
|
->latest('checked_in_at')
|
|
->limit(10)
|
|
->get();
|
|
|
|
$expectedVisitors = (clone $visitQuery)
|
|
->whereIn('status', [Visit::STATUS_EXPECTED, Visit::STATUS_SCHEDULED, Visit::STATUS_WAITING, Visit::STATUS_OVERDUE])
|
|
->whereDate('scheduled_at', today())
|
|
->with(['visitor', 'host'])
|
|
->orderBy('scheduled_at')
|
|
->limit(10)
|
|
->get();
|
|
|
|
$pendingApprovals = (clone $visitQuery)
|
|
->where('status', Visit::STATUS_WAITING)
|
|
->whereNull('checked_in_at')
|
|
->where(function ($q) {
|
|
$q->whereJsonContains('contractor_details', ['_awaiting_approval' => true])
|
|
->orWhereJsonContains('delivery_details', ['_awaiting_approval' => true]);
|
|
})
|
|
->with(['visitor', 'host'])
|
|
->latest()
|
|
->limit(10)
|
|
->get();
|
|
|
|
$staffSteppedOut = EmployeePresence::query()
|
|
->where('status', EmployeePresence::STATUS_STEPPED_OUT)
|
|
->whereHas('employee', function ($q) use ($owner, $organization, $request) {
|
|
$q->owned($owner)->where('organization_id', $organization->id)->where('active', true);
|
|
$this->scopeToBranch($request, $q, 'branch_id');
|
|
})
|
|
->with('employee')
|
|
->orderByDesc('last_event_at')
|
|
->limit(10)
|
|
->get();
|
|
|
|
return view('frontdesk.dashboard', compact(
|
|
'stats', 'currentVisitors', 'expectedVisitors', 'pendingApprovals', 'staffSteppedOut', 'organization',
|
|
));
|
|
}
|
|
}
|