2021-11-09 14:10:43 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import Section from 'salix/components/section';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
class Controller extends Section {
|
2021-11-10 13:48:17 +00:00
|
|
|
constructor($element, $, vnReport, vnEmail) {
|
2021-11-09 14:10:43 +00:00
|
|
|
super($element, $);
|
2021-11-10 13:48:17 +00:00
|
|
|
this.vnReport = vnReport;
|
|
|
|
this.vnEmail = vnEmail;
|
2021-11-09 14:10:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get invoiceOut() {
|
|
|
|
return this._invoiceOut;
|
|
|
|
}
|
|
|
|
|
|
|
|
set invoiceOut(value) {
|
|
|
|
this._invoiceOut = value;
|
2021-11-10 13:48:17 +00:00
|
|
|
if (value)
|
|
|
|
this.id = value.id;
|
2021-11-09 14:10:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
loadData() {
|
|
|
|
const filter = {
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
relation: 'company',
|
|
|
|
scope: {
|
|
|
|
fields: ['id', 'code']
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
relation: 'client',
|
|
|
|
scope: {
|
|
|
|
fields: ['id', 'name', 'email']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2021-11-10 13:48:17 +00:00
|
|
|
return this.$http.get(`InvoiceOuts/${this.invoiceOut.id}`, {filter})
|
|
|
|
.then(res => this.invoiceOut = res.data);
|
2021-11-09 14:10:43 +00:00
|
|
|
}
|
|
|
|
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'))
|
2021-11-10 13:48:17 +00:00
|
|
|
.then(() => this.$state.reload())
|
|
|
|
.then(() => this.vnApp.showSuccess(this.$t('InvoiceOut deleted')));
|
2021-11-09 14:10:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bookInvoiceOut() {
|
|
|
|
return this.$http.post(`InvoiceOuts/${this.invoiceOut.ref}/book`)
|
|
|
|
.then(() => this.$state.reload())
|
|
|
|
.then(() => this.vnApp.showSuccess(this.$t('InvoiceOut booked')));
|
|
|
|
}
|
|
|
|
|
|
|
|
createPdfInvoice() {
|
2021-11-10 13:48:17 +00:00
|
|
|
return this.$http.post(`InvoiceOuts/${this.id}/createPdf`)
|
2021-11-09 14:10:43 +00:00
|
|
|
.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,
|
2021-11-10 13:48:17 +00:00
|
|
|
invoiceId: this.id
|
2021-11-09 14:10:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
sendPdfInvoice($data) {
|
2021-11-11 13:46:05 +00:00
|
|
|
if (!$data.email)
|
|
|
|
return this.vnApp.showError(this.$t(`The email can't be empty`));
|
|
|
|
|
2021-11-09 14:10:43 +00:00
|
|
|
return this.vnEmail.send('invoice', {
|
|
|
|
recipientId: this.invoiceOut.client.id,
|
|
|
|
recipient: $data.email,
|
|
|
|
invoiceId: this.id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
sendCsvInvoice($data) {
|
2021-11-11 13:46:05 +00:00
|
|
|
if (!$data.email)
|
|
|
|
return this.vnApp.showError(this.$t(`The email can't be empty`));
|
|
|
|
|
2021-11-09 14:10:43 +00:00
|
|
|
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,
|
2021-11-10 13:48:17 +00:00
|
|
|
invoiceId: this.id
|
2021-11-09 14:10:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-10 13:48:17 +00:00
|
|
|
Controller.$inject = ['$element', '$scope', 'vnReport', 'vnEmail'];
|
2021-11-09 14:10:43 +00:00
|
|
|
|
|
|
|
ngModule.vnComponent('vnInvoiceOutDescriptorMenu', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
invoiceOut: '<',
|
2021-11-10 13:48:17 +00:00
|
|
|
parentReload: '&'
|
2021-11-09 14:10:43 +00:00
|
|
|
}
|
|
|
|
});
|