--------------------------------------------------------
-- View-uri pentru ROAAUTO v 1.4.151                  --
-- Created by marius.atanasiu on 2/2/2006, 9:43:41 AM --
--------------------------------------------------------

spool viewuri.log

prompt
prompt Creating view DEV_VORDL_FACTURATE
prompt =================================
prompt
create or replace view dev_vordl_facturate as
select distinct b.id_lucrare,
                max(b.dataact) keep(dense_rank first order by b.id_set desc) over(partition by b.id_lucrare) as dataact,
                max(b.nract) keep(dense_rank first order by b.id_set desc, b.dataact desc) over(partition by b.id_lucrare) as nract,
                max(case
                      when b.id_set in (31003, 31004, 31005, 31011, 31012) then
                       1
                      else
                       0
                    end) over(partition by b.id_lucrare) as facturat
  from mv_ordl_sume_act b
 where extract(month from b.dataact) + extract(year from b.dataact) * 12 <=
       pack_sesiune.getluna() +
       pack_sesiune.getAn() * 12
/

prompt
prompt Creating view DEV_VORDL_FACTURI
prompt ===============================
prompt
create or replace view dev_vordl_facturi as
select a.id_lucrare,
       (case
         when pack_sesiune.getAn() * 12 +
              pack_sesiune.getLuna() >=
              pack_sesiune.GET_ANRON() * 12 +
              pack_sesiune.GET_LUNARON() then
          NVL(b.manopera_ron + b.materiale_ron + b.tva_ron, -1.000)
         else
          NVL(b.manopera_rol + b.materiale_rol + b.tva_rol, -1.000)
       end) as valctva,
       a.dataact,
       a.nract,
       a.facturat
  from dev_vordl_facturate a
  left join mv_ordl_sume_act b on a.nract = b.nract
                              and a.id_lucrare = b.id_lucrare
                              and a.dataact = b.dataact
/

prompt
prompt Creating view DEV_COMENZI_VALIDATE
prompt ==================================
prompt
create or replace view dev_comenzi_validate as
select a.id_ordl,
       a.id_lucrare,
       a.id_masiniclient,
       a.id_tip,
       a.datai,
       a.id_inspector,
       a.id_asigurator,
       (case
         when extract(month from a.dataoravalid) +
              extract(year from a.dataoravalid) * 12 <=
              pack_sesiune.getluna() +
              pack_sesiune.getan() * 12 then
          1
         else
          0
       end) as validat,
       (case
         when extract(month from a.dataoravalid) +
              extract(year from a.dataoravalid) * 12 <=
              pack_sesiune.getluna() +
              pack_sesiune.getan() * 12 then
          a.dataoravalid
         else
          null
       end) as dataoravalid,
       (case
         when extract(month from a.dataoravalid) +
              extract(year from a.dataoravalid) * 12 <=
              pack_sesiune.getluna() +
              pack_sesiune.getan() * 12 then
          b.utilizator
         else
          null
       end) as util_valid,
       c.nrord
  from dev_ordl a
  left join syn_utilizatori b on a.id_util_valid = b.id_util
  left join nom_lucrari c on a.id_lucrare = c.id_lucrare
 where a.sters = 0
/

prompt
prompt Creating view DEV_ISTORIC_COMENZI
prompt =================================
prompt
create or replace view dev_istoric_comenzi as
select a.id_ordl,
       a.id_lucrare,
       a.id_masiniclient,
       a.id_tip,
       a.datai,
       nvl(a.validat, 0) as validat,
       a.dataoravalid,
       a.util_valid,
       a.nrord,
       nvl(c.facturat, 0) as facturat,
       c.dataact as datafact,
       nvl(c.nract, 0) as nrfact,
       d.id_partener,
       d.nrinmat,
       b.masina,
       b1.marca,
       e.nume,
       g.asigurator,
       h.inspector,
       i.denumire as tip_comanda
  from dev_comenzi_validate a
  left join dev_vordl_facturi c on a.id_lucrare = c.id_lucrare
  left join dev_masiniclienti d on a.id_masiniclient = d.id_masiniclient
  left join dev_nom_masini b on d.id_masina = b.id_masina
  left join dev_nom_marci b1 on b.id_marca = b1.id_marca
  left join nom_parteneri e on d.id_partener = e.id_part
  left join dev_nom_asiguratori g on a.id_asigurator = g.id_asigurator
  left join dev_nom_inspectori h on a.id_inspector = h.id_inspector
  left join dev_tip_deviz i on a.id_tip = i.id_tip
