Files
ladill-queue/app/Services/Qms/TicketPresenter.php
T
isaaccladandCursor 0854b431bc
Deploy Ladill Queue / deploy (push) Successful in 2m17s
Add service-point routing so call-next cannot steal assigned tickets.
Counters gain destination/staff metadata; tickets can be pre-assigned to a
service point with assigned_only queues for healthcare while shared_pool
preserves generic bank/government behavior. Display and announcements expose
ticket, staff, and destination clearly for Care and public boards.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-17 17:21:56 +00:00

80 lines
2.8 KiB
PHP

<?php
namespace App\Services\Qms;
use App\Models\Ticket;
class TicketPresenter
{
/**
* @return array<string, mixed>
*/
public static function toArray(Ticket $ticket, bool $includeQr = true): array
{
$ticket->loadMissing(['serviceQueue', 'counter', 'assignedCounter']);
$serving = $ticket->counter;
$assigned = $ticket->assignedCounter;
$point = $serving ?? $assigned;
return [
'uuid' => $ticket->uuid,
'ticket_number' => $ticket->ticket_number,
'status' => $ticket->status,
'priority' => $ticket->priority,
'position' => $ticket->position,
'customer_name' => $ticket->customer_name,
'customer_phone' => $ticket->customer_phone,
'source' => $ticket->source,
'estimated_wait_seconds' => $ticket->estimated_wait_seconds,
'issued_at' => $ticket->issued_at?->toIso8601String(),
'called_at' => $ticket->called_at?->toIso8601String(),
'queue' => $ticket->serviceQueue ? [
'uuid' => $ticket->serviceQueue->uuid,
'name' => $ticket->serviceQueue->name,
'prefix' => $ticket->serviceQueue->prefix,
'color' => $ticket->serviceQueue->color,
'routing_mode' => $ticket->serviceQueue->routingMode(),
] : null,
'counter' => $serving ? self::serializePoint($serving) : null,
'assigned_counter' => $assigned ? self::serializePoint($assigned) : null,
'destination' => $point?->displayDestination(),
'staff_display_name' => $point?->staff_display_name,
'announcement_text' => self::announcementText($ticket, $point),
'track_url' => $includeQr ? route('qms.mobile.show', $ticket->qr_token) : null,
'barcode' => $ticket->barcode,
];
}
/**
* @return array<string, mixed>
*/
public static function serializePoint(\App\Models\Counter $counter): array
{
return [
'uuid' => $counter->uuid,
'name' => $counter->name,
'destination' => $counter->displayDestination(),
'staff_ref' => $counter->staff_ref,
'staff_display_name' => $counter->staff_display_name,
'code' => $counter->code,
];
}
public static function announcementText(Ticket $ticket, ?\App\Models\Counter $point): ?string
{
if (! $point) {
return $ticket->ticket_number;
}
$parts = array_values(array_filter([
$ticket->ticket_number,
$point->staff_display_name ?: null,
$ticket->serviceQueue?->name,
$point->displayDestination(),
]));
return implode(', ', $parts);
}
}