Separacion de Promocion de Contrato y Precio
"Simplificacion" de datos en listado de precios
This commit is contained in:
@ -8,11 +8,46 @@
|
||||
{{ $contract->broker->name }} - {{ $contract->project->descripcion }}
|
||||
@endsection
|
||||
|
||||
@include('layout.body.scripts.stats')
|
||||
@prepend('page_scripts')
|
||||
<script>
|
||||
class TableHandler {
|
||||
commission
|
||||
constructor(commission) {
|
||||
this.commission = commission
|
||||
}
|
||||
draw() {}
|
||||
prices(units) {
|
||||
const prices = []
|
||||
units.forEach(unit => {
|
||||
const price = unit.precio?.valor ?? 0
|
||||
let amount = 1
|
||||
unit.promotions?.forEach(promotion => {
|
||||
amount /= 1/(1 - promotion.amount)
|
||||
})
|
||||
amount /= 1/(1 - this.commission)
|
||||
amount = 1 - amount
|
||||
prices.push({
|
||||
id: unit.id,
|
||||
base: price,
|
||||
amount,
|
||||
final: price / (1 - amount)
|
||||
})
|
||||
})
|
||||
return prices
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endprepend
|
||||
|
||||
@section('brokers_content')
|
||||
<div class="ui compact segment">
|
||||
<b>Comisión:</b> {{ $format->percent($contract->commission, 2, true) }} <br/>
|
||||
<b>Fecha Inicio:</b> {{ $contract->current()->date->format('d/m/Y') }} <br/>
|
||||
<div class="ui statistic">
|
||||
<div class="value">{{ $format->percent($contract->commission, 2, true) }}</div>
|
||||
<div class="label">
|
||||
Comisión desde {{ $contract->current()->date->format('d/m/Y') }}
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
<div class="ui active inline loader"></div>
|
||||
<div id="results">
|
||||
<div class="ui top attached tabular menu">
|
||||
@ -21,75 +56,20 @@
|
||||
<a class="item" data-tab="unidades">Unidades</a>
|
||||
</div>
|
||||
<div class="ui bottom attached tab basic horizontally fitted segment active" data-tab="tipos">
|
||||
<table class="ui table" id="tipos">
|
||||
<thead>
|
||||
<tr>
|
||||
<th rowspan="2">Tipo</th>
|
||||
<th class="center aligned" rowspan="2">Cantidad</th>
|
||||
<th class="center aligned" colspan="3">Precio</th>
|
||||
<th class="center aligned" colspan="3">Promoción</th>
|
||||
<th class="right aligned" rowspan="2">Acciones</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="right aligned">Mínimo</th>
|
||||
<th class="right aligned">Promedio</th>
|
||||
<th class="right aligned">Máximo</th>
|
||||
<th class="right aligned">Mínima</th>
|
||||
<th class="right aligned">Promedio</th>
|
||||
<th class="right aligned">Máxima</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
@include('proyectos.brokers.contracts.show.tipo')
|
||||
</div>
|
||||
<div class="ui bottom attached tab basic horizontally fitted segment" data-tab="lineas">
|
||||
<table class="ui table" id="lineas">
|
||||
<thead>
|
||||
<tr>
|
||||
<th rowspan="2">Tipo</th>
|
||||
<th class="center aligned" rowspan="2">Línea</th>
|
||||
<th class="center aligned" rowspan="2">Orientación</th>
|
||||
<th class="center aligned" rowspan="2">Cantidad</th>
|
||||
<th class="center aligned" colspan="3">Precio</th>
|
||||
<th class="center aligned" colspan="3">Promoción</th>
|
||||
<th class="right aligned" rowspan="2">Acciones</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="right aligned">Mínimo</th>
|
||||
<th class="right aligned">Promedio</th>
|
||||
<th class="right aligned">Máximo</th>
|
||||
<th class="right aligned">Mínima</th>
|
||||
<th class="right aligned">Promedio</th>
|
||||
<th class="right aligned">Máxima</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
@include('proyectos.brokers.contracts.show.linea')
|
||||
</div>
|
||||
<div class="ui bottom attached tab basic horizontally fitted segment" data-tab="unidades">
|
||||
<table class="ui table" id="unidades">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Tipo</th>
|
||||
<th>Tipo Order</th>
|
||||
<th class="right aligned">Unidad</th>
|
||||
<th>Unidad Orden</th>
|
||||
<th>Estado</th>
|
||||
<th class="right aligned">Precio</th>
|
||||
<th class="right aligned">Promoción</th>
|
||||
<th>Fecha Inicio</th>
|
||||
<th>Fecha Término</th>
|
||||
<th class="right aligned">Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
@include('proyectos.brokers.contracts.show.unidades')
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@include('layout.body.scripts.datatables')
|
||||
@include('layout.body.scripts.datatables.searchbuilder')
|
||||
@include('layout.body.scripts.datatables.buttons')
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
@ -100,12 +80,18 @@
|
||||
},
|
||||
data: {
|
||||
project_id: {{ $contract->project->id }},
|
||||
commission: {{ $contract->commission }},
|
||||
units: []
|
||||
},
|
||||
formatters: {
|
||||
ufs: new Intl.NumberFormat('es-CL', { style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2 }),
|
||||
percent: new Intl.NumberFormat('es-CL', { style: 'percent', minimumFractionDigits: 2 })
|
||||
},
|
||||
handlers: {
|
||||
tipo: null,
|
||||
linea: null,
|
||||
unit: null
|
||||
},
|
||||
get() {
|
||||
return {
|
||||
units: () => {
|
||||
@ -139,7 +125,7 @@
|
||||
}
|
||||
json.unidades.forEach(unidad => {
|
||||
const idx = units.data.units.findIndex(u => u.id === parseInt(unidad.id))
|
||||
units.data.units[idx].promotion = unidad.promotion
|
||||
units.data.units[idx].promotions = unidad.promotions
|
||||
})
|
||||
}))
|
||||
})
|
||||
@ -198,179 +184,22 @@
|
||||
draw() {
|
||||
return {
|
||||
units: () => {
|
||||
const table = $(`#${units.ids.units}`).DataTable()
|
||||
table.clear()
|
||||
const tableData = []
|
||||
units.data.units.forEach(unidad => {
|
||||
const tipo = unidad.proyecto_tipo_unidad.tipo_unidad.descripcion
|
||||
const price = unidad.promotion?.price ?? (unidad.precio?.valor ?? 0)
|
||||
const amount = unidad.promotion?.amount ?? 0
|
||||
tableData.push([
|
||||
tipo.charAt(0).toUpperCase() + tipo.slice(1),
|
||||
unidad.proyecto_tipo_unidad.tipo_unidad.orden,
|
||||
unidad.descripcion,
|
||||
unidad.descripcion.padStart(4, '0'),
|
||||
unidad.sold ? 'Vendida' : 'Disponible',
|
||||
price === 0 ? '' : 'UF ' + units.formatters.ufs.format(price),
|
||||
amount === 0 ? '' : units.formatters.percent.format(amount),
|
||||
unidad.promotion?.start_date ?? '',
|
||||
unidad.promotion?.end_date ?? '',
|
||||
`<button type="button" class="ui small tertiary green icon button add_button" data-index="${unidad.id}"><i class="plus icon"></i></button>`
|
||||
+ `<button type="button" class="ui small tertiary red icon button remove_button" data-index="${unidad.id}"><i class="remove icon"></i></button>`
|
||||
+ `<div class="ui input"><input type="checkbox" name="unidad_ids[]" value="${unidad.id}"></div>`
|
||||
])
|
||||
})
|
||||
table.rows.add(tableData)
|
||||
table.draw()
|
||||
units.handlers.units.draw({units: units.data.units, formatters: units.formatters})
|
||||
},
|
||||
tipos: () => {
|
||||
const table = document.getElementById(units.ids.tipos)
|
||||
const tbody = table.querySelector('tbody')
|
||||
tbody.innerHTML = ''
|
||||
const groups = Object.groupBy(units.data.units, unit => {
|
||||
return unit.proyecto_tipo_unidad.tipo_unidad.descripcion
|
||||
})
|
||||
Object.entries(groups).forEach(([tipo, unidades]) => {
|
||||
const precios = {
|
||||
min: null,
|
||||
avg: 0,
|
||||
max: 0
|
||||
}
|
||||
const amounts = {
|
||||
min: null,
|
||||
avg: 0,
|
||||
max: 0
|
||||
}
|
||||
unidades.forEach(unidad => {
|
||||
if (precios.min === null) {
|
||||
precios.min = unidad.promotion?.price ?? (unidad.precio?.valor ?? 0)
|
||||
}
|
||||
if (amounts.min === null) {
|
||||
amounts.min = unidad.promotion?.amount ?? 0
|
||||
}
|
||||
precios.min = Math.min(precios.min, unidad.promotion?.price ?? (unidad.precio?.valor ?? 0))
|
||||
precios.avg += unidad.promotion?.price ?? (unidad.precio?.valor ?? 0)
|
||||
precios.max = Math.max(precios.max, unidad.promotion?.price ?? (unidad.precio?.valor ?? 0))
|
||||
amounts.min = Math.min(amounts.min, unidad.promotion?.amount ?? 0)
|
||||
amounts.avg += unidad.promotion?.amount ?? 0
|
||||
amounts.max = Math.max(amounts.max, unidad.promotion?.amount ?? 0)
|
||||
})
|
||||
precios.avg /= unidades.length
|
||||
amounts.avg /= unidades.length
|
||||
tbody.innerHTML += [
|
||||
`<tr>`,
|
||||
`<td>${tipo.charAt(0).toUpperCase() + tipo.slice(1)}</td>`,
|
||||
`<td class="center aligned">${unidades.length}</td>`,
|
||||
`<td class="right aligned">UF ${units.formatters.ufs.format(precios.min)}</td>`,
|
||||
`<td class="right aligned">UF ${units.formatters.ufs.format(precios.avg)}</td>`,
|
||||
`<td class="right aligned">UF ${units.formatters.ufs.format(precios.max)}</td>`,
|
||||
`<td class="right aligned">${units.formatters.percent.format(amounts.min)}</td>`,
|
||||
`<td class="right aligned">${units.formatters.percent.format(amounts.avg)}</td>`,
|
||||
`<td class="right aligned">${units.formatters.percent.format(amounts.max)}</td>`,
|
||||
`<td class="right aligned"><button type="button" class="ui small tertiary green icon button add_tipo_button" data-tipo="${tipo}"><i class="plus icon"></i></button></td>`,
|
||||
`</tr>`
|
||||
].join("\n")
|
||||
})
|
||||
units.handlers.tipo.draw({units: units.data.units, formatters: units.formatters})
|
||||
},
|
||||
lineas: () => {
|
||||
const table = document.getElementById(units.ids.lineas)
|
||||
const tbody = table.querySelector('tbody')
|
||||
const lineas = Object.groupBy(units.data.units, unit => {
|
||||
return [unit.proyecto_tipo_unidad.tipo_unidad.descripcion, unit.proyecto_tipo_unidad.nombre, unit.orientacion]
|
||||
})
|
||||
Object.entries(lineas).sort(([linea1, unidades1], [linea2, unidades2]) => {
|
||||
const split1 = linea1.split(',')
|
||||
const split2 = linea2.split(',')
|
||||
const ct = unidades1[0].proyecto_tipo_unidad.tipo_unidad.orden - unidades2[0].proyecto_tipo_unidad.tipo_unidad.orden
|
||||
if (ct === 0) {
|
||||
const cl = split1[1].localeCompare(split2[1])
|
||||
if (cl === 0) {
|
||||
return split1[2].localeCompare(split2[2])
|
||||
}
|
||||
return cl
|
||||
}
|
||||
return ct
|
||||
}).forEach(([linea, unidades]) => {
|
||||
[tipo, linea, orientacion] = linea.split(',')
|
||||
const precios = {
|
||||
min: null,
|
||||
avg: 0,
|
||||
max: 0
|
||||
}
|
||||
const amounts = {
|
||||
min: null,
|
||||
avg: 0,
|
||||
max: 0
|
||||
}
|
||||
unidades.forEach(unidad => {
|
||||
if (precios.min === null) {
|
||||
precios.min = unidad.promotion?.price ?? (unidad.precio?.valor ?? 0)
|
||||
}
|
||||
if (amounts.min === null) {
|
||||
amounts.min = unidad.promotion?.amount ?? 0
|
||||
}
|
||||
precios.min = Math.min(precios.min, unidad.promotion?.price ?? (unidad.precio?.valor ?? 0))
|
||||
precios.avg += unidad.promotion?.price ?? (unidad.precio?.valor ?? 0)
|
||||
precios.max = Math.max(precios.max, unidad.promotion?.price ?? (unidad.precio?.valor ?? 0))
|
||||
amounts.min = Math.min(amounts.min, unidad.promotion?.amount ?? 0)
|
||||
amounts.avg += unidad.promotion?.amount ?? 0
|
||||
amounts.max = Math.max(amounts.max, unidad.promotion?.amount ?? 0)
|
||||
})
|
||||
precios.avg /= unidades.length
|
||||
amounts.avg /= unidades.length
|
||||
|
||||
tbody.innerHTML += [
|
||||
`<tr>`,
|
||||
`<td>${tipo.charAt(0).toUpperCase() + tipo.slice(1)}</td>`,
|
||||
`<td class="center aligned"><span data-tooltip="${unidades[0].proyecto_tipo_unidad.tipologia}" data-position="right center">${linea}</span></td>`,
|
||||
`<td class="center aligned">${orientacion}</td>`,
|
||||
`<td class="center aligned">${unidades.length}</td>`,
|
||||
`<td class="right aligned">UF ${units.formatters.ufs.format(precios.min)}</td>`,
|
||||
`<td class="right aligned">UF ${units.formatters.ufs.format(precios.avg)}</td>`,
|
||||
`<td class="right aligned">UF ${units.formatters.ufs.format(precios.max)}</td>`,
|
||||
`<td class="right aligned">${units.formatters.percent.format(amounts.min)}</td>`,
|
||||
`<td class="right aligned">${units.formatters.percent.format(amounts.avg)}</td>`,
|
||||
`<td class="right aligned">${units.formatters.percent.format(amounts.max)}</td>`,
|
||||
`<td class="right aligned"><button type="button" class="ui small tertiary green icon button add_linea_button" data-linea="${linea}"><i class="plus icon"></i></button></td>`,
|
||||
`</tr>`
|
||||
].join("\n")
|
||||
})
|
||||
units.handlers.lineas.draw({units: units.data.units, formatters: units.formatters})
|
||||
}
|
||||
}
|
||||
},
|
||||
setup(ids) {
|
||||
units.ids = ids
|
||||
|
||||
const dto = structuredClone(datatables_defaults)
|
||||
dto.pageLength = 100
|
||||
dto.columnDefs = [
|
||||
{
|
||||
target: [1, 3],
|
||||
visible: false
|
||||
},
|
||||
{
|
||||
target: 0,
|
||||
orderData: 1
|
||||
},
|
||||
{
|
||||
target: 2,
|
||||
orderData: 3
|
||||
},
|
||||
{
|
||||
target: [2, 5, 6],
|
||||
className: 'dt-right right aligned'
|
||||
}
|
||||
]
|
||||
dto.order = [[1, 'asc'], [3, 'asc']]
|
||||
dto.language.searchBuilder = searchBuilder
|
||||
dto.layout = {
|
||||
top1Start: {
|
||||
searchBuilder: {
|
||||
columns: [0, 2, 4, 5, 6, 7, 8],
|
||||
}
|
||||
},
|
||||
}
|
||||
$(`#${units.ids.units}`).DataTable(dto)
|
||||
units.handlers.tipo = new TipoTable(units.data.commission)
|
||||
units.handlers.lineas = new LineasTable(units.data.commission)
|
||||
units.handlers.units = new UnitsTable(units.data.commission)
|
||||
|
||||
$(`#${units.ids.results}`).find('.tabular.menu .item').tab({
|
||||
onVisible: function(tabPath) {
|
||||
@ -401,7 +230,7 @@
|
||||
}
|
||||
}
|
||||
$(document).ready(function () {
|
||||
units.setup({results: 'results', units: 'unidades', tipos: 'tipos', lineas: 'lineas', loader: '.ui.loader'})
|
||||
units.setup({results: 'results', loader: '.ui.loader'})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
||||
|
Reference in New Issue
Block a user