--DEL35_CESS_FENP_DBCFX_TC12
create
or replace view del35_cess_fenp_dbcfx_tc12
(unique_id, id_richiesta, codice_richiesta, inbound_outbound, sistema_in_out, cod_tipo_comunicazione, desc_tipo_comunicazione, delibera, esito_notifica, data_inv_not_da_dbcfx, data_ric_not_su_dbcfx, data_notifica, codice_ordine_olo, data_ordine_olo, codice_ordine_ti, data_ordine_ti, dn, id_risorsa, nome_file_inviato_a_now, nome_file_ricevuto_da_now, cod_operatore_recipient, cod_operatore_donor, cod_operatore_donating, dac, des, dac_rimodulata, bid, unique_id_now, unique_id_crm_notify, unique_id_crm, unique_id_now_notify, data_filtro)
as
select SYS_GUID()                                     as UNIQUE_ID,
       null                                           AS ID_RICHIESTA,
       CAST(GFRI.ID_RICHIESTA AS varchar2(100))       AS CODICE_RICHIESTA,
       'INBOUND'                                      AS INBOUND_OUTBOUND,
       CAST('FENP/NOW' AS varchar2(100))              AS SISTEMA_IN_OUT,
       CAST(gfri.tipo_comunicazione AS varchar2(100)) AS TIPO_COMUNICAZIONE,
       CASE gfri.TIPO_COMUNICAZIONE
           WHEN 2 THEN CAST('Notificaito  verifiche Formali e Tecniche del Donor vs Recipient' AS varchar2
                            (100)) --Non interessato
           WHEN 3 THEN CAST('PRENOTIFICA' AS varchar2(100))
           WHEN 5 THEN CAST('ESITO VERIFICHE CS' AS varchar2(100)) -- Non Interessato per questa query
           WHEN 6 THEN CAST('Comunicazione es verifiche  del Donor vs Recipient' AS varchar2 (100)) -- Non Interessato
           WHEN 7 THEN CAST('ESPLETAMENTO' AS varchar2(100))
           WHEN 8 THEN CAST('CESSAZIONE' AS varchar2(100)) -- Non Interessato
           WHEN 10 THEN CAST('RIMODULAZIONE DAC' AS varchar2(100))
           WHEN 11 THEN CAST('ANNULLAMENTO' AS varchar2(100))
           WHEN 12 THEN CAST('CESSAZIONE CON RIENTRO' AS varchar2(100)) -- Non Interessato
           WHEN 17 THEN CAST('RIMODULAZIONE DAC' AS varchar2(100))
           WHEN 18 THEN CAST('ANNULLAMENTO' AS varchar2(100))
           END                                        AS DESC_TIPO_COMUNICAZIONE,
       CASE WHEN gfri.nome_file LIKE '103%NP%' THEN 'Del.103' ELSE 'Del.35' end AS DELIBERA,
       null                                           AS ESITO_NOTIFICA,
       null                                           AS DATA_INV_NOT_DA_DBCFX,
       null                                           AS DATA_RIC_NOT_SU_DBCFX,
       CAST(gfri.data_ricezione AS varchar2(100))     AS DATA_NOTIFICA,
       CAST(gfri.codice_ordine AS varchar2(100))      as CODICE_ORDINE_OLO,
       CAST(gfri.data_ordine AS varchar2(100))        as DATA_ORDINE_OLO,
       null                                           as CODICE_ORDINE_TI,
       null                                           as DATA_ORDINE_TI,
       CAST(gfri.dn AS varchar2(100))                 as DN,
       null                                           as ID_RISORSA,
       null                                           as NOME_FILE_INVIATO_A_NOW,
       CAST(gfri.NOME_FILE AS varchar2(100))          as NOME_FILE_RICEVUTO_DA_NOW,
       CAST(gfri.COD_OP_RECIPIENT AS varchar2(100))   as COD_OPERATORE_RECIPIENT,
       CAST(gfri.COD_OP_DONOR AS varchar2(100))       as COD_OPERATORE_DONOR,
       CAST(gfri.COD_OP_DONATING AS varchar2(100))    as COD_OPERATORE_DONATING,
       CAST(gfri.DAC AS varchar2(100))                as DAC,
       CASE gfri.TIPO_COMUNICAZIONE
           WHEN 7 THEN CAST(gfri.data_ordine AS varchar2(100))
           END                                        AS DES,
       CASE gfri.TIPO_COMUNICAZIONE
           WHEN 10 THEN CAST(gfri.DAC AS varchar2(100))
           WHEN 17 THEN CAST(gfri.DAC AS varchar2(100))
           END                                        AS DAC_RIMODULATA,
       null                                           AS BID,
       CAST(GFRI.PROG_ID AS varchar2(100))            AS UNIQUE_ID_NOW,
       null                                              UNIQUE_ID_CRM_NOTIFY,
       null                                              UNIQUE_ID_CRM,
       null                                              UNIQUE_ID_NOW_NOTIFY,
       GFRI.DATA_RICEZIONE                            AS DATA_FILTRO
from GNP_FENP_RICHIESTE_IN GFRI
WHERE tipo_comunicazione = 12;