fix(tickets): show numeric id and remove date column

This commit is contained in:
ncoronel 2026-09-01 11:53:47 -03:00
parent 58b15f3026
commit 80b8707771
6 changed files with 25 additions and 36 deletions

View File

@ -12,8 +12,8 @@ class AdminAppTicketColumnService
public function columns(Tenant $tenant): array
{
$keys = $tenant->codigo === self::FIESTA_FUTBOL_INFANTIL
? ['order_number', 'category', 'product', 'type', 'amount', 'client', 'ticket', 'date', 'status', 'scanned_by']
: ['order_number', 'product', 'amount', 'client', 'ticket', 'date', 'status', 'scanned_by'];
? ['order_number', 'category', 'product', 'type', 'amount', 'client', 'id', 'status', 'scanned_by']
: ['order_number', 'product', 'amount', 'client', 'id', 'status', 'scanned_by'];
$columns = array_map(fn (string $key): array => $this->definitions()[$key], $keys);
@ -31,8 +31,7 @@ class AdminAppTicketColumnService
'product' => '15%',
'amount' => '10%',
'client' => '15%',
'ticket' => '19%',
'date' => '11%',
'id' => '8%',
'status' => '8%',
'scanned_by' => '11%',
];
@ -75,8 +74,7 @@ class AdminAppTicketColumnService
'type' => $this->column('type', 'Tipo', 'text', '8%', 18),
'amount' => $this->column('amount', 'Importe', 'currency', '9%', 15),
'client' => $this->column('client', 'Cliente', 'text', '13%', 30),
'ticket' => $this->column('ticket', 'ID', 'text', '14.5%', 39),
'date' => $this->column('date', 'Fecha', 'date', '9.5%', 20),
'id' => $this->column('id', 'ID', 'text', '7%', 12),
'status' => $this->column('status', 'Estado', 'status', '7%', 13),
'scanned_by' => $this->column('scanned_by', 'Escaneado por', 'text', '9%', 28),
];

View File

