import ngModule from '../module'; import Section from 'salix/components/section'; class Controller extends Section { onDialogAccept(id) { return this.$http.delete(`Expeditions/${id}`) .then(() => this.$.model.refresh()); } showLog(expedition) { this.expedition = expedition; this.$.statusLog.show(); } get checked() { const rows = this.$.model.data || []; const checkedRows = []; for (let row of rows) { if (row.checked) checkedRows.push(row); } return checkedRows; } get totalChecked() { return this.checked.length; } async onRemove() { const params = []; for (let expedition of this.checked) params.push(expedition.id); for (let id of params) { await this.$http.delete(`Expeditions/${id}`) .then(() => { this.vnApp.showSuccess(this.$t('Expedition removed')); this.$state.reload(); }); } } createTicket(routeFk) { const date = new Date(); // esta fecha hay que preguntarla a Fran Monsalvez const ticketParams = { clientId: this.ticket.clientFk, landed: date, addressId: this.ticket.addressFk, agencyModeId: this.ticket.agencyModeFk, warehouseId: this.ticket.warehouseFk }; const query = `Tickets/new`; this.$http.post(query, ticketParams).then(res => { if (routeFk) this.$http.patch(`Tickets/${res.data.id}`, {routeFk: routeFk}); const params = []; for (let expedition of this.checked) params.push(expedition.id); const expeditionParams = {ticketFk: res.data.id}; for (let id of params) this.$http.patch(`Expeditions/${id}`, expeditionParams); this.vnApp.showSuccess(this.$t('Data saved!')); this.$state.go('ticket.card.summary', {id: res.data.id}); }); } } ngModule.vnComponent('vnTicketExpedition', { template: require('./index.html'), controller: Controller, bindings: { ticket: '<', }, });