/

prompt
prompt Creating view DEV_ANALIZA_MANASIG
prompt =================================
prompt
create or replace view dev_analiza_manasig as
Select 'GARANTIE' As tip,
       NVL(a.asigurator, 'FARA ASIGURATOR') as asig,
       last_day(to_date(a.dataoravalid)) as luna,
       Nvl(Sum(round(b.timpn, 3)), 0) As timp_n
  From dev_istoric_comenzi a
  Left Join dev_oper b On a.id_ordl = b.id_ordl
 Where a.validat = 1
   and a.id_tip = 2
   and b.sters = 0
 Group By a.asigurator, last_day(to_date(a.dataoravalid))
Union all
Select 'REGIE' As tip,
       NVL(a.asigurator, 'FARA ASIGURATOR') as asig,
       last_day(to_date(a.dataoravalid)) as luna,
       Nvl(Round(Sum(b.timpn), 3), 0) As timp_n
  From dev_istoric_comenzi a
  Left Join dev_oper b On a.id_ordl = b.id_ordl
 Where a.Validat = 1
   And a.id_tip > 2
   and b.sters = 0
 Group By a.asigurator, last_day(to_date(a.dataoravalid))
Union all
Select 'POST GARANTIE' As tip,
       NVL(a.asigurator, 'FARA ASIGURATOR') as asig,
       last_day(to_date(a.datafact)) as luna,
       Nvl(Round(Sum(b.timpn), 3), 0) As timp_n
  From dev_istoric_comenzi a
  Left Join dev_oper b On a.id_ordl = b.id_ordl
 Where a.facturat = 1
   and b.sters = 0
 Group By a.asigurator, last_day(to_date(a.datafact))
/

prompt
prompt Creating view DEV_VORDL
prompt =======================
prompt
create or replace view dev_vordl as
select o.*,p.nume,p.cod_fiscal,p.adresa,p.telefon,p.banca,p.cont_banca,p.reg_comert,
l.nrord,
m.nrinmat,m.series,m.seriem,
asig.asigurator,
mar.marca,mas.masina,ins.inspector,ut.utilizator as util_valid,k.denumire as tip_comanda
    from dev_ordl o
    left join dev_masiniclienti m on o.id_masiniclient = m.id_masiniclient
    left join nom_parteneri p on m.id_partener = p.id_part
    left join nom_lucrari l on o.id_lucrare = l.id_lucrare
    left join dev_nom_asiguratori asig on o.id_asigurator = asig.id_asigurator
    left join dev_nom_masini mas on m.id_masina = mas.id_masina
    left join dev_nom_marci mar on mas.id_marca = mar.id_marca
    left join dev_nom_inspectori ins on o.id_inspector = ins.id_inspector
    left join dev_tip_deviz k on o.id_tip=k.id_tip
    left join syn_vutilizatori ut on o.id_util_valid=ut.id_util
    where o.sters = 0
/

prompt
prompt Creating view DEV_DETALII_COMENZI
prompt =================================
prompt
create or replace view dev_detalii_comenzi as
select a.id_ordl,a.validat,a.dataoravalid,a.id_tip,a.tip_comanda,
nvl(b.facturat,0) as facturat,b.dataact as datafact,nvl(b.nract,0) as nrfact
from dev_vordl a
left join dev_vordl_facturi b on a.id_lucrare=b.id_lucrare
/

