Informe Tesoreria

This commit is contained in:
Juan Pablo Vial
2024-02-13 01:16:17 -03:00
parent 19333bc338
commit e44ab30665
23 changed files with 896 additions and 40 deletions

View File

@ -1,6 +1,7 @@
<?php
namespace Incoviba\Controller\API\Contabilidad;
use DateTimeImmutable;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Incoviba\Common\Ideal;
@ -12,24 +13,56 @@ class DAPs extends Ideal\Controller
{
use withJson;
public function inmobiliaria(ServerRequestInterface $request, ResponseInterface $response,
Repository\Inmobiliaria $inmobiliariaRepository,
Repository\Banco $bancoRepository,
public function inmobiliaria(ServerRequestInterface $request, ResponseInterface $response,
Repository\Inmobiliaria $inmobiliariaRepository,
Repository\Banco $bancoRepository,
Repository\Inmobiliaria\Cuenta $cuentaRepository,
Repository\DAP $dapRepository,
int $inmobiliaria_rut): ResponseInterface
Repository\Deposito $dapRepository,
int $inmobiliaria_rut): ResponseInterface
{
$output = [
'inmobiliaria_rut' => $inmobiliaria_rut,
'daps' => []
'depositos' => []
];
try {
$inmobiliaria = $inmobiliariaRepository->fetchById($inmobiliaria_rut);
$cuentas = $cuentaRepository->fetchByInmobiliaria($inmobiliaria->rut);
foreach ($cuentas as $cuenta) {
$daps = $dapRepository->fetchByCuenta($cuenta->id);
$output['depositos'] = $dapRepository->fetchByCuenta($cuenta->id);
}
} catch (Implement\Exception\EmptyResult) {}
return $this->withJson($response, $output);
}
}
public function add(ServerRequestInterface $request, ResponseInterface $response,
Repository\Inmobiliaria $inmobiliariaRepository, Repository\Banco $bancoRepository,
Repository\Inmobiliaria\Cuenta $cuentaRepository,
Repository\Deposito $dapRepository): ResponseInterface
{
$body = $request->getParsedBody();
$output = [
'input' => $body,
'status' => false
];
try {
$inmobiliaria = $inmobiliariaRepository->fetchById($body['inmobiliaria_rut']);
$banco = $bancoRepository->fetchById($body['banco_id']);
$cuenta = $cuentaRepository->fetchByInmobiliariaAndBanco($inmobiliaria->rut, $banco->id);
$data = [
'id' => $body['id'],
'cuenta_id' => $cuenta->id,
'capital' => $body['capital'],
'futuro' => $body['futuro'],
'inicio' => (new DateTimeImmutable($body['inicio']))->format('Y-m-d'),
'termino' => (new DateTimeImmutable($body['termino']))->format('Y-m-d')
];
try {
$dapRepository->fetchById($body['id']);
} catch (Implement\Exception\EmptyResult) {
$dap = $dapRepository->create($data);
$dapRepository->save($dap);
}
$output['status'] = true;
} catch (Implement\Exception\EmptyResult) {}
return $this->withJson($response, $output);
}
}

View File

@ -1,6 +1,9 @@
<?php
namespace Incoviba\Controller;
use DateTimeImmutable;
use DateInterval;
use Incoviba\Common\Ideal\Controller;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Alias\View;
@ -8,7 +11,7 @@ use Incoviba\Common\Implement\Exception\{EmptyResult, EmptyRedis};
use Incoviba\Repository;
use Incoviba\Service;
class Contabilidad
class Contabilidad extends Controller
{
use withRedis;
@ -22,10 +25,40 @@ class Contabilidad
$inmobiliarias = $this->fetchRedis($redisService, $redisKey);
} catch (EmptyRedis) {
try {
$inmobiliarias = $inmobiliariaRepository->fetchAll();
$inmobiliarias = $inmobiliariaRepository->fetchAllActive();
$this->saveRedis($redisService, $redisKey, $inmobiliarias, 30 * 24 * 60 * 60);
} catch (EmptyResult) {}
}
return $view->render($response, 'contabilidad.cartolas.diaria', compact('inmobiliarias'));
}
public function depositos(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Redis $redisService,
Repository\Inmobiliaria $inmobiliariaRepository,
Repository\Deposito $dapRepository): ResponseInterface
{
$redisKey = 'inmobiliarias';
$inmobiliarias = [];
try {
$inmobiliarias = $this->fetchRedis($redisService, $redisKey);
} catch (EmptyRedis) {
try {
$inmobiliarias = $inmobiliariaRepository->fetchAllActive();
$this->saveRedis($redisService, $redisKey, $inmobiliarias, 30 * 24 * 60 * 60);
} catch (EmptyResult) {}
}
$depositos = [];
try {
$depositos = $dapRepository->fetchAll();
} catch (EmptyResult) {}
return $view->render($response, 'contabilidad.depositos', compact('inmobiliarias', 'depositos'));
}
public function tesoreria(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Contabilidad\Informe\Tesoreria $contabilidadService,
string $fecha = 'today'): ResponseInterface
{
$fecha = new DateTimeImmutable($fecha);
$anterior = $contabilidadService->getAnterior($fecha);
$informes = $contabilidadService->build($fecha);
return $view->render($response, 'contabilidad.informes.tesoreria', compact('fecha', 'anterior', 'informes'));
}
}