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>
91 lines
4.0 KiB
PHP
91 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Frontdesk;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Frontdesk\Concerns\ScopesToAccount;
|
|
use App\Models\Visit;
|
|
use App\Services\Frontdesk\BadgeRenderService;
|
|
use App\Services\Frontdesk\EmployeeReportService;
|
|
use App\Services\Frontdesk\FrontdeskPermissions;
|
|
use App\Services\Frontdesk\OrganizationResolver;
|
|
use App\Services\Frontdesk\ReportService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\View\View;
|
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
|
|
class ReportController extends Controller
|
|
{
|
|
use ScopesToAccount;
|
|
|
|
public function index(Request $request, ReportService $reports, EmployeeReportService $employeeReports): View
|
|
{
|
|
$this->authorizeAbility($request, 'reports.view');
|
|
$organization = $this->organization($request);
|
|
$owner = $this->ownerRef($request);
|
|
|
|
[$from, $to] = $this->dateRange($request);
|
|
$branchId = app(OrganizationResolver::class)->branchScope($this->member($request));
|
|
|
|
return view('frontdesk.reports.index', [
|
|
'organization' => $organization,
|
|
'from' => $from->toDateString(),
|
|
'to' => $to->toDateString(),
|
|
'summary' => $reports->summary($owner, $organization, $from, $to, $branchId),
|
|
'peakHours' => $reports->peakHours($owner, $organization, $from, $to, $branchId),
|
|
'departments' => $reports->visitsByDepartment($owner, $organization, $from, $to, $branchId),
|
|
'frequentVisitors' => $reports->frequentVisitors($owner, $organization),
|
|
'security' => $reports->securityIncidents($owner, $organization, $from, $to),
|
|
'dailyCounts' => $reports->dailyCounts($owner, $organization, $from, $to, $branchId),
|
|
'employeeSummary' => $employeeReports->summary($owner, $organization, $from, $to, $branchId),
|
|
'employeeAttendance' => $employeeReports->attendanceLog($owner, $organization, $from, $to, $branchId),
|
|
'employeeStepOuts' => $employeeReports->stepOutLog($owner, $organization, $from, $to, $branchId),
|
|
'canExport' => app(FrontdeskPermissions::class)->can($this->member($request), 'reports.export'),
|
|
]);
|
|
}
|
|
|
|
public function export(Request $request, ReportService $reports): StreamedResponse
|
|
{
|
|
$this->authorizeAbility($request, 'reports.export');
|
|
$organization = $this->organization($request);
|
|
$owner = $this->ownerRef($request);
|
|
|
|
[$from, $to] = $this->dateRange($request);
|
|
$branchId = app(OrganizationResolver::class)->branchScope($this->member($request));
|
|
$summary = $reports->summary($owner, $organization, $from, $to, $branchId);
|
|
$departments = $reports->visitsByDepartment($owner, $organization, $from, $to, $branchId);
|
|
|
|
$filename = 'frontdesk-report-'.$from->format('Y-m-d').'-'.$to->format('Y-m-d').'.csv';
|
|
|
|
return response()->streamDownload(function () use ($summary, $departments, $from, $to) {
|
|
$handle = fopen('php://output', 'w');
|
|
fputcsv($handle, ['Frontdesk report', $from->toDateString(), 'to', $to->toDateString()]);
|
|
fputcsv($handle, []);
|
|
fputcsv($handle, ['Metric', 'Value']);
|
|
foreach ($summary as $key => $value) {
|
|
fputcsv($handle, [str_replace('_', ' ', $key), $value]);
|
|
}
|
|
fputcsv($handle, []);
|
|
fputcsv($handle, ['Department', 'Visits']);
|
|
foreach ($departments as $row) {
|
|
fputcsv($handle, [$row->department, $row->count]);
|
|
}
|
|
fclose($handle);
|
|
}, $filename, ['Content-Type' => 'text/csv']);
|
|
}
|
|
|
|
/** @return array{0: Carbon, 1: Carbon} */
|
|
protected function dateRange(Request $request): array
|
|
{
|
|
$from = $request->filled('from')
|
|
? Carbon::parse($request->string('from'))->startOfDay()
|
|
: now()->subDays(30)->startOfDay();
|
|
$to = $request->filled('to')
|
|
? Carbon::parse($request->string('to'))->endOfDay()
|
|
: now()->endOfDay();
|
|
|
|
return [$from, $to];
|
|
}
|
|
}
|