diff --git a/app/resources/views/ventas/reservations.blade.php b/app/resources/views/ventas/reservations.blade.php
index 92d46c9..1677931 100644
--- a/app/resources/views/ventas/reservations.blade.php
+++ b/app/resources/views/ventas/reservations.blade.php
@@ -295,46 +295,72 @@
}
}
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 ? 'Si' : 'No',
+ 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 ? 'Si' : 'No',
operador: reservation.broker?.name ?? '',
- }
+ }*/
})
}
draw() {
- if (this.reservations.length === 0) {
- this.empty()
- return
- }
- const tbody = this.component.querySelector('tbody')
- tbody.innerHTML = ''
- this.columnsData.forEach(column => {
- const tr = document.createElement('tr')
- const contents = []
- const id = column.id
- this.columnNames.forEach(name => {
- contents.push(`
${column[name]} | `)
- })
- const actions = this.drawActions(id)
- if (actions !== '') {
- contents.push(actions)
- }
- tr.innerHTML = contents.join("\n")
- tbody.appendChild(tr)
- })
- this.show()
+ return {
+ tbody: () => {
+ if (this.reservations.length === 0) {
+ this.empty()
+ return
+ }
+ const tbody = this.component.querySelector('tbody')
+ tbody.innerHTML = ''
+ this.columnsData.forEach(column => {
+ const tr = document.createElement('tr')
+ const contents = []
+ const id = column.id
+ this.columnNames.forEach(name => {
+ let td = `${column[name]} | `
+ if (['oferta', 'cliente', 'valida'].includes(name)) {
+ td = ``
+ }
+ contents.push(td)
+ })
+ const actions = this.draw().actions(id)
+ if (actions !== '') {
+ contents.push(actions)
+ }
+ tr.innerHTML = contents.join("\n")
+ tbody.appendChild(tr)
+ })
+ this.show()
- this.watch()
- }
- drawActions(id) {
- return `
+ $(this.component).find('[data-content]').popup()
+
+ this.watch()
+ },
+ actions: id => {
+ return `
|
| `
+ },
+ 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,8 +471,10 @@
return row
})
}
- drawActions(id) {
- return `
+ draw() {
+ const draw = super.draw()
+ draw.actions = (id) => {
+ return `
| `
+ }
+ return draw
}
actions = {
edit: event => {
@@ -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,8 +579,12 @@
return data[idx]
})
}
- drawActions(id) {
- return ''
+ draw() {
+ const draw = super.draw()
+ draw.actions = (id) => {
+ return ''
+ }
+ return draw
}
watch() {}
@@ -522,7 +623,7 @@
if (json.reservations.length > 0) {
component.set.reservations(json.reservations)
}
- component.draw()
+ component.draw().tbody()
})
},
active: project_id => {
diff --git a/app/src/Model/Venta/Reservation.php b/app/src/Model/Venta/Reservation.php
index 8f84ce4..79639d6 100644
--- a/app/src/Model/Venta/Reservation.php
+++ b/app/src/Model/Venta/Reservation.php
@@ -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;
}
diff --git a/app/src/Service/Venta/Reservation.php b/app/src/Service/Venta/Reservation.php
index 3be8c93..59a0ded 100644
--- a/app/src/Service/Venta/Reservation.php
+++ b/app/src/Service/Venta/Reservation.php
@@ -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;
}