From e6892ee085e77c054bcb819f9880c000a95aac43 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Tue, 29 Apr 2025 13:01:57 -0400 Subject: [PATCH] Valor de PU cuando unidad no tiene valor --- app/src/Service/Venta/PropiedadUnidad.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/Service/Venta/PropiedadUnidad.php b/app/src/Service/Venta/PropiedadUnidad.php index 4fee5ee..7fea997 100644 --- a/app/src/Service/Venta/PropiedadUnidad.php +++ b/app/src/Service/Venta/PropiedadUnidad.php @@ -4,14 +4,15 @@ namespace Incoviba\Service\Venta; use PDOException; use Incoviba\Common\Implement\Exception\EmptyResult; use Incoviba\Exception\ServiceAction\{Create, Read, Update}; -use Incoviba\Repository; use Incoviba\Model; +use Incoviba\Repository; +use Incoviba\Service; class PropiedadUnidad { public function __construct(protected Repository\Venta\PropiedadUnidad $propiedadUnidadRepository, protected Repository\Venta\Unidad $unidadRepository, - protected Precio $precioService) {} + protected Precio $precioService, protected Service\Valor $valorService) {} /** * @param int $unidad_id @@ -93,7 +94,11 @@ class PropiedadUnidad public function edit(Model\Venta\PropiedadUnidad $propiedadUnidad, array $data): Model\Venta\PropiedadUnidad { try { - return $this->process($this->propiedadUnidadRepository->edit($propiedadUnidad, $data)); + $filteredData = $this->propiedadUnidadRepository->filterData($data); + if (array_key_exists('valor', $filteredData)) { + $filteredData['valor'] = $this->valorService->clean($filteredData['valor']); + } + return $this->process($this->propiedadUnidadRepository->edit($propiedadUnidad, $filteredData)); } catch (PDOException $exception) { throw new Update(__CLASS__, $exception); } @@ -104,7 +109,9 @@ class PropiedadUnidad try { $unidad->precios = $this->precioService->getByUnidad($unidad->id); $unidad->currentPrecio = $this->precioService->getVigenteByUnidad($unidad->id); - $unidad->valor = $unidad->currentPrecio->valor; + if ($unidad->valor === null) { + $unidad->valor = $unidad->currentPrecio->valor; + } } catch (Read) {} return $unidad; }