update structure db
This commit is contained in:
parent
937ddd7880
commit
2bcd0caa06
|
@ -0,0 +1,81 @@
|
|||
|
||||
DROP procedure IF EXISTS `vn`.`buy_afterUpsert`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`buy_afterUpsert`(vSelf INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Triggered actions when a buy is updated or inserted.
|
||||
*
|
||||
* @param vSelf The buy reference
|
||||
*/
|
||||
DECLARE vEntryFk INT;
|
||||
DECLARE vItemFk INT;
|
||||
DECLARE vStickers INT;
|
||||
DECLARE vPacking INT;
|
||||
DECLARE vWarehouse INT;
|
||||
DECLARE vWarehouseOut INT;
|
||||
DECLARE vIsMerchandise BOOL;
|
||||
DECLARE vIsFeedStock BOOL;
|
||||
DECLARE vLanded DATE;
|
||||
DECLARE vBuyerFk INT;
|
||||
DECLARE vItemName VARCHAR(50);
|
||||
|
||||
SELECT entryFk, itemFk, stickers, packing
|
||||
INTO vEntryFk, vItemFk, vStickers, vPacking
|
||||
FROM buy
|
||||
WHERE id = vSelf;
|
||||
|
||||
SELECT t.warehouseInFk, t.warehouseOutFk, t.landed
|
||||
INTO vWarehouse, vWarehouseOut, vLanded
|
||||
FROM entry e
|
||||
JOIN travel t ON t.id = e.travelFk
|
||||
WHERE e.id = vEntryFk;
|
||||
|
||||
SELECT k.merchandise, it.workerFk, i.longName
|
||||
INTO vIsMerchandise, vBuyerFk, vItemName
|
||||
FROM itemCategory k
|
||||
JOIN itemType it ON it.categoryFk = k.id
|
||||
JOIN item i ON i.typeFk = it.id
|
||||
WHERE i.id = vItemFk;
|
||||
|
||||
IF vIsMerchandise THEN
|
||||
REPLACE itemCost SET
|
||||
itemFk = vItemFk,
|
||||
warehouseFk = vWarehouse,
|
||||
cm3 = buy_getUnitVolume(vSelf);
|
||||
END IF;
|
||||
|
||||
SELECT isFeedStock INTO vIsFeedStock
|
||||
FROM warehouse WHERE id = vWarehouseOut AND id <> 13;
|
||||
|
||||
IF vIsFeedStock THEN
|
||||
INSERT IGNORE INTO producer(`name`)
|
||||
SELECT es.company_name
|
||||
FROM buy b
|
||||
JOIN edi.ekt be ON be.id = b.ektFk
|
||||
JOIN edi.supplier es ON es.supplier_id = be.pro
|
||||
WHERE b.id = vSelf;
|
||||
|
||||
IF buy_hasNotifyPassport(vSelf, vItemFk) THEN
|
||||
CALL vn.buy_notifyPassport(vSelf, vItemFk, vStickers, vPacking);
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
-- Aviso al comprador de modificacion de entrada en Barajas
|
||||
IF (SELECT isBuyerToBeEmailed FROM warehouse WHERE id = vWarehouse)
|
||||
AND vLanded = CURDATE()
|
||||
AND vBuyerFk != account.myUserGetId()
|
||||
THEN
|
||||
|
||||
CALL vn.mail_insert(CONCAT(account.userGetNameFromId(vBuyerFk),'@verdnatura.es'),
|
||||
CONCAT(account.myUserGetName(),'@verdnatura.es'),
|
||||
CONCAT('E ',vEntryFk,' Se ha modificado item ', vItemFk, ' ',vItemName),
|
||||
'Este email se ha generado automáticamente');
|
||||
|
||||
END IF;
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,16 +1,3 @@
|
|||
ALTER TABLE `vn`.`componentType`
|
||||
CHANGE COLUMN `isBase` `base` TINYINT(4) NOT NULL DEFAULT '0' COMMENT 'Marca aquellas series que se utilizan para calcular el precio base de las ventas, a efectos estadisticos' ;
|
||||
CHANGE COLUMN `base` `isBase` TINYINT(4) NOT NULL DEFAULT '0' COMMENT 'Marca aquellas series que se utilizan para calcular el precio base de las ventas, a efectos estadisticos' ;
|
||||
|
||||
|
||||
CREATE
|
||||
OR REPLACE ALGORITHM = UNDEFINED
|
||||
DEFINER = `root`@`%`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `bi`.`tarifa_componentes_series` AS
|
||||
SELECT
|
||||
`ct`.`id` AS `tarifa_componentes_series_id`,
|
||||
`ct`.`type` AS `Serie`,
|
||||
`ct`.`base` AS `base`,
|
||||
`ct`.`isMargin` AS `margen`
|
||||
FROM
|
||||
`vn`.`componentType` `ct`;
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
|
||||
|
||||
DROP procedure IF EXISTS `vn`.`ticketComponentUpdateSale`;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`ticketComponentUpdateSale`(vOption INT)
|
||||
BEGIN
|
||||
/**
|
||||
* A partir de la tabla tmp.sale, crea los Movimientos_componentes
|
||||
* y modifica el campo Preu de la tabla Movimientos
|
||||
*
|
||||
* @param i_option integer tipo de actualizacion
|
||||
* @param table tmp.sale tabla memory con el campo saleFk, warehouseFk
|
||||
**/
|
||||
DECLARE vComponentFk INT;
|
||||
DECLARE vRenewComponents BOOLEAN;
|
||||
DECLARE vKeepPrices BOOLEAN;
|
||||
|
||||
CASE vOption
|
||||
WHEN 1 THEN
|
||||
SET vRenewComponents = TRUE;
|
||||
SET vKeepPrices = FALSE;
|
||||
WHEN 2 THEN
|
||||
SET vComponentFk = 17;
|
||||
SET vRenewComponents = TRUE;
|
||||
SET vKeepPrices = TRUE;
|
||||
WHEN 3 THEN
|
||||
SET vComponentFk = 37;
|
||||
SET vRenewComponents = TRUE;
|
||||
SET vKeepPrices = TRUE;
|
||||
WHEN 4 THEN
|
||||
SET vComponentFk = 34;
|
||||
SET vRenewComponents = TRUE;
|
||||
SET vKeepPrices = TRUE;
|
||||
WHEN 5 THEN
|
||||
SET vComponentFk = 35;
|
||||
SET vRenewComponents = TRUE;
|
||||
SET vKeepPrices = TRUE;
|
||||
WHEN 6 THEN
|
||||
SET vComponentFk = 36;
|
||||
SET vRenewComponents = TRUE;
|
||||
SET vKeepPrices = TRUE;
|
||||
WHEN 7 THEN
|
||||
REPLACE INTO saleComponent(saleFk, componentFk, value)
|
||||
SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.8, 3)
|
||||
FROM sale s
|
||||
JOIN tmp.sale tmps ON tmps.saleFk = s.id
|
||||
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
||||
AND sc.componentFk NOT IN (28, 29)
|
||||
GROUP BY s.id;
|
||||
|
||||
REPLACE INTO saleComponent(saleFk, componentFk, value)
|
||||
SELECT s.id, 29, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.2, 3)
|
||||
FROM sale s
|
||||
JOIN tmp.sale tmps ON tmps.saleFk = s.id
|
||||
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
||||
AND sc.componentFk NOT IN (28, 29)
|
||||
GROUP BY s.id;
|
||||
|
||||
SET vRenewComponents = FALSE;
|
||||
SET vKeepPrices = FALSE;
|
||||
WHEN 8 THEN
|
||||
DELETE sc.*
|
||||
FROM tmp.sale tmps JOIN saleComponent sc ON sc.saleFk = tmps.saleFk;
|
||||
|
||||
REPLACE INTO saleComponent(saleFk, componentFk, value)
|
||||
SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100)), 3)
|
||||
FROM sale s
|
||||
JOIN tmp.sale tmps ON tmps.saleFk = s.id;
|
||||
|
||||
SET vRenewComponents = FALSE;
|
||||
SET vKeepPrices = FALSE;
|
||||
WHEN 9 THEN
|
||||
SET vRenewComponents = TRUE;
|
||||
SET vKeepPrices = TRUE;
|
||||
END CASE;
|
||||
|
||||
IF vRenewComponents THEN
|
||||
DELETE sc.*
|
||||
FROM tmp.sale tmps
|
||||
JOIN saleComponent sc ON sc.saleFk = tmps.saleFk
|
||||
JOIN `component` c ON c.id = sc.componentFk
|
||||
WHERE c.isRenewable;
|
||||
|
||||
REPLACE INTO saleComponent(saleFk, componentFk, value)
|
||||
SELECT s.id, tc.componentFk, tc.cost
|
||||
FROM sale s
|
||||
JOIN tmp.sale tmps ON tmps.saleFk = s.id
|
||||
JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk
|
||||
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
||||
AND sc.componentFk = tc.componentFk
|
||||
LEFT JOIN `component` c ON c.id = tc.componentFk
|
||||
WHERE IF(sc.componentFk IS NULL AND NOT c.isRenewable, FALSE, TRUE);
|
||||
END IF;
|
||||
|
||||
IF vKeepPrices THEN
|
||||
REPLACE INTO saleComponent(saleFk, componentFk, value)
|
||||
SELECT s.id, vComponentFk, ROUND((s.price * (100 - s.discount) / 100) - SUM(sc.value), 3) dif
|
||||
FROM sale s
|
||||
JOIN tmp.sale tmps ON tmps.saleFk = s.id
|
||||
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
||||
WHERE sc.saleFk <> vComponentFk
|
||||
GROUP BY s.id
|
||||
HAVING dif <> 0;
|
||||
ELSE
|
||||
UPDATE sale s
|
||||
JOIN item i on i.id = s.itemFk
|
||||
JOIN itemType it on it.id = i.typeFk
|
||||
JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk
|
||||
FROM saleComponent sc
|
||||
JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk
|
||||
GROUP BY sc.saleFk) sc ON sc.saleFk = s.id
|
||||
SET s.price = sumValue
|
||||
WHERE it.code != 'PRT' ;
|
||||
|
||||
REPLACE INTO saleComponent(saleFk, componentFk, value)
|
||||
SELECT s.id, 21, ROUND((s.price * (100 - s.discount) / 100) - SUM(value), 3) saleValue
|
||||
FROM sale s
|
||||
JOIN tmp.sale tmps ON tmps.saleFk = s.id
|
||||
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
||||
WHERE sc.componentFk != 21
|
||||
GROUP BY s.id
|
||||
HAVING ROUND(saleValue, 4) <> 0;
|
||||
END IF;
|
||||
|
||||
UPDATE sale s
|
||||
JOIN (
|
||||
SELECT SUM(sc.value) sumValue, sc.saleFk
|
||||
FROM saleComponent sc
|
||||
JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk
|
||||
JOIN `component` c ON c.id = sc.componentFk
|
||||
JOIN componentType ct on ct.id = c.typeFk AND ct.isBase
|
||||
GROUP BY sc.saleFk) sc ON sc.saleFk = s.id
|
||||
SET s.priceFixed = sumValue, s.isPriceFixed = 1;
|
||||
|
||||
DELETE sc.*
|
||||
FROM saleComponent sc
|
||||
JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk
|
||||
JOIN sale s on s.id = sc.saleFk
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
WHERE it.code = 'PRT';
|
||||
|
||||
INSERT INTO saleComponent(saleFk, componentFk, value)
|
||||
SELECT s.id, 15, s.price
|
||||
FROM sale s
|
||||
JOIN tmp.sale tmps ON tmps.saleFk = s.id
|
||||
JOIN item i ON i.id = s.itemFK
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
WHERE it.code = 'PRT' AND s.price > 0;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -5,3 +5,23 @@ CREATE DEFINER=`root`@`%` TRIGGER `vn`.`invoiceOut_afterInsert` AFTER INSERT ON
|
|||
CALL clientRisk_update(NEW.clientFk, NEW.companyFk, NEW.amount);
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
DROP TRIGGER IF EXISTS `vn`.`invoiceOut_beforeUpdate`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`invoiceOut_beforeUpdate` BEFORE UPDATE ON `vn`.`invoiceOut` FOR EACH ROW
|
||||
BEGIN
|
||||
CALL clientRisk_update (OLD.clientFk, OLD.companyFk, -OLD.amount);
|
||||
CALL clientRisk_update (NEW.clientFk, NEW.companyFk, NEW.amount);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
||||
|
||||
DROP TRIGGER IF EXISTS `vn`.`invoiceOut_beforeDelete`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`invoiceOut_beforeDelete` BEFORE DELETE ON `invoiceOut` FOR EACH ROW BEGIN
|
||||
CALL clientRisk_update (OLD.clientFk, OLD.companyFk, -OLD.amount);
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
DROP TRIGGER IF EXISTS `vn`.`receipt_afterInsert`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`receipt_afterInsert` AFTER INSERT ON `receipt` FOR EACH ROW
|
||||
CALL clientRisk_update(NEW.clientFk, NEW.companyFk, -NEW.amountPaid)$$
|
||||
DELIMITER ;
|
||||
DROP TRIGGER IF EXISTS `vn`.`receipt_beforeUpdate`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`receipt_beforeUpdate` BEFORE UPDATE ON `receipt` FOR EACH ROW BEGIN
|
||||
CALL clientRisk_update(OLD.clientFk, OLD.companyFk, OLD.amountPaid);
|
||||
CALL clientRisk_update(NEW.clientFk, NEW.companyFk, -NEW.amountPaid);
|
||||
END$$
|
||||
DELIMITER ;
|
||||
DROP TRIGGER IF EXISTS `vn`.`receipt_beforeDelete`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`receipt_beforeDelete` BEFORE DELETE ON `receipt` FOR EACH ROW
|
||||
CALL clientRisk_update(OLD.clientFk, OLD.companyFk, OLD.amountPaid)$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,12 @@
|
|||
CREATE
|
||||
OR REPLACE ALGORITHM = UNDEFINED
|
||||
DEFINER = `root`@`%`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `bi`.`tarifa_componentes_series` AS
|
||||
SELECT
|
||||
`ct`.`id` AS `tarifa_componentes_series_id`,
|
||||
`ct`.`type` AS `Serie`,
|
||||
`ct`.`isBase` AS `base`,
|
||||
`ct`.`isMargin` AS `margen`
|
||||
FROM
|
||||
`vn`.`componentType` `ct`;
|
|
@ -36,7 +36,7 @@ UNLOCK TABLES;
|
|||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
-- Dump completed on 2020-01-23 11:37:31
|
||||
-- Dump completed on 2020-01-23 14:05:01
|
||||
USE `account`;
|
||||
-- MySQL dump 10.13 Distrib 5.7.28, for osx10.15 (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 2020-01-23 11:37:32
|
||||
-- Dump completed on 2020-01-23 14:05:01
|
||||
USE `salix`;
|
||||
-- MySQL dump 10.13 Distrib 5.7.28, for osx10.15 (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 2020-01-23 11:37:32
|
||||
-- Dump completed on 2020-01-23 14:05:01
|
||||
USE `vn`;
|
||||
-- MySQL dump 10.13 Distrib 5.7.28, for osx10.15 (x86_64)
|
||||
--
|
||||
|
@ -340,7 +340,7 @@ UNLOCK TABLES;
|
|||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
-- Dump completed on 2020-01-23 11:37:32
|
||||
-- Dump completed on 2020-01-23 14:05:01
|
||||
USE `cache`;
|
||||
-- MySQL dump 10.13 Distrib 5.7.28, for osx10.15 (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 2020-01-23 11:37:32
|
||||
-- Dump completed on 2020-01-23 14:05:01
|
||||
USE `hedera`;
|
||||
-- MySQL dump 10.13 Distrib 5.7.28, for osx10.15 (x86_64)
|
||||
--
|
||||
|
@ -436,7 +436,7 @@ UNLOCK TABLES;
|
|||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
-- Dump completed on 2020-01-23 11:37:32
|
||||
-- Dump completed on 2020-01-23 14:05:01
|
||||
USE `postgresql`;
|
||||
-- MySQL dump 10.13 Distrib 5.7.28, for osx10.15 (x86_64)
|
||||
--
|
||||
|
@ -524,4 +524,4 @@ UNLOCK TABLES;
|
|||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
-- Dump completed on 2020-01-23 11:37:32
|
||||
-- Dump completed on 2020-01-23 14:05:01
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue