From 28036fdd057df225179de3155fd2360b1a5f3d0b Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Wed, 20 Nov 2024 20:49:05 -0300 Subject: [PATCH] FIX: Si no conecta con Nubox solo se reajusta el terreno. --- app/setup/setups/services.php | 13 ++++++++++- app/src/Service/Contabilidad/Nubox.php | 31 ++++++++++++++++++++++++++ app/src/Service/Proyecto/Terreno.php | 19 ++++++++-------- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/app/setup/setups/services.php b/app/setup/setups/services.php index c04697e..ad5cebc 100644 --- a/app/setup/setups/services.php +++ b/app/setup/setups/services.php @@ -69,7 +69,18 @@ return [ $container->get(Psr\Log\LoggerInterface::class), $container->get(Incoviba\Repository\Contabilidad\Nubox::class), $container->get(Incoviba\Service\Redis::class), - new GuzzleHttp\Client(), + new GuzzleHttp\Client([ + 'defaults' => [ + 'config' => [ + 'curl' => [ + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_SSL_VERIFYHOST => false, + CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1_3 + ], + 'verify' => false + ] + ], + ]), $container->get(Psr\Http\Message\RequestFactoryInterface::class), $container->get('nubox')->get('url')); }, diff --git a/app/src/Service/Contabilidad/Nubox.php b/app/src/Service/Contabilidad/Nubox.php index d100e5c..b7622de 100644 --- a/app/src/Service/Contabilidad/Nubox.php +++ b/app/src/Service/Contabilidad/Nubox.php @@ -3,10 +3,12 @@ namespace Incoviba\Service\Contabilidad; use DateTimeInterface; use DateTimeImmutable; +use DateMalformedStringException; use Incoviba\Common\Ideal; use Incoviba\Common\Implement\Exception; use Incoviba\Repository; use Incoviba\Service; +use Psr\Http\Client\ClientExceptionInterface; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\ResponseInterface; @@ -81,6 +83,13 @@ class Nubox extends Ideal\Service return $this; } + /** + * @param int $inmobiliaria_rut + * @return array + * @throws ClientExceptionInterface + * @throws Exception\HttpResponse + * @throws DateMalformedStringException + */ public function getCuentas(int $inmobiliaria_rut): array { $redisKey = "nubox:cuentas:{$inmobiliaria_rut}"; @@ -98,6 +107,13 @@ class Nubox extends Ideal\Service return $cuentas; } } + + /** + * @throws DateMalformedStringException + * @throws ClientExceptionInterface + * @throws Exception\HttpResponse + * @throws Exception\EmptyResult + */ public function getCuenta(int $inmobiliaria_rut, string $cuentaNombre): string { $cuentas = $this->getCuentas($inmobiliaria_rut); @@ -109,6 +125,11 @@ class Nubox extends Ideal\Service } return array_values($validas)[0]['codigo']; } + + /** + * @throws Exception\HttpResponse + * @throws ClientExceptionInterface + */ public function getLibroMayor(int $inmobiliaria_rut, DateTimeInterface $from, DateTimeInterface $to): array { $inmobiliaria = $this->nuboxRepository->fetchByInmobiliaria($inmobiliaria_rut); @@ -153,6 +174,12 @@ class Nubox extends Ideal\Service $response = $this->send($uri, $inmobiliaria_rut); return json_decode($response->getBody()->getContents(), JSON_OBJECT_AS_ARRAY); } + + /** + * @throws DateMalformedStringException + * @throws Exception\HttpResponse + * @throws ClientExceptionInterface + */ public function getMesCuenta(int $inmobiliaria_rut, string $cuenta, DateTimeInterface $mes): array { $inmobiliaria = $this->nuboxRepository->fetchByInmobiliaria($inmobiliaria_rut); @@ -200,6 +227,10 @@ class Nubox extends Ideal\Service return $content; } + /** + * @throws Exception\HttpResponse + * @throws ClientExceptionInterface + */ private function send(string $uri, int $inmobiliaria_rut, string $method = 'GET', ?StreamInterface $body = null): ResponseInterface { $request = $this->requestFactory diff --git a/app/src/Service/Proyecto/Terreno.php b/app/src/Service/Proyecto/Terreno.php index 45d9c7b..bd264e4 100644 --- a/app/src/Service/Proyecto/Terreno.php +++ b/app/src/Service/Proyecto/Terreno.php @@ -4,9 +4,7 @@ namespace Incoviba\Service\Proyecto; use Exception; use DateTimeImmutable; use DateInterval; -use Incoviba\Common\Implement\Exception\EmptyResponse; -use Incoviba\Common\Implement\Exception\EmptyResult; -use Incoviba\Common\Implement\Exception\HttpResponse; +use Psr\Http\Client\ClientExceptionInterface; use Psr\Log\LoggerInterface; use Incoviba\Common\Ideal; use Incoviba\Common\Implement; @@ -38,7 +36,7 @@ class Terreno extends Ideal\Service return $proyecto->terreno; } try { - return $this->getValorContable($proyecto, $lastDecember); + return $this->getValorContable($proyecto, $lastDecember->add(new DateInterval('P1D'))); } catch (Implement\Exception\EmptyResponse) {} if ($proyecto->terreno->fecha === null) { return null; @@ -52,15 +50,18 @@ class Terreno extends Ideal\Service } /** - * @throws EmptyResponse - * @throws HttpResponse - * @throws EmptyResult + * @throws Implement\Exception\EmptyResponse + * @throws Implement\Exception\EmptyResult * @throws Exception */ protected function getValorContable(Model\Proyecto $proyecto, DateTimeImmutable $lastDecember): Model\Proyecto\Terreno { - $cuentaNubox = $this->nuboxService->getCuenta($proyecto->inmobiliaria()->rut, 'Terrenos'); - $movimientos = $this->nuboxService->getMesCuenta($proyecto->inmobiliaria()->rut, $cuentaNubox, $lastDecember); + try { + $cuentaNubox = $this->nuboxService->getCuenta($proyecto->inmobiliaria()->rut, 'Terrenos'); + $movimientos = $this->nuboxService->getMesCuenta($proyecto->inmobiliaria()->rut, $cuentaNubox, $lastDecember); + } catch (Implement\Exception\HttpResponse | ClientExceptionInterface $exception) { + throw new Implement\Exception\EmptyResponse("No existen cuentas para este proyecto para la fecha {$lastDecember->format('d-m-Y')}", $exception); + } if (count($movimientos) === 0 or $movimientos[0]['Saldo'] === 0.0) { throw new Implement\Exception\EmptyResponse("No hay movimientos para este proyecto para la fecha {$lastDecember->format('d-m-Y')}"); }