Compare commits
10 Commits
5e541f7cd0
...
feature/ti
| Author | SHA1 | Date | |
|---|---|---|---|
| c2233389d0 | |||
| 334ffe92e7 | |||
| a19ace3115 | |||
| acc0a68736 | |||
| dcf105c316 | |||
| f74bf41931 | |||
| 34217be630 | |||
| ee906d2d2e | |||
| 836aa1afd7 | |||
| 6896646c54 |
@@ -5,6 +5,7 @@ namespace App\Domains\Desfile\Services;
|
|||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
|
||||||
@@ -58,7 +59,7 @@ class InvitationPurchaseProvisioner
|
|||||||
$allocation['type'],
|
$allocation['type'],
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->createPurchaseItem(
|
$purchaseItemId = $this->createPurchaseItem(
|
||||||
$purchaseId,
|
$purchaseId,
|
||||||
$catalogItem,
|
$catalogItem,
|
||||||
$variant,
|
$variant,
|
||||||
@@ -70,6 +71,7 @@ class InvitationPurchaseProvisioner
|
|||||||
);
|
);
|
||||||
$this->createTicketAndCommitStock(
|
$this->createTicketAndCommitStock(
|
||||||
$purchaseId,
|
$purchaseId,
|
||||||
|
$purchaseItemId,
|
||||||
$userId,
|
$userId,
|
||||||
(int) $catalogItem->id,
|
(int) $catalogItem->id,
|
||||||
$variant,
|
$variant,
|
||||||
@@ -326,12 +328,13 @@ class InvitationPurchaseProvisioner
|
|||||||
int $seat,
|
int $seat,
|
||||||
string $type,
|
string $type,
|
||||||
DateTimeInterface $now,
|
DateTimeInterface $now,
|
||||||
): void {
|
): int {
|
||||||
if (DB::table('compra_items')
|
$existingId = DB::table('compra_items')
|
||||||
->where('compra_id', $purchaseId)
|
->where('compra_id', $purchaseId)
|
||||||
->where('source_variant_id', $variant->id)
|
->where('source_variant_id', $variant->id)
|
||||||
->exists()) {
|
->value('id');
|
||||||
return;
|
if ($existingId !== null) {
|
||||||
|
return (int) $existingId;
|
||||||
}
|
}
|
||||||
|
|
||||||
$attributes = [
|
$attributes = [
|
||||||
@@ -341,7 +344,7 @@ class InvitationPurchaseProvisioner
|
|||||||
['name' => 'Asiento', 'value' => (string) $seat],
|
['name' => 'Asiento', 'value' => (string) $seat],
|
||||||
];
|
];
|
||||||
|
|
||||||
DB::table('compra_items')->insert([
|
return DB::table('compra_items')->insertGetId([
|
||||||
'compra_id' => $purchaseId,
|
'compra_id' => $purchaseId,
|
||||||
'source_catalog_item_id' => $catalogItem->id,
|
'source_catalog_item_id' => $catalogItem->id,
|
||||||
'source_variant_id' => $variant->id,
|
'source_variant_id' => $variant->id,
|
||||||
@@ -367,13 +370,18 @@ class InvitationPurchaseProvisioner
|
|||||||
|
|
||||||
private function createTicketAndCommitStock(
|
private function createTicketAndCommitStock(
|
||||||
int $purchaseId,
|
int $purchaseId,
|
||||||
|
int $purchaseItemId,
|
||||||
int $userId,
|
int $userId,
|
||||||
int $catalogItemId,
|
int $catalogItemId,
|
||||||
object $variant,
|
object $variant,
|
||||||
DateTimeInterface $now,
|
DateTimeInterface $now,
|
||||||
): void {
|
): void {
|
||||||
|
$purchaseReference = Schema::hasColumn('tickets', 'source_purchase_item_id')
|
||||||
|
? ['source_purchase_item_id' => $purchaseItemId]
|
||||||
|
: ['source_purchase_id' => $purchaseId];
|
||||||
|
|
||||||
if (DB::table('tickets')
|
if (DB::table('tickets')
|
||||||
->where('source_purchase_id', $purchaseId)
|
->where($purchaseReference)
|
||||||
->where('source_variant_id', $variant->id)
|
->where('source_variant_id', $variant->id)
|
||||||
->exists()) {
|
->exists()) {
|
||||||
return;
|
return;
|
||||||
@@ -420,7 +428,7 @@ class InvitationPurchaseProvisioner
|
|||||||
'ticket' => (string) Str::uuid(),
|
'ticket' => (string) Str::uuid(),
|
||||||
'name' => null,
|
'name' => null,
|
||||||
'description' => null,
|
'description' => null,
|
||||||
'source_purchase_id' => $purchaseId,
|
...$purchaseReference,
|
||||||
'source_catalog_item_id' => $catalogItemId,
|
'source_catalog_item_id' => $catalogItemId,
|
||||||
'source_variant_id' => $variant->id,
|
'source_variant_id' => $variant->id,
|
||||||
'used_at' => null,
|
'used_at' => null,
|
||||||
|
|||||||
@@ -6,27 +6,18 @@ use App\Domains\Purchase\Models\Purchase;
|
|||||||
|
|
||||||
class SaleFormService
|
class SaleFormService
|
||||||
{
|
{
|
||||||
/** @return array{statuses: list<array{code: string, name: string}>} */
|
/** @return array{statuses: list<array{value: string, label: string, real_statuses: list<string>}>} */
|
||||||
public function get(): array
|
public function get(): array
|
||||||
{
|
{
|
||||||
$names = [
|
|
||||||
Purchase::STATUS_CREATED => 'Creada',
|
|
||||||
Purchase::STATUS_PENDING_PAYMENT => 'Esperando pago',
|
|
||||||
Purchase::STATUS_IN_REVIEW => 'En revisión',
|
|
||||||
Purchase::STATUS_PAID => 'Confirmada',
|
|
||||||
Purchase::STATUS_CANCELLED => 'Cancelada',
|
|
||||||
Purchase::STATUS_REJECTED => 'Rechazada',
|
|
||||||
Purchase::STATUS_EXPIRED => 'Vencida',
|
|
||||||
Purchase::STATUS_SUPERSEDED => 'Reemplazada',
|
|
||||||
];
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'statuses' => array_map(
|
'statuses' => array_map(
|
||||||
fn (string $status): array => [
|
fn (string $code, array $definition): array => [
|
||||||
'code' => $status,
|
'value' => $code,
|
||||||
'name' => $names[$status],
|
'label' => $definition['name'],
|
||||||
|
'real_statuses' => $definition['statuses'],
|
||||||
],
|
],
|
||||||
Purchase::statuses(),
|
array_keys(Purchase::adminStatuses()),
|
||||||
|
array_values(Purchase::adminStatuses()),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class TicketFilterFormService
|
|||||||
if ($tenant->codigo === self::FIESTA_FUTBOL_INFANTIL) {
|
if ($tenant->codigo === self::FIESTA_FUTBOL_INFANTIL) {
|
||||||
$fields = [
|
$fields = [
|
||||||
...$this->fiestaFutbolInfantilFields($tenant),
|
...$this->fiestaFutbolInfantilFields($tenant),
|
||||||
...$fields,
|
...$this->commonFields(includeDate: false),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +55,7 @@ class TicketFilterFormService
|
|||||||
'value' => $category['value'],
|
'value' => $category['value'],
|
||||||
'label' => $category['label'],
|
'label' => $category['label'],
|
||||||
'children' => [
|
'children' => [
|
||||||
|
[
|
||||||
'field' => 'product',
|
'field' => 'product',
|
||||||
'disabled' => $category['products'] === [],
|
'disabled' => $category['products'] === [],
|
||||||
'options' => array_map(
|
'options' => array_map(
|
||||||
@@ -62,35 +63,59 @@ class TicketFilterFormService
|
|||||||
'value' => $product['value'],
|
'value' => $product['value'],
|
||||||
'label' => $product['label'],
|
'label' => $product['label'],
|
||||||
'children' => [
|
'children' => [
|
||||||
|
[
|
||||||
'field' => 'type',
|
'field' => 'type',
|
||||||
'disabled' => $product['types'] === [],
|
'disabled' => $product['types'] === [],
|
||||||
'options' => $product['types'],
|
'options' => array_map(
|
||||||
|
fn (array $type): array => [
|
||||||
|
'value' => $type['value'],
|
||||||
|
'label' => $type['label'],
|
||||||
|
'children' => [[
|
||||||
|
'field' => 'size',
|
||||||
|
'disabled' => ($type['sizes'] ?? []) === [],
|
||||||
|
'options' => $type['sizes'] ?? [],
|
||||||
|
]],
|
||||||
|
],
|
||||||
|
$product['types'],
|
||||||
|
),
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
$category['products'],
|
$category['products'],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'field' => 'date',
|
||||||
|
'disabled' => ! in_array($category['value'], ['comidas', 'comida'], true),
|
||||||
|
'options' => [],
|
||||||
|
],
|
||||||
|
],
|
||||||
],
|
],
|
||||||
$form['categories'],
|
$form['categories'],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
$this->dependentSelect('product', 'Producto', 'category'),
|
$this->dependentSelect('product', 'Producto', 'category'),
|
||||||
$this->dependentSelect('type', 'Tipo', 'product'),
|
$this->dependentSelect('type', 'Tipo', 'product'),
|
||||||
|
$this->dependentSelect('size', 'Talle', 'type'),
|
||||||
|
[
|
||||||
|
...$this->dependentSelect('date', 'Fecha', 'category'),
|
||||||
|
'type' => 'date',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return list<array<string, mixed>> */
|
/** @return list<array<string, mixed>> */
|
||||||
private function commonFields(): array
|
private function commonFields(bool $includeDate = true): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[
|
...($includeDate ? [[
|
||||||
'name' => 'date',
|
'name' => 'date',
|
||||||
'query_param' => 'date',
|
'query_param' => 'date',
|
||||||
'label' => 'Fecha',
|
'label' => 'Fecha',
|
||||||
'type' => 'date',
|
'type' => 'date',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'default' => null,
|
'default' => null,
|
||||||
],
|
]] : []),
|
||||||
[
|
[
|
||||||
'name' => 'status',
|
'name' => 'status',
|
||||||
'query_param' => 'status',
|
'query_param' => 'status',
|
||||||
|
|||||||
@@ -54,6 +54,18 @@ class TicketFormService
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array<string, array{label: string|null, product: string, type: string|null, size: string|null, order: int}>
|
||||||
|
*/
|
||||||
|
private const FILTER_CATEGORY_PRESENTATIONS = [
|
||||||
|
'entradas' => ['label' => null, 'product' => self::PRODUCT, 'type' => null, 'size' => null, 'order' => 1],
|
||||||
|
'alojamientos' => ['label' => 'Camping', 'product' => 'tipo_alojamiento', 'type' => null, 'size' => null, 'order' => 2],
|
||||||
|
'camping' => ['label' => null, 'product' => 'tipo_alojamiento', 'type' => null, 'size' => null, 'order' => 2],
|
||||||
|
'comidas' => ['label' => 'Comida', 'product' => 'horario', 'type' => 'servicio', 'size' => null, 'order' => 3],
|
||||||
|
'comida' => ['label' => null, 'product' => 'horario', 'type' => 'servicio', 'size' => null, 'order' => 3],
|
||||||
|
'merchandising' => ['label' => null, 'product' => self::PRODUCT, 'type' => 'color', 'size' => 'talle', 'order' => 4],
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array{
|
* @return array{
|
||||||
* statuses: list<array{value: string, label: string}>,
|
* statuses: list<array{value: string, label: string}>,
|
||||||
@@ -79,7 +91,7 @@ class TicketFormService
|
|||||||
->orderBy('nombre')
|
->orderBy('nombre')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
return $this->build($items);
|
return $this->build($items, self::CATEGORY_PRESENTATIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -154,7 +166,7 @@ class TicketFormService
|
|||||||
->orderBy('nombre')
|
->orderBy('nombre')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
return $this->build($items);
|
return $this->build($items, self::FILTER_CATEGORY_PRESENTATIONS, includeSizes: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -172,17 +184,18 @@ class TicketFormService
|
|||||||
* }>
|
* }>
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
private function build(Collection $items): array
|
private function build(Collection $items, array $presentations, bool $includeSizes = false): array
|
||||||
{
|
{
|
||||||
$categories = [];
|
$categories = [];
|
||||||
|
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
$sourceCategory = trim((string) $item->category?->nombre);
|
$sourceCategory = trim((string) $item->category?->nombre);
|
||||||
$categoryValue = mb_strtolower($sourceCategory);
|
$categoryValue = mb_strtolower($sourceCategory);
|
||||||
$presentation = self::CATEGORY_PRESENTATIONS[$categoryValue] ?? [
|
$presentation = $presentations[$categoryValue] ?? [
|
||||||
'label' => null,
|
'label' => null,
|
||||||
'product' => self::PRODUCT,
|
'product' => self::PRODUCT,
|
||||||
'type' => null,
|
'type' => null,
|
||||||
|
'size' => null,
|
||||||
'order' => PHP_INT_MAX,
|
'order' => PHP_INT_MAX,
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -193,18 +206,28 @@ class TicketFormService
|
|||||||
'products' => [],
|
'products' => [],
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($this->products($item, $presentation['product'], $presentation['type']) as $product) {
|
foreach ($this->products(
|
||||||
|
$item,
|
||||||
|
$presentation['product'],
|
||||||
|
$presentation['type'],
|
||||||
|
$presentation['size'] ?? null,
|
||||||
|
) as $product) {
|
||||||
$productValue = $product['value'];
|
$productValue = $product['value'];
|
||||||
$existingProduct = $categories[$categoryValue]['products'][$productValue] ?? [
|
$existingProduct = $categories[$categoryValue]['products'][$productValue] ?? [
|
||||||
'value' => $productValue,
|
'value' => $productValue,
|
||||||
'label' => $product['label'],
|
'label' => $product['label'],
|
||||||
'types' => [],
|
'types' => [],
|
||||||
|
'sizes' => [],
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($product['types'] as $type) {
|
foreach ($product['types'] as $type) {
|
||||||
$existingProduct['types'][$type['value']] = $type;
|
$existingProduct['types'][$type['value']] = $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($product['sizes'] as $size) {
|
||||||
|
$existingProduct['sizes'][$size['value']] = $size;
|
||||||
|
}
|
||||||
|
|
||||||
$categories[$categoryValue]['products'][$productValue] = $existingProduct;
|
$categories[$categoryValue]['products'][$productValue] = $existingProduct;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,6 +250,7 @@ class TicketFormService
|
|||||||
'value' => $product['value'],
|
'value' => $product['value'],
|
||||||
'label' => $product['label'],
|
'label' => $product['label'],
|
||||||
'types' => array_values($product['types']),
|
'types' => array_values($product['types']),
|
||||||
|
...($includeSizes ? ['sizes' => array_values($product['sizes'])] : []),
|
||||||
],
|
],
|
||||||
$category['products'],
|
$category['products'],
|
||||||
)),
|
)),
|
||||||
@@ -252,16 +276,18 @@ class TicketFormService
|
|||||||
* @return list<array{
|
* @return list<array{
|
||||||
* value: string,
|
* value: string,
|
||||||
* label: string,
|
* label: string,
|
||||||
* types: list<array{value: string, label: string}>
|
* types: list<array{value: string, label: string}>,
|
||||||
|
* sizes: list<array{value: string, label: string}>
|
||||||
* }>
|
* }>
|
||||||
*/
|
*/
|
||||||
private function products(CatalogItem $item, string $productCode, ?string $typeCode): array
|
private function products(CatalogItem $item, string $productCode, ?string $typeCode, ?string $sizeCode): array
|
||||||
{
|
{
|
||||||
if ($productCode === self::PRODUCT) {
|
if ($productCode === self::PRODUCT) {
|
||||||
return [[
|
return [[
|
||||||
'value' => $item->slug,
|
'value' => $item->slug,
|
||||||
'label' => $item->nombre,
|
'label' => $item->nombre,
|
||||||
'types' => $this->types($item, $typeCode),
|
'types' => $this->types($item, $typeCode, $sizeCode),
|
||||||
|
'sizes' => $this->types($item, $sizeCode),
|
||||||
]];
|
]];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,10 +300,20 @@ class TicketFormService
|
|||||||
'value' => $productValue,
|
'value' => $productValue,
|
||||||
'label' => $this->optionLabel($productOption['label'], $productCode),
|
'label' => $this->optionLabel($productOption['label'], $productCode),
|
||||||
'types' => [],
|
'types' => [],
|
||||||
|
'sizes' => [],
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($this->variantOptions($variant, $typeCode) as $typeOption) {
|
foreach ($this->variantOptions($variant, $typeCode) as $typeOption) {
|
||||||
$products[$productValue]['types'][$typeOption['value']] = $typeOption;
|
$this->mergeTypeOption(
|
||||||
|
$products[$productValue]['types'],
|
||||||
|
$typeOption,
|
||||||
|
$variant,
|
||||||
|
$sizeCode,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->variantOptions($variant, $sizeCode) as $sizeOption) {
|
||||||
|
$products[$productValue]['sizes'][$sizeOption['value']] = $sizeOption;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -287,23 +323,51 @@ class TicketFormService
|
|||||||
'value' => $product['value'],
|
'value' => $product['value'],
|
||||||
'label' => $product['label'],
|
'label' => $product['label'],
|
||||||
'types' => array_values($product['types']),
|
'types' => array_values($product['types']),
|
||||||
|
'sizes' => array_values($product['sizes']),
|
||||||
],
|
],
|
||||||
$products,
|
$products,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return list<array{value: string, label: string}> */
|
/** @return list<array<string, mixed>> */
|
||||||
private function types(CatalogItem $item, ?string $typeCode): array
|
private function types(CatalogItem $item, ?string $typeCode, ?string $sizeCode = null): array
|
||||||
{
|
{
|
||||||
$types = [];
|
$types = [];
|
||||||
|
|
||||||
foreach ($item->variants as $variant) {
|
foreach ($item->variants as $variant) {
|
||||||
foreach ($this->variantOptions($variant, $typeCode) as $typeOption) {
|
foreach ($this->variantOptions($variant, $typeCode) as $typeOption) {
|
||||||
$types[$typeOption['value']] = $typeOption;
|
$this->mergeTypeOption($types, $typeOption, $variant, $sizeCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_values($types);
|
return array_values(array_map(function (array $type) use ($sizeCode): array {
|
||||||
|
if ($sizeCode !== null) {
|
||||||
|
$type['sizes'] = array_values($type['sizes']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $type;
|
||||||
|
}, $types));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, array<string, mixed>> $types
|
||||||
|
* @param array{value: string, label: string} $typeOption
|
||||||
|
*/
|
||||||
|
private function mergeTypeOption(
|
||||||
|
array &$types,
|
||||||
|
array $typeOption,
|
||||||
|
Variant $variant,
|
||||||
|
?string $sizeCode,
|
||||||
|
): void {
|
||||||
|
$typeValue = $typeOption['value'];
|
||||||
|
$types[$typeValue] ??= [
|
||||||
|
...$typeOption,
|
||||||
|
...($sizeCode !== null ? ['sizes' => []] : []),
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($this->variantOptions($variant, $sizeCode) as $sizeOption) {
|
||||||
|
$types[$typeValue]['sizes'][$sizeOption['value']] = $sizeOption;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return list<array{value: string, label: string}> */
|
/** @return list<array{value: string, label: string}> */
|
||||||
|
|||||||
@@ -138,8 +138,7 @@ class NotificationMailService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @var Collection<int, Ticket> $tickets */
|
/** @var Collection<int, Ticket> $tickets */
|
||||||
$tickets = Ticket::query()
|
$tickets = $purchase->tickets()
|
||||||
->where('source_purchase_id', $purchase->getKey())
|
|
||||||
->where('tenant_code', $purchase->tenant_codigo)
|
->where('tenant_code', $purchase->tenant_codigo)
|
||||||
->with(TicketPresentationResolver::RELATIONS)
|
->with(TicketPresentationResolver::RELATIONS)
|
||||||
->get();
|
->get();
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
@@ -51,6 +52,14 @@ class Purchase extends Model
|
|||||||
|
|
||||||
public const STATUS_SUPERSEDED = 'superseded';
|
public const STATUS_SUPERSEDED = 'superseded';
|
||||||
|
|
||||||
|
public const ADMIN_STATUS_INCOMPLETE = 'incomplete';
|
||||||
|
|
||||||
|
public const ADMIN_STATUS_AWAITING_PAYMENT = 'awaiting_payment';
|
||||||
|
|
||||||
|
public const ADMIN_STATUS_CONFIRMED = 'confirmed';
|
||||||
|
|
||||||
|
public const ADMIN_STATUS_CANCELLED = 'cancelled';
|
||||||
|
|
||||||
/** @return list<string> */
|
/** @return list<string> */
|
||||||
public static function statuses(): array
|
public static function statuses(): array
|
||||||
{
|
{
|
||||||
@@ -66,6 +75,68 @@ class Purchase extends Model
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array{name: string, statuses: list<string>}>
|
||||||
|
*/
|
||||||
|
public static function adminStatuses(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
self::ADMIN_STATUS_INCOMPLETE => [
|
||||||
|
'name' => 'Por completar datos',
|
||||||
|
'statuses' => [self::STATUS_CREATED],
|
||||||
|
],
|
||||||
|
self::ADMIN_STATUS_AWAITING_PAYMENT => [
|
||||||
|
'name' => 'Esperando pago',
|
||||||
|
'statuses' => [self::STATUS_PENDING_PAYMENT, self::STATUS_IN_REVIEW],
|
||||||
|
],
|
||||||
|
self::ADMIN_STATUS_CONFIRMED => [
|
||||||
|
'name' => 'Confirmado',
|
||||||
|
'statuses' => [self::STATUS_PAID],
|
||||||
|
],
|
||||||
|
self::ADMIN_STATUS_CANCELLED => [
|
||||||
|
'name' => 'Anulado',
|
||||||
|
'statuses' => [
|
||||||
|
self::STATUS_CANCELLED,
|
||||||
|
self::STATUS_REJECTED,
|
||||||
|
self::STATUS_EXPIRED,
|
||||||
|
self::STATUS_SUPERSEDED,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return list<string> */
|
||||||
|
public static function adminStatusCodes(): array
|
||||||
|
{
|
||||||
|
return array_keys(self::adminStatuses());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return list<string> */
|
||||||
|
public static function realStatusesForAdminStatus(string $adminStatus): array
|
||||||
|
{
|
||||||
|
return self::adminStatuses()[$adminStatus]['statuses'] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function adminStatusFor(string $realStatus): ?string
|
||||||
|
{
|
||||||
|
foreach (self::adminStatuses() as $adminStatus => $definition) {
|
||||||
|
if (in_array($realStatus, $definition['statuses'], true)) {
|
||||||
|
return $adminStatus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function adminStatusNameFor(string $realStatus): ?string
|
||||||
|
{
|
||||||
|
$adminStatus = self::adminStatusFor($realStatus);
|
||||||
|
|
||||||
|
return $adminStatus === null
|
||||||
|
? null
|
||||||
|
: self::adminStatuses()[$adminStatus]['name'];
|
||||||
|
}
|
||||||
|
|
||||||
protected $table = 'compras';
|
protected $table = 'compras';
|
||||||
|
|
||||||
/** @var array<int, string> */
|
/** @var array<int, string> */
|
||||||
@@ -115,12 +186,15 @@ class Purchase extends Model
|
|||||||
return $this->hasMany(PurchaseItem::class, 'compra_id');
|
return $this->hasMany(PurchaseItem::class, 'compra_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @return HasManyThrough<Ticket, PurchaseItem, $this> */
|
||||||
* @return HasMany<Ticket, $this>
|
public function tickets(): HasManyThrough
|
||||||
*/
|
|
||||||
public function tickets(): HasMany
|
|
||||||
{
|
{
|
||||||
return $this->hasMany(Ticket::class, 'source_purchase_id');
|
return $this->hasManyThrough(
|
||||||
|
Ticket::class,
|
||||||
|
PurchaseItem::class,
|
||||||
|
'compra_id',
|
||||||
|
'source_purchase_item_id',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return BelongsTo<StockReservation, $this> */
|
/** @return BelongsTo<StockReservation, $this> */
|
||||||
|
|||||||
@@ -5,10 +5,12 @@ namespace App\Domains\Purchase\Models;
|
|||||||
use App\Domains\Attachable\Models\Attachment;
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
use App\Domains\Catalog\Models\CatalogItem;
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
use App\Domains\Catalog\Models\Variant;
|
use App\Domains\Catalog\Models\Variant;
|
||||||
|
use App\Domains\Ticket\Models\Ticket;
|
||||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
#[Fillable([
|
#[Fillable([
|
||||||
'compra_id',
|
'compra_id',
|
||||||
@@ -56,6 +58,12 @@ class PurchaseItem extends Model
|
|||||||
return $this->belongsTo(Purchase::class, 'compra_id');
|
return $this->belongsTo(Purchase::class, 'compra_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return HasMany<Ticket, $this> */
|
||||||
|
public function tickets(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Ticket::class, 'source_purchase_item_id');
|
||||||
|
}
|
||||||
|
|
||||||
/** @return BelongsTo<Attachment, $this> */
|
/** @return BelongsTo<Attachment, $this> */
|
||||||
public function imageAttachment(): BelongsTo
|
public function imageAttachment(): BelongsTo
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -43,6 +43,11 @@ class ReleaseCheckoutService
|
|||||||
): Purchase {
|
): Purchase {
|
||||||
$purchase = $this->lockPurchase($purchase);
|
$purchase = $this->lockPurchase($purchase);
|
||||||
|
|
||||||
|
if ($purchase->status === Purchase::STATUS_EXPIRED
|
||||||
|
&& $targetStatus === Purchase::STATUS_CANCELLED) {
|
||||||
|
return $this->loadPurchase($purchase);
|
||||||
|
}
|
||||||
|
|
||||||
if ($purchase->status === Purchase::STATUS_EXPIRED
|
if ($purchase->status === Purchase::STATUS_EXPIRED
|
||||||
&& $targetStatus !== Purchase::STATUS_EXPIRED) {
|
&& $targetStatus !== Purchase::STATUS_EXPIRED) {
|
||||||
throw new PurchaseExpiredException;
|
throw new PurchaseExpiredException;
|
||||||
@@ -72,6 +77,14 @@ class ReleaseCheckoutService
|
|||||||
|
|
||||||
$cart = $purchase->cart()->withTrashed()->lockForUpdate()->first();
|
$cart = $purchase->cart()->withTrashed()->lockForUpdate()->first();
|
||||||
|
|
||||||
|
// Leaving checkout is allowed at the exact instant the reservation
|
||||||
|
// expires. Finish the expiration while holding the purchase lock so
|
||||||
|
// the request is idempotent with the scheduled expiration job.
|
||||||
|
if ($targetStatus === Purchase::STATUS_CANCELLED
|
||||||
|
&& $this->hasOverdueActiveReservation($purchase)) {
|
||||||
|
$targetStatus = Purchase::STATUS_EXPIRED;
|
||||||
|
}
|
||||||
|
|
||||||
if ($targetStatus === Purchase::STATUS_CANCELLED
|
if ($targetStatus === Purchase::STATUS_CANCELLED
|
||||||
&& $cart?->status === 'active'
|
&& $cart?->status === 'active'
|
||||||
&& in_array($purchase->status, [
|
&& in_array($purchase->status, [
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Domains\Sale\Controllers\AdminApp;
|
namespace App\Domains\Sale\Controllers\AdminApp;
|
||||||
|
|
||||||
use App\Domains\Sale\Requests\AdminAppSaleIndexRequest;
|
use App\Domains\Sale\Requests\AdminAppSaleIndexRequest;
|
||||||
|
use App\Domains\Sale\Requests\AdminAppSaleModificationIndexRequest;
|
||||||
use App\Domains\Sale\Requests\AdminAppSaleModificationPdfRequest;
|
use App\Domains\Sale\Requests\AdminAppSaleModificationPdfRequest;
|
||||||
use App\Domains\Sale\Requests\AdminAppSalePdfRequest;
|
use App\Domains\Sale\Requests\AdminAppSalePdfRequest;
|
||||||
use App\Domains\Sale\Resources\AdminApp\SaleDetailResource;
|
use App\Domains\Sale\Resources\AdminApp\SaleDetailResource;
|
||||||
@@ -67,11 +68,13 @@ class SaleController extends Controller
|
|||||||
return new SaleResource($this->saleService->cancel($tenant, $sale));
|
return new SaleResource($this->saleService->cancel($tenant, $sale));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function modifications(Request $request): AnonymousResourceCollection
|
public function modifications(
|
||||||
{
|
AdminAppSaleModificationIndexRequest $request,
|
||||||
|
): AnonymousResourceCollection {
|
||||||
return SaleModificationResource::collection(
|
return SaleModificationResource::collection(
|
||||||
$this->saleService->modifications(
|
$this->saleService->modifications(
|
||||||
$request->user()->tenant()->firstOrFail()
|
$request->user()->tenant()->firstOrFail(),
|
||||||
|
$request->validated(),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -93,7 +96,7 @@ class SaleController extends Controller
|
|||||||
|
|
||||||
return $this->salePdfService->downloadModifications(
|
return $this->salePdfService->downloadModifications(
|
||||||
$tenant,
|
$tenant,
|
||||||
$this->saleService->modificationsForExport($tenant),
|
$this->saleService->modificationsForExport($tenant, $request->validated()),
|
||||||
$request->validated('timezone'),
|
$request->validated('timezone'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -116,7 +119,7 @@ class SaleController extends Controller
|
|||||||
|
|
||||||
return $this->saleExcelService->downloadModifications(
|
return $this->saleExcelService->downloadModifications(
|
||||||
$tenant,
|
$tenant,
|
||||||
$this->saleService->modificationsForExport($tenant),
|
$this->saleService->modificationsForExport($tenant, $request->validated()),
|
||||||
$request->validated('timezone'),
|
$request->validated('timezone'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class AdminAppSaleIndexRequest extends FormRequest
|
|||||||
'q' => ['sometimes', 'nullable', 'string', 'max:255'],
|
'q' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||||
'id' => ['sometimes', 'nullable', 'integer', 'min:1'],
|
'id' => ['sometimes', 'nullable', 'integer', 'min:1'],
|
||||||
'sale_date' => ['sometimes', 'nullable', 'date_format:Y-m-d'],
|
'sale_date' => ['sometimes', 'nullable', 'date_format:Y-m-d'],
|
||||||
'status' => ['sometimes', 'nullable', 'string', Rule::in(Purchase::statuses())],
|
'status' => ['sometimes', 'nullable', 'string', Rule::in(Purchase::adminStatusCodes())],
|
||||||
'sort_by' => ['sometimes', 'string', 'in:id,date,customer_name,quantity,status,total'],
|
'sort_by' => ['sometimes', 'string', 'in:id,date,customer_name,quantity,status,total'],
|
||||||
'sort_direction' => ['sometimes', 'string', 'in:asc,desc'],
|
'sort_direction' => ['sometimes', 'string', 'in:asc,desc'],
|
||||||
'page' => ['sometimes', 'integer', 'min:1'],
|
'page' => ['sometimes', 'integer', 'min:1'],
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Sale\Requests;
|
||||||
|
|
||||||
|
class AdminAppSaleModificationIndexRequest extends AdminAppSaleIndexRequest
|
||||||
|
{
|
||||||
|
/** @return array<string, list<string>> */
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
$rules = parent::rules();
|
||||||
|
|
||||||
|
unset($rules['sort_by'], $rules['sort_direction']);
|
||||||
|
|
||||||
|
return $rules;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,19 +3,14 @@
|
|||||||
namespace App\Domains\Sale\Requests;
|
namespace App\Domains\Sale\Requests;
|
||||||
|
|
||||||
use App\Domains\Shared\Rules\ValidTimezone;
|
use App\Domains\Shared\Rules\ValidTimezone;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
|
|
||||||
class AdminAppSaleModificationPdfRequest extends FormRequest
|
class AdminAppSaleModificationPdfRequest extends AdminAppSaleModificationIndexRequest
|
||||||
{
|
{
|
||||||
public function authorize(): bool
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return array<string, list<string>> */
|
/** @return array<string, list<string>> */
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
...parent::rules(),
|
||||||
'timezone' => ['required', 'string', new ValidTimezone],
|
'timezone' => ['required', 'string', new ValidTimezone],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,12 @@ class SaleModificationResource extends JsonResource
|
|||||||
'attribute' => $this->attribute,
|
'attribute' => $this->attribute,
|
||||||
'old_value' => $this->old_value,
|
'old_value' => $this->old_value,
|
||||||
'new_value' => $this->new_value,
|
'new_value' => $this->new_value,
|
||||||
|
'admin_status' => is_string($this->new_value)
|
||||||
|
? Purchase::adminStatusFor($this->new_value)
|
||||||
|
: null,
|
||||||
|
'status_label' => is_string($this->new_value)
|
||||||
|
? Purchase::adminStatusNameFor($this->new_value)
|
||||||
|
: null,
|
||||||
'changed_at' => $this->changed_at->utc()->toIso8601String(),
|
'changed_at' => $this->changed_at->utc()->toIso8601String(),
|
||||||
'date' => $this->changed_at->format('Y-m-d'),
|
'date' => $this->changed_at->format('Y-m-d'),
|
||||||
'time' => $this->changed_at->format('H:i:s'),
|
'time' => $this->changed_at->format('H:i:s'),
|
||||||
@@ -31,6 +37,8 @@ class SaleModificationResource extends JsonResource
|
|||||||
'id' => $sale->id,
|
'id' => $sale->id,
|
||||||
'customer_name' => $sale->nombre_apellido,
|
'customer_name' => $sale->nombre_apellido,
|
||||||
'status' => $sale->status,
|
'status' => $sale->status,
|
||||||
|
'admin_status' => Purchase::adminStatusFor($sale->status),
|
||||||
|
'status_label' => Purchase::adminStatusNameFor($sale->status),
|
||||||
] : null,
|
] : null,
|
||||||
'modified_by' => $user ? [
|
'modified_by' => $user ? [
|
||||||
'id' => $user->id,
|
'id' => $user->id,
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ class SaleResource extends JsonResource
|
|||||||
'customer_name' => $this->nombre_apellido,
|
'customer_name' => $this->nombre_apellido,
|
||||||
'quantity' => (int) ($this->quantity ?? 0),
|
'quantity' => (int) ($this->quantity ?? 0),
|
||||||
'status' => $this->status,
|
'status' => $this->status,
|
||||||
|
'admin_status' => Purchase::adminStatusFor($this->status),
|
||||||
|
'status_label' => Purchase::adminStatusNameFor($this->status),
|
||||||
'total' => number_format((float) $this->total, 2, '.', ''),
|
'total' => number_format((float) $this->total, 2, '.', ''),
|
||||||
'tickets_count' => $ticketsCount,
|
'tickets_count' => $ticketsCount,
|
||||||
'has_generated_tickets' => $ticketsCount > 0,
|
'has_generated_tickets' => $ticketsCount > 0,
|
||||||
|
|||||||
@@ -201,11 +201,6 @@ class AdminAppSaleExcelService
|
|||||||
|
|
||||||
private function saleStatus(string $status): string
|
private function saleStatus(string $status): string
|
||||||
{
|
{
|
||||||
return match ($status) {
|
return Purchase::adminStatusNameFor($status) ?? $status;
|
||||||
Purchase::STATUS_PAID => 'Confirmado',
|
|
||||||
Purchase::STATUS_CREATED => 'Por completar datos',
|
|
||||||
Purchase::STATUS_PENDING_PAYMENT, Purchase::STATUS_IN_REVIEW => 'Esperando pago',
|
|
||||||
default => 'Anulado',
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,18 +92,24 @@ class AdminAppSaleService
|
|||||||
return $this->salesQuery($tenant, $filters)->get();
|
return $this->salesQuery($tenant, $filters)->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return LengthAwarePaginator<ValueChange> */
|
/**
|
||||||
public function modifications(Tenant $tenant): LengthAwarePaginator
|
* @param array<string, mixed> $filters
|
||||||
|
* @return LengthAwarePaginator<ValueChange>
|
||||||
|
*/
|
||||||
|
public function modifications(Tenant $tenant, array $filters = []): LengthAwarePaginator
|
||||||
{
|
{
|
||||||
return $this->modificationsQuery($tenant)
|
return $this->modificationsQuery($tenant, $filters)
|
||||||
->paginateFromRequest()
|
->paginateFromRequest()
|
||||||
->withQueryString();
|
->withQueryString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return Collection<int, ValueChange> */
|
/**
|
||||||
public function modificationsForExport(Tenant $tenant): Collection
|
* @param array<string, mixed> $filters
|
||||||
|
* @return Collection<int, ValueChange>
|
||||||
|
*/
|
||||||
|
public function modificationsForExport(Tenant $tenant, array $filters = []): Collection
|
||||||
{
|
{
|
||||||
return $this->modificationsQuery($tenant)->get();
|
return $this->modificationsQuery($tenant, $filters)->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param array<string, mixed> $filters */
|
/** @param array<string, mixed> $filters */
|
||||||
@@ -126,7 +132,6 @@ class AdminAppSaleService
|
|||||||
|
|
||||||
return Purchase::query()
|
return Purchase::query()
|
||||||
->where('tenant_codigo', $tenant->codigo)
|
->where('tenant_codigo', $tenant->codigo)
|
||||||
->where('status', '!=', Purchase::STATUS_SUPERSEDED)
|
|
||||||
->when($filters['q'] ?? null, function (Builder $query, string $search): void {
|
->when($filters['q'] ?? null, function (Builder $query, string $search): void {
|
||||||
$term = trim($search);
|
$term = trim($search);
|
||||||
|
|
||||||
@@ -144,12 +149,10 @@ class AdminAppSaleService
|
|||||||
)
|
)
|
||||||
->when(
|
->when(
|
||||||
$filters['status'] ?? null,
|
$filters['status'] ?? null,
|
||||||
fn (Builder $query, string $status): Builder => $status === Purchase::STATUS_PENDING_PAYMENT
|
fn (Builder $query, string $status): Builder => $query->whereIn(
|
||||||
? $query->whereIn('status', [
|
'status',
|
||||||
Purchase::STATUS_PENDING_PAYMENT,
|
Purchase::realStatusesForAdminStatus($status),
|
||||||
Purchase::STATUS_IN_REVIEW,
|
)
|
||||||
])
|
|
||||||
: $query->where('status', $status)
|
|
||||||
)
|
)
|
||||||
->select('compras.*')
|
->select('compras.*')
|
||||||
->selectRaw(
|
->selectRaw(
|
||||||
@@ -162,12 +165,50 @@ class AdminAppSaleService
|
|||||||
->when($sortBy !== 'id', fn (Builder $query): Builder => $query->orderByDesc('id'));
|
->when($sortBy !== 'id', fn (Builder $query): Builder => $query->orderByDesc('id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return Builder<ValueChange> */
|
/**
|
||||||
protected function modificationsQuery(Tenant $tenant): Builder
|
* @param array<string, mixed> $filters
|
||||||
|
* @return Builder<ValueChange>
|
||||||
|
*/
|
||||||
|
protected function modificationsQuery(Tenant $tenant, array $filters): Builder
|
||||||
{
|
{
|
||||||
return ValueChange::query()
|
return ValueChange::query()
|
||||||
->where('tenant_code', $tenant->codigo)
|
->where('tenant_code', $tenant->codigo)
|
||||||
->where('trackable_type', (new Purchase)->getMorphClass())
|
->where('trackable_type', (new Purchase)->getMorphClass())
|
||||||
|
->when($filters['q'] ?? null, function (Builder $query, string $search): void {
|
||||||
|
$term = trim($search);
|
||||||
|
|
||||||
|
$query->where(function (Builder $query) use ($term): void {
|
||||||
|
$query
|
||||||
|
->where('trackable_id', 'like', "%{$term}%")
|
||||||
|
->orWhereHasMorph(
|
||||||
|
'trackable',
|
||||||
|
[Purchase::class],
|
||||||
|
function (Builder $sales) use ($term): void {
|
||||||
|
$sales
|
||||||
|
->where('nombre_apellido', 'like', "%{$term}%")
|
||||||
|
->orWhere('created_at', 'like', "%{$term}%");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
->when(
|
||||||
|
$filters['id'] ?? null,
|
||||||
|
fn (Builder $query, int $id): Builder => $query->where('trackable_id', $id)
|
||||||
|
)
|
||||||
|
->when(
|
||||||
|
$filters['sale_date'] ?? null,
|
||||||
|
fn (Builder $query, string $date): Builder => $query->whereHasMorph(
|
||||||
|
'trackable',
|
||||||
|
[Purchase::class],
|
||||||
|
fn (Builder $sales): Builder => $sales->whereDate('created_at', $date),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
->when(
|
||||||
|
$filters['status'] ?? null,
|
||||||
|
fn (Builder $query, string $status): Builder => $query
|
||||||
|
->where('attribute', 'status')
|
||||||
|
->whereIn('new_value', Purchase::realStatusesForAdminStatus($status))
|
||||||
|
)
|
||||||
->with(['trackable', 'user'])
|
->with(['trackable', 'user'])
|
||||||
->orderByDesc('changed_at')
|
->orderByDesc('changed_at')
|
||||||
->orderByDesc('id');
|
->orderByDesc('id');
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ Provee consultas administrativas y exportaciones de ventas confirmadas, además
|
|||||||
- `AdminAppSaleService`: pagina ventas, calcula totales y obtiene colecciones para exportación; también consulta modificaciones.
|
- `AdminAppSaleService`: pagina ventas, calcula totales y obtiene colecciones para exportación; también consulta modificaciones.
|
||||||
- `AdminAppSalePdfService`: genera descargas PDF de ventas y de cambios.
|
- `AdminAppSalePdfService`: genera descargas PDF de ventas y de cambios.
|
||||||
- `AdminAppSaleExcelService`: genera descargas Excel de ventas y de cambios.
|
- `AdminAppSaleExcelService`: genera descargas Excel de ventas y de cambios.
|
||||||
- `AdminAppSaleIndexRequest`: valida filtros del listado y la exportación.
|
- `AdminAppSaleIndexRequest`: valida filtros del listado y la exportación de ventas.
|
||||||
|
- `AdminAppSaleModificationIndexRequest`: valida los filtros compartidos por el historial y sus exportaciones.
|
||||||
- `SaleResource` y `SaleModificationResource`: representan ventas e historial para AdminApp.
|
- `SaleResource` y `SaleModificationResource`: representan ventas e historial para AdminApp.
|
||||||
- `SaleController`: entrada HTTP del panel.
|
- `SaleController`: entrada HTTP del panel.
|
||||||
|
|
||||||
@@ -27,3 +28,5 @@ Consume compras de `Purchase`, datos del tenant y entradas de `Logging`. No es d
|
|||||||
## Consideraciones
|
## Consideraciones
|
||||||
|
|
||||||
La consulta paginada y la colección de exportación deben aplicar los mismos filtros para evitar diferencias entre pantalla, PDF y Excel.
|
La consulta paginada y la colección de exportación deben aplicar los mismos filtros para evitar diferencias entre pantalla, PDF y Excel.
|
||||||
|
|
||||||
|
El historial comparte con ventas los filtros de búsqueda, ID, fecha de venta y estado. En el historial, el estado se evalúa sobre `ValueChange.new_value`: representa el resultado de esa modificación y no el estado actual de la venta.
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class GenerateTicketsForPaidPurchase
|
|||||||
$user,
|
$user,
|
||||||
$purchaseItem->cantidad,
|
$purchaseItem->cantidad,
|
||||||
$purchaseItem->source_variant_id,
|
$purchaseItem->source_variant_id,
|
||||||
$purchase->getKey(),
|
$purchaseItem->getKey(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace App\Domains\Ticket\Models;
|
|||||||
use App\Domains\Auth\Models\User;
|
use App\Domains\Auth\Models\User;
|
||||||
use App\Domains\Catalog\Models\CatalogItem;
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
use App\Domains\Catalog\Models\Variant;
|
use App\Domains\Catalog\Models\Variant;
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
use App\Domains\Purchase\Models\PurchaseItem;
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
use App\Domains\Ticket\Services\ResolvedTicketValidity;
|
use App\Domains\Ticket\Services\ResolvedTicketValidity;
|
||||||
use App\Domains\Ticket\Services\ResolvedValidityGroup;
|
use App\Domains\Ticket\Services\ResolvedValidityGroup;
|
||||||
@@ -21,7 +21,7 @@ use Illuminate\Support\Collection;
|
|||||||
#[Fillable([
|
#[Fillable([
|
||||||
'tenant_code',
|
'tenant_code',
|
||||||
'ticket',
|
'ticket',
|
||||||
'source_purchase_id',
|
'source_purchase_item_id',
|
||||||
'source_catalog_item_id',
|
'source_catalog_item_id',
|
||||||
'source_variant_id',
|
'source_variant_id',
|
||||||
'used_at',
|
'used_at',
|
||||||
@@ -56,7 +56,7 @@ class Ticket extends Model
|
|||||||
return [
|
return [
|
||||||
'source_catalog_item_id' => 'integer',
|
'source_catalog_item_id' => 'integer',
|
||||||
'source_variant_id' => 'integer',
|
'source_variant_id' => 'integer',
|
||||||
'source_purchase_id' => 'integer',
|
'source_purchase_item_id' => 'integer',
|
||||||
'used_at' => 'datetime',
|
'used_at' => 'datetime',
|
||||||
'scanner_user_id' => 'integer',
|
'scanner_user_id' => 'integer',
|
||||||
'user_id' => 'integer',
|
'user_id' => 'integer',
|
||||||
@@ -81,10 +81,10 @@ class Ticket extends Model
|
|||||||
return $this->belongsTo(User::class, 'scanner_user_id');
|
return $this->belongsTo(User::class, 'scanner_user_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return BelongsTo<Purchase, $this> */
|
/** @return BelongsTo<PurchaseItem, $this> */
|
||||||
public function sourcePurchase(): BelongsTo
|
public function sourcePurchaseItem(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Purchase::class, 'source_purchase_id');
|
return $this->belongsTo(PurchaseItem::class, 'source_purchase_item_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return BelongsTo<CatalogItem, $this> */
|
/** @return BelongsTo<CatalogItem, $this> */
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ class AdminAppTicketIndexRequest extends FormRequest
|
|||||||
'product' => ['sometimes', 'nullable', 'string', 'max:255'],
|
'product' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||||
'type' => ['sometimes', 'nullable', 'string', 'max:255'],
|
'type' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||||
'date' => ['sometimes', 'nullable', 'date_format:Y-m-d'],
|
'date' => ['sometimes', 'nullable', 'date_format:Y-m-d'],
|
||||||
|
'size' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||||
'status' => [
|
'status' => [
|
||||||
'sometimes',
|
'sometimes',
|
||||||
'nullable',
|
'nullable',
|
||||||
|
|||||||
@@ -12,14 +12,14 @@ class AdminAppTicketColumnService
|
|||||||
public function columns(Tenant $tenant): array
|
public function columns(Tenant $tenant): array
|
||||||
{
|
{
|
||||||
$keys = $tenant->codigo === self::FIESTA_FUTBOL_INFANTIL
|
$keys = $tenant->codigo === self::FIESTA_FUTBOL_INFANTIL
|
||||||
? ['order_number', 'category', 'product', 'type', 'amount', 'client', 'id', 'status', 'scanned_by']
|
? ['order_number', 'category', 'product', 'type', 'date', 'size', 'amount', 'client', 'id', 'status', 'scanned_by']
|
||||||
: ['order_number', 'product', '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);
|
$columns = array_map(fn (string $key): array => $this->definitions()[$key], $keys);
|
||||||
|
|
||||||
if ($tenant->codigo === self::FIESTA_FUTBOL_INFANTIL) {
|
if ($tenant->codigo === self::FIESTA_FUTBOL_INFANTIL) {
|
||||||
$columns = array_map(function (array $column): array {
|
$columns = array_map(function (array $column): array {
|
||||||
if (in_array($column['key'], ['product', 'type'], true)) {
|
if (in_array($column['key'], ['product', 'type', 'date', 'size'], true)) {
|
||||||
$column['sortable'] = false;
|
$column['sortable'] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,11 +72,13 @@ class AdminAppTicketColumnService
|
|||||||
'category' => $this->column('category', 'Categoría', 'text', '11%', 18),
|
'category' => $this->column('category', 'Categoría', 'text', '11%', 18),
|
||||||
'product' => $this->column('product', 'Producto', 'text', '11%', 22),
|
'product' => $this->column('product', 'Producto', 'text', '11%', 22),
|
||||||
'type' => $this->column('type', 'Tipo', 'text', '8%', 18),
|
'type' => $this->column('type', 'Tipo', 'text', '8%', 18),
|
||||||
'amount' => $this->column('amount', 'Importe', 'currency', '9%', 15),
|
'date' => $this->column('date', 'Fecha', 'text', '7%', 14),
|
||||||
'client' => $this->column('client', 'Cliente', 'text', '13%', 30),
|
'size' => $this->column('size', 'Talle', 'text', '6%', 12),
|
||||||
'id' => $this->column('id', 'ID', 'text', '7%', 12),
|
'amount' => $this->column('amount', 'Importe', 'currency', '8%', 15),
|
||||||
|
'client' => $this->column('client', 'Cliente', 'text', '11%', 30),
|
||||||
|
'id' => $this->column('id', 'ID', 'text', '6%', 12),
|
||||||
'status' => $this->column('status', 'Estado', 'status', '7%', 13),
|
'status' => $this->column('status', 'Estado', 'status', '7%', 13),
|
||||||
'scanned_by' => $this->column('scanned_by', 'Escaneado por', 'text', '9%', 28),
|
'scanned_by' => $this->column('scanned_by', 'Escaneado por', 'text', '8%', 28),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
namespace App\Domains\Ticket\Services;
|
namespace App\Domains\Ticket\Services;
|
||||||
|
|
||||||
use App\Domains\Catalog\Models\ItemAttribute;
|
use App\Domains\Catalog\Models\ItemAttribute;
|
||||||
use App\Domains\Purchase\Models\PurchaseItem;
|
|
||||||
use App\Domains\Ticket\Models\Ticket;
|
use App\Domains\Ticket\Models\Ticket;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
@@ -12,27 +11,27 @@ class AdminAppTicketRowService
|
|||||||
private const FIESTA_FUTBOL_INFANTIL = 'fiesta_futbol_infantil';
|
private const FIESTA_FUTBOL_INFANTIL = 'fiesta_futbol_infantil';
|
||||||
|
|
||||||
private const CATEGORY_PRESENTATIONS = [
|
private const CATEGORY_PRESENTATIONS = [
|
||||||
'alojamientos' => ['category' => 'Camping', 'product' => 'tipo_alojamiento', 'type' => null],
|
'alojamientos' => ['category' => 'Camping', 'product' => 'tipo_alojamiento', 'type' => null, 'date' => null, 'size' => null],
|
||||||
'camping' => ['category' => null, 'product' => 'tipo_alojamiento', 'type' => null],
|
'camping' => ['category' => null, 'product' => 'tipo_alojamiento', 'type' => null, 'date' => null, 'size' => null],
|
||||||
'entradas' => ['category' => null, 'product' => 'product', 'type' => null],
|
'entradas' => ['category' => null, 'product' => 'product', 'type' => null, 'date' => null, 'size' => null],
|
||||||
'comidas' => ['category' => 'Comida', 'product' => 'event_date', 'type' => 'horario'],
|
'comidas' => ['category' => 'Comida', 'product' => 'horario', 'type' => 'servicio', 'date' => 'event_date', 'size' => null],
|
||||||
'comida' => ['category' => null, 'product' => 'event_date', 'type' => 'horario'],
|
'comida' => ['category' => null, 'product' => 'horario', 'type' => 'servicio', 'date' => 'event_date', 'size' => null],
|
||||||
'merchandising' => ['category' => null, 'product' => 'product', 'type' => 'color'],
|
'merchandising' => ['category' => null, 'product' => 'product', 'type' => 'color', 'date' => null, 'size' => 'talle'],
|
||||||
];
|
];
|
||||||
|
|
||||||
/** @return array<string, mixed> */
|
/** @return array<string, mixed> */
|
||||||
public function details(Ticket $ticket): array
|
public function details(Ticket $ticket): array
|
||||||
{
|
{
|
||||||
$purchaseItem = $this->sourcePurchaseItem($ticket);
|
$purchaseItem = $ticket->sourcePurchaseItem;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'source_purchase_id' => $ticket->source_purchase_id,
|
'source_purchase_item_id' => $ticket->source_purchase_item_id,
|
||||||
'order_number' => $ticket->source_purchase_id,
|
'order_number' => $purchaseItem?->compra_id,
|
||||||
'product' => $purchaseItem?->item_nombre
|
'product' => $purchaseItem?->item_nombre
|
||||||
?? $ticket->sourceCatalogItem?->nombre
|
?? $ticket->sourceCatalogItem?->nombre
|
||||||
?? $ticket->name,
|
?? $ticket->name,
|
||||||
'amount' => $purchaseItem?->precio_unitario,
|
'amount' => $purchaseItem?->precio_unitario,
|
||||||
'client' => $ticket->sourcePurchase?->nombre_apellido ?? $ticket->user?->nombre_apellido,
|
'client' => $purchaseItem?->purchase?->nombre_apellido ?? $ticket->user?->nombre_apellido,
|
||||||
'status' => $ticket->status,
|
'status' => $ticket->status,
|
||||||
'scanned_by' => $ticket->scannerUser?->nombre_apellido,
|
'scanned_by' => $ticket->scannerUser?->nombre_apellido,
|
||||||
'variant_properties' => $this->variantProperties($ticket),
|
'variant_properties' => $this->variantProperties($ticket),
|
||||||
@@ -50,6 +49,8 @@ class AdminAppTicketRowService
|
|||||||
'category' => $presentation['category'],
|
'category' => $presentation['category'],
|
||||||
'product' => $presentation['product'],
|
'product' => $presentation['product'],
|
||||||
'type' => $presentation['type'],
|
'type' => $presentation['type'],
|
||||||
|
'date' => $presentation['date'],
|
||||||
|
'size' => $presentation['size'],
|
||||||
'amount' => $details['amount'] === null ? null : (float) $details['amount'],
|
'amount' => $details['amount'] === null ? null : (float) $details['amount'],
|
||||||
'client' => $details['client'] ?? 'Sin nombre',
|
'client' => $details['client'] ?? 'Sin nombre',
|
||||||
'id' => $ticket->id,
|
'id' => $ticket->id,
|
||||||
@@ -113,6 +114,8 @@ class AdminAppTicketRowService
|
|||||||
'category' => $sourceCategory,
|
'category' => $sourceCategory,
|
||||||
'product' => (string) ($details['product'] ?: $ticket->name ?: '-'),
|
'product' => (string) ($details['product'] ?: $ticket->name ?: '-'),
|
||||||
'type' => $this->allPropertyLabels($details) ?: '-',
|
'type' => $this->allPropertyLabels($details) ?: '-',
|
||||||
|
'date' => '-',
|
||||||
|
'size' => '-',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,6 +125,8 @@ class AdminAppTicketRowService
|
|||||||
'category' => $sourceCategory,
|
'category' => $sourceCategory,
|
||||||
'product' => (string) ($details['product'] ?: $ticket->name ?: '-'),
|
'product' => (string) ($details['product'] ?: $ticket->name ?: '-'),
|
||||||
'type' => $this->allPropertyLabels($details) ?: '-',
|
'type' => $this->allPropertyLabels($details) ?: '-',
|
||||||
|
'date' => '-',
|
||||||
|
'size' => '-',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,6 +138,12 @@ class AdminAppTicketRowService
|
|||||||
'type' => $configuration['type'] === null
|
'type' => $configuration['type'] === null
|
||||||
? '-'
|
? '-'
|
||||||
: ($this->propertyLabels($details, $configuration['type']) ?: '-'),
|
: ($this->propertyLabels($details, $configuration['type']) ?: '-'),
|
||||||
|
'date' => $configuration['date'] === null
|
||||||
|
? '-'
|
||||||
|
: ($this->propertyLabels($details, $configuration['date']) ?: '-'),
|
||||||
|
'size' => $configuration['size'] === null
|
||||||
|
? '-'
|
||||||
|
: ($this->propertyLabels($details, $configuration['size']) ?: '-'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,18 +174,6 @@ class AdminAppTicketRowService
|
|||||||
->implode(', ');
|
->implode(', ');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function sourcePurchaseItem(Ticket $ticket): ?PurchaseItem
|
|
||||||
{
|
|
||||||
return $ticket->sourcePurchase?->items->first(function (PurchaseItem $item) use ($ticket): bool {
|
|
||||||
if ($ticket->source_variant_id !== null) {
|
|
||||||
return $item->source_variant_id === $ticket->source_variant_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $item->source_catalog_item_id === $ticket->source_catalog_item_id
|
|
||||||
&& $item->source_variant_id === null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return list<array{code: string, label: string, values: list<array{value: string, label: string}>}> */
|
/** @return list<array{code: string, label: string, values: list<array{value: string, label: string}>}> */
|
||||||
private function variantProperties(Ticket $ticket): array
|
private function variantProperties(Ticket $ticket): array
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class AdminAppTicketService
|
|||||||
'user',
|
'user',
|
||||||
'scannerUser',
|
'scannerUser',
|
||||||
'sourceCatalogItem.category',
|
'sourceCatalogItem.category',
|
||||||
'sourcePurchase.items',
|
'sourcePurchaseItem.purchase',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
@@ -27,7 +27,7 @@ class AdminAppTicketService
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array{q?: string|null, category?: string|null, product?: string|null, type?: string|null, date?: string|null, status?: string|null, page?: int, per_page?: int, sort_by?: string|null, sort_direction?: string|null} $filters
|
* @param array{q?: string|null, category?: string|null, product?: string|null, type?: string|null, date?: string|null, size?: string|null, status?: string|null, page?: int, per_page?: int, sort_by?: string|null, sort_direction?: string|null} $filters
|
||||||
*/
|
*/
|
||||||
public function search(Tenant $tenant, array $filters = []): AdminAppTicketResult
|
public function search(Tenant $tenant, array $filters = []): AdminAppTicketResult
|
||||||
{
|
{
|
||||||
@@ -60,7 +60,7 @@ class AdminAppTicketService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array{q?: string|null, category?: string|null, product?: string|null, type?: string|null, date?: string|null, status?: string|null, sort_by?: string|null, sort_direction?: string|null} $filters
|
* @param array{q?: string|null, category?: string|null, product?: string|null, type?: string|null, date?: string|null, size?: string|null, status?: string|null, sort_by?: string|null, sort_direction?: string|null} $filters
|
||||||
* @return Collection<int, Ticket>
|
* @return Collection<int, Ticket>
|
||||||
*/
|
*/
|
||||||
public function ticketsForExport(Tenant $tenant, array $filters = []): Collection
|
public function ticketsForExport(Tenant $tenant, array $filters = []): Collection
|
||||||
@@ -76,7 +76,7 @@ class AdminAppTicketService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array{q?: string|null, category?: string|null, product?: string|null, type?: string|null, date?: string|null, status?: string|null, page?: int, per_page?: int} $filters
|
* @param array{q?: string|null, category?: string|null, product?: string|null, type?: string|null, date?: string|null, size?: string|null, status?: string|null, page?: int, per_page?: int} $filters
|
||||||
* @return Builder<Ticket>
|
* @return Builder<Ticket>
|
||||||
*/
|
*/
|
||||||
private function baseQuery(Tenant $tenant, array $filters): Builder
|
private function baseQuery(Tenant $tenant, array $filters): Builder
|
||||||
@@ -86,13 +86,7 @@ class AdminAppTicketService
|
|||||||
$query = Ticket::query()
|
$query = Ticket::query()
|
||||||
->where('tenant_code', $tenant->codigo)
|
->where('tenant_code', $tenant->codigo)
|
||||||
->when($search !== '', function (Builder $query) use ($search): void {
|
->when($search !== '', function (Builder $query) use ($search): void {
|
||||||
$query->when(
|
$this->applySearchFilter($query, $search);
|
||||||
ctype_digit($search),
|
|
||||||
fn (Builder $searchQuery): Builder => $searchQuery
|
|
||||||
->where('tickets.id', (int) $search),
|
|
||||||
fn (Builder $searchQuery): Builder => $searchQuery
|
|
||||||
->where('ticket', 'like', "%{$search}%"),
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
->when($filters['category'] ?? null, function (Builder $query, string $category): void {
|
->when($filters['category'] ?? null, function (Builder $query, string $category): void {
|
||||||
$query->whereHas('sourceCatalogItem.category', fn (Builder $categoryQuery): Builder => $categoryQuery
|
$query->whereHas('sourceCatalogItem.category', fn (Builder $categoryQuery): Builder => $categoryQuery
|
||||||
@@ -104,15 +98,86 @@ class AdminAppTicketService
|
|||||||
->when($filters['type'] ?? null, function (Builder $query, string $type) use ($filters): void {
|
->when($filters['type'] ?? null, function (Builder $query, string $type) use ($filters): void {
|
||||||
$this->applyTypeFilter($query, (string) ($filters['category'] ?? ''), $type);
|
$this->applyTypeFilter($query, (string) ($filters['category'] ?? ''), $type);
|
||||||
})
|
})
|
||||||
->when($filters['date'] ?? null, fn (Builder $query, string $date): Builder => $query
|
->when($filters['date'] ?? null, function (Builder $query, string $date) use ($tenant): void {
|
||||||
->whereHas('sourcePurchase', fn (Builder $purchaseQuery): Builder => $purchaseQuery
|
if ($tenant->codigo === 'fiesta_futbol_infantil') {
|
||||||
->whereDate('created_at', $date)));
|
$this->applyEventDateFilter($query, $date);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query->whereHas('sourcePurchaseItem.purchase', fn (Builder $purchaseQuery): Builder => $purchaseQuery
|
||||||
|
->whereDate('created_at', $date));
|
||||||
|
})
|
||||||
|
->when($filters['size'] ?? null, function (Builder $query, string $size) use ($filters): void {
|
||||||
|
$this->applySizeFilter($query, (string) ($filters['category'] ?? ''), $size);
|
||||||
|
});
|
||||||
|
|
||||||
$this->applyStatusFilter($query, $filters['status'] ?? null);
|
$this->applyStatusFilter($query, $filters['status'] ?? null);
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @param Builder<Ticket> $query */
|
||||||
|
private function applySearchFilter(Builder $query, string $search): void
|
||||||
|
{
|
||||||
|
$containsPattern = '%'.mb_strtolower($search).'%';
|
||||||
|
$amount = $this->searchAmount($search);
|
||||||
|
|
||||||
|
$query->where(function (Builder $searchQuery) use ($search, $containsPattern, $amount): void {
|
||||||
|
$searchQuery
|
||||||
|
->where(function (Builder $clientQuery) use ($containsPattern): void {
|
||||||
|
$clientQuery
|
||||||
|
->whereHas('sourcePurchaseItem.purchase', fn (Builder $purchaseQuery): Builder => $purchaseQuery
|
||||||
|
->whereRaw('LOWER(nombre_apellido) LIKE ?', [$containsPattern]))
|
||||||
|
->orWhere(function (Builder $fallbackClientQuery) use ($containsPattern): void {
|
||||||
|
$fallbackClientQuery
|
||||||
|
->where(function (Builder $missingPurchaseClientQuery): void {
|
||||||
|
$missingPurchaseClientQuery
|
||||||
|
->whereDoesntHave('sourcePurchaseItem.purchase')
|
||||||
|
->orWhereHas('sourcePurchaseItem.purchase', fn (Builder $purchaseQuery): Builder => $purchaseQuery
|
||||||
|
->whereNull('nombre_apellido'));
|
||||||
|
})
|
||||||
|
->whereHas('user', fn (Builder $userQuery): Builder => $userQuery
|
||||||
|
->whereRaw('LOWER(nombre_apellido) LIKE ?', [$containsPattern]));
|
||||||
|
});
|
||||||
|
})
|
||||||
|
->orWhereHas('scannerUser', fn (Builder $scannerQuery): Builder => $scannerQuery
|
||||||
|
->whereRaw('LOWER(nombre_apellido) LIKE ?', [$containsPattern]));
|
||||||
|
|
||||||
|
if (ctype_digit($search)) {
|
||||||
|
$searchQuery
|
||||||
|
->orWhere('tickets.id', (int) $search)
|
||||||
|
->orWhereHas('sourcePurchaseItem', fn (Builder $purchaseItemQuery): Builder => $purchaseItemQuery
|
||||||
|
->where('compra_id', (int) $search));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($amount !== null) {
|
||||||
|
$searchQuery->orWhereHas('sourcePurchaseItem', fn (Builder $purchaseItemQuery): Builder => $purchaseItemQuery
|
||||||
|
->where('precio_unitario', $amount));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function searchAmount(string $search): ?string
|
||||||
|
{
|
||||||
|
$value = preg_replace('/[\s$]/u', '', trim($search));
|
||||||
|
if ($value === null || $value === '') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preg_match('/^\d{1,3}(?:\.\d{3})+(?:,\d{1,2})?$/', $value) === 1) {
|
||||||
|
$value = str_replace(['.', ','], ['', '.'], $value);
|
||||||
|
} elseif (preg_match('/^\d{1,3}(?:,\d{3})+(?:\.\d{1,2})?$/', $value) === 1) {
|
||||||
|
$value = str_replace(',', '', $value);
|
||||||
|
} elseif (preg_match('/^\d+(?:[.,]\d{1,2})?$/', $value) === 1) {
|
||||||
|
$value = str_replace(',', '.', $value);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return number_format((float) $value, 2, '.', '');
|
||||||
|
}
|
||||||
|
|
||||||
/** @param Builder<Ticket> $query */
|
/** @param Builder<Ticket> $query */
|
||||||
private function applyProductFilter(Builder $query, string $category, string $product): void
|
private function applyProductFilter(Builder $query, string $category, string $product): void
|
||||||
{
|
{
|
||||||
@@ -125,14 +190,7 @@ class AdminAppTicketService
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($category, ['comidas', 'comida'], true)) {
|
if (in_array($category, ['comidas', 'comida'], true)) {
|
||||||
$query->whereHas('sourceVariant', function (Builder $variantQuery) use ($product): void {
|
$this->whereVariantDefinition($query, 'horario', $product);
|
||||||
$variantQuery->where(function (Builder $dateQuery) use ($product): void {
|
|
||||||
$dateQuery
|
|
||||||
->where('event_date_id', $product)
|
|
||||||
->orWhereHas('eventDates', fn (Builder $eventDateQuery): Builder => $eventDateQuery
|
|
||||||
->whereKey($product));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -145,7 +203,7 @@ class AdminAppTicketService
|
|||||||
private function applyTypeFilter(Builder $query, string $category, string $type): void
|
private function applyTypeFilter(Builder $query, string $category, string $type): void
|
||||||
{
|
{
|
||||||
$attribute = match ($this->normalizedCategory($category)) {
|
$attribute = match ($this->normalizedCategory($category)) {
|
||||||
'comidas', 'comida' => 'horario',
|
'comidas', 'comida' => 'servicio',
|
||||||
'merchandising' => 'color',
|
'merchandising' => 'color',
|
||||||
default => null,
|
default => null,
|
||||||
};
|
};
|
||||||
@@ -155,6 +213,31 @@ class AdminAppTicketService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @param Builder<Ticket> $query */
|
||||||
|
private function applyEventDateFilter(Builder $query, string $date): void
|
||||||
|
{
|
||||||
|
$query
|
||||||
|
->whereHas('sourceCatalogItem.category', fn (Builder $categoryQuery): Builder => $categoryQuery
|
||||||
|
->whereRaw('LOWER(nombre) IN (?, ?)', ['comidas', 'comida']))
|
||||||
|
->whereHas('sourceVariant', function (Builder $variantQuery) use ($date): void {
|
||||||
|
$variantQuery->where(function (Builder $dateQuery) use ($date): void {
|
||||||
|
$dateQuery
|
||||||
|
->whereHas('eventDate', fn (Builder $eventDateQuery): Builder => $eventDateQuery
|
||||||
|
->whereDate('date', $date))
|
||||||
|
->orWhereHas('eventDates', fn (Builder $eventDateQuery): Builder => $eventDateQuery
|
||||||
|
->whereDate('date', $date));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param Builder<Ticket> $query */
|
||||||
|
private function applySizeFilter(Builder $query, string $category, string $size): void
|
||||||
|
{
|
||||||
|
if ($this->normalizedCategory($category) === 'merchandising') {
|
||||||
|
$this->whereVariantDefinition($query, 'talle', $size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** @param Builder<Ticket> $query */
|
/** @param Builder<Ticket> $query */
|
||||||
private function whereVariantDefinition(Builder $query, string $attribute, string $value): void
|
private function whereVariantDefinition(Builder $query, string $attribute, string $value): void
|
||||||
{
|
{
|
||||||
@@ -206,15 +289,15 @@ class AdminAppTicketService
|
|||||||
$direction = ($filters['sort_direction'] ?? 'asc') === 'desc' ? 'desc' : 'asc';
|
$direction = ($filters['sort_direction'] ?? 'asc') === 'desc' ? 'desc' : 'asc';
|
||||||
|
|
||||||
$sortExpression = match ($sortBy) {
|
$sortExpression = match ($sortBy) {
|
||||||
'order_number' => 'tickets.source_purchase_id',
|
'order_number' => $this->purchaseItemColumnQuery('compra_id'),
|
||||||
'id' => 'tickets.id',
|
'id' => 'tickets.id',
|
||||||
'amount' => $this->purchaseItemSortQuery('precio_unitario'),
|
'amount' => $this->purchaseItemColumnQuery('precio_unitario'),
|
||||||
'scanned_by' => User::query()
|
'scanned_by' => User::query()
|
||||||
->select('nombre_apellido')
|
->select('nombre_apellido')
|
||||||
->whereColumn('users.id', 'tickets.scanner_user_id'),
|
->whereColumn('users.id', 'tickets.scanner_user_id'),
|
||||||
'product' => $tenant->codigo === 'fiesta_futbol_infantil'
|
'product' => $tenant->codigo === 'fiesta_futbol_infantil'
|
||||||
? null
|
? null
|
||||||
: $this->purchaseItemSortQuery('item_nombre'),
|
: $this->purchaseItemColumnQuery('item_nombre'),
|
||||||
default => null,
|
default => null,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -228,25 +311,11 @@ class AdminAppTicketService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @return Builder<PurchaseItem> */
|
/** @return Builder<PurchaseItem> */
|
||||||
private function purchaseItemSortQuery(string $column): Builder
|
private function purchaseItemColumnQuery(string $column): Builder
|
||||||
{
|
{
|
||||||
return PurchaseItem::query()
|
return PurchaseItem::query()
|
||||||
->select($column)
|
->select($column)
|
||||||
->whereColumn('compra_items.compra_id', 'tickets.source_purchase_id')
|
->whereColumn('compra_items.id', 'tickets.source_purchase_item_id')
|
||||||
->where(function (Builder $query): void {
|
|
||||||
$query
|
|
||||||
->where(function (Builder $variantQuery): void {
|
|
||||||
$variantQuery
|
|
||||||
->whereNotNull('tickets.source_variant_id')
|
|
||||||
->whereColumn('compra_items.source_variant_id', 'tickets.source_variant_id');
|
|
||||||
})
|
|
||||||
->orWhere(function (Builder $itemQuery): void {
|
|
||||||
$itemQuery
|
|
||||||
->whereNull('tickets.source_variant_id')
|
|
||||||
->whereNull('compra_items.source_variant_id')
|
|
||||||
->whereColumn('compra_items.source_catalog_item_id', 'tickets.source_catalog_item_id');
|
|
||||||
});
|
|
||||||
})
|
|
||||||
->limit(1);
|
->limit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,13 +23,13 @@ class TicketGeneratorService
|
|||||||
User $user,
|
User $user,
|
||||||
int $quantity = 1,
|
int $quantity = 1,
|
||||||
?int $sourceVariantId = null,
|
?int $sourceVariantId = null,
|
||||||
?int $sourcePurchaseId = null,
|
?int $sourcePurchaseItemId = null,
|
||||||
): Collection {
|
): Collection {
|
||||||
if ($quantity < 1) {
|
if ($quantity < 1) {
|
||||||
throw TicketGenerationException::invalidQuantity();
|
throw TicketGenerationException::invalidQuantity();
|
||||||
}
|
}
|
||||||
|
|
||||||
return DB::transaction(function () use ($catalogItem, $user, $quantity, $sourceVariantId, $sourcePurchaseId): Collection {
|
return DB::transaction(function () use ($catalogItem, $user, $quantity, $sourceVariantId, $sourcePurchaseItemId): Collection {
|
||||||
$targets = $this->resolveTargets(
|
$targets = $this->resolveTargets(
|
||||||
$catalogItem,
|
$catalogItem,
|
||||||
$quantity,
|
$quantity,
|
||||||
@@ -37,7 +37,7 @@ class TicketGeneratorService
|
|||||||
);
|
);
|
||||||
|
|
||||||
return $targets->map(function (array $target) use (
|
return $targets->map(function (array $target) use (
|
||||||
$sourcePurchaseId,
|
$sourcePurchaseItemId,
|
||||||
$user,
|
$user,
|
||||||
): Ticket {
|
): Ticket {
|
||||||
$item = $target['catalog_item'];
|
$item = $target['catalog_item'];
|
||||||
@@ -45,7 +45,7 @@ class TicketGeneratorService
|
|||||||
$ticket = Ticket::query()->create([
|
$ticket = Ticket::query()->create([
|
||||||
'tenant_code' => $item->tenant_code,
|
'tenant_code' => $item->tenant_code,
|
||||||
'ticket' => (string) Str::uuid(),
|
'ticket' => (string) Str::uuid(),
|
||||||
'source_purchase_id' => $sourcePurchaseId,
|
'source_purchase_item_id' => $sourcePurchaseItemId,
|
||||||
'source_catalog_item_id' => $item->getKey(),
|
'source_catalog_item_id' => $item->getKey(),
|
||||||
'source_variant_id' => $variant?->getKey(),
|
'source_variant_id' => $variant?->getKey(),
|
||||||
'used_at' => null,
|
'used_at' => null,
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ Genera, valida, consulta y exporta entradas asociadas a compras pagadas de produ
|
|||||||
|
|
||||||
## Modelo
|
## Modelo
|
||||||
|
|
||||||
- `Ticket`: pertenece a tenant y usuario, y conserva referencias a compra, producto, variante y usuario escáner.
|
- `Ticket`: pertenece a tenant y usuario, y conserva referencias al ítem de compra que lo generó, producto,
|
||||||
|
variante y usuario escáner. La compra se obtiene a través de su ítem.
|
||||||
- El nombre y la descripción se calculan dinámicamente desde el producto y la variante; los tickets no
|
- El nombre y la descripción se calculan dinámicamente desde el producto y la variante; los tickets no
|
||||||
persisten una copia de esos textos.
|
persisten una copia de esos textos.
|
||||||
- `ValidityTime`: define ventanas absolutas o relativas de vigencia para fechas de evento y opciones de atributos.
|
- `ValidityTime`: define ventanas absolutas o relativas de vigencia para fechas de evento y opciones de atributos.
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('tickets', function (Blueprint $table): void {
|
||||||
|
$table->foreignId('source_purchase_item_id')
|
||||||
|
->nullable()
|
||||||
|
->after('source_purchase_id')
|
||||||
|
->constrained('compra_items')
|
||||||
|
->cascadeOnUpdate()
|
||||||
|
->nullOnDelete();
|
||||||
|
});
|
||||||
|
|
||||||
|
DB::table('tickets')
|
||||||
|
->whereNotNull('source_purchase_id')
|
||||||
|
->whereNull('source_purchase_item_id')
|
||||||
|
->orderBy('id')
|
||||||
|
->chunkById(500, function (Collection $tickets): void {
|
||||||
|
$purchaseIds = $tickets->pluck('source_purchase_id')->unique()->values();
|
||||||
|
$itemsByPurchase = DB::table('compra_items')
|
||||||
|
->whereIn('compra_id', $purchaseIds)
|
||||||
|
->get(['id', 'compra_id', 'source_catalog_item_id', 'source_variant_id'])
|
||||||
|
->groupBy('compra_id');
|
||||||
|
$bundleIds = $itemsByPurchase->flatten(1)
|
||||||
|
->pluck('source_catalog_item_id')
|
||||||
|
->filter()
|
||||||
|
->unique()
|
||||||
|
->values();
|
||||||
|
$componentsByBundle = DB::table('bundle_components')
|
||||||
|
->whereIn('bundle_catalog_item_id', $bundleIds)
|
||||||
|
->get([
|
||||||
|
'bundle_catalog_item_id',
|
||||||
|
'component_catalog_item_id',
|
||||||
|
'component_variant_id',
|
||||||
|
])
|
||||||
|
->groupBy('bundle_catalog_item_id');
|
||||||
|
|
||||||
|
foreach ($tickets as $ticket) {
|
||||||
|
$candidates = collect($itemsByPurchase->get($ticket->source_purchase_id, []))
|
||||||
|
->filter(function (object $item) use ($ticket, $componentsByBundle): bool {
|
||||||
|
if ($this->sameCatalogTarget($item, $ticket)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return collect($componentsByBundle->get($item->source_catalog_item_id, []))
|
||||||
|
->contains(fn (object $component): bool => $this->sameBundleTarget($component, $ticket));
|
||||||
|
})
|
||||||
|
->pluck('id')
|
||||||
|
->unique()
|
||||||
|
->values();
|
||||||
|
|
||||||
|
if ($candidates->count() === 1) {
|
||||||
|
DB::table('tickets')->where('id', $ticket->id)->update([
|
||||||
|
'source_purchase_item_id' => $candidates->sole(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('tickets', function (Blueprint $table): void {
|
||||||
|
$table->dropConstrainedForeignId('source_purchase_item_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sameCatalogTarget(object $item, object $ticket): bool
|
||||||
|
{
|
||||||
|
return (int) $item->source_catalog_item_id === (int) $ticket->source_catalog_item_id
|
||||||
|
&& $this->sameNullableId($item->source_variant_id, $ticket->source_variant_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sameBundleTarget(object $component, object $ticket): bool
|
||||||
|
{
|
||||||
|
return (int) $component->component_catalog_item_id === (int) $ticket->source_catalog_item_id
|
||||||
|
&& $this->sameNullableId($component->component_variant_id, $ticket->source_variant_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sameNullableId(mixed $left, mixed $right): bool
|
||||||
|
{
|
||||||
|
return $left === null || $right === null
|
||||||
|
? $left === null && $right === null
|
||||||
|
: (int) $left === (int) $right;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
$unresolved = DB::table('tickets')
|
||||||
|
->whereNotNull('source_purchase_id')
|
||||||
|
->whereNull('source_purchase_item_id')
|
||||||
|
->orderBy('id')
|
||||||
|
->limit(20)
|
||||||
|
->pluck('id');
|
||||||
|
|
||||||
|
if ($unresolved->isNotEmpty()) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
'No se puede eliminar tickets.source_purchase_id: hay tickets sin un compra_item inequívoco. '
|
||||||
|
.'IDs: '.$unresolved->implode(', ')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$inconsistent = DB::table('tickets')
|
||||||
|
->join('compra_items', 'compra_items.id', '=', 'tickets.source_purchase_item_id')
|
||||||
|
->whereNotNull('tickets.source_purchase_id')
|
||||||
|
->whereColumn('tickets.source_purchase_id', '!=', 'compra_items.compra_id')
|
||||||
|
->orderBy('tickets.id')
|
||||||
|
->limit(20)
|
||||||
|
->pluck('tickets.id');
|
||||||
|
|
||||||
|
if ($inconsistent->isNotEmpty()) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
'No se puede eliminar tickets.source_purchase_id: hay referencias de compra inconsistentes. '
|
||||||
|
.'IDs: '.$inconsistent->implode(', ')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Schema::table('tickets', function (Blueprint $table): void {
|
||||||
|
$table->dropConstrainedForeignId('source_purchase_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('tickets', function (Blueprint $table): void {
|
||||||
|
$table->foreignId('source_purchase_id')
|
||||||
|
->nullable()
|
||||||
|
->after('description')
|
||||||
|
->constrained('compras')
|
||||||
|
->cascadeOnUpdate()
|
||||||
|
->nullOnDelete();
|
||||||
|
});
|
||||||
|
|
||||||
|
DB::table('tickets')
|
||||||
|
->whereNotNull('source_purchase_item_id')
|
||||||
|
->orderBy('id')
|
||||||
|
->chunkById(500, function (Collection $tickets): void {
|
||||||
|
$purchaseIdsByItem = DB::table('compra_items')
|
||||||
|
->whereIn('id', $tickets->pluck('source_purchase_item_id'))
|
||||||
|
->pluck('compra_id', 'id');
|
||||||
|
|
||||||
|
foreach ($tickets as $ticket) {
|
||||||
|
DB::table('tickets')->where('id', $ticket->id)->update([
|
||||||
|
'source_purchase_id' => $purchaseIdsByItem->get($ticket->source_purchase_item_id),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('tickets', function (Blueprint $table): void {
|
||||||
|
$table->dropForeign(['source_purchase_item_id']);
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('tickets', function (Blueprint $table): void {
|
||||||
|
$table->foreign('source_purchase_item_id')
|
||||||
|
->references('id')
|
||||||
|
->on('compra_items')
|
||||||
|
->cascadeOnUpdate()
|
||||||
|
->restrictOnDelete();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('tickets', function (Blueprint $table): void {
|
||||||
|
$table->dropForeign(['source_purchase_item_id']);
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('tickets', function (Blueprint $table): void {
|
||||||
|
$table->foreign('source_purchase_item_id')
|
||||||
|
->references('id')
|
||||||
|
->on('compra_items')
|
||||||
|
->cascadeOnUpdate()
|
||||||
|
->nullOnDelete();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -47,11 +47,7 @@
|
|||||||
<td>{{ $sale->created_at?->copy()->timezone($timeZone)->format('d/m/Y H:i') ?? '-' }}</td>
|
<td>{{ $sale->created_at?->copy()->timezone($timeZone)->format('d/m/Y H:i') ?? '-' }}</td>
|
||||||
<td>{{ $sale->nombre_apellido ?: 'Sin nombre' }}</td>
|
<td>{{ $sale->nombre_apellido ?: 'Sin nombre' }}</td>
|
||||||
<td class="center">{{ (int) ($sale->quantity ?? 0) }}</td>
|
<td class="center">{{ (int) ($sale->quantity ?? 0) }}</td>
|
||||||
<td>{{ match ($sale->status) {
|
<td>{{ \App\Domains\Purchase\Models\Purchase::adminStatusNameFor($sale->status) ?? $sale->status }}</td>
|
||||||
'paid' => 'Confirmado',
|
|
||||||
'created', 'pending_payment' => 'Esperando pago',
|
|
||||||
default => 'Anulado',
|
|
||||||
} }}</td>
|
|
||||||
<td class="number">${{ number_format((float) $sale->total, 2, ',', '.') }}</td>
|
<td class="number">${{ number_format((float) $sale->total, 2, ',', '.') }}</td>
|
||||||
<td class="center">{{ (int) ($sale->tickets_count ?? 0) }}</td>
|
<td class="center">{{ (int) ($sale->tickets_count ?? 0) }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace Tests\Feature\Forms;
|
namespace Tests\Feature\Forms;
|
||||||
|
|
||||||
|
use App\Domains\Attachable\Enums\AttachmentType;
|
||||||
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
use App\Domains\Auth\Models\User;
|
use App\Domains\Auth\Models\User;
|
||||||
use App\Domains\Authorization\Enums\RoleCode;
|
use App\Domains\Authorization\Enums\RoleCode;
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
@@ -34,12 +36,7 @@ class AdminAppSaleFormControllerTest extends TestCase
|
|||||||
|
|
||||||
public function test_an_adminapp_user_can_get_the_sale_form(): void
|
public function test_an_adminapp_user_can_get_the_sale_form(): void
|
||||||
{
|
{
|
||||||
$tenant = Tenant::query()->create([
|
$tenant = $this->createTenant('acme');
|
||||||
'codigo' => 'acme',
|
|
||||||
'nombre' => 'Acme',
|
|
||||||
'dominio' => 'acme.test',
|
|
||||||
'website_type_code' => 'onticket',
|
|
||||||
]);
|
|
||||||
Sanctum::actingAs(User::factory()->create([
|
Sanctum::actingAs(User::factory()->create([
|
||||||
'rol_codigo' => RoleCode::AdminApp->value,
|
'rol_codigo' => RoleCode::AdminApp->value,
|
||||||
'tenant_codigo' => $tenant->codigo,
|
'tenant_codigo' => $tenant->codigo,
|
||||||
@@ -47,13 +44,15 @@ class AdminAppSaleFormControllerTest extends TestCase
|
|||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/forms/sale')
|
$this->getJson('/api/v1/adminapp/forms/sale')
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertJsonCount(count(Purchase::statuses()), 'data.statuses')
|
->assertJsonCount(count(Purchase::adminStatusCodes()), 'data.statuses')
|
||||||
->assertJsonPath('data.statuses.0.code', Purchase::STATUS_CREATED)
|
->assertJsonPath('data.statuses.0.value', Purchase::ADMIN_STATUS_INCOMPLETE)
|
||||||
->assertJsonPath('data.statuses.0.name', 'Creada')
|
->assertJsonPath('data.statuses.0.label', 'Por completar datos')
|
||||||
->assertJsonPath('data.statuses.1.code', Purchase::STATUS_PENDING_PAYMENT)
|
->assertJsonPath('data.statuses.0.real_statuses.0', Purchase::STATUS_CREATED)
|
||||||
->assertJsonPath('data.statuses.2.code', Purchase::STATUS_IN_REVIEW)
|
->assertJsonPath('data.statuses.1.value', Purchase::ADMIN_STATUS_AWAITING_PAYMENT)
|
||||||
->assertJsonPath('data.statuses.3.code', Purchase::STATUS_PAID)
|
->assertJsonPath('data.statuses.1.real_statuses.0', Purchase::STATUS_PENDING_PAYMENT)
|
||||||
->assertJsonPath('data.statuses.6.code', Purchase::STATUS_EXPIRED);
|
->assertJsonPath('data.statuses.1.real_statuses.1', Purchase::STATUS_IN_REVIEW)
|
||||||
|
->assertJsonPath('data.statuses.2.value', Purchase::ADMIN_STATUS_CONFIRMED)
|
||||||
|
->assertJsonPath('data.statuses.3.value', Purchase::ADMIN_STATUS_CANCELLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_a_customer_cannot_get_the_sale_form(): void
|
public function test_a_customer_cannot_get_the_sale_form(): void
|
||||||
@@ -65,4 +64,34 @@ class AdminAppSaleFormControllerTest extends TestCase
|
|||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/forms/sale')->assertForbidden();
|
$this->getJson('/api/v1/adminapp/forms/sale')->assertForbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function createTenant(string $code): Tenant
|
||||||
|
{
|
||||||
|
$headerLogo = $this->createAttachment("{$code}-header");
|
||||||
|
$footerLogo = $this->createAttachment("{$code}-footer");
|
||||||
|
|
||||||
|
return Tenant::query()->create([
|
||||||
|
'codigo' => $code,
|
||||||
|
'nombre' => ucfirst($code),
|
||||||
|
'dominio' => "{$code}.test",
|
||||||
|
'primary_color' => '#000000',
|
||||||
|
'secondary_color' => '#ffffff',
|
||||||
|
'danger_color' => '#dc3545',
|
||||||
|
'header_bg_color' => '#ffffff',
|
||||||
|
'footer_bg_color' => '#000000',
|
||||||
|
'header_logo_id' => $headerLogo->id,
|
||||||
|
'footer_logo_id' => $footerLogo->id,
|
||||||
|
'website_type_code' => 'onticket',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createAttachment(string $name): Attachment
|
||||||
|
{
|
||||||
|
return Attachment::query()->create([
|
||||||
|
'path' => "test/{$name}.png",
|
||||||
|
'filename' => "{$name}.png",
|
||||||
|
'type' => AttachmentType::Image,
|
||||||
|
'mime_type' => 'image/png',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,17 +102,25 @@ class AdminAppTicketFilterFormControllerTest extends TestCase
|
|||||||
->assertJsonPath('data.fields.2.name', 'type')
|
->assertJsonPath('data.fields.2.name', 'type')
|
||||||
->assertJsonPath('data.fields.2.query_param', 'type')
|
->assertJsonPath('data.fields.2.query_param', 'type')
|
||||||
->assertJsonPath('data.fields.2.depends_on', 'product')
|
->assertJsonPath('data.fields.2.depends_on', 'product')
|
||||||
->assertJsonPath('data.fields.3.name', 'date')
|
->assertJsonPath('data.fields.3.name', 'size')
|
||||||
->assertJsonPath('data.fields.3.query_param', 'date')
|
->assertJsonPath('data.fields.3.query_param', 'size')
|
||||||
->assertJsonPath('data.fields.4.name', 'status')
|
->assertJsonPath('data.fields.3.depends_on', 'type')
|
||||||
->assertJsonPath('data.fields.4.query_param', 'status')
|
->assertJsonPath('data.fields.4.name', 'date')
|
||||||
|
->assertJsonPath('data.fields.4.query_param', 'date')
|
||||||
|
->assertJsonPath('data.fields.4.depends_on', 'category')
|
||||||
|
->assertJsonPath('data.fields.5.name', 'status')
|
||||||
|
->assertJsonPath('data.fields.5.query_param', 'status')
|
||||||
->assertJsonPath('data.columns.0.key', 'order_number')
|
->assertJsonPath('data.columns.0.key', 'order_number')
|
||||||
->assertJsonPath('data.columns.0.sort_param', 'order_number')
|
->assertJsonPath('data.columns.0.sort_param', 'order_number')
|
||||||
->assertJsonPath('data.columns.1.key', 'category')
|
->assertJsonPath('data.columns.1.key', 'category')
|
||||||
->assertJsonPath('data.columns.2.key', 'product')
|
->assertJsonPath('data.columns.2.key', 'product')
|
||||||
->assertJsonPath('data.columns.2.sortable', false)
|
->assertJsonPath('data.columns.2.sortable', false)
|
||||||
->assertJsonPath('data.columns.3.key', 'type')
|
->assertJsonPath('data.columns.3.key', 'type')
|
||||||
->assertJsonPath('data.columns.3.sortable', false);
|
->assertJsonPath('data.columns.3.sortable', false)
|
||||||
|
->assertJsonPath('data.columns.4.key', 'date')
|
||||||
|
->assertJsonPath('data.columns.4.sortable', false)
|
||||||
|
->assertJsonPath('data.columns.5.key', 'size')
|
||||||
|
->assertJsonPath('data.columns.5.sortable', false);
|
||||||
|
|
||||||
$categories = collect($response->json('data.fields.0.options'));
|
$categories = collect($response->json('data.fields.0.options'));
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
@@ -121,22 +129,63 @@ class AdminAppTicketFilterFormControllerTest extends TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$entries = $categories->firstWhere('value', 'entradas');
|
$entries = $categories->firstWhere('value', 'entradas');
|
||||||
$this->assertSame('Abono', $entries['children']['options'][0]['label']);
|
$this->assertSame('Abono', $entries['children'][0]['options'][0]['label']);
|
||||||
$this->assertTrue($entries['children']['options'][0]['children']['disabled']);
|
$this->assertTrue($entries['children'][0]['options'][0]['children'][0]['disabled']);
|
||||||
|
$this->assertTrue($entries['children'][1]['disabled']);
|
||||||
|
|
||||||
$camping = $categories->firstWhere('value', 'alojamientos');
|
$camping = $categories->firstWhere('value', 'alojamientos');
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
['Carpa', 'Motorhome'],
|
['Carpa', 'Motorhome'],
|
||||||
collect($camping['children']['options'])->pluck('label')->all(),
|
collect($camping['children'][0]['options'])->pluck('label')->all(),
|
||||||
);
|
);
|
||||||
$this->assertTrue($camping['children']['options'][0]['children']['disabled']);
|
$this->assertTrue($camping['children'][0]['options'][0]['children'][0]['disabled']);
|
||||||
|
|
||||||
$merchandise = $categories->firstWhere('value', 'merchandising');
|
$merchandise = $categories->firstWhere('value', 'merchandising');
|
||||||
$this->assertSame('Camiseta', $merchandise['children']['options'][0]['label']);
|
$merchandiseProduct = $merchandise['children'][0]['options'][0];
|
||||||
|
$this->assertSame('Camiseta', $merchandiseProduct['label']);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
['Verde', 'Blanco'],
|
['Verde', 'Blanco'],
|
||||||
collect($merchandise['children']['options'][0]['children']['options'])->pluck('label')->all(),
|
collect($merchandiseProduct['children'][0]['options'])->pluck('label')->all(),
|
||||||
);
|
);
|
||||||
|
$this->assertSame(
|
||||||
|
['14', 'S', 'M', 'L', 'XL', 'XXL'],
|
||||||
|
collect($merchandiseProduct['children'][0]['options'][0]['children'][0]['options'])
|
||||||
|
->pluck('label')
|
||||||
|
->all(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_merchandise_sizes_are_scoped_to_the_selected_product_and_color(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createFiestaFutbolInfantilTenant();
|
||||||
|
$this->grantTicketsMenu($tenant);
|
||||||
|
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||||
|
|
||||||
|
$merchandise = CatalogItem::query()
|
||||||
|
->where('tenant_code', $tenant->codigo)
|
||||||
|
->where('slug', 'camiseta')
|
||||||
|
->with([
|
||||||
|
'itemAttributes.attribute.options',
|
||||||
|
'variants.definitions.itemAttribute.attribute.options',
|
||||||
|
])
|
||||||
|
->firstOrFail();
|
||||||
|
$whiteXxl = $merchandise->variants->first(fn ($variant): bool => $variant->selectionValues()->get('color') === 'Blanco'
|
||||||
|
&& $variant->selectionValues()->get('talle') === 'XXL');
|
||||||
|
$this->assertNotNull($whiteXxl);
|
||||||
|
app(CatalogService::class)->deleteVariant($whiteXxl);
|
||||||
|
|
||||||
|
$response = $this->getJson('/api/v1/adminapp/forms/tickets-filter')->assertOk();
|
||||||
|
$merchandiseCategory = collect($response->json('data.fields.0.options'))
|
||||||
|
->firstWhere('value', 'merchandising');
|
||||||
|
$product = $merchandiseCategory['children'][0]['options'][0];
|
||||||
|
$colors = collect($product['children'][0]['options']);
|
||||||
|
$greenSizes = collect($colors->firstWhere('value', 'Verde')['children'][0]['options'])
|
||||||
|
->pluck('value');
|
||||||
|
$whiteSizes = collect($colors->firstWhere('value', 'Blanco')['children'][0]['options'])
|
||||||
|
->pluck('value');
|
||||||
|
|
||||||
|
$this->assertContains('XXL', $greenSizes);
|
||||||
|
$this->assertNotContains('XXL', $whiteSizes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_a_food_schedule_is_only_returned_when_a_variant_exists_for_the_date(): void
|
public function test_a_food_schedule_is_only_returned_when_a_variant_exists_for_the_date(): void
|
||||||
@@ -145,7 +194,6 @@ class AdminAppTicketFilterFormControllerTest extends TestCase
|
|||||||
$this->grantTicketsMenu($tenant);
|
$this->grantTicketsMenu($tenant);
|
||||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||||
|
|
||||||
$date = $tenant->eventDates()->orderByDesc('date')->firstOrFail();
|
|
||||||
$food = CatalogItem::query()
|
$food = CatalogItem::query()
|
||||||
->where('tenant_code', $tenant->codigo)
|
->where('tenant_code', $tenant->codigo)
|
||||||
->where('slug', 'comida')
|
->where('slug', 'comida')
|
||||||
@@ -158,15 +206,12 @@ class AdminAppTicketFilterFormControllerTest extends TestCase
|
|||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
|
|
||||||
$food->variants
|
$food->variants
|
||||||
->filter(fn ($variant): bool => $variant->selectedEventDates()->contains('id', $date->id)
|
->filter(fn ($variant): bool => $variant->selectionValues()->get('horario') === 'Almuerzo')
|
||||||
&& $variant->selectionValues()->get('horario') === 'Almuerzo')
|
|
||||||
->each->delete();
|
->each->delete();
|
||||||
|
|
||||||
$response = $this->getJson('/api/v1/adminapp/forms/tickets-filter')->assertOk();
|
$response = $this->getJson('/api/v1/adminapp/forms/tickets-filter')->assertOk();
|
||||||
$foodCategory = collect($response->json('data.fields.0.options'))->firstWhere('value', 'comidas');
|
$foodCategory = collect($response->json('data.fields.0.options'))->firstWhere('value', 'comidas');
|
||||||
$dateProduct = collect($foodCategory['children']['options'])
|
$schedules = collect($foodCategory['children'][0]['options'])->pluck('value');
|
||||||
->firstWhere('value', (string) $date->id);
|
|
||||||
$schedules = collect($dateProduct['children']['options'])->pluck('value');
|
|
||||||
|
|
||||||
$this->assertNotContains('Almuerzo', $schedules);
|
$this->assertNotContains('Almuerzo', $schedules);
|
||||||
$this->assertContains('Desayuno', $schedules);
|
$this->assertContains('Desayuno', $schedules);
|
||||||
@@ -195,6 +240,7 @@ class AdminAppTicketFilterFormControllerTest extends TestCase
|
|||||||
&& $variant->selectionValues()->get('horario') === 'Cena';
|
&& $variant->selectionValues()->get('horario') === 'Cena';
|
||||||
});
|
});
|
||||||
$this->assertNotNull($historicalVariant);
|
$this->assertNotNull($historicalVariant);
|
||||||
|
$historicalService = $historicalVariant->selectionValues()->get('servicio');
|
||||||
|
|
||||||
$ticket = Ticket::query()->create([
|
$ticket = Ticket::query()->create([
|
||||||
'tenant_code' => $tenant->codigo,
|
'tenant_code' => $tenant->codigo,
|
||||||
@@ -213,26 +259,29 @@ class AdminAppTicketFilterFormControllerTest extends TestCase
|
|||||||
|
|
||||||
$response = $this->getJson('/api/v1/adminapp/forms/tickets-filter')->assertOk();
|
$response = $this->getJson('/api/v1/adminapp/forms/tickets-filter')->assertOk();
|
||||||
$foodCategory = collect($response->json('data.fields.0.options'))->firstWhere('value', 'comidas');
|
$foodCategory = collect($response->json('data.fields.0.options'))->firstWhere('value', 'comidas');
|
||||||
$products = collect($foodCategory['children']['options']);
|
$products = collect($foodCategory['children'][0]['options']);
|
||||||
|
|
||||||
$this->assertCount(1, $products);
|
$this->assertCount(1, $products);
|
||||||
$this->assertSame('12/10', $products->first()['label']);
|
$this->assertSame('Cena', $products->first()['label']);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
['Cena'],
|
[$historicalService],
|
||||||
collect($products->first()['children']['options'])->pluck('label')->all(),
|
collect($products->first()['children'][0]['options'])->pluck('label')->all(),
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets?'.http_build_query([
|
$this->getJson('/api/v1/adminapp/tenant/tickets?'.http_build_query([
|
||||||
'category' => 'comidas',
|
'category' => 'comidas',
|
||||||
'product' => $products->first()['value'],
|
'product' => $products->first()['value'],
|
||||||
'type' => 'Cena',
|
'type' => $historicalService,
|
||||||
|
'date' => '2026-10-12',
|
||||||
]))
|
]))
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertJsonCount(1, 'data')
|
->assertJsonCount(1, 'data')
|
||||||
->assertJsonPath('data.0.id', $ticket->id)
|
->assertJsonPath('data.0.id', $ticket->id)
|
||||||
->assertJsonPath('data.0.values.category', 'Comida')
|
->assertJsonPath('data.0.values.category', 'Comida')
|
||||||
->assertJsonPath('data.0.values.product', '12/10')
|
->assertJsonPath('data.0.values.product', 'Cena')
|
||||||
->assertJsonPath('data.0.values.type', 'Cena');
|
->assertJsonPath('data.0.values.type', $historicalService)
|
||||||
|
->assertJsonPath('data.0.values.date', '12/10')
|
||||||
|
->assertJsonPath('data.0.values.size', '-');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createFiestaFutbolInfantilTenant(): Tenant
|
private function createFiestaFutbolInfantilTenant(): Tenant
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ class NotificationMailServiceTest extends TestCase
|
|||||||
'precio' => 25,
|
'precio' => 25,
|
||||||
'has_tickets' => true,
|
'has_tickets' => true,
|
||||||
]);
|
]);
|
||||||
$purchase->items()->create([
|
$purchaseItem = $purchase->items()->create([
|
||||||
'source_catalog_item_id' => $catalogItem->id,
|
'source_catalog_item_id' => $catalogItem->id,
|
||||||
'nombre' => 'Entrada',
|
'nombre' => 'Entrada',
|
||||||
'descripcion' => 'Entrada general',
|
'descripcion' => 'Entrada general',
|
||||||
@@ -175,7 +175,7 @@ class NotificationMailServiceTest extends TestCase
|
|||||||
$ticket = Ticket::query()->create([
|
$ticket = Ticket::query()->create([
|
||||||
'tenant_code' => $this->tenant->codigo,
|
'tenant_code' => $this->tenant->codigo,
|
||||||
'ticket' => fake()->uuid(),
|
'ticket' => fake()->uuid(),
|
||||||
'source_purchase_id' => $purchase->id,
|
'source_purchase_item_id' => $purchaseItem->id,
|
||||||
'source_catalog_item_id' => $catalogItem->id,
|
'source_catalog_item_id' => $catalogItem->id,
|
||||||
'user_id' => $this->user->id,
|
'user_id' => $this->user->id,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use App\Domains\Catalog\Enums\InventoryPolicy;
|
|||||||
use App\Domains\Catalog\Models\CatalogItem;
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
use App\Domains\Catalog\Models\Category;
|
use App\Domains\Catalog\Models\Category;
|
||||||
use App\Domains\Catalog\Models\Inventory;
|
use App\Domains\Catalog\Models\Inventory;
|
||||||
|
use App\Domains\Catalog\Models\StockReservation;
|
||||||
use App\Domains\Catalog\Models\Variant;
|
use App\Domains\Catalog\Models\Variant;
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
use App\Domains\Purchase\Services\CheckoutService;
|
use App\Domains\Purchase\Services\CheckoutService;
|
||||||
@@ -714,11 +715,11 @@ class StorePurchaseTest extends TestCase
|
|||||||
|
|
||||||
$this->actingAs($user, 'sanctum')
|
$this->actingAs($user, 'sanctum')
|
||||||
->postJson("/api/tenants/sonder/compras/{$purchase->id}/cancel")
|
->postJson("/api/tenants/sonder/compras/{$purchase->id}/cancel")
|
||||||
->assertUnprocessable()
|
->assertOk()
|
||||||
->assertJsonPath('code', 'purchase.expired');
|
->assertJsonPath('data.status', Purchase::STATUS_EXPIRED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_an_overdue_purchase_cannot_be_cancelled_before_the_expiration_job_runs(): void
|
public function test_leaving_an_overdue_purchase_expires_it_before_the_expiration_job_runs(): void
|
||||||
{
|
{
|
||||||
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
@@ -728,20 +729,17 @@ class StorePurchaseTest extends TestCase
|
|||||||
|
|
||||||
$this->actingAs($user, 'sanctum')
|
$this->actingAs($user, 'sanctum')
|
||||||
->postJson("/api/tenants/sonder/compras/{$purchase->id}/cancel")
|
->postJson("/api/tenants/sonder/compras/{$purchase->id}/cancel")
|
||||||
->assertUnprocessable()
|
->assertOk()
|
||||||
->assertExactJson([
|
->assertJsonPath('data.status', Purchase::STATUS_EXPIRED);
|
||||||
'code' => 'stock_reservation.expired',
|
|
||||||
'message' => __('api.cart.reservation_expired'),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->assertDatabaseHas('compras', [
|
$this->assertDatabaseHas('compras', [
|
||||||
'id' => $purchase->id,
|
'id' => $purchase->id,
|
||||||
'status' => Purchase::STATUS_CREATED,
|
'status' => Purchase::STATUS_EXPIRED,
|
||||||
'stock_reservation_id' => $purchase->stock_reservation_id,
|
'stock_reservation_id' => $purchase->stock_reservation_id,
|
||||||
]);
|
]);
|
||||||
$this->assertDatabaseHas('stock_reservations', [
|
$this->assertDatabaseHas('stock_reservations', [
|
||||||
'id' => $purchase->stock_reservation_id,
|
'id' => $purchase->stock_reservation_id,
|
||||||
'status' => 'active',
|
'status' => StockReservation::STATUS_EXPIRED,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace Tests\Feature\Sale;
|
namespace Tests\Feature\Sale;
|
||||||
|
|
||||||
|
use App\Domains\Attachable\Enums\AttachmentType;
|
||||||
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
use App\Domains\Auth\Models\User;
|
use App\Domains\Auth\Models\User;
|
||||||
use App\Domains\Authorization\Enums\RoleCode;
|
use App\Domains\Authorization\Enums\RoleCode;
|
||||||
use App\Domains\Cart\Models\Cart;
|
use App\Domains\Cart\Models\Cart;
|
||||||
@@ -9,6 +11,8 @@ use App\Domains\Cart\Models\CartItem;
|
|||||||
use App\Domains\Catalog\Models\CatalogItem;
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
use App\Domains\Catalog\Models\Inventory;
|
use App\Domains\Catalog\Models\Inventory;
|
||||||
use App\Domains\Catalog\Models\Variant;
|
use App\Domains\Catalog\Models\Variant;
|
||||||
|
use App\Domains\Logging\Enums\ValueChangeActorType;
|
||||||
|
use App\Domains\Logging\Models\ValueChange;
|
||||||
use App\Domains\Purchase\Events\PurchasePaid;
|
use App\Domains\Purchase\Events\PurchasePaid;
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
use App\Domains\Purchase\Models\PurchaseItem;
|
use App\Domains\Purchase\Models\PurchaseItem;
|
||||||
@@ -34,6 +38,96 @@ class AdminAppSaleControllerTest extends TestCase
|
|||||||
WebsiteType::query()->create(['codigo' => 'onticket', 'nombre' => 'OnTicket']);
|
WebsiteType::query()->create(['codigo' => 'onticket', 'nombre' => 'OnTicket']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_sale_modifications_use_sale_filters_and_resulting_status(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('acme');
|
||||||
|
$otherTenant = $this->createTenant('other');
|
||||||
|
$admin = $this->createAdminAppUser($tenant);
|
||||||
|
Sanctum::actingAs($admin);
|
||||||
|
|
||||||
|
$sale = Purchase::query()->create([
|
||||||
|
'tenant_codigo' => $tenant->codigo,
|
||||||
|
'nombre_apellido' => 'Ana Pérez',
|
||||||
|
'status' => Purchase::STATUS_CANCELLED,
|
||||||
|
'total' => '10000.00',
|
||||||
|
]);
|
||||||
|
Purchase::query()->whereKey($sale->id)->update([
|
||||||
|
'created_at' => '2026-08-04 10:00:00',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$otherSale = Purchase::query()->create([
|
||||||
|
'tenant_codigo' => $tenant->codigo,
|
||||||
|
'nombre_apellido' => 'Otro cliente',
|
||||||
|
'status' => Purchase::STATUS_PAID,
|
||||||
|
'total' => '20000.00',
|
||||||
|
]);
|
||||||
|
Purchase::query()->whereKey($otherSale->id)->update([
|
||||||
|
'created_at' => '2026-08-05 10:00:00',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$confirmedChange = ValueChange::query()->create([
|
||||||
|
'tenant_code' => $tenant->codigo,
|
||||||
|
'trackable_type' => $sale->getMorphClass(),
|
||||||
|
'trackable_id' => $sale->id,
|
||||||
|
'attribute' => 'status',
|
||||||
|
'old_value' => Purchase::STATUS_PENDING_PAYMENT,
|
||||||
|
'new_value' => Purchase::STATUS_PAID,
|
||||||
|
'changed_at' => '2026-08-06 10:00:00',
|
||||||
|
'actor_type' => ValueChangeActorType::User,
|
||||||
|
'user_id' => $admin->id,
|
||||||
|
]);
|
||||||
|
ValueChange::query()->create([
|
||||||
|
'tenant_code' => $tenant->codigo,
|
||||||
|
'trackable_type' => $sale->getMorphClass(),
|
||||||
|
'trackable_id' => $sale->id,
|
||||||
|
'attribute' => 'status',
|
||||||
|
'old_value' => Purchase::STATUS_PAID,
|
||||||
|
'new_value' => Purchase::STATUS_CANCELLED,
|
||||||
|
'changed_at' => '2026-08-07 10:00:00',
|
||||||
|
'actor_type' => ValueChangeActorType::User,
|
||||||
|
'user_id' => $admin->id,
|
||||||
|
]);
|
||||||
|
ValueChange::query()->create([
|
||||||
|
'tenant_code' => $tenant->codigo,
|
||||||
|
'trackable_type' => $otherSale->getMorphClass(),
|
||||||
|
'trackable_id' => $otherSale->id,
|
||||||
|
'attribute' => 'status',
|
||||||
|
'old_value' => Purchase::STATUS_PENDING_PAYMENT,
|
||||||
|
'new_value' => Purchase::STATUS_PAID,
|
||||||
|
'changed_at' => '2026-08-08 10:00:00',
|
||||||
|
'actor_type' => ValueChangeActorType::System,
|
||||||
|
]);
|
||||||
|
ValueChange::query()->create([
|
||||||
|
'tenant_code' => $otherTenant->codigo,
|
||||||
|
'trackable_type' => $sale->getMorphClass(),
|
||||||
|
'trackable_id' => $sale->id,
|
||||||
|
'attribute' => 'status',
|
||||||
|
'old_value' => Purchase::STATUS_PENDING_PAYMENT,
|
||||||
|
'new_value' => Purchase::STATUS_PAID,
|
||||||
|
'changed_at' => '2026-08-09 10:00:00',
|
||||||
|
'actor_type' => ValueChangeActorType::System,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/sales/modifications?'.http_build_query([
|
||||||
|
'q' => 'Ana',
|
||||||
|
'id' => $sale->id,
|
||||||
|
'sale_date' => '2026-08-04',
|
||||||
|
'status' => Purchase::ADMIN_STATUS_CONFIRMED,
|
||||||
|
]))
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonCount(1, 'data')
|
||||||
|
->assertJsonPath('data.0.id', $confirmedChange->id)
|
||||||
|
->assertJsonPath('data.0.new_value', Purchase::STATUS_PAID)
|
||||||
|
->assertJsonPath('data.0.admin_status', Purchase::ADMIN_STATUS_CONFIRMED);
|
||||||
|
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/sales/modifications?status='.
|
||||||
|
Purchase::ADMIN_STATUS_CANCELLED)
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonCount(1, 'data')
|
||||||
|
->assertJsonPath('data.0.sale_id', $sale->id)
|
||||||
|
->assertJsonPath('data.0.new_value', Purchase::STATUS_CANCELLED);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_sales_list_uses_purchase_item_snapshots_for_every_status(): void
|
public function test_sales_list_uses_purchase_item_snapshots_for_every_status(): void
|
||||||
{
|
{
|
||||||
$tenant = $this->createTenant('acme');
|
$tenant = $this->createTenant('acme');
|
||||||
@@ -64,6 +158,7 @@ class AdminAppSaleControllerTest extends TestCase
|
|||||||
PurchaseItem::query()->create([
|
PurchaseItem::query()->create([
|
||||||
'compra_id' => $createdPurchase->id,
|
'compra_id' => $createdPurchase->id,
|
||||||
'source_catalog_item_id' => $catalogItem->id,
|
'source_catalog_item_id' => $catalogItem->id,
|
||||||
|
'nombre' => $catalogItem->nombre,
|
||||||
'item_nombre' => $catalogItem->nombre,
|
'item_nombre' => $catalogItem->nombre,
|
||||||
'cantidad' => 3,
|
'cantidad' => 3,
|
||||||
'precio_unitario' => '10000.00',
|
'precio_unitario' => '10000.00',
|
||||||
@@ -88,6 +183,7 @@ class AdminAppSaleControllerTest extends TestCase
|
|||||||
PurchaseItem::query()->create([
|
PurchaseItem::query()->create([
|
||||||
'compra_id' => $pendingPurchase->id,
|
'compra_id' => $pendingPurchase->id,
|
||||||
'source_catalog_item_id' => $catalogItem->id,
|
'source_catalog_item_id' => $catalogItem->id,
|
||||||
|
'nombre' => $catalogItem->nombre,
|
||||||
'item_nombre' => $catalogItem->nombre,
|
'item_nombre' => $catalogItem->nombre,
|
||||||
'cantidad' => 4,
|
'cantidad' => 4,
|
||||||
'precio_unitario' => '10000.00',
|
'precio_unitario' => '10000.00',
|
||||||
@@ -102,6 +198,7 @@ class AdminAppSaleControllerTest extends TestCase
|
|||||||
PurchaseItem::query()->create([
|
PurchaseItem::query()->create([
|
||||||
'compra_id' => $paidPurchase->id,
|
'compra_id' => $paidPurchase->id,
|
||||||
'source_catalog_item_id' => $catalogItem->id,
|
'source_catalog_item_id' => $catalogItem->id,
|
||||||
|
'nombre' => $catalogItem->nombre,
|
||||||
'item_nombre' => $catalogItem->nombre,
|
'item_nombre' => $catalogItem->nombre,
|
||||||
'cantidad' => 2,
|
'cantidad' => 2,
|
||||||
'precio_unitario' => '10000.00',
|
'precio_unitario' => '10000.00',
|
||||||
@@ -116,6 +213,7 @@ class AdminAppSaleControllerTest extends TestCase
|
|||||||
PurchaseItem::query()->create([
|
PurchaseItem::query()->create([
|
||||||
'compra_id' => $supersededPurchase->id,
|
'compra_id' => $supersededPurchase->id,
|
||||||
'source_catalog_item_id' => $catalogItem->id,
|
'source_catalog_item_id' => $catalogItem->id,
|
||||||
|
'nombre' => $catalogItem->nombre,
|
||||||
'item_nombre' => $catalogItem->nombre,
|
'item_nombre' => $catalogItem->nombre,
|
||||||
'cantidad' => 5,
|
'cantidad' => 5,
|
||||||
'precio_unitario' => '10000.00',
|
'precio_unitario' => '10000.00',
|
||||||
@@ -124,17 +222,25 @@ class AdminAppSaleControllerTest extends TestCase
|
|||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/sales?sort_by=id&sort_direction=asc')
|
$this->getJson('/api/v1/adminapp/tenant/sales?sort_by=id&sort_direction=asc')
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertJsonCount(3, 'data')
|
->assertJsonCount(4, 'data')
|
||||||
->assertJsonPath('data.0.id', $createdPurchase->id)
|
->assertJsonPath('data.0.id', $createdPurchase->id)
|
||||||
->assertJsonPath('data.0.quantity', 3)
|
->assertJsonPath('data.0.quantity', 3)
|
||||||
|
->assertJsonPath('data.0.admin_status', Purchase::ADMIN_STATUS_INCOMPLETE)
|
||||||
|
->assertJsonPath('data.0.status_label', 'Por completar datos')
|
||||||
->assertJsonPath('data.1.id', $pendingPurchase->id)
|
->assertJsonPath('data.1.id', $pendingPurchase->id)
|
||||||
->assertJsonPath('data.1.quantity', 4)
|
->assertJsonPath('data.1.quantity', 4)
|
||||||
|
->assertJsonPath('data.1.admin_status', Purchase::ADMIN_STATUS_AWAITING_PAYMENT)
|
||||||
|
->assertJsonPath('data.1.status_label', 'Esperando pago')
|
||||||
->assertJsonPath('data.2.id', $paidPurchase->id)
|
->assertJsonPath('data.2.id', $paidPurchase->id)
|
||||||
->assertJsonPath('data.2.quantity', 2);
|
->assertJsonPath('data.2.quantity', 2)
|
||||||
|
->assertJsonPath('data.2.admin_status', Purchase::ADMIN_STATUS_CONFIRMED)
|
||||||
|
->assertJsonPath('data.2.status_label', 'Confirmado')
|
||||||
|
->assertJsonPath('data.3.id', $supersededPurchase->id)
|
||||||
|
->assertJsonPath('data.3.admin_status', Purchase::ADMIN_STATUS_CANCELLED)
|
||||||
|
->assertJsonPath('data.3.status_label', 'Anulado');
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/sales?status='.Purchase::STATUS_SUPERSEDED)
|
$this->getJson('/api/v1/adminapp/tenant/sales?status='.Purchase::STATUS_SUPERSEDED)
|
||||||
->assertOk()
|
->assertUnprocessable();
|
||||||
->assertJsonCount(0, 'data');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_authentication_is_required_to_read_a_sale_detail(): void
|
public function test_authentication_is_required_to_read_a_sale_detail(): void
|
||||||
@@ -142,7 +248,7 @@ class AdminAppSaleControllerTest extends TestCase
|
|||||||
$this->getJson('/api/v1/adminapp/tenant/sales/1')->assertUnauthorized();
|
$this->getJson('/api/v1/adminapp/tenant/sales/1')->assertUnauthorized();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_pending_payment_filter_also_returns_purchases_in_review(): void
|
public function test_awaiting_payment_filter_returns_every_mapped_real_status(): void
|
||||||
{
|
{
|
||||||
$tenant = $this->createTenant('acme');
|
$tenant = $this->createTenant('acme');
|
||||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||||
@@ -160,13 +266,41 @@ class AdminAppSaleControllerTest extends TestCase
|
|||||||
'status' => Purchase::STATUS_PAID,
|
'status' => Purchase::STATUS_PAID,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/sales?status=pending_payment&sort_by=id&sort_direction=asc')
|
$this->getJson('/api/v1/adminapp/tenant/sales?status=awaiting_payment&sort_by=id&sort_direction=asc')
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertJsonCount(2, 'data')
|
->assertJsonCount(2, 'data')
|
||||||
->assertJsonPath('data.0.id', $pendingPurchase->id)
|
->assertJsonPath('data.0.id', $pendingPurchase->id)
|
||||||
->assertJsonPath('data.1.id', $reviewPurchase->id);
|
->assertJsonPath('data.1.id', $reviewPurchase->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_cancelled_filter_returns_every_visible_mapped_real_status(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('acme');
|
||||||
|
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||||
|
|
||||||
|
foreach ([
|
||||||
|
Purchase::STATUS_CANCELLED,
|
||||||
|
Purchase::STATUS_REJECTED,
|
||||||
|
Purchase::STATUS_EXPIRED,
|
||||||
|
Purchase::STATUS_SUPERSEDED,
|
||||||
|
] as $status) {
|
||||||
|
Purchase::query()->create([
|
||||||
|
'tenant_codigo' => $tenant->codigo,
|
||||||
|
'status' => $status,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
Purchase::query()->create([
|
||||||
|
'tenant_codigo' => $tenant->codigo,
|
||||||
|
'status' => Purchase::STATUS_PAID,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/sales?status=cancelled')
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonCount(4, 'data')
|
||||||
|
->assertJsonPath('data.0.admin_status', Purchase::ADMIN_STATUS_CANCELLED)
|
||||||
|
->assertJsonPath('data.0.status_label', 'Anulado');
|
||||||
|
}
|
||||||
|
|
||||||
public function test_an_adminapp_user_can_read_a_sale_detail_from_its_tenant(): void
|
public function test_an_adminapp_user_can_read_a_sale_detail_from_its_tenant(): void
|
||||||
{
|
{
|
||||||
$tenant = $this->createTenant('acme');
|
$tenant = $this->createTenant('acme');
|
||||||
@@ -233,6 +367,7 @@ class AdminAppSaleControllerTest extends TestCase
|
|||||||
$purchaseItem = PurchaseItem::query()->create([
|
$purchaseItem = PurchaseItem::query()->create([
|
||||||
'compra_id' => $purchase->id,
|
'compra_id' => $purchase->id,
|
||||||
'source_catalog_item_id' => $catalogItem->id,
|
'source_catalog_item_id' => $catalogItem->id,
|
||||||
|
'nombre' => $catalogItem->nombre,
|
||||||
'item_nombre' => $catalogItem->nombre,
|
'item_nombre' => $catalogItem->nombre,
|
||||||
'cantidad' => 2,
|
'cantidad' => 2,
|
||||||
'precio_unitario' => '12500.00',
|
'precio_unitario' => '12500.00',
|
||||||
@@ -336,17 +471,28 @@ class AdminAppSaleControllerTest extends TestCase
|
|||||||
'precio' => 20000,
|
'precio' => 20000,
|
||||||
'has_tickets' => true,
|
'has_tickets' => true,
|
||||||
]);
|
]);
|
||||||
|
$purchaseItem = $purchase->items()->create([
|
||||||
|
'source_catalog_item_id' => $catalogItem->id,
|
||||||
|
'nombre' => $catalogItem->nombre,
|
||||||
|
'descripcion' => $catalogItem->descripcion,
|
||||||
|
'slug' => $catalogItem->slug,
|
||||||
|
'item_nombre' => $catalogItem->nombre,
|
||||||
|
'variant_attributes' => [],
|
||||||
|
'cantidad' => 2,
|
||||||
|
'precio_unitario' => 10000,
|
||||||
|
'total' => 20000,
|
||||||
|
]);
|
||||||
$firstTicket = Ticket::query()->create([
|
$firstTicket = Ticket::query()->create([
|
||||||
'tenant_code' => $tenant->codigo,
|
'tenant_code' => $tenant->codigo,
|
||||||
'ticket' => '11111111-1111-4111-8111-111111111111',
|
'ticket' => '11111111-1111-4111-8111-111111111111',
|
||||||
'source_purchase_id' => $purchase->id,
|
'source_purchase_item_id' => $purchaseItem->id,
|
||||||
'source_catalog_item_id' => $catalogItem->id,
|
'source_catalog_item_id' => $catalogItem->id,
|
||||||
'user_id' => $admin->id,
|
'user_id' => $admin->id,
|
||||||
]);
|
]);
|
||||||
$usedTicket = Ticket::query()->create([
|
$usedTicket = Ticket::query()->create([
|
||||||
'tenant_code' => $tenant->codigo,
|
'tenant_code' => $tenant->codigo,
|
||||||
'ticket' => '22222222-2222-4222-8222-222222222222',
|
'ticket' => '22222222-2222-4222-8222-222222222222',
|
||||||
'source_purchase_id' => $purchase->id,
|
'source_purchase_item_id' => $purchaseItem->id,
|
||||||
'source_catalog_item_id' => $catalogItem->id,
|
'source_catalog_item_id' => $catalogItem->id,
|
||||||
'used_at' => now()->subMinute(),
|
'used_at' => now()->subMinute(),
|
||||||
'user_id' => $admin->id,
|
'user_id' => $admin->id,
|
||||||
@@ -468,6 +614,7 @@ class AdminAppSaleControllerTest extends TestCase
|
|||||||
PurchaseItem::query()->create([
|
PurchaseItem::query()->create([
|
||||||
'compra_id' => $purchase->id,
|
'compra_id' => $purchase->id,
|
||||||
'source_catalog_item_id' => $catalogItem->id,
|
'source_catalog_item_id' => $catalogItem->id,
|
||||||
|
'nombre' => $catalogItem->nombre,
|
||||||
'item_nombre' => $catalogItem->nombre,
|
'item_nombre' => $catalogItem->nombre,
|
||||||
'cantidad' => 2,
|
'cantidad' => 2,
|
||||||
'precio_unitario' => '10000.00',
|
'precio_unitario' => '10000.00',
|
||||||
@@ -563,14 +710,34 @@ class AdminAppSaleControllerTest extends TestCase
|
|||||||
|
|
||||||
private function createTenant(string $code): Tenant
|
private function createTenant(string $code): Tenant
|
||||||
{
|
{
|
||||||
|
$headerLogo = $this->createAttachment("{$code}-header");
|
||||||
|
$footerLogo = $this->createAttachment("{$code}-footer");
|
||||||
|
|
||||||
return Tenant::query()->create([
|
return Tenant::query()->create([
|
||||||
'codigo' => $code,
|
'codigo' => $code,
|
||||||
'nombre' => ucfirst($code),
|
'nombre' => ucfirst($code),
|
||||||
'dominio' => "{$code}.test",
|
'dominio' => "{$code}.test",
|
||||||
|
'primary_color' => '#000000',
|
||||||
|
'secondary_color' => '#ffffff',
|
||||||
|
'danger_color' => '#dc3545',
|
||||||
|
'header_bg_color' => '#ffffff',
|
||||||
|
'footer_bg_color' => '#000000',
|
||||||
|
'header_logo_id' => $headerLogo->id,
|
||||||
|
'footer_logo_id' => $footerLogo->id,
|
||||||
'website_type_code' => 'onticket',
|
'website_type_code' => 'onticket',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function createAttachment(string $name): Attachment
|
||||||
|
{
|
||||||
|
return Attachment::query()->create([
|
||||||
|
'path' => "test/{$name}.png",
|
||||||
|
'filename' => "{$name}.png",
|
||||||
|
'type' => AttachmentType::Image,
|
||||||
|
'mime_type' => 'image/png',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
private function createAdminAppUser(Tenant $tenant): User
|
private function createAdminAppUser(Tenant $tenant): User
|
||||||
{
|
{
|
||||||
return User::factory()->create([
|
return User::factory()->create([
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ class DesfilePuraTendenciaSeederTest extends TestCase
|
|||||||
->where('total', 0)
|
->where('total', 0)
|
||||||
->count());
|
->count());
|
||||||
$this->assertSame(49, DB::table('tickets')
|
$this->assertSame(49, DB::table('tickets')
|
||||||
->where('source_purchase_id', $purchase->id)
|
->whereIn('source_purchase_item_id', (clone $items)->pluck('id'))
|
||||||
->where('user_id', $user->id)
|
->where('user_id', $user->id)
|
||||||
->where('source_catalog_item_id', $catalogItemId)
|
->where('source_catalog_item_id', $catalogItemId)
|
||||||
->count());
|
->count());
|
||||||
|
|||||||
@@ -73,12 +73,13 @@ class AdminAppTicketControllerTest extends TestCase
|
|||||||
->assertJsonPath('data.0.values.id', $ticket->id)
|
->assertJsonPath('data.0.values.id', $ticket->id)
|
||||||
->assertJsonPath('data.0.values.status', Ticket::STATUS_ACTIVE)
|
->assertJsonPath('data.0.values.status', Ticket::STATUS_ACTIVE)
|
||||||
->assertJsonMissingPath('data.0.values.ticket')
|
->assertJsonMissingPath('data.0.values.ticket')
|
||||||
->assertJsonMissingPath('data.0.values.date')
|
->assertJsonPath('data.0.values.date', '-')
|
||||||
|
->assertJsonPath('data.0.values.size', '-')
|
||||||
->assertJsonMissingPath('data.0.date')
|
->assertJsonMissingPath('data.0.date')
|
||||||
->assertJsonPath('meta.total', 1);
|
->assertJsonPath('meta.total', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_it_supports_id_and_uuid_search(): void
|
public function test_it_searches_by_id_and_does_not_search_by_uuid(): void
|
||||||
{
|
{
|
||||||
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
||||||
$admin = $this->createAdminAppUser($tenant);
|
$admin = $this->createAdminAppUser($tenant);
|
||||||
@@ -94,9 +95,98 @@ class AdminAppTicketControllerTest extends TestCase
|
|||||||
->assertJsonPath('data.0.id', $matching->id);
|
->assertJsonPath('data.0.id', $matching->id);
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets?q='.substr($matching->ticket, 0, 8))
|
$this->getJson('/api/v1/adminapp/tenant/tickets?q='.substr($matching->ticket, 0, 8))
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonCount(0, 'data');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_searches_by_visible_client_and_scanner_names(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
||||||
|
$admin = $this->createAdminAppUser($tenant);
|
||||||
|
$client = User::factory()->create([
|
||||||
|
'tenant_codigo' => $tenant->codigo,
|
||||||
|
'nombre_apellido' => 'María Cliente',
|
||||||
|
]);
|
||||||
|
$scanner = $this->createAdminAppUser($tenant);
|
||||||
|
$scanner->update(['nombre_apellido' => 'Carlos Inspector']);
|
||||||
|
$this->grantTicketsMenu($tenant);
|
||||||
|
Sanctum::actingAs($admin);
|
||||||
|
|
||||||
|
$clientTicket = $this->createTicket($tenant, $client);
|
||||||
|
$scannerTicket = $this->createTicket($tenant, $admin, [
|
||||||
|
'scanner_user_id' => $scanner->id,
|
||||||
|
'used_at' => now(),
|
||||||
|
]);
|
||||||
|
$this->createTicket($tenant, $admin);
|
||||||
|
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/tickets?'.http_build_query(['q' => 'maría']))
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertJsonCount(1, 'data')
|
->assertJsonCount(1, 'data')
|
||||||
->assertJsonPath('data.0.ticket', $matching->ticket);
|
->assertJsonPath('data.0.id', $clientTicket->id);
|
||||||
|
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/tickets?'.http_build_query(['q' => 'INSPECTOR']))
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonCount(1, 'data')
|
||||||
|
->assertJsonPath('data.0.id', $scannerTicket->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_searches_by_order_number_and_formatted_unit_amount(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
||||||
|
$admin = $this->createAdminAppUser($tenant);
|
||||||
|
$this->grantTicketsMenu($tenant);
|
||||||
|
Sanctum::actingAs($admin);
|
||||||
|
|
||||||
|
foreach (range(1, 10) as $number) {
|
||||||
|
$this->createPurchase($tenant, $admin, now()->subMinutes($number)->toDateTimeString());
|
||||||
|
}
|
||||||
|
|
||||||
|
$item = CatalogItem::query()->create([
|
||||||
|
'tenant_code' => $tenant->codigo,
|
||||||
|
'slug' => 'entrada-busqueda',
|
||||||
|
'nombre' => 'Entrada búsqueda',
|
||||||
|
'precio' => '1234.50',
|
||||||
|
]);
|
||||||
|
$purchase = Purchase::query()->create([
|
||||||
|
'tenant_codigo' => $tenant->codigo,
|
||||||
|
'user_id' => $admin->id,
|
||||||
|
'status' => Purchase::STATUS_PAID,
|
||||||
|
'nombre_apellido' => 'Cliente de la compra',
|
||||||
|
'total' => '1234.50',
|
||||||
|
]);
|
||||||
|
$purchaseItem = PurchaseItem::query()->create([
|
||||||
|
'compra_id' => $purchase->id,
|
||||||
|
'source_catalog_item_id' => $item->id,
|
||||||
|
'nombre' => $item->nombre,
|
||||||
|
'descripcion' => '',
|
||||||
|
'slug' => $item->slug,
|
||||||
|
'item_nombre' => $item->nombre,
|
||||||
|
'cantidad' => 1,
|
||||||
|
'precio_unitario' => '1234.50',
|
||||||
|
'total' => '1234.50',
|
||||||
|
]);
|
||||||
|
$matching = $this->createTicket($tenant, $admin, [
|
||||||
|
'source_purchase_item_id' => $purchaseItem->id,
|
||||||
|
'source_catalog_item_id' => $item->id,
|
||||||
|
]);
|
||||||
|
$this->createTicket($tenant, $admin);
|
||||||
|
|
||||||
|
$this->getJson("/api/v1/adminapp/tenant/tickets?q={$purchase->id}")
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonCount(1, 'data')
|
||||||
|
->assertJsonPath('data.0.id', $matching->id);
|
||||||
|
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/tickets?'.http_build_query(['q' => 'cliente de la compra']))
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonCount(1, 'data')
|
||||||
|
->assertJsonPath('data.0.id', $matching->id);
|
||||||
|
|
||||||
|
foreach (['1234,50', '$1.234,50', '1,234.50'] as $amount) {
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/tickets?'.http_build_query(['q' => $amount]))
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonCount(1, 'data')
|
||||||
|
->assertJsonPath('data.0.id', $matching->id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_it_sorts_by_ticket_id_before_paginating(): void
|
public function test_it_sorts_by_ticket_id_before_paginating(): void
|
||||||
@@ -218,7 +308,7 @@ class AdminAppTicketControllerTest extends TestCase
|
|||||||
'nombre_apellido' => 'Nombre Apellido',
|
'nombre_apellido' => 'Nombre Apellido',
|
||||||
'total' => '8000.00',
|
'total' => '8000.00',
|
||||||
]);
|
]);
|
||||||
PurchaseItem::query()->create([
|
$purchaseItem = PurchaseItem::query()->create([
|
||||||
'compra_id' => $purchase->id,
|
'compra_id' => $purchase->id,
|
||||||
'source_catalog_item_id' => $item->id,
|
'source_catalog_item_id' => $item->id,
|
||||||
'source_variant_id' => $variant->id,
|
'source_variant_id' => $variant->id,
|
||||||
@@ -231,7 +321,7 @@ class AdminAppTicketControllerTest extends TestCase
|
|||||||
'total' => '8000.00',
|
'total' => '8000.00',
|
||||||
]);
|
]);
|
||||||
$ticket = $this->createTicket($tenant, $admin, [
|
$ticket = $this->createTicket($tenant, $admin, [
|
||||||
'source_purchase_id' => $purchase->id,
|
'source_purchase_item_id' => $purchaseItem->id,
|
||||||
'source_catalog_item_id' => $item->id,
|
'source_catalog_item_id' => $item->id,
|
||||||
'source_variant_id' => $variant->id,
|
'source_variant_id' => $variant->id,
|
||||||
'scanner_user_id' => $admin->id,
|
'scanner_user_id' => $admin->id,
|
||||||
@@ -241,6 +331,7 @@ class AdminAppTicketControllerTest extends TestCase
|
|||||||
$this->getJson('/api/v1/adminapp/tenant/tickets')
|
$this->getJson('/api/v1/adminapp/tenant/tickets')
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertJsonPath('data.0.id', $ticket->id)
|
->assertJsonPath('data.0.id', $ticket->id)
|
||||||
|
->assertJsonPath('data.0.source_purchase_item_id', $purchaseItem->id)
|
||||||
->assertJsonPath('data.0.order_number', $purchase->id)
|
->assertJsonPath('data.0.order_number', $purchase->id)
|
||||||
->assertJsonPath('data.0.product', 'Remera')
|
->assertJsonPath('data.0.product', 'Remera')
|
||||||
->assertJsonPath('data.0.amount', '8000.00')
|
->assertJsonPath('data.0.amount', '8000.00')
|
||||||
@@ -278,42 +369,103 @@ class AdminAppTicketControllerTest extends TestCase
|
|||||||
&& $variant->selectionValues()->get('horario') === 'Almuerzo');
|
&& $variant->selectionValues()->get('horario') === 'Almuerzo');
|
||||||
$this->assertNotNull($dinner);
|
$this->assertNotNull($dinner);
|
||||||
$this->assertNotNull($lunch);
|
$this->assertNotNull($lunch);
|
||||||
|
$dinnerService = $dinner->selectionValues()->get('servicio');
|
||||||
|
$otherDate = $tenant->eventDates()->where('id', '!=', $date->id)->firstOrFail();
|
||||||
|
$otherDinner = $food->variants->first(fn (Variant $variant): bool => $variant
|
||||||
|
->selectedEventDates()->contains('id', $otherDate->id)
|
||||||
|
&& $variant->selectionValues()->get('horario') === 'Cena'
|
||||||
|
&& $variant->selectionValues()->get('servicio') === $dinnerService);
|
||||||
|
$this->assertNotNull($otherDinner);
|
||||||
|
|
||||||
$matchingPurchase = $this->createPurchase($tenant, $admin, '2026-08-20 10:00:00');
|
$matchingPurchase = $this->createPurchase($tenant, $admin, '2026-08-20 10:00:00');
|
||||||
$otherPurchase = $this->createPurchase($tenant, $admin, '2026-08-21 10:00:00');
|
$otherPurchase = $this->createPurchase($tenant, $admin, '2026-08-21 10:00:00');
|
||||||
|
$dinnerItem = $this->createPurchaseItem($matchingPurchase, $food, $dinner);
|
||||||
|
$lunchItem = $this->createPurchaseItem($matchingPurchase, $food, $lunch);
|
||||||
|
$otherDinnerItem = $this->createPurchaseItem($otherPurchase, $food, $otherDinner);
|
||||||
$matching = $this->createTicket($tenant, $admin, [
|
$matching = $this->createTicket($tenant, $admin, [
|
||||||
'source_purchase_id' => $matchingPurchase->id,
|
'source_purchase_item_id' => $dinnerItem->id,
|
||||||
'source_catalog_item_id' => $food->id,
|
'source_catalog_item_id' => $food->id,
|
||||||
'source_variant_id' => $dinner->id,
|
'source_variant_id' => $dinner->id,
|
||||||
'used_at' => now(),
|
'used_at' => now(),
|
||||||
]);
|
]);
|
||||||
$this->createTicket($tenant, $admin, [
|
$this->createTicket($tenant, $admin, [
|
||||||
'source_purchase_id' => $matchingPurchase->id,
|
'source_purchase_item_id' => $lunchItem->id,
|
||||||
'source_catalog_item_id' => $food->id,
|
'source_catalog_item_id' => $food->id,
|
||||||
'source_variant_id' => $lunch->id,
|
'source_variant_id' => $lunch->id,
|
||||||
'used_at' => now(),
|
'used_at' => now(),
|
||||||
]);
|
]);
|
||||||
$this->createTicket($tenant, $admin, [
|
$this->createTicket($tenant, $admin, [
|
||||||
'source_purchase_id' => $otherPurchase->id,
|
'source_purchase_item_id' => $otherDinnerItem->id,
|
||||||
'source_catalog_item_id' => $food->id,
|
'source_catalog_item_id' => $food->id,
|
||||||
'source_variant_id' => $dinner->id,
|
'source_variant_id' => $otherDinner->id,
|
||||||
'used_at' => now(),
|
'used_at' => now(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets?'.http_build_query([
|
$this->getJson('/api/v1/adminapp/tenant/tickets?'.http_build_query([
|
||||||
'category' => 'comidas',
|
'category' => 'comidas',
|
||||||
'product' => (string) $date->id,
|
'product' => 'Cena',
|
||||||
'type' => 'Cena',
|
'type' => $dinnerService,
|
||||||
'date' => '2026-08-20',
|
'date' => $date->date->format('Y-m-d'),
|
||||||
'status' => Ticket::STATUS_USED,
|
'status' => Ticket::STATUS_USED,
|
||||||
]))
|
]))
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertJsonCount(1, 'data')
|
->assertJsonCount(1, 'data')
|
||||||
->assertJsonPath('data.0.id', $matching->id)
|
->assertJsonPath('data.0.id', $matching->id)
|
||||||
|
->assertJsonPath('data.0.values.product', 'Cena')
|
||||||
|
->assertJsonPath('data.0.values.type', $dinnerService)
|
||||||
|
->assertJsonPath('data.0.values.date', $date->date->format('d/m'))
|
||||||
->assertJsonPath('scanned_tickets', 1)
|
->assertJsonPath('scanned_tickets', 1)
|
||||||
->assertJsonPath('total_tickets', 1);
|
->assertJsonPath('total_tickets', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_it_exposes_and_filters_merchandise_color_and_size(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
||||||
|
$admin = $this->createAdminAppUser($tenant);
|
||||||
|
$this->grantTicketsMenu($tenant);
|
||||||
|
$this->seed([AttributeSeeder::class, FiestaFutbolInfantilProductSeeder::class]);
|
||||||
|
Sanctum::actingAs($admin);
|
||||||
|
|
||||||
|
$merchandise = CatalogItem::query()
|
||||||
|
->where('tenant_code', $tenant->codigo)
|
||||||
|
->where('slug', 'camiseta')
|
||||||
|
->with([
|
||||||
|
'variants.definitions.itemAttribute.attribute.options',
|
||||||
|
'variants.eventDates',
|
||||||
|
'variants.eventDate',
|
||||||
|
])
|
||||||
|
->firstOrFail();
|
||||||
|
$greenMedium = $merchandise->variants->first(fn (Variant $variant): bool => $variant->selectionValues()->get('color') === 'Verde'
|
||||||
|
&& $variant->selectionValues()->get('talle') === 'M');
|
||||||
|
$whiteMedium = $merchandise->variants->first(fn (Variant $variant): bool => $variant->selectionValues()->get('color') === 'Blanco'
|
||||||
|
&& $variant->selectionValues()->get('talle') === 'M');
|
||||||
|
$this->assertNotNull($greenMedium);
|
||||||
|
$this->assertNotNull($whiteMedium);
|
||||||
|
|
||||||
|
$matching = $this->createTicket($tenant, $admin, [
|
||||||
|
'source_catalog_item_id' => $merchandise->id,
|
||||||
|
'source_variant_id' => $greenMedium->id,
|
||||||
|
]);
|
||||||
|
$this->createTicket($tenant, $admin, [
|
||||||
|
'source_catalog_item_id' => $merchandise->id,
|
||||||
|
'source_variant_id' => $whiteMedium->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/tickets?'.http_build_query([
|
||||||
|
'category' => 'merchandising',
|
||||||
|
'product' => 'camiseta',
|
||||||
|
'type' => 'Verde',
|
||||||
|
'size' => 'M',
|
||||||
|
]))
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonCount(1, 'data')
|
||||||
|
->assertJsonPath('data.0.id', $matching->id)
|
||||||
|
->assertJsonPath('data.0.values.product', 'Camiseta')
|
||||||
|
->assertJsonPath('data.0.values.type', 'Verde')
|
||||||
|
->assertJsonPath('data.0.values.date', '-')
|
||||||
|
->assertJsonPath('data.0.values.size', 'M');
|
||||||
|
}
|
||||||
|
|
||||||
public function test_it_filters_computed_active_and_expired_statuses(): void
|
public function test_it_filters_computed_active_and_expired_statuses(): void
|
||||||
{
|
{
|
||||||
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
||||||
@@ -435,6 +587,22 @@ class AdminAppTicketControllerTest extends TestCase
|
|||||||
return $purchase;
|
return $purchase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function createPurchaseItem(Purchase $purchase, CatalogItem $item, Variant $variant): PurchaseItem
|
||||||
|
{
|
||||||
|
return $purchase->items()->create([
|
||||||
|
'source_catalog_item_id' => $item->id,
|
||||||
|
'source_variant_id' => $variant->id,
|
||||||
|
'nombre' => $item->nombre,
|
||||||
|
'descripcion' => $item->descripcion,
|
||||||
|
'slug' => $item->slug,
|
||||||
|
'item_nombre' => $item->nombre,
|
||||||
|
'variant_attributes' => [],
|
||||||
|
'cantidad' => 1,
|
||||||
|
'precio_unitario' => 0,
|
||||||
|
'total' => 0,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
private function grantTicketsMenu(Tenant $tenant): void
|
private function grantTicketsMenu(Tenant $tenant): void
|
||||||
{
|
{
|
||||||
$menu = Menu::query()->create([
|
$menu = Menu::query()->create([
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ use App\Domains\Ticket\Exceptions\TicketGenerationException;
|
|||||||
use App\Domains\Ticket\Models\ValidityTime;
|
use App\Domains\Ticket\Models\ValidityTime;
|
||||||
use App\Domains\Ticket\Services\TicketGeneratorService;
|
use App\Domains\Ticket\Services\TicketGeneratorService;
|
||||||
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
||||||
|
use Illuminate\Database\QueryException;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
use Illuminate\Support\Facades\Queue;
|
use Illuminate\Support\Facades\Queue;
|
||||||
@@ -246,14 +247,59 @@ class TicketGeneratorServiceTest extends TestCase
|
|||||||
$purchase = $this->createPurchase($item, 1, $variant->id);
|
$purchase = $this->createPurchase($item, 1, $variant->id);
|
||||||
|
|
||||||
$purchase->markAsPaid();
|
$purchase->markAsPaid();
|
||||||
|
$purchaseItem = $purchase->items()->sole();
|
||||||
|
|
||||||
$this->assertDatabaseHas('tickets', [
|
$this->assertDatabaseHas('tickets', [
|
||||||
'source_purchase_id' => $purchase->id,
|
'source_purchase_item_id' => $purchaseItem->id,
|
||||||
'source_catalog_item_id' => $item->id,
|
'source_catalog_item_id' => $item->id,
|
||||||
'source_variant_id' => $variant->id,
|
'source_variant_id' => $variant->id,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_bundle_tickets_reference_the_purchase_item_that_generated_them(): void
|
||||||
|
{
|
||||||
|
$component = $this->createTicketableItem('bundle-component');
|
||||||
|
$bundle = $this->createBundle('purchased-bundle');
|
||||||
|
$bundle->bundleComponents()->create([
|
||||||
|
'component_catalog_item_id' => $component->id,
|
||||||
|
'quantity' => 2,
|
||||||
|
]);
|
||||||
|
$purchase = $this->createPurchase($bundle, 2);
|
||||||
|
$purchaseItem = $purchase->items()->sole();
|
||||||
|
|
||||||
|
$purchase->markAsPaid();
|
||||||
|
|
||||||
|
$this->assertCount(4, $purchaseItem->tickets);
|
||||||
|
$this->assertTrue($purchaseItem->tickets->every(
|
||||||
|
fn ($ticket): bool => $ticket->source_purchase_item_id === $purchaseItem->id
|
||||||
|
&& $ticket->source_catalog_item_id === $component->id
|
||||||
|
));
|
||||||
|
$this->assertCount(4, $purchase->tickets);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_purchase_item_that_generated_tickets_cannot_be_deleted(): void
|
||||||
|
{
|
||||||
|
$item = $this->createTicketableItem('protected-purchase-item');
|
||||||
|
$purchase = $this->createPurchase($item, 1);
|
||||||
|
$purchase->markAsPaid();
|
||||||
|
$purchaseItem = $purchase->items()->sole();
|
||||||
|
|
||||||
|
$this->expectException(QueryException::class);
|
||||||
|
|
||||||
|
$purchaseItem->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_purchase_with_generated_tickets_cannot_be_deleted(): void
|
||||||
|
{
|
||||||
|
$item = $this->createTicketableItem('protected-purchase');
|
||||||
|
$purchase = $this->createPurchase($item, 1);
|
||||||
|
$purchase->markAsPaid();
|
||||||
|
|
||||||
|
$this->expectException(QueryException::class);
|
||||||
|
|
||||||
|
$purchase->delete();
|
||||||
|
}
|
||||||
|
|
||||||
public function test_event_date_and_time_window_are_combined_in_the_same_and_group(): void
|
public function test_event_date_and_time_window_are_combined_in_the_same_and_group(): void
|
||||||
{
|
{
|
||||||
$item = $this->createTicketableItem('scheduled-meal');
|
$item = $this->createTicketableItem('scheduled-meal');
|
||||||
|
|||||||
@@ -8,20 +8,27 @@ use PHPUnit\Framework\TestCase;
|
|||||||
|
|
||||||
class SaleFormServiceTest extends TestCase
|
class SaleFormServiceTest extends TestCase
|
||||||
{
|
{
|
||||||
public function test_it_returns_every_purchase_status_as_a_form_option(): void
|
public function test_it_returns_admin_statuses_with_their_real_statuses(): void
|
||||||
{
|
{
|
||||||
$form = (new SaleFormService)->get();
|
$form = (new SaleFormService)->get();
|
||||||
|
|
||||||
$this->assertSame(Purchase::statuses(), array_column($form['statuses'], 'code'));
|
$this->assertSame(Purchase::adminStatusCodes(), array_column($form['statuses'], 'value'));
|
||||||
$this->assertSame([
|
$this->assertSame([
|
||||||
'Creada',
|
'Por completar datos',
|
||||||
'Esperando pago',
|
'Esperando pago',
|
||||||
'En revisión',
|
'Confirmado',
|
||||||
'Confirmada',
|
'Anulado',
|
||||||
'Cancelada',
|
], array_column($form['statuses'], 'label'));
|
||||||
'Rechazada',
|
$this->assertSame([
|
||||||
'Vencida',
|
[Purchase::STATUS_CREATED],
|
||||||
'Reemplazada',
|
[Purchase::STATUS_PENDING_PAYMENT, Purchase::STATUS_IN_REVIEW],
|
||||||
], array_column($form['statuses'], 'name'));
|
[Purchase::STATUS_PAID],
|
||||||
|
[
|
||||||
|
Purchase::STATUS_CANCELLED,
|
||||||
|
Purchase::STATUS_REJECTED,
|
||||||
|
Purchase::STATUS_EXPIRED,
|
||||||
|
Purchase::STATUS_SUPERSEDED,
|
||||||
|
],
|
||||||
|
], array_column($form['statuses'], 'real_statuses'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
69
tests/Unit/Purchase/PurchaseAdminStatusTest.php
Normal file
69
tests/Unit/Purchase/PurchaseAdminStatusTest.php
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit\Purchase;
|
||||||
|
|
||||||
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class PurchaseAdminStatusTest extends TestCase
|
||||||
|
{
|
||||||
|
#[DataProvider('statusMappings')]
|
||||||
|
public function test_it_maps_real_statuses_to_admin_statuses(
|
||||||
|
string $realStatus,
|
||||||
|
string $adminStatus,
|
||||||
|
string $adminStatusName,
|
||||||
|
): void {
|
||||||
|
$this->assertSame($adminStatus, Purchase::adminStatusFor($realStatus));
|
||||||
|
$this->assertSame($adminStatusName, Purchase::adminStatusNameFor($realStatus));
|
||||||
|
$this->assertContains(
|
||||||
|
$realStatus,
|
||||||
|
Purchase::realStatusesForAdminStatus($adminStatus),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return iterable<string, array{string, string, string}> */
|
||||||
|
public static function statusMappings(): iterable
|
||||||
|
{
|
||||||
|
yield 'created' => [
|
||||||
|
Purchase::STATUS_CREATED,
|
||||||
|
Purchase::ADMIN_STATUS_INCOMPLETE,
|
||||||
|
'Por completar datos',
|
||||||
|
];
|
||||||
|
yield 'pending payment' => [
|
||||||
|
Purchase::STATUS_PENDING_PAYMENT,
|
||||||
|
Purchase::ADMIN_STATUS_AWAITING_PAYMENT,
|
||||||
|
'Esperando pago',
|
||||||
|
];
|
||||||
|
yield 'in review' => [
|
||||||
|
Purchase::STATUS_IN_REVIEW,
|
||||||
|
Purchase::ADMIN_STATUS_AWAITING_PAYMENT,
|
||||||
|
'Esperando pago',
|
||||||
|
];
|
||||||
|
yield 'paid' => [
|
||||||
|
Purchase::STATUS_PAID,
|
||||||
|
Purchase::ADMIN_STATUS_CONFIRMED,
|
||||||
|
'Confirmado',
|
||||||
|
];
|
||||||
|
yield 'cancelled' => [
|
||||||
|
Purchase::STATUS_CANCELLED,
|
||||||
|
Purchase::ADMIN_STATUS_CANCELLED,
|
||||||
|
'Anulado',
|
||||||
|
];
|
||||||
|
yield 'rejected' => [
|
||||||
|
Purchase::STATUS_REJECTED,
|
||||||
|
Purchase::ADMIN_STATUS_CANCELLED,
|
||||||
|
'Anulado',
|
||||||
|
];
|
||||||
|
yield 'expired' => [
|
||||||
|
Purchase::STATUS_EXPIRED,
|
||||||
|
Purchase::ADMIN_STATUS_CANCELLED,
|
||||||
|
'Anulado',
|
||||||
|
];
|
||||||
|
yield 'superseded' => [
|
||||||
|
Purchase::STATUS_SUPERSEDED,
|
||||||
|
Purchase::ADMIN_STATUS_CANCELLED,
|
||||||
|
'Anulado',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace Tests\Unit\Sale;
|
namespace Tests\Unit\Sale;
|
||||||
|
|
||||||
use App\Domains\Logging\Models\ValueChange;
|
use App\Domains\Logging\Models\ValueChange;
|
||||||
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
use App\Domains\Sale\Resources\AdminApp\SaleModificationResource;
|
use App\Domains\Sale\Resources\AdminApp\SaleModificationResource;
|
||||||
use Carbon\CarbonImmutable;
|
use Carbon\CarbonImmutable;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@@ -29,5 +30,7 @@ class SaleModificationResourceTest extends TestCase
|
|||||||
$this->assertSame('2026-08-24T17:53:00+00:00', $data['changed_at']);
|
$this->assertSame('2026-08-24T17:53:00+00:00', $data['changed_at']);
|
||||||
$this->assertSame('2026-08-24', $data['date']);
|
$this->assertSame('2026-08-24', $data['date']);
|
||||||
$this->assertSame('17:53:00', $data['time']);
|
$this->assertSame('17:53:00', $data['time']);
|
||||||
|
$this->assertSame(Purchase::ADMIN_STATUS_CANCELLED, $data['admin_status']);
|
||||||
|
$this->assertSame('Anulado', $data['status_label']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,10 +53,11 @@ class AdminAppTicketExportServiceTest extends TestCase
|
|||||||
$this->assertSame('Tickets', $sheet->getTitle());
|
$this->assertSame('Tickets', $sheet->getTitle());
|
||||||
$this->assertSame('N° de orden', $sheet->getCell('A1')->getValue());
|
$this->assertSame('N° de orden', $sheet->getCell('A1')->getValue());
|
||||||
$this->assertSame('#15', $sheet->getCell('A2')->getValue());
|
$this->assertSame('#15', $sheet->getCell('A2')->getValue());
|
||||||
$this->assertSame('Cena', $sheet->getCell('D2')->getValue());
|
$this->assertSame('Vianda', $sheet->getCell('D2')->getValue());
|
||||||
$this->assertSame(8000.0, $sheet->getCell('E2')->getValue());
|
$this->assertSame('12/10', $sheet->getCell('E2')->getValue());
|
||||||
$this->assertSame('25', $sheet->getCell('G2')->getValue());
|
$this->assertSame(8000.0, $sheet->getCell('G2')->getValue());
|
||||||
$this->assertSame('Usado', $sheet->getCell('H2')->getValue());
|
$this->assertSame('25', $sheet->getCell('I2')->getValue());
|
||||||
|
$this->assertSame('Usado', $sheet->getCell('J2')->getValue());
|
||||||
} finally {
|
} finally {
|
||||||
@unlink($path);
|
@unlink($path);
|
||||||
}
|
}
|
||||||
@@ -93,7 +94,8 @@ class AdminAppTicketExportServiceTest extends TestCase
|
|||||||
$this->assertStringContainsString('Generado el 24/08/2026 13:53', $html);
|
$this->assertStringContainsString('Generado el 24/08/2026 13:53', $html);
|
||||||
$this->assertStringContainsString('25', $html);
|
$this->assertStringContainsString('25', $html);
|
||||||
$this->assertStringNotContainsString('00000000-0000-0000-0000-000000000001', $html);
|
$this->assertStringNotContainsString('00000000-0000-0000-0000-000000000001', $html);
|
||||||
$this->assertStringContainsString('Cena', $html);
|
$this->assertStringContainsString('Almuerzo', $html);
|
||||||
|
$this->assertStringContainsString('Vianda', $html);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function reportService(): AdminAppTicketReportService
|
private function reportService(): AdminAppTicketReportService
|
||||||
@@ -110,8 +112,10 @@ class AdminAppTicketExportServiceTest extends TestCase
|
|||||||
return [
|
return [
|
||||||
'order_number' => 15,
|
'order_number' => 15,
|
||||||
'category' => 'Comida',
|
'category' => 'Comida',
|
||||||
'product' => '12/10',
|
'product' => 'Almuerzo',
|
||||||
'type' => 'Cena',
|
'type' => 'Vianda',
|
||||||
|
'date' => '12/10',
|
||||||
|
'size' => '-',
|
||||||
'amount' => 8000.0,
|
'amount' => 8000.0,
|
||||||
'client' => 'Cliente Test',
|
'client' => 'Cliente Test',
|
||||||
'id' => 25,
|
'id' => 25,
|
||||||
|
|||||||
Reference in New Issue
Block a user