prompt
prompt Creating view DEV_ANALIZA_SALARII
prompt =================================
prompt
create or replace view dev_analiza_salarii as
select a.id_ordl,
       a.id_tip,
       (case
         when pack_sesiune.getAn() * 12 +
              pack_sesiune.getLuna() <
              pack_sesiune.GET_ANRON() * 12 +
              pack_sesiune.GET_LUNARON() then
          b.pret
         else
          (case b.nou
         when 0 then
          round(b.pret / 10000, 2)
         else
          b.pret
       end) end) as pret,
       c.ore,
       d.id_mecanic,
       e.nume,
       e.prenume
  from dev_detalii_comenzi a
  left join dev_oper b on a.id_ordl = b.id_ordl
  left join dev_oper_mecanici c on b.id_oper = c.id_oper
  left join dev_mecanici d on c.id_mecanic = d.id_mecanic
  left join sal_personal e on d.id_salariat = e.id_salariat
 where b.sters = 0
   and ((a.id_tip = 1 and
       (a.facturat = 1 and (extract(month from a.datafact) =
       pack_sesiune.getluna() and
       extract(year from a.datafact) =
       pack_sesiune.getan()))) or
       (a.id_tip > 1 and
       (a.validat = 1 and (extract(month from a.dataoravalid) =
       pack_sesiune.getluna() and
       extract(year from a.dataoravalid) =
       pack_sesiune.getan()))))
/

prompt
prompt Creating view DEV_ANALIZA_SALARII_REG
prompt =====================================
prompt
create or replace view dev_analiza_salarii_reg as
select distinct id_mecanic,nume||' '||prenume as nume,
sum(case when id_tip=1 then ore else 0 end) over (partition by id_mecanic) as ore,
sum(case when id_tip=1 then round(pret*ore,2) else 0 end) over (partition by id_mecanic) as manopera,
sum(case when id_tip!=1 then ore else 0 end) over (partition by id_mecanic) as ore_reg,
sum(case when id_tip!=1 then round(pret*ore,2) else 0 end) over (partition by id_mecanic) as manopera_reg
from dev_analiza_salarii
/

prompt
prompt Creating view DEV_DATE_SUPLIMENTARE
prompt ===================================
prompt
create or replace view dev_date_suplimentare as
select a.id_ordl,a.kmint,a.termen,b.asigurator,c.inspector,d.id_partener,d.series,e.masina,f.marca
from dev_ordl a
left join dev_nom_asiguratori b on a.id_asigurator=b.id_asigurator
left join dev_nom_inspectori c on a.id_inspector=c.id_inspector
left join dev_masiniclienti d on a.id_masiniclient=d.id_masiniclient
left join dev_nom_masini e on d.id_masina=e.id_masina
left join dev_nom_marci f on e.id_marca=f.id_marca
where a.sters=0
/

prompt
prompt Creating view DEV_DATE_SUPLIMENTARE_RAP
prompt =======================================
prompt
create or replace view dev_date_suplimentare_rap as
select a.id_ordl,a.termen,a.kmint,
b.asigurator,
c.inspector,
d.seriem,d.nrinmat,d.series,d.nrachi,d.dataachi,
e.masina,
f.marca,
g.telefon,g.cod_fiscal,g.adresa,
h.denumire as furnizor
from dev_ordl a
left join dev_nom_asiguratori b on a.id_asigurator=b.id_asigurator
left join dev_nom_inspectori c on a.id_inspector=c.id_inspector
left join dev_masiniclienti d on a.id_masiniclient=d.id_masiniclient
left join dev_nom_masini e on d.id_masina=e.id_masina
left join dev_nom_marci f on e.id_marca=f.id_marca
left join nom_parteneri g on d.id_partener=g.id_part
left join dev_nom_furnizorimasini h on d.id_furnizor=h.id_furnizor
/

prompt
prompt Creating view DEV_NORMARE_COMENZI
prompt =================================
prompt
create or replace view dev_normare_comenzi as
select a.id_ordl,a.id_lucrare,a.id_tip,a.datai,a.id_inspector,a.id_asigurator,
nvl(a.validat,0) as validat,a.dataoravalid,a.nrord,a.id_masiniclient,
nvl(b.facturat,0) as facturat,b.dataact as datafact,b.nract as nrfact,
d.nrinmat,
e.nume,
i.denumire as tip_comanda
from dev_comenzi_validate a
left join dev_vordl_facturi b on a.id_lucrare=b.id_lucrare
left join dev_masiniclienti d on a.id_masiniclient=d.id_masiniclient
left join nom_parteneri e on d.id_partener=e.id_part
left join dev_tip_deviz i on a.id_tip=i.id_tip
/

