salix/print/templates/reports/letter-debtor/letter-debtor.js

53 lines
1.4 KiB
JavaScript
Executable File

const vnReport = require('../../../core/mixins/vn-report.js');
module.exports = {
name: 'letter-debtor',
mixins: [vnReport],
async serverPrefetch() {
this.client = await this.findOneFromDef('client', [this.id]);
this.checkMainEntity(this.client);
this.sales = await this.findOneFromDef('sales', [this.id, this.companyId]);
},
data() {
return {totalBalance: 0.00};
},
methods: {
getBalance(sale) {
if (sale.debtOut)
this.totalBalance += parseFloat(sale.debtOut);
if (sale.debtIn)
this.totalBalance -= parseFloat(sale.debtIn);
return parseFloat(this.totalBalance.toFixed(2));
},
getTotalDebtOut() {
let debtOut = 0.00;
this.sales.forEach(sale => {
debtOut += sale.debtOut ? parseFloat(sale.debtOut) : 0;
});
return debtOut.toFixed(2);
},
getTotalDebtIn() {
let debtIn = 0.00;
this.sales.forEach(sale => {
debtIn += sale.debtIn ? parseFloat(sale.debtIn) : 0;
});
return debtIn.toFixed(2);
},
},
props: {
id: {
type: Number,
required: true,
description: 'The client id'
},
companyId: {
type: Number,
required: true
}
}
};