75 lines
2.4 KiB
PHP
75 lines
2.4 KiB
PHP
<?php
|
|
namespace Incoviba\Model\Venta;
|
|
|
|
use Incoviba\Common\Ideal;
|
|
use Incoviba\Model;
|
|
|
|
class Propiedad extends Ideal\Model
|
|
{
|
|
public array $unidades;
|
|
|
|
protected array $departamentos;
|
|
public function departamentos(): array
|
|
{
|
|
if (!isset($this->departamentos)) {
|
|
$this->departamentos = array_values(array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'departamento';}));
|
|
}
|
|
return $this->departamentos;
|
|
}
|
|
protected array $estacionamientos;
|
|
public function estacionamientos(): array
|
|
{
|
|
if (!isset($this->estacionamientos)) {
|
|
$this->estacionamientos = array_values(array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'estacionamiento';}));
|
|
}
|
|
return $this->estacionamientos;
|
|
}
|
|
protected array $bodegas;
|
|
public function bodegas(): array
|
|
{
|
|
if (!isset($this->bodegas)) {
|
|
$this->bodegas = array_values(array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'bodega';}));
|
|
}
|
|
return $this->bodegas;
|
|
}
|
|
|
|
public function proyecto(): Model\Proyecto
|
|
{
|
|
return $this->unidades[0]->proyectoTipoUnidad->proyecto;
|
|
}
|
|
|
|
protected float $vendible;
|
|
public function vendible(): float
|
|
{
|
|
return array_reduce($this->departamentos(), function(float $sum, Unidad $unidad) {
|
|
return $sum + $unidad->proyectoTipoUnidad->vendible();
|
|
}, 0);
|
|
}
|
|
|
|
public function summary(): string
|
|
{
|
|
return implode(' - ', array_merge(
|
|
array_map(function(Unidad $unidad) {
|
|
return $unidad->descripcion;
|
|
}, $this->departamentos()),
|
|
array_map(function(Unidad $unidad) {
|
|
return "E{$unidad->descripcion}";
|
|
}, $this->estacionamientos()),
|
|
array_map(function(Unidad $unidad) {
|
|
return "B{$unidad->descripcion}";
|
|
}, $this->bodegas())
|
|
));
|
|
}
|
|
|
|
public function jsonSerialize(): mixed
|
|
{
|
|
return [
|
|
'unidades' => $this->unidades,
|
|
'departamentos' => $this->departamentos(),
|
|
'estacionamientos' => $this->estacionamientos(),
|
|
'bodegas' => $this->bodegas(),
|
|
'summary' => $this->summary()
|
|
];
|
|
}
|
|
}
|