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

33 lines
744 B
JavaScript

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;
});
return totalTax;
};
};