Simplificacion a contabilidad clasica

This commit is contained in:
2021-07-30 16:38:09 -04:00
parent 510b5aa46d
commit 69b823750a
18 changed files with 194 additions and 468 deletions

View File

@ -18,4 +18,24 @@ class Categoria extends Model {
}
return $this->cuentas;
}
protected $saldo;
public function saldo() {
if ($this->saldo === null) {
$this->saldo = 0;
if ($this->cuentas() !== null) {
$this->saldo = array_reduce($this->cuentas(), function($sum, $item) {
return $sum + $item->saldo();
});
}
}
return $this->saldo;
}
public function toArray(): array {
$arr = parent::toArray();
$arr['saldo'] = $this->saldo();
$arr['saldoFormateado'] = '$' . number_format($this->saldo(), 0, ',', '.');
return $arr;
}
}