Se agregan los campos por segmento
This commit is contained in:
@ -27,25 +27,7 @@ class Producto extends Model {
|
||||
}
|
||||
$this->valor = number_format($valor, 0, ',', '.');
|
||||
}
|
||||
public function tamaños(int $min = -1, int $max = -1) {
|
||||
if ($min == -1) {
|
||||
return $this->tamaños;
|
||||
}
|
||||
if ($max == -1) {
|
||||
$max = $min;
|
||||
}
|
||||
$this->tamaños = $min . ' - ' . $max . ' m²';
|
||||
}
|
||||
public function entrega(\DataTime $fecha = null) {
|
||||
if ($fecha === null) {
|
||||
return Carbon::parse(implode('-', array_reverse(explode('/', $this->entrega))) . '-01');
|
||||
}
|
||||
$this->entrega = $fecha->format('%m/%Y');
|
||||
}
|
||||
public function publicacion(\DateTime $fecha = null) {
|
||||
if ($fecha === null) {
|
||||
return Carbon::parse($this->publicacion);
|
||||
}
|
||||
public function setPublicacion(\DateTime $fecha) {
|
||||
$this->publicacion = implode(' ', [
|
||||
$fecha->day,
|
||||
'de',
|
||||
@ -53,6 +35,9 @@ class Producto extends Model {
|
||||
$fecha->year
|
||||
]);
|
||||
}
|
||||
public function getPublicacion() {
|
||||
return Carbon::parse($this->publicacion);
|
||||
}
|
||||
protected $destacado;
|
||||
public function destacado(bool $destacado = null) {
|
||||
if ($destacado === null) {
|
||||
@ -140,35 +125,40 @@ class Producto extends Model {
|
||||
$this->direccion = new Direccion();
|
||||
$this->direccion->map($data);
|
||||
$this->valor($data->valor);
|
||||
$this->bono = $data->bono;
|
||||
$this->rentabilidad = $data->rentabilidad;
|
||||
$this->cuota = $data->cuota;
|
||||
$this->entrega = $data->entrega;
|
||||
$this->estado = $data->estado;
|
||||
$this->unidades = $data->unidades;
|
||||
$this->modelos = $data->modelos;
|
||||
$this->tamaños = $data->tamaños;
|
||||
$this->descripcion = $data->descripcion;
|
||||
$this->publicacion = $data->publicacion;
|
||||
foreach ($this->properties as $property) {
|
||||
$this->$property = $data->$property ?? '';
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
public function __get(string $name) {
|
||||
if (method_exists($this, $name)) {
|
||||
return $this->$name();
|
||||
}
|
||||
if (!property_exists($this, $name) and array_search($name, $this->properties) === false) {
|
||||
throw new \InvalidArgumentException($name . ' no es una propiedad de ' . get_called_class());
|
||||
}
|
||||
return $this->$name;
|
||||
}
|
||||
public function __set(string $name, $value) {
|
||||
if (!property_exists($this, $name) and array_search($name, $this->properties) === false) {
|
||||
throw new \InvalidArgumentException($name . ' no es una propiedad de ' . get_called_class());
|
||||
}
|
||||
$this->$name = $value;
|
||||
}
|
||||
public function jsonSerialize() {
|
||||
$arr = [
|
||||
'id' => $this->id,
|
||||
'nombre' => $this->nombre,
|
||||
'segmento' => $this->segmento,
|
||||
'valor' => $this->valor,
|
||||
'bono' => $this->bono,
|
||||
'rentabilidad' => $this->rentabilidad,
|
||||
'cuota' => $this->cuota,
|
||||
'entrega' => $this->entrega,
|
||||
'estado' => $this->estado,
|
||||
'unidades' => $this->unidades,
|
||||
'modelos' => $this->modelos,
|
||||
'tamaños' => $this->tamaños,
|
||||
'descripcion' => $this->descripcion,
|
||||
'publicacion' => $this->publicacion
|
||||
];
|
||||
foreach ($this->properties as $property) {
|
||||
$arr[$property] = $this->$property;
|
||||
}
|
||||
$arr = array_merge($arr, $this->direccion->jsonSerialize());
|
||||
return $arr;
|
||||
}
|
||||
@ -230,4 +220,15 @@ class Producto extends Model {
|
||||
file_put_contents($filename, json_encode($destacados));
|
||||
}
|
||||
}
|
||||
public function getProperties(): array {
|
||||
$properties = [];
|
||||
foreach ($this->properties as $property) {
|
||||
$p = (object) [
|
||||
'label' => ucwords($property),
|
||||
'name' => $property
|
||||
];
|
||||
$properties []= $p;
|
||||
}
|
||||
return $properties;
|
||||
}
|
||||
}
|
||||
|
61
src/Productos/Bodega.php
Normal file
61
src/Productos/Bodega.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
namespace ProVM\KI\Productos;
|
||||
|
||||
use ProVM\KI\Producto;
|
||||
|
||||
class Bodega extends Producto {
|
||||
protected $properties = [
|
||||
'modulo',
|
||||
'tamaño',
|
||||
'oficina',
|
||||
'superficie',
|
||||
'arriendo'
|
||||
];
|
||||
|
||||
public function uf_m2() {
|
||||
return $this->arriendo / $this->superficie;
|
||||
}
|
||||
public function getFicha(): array {
|
||||
$properties = [
|
||||
[
|
||||
'label' => 'Superficie',
|
||||
'name' => 'superficie',
|
||||
'suffix' => ' m²'
|
||||
],
|
||||
[
|
||||
'label' => 'Valor Arriendo',
|
||||
'name' => 'arriendo',
|
||||
'suffix' => ' UF'
|
||||
],
|
||||
[
|
||||
'label' => 'UF/m²',
|
||||
'name' => 'uf_m2'
|
||||
]
|
||||
];
|
||||
array_walk($properties, function(&$item) {
|
||||
$item['suffix'] = $item['suffix'] ?? '';
|
||||
$item = (object) $item;
|
||||
});
|
||||
return $properties;
|
||||
}
|
||||
public function getShow(): array {
|
||||
$data = $this->getFicha();
|
||||
$data []= (object) [
|
||||
'label' => 'Modulo',
|
||||
'name' => 'modulo'
|
||||
];
|
||||
$data []= (object) [
|
||||
'label' => 'Oficina',
|
||||
'name' => 'oficina'
|
||||
];
|
||||
$data []= (object) [
|
||||
'label' => 'Tamaño',
|
||||
'name' => 'tamaño',
|
||||
'suffix' => ' m²'
|
||||
];
|
||||
array_walk($data, function(&$item) {
|
||||
$item->suffix = $item->suffix ?? '';
|
||||
});
|
||||
return $data;
|
||||
}
|
||||
}
|
67
src/Productos/Oficina.php
Normal file
67
src/Productos/Oficina.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace ProVM\KI\Productos;
|
||||
|
||||
use ProVM\KI\Producto;
|
||||
|
||||
class Oficina extends Producto {
|
||||
protected $properties = [
|
||||
'arriendo',
|
||||
'm2',
|
||||
'baños',
|
||||
'privados',
|
||||
'gastos'
|
||||
];
|
||||
|
||||
public function uf_m2() {
|
||||
return $this->arriendo / $this->m2;
|
||||
}
|
||||
public function privados() {
|
||||
if ($this->privados == 0) {
|
||||
return 'planta libre';
|
||||
}
|
||||
return 'privados ' . $this->privados;
|
||||
}
|
||||
public function getFicha(): array {
|
||||
$properties = [
|
||||
[
|
||||
'label' => 'Valor Arriendo',
|
||||
'name' => 'arriendo',
|
||||
'suffix' => ' UF'
|
||||
],
|
||||
[
|
||||
'label' => 'Superficie',
|
||||
'name' => 'm2',
|
||||
'suffix' => ' m²'
|
||||
],
|
||||
[
|
||||
'label' => 'Baños',
|
||||
'name' => 'baños'
|
||||
],
|
||||
[
|
||||
'label' => 'Privados',
|
||||
'name' => 'privados'
|
||||
]
|
||||
];
|
||||
array_walk($properties, function(&$item) {
|
||||
$item['suffix'] = $item['suffix'] ?? '';
|
||||
$item = (object) $item;
|
||||
});
|
||||
return $properties;
|
||||
}
|
||||
public function getShow() {
|
||||
$data = $this->getFicha();
|
||||
$data []= (object) [
|
||||
'label' => 'Gastos Comunes',
|
||||
'name' => 'gastos',
|
||||
'suffix' => ' UF'
|
||||
];
|
||||
$data []= (object) [
|
||||
'label' => 'UF/m²',
|
||||
'name' => 'uf_m2'
|
||||
];
|
||||
array_walk($data, function(&$item) {
|
||||
$item->suffix = $item->suffix ?? '';
|
||||
});
|
||||
return $data;
|
||||
}
|
||||
}
|
148
src/Productos/Retail.php
Normal file
148
src/Productos/Retail.php
Normal file
@ -0,0 +1,148 @@
|
||||
<?php
|
||||
namespace ProVM\KI\Productos;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use ProVM\KI\Producto;
|
||||
|
||||
class Retail extends Producto {
|
||||
protected $properties = [
|
||||
'bono',
|
||||
'rentabilidad',
|
||||
'cuota',
|
||||
'entrega',
|
||||
'estado',
|
||||
'unidades',
|
||||
'modelos',
|
||||
'tamaños'
|
||||
];
|
||||
|
||||
public function setTamaños(int $min, int $max = -1) {
|
||||
if ($max == -1) {
|
||||
$max = $min;
|
||||
}
|
||||
$this->tamaños = $min . ' - ' . $max . ' m²';
|
||||
}
|
||||
public function getTamaños() {
|
||||
return $this->tamaños;
|
||||
}
|
||||
public function setEntrega(\DataTime $fecha) {
|
||||
$this->entrega = $fecha->format('%m/%Y');
|
||||
}
|
||||
public function getEntrega() {
|
||||
return Carbon::parse(implode('-', array_reverse(explode('/', $this->entrega))) . '-01');
|
||||
}
|
||||
public function getDireccion() {
|
||||
return implode(', ', [
|
||||
$this->direccion->calle,
|
||||
$this->direccion->comuna ?? '',
|
||||
$this->direccion->ciudad ?? ''
|
||||
]);
|
||||
}
|
||||
public function getProperties(): array {
|
||||
$properties = [];
|
||||
$properties []= (object) [
|
||||
'label' => 'Bono Pie en UF',
|
||||
'name' => 'bono'
|
||||
];
|
||||
$properties []= (object) [
|
||||
'label' => 'Rentabilidad %',
|
||||
'name' => 'rentabilidad'
|
||||
];
|
||||
$properties []= (object) [
|
||||
'label' => 'Valor Cuota en UF',
|
||||
'name' => 'cuota'
|
||||
];
|
||||
$properties []= (object) [
|
||||
'label' => 'Entrega Estimada',
|
||||
'name' => 'entrega'
|
||||
];
|
||||
$properties []= (object) [
|
||||
'label' => 'Estado',
|
||||
'name' => 'estado'
|
||||
];
|
||||
$properties []= (object) [
|
||||
'label' => 'Unidades',
|
||||
'name' => 'unidades'
|
||||
];
|
||||
$properties []= (object) [
|
||||
'label' => 'Modelos',
|
||||
'name' => 'modelos'
|
||||
];
|
||||
$properties []= (object) [
|
||||
'label' => 'Tamaños',
|
||||
'name' => 'tamaños'
|
||||
];
|
||||
return $properties;
|
||||
}
|
||||
public function getFicha(): array {
|
||||
$properties = [
|
||||
[
|
||||
'label' => 'Valor Depto',
|
||||
'name' => 'valor',
|
||||
'suffix' => ' UF'
|
||||
],
|
||||
[
|
||||
'label' => 'Bono Pie',
|
||||
'name' => 'bono',
|
||||
'suffix' => ' UF'
|
||||
],
|
||||
[
|
||||
'label' => 'Rentabilidad',
|
||||
'name' => 'rentabilidad',
|
||||
'suffix' => '%'
|
||||
],
|
||||
[
|
||||
'label' => 'Valor Cuota',
|
||||
'name' => 'cuota',
|
||||
'suffix' => ' UF'
|
||||
],
|
||||
[
|
||||
'label' => 'Entrega Estimada',
|
||||
'name' => 'entrega'
|
||||
]
|
||||
];
|
||||
array_walk($properties, function(&$item) {
|
||||
$item['suffix'] = $item['suffix'] ?? '';
|
||||
$item = (object) $item;
|
||||
});
|
||||
return $properties;
|
||||
}
|
||||
public function getShow() {
|
||||
$properties = [
|
||||
[
|
||||
'label' => 'Precio',
|
||||
'name' => 'valor',
|
||||
'suffix' => ' UF'
|
||||
],
|
||||
[
|
||||
'label' => 'Estado',
|
||||
'name' => 'estado'
|
||||
],
|
||||
[
|
||||
'label' => 'Tipo',
|
||||
'name' => 'segmento'
|
||||
],
|
||||
[
|
||||
'label' => 'Ubicación',
|
||||
'name' => 'getDireccion'
|
||||
],
|
||||
[
|
||||
'label' => 'Unidades',
|
||||
'name' => 'unidades'
|
||||
],
|
||||
[
|
||||
'label' => 'Modelos',
|
||||
'name' => 'modelos'
|
||||
],
|
||||
[
|
||||
'label' => 'Tamaño',
|
||||
'name' => 'tamaños'
|
||||
]
|
||||
];
|
||||
array_walk($properties, function(&$item) {
|
||||
$item['suffix'] = $item['suffix'] ?? '';
|
||||
$item = (object) $item;
|
||||
});
|
||||
return $properties;
|
||||
}
|
||||
}
|
39
src/Productos/Terreno.php
Normal file
39
src/Productos/Terreno.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace ProVM\KI\Productos;
|
||||
|
||||
use ProVM\KI\Producto;
|
||||
|
||||
class Terreno extends Producto {
|
||||
protected $properties = [
|
||||
'sector',
|
||||
'delimitacion',
|
||||
'superficie'
|
||||
];
|
||||
|
||||
public function getFicha(): array {
|
||||
$properties = [
|
||||
[
|
||||
'label' => 'Sector',
|
||||
'name' => 'sector'
|
||||
],
|
||||
[
|
||||
'label' => 'Valor Total',
|
||||
'name' => 'valor',
|
||||
'suffix' => ' UF'
|
||||
],
|
||||
[
|
||||
'label' => 'Superficie',
|
||||
'name' => 'superficie',
|
||||
'suffix' => ' m²'
|
||||
]
|
||||
];
|
||||
array_walk($properties, function(&$item) {
|
||||
$item['suffix'] = $item['suffix'] ?? '';
|
||||
$item = (object) $item;
|
||||
});
|
||||
return $properties;
|
||||
}
|
||||
public function getShow() {
|
||||
return $this->getFicha();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user