Limpieza de input de valor y filtro de datos a nivel Repo
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Exception;
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@ -29,7 +30,8 @@ class Venta extends Service
|
||||
protected Venta\BonoPie $bonoPieService,
|
||||
protected Venta\Pago $pagoService,
|
||||
protected Proyecto\Terreno $terrenoService,
|
||||
protected Money $moneyService
|
||||
protected Money $moneyService,
|
||||
protected Valor $valorService
|
||||
) {
|
||||
parent::__construct($logger);
|
||||
}
|
||||
@ -136,6 +138,9 @@ class Venta extends Service
|
||||
return $venta;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function add(array $data): Model\Venta
|
||||
{
|
||||
$fecha = new DateTimeImmutable($data['fecha_venta']);
|
||||
@ -147,7 +152,7 @@ class Venta extends Service
|
||||
'propietario' => $propietario->rut,
|
||||
'propiedad' => $propiedad->id,
|
||||
'fecha' => $fecha->format('Y-m-d'),
|
||||
'valor_uf' => $this->cleanValue($data['valor']),
|
||||
'valor_uf' => $this->valorService->clean($data['valor']),
|
||||
'fecha_ingreso' => (new DateTimeImmutable())->format('Y-m-d'),
|
||||
'uf' => $data['uf']
|
||||
];
|
||||
@ -279,6 +284,10 @@ class Venta extends Service
|
||||
{
|
||||
return $this->formaPagoService->add($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function addEstado(Model\Venta $venta, Model\Venta\TipoEstadoVenta $tipoEstadoVenta, array $data): void
|
||||
{
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
@ -290,13 +299,6 @@ class Venta extends Service
|
||||
$estado = $this->estadoVentaRepository->create($estadoData);
|
||||
$this->estadoVentaRepository->save($estado);
|
||||
}
|
||||
protected function cleanValue($value): float
|
||||
{
|
||||
if ((float) $value == $value) {
|
||||
return (float) $value;
|
||||
}
|
||||
return (float) str_replace(['.', ','], ['', '.'], $value);
|
||||
}
|
||||
|
||||
public function escriturar(Model\Venta $venta, array $data): bool
|
||||
{
|
||||
@ -340,21 +342,29 @@ class Venta extends Service
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function reajustarEscritura(Model\Venta $venta, array $data): void
|
||||
{
|
||||
$fecha = new DateTimeImmutable($data['fecha_reajuste']);
|
||||
$reajusteData = [
|
||||
'valor' => $data['valor_reajuste'],
|
||||
'valor' => $this->valorService->clean($data['valor_reajuste']),
|
||||
'fecha' => $fecha->format('Y-m-d')
|
||||
];
|
||||
$pie = $venta->formaPago()->pie;
|
||||
$this->pieService->reajustar($pie, $reajusteData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function abonoEscritura(Model\Venta $venta, array $data): void
|
||||
{
|
||||
$fecha = new DateTimeImmutable($data['fecha_pago']);
|
||||
$uf = $this->moneyService->getUF($fecha);
|
||||
$valor = $data['valor_pago_ufs'] !== '' ? $data['valor_pago_ufs'] * $uf : $data['valor_pago_pesos'];
|
||||
$valor = $data['valor_pago_ufs'] !== '' ? $this->valorService->clean($data['valor_pago_ufs']) * $uf : $this->valorService->clean($data['valor_pago_pesos']);
|
||||
$pagoData = [
|
||||
'valor' => $valor,
|
||||
'fecha' => $fecha->format('Y-m-d'),
|
||||
@ -371,24 +381,32 @@ class Venta extends Service
|
||||
$escritura = $this->escrituraRepository->save($escritura);
|
||||
$this->ventaRepository->edit($venta, ['escritura' => $escritura->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function subsidioEscritura(Model\Venta $venta, array $data): void
|
||||
{
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
$uf = $this->moneyService->getUF($fecha);
|
||||
$subsidioData = [
|
||||
'fecha_venta' => $fecha->format('Y-m-d'),
|
||||
'ahorro' => $data['valor_ahorro'],
|
||||
'subsidio' => $data['valor_subsidio'],
|
||||
'ahorro' => $this->valorService->clean($data['valor_ahorro']),
|
||||
'subsidio' => $this->valorService->clean($data['valor_subsidio']),
|
||||
'uf' => $uf
|
||||
];
|
||||
$subsidio = $this->addSubsidio($subsidioData);
|
||||
$this->ventaRepository->edit($venta, ['subsidio' => $subsidio->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function editCredito(Model\Venta $venta, array $data): void
|
||||
{
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
$uf = $this->moneyService->getUF($fecha);
|
||||
$valor = $data['valor_credito'] * $uf;
|
||||
$valor = $this->valorService->clean($data['valor_credito']) * $uf;
|
||||
if ($venta->formaPago()->credito === null) {
|
||||
$pagoData = [
|
||||
'valor' => $valor,
|
||||
@ -425,7 +443,7 @@ class Venta extends Service
|
||||
{
|
||||
try {
|
||||
if ($this->validarData($data, ['fecha', 'devolucion'])) {
|
||||
$pago = $this->pagoService->add(['fecha' => $data['fecha'], 'valor' => str_replace(['.', ','], ['', '.'], $data['devolucion'])]);
|
||||
$pago = $this->pagoService->add(['fecha' => $data['fecha'], 'valor' => $this->valorService->clean($data['devolucion'])]);
|
||||
$this->ventaRepository->edit($venta, ['resciliacion' => $pago->id]);
|
||||
}
|
||||
$tipoEstado = $this->tipoEstadoVentaRepository->fetchByDescripcion('desistida');
|
||||
|
Reference in New Issue
Block a user