Cambios al api revisado en UI

This commit is contained in:
2021-07-29 22:05:38 -04:00
parent e338e39e75
commit 4374392af1
5 changed files with 59 additions and 2 deletions

View File

@ -26,6 +26,18 @@ class Fuente extends Model {
}
return $this->banco;
}
protected $saldo;
public function saldo() {
if ($this->saldo === null) {
$this->saldo = 0;
if ($this->entradas() !== null) {
$this->saldo = array_reduce($this->entradas(), function($sum, $item) {
return $sum + $item->valor;
});
}
}
return $this->saldo;
}
protected $entradas;
public function entradas() {
@ -39,6 +51,8 @@ class Fuente extends Model {
$arr = parent::toArray();
$arr['tipo'] = $this->tipo()->toArray();
$arr['banco'] = $this->banco()->toArray();
$arr['saldo'] = $this->saldo();
$arr['saldoFormateado'] = '$' . number_format($this->saldo(), 0, ',', '.');
return $arr;
}
}