update structure db
This commit is contained in:
parent
87447661b2
commit
cb17a1dc79
|
@ -12,7 +12,9 @@ BEGIN
|
|||
|
||||
SET vOrder = myBasketGetId();
|
||||
|
||||
CALL orderAddItem(vWarehouse, vItem, vAmount, vOrder);
|
||||
CALL bionic_from_item (vItem);
|
||||
|
||||
CALL addItem(vWarehouse, vItem, vAmount, vOrder);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
|
@ -0,0 +1,98 @@
|
|||
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 ;
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
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,81 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticketCalculateClon`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticketCalculateClon`(IN vTicket BIGINT)
|
||||
BEGIN
|
||||
|
||||
/*
|
||||
*
|
||||
* Este procedimiento "rebioniza" una linea, eliminando los componentes existentes e insertandolos de nuevo
|
||||
*/
|
||||
DECLARE vShipped DATE;
|
||||
DECLARE vClient INT;
|
||||
DECLARE vWarehouse SMALLINT;
|
||||
DECLARE vAgencyMode INT;
|
||||
DECLARE vAddress INT;
|
||||
DECLARE vLanded DATE;
|
||||
DECLARE vAgency INT;
|
||||
|
||||
REPLACE orderTicket(orderFk,ticketFk) VALUES(48, vTicket);
|
||||
|
||||
SELECT t.clientFk , t.warehouseFk, date(t.shipped), t.addressFk, t.agencyModeFk, t.landed, a.agencyFk
|
||||
INTO vClient, vWarehouse, vShipped, vAddress, vAgencyMode, vLanded, vAgency
|
||||
FROM vn.agencyMode a
|
||||
JOIN vn.ticket t ON t.agencyModeFk = a.id
|
||||
WHERE t.id = vTicket;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.agencyHourGetShipped;
|
||||
CREATE TEMPORARY TABLE tmp.agencyHourGetShipped ENGINE = MEMORY
|
||||
SELECT vWarehouse warehouseFk, vShipped shipped, vLanded landed;
|
||||
|
||||
CALL buyUltimate(vWarehouse, vShipped); -- rellena la tabla tmp.buyUltimate con la ultima compra
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
|
||||
CREATE TEMPORARY TABLE tmp.ticketLot
|
||||
SELECT vWarehouse warehouseFk,NULL available,s.itemFk, bu.buyFk
|
||||
FROM sale s
|
||||
LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
|
||||
WHERE s.ticketFk = vTicket GROUP BY s.itemFk;
|
||||
|
||||
CALL ticketComponentCalculate(vAddress,vAgencyMode);
|
||||
|
||||
-- Bionizamos lineas con Preu = 0
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
|
||||
CREATE TEMPORARY TABLE tmp.sale
|
||||
(PRIMARY KEY (saleFk)) ENGINE = MEMORY
|
||||
SELECT s.id saleFk, vWarehouse warehouseFk
|
||||
FROM sale s
|
||||
JOIN ticket t on t.id = s.ticketFk WHERE s.ticketFk = vTicket AND s.price = 0;
|
||||
|
||||
CALL ticketComponentUpdateSale(1);
|
||||
|
||||
-- Bionizamos lineas con Preu > 0
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
|
||||
CREATE TEMPORARY TABLE tmp.sale
|
||||
(PRIMARY KEY (saleFk)) ENGINE = MEMORY
|
||||
SELECT s.id saleFk, vWarehouse warehouseFk
|
||||
FROM sale s
|
||||
JOIN ticket t on t.id = s.ticketFk WHERE s.ticketFk = vTicket AND s.price > 0;
|
||||
|
||||
CALL ticketComponentUpdateSale(6);
|
||||
|
||||
IF vLanded IS NULL THEN
|
||||
CALL agencyHourGetLanded(vShipped, vAddress, vAgency,vWarehouse);
|
||||
|
||||
UPDATE ticket t
|
||||
JOIN tmp.agencyHourGetLanded ah ON t.warehouseFk = ah.warehouseFk
|
||||
SET t.landed = ah.landed
|
||||
WHERE t.id = vTicket;
|
||||
END IF;
|
||||
|
||||
-- Log
|
||||
CALL `logAdd`(vTicket, 'update', ' ticket' , 'Bioniza Ticket');
|
||||
|
||||
-- Limpieza
|
||||
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
Loading…
Reference in New Issue