Deploy Ladill Queue / deploy (push) Successful in 56s
Phases 1–6: tickets, counters, displays, appointments, workflows, rules, analytics, reports, feedback, admin, device API, and Gitea deploy workflow for queue.ladill.com. Co-authored-by: Cursor <cursoragent@cursor.com>
42 lines
1016 B
PHP
42 lines
1016 B
PHP
<?php
|
|
|
|
namespace App\Services\Qms;
|
|
|
|
use App\Models\ServiceSession;
|
|
use App\Models\Ticket;
|
|
|
|
class ServiceSessionTracker
|
|
{
|
|
public function start(Ticket $ticket, ?string $staffRef = null): ServiceSession
|
|
{
|
|
return ServiceSession::create([
|
|
'owner_ref' => $ticket->owner_ref,
|
|
'ticket_id' => $ticket->id,
|
|
'counter_id' => $ticket->counter_id,
|
|
'staff_ref' => $staffRef,
|
|
'started_at' => now(),
|
|
]);
|
|
}
|
|
|
|
public function endForTicket(Ticket $ticket): ?ServiceSession
|
|
{
|
|
$session = ServiceSession::query()
|
|
->where('ticket_id', $ticket->id)
|
|
->whereNull('ended_at')
|
|
->latest('started_at')
|
|
->first();
|
|
|
|
if (! $session) {
|
|
return null;
|
|
}
|
|
|
|
$ended = now();
|
|
$session->update([
|
|
'ended_at' => $ended,
|
|
'duration_seconds' => $session->started_at->diffInSeconds($ended),
|
|
]);
|
|
|
|
return $session->fresh();
|
|
}
|
|
}
|