Mostrar valor de venta para unidades vendidas
This commit is contained in:
@ -20,7 +20,7 @@
|
||||
prices(units) {
|
||||
const prices = []
|
||||
units.forEach(unit => {
|
||||
let price = unit.precio?.valor ?? 0
|
||||
let price = unit.valor ?? (unit.precio?.valor ?? 0)
|
||||
let amount = 1
|
||||
let diff = 0
|
||||
unit.promotions?.forEach(promotion => {
|
||||
@ -71,7 +71,9 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui active inline loader"></div>
|
||||
<div class="ui very basic segment">
|
||||
<div class="ui active inline loader"></div>
|
||||
</div>
|
||||
<div id="results">
|
||||
<div class="ui top attached tabular menu">
|
||||
<a class="item active" data-tab="tipos">Tipos</a>
|
||||
@ -155,10 +157,11 @@
|
||||
return Promise.all(promises)
|
||||
},
|
||||
prices: () => {
|
||||
const unsold = [...units.data.units.filter(unit => !unit.sold), ...units.data.units.filter(unit => unit.sold && unit.proyecto_tipo_unidad.tipo_unidad.descripcion !== 'departamento')]
|
||||
const chunkSize = 100
|
||||
const chunks = []
|
||||
for (let i = 0; i < units.data.units.length; i += chunkSize) {
|
||||
chunks.push(units.data.units.slice(i, i + chunkSize).map(u => u.id))
|
||||
for (let i = 0; i < unsold.length; i += chunkSize) {
|
||||
chunks.push(unsold.slice(i, i + chunkSize).map(u => u.id))
|
||||
}
|
||||
const promises = []
|
||||
const url = `{{ $urls->api }}/proyecto/{{ $contract->project->id }}/unidades/precios`
|
||||
@ -178,6 +181,51 @@
|
||||
})
|
||||
return Promise.all(promises)
|
||||
},
|
||||
values: () => {
|
||||
const sold = units.data.units.filter(unit => unit.sold && unit.proyecto_tipo_unidad.tipo_unidad.descripcion === 'departamento')
|
||||
const chunkSize = 10
|
||||
const chunks = []
|
||||
for (let i = 0; i < sold.length; i += chunkSize) {
|
||||
chunks.push(sold.slice(i, i + chunkSize).map(u => u.id))
|
||||
}
|
||||
const promises = []
|
||||
const url = `{{ $urls->api }}/ventas/by/unidades`
|
||||
const method = 'post'
|
||||
chunks.forEach(chunk => {
|
||||
const body = new FormData()
|
||||
chunk.forEach(id => body.append('unidad_ids[]', id))
|
||||
promises.push(APIClient.fetch(url, {method, body}).then(response => response.json()).then(json => {
|
||||
if (json.ventas.length === 0) {
|
||||
return
|
||||
}
|
||||
json.ventas.forEach(({unidad_id, venta}) => {
|
||||
const unidades = venta.propiedad.unidades
|
||||
const otras_unidades = unidades.filter(unit => unit.id !== parseInt(unidad_id) && unit.proyecto_tipo_unidad.tipo_unidad.descripcion !== 'departamento')
|
||||
const departamentos = unidades.filter(unit => unit.proyecto_tipo_unidad.tipo_unidad.descripcion === 'departamento' && unit.id !== parseInt(unidad_id))
|
||||
const precios = otras_unidades.map(unit => {
|
||||
const idx = units.data.units.findIndex(u => u.id === unit.id)
|
||||
return units.data.units[idx].precio?.valor ?? 0
|
||||
}).reduce((sum, precio) => sum + precio, 0)
|
||||
if (departamentos.length === 0) {
|
||||
const idx = units.data.units.findIndex(unit => unit.id === parseInt(unidad_id))
|
||||
units.data.units[idx].valor = venta.valor - precios
|
||||
units.data.units[idx].venta = venta
|
||||
return
|
||||
}
|
||||
const sum_precios = departamentos.map(departamento => {
|
||||
return departamento.current_precio.valor
|
||||
}).reduce((sum, precio) => sum + precio, 0)
|
||||
departamentos.forEach(departamento => {
|
||||
const idx = units.data.units.findIndex(unit => unit.id === departamento.id)
|
||||
const saldo = venta.valor - precios
|
||||
units.data.units[idx].valor = saldo / sum_precios * departamento.current_precio.valor
|
||||
units.data.units[idx].venta = venta
|
||||
})
|
||||
})
|
||||
}))
|
||||
})
|
||||
return Promise.all(promises)
|
||||
},
|
||||
sold: () => {
|
||||
const chunkSize = 100
|
||||
const chunks = []
|
||||
@ -236,16 +284,23 @@
|
||||
document.getElementById(units.ids.results).style.visibility = 'hidden'
|
||||
|
||||
units.get().units().then(() => {
|
||||
units.get().prices().then(() => {
|
||||
units.get().promotions().then(() => {
|
||||
units.get().sold().then(() => {
|
||||
$(units.ids.loader).hide()
|
||||
|
||||
units.get().promotions().then(() => {
|
||||
units.get().sold().then(() => {
|
||||
units.get().prices().then(() => {
|
||||
document.getElementById(units.ids.results).style.visibility = 'visible'
|
||||
|
||||
units.draw().units()
|
||||
units.draw().tipos()
|
||||
units.draw().lineas()
|
||||
|
||||
units.get().values().then(() => {
|
||||
$(units.ids.loader).hide()
|
||||
$(units.ids.loader).parent().hide()
|
||||
|
||||
units.draw().units()
|
||||
units.draw().tipos()
|
||||
units.draw().lineas()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -118,10 +118,10 @@
|
||||
const tipo = unidad.proyecto_tipo_unidad.tipo_unidad.descripcion
|
||||
const price = prices.find(p => p.id === unidad.id)
|
||||
tableData.push([
|
||||
unidad.sold ? '<span class="ui yellow text">Vendida</span>' : 'Libre',
|
||||
unidad.sold ? `<a href="{{ $urls->base }}/venta/${unidad.venta?.id }" class="ui yellow text">Vendida</a>` : 'Libre',
|
||||
tipo.charAt(0).toUpperCase() + tipo.slice(1),
|
||||
unidad.proyecto_tipo_unidad.tipo_unidad.orden,
|
||||
unidad.descripcion,
|
||||
unidad.sold ? `<span data-tooltip="Valor Promesa: UF ${formatters.ufs.format(unidad.venta?.valor ?? 0)}" data-position="right center">${unidad.descripcion}</span>` : unidad.descripcion,
|
||||
unidad.descripcion.padStart(4, '0'),
|
||||
unidad.proyecto_tipo_unidad.tipologia,
|
||||
unidad.piso,
|
||||
|
Reference in New Issue
Block a user