Estado cuenta
This commit is contained in:
56
app/src/Service/Inmobiliaria/Cuenta.php
Normal file
56
app/src/Service/Inmobiliaria/Cuenta.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Inmobiliaria;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal\Service;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Cuenta extends Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger, protected Repository\Inmobiliaria\Cuenta $cuentaRepository,
|
||||
protected Repository\Inmobiliaria\Cuenta\Estado $estadoRepository)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
public function getAllActive(): array
|
||||
{
|
||||
$cuentas = array_map([$this, 'process'], $this->cuentaRepository->fetchAll());
|
||||
return array_values(array_filter($cuentas, function(Model\Inmobiliaria\Cuenta $cuenta) {
|
||||
return $cuenta->currentEstado()->active;
|
||||
}));
|
||||
}
|
||||
public function getAllActiveByInmobiliaria(int $inmobiliaria_rut): array
|
||||
{
|
||||
$cuentas = array_map([$this, 'process'], $this->cuentaRepository->fetchByInmobiliaria($inmobiliaria_rut));
|
||||
return array_values(array_filter($cuentas, function(Model\Inmobiliaria\Cuenta $cuenta) {
|
||||
return $cuenta->currentEstado()->active;
|
||||
}));
|
||||
}
|
||||
public function add(array $data): Model\Inmobiliaria\Cuenta
|
||||
{
|
||||
$cuenta = $this->cuentaRepository->create($data);
|
||||
$cuenta = $this->cuentaRepository->save($cuenta);
|
||||
$dataEstado = [
|
||||
'cuenta_id' => $cuenta->id,
|
||||
'fecha' => new DateTimeImmutable(),
|
||||
'active' => true
|
||||
];
|
||||
$estado = $this->estadoRepository->create($dataEstado);
|
||||
$this->estadoRepository->save($estado);
|
||||
return $this->process($cuenta);
|
||||
}
|
||||
|
||||
protected function process(Model\Inmobiliaria\Cuenta $cuenta): Model\Inmobiliaria\Cuenta
|
||||
{
|
||||
$cuenta->addFactory('estados', (new Implement\Repository\Factory())
|
||||
->setCallable(function($cuenta_id) {
|
||||
return $this->estadoRepository->fetchByCuenta($cuenta_id);
|
||||
})
|
||||
->setArgs(['cuenta_id' => $cuenta->id]));
|
||||
return $cuenta;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user