Estado cuenta
This commit is contained in:
@ -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(), [
|
||||
|
22
app/src/Model/Inmobiliaria/Cuenta/Estado.php
Normal file
22
app/src/Model/Inmobiliaria/Cuenta/Estado.php
Normal 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
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user