PL/SQL Developer Test script 3.0
307
create or replace procedure actualizare_stoc_072010 (V_PRET_CU_TVA_IDENTIC IN NUMBER DEFAULT 0) 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);

    select MAX(ID_FDOC) INTO lnIdFdoc 
           from nom_fdoc  
           where fel_document = 'NOTA' AND STERS = 0 AND INACTIV = 0;
lnNrAct = 201007010000;
lnNNir = 201007010000;

lnIdMonedaNationala := pack_def.GetIdMonedaNationala();
        
  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
  
lnNrAct = lnNrAct + 1;
lnNNir = lnNNir + 1;
--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 a.id_gestiune, g.nr_pag, a.cont, a.acont, apg.id_part, apg1.id_part as id_part378,
  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
  left join vasociere_parteneri_gestiuni apg on a.id_gestiune = apg.id_gestiune and a.cont = apg.cont
  left join vasociere_parteneri_gestiuni apg1 on a.id_gestiune = apg1.id_gestiune and apg1.cont = '378'
  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
order by nr_pag, id_gestiune, a.cont, a.acont, apg.id_part, apg1.id_part) loop

-- nr_pag = 7 -- nu sunt note contabile, suma = 0
IF item.nr_pag = 7 then
  -- 371 = 378 0
    insert into act_temp
    (luna, an, dataireg, nract, dataact, explicatia, scd, ascd, scc, ascc, suma, nnir, id_util, dataora, id_set, id_partd, id_partc, id_sucursala, id_fdoc, id_gestin, id_gestout, id_valuta, proc_tva)
    select lnLuna as luna, lnAn as an, ldDataIreg as dataireg, lnNrAct as nract, ldDataAct as dataact, 
    'ADAOS 19' AS explicatia, item_act.cont AS scd, item_act.acont as ascd, '378' as scc, item.acont_adaos as ascc, 
    0 as suma, lnNir as nnir, lnIdUtil as id_util, ldDataora as dataora, lnIdSet as id_set, 
    item_act.id_part as id_partd, item_act.id_part378 as id_partc, item.id_sucursala as id_sucursala, 
    lnIdFdoc as id_fdoc, item_act.id_gestiune as id_gestin, item_act.id_gestiune as id_gestout, 
    lnIdMonedaNationala as id_valuta, lnProcTVA19 as proc_tva;
else 
  lnAdaos19 := -item_act.adaos_1;
  lnTVA19 := -item_act.tva_1;  
  if V_PRET_CU_TVA_IDENTIC = 1 THEN
    lnAdaos24 := adaos_2;
    lnTVA24 := tva_2;
   ELSE
    lnAdaos24 := adaos_3;
    lnTVA24 := tva_3;     
   END IF; 
  -- 371 = 378 (adaos 19%) 
    insert into act_temp
    (luna, an, dataireg, nract, dataact, explicatia, scd, ascd, scc, ascc, suma, nnir, id_util, dataora, id_set, id_partd, id_partc, id_sucursala, id_fdoc, id_gestin, id_gestout, id_valuta, proc_tva)
    select lnLuna as luna, lnAn as an, ldDataIreg as dataireg, lnNrAct as nract, ldDataAct as dataact, 
    'ADAOS 19%' AS explicatia, item_act.cont AS scd, item_act.acont as ascd, '378' as scc, item.acont_adaos as ascc, 
    lnAdaos19 as suma, lnNir as nnir, lnIdUtil as id_util, ldDataora as dataora, lnIdSet as id_set, 
    item_act.id_part as id_partd, item_act.id_part378 as id_partc, item.id_sucursala as id_sucursala, 
    lnIdFdoc as id_fdoc, item_act.id_gestiune as id_gestin, item_act.id_gestiune as id_gestout, 
    lnIdMonedaNationala as id_valuta, lnProcTVA19 as proc_tva;

  -- 371 = 4428 (tva 19%)
    insert into act_temp
    (luna, an, dataireg, nract, dataact, explicatia, scd, ascd, scc, ascc, suma, nnir, id_util, dataora, id_set, id_partd, id_partc, id_sucursala, id_fdoc, id_gestin, id_gestout, id_valuta, proc_tva)
    select lnLuna as luna, lnAn as an, ldDataIreg as dataireg, lnNrAct as nract, ldDataAct as dataact, 
    'TVA 19%' AS explicatia, item_act.cont AS scd, item_act.acont as ascd, '4428' as scc, '' as ascc, 
    lnTVA19 as suma, lnNir as nnir, lnIdUtil as id_util, ldDataora as dataora, lnIdSet as id_set, 
    item_act.id_part as id_partd, 0 as id_partc, item.id_sucursala as id_sucursala, 
    lnIdFdoc as id_fdoc, item_act.id_gestiune as id_gestin, item_act.id_gestiune as id_gestout, 
    lnIdMonedaNationala as id_valuta, lnProcTVA19 as proc_tva;
  -- 371 = 378 adaos 24% 
    insert into act_temp
    (luna, an, dataireg, nract, dataact, explicatia, scd, ascd, scc, ascc, suma, nnir, id_util, dataora, id_set, id_partd, id_partc, id_sucursala, id_fdoc, id_gestin, id_gestout, id_valuta, proc_tva)
    select lnLuna as luna, lnAn as an, ldDataIreg as dataireg, lnNrAct as nract, ldDataAct as dataact, 
    'ADAOS 24%' AS explicatia, item_act.cont AS scd, item_act.acont as ascd, '378' as scc, item.acont_adaos as ascc, 
    lnAdaos24 as suma, lnNir as nnir, lnIdUtil as id_util, ldDataora as dataora, lnIdSet as id_set, 
    item_act.id_part as id_partd, item_act.id_part378 as id_partc, item.id_sucursala as id_sucursala, 
    lnIdFdoc as id_fdoc, item_act.id_gestiune as id_gestin, item_act.id_gestiune as id_gestout, 
    lnIdMonedaNationala as id_valuta, lnProcTVA24 as proc_tva;  
  -- 371 = 4428 tva 24%      
    insert into act_temp
    (luna, an, dataireg, nract, dataact, explicatia, scd, ascd, scc, ascc, suma, nnir, id_util, dataora, id_set, id_partd, id_partc, id_sucursala, id_fdoc, id_gestin, id_gestout, id_valuta, proc_tva)
    select lnLuna as luna, lnAn as an, ldDataIreg as dataireg, lnNrAct as nract, ldDataAct as dataact, 
    'TVA 24%' AS explicatia, item_act.cont AS scd, item_act.acont as ascd, '4428' as scc, '' as ascc, 
    lnTVA24 as suma, lnNir as nnir, lnIdUtil as id_util, ldDataora as dataora, lnIdSet as id_set, 
    item_act.id_part as id_partd, 0 as id_partc, item.id_sucursala as id_sucursala, 
    lnIdFdoc as id_fdoc, item_act.id_gestiune as id_gestin, item_act.id_gestiune as id_gestout, 
    lnIdMonedaNationala as id_valuta, lnProcTVA24 as proc_tva;  
end if;
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