prompt
prompt Creating view DEV_FACTURI_ASIG
prompt ==============================
prompt
create or replace view dev_facturi_asig as
select a.nrord,a.datai,a.nume,c.asigurator,
		b.nract,b.dataact,
    (case
 when pack_sesiune.getAn()*12+pack_sesiune.getLuna()>=pack_sesiune.GET_ANRON()*12+pack_sesiune.GET_LUNARON()
 then
   b.manopera_ron
 else
   b.manopera_rol end)
    as manopera,
   (case
 when pack_sesiune.getAn()*12+pack_sesiune.getLuna()>=pack_sesiune.GET_ANRON()*12+pack_sesiune.GET_LUNARON()
 then
   b.materiale_ron
 else
   b.materiale_rol end) as materiale,
   (case
 when pack_sesiune.getAn()*12+pack_sesiune.getLuna()>=pack_sesiune.GET_ANRON()*12+pack_sesiune.GET_LUNARON()
 then
   b.manopera_ron+b.materiale_ron+b.tva_ron
 else
   b.manopera_rol+b.materiale_rol+b.tva_rol end)
   as valctva
from dev_normare_comenzi a
join mv_ordl_sume_act b on a.id_lucrare=b.id_lucrare
left join dev_nom_asiguratori c on a.id_asigurator=c.id_asigurator
where a.id_asigurator<>0
order by c.asigurator,b.dataact
/

prompt
prompt Creating view DEV_FACTURI_CLIENTI
prompt =================================
prompt
create or replace view dev_facturi_clienti as
select a.nrord,a.datai,d.nume,d.telefon,
		b.nract,b.dataact,
    (case
 when pack_sesiune.getAn()*12+pack_sesiune.getLuna()>=pack_sesiune.GET_ANRON()*12+pack_sesiune.GET_LUNARON()
 then b.manopera_ron
 else
   b.manopera_rol end)
    as manopera,
   (case
 when pack_sesiune.getAn()*12+pack_sesiune.getLuna()>=pack_sesiune.GET_ANRON()*12+pack_sesiune.GET_LUNARON()
 then
   b.materiale_ron
 else
   b.materiale_rol end) as materiale,
   (case
 when pack_sesiune.getAn()*12+pack_sesiune.getLuna()>=pack_sesiune.GET_ANRON()*12+pack_sesiune.GET_LUNARON()
 then
   b.manopera_ron+b.materiale_ron+b.tva_ron
 else
   b.manopera_rol+b.materiale_rol+b.tva_rol end)
   as valctva
from dev_normare_comenzi a
join mv_ordl_sume_act b on a.id_lucrare=b.id_lucrare
left join dev_masiniclienti c on a.id_masiniclient=c.id_masiniclient
left join nom_parteneri d on c.id_partener=d.id_part
order by b.dataact
/

prompt
prompt Creating view DEV_VORDL_MAN
prompt ===========================
prompt
create or replace view dev_vordl_man as
select a.id_ordl,
       sum((case
             when pack_sesiune.getAn() * 12 +
                  pack_sesiune.getLuna() >=
                  pack_sesiune.GET_ANRON() * 12 +
                  pack_sesiune.GET_LUNARON() then
              a.manopera_ron
             else
              a.manopera_rol
           end)) as manopera
  from mv_ordl_man a
 where a.luni <= pack_sesiune.getluna() +
       pack_sesiune.getan() * 12
 group by a.id_ordl
/

prompt
prompt Creating view DEV_VORDL_MAT
prompt ===========================
prompt
create or replace view dev_vordl_mat as
select a.id_lucrare,
       sum((case
             when pack_sesiune.getAn() * 12 +
                  pack_sesiune.getLuna() >=
                  pack_sesiune.GET_ANRON() * 12 +
                  pack_sesiune.GET_LUNARON() then
              a.materiale_ron
             else
              a.materiale_rol
           end)) as materiale
  from mv_ordl_mat a
 where a.luni <= pack_sesiune.getluna() +
       pack_sesiune.getan() * 12
 group by a.id_lucrare
/

