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,20 +295,40 @@
}
}
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 => {
const date = new Date(Date.parse(reservation.date) + 24 * 60 * 60 * 1000)
return {
//const date = new Date(Date.parse(reservation.date) + 24 * 60 * 60 * 1000)
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,
unidades: reservation.summary,
cliente: reservation.buyer.nombreCompleto,
cliente: `data-content="${this.draw().tooltip().buyer(reservation)}">${reservation.buyer.nombreCompleto}`,
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>',
operador: reservation.broker?.name ?? '',
}
}*/
})
}
draw() {
return {
tbody: () => {
if (this.reservations.length === 0) {
this.empty()
return
@ -320,9 +340,13 @@
const contents = []
const id = column.id
this.columnNames.forEach(name => {
contents.push(`<td>${column[name]}</td>`)
let td = `<td>${column[name]}</td>`
if (['oferta', 'cliente', 'valida'].includes(name)) {
td = `<td ${column[name]}</td>`
}
contents.push(td)
})
const actions = this.drawActions(id)
const actions = this.draw().actions(id)
if (actions !== '') {
contents.push(actions)
}
@ -331,9 +355,11 @@
})
this.show()
$(this.component).find('[data-content]').popup()
this.watch()
}
drawActions(id) {
},
actions: id => {
return `
<td class="right aligned">
<button class="ui green mini icon button approve" data-id="${id}" title="Aprobar">
@ -343,6 +369,39 @@
<i class="trash icon"></i>
</button>
</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() {
if (Object.keys(this.actions).length === 0) {
@ -412,7 +471,9 @@
return row
})
}
drawActions(id) {
draw() {
const draw = super.draw()
draw.actions = (id) => {
return `
<td class="right aligned">
<button class="ui green mini icon button edit" data-id="${id}" title="Promesar">
@ -423,6 +484,8 @@
</button>
</td>`
}
return draw
}
actions = {
edit: event => {
event.preventDefault()
@ -448,6 +511,40 @@
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 = {
approve: event => {
event.preventDefault()
@ -482,9 +579,13 @@
return data[idx]
})
}
drawActions(id) {
draw() {
const draw = super.draw()
draw.actions = (id) => {
return ''
}
return draw
}
watch() {}
mapState(state) {
@ -522,7 +623,7 @@
if (json.reservations.length > 0) {
component.set.reservations(json.reservations)
}
component.draw()
component.draw().tbody()
})
},
active: project_id => {

View File

@ -22,10 +22,13 @@ class Reservation extends Common\Ideal\Model
public function withCommission(): float
{
$base = 0;
foreach ($this->units as $unit) {
foreach ($this->units as &$unit) {
$unitBase = $unit->value;
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;
}

View File

@ -251,6 +251,9 @@ class Reservation extends Ideal\Service\API
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);
return $model;
}