Agregando calculo de efectivo
This commit is contained in:
@@ -12,17 +12,30 @@ class Efectivo extends Model
|
||||
|
||||
protected $table = 'efectivos';
|
||||
|
||||
public function getTotal(): Attribute {
|
||||
protected $fillable = [
|
||||
'veinte_mil',
|
||||
'diez_mil',
|
||||
'cinco_mil',
|
||||
'dos_mil',
|
||||
'mil',
|
||||
'quinientos',
|
||||
'cien',
|
||||
'cincuenta',
|
||||
'diez',
|
||||
];
|
||||
|
||||
public function total(): Attribute
|
||||
{
|
||||
return Attribute::get(function () {
|
||||
return $this->veinte_mil
|
||||
+ $this->diez_mil
|
||||
+ $this->cinco_mil
|
||||
+ $this->dos_mil
|
||||
+ $this->mil
|
||||
+ $this->quinientos
|
||||
+ $this->cien
|
||||
+ $this->cincuenta
|
||||
+ $this->diez;
|
||||
return $this->veinte_mil
|
||||
+ $this->diez_mil
|
||||
+ $this->cinco_mil
|
||||
+ $this->dos_mil
|
||||
+ $this->mil
|
||||
+ $this->quinientos
|
||||
+ $this->cien
|
||||
+ $this->cincuenta
|
||||
+ $this->diez;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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