salix/modules/invoiceOut/front/index/manual/index.js

48 lines
1.4 KiB
JavaScript
Raw Normal View History

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()
};
}
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/createManualInvoice`, this.invoice)
.then(res => {
this.$state.go('invoiceOut.card.summary', {id: res.data.id});
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('vnInvoiceOutManual', {
slotTemplate: require('./index.html'),
controller: Controller,
bindings: {
ticketFk: '<?',
clientFk: '<?'
}
});