Respuesta: Convertir Funcion para consultar todos los usuarios!!! MIRA ESTA ES LA FUNCION ORIGINAL, QUE SI FUNCIONA CON EL PARAMETRO CEDULA QUE ES LA ID DEL USUARIO EN LA TABLA BENEFICIARIO QUE ES EL BE. (v_cedula_titular)
CREATE OR REPLACE FUNCTION f_consulta_fondo_solidario(v_ano_fondo smallint, v_id_area integer, v_cedula_titular character varying)
RETURNS SETOF consulta_fondo_solidario AS
$BODY$
DECLARE
BENEFI RECORD;
REGISTRO consulta_fondo_solidario;
V_TOTALES_FONDO VARCHAR[];
V_TOTALES_INDIV numeric;
BEGIN
FOR BENEFI IN SELECT
be.id,
CASE
WHEN be.consecutivo = 0 AND be.id_status_laboral <> 'TJ'::text THEN 'Tit-'::text || f_smident(be.id)
WHEN be.id_status_laboral= 'TJ'::text THEN 'Jub-'::text || f_smident(be.id)
ELSE 'Fam-'::text || f_smident(be.id)
END as identific,
''::varchar as numero_sap,
cedula_titular as cedula_titular,
(select nombre from "Beneficiario" where cedula_titular=be.cedula_titular and consecutivo=0) as nombre_titular,
date_part('year'::text,age(f_dato_benefi(id, 'fecha_nacimiento'::character varying, true)::timestamp without time zone)) AS edad_titular,
CASE WHEN F_DATO_BENEFI(id,'sexo',true)=1 THEN 'M' ELSE 'F' END as sexo_titular,
(select nombre from "Tipo_nomina" where id=be.id_tipo_nomina) as nomina,
''::varchar as grupo_personal,
(select nombre from "Area" where id =(select id_area from "Beneficiario" where cedula_titular=be.cedula_titular and consecutivo=0)) as area_titular,
(select nombre from "Filial" where id =be.id_filial) as filial,
''::varchar as division,
(select localidad from "Localidad" where id=be.id_localidad) as localidad,
(select nombre from "Status_laboral" where id=be.id_status_laboral) as estatus_laboral,
cedula as cedula_participante,
nombre as participante,
(select nombre from "Parentesco" where id=be.id_parentesco) as parentesco,
date_part('year'::text,age(fecha_nacimiento)) AS edad_familiar,
CASE WHEN sexo=1 THEN 'M' ELSE 'F' END as sexo_familiar
FROM "Beneficiario" AS be
WHERE
EXISTS (select id from "Status_laboral" where "Status_laboral".id = BE.ID_STATUS_LABORAL AND aplica_planes=true)
AND EXISTS (select id from "Parentesco" where "Parentesco".id = BE.id_parentesco AND aplica_fondo_solidario=true)
AND EXISTS (select id from "Filial" where "Filial".id = BE.id_filial AND aplica_fondo_solidario=true)
AND EXISTS(SELECT ID FROM "Ajuste_y_transferencia_de_fondo" aj WHERE ANO_FONDO=V_ANO_FONDO and (be.cedula_titular= substr(id_beneficiario_desde,1,9)::int OR be.cedula_titular= substr(id_beneficiario_hasta,1,9)::int))
AND CASE WHEN V_ID_AREA=0 THEN 0=0 ELSE be.id_area= V_ID_AREA END
AND CASE WHEN V_CEDULA_TITULAR='' THEN 0=0 ELSE be.cedula_titular=V_CEDULA_TITULAR END
LOOP
IF (V_ANO_FONDO=TO_CHAR(CURRENT_DATE,'YYYY')) THEN
V_TOTALES_FONDO=(SELECT ARRAY[p,i,f] FROM (select nombre as p,sum(pote)::varchar as i,sum(disponible)::varchar as f from f_suma_pote_familia_por_beneficiario(BENEFI.id) where aplica_fondo_solidario= true and aplica_planes=true and id_plan='plan1' group by 1) as f);
V_TOTALES_INDIV=(select pote from f_suma_pote_por_beneficiario(BENEFI.ID) where aplica_fondo_solidario= true and aplica_planes=true and id_plan='plan1');
ELSE
V_TOTALES_FONDO=(SELECT ARRAY[p,i,f] FROM (select nombre as p,sum(pote)::varchar as i,sum(disponible)::varchar as f from f_suma_pote_familia_por_beneficiario_anos_anterior es(BENEFI.id,V_ANO_FONDO) where aplica_fondo_solidario= true and aplica_planes=true and id_plan='plan1' group by 1) as f);
V_TOTALES_INDIV=(select pote from f_suma_pote_por_beneficiario_anos_anteriores(BENEF I.ID,V_ANO_FONDO) where aplica_fondo_solidario= true and aplica_planes=true and id_plan='plan1');
END IF;
FOR REGISTRO IN SELECT
V_TOTALES_FONDO[1],BENEFI.identific,BENEFI.NUMERO_SAP,BENEFI.CEDULA_ TITULAR,BENEFI.NOMBRE_TITULAR,BENEFI.EDAD_TITULAR, BENEFI.SEXO_TITULAR,BENEFI.NOMINA,BENEFI.GRUPO_PER SONAL,BENEFI.AREA_TITULAR,BENEFI.FILIAL,BENEFI.DIV ISION,BENEFI.LOCALIDAD,BENEFI.ESTATUS_LABORAL, BENEFI.CEDULA_PARTICIPANTE,BENEFI.PARTICIPANTE,BEN EFI.PARENTESCO,BENEFI.EDAD_FAMILIAR,BENEFI.SEXO_FA MILIAR,V_TOTALES_INDIV,V_TOTALES_FONDO[2]::numeric - V_TOTALES_INDIV,V_TOTALES_FONDO[2]::numeric,V_TOTALES_FONDO[3]::numeric
LOOP
RETURN NEXT REGISTRO;
END LOOP;
END LOOP;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION f_consulta_fondo_solidario(smallint, integer, character varying) OWNER TO sigplan;
GRANT EXECUTE ON FUNCTION f_consulta_fondo_solidario(smallint, integer, character varying) TO sigplan;
GRANT EXECUTE ON FUNCTION f_consulta_fondo_solidario(smallint, integer, character varying) TO public;
GRANT EXECUTE ON FUNCTION f_consulta_fondo_solidario(smallint, integer, character varying) TO sigplan_app_grupo;
GRANT EXECUTE ON FUNCTION f_consulta_fondo_solidario(smallint, integer, character varying) TO sigplan_auditoria_grupo; LO QUE QUIERO ES MODIFICAR ESTA FUNCION PARA QUE TRABAJE SOLO CON LOS OTROS DOS PARAMETROS. (ELIMINANDO v_cedula_titular) CREATE OR REPLACE FUNCTION f_consulta_fondo_solidario(v_ano_fondo smallint, v_id_area integer) |