Files
zentral/docs/views/GET_COSTO_ART_BY_EVT.md
2025-11-28 10:59:10 +01:00

2.1 KiB

GET_COSTO_ART_BY_EVT

Colonne

Colonna Tipo
ID_EVENTO NUMBER
COD_ARTICOLO VARCHAR2(10)
COSTO_UNI NUMBER
NUMERO NUMBER
COSTO_CALC NUMBER
COSTO_CALC_IVA NUMBER

Definizione

CREATE OR REPLACE VIEW GET_COSTO_ART_BY_EVT AS
SELECT p.id_evento, ca.COD_ARTICOLO, nvl(p.COSTO_ARTICOLO, ca.costo_uni) as costo_uni,
(
    case when a.flg_qta_type = 'S' then nvl(qta_std_prel_tot, 0) else 1 end
    *
    case when a.flg_qta_type = 'C' then nvl(qta_coeff_prel_tot, 0) else 1 end
    *
    case when a.flg_qta_type = 'P' then nvl(qta_prec_prel_tot, 0) else 1 end
) as numero,
NVL(p.COSTO_ARTICOLO, ca.COSTO_UNI)
*
(
    case when a.flg_qta_type = 'S' then nvl(qta_std_prel_tot, 0) else 1 end
    *
    case when a.flg_qta_type = 'C' then nvl(qta_coeff_prel_tot, 0) else 1 end
    *
    case when a.flg_qta_type = 'P' then nvl(qta_prec_prel_tot, 0) else 1 end
) as costo_calc,
(NVL(p.COSTO_ARTICOLO, ca.COSTO_UNI)+NVL(p.COSTO_ARTICOLO, ca.COSTO_UNI)*(a.perc_iva/100))
*
(
    case when a.flg_qta_type = 'S' then nvl(qta_std_prel_tot, 0) else 1 end
    *
    case when a.flg_qta_type = 'C' then nvl(qta_coeff_prel_tot, 0) else 1 end
    *
    case when a.flg_qta_type = 'P' then nvl(qta_prec_prel_tot, 0) else 1 end
)
as costo_calc_iva
FROM ARTICOLI a
left JOIN COSTI_ARTICOLI ca ON a.COD_ARTICOLO = ca.COD_ARTICOLO
left join get_prel_art_tot p on a.cod_articolo = p.cod_articolo
left join eventi ed on ed.id = p.id_evento
left join eventi e on e.id = p.id_evento and e.data in (SELECT b.DATA_COSTO FROM COSTI_ARTICOLI b where b.cod_articolo = a.cod_articolo)
left join EVENTI_DET_OSPITI d on d.id_evento = nvl(e.id, ed.id) and d.cod_tipo_ospite = 8 -- adulti (se non trovo un evento per quel costo articolo lo devo ignorare)
WHERE (e.id is not null and ca.DATA_COSTO = nvl(e.data, (SELECT max(b.DATA_COSTO) FROM COSTI_ARTICOLI b where b.cod_articolo = a.cod_articolo)))
or (e.id is null and ca.cod_articolo is not null and ca.DATA_COSTO = nvl(e.data, (SELECT max(b.DATA_COSTO) FROM COSTI_ARTICOLI b where b.cod_articolo = a.cod_articolo)))