salix/print/templates/reports/client-debt-statement/client-debt-statement.js

51 lines
1.4 KiB
JavaScript
Executable File

const vnReport = require('../../../core/mixins/vn-report.js');
module.exports = {
name: 'client-debt-statement',
mixins: [vnReport],
async serverPrefetch() {
this.client = await this.findOneFromDef('client', [this.id]);
this.checkMainEntity(this.client);
this.sales = await this.rawSqlFromDef('sales',
[this.from, this.id, this.from, this.id, this.from, this.id, this.from, this.id, this.from, this.id]);
},
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;
for (let sale of this.sales)
debtOut += sale.debtOut ? parseFloat(sale.debtOut) : 0;
return debtOut.toFixed(2);
},
getTotalDebtIn() {
let debtIn = 0.00;
for (let sale of this.sales)
debtIn += sale.debtIn ? parseFloat(sale.debtIn) : 0;
return debtIn.toFixed(2);
},
},
props: {
id: {
type: Number,
required: true,
description: 'The client id'
},
from: {
required: true
}
}
};