feat(event): add effective date resolution for rescheduled events and update tests

This commit is contained in:
2026-09-16 14:27:35 -03:00
parent 9aa0c1f3b9
commit f8a3296821
7 changed files with 96 additions and 25 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Domains\Ticket\Services;
use App\Domains\Catalog\Models\ItemAttribute;
use App\Domains\Event\Models\EventDate;
use App\Domains\Ticket\Models\Ticket;
use Illuminate\Support\Collection;
@@ -11,12 +12,12 @@ class AdminAppTicketRowService
private const FIESTA_FUTBOL_INFANTIL = 'fiesta_futbol_infantil';
private const CATEGORY_PRESENTATIONS = [
'alojamientos' => ['category' => 'Camping', 'product' => 'tipo_alojamiento', 'type' => null, 'date' => null, 'size' => null],
'camping' => ['category' => null, 'product' => 'tipo_alojamiento', 'type' => null, 'date' => null, 'size' => null],
'entradas' => ['category' => null, 'product' => 'product', 'type' => null, 'date' => null, 'size' => null],
'comidas' => ['category' => 'Comida', 'product' => 'horario', 'type' => 'servicio', 'date' => 'event_date', 'size' => null],
'comida' => ['category' => null, 'product' => 'horario', 'type' => 'servicio', 'date' => 'event_date', 'size' => null],
'merchandising' => ['category' => null, 'product' => 'product', 'type' => 'color', 'date' => null, 'size' => 'talle'],
'alojamientos' => ['category' => 'Camping', 'product' => 'tipo_alojamiento', 'type' => null, 'size' => null],
'camping' => ['category' => null, 'product' => 'tipo_alojamiento', 'type' => null, 'size' => null],
'entradas' => ['category' => null, 'product' => 'product', 'type' => null, 'size' => null],
'comidas' => ['category' => 'Comida', 'product' => 'horario', 'type' => 'servicio', 'size' => null],
'comida' => ['category' => null, 'product' => 'horario', 'type' => 'servicio', 'size' => null],
'merchandising' => ['category' => null, 'product' => 'product', 'type' => 'color', 'size' => 'talle'],
];
/** @return array<string, mixed> */
@@ -111,13 +112,14 @@ class AdminAppTicketRowService
private function presentation(Ticket $ticket, array $details): array
{
$sourceCategory = trim((string) ($ticket->sourceCatalogItem?->category?->nombre ?? '')) ?: '-';
$effectiveDates = $this->effectiveEventDateLabels($ticket) ?: '-';
if ($ticket->tenant_code !== self::FIESTA_FUTBOL_INFANTIL) {
return [
'category' => $sourceCategory,
'product' => (string) ($details['product'] ?: $ticket->name ?: '-'),
'type' => $this->allPropertyLabels($details) ?: '-',
'date' => '-',
'date' => $effectiveDates,
'size' => '-',
];
}
@@ -128,7 +130,7 @@ class AdminAppTicketRowService
'category' => $sourceCategory,
'product' => (string) ($details['product'] ?: $ticket->name ?: '-'),
'type' => $this->allPropertyLabels($details) ?: '-',
'date' => '-',
'date' => $effectiveDates,
'size' => '-',
];
}
@@ -141,29 +143,30 @@ class AdminAppTicketRowService
'type' => $configuration['type'] === null
? '-'
: ($this->propertyLabels($details, $configuration['type']) ?: '-'),
'date' => $configuration['date'] === null
? '-'
: ($this->propertyLabels($details, $configuration['date']) ?: '-'),
'date' => $effectiveDates,
'size' => $configuration['size'] === null
? '-'
: ($this->propertyLabels($details, $configuration['size']) ?: '-'),
];
}
private function effectiveEventDateLabels(Ticket $ticket): string
{
return $ticket->sourceVariant?->selectedEventDates()
->map(fn (EventDate $date): ?EventDate => $date->effectiveDate())
->filter()
->unique(fn (EventDate $date): int => $date->getKey())
->sortBy(fn (EventDate $date): string => $date->date->format('Y-m-d'))
->map(fn (EventDate $date): string => $date->date->format('d/m'))
->implode(', ') ?? '';
}
/** @param array<string, mixed> $details */
private function propertyLabels(array $details, string $code): string
{
$property = collect($details['variant_properties'] ?? [])->firstWhere('code', $code);
$labels = collect($property['values'] ?? [])->pluck('label')->filter();
if ($code === 'event_date') {
$labels = $labels->map(function (string $label): string {
[$day, $month] = array_pad(explode('/', $label), 2, null);
return $day !== null && $month !== null ? "{$day}/{$month}" : $label;
});
}
return $labels->implode(', ');
}