pdv.backend/app/Models/SaleDetail.php
Juan Felipe Zapata Moreno 810aff1b0e WIP: Serials
2026-01-16 17:37:39 -06:00

55 lines
1.0 KiB
PHP

<?php namespace App\Models;
/**
* @copyright (c) 2025 Notsoweb Software (https://notsoweb.com) - All Rights Reserved
*/
use Illuminate\Database\Eloquent\Model;
/**
* Descripción
*
* @author Moisés Cortés C. <moises.cortes@notsoweb.com>
*
* @version 1.0.0
*/
class SaleDetail extends Model
{
protected $fillable = [
'sale_id',
'inventory_id',
'product_name',
'quantity',
'unit_price',
'subtotal',
];
protected $casts = [
'unit_price' => 'decimal:2',
'subtotal' => 'decimal:2',
];
public function sale()
{
return $this->belongsTo(Sale::class);
}
public function inventory()
{
return $this->belongsTo(Inventory::class);
}
public function serials()
{
return $this->hasMany(InventorySerial::class);
}
/**
* Obtener números de serie vendidos
*/
public function getSerialNumbersAttribute(): array
{
return $this->serials()->pluck('serial_number')->toArray();
}
}