8144-devToTest_2448 #3216
|
@ -3,81 +3,124 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_splitItemPacki
|
||||||
vSelf INT,
|
vSelf INT,
|
||||||
vOriginalItemPackingTypeFk VARCHAR(1)
|
vOriginalItemPackingTypeFk VARCHAR(1)
|
||||||
)
|
)
|
||||||
proc:BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Clona y reparte las líneas de ventas de un ticket en funcion del tipo de empaquetado.
|
* Clona y reparte las ventas de un ticket en funcion del tipo de empaquetado.
|
||||||
* Respeta el id de ticket original para el tipo de empaquetado propuesto.
|
* Respeta el id inicial para el tipo propuesto.
|
||||||
*
|
*
|
||||||
* @param vSelf Id ticket
|
* @param vSelf Id ticket
|
||||||
* @param vOriginalItemPackingTypeFk Tipo empaquetado que se mantiene el ticket original
|
* @param vOriginalItemPackingTypeFk Tipo para el que se reserva el número de ticket original
|
||||||
* @return table tmp.ticketIPT(ticketFk, itemPackingTypeFk)
|
* @return table tmp.ticketIPT(ticketFk, itemPackingTypeFk)
|
||||||
*/
|
*/
|
||||||
DECLARE vDone INT DEFAULT FALSE;
|
|
||||||
DECLARE vHasItemPackingType BOOL;
|
|
||||||
DECLARE vItemPackingTypeFk VARCHAR(1) DEFAULT 'H';
|
DECLARE vItemPackingTypeFk VARCHAR(1) DEFAULT 'H';
|
||||||
DECLARE vNewTicketFk INT;
|
DECLARE vNewTicketFk INT;
|
||||||
|
DECLARE vPackingTypesToSplit INT;
|
||||||
|
DECLARE vDone INT DEFAULT FALSE;
|
||||||
|
|
||||||
DECLARE vItemPackingTypes CURSOR FOR
|
DECLARE vSaleGroup CURSOR FOR
|
||||||
SELECT DISTINCT itemPackingTypeFk
|
SELECT itemPackingTypeFk
|
||||||
FROM tSalesToMove;
|
FROM tSaleGroup
|
||||||
|
WHERE itemPackingTypeFk IS NOT NULL
|
||||||
|
ORDER BY (itemPackingTypeFk = vOriginalItemPackingTypeFk) DESC;
|
||||||
|
|
||||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||||
|
|
||||||
SELECT COUNT(*) INTO vHasItemPackingType
|
START TRANSACTION;
|
||||||
FROM ticket t
|
|
||||||
JOIN sale s ON s.ticketFk = t.id
|
SELECT id
|
||||||
JOIN item i ON i.id = s.itemFk
|
FROM sale
|
||||||
WHERE t.id = vSelf
|
WHERE ticketFk = vSelf
|
||||||
AND i.itemPackingTypeFk = vOriginalItemPackingTypeFk;
|
AND NOT quantity
|
||||||
|
FOR UPDATE;
|
||||||
|
|
||||||
|
DELETE FROM sale
|
||||||
|
WHERE NOT quantity
|
||||||
|
AND ticketFk = vSelf;
|
||||||
|
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tSale
|
||||||
|
(PRIMARY KEY (id))
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT s.id, i.itemPackingTypeFk, IFNULL(sv.litros, 0) litros
|
||||||
|
FROM sale s
|
||||||
|
JOIN item i ON i.id = s.itemFk
|
||||||
|
LEFT JOIN saleVolume sv ON sv.saleFk = s.id
|
||||||
|
WHERE s.ticketFk = vSelf;
|
||||||
|
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tSaleGroup
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT itemPackingTypeFk, SUM(litros) totalLitros
|
||||||
|
FROM tSale
|
||||||
|
GROUP BY itemPackingTypeFk;
|
||||||
|
|
||||||
|
SELECT COUNT(*) INTO vPackingTypesToSplit
|
||||||
|
FROM tSaleGroup
|
||||||
|
WHERE itemPackingTypeFk IS NOT NULL;
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketIPT(
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketIPT(
|
||||||
ticketFk INT,
|
ticketFk INT,
|
||||||
itemPackingTypeFk VARCHAR(1)
|
itemPackingTypeFk VARCHAR(1)
|
||||||
) ENGINE=MEMORY
|
) ENGINE = MEMORY;
|
||||||
SELECT vSelf ticketFk, vOriginalItemPackingTypeFk itemPackingTypeFk;
|
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tSalesToMove (
|
CASE vPackingTypesToSplit
|
||||||
ticketFk INT,
|
WHEN 0 THEN
|
||||||
saleFk INT,
|
INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk)
|
||||||
itemPackingTypeFk VARCHAR(1)
|
VALUES(vSelf, vItemPackingTypeFk);
|
||||||
) ENGINE=MEMORY;
|
WHEN 1 THEN
|
||||||
|
INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk)
|
||||||
|
SELECT vSelf, itemPackingTypeFk
|
||||||
|
FROM tSaleGroup
|
||||||
|
WHERE itemPackingTypeFk IS NOT NULL;
|
||||||
|
ELSE
|
||||||
|
OPEN vSaleGroup;
|
||||||
|
FETCH vSaleGroup INTO vItemPackingTypeFk;
|
||||||
|
|
||||||
INSERT INTO tSalesToMove (saleFk, itemPackingTypeFk)
|
INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk)
|
||||||
SELECT s.id, i.itemPackingTypeFk
|
VALUES(vSelf, vItemPackingTypeFk);
|
||||||
FROM ticket t
|
|
||||||
JOIN sale s ON s.ticketFk = t.id
|
|
||||||
JOIN item i ON i.id = s.itemFk
|
|
||||||
WHERE t.id = vSelf
|
|
||||||
AND i.itemPackingTypeFk <> vOriginalItemPackingTypeFk;
|
|
||||||
|
|
||||||
OPEN vItemPackingTypes;
|
l: LOOP
|
||||||
l: LOOP
|
SET vDone = FALSE;
|
||||||
SET vDone = FALSE;
|
FETCH vSaleGroup INTO vItemPackingTypeFk;
|
||||||
FETCH vItemPackingTypes INTO vItemPackingTypeFk;
|
|
||||||
|
|
||||||
IF vDone THEN
|
IF vDone THEN
|
||||||
LEAVE l;
|
LEAVE l;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
CALL ticket_Clone(vSelf, vNewTicketFk);
|
CALL ticket_Clone(vSelf, vNewTicketFk);
|
||||||
|
|
||||||
UPDATE tSalesToMove
|
INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk)
|
||||||
SET ticketFk = vNewTicketFk
|
VALUES(vNewTicketFk, vItemPackingTypeFk);
|
||||||
WHERE itemPackingTypeFk = vItemPackingTypeFk;
|
END LOOP;
|
||||||
|
|
||||||
END LOOP;
|
CLOSE vSaleGroup;
|
||||||
CLOSE vItemPackingTypes;
|
|
||||||
|
|
||||||
UPDATE sale s
|
SELECT s.id
|
||||||
JOIN tSalesToMove stm ON stm.saleFk = s.id
|
FROM sale s
|
||||||
SET s.ticketFk = stm.ticketFk
|
JOIN tSale ts ON ts.id = s.id
|
||||||
WHERE stm.ticketFk;
|
JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = ts.itemPackingTypeFk
|
||||||
|
FOR UPDATE;
|
||||||
|
|
||||||
INSERT INTO tmp.ticketIPT (ticketFk, itemPackingTypeFk)
|
UPDATE sale s
|
||||||
SELECT ticketFk, itemPackingTypeFk
|
JOIN tSale ts ON ts.id = s.id
|
||||||
FROM tSalesToMove
|
JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = ts.itemPackingTypeFk
|
||||||
GROUP BY ticketFk;
|
SET s.ticketFk = t.ticketFk;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tSalesToMove;
|
SELECT itemPackingTypeFk INTO vItemPackingTypeFk
|
||||||
|
FROM tSaleGroup sg
|
||||||
|
WHERE sg.itemPackingTypeFk IS NOT NULL
|
||||||
|
ORDER BY sg.itemPackingTypeFk
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
|
UPDATE sale s
|
||||||
|
JOIN tSale ts ON ts.id = s.id
|
||||||
|
JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = vItemPackingTypeFk
|
||||||
|
SET s.ticketFk = t.ticketFk
|
||||||
|
WHERE ts.itemPackingTypeFk IS NULL;
|
||||||
|
END CASE;
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE
|
||||||
|
tSale,
|
||||||
|
tSaleGroup;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
CREATE TABLE IF NOT EXISTS `vn`.`itemTextureTag` (
|
||||||
|
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`name` varchar(50) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE KEY `name_UNIQUE` (`name`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT
|
||||||
|
CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
||||||
|
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Natural y encerado');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Natural y esponjoso');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Natural y foam');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Natural y látex');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Arenosa');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Aterciopelado');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Engomado');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Flocado');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Foam');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Gasa');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Goma');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Látex');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Latón');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Mate');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Metálico');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Natural');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Natural y engomado');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Plastificado');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Plastificado y engomado');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Plastificado y rugoso');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Pluma');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Plástico');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Plástico engomado');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Poliéster');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Poliéster texturizado');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Rugoso');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Rígido');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Seminatural');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Silicona');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Suave');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela con brillo');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela con texturas');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela dura');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela engomada');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela escarchada');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela flocada');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela flocada engomada');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela foam');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela micro peach');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela plastificada');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela plástico engomado');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela poliéster');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela PVC');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela ratan');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela rigida');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela rugosa');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela rústica');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela sintética');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela y cristal');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela y foam');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela y goma');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela y látex');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela y madera');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela y plástico');
|
||||||
|
INSERT IGNORE INTO `vn`.`itemTextureTag` (`name`) VALUES ('Tela y seco');
|
||||||
|
|
||||||
|
UPDATE vn.tag
|
||||||
|
SET isFree=0,
|
||||||
|
sourceTable='itemTextureTag'
|
||||||
|
WHERE name= 'Textura';
|
||||||
|
|
||||||
|
GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemTextureTag TO logisticAssist;
|
Loading…
Reference in New Issue