Compare commits

13 Commits

Author SHA1 Message Date
06558d778d Merge pull request 'FIX: Skip handling import errors' (#49) from fix/add-venta into develop
Reviewed-on: #49
2025-10-06 12:08:39 -03:00
538833a5a4 FIX: Skip handling import errors 2025-10-06 12:08:08 -03:00
7bee4e3bb4 Merge pull request 'FIX: Cartolas not adding Movimientos or adding cargos and abonos' (#46) from fix/carga-cartolas into develop
Reviewed-on: #46
2025-10-04 14:16:29 -03:00
0c640d6cab FIX: Cartolas not adding Movimientos or adding cargos and abonos 2025-10-04 14:14:13 -03:00
6d871d77fe Merge branch 'master' into develop 2025-10-04 11:39:53 -03:00
b0267320a1 fix/add-venta (#44)
FIXES:
 - cast Comuna.id to int in Propietario
 - Inmobiliaria without tipoSociedad not loading descripcion

Log exception processor
Get Money values when stored as 0

Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl>
Reviewed-on: #44
2025-10-03 12:13:02 -03:00
a668b6b7be Merge pull request 'FIX: cuando no existe departamento' (#43) from feature/resumen-escritura-sin-departamento into develop
Reviewed-on: #43
2025-09-23 15:45:33 -03:00
3cf67a71b6 FIX: cuando no existe departamento 2025-09-22 12:19:29 -03:00
6ddc48ec60 Merge branch 'develop' 2024-03-13 16:31:34 -03:00
331ee1e584 Merge branch 'develop' 2023-06-22 23:18:13 -04:00
24c17debf3 Merge branch 'develop' 2023-02-15 18:30:09 -03:00
552fd0aa06 Merge branch 'develop' 2023-02-14 20:50:42 -03:00
60faf293d4 Merge branch 'develop' 2023-02-13 17:18:41 -03:00
19 changed files with 203 additions and 56 deletions

View File

@ -2,6 +2,7 @@
namespace Incoviba\Common\Define\Cartola; namespace Incoviba\Common\Define\Cartola;
use Psr\Http\Message\UploadedFileInterface; use Psr\Http\Message\UploadedFileInterface;
use Incoviba\Exception\ServiceAction\Read;
interface Banco interface Banco
{ {
@ -9,6 +10,7 @@ interface Banco
* Process bank movements for database inserts * Process bank movements for database inserts
* @param UploadedFileInterface $file * @param UploadedFileInterface $file
* @return array * @return array
* @throws Read
*/ */
public function process(UploadedFileInterface $file): array; public function process(UploadedFileInterface $file): array;

View File

@ -3,10 +3,16 @@ namespace Incoviba\Common\Ideal\Cartola;
use Incoviba\Common\Define; use Incoviba\Common\Define;
use Incoviba\Common\Ideal\Service; use Incoviba\Common\Ideal\Service;
use Incoviba\Exception\ServiceAction\Read;
use Psr\Http\Message\UploadedFileInterface; use Psr\Http\Message\UploadedFileInterface;
abstract class Banco extends Service implements Define\Cartola\Banco abstract class Banco extends Service implements Define\Cartola\Banco
{ {
/**
* @param UploadedFileInterface $file
* @return array
* @throws Read
*/
public function process(UploadedFileInterface $file): array public function process(UploadedFileInterface $file): array
{ {
$filename = $this->processUploadedFile($file); $filename = $this->processUploadedFile($file);
@ -40,6 +46,7 @@ abstract class Banco extends Service implements Define\Cartola\Banco
* Process the temp file from getFilename and remove it * Process the temp file from getFilename and remove it
* @param string $filename * @param string $filename
* @return array * @return array
* @throws Read
*/ */
protected function processFile(string $filename): array protected function processFile(string $filename): array
{ {
@ -88,6 +95,7 @@ abstract class Banco extends Service implements Define\Cartola\Banco
* Translate uploaded file data to database data * Translate uploaded file data to database data
* @param string $filename * @param string $filename
* @return array * @return array
* @throws Read
*/ */
abstract protected function parseFile(string $filename): array; abstract protected function parseFile(string $filename): array;
} }

View File

@ -0,0 +1,68 @@
<?php
namespace Incoviba\Common\Implement\Log\Processor;
use Throwable;
use Monolog\LogRecord;
use Monolog\Processor\ProcessorInterface;
class Exception implements ProcessorInterface
{
public function __invoke(LogRecord $record): LogRecord
{
$context = $record->context;
$changed = false;
array_walk_recursive($context, function (&$item) use (&$changed) {
if (is_a($item, Throwable::class)) {
$item = $this->processException($item);
$changed = true;
}
});
if ($changed) {
$new_record = new LogRecord(
$record->datetime,
$record->channel,
$record->level,
$record->message,
$context,
$record->extra
);
$record = $new_record;
}
if (is_a($record->message, Throwable::class)) {
$exception = $record->message;
$output = $this->processException($exception);
$message = $output['message'];
if (array_key_exists('exception', $context)) {
$context['other_exception'] = $context['exception'];
}
$context['exception'] = $output;
$new_record = new LogRecord(
$record->datetime,
$record->channel,
$record->level,
$message,
$context,
$record->extra
);
$record = $new_record;
}
return $record;
}
protected function processException(Throwable $exception): array
{
$output = [
'class' => get_class($exception),
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'trace' => $exception->getTraceAsString(),
];
if ($exception->getPrevious() !== null) {
$output['previous'] = $this->processException($exception);
}
return $output;
}
}

View File

@ -338,6 +338,7 @@
data.errors.forEach(errorData => { data.errors.forEach(errorData => {
console.error(errorData) console.error(errorData)
}) })
throw Error('Error al importar cartolas')
} }
this.data.movimientos = data.movimientos.map(movimiento => new Movimiento(movimiento)) this.data.movimientos = data.movimientos.map(movimiento => new Movimiento(movimiento))
this.draw().movimientos() this.draw().movimientos()

View File

@ -19,7 +19,7 @@
<div class="header"> <div class="header">
{{$inmobiliaria->abreviacion}} {{$inmobiliaria->abreviacion}}
</div> </div>
<div class="description">{{$inmobiliaria->razon}} {{$inmobiliaria->tipoSociedad->descripcion}}</div> <div class="description">{{$inmobiliaria->razon}} {{$inmobiliaria->tipoSociedad?->descripcion ?? ''}}</div>
<div class="meta">{{$inmobiliaria->rut()}}</div> <div class="meta">{{$inmobiliaria->rut()}}</div>
</div> </div>
</div> </div>

View File

@ -6,7 +6,12 @@
@section('venta_content') @section('venta_content')
<div class="ui segment"> <div class="ui segment">
@if (count($venta->propiedad()->departamentos()) > 0)
El departamento {{$venta->propiedad()->departamentos()[0]->descripcion}}:<br /> El departamento {{$venta->propiedad()->departamentos()[0]->descripcion}}:<br />
@else
La unidad {{ ucwords($venta->propiedad()->principal()?->proyectoTipoUnidad->tipoUnidad->descripcion) }}
{{ $venta->propiedad()->principal()?->descripcion }}:<br />
@endif
@php @php
$estacionamientos = $venta->propiedad()->estacionamientos(); $estacionamientos = $venta->propiedad()->estacionamientos();
@endphp @endphp

View File

@ -25,6 +25,7 @@ return [
$container->get(Monolog\Processor\MemoryPeakUsageProcessor::class), $container->get(Monolog\Processor\MemoryPeakUsageProcessor::class),
$container->get(Monolog\Processor\PsrLogMessageProcessor::class), $container->get(Monolog\Processor\PsrLogMessageProcessor::class),
$container->get(Monolog\Processor\UidProcessor::class), $container->get(Monolog\Processor\UidProcessor::class),
$container->get(Incoviba\Common\Implement\Log\Processor\Exception::class),
]; ];
}, },
'baseDefaultHandlers' => function(ContainerInterface $container) { 'baseDefaultHandlers' => function(ContainerInterface $container) {

View File

@ -2,6 +2,7 @@
namespace Incoviba\Controller\API\Contabilidad; namespace Incoviba\Controller\API\Contabilidad;
use DateTimeImmutable; use DateTimeImmutable;
use Incoviba\Exception\ServiceAction\Read;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Ideal\Controller; use Incoviba\Common\Ideal\Controller;
@ -117,7 +118,10 @@ class Cartolas extends Controller
UPLOAD_ERR_CANT_WRITE => 'No se pudo escribir el archivo', UPLOAD_ERR_CANT_WRITE => 'No se pudo escribir el archivo',
UPLOAD_ERR_EXTENSION => 'Una extensión de PHP detuvo la subida del archivo' UPLOAD_ERR_EXTENSION => 'Una extensión de PHP detuvo la subida del archivo'
]; ];
if (is_array($files['file'])) { if (!is_array($files['file'])) {
$files['file'] = [$files['file']];
$body['cuenta_id'] = [$body['cuenta_id']];
}
foreach ($files['file'] as $i => $file) { foreach ($files['file'] as $i => $file) {
if ($file->getError() !== UPLOAD_ERR_OK) { if ($file->getError() !== UPLOAD_ERR_OK) {
$output['errors'] []= ['filename' => $file->getClientFilename(), 'error' => $errors[$file->getError()]]; $output['errors'] []= ['filename' => $file->getClientFilename(), 'error' => $errors[$file->getError()]];
@ -125,16 +129,10 @@ class Cartolas extends Controller
} }
try { try {
$output['movimientos'] = array_merge($output['movimientos'], $cartolaService->import($body['cuenta_id'][$i], $file)); $output['movimientos'] = array_merge($output['movimientos'], $cartolaService->import($body['cuenta_id'][$i], $file));
} catch (EmptyResult) {} } catch (Read $exception) {
} $output['errors'] []= ['filename' => $file->getClientFilename(),
} else { 'error' => ['message' => $exception->getMessage(), 'file' => $exception->getFile(),
$file = $files['file']; 'line' => $exception->getLine()]];
if ($file->getError() !== UPLOAD_ERR_OK) {
$output['errors'][] = ['filename' => $file->getClientFilename(), 'error' => $errors[$file->getError()]];
} else {
try {
$output['movimientos'] = $cartolaService->import($body['cuenta_id'], $file);
} catch (EmptyResult) {}
} }
} }
return $this->withJson($response, $output); return $this->withJson($response, $output);

View File

@ -53,7 +53,7 @@ class Money
} }
try { try {
$this->data[$provider] = (array) $this->fetchRedis($redisService, $redisKey); $this->data[$provider] = (array) $this->fetchRedis($redisService, $redisKey);
if (!isset($this->data[$provider][$date->format('Y-m-d')])) { if (!isset($this->data[$provider][$date->format('Y-m-d')]) or $this->data[$provider][$date->format('Y-m-d')] === 0) {
throw new EmptyRedis($redisKey); throw new EmptyRedis($redisKey);
} }
} catch (EmptyRedis) { } catch (EmptyRedis) {

View File

@ -1,18 +1,21 @@
<?php <?php
namespace Incoviba\Service\Contabilidad; namespace Incoviba\Service\Contabilidad;
use DateMalformedStringException;
use PDOException; use PDOException;
use DateTimeImmutable; use DateTimeImmutable;
use DateTimeInterface; use DateTimeInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UploadedFileInterface;
use Psr\Log\LoggerInterface;
use PhpOffice\PhpSpreadsheet;
use Incoviba\Common\Define\Cartola\Banco; use Incoviba\Common\Define\Cartola\Banco;
use Incoviba\Common\Define\Contabilidad\Exporter; use Incoviba\Common\Define\Contabilidad\Exporter;
use Incoviba\Common\Ideal\Service; use Incoviba\Common\Ideal\Service;
use Incoviba\Common\Implement\Exception; use Incoviba\Common\Implement\Exception;
use Incoviba\Exception\ServiceAction\Read;
use Incoviba\Model; use Incoviba\Model;
use Incoviba\Repository; use Incoviba\Repository;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UploadedFileInterface;
use Psr\Log\LoggerInterface;
class Cartola extends Service class Cartola extends Service
{ {
@ -32,6 +35,13 @@ class Cartola extends Service
$this->bancos[$name] = $banco; $this->bancos[$name] = $banco;
return $this; return $this;
} }
/**
* @param Model\Contabilidad\Banco $banco
* @param UploadedFileInterface $file
* @return array
* @throws Read
*/
public function process(Model\Contabilidad\Banco $banco, UploadedFileInterface $file): array public function process(Model\Contabilidad\Banco $banco, UploadedFileInterface $file): array
{ {
return $this->bancos[strtolower($banco->nombre)]->process($file); return $this->bancos[strtolower($banco->nombre)]->process($file);
@ -93,9 +103,19 @@ class Cartola extends Service
return compact('cartola', 'movimientos'); return compact('cartola', 'movimientos');
} }
/**
* @param int $cuenta_id
* @param UploadedFileInterface $file
* @return array
* @throws Read
*/
public function import(int $cuenta_id, UploadedFileInterface $file): array public function import(int $cuenta_id, UploadedFileInterface $file): array
{ {
try {
$cuenta = $this->cuentaRepository->fetchById($cuenta_id); $cuenta = $this->cuentaRepository->fetchById($cuenta_id);
} catch (Exception\EmptyResult $exception) {
throw new Read(__CLASS__, $exception);
}
$movimientos = $this->process($cuenta->banco, $file); $movimientos = $this->process($cuenta->banco, $file);
$inmobiliaria = $cuenta->inmobiliaria; $inmobiliaria = $cuenta->inmobiliaria;
@ -106,8 +126,15 @@ class Cartola extends Service
if (array_key_exists('centro_costo', $dataMovimiento) and $dataMovimiento['centro_costo'] !== 0) { if (array_key_exists('centro_costo', $dataMovimiento) and $dataMovimiento['centro_costo'] !== 0) {
$dataMovimiento['centro_costo_id'] = $dataMovimiento['centro_costo']; $dataMovimiento['centro_costo_id'] = $dataMovimiento['centro_costo'];
} }
try {
$dataMovimiento['fecha'] = new DateTimeImmutable($dataMovimiento['fecha']); $dataMovimiento['fecha'] = new DateTimeImmutable($dataMovimiento['fecha']);
} catch (DateMalformedStringException) {
continue;
}
if (array_key_exists('rut', $dataMovimiento)) { if (array_key_exists('rut', $dataMovimiento)) {
if ($dataMovimiento['rut'] === '') {
unset($dataMovimiento['rut']);
} else {
$ruts = $this->parseRut($dataMovimiento['rut']); $ruts = $this->parseRut($dataMovimiento['rut']);
if (key_exists('rut', $ruts)) { if (key_exists('rut', $ruts)) {
$dataMovimiento['rut'] = $ruts['rut']; $dataMovimiento['rut'] = $ruts['rut'];
@ -117,6 +144,7 @@ class Cartola extends Service
$dataMovimiento['digito'] = $ruts[0]['digito']; $dataMovimiento['digito'] = $ruts[0]['digito'];
} }
} }
}
try { try {
$movimiento = $this->movimientoRepository $movimiento = $this->movimientoRepository
->fetchByCuentaAndFechaAndGlosaAndCargoAndAbonoAndSaldo($dataMovimiento['cuenta_id'], $dataMovimiento['fecha'], ->fetchByCuentaAndFechaAndGlosaAndCargoAndAbonoAndSaldo($dataMovimiento['cuenta_id'], $dataMovimiento['fecha'],
@ -133,14 +161,28 @@ class Cartola extends Service
$fechas = array_unique(array_map(function($movimiento) { $fechas = array_unique(array_map(function($movimiento) {
return $movimiento['fecha']->format('Y-m-d'); return $movimiento['fecha']->format('Y-m-d');
}, $movimientos)); }, $movimientos));
if (count($fechas) === 0) {
throw new Read(__CLASS__);
}
foreach ($fechas as $dia) { foreach ($fechas as $dia) {
try { try {
$this->cartolaRepository->fetchByCuentaAndFecha($cuenta->id, new DateTimeImmutable($dia)); $dayDate = new DateTimeImmutable($dia);
} catch (DateMalformedStringException) {
continue;
}
try {
$this->cartolaRepository->fetchByCuentaAndFecha($cuenta->id, $dayDate);
continue; continue;
} catch (Exception\EmptyResult) {} } catch (Exception\EmptyResult) {}
$movs = array_filter($movimientos, function($movimiento) use ($dia) { $movs = array_filter($movimientos, function($movimiento) use ($dia) {
return $movimiento['fecha'] === $dia; return $movimiento['fecha']->format('Y-m-d') === $dia;
}); });
if (count($movs) === 0) {
continue;
}
$cargos = array_sum(array_map(function($movimiento) { $cargos = array_sum(array_map(function($movimiento) {
return $movimiento['cargo']; return $movimiento['cargo'];
}, $movs)); }, $movs));
@ -153,11 +195,19 @@ class Cartola extends Service
'abonos' => $abonos, 'abonos' => $abonos,
'saldo' => $saldo 'saldo' => $saldo
]; ];
$this->buildCartola($cuenta, new DateTimeImmutable($dia), $cartolaData); $this->buildCartola($cuenta, $dayDate, $cartolaData);
} }
try {
$startDate = new DateTimeImmutable(min($fechas)); $startDate = new DateTimeImmutable(min($fechas));
} catch (DateMalformedStringException $exception) {
throw new Read(__CLASS__, $exception);
}
try {
$endDate = new DateTimeImmutable(max($fechas)); $endDate = new DateTimeImmutable(max($fechas));
} catch (DateMalformedStringException $exception) {
throw new Read(__CLASS__, $exception);
}
$movimientosFaltantes = $this->movimientoService->findMissing($cuenta, $addedMovimientos, $startDate, $endDate); $movimientosFaltantes = $this->movimientoService->findMissing($cuenta, $addedMovimientos, $startDate, $endDate);
$movimientosObsoletos = []; $movimientosObsoletos = [];
if (count($movimientosFaltantes) > 0) { if (count($movimientosFaltantes) > 0) {

View File

@ -3,6 +3,7 @@ namespace Incoviba\Service\Contabilidad\Cartola;
use DateTimeImmutable; use DateTimeImmutable;
use Incoviba\Common\Ideal\Cartola\Banco; use Incoviba\Common\Ideal\Cartola\Banco;
use Incoviba\Exception\ServiceAction\Read;
use PhpOffice\PhpSpreadsheet; use PhpOffice\PhpSpreadsheet;
use Psr\Http\Message\UploadedFileInterface; use Psr\Http\Message\UploadedFileInterface;
@ -10,8 +11,8 @@ class Itau extends Banco
{ {
use isExcel; use isExcel;
const CUENTA_CORRIENTE = 0; const int CUENTA_CORRIENTE = 0;
const ULTIMOS_MOVIMIENTOS = 1; const int ULTIMOS_MOVIMIENTOS = 1;
public function processMovimientosDiarios(array $movimientos): array public function processMovimientosDiarios(array $movimientos): array
{ {
@ -44,6 +45,12 @@ class Itau extends Banco
$ext = pathinfo($uploadedFile->getClientFilename(), PATHINFO_EXTENSION); $ext = pathinfo($uploadedFile->getClientFilename(), PATHINFO_EXTENSION);
return "/tmp/cartola.{$ext}"; return "/tmp/cartola.{$ext}";
} }
/**
* @param string $filename
* @return array
* @throws Read
*/
protected function parseFile(string $filename): array protected function parseFile(string $filename): array
{ {
$ext = pathinfo($filename, PATHINFO_EXTENSION); $ext = pathinfo($filename, PATHINFO_EXTENSION);
@ -62,7 +69,7 @@ class Itau extends Banco
break; break;
} }
} catch (PhpSpreadsheet\Exception $exception) { } catch (PhpSpreadsheet\Exception $exception) {
$this->logger->critical($exception); throw new Read(__CLASS__, $exception);
} }
return $data; return $data;
} }
@ -166,6 +173,11 @@ class Itau extends Banco
}); });
} }
/**
* @param PhpSpreadsheet\Worksheet\Worksheet $sheet
* @return int
* @throws PhpSpreadsheet\Exception
*/
protected function identifySheet(PhpSpreadsheet\Worksheet\Worksheet $sheet): int protected function identifySheet(PhpSpreadsheet\Worksheet\Worksheet $sheet): int
{ {
foreach ($sheet->getRowIterator(1, 10) as $row) { foreach ($sheet->getRowIterator(1, 10) as $row) {
@ -177,7 +189,7 @@ class Itau extends Banco
return self::ULTIMOS_MOVIMIENTOS; return self::ULTIMOS_MOVIMIENTOS;
} }
} }
throw new PhpSpreadsheet\Exception(); throw new PhpSpreadsheet\Exception('Incorrect type of Worksheet');
} }
protected function getDateRange(PhpSpreadsheet\Worksheet\Row $row): array protected function getDateRange(PhpSpreadsheet\Worksheet\Row $row): array
{ {

View File

@ -21,7 +21,7 @@ class IPC
$ipcs = []; $ipcs = [];
try { try {
$ipcs = json_decode($this->redisService->get($this->redisKey), JSON_OBJECT_AS_ARRAY); $ipcs = json_decode($this->redisService->get($this->redisKey), JSON_OBJECT_AS_ARRAY);
if (!isset($ipcs[$dateKey])) { if (!isset($ipcs[$dateKey]) or $ipcs[$dateKey] === 0) {
throw new EmptyRedis($this->redisKey); throw new EmptyRedis($this->redisKey);
} }
} catch (EmptyRedis) { } catch (EmptyRedis) {

View File

@ -48,8 +48,8 @@ class Ine implements Provider
]); ]);
try { try {
$response = $this->client->get($request_uri); $response = $this->client->get($request_uri);
} catch (GuzzleException) { } catch (GuzzleException $exception) {
throw new EmptyResponse($request_uri); throw new EmptyResponse($request_uri, $exception);
} }
$body = $response->getBody(); $body = $response->getBody();
$json = json_decode($body->getContents()); $json = json_decode($body->getContents());

View File

@ -12,6 +12,9 @@ class MiIndicador implements Provider
public function __construct(protected ClientInterface $client) {} public function __construct(protected ClientInterface $client) {}
/** /**
* @param string $money_symbol
* @param DateTimeInterface|null $dateTime
* @return float
* @throws EmptyResponse * @throws EmptyResponse
*/ */
public function get(string $money_symbol, ?DateTimeInterface $dateTime = null): float public function get(string $money_symbol, ?DateTimeInterface $dateTime = null): float
@ -33,7 +36,7 @@ class MiIndicador implements Provider
$body = $response->getBody(); $body = $response->getBody();
$json = json_decode($body->getContents()); $json = json_decode($body->getContents());
if (empty($json) or $json->codigo !== $money_symbol or count($json->serie) === 0) { if (empty($json) or !isset($json->codigo) or !isset($json->serie) or $json->codigo !== $money_symbol or count($json->serie) === 0) {
throw new EmptyResponse($request_uri); throw new EmptyResponse($request_uri);
} }
return $json->serie[0]->valor; return $json->serie[0]->valor;

View File

@ -79,13 +79,7 @@ class Queue extends Ideal\Service
try { try {
$this->jobService->update($job); $this->jobService->update($job);
} catch (Update $exception) { } catch (Update $exception) {
$this->logger->error($exception->getMessage(), ['job' => $job, 'exception' => [ $this->logger->error($exception->getMessage(), ['job' => $job, 'exception' => $exception]);
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'trace' => $exception->getTraceAsString(),
]]);
} }
return false; return false;
} }

