112 lines
3.0 KiB
JavaScript
112 lines
3.0 KiB
JavaScript
|
import ngModule from '../module';
|
||
|
import Section from 'salix/components/section';
|
||
|
import './style.scss';
|
||
|
|
||
|
class Controller extends Section {
|
||
|
constructor($element, $) {
|
||
|
super($element, $);
|
||
|
}
|
||
|
|
||
|
get invoiceOut() {
|
||
|
return this._invoiceOut;
|
||
|
}
|
||
|
|
||
|
set invoiceOut(value) {
|
||
|
this._invoiceOut = value;
|
||
|
}
|
||
|
|
||
|
loadData() {
|
||
|
const filter = {
|
||
|
include: [
|
||
|
{
|
||
|
relation: 'company',
|
||
|
scope: {
|
||
|
fields: ['id', 'code']
|
||
|
}
|
||
|
}, {
|
||
|
relation: 'client',
|
||
|
scope: {
|
||
|
fields: ['id', 'name', 'email']
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
};
|
||
|
return this.getData(`InvoiceOuts/${this.invoiceOut.id}`, {filter})
|
||
|
.then(res => this.invoice = res.data);
|
||
|
}
|
||
|
reload() {
|
||
|
return this.loadData().then(() => {
|
||
|
if (this.parentReload)
|
||
|
this.parentReload();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
cardReload() {
|
||
|
// Prevents error when not defined
|
||
|
}
|
||
|
|
||
|
deleteInvoiceOut() {
|
||
|
return this.$http.post(`InvoiceOuts/${this.invoiceOut.id}/delete`)
|
||
|
.then(() => this.$state.go('invoiceOut.index'))
|
||
|
.then(() => this.vnApp.showSuccess(this.$t('InvoiceOut deleted')))
|
||
|
.then(() => this.close());
|
||
|
}
|
||
|
|
||
|
bookInvoiceOut() {
|
||
|
return this.$http.post(`InvoiceOuts/${this.invoiceOut.ref}/book`)
|
||
|
.then(() => this.$state.reload())
|
||
|
.then(() => this.vnApp.showSuccess(this.$t('InvoiceOut booked')));
|
||
|
}
|
||
|
|
||
|
createPdfInvoice() {
|
||
|
const invoiceId = this.invoiceOut.id;
|
||
|
return this.$http.post(`InvoiceOuts/${invoiceId}/createPdf`)
|
||
|
.then(() => this.reload())
|
||
|
.then(() => {
|
||
|
const snackbarMessage = this.$t(
|
||
|
`The invoice PDF document has been regenerated`);
|
||
|
this.vnApp.showSuccess(snackbarMessage);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
showCsvInvoice() {
|
||
|
this.vnReport.showCsv('invoice', {
|
||
|
recipientId: this.invoiceOut.client.id,
|
||
|
invoiceId: this.id,
|
||
|
});
|
||
|
}
|
||
|
|
||
|
sendPdfInvoice($data) {
|
||
|
return this.vnEmail.send('invoice', {
|
||
|
recipientId: this.invoiceOut.client.id,
|
||
|
recipient: $data.email,
|
||
|
invoiceId: this.id
|
||
|
});
|
||
|
}
|
||
|
|
||
|
sendCsvInvoice($data) {
|
||
|
return this.vnEmail.sendCsv('invoice', {
|
||
|
recipientId: this.invoiceOut.client.id,
|
||
|
recipient: $data.email,
|
||
|
invoiceId: this.id
|
||
|
});
|
||
|
}
|
||
|
|
||
|
showExportationLetter() {
|
||
|
this.vnReport.show('exportation', {
|
||
|
recipientId: this.invoiceOut.client.id,
|
||
|
invoiceId: this.id,
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Controller.$inject = ['$element', '$scope'];
|
||
|
|
||
|
ngModule.vnComponent('vnInvoiceOutDescriptorMenu', {
|
||
|
template: require('./index.html'),
|
||
|
controller: Controller,
|
||
|
bindings: {
|
||
|
invoiceOut: '<',
|
||
|
}
|
||
|
});
|