#1711 Eliminar referencias al esquema vn2008
gitea/salix/dev This commit looks good Details

This commit is contained in:
Bernat 2019-11-22 14:34:28 +01:00
parent f50f99b962
commit 5040d1d4a8
10 changed files with 581 additions and 7867 deletions

View File

@ -0,0 +1,132 @@
DROP procedure IF EXISTS `vn`.`clonTravelComplete`;
DELIMITER $$
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`clonTravelComplete`(IN `vTravelFk` INT, IN `vDateStart` DATE, IN `vDateEnd` DATE, IN `vRef` VARCHAR(255))
BEGIN
DECLARE vTravelNew INT;
DECLARE vEntryNew INT;
DECLARE vDone BIT DEFAULT 0;
DECLARE vAuxEntryFk INT;
DECLARE vRsEntry CURSOR FOR
SELECT e.id
FROM entry e
JOIN travel t
ON t.id = e.travelFk
WHERE e.travelFk = vTravelFk;
DECLARE vRsBuy CURSOR FOR
SELECT b.*
FROM buy b
JOIN entry e
ON b.entryFk = e.id
WHERE e.travelFk = vTravelNew and b.entryFk=entryNew
ORDER BY e.id;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = 1;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
RESIGNAL;
END;
START TRANSACTION;
INSERT INTO travel (shipped,landed, warehouseInFk, warehouseOutFk, agencyFk, ref, isDelivered, isReceived, m3, kg)
SELECT vDateStart, vDateEnd,warehouseInFk, warehouseOutFk, agencyFk, vRef, isDelivered, isReceived, m3, kg
FROM travel
WHERE id = vTravelFk;
SET vTravelNew = LAST_INSERT_ID();
SET vDone = 0;
OPEN vRsEntry ;
FETCH vRsEntry INTO vAuxEntryFk;
WHILE NOT vDone DO
INSERT INTO entry (supplierFk,
ref,
isInventory,
isConfirmed,
isOrdered,
isRaid,
commission,
created,
evaNotes,
travelFk,
currencyFk,
companyFk,
gestDocFk,
invoiceInFk)
SELECT supplierFk,
ref,
isInventory,
isConfirmed,
isOrdered,
isRaid,
commission,
created,
evaNotes,
vTravelNew,
currencyFk,
companyFk,
gestDocFk,
invoiceInFk
FROM entry
WHERE id = vAuxEntryFk;
SET vEntryNew = LAST_INSERT_ID();
INSERT INTO buy (entryFk,
itemFk,
quantity,
buyingValue,
packageFk,
stickers,
freightValue,
packageValue,
comissionValue,
packing,
`grouping`,
groupingMode,
location,
price1,
price2,
price3,
minPrice,
producer,
printedStickers,
isChecked)
SELECT vEntryNew,
itemFk,
quantity,
buyingValue,
packageFk,
stickers,
freightValue,
packageValue,
comissionValue,
packing,
`grouping`,
groupingMode,
location,
price1,
price2,
price3,
minPrice,
producer,
printedStickers,
isChecked
FROM buy
WHERE entryFk = vAuxEntryFk;
FETCH vRsEntry INTO vAuxEntryFk;
END WHILE;
CLOSE vRsEntry;
COMMIT;
END$$
DELIMITER ;

View File

@ -0,0 +1,16 @@
DELIMITER $$
DROP TRIGGER IF EXISTS `vn`.`creditClassification_BEFORE_UPDATE` $$
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`creditClassification_beforeUpdate` BEFORE UPDATE ON `creditClassification` FOR EACH ROW
BEGIN
IF NEW.client <> OLD.client THEN
CALL util.throw('NOT_ALLOWED_CHANGE_CLIENT');
END IF;
IF NEW.dateEnd IS NOT NULL AND OLD.dateEnd IS NULL THEN
UPDATE `client` c
SET creditInsurance = 0 WHERE c.id = NEW.client;
END IF;
END$$
DELIMITER ;

View File

