111 lines
6.0 KiB
PHP
111 lines
6.0 KiB
PHP
@include('ventas.reservations.modal.common.modal', ['prefix' => 'edit', 'modalTitle' => 'Editar Reserva', 'okText' => 'Guardar Cambios'])
|
|
|
|
@push('page_scripts')
|
|
<script>
|
|
class EditModalPromotions extends ModalPromotions {
|
|
constructor() {
|
|
super('edit');
|
|
}
|
|
}
|
|
class EditModalUnits extends ModalUnits {
|
|
constructor(parent) {
|
|
super({prefix: 'edit', parent})
|
|
}
|
|
}
|
|
class EditModalPayments extends ModalPayments {
|
|
constructor() {
|
|
super('edit');
|
|
}
|
|
}
|
|
class EditReservationModal extends ReservationModal {
|
|
constructor(projects_id) {
|
|
super({projects_id, prefix: 'edit', components: {
|
|
promotions: new EditModalPromotions(),
|
|
units: new EditModalUnits(),
|
|
payments: new EditModalPayments()
|
|
}});
|
|
}
|
|
|
|
show({type, reservation_id}) {
|
|
const reservation = reservations.components.reservations[type].reservations.find(r => r.id === parseInt(reservation_id))
|
|
super.show()
|
|
this.fillReservation(reservation)
|
|
}
|
|
async fillReservation(reservation) {
|
|
console.debug(this.components, reservation)
|
|
this.components.form.querySelector('#edit_reservation_id').value = reservation.id
|
|
const date = new Date(reservation.date)
|
|
date.setDate(date.getDate() + 1)
|
|
this.components.$date.calendar('set date', date)
|
|
this.components.rut.querySelector('input[name="edit_buyer_rut"]').value = Rut.format(reservation.buyer.rut) || ''
|
|
this.components.digit.textContent = reservation.buyer.digito || ''
|
|
this.components.form.querySelector('[name="edit_buyer_name"]').value = reservation.buyer.nombres || ''
|
|
this.components.form.querySelector('[name="edit_buyer_last_name"]').value = reservation.buyer.apellidoPaterno || ''
|
|
this.components.form.querySelector('[name="edit_buyer_last_name2"]').value = reservation.buyer.apellidoMaterno || ''
|
|
if ('datos' in reservation.buyer && reservation.buyer.datos !== null) {
|
|
if ('direccion' in reservation.buyer.datos && reservation.buyer.datos.direccion !== null) {
|
|
this.components.form.querySelector('[name="edit_buyer_address_street"]').value = reservation.buyer.datos.direccion.calle
|
|
this.components.form.querySelector('[name="edit_buyer_address_number"]').value = reservation.buyer.datos.direccion.numero
|
|
this.components.form.querySelector('[name="edit_buyer_address_extra"]').value = reservation.buyer.datos.direccion.extra
|
|
this.components.$region.dropdown('set selected', reservation.buyer.datos.direccion.comuna.provincia.region.id)
|
|
const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
|
|
const waitComuna = async () => {
|
|
await delay(500)
|
|
this.components.$comuna.dropdown('set selected', reservation.buyer.datos.direccion.comuna.id)
|
|
}
|
|
await waitComuna()
|
|
}
|
|
this.components.form.querySelector('[name="edit_buyer_phone"]').value = reservation.buyer.datos.telefono || ''
|
|
if ('email' in reservation.buyer.datos && reservation.buyer.datos.email.includes('@') && reservation.buyer.datos.email.length > 1) {
|
|
const parts = reservation.buyer.datos.email.split('@')
|
|
this.components.form.querySelector('[name="edit_buyer_email_name"]').value = parts[0]
|
|
this.components.form.querySelector('[name="edit_buyer_email_domain"]').value = parts[1]
|
|
}
|
|
this.components.form.querySelector('[name="edit_buyer_marital_status"]').value = reservation.buyer.datos.estadoCivil || ''
|
|
this.components.form.querySelector('[name="edit_buyer_profession"]').value = reservation.buyer.datos.ocupacion || ''
|
|
if ('fechaNacimiento' in reservation.buyer.datos) {
|
|
const birthdate = new Date(reservation.buyer.datos.fechaNacimiento)
|
|
birthdate.setDate(birthdate.getDate() + 1)
|
|
this.components.$birthdate.calendar('set date', birthdate)
|
|
}
|
|
}
|
|
if (reservation.broker !== null) {
|
|
if (reservations.locks.brokers === null) {
|
|
await reservations.locks.brokers
|
|
}
|
|
this.components.$broker.dropdown('set selected', reservation.broker.rut)
|
|
}
|
|
if (reservation.promotions.length > 0) {
|
|
this.components.promotions.fill(reservation.promotions)
|
|
}
|
|
if (reservation.units.length > 0) {
|
|
this.components.units.fill(reservation.units)
|
|
}
|
|
if ('formaPago' in reservation && reservation.formaPago !== null) {
|
|
this.components.payments.fill(reservation.formaPago)
|
|
}
|
|
}
|
|
edit() {}
|
|
setup() {
|
|
super.setup()
|
|
|
|
this.components.$modal.modal({
|
|
onApprove: () => {
|
|
this.edit()
|
|
}
|
|
})
|
|
this.components.form.addEventListener('submit', event => {
|
|
event.preventDefault()
|
|
this.edit()
|
|
return false
|
|
})
|
|
const idInput = document.createElement('input')
|
|
idInput.type = 'hidden'
|
|
idInput.id = 'edit_reservation_id'
|
|
idInput.name = 'edit_reservation_id'
|
|
this.components.form.appendChild(idInput)
|
|
}
|
|
}
|
|
</script>
|
|
@endpush
|