Mostrar alertas en inicio
This commit is contained in:
@ -9,10 +9,7 @@ $app->group('/ventas', function($app) {
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
$app->group('/add', function($app) {
|
||||
$app->post('[/]', [Ventas::class, 'doAdd']);
|
||||
$app->get('[/]', [Ventas::class, 'add']);
|
||||
});
|
||||
$app->get('/add[/]', [Ventas::class, 'add']);
|
||||
$app->get('[/]', Ventas::class);
|
||||
});
|
||||
$app->group('/venta/{proyecto_nombre:[A-za-zÑñ\+\ %0-9]+}/{unidad_descripcion:[0-9]+}', function($app) {
|
||||
|
@ -2,10 +2,10 @@
|
||||
use Incoviba\Controller\API\Proyectos;
|
||||
|
||||
$app->group('/proyectos', function($app) {
|
||||
$app->get('/escriturando[/]', [Proyectos::class, 'escriturando']);
|
||||
$app->get('[/]', [Proyectos::class, 'list']);
|
||||
});
|
||||
$app->group('/proyecto/{proyecto_id}', function($app) {
|
||||
$app->get('/unidades[/]', [Proyectos::class, 'unidades']);
|
||||
$app->get('/estados[/]', [Proyectos\EstadosProyectos::class, 'byProyecto']);
|
||||
$app->get('/estado[/]', [Proyectos\EstadosProyectos::class, 'currentByProyecto']);
|
||||
$app->get('/inicio[/]', [Proyectos\EstadosProyectos::class, 'firstByProyecto']);
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Ventas;
|
||||
use Incoviba\Controller\API\Ventas;
|
||||
|
||||
$app->group('/ventas', function($app) {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, 'ventas']);
|
||||
@ -12,6 +12,13 @@ $app->group('/ventas', function($app) {
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
}
|
||||
$app->post('/add[/]', [Ventas::class, 'add']);
|
||||
$app->group('/estados', function($app) {
|
||||
$app->post('/firmar[/]', [Ventas::class, 'porFirmar']);
|
||||
});
|
||||
$app->group('/escrituras', function($app) {
|
||||
$app->post('/estados[/]', [Ventas::class, 'escrituras']);
|
||||
});
|
||||
$app->post('[/]', [Ventas::class, 'proyecto']);
|
||||
});
|
||||
$app->group('/venta/{venta_id}', function($app) {
|
||||
|
6
app/resources/routes/api/ventas/unidades.php
Normal file
6
app/resources/routes/api/ventas/unidades.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
use Incoviba\Controller\API\Ventas\Unidades;
|
||||
|
||||
$app->group('/unidades', function($app) {
|
||||
$app->post('/disponibles', [Unidades::class, 'disponibles']);
|
||||
});
|
@ -12,7 +12,7 @@
|
||||
@include('home.cuotas_por_vencer')
|
||||
</div>
|
||||
<div class="column">
|
||||
Alertas
|
||||
@include('home.alertas')
|
||||
</div>
|
||||
<div class="column">
|
||||
@include('home.cierres_vigentes')
|
||||
|
191
app/resources/views/home/alertas.blade.php
Normal file
191
app/resources/views/home/alertas.blade.php
Normal file
@ -0,0 +1,191 @@
|
||||
<h4 class="ui dividing header">Alertas Escrituras</h4>
|
||||
<div class="ui divided list" id="alertas_escrituras"></div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
const alertas_escrituras = {
|
||||
id: '#alertas_escrituras',
|
||||
data: {
|
||||
proyectos: []
|
||||
},
|
||||
get: function() {
|
||||
return {
|
||||
proyectos: () => {
|
||||
this.draw().loading()
|
||||
const url = '{{$urls->api}}/proyectos/escriturando'
|
||||
return fetch(url).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
const promises = []
|
||||
data.proyectos.forEach(proyecto => {
|
||||
this.add().proyecto(proyecto)
|
||||
promises.push(
|
||||
this.get().unidades(proyecto.id)
|
||||
)
|
||||
promises.push(
|
||||
this.get().promesas(proyecto.id)
|
||||
)
|
||||
promises.push(
|
||||
this.get().escrituras(proyecto.id)
|
||||
)
|
||||
})
|
||||
Promise.all(promises).then(() => {
|
||||
this.draw().list()
|
||||
})
|
||||
})
|
||||
},
|
||||
unidades: proyecto_id => {
|
||||
const url = '{{$urls->api}}/ventas/unidades/disponibles'
|
||||
return fetch(url, {method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
const index = this.data.proyectos.findIndex(proyecto => proyecto.id === data.proyecto_id)
|
||||
this.data.proyectos[index].unidades = data.unidades
|
||||
})
|
||||
},
|
||||
promesas: proyecto_id => {
|
||||
const url = '{{$urls->api}}/ventas/estados/firmar'
|
||||
return fetch(url, {method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
const index = this.data.proyectos.findIndex(proyecto => proyecto.id === data.proyecto_id)
|
||||
this.data.proyectos[index].promesas = data.promesas
|
||||
})
|
||||
},
|
||||
escrituras: proyecto_id => {
|
||||
const url = '{{$urls->api}}/ventas/escrituras/estados';
|
||||
return fetch(url, {method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
const index = this.data.proyectos.findIndex(proyecto => proyecto.id === data.proyecto_id)
|
||||
this.data.proyectos[index].escrituras = data.escrituras
|
||||
})
|
||||
/*const index = this.data.proyectos.findIndex(proyecto => proyecto.id === proyecto_id)
|
||||
if (proyecto_id === 3) {
|
||||
this.data.proyectos[index].escrituras = {
|
||||
firmar: 20,
|
||||
pagar: 70,
|
||||
abonar: 3
|
||||
}
|
||||
}
|
||||
if (proyecto_id === 4) {
|
||||
this.data.proyectos[index].escrituras = {
|
||||
firmar: 0,
|
||||
pagar: 0,
|
||||
abonar: 2
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
},
|
||||
draw: function() {
|
||||
return {
|
||||
reset: () => {
|
||||
const list = $(this.id)
|
||||
list.html('')
|
||||
},
|
||||
loading: () => {
|
||||
this.draw().reset()
|
||||
const list = $(this.id)
|
||||
list.append(
|
||||
$('<div><div>').addClass('ui inline active loader')
|
||||
)
|
||||
},
|
||||
list: () => {
|
||||
this.draw().reset()
|
||||
const list = $(this.id)
|
||||
this.data.proyectos.forEach(proyecto => {
|
||||
const feed = $('<div></div>').addClass('ui feed').append(
|
||||
$('<div></div>').addClass('date').append(
|
||||
$('<strong></strong>').html(proyecto.descripcion)
|
||||
)
|
||||
)
|
||||
|
||||
function add(control, title, value = null) {
|
||||
if (control > 0) {
|
||||
return $('<div></div>').addClass('event').append(
|
||||
$('<div></div>').addClass('content').html(title)
|
||||
).append(
|
||||
$('<div></div>').addClass('meta').html(value ?? control)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const total_unidades = Object.entries(proyecto.unidades)
|
||||
.filter(([tipo, total]) => tipo !== 'total')
|
||||
.map(([tipo, total]) => total)
|
||||
.reduce((sum, total_tipo) => sum + total_tipo, 0)
|
||||
const unidades = $('<div></div>').addClass('ui feed')
|
||||
const formatter = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 0, maximumFractionDigits: 0})
|
||||
Object.entries(proyecto.unidades).filter(([tipo, total]) => tipo !== 'total').forEach(([tipo, total]) => {
|
||||
const full = proyecto.unidades.total[tipo]
|
||||
tipo = tipo.charAt(0).toUpperCase() + tipo.slice(1)
|
||||
unidades.append(
|
||||
$('<div></div>').addClass('event').append(
|
||||
$('<div></div>').addClass('content').html(tipo)
|
||||
).append(
|
||||
$('<div></div>').addClass('meta').html(total + '/' + full + ' ' + formatter.format(Math.round(total / full * 10000) / 100).padStart(2, ' ') + '%')
|
||||
)
|
||||
)
|
||||
})
|
||||
if (total_unidades > 0) {
|
||||
feed.append(
|
||||
$('<div></div>').addClass('event').append(
|
||||
$('<div></div>').addClass('content').html('Unidades por Vender')
|
||||
).append(
|
||||
$('<div></div>').addClass('content').append(unidades)
|
||||
)
|
||||
)
|
||||
}
|
||||
feed.append(add(proyecto.promesas, 'Promesas por Escriturar'))
|
||||
feed.append(add(proyecto.escrituras.firmar, 'Escrituras por Firmar'))
|
||||
feed.append(add(proyecto.escrituras.pagar, 'Escrituras con Pagos Pendientes'))
|
||||
feed.append(add(proyecto.escrituras.abonar, 'Escrituras con Pagos no Abonados'))
|
||||
list.append(
|
||||
$('<div></div>').addClass('item').append(feed)
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
add: function() {
|
||||
return {
|
||||
proyecto: proyecto => {
|
||||
proyecto.unidades = {
|
||||
total: 0,
|
||||
departamentos: 0,
|
||||
estacionamientos: 0,
|
||||
bodegas: 0
|
||||
}
|
||||
proyecto.promesas = 0
|
||||
proyecto.escrituras = {
|
||||
firmar: 0,
|
||||
pagar: 0,
|
||||
abonar: 0
|
||||
}
|
||||
this.data.proyectos.push(proyecto)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
alertas_escrituras.get().proyectos()
|
||||
})
|
||||
/**
|
||||
* Listar proyectos construidos no terminados con unidades no vendidas, promesas o escrituras pendientes
|
||||
* Listar # unidades no vendidas
|
||||
* Listar # promesas por escriturar
|
||||
* Listar # escrituras por firmar
|
||||
* Listar # escrituras con pagos pendientes
|
||||
* Listar # escrituras con abonos pendientes
|
||||
*/
|
||||
</script>
|
||||
@endpush
|
@ -1,4 +1,233 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h2 class="ui header">Unidades por Proyecto</h2>
|
||||
<h4 class="ui dividing header">
|
||||
<div class="ui two column grid">
|
||||
<div id="list_title" class="column">Proyectos</div>
|
||||
<div class="right aligned column">
|
||||
<div class="ui tiny icon buttons">
|
||||
<button id="up_button" class="ui button">
|
||||
<i class="up arrow icon"></i>
|
||||
</button>
|
||||
<button id="refresh_button" class="ui button">
|
||||
<i class="refresh icon"></i>
|
||||
</button>
|
||||
</div>
|
||||
<button class="ui tiny green icon button" id="add_button">
|
||||
<i class="plus icon"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</h4>
|
||||
<div id="proyectos" class="ui link selection list">
|
||||
@foreach ($proyectos as $proyecto)
|
||||
<div class="item" data-proyecto="{{$proyecto->id}}">{{$proyecto->descripcion}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<table class="ui table" id="data"></table>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('page_styles')
|
||||
<style>
|
||||
.show-unidades, .linea {
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
@endpush
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
class Unidad
|
||||
{
|
||||
id
|
||||
descripcion
|
||||
piso
|
||||
linea
|
||||
|
||||
constructor({id, descripcion, piso, linea})
|
||||
{
|
||||
this.id = id
|
||||
this.descripcion = descripcion
|
||||
this.piso = piso
|
||||
this.linea = linea
|
||||
}
|
||||
draw(parent)
|
||||
{
|
||||
const row = $('<tr></tr>').addClass('unidad').attr('data-linea', linea).append(
|
||||
$('<td></td>').html(this.descripcion)
|
||||
).append(
|
||||
$('<td></td>').html(this.piso)
|
||||
).append(
|
||||
$('<td></td>').addClass('right aligned').append(
|
||||
$('<button></button>').addClass('ui yellow icon button').attr('type', 'button').append(
|
||||
$('<i></i>').addClass('edit icon')
|
||||
)
|
||||
).append(
|
||||
$('<button></button>').addClass('ui red icon button').attr('type', 'button').append(
|
||||
$('<i></i>').addClass('remove icon')
|
||||
)
|
||||
)
|
||||
)
|
||||
parent.append(row)
|
||||
}
|
||||
}
|
||||
class Linea
|
||||
{
|
||||
numero
|
||||
orientacion
|
||||
|
||||
unidades
|
||||
constructor({numero, orientacion})
|
||||
{
|
||||
this.numero = numero
|
||||
this.orientacion = orientacion
|
||||
this.unidades = []
|
||||
}
|
||||
get cantidad()
|
||||
{
|
||||
return this.unidades.length
|
||||
}
|
||||
get pisos()
|
||||
{
|
||||
if (this.cantidad === 0) {
|
||||
return ''
|
||||
}
|
||||
const pisos = this.unidades.map(unidad => unidad.piso)
|
||||
return Math.min(pisos) + ' - ' + Math.max(pisos)
|
||||
}
|
||||
get descripcion()
|
||||
{
|
||||
return 'Linea ' + this.numero
|
||||
}
|
||||
draw(parent)
|
||||
{
|
||||
const row = $('<tr></tr>').addClass('linea').attr('data-id', this.numero).attr('data-status', 'closed').append(
|
||||
$('<td></td>').append(
|
||||
$('<strong></strong>').html(this.descripcion)
|
||||
).append(
|
||||
$('<i></i>').addClass('caret right icon')
|
||||
)
|
||||
).append(
|
||||
$('<td></td>').append(
|
||||
$('<stong></stong>').html(this.orientacion)
|
||||
)
|
||||
).append($('<td></td>'))
|
||||
parent.append(row)
|
||||
this.unidades.forEach(unidad => {
|
||||
unidad.draw(parent)
|
||||
})
|
||||
}
|
||||
}
|
||||
class ProyectoTipoUnidad
|
||||
{
|
||||
id
|
||||
descripcion
|
||||
tipo
|
||||
tipologia
|
||||
superficies
|
||||
|
||||
lineas
|
||||
|
||||
constructor({id, descripcion, tipo, tipologia, superficies})
|
||||
{
|
||||
this.id = id
|
||||
this.descripcion = descripcion
|
||||
this.tipo = tipo
|
||||
this.tipologia = tipologia
|
||||
this.superficies = superficies
|
||||
|
||||
this.lineas = []
|
||||
}
|
||||
|
||||
|
||||
get cantidad()
|
||||
{
|
||||
return this.lineas.reduce((sum, linea) => sum + linea.cantidad)
|
||||
}
|
||||
|
||||
draw(parent)
|
||||
{
|
||||
const row = $('<tr></tr>').addClass('proyecto_tipo_unidad').attr('data-id', this.id).attr('data-status', 'closed').append(
|
||||
$('<td></td>').append(this.tipo.descripcion).append(
|
||||
$('<i></i>').addClass('caret icon right')
|
||||
)
|
||||
).append(
|
||||
$('<td></td>').html(this.descripcion)
|
||||
).append(
|
||||
$('<td></td>').html(this.tipologia.abreviacion)
|
||||
).append(
|
||||
$('<td></td>').html(this.cantidad)
|
||||
).append(
|
||||
$('<td></td>').html(this.lineas.map(linea => linea.numero).join(' - '))
|
||||
).append(
|
||||
$('<td></td>').html(this.superficies.interior)
|
||||
).append(
|
||||
$('<td></td>').html(this.superficies.terraza)
|
||||
).append(
|
||||
$('<td></td>').html(this.superficies.vendible)
|
||||
).append(
|
||||
$('<td></td>').html(this.superficies.total)
|
||||
).append(
|
||||
$('<td></td>').html(this.tipologia.descripcion)
|
||||
)
|
||||
parent.append(row)
|
||||
const tbody = $('<tbody></tbody>')
|
||||
this.lineas.forEach(linea => {
|
||||
linea.draw(tbody)
|
||||
})
|
||||
const table = $('<table></table>').addClass('ui table').append(
|
||||
$('<thead></thead>').append(
|
||||
$('<th></th>').html('Unidad')
|
||||
).append(
|
||||
$('<th></th>').html('Orientacion')
|
||||
).append(
|
||||
$('<th></th>').html('Cantidad<br />Piso')
|
||||
)
|
||||
).append(tbody)
|
||||
|
||||
const line_row = $('<tr></tr>').addClass('unidades').attr('data-tipo', this.id).append(
|
||||
$('<td></td>')
|
||||
).append(
|
||||
$('<td></td>').attr('colspan', 9).append(table)
|
||||
)
|
||||
parent.append(line_row)
|
||||
}
|
||||
}
|
||||
const proyectos = {
|
||||
ids: {},
|
||||
tipos: [],
|
||||
get: function() {
|
||||
return {
|
||||
tipos: proyecto_id => {
|
||||
const url = '{{$urls->api}}/proyecto/' + proyecto_id + '/unidades/tipos'
|
||||
return fetch(url).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
console.debug(tipos)
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
setup: function() {
|
||||
$('.item.proyecto').click(event => {
|
||||
if (this.loading.precios) {
|
||||
return false
|
||||
}
|
||||
const element = $(event.currentTarget)
|
||||
$('.item.proyecto').css('cursor', 'wait')
|
||||
this.loading.precios = true
|
||||
const proyecto_id = element.data('proyecto')
|
||||
this.get().tipos(proyecto_id)
|
||||
})
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
proyectos.setup()
|
||||
})
|
||||
</script>
|
||||
@endpush
|
||||
|
@ -3,7 +3,7 @@
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h2 class="ui header">Nueva Venta</h2>
|
||||
<form class="ui form" id="add_form" action="{{$urls->base}}/ventas/add" method="post">
|
||||
<form class="ui form" id="add_form" action="{{$urls->api}}/ventas/add" method="post">
|
||||
<label for="fecha_venta">Fecha de Venta</label>
|
||||
<div class="inline field">
|
||||
<div class="ui calendar" id="fecha_venta_calendar">
|
||||
|
@ -75,48 +75,46 @@
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
class Unidad {
|
||||
data = {
|
||||
id: 0,
|
||||
nombre: '',
|
||||
fecha: '',
|
||||
precio: 0,
|
||||
superficie: 0,
|
||||
tipo: '',
|
||||
linea: 0
|
||||
}
|
||||
id
|
||||
nombre
|
||||
fecha
|
||||
precio
|
||||
superficie
|
||||
tipo
|
||||
linea
|
||||
|
||||
constructor({id, nombre, fecha, precio, superficie, tipo, linea}) {
|
||||
this.data.id = id
|
||||
this.data.nombre = nombre
|
||||
this.data.fecha = fecha
|
||||
this.data.precio = precio
|
||||
this.data.superficie = superficie
|
||||
this.data.tipo = tipo
|
||||
this.data.linea = linea
|
||||
this.id = id
|
||||
this.nombre = nombre
|
||||
this.fecha = fecha
|
||||
this.precio = precio
|
||||
this.superficie = superficie
|
||||
this.tipo = tipo
|
||||
this.linea = linea
|
||||
}
|
||||
|
||||
unitario() {
|
||||
return this.data.precio / this.data.superficie
|
||||
get unitario() {
|
||||
return this.precio / this.superficie
|
||||
}
|
||||
draw(formatter) {
|
||||
const date = new Date(this.data.fecha)
|
||||
const date = new Date(this.fecha)
|
||||
const dateFormatter = new Intl.DateTimeFormat('es-CL')
|
||||
return $('<tr></tr>').addClass('unidad').attr('data-linea', this.data.linea).append(
|
||||
$('<td></td>').html(this.data.nombre)
|
||||
return $('<tr></tr>').addClass('unidad').attr('data-linea', this.linea).append(
|
||||
$('<td></td>').html(this.nombre)
|
||||
).append(
|
||||
$('<td></td>')
|
||||
).append(
|
||||
$('<td></td>').html(dateFormatter.format(date))
|
||||
).append(
|
||||
$('<td></td>').html(formatter.format(this.data.precio) + ' UF')
|
||||
$('<td></td>').html(formatter.format(this.precio) + ' UF')
|
||||
).append(
|
||||
$('<td></td>').html(formatter.format(this.unitario()) + ' UF/m²')
|
||||
$('<td></td>').html(formatter.format(this.unitario) + ' UF/m²')
|
||||
).append(
|
||||
$('<td></td>').append(
|
||||
$('<button></button>').addClass('ui tiny green icon button add_unidad')
|
||||
.attr('data-id', this.data.id)
|
||||
.attr('data-tipo', this.data.tipo)
|
||||
.attr('data-unidad', this.data.nombre).append(
|
||||
.attr('data-id', this.id)
|
||||
.attr('data-tipo', this.tipo)
|
||||
.attr('data-unidad', this.nombre).append(
|
||||
$('<i></i>').addClass('plus icon')
|
||||
).click(precios.actions().add().unidad)
|
||||
)
|
||||
@ -124,36 +122,36 @@
|
||||
}
|
||||
}
|
||||
class Linea {
|
||||
data = {
|
||||
id: 0,
|
||||
nombre: '',
|
||||
orientacion: '',
|
||||
superficie: 0,
|
||||
unidades: [],
|
||||
}
|
||||
id
|
||||
nombre
|
||||
orientacion
|
||||
superficie
|
||||
|
||||
unidades
|
||||
|
||||
constructor({id, nombre, orientacion, superficie}) {
|
||||
this.data.id = id
|
||||
this.data.nombre = nombre
|
||||
this.data.orientacion = orientacion
|
||||
this.data.superficie = superficie
|
||||
this.id = id
|
||||
this.nombre = nombre
|
||||
this.orientacion = orientacion
|
||||
this.superficie = superficie
|
||||
this.unidades = []
|
||||
}
|
||||
|
||||
precio() {
|
||||
get precio() {
|
||||
let sum = 0
|
||||
this.data.unidades.forEach(unidad => {
|
||||
sum += unidad.data.precio
|
||||
this.unidades.forEach(unidad => {
|
||||
sum += unidad.precio
|
||||
})
|
||||
return sum / this.data.unidades.length
|
||||
return sum / this.unidades.length
|
||||
}
|
||||
unitario() {
|
||||
return this.precio() / this.data.superficie
|
||||
get unitario() {
|
||||
return this.precio / this.superficie
|
||||
}
|
||||
add(data) {
|
||||
if (this.data.id !== data.unidad.subtipo) {
|
||||
if (this.id !== data.unidad.subtipo) {
|
||||
return
|
||||
}
|
||||
let unidad = this.data.unidades.find(unidad => unidad.data.id === data.unidad.id)
|
||||
let unidad = this.unidades.find(unidad => unidad.id === data.unidad.id)
|
||||
if (typeof unidad !== 'undefined') {
|
||||
return
|
||||
}
|
||||
@ -163,28 +161,28 @@
|
||||
nombre: data.unidad.descripcion,
|
||||
fecha: data.estado_precio.fecha,
|
||||
precio: data.valor,
|
||||
superficie: this.data.superficie,
|
||||
superficie: this.superficie,
|
||||
tipo: tipo.charAt(0).toUpperCase() + tipo.slice(1),
|
||||
linea: this.data.id
|
||||
linea: this.id
|
||||
})
|
||||
this.data.unidades.push(unidad)
|
||||
this.unidades.push(unidad)
|
||||
}
|
||||
draw(formatter) {
|
||||
const row1 = $('<tr></tr>').attr('data-id', this.data.id).attr('data-status', 'closed').append(
|
||||
$('<td></td>').addClass('linea').append($('<strong></strong>').html(this.data.nombre)).append(
|
||||
const row1 = $('<tr></tr>').attr('data-id', this.id).attr('data-status', 'closed').append(
|
||||
$('<td></td>').addClass('linea').append($('<strong></strong>').html(this.nombre)).append(
|
||||
$('<i></i>').addClass('right caret icon')
|
||||
)
|
||||
).append(
|
||||
$('<td></td>').addClass('linea').append($('<strong></strong>').html(this.data.orientacion))
|
||||
$('<td></td>').addClass('linea').append($('<strong></strong>').html(this.orientacion))
|
||||
).append(
|
||||
$('<td></td>').addClass('linea')
|
||||
).append(
|
||||
$('<td></td>').addClass('linea').append($('<strong></strong>').html(formatter.format(this.precio()) + ' UF'))
|
||||
$('<td></td>').addClass('linea').append($('<strong></strong>').html(formatter.format(this.precio) + ' UF'))
|
||||
).append(
|
||||
$('<td></td>').addClass('linea').append($('<strong></strong>').html(formatter.format(this.unitario()) + ' UF/m²'))
|
||||
$('<td></td>').addClass('linea').append($('<strong></strong>').html(formatter.format(this.unitario) + ' UF/m²'))
|
||||
).append(
|
||||
$('<td></td>').append(
|
||||
$('<button></button>').addClass('ui tiny green icon button add_linea').attr('data-id', this.data.id).append(
|
||||
$('<button></button>').addClass('ui tiny green icon button add_linea').attr('data-id', this.id).append(
|
||||
$('<i></i>').addClass('plus icon')
|
||||
).click(precios.actions().add().linea)
|
||||
)
|
||||
@ -192,90 +190,93 @@
|
||||
const output = [
|
||||
row1
|
||||
]
|
||||
this.data.unidades.forEach(unidad => {
|
||||
this.unidades.forEach(unidad => {
|
||||
output.push(unidad.draw(formatter))
|
||||
})
|
||||
return output
|
||||
}
|
||||
|
||||
}
|
||||
class Tipologia {
|
||||
data = {
|
||||
id: 0,
|
||||
tipo: '',
|
||||
nombre: '',
|
||||
descripcion: '',
|
||||
lineas: [],
|
||||
superficie: 0,
|
||||
}
|
||||
id
|
||||
tipo
|
||||
nombre
|
||||
descripcion
|
||||
lineas
|
||||
|
||||
superficie
|
||||
|
||||
constructor({id, tipo, nombre, descripcion, superficie}) {
|
||||
this.data.id = id
|
||||
this.data.tipo = tipo
|
||||
this.data.nombre = nombre
|
||||
this.data.descripcion = descripcion
|
||||
this.data.superficie = superficie
|
||||
this.id = id
|
||||
this.tipo = tipo
|
||||
this.nombre = nombre
|
||||
this.descripcion = descripcion
|
||||
this.superficie = superficie
|
||||
|
||||
this.lineas = []
|
||||
}
|
||||
count() {
|
||||
return this.data.lineas.reduce((sum, linea) => {
|
||||
return sum + linea.data.unidades.length
|
||||
get count() {
|
||||
return this.lineas.reduce((sum, linea) => {
|
||||
return sum + linea.unidades.length
|
||||
}, 0)
|
||||
}
|
||||
precio() {
|
||||
get precio() {
|
||||
let sum = 0
|
||||
this.data.lineas.forEach(linea => {
|
||||
sum += linea.precio()
|
||||
this.lineas.forEach(linea => {
|
||||
sum += linea.precio
|
||||
})
|
||||
return sum / this.data.lineas.length
|
||||
return sum / this.lineas.length
|
||||
}
|
||||
unitario() {
|
||||
return this.precio() / this.data.superficie
|
||||
get unitario() {
|
||||
return this.precio / this.superficie
|
||||
}
|
||||
add(data) {
|
||||
if (this.data.id !== data.unidad.proyecto_tipo_unidad.id) {
|
||||
if (this.id !== data.unidad.proyecto_tipo_unidad.id) {
|
||||
return
|
||||
}
|
||||
let linea = this.data.lineas.find(linea => linea.data.id === data.unidad.subtipo)
|
||||
if (this.data.lineas.length === 0 || typeof linea === 'undefined') {
|
||||
let linea = this.lineas.find(linea => linea.id === data.unidad.subtipo)
|
||||
if (this.lineas.length === 0 || typeof linea === 'undefined') {
|
||||
linea = new Linea({
|
||||
id: data.unidad.subtipo,
|
||||
nombre: 'Linea ' + data.unidad.subtipo,
|
||||
orientacion: data.unidad.orientacion,
|
||||
superficie: data.unidad.proyecto_tipo_unidad.vendible
|
||||
})
|
||||
this.data.lineas.push(linea)
|
||||
this.lineas.push(linea)
|
||||
}
|
||||
linea.add(data)
|
||||
}
|
||||
draw(formatter) {
|
||||
const output = []
|
||||
const row1 = $('<tr></tr>').attr('data-status', 'closed').attr('data-id', this.data.id)
|
||||
const row1 = $('<tr></tr>').attr('data-status', 'closed').attr('data-id', this.id)
|
||||
row1.append(
|
||||
$('<td></td>').addClass('show-unidades').html(this.data.tipo).append(
|
||||
$('<td></td>').addClass('show-unidades').html(this.tipo).append(
|
||||
$('<i></i>').addClass('right caret icon')
|
||||
)
|
||||
).append(
|
||||
$('<td></td>').addClass('show-unidades').html(this.data.nombre)
|
||||
$('<td></td>').addClass('show-unidades').html(this.nombre)
|
||||
).append(
|
||||
$('<td></td>').addClass('show-unidades').html(this.data.descripcion)
|
||||
$('<td></td>').addClass('show-unidades').html(this.descripcion)
|
||||
).append(
|
||||
$('<td></td>').addClass('show-unidades').html(this.data.lineas.map(linea => linea.data.id).sort((a, b) => parseInt(a) - parseInt(b)).join(' - '))
|
||||
$('<td></td>').addClass('show-unidades').html(this.lineas.map(linea => linea.id).sort((a, b) => parseInt(a) - parseInt(b)).join(' - '))
|
||||
).append(
|
||||
$('<td></td>').addClass('show-unidades').html(formatter.format(this.data.superficie) + ' m²')
|
||||
$('<td></td>').addClass('show-unidades').html(formatter.format(this.superficie) + ' m²')
|
||||
).append(
|
||||
$('<td></td>').addClass('show-unidades').html(this.count())
|
||||
$('<td></td>').addClass('show-unidades').html(this.count)
|
||||
).append(
|
||||
$('<td></td>').addClass('show-unidades').html(formatter.format(this.precio()) + ' UF')
|
||||
$('<td></td>').addClass('show-unidades').html(formatter.format(this.precio) + ' UF')
|
||||
).append(
|
||||
$('<td></td>').addClass('show-unidades').html(formatter.format(this.unitario()) + ' UF/m²')
|
||||
$('<td></td>').addClass('show-unidades').html(formatter.format(this.unitario) + ' UF/m²')
|
||||
).append(
|
||||
$('<td></td>').append(
|
||||
$('<button></button>').addClass('ui tiny green icon button add_tipologia').attr('data-id', this.data.id).attr('data-tipologia', this.data.nombre).append(
|
||||
$('<button></button>').addClass('ui tiny green icon button add_tipologia').attr('data-id', this.id).attr('data-tipologia', this.nombre).append(
|
||||
$('<i></i>').addClass('plus icon')
|
||||
).click(precios.actions().add().tipologia)
|
||||
)
|
||||
)
|
||||
const row2 = $('<tr></tr>').addClass('unidades').attr('data-tipo', this.data.id)
|
||||
const row2 = $('<tr></tr>').addClass('unidades').attr('data-tipo', this.id)
|
||||
const tbody = $('<tbody></tbody>')
|
||||
this.data.lineas.forEach(linea => {
|
||||
this.lineas.forEach(linea => {
|
||||
linea.draw(formatter).forEach(row => {
|
||||
tbody.append(row)
|
||||
})
|
||||
@ -308,6 +309,7 @@
|
||||
return output
|
||||
}
|
||||
}
|
||||
|
||||
const precios = {
|
||||
ids: {
|
||||
list: '',
|
||||
@ -379,7 +381,7 @@
|
||||
add: function() {
|
||||
return {
|
||||
precio: data => {
|
||||
let tipologia = this.data.precios.find(tipologia => tipologia.data.id === data.unidad.proyecto_tipo_unidad.id)
|
||||
let tipologia = this.data.precios.find(tipologia => tipologia.id === data.unidad.proyecto_tipo_unidad.id)
|
||||
if (this.data.precios.length === 0 || typeof tipologia === 'undefined') {
|
||||
const tipo = data.unidad.proyecto_tipo_unidad.tipo_unidad.descripcion
|
||||
tipologia = new Tipologia({
|
||||
@ -495,13 +497,16 @@
|
||||
const unidades = $(".unidades[data-tipo='" + id + "']")
|
||||
if (status === 'closed') {
|
||||
unidades.show()
|
||||
|
||||
row.attr('data-status', 'open')
|
||||
row.find('.caret.icon').removeClass('right').addClass('down')
|
||||
return
|
||||
}
|
||||
unidades.find('.linea').data('status', 'closed')
|
||||
unidades.find('.linea').parent().attr('data-status', 'closed')
|
||||
unidades.find('.linea').find('.caret.icon').removeClass('down').addClass('right')
|
||||
unidades.find('.unidad').hide()
|
||||
unidades.hide()
|
||||
|
||||
row.attr('data-status', 'closed')
|
||||
row.find('.caret.icon').removeClass('down').addClass('right')
|
||||
},
|
||||
@ -513,11 +518,13 @@
|
||||
const unidades = $(".unidad[data-linea='" + id + "']")
|
||||
if (status === 'closed') {
|
||||
unidades.show()
|
||||
|
||||
row.attr('data-status', 'open')
|
||||
row.find('.caret.icon').removeClass('right').addClass('down')
|
||||
return
|
||||
}
|
||||
unidades.hide()
|
||||
|
||||
row.attr('data-status', 'closed')
|
||||
row.find('.caret.icon').removeClass('down').addClass('right')
|
||||
}
|
||||
@ -576,7 +583,13 @@
|
||||
},
|
||||
}
|
||||
},
|
||||
setup: function() {
|
||||
setup: function({list, proyectos, buttons_up, buttons_refresh, buttons_add}) {
|
||||
this.ids.list = list
|
||||
this.ids.proyectos = proyectos
|
||||
this.ids.buttons.up = buttons_up
|
||||
this.ids.buttons.refresh = buttons_refresh
|
||||
this.ids.buttons.add = buttons_add
|
||||
|
||||
$(this.ids.buttons.up).click(this.actions().up)
|
||||
$(this.ids.buttons.refresh).click(this.actions().refresh)
|
||||
$(this.ids.buttons.add).click(this.actions().add().list)
|
||||
@ -584,7 +597,6 @@
|
||||
this.draw().proyectos()
|
||||
}
|
||||
}
|
||||
|
||||
const list_modal = {
|
||||
ids: {
|
||||
modal: '',
|
||||
@ -644,7 +656,15 @@
|
||||
$(this.ids.modal).find("input[name='type']").val(this.data.type)
|
||||
$(this.ids.modal).find("input[name='id']").val(this.data.id)
|
||||
},
|
||||
setup: function() {
|
||||
setup: function({modal, title, fields_type, fields_id, fields_calendar, fields_valor, button}) {
|
||||
this.ids.modal = modal
|
||||
this.ids.title = title
|
||||
this.ids.fields.type = fields_type
|
||||
this.ids.fields.id = fields_id
|
||||
this.ids.fields.calendar = fields_calendar
|
||||
this.ids.fields.valor = fields_valor
|
||||
this.ids.button = button
|
||||
|
||||
$(this.ids.modal).modal('hide')
|
||||
$(this.ids.modal).find('.icon.button').find('.close.icon').parent().click(this.actions().close)
|
||||
|
||||
@ -656,21 +676,22 @@
|
||||
}
|
||||
|
||||
$(document).ready(() => {
|
||||
precios.ids.list = '#list'
|
||||
precios.ids.proyectos = '#proyectos'
|
||||
precios.ids.buttons.up = '#up_button'
|
||||
precios.ids.buttons.refresh = '#refresh_button'
|
||||
precios.ids.buttons.add = '#add_button'
|
||||
precios.setup()
|
||||
|
||||
list_modal.ids.modal = '#list_modal'
|
||||
list_modal.ids.title = '#modal_title'
|
||||
list_modal.ids.fields.type = "input[name='type']"
|
||||
list_modal.ids.fields.id = "input[name='id']"
|
||||
list_modal.ids.fields.calendar = '#fecha'
|
||||
list_modal.ids.fields.valor = '#valor'
|
||||
list_modal.ids.button = '#send'
|
||||
list_modal.setup()
|
||||
precios.setup({
|
||||
list: '#list',
|
||||
proyectos: '#proyectos',
|
||||
buttons_up: '#up_button',
|
||||
buttons_refresh: '#refresh_button',
|
||||
buttons_add: '#add_button'
|
||||
})
|
||||
list_modal.setup({
|
||||
modal: '#list_modal',
|
||||
title: '#modal_title',
|
||||
fields_type: "input[name='type']",
|
||||
fields_id: "input[name='id']",
|
||||
fields_calendar: '#fecha',
|
||||
fields_valor: '#valor',
|
||||
button: '#send'
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
||||
|
@ -21,6 +21,19 @@ class Proyectos
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function escriturando(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'total' => 0,
|
||||
'proyectos' => []
|
||||
];
|
||||
try {
|
||||
$proyectos = $proyectoRepository->fetchAllEscriturando();
|
||||
$output['proyectos'] = $proyectos;
|
||||
$output['total'] = count($proyectos);
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function unidades(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = ['proyecto_id' => $proyecto_id, 'unidades' => [], 'total' => 0];
|
||||
|
138
app/src/Controller/API/Ventas.php
Normal file
138
app/src/Controller/API/Ventas.php
Normal file
@ -0,0 +1,138 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Ventas
|
||||
{
|
||||
use withJson;
|
||||
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta $service): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$output = [
|
||||
'proyecto' => [
|
||||
'id' => $proyecto_id
|
||||
],
|
||||
'total' => 0
|
||||
];
|
||||
try {
|
||||
$ventas = $service->fetchActivaByProyecto($proyecto_id);
|
||||
$output['ventas'] = array_map(function(Model\Venta $venta) {return $venta->id;}, $ventas);
|
||||
$output['proyecto']['descripcion'] = $ventas[0]->proyecto()->descripcion;
|
||||
$output['total'] = count($ventas);
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, int $venta_id): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$venta = $service->getById($venta_id);
|
||||
$output = compact('venta');
|
||||
} catch (EmptyResult $exception) {
|
||||
$output = [
|
||||
'error' => [
|
||||
'code' => $exception->getCode(),
|
||||
'message' => str_replace([PHP_EOL, "\r"], [' ', ''], $exception->getMessage())
|
||||
]
|
||||
];
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function porFirmar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
'promesas' => 0
|
||||
];
|
||||
try {
|
||||
$ventas = $ventaService->getByProyecto($proyecto_id);
|
||||
$promesas = array_filter($ventas, function(Model\Venta $venta) {
|
||||
return $venta->currentEstado()->tipoEstadoVenta->descripcion === 'vigente';
|
||||
});
|
||||
$output['promesas'] = count($promesas);
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function escrituras(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
'escrituras' => [
|
||||
'firmar' => 0,
|
||||
'pagar' => 0,
|
||||
'abonar' => 0
|
||||
]
|
||||
];
|
||||
try {
|
||||
$ventas = $ventaService->getEscriturasByProyecto($proyecto_id);
|
||||
$porFirmar = array_filter($ventas, function(Model\Venta $venta) {
|
||||
return $venta->currentEstado()->tipoEstadoVenta->descripcion === 'escriturando';
|
||||
});
|
||||
$output['escrituras']['firmar'] = count($porFirmar);
|
||||
unset($porFirmar);
|
||||
$escrituras = array_filter($ventas, function(Model\Venta $venta) {
|
||||
return $venta->currentEstado()->tipoEstadoVenta->descripcion === 'firmado por inmobiliaria';
|
||||
});
|
||||
unset($ventas);
|
||||
$porPagar = array_filter($escrituras, function(Model\Venta $venta) use ($pagoService) {
|
||||
$pagos = $pagoService->getByVenta($venta->id);
|
||||
$porPagar = array_filter($pagos, function(Model\Venta\Pago $pago) {
|
||||
return $pago->currentEstado->tipoEstadoPago->descripcion === 'no pagado';
|
||||
});
|
||||
return count($porPagar) > 0;
|
||||
});
|
||||
$output['escrituras']['pagar'] = count($porPagar);
|
||||
unset($porPagar);
|
||||
$porAbonar = array_filter($escrituras, function(Model\Venta $venta) use ($pagoService) {
|
||||
$pagos = $pagoService->getByVenta($venta->id);
|
||||
$porPagar = array_filter($pagos, function(Model\Venta\Pago $pago) {
|
||||
return $pago->currentEstado->tipoEstadoPago->descripcion === 'depositado';
|
||||
});
|
||||
return count($porPagar) > 0;
|
||||
});
|
||||
$output['escrituras']['abonar'] = count($porAbonar);
|
||||
unset($porAbonar);
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function comentarios(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, Repository\Venta\Comentario $comentarioRepository, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $service->getById($venta_id);
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$comentarios = $comentarioRepository->fetchByVenta($venta->id);
|
||||
$output['total'] = count($comentarios);
|
||||
$output['comentarios'] = $comentarios;
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService): ResponseInterface
|
||||
{
|
||||
$data = $request->getParsedBody();
|
||||
$output = [
|
||||
'status' => false,
|
||||
'errors' => []
|
||||
];
|
||||
try {
|
||||
$ventaService->add($data);
|
||||
$output['status'] = true;
|
||||
} catch (\Exception $exception) {
|
||||
$output['errors'] = $exception;
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
56
app/src/Controller/API/Ventas/Unidades.php
Normal file
56
app/src/Controller/API/Ventas/Unidades.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?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\withJson;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Unidades
|
||||
{
|
||||
use withJson;
|
||||
|
||||
public function disponibles(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, Repository\Proyecto\TipoUnidad $tipoUnidadRepository): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$output = [
|
||||
'proyecto_id' => $proyecto_id,
|
||||
'unidades' => [
|
||||
'total' => [
|
||||
'departamentos' => 0,
|
||||
'estacionamientos' => 0,
|
||||
'bodegas' => 0,
|
||||
],
|
||||
'departamentos' => 0,
|
||||
'estacionamientos' => 0,
|
||||
'bodegas' => 0,
|
||||
]
|
||||
];
|
||||
try {
|
||||
$totalUnidades = $unidadRepository->fetchByProyecto($proyecto_id);
|
||||
$unidades = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
|
||||
|
||||
$tiposUnidades = $tipoUnidadRepository->fetchAll();
|
||||
foreach ($tiposUnidades as $tipoUnidad) {
|
||||
$tempUnidades = array_filter($totalUnidades, function(Model\Venta\Unidad $unidad) use ($tipoUnidad) {
|
||||
return $unidad->proyectoTipoUnidad->tipoUnidad->id === $tipoUnidad->id;
|
||||
});
|
||||
if (count($tempUnidades) > 0) {
|
||||
$output['unidades']['total']["{$tipoUnidad->descripcion}s"] = count($tempUnidades);
|
||||
}
|
||||
$tempUnidades = array_filter($unidades, function(Model\Venta\Unidad $unidad) use ($tipoUnidad) {
|
||||
return $unidad->proyectoTipoUnidad->tipoUnidad->id === $tipoUnidad->id;
|
||||
});
|
||||
if (count($tempUnidades) === 0) {
|
||||
continue;
|
||||
}
|
||||
$output['unidades']["{$tipoUnidad->descripcion}s"] = count($tempUnidades);
|
||||
}
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
@ -28,39 +28,6 @@ class Ventas
|
||||
$venta = $service->getByProyectoAndUnidad($proyecto_nombre, $unidad_descripcion);
|
||||
return $view->render($response, 'ventas.show', compact('venta'));
|
||||
}
|
||||
public function proyecto(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta $service): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$proyecto_id = $json->proyecto_id;
|
||||
$output = [
|
||||
'proyecto' => [
|
||||
'id' => $proyecto_id
|
||||
],
|
||||
'total' => 0
|
||||
];
|
||||
try {
|
||||
$ventas = $service->fetchActivaByProyecto($proyecto_id);
|
||||
$output['ventas'] = array_map(function(Model\Venta $venta) {return $venta->id;}, $ventas);
|
||||
$output['proyecto']['descripcion'] = $ventas[0]->proyecto()->descripcion;
|
||||
$output['total'] = count($ventas);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, int $venta_id): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$venta = $service->getById($venta_id);
|
||||
$response->getBody()->write(json_encode(compact('venta')));
|
||||
} catch (EmptyResult $exception) {
|
||||
$response->getBody()->write(json_encode(['error' => [
|
||||
'code' => $exception->getCode(),
|
||||
'message' => str_replace([PHP_EOL, "\r"], [' ', ''], $exception->getMessage())
|
||||
]]));
|
||||
}
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $service, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $service->getById($venta_id);
|
||||
@ -90,18 +57,6 @@ class Ventas
|
||||
}
|
||||
return $view->render($response, 'ventas.propiedades.edit', compact('propiedad', 'proyecto', 'tiposUnidades', 'unidades', 'venta_id'));
|
||||
}
|
||||
public function comentarios(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $service, Repository\Venta\Comentario $comentarioRepository, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $service->getById($venta_id);
|
||||
$output = ['total' => 0];
|
||||
try {
|
||||
$comentarios = $comentarioRepository->fetchByVenta($venta->id);
|
||||
$output['total'] = count($comentarios);
|
||||
$output['comentarios'] = $comentarios;
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Region $regionRepository, Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
{
|
||||
$regiones = $regionRepository->fetchAll();
|
||||
@ -111,22 +66,6 @@ class Ventas
|
||||
$proyectos = $proyectoRepository->fetchAllActive();
|
||||
return $view->render($response, 'ventas.add', compact('regiones', 'proyectos'));
|
||||
}
|
||||
public function doAdd(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService): ResponseInterface
|
||||
{
|
||||
$data = $request->getParsedBody();
|
||||
$output = [
|
||||
'status' => false,
|
||||
'errors' => []
|
||||
];
|
||||
try {
|
||||
$ventaService->add($data);
|
||||
$output['status'] = true;
|
||||
} catch (\Exception $exception) {
|
||||
$output['errors'] = $exception;
|
||||
}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function cuotas(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, View $view, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $ventaService->getById($venta_id);
|
||||
|
@ -7,7 +7,7 @@ use Incoviba\Model;
|
||||
class ProyectoTipoUnidad extends Ideal\Model
|
||||
{
|
||||
public Model\Proyecto $proyecto;
|
||||
public Model\Venta\TipoUnidad $tipoUnidad;
|
||||
public Model\Proyecto\TipoUnidad $tipoUnidad;
|
||||
public string $nombre;
|
||||
public string $abreviacion;
|
||||
public float $util;
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
namespace Incoviba\Model\Proyecto;
|
||||
|
||||
use Incoviba\Model;
|
||||
|
@ -11,7 +11,8 @@ class Proyecto extends Ideal\Repository
|
||||
public function __construct(
|
||||
Define\Connection $connection,
|
||||
protected Inmobiliaria $inmobiliariaRepository,
|
||||
protected Direccion $direccionRepository
|
||||
protected Direccion $direccionRepository,
|
||||
protected Proyecto\Etapa $etapaRepository
|
||||
)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
@ -71,13 +72,44 @@ class Proyecto extends Ideal\Repository
|
||||
}
|
||||
public function fetchAllActive(): array
|
||||
{
|
||||
$etapaProyecto = $this->etapaRepository->fetchByDescripcion('Proyecto');
|
||||
$etapaTerminado = $this->etapaRepository->fetchByDescripcion('Terminado');
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN (SELECT e1.* FROM `estado_proyecto` e1 JOIN (SELECT MAX(`id`) AS 'id', `proyecto` FROM `estado_proyecto` GROUP BY `proyecto`) e0 ON e0.`id` = e1.`id`) ep ON ep.`proyecto` = a.`id`
|
||||
JOIN `tipo_estado_proyecto` tep ON tep.`id` = ep.`estado`
|
||||
JOIN `etapa_proyecto` et ON et.`id` = tep.`etapa`
|
||||
WHERE et.`orden` BETWEEN 4 AND 8
|
||||
{$this->joinEstado()}
|
||||
WHERE et.`orden` BETWEEN {$etapaProyecto->orden} AND ({$etapaTerminado->orden} - 1)
|
||||
ORDER BY a.`descripcion`";
|
||||
return $this->fetchMany($query);
|
||||
}
|
||||
public function fetchAllEscriturando(): array
|
||||
{
|
||||
$etapaRecepcion = $this->etapaRepository->fetchByDescripcion('Recepción');
|
||||
$etapaTerminado = $this->etapaRepository->fetchByDescripcion('Terminado');
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
{$this->joinEstado()}
|
||||
WHERE et.`orden` BETWEEN {$etapaRecepcion->orden} AND ({$etapaTerminado->orden} - 1)
|
||||
ORDER BY a.`descripcion`";
|
||||
return $this->fetchMany($query);
|
||||
}
|
||||
|
||||
protected function joinEstado(): string
|
||||
{
|
||||
return "JOIN (
|
||||
SELECT e2.*
|
||||
FROM `estado_proyecto` e2
|
||||
JOIN (
|
||||
SELECT MAX(e1.`id`) AS 'id', e1.`proyecto`
|
||||
FROM `estado_proyecto` e1
|
||||
JOIN (
|
||||
SELECT MAX(`id`) AS 'id', `proyecto`, `fecha`
|
||||
FROM `estado_proyecto`
|
||||
GROUP BY `proyecto`, `fecha`
|
||||
) e0 ON e1.`id` = e0.`id`
|
||||
GROUP BY `proyecto`
|
||||
) e01 ON e01.`id` = e2.`id`
|
||||
) ep ON ep.`proyecto` = a.`id`
|
||||
JOIN `tipo_estado_proyecto` tep ON tep.`id` = ep.`estado`
|
||||
JOIN `etapa_proyecto` et ON et.`id` = tep.`etapa`";
|
||||
}
|
||||
}
|
||||
|
@ -28,4 +28,10 @@ class Etapa extends Ideal\Repository
|
||||
{
|
||||
return $this->update($model, ['descripcion', 'orden'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByDescripcion(string $descripcion): Model\Proyecto\Etapa
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `descripcion` = ?";
|
||||
return $this->fetchOne($query, [$descripcion]);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ use Incoviba\Repository;
|
||||
|
||||
class ProyectoTipoUnidad extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Proyecto $proyectoRepository, protected Repository\Venta\TipoUnidad $tipoUnidadRepository)
|
||||
public function __construct(Define\Connection $connection, protected Repository\Proyecto $proyectoRepository, protected Repository\Proyecto\TipoUnidad $tipoUnidadRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('proyecto_tipo_unidad');
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
namespace Incoviba\Repository\Proyecto;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
@ -17,7 +17,7 @@ class TipoUnidad extends Ideal\Repository
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = new Implement\Repository\MapperParser(['descripcion', 'orden']);
|
||||
return $this->parseData(new Model\Venta\TipoUnidad(), $data, $map);
|
||||
return $this->parseData(new Model\Proyecto\TipoUnidad(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
@ -220,4 +220,17 @@ FROM `{$this->getTable()}` a
|
||||
WHERE CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE ?";
|
||||
return $this->fetchMany($query, [$propietario]);
|
||||
}
|
||||
public function fetchEscriturasByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = "SELECT DISTINCT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`
|
||||
JOIN `unidad` ON `unidad`.`id` = pu.`unidad`
|
||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`id`
|
||||
JOIN (SELECT e1.* FROM `estado_venta` e1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) e0 ON e0.`id` = e1.`id`) ev ON ev.`venta` = a.`id`
|
||||
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
|
||||
WHERE ptu.`proyecto` = ? AND tev.`descripcion` IN ('firmado por inmobiliaria', 'escriturando')
|
||||
GROUP BY a.`id`";
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
}
|
||||
|
@ -60,4 +60,44 @@ class Pago extends Ideal\Repository
|
||||
{
|
||||
return $this->update($model, ['valor', 'banco', 'tipo', 'identificador', 'fecha', 'uf', 'pagador', 'asociado'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByVenta(int $venta_id): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM (
|
||||
SELECT a.*, venta.id AS venta_id, 'cuota' AS fuente
|
||||
FROM pago a
|
||||
JOIN cuota ON cuota.pago = a.id
|
||||
JOIN venta ON venta.pie = cuota.pie
|
||||
UNION ALL
|
||||
SELECT a.*, venta.id AS venta_id, 'reajuste' AS fuente
|
||||
FROM pago a
|
||||
JOIN pie ON pie.reajuste = a.id
|
||||
JOIN venta ON venta.pie = pie.id
|
||||
UNION ALL
|
||||
SELECT a.*, venta.id AS venta_id, 'credito' AS fuente
|
||||
FROM pago a
|
||||
JOIN credito ON credito.pago = a.id
|
||||
JOIN venta ON venta.credito = credito.id
|
||||
UNION ALL
|
||||
SELECT a.*, venta.id AS venta_id, 'escritura' AS fuente
|
||||
FROM pago a
|
||||
JOIN escritura ON escritura.pago = a.id
|
||||
JOIN venta ON venta.escritura = escritura.id
|
||||
UNION ALL
|
||||
SELECT a.*, venta.id AS venta_id, 'subsidio' AS fuente
|
||||
FROM pago a
|
||||
JOIN subsidio ON subsidio.subsidio = a.id
|
||||
JOIN venta ON venta.subsidio = subsidio.id
|
||||
UNION ALL
|
||||
SELECT a.*, venta.id AS venta_id, 'ahorro' AS fuente
|
||||
FROM pago a
|
||||
JOIN subsidio ON subsidio.pago = a.id
|
||||
JOIN venta ON venta.subsidio = subsidio.id
|
||||
) a
|
||||
JOIN (SELECT e1.* FROM estado_pago e1 JOIN (SELECT MAX(id) AS id, pago FROM estado_pago GROUP BY pago) e0 ON e0.id = e1.id) ep ON ep.pago = a.id
|
||||
JOIN tipo_estado_pago tep ON tep.id = ep.estado
|
||||
WHERE venta_id = ?";
|
||||
return $this->fetchMany($query, [$venta_id]);
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,12 @@
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Search
|
||||
{
|
||||
public function __construct(protected Venta $ventaService, protected Repository\Venta $ventaRepository, protected Repository\Venta\Unidad $unidadRepository, protected Repository\Venta\TipoUnidad $tipoUnidadRepository) {}
|
||||
public function __construct(protected Venta $ventaService, protected Repository\Venta $ventaRepository, protected Repository\Venta\Unidad $unidadRepository, protected Repository\Proyecto\TipoUnidad $tipoUnidadRepository) {}
|
||||
|
||||
public function query(string $query, string $tipo): array
|
||||
{
|
||||
@ -127,7 +127,7 @@ class Search
|
||||
protected function getTiposUnidades(): array
|
||||
{
|
||||
if (!isset($this->tipos)) {
|
||||
$this->tipos = array_map(function(Model\Venta\TipoUnidad $tipoUnidad) {
|
||||
$this->tipos = array_map(function(Model\Proyecto\TipoUnidad $tipoUnidad) {
|
||||
return $tipoUnidad->descripcion;
|
||||
}, $this->tipoUnidadRepository->fetchAll());
|
||||
}
|
||||
|
@ -28,18 +28,12 @@ class Venta
|
||||
public function getByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$ventas = $this->ventaRepository->fetchByProyecto($proyecto_id);
|
||||
foreach ($ventas as &$venta) {
|
||||
$venta = $this->process($venta);
|
||||
}
|
||||
return $ventas;
|
||||
return array_map([$this, 'process'], $ventas);
|
||||
}
|
||||
public function getActivaByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$ventas = $this->ventaRepository->fetchActivaByProyecto($proyecto_id);
|
||||
foreach ($ventas as &$venta) {
|
||||
$venta = $this->process($venta);
|
||||
}
|
||||
return $ventas;
|
||||
return array_map([$this, 'process'], $ventas);
|
||||
}
|
||||
public function getByProyectoAndUnidad(string $proyecto_nombre, int $unidad_descripcion): Model\Venta
|
||||
{
|
||||
@ -49,26 +43,22 @@ class Venta
|
||||
public function getByUnidad(string $unidad, string $tipo): array
|
||||
{
|
||||
$ventas = $this->ventaRepository->fetchByUnidad($unidad, $tipo);
|
||||
foreach ($ventas as &$venta) {
|
||||
$venta = $this->process($venta);
|
||||
}
|
||||
return $ventas;
|
||||
return array_map([$this, 'process'], $ventas);
|
||||
}
|
||||
public function getByPropietario(string $propietario): array
|
||||
{
|
||||
$ventas = $this->ventaRepository->fetchByPropietario($propietario);
|
||||
foreach ($ventas as &$venta) {
|
||||
$venta = $this->process($venta);
|
||||
}
|
||||
return $ventas;
|
||||
return array_map([$this, 'process'], $ventas);
|
||||
}
|
||||
public function getByPrecio(string $precio): array
|
||||
{
|
||||
$ventas = $this->ventaRepository->fetchByPrecio($precio);
|
||||
foreach ($ventas as &$venta) {
|
||||
$venta = $this->process($venta);
|
||||
}
|
||||
return $ventas;
|
||||
return array_map([$this, 'process'], $ventas);
|
||||
}
|
||||
public function getEscriturasByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$ventas = $this->ventaRepository->fetchEscriturasByProyecto($proyecto_id);
|
||||
return array_map([$this, 'process'], $ventas);
|
||||
}
|
||||
|
||||
protected function process(Model\Venta $venta): Model\Venta
|
||||
|
@ -69,15 +69,12 @@ class Pago
|
||||
public function getById(int $pago_id): Model\Venta\Pago
|
||||
{
|
||||
$pago = $this->pagoRepository->fetchById($pago_id);
|
||||
$pago->estados = $this->estadoPagoRepository->fetchByPago($pago_id);
|
||||
$pago->currentEstado = $this->estadoPagoRepository->fetchCurrentByPago($pago_id);
|
||||
if (($pago->uf === null or $pago->uf === 0.0) and $pago->fecha < new DateTimeImmutable()) {
|
||||
$pago->uf = $this->moneyService->getUF($pago->fecha);
|
||||
if ($pago->uf !== 0.0) {
|
||||
$this->pagoRepository->edit($pago, ['uf' => $pago->uf]);
|
||||
}
|
||||
}
|
||||
return $pago;
|
||||
return $this->process($pago);
|
||||
}
|
||||
|
||||
public function getByVenta(int $venta_id): array
|
||||
{
|
||||
return array_map([$this, 'process'], $this->pagoRepository->fetchByVenta($venta_id));
|
||||
}
|
||||
|
||||
public function getPendientes(): array
|
||||
@ -121,4 +118,17 @@ class Pago
|
||||
$pago->currentEstado = $estado;
|
||||
return $pago;
|
||||
}
|
||||
|
||||
protected function process($pago): Model\Venta\Pago
|
||||
{
|
||||
$pago->estados = $this->estadoPagoRepository->fetchByPago($pago->id);
|
||||
$pago->currentEstado = $this->estadoPagoRepository->fetchCurrentByPago($pago->id);
|
||||
if (($pago->uf === null or $pago->uf === 0.0) and $pago->fecha < new DateTimeImmutable()) {
|
||||
$pago->uf = $this->moneyService->getUF($pago->fecha);
|
||||
if ($pago->uf !== 0.0) {
|
||||
$this->pagoRepository->edit($pago, ['uf' => $pago->uf]);
|
||||
}
|
||||
}
|
||||
return $pago;
|
||||
}
|
||||
}
|
||||
|
@ -41,6 +41,8 @@ services:
|
||||
volumes:
|
||||
- dbdata:/var/lib/mysql
|
||||
- ./incoviba.sql.gz:/docker-entrypoint-initdb.d/incoviba.sql.gz
|
||||
ports:
|
||||
- "33060:3306"
|
||||
networks:
|
||||
- default
|
||||
- adminer_network
|
||||
|
Reference in New Issue
Block a user