2021-07-27 07:07:04 +00:00
|
|
|
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;
|
2021-07-27 07:07:04 +00:00
|
|
|
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');
|
|
|
|
|
2021-08-10 09:48:29 +00:00
|
|
|
this.isInvoicing = true;
|
2021-07-27 07:07:04 +00:00
|
|
|
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);
|
2021-07-27 07:07:04 +00:00
|
|
|
} catch (e) {
|
|
|
|
this.vnApp.showError(this.$t(e.message));
|
2021-08-10 09:48:29 +00:00
|
|
|
this.isInvoicing = false;
|
2021-07-27 07:07:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Controller.$inject = ['$element', '$scope', '$transclude'];
|
|
|
|
|
|
|
|
ngModule.vnComponent('vnInvoiceOutManual', {
|
|
|
|
slotTemplate: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
ticketFk: '<?',
|
|
|
|
clientFk: '<?'
|
|
|
|
}
|
|
|
|
});
|