prompt
prompt Creating view DEV_FACTURI_EMISE
prompt ===============================
prompt
create or replace view dev_facturi_emise as
select row_number() over(partition by a.nrord order by a.datai, a.nrord) as nrcrt,
       a.dataoravalid,a.datafact,a.validat,a.facturat,e.inspector,f.asigurator,a.id_tip,
       a.nrord,
       a.datai,
       d.nume,
       b.nract,
       b.dataact,
       NVL(a1.manopera,0) as manopera,
       NVL(a2.materiale,0) as materiale,
       a.nrinmat,
       (case
         when pack_sesiune.getAn() * 12 +
              pack_sesiune.getLuna() >=
              pack_sesiune.GET_ANRON() * 12 +
              pack_sesiune.GET_LUNARON() then
          b.manopera_ron + b.materiale_ron + b.tva_ron
         else
          b.manopera_rol + b.materiale_rol + b.tva_rol
       end) as valctva
  from dev_normare_comenzi a
  join mv_ordl_sume_act b on a.id_lucrare = b.id_lucrare
  left join dev_vordl_man a1 on a.id_ordl = a1.id_ordl
  left join dev_vordl_mat a2 on a.id_lucrare = a2.id_lucrare
  left join dev_masiniclienti c on a.id_masiniclient = c.id_masiniclient
  left join nom_parteneri d on c.id_partener = d.id_part
  left join dev_nom_inspectori e on a.id_inspector = e.id_inspector
  left join dev_nom_asiguratori f on a.id_asigurator = f.id_asigurator
 order by b.dataact
/

prompt
prompt Creating view DEV_FACTURI_TOATE
prompt ===============================
prompt
create or replace view dev_facturi_toate as
select a.nrord,a.datai,a.nume,c.asigurator,
		b.nract,b.dataact,
    (case
 when pack_sesiune.getAn()*12+pack_sesiune.getLuna()>=pack_sesiune.GET_ANRON()*12+pack_sesiune.GET_LUNARON()
 then
   b.manopera_ron
 else
   b.manopera_rol end)
    as manopera,
   (case
 when pack_sesiune.getAn()*12+pack_sesiune.getLuna()>=pack_sesiune.GET_ANRON()*12+pack_sesiune.GET_LUNARON()
 then
   b.materiale_ron
 else
   b.materiale_rol end) as materiale,
   (case
 when pack_sesiune.getAn()*12+pack_sesiune.getLuna()>=pack_sesiune.GET_ANRON()*12+pack_sesiune.GET_LUNARON()
 then
   b.manopera_ron+b.materiale_ron+b.tva_ron
 else
   b.manopera_rol+b.materiale_rol+b.tva_rol end)
   as valctva
from dev_normare_comenzi a
join mv_ordl_sume_act b on a.id_lucrare=b.id_lucrare
left join dev_nom_asiguratori c on a.id_asigurator=c.id_asigurator
order by c.asigurator,b.dataact
/

prompt
prompt Creating view DEV_VOPER_MECANICI
prompt ================================
prompt
create or replace view dev_voper_mecanici as
select a.id_opermecanic,
       a.id_oper,
       a.ore,
       a.inactiv,
       a.id_mecanic,
       c.nume,
       c.prenume,
       c.marca,
       c.id_salariat,
       d.sectie
  from dev_oper_mecanici a
  left join dev_mecanici b on a.id_mecanic = b.id_mecanic
  left join sal_personal c on b.id_salariat = c.id_salariat
  left join nom_sectii d on b.id_sectie = d.id_sectie
 where a.sters = 0
/

prompt
prompt Creating view DEV_VOPER_PRETURI
prompt ===============================
prompt
create or replace view dev_voper_preturi as
select op.timpn,
       op.id_ordl,
       op.id_oper,
       op.dataora,
       op.datai,
       (case
         when pack_sesiune.getAn() * 12 +
              pack_sesiune.getLuna() <
              pack_sesiune.GET_ANRON() * 12 +
              pack_sesiune.GET_LUNARON() then
          op.pret
         else
          (case op.nou
         when 0 then
          round(op.pret / 10000, 2)
         else
          op.pret
       end) end) as pret,
       op.validat,
       n.denop
  from dev_oper op
  left join dev_nom_norme n on op.id_norme = n.id_norme
 where op.sters = 0
/

