Estado cuenta

This commit is contained in:
Juan Pablo Vial
2024-03-21 23:10:18 -03:00
parent 529f9e32a1
commit 4b3397dd63
5 changed files with 173 additions and 9 deletions

View File

@ -2,6 +2,7 @@
namespace Incoviba\Model\Inmobiliaria;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Model;
class Cuenta extends Ideal\Model
@ -10,6 +11,30 @@ class Cuenta extends Ideal\Model
public Model\Banco $banco;
public string $cuenta;
protected array $estados;
public function getEstados(): array
{
if (!isset($this->estados)) {
$this->estados = $this->runFactory('estados');
}
return $this->estados;
}
protected Model\Inmobiliaria\Cuenta\Estado $currentEstado;
public function currentEstado(): Model\Inmobiliaria\Cuenta\Estado
{
if (!isset($this->currentEstado)) {
$estados = $this->getEstados();
if (count($estados) === 0) {
throw new EmptyResult('Current Estado Cuenta');
}
usort($estados, function(Model\Inmobiliaria\Cuenta\Estado $a, Model\Inmobiliaria\Cuenta\Estado $b) {
return $a->id - $b->id;
});
$this->currentEstado = end($estados);
}
return $this->currentEstado;
}
public function jsonSerialize(): mixed
{
return array_merge(parent::jsonSerialize(), [

View File

@ -0,0 +1,22 @@
<?php
namespace Incoviba\Model\Inmobiliaria\Cuenta;
use DateTimeInterface;
use Incoviba\Common\Ideal;
use Incoviba\Model;
class Estado extends Ideal\Model
{
public Model\Inmobiliaria\Cuenta $cuenta;
public DateTimeInterface $fecha;
public bool $active;
public function jsonSerialize(): mixed
{
return array_merge(parent::jsonSerialize(), [
'cuenta_id' => $this->cuenta->id,
'fecha' => $this->fecha->format('Y-m-d'),
'active' => $this->active
]);
}
}