diff --git a/app/resources/routes/api/ventas/reservations.php b/app/resources/routes/api/ventas/reservations.php
index 7e2e194..7625931 100644
--- a/app/resources/routes/api/ventas/reservations.php
+++ b/app/resources/routes/api/ventas/reservations.php
@@ -3,6 +3,11 @@ use Incoviba\Controller\API\Ventas\Reservations;
$app->group('/reservations', function($app) {
$app->post('/add[/]', [Reservations::class, 'add']);
+ $app->group('/project/{project_id}', function($app) {
+ $app->get('/active[/]', [Reservations::class, 'active']);
+ $app->get('/pending[/]', [Reservations::class, 'pending']);
+ $app->get('/rejected[/]', [Reservations::class, 'rejected']);
+ });
$app->get('[/]', Reservations::class);
});
$app->group('/reservation/{reservation_id}', function($app) {
diff --git a/app/resources/views/ventas/reservations.blade.php b/app/resources/views/ventas/reservations.blade.php
index 14936e6..3a5eddb 100644
--- a/app/resources/views/ventas/reservations.blade.php
+++ b/app/resources/views/ventas/reservations.blade.php
@@ -25,70 +25,73 @@
@endif
-
-
@endsection
@@ -131,6 +134,8 @@
event.preventDefault()
const project_id = event.currentTarget.dataset.id
+ reservations.show().results()
+
if (project_id === this.current_project) {
this.hide()
this.title_component.innerHTML = event.currentTarget.innerHTML
@@ -140,9 +145,10 @@
return
}
this.current_project = project_id
- reservations.get().reservations(project_id)
+ reservations.get().reservations(project_id)
this.hide()
+
this.title_component.innerHTML = event.currentTarget.innerHTML
}
watch() {
@@ -295,6 +301,16 @@
`
}
+ empty() {
+ const tbody = this.component.querySelector('tbody')
+ tbody.innerHTML = ''
+ const col_span = this.columnNames.length + 1
+ const tr = document.createElement('tr')
+ tr.innerHTML = `
No hay cierres | `
+ tbody.appendChild(tr)
+
+ this.show()
+ }
show() {
this.component.style.display = this.display.reservations
@@ -352,6 +368,8 @@
const reservations = {
components: {
projects: null,
+ loader: null,
+ results: null,
controls: null,
reservations: {
active: null,
@@ -359,86 +377,74 @@
rejected: null
}
},
+ display: {
+ loader: '',
+ results: '',
+ },
get() {
return {
- active: project_id => {
- const reservations = [
- {
- id: 1,
- summary: 'D1',
- buyer: {
- rut: '12345678-9',
- nombreCompleto: 'Juan Perez'
- },
- fecha: '2021-01-01',
- offer: 3000,
- valid: true,
- broker: {
- name: 'Operador 1'
- }
+ send: (project_id, url_segment, component) => {
+ const url = `/api/ventas/reservations/project/${project_id}/${url_segment}`
+ return APIClient.fetch(url).then(response => response.json()).then(json => {
+ if (json.reservations.length === 0) {
+ component.empty()
+ return
}
- ]
- this.components.reservations.active.set().reservations(reservations).draw()
+ component.set().reservations(json.reservations).draw()
+ })
+ },
+ active: project_id => {
+ return this.get().send(project_id, 'active', this.components.reservations.active)
+ /*const url = `/ventas/reservations/project/${project_id}/active`
+ return APIClient.fetch(url).then(json => {
+ if (json.reservations.length === 0) {
+ return
+ }
+ this.components.reservations.active.set().reservations(json.reservations).draw()
+ })*/
},
pending: project_id => {
- const reservations = [
- {
- id: 2,
- summary: 'D2',
- buyer: {
- rut: '12345678-9',
- nombreCompleto: 'Pedro Jimenez'
- },
- fecha: '2021-10-01',
- offer: 1000,
- valid: false,
- broker: {
- name: 'Operador 2'
- }
+ return this.get().send(project_id, 'pending', this.components.reservations.pending)
+ /*const url = `/ventas/reservations/project/${project_id}/pending`
+ return APIClient.fetch(url).then(json => {
+ if (json.reservations.length === 0) {
+ return
}
- ]
- this.components.reservations.pending.set().reservations(reservations).draw()
+ this.components.reservations.pending.set().reservations(json.reservations).draw()
+ })*/
},
rejected: project_id => {
- const reservations = [
- {
- id: 3,
- summary: 'D3',
- buyer: {
- rut: '12345678-9',
- nombreCompleto: 'Fernando Dominguez'
- },
- fecha: '2021-01-10',
- offer: 1000,
- valid: false,
- state: 'rechazado',
- broker: {
- name: 'Operador 3'
- },
- comments: ['Comentarios']
- },
- {
- id: 4,
- summary: 'D4',
- buyer: {
- rut: '12345678-9',
- nombreCompleto: 'Domingo Gomez'
- },
- fecha: '2021-02-01',
- offer: 1000,
- valid: false,
- state: 'abandonado',
- broker: {
- name: 'Operador 4'
- }
+ return this.get().send(project_id, 'rejected', this.components.reservations.rejected)
+ /*const url = `/ventas/reservations/project/${project_id}/rejected`
+ return APIClient.fetch(url).then(json => {
+ if (json.reservations.length === 0) {
+ return
}
- ]
- this.components.reservations.rejected.set().reservations(reservations).draw()
+ this.components.reservations.rejected.set().reservations(json.reservations).draw()
+ })*/
},
reservations: project_id => {
- this.get().active(project_id)
- this.get().pending(project_id)
- this.get().rejected(project_id)
+ this.loading().show()
+
+ const promises = []
+
+ promises.push(this.get().active(project_id))
+ promises.push(this.get().pending(project_id))
+ promises.push(this.get().rejected(project_id))
+
+ return Promise.any(promises).then(() => {
+ this.loading().hide()
+ })
+ }
+ }
+ },
+ loading() {
+ return {
+ show: () => {
+ this.components.loader.style.display = this.display.loader
+ },
+ hide: () => {
+ this.components.loader.style.display = 'none'
}
}
},
@@ -451,13 +457,13 @@
this.components.reservations[key].reservations = []
this.components.reservations[key].hide()
})
- this.components.projects.show()
+ this.show().projects()
return false
},
up: event => {
event.preventDefault()
Object.values(this.components.reservations).forEach(reservations => reservations.hide())
- this.components.projects.show()
+ this.show().projects()
return false
},
add: event => {
@@ -472,18 +478,37 @@
}
}
},
+ show() {
+ return {
+ projects: () => {
+ this.components.projects.show()
+ this.components.results.style.display = 'none'
+ },
+ results: () => {
+ this.components.projects.hide()
+ this.components.results.style.display = this.display.results
+ }
+ }
+ },
setup(configuration) {
const formatters = {
date: new Intl.DateTimeFormat('es-CL', {year: 'numeric', month: 'long', day: 'numeric'}),
ufs: new Intl.NumberFormat('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2})
}
+ this.components.loader = document.getElementById(configuration.ids.loader)
this.components.projects = new Projects({component_id: configuration.ids.projects, title_id: configuration.ids.project})
this.components.controls = new Controls({component_id: configuration.ids.controls})
this.components.reservations.active = new ActiveReservations({component_id: configuration.ids.active, formatters})
this.components.reservations.pending = new PendingReservations({component_id: configuration.ids.pending, formatters})
this.components.reservations.rejected = new RejectedReservations({component_id: configuration.ids.rejected, formatters})
+ this.display.loader = this.components.loader.style.display
+ this.loading().hide()
+
$(`#${configuration.ids.tabs} .item`).tab()
+ this.components.results = document.getElementById(configuration.ids.results)
+ this.display.results = this.components.results.style.display
+ this.show().projects()
}
}
$(document).ready(() => {
@@ -491,6 +516,8 @@
ids: {
projects: 'projects',
project: 'project',
+ results: 'results',
+ loader: 'loader',
controls: 'controls',
tabs: 'tabs',
active: 'active_reservations',