up
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user