Files
oficial/app/src/Service/Venta/Precio.php

68 lines
2.2 KiB
PHP
Raw Normal View History

<?php
namespace Incoviba\Service\Venta;
2025-03-03 14:57:22 -03:00
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Exception\ServiceAction\Read;
use Incoviba\Repository;
2023-07-28 16:22:20 -04:00
use Incoviba\Model;
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
*/
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);
}
}
2025-03-03 14:57:22 -03:00
/**
* @param int $unidad_id
* @return Model\Venta\Precio
* @throws Read
*/
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
*/
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);
}
}
}