prompt
prompt Creating view DEV_LISTARE_MAN_TOT_COM
prompt =====================================
prompt
create or replace view dev_listare_man_tot_com as
select sum(d.ore) as ore,
       d.id_mecanic,
       sum(round(c.pret * d.ore, 2)) as valoare,
       d.nume,
       d.prenume,
       a.nrord,
       a.datai,
       d.sectie
  from dev_comenzi_validate a
  left join dev_vordl_facturi b on a.id_lucrare = b.id_lucrare
  left join dev_voper_preturi c on a.id_ordl = c.id_ordl
  left join dev_voper_mecanici d on c.id_oper = d.id_oper
 where (extract(month from a.dataoravalid) =
       pack_sesiune.getluna() and
       extract(year from a.dataoravalid) =
       pack_sesiune.getan() and a.validat=1 and a.id_tip > 1)
    or (extract(month from b.dataact) =
       pack_sesiune.getluna() and
       extract(year from b.dataact) =
       pack_sesiune.getan() and a.id_tip = 1 and
       b.facturat = 1)
 group by a.id_ordl,
          a.nrord,
          d.id_mecanic,
          d.nume,
          d.prenume,
          a.datai,
          d.sectie
 order by d.id_mecanic
/

prompt
prompt Creating view DEV_LISTARE_MAN_TOT_DESF
prompt ======================================
prompt
create or replace view dev_listare_man_tot_desf as
select d.id_opermecanic,
       d.id_oper,
       d.ore,
       d.inactiv,
       d.id_mecanic,
       d.nume,
       d.prenume,
       d.marca,
       d.id_salariat,
       d.sectie,
       a.id_ordl,
       c.pret,
       a.datai,
       b.nract as nract,
       b.dataact as datafact,
       c.denop,
       c.timpn,
       a.nrord
  from dev_comenzi_validate a
  left join dev_vordl_facturi b on a.id_lucrare = b.id_lucrare
  left join dev_voper_preturi c on a.id_ordl = c.id_ordl
  left join dev_voper_mecanici d on c.id_oper = d.id_oper
 where (extract(month from a.dataoravalid) =
       pack_sesiune.getluna() and
       extract(year from a.dataoravalid) =
       pack_sesiune.getan() and a.validat=1 and a.id_tip > 1)
    or (extract(month from b.dataact) =
       pack_sesiune.getluna() and
       extract(year from b.dataact) =
       pack_sesiune.getan() and a.id_tip = 1 and
       b.facturat = 1)
 order by id_mecanic
/

prompt
prompt Creating view DEV_ORDL_FACTURARE
prompt ================================
prompt
create or replace view dev_ordl_facturare as
select a.id_ordl,a.id_lucrare,a.datai,a.id_masiniclient,
b.nrord,
c.id_partener,c.nrinmat,
d.nume,
e.masina,
f.marca
from dev_ordl a
left join nom_lucrari b on a.id_lucrare=b.id_lucrare
left join dev_masiniclienti c on a.id_masiniclient=c.id_masiniclient
left join nom_parteneri d on c.id_partener=d.id_part
left join dev_nom_masini e on c.id_masina=e.id_masina
left join dev_nom_marci f on e.id_marca=f.id_marca
where a.sters=0
/

prompt
prompt Creating view DEV_VALIDARE_COMENZI
prompt ==================================
prompt
create or replace view dev_validare_comenzi as
select a.id_ordl,
       a.id_lucrare,
       a.id_masiniclient,
       a.id_tip,
       a.datai,
       nvl(a.validat, 0) as validat,
       a.dataoravalid,
       a.util_valid,
       a.nrord,
       nvl(b.manopera, 0) as manopera,
       nvl(b1.materiale, 0) as materiale,
       nvl(c.facturat, 0) as facturat,
       c.dataact as datafact,
       nvl(c.nract, 0) as nrfact,
       c.valctva,
       d.id_partener,
       d.nrinmat,
       e.nume,
       g.asigurator,
       h.inspector,
       i.denumire as tip_comanda
  from dev_comenzi_validate a
  left join dev_vordl_man b on a.id_ordl = b.id_ordl
  left join dev_vordl_mat b1 on a.id_lucrare = b1.id_lucrare
  left join dev_vordl_facturi c on a.id_lucrare = c.id_lucrare
  left join dev_masiniclienti d on a.id_masiniclient = d.id_masiniclient
  left join nom_parteneri e on d.id_partener = e.id_part
  left join dev_nom_asiguratori g on a.id_asigurator = g.id_asigurator
  left join dev_nom_inspectori h on a.id_inspector = h.id_inspector
  left join dev_tip_deviz i on a.id_tip = i.id_tip
 order by a.datai, a.nrord
