Files
ladill-queue/app/Services/Qms/TicketPresenter.php
T
isaaccladandCursor b5ffa499b9
Deploy Ladill Queue / deploy (push) Successful in 55s
Use industry-specific ticket priority labels.
Restaurant (and other packages) now show Rush, Reservation, VIP table, etc. instead of clinic terms like Emergency and Elderly.

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

82 lines
2.9 KiB
PHP

<?php
namespace App\Services\Qms;
use App\Models\Ticket;
use App\Services\Qms\TicketPriorities;
class TicketPresenter
{
/**
* @return array<string, mixed>
*/
public static function toArray(Ticket $ticket, bool $includeQr = true): array
{
$ticket->loadMissing(['serviceQueue', 'counter', 'assignedCounter', 'organization']);
$serving = $ticket->counter;
$assigned = $ticket->assignedCounter;
$point = $serving ?? $assigned;
return [
'uuid' => $ticket->uuid,
'ticket_number' => $ticket->ticket_number,
'status' => $ticket->status,
'priority' => $ticket->priority,
'priority_label' => TicketPriorities::label($ticket->organization, $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);
}
}