Files
shopit-back/app/Domains/Ticket/Services/AdminAppTicketColumnService.php

86 lines
3.2 KiB
PHP

<?php
namespace App\Domains\Ticket\Services;
use App\Domains\Tenant\Models\Tenant;
class AdminAppTicketColumnService
{
private const FIESTA_FUTBOL_INFANTIL = 'fiesta_futbol_infantil';
/** @return list<array{key: string, label: string, type: string, sortable: bool, width: string, excel_width: int}> */
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'];
$columns = array_map(fn (string $key): array => $this->definitions()[$key], $keys);
if ($tenant->codigo !== self::FIESTA_FUTBOL_INFANTIL) {
$widths = [
'order_number' => '11%',
'product' => '15%',
'amount' => '10%',
'client' => '15%',
'ticket' => '19%',
'date' => '11%',
'status' => '8%',
'scanned_by' => '11%',
];
$columns = array_map(function (array $column) use ($widths): array {
$column['width'] = $widths[$column['key']];
return $column;
}, $columns);
}
return $columns;
}
/** @return list<array{key: string, label: string, type: string, sortable: bool, width: string}> */
public function publicColumns(Tenant $tenant): array
{
return array_map(function (array $column): array {
unset($column['excel_width']);
return $column;
}, $this->columns($tenant));
}
/** @return array<string, array{key: string, label: string, type: string, sortable: bool, width: string, excel_width: int}> */
private function definitions(): array
{
return [
'order_number' => $this->column('order_number', 'N° de orden', 'order_number', '10.5%', 14),
'category' => $this->column('category', 'Categoría', 'text', '11%', 18),
'product' => $this->column('product', 'Producto', 'text', '11%', 22),
'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),
'status' => $this->column('status', 'Estado', 'status', '7%', 13),
'scanned_by' => $this->column('scanned_by', 'Escaneado por', 'text', '9%', 28),
];
}
/** @return array{key: string, label: string, type: string, sortable: bool, width: string, excel_width: int} */
private function column(
string $key,
string $label,
string $type,
string $width,
int $excelWidth,
): array {
return [
'key' => $key,
'label' => $label,
'type' => $type,
'sortable' => true,
'width' => $width,
'excel_width' => $excelWidth,
];
}
}