CREATE OR REPLACE FUNCTION fn_fco_centro_trabajo(pch_compania   in char,
                                                      pch_trabajador in char)
  RETURN number is
  vdc_centro_tra number;
  vch_agt_CTR    char(10); -- Centro de Trabajo
BEGIN

begin
  SELECT dato
    INTO vch_agt_CTR
    FROM vw_fdt_parametros
   WHERE pais = 'COL'
     AND compania = pch_compania
     AND parametro = 'autoliq'
     AND secuencia = 24;
exception
  when no_data_found then
    return(0);
end;

begin
  SELECT codigo_reporte
    INTO vdc_centro_tra
    FROM vw_fco_centros_trabajo a, rel_trab_agr b
   WHERE a.compania = b.compania
     AND a.centro_trabajo = b.dato
     AND a.compania = pch_compania
     AND b.trabajador = pch_trabajador
     AND b.agrupacion = vch_agt_CTR;
exception
  when no_data_found then
    return(0);
end;

  RETURN nvl(vdc_centro_tra, 0);
END fn_fco_centro_trabajo;
/
