#723 Added getTaxes to get the total taxes of an order
This commit is contained in:
parent
8c0e68313b
commit
274e44368e
|
@ -48,10 +48,10 @@ class Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
getVAT() {
|
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.$http.get(query).then(res => {
|
||||||
this.VAT = res.data.tax;
|
this.VAT = res.data;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,9 +56,9 @@ describe('Order', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getTaxes()', () => {
|
describe('getVAT()', () => {
|
||||||
it('should make a query to get the taxes of a given order', () => {
|
it('should make a query to get the VAT of a given order', () => {
|
||||||
$httpBackend.expectGET(`/order/api/Orders/1/getTaxes`).respond({data: {tax: 3}});
|
$httpBackend.expectGET(`/order/api/Orders/1/getVAT`).respond({data: {tax: 3}});
|
||||||
controller.getVAT();
|
controller.getVAT();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
});
|
});
|
||||||
|
|
|
@ -23,7 +23,7 @@ module.exports = Self => {
|
||||||
let query = `CALL hedera.orderGetTax(?);
|
let query = `CALL hedera.orderGetTax(?);
|
||||||
SELECT * FROM tmp.orderTax;`;
|
SELECT * FROM tmp.orderTax;`;
|
||||||
let res = await Self.rawSql(query, [orderFk]);
|
let res = await Self.rawSql(query, [orderFk]);
|
||||||
let [taxes] = res[1];
|
let taxes = res[1];
|
||||||
|
|
||||||
return taxes;
|
return taxes;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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;
|
||||||
|
};
|
||||||
|
};
|
|
@ -4,18 +4,19 @@ describe('order getTaxes()', () => {
|
||||||
it('should call the getTaxes method and return undefined if its called with a string', async() => {
|
it('should call the getTaxes method and return undefined if its called with a string', async() => {
|
||||||
let result = await app.models.Order.getTaxes('pepinillos');
|
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() => {
|
it('should call the getTaxes method and return undefined if its called with unknown id', async() => {
|
||||||
let result = await app.models.Order.getTaxes(99999999999999999999999);
|
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() => {
|
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);
|
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,4 +6,6 @@ module.exports = Self => {
|
||||||
require('../methods/order/isEditable')(Self);
|
require('../methods/order/isEditable')(Self);
|
||||||
require('../methods/order/getTotal')(Self);
|
require('../methods/order/getTotal')(Self);
|
||||||
require('../methods/order/catalogFilter')(Self);
|
require('../methods/order/catalogFilter')(Self);
|
||||||
|
require('../methods/order/summary')(Self);
|
||||||
|
require('../methods/order/getVAT')(Self);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue