-- VINCULO AUTOMATICO DE ROTAS
DECLARE @IS_CLI_BRPH INT
SET @IS_CLI_BRPH = COALESCE((SELECT 1 FROM PRC_EMP WHERE CGC_EMP = '00447821/0001-70'),0)

IF @IS_CLI_BRPH = 1
BEGIN
	-- CRIANDO ROTA GOIANIA-GO
	DECLARE @CD_ROTA INT
	SET @CD_ROTA = COALESCE((SELECT COALESCE(MAX(CD_ROTA), 0) + 1 FROM RC_CLI_ROTA), 1)
	INSERT INTO RC_CLI_ROTA
	SELECT 1,@CD_ROTA, 'GOIANIA - GO', 0, 0, '07:00:00',	'23:59:59',	1

	INSERT INTO RC_CLI_ROTA_CEP
	SELECT 1, @CD_ROTA, CEP, CD_CID_LOGRA FROM GLB_CID_LOGRA WHERE CD_CID = 52

	INSERT INTO PRC_FILIAL_RC_CLI_ROTA
	SELECT 1, 91, @CD_ROTA, 60, 0, '00:00:00.0000000', '23:59:59.9999999'

	-- CRIANDO ROTA CUIABA-MT
	SET @CD_ROTA = COALESCE((SELECT COALESCE(MAX(CD_ROTA), 0) + 1 FROM RC_CLI_ROTA), 1)
	INSERT INTO RC_CLI_ROTA
	SELECT 1,@CD_ROTA, 'CUIABA - MT', 0, 0, '07:00:00',	'23:59:59',	1

	INSERT INTO RC_CLI_ROTA_CEP
	SELECT 1, @CD_ROTA, CEP, CD_CID_LOGRA FROM GLB_CID_LOGRA WHERE CD_CID = 2721

	INSERT INTO PRC_FILIAL_RC_CLI_ROTA
	SELECT 1, 107, @CD_ROTA, 60, 0, '00:00:00.0000000', '23:59:59.9999999'
END