Merge pull request 'FIX: Telefono sobre rango maximo de integer en MySQL' (#26) from hotfix/nueva-venta-fallando into develop
Reviewed-on: #26
This commit is contained in:
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class ChangeTelefonoSizeInPropietario extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('propietario')
|
||||
->changeColumn('telefono', 'biginteger', ['null' => true, 'signed' => false, 'default' => null])
|
||||
->update();
|
||||
}
|
||||
}
|
@ -156,7 +156,7 @@
|
||||
<script>
|
||||
const regiones = [
|
||||
@foreach ($regiones as $region)
|
||||
'<div class="item" data-value="{{$region->id}}">{{$region->descripcion}}</div>',
|
||||
'<div class="item" data-value="{{$region->id}}">{{$region->numeral}} - {{$region->descripcion}}</div>',
|
||||
@endforeach
|
||||
]
|
||||
|
||||
|
@ -4,7 +4,7 @@ namespace Incoviba\Service;
|
||||
use DateTimeInterface;
|
||||
use DateTimeImmutable;
|
||||
use DateMalformedStringException;
|
||||
use function PHPUnit\Framework\countOf;
|
||||
use Incoviba\Service\Valor\Phone;
|
||||
|
||||
class Valor
|
||||
{
|
||||
@ -40,6 +40,14 @@ class Valor
|
||||
}
|
||||
return $value / $this->ufService->get($date);
|
||||
}
|
||||
public function phone(): Phone
|
||||
{
|
||||
return new Phone();
|
||||
}
|
||||
public function telefono(): Phone
|
||||
{
|
||||
return $this->phone();
|
||||
}
|
||||
|
||||
protected function getDateTime(null|string|DateTimeInterface $date): DateTimeInterface
|
||||
{
|
||||
|
28
app/src/Service/Valor/Phone.php
Normal file
28
app/src/Service/Valor/Phone.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Valor;
|
||||
|
||||
class Phone
|
||||
{
|
||||
public function toDatabase(?string $phone): ?int
|
||||
{
|
||||
if ($phone === null) {
|
||||
return null;
|
||||
}
|
||||
return (int) str_replace([' ', '+'], '', $phone) ?? null;
|
||||
}
|
||||
public function toDisplay(?int $phone): ?string
|
||||
{
|
||||
if ($phone === null) {
|
||||
return null;
|
||||
}
|
||||
$parts = preg_split('/(?=<country>\d{2})?(?=<area>\d)(?=<first>\d{4})(?=<last>\d{4})/', $phone);
|
||||
$output = [];
|
||||
if (array_key_exists('country', $parts)) {
|
||||
$output [] = "+{$parts[0]}";
|
||||
}
|
||||
$output [] = $parts[1] ?? '';
|
||||
$output [] = $parts[2] ?? '';
|
||||
$output [] = $parts[3] ?? '';
|
||||
return implode(' ', $output);
|
||||
}
|
||||
}
|
@ -1,22 +1,24 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use PDOException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal\Service;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Exception\ServiceAction\Create;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use Incoviba\Exception\ServiceAction\Update;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use PDOException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service\Valor;
|
||||
|
||||
class Propietario extends Service
|
||||
{
|
||||
public function __construct(
|
||||
LoggerInterface $logger,
|
||||
protected Repository\Venta\Propietario $propietarioRepository,
|
||||
protected Repository\Direccion $direccionRepository
|
||||
protected Repository\Direccion $direccionRepository,
|
||||
protected Valor $valorService
|
||||
) {
|
||||
parent::__construct($logger);
|
||||
}
|
||||
@ -49,6 +51,9 @@ class Propietario extends Service
|
||||
$data['direccion'] = $direccion->id;
|
||||
}
|
||||
$filteredData = $this->propietarioRepository->filterData($data);
|
||||
if (array_key_exists('telefono', $filteredData)) {
|
||||
$filteredData['telefono'] = $this->valorService->telefono()->toDatabase($filteredData['telefono']);
|
||||
}
|
||||
try {
|
||||
return $this->propietarioRepository->edit($propietario, $filteredData);
|
||||
} catch (PDOException | EmptyResult $exception) {
|
||||
@ -85,6 +90,10 @@ class Propietario extends Service
|
||||
]);
|
||||
$filtered_data = array_intersect_key($data, $fields);
|
||||
|
||||
if (array_key_exists('telefono', $filtered_data)) {
|
||||
$filtered_data['telefono'] = $this->valorService->telefono()->toDatabase($filtered_data['telefono']);
|
||||
}
|
||||
|
||||
try {
|
||||
$propietario = $this->propietarioRepository->fetchById($data['rut']);
|
||||
$edits = [];
|
||||
@ -95,6 +104,7 @@ class Propietario extends Service
|
||||
} catch (EmptyResult) {
|
||||
try {
|
||||
$propietario = $this->propietarioRepository->create($filtered_data);
|
||||
$this->logger->info('Propietario', ['propietario' => $propietario]);
|
||||
$propietario = $this->propietarioRepository->save($propietario);
|
||||
} catch (PDOException $exception) {
|
||||
throw new Create(__CLASS__, $exception);
|
||||
|
Reference in New Issue
Block a user