50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
![]() |
<?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,
|
||
|
protected Service\Venta\Precio $precioService
|
||
|
) {}
|
||
|
|
||
|
public function getById(int $unidad_id): Model\Venta\Unidad
|
||
|
{
|
||
|
$unidad = $this->unidadRepository->fetchById($unidad_id);
|
||
|
$this->fillPrecios($unidad);
|
||
|
return $unidad;
|
||
|
}
|
||
|
public function getByPropiedad(int $propiedad_id): array
|
||
|
{
|
||
|
$unidades = $this->unidadRepository->fetchByPropiedad($propiedad_id);
|
||
|
array_walk($unidades, [$this, 'fillPrecios']);
|
||
|
return $unidades;
|
||
|
}
|
||
|
public function getByCierre(int $cierre_id): array
|
||
|
{
|
||
|
$unidades = $this->unidadRepository->fetchByCierre($cierre_id);
|
||
|
array_walk($unidades, [$this, 'fillPrecios']);
|
||
|
return $unidades;
|
||
|
}
|
||
|
public function getDisponiblesByProyecto(int $proyecto_id): array
|
||
|
{
|
||
|
$unidades = $this->unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
|
||
|
//array_walk($unidades, [$this, 'fillPrecios']);
|
||
|
return $unidades;
|
||
|
}
|
||
|
|
||
|
protected function fillPrecios(&$unidad): void
|
||
|
{
|
||
|
try {
|
||
|
$unidad->precios = $this->precioService->getByUnidad($unidad->id);
|
||
|
$unidad->currentPrecio = $this->precioService->getVigenteByUnidad($unidad->id);
|
||
|
} catch (EmptyResult) {
|
||
|
}
|
||
|
}
|
||
|
}
|