@ -5,8 +5,6 @@ namespace App\Domains\Ticket\Services;
use App\Domains\Catalog\Models\ItemAttribute;
use App\Domains\Purchase\Models\PurchaseItem;
use App\Domains\Ticket\Models\Ticket;
use Carbon\Carbon;
use Carbon\CarbonInterface;
use Illuminate\Support\Collection;
class AdminAppTicketRowService
@ -35,7 +33,6 @@ class AdminAppTicketRowService
?? $ticket->name,
'amount' => $purchaseItem?->precio_unitario,
'client' => $ticket->sourcePurchase?->nombre_apellido ?? $ticket->user?->nombre_apellido,
'date' => $ticket->sourcePurchase?->created_at,
'status' => $ticket->status,
'scanned_by' => $ticket->scannerUser?->nombre_apellido,
'variant_properties' => $this->variantProperties($ticket),
@ -55,8 +52,7 @@ class AdminAppTicketRowService
'type' => $presentation['type'],
'amount' => $details['amount'] === null ? null : (float) $details['amount'],
'client' => $details['client'] ?? 'Sin nombre',
'ticket' => $ticket->ticket,
'date' => $details['date'],
'id' => $ticket->id,
'status' => $details['status'],
'scanned_by' => $details['scanned_by'] ?? '-',
];
@ -98,8 +94,6 @@ class AdminAppTicketRowService
return match ($type) {
'order_number' => '#'.$value,
'currency' => '$'.number_format((float) $value, 2, ',', '.'),
'date' => ($value instanceof CarbonInterface ? $value : Carbon::parse((string) $value))
->copy()->timezone($timeZone)->format('d/m/Y H:i'),
'status' => match ((string) $value) {
Ticket::STATUS_USED => 'Usado',
Ticket::STATUS_EXPIRED => 'Vencido',

View File

@ -3,7 +3,6 @@
namespace App\Domains\Ticket\Services;
use App\Domains\Auth\Models\User;
use App\Domains\Purchase\Models\Purchase;
use App\Domains\Purchase\Models\PurchaseItem;
use App\Domains\Tenant\Models\Tenant;
use App\Domains\Ticket\Models\Ticket;
@ -208,10 +207,7 @@ class AdminAppTicketService
$sortExpression = match ($sortBy) {
'order_number' => 'tickets.source_purchase_id',
'ticket' => 'tickets.ticket',
'date' => Purchase::query()
->select('created_at')
->whereColumn('compras.id', 'tickets.source_purchase_id'),
'id' => 'tickets.id',
'amount' => $this->purchaseItemSortQuery('precio_unitario'),
'scanned_by' => User::query()
->select('nombre_apellido')

View File

@ -251,8 +251,7 @@ class AdminAppTicketFilterFormControllerTest extends TestCase
['key' => 'product', 'label' => 'Producto', 'type' => 'text', 'sortable' => true, 'sort_param' => 'product', 'width' => '15%'],
['key' => 'amount', 'label' => 'Importe', 'type' => 'currency', 'sortable' => true, 'sort_param' => 'amount', 'width' => '10%'],
['key' => 'client', 'label' => 'Cliente', 'type' => 'text', 'sortable' => true, 'sort_param' => 'client', 'width' => '15%'],
['key' => 'ticket', 'label' => 'ID', 'type' => 'text', 'sortable' => true, 'sort_param' => 'ticket', 'width' => '19%'],
['key' => 'date', 'label' => 'Fecha', 'type' => 'date', 'sortable' => true, 'sort_param' => 'date', 'width' => '11%'],
['key' => 'id', 'label' => 'ID', 'type' => 'text', 'sortable' => true, 'sort_param' => 'id', 'width' => '8%'],
['key' => 'status', 'label' => 'Estado', 'type' => 'status', 'sortable' => true, 'sort_param' => 'status', 'width' => '8%'],
['key' => 'scanned_by', 'label' => 'Escaneado por', 'type' => 'text', 'sortable' => true, 'sort_param' => 'scanned_by', 'width' => '11%'],
];

View File

@ -70,8 +70,11 @@ class AdminAppTicketControllerTest extends TestCase
->assertJsonCount(1, 'data')
->assertJsonPath('data.0.id', $ticket->id)
->assertJsonPath('data.0.tenant_code', $tenant->codigo)
->assertJsonPath('data.0.values.ticket', $ticket->ticket)
->assertJsonPath('data.0.values.id', $ticket->id)
->assertJsonPath('data.0.values.status', Ticket::STATUS_ACTIVE)
->assertJsonMissingPath('data.0.values.ticket')
->assertJsonMissingPath('data.0.values.date')
->assertJsonMissingPath('data.0.date')
->assertJsonPath('meta.total', 1);
}
@ -96,34 +99,34 @@ class AdminAppTicketControllerTest extends TestCase
->assertJsonPath('data.0.ticket', $matching->ticket);
}
public function test_it_sorts_the_complete_filtered_result_before_paginating(): void
public function test_it_sorts_by_ticket_id_before_paginating(): void
{
$tenant = $this->createTenant('fiesta_futbol_infantil');
$admin = $this->createAdminAppUser($tenant);
$this->grantTicketsMenu($tenant);
Sanctum::actingAs($admin);
foreach (['ticket-c', 'ticket-a', 'ticket-d', 'ticket-b'] as $value) {
$this->createTicket($tenant, $admin)->update(['ticket' => $value]);
}
$ids = collect(range(1, 4))
->map(fn (): int => $this->createTicket($tenant, $admin)->id)
->all();
$query = http_build_query([
'sort_by' => 'ticket',
'sort_by' => 'id',
'sort_direction' => 'asc',
'per_page' => 2,
]);
$this->getJson('/api/v1/adminapp/tenant/tickets?'.$query)
->assertOk()
->assertJsonPath('data.0.values.ticket', 'ticket-a')
->assertJsonPath('data.1.values.ticket', 'ticket-b')
->assertJsonPath('data.0.values.id', $ids[0])
->assertJsonPath('data.1.values.id', $ids[1])
->assertJsonPath('meta.total', 4)
->assertJsonPath('meta.last_page', 2);
$this->getJson('/api/v1/adminapp/tenant/tickets?'.$query.'&page=2')
->assertOk()
->assertJsonPath('data.0.values.ticket', 'ticket-c')
->assertJsonPath('data.1.values.ticket', 'ticket-d');
->assertJsonPath('data.0.values.id', $ids[2])
->assertJsonPath('data.1.values.id', $ids[3]);
}
public function test_it_rejects_sort_columns_not_enabled_for_the_tenant(): void

View File

@ -55,8 +55,8 @@ class AdminAppTicketExportServiceTest extends TestCase
$this->assertSame('#15', $sheet->getCell('A2')->getValue());
$this->assertSame('Cena', $sheet->getCell('D2')->getValue());
$this->assertSame(8000.0, $sheet->getCell('E2')->getValue());
$this->assertSame('00000000-0000-0000-0000-000000000001', $sheet->getCell('G2')->getValue());
$this->assertSame('Usado', $sheet->getCell('I2')->getValue());
$this->assertSame('25', $sheet->getCell('G2')->getValue());
$this->assertSame('Usado', $sheet->getCell('H2')->getValue());
} finally {
@unlink($path);
}
@ -91,9 +91,9 @@ class AdminAppTicketExportServiceTest extends TestCase
])->render();
$this->assertStringContainsString('Generado el 24/08/2026 13:53', $html);
$this->assertStringContainsString('00000000-0000-0000-0000-000000000001', $html);
$this->assertStringContainsString('25', $html);
$this->assertStringNotContainsString('00000000-0000-0000-0000-000000000001', $html);
$this->assertStringContainsString('Cena', $html);
$this->assertStringContainsString('24/08/2026 13:53', $html);
}
private function reportService(): AdminAppTicketReportService
@ -114,8 +114,7 @@ class AdminAppTicketExportServiceTest extends TestCase
'type' => 'Cena',
'amount' => 8000.0,
'client' => 'Cliente Test',
'ticket' => '00000000-0000-0000-0000-000000000001',
'date' => now(),
'id' => 25,
'status' => 'used',
'scanned_by' => 'Admin Test',
];