procedure SCRIE_JC_2007(tnAn    JC2007.AN%TYPE,
                          tnLuna  JC2007.LUNA%TYPE,
                          tnScrie number) IS

    lcSql                    clob;
    lcContTvaDeductibil      ACT.SCD%TYPE := '4426';
    lcContTvaColectat        ACT.SCD%TYPE := '4427';
    lcContTvaNeexigibil      ACT.SCD%TYPE := '4428';
    lcContDebitRegularizare  VARCHAR2(100) := '408';
    lcContCreditRegularizare VARCHAR2(100) := '401,404,4511,462';
    lnIdMinJtvaColoana       JTVA_COLOANE.ID_JTVA_COLOANA%TYPE := 101;
    lnIdMaxJtvaColoana       JTVA_COLOANE.ID_JTVA_COLOANA%TYPE := 500;
    lcTabelSursa             VARCHAR2(100);
    lcCondSucursala          VARCHAR2(1000);
  begin
    -- tnScrie: 0 - scriere; 1 - refacere; 2 - stergere
    -- 0,2 - selectie din act_temp
    -- 1 - selectie din act
    if pack_contafin.get_id_sucursala() is not null then
      lcCondSucursala := ' AND ALIAS.ID_SUCURSALA = ' ||
                         pack_contafin.GET_ID_SUCURSALA();
    end if;

    if tnScrie in (pack_contafin.nScriere, pack_contafin.nStergere) then
      lcTabelSursa := 'act_temp'; -- scriere, stergere
    else
      lcTabelSursa := 'act'; -- refacere
    end if;

    -- COMPLETARE JC2007 CU ID_SET 10616 STORNARE PLATA/INCASARE
    pack_contafin.completeaza_jc_2007(tnAn,
                                      tnLuna,
                                      lcTabelSursa,
                                      lcCondSucursala);

  MERGE INTO JC2007 J
      USING (SELECT ID_SUCURSALA,
                    AN,
                    LUNA,
                    ID_FACT,
                    ID_FDOC,
                    NRACT,
                    SERIE_ACT,
                    DATAACT,
                    DATAIREG,
                    ID_PART,
                    COD,
                    (CASE
                      WHEN NOTA_TVA_EX = 1 THEN
                       0
                      WHEN REGULARIZARE > 0 THEN
                       TOTCTVA - RO24TR - RO20TR - RO21TR - RO11TR - RO19BCTR - RO19BVTR - RO19BFTR -
                       RO09BCTR - RO09BVTR - RO09BFTR - RO05TR - FO21TR - FO24TR - FO20TR -
                       FO19BCTR - FO19BVTR - FO19BFTR - FO09BCTR - FO09BVTR -
                       FO09BFTR - CE24TR - CE20TR - CE5STR - CE9STR -
                       CE21STR - CE24STR - CE20STR - CE19STR - CEBCTR - CEBVTR - CEBFTR -
                       TI21TR - TI11TR - TI24TR - TI20TR - TI19BCTR - TI19BVTR - TI19BFTR - TI09BVTR - TI09BFTR -
                       RO24NTR - RO20NTR - RO21NTR - RO11NTR - RO19NTR - RO09NTR - RO05NTR
                      ELSE
                       TOTCTVA -
                       DECODE(RO21NB, 0, 0, RO21B) -
                       DECODE(RO11NB, 0, 0, RO11B) -
                       DECODE(RO24NB, 0, 0, RO24B) -
                       DECODE(RO20NB, 0, 0, RO20B) -
                       DECODE(RO19NB, 0, 0, RO19BCB + RO19BVB + RO19BFB) -
                       DECODE(RO9NB, 0, 0, RO09BCB + RO09BVB + RO09BFB) -
                       DECODE(RO5NB, 0, 0, RO05B) -
                       DECODE(RO21NT, 0, 0, RO21T) -
                       DECODE(RO11NT, 0, 0, RO11T) -
                       DECODE(RO24NT, 0, 0, RO24T) -
                       DECODE(RO20NT, 0, 0, RO20T) -
                       DECODE(RO19NT, 0, 0, RO19BCT + RO19BVT + RO19BFT) -
                       DECODE(RO9NT, 0, 0, RO09BCT + RO09BVT + RO09BFT) -
                       DECODE(RO5NT, 0, 0, RO05T)
                    END) AS TOTCTVA,
                    (CASE
                      WHEN NOTA_TVA_EX = 1 THEN
                       0
                      WHEN REGULARIZARE > 0 THEN
                       DECODE(RO24NB, 0, RO24B, RO24NB) +
                       DECODE(RO20NB, 0, RO20B, RO20NB) +
                       DECODE(RO21NB, 0, RO21B, RO21NB) +
                       DECODE(RO11NB, 0, RO11B, RO11NB) +
                       DECODE(RO19NB, 0, RO19BCB + RO19BVB + RO19BFB, RO19NB) +
                       DECODE(RO9NB, 0, RO09BCB + RO09BVB + RO09BFB, RO9NB) +
                       DECODE(RO5NB, 0, RO05B, RO5NB) -
                       DECODE(RO24NB, 0, RO24TR, RO24NTR) -
                       DECODE(RO20NB, 0, RO20TR, RO20NTR) -
                       DECODE(RO21NB, 0, RO21TR, RO21NTR) -
                       DECODE(RO11NB, 0, RO11TR, RO11NTR) -
                       DECODE(RO19NB, 0, RO19BCTR + RO19BVTR + RO19BFTR, RO19NTR) -
                       DECODE(RO9NB, 0, RO09BCTR + RO09BVTR + RO09BFTR, RO09NTR) -
                       DECODE(RO5NB, 0, RO05TR, RO05NTR) - FO21TR - FO24TR - FO20TR -
                       FO19BCTR - FO19BVTR - FO19BFTR - FO09BCTR - FO09BVTR - FO09BFTR -
                       CE24TR - CE20TR - CE5STR - CE9STR - CE21STR - CE24STR - CE20STR - CE19STR -
                       CEBCTR - CEBVTR - CEBFTR -
                       TI21TR - TI11TR - TI24TR - TI20TR - TI19BCTR - TI19BVTR - TI19BFTR - TI09BVTR - TI09BFTR

                      ELSE
                       DECODE(RO24NB, 0, RO24B, RO24NB) +
                       DECODE(RO20NB, 0, RO20B, RO20NB) +
                       DECODE(RO21NB, 0, RO21B, RO21NB) +
                       DECODE(RO11NB, 0, RO11B, RO11NB) +
                       DECODE(RO19NB, 0, RO19BCB + RO19BVB + RO19BFB, RO19NB) +
                       DECODE(RO9NB, 0, RO09BCB + RO09BVB + RO09BFB, RO9NB) +
                       DECODE(RO5NB, 0, RO05B, RO5NB)
                    END) AS TOTFTVATAX,
                    DECODE(NOTA_TVA_EX,
                           1,
                           0,
                           DECODE(RO24NT, 0, RO24T, RO24NT) +
                           DECODE(RO20NT, 0, RO20T, RO20NT) +
                           DECODE(RO21NT, 0, RO21T, RO21NT) +
                           DECODE(RO11NT, 0, RO11T, RO11NT) +
                           DECODE(RO19NT, 0, RO19BCT + RO19BVT + RO19BFT, RO19NT) +
                           DECODE(RO9NT, 0, RO09BCT + RO09BVT + RO09BFT, RO9NT) +
                           DECODE(RO5NT, 0, RO05T, RO5NT)) AS TOTTVATAX,
                    ROSCN + FOSCN + (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CEBCB - CEBCTR
                      ELSE
                       CEBCB
                    END) + CEBCT + (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CEBVB - CEBVTR
                      ELSE
                       CEBVB
                    END) + CEBVT + CEBVSC + CEBVN + (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CEBFB - CEBFTR
                      ELSE
                       CEBFB
                    END) + CEBFT + CEBFSC + CEBFN + ROTN + ROTN50 + ROTN100 AS TOTNETAX,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       DECODE(RO24B,
                              0,
                              DECODE(RO24T, 0, 0, ROUND(RO24T / 0.24, 2)),
                              RO24B - RO24TR)
                      ELSE
                       DECODE(RO24B,
                              0,
                              DECODE(RO24T, 0, 0, ROUND(RO24T / 0.24, 2)),
                              RO24B)
                    END) AS RO24B,
                    RO24T,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       DECODE(RO20B,
                              0,
                              DECODE(RO20T, 0, 0, ROUND(RO20T / 0.20, 2)),
                              RO20B - RO20TR)
                      ELSE
                       DECODE(RO20B,
                              0,
                              DECODE(RO20T, 0, 0, ROUND(RO20T / 0.20, 2)),
                              RO20B)
                    END) AS RO20B,
                    RO20T,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       DECODE(RO21B,
                              0,
                              DECODE(RO21T, 0, 0, ROUND(RO21T / 0.21, 2)),
                              RO21B - RO21TR)
                      ELSE
                       DECODE(RO21B,
                              0,
                              DECODE(RO21T, 0, 0, ROUND(RO21T / 0.21, 2)),
                              RO21B)
                    END) AS RO21B,
                    RO21T,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       DECODE(RO11B,
                              0,
                              DECODE(RO11T, 0, 0, ROUND(RO11T / 0.11, 2)),
                              RO11B - RO11TR)

                      ELSE
                       DECODE(RO11B,
                              0,
                              DECODE(RO11T, 0, 0, ROUND(RO11T / 0.11, 2)),
                              RO11B)
                    END) AS RO11B,
                    RO11T,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       DECODE(RO19BCB,
                              0,
                              DECODE(RO19BCT, 0, 0, ROUND(RO19BCT / 0.19, 2)),
                              RO19BCB - RO19BCTR)
                      ELSE
                       DECODE(RO19BCB,
                              0,
                              DECODE(RO19BCT, 0, 0, ROUND(RO19BCT / 0.19, 2)),
                              RO19BCB)
                    END) AS RO19BCB,
                    RO19BCT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       DECODE(RO19BVB,
                              0,
                              DECODE(RO19BVT, 0, 0, ROUND(RO19BVT / 0.19, 2)),
                              RO19BVB - RO19BVTR)
                      ELSE
                       DECODE(RO19BVB,
                              0,
                              DECODE(RO19BVT, 0, 0, ROUND(RO19BVT / 0.19, 2)),
                              RO19BVB)
                    END) AS RO19BVB,
                    RO19BVT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       DECODE(RO19BFB,
                              0,
                              DECODE(RO19BFT, 0, 0, ROUND(RO19BFT / 0.19, 2)),
                              RO19BFB - RO19BFTR)
                      ELSE
                       DECODE(RO19BFB,
                              0,
                              DECODE(RO19BFT, 0, 0, ROUND(RO19BFT / 0.19, 2)),
                              RO19BFB)
                    END) AS RO19BFB,
                    RO19BFT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       DECODE(RO09BCB,
                              0,
                              DECODE(RO09BCT, 0, 0, ROUND(RO09BCT / 0.09, 2)),
                              RO09BCB - RO09BCTR)
                      ELSE
                       DECODE(RO09BCB,
                              0,
                              DECODE(RO09BCT, 0, 0, ROUND(RO09BCT / 0.09, 2)),
                              RO09BCB)
                    END) AS RO09BCB,
                    RO09BCT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       DECODE(RO09BVB,
                              0,
                              DECODE(RO09BVT, 0, 0, ROUND(RO09BVT / 0.09, 2)),
                              RO09BVB - RO09BVTR)
                      ELSE
                       DECODE(RO09BVB,
                              0,
                              DECODE(RO09BVT, 0, 0, ROUND(RO09BVT / 0.09, 2)),
                              RO09BVB)
                    END) AS RO09BVB,
                    RO09BVT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       DECODE(RO09BFB,
                              0,
                              DECODE(RO09BFT, 0, 0, ROUND(RO09BFT / 0.09, 2)),
                              RO09BFB - RO09BFTR)
                      ELSE
                       DECODE(RO09BFB,
                              0,
                              DECODE(RO09BFT, 0, 0, ROUND(RO09BFT / 0.09, 2)),
                              RO09BFB)
                    END) AS RO09BFB,
                    RO09BFT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       DECODE(RO05B,
                              0,
                              DECODE(RO05T, 0, 0, ROUND(RO05T / 0.05, 2)),
                              RO05B - RO05TR)
                      ELSE
                       DECODE(RO05B,
                              0,
                              DECODE(RO05T, 0, 0, ROUND(RO05T / 0.05, 2)),
                              RO05B)
                    END) AS RO05B,
                    RO05T,
                    ROSCN,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       FO21B - FO21TR
                      ELSE
                       FO21B
                    END) AS FO21B,
                    FO21T,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       FO24B - FO24TR
                      ELSE
                       FO24B
                    END) AS FO24B,
                    FO24T,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       FO20B - FO20TR
                      ELSE
                       FO20B
                    END) AS FO20B,
                    FO20T,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       FO19BCB - FO19BCTR
                      ELSE
                       FO19BCB
                    END) AS FO19BCB,
                    FO19BCT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       FO19BVB - FO19BVTR
                      ELSE
                       FO19BVB
                    END) AS FO19BVB,
                    FO19BVT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       FO19BFB - FO19BFTR
                      ELSE
                       FO19BFB
                    END) AS FO19BFB,
                    FO19BFT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       XX21TIB - XX21TITR
                      ELSE
                       XX21TIB
                    END) AS XX21TIB,
                    XX21TIT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       XX11TIB - XX11TITR
                      ELSE
                       XX11TIB
                    END) AS XX11TIB,
                    XX11TIT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       XX19TIB - XX19TITR
                      ELSE
                       XX19TIB
                    END) AS XX19TIB,
                    XX19TIT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       XX9TIB - XX9TITR
                      ELSE
                       XX9TIB
                    END) AS XX9TIB,
                    XX9TIT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       FO09BCB - FO09BCTR
                      ELSE
                       FO09BCB
                    END) AS FO09BCB,
                    FO09BCT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       FO09BVB - FO09BVTR
                      ELSE
                       FO09BVB
                    END) AS FO09BVB,
                    FO09BVT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       FO09BFB - FO09BFTR
                      ELSE
                       FO09BFB
                    END) AS FO09BFB,
                    FO09BFT,
                    FOSCN,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CE24B - CE24TR
                      ELSE
                       CE24B
                    END) AS CE24B,
                    CE24T,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CE20B - CE20TR
                      ELSE
                       CE20B
                    END) AS CE20B,
                    CE20T,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CE5SB - CE5STR
                      ELSE
                       CE5SB
                    END) AS CE5SB,
                    CE5ST,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CE9SB - CE9STR
                      ELSE
                       CE9SB
                    END) AS CE9SB,
                    CE9ST,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CE24SB - CE24STR
                      ELSE
                       CE24SB
                    END) AS CE24SB,
                    CE24ST,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CE20SB - CE20STR
                      ELSE
                       CE20SB
                    END) AS CE20SB,
                    CE20ST,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CE21SB - CE21STR
                      ELSE
                       CE21SB
                    END) AS CE21SB,
                    CE21ST,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CE19SB - CE19STR
                      ELSE
                       CE19SB
                    END) AS CE19SB,
                    CE19ST,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CEBCB - CEBCTR
                      ELSE
                       CEBCB
                    END) AS CEBCB,
                    CEBCT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CEBVB - CEBVTR
                      ELSE
                       CEBVB
                    END) AS CEBVB,
                    CEBVT,
                    CEBVSC,
                    CEBVN,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CEBFB - CEBFTR
                      ELSE
                       CEBFB
                    END) AS CEBFB,
                    CEBFT,
                    CEBFSC,
                    CEBFN,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CE21CTB - CE21CTTR
                      ELSE
                       CE21CTB
                    END) AS CE21CTB,
                    CE21CTT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CE11CTB - CE11CTTR
                      ELSE
                       CE11CTB
                    END) AS CE11CTB,
                    CE11CTT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CE19CTB - CE19CTTR
                      ELSE
                       CE19CTB
                    END) AS CE19CTB,
                    CE19CTT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CE9CTB - CE9CTTR
                      ELSE
                       CE9CTB
                    END) AS CE9CTB,
                    CE9CTT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CE5CTB - CE5CTTR
                      ELSE
                       CE5CTB
                    END) AS CE5CTB,
                    CE5CTT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CE21FTB - CE21FTTR
                      ELSE
                       CE21FTB
                    END) AS CE21FTB,
                    CE21FTT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CE11FTB - CE11FTTR
                      ELSE
                       CE11FTB
                    END) AS CE11FTB,
                    CE11FTT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CE19FTB - CE19FTTR
                      ELSE
                       CE19FTB
                    END) AS CE19FTB,
                    CE19FTT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CE9FTB - CE9FTTR
                      ELSE
                       CE9FTB
                    END) AS CE9FTB,
                    CE9FTT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       CE5FTB - CE5FTTR
                      ELSE
                       CE5FTB
                    END) AS CE5FTB,
                    CE5FTT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       TI24B - TI24TR
                      ELSE
                       TI24B
                    END) AS TI24B,
                    TI24T,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       TI20B - TI20TR
                      ELSE
                       TI20B
                    END) AS TI20B,
                    TI20T,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       TI21B - TI21TR
                      ELSE
                       TI21B
                    END) AS TI21B,
                    TI21T,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       TI11B - TI11TR
                      ELSE
                       TI11B
                    END) AS TI11B,
                    TI11T,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       TI19BCB - TI19BCTR
                      ELSE
                       TI19BCB
                    END) AS TI19BCB,
                    TI19BCT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       TI19BVB - TI19BVTR
                      ELSE
                       TI19BVB
                    END) AS TI19BVB,
                    TI19BVT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       TI19BFB - TI19BFTR
                      ELSE
                       TI19BFB
                    END) AS TI19BFB,
                    TI19BFT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       TI09BVB - TI09BVTR
                      ELSE
                       TI09BVB
                    END) AS TI09BVB,
                    TI09BVT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       TI09BFB - TI09BFTR
                      ELSE
                       TI09BFB
                    END) AS TI09BFB,
                    TI09BFT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       RO24NB - RO24NTR
                      ELSE
                       RO24NB
                    END) AS RO24NB,
                    RO24NT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       RO20NB - RO20NTR
                      ELSE
                       RO20NB
                    END) AS RO20NB,
                    RO20NT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       RO21NB - RO21NTR
                      ELSE
                       RO21NB
                    END) AS RO21NB,
                    RO21NT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       RO11NB - RO11NTR
                      ELSE
                       RO11NB
                    END) AS RO11NB,
                    RO11NT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       RO19NB - RO19NTR
                      ELSE
                       RO19NB
                    END) AS RO19NB,
                    RO19NT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       RO9NB - RO09NTR
                      ELSE
                       RO9NB
                    END) AS RO9NB,
                    RO9NT,
                    (CASE
                      WHEN REGULARIZARE > 0 THEN
                       RO5NB - RO05NTR
                      ELSE
                       RO5NB
                    END) AS RO5NB,
                    RO5NT,
                    ROTN,
                    ROTN50,
                    ROTN100,
                    RORTD24,
                    RORTD20,
                    RORTD19,
                    RORTD9,
                    RORTD5,
                    RORTD21,
                    RORTD11
               FROM (SELECT JC.ID_SUCURSALA,
                            JC.AN,
                            JC.LUNA,
                            JC.ID_FACT,
                            MAX(JC.ID_FDOC) AS ID_FDOC,
                            JC.NRACT,
                            JC.SERIE_ACT,
                            JC.DATAACT,
                            JC.DATAIREG,
                            MAX(JC.ID_PART) AS ID_PART,
                            MIN(JC.COD) AS COD,
                            MIN(JC.NOTA_TVA_EX) AS NOTA_TVA_EX,
                            sum(CASE
                                  WHEN NVL(JC.ID_JTVA_COLOANA, 0) > 100 and
                                       JC.ID_JTVA_COLOANA NOT IN (1001, 1004, 1005) THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) TOTCTVA,
                            SUM(CASE
                                  WHEN ID_JTVA_COLOANA In (156,
                                                           176,
                                                           208,
                                                           212,
                                                           107,
                                                           109,
                                                           111,
                                                           154,
                                                           170,
                                                           172,
                                                           174,
                                                           178,
                                                           210,
                                                           214,
                                                           101,
                                                           103,
                                                           105,
                                                           188) THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) As totftvatax,
                            SUM(CASE
                                  WHEN ID_JTVA_COLOANA In (157,
                                                           177,
                                                           209,
                                                           213,
                                                           108,
                                                           110,
                                                           112,
                                                           155,
                                                           171,
                                                           173,
                                                           175,
                                                           179,
                                                           211,
                                                           215,
                                                           102,
                                                           104,
                                                           106,
                                                           189) THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) As tottvatax,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 156, JC.suma, 0)) RO24B,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 157, JC.suma, 0)) RO24T,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 176, JC.suma, 0)) RO20B,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 177, JC.suma, 0)) RO20T,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 208, JC.suma, 0)) RO21B,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 209, JC.suma, 0)) RO21T,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 101, JC.suma, 0)) RO19BCB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 102, JC.suma, 0)) RO19BCT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 103, JC.suma, 0)) RO19BVB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 104, JC.suma, 0)) RO19BVT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 105, JC.suma, 0)) RO19BFB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 106, JC.suma, 0)) RO19BFT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 107, JC.suma, 0)) RO09BCB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 108, JC.suma, 0)) RO09BCT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 109, JC.suma, 0)) RO09BVB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 110, JC.suma, 0)) RO09BVT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 111, JC.suma, 0)) RO09BFB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 112, JC.suma, 0)) RO09BFT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 154, JC.suma, 0)) RO05B,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 155, JC.suma, 0)) RO05T,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 212, JC.suma, 0)) RO11B,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 213, JC.suma, 0)) RO11T,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 113, JC.suma, 0)) ROSCN,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 158, JC.suma, 0)) FO24B,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 159, JC.suma, 0)) FO24T,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 180, JC.suma, 0)) FO20B,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 181, JC.suma, 0)) FO20T,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 220, JC.suma, 0)) FO21B,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 221, JC.suma, 0)) FO21T,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 114, JC.suma, 0)) FO19BCB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 115, JC.suma, 0)) FO19BCT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 116, JC.suma, 0)) FO19BVB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 117, JC.suma, 0)) FO19BVT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 118, JC.suma, 0)) FO19BFB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 119, JC.suma, 0)) FO19BFT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 192, JC.suma, 0)) XX19TIB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 193, JC.suma, 0)) XX19TIT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 224, JC.suma, 0)) XX21TIB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 225, JC.suma, 0)) XX21TIT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 230, JC.suma, 0)) XX11TIB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 231, JC.suma, 0)) XX11TIT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 206, JC.suma, 0)) XX9TIB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 207, JC.suma, 0)) XX9TIT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 120, JC.suma, 0)) FO09BCB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 121, JC.suma, 0)) FO09BCT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 122, JC.suma, 0)) FO09BVB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 123, JC.suma, 0)) FO09BVT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 124, JC.suma, 0)) FO09BFB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 125, JC.suma, 0)) FO09BFT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 126, JC.suma, 0)) FOSCN,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 160, JC.suma, 0)) CE24B,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 161, JC.suma, 0)) CE24T,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 182, JC.suma, 0)) CE20B,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 183, JC.suma, 0)) CE20T,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 164, JC.suma, 0)) CE5SB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 165, JC.suma, 0)) CE5ST,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 166, JC.suma, 0)) CE9SB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 167, JC.suma, 0)) CE9ST,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 168, JC.suma, 0)) CE24SB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 169, JC.suma, 0)) CE24ST,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 184, JC.suma, 0)) CE20SB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 185, JC.suma, 0)) CE20ST,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 190, JC.suma, 0)) CE19SB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 191, JC.suma, 0)) CE19ST,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 222, JC.suma, 0)) CE21SB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 223, JC.suma, 0)) CE21ST,
                            sum(DECODE(JC.ID_JTVA_COLOANA,
                                       127,
                                       JC.suma,
                                       148,
                                       JC.suma,
                                       0)) CEBCB,
                            sum(DECODE(JC.ID_JTVA_COLOANA,
                                       128,
                                       JC.suma,
                                       149,
                                       JC.suma,
                                       0)) CEBCT,
                            sum(DECODE(JC.ID_JTVA_COLOANA,
                                       129,
                                       JC.suma,
                                       150,
                                       JC.suma,
                                       0)) CEBVB,
                            sum(DECODE(JC.ID_JTVA_COLOANA,
                                       130,
                                       JC.suma,
                                       151,
                                       JC.suma,
                                       0)) CEBVT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 131, JC.suma, 0)) CEBVSC,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 132, JC.suma, 0)) CEBVN,
                            sum(DECODE(JC.ID_JTVA_COLOANA,
                                       133,
                                       JC.suma,
                                       152,
                                       JC.suma,
                                       0)) CEBFB,
                            sum(DECODE(JC.ID_JTVA_COLOANA,
                                       134,
                                       JC.suma,
                                       153,
                                       JC.suma,
                                       0)) CEBFT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 135, JC.suma, 0)) CEBFSC,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 136, JC.suma, 0)) CEBFN,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 194, JC.suma, 0)) CE19CTB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 195, JC.suma, 0)) CE19CTT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 226, JC.suma, 0)) CE21CTB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 227, JC.suma, 0)) CE21CTT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 232, JC.suma, 0)) CE11CTB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 233, JC.suma, 0)) CE11CTT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 196, JC.suma, 0)) CE9CTB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 197, JC.suma, 0)) CE9CTT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 198, JC.suma, 0)) CE5CTB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 199, JC.suma, 0)) CE5CTT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 200, JC.suma, 0)) CE19FTB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 201, JC.suma, 0)) CE19FTT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 228, JC.suma, 0)) CE21FTB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 229, JC.suma, 0)) CE21FTT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 234, JC.suma, 0)) CE11FTB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 235, JC.suma, 0)) CE11FTT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 202, JC.suma, 0)) CE9FTB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 203, JC.suma, 0)) CE9FTT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 204, JC.suma, 0)) CE5FTB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 205, JC.suma, 0)) CE5FTT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 162, JC.suma, 0)) TI24B,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 163, JC.suma, 0)) TI24T,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 186, JC.suma, 0)) TI20B,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 187, JC.suma, 0)) TI20T,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 216, JC.suma, 0)) TI21B,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 217, JC.suma, 0)) TI21T,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 218, JC.suma, 0)) TI11B,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 219, JC.suma, 0)) TI11T,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 137, JC.suma, 0)) TI19BCB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 138, JC.suma, 0)) TI19BCT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 139, JC.suma, 0)) TI19BVB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 140, JC.suma, 0)) TI19BVT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 141, JC.suma, 0)) TI19BFB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 142, JC.suma, 0)) TI19BFT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 143, JC.suma, 0)) TI09BVB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 144, JC.suma, 0)) TI09BVT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 145, JC.suma, 0)) TI09BFB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 146, JC.suma, 0)) TI09BFT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 170, JC.suma, 0)) RO24NB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 171, JC.suma, 0)) RO24NT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 178, JC.suma, 0)) RO20NB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 179, JC.suma, 0)) RO20NT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 210, JC.suma, 0)) RO21NB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 211, JC.suma, 0)) RO21NT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 214, JC.suma, 0)) RO11NB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 215, JC.suma, 0)) RO11NT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 188, JC.suma, 0)) RO19NB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 189, JC.suma, 0)) RO19NT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 172, JC.suma, 0)) RO9NB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 173, JC.suma, 0)) RO9NT,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 174, JC.suma, 0)) RO5NB,
                            sum(DECODE(JC.ID_JTVA_COLOANA, 175, JC.suma, 0)) RO5NT,
                            SUM(JC.REGULARIZARE) AS REGULARIZARE,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 209 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) RO21TR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 213 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) RO11TR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 157 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) RO24TR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 177 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) RO20TR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 102 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) RO19BCTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 104 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) RO19BVTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 106 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) RO19BFTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 108 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) RO09BCTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 110 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) RO09BVTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 112 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) RO09BFTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 155 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) RO05TR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 159 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) FO24TR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 181 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) FO20TR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 221 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) FO21TR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 115 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) FO19BCTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 117 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) FO19BVTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 119 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) FO19BFTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 225 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) XX21TITR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 231 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) XX11TITR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 193 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) XX19TITR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 207 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) XX9TITR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 121 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) FO09BCTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 123 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) FO09BVTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 125 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) FO09BFTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 161 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) CE24TR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 183 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) CE20TR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 165 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) CE5STR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 167 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) CE9STR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 169 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) CE24STR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 185 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) CE20STR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 223 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) CE21STR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 191 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) CE19STR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA in (128, 149) AND
                                       JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) CEBCTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA in (130, 151) AND
                                       JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) CEBVTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA in (134, 153) AND
                                       JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) CEBFTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 227 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) CE21CTTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 233 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) CE11CTTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 195 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) CE19CTTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 197 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) CE9CTTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 199 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) CE5CTTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 229 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) CE21FTTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 235 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) CE11FTTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 201 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) CE19FTTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 203 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) CE9FTTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 205 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) CE5FTTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 217 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) TI21TR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 219 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) TI11TR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 163 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) TI24TR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 187 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) TI20TR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 138 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) TI19BCTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 140 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) TI19BVTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 142 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) TI19BFTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 144 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) TI09BVTR,
                            SUM(CASE
                                  WHEN JC.ID_JTVA_COLOANA = 146 AND JC.SCC = '4428' THEN
                                   JC.suma
                                  ELSE
                                   0
                                END) TI09BFTR,
                            SUM(CASE
                                  WHEN ID_JTVA_COLOANA = 171 AND SCC = '4428' THEN
                                   SUMA
                                  ELSE
                                   0
                                END) RO24NTR,
                            SUM(CASE
                                  WHEN ID_JTVA_COLOANA = 179 AND SCC = '4428' THEN
                                   SUMA
                                  ELSE
                                   0
                                END) RO20NTR,
                            SUM(CASE
                                  WHEN ID_JTVA_COLOANA = 211 AND SCC = '4428' THEN
                                   SUMA
                                  ELSE
                                   0
                                END) RO21NTR,
                            SUM(CASE
                                  WHEN ID_JTVA_COLOANA = 215 AND SCC = '4428' THEN
                                   SUMA
                                  ELSE
                                   0
                                END) RO11NTR,
                            SUM(CASE
                                  WHEN ID_JTVA_COLOANA = 189 AND SCC = '4428' THEN
                                   SUMA
                                  ELSE
                                   0
                                END) RO19NTR,
                            SUM(CASE
                                  WHEN ID_JTVA_COLOANA = 173 AND SCC = '4428' THEN
                                   SUMA
                                  ELSE
                                   0
                                END) RO09NTR,
                            SUM(CASE
                                  WHEN ID_JTVA_COLOANA = 175 AND SCC = '4428' THEN
                                   SUMA
                                  ELSE
                                   0
                                END) RO05NTR,
                            SUM(CASE
                                  WHEN ID_JTVA_COLOANA = 1001 THEN
                                   SUMA
                                  ELSE
                                   0
                                END) ROTN,
                            SUM(CASE
                                  WHEN ID_JTVA_COLOANA = 1004 THEN
                                   SUMA
                                  ELSE
                                   0
                                END) ROTN50,
                            SUM(CASE
                                  WHEN ID_JTVA_COLOANA = 1005 THEN
                                   SUMA
                                  ELSE
                                   0
                                END) ROTN100,
                            SUM(CASE
                                  WHEN ID_JTVA_COLOANA = 1011 THEN
                                   SUMA
                                  ELSE
                                   0
                                END) RORTD24,
                            SUM(CASE
                                  WHEN ID_JTVA_COLOANA = 1012 THEN
                                   SUMA
                                  ELSE
                                   0
                                END) RORTD20,
                            SUM(CASE
                                  WHEN ID_JTVA_COLOANA = 1013 THEN
                                   SUMA
                                  ELSE
                                   0
                                END) RORTD19,
                            SUM(CASE
                                  WHEN ID_JTVA_COLOANA = 1014 THEN
                                   SUMA
                                  ELSE
                                   0
                                END) RORTD9,
                            SUM(CASE
                                  WHEN ID_JTVA_COLOANA = 1015 THEN
                                   SUMA
                                  ELSE
                                   0
                                END) RORTD5,
                            SUM(CASE
                                  WHEN ID_JTVA_COLOANA = 1018 THEN
                                   SUMA
                                  ELSE
                                   0
                                END) RORTD21,
                            SUM(CASE
                                  WHEN ID_JTVA_COLOANA = 1019 THEN
                                   SUMA
                                  ELSE
                                   0
                                END) RORTD11
                       FROM (SELECT A.ID_SUCURSALA,
                                    A.AN,
                                    A.LUNA,
                                    (CASE
                                      WHEN A.NRACT <> D.NRACT or
                                           A.DATAACT <> D.DATAACT THEN
                                       1
                                      ELSE
                                       0
                                    END) AS NOTA_TVA_EX,
                                    (CASE
                                      WHEN A.NRACT <> D.NRACT or
                                           A.DATAACT <> D.DATAACT OR
                                           A.ID_SET <> D.ID_SET OR
                                           NVL(A.SERIE_ACT, 'X') <>
                                           NVL(D.SERIE_ACT, 'X') THEN
                                       NULL
                                      ELSE
                                       A.ID_FDOC
                                    END) AS ID_FDOC,
                                    A.ID_FACT,
                                    (CASE
                                      WHEN A.NRACT <> D.NRACT THEN
                                       D.NRACT
                                      ELSE
                                       A.NRACT
                                    END) AS NRACT,
                                    D.SERIE_ACT,
                                    (CASE
                                      WHEN A.NRACT <> D.NRACT or
                                           A.DATAACT <> D.DATAACT THEN
                                       TRUNC(D.DATAACT)
                                      ELSE
                                       TRUNC(A.DATAACT)
                                    END) AS DATAACT,
                                    (CASE
                                      WHEN A.NRACT <> D.NRACT or
                                           NVL(A.DATAIREG, A.DATAACT) <>
                                           NVL(D.DATAIREG, D.DATAACT) THEN
                                       TRUNC(NVL(D.DATAIREG, D.DATAACT))
                                      ELSE
                                       TRUNC(NVL(A.DATAIREG, A.DATAACT))
                                    END) AS DATAIREG,
                                    A.COD,
                                    A.SCD,
                                    A.SCC,
                                    -- 4426 = 4427 sau 4428 = 4427 nu au parteneri
                                    MAX(DECODE(E.EXCEPTIE,
                                               1,
                                               A.ID_PARTD,
                                               (CASE
                                                 WHEN A.SCC IN
                                                      (lcContTvaColectat, lcContTvaNeexigibil) OR
                                                      SUBSTR(A.SCC, 1, 1) = '5' OR
                                                      ID_JTVA_COLOANA in (1001, 1004, 1005) THEN
                                                  -9999999999
                                                 ELSE
                                                  A.ID_PARTC
                                               END))) OVER(PARTITION BY A.AN, A.LUNA, A.ID_FDOC, A.NRACT, A.DATAACT, A.COD) AS ID_PART,
                                    -- INVERSARE SUME LA EXCEPTII
                                    DECODE(A.ID_SET, 10616, -1, 1) *
                                    DECODE(E.EXCEPTIE, 1, -A.SUMA, A.SUMA) AS SUMA,
                                    -- MARCA REGULARIZARE FACTURI NESOSITE
                                    (CASE
                                      WHEN INSTR(lcContDebitRegularizare, A.scd) > 0 and
                                           INSTR(lcContCreditRegularizare, A.scc) > 0 THEN
                                       1
                                      ELSE
                                       0
                                    END) AS REGULARIZARE,
                                    ID_JTVA_COLOANA,
                                    ROW_NUMBER() OVER(PARTITION BY a.nract ORDER BY a.nract) AS RN
                               FROM (
                                  SELECT ID_SUCURSALA,
                                         AN,
                                         LUNA,
                                         ID_FDOC,
                                         ID_FACT,
                                         NRACT,
                                         SERIE_ACT,
                                         DATAACT,
                                         DATAIREG,
                                         COD,
                                         SCD,
                                         SCC,
                                         ID_PARTD,
                                         ID_PARTC,
                                         ID_SET,
                                         SUMA,
                                         ID_JTVA_COLOANA,
                                         STERS
                                  FROM ACT_TEMP
                                  WHERE lcTabelSursa = 'act_temp'
                                    AND AN = tnAn
                                    AND LUNA = tnLuna
                                    AND STERS = 0
                                    AND (ID_JTVA_COLOANA BETWEEN lnIdMinJtvaColoana AND lnIdMaxJtvaColoana
                                         OR ID_JTVA_COLOANA in (1001, 1004, 1005, 1011, 1012, 1013, 1014, 1015,1018,1019))
                                    AND ID_SET <> 10622
                                  UNION ALL
                                  SELECT ID_SUCURSALA,
                                         AN,
                                         LUNA,
                                         ID_FDOC,
                                         ID_FACT,
                                         NRACT,
                                         SERIE_ACT,
                                         DATAACT,
                                         DATAIREG,
                                         COD,
                                         SCD,
                                         SCC,
                                         ID_PARTD,
                                         ID_PARTC,
                                         ID_SET,
                                         SUMA,
                                         ID_JTVA_COLOANA,
                                         STERS
                                  FROM ACT
                                  WHERE lcTabelSursa = 'act'
                                    AND AN = tnAn
                                    AND LUNA = tnLuna
                                    AND STERS = 0
                                    AND (ID_JTVA_COLOANA BETWEEN lnIdMinJtvaColoana AND lnIdMaxJtvaColoana
                                         OR ID_JTVA_COLOANA in (1001, 1004, 1005, 1011, 1012, 1013, 1014, 1015,1018,1019))
                                    AND ID_SET <> 10622
                                 ) A
                               LEFT JOIN (SELECT DISTINCT 1 AS EXCEPTIE,
                                                         DECODE(DEBIT,
                                                                1,
                                                                CONT_C,
                                                                CONT) AS SCD,
                                                         DECODE(DEBIT,
                                                                1,
                                                                CONT,
                                                                CONT_C) AS SCC
                                           FROM EXCEPTII_IREG
                                          WHERE INVERS = 1
                                            AND IN_TVA = 1) E
                                 ON A.SCD = E.SCD
                                AND A.SCC = E.SCC
                               LEFT JOIN DOCUMENTE D
                                 ON A.ID_FACT = D.ID_DOC
                              WHERE A.AN = tnAn
                                and A.LUNA = tnLuna
                                and A.STERS = 0
                                AND (A.ID_JTVA_COLOANA BETWEEN lnIdMinJtvaColoana AND
                                    lnIdMaxJtvaColoana OR
                                    A.ID_JTVA_COLOANA in
                                    (1001,
                                      1004,
                                      1005,
                                      1011,
                                      1012,
                                      1013,
                                      1014,
                                      1015,
                                      1018,
                                      1019))
                                   -- IN JURNALUL DE CUMPARARI NU INTRA FACTURILE NESOSITE + INCASARILE
                                   -- SAU COMPENSARI 409 CU EXPLICATIE TVA
                                AND A.ID_SET <> 10622
                                AND NOT (TRIM(NVL(A.SCC, 'X')) =
                                     lcContDebitRegularizare OR
                                     (TRIM(NVL(A.SCD, 'X')) =
                                     lcContDebitRegularizare AND
                                     INSTR(lcContCreditRegularizare,
                                                TRIM(NVL(A.SCC, 'X'))) = 0))
                                AND nvl2(pack_contafin.GET_ID_SUCURSALA(),
                                         A.ID_SUCURSALA,
                                         0) =
                                    nvl(pack_contafin.GET_ID_SUCURSALA(), 0)) JC
                      GROUP BY JC.AN,
                               JC.LUNA,
                               JC.ID_FACT,
                               JC.NRACT,
                               JC.SERIE_ACT,
                               JC.DATAACT,
                               JC.DATAIREG,
                               JC.ID_SUCURSALA)) S
      ON (J.AN = S.AN AND J.LUNA = S.LUNA AND J.ID_FACT = S.ID_FACT AND NVL(J.ID_SUCURSALA, -99) = NVL(S.ID_SUCURSALA, -99))
      WHEN MATCHED THEN
        UPDATE
           SET J.TOTCTVA    = J.TOTCTVA + (CASE
                                WHEN EXTRACT(MONTH FROM J.DATAACT) = J.LUNA AND
                                     EXTRACT(YEAR FROM J.DATAACT) = J.AN THEN
                                 S.TOTCTVA
                                ELSE
                                 0
                              END),
               J.TOTFTVATAX = J.TOTFTVATAX + (CASE
                                WHEN EXTRACT(MONTH FROM J.DATAACT) = J.LUNA AND
                                     EXTRACT(YEAR FROM J.DATAACT) = J.AN THEN
                                 S.TOTFTVATAX
                                ELSE
                                 0
                              END),
               J.TOTTVATAX  = J.TOTTVATAX + (CASE
                                WHEN EXTRACT(MONTH FROM J.DATAACT) = J.LUNA AND
                                     EXTRACT(YEAR FROM J.DATAACT) = J.AN THEN
                                 S.TOTTVATAX
                                ELSE
                                 0
                              END),
               J.TOTNETAX   = J.TOTNETAX + (CASE
                                WHEN EXTRACT(MONTH FROM J.DATAACT) = J.LUNA AND
                                     EXTRACT(YEAR FROM J.DATAACT) = J.AN THEN
                                 S.TOTNETAX
                                ELSE
                                 0
                              END),
               J.RO21B      = J.RO21B + NVL(S.RO21B, 0) + (CASE
                                WHEN NVL(S.RO21B, 0) <> 0 AND NVL(J.RO21NT, 0) <> 0 AND
                                     NVL(J.RO21NT, 0) - (NVL(J.RO21T, 0) + NVL(S.RO21T, 0)) = 0 THEN
                                 NVL(J.RO21NB, 0) - (NVL(J.RO21B, 0) + NVL(S.RO21B, 0))
                                ELSE
                                 0
                              END),
               J.RO21T      = J.RO21T + S.RO21T,
               J.RO11B      = J.RO11B + NVL(S.RO11B, 0) + (CASE
                                WHEN NVL(S.RO11B, 0) <> 0 AND NVL(J.RO11NT, 0) <> 0 AND
                                     NVL(J.RO11NT, 0) - (NVL(J.RO11T, 0) + NVL(S.RO11T, 0)) = 0 THEN
                                 NVL(J.RO11NB, 0) - (NVL(J.RO11B, 0) + NVL(S.RO11B, 0))
                                ELSE
                                 0
                              END),
               J.RO11T      = J.RO11T + S.RO11T,
               J.RO24B      = J.RO24B + NVL(S.RO24B, 0) + (CASE
                                WHEN NVL(S.RO24B, 0) <> 0 AND NVL(J.RO24NT, 0) <> 0 AND
                                     NVL(J.RO24NT, 0) - (NVL(J.RO24T, 0) + NVL(S.RO24T, 0)) = 0 THEN
                                 NVL(J.RO24NB, 0) - (NVL(J.RO24B, 0) + NVL(S.RO24B, 0))
                                ELSE
                                 0
                              END),
               J.RO24T      = J.RO24T + S.RO24T,
               J.RO20B      = J.RO20B + NVL(S.RO20B, 0) + (CASE
                                WHEN NVL(S.RO20B, 0) <> 0 AND NVL(J.RO20NT, 0) <> 0 AND
                                     NVL(J.RO20NT, 0) - (NVL(J.RO20T, 0) + NVL(S.RO20T, 0)) = 0 THEN
                                 NVL(J.RO20NB, 0) - (NVL(J.RO20B, 0) + NVL(S.RO20B, 0))
                                ELSE
                                 0
                              END),
               J.RO20T      = J.RO20T + S.RO20T,
               J.RO19BCB    = J.RO19BCB + NVL(S.RO19BCB, 0) + (CASE
                                WHEN NVL(S.RO19BCB, 0) <> 0 AND NVL(J.RO19NT, 0) <> 0 AND
                                     NVL(S.RO19BVB, 0) = 0 AND NVL(S.RO19BFB, 0) = 0 AND
                                     NVL(J.RO19NT, 0) - (NVL(J.RO19BCT, 0) + NVL(S.RO19BCT, 0)) = 0 THEN
                                 NVL(J.RO19NB, 0) - (NVL(J.RO19BCB, 0) + NVL(S.RO19BCB, 0))
                                ELSE
                                 0
                              END),
               J.RO19BCT    = J.RO19BCT + S.RO19BCT,
               J.RO19BVB    = J.RO19BVB + NVL(S.RO19BVB, 0) + (CASE
                                WHEN NVL(S.RO19BVB, 0) <> 0 AND NVL(J.RO19NT, 0) <> 0 AND
                                     NVL(S.RO19BFB, 0) = 0 AND
                                     NVL(J.RO19NT, 0) - (NVL(J.RO19BVT, 0) + NVL(S.RO19BVT, 0)) = 0 THEN
                                 NVL(J.RO19NB, 0) - (NVL(J.RO19BVB, 0) + NVL(S.RO19BVB, 0))
                                ELSE
                                 0
                              END),
               J.RO19BVT    = J.RO19BVT + S.RO19BVT,
               J.RO19BFB    = J.RO19BFB + NVL(S.RO19BFB, 0) + (CASE
                                WHEN NVL(S.RO19BFB, 0) <> 0 AND NVL(J.RO19NT, 0) <> 0 AND
                                     NVL(J.RO19NT, 0) - (NVL(J.RO19BFT, 0) + NVL(S.RO19BFT, 0)) = 0 THEN
                                 NVL(J.RO19NB, 0) - (NVL(J.RO19BFB, 0) + NVL(S.RO19BFB, 0))
                                ELSE
                                 0
                              END),
               J.RO19BFT    = J.RO19BFT + S.RO19BFT,
               J.RO09BCB    = J.RO09BCB + NVL(S.RO09BCB, 0) + (CASE
                                WHEN NVL(S.RO09BCB, 0) <> 0 AND NVL(J.RO9NT, 0) <> 0 AND
                                     NVL(S.RO09BVB, 0) = 0 AND NVL(S.RO09BFB, 0) = 0 AND
                                     NVL(J.RO9NT, 0) - (NVL(J.RO09BCT, 0) + NVL(S.RO09BCT, 0)) = 0 THEN
                                 NVL(J.RO9NB, 0) - (NVL(J.RO09BCB, 0) + NVL(S.RO09BCB, 0))
                                ELSE
                                 0
                              END),
               J.RO09BCT    = J.RO09BCT + S.RO09BCT,
               J.RO09BVB    = J.RO09BVB + NVL(S.RO09BVB, 0) + (CASE
                                WHEN NVL(S.RO09BVB, 0) <> 0 AND NVL(J.RO9NT, 0) <> 0 AND
                                     NVL(S.RO09BFB, 0) = 0 AND
                                     NVL(J.RO9NT, 0) - (NVL(J.RO09BVT, 0) + NVL(S.RO09BVT, 0)) = 0 THEN
                                 NVL(J.RO9NB, 0) - (NVL(J.RO09BVB, 0) + NVL(S.RO09BVB, 0))
                                ELSE
                                 0
                              END),
               J.RO09BVT    = J.RO09BVT + S.RO09BVT,
               J.RO09BFB    = J.RO09BFB + NVL(S.RO09BFB, 0) + (CASE
                                WHEN NVL(S.RO09BFB, 0) <> 0 AND NVL(J.RO9NT, 0) <> 0 AND
                                     NVL(J.RO9NT, 0) - (NVL(J.RO09BFT, 0) + NVL(S.RO09BFT, 0)) = 0 THEN
                                 NVL(J.RO9NB, 0) - (NVL(J.RO09BFB, 0) + NVL(S.RO09BFB, 0))
                                ELSE
                                 0
                              END),
               J.RO09BFT    = J.RO09BFT + S.RO09BFT,
               J.RO05B      = J.RO05B + NVL(S.RO05B, 0) + (CASE
                                WHEN NVL(S.RO05B, 0) <> 0 AND NVL(J.RO5NB, 0) <> 0 AND
                                     NVL(J.RO5NT, 0) - (NVL(J.RO05T, 0) + NVL(S.RO05T, 0)) = 0 THEN
                                 NVL(J.RO5NB, 0) - (NVL(J.RO05B, 0) + NVL(S.RO05B, 0))
                                ELSE
                                 0
                              END),
               J.RO05T      = J.RO05T + S.RO05T,
               J.RO21NB     = J.RO21NB + S.RO21NB,
               J.RO21NT     = J.RO21NT + S.RO21NT,
               J.RO11NB     = J.RO11NB + S.RO11NB,
               J.RO11NT     = J.RO11NT + S.RO11NT,
               J.RO24NB     = J.RO24NB + S.RO24NB,
               J.RO24NT     = J.RO24NT + S.RO24NT,
               J.RO19NB     = J.RO19NB + S.RO19NB,
               J.RO19NT     = J.RO19NT + S.RO19NT,
               J.RO20NB     = J.RO20NB + S.RO20NB,
               J.RO20NT     = J.RO20NT + S.RO20NT,
               J.RO9NB      = J.RO9NB + S.RO9NB,
               J.RO9NT      = J.RO9NT + S.RO9NT,
               J.RO5NB      = J.RO5NB + S.RO5NB,
               J.RO5NT      = J.RO5NT + S.RO5NT,
               J.ROSCN      = J.ROSCN + S.ROSCN,
               J.FO21B      = J.FO21B + S.FO21B,
               J.FO21T      = J.FO21T + S.FO21T,
               J.FO24B      = J.FO24B + S.FO24B,
               J.FO24T      = J.FO24T + S.FO24T,
               J.FO20B      = J.FO20B + S.FO20B,
               J.FO20T      = J.FO20T + S.FO20T,
               J.FO19BCB    = J.FO19BCB + S.FO19BCB,
               J.FO19BCT    = J.FO19BCT + S.FO19BCT,
               J.FO19BVB    = J.FO19BVB + S.FO19BVB,
               J.FO19BVT    = J.FO19BVT + S.FO19BVT,
               J.FO19BFB    = J.FO19BFB + S.FO19BFB,
               J.FO19BFT    = J.FO19BFT + S.FO19BFT,
               J.XX21TIB    = J.XX21TIB + S.XX21TIB,
               J.XX21TIT    = J.XX21TIT + S.XX21TIT,
               J.XX11TIB     = J.XX11TIB + S.XX11TIB,
               J.XX11TIT     = J.XX11TIT + S.XX11TIT,
               J.XX19TIB    = J.XX19TIB + S.XX19TIB,
               J.XX19TIT    = J.XX19TIT + S.XX19TIT,
               J.XX9TIB     = J.XX9TIB + S.XX9TIB,
               J.XX9TIT     = J.XX9TIT + S.XX9TIT,
               J.FO09BCB    = J.FO09BCB + S.FO09BCB,
               J.FO09BCT    = J.FO09BCT + S.FO09BCT,
               J.FO09BVB    = J.FO09BVB + S.FO09BVB,
               J.FO09BVT    = J.FO09BVT + S.FO09BVT,
               J.FO09BFB    = J.FO09BFB + S.FO09BFB,
               J.FO09BFT    = J.FO09BFT + S.FO09BFT,
               J.FOSCN      = J.FOSCN + S.FOSCN,
               J.CE24B      = J.CE24B + S.CE24B,
               J.CE24T      = J.CE24T + S.CE24T,
               J.CE20B      = J.CE20B + S.CE20B,
               J.CE20T      = J.CE20T + S.CE20T,
               J.CE5SB      = J.CE5SB + S.CE5SB,
               J.CE5ST      = J.CE5ST + S.CE5ST,
               J.CE9SB      = J.CE9SB + S.CE9SB,
               J.CE9ST      = J.CE9ST + S.CE9ST,
               J.CE21SB     = J.CE21SB + S.CE21SB,
               J.CE21ST     = J.CE21ST + S.CE21ST,
               J.CE24SB     = J.CE24SB + S.CE24SB,
               J.CE24ST     = J.CE24ST + S.CE24ST,
               J.CE20SB     = J.CE20SB + S.CE20SB,
               J.CE20ST     = J.CE20ST + S.CE20ST,
               J.CE19SB     = J.CE19SB + S.CE19SB,
               J.CE19ST     = J.CE19ST + S.CE19ST,
               J.CEBCB      = J.CEBCB + S.CEBCB,
               J.CEBCT      = J.CEBCT + S.CEBCT,
               J.CEBVB      = J.CEBVB + S.CEBVB,
               J.CEBVT      = J.CEBVT + S.CEBVT,
               J.CEBVSC     = J.CEBVSC + S.CEBVSC,
               J.CEBVN      = J.CEBVN + S.CEBVN,
               J.CEBFB      = J.CEBFB + S.CEBFB,
               J.CEBFT      = J.CEBFT + S.CEBFT,
               J.CEBFSC     = J.CEBFSC + S.CEBFSC,
               J.CEBFN      = J.CEBFN + S.CEBFN,
               J.CE21CTB    = J.CE21CTB + S.CE21CTB,
               J.CE21CTT    = J.CE21CTT + S.CE21CTT,
               J.CE11CTB     = J.CE11CTB + S.CE11CTB,
               J.CE11CTT     = J.CE11CTT + S.CE11CTT,
               J.CE19CTB    = J.CE19CTB + S.CE19CTB,
               J.CE19CTT    = J.CE19CTT + S.CE19CTT,
               J.CE9CTB     = J.CE9CTB + S.CE9CTB,
               J.CE9CTT     = J.CE9CTT + S.CE9CTT,
               J.CE5CTB     = J.CE5CTB + S.CE5CTB,
               J.CE5CTT     = J.CE5CTT + S.CE5CTT,
               J.CE21FTB    = J.CE21FTB + S.CE21FTB,
               J.CE21FTT    = J.CE21FTT + S.CE21FTT,
               J.CE11FTB     = J.CE11FTB + S.CE11FTB,
               J.CE11FTT     = J.CE11FTT + S.CE11FTT,
               J.CE19FTB    = J.CE19FTB + S.CE19FTB,
               J.CE19FTT    = J.CE19FTT + S.CE19FTT,
               J.CE9FTB     = J.CE9FTB + S.CE9FTB,
               J.CE9FTT     = J.CE9FTT + S.CE9FTT,
               J.CE5FTB     = J.CE5FTB + S.CE5FTB,
               J.CE5FTT     = J.CE5FTT + S.CE5FTT,
               J.TI21B      = J.TI21B + S.TI21B,
               J.TI21T      = J.TI21T + S.TI21T,
               J.TI11B      = J.TI11B + S.TI11B,
               J.TI11T      = J.TI11T + S.TI11T,
               J.TI24B      = J.TI24B + S.TI24B,
               J.TI24T      = J.TI24T + S.TI24T,
               J.TI20B      = J.TI20B + S.TI20B,
               J.TI20T      = J.TI20T + S.TI20T,
               J.TI19BCB    = J.TI19BCB + S.TI19BCB,
               J.TI19BCT    = J.TI19BCT + S.TI19BCT,
               J.TI19BVB    = J.TI19BVB + S.TI19BVB,
               J.TI19BVT    = J.TI19BVT + S.TI19BVT,
               J.TI19BFB    = J.TI19BFB + S.TI19BFB,
               J.TI19BFT    = J.TI19BFT + S.TI19BFT,
               J.TI09BVB    = J.TI09BVB + S.TI09BVB,
               J.TI09BVT    = J.TI09BVT + S.TI09BVT,
               J.TI09BFB    = J.TI09BFB + S.TI09BFB,
               J.TI09BFT    = J.TI09BFT + S.TI09BFT,
               J.ROTN       = J.ROTN + S.ROTN,
               J.ROTN50     = J.ROTN50 + S.ROTN50,
               J.ROTN100    = J.ROTN100 + S.ROTN100,
               J.RORTD21    = J.RORTD21 + S.RORTD21,
               J.RORTD11    = J.RORTD11 + S.RORTD11,
               J.RORTD24    = J.RORTD24 + S.RORTD24,
               J.RORTD20    = J.RORTD20 + S.RORTD20,
               J.RORTD19    = J.RORTD19 + S.RORTD19,
               J.RORTD9     = J.RORTD9 + S.RORTD9,
               J.RORTD5     = J.RORTD5 + S.RORTD5 DELETE
         WHERE tnScrie = pack_contafin.nStergere
           AND J.TOTCTVA = 0
           AND J.TOTFTVATAX = 0
           AND J.TOTTVATAX = 0
           AND J.TOTNETAX = 0
           AND J.RO24B = 0
           AND J.RO24T = 0
           AND J.RO20B = 0
           AND J.RO20T = 0
           AND J.RO21B = 0
           AND J.RO21T = 0
           AND J.RO11B = 0
           AND J.RO11T = 0
           AND J.RO19BCB = 0
           AND J.RO19BCT = 0
           AND J.RO19BVB = 0
           AND J.RO19BVT = 0
           AND J.RO19BFB = 0
           AND J.RO19BFT = 0
           AND J.RO09BCB = 0
           AND J.RO09BCT = 0
           AND J.RO09BVB = 0
           AND J.RO09BVT = 0
           AND J.RO09BFB = 0
           AND J.RO09BFT = 0
           AND J.RO05B = 0
           AND J.RO05T = 0
           AND J.RO21NB = 0
           AND J.RO21NT = 0
           AND J.RO11NB = 0
           AND J.RO11NT = 0
           AND J.RO24NB = 0
           AND J.RO24NT = 0
           AND J.RO20NB = 0
           AND J.RO20NT = 0
           AND J.RO19NB = 0
           AND J.RO19NT = 0
           AND J.RO9NB = 0
           AND J.RO9NT = 0
           AND J.RO5NB = 0
           AND J.RO5NT = 0
           AND J.ROSCN = 0
           AND J.FO21B = 0
           AND J.FO21T = 0
           AND J.FO24B = 0
           AND J.FO24T = 0
           AND J.FO20B = 0
           AND J.FO20T = 0
           AND J.FO19BCB = 0
           AND J.FO19BCT = 0
           AND J.FO19BVB = 0
           AND J.FO19BVT = 0
           AND J.FO19BFB = 0
           AND J.FO19BFT = 0
           AND J.XX21TIB = 0
           AND J.XX21TIT = 0
           AND J.XX11TIB = 0
           AND J.XX11TIT = 0
           AND J.XX19TIB = 0
           AND J.XX19TIT = 0
           AND J.XX9TIB = 0
           AND J.XX9TIT = 0
           AND J.FO09BCB = 0
           AND J.FO09BCT = 0
           AND J.FO09BVB = 0
           AND J.FO09BVT = 0
           AND J.FO09BFB = 0
           AND J.FO09BFT = 0
           AND J.FOSCN = 0
           AND J.CE24B = 0
           AND J.CE24T = 0
           AND J.CE20B = 0
           AND J.CE20T = 0
           AND J.CE5SB = 0
           AND J.CE5ST = 0
           AND J.CE9SB = 0
           AND J.CE9ST = 0
           AND J.CE21SB = 0
           AND J.CE21ST = 0
           AND J.CE24SB = 0
           AND J.CE24ST = 0
           AND J.CE20SB = 0
           AND J.CE20ST = 0
           AND J.CE19SB = 0
           AND J.CE19ST = 0
           AND J.CEBCB = 0
           AND J.CEBCT = 0
           AND J.CEBVB = 0
           AND J.CEBVT = 0
           AND J.CEBVSC = 0
           AND J.CEBVN = 0
           AND J.CEBFB = 0
           AND J.CEBFT = 0
           AND J.CEBFSC = 0
           AND J.CEBFN = 0
           AND J.CE21CTB = 0
           AND J.CE21CTT = 0
           AND J.CE11CTB = 0
           AND J.CE11CTT = 0
           AND J.CE19CTB = 0
           AND J.CE19CTT = 0
           AND J.CE9CTB = 0
           AND J.CE9CTT = 0
           AND J.CE5CTB = 0
           AND J.CE5CTT = 0
           AND J.CE21FTB = 0
           AND J.CE21FTT = 0
           AND J.CE11FTB = 0
           AND J.CE11FTT = 0
           AND J.CE19FTB = 0
           AND J.CE19FTT = 0
           AND J.CE9FTB = 0
           AND J.CE9FTT = 0
           AND J.CE5FTB = 0
           AND J.CE5FTT = 0
           AND J.TI21B = 0
           AND J.TI21T = 0
           AND J.TI11B = 0
           AND J.TI11T = 0
           AND J.TI24B = 0
           AND J.TI24T = 0
           AND J.TI20B = 0
           AND J.TI20T = 0
           AND J.TI19BCB = 0
           AND J.TI19BCT = 0
           AND J.TI19BVB = 0
           AND J.TI19BVT = 0
           AND J.TI19BFB = 0
           AND J.TI19BFT = 0
           AND J.TI09BVB = 0
           AND J.TI09BVT = 0
           AND J.TI09BFB = 0
           AND J.TI09BFT = 0
           AND J.ROTN = 0
           AND J.ROTN50 = 0
           AND J.ROTN100 = 0
        WHEN NOT MATCHED THEN INSERT(AN, LUNA, ID_FACT, NRACT, SERIE_ACT, ID_FDOC, DATAACT, DATAIREG, ID_PART, COD, TOTCTVA, TOTFTVATAX, TOTTVATAX, TOTNETAX, RO21B, RO21T, RO11B, RO11T, RO24B, RO24T, RO20B, RO20T, RO19BCB, RO19BCT, RO19BVB, RO19BVT, RO19BFB, RO19BFT, RO09BCB, RO09BCT, RO09BVB, RO09BVT, RO09BFB, RO09BFT, RO05B, RO05T, RO21NB, RO21NT, RO11NB, RO11NT, RO24NB, RO24NT, RO20NB, RO20NT, RO19NB, RO19NT, RO9NB, RO9NT, RO5NB, RO5NT, ROSCN, FO21B, FO21T, FO24B, FO24T, FO20B, FO20T, FO19BCB, FO19BCT, FO19BVB, FO19BVT, FO19BFB, FO19BFT, XX21TIB, XX21TIT, XX11TIB, XX11TIT, XX19TIB, XX19TIT, XX9TIB, XX9TIT, FO09BCB, FO09BCT, FO09BVB, FO09BVT, FO09BFB, FO09BFT, FOSCN, CE24B, CE24T, CE20B, CE20T, CE5SB, CE5ST, CE9SB, CE9ST, CE21SB, CE21ST, CE24SB, CE24ST, CE20SB, CE20ST, CE19SB, CE19ST, CEBCB, CEBCT, CEBVB, CEBVT, CEBVSC, CEBVN, CEBFB, CEBFT, CEBFSC, CEBFN, CE21CTB, CE21CTT, CE11CTB, CE11CTT, CE19CTB, CE19CTT, CE9CTB, CE9CTT, CE5CTB, CE5CTT, CE21FTB, CE21FTT, CE11FTB, CE11FTT, CE19FTB, CE19FTT, CE9FTB, CE9FTT, CE5FTB, CE5FTT, TI21B, TI21T, TI11B, TI11T, TI24B, TI24T, TI20B, TI20T, TI19BCB, TI19BCT, TI19BVB, TI19BVT, TI19BFB, TI19BFT, TI09BVB, TI09BVT, TI09BFB, TI09BFT, ROTN, ROTN50, ROTN100, RORTD21, RORTD11, RORTD24, RORTD20, RORTD19, RORTD9, RORTD5, ID_SUCURSALA) VALUES(S.AN, S.LUNA, S.ID_FACT, S.NRACT, S.SERIE_ACT, S.ID_FDOC, S.DATAACT, S.DATAIREG, S.ID_PART, S.COD, S.TOTCTVA, S.TOTFTVATAX, S.TOTTVATAX, S.TOTNETAX,
          (CASE
          WHEN NVL(S.RO21B, 0) <> 0 AND NVL(S.RO21NT, 0) <> 0 AND
               NVL(S.RO21NT, 0) = NVL(S.RO21T, 0) THEN
           NVL(S.RO21NB, 0)
          ELSE
           NVL(S.RO21B, 0)
        END), S.RO21T,(CASE
          WHEN NVL(S.RO11B, 0) <> 0 AND NVL(S.RO11NT, 0) <> 0 AND
               NVL(S.RO11NT, 0) = NVL(S.RO11T, 0) THEN
           NVL(S.RO11NB, 0)
          ELSE
           NVL(S.RO11B, 0)
        END), S.RO11T, (CASE
          WHEN NVL(S.RO24B, 0) <> 0 AND NVL(S.RO24NT, 0) <> 0 AND
               NVL(S.RO24NT, 0) = NVL(S.RO24T, 0) THEN
           NVL(S.RO24NB, 0)
          ELSE
           NVL(S.RO24B, 0)
        END), S.RO24T,(CASE
          WHEN NVL(S.RO20B, 0) <> 0 AND NVL(S.RO20NT, 0) <> 0 AND
               NVL(S.RO20NT, 0) = NVL(S.RO20T, 0) THEN
           NVL(S.RO20NB, 0)
          ELSE
           NVL(S.RO20B, 0)
        END), S.RO20T,(CASE
          WHEN NVL(S.RO19BCB, 0) <> 0 AND NVL(S.RO19BVB, 0) = 0 AND
               NVL(S.RO19BFB, 0) = 0 AND NVL(S.RO19NT, 0) <> 0 AND
               NVL(S.RO19NT, 0) = NVL(S.RO19BCT, 0) THEN
           NVL(S.RO19NB, 0)
          ELSE
           NVL(S.RO19BCB, 0)
        END), S.RO19BCT,(CASE
          WHEN NVL(S.RO19BVB, 0) <> 0 AND NVL(S.RO19BFB, 0) = 0 AND
               NVL(S.RO19NT, 0) <> 0 AND NVL(S.RO19NT, 0) = NVL(S.RO19BVT, 0) THEN
           NVL(S.RO19NB, 0)
          ELSE
           NVL(S.RO19BVB, 0)
        END), S.RO19BVT,(CASE
          WHEN NVL(S.RO19BFB, 0) <> 0 AND NVL(S.RO19NT, 0) <> 0 AND
               NVL(S.RO19NT, 0) = NVL(S.RO19BFT, 0) THEN
           NVL(S.RO19NB, 0)
          ELSE
           NVL(S.RO19BFB, 0)
        END), S.RO19BFT,(CASE
          WHEN NVL(S.RO09BCB, 0) <> 0 AND NVL(S.RO09BVB, 0) = 0 AND
               NVL(S.RO09BFB, 0) = 0 AND NVL(S.RO9NT, 0) <> 0 AND
               NVL(S.RO9NT, 0) = NVL(S.RO09BCT, 0) THEN
           NVL(S.RO9NB, 0)
          ELSE
           NVL(S.RO09BCB, 0)
        END), S.RO09BCT,(CASE
          WHEN NVL(S.RO09BVB, 0) <> 0 AND NVL(S.RO09BFB, 0) = 0 AND
               NVL(S.RO9NT, 0) <> 0 AND NVL(S.RO9NT, 0) = NVL(S.RO09BVT, 0) THEN
           NVL(S.RO9NB, 0)
          ELSE
           NVL(S.RO09BVB, 0)
        END), S.RO09BVT,(CASE
          WHEN NVL(S.RO09BFB, 0) <> 0 AND NVL(S.RO9NT, 0) <> 0 AND
               NVL(S.RO9NT, 0) = NVL(S.RO09BFT, 0) THEN
           NVL(S.RO9NB, 0)
          ELSE
           NVL(S.RO09BFB, 0)
        END), S.RO09BFT,(CASE
          WHEN NVL(S.RO05B, 0) <> 0 AND NVL(S.RO5NT, 0) <> 0 AND
               NVL(S.RO5NT, 0) = NVL(S.RO05T, 0) THEN
           NVL(S.RO5NB, 0)
          ELSE
           NVL(S.RO05B, 0)
        END), S.RO05T, S.RO21NB, S.RO21NT, S.RO11NB, S.RO11NT, S.RO24NB, S.RO24NT, S.RO20NB, S.RO20NT, S.RO19NB, S.RO19NT, S.RO9NB, S.RO9NT, S.RO5NB, S.RO5NT, S.ROSCN, S.FO21B, S.FO21T, S.FO24B, S.FO24T, S.FO20B, S.FO20T, S.FO19BCB, S.FO19BCT, S.FO19BVB, S.FO19BVT, S.FO19BFB, S.FO19BFT, S.XX21TIB, S.XX21TIT, S.XX11TIB, S.XX11TIT, S.XX19TIB, S.XX19TIT, S.XX9TIB, S.XX9TIT, S.FO09BCB, S.FO09BCT, S.FO09BVB, S.FO09BVT, S.FO09BFB, S.FO09BFT, S.FOSCN, S.CE24B, S.CE24T, S.CE20B, S.CE20T, S.CE5SB, S.CE5ST, S.CE9SB, S.CE9ST, S.CE21SB, S.CE21ST, S.CE24SB, S.CE24ST, S.CE20SB, S.CE20ST, S.CE19SB, S.CE19ST, S.CEBCB, S.CEBCT, S.CEBVB, S.CEBVT, S.CEBVSC, S.CEBVN, S.CEBFB, S.CEBFT, S.CEBFSC, S.CEBFN, S.CE21CTB, S.CE21CTT, S.CE11CTB, S.CE11CTT, S.CE19CTB, S.CE19CTT, S.CE9CTB, S.CE9CTT, S.CE5CTB, S.CE5CTT, S.CE21FTB, S.CE21FTT, S.CE11FTB, S.CE11FTT, S.CE19FTB, S.CE19FTT, S.CE9FTB, S.CE9FTT, S.CE5FTB, S.CE5FTT, S.TI21B, S.TI21T, S.TI11B, S.TI11T, S.TI24B, S.TI24T, S.TI20B, S.TI20T, S.TI19BCB, S.TI19BCT, S.TI19BVB, S.TI19BVT, S.TI19BFB, S.TI19BFT, S.TI09BVB, S.TI09BVT, S.TI09BFB, S.TI09BFT, S.ROTN, S.ROTN50, S.ROTN100, S.RORTD21, S.RORTD11, S.RORTD24, S.RORTD20, S.RORTD19, S.RORTD9, S.RORTD5, S.ID_SUCURSALA);


    <<sfarsit_procedura>>
    null;
  end SCRIE_JC_2007;