feat(admin): expose ticket refund states

This commit is contained in:
2026-09-10 16:10:17 -03:00
parent 18f739b712
commit f19bca64d0
14 changed files with 84 additions and 21 deletions

View File

@@ -124,11 +124,7 @@ class TicketFilterFormService
'required' => false,
'default' => null,
'placeholder' => 'Estado',
'options' => [
['value' => Ticket::STATUS_ACTIVE, 'label' => 'Activo'],
['value' => Ticket::STATUS_USED, 'label' => 'Usado'],
['value' => Ticket::STATUS_EXPIRED, 'label' => 'Vencido'],
],
'options' => Ticket::statusOptions(),
],
];
}

View File

@@ -236,11 +236,7 @@ class TicketFormService
?: $left['label'] <=> $right['label']);
return [
'statuses' => [
['value' => Ticket::STATUS_ACTIVE, 'label' => 'Activo'],
['value' => Ticket::STATUS_USED, 'label' => 'Usado'],
['value' => Ticket::STATUS_EXPIRED, 'label' => 'Vencido'],
],
'statuses' => Ticket::statusOptions(),
'categories' => array_values(array_map(
fn (array $category): array => [
'value' => $category['value'],

View File

@@ -25,6 +25,7 @@ class PurchaseItemResource extends JsonResource
'quantity' => (int) $this->cantidad,
'unit_price' => $this->formatMoney($this->precio_unitario),
'line_total' => $this->formatMoney($this->total),
'refunded_amount' => $this->formatMoney($this->refunded_amount),
'source_catalog_item_id' => $this->source_catalog_item_id,
'source_variant_id' => $this->source_variant_id,
'item_details' => [

View File

@@ -22,6 +22,7 @@ class SaleDetailResource extends JsonResource
'quantity' => (int) $item->cantidad,
'unit_price' => $this->formatMoney($item->precio_unitario),
'total' => $this->formatMoney($item->total),
'refunded_amount' => $this->formatMoney($item->refunded_amount),
])->values(),
'total' => $this->formatMoney($this->total),
];

View File

@@ -17,6 +17,7 @@ class SaleTicketResource extends JsonResource
'id' => $this->id,
'expires_at' => $this->getEffectiveExpiresAt(),
'status' => $this->status,
'status_label' => $this->status_label,
];
}
}

View File

@@ -32,11 +32,7 @@ class AdminAppTicketIndexRequest extends FormRequest
'status' => [
'sometimes',
'nullable',
Rule::in([
Ticket::STATUS_ACTIVE,
Ticket::STATUS_USED,
Ticket::STATUS_EXPIRED,
]),
Rule::in(Ticket::statuses()),
],
'page' => ['sometimes', 'integer', 'min:1'],
'per_page' => ['sometimes', 'integer', 'min:1', 'max:100'],

View File

@@ -16,6 +16,8 @@ class TicketResource extends JsonResource
'id' => $this->id,
'tenant_code' => $this->tenant_code,
'ticket' => $this->ticket,
'status' => $this->status,
'status_label' => $this->status_label,
'name' => $this->name,
'description' => $this->description,
'client' => $this->user?->nombre_apellido,

View File

@@ -31,6 +31,7 @@ class AdminAppTicketRowService
?? $ticket->sourceCatalogItem?->nombre
?? $ticket->name,
'amount' => $purchaseItem?->precio_unitario,
'refunded_amount' => $purchaseItem?->refunded_amount,
'client' => $purchaseItem?->purchase?->nombre_apellido ?? $ticket->user?->nombre_apellido,
'status' => $ticket->status,
'scanned_by' => $ticket->scannerUser?->nombre_apellido,
@@ -95,11 +96,7 @@ class AdminAppTicketRowService
return match ($type) {
'order_number' => '#'.$value,
'currency' => '$'.number_format((float) $value, 2, ',', '.'),
'status' => match ((string) $value) {
Ticket::STATUS_USED => 'Usado',
Ticket::STATUS_EXPIRED => 'Vencido',
default => 'Activo',
},
'status' => Ticket::statusLabel((string) $value),
default => (string) $value,
};
}

View File

@@ -255,13 +255,41 @@ class AdminAppTicketService
}
if ($status === Ticket::STATUS_USED) {
$query->whereNotNull('used_at');
$query
->whereNotNull('used_at')
->whereNull('disabled_at')
->whereNull('cancelled_at')
->whereNull('refunded_at');
return;
}
$timestampColumn = match ($status) {
Ticket::STATUS_DISABLED => 'disabled_at',
Ticket::STATUS_CANCELLED => 'cancelled_at',
Ticket::STATUS_REFUNDED => 'refunded_at',
default => null,
};
if ($timestampColumn !== null) {
$query->whereNotNull($timestampColumn);
if ($status === Ticket::STATUS_DISABLED) {
$query->whereNull('cancelled_at')->whereNull('refunded_at');
}
if ($status === Ticket::STATUS_CANCELLED) {
$query->whereNull('refunded_at');
}
return;
}
$matchingIds = (clone $query)
->whereNull('used_at')
->whereNull('disabled_at')
->whereNull('cancelled_at')
->whereNull('refunded_at')
->with(TicketValidityResolver::RELATIONS)
->get()
->filter(fn (Ticket $ticket): bool => $ticket->status === $status)