2023-08-08 23:53:49 -04:00
|
|
|
<?php
|
|
|
|
namespace Incoviba\Service\Venta;
|
|
|
|
|
|
|
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
|
|
|
use Incoviba\Repository;
|
|
|
|
use Incoviba\Service;
|
|
|
|
use Incoviba\Model;
|
|
|
|
|
|
|
|
class Unidad
|
|
|
|
{
|
|
|
|
public function __construct(
|
|
|
|
protected Repository\Venta\Unidad $unidadRepository,
|
2023-11-29 20:09:08 -03:00
|
|
|
protected Precio $precioService
|
2023-08-08 23:53:49 -04:00
|
|
|
) {}
|
|
|
|
|
|
|
|
public function getById(int $unidad_id): Model\Venta\Unidad
|
|
|
|
{
|
2023-11-22 19:08:19 -03:00
|
|
|
return $this->process($this->unidadRepository->fetchById($unidad_id));
|
|
|
|
}
|
|
|
|
public function getByVenta(int $venta_id): array
|
|
|
|
{
|
|
|
|
return array_map([$this, 'process'], $this->unidadRepository->fetchByVenta($venta_id));
|
2023-08-08 23:53:49 -04:00
|
|
|
}
|
|
|
|
public function getByPropiedad(int $propiedad_id): array
|
|
|
|
{
|
2023-11-22 19:08:19 -03:00
|
|
|
return array_map([$this, 'process'], $this->unidadRepository->fetchByPropiedad($propiedad_id));
|
2023-08-08 23:53:49 -04:00
|
|
|
}
|
|
|
|
public function getByCierre(int $cierre_id): array
|
|
|
|
{
|
2023-11-22 19:08:19 -03:00
|
|
|
return array_map([$this, 'process'], $this->unidadRepository->fetchByCierre($cierre_id));
|
2023-08-08 23:53:49 -04:00
|
|
|
}
|
|
|
|
public function getDisponiblesByProyecto(int $proyecto_id): array
|
|
|
|
{
|
2023-11-22 19:08:19 -03:00
|
|
|
return $this->unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
|
2023-08-08 23:53:49 -04:00
|
|
|
}
|
2024-02-28 21:44:37 -03:00
|
|
|
public function getByIdForSearch(int $unidad_id): array
|
|
|
|
{
|
|
|
|
return $this->unidadRepository->fetchByIdForSearch($unidad_id);
|
|
|
|
}
|
2023-08-08 23:53:49 -04:00
|
|
|
|
2023-11-22 19:08:19 -03:00
|
|
|
protected function process($unidad): Model\Venta\Unidad
|
2023-08-08 23:53:49 -04:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
$unidad->precios = $this->precioService->getByUnidad($unidad->id);
|
|
|
|
$unidad->currentPrecio = $this->precioService->getVigenteByUnidad($unidad->id);
|
|
|
|
} catch (EmptyResult) {
|
|
|
|
}
|
2023-11-22 19:08:19 -03:00
|
|
|
return $unidad;
|
2023-08-08 23:53:49 -04:00
|
|
|
}
|
|
|
|
}
|