salix/modules/order/back/methods/order/getVAT.js

37 lines
904 B
JavaScript

module.exports = Self => {
Self.remoteMethod('getVAT', {
description: 'Returns order total VAT',
accessType: 'READ',
accepts: [{
arg: 'id',
type: 'number',
required: true,
description: 'order id',
http: {source: 'path'}
}],
returns: {
type: 'number',
root: true
},
http: {
path: `/:id/getVAT`,
verb: 'GET'
}
});
Self.getVAT = async(orderId, options) => {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
let totalTax = 0.00;
const taxes = await Self.app.models.Order.getTaxes(orderId, myOptions);
taxes.forEach(tax => {
totalTax += tax.tax;
});
return Math.round(totalTax * 100) / 100;
};
};