This commit is contained in:
2023-11-23 00:53:49 -03:00
parent 9ab0515954
commit bf03e85975
32 changed files with 599 additions and 314 deletions

View File

@ -1,55 +1,74 @@
<?php
namespace Incoviba\Controller\API\Ventas;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Implement\Exception\EmptyRedis;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Controller\API\withJson;
use Incoviba\Controller\withRedis;
use Incoviba\Repository;
use Incoviba\Service;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
class Cierres
{
use withJson;
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Cierre $service): ResponseInterface
use withJson, withRedis;
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
Service\Venta\Cierre $service): ResponseInterface
{
$body = $request->getBody();
$json = json_decode($body->getContents());
$proyecto_id = $json->proyecto_id;
$output = ['total' => 0];
$output = ['total' => 0, 'cierres' => []];
$redisKey = "cierres:proyecto:{$proyecto_id}";
try {
$cierres = $service->getByProyecto($proyecto_id);
$output['cierres'] = $cierres;
$output['total'] = count($cierres);
} catch (EmptyResult) {}
$output['cierres'] = $this->fetchRedis($redisService, $redisKey);
$output['total'] = count($output['cierres']);
} catch (EmptyRedis) {
try {
$cierres = $service->getByProyecto($proyecto_id);
$output['cierres'] = $cierres;
$this->saveRedis($redisService, $redisKey, $output['cierres']);
$output['total'] = count($cierres);
} catch (EmptyResult) {}
}
return $this->withJson($response, $output);
}
public function vigentes(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cierre $cierreRepository): ResponseInterface
public function vigentes(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
Repository\Venta\Cierre $cierreRepository): ResponseInterface
{
$cierres = $cierreRepository->fetchDatosVigentes();
$output = [];
$estados = [
'revisado' => 'pendientes',
'rechazado' => 'rechazados',
'aprobado' => 'pendientes',
'vendido' => 'promesados',
'abandonado' => 'rechazados',
'promesado' => 'promesados',
'resciliado' => 'rechazados'
];
foreach ($cierres as $row) {
if (!isset($output[$row['Proyecto']])) {
$output[$row['Proyecto']] = [
'promesados' => 0,
'pendientes' => 0,
'rechazados' => 0,
'total' => 0
$output = ['cierres' => []];
$redisKey = "cierres:vigentes";
try {
$output['cierres'] = $this->fetchRedis($redisService, $redisKey);
} catch (EmptyRedis) {
try {
$cierres = $cierreRepository->fetchDatosVigentes();
$estados = [
'revisado' => 'pendientes',
'rechazado' => 'rechazados',
'aprobado' => 'pendientes',
'vendido' => 'promesados',
'abandonado' => 'rechazados',
'promesado' => 'promesados',
'resciliado' => 'rechazados'
];
}
$estado = $estados[$row['Estado']];
$output[$row['Proyecto']][$estado] += $row['Cantidad'];
$output[$row['Proyecto']]['total'] += $row['Cantidad'];
foreach ($cierres as $row) {
if (!isset($output['cierres'][$row['Proyecto']])) {
$output['cierres'][$row['Proyecto']] = [
'promesados' => 0,
'pendientes' => 0,
'rechazados' => 0,
'total' => 0
];
}
$estado = $estados[$row['Estado']];
$output['cierres'][$row['Proyecto']][$estado] += $row['Cantidad'];
$output['cierres'][$row['Proyecto']]['total'] += $row['Cantidad'];
}
$this->saveRedis($redisService, $redisKey, $output['cierres']);
} catch (EmptyRedis) {}
}
return $this->withJson($response, ['cierres' => $output]);
return $this->withJson($response, $output);
}
}

View File

@ -1,24 +1,25 @@
<?php
namespace Incoviba\Controller\API\Ventas;
use DateTimeImmutable;
use DateInterval;
use Incoviba\Controller\API\withRedis;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use DateTimeImmutable;
use Incoviba\Common\Implement\Exception\EmptyRedis;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Controller\API\withJson;
use Incoviba\Controller\withRedis;
use Incoviba\Repository;
use Incoviba\Service;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
class Cuotas
{
use withJson, withRedis;
public function hoy(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Redis $redisService): ResponseInterface
public function hoy(ServerRequestInterface $request, ResponseInterface $response,
Repository\Venta\Cuota $cuotaRepository, Service\Redis $redisService): ResponseInterface
{
$today = new DateTimeImmutable();
$redisKey = "cuotas_hoy-{$today->format('Y-m-d')}";
$redisKey = "cuotas:hoy:{$today->format('Y-m-d')}";
$output = [
'cuotas' => 0
];
@ -32,10 +33,11 @@ class Cuotas
}
return $this->withJson($response, $output);
}
public function pendiente(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Redis $redisService): ResponseInterface
public function pendiente(ServerRequestInterface $request, ResponseInterface $response,
Repository\Venta\Cuota $cuotaRepository, Service\Redis $redisService): ResponseInterface
{
$today = new DateTimeImmutable();
$redisKey = "cuotas_pendientes-{$today->format('Y-m-d')}";
$redisKey = "cuotas:pendientes:{$today->format('Y-m-d')}";
$output = [
'cuotas' => 0
];
@ -49,10 +51,12 @@ class Cuotas
}
return $this->withJson($response, $output);
}
public function porVencer(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Redis $redisService, Service\Format $formatService): ResponseInterface
public function porVencer(ServerRequestInterface $request, ResponseInterface $response,
Repository\Venta\Cuota $cuotaRepository, Service\Redis $redisService,
Service\Format $formatService): ResponseInterface
{
$today = new DateTimeImmutable();
$redisKey = "cuotas_por_vencer-{$today->format('Y-m-d')}";
$redisKey = "cuotas:por_vencer:{$today->format('Y-m-d')}";
try {
$output = $this->fetchRedis($redisService, $redisKey);
} catch (EmptyRedis) {

View File

@ -2,27 +2,28 @@
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\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
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')}";
$redisKey = "ventas:facturacion:proyecto:{$proyecto_id}:{$today->format('Y-m-d')}";
try {
$output['ventas'] = $this->fetchRedis($redisService, $redisKey);
} catch (EmptyRedis) {

View File

@ -1,36 +1,53 @@
<?php
namespace Incoviba\Controller\API\Ventas;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Implement\Exception\EmptyRedis;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Controller\API;
use Incoviba\Service;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
class Precios
{
use API\withJson, API\emptyBody;
use API\withJson, API\emptyBody, \Incoviba\Controller\withRedis;
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService): ResponseInterface
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
Service\Venta\Precio $precioService): ResponseInterface
{
$body = $request->getBody();
$json = json_decode($body->getContents());
$proyecto_id = $json->proyecto_id;
$output = ['total' => 0];
$output = ['total' => 0, 'precios' => []];
$redisKey = "precios:proyecto:{$proyecto_id}";
try {
$precios = $precioService->getByProyecto($proyecto_id);
$output['precios'] = $precios;
$output['total'] = count($precios);
} catch (EmptyResult) {}
$output['precios'] = $this->fetchRedis($redisService, $redisKey);
$output['total'] = count($output['precios']);
} catch (EmptyRedis) {
try {
$precios = $precioService->getByProyecto($proyecto_id);
$output['precios'] = $precios;
$output['total'] = count($precios);
$this->saveRedis($redisService, $redisKey, $output['precios']);
} catch (EmptyResult) {}
}
return $this->withJson($response, $output);
}
public function unidad(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService, int $unidad_id): ResponseInterface
public function unidad(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
Service\Venta\Precio $precioService, int $unidad_id): ResponseInterface
{
$redisKey = "precio:unidad:{$unidad_id}";
try {
$precio = $precioService->getVigenteByUnidad($unidad_id);
$precio = $this->fetchRedis($redisService, $redisKey);
return $this->withJson($response, compact('precio'));
} catch (EmptyResult) {
return $this->emptyBody($response);
} catch (EmptyRedis) {
try {
$precio = $precioService->getVigenteByUnidad($unidad_id);
$this->saveRedis($redisService, $redisKey, $precio);
return $this->withJson($response, compact('precio'));
} catch (EmptyResult) {
return $this->emptyBody($response);
}
}
}
}

View File

@ -3,14 +3,14 @@ namespace Incoviba\Controller\API\Ventas;
use DateTimeImmutable;
use Incoviba\Common\Implement\Exception\EmptyRedis;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Controller\API\withJson;
use Incoviba\Controller\API\withRedis;
use Incoviba\Controller\withRedis;
use Incoviba\Model;
use Incoviba\Repository;
use Incoviba\Service;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
class Unidades
{
@ -22,7 +22,7 @@ class Unidades
$json = json_decode($body->getContents());
$proyecto_id = $json->proyecto_id;
$today = new DateTimeImmutable();
$redisKey = "unidades_disponibles-proyecto-{$proyecto_id}-{$today->format('Y-m-d')}";
$redisKey = "unidades:disponibles:proyecto:{$proyecto_id}:{$today->format('Y-m-d')}";
$output = [
'proyecto_id' => $proyecto_id,