diff --git a/resources/views/productos/producto/ficha.blade.php b/resources/views/productos/producto/ficha.blade.php
new file mode 100644
index 0000000..f259cb7
--- /dev/null
+++ b/resources/views/productos/producto/ficha.blade.php
@@ -0,0 +1,10 @@
+@foreach ($producto->getShow() as $property)
+
+
+ {{$property->label}}:
+
+
+ {{$producto->{$property->name} ?? ''}}{{$property->suffix}}
+
+
+@endforeach
diff --git a/src/Producto.php b/src/Producto.php
index 4b8c257..407950a 100644
--- a/src/Producto.php
+++ b/src/Producto.php
@@ -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;
+ }
}
diff --git a/src/Productos/Bodega.php b/src/Productos/Bodega.php
new file mode 100644
index 0000000..6e47854
--- /dev/null
+++ b/src/Productos/Bodega.php
@@ -0,0 +1,61 @@
+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;
+ }
+}
diff --git a/src/Productos/Oficina.php b/src/Productos/Oficina.php
new file mode 100644
index 0000000..3a6f098
--- /dev/null
+++ b/src/Productos/Oficina.php
@@ -0,0 +1,67 @@
+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;
+ }
+}
diff --git a/src/Productos/Retail.php b/src/Productos/Retail.php
new file mode 100644
index 0000000..4bf4b4a
--- /dev/null
+++ b/src/Productos/Retail.php
@@ -0,0 +1,148 @@
+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;
+ }
+}
diff --git a/src/Productos/Terreno.php b/src/Productos/Terreno.php
new file mode 100644
index 0000000..8a3eefc
--- /dev/null
+++ b/src/Productos/Terreno.php
@@ -0,0 +1,39 @@
+ '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();
+ }
+}