Estado cuenta
This commit is contained in:
@ -4,7 +4,6 @@ namespace Incoviba\Service\Contabilidad\Informe;
|
||||
use DateTimeInterface;
|
||||
use DateInterval;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use PhpOffice\PhpSpreadsheet;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
@ -13,14 +12,14 @@ use Incoviba\Service;
|
||||
|
||||
class Tesoreria extends Ideal\Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger,
|
||||
protected Repository\Inmobiliaria $inmobiliariaRepository,
|
||||
protected Repository\Inmobiliaria\Cuenta $cuentaRepository,
|
||||
protected Repository\Deposito $depositoRepository,
|
||||
protected Repository\Cartola $cartolaRepository,
|
||||
protected Repository\Movimiento $movimientoRepository,
|
||||
public function __construct(LoggerInterface $logger,
|
||||
protected Repository\Inmobiliaria $inmobiliariaRepository,
|
||||
protected Service\Inmobiliaria\Cuenta $cuentaService,
|
||||
protected Repository\Deposito $depositoRepository,
|
||||
protected Repository\Cartola $cartolaRepository,
|
||||
protected Repository\Movimiento $movimientoRepository,
|
||||
protected Service\Contabilidad\Informe\Tesoreria\Excel $excelService,
|
||||
protected Service\Contabilidad\Informe\Tesoreria\PDF $pdfService)
|
||||
protected Service\Contabilidad\Informe\Tesoreria\PDF $pdfService)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
|
||||
@ -170,7 +169,7 @@ class Tesoreria extends Ideal\Service
|
||||
};
|
||||
$dataInmobiliaria->inmobiliaria = $inmobiliaria;
|
||||
try {
|
||||
$cuentas = $this->cuentaRepository->fetchByInmobiliaria($inmobiliaria->rut);
|
||||
$cuentas = $this->cuentaService->getAllActiveByInmobiliaria($inmobiliaria->rut);
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return $dataInmobiliaria;
|
||||
}
|
||||
|
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