precioRepository->fetchByProyecto($proyecto_id); foreach ($precios as $precio) { $precio->estados = $this->estadoPrecioRepository->fetchByPrecio($precio->id); $precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id); } return $precios; } catch (EmptyResult $exception) { throw new ServiceAction\Read(__CLASS__, $exception); } } /** * @param int $unidad_id * @return Model\Venta\Precio * @throws ServiceAction\Read */ public function getVigenteByUnidad(int $unidad_id): Model\Venta\Precio { try { $precio = $this->precioRepository->fetchVigenteByUnidad($unidad_id); $precio->estados = $this->estadoPrecioRepository->fetchByPrecio($precio->id); $precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id); return $precio; } catch (EmptyResult $exception) { throw new ServiceAction\Read(__CLASS__, $exception); } } /** * @param int $unidad_id * @return array * @throws ServiceAction\Read */ public function getByUnidad(int $unidad_id): array { try { $precios = $this->precioRepository->fetchByUnidad($unidad_id); foreach ($precios as $precio) { $precio->estados = $this->estadoPrecioRepository->fetchByPrecio($precio->id); $precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id); } return $precios; } catch (EmptyResult $exception) { throw new ServiceAction\Read(__CLASS__, $exception); } } /** * @param int $projectId * @param DateTimeInterface $date * @param UploadedFileInterface $uploadedFile * @return array * @throws ServiceAction\Create */ public function import(int $projectId, DateTimeInterface $date, UploadedFileInterface $uploadedFile): array { $pricesData = $this->importService->importData($projectId, $date, $uploadedFile); $prices = []; foreach ($pricesData as $data) { try { $price = $this->precioRepository->create($data); $price = $this->precioRepository->save($price); $prices[] = $price; } catch (EmptyResult | PDOException $exception) { $this->logger->error('Problemas para agregar precio', ['data' => $data, 'exception' => $exception]); } } foreach ($prices as $price) { $idx = array_search($price->unidad->id, array_column($pricesData, 'unidad')); $row = $pricesData[$idx]; try { $this->estadoPrecioService->replacePrices($price->unidad, $date, $price); } catch (ServiceAction\Update $exception) { $this->logger->error('Problemas para reemplazar precios', [ 'data' => $row, 'exception' => $exception ]); } try { $this->estadoPrecioService->updatePrice($price, $row['fecha']); } catch (ServiceAction\Update $exception) { $this->logger->error('Problemas para actualizar estado de precio', [ 'data' => $row, 'exception' => $exception ]); } } return $prices; } }