PL/SQL Developer Test script 3.0
254
create or replace procedure actualizare_stoc_072010 (ID_FDOC act.id_fdoc%type) as
begin
    -- 20.04.2010 ANUNT Z ORA 24 ^

    lnAn       := extract(year from sysdate);
    lnLuna     := extract(month from sysdate);
    ldDataAct  := trunc(sysdate);
    ldDataIreg := trunc(sysdate);
    ldDataScad := trunc(sysdate);
    ldDataCurs := trunc(sysdate);

  
    pack_sesiune.setAn(lnAn);
    pack_sesiune.setLuna(lnLuna);

    lnIdFdoc             := tnIdFdoc;
        
  for item in (select distinct s.id_gestiune, g.nr_pag, g.id_sucursala, id_sectie, acont_adaos)
  from stoc s
  join nom_gestiuni g
    on s.id_Gestiune = g.id_gestiune
 where s.an = lnAn
   and s.luna = lnLuna
   and g.nr_pag in (6, 7)) loop
  
--1: 19% ----------------------------------------------------
--2: 24% PRETUL CU TVA CRESTE (PRETUL FARA TVA RAMANE LA FEL, TVA-UL CRESTE)
--3: 24% PRETUL CU TVA RAMANE LA FEL (PRETUL FARA TVA SCADE, TVA-UL CRESTE)
for item_act in 
(select id_gestiune, nr_pag, a.cont, a.acont, tip,
decode(tip, 1, '19 - original', 2, '24 - pret cu tva creste', 3, '24 - pret cu tva la fel') as explicatie,
decode (tip, 1, valoare_fara_tva_1, 2, valoare_fara_tva_2, valoare_fara_tva_3) as valoare_fara_tva,
decode (tip, 1, adaos_1, 2, adaos_2, adaos_3) as adaos,
decode (tip, 1, tva_1, 2, tva_2, tva_3) as tva
from
(SELECT a.id_gestiune, g.nr_pag, a.cont, a.acont,
  sum(pack_sesiune.calculeaza_total_fara_tva(pretv+tvav,0,1,0,0,cants+cant-cante,1,proc_tvav,2)) as valoare_fara_tva_1,
  sum(pack_sesiune.calculeaza_total_fara_tva(pretv+tvav,0,1,0,0,cants+cant-cante,1,proc_tvav,2) - 
  pack_sesiune.calculeaza_total_fara_tva(pret,0,1,0,0,cants+cant-cante,0,proc_tvav,2)) as adaos_1,
 sum(pack_sesiune.calculeaza_total_tva(pretv+tvav,0,1,0,0,cants+cant-cante,1,proc_tvav,2)) as tva_1,
    sum(pack_sesiune.calculeaza_total_fara_tva(pretv+tvav,0,1,0,0,cants+cant-cante,1,proc_tvav,2)) as valoare_fara_tva_2,
    sum(pack_sesiune.calculeaza_total_fara_tva(pretv+tvav,0,1,0,0,cants+cant-cante,1,proc_tvav,2) - 
    pack_sesiune.calculeaza_total_fara_tva(pret,0,1,0,0,cants+cant-cante,0,proc_tvav,2)) as  adaos_2,
  sum(pack_sesiune.calculeaza_total_tva(pretv,0,1,0,0,cants+cant-cante,0,1.24,2)) as tva_2,
sum(pack_sesiune.calculeaza_total_fara_tva(pretv+tvav,0,1,0,0,cants+cant-cante,1,1.24,2)) as valoare_fara_tva_3,
  sum(pack_sesiune.calculeaza_total_fara_tva(pretv+tvav,0,1,0,0,cants+cant-cante,1,1.24,2) -
    pack_sesiune.calculeaza_total_fara_tva(pret,0,1,0,0,cants+cant-cante,0,1.19,2)) as adaos_3,
  sum(pack_sesiune.calculeaza_total_tva(pretv+tvav,0,1,0,0,cants+cant-cante,1,1.24,2)) as tva_3       
  FROM stoc a join nom_gestiuni g on a.id_gestiune = g.id_gestiune
  where an = 2010 and luna = 6 and g.nr_pag in (6,7) and a.proc_tvav = 1.19  and a.cants+a.cant-a.cante <> 0 and id_gestiune = item.id_gestiune
  GROUP BY a.id_gestiune, g.nr_pag, a.cont, a.acont) s1, 
  (SELECT ROWNUM tip
FROM   ( SELECT 1 just_a_column
         FROM   dual
         CONNECT BY LEVEL <= 3
       )) s2 
order by nr_pag, id_gestiune, a.cont, a.acont, tip) loop

    insert into act_temp
    (luna, an, dataireg, nract, dataact, explicatia, scd, ascd, scc, ascc, suma, nnir, id_util, dataora, id_set, id_fact, id_partd, id_partc, id_sucursala, id_fdoc, sters, explicatia4, explicatia5, id_lucrare, id_gestin, id_gestout, id_valuta, proc_tva, id_ctr, id_jtva_coloana, serie_act)

    select lnLuna as luna, lnAn as an, ldDataIreg as dataireg, lnNrAct as nract, ldDataAct as dataact, 
    'ADAOS 19' AS explicatia, '371' AS scd, ascd, scc, ascc, suma, nnir, id_util, dataora, id_set, id_fact, id_partd, id_partc, id_sucursala, id_fdoc, sters, explicatia4, explicatia5, id_lucrare, id_gestin, id_gestout, id_valuta, proc_tva, id_ctr, id_jtva_coloana, serie_act