/

prompt
prompt Creating view DEV_VANSAMBLE
prompt ===========================
prompt
create or replace view dev_vansamble as
select a.*    from dev_nom_ansamble a where a.sters = 0
/

prompt
prompt Creating view DEV_VASIGURATORI
prompt ==============================
prompt
create or replace view dev_vasiguratori as
select a.*    from dev_nom_asiguratori a    where a.sters = 0
/

prompt
prompt Creating view DEV_VDELEGATI
prompt ===========================
prompt
create or replace view dev_vdelegati as
select d.*,p.nume,p.cod_fiscal    from dev_nom_delegati d    left join nom_parteneri p on d.id_partener = p.id_part where d.sters = 0
/

prompt
prompt Creating view DEV_VFURNIZORI
prompt ============================
prompt
create or replace view dev_vfurnizori as
select f.*    from dev_nom_furnizorimasini f where f.sters = 0
/

prompt
prompt Creating view DEV_VINSPECTORI
prompt =============================
prompt
create or replace view dev_vinspectori as
select i.*    from dev_nom_inspectori i where i.sters = 0
/

prompt
prompt Creating view DEV_VMARCI
prompt ========================
prompt
create or replace view dev_vmarci as
select m.*    from dev_nom_marci m where m.sters = 0
/

prompt
prompt Creating view DEV_VMASINI
prompt =========================
prompt
create or replace view dev_vmasini as
select m.*,s.marca    from dev_nom_masini m    left join dev_nom_marci s on m.id_marca = s.id_marca    where m.sters = 0
/

prompt
prompt Creating view DEV_VMASINICLIENTI
prompt ================================
prompt
create or replace view dev_vmasiniclienti as
select mc.*,tm.denumire as tip_motor,m.id_marca,fm.denumire as furnizor,mm.marca,m.masina,p.nume as partener
  from dev_masiniclienti mc
    left join dev_tipuri_motoare tm on mc.id_tipmotor = tm.id_tipmotor
    left join dev_nom_furnizorimasini fm on mc.id_furnizor = fm.id_furnizor
    left join dev_nom_masini m on mc.id_masina = m.id_masina
      left join dev_nom_marci mm on m.id_marca = mm.id_marca
    left join nom_parteneri p on mc.id_partener = p.id_part
  where mc.sters = 0
/

prompt
prompt Creating view DEV_VMECANICI
prompt ===========================
prompt
create or replace view dev_vmecanici as
select m.*,s.sectie,p.nume,p.prenume,p.marca    from dev_mecanici m   left join nom_sectii s on m.id_sectie = s.id_sectie   left join sal_personal p on m.id_salariat = p.id_salariat where m.sters = 0
/

prompt
prompt Creating view DEV_VNOM_MASINI
prompt =============================
prompt
create or replace view dev_vnom_masini as
select m.*    from dev_nom_masini m where m.sters = 0
/

prompt
prompt Creating view DEV_VNOM_RESP
prompt ===========================
prompt
create or replace view dev_vnom_resp as
select "ID_RESP","NUME","BI","CNPRESP","ALES","STERS"
    from dev_nom_resp where sters = 0
/

prompt
prompt Creating view DEV_VNORME
prompt ========================
prompt
create or replace view dev_vnorme as
select n.*,a.denumire as ansamblu,m.masina,mar.marca from dev_nom_norme n left join dev_nom_ansamble a on n.id_ansamblu = a.id_ansamblu    left join dev_nom_masini m on n.id_masina = m.id_masina    left join dev_nom_marci mar on m.id_marca = mar.id_marca    where n.sters = 0
/

