DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`saleTracking_addPrevOK`(vSectorCollectionFk INT)
BEGIN
/**
 * Inserta los registros de la colección de sector con el estado PREVIA OK
 *
 * @param vSectorCollectionFk Identificador de vn.sectorCollection
 */
	REPLACE vn.saleTracking(
			saleFk,
			isChecked,
			workerFk,
			stateFk
		)
		SELECT sgd.saleFk,
				TRUE,
				sc.userFk,
				s.id
			FROM sectorCollection sc
				JOIN sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id
				JOIN saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk
				JOIN state s ON s.code = 'OK PREVIOUS'
				JOIN itemShelvingSale iss ON iss.saleFk = sgd.saleFk
			WHERE sc.id = vSectorCollectionFk;
END$$
DELIMITER ;
