salix/services/loopback/common/methods/ticket/getVAT.js

33 lines
768 B
JavaScript
Raw Normal View History

2018-06-19 10:10:38 +00:00
module.exports = Self => {
Self.remoteMethod('getVAT', {
description: 'Returns ticket total VAT',
accessType: 'READ',
accepts: [{
arg: 'id',
type: 'number',
required: true,
description: 'ticket id',
http: {source: 'path'}
}],
returns: {
type: 'number',
root: true
},
http: {
path: `/:id/getVAT`,
verb: 'GET'
}
});
Self.getVAT = async ticketFk => {
let totalTax = 0.00;
let taxes = await Self.app.models.Ticket.getTaxes(ticketFk);
taxes.forEach(tax => {
totalTax += tax.tax;
});
2018-09-11 13:09:15 +00:00
return Math.round(totalTax * 100) / 100;
2018-06-19 10:10:38 +00:00
};
};