· 6 years ago · Jul 04, 2019, 10:38 PM
1
2
3drop function if exists mcom.fn_centros_acreditados_referente_detalle(integer, integer, integer [], integer);
4create or replace function mcom.fn_centros_acreditados_referente_detalle(idReferente integer, anio integer, metodo integer [],
5 mes integer default null)
6 returns TABLE
7 (
8 nombre_centro varchar,
9 grupo varchar,
10 cupo_beca_nacional integer,
11 cupo_fondos_propios integer
12 )
13 language plpgsql
14as
15$$
16DECLARE
17 CONSULTA VARCHAR;
18BEGIN
19
20 CONSULTA := 'SELECT centros_inatec.nombre,
21 o.grupo as grupo_oferta,
22 P.cupo AS cupo_beca_nacional,
23 P.cupofp AS cupo_fondos_propios
24 FROM registro_cobranza.rg_oferta o
25 INNER JOIN sac.acuerdos_detalles acd ON (acd.ID = o.id_acuerdo_deta)
26 INNER JOIN sac.acuerdos ac ON (acd.acuerdoid = ac.acuerdoid)
27 INNER JOIN registro_cobranza.cu_curso_clasificacion cl ON (
28 acd.id_curso_clasificacion = cl.ID
29 )
30 INNER JOIN registro_cobranza.cu_estructura_formativa ef ON (
31 ef.ID = cl.id_estructura_formativa
32 )
33 INNER JOIN registro_cobranza.cu_cat_curso C ON cl.id_curso = C.ID
34 LEFT JOIN registro_cobranza.indicadores_vis ON registro_cobranza.indicadores_vis.ID = o.id_indicador_detalle
35 INNER JOIN registro_cobranza.reg_catalogo_turno ON o.id_turno =
36 registro_cobranza.reg_catalogo_turno.id_turno
37 INNER JOIN registro_cobranza.cu_det_rama_familia drf ON C
38 .id_det_rama_familia = drf.ID
39 INNER JOIN registro_cobranza.cu_det_sector_rama dsr ON drf.id_sector_rama = dsr.ID
40 INNER JOIN PUBLIC.tb_sectores s ON s.id_sector = dsr.id_sector
41 INNER JOIN registro_cobranza.rg_programacion P ON P.ID = o.id_programacion
42 INNER JOIN public.tb_centros_inatec as centros_inatec
43 on o.id_centro = centros_inatec.id_centro::integer
44 WHERE C.id_tipo_evento = 4
45 AND o.activo IN (1) and';
46
47 IF idreferente != -1
48 THEN
49 CONSULTA := CONSULTA || ' ef.ID = ' || idreferente || ' AND';
50 end if;
51
52 CONSULTA := CONSULTA || ' o.anio_ofertado = ' || anio || ' AND';
53
54 CONSULTA := CONSULTA || ' P.metodo_evaluacion in (' || (select * from array_to_string(ARRAY [metodo], ',')) ||
55 ')';
56 if mes is not null
57 then
58 CONSULTA := CONSULTA || ' and o.mes_ofertado=' || mes;
59 end if;
60
61 consulta := CONSULTA || 'ORDER BY o.finicio';
62 RETURN QUERY EXECUTE CONSULTA;
63END;
64$$;
65comment on function mcom.fn_centros_acreditados_referente_detalle(integer, integer, integer [], integer)
66is 'función para obtener detalles de ofertas de un referente especifico';