diff --git a/app/resources/views/ventas/reservations.blade.php b/app/resources/views/ventas/reservations.blade.php index 7a01dfd..94c604c 100644 --- a/app/resources/views/ventas/reservations.blade.php +++ b/app/resources/views/ventas/reservations.blade.php @@ -891,12 +891,16 @@ }, units: project_id => { if (project_id in reservations.data.units) { + reservations.locks.units = null return new Promise((resolve, reject) => { resolve(reservations.data.units[project_id]) }) } + if (reservations.locks.units !== null) { + return reservations.locks.units + } const uri = `/api/proyecto/${project_id}/unidades/disponibles` - return APIClient.fetch(uri).then(response => response.json()).then(json => { + reservations.locks.units = APIClient.fetch(uri).then(response => response.json()).then(json => { if (json.unidades.length === 0) { reservations.data.units[project_id] = {} return reservations.data.units[project_id] @@ -914,6 +918,7 @@ return reservations.data.units[project_id] }) + return reservations.locks.units }, }, loading: { diff --git a/app/resources/views/ventas/reservations/modal/common/scripts/modal.blade.php b/app/resources/views/ventas/reservations/modal/common/scripts/modal.blade.php index ae5f4db..f0dc269 100644 --- a/app/resources/views/ventas/reservations/modal/common/scripts/modal.blade.php +++ b/app/resources/views/ventas/reservations/modal/common/scripts/modal.blade.php @@ -23,7 +23,6 @@ $modal: null, form: null, $date: null, - $rut: null, rut: null, digit: null, $birthdate: null, @@ -90,7 +89,7 @@ this.get.brokers(project_id) this.get.promotions(project_id).then(() => { - const promotions = reservations.data.promotions[project_id] + const promotions = structuredClone(reservations.data.promotions[project_id]) this.components.promotions.data.promotions = promotions.map(promotion => { return { text: promotion.description, @@ -101,7 +100,7 @@ this.components.promotions.draw.promotions() }) this.get.units(project_id).then(() => { - const unitTypes = reservations.data.units[project_id] + const unitTypes = structuredClone(reservations.data.units[project_id]) Object.entries(unitTypes).map(([type, units]) => { units = units.map(unit => { return { @@ -142,24 +141,6 @@ this.components.$comuna.dropdown('set selected', this.data.current_user.direccion.comuna.id) } }) - /*const uri = `/api/region/${region_id}/comunas` - return APIClient.fetch(uri).then(response => response.json()).then(json => { - if (json.comunas.length === 0) { - return - } - this.data.comunas[region_id] = json.comunas.map(comuna => { - return { - text: comuna.descripcion, - name: comuna.descripcion, - value: comuna.id - } - }) - this.components.$comuna.dropdown('change values', this.data.comunas[region_id]) - - if (this.data.current_user !== null && this.data.current_user?.direccion?.comuna !== null) { - this.components.$comuna.dropdown('set selected', this.data.current_user.direccion.comuna.id) - } - })*/ }, brokers: project_id => { if (project_id in this.data.brokers) { @@ -167,41 +148,10 @@ resolve(this.data.brokers[project_id]) }) } - return reservations.get.brokers(project_id).then(brokers => { - this.data.brokers[project_id] = brokers + return reservations.get.brokers(project_id).then(() => { + this.data.brokers[project_id] = reservations.data.brokers[project_id] this.fill.brokers() }) - /*const uri = `/api/proyecto/${project_id}/brokers` - return APIClient.fetch(uri).then(response => response.json()).then(json => { - if (json.contracts.length === 0) { - return - } - const formatter = new Intl.NumberFormat('es-CL', { style: 'percent', minimumFractionDigits: 2 }) - this.data.brokers[project_id] = json.contracts.map(contract => { - return { - id: contract.id, - broker_rut: contract.broker_rut, - commission: formatter.format(contract.commission), - name: '', - text: '', - } - }) - const promises = [] - json.contracts.forEach(contract => { - promises.push(this.get.broker(contract.broker_rut)) - }) - - return Promise.all(promises).then(data => { - data.forEach(broker => { - if (!('rut' in broker)) { - return - } - const idx = this.data.brokers[project_id].findIndex(contract => contract.broker_rut === broker.rut) - this.data.brokers[project_id][idx].name = this.data.brokers[project_id][idx].text = `${broker.name} - ${this.data.brokers[project_id][idx].commission}` - }) - this.fill.brokers() - }) - })*/ }, broker: (broker_rut) => { const uri = `/api/proyectos/broker/${broker_rut}` @@ -221,13 +171,6 @@ return reservations.get.promotions(project_id).then(promotions => { this.data.promotions[project_id] = promotions }) - /*const uri = `/api/proyecto/${project_id}/promotions` - return APIClient.fetch(uri).then(response => response.json()).then(json => { - if (json.promotions.length === 0) { - return this.data.promotions[project_id] = [] - } - return this.data.promotions[project_id] = json.promotions - })*/ }, units: project_id => { if (project_id in this.data.units) { @@ -238,25 +181,6 @@ return reservations.get.units(project_id).then(units => { this.data.units[project_id] = units }) - /*const uri = `/api/proyecto/${project_id}/unidades/disponibles` - return APIClient.fetch(uri).then(response => response.json()).then(json => { - if (json.unidades.length === 0) { - this.data.units[project_id] = {} - return this.data.units[project_id] - } - if (!(project_id in this.data.units)) { - this.data.units[project_id] = {} - } - json.unidades.forEach(unit => { - const type = unit.proyecto_tipo_unidad.tipo_unidad.descripcion - if (!(type in this.data.units[project_id])) { - this.data.units[project_id][type] = [] - } - this.data.units[project_id][type].push(unit) - }) - - return this.data.units[project_id] - })*/ }, user: rut => { if (this.data.current_user !== null && this.data.current_user?.rut === rut) { diff --git a/app/resources/views/ventas/reservations/modal/common/scripts/payments.blade.php b/app/resources/views/ventas/reservations/modal/common/scripts/payments.blade.php index d0406e1..ac1f8d3 100644 --- a/app/resources/views/ventas/reservations/modal/common/scripts/payments.blade.php +++ b/app/resources/views/ventas/reservations/modal/common/scripts/payments.blade.php @@ -77,6 +77,19 @@ this.hide.credit() } } + fill(formaPago) { + if ('pie' in formaPago && formaPago.pie !== null) { + this.components.pie.$checkbox.prop('checked', true) + //this.show.pie() + this.components.pie.value.value = formaPago.pie.valor + this.components.pie.installments.value = formaPago.pie.cuotas + } + if ('credito' in formaPago && formaPago.credito !== null) { + this.components.credit.$checkbox.prop('checked', true) + //this.show.credit() + this.components.credit.value.value = formaPago.credito.value + } + } setup() { this.components.pie.$checkbox = $(`#${this.ids.pie.checkbox}`) this.components.pie.value = document.getElementById(this.ids.pie.value) diff --git a/app/resources/views/ventas/reservations/modal/common/scripts/promotions.blade.php b/app/resources/views/ventas/reservations/modal/common/scripts/promotions.blade.php index d12588a..8cc8d39 100644 --- a/app/resources/views/ventas/reservations/modal/common/scripts/promotions.blade.php +++ b/app/resources/views/ventas/reservations/modal/common/scripts/promotions.blade.php @@ -30,6 +30,7 @@ const idx = Math.max(this.data.selected.length, 0, Math.max(...this.data.selected) + 1) this.data.selected.push(idx) this.draw.promotions() + return idx } reset() { this.data.selected = [] @@ -86,6 +87,16 @@ }) } } + async fill(promotions) { + if (reservations.locks.promotions !== null) { + await reservations.locks.promotions + } + promotions.forEach(promotion => { + const idx = this.add() + const dropdown = $(this.components.promotions.querySelector(`div.promotion[data-id="${idx}"]`).querySelector('div.dropdown')) + dropdown.dropdown('set selected', promotion.id) + }) + } setup() { this.components.button = document.getElementById(this.ids.button) this.components.promotions = document.getElementById(this.ids.elements) diff --git a/app/resources/views/ventas/reservations/modal/common/scripts/units.blade.php b/app/resources/views/ventas/reservations/modal/common/scripts/units.blade.php index 5801111..ab93216 100644 --- a/app/resources/views/ventas/reservations/modal/common/scripts/units.blade.php +++ b/app/resources/views/ventas/reservations/modal/common/scripts/units.blade.php @@ -113,17 +113,19 @@ ].join('') } } + const type = unit.type.charAt(0).toUpperCase() + unit.type.slice(1) + return [ - '