2019-03-26 13:27:08 +00:00
|
|
|
import ngModule from '../module';
|
2020-04-25 09:50:04 +00:00
|
|
|
import Descriptor from 'salix/components/descriptor';
|
2019-03-26 13:27:08 +00:00
|
|
|
|
2020-04-25 09:50:04 +00:00
|
|
|
class Controller extends Descriptor {
|
2019-03-26 13:27:08 +00:00
|
|
|
get invoiceOut() {
|
2020-04-30 10:48:52 +00:00
|
|
|
return this.entity;
|
2019-04-26 10:05:49 +00:00
|
|
|
}
|
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
set invoiceOut(value) {
|
|
|
|
this.entity = value;
|
2019-04-30 09:03:48 +00:00
|
|
|
}
|
|
|
|
|
2021-10-01 12:31:42 +00:00
|
|
|
get hasInvoicing() {
|
|
|
|
return this.aclService.hasAny(['invoicing']);
|
|
|
|
}
|
|
|
|
|
2020-03-31 13:15:16 +00:00
|
|
|
deleteInvoiceOut() {
|
2020-04-30 10:48:52 +00:00
|
|
|
return this.$http.post(`InvoiceOuts/${this.id}/delete`)
|
2020-03-31 13:15:16 +00:00
|
|
|
.then(() => this.$state.go('invoiceOut.index'))
|
|
|
|
.then(() => this.vnApp.showSuccess(this.$t('InvoiceOut deleted')));
|
2019-04-26 10:05:49 +00:00
|
|
|
}
|
|
|
|
|
2020-03-31 13:15:16 +00:00
|
|
|
bookInvoiceOut() {
|
2020-04-30 10:48:52 +00:00
|
|
|
return this.$http.post(`InvoiceOuts/${this.invoiceOut.ref}/book`)
|
2020-03-31 13:15:16 +00:00
|
|
|
.then(() => this.$state.reload())
|
|
|
|
.then(() => this.vnApp.showSuccess(this.$t('InvoiceOut booked')));
|
2019-04-30 09:03:48 +00:00
|
|
|
}
|
2020-04-30 10:48:52 +00:00
|
|
|
|
2021-10-07 08:04:50 +00:00
|
|
|
createPdfInvoice() {
|
2021-03-15 12:43:22 +00:00
|
|
|
const invoiceId = this.invoiceOut.id;
|
|
|
|
return this.$http.post(`InvoiceOuts/${invoiceId}/createPdf`)
|
2021-10-01 12:31:42 +00:00
|
|
|
.then(() => this.reload())
|
2021-03-15 12:43:22 +00:00
|
|
|
.then(() => {
|
|
|
|
const snackbarMessage = this.$t(
|
|
|
|
`The invoice PDF document has been regenerated`);
|
|
|
|
this.vnApp.showSuccess(snackbarMessage);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-05-29 09:10:58 +00:00
|
|
|
get filter() {
|
|
|
|
if (this.invoiceOut)
|
|
|
|
return JSON.stringify({refFk: this.invoiceOut.ref});
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
loadData() {
|
|
|
|
const filter = {
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
relation: 'company',
|
|
|
|
scope: {
|
|
|
|
fields: ['id', 'code']
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
relation: 'client',
|
|
|
|
scope: {
|
2021-10-01 10:41:31 +00:00
|
|
|
fields: ['id', 'name', 'email']
|
2020-04-30 10:48:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
return this.getData(`InvoiceOuts/${this.id}`, {filter})
|
|
|
|
.then(res => this.entity = res.data);
|
|
|
|
}
|
2021-07-19 10:31:09 +00:00
|
|
|
|
2021-10-01 12:31:42 +00:00
|
|
|
reload() {
|
|
|
|
return this.loadData().then(() => {
|
|
|
|
if (this.cardReload)
|
|
|
|
this.cardReload();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
cardReload() {
|
|
|
|
// Prevents error when not defined
|
|
|
|
}
|
|
|
|
|
2021-10-07 08:04:50 +00:00
|
|
|
showCsvInvoice() {
|
|
|
|
this.vnReport.showCsv('invoice', {
|
2021-10-01 10:41:31 +00:00
|
|
|
recipientId: this.invoiceOut.client.id,
|
|
|
|
invoiceId: this.id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-10-07 08:04:50 +00:00
|
|
|
sendPdfInvoice($data) {
|
2021-07-19 10:31:09 +00:00
|
|
|
return this.vnEmail.send('invoice', {
|
|
|
|
recipientId: this.invoiceOut.client.id,
|
2021-09-20 11:59:57 +00:00
|
|
|
recipient: $data.email,
|
2021-07-19 10:31:09 +00:00
|
|
|
invoiceId: this.id
|
|
|
|
});
|
|
|
|
}
|
2021-10-01 10:41:31 +00:00
|
|
|
|
2021-10-07 08:04:50 +00:00
|
|
|
sendCsvInvoice($data) {
|
|
|
|
return this.vnEmail.sendCsv('invoice', {
|
|
|
|
recipientId: this.invoiceOut.client.id,
|
2021-10-01 10:41:31 +00:00
|
|
|
recipient: $data.email,
|
2021-10-07 08:04:50 +00:00
|
|
|
invoiceId: this.id
|
2021-10-01 10:41:31 +00:00
|
|
|
});
|
|
|
|
}
|
2019-03-26 13:27:08 +00:00
|
|
|
}
|
|
|
|
|
2020-04-25 09:50:04 +00:00
|
|
|
ngModule.vnComponent('vnInvoiceOutDescriptor', {
|
2019-03-26 13:27:08 +00:00
|
|
|
template: require('./index.html'),
|
2020-04-25 09:50:04 +00:00
|
|
|
controller: Controller,
|
2019-03-26 13:27:08 +00:00
|
|
|
bindings: {
|
2021-10-01 12:31:42 +00:00
|
|
|
invoiceOut: '<',
|
|
|
|
cardReload: '&'
|
2020-04-25 09:50:04 +00:00
|
|
|
}
|
2019-03-26 13:27:08 +00:00
|
|
|
});
|