FIX: Si no conecta con Nubox solo se reajusta el terreno.
This commit is contained in:
@ -69,7 +69,18 @@ return [
|
|||||||
$container->get(Psr\Log\LoggerInterface::class),
|
$container->get(Psr\Log\LoggerInterface::class),
|
||||||
$container->get(Incoviba\Repository\Contabilidad\Nubox::class),
|
$container->get(Incoviba\Repository\Contabilidad\Nubox::class),
|
||||||
$container->get(Incoviba\Service\Redis::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(Psr\Http\Message\RequestFactoryInterface::class),
|
||||||
$container->get('nubox')->get('url'));
|
$container->get('nubox')->get('url'));
|
||||||
},
|
},
|
||||||
|
@ -3,10 +3,12 @@ namespace Incoviba\Service\Contabilidad;
|
|||||||
|
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
|
use DateMalformedStringException;
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
use Incoviba\Common\Implement\Exception;
|
use Incoviba\Common\Implement\Exception;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
use Psr\Http\Client\ClientExceptionInterface;
|
||||||
use Psr\Http\Client\ClientInterface;
|
use Psr\Http\Client\ClientInterface;
|
||||||
use Psr\Http\Message\RequestFactoryInterface;
|
use Psr\Http\Message\RequestFactoryInterface;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
@ -81,6 +83,13 @@ class Nubox extends Ideal\Service
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $inmobiliaria_rut
|
||||||
|
* @return array
|
||||||
|
* @throws ClientExceptionInterface
|
||||||
|
* @throws Exception\HttpResponse
|
||||||
|
* @throws DateMalformedStringException
|
||||||
|
*/
|
||||||
public function getCuentas(int $inmobiliaria_rut): array
|
public function getCuentas(int $inmobiliaria_rut): array
|
||||||
{
|
{
|
||||||
$redisKey = "nubox:cuentas:{$inmobiliaria_rut}";
|
$redisKey = "nubox:cuentas:{$inmobiliaria_rut}";
|
||||||
@ -98,6 +107,13 @@ class Nubox extends Ideal\Service
|
|||||||
return $cuentas;
|
return $cuentas;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws DateMalformedStringException
|
||||||
|
* @throws ClientExceptionInterface
|
||||||
|
* @throws Exception\HttpResponse
|
||||||
|
* @throws Exception\EmptyResult
|
||||||
|
*/
|
||||||
public function getCuenta(int $inmobiliaria_rut, string $cuentaNombre): string
|
public function getCuenta(int $inmobiliaria_rut, string $cuentaNombre): string
|
||||||
{
|
{
|
||||||
$cuentas = $this->getCuentas($inmobiliaria_rut);
|
$cuentas = $this->getCuentas($inmobiliaria_rut);
|
||||||
@ -109,6 +125,11 @@ class Nubox extends Ideal\Service
|
|||||||
}
|
}
|
||||||
return array_values($validas)[0]['codigo'];
|
return array_values($validas)[0]['codigo'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception\HttpResponse
|
||||||
|
* @throws ClientExceptionInterface
|
||||||
|
*/
|
||||||
public function getLibroMayor(int $inmobiliaria_rut, DateTimeInterface $from, DateTimeInterface $to): array
|
public function getLibroMayor(int $inmobiliaria_rut, DateTimeInterface $from, DateTimeInterface $to): array
|
||||||
{
|
{
|
||||||
$inmobiliaria = $this->nuboxRepository->fetchByInmobiliaria($inmobiliaria_rut);
|
$inmobiliaria = $this->nuboxRepository->fetchByInmobiliaria($inmobiliaria_rut);
|
||||||
@ -153,6 +174,12 @@ class Nubox extends Ideal\Service
|
|||||||
$response = $this->send($uri, $inmobiliaria_rut);
|
$response = $this->send($uri, $inmobiliaria_rut);
|
||||||
return json_decode($response->getBody()->getContents(), JSON_OBJECT_AS_ARRAY);
|
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
|
public function getMesCuenta(int $inmobiliaria_rut, string $cuenta, DateTimeInterface $mes): array
|
||||||
{
|
{
|
||||||
$inmobiliaria = $this->nuboxRepository->fetchByInmobiliaria($inmobiliaria_rut);
|
$inmobiliaria = $this->nuboxRepository->fetchByInmobiliaria($inmobiliaria_rut);
|
||||||
@ -200,6 +227,10 @@ class Nubox extends Ideal\Service
|
|||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception\HttpResponse
|
||||||
|
* @throws ClientExceptionInterface
|
||||||
|
*/
|
||||||
private function send(string $uri, int $inmobiliaria_rut, string $method = 'GET', ?StreamInterface $body = null): ResponseInterface
|
private function send(string $uri, int $inmobiliaria_rut, string $method = 'GET', ?StreamInterface $body = null): ResponseInterface
|
||||||
{
|
{
|
||||||
$request = $this->requestFactory
|
$request = $this->requestFactory
|
||||||
|
@ -4,9 +4,7 @@ namespace Incoviba\Service\Proyecto;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResponse;
|
use Psr\Http\Client\ClientExceptionInterface;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
|
||||||
use Incoviba\Common\Implement\Exception\HttpResponse;
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
use Incoviba\Common\Implement;
|
use Incoviba\Common\Implement;
|
||||||
@ -38,7 +36,7 @@ class Terreno extends Ideal\Service
|
|||||||
return $proyecto->terreno;
|
return $proyecto->terreno;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return $this->getValorContable($proyecto, $lastDecember);
|
return $this->getValorContable($proyecto, $lastDecember->add(new DateInterval('P1D')));
|
||||||
} catch (Implement\Exception\EmptyResponse) {}
|
} catch (Implement\Exception\EmptyResponse) {}
|
||||||
if ($proyecto->terreno->fecha === null) {
|
if ($proyecto->terreno->fecha === null) {
|
||||||
return null;
|
return null;
|
||||||
@ -52,15 +50,18 @@ class Terreno extends Ideal\Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws EmptyResponse
|
* @throws Implement\Exception\EmptyResponse
|
||||||
* @throws HttpResponse
|
* @throws Implement\Exception\EmptyResult
|
||||||
* @throws EmptyResult
|
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected function getValorContable(Model\Proyecto $proyecto, DateTimeImmutable $lastDecember): Model\Proyecto\Terreno
|
protected function getValorContable(Model\Proyecto $proyecto, DateTimeImmutable $lastDecember): Model\Proyecto\Terreno
|
||||||
{
|
{
|
||||||
$cuentaNubox = $this->nuboxService->getCuenta($proyecto->inmobiliaria()->rut, 'Terrenos');
|
try {
|
||||||
$movimientos = $this->nuboxService->getMesCuenta($proyecto->inmobiliaria()->rut, $cuentaNubox, $lastDecember);
|
$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) {
|
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')}");
|
throw new Implement\Exception\EmptyResponse("No hay movimientos para este proyecto para la fecha {$lastDecember->format('d-m-Y')}");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user