79 lines
1.7 KiB
PHP
79 lines
1.7 KiB
PHP
<?php namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Returns extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'sale_id',
|
|
'user_id',
|
|
'cash_register_id',
|
|
'return_number',
|
|
'subtotal',
|
|
'tax',
|
|
'total',
|
|
'discount_refund',
|
|
'refund_method',
|
|
'reason',
|
|
'notes'
|
|
];
|
|
|
|
protected $casts = [
|
|
'subtotal' => 'decimal:2',
|
|
'tax' => 'decimal:2',
|
|
'total' => 'decimal:2',
|
|
'discount_refund' => 'decimal:2',
|
|
'created_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* Relación con la venta original
|
|
*/
|
|
public function sale()
|
|
{
|
|
return $this->belongsTo(Sale::class);
|
|
}
|
|
|
|
/**
|
|
* Relación con usuario que procesó la devolución
|
|
*/
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
/**
|
|
* Relación con caja registradora
|
|
*/
|
|
public function cashRegister()
|
|
{
|
|
return $this->belongsTo(CashRegister::class);
|
|
}
|
|
|
|
/**
|
|
* Detalles de la devolución
|
|
*/
|
|
public function details()
|
|
{
|
|
return $this->hasMany(ReturnDetail::class, 'return_id');
|
|
}
|
|
|
|
/**
|
|
* Obtener texto descriptivo de la razón
|
|
*/
|
|
public function getReasonTextAttribute(): string
|
|
{
|
|
return match($this->reason) {
|
|
'defective' => 'Producto defectuoso',
|
|
'wrong_product' => 'Producto incorrecto',
|
|
'change_of_mind' => 'Cambio de opinión',
|
|
'damaged' => 'Producto dañado',
|
|
'other' => 'Otra razón',
|
|
default => 'No especificado',
|
|
};
|
|
}
|
|
}
|