process($this->propiedadUnidadRepository->fetchById($unidad_id)); } public function getByVenta(int $venta_id): array { return array_map([$this, 'process'], $this->propiedadUnidadRepository->fetchByVenta($venta_id)); } public function getByPropiedad(int $propiedad_id): array { return array_map([$this, 'process'], $this->propiedadUnidadRepository->fetchByPropiedad($propiedad_id)); } public function add(array $data): Model\Venta\PropiedadUnidad { $unidad = $this->unidadRepository->fetchById($data['unidad']); $temp = json_decode(json_encode($unidad), JSON_OBJECT_AS_ARRAY); $columnMap = [ 'proyecto_tipo_unidad' => 'pt' ]; foreach ($temp as $key => $value) { if (isset($columnMap[$key])) { $temp[$columnMap[$key]] = $value['id']; } } $temp['propiedad'] = $data['propiedad']; $temp['valor'] = $data['valor']; $pu = $this->propiedadUnidadRepository->create($temp); return $this->process($this->propiedadUnidadRepository->save($pu)); } public function edit(Model\Venta\PropiedadUnidad $propiedadUnidad, array $data): Model\Venta\PropiedadUnidad { return $this->process($this->propiedadUnidadRepository->edit($propiedadUnidad, $data)); } protected function process(Model\Venta\PropiedadUnidad $unidad): Model\Venta\PropiedadUnidad { try { $unidad->precios = $this->precioService->getByUnidad($unidad->id); $unidad->currentPrecio = $this->precioService->getVigenteByUnidad($unidad->id); if ($unidad->valor === null or $unidad->valor === 0) { $unidad->valor = $unidad->currentPrecio->valor; } } catch (Read) {} return $unidad; } }