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: [
|
2022-03-23 09:36:00 +00:00
|
|
|
{relation: 'supplier'},
|
|
|
|
{relation: 'invoiceInDueDay'},
|
|
|
|
{relation: 'company',
|
2021-02-10 14:03:11 +00:00
|
|
|
scope: {
|
|
|
|
fields: ['id', 'code']
|
|
|
|
}
|
|
|
|
}
|
2022-03-23 09:36:00 +00:00
|
|
|
|
2021-02-10 14:03:11 +00:00
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2021-02-12 11:19:42 +00:00
|
|
|
return this.getData(`InvoiceIns/${this.id}`, {filter})
|
2022-03-23 09:36:00 +00:00
|
|
|
.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,
|
|
|
|
dueDated: {gte: new Date()}
|
|
|
|
}
|
|
|
|
}})
|
|
|
|
.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-17 13:13:27 +00:00
|
|
|
showPdfInvoice() {
|
|
|
|
this.vnReport.show(`InvoiceIns/${this.id}/invoiceInPdf`);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
});
|