Comparacion con valor base

This commit is contained in:
Juan Pablo Vial
2025-10-17 11:59:34 -03:00
parent 06558d778d
commit beb73ba6df
3 changed files with 144 additions and 37 deletions

View File

@ -295,46 +295,72 @@
} }
} }
get columnsData() { get columnsData() {
const columnValues = {
id: reservation => reservation.id,
unidades: reservation => reservation.summary,
cliente: reservation => reservation.buyer.nombreCompleto,
fecha: reservation => this.formatters.date.format(new Date(Date.parse(reservation.date) + 24 * 60 * 60 * 1000)),
oferta: reservation => `${this.formatters.ufs.format(reservation.offer)} UF`,
valida: reservation => reservation.valid ? '<span class="ui green text">Si</span>' : '<span class="ui red text">No</span>',
operador: reservation => reservation.broker?.name ?? '',
};
return this.reservations.map(reservation => { return this.reservations.map(reservation => {
const date = new Date(Date.parse(reservation.date) + 24 * 60 * 60 * 1000) //const date = new Date(Date.parse(reservation.date) + 24 * 60 * 60 * 1000)
return { const data = {}
Object.entries(columnValues).forEach(([key, value]) => {
if (key in this.draw().tooltip()) {
data[key] = `data-content="${this.draw().tooltip()[key](reservation)}" data-variation="very wide">${value(reservation)}`
return
}
data[key] = value(reservation)
})
return data
/*return {
id: reservation.id, id: reservation.id,
unidades: reservation.summary, unidades: reservation.summary,
cliente: reservation.buyer.nombreCompleto, cliente: `data-content="${this.draw().tooltip().buyer(reservation)}">${reservation.buyer.nombreCompleto}`,
fecha: this.formatters.date.format(date), fecha: this.formatters.date.format(date),
oferta: `${this.formatters.ufs.format(reservation.offer)} UF`, oferta: `data-content="${this.draw().tooltip().payment(reservation)}">${this.formatters.ufs.format(reservation.offer)} UF`,
valida: reservation.valid ? '<span class="ui green text">Si</span>' : '<span class="ui red text">No</span>', valida: reservation.valid ? '<span class="ui green text">Si</span>' : '<span class="ui red text">No</span>',
operador: reservation.broker?.name ?? '', operador: reservation.broker?.name ?? '',
} }*/
}) })
} }
draw() { draw() {
if (this.reservations.length === 0) { return {
this.empty() tbody: () => {
return if (this.reservations.length === 0) {
} this.empty()
const tbody = this.component.querySelector('tbody') return
tbody.innerHTML = '' }
this.columnsData.forEach(column => { const tbody = this.component.querySelector('tbody')
const tr = document.createElement('tr') tbody.innerHTML = ''
const contents = [] this.columnsData.forEach(column => {
const id = column.id const tr = document.createElement('tr')
this.columnNames.forEach(name => { const contents = []
contents.push(`<td>${column[name]}</td>`) const id = column.id
}) this.columnNames.forEach(name => {
const actions = this.drawActions(id) let td = `<td>${column[name]}</td>`
if (actions !== '') { if (['oferta', 'cliente', 'valida'].includes(name)) {
contents.push(actions) td = `<td ${column[name]}</td>`
} }
tr.innerHTML = contents.join("\n") contents.push(td)
tbody.appendChild(tr) })
}) const actions = this.draw().actions(id)
this.show() if (actions !== '') {
contents.push(actions)
}
tr.innerHTML = contents.join("\n")
tbody.appendChild(tr)
})
this.show()
this.watch() $(this.component).find('[data-content]').popup()
}
drawActions(id) { this.watch()
return ` },
actions: id => {
return `
<td class="right aligned"> <td class="right aligned">
<button class="ui green mini icon button approve" data-id="${id}" title="Aprobar"> <button class="ui green mini icon button approve" data-id="${id}" title="Aprobar">
<i class="check icon"></i> <i class="check icon"></i>
@ -343,6 +369,39 @@
<i class="trash icon"></i> <i class="trash icon"></i>
</button> </button>
</td>` </td>`
},
tooltip: () => {
return {
oferta: reservation => {
const formatter = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2})
const output = []
reservation.units.forEach(unit => {
const type = unit.unit.proyecto_tipo_unidad.tipo_unidad.descripcion
output.push(`${type.charAt(0).toUpperCase() + type.slice(1)} ${unit.unit.descripcion}: ${formatter.format(unit.value)} UF`)
})
if (reservation.broker !== null) {
output.push('-----')
let commission = reservation.broker.commission
output.push(`Broker: ${reservation.broker.name} (${commission})`)
}
if (reservation.promotions.length > 0) {
output.push('-----')
reservation.promotions.forEach(promotion => {
output.push(`${promotion.name}: ${formatter.format(promotion.value)} UF`)
})
}
return output.join("\n")
},
cliente: reservation => {
const formatter = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 0, maximumFractionDigits: 0})
return [
`RUT: ${formatter.format(reservation.buyer.rut)}-${reservation.buyer.digito}`
].join("\n")
}
}
}
}
} }
watch() { watch() {
if (Object.keys(this.actions).length === 0) { if (Object.keys(this.actions).length === 0) {
@ -412,8 +471,10 @@
return row return row
}) })
} }
drawActions(id) { draw() {
return ` const draw = super.draw()
draw.actions = (id) => {
return `
<td class="right aligned"> <td class="right aligned">
<button class="ui green mini icon button edit" data-id="${id}" title="Promesar"> <button class="ui green mini icon button edit" data-id="${id}" title="Promesar">
<i class="right chevron icon"></i> <i class="right chevron icon"></i>
@ -422,6 +483,8 @@
<i class="trash icon"></i> <i class="trash icon"></i>
</button> </button>
</td>` </td>`
}
return draw
} }
actions = { actions = {
edit: event => { edit: event => {
@ -448,6 +511,40 @@
super({component_id, formatters}) super({component_id, formatters})
} }
draw() {
const draw = super.draw()
const tooltip = draw.tooltip()
tooltip['valida'] = reservation => {
const formatter = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2})
const output = []
reservation.units.forEach(unit => {
let type = unit.unit.proyecto_tipo_unidad.tipo_unidad.descripcion
type = type.charAt(0).toUpperCase() + type.slice(1)
const base = unit.base ?? (unit.value ?? 0);
const price = unit.unit.current_precio?.valor ?? 0
const diff = (base - price) / price * 100
output.push(`${type} ${unit.unit.descripcion}: ${formatter.format(base)} UF - ${formatter.format(price)} UF (${formatter.format(diff)} %)`)
})
reservation.promotions.forEach(promotion => {
let value = 0
switch (promotion.type) {
case {{ \Incoviba\Model\Venta\Promotion\Type::FIXED }}:
value = `${formatter.format(promotion.value)} UF`
break;
case {{ \Incoviba\Model\Venta\Promotion\Type::VARIABLE }}:
value = `${formatter.format(promotion.value * 100)} %`
break;
}
output.push(`${promotion.description}: ${value}`)
})
return output.join("\n")
}
draw['tooltip'] = () => {
return tooltip
}
return draw
}
actions = { actions = {
approve: event => { approve: event => {
event.preventDefault() event.preventDefault()
@ -482,8 +579,12 @@
return data[idx] return data[idx]
}) })
} }
drawActions(id) { draw() {
return '' const draw = super.draw()
draw.actions = (id) => {
return ''
}
return draw
} }
watch() {} watch() {}
@ -522,7 +623,7 @@
if (json.reservations.length > 0) { if (json.reservations.length > 0) {
component.set.reservations(json.reservations) component.set.reservations(json.reservations)
} }
component.draw() component.draw().tbody()
}) })
}, },
active: project_id => { active: project_id => {

View File

@ -22,10 +22,13 @@ class Reservation extends Common\Ideal\Model
public function withCommission(): float public function withCommission(): float
{ {
$base = 0; $base = 0;
foreach ($this->units as $unit) { foreach ($this->units as &$unit) {
$unitBase = $unit->value;
foreach ($this->promotions as $promotion) { foreach ($this->promotions as $promotion) {
$base += $promotion->activate()->reverse($unit['unit'], $unit['value'], $this->broker); $unitBase = $promotion->activate()->reverse($unit->unit, $unitBase, $this->broker);
} }
$unit->base = $unitBase;
$base += $unitBase;
} }
return $base; return $base;
} }

View File

@ -251,6 +251,9 @@ class Reservation extends Ideal\Service\API
return $this->stateRepository->fetchByReservation($reservation_id); return $this->stateRepository->fetchByReservation($reservation_id);
}) })
); );
foreach ($model->units as &$unit) {
$unit->unit = $this->unitService->getById($unit->unit->id);
}
$model->buyer = $this->personaService->getById($model->buyer->rut); $model->buyer = $this->personaService->getById($model->buyer->rut);
return $model; return $model;
} }