Cau 8402 fix test and update structure
gitea/salix/dev This commit looks good
Details
gitea/salix/dev This commit looks good
Details
This commit is contained in:
parent
acbe9b8488
commit
11c6fd2da7
|
@ -38,7 +38,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
stmts.push('CALL hedera.orderGetTax()');
|
stmts.push('CALL hedera.orderGetTax()');
|
||||||
|
|
||||||
let orderTaxIndex = stmts.push('SELECT * FROM tmp.orderTax') - 1;
|
let orderTaxIndex = stmts.push('SELECT * FROM tmp.orderAmount') - 1;
|
||||||
|
|
||||||
stmts.push(`
|
stmts.push(`
|
||||||
DROP TEMPORARY TABLE
|
DROP TEMPORARY TABLE
|
||||||
|
|
|
@ -13,10 +13,19 @@ describe('order getTaxes()', () => {
|
||||||
expect(result.length).toEqual(0);
|
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 splited if different type of taxes', async() => {
|
||||||
let result = await app.models.Order.getTaxes(1);
|
let result = await app.models.Order.getTaxes(1);
|
||||||
|
|
||||||
expect(result[0].tax).toEqual(9.49);
|
const expectedResult = result[0].tax + result[1].tax;
|
||||||
|
|
||||||
|
expect(expectedResult).toEqual(20.29);
|
||||||
|
expect(result.length).toEqual(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call the getTaxes method and return the taxes for them same type', async() => {
|
||||||
|
let result = await app.models.Order.getTaxes(2);
|
||||||
|
|
||||||
|
expect(result[0].tax).toEqual(9.1);
|
||||||
expect(result.length).toEqual(1);
|
expect(result.length).toEqual(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('order getTotal()', () => {
|
describe('order getTotal()', () => {
|
||||||
it('should return the total', async() => {
|
it('should return the order total', async() => {
|
||||||
let result = await app.models.Order.getTotal(1);
|
let result = await app.models.Order.getTotal(1);
|
||||||
|
|
||||||
expect(result).toEqual(145.09);
|
expect(result).toEqual(155.89);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,10 +2,9 @@ const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('order getVAT()', () => {
|
describe('order getVAT()', () => {
|
||||||
it('should call the getVAT method and return the response', async() => {
|
it('should call the getVAT method and return the response', async() => {
|
||||||
await app.models.Order.getVAT(1)
|
const result = await app.models.Order.getVAT(1);
|
||||||
.then(response => {
|
|
||||||
expect(response).toEqual(9.49);
|
expect(result).toEqual(20.29);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should call the getVAT method and return zero if doesn't have lines`, async() => {
|
it(`should call the getVAT method and return zero if doesn't have lines`, async() => {
|
||||||
|
|
|
@ -23,7 +23,7 @@ describe('order summary()', () => {
|
||||||
it('should return a summary object containing VAT for 1 order', async() => {
|
it('should return a summary object containing VAT for 1 order', async() => {
|
||||||
let result = await app.models.Order.summary(1);
|
let result = await app.models.Order.summary(1);
|
||||||
|
|
||||||
expect(Math.round(result.VAT * 100) / 100).toEqual(9.49);
|
expect(Math.round(result.VAT * 100) / 100).toEqual(20.29);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a summary object containing total for 1 order', async() => {
|
it('should return a summary object containing total for 1 order', async() => {
|
||||||
|
|
|
@ -25,7 +25,6 @@ module.exports = Self => {
|
||||||
summary.subTotal = getSubTotal(summary.rows);
|
summary.subTotal = getSubTotal(summary.rows);
|
||||||
summary.VAT = await models.Order.getVAT(orderId);
|
summary.VAT = await models.Order.getVAT(orderId);
|
||||||
summary.total = await models.Order.getTotal(orderId);
|
summary.total = await models.Order.getTotal(orderId);
|
||||||
|
|
||||||
return summary;
|
return summary;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,9 @@ DROP TEMPORARY TABLE IF EXISTS tmp.orderTotal;
|
||||||
CREATE TEMPORARY TABLE tmp.orderTotal
|
CREATE TEMPORARY TABLE tmp.orderTotal
|
||||||
(INDEX (orderFk))
|
(INDEX (orderFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT o.orderFk, IFNULL(SUM(ot.taxBase + ot.tax + ot.equalizationTax), 0.0) AS total
|
SELECT o.orderFk, IFNULL(SUM(ot.taxableBase + ot.tax), 0.0) AS total
|
||||||
FROM tmp.order o
|
FROM tmp.order o
|
||||||
LEFT JOIN tmp.orderTax ot ON o.orderFk = ot.orderFk
|
LEFT JOIN tmp.orderAmount ot ON o.orderFk = ot.orderFk
|
||||||
GROUP BY orderFk;
|
GROUP BY orderFk;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.orderTax;
|
DROP TEMPORARY TABLE IF EXISTS tmp.orderTax;
|
||||||
|
|
|
@ -3,49 +3,63 @@ DROP procedure IF EXISTS `orderGetTax`;
|
||||||
|
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
USE `hedera`$$
|
USE `hedera`$$
|
||||||
|
|
||||||
CREATE DEFINER=`root`@`%` PROCEDURE `orderGetTax`()
|
CREATE DEFINER=`root`@`%` PROCEDURE `orderGetTax`()
|
||||||
READS SQL DATA
|
READS SQL DATA
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Calcula el IVA, y el recargo de equivalencia de un pedido
|
* Calcula el IVA, y el recargo de equivalencia de un pedido
|
||||||
* desglosados por tipos.
|
* desglosados por tipos.
|
||||||
*
|
*
|
||||||
* @tabla tmp.order Contiene los identificadores de los pedidos
|
* @param vOrder El identificador del pedido
|
||||||
* @treturn tmp.orderTax Bases imponibles, IVA y recargo de equivalencia
|
* @treturn tmp.orderTax Bases imponibles, IVA y recargo de equivalencia
|
||||||
*/
|
*/
|
||||||
CALL vn.taxGetRates (NULL);
|
DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany;
|
||||||
|
CREATE TEMPORARY TABLE tmp.addressCompany
|
||||||
|
(INDEX (addressFk, companyFk))
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT DISTINCT o.address_id addressFk, o.company_id companyFk
|
||||||
|
FROM tmp.order tmpOrder
|
||||||
|
JOIN hedera.order o ON o.id = tmpOrder.orderFk;
|
||||||
|
|
||||||
-- Calcula el IVA y el recargo desglosado.
|
CALL vn.addressTaxArea ();
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.orderTax;
|
-- Calcula el IVA y el recargo desglosado.
|
||||||
CREATE TEMPORARY TABLE tmp.orderTax
|
DROP TEMPORARY TABLE IF EXISTS tmp.orderTax;
|
||||||
(INDEX (orderFk))
|
CREATE TEMPORARY TABLE tmp.orderTax
|
||||||
ENGINE = MEMORY
|
(INDEX (orderFk))
|
||||||
SELECT id orderFk, t.type, t.taxBase,
|
ENGINE = MEMORY
|
||||||
CAST(IF(t.hasTax, t.taxBase * x.rate, 0) AS DECIMAL(10,2)) tax,
|
SELECT o.id orderFk,
|
||||||
CAST(IF(t.hasEqualizationTax, t.taxBase * x.equalizationTax, 0) AS DECIMAL(10,2)) equalizationTax
|
tc.code,
|
||||||
FROM (
|
SUM(m.amount * m.price) taxableBase,
|
||||||
SELECT o.id, g.countryFk, g.type
|
pgc.rate
|
||||||
,SUM(CAST(m.amount * m.price AS DECIMAL(10,2))) taxBase
|
FROM tmp.order tmpOrder
|
||||||
,NOT(c.isVies AND p.countryFk <> c.countryFk) hasTax
|
JOIN `order` o ON o.id = tmpOrder.orderFk
|
||||||
,c.isEqualizated != FALSE AS hasEqualizationTax
|
JOIN orderRow m ON m.orderFk = o.id
|
||||||
FROM `order` o
|
JOIN vn.item i ON i.id = m.itemFk
|
||||||
JOIN tmp.order tmpo ON tmpo.orderFk = o.id
|
JOIN vn.client c ON c.id = o.customer_id
|
||||||
JOIN orderRow m ON m.orderFk = o.id
|
JOIN vn.supplier s ON s.id = o.company_id
|
||||||
JOIN vn.item a ON a.id = m.itemFk
|
JOIN tmp.addressTaxArea ata
|
||||||
JOIN vn.client c ON c.id = o.customer_id
|
ON ata.addressFk = o.address_id AND ata.companyFk = o.company_id
|
||||||
JOIN vn.supplier p ON p.id = o.company_id
|
JOIN vn.itemTaxCountry itc
|
||||||
JOIN tmp.taxClass g
|
ON itc.itemFk = i.id AND itc.countryFk = s.countryFk
|
||||||
ON g.countryFk = p.countryFk AND g.taxClassFk = a.taxClassFk
|
JOIN vn.bookingPlanner bp
|
||||||
GROUP BY o.id, g.type
|
ON bp.countryFk = s.countryFk
|
||||||
) t
|
AND bp.taxAreaFk = ata.areaFk
|
||||||
JOIN tmp.taxType x
|
AND bp.taxClassFk = itc.taxClassFk
|
||||||
ON x.countryFk = t.countryFk AND x.type = t.type;
|
JOIN vn.pgc ON pgc.code = bp.pgcFk
|
||||||
|
JOIN vn.taxClass tc ON tc.id = bp.taxClassFk
|
||||||
|
GROUP BY tmpOrder.orderFk, pgc.code,pgc.rate
|
||||||
|
HAVING taxableBase != 0;
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE IF EXISTS tmp.orderAmount;
|
||||||
|
CREATE TEMPORARY TABLE tmp.orderAmount
|
||||||
|
(INDEX (orderFk))
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT orderFk, taxableBase, SUM(CAST(taxableBase * rate / 100 AS DECIMAL(10, 2))) tax,code
|
||||||
|
FROM tmp.orderTax
|
||||||
|
GROUP BY orderFk, code;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE
|
|
||||||
tmp.taxClass,
|
|
||||||
tmp.taxType;
|
|
||||||
END$$
|
END$$
|
||||||
|
|
||||||
DELIMITER;
|
DELIMITER ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue