Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 6276-createNewWarehouse
This commit is contained in:
commit
9b5823384a
|
@ -1750,8 +1750,6 @@ USE `vn`;
|
|||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
||||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
||||
|
||||
INSERT INTO `agencyTermConfig` VALUES ('6240000000','4721000015',21.0000000000,'Adquisiciones intracomunitarias de servicios');
|
||||
|
||||
INSERT INTO `alertLevel` VALUES ('FREE',0,1);
|
||||
INSERT INTO `alertLevel` VALUES ('ON_PREPARATION',1,1);
|
||||
INSERT INTO `alertLevel` VALUES ('PACKED',2,0);
|
||||
|
|
|
@ -653,6 +653,7 @@ INSERT INTO `vn`.`expense`(`id`, `name`, `isWithheld`)
|
|||
(7001000000, 'Mercaderia', 0),
|
||||
(7050000000, 'Prestacion de servicios', 1);
|
||||
|
||||
INSERT INTO `vn`.`agencyTermConfig` VALUES ('6240000000','4721000015',21.0000000000,'Adquisiciones intracomunitarias de servicios');
|
||||
|
||||
INSERT INTO `vn`.`invoiceOutExpense`(`id`, `invoiceOutFk`, `amount`, `expenseFk`, `created`)
|
||||
VALUES
|
||||
|
|
|
@ -47,12 +47,12 @@ BEGIN
|
|||
, tp.reino_id
|
||||
, a.tipo_id
|
||||
, t.empresa_id
|
||||
, 7000000000
|
||||
, a.expenseFk
|
||||
+ IF(e.empresa_grupo = e2.empresa_grupo
|
||||
,1
|
||||
,IF(e2.empresa_grupo,2,0)
|
||||
) * 1000000
|
||||
+ tp.reino_id * 10000 as Gasto
|
||||
) * 100000
|
||||
+ tp.reino_id * 1000 as Gasto
|
||||
FROM vn2008.Movimientos m
|
||||
JOIN vn2008.Tickets t on t.Id_Ticket = m.Id_Ticket
|
||||
JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna
|
||||
|
|
|
@ -9,6 +9,8 @@ BEGIN
|
|||
* @return tmp.ticketAmount (ticketFk, taxableBase, tax, code)
|
||||
* @return tmp.ticketTax (ticketFk, pgcFk, taxableBase, rate, code) Impuesto desglosado para cada ticket.
|
||||
*/
|
||||
-- Mantengo el drop porque si no da error en los tests de back de salix
|
||||
-- Table 'addressCompany' was locked with a READ lock and can't be updated'
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany;
|
||||
CREATE TEMPORARY TABLE tmp.addressCompany
|
||||
(INDEX (addressFk, companyFk))
|
||||
|
@ -17,24 +19,24 @@ BEGIN
|
|||
FROM tmp.ticket tmpTicket
|
||||
JOIN ticket t ON t.id = tmpTicket.ticketFk;
|
||||
|
||||
CALL addressTaxArea ();
|
||||
CALL addressTaxArea();
|
||||
|
||||
IF vTaxArea IS NOT NULL THEN
|
||||
UPDATE tmp.addressTaxArea
|
||||
SET areaFk = vTaxArea;
|
||||
END IF;
|
||||
|
||||
/* Solo se calcula la base imponible (taxableBase) y el impuesto se calculará posteriormente
|
||||
* No se debería cambiar el sistema por problemas con los decimales
|
||||
*/
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketTax;
|
||||
CREATE TEMPORARY TABLE tmp.ticketTax
|
||||
-- Solo se calcula la base imponible (taxableBase) y
|
||||
-- el impuesto se calculará posteriormente
|
||||
-- No se debería cambiar el sistema por problemas con los decimales
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketTax
|
||||
(PRIMARY KEY (ticketFk, code, rate))
|
||||
ENGINE = MEMORY
|
||||
SELECT * FROM (
|
||||
SELECT tmpTicket.ticketFk,
|
||||
bp.pgcFk,
|
||||
SUM(s.quantity * s.price * (100 - s.discount)/100 ) taxableBase,
|
||||
SUM(s.quantity * s.price * (100 - s.discount) / 100 ) taxableBase,
|
||||
pgc.rate,
|
||||
tc.code,
|
||||
bp.priority
|
||||
|
@ -43,22 +45,21 @@ BEGIN
|
|||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN ticket t ON t.id = tmpTicket.ticketFk
|
||||
JOIN supplier su ON su.id = t.companyFk
|
||||
JOIN tmp.addressTaxArea ata
|
||||
ON ata.addressFk = t.addressFk AND ata.companyFk = t.companyFk
|
||||
JOIN itemTaxCountry itc
|
||||
ON itc.itemFk = i.id AND itc.countryFk = su.countryFk
|
||||
JOIN bookingPlanner bp
|
||||
ON bp.countryFk = su.countryFk
|
||||
AND bp.taxAreaFk = ata.areaFk
|
||||
AND bp.taxClassFk = itc.taxClassFk
|
||||
JOIN tmp.addressTaxArea ata ON ata.addressFk = t.addressFk
|
||||
AND ata.companyFk = t.companyFk
|
||||
JOIN itemTaxCountry itc ON itc.itemFk = i.id
|
||||
AND itc.countryFk = su.countryFk
|
||||
JOIN bookingPlanner bp ON bp.countryFk = su.countryFk
|
||||
AND bp.taxAreaFk = ata.areaFk
|
||||
AND bp.taxClassFk = itc.taxClassFk
|
||||
JOIN pgc ON pgc.code = bp.pgcFk
|
||||
JOIN taxClass tc ON tc.id = bp.taxClassFk
|
||||
GROUP BY tmpTicket.ticketFk, pgc.code, pgc.rate
|
||||
HAVING taxableBase <> 0) t3
|
||||
HAVING taxableBase
|
||||
) t3
|
||||
ORDER BY priority;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketServiceTax;
|
||||
CREATE TEMPORARY TABLE tmp.ticketServiceTax
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketServiceTax
|
||||
(PRIMARY KEY (ticketFk, code, rate))
|
||||
ENGINE = MEMORY
|
||||
SELECT tt.ticketFk,
|
||||
|
@ -70,24 +71,22 @@ BEGIN
|
|||
JOIN ticketService ts ON ts.ticketFk = tt.ticketFk
|
||||
JOIN ticket t ON t.id = tt.ticketFk
|
||||
JOIN supplier su ON su.id = t.companyFk
|
||||
JOIN tmp.addressTaxArea ata
|
||||
ON ata.addressFk = t.addressFk AND ata.companyFk = t.companyFk
|
||||
JOIN bookingPlanner bp
|
||||
ON bp.countryFk = su.countryFk
|
||||
AND bp.taxAreaFk = ata.areaFk
|
||||
AND bp.taxClassFk = ts.taxClassFk
|
||||
JOIN tmp.addressTaxArea ata ON ata.addressFk = t.addressFk
|
||||
AND ata.companyFk = t.companyFk
|
||||
JOIN bookingPlanner bp ON bp.countryFk = su.countryFk
|
||||
AND bp.taxAreaFk = ata.areaFk
|
||||
AND bp.taxClassFk = ts.taxClassFk
|
||||
JOIN pgc ON pgc.code = bp.pgcFk
|
||||
JOIN taxClass tc ON tc.id = bp.taxClassFk
|
||||
GROUP BY tt.ticketFk, pgc.code
|
||||
HAVING taxableBase <> 0;
|
||||
HAVING taxableBase;
|
||||
|
||||
INSERT INTO tmp.ticketTax (ticketFk, pgcFk, taxableBase, rate, code)
|
||||
SELECT ts.ticketFk, ts.pgcFk, ts.taxableBase, ts.rate, ts.code
|
||||
FROM tmp.ticketServiceTax ts
|
||||
ON DUPLICATE KEY UPDATE ticketTax.taxableBase = VALUES (taxableBase) + ticketTax.taxableBase ;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketAmount;
|
||||
CREATE TEMPORARY TABLE tmp.ticketAmount
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketAmount
|
||||
(INDEX (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT ticketFk,
|
||||
|
@ -97,7 +96,8 @@ BEGIN
|
|||
FROM tmp.ticketTax
|
||||
GROUP BY ticketFk, code;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.addressCompany;
|
||||
DROP TEMPORARY TABLE tmp.addressTaxArea;
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.addressCompany,
|
||||
tmp.addressTaxArea;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
USE vn;
|
||||
ALTER TABLE vn.agencyTermConfig
|
||||
ADD CONSTRAINT agencyTermConfig_expense_FK FOREIGN KEY (expenseFk) REFERENCES vn.expense(id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
@ -0,0 +1,11 @@
|
|||
USE vn;
|
||||
|
||||
ALTER TABLE vn2008.gastos_resumen MODIFY COLUMN Id_Gasto varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL;
|
||||
|
||||
DELETE gr.*
|
||||
FROM vn2008.gastos_resumen gr LEFT JOIN vn.expense e ON gr.Id_Gasto = e.id
|
||||
WHERE e.id IS NULL;
|
||||
|
||||
ALTER TABLE vn2008.gastos_resumen
|
||||
ADD CONSTRAINT gastos_resumen_expense_FK
|
||||
FOREIGN KEY (Id_Gasto) REFERENCES vn.expense(id) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@ -0,0 +1,5 @@
|
|||
USE vn;
|
||||
ALTER TABLE vn.invoiceOutTaxConfig MODIFY COLUMN expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL NULL;
|
||||
|
||||
ALTER TABLE vn.invoiceOutTaxConfig
|
||||
ADD CONSTRAINT invoiceOutTaxConfig_expense_FK FOREIGN KEY (expenseFk) REFERENCES vn.expense(id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
@ -0,0 +1,5 @@
|
|||
USE edi;
|
||||
ALTER TABLE edi.item_groupToOffer MODIFY COLUMN expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT '7001000000' NULL;
|
||||
|
||||
ALTER TABLE edi.item_groupToOffer
|
||||
ADD CONSTRAINT item_groupToOffer_expense_FK FOREIGN KEY (expenseFk) REFERENCES vn.expense(id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
@ -0,0 +1,14 @@
|
|||
USE vn;
|
||||
-- Eliminar la clave primaria actual
|
||||
ALTER TABLE bs.ventas_contables DROP PRIMARY KEY;
|
||||
|
||||
-- Agregar la nueva clave primaria incluyendo el campo `gasto`
|
||||
ALTER TABLE bs.ventas_contables ADD PRIMARY KEY (`year`, `month`, `grupo`, `reino_id`, `tipo_id`, `empresa_id`, `gasto`);
|
||||
|
||||
DELETE vc.* FROM bs.ventas_contables vc LEFT JOIN vn.expense e ON e.id = vc.gasto WHERE e.id IS NULL;
|
||||
|
||||
ALTER TABLE bs.ventas_contables
|
||||
MODIFY COLUMN gasto VARCHAR(10)
|
||||
CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL;
|
||||
|
||||
ALTER TABLE bs.ventas_contables ADD CONSTRAINT ventas_contables_expense_FK FOREIGN KEY (gasto) REFERENCES vn.expense(id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
@ -0,0 +1,8 @@
|
|||
DELETE FROM vn.expense
|
||||
WHERE id ='' AND id IS NULL AND isWithheld = FALSE;
|
||||
UPDATE vn.expense
|
||||
SET id='7002090000'
|
||||
WHERE id='7002009000';
|
||||
UPDATE vn.expense
|
||||
SET id='7001090000'
|
||||
WHERE id='7001009000';
|
|
@ -0,0 +1,44 @@
|
|||
UPDATE vn.expense
|
||||
SET id = CASE id
|
||||
WHEN 7000010000 THEN 7001001000
|
||||
WHEN 7000020000 THEN 7001002000
|
||||
WHEN 7000030000 THEN 7001003000
|
||||
WHEN 7000040000 THEN 7001004000
|
||||
WHEN 7000050000 THEN 7001005000
|
||||
WHEN 7000060000 THEN 7001006000
|
||||
WHEN 7000070000 THEN 7001007000
|
||||
WHEN 7002060000 THEN 7001206000
|
||||
WHEN 7002070000 THEN 7001207000
|
||||
WHEN 7002030000 THEN 7001203000
|
||||
WHEN 7002040000 THEN 7001204000
|
||||
WHEN 7002050000 THEN 7001205000
|
||||
WHEN 7002020000 THEN 7001202000
|
||||
WHEN 7002010000 THEN 7001201000
|
||||
WHEN 7001060000 THEN 7001106000
|
||||
WHEN 7001070000 THEN 7001107000
|
||||
WHEN 7001030000 THEN 7001103000
|
||||
WHEN 7001040000 THEN 7001104000
|
||||
WHEN 7001050000 THEN 7001105000
|
||||
WHEN 7001020000 THEN 7001102000
|
||||
WHEN 7001010000 THEN 7001101000
|
||||
WHEN 7000080000 THEN 7040008000
|
||||
WHEN 7001080000 THEN 7000108000
|
||||
WHEN 7002080000 THEN 7001208000
|
||||
WHEN 7000090000 THEN 7001009000
|
||||
WHEN 7002090000 THEN 7001209000
|
||||
WHEN 7002100000 THEN 7001210000
|
||||
WHEN 7001090000 THEN 7001109000
|
||||
WHEN 7001100000 THEN 7001110000
|
||||
WHEN 7000120000 THEN 7001012000
|
||||
WHEN 7002120000 THEN 7001212000
|
||||
WHEN 7000130000 THEN 7001013000
|
||||
WHEN 7000140000 THEN 7001014000
|
||||
ELSE id
|
||||
END
|
||||
WHERE id IN (7000010000, 7000020000, 7000030000, 7000040000, 7000050000,
|
||||
7000060000, 7000070000, 7002060000, 7002070000, 7002030000,
|
||||
7002040000, 7002050000, 7002020000, 7002010000, 7001060000,
|
||||
7001070000, 7001030000, 7001040000, 7001050000, 7001020000,
|
||||
7001010000, 7000080000, 7001080000, 7002080000, 7000090000,
|
||||
7002090000, 7002100000, 7001090000, 7001100000,
|
||||
7000120000, 7002120000, 7000130000, 7000140000);
|
|
@ -0,0 +1,6 @@
|
|||
UPDATE vn.expense
|
||||
SET id = CASE id
|
||||
WHEN 7000100000 THEN 7001010000
|
||||
ELSE id
|
||||
END
|
||||
WHERE id IN (7000100000);
|
|
@ -46,23 +46,19 @@ module.exports = Self => {
|
|||
|
||||
const stmts = [];
|
||||
let stmt;
|
||||
stmts.push(`DROP TEMPORARY TABLE IF EXISTS tmp.ticket`);
|
||||
|
||||
stmts.push(new ParameterizedSQL(
|
||||
`CREATE TEMPORARY TABLE tmp.ticket
|
||||
`CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
(KEY (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT id ticketFk
|
||||
FROM ticket t
|
||||
WHERE shipped BETWEEN ? AND ?
|
||||
WHERE shipped BETWEEN ? AND util.dayEnd(?)
|
||||
AND refFk IS NULL`, [args.from, args.to]));
|
||||
stmts.push(`CALL vn.ticket_getTax(NULL)`);
|
||||
stmts.push(`DROP TEMPORARY TABLE IF EXISTS tmp.filter`);
|
||||
stmts.push(new ParameterizedSQL(
|
||||
`CREATE TEMPORARY TABLE tmp.filter
|
||||
`CREATE OR REPLACE TEMPORARY TABLE tmp.filter
|
||||
ENGINE = MEMORY
|
||||
SELECT
|
||||
co.code company,
|
||||
SELECT co.code company,
|
||||
cou.country,
|
||||
c.id clientId,
|
||||
c.socialName clientSocialName,
|
||||
|
@ -75,28 +71,26 @@ module.exports = Self => {
|
|||
c.isTaxDataChecked,
|
||||
w.id comercialId,
|
||||
CONCAT(w.firstName, ' ', w.lastName) comercialName
|
||||
FROM vn.ticket t
|
||||
JOIN vn.company co ON co.id = t.companyFk
|
||||
JOIN vn.sale s ON s.ticketFk = t.id
|
||||
JOIN vn.client c ON c.id = t.clientFk
|
||||
JOIN vn.country cou ON cou.id = c.countryFk
|
||||
LEFT JOIN vn.worker w ON w.id = c.salesPersonFk
|
||||
JOIN account.user u ON u.id = w.id
|
||||
LEFT JOIN (
|
||||
SELECT ticketFk, taxableBase
|
||||
FROM tmp.ticketAmount
|
||||
GROUP BY ticketFk
|
||||
HAVING taxableBase < 0
|
||||
) negativeBase ON negativeBase.ticketFk = t.id
|
||||
WHERE t.shipped BETWEEN ? AND ?
|
||||
AND t.refFk IS NULL
|
||||
AND c.typeFk IN ('normal','trust')
|
||||
GROUP BY t.clientFk, negativeBase.taxableBase
|
||||
HAVING amount < 0`, [args.from, args.to]));
|
||||
FROM vn.ticket t
|
||||
JOIN vn.company co ON co.id = t.companyFk
|
||||
JOIN vn.sale s ON s.ticketFk = t.id
|
||||
JOIN vn.client c ON c.id = t.clientFk
|
||||
JOIN vn.country cou ON cou.id = c.countryFk
|
||||
LEFT JOIN vn.worker w ON w.id = c.salesPersonFk
|
||||
JOIN account.user u ON u.id = w.id
|
||||
LEFT JOIN (
|
||||
SELECT ticketFk, taxableBase
|
||||
FROM tmp.ticketAmount
|
||||
GROUP BY ticketFk
|
||||
HAVING taxableBase < 0
|
||||
) negativeBase ON negativeBase.ticketFk = t.id
|
||||
WHERE t.shipped BETWEEN ? AND util.dayEnd(?)
|
||||
AND t.refFk IS NULL
|
||||
AND c.typeFk IN ('normal','trust')
|
||||
GROUP BY t.clientFk, negativeBase.taxableBase
|
||||
HAVING amount < 0`, [args.from, args.to]));
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
SELECT f.*
|
||||
FROM tmp.filter f`);
|
||||
stmt = new ParameterizedSQL(`SELECT * FROM tmp.filter`);
|
||||
|
||||
if (args.filter) {
|
||||
stmt.merge(conn.makeWhere(args.filter.where));
|
||||
|
|
|
@ -44,7 +44,6 @@ fixtures:
|
|||
- module
|
||||
- defaultViewConfig
|
||||
vn:
|
||||
- agencyTermConfig
|
||||
- alertLevel
|
||||
- bookingPlanner
|
||||
- businessType
|
||||
|
|
Loading…
Reference in New Issue