@ -0,0 +1,13 @@
DELIMITER $$
DROP TRIGGER IF EXISTS `vn`.`creditInsurance_AFTER_INSERT` $$
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`creditInsurance_afterInsert` AFTER INSERT ON `creditInsurance` FOR EACH ROW
BEGIN
UPDATE `client` c
JOIN vn.creditClassification cc ON cc.client = c.id
SET creditInsurance = NEW.credit WHERE cc.id = NEW.creditClassification;
END$$
DELIMITER ;

View File

@ -0,0 +1,74 @@
DROP procedure IF EXISTS `vn`.`duaInvoiceInBooking`;
DELIMITER $$
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`duaInvoiceInBooking`(vDuaFk INT)
BEGIN
DECLARE done BOOL DEFAULT FALSE;
DECLARE vInvoiceFk INT;
DECLARE vASIEN BIGINT DEFAULT 0;
DECLARE vCounter INT DEFAULT 0;
DECLARE rs CURSOR FOR
SELECT e.invoiceInFk
FROM entry e
JOIN duaEntry de ON de.entryFk = e.id
JOIN invoiceIn ii ON ii.id = e.invoiceInFk
WHERE de.duaFk = vDuaFk
AND de.customsValue
AND ii.isBooked = FALSE;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN rs;
UPDATE invoiceIn ii
JOIN entry e ON e.invoiceInFk = ii.id
JOIN duaEntry de ON de.entryFk = e.id
JOIN dua d ON d.id = de.duaFk
SET ii.isBooked = TRUE,
ii.booked = IFNULL(ii.booked,d.booked),
ii.operated = IFNULL(ii.operated,d.operated),
ii.issued = IFNULL(ii.issued,d.issued),
ii.bookEntried = IFNULL(ii.bookEntried,d.bookEntried),
e.isConfirmed = TRUE
WHERE d.id = vDuaFk;
SELECT IFNULL(ASIEN,0) INTO vASIEN
FROM dua
WHERE id = vDuaFk;
FETCH rs INTO vInvoiceFk;
WHILE NOT done DO
CALL invoiceInBookingMain(vInvoiceFk);
IF vCounter > 0 OR vASIEN > 0 THEN
UPDATE XDiario x
JOIN config c ON c.ASIEN = x.ASIEN
SET x.ASIEN = vASIEN;
ELSE
SELECT ASIEN INTO vASIEN FROM config;
END IF;
SET vCounter = vCounter + 1;
FETCH rs INTO vInvoiceFk;
END WHILE;
CLOSE rs;
UPDATE dua
SET ASIEN = vASIEN
WHERE id = vDuaFk;
END$$
DELIMITER ;

View File

