2019-11-04 07:54:21 +00:00
|
|
|
const Component = require(`${appPath}/core/component`);
|
|
|
|
const reportHeader = new Component('report-header');
|
|
|
|
const reportFooter = new Component('report-footer');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: 'letter-debtor',
|
|
|
|
async serverPrefetch() {
|
2020-05-22 13:20:55 +00:00
|
|
|
this.client = await this.fetchClient(this.recipientId);
|
|
|
|
this.sales = await this.fetchSales(this.recipientId, 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: {
|
|
|
|
fetchClient(clientId) {
|
2020-09-28 11:54:02 +00:00
|
|
|
return this.findOneFromDef('client', [clientId]);
|
2019-11-04 07:54:21 +00:00
|
|
|
},
|
|
|
|
fetchSales(clientId, companyId) {
|
2021-04-27 08:29:09 +00:00
|
|
|
return this.findOneFromDef('sales', [
|
|
|
|
clientId,
|
|
|
|
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: {
|
2020-05-22 13:20:55 +00:00
|
|
|
recipientId: {
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|