Files
oficial/app/resources/views/proyectos/brokers/contracts/show/unidades.blade.php
2025-04-08 18:30:14 -04:00

134 lines
5.7 KiB
PHP

<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>m&#0178;</th>
<th>Estado</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">Precio Final</th>
</tr>
</thead>
<tbody></tbody>
</table>
@push('page_scripts')
<script>
class UnitsTable extends TableHandler {
ids = {
units: 'unidades',
}
columns = [
'tipo',
'tipo_order',
'unidad',
'unidad_order',
'metros',
'estado',
'precio_base',
'commission',
'precio_operador',
'porcentaje',
'precio_final',
]
constructor(commission) {
super(commission)
const dto = structuredClone(datatables_defaults)
dto.pageLength = 100
dto.columnDefs = [
{
target: [1, 3],
visible: false
},
{
target: 0,
orderData: 1
},
{
target: 2,
orderData: 3
},
{
target: ['metros', 'precio_base', 'commission', 'precio_operador', 'porcentaje', 'precio_final']
.map(column => this.columns.indexOf(column)),
className: 'dt-right right aligned'
}
]
dto.order = [[1, 'asc'], [3, 'asc']]
dto.language.searchBuilder = searchBuilder
dto.layout = {
top1Start: {
searchBuilder: {
columns: this.columns.filter(column => !['tipo_order', 'unidad_order'].includes(column))
.map(column => this.columns.indexOf(column)),
}
},
top1End: {
buttons: [
{
extend: 'excelHtml5',
className: 'green',
text: 'Exportar a Excel <i class="file excel icon"></i>',
title: 'Lista de Precios - {{ $contract->broker->name }} - {{ $contract->project->descripcion }} - {{ (new DateTime())->format('Y-m-d') }}',
download: 'open',
exportOptions: {
columns: ['tipo', 'unidad', 'metros', 'commission', 'precio_operador', 'porcentaje', 'precio_final']
.map(column => this.columns.indexOf(column)),
rows: (idx, data, node) => {
return data[this.columns.indexOf('estado')] === 'Disponible'
},
format: {
body: (data, row, columnIdx, node) => {
if (typeof data === 'string' && data.includes('<span')) {
return data.replace(/<span.*>(.*)<\/span>/, '$1')
}
if (columnIdx === this.columns.indexOf('metros')) {
return data.replaceAll('.', '').replaceAll(',', '.')
}
return data
}
}
},
}
]
}
}
$(`#${this.ids.units}`).DataTable(dto)
}
draw({units, formatters}) {
const table = $(`#${this.ids.units}`).DataTable()
table.clear()
const tableData = []
const prices = this.prices(units)
units.forEach(unidad => {
const tipo = unidad.proyecto_tipo_unidad.tipo_unidad.descripcion
const price = prices.find(p => p.id === unidad.id)
tableData.push([
tipo.charAt(0).toUpperCase() + tipo.slice(1),
unidad.proyecto_tipo_unidad.tipo_unidad.orden,
unidad.descripcion,
unidad.descripcion.padStart(4, '0'),
formatters.ufs.format(unidad.proyecto_tipo_unidad.vendible) ?? 0,
unidad.sold ? '<span class="ui yellow text">Vendida</span>' : 'Disponible',
'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),
'UF ' + formatters.ufs.format(price.final ?? 0),
unidad.promotion?.start_date ?? '',
unidad.promotion?.end_date ?? '',
])
})
table.rows.add(tableData)
table.draw()
}
}
</script>
@endpush