Agregando calculo de efectivo
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
@@ -19,24 +20,46 @@ class Turno extends Model
|
||||
'fecha' => 'date',
|
||||
];
|
||||
|
||||
public function ingresos(): HasMany
|
||||
{
|
||||
return $this->hasMany(Ingreso::class, 'turno_id');
|
||||
}
|
||||
public function egresos(): HasMany
|
||||
{
|
||||
return $this->hasMany(Egreso::class, 'turno_id');
|
||||
}
|
||||
public function documentos(): HasMany
|
||||
{
|
||||
return $this->hasMany(Documento::class, 'turno_id');
|
||||
}
|
||||
public function efectivo(): HasOne
|
||||
{
|
||||
return $this->hasOne(Efectivo::class, 'turno_id');
|
||||
}
|
||||
public function calculosFondo(): HasMany
|
||||
{
|
||||
return $this->hasMany(CalculoFondo::class, 'turno_id');
|
||||
}
|
||||
|
||||
public function rendido(): Attribute
|
||||
{
|
||||
return Attribute::get(function () {
|
||||
$documentos = $this->documentos()->sum('valor');
|
||||
$egresos = $this->egresos()->sum('valor');
|
||||
$efectivo = $this->efectivo()->first()?->total ?? 0;
|
||||
|
||||
return $documentos + $efectivo + $egresos;
|
||||
});
|
||||
}
|
||||
|
||||
public function documentos(): HasMany
|
||||
{
|
||||
return $this->hasMany(Documento::class, 'turno_id');
|
||||
}
|
||||
|
||||
public function egresos(): HasMany
|
||||
{
|
||||
return $this->hasMany(Egreso::class, 'turno_id');
|
||||
}
|
||||
|
||||
public function efectivo(): HasOne
|
||||
{
|
||||
return $this->hasOne(Efectivo::class, 'turno_id');
|
||||
}
|
||||
|
||||
public function arqueo(): Attribute
|
||||
{
|
||||
return Attribute::get(function () {
|
||||
return $this->rendido - $this->ingresos()->sum('total');
|
||||
});
|
||||
}
|
||||
|
||||
public function ingresos(): HasMany
|
||||
{
|
||||
return $this->hasMany(Ingreso::class, 'turno_id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user