11 Commits

5 changed files with 97 additions and 53 deletions

View File

@ -25,13 +25,14 @@
unit.promotions?.forEach(promotion => { unit.promotions?.forEach(promotion => {
amount /= 1/(1 - promotion.amount) amount /= 1/(1 - promotion.amount)
}) })
amount /= 1/(1 - this.commission)
amount = 1 - amount amount = 1 - amount
prices.push({ prices.push({
id: unit.id, id: unit.id,
base: price, base: price,
commission: this.commission,
broker: price / (1 - this.commission),
amount, amount,
final: price / (1 - amount) final: price / (1 - this.commission) / (1 - amount)
}) })
}) })
return prices return prices

View File

@ -5,8 +5,10 @@
<th class="center aligned">Línea</th> <th class="center aligned">Línea</th>
<th class="center aligned">Orientación</th> <th class="center aligned">Orientación</th>
<th class="center aligned">Cantidad</th> <th class="center aligned">Cantidad</th>
<th class="right aligned" style="text-decoration: overline">Precio Lista</th> <th class="right aligned" style="text-decoration: overline">Precio Base</th>
<th class="right aligned" style="text-decoration: overline">Comisión</th>
<th class="right aligned" style="text-decoration: overline">Porcentaje</th> <th class="right aligned" style="text-decoration: overline">Porcentaje</th>
<th class="right aligned" style="text-decoration: overline">Precio Operador</th>
<th class="right aligned" style="text-decoration: overline">Precio Final</th> <th class="right aligned" style="text-decoration: overline">Precio Final</th>
</tr> </tr>
</thead> </thead>
@ -51,6 +53,16 @@
`Max: UF ${formatters.ufs.format(Math.max(...prices.map(p => p.base)))}`, `Max: UF ${formatters.ufs.format(Math.max(...prices.map(p => p.base)))}`,
`Desv: UF ${formatters.ufs.format(Stat.standardDeviation(prices.map(p => p.base)))}` `Desv: UF ${formatters.ufs.format(Stat.standardDeviation(prices.map(p => p.base)))}`
].join("\n").replaceAll(' ', '&nbsp;') ].join("\n").replaceAll(' ', '&nbsp;')
const commission_tooltip = [
`Min: ${formatters.percent.format(Math.min(...prices.map(p => p.commission)))}`,
`Max: ${formatters.percent.format(Math.max(...prices.map(p => p.commission)))}`,
`Desv: ${formatters.percent.format(Stat.standardDeviation(prices.map(p => p.commission)))}`
].join("\n").replaceAll(' ', '&nbsp;')
const broker_tooltip = [
`Min: ${formatters.ufs.format(Math.min(...prices.map(p => p.broker)))}`,
`Max: ${formatters.ufs.format(Math.max(...prices.map(p => p.broker)))}`,
`Desv: ${formatters.ufs.format(Stat.standardDeviation(prices.map(p => p.broker)))}`
].join("\n").replaceAll(' ', '&nbsp;')
const amount_tooltip = [ const amount_tooltip = [
`Min: ${formatters.percent.format(Math.min(...prices.map(p => p.amount)))}`, `Min: ${formatters.percent.format(Math.min(...prices.map(p => p.amount)))}`,
`Max: ${formatters.percent.format(Math.max(...prices.map(p => p.amount)))}`, `Max: ${formatters.percent.format(Math.max(...prices.map(p => p.amount)))}`,
@ -69,6 +81,8 @@
`<td class="center aligned">${orientacion}</td>`, `<td class="center aligned">${orientacion}</td>`,
`<td class="center aligned">${unidades.length}</td>`, `<td class="center aligned">${unidades.length}</td>`,
`<td class="right aligned"><span data-tooltip="${base_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.base)))}</span></td>`, `<td class="right aligned"><span data-tooltip="${base_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.base)))}</span></td>`,
`<td class="right aligned"><span data-tooltip="${commission_tooltip}" data-position="right center" data-variation="wide multiline">${formatters.percent.format(Stat.mean(prices.map(p => p.commission)))}</span></td>`,
`<td class="right aligned"><span data-tooltip="${broker_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.broker)))}</span></td>`,
`<td class="right aligned"><span data-tooltip="${amount_tooltip}" data-position="right center" data-variation="wide multiline">${formatters.percent.format(Stat.mean(prices.map(p => p.amount)))}</span></td>`, `<td class="right aligned"><span data-tooltip="${amount_tooltip}" data-position="right center" data-variation="wide multiline">${formatters.percent.format(Stat.mean(prices.map(p => p.amount)))}</span></td>`,
`<td class="right aligned"><span data-tooltip="${final_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.final)))}</span></td>`, `<td class="right aligned"><span data-tooltip="${final_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.final)))}</span></td>`,
`</tr>` `</tr>`

View File

@ -4,6 +4,8 @@
<th>Tipo</th> <th>Tipo</th>
<th class="center aligned">Cantidad</th> <th class="center aligned">Cantidad</th>
<th class="right aligned" style="text-decoration: overline">Precio Base</th> <th class="right aligned" style="text-decoration: overline">Precio Base</th>
<th class="right aligned" style="text-decoration: overline">Comisión</th>
<th class="right aligned" style="text-decoration: overline">Precio Operador</th>
<th class="right aligned" style="text-decoration: overline">Porcentaje</th> <th class="right aligned" style="text-decoration: overline">Porcentaje</th>
<th class="right aligned" style="text-decoration: overline">Precio Final</th> <th class="right aligned" style="text-decoration: overline">Precio Final</th>
</tr> </tr>
@ -34,6 +36,16 @@
`Max: UF ${formatters.ufs.format(Math.max(...prices.map(p => p.base)))}`, `Max: UF ${formatters.ufs.format(Math.max(...prices.map(p => p.base)))}`,
`Desv: UF ${formatters.ufs.format(Stat.standardDeviation(prices.map(p => p.base)))}` `Desv: UF ${formatters.ufs.format(Stat.standardDeviation(prices.map(p => p.base)))}`
].join("\n").replaceAll(' ', '&nbsp;') ].join("\n").replaceAll(' ', '&nbsp;')
const commission_tooltip = [
`Min: ${formatters.percent.format(Math.min(...prices.map(p => p.commission)))}`,
`Max: ${formatters.percent.format(Math.max(...prices.map(p => p.commission)))}`,
`Desv: ${formatters.percent.format(Stat.standardDeviation(prices.map(p => p.commission)))}`
].join("\n").replaceAll(' ', '&nbsp;')
const broker_tooltip = [
`Min: ${formatters.ufs.format(Math.min(...prices.map(p => p.broker)))}`,
`Max: ${formatters.ufs.format(Math.max(...prices.map(p => p.broker)))}`,
`Desv: ${formatters.ufs.format(Stat.standardDeviation(prices.map(p => p.broker)))}`
].join("\n").replaceAll(' ', '&nbsp;')
const amount_tooltip = [ const amount_tooltip = [
`Min: ${formatters.percent.format(Math.min(...prices.map(p => p.amount)))}`, `Min: ${formatters.percent.format(Math.min(...prices.map(p => p.amount)))}`,
`Max: ${formatters.percent.format(Math.max(...prices.map(p => p.amount)))}`, `Max: ${formatters.percent.format(Math.max(...prices.map(p => p.amount)))}`,
@ -50,6 +62,8 @@
`<td>${tipo.charAt(0).toUpperCase() + tipo.slice(1)}</td>`, `<td>${tipo.charAt(0).toUpperCase() + tipo.slice(1)}</td>`,
`<td class="center aligned">${unidades.length}</td>`, `<td class="center aligned">${unidades.length}</td>`,
`<td class="right aligned"><span data-tooltip="${base_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.base)))}</span></td>`, `<td class="right aligned"><span data-tooltip="${base_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.base)))}</span></td>`,
`<td class="right aligned"><span data-tooltip="${commission_tooltip}" data-position="right center" data-variation="wide multiline">${formatters.percent.format(Stat.mean(prices.map(p => p.commission)))}</span></td>`,
`<td class="right aligned"><span data-tooltip="${broker_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.broker)))}</span></td>`,
`<td class="right aligned"><span data-tooltip="${amount_tooltip}" data-position="right center" data-variation="wide multiline">${formatters.percent.format(Stat.mean(prices.map(p => p.amount)))}</span></td>`, `<td class="right aligned"><span data-tooltip="${amount_tooltip}" data-position="right center" data-variation="wide multiline">${formatters.percent.format(Stat.mean(prices.map(p => p.amount)))}</span></td>`,
`<td class="right aligned"><span data-tooltip="${final_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.final)))}</span></td>`, `<td class="right aligned"><span data-tooltip="${final_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.final)))}</span></td>`,
`</tr>` `</tr>`

View File

@ -5,12 +5,13 @@
<th>Tipo Order</th> <th>Tipo Order</th>
<th class="right aligned">Unidad</th> <th class="right aligned">Unidad</th>
<th>Unidad Orden</th> <th>Unidad Orden</th>
<th>m&#0178;</th>
<th>Estado</th> <th>Estado</th>
<th class="right aligned">Precio Lista</th> <th class="right aligned">Precio Base</th>
<th class="right aligned">Comisión</th>
<th class="right aligned">Precio Operador</th>
<th class="right aligned">Porcentaje</th> <th class="right aligned">Porcentaje</th>
<th class="right aligned">Precio Final</th> <th class="right aligned">Precio Final</th>
<th>Fecha Inicio</th>
<th>Fecha Término</th>
</tr> </tr>
</thead> </thead>
<tbody></tbody> <tbody></tbody>
@ -22,6 +23,19 @@
ids = { ids = {
units: 'unidades', units: 'unidades',
} }
columns = [
'tipo',
'tipo_order',
'unidad',
'unidad_order',
'metros',
'estado',
'precio_base',
'commission',
'precio_operador',
'porcentaje',
'precio_final',
]
constructor(commission) { constructor(commission) {
super(commission) super(commission)
@ -41,7 +55,8 @@
orderData: 3 orderData: 3
}, },
{ {
target: [2, 5, 6, 7], target: ['metros', 'precio_base', 'commission', 'precio_operador', 'porcentaje', 'precio_final']
.map(column => this.columns.indexOf(column)),
className: 'dt-right right aligned' className: 'dt-right right aligned'
} }
] ]
@ -50,7 +65,8 @@
dto.layout = { dto.layout = {
top1Start: { top1Start: {
searchBuilder: { searchBuilder: {
columns: [0, 2, 4, 5, 6, 7, 8, 9], columns: this.columns.filter(column => !['tipo_order', 'unidad_order'].includes(column))
.map(column => this.columns.indexOf(column)),
} }
}, },
top1End: { top1End: {
@ -62,31 +78,23 @@
title: 'Lista de Precios - {{ $contract->broker->name }} - {{ $contract->project->descripcion }} - {{ (new DateTime())->format('Y-m-d') }}', title: 'Lista de Precios - {{ $contract->broker->name }} - {{ $contract->project->descripcion }} - {{ (new DateTime())->format('Y-m-d') }}',
download: 'open', download: 'open',
exportOptions: { exportOptions: {
columns: [0, 2, 5, 6, 7], columns: ['tipo', 'unidad', 'metros', 'commission', 'precio_operador', 'porcentaje', 'precio_final']
.map(column => this.columns.indexOf(column)),
rows: (idx, data, node) => { rows: (idx, data, node) => {
return data[4] === 'Disponible' return data[this.columns.indexOf('estado')] === 'Disponible'
}, },
format: { format: {
body: (data, row, columnIdx, node) => { body: (data, row, columnIdx, node) => {
if (typeof data === 'string' && data.includes('<span')) { if (typeof data === 'string' && data.includes('<span')) {
return data.replace(/<span.*>(.*)<\/span>/, '$1') return data.replace(/<span.*>(.*)<\/span>/, '$1')
} }
if (columnIdx === this.columns.indexOf('metros')) {
return data.replaceAll('.', '').replaceAll(',', '.')
}
return data return data
} }
} }
}, },
customize: xlsx => {
const sheet = xlsx.xl.worksheets['sheet1.xml']
const columns = Object.values($('row[r="2"] t', sheet).map((idx, column) => column.textContent))
const columnStylesMap = {
Valor: '63',
Fecha: '15'
}
Object.entries(columnStylesMap).forEach((column, style) => {
const columnIndex = String.fromCharCode('A'.charCodeAt(0) + columns.indexOf(column))
$(`c[r^="${columnIndex}"]`, sheet).attr('s', style)
})
}
} }
] ]
} }
@ -106,8 +114,11 @@
unidad.proyecto_tipo_unidad.tipo_unidad.orden, unidad.proyecto_tipo_unidad.tipo_unidad.orden,
unidad.descripcion, unidad.descripcion,
unidad.descripcion.padStart(4, '0'), unidad.descripcion.padStart(4, '0'),
formatters.ufs.format(unidad.proyecto_tipo_unidad.vendible) ?? 0,
unidad.sold ? '<span class="ui yellow text">Vendida</span>' : 'Disponible', unidad.sold ? '<span class="ui yellow text">Vendida</span>' : 'Disponible',
'UF ' + formatters.ufs.format(price.base ?? 0), 'UF ' + formatters.ufs.format(price.base ?? 0),
formatters.percent.format(price.commission ?? 0),
'UF ' + formatters.ufs.format(price.broker ?? 0),
formatters.percent.format(price.amount ?? 0), formatters.percent.format(price.amount ?? 0),
'UF ' + formatters.ufs.format(price.final ?? 0), 'UF ' + formatters.ufs.format(price.final ?? 0),
unidad.promotion?.start_date ?? '', unidad.promotion?.start_date ?? '',

