Fixes de telefono y apellido de persona

This commit is contained in:
Juan Pablo Vial
2025-05-16 16:35:17 -04:00
parent 16cd29635d
commit 105179b4ed
6 changed files with 29 additions and 12 deletions

View File

@ -38,7 +38,9 @@ class Toku extends Controller
} else {
$output['success'] = true;
}
} catch (Read | InvalidResult) {}
} catch (Read | InvalidResult $exception) {
$this->logger->debug($exception);
}
return $this->withJson($response, $output);
}
public function success(ServerRequestInterface $request, ResponseInterface $response,

View File

@ -19,8 +19,8 @@ class Persona extends Ideal\Repository
public function create(?array $data = null): Model\Persona
{
$map = (new Implement\Repository\MapperParser(['rut', 'digito', 'nombres']))
->register('apellido_paterno', (new Implement\Repository\Mapper())->setProperty('apellidoPaterno'))
->register('apellido_materno', (new Implement\Repository\Mapper())->setProperty('apellidoMaterno'))
->register('apellido_paterno', (new Implement\Repository\Mapper())->setProperty('apellidoPaterno')->setDefault(''))
->register('apellido_materno', (new Implement\Repository\Mapper())->setProperty('apellidoMaterno')->setDefault(''))
;
return $this->parseData(new Model\Persona(), $data, $map);
}

View File

@ -2,9 +2,9 @@
namespace Incoviba\Service;
use DateTimeImmutable;
use DateTimeZone;
use InvalidArgumentException;
use OutOfRangeException;
use PDOException;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement\Exception\EmptyRedis;
@ -65,9 +65,9 @@ class Job extends Ideal\Service
*/
public function add(array $configuration): Model\Job
{
$now = (new DateTimeImmutable());
$now = (new DateTimeImmutable('now', new DateTimeZone($_ENV['TZ'] ?? 'America/Santiago')));
$data = [
'id' => $now->getTimestamp(),
'id' => $now->format('Uu'),
'configuration' => $configuration,
'executed' => false,
'created_at' => $now->format('Y-m-d H:i:s'),
@ -129,8 +129,10 @@ class Job extends Ideal\Service
*/
protected function findJob(array $jobs, int $id): int
{
$idx = array_find_key($jobs, fn($job) => $job['id'] === $id);
if ($idx === false) {
$idx = array_find_key($jobs, function($job) use ($id) {
return (int) $job['id'] === $id;
});
if ($idx === null) {
throw new EmptyResult("SELECT * FROM jobs WHERE id = ?");
}
return $idx;

View File

@ -70,7 +70,7 @@ class Persona extends Ideal\Service
$data['digito'] = $propietario->dv;
$data['nombres'] = $propietario->nombres;
$data['apellido_paterno'] = $propietario->apellidos['paterno'];
$data['apellido_materno'] = $propietario->apellidos['materno'];
$data['apellido_materno'] = $propietario->apellidos['materno'] ?? '';
$persona = $this->personaRepository->create($data);
try {
$persona = $this->personaRepository->save($persona);

View File

@ -113,10 +113,12 @@ class Toku extends Ideal\Service
$invoice = array_find($customerInvoices, function($invoiceRow) use ($cuota) {
return $invoiceRow['invoice_external_id'] === $cuota->id;
});
if ($invoice !== null) {
$invoices []= $invoice;
$this->invoice->save($invoice);
continue;
}
}
try {
$invoices []= $this->invoice->getById($cuota->id);
} catch (InvalidResult $exception) {

View File

@ -72,6 +72,17 @@ class Customer extends AbstractEndPoint
if ($ref === null) {
continue;
}
if ($ref === 'telefono') {
$value = $data[$ref];
if ($value === '' or $value === null or $value === '0') {
continue;
}
if (!str_starts_with($value, '+')) {
$value = "+56{$value}";
}
$params[$key] = $value;
continue;
}
if (array_key_exists($ref, $data) and $data[$ref] !== '' and $data[$ref] !== null) {
$params[$key] = $data[$ref];
}