feat(desfile): associate tickets menu with desfile tenant and add migration test

This commit is contained in:
2026-09-25 11:15:52 -03:00
parent b309738222
commit 57d278336d
11 changed files with 421 additions and 11 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Domains\Ticketing\Ticket\Requests;
use App\Domains\Ticketing\Ticket\Models\Ticket;
use App\Domains\Ticketing\Ticket\Services\AdminAppTicketAttributeService;
use App\Domains\Ticketing\Ticket\Services\AdminAppTicketColumnService;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
@@ -22,7 +23,7 @@ class AdminAppTicketIndexRequest extends FormRequest
? []
: app(AdminAppTicketColumnService::class)->sortableKeys($tenant);
return [
$rules = [
'q' => ['sometimes', 'nullable', 'string', 'max:255'],
'category' => ['sometimes', 'nullable', 'string', 'max:255'],
'product' => ['sometimes', 'nullable', 'string', 'max:255'],
@@ -39,5 +40,18 @@ class AdminAppTicketIndexRequest extends FormRequest
'sort_by' => ['sometimes', 'nullable', 'string', Rule::in($sortableKeys)],
'sort_direction' => ['sometimes', 'nullable', 'string', Rule::in(['asc', 'desc'])],
];
if ($tenant !== null) {
foreach (app(AdminAppTicketAttributeService::class)->attributes($tenant) as $attribute) {
$rules[$attribute['code']] = [
'sometimes',
'nullable',
'string',
Rule::in(array_column($attribute['options'], 'value')),
];
}
}
return $rules;
}
}

View File

@@ -0,0 +1,92 @@
<?php
namespace App\Domains\Ticketing\Ticket\Services;
use App\Domains\Commerce\Catalog\Models\CatalogItem;
use App\Domains\Core\Tenant\Models\Tenant;
use Illuminate\Database\Eloquent\Builder;
class AdminAppTicketAttributeService
{
private const DESFILE_PURA_TENDENCIA = 'desfile_pura_tendencia';
/**
* @return list<array{
* code: string,
* label: string,
* options: list<array{value: string, label: string}>
* }>
*/
public function attributes(Tenant $tenant): array
{
if ($tenant->codigo !== self::DESFILE_PURA_TENDENCIA) {
return [];
}
$items = CatalogItem::withTrashed()
->where('tenant_code', $tenant->codigo)
->where(function (Builder $query): void {
$query
->where(function (Builder $activeQuery): void {
$activeQuery
->whereNull('catalog_items.deleted_at')
->where('has_tickets', true);
})
->orWhereHas('sourceTickets');
})
->with([
'itemAttributes' => fn ($query) => $query->orderBy('sort_order')->orderBy('id'),
'itemAttributes.attribute.options',
'variants' => fn ($query) => $query
->withTrashed()
->where(fn (Builder $variantQuery): Builder => $variantQuery
->whereNull('variantes.deleted_at')
->orWhereHas('sourceTickets'))
->orderBy('id'),
'variants.definitions.itemAttribute.attribute.options',
])
->get();
$attributes = [];
foreach ($items as $item) {
foreach ($item->itemAttributes as $itemAttribute) {
$attribute = $itemAttribute->attribute;
if ($attribute === null) {
continue;
}
$code = $attribute->codigo;
$attributes[$code] ??= [
'code' => $code,
'label' => $itemAttribute->ticket_label ?: $attribute->nombre,
'sort_order' => $itemAttribute->sort_order,
'options' => [],
];
foreach ($item->variants as $variant) {
$definition = $variant->definitions->firstWhere('item_attribute_id', $itemAttribute->id);
if ($definition === null) {
continue;
}
$value = (string) $definition->value;
$option = $attribute->options->firstWhere('value', $value);
$attributes[$code]['options'][$value] = [
'value' => $value,
'label' => (string) ($option?->label ?: $value),
];
}
}
}
uasort($attributes, fn (array $left, array $right): int => $left['sort_order'] <=> $right['sort_order']
?: $left['label'] <=> $right['label']);
return array_values(array_map(fn (array $attribute): array => [
'code' => $attribute['code'],
'label' => $attribute['label'],
'options' => array_values($attribute['options']),
], $attributes));
}
}

