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

40 lines
1.4 KiB
PHP
Raw Normal View History

2023-11-29 20:09:08 -03:00
<?php
namespace Incoviba\Service\Venta;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Repository;
use Incoviba\Service;
use Incoviba\Model;
class PropiedadUnidad
{
public function __construct(protected Repository\Venta\PropiedadUnidad $propiedadUnidadRepository, protected Precio $precioService) {}
public function getById(int $unidad_id): Model\Venta\PropiedadUnidad
{
return $this->process($this->propiedadUnidadRepository->fetchById($unidad_id));
}
public function getByVenta(int $venta_id): array
{
return array_map([$this, 'process'], $this->propiedadUnidadRepository->fetchByVenta($venta_id));
}
public function getByPropiedad(int $propiedad_id): array
{
return array_map([$this, 'process'], $this->propiedadUnidadRepository->fetchByPropiedad($propiedad_id));
}
public function edit(Model\Venta\PropiedadUnidad $propiedadUnidad, array $data): Model\Venta\PropiedadUnidad
{
return $this->process($this->propiedadUnidadRepository->edit($propiedadUnidad, $data));
}
protected function process($unidad): Model\Venta\PropiedadUnidad
{
try {
$unidad->precios = $this->precioService->getByUnidad($unidad->id);
$unidad->currentPrecio = $this->precioService->getVigenteByUnidad($unidad->id);
} catch (EmptyResult) {
}
return $unidad;
}
}