CREATE OR REPLACE PROCEDURE sp_fdt_del_bancos
(
    pch_compania char,
    pti_banco number
)
AS
/********************************************************************/
/*** Módulo Fiscal de Colombia                                    ***/
/*** Descripcion: borra registros de las tablas fdt_bancos        ***/
/*** y fdt_bancos_cias_datos y fdt_bancos_cias  				          ***/
/*** Autor:	Diana Cecilia Rios Peinado                            ***/
/*** Fecha:	Marzo 11 de 2005                                      ***/
/********************************************************************/
  vnm_existe      number(1);
BEGIN
    vnm_existe := 0;
    BEGIN
      SELECT 1
      INTO vnm_existe
      FROM fdt_bancos_cias
      WHERE banco = pti_banco AND compania <> pch_compania;
      EXCEPTION
              WHEN OTHERS THEN vnm_existe := 0;        
    END;
      
    IF vnm_existe = 1 THEN
        RAISE_APPLICATION_ERROR(-20001,'Este Banco no se puede eliminar porque tiene relación con otras compañías');
        RETURN;        
    END IF;
        
    DELETE FROM fdt_bancos_cias WHERE compania = pch_compania AND banco = pti_banco;
    DELETE FROM fdt_bancos_cias_datos WHERE compania = pch_compania AND banco = pti_banco;
    DELETE FROM fdt_bancos_ins_dep WHERE banco = pti_banco;
    DELETE FROM fdt_bancos WHERE banco = pti_banco;
	  DELETE FROM fdt_rutas WHERE codigo = pti_banco AND operacion = 'FCO1070';
    
    COMMIT WORK;
END;
/
CREATE PUBLIC SYNONYM sp_fdt_del_bancos FOR ADAM.sp_fdt_del_bancos;
GRANT EXECUTE ON sp_fdt_del_bancos TO adama;

