Se agregan los campos por segmento
This commit is contained in:
@ -61,7 +61,8 @@ class Productos {
|
|||||||
'segmentos.json'
|
'segmentos.json'
|
||||||
]);
|
]);
|
||||||
$segmentos = json_decode(trim(file_get_contents($filename)));
|
$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 {
|
public function do_edit(Request $request, Response $response, Container $container, ModelFactory $factory, $producto): Response {
|
||||||
$post = $request->getParsedBody();
|
$post = $request->getParsedBody();
|
||||||
@ -92,15 +93,6 @@ class Productos {
|
|||||||
$producto->tamaño = $tamaño;
|
$producto->tamaño = $tamaño;
|
||||||
$changed = true;
|
$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();
|
$f = Carbon::today();
|
||||||
$post['publicacion'] = $producto->publicacion ?? implode(' ', [
|
$post['publicacion'] = $producto->publicacion ?? implode(' ', [
|
||||||
$f->day,
|
$f->day,
|
||||||
@ -346,4 +338,24 @@ class Productos {
|
|||||||
]);
|
]);
|
||||||
return $response;
|
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 {
|
public function ficha(Request $request, Response $response, View $view, ModelFactory $factory, $producto): Response {
|
||||||
$producto = $factory->find(Producto::class)->where([['id', $producto]])->one();
|
$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;
|
return $data;
|
||||||
}
|
}
|
||||||
protected function fillObject($data): BaseModel {
|
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->map($data);
|
||||||
$obj->setFactory($this);
|
$obj->setFactory($this);
|
||||||
$obj->setImageFolder($this->image_folder);
|
$obj->setImageFolder($this->image_folder);
|
||||||
@ -139,6 +147,13 @@ class Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function create(string $class, $data) {
|
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 = new $class;
|
||||||
$obj->map($data);
|
$obj->map($data);
|
||||||
$obj->setFactory($this);
|
$obj->setFactory($this);
|
||||||
|
@ -47,9 +47,14 @@ abstract class Model implements \JsonSerializable {
|
|||||||
protected function getFilename(): string {
|
protected function getFilename(): string {
|
||||||
$data = explode("\\", get_called_class());
|
$data = explode("\\", get_called_class());
|
||||||
$folder = $this->factory->getFolder();
|
$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, [
|
return implode(DIRECTORY_SEPARATOR, [
|
||||||
$folder,
|
$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 ?? '')}}" />
|
<input type="text" name="valor" value="{{str_replace('.', '', $producto->valor ?? '')}}" />
|
||||||
</div>
|
</div>
|
||||||
</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="column">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Destacado</label>
|
<label>Destacado</label>
|
||||||
@ -83,36 +57,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="column">
|
<span id="campos"></span>
|
||||||
<div class="field">
|
@foreach ($properties as $property)
|
||||||
<label>Estado</label>
|
<div class="column">
|
||||||
<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">
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Tamaño Mínimo</label>
|
<label>{{$property->label}}</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] : ''}}" />
|
<input type="text" name="{{$property->name}}" value="{{$producto->{$property->name} ?? ''}}" />
|
||||||
</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] : ''}}" />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
@endforeach
|
||||||
|
<span id="end_campos"></span>
|
||||||
<div class="ten wide column">
|
<div class="ten wide column">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Descripción</label>
|
<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(() => {
|
$(document).ready(() => {
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
<div class="column">
|
<div class="column">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Segmento</label>
|
<label>Segmento</label>
|
||||||
<div class="ui selection dropdown">
|
<div class="ui selection dropdown" id="segmento">
|
||||||
<input type="hidden" name="segmento" />
|
<input type="hidden" name="segmento" />
|
||||||
<i class="dropdown icon"></i>
|
<i class="dropdown icon"></i>
|
||||||
<div class="default text">Segmento</div>
|
<div class="default text">Segmento</div>
|
||||||
@ -50,6 +50,23 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="column">
|
<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">
|
<div class="field">
|
||||||
<label>Bono Pie en UF</label>
|
<label>Bono Pie en UF</label>
|
||||||
<input type="text" name="bono" />
|
<input type="text" name="bono" />
|
||||||
@ -75,14 +92,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</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="column">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Estado</label>
|
<label>Estado</label>
|
||||||
@ -112,7 +121,7 @@
|
|||||||
<input type="text" name="tamaño_max" />
|
<input type="text" name="tamaño_max" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div> -->
|
||||||
<div class="ten wide column">
|
<div class="ten wide column">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Descripción</label>
|
<label>Descripción</label>
|
||||||
@ -152,7 +161,7 @@
|
|||||||
},
|
},
|
||||||
setup: () => {
|
setup: () => {
|
||||||
producto.setMonths()
|
producto.setMonths()
|
||||||
$('.selection.dropdown').dropdown()
|
$('#segmento').dropdown()
|
||||||
$('.calendar').calendar({
|
$('.calendar').calendar({
|
||||||
type: 'month',
|
type: 'month',
|
||||||
text: {
|
text: {
|
||||||
@ -165,6 +174,22 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
$('.checkbox').checkbox()
|
$('.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(() => {
|
$(document).ready(() => {
|
||||||
|
@ -17,7 +17,15 @@
|
|||||||
<img src="{{$urls->images}}/{{$producto->imagen()}}" />
|
<img src="{{$urls->images}}/{{$producto->imagen()}}" />
|
||||||
</div>
|
</div>
|
||||||
<div class="content">
|
<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">
|
<span class="right floated">
|
||||||
{{$producto->valor()}} UF
|
{{$producto->valor()}} UF
|
||||||
</span>
|
</span>
|
||||||
@ -46,7 +54,7 @@
|
|||||||
{{$producto->entrega}}
|
{{$producto->entrega}}
|
||||||
</span>
|
</span>
|
||||||
Entrega Estimada
|
Entrega Estimada
|
||||||
</div>
|
</div> -->
|
||||||
<span class="right floated">
|
<span class="right floated">
|
||||||
<a href="{{$urls->base}}/producto/{{$producto->id}}">
|
<a href="{{$urls->base}}/producto/{{$producto->id}}">
|
||||||
<button class="ui inverted brand button">
|
<button class="ui inverted brand button">
|
||||||
|
@ -10,66 +10,7 @@
|
|||||||
<div class="ui grid">
|
<div class="ui grid">
|
||||||
<div class="four wide column">
|
<div class="four wide column">
|
||||||
<div class="ui two columns grid informacion">
|
<div class="ui two columns grid informacion">
|
||||||
<div class="row">
|
@include('productos.producto.ficha')
|
||||||
<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>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="twelve wide column">
|
<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, ',', '.');
|
$this->valor = number_format($valor, 0, ',', '.');
|
||||||
}
|
}
|
||||||
public function tamaños(int $min = -1, int $max = -1) {
|
public function setPublicacion(\DateTime $fecha) {
|
||||||
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);
|
|
||||||
}
|
|
||||||
$this->publicacion = implode(' ', [
|
$this->publicacion = implode(' ', [
|
||||||
$fecha->day,
|
$fecha->day,
|
||||||
'de',
|
'de',
|
||||||
@ -53,6 +35,9 @@ class Producto extends Model {
|
|||||||
$fecha->year
|
$fecha->year
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
public function getPublicacion() {
|
||||||
|
return Carbon::parse($this->publicacion);
|
||||||
|
}
|
||||||
protected $destacado;
|
protected $destacado;
|
||||||
public function destacado(bool $destacado = null) {
|
public function destacado(bool $destacado = null) {
|
||||||
if ($destacado === null) {
|
if ($destacado === null) {
|
||||||
@ -140,35 +125,40 @@ class Producto extends Model {
|
|||||||
$this->direccion = new Direccion();
|
$this->direccion = new Direccion();
|
||||||
$this->direccion->map($data);
|
$this->direccion->map($data);
|
||||||
$this->valor($data->valor);
|
$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->descripcion = $data->descripcion;
|
||||||
$this->publicacion = $data->publicacion;
|
$this->publicacion = $data->publicacion;
|
||||||
|
foreach ($this->properties as $property) {
|
||||||
|
$this->$property = $data->$property ?? '';
|
||||||
|
}
|
||||||
return $this;
|
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() {
|
public function jsonSerialize() {
|
||||||
$arr = [
|
$arr = [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'nombre' => $this->nombre,
|
'nombre' => $this->nombre,
|
||||||
'segmento' => $this->segmento,
|
'segmento' => $this->segmento,
|
||||||
'valor' => $this->valor,
|
'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,
|
'descripcion' => $this->descripcion,
|
||||||
'publicacion' => $this->publicacion
|
'publicacion' => $this->publicacion
|
||||||
];
|
];
|
||||||
|
foreach ($this->properties as $property) {
|
||||||
|
$arr[$property] = $this->$property;
|
||||||
|
}
|
||||||
$arr = array_merge($arr, $this->direccion->jsonSerialize());
|
$arr = array_merge($arr, $this->direccion->jsonSerialize());
|
||||||
return $arr;
|
return $arr;
|
||||||
}
|
}
|
||||||
@ -230,4 +220,15 @@ class Producto extends Model {
|
|||||||
file_put_contents($filename, json_encode($destacados));
|
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