Cambios al api revisado en UI
This commit is contained in:
@ -8,12 +8,14 @@ use ProVM\Common\Alias\Model;
|
||||
* @property int $id
|
||||
* @property \DateTime $fecha
|
||||
* @property Fuente $fuente_id
|
||||
* @property string $glosa
|
||||
* @property string $detalle
|
||||
* @property Cuenta $cuenta_id
|
||||
* @property double $valor
|
||||
*/
|
||||
class Entrada extends Model {
|
||||
public static $_table = 'entradas';
|
||||
protected static $fields = ['fecha', 'fuente_id', 'cuenta_id', 'value'];
|
||||
protected static $fields = ['fecha', 'fuente_id', 'glosa', 'detalle', 'cuenta_id', 'valor'];
|
||||
|
||||
protected $fuente;
|
||||
public function fuente() {
|
||||
@ -25,7 +27,7 @@ class Entrada extends Model {
|
||||
protected $cuenta;
|
||||
public function cuenta() {
|
||||
if ($this->cuenta === null) {
|
||||
$this->cuenta = $this->childOf(Cuente::class, [Model::SELF_KEY => 'cuenta_id']);
|
||||
$this->cuenta = $this->childOf(Cuenta::class, [Model::SELF_KEY => 'cuenta_id']);
|
||||
}
|
||||
return $this->cuenta;
|
||||
}
|
||||
@ -35,4 +37,13 @@ class Entrada extends Model {
|
||||
}
|
||||
$this->fecha = $fecha->format('Y-m-d');
|
||||
}
|
||||
|
||||
public function toArray(): array {
|
||||
$arr = parent::toArray();
|
||||
$arr['fuente'] = $this->fuente()->toArray();
|
||||
$arr['cuenta'] = $this->cuenta()->toArray();
|
||||
$arr['fechaFormateada'] = $this->fecha()->format('d-m-Y');
|
||||
$arr['valorFormateado'] = '$' . number_format($this->valor, 0, ',', '.');
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user