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

75 lines
2.0 KiB
JavaScript
Raw Normal View History

2022-09-26 06:07:45 +00:00
const Component = require(`vn-print/core/component`);
2019-11-04 07:54:21 +00:00
const reportHeader = new Component('report-header');
const reportFooter = new Component('report-footer');
module.exports = {
name: 'letter-debtor',
async serverPrefetch() {
2022-09-26 06:07:45 +00:00
this.client = await this.fetchClient(this.id);
this.sales = await this.fetchSales(this.id, this.companyId);
2019-11-04 07:54:21 +00:00
if (!this.client)
throw new Error('Something went wrong');
},
computed: {
dated: function() {
const filters = this.$options.filters;
return filters.date(new Date(), '%d-%m-%Y');
}
},
data() {
return {totalBalance: 0.00};
},
methods: {
2022-09-26 06:07:45 +00:00
fetchClient(id) {
return this.findOneFromDef('client', [id]);
2019-11-04 07:54:21 +00:00
},
2022-09-26 06:07:45 +00:00
fetchSales(id, companyId) {
2021-04-27 08:29:09 +00:00
return this.findOneFromDef('sales', [
2022-09-26 06:07:45 +00:00
id,
2021-04-27 08:29:09 +00:00
companyId
]);
2019-11-04 07:54:21 +00:00
},
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);
},
},
components: {
'report-header': reportHeader.build(),
'report-footer': reportFooter.build()
},
props: {
2022-09-26 06:07:45 +00:00
id: {
2022-01-17 11:44:43 +00:00
type: [Number, String],
2019-11-04 07:54:21 +00:00
required: true
},
companyId: {
2022-01-17 11:44:43 +00:00
type: [Number, String],
2019-11-04 07:54:21 +00:00
required: true
}
}
};