Vai al contenuto

F_REP_CUCINA

Codice Sorgente

```sql FUNCTION "F_REP_CUCINA" (p_data_in IN varchar2,p_data_fi IN varchar2) RETURN t_rep_cucina_tab PIPELINED AS

cursor c_evento is select e.id, e.data, l.LOCATION, e.cliente, t.DESCRIZIONE, e.ORA_CERIMONIA, e.ORA_EVENTO, e.ALLERGIE, e.torta, e.CONFETTATA,
e.STAMPA_MENU, e.extra_info, e.cliente_email, e.cliente_tel, e.referente_tel, e.distanza_location, e.buffet_iniziale, e.buffet_finale, e.primi, e.secondi, e.vini, e.extra_costi from eventi e
left join location l on e.id_location = l.id join tb_tipi_evento t on e.cod_tipo = t.cod_tipo where e.data between to_date(p_data_in,'YYYYMMDD') and to_date(p_data_fi,'YYYYMMDD') and e.stato = 300 -- Considero soltanto le schede confermate and e.disabled = 0 and e.deleted = 0;

v_data date; v_LOCATION varchar2(4000); v_cliente varchar2(4000); v_DESCRIZIONE varchar2(4000); v_ORA_CERIMONIA varchar2(4000); v_ORA_EVENTO varchar2(4000); v_TOT_ADULTI number; v_TOT_KINDER number; v_TOT_BABY number; v_TOT_STAFF number; v_TOT_INVITATI number; v_ALLERGIE varchar2(4000); v_TORTA varchar2(4000); v_CONFETTATA varchar2(4000); v_STAMPA_MENU varchar2(4000); v_angoli varchar2(4000); v_EXTRA_INFO varchar2(4000); v_NOTE_ADULTI varchar2(4000); v_NOTE_KINDER varchar2(4000); v_NOTE_BABY varchar2(4000); v_NOTE_STAFF varchar2(4000); v_cliente_email varchar2(4000) := ''; v_cliente_tel varchar2(4000) := ''; v_referente_tel varchar2(4000) := ''; v_distanza_location varchar2(4000) := ''; v_buffet_iniziale varchar2(4000) := ''; v_buffet_finale varchar2(4000) := ''; v_primi varchar2(4000) := ''; v_secondi varchar2(4000) := ''; v_vini varchar2(4000) := ''; v_extra_costi varchar2(4000) := ''; v_event_id number;

BEGIN

for c in c_evento
loop

    begin

        v_TOT_ADULTI := 0;
        v_TOT_KINDER := 0;
        v_TOT_BABY := 0;                                  
        v_TOT_STAFF := 0;
        v_TOT_INVITATI  := 0;
        v_angoli := 0;            
        v_NOTE_ADULTI  := '';
        v_NOTE_KINDER  := '';
        v_NOTE_BABY    := '';
        v_NOTE_STAFF   := '';

        v_cliente_email      := c.cliente_email;
        v_cliente_tel        := c.cliente_tel;
        v_referente_tel      := c.referente_tel;
        v_distanza_location  := c.distanza_location;
        v_buffet_iniziale    := c.buffet_iniziale;
        v_buffet_finale      := c.buffet_finale;
        v_primi              := c.primi;
        v_secondi            := c.secondi;
        v_vini               := c.vini;
        v_extra_costi        := c.extra_costi;
        v_event_id           := c.id;

    --ospiti
    select nvl(sum(o.NUMERO),0)
      into v_TOT_ADULTI
      from eventi e
      join eventi_det_ospiti o on e.id = o.id_evento 
      --join tb_tipi_ospiti tos on o.cod_tipo_ospite = tos.COD_TIPO
     where e.id = c.id
       and o.cod_tipo_ospite = 8; -- adulti

    begin
    select o.NOTE
      into v_NOTE_ADULTI
      from eventi e
      join eventi_det_ospiti o on e.id = o.id_evento 
     where e.id = c.id
       and o.cod_tipo_ospite = 8; -- adulti

    exception when no_data_found then null;
    end;

    select nvl(sum(o.NUMERO),0)
      into v_TOT_KINDER
      from eventi e
      join eventi_det_ospiti o on e.id = o.id_evento 
      --join tb_tipi_ospiti tos on o.cod_tipo_ospite = tos.COD_TIPO
     where e.id = c.id
       and o.cod_tipo_ospite = 5;   --Kinder

    begin
    select o.NOTE
      into v_NOTE_KINDER
      from eventi e
      join eventi_det_ospiti o on e.id = o.id_evento 
     where e.id = c.id
       and o.cod_tipo_ospite = 5;   --Kinder

    exception when no_data_found then null;
    end;

    select nvl(sum(o.NUMERO),0)
      into v_TOT_BABY
      from eventi e
      join eventi_det_ospiti o on e.id = o.id_evento 
      --join tb_tipi_ospiti tos on o.cod_tipo_ospite = tos.COD_TIPO
     where e.id = c.id
       and o.cod_tipo_ospite = 6; --    Baby

    begin
    select o.NOTE
      into v_NOTE_BABY
      from eventi e
      join eventi_det_ospiti o on e.id = o.id_evento 
     where e.id = c.id
       and o.cod_tipo_ospite = 6; --    Baby

    exception when no_data_found then null;
    end;

    select nvl(sum(o.NUMERO),0)
      into v_TOT_STAFF
      from eventi e
      join eventi_det_ospiti o on e.id = o.id_evento 
      --join tb_tipi_ospiti tos on o.cod_tipo_ospite = tos.COD_TIPO
     where e.id = c.id
       and o.cod_tipo_ospite = 7; --    Staff

    begin
    select o.NOTE
      into v_NOTE_STAFF
      from eventi e
      join eventi_det_ospiti o on e.id = o.id_evento 
     where e.id = c.id
       and o.cod_tipo_ospite = 7; --    Staff

    exception when no_data_found then null;
    end;

    select nvl(e.tot_ospiti,0)
      into v_TOT_INVITATI
      from eventi e        
     where e.id = c.id;

    --angoli "speciali"
    v_angoli := '';
    for a in (  select trim(substr(a.descrizione || ' - ' || p.note,1,1000)) descrizione from eventi e
                  join eventi_det_prel p on e.id=p.id_evento  
                  join articoli a on p.cod_articolo=a.cod_articolo 
                 where a.flg_cucina = 1
                   and e.id = c.id
                )
    loop
        v_angoli :=  a.descrizione || ', ' || v_angoli ;               
    end loop;

    PIPE ROW(t_rep_cucina_row(  c.data,c.location,c.cliente,
                                c.DESCRIZIONE,
                                to_char(c.ORA_CERIMONIA,'HH24:MI'), 
                                to_char(c.ORA_EVENTO,'HH24:MI'),                                    
                                v_TOT_ADULTI ,
                                v_TOT_KINDER      ,
                                v_TOT_BABY        ,                                    
                                v_TOT_STAFF        ,  
                                v_TOT_INVITATI    ,
                                c.ALLERGIE        ,
                                c.TORTA        ,
                                c.CONFETTATA      ,
                                c.STAMPA_MENU   ,
                                v_angoli,
                                c.extra_info ,

                                v_NOTE_ADULTI     ,
                                v_NOTE_KINDER     ,
                                v_NOTE_BABY       ,
                                v_NOTE_STAFF      ,
                                v_cliente_email      ,
                                v_cliente_tel     ,
                                v_referente_tel   ,
                                v_distanza_location ,
                                v_buffet_iniziale  ,
                                v_buffet_finale    ,
                                v_primi            ,
                                v_secondi          ,
                                v_vini             ,
                                v_extra_costi      ,
                                v_event_id
                             ));

    --exception when others
     --   then null;

    exception when others
                then
                    RAISE_APPLICATION_ERROR(-20000, 'Errore: ' || SQLCODE || ' - ' || SUBSTR(SQLERRM, 1 , 64));

    end;

end loop;

RETURN;

END;```