Cleanup
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
@ -8,29 +10,58 @@ class Precio
|
||||
{
|
||||
public function __construct(protected Repository\Venta\Precio $precioRepository, protected Repository\Venta\EstadoPrecio $estadoPrecioRepository) {}
|
||||
|
||||
/**
|
||||
* @param int $proyecto_id
|
||||
* @return array
|
||||
* @throws Read
|
||||
*/
|
||||
public function getByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$precios = $this->precioRepository->fetchByProyecto($proyecto_id);
|
||||
foreach ($precios as &$precio) {
|
||||
$precio->estados = $this->estadoPrecioRepository->fetchByPrecio($precio->id);
|
||||
$precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id);
|
||||
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);
|
||||
}
|
||||
return $precios;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $unidad_id
|
||||
* @return Model\Venta\Precio
|
||||
* @throws Read
|
||||
*/
|
||||
public function getVigenteByUnidad(int $unidad_id): Model\Venta\Precio
|
||||
{
|
||||
$precio = $this->precioRepository->fetchVigenteByUnidad($unidad_id);
|
||||
$precio->estados = $this->estadoPrecioRepository->fetchByPrecio($precio->id);
|
||||
$precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id);
|
||||
return $precio;
|
||||
}
|
||||
public function getByUnidad(int $unidad_id): array
|
||||
{
|
||||
$precios = $this->precioRepository->fetchByUnidad($unidad_id);
|
||||
foreach ($precios as &$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 Read(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $unidad_id
|
||||
* @return array
|
||||
* @throws 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 Read(__CLASS__, $exception);
|
||||
}
|
||||
return $precios;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user