salix/modules/invoiceIn/front/descriptor/index.js

126 lines
3.7 KiB
JavaScript
Raw Permalink Normal View History

2021-02-10 14:03:11 +00:00
import ngModule from '../module';
import Descriptor from 'salix/components/descriptor';
class Controller extends Descriptor {
2021-02-12 11:19:42 +00:00
get invoiceIn() {
2021-02-10 14:03:11 +00:00
return this.entity;
}
2021-02-12 11:19:42 +00:00
set invoiceIn(value) {
2021-02-10 14:03:11 +00:00
this.entity = value;
}
2021-04-12 10:43:17 +00:00
get entryFilter() {
if (this.invoiceIn)
return JSON.stringify({invoiceInFk: this.invoiceIn.id});
return null;
}
get invoiceInFilter() {
if (this.invoiceIn)
return JSON.stringify({supplierFk: this.invoiceIn.supplierFk});
return null;
}
deleteInvoiceIn() {
return this.$http.delete(`InvoiceIns/${this.id}`)
.then(() => this.$state.go('invoiceIn.index'))
.then(() => this.vnApp.showSuccess(this.$t('InvoiceIn deleted')));
}
2021-07-23 12:06:48 +00:00
cloneInvoiceIn() {
return this.$http.post(`InvoiceIns/${this.id}/clone`)
.then(res => this.$state.go('invoiceIn.card.summary', {id: res.data.id}))
.then(() => this.vnApp.showSuccess(this.$t('InvoiceIn cloned')));
}
2021-02-10 14:03:11 +00:00
loadData() {
const filter = {
include: [
{relation: 'supplier'},
{relation: 'invoiceInDueDay'},
{relation: 'company',
2021-02-10 14:03:11 +00:00
scope: {
fields: ['id', 'code']
}
}
2021-02-10 14:03:11 +00:00
]
};
2021-02-12 11:19:42 +00:00
return this.getData(`InvoiceIns/${this.id}`, {filter})
.then(res => {
this.entity = res.data;
this.invoiceIn.amount = res.data.invoiceInDueDay.reduce(
(accumulator, currentValue) => {
return accumulator + (currentValue['amount'] || 0);
}, 0);
});
2021-02-10 14:03:11 +00:00
}
2021-10-05 09:19:48 +00:00
2022-01-20 09:05:24 +00:00
checkToBook() {
2021-09-28 08:57:51 +00:00
let message = '';
const id = this.invoiceIn.id;
this.$q.all([
this.$http.get(`InvoiceIns/${this.id}/getTotals`)
.then(res => {
2021-10-05 09:19:48 +00:00
const taxableBaseNotEqualDueDay = res.data.totalDueDay != res.data.totalTaxableBase;
const vatNotEqualDueDay = res.data.totalDueDay != res.data.totalVat;
if (taxableBaseNotEqualDueDay && vatNotEqualDueDay)
message += 'amountsDoNotMatch';
2021-09-28 08:57:51 +00:00
}),
this.$http.get('InvoiceInDueDays/count', {
filter: {
where: {
invoiceInFk: id,
2023-01-16 14:18:24 +00:00
dueDated: {gte: Date.vnNew()}
2021-09-28 08:57:51 +00:00
}
}})
.then(res => {
2022-01-19 13:21:19 +00:00
if (res.data)
2021-09-28 08:57:51 +00:00
message += 'future payments';
})
]).finally(() => {
2021-10-05 09:19:48 +00:00
if (message.length)
2021-09-28 08:57:51 +00:00
this.$.confirmToBookAnyway.show();
else
2022-01-19 13:21:19 +00:00
this.onAcceptToBook();
2021-09-28 08:57:51 +00:00
});
}
onAcceptToBook() {
2021-10-05 09:19:48 +00:00
this.$http.post(`InvoiceIns/${this.id}/toBook`)
2021-11-23 14:13:34 +00:00
.then(() => this.$state.reload())
.then(() => this.vnApp.showSuccess(this.$t('InvoiceIn booked')));
2021-09-24 06:24:34 +00:00
}
2022-10-24 13:15:23 +00:00
2022-10-17 13:13:27 +00:00
showPdfInvoice() {
2022-10-24 13:15:23 +00:00
this.vnReport.show(`InvoiceIns/${this.id}/invoice-in-pdf`);
}
sendPdfInvoice($data) {
if (!$data.email)
return this.vnApp.showError(this.$t(`The email can't be empty`));
return this.vnEmail.send(`InvoiceIns/${this.entity.id}/invoice-in-email`, {
recipient: $data.email,
recipientId: this.entity.supplier.id
});
2022-10-17 13:13:27 +00:00
}
2022-12-16 09:36:18 +00:00
isAgricultural() {
return this.invoiceIn.supplier.sageWithholdingFk == this.config[0].sageWithholdingFk;
}
2021-02-10 14:03:11 +00:00
}
2021-02-12 11:19:42 +00:00
ngModule.vnComponent('vnInvoiceInDescriptor', {
2021-02-10 14:03:11 +00:00
template: require('./index.html'),
controller: Controller,
bindings: {
2021-02-12 11:19:42 +00:00
invoiceIn: '<'
2021-02-10 14:03:11 +00:00
}
});