- Added ValidityTime model and migration to manage ticket validity periods. - Updated TicketGeneratorService to resolve and assign validity times to tickets. - Refactored ticket generation logic to remove legacy date fields and use validity time. - Introduced timezone support for tenants to handle service dates correctly. - Updated migrations to remove deprecated columns and add foreign keys for validity times. - Modified seeders and tests to accommodate new validity time structure. - Enhanced tests to validate ticket generation and validity time behavior.
96 lines
2.4 KiB
PHP
96 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Catalog\Models;
|
|
|
|
use App\Domains\Attachable\Models\Attachment;
|
|
use App\Domains\Event\Models\EventDate;
|
|
use App\Domains\Ticket\Models\Ticket;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
#[Fillable([
|
|
'catalog_item_id',
|
|
'event_date_id',
|
|
'inventory_id',
|
|
])]
|
|
class Variant extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
public $timestamps = false;
|
|
|
|
protected $table = 'variantes';
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'catalog_item_id' => 'integer',
|
|
'event_date_id' => 'integer',
|
|
'inventory_id' => 'integer',
|
|
];
|
|
}
|
|
|
|
/** @return BelongsTo<CatalogItem, $this> */
|
|
public function catalogItem(): BelongsTo
|
|
{
|
|
return $this->belongsTo(CatalogItem::class);
|
|
}
|
|
|
|
/** @return BelongsTo<EventDate, $this> */
|
|
public function eventDate(): BelongsTo
|
|
{
|
|
return $this->belongsTo(EventDate::class);
|
|
}
|
|
|
|
/** @return HasMany<Ticket, $this> */
|
|
public function sourceTickets(): HasMany
|
|
{
|
|
return $this->hasMany(Ticket::class, 'source_variant_id');
|
|
}
|
|
|
|
/** @return BelongsTo<Inventory, $this> */
|
|
public function inventory(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Inventory::class);
|
|
}
|
|
|
|
/** @return HasMany<VariantDefinition, $this> */
|
|
public function definitions(): HasMany
|
|
{
|
|
return $this->hasMany(VariantDefinition::class);
|
|
}
|
|
|
|
/** @return BelongsToMany<Attachment, $this> */
|
|
public function attachments(): BelongsToMany
|
|
{
|
|
$relation = $this->belongsToMany(
|
|
Attachment::class,
|
|
'catalog_items_attachments',
|
|
'variant_id',
|
|
'attachment_id'
|
|
)
|
|
->withPivot('orden')
|
|
->orderByPivot('orden');
|
|
|
|
if ($this->catalog_item_id !== null) {
|
|
$relation->withPivotValue('catalog_item_id', $this->catalog_item_id);
|
|
}
|
|
|
|
return $relation;
|
|
}
|
|
|
|
public function getPrice(): float
|
|
{
|
|
return $this->catalogItem->getPrice();
|
|
}
|
|
|
|
public function getName(): string
|
|
{
|
|
return $this->catalogItem->nombre;
|
|
}
|
|
}
|