View File

@ -23,43 +23,45 @@
</div> </div>
</div> </div>
</div> </div>
@if ($venta->formaPago()->pie->reajuste === null) @if ($venta->formaPago()->pie !== null)
<h4 class="ui header optional" data-name="reajuste">Reajuste <i class="small plus icon"></i></h4> @if ($venta->formaPago()->pie->reajuste === null)
<div class="fields optional" id="reajuste"> <h4 class="ui header optional" data-name="reajuste">Reajuste <i class="small plus icon"></i></h4>
<div class="field"> <div class="fields optional" id="reajuste">
<label for="valor_reajuste">Valor [$]</label> <div class="field">
<div class="ui left labeled input"> <label for="valor_reajuste">Valor [$]</label>
<div class="ui basic label">$</div> <div class="ui left labeled input">
<input type="text" name="valor_reajuste" id="valor_reajuste" /> <div class="ui basic label">$</div>
<input type="text" name="valor_reajuste" id="valor_reajuste" />
</div>
</div> </div>
</div> <div class="field">
<div class="field"> <label for="fecha_reajuste">Fecha</label>
<label for="fecha_reajuste">Fecha</label> <div class="ui calendar" id="fecha_reajuste">
<div class="ui calendar" id="fecha_reajuste"> <div class="ui left icon input">
<div class="ui left icon input"> <i class="calendar icon"></i>
<i class="calendar icon"></i> <input type="text" name="fecha_reajuste" />
<input type="text" name="fecha_reajuste" /> </div>
</div> </div>
</div> </div>
</div> </div>
</div> @else
@else <h4 class="ui header" data-name="reajuste">Reajuste</h4>
<h4 class="ui header" data-name="reajuste">Reajuste</h4> <div class="fields" id="reajuste">
<div class="fields" id="reajuste"> <div class="field">
<div class="field"> <label for="valor_reajuste">Valor [$]</label>
<label for="valor_reajuste">Valor [$]</label> <div class="ui left labeled disabled input">
<div class="ui left labeled disabled input"> <div class="ui basic label">$</div>
<div class="ui basic label">$</div> <input type="text" value="{{$format->number($venta->formaPago()->pie->reajuste->valor)}}" />
<input type="text" value="{{$format->number($venta->formaPago()->pie->reajuste->valor)}}" /> </div>
</div>
<div class="field">
<label for="fecha_reajuste">Fecha</label>
<div class="ui disabled input">
<input type="text" value="{{$venta->formaPago()->pie->reajuste->fecha->format('d-m-Y')}}" />
</div>
</div> </div>
</div> </div>
<div class="field"> @endif
<label for="fecha_reajuste">Fecha</label>
<div class="ui disabled input">
<input type="text" value="{{$venta->formaPago()->pie->reajuste->fecha->format('d-m-Y')}}" />
</div>
</div>
</div>
@endif @endif
@if (!isset($venta->formaPago()->escritura)) @if (!isset($venta->formaPago()->escritura))
<h4 class="ui header optional" data-name="pago">Pago en Escritura <i class="small plus icon"></i></h4> <h4 class="ui header optional" data-name="pago">Pago en Escritura <i class="small plus icon"></i></h4>
@ -249,6 +251,7 @@
subsidio.watch() subsidio.watch()
$('#escriturar_form').submit(event => { $('#escriturar_form').submit(event => {
event.preventDefault() event.preventDefault()
$('.ui.button').addClass('loading')
const url = '{{$urls->api}}/venta/{{$venta->id}}/escriturar' const url = '{{$urls->api}}/venta/{{$venta->id}}/escriturar'
const body = new FormData(event.currentTarget) const body = new FormData(event.currentTarget)
const fecha = $('#fecha').calendar('get date') const fecha = $('#fecha').calendar('get date')
@ -268,6 +271,7 @@
} }
} }
fetchAPI(url, {method: 'post', body}).then(response => { fetchAPI(url, {method: 'post', body}).then(response => {
$('.ui.button').removeClass('loading')
if (response.ok) { if (response.ok) {
return response.json() return response.json()
} }