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

53 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-01-23 12:15:30 +00:00
const vnReport = require('../../../core/mixins/vn-report.js');
2019-11-04 07:54:21 +00:00
module.exports = {
name: 'letter-debtor',
2023-01-23 12:15:30 +00:00
mixins: [vnReport],
2019-11-04 07:54:21 +00:00
async serverPrefetch() {
2023-01-23 12:15:30 +00:00
this.client = await this.findOneFromDef('client', [this.id]);
this.checkMainEntity(this.client);
this.sales = await this.findOneFromDef('sales', [this.id, this.companyId]);
2019-11-04 07:54:21 +00:00
},
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: {
2022-09-26 06:07:45 +00:00
id: {
2022-10-28 13:53:57 +00:00
type: Number,
2022-09-26 11:33:27 +00:00
required: true,
description: 'The client id'
2019-11-04 07:54:21 +00:00
},
companyId: {
2022-10-28 13:53:57 +00:00
type: Number,
2019-11-04 07:54:21 +00:00
required: true
}
}
};