Matriz facturacion

This commit is contained in:
Juan Pablo Vial
2024-04-29 18:35:44 -04:00
parent 94d618b2a1
commit 9c024d1ef7
5 changed files with 182 additions and 307 deletions

View File

@ -2,16 +2,15 @@
namespace Incoviba\Controller\API\Ventas;
use DateTimeImmutable;
use Incoviba\Common\Implement\Exception\EmptyRedis;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Controller\API\emptyBody;
use Incoviba\Controller\API\withJson;
use Incoviba\Controller\withRedis;
use Incoviba\Service;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Implement\Exception\{EmptyRedis,EmptyResult};
use Incoviba\Controller\API\{emptyBody,withJson};
use Incoviba\Controller\withRedis;
use Incoviba\Service;
use Incoviba\Common\Ideal;
class Facturacion
class Facturacion extends Ideal\Service
{
use withJson, withRedis, emptyBody;
@ -34,4 +33,31 @@ class Facturacion
}
return $this->withJson($response, $output);
}
public function ventas(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
Service\Venta $ventaService, Service\Proyecto\Terreno $terrenoService, Service\UF $ufService,
Service\IPC $ipcService): ResponseInterface
{
$input = $request->getParsedBody();
$output = [
'input' => $input,
'ventas' => []
];
$ventas = explode(',', $input['ventas']);
foreach ($ventas as $venta_id) {
$redisKey = "ventas:facturacion:venta:{$venta_id}";
try {
$venta = $this->fetchRedis($redisService, $redisKey);
$output['ventas'] []= $venta;
} catch (EmptyRedis) {
try {
$venta = $ventaService->getFacturacionById($venta_id);
$output['ventas'] []= $venta;
$this->saveRedis($redisService, $redisKey, $venta);
} catch (EmptyResult $exception) {
$this->logger->notice($exception);
}
}
}
return $this->withJson($response, $output);
}
}