Facturacion

This commit is contained in:
2023-11-22 19:08:19 -03:00
parent b4742a501e
commit 9ab0515954
45 changed files with 1846 additions and 71 deletions

View File

@ -0,0 +1,36 @@
<?php
namespace Incoviba\Controller\API\Ventas;
use DateTimeImmutable;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Service;
use Incoviba\Controller\API\withJson;
use Incoviba\Controller\API\withRedis;
use Incoviba\Controller\API\emptyBody;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Common\Implement\Exception\EmptyRedis;
class Facturacion
{
use withJson, withRedis, emptyBody;
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService, Service\Venta $ventaService, int $proyecto_id): ResponseInterface
{
$output = [
'proyecto_id' => $proyecto_id,
'ventas' => []
];
$today = new DateTimeImmutable();
$redisKey = "ventas_facturacion-proyecto-{$proyecto_id}-{$today->format('Y-m-d')}";
try {
$output['ventas'] = $this->fetchRedis($redisService, $redisKey);
} catch (EmptyRedis) {
try {
$output['ventas'] = $ventaService->getActivaByProyecto($proyecto_id);
$this->saveRedis($redisService, $redisKey, $output['ventas']);
} catch (EmptyResult) {}
}
return $this->withJson($response, $output);
}
}