@ -0,0 +1,149 @@
DROP procedure IF EXISTS `vn`.`duaTaxBooking`;
DELIMITER $$
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`duaTaxBooking`(vDuaFk INT)
BEGIN
DECLARE vBookNumber INT;
DECLARE vBookDated DATE;
DECLARE vDiff DECIMAL(10,2);
DECLARE vApunte BIGINT;
SELECT IFNULL(d.ASIEN,MAX(x.ASIEN) + 1 )
INTO vBookNumber
FROM XDiario x
LEFT JOIN dua d ON d.id = vDuaFk ;
SELECT IFNULL(bookEntried, CURDATE()) INTO vBookDated
FROM dua
WHERE id = vDuaFk;
-- Apunte de la aduana
INSERT INTO XDiario(
ASIEN,
FECHA,
SUBCTA,
CONCEPTO,
EUROHABER,
SERIE,
empresa_id,
CLAVE,
FACTURA)
SELECT
vBookNumber,
d.bookEntried,
'4700000999',
CONCAT('DUA ',d.code),
sum(di.amount * tr.rate / 100) EUROHABER,
'R',
d.companyFk,
vDuaFk,
vDuaFk
FROM duaIntrastat di
JOIN intrastat ist ON ist.id = di.intrastatFk
JOIN (SELECT rate, taxClassFk
FROM
(SELECT rate, taxClassFk
FROM invoiceInTaxBookingAccount ta
WHERE ta.effectived <= vBookDated
ORDER BY ta.effectived DESC
) tba
GROUP BY taxClassFk
) tr ON tr.taxClassFk = ist.taxClassFk
JOIN dua d ON d.id = di.duaFk
WHERE di.duaFk = vDuaFk;
-- Apuntes por tipo de IVA y proveedor
INSERT INTO XDiario(
ASIEN,
FECHA,
SUBCTA,
CONTRA,
EURODEBE,
BASEEURO,
CONCEPTO,
FACTURA,
IVA,
AUXILIAR,
SERIE,
FECHA_EX,
FECHA_OP,
FACTURAEX,
NFACTICK,
L340,
LDIFADUAN,
TIPOCLAVE,
TIPOEXENCI,
TIPONOSUJE,
TIPOFACT,
TIPORECTIF,
TERIDNIF,
TERNIF,
TERNOM,
empresa_id,
FECREGCON
)
SELECT
vBookNumber ASIEN,
vBookDated FECHA,
tr.account SUBCTA,
'4330002067' CONTRA,
sum(dt.tax) EURODEBE,
sum(dt.base) BASEEURO,
CONCAT('DUA nº',d.code) CONCEPTO,
d.id FACTURA,
dt.rate IVA,
'*' AUXILIAR,
'D' SERIE,
d.issued FECHA_EX,
d.operated FECHA_OP,
d.code FACTURAEX,
1 NFACTICK,
1 L340,
TRUE LDIFADUAN,
1 TIPOCLAVE,
1 TIPOEXENCI,
1 TIPONOSUJE,
5 TIPOFACT,
1 TIPORECTIF,
IF(s.countryFk IN (30, 1), 1, 4) TERIDNIF,
s.nif TERNIF,
s.name TERNOM,
d.companyFk,
d.booked FECREGCON
FROM duaTax dt
JOIN dua d ON dt.duaFk = d.id
JOIN (SELECT account, rate
FROM
(SELECT rate, account
FROM invoiceInTaxBookingAccount ta
WHERE ta.effectived <= vBookDated
AND taxAreaFk = 'WORLD'
ORDER BY ta.effectived DESC
) tba
GROUP BY rate
) tr ON tr.rate = dt.rate
JOIN supplier s ON s.id = d.companyFk
WHERE d.id = vDuaFk
GROUP BY dt.rate;
SELECT SUM(EURODEBE) -SUM(EUROHABER), MAX(id) INTO vDiff, vApunte
FROM XDiario
WHERE ASIEN = vBookNumber;
UPDATE XDiario
SET BASEEURO = 100 * (EURODEBE - vDiff) / IVA,
EURODEBE = EURODEBE - vDiff
WHERE id = vApunte;
UPDATE dua
SET ASIEN = vBookNumber
WHERE id = vDuaFk;
END$$
DELIMITER ;

View File

@ -3,21 +3,36 @@ DROP procedure IF EXISTS `vn`.`rangeDateInfo`;
DELIMITER $$
CREATE PROCEDURE `vn`.`rangeDateInfo` (vStarted DATE, vEnded DATE)
BEGIN
/*
* Crea una tabla temporal con las fechas
* desde una fecha inicial a una final
* @vStarted: fecha inicial
* @vEnded: fecha final
*/
/**
* Crea una tabla temporal con las fechas
* desde una fecha inicial a una final
* @param vStarted fecha inicial
* @param vEnded fecha final
*/
DECLARE vDated DATE DEFAULT vStarted;
DROP TEMPORARY TABLE IF EXISTS tmp.rangeDate;
CREATE TEMPORARY TABLE tmp.rangeDate(
dated DATE
`dated` DATE,
`period` INT,
`month` INT,
`year` INT,
`day` INT,
`week` INT,
`yearMonth` INT
)
ENGINE = MEMORY;
WHILE vDated <= vEnded DO
INSERT INTO tmp.rangeDate(dated) VALUES(vDated);
INSERT INTO tmp.rangeDate
SET `dated` = vDated,
`period` = YEAR(vDated) * 100 + WEEK(vDated, 1),
`month` = MONTH(vDated),
`year` = YEAR(vDated),
`day` = DAY(vDated),
`week` = WEEK(vDated, 1),
`yearMonth` = YEAR(vDated) * 100 + MONTH(vDated);
SET vDated = DATE_ADD(vDated, INTERVAL 1 DAY);
END WHILE;
END$$

