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

52 lines
1.6 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);
2021-08-10 09:48:29 +00:00
this.isInvoicing = false;
this.invoice = {
2023-01-16 14:18:24 +00:00
maxShipped: Date.vnNew()
};
}
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');
2021-08-10 09:48:29 +00:00
this.isInvoicing = true;
return this.$http.post(`InvoiceOuts/createManualInvoice`, this.invoice)
.then(res => {
this.$state.go('invoiceOut.card.summary', {id: res.data.id});
super.responseHandler(response);
})
2021-08-10 09:48:29 +00:00
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
.finally(() => this.isInvoicing = false);
} catch (e) {
this.vnApp.showError(this.$t(e.message));
2021-08-10 09:48:29 +00:00
this.isInvoicing = false;
return false;
}
}
}
Controller.$inject = ['$element', '$scope', '$transclude'];
ngModule.vnComponent('vnInvoiceOutManual', {
slotTemplate: require('./index.html'),
controller: Controller,
bindings: {
ticketFk: '<?',
clientFk: '<?'
}
});