-- Seleccionar base de datos
USE testing_votaciones;
GO

DROP PROCEDURE IF EXISTS TJT.get_tarjetas_propietarios_tipos;
GO
CREATE PROCEDURE TJT.get_tarjetas_propietarios_tipos
    @varPK INT,
    @opc INT
AS
BEGIN
    SELECT *
    FROM TJT.tarjetas_propietarios_tipos
    WHERE (@varPK = 0 OR id_tarjeta_propietario_tipo = @varPK)
        AND (@opc = 0 OR estado <> 3);
END;
GO





DROP PROCEDURE IF EXISTS TJT.get_tarjetas_propietarios;
GO
CREATE PROCEDURE TJT.get_tarjetas_propietarios
    @varPK INT,
    @opc INT
AS
BEGIN
    SELECT *
    FROM TJT.tarjetas_propietarios
    WHERE (@varPK = 0 OR id_tarjeta_propietario = @varPK)
        AND (@opc = 0 OR estado <> 3);
END;
GO





DROP PROCEDURE IF EXISTS TJT.get_tarjetas_tipos;
GO
CREATE PROCEDURE TJT.get_tarjetas_tipos
    @varPK INT,
    @opc INT
AS
BEGIN
    SELECT *
    FROM TJT.tarjetas_tipos
    WHERE (@varPK = 0 OR id_tarjeta_tipo = @varPK)
        AND (@opc = 0 OR estado <> 3);
END;
GO





DROP PROCEDURE IF EXISTS TJT.get_bancos;
GO
CREATE PROCEDURE TJT.get_bancos
    @varPK INT,
    @opc INT
AS
BEGIN
    SELECT *
    FROM TJT.bancos
    WHERE (@varPK = 0 OR id_banco = @varPK)
        AND (@opc = 0 OR estado <> 3);
END;
GO





DROP PROCEDURE IF EXISTS TJT.get_tarjetas;
GO
CREATE PROCEDURE TJT.get_tarjetas
    @varPK INT,
    @opc INT
AS
BEGIN
    SELECT *
    FROM TJT.tarjetas
    WHERE (@varPK = 0 OR id_tarjeta = @varPK)
        AND (@opc = 0 OR estado <> 3);
END;
GO





DROP PROCEDURE IF EXISTS TJT.get_empresas_empleados;
GO
CREATE PROCEDURE TJT.get_empresas_empleados
    @varPK INT,
    @opc INT
AS
BEGIN
    SELECT *
    FROM TJT.empresas_empleados
    WHERE (@varPK = 0 OR id_empresa_empleado = @varPK)
        AND (@opc = 0 OR estado <> 3);
END;
GO





DROP PROCEDURE IF EXISTS TJT.get_empresas_departamentos;
GO
CREATE PROCEDURE TJT.get_empresas_departamentos
    @varPK INT,
    @opc INT
AS
BEGIN
    SELECT *
    FROM TJT.empresas_departamentos
    WHERE (@varPK = 0 OR id_empresa_departamento = @varPK)
        AND (@opc = 0 OR estado <> 3);
END;
GO





DROP PROCEDURE IF EXISTS TJT.get_tarjetas_beneficios;
GO
CREATE PROCEDURE TJT.get_tarjetas_beneficios
    @varPK INT,
    @opc INT
AS
BEGIN
    SELECT *
    FROM TJT.tarjetas_beneficios
    WHERE (@varPK = 0 OR id_tarjeta_beneficio = @varPK)
        AND (@opc = 0 OR estado <> 3);
END;
GO





-- DROP PROCEDURE IF EXISTS TJT.get_tarjetas_beneficios_asignaciones;
-- GO
-- CREATE PROCEDURE TJT.get_tarjetas_beneficios_asignaciones
--     @varPK INT,
--     @opc INT
-- AS
-- BEGIN
--     SELECT *
--     FROM TJT.tarjetas_beneficios_asignaciones
--     WHERE (@varPK = 0 OR id_tarjeta_beneficio_asignacion = @varPK)
--         AND (@opc = 0 OR estado <> 3);
-- END;
-- GO





DROP PROCEDURE IF EXISTS TJT.get_tarjetas_intereses;
GO
CREATE PROCEDURE TJT.get_tarjetas_intereses
    @varPK INT,
    @opc INT
AS
BEGIN
    SELECT *
    FROM TJT.tarjetas_intereses
    WHERE (@varPK = 0 OR id_tarjeta_interes = @varPK)
        AND (@opc = 0 OR estado <> 3);
END;
GO





-- DROP PROCEDURE IF EXISTS TJT.get_tarjetas_intereses_asignaciones;
-- GO
-- CREATE PROCEDURE TJT.get_tarjetas_intereses_asignaciones
--     @varPK INT,
--     @opc INT
-- AS
-- BEGIN
--     SELECT *
--     FROM TJT.tarjetas_intereses_asignaciones
--     WHERE (@varPK = 0 OR id_tarjeta_interes_asignacion = @varPK)
--         AND (@opc = 0 OR estado <> 3);
-- END;
-- GO





