feat: add ticket fields to Product and ProductVariant models, requests, and resources

This commit is contained in:
ncoronel 2026-07-14 15:19:53 -03:00
parent 0e9f7faaf1
commit cababe1a43
8 changed files with 87 additions and 1 deletions

View File

@ -18,6 +18,9 @@ use Illuminate\Database\Eloquent\Casts\Attribute;
'stock_reservado', 'stock_reservado',
'stock', 'stock',
'is_placeholder', 'is_placeholder',
'has_tickets',
'minimum_use_date',
'maximum_use_date',
])] ])]
class ProductVariant extends Model class ProductVariant extends Model
{ {
@ -126,6 +129,9 @@ class ProductVariant extends Model
'stock_real' => 'integer', 'stock_real' => 'integer',
'stock_reservado' => 'integer', 'stock_reservado' => 'integer',
'is_placeholder' => 'boolean', 'is_placeholder' => 'boolean',
'has_tickets' => 'boolean',
'minimum_use_date' => 'datetime',
'maximum_use_date' => 'datetime',
]; ];
} }

View File

@ -32,6 +32,9 @@ class StoreProductVariantRequest extends FormRequest
'definitions.*.value' => ['nullable', 'string'], 'definitions.*.value' => ['nullable', 'string'],
'images' => ['sometimes', 'nullable', 'array'], 'images' => ['sometimes', 'nullable', 'array'],
'images.*' => ['required', new ImageOrBase64Rule()], 'images.*' => ['required', new ImageOrBase64Rule()],
'has_tickets' => ['boolean'],
'minimum_use_date' => ['nullable', 'date'],
'maximum_use_date' => ['nullable', 'date', 'after_or_equal:minimum_use_date'],
]; ];
} }
} }

View File

@ -32,6 +32,9 @@ class UpdateProductVariantRequest extends FormRequest
'definitions.*.value' => ['nullable', 'string'], 'definitions.*.value' => ['nullable', 'string'],
'images' => ['sometimes', 'nullable', 'array'], 'images' => ['sometimes', 'nullable', 'array'],
'images.*' => ['required', new ImageOrBase64Rule()], 'images.*' => ['required', new ImageOrBase64Rule()],
'has_tickets' => ['boolean'],
'minimum_use_date' => ['nullable', 'date'],
'maximum_use_date' => ['nullable', 'date', 'after_or_equal:minimum_use_date'],
]; ];
} }
} }

View File

@ -26,6 +26,7 @@ class ProductResource extends JsonResource
'precio' => $this->precio, 'precio' => $this->precio,
'category' => $this->whenLoaded('category', fn () => $this->category?->nombre), 'category' => $this->whenLoaded('category', fn () => $this->category?->nombre),
'brand' => $this->whenLoaded('brand', fn () => $this->brand?->nombre), 'brand' => $this->whenLoaded('brand', fn () => $this->brand?->nombre),
'images' => $this->whenLoaded('attachments', fn () => $this->attachments 'images' => $this->whenLoaded('attachments', fn () => $this->attachments
->map(fn ($attachment) => $attachment->getTemporaryUrl(1440)) ->map(fn ($attachment) => $attachment->getTemporaryUrl(1440))
->values() ->values()

View File

@ -19,6 +19,9 @@ class ProductVariantResource extends JsonResource
return [ return [
'id' => $this->id, 'id' => $this->id,
'cantidad_maxima' => $this->stock_tecnico, 'cantidad_maxima' => $this->stock_tecnico,
'has_tickets' => $this->has_tickets,
'minimum_use_date' => $this->minimum_use_date,
'maximum_use_date' => $this->maximum_use_date,
'product' => ProductResource::make($this->whenLoaded('product')), 'product' => ProductResource::make($this->whenLoaded('product')),
'definitions' => $this->whenLoaded( 'definitions' => $this->whenLoaded(
'definitions', 'definitions',

View File

@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('productos', function (Blueprint $table) {
$table->boolean('has_tickets')->default(false);
$table->dateTime('minimum_use_date')->nullable();
$table->dateTime('maximum_use_date')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('productos', function (Blueprint $table) {
$table->dropColumn(['has_tickets', 'minimum_use_date', 'maximum_use_date']);
});
}
};

View File

@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('productos', function (Blueprint $table) {
$table->dropColumn(['has_tickets', 'minimum_use_date', 'maximum_use_date']);
});
Schema::table('productos_variantes', function (Blueprint $table) {
$table->boolean('has_tickets')->default(false);
$table->dateTime('minimum_use_date')->nullable();
$table->dateTime('maximum_use_date')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('productos', function (Blueprint $table) {
$table->boolean('has_tickets')->default(false);
$table->dateTime('minimum_use_date')->nullable();
$table->dateTime('maximum_use_date')->nullable();
});
Schema::table('productos_variantes', function (Blueprint $table) {
$table->dropColumn(['has_tickets', 'minimum_use_date', 'maximum_use_date']);
});
}
};

View File

@ -11,4 +11,4 @@ require __DIR__.'/../app/Domains/Purchase/routes/api.php';
require __DIR__.'/../app/Domains/Tenant/routes/api.php'; require __DIR__.'/../app/Domains/Tenant/routes/api.php';
require __DIR__.'/../app/Domains/Integration/routes/api.php'; require __DIR__.'/../app/Domains/Integration/routes/api.php';
require __DIR__.'/../app/Domains/Menu/routes/api.php'; require __DIR__.'/../app/Domains/Menu/routes/api.php';
require __DIR__.'/../app/Domains/Product/routes/api.php';