diff --git a/app/common/Implement/Log/Processor/Exception.php b/app/common/Implement/Log/Processor/Exception.php
index d02431d..22507b9 100644
--- a/app/common/Implement/Log/Processor/Exception.php
+++ b/app/common/Implement/Log/Processor/Exception.php
@@ -61,7 +61,7 @@ class Exception implements ProcessorInterface
'trace' => $exception->getTraceAsString(),
];
if ($exception->getPrevious() !== null) {
- $output['previous'] = $this->processException($exception);
+ $output['previous'] = $this->processException($exception->getPrevious());
}
return $output;
}
diff --git a/app/resources/views/ventas/promotions/show.blade.php b/app/resources/views/ventas/promotions/show.blade.php
index 9d4eb4d..abd45d4 100644
--- a/app/resources/views/ventas/promotions/show.blade.php
+++ b/app/resources/views/ventas/promotions/show.blade.php
@@ -79,7 +79,7 @@
'
@@ -153,7 +188,8 @@
elements: ''
}
data = {
- promotions: []
+ promotions: [],
+ selected: []
}
components = {
button: null,
@@ -171,16 +207,16 @@
this.setup()
}
add() {
- const idx = Math.max(this.data.promotions.length, 0, Math.max(...this.data.promotions) + 1)
- this.data.promotions.push(idx)
+ const idx = Math.max(this.data.selected.length, 0, Math.max(...this.data.selected) + 1)
+ this.data.selected.push(idx)
this.draw.promotions()
}
reset() {
- this.data.promotions = []
+ this.data.selected = []
this.draw.promotions()
}
remove(idx) {
- this.data.promotions = this.data.promotions.filter(promotion => promotion !== idx)
+ this.data.selected = this.data.selected.filter(promotion => promotion !== idx)
this.draw.promotions()
}
draw = {
@@ -213,7 +249,10 @@
return
}
this.components.button.parentElement.style.display = this.display.button
- this.components.promotions.innerHTML = this.data.promotions.map((promotion, idx) => {
+ if (this.data.selected.length === 0) {
+ return
+ }
+ this.components.promotions.innerHTML = this.data.selected.map(idx => {
return this.draw.promotion(idx)
}).join('')
this.components.promotions.querySelectorAll('.dropdown').forEach(dropdown => {
@@ -362,7 +401,7 @@
'
',
@@ -394,6 +433,101 @@
this.draw.buttons()
}
}
+ class AddModalPayments {
+ ids = {
+ pie: {
+ checkbox: 'add_has_pie',
+ value: 'add_pie',
+ installments: 'add_cuotas'
+ },
+ credit: {
+ checkbox: 'add_has_credit',
+ value: 'add_credit'
+ }
+ }
+ components = {
+ pie: {
+ $checkbox: null,
+ value: null,
+ installments: null
+ },
+ credit: {
+ $checkbox: null,
+ value: null
+ }
+ }
+ data = {
+ pie: {
+ value: '',
+ installments: ''
+ },
+ credit: {
+ value: ''
+ }
+ }
+ constructor() {
+ this.setup()
+ }
+ reset() {
+ this.components.pie.$checkbox.prop('checked', false)
+ this.components.pie.value.value = ''
+ this.components.pie.installments.value = ''
+ this.components.credit.$checkbox.prop('checked', false)
+ this.components.credit.value.value = ''
+ }
+ show = {
+ pie: () => {
+ this.components.pie.value.style.display = this.data.pie.value
+ this.components.pie.installments.style.display = this.data.pie.installments
+ },
+ credit: () => {
+ this.components.credit.value.style.display = this.data.credit.value
+ }
+ }
+ hide = {
+ pie: () => {
+ this.components.pie.value.style.display = 'none'
+ this.components.pie.installments.style.display = 'none'
+ },
+ credit: () => {
+ this.components.credit.value.style.display = 'none'
+ },
+ all: () => {
+ this.hide.pie()
+ this.hide.credit()
+ }
+ }
+ setup() {
+ this.components.pie.$checkbox = $(`#${this.ids.pie.checkbox}`)
+ this.components.pie.value = document.getElementById(this.ids.pie.value)
+ this.components.pie.installments = document.getElementById(this.ids.pie.installments)
+ this.components.credit.$checkbox = $(`#${this.ids.credit.checkbox}`)
+ this.components.credit.value = document.getElementById(this.ids.credit.value)
+
+ this.components.pie.$checkbox.checkbox()
+ this.components.pie.$checkbox.change(changeEvent => {
+ if (this.components.pie.$checkbox.is(':checked')) {
+ this.show.pie()
+ return
+ }
+ this.hide.pie()
+ })
+ this.components.credit.$checkbox.checkbox()
+ this.components.credit.$checkbox.change(changeEvent => {
+ if (this.components.credit.$checkbox.is(':checked')) {
+ this.show.credit()
+ return
+ }
+ this.hide.credit()
+ })
+
+ this.data.pie.value = this.components.pie.value.style.display
+ this.data.pie.installments = this.components.pie.installments.style.display
+ this.data.credit.value = this.components.credit.value.style.display
+
+ this.hide.all()
+ }
+ }
class AddReservationModal {
ids = {
modal: '',
@@ -429,6 +563,7 @@
project_name: null,
unit_buttons: null,
units: null,
+ payments: null,
$loader: null
}
data = {
@@ -480,8 +615,8 @@
this.get.promotions(project_id).then(promotions => {
this.components.promotions.data.promotions = promotions.map(promotion => {
return {
- text: promotion.name,
- name: promotion.name,
+ text: promotion.description,
+ name: promotion.description,
value: promotion.id
}
})
@@ -509,6 +644,7 @@
this.components.form.reset()
this.components.promotions.reset()
this.components.units.reset()
+ this.components.payments.reset()
}
add() {
const url = '/api/ventas/reservation/add'
@@ -524,6 +660,16 @@
const birthdate = this.components.$birthdate.calendar('get date')
body.set('add_buyer_birthdate', [birthdate.getFullYear(), birthdate.getMonth() + 1, birthdate.getDate()].join('-'))
+ if (this.components.payments.components.pie.$checkbox.checkbox('is unchecked')) {
+ body.delete('add_pie')
+ body.delete('add_cuotas')
+ }
+ body.delete('add_has_pie')
+ if (this.components.payments.components.credit.$checkbox.checkbox('is unchecked')) {
+ body.delete('add_credit')
+ }
+ body.delete('add_has_credit')
+
body.delete('comuna')
body.delete('region')
body.delete('broker')
@@ -672,6 +818,9 @@
}
fill = {
user: user => {
+ if (typeof user === 'undefined' || user === null) {
+ return
+ }
const form = this.components.form
form.querySelector('input[name="add_buyer_name"]').value = user.nombres || ''
form.querySelector('input[name="add_buyer_last_name"]').value = user.apellidoPaterno || ''
@@ -753,6 +902,7 @@
this.components.projects = document.getElementById(this.ids.projects)
this.components.project_name = document.getElementById(this.ids.project_name)
this.components.units = new AddModalUnits(this)
+ this.components.payments = new AddModalPayments()
this.components.$modal.modal({
onApprove: () => {
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/Repository/Persona/Datos.php b/app/src/Repository/Persona/Datos.php
index 06cd4b7..baf35e8 100644
--- a/app/src/Repository/Persona/Datos.php
+++ b/app/src/Repository/Persona/Datos.php
@@ -63,7 +63,7 @@ class Datos extends Ideal\Repository
'persona_rut', 'direccion_id', 'telefono', 'email', 'fecha_nacimiento', 'sexo', 'estado_civil',
'nacionalidad', 'ocupacion'
], [
- $model->persona->rut, $model->direccion?->id, $model->telefono, $model->email, $model->fechaNacimiento,
+ $model->persona->rut, $model->direccion?->id, $model->telefono, $model->email, $model->fechaNacimiento->format('Y-m-d'),
$model->sexo, $model->estadoCivil, $model->nacionalidad, $model->ocupacion
]);
return $model;
diff --git a/app/src/Service/Persona.php b/app/src/Service/Persona.php
index 84bc645..ba219ae 100644
--- a/app/src/Service/Persona.php
+++ b/app/src/Service/Persona.php
@@ -236,6 +236,9 @@ class Persona extends Ideal\Service
} else {
$newKey = substr($key, strlen('address_'));
}
+ if ($newKey === 'id') {
+ continue;
+ }
$addressData[$newKey] = $value;
}
if (!empty($addressData)) {
@@ -258,7 +261,7 @@ class Persona extends Ideal\Service
'birthdate' => 'fecha_nacimiento',
];
foreach ($data as $key => $value) {
- if (array_key_exists($key, $dataMap)) {
+ if (array_key_exists($key, $dataMap) and trim($value) !== '') {
$data[$dataMap[$key]] = $value;
unset($data[$key]);
}
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;
}