Ventas->Listado->Ventas

This commit is contained in:
Juan Pablo Vial
2023-07-28 16:22:20 -04:00
parent 38383f5295
commit ef30ae67d2
52 changed files with 1496 additions and 17 deletions

View File

@ -124,7 +124,7 @@
).append(
$('<div></div>').addClass('content').append(table)
)
const dt = new DataTable(table, {
new DataTable(table, {
order: [[1, 'desc'], [0, 'asc']]
})
}

View File

@ -0,0 +1,141 @@
@extends('layout.base')
@section('page_title')
Cierre - Detalle
@endsection
@section('page_content')
<div class="ui container">
<div class="ui segment">
<h2 class="ui blue header">Cierre {{$cierre->principal()->descripcion}} - {{$cierre->proyecto->descripcion}}</h2>
<div class="ui basic segments">
<div class="ui grid segment">
<div class="two wide column">
Fecha
</div>
<div class="two wide column">
{{$cierre->dateTime->format('d-m-Y')}}
</div>
</div>
<div class="ui inverted grey segment">PROPIETARIO</div>
<div class="ui grid segment">
<div class="row">
<div class="two wide column">
{{$cierre->propietario->rut()}}
</div>
<div class="six wide column">
{{$cierre->propietario->nombreCompleto()}}
</div>
</div>
<div class="row">
<div class="column"></div>
<div class="fifteen wide column">
{{$cierre->propietario->datos->direccion}}
</div>
</div>
</div>
<div class="ui inverted grey segment">PROPIEDAD</div>
<div class="ui segment">
<table class="ui very basic table">
<tbody>
@foreach ($cierre->unidades as $unidad)
<tr>
<td>{{ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}}</td>
<td>{{$unidad->descripcion}}</td>
<td>{{$unidad->proyectoTipoUnidad->nombre}}</td>
<td>{{$unidad->proyectoTipoUnidad->abreviacion}}</td>
<td>{{number_format($unidad->proyectoTipoUnidad->vendible(), 2, ',', '.')}} </td>
<td>{{number_format($unidad->currentPrecio->valor, 2, ',', '.')}} UF</td>
<td>{{number_format($unidad->currentPrecio->valor / $unidad->proyectoTipoUnidad->vendible(), 2, ',', '.')}} UF/</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="ui inverted grey segment">OFERTA</div>
<div class="ui grid segment">
<div class="two wide column">
Precio
</div>
<div class="two wide column">
{{number_format($cierre->precio, 2, ',', '.')}} UF
</div>
</div>
<div class="ui grid segment">
<strong class="two wide column">
Neto
</strong>
<strong class="two wide column">
{{number_format($cierre->neto(), 2, ',', '.')}} UF
</strong>
<strong class="two wide column">
{{number_format($cierre->neto() / $cierre->principal()->vendible, 2, ',', '.')}} UF/
</strong>
<div class="column">
@if ($cierre->neto() / $cierre->principal()->vendible > $cierre->principal()->precio / $cierre->principal()->vendible)
<i class="green check icon"></i>
@else
<i class="red remove icon"></i>
@endif
</div>
</div>
@foreach($cierre->valoresCierre as $valorCierre)
<div class="ui grid segment">
<div class="two wide column">{{ucwords($valorCierre->tipoValorCierre->descripcion)}}</div>
<div class="two wide column">{{number_format($valorCierre->valor, 2, ',', '.')}} UF</div>
<div class="two wide column">{{number_format($valorCierre->valor / $cierre->precio * 100, 2, ',', '.')}}%</div>
</div>
@endforeach
<div class="ui inverted grey segment">DIFERENCIA</div>
<div class="ui grid segment">
<div class="two wide column">Neto</div>
<div class="two wide column">
{{number_format($cierre->neto() - $cierre->principal()->precio, 2, ',', '.')}} UF
</div>
</div>
<div class="ui inverted grey segment">ESTADO</div>
<div class="ui segment">
<div class="ui grid message {{['aprobado' => 'success', 'abandonado' => 'warning', 'promesado' => 'success'][$cierre->current->tipoEstadoCierre->descripcion]}}">
<div class="two wide column">
{{ucwords($cierre->current->tipoEstadoCierre->descripcion)}}
</div>
<div class="four wide column">
{{$cierre->current->fecha->format('d-m-Y')}}
</div>
<div class="right aligned ten wide column">
@if ($cierre->current->tipoEstadoCierre->descripcion === 'aprobado')
<button class="ui icon basic button" data-content="Promesar" id="promesar" data-id="{{$cierre->id}}">
<i class="check icon"></i>
</button>
<button class="ui icon basic button" data-content="Abandonar" id="abandonar" data-id="{{$cierre->id}}">
<i class="remove icon"></i>
</button>
@endif
</div>
</div>
</div>
</div>
</div>
</div>
@endsection
@push('page_scripts')
<script type="text/javascript">
function action(action, cierre_id) {
const url = '{{$urls->base}}/api/cierre/' + cierre_id + '/' + action
console.debug(url)
}
$(document).ready(() => {
$('#promesar').popup().click(event => {
const button = $(event.currentTarget)
const id = button.data('id')
action('promesar', id)
})
$('#abandonar').popup().click(event => {
const button = $(event.currentTarget)
const id = button.data('id')
action('abandonar', id)
})
})
</script>
@endpush

View File

@ -0,0 +1,274 @@
@extends('layout.base')
@section('page_title')
Ventas
@endsection
@section('page_content')
<div class="ui container">
<h2 class="ui header">Listado de Ventas</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 class="ui button" id="up_button">
<i class="up arrow icon"></i>
</button>
<button class="ui button" id="refresh_button">
<i class="refresh icon"></i>
</button>
</div>
</div>
</div>
</h4>
<div class="ui link selection list" id="proyectos"></div>
<table class="ui table" id="data"></table>
</div>
@endsection
@include('layout.head.styles.datatables')
@include('layout.body.scripts.datatables')
@push('page_scripts')
<script type="text/javascript">
class Venta {
id
propiedad
propietario
valor
fecha
estado
constructor({id, propiedad, propietario, valor, fecha, estado}) {
this.id = id
this.propiedad = propiedad
this.propietario = propietario
this.valor = valor
this.fecha = fecha
this.estado = estado
}
draw(formatter, dateFormatter) {
const tipo = this.estado.tipo_estado_venta.descripcion
const date = new Date(this.fecha)
return $('<tr></tr>').append(
$('<td></td>').attr('data-order', this.propiedad.departamentos[0].descripcion).append(
$('<a></a>').attr('href', '{{$urls->base}}/venta/' + this.id).html(this.propiedad.summary)
)
).append(
$('<td></td>').append(
$('<a></a>').attr('href', '{{$urls->base}}/search?tipo=propietario&query=' + encodeURIComponent(this.propietario.nombre_completo)).html(this.propietario.nombre_completo)
)
).append(
$('<td></td>').html(formatter.format(this.valor) + ' UF')
).append(
$('<td></td>').html(this.propiedad.departamentos[0].proyecto_tipo_unidad.abreviacion + ' (' + formatter.format(this.propiedad.departamentos[0].proyecto_tipo_unidad.vendible) + ' m²)')
).append(
$('<td></td>').html(formatter.format(this.valor / this.propiedad.departamentos[0].proyecto_tipo_unidad.vendible) + ' UF/m²')
).append(
$('<td></td>').attr('data-order', this.fecha).html(dateFormatter.format(date))
).append(
$('<td></td>').html(tipo.charAt(0).toUpperCase() + tipo.slice(1))
)
}
}
const ventas = {
ids: {
title: '',
proyectos: '',
table: '',
buttons: {
up: '',
refresh: ''
}
},
data: {
id: 0,
proyecto: '',
proyectos: JSON.parse('{!! json_encode($proyectos) !!}'),
ventas: []
},
loading: {
ventas: false
},
formatters: {
number: new Intl.NumberFormat('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2}),
date: new Intl.DateTimeFormat('es-CL')
},
table: null,
get: function() {
return {
ventas: proyecto_id => {
this.data.ventas = []
return fetch('{{$urls->api}}/ventas',
{method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proyecto_id})}
).then(response => {
this.loading.precios = false
if (response.ok) {
return response.json()
}
}).then(data => {
if (data.total > 0) {
this.data.id = data.ventas[0].propiedad.departamentos[0].proyecto_tipo_unidad.proyecto.id
this.data.proyecto = data.ventas[0].propiedad.departamentos[0].proyecto_tipo_unidad.proyecto.descripcion
data.ventas.forEach(venta => {
this.add().venta(venta)
})
this.draw().ventas()
}
})
}
}
},
add: function() {
return {
venta: data => {
const venta = new Venta({
id: data.id,
propiedad: data.propiedad,
propietario: data.propietario,
valor: data.valor,
fecha: data.fecha,
estado: data.current_estado
})
this.data.ventas.push(venta)
}
}
},
draw: function() {
return {
proyectos: () => {
const title = $(this.ids.title)
const parent = $(this.ids.proyectos)
const table = $(this.ids.table)
table.hide()
parent.html('')
this.loading.ventas = false
if (this.table !== null) {
this.table.destroy()
this.table = null
}
title.html('Proyectos')
this.data.proyectos.forEach(proyecto => {
parent.append(
$('<div></div>').addClass('item proyecto').attr('data-proyecto', proyecto.id).html(proyecto.descripcion).css('cursor', 'pointer')
)
})
parent.show()
parent.find('.item.proyecto').click(this.actions().get)
},
ventas: () => {
const title = $(this.ids.title)
const parent = $(this.ids.proyectos)
const table = $(this.ids.table)
parent.hide()
table.html('')
this.loading.ventas = false
if (this.table !== null) {
this.table.destroy()
this.table = null
}
title.html('Ventas de ' + this.data.proyecto + ' [' + this.data.ventas.length + ']')
const tbody = $('<tbody></tbody>')
this.data.ventas.forEach(venta => {
tbody.append(venta.draw(this.formatters.number, this.formatters.date))
})
table.append(this.draw().header()).append(tbody)
table.show()
this.table = new DataTable(table, {
order: [[0, 'asc']],
})
},
table: () => {
const parent = $(this.ids.proyectos)
const table = $(this.ids.table)
if (table.length > 0) {
return
}
console.debug(parent.parent())
},
header: () => {
return $('<thead></thead>').append(
$('<tr></tr>').append(
$('<th></th>').html('Departamento')
).append(
$('<th></th>').html('Propietario')
).append(
$('<th></th>').html('Valor [UF]')
).append(
$('<th></th>').html('Tipologia')
).append(
$('<th></th>').html('UF/m²')
).append(
$('<th></th>').html('Fecha Venta')
).append(
$('<th></th>').html('Estado')
)
)
}
}
},
actions: function() {
return {
up: event => {
this.draw().proyectos()
},
refresh: event => {
const list = $(this.ids.proyectos)
if (list.is(':hidden')) {
const table = $(this.ids.table)
table.hide()
if (this.table !== null) {
this.table.destroy()
this.table = null
}
this.get().ventas(this.data.id)
} else {
this.draw().proyectos()
}
},
get: event => {
if (this.loading.ventas) {
return false
}
const element = $(event.currentTarget)
$(this.ids.proyectos + ' .item.proyecto').css('cursor', 'wait')
this.loading.ventas = true
const proyecto_id = element.data('proyecto')
this.get().ventas(proyecto_id)
}
}
},
setup: function({title, proyectos_id, table_id, up_button, refresh_button}) {
this.ids.title = title
this.ids.proyectos = proyectos_id
this.ids.table = table_id
this.ids.buttons.up = up_button
this.ids.buttons.refresh = refresh_button
$(this.ids.buttons.up).click(this.actions().up)
$(this.ids.buttons.refresh).click(this.actions().refresh)
this.draw().proyectos()
}
}
$(document).ready(() => {
ventas.setup({
title: '#list_title',
proyectos_id: '#proyectos',
table_id: '#data',
up_button: '#up_button',
refresh_button: '#refresh_button'
})
})
</script>
@endpush

View File

@ -321,7 +321,7 @@
data: {
id: 0,
proyecto: '',
proyectos: [],
proyectos: JSON.parse('{!! json_encode($proyectos) !!}'),
precios: []
},
table: null,
@ -524,14 +524,14 @@
}
},
up: event => {
this.get().proyectos()
this.draw().proyectos()
},
refresh: event => {
const list = $(this.ids.proyectos)
if (list.is(':hidden')) {
this.get().precios(this.data.id)
} else {
this.get().proyectos()
this.draw().proyectos()
}
},
add: () => {
@ -581,7 +581,7 @@
$(this.ids.buttons.refresh).click(this.actions().refresh)
$(this.ids.buttons.add).click(this.actions().add().list)
this.get().proyectos()
this.draw().proyectos()
}
}