2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`sectorCollectionSaleGroup_add`(vSaleGroupFk INT, vSectorCollectionFk INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Inserta un nuevo registro en vn.sectorCollectionSaleGroup
|
|
|
|
* Actualiza el usuario en vn.saleGroup y reemplaza los registros de vn.saleTracking
|
|
|
|
*
|
|
|
|
* @param vSaleGroupFk Identificador de vn.saleGroup
|
|
|
|
* @param vSectorCollectionFk Identificador de vn.sectorCollection
|
|
|
|
*/
|
2024-02-20 15:10:16 +00:00
|
|
|
DECLARE vHasSaleGroup INT;
|
|
|
|
DECLARE vHasSectorCollection INT;
|
|
|
|
|
|
|
|
SELECT COUNT(id) INTO vHasSaleGroup
|
2024-02-21 06:15:43 +00:00
|
|
|
FROM saleGroup
|
2024-02-21 06:08:45 +00:00
|
|
|
WHERE id = vSaleGroupFk;
|
2024-02-20 15:10:16 +00:00
|
|
|
|
|
|
|
IF !vHasSaleGroup THEN
|
2024-02-21 06:08:45 +00:00
|
|
|
CALL util.throw ("invalid saleGroup");
|
2024-02-20 15:10:16 +00:00
|
|
|
END IF;
|
|
|
|
|
|
|
|
SELECT COUNT(id) INTO vHasSectorCollection
|
2024-02-21 06:15:43 +00:00
|
|
|
FROM sectorCollection
|
2024-02-21 06:08:45 +00:00
|
|
|
WHERE id = vSectorCollectionFk;
|
2024-02-20 15:10:16 +00:00
|
|
|
|
|
|
|
IF !vHasSectorCollection THEN
|
2024-02-21 06:08:45 +00:00
|
|
|
CALL util.throw ("invalid sectorCollection");
|
2024-02-20 15:10:16 +00:00
|
|
|
END IF;
|
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
REPLACE sectorCollectionSaleGroup
|
|
|
|
SET sectorCollectionFk = vSectorCollectionFk,
|
|
|
|
saleGroupFk = vSaleGroupFk;
|
|
|
|
|
|
|
|
UPDATE saleGroup sg
|
|
|
|
JOIN sectorCollectionSaleGroup scsg ON scsg.saleGroupFk = sg.id
|
|
|
|
JOIN sectorCollection sc ON sc.id = scsg.sectorCollectionFk
|
|
|
|
SET sg.userFk = sc.userFk
|
|
|
|
WHERE sg.id = vSaleGroupFk;
|
|
|
|
|
|
|
|
INSERT IGNORE saleTracking(
|
|
|
|
saleFk,
|
|
|
|
isChecked,
|
|
|
|
workerFk,
|
|
|
|
stateFk
|
|
|
|
)
|
|
|
|
SELECT sgd.saleFk ,
|
|
|
|
FALSE,
|
|
|
|
sc.userFk,
|
|
|
|
s.id
|
|
|
|
FROM saleGroupDetail sgd
|
|
|
|
JOIN sectorCollectionSaleGroup scsg
|
|
|
|
ON scsg.saleGroupFk = sgd.saleGroupFk
|
|
|
|
JOIN sectorCollection sc ON sc.id = scsg.sectorCollectionFk
|
|
|
|
JOIN state s ON s.code = 'PREVIOUS_PREPARATION'
|
|
|
|
WHERE sgd.saleGroupFk = vSaleGroupFk;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|