Se agregan los campos por segmento
This commit is contained in:
@ -61,7 +61,8 @@ class Productos {
|
||||
'segmentos.json'
|
||||
]);
|
||||
$segmentos = json_decode(trim(file_get_contents($filename)));
|
||||
return $view->render($response, 'admin.producto', compact('producto', 'segmentos'));
|
||||
$properties = $producto->getProperties();
|
||||
return $view->render($response, 'admin.producto', compact('producto', 'segmentos', 'properties'));
|
||||
}
|
||||
public function do_edit(Request $request, Response $response, Container $container, ModelFactory $factory, $producto): Response {
|
||||
$post = $request->getParsedBody();
|
||||
@ -92,15 +93,6 @@ class Productos {
|
||||
$producto->tamaño = $tamaño;
|
||||
$changed = true;
|
||||
}*/
|
||||
if (isset($post['destacado']) and $post['destacado'] == 'on') {
|
||||
$producto->destacado(true);
|
||||
}
|
||||
$post['tamaños'] = implode(' ', [
|
||||
$post['tamaño_min'],
|
||||
'-',
|
||||
$post['tamaño_max'],
|
||||
'm²'
|
||||
]);
|
||||
$f = Carbon::today();
|
||||
$post['publicacion'] = $producto->publicacion ?? implode(' ', [
|
||||
$f->day,
|
||||
@ -346,4 +338,24 @@ class Productos {
|
||||
]);
|
||||
return $response;
|
||||
}
|
||||
public function fields(Request $request, Response $response): Response {
|
||||
$post = $request->getParsedBody();
|
||||
$class = implode("\\", [
|
||||
'ProVM',
|
||||
'KI',
|
||||
'Productos',
|
||||
$post['segmento']
|
||||
]);
|
||||
$obj = new $class;
|
||||
$properties = $obj->getProperties();
|
||||
|
||||
$output = [
|
||||
'information' => $post,
|
||||
'fields' => $properties
|
||||
];
|
||||
$response->getBody()->write(json_encode($output, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE));
|
||||
return $response
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->withStatus(201);
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ class Productos {
|
||||
}
|
||||
public function ficha(Request $request, Response $response, View $view, ModelFactory $factory, $producto): Response {
|
||||
$producto = $factory->find(Producto::class)->where([['id', $producto]])->one();
|
||||
return $view->render($response, 'productos.ficha', compact('producto'));
|
||||
$properties = $producto->getFicha();
|
||||
return $view->render($response, 'productos.ficha', compact('producto', 'properties'));
|
||||
}
|
||||
}
|
||||
|
@ -114,7 +114,15 @@ class Model {
|
||||
return $data;
|
||||
}
|
||||
protected function fillObject($data): BaseModel {
|
||||
$obj = new $this->class;
|
||||
$class = $this->class;
|
||||
if (strpos($class, 'Producto') !== false) {
|
||||
$segmento = str_replace(' ', '', $data->segmento);
|
||||
$class = implode("\\", [
|
||||
$class . 's',
|
||||
rtrim($segmento, 's')
|
||||
]);
|
||||
}
|
||||
$obj = new $class;
|
||||
$obj->map($data);
|
||||
$obj->setFactory($this);
|
||||
$obj->setImageFolder($this->image_folder);
|
||||
@ -139,6 +147,13 @@ class Model {
|
||||
}
|
||||
|
||||
public function create(string $class, $data) {
|
||||
if (strpos($class, 'Producto') !== false) {
|
||||
$segmento = str_replace(' ', '', $data->segmento);
|
||||
$class = implode("\\", [
|
||||
$class . 's',
|
||||
rtrim($segmento, 's')
|
||||
]);
|
||||
}
|
||||
$obj = new $class;
|
||||
$obj->map($data);
|
||||
$obj->setFactory($this);
|
||||
|
@ -47,9 +47,14 @@ abstract class Model implements \JsonSerializable {
|
||||
protected function getFilename(): string {
|
||||
$data = explode("\\", get_called_class());
|
||||
$folder = $this->factory->getFolder();
|
||||
$class = array_pop($data);
|
||||
$productos = ['Bodega', 'Oficina', 'Retail', 'Terreno'];
|
||||
if (array_search($class, $productos) !== false) {
|
||||
$class = 'Producto';
|
||||
}
|
||||
return implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
str_replace(' ', '_', mb_strtolower(array_pop($data))) . 's.json'
|
||||
str_replace(' ', '_', mb_strtolower($class)) . 's.json'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -49,32 +49,6 @@
|
||||
<input type="text" name="valor" value="{{str_replace('.', '', $producto->valor ?? '')}}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label>Bono Pie en UF</label>
|
||||
<input type="text" name="bono" value="{{$producto->bono ?? ''}}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label>Rentabilidad %</label>
|
||||
<input type="text" name="rentabilidad" value="{{$producto->rentabilidad ?? ''}}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label>Valor Cuota en UF</label>
|
||||
<input type="text" name="cuota" value="{{$producto->cuota ?? ''}}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label>Entrega Estimada</label>
|
||||
<div class="ui calendar">
|
||||
<input type="text" name="entrega" placeholder="Entrega" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label>Destacado</label>
|
||||
@ -83,36 +57,16 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label>Estado</label>
|
||||
<input type="text" name="estado" value="{{$producto->estado ?? ''}}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label>Unidades</label>
|
||||
<input type="text" name="unidades" value="{{$producto->unidades ?? ''}}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label>Modelos</label>
|
||||
<input type="text" name="modelos" value="{{$producto->modelos ?? ''}}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="fields">
|
||||
<span id="campos"></span>
|
||||
@foreach ($properties as $property)
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label>Tamaño Mínimo</label>
|
||||
<input type="text" name="tamaño_min" value="{{(property_exists($producto, 'tamaños') and is_array($producto->tamaños)) ? explode(' - ', rtrim($producto->tamaños, ' m²'))[0] : ''}}" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Tamaño Máximo</label>
|
||||
<input type="text" name="tamaño_max" value="{{(property_exists($producto, 'tamaños') and is_array($producto->tamaños)) ? explode(' - ', rtrim($producto->tamaños, ' m²'))[1] : ''}}" />
|
||||
<label>{{$property->label}}</label>
|
||||
<input type="text" name="{{$property->name}}" value="{{$producto->{$property->name} ?? ''}}" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
<span id="end_campos"></span>
|
||||
<div class="ten wide column">
|
||||
<div class="field">
|
||||
<label>Descripción</label>
|
||||
@ -263,6 +217,31 @@
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
changeSegmento: () => {
|
||||
var segmento = $('#segmento').dropdown('get value')
|
||||
var url = '{{$urls->admin}}/productos/campos'
|
||||
$.post(url, {segmento: segmento}, (data) => {
|
||||
var div = $('#campos')
|
||||
var end = $('#end_campos')
|
||||
var current = div.next()
|
||||
var next = current.next()
|
||||
while (next != end) {
|
||||
current.remove()
|
||||
current = next
|
||||
next = next.next()
|
||||
}
|
||||
$.each(data.fields, (i, el) => {
|
||||
var campo = $('<div></div>').attr('class', 'column').append(
|
||||
$('<div></div>').attr('class', 'field').append(
|
||||
$('<label></label>').html(el.label)
|
||||
).append(
|
||||
$('<input />').attr('type', 'text').attr('name', el.name)
|
||||
)
|
||||
)
|
||||
end.before(campo)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
|
@ -31,7 +31,7 @@
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label>Segmento</label>
|
||||
<div class="ui selection dropdown">
|
||||
<div class="ui selection dropdown" id="segmento">
|
||||
<input type="hidden" name="segmento" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Segmento</div>
|
||||
@ -50,6 +50,23 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label>Destacado</label>
|
||||
<div class="ui toggle checkbox">
|
||||
<input type="checkbox" name="destacado" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="campos"></div>
|
||||
@foreach ($properties as $property)
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label>{{$property->label}}</label>
|
||||
<input type="text" name="{{$property->name}}" />
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
<!-- <div class="column">
|
||||
<div class="field">
|
||||
<label>Bono Pie en UF</label>
|
||||
<input type="text" name="bono" />
|
||||
@ -75,14 +92,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label>Destacado</label>
|
||||
<div class="ui toggle checkbox">
|
||||
<input type="checkbox" name="destacado" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label>Estado</label>
|
||||
@ -112,7 +121,7 @@
|
||||
<input type="text" name="tamaño_max" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
<div class="ten wide column">
|
||||
<div class="field">
|
||||
<label>Descripción</label>
|
||||
@ -152,7 +161,7 @@
|
||||
},
|
||||
setup: () => {
|
||||
producto.setMonths()
|
||||
$('.selection.dropdown').dropdown()
|
||||
$('#segmento').dropdown()
|
||||
$('.calendar').calendar({
|
||||
type: 'month',
|
||||
text: {
|
||||
@ -165,6 +174,22 @@
|
||||
}
|
||||
})
|
||||
$('.checkbox').checkbox()
|
||||
},
|
||||
changeSegmento: () => {
|
||||
var segmento = $('#segmento').dropdown('get value')
|
||||
var url = '{{$urls->admin}}/productos/campos'
|
||||
$.post(url, {segmento: segmento}, (data) => {
|
||||
var div = $('#campos')
|
||||
$.each(data.fields, (i, el) => {
|
||||
var campo = $('<div></div>').attr('class', 'column').append(
|
||||
$('<div></div>').attr('class', 'field').append(
|
||||
$('<label></label>').html(el.label)
|
||||
).append(
|
||||
$('<input />').attr('type', 'text').attr('name', el.name)
|
||||
)
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
|
@ -17,7 +17,15 @@
|
||||
<img src="{{$urls->images}}/{{$producto->imagen()}}" />
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="ui basic segment">
|
||||
@foreach ($properties as $property)
|
||||
<div class="ui basic segment">
|
||||
<span class="right floated">
|
||||
{{$producto->{$property->name} }}{{$property->suffix}}
|
||||
</span>
|
||||
{{$property->label}}
|
||||
</div>
|
||||
@endforeach
|
||||
<!-- <div class="ui basic segment">
|
||||
<span class="right floated">
|
||||
{{$producto->valor()}} UF
|
||||
</span>
|
||||
@ -46,7 +54,7 @@
|
||||
{{$producto->entrega}}
|
||||
</span>
|
||||
Entrega Estimada
|
||||
</div>
|
||||
</div> -->
|
||||
<span class="right floated">
|
||||
<a href="{{$urls->base}}/producto/{{$producto->id}}">
|
||||
<button class="ui inverted brand button">
|
||||
|
@ -10,66 +10,7 @@
|
||||
<div class="ui grid">
|
||||
<div class="four wide column">
|
||||
<div class="ui two columns grid informacion">
|
||||
<div class="row">
|
||||
<div class="column">
|
||||
Precio:
|
||||
</div>
|
||||
<div class="column">
|
||||
{{$producto->valor() ?? ''}} UF
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="column">
|
||||
Estado:
|
||||
</div>
|
||||
<div class="column">
|
||||
{{$producto->estado ?? ''}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="column">
|
||||
Tipo:
|
||||
</div>
|
||||
<div class="column">
|
||||
{{$producto->segmento ?? ''}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="column">
|
||||
Ubicación:
|
||||
</div>
|
||||
<div class="column">
|
||||
{{implode(', ', [
|
||||
$producto->direccion->calle,
|
||||
$producto->direccion->comuna ?? '',
|
||||
$producto->direccion->ciudad ?? ''
|
||||
])}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="column">
|
||||
Unidades:
|
||||
</div>
|
||||
<div class="column">
|
||||
{{$producto->unidades ?? ''}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="column">
|
||||
Modelos:
|
||||
</div>
|
||||
<div class="column">
|
||||
{{$producto->modelos ?? ''}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="column">
|
||||
Tamaño
|
||||
</div>
|
||||
<div class="column">
|
||||
{{$producto->tamaños ?? ''}}
|
||||
</div>
|
||||
</div>
|
||||
@include('productos.producto.ficha')
|
||||
</div>
|
||||
</div>
|
||||
<div class="twelve wide column">
|
||||
|
10
resources/views/productos/producto/ficha.blade.php
Normal file
10
resources/views/productos/producto/ficha.blade.php
Normal file
@ -0,0 +1,10 @@
|
||||
@foreach ($producto->getShow() as $property)
|
||||
<div class="row">
|
||||
<div class="column">
|
||||
{{$property->label}}:
|
||||
</div>
|
||||
<div class="column">
|
||||
{{$producto->{$property->name} ?? ''}}{{$property->suffix}}
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
@ -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