prompt
prompt Creating view DEV_VOPER
prompt =======================
prompt
create or replace view dev_voper as
select op.timpn,
       op.id_ordl,
       op.id_oper,
       (case
         when pack_sesiune.getAn() * 12 +
              pack_sesiune.getLuna() >=
              extract(year from op.dataora) * 12 +
              extract(month from op.dataora) then
          op.dataora
         else
          null
       end) as dataora,
       op.id_sectie,
       op.datai,
       (case
         when pack_sesiune.getAn() * 12 +
              pack_sesiune.getLuna() <
              pack_sesiune.GET_ANRON() * 12 +
              pack_sesiune.GET_LUNARON() then
          op.pret
         else
          (case op.nou
         when 0 then
          round(op.pret / 10000, 2)
         else
          op.pret
       end) end) as pret,
       (case
         when pack_sesiune.getAn() * 12 +
              pack_sesiune.getLuna() >=
              extract(year from op.dataora) * 12 +
              extract(month from op.dataora) then
          op.validat
         else
          0
       end) as validat,
       op.nou,
       n.denop,
       n.timpn as timp_nom,
       n.codop,
       a.denumire as ansamblu,
       m.masina,
       s.sectie,
       s.nsectie,
       (case
         when pack_sesiune.getAn() * 12 +
              pack_sesiune.getLuna() >=
              extract(year from op.dataora) * 12 +
              extract(month from op.dataora) then
          ut.utilizator
         else
          null
       end) as util
  from dev_oper op
  left join dev_nom_norme n on op.id_norme = n.id_norme
  left join dev_nom_ansamble a on n.id_ansamblu = a.id_ansamblu
  left join dev_nom_masini m on n.id_masina = m.id_masina
  left join nom_sectii s on op.id_sectie = s.id_sectie
  left join syn_utilizatori ut on op.id_util = ut.id_util
 where op.sters = 0
/

prompt
prompt Creating view DEV_VOPER_DETALII_M
prompt =================================
prompt
create or replace view dev_voper_detalii_m as
select a.id_opermecanic,a.id_oper,a.ore,a.id_mecanic,c.nume,c.prenume from dev_oper_mecanici a
left join dev_mecanici b on a.id_mecanic=b.id_mecanic
left join sal_personal c on b.id_salariat=c.id_salariat
where a.sters=0
/

prompt
prompt Creating view DEV_VOPER_SIMPLU
prompt ==============================
prompt
create or replace view dev_voper_simplu as
select op.timpn,
       op.id_ordl,
       op.id_oper,
       op.dataora,
       op.datai,
       op.id_sectie,
       op.validat,
       op.id_norme,
       s.sectie,
       s.nsectie
  from dev_oper op
  left join nom_sectii s on op.id_sectie = s.id_sectie
 where op.sters = 0
/

prompt
prompt Creating view DEV_VORDL_AVANSURI
prompt ================================
prompt
create or replace view dev_vordl_avansuri as
select a.id_lucrare,
(case
 when a.luna+a.an*12<
pack_sesiune.GET_LUNARON()+pack_sesiune.GET_ANRON()*12
and
pack_sesiune.getAn()*12+pack_sesiune.getLuna()>=
  pack_sesiune.GET_ANRON()*12+pack_sesiune.GET_LUNARON()
then a.suma/10000
else
a.suma end) as suma,a.scd,a.ascd,a.scc,a.ascc,a.id_partc,a.id_partd,a.id_sectie,
b.nume as partc,c.nume as partd,d.sectie from act a
left join nom_parteneri b on a.id_partc=b.id_part
left join nom_parteneri c on a.id_partd=c.id_part
left join nom_sectii d on a.id_sectie=d.id_sectie
where a.sters=0 and a.id_set in (31001,31002) and a.scd = '4111'
/

prompt
prompt Creating view DEV_VPRETURI
prompt ==========================
prompt
create or replace view dev_vpreturi as
select p.*,m.marca,a.asigurator,v.nume_val
    from dev_nom_preturi p
    left join dev_nom_marci m on p.id_marca = m.id_marca
    left join dev_nom_asiguratori a on p.id_asiguratori = a.id_asigurator
    left join nom_valute v on p.id_valuta = v.id_valuta
    where p.sters = 0
/


spool off
