2022-09-22 07:42:04 +00:00
|
|
|
const Component = require(`vn-print/core/component`);
|
2022-11-10 06:48:24 +00:00
|
|
|
const reportBody = new Component('report-body');
|
2021-07-20 07:09:46 +00:00
|
|
|
const reportFooter = new Component('report-footer');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: 'client-debt-statement',
|
|
|
|
async serverPrefetch() {
|
2022-09-22 07:42:04 +00:00
|
|
|
this.client = await this.fetchClient(this.id);
|
|
|
|
this.sales = await this.fetchSales(this.id, this.from);
|
2021-07-20 07:09:46 +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-22 07:42:04 +00:00
|
|
|
fetchClient(id) {
|
|
|
|
return this.findOneFromDef('client', [id]);
|
2021-07-20 07:09:46 +00:00
|
|
|
},
|
2022-09-22 07:42:04 +00:00
|
|
|
fetchSales(id, from) {
|
2021-07-20 07:09:46 +00:00
|
|
|
return this.rawSqlFromDef('sales', [
|
|
|
|
from,
|
2022-09-22 07:42:04 +00:00
|
|
|
id,
|
2021-07-20 07:09:46 +00:00
|
|
|
from,
|
2022-09-22 07:42:04 +00:00
|
|
|
id,
|
2021-07-20 07:09:46 +00:00
|
|
|
from,
|
2022-09-22 07:42:04 +00:00
|
|
|
id,
|
2021-07-20 07:09:46 +00:00
|
|
|
from,
|
2022-09-22 07:42:04 +00:00
|
|
|
id,
|
2021-07-20 07:09:46 +00:00
|
|
|
from,
|
2022-09-22 07:42:04 +00:00
|
|
|
id
|
2021-07-20 07:09:46 +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;
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
components: {
|
2022-11-10 06:48:24 +00:00
|
|
|
'report-body': reportBody.build(),
|
2021-07-20 07:09:46 +00:00
|
|
|
'report-footer': reportFooter.build()
|
|
|
|
},
|
|
|
|
props: {
|
2022-09-22 07:42:04 +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'
|
2021-07-20 07:09:46 +00:00
|
|
|
},
|
|
|
|
from: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|