View File

@@ -8,9 +8,17 @@ class AdminAppTicketColumnService
{
private const FIESTA_FUTBOL_INFANTIL = 'fiesta_futbol_infantil';
private const DESFILE_PURA_TENDENCIA = 'desfile_pura_tendencia';
public function __construct(private readonly AdminAppTicketAttributeService $attributeService) {}
/** @return list<array{key: string, label: string, type: string, sortable: bool, sort_param: string, width: string, excel_width: int}> */
public function columns(Tenant $tenant): array
{
if ($tenant->codigo === self::DESFILE_PURA_TENDENCIA) {
return $this->desfileColumns($tenant);
}
$keys = $tenant->codigo === self::FIESTA_FUTBOL_INFANTIL
? ['order_number', 'category', 'product', 'type', 'date', 'size', 'amount', 'client', 'id', 'status', 'scanned_by']
: ['order_number', 'product', 'amount', 'client', 'id', 'status', 'scanned_by'];
@@ -45,6 +53,31 @@ class AdminAppTicketColumnService
return $columns;
}
/** @return list<array{key: string, label: string, type: string, sortable: bool, sort_param: string, width: string, excel_width: int}> */
private function desfileColumns(Tenant $tenant): array
{
$attributeColumns = array_map(fn (array $attribute): array => [
'key' => $attribute['code'],
'label' => $attribute['label'],
'type' => 'text',
'sortable' => false,
'sort_param' => $attribute['code'],
'width' => '8%',
'excel_width' => 15,
], $this->attributeService->attributes($tenant));
return [
$this->definitions()['order_number'],
$this->definitions()['product'],
...$attributeColumns,
$this->definitions()['amount'],
$this->definitions()['client'],
$this->definitions()['id'],
$this->definitions()['status'],
$this->definitions()['scanned_by'],
];
}
/** @return list<array{key: string, label: string, type: string, sortable: bool, sort_param: string, width: string}> */
public function publicColumns(Tenant $tenant): array
{

View File

@@ -48,8 +48,17 @@ class AdminAppTicketRowService
{
$details ??= $this->details($ticket);
$presentation = $this->presentation($ticket, $details);
$attributeValues = collect($details['variant_properties'] ?? [])
->mapWithKeys(fn (array $property): array => [
$property['code'] => collect($property['values'] ?? [])
->pluck('label')
->filter()
->implode(', ') ?: '-',
])
->all();
return [
...$attributeValues,
'order_number' => $details['order_number'],
'category' => $presentation['category'],
'product' => $presentation['product'],

View File

@@ -2,12 +2,12 @@
namespace App\Domains\Ticketing\Ticket\Services;
use App\Domains\Core\Auth\Models\User;
use App\Domains\Commerce\Catalog\Enums\InventoryPolicy;
use App\Domains\Commerce\Catalog\Models\Inventory;
use App\Domains\Commerce\Catalog\Models\Variant;
use App\Domains\Commerce\Purchase\Models\PurchaseItem;
use App\Domains\Commerce\Purchase\Services\PurchaseRefundSummaryService;
use App\Domains\Core\Auth\Models\User;
use App\Domains\Core\Tenant\Models\Tenant;
use App\Domains\Ticketing\Ticket\Models\Ticket;
use App\Domains\Ticketing\Ticket\Models\TicketRefund;
@@ -32,6 +32,7 @@ class AdminAppTicketService
public function __construct(
private readonly AdminAppTicketColumnService $columnService,
private readonly AdminAppTicketAttributeService $attributeService,
private readonly AdminAppTicketRowService $rowService,
private readonly PurchaseRefundSummaryService $refundSummaryService,
) {}
@@ -347,6 +348,13 @@ class AdminAppTicketService
$this->applyStatusFilter($query, $filters['status'] ?? null);
foreach ($this->attributeService->attributes($tenant) as $attribute) {
$value = $filters[$attribute['code']] ?? null;
if ($value !== null && $value !== '') {
$this->whereVariantDefinition($query, $attribute['code'], (string) $value);
}
}
return $query;
}