update structure db
This commit is contained in:
parent
03c6aef542
commit
6b64b2b419
|
@ -0,0 +1,4 @@
|
|||
CREATE TABLE `vn`.`localLog` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`ticketFk` VARCHAR(45) NULL,
|
||||
PRIMARY KEY (`id`));
|
|
@ -0,0 +1,21 @@
|
|||
DROP TRIGGER IF EXISTS `vn2008`.`TicketsAfterUpdate`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn2008`$$
|
||||
CREATE DEFINER=`root`@`%` TRIGGER `vn2008`.`TicketsAfterUpdate`
|
||||
AFTER UPDATE ON `Tickets` FOR EACH ROW
|
||||
BEGIN
|
||||
IF NEW.Id_Ruta IS NULL AND OLD.Id_Ruta IS NOT NULL THEN
|
||||
INSERT INTO vn.routeLog(originFk, userFk, `action`, description)
|
||||
VALUES (OLD.Id_Ruta, account.userGetId(), 'update', CONCAT('Saca el ticket ', OLD.Id_Ticket, ' de la ruta'));
|
||||
ELSEIF NOT (NEW.Id_Ruta <=> OLD.Id_Ruta) THEN
|
||||
INSERT INTO vn.routeLog(originFk, userFk, `action`, description)
|
||||
VALUES (NEW.Id_Ruta, account.userGetId(), 'update', CONCAT('Añade el ticket ', OLD.Id_Ticket, ' a la ruta'));
|
||||
END IF;
|
||||
|
||||
CALL stock.queueAdd ('ticket', NEW.Id_Ticket, OLD.Id_Ticket);
|
||||
|
||||
INSERT INTO vn.localLog(ticketFk)
|
||||
VALUES(NEW.Id_Ticket);
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -4,10 +4,10 @@ DROP procedure IF EXISTS `orderAddItem`;
|
|||
DELIMITER $$
|
||||
USE `hedera`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `orderAddItem`(
|
||||
vWarehouse INT,
|
||||
vOrder INT,
|
||||
vWarehouse INT,
|
||||
vItem INT,
|
||||
vAmount INT,
|
||||
vOrder INT)
|
||||
vAmount INT)
|
||||
BEGIN
|
||||
DECLARE vRow INT;
|
||||
DECLARE vAdd INT;
|
||||
|
@ -17,27 +17,34 @@ BEGIN
|
|||
DECLARE vRate INT;
|
||||
DECLARE vShipment DATE;
|
||||
DECLARE vPrice DECIMAL(10,2);
|
||||
|
||||
DECLARE vDate DATE;
|
||||
DECLARE vAddress INT;
|
||||
DECLARE vAgencyMode INT;
|
||||
DECLARE cur CURSOR FOR
|
||||
SELECT grouping, price, rate
|
||||
FROM tmp.bionic_price
|
||||
WHERE warehouse_id = vWarehouse
|
||||
AND item_id = vItem
|
||||
ORDER BY grouping DESC;
|
||||
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND
|
||||
SET vDone = TRUE;
|
||||
|
||||
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
ROLLBACK;
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
CALL bionic_from_item (vItem);
|
||||
SELECT date_send, address_id, agency_id
|
||||
INTO vDate, vAddress, vAgencyMode
|
||||
FROM `order`
|
||||
WHERE id = vOrder;
|
||||
|
||||
CALL vn2008.bionic_from_item(vDate, vAddress, vAgencyMode, vItem);
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
|
||||
SELECT shipped INTO vShipment
|
||||
FROM tmp.travel_tree
|
||||
WHERE warehouseFk = vWarehouse;
|
||||
|
|
|
@ -11,10 +11,8 @@ BEGIN
|
|||
DECLARE vOrder INT;
|
||||
|
||||
SET vOrder = myBasketGetId();
|
||||
|
||||
CALL bionic_from_item (vItem);
|
||||
|
||||
CALL addItem(vWarehouse, vItem, vAmount, vOrder);
|
||||
|
||||
CALL orderAddItem(vOrder,vWarehouse, vItem, vAmount);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
|
@ -1,98 +0,0 @@
|
|||
USE `hedera`;
|
||||
DROP procedure IF EXISTS `addItem`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `hedera`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `addItem`(
|
||||
vWarehouse INT,
|
||||
vItem INT,
|
||||
vAmount INT,
|
||||
vOrder INT)
|
||||
BEGIN
|
||||
DECLARE vRow INT;
|
||||
DECLARE vAdd INT;
|
||||
DECLARE vAvailable INT;
|
||||
DECLARE vDone BOOL;
|
||||
DECLARE vGrouping INT;
|
||||
DECLARE vRate INT;
|
||||
DECLARE vShipment DATE;
|
||||
DECLARE vPrice DECIMAL(10,2);
|
||||
DECLARE cur CURSOR FOR
|
||||
SELECT grouping, price, rate
|
||||
FROM tmp.bionic_price
|
||||
WHERE warehouse_id = vWarehouse
|
||||
AND item_id = vItem
|
||||
ORDER BY grouping DESC;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND
|
||||
SET vDone = TRUE;
|
||||
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
ROLLBACK;
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
SELECT shipped INTO vShipment
|
||||
FROM tmp.travel_tree
|
||||
WHERE warehouseFk = vWarehouse;
|
||||
|
||||
SELECT available INTO vAvailable
|
||||
FROM tmp.bionic_lot
|
||||
WHERE warehouse_id = vWarehouse
|
||||
AND item_id = vItem;
|
||||
|
||||
IF vAmount > vAvailable
|
||||
THEN
|
||||
CALL util.throw ('ORDER_ROW_UNAVAILABLE');
|
||||
END IF;
|
||||
|
||||
OPEN cur;
|
||||
|
||||
l: LOOP
|
||||
SET vDone = FALSE;
|
||||
|
||||
FETCH cur INTO vGrouping, vPrice, vRate;
|
||||
|
||||
IF vDone THEN
|
||||
LEAVE l;
|
||||
END IF;
|
||||
|
||||
SET vAdd = vAmount - MOD(vAmount, vGrouping);
|
||||
SET vAmount = vAmount - vAdd;
|
||||
|
||||
IF vAdd = 0 THEN
|
||||
ITERATE l;
|
||||
END IF;
|
||||
|
||||
INSERT INTO order_row SET
|
||||
order_id = vOrder,
|
||||
item_id = vItem,
|
||||
warehouse_id = vWarehouse,
|
||||
shipment = vShipment,
|
||||
rate = vRate,
|
||||
amount = vAdd,
|
||||
price = vPrice;
|
||||
|
||||
SET vRow = LAST_INSERT_ID();
|
||||
|
||||
INSERT INTO order_component (order_row_id, component_id, price)
|
||||
SELECT vRow, c.component_id, c.cost
|
||||
FROM tmp.bionic_component c
|
||||
JOIN bi.tarifa_componentes t
|
||||
ON t.Id_Componente = c.component_id
|
||||
AND (t.tarifa_class IS NULL OR t.tarifa_class = vRate)
|
||||
WHERE c.warehouse_id = vWarehouse
|
||||
AND c.item_id = vItem;
|
||||
END LOOP;
|
||||
|
||||
CLOSE cur;
|
||||
COMMIT;
|
||||
|
||||
CALL vn2008.bionic_free ();
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
USE `hedera`;
|
||||
DROP procedure IF EXISTS `orderAddItem`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `hedera`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `orderAddItem`(
|
||||
vWarehouse INT,
|
||||
vItem INT,
|
||||
vAmount INT,
|
||||
vOrder INT)
|
||||
BEGIN
|
||||
DECLARE vDate DATE;
|
||||
DECLARE vAddress INT;
|
||||
DECLARE vAgencyMode INT;
|
||||
|
||||
SELECT date_send, address_id, agency_id
|
||||
INTO vDate, vAddress, vAgencyMode
|
||||
FROM `order`
|
||||
WHERE id = vOrder;
|
||||
|
||||
CALL vn2008.bionic_from_item(vDate, vAddress, vAgencyMode, vItem);
|
||||
|
||||
CALL addItem(vWarehouse, vItem, vAmount, vOrder);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -0,0 +1,154 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticketComponentUpdateSale`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `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 Id_Movimiento, warehouse_id
|
||||
**/
|
||||
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 componentRate cr ON cr.id = sc.componentFk
|
||||
WHERE cr.isRenewable;
|
||||
|
||||
REPLACE INTO saleComponent(saleFk, componentFk, value)
|
||||
SELECT s.id, tc.componentFk, ROUND(tc.cost,3)
|
||||
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 componentRate cr ON cr.id = tc.componentFk
|
||||
WHERE IF(sc.componentFk IS NULL AND NOT cr.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 componentRate cr ON cr.id = sc.componentFk
|
||||
JOIN componentTypeRate ctr on ctr.id = cr.componentTypeRate AND ctr.base
|
||||
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, ROUND(s.price,3)
|
||||
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 ;
|
||||
|
Loading…
Reference in New Issue