View File

@ -22,7 +22,7 @@ class UF
if ($date === null) { if ($date === null) {
$date = new DateTimeImmutable(); $date = new DateTimeImmutable();
} }
if ($date->diff($today)->days < 0) { if ($date->diff($today)->invert === 1) {
return 0.0; return 0.0;
} }
/** /**
@ -32,7 +32,7 @@ class UF
*/ */
try { try {
$ufs = $this->getRedisUFs(); $ufs = $this->getRedisUFs();
if (!isset($ufs[$date->format('Y-m-d')])) { if (!isset($ufs[$date->format('Y-m-d')]) or $ufs[$date->format('Y-m-d')] === 0) {
throw new EmptyRedis($this->redisKey); throw new EmptyRedis($this->redisKey);
} }
return $ufs[$date->format('Y-m-d')]; return $ufs[$date->format('Y-m-d')];
@ -54,12 +54,16 @@ class UF
} }
public function updateMany(array $dates): array public function updateMany(array $dates): array
{ {
$today = new DateTimeImmutable();
$ufs = []; $ufs = [];
try { try {
$ufs = json_decode($this->redisService->get($this->redisKey), JSON_OBJECT_AS_ARRAY); $ufs = json_decode($this->redisService->get($this->redisKey), JSON_OBJECT_AS_ARRAY);
} catch (EmptyRedis) {} } catch (EmptyRedis) {}
$updated = []; $updated = [];
foreach ($dates as $date) { foreach ($dates as $date) {
if ($date->diff($today)->invert === 1) {
continue;
}
if (!isset($ufs[$date->format('Y-m-d')]) or $ufs[$date->format('Y-m-d')] === 0) { if (!isset($ufs[$date->format('Y-m-d')]) or $ufs[$date->format('Y-m-d')] === 0) {
$uf = $this->moneyService->getUF($date); $uf = $this->moneyService->getUF($date);
if ($uf === 0.0) { if ($uf === 0.0) {

View File

@ -19,7 +19,7 @@ class USD
$usds = []; $usds = [];
try { try {
$usds = json_decode($this->redisService->get($this->redisKey), JSON_OBJECT_AS_ARRAY); $usds = json_decode($this->redisService->get($this->redisKey), JSON_OBJECT_AS_ARRAY);
if (!isset($usds[$date->format('Y-m-d')])) { if (!isset($usds[$date->format('Y-m-d')]) or $usds[$date->format('Y-m-d')] === 0) {
throw new EmptyRedis($this->redisKey); throw new EmptyRedis($this->redisKey);
} }
$usd = $usds[$date->format('Y-m-d')]; $usd = $usds[$date->format('Y-m-d')];

View File

@ -181,7 +181,8 @@ class Propietario extends Service
]); ]);
$filtered_data = array_intersect_key($data, $fields); $filtered_data = array_intersect_key($data, $fields);
try { try {
$direccion = $this->direccionRepository->fetchByCalleAndNumeroAndExtraAndComuna($filtered_data['calle'], $filtered_data['numero'], $filtered_data['extra'], $filtered_data['comuna']); $direccion = $this->direccionRepository->fetchByCalleAndNumeroAndExtraAndComuna($filtered_data['calle'],
$filtered_data['numero'], $filtered_data['extra'], (int) $filtered_data['comuna']);
} catch (EmptyResult) { } catch (EmptyResult) {
try { try {
$direccion = $this->direccionRepository->create($filtered_data); $direccion = $this->direccionRepository->create($filtered_data);

View File

@ -174,7 +174,7 @@ class Reservation extends Ideal\Service\API
$this->reservationRepository->getConnection()->getPDO()->commit(); $this->reservationRepository->getConnection()->getPDO()->commit();
} }
} catch (PDOException $exception) { } catch (PDOException $exception) {
$this->logger->warning($exception->getMessage(), ['exception' => $exception->getTraceAsString()]); $this->logger->warning($exception->getMessage(), ['exception' => $exception]);
if ($this->reservationRepository->getConnection()->getPDO()->inTransaction()) { if ($this->reservationRepository->getConnection()->getPDO()->inTransaction()) {
$this->reservationRepository->getConnection()->getPDO()->rollBack(); $this->reservationRepository->getConnection()->getPDO()->rollBack();
} }