import ngModule from '../module'; import ModuleCard from 'salix/components/module-card'; import UserError from 'core/lib/user-error'; class Controller extends ModuleCard { reload() { let filter = { include: [ { relation: 'address' }, { relation: 'zone' }, { relation: 'warehouse', scope: {fields: ['name']} }, { relation: 'invoiceOut', scope: {fields: ['id']} }, { relation: 'agencyMode', scope: {fields: ['name']} }, { relation: 'client', scope: { fields: [ 'salesPersonFk', 'name', 'isActive', 'isFreezed', 'isTaxDataChecked', 'credit', 'email', 'phone', 'mobile', 'hasElectronicInvoice', ], include: { relation: 'salesPersonUser', scope: { fields: ['id', 'name'] } }, }, }, { relation: 'ticketState', scope: { fields: ['stateFk'], include: { relation: 'state', fields: ['id', 'name'], } }, }, ], }; if (!this.$params.id) { this.$state.go('ticket.index'); throw new UserError(`You must select a ticket`); } return this.$http.get(`Tickets/${this.$params.id}`, {filter}) .then(res => this.onData(res.data)); } onData(data) { this.ticket = data; return this.$http.get(`Clients/${data.client.id}/getDebt`) .then(res => this.ticket.client.debt = res.data.debt); } } ngModule.vnComponent('vnTicketCard', { template: require('./index.html'), controller: Controller });