import ngModule from '../../module'; import Dialog from 'core/components/dialog'; import './style.scss'; class Controller extends Dialog { constructor($element, $, $transclude) { super($element, $, $transclude); this.invoice = { maxShipped: new Date() }; this.getMinClientId(); this.getMaxClientId(); } getMinClientId() { this.getClientId('min').then(res => { this.invoice.fromClientId = res.data.id; }); } getMaxClientId() { this.getClientId('max').then(res => { this.invoice.toClientId = res.data.id; }); } getClientId(func) { const order = func == 'min' ? 'ASC' : 'DESC'; const params = { filter: { order: 'id ' + order, limit: 1 } }; return this.$http.get('Clients/findOne', {params}); } get companyFk() { return this.invoice.companyFk; } set companyFk(value) { this.invoice.companyFk = value; } responseHandler(response) { try { if (response !== 'accept') return super.responseHandler(response); /* if (this.invoice.clientFk && !this.invoice.maxShipped) throw new Error('Client and the max shipped should be filled'); if (!this.invoice.serial || !this.invoice.taxArea) throw new Error('Some fields are required'); */ return this.$http.post(`InvoiceOuts/globalInvoicing`, this.invoice) .then(() => super.responseHandler(response)) .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))); } catch (e) { this.vnApp.showError(this.$t(e.message)); return false; } } } Controller.$inject = ['$element', '$scope', '$transclude']; ngModule.vnComponent('vnInvoiceOutGlobalInvoicing', { slotTemplate: require('./index.html'), controller: Controller, bindings: { companyFk: '