75 lines
3.2 KiB
PHP
75 lines
3.2 KiB
PHP
<?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;
|
|
use Incoviba\Common\Implement\Exception\{EmptyResult, EmptyRedis};
|
|
use Incoviba\Model;
|
|
use Incoviba\Repository;
|
|
use Incoviba\Service;
|
|
|
|
class Contabilidad extends Controller
|
|
{
|
|
use withRedis;
|
|
|
|
public function diaria(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
|
Service\Redis $redisService,
|
|
Repository\Inmobiliaria $inmobiliariaRepository): ResponseInterface
|
|
{
|
|
$redisKey = 'inmobiliarias';
|
|
$inmobiliarias = [];
|
|
try {
|
|
$inmobiliarias = $this->fetchRedis($redisService, $redisKey);
|
|
} catch (EmptyRedis) {
|
|
try {
|
|
$inmobiliarias = $inmobiliariaRepository->fetchAll();
|
|
$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->fetchAll();
|
|
$this->saveRedis($redisService, $redisKey, $inmobiliarias, 30 * 24 * 60 * 60);
|
|
} catch (EmptyResult) {}
|
|
}
|
|
$depositos = [];
|
|
try {
|
|
$depositos = $dapRepository->fetchAll();
|
|
} catch (EmptyResult) {}
|
|
$fecha = new DateTimeImmutable('today');
|
|
$activos = array_filter($depositos, function(Model\Deposito $deposito) use ($fecha) {
|
|
return $deposito->termino >= $fecha;
|
|
});
|
|
$mes = $fecha->sub(new DateInterval('P1M'));
|
|
$vencidos = array_filter($depositos, function(Model\Deposito $deposito) use ($fecha, $mes) {
|
|
return $deposito->termino < $fecha and $deposito->termino >= $mes;
|
|
});
|
|
return $view->render($response, 'contabilidad.depositos', compact('inmobiliarias', 'activos', 'vencidos'));
|
|
}
|
|
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);
|
|
$filename = "Informe de Tesorería {$fecha->format('d.m.Y')}";
|
|
return $view->render($response, 'contabilidad.informes.tesoreria', compact('fecha', 'anterior', 'informes', 'filename'));
|
|
}
|
|
}
|