#723 Added getTaxes to get the total taxes of an order

This commit is contained in:
Gerard 2018-10-08 15:21:06 +02:00
parent 8c0e68313b
commit 274e44368e
6 changed files with 43 additions and 9 deletions

View File

@ -48,10 +48,10 @@ class Controller {
}
getVAT() {
let query = `/order/api/Orders/${this.$state.params.id}/getTaxes`;
let query = `/order/api/Orders/${this.$state.params.id}/getVAT`;
this.$http.get(query).then(res => {
this.VAT = res.data.tax;
this.VAT = res.data;
});
}

View File

@ -56,9 +56,9 @@ describe('Order', () => {
});
});
describe('getTaxes()', () => {
it('should make a query to get the taxes of a given order', () => {
$httpBackend.expectGET(`/order/api/Orders/1/getTaxes`).respond({data: {tax: 3}});
describe('getVAT()', () => {
it('should make a query to get the VAT of a given order', () => {
$httpBackend.expectGET(`/order/api/Orders/1/getVAT`).respond({data: {tax: 3}});
controller.getVAT();
$httpBackend.flush();
});

View File

@ -23,7 +23,7 @@ module.exports = Self => {
let query = `CALL hedera.orderGetTax(?);
SELECT * FROM tmp.orderTax;`;
let res = await Self.rawSql(query, [orderFk]);
let [taxes] = res[1];
let taxes = res[1];
return taxes;
};

View File

@ -0,0 +1,31 @@
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 => {
let totalTax = 0.00;
let taxes = await Self.app.models.Order.getTaxes(orderId);
taxes.forEach(tax => {
totalTax += tax.tax;
});
return Math.round(totalTax * 100) / 100;
};
};

View File

@ -4,18 +4,19 @@ describe('order getTaxes()', () => {
it('should call the getTaxes method and return undefined if its called with a string', async() => {
let result = await app.models.Order.getTaxes('pepinillos');
expect(result).toEqual(undefined);
expect(result.length).toEqual(0);
});
it('should call the getTaxes method and return undefined if its called with unknown id', async() => {
let result = await app.models.Order.getTaxes(99999999999999999999999);
expect(result).toEqual(undefined);
expect(result.length).toEqual(0);
});
it('should call the getTaxes method and return the taxes if its called with a known id', async() => {
let result = await app.models.Order.getTaxes(1);
expect(result.tax).toEqual(0.95);
expect(result[0].tax).toEqual(0.95);
expect(result.length).toEqual(1);
});
});

View File

@ -6,4 +6,6 @@ module.exports = Self => {
require('../methods/order/isEditable')(Self);
require('../methods/order/getTotal')(Self);
require('../methods/order/catalogFilter')(Self);
require('../methods/order/summary')(Self);
require('../methods/order/getVAT')(Self);
};