CREATE OR REPLACE VIEW vw_fco_centros_trabajo
AS
SELECT 
  rac.compania, dato AS centro_trabajo, 
  NVL((SELECT ct.descripcion FROM fco_centros_trabajo ct 
       WHERE rac.compania = ct.compania AND ct.centro_trabajo = dat.dato), dat.descripcion) AS descripcion, 
  NVL((SELECT TO_CHAR(ct.codigo_reporte) FROM fco_centros_trabajo ct 
       WHERE rac.compania = ct.compania AND ct.centro_trabajo = dat.dato), dato) AS codigo_reporte , 
  (SELECT ct.tarifa FROM fco_centros_trabajo ct 
   WHERE rac.compania = ct.compania AND ct.centro_trabajo = dat.dato) AS tarifa
FROM rel_agr_companias rac, datos_agr_trab dat 
WHERE rac.agrupacion = dat.agrupacion
AND rtrim(rac.agrupacion) = rtrim(NVL(
(Select dato FROM vw_fdt_parametros x
 Where x.pais = 'COL' and x.compania = rac.compania 
   and x.parametro = 'autoliq' and secuencia = 24), 'CENTROS_TR'));

CREATE PUBLIC SYNONYM vw_fco_centros_trabajo FOR ADAM.vw_fco_centros_trabajo;
GRANT ALL ON vw_fco_centros_trabajo TO ADAMA;
