2023-07-24 20:55:26 -04:00
|
|
|
<?php
|
2023-08-08 23:53:49 -04:00
|
|
|
namespace Incoviba\Service\Venta;
|
2023-07-24 20:55:26 -04:00
|
|
|
|
2025-03-03 14:57:22 -03:00
|
|
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
|
|
|
use Incoviba\Exception\ServiceAction\Read;
|
2023-07-24 20:55:26 -04:00
|
|
|
use Incoviba\Repository;
|
2023-07-28 16:22:20 -04:00
|
|
|
use Incoviba\Model;
|
2023-07-24 20:55:26 -04:00
|
|
|
|
|
|
|
class Precio
|
|
|
|
{
|
|
|
|
public function __construct(protected Repository\Venta\Precio $precioRepository, protected Repository\Venta\EstadoPrecio $estadoPrecioRepository) {}
|
|
|
|
|
2025-03-03 14:57:22 -03:00
|
|
|
/**
|
|
|
|
* @param int $proyecto_id
|
|
|
|
* @return array
|
|
|
|
* @throws Read
|
|
|
|
*/
|
2023-07-24 20:55:26 -04:00
|
|
|
public function getByProyecto(int $proyecto_id): array
|
|
|
|
{
|
2025-03-03 14:57:22 -03:00
|
|
|
try {
|
|
|
|
$precios = $this->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 Read(__CLASS__, $exception);
|
2023-07-24 20:55:26 -04:00
|
|
|
}
|
|
|
|
}
|
2025-03-03 14:57:22 -03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $unidad_id
|
|
|
|
* @return Model\Venta\Precio
|
|
|
|
* @throws Read
|
|
|
|
*/
|
2023-08-08 23:53:49 -04:00
|
|
|
public function getVigenteByUnidad(int $unidad_id): Model\Venta\Precio
|
2023-07-28 16:22:20 -04:00
|
|
|
{
|
2025-03-03 14:57:22 -03:00
|
|
|
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 Read(__CLASS__, $exception);
|
|
|
|
}
|
2023-07-28 16:22:20 -04:00
|
|
|
}
|
2025-03-03 14:57:22 -03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $unidad_id
|
|
|
|
* @return array
|
|
|
|
* @throws Read
|
|
|
|
*/
|
2023-08-08 23:53:49 -04:00
|
|
|
public function getByUnidad(int $unidad_id): array
|
|
|
|
{
|
2025-03-03 14:57:22 -03:00
|
|
|
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 Read(__CLASS__, $exception);
|
2023-08-08 23:53:49 -04:00
|
|
|
}
|
|
|
|
}
|
2023-07-24 20:55:26 -04:00
|
|
|
}
|