Facturacion
This commit is contained in:
36
app/src/Controller/API/Ventas/Facturacion.php
Normal file
36
app/src/Controller/API/Ventas/Facturacion.php
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user