commit 6ae625d4fdc11989950ef0678db62fdb52be7c8c Author: ncoronel <ncoronel@quo.ar> Date: Wed Sep 2 09:46:18 2026 -0300 refactor(tickets): enhance search functionality for tickets by client names and formatted amounts commit 098e525d32be9cb6487bc01a3d120aa0f2386a15 Author: ncoronel <ncoronel@quo.ar> Date: Wed Sep 2 09:09:30 2026 -0300 fix(tickets): protect referenced purchase items commit 210db17f2f6a6a4a509297b773a2b5d3e3149a3d Author: ncoronel <ncoronel@quo.ar> Date: Wed Sep 2 08:59:24 2026 -0300 test(tickets): cover purchase item references commit 6a004713c4bad622dfa5e26394458925db1cb5a7 Author: ncoronel <ncoronel@quo.ar> Date: Wed Sep 2 08:59:02 2026 -0300 refactor(tickets): reference purchase items directly
85 lines
2.2 KiB
PHP
85 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Purchase\Models;
|
|
|
|
use App\Domains\Attachable\Models\Attachment;
|
|
use App\Domains\Catalog\Models\CatalogItem;
|
|
use App\Domains\Catalog\Models\Variant;
|
|
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\HasMany;
|
|
|
|
#[Fillable([
|
|
'compra_id',
|
|
'source_catalog_item_id',
|
|
'source_variant_id',
|
|
'image_attachment_id',
|
|
'nombre',
|
|
'descripcion',
|
|
'slug',
|
|
'item_nombre',
|
|
'variant_attributes',
|
|
'cantidad',
|
|
'precio_unitario',
|
|
'discount_total',
|
|
'tax_total',
|
|
'total',
|
|
])]
|
|
class PurchaseItem extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'compra_items';
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'compra_id' => 'integer',
|
|
'source_catalog_item_id' => 'integer',
|
|
'source_variant_id' => 'integer',
|
|
'image_attachment_id' => 'integer',
|
|
'variant_attributes' => 'array',
|
|
'cantidad' => 'integer',
|
|
'precio_unitario' => 'decimal:2',
|
|
'discount_total' => 'decimal:2',
|
|
'tax_total' => 'decimal:2',
|
|
'total' => 'decimal:2',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Purchase, $this>
|
|
*/
|
|
public function purchase(): BelongsTo
|
|
{
|
|
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> */
|
|
public function imageAttachment(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Attachment::class, 'image_attachment_id');
|
|
}
|
|
|
|
/** @return BelongsTo<CatalogItem, $this> */
|
|
public function sourceCatalogItem(): BelongsTo
|
|
{
|
|
return $this->belongsTo(CatalogItem::class, 'source_catalog_item_id')->withTrashed();
|
|
}
|
|
|
|
/** @return BelongsTo<Variant, $this> */
|
|
public function sourceVariant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Variant::class, 'source_variant_id')->withTrashed();
|
|
}
|
|
}
|