Show Proyecto
This commit is contained in:
@ -5,3 +5,6 @@ $app->group('/proyectos', function($app) {
|
||||
$app->get('/unidades[/]', [Proyectos::class, 'unidades']);
|
||||
$app->get('[/]', Proyectos::class);
|
||||
});
|
||||
$app->group('/proyecto/{proyecto_id}', function($app) {
|
||||
$app->get('[/]', [Proyectos::class, 'show']);
|
||||
});
|
||||
|
@ -10,4 +10,11 @@ $app->group('/proyecto/{proyecto_id}', function($app) {
|
||||
$app->get('/estado[/]', [Proyectos\EstadosProyectos::class, 'currentByProyecto']);
|
||||
$app->get('/inicio[/]', [Proyectos\EstadosProyectos::class, 'firstByProyecto']);
|
||||
$app->get('/recepcion[/]', [Proyectos\EstadosProyectos::class, 'recepcionByProyecto']);
|
||||
$app->group('/superficies', function($app) {
|
||||
$app->get('/vendible[/]', [Proyectos::class, 'superficies']);
|
||||
});
|
||||
$app->group('/unidades', function($app) {
|
||||
$app->get('/disponibles[/]', [Proyectos::class, 'disponibles']);
|
||||
$app->get('[/]', [Proyectos::class, 'unidades']);
|
||||
});
|
||||
});
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Ventas\Precios;
|
||||
use Incoviba\Controller\API\Ventas\Precios;
|
||||
|
||||
$app->group('/precios', function($app) {
|
||||
$app->post('[/]', [Precios::class, 'proyecto']);
|
||||
|
@ -17,7 +17,11 @@
|
||||
<tbody>
|
||||
@foreach ($proyectos as $proyecto)
|
||||
<tr class="proyecto" data-id="{{$proyecto->id}}">
|
||||
<td>{{$proyecto->descripcion}}</td>
|
||||
<td>
|
||||
<a href="{{$urls->base}}/proyecto/{{$proyecto->id}}">
|
||||
{{$proyecto->descripcion}}
|
||||
</a>
|
||||
</td>
|
||||
<td>{{$proyecto->inmobiliaria()->nombreCompleto()}}</td>
|
||||
<td class="etapa"></td>
|
||||
<td class="estado"></td>
|
||||
|
470
app/resources/views/proyectos/show.blade.php
Normal file
470
app/resources/views/proyectos/show.blade.php
Normal file
@ -0,0 +1,470 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_title')
|
||||
Proyecto {{$proyecto->descripcion}}
|
||||
@endsection
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h2 class="ui header">
|
||||
Proyecto {{$proyecto->descripcion}} - {{$proyecto->inmobiliaria()->razon}}
|
||||
</h2>
|
||||
@php
|
||||
$today = new DateTimeImmutable();
|
||||
@endphp
|
||||
<table class="ui striped table">
|
||||
<tr>
|
||||
<td>Dirección</td>
|
||||
<td>{{$proyecto->direccion()}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Inmobiliaria</td>
|
||||
<td>{{$proyecto->inmobiliaria()->nombreCompleto()}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Inicio</td>
|
||||
<td>
|
||||
{{$proyecto->estados()[0]->tipoEstadoProyecto->descripcion}}
|
||||
[{{$proyecto->estados()[0]->tipoEstadoProyecto->etapa->descripcion}}]
|
||||
({{$proyecto->estados()[0]->fecha->format('d-m-Y')}})
|
||||
({{$today->diff($proyecto->estados()[0]->fecha)->format('%y años antes')}})
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Estado</td>
|
||||
<td>
|
||||
{{$proyecto->currentEstado()->tipoEstadoProyecto->descripcion}}
|
||||
[{{$proyecto->currentEstado()->tipoEstadoProyecto->etapa->descripcion}}]
|
||||
({{$proyecto->currentEstado()->fecha->format('d-m-Y')}})
|
||||
({{$today->diff($proyecto->currentEstado()->fecha)->format('%y años antes')}})
|
||||
<span class="ui blue text" id="estados_avanzar" style="cursor: pointer;">
|
||||
<i class="right chevron icon"></i>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Superficies</td>
|
||||
<td>
|
||||
<table class="ui very basic striped table">
|
||||
<tr>
|
||||
<td>
|
||||
<strong>
|
||||
Total
|
||||
</strong>
|
||||
</td>
|
||||
<td>
|
||||
<strong>
|
||||
{{$format->number($proyecto->superficie->total(), 2)}}m²
|
||||
</strong>
|
||||
</td>
|
||||
<td rowspan="6" id="chart_superficies" class="six wide"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Bajo Nivel</td>
|
||||
<td>{{$format->number($proyecto->superficie->bajo_nivel, 2)}}m²</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Sobre Nivel</td>
|
||||
<td>{{$format->number($proyecto->superficie->sobre_nivel, 2)}}m²</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<strong>
|
||||
Vendible
|
||||
</strong>
|
||||
</td>
|
||||
<td>
|
||||
<strong id="superficie_vendible"></strong>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Vendido</td>
|
||||
<td id="superficie_vendido"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Por Vender</td>
|
||||
<td id="superficie_por_vender"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Unidades</td>
|
||||
<td id="unidades"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Ventas</td>
|
||||
<td id="ventas"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Stock</td>
|
||||
<td id="stock"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Proyección</td>
|
||||
<td id="proyeccion"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" id="chart_venta_general"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" id="chart_venta_tipologias"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" id="chart_venta_velocidad"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@include('layout.body.scripts.chartjs')
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
const superficies = {
|
||||
ids: {
|
||||
vendible: '',
|
||||
vendido: '',
|
||||
por_vender: '',
|
||||
chart: ''
|
||||
},
|
||||
data: {},
|
||||
chart_obj: null,
|
||||
get: function() {
|
||||
return {
|
||||
superficies: () => {
|
||||
const url = '{{$urls->api}}/proyecto/{{$proyecto->id}}/superficies/vendible'
|
||||
return fetch(url).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
this.data = data
|
||||
this.fill()
|
||||
this.chart()
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
fill: function() {
|
||||
$(this.ids.vendible).html(this.data.formatted.vendible)
|
||||
$(this.ids.vendido).html(this.data.formatted.vendido)
|
||||
$(this.ids.por_vender).html(this.data.formatted.por_vender)
|
||||
},
|
||||
chart: function() {
|
||||
const container = $(this.ids.chart)
|
||||
container.html('')
|
||||
this.chart_obj = null
|
||||
const ctx = $('<canvas></canvas>').attr('width', '100')
|
||||
container.append(ctx)
|
||||
const data = {
|
||||
labels: [
|
||||
'Vendida',
|
||||
'Por Vender'
|
||||
],
|
||||
datasets: [
|
||||
{
|
||||
label: 'Superficies',
|
||||
data: [
|
||||
this.data.superficies.vendido,
|
||||
this.data.superficies.por_vender
|
||||
],
|
||||
backgroundColor: [
|
||||
'green',
|
||||
'red'
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
const options = {
|
||||
type: 'pie',
|
||||
data
|
||||
}
|
||||
|
||||
this.chart_obj = new Chart(ctx, options)
|
||||
},
|
||||
setup: function({id_vendible, id_vendido, id_por_vender, id_chart}) {
|
||||
this.ids.vendible = id_vendible
|
||||
this.ids.vendido = id_vendido
|
||||
this.ids.por_vender = id_por_vender
|
||||
this.ids.chart = id_chart
|
||||
|
||||
this.get().superficies()
|
||||
}
|
||||
}
|
||||
const unidades = {
|
||||
id: '',
|
||||
data: {},
|
||||
get: function() {
|
||||
const url = '{{$urls->api}}/proyecto/{{$proyecto->id}}/unidades'
|
||||
return fetch(url).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
this.data = data
|
||||
this.draw()
|
||||
})
|
||||
},
|
||||
draw: function() {
|
||||
const parent = $(this.id)
|
||||
const table = $('<table></table>').addClass('ui very basic striped table')
|
||||
Object.entries(this.data.unidades).forEach(([tipo, unidades]) => {
|
||||
tipo = tipo.charAt(0).toUpperCase() + tipo.slice(1) + 's'
|
||||
table.append(
|
||||
$('<tr></tr>').append(
|
||||
$('<td></td>').html(tipo)
|
||||
).append(
|
||||
$('<td></td>').html(unidades.length)
|
||||
)
|
||||
)
|
||||
})
|
||||
parent.append(table)
|
||||
},
|
||||
setup: function(id) {
|
||||
this.id = id
|
||||
this.get()
|
||||
}
|
||||
}
|
||||
const ventas = {
|
||||
ids: {
|
||||
ventas: '',
|
||||
stock: '',
|
||||
proyeccion: '',
|
||||
charts: {
|
||||
general: '',
|
||||
tipologias: '',
|
||||
velocidad: ''
|
||||
}
|
||||
},
|
||||
data: {
|
||||
ventas: {
|
||||
unidades: {},
|
||||
valores: {
|
||||
total: 0,
|
||||
promedio: 0,
|
||||
bonos: 0,
|
||||
promociones: 0,
|
||||
operadores: 0,
|
||||
metro: 0,
|
||||
},
|
||||
superficies: {
|
||||
total: 0,
|
||||
promedio: 0
|
||||
}
|
||||
},
|
||||
stock: {
|
||||
unidades: {},
|
||||
valores: {
|
||||
total: 0,
|
||||
promedio: 0,
|
||||
bonos: 0,
|
||||
promociones: 0,
|
||||
operadores: 0,
|
||||
metro: 0,
|
||||
},
|
||||
superficies: {
|
||||
total: 0,
|
||||
promedio: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
get: function() {
|
||||
return {
|
||||
ventas: () => {
|
||||
const url = '{{$urls->api}}/ventas'
|
||||
return fetch(url, {method: 'post', headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({proyecto_id: '{{$proyecto->id}}'})}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
const promises = []
|
||||
data.ventas.forEach(venta_id => {
|
||||
promises.push(this.get().venta(venta_id))
|
||||
})
|
||||
return Promise.all(promises).then(() => {
|
||||
const cantidad_total = Object.values(this.data.ventas.unidades).reduce((sum, cantidad) => sum + cantidad, 0)
|
||||
this.data.ventas.valores.promedio = this.data.ventas.valores.total / cantidad_total
|
||||
this.data.ventas.superficies.promedio = this.data.ventas.superficies.total / cantidad_total
|
||||
this.data.ventas.valores.metro = this.data.ventas.valores.total / this.data.ventas.superficies.total
|
||||
this.draw().ventas()
|
||||
})
|
||||
})
|
||||
},
|
||||
stock: () => {
|
||||
const url = '{{$urls->api}}/proyecto/{{$proyecto->id}}/unidades/disponibles'
|
||||
return fetch(url).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
const promises = []
|
||||
data.unidades.forEach(unidad => {
|
||||
this.add().unidad(unidad)
|
||||
promises.push(this.get().precio(unidad.id))
|
||||
})
|
||||
return Promise.all(promises).then(() => {
|
||||
const cantidad_total = Object.values(this.data.stock.unidades).reduce((sum, cantidad) => sum + cantidad, 0)
|
||||
this.data.stock.valores.promedio = this.data.stock.valores.total / cantidad_total
|
||||
this.data.stock.superficies.promedio = this.data.stock.superficies.total / cantidad_total
|
||||
this.data.stock.valores.metro = this.data.stock.valores.total / this.data.stock.superficies.total
|
||||
this.draw().stock()
|
||||
})
|
||||
})
|
||||
},
|
||||
venta: venta_id => {
|
||||
const url = '{{$urls->api}}/venta/' + venta_id
|
||||
return fetch(url).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
this.add().venta(data.venta)
|
||||
})
|
||||
},
|
||||
precio: unidad_id => {
|
||||
const url = '{{$urls->api}}/ventas/precio/unidad/' + unidad_id
|
||||
return fetch(url).then(response => {
|
||||
if (response.ok) {
|
||||
if (response.status === 204) {
|
||||
return null
|
||||
}
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
if (data === null) {
|
||||
return
|
||||
}
|
||||
this.add().precio(data.precio)
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
add: function() {
|
||||
return {
|
||||
venta: venta => {
|
||||
Object.entries(venta.propiedad).forEach(([tipo, unidades]) => {
|
||||
if (tipo === 'summary') {
|
||||
return
|
||||
}
|
||||
tipo = tipo.charAt(0).toUpperCase() + tipo.slice(1)
|
||||
if (typeof this.data.ventas.unidades[tipo] === 'undefined') {
|
||||
this.data.ventas.unidades[tipo] = 0
|
||||
}
|
||||
this.data.ventas.unidades[tipo] ++
|
||||
this.data.ventas.superficies.total += unidades.reduce((sum, unidad) => sum + unidad.proyecto_tipo_unidad.vendible, 0)
|
||||
this.data.ventas.valores.total += venta.valor
|
||||
if (venta.forma_pago.bono_pie !== null) {
|
||||
this.data.ventas.valores.bonos += venta.forma_pago.bono_pie
|
||||
}
|
||||
})
|
||||
},
|
||||
unidad: unidad => {
|
||||
let tipo = unidad.proyecto_tipo_unidad.tipo_unidad.descripcion
|
||||
tipo = tipo.charAt(0).toUpperCase() + tipo.slice(1) + 's'
|
||||
if (typeof this.data.stock.unidades[tipo] === 'undefined') {
|
||||
this.data.stock.unidades[tipo] = 0
|
||||
}
|
||||
this.data.stock.unidades[tipo] ++
|
||||
this.data.ventas.superficies.total += unidad.proyecto_tipo_unidad.vendible
|
||||
},
|
||||
precio: precio => {
|
||||
this.data.stock.valores.total += precio.valor
|
||||
}
|
||||
}
|
||||
},
|
||||
draw: function() {
|
||||
return {
|
||||
loading: parent => {
|
||||
parent.html('')
|
||||
parent.append(
|
||||
$('<div></div>').addClass('ui active inline loader')
|
||||
)
|
||||
},
|
||||
ventas: () => {
|
||||
const parent = $(this.ids.ventas)
|
||||
parent.html('')
|
||||
this.draw().table(parent, this.data.ventas)
|
||||
},
|
||||
stock: () => {
|
||||
const parent = $(this.ids.stock)
|
||||
parent.html('')
|
||||
this.draw().table(parent, this.data.stock)
|
||||
},
|
||||
proyeccion: () => {
|
||||
|
||||
},
|
||||
table: (parent, data) => {
|
||||
const formatter = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2})
|
||||
const table = $('<table></table>').addClass('ui very basic striped table')
|
||||
let row = $('<tr></tr>')
|
||||
let row2 = $('<tr></tr>')
|
||||
Object.entries(data.unidades).forEach(([tipo, cantidad]) => {
|
||||
row.append(
|
||||
$('<td></td>').html(tipo)
|
||||
)
|
||||
row2.append(
|
||||
$('<td></td>').html(cantidad)
|
||||
)
|
||||
})
|
||||
table.append(row).append(row2)
|
||||
row = $('<tr></tr>').append(
|
||||
$('<td></td>').html('Valor Total [UF]')
|
||||
).append(
|
||||
$('<td></td>').html('Valor Promedio [UF]')
|
||||
).append(
|
||||
$('<td></td>').html('Valor Metro [UF/m²]')
|
||||
)
|
||||
table.append(row)
|
||||
row = $('<tr></tr>').append(
|
||||
$('<td></td>').html(formatter.format(data.valores.total))
|
||||
).append(
|
||||
$('<td></td>').html(formatter.format(data.valores.promedio))
|
||||
).append(
|
||||
$('<td></td>').html(formatter.format(data.valores.metro))
|
||||
)
|
||||
table.append(row)
|
||||
parent.append(table)
|
||||
}
|
||||
}
|
||||
},
|
||||
chart: function() {
|
||||
return {
|
||||
general: () => {},
|
||||
tipologias: () => {},
|
||||
velocidad: () => {}
|
||||
}
|
||||
},
|
||||
setup: function({id_ventas, id_stock, id_proyeccion, id_chart_general, id_chart_tipologias, id_chart_velocidad}) {
|
||||
this.ids.ventas = id_ventas
|
||||
this.ids.stock = id_stock
|
||||
this.ids.proyeccion = id_proyeccion
|
||||
this.ids.charts.general = id_chart_general
|
||||
this.ids.charts.tipologias = id_chart_tipologias
|
||||
this.ids.charts.velocidad = id_chart_velocidad
|
||||
|
||||
const promises = []
|
||||
promises.push(this.get().ventas())
|
||||
promises.push(this.get().stock())
|
||||
Promise.all(promises).then(() => {
|
||||
this.draw().proyeccion()
|
||||
this.chart().general()
|
||||
this.chart().tipologias()
|
||||
this.chart().velocidad()
|
||||
})
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
$('#estados_avanzar').click(event => {
|
||||
alert('Avanzar')
|
||||
})
|
||||
superficies.setup({id_vendible: '#superficie_vendible', id_vendido: '#superficie_vendido',
|
||||
id_por_vender: '#superficie_por_vender', id_chart: '#chart_superficies'})
|
||||
unidades.setup('#unidades')
|
||||
ventas.setup({id_ventas: '#ventas', id_stock: '#stock', id_proyeccion: '#proyeccion',
|
||||
id_chart_general: '#chart_venta_general', id_chart_tipologias: '#chart_venta_tipologia',
|
||||
id_chart_velocidad: '#chart_venta_velocidad'})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
@ -3,13 +3,15 @@ namespace Incoviba\Controller\API;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Proyectos
|
||||
{
|
||||
use withJson;
|
||||
use withJson, withRedis;
|
||||
|
||||
public function list(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
{
|
||||
@ -34,26 +36,88 @@ class Proyectos
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function unidades(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, int $proyecto_id): ResponseInterface
|
||||
public function unidades(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Repository\Venta\Unidad $unidadRepository, Service\Redis $redisService,
|
||||
int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = ['proyecto_id' => $proyecto_id, 'unidades' => [], 'total' => 0];
|
||||
$redisKey = "unidades-proyecto-{$proyecto_id}";
|
||||
try {
|
||||
$unidades = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
|
||||
$tipos = [];
|
||||
foreach ($unidades as $unidad) {
|
||||
if (!isset($tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion])) {
|
||||
$tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion] = [];
|
||||
$output = $this->fetchRedis($redisService, $redisKey);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$unidades = $unidadRepository->fetchByProyecto($proyecto_id);
|
||||
$tipos = [];
|
||||
foreach ($unidades as $unidad) {
|
||||
if (!isset($tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion])) {
|
||||
$tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion] = [];
|
||||
}
|
||||
$tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion] []= $unidad;
|
||||
}
|
||||
$tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion] []= $unidad;
|
||||
}
|
||||
foreach ($tipos as &$subtipo) {
|
||||
usort($subtipo, function(Model\Venta\Unidad $a, Model\Venta\Unidad $b) {
|
||||
return strcmp(str_pad($a->descripcion, 4, '0', STR_PAD_LEFT), str_pad($b->descripcion, 4, '0', STR_PAD_LEFT));
|
||||
});
|
||||
}
|
||||
$output['unidades'] = $tipos;
|
||||
$output['total'] = count($unidades);
|
||||
foreach ($tipos as &$subtipo) {
|
||||
usort($subtipo, function(Model\Venta\Unidad $a, Model\Venta\Unidad $b) {
|
||||
return strcmp(str_pad($a->descripcion, 4, '0', STR_PAD_LEFT), str_pad($b->descripcion, 4, '0', STR_PAD_LEFT));
|
||||
});
|
||||
}
|
||||
$output['unidades'] = $tipos;
|
||||
$output['total'] = count($unidades);
|
||||
$this->saveRedis($redisService, $redisKey, $output);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function disponibles(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
'unidades' => []
|
||||
];
|
||||
try {
|
||||
$output['unidades'] = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function superficies(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Repository\Proyecto $proyectoRepository, Repository\Venta $ventaRepository,
|
||||
Repository\Venta\Unidad $unidadRepository, Service\Redis $redisService,
|
||||
Service\Format $formatService, int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
'superficies' => [
|
||||
'vendible' => 0,
|
||||
'vendido' => 0,
|
||||
'por_vender' => 0
|
||||
],
|
||||
'formatted' => [
|
||||
'vendible' => '0m²',
|
||||
'vendido' => '0m²',
|
||||
'por_vender' => '0m²'
|
||||
]
|
||||
];
|
||||
$redisKey = "superficices-proyecto-{$proyecto_id}";
|
||||
try {
|
||||
$output = $this->fetchRedis($redisService, $redisKey);
|
||||
} catch (EmptyRedis) {
|
||||
try {
|
||||
$ventas = $ventaRepository->fetchActivaByProyecto($proyecto_id);
|
||||
$unidades = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
|
||||
|
||||
$output['superficies']['vendido'] = array_reduce($ventas, function($sum, Model\Venta $venta) {
|
||||
return $sum + array_reduce($venta->propiedad()->unidades, function($sum, Model\Venta\Unidad $unidad) {
|
||||
return $sum + $unidad->proyectoTipoUnidad->vendible();
|
||||
});
|
||||
}, 0);
|
||||
$output['formatted']['vendido'] = "{$formatService->number($output['superficies']['vendido'], 2)}m²";
|
||||
$output['superficies']['por_vender'] = array_reduce($unidades, function($sum, Model\Venta\Unidad $unidad) {
|
||||
return $sum + $unidad->proyectoTipoUnidad->vendible();
|
||||
});
|
||||
$output['formatted']['por_vender'] = "{$formatService->number($output['superficies']['por_vender'], 2)}m²";
|
||||
$output['superficies']['vendible'] = $output['superficies']['vendido'] + $output['superficies']['por_vender'];
|
||||
$output['formatted']['vendible'] = "{$formatService->number($output['superficies']['vendible'], 2)}m²";
|
||||
$this->saveRedis($redisService, $redisKey, $output, 60 * 60);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ class Ventas
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$today = new DateTimeImmutable();
|
||||
$redisKey = "promesas_por_firmar-{$proyecto_id}-{$today->format('Y-m-d')}";
|
||||
$redisKey = "promesas_por_firmar-proyecto-{$proyecto_id}-{$today->format('Y-m-d')}";
|
||||
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
@ -80,7 +80,7 @@ class Ventas
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$today = new DateTimeImmutable();
|
||||
$redisKey = "escrituras-{$proyecto_id}-{$today->format('Y-m-d')}";
|
||||
$redisKey = "escrituras-proyecto-{$proyecto_id}-{$today->format('Y-m-d')}";
|
||||
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
|
36
app/src/Controller/API/Ventas/Precios.php
Normal file
36
app/src/Controller/API/Ventas/Precios.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API\Ventas;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Controller\API;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Precios
|
||||
{
|
||||
use API\withJson, API\emptyBody;
|
||||
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$precios = $precioService->getByProyecto($proyecto_id);
|
||||
$output['precios'] = $precios;
|
||||
$output['total'] = count($precios);
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function unidad(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService, int $unidad_id): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$precio = $precioService->getVigenteByUnidad($unidad_id);
|
||||
return $this->withJson($response, compact('precio'));
|
||||
} catch (EmptyResult) {
|
||||
return $this->emptyBody($response);
|
||||
}
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@ class Unidades
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$today = new DateTimeImmutable();
|
||||
$redisKey = "unidades_disponibles-{$proyecto_id}-{$today->format('Y-m-d')}";
|
||||
$redisKey = "unidades_disponibles-proyecto-{$proyecto_id}-{$today->format('Y-m-d')}";
|
||||
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
|
@ -4,8 +4,9 @@ namespace Incoviba\Controller;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Proyectos
|
||||
{
|
||||
@ -29,4 +30,9 @@ class Proyectos
|
||||
});
|
||||
return $view->render($response, 'proyectos.unidades', compact('proyectos'));
|
||||
}
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Proyecto $proyectoService, int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$proyecto = $proyectoService->getById($proyecto_id);
|
||||
return $view->render($response, 'proyectos.show', compact('proyecto'));
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
@ -15,24 +14,4 @@ class Precios
|
||||
$proyectos = array_map(function(Model\Proyecto $proyecto) {return ['id' => $proyecto->id, 'descripcion' => $proyecto->descripcion];}, $proyectoService->getVendibles());
|
||||
return $view->render($response, 'ventas.precios.list', compact('proyectos'));
|
||||
}
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$precios = $precioService->getByProyecto($proyecto_id);
|
||||
$output['precios'] = $precios;
|
||||
$output['total'] = count($precios);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function unidad(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Precio $precioService, int $unidad_id): ResponseInterface
|
||||
{
|
||||
$precio = $precioService->getVigenteByUnidad($unidad_id);
|
||||
$response->getBody()->write(json_encode(['precio' => $precio]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Alias\Model;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Proyecto extends Ideal\Model
|
||||
@ -15,6 +16,9 @@ class Proyecto extends Ideal\Model
|
||||
public int $subterraneos;
|
||||
protected Proyecto\Etapa $etapa;
|
||||
|
||||
protected array $estados;
|
||||
protected Proyecto\EstadoProyecto $currentEstado;
|
||||
|
||||
public function inmobiliaria(): Inmobiliaria
|
||||
{
|
||||
if (!isset($this->inmobiliaria)) {
|
||||
@ -29,6 +33,20 @@ class Proyecto extends Ideal\Model
|
||||
}
|
||||
return $this->direccion;
|
||||
}
|
||||
public function estados(): array
|
||||
{
|
||||
if (!isset($this->estados)) {
|
||||
$this->estados = $this->runFactory('estados');
|
||||
}
|
||||
return $this->estados;
|
||||
}
|
||||
public function currentEstado(): Proyecto\EstadoProyecto
|
||||
{
|
||||
if (!isset($this->currentEstado)) {
|
||||
$this->currentEstado = $this->runFactory('currentEstado');
|
||||
}
|
||||
return $this->currentEstado;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
|
@ -5,4 +5,9 @@ class Superficie
|
||||
{
|
||||
public float $sobre_nivel;
|
||||
public float $bajo_nivel;
|
||||
|
||||
public function total(): float
|
||||
{
|
||||
return $this->bajo_nivel + $this->sobre_nivel;
|
||||
}
|
||||
}
|
||||
|
@ -9,15 +9,15 @@ class Propiedad extends Ideal\Model
|
||||
|
||||
public function departamentos(): array
|
||||
{
|
||||
return array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'departamento';});
|
||||
return array_values(array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'departamento';}));
|
||||
}
|
||||
public function estacionamientos(): array
|
||||
{
|
||||
return array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'estacionamiento';});
|
||||
return array_values(array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'estacionamiento';}));
|
||||
}
|
||||
public function bodegas(): array
|
||||
{
|
||||
return array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'bodega';});
|
||||
return array_values(array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'bodega';}));
|
||||
}
|
||||
|
||||
protected float $vendible;
|
||||
|
@ -92,6 +92,10 @@ WHERE et.`orden` BETWEEN {$etapaRecepcion->orden} AND ({$etapaTerminado->orden}
|
||||
ORDER BY a.`descripcion`";
|
||||
return $this->fetchMany($query);
|
||||
}
|
||||
public function fetchSuperficieVendido(int $proyecto_id): float
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function joinEstado(): string
|
||||
{
|
||||
|
@ -15,8 +15,8 @@ class Redis
|
||||
}
|
||||
return $this->client->get($name);
|
||||
}
|
||||
public function set(string $name, mixed $value): void
|
||||
public function set(string $name, mixed $value, int $expirationTTL = 60 * 60 * 24): void
|
||||
{
|
||||
$this->client->set($name, $value, 'EX', 60 * 60 * 24);
|
||||
$this->client->set($name, $value, 'EX', $expirationTTL);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user