2024-07-22 09:52:42 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`sectorCollection_new`(vSectorFk INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Inserta una nueva colección, si el usuario no tiene ninguna vacia.
|
|
|
|
* Esto se hace para evitar que por error se generen colecciones sin sentido.
|
|
|
|
*
|
|
|
|
* @param vSectorFk Identificador de #vn.sector
|
|
|
|
*/
|
|
|
|
DECLARE hasEmptyCollections BOOL;
|
|
|
|
DECLARE vUserFk INT;
|
|
|
|
|
|
|
|
SET vUserFk = account.myUser_getId();
|
|
|
|
|
|
|
|
SELECT (COUNT(sc.id) > 0) INTO hasEmptyCollections
|
|
|
|
FROM vn.sectorCollection sc
|
|
|
|
LEFT JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id
|
|
|
|
WHERE ISNULL(scsg.id)
|
|
|
|
AND sc.userFk = vUserFk
|
|
|
|
AND sc.sectorFk = vSectorFk
|
|
|
|
AND sc.created >= util.VN_CURDATE();
|
|
|
|
|
|
|
|
IF NOT hasEmptyCollections THEN
|
|
|
|
INSERT INTO vn.sectorCollection(userFk, sectorFk)
|
|
|
|
VALUES(vUserFk, vSectorFk);
|
|
|
|
END IF;
|
2024-07-22 09:52:42 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|