Add employee presence with kiosk sign-in, QR badges, and mobile step-out.
Deploy Ladill Frontdesk / deploy (push) Failing after 26s
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>
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Frontdesk;
|
||||
|
||||
use App\Models\EmployeePresence;
|
||||
use App\Models\EmployeePresenceEvent;
|
||||
use App\Models\Organization;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class EmployeeReportService
|
||||
{
|
||||
/** @return array<string, int> */
|
||||
public function summary(
|
||||
string $ownerRef,
|
||||
Organization $organization,
|
||||
Carbon $from,
|
||||
Carbon $to,
|
||||
?int $branchId = null,
|
||||
): array {
|
||||
$events = $this->eventsQuery($ownerRef, $organization->id, $from, $to, $branchId);
|
||||
|
||||
return [
|
||||
'sign_ins' => (clone $events)->where('event', EmployeePresenceEvent::EVENT_SIGN_IN)->count(),
|
||||
'sign_outs' => (clone $events)->where('event', EmployeePresenceEvent::EVENT_SIGN_OUT)->count(),
|
||||
'step_outs' => (clone $events)->where('event', EmployeePresenceEvent::EVENT_STEP_OUT)->count(),
|
||||
'staff_on_site_now' => EmployeePresence::query()
|
||||
->where('status', EmployeePresence::STATUS_ON_SITE)
|
||||
->whereHas('employee', function ($q) use ($ownerRef, $organization, $branchId) {
|
||||
$q->owned($ownerRef)->where('organization_id', $organization->id)->where('active', true);
|
||||
if ($branchId) {
|
||||
$q->where('branch_id', $branchId);
|
||||
}
|
||||
})
|
||||
->count(),
|
||||
];
|
||||
}
|
||||
|
||||
/** @return Collection<int, EmployeePresenceEvent> */
|
||||
public function attendanceLog(
|
||||
string $ownerRef,
|
||||
Organization $organization,
|
||||
Carbon $from,
|
||||
Carbon $to,
|
||||
?int $branchId = null,
|
||||
): Collection {
|
||||
return $this->eventsQuery($ownerRef, $organization->id, $from, $to, $branchId)
|
||||
->with(['employee'])
|
||||
->orderByDesc('created_at')
|
||||
->limit(200)
|
||||
->get();
|
||||
}
|
||||
|
||||
/** @return Collection<int, EmployeePresenceEvent> */
|
||||
public function stepOutLog(
|
||||
string $ownerRef,
|
||||
Organization $organization,
|
||||
Carbon $from,
|
||||
Carbon $to,
|
||||
?int $branchId = null,
|
||||
): Collection {
|
||||
return $this->eventsQuery($ownerRef, $organization->id, $from, $to, $branchId)
|
||||
->where('event', EmployeePresenceEvent::EVENT_STEP_OUT)
|
||||
->with(['employee'])
|
||||
->orderByDesc('created_at')
|
||||
->limit(100)
|
||||
->get();
|
||||
}
|
||||
|
||||
protected function eventsQuery(
|
||||
string $ownerRef,
|
||||
int $organizationId,
|
||||
Carbon $from,
|
||||
Carbon $to,
|
||||
?int $branchId,
|
||||
) {
|
||||
$query = EmployeePresenceEvent::owned($ownerRef)
|
||||
->where('organization_id', $organizationId)
|
||||
->whereBetween('created_at', [$from, $to]);
|
||||
|
||||
if ($branchId) {
|
||||
$query->where('branch_id', $branchId);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user