View File

@ -89,6 +89,7 @@ BEGIN
t.type = 'Festivo'
WHERE t.type IS NULL;
DROP TEMPORARY TABLE IF EXISTS tmp.rangeDate;
END$$
DELIMITER ;

View File

@ -36,7 +36,7 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2019-11-22 8:14:41
-- Dump completed on 2019-11-22 14:03:55
USE `account`;
-- MySQL dump 10.13 Distrib 5.7.28, for Linux (x86_64)
--
@ -94,7 +94,7 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2019-11-22 8:14:41
-- Dump completed on 2019-11-22 14:03:55
USE `salix`;
-- MySQL dump 10.13 Distrib 5.7.28, for Linux (x86_64)
--
@ -142,7 +142,7 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2019-11-22 8:14:41
-- Dump completed on 2019-11-22 14:03:55
USE `vn`;
-- MySQL dump 10.13 Distrib 5.7.28, for Linux (x86_64)
--
@ -310,7 +310,7 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2019-11-22 8:14:41
-- Dump completed on 2019-11-22 14:03:55
USE `vn2008`;
-- MySQL dump 10.13 Distrib 5.7.28, for Linux (x86_64)
--
@ -378,7 +378,7 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2019-11-22 8:14:41
-- Dump completed on 2019-11-22 14:03:55
USE `bi`;
-- MySQL dump 10.13 Distrib 5.7.28, for Linux (x86_64)
--
@ -426,7 +426,7 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2019-11-22 8:14:42
-- Dump completed on 2019-11-22 14:03:55
USE `cache`;
-- MySQL dump 10.13 Distrib 5.7.28, for Linux (x86_64)
--
@ -464,7 +464,7 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2019-11-22 8:14:42
-- Dump completed on 2019-11-22 14:03:55
USE `hedera`;
-- MySQL dump 10.13 Distrib 5.7.28, for Linux (x86_64)
--
@ -522,7 +522,7 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2019-11-22 8:14:42
-- Dump completed on 2019-11-22 14:03:55
USE `postgresql`;
-- MySQL dump 10.13 Distrib 5.7.28, for Linux (x86_64)
--
@ -610,4 +610,4 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2019-11-22 8:14:42
-- Dump completed on 2019-11-22 14:03:55

View File

@ -361,7 +361,7 @@ INSERT INTO `vn`.`creditInsurance`(`id`, `creditClassification`, `credit`, `crea
(2, 2, 6000, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), NULL),
(3, 3, 10000, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), NULL);
INSERT INTO `vn2008`.`empresa_grupo`(`empresa_grupo_id`, `grupo`)
INSERT INTO `vn`.`companyGroup`(`id`, `code`)
VALUES
(1, 'Wayne Industries');
@ -1464,7 +1464,7 @@ INSERT INTO `vn`.`receipt`(`id`, `invoiceFk`, `amountPaid`, `amountUnpaid`, `pay
(3, 'Cobro en efectivo', 300.00, 100.00, DATE_ADD(CURDATE(), INTERVAL -10 DAY), 9, 1, 102, DATE_ADD(CURDATE(), INTERVAL -10 DAY), 442, 0),
(4, 'Cobro en efectivo', 400.00, -50.00, DATE_ADD(CURDATE(), INTERVAL -15 DAY), 9, 1, 103, DATE_ADD(CURDATE(), INTERVAL -15 DAY), 442, 0);
INSERT INTO `vn2008`.`workerTeam`(`id`, `team`, `user`)
INSERT INTO `vn`.`workerTeam`(`id`, `team`, `workerFk`)
VALUES
(1, 1, 9),
(2, 1, 18),
@ -1955,5 +1955,4 @@ INSERT INTO `vn`.`userPhone`(`id`, `userFk`, `typeFk`, `phone`)
INSERT INTO `vn`.`workerTimeControlParams` (`id`, `dayBreak`, `weekBreak`, `weekScope`, `dayWorkMax`, `dayStayMax`)
VALUES
(1, 43200, 129600, 734400, 43200, 50400);
(1, 43200, 129600, 734400, 43200, 50400);

File diff suppressed because it is too large Load Diff