Limpieza de input de valor y filtro de datos a nivel Repo

This commit is contained in:
Juan Pablo Vial
2024-07-03 15:13:13 -04:00
parent d5b9be0196
commit d68eba5697
28 changed files with 436 additions and 189 deletions

View File

@ -1,6 +1,7 @@
<?php
namespace Incoviba\Service\Venta;
use Incoviba\Service\Valor;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Implement;
use Incoviba\Common\Ideal;
@ -15,7 +16,8 @@ class FormaPago extends Ideal\Service
protected Credito $creditoService,
protected Repository\Venta\Escritura $escrituraRepository,
protected Subsidio $subsidioService,
protected Pago $pagoService)
protected Pago $pagoService,
protected Valor $valorService)
{
parent::__construct($logger);
}
@ -83,7 +85,7 @@ class FormaPago extends Ideal\Service
'cuotas',
'uf'
], $filtered_data);
$mapped_data['valor'] = $this->cleanValue($mapped_data['valor']);
$mapped_data['valor'] = $this->valorService->clean($mapped_data['valor']);
return $this->pieService->add($mapped_data);
}
protected function addSubsidio(array $data): Model\Venta\Subsidio
@ -101,6 +103,8 @@ class FormaPago extends Ideal\Service
'subsidio',
'uf'
], $filtered_data);
$mapped_data['ahorro'] = $this->valorService->clean($mapped_data['ahorro']);
$mapped_data['subsidio'] = $this->valorService->clean($mapped_data['subsidio']);
return $this->subsidioService->add($mapped_data);
}
protected function addCredito(array $data): Model\Venta\Credito
@ -116,6 +120,7 @@ class FormaPago extends Ideal\Service
'valor',
'uf'
], $filtered_data);
$mapped_data['valor'] = $this->valorService->clean($mapped_data['valor']);
return $this->creditoService->add($mapped_data);
}
protected function addBonoPie(array $data): Model\Venta\BonoPie
@ -129,14 +134,7 @@ class FormaPago extends Ideal\Service
'fecha',
'valor'
], $filtered_data);
$mapped_data['valor'] = $this->valorService->clean($mapped_data['valor']);
return $this->bonoPieService->add($mapped_data);
}
protected function cleanValue($value): float
{
if ((float) $value == $value) {
return (float) $value;
}
return (float) str_replace(['.', ','], ['', '.'], $value);
}
}