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

51 lines
1.6 KiB
PHP
Raw Normal View History

<?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
) {}
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));
}
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));
}
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));
}
public function getDisponiblesByProyecto(int $proyecto_id): array
{
2023-11-22 19:08:19 -03:00
return $this->unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
}
2024-02-28 21:44:37 -03:00
public function getByIdForSearch(int $unidad_id): array
{
return $this->unidadRepository->fetchByIdForSearch($unidad_id);
}
2023-11-22 19:08:19 -03:00
protected function process($unidad): Model\Venta\Unidad
{
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;
}
}