gke_arce_rupe2
.rupe
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
generar_datos_sancion()
Parameters
Name
Type
Mode
Definition
declare /* variables auxiliares para actualizar los registros */ aux_prv_id integer; aux_tipo_sancion VARCHAR(255); aux_fecha_resolucion date; aux_fecha_inicio date; aux_fecha_fin date; aux_fecha_ingreso timestamp; aux_cedula_funcionario VARCHAR(255); aux_inciso VARCHAR(255); aux_unidad_ejecutora VARCHAR(255); aux_visible_rupe boolean; aux_revocada boolean; aux_eliminada boolean; aux_fecha_eliminacion timestamp; aux_fecha_revocacion_rupe timestamp; aux_fecha_revocacion_usuario timestamp; aux_aplica_inciso boolean; sancion_id integer; cod_tipo_sancion VARCHAR(255); es_rango boolean; aux_tipo_usuario VARCHAR(255); tipo_usuario integer; unidad_ejecutora_id integer; inciso_id integer; sancion_procesada integer; /* cursor que retorna las cuentas bancarias del banco BROU (no eliminadas y en estado: Pendiente Validar o Validada)*/ C_sancion CURSOR FOR SELECT d.hch_id FROM rupe.rupe_hechos d; reg_sancion RECORD; BEGIN delete from rupe.exportar_sanciones_indicador; OPEN C_sancion; LOOP FETCH C_sancion INTO reg_sancion; EXIT WHEN NOT FOUND; select id_sancion from rupe.exportar_sanciones_indicador into sancion_procesada where id_sancion = reg_sancion.hch_id; if not found then select hch_id, hch_crea_fecha,hch_crea_usu,hch_revocada,hch_eliminado,hch_aplica_a_todas, th.the_codigo, th.the_es_rango, hch_vigencia_desde, hch_vigencia_hasta, hch_fecha_hecho, th.the_nombre, hch_proveedor_prv_id,hch_inciso_inc_id,hch_unidad_ejecutora_uej_id into sancion_id,aux_fecha_ingreso,aux_cedula_funcionario,aux_revocada,aux_eliminada,aux_aplica_inciso, cod_tipo_sancion, es_rango, aux_fecha_inicio, aux_fecha_fin, aux_fecha_resolucion, aux_tipo_sancion, aux_prv_id,inciso_id,unidad_ejecutora_id from rupe.rupe_hechos, rupe.rupe_tipos_hecho th where hch_id = reg_sancion.hch_id and hch_tipo_hecho_the_id = th.the_id; if not es_rango then aux_fecha_inicio := null; aux_fecha_fin := null; end if; if aux_aplica_inciso is null then aux_aplica_inciso := false; end if; if aux_revocada is null then aux_revocada := false; end if; if aux_eliminada is null then aux_eliminada := false; end if; aux_visible_rupe := false; if cod_tipo_sancion = 'ELIO' then aux_visible_rupe := true; end if; if es_rango and (aux_fecha_fin + interval '5 years') >= current_date then aux_visible_rupe := true; end if; if not es_rango and (aux_fecha_resolucion + interval '5 years') >= current_date then aux_visible_rupe := true; end if; select ua.usu_tipo from audit.rupe_usuarios_aud ua into tipo_usuario where ua.usu_codigo = aux_cedula_funcionario and ua.rev = (select max(rev) from audit.rupe_usuarios_aud r1 where r1.usu_ultmod_fecha < aux_fecha_ingreso and aux_cedula_funcionario = r1.usu_codigo); aux_unidad_ejecutora := null; aux_inciso := null; select uej_nombre from rupe.rupe_unidades_ejecutoras into aux_unidad_ejecutora where uej_id = unidad_ejecutora_id; select inc_nombre from rupe.rupe_incisos into aux_inciso where inc_id = inciso_id; if cod_tipo_sancion = 'SPA' then aux_inciso := null; aux_unidad_ejecutora := null; end if; aux_fecha_eliminacion := null; if aux_eliminada then -- obtengo fecha de revocación en rupe select h.hch_ultmod_fecha from audit.rupe_hechos_aud h into aux_fecha_eliminacion where h.hch_id = sancion_id and h.rev = (select min(rev) from audit.rupe_hechos_aud r1 where r1.hch_eliminado = true and r1.hch_id = sancion_id); end if; aux_fecha_revocacion_rupe := null; aux_fecha_revocacion_usuario := null; if aux_revocada then -- obtengo fecha de revocación en rupe select h.hch_ultmod_fecha from audit.rupe_hechos_aud h into aux_fecha_revocacion_rupe where h.hch_id = sancion_id and h.rev = (select min(rev) from audit.rupe_hechos_aud r1 where r1.hch_revocada = true and r1.hch_id = sancion_id); select rs.rev_fecha from rupe.rupe_revocacion_sancion rs into aux_fecha_revocacion_usuario where rs.rev_san_id = sancion_id; end if; insert into rupe.exportar_sanciones_indicador values (aux_prv_id,sancion_id,aux_tipo_sancion,aux_fecha_resolucion,aux_fecha_inicio,aux_fecha_fin, aux_fecha_ingreso,aux_cedula_funcionario,aux_inciso,aux_unidad_ejecutora,aux_visible_rupe,aux_revocada,aux_eliminada,aux_fecha_eliminacion,aux_fecha_revocacion_rupe, aux_fecha_revocacion_usuario,aux_aplica_inciso); end if; END LOOP; CLOSE C_sancion; Raise debug 'finalizo el proceso de generar tabla para exportar sanciones '; END;