end loop;    
    insert into rul_temp
      (an,
       luna,
       cod,
       nnir,
       id_articol,
       id_gestiune,
       pret,
       pretv,
       tva,
       tvav,
       cant,
       cante,
       cont,
       dataact,
       pretd,
       id_util,
       dataora,
       pretvtva,
       acont,
       datain,
       dataout,
       proc_tva,
       proc_tvav,
       id_tip_rulaj,
       id_set,
       id_sucursala,
       id_rul_aux,
       nract,
       serie,
       id_valuta,
       serie_act,
       lot,
       adata_expirare,
       id_part_rez,
       id_lucrare_rez)
      select an,
             luna,
             lnCod as cod,
             lnNnir as nnir,
             id_articol,
             id_gestiune,
             pret,
             pretv,
             tva,
             tvav,
             0 as cant,
             cants + cant - cante as cante,
             cont,
             to_date('01072010', 'ddmmyyyy') as dataact,
             pretd,
             lnIdUtil as id_util,
             sysdate as dataora,
             pretv + tvav as pretvtva,
             acont,
             datain,
             dataout,
             proc_tvav as proc_tva,
             proc_tvav,
             lnIdTipRulaj as id_tip_rulaj,
             lnIdSet as id_set,
             id_sucursala,
             id_rul_aux,
             lnNrAct as nract,
             serie,
             id_valuta,
             null as serie_act,
             lot,
             adata_expirare,
             id_part_rez,
             id_lucrare_rez
        from stoc
       where an = lnAn
         and luna = lnLuna
         and proc_tvav = lnProcTva19
         and id_gestiune in
             (select id_Gestiune from nom_gestiuni where nr_pag in (6, 7));
  
    -- RULAJE 24%
    insert into rul_temp
      (an,
       luna,
       cod,
       nnir,
       id_articol,
       id_gestiune,
       pret,
       pretv,
       tva,
       tvav,
       cant,
       cante,
       cont,
       dataact,
       pretd,
       id_util,
       dataora,
       pretvtva,
       acont,
       datain,
       dataout,
       proc_tva,
       proc_tvav,
       id_tip_rulaj,
       id_set,
       id_sucursala,
       id_rul_aux,
       nract,
       serie,
       id_valuta,
       serie_act,
       lot,
       adata_expirare,
       id_part_rez,
       id_lucrare_rez)
      select an,
             luna,
             lnCod as cod,
             lnNnir as nnir,
             id_articol,
             id_gestiune,
             pret,
             CASE V_PRET_CU_TVA_IDENTIC
               WHEN 1 THEN
                pack_sesiune.calculeaza_pret_fara_tva(pretv + tvav,
                                                      1,
                                                      null,
                                                      lnProcTVA24,
                                                      1)
               ELSE
                PRETV
             END AS PRETV tva,
             CASE V_PRET_CU_TVA_IDENTIC
               WHEN 1 THEN
                pack_sesiune.calculeaza_pret_tva(pretv + tvav,
                                                 1,
                                                 null,
                                                 lnProcTVA24,
                                                 1)
               ELSE
                pack_sesiune.calculeaza_pret_tva(pretv,
                                                 1,
                                                 null,
                                                 lnProcTVA24,
                                                 0)
             END as tvav,
             cants + cant - cante as cant,
             0 as cante,
             cont,
             to_date('01072010', 'ddmmyyyy') as dataact,
             pretd,
             lnIdUtil as id_util,
             sysdate as dataora,
             pack_sesiune.calculeaza_pret_fara_tva(pretv + tvav,
                                                   1,
                                                   null,
                                                   lnProcTVA24,
                                                   1) +
             pack_sesiune.calculeaza_pret_tva(pretv + tvav,
                                              1,
                                              null,
                                              lnProcTVA24,
                                              1) as pretvtva,
             acont,
             datain,
             dataout,
             proc_tvav as proc_tva,
             lnProcTVA24 as proc_tvav,
             lnIdTipRulaj as id_tip_rulaj,
             lnIdSet as id_set,
             id_sucursala,
             id_rul_aux,
             lnNrAct as nract,
             serie,
             id_valuta,
             null as serie_act,
             lot,
             adata_expirare,
             id_part_rez,
             id_lucrare_rez
        from stoc
       where an = lnAn
         and luna = lnLuna
         and proc_tvav = lnProcTva19
         and id_gestiune in
             (select id_Gestiune from nom_gestiuni where nr_pag in (6, 7));
  
  end loop;
end;
0
0