DROP PROCEDURE IF EXISTS TJT.get_cuentas;
GO
CREATE PROCEDURE TJT.get_cuentas
    @varPK INT,
    @opc INT
AS
BEGIN
    SELECT *
    FROM TJT.cuentas
    WHERE (@varPK = 0 OR id_cuenta = @varPK)
        AND (@opc = 0 OR estado <> 3);
END;
GO





DROP PROCEDURE IF EXISTS TJT.get_tarjetas_gastos_categorias;
GO
CREATE PROCEDURE TJT.get_tarjetas_gastos_categorias
    @varPK INT,
    @opc INT
AS
BEGIN
    SELECT *
    FROM TJT.tarjetas_gastos_categorias
    WHERE (@varPK = 0 OR id_tarjeta_gasto_categoria = @varPK)
        AND (@opc = 0 OR estado <> 3);
END;
GO





DROP PROCEDURE IF EXISTS TJT.get_tarjetas_gastos;
GO
CREATE PROCEDURE TJT.get_tarjetas_gastos
    @varPK INT,
    @opc INT
AS
BEGIN
    SELECT *
    FROM TJT.tarjetas_gastos
    WHERE (@varPK = 0 OR id_tarjeta_gasto = @varPK)
        AND (@opc = 0 OR estado <> 3);
END;
GO





DROP PROCEDURE IF EXISTS TJT.get_cuentas_gastos_asignaciones;
GO
CREATE PROCEDURE TJT.get_cuentas_gastos_asignaciones
    @varPK INT,
    @opc INT
AS
BEGIN
    SELECT *
    FROM TJT.cuentas_gastos_asignaciones
    WHERE (@varPK = 0 OR id_cuenta_gasto_asignacion = @varPK)
        AND (@opc = 0 OR estado <> 3);
END;
GO





DROP PROCEDURE IF EXISTS TJT.get_tarjetas_pagos;
GO
CREATE PROCEDURE TJT.get_tarjetas_pagos
    @varPK INT,
    @opc INT
AS
BEGIN
    SELECT *
    FROM TJT.tarjetas_pagos
    WHERE (@varPK = 0 OR id_tarjeta_pago = @varPK)
        AND (@opc = 0 OR estado <> 3);
END;
GO





DROP PROCEDURE IF EXISTS TJT.get_presupuestos_recipientes_tipos;
GO
CREATE PROCEDURE TJT.get_presupuestos_recipientes_tipos
    @varPK INT,
    @opc INT
AS
BEGIN
    SELECT *
    FROM TJT.presupuestos_recipientes_tipos
    WHERE (@varPK = 0 OR id_presupuesto_recipiente_tipo = @varPK)
        AND (@opc = 0 OR estado <> 3);
END;
GO





DROP PROCEDURE IF EXISTS TJT.get_presupuestos;
GO
CREATE PROCEDURE TJT.get_presupuestos
    @varPK INT,
    @opc INT
AS
BEGIN
    SELECT *
    FROM TJT.presupuestos
    WHERE (@varPK = 0 OR id_presupuesto = @varPK)
        AND (@opc = 0 OR estado <> 3);
END;
GO





-- DROP PROCEDURE IF EXISTS TJT.get_backups_tipos;
-- GO
-- CREATE PROCEDURE TJT.get_backups_tipos
--     @varPK INT,
--     @opc INT
-- AS
-- BEGIN
--     SELECT *
--     FROM TJT.backups_tipos
--     WHERE @varPK = 0 OR id_backup_tipo = @varPK;
-- END;
-- GO





DROP PROCEDURE IF EXISTS TJT.get_backups;
GO
CREATE PROCEDURE TJT.get_backups
    @varPK INT,
    @opc INT
AS
BEGIN
    SELECT *
    FROM TJT.backups
    WHERE (@varPK = 0 OR id_backup = @varPK)
        AND (@opc = 0 OR estado <> 3);
END;
GO





DROP PROCEDURE IF EXISTS TJT.get_audit_log;
GO
CREATE PROCEDURE TJT.get_audit_log
    @varPK INT,
    @opc INT
AS
BEGIN
    SELECT *
    FROM TJT.audit_log
    WHERE @varPK = 0 OR id_audit_log = @varPK;
END;
GO





DROP PROCEDURE IF EXISTS TJT.get_aichat_mensajes;
GO
CREATE PROCEDURE TJT.get_aichat_mensajes
    @varPK INT,
    @opc INT
AS
BEGIN
    SELECT *
    FROM TJT.aichat_mensajes
    WHERE (@varPK = 0 OR id_mensaje = @varPK)
        AND (@opc = 0 OR estado <> 3);
END;
GO
