Files
pos_heidiver/app/Models/Caja.php
T
2026-01-06 15:35:59 -05:00

50 lines
1.1 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Caja extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'monto_inicial',
'monto_final',
'fecha_apertura',
'fecha_cierre',
'estado',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'id' => 'integer',
'monto_inicial' => 'decimal:2',
'monto_final' => 'decimal:2',
'fecha_apertura' => 'datetime',
'fecha_cierre' => 'datetime',
];
public function movimientoscaja()
{
return $this->hasMany(MovimientoCaja::class);
}
// Método para calcular el monto final
public function calcularMontoFinal()
{
$ingresos = $this->movimientoscaja()->where('tipo', 'Ingreso')->sum('monto');
$egresos = $this->movimientoscaja()->where('tipo', 'Egreso')->sum('monto');
return $this->monto_inicial + $ingresos - $egresos;
}
}