<table xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_check_regul_luna</obj_name>
  <obj_hashval>957ac941ddcb4d8bd06a78fee1c9eb8a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_check_regul_luna()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC_MARE RECORD;
  V_REG1CONT RECORD;
  V_REC      RECORD;
  aCODREG            numeric := 0;
  REG1CONT_IDX_LOCAL numeric := 0;
  REG1_IDX_LOCAL     numeric;
  PARAM_REG_DATA     date;
  PARAM_REG_MONEDA   numeric;
  PARAM_REG_CURS     double precision;
  DIFERENTE          numeric := 0;
  COUNTIN            numeric := 0;
  COUNTOUT           numeric := 0;
  NR                 numeric := 0;
BEGIN
  --Florin 07.02.2023 - sinc. Oracle
  --Bogdan 15.08.2020
  FOR V_REC_MARE IN  (SELECT * FROM REG, TMP_PKG_GLOBALS X WHERE TIPREG = 46 AND  AN = ANLUCRU AND  LUNA = LUNALUCRU) LOOP
    DELETE FROM TMP_REG;
    DELETE FROM TMP_REG1;
    DELETE FROM TMP_REG1CONT;
    DELETE FROM TMP_REG;
    INSERT INTO TMP_REG (CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, SimbolMoneda, SimbolBank, Provizion, An, Luna, CODGEST)
    SELECT R.CodReg, R.TipReg, R.NrDoc, R.DataDoc, R.CodBank, R.CodMoneda, R.Curs, R.Dirty, R.Obs, R.CodSubunit,
           M.Simbol AS SIMBOLMONEDA, B.Simbol AS SIMBOLBANK, R.Provizion, R.An, R.Luna, R.CODGEST
    FROM REG R
        LEFT JOIN NMONEDE M ON  M.CODMONEDA = R.CODMONEDA
        LEFT JOIN NBANK   B ON  B.CODBANK   = R.CODBANK
    WHERE CODREG = V_REC_MARE.CODREG;

    BEGIN
      SELECT CODREG INTO aCODREG FROM TMP_REG;
    EXCEPTION WHEN OTHERS THEN
      aCODREG := 0;
    END;

    IF  aCODREG = 0 THEN  return; END IF;

    DELETE FROM TMP_REG1CONT_MARTOR;
    REG1CONT_IDX_LOCAL := 0;

    FOR V_REG1CONT IN (
      SELECT SUM( SoldDoc) AS SOLDDOC,
              SUM( SoldDocVal) AS SOLDDOCVAL,
              SUM( SoldDocReg) AS SOLDDOCREG,
              SUM( (SoldDocReg) - (SoldDocVal) ) AS DIFERENTA,
              Cont
      FROM REG1 R1
      WHERE R1.CODREG = aCODREG
      GROUP BY Cont
      )
    LOOP
      REG1CONT_IDX_LOCAL := REG1CONT_IDX_LOCAL + 1;
      INSERT INTO TMP_REG1CONT_MARTOR (CodReg1Cont, SoldDoc, SoldDocVal, SoldDocReg, Diferenta, Cont)
      values (-1 * REG1CONT_IDX_LOCAL, V_REG1CONT.SoldDoc, V_REG1CONT.SoldDocVal, V_REG1CONT.SoldDocReg, V_REG1CONT.Diferenta, V_REG1CONT.Cont);
    END LOOP;

    SELECT DataDoc, CodMoneda, Curs
      INTO PARAM_REG_DATA, PARAM_REG_MONEDA, PARAM_REG_CURS
    FROM TMP_REG;

    PERFORM PKG_REG_SetParamsReg( TO_CHAR( PARAM_REG_DATA, 'DD.MM.YYYY'), PARAM_REG_MONEDA, PARAM_REG_CURS::NUMERIC);
    DELETE FROM TMP_REG1;
    REG1_IDX_LOCAL := 0;

    PERFORM PKG_REGPART_MAKE_REGPART_LUNA();

    FOR V_REC IN (SELECT RP.*, P.DEN_PART FROM TMP_REGPART_LUNA RP LEFT JOIN NPART P ON  P.CODPART = RP.CODPART) LOOP
      IF  ABS( V_REC.SoldDoc * TO_NUMBER((current_setting('PKG_REG.CURS_REG', true)),'99999999999.9999999') - V_REC.SoldDocVal) &gt; 0.0000001 THEN
            REG1_IDX_LOCAL := REG1_IDX_LOCAL + 1;
            INSERT INTO TMP_REG1 (CodReg1, CodGeneral, Cont, PrefixDoc, NrDoc, DataDoc, CodPart, DenPart,
                                  SimbolCont, SoldDocVal, SoldDoc, SoldDocReg, Diferenta, Document,
                                  CodGest, Semn, Curs, Semnificatie, CoefProvizion, SUBUNITATEA, CODOBLIGPIF
                                 )
            values (
              -1 * REG1_IDX_LOCAL, V_REC.CodGeneral, V_REC.ICONT, V_REC.PrefixDoc,
              V_REC.NrDoc, V_REC.DataDoc, V_REC.CodPart, V_REC.Den_Part,
              (SELECT PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT
               FROM PKG_PLANCONTURI_GETSIMBOLCONT(NULL, (SELECT PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG.WME_RESULT
                                                         FROM PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(NULL, V_REC.Semnificatie, V_REC.ICont, V_REC.CodIOPart1)))),
              V_REC.SoldDocVal, V_REC.SoldDoc, V_REC.SoldDoc * PARAM_REG_CURS, V_REC.SoldDoc * PARAM_REG_CURS - V_REC.SoldDocVal,
              V_REC.PREFIXDOC || TO_CHAR( V_REC.NRDOC,'9999999999') || '/' || TO_CHAR( V_REC.DATADOC, 'DD.MM.YYYY'),
              V_REC.CodGest, 1, V_REC.Curs, V_REC.Semnificatie, V_REC.CoefProvizion, V_REC.SUBUNITATEA, V_REC.CODOBLIGPIF
            );
      END IF;
    END LOOP;

    FOR V_REC IN (
      SELECT R1.CODREG1, R1.CODREG, O.CONTBANKTRANZACTIE, O.SEMNIFICATIE, T1.TIPDECONT, x.ANLUCRU, x.LUNALUCRU
      FROM TMP_PKG_GLOBALS X, TMP_REG1 R1, OBLIGPIF O, GENERAL G, TREZOR1 T1
      WHERE
           R1.CODOBLIGPIF = O.CODOBLIGPIF
           AND O.SEMNIFICATIE IN (500, 600)
           AND  G.CODGENERAL = O.CODGENERAL
           AND  T1.CODTREZOR1 = G.CODDOC
      )
    LOOP
      UPDATE TMP_REG1 SET
        CONT = (SELECT PKG_TREZOR_CODCONTCEC.WME_RESULT FROM PKG_TREZOR_CODCONTCEC(NULL, V_REC.CONTBANKTRANZACTIE, V_REC.SEMNIFICATIE, V_REC.TIPDECONT, V_REC.OBIECTTRANZ, V_REC.AnLucru, V_REC.LunaLUCRU,NULL))
      WHERE CODREG1 = V_REC.CODREG1;
    END LOOP;

    REG1CONT_IDX_LOCAL := 0;
    FOR V_REG1CONT IN (
      SELECT SUM( SoldDoc) AS SOLDDOC,
        SUM( SoldDocVal) AS SOLDDOCVAL,
        SUM( SoldDocReg) AS SOLDDOCREG,
        SUM( (SoldDocReg) - (SoldDocVal) ) AS DIFERENTA,
        Cont
      FROM TMP_REG1
      GROUP BY   Cont
    ) LOOP
      REG1CONT_IDX_LOCAL := REG1CONT_IDX_LOCAL + 1;
      INSERT INTO TMP_REG1CONT (CodReg1Cont, SoldDoc, SoldDocVal, SoldDocReg, Diferenta, Cont)
      values (-1 * REG1CONT_IDX_LOCAL, V_REG1CONT.SoldDoc, V_REG1CONT.SoldDocVal, V_REG1CONT.SoldDocReg, V_REG1CONT.Diferenta, V_REG1CONT.Cont);
    END LOOP;

    DIFERENTE := 0;
    SELECT COUNT( *) INTO COUNTIN FROM TMP_REG1CONT_MARTOR;

    SELECT COUNT( *) INTO COUNTOUT FROM TMP_REG1CONT;

    IF  COUNTIN &lt;&gt; COUNTOUT
    THEN  DIFERENTE := 1;
    ELSE
      FOR V_REC in (
          SELECT INTBL.CONT, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT, INTBL.SOLDDOCREG SOLDREGIN, OUTTBL.SOLDDOCREG SOLDREGOUT
          FROM TMP_REG1CONT_MARTOR INTBL LEFT JOIN TMP_REG1CONT OUTTBL ON  OUTTBL.CONT = INTBL.CONT
          union
          SELECT OUTTBL.CONT, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT, INTBL.SOLDDOCREG SOLDREGIN, OUTTBL.SOLDDOCREG SOLDREGOUT
          FROM TMP_REG1CONT OUTTBL LEFT JOIN TMP_REG1CONT_MARTOR INTBL ON  INTBL.CONT = OUTTBL.CONT
      )
      LOOP
        IF (COALESCE( V_REC.SOLDIN, 0) &lt;&gt; COALESCE( V_REC.SOLDOUT, 0))  OR (COALESCE( V_REC.SOLDREGIN, 0) &lt;&gt; COALESCE( V_REC.SOLDREGOUT, 0))   THEN
            DIFERENTE := 1;
            EXIT ;
        END IF;
      END LOOP;
    END IF;

    IF  DIFERENTE &gt; 0 THEN
        SELECT COUNT( *) INTO NR FROM JURNAL1 WHERE TIPDOC = 46 AND  CODDOC = aCODREG;
        IF  NR = 0 THEN
          INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, DIRTY)
          values (NEXTVAL('SEQ_JURNAL1_CODJURNAL1'), aCODREG, 46, -1, 1);
        ELSE
          UPDATE JURNAL1 set DIRTY = 1 where  TIPDOC = 46 AND  CODDOC = aCODREG;
        END IF;
    END IF;

  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_oferte_agent_si_fara_agent_4php</obj_name>
  <obj_hashval>7450506142718a1f5779930fd8ec28bc</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_oferte_agent_si_fara_agent_4php(refcursor, numeric, character varying, character varying, character varying, character varying, character varying, character varying, character varying)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
  DECLARE
    S varchar;
    OFERTACURSOR REFCURSOR;
    FILTRU_PART varchar := '';
  FILTRU_NRDOC varchar := '';
  FILTRU_DATASTART varchar := '';
  FILTRU_DATAEND varchar := '';
  FILTRU_DATAOFERTA varchar := '';
    FILTRU_DATAREF varchar := '';
  FILTRU_OBS   varchar := '';
  begin
    IF COALESCE ($3, '?') &lt;&gt; '?' THEN
      FILTRU_PART := coalesce (' AND (UPPER(DEN_PART) LIKE '
      || '''%','')
      || coalesce (UPPER ($3) ,'')
      || '%'' OR coalesce(PARTENER, 0) = 0)';
    END IF;
  IF COALESCE ($5, '?') not in ('?', '') THEN
      FILTRU_NRDOC := coalesce (' AND UPPER(NRDOC::varchar) LIKE '
      || '''%','')
      || coalesce (UPPER ($5) ::varchar ,'')
      || '%''';
    END IF;
  IF COALESCE ($6, '?') not in ('?', '') THEN
      FILTRU_DATASTART := ' AND DATASTART = TO_DATE('''
      || $6
      || ''',''DD-MM-YYYY'') ';
    END IF;
  IF COALESCE ($7, '?') not in ('?', '') THEN
      FILTRU_DATAEND := ' AND DATAEND = TO_DATE('''
      || $7
      || ''',''DD-MM-YYYY'') ';
    END IF;
    IF COALESCE ($9, '?') not in ('?', '') THEN
      FILTRU_DATAOFERTA := ' AND DATAOFERTA = TO_DATE('''
      || $9
      || ''',''DD-MM-YYYY'') ';
    END IF;
    IF COALESCE ($4, '?') not in ('?', '') THEN
      FILTRU_DATAREF := ' AND DATASTART &lt;= TO_DATE ('''
            || $4
      || ''',''DD-MM-YYYY'')
                      AND DATAEND &gt;= TO_DATE ('''
            || $4
      || ''',''DD-MM-YYYY'') ';
    END IF;
  IF COALESCE ($8, '?') not in ('?', '') THEN
      FILTRU_OBS := coalesce (' AND UPPER(OBS) LIKE '
      || '''%','')
      || coalesce (UPPER ($8) ,'')
      || '%''';
    END IF;
    S := '
        SELECT *
        FROM (   SELECT OFE.*
            FROM (   SELECT CODOFERTA, TIPDOC, ANULAT, BLOCAT,
                  OPERAT, SERIE, NRDOC, DATASTART,
                  DATAEND, PARTENER, AN, LUNA,
                  OBS, MONEDA, CODLOCATIE, SUBUNITATEA,
                  CODFISCAL, USERID, DATACREARE, DATAOFERTA,
                  PE_CLASA, DEN_PART, DEN_MONEDA, DEN_LOCALIT,
                  SUBUNITATEDOC, SEDIU, NUMEAGENT, PCNume,
                  PCTel, PCEmail, Aprobari, NRI,
                  Utilizator, Valoare
                FROM (   SELECT O.CODOFERTA, O.TIPDOC, O.ANULAT, O.BLOCAT,
                      O.OPERAT, C.SERIE, O.NRDOC, O.DATASTART,
                      O.DATAEND, O.PARTENER, O.AN, O.LUNA,
                      O.OBS, O.MONEDA, O.CODLOCATIE, O.SUBUNITATEA,
                      O.CODFISCAL, O.USERID, O.DATACREARE, O.DATAOFERTA,
                      (case when O.TipBeneficiar = 1 then ''DA'' else ''NU'' end) PE_CLASA,
                      Coalesce (P.Den_Part, CP.Den_Clasep, ''...'') Den_Part, M.Den_Moneda, L.Den_Localit,
                      S.DEN_SUBUNIT       SUBUNITATEDOC, SED.OBS SEDIU,
                      (case when A.CodPers = 0 then A.Nume else A.NUME ||'' '' ||A.PRENUME end) NUMEAGENT, O.NRI, PC.Nume
                        ||'' ''
                        ||PC.Prenume PCNume, PC.TELEFON PCTel, PC.EMAIL PCEmail, UT.UserName Utilizator, (   SELECT Sum (coalesce (O1.CANTMIN * O1.PRET * Coalesce (1 + O1.PROCADAOS / 100,1) * Coalesce (1 + O1.ProcDiscount / 100,1) ,0))
                        FROM OFERTA1 O1
                        WHERE
                          O1.CodOferta = O.CodOferta) Valoare, '' '' AS Aprobari
                    FROM OFERTA                             O
                      LEFT JOIN NPART                     P   ON coalesce (O.Partener, 0) = P.Codpart AND coalesce (TipBeneficiar, 0) = 0
                      LEFT JOIN NCLASEP                   CP  ON coalesce (O.CodClaseP, 0) = CP.CodClaseP AND coalesce (TipBeneficiar, 0) = 1
                      LEFT JOIN NAGENDA                   SED ON SED.Codagenda = O.CodLocatie
                      LEFT JOIN NLOCALIT                  L   ON L.Codlocalit = SED.CodLocalit
                      LEFT JOIN NMONEDE                   M   ON M.CodMoneda = O.Moneda
                      LEFT JOIN NSUBUNIT                  S   ON S.CODSUBUNIT = O.SUBUNITATEA
                      LEFT JOIN NPERS                     A   ON A.CODPERS = coalesce (O.AGENT,0)
                      LEFT JOIN NPERSCONTACT              PC  ON PC.CodPart = P.CodPart AND PC.CodPersC = O.CodPersC
                      LEFT JOIN DOCCARNETE                C   ON C.CODCARNET = O.CARNETDOC
                      LEFT JOIN TMP_UTILIZATOR            UT  ON UT.CODUTILIZATOR = O.USERID
                    WHERE
                      O.TipDoc = 50
                      AND O.OFERTAT = 1
                      AND (O.AGENT = '
            || coalesce ( ($2) ::varchar::varchar ,'')
            || '
                        OR coalesce (O.AGENT, 0) = 0)
                      AND (coalesce (O.ToateSubunit,0) = 1
                        or O.SUBUNITATEA = ' || (current_setting('PKG_GLOBALS.SUBUNITATE', True))::numeric || ')) OF1) OFE) OF2
        WHERE
          1 = 1'
            || coalesce (Filtru_Part,'')
      || coalesce (FILTRU_NRDOC,'')
      || coalesce (FILTRU_DATASTART,'')
      || coalesce (FILTRU_DATAEND,'')
          || coalesce (FILTRU_DATAOFERTA,'')
          || coalesce (FILTRU_DATAREF,'')
      || coalesce (FILTRU_OBS,'')
      || ' ORDER BY DEN_PART, NRDOC DESC';
    OPEN $1 FOR EXECUTE S;
  return next $1;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_interne_for_jurnal</obj_name>
  <obj_hashval>2e8834ff8d002b905325c4663002c4a2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_interne_for_jurnal(startrec numeric, endrec numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  LT         RECORD;
  NR         double precision := 0;
  LUNAREF    REFCURSOR;
  IOPART1REC RECORD;
BEGIN
  --Stef 03.03.2023
  --Florin 09.11.2022 - sinc. Oracle
  --Florin 29.06.2022 - fnc_getprocenttvaart
  --Laura 27.01.2022 - sinc. Oracle (29.12.2021)
  --Bogdan 15.08.2020
  PERFORM pkg_service_EMPTY_DOC_INTERNE_FOR_JURNAL();

  INSERT INTO TMP_TRANSF (
        CODTRANSF, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, SERIADOC,
        CARNETDOC, NRDOC, DATADOC, CARNETAE, NRAE, VALDOC, TVADOC, OBS,
        AN, LUNA, VALSUPLIM, CONTSUPLIM, TIPREPSUPLIM, DELEGAT, CODPART,
        STORNO, TIPMODIFPRET, SUBUNITATEA, REEVALUARE, Corectie)
  SELECT CODTRANSF, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, SERIADOC,
      CARNETDOC, NRDOC, DATADOC, CARNETAE, NRAE, VALDOC, TVADOC, OBS,
      AN, LUNA, VALSUPLIM, CONTSUPLIM, TIPREPSUPLIM, DELEGAT, CODPART,
      STORNO, TIPMODIFPRET, SUBUNITATEA, REEVALUARE, Corectie
  FROM (
    SELECT row_number() over() AS RN, S.*
    FROM (
        SELECT CODTRANSF, TIPDOC, ANULAT, BLOCAT, OPERAT,
            PREFIXDOC, SERIADOC, CARNETDOC, NRDOC, DATADOC,
            CARNETAE, NRAE, VALDOC, TVADOC, OBS, AN, LUNA, VALSUPLIM,
            CONTSUPLIM, TIPREPSUPLIM, DELEGAT, CODPART, STORNO,
            TIPMODIFPRET, SUBUNITATEA, REEVALUARE, Corectie
        FROM TRANSF
        WHERE  AN * 12 + LUNA = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X)
          AND PKG_SERVICE_IS_DIRTY_DOC(TIPDOC, CODTRANSF) = 1
        ORDER BY  CODTRANSF
      ) S
  ) A_PG
  WHERE   RN &gt;= STARTREC AND  RN &lt;= ENDREC;

  INSERT INTO TMP_TRANSF1(
        CODTRANSF1, CODTRANSF, INDEXLOCAL, TIPLINIE,
        UMSEC, CODCONT, CODOBIECT, PU, CANT, TVA, CodCentru,
        DENUM, VALOARE, PARITATE, PROCTVA, CODTVA, CODACCIZE,
        CODTAXA1, CODTAXA2, DENOBIECT, CODANALIZANOD )
  SELECT * FROM (
      SELECT T1.CODTRANSF1, T1.CODTRANSF, T1.INDEXLOCAL, TIPLINIE,
      T1.UMSEC, T1.CODCONT, T1.CODOBIECT, T1.PU * U1.PARITATE, T1.CANT / U1.PARITATE, T1.TVA,
      t1.CodCentru, U1.DEN_UM1, T1.CANT * T1.PU, U1.PARITATE,
      fnc_getprocenttvaart(A.CODARTICOL, TG.ANLUCRU, TG.LUNALUCRU),
      NART1LUNA.CODTVA, NART1LUNA.CODACCIZE, NART1LUNA.CODTAXA1, NART1LUNA.CODTAXA2, O.DENUMIRE, T1.CODANALIZANOD
      FROM TRANSF1 T1
        CROSS JOIN TMP_PKG_GLOBALS TG
        LEFT  JOIN NARTOBJ O       ON  O.CODOBIECT  = T1.CODOBIECT
        LEFT  JOIN NART    A       ON  A.CODARTICOL = O.CODARTICOL
        LEFT  JOIN NART1   NART1LUNA ON  NART1LUNA.CODARTICOL = O.CODARTICOL AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP
        LEFT  JOIN NUM1    U1      ON  U1.CODUM1 = T1.UMSEC
      WHERE
         EXISTS (SELECT * FROM TMP_TRANSF WHERE CODTRANSF = T1.CODTRANSF)
      ) B_PG
  ORDER BY INDEXLOCAL ;

  INSERT INTO TMP_LIVR (
      CODLIVR, CODIES, CODINTR, CODTRANSF, CARNETLIVR,
      NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT
  )
  (
    SELECT CODLIVR, CODIES, CODINTR, CODTRANSF, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT
    FROM LIVR L
    WHERE
       EXISTS (SELECT * FROM TMP_TRANSF WHERE CODTRANSF = L.CODTRANSF)
  );

  INSERT INTO TMP_LIVR1(
        CODLIVR1, CODLIVR, CODIES1, CODNIRSTOC, CANT, CODNIRSER, PMP,
        UMSEC, DENUM, PARITATE, GEST, CODIOART, CONTINTERMED, CODPROIECT,
        CODOBIECT, DENOBIECT, CODLIVRTOT, TIPLINIE, PRETINREG, ADAOS, TVANEEX,
        PRETACHIZ, TIPSERIE, CODSERIE, SERIE, TG, PUMAXIMAL, FURN, DATAACHIZ,
        TIPDOCACHIZ, CODGESTPROD, SUBUNITATEA, PROVIZION
    )
  (
    SELECT L1.CODLIVR1, L1.CODLIVR, L1.CODIES1, L1.CODNIRSTOC,
        L1.CANT / U1.PARITATE, L1.CODNIRSER, L1.PMP, L1.UMSEC, U1.DEN_UM1, U1.PARITATE,
        CASE WHEN LV.CODLIVR1 IS NULL  THEN N.GEST ELSE LV.GEST END ,
        CASE WHEN LV.CODLIVR1 IS NULL  THEN NS.CODIOART ELSE LV.CODIOART END ,
        COALESCE( L1.CONTINTERMED, 0),
        COALESCE( L1.CODPROIECT, 0),
        CASE WHEN LV.CODLIVR1 IS NULL  THEN NS.CODOBIECT ELSE LV.CODOBIECT END ,
        CASE WHEN LV.CODLIVR1 IS NULL  THEN (SELECT PKG_SELECTARTICOLE_GETDENOBIECTEXT.WME_RESULT FROM PKG_SELECTARTICOLE_GETDENOBIECTEXT(NULL, NS.CODOBIECT))
             ELSE (SELECT PKG_SELECTARTICOLE_GETDENOBIECTEXT.WME_RESULT FROM PKG_SELECTARTICOLE_GETDENOBIECTEXT(NULL, LV.CODOBIECT))
         END ,
         0, '=',
         CASE WHEN LV.CODLIVR1 IS NULL  THEN NS.PRET * U1.PARITATE ELSE LV.PRETINREG * U1.PARITATE END ,
         CASE WHEN LV.CODLIVR1 IS NULL  THEN NS.ADAOS * U1.PARITATE ELSE (  LV.PRETINREG - LV.PRETACHIZ)  * U1.PARITATE END ,
         CASE WHEN LV.CODLIVR1 IS NULL  THEN NS.TVA ELSE LV.TVANEEX END ,
         CASE WHEN LV.CODLIVR1 IS NULL  THEN (  NS.PRET - NS.ADAOS)  * U1.PARITATE ELSE LV.PRETACHIZ * U1.PARITATE END ,
         CASE WHEN LV.CODLIVR1 IS NULL  THEN NS.TIPSERIE ELSE 0 END ,
         (SELECT CODSERIE FROM NIRSER WHERE CODNIRSER = L1.CODNIRSER),
         (SELECT SERIE FROM NSERII WHERE CODSERIE = (SELECT CODSERIE FROM NIRSER WHERE CODNIRSER = L1.CODNIRSER)),
         NS.TG, NS.PUMAXIMAL, NS.FURN, NS.DATAACHIZ, NS.TIPDOCACHIZ, NS.CODGESTPROD, NS.SUBUNITATEA, NS.PROVIZION
        FROM LIVR1 L1
          LEFT JOIN NIRSTOC NS ON  NS.CODNIRSTOC = L1.CODNIRSTOC
          LEFT JOIN LIVRVAL LV ON  LV.CODLIVR1   = L1.CODLIVR1
          LEFT JOIN NIR     N  ON  N.CODNIR      = NS.CODNIR
          LEFT JOIN LIVR    L  ON  L.CODLIVR     = L1.CODLIVR, NUM1 U1
        WHERE
             CODUM1 = L1.UMSEC AND  EXISTS (SELECT * FROM TMP_TRANSF WHERE CODTRANSF = L.CODTRANSF)
    );

    INSERT INTO TMP_LIVRTOT (
              CODLIVRTOT, CODLIVR, CODIESINT1, UMSEC, GEST,
              CODIOART, CODOBIECT, CONTINTERMED, CODPROIECT,
              DENUM, PARITATE, DENGESTIOART, DIFPRET, ACCIZELATRANSFER,
              ARETVANEEX, MG, CONT, SUFIXTVANEEX, STOCREZOLVAT, CANT,
              PRETINREG, PRETACHIZ
              )
    SELECT row_number() over(),CODLIVR,CODIES1,UMSEC,GEST,CODIOART,CINTERMED,CPROIECT,CODOBIECT,DENUM,
        PARITATE,DENGESTIOART,DIFPRET,ACCIZELATRANSFER,ARETVANEEX,MG,CONT,TVANEEX,STOCREZOLVAT,CANT,
        PRETINREG,PRETACHIZ
    FROM (
        SELECT L1.CODLIVR, L1.CODIES1, L1.UMSEC,
          L1.GEST, L1.CODIOART, COALESCE( L1.CONTINTERMED, 0) CINTERMED,
          COALESCE( L1.CODPROIECT, 0) CPROIECT, L1.CODOBIECT, L1.DENUM,
          L1.PARITATE,
          G.DEN_GEST || CHR(13) || IO.DEN_IOART DENGESTIOART,
          IOALUNA.DIFPRET,
          IOALUNA.ACCIZELATRANSFER, IOALUNA.ARETVANEEX, IOALUNA.MG,
          IOALUNA.CONT, IOALUNA.TVANEEX, 1 STOCREZOLVAT,
          SUM( L1.CANT) CANT, SUM( L1.PRETINREG * L1.CANT) / case WHEN  SUM( L1.CANT)=0 THEN 1 ELSE  SUM( L1.CANT)END  PRETINREG,
          SUM( L1.PRETACHIZ * L1.CANT) / CASE WHEN  SUM( L1.CANT)=0 THEN 1 ELSE  SUM( L1.CANT) end PRETACHIZ
        FROM TMP_LIVR1 L1
          CROSS JOIN TMP_PKG_GLOBALS TG
          LEFT  JOIN IOART1 IOALUNA   ON  IOALUNA.CODIOART = L1.CODIOART AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN IOALUNA.ALSTART AND IOALUNA.ALSTOP
          LEFT  JOIN LIVR   L     ON  L.CODLIVR = L1.CODLIVR
          LEFT  JOIN NGEST  G     ON  G.CODGEST = L1.GEST
          LEFT  JOIN IOART  IO    ON  IO.CODIOART = L1.CODIOART
    WHERE
       EXISTS (SELECT * FROM TMP_TRANSF WHERE CODTRANSF = L.CODTRANSF)
    GROUP BY
      L1.CODLIVR, L1.CODIES1, L1.CODOBIECT, L1.UMSEC, L1.GEST, L1.CODIOART,
      COALESCE( L1.CONTINTERMED, 0), COALESCE( L1.CODPROIECT, 0), L1.DENUM, L1.PARITATE,
      G.DEN_GEST || CHR(13) || IO.DEN_IOART, IOALUNA.DIFPRET, IOALUNA.ACCIZELATRANSFER,
      IOALUNA.ARETVANEEX, IOALUNA.MG, IOALUNA.CONT, IOALUNA.TVANEEX
    ) C_PG
    ORDER BY
      CODLIVR , CODIES1 ;

  UPDATE TMP_LIVRTOT T SET
      --CODLIVRTOT = ROWNUM,
      DENOBIECT = (SELECT PKG_SELECTARTICOLE_GETDENOBIECTEXT.WME_RESULT FROM PKG_SELECTARTICOLE_GETDENOBIECTEXT(NULL, T.CODOBIECT)),
      INDEXMASTER = (SELECT INDEXLOCAL FROM TMP_TRANSF1 WHERE CODTRANSF1 = T.CODIESINT1),
      GESTIMPLICITA = (
              SELECT GESTIMPLICITA
              FROM NART
              WHERE
                 CODARTICOL = (SELECT PKG_SELECTARTICOLE_GETARTOFOBJECT.WME_RESULT FROM PKG_SELECTARTICOLE_GETARTOFOBJECT(NULL, T.CODOBIECT))
            ),
      PROCTVA = fnc_getprocenttvaart(
                                (SELECT PKG_SELECTARTICOLE_GETARTOFOBJECT.WME_RESULT FROM PKG_SELECTARTICOLE_GETARTOFOBJECT(NULL, T.CODOBIECT)),
                                (SELECT ANLUCRU FROM TMP_PKG_GLOBALS),
                                (SELECT LunaLUCRU FROM TMP_PKG_GLOBALS ));

  INSERT INTO TMP_LIVRVAL
  SELECT * FROM LIVRVAL WHERE CODLIVR1 IN (SELECT CODLIVR1 FROM TMP_LIVR1);

  FOR LT IN (SELECT * FROM TMP_LIVRTOT LT) LOOP
    UPDATE  TMP_LIVR1 L1
     SET CODLIVRTOT    = LT.CODLIVRTOT,
          GESTIMPLICITA = LT.GESTIMPLICITA
    WHERE
           COALESCE( LT.CODLIVR, 0)      = COALESCE( L1.CODLIVR, 0)
      AND  COALESCE( LT.CODIESINT1, 0)   = COALESCE( L1.CODIES1, 0)
      AND  COALESCE( LT.UMSEC, 0)        = COALESCE( L1.UMSEC, 0)
      AND  COALESCE( LT.PARITATE, 0)     = COALESCE( L1.PARITATE, 0)
      AND  COALESCE( LT.GEST, 0)         = COALESCE( L1.GEST, 0)
      AND  COALESCE( LT.CODIOART, 0)     = COALESCE( L1.CODIOART, 0)
      AND  COALESCE( LT.CONTINTERMED, 0) = COALESCE( L1.CONTINTERMED, 0);
  END LOOP;

  INSERT INTO TMP_NIR (CODNIR, CODINTR, CODTRANSF, CARNETNIR, NRNIR, DATANIR, GEST, OBS, TIPNIR, ANULAT, BLOCAT, OPERAT, VALOARE)
  (SELECT N.CODNIR, N.CODINTR, N.CODTRANSF, N.CARNETNIR, N.NRNIR, N.DATANIR, N.GEST, N.OBS,
          N.TIPNIR, N.ANULAT, N.BLOCAT, N.OPERAT,
         (SELECT SUM( NS.CANTNIR * NS.PRET) FROM NIRSTOC NS WHERE NS.CODNIR = N.CODNIR)
   FROM NIR N
   WHERE EXISTS (SELECT * FROM TMP_TRANSF WHERE CODTRANSF = N.CODTRANSF)
  );

  INSERT INTO TMP_NIRSTOC  (
          CODNIRSTOC, CODNIR, CODINTR1, CODTRANSF1, CODNIRSTOCPARINTE,
          FURN, CANTNIR, UMSEC, CODOBIECT, CODIOART, PRET, ROTLEI, ROTVALUTA,
          CODLOCATIE, PUMAXIMAL, ADAOS, TVA, TIPSERIE, CODLIVR1, REST,
          PROCENTADAOS, Supliment, TG, DATAACHIZ, DENUM, PARITATE, VALOARE,
          CANTFURN, MG, DIFPRET, ACCIZELATRANSFER, ARETVANEEX, PUSTANDARD,
          PRETACHIZ, PROCTVA, DISCLIKISTOC, DENOBIECT, CANTUM1, CANTUM2,
          UM1, UM2, RelatieUM1, D1, D2, D3, CODGESTPROD, TIPDOCACHIZ, PUVAL, PROVIZION
        )
  SELECT *
  FROM (
      SELECT NS.CODNIRSTOC, NS.CODNIR, NS.CODINTR1, NS.CODTRANSF1, NS.CODNIRSTOCPARINTE,
      NS.FURN, NS.CANTNIR / U1.PARITATE, NS.UMSEC, NS.CODOBIECT, NS.CODIOART,
      NS.PRET * U1.PARITATE, NS.ROTLEI, NS.ROTVALUTA, NS.CODLOCATIE,
      NS.PUMAXIMAL * U1.PARITATE, NS.ADAOS * U1.PARITATE, NS.TVA,
      NS.TIPSERIE, NS.CODLIVR1, NS.REST, NS.PROCENTADAOS, NS.Supliment,
      NS.TG, NS.DATAACHIZ, U1.DEN_UM1, U1.PARITATE, NS.CANTNIR * NS.PRET,
      NS.CANTFURN / U1.PARITATE, IOALUNA.MG, IOALUNA.DIFPRET, IOALUNA.ACCIZELATRANSFER,
      IOALUNA.ARETVANEEX, IOALUNA.PUSTANDARD,
      ( NS.PRET - NS.ADAOS - CASE WHEN  COALESCE( NS.CANTNIR, 0) = 0 THEN 0 ELSE COALESCE( NS.SUPLIMENT, 0) / (  NS.CANTNIR / U1.PARITATE)    END )  * u1.Paritate,
      fnc_getprocenttvaart(A.CODARTICOL, TG.ANLUCRU, TG.LUNALUCRU),
      DISCLIKISTOC, O.DENUMIRE, NS.CANTUM1, NS.CANTUM2, A.UM1, A.UM2, A.RelatieUM1, NS.D1, NS.D2, NS.D3,
      NS.CODGESTPROD, NS.TIPDOCACHIZ, NS.PUVAL, NS.PROVIZION
  FROM NIRSTOC NS
    CROSS JOIN TMP_PKG_GLOBALS TG
    LEFT  JOIN IOART1  IOALUNA  ON  IOALUNA.CODIOART = NS.CODIOART AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN IOALUNA.ALSTART AND IOALUNA.ALSTOP
    LEFT  JOIN NARTOBJ O     ON  O.CODOBIECT  = NS.CODOBIECT
    LEFT  JOIN NART    A     ON  A.CODARTICOL = O.CODARTICOL, NUM1 U1
  WHERE
    NS.CODNIR IN (SELECT CODNIR FROM TMP_NIR)
    AND  U1.CODUM1 = NS.UMSEC
  ) D_PG
  ORDER BY
    CODNIR , CODINTR1 ;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_setzerorecords</obj_name>
  <obj_hashval>8a0b3b0b0b2ff3ed9f6564621ab23e70</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_setzerorecords()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  NR numeric;
BEGIN
  --Florin 05.08.2025 - sinc. Oracle
  --Florin 05.04.2025 - sinc. Oracle
  --Florin 14.03.2025 - sinc. Oracle
  --Florin 29.09.2022 - sinc. Oracle (27.09.2022)
  --Florin 03.12.2021 - sinc. Oracle (39627)
  --Laura 11.10.2021 - sinc Oracle (11.10.2021)
  --Laura 08.10.2021 - sinc Oracle (08.10.2021)
  --Bogdan 23.09.2020 -- adaugat ncontt
  SELECT COUNT ( *) INTO Nr FROM ANALIZA WHERE CodANALIZA = 0;
  IF Nr = 0 THEN
    INSERT INTO ANALIZA (CodANALIZA, DEN_ANALIZA)
    VALUES (0, '... nedefinit ...');
  ELSE
    UPDATE ANALIZA SET den_ANALIZA = '... nedefinit ...' WHERE codANALIZA = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM ELEMENTE WHERE CodELEMENT = 0;
  IF Nr = 0 THEN
    INSERT INTO ELEMENTE (CodELEMENT, DEN_ELEMENT)
    VALUES (0, '... nedefinit ...');
  ELSE
    UPDATE ELEMENTE SET den_ELEMENT = '... nedefinit ...' WHERE codELEMENT = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM ELEMBUGET WHERE CodELEMBUGET = 0;
  IF Nr = 0 THEN
    INSERT INTO ELEMBUGET (CodELEMBUGET, ELEMENT, SIMBOL)
    VALUES (0, '... nedefinit ...', '... nedefinit ...');
  ELSE
    UPDATE ELEMBUGET SET ELEMENT = '... nedefinit ...', simbol = '... nedefinit ...' WHERE codELEMBUGET = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NART WHERE CodARTICOL = 0;
  IF Nr = 0 THEN
    INSERT INTO NART (CodARTICOL, DEN_ARTICOL)
    VALUES (0, '... nedefinit ...');
  ELSE
    UPDATE nart SET den_articol = '... nedefinit ...' WHERE codarticol = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NARTOBJ WHERE CodOBIECT = 0;
  IF Nr = 0 THEN
    INSERT INTO NARTOBJ (CodOBIECT, CodARTICOL, DENUMIRE)
    VALUES (0, 0, '... nedefinit ...');
  ELSE
    UPDATE nartObj SET denumire = '... nedefinit ...' WHERE codobiect = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM FUNCTII WHERE CodFUNCTIE = 0;
  IF Nr = 0 THEN
    INSERT INTO FUNCTII (CodFUNCTIE, DENUMIRE)
    VALUES (0, '... nedefinit ...');
  ELSE
    UPDATE FUNCTII SET denumire = '... nedefinit ...' WHERE codFUNCTIE = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM PROIECT WHERE CODPROIECT = 0;
  IF Nr = 0 THEN
    INSERT INTO PROIECT (CODPROIECT, CODOBIECTPROD, VERSIUNE)
    VALUES (0, 0, '... nedefinit ...');
  ELSE
    UPDATE PROIECT SET CODOBIECTPROD = 0, VERSIUNE = '... nedefinit ...' WHERE CODPROIECT = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM PRODCOMP WHERE CODPRODCOMP = 0;
  IF Nr = 0 THEN
    INSERT INTO PRODCOMP (CODPRODCOMP, CODOBIECT, OBS)
    VALUES (0, 0, '... nedefinit ...');
  ELSE
    UPDATE PRODCOMP SET CODOBIECT = 0, OBS = '... nedefinit ...' WHERE CODPRODCOMP = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM PRODCOMP WHERE CODPRODCOMP = 1;
  IF Nr = 0 THEN
    INSERT INTO PRODCOMP (CODPRODCOMP, CODOBIECT, OBS)
    VALUES (1, 0, '... consum nedefinit...');
  ELSE
    UPDATE PRODCOMP SET CODOBIECT = 0, OBS = '... consum nedefinit ...' WHERE CODPRODCOMP = 1;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM GRECHIV WHERE CODGRECHIV = 0;
  IF Nr = 0 THEN
    INSERT INTO GRECHIV (CODGRECHIV, DENUMIRE)
    VALUES (0, '... nedefinita ...');
  ELSE
    UPDATE GRECHIV SET DENUMIRE = '... nedefinita ...' WHERE CODGRECHIV = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM SCENARIILIVR WHERE CODSCENARIU = 0;
  IF Nr = 0 THEN
    INSERT INTO SCENARIILIVR (CODSCENARIU, DEN_SCENARIU)
    VALUES (0, '... nedefinit ...');
  ELSE
    UPDATE SCENARIILIVR SET DEN_SCENARIU = '... nedefinit ...' WHERE CODSCENARIU = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NTAXE WHERE CodTAXA = 0;
  IF Nr = 0 THEN
    INSERT INTO NTAXE (CodTAXA, Den_TAXA)
    VALUES (0, '... nedefinita ...');
  ELSE
    UPDATE ntaxe SET den_taxa = '... nedefinita ...' WHERE codtaxa = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NActivit WHERE CODACTIVIT = 0;
  IF Nr = 0 THEN
    INSERT INTO nactivit (CODACTIVIT, DEN_ACTIVIT)
    VALUES (0, '... nedefinita ...');
  ELSE
    UPDATE NActivit SET den_activit = '... nedefinita ...' WHERE codactivit = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM formatii WHERE CodFormatie = 0;
  IF Nr = 0 THEN
    INSERT INTO formatii (CodFormatie, Den_Formatie, simbol, codgest)
    VALUES (0, '... nedefinita ...', '...', 0);
  ELSE
    UPDATE formatii SET den_Formatie = '... nedefinita ...' WHERE codFormatie = 0;
  END IF;

  -- prestatii
  SELECT COUNT(*) INTO Nr FROM prestatii WHERE Codprestatie = 0;
  IF Nr = 0 THEN
    INSERT INTO prestatii (Codprestatie, cod, denumire) values (0, '... nedefinit ...', '...nedefinit...');
  ELSE
    UPDATE prestatii SET cod ='... nedefinit ...', denumire ='... nedefinit ...' WHERE codprestatie = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NTIPSEDII WHERE CODTIPSEDIU = 0;
  IF Nr = 0 THEN
    INSERT INTO NTIPSEDII (CODTIPSEDIU, DENUMIRE)
    VALUES (0, '... nedefinit ...');
  ELSE
    UPDATE ntipsedii SET denumire = '... nedefinit ...' WHERE codtipsediu = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NCLASEA WHERE CodClaseA = 0;
  IF Nr = 0 THEN
    INSERT INTO NClaseA (CodClaseA, Den_Clasea, Simbol)
    VALUES (0, '... nedefinit ...', '... nedefinit ...');
  ELSE
    UPDATE nclasea SET den_clasea = '... nedefinit ...', simbol = '... nedefinit ...' WHERE codclasea = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NCLASEAS WHERE CodCLASEAS = 0;
  IF Nr = 0 THEN
    INSERT INTO NCLASEAS (CodCLASEAS, Den_CLASEAS, Simbol)
    VALUES (0, '... nedefinit ...', '... nedefinit ...');
  ELSE
    UPDATE nCLASEAS SET den_CLASEAS = '... nedefinit ...', simbol = '... nedefinit ...' WHERE codCLASEAS = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NCLASEPROD WHERE CodClaseProd = 0;
  IF Nr = 0 THEN
    INSERT INTO NClaseProd (CodClaseProd, Den_ClaseProd, Simbol)
    VALUES (0, '... nedefinit ...', '... nedefinit ...');
  ELSE
    UPDATE nclaseprod SET den_claseprod = '... nedefinit ...', simbol = '... nedefinit ...' WHERE codclaseprod = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NCLASEP WHERE CodClaseP = 0;
  IF Nr = 0 THEN
    INSERT INTO NClaseP (CodClaseP, Den_ClaseP, Simbol)
    VALUES (0, '... nedefinit ...', '... nedefinit ...');
  ELSE
    UPDATE nclasep SET den_clasep = '... nedefinit ...', simbol = '... nedefinit ...' WHERE codclasep = 0;
  END IF;

  SELECT COUNT ( *) INTO nr FROM nclaseg WHERE codclaseg = 0;
  IF nr = 0 THEN
    INSERT INTO nclaseg (codclaseg, den_claseg, simbol)
    VALUES (0, '... nedefinit ...', '... nedefinit ...');
  ELSE
    UPDATE nclaseg SET den_claseg = '... nedefinit ...', simbol = '... nedefinit ...' WHERE codclaseg = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NPART WHERE CodPART = 0;
  IF Nr = 0 THEN
    INSERT INTO NPART (CodPART, DEN_PART)
    VALUES (0, '... nedefinit ...');
  ELSE
    UPDATE npart SET den_part = '... nedefinit ...' WHERE codpart = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NPERS WHERE CodPERS = 0;
  IF Nr = 0 THEN
    INSERT INTO NPERS (CodPERS, NUME, PRENUME)
    VALUES (0, '... nedefinit ...', '... nedefinit ...');
  ELSE
    UPDATE npers SET nume = '... nedefinit ...', prenume = '... nedefinit ...' WHERE codpers = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NGEST WHERE CodGEST = 0;
  IF Nr = 0 THEN
    INSERT INTO NGEST (CodGEST, DEN_GEST)
    VALUES (0, '... nedefinit ...');
  ELSE
    UPDATE ngest SET den_gest = '... nedefinit ...' WHERE codgest = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM IOART WHERE CodIOART = 0;
  IF Nr = 0 THEN
    INSERT INTO IOART (CodIOART, DEN_IOART)
    VALUES (0, '... nedefinit ...');
  ELSE
    UPDATE ioart SET den_ioart = '... nedefinit ...' WHERE codioart = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM IOPART WHERE CodIOPART = 0;
  IF Nr = 0 THEN
    INSERT INTO IOPART (CodIOPART, DEN_IOPART)
    VALUES (0, '... nedefinit ...');
  ELSE
    UPDATE iopart SET den_iopart = '... nedefinit ...' WHERE codiopart = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM IOPERS WHERE CodIOPERS = 0;
  IF Nr = 0 THEN
    INSERT INTO IOPERS (CodIOPERS, DEN_IOPERS)
    VALUES (0, '... nedefinit ...');
  ELSE
    UPDATE iopers SET den_iopers = '... nedefinit ...' WHERE codiopers = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM IOBANK WHERE CodIOBANK = 0;
  IF Nr = 0 THEN
    INSERT INTO IOBANK (CodIOBANK, DEN_IOBANK)
    VALUES (0, '... nedefinit ...');
  ELSE
    UPDATE iobank SET den_iobank = '... nedefinit ...' WHERE codiobank = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NTVA WHERE CodTVA = 0;
  IF Nr = 0 THEN
    INSERT INTO NTVA (CodTVA, DEN_TVA)
    VALUES (0, '... nedefinit ...');
  ELSE
    UPDATE ntva SET den_tva = '... nedefinit ...' WHERE codtva = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NMONEDE WHERE CodMONEDA = 0;
  IF Nr = 0 THEN
    INSERT INTO NMONEDE (CodMONEDA, Den_MONEDA, Simbol)
    VALUES (0, 'Lei', 'RON');
  ELSE
    UPDATE nmonede SET den_moneda = 'Lei', simbol = 'RON' WHERE codmoneda = 0;
  END IF;

  SELECT COUNT ( *) INTO NR FROM NTARI WHERE CODTARA = 0;
  IF NR = 0 THEN
    INSERT INTO NTARI (CODTARA, DEN_TARA)
    VALUES (0, '...nedefinita...');
  ELSE
    UPDATE ntari SET den_tara = '... nedefinita ...' WHERE codtara = 0;
  END IF;

  SELECT COUNT ( *) INTO NR FROM NJUDET WHERE CODJUDET = 0;
  IF NR = 0 THEN
    INSERT INTO NJUDET (CODJUDET, DEN_JUDET, CODTARA)
    VALUES (0, '...nedefinit...', 0);
  ELSE
    UPDATE njudet SET den_judet = '... nedefinit ...', codtara = 0 WHERE codjudet = 0;
  END IF;

  SELECT COUNT ( *) INTO NR FROM NZONE WHERE CODZONA = 0;
  IF NR = 0 THEN
    INSERT INTO NZONE (CODZONA, DEN_ZONA)
    VALUES (0, '...nedefinita...');
  ELSE
    UPDATE nzone SET den_zona = '... nedefinita ...' WHERE codzona = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NLOCALIT WHERE CODLOCALIT = 0;
  IF Nr = 0 THEN
    INSERT INTO NLOCALIT (codlocalit, DEN_LOCALIT, CODJUDET, CODZONA)
    VALUES (0, '...nedefinita...', 0, 0);
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NBANK WHERE CodBANK = 0;
  IF Nr = 0 THEN
    INSERT INTO NBANK (CodBANK, DENUMIRE, SIMBOL)
    VALUES (0, '... nedefinita ...', '...');
  ELSE
    UPDATE nbank SET DENUMIRE = '... nedefinita ...', simbol = '...' WHERE codbank = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NCONT WHERE CodCONT = 0;
  IF Nr = 0 THEN
    INSERT INTO NCONT (CodCONT, DEN_CONT, SIMBOL, CLASA, TIPCONT)
    VALUES (0, '... nedefinit ...', '...', 0, 0);
  ELSE
    UPDATE ncont
    SET
      DEN_CONT = '... nedefinit ...',
      SIMBOL   = '...',
      CLASA    = 0,
      TIPCONT  = 0
    WHERE codcont = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NCONTS WHERE CodCONTS = 0;
  IF Nr = 0 THEN
    INSERT INTO NCONTS (CodCONTS, DEN_CONT, SIMBOL, CLASA, TIPCONT)
    VALUES (0, '... nedefinit ...', '...', 0, 0);
  ELSE
    UPDATE ncontS
    SET
      DEN_CONT = '... nedefinit ...',
      SIMBOL   = '...',
      CLASA    = 0,
      TIPCONT  = 0
    WHERE codconts = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NCATPRET WHERE CODCATPRET = 0;
  IF Nr = 0 THEN
    INSERT INTO NCATPRET (CODCATPRET, DEN_CATPRET, TIP, SIMBOL)
    VALUES (0, '... nedefinit ...', 0, '...');
  ELSE
    UPDATE ncatpret
    SET DEN_CATPRET = '... nedefinit ...', TIP = 0, SIMBOL = '...' WHERE codcatpret = 0;
  END IF;

  SELECT COUNT ( *) INTO NR FROM NSUBUNIT WHERE CODSUBUNIT = 0;
  IF NR = 0 THEN
    INSERT INTO NSUBUNIT (CODSUBUNIT, DEN_SUBUNIT)
    VALUES (0, '... nedefinita ...');
  ELSE
    UPDATE nsubunit SET den_subunit = '... nedefinita ...' WHERE codsubunit = 0;
  END IF;

  SELECT COUNT ( *) INTO NR FROM NSUBUNIT WHERE CODSUBUNIT = 1;
  IF NR = 0 THEN
    INSERT INTO NSUBUNIT (CODSUBUNIT, DEN_SUBUNIT)
    VALUES (1, 'Cumulat Firma');
  ELSE
    UPDATE nsubunit SET den_subunit = 'Cumulat Firma' WHERE codsubunit = 1;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NUM WHERE CodUM = 0;
  IF Nr = 0 THEN
    INSERT INTO NUM (CodUM, DEN_UM)
    VALUES (0, '......');
  ELSE
    UPDATE num SET den_um = '......' WHERE codum = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NUM1 WHERE CodUM1 = 0;
  IF Nr = 0 THEN
    INSERT INTO NUM1 (COdUM1, CODUM, SECUNDARA, PARITATE, DEN_UM1)
    VALUES (0, 0, 0, 1, '.....');
  ELSE
    UPDATE num1 SET CODUM = 0, SECUNDARA = 0, PARITATE = 1, DEN_UM1 = '.....' WHERE codum1 = 0;
  END IF;

  SELECT COUNT ( *) INTO nr FROM nlocatii WHERE CODLOCATIE = 0;
  IF NR = 0 THEN
    INSERT INTO NLOCATII (CODLOCATIE, CODGEST, DENUMIRE)
    VALUES (0, 0, '...nedefinita...');
  ELSE
    UPDATE nlocatii SET codgest = 0, denumire = '...nedefinita...' WHERE codlocatie = 0;
  END IF;

  SELECT COUNT ( *) INTO NR FROM NAGENDA WHERE CODAGENDA = 0;
  IF NR = 0 THEN
    INSERT INTO nagenda (codagenda, codlocalit, codpart, codgest)
    VALUES (0, 0, 0, 0);
  ELSE
    UPDATE nagenda SET codlocalit = 0, codpart = 0, codgest = 0 WHERE codagenda = 0;
  END IF;

  SELECT COUNT ( *) INTO nr FROM nparcaut WHERE CODnparcaut = 0;
  IF NR = 0 THEN
    INSERT INTO nparcaut (codnparcaut, nrinreg, codart, nrinv)
    VALUES (0, '..nedefinit..', 0, 0);
  ELSE
    UPDATE nparcaut SET codart = 0, nrinreg = '..nedefinit..', nrinv = 0 WHERE codnparcaut = 0;
  END IF;

  SELECT COUNT ( *) INTO nr FROM TraseuLivr WHERE CodTraseuLivr = 0;
  IF nr = 0 THEN
    INSERT INTO TraseuLivr (CodTraseuLivr, DenTraseu, SimbolTraseu)
    VALUES (0, '..nedefinit..', '..nedefinit..');
  ELSE
    UPDATE TraseuLivr SET DenTraseu = '..nedefinit..', SimbolTraseu = '..nedefinit..' WHERE CodTraseuLivr = 0;
  END IF;

  SELECT COUNT ( *) INTO nr FROM TraseuLivr WHERE CodTraseuLivr = 1;
  IF nr = 0 THEN
    INSERT INTO TraseuLivr (CodTraseuLivr, DenTraseu, SimbolTraseu)
    VALUES (1, 'TRANSPORT ASIGURAT DE CLIENT', 'TAC');
  ELSE
    UPDATE TraseuLivr
    SET
      DenTraseu    = 'TRANSPORT ASIGURAT DE CLIENT',
      SimbolTraseu = 'TAC'
    WHERE CodTraseuLivr = 1;
  END IF;

  BEGIN
    SELECT COUNT ( *) INTO nr FROM winmadmin.Setliste WHERE codset = 0;
    IF nr = 0 THEN
      INSERT INTO winmadmin.setliste (codset, denumire)
      VALUES (0, 'Set Baza');
    ELSE
      UPDATE winmadmin.Setliste SET denumire = 'Set Baza' WHERE codset = 0;
    END IF;

    SELECT COUNT ( *) INTO nr FROM winmadmin.Setliste WHERE codset = 1;
    IF nr = 0 THEN
      INSERT INTO winmadmin.setliste (codset, denumire)
      VALUES (1, 'Set General');
    ELSE
      UPDATE winmadmin.Setliste SET denumire = 'Set General' WHERE codset = 1;
    END IF;
  EXCEPTION
    WHEN OTHERS THEN
      INSERT INTO x (test) VALUES ('exceptie');
  END;

  SELECT COUNT ( *) INTO Nr FROM CRITERIIDISC WHERE CODCRITERIU = 9;
  IF Nr = 0 THEN
    INSERT INTO CRITERIIDISC (
        CODCRITERIU,
        DENCRITERIU,
        EXCLUDVOLTR,
        EXCLUDCANTFACT,
        EXCLUDTERMEN,
        EXCLUDVALDOC,
        EXCLUDDISTANTA,
        PECLASE,
        CUMULAT)
      VALUES (
        9,
        'Facturi in baza comenzii',
        0,
        0,
        0,
        0,
        0,
        0,
        0);
  END IF;

  SELECT COUNT ( *) INTO Nr FROM CRITERIIDISC WHERE CODCRITERIU = 10;
  IF Nr = 0 THEN
    INSERT INTO CRITERIIDISC (
        CODCRITERIU,
        DENCRITERIU,
        EXCLUDVOLTR,
        EXCLUDCANTFACT,
        EXCLUDTERMEN,
        EXCLUDVALDOC,
        EXCLUDDISTANTA,
        PECLASE,
        CUMULAT)
      VALUES (
        10,
        'Transport asigurat de client',
        0,
        0,
        0,
        0,
        0,
        0,
        0);
  END IF;

  SELECT COUNT ( *) INTO Nr FROM CRITERIIDISC WHERE CODCRITERIU = 11;
  IF Nr = 0 THEN
    INSERT INTO CRITERIIDISC (
        CODCRITERIU,
        DENCRITERIU,
        EXCLUDVOLTR,
        EXCLUDCANTFACT,
        EXCLUDTERMEN,
        EXCLUDVALDOC,
        EXCLUDDISTANTA,
        PECLASE,
        CUMULAT)
      VALUES (
        11,
        'Zi de nastere',
        0,
        0,
        0,
        0,
        0,
        0,
        0);
  END IF;

  SELECT COUNT ( *) INTO NR FROM CENTRECOST WHERE CODCENTRU = 0;
  IF NR = 0 THEN
    INSERT INTO CENTRECOST (CODCENTRU, SIMBOL, DENUMIRE)
    VALUES (0, '... nedefinit ...', '... nedefinit ...');
  ELSE
    UPDATE CENTRECOST SET SIMBOL = '... nedefinit ...', DENUMIRE = '... nedefinit ...' WHERE CODCENTRU = 0;
  END IF;

  -- CARDURI
  SELECT COUNT(*) INTO NR FROM CARDURI WHERE CODCARD = 0;
  IF NR = 0 THEN
    INSERT INTO CARDURI(CODCARD,SIMBOL,DENUMIRE) VALUES (0,'... nedefinit ...','... nedefinit ...');
  ELSE
    UPDATE CARDURI SET
     SIMBOL   = '... nedefinit ...',
     DENUMIRE = '... nedefinit ...'
   WHERE CODCARD = 0;
  END IF;

  SELECT COUNT ( *) INTO NR FROM NCASEMARCAT WHERE CODCASEMARCAT = 0;
  IF NR = 0 THEN
    INSERT INTO NCASEMARCAT (CODCASEMARCAT, DENUMIRE)
    VALUES (0, '... nedefinita ...');
  END IF;

  SELECT COUNT ( *) INTO NR FROM DESCRIPTORI WHERE CODDESCRIPTOR = 0;
  IF NR = 0 THEN
    INSERT INTO DESCRIPTORI (CODDESCRIPTOR, SIMBOL, DEN_DESCRIPTOR, TIP)
    VALUES (0, '-', '... nedefinit ...', 0);
  ELSE
    UPDATE DESCRIPTORI SET SIMBOL = '-', DEN_DESCRIPTOR = '... nedefinit ...' WHERE CODDESCRIPTOR = 0;
  END IF;

  SELECT COUNT ( *) INTO NR FROM NLIMBA WHERE CodLimba = 0;
  IF NR = 0 THEN
    INSERT INTO NLIMBA (CodLimba, DenLimba, CodTara, ExtLink)
    VALUES (0, '... nedefinit ...', 0, '--');
  ELSE
    UPDATE NLIMBA SET DenLimba = '... nedefinit ...', CodTara = 0, ExtLink = '--' WHERE CodLimba = 0;
  END IF;

  SELECT COUNT ( *) INTO NR FROM NMESERII WHERE CODMESERIE = 0;
  IF NR = 0 THEN
    INSERT INTO NMESERII (CODMESERIE, DEN_MESERIE)
    VALUES (0, '... nedefinit ...');
  ELSE
    UPDATE NMESERII SET DEN_MESERIE = '... nedefinit ...' WHERE CODMESERIE = 0;
  END IF;

  SELECT COUNT ( *) INTO NR FROM CURSURI WHERE CODCURS = 0;
  IF NR = 0 THEN
    INSERT INTO CURSURI (CODCURS, DEN_CURS)
    VALUES (0, '... nedefinit ...');
  ELSE
    UPDATE CURSURI SET DEN_CURS = '... nedefinit ...' WHERE CODCURS = 0;
  END IF;

  SELECT COUNT ( *) INTO NR FROM FORMATORI WHERE CODFORMATOR = 0;
  IF NR = 0 THEN
    INSERT INTO FORMATORI (CODFORMATOR, DEN_FORMATOR, TELEFON, EMAIL, CODPERS)
    VALUES (0, '... nedefinit ...', '... nedefinit ...', '... nedefinit ...', 0);
  ELSE
    UPDATE FORMATORI SET DEN_FORMATOR = '... nedefinit ...' WHERE CODFORMATOR = 0;
  END IF;

  SELECT COUNT ( *) INTO NR FROM TEME WHERE CODTEMA = 0;
  IF NR = 0 THEN
    INSERT INTO TEME (CODTEMA, DEN_TEMA, ORE, PRET, CODFORMATOR)
    VALUES (0, '... nedefinit ...', 0, 0, 0);
  ELSE
    UPDATE TEME SET DEN_TEMA = '... nedefinit ...' WHERE CODTEMA = 0;
  END IF;

  SELECT COUNT ( *) INTO NR FROM FUNCTII WHERE CODFUNCTIE = 0;
  IF NR = 0 THEN
    INSERT INTO FUNCTII (CODFUNCTIE, DENUMIRE, CODEXTERN)
    VALUES (0, '... nedefinit ...', 0);
  ELSE
    UPDATE FUNCTII SET DENUMIRE = '... nedefinit ...' WHERE CODFUNCTIE = 0;
  END IF;

  SELECT COUNT ( *) INTO NR FROM CONCURENTI WHERE CodConcurent = 0;
  IF NR = 0 THEN
    INSERT INTO CONCURENTI (CodConcurent, DenConcurent)
    VALUES (0, '... nedefinit ...');
  ELSE
    UPDATE CONCURENTI SET DenConcurent = '... nedefinit ...' WHERE CodConcurent = 0;
  END IF;

  SELECT COUNT ( *) INTO NR FROM CAMPANII WHERE CodCampanie = 0;
  IF NR = 0 THEN
    INSERT INTO CAMPANII (CodCampanie, DenCampanie, Obiectiv, Target)
    VALUES (0, '... nedefinit ...', '... nedefinit ...', '... nedefinit ...');
  ELSE
    UPDATE CAMPANII
    SET
      DenCampanie = '... nedefinit ...',
      Obiectiv    = '... nedefinit ...',
      Target      = '... nedefinit ...'
    WHERE CodCampanie = 0;
  END IF;

  SELECT COUNT ( *) INTO NR FROM CERTIF WHERE CodCertif = 0;
  IF NR = 0 THEN
    BEGIN
      INSERT INTO CERTIF (CodCertif, NrCertif, CodObiect)
      VALUES (0, '... nedefinit ...', 0);
    EXCEPTION
      WHEN others THEN
        INSERT INTO x (test) VALUES ('exceptie');
    END;
  ELSE
    UPDATE CERTIF SET NrCertif = '... nedefinit ...' WHERE CodCertif = 0;
  END IF;

  SELECT COUNT ( *) INTO NR FROM GRUPEDRUM WHERE CODGRUPA = 101;
  IF NR = 0 THEN
    BEGIN
      INSERT INTO GRUPEDRUM (CODGRUPA, DENUMIRE, SIMBOL, COEF, DESCRIERE)
      VALUES (101, 'I (M)', 'D1', 0.9, 'Drumuri asfaltate in stare buna (beton asfaltic, macadan asfaltic, macadan cu tratament dublu, balast bituminat, beton ciment).');
    EXCEPTION
      WHEN others THEN
        INSERT INTO x (test) VALUES ('exceptie');
    END;
  END IF;

  SELECT COUNT ( *) INTO NR FROM GRUPEDRUM WHERE CODGRUPA = 102;
  IF NR = 0 THEN
    BEGIN
      INSERT INTO GRUPEDRUM (CODGRUPA, DENUMIRE, SIMBOL, COEF, DESCRIERE)
      VALUES (102, 'II (K)', 'D2', 1, 'Drumuri pavate (cu calupuri, cu pavele normale sau abnorme) in stare buna. Drumuri macadamizate si impietruite in stare buna.');
    EXCEPTION
      WHEN others THEN
        INSERT INTO x (test) VALUES ('exceptie');
    END;
  END IF;

  SELECT COUNT ( *) INTO NR FROM GRUPEDRUM WHERE CODGRUPA = 103;
  IF NR = 0 THEN
    BEGIN
      INSERT INTO GRUPEDRUM (CODGRUPA, DENUMIRE, SIMBOL, COEF, DESCRIERE)
      VALUES (103, 'III (T)', 'D3', 1.1, 'Drumuri asfaltate, pavate, macadamizate si impietruite in stare mediocra, care impun schimbari de viteza pe cca.20% din parcurs. Drumuri de pamant si terasamente in stare buna. Drumuripavate cu piatra bruta, bolovani de rau si nisipate, in');
    EXCEPTION
      WHEN others THEN
        INSERT INTO x (test) VALUES ('exceptie');
    END;
  END IF;

  SELECT COUNT ( *) INTO NR FROM GRUPEDRUM WHERE CODGRUPA = 104;
  IF NR = 0 THEN
    BEGIN
      INSERT INTO GRUPEDRUM (CODGRUPA, DENUMIRE, SIMBOL, COEF, DESCRIERE)
      VALUES (104, 'IV (L)', 'D4', 1.2, 'Drumuri impietruite cu piatra sparta, pietris sau macadamizate si pavate cu piatra si bolovani de rau , in stare mediocra. Drumuri de categoria K si T cu declivitati ce impun scimbari de viteza pe cca.40% din parcurs.');
    EXCEPTION
      WHEN others THEN
        INSERT INTO x (test) VALUES ('exceptie');
    END;
  END IF;

  SELECT COUNT ( *) INTO NR FROM GRUPEDRUM WHERE CODGRUPA = 105;
  IF NR = 0 THEN
    BEGIN
      INSERT INTO GRUPEDRUM (CODGRUPA, DENUMIRE, SIMBOL, COEF, DESCRIERE)
      VALUES (105, 'V (E)', 'D5', 1.4, 'Drumuri a caror stare impune schimbari de viteza pe cca.70% din parcurs. Drumuri de pamant si terasamente, in stare mediocra. Drumuri pavate cu bolovani de rau sau cu piatra in stare rea.');
    EXCEPTION
      WHEN others THEN
        INSERT INTO x (test) VALUES ('exceptie');
    END;
  END IF;

  SELECT COUNT ( *) INTO NR FROM GRUPEDRUM WHERE CODGRUPA = 106;
  IF NR = 0 THEN
    BEGIN
      INSERT INTO GRUPEDRUM (CODGRUPA, DENUMIRE, SIMBOL, COEF, DESCRIERE)
      VALUES (106, 'VI (H)', 'D6', 1.6, 'Toate celelalte drumuri cu o stare de viabilitate sau care prezinta declivitati ce nu permit circulatia cu viteze mai mari de 15  km/ora pe toata lungimea lor.');
    EXCEPTION
      WHEN others THEN
        INSERT INTO x (test) VALUES ('exceptie');
    END;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NGAMEART WHERE CodGama = 0;
  IF Nr = 0 THEN
    INSERT INTO NGAMEART (CodGama, DENUMIRE)
    VALUES (0, '... nedefinit ...');
  ELSE
    UPDATE NGAMEART SET DENUMIRE = '... nedefinit ...' WHERE codGAMA = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM TIPCHELT WHERE CodTipChelt = 0;
  IF Nr = 0 THEN
    INSERT INTO TIPCHELT (CodTipChelt, DENUMIRE)
    VALUES (0, '... nedefinit ...');
  ELSE
    UPDATE TIPCHELT SET DENUMIRE = '... nedefinit ...' WHERE CodTipChelt = 0;
  END IF;

  SELECT COUNT ( *) INTO Nr FROM NCONTT WHERE CodCONTT = 0;
  IF Nr = 0 THEN
    INSERT INTO NCONTT (CodCONTT, DEN_CONT, SIMBOL, CLASA, TIPCONT)
    VALUES (0, '... nedefinit ...', '...', 0, 0);
  ELSE
    UPDATE ncontt
    SET
      DEN_CONT = '... nedefinit ...',
      SIMBOL   = '...',
      CLASA    = 0,
      TIPCONT  = 0
    WHERE codcontt = 0;
  END IF;

    SELECT COUNT(*) INTO NR FROM TVAServ WHERE CODTVASERV = 0;
    IF NR = 0 then
      INSERT INTO TVASERV(CODTVASERV,DENUMIRE, CODCONT, SIMBOL) values (0, '...nedefinit...', 0, '...nedefinit...');
    END IF;

  -- NOPER
  SELECT COUNT(*) INTO NR FROM NOPER WHERE CODOP = 0;
  IF NR = 0 THEN
    INSERT INTO NOPER(CODOP, DENUMIRE) values (0, '...nedefinit...');
  END IF;

  -- TIPLUCRARISA
  SELECT COUNT(*) INTO NR FROM TIPLUCRARISA WHERE CODTIPLUCRARE = 0;
  IF NR = 0 THEN
    INSERT INTO TIPLUCRARISA(CODTIPLUCRARE, DENUMIRE) values (0, '...nedefinit...');
  END IF;

   -- efcustom
   SELECT COUNT(*) INTO NR FROM EFCUSTOM WHERE CODEFCUSTOM = 0;
   IF NR = 0 THEN
     INSERT INTO EFCUSTOM(CODEFCUSTOM,DEN_EFCUSTOM) values (0, '...nedefinit...');
   END IF;

     SELECT COUNT ( *) INTO Nr FROM nbankcont WHERE codbankcont = 0;
  IF Nr = 0 THEN
    INSERT INTO nbankcont (codbankcont, DEN_cont) VALUES (0, '... nedefinit ...');
  ELSE
    UPDATE nbankcont SET DEN_cont = '... nedefinit ...' WHERE codbankcont = 0;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_ambalaje</obj_name>
  <obj_hashval>2691ae0fe86a0ddc0f20fd3a91569a03</obj_hashval>
  <obj_text>SELECT o.codobiect,
    o.denumire,
    a.um,
    a.clasa,
    a.tipserie,
    a.tiparticol,
    a.aretg,
    a.um1,
    a.um2,
    o.codextern,
    o.codintern,
    o.masa,
    o.volum,
    o.umambalare
   FROM martor.nartobj o
     JOIN martor.nart a ON a.codarticol = o.codarticol
  WHERE o.returnabil = 1::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rezervari_updatenecesarperez</obj_name>
  <obj_hashval>516030a1a3a6bcc6ec710c96d3757b5b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rezervari_updatenecesarperez(acodcomanda1 numeric DEFAULT 0)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_COM        RECORD;
  V_NOD        RECORD;
  V_NODXXX     RECORD;
  REST_Rez     numeric;
  REST_RezFurn numeric;
  REST_RezCmdFurn   NUMERIC(20,7);
  REZ_Rezervat numeric;
  REZ_RezFURN  numeric;
  REZ_RezCmdFURN NUMERIC(20,7);
  REZ_TOTAL    numeric;
  CATE_VREAU   numeric;
  aParitate    numeric;
  ZEC          numeric;
  NOD_Rezervat numeric;
  NOD_Rezolvat numeric;
  NOD_Necesar  numeric;
  NOD_RezFurn  numeric;
  NOD_RezCmdFurn NUMERIC(20,7);
  aCantIni     numeric;
  aRest        numeric;
  STOC_Rest    numeric;
  aCod         numeric;
  REZ_CodGest  numeric;
  REZ_CodIOArt numeric;
  REZ_UMSec    numeric;
BEGIN
  --Florin 11.01.2023 - sinc. Oracle
  --Laura 24.11.2021 - sinc Oracle (24.11.2021)
  --Adina 01.07.2021 - sinc.Oracle din 30.06.2021
  --Adina 29.06.2021 - sinc.Oracle din 28.06.2021
  --Bogdan 15.10.2020
  PERFORM PKG_REZERVARI_GET_TMP_REZ_STOC (aCodComanda1);

  UPDATE TMP_REZ_REZ
  SET
    Rez      = 0,
    RezFurn  = 0,
    RezCmdFurn = 0,
    Rezolvat = 0
  WHERE COALESCE (aCodComanda1, 0) = 0 or Codcomanda1 = COALESCE (aCodComanda1, 0);

  UPDATE TMP_REZ_ProiectNod
  SET
    Rezervat = 0,
    RezFurn  = 0,
    Rezolvat = 0,
    RezCmdFurn = 0
  WHERE COALESCE (aCodComanda1, 0) = 0 or Codcomanda1 = COALESCE (aCodComanda1, 0);

  FOR v_COM IN (SELECT CodComanda1, TipComanda, CodProiect
                FROM TMP_REZ_CCOM1
                WHERE COALESCE (aCodComanda1, 0) = 0 or Codcomanda1 = COALESCE (aCodComanda1, 0))
  LOOP
    FOR v_NOD IN (SELECT tmp.*,
                          CASE WHEN pn.nodoriginal = 0 THEN 0
                               ELSE CASE WHEN pn.Tip = 5 THEN 3 ELSE pn.tip END
                          END TIP
                  FROM TMP_REZ_ProiectNod   tmp INNER JOIN proiectnod pn ON pn.codproiectnod = tmp.codproiectnod
                  WHERE tmp.CodComanda1 = v_COM.Codcomanda1 and (tmp.NodOriginal &gt; 0 or v_COM.TipComanda &lt;&gt; 2)
                  ORDER BY tmp.CodComanda1, tmp.Nivel, tmp.Pozitie
                 )
    LOOP
      SELECT
        Rezervat,
        RezFurn,
        RezCmdFurn,
        Necesar,
        Rezolvat
      INTO
        NOD_Rezervat,
        NOD_RezFurn,
        NOD_RezCmdFurn,
        NOD_Necesar,
        NOD_Rezolvat
      FROM TMP_REZ_ProiectNod
      WHERE
        CodComanda1 = v_COM.CodComanda1
        and CodProiectNod = v_NOD.CodProiectNod;

      SELECT CodGest,
        CodIOArt,
        UMSec,
        REZINI     - REZ,
        REZFURNINI - REZFURN,
        rezcmdfurn_ini rezcmdfurn
      INTO
        REZ_CodGest,
        REZ_CodIOArt,
        REZ_UMSec,
        REST_REZ,
        REST_REZFURN,
        REST_REZCMDFURN
      FROM TMP_REZ_REZ
      WHERE
        CodComanda1 = v_COM.CodComanda1
        and CodObiect = v_NOD.CodObiect
        and idx = v_nod.tip;

      REZ_Rezervat := 0;
      REZ_RezFurn  := 0;
      CATE_VREAU   := NOD_Necesar - NOD_Rezolvat - NOD_Rezervat - NOD_RezFurn;
      IF CATE_VREAU &lt; REST_Rez THEN
        REZ_Rezervat := CATE_VREAU;
        CATE_VREAU   := 0;
      ELSE
        REZ_Rezervat := REST_Rez;
        CATE_VREAU   := CATE_VREAU - REST_Rez;
      END IF;

      if CATE_VREAU &lt; REST_RezCmdFurn THEN
        REZ_RezCmdFurn := CATE_VREAU;
        CATE_VREAU     := 0;
      ELSE
        REZ_RezCmdFurn := REST_RezCmdFurn;
        CATE_VREAU     := CATE_VREAU - REST_RezCmdFurn;
      END IF;

      IF CATE_VREAU &lt; REST_RezFurn THEN
        REZ_RezFurn := CATE_VREAU;
        CATE_VREAU  := 0;
      ELSE
        REZ_RezFurn := REST_RezFurn;
        CATE_VREAU  := CATE_VREAU - REST_RezFurn;
      END IF;

      IF REZ_Rezervat &lt;&gt; 0.0 THEN
        UPDATE TMP_REZ_REZ SET Rez = Rez + REZ_Rezervat WHERE CodComanda1 = v_NOD.CodComanda1 and CodObiect = v_NOD.CodObiect;

        UPDATE TMP_REZ_ProiectNod SET Rezervat = Rezervat + REZ_Rezervat WHERE CodComanda1 = v_COM.CodComanda1 and CodProiectNod = v_NOD.CodProiectNod;

        REZ_TOTAL := REZ_Rezervat;
        aParitate := REZ_TOTAL / v_NOD.Necesar;

        FOR v_NODXXX IN (
                with recursive recCP as (
                    SELECT trp1.CODPROIECTNOD,
                         trp1.CODOBIECT,
                         trp1.Necesar
                    FROM TMP_REZ_ProiectNod trp1
                    where trp1.CODPROIECTNOD = v_NOD.CodProiectNod
                    union all
                    select trp2.CODPROIECTNOD,
                         trp2.CODOBIECT,
                         trp2.Necesar
                    FROM TMP_REZ_ProiectNod trp2
                    join  recCP r on r.codproiectnod = trp2.NODORIGINAL
                    where  trp2.CODPROIECTNOD &lt;&gt; v_NOD.CodProiectNod
                    ) select * from recCP rc where rc.CODPROIECTNOD &lt;&gt; v_NOD.CodProiectNod
                  )
        LOOP
          SELECT COALESCE (u.Zecimale, 0) INTO ZEC FROM NUM  u, NART    a, NARTOBJ o
          where o.CodObiect = v_NOD.CodObiect and a.CodArticol = o.CodArticol and u.CODUM = a.UM;
          UPDATE TMP_REZ_REZ
          SET Rezolvat = Round ( (Rezolvat + v_NodXXX.Necesar * aParitate) ::numeric, (ZEC) ::int)
          WHERE CodObiect = v_NodXXX.codObiect and CodComanda1 = v_COM.CodComanda1;

          UPDATE TMP_REZ_ProiectNod
          SET Rezolvat = Round ( (Rezolvat + v_NodXXX.Necesar * aParitate) ::numeric, (ZEC) ::int)
          WHERE CodComanda1 = v_COM.CodComanda1 and CodProiectNod = v_NODXXX.CodProiectNod;
        END LOOP;
      END IF;

      if REZ_RezCmdFurn &lt;&gt; 0.0 then
        update TMP_REZ_REZ set RezCmdFurn = RezCmdFurn + REZ_RezCmdFurn
          where CodComanda1 = v_NOD.CodComanda1 and CodObiect = v_NOD.CodObiect;
        update TMP_REZ_ProiectNod set RezCmdFurn = RezCmdFurn + REZ_RezCmdFurn
          where CodComanda1 = v_COM.CodComanda1 and CodProiectNod = v_NOD.CodProiectNod;
      END IF;

      IF REZ_RezFurn &lt;&gt; 0.0 THEN
        UPDATE TMP_REZ_REZ SET RezFurn = RezFurn + REZ_RezFurn WHERE CodComanda1 = v_NOD.CodComanda1 and CodObiect = v_NOD.CodObiect;

        UPDATE TMP_REZ_ProiectNod SET RezFurn = RezFurn + REZ_RezFurn WHERE CodComanda1 = v_COM.CodComanda1 and CodProiectNod = v_NOD.CodProiectNod;
      END IF;
    END LOOP;
  END LOOP;

  UPDATE TMP_REZ_REZ
  SET
  RestCom = Round ( (NecesarIni - Rezolvat - RezIni - RezCmdFurn - RezFurnIni) ::numeric, 7)
  WHERE (COALESCE (aCodComanda1, 0) = 0 or Codcomanda1 = COALESCE (aCodComanda1, 0));
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t21</obj_name>
  <obj_hashval>3968f4e46692373c12fa1dbe2eee958f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t21()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 06.01.2022
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_impoz_getct_monitor</obj_name>
  <obj_hashval>732ca57ce17f9df1796118956145b410</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_impoz_getct_monitor(wme_result character varying, fakeparam numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
 DECLARE
BEGIN
  --Florin 02.03.2022
  WME_Result := current_setting('PKG_SAL_IMPOZ.CT_MONITOR', true);
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
  WME_Result := 'MON_5';
  END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_simlans_get_tmp_sim_lans1</obj_name>
  <obj_hashval>717290e16a173e95ad1570d14733b82c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_simlans_get_tmp_sim_lans1(g_subunit numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_SCEN       RECORD;
  NOD_Rezervat numeric;
  NOD_RezFurn  numeric;
  TOT_RestCmd  numeric;
  TOT_RestFurn numeric;
  Init         numeric;
  Zec          numeric;
  LastProiectNod numeric;
begin
  DELETE FROM TMP_SIM_LANS1;
  INSERT INTO TMP_SIM_LANS1(DENUMIRE, CODOBIECT, CODCOMANDA1, PREF, NIVEL, POZITIE, CODPROIECTNOD, NODORIGINAL, TIP, CANT, NECESARP, NECESAR, REZOLVAT, REZERVAT,
                            NESOSIT, RESTREZERVAT, RESTNESOSIT, TOTREZERVAT, TOTNESOSIT, STOC, CMDINT, DIFERENTE, ZECIMALE, UMSEC, DEN_UM, MatEchiv, CodExtern)
  (SELECT DENUMIRE, CODOBIECT, CODCMD1, PREF, NIVEL, POZITIE, CODPROIECTNOD, NODORIGINAL, TIP, COALESCE(CANT, 0), COALESCE(NECESARP, 0), 0 NECESAR, 0 REZOLVAT, 0 REZERVAT,
          0 NESOSIT,
          CASE WHEN  NODORIGINAL = 0 THEN 0 ELSE COALESCE(TotRezervat, 0) END ,
          COALESCE(RestDeSosit, 0),
          CASE WHEN  NODORIGINAL = 0 THEN 0 ELSE COALESCE(TotRezervat, 0) END ,
          COALESCE(RestDeSosit, 0), COALESCE(STOC, 0), 0 CMDINT, 0 DIFERENTE, Zecimale, UMSEC, DEN_UM, MatEchiv, CodExtern
   FROM (SELECT Y.DENUMIRE, Y.CODOBIECT, Y.CODCMD1, Y.PREF, Y.NIVEL, Y.POZITIE, Y.CODPROIECTNOD, Y.NODORIGINAL, Y.Tip, Y.CANT, Y.TotRezervat, RestFurn.RestDeSosit,
                Y.STOC - COALESCE(RestRez.RestDeConsumat, 0) STOC, Y.NECESARP,
                (SELECT COALESCE(u.Zecimale, 0) FROM NUM u, NART a, NARTOBJ o WHERE o.CodObiect = Y.CodObiect and  a.CodArticol = o.CodArticol and  u.CODUM = a.UM) ZECIMALE,
                0 UMSEC,
                (SELECT DEN_UM FROM NUM u, NART a, NARTOBJ o WHERE o.CodObiect = Y.CodObiect and  a.CodArticol = o.CodArticol and  u.CODUM = a.UM) DEN_UM,
                MatEchiv, CodExtern
         FROM (SELECT NOBJ.DENUMIRE, NOBJ.CODOBIECT, COALESCE(NE.CODCOMANDA1, C1.CODCOMANDA1) CODCMD1, X.PREF, X.NIVEL, X.POZITIE, X.CODPROIECTNOD, X.NODORIGINAL,
                      X.Tip, X.CANT, REZ.TotRezervat, NS.REST * COALESCE(NE.PARITATE, 1) STOC, X.CANT / ORIG.CANT * COALESCE(NE.PARITATE, 1) NECESARP, x.MatEchiv, NOBJ.CodExtern
               FROM COMANDA1 C1
                   INNER JOIN (SELECT PN0.CODPROIECTNOD NODORIG, PN.CODPROIECTNOD, PN.CODPROIECT, PN.CANT, PN.NODORIGINAL, PN.TIP, PN.CODOBIECT, PN.NIVEL, PN.POZITIE,
                                      SUBSTR(PN.INDEXPARINTE, 4, 47) PREF,
                                      CASE WHEN  MECHIV.Nr &gt; 0 THEN PN.Codprodmat ELSE 0 END  MATECHIV
                              FROM PROIECTNOD PN
                                  INNER JOIN PROIECTNOD PN0 ON  PN0.CODPROIECT = PN.CODPROIECT AND  PN0.NODORIGINAL = 0
                                  LEFT  JOIN (SELECT count(*) NR, codmat FROM prodmat GROUP BY codmat
                                             ) MECHIV ON  MECHIV.CODMAT = PN.CODPRODMAT
                             ) X ON  X.CODPROIECT = C1.CODPROIECT
                  LEFT  JOIN PROIECTNOD ORIG ON  ORIG.CODPROIECTNOD = X.NODORIG
                  LEFT  JOIN NODECHIV NE ON  NE.CODCOMANDA1 = C1.CODCOMANDA1 AND  NE.CODPROIECTNOD = X.CODPROIECTNOD
                  LEFT  JOIN NARTOBJ NOBJ ON  NOBJ.CODOBIECT = COALESCE(NE.CODOBIECT, X.CODOBIECT)
                  LEFT  JOIN (SELECT sum(NSS.REST) REST, NSS.CODOBIECT
                              FROM NIRSTOC NSS
                              INNER JOIN NIR ON  NSS.CODNIR = NIR.CodNIR
                              INNER JOIN NGEST NG ON  NG.CODGEST = NIR.GEST
                              WHERE (G_SUBUNIT = 1 OR  NG.CodSubunit = G_SUBUNIT)
                              GROUP BY NSS.CODOBIECT
                             ) NS ON  NS.CODOBIECT = NOBJ.CODOBIECT
                  LEFT  JOIN (SELECT R.CodComanda1, NSR.CodObiect, SUM(R.REST) TOTREZERVAT
                              FROM REZERVATS R INNER JOIN NIRSTOC NSR ON  R.CODNIRSTOC = NSR.CodNIRSTOC
                              GROUP BY R.CodCOmanda1, NSR.CodObiect
                             ) REZ ON  C1.CodComanda1 = REZ.CodComanda1 AND  NOBJ.CODOBIECT = REZ.CodObiect
               WHERE EXISTS (SELECT TMP.CODPROIECT  FROM TMP_SIM_CCOM1 TMP WHERE COALESCE(TMP.Activ, 0) = 1 and  TMP.CODPROIECT = X.CODPROIECT)
                AND  EXISTS (SELECT TMP.CODCOMANDA1 FROM TMP_SIM_CCOM1 TMP WHERE COALESCE(TMP.Activ, 0) = 1 and  TMP.CODCOMANDA1 = COALESCE(NE.CODCOMANDA1, C1.CODCOMANDA1))
              ) Y
              LEFT JOIN (SELECT R.CodComanda1, NS.CodObiect, sum(r.rest) RESTDECONSUMAT
                         FROM rezervats r INNER JOIN nirstoc ns ON  ns.codnirstoc = r.codnirstoc
                         GROUP BY NS.CodObiect, R.CodComanda1
                        ) RESTREZ ON  RESTREZ.CodObiect = Y.CodObiect AND  RESTREZ.CodComanda1 = Y.CodCmd1
              LEFT JOIN (SELECT R.CodComanda1, R.CodObiect, sum(r.rest) RESTDESOSIT
                         FROM rezervats r
                         WHERE COALESCE(r.codnirstoc, 0) = 0 and  COALESCE(r.CODCOMANDA1F, 0) &lt;&gt; 0
                         GROUP BY r.CodObiect, r.codcomanda1
                        ) RESTFURN ON  RESTFURN.CodObiect = Y.CodObiect and  RESTFURN.CodComanda1 = Y.CodCmd1
          ORDER BY Y.DENUMIRE
         ) A_PG
   WHERE NecesarP &gt; 0
  );

  INSERT INTO TMP_SIM_NODECHIV1(CODCOMANDA1, CODPROIECTNOD, CODOBIECT, CANT, PARITATE, TIP, CODOBIECTORIG, NODORIGINAL, STOC, CANTECHIVALATA, DENOBIECTECHIV, CODEXTERN)
  SELECT NE1.CODCOMANDA1, NE1.CODPROIECTNOD, NE1.CODOBIECT, NE1.CANT, NE1.PARITATE, NE1.TIP, L1.CODOBIECT, L1.NODORIGINAL,
         COALESCE(NS.REST, 0), NE1.CANT / NE1.PARITATE, OBJ.DENUMIRE, OBJ.CODEXTERN
  FROM TMP_SIM_LANS1 L1
  INNER JOIN NODECHIV1 NE1 ON  L1.CODCOMANDA1 = NE1.CODCOMANDA1 AND  L1.CODPROIECTNOD = NE1.CODPROIECTNOD
  INNER JOIN NARTOBJ OBJ ON  OBJ.CODOBIECT = NE1.CODOBIECT
  LEFT  JOIN (SELECT sum(NSS.REST) REST, NSS.CODOBIECT
              FROM NIRSTOC NSS
                  INNER JOIN NIR      ON  NSS.CODNIR = NIR.CodNIR
                  INNER JOIN NGEST NG ON  NG.CODGEST = NIR.GEST
              WHERE (G_SUBUNIT = 1 OR  NG.CodSubunit = G_SUBUNIT)
              GROUP BY NSS.CODOBIECT
             ) NS ON  NS.CODOBIECT = OBJ.CODOBIECT;

  FOR v_SCEN IN
  (
  SELECT s2.CodComanda1, pn.CodObiect, s2.Rezervat
  FROM ScenariiLivr2 s2
      INNER JOIN Proiectnod    pn  ON  pn.codproiectnod = s2.codproiectnod
      INNER JOIN ScenariiLivr  s   ON  s.codscenariu    = s2.codscenariu
      INNER JOIN TMP_SIM_LANS1 TMP ON  TMP.CodComanda1  = s2.CODComanda1 and  TMP.CodProiectnod = s2.CodProiectnod
  WHERE s.Definitiv = 1
  )
  LOOP
    UPDATE TMP_SIM_LANS1 SET TotRezervat = TotRezervat - v_SCEN.Rezervat WHERE CodObiect = v_SCEN.CodObiect and  CodComanda1 = v_SCEN.Codcomanda1;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_get_tmp_comenzi</obj_name>
  <obj_hashval>62d8274c342f8ed2841f8827ea21a0ad</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_get_tmp_comenzi(adatestart character varying, adateend character varying, asubunit numeric, acc boolean, acs boolean, acg boolean)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  lOraDateStart  date;
  lOraDateEnd    date;
  lRezervat      numeric;
  lStoc          numeric;
  lComenziInCurs numeric;
BEGIN
  --Florin 22.08.2025 - fixat 66464
  --Florin 11.04.2024 - sinc. Oracle
  lOraDateStart := to_date (aDateStart, 'DD.MM.YYYY');
  lOraDateEnd   := to_date (aDateEnd, 'DD.MM.YYYY');

  DELETE FROM TMP_TraseuLivr_AllCmd;
  DELETE FROM TMP_TraseuLivr_AllCmd_baza;
  DELETE FROM TMP_TraseuLivr_Auto;
  DELETE FROM TMP_TraseuLivr_Comenzi;

  IF aCC THEN
    INSERT INTO TMP_TraseuLivr_Comenzi (CodComanda, TipDoc, CodComanda1, CodObiect,
        CodArticol, CodObiectEchiv, CodArticolEchiv, CantComandat,
        CantAcceptat, CantDisponibil, CantRezervat, CantComenzi,
        CodUM, ZecimaleUM, CodClient, CodAgenda,
        CodJudet, CodLocalit, NrDoc, DataDoc,
        CodTraseu, PozTraseu, Masa, Volum,
        CodMijlTransp, MasaU, VolumU, Delegat,
        Insotitor, InregNula, MasaO, VolumO,
        DenObiect, FlagLucru, CodTara, CodZona,
        Den_Zona, Den_Tara, Den_Judet, Den_Localit,
        Den_Client, TRANSPCLIENT, CODGRUPA, PARITATEGRUPA,
        D1, D2, D3)
    ( SELECT  DISTINCT C.CodComanda, C.TipDoc, C1.CodComanda1, C1.CodObiect, NAO.CodArticol, 0, 0, COALESCE (C1.CantComandat, 0) , COALESCE (C1.CantAcceptat, 0) , 0,
          0, 0, COALESCE (NA.UM, 0) , COALESCE (NUM.Zecimale, 2) , C.Partener, COALESCE (NAG.CodAgenda, 0) , COALESCE (NL.CodJudet, 0) , COALESCE (NAG.CodLocalit, 0) ,
          C.NrDoc, C.DataDoc,
          (CASE WHEN COALESCE (C.FaraTransport, 0) = 1 THEN 1
                ELSE (CASE WHEN COALESCE (C.CodTraseuLivr, 0) = 0 THEN COALESCE (NAG.CodTraseu, 0) ELSE C.CodTraseuLivr END)
           END),
          (CASE WHEN COALESCE (C.FaraTransport, 0) = 1 THEN 0
                ELSE (CASE WHEN COALESCE (C.ORDINELIVRARE, 0) = 0 THEN COALESCE (NAG.POZTRASEU, 0) ELSE C.ORDINELIVRARE END)
           END),
          COALESCE (C1.CantAcceptat * NAO.Masa, 0) , COALESCE (C1.CantAcceptat * NAO.Volum, 0) / 1000000,
          (CASE WHEN COALESCE (C.FaraTransport, 0) = 1 THEN 0 ELSE COALESCE (C.Mijltransp, 0) END),
          (CASE WHEN COALESCE (C.FaraTransport, 0) = 1 THEN 0 ELSE COALESCE (NPA.MasaU, 0) END),
          (CASE WHEN COALESCE (C.FaraTransport, 0) = 1 THEN 0 ELSE COALESCE (NPA.VolumU, 0) / 1000000 END),
          (CASE WHEN COALESCE (C.FaraTransport, 0) = 1 THEN 0 ELSE COALESCE (C.Delegat, 0) END),
          (CASE WHEN COALESCE (C.FaraTransport, 0) = 1 THEN 0 ELSE COALESCE (C.Insotitor, 0) END),
          0, COALESCE (NAO.Masa, 0) , COALESCE (NAO.Volum, 0) / 1000000, NAO.Denumire, 0, COALESCE (NL.CodTara, 0) , COALESCE (NL.CodZona, 0) , NZ.Den_Zona,
          NT.Den_Tara, NJ.Den_Judet, NL.Den_Localit, P.Den_Part,
          (CASE WHEN COALESCE (C.Faratransport, 0) = 0 THEN COALESCE (NAG.TRANSPCLIENT, 0) ELSE 2 END),
          NE.CODGRUPA, NE.PARITATE, C1.D1, C1.D2, C1.D3
        FROM Comanda          C
          INNER JOIN Comanda1 C1     ON C1.CodComanda   = C.CodComanda
          INNER JOIN NArtObj  NAO    ON NAO.CodObiect   = C1.CodObiect
          INNER JOIN NArt     NA     ON NA.CodArticol   = NAO.CodArticol
          INNER JOIN NUM             ON NUM.CodUM       = NA.UM
          INNER JOIN NPart    P      ON P.CodPart       = C.Partener
          LEFT  JOIN NAgenda  NAG    ON NAG.CodAgenda   = C.CodLocatie
          LEFT  JOIN NLocalit NL     ON NL.CodLocalit   = NAG.CodLocalit
          LEFT  JOIN NJudet   NJ     ON NJ.CodJudet     = NL.CodJudet
          LEFT  JOIN NTari    NT     ON NT.CodTara      = NL.CodTara
          LEFT  JOIN NZone    NZ     ON NZ.CodZona      = NL.Codzona
          LEFT  JOIN NParcAut NPA    ON NPA.CodNParcAut = C.MijlTransp
          LEFT  JOIN NEchiv   NE     ON NE.CodObiect    = C1.CodObiect
        WHERE
          COALESCE (C.Inchisa, 0) = 0
          and C1.Termen BETWEEN lOraDateStart AND lOraDateEnd
          and C.Subunitatea = aSubunit
          and C1.CantAcceptat = C1.RestAcceptat
          and C.UserIDBlocaj = current_setting ('PKG_GLOBALS.UserID', true) ::numeric
          and C.TipDoc = 18
          and C1.CantComandat &gt; 0
          and COALESCE (C.Displivrare, 0) = 0
          and coalesce (C.faratransport, 0) = 0);
    INSERT INTO TMP_TraseuLivr_AllCmd (codcomanda, tipdoc, partener, codagenda, codjudet, codlocalit, nrdoc, datadoc, masa, volum, codauto, delegat,
                                       selectie, sediu, judet, localitate, codtraseu)
    ( SELECT  DISTINCT C.CodComanda, C.TipDoc, p.Den_part, COALESCE (NAG.CodAgenda, 0) ,
          COALESCE (NL.CodJudet, 0) , COALESCE (NAG.CodLocalit, 0) , C.NrDoc, C.DataDoc,
          (select sum(nvl(C1.CantAcceptat * case when a.tiparticol = '1' then 0 else coalesce(NAO.Masa,0) end, 0))
            FROM comanda1 c1 INNER JOIN nartobj nao ON nao.codobiect = c1.codobiect
            inner join nart a on a.codarticol = nao.codarticol
            WHERE c1.codcomanda = c.codcomanda and c1.termen BETWEEN lOraDateStart AND lOraDateEnd
            and to_number(a.tiparticol) in (0,2)) ,
          (select sum(nvl(C1.CantAcceptat * case when a1.tiparticol = '1' then 0 else coalesce(NAO.Volum,0) end, 0) / 1000000)
            FROM comanda1 c1 INNER JOIN nartobj nao ON nao.codobiect = c1.codobiect
            inner join nart a1 on a1.codarticol = nao.codarticol
            WHERE c1.codcomanda = c.codcomanda and c1.termen BETWEEN lOraDateStart AND lOraDateEnd
            and to_number(a1.tiparticol) in (0,2)),
          COALESCE (c.MIJLTRANSP, 0) , c.delegat, 0, nag.obs, nj.den_judet, nl.den_localit, COALESCE (c.codtraseulivr, 0)
        FROM Comanda         C
          INNER JOIN NPart   P   ON P.CodPart     = C.Partener
          LEFT JOIN NAgenda  NAG ON NAG.CodAgenda = C.CodLocatie
          LEFT JOIN NLocalit NL  ON NL.CodLocalit = NAG.CodLocalit
          LEFT JOIN NJudet   NJ  ON NJ.CodJudet   = NL.CodJudet
        WHERE
          COALESCE (C.Inchisa, 0) = 0
          and EXISTS (SELECT C1.Termen FROM comanda1 c1 WHERE c1.codcomanda = c.codcomanda and c1.termen BETWEEN lOraDateStart AND lOraDateEnd)
          and C.Subunitatea = aSubunit
          and C.TipDoc = 18
          and COALESCE (C.Displivrare, 0) = 0
          and coalesce (C.faratransport, 0) = 0);
  END IF;

  IF aCS THEN
    INSERT INTO TMP_TraseuLivr_Comenzi (CodComanda, TipDoc, CodComanda1, CodObiect, CodArticol, CodObiectEchiv, CodArticolEchiv, CantComandat,
        CantAcceptat, CantDisponibil, CantRezervat, CantComenzi, CodUM, ZecimaleUM, CodClient, CodAgenda, CodJudet, CodLocalit, NrDoc, DataDoc,
        CodTraseu, PozTraseu, Masa, Volum, CodMijlTransp, MasaU, VolumU, Delegat, Insotitor, InregNula, MasaO, VolumO, DenObiect, FlagLucru, CodTara, CodZona,
        Den_Zona, Den_Tara, Den_Judet, Den_Localit, Den_Client, TRANSPCLIENT, CODGRUPA, PARITATEGRUPA,
        D1, D2, D3)
    ( SELECT  DISTINCT C.CodComanda, C.TipDoc, C1.CodComanda1, C1.CodObiect, NAO.CodArticol, 0,
          0, COALESCE (C1.CantComandat, 0) , COALESCE (C1.CantAcceptat, 0) , 0, 0, 0, COALESCE (NA.UM, 0) , COALESCE (NUM.Zecimale, 2) ,
          C.Subunitatea, COALESCE (NAG.CodAgenda, 0) , COALESCE (NL.CodJudet, 0) , COALESCE (NAG.CodLocalit, 0) , C.NrDoc, C.DataDoc,
          (CASE WHEN COALESCE (C.FaraTransport, 0) = 1 THEN 1
                ELSE (CASE WHEN COALESCE (C.CodTraseuLivr, 0) = 0 THEN COALESCE (NAG.CodTraseu, 0) ELSE C.CodTraseuLivr END)
           END),
          (CASE WHEN COALESCE (C.FaraTransport, 0) = 1 THEN 0
                ELSE (CASE WHEN COALESCE (C.ORDINELIVRARE, 0) = 0 THEN COALESCE (NAG.POZTRASEU, 0) ELSE C.ORDINELIVRARE END)
           END),
          COALESCE (C1.CantAcceptat * NAO.Masa, 0) , COALESCE (C1.CantAcceptat * NAO.Volum, 0) / 1000000,
          (CASE WHEN COALESCE (C.FaraTransport, 0) = 1 THEN 0 ELSE COALESCE (C.Mijltransp, 0) END),
          (CASE WHEN COALESCE (C.FaraTransport, 0) = 1 THEN 0 ELSE COALESCE (NPA.MasaU, 0) END),
          (CASE WHEN COALESCE (C.FaraTransport, 0) = 1 THEN 0 ELSE COALESCE (NPA.VolumU, 0) / 1000000 END),
          (CASE WHEN COALESCE (C.FaraTransport, 0) = 1 THEN 0 ELSE COALESCE (C.Delegat, 0) END),
          (CASE WHEN COALESCE (C.FaraTransport, 0) = 1 THEN 0 ELSE COALESCE (C.Insotitor, 0) END),
          0,
          CASE WHEN NA.TIPARTICOL = '1' THEN 0 ELSE nvl(NAO.Masa, 0) END, CASE WHEN NA.TIPARTICOL = '1' THEN 0 ELSE nvl(NAO.Volum, 0) END/ 1000000, NAO.Denumire,
          0, COALESCE (NL.CodTara, 0) , COALESCE (NL.CodZona, 0) , NZ.Den_Zona,
          NT.Den_Tara, NJ.Den_Judet, NL.Den_Localit, NS.Den_Subunit,
          (CASE WHEN COALESCE (C.Faratransport, 0) = 0 THEN COALESCE (NAG.TRANSPCLIENT, 0) ELSE 2 END),
          NE.CODGRUPA, NE.PARITATE, C1.D1, C1.D2, C1.D3
        FROM Comanda           C
          INNER JOIN Comanda1  C1    ON C1.CodComanda   = C.CodComanda
          INNER JOIN NArtObj   NAO   ON NAO.CodObiect   = C1.CodObiect
          INNER JOIN NArt      NA    ON NA.CodArticol   = NAO.CodArticol
          INNER JOIN NUM             ON NUM.CodUM       = NA.UM
          LEFT  JOIN NAgenda   NAG   ON NAG.CodSubunit  = C.Subunitsursa
          LEFT  JOIN NLocalit  NL    ON NL.CodLocalit   = NAG.CodLocalit
          LEFT  JOIN NJudet    NJ    ON NJ.CodJudet     = NL.CodJudet
          LEFT  JOIN NTari     NT    ON NT.CodTara      = NL.CodTara
          LEFT  JOIN NZone     NZ    ON NZ.CodZona      = NL.Codzona
          LEFT  JOIN NParcAut  NPA   ON NPA.CodNParcAut = C.MijlTransp
          LEFT  JOIN RezervatS RS    ON RS.CodComanda1  = C1.CodComanda1
          LEFT  JOIN NPARTTR   DEL   ON C.Delegat       = DEL.CODPARTTR
          LEFT  JOIN NEchiv    NE    ON NE.CodObiect    = C1.CodObiect
          LEFT  JOIN NSubunit  NS    ON NS.CodSubunit   = C.Subunitatea
        WHERE
          COALESCE (C.Inchisa, 0) = 0
          and C1.Termen BETWEEN lOraDateStart AND lOraDateEnd
          and C.SubunitSursa = aSubunit
          and C1.CantAcceptat = C1.RestAcceptat
          and C.UserIDBlocaj = current_setting ('PKG_GLOBALS.UserID', true) ::numeric
          and C.TipDoc = 44
          and C1.CantComandat &gt; 0
          and COALESCE (C.Displivrare, 0) = 0
          and coalesce (C.faratransport, 0) = 0);

    INSERT INTO TMP_TraseuLivr_AllCmd (codcomanda, tipdoc, partener, codagenda, codjudet, codlocalit, nrdoc, datadoc, masa, volum, codauto, delegat,
                                       selectie, sediu, judet, localitate, codtraseu)
    ( SELECT  DISTINCT C.CodComanda, C.TipDoc, ns.Den_Subunit, COALESCE (NAG.CodAgenda, 0) ,
          COALESCE (NL.CodJudet, 0) , COALESCE (NAG.CodLocalit, 0) , C.NrDoc, C.DataDoc,
          ( SELECT sum (COALESCE (C1.CantAcceptat * NAO.Masa, 0))
            FROM comanda1 c1 INNER JOIN nartobj nao ON nao.codobiect = c1.codobiect
            WHERE c1.codcomanda = c.codcomanda and c1.termen BETWEEN lOraDateStart AND lOraDateEnd) ,
          ( SELECT sum (COALESCE (C1.CantAcceptat * NAO.Volum, 0) / 1000000)
            FROM comanda1 c1 INNER JOIN nartobj nao ON nao.codobiect = c1.codobiect
            WHERE c1.codcomanda = c.codcomanda and c1.termen BETWEEN lOraDateStart AND lOraDateEnd) ,
          COALESCE (c.MIJLTRANSP, 0) , c.delegat, 0, nag.obs, nj.den_judet, nl.den_localit, COALESCE (c.codtraseulivr, 0)
        FROM Comanda           C
          INNER JOIN NSubunit  NS  ON NS.CodSubunit = C.Subunitatea
          LEFT  JOIN NAgenda   NAG ON NAG.CodAgenda = C.CodLocatie
          LEFT  JOIN NLocalit  NL  ON NL.CodLocalit = NAG.CodLocalit
          LEFT  JOIN NJudet    NJ  ON NJ.CodJudet   = NL.CodJudet
        WHERE
          COALESCE (C.Inchisa, 0) = 0
          and EXISTS (SELECT C1.Termen FROM comanda1 c1 WHERE c1.codcomanda = c.codcomanda and c1.termen BETWEEN lOraDateStart AND lOraDateEnd)
          and C.SubunitSursa = aSubunit
          and C.TipDoc = 44
          and COALESCE (C.Displivrare, 0) = 0
          and coalesce (C.faratransport, 0) = 0);
  END IF;

  IF aCG THEN
    INSERT INTO TMP_TraseuLivr_Comenzi (CodComanda, TipDoc, CodComanda1, CodObiect, CodArticol, CodObiectEchiv, CodArticolEchiv, CantComandat,
        CantAcceptat, CantDisponibil, CantRezervat, CantComenzi, CodUM, ZecimaleUM, CodClient, CodAgenda, CodJudet, CodLocalit, NrDoc, DataDoc,
        CodTraseu, PozTraseu, Masa, Volum, CodMijlTransp, MasaU, VolumU, Delegat, Insotitor, InregNula, MasaO, VolumO, DenObiect, FlagLucru, CodTara, CodZona,
        Den_Zona, Den_Tara, Den_Judet, Den_Localit, Den_Client, TRANSPCLIENT, CODGRUPA, PARITATEGRUPA, D1, D2, D3)
    ( SELECT  DISTINCT C.CodComanda, C.TipDoc, C1.CodComanda1, C1.CodObiect, NAO.CodArticol, 0, 0, COALESCE (C1.CantComandat, 0) , COALESCE (C1.CantAcceptat, 0) , 0,
          0, 0, COALESCE (NA.UM, 0) , COALESCE (NUM.Zecimale, 2) , C.Codgest, COALESCE (NAG.CodAgenda, 0) , COALESCE (NL.CodJudet, 0) , COALESCE (NAG.CodLocalit, 0) ,
          C.NrDoc, C.DataDoc,
          CASE WHEN COALESCE (C.FaraTransport, 0) = 1 THEN 1
               ELSE (CASE WHEN COALESCE (C.CodTraseuLivr, 0) = 0 THEN COALESCE (NAG.CodTraseu, 0) ELSE C.CodTraseuLivr END)
          END ,
          CASE WHEN COALESCE (C.FaraTransport, 0) = 1 THEN 0
               ELSE (CASE WHEN COALESCE (C.ORDINELIVRARE, 0) = 0 THEN COALESCE (NAG.POZTRASEU, 0) ELSE C.ORDINELIVRARE END)
          END ,
          nvl(C1.CantAcceptat * case when na.tiparticol = '1' then 0 else NAO.Masa end, 0), nvl(C1.CantAcceptat * case when na.tiparticol = '1' then 0 else NAO.Volum end, 0) / 1000000,
          (CASE WHEN COALESCE (C.FaraTransport, 0) = 1 THEN 0 ELSE COALESCE (C.Mijltransp, 0) END),
          (CASE WHEN COALESCE (C.FaraTransport, 0) = 1 THEN 0 ELSE COALESCE (NPA.MasaU, 0) END),
          (CASE WHEN COALESCE (C.FaraTransport, 0) = 1 THEN 0 ELSE COALESCE (NPA.VolumU, 0) / 1000000 END),
          (CASE WHEN COALESCE (C.FaraTransport, 0) = 1 THEN 0 ELSE COALESCE (C.Delegat, 0) END),
          (CASE WHEN COALESCE (C.FaraTransport, 0) = 1 THEN 0 ELSE COALESCE (C.Insotitor, 0) END),
          0,
          case when na.tiparticol = '1' then 0 else nvl(NAO.Masa, 0) end, case when na.tiparticol = '1' then 0 else nvl(NAO.Volum, 0) / 1000000 end, NAO.Denumire,
          0, COALESCE (NL.CodTara, 0) , COALESCE (NL.CodZona, 0) , NZ.Den_Zona,
          NT.Den_Tara, NJ.Den_Judet, NL.Den_Localit, NGE.Den_Gest,
          CASE WHEN COALESCE (C.Faratransport, 0) = 0 THEN COALESCE (NAG.TRANSPCLIENT, 0) ELSE 2 END ,
          NE.CODGRUPA, NE.PARITATE, C1.D1, C1.D2, C1.D3
        FROM Comanda          C
          INNER JOIN Comanda1 C1    ON C1.CodComanda   = C.CodComanda
          INNER JOIN NArtObj  NAO   ON NAO.CodObiect   = C1.CodObiect
          INNER JOIN NArt     NA    ON NA.CodArticol   = NAO.CodArticol
          INNER JOIN NUM            ON NUM.CodUM       = NA.UM
          LEFT  JOIN NAgenda  NAG   ON NAG.CodGest     = C.CodGest
          LEFT  JOIN NLocalit NL    ON NL.CodLocalit   = NAG.CodLocalit
          LEFT  JOIN NJudet   NJ    ON NJ.CodJudet     = NL.CodJudet
          LEFT  JOIN NTari    NT    ON NT.CodTara      = NL.CodTara
          LEFT  JOIN NZone    NZ    ON NZ.CodZona      = NL.Codzona
          LEFT  JOIN NParcAut NPA   ON NPA.CodNParcAut = C.MijlTransp
          LEFT  JOIN NPARTTR  DEL   ON C.Delegat       = DEL.CODPARTTR
          LEFT  JOIN NEchiv   NE    ON NE.CodObiect    = C1.CodObiect
          LEFT  JOIN NGest    NGE   ON NGE.CodGest     = C.CodGest
        WHERE
          COALESCE (C.Inchisa, 0) = 0
          and C1.Termen BETWEEN lOraDateStart AND lOraDateEnd
          and C.Subunitatea = aSubunit
          and C1.CantAcceptat = C1.RestAcceptat
          and C.UserIDBlocaj = current_setting ('PKG_GLOBALS.UserID', true) ::numeric
          and C.TipDoc = 43
          and C1.CantComandat &gt; 0
          and COALESCE (C.Displivrare, 0) = 0
          and coalesce (C.faratransport, 0) = 0);

    INSERT INTO TMP_TraseuLivr_AllCmd (codcomanda, tipdoc, partener, codagenda, codjudet, codlocalit, nrdoc, datadoc, masa, volum, codauto, delegat,
        selectie, sediu, judet, localitate, codtraseu)
    ( SELECT  DISTINCT C.CodComanda, C.TipDoc, nge.Den_gest, COALESCE (NAG.CodAgenda, 0) ,
          COALESCE (NL.CodJudet, 0) , COALESCE (NAG.CodLocalit, 0) , C.NrDoc, C.DataDoc,
            (select sum(nvl(C1.CantAcceptat * case when na.tiparticol = '1' then 0 else NAO.Masa end, 0))
            FROM comanda1 c1 INNER JOIN nartobj nao ON nao.codobiect = c1.codobiect
                          inner join nart na on na.codarticol = nao.codarticol
            WHERE c1.codcomanda = c.codcomanda and c1.termen BETWEEN lOraDateStart AND lOraDateEnd) ,
            (select sum(nvl(C1.CantAcceptat * case when na.tiparticol = '1' then 0 else NAO.Volum end, 0) / 1000000)
            FROM comanda1 c1 INNER JOIN nartobj nao ON nao.codobiect = c1.codobiect
                          inner join nart na on na.codarticol = nao.codarticol
            WHERE c1.codcomanda = c.codcomanda and c1.termen BETWEEN lOraDateStart AND lOraDateEnd) ,
          COALESCE (c.MIJLTRANSP, 0) , c.delegat, 0, nag.obs, nj.den_judet, nl.den_localit, COALESCE (c.codtraseulivr, 0)
        FROM Comanda         C
          INNER JOIN NGest   NGE ON NGE.CodGest   = C.CodGest
          LEFT JOIN NAgenda  NAG ON NAG.CodAgenda = C.CodLocatie
          LEFT JOIN NLocalit NL  ON NL.CodLocalit = NAG.CodLocalit
          LEFT JOIN NJudet   NJ  ON NJ.CodJudet   = NL.CodJudet
          LEFT JOIN NSubunit NS  ON NS.CodSubunit = C.Subunitatea
        WHERE
          COALESCE (C.Inchisa, 0) = 0
          and EXISTS (SELECT C1.Termen FROM comanda1 c1 WHERE c1.codcomanda = c.codcomanda and c1.termen BETWEEN lOraDateStart AND lOraDateEnd)
          and C.Subunitatea = aSubunit
          and C.TipDoc = 43
          and COALESCE (C.Displivrare, 0) = 0
          and coalesce (C.faratransport, 0) = 0);
  END IF;

  INSERT INTO tmp_traseulivr_auto (CODAUTO, MODEL, MARCA, SOFER, MASAU, VOLUMU, denumire, CodTraseu)
  SELECT  DISTINCT a.codnparcaut, mo.model, ma.marca, coalesce (s.nume,'') || ' ' || coalesce (s.prenume,'') , a.masau, a.volumu, obj.denumire, tmp.codtraseu
  FROM tmp_traseulivr_allcmd tmp
    INNER JOIN nparcaut    a   ON a.codnparcaut    = tmp.codauto
    LEFT JOIN nartobj      obj ON obj.codobiect    = a.codart
    LEFT JOIN nmarciauto   ma  ON ma.codmarciauto  = a.marca
    LEFT JOIN nmodeleauto  mo  ON mo.codmodeleauto = a.model
    LEFT JOIN npers        s   ON s.codpers        = a.sofer
  WHERE
    tmp.codauto &gt; 0;

  UPDATE tmp_traseulivr_auto a
  SET
  masai  = COALESCE (masai , 0) + (SELECT sum (COALESCE (c.masa , 0)) FROM tmp_traseulivr_allcmd c WHERE c.codauto = a.codauto) ,
  volumi = COALESCE (volumi, 0) + (SELECT sum (COALESCE (c.volum, 0)) FROM tmp_traseulivr_allcmd c WHERE c.codauto = a.codauto);

  FOR v_rec IN (SELECT CodObiect, CodComanda1, CodAgenda FROM TMP_TraseuLivr_Comenzi) LOOP
    lRezervat := 0;
    SELECT COALESCE (sum (RS.REST) , 0)
    INTO lRezervat
    FROM RezervatS        RS
      INNER JOIN Comanda1 C1 ON C1.CodComanda1 = RS.CodComanda1
      INNER JOIN Comanda  C  ON C.CodComanda   = C1.CodComanda
    WHERE
      C.Inchisa = 0
      and C1.Termen BETWEEN lOraDateStart AND lOraDateEnd
      and C.Subunitatea = aSubunit
      and C1.CantAcceptat = C1.RestAcceptat
      and C1.CodComanda1 = v_rec.CodComanda1
      and C.TipDoc IN (18, 43, 44)
      and coalesce (C.faratransport, 0) = 0
      and C1.CantComandat &gt; 0;

    lStoc := 0;
    SELECT sum (COALESCE (NS.Rest, 0))
    INTO lStoc
    FROM NIRStoc               NS
      LEFT JOIN TMP_IOArt_Luna TIOAL ON TIOAL.CodIOArt = NS.CodIOArt
      LEFT JOIN NIR                  ON NIR.CodNIR     = NS.CodNIR
      LEFT JOIN IOArt IOA            ON IOA.CodIOArt   = NS.CodIOArt
    WHERE
      NS.CodObiect = v_rec.CodObiect
      and TIOAL.MG &lt;&gt; 5
      and NS.Rest &lt;&gt; 0;

    lComenziInCurs := 0;
    SELECT sum (COALESCE (C1.RestAcceptat, 0))
    INTO lComenziInCurs
    FROM Comanda1 C1 INNER JOIN Comanda C ON C.CodComanda = C1.CodComanda
    WHERE
      C1.CodObiect = v_rec.CodObiect
      and C.Subunitatea = aSubunit
      and C1.Termen BETWEEN lOraDateStart AND lOraDateEnd
      and C1.RestAcceptat &gt; 0
      and coalesce (C.faratransport, 0) = 0
      and C.TipDoc IN (8, 11);

    UPDATE TMP_TraseuLivr_Comenzi
    SET
    CantRezervat   = lRezervat,
    CantDisponibil = lStoc,
    CantComenzi    = lComenziInCurs
    WHERE
      CodObiect = v_rec.CodObiect
      and CodComanda1 = v_rec.CodComanda1
      and CodAgenda = v_rec.CodAgenda;
  END LOOP;

  IF current_setting ('PKG_TRASEULIVR.FromManevra', true) ::numeric = 0 THEN
    INSERT INTO TMP_TRASEULIVR_ALLCMD_BAZA
    SELECT * FROM TMP_TRASEULIVR_ALLCMD;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_sp_gotorecord</obj_name>
  <obj_hashval>7dcf6e5382ba6a5f858f4165a4f5944c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  aCount        numeric;
  LastIndex     numeric;
  DataLastIndex date;
  vAlerta       numeric;
  vDataI       Date;
  vDataF       Date;
  vDurata      numeric;
  vOreStart    numeric;
  vOreStop     numeric;
  vOreSchimb   numeric;
  vOrePeZi     numeric;
  vNrSchimburi numeric;
  vZile        Integer;
BEGIN
  --Florin 12.04.2023 - sinc. Oracle
  --Florin 13.02.2023 - sinc. Oracle
  --Florin 20.07.2022 - sinc. Oracle
  --Florin 22.06.2022 - fixat 54674/54677
  --Florin 15.06.2022 - sinc. Oracle
  --Florin 29.12.2021 - sinc. Oracle (27.12.2021)
  --Laura 09.12.2021 - sinc. Oracle (09.12.2021)
  --Laura 15.10.2021 - sinc Oracle (14.10.2021)
  --Laura 24.09.2021 - sinc Oracle (24.09.2021)
  --Adina 02.08.2021 - sinc.Oracle - add callcenter si completat over la row_number
  --Adina 14.07.2021 - sinc.Oracle din 14.07.2021
  --Bogdan 08.10.2020
  --Florin 02.04.2021 - fixat 46726
  --Florin 16.11.2021 - fixat 52001
  perform pkg_utilaje_setct_monitor('MON_53');
  INSERT INTO TMP_UTILAJE (CODUTILAJ,
      CODOBIECT,
      NRINVENTAR,
      ETICHETA,
      TIPUTILAJ,
      FLOTA,
      MODEL,
      ANF,
      SERIEF,
      INCARCARE,
      DATAGARANTIE,
      DATAGARANTIEI,
      INGARANTIE,
      LUNGIME,
      LATIME,
      INALTIME,
      OBS,
      DENUMIRE,
      INACTIV,
      CORECTIEINDEX,
      UM,
      CodGest,
      PLAFONCANTF,
      CodPart,
      Dincontract,
      CodIes1,
      FURNIZOR,
      DOC,
      APROBAT,
      DATASTART,
      NRCONTR,
      DATACONTR,
      CODCONTRFACT,
      CODFURNIZOR,
      TIP,
      CODLOCALIT,
      ADRESA,
      HFACTOR,
      AGENT,
      CODPRODUCATOR, CODLOCATIE)
  SELECT U.CODUTILAJ,
    U.CODOBIECT,
    CASE WHEN U.NRINVENTAR = 0 THEN NULL ELSE U.NRINVENTAR END ,
    U.ETICHETA,
    U.TIPUTILAJ,
    U.FLOTA,
    U.MODEL,
    U.ANF,
    U.SERIEF,
    U.INCARCARE,
    U.DATAGARANTIE,
    U.DATAGARANTIEI,
    U.INGARANTIE,
    U.LUNGIME,
    U.LATIME,
    U.INALTIME,
    U.OBS,
    NOBJ.DENUMIRE,
    U.INACTIV,
    COALESCE (U.CORECTIEINDEX, -1) ,
    U.UM,
    U.CodGest,
    U.PLAFONCANTF,
    U.CodPart,
    (SELECT count ( *)
     FROM contract1 c1 INNER JOIN contract c ON c.codcontract = c1.codcontract
     WHERE COALESCE (c.anulat, 0) = 0 and c1.codutilaj = u.codutilaj
    ) ,
    U.CodIes1,
    COALESCE (P.DEN_PART, '?') ,
    CASE WHEN U.DOC IS NULL and U.CODIES1 &gt; 0 THEN I.NRDoc || '/' || to_char (I.DataDoc, 'DD.MM.YYYY') ELSE U.DOC END ,
    COALESCE (U.Aprobat, 0) ,
    U.DATASTART,
    U.NRCONTR,
    U.DATACONTR,
    COALESCE (C1.CODCONTRACT, C.CODCONTRACT) ,
    U.CODFURNIZOR,
    CASE WHEN U.TIP IS NULL AND U.CODPART &gt; 0 THEN 2
         ELSE CASE WHEN (SELECT COUNT ( *) FROM UTILAJE1 WHERE CODUTILAJ = RECID) &gt; 0 AND U.TIP IS NULL THEN 1  ELSE COALESCE (U.TIP, 0) END
    END ,
    U.CODLOCALIT,
    U.ADRESA,
    U.HFACTOR,
    U.AGENT,
    U.CODPRODUCATOR, U.CODLOCATIE
  FROM UTILAJE          U
    LEFT JOIN NARTOBJ  NOBJ ON NOBJ.CODOBIECT  = U.CODOBIECT
    LEFT JOIN IESIRI1   I1   ON I1.CODIES1      = U.CODIES1
    LEFT JOIN IESIRI    I    ON I1.CODIES       = I.CODIES
    LEFT JOIN NPART     P    ON U.CODFURNIZOR   = P.CODPART
    LEFT JOIN CONTRACT1 C1   ON C1.CODCONTRACT1 = I1.CODCONTRACT1
    LEFT JOIN CONTRACT  C    ON C.CODCONTRACT   = I.CODCONTRACT
  WHERE
    U.CODUTILAJ = RECID;
  INSERT INTO TMP_UTILAJE1 (CODUTILAJ1,
      CODUTILAJ,
      NRCONTR,
      CARNETCONTR,
      STATUS_PART,
      STATUS_DEPO,
      CODPART,
      CODLOCATIE,
      DATA,
      OBS,
      STATUS_SERVICE,
      Denlocatie,
      INDEXLOCAL,
      CODPERS,
      DATACREARE,
      RESPONSABIL,
      ESTETIC)
  SELECT U1.CODUTILAJ1,
    U1.CODUTILAJ,
    U1.NRCONTR,
    U1.CARNETCONTR,
    U1.STATUS_PART,
    U1.STATUS_DEPO,
    U1.CODPART,
    COALESCE (U1.CODLOCATIE, 0) ,
    U1.DATA,
    U1.OBS,
    U1.STATUS_SERVICE,
    NAG.OBS,
    U1.INDEXLOCAL,
    U1.CODPERS,
    U1.Datacreare,
    P.NUME || ' ' || P.PRENUME,
    U1.ESTETIC
  FROM UTILAJE1       U1
    LEFT JOIN NPERS   P   ON P.CODPERS     = COALESCE (U1.CODPERS, 0)
    LEFT JOIN NAGENDA NAG ON U1.CODLOCATIE = NAG.CODAGENDA
  WHERE
    CODUTILAJ = RECID;

  INSERT INTO TMP_UTILAJE20 (CODUTILAJ20,
      CODUTILAJ,
      NRDOC,
      DATADOC,
      DESCRIERE,
      STARE,
      OPERATOR,
      OBS,
      DENOPERATOR,
      CODIES,
      FACTURARE,
      BONCONSUM,
      CODLOCALIT,
      ADRESA,
      CODPERSC,
      TELEFON,
      CALLCENTER,
      CODBC,
      PRIORITATE)
  SELECT U.CODUTILAJ20,
    U.CODUTILAJ,
    U.NRDOC,
    U.DATADOC,
    U.DESCRIERE,
    CASE WHEN U.STARE = 5 AND I.CODIES IS NULL THEN 4  ELSE U.STARE END ,
    U.OPERATOR,
    U.OBS,
    UT.USERNAME DENOPERATOR,
    I.CODIES,
    CASE WHEN I.CODIES IS NOT NULL THEN I.PREFIXDOC||I.NRDOC||'/'||TO_CHAR(I.DATADOC,'DD.MM.YYYY') END,
       CASE WHEN BC.CODIES IS NOT NULL THEN BC.PREFIXDOC||BC.NRDOC||'/'||TO_CHAR(BC.DATADOC,'DD.MM.YYYY') END,
      U.CODLOCALIT,
    U.ADRESA,
    U.CODPERSC,
    C.TELEFON,
    U.CALLCENTER,
    BC.CODIES,
    U.PRIORITATE
  FROM UTILAJE20              U
    LEFT JOIN TMP_UTILIZATOR UT ON U.OPERATOR = UT.CODUTILIZATOR
    LEFT JOIN NPERSCONTACT    C  ON U.CODPERSC = C.CODPERSC
    LEFT JOIN IESIRI          I  ON I.CODIES   = U.CODIES
    LEFT JOIN IESIRI       BC ON BC.CODIES = U.CODBC
  WHERE
    CODUTILAJ = RECID;
  INSERT INTO TMP_UTILAJEDEV (CODUTILAJDEV,
      CODUTILAJ,
      CODUTILAJ20,
      CODOBIECT,
      CANT,
      PRET,
      CANTFACT,
      FACTURABIL,
      CODIES1,
      DENUMIRE,
      CODUTILAJ2,
      SERVICIU,
      DENSERVICIU,
      TIPLIVRARE,
      CODAUTO,
      TVA,
      VALOARE,
          CONSUMABIL,
          CANTCONS)
  SELECT D.CODUTILAJDEV,
    D.CODUTILAJ,
    D.CODUTILAJ20,
    D.CODOBIECT,
    D.CANT,
    D.PRET,
    D.CANTFACT,
    D.FACTURABIL,
    D.CODIES1,
    OBJ.DENUMIRE,
    D.CODUTILAJ2,
    IV.SERVICIU,
    SERV.DENUMIRE,
    D.TIPLIVRARE,
    U2.CODAUTO,
    COALESCE (D.TVA, D.CANT * D.PRET * OBJTVA.PROCENT / 100) ,
    D.CANT * D.PRET,
      D.CONSUMABIL,
       D.CANTCONS
  FROM UTILAJEDEV              D
    LEFT JOIN UTILAJE2         U2   ON U2.CODUTILAJ2         = D.CODUTILAJ2
    LEFT JOIN NINTERVENTIIAUTO IV   ON IV.CODINTERVENTIIAUTO = U2.INTERVENTIE
    LEFT JOIN NARTOBJ          OBJ  ON OBJ.CODOBIECT         = D.CODOBIECT
    LEFT JOIN NARTOBJ          SERV ON SERV.CODOBIECT        = IV.SERVICIU
    LEFT JOIN ( SELECT NTVA.PROCENT, O.CODOBIECT
                FROM NARTOBJ              O
                  LEFT JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = O.CODARTICOL
                  LEFT JOIN TMP_NTVA_LUNA NTVA ON NTVA.CODTVA    = NAL.CODTVA
              ) OBJTVA ON OBJTVA.CODOBIECT = D.CODOBIECT
  WHERE
    D.CODUTILAJ = RECID;

  UPDATE TMP_UTILAJE20 TMP SET DEVIZ = CASE WHEN (SELECT COUNT ( *) FROM TMP_UTILAJEDEV D WHERE D.CODUTILAJ20 = TMP.CODUTILAJ20) &gt; 0 THEN 1  ELSE 0 END;
  INSERT INTO TMP_UTILAJE2 (CODUTILAJ2,
      CODUTILAJ,
      INTERVENTIE,
      CODCOMANDA1,
      CODOBIECT,
      CODRETETA,
      UMSec,
      Denumire,
      Den_UM1,
      D1,
      D2,
      D3,
      RelatieUM1,
      RESTDEPREDAT,
      PERTIP,
      PERDURATA,
      PERKM,
      ATENTIONAREZILE,
      ATENTIONAREKM,
      DATACURENTA,
      den_interventie,
      accidentala,
      CODUTILAJ20,
      CODAUTO,
      KMPARCURSI,
      DURATA,
      NRSCHIMBURI,
      ORESCHIMB,
      ORASTART)
  SELECT U2.CODUTILAJ2,
    U2.CODUTILAJ,
    U2.INTERVENTIE,
    U2.CODCOMANDA1,
    IA.Serviciu,
    IA.Codreteta,
    num1.codum1,
    obj.denumire,
    num1.den_um1,
    a.d1,
    a.d2,
    a.d3,
    a.relatieum1,
    COALESCE (prod.rest, 0) ,
    ia.PERTIP,
    ia.PERDURATA,
    ia.PERKM,
    ia.ATENTIONAREZILE,
    ia.ATENTIONAREKM,
    CURRENT_DATE,
    ia.denumire,
    COALESCE (ia.accidentala, 0) ,
    U2.CODUTILAJ20,
    U2.CODAUTO,
    U2.KMPARCURSI,
    PC.DURATA,
    G.NRSCHIMBURI,
    G.ORESCHIMB,
    G.ORASTART
  FROM UTILAJE2                U2
    LEFT JOIN ninterventiiauto ia   ON u2.interventie = ia.codinterventiiauto
    LEFT JOIN nartobj          obj  ON ia.serviciu    = obj.codobiect
    LEFT JOIN nart             a    ON obj.codarticol = a.codarticol
    LEFT JOIN num1                  ON a.UM           = num1.codum and COALESCE (num1.secundara, 0) = 0
    LEFT JOIN comanda1         c1   ON u2.codcomanda1 = c1.codcomanda1
    LEFT JOIN cmdprodmat       prod ON c1.codcomanda1 = prod.codcomanda1 and COALESCE (prod.tip, 0) = 0
    left join prodcomp        pc   on pc.codprodcomp = ia.codreteta
    left join prodgest        pg   on pc.codprodcomp = pg.codprodcomp and coalesce(pg.timpest,0) = 0
    left join ngest        g    on pg.codgest      = g.codgest
  WHERE
    u2.CODUTILAJ = RECID;
  FOR v_rec IN (SELECT * FROM tmp_utilaje2) LOOP
    SELECT count ( *)
    INTO acount
    FROM prodcomp pc INNER JOIN prodgest pg ON pg.codprodcomp = pc.codprodcomp
    WHERE pc.codprodcomp = v_rec.codreteta;

    IF acount = 1 THEN
      SELECT pg.codgest
      INTO acount
      FROM prodcomp pc INNER JOIN prodgest pg ON pg.codprodcomp = pc.codprodcomp
      WHERE pc.codprodcomp = v_rec.codreteta;

      UPDATE tmp_utilaje2 SET codgest = acount WHERE codutilaj2 = v_rec.codutilaj2;
    END IF;
  END LOOP;

  INSERT INTO TMP_UTILAJE2C (CODUTILAJ2C,
      CODUTILAJ2,
      CODUTILAJ,
      INDEXC,
      DATAINDEXC,
      CODCOMANDA1,
      indexv,
      datav,
      resetat,
      IndexLocal,
      NrDoc,
      Datadoc,
      Den_Gest,
      Codcomanda,
      TipDoc,
      Explicatii,
      DATASTART,
      DATAEND,
      DURATA,
      DATASTARTS,
      DATAENDS,
      CODINTR1,
      INDEXA,
      DATAA,
      ZiV,
      ORESTART,
      ORESTOP)
  SELECT u2c.CODUTILAJ2C,
    u2c.CODUTILAJ2,
    u2c.CODUTILAJ,
    u2c.INDEXC,
    u2c.DATAINDEXC,
    COALESCE (c1.CODCOMANDA1, 0) ,
    u2c.indexv,
    u2c.datav,
    u2c.resetat,
    COALESCE (u2c.indexlocal, Row_Number() over(partition by u2c.codutilaj order by u2c.datav, u2c.indexv)) ,
    c.nrdoc,
    c.datadoc,
    G.Den_Gest,
    c.codcomanda,
    c.tipdoc,
    u2c.Explicatii,
    u2c.datastart,
    u2c.dataend,
    case when coalesce(pc.durata,0) &gt; 0 then pc.durata
    else
      CASE WHEN (NOT u2c.datastart IS NULL) and (NOT u2c.dataend IS NULL) THEN TRUNC (24 * 60 * (CAST (u2c.dataend AS DATE) - CAST (u2c.datastart AS DATE))) END
    end,
    to_char (u2c.datastart, 'DD.MM.YYYY HH24:MI') ,
    to_char (u2c.dataend, 'DD.MM.YYYY HH24:MI') ,
    i1.codintr1,
    U2C.INDEXV - COALESCE (I.ATENTIONAREKM, 0) ,
    U2C.DATAV  - COALESCE (I.ATENTIONAREZILE, 0)::integer ,
    pkg_list_base_utils_decode_zi (u2c.datav),
    U2C.ORESTART, U2C.ORESTOP
  FROM UTILAJE2C                U2C
    INNER JOIN UTILAJE2         U2 ON U2C.CODUTILAJ2       = U2.CODUTILAJ2
    INNER JOIN NINTERVENTIIAUTO I  ON I.CODINTERVENTIIAUTO = U2.INTERVENTIE
    LEFT JOIN comanda1          c1 ON u2c.codcomanda1      = c1.codcomanda1
    LEFT JOIN comanda           c  ON c1.codcomanda        = c.codcomanda
    LEFT JOIN ngest             g  ON g.codgest            = c.codgest
    LEFT JOIN intrari1          i1 ON c1.codcomanda1       = i1.codcmdint1
    left join prodcomp pc on pc.codprodcomp = i.codreteta
  WHERE
    u2c.CODUTILAJ = RECID;
  for v_rec in (
                select u2c.codutilaj2c, u2.codutilaj2, pc.durata, g.nrschimburi, g.oreschimb, g.orastart, u2c.datastart
                from utilaje2 u2
                     INNER JOIN NINTERVENTIIAUTO I ON I.CODINTERVENTIIAUTO = U2.INTERVENTIE
                     inner join prodcomp pc on pc.codprodcomp = i.codreteta
                     inner join utilaje2c u2c on u2c.codutilaj2 = u2.codutilaj2
                     inner join prodgest pg on pg.codprodcomp = pc.codprodcomp and coalesce(pg.timpest,0) = 0
                     inner join ngest g on g.codgest = pg.codgest
                where i.accidentala = 1 and pc.durata &lt;&gt; 0
               ) loop
    vDurata      := v_rec.Durata;
    vOreSchimb   := v_rec.OreSchimb;
    vNrSchimburi := v_rec.NrSchimburi;
    if vNrSchimburi = 0 then vNrSchimburi := 1; end if;
    if (vOreSchimb = 0) and (vNrSchimburi = 1) then vOreSchimb := 24;
    else
      if (vOreSchimb = 0) and (vNrSchimburi &gt; 1) then
        vOreSchimb := 24/vNrSchimburi;
      end if;
    end if;
    vOrePeZi := vOreSchimb * vNrSchimburi;
    update tmp_utilaje2c set durata = vDurata where codutilaj2c = v_rec.codutilaj2c;
    vDataI   := v_rec.DataStart;
    vZile    := Trunc(vDurata / 60 / vOrePeZi);
    if vZile = 0 then
      update utilaje2c set OreStart = vDurata / 60 where codutilaj2c = v_rec.codutilaj2c;
      update tmp_utilaje2c set OreStart = vDurata / 60 where codutilaj2c = v_rec.codutilaj2c;
      vOreStart := vDurata / 60;
    else
      if vOrePeZi &gt; 24 then
        update utilaje2c set OreStart = 24 where codutilaj2c = v_rec.codutilaj2c;
        update tmp_utilaje2c set OreStart = 24 where codutilaj2c = v_rec.codutilaj2c;
        vOreStart := 24;
        vOrePeZi := 24;
      else
        if vDurata/60 &lt; vOreSchimb * vNrSchimburi then
          update utilaje2c set OreStart = vDurata/60 where codutilaj2c = v_rec.codutilaj2c;
          update tmp_utilaje2c set OreStart = vDurata/60 where codutilaj2c = v_rec.codutilaj2c;
          vOreStart := vDurata / 60;
        else
          update utilaje2c set OreStart = vOreSchimb * vNrSchimburi where codutilaj2c = v_rec.codutilaj2c;
          update tmp_utilaje2c set OreStart = vOreSchimb * vNrSchimburi where codutilaj2c = v_rec.codutilaj2c;
          vOreStart := vOreSchimb * vNrSchimburi;
        end if;
      end if;
    end if;
    vDataF   := add_days(vDataI,vZile);
    vOreStop := 0;
    if vZile &gt; 0 then
      vOreStop := vDurata / 60 - (vZile - 1) * vOrePeZi - vOreStart;
    end if;
    update utilaje2c set OreStop = vOreStop where codutilaj2c = v_rec.codutilaj2c;
    update tmp_utilaje2c set OreStop = vOreStop where codutilaj2c = v_rec.codutilaj2c;
    if vZile &gt; 0 then
      vOreStop := vDurata / 60 - (vZile - 1) * vOrePeZi - vOreStart;
    else
      vOreStop := vDurata / 60;
    end if;
    vDataF   := add_days(vDataF, (vOreStop/24)::integer);
    update tmp_utilaje2c set DataEnd = vDataF where codutilaj2c = v_rec.codutilaj2c;
  end loop;

  INSERT INTO tmp_utilaje2p (codutilaj2p, codutilaj2, codutilaj, codpers, angajat, marca)
  SELECT u2p.codutilaj2p, u2p.codutilaj2, u2p.codutilaj, u2p.codpers, p.nume|| ' '|| p.prenume, p.marca
  FROM utilaje2p u2p LEFT JOIN npers p ON p.codpers = u2p.codpers
  WHERE u2p.codutilaj = recid;

  INSERT INTO TMP_UTILAJE3(CODUTILAJ3,CODUTILAJ,DATABORD,INDEXBORD,AN,LUNA,CORECTIEINDEX, TIP_INDEX, INDEXRESETAT)
  SELECT CODUTILAJ3,CODUTILAJ,DATABORD,INDEXBORD,AN,LUNA,CORECTIEINDEX, COALESCE(TIP_INDEX,0), CASE WHEN NVL(CORECTIEINDEX, 0) &lt;&gt; 0 THEN 1 ELSE 0 END
  FROM UTILAJE3
  WHERE CODUTILAJ = RECID;

  LastIndex     := 0;
  DataLastIndex := null;

  for v_rec in (select * from tmp_utilaje3 where coalesce (tip_index,0) = 0 order by An, Luna, DataBord) loop
    LastIndex     := v_rec.indexbord;
    DataLastIndex := v_Rec.Databord;
  END LOOP;

  FOR v_Rec IN (SELECT * FROM tmp_utilaje2c) LOOP
    vAlerta := 0;
    IF   ((LastIndex &gt; 0)
      and (LastIndex &gt;= COALESCE (v_Rec.IndexA, 0))
      and (LastIndex &lt;  COALESCE (v_Rec.IndexV, 0))
      and (COALESCE (v_rec.CodIntr1, 0) = 0)
      )
      or   ((DataLastIndex IS NOT NULL)
        and (DataLastIndex &gt;= v_rec.DataA)
        and (DataLastIndex &lt;  v_Rec.DataV)
        and (COALESCE (v_rec.CodIntr1, 0) = 0))
      THEN
      vAlerta := 1;
    END IF;

    IF LastIndex &gt; 0 THEN
      IF COALESCE (v_rec.IndexV, 0) &gt; 0 THEN
        IF LastIndex &gt;= COALESCE (v_rec.IndexV, 0) THEN
          IF (COALESCE (v_Rec.CodComanda1, 0)   &gt; 0) and (COALESCE (v_rec.CodIntr1, 0) = 0) THEN
            vAlerta := 2;
          ELSE
            IF COALESCE (v_rec.CodComanda1, 0) = 0 THEN
              vAlerta := 3;
            END IF;
          END IF;
        END IF;
      END IF;
    END IF;

    IF DataLastIndex IS NOT NULL THEN
      IF v_rec.DataV IS NOT NULL THEN
        IF DataLastIndex &gt;= v_rec.DataV THEN
          IF (COALESCE (v_Rec.CodComanda1, 0) &gt; 0) and (COALESCE (v_rec.CodIntr1, 0) = 0) THEN
            IF vAlerta = 0 THEN
              vAlerta := 2;
            END IF;
          ELSE
            IF COALESCE (v_rec.CodComanda1, 0) = 0 THEN
              IF vAlerta = 0 THEN
                vAlerta := 3;
              END IF;
            END IF;
          END IF;
        END IF;
      END IF;
    END IF;

    UPDATE tmp_utilaje2c SET alerta = vAlerta WHERE codutilaj2c = v_rec.codutilaj2c;
  END LOOP;

  INSERT INTO TMP_UTILAJETIPINDEX(CODTINDEX, codutilaj, tip_index, denumire, um, plafoncantf)
  SELECT CODTINDEX, codutilaj, tip_index, denumire, um, plafoncantf
  FROM UTILAJETIPINDEX WHERE CODUTILAJ = RECID;
  PERFORM pkg_utilaje_InitUtilajeTipIndex(RECID);
  PERFORM PKG_CFGTABLES_EXT_GOTORECORD(508);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_serii_obiect_stoc</obj_name>
  <obj_hashval>fd350a127ce33a401d5807ea550de0de</obj_hashval>
  <obj_text>SELECT DISTINCT s.codserie,
    s.serie,
    s.codobiect,
    s.obs
   FROM martor.nserii s
     JOIN martor.nirser ser ON ser.codserie = s.codserie
  WHERE s.codobiect = (( SELECT pkg_serii_getobiectcurent.wme_result
           FROM martor.pkg_serii_getobiectcurent(NULL::numeric, NULL::numeric) pkg_serii_getobiectcurent(wme_result, fakeparam))) AND ser.rest &gt; 0::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_dvi_contchelt</obj_name>
  <obj_reftable>dvi</obj_reftable>
  <obj_hashval>65d65ac0b9da579fcd932d564ec428c9</obj_hashval>
  <obj_text>CREATE INDEX idx_dvi_contchelt ON dvi USING btree (contchelt)</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rapstocmed_umple_tmp</obj_name>
  <obj_hashval>a5b1abb48db5f29dcf545917881b494c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rapstocmed_umple_tmp(pnewdata character varying, polddata character varying, pcodsiui character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vNewData     date;
  vDataRef     date;
  cEGN         varchar;
  vAn          numeric;
  vLuna        numeric;
  vZi          numeric;
  vTipGestExcl numeric := -1;
BEGIN
  --Florin 28.08.2025 - sinc. Oracle
  --Florin 30.09.2024 - fixat 63531
  --Florin 25.09.2024 - sinc. Oracle
  --Florin 05.09.2024 - sinc. Oracle
  --Florin 29.08.2024 - sinc. Oracle
  --Stef 11.04.2024
  CALL create_wm_temps_flag('PKG_RAPSTOCMED'); --Se activeaza pt PG
  vNewData := To_Date(pNewData,'dd.mm.yyyy');
  vDataRef := CASE WHEN pOldData IS NULL THEN vNewData ELSE add_days(To_Date(pOldData, 'dd.mm.yyyy'), 1) END;
  PERFORM pkg_rapstocmed_GOLESTE_TMP();

  vAn   := Extract( YEAR FROM vDataRef);
  vLuna := Extract( MONTH FROM vDataRef);
  cEGN  := Coalesce(NULLIF(fnc_getvalconstanta('ExclGestNeconforme', vAn, vLuna), ''), '1');
  IF cEGN = '2' THEN
    vTipGestExcl := 4;
  END IF;

  INSERT INTO TMP_RAPSTOCMED_NAO
  SELECT codobiect, NULLIF(Trim(codcnas),'') CIM, Coalesce(coefcnas,1) coefcnas
  FROM nartobj
  WHERE Coalesce(rapcnas,1) = 1 AND Coalesce(coefcnas,1) &lt;&gt; 0 AND NULLIF(Trim(codcnas),'') IS NOT NULL;

  INSERT INTO TMP_RAPSTOCMED_SUB
  SELECT codsubunit, NULLIF(Trim(codsiui),'') CodWorkplace, Trim(REPLACE(Upper(cif), 'RO','')) cif
  FROM nsubunit
  WHERE NULLIF(Trim(codsiui),'') IS NOT NULL AND codsiui = pCodSIUI;

  INSERT INTO TMP_RAPSTOCMED(codworkplace, cim, numarLot, dataExpirareLot, tip, semn, cant, dataop)
  SELECT sub.CodWorkplace, nao.CIM, Trim(ser.SERIE) numarLot, Coalesce(nser.TG, ns.TG) dataExpirareLot, 0 Tip, 1 Semn, Sum(ns.rest*nao.coefcnas) CANT, To_Date('2100','yyyy') DataOp
  FROM nirstoc ns
    INNER JOIN tmp_rapstocmed_nao nao ON nao.codobiect = ns.codobiect
    INNER JOIN nir n ON n.codnir = ns.codnir
    INNER JOIN ngest g ON g.codgest = n.gest
    INNER JOIN tmp_rapstocmed_sub sub ON sub.codsubunit = g.codsubunit
    INNER JOIN nirser nser ON nser.codnirstoc = ns.codnirstoc
    INNER JOIN nserii ser ON ser.codserie = nser.codserie
  WHERE ns.rest &lt;&gt; 0
    AND NOT ns.codioart IN (SELECT DISTINCT codioart FROM ioart1 WHERE mg = 5)
    AND Coalesce(g.tip, 0) &lt;&gt; vTipGestExcl
  GROUP BY sub.CodWorkplace, nao.CIM, Trim(ser.SERIE), Coalesce(nser.TG, ns.TG);

  INSERT INTO TMP_RAPSTOCMED(
    codworkplace, cim, numarLot, dataExpirareLot, tip, semn, cant, dataop,
    CodTipPart, CodTipDoc, Part, NrFactura, NrAviz, DataDoc, CodTara )
  SELECT -- intrari in stoc
    sub.CodWorkplace, nao.CIM, Trim(ser.SERIE) numarLot, Coalesce(nser.TG, ns.TG) dataExpirareLot, 1 Tip, 1 Semn, nser.cantnir*nao.coefcnas CANT, DATE_TRUNC('DAY', i.datacreare) DataOp,
    CASE WHEN Upper(t.simbauto) = 'RO' THEN 1 ELSE 2 END CodTipPart,
    1 CodTipDoc, --1 (achizitie), 2 (retur), 3 (retragere), 4 (reglare stoc prin inventar).
    CASE
      WHEN i.tipdoc = 6             THEN Trim(REPLACE(Upper(subs.cif), 'RO',''))
      WHEN Upper(t.simbauto) = 'RO' THEN Trim(REPLACE(Upper(fisc.codfiscal), 'RO',''))
      ELSE                               p.den_part
    END Part,
    CASE WHEN i.tipdoc &lt;&gt; 2 THEN I.Nrdoc END NrFactura,
    CASE WHEN i.tipdoc = 2  THEN I.Nrdoc END NrAviz,
    I.DataDoc,
    NULL CodTara
  FROM intrari i
    INNER JOIN tmp_rapstocmed_sub sub ON sub.codsubunit = i.subunitatea
    INNER JOIN nir n ON n.codintr = i.codintr AND n.tipnir = i.tipdoc
    INNER JOIN nirstoc ns ON ns.codnir = n.codnir
    INNER JOIN ngest g ON g.codgest = n.gest
    INNER JOIN nirser nser ON nser.codnirstoc = ns.codnirstoc
    INNER JOIN nserii ser ON ser.codserie = nser.codserie
    LEFT  JOIN tmp_rapstocmed_nao nao ON nao.codobiect = ns.codobiect
    LEFT  JOIN npart p ON p.codpart = i.partener
    LEFT  JOIN nagenda a ON a.codagenda = i.codlocatie
    LEFT  JOIN nlocalit loc ON loc.codlocalit = a.codlocalit
    LEFT  JOIN ntari t ON t.codtara = loc.codtara
    LEFT  JOIN npartcodfisc fisc ON fisc.cod_codfiscal = i.codfiscal
    LEFT  JOIN nsubunit subs ON subs.codsubunit = i.codsubunit
  WHERE i.operat = 1 AND i.anulat = 0 AND i.tipdoc IN (1,2,5,6)
    AND n.operat = 1
    AND Coalesce(n.datacreare, i.datacreare) &gt;= vDataRef
    AND ns.cantnir &lt;&gt; 0
    AND nao.codobiect IS NOT NULL
    AND NOT ns.codioart IN (SELECT DISTINCT codioart FROM ioart1 WHERE mg = 5)
    AND Coalesce(g.tip, 0) &lt;&gt; vTipGestExcl;

  INSERT INTO TMP_RAPSTOCMED(
    codworkplace, cim, numarLot, dataExpirareLot, tip, semn, cant, dataop,
    CodTipPart, CodTipDoc, Part, NrFactura, NrAviz, DataDoc, CodTara )
  SELECT -- livrari din intrari
    sub.CodWorkplace, nao.CIM, Trim(ser.SERIE) numarLot, Coalesce(nser.TG, ns.TG) dataExpirareLot, 1 Tip, -1 Semn, l1.cant*nao.coefcnas CANT, DATE_TRUNC('DAY',i.datacreare) DataOp,
    CASE WHEN Upper(t.simbauto) = 'RO' THEN 1 ELSE 2 END CodTipPart,
    2 CodTipDoc, --1 (achizitie), 2 (retur), 3 (retragere), 4 (reglare stoc prin inventar).
    CASE
      WHEN i.tipdoc = 6             THEN Trim(REPLACE(Upper(subs.cif), 'RO',''))
      WHEN Upper(t.simbauto) = 'RO' THEN Trim(REPLACE(Upper(fisc.codfiscal), 'RO',''))
      ELSE                               p.den_part
    END Part,
    CASE WHEN i.tipdoc &lt;&gt; 2 THEN I.Nrdoc END NrFactura,
    CASE WHEN i.tipdoc = 2  THEN I.Nrdoc END NrAviz,
    I.DataDoc,
    NULL CodTara
  FROM intrari i
    INNER JOIN tmp_rapstocmed_sub sub ON sub.codsubunit = i.subunitatea
    INNER JOIN livr l ON l.codintr = i.codintr AND l.tiplivr = i.tipdoc
    INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
    INNER JOIN nirser nser ON nser.codnirser = l1.codnirser
    INNER JOIN nirstoc ns ON ns.codnirstoc = nser.codnirstoc
    INNER JOIN nir n ON n.codnir = ns.codnir
    INNER JOIN ngest g ON g.codgest = n.gest
    INNER JOIN nserii ser ON ser.codserie = nser.codserie
    LEFT  JOIN tmp_rapstocmed_nao nao ON nao.codobiect = ns.codobiect
    LEFT  JOIN npart p ON p.codpart = i.partener
    LEFT  JOIN nagenda a ON a.codagenda = i.codlocatie
    LEFT  JOIN nlocalit loc ON loc.codlocalit = a.codlocalit
    LEFT  JOIN ntari t ON t.codtara = loc.codtara
    LEFT  JOIN npartcodfisc fisc ON fisc.cod_codfiscal = i.codfiscal
    LEFT  JOIN nsubunit subs ON subs.codsubunit = i.codsubunit
  WHERE i.operat = 1 AND i.anulat = 0 AND i.tipdoc IN (1,2,5,6)
    AND i.datacreare &gt;= vDataRef
    AND l1.cant &lt;&gt; 0
    AND nao.codobiect IS NOT NULL
    AND NOT ns.codioart IN (SELECT DISTINCT codioart FROM ioart1 WHERE mg = 5)
    AND Coalesce(g.tip, 0) &lt;&gt; vTipGestExcl;

  INSERT INTO TMP_RAPSTOCMED(
    codworkplace, cim, numarLot, dataExpirareLot, tip, semn, cant, dataop,
    CodTipPart, CodTipDoc, Part, NrFactura, NrAviz, DataDoc, CodTara )
  SELECT --iesiri din stoc
    sub.CodWorkplace, nao.CIM, Trim(ser.SERIE) numarLot, Coalesce(nser.TG, ns.TG) dataExpirareLot, 2 Tip,
    CASE WHEN i.tipdoc = 15 THEN 1 ELSE -1 END * Sign(l1.cant) Semn,
    Abs(l1.cant)*nao.coefcnas CANT, i.datacreare DataOp,
    CASE
      WHEN i.tipdoc IN (14,15)              AND Coalesce(S.TIPUNITJURIDICA, 0) = 1 THEN 2
      WHEN i.tipdoc IN (14,15)                                                     THEN 6
      WHEN i.tipdoc IN (16)                 AND Coalesce(S.TIPUNITJURIDICA, 0) = 1 THEN 1
      WHEN i.tipdoc IN (16)                                                        THEN 6
      WHEN Coalesce(p.persoanafizica,0) = 1 AND Coalesce(S.TIPUNITJURIDICA, 0) = 1 THEN 1
      WHEN Coalesce(p.persoanafizica,0) = 1                                        THEN 6
      WHEN                                      Coalesce(S.TIPUNITJURIDICA, 0) = 1 THEN 2
      ELSE                                                                              3
    END CodTipPart, --  S.TIPUNITJURIDICA = 1 --  1 persoana fizica / 2 persoana juridica,
                                              -- cumparator de antibiotic 7 - identificata cu CNP / 8 - identificata cu CID / 9 - identificat cu pasaport / 10 - identificat cu Card EU
                                              -- 11 Unitate medicala
                    --  S.TIPUNITJURIDICA = 2 --  3 unitate de distributie angro, importator sau fabricant / 4 farmacie comunitara / 5 farmacie cu circuit inchis  / 6 altele
    CASE
      WHEN i.tipdoc IN (14,15) AND Coalesce(nser.TG, ns.TG) &lt;= i.datacreare THEN 6
      WHEN i.tipdoc IN (14,15)                                              THEN 4
      WHEN l1.cant &lt; 0                                                      THEN 2
      ELSE                                                                       5
    END CodTipDoc,--2 (retur), 3 (retragere), 4 (reglare stoc prin inventar), 5 (vanzare), 6 (expirare)
    CASE
      WHEN i.tipdoc IN (23)         THEN                 Trim(REPLACE(Upper(subd.cif)      , 'RO',''))
      WHEN i.tipdoc IN (16)         THEN Coalesce(NULLIF(Trim(REPLACE(Upper(fisc.codfiscal), 'RO','')),''), p.den_part)
      WHEN i.tipdoc IN (14,15)      THEN Coalesce(NULLIF(Trim(REPLACE(Upper(fisc.codfiscal), 'RO','')),''), sub.cif)
      WHEN Upper(t.simbauto) = 'RO' THEN                 Trim(REPLACE(Upper(fisc.codfiscal), 'RO',''))
      ELSE p.den_part
    END Part,
    CASE
      WHEN i.tipdoc IN (14,15,16) THEN NULL
      WHEN i.tipdoc &lt;&gt; 20         THEN I.Nrdoc
    END NrFactura,
    CASE
      WHEN i.tipdoc IN (14,15,20) THEN I.Nrdoc
    END NrAviz,
    CASE
      WHEN i.tipdoc IN (16) THEN NULL
      ELSE I.DataDoc
    END DataDoc,
    Coalesce(Upper(t.simbauto), 'RO') CodTara
  FROM iesiri i
    INNER JOIN tmp_rapstocmed_sub sub ON sub.codsubunit = i.subunitatea
    INNER JOIN nsubunit s ON s.codsubunit = i.subunitatea
    INNER JOIN livr l ON l.codies = i.codies AND l.tiplivr = i.tipdoc
    INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
    INNER JOIN nirser nser ON nser.codnirser = l1.codnirser
    INNER JOIN nirstoc ns ON ns.codnirstoc = nser.codnirstoc
    INNER JOIN nir n ON n.codnir = ns.codnir
    INNER JOIN ngest g ON g.codgest = n.gest
    INNER JOIN nserii ser ON ser.codserie = nser.codserie
    LEFT  JOIN tmp_rapstocmed_nao nao ON nao.codobiect = ns.codobiect
    LEFT  JOIN npart p ON p.codpart = i.partener
    LEFT  JOIN nagenda a ON a.codagenda = i.codlocatie
    LEFT  JOIN nlocalit loc ON loc.codlocalit = a.codlocalit
    LEFT  JOIN ntari t ON t.codtara = loc.codtara
    LEFT  JOIN npartcodfisc fisc ON fisc.cod_codfiscal = i.codfiscal
    LEFT  JOIN nsubunit subd ON subd.codsubunit = i.codsubunit
  WHERE i.operat = 1 AND i.anulat = 0 AND i.tipdoc IN (14,15,16,19,20,21,22,23)
    AND i.datacreare &gt;= vDataRef
    AND l1.cant &lt;&gt; 0
    AND nao.codobiect IS NOT NULL
    AND NOT ns.codioart IN (SELECT DISTINCT codioart FROM ioart1 WHERE mg = 5)
    AND Coalesce(g.tip, 0) &lt;&gt; vTipGestExcl;

  INSERT INTO TMP_RAPSTOCMED(
    codworkplace, cim, numarLot, dataExpirareLot, tip, semn, cant, dataop,
    CodTipPart, CodTipDoc, Part, NrFactura, NrAviz, DataDoc, CodTara )
  SELECT -- intrari in stoc pe documente de iesire
    sub.CodWorkplace, nao.CIM, Trim(ser.SERIE) numarLot, Coalesce(nser.TG, ns.TG) dataExpirareLot, 2 Tip, 1 Semn, nser.cantnir*nao.coefcnas CANT, DATE_TRUNC('DAY',i.datacreare) DataOp,
    CASE
      WHEN i.tipdoc IN (14,15)              THEN 1
      WHEN i.tipdoc IN (16)                 THEN 1
      WHEN Coalesce(p.persoanafizica,0) = 1 THEN 1
      ELSE                                       2
    END CodTipPart,
    CASE
      WHEN i.tipdoc IN (14,15) AND Coalesce(nser.TG, ns.TG) &lt;= i.datacreare THEN 6
      WHEN i.tipdoc IN (14,15)                                              THEN 4
      WHEN i.tipdoc IN (16,19,20,21,22, 23)                                 THEN 2
    END CodTipDoc,--2 (retur), 3 (retragere), 4 (reglare stoc prin inventar), 5 (vanzare), 6 (expirare)
    CASE
      WHEN i.tipdoc IN (23)         THEN                 Trim(REPLACE(Upper(subd.cif)      , 'RO',''))
      WHEN i.tipdoc IN (16)         THEN Coalesce(NULLIF(Trim(REPLACE(Upper(fisc.codfiscal), 'RO','')),''), p.den_part)
      WHEN i.tipdoc IN (14,15)      THEN Coalesce(NULLIF(Trim(REPLACE(Upper(fisc.codfiscal), 'RO','')),''), sub.cif)
      WHEN Upper(t.simbauto) = 'RO' THEN                 Trim(REPLACE(Upper(fisc.codfiscal), 'RO',''))
      ELSE p.den_part
    END Part,
    CASE
      WHEN i.tipdoc IN (14,15,16) THEN NULL
      WHEN i.tipdoc &lt;&gt; 20         THEN I.Nrdoc
    END NrFactura,
    CASE
      WHEN i.tipdoc IN (14,15,20) THEN I.Nrdoc
    END NrAviz,
    CASE
      WHEN i.tipdoc IN (16) THEN NULL
      ELSE I.DataDoc
    END DataDoc,
    Coalesce(Upper(t.simbauto), 'RO') CodTara
  FROM iesiri i
    INNER JOIN tmp_rapstocmed_sub sub ON sub.codsubunit = i.subunitatea
    INNER JOIN nir n ON n.codies = i.codies AND n.tipnir = i.tipdoc
    INNER JOIN nirstoc ns ON ns.codnir = n.codnir
    INNER JOIN ngest g ON g.codgest = n.gest
    INNER JOIN nirser nser ON nser.codnirstoc = ns.codnirstoc
    INNER JOIN nserii ser ON ser.codserie = nser.codserie
    LEFT  JOIN tmp_rapstocmed_nao nao ON nao.codobiect = ns.codobiect
    LEFT  JOIN npart p ON p.codpart = i.partener
    LEFT  JOIN nagenda a ON a.codagenda = i.codlocatie
    LEFT  JOIN nlocalit loc ON loc.codlocalit = a.codlocalit
    LEFT  JOIN ntari t ON t.codtara = loc.codtara
    LEFT  JOIN npartcodfisc fisc ON fisc.cod_codfiscal = i.codfiscal
    LEFT  JOIN nsubunit subd ON subd.codsubunit = i.codsubunit
  WHERE i.operat = 1 AND i.anulat = 0 AND i.tipdoc IN (14,15,16,19,20,21,22,23)
    AND n.operat = 1
    AND Coalesce(n.datacreare, i.datacreare) &gt;= vDataRef
    AND i.datacreare &gt;= vDataRef
    AND ns.cantnir &lt;&gt; 0
    AND nao.codobiect IS NOT NULL
    AND NOT ns.codioart IN (SELECT DISTINCT codioart FROM ioart1 WHERE mg = 5)
    AND Coalesce(g.tip, 0) &lt;&gt; vTipGestExcl;

  IF cEGN = '2' THEN
    INSERT INTO TMP_RAPSTOCMED(
      codworkplace, cim, numarLot, dataExpirareLot, tip, semn, cant, dataop,
      CodTipPart, CodTipDoc, Part, NrFactura, NrAviz, DataDoc, CodTara )
    SELECT -- intrari in stoc pe documente de transfer din gestiuni Neconforme Excluse
      sub.CodWorkplace, nao.CIM, Trim(ser.SERIE) numarLot, Coalesce(nser.TG, ns_s.TG) dataExpirareLot,
      CASE WHEN Coalesce(g_s.tip, 0) = vTipGestExcl THEN 1 ELSE  2 END Tip,
      CASE WHEN Coalesce(g_s.tip, 0) = vTipGestExcl THEN 1 ELSE -1 END Semn,
      /*nser.cantnir*/l1.cant*nao.coefcnas CANT, DATE_TRUNC('DAY',t.datacreare) DataOp,
      CASE
        WHEN Coalesce(g_s.tip, 0) = vTipGestExcl THEN 1 -- intrare                      --&gt; 1 intern
        WHEN Coalesce(S.TIPUNITJURIDICA, 0) = 1  THEN 2 -- iesire S.TIPUNITJURIDICA = 1 --&gt; 2 extern
        WHEN Coalesce(S.TIPUNITJURIDICA, 0) = 2  THEN 3 -- iesire S.TIPUNITJURIDICA = 2 --&gt; 3 Unitate de distributie angro/importator/fabricant autorizat
                                                 ELSE 6                                 --&gt; 6 altele
      END CodTipPart,
      CASE WHEN Coalesce(g_s.tip, 0) = 4 THEN vTipGestExcl ELSE 3 END Tip, --1 (achizitie), 2 (retur), 3 (retragere), 4 (reglare stoc prin inventar).
      Trim(REPLACE(Upper(sub.cif), 'RO','')) Part,
      NULL NrFactura,
      CASE WHEN Coalesce(g_s.tip, 0) = vTipGestExcl THEN n_d.NrNir ELSE L.NRLivr END NrAviz,
      T.DataDoc,
      CASE WHEN Coalesce(g_s.tip, 0) = vTipGestExcl THEN NULL      ELSE 'RO' END CodTara
    FROM transf t
      INNER JOIN tmp_rapstocmed_sub sub  ON sub.codsubunit  = t.subunitatea
      INNER JOIN nsubunit           s    ON s.codsubunit    = t.subunitatea
      INNER JOIN transf1            t1   ON t1.codtransf    = t.codtransf
      INNER JOIN tmp_rapstocmed_nao nao  ON nao.codobiect   = t1.codobiect
      INNER JOIN livr               l    ON l.codtransf     = t.codtransf
      INNER JOIN livr1              l1   ON l1.codlivr      = l.codlivr AND l1.codies1 = t1.codtransf1
      INNER JOIN nirser             nser ON nser.codnirser  = l1.codnirser
      INNER JOIN nserii             ser  ON ser.codserie    = nser.codserie
      INNER JOIN nirstoc            ns_d ON ns_d.codlivr1   = l1.codlivr1
      INNER JOIN nir                n_d  ON n_d.codnir      = ns_d.codnir
      LEFT  JOIN ngest              g_d  ON g_d.codgest     = n_d.gest
      INNER JOIN nirstoc            ns_s ON ns_s.codnirstoc = l1.codnirstoc
      INNER JOIN nir                n_s  ON n_s.codnir      = ns_s.codnir
      LEFT  JOIN ngest              g_s  ON g_s.codgest     = n_s.gest
    WHERE t.operat = 1 AND t.anulat = 0 AND t.tipdoc IN (12)
      AND n_d.operat = 1
      AND Coalesce(n_d.datacreare, t.datacreare) &gt;= vDataRef
      AND l1.cant &lt;&gt; 0
      AND NOT ns_s.codioart IN (SELECT DISTINCT codioart FROM ioart1 WHERE mg = 5)
      AND ( (Coalesce(g_d.tip, 0) &lt;&gt; vTipGestExcl AND Coalesce(g_s.tip, 0) =  vTipGestExcl) OR
            (Coalesce(g_d.tip, 0) =  vTipGestExcl AND Coalesce(g_s.tip, 0) &lt;&gt; vTipGestExcl) );
  END IF;

  INSERT INTO TMP_RAPSTOCMED0 (codworkplace)
  SELECT DISTINCT CodWorkplace
  FROM TMP_RAPSTOCMED_SUB;

  INSERT INTO TMP_RAPSTOCMED1 (
    CodWorkplace, CIM, numarLot, dataExpirareLot,
    stoc,
    stocant,
    aretranz )
  SELECT
    CodWorkplace, CIM, numarLot, dataExpirareLot,
    Round(Sum(CASE WHEN Tip = 0 THEN Cant WHEN DataOp &gt; vNewData THEN - Semn * Cant ELSE 0 END)) stoc,
    Round(Sum(CASE WHEN Tip = 0 THEN Cant ELSE - Semn * Cant END)) stocant,
    Max (CASE WHEN Tip = 0 OR DataOp &gt; vNewData THEN 0 ELSE 1 END) aretranz
  FROM TMP_RAPSTOCMED
  GROUP BY CodWorkplace, CIM, numarLot, dataExpirareLot;

  DELETE FROM TMP_RAPSTOCMED1 WHERE stoc = 0 AND aretranz = 0;
  DELETE FROM TMP_RAPSTOCMED  WHERE Tip = 0;
  DELETE FROM TMP_RAPSTOCMED  WHERE DataOp &gt; vNewData;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reclamatii_sp_lockrecord</obj_name>
  <obj_hashval>a004ad805661e0e0e2193d212490c4d8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reclamatii_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CodRECLAMATIE INTO Tmp FROM RECLAMATII WHERE CodRECLAMATIE = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_getinclusiv_cecuri</obj_name>
  <obj_hashval>1fa9da6bc668375a16b3d317daef4880</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_getinclusiv_cecuri(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REGPART.INCLUSIV_CECURI')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpers_getcurs_in</obj_name>
  <obj_hashval>aefe70217e1fa042faf5436aec15582e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpers_getcurs_in(INOUT wme_result double precision, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REGPERS.CURS_IN', true)),'99999999999.9999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_make_stoc_la_data</obj_name>
  <obj_hashval>3a19c18f4582168c7e94987bce8220df</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_make_stoc_la_data(agest numeric, adata character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  L_rec RECORD;
BEGIN
  --Florin 28.11.2023 - sinc. Oracle
  --Florin 17.05.2022 - sinc. Oracle
  DELETE FROM TMP_NIR_LA_DATA;
  INSERT INTO TMP_NIR_LA_DATA(CODOBIECT, CANTNIR)
  SELECT CODOBIECT, SUM( CANTNIR) AS CANTNIR
  FROM (SELECT NS.CODOBIECT, CANTNIR, N.DATANIR AS DATACREARE
        FROM NIRSTOC NS, NIR N, NARTOBJ O, NART A, IOART1 IO1
        WHERE NS.CODNIR = N.CODNIR AND  N.GEST = aGEST AND  O.CODOBIECT = NS.CODOBIECT AND  A.CODARTICOL = O.CODARTICOL AND  COALESCE( A.CASADEMARCAT, 0) = 1
         AND NS.CODIOART = IO1.CODIOART AND IO1.MG &lt;&gt; 5
         AND EXTRACT(YEAR FROM N.DATANIR) * 12 + EXTRACT(MONTH FROM N.DATANIR) BETWEEN IO1.ALSTART AND IO1.ALSTOP
         AND EXTRACT(YEAR FROM N.DATANIR) * 12 + EXTRACT(MONTH FROM N.DATANIR) &gt;= (select aninitial * 12 + lunainitiala from firmaluni)
  UNION ALL
   SELECT
    NS.CODOBIECT,
    CANTNIR,
    N.DATANIR AS DATACREARE
   FROM
     NIRSTOC NS,
     NIR N,
     NARTOBJ O,
     NART A
   WHERE
     NS.CODNIR = N.CODNIR
     AND N.GEST = aGEST
     AND O.CODOBIECT = NS.CODOBIECT
     AND A.CODARTICOL = O.CODARTICOL
     AND coalesce(A.CASADEMARCAT, 0) = 1
     AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) &lt; (select aninitial*12+lunainitiala from firmaluni)
   ) a_pg
   WHERE
     COALESCE(DATACREARE, to_timestamp('01.01.2000', 'DD.MM.YYYY')) &lt; to_timestamp(aDATA, 'DD.MM.YYYY hh24:mi')
  GROUP BY CODOBIECT;

  DELETE FROM TMP_LIVR_LA_DATA;
  INSERT INTO TMP_LIVR_LA_DATA(CODOBIECT, CANTNIR)
  SELECT CODOBIECT, SUM( CANT) AS CANT
  FROM (SELECT NS.CODOBIECT, CASE WHEN  L.TIPLIVR = 15 THEN -L1.CANT ELSE L1.CANT END  CANT, L.DATALIVR AS DATACREARE
        FROM LIVR1 L1, LIVR L, NIRSTOC NS, NIR N, NARTOBJ O, NART A
        WHERE L1.CODNIRSTOC = NS.CODNIRSTOC AND  L1.CODLIVR = L.CODLIVR AND  NS.CODNIR = N.CODNIR AND  N.GEST = aGEST AND
              O.CODOBIECT = NS.CODOBIECT AND  A.CODARTICOL = O.CODARTICOL AND  COALESCE( A.CASADEMARCAT, 0) = 1
       ) B_PG
  WHERE COALESCE( DATACREARE, to_timestamp( '01.01.2000', 'DD.MM.YYYY')) &lt; to_timestamp( aData, 'DD.MM.YYYY hh24:mi')
  GROUP BY CODOBIECT;

  FOR L_rec IN ( SELECT * FROM TMP_LIVR_LA_DATA L) LOOP
    UPDATE TMP_NIR_LA_DATA N SET CANTNIR = N.CANTNIR - L_rec.CANTNIR WHERE N.CODOBIECT = L_rec.CODOBIECT;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restobiecte_sp_deleterecord</obj_name>
  <obj_hashval>6ce73a8f9533819c2b2e9d9a9426c60d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restobiecte_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_RESTOBIECTE_SP_LOCKRECORD( RecId);
  DELETE FROM RESTOBIECT WHERE COD = RecId;
  PERFORM NotifyModif( 2, RecId, 'RESTOBIECT');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restobiecte_sp_lockrecord</obj_name>
  <obj_hashval>100599c82e9a87fff2520246745c019f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restobiecte_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT COD INTO Tmp FROM RESTOBIECT WHERE COD = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rezervari_dorezervare</obj_name>
  <obj_hashval>61209e64e248650282ed8047f91bb52f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rezervari_dorezervare(acodcomanda1 numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_COM        RECORD;
  V_NOD        RECORD;
  V_STOC       RECORD;
  V_NODXXX     RECORD;
  REZ_Rezervat numeric;
  REZ_TOTAL    numeric;
  CATE_VREAU   numeric;
  ZEC          numeric;
  aParitate    numeric;
  NOD_Rezervat numeric;
  NOD_Rezolvat numeric;
  NOD_Necesar  numeric;
  NOD_RezFurn  numeric;
  aCantIni     numeric;
  aRest        numeric;
  STOC_Rest    numeric;
  REZ_CodGest  numeric;
  REZ_CodIOArt numeric;
  REZ_UMSec    numeric;
  DenObiect    varchar;
begin
  --Florin 15.12.2021 - fixat 52301
  --Laura 24.11.2021 - sinc Oracle (24.11.2021)
  --Adina 01.07.2021 - sinc.Oracle din 30.06.2021
  --Adina 29.06.2021 - sinc.Oracle din 28.06.2021
  --Florin 30.12.2020
  --Florin 09.02.2021 - prefix pentru bagarezervare
  PERFORM PKG_REZERVARI_GET_TMP_REZ_STOC(aCodComanda1);

  UPDATE TMP_REZ_REZ SET Rez = 0 WHERE aCodComanda1 = 0 or  Codcomanda1 = aCodcomanda1;

  FOR v_COM IN (SELECT CodComanda1, TipComanda FROM TMP_REZ_CCOM1 WHERE aCodcomanda1 = 0 or  CodComanda1 = aCodComanda1) LOOP
    FOR v_NOD IN (SELECT * FROM TMP_REZ_ProiectNod
                  WHERE CodComanda1 = v_COM.Codcomanda1 and (NodOriginal &gt; 0 or  v_COM.TipComanda &lt;&gt; 2) and
                  (
                  (codreteta = 0 and COALESCE(fnc_GetValConstanta('CmdRezProd', getanlucru(), getlunalucru()),'2') &lt;&gt; '1')
                  or COALESCE(fnc_GetValConstanta('CmdRezProd' ,getanlucru(), getlunalucru()),'2') = '1'
                  )
                  ORDER BY CodComanda1, Nivel, Pozitie
                 )
    LOOP
      SELECT Denumire INTO DenObiect FROM TMP_REZ_REZ WHERE CodComanda1 = v_COM.CodComanda1 and  CodObiect = v_NOD.CodObiect;

      SELECT Rezervat, RezFurn, Necesar, Rezolvat
      INTO NOD_Rezervat, NOD_RezFurn, NOD_Necesar, NOD_Rezolvat
      FROM TMP_REZ_ProiectNod
      WHERE CodComanda1 = v_COM.CodComanda1 and  CodProiectNod = v_NOD.CodProiectNod;

      REZ_Rezervat := 0;
      CATE_VREAU := NOD_Necesar - NOD_Rezolvat - NOD_Rezervat - NOD_RezFurn;
      IF  CATE_VREAU &gt; 0 THEN
        SELECT CodGest, CodIOArt, UMSec
        INTO REZ_CodGest, REZ_CodIOArt, REZ_UMSec
        FROM TMP_REZ_REZ
        WHERE CodComanda1 = v_COM.CodComanda1 and  CodObiect = v_NOD.CodObiect;

        aRest := CATE_VREAU;
        FOR v_STOC IN (SELECT * FROM TMP_REZ_STOC WHERE Rest &gt; 0 and  CodObiect = v_NOD.CodObiect and  CodGest = REZ_CodGest and  CodIoart = REZ_CodIOArt) LOOP
          IF  aRest &gt; 0 THEN
            SELECT Rest INTO STOC_Rest FROM TMP_REZ_STOC WHERE CodNIRStoc = v_STOC.CodNIRSTOC and  COALESCE(CodNIRSer, 0) = COALESCE(v_STOC.CodNIRSer, 0);
            IF  STOC_Rest &gt; aRest THEN
              UPDATE TMP_REZ_STOC SET Rest = Rest - aRest WHERE CodNIRStoc = v_Stoc.CodNIRSTOC and  COALESCE(CodNIRSer, 0) = COALESCE(v_STOC.CodNIRSer, 0);
              PERFORM PKG_REZERVARI_BAGAREZERVARE(v_COM.CodComanda1, 0, v_STOC.CodNirStoc, COALESCE(v_STOC.CodNirSer, 0), aRest, REZ_UMSec, v_NOD.CodObiect, 0);
              aRest := 0;
            ELSE
              aRest := aRest - STOC_Rest;
              UPDATE TMP_REZ_STOC SET Rest = 0 WHERE CodNIRStoc = v_Stoc.CodNIRSTOC and  COALESCE(CodNIRSer, 0) = COALESCE(v_STOC.CodNIRSer, 0);
              PERFORM PKG_REZERVARI_BAGAREZERVARE(v_COM.CodComanda1, 0, v_STOC.CodNirStoc, COALESCE(v_STOC.CodNirSer, 0), STOC_Rest, REZ_UMSec, v_NOD.CodObiect, 0);
            END IF;
          END IF;
        END LOOP;

        REZ_Rezervat := CATE_VREAU - aRest;
      END IF;

      IF  REZ_Rezervat &lt;&gt; 0.0 THEN
        UPDATE TMP_REZ_REZ SET RezIni = RezIni + REZ_Rezervat WHERE CodComanda1 = v_NOD.CodComanda1 and  CodObiect = v_NOD.CodObiect;
        UPDATE TMP_REZ_ProiectNod SET Rezervat = Rezervat + REZ_Rezervat WHERE CodComanda1 = v_COM.CodComanda1 and  CodProiectNod = v_NOD.CodProiectNod;

        REZ_TOTAL := REZ_Rezervat;
        IF  REZ_TOTAL &lt;&gt; 0 THEN
          aParitate := REZ_TOTAL / v_NOD.Necesar;

          FOR v_NODXXX IN
                          (
                              WITH RECURSIVE a (rootNODORIGINAL,NODORIGINAL,CODPROIECTNOD,CODOBIECT,Necesar) AS
                                   (
                                    SELECT NODORIGINAL AS rootNODORIGINAL,NODORIGINAL, CODPROIECTNOD,CODOBIECT,Necesar
                                    FROM TMP_REZ_ProiectNod
                                    where CODPROIECTNOD = v_NOD.CodProiectNod
                                    UNION ALL
                                    SELECT A.rootNODORIGINAL, a.CODPROIECTNOD NODORIGINAL, o.CODPROIECTNOD, o.CODOBIECT, O.Necesar
                                    FROM TMP_REZ_ProiectNod O  inner join A ON o.NODORIGINAL = a.CODPROIECTNOD
                                    )
                          SELECT CODPROIECTNOD,CODOBIECT,Necesar FROM A
                          WHERE CODPROIECTNOD &lt;&gt; v_NOD.CodProiectNod
                          )
          loop
            SELECT COALESCE(u.Zecimale, 0) INTO ZEC  FROM NUM u, NART a, NARTOBJ o
            WHERE o.CodObiect = v_NOD.CodObiect and  a.CodArticol = o.CodArticol and  u.CODUM = a.UM;
            UPDATE TMP_REZ_REZ
            SET Rezolvat = Round((Rezolvat + v_NodXXX.Necesar * aParitate)::numeric, (ZEC)::int)
            WHERE CodObiect = v_NodXXX.codObiect and  CodComanda1 = v_COM.CodComanda1;

            UPDATE TMP_REZ_ProiectNod
            SET Rezolvat = Round((Rezolvat + v_NodXXX.Necesar * aParitate)::numeric, (ZEC)::int)
            WHERE CodComanda1 = v_COM.CodComanda1 and  CodProiectNod = v_NODXXX.CodProiectNod;
          END LOOP;
        END IF;
      END IF;
    END LOOP;
  END LOOP;

  UPDATE TMP_REZ_REZ
  SET
  RestCom = Round((NecesarIni - Rezolvat - RezIni - RezCmdFurn - RezFurnIni)::numeric, 7)
  WHERE (aCodComanda1 = 0 or  Codcomanda1 = aCodcomanda1);
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_curata_intrari</obj_name>
  <obj_hashval>4bc5e9f683f39920100db02c0a6fb9c5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_curata_intrari()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  FOR V_REC IN
  (
  SELECT I.CODINTR
  FROM INTRARI I
      LEFT JOIN INTRARI1 I1 ON  I1.CODINTR = I.CODINTR
      LEFT JOIN NIR      N  ON  N.CODINTR  = I.CODINTR
      LEFT JOIN GENERAL  G  ON  G.TIPDOC   = I.TIPDOC AND  G.CODDOC = I.CODINTR
  WHERE I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
    AND I1.CODINTR1 IS NULL  AND G.CODGENERAL IS NULL  AND N.CODNIR IS NULL
  )
  LOOP
    DELETE FROM INTRARI WHERE CODINTR = V_REC.CODINTR;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_setluna_initializari</obj_name>
  <obj_hashval>e68165e7370e204868afb54d0f3c9796</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_setluna_initializari(aluna_initializari numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI',to_char(aLUNA_INITIALIZARI,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_put_info</obj_name>
  <obj_hashval>52f9fbd4efd447439556b5067258fa9b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_put_info(pinfoline character varying, pdetalii text)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 05.10.2022
  NULL;
  IF current_setting('PKG_SAFT.pSaftDebug', true)::boolean THEN
    INSERT INTO SAFT_INFO VALUES (current_timestamp, pINFOLINE, pDETALII);
  END IF;
  --Pentru debug timpi generare se decomenteaza liniile urmatoare
  --INSERT INTO SAFT_INFO VALUES (CURRENT_TIMESTAMP, pINFOLINE, pDETALII);
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t04</obj_name>
  <obj_hashval>8de5c8b7f902f74a0b3607b542dfd584</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t04()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef   22.10.2025 - 67039
  --Florin 17.10.2025 - fixat 66994
  --Florin 13.10.2025 - sinc. Oracle
  --Florin  21.11.2023 - fixat 60132
  perform pkg_saft_PUT_INFO('04.A','UMPLE_T04--SAF_CUSTOMER');
  INSERT INTO TMP_SAFT04
  SELECT
    NEXTVAL('SEQ_SAFT')                          COL01,--CODSAF_CUSTOMER         NUMERIC(20,0)
    C06.CODSAF                                   COL02,--CODSAF_COMPANYSTRUCTURE NUMERIC(20,0)
    PD.PartID                                    COL03,--CUSTOMERID              STRING(35,0)
    NULL                                         COL04,--SELFBILLINGINDICATOR    STRING(9,0)
    P.CODSAFT                                    COL05,--ACCOUNTID               STRING(70,0)
    CASE
      WHEN P.TIPCONT = 1                                 THEN NULL
      WHEN P.TIPCONT = 2 AND P.SOLDI &lt; 0                 THEN NULL
      WHEN P.TIPCONT = 2 AND P.SOLDI = 0 AND P.SOLDF &lt; 0 THEN NULL
                                                         ELSE P.SOLDI
    END                                          COL06,--OPENINGDEBITBALANCE     NUMERIC(18,2)
    CASE
      WHEN P.TIPCONT = 1                                 THEN -P.SOLDI
      WHEN P.TIPCONT = 2 AND P.SOLDI &lt; 0                 THEN -P.SOLDI
      WHEN P.TIPCONT = 2 AND P.SOLDI = 0 AND P.SOLDF &lt; 0 THEN -P.SOLDI
                                                         ELSE NULL
    END                                          COL07,--OPENINGCREDITBALANCE    NUMERIC(18,2)
    CASE
      WHEN P.TIPCONT = 1                                 THEN NULL
      WHEN P.TIPCONT = 2 AND P.SOLDI &lt; 0                 THEN NULL
      WHEN P.TIPCONT = 2 AND P.SOLDI = 0 AND P.SOLDF &lt; 0 THEN NULL
                                                         ELSE P.SOLDF

    END                                          COL08,--CLOSINGDEBITBALANCE     NUMERIC(18,2)
    CASE
      WHEN P.TIPCONT = 1                                 THEN -P.SOLDF
      WHEN P.TIPCONT = 2 AND P.SOLDI &lt; 0                 THEN -P.SOLDF
      WHEN P.TIPCONT = 2 AND P.SOLDI = 0 AND P.SOLDF &lt; 0 THEN -P.SOLDF
                                                         ELSE NULL
    END                                          COL09 --CLOSINGCREDITBALANCE    NUMERIC(18,2)
  FROM (
    SELECT F.CODPARTFUZ AS CODPART, C.CODSAFT, C.TIPCONT, Sum(TP.SOLDI) SOLDI, Sum(TP.SOLDF) SOLDF
    FROM TMP_SAFT_NPART TP
      INNER JOIN TMP_SAFT_NCONT    C ON C.CODCONT = TP.CODCONT AND C.NO_SOLDPART = 0
      INNER JOIN TMP_SAFT_NPARTFUZ F ON F.CODPART = TP.CODPART
    WHERE TP.CLIENT = 1
    GROUP BY F.CODPARTFUZ, C.CODSAFT, C.TIPCONT
  ) P
    INNER JOIN TMP_SAFT_NPARTDET PD  ON PD.CODPART   = P.CODPART
    LEFT  JOIN TMP_SAFT_CODSAF   C06 ON C06.CODSURSA = P.CODPART AND C06.CodSAFTTab = 06;
  perform pkg_saft_PUT_INFO('04.Z','UMPLE_T04--SAF_CUSTOMER');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t23</obj_name>
  <obj_hashval>1dd886f8e0a4459cade2f50c8896a48b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t23()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 30.10.2025 - sinc. Oracle
  --Stef  25.05.2023
  INSERT INTO TMP_SAFT23
  SELECT
    C23.CODSAF                  COL01,--CODSAF_ASSETSUPPLIER        NUMBER(20)
    SubStr(P.Den_Part, 1, 70)   COL02,--SUPPLIERNAME                NVARCHAR2(70)
    PD.PartID                   COL03,--SUPPLIERID                  NVARCHAR2(35)
    C07.CODSAF                  COL04 --CODPOSTALADDRESSSAF_ADDRESS NUMBER(20)
  FROM TMP_SAFT_CODSAF C23
    LEFT JOIN TMP_SAFT_NPARTDET PD  ON PD.CODPART   = C23.CODSURSA
    LEFT JOIN NPART             P   ON P.CODPART    = C23.CODSURSA
    LEFT JOIN NAGENDA           A   ON A.CODPART    = C23.CODSURSA     AND A.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(A.INACTIV, 0) = 0
    LEFT JOIN TMP_SAFT_CODSAF   C07 ON C07.CODSURSA = A.CODAGENDA      AND C07.CodSAFTTab = 07
  WHERE C23.CodSAFTTab = 23;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t28</obj_name>
  <obj_hashval>8902ef8b40e1485194e12355784a6505</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t28()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  dDataTip32 date;
  sFirmaID   VARCHAR(35);
  vSubunit   NUMERIC(20);
BEGIN
  --Florin 16.12.2025 - sinc. Oracle
  --Florin 10/12.12.2025 - sinc. Oracle
  --Stef 28.04.2025 - sinc. Oracle
  PERFORM pkg_saft_PUT_INFO('28.A','UMPLE_T28--SAF_TRANSACTION');

  SELECT Last_Day( To_Date( To_Char(ANFIN,'fm0000')||To_Char(LUNAFIN,'fm00'), 'yyyymm')), CODSUBUNIT INTO dDataTip32, vSubunit
  FROM TMP_SAFT_PARAMS;

  IF vSubunit = 1 THEN
    SELECT '00'||REGEXP_REPLACE(F.CODFISCAL,'\D+','') INTO sFirmaID
    FROM TMP_SAFT_PARAMS SP INNER JOIN WINMADMIN.FIRMA F ON F.CODFIRMA = SP.CODFIRMA;
  ELSE
    SELECT '00'||REGEXP_REPLACE(S.CIF,'\D+','') INTO sFirmaID
    FROM TMP_SAFT_PARAMS SP INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = SP.CODSUBUNIT;
  END IF;

  INSERT INTO TMP_SAFT28
  WITH TMP_SAFT_PARTCONT (CODPART, CODCONT, CLIENT, FURNIZOR) AS (
    SELECT DISTINCT CODPART, CODCONT, CLIENT, FURNIZOR
    FROM TMP_SAFT_NPART
  )
  SELECT
    C28.CODSAF                                              COL01,--CODSAF_TRANSACTION     NUMBER(20)
    C27.CODSAF                                              COL02,--CODSAF_MASTER          NUMBER(20)
    To_Char(J.TipDoc)||'_'||
    To_Char(J.CodDoc)                                       COL03,--TRANSACTIONID          NVARCHAR2(70)
    J.LUNA                                                  COL04,--PERIOD                 NUMBER(20)
    J.AN                                                    COL05,--PERIODYEAR             NUMBER(20)
    JD.DATADOC                                              COL06,--TRANSACTIONDATE        DATE
    CASE
      WHEN J.TIPDOC IN (29, 30, 31, 35, 46, 81)
      THEN To_Char(J.IndexLocal)
    END                                                     COL07,--SOURCEID               NVARCHAR2(35)
    To_Char(J.TipDoc)                                       COL08,--TRANSACTIONTYPE        NVARCHAR2(18)
    J.DESCRIPTION                                           COL09,--DESCRIPTION            NVARCHAR2(256)
    NULL                                                    COL10,--BATCHID                NVARCHAR2(35)
    CASE
      WHEN J.TIPDOC IN (25,32,36,45,46,47,52,58,71,81,106,108) THEN dDataTip32
      ELSE JD.DATACREARE
    END                                                     COL11,--SYSTEMENTRYDATE        DATE
    CASE
      WHEN J.TIPDOC IN (25,32,36,45,46,47,52,58,71,81,106,108) THEN dDataTip32
      ELSE JD.DATACREARE
    END                                                     COL12,--GLPOSTINGDATE          DATE
    CASE
      WHEN J.TIPDOC IN (28, 35)          AND PD1.CODPART &lt;&gt; 0      AND P1C.CODCONT IS NOT NULL AND P1C.CLIENT   = 1 THEN PD1.PartID
      WHEN J.TIPDOC IN (28, 35)          AND PD2.CODPART &lt;&gt; 0      AND P2D.CODCONT IS NOT NULL AND P2D.CLIENT   = 1 THEN PD2.PartID
      WHEN J.TIPDOC IN (28, 35)          AND PD1.CODPART &lt;&gt; 0      AND P1D.CODCONT IS NOT NULL AND P1D.FURNIZOR = 1 THEN '0'
      WHEN J.TIPDOC IN (28, 35)          AND PD2.CODPART &lt;&gt; 0      AND P2C.CODCONT IS NOT NULL AND P2C.FURNIZOR = 1 THEN sFirmaID
      WHEN J.TIPDOC IN (28, 35)                                                       THEN '0' --sFirmaID
      WHEN J.TIPDOC IN (46, 59) AND PD1.CODPART &lt;&gt; 0      AND P1D.CODCONT IS NOT NULL THEN PD1.PartID
      WHEN J.TIPDOC IN (46, 59) AND PD1.CODPART &lt;&gt; 0      AND P1C.CODCONT IS NOT NULL THEN '0' --sFirmaID
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 0    AND P1D.CODCONT IS NOT NULL AND P1D.CLIENT   = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 0    AND P1C.CODCONT IS NOT NULL AND P1C.CLIENT   = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 0                                                     THEN '0'
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 1    AND P1D.CODCONT IS NOT NULL AND P1D.CLIENT   = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 1    AND P1C.CODCONT IS NOT NULL AND P1C.CLIENT   = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 1                                                     THEN '0'
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 0    AND P1D.CODCONT IS NOT NULL AND P1D.CLIENT   = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 0    AND P1C.CODCONT IS NOT NULL AND P1C.CLIENT   = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 0    AND P1D.CODCONT IS NOT NULL                      THEN '0'
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 0    AND P1C.CODCONT IS NOT NULL                      THEN '0'
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 0                                                     THEN sFirmaID
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 1    AND P1D.CODCONT IS NOT NULL AND P1D.CLIENT   = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 1    AND P1C.CODCONT IS NOT NULL AND P1C.CLIENT   = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 1    AND P1D.CODCONT IS NOT NULL                      THEN '0'
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 1    AND P1C.CODCONT IS NOT NULL                      THEN '0'
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 1                                THEN sFirmaID
      WHEN IES_J.CODIES IS NULL          AND INT_J.CODINTR IS NULL                             THEN sFirmaID
      WHEN IES_J.CODIES IS NULL                                                       THEN '0'
      WHEN IES_J.TIPDOC = 14                                                          THEN sFirmaID
      WHEN IES_J.TIPDOC = 15                                                          THEN sFirmaID
      WHEN IES_J.TIPDOC = 16                                                          THEN '080000000000000'
      WHEN IES_J.TIPDOC = 23                                                          THEN sFirmaID
      WHEN IES_J.TIPDOC = 24                                                          THEN sFirmaID
      WHEN                                                    P1D.CODCONT IS NOT NULL THEN PD1.PartID
      WHEN                                                    P1C.CODCONT IS NOT NULL THEN PD1.PartID
                                                                                      ELSE sFirmaID -- PD1.PartID
    END                                                     COL13,--CUSTOMERID             NVARCHAR2(35)
    CASE
      WHEN J.TIPDOC IN (28, 35)          AND PD2.CODPART &lt;&gt; 0      AND P2D.CODCONT IS NOT NULL AND P2D.FURNIZOR = 1 THEN PD2.PartID
      WHEN J.TIPDOC IN (28, 35)          AND PD1.CODPART &lt;&gt; 0      AND P1C.CODCONT IS NOT NULL AND P1C.FURNIZOR = 1 THEN PD1.PartID
      WHEN J.TIPDOC IN (28, 35)          AND PD2.CODPART &lt;&gt; 0      AND P2C.CODCONT IS NOT NULL AND P2C.CLIENT   = 1 THEN '0'
      WHEN J.TIPDOC IN (28, 35)          AND PD1.CODPART &lt;&gt; 0      AND P1D.CODCONT IS NOT NULL AND P1D.CLIENT   = 1 THEN sFirmaID
      WHEN J.TIPDOC IN (28, 35)                                                       THEN '0' --sFirmaID
      WHEN J.TIPDOC IN (46, 59) AND PD1.CODPART &lt;&gt; 0      AND P1C.CODCONT IS NOT NULL THEN PD1.PartID
      WHEN J.TIPDOC IN (46, 59) AND PD1.CODPART &lt;&gt; 0      AND P1D.CODCONT IS NOT NULL THEN '0' --sFirmaID
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 0    AND P1D.CODCONT IS NOT NULL AND P1D.FURNIZOR = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 0    AND P1C.CODCONT IS NOT NULL AND P1C.FURNIZOR = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 0                                                     THEN '0'
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 1    AND P1D.CODCONT IS NOT NULL AND P1D.FURNIZOR = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 1    AND P1C.CODCONT IS NOT NULL AND P1C.FURNIZOR = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 1                                                     THEN '0'
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 0    AND P1D.CODCONT IS NOT NULL AND P1D.FURNIZOR = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 0    AND P1C.CODCONT IS NOT NULL AND P1C.FURNIZOR = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 0    AND P1D.CODCONT IS NOT NULL                      THEN '0'
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 0    AND P1C.CODCONT IS NOT NULL                      THEN '0'
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 0                                                     THEN sFirmaID
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 1    AND P1D.CODCONT IS NOT NULL AND P1D.FURNIZOR = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 1    AND P1C.CODCONT IS NOT NULL AND P1C.FURNIZOR = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 1    AND P1D.CODCONT IS NOT NULL                      THEN '0'
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 1    AND P1C.CODCONT IS NOT NULL                      THEN '0'
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 1                                                     THEN sFirmaID
      WHEN IES_J.CODIES   IS NULL AND INT_J.CODINTR IS NULL                           THEN sFirmaID
      WHEN INT_J.CODINTR IS NULL                                                      THEN '0'
      WHEN INT_J.TIPDOC =  6                                                          THEN sFirmaID
      WHEN INT_J.TIPDOC =  7                                                          THEN sFirmaID
      WHEN                                                    P1D.CODCONT IS NOT NULL THEN PD1.PartID
      WHEN                                                    P1C.CODCONT IS NOT NULL THEN PD1.PartID
      WHEN Coalesce(INT_J.TIPTVA, 0) = 2 AND CD.CodSAFT = '4426'   AND CC.CodSAFT = '4427'     THEN PD1.PartID
                                                                                      ELSE sFirmaID -- PD1.PartID
    END                                                     COL14,--SUPPLIERID             NVARCHAR2(35)
    To_Char(Coalesce(INT_S.TipDoc, IES_S.TipDoc, J.CodDoc)) COL15,--SYSTEMID               NVARCHAR2(18)
    2                                                       COL16 --DETSAF_TRANSACTIONLINE NUMBER(20)
  FROM TMP_SAFT_CODSAF C28
    LEFT JOIN TMP_SAFT_CODSAF    C27   ON C27.CODSURSA     = C28.CODSURSA   AND C27.CodSAFTTab = 27
    LEFT JOIN TMP_SAFT_JURNAL    J     ON J.CODJURNAL      = C28.CODSURSA
    LEFT JOIN TMP_SAFT_JURNALDET JD    ON JD.CODJURNAL     = C28.CODSURSA
    LEFT JOIN IESIRI             IES_J ON IES_J.CODIES     = J.CODDOC       AND IES_J.TIPDOC     = J.TIPDOC
    LEFT JOIN INTRARI            INT_J ON INT_J.CODINTR    = J.CODDOC       AND INT_J.TIPDOC     = J.TIPDOC
    LEFT JOIN INTRARI            INT_S ON INT_S.CODINTR    = J.INDEXLOCAL   AND J.TIPDOC         = 81        AND J.CODDOC = 1
    LEFT JOIN IESIRI             IES_S ON IES_S.CODIES     = J.INDEXLOCAL   AND J.TIPDOC         = 81        AND J.CODDOC = 2
    LEFT JOIN TMP_SAFT_NPARTFUZ  P1    ON P1.CODPART       = JD.CODPART
    LEFT JOIN TMP_SAFT_NPARTFUZ  P2    ON P2.CODPART       = JD.CODPART_2
    LEFT JOIN TMP_SAFT_NPARTDET  PD1   ON PD1.CODPART      = P1.CODPARTFUZ
    LEFT JOIN TMP_SAFT_NPARTDET  PD2   ON PD2.CODPART      = P2.CODPARTFUZ
    LEFT JOIN TMP_SAFT_PARTCONT  P1D   ON P1D.CODPART      = P1.CODPART AND P1D.CODCONT = J.CONTD
    LEFT JOIN TMP_SAFT_PARTCONT  P1C   ON P1C.CODPART      = P1.CODPART AND P1C.CODCONT = J.CONTC
    LEFT JOIN TMP_SAFT_PARTCONT  P2D   ON P2D.CODPART      = P2.CODPART AND P2D.CODCONT = J.CONTD
    LEFT JOIN TMP_SAFT_PARTCONT  P2C   ON P2C.CODPART      = P2.CODPART AND P2C.CODCONT = J.CONTC
    LEFT JOIN TMP_SAFT_NCONT     CD    ON CD.CODCONT    = J.CONTD
    LEFT JOIN TMP_SAFT_NCONT     CC    ON CC.CodCont    = J.CONTC
  WHERE C28.CodSAFTTab = 28;

  UPDATE TMP_SAFT28
  SET    COL13 = sFirmaID,    COL14 = sFirmaID
  WHERE (COL13 = '0'      AND COL14 = '0'     ) OR
        (COL13 = '0'      AND COL14 = sFirmaID) OR
        (COL13 = sFirmaID AND COL14 = '0'     );

  PERFORM pkg_saft_PUT_INFO('28.Z','UMPLE_T28--SAF_TRANSACTION');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t30</obj_name>
  <obj_hashval>88be1aecbd6e0de45dc1aa73044bfd72</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t30()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 06.01.2022
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t38</obj_name>
  <obj_hashval>a55d642eb066bab7efdfdb4b8ae12996</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t38()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 06.01.2022
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t39</obj_name>
  <obj_hashval>ddca5085d0949107d94f788b4a7d5b4f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t39()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 06.01.2022
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t40</obj_name>
  <obj_hashval>730b7bc2ef5a84629b574b3e11399b42</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t40()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 06.01.2022
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t41</obj_name>
  <obj_hashval>1a5d92aa4dc349984fbdc712a73c33d4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t41()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 06.01.2022
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_catret_sp_gotorecord</obj_name>
  <obj_hashval>222bc7cbada725ac12a0149067c85be7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_catret_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
tmp double precision;
BEGIN
  --Florin 01.03.2022
  INSERT INTO TMP_SAL_CATRET
  (
  CODCATRET, Denumire, Simbol
  )
  (
  SELECT CODCATRET, Denumire, Simbol
  FROM SAL_CATRET
  WHERE
     CODCATRET = RecId
  );
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_contrpp_sp_gotorecord</obj_name>
  <obj_hashval>215f87ecc7d5a5749c30b6854fe61b3e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_contrpp_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aDoc varchar;
BEGIN
  --Florin 01.03.2022
  INSERT INTO TMP_SAL_CONTRPP1
  (
  codCONTRPP1, codCONTRPP, ANGAJAT, NRCONTRACT, DATASTART, DATASTOP, FOND, PLATAFIRMA, CONTBANCAR, MODPLATA, RATA, ZIPLATA, DATAINREG, PLAFONLEI, PLAFONEURO, DIFERENTE, VALRATEAN, RETNEIMPOZ, RETIMPOZ
  )
  (
  SELECT codCONTRPP1, codCONTRPP, ANGAJAT, NRCONTRACT, DATASTART, DATASTOP, FOND, PLATAFIRMA, CONTBANCAR, MODPLATA, RATA, ZIPLATA, DATAINREG, PLAFONLEI, PLAFONEURO, DIFERENTE, VALRATEAN, RETNEIMPOZ, RETIMPOZ
  FROM SAL_CONTRPP1
  WHERE
     codCONTRPP = RecId
  );
  INSERT INTO TMP_SAL_CONTRPP
  (
  CODCONTRPP, SUCURSALA
  )
  (
  SELECT CODCONTRPP, SUCURSALA
  FROM SAL_CONTRPP
  WHERE
     CODCONTRPP = RecId
  );
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_contrpp_sp_insertrecord</obj_name>
  <obj_hashval>8492f9aa87612583674a93993e9d5596</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_contrpp_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 01.03.2022
  INSERT INTO TMP_SAL_CONTRPP
  (
  CODCONTRPP
  )
  VALUES
  (
  0
  );
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_fondp_setct_monitor</obj_name>
  <obj_hashval>ad2fe2fd75d764fb0031d1030a2b91d0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_fondp_setct_monitor(act_monitor character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 05.04.2022
  perform set_config('PKG_SAL_fondp.CT_MONITOR',aCT_MONITOR,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_fondp_sp_deleterecord</obj_name>
  <obj_hashval>f0a84897cd17cbdfe170681427a88b6d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_fondp_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aDoc varchar(500);
BEGIN
  --Florin 04.04.2022 - postLog
  --Florin 23.02.2022
  --Florin 01.03.2022
  PERFORM pkg_sal_FONDP_setct_monitor('MON_5');
  SELECT denumire  INTO aDoc FROM TMP_SAL_FONDP;
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_FONDP.CT_MONITOR', true)))
  THEN
    PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit('SAL_FONDP', current_setting ('PKG_GLOBALS.USERNAME', true) , 'M', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
  PERFORM pkg_sal_fondp_SP_LOCKRECORD( RecId);
  DELETE FROM SAL_FONDP
  WHERE
   CODFONDP = RecId;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_ndrep_sp_insertrecord</obj_name>
  <obj_hashval>f380b371d943ef46a6c008dcf0db1c54</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_ndrep_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 02.03.2022
  INSERT INTO TMP_SAL_NDREP
  (
  codndrep
  )
  VALUES
  (
  0
  );
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_retineri_sp_gotorecord</obj_name>
  <obj_hashval>e77f95fe9143f984b67961927c6b2cb6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_retineri_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  AANSFARSIT numeric;
  ALUNASFARSIT numeric;
BEGIN
  --Florin 02.03.2022
  INSERT INTO TMP_SAL_RETINERI0
  (
  codretinere0, codretinere, marime, modcalcul, caracter, cont, tert, neimpoz, nrcontr, datacontr, anstart, lunastart, alstart, alstop
  )
  (
  SELECT codretinere0, codretinere, marime, modcalcul, caracter, cont, tert, neimpoz, nrcontr, datacontr, anstart, lunastart, alstart, alstop
  FROM SAL_RETINERI0
  WHERE
     codretinere = RecId
  );
  INSERT INTO TMP_SAL_RETINERI
  (
  codretinere, denumire, codcatret
  )
  (
  SELECT codretinere, denumire, codcatret
  FROM SAL_RETINERI
  WHERE
     CODRETINERE = RecId
  );
  AANSFARSIT := 0;
  ALUNASFARSIT := 0;
  FOR V_REC IN
  (
  SELECT codretinere0, ANSTART, LUNASTART
  FROM TMP_SAL_RETINERI0
  ORDER BY
    ANSTART * 12 + LUNASTART desc
  )
  LOOP
  IF (   AANSFARSIT &lt;&gt; 0)  AND (   ALUNASFARSIT &lt;&gt; 0)
  THEN
  UPDATE TMP_SAL_RETINERI0
  SET
  ANSFARSIT = AANSFARSIT,
  LUNASFARSIT = ALUNASFARSIT
  WHERE
   codretinere0 = V_REC.codretinere0
  ;
  END IF;
  PERFORM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( V_REC.ANSTART, V_REC.LUNASTART, AANSFARSIT, ALUNASFARSIT);
  END LOOP;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_sporuri_sp_insertrecord</obj_name>
  <obj_hashval>1214cf16856d7495472b3eb593f1157e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_sporuri_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 02.03.2022
  INSERT INTO TMP_SAL_SPORURI
  (
  codspor
  )
  VALUES
  (
  0
  );
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_scenariilivr_set_do_commit</obj_name>
  <obj_hashval>8f0f686f54f5836e616928d086406a21</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_scenariilivr_set_do_commit(adocommit boolean)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SCENARIILIVR.DoCommit',aDoCommit,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_setcodclasa</obj_name>
  <obj_hashval>0d09794f672dc840253c8eea53cdf2c3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_setcodclasa(acodclasa numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SELECTARTICOLE.CODCLASA',to_char(aCODCLASA,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_empty_doc_interne_for_jurnal</obj_name>
  <obj_hashval>095efd3dc1d686ae44eb93a1b50bdd46</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_empty_doc_interne_for_jurnal()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_TRANSF;
  DELETE FROM TMP_TRANSF1;
  DELETE FROM TMP_NIR;
  DELETE FROM TMP_NIRSTOC;
  DELETE FROM TMP_LIVR;
  DELETE FROM TMP_LIVR1;
  DELETE FROM TMP_LIVRTOT;
  DELETE FROM TMP_LIVRVAL;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_empty_documente_for_cheltavans</obj_name>
  <obj_hashval>6f035f43f077d9641ce9fdfc17ac1aff</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_empty_documente_for_cheltavans()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_CHELTAVANS;
  DELETE FROM TMP_CHELTAVANS1;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_simlans_loadscenariilivr</obj_name>
  <obj_hashval>4fa7eb8e4cf6fa61c36514432a143575</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_simlans_loadscenariilivr(acodscenariu numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_CC1 RECORD;
  V_REC RECORD;
  V_TMP RECORD;
  vRez  numeric;
  vNes  numeric;
  vCer  numeric;
  vCod  numeric;
BEGIN
  --Laura 01.12.2021 - sinc Oracle (30.11.2021)
  --Laura 25.11.2021 - sinc Oracle (24.11.2021)
  --Adina 09.07.2021 - sinc.Oracle din 08.07.2021
  --Adina 07.07.2021 - sinc.Oracle din 06.07.2021
  --Adina 25.06.2021 - sinc.Oracle din 24.06.2021 (am comentat varianta veche care oricum nu era completa) + 25.06.2021
  --Florin 22.12.2020 - fixat #41814
/*
  FOR V_CC1 IN (SELECT * FROM TMP_SIM_CCOM1) LOOP
    UPDATE TMP_SIM_LANS1 SET NECESAR   = NECESARP * V_CC1.Lansscenariu                  WHERE CodComanda1 = V_CC1.CodComanda1;
    UPDATE TMP_SIM_LANS1 SET DIFERENTE = NECESAR - REZERVAT - NESOSIT - CERERE - CmdInt WHERE CodComanda1 = V_CC1.CodComanda1 and  NECESAR &lt;&gt; 0;
  END LOOP;

  FOR V_Rec IN (SELECT CodComanda1, CodObiect, sum(Necesar) TOTAL
                FROM TMP_SIM_LANS1
                WHERE COALESCE(Necesar, 0) &lt;&gt; 0
                GROUP BY CodComanda1, CodObiect
               )
  LOOP
    UPDATE TMP_SIM_LANS1
      SET
          REZERVAT = Round((REZERVAT * NECESAR / V_REC.TOTAL)::numeric, (Zecimale)::int),
          CERERE   = Round((CERERE   * NECESAR / V_REC.TOTAL)::numeric, (Zecimale)::int),
          NESOSIT  = Round((NESOSIT  * NECESAR / V_REC.TOTAL)::numeric, (Zecimale)::int)
    WHERE CodComanda1 = V_REC.CodComanda1 and  CodObiect = V_REC.CodObiect;

    UPDATE TMP_SIM_LANS1
      SET
          DIFERENTE = NECESAR - REZERVAT - NESOSIT - CERERE - CmdInt
    WHERE CodComanda1 = V_REC.CodComanda1 and  NECESAR &lt;&gt; 0 and  CodObiect = V_REC.CodObiect;
  END LOOP;
*/

  FOR V_CC1 IN (SELECT * FROM TMP_SIM_CCOM1) LOOP
    UPDATE TMP_SIM_LANS1 SET NECESAR = NECESARP * V_CC1.Lansscenariu                    WHERE CodComanda1 = V_CC1.CodComanda1;
    --select codproiectnod, rezervat/necesar into vCod, vCer from tmp_sim_lans1 where codcomanda1 = v_cc1.codcomanda1 and nodoriginal = 0;
    --if vCer &gt; 0 then
    --  perform pkg_simlans_rezolva(v_cc1.codcomanda1, vCod, vCer);
    --end if;
    for v_tmp in (select * from tmp_sim_lans1
            where codcomanda1 = v_cc1.codcomanda1 and tip &lt;&gt; 3
            order by nivel desc, pozitie
            ) loop
            select codproiectnod, rezervat/necesar into vCod, vCer from tmp_sim_lans1 where codcomanda1 = v_cc1.codcomanda1 and codproiectnod = v_tmp.codproiectnod;
    if vCer &gt; 0 then
      perform pkg_simlans_rezolva(v_cc1.codcomanda1, vCod, vCer);
    end if;
   end loop;
   --UPDATE TMP_SIM_LANS1 SET DIFERENTE = NECESAR - REZERVAT - NESOSIT - CERERE - CmdInt WHERE CodComanda1 = V_CC1.CodComanda1 and  NECESAR &lt;&gt; 0;
  END LOOP;

  UPDATE tmp_sim_lans1 SET diferente = coalesce(necesar,0) - coalesce(cmdint,0);

  FOR V_Rec IN (SELECT  DISTINCT CodComanda1, CodObiect, rezervat FROM TMP_SIM_LANS1 WHERE COALESCE(Necesar, 0) &lt;&gt; 0 and rezervat &gt; 0) LOOP
    vRez := v_rec.rezervat;
    UPDATE tmp_sim_lans1 SET rezervat = 0 WHERE codcomanda1 = v_rec.codcomanda1 and  codobiect = v_rec.codobiect;

    FOR v_tmp IN (SELECT * FROM tmp_sim_lans1 WHERE codcomanda1 = v_rec.codcomanda1 and  codobiect = v_rec.codobiect ORDER BY nivel desc, pozitie) LOOP
      IF  v_tmp.Diferente &gt; 0 and  vRez &gt; 0 THEN
        IF  v_tmp.Diferente &lt; vRez THEN
          --se acopera cu rezervarile
          UPDATE tmp_sim_lans1
          SET
          rezervat  = v_tmp.diferente,
          diferente = 0
          WHERE codcomanda1 = v_tmp.codcomanda1 and  codobiect = v_rec.codobiect and  codproiectnod = v_tmp.codproiectnod;

          vRez := vRez - v_tmp.diferente;
        ELSE
          UPDATE tmp_sim_lans1
          SET
          rezervat  = vRez,
          diferente = diferente - vRez
          WHERE codcomanda1 = v_tmp.codcomanda1 and  codobiect = v_rec.codobiect and  codproiectnod = v_tmp.codproiectnod;

          vRez := 0;
        END IF;
      END IF;
    END LOOP;
  END LOOP;

  FOR V_Rec IN (SELECT  DISTINCT CodComanda1, CodObiect, nesosit FROM TMP_SIM_LANS1 WHERE COALESCE(Necesar, 0) &lt;&gt; 0 and nesosit &gt; 0) LOOP
    vNes := v_rec.nesosit;
    UPDATE tmp_sim_lans1 SET nesosit = 0 WHERE codcomanda1 = v_rec.codcomanda1 and  codobiect = v_rec.codobiect;

    FOR v_tmp IN (SELECT * FROM tmp_sim_lans1 WHERE codcomanda1 = v_rec.codcomanda1 and  codobiect = v_rec.codobiect ORDER BY nivel desc, pozitie) LOOP
      IF  v_tmp.Diferente &gt; 0 and  vNes &gt; 0 THEN
        IF  v_tmp.Diferente &lt; vNes THEN
          --se acopera cu rezervarile
          UPDATE tmp_sim_lans1
          SET
          nesosit   = v_tmp.diferente,
          diferente = 0
          WHERE codcomanda1 = v_tmp.codcomanda1 and  codobiect = v_rec.codobiect and  codproiectnod = v_tmp.codproiectnod;

          vNes := vNes - v_tmp.diferente;
        ELSE
          UPDATE tmp_sim_lans1
          SET
          nesosit   = vNes,
          diferente = diferente - vNes
          WHERE codcomanda1 = v_tmp.codcomanda1 and  codobiect = v_rec.codobiect and  codproiectnod = v_tmp.codproiectnod;

          vNes := 0;
        END IF;
      END IF;
    END LOOP;
  END LOOP;

  FOR V_Rec IN (SELECT  DISTINCT CodComanda1, CodObiect, cerere FROM TMP_SIM_LANS1 WHERE COALESCE(Necesar, 0) &lt;&gt; 0 and cerere &gt; 0) LOOP
    vCer := v_rec.cerere;
    UPDATE tmp_sim_lans1 SET cerere = 0 WHERE codcomanda1 = v_rec.codcomanda1 and  codobiect = v_rec.codobiect;

    FOR v_tmp IN (SELECT * FROM tmp_sim_lans1 WHERE codcomanda1 = v_rec.codcomanda1 and  codobiect = v_rec.codobiect ORDER BY nivel desc, pozitie) LOOP
      IF  v_tmp.Diferente &gt; 0 and  vCer &gt; 0 THEN
        IF  v_tmp.Diferente &lt; vCer THEN
          UPDATE tmp_sim_lans1
          SET
          cerere    = v_tmp.diferente,
          diferente = 0
          WHERE
           codcomanda1 = v_tmp.codcomanda1 and  codobiect = v_rec.codobiect and  codproiectnod = v_tmp.codproiectnod;

          vCer := vCer - v_tmp.diferente;
        ELSE
          UPDATE tmp_sim_lans1
          SET
          cerere    = vCer,
          diferente = diferente - vCer
          WHERE
           codcomanda1 = v_tmp.codcomanda1 and  codobiect = v_rec.codobiect and  codproiectnod = v_tmp.codproiectnod;

          vCer := 0;
        END IF;
      END IF;
    END LOOP;
  END LOOP;

  UPDATE TMP_SIM_LANS1 SET DIFERENTE = NECESAR - REZERVAT- NESOSIT - CERERE - CmdInt - case when nodoriginal &gt; 0 then Rezolvat else 0 end;
  UPDATE TMP_SIM_LANS1 SET DIFERENTE = 0 WHERE DIFERENTE &lt; 0;

  for v_rec in (select * from tmp_sim_lans1) loop
    if coalesce(v_rec.necesar,0) &lt;= coalesce(v_rec.rezervat,0) and coalesce(v_rec.necesar,0) &gt; 0 then
      UPDATE tmp_sim_lans1 set datastart = pkg_globals_DataDeAzi() where codcomanda1 = v_rec.codcomanda1 and INSTRB(indexparinte, v_rec.indexparinte) = 1;
    end if;
  end loop;
  UPDATE tmp_sim_lans1 SET datastart = to_date('31.12.9999', 'dd.mm.yyyy') WHERE datastart IS NULL;

  FOR v_Rec IN (SELECT codproiectnod, codcomanda1 FROM tmp_sim_lans1 where coalesce(necesar,0) &gt; coalesce(rezervat,0) and coalesce(necesar,0) &gt; 0 and tip &lt; 3) LOOP
    PERFORM pkg_simlans_setdatastart(v_rec.codproiectnod, v_rec.codcomanda1);
  END LOOP;

  UPDATE tmp_sim_lans1 SET datastart = NULL WHERE datastart = to_date('31.12.9999', 'dd.mm.yyyy');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_simlans_populeaza_tmpuri</obj_name>
  <obj_hashval>2df93fc044a4c55abbe39cff6ca84fbb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_simlans_populeaza_tmpuri(g_subunit numeric, datalivrs character varying, datalivrf character varying, datacmds character varying, datacmdf character varying, scenariu numeric DEFAULT 0, vcodcomanda1 numeric DEFAULT 0)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  NOD_Rezervat     numeric;
  NOD_RezFurn      numeric;
  TOT_RestCmd      numeric;
  TOT_RestFurn     numeric;
  Init             numeric;
  Zec              numeric;
  LastProiectNod   numeric;
  RezolvareLansari numeric;
begin
  --Laura 14.02.2022 - sinc. Oracle (14.02.2022)
  --Florin 11.12.2021 - fixat 52277
  --Laura 30.11.2021 - sinc Oracle (29.11.2021)
  --Laura 29.11.2021 - sinc Oracle (27.11.2021)
  --Laura 25.11.2021 - sinc Oracle (24.11.2021)
  --Laura 28.10.2021 - sinc Oracle (26.10.2021)
  --Adina 07.07.2021 - sinc.Oracle din 07.07.2021
  --Adina 25.06.2021 - sinc.Oracle din 24.06.2021
  --Adina 30.12.2020 - am pus coalesce(Scenariu,0) in loc de Scenariu pt.ca in Oracle este default 0
  --Florin 22.12.2020 - fixat #41814
  --Florin 28.01.2021 - fixat #41886
  if vCodComanda1 = 0 then
    DELETE FROM TMP_SIM_CCOM1;
    DELETE FROM TMP_SIM_LANS;
    DELETE FROM TMP_SIM_LANS1;
    DELETE FROM TMP_SIM_NODECHIV1;
  end if;
  INSERT INTO TMP_SIM_CCOM1(NRDOC, DATADOC, DENOBIECT, DEN_CLIENT, CODCOMANDA1, CODOBIECT, CODPROIECT, VERSIUNE, CODCOMANDA, TIPDOC, CODCLIENT, TERMEN, MASAO, VOLUMO,
                            CODGRUPA, PARITATEGRUPA, GrupaE, ObjGeneric, CODTARA, DEN_TARA, CODZONA, DEN_ZONA, CODLOCALIT, DEN_LOCALIT, UMSEC, OK, ACTIV, TIPCOMANDA,
                            CODEXTERN, DENMAT, TRASEU, POZTRASEU, HTAG, CANTACCEPTAT, STOCREZERVAT, SCENDEFINITIVE, ALTESCENARII, REST, DEREZOLVAT, LANSSCENARIU, LANSAT,
                            Masa, Volum, TipClient)
  select * from
  (SELECT C.NRDOC, C.DATADOC, NOBJ.DENUMIRE DENOBIECT, NP.DEN_PART DEN_CLIENT, C1.CODCOMANDA1, C1.CODOBIECT, C1.CODPROIECT, PR.VERSIUNE, C.CODCOMANDA,
         C.TIPDOC, NP.CODPART CODCLIENT, C1.TERMEN, NOBJ.MASA MASAO, NOBJ.VOLUM / 1000000 VOLUMO, NE.CODGRUPA, NE.PARITATE PARITATEGRUPA, GE.DENUMIRE GRUPAE,
         NOBJE.DENUMIRE OBJGENERIC, TARA.CODTARA, TARA.DEN_TARA, NZ.CODZONA, NZ.DEN_ZONA, NLOC.CODLOCALIT, NLOC.DEN_LOCALIT, C1.UMSEC, 0 OK,
         CASE WHEN  COALESCE(SCEN1.CANT, 0) = 0 THEN 0 ELSE 1 END  ACTIV,
         C.DISPLIVRARE, NOBJ.CODEXTERN, NOBJMAT.DENUMIRE DENMAT, TR.DENTRASEU TRASEU, NAG.POZTRASEU,
         COALESCE(PR.OBS1, '') || coalesce(COALESCE(PC.OBS1, ''),'') HTAG, C1.CANTACCEPTAT CANTACCEPTAT, REZ.REZERVAT STOCREZERVAT,
         COALESCE(SCDEF.CANT, 0) SCENDEFINITIVE, COALESCE(SC.CANT, 0) ALTESCENARII,
         C1.CANTACCEPTAT - COALESCE(SC.CANT, 0) - COALESCE(SCDEF.CANT, 0) REST,
         C1.CANTACCEPTAT - COALESCE(SC.CANT, 0) - COALESCE(SCDEF.CANT, 0) - COALESCE(SCEN1.LANS, 0) DEREZOLVAT,
         coalesce(SCEN1.LANS, C1.CANTACCEPTAT - coalesce(SC.CANT, 0) - coalesce(SCDEF.CANT, 0)) LANSSCENARIU,
         COALESCE(CMDINT.CANTCMDINT, 0) LANSAT, COALESCE(NOBJ.MASA, 0) * COALESCE(SCEN1.LANS, 0),
         Round((COALESCE(NOBJ.VOLUM, 0) / 1000000 * COALESCE(SCEN1.LANS, 0))::numeric, 2),
           case when bitand(NP.Strategic,1)=1 then 'strategic ' else '' end ||
           case when bitand(NP.tippartener,1)=1 then 'intern ' else '' end ||
           case when bitand(NP.tippartener,2)=2 then 'extern ' else '' end ||
           case when bitand(NP.tippartener,4)=4 then 'produc. ' else '' end ||
           case when bitand(NP.tippartener,8)=8 then 'asig.' else '' end ||
           case when BITand(NP.tippartener,16)=16 then 'comis.' else '' end as TipClient
  FROM COMANDA C
       INNER JOIN COMANDA1         C1      ON  C.CODCOMANDA      = C1.CODCOMANDA
       INNER JOIN NARTOBJ          NOBJ    ON  NOBJ.CODOBIECT    = C1.CODOBIECT
       LEFT JOIN NPART             NP      ON  NP.CODPART        = C.PARTENER
       LEFT JOIN TMP_SCENARIILIVR1 SCEN1   ON  SCEN1.CODCOMANDA1 = C1.CODCOMANDA1
       LEFT JOIN PROIECT           PR      ON  PR.CODPROIECT     = C1.CODPROIECT
       LEFT JOIN PROIECTNOD        PRN     ON  PRN.CODPROIECT    = PR.CODPROIECT AND  PRN.NODORIGINAL = 0
       LEFT JOIN (SELECT CODPRODCOMP, CODOBIECT FROM PRODMAT WHERE PRINCIPAL = 1
                 )                 MAT     ON  MAT.CODPRODCOMP   = PRN.CODRETETA
       LEFT JOIN NARTOBJ           NOBJMAT ON  NOBJMAT.CODOBIECT = MAT.CODOBIECT
       LEFT JOIN PRODCOMP          PC      ON  PC.CODPRODCOMP    = PRN.CODRETETA
       LEFT OUTER JOIN NECHIV      NE      ON  NE.CODOBIECT      = C1.CODOBIECT
       LEFT OUTER JOIN GRECHIV     GE      ON  GE.CODGRECHIV     = NE.CODGRUPA
       LEFT OUTER JOIN NECHIV      NG      ON  NG.CODGRUPA       = NE.CODGRUPA AND  NG.GENERIC = 1
       LEFT JOIN NARTOBJ           NOBJE   ON  NOBJE.CODOBIECT   = NG.CODOBIECT
       LEFT JOIN NAGENDA           NAG     ON  NAG.CODAGENDA     = C.CODLOCATIE
       LEFT JOIN TRASEULIVR        TR      ON  TR.CODTRASEULIVR  = NAG.CODTRASEU
       LEFT JOIN NLOCALIT          NLOC    ON  NLOC.CODLOCALIT   = NAG.CODLOCALIT
       LEFT JOIN NZONE             NZ      ON  NZ.CODZONA        = NLOC.CODZONA
       LEFT JOIN NTARI             TARA    ON  TARA.CODTARA      = NLOC.CODTARA
       LEFT JOIN (SELECT S1.CODCOMANDA1, SUM(S1.LANS) CANT
                  FROM SCENARIILIVR1 S1 INNER JOIN SCENARIILIVR S ON  S1.CODSCENARIU = S.CODSCENARIU
                  WHERE COALESCE(S.DEFINITIV, 0) = 1 AND  S.CODSCENARIU &lt;&gt; COALESCE(SCENARIU,0)
                  GROUP BY S1.CODCOMANDA1
                 ) SCDEF                   ON  SCDEF.CODCOMANDA1 = C1.CODCOMANDA1
       LEFT JOIN (SELECT S1.CODCOMANDA1, SUM(S1.LANS) CANT
                  FROM SCENARIILIVR1 S1 INNER JOIN SCENARIILIVR S ON  S1.CODSCENARIU = S.CODSCENARIU
                  WHERE COALESCE(S.DEFINITIV, 0) = 0 AND  S.CODSCENARIU &lt;&gt; COALESCE(SCENARIU,0)
                  GROUP BY S1.CODCOMANDA1
                 ) SC                      ON  SC.CODCOMANDA1 = C1.CODCOMANDA1
       LEFT JOIN (SELECT R.CODCOMANDA1, SUM(R.REST) REZERVAT, NS.CODOBIECT
                  FROM REZERVATS R INNER JOIN NIRSTOC NS ON  R.CODNIRSTOC = NS.CODNIRSTOC
                  WHERE COALESCE(CODCMDPRODMAT, 0) = 0
                  GROUP BY R.CODCOMANDA1, NS.CODOBIECT
                 ) REZ                     ON  REZ.CODCOMANDA1 = C1.CODCOMANDA1 AND  NOBJ.CODOBIECT = REZ.CODOBIECT
       LEFT JOIN (SELECT L0.Codcmd1 CMDCLI, C1.CodObiect, L0.CODSCENARIU, SUM(C1.CANTAcceptat) CANTCMDINT
                  FROM LANSARE1 L1
                       INNER JOIN LANSARE0 L0 ON  L0.CodLansare0 = L1.CodLansare0
                       INNER JOIN Comanda1 C1 ON  C1.CODCOMANDA1 = L1.CodCmd1
                  GROUP BY L0.Codcmd1, C1.CodObiect, L0.CODSCENARIU
                 ) CMDINT                  ON  CMDINT.CMDCLI = C1.CODCOMANDA1 and  NOBJ.CODOBIECT = CMDINT.CODOBIECT
  WHERE C.TIPDOC in (18, 44) AND  COALESCE(C1.CULANSARE, 0) = 1 AND (   G_SUBUNIT = 1 OR  ((C.SUBUNITATEA = G_SUBUNIT and C.TIPDOC = 18) OR (C.SUBUNITSURSA = G_SUBUNIT and C.TIPDOC = 44)))
        AND COALESCE(C.INCHISA, 0) = 0 AND C.OPERAT = 1 AND  COALESCE(C1.CodProiect, 0) &gt; 0 AND  C1.RESTACCEPTAT &lt;&gt; 0
        AND (C1.CODCOMANDA1 = vCODCOMANDA1 or (vCODCOMANDA1 = 0 and (DataLivrS IS NULL OR DataLivrS = '' OR (  C1.TERMEN BETWEEN TO_DATE(DataLivrS, 'DD.MM.YYYY') AND TO_DATE(DataLivrF, 'DD.MM.YYYY')))) )
        AND (C1.CODCOMANDA1 = vCODCOMANDA1 or (vCODCOMANDA1 = 0 and (DataCmdS IS NULL OR DataCmdS = '' OR (  C.DATADOC BETWEEN TO_DATE(DataCmdS , 'DD.MM.YYYY') AND TO_DATE(DataCmdF , 'DD.MM.YYYY')))) )
        AND (vCODCOMANDA1 = 0 OR C1.CODCOMANDA1 = vCODCOMANDA1)
     ) A_PG where Scenariu &gt; 0  or Rest &gt; 0;

  INSERT INTO TMP_SIM_LANS1(DENUMIRE, CODOBIECT, CODCOMANDA1, PREF, NIVEL, POZITIE, CODPROIECTNOD, NODORIGINAL, TIP, NECESARP, NECESAR, REZERVAT, NESOSIT, DataStart, CERERE,
                            STOC, CMDINT, DIFERENTE, ZECIMALE, UMSEC, DEN_UM, MatEchiv, CodExtern, IndexParinte, Rezolvat)
  (
  SELECT DENUMIRE, CODOBIECT, CODCMD1, PREF, NIVEL, POZITIE, CODPROIECTNOD, NODORIGINAL, TIP, COALESCE(NECESARP, 0), 0 NECESAR,
         COALESCE(TotRezervat, 0), COALESCE(RestDeSosit, 0), DataStart, COALESCE(RestCerere, 0), COALESCE(STOC, 0), COALESCE(CantCMDINT, 0),
         0 DIFERENTE, Zecimale, UMSEC, DEN_UM, MatEchiv, CodExtern, IndexParinte, 0
  FROM (
        SELECT Y.DENUMIRE, Y.CODOBIECT, Y.CODCMD1, Y.PREF, Y.NIVEL, Y.POZITIE, Y.CODPROIECTNOD, Y.NODORIGINAL, Y.Tip, Y.CANT, Y.TotRezervat,
               RestFurn.RestDeSosit, RestFurn.DataStart::date DataStart, CEREFURN.RestCerere, Y.STOC, Y.NECESARP, CMDI.CANTCMDINT,
               (SELECT COALESCE(u.Zecimale, 0) FROM NUM u, NART a, NARTOBJ o WHERE o.CodObiect = Y.CodObiect and  a.CodArticol = o.CodArticol and  u.CODUM = a.UM) ZECIMALE,
               0 UMSEC,
               (SELECT DEN_UM FROM NUM u, NART a, NARTOBJ o WHERE o.CodObiect = Y.CodObiect and  a.CodArticol = o.CodArticol and  u.CODUM = a.UM) DEN_UM,
               MatEchiv, CodExtern, Y.IndexParinte
        FROM (
              SELECT NOBJ.DENUMIRE, NOBJ.CODOBIECT, COALESCE(NE.CODCOMANDA1, C1.CODCOMANDA1) CODCMD1, X.PREF, X.NIVEL, X.POZITIE, X.CODPROIECTNOD,
                     X.NODORIGINAL, X.Tip, X.CANT, REZ.TotRezervat, NS.REST * COALESCE(NE.PARITATE, 1) STOC, X.CANT / ORIG.CANT * COALESCE(NE.PARITATE, 1) NECESARP,
                     x.MatEchiv, NOBJ.CodExtern, X.IndexParinte
              FROM COMANDA1 C1
                   INNER JOIN (SELECT PN0.CODPROIECTNOD NODORIG, PN.CODPROIECTNOD, PN.CODPROIECT, PN.CANT, PN.NODORIGINAL, PN.TIP, PN.CODOBIECT,
                                      PN.NIVEL, PN.POZITIE, SUBSTR(PN.INDEXPARINTE, 3, 47) PREF,
                                      CASE WHEN  MECHIV.Nr &gt; 0 THEN PN.Codprodmat ELSE 0 END  MATECHIV,
                                      PN.INDEXPARINTE
                               FROM PROIECTNOD PN
                                    INNER JOIN PROIECTNOD PN0 ON  PN0.CODPROIECT = PN.CODPROIECT AND  PN0.NODORIGINAL = 0
                                    LEFT  JOIN (SELECT count(*) NR, codmat FROM prodmat GROUP BY codmat) MECHIV ON  MECHIV.CODMAT = PN.CODPRODMAT
                              ) X ON  X.CODPROIECT = C1.CODPROIECT
                   LEFT JOIN PROIECTNOD ORIG ON  ORIG.CODPROIECTNOD = X.NODORIG
                   LEFT JOIN NODECHIV   NE   ON  NE.CODCOMANDA1 = C1.CODCOMANDA1 AND  NE.CODPROIECTNOD = X.CODPROIECTNOD
                   LEFT JOIN NARTOBJ    NOBJ ON  NOBJ.CODOBIECT = COALESCE(NE.CODOBIECT, X.CODOBIECT)
                   LEFT JOIN (SELECT sum(NSS.REST) REST, NSS.CODOBIECT
                              FROM NIRSTOC NSS
                                   INNER JOIN NIR      ON  NSS.CODNIR = NIR.CodNIR
                                   INNER JOIN NGEST NG ON  NG.CODGEST = NIR.GEST
                                   WHERE (G_SUBUNIT = 1 OR  NG.CodSubunit = G_SUBUNIT)
                              GROUP BY NSS.CODOBIECT
                             ) NS ON  NS.CODOBIECT = NOBJ.CODOBIECT
                   LEFT JOIN (SELECT R.CodComanda1, NSR.CodObiect, SUM(R.REZERVATINI) TOTREZERVAT
                              FROM REZERVATS R INNER JOIN NIRSTOC NSR ON  R.CODNIRSTOC = NSR.CodNIRSTOC
                              GROUP BY R.CodCOmanda1, NSR.CodObiect
                             ) REZ ON  REZ.CodComanda1 = C1.CodComanda1 AND  NOBJ.CODOBIECT = REZ.CodObiect
              WHERE EXISTS (SELECT TMP.CODPROIECT FROM TMP_SIM_CCOM1 TMP WHERE TMP.CODPROIECT = X.CODPROIECT)
                    AND
                    EXISTS (SELECT TMP.CODCOMANDA1 FROM TMP_SIM_CCOM1 TMP WHERE TMP.CODCOMANDA1 = COALESCE(NE.CODCOMANDA1, C1.CODCOMANDA1) AND (vCODCOMANDA1 = 0 OR tmp.CODCOMANDA1 = vCODCOMANDA1))
              ) Y
                LEFT JOIN (SELECT L0.Codcmd1 CMDCLI1, L0.CODSCENARIU, L1.CODPROIECTNOD, SUM(C1.CANTAcceptat) CANTCMDINT
                           FROM LANSARE1 L1
                                INNER JOIN LANSARE0      L0  ON  L0.CodLansare0  = L1.CodLansare0
                                INNER JOIN TMP_SIM_CCOM1 CC1 ON  CC1.CODCOMANDA1 = L0.CodCmd1
                                INNER JOIN Comanda1      C1  ON  C1.CODCOMANDA1  = L1.CodCmd1
                           GROUP BY L0.Codcmd1, L1.CODPROIECTNOD, L0.CODSCENARIU
                          ) CMDI ON  CMDI.CmdCli1 = Y.CodCmd1 and  CMDI.Codproiectnod = Y.CODPROIECTNOD
                LEFT JOIN (SELECT R.CodComanda1, NS.CodObiect, sum(r.rest) RESTDECONSUMAT
                           FROM rezervats r INNER JOIN nirstoc ns ON  ns.codnirstoc = r.codnirstoc
                           WHERE COALESCE(r.codnirstoc, 0) &gt; 0
                           GROUP BY NS.CodObiect, R.CodComanda1
                          ) RESTREZ ON  RESTREZ.CodObiect = Y.CodObiect AND  RESTREZ.CodComanda1 = Y.CodCmd1
                LEFT JOIN (SELECT R.CodComanda1, R.CodObiect, Max(C1.Termen) DataStart, sum(r.rest) RESTDESOSIT
                           FROM rezervats r inner join Comanda1 C1 on C1.CodComanda1 = r.CODCOMANDA1F
                           WHERE COALESCE(r.codnirstoc, 0) = 0 and  COALESCE(r.CODCOMANDA1F, 0) &lt;&gt; 0
                           GROUP BY r.CodObiect, r.codcomanda1
                          ) RESTFURN ON  RESTFURN.CodObiect = Y.CodObiect and  RESTFURN.CodComanda1 = Y.CodCmd1
                LEFT JOIN (SELECT R.CodComanda1, R.CodObiect, sum(r.rest) RESTCERERE
                           FROM rezervats r
                           WHERE COALESCE(r.codnirstoc, 0) = 0 and  COALESCE(r.CODCOMANDA1F, 0) = 0
                           GROUP BY r.CodObiect, r.codcomanda1
                          ) CEREFURN ON  CEREFURN.CodObiect = Y.CodObiect and  CEREFURN.CodComanda1 = Y.CodCmd1
        ORDER BY Y.DENUMIRE
       ) A_PG
  WHERE NecesarP &gt; 0
  );

  INSERT INTO TMP_SIM_NODECHIV1(CODCOMANDA1, CODPROIECTNOD, CODOBIECT, CANT, PARITATE, TIP, CODOBIECTORIG, NODORIGINAL, STOC, CANTECHIVALATA, DENOBIECTECHIV, CODEXTERN)
  SELECT NE1.CODCOMANDA1, NE1.CODPROIECTNOD, NE1.CODOBIECT, NE1.CANT, NE1.PARITATE, NE1.TIP, L1.CODOBIECT, L1.NODORIGINAL,
         COALESCE(NS.REST, 0), NE1.CANT / NE1.PARITATE, OBJ.DENUMIRE, OBJ.CODEXTERN
  FROM TMP_SIM_LANS1 L1
       INNER JOIN NODECHIV1 NE1 ON  L1.CODCOMANDA1 = NE1.CODCOMANDA1 AND  L1.CODPROIECTNOD = NE1.CODPROIECTNOD
       INNER JOIN NARTOBJ   OBJ ON  OBJ.CODOBIECT  = NE1.CODOBIECT
       LEFT JOIN (SELECT sum(NSS.REST) REST, NSS.CODOBIECT
                  FROM NIRSTOC NSS
                       INNER JOIN NIR      ON  NSS.CODNIR = NIR.CodNIR
                       INNER JOIN NGEST NG ON  NG.CODGEST = NIR.GEST
                  WHERE (G_SUBUNIT = 1 OR  NG.CodSubunit = G_SUBUNIT)
                  GROUP BY NSS.CODOBIECT
                 ) NS ON  NS.CODOBIECT = OBJ.CODOBIECT
  WHERE vCODCOMANDA1 = 0 OR L1.CODCOMANDA1 = vCODCOMANDA1;

  IF  COALESCE(Scenariu,0) = 0 THEN
    RezolvareLansari := 0;
  ELSE
    RezolvareLansari := 1;
  END IF;

  PERFORM PKG_SimLans_LoadScenariiLivr(COALESCE(Scenariu,0));
  update TMP_SIM_CCOM1 tmp set lansscenariu = (select t.lans from TMP_SCENARIILIVR1 t where tmp.codcomanda1 = t.codcomanda1);--repun
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settccurtotal</obj_name>
  <obj_hashval>500b0967e83800fed071c1bec7086214</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settccurtotal(atccurtotal numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcCurTotal',to_char(atcCurTotal,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settccurtotalaj</obj_name>
  <obj_hashval>52cbd18bc7a0dad1e841a972f91c93bd</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settccurtotalaj(atccurtotalaj numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcCurTotalAj',to_char(atcCurTotalAj,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_sp_lockrecord</obj_name>
  <obj_hashval>afbe68bdb0e3c1f6e927a98f14903f8c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CodSitFin INTO Tmp FROM SITFIN WHERE CodSitFin = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stocinitial_sp_insertrecord</obj_name>
  <obj_hashval>e5e2956add13c377ad3b53108a3dbd17</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stocinitial_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_STOCINI (CODSTOCINI) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stocvalini_sp_lockrecord</obj_name>
  <obj_hashval>b5053e8bb0f9e752315e7bb476464b37</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stocvalini_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMP numeric;
begin
  SELECT CODSTOCVALINI INTO TMP FROM STOCVALINI WHERE CODSTOCVALINI = RECID FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_targetag_sp_gotorecord</obj_name>
  <obj_hashval>3ee697ddfbf35499459c825a5ebb9e95</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_targetag_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aTipTarget numeric;
BEGIN
  --Florin 02.12.2024 - sinc. Oracle
  --Florin 11.04.2023 -
  --Florin 03.11.2020 - fixat #40804
  --Bogdan 09.11.2020
  INSERT INTO TMP_TARGETAG (CodTARGETAG,
      TipDoc,
      Anulat,
      Blocat,
      Operat,
      Activ,
      DataStart,
      DataStop,
      TipTarget,
      Moneda,
      Obs,
      Subunitatea,
      An,
      Luna,
      UserId,
      DataCreare,
      Agent,
      Client,
      ClasaPart,
      TipPart,
      LunaStart,
      AnStart,
      LunaEnd,
      AnEnd,
      Nrclienti)
  SELECT CodTARGETAG,
    TipDoc,
    Anulat,
    Blocat,
    Operat,
    Activ,
    DataStart,
    DataStop,
    TipTarget,
    Moneda,
    Obs,
    Subunitatea,
    (SELECT PKG_GLOBALS_GetAnLucru.WME_RESULT   FROM PKG_GLOBALS_GetAnLucru (NULL,NULL)) ,
    (SELECT PKG_GLOBALS_GetLunaLucru.WME_RESULT FROM PKG_GLOBALS_GetLunaLucru (NULL,NULL)) ,
    UserId,
    DataCreare,
    Agent,
    Client,
    ClasaPart,
    TipPart,
    LunaStart,
    AnStart,
    LunaEnd,
    AnEnd,
    Nrclienti
  FROM TARGETAG
  WHERE
    CodTARGETAG = RecId;

  INSERT INTO TMP_TARGETAG1 (CodTARGETAG1,
      CodTARGETAG,
      CodObiect,
      CodClasa,
      CodClasaS,
      UMSec,
      Cant,
      Valoare,
      Masa,
      Volum,
      Obs,
      CantMin,
      CantMax,
      IndexLocal,
      TipLinie,
      DenObiect,
      DenUM,
      Paritate,
      CodArticol)
  SELECT C1.CodTARGETAG1,
    C1.CodTARGETAG,
    C1.CodObiect,
    C1.CodClasa,
    CodClasaS,
    C1.UMSec,
    C1.Cant / CASE WHEN COALESCE (U.Paritate, 1) = 0 THEN 1 ELSE COALESCE (U.Paritate, 1) END ,
    C1.Valoare,
    C1.Masa,
    C1.Volum,
    C1.Obs,
    C1.CantMin,
    C1.CantMax,
    ROW_NUMBER() OVER() ,
    CASE WHEN A.TipArticol = '0' THEN '=' ELSE 'S' END ,
    O.Denumire,
    U.Den_UM1,
    CASE WHEN COALESCE (U.Paritate, 1) = 0 THEN 1 ELSE COALESCE (U.Paritate, 1) END ,
    O.CodArticol
  FROM TARGETAG          C
    INNER JOIN TARGETAG1 C1 ON C1.CodTARGETAG = C.CodTARGETAG
    LEFT JOIN NArtObj    O  ON O.CodObiect    = C1.CodObiect
    LEFT JOIN NArt       A  ON A.CodArticol   = O.CodArticol
    LEFT JOIN NUM1       U  ON U.CodUM1       = C1.UMSec
  WHERE
    C.CodTARGETAG = RecId;

  SELECT TipTarget INTO aTipTarget FROM TMP_TARGETAG;

  IF aTipTarget = 2 THEN
    UPDATE TMP_TARGETAG1 T1
    SET DenObiect = (SELECT DEN_CLASEA FROM NCLASEA C WHERE CodCLASEA = T1.Codclasa);
  ELSIF aTipTarget = 3 THEN
    UPDATE TMP_TARGETAG1 T1
    SET DenObiect = (SELECT DEN_CLASEAS FROM NCLASEAS C WHERE CodCLASEAS = T1.Codclasas);
  END IF;

  PERFORM PKG_CFGTABLES_EXT_GOTORECORD(17);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tesaturi_sp_gotorecord</obj_name>
  <obj_hashval>87c3d744f6fd8397035205f3a119841d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tesaturi_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_TESATURI(CODTESATURA, DENUMIRE, COMPOZITIE, MASASPECIFICA, LEGATURA, DESIMEU, DESIMEB, CATEGORIE)
  SELECT CODTESATURA, DENUMIRE, COMPOZITIE, MASASPECIFICA, LEGATURA, DESIMEU, DESIMEB, CATEGORIE FROM TESATURI WHERE CodTESATURA = RECID;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tipsedii_sp_lockrecord</obj_name>
  <obj_hashval>e2668c9f76e14a690cee939edeb1805c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tipsedii_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CODTIPSEDIU INTO Tmp FROM NTIPSEDII WHERE CODTIPSEDIU = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_getvvalsuplim</obj_name>
  <obj_hashval>0940b94b2b7fd0e547486cf36892c7d5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_getvvalsuplim(INOUT wme_result double precision, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_TRANSPORT.vValSuplim', true)),'99999999999.9999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_sp_lockrecord</obj_name>
  <obj_hashval>97223cc4488cf9f688da48f5a59bb6ba</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  tmp_recid numeric;
begin
  SELECT CodTraseuLivr INTO tmp_recid FROM TraseuLivr WHERE CodTraseuLivr = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_sp_postrecord_from_import</obj_name>
  <obj_hashval>4c232d2a3b7628f26870d88425b6ec3c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_sp_postrecord_from_import(INOUT recid numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC           RECORD;
  TIPDOCCASABANCA NUMERIC := 0;
  NR              NUMERIC := 0;
  vCOD            numeric;
  MONEDA          numeric;
  OLDCARNETDOC    numeric := 0;
  OLDNRDOC        numeric := 0;
begin
  SELECT TIPDOC    INTO TIPDOCCASABANCA FROM TMP_TREZOR;
  SELECT CODMONEDA INTO MONEDA          FROM TMP_TREZOR;
  SELECT NEXTVAL('SEQ_TREZOR_CODTREZOR') INTO RecID;

  UPDATE TMP_TREZOR1 SET CODTREZOR = RecID;

  INSERT INTO TREZOR(CODTREZOR, TIPDOC, CODBANCA, ICONTPERS, MONEDAPERS, DATADOC, NUMEDOC, AN, LUNA, AGENT, OPERAT, BLOCAT, SUBUNITATEA, userid, datacreare, IDIMPORT)
  (
  SELECT RecId, TIPDOC, CODBANCA, ICONTPERS, MONEDAPERS, DATADOC, NUMEDOC, AN, LUNA, AGENT, OPERAT, BLOCAT, SUBUNITATEA,
         TO_NUMBER(current_setting('PKG_GLOBALS.USERID', true),'999999999999999999'), current_timestamp, IDIMPORT
  FROM TMP_TREZOR
  );

  FOR v_rec IN (SELECT * FROM TMP_TREZOR1 ORDER BY INDEXLOCAL) LOOP
    SELECT NEXTVAL('SEQ_TREZOR1_CODTREZOR1') INTO vCOD;

    UPDATE TMP_GENERAL  SET CODDOC     = vCOD WHERE CODDOC = v_rec.CODTREZOR1;
    UPDATE TMP_OBLIGPIF SET CODTREZOR1 = vCOD WHERE CODTREZOR1 = v_rec.CODTREZOR1;

    INSERT INTO TREZOR1(CODTREZOR1, CODTREZOR, INDEXLOCAL, TIPTRANZ, CARNETDOC, DOC, NRDOC, DATADOC, VALDOC, CURS, COMISION, OBIECTTRANZ, SERIEDOC, CODPART, TIPDECONT,
                        PLATATVA, DATADECONT, AN, LUNA, OBS, AGENT, ANULAT, userid, datacreare)
    VALUES(vCod, RecID, v_rec.INDEXLOCAL, v_rec.TIPTRANZ, v_rec.CARNETDOC, v_rec.DOC, v_rec.NRDOC, v_rec.DATADOC, v_rec.VALDOC, v_rec.CURS, v_rec.COMISION,
           v_rec.OBIECTTRANZ, V_REC.SERIEDOC, v_rec.CODPART, v_rec.TIPDECONT, V_REC.PLATATVA, v_rec.DATADECONT, v_rec.AN, v_rec.LUNA, v_rec.OBS, V_REC.AGENT, V_REC.ANULAT,
           TO_NUMBER(current_setting('PKG_GLOBALS.USERID', true),'999999999999999999'), current_timestamp);
  END LOOP;

  FOR v_rec IN (SELECT * FROM TMP_GENERAL) LOOP
    SELECT NEXTVAL('SEQ_GENERAL_CODGENERAL') INTO vCOD;

    UPDATE TMP_OBLIGPIF SET CODGENERAL = vCOD WHERE CODGENERAL = v_rec.CODGENERAL;

    INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
    VALUES(vCOD, v_rec.TIPDOC, v_rec.CODDOC, v_rec.MONEDA, v_rec.CURS, v_rec.TVA, v_rec.SEMNIFICATIE);
  END LOOP;

  DELETE FROM TMP_OBLIGPIF_ASOCIAT;
  INSERT INTO TMP_OBLIGPIF_ASOCIAT(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODANALIZANOD, TVANEDED, PROCTVA)
  (
  SELECT CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODANALIZANOD, TVANEDED, PROCTVA
  FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (700, 701, 750, 751)
  );

  DELETE FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (700, 701, 750, 751);

  FOR v_rec IN (SELECT * FROM TMP_OBLIGPIF ORDER BY CODOBLIGPIF) LOOP
    IF  V_REC.CODOBLIGPIF &lt; 0 THEN
      SELECT NEXTVAL('SEQ_OBLIGPIF_CODOBLIGPIF') INTO vCOD;
    ELSE
      vCOD := V_REC.CODOBLIGPIF;
    END IF;

    UPDATE TMP_STINGERE SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;
    UPDATE TMP_OBLIGPIF_ASOCIAT SET CODOBLIGASOCIAT = vCOD WHERE CODOBLIGASOCIAT = v_rec.CODOBLIGPIF;

    INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CODNPARCAUT, CODANALIZANOD, TVANEDED, PROCTVA)
    VALUES(vCOD, v_rec.CODGENERAL, v_rec.TERMEN, V_REC.VALOARE, V_REC.VALOARE, v_rec.CODPART, v_rec.ICONT, v_rec.TIPPLATA, v_rec.MAJORARI, v_rec.SEMNIFICATIE, v_rec.TIP, v_rec.CONTBANKTRANZACTIE, v_rec.CODOBLIGASOCIAT, v_rec.VALOAREAFISATA, v_rec.CODGEST, V_REC.CODNPARCAUT, v_Rec.CODANALIZANOD, V_REC.TVANEDED, V_REC.PROCTVA);
  END LOOP;

  FOR v_rec IN (SELECT * FROM TMP_OBLIGPIF_ASOCIAT ORDER BY CODOBLIGPIF) LOOP
    IF  V_REC.CODOBLIGPIF &lt; 0 THEN
      SELECT NEXTVAL('SEQ_OBLIGPIF_CODOBLIGPIF') INTO vCOD;
    ELSE
      vCOD := V_REC.CODOBLIGPIF;
    END IF;

    UPDATE TMP_OBLIGPIF SET CODOBLIGPIF = vCOD WHERE CODOBLIGPIF = v_rec.CODOBLIGPIF;
    UPDATE TMP_STINGERE SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;

    INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CODNPARCAUT, CODANALIZANOD, TVANEDED, PROCTVA)
    VALUES(vCOD, v_rec.CODGENERAL, v_rec.TERMEN, v_rec.VALOARE, v_rec.REST, v_rec.CODPART, v_rec.ICONT, v_rec.TIPPLATA, v_rec.MAJORARI, v_rec.SEMNIFICATIE, v_rec.TIP, v_rec.CONTBANKTRANZACTIE, v_rec.CODOBLIGASOCIAT, v_rec.VALOAREAFISATA, v_rec.CODGEST, V_REC.CODNPARCAUT, v_rec.CODANALIZANOD, V_REC.TVANEDED, V_REC.PROCTVA);
  END LOOP;

  FOR v_rec IN (SELECT * FROM TMP_STINGERE) LOOP
    SELECT NEXTVAL('SEQ_STINGERE_CODSTINGERE') INTO VCod;

    INSERT INTO STINGERE(CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
    VALUES(vCod, v_rec.CODSTINSPIF, v_rec.CODSTINGATORPIF, v_rec.VALOARE);
  END LOOP;

  UPDATE OBLIGPIF O
  SET
  REST = (CASE WHEN  VALOARE &gt;= 0 THEN VALOARE - COALESCE( (SELECT SUM( VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
               WHEN  VALOARE &lt;  0 THEN VALOARE + COALESCE( (SELECT SUM( VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
          END )
  WHERE
    O.CODOBLIGPIF IN (SELECT CODSTINSPIF FROM TMP_STINGERE
                      UNION
                      SELECT CODSTINSPIF FROM TMP_STINGERE_INITIAL
                      UNION
                      SELECT CODOBLIGPIF AS CODSTINSPIF FROM TMP_OBLIGPIF_INITIAL WHERE SEMNIFICATIE IN (310, 410, 500, 600, 800, 801)
                     );

  UPDATE OBLIGPIF O
  SET
  REST = (CASE WHEN ((O.SEMNIFICATIE IN (310, 410, 500, 600, 330, 430)) OR (O.SEMNIFICATIE IN (800, 801) AND COALESCE(CONTBANKTRANZACTIE, 0) &lt;&gt; 0)) AND  O.VALOARE &gt;= 0
                 THEN O.VALOARE - COALESCE( (SELECT SUM( VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
               WHEN ((O.SEMNIFICATIE IN (310, 410, 500, 600, 330, 430)) OR (O.SEMNIFICATIE IN (800, 801) AND COALESCE(CONTBANKTRANZACTIE, 0) &lt;&gt; 0) ) AND  O.VALOARE &lt; 0
                 THEN O.VALOARE + COALESCE( (SELECT SUM( VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
               WHEN O.SEMNIFICATIE NOT IN (310, 410, 500, 600, 800, 801, 1100, 1101, 330, 430) THEN 0
               WHEN O.SEMNIFICATIE IN (800, 801) AND  COALESCE( CONTBANKTRANZACTIE, 0) = 0     THEN 0
               WHEN O.SEMNIFICATIE IN (1100, 1101)                                             THEN O.VALOARE
          END )
  WHERE
    O.CODGENERAL IN (SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = TIPDOCCASABANCA AND CODDOC IN (SELECT CODTREZOR1 FROM TREZOR1 WHERE CODTREZOR = RECID));
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tvaserv_makejurnaldirty</obj_name>
  <obj_hashval>54eefe68eb6b7c7ab5007257d471f5f2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tvaserv_makejurnaldirty(pcodtvaserv numeric, palstart numeric, palstop numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  v_rec record;
BEGIN
  --Florin 28.11.2022
    for v_rec in (select i.codies, i.tipdoc
      from iesiri i
    where i.codtvaserv = pCodTVAServ
      and (i.an * 12 + i.luna) between pALStart and pALStop) LOOP
        update jurnal1 j1
          set dirty = 1
        where j1.coddoc = v_rec.codies and  j1.tipdoc = v_rec.tipdoc;
    END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_umsec_sp_insertrecord</obj_name>
  <obj_hashval>37d0fb6f5e792ff63bcff3d546df2587</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_umsec_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_NUM1 (CODUM1) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_getsectieinterventie</obj_name>
  <obj_hashval>33cf2c7511a50d3553676ef2f16ccc32</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_getsectieinterventie(INOUT wme_result numeric, INOUT acodprodcomp numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCount numeric;
begin
  IF  aCodProdComp = 0 THEN
    WME_Result :=  0;
    RETURN;
  END IF;

  SELECT count( *)
  INTO acount
  FROM prodcomp pc INNER JOIN prodgest pg ON  pg.codprodcomp = pc.codprodcomp
  WHERE pc.codprodcomp = aCodProdComp;

  IF  acount = 1 THEN
    SELECT pg.codgest
    INTO acount
    FROM prodcomp pc INNER JOIN prodgest pg ON  pg.codprodcomp = pc.codprodcomp
    WHERE pc.codprodcomp = aCodProdComp;
  END IF;

  WME_Result :=  aCount;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_getvcodutilaj2c</obj_name>
  <obj_hashval>4f95c2359fcbfa30e9ed707ba55aa410</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_getvcodutilaj2c(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_UTILAJE.vCodUtilaj2C', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_voucher_sp_gotorecord</obj_name>
  <obj_hashval>325f224e8747f3f1903d6eef4bdab80f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_voucher_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 14.11.2023 - sinc. Oracle
  INSERT INTO  TMP_VOUCHERCADOU SELECT * FROM VOUCHERCADOU WHERE COD = RECID;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_voucher_sp_lockrecord</obj_name>
  <obj_hashval>f8629e8a288a6db59b230ee9a5140588</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_voucher_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CodVoucher INTO Tmp FROM VOUCHER WHERE CodVoucher = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_vouchercadou_sp_insertrecord</obj_name>
  <obj_hashval>3022a8021508af4169f15ae79f1d481b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_vouchercadou_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 12.12.2024 - sinc. Oracle
  INSERT INTO TMP_VOUCHERCADOU( COD ) VALUES (0) ;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_next_numar_doc</obj_name>
  <obj_hashval>c47757d20e26b9867419dac1e6efb4c9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_next_numar_doc(INOUT wme_result character varying, INOUT acodcarnet numeric, INOUT seriedoc character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
  DECLARE
    NRDOC      varchar := '0';
    PASI       numeric := 0;
    aSIMBOLDOC varchar := '';
  begin
    WHILE 1 = 1
    LOOP
    /*  NRDOC := (   SELECT PKG_CARNETEDOC_GETNEXTNRDOC.WME_RESULT
          FROM PKG_CARNETEDOC_GETNEXTNRDOC (NULL,aCODCARNET, SERIEDOC, aSIMBOLDOC)); */
          SELECT PKG_CARNETEDOC_GETNEXTNRDOC.WME_RESULT, PKG_CARNETEDOC_GETNEXTNRDOC.SERIEDOC
          FROM PKG_CARNETEDOC_GETNEXTNRDOC (NULL,aCODCARNET, NULL, aSIMBOLDOC) into NRDOC, SERIEDOC;
      IF (   SELECT PKG_CARNETEDOC_CANLOCKNUMARDOC.WME_RESULT
          FROM PKG_CARNETEDOC_CANLOCKNUMARDOC (NULL,aCODCARNET, NRDOC)) = 1
        OR PASI                                                           &gt; 1000 THEN
        EXIT;
      END IF;
      PASI := PASI + 1;
    END LOOP;
    WME_Result := NRDOC;
    RETURN;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_getstocuri_stoc0_fara_partener</obj_name>
  <obj_hashval>4699b8725ea45ee3e4161252bd7cd9ec</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_getstocuri_stoc0_fara_partener(INOUT wme_result refcursor, INOUT adenobiect character varying, INOUT adenclasa character varying, INOUT acodgest numeric, INOUT acodextern character varying, INOUT acodintern character varying, INOUT atogglevat numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
  DECLARE
    STOCCURSOR REFCURSOR;
    FILTRU_ART   varchar := '';
      FILTRU_CLASA varchar := '';
    FILTRU_GEST  varchar := '';
     FILTRU_CODEXTERN   varchar := '';
      FILTRU_CODINTERN   varchar := '';
      S           varchar;
      AN           numeric(5);
      LUNA         numeric(2);
      aCODCATPRET  numeric := 0;
      COMPUTE_VAT  varchar := ' coalesce(PM.LEI, 0) ';
      REVERSE_VAT  varchar := ' coalesce(PM.LEI, 0) ';
       var_table_varchar varchar array;
  begin
    AN   := EXTRACT(YEAR FROM current_date);
    LUNA := EXTRACT(MONTH FROM current_date);
    perform pkg_globals_setlunalucru_simpla(AN, Luna);
    perform pkg_stoc_generare_facturi_make_config_luna_ext();

    IF coalesce(aToggleVAT, 0) = 1 THEN
      COMPUTE_VAT := ' ROUND(coalesce(PM.LEI, 0) * (1 + coalesce(TVAL.PROCENT, 0) / 100), 2) ';
    END IF;

     IF coalesce(aToggleVAT, 0) = 1 THEN
      REVERSE_VAT := ' ROUND(coalesce(PM.LEI, 0) / (1 + coalesce(TVAL.PROCENT, 0) / 100), 2) ';
    END IF;

    S := ' SELECT distinct * FROM ' ||
         ' ( ' ||
         '    SELECT ' ||
         '      1 AS TIPARTICOL, ' ||
         '      O.DENUMIRE AS DENOBIECT, ' ||
         '      O.CODEXTERN, ' ||
         '      O.CODINTERN,' ||
       '      O.CODARTICOL,' ||
       '      O.INACTIV, ' ||
         '      A.DEN_ARTICOL AS DEN_ART,' ||
         '      A.UM1 AS DUM1,' ||
         '      A.COMENZIONLINE,' ||
         '      U0.DEN_UM1 AS DENUM1,' ||
         '      NULL as DEN_GEST, ' ||
         '      O.CODOBIECT, ' ||
         '      0 as CODGEST, ' ||

          '    CASE ' ||
         '      WHEN CAT.TIP = 1 THEN '|| REVERSE_VAT || ' ' ||
         '      ELSE coalesce(PM.LEI, 0) ' ||
         '    END  AS PRET, ' ||
         '      coalesce(TVAL.PROCENT, 0) AS TVA, ' ||
         '    CASE ' ||
         '      WHEN CAT.TIP = 1 THEN coalesce(PM.LEI, 0) ' ||
         '      ELSE '|| COMPUTE_VAT || ' ' ||
         '    END  AS PRET_TVA, ' ||

         '      0 AS STOC, ' ||
         '      P.DEN_PART AS PRODUCATOR, ' ||
         '      CLAS.DEN_CLASEA AS CLASA, ' ||
         '      U.DEN_UM, ' ||
         '      U1.CODUM1 ' ||
         '    FROM  ' ||
         '      NART A   ' ||
       '      LEFT OUTER JOIN NUM1 U0 ON U0.CODUM1 = A.UM1 ' ||
         '      LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = A.CODARTICOL  ' ||
         '      LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA = NAL.CODTVA ' ||
         '      LEFT OUTER JOIN NUM U ON U.CODUM = A.UM ' ||
         '      LEFT OUTER JOIN NUM1 U1 ON U1.CODUM = U.CODUM AND U1.SECUNDARA = 0' ||
         '      LEFT OUTER JOIN NCLASEA CLAS ON CLAS.CODCLASEA = CLASA, ' ||
         '      NARTOBJ O ' ||
         '      LEFT OUTER JOIN PRETM PM ON PM.CODOBIECT = O.CODOBIECT AND PM.IMPLICIT = 1' ||
         '      LEFT JOIN NCATPRET CAT ON CAT.CODCATPRET = PM.CODCATPRET ' ||
         '      LEFT OUTER JOIN NPART P ON P.CODPART = O.CODPRODUCATOR ' ||
         '    WHERE O.CODARTICOL = A.CODARTICOL AND coalesce(O.INACTIV, 0) &lt;&gt;1 AND coalesce(O.BLOCAT, 0) NOT IN (1, 3) AND ( (A.TIPARTICOL = 1 ) OR (A.TIPARTICOL = 0 AND ((SELECT COUNT(*) FROM NIRSTOC NS WHERE NS.CODOBIECT=O.CODOBIECT) = 0) and 2&gt; 1 ) ) ' ||
         ' UNION ALL ' ||
         ' SELECT ' ||
         '    0 AS TIPARTICOL, ' ||
         '    O.DENUMIRE AS DENOBIECT, ' ||
         '    O.CODEXTERN,' ||
         '    O.CODINTERN, ' ||
       '    O.CODARTICOL,' ||
       '      O.INACTIV, ' ||
         '    A.DEN_ARTICOL AS DEN_ART,' ||
         '    A.UM1 AS DUM1,' ||
         '      A.COMENZIONLINE,' ||
         '    U0.DEN_UM1 AS DENUM1,' ||
         '    G.DEN_GEST, ' ||
         '    STOCVIEW.CODOBIECT, ' ||
         '    STOCVIEW.CODGEST,' ||

         '    CASE ' ||
         '      WHEN CAT.TIP = 1 THEN '|| REVERSE_VAT || ' ' ||
         '      ELSE coalesce(PM.LEI, 0) ' ||
         '    END  AS PRET, ' ||
         '      coalesce(TVAL.PROCENT, 0) AS TVA, ' ||
         '    CASE ' ||
         '      WHEN CAT.TIP = 1 THEN coalesce(PM.LEI, 0) ' ||
         '      ELSE '|| COMPUTE_VAT || ' ' ||
         '    END  AS PRET_TVA, ' ||

         '    STOCVIEW.STOC, ' ||
         '    P.DEN_PART AS PRODUCATOR, ' ||
         '    CLAS.DEN_CLASEA AS CLASA, ' ||
         '    U.DEN_UM, ' ||
         '    U1.CODUM1 ' ||
         ' FROM ' ||
         '    ( ' ||  -- stoc cumulat
         '     SELECT CODOBIECT, CODGEST, SUM(STOC) AS STOC ' ||
         '     FROM ' ||
         '         ( ' ||
         '           SELECT  CODOBIECT, CODGEST, STOC FROM ' ||
         '                (  ' ||
         '                   SELECT ' ||
         '                      NS.CODOBIECT, ' ||
         '                      N.GEST AS CODGEST,' ||
         '                      SUM(NS.REST - coalesce((SELECT SUM(REST) FROM REZERVATS R WHERE R.CODNIRSTOC = NS.CODNIRSTOC), 0)) AS STOC ' ||
         '                   FROM ' ||
         '                      NIRSTOC NS  ' ||
         '                      LEFT OUTER JOIN TMP_IOART_LUNA IOAL ON IOAL.CODIOART = NS.CODIOART, ' ||
         '                      NIR     N ' ||
         '                   WHERE ' ||
  --     '                      NS.REST &gt;= 0 ' ||
         '                      N.CODNIR = NS.CODNIR ' ||
         '                      AND (((SELECT COUNT(*) FROM TMP_GESTDEDICATE) = 0) OR (EXISTS (SELECT CODGEST FROM TMP_GESTDEDICATE WHERE CODGEST = N.GEST))) ' ||
         '                      AND IOAL.MG &lt;&gt; 3 AND IOAL.MG &lt;&gt; 5  ' ||
         '                      AND coalesce(IOAL.ESTEMIFIX, 0) = 0    ' ||
         '                      AND coalesce(IOAL.ESTEOBINV, 0) = 0    ' ||
         '                   GROUP BY ' ||
         '                      NS.CODOBIECT, ' ||
         '                      N.GEST ' ||
         '                ) ' ||
  --       '           WHERE STOC &gt;= 0 ' ||
         '         ) ' ||
         '     GROUP BY CODOBIECT, CODGEST ' ||
         '    ) STOCVIEW,  ' ||
         '    NARTOBJ O ' ||
         '    LEFT OUTER JOIN PRETM PM ON PM.CODOBIECT = O.CODOBIECT AND PM.IMPLICIT = 1 ' ||
         '    LEFT JOIN NCATPRET CAT ON CAT.CODCATPRET = PM.CODCATPRET ' ||
         '    LEFT OUTER JOIN NART A ON A.CODARTICOL = O.CODARTICOL  ' ||
      '      LEFT OUTER JOIN NUM1 U0 ON U0.CODUM1 = A.UM1 ' ||
         '    LEFT OUTER JOIN NUM U ON U.CODUM = A.UM ' ||
         '    LEFT OUTER JOIN NUM1 U1 ON U1.CODUM = U.CODUM AND U1.SECUNDARA = 0' ||
         '    LEFT OUTER JOIN NCLASEA CLAS ON CLAS.CODCLASEA = CLASA  ' ||
         '    LEFT OUTER JOIN NPART P ON P.CODPART = O.CODPRODUCATOR ' ||
         '    LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = A.CODARTICOL  ' ||
         '    LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA = NAL.CODTVA, ' ||
         '    NGEST G ' ||
         '  WHERE ' ||
         '    G.CODGEST = STOCVIEW.CODGEST ' ||
         '    AND G.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE ' ||
         '    AND O.CODOBIECT = STOCVIEW.CODOBIECT AND coalesce(O.INACTIV, 0) &lt;&gt;1 AND coalesce(O.BLOCAT, 0) NOT IN (1, 3) ' ||
         ' ) ' ||
         '  WHERE 1=1';

    IF coalesce(aDENOBIECT, '?') &lt;&gt; '?' THEN
    /*
      FILTRU_ART := ' AND UPPER(DENOBIECT) LIKE ' || '''%' || UPPER(aDENOBIECT) || '%''';
      */
      var_table_varchar := pkg_wmeonline_TOKENIZE_STRING(aDENOBIECT, ' ');
          for elem in 1 .. array_length(var_table_varchar)
          loop
           FILTRU_ART := FILTRU_ART || ' AND UPPER(DENOBIECT) LIKE ' || '''%' || UPPER(var_table_varchar[elem]) || '%''';
          end loop;
    END IF;

    IF coalesce(aDENOBIECT, '?') &lt;&gt; '?' AND SUBSTR(aDENOBIECT, 1, 1) = '=' THEN
      FILTRU_ART := ' AND UPPER(DENOBIECT) = ''' ||  LTRIM(UPPER(aDENOBIECT), '=') || ''' ';
    END IF;


    IF coalesce(aCODEXTERN, '?') &lt;&gt; '?' THEN
      FILTRU_CODEXTERN := ' AND UPPER(CODEXTERN) LIKE ' || '''%' || UPPER(aCODEXTERN) || '%''';
    END IF;

    IF coalesce(aCODEXTERN, '?') &lt;&gt; '?' AND SUBSTR(aCODEXTERN, 1, 1) = '=' THEN
      FILTRU_CODEXTERN := ' AND UPPER(CODEXTERN) = ''' ||  LTRIM(UPPER(aCODEXTERN), '=') || ''' ';
    END IF;


    IF coalesce(aCODINTERN, '?') &lt;&gt; '?' THEN
      FILTRU_CODINTERN := ' AND UPPER(CODINTERN) LIKE ' || '''%' || UPPER(aCODINTERN) || '%''';
    END IF;

    IF coalesce(aCODINTERN, '?') &lt;&gt; '?' AND SUBSTR(aCODINTERN, 1, 1) = '=' THEN
      FILTRU_CODINTERN := ' AND UPPER(CODINTERN) = ''' ||  LTRIM(UPPER(aCODINTERN), '=') || ''' ';
    END IF;


    IF coalesce(aDENCLASA, '?') &lt;&gt; '?' THEN
      FILTRU_CLASA := ' AND UPPER(CLASA) LIKE ' || '''%' || UPPER(aDENCLASA) || '%''';
    END IF;

    IF coalesce(aDENCLASA, '?') &lt;&gt; '?' AND SUBSTR(aDENCLASA, 1, 1) = '=' THEN
      FILTRU_CLASA := ' AND UPPER(CLASA) = ''' ||  LTRIM(UPPER(aDENCLASA), '=') || ''' ';
    END IF;


    IF coalesce(aCODGEST, 0) &lt;&gt; 0 THEN
      FILTRU_GEST := ' AND CODGEST = ' || aCODGEST::varchar;
    END IF;


    OPEN STOCCURSOR FOR execute S || FILTRU_ART || ' ' || FILTRU_CLASA || ' ' || FILTRU_GEST || FILTRU_CODEXTERN || ' ' || FILTRU_CODINTERN || ' ORDER BY DENOBIECT ';
  WME_Result := STOCCURSOR;
    RETURN;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_zineluc_sp_deleterecord</obj_name>
  <obj_hashval>26d2ecefdb5d9a208f0698172788c800</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_zineluc_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_ZINELUC_SP_LOCKRECORD( RecId);
  DELETE FROM ZINELUC1 WHERE CodZiNeluc = RecId;
  DELETE FROM ZINELUC  WHERE CodZiNeluc = RecId;
  PERFORM NotifyModif( 2, RecId, 'ZINELUC');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_comanda_validadaosminim</obj_name>
  <obj_hashval>78bd49e353c38f8c97f7372bd17d56b8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_comanda_validadaosminim(pcodcomanda1 numeric)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
DECLARE
  vRESULT        INTEGER := 1;
  PRETV          NUMERIC := 0;
  PUVV           NUMERIC := 0;
  PUAV           NUMERIC := 0;
  Adaos          NUMERIC := 0;
  CursBanca      NUMERIC  := 1;
  CursDoc        NUMERIC := 1;
  CursTransf     NUMERIC := 1;
  PMin           NUMERIC := 0;
  PUVV_min       VARCHAR(20);
  MonedaAdaosMin NUMERIC;
  MonedaDoc      NUMERIC;
  vCodObiect     NUMERIC;
  vAn            NUMERIC;
  vLuna          NUMERIC;
BEGIN
  SELECT C1.PU, C.Moneda,  C.Curs,  PKG_LIST_BASE_UTILS_GETCURSREFERINTA(xValidMonedaSitV, xValidBancaSitV, C.DataDoc), Coalesce(o.AdaosExceptie, 0), o.CodObiect
  INTO   PRETV, MonedaDoc, CursDoc, CursBanca                                                                         , PMin                        , vCodObiect
  FROM comanda1 c1
    LEFT JOIN comanda c ON c.codcomanda = c1.codcomanda
    LEFT JOIN nartobj o ON o.codobiect  = c1.codobiect
  WHERE CodComanda1 = pCodComanda1;

  IF PMin &lt;&gt; 0 THEN
    IF CursBanca = 0 THEN CursBanca  := 1; END IF;
    IF CursDoc   = 0 THEN CursDoc    := 1; END IF;
    CursTransf  := CursBanca;

    -- PretVanzare
    IF    MonedaDoc = 0 AND current_setting('PKG_comanda.xValidMonedaAdaosMin'  , TRUE)::NUMERIC = 2 THEN PUVV := PretV;
    ELSIF MonedaDoc = 0                              THEN PUVV := PretV / CursTransf;
    ELSIF                   current_setting('PKG_comanda.xValidMonedaAdaosMin'  , TRUE)::NUMERIC = 2 THEN PUVV := PretV * CursDoc;
    ELSE                                                  PUVV := PretV * CursDoc / CursBanca;
    END IF;

    -- PretAchiz, CodObiect etc.
    IF current_setting('PKG_comanda.xValidAdaosValPret'  , TRUE)::NUMERIC = 1 THEN
      SELECT PretReferinta INTO PUAV FROM NartObj1 WHERE CodObiect = vCodObiect AND xValidAL BETWEEN ALStart AND ALStop;
    ELSE
      SELECT
        CASE
          WHEN Sum(R.REST) = 0 THEN 0
          ELSE Sum(R.REST * (NS.PRET - COALESCE(NS.ADAOS,0))) / Sum(R.REST)
        END
      INTO PUAV
      FROM REZERVATS R
        LEFT JOIN COMANDA1 C1   ON C1.CODCOMANDA1 = R.CODCOMANDA1
        LEFT JOIN COMANDA  C    ON C.CODCOMANDA   = C1.CODCOMANDA
        LEFT JOIN NIRSTOC  NS   ON NS.CODNIRSTOC  = R.CODNIRSTOC AND NS.CODOBIECT = C1.CODOBIECT
        LEFT JOIN NIR      N    ON N.CODNIR       = NS.CODNIR
        LEFT JOIN IOART1   IOAL ON IOAL.CODIOART  = NS.CODIOART  AND C.AN*12+C.LUNA BETWEEN IOAL.ALStart AND IOAL.ALStop
      WHERE R.CODCOMANDA1 = pCodComanda1;
    END IF;

    -- Calcul Adaos
    IF    current_setting('PKG_comanda.xValidAdaosOrMarja'  , TRUE)::NUMERIC = 2 AND PUVV = 0 THEN Adaos := 0;
    ELSIF current_setting('PKG_comanda.xValidAdaosOrMarja'  , TRUE)::NUMERIC = 2              THEN Adaos := (1 - (PUAV / PUVV)) * 100;
    ELSIF                            PUAV = 0 THEN Adaos := 0;
    ELSE                                           Adaos := ((PUVV / PUAV) - 1) * 100;
    END IF;

--INSERT INTO x (test) VALUES ('PretV -&gt; '||PretV||' / Adaos -&gt; '||Adaos||' / vCodObiect -&gt; '||vCodObiect||' / PUAV -&gt; '||PUAV||' / PUVV -&gt; '||PUVV);

    -- Verificare depa¿ire adaos
    IF Adaos &lt; PMin THEN -- adaos invalid
      vRESULT := 0;
    END IF;
  END IF;

  RETURN vRESULT;
EXCEPTION
  WHEN OTHERS THEN RETURN 0;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_comanda_validsetconst</obj_name>
  <obj_hashval>7d8e53427ff855614870aa0cf6617d92</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_comanda_validsetconst(pan numeric, pluna numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  perform set_config('PKG_COMANDA.xValidAn'             , pAn::varchar           , false);
  perform set_config('PKG_COMANDA.xValidLuna'           , pLuna::varchar         , false);
  perform set_config('PKG_COMANDA.xValidAL'             , (pAn*12+pLuna)::varchar, false);
  perform set_config('PKG_COMANDA.xValidBancaSitV'      , 0::varchar             , false);
  perform set_config('PKG_COMANDA.xValidMonedaSitV'     , 0::varchar             , false);
  perform set_config('PKG_COMANDA.xValidMonedaAdaosMin' , 0::varchar             , false);
  perform set_config('PKG_COMANDA.xValidAdaosOrMarja'   , 0::varchar             , false);

  BEGIN perform set_config('PKG_COMANDA.xValidBancaSitV'      , fnc_GetValConstanta('BancaSitV',      pAn, pLuna), FALSE); EXCEPTION WHEN OTHERS THEN NULL; END;
  BEGIN perform set_config('PKG_COMANDA.xValidMonedaSitV'     , fnc_GetValConstanta('MonedaSitV',     pAn, pLuna), FALSE); EXCEPTION WHEN OTHERS THEN NULL; END;
  BEGIN perform set_config('PKG_COMANDA.xValidMonedaAdaosMin' , fnc_GetValConstanta('MonedaAdaosMin', pAn, pLuna), FALSE); EXCEPTION WHEN OTHERS THEN NULL; END;
  BEGIN perform set_config('PKG_COMANDA.xValidAdaosOrMarja'   , fnc_GetValConstanta('AdaosOrMarja',   pAn, pLuna), FALSE); EXCEPTION WHEN OTHERS THEN NULL; END;
  BEGIN perform set_config('PKG_COMANDA.xValidAdaosValPret'   , fnc_GetValConstanta('AdaosValPret',   pAn, pLuna), FALSE); EXCEPTION WHEN OTHERS THEN NULL; END;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>PROCEDURE</obj_type>
  <obj_name>pkg_contract_setcantcontor</obj_name>
  <obj_hashval>3646da680fa03d127d2cf55d8e06d52e</obj_hashval>
  <obj_text>CREATE OR REPLACE PROCEDURE pkg_contract_setcantcontor(IN acodcontract1 numeric, IN adata date)
 LANGUAGE plpgsql
AS $procedure$
DECLARE
  vCNT  NUMERIC;
  vCant NUMERIC;
BEGIN
  --Stef 02.11.2023
  SELECT Count(1) INTO vCNT
  FROM TMP_C1_CantContor
  WHERE CodContract1 = aCodContract1 AND DataRef = aData;

  IF vCNT = 0 THEN
    SELECT PKG_CONTRACT_getCantContor.WME_RESULT INTO vCant FROM PKG_CONTRACT_getCantContor(null, aCodContract1, aData);
    INSERT INTO TMP_C1_CantContor (
      CodContract1,
      DataRef,
      Cant,
      DataIni,
      IDXIni,
      DataFin,
      IDXFin
    )
    VALUES (
      NULLIF(current_setting('PKG_CONTRACT.pContor_IdxCC1' , true), '')::NUMERIC,
      NULLIF(current_setting('PKG_CONTRACT.pContor_DataR'  , true), '')::DATE,
      vCant,
      NULLIF(current_setting('PKG_CONTRACT.pContor_DataIni', true), '')::DATE,
      NULLIF(current_setting('PKG_CONTRACT.pContor_IdxIni' , true), '')::NUMERIC,
      NULLIF(current_setting('PKG_CONTRACT.pContor_DataFin', true), '')::DATE,
      NULLIF(current_setting('PKG_CONTRACT.pContor_IdxFin' , true), '')::NUMERIC
    );
  END IF;
END;
$procedure$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_dvi_total_count_semnif</obj_name>
  <obj_hashval>274a1f591ae1a2aa7e1e0407fed0a113</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_dvi_total_count_semnif(asemnif numeric)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
DECLARE
 nr NUMERIC(20, 7) := 0;
BEGIN
  --Florin 04.08.2025
 BEGIN
    SELECT CODOBLIGPIF INTO NR FROM TMP_OBLIGPIF_INITIAL WHERE SEMNIFICATIE = aSEMNIF;
    --SELECT COUNT(*) INTO NR FROM TMP_OBLIGPIF_INITIAL WHERE ICONT = aICONT AND NVL(CURS, 0) = NVL(aCURS, 0);
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  IF NR = 0 THEN
    NR := 1;
  END IF;
  RETURN NR;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_dvi_total_count_semnif_vama</obj_name>
  <obj_hashval>ca3edd81a67f953c8bc95c343667a10d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_dvi_total_count_semnif_vama(asemnif numeric)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
DECLARE
 nr NUMERIC(20, 7) := 0;
BEGIN
  BEGIN
    SELECT CODOBLIGPIF INTO NR FROM TMP_OBLIGVAMA_INITIAL WHERE SEMNIFICATIE = aSEMNIF;
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  IF NR = 0 THEN
    NR := 1;
  END IF;
  RETURN NR;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_dvi_total_valoare_semnif</obj_name>
  <obj_hashval>aca4d6ba3824a45615a3312080d875b0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_dvi_total_valoare_semnif(asemnif numeric)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
DECLARE
 total NUMERIC(20, 7) := 0;
BEGIN
  --Florin 04.08.2025
  BEGIN
    SELECT SUM(VALOARE) INTO TOTAL FROM TMP_OBLIGPIF_INITIAL WHERE SEMNIFICATIE = aSEMNIF;
    EXCEPTION WHEN OTHERS THEN TOTAL := 0;
  END;
  RETURN TOTAL;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_dvi_total_valoare_semnif_vama</obj_name>
  <obj_hashval>9ea6757e8449fc695e3d1f83139e4c52</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_dvi_total_valoare_semnif_vama(asemnif numeric)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
DECLARE
 total NUMERIC(20, 7) := 0;
BEGIN
  --Florin 04.08.2025
   BEGIN
    SELECT SUM(VALOARE) INTO TOTAL FROM TMP_OBLIGVAMA_INITIAL WHERE SEMNIFICATIE = aSEMNIF;
    EXCEPTION WHEN OTHERS THEN TOTAL := 0;
  END;
  RETURN TOTAL;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_eudr_updatenplinkintr</obj_name>
  <obj_hashval>2e54b2cdcde1891c5e264b18a63df7cb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_eudr_updatenplinkintr(acodintr numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
  DECLARE v_rec record;
BEGIN
  --Florin 12.12.2025 - sinc. Oracle
  for v_rec in (
    select l1.codlivr1, ns.codnirstoc
    from intrari1 i1
         inner join iesiri1 ies1 on ies1.codcmdint1 = i1.codcmdint1
         inner join nartobj o on o.codobiect = ies1.codobiect
         inner join tmp_manevra_liste t on t.filtru = 'CODBC' and t.valoare = ies1.codies::varchar
         inner join livr l on l.codies = ies1.codies
         inner join livr1 l1 on l1.codlivr = l.codlivr and ies1.codies1 = l1.codies1
         inner join nir n on n.codintr = i1.codintr
         inner join nirstoc ns on ns.codintr1 = i1.codintr1 and ns.codnir = n.codnir
    where i1.codintr = aCodIntr
  ) loop
    insert into nplink(codlivr1, codnirstoc)
    values (v_rec.codlivr1, v_rec.codnirstoc);
  end loop;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_eudr_updatepezi</obj_name>
  <obj_hashval>0b9d7cfc32fe554a0bc783ef86eeed4b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_eudr_updatepezi(arn_old character varying, avn_old character varying, arn character varying, avn character varying, adatadoc character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
  DECLARE v_rec record;
begin
  --Florin 17.12.2025 - null
  if arn_old = '' then arn_old := null; end if;
  if avn_old = '' then avn_old := null; end if;
  for v_rec in (
    select ns.codnirstoc
    from nirstoc ns
         INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
         INNER JOIN INTRARI I ON I.CODINTR = N.CODINTR
         INNER JOIN INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1 AND I1.CODINTR = I.CODINTR
         INNER JOIN NARTOBJ O ON O.CODOBIECT = NS.CODOBIECT
    WHERE I.DATADOC = TO_DATE(aDataDoc, 'dd.mm.yyyy') AND O.PRODUSPROPRIU = 2
          AND I.TIPDOC = 7 AND I.OPERAT = 1 AND coalesce(NS.EUDR_RN,'?') = coalesce(aRN_OLD,'?') AND coalesce(NS.EUDR_VN,'?') = coalesce(aVN_OLD,'?')
  ) loop
    update nirstoc ns set EUDR_RN = aRN, EUDR_VN = aVN
    where ns.codnirstoc in  (select ns1.codnirstoc from nirstoc1 ns1 where ns1.codnirstocorig = v_rec.codnirstoc);
  end loop;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_exportedi_setxmliatadata_linedr</obj_name>
  <obj_hashval>361c04d5facbf43d28e3db646845aace</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_exportedi_setxmliatadata_linedr(pcodies numeric, pidrtype character varying, pvalfieldi1 character varying, pvalfieldi character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vCntFieldI1 INTEGER;
  vCntFieldI  INTEGER;
  vOrd1       INTEGER;
  sVal        VARCHAR(200);
  sJoinI1EXT  VARCHAR(500);
  SJOINIEXT   VARCHAR(500);
  cSql        text;
BEGIN
  --Florin 18.06.2025 - sinc. Oracle
  SELECT Count(1)  INTO vCntFieldI1 FROM information_schema.columns WHERE TABLE_NAME = 'IESIRI1EXT' AND COLUMN_NAME = pValFieldI1;
  SELECT Count(1)  INTO vCntFieldI  FROM information_schema.columns WHERE TABLE_NAME = 'IESIRIEXT'  AND COLUMN_NAME = pValFieldI;
  SELECT Max(ORD1) INTO vOrd1       FROM TMP_IATA_LINEDR;
  vOrd1 := Coalesce(vOrd1, 0) + 1;

  IF vCntFieldI1 &gt; 0 OR vCntFieldI &gt; 0 THEN
    IF     vCntFieldI1 = 0 THEN
      sVal := 'IE.'||pValFieldI;
    ELSIF  vCntFieldI = 0 THEN
      sVal := 'I1E.'||pValFieldI1;
    ELSE
      sVal := 'Coalesce(I1E.'||pValFieldI1||', IE.'||pValFieldI||')';
    END IF;

    IF vCntFieldI1 &gt; 0 THEN
      sJoinI1EXT :='
          LEFT  JOIN IESIRI1EXT I1E ON I1E.CODIES1  = AE1.CODIES1';
    END IF;

    IF vCntFieldI &gt; 0 THEN
      SJOINIEXT :='
          LEFT  JOIN IESIRIEXT   IE ON IE.CODIES    = AE.CODIES';
    END IF;

    BEGIN
      EXECUTE '
        INSERT INTO TMP_IATA_LINEDR
        SELECT
          I1.CODIES1,
          :vOrd1     AS ORD1,
          '||sVal||' AS LDR01 ,--120/ItemDeliveryReferenceValue
          :pIDRType  AS LDR01A --121/ItemDeliveryReferenceType
        FROM IESIRI I
          INNER JOIN IESIRI1     I1 ON I1.CODIES    = I.CODIES
          LEFT  JOIN IESLINK   ILAE ON ILAE.CODIES1 = I1.CODIES1 AND ILAE.CODLINIEAVIZ IS NOT NULL
          LEFT  JOIN IESIRI1    AE1 ON AE1.CODIES1  = Coalesce(ILAE.CODLINIEAVIZ, I1.CODIES1) '||
          sJoinI1EXT ||'
          LEFT  JOIN IESIRI      AE ON AE.CODIES    = AE1.CODIES '||
          sJoinIEXT ||'
        WHERE I.CODIES = :pCodIes'
      USING vOrd1, pIDRType, pCodIes;
    EXCEPTION
      WHEN OTHERS THEN NULL;
    END;
  END IF;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_iesiri_total_valoare_semnif</obj_name>
  <obj_hashval>fb45f4627dccf305a0d0686ab5b09f5e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_iesiri_total_valoare_semnif(aicont numeric)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
DECLARE
 TOTAL NUMERIC(20, 7) := 0;
BEGIN
  --Florin 31.07.2025
  BEGIN
    SELECT SUM(VALOARE) INTO TOTAL FROM TMP_OBLIGPIF_INITIAL WHERE SEMNIFICATIE = aSEMNIF;
    EXCEPTION WHEN OTHERS THEN TOTAL := 0;
  END;
  RETURN TOTAL;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_importalteaplicatii_post_jurnal_cheltavans</obj_name>
  <obj_hashval>60cb69c606cec633397f33e481ea4646</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_importalteaplicatii_post_jurnal_cheltavans()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  NR NUMERIC;
  V_REC record;
  V_REC_SUB record;
BEGIN
  --Florin 04.09.2025
  FOR V_REC IN (SELECT * FROM TMP_JURNAL)
  LOOP
    DELETE FROM JURNAL WHERE CODDOC = V_REC.CODDOC AND TIPDOC = V_REC.TIPDOC;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_JURNAL1)
  LOOP
    DELETE FROM JURNAL1 WHERE CODDOC = V_REC.CODDOC AND TIPDOC = V_REC.TIPDOC;
  END LOOP;

 FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
   IF V_REC.CODJURNAL1 &gt; 0 THEN
    UPDATE JURNAL1
    SET
      CODDOC       = V_REC.CODDOC,
      TIPDOC       = V_REC.TIPDOC,
      INDEXLOCAL   = V_REC.INDEXLOCAL,

      CODBAZAD     = V_REC.CODBAZAD,
      ICONTBAZAD   = V_REC.ICONTBAZAD,
      TIPBAZAD     = V_REC.TIPBAZAD,
      CODBAZAC     = V_REC.CODBAZAC,
      ICONTBAZAC   = V_REC.ICONTBAZAC,
      TIPBAZAC     = V_REC.TIPBAZAC,

      CODDESCRD     = V_REC.CODDESCRD,
      ICONTD        = V_REC.ICONTD,
      TIPCONTD      = V_REC.TIPCONTD,
      ANALITICCONTD = V_REC.ANALITICCONTD,
      CODDESCRC     = V_REC.CODDESCRC,
      ICONTC        = V_REC.ICONTC,
      TIPCONTC      = V_REC.TIPCONTC,
      ANALITICCONTC = V_REC.ANALITICCONTC,
      GEST          = V_REC.GEST,
      VALOARE       = V_REC.VALOARE,
      VALOAREV      = V_REC.VALOAREV,
      OBS           = V_REC.OBS,
      AN            = V_REC.AN,
      LUNA          = V_REC.LUNA,
      SUBUNITATEA   = V_REC.SUBUNITATEA,
      CODCENTRU     = V_REC.CODCENTRU,
      CODANALIZANOD = V_REC.CODANALIZANOD,
      DATADOC       = V_REC.DATADOC,
      DOCUMENT      = V_REC.DOCUMENT,
      DIRTY         = V_REC.DIRTY
    WHERE
      CODJURNAL1 = V_REC.CODJURNAL1;
   ELSE
     INSERT INTO JURNAL1
     (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL,
      CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD,
      ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,
      TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC,
      GEST, VALOARE, VALOAREV, OBS, AN, LUNA,
      DIRTY, SUBUNITATEA, CODCENTRU, CODANALIZANOD,
      DATADOC, DOCUMENT )
     VALUES
     (NEXTVAL('SEQ_JURNAL1_CODJURNAL1'), V_REC.CODDOC, V_REC.TIPDOC, V_REC.INDEXLOCAL,
      V_REC.CODBAZAD,  V_REC.ICONTBAZAD,  V_REC.TIPBAZAD, V_REC.CODDESCRD,
      V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,
      V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC,
      V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA,
      V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.CODCENTRU, V_REC.CODANALIZANOD,
      V_REC.DATADOC, V_REC.DOCUMENT);
   END IF;
  END LOOP;
  FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
   IF V_REC.CODJURNAL &gt; 0 THEN
    UPDATE JURNAL
    SET
      CODDOC     = V_REC.CODDOC,
      TIPDOC     = V_REC.TIPDOC,
      INDEXLOCAL = V_REC.INDEXLOCAL,
      CONTD      = V_REC.CONTD,
      CONTC      = V_REC.CONTC,
      GEST       = V_REC.GEST,
      VALOARE    = V_REC.VALOARE,
      VALOAREV   = V_REC.VALOAREV,
      OBS        = V_REC.OBS,
      AN         = V_REC.AN,
      LUNA       = V_REC.LUNA,
      SUBUNITATEA= V_REC.SUBUNITATEA,
      CODCENTRU  = V_REC.CODCENTRU,
      CODANALIZANOD = V_REC.CODANALIZANOD,
      DATADOC    = V_REC.DATADOC,
      DOCUMENT   = V_REC.DOCUMENT
    WHERE
      CODJURNAL = V_REC.CODJURNAL;
   ELSE
     INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA,
     CODCENTRU, CODANALIZANOD,
     DATADOC, DOCUMENT)
     VALUES
     (NEXTVAL('SEQ_JURNAL_CODJURNAL'), V_REC.CODDOC, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA,
     V_REC.CODCENTRU, V_REC.CODANALIZANOD,
     V_REC.DATADOC, V_REC.DOCUMENT);
   END IF;
  END LOOP;
-- ACTUALIZARE RULAJE CONTURI
  FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP

    SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = getANLUCRU() AND LUNA = getLUNALUCRU();
    IF NR = 0 THEN
      INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
      VALUES
      (NEXTVAL('SEQ_NCONTRUL_CODCONTRUL'), V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
    END IF;

    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = 'D' THEN V_REC.VALOARE  ELSE 0 END),
      RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = 'C' THEN V_REC.VALOARE  ELSE 0 END),
      RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = 'D' THEN V_REC.VALOAREV ELSE 0 END),
      RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = 'C' THEN V_REC.VALOAREV ELSE 0 END)
    WHERE
     CODCONT = V_REC.CODCONT AND AN = getANLUCRU() AND LUNA = getLUNALUCRU();
     IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
     FOR V_REC_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = getANLUCRU() AND LUNA = getLUNALUCRU())
     LOOP
       SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;

       IF NR = 0 THEN
         INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA)
         VALUES
         (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,  0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
       END IF;
       UPDATE NCONTRULSUB
       SET
         RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = 'D' THEN V_REC.VALOARE  ELSE 0 END),
         RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = 'C' THEN V_REC.VALOARE  ELSE 0 END),
         RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = 'D' THEN V_REC.VALOAREV ELSE 0 END),
         RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = 'C' THEN V_REC.VALOAREV ELSE 0 END)
       WHERE
         CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
     END LOOP;
   END IF;
  END LOOP;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_importalteaplicatii_prepare_jurnal_cheltavans</obj_name>
  <obj_hashval>b9eedd794c13d8c20c81d14976a45d8a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_importalteaplicatii_prepare_jurnal_cheltavans(atipdoc numeric, acoddoc numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  V_REC record;
BEGIN
  --Florin 04.09.2025
  DELETE FROM TMP_CHELTAVANS;
  DELETE FROM TMP_CHELTAVANS1;
  DELETE FROM TMP_JURNAL;
  DELETE FROM TMP_JURNAL1;
  DELETE FROM TMP_RULAJ;
  IF aTIPDOC &lt; 19 THEN
    FOR V_REC IN (SELECT
                   AV.CODCHELTAVANS,
                   AV.CODINTR1,
                   AV.CODOBLIGPIF,
                   AV.CODNC1,
                   AV.ANINCEPUT,
                   AV.LUNAINCEPUT,
                   AV.CODIOART,
                   G.CODGEST,
                   G.DEN_GEST,
                   I.SUBUNITATEA,
                   I.NRDOC,
                   P.DEN_PART,
                   I1.OBS,
                   I.PREFIXDOC,
                   I.SERIADOC,
                   AV.DATASTART,
                   AV.DATAEND,
                   AV.IsVenit
                  FROM
                    INTRARI I
                    INNER JOIN NPART P ON P.CODPART = I.PARTENER
                    INNER JOIN INTRARI1 I1 ON I1.CODINTR = I.CODINTR
                    LEFT  JOIN NGEST G ON G.CODGEST = I1.GESTACT
                    INNER JOIN CHELTAVANS AV ON AV.CODINTR1 = I1.CODINTR1
                  WHERE
                    I.CODINTR = aCODDOC
                  )
    LOOP
      INSERT INTO TMP_CHELTAVANS(CODCHELTAVANS,CODINTR1, ANINCEPUT, LUNAINCEPUT, CODIOART, CODGEST, DEN_GEST, CODSUBUNIT, NRDOC,  DEN_PART, OBS, PREFIXDOC, SERIADOC, DATASTART, DATAEND, TIPINTERVAL, IsVenit )
                          VALUES(V_REC.CODCHELTAVANS, V_REC.CODINTR1, V_REC.ANINCEPUT, V_REC.LUNAINCEPUT, V_REC.CODIOART, V_REC.CODGEST, V_REC.DEN_GEST, V_REC.SUBUNITATEA, V_REC.NRDOC,  V_REC.DEN_PART, V_REC.OBS, V_REC.PREFIXDOC, V_REC.SERIADOC, V_REC.DATASTART, V_REC.DATAEND, 0, V_REC.IsVenit );
    END LOOP;
  ELSE
    FOR V_REC IN (SELECT
                   AV.CODCHELTAVANS,
                   AV.CODIES1,
                   AV.CODOBLIGPIF,
                   AV.CODNC1,
                   AV.ANINCEPUT,
                   AV.LUNAINCEPUT,
                   AV.CODIOART,
                   G.CODGEST,
                   G.DEN_GEST,
                   I.SUBUNITATEA,
                   I.NRDOC,
                   P.DEN_PART,
                   I1.OBS,
                   I.PREFIXDOC,
                   I.SERIADOC,
                   AV.DATASTART,
                   AV.DATAEND,
                   AV.IsVenit
                  FROM
                    IESIRI I
                    INNER JOIN NPART P ON P.CODPART = I.PARTENER
                    INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES
                    LEFT  JOIN NGEST G ON G.CODGEST = I1.GESTACT
                    INNER JOIN CHELTAVANS AV ON AV.CODIES1 = I1.CODIES1
                  WHERE
                    I.CODIES = aCODDOC
                  )
    LOOP
      INSERT INTO TMP_CHELTAVANS(CODCHELTAVANS,CODIES1, ANINCEPUT, LUNAINCEPUT, CODIOART, CODGEST, DEN_GEST, CODSUBUNIT, NRDOC,  DEN_PART, OBS, PREFIXDOC, SERIADOC, DATASTART, DATAEND, TIPINTERVAL, IsVenit )
                          VALUES(V_REC.CODCHELTAVANS, V_REC.CODIES1, V_REC.ANINCEPUT, V_REC.LUNAINCEPUT, V_REC.CODIOART, V_REC.CODGEST, V_REC.DEN_GEST, V_REC.SUBUNITATEA, V_REC.NRDOC,  V_REC.DEN_PART, V_REC.OBS, V_REC.PREFIXDOC, V_REC.SERIADOC, V_REC.DATASTART, V_REC.DATAEND, 0, V_REC.IsVenit );
    END LOOP;
  END IF;
   INSERT INTO TMP_CHELTAVANS1(CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, ANSTART, LUNASTART, AMO, CODCENTRU, CODGEST, CODANALIZANOD, DATAENDNOUA, DATAENDBLOCATA)
   SELECT CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, ANSTART, LUNASTART, AMO, CODCENTRU, CODGEST, CODANALIZANOD, DATAENDNOUA, DATAENDBLOCATA FROM CHELTAVANS1 AV1
   WHERE
     EXISTS (SELECT CODCHELTAVANS FROM TMP_CHELTAVANS WHERE CODCHELTAVANS = AV1.CODCHELTAVANS);
    UPDATE TMP_CHELTAVANS C
    SET
      TIPINTERVAL = 1
    WHERE
      DATASTART IS NOT NULL
      AND
    (
      DATAEND IS NOT NULL
      OR (SELECT COUNT(*) FROM TMP_CHELTAVANS1 C1 WHERE C1.CODCHELTAVANS = C.CODCHELTAVANS AND DATAENDNOUA IS NOT NULL) &gt; 0
    );
    FOR V_REC IN (SELECT * FROM TMP_CHELTAVANS1)
    LOOP
      IF V_REC.DATAENDNOUA IS NOT NULL THEN
        UPDATE TMP_CHELTAVANS
        SET
          DATAEND = V_REC.DATAENDNOUA
        WHERE
          CODCHELTAVANS = V_REC.CODCHELTAVANS;
      END IF;
    END LOOP;
END;

$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_intrari_total_count_semnif</obj_name>
  <obj_hashval>256617218a61fd1a38b40bef0e4a4360</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_intrari_total_count_semnif(asemnif numeric)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
DECLARE
 nr NUMERIC(20, 7) := 0;
BEGIN
  --Florin 31.07.2025
  BEGIN
    SELECT CODOBLIGPIF INTO NR FROM TMP_OBLIGPIF_INITIAL WHERE SEMNIFICATIE = aSEMNIF;
    --SELECT COUNT(*) INTO NR FROM TMP_OBLIGPIF_INITIAL WHERE ICONT = aICONT AND NVL(CURS, 0) = NVL(aCURS, 0);
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  RETURN nr;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_intrari_total_valoare_semnif</obj_name>
  <obj_hashval>970fab87fcf83dda062956f30bec4b20</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_intrari_total_valoare_semnif(aicont numeric)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
DECLARE
 TOTAL NUMERIC(20, 7) := 0;
BEGIN
  --Florin 31.07.2025
  BEGIN
    SELECT SUM(VALOARE) INTO TOTAL FROM TMP_OBLIGPIF_INITIAL WHERE SEMNIFICATIE = aSEMNIF;
    EXCEPTION WHEN OTHERS THEN TOTAL := 0;
  END;
  RETURN TOTAL;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>PROCEDURE</obj_type>
  <obj_name>pkg_list_base_comanda_baga_dinamic_cols</obj_name>
  <obj_hashval>80a03eedac2a5e8cdb1aa5fbbb26a559</obj_hashval>
  <obj_text>CREATE OR REPLACE PROCEDURE pkg_list_base_comanda_baga_dinamic_cols()
 LANGUAGE plpgsql
AS $procedure$
declare
  sInsert VARCHAR(10000);
  sSelect VARCHAR(10000);
BEGIN
  --Florin 29.04.2022 - sinc. Oracle (27.04.2022)
  --Florin 12.04.2022
  DELETE FROM tmp_dinamic_cols;

  delete FROM tmp_manevra_liste where filtru = 'CODPART';
  INSERT INTO TMP_MANEVRA_LISTE(FILTRU,VALOARE)
  select distinct 'CODPART', partener
  FROM
  (
  SELECT cf.partener::varchar partener
  FROM comanda c
       INNER JOIN comanda1 c1 ON c.codcomanda = c1.codcomanda
       INNER JOIN REZERVATS R ON R.CODCOMANDA1 = C1.CODCOMANDA1 AND R.CODCOMANDA1F &gt; 0
       INNER JOIN COMANDA1 CF1 ON CF1.CODCOMANDA1 = R.CODCOMANDA1F
       INNER JOIN COMANDA CF ON CF.CODCOMANDA = CF1.CODCOMANDA
       INNER JOIN NPART P ON P.CODPART = CF.PARTENER
  WHERE c.tipdoc in (18,65)
    AND c.datadoc BETWEEN current_setting('PKG_LIST_ALEGPERIOADA.gDataS', TRUE) AND current_setting('PKG_LIST_ALEGPERIOADA.gDataF', TRUE)
    AND C.ANULAT = 0 AND C.OPERAT = 1 AND (GETSUBUNITATE() = 1 OR C.SUBUNITATEA = GETSUBUNITATE())
  UNION ALL
   SELECT cf.partener::varchar partener
   FROM comanda c
       INNER JOIN comanda1 c1 ON c.codcomanda = c1.codcomanda
       INNER JOIN CMDLINK L ON L.CODLINIECOMANDA = C1.CODCOMANDA1
       INNER JOIN REZERVATS R ON R.CODCOMANDA1 = L.CODCOMANDA1 AND R.CODCOMANDA1F &gt; 0
       INNER JOIN COMANDA1 CF1 ON CF1.CODCOMANDA1 = R.CODCOMANDA1F
       INNER JOIN COMANDA CF ON CF.CODCOMANDA = CF1.CODCOMANDA
       INNER JOIN NPART P ON P.CODPART = CF.PARTENER
  WHERE c.tipdoc in (18,65)
    AND c.datadoc BETWEEN current_setting('PKG_LIST_ALEGPERIOADA.gDataS', TRUE) AND current_setting('PKG_LIST_ALEGPERIOADA.gDataF', TRUE)
    AND C.ANULAT = 0 AND C.OPERAT = 1 AND (GETSUBUNITATE() = 1 OR C.SUBUNITATEA = GETSUBUNITATE())) a_pg;

 INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, Cod, Ftype, fsize)
  SELECT fieldname, display, ROW_NUMBER(), cod, 2, 2500 from (
  select 'C'||partener::varchar fieldname, DEN_PART display, partener cod
  from (
  SELECT
    T.VALOARE partener, P.DEN_PART
  FROM TMP_MANEVRA_LISTE T
       INNER JOIN NPART P ON P.CODPART = T.VALOARE
  WHERE T.FILTRU = 'CODPART'
  ) d_pg
  union all
  select 'F'||partener::varchar fieldname, 'Intr.'||DEN_PART display, partener cod
  from (
  SELECT
    T.VALOARE partener, P.DEN_PART
  FROM TMP_MANEVRA_LISTE T
       INNER JOIN NPART P ON P.CODPART = T.VALOARE
  WHERE T.FILTRU = 'CODPART'
  ) b_pg
  ) c_pg;
END;
$procedure$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_compens_get_datadoc_from_var</obj_name>
  <obj_hashval>7b8b15dab8b13aad4c6ff351b1d29886</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_compens_get_datadoc_from_var()
 RETURNS date
 LANGUAGE plpgsql
AS $function$
declare
  xDataDoc date;
BEGIN
  --Florin 02.09.2025
  if (current_setting('PKG_LIST_BASE_COMPENS.xDataDoc', true) = '') then xDataDoc := null; else xDataDoc := current_setting('PKG_LIST_BASE_COMPENS.xDataDoc', true)::date; end if;
  return xDataDoc;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_compens_get_nrdoc_from_var</obj_name>
  <obj_hashval>5afa612d7b9e5ae74f8869a683b75486</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_compens_get_nrdoc_from_var()
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 24.09.2025 - fixat 66763
  --Florin 02.09.2025
  return (case when current_setting('PKG_LIST_BASE_COMPENS.xNrDoc', true) is null or current_setting('PKG_LIST_BASE_COMPENS.xNrDoc', true) = '' then null
    else current_setting('PKG_LIST_BASE_COMPENS.xNrDoc', true)::numeric end);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_compens_get_prefixdoc_from_var</obj_name>
  <obj_hashval>743bdcd52f582e62a1e353d236925f41</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_compens_get_prefixdoc_from_var()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  return current_setting('PKG_LIST_BASE_COMPENS.xPrefixDoc', true);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_docmonetare_getcodies</obj_name>
  <obj_hashval>232995ff597dec9b6d8838d1e5796a1d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_docmonetare_getcodies()
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
declare
  vCodDoc         varchar := current_setting('PKG_LIST_BASE_DOCMONETARE.vCodDoc', true);
BEGIN
  --Florin 18.08.2025
  return vCodDoc;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_eudr_completeazasemif</obj_name>
  <obj_hashval>e37ffad624cf36dad70c9556bdc55d1a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_eudr_completeazasemif(acodnirstoc numeric, acodnirstocs numeric, acantsemif numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  vSQL VARCHAR(10000);
  v_rec record;
BEGIN
  --Florin 12.12.2025
   for v_rec in (
    select ns1.tipdoc, ns.codintr1, l1.codlivr1, aCantSemif * l1.cant / nssp.cantnir cant, l1.codnirstoc
    from nirstoc1 nss1
         inner join nirstoc nssp on nssp.codnirstoc = nss1.codnirstoc
         inner join comanda1 c1 on c1.codcomanda1 = nss1.codcomanda1
         inner join nartobj objp on objp.codobiect = c1.codobiect
         inner join nplink lk on lk.codnirstoc = nssp.codnirstoc
         inner join livr1 l1 on l1.codlivr1 = lk.codlivr1
         inner join iesiri1 bc1 on bc1.codies1 = l1.codies1
         inner join iesiri bc on bc.codies = bc1.codies
         inner join livr l on l.codies = bc.codies and l1.codlivr = l.codlivr
         inner join nirstoc nsm on nsm.codnirstoc = l1.codnirstoc
         inner join nirstoc1 ns1 on ns1.codnirstoc = l1.codnirstoc
         inner join nirstoc ns on ns.codnirstoc = ns1.codnirstocorig
    where nss1.codnirstoc = aCodNirStocS
  ) loop
    if v_rec.tipdoc = 7 then
      perform pkg_list_base_eudr_CompleteazaSemif(acodnirstoc, v_rec.CodNirStoc, v_rec.cant);
    else
      insert into tmp_lst_eudr(codnirstoc, codlivr1, cant)
      values(acodnirstoc, v_rec.codlivr1, v_rec.cant);
    end if;
  end loop;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_eudr_createtmp</obj_name>
  <obj_hashval>8d4e269621c6b420c745bcfa20a5dc0b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_eudr_createtmp()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  vSQL VARCHAR(10000);
  sFiltruNP varchar(500);
  v_rec record;
BEGIN
  --Florin 12.12.2025
   delete from tmp_lst_eudr;
   if current_setting('PKG_LIST_BASE_EUDR.vNP', true)::boolean then
    -- produse + semifabricate
    for v_rec in (
      select ns1.tipdoc, np1.codintr1, L1.codlivr1, l1.codnirstoc codnirstocS, l1.cant, nsp.codnirstoc
      from intrari np
           inner join intrari1 np1 on np1.codintr = np.codintr
           inner join nirstoc nsp on nsp.codintr1 = np1.codintr1
           inner join nartobj objp on objp.codobiect = np1.codobiect
           inner join nart a on objp.codarticol = a.codarticol
           inner join nplink lk on lk.codnirstoc = nsp.codnirstoc
           inner join livr1 l1 on l1.codlivr1 = lk.codlivr1
           inner join iesiri1 bc1 on bc1.codies1 = l1.codies1
           inner join iesiri bc on bc.codies = bc1.codies
           inner join livr l on l.codies = bc.codies and l1.codlivr = l.codlivr
           inner join nirstoc1 ns1 on ns1.codnirstoc = l1.codnirstoc
           inner join nirstoc ns on ns.codnirstoc = ns1.codnirstocorig
           inner join nartobj objm on objm.codobiect = bc1.codobiect
      where np.tipdoc = 7 and np.operat = 1 and coalesce(np.anulat,0) = 0 and np1.codcmdint1 &gt; 0
            and np.datadoc between to_date(current_setting('pkg_list_base_eudr.vDataIni', true), 'dd.mm.yyyy') and to_date(current_setting('pkg_list_base_eudr.vDataFin', true), 'dd.mm.yyyy')
            and objp.produspropriu in (1,2)
            and (current_setting('pkg_list_base_eudr.vAllCls', true)::numeric = 1 or exists (select t.valoare from tmp_manevra_liste t where t.filtru = 'CODCLASEA' and t.valoare = a.clasa::varchar))
            and (current_setting('pkg_list_base_eudr.vAllArt', true)::numeric = 1 or exists (select t.valoare from tmp_manevra_liste t where t.filtru = 'CODOBIECT' and t.valoare = objp.codobiect::varchar))
            and (current_setting('pkg_list_base_eudr.vTipA', true)::numeric = 0 or current_setting('pkg_list_base_eudr.vTipA', true)::numeric = 1 and objm.CERTIF_DDS = 1 or current_setting('pkg_list_base_eudr.vTipA', true)::numeric = 2 and ns.eudr_rn = current_setting('pkg_list_base_eudr.vEUDRA', true))
            and (current_setting('pkg_list_base_eudr.vTipV', true)::numeric = 0 or current_setting('pkg_list_base_eudr.vTipV', true)::numeric = 1 and objp.CERTIF_DDS = 1 or current_setting('pkg_list_base_eudr.vTipV', true)::numeric = 2 and nsp.eudr_rn = current_setting('pkg_list_base_eudr.vEUDRV', true))
    ) loop
      if v_rec.tipdoc = 7 then
        perform pkg_list_base_eudr_CompleteazaSemif(v_rec.codnirstoc, v_rec.CodNirStocS, v_rec.cant);
      else
        insert into tmp_lst_eudr(codnirstoc, codlivr1, cant)
        values(v_rec.codnirstoc, v_rec.codlivr1, v_rec.cant);
      end if;
    end loop;
  else
    -- produse
    for v_rec in (
      select ns1.tipdoc, np1.codintr1, l1.codlivr1, l1.codnirstoc codnirstocS, l1.cant, nsp.codnirstoc
      from intrari np
           inner join intrari1 np1 on np1.codintr = np.codintr
           inner join nirstoc nsp on nsp.codintr1 = np1.codintr1
           inner join nartobj objp on objp.codobiect = np1.codobiect
           inner join nart a on objp.codarticol = a.codarticol
           inner join nplink lk on lk.codnirstoc = nsp.codnirstoc
           inner join livr1 l1 on l1.codlivr1 = lk.codlivr1
           inner join iesiri1 bc1 on bc1.codies1 = l1.codies1
           inner join iesiri bc on bc.codies = bc1.codies
           inner join livr l on l.codies = bc.codies and l1.codlivr = l.codlivr
           inner join nirstoc1 ns1 on ns1.codnirstoc = l1.codnirstoc
           inner join nirstoc ns on ns.codnirstoc = ns1.codnirstocorig
           inner join nartobj objm on objm.codobiect = bc1.codobiect
      where np.tipdoc = 7 and np.operat = 1 and coalesce(np.anulat,0) = 0 and np1.codcmdint1 &gt; 0
            and np.datadoc between to_date(current_setting('pkg_list_base_eudr.vDataIni', true),'dd.mm.yyyy') and to_date(current_setting('pkg_list_base_eudr.vDataFin', true), 'dd.mm.yyyy')
            and objp.produspropriu = 2
            and (current_setting('pkg_list_base_eudr.vAllCls', true)::numeric = 1 or exists (select t.valoare from tmp_manevra_liste t where t.filtru = 'CODCLASEA' and t.valoare = a.clasa::varchar))
            and (current_setting('pkg_list_base_eudr.vAllArt', true)::numeric = 1 or exists (select t.valoare from tmp_manevra_liste t where t.filtru = 'CODOBIECT' and t.valoare = objp.codobiect::varchar))
            and (current_setting('pkg_list_base_eudr.vTipA', true)::numeric = 0 or current_setting('pkg_list_base_eudr.vTipA', true)::numeric = 1 and objm.CERTIF_DDS = 1 or current_setting('pkg_list_base_eudr.vTipA', true)::numeric = 2 and ns.eudr_rn = current_setting('pkg_list_base_eudr.vEUDRA', true))
            and (current_setting('pkg_list_base_eudr.vTipV', true)::numeric = 0 or current_setting('pkg_list_base_eudr.vTipV', true)::numeric = 1 and objp.CERTIF_DDS = 1 or current_setting('pkg_list_base_eudr.vTipV', true)::numeric = 2 and nsp.eudr_rn = current_setting('pkg_list_base_eudr.vEUDRV', true))
    ) loop
      if v_rec.tipdoc = 7 then
        perform pkg_list_base_eudr_CompleteazaSemif(v_rec.codnirstoc, v_rec.CodNirStocS, v_rec.cant);
      else
        insert into tmp_lst_eudr(codnirstoc, codlivr1, cant)
        values(v_rec.codnirstoc, v_rec.codlivr1, v_rec.cant);
      end if;
    end loop;
  end if;

END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_eudr_processlist</obj_name>
  <obj_hashval>a3e0aae1b0848d96fb668b4158e29c67</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_eudr_processlist(tmpname character varying, alistid numeric DEFAULT 0, alistver numeric DEFAULT 0)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  sInsert       varchar := '';
  gUserFields   VARCHAR := '';
  gUserAlias    VARCHAR := '';
  gNullAlias    VARCHAR := '';
  gSuplJoins    VARCHAR := '';
  gSuplCols     varchar := 'tmp_lst_eudr t, intrari i, intrari1 i1, livr1 l1';
BEGIN
  --Florin 15.12.2025
  call pkg_list_struct_startsuplcols();
  call pkg_list_struct_getsuplcols(aLISTID, alistver, gUserFields, gUserAlias , gNullAlias , gSuplJoins , gSuplCols);
  PERFORM set_config('pkg_list_base_eudr.gSuplCols',gSuplCols,false);
  gUserFields := coalesce(gUserFields,'');
  gUserAlias  := coalesce(gUserAlias,'') ;
  gNullAlias  := coalesce(gNullAlias,'') ;
  gSuplJoins  := coalesce(gSuplJoins,'') ;
  gSuplCols   := coalesce(gSuplCols,'')  ;

  perform pkg_list_base_eudr_CreateTmp();

  sInsert:=
  'INSERT INTO '||tmpName||'(
     NAV_CodDoc,
     NAV_TipDoc,
     RegNrV,
     VerNrV,
     DataProd,
     Produs,
     CodExternV,
     UMV,
     CantV,
     Material,
     CodExternA,
     UMA,
     CantA,
     RegNrA,
     VerNrA,
     Furnizor'||gUserFields||'
   )
  SELECT
     i.codintr NAV_CodDoc,
     i.tipdoc NAV_TipDoc,
     ns.EUDR_RN RegNrV,
     ns.EUDR_VN VerNrV,
     i.datadoc DataProd,
     objp.denumire Produs,
     objp.codextern CodExternV,
     ump1.den_um1 UMV,
     ns.cantnir CantV,
     objm.denumire Material,
     objm.codextern CodExternA,
     umm1.den_um1 UMA,
     t.cant CantA,
     nsm.EUDR_RN RegNrA,
     nsm.EUDR_VN VerNrA,
     p.den_part Furnizor '||gUserAlias||'
  FROM tmp_lst_eudr t
       inner join nirstoc ns on ns.codnirstoc = t.codnirstoc
       inner join intrari1 i1 on ns.codintr1 = i1.codintr1
       inner join intrari i on i.codintr = i1.codintr
       inner join nir n on n.codintr = i.codintr and ns.codnir = n.codnir
       inner join nartobj objp on objp.codobiect = i1.codobiect
       inner join num1 ump1 on ump1.codum1 = i1.umsec
       inner join livr1 l1 on t.codlivr1 = l1.codlivr1
       inner join iesiri1 ies1 on ies1.codies1 = l1.codies1
       inner join nartobj objm on objm.codobiect = ies1.codobiect
       inner join num1 umm1 on umm1.codum1 = ies1.umsec
       inner join nirstoc nsm on nsm.codnirstoc = l1.codnirstoc
       left join npart p on p.codpart = nsm.furn '||
       gSuplJoins;

  perform LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_eudr_setparams</obj_name>
  <obj_hashval>22b5f1ea52ac118d16b85e6fd486cce4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_eudr_setparams(pdupadata numeric DEFAULT 1, pdataini character varying DEFAULT NULL::character varying, pdatafin character varying DEFAULT NULL::character varying, plunaanini integer DEFAULT 0, plunaanfin integer DEFAULT 0, pnp integer DEFAULT 0, pies integer DEFAULT 0, ptipa integer DEFAULT 0, ptipv integer DEFAULT 0, peudra character varying DEFAULT NULL::character varying, peudrv character varying DEFAULT NULL::character varying, pallcls numeric DEFAULT 1, pallart numeric DEFAULT 1, pcodjob1 numeric DEFAULT 0)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  vSQL VARCHAR(10000);
  v_rec record;
BEGIN
  --Florin 12.12.2025
  PERFORM set_config('PKG_ESTIMARIPROD.vDupaData',  (pDupaData = 1)::varchar, false);
  PERFORM set_config('PKG_ESTIMARIPROD.vDataIni',   to_date(pDataIni,'dd.mm.yyyy')::varchar, false);
  PERFORM set_config('PKG_ESTIMARIPROD.vDataFin',   to_date(pDataFin,'dd.mm.yyyy')::varchar, false);
  PERFORM set_config('PKG_ESTIMARIPROD.vLunaAnIni', NVL(pLunaAnIni,0)::varchar, false);
  PERFORM set_config('PKG_ESTIMARIPROD.vLunaAnFin', NVL(pLunaAnFin,0)::varchar, false);
  PERFORM set_config('PKG_ESTIMARIPROD.vNP',        (pNP = 1)::varchar, false);
  PERFORM set_config('PKG_ESTIMARIPROD.vIes',       (pIes = 1)::varchar, false);
  PERFORM set_config('PKG_ESTIMARIPROD.vTipA',      pTipA::varchar, false);
  PERFORM set_config('PKG_ESTIMARIPROD.vTipV',      pTipV::varchar, false);
  PERFORM set_config('PKG_ESTIMARIPROD.vEUDRA',     pEUDRA, false);
  PERFORM set_config('PKG_ESTIMARIPROD.vEUDRV',     pEUDRV, false);
  PERFORM set_config('PKG_ESTIMARIPROD.vAllCls',    pAllCls::varchar, false);
  PERFORM set_config('PKG_ESTIMARIPROD.vAllArt',    pAllArt::varchar, false);
  IF NVL(pCodJob1,0) &gt; 0 THEN
    perform PKG_ORA_LISTS_SET_INTERVAL_DINAMIC(pCODJOB1, vDataIni, vDataFin, vLunaAnIni, vLunaAnFin);
  END IF;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_pkg_list_base_restlistgest_setparams</obj_name>
  <obj_hashval>ad317a84f71ed030d04c6edb4e833283</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_pkg_list_base_restlistgest_setparams(acodgest numeric, acodrestcmd numeric, aid numeric, aver numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 20.05.2025
  PERFORM set_config('pkg_list_base_pkg_list_base_restlistgest.CODGEST', aCodGest::varchar, false);
  PERFORM set_config('pkg_list_base_pkg_list_base_restlistgest.CODRESTCMD', aCODRESTCMD::varchar, false);
  PERFORM set_config('pkg_list_base_pkg_list_base_restlistgest.ID',aID::varchar, false);
  PERFORM set_config('pkg_list_base_pkg_list_base_restlistgest.CODGEST', aVER::varchar, false);
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_prodestprj_estimeaza</obj_name>
  <obj_hashval>338a87cc9f98cc9d501439399b4fcd36</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_prodestprj_estimeaza()
 RETURNS boolean
 LANGUAGE plpgsql
AS $function$
DECLARE
vCod NUMERIC(20);
vCodObiect NUMERIC(20);
vRez boolean;
vCant NUMERIC(20,7);
v_rec record;
BEGIN
  --Florin 18.12.2025 - fixat 67614
  --Florin 17.06.2025 - sinc. Oracle
  vRez := True;
  begin
    select codproiectnod, codobiect into vCod, vCodObiect from proiectnod where nodoriginal = 0 and codproiect = PKG_LIST_BASE_NAPROVIZ1.CodProiect;
  exception when others then vCod := 0;
  end;
  if vCod &gt; 0 then
    begin
      select cant into vCant from tmp_stocreal where codobiect = vCodObiect;
    exception when others then vCant := 0;
    end;
    vCant := current_setting('PKG_LIST_BASE_NAPROVIZ1.Cant', true)::numeric - vCant;
    if vCant &lt; 0 then vCant := 0; end if;
    if vCant &gt; 0 then
      PERFORM pkg_list_base_prodestprj_EstimeazaNod(vCod, current_setting('PKG_LIST_BASE_NAPROVIZ1.Cant', true)::numeric, vRez);
    end if;
    if vrez then
      update tmp_proiectnod_lans set Lansat = coalesce(lansat,0) + current_setting('PKG_LIST_BASE_NAPROVIZ1.Cant', true)::numeric, NecesarAut = coalesce(NecesarAut,0) + vCant where codproiectnod = vCod;
      if vCant = 0 then
        update tmp_proiectnod_lans set Necesar = current_setting('PKG_LIST_BASE_NAPROVIZ1.Cant', true)::numeric where codproiectnod = vCod;
        update tmp_stocreal set cant = cant - current_setting('PKG_LIST_BASE_NAPROVIZ1.Cant', true)::numeric where codobiect = vCodobiect;
      end if;
      for v_rec in (select codproiectnod, totalrezervat, totalrealizat, codobiect, cant, tip
                    from tmp_proiectnod_lans
                    where codproiectnod &lt;&gt; vCod
                    order by indexparinte) loop
        if v_rec.totalrezervat &gt; 0 then
          update tmp_stocreal set cant = cant - v_rec.totalrezervat where codobiect = v_rec.codobiect;
          update tmp_proiectnod_lans set necesar = coalesce(necesar,0) + v_rec.totalrezervat where codproiectnod = v_rec.Codproiectnod;
          if v_rec.tip = 1 then
            update tmp_proiectnod_lans set Lansat = coalesce(lansat,0) + v_rec.totalrezervat where codproiectnod = v_rec.codproiectnod;
          end if;
        end if;
        if v_rec.totalrealizat &gt; 0 then
          update tmp_proiectnod_lans set Lansat = coalesce(lansat,0) + v_rec.totalrealizat, NecesarAut = coalesce(NecesarAut,0) + v_rec.totalrealizat where codproiectnod = v_rec.codproiectnod;
        end if;
      end loop;
    end if;
    return vRez;
  else
    return False;
  end if;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_prodestprj_estimeazanod</obj_name>
  <obj_hashval>b66eb3d6328e50eb9b07ba8029199340</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_prodestprj_estimeazanod(acodproiectnod numeric, acant numeric, arez boolean)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
aStoc NUMERIC(20,7);
aProd NUMERIC(20,7);
v_rec record;
begin
  for v_rec in (select n.codproiectnod, n.codobiect, aCant*n.cant cant, n.cant cant_p, n.tip
                from tmp_proiectnod_lans n
                     inner join tmp_proiectnod_lans p on p.codproiectnod = n.nodoriginal
                where n.nodoriginal = aCodProiectNod
               ) loop
    if v_rec.tip = 3 then
      begin
        select coalesce(cant,0) - coalesce(cantum1,0) into aStoc from tmp_stocreal where codobiect = v_rec.codobiect;
      exception when others then aStoc := 0;
      end;
      if aStoc &lt; v_rec.cant then
        aRez := False;
        Exit;
      else
        update tmp_proiectnod_lans set totalrezervat = v_rec.cant where codproiectnod = v_rec.codproiectnod;
        update tmp_stocreal set cantum1 = coalesce(cantum1,0) + v_rec.cant where codobiect = v_rec.codobiect;
      end if;
    else
      begin
        select coalesce(cant,0) - coalesce(cantum1,0) into aStoc from tmp_stocreal where codobiect = v_rec.codobiect;
      exception when others then aStoc := 0;
      end;
      if aStoc &gt; 0 then
        -- am stoc
        if aStoc &gt;= v_rec.cant then
          -- am stoc suficient
          update tmp_proiectnod_lans set totalrezervat = v_rec.cant where codproiectnod = v_rec.codproiectnod;
          update tmp_stocreal set cantum1 = coalesce(cantum1,0) + v_rec.cant where codobiect = v_rec.codobiect;
        else
          -- stoc insuficient, vad cat se poate aloca
          aProd := Trunc(aStoc/v_rec.cant_p);
          if aProd &gt; 0 then
            update tmp_proiectnod_lans set totalrezervat = aProd * v_rec.cant_p where codproiectnod = v_rec.codproiectnod;
            update tmp_stocreal set cantum1 = coalesce(cantum1,0) + aProd * v_rec.cant_p where codobiect = v_rec.codobiect;
            PERFORM pkg_list_base_prodestprj_EstimeazaNod(v_rec.CodProiectNod, aCant - aProd, aRez);
            if not aRez then
              Exit;
            else
              update tmp_proiectnod_lans set totalrealizat = (aCant - aProd)*v_rec.cant_p where codproiectnod = v_rec.codproiectnod;
            end if;
          else
            PERFORM pkg_list_base_prodestprj_EstimeazaNod(v_rec.CodProiectNod, aCant, aRez);
            if not aRez then
              Exit;
            end if;
          end if;
        end if;
      else
        PERFORM pkg_list_base_prodestprj_EstimeazaNod(v_rec.CodProiectNod, aCant, aRez);
        if not aRez then
          Exit;
        else
          update tmp_proiectnod_lans set totalrealizat = v_rec.cant where codproiectnod = v_rec.codproiectnod;
        end if;
      end if;
    end if;
  end loop;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_prodestprj_rezolva</obj_name>
  <obj_hashval>7f10e0728357bfae3fa7b1e3eb0526dd</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_prodestprj_rezolva()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  rez boolean;
  aCod NUMERIC(20);
  aCant NUMERIC(20,7);
  v_rec record;
begin
  begin
    select codproiectnod, cant into strict aCod, aCant from tmp_proiectnod_lans where coalesce(nodoriginal,0) = 0;
  exception when others then aCod := 0;
  end;
  rez := True;
  while rez loop
    rez := pkg_list_base_prodestprj_RezProd(aCod, rez);
    if rez then
      update tmp_proiectnod_lans set Lansat = coalesce(lansat,0) + aCant, NecesarAut = coalesce(NecesarAut,0) + aCant where codproiectnod = aCod;
      for v_rec in (select codproiectnod, totalrezervat, totalrealizat, codobiect, cant, tip
                    from tmp_proiectnod_lans
                    where codproiectnod &lt;&gt; aCod
                    order by indexparinte) loop
        if v_rec.totalrezervat &gt; 0 then
          update tmp_stocreal set cant = cant - v_rec.totalrezervat where codobiect = v_rec.codobiect;
          update tmp_proiectnod_lans set necesar = coalesce(necesar,0) + v_rec.totalrezervat where codproiectnod = v_rec.Codproiectnod;
          if v_rec.tip = 1 then
            update tmp_proiectnod_lans set Lansat = coalesce(lansat,0) + v_rec.totalrezervat where codproiectnod = v_rec.codproiectnod;
          end if;
        end if;
        if v_rec.totalrealizat &gt; 0 then
          update tmp_proiectnod_lans set Lansat = coalesce(lansat,0) + v_rec.totalrealizat, NecesarAut = coalesce(NecesarAut,0) + v_rec.totalrealizat where codproiectnod = v_rec.codproiectnod;
        end if;
      end loop;
    end if;
    update tmp_proiectnod_lans set totalrezervat = 0, totalrealizat = 0;
    update tmp_stocreal set cantum1 = 0;
  end loop;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_prodestprj_rezprod</obj_name>
  <obj_hashval>1e49b4dd4fa5724246c28a527370f12d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_prodestprj_rezprod(acodproiectnod numeric, arez boolean)
 RETURNS boolean
 LANGUAGE plpgsql
AS $function$
declare
  aStoc NUMERIC(20,7);
  rez boolean;
  v_rec record;
begin
  for v_rec in (select codproiectnod, codobiect, cant, tip
                from tmp_proiectnod_lans
                where nodoriginal = aCodProiectNod
               ) loop
    if v_rec.tip = 3 then
      begin
        select coalesce(cant,0) - coalesce(cantum1,0) into STRICT aStoc from tmp_stocreal where codobiect = v_rec.codobiect;
      exception when others then aStoc := 0;
      end;
      if aStoc &lt; v_rec.cant then
        rez := False;
        Exit;
      else
        update tmp_proiectnod_lans set totalrezervat = v_rec.cant where codproiectnod = v_rec.codproiectnod;
        update tmp_stocreal set cantum1 = coalesce(cantum1,0) + v_rec.cant where codobiect = v_rec.codobiect;
      end if;
    else
      begin
        select coalesce(cant,0) - coalesce(cantum1,0) into aStoc from tmp_stocreal where codobiect = v_rec.codobiect;
      exception when others then aStoc := 0;
      end;
      if aStoc &lt; v_rec.cant then
        -- nu am stoc, merg pe productie
        rez := pkg_list_base_prodestprj_RezProd(v_rec.CodProiectNod, aRez);
        if not rez then
          Exit;
        else
          update tmp_proiectnod_lans set totalrealizat = v_rec.cant where codproiectnod = v_rec.codproiectnod;
        end if;
      else
        -- am stoc
        update tmp_proiectnod_lans set totalrezervat = v_rec.cant where codproiectnod = v_rec.codproiectnod;
        update tmp_stocreal set cantum1 = coalesce(cantum1,0) + v_rec.cant where codobiect = v_rec.codobiect;
      end if;
    end if;
  end loop;
  RETURN rez;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_prodestprj_test</obj_name>
  <obj_hashval>44451d54efc89d9894bbb82c036b3639</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_prodestprj_test()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vSelStocReal VARCHAR(5000);
  NivelMaxim numeric(5);
  CanProd boolean;
  vStoc numeric(20,7);
  i numeric(5);
  v_rec record;
  v_mat record;
BEGIN
  --Florin 03.06.2025
   begin
    select max(nivel) into NivelMaxim from tmp_proiectnod_lans;
  exception when others then NivelMaxim := -1;
  end;
  CanProd := True;
  while CanProd loop
    for i in reverse 0..NivelMaxim loop
      for v_rec in (select tip, codproiectnod, cant, codobiect
                    from tmp_proiectnod_lans
                    where nivel = i and tip in (0,1)
                    order by indexparinte
                   ) loop
        for v_mat in (
          select tip, codproiectnod, cant, necesar, codobiect
          from tmp_proiectnod_lans
          where nodoriginal = v_rec.codproiectnod and tip = 3
        ) loop
          if v_mat.tip = 3 then
            --material, caut sa vad daca mai am stoc
            begin
              select cant into vStoc from tmp_stocreal where codobiect = v_mat.codobiect;
            exception when others then vStoc := 0;
            end;
            if vStoc &lt; v_mat.cant then
              CanProd := False;
              Exit;
            else
              update tmp_proiectnod_lans set necesar = coalesce(necesar,0) + v_mat.cant where codproiectnod = v_mat.Codproiectnod;
              update tmp_stocreal set cant = cant - v_mat.cant where codobiect = v_mat.codobiect;
            end if;
          end if;
        end loop;
        if not CanProd then
          Exit;
        else
          update tmp_proiectnod_lans set Lansat = coalesce(lansat,0) + v_rec.cant, NecesarAut = coalesce(NecesarAut,0) + v_rec.cant where codproiectnod = v_rec.codproiectnod;
        end if;
      end loop;
      if not CanProd then
        Exit;
      end if;
    end loop;
  end loop;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_restsitlistgest_processlist</obj_name>
  <obj_hashval>fd95d1fd1d7d1efa08b1a4f272f1f6b7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_restsitlistgest_processlist(tmpname character varying, alistid numeric DEFAULT 0, alistver numeric DEFAULT 0)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  S               varchar := '';
  gSuplCols        VARCHAR := 'RESTCMD1 R1, NARTOBJ O, NART A, NUM1 U1';
  gUserFields      VARCHAR := COALESCE(NULLIF(current_setting('pkg_list_base_restsitlistgest.gUserFields', true),''),'');
  gUserAlias       VARCHAR := COALESCE(NULLIF(current_setting('pkg_list_base_restsitlistgest.gUserAlias' , true),''),'');
  gNullAlias       VARCHAR := COALESCE(NULLIF(current_setting('pkg_list_base_restsitlistgest.gNullAlias' , true),''),'');
  gSuplJoins       VARCHAR := COALESCE(NULLIF(current_setting('pkg_list_base_restsitlistgest.gSuplJoins' , true),''),'');
BEGIN
   --Florin 21.05.2025
  call pkg_list_struct_startsuplcols();
  CALL pkg_list_struct_getsuplcols(aLISTID, alistver, gUserFields, gUserAlias, gNullAlias, gSuplJoins, gSuplCols);
  gUserFields := coalesce(gUserFields,'');
  gUserAlias  := coalesce(gUserAlias ,'');
  gNullAlias  := coalesce(gNullAlias ,'');
  gSuplJoins  := coalesce(gSuplJoins ,'');
  gSuplCols   := coalesce(gSuplCols  ,'');
  PERFORM set_config('pkg_list_base_restsitlistgest.gSuplCols'  ,gSuplCols  ,false);
  PERFORM set_config('pkg_list_base_restsitlistgest.gUserFields',gUserFields,false);
  PERFORM set_config('pkg_list_base_restsitlistgest.gUserAlias' ,gUserAlias ,false);
  PERFORM set_config('pkg_list_base_restsitlistgest.gNullAlias' ,gNullAlias ,false);
  PERFORM set_config('pkg_list_base_restsitlistgest.gSuplJoins' ,gSuplJoins ,false);

  S := 'INSERT INTO ' || TMPNAME || '(den_obj, cant, observatii, den_gest, dataora, ospatar, nr_comanda, masa, sala'||gUserFields||') ' || CHR(13) ||
  'SELECT '                                                    ||  CHR(13) ||
  '  obj.denumire as den_obj, '                                ||  CHR(13) ||
  '  lg.cant as cant, '                                        ||  CHR(13) ||
  '  lg.obs as observatii, '                                   ||  CHR(13) ||
  '  ng.den_gest as den_gest, '                                ||  CHR(13) ||
  '  lg.dataora as dataora, '                                  ||  CHR(13) ||
  '  prs.NUME || '' '' ||  prs.PRENUME AS OSPATAR, '           ||  CHR(13) ||
  '  rc.nrcomanda as nr_comanda, '                             ||  CHR(13) ||
  '  coalesce(m.textafisare,to_char(m.indexlocal)) as masa, '  ||  CHR(13) ||
  '  s.denumire as sala  ' ||gUserAlias                        ||CHR(13)||
  'FROM '                                                      ||  CHR(13) ||
  '  RESTLISTGEST lg'                                          ||  CHR(13) ||
  '  join RESTCMD1 rc1 on lg.codrestcmd1 = rc1.codrestcmd1 '   ||  CHR(13) ||
  '  join RESTCMD rc on rc.codrestcmd = rc1.codrestcmd'        ||  CHR(13) ||
  '  join NARTOBJ obj on obj.codobiect = rc1.codobiect'        ||  CHR(13) ||
  '  join MESE m on m.codmasa = rc.codmasa'                    ||  CHR(13) ||
  '  join SALI s ON s.codsala      = m.codsala'                ||  CHR(13) ||
  '  left join NGEST ng on ng.codgest = rc1.codgest'           ||  CHR(13) ||
  '  left join OSPATARI osp on osp.cod = rc.codospatar'        ||  CHR(13) ||
  '  left join NPERS prs on prs.codpers = osp.codpers'         ||  CHR(13) ||  gSuplJoins  ||  CHR(13) ||
  'WHERE '                                                                                 ||  CHR(13) ||
  '  lg.dataora     &gt;= TO_DATE(''' || current_setting('PKG_LIST_BASE_RESTLISTGEST.DATASTART', true) || ''', ''DD.MM.YYYY:HH24:MI:SS'')' || CHR(13) ||
  '  AND lg.dataora     &lt;= TO_DATE(''' || current_setting('PKG_LIST_BASE_RESTLISTGEST.DATAEND', true)   || ''', ''DD.MM.YYYY:HH24:MI:SS'')' || CHR(13) ||
  '  AND S.CODRESTAURANT = ' || TO_CHAR(NVL(current_setting('PKG_LIST_BASE_RESTLISTGEST.CODRESTAURANT', TRUE), 0));
  PERFORM LIST_EXECUTE_IMMEDIATE(s, aListID, aListVer);
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_sitfin_inchid712cu121</obj_name>
  <obj_hashval>3c9074d8d64eb1c3a8c4aa7ea800ef41</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_sitfin_inchid712cu121()
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
declare
  sSelect varchar(10000);
  vRez NUMERIC(20,7);
BEGIN
  --Florin 14.11.2025 - sinc. Oracle
  --Florin 15.10.2025
  vRez := 0;
  sSelect := '
  WITH
    r as (
      SELECT
        r.codcont, rs.rulajpd, rs.rulajpc, rs.rulajcd, rs.rulajcc, rs.rulajvpd, rs.rulajvpc, rs.rulajvcd, rs.rulajvcc,
        rs.rulajp_ifrs, rs.rulajc_ifrs, rs.rulajvp_ifrs, rs.rulajvc_ifrs, rs.rulajp_grup, rs.rulajc_grup, rs.rulajvp_grup, rs.rulajvc_grup, rs.subunitatea, r.an, r.luna
      FROM ncontrul r
        INNER JOIN ncontrulsub rs ON rs.codcontrul = r.codcontrul
      WHERE r.an*12+r.luna = '||GetANLUCRU()||'*12+1 AND r.luna &gt; 1),
    n AS (
      WITH RECURSIVE hierarchy AS (
    -- Anchor member: punctul de start (radacina ierarhiei)
    SELECT c.codcont, c.codparinte
    FROM ncont c
    WHERE c.simbol = ''712''
      AND EXISTS (
        SELECT 1
        FROM ncont1 c1
        WHERE c1.codcont = c.codcont
          AND c1.anstart * 12 + c1.lunastart &lt;= GetANLUCRU() * 12
      )
    UNION ALL
    -- Recursive member: cauta descenden?ii
    SELECT c.codcont, c.codparinte
    FROM ncont c
    INNER JOIN hierarchy h ON c.codparinte = h.codcont
    WHERE EXISTS (
      SELECT 1
      FROM ncont1 c1
      WHERE c1.codcont = c.codcont
        AND c1.anstart * 12 + c1.lunastart &lt;= GetANLUCRU() * 12
    )
  )
  SELECT codcont
  FROM hierarchy)
    select sum(nvl(debit,0) - nvl(credit,0)) from (
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, sc.codcont, 0 codcoresp,
      0 debit, 0 credit, 0 debitv, 0 creditv, 0 valoare, 0 valoarev,
      nvl(s.soldid,0) - nvl(s.soldic,0) sold, nvl(s.soldvid,0) - nvl(s.soldvic,0) soldv,
      nvl(s.soldi_ifrs,0) ifrs,  nvl(s.soldvi_ifrs,0) ifrsv, nvl(s.soldi_ifrs,0) sold_ifrs, nvl(s.soldvi_ifrs,0) sold_ifrsv,
      nvl(s.soldi_grup,0) grup,  nvl(s.soldvi_grup,0) grupv, nvl(s.soldi_grup,0) sold_grup, nvl(s.soldvi_grup,0) sold_grupv,
      ''Sold initial'' obs, null document, to_date(''01.''||sc.luna||''.''||sc.an,''dd.mm.yyyy'')  datadoc, s.subunitatea, 0 gest, sc.an, sc.luna,
      -1 ordine,
      0 codcentru, 0 indexlocal
    FROM ncontsold sc
      INNER JOIN ncontsoldsub s ON s.codcontsold = sc.codcontsold
      INNER JOIN n ON n.codcont = sc.codcont
    WHERE sc.an * 12 + sc.luna = '||GetANLUCRU()||'*12+1
    UNION ALL
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, r.codcont, 0 codcoresp,
      nvl(r.rulajpd,0) debit, nvl(r.rulajpc,0) credit, nvl(r.rulajvpd,0) debitv, nvl(r.rulajvpc,0) creditv, 0 valoare, 0 valoarev,
      nvl(r.rulajpd,0) - nvl(r.rulajpc,0) sold, nvl(r.rulajvpd,0) - nvl(r.rulajvpc,0) soldv,
      nvl(r.rulajp_ifrs,0) ifrs, nvl(r.rulajvp_ifrs,0) ifrsv, nvl(r.rulajp_ifrs,0) sold_ifrs, nvl(r.rulajvp_ifrs,0) sold_ifrsv,
      nvl(r.rulajp_grup,0) grup, nvl(r.rulajvp_grup,0) grupv, nvl(r.rulajp_grup,0) sold_grup, nvl(r.rulajvp_grup,0) sold_grupv,
      ''Rulaj precedent'' obs, null document, to_date(r.an||''.''||r.luna,''yyyy.mm'')-1 datadoc, r.subunitatea, 0 gest, r.an, r.luna - 1 luna,
      0 ordine,
      0 codcentru, 0 indexlocal
    FROM r
      INNER JOIN n ON n.codcont = r.codcont
    UNION ALL
    SELECT  -- tipinreg 1 debit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, j.contd codcont,j.contc codcoresp,
      j.valoare debit, 0 credit, j.valoarev debitv, 0 creditv, j.valoare, j.valoarev,
      Nvl(j.valoare,0) sold, Nvl(j.valoarev,0) soldv,
      Nvl(j.valoare_ifrs,0) ifrs, Nvl(j.valoarev_ifrs,0) ifrsv, Nvl(j.valoare_ifrs,0) sold_ifrs, Nvl(j.valoarev_ifrs,0) sold_ifrsv,
      Nvl(j.valoaregrup,0) grup, Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) grupv, Nvl(j.valoaregrup,0) sold_grup, Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (''SINCRONIZARE%'') THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (''INCHIDERE%'')    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      j.codcentru, j.indexlocal
    FROM jurnal j
      INNER JOIN n ON n.codcont = j.contd
    WHERE j.an *12 + j.luna BETWEEN '||GetANLUCRU()||'*12+1 AND '||GetANLUCRU()||'*12+12 +'|| getGetlunaLUCRU() ||' and j.contc in (select codcont from ncont where simbol like ''121%'')
    UNION ALL
    SELECT  -- tipinreg 1 credit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, j.contc codcont,j.contd codcoresp,
      0 debit, j.valoare credit, 0 debitv, j.valoarev creditv, j.valoare, j.valoarev,
      Nvl(-j.valoare,0) sold, Nvl(-j.valoarev,0) soldv,
      -Nvl(j.valoare_ifrs,0) ifrs, -Nvl(j.valoarev_ifrs,0) ifrsv, -Nvl(j.valoare_ifrs,0) sold_ifrs, -Nvl(j.valoarev_ifrs,0) sold_ifrsv,
      -Nvl(j.valoaregrup,0) grup, -Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) grupv, -Nvl(j.valoaregrup,0) sold_grup, -Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (''SINCRONIZARE%'') THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (''INCHIDERE%'')    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      j.codcentru, j.indexlocal
    FROM jurnal j
      INNER JOIN n ON n.codcont = j.contc
    WHERE j.an *12 + j.luna BETWEEN '||GetANLUCRU()||'*12+1 AND '||GetANLUCRU()||'*12+12 +'|| getGetlunaLUCRU() ||'  and j.contd in (select codcont from ncont where simbol like ''121%''))';

  begin
    execute sSelect into vRez;
    execute 'commit';
  exception when others then
    vRez := 0;
  end;
  return vRez;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_sitfin_inchid722cu121</obj_name>
  <obj_hashval>46a70cd24be7de1cdfbd8f8859fae12d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_sitfin_inchid722cu121()
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
declare
  sSelect varchar(10000);
  vRez NUMERIC(20,7);
BEGIN
  --Florin 14.11.2025 - sinc. Oracle
  --Florin 15.10.2025
  vRez := 0;
  sSelect := '
  WITH
    r as (
      SELECT
        r.codcont, rs.rulajpd, rs.rulajpc, rs.rulajcd, rs.rulajcc, rs.rulajvpd, rs.rulajvpc, rs.rulajvcd, rs.rulajvcc,
        rs.rulajp_ifrs, rs.rulajc_ifrs, rs.rulajvp_ifrs, rs.rulajvc_ifrs, rs.rulajp_grup, rs.rulajc_grup, rs.rulajvp_grup, rs.rulajvc_grup, rs.subunitatea, r.an, r.luna
      FROM ncontrul r
        INNER JOIN ncontrulsub rs ON rs.codcontrul = r.codcontrul
      WHERE r.an*12+r.luna = '||GetANLUCRU()||'*12+1 AND r.luna &gt; 1),
    n AS (
       WITH RECURSIVE hierarchy AS (
    -- Anchor member: punctul de start (radacina ierarhiei)
    SELECT c.codcont, c.codparinte
    FROM ncont c
    WHERE c.codcont IN (SELECT codcont FROM ncont WHERE simbol = ''722'')
      AND EXISTS (
        SELECT 1l - extrage doar coloana codcont din rezultatul ierarhic
        FROM ncont1 c1
        WHERE c1.codcont = c.codcontte specifica Oracle, va trebui sa o adaptezi sau sa o înlocuie?ti cu
          AND c1.anstart * 12 + c1.lunastart &lt;= GetANLUCRU() * 12
      )
    UNION ALL
    -- Recursive member: cauta descenden?ii
    SELECT c.codcont, c.codparinte
    FROM ncont c
    INNER JOIN hierarchy h ON c.codparinte = h.codcont
    WHERE EXISTS (
      SELECT 1
      FROM ncont1 c1
      WHERE c1.codcont = c.codcont
        AND c1.anstart * 12 + c1.lunastart &lt;= GetANLUCRU() * 12
    )
  )
  SELECT codcont
  FROM hierarchy)
    select sum(nvl(debit,0) - nvl(credit,0)) from (
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, sc.codcont, 0 codcoresp,
      0 debit, 0 credit, 0 debitv, 0 creditv, 0 valoare, 0 valoarev,
      nvl(s.soldid,0) - nvl(s.soldic,0) sold, nvl(s.soldvid,0) - nvl(s.soldvic,0) soldv,
      nvl(s.soldi_ifrs,0) ifrs,  nvl(s.soldvi_ifrs,0) ifrsv, nvl(s.soldi_ifrs,0) sold_ifrs, nvl(s.soldvi_ifrs,0) sold_ifrsv,
      nvl(s.soldi_grup,0) grup,  nvl(s.soldvi_grup,0) grupv, nvl(s.soldi_grup,0) sold_grup, nvl(s.soldvi_grup,0) sold_grupv,
      ''Sold initial'' obs, null document, to_date(''01.''||sc.luna||''.''||sc.an,''dd.mm.yyyy'')  datadoc, s.subunitatea, 0 gest, sc.an, sc.luna,
      -1 ordine,
      0 codcentru, 0 indexlocal
    FROM ncontsold sc
      INNER JOIN ncontsoldsub s ON s.codcontsold = sc.codcontsold
      INNER JOIN n ON n.codcont = sc.codcont
    WHERE sc.an * 12 + sc.luna = '||GetANLUCRU()||'*12+1
    UNION ALL
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, r.codcont, 0 codcoresp,
      nvl(r.rulajpd,0) debit, nvl(r.rulajpc,0) credit, nvl(r.rulajvpd,0) debitv, nvl(r.rulajvpc,0) creditv, 0 valoare, 0 valoarev,
      nvl(r.rulajpd,0) - nvl(r.rulajpc,0) sold, nvl(r.rulajvpd,0) - nvl(r.rulajvpc,0) soldv,
      nvl(r.rulajp_ifrs,0) ifrs, nvl(r.rulajvp_ifrs,0) ifrsv, nvl(r.rulajp_ifrs,0) sold_ifrs, nvl(r.rulajvp_ifrs,0) sold_ifrsv,
      nvl(r.rulajp_grup,0) grup, nvl(r.rulajvp_grup,0) grupv, nvl(r.rulajp_grup,0) sold_grup, nvl(r.rulajvp_grup,0) sold_grupv,
      ''Rulaj precedent'' obs, null document, to_date(r.an||''.''||r.luna,''yyyy.mm'')-1 datadoc, r.subunitatea, 0 gest, r.an, r.luna - 1 luna,
      0 ordine,
      0 codcentru, 0 indexlocal
    FROM r
      INNER JOIN n ON n.codcont = r.codcont
    UNION ALL
    SELECT  -- tipinreg 1 debit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, j.contd codcont,j.contc codcoresp,
      j.valoare debit, 0 credit, j.valoarev debitv, 0 creditv, j.valoare, j.valoarev,
      Nvl(j.valoare,0) sold, Nvl(j.valoarev,0) soldv,
      Nvl(j.valoare_ifrs,0) ifrs, Nvl(j.valoarev_ifrs,0) ifrsv, Nvl(j.valoare_ifrs,0) sold_ifrs, Nvl(j.valoarev_ifrs,0) sold_ifrsv,
      Nvl(j.valoaregrup,0) grup, Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) grupv, Nvl(j.valoaregrup,0) sold_grup, Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (''SINCRONIZARE%'') THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (''INCHIDERE%'')    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      j.codcentru, j.indexlocal
    FROM jurnal j
      INNER JOIN n ON n.codcont = j.contd
    WHERE j.an *12 + j.luna BETWEEN '||GetANLUCRU()||'*12+1 AND '||GetANLUCRU()||'*12+12 +'|| getGetlunaLUCRU() ||' and j.contc in (select codcont from ncont where simbol like ''121%'')
    UNION ALL
    SELECT  -- tipinreg 1 credit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, j.contc codcont,j.contd codcoresp,
      0 debit, j.valoare credit, 0 debitv, j.valoarev creditv, j.valoare, j.valoarev,
      Nvl(-j.valoare,0) sold, Nvl(-j.valoarev,0) soldv,
      -Nvl(j.valoare_ifrs,0) ifrs, -Nvl(j.valoarev_ifrs,0) ifrsv, -Nvl(j.valoare_ifrs,0) sold_ifrs, -Nvl(j.valoarev_ifrs,0) sold_ifrsv,
      -Nvl(j.valoaregrup,0) grup, -Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) grupv, -Nvl(j.valoaregrup,0) sold_grup, -Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (''SINCRONIZARE%'') THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (''INCHIDERE%'')    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      j.codcentru, j.indexlocal
    FROM jurnal j
      INNER JOIN n ON n.codcont = j.contc
    WHERE j.an *12 + j.luna BETWEEN '||GetANLUCRU()||'*12+1 AND '||GetANLUCRU()||'*12+12 +'|| getGetlunaLUCRU() ||'  and j.contd in (select codcont from ncont where simbol like ''121%''))';
  begin
    execute sSelect into vRez;
    execute 'commit';
  exception when others then
    vRez := 0;
  end;
  return vRez;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_sitimob_anlunafin</obj_name>
  <obj_hashval>d35f226fd8a23aa477c7ff1e7d7e2a73</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_sitimob_anlunafin()
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 07.11.2025
  return case when current_setting('PKG_LIST_BASE_SITIMOB.vLunaAnFin', true) is not null and current_setting('PKG_LIST_BASE_SITIMOB.vLunaAnFin', true) &lt;&gt; ''
   then current_setting('PKG_LIST_BASE_SITIMOB.vLunaAnFin', true)::numeric else 0 end;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_sitimob_anlunaini</obj_name>
  <obj_hashval>fccff2dd66ddb250b64c71ca077183ca</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_sitimob_anlunaini()
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 07.11.2025
  return case when current_setting('PKG_LIST_BASE_SITIMOB.vLunaAnIni', true) is not null and current_setting('PKG_LIST_BASE_SITIMOB.vLunaAnIni', true) &lt;&gt; ''
   then current_setting('PKG_LIST_BASE_SITIMOB.vLunaAnIni', true)::numeric else 0 end;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_utils_umpletempconsauto</obj_name>
  <obj_hashval>89e6033c189c54e1bb0ee22711d9b4b0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_utils_umpletempconsauto()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  v_rec record;
begin
  --Florin 20.11.2025 - sinc. Oracle
  --Florin 14.11.2025 - sinc. Oracle
  --Florin 01.10.2025
  delete FROM tmp_cons_auto;

  insert into tmp_cons_auto(codnparc0,codnparcaut,dataprec,bordprec,datacurent,bordcurent,consum,consum_val, consum_tva)
  select x.codnparc0,x.codnparcaut, x.dataprec, x.bordprec, x.datacurent, x.bordcurent,
         (select sum(i1.cant*i1.pu-coalesce(i1.tva,0))
          FROM INTRARI I, INTRARI1 I1
          WHERE I1.CODOBIECT in (214,8878) AND I1.CODINTR = I.CODINTR AND I.CODAUTO = X.CODNPARCAUT
                AND TRUNC(I.DATADOC) &gt;= TRUNC(x.DATAPREC)+1 AND TRUNC(I.DATADOC) &lt;= TRUNC(x.DATAcurent)
         ) consum_val,
         (select sum(i1.tva)
          FROM INTRARI I, INTRARI1 I1
          WHERE I1.CODOBIECT in (214,8878) AND I1.CODINTR = I.CODINTR AND I.CODAUTO = X.CODNPARCAUT
                AND I.DATADOC &gt;= x.DATAPREC+1 AND I.DATADOC &lt;= x.DATAcurent
         ) consum_tva
  from
  (select npc0.codnparc0,npc0.codnparcaut, trunc(pcl.databord) dataprec, pcl.kmbord bordprec, trunc(npc0.databord) datacurent, npc0.kmbord bordcurent
   from nparc0 npc0
        INNER JOIN NPARCAUT PC ON PC.CODNPARCAUT = NPC0.CODNPARCAUT
        inner join nparc0 pcl on pcl.codnparcaut = npc0.codnparcaut
   where pcl.databord = (select max(pcl0.databord)
                         from nparc0 pcl0
                         where pcl0.codnparcaut = npc0.codnparcaut and
                               pcl0.databord &lt; npc0.databord
                        )
         and npc0.databord between PKG_GLOBALS.datastart and PKG_GLOBALS.datastop
  ) x
  union all
  select x.codnparc0,x.codnparcaut, x.dataprec, x.bordprec, x.datacurent, x.bordcurent,
         (select sum(i1.cant)
          FROM INTRARI I, INTRARI1 I1
          WHERE I1.CODOBIECT in (214,8878) AND I1.CODINTR = I.CODINTR AND I.CODAUTO = X.CODNPARCAUT
                AND I.DATADOC &gt;= x.DATAPREC+1 AND I.DATADOC &lt;= x.DATAcurent
         ) consum,
        (select sum(i1.cant*i1.pu-coalesce(i1.tva,0))
          FROM INTRARI I, INTRARI1 I1
          WHERE I1.CODOBIECT in (214,8878) AND I1.CODINTR = I.CODINTR AND I.CODAUTO = X.CODNPARCAUT
                AND TRUNC(I.DATADOC) &gt;= TRUNC(x.DATAPREC)+1 AND TRUNC(I.DATADOC) &lt;= TRUNC(x.DATAcurent)
         ) consum_val,
         (select sum(i1.tva)
          FROM INTRARI I, INTRARI1 I1
          WHERE I1.CODOBIECT in (214,8878) AND I1.CODINTR = I.CODINTR AND I.CODAUTO = X.CODNPARCAUT
                AND TRUNC(I.DATADOC) &gt;= TRUNC(x.DATAPREC)+1 AND TRUNC(I.DATADOC) &lt;= TRUNC(x.DATAcurent)
         ) consum_tva
  from
  (select npc0.codnparc0,npc0.codnparcaut, trunc(pc.datainreg) dataprec, 0 bordprec, npc0.databord datacurent, npc0.kmbord bordcurent
   from nparc0 npc0
        INNER JOIN NPARCAUT PC ON PC.CODNPARCAUT = NPC0.CODNPARCAUT
   where npc0.databord = (select min(pcl0.databord)
                           from nparc0 pcl0
                           where pcl0.codnparcaut = npc0.codnparcaut)
   and  npc0.databord between PKG_GLOBALS.datastart and PKG_GLOBALS.datastop
  ) x;

  for v_rec in (select * from tmp_cons_auto) loop
    update tmp_cons_auto tmp set
    bordprec_c = (
       SELECT bordcurent
        FROM tmp_cons_auto p0
        WHERE p0.codnparcaut = tmp.codnparcaut
          AND p0.datacurent &lt; tmp.datacurent
          AND coalesce(p0.consum, 0) &lt;&gt; 0
        ORDER BY p0.datacurent DESC
        LIMIT 1
    )
    where tmp.codnparc0 = v_rec.codnparc0;
  end loop;

  delete from tmp_cons_auto where
    not (datacurent between current_setting('PKG_GLOBALS.datastart', true)::date and current_setting('PKG_GLOBALS.datastop', true)::date);

  update tmp_cons_auto set bordprec = 0 where bordprec is null;
  update tmp_cons_auto set bordprec_c = 0 where bordprec_c is null;
  update tmp_cons_auto tmp set
    bordmin = (select min(t.bordprec) from tmp_cons_auto t where t.codnparcaut = tmp.codnparcaut),
    bordmax = (select max(t.bordcurent) from tmp_cons_auto t where t.codnparcaut = tmp.codnparcaut),
    consum_total = (select sum(t.consum) from tmp_cons_auto t where t.codnparcaut = tmp.codnparcaut);

  commit;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>PROCEDURE</obj_type>
  <obj_name>pkg_list_struct_addsupltab</obj_name>
  <obj_hashval>b7e46d1e66f372f86baf45310e8a1f89</obj_hashval>
  <obj_text>CREATE OR REPLACE PROCEDURE pkg_list_struct_addsupltab(INOUT asuplcols character varying, IN atable character varying, IN aalias character varying, IN ajoincond character varying, IN aforcevalid numeric DEFAULT 0, IN acustomlst numeric DEFAULT 0)
 LANGUAGE plpgsql
AS $procedure$
DECLARE
  vSuplCols VARCHAR       := aSuplCols;
  vTable    TEXT          := aTable;
  vAlias    VARCHAR(100)  := aAlias;
  vJoinCond TEXT          := aJoinCond;
  vTestCond TEXT;
  bCondOk   BOOLEAN;
  sSQL      VARCHAR;
  v_IdxSuplTab integer;
BEGIN
  --Adina 24.02.2021
  v_IdxSuplTab := CASE WHEN length(current_setting('PKG_LIST_STRUCT.v_IdxSuplTab', true))=0 THEN 0 ELSE current_setting('PKG_LIST_STRUCT.v_IdxSuplTab', true)::integer END;
  IF  v_IdxSuplTab = 0 AND  COALESCE( aCUSTOMLST, 0) = 1 THEN
    bCondOk := TRUE;
  ELSE
    bCondOk := vJoinCond IS NOT NULL ;
  END IF;

  IF vTable IS NOT NULL  AND vAlias IS NOT NULL  AND bCondOk AND  (SELECT pkg_list_struct_TmpExists.WME_RESULT FROM pkg_list_struct_TmpExists(NULL, vTable)) = 1 THEN
    IF  v_IdxSuplTab = 0 AND  COALESCE( aCUSTOMLST, 0) = 1 THEN
      vTestCond := '';
      vSuplCols := vTable || ' ' || vAlias;
    ELSIF vSuplCols IS NULL  AND  aFORCEVALID = 1 THEN
      vTestCond := '';
      vSuplCols := vTable || ' ' || vAlias;
    ELSE
      vTestCond := ' AND ' || vJoinCond;
      vSuplCols := vSuplCols || ', ' || vTable || ' ' || vAlias;
    END IF;
    sSQL := 'SELECT * FROM ' || vSuplCols || ' WHERE 1=0' || vTestCond;

    BEGIN
      IF  COALESCE( aFORCEVALID, 0) = 0 THEN
        EXECUTE sSQL;
      END IF;
      v_IdxSuplTab := v_IdxSuplTab + 1;
      perform set_config('PKG_LIST_STRUCT.v_IdxSuplTab', v_IdxSuplTab::varchar,false);
      aSuplCols := vSuplCols;
      INSERT INTO TMP_LST_TABS(ORDINE, TABLENAME, ALIASNAME, JOINCOND, FORCEVALID, ISVIEW)
      VALUES(v_IdxSuplTab, vTable, vAlias, vJoinCond, COALESCE( aFORCEVALID, 0), 0);
    EXCEPTION WHEN OTHERS THEN
      NULL;
    END;
  END IF;
END;
$procedure$
</obj_text>
</row>

<row>
  <obj_type>PROCEDURE</obj_type>
  <obj_name>pkg_list_struct_addsupltabs</obj_name>
  <obj_hashval>37976531dd6c7de0ac3c781d81a97394</obj_hashval>
  <obj_text>CREATE OR REPLACE PROCEDURE pkg_list_struct_addsupltabs(INOUT asuplcols character varying, IN atable character varying, IN aalias character varying, IN ajoincond character varying, IN aforcevalid numeric DEFAULT 0, IN acustomlst numeric DEFAULT 0)
 LANGUAGE plpgsql
AS $procedure$
DECLARE
  vSuplCols TEXT         := aSuplCols;
  vTable    TEXT         := TRIM(aTable);
  vAlias    VARCHAR(100) := TRIM(aAlias);
  vJoinCond TEXT         := TRIM(aJoinCond);
  vTestCond TEXT;
  bCondOk   BOOLEAN;
  sSQL      VARCHAR;
  v_IdxSuplTab NUMERIC  := COALESCE(NULLIF(current_setting('PKG_LIST_STRUCT.v_IdxSuplTab', true),''),'0')::NUMERIC;
BEGIN
  --STEF 09.03.2021
  --aFORCEVALID = 1 SKIP VALIDARE PENTRU JOINURI CU TABLELE CARE NU SUNT IN COLOANE SUPLIMENTARE
  IF v_IdxSuplTab = 0 AND Coalesce(aCUSTOMLST,0) = 1
  THEN bCondOk := TRUE;
  ELSE bCondOk := Coalesce(Length(vJoinCond),0) &lt;&gt; 0;
  END IF;

  IF  Coalesce(Length(vTable), 0) &lt;&gt; 0
  AND Coalesce(Length(vAlias), 0) &lt;&gt; 0
  AND bCondOk
  AND fnc_TmpExists(vTable) = 1
  THEN
    IF v_IdxSuplTab = 0 AND Coalesce(aCUSTOMLST,0) = 1 THEN
      vTestCond := '';
      vSuplCols := vTable||' '||vAlias;
    ELSIF Coalesce(Length(vSuplCols),0) = 0 AND Coalesce(aFORCEVALID,0) = 1 THEN
      vTestCond := '';
      vSuplCols := vTable||' '||vAlias;
    ELSE
      vTestCond := ' AND '||vJoinCond;
      vSuplCols := vSuplCols||', '||vTable||' '||vAlias;
    END IF;
    sSQL := 'SELECT 1 FROM '||vSuplCols||' WHERE 1=0'||vTestCond;
    BEGIN
      IF Coalesce(aFORCEVALID,0) = 0 THEN
        EXECUTE sSQL;
      END IF;
      CALL pkg_list_struct_IncIdxSuplTab(v_IdxSuplTab);
      aSuplCols    := vSuplCols;
      INSERT INTO TMP_LST_TABS(ORDINE, TABLENAME, ALIASNAME, JOINCOND, FORCEVALID, ISVIEW) VALUES (v_IdxSuplTab, vTable, vAlias, vJoinCond, Coalesce(aFORCEVALID,0), 0);
    EXCEPTION
      WHEN OTHERS THEN NULL;
    END;
  END IF;
END;
$procedure$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_struct_addsuplview</obj_name>
  <obj_hashval>60027d2acbc1ed1b967115fdd3cefc09</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_struct_addsuplview(asuplcols text, aview character varying, aalias character varying, ajoincond character varying, aforcevalid numeric, acustomlst numeric)
 RETURNS text
 LANGUAGE plpgsql
AS $function$
DECLARE
  vView     VARCHAR       := TRIM( aView);
  vAlias    VARCHAR(100)  := TRIM( aAlias);
  vJoinCond TEXT          := TRIM( aJoinCond);
  vTestCond TEXT;
  bCondOk   BOOLEAN;
  sSQL      VARCHAR;
  v_IdxSuplTab integer;
begin
  --Florin 03.12.2025 - sinc. Oracle
  IF  NOT vView LIKE (  '(%)') THEN  vView := '(' || vView || ')'; END IF;
  v_IdxSuplTab := current_setting('PKG_LIST_STRUCT.v_IdxSuplTab', true)::integer;

  IF  v_IdxSuplTab = 0 AND  COALESCE( aCUSTOMLST, 0) = 1
    THEN bCondOk := TRUE;
    ELSE bCondOk := Coalesce(Length(vJoinCond),0) &lt;&gt; 0;
  END IF;

  IF aView IS NOT NULL  AND vAlias IS NOT NULL  AND bCondOk THEN
    IF  v_IdxSuplTab  = 0 AND  COALESCE( aCUSTOMLST, 0) = 1 THEN
      vTestCond := '';
      aSuplCols := vView || ' ' || vAlias;
    ELSE
      vTestCond := ' AND ' || vJoinCond;
      aSuplCols := aSuplCols || ', ' || vView || ' ' || vAlias;
    END IF;
    sSQL := 'SELECT * FROM ' || aSuplCols || ' WHERE 1=0' || vTestCond;
    BEGIN
      IF  COALESCE( aFORCEVALID, 0) = 0 THEN  EXECUTE sSQL; END IF;
      v_IdxSuplTab := v_IdxSuplTab + 1;
      perform set_config('PKG_LIST_STRUCT.v_IdxSuplTab', v_IdxSuplTab::varchar,false);
      INSERT INTO TMP_LST_TABS (ORDINE, TABLENAME, ALIASNAME, JOINCOND, FORCEVALID, ISVIEW)
      VALUES(v_IdxSuplTab, vView, vAlias, vJoinCond, COALESCE( aFORCEVALID, 0), 1);
    EXCEPTION WHEN OTHERS THEN
       raise;
    END;
  END IF;
  RETURN aSuplCols;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>PROCEDURE</obj_type>
  <obj_name>pkg_list_struct_getsuplcols</obj_name>
  <obj_hashval>c75ba978ccf59e7697993711beb2f7c7</obj_hashval>
  <obj_text>CREATE OR REPLACE PROCEDURE pkg_list_struct_getsuplcols(IN alistid numeric, IN alistver numeric, INOUT sfields character varying, INOUT salias character varying, INOUT snullalias character varying, INOUT sjoin character varying, IN gsuplcols character varying)
 LANGUAGE plpgsql
AS $procedure$
DECLARE
  v_rec     RECORD;
  sSuplCols VARCHAR;
  vOK       BOOLEAN;
  sSQL      VARCHAR := '';
  sAux      VARCHAR := '';
BEGIN
  --Florin 16.12.2025 - fixat 67595
  --STEF 14.07.2023
  sSuplCols  := Trim(gSuplCols);
  sFields    := '';
  sAlias     := '';
  sNullAlias := '';

  FOR v_rec IN (
    SELECT l.tablename, l.fieldname aliasname, l.joincond, Trim(l.sql) sql_sview
    FROM winmadmin.listsql l
    WHERE l.tip = 0
      AND l.listid  = aLISTID
      AND l.listver = aLISTVER
    ORDER BY codlistsql
  ) LOOP
    IF Coalesce(Length(v_rec.sql_sview), 0) = 0 --aici problema, v_rec.sql_sview intra trunchiat in parametru de tip clob
    THEN CALL pkg_list_struct_AddSuplTabs(sSuplCols, v_rec.tablename, v_rec.aliasname, v_rec.joincond, 0, CASE WHEN aLISTID &lt; 0 OR aLISTID BETWEEN 40000 AND 44999 THEN 1 ELSE 0 END);
    ELSE perform pkg_list_struct_AddSuplView(sSuplCols, v_rec.sql_sview, v_rec.aliasname, v_rec.joincond, 0, CASE WHEN aLISTID &lt; 0 OR aLISTID BETWEEN 40000 AND 44999 THEN 1 ELSE 0 END);
    END IF;
  END LOOP;

  FOR v_rec IN (
    SELECT lc.alias, lc.fieldname
    FROM winmadmin.listcols lc
    WHERE lc.usercolumn = 1
      AND lc.listid = aLISTID
      AND lc.listver = aLISTVER
  ) LOOP
    vOK := True;
    IF Coalesce(Length(sSuplCols), 0) &lt;&gt; 0 THEN
      -- stef am nevoie sa validez coloanele suplimentare fiindca in cazul extensiilor aceste pot diferi de la o firma la alta
      sSQL := 'SELECT '||v_rec.alias||' FROM '||sSuplCols||' WHERE 1=0';
      BEGIN
        EXECUTE sSQL;
      EXCEPTION
        WHEN OTHERS THEN vOK := FALSE;
      END;
    END IF;
    IF vOK THEN
      sFields    := sFields   ||','||v_rec.fieldname;
      sAlias     := sAlias    ||','||v_rec.alias;
      sNullAlias := sNullAlias||',NULL';
    END IF;
  END LOOP;

  sAux  := Upper(sAlias);
  sJoin := '';
  FOR v_rec IN (
    SELECT Upper(TABLENAME) TABLENAME, Upper(ALIASNAME) ALIASNAME, Upper(JOINCOND) JOINCOND, ORDINE
    FROM TMP_LST_TABS
    ORDER BY ORDINE DESC
    -- creez joinul de la coada la cap pentru a vede daca exista dependinte
  ) LOOP
    IF (aLISTID &lt; 0 or aLISTID BETWEEN 40000 AND 44999) AND v_rec.ORDINE = 1 THEN
      sJoin := v_rec.TABLENAME||' '||v_rec.ALIASNAME||sJoin;
    ELSIF InStr(sAux, v_rec.ALIASNAME||'.') &gt; 0 THEN
      sJoin := ' LEFT JOIN '||v_rec.TABLENAME||' '||v_rec.ALIASNAME||' ON '||v_rec.JOINCOND||sJoin;
      sAux  := sAux||','||v_rec.JOINCOND;
    END IF;
  END LOOP;
  sFields    := Coalesce(sFields   , '');
  sAlias     := Coalesce(sAlias    , '');
  sNullAlias := Coalesce(sNullAlias, '');
  sJoin      := Coalesce(sJoin     , '');
END;
$procedure$
</obj_text>
</row>

<row>
  <obj_type>PROCEDURE</obj_type>
  <obj_name>pkg_list_struct_incidxsupltab</obj_name>
  <obj_hashval>9a6ab9fd27580f5ca65d81bbc10ade02</obj_hashval>
  <obj_text>CREATE OR REPLACE PROCEDURE pkg_list_struct_incidxsupltab(INOUT v_idxsupltab numeric)
 LANGUAGE plpgsql
AS $procedure$
BEGIN
  --STEF 09.03.2021
  v_IdxSuplTab := v_IdxSuplTab + 1;
  perform set_config('PKG_LIST_STRUCT.v_IdxSuplTab', v_IdxSuplTab::varchar,false);
END;
$procedure$
</obj_text>
</row>

<row>
  <obj_type>PROCEDURE</obj_type>
  <obj_name>pkg_list_struct_startsuplcols</obj_name>
  <obj_hashval>c42512d031ddd48a978321f011cc97ee</obj_hashval>
  <obj_text>CREATE OR REPLACE PROCEDURE pkg_list_struct_startsuplcols()
 LANGUAGE plpgsql
AS $procedure$
BEGIN
  --STEF 25.02.2021
  PERFORM set_config('PKG_LIST_STRUCT.v_IdxSuplTab','0',false);
  DELETE FROM TMP_LST_TABS;
end;
$procedure$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_miscari_interne_make_mifix_nou</obj_name>
  <obj_hashval>ad5614331cb187a622d7a173434e393a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_miscari_interne_make_mifix_nou(acodmifix numeric, acodmifix1 numeric, aanstart numeric, alunastart numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCODMIFIXNOU  NUMERIC;
  NRINVNOU      NUMERIC;
BEGIN
   --Florin 12.12.2025 - sinc. Oracle
   --Florin 20.11.2025 - sinc. Oracle
   --Florin 18.11.2025 - sinc. Oracle
   SELECT COALESCE(CODMIFIXNOU, 0) INTO aCODMIFIXNOU
   FROM
     MIFIX
   WHERE
     CODMIFIX = aCODMIFIX;

 IF aCODMIFIXNOU = 0 THEN
   aCODMIFIXNOU := NEXTVAL('SEQ_MIFIX_CODMIFIX');
   NRINVNOU := PKG_MIFIX_GETNEXTNRINV('MF');

   INSERT INTO MIFIX(CODMIFIX, TIP, NRINVENTAR, ANINTRARE, LUNAINTRARE, OBS, ANINTRAREG, LUNAINTRAREG, SERIEINV,CODMIFIXIMB)
   SELECT  aCODMIFIXNOU, 'MF', NRINVNOU, ANINTRARE, LUNAINTRARE, OBS, ANINTRAREG, LUNAINTRAREG, SERIEINV,CODMIFIXIMB
   FROM
     MIFIX
   WHERE
      CODMIFIX = aCODMIFIX;

   UPDATE MIFIX
   SET
     CODMIFIXNOU = aCODMIFIXNOU
   WHERE
     CODMIFIX = aCODMIFIX;
 END IF;

 UPDATE MIFIX1
 SET
   CODMIFIX = aCODMIFIXNOU,
   STARE = 7
 WHERE
   CODMIFIX1 = aCODMIFIX1;

  IF aANSTART * 12 + aLUNASTART = getANLUCRU() * 12 + getLUNALUCRU() THEN
    UPDATE MIFIX1
    SET
      AMOBLOCAT = 1,
      DFBLOCAT = 1
    WHERE
       CODMIFIX1 = aCODMIFIX1;
  END IF;

  INSERT INTO JURNAL1(CODJURNAL1,CODDOC, TIPDOC, INDEXLOCAL, DIRTY, AN, LUNA)
              VALUES(NEXTVAL('SEQ_JURNAL1_CODJURNAL1'), aCODMIFIXNOU, 36, aCODMIFIXNOU, 1, getANLUCRU(), getLUNALUCRU());
  INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, AN, LUNA)
              VALUES(NEXTVAL('SEQ_JURNAL_CODJURNAL'), aCODMIFIXNOU, 36, aCODMIFIXNOU, 0, 0, getANLUCRU(), getLUNALUCRU());


END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_nompart_partanaf_actden</obj_name>
  <obj_hashval>e141e41b8e234db9c7be26e37bf60788</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_nompart_partanaf_actden()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  v_rec record;
BEGIN
  --Florin 31.10.2025
  FOR v_rec IN (
    SELECT CODPART, DENUMIRE
    FROM TMP_NPART_ANAF
    WHERE Coalesce(CHANGE_DEN,0) = 1 AND DENUMIRE IS NOT NULL AND CODPART IS NOT NULL
  ) LOOP
    UPDATE NPART
    SET DEN_PART = v_rec.DENUMIRE
    WHERE CODPART = v_rec.CODPART;
  END LOOP;
  perform pkg_nompart_PartANAF_Init();
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_nompart_partanaf_actrtvai</obj_name>
  <obj_hashval>ae326166855ea979e3e68507fb498b18</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_nompart_partanaf_actrtvai()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  vRec record;
BEGIN
  --Florin 17.09.2025
  FOR vRec IN (
    SELECT CodPart, RTVAI FROM TMP_NPART_ANAF WHERE OLD_RTVAI &lt;&gt; RTVAI
  ) LOOP
    UPDATE NPART SET TVALAINCASARE = vRec.RTVAI WHERE CodPArt = vRec.CodPart;
  END LOOP;
  UPDATE TMP_NPART_ANAF SET OLD_RTVAI = RTVAI WHERE OLD_RTVAI &lt;&gt; RTVAI;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_nompart_partanaf_actstareinactiv</obj_name>
  <obj_hashval>bc2fa911d948eff21e7779187875d9cd</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_nompart_partanaf_actstareinactiv()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  vRec record;
BEGIN
  --Florin 17.09.2025
  FOR vRec IN (
    SELECT CodPart, INACTIV FROM TMP_NPART_ANAF WHERE OLD_INACTIV &lt;&gt; INACTIV
  ) LOOP
    UPDATE NPART SET INACTIV = vRec.INACTIV WHERE CodPArt = vRec.CodPart;
  END LOOP;
  UPDATE TMP_NPART_ANAF SET OLD_INACTIV = INACTIV WHERE OLD_INACTIV &lt;&gt; INACTIV;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_nompart_structuraanaf_cuiinit</obj_name>
  <obj_hashval>b727f69601ad1a7a5164eebb0c44e2f7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_nompart_structuraanaf_cuiinit(pcui numeric, pdata date DEFAULT NULL::date)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  dData date := Coalesce(pData, DATE_TRUNC ('DAY',CURRENT_TIMESTAMP));
BEGIN
  --Florin 04.11.2025 - sinc. Oracle
  --Florin 17.09.2025 - fixat 66666
  --Stef 21.07.2025
  DELETE FROM TMP_STRUCTURAANAF;
  INSERT INTO TMP_STRUCTURAANAF (
    CUI, DATA, STARE, CONTRIBUABIL, DENUMIRE,
    ADRESA, LOCALITATE, JUDET, STRADA, BLOC, SCARA, NUMAR1, NUMAR2, ETAJ, APART,
    NRREGCOM, SPLITTVA, RTVAI, STAREINREG, STAREINACTIV, MESAJ
  )
  SELECT
    TMP.Cui, TMP.Data, Coalesce(PA.Stare, 0) Stare, PA.CONTRIBUABIL, PA.DENUMIRE,
    PA.ADRESA, PA.LOCALITATE, PA.JUDET, PA.STRADA, PA.BLOC, PA.SCARA, PA.NUMAR1, PA.NUMAR2, PA.ETAJ, PA.APART,
    PA.NRREGCOM, PA.SPLITTVA, PA.RTVAI, PA.STAREINREG, PA.STAREINACTIV, PA.MESAJ
  FROM (SELECT pCUI AS CUI , dData AS DATA) tmp LEFT JOIN WINMADMIN.NPART_ANAF PA ON PA.CUI = TMP.CUI AND PA.DATA = TMP.Data AND NOT PA.STARE = 2;

  DELETE FROM TMP_STRUCTURAANAF WHERE Cif_Valid(Cui::varchar) = 0;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_nompart_structuraanaf_sinc</obj_name>
  <obj_hashval>a92808981a0405eb4c2dca64a6082f0a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_nompart_structuraanaf_sinc()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 21.07.2025
  INSERT INTO WINMADMIN.NPART_ANAF (
    CUI, DATA, STARE, CONTRIBUABIL, DENUMIRE,
    ADRESA, LOCALITATE, JUDET, STRADA, BLOC, SCARA, NUMAR1, NUMAR2, ETAJ, APART,
    NRREGCOM, SPLITTVA, RTVAI, STAREINREG, STAREINACTIV, MESAJ)
  SELECT DISTINCT
    T.CUI, T.DATA, T.STARE, T.CONTRIBUABIL, T.DENUMIRE,
    T.ADRESA, T.LOCALITATE, T.JUDET, T.STRADA, T.BLOC, T.SCARA, T.NUMAR1, T.NUMAR2, T.ETAJ, T.APART,
    T.NRREGCOM, T.SPLITTVA, T.RTVAI, T.STAREINREG, T.STAREINACTIV, T.MESAJ
  FROM TMP_STRUCTURAANAF T
  WHERE NOT STARE IN (0, 9)
    AND NOT EXISTS (SELECT 1 FROM WINMADMIN.NPART_ANAF A WHERE A.CUI = T.CUI AND A.DATA = T.DATA);
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rapstocmed_vcodsiui</obj_name>
  <obj_hashval>3159f06134a4853078498f885dbaa0cb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rapstocmed_vcodsiui(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := current_setting('PKG_RAPSTOCMED.vCodSiui', true);
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reclamatii_check_struct_extensie_reclamatii</obj_name>
  <obj_hashval>83ebcbdd997ffd670a636352d43d625b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reclamatii_check_struct_extensie_reclamatii()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  NR  NUMERIC(10) := 0;
  DT  VARCHAR(100);
  SIR VARCHAR(1000);
  VG  VARCHAR(100);
  NR1 NUMERIC(10) := 0;
  V_REC record;
  sFIRMANAME varchar;
BEGIN
  --Florin 08.02.2021 - fixat 57067
  --Florin 17.08.2022 - sinc. Oracle
  sFIRMANAME := lower(current_setting('PKG_GLOBALS.FIRMANAME',true));
  IF (SELECT wme_result FROM PKG_LIST_STRUCT_TmpExists(NULL, 'RECLAMATIIEXT')) = 0 THEN
    execute 'CREATE TABLE ' || getFIRMANAME() || '.RECLAMATIIEXT ( CODRECLAMATIIEXT NUMERIc(20), CODRECLAMATIE NUMERIC(20) ) ';
    PERFORM PKG_CFGTABLES_SETGRANTMODUL('RECLAMATIIEXT', getFIRMANAME());
  END IF;

  SELECT COUNT(*) INTO NR FROM pg_statio_all_sequences WHERE relname = 'SEQ_RECLAMATIIEXT_CODRECLAMATIIEXT' and schemaname = sFIRMANAME;
  IF NR = 0 THEN
    PERFORM PKG_REMAKE_SEQUENCES_REMAKE_SEQUENCE('RECLAMATIIEXT', 'CODRECLAMATIIEXT', 'SEQ_RECLAMATIIEXT_CODRECLAMATIIEXT');
  END IF;


  IF (SELECT wme_result FROM PKG_LIST_STRUCT_TmpExists(NULL, 'TMP_RECLAMATIIEXT')) = 1 THEN
    SELECT COUNT(*) INTO NR1 FROM information_schema.Columns WHERE TABLE_NAME = 'RECLAMATIIEXT' AND TABLE_SCHEMA = sFIRMANAME;
    SELECT COUNT(*) INTO NR  FROM information_schema.Columns WHERE TABLE_NAME = 'TMP_RECLAMATIIEXT';

    IF NR1 &lt;&gt; NR THEN
      EXECUTE 'DROP TABLE ' || getFIRMANAME() || '.TMP_RECLAMATIIEXT ' ;
    END IF;
  END IF;

  IF (SELECT wme_result FROM PKG_LIST_STRUCT_TmpExists(NULL, 'TMP_RECLAMATIIEXT')) = 0 THEN
    Sir := 'CREATE TEMPORARY TABLE TMP_RECLAMATIIEXT (' ;

    select  count(*) into  NR from  information_schema.COLUMNS WHERE TABLE_NAME = 'RECLAMATIIEXT' and TABLE_SCHEMA = sFIRMANAME;
    for V_REC in (SELECT * from  information_schema.COLUMNS WHERE TABLE_NAME = 'RECLAMATIIEXT' and TABLE_SCHEMA = sFIRMANAME order BY ORDINAL_POSITION)
    LOOP
      IF V_REC.DATA_TYPE = 'VARCHAR' THEN DT := ' VARCHAR(' || V_REC.DATA_LENGTH || ') ';
      ELSE
      IF V_REC.DATA_TYPE = 'DATE' THEN DT := ' DATE ';
      ELSE
       DT := ' NUMERIC(' || V_REC.DATA_PRECISION || ',' || V_REC.DATA_SCALE || ') ';
      END IF;
      END IF;

      IF V_REC.COLUMN_ID &lt; NR  THEN VG := ', ';
      ELSE
       VG := '';
      END IF;
      DT := DT || VG;
      SIR := SIR || ' ' || V_REC.COLUMN_NAME || ' ' || DT;
    END LOOP;
    SIR := SIR || ' )';
    execute SIR;
--
    PERFORM PKG_CFGTABLES_SETGRANTMODUL('TMP_RECLAMATIIEXT', getFIRMANAME());
  END IF;
End;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reclamatii_getnrdoc_i</obj_name>
  <obj_hashval>b237ae2ac9bad51df18e09d6480963d3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reclamatii_getnrdoc_i(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_RECLAMATII.NRDOC_I', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reclamatii_nrdoc_i</obj_name>
  <obj_hashval>d041cbe98de8c4ffca32048b42395cde</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reclamatii_nrdoc_i(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_RECLAMATII.NRDOC_I', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reclamatii_rezolvareclamatie</obj_name>
  <obj_hashval>2a44ef58f142a4503c0e627d095fcb1f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reclamatii_rezolvareclamatie(recid numeric, acoddoc numeric, atipdoc numeric, adatadoc date)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  UPDATE Reclamatii
  SET
  CodDocR  = aCodDoc,
  TipdocR  = aTipDoc,
  Rezolvat = 1,
  DataRez  = aDataDoc
  WHERE
   CodReclamatie = RecID;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reclamatii_setnrdoc_i</obj_name>
  <obj_hashval>a117abf63cb72e29dce5405e96728b43</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reclamatii_setnrdoc_i(anrdoc numeric, acarnet numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_RECLAMATII.CARNETDOC_I',to_char(ACARNET,'999999999999999999'),false);
perform set_config('PKG_RECLAMATII.NRDOC_I',to_char(ANRDOC,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reclamatii_sp_deleterecord</obj_name>
  <obj_hashval>b47e659a6b35d5e4c58b4704b4f412b7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reclamatii_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 24.04.2023 - sinc. Oracle
  --Florin 17.08.2022 - sinc. Oracle (16.08.2022)
  PERFORM PKG_RECLAMATII_SP_LOCKRECORD( RecId);
  PERFORM PKG_CFGTABLES_EXT_DELETERECORD (recId, 97);
  DELETE FROM RECLAMATII  WHERE CodRECLAMATIE = RecId;
  DELETE FROM RECLAMATII1 WHERE CodRECLAMATIE = RecId;
  DELETE FROM RECLAMATII2 WHERE CodRECLAMATIE = RecId;
  IF (SELECT wme_result FROM PKG_LIST_STRUCT_TMPEXISTS(NULL, 'RECLAMATIIEXT')) &gt; 0 THEN
    EXECUTE 'DELETE FROM RECLAMATIIEXT WHERE CODRECLAMATIE = ' || RECID;
  END IF;
  PERFORM PKG_CARNETEDOC_RELEASENUMARDOC( TO_NUMBER((current_setting('PKG_RECLAMATII.CARNETDOC_I', true)),'999999999999999999'), TO_NUMBER((current_setting('PKG_RECLAMATII.NRDOC_I', true)),'999999999999999999'));
  PERFORM PKG_CARNETEDOC_COMPACTEAZAINTERVALE( TO_NUMBER((current_setting('PKG_RECLAMATII.CARNETDOC_I', true)),'999999999999999999'));
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reclamatii_sp_gotorecord</obj_name>
  <obj_hashval>31f1b279ef02d0e5e3580a206d3a4bc1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reclamatii_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aTipDoc numeric;
  aCodDoc numeric;
BEGIN
  --Florin 24.04.2023 - sinc. Oracle
  --Florin 21.04.2023 - fixat 58011
  --Florin 15.03.2023 - fixat 57626
  --Florin 06.10.2022 - sinc. Oracle
  --Florin 17.08.2022 - sinc. Oracle (16.08.2022)
  --Florin 02.06.2022 - sinc. Oracle
  --Bogdan 27.10.2020
  --PERFORM pkg_reclamatii_CHECK_STRUCT_EXTENSIE_RECLAMATII();
  IF RecID &gt; 0 THEN
    SELECT TipDoc, CodDoc INTO aTipDoc, aCodDoc FROM Reclamatii WHERE CodReclamatie = RecId;

    IF aTipDoc IN (1, 2, 3, 4, 5, 9) THEN
      DELETE FROM Reclamatii1 WHERE CodReclamatie = RecId and CodDoc1 NOT IN (SELECT CodIntr1 FROM Intrari1 WHERE CodIntr = aCodDoc);
    ELSIF aTipDoc IN (8, 18) THEN
      DELETE FROM Reclamatii1 WHERE CodReclamatie = RecId and CodDoc1 NOT IN (SELECT CodComanda1 FROM Comanda1 WHERE CodComanda = aCodDoc);
    ELSIF aTipDoc in (19,20,21,26) THEN
      Delete from Reclamatii1 where CodReclamatie = RecId and CodDoc1 not in (Select CodIes1 from Iesiri1 where CodIes = aCodDoc);
    elsif aTipDoc in (10,27) then
      Delete from Reclamatii1 where CodReclamatie = RecId and CodDoc1 not in (Select CodContract1 from Contract1 where CodContract = aCodDoc);
    END IF;
  END IF;

  INSERT INTO TMP_RECLAMATII (CODRECLAMATIE, ANULAT, BLOCAT, OPERAT, CODDOC, TIPDOC, NRDOC, SERIADOC, DATADOC, CARNETDOC, CodSubunit, codutilizator, Motiv,
                              CodPart, Reclamatie, CodDocR, TipDocR, Rezolvat, DATARez, CodResp, IMPUTABILA, TIPIMPUT, CODPIMPUT, CodPersC, CodLocatie, VALOARE)
  SELECT R.CODRECLAMATIE, R.ANULAT, R.BLOCAT, R.OPERAT, R.CODDOC, R.TIPDOC, R.NRDOC, R.SERIADOC, R.DATADOC, R.CARNETDOC, R.CodSubunit, R.codutilizator, R.Motiv,
         R.CodPart, R.Reclamatie, R.CodDocR, R.TipDocR, R.Rezolvat, R.DATARez, R.CodResp, R.IMPUTABILA, R.TIPIMPUT, R.CODPIMPUT, R.CodPersC, R.CodLocatie, 0
  FROM RECLAMATII R WHERE R.CodRECLAMATIE = RECID;

  INSERT INTO TMP_RECLAMATII1 (CODRECLAMATIE1, codReclamatie, CodDoc1, Cant, Obs, CodObiect, UMSec, D1, D2, D3, CantUMs, PU, Valoare, Imputabil, CodIntern, CodExtern)
  SELECT CODRECLAMATIE1, R1.codReclamatie, CodDoc1, R1.Cant, R1.Obs,
         CASE WHEN C.TipDoc IS NOT NULL THEN C1.CodObiect
              WHEN I.TipDoc IS NOT NULL THEN I1.CodObiect
              WHEN E.TipDoc IS NOT NULL THEN E1.CodObiect
              when CT.TipDoc is not null then CT1.CodObiect
              ELSE 0
         END ,
         CASE WHEN C.TipDoc IS NOT NULL THEN C1.UMSec
              WHEN I.TipDoc IS NOT NULL THEN I1.UMSec
              WHEN E.TipDoc IS NOT NULL THEN E1.UMSec
              when CT.TipDoc is not null then CT1.UMSec
              ELSE 0
         END ,
         R1.D1, R1.D2, R1.D3, R1.CantUMs,
         CASE WHEN C.TipDoc IS NOT NULL THEN C1.PU
              WHEN I.TipDoc IS NOT NULL THEN I1.PU
              WHEN E.TipDoc IS NOT NULL THEN E1.PU
              when CT.TipDoc is not null then CT1.PRET
              ELSE 0
         END PU,
         CASE WHEN C.TipDoc IS NOT NULL THEN C1.PU * R1.Cant
              WHEN I.TipDoc IS NOT NULL THEN I1.PU * R1.Cant
              WHEN E.TipDoc IS NOT NULL THEN E1.PU * R1.Cant
              when CT.TipDoc is not null then CT1.PRET*R1.Cant
              ELSE 0
         END VALOARE,
         R1.Imputabil, o.codintern, o.codextern
  FROM TMP_RECLAMATII      R
    LEFT JOIN Comanda      C  ON C.CodComanda     = R.CodDoc and C.TipDoc = R.TipDoc
    LEFT JOIN Intrari      I  ON I.CodIntr        = R.CodDoc and I.TipDoc = R.TipDoc
    LEFT JOIN Iesiri       E  ON E.CodIes         = R.CodDoc and E.TipDoc = R.TipDoc
    LEFT JOIN Contract CT     ON CT.CodContract   = R.CodDoc and CT.TipDoc = R.TipDoc
    INNER JOIN RECLAMATII1 R1 ON R1.Codreclamatie = R.CodReclamatie
    LEFT JOIN Comanda1     C1 ON C1.CodComanda1   = R1.CodDoc1
    LEFT JOIN Intrari1     I1 ON I1.CodIntr1      = R1.CodDoc1
    LEFT JOIN Iesiri1      E1 ON E1.CodIes1       = R1.CodDoc1
    left join Contract1 CT1  on CT1.CodContract1 = R1.CodDoc1
    LEFT JOIN NartObj o ON o.CodObiect  = coalesce(c1.codobiect,i1.CodObiect,e1.codobiect,CT1.CodObiect)
    LEFT JOIN Nart         A  ON a.CodArticol     = o.CodArticol
  WHERE
    R1.CodReclamatie = RecId;

  UPDATE TMP_RECLAMATII R SET Valoare = (SELECT SUM (R1.valoare) FROM TMP_RECLAMATII1 R1 WHERE R.CodReclamatie = R1.CodReclamatie);

  UPDATE TMP_RECLAMATII1 R1
  SET
    DenObiect = (SELECT O.Denumire FROM NArtOBJ O WHERE O.CodObiect = R1.CodObiect) ,
    DenUM     = (SELECT U.DEN_UM1  FROM NUM1 U    WHERE U.CodUM1 = R1.UMSec);

  INSERT INTO TMP_RECLAMATII2 (CODRECLAMATIE2, codReclamatie, CodPers)
  SELECT CODRECLAMATIE2, codReclamatie, CodPers FROM RECLAMATII2 WHERE CodReclamatie = RecId;
  PERFORM PKG_CFGTABLES_EXT_GOTORECORD(97);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reclamatii_sp_insertrecord</obj_name>
  <obj_hashval>4ac1f3c3b53f7fc55c1e6521456d60f1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reclamatii_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 24.04.2023 - sinc. Oracle
  --Florin 15.03.2023 - fixat 57626
  --Florin 08.02.2023 - fixat 57067
  --Florin 17.08.2022 - sinc. Oracle (16.08.2022)
  INSERT INTO TMP_RECLAMATII (CodRECLAMATIE) VALUES(0);
  PERFORM PKG_CFGTABLES_EXT_INSERTRECORD(97);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reclamatii_sp_postrecords</obj_name>
  <obj_hashval>b46eaebd2d8f8c5b864a7386769b7975</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reclamatii_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC      RECORD;
  Cod        numeric;
  aCARNETDOC numeric;
  aNRDOC     numeric;
BEGIN
  --Florin 24.04.2023 - sinc. Oracle
  --Florin 15.03.2023 - fixat 57626
  --Florin 02.06.2022 - sinc. Oracle
  SELECT CarnetDoc, NrDoc INTO aCarnetDoc, aNrDoc FROM Tmp_Reclamatii;
  PERFORM PKG_CFGTABLES_EXT_POSTRECORDS_INIT (97);

  IF Operation = 0 THEN
    BEGIN
      SELECT CodRECLAMATIE INTO RECID FROM TMP_RECLAMATII;
    EXCEPTION
    WHEN OTHERS THEN
      RECID := 0;
    END;

    UPDATE RECLAMATII
    SET
      (
        CODRECLAMATIE,
        ANULAT,
        BLOCAT,
        OPERAT,
        CODDOC,
        TIPDOC,
        NRDOC,
        SERIADOC,
        DATADOC,
        CARNETDOC,
        CodSubunit,
        codutilizator,
        Motiv,
        CodPart,
        Reclamatie,
        CodDocR,
        TipDocR,
        Rezolvat,
        DATARez,
        CodResp,
        IMPUTABILA,
        TIPIMPUT,
        CODPIMPUT,
        CodPersC,
        CodLocatie
      )
      = (SELECT CODRECLAMATIE,
          ANULAT,
          BLOCAT,
          OPERAT,
          CODDOC,
          TIPDOC,
          NRDOC,
          SERIADOC,
          DATADOC,
          CARNETDOC,
          CodSubunit,
          codutilizator,
          Motiv,
          CodPart,
          Reclamatie,
          CodDocR,
          TipDocR,
          Rezolvat,
          DATARez,
          CodResp,
          IMPUTABILA,
          TIPIMPUT,
          CODPIMPUT,
          CodPersC,
          CodLocatie
        FROM TMP_RECLAMATII)
    WHERE
      CodRECLAMATIE = RECID;

    DELETE FROM Reclamatii1 WHERE CODReclamatie = RecID and CodReclamatie1 NOT IN (SELECT CODReclamatie1 FROM TMP_Reclamatii1);

    FOR v_rec IN (SELECT * FROM TMP_Reclamatii1 WHERE CODReclamatie1 &lt; 0) LOOP
      INSERT INTO Reclamatii1 (codReclamatie1, codReclamatie, CodDoc1, Cant, Obs, D1, D2, D3, CantUMs, PU, Imputabil)
      VALUES (NEXTVAL ('SEQ_RECLAMATII1_CODRECLAMATIE1'), RecId, V_REC.CodDoc1, V_REC.Cant, V_REC.Obs, V_REC.D1, V_REC.D2, V_REC.D3, V_REC.CantUMs, V_REC.PU, V_REC.IMPUTABIL);
    END LOOP;

    FOR v_rec IN (SELECT * FROM TMP_Reclamatii1 WHERE CODReclamatie1 &gt; 0) LOOP
      UPDATE Reclamatii1
      SET
        Cant      = v_rec.Cant,
        Obs       = v_rec.Obs,
        D1        = V_REC.D1,
        D2        = V_REC.D2,
        D3        = V_REC.D3,
        CantUMs   = V_REC.CantUMs,
        PU        = V_REC.PU,
        IMPUTABIL = V_REC.IMPUTABIL
      WHERE
        CODReclamatie1 = v_rec.CODReclamatie1;
    END LOOP;

    DELETE FROM Reclamatii2 WHERE CODReclamatie = RecID and CodReclamatie2 NOT IN (SELECT CODReclamatie2 FROM TMP_Reclamatii2);

    FOR v_rec IN (SELECT * FROM TMP_Reclamatii2 WHERE CODReclamatie2 &lt; 0) LOOP
      INSERT INTO Reclamatii2 (codReclamatie2, codReclamatie, CodPers)
      VALUES (NEXTVAL ('SEQ_RECLAMATII2_CODRECLAMATIE2'), RecId, V_REC.CodPers);
    END LOOP;

    FOR v_rec IN (SELECT * FROM TMP_Reclamatii2 WHERE CODReclamatie2 &gt; 0) LOOP
      UPDATE Reclamatii2 SET CodPers = V_REC.CodPers WHERE CODReclamatie2 = v_rec.CODReclamatie2;
    END LOOP;
  ELSE
    SELECT NEXTVAL ('SEQ_RECLAMATII_CODRECLAMATIE') INTO RecId;
    PERFORM PKG_CFGTABLES_EXT_UPDATE_COD_CORESP('RECLAMATII', RecId);

    INSERT INTO RECLAMATII (CODRECLAMATIE, ANULAT, BLOCAT, OPERAT, CODDOC, TIPDOC, NRDOC, SERIADOC, DATADOC, CARNETDOC, CodSubunit, codutilizator, Motiv,
                            CodPart, Reclamatie, CodDocR, TipDocR, Rezolvat, DATARez, CodResp, IMPUTABILA, TIPIMPUT, CODPIMPUT, CodPersC, CodLocatie )
    SELECT RECID, ANULAT, BLOCAT, OPERAT, CODDOC, TIPDOC, NRDOC, SERIADOC, DATADOC, CARNETDOC, CodSubunit, codutilizator, Motiv,
           CodPart, Reclamatie, CodDocR, TipDocR, Rezolvat, DATARez, CodResp, IMPUTABILA, TIPIMPUT, CODPIMPUT, CodPersC, CodLocatie
    FROM TMP_RECLAMATII;

    FOR v_rec IN (SELECT * FROM TMP_RECLAMATII1) LOOP
      INSERT INTO RECLAMATII1 (codReclamatie1, codReclamatie, CodDoc1, Cant, Obs, D1, D2, D3, CantUMs, PU, Imputabil)
      VALUES (NEXTVAL ('SEQ_RECLAMATII1_CODRECLAMATIE1'), RecId, V_REC.CodDoc1, V_REC.Cant, V_REC.Obs, V_REC.D1, V_REC.D2, V_REC.D3, V_REC.CantUMs, V_REC.PU, V_REC.IMPUTABIL);
    END LOOP;

    FOR v_rec IN (SELECT * FROM TMP_RECLAMATII2) LOOP
      INSERT INTO RECLAMATII2 (codReclamatie2, codReclamatie, CodPers)
      VALUES (NEXTVAL ('SEQ_RECLAMATII2_CODRECLAMATIE2'), RecId, V_REC.CodPers);
    END LOOP;
  END IF;

--  IF PKG_LIST_STRUCT.TmpExists('RECLAMATIIEXT') = 1
--    AND PKG_LIST_STRUCT.TmpExists('TMP_RECLAMATIIEXT') = 1 THEN
--      EXECUTE 'DELETE FROM RECLAMATIIEXT WHERE CODRECLAMATIE =  ' || RECID;
--      EXECUTE 'UPDATE TMP_RECLAMATIIEXT SET CODRECLAMATIIEXT = NEXTVAL(''SEQ_RECLAMATIIEXT_CODRECLAMATIIEXT'') WHERE CODRECLAMATIIEXT &lt; 0';
--      EXECUTE 'UPDATE TMP_RECLAMATIIEXT SET CODRECLAMATIE = ' || RECID;
--      EXECUTE 'INSERT INTO RECLAMATIIEXT SELECT * FROM TMP_RECLAMATIIEXT ';
--  END IF;

  IF (current_setting ('PKG_RECLAMATII.CARNETDOC_I', true) ::numeric  &lt;&gt; 0)
    AND (current_setting ('PKG_RECLAMATII.NRDOC_I', true) ::numeric &lt;&gt; 0)
    AND (aCARNETDOC                                                 &lt;&gt; current_setting ('PKG_RECLAMATII.CARNETDOC_I', true) ::numeric
      OR aNRDOC                                                   &lt;&gt; current_setting ('PKG_RECLAMATII.NRDOC_I', true) ::numeric)
  THEN
    PERFORM PKG_CARNETEDOC_RELEASENUMARDOC (current_setting ('PKG_RECLAMATII.CARNETDOC_I', true) ::numeric, current_setting ('PKG_RECLAMATII.NRDOC_I', true) ::numeric);
    PERFORM PKG_CARNETEDOC_COMPACTEAZAINTERVALE (current_setting ('PKG_RECLAMATII.CARNETDOC_I', true) ::numeric);
  END IF;

  PERFORM PKG_CARNETEDOC_SOLVENUMARDOC (aCARNETDOC, (aNRDOC) ::character varying);
  PERFORM PKG_CFGTABLES_EXT_POSTRECORDS(97);
  PERFORM NotifyModif (Operation, RecId, 'RECLAMATII');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reclamatii_umpledocasoc</obj_name>
  <obj_hashval>9f1e94849bb6adeda852d05432bda943</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reclamatii_umpledocasoc(acoddoc numeric, atipdoc numeric, acoddocasoc numeric, atipdocasoc numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Duplicat numeric;
begin
  SELECT COUNT( *) INTO Duplicat FROM DocAsoc WHERE CodDoc = aCodDoc AND  TipDoc = aTipDoc AND  CodDocAsoc = aCodDocAsoc AND  TipDocAsoc = aTipDocAsoc;
  IF  Duplicat = 0 THEN
    INSERT INTO DOCASOC(CodDoc, Tipdoc, CodDocAsoc, TipDocAsoc)
    VALUES(aCodDOC, aTipDOC, aCodDOCAsoc, aTipDocAsoc);
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_an_reg</obj_name>
  <obj_hashval>6b8144f1e0335781307ca66dedd56b27</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_an_reg(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REG.an_reg', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_bank_reg</obj_name>
  <obj_hashval>ed429fbb6ba7b8d4d5a1c62edce37d6d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_bank_reg(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REG.bank_reg', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_curs_reg</obj_name>
  <obj_hashval>5c2e6e4c423340aaaac24e33e16b849f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_curs_reg(INOUT wme_result double precision, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REG.curs_reg', true)),'99999999999.9999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_getan_reg</obj_name>
  <obj_hashval>952d18e48e3f7069150c35679458dc38</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_getan_reg(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REG.an_reg', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_getanreg</obj_name>
  <obj_hashval>aa0297f8714a065e0d865a6214c0eee3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_getanreg(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
WME_Result :=  TO_NUMBER((current_setting('PKG_REG.an_reg', true)),'999999999999999999');
RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_getbank_reg</obj_name>
  <obj_hashval>6343d930e7df3c4e5300ed84c506d854</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_getbank_reg(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REG.bank_reg', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_getbankreg</obj_name>
  <obj_hashval>2e219f596c7a67cfc18f72495831f67a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_getbankreg(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
WME_Result :=  TO_NUMBER((current_setting('PKG_REG.bank_reg', true)),'999999999999999999');
RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_getcurs_reg</obj_name>
  <obj_hashval>1cd536f5827f35d8c48dbc9e007b21a5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_getcurs_reg(INOUT wme_result double precision, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REG.curs_reg', true)),'99999999999.9999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_getcursbanca</obj_name>
  <obj_hashval>126b100fa7ec7c1cb93fa9bca905a949</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_getcursbanca(INOUT wme_result numeric, INOUT data_p character varying, INOUT banca_p numeric, INOUT moneda_p numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  tmp       double precision := -1;
  data_curs date;
BEGIN
  --Florin 26.02.2021 - fixat 44070
  data_curs := TO_DATE( data_p, 'DD.MM.YYYY');

  SELECT Valoare
  INTO tmp
  FROM NMONEDE1
  WHERE Data = (SELECT MAX( Data) FROM NMONEDE1 WHERE CodBanca = banca_p AND  CodMoneda = moneda_p AND  Data &lt;= data_curs)
    and codbanca = banca_p and codmoneda = moneda_p;

  IF tmp IS NULL THEN
    perform set_config('PKG_REG.curs_reg',to_char(0,'99999999999.9999999'),false);
  ELSE
    perform set_config('PKG_REG.curs_reg',to_char(tmp,'99999999999.9999999'),false);
  END IF;

  WME_Result :=  TO_NUMBER((current_setting('PKG_REG.curs_reg', true)),'99999999999.9999999');
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_getcursreg</obj_name>
  <obj_hashval>dfb29cc9e8104cb2fa5f7bb14668ab2f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_getcursreg(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
WME_Result :=  TO_NUMBER((current_setting('PKG_REG.curs_reg', true)),'99999999999.9999999');
RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_getlastregdate</obj_name>
  <obj_hashval>cb2ebf524d5233496c2a0f100392fafc</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_getlastregdate(INOUT wme_result date, INOUT moneda_p numeric, INOUT tipreg_p numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  tmp date;
begin
  SELECT MAX( DataDoc)
  INTO tmp
  FROM REG
  WHERE CodMoneda = moneda_p AND  TipReg = tipreg_p
    AND TO_DATE( '01.' || TO_CHAR( EXTRACT( MONTH FROM DataDoc),'9999999999') || '.' || TO_CHAR( EXTRACT( YEAR FROM DataDoc),'9999999999'), 'DD.MM.YYYY') &lt;= TO_DATE( '01.' || TO_CHAR( (SELECT PKG_GLOBALS_GETLUNALUCRU.WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL)),'9999999999') || '.' || TO_CHAR( (SELECT PKG_GLOBALS_GETANLUCRU.WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL)),'9999999999'), 'DD.MM.YYYY') - INTERVAL '1' MONTH;

  IF tmp IS NULL THEN
    WME_Result :=  TO_DATE( '01.01.0001', 'DD.MM.YYYY');
    RETURN;
  ELSE
    WME_Result :=  tmp;
    RETURN;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_getluna_reg</obj_name>
  <obj_hashval>5d66b85f35ce71e9ada40f441ff67ab4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_getluna_reg(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REG.luna_reg', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_getlunareg</obj_name>
  <obj_hashval>5cf6aa130c056f3781e00742485ece8b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_getlunareg(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
WME_Result :=  TO_NUMBER((current_setting('PKG_REG.luna_reg', true)),'999999999999999999');
RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_getmoneda_reg</obj_name>
  <obj_hashval>fcc727e77f54101ca8a1cfeda9653486</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_getmoneda_reg(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REG.moneda_reg', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_getmonedareg</obj_name>
  <obj_hashval>b02a0a192495741bac87eab0616d511c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_getmonedareg(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  --Bogdan 17.08.2020
  -- todo - verifica daca poate fi stearsa
  WME_Result :=  TO_NUMBER((current_setting('PKG_REG.moneda_reg', true)),'999999999999999999');
RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_getnumregspermonth</obj_name>
  <obj_hashval>c3501e30c758d51bb6cded216bcd2037</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_getnumregspermonth(INOUT wme_result numeric, INOUT tip_p numeric, INOUT month_p numeric, INOUT year_p numeric, INOUT moneda_p numeric, INOUT codreg_p numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  tmp numeric;
begin
  SELECT COUNT( *)
  INTO tmp
  FROM REG
  WHERE CodReg &lt;&gt; codreg_p AND  TipReg = tip_p AND  CodMoneda = moneda_p AND  EXTRACT( MONTH FROM DataDoc) = month_p AND  EXTRACT( YEAR FROM DataDoc) = year_p;

  WME_Result :=  tmp;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_gettrezorcurs</obj_name>
  <obj_hashval>ed0e36ea62a7c6bdf347fe40402ceaef</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_gettrezorcurs(INOUT wme_result numeric, INOUT codtrezor1_p numeric, INOUT subunit_p numeric, INOUT moneda_p numeric, INOUT curs_p numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  tmp          double precision := 0;
  tmp_cod_reg  numeric;
  cod_last_reg numeric;
  num_reg      numeric;
begin
  SELECT COUNT( *)
  INTO num_reg
  FROM REG
  WHERE CodMoneda = moneda_p AND  CodSubunit = subunit_p AND  TipReg = 45 AND  EXTRACT( YEAR FROM DataDoc) = (SELECT PKG_GLOBALS_GETANLUCRU.WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL)) AND  EXTRACT( MONTH FROM DataDoc) = (SELECT PKG_GLOBALS_GETLUNALUCRU.WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL));

  IF  num_reg = 0 THEN
    SELECT CodReg INTO cod_last_reg FROM REG WHERE DataDoc = (SELECT PKG_REG_GetLastRegDate.WME_RESULT FROM PKG_REG_GetLastRegDate(NULL, moneda_p, 45)) AND  TipReg = 45;
  ELSE
    SELECT CodReg INTO tmp_cod_reg FROM TMP_REG;
    IF  tmp_cod_reg = 0 THEN
      SELECT CodReg INTO cod_last_reg FROM REG WHERE DataDoc = (SELECT PKG_REG_GetLastRegDate.WME_RESULT FROM PKG_REG_GetLastRegDate(NULL, moneda_p, 45)) AND  TipReg = 45;
    ELSE
      SELECT CodReg INTO cod_last_reg FROM REG
      WHERE CodMoneda = moneda_p AND  TipReg = 45
        AND  DataDoc = (SELECT MAX( DataDoc) FROM REG WHERE DataDoc &lt; (SELECT PKG_REG_GetLastRegDate.WME_RESULT FROM PKG_REG_GetLastRegDate(NULL, moneda_p, 45)));
    END IF;
  END IF;

  SELECT Curs INTO tmp FROM TREZOR1_REG WHERE CodTrezor1 = codtrezor1_p AND  CodReg = cod_last_reg;
  IF tmp IS NULL THEN
    WME_Result :=  curs_p;
    RETURN;
  ELSE
    WME_Result :=  tmp;
    RETURN;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_getzi_reg</obj_name>
  <obj_hashval>99fc696c7d9118ed38933254c8a3946c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_getzi_reg(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REG.zi_reg', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_luna_reg</obj_name>
  <obj_hashval>e5a782af0eb850ed82449db704af4be4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_luna_reg(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REG.luna_reg', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_setcurs_reg</obj_name>
  <obj_hashval>83e83247751137b7295512b7287b6a05</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_setcurs_reg(acurs_reg double precision)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REG.curs_reg',to_char(acurs_reg,'99999999999.9999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_setdatareg</obj_name>
  <obj_hashval>5245434e7644e77501936d95fe628dd9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_setdatareg(data_p character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
   --Bogdan 17.08.2020
  perform set_config('PKG_REG.data_reg',TO_DATE( data_p, 'DD.MM.YYYY')::varchar,false);
  perform set_config('PKG_REG.zi_reg'  ,EXTRACT( DAY   FROM (current_setting('PKG_REG.data_reg', true)::date))::varchar,false);
  perform set_config('PKG_REG.luna_reg',EXTRACT( MONTH FROM (current_setting('PKG_REG.data_reg', true)::date))::varchar,false);
  perform set_config('PKG_REG.an_reg'  ,EXTRACT( YEAR  FROM (current_setting('PKG_REG.data_reg', true)::date))::varchar,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_setluna_reg</obj_name>
  <obj_hashval>7419b22a7dd3b067196e569f984bb5f5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_setluna_reg(aluna_reg numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REG.luna_reg',to_char(aluna_reg,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_setmoneda_reg</obj_name>
  <obj_hashval>eba8b2ec24563455846becf985c21472</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_setmoneda_reg(amoneda_reg numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REG.moneda_reg',to_char(amoneda_reg,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_setmonedareg</obj_name>
  <obj_hashval>b89a10f4dd501b4c7dcae68d1455eac5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_setmonedareg(moneda_p numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REG.moneda_reg',to_char(moneda_p,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_setparamsreg</obj_name>
  <obj_hashval>f71e6ae4b26cee14bf5e2ee661213a0c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_setparamsreg(data_p character varying, moneda_p numeric, curs_p numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_REG_SetDataReg( data_p);
  PERFORM PKG_REG_SetMonedaReg(moneda_p);
  PERFORM PKG_REG_SetCursReg( curs_p);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_setzi_reg</obj_name>
  <obj_hashval>596826f650fa6f1d901db3366f3afc6b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_setzi_reg(azi_reg numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REG.zi_reg',to_char(azi_reg,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_zi_reg</obj_name>
  <obj_hashval>12ba11688c18f235b2ecd20e97630d4b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_zi_reg(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REG.zi_reg', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regoss_getdatetrimestru</obj_name>
  <obj_hashval>573d3d839b46bbe2aabd3d376f62ca84</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regoss_getdatetrimestru(ptrimestrul numeric, INOUT datastart date, INOUT datastop date, pan numeric DEFAULT NULL::numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
    aAn NUMERIC(4);
  BEGIN
  --Florin 05.12.2022 - fixat 56437
  --Florin 24.11.2022
    if pAn is null then
      aAn := GetANLUCRU();
    else
      aAn := pAn;
    end if;
  WITH RECURSIVE a(qtr, trimestrul) AS
  (
    SELECT add_months(to_date('01.01.'||aAn::varchar,'dd.mm.yyyy'), 0), 1 trimestrul
    UNION ALL
    SELECT add_months(to_date('01.01.'||aAn::varchar,'dd.mm.yyyy'), a.trimestrul * 3), a.trimestrul + 1 FROM a WHERE a.trimestrul &lt;= 4)
    select qtr as first_day,
        last_day(add_months(qtr, 2)) as last_day into dataStart, dataStop
       from a
       WHERE trimestrul = pTrimestrul;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regoss_getnumregsperquarter</obj_name>
  <obj_hashval>06d12621d2b8751e93d215ef622061cb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regoss_getnumregsperquarter(INOUT wme_result numeric, INOUT ptrimestru numeric, INOUT pmoneda numeric, INOUT pcodreg numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
 tmp numeric(20);
  BEGIN
    --Florin 08.11.2022 - sinc. Oracle
    SELECT
      COUNT(*) INTO tmp
    FROM
      REGOSS ross
    WHERE
      ross.codregoss &lt;&gt; pCodreg AND
      ross.codmoneda = pMoneda AND
      ross.trimestrul = pTrimestru ;
      wme_result := tmp;
      RETURN;
    EXCEPTION WHEN OTHERS THEN
    wme_result := -1;
    RETURN;
 END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regoss_sp_deleterecord</obj_name>
  <obj_hashval>3a0aff43dc34874595ae17c7e399686a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regoss_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  v_rec record;
  V_REC_JURN_SUB record;
BEGIN
  --Florin 05.12.2022 - fixat 56447
  --Florin 23.11.2022 - sinc. Oracle
  --Florin 04.11.2022 - sinc. Oracle
   PERFORM pkg_regoss_SP_LOCKRECORD(RecID);
   DELETE FROM REGOSS1 WHERE CODREGOSS = RecID;
   DELETE FROM REGOSS WHERE CODREGOSS = RecID;

   FOR V_REC IN
      (SELECT * FROM JURNAL WHERE CODDOC = RecID AND TIPDOC = 108) -- mRegularOSS = 108
    LOOP
      UPDATE NCONTRUL
      SET RULAJCD = RULAJCD - V_REC.VALOARE, RULAJVCD = RULAJVCD - V_REC.VALOAREV
      WHERE CODCONT = V_REC.CONTD AND AN = getANLUCRU() AND LUNA = getLUNALUCRU();

      FOR V_REC_JURN_SUB IN
        (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND AN = V_REC.AN AND LUNA = V_REC.LUNA)
      LOOP
        UPDATE NCONTRULSUB
        SET RULAJCD = RULAJCD - V_REC.VALOARE, RULAJVCD = RULAJVCD - V_REC.VALOAREV
        WHERE CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
      END LOOP;

       UPDATE NCONTRUL
       SET RULAJCC = RULAJCC - V_REC.VALOARE, RULAJVCC = RULAJVCC - V_REC.VALOAREV
       WHERE CODCONT = V_REC.CONTC AND AN = getANLUCRU() AND LUNA = getLUNALUCRU();

      FOR V_REC_JURN_SUB IN
        (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND AN = V_REC.AN AND LUNA = V_REC.LUNA)
      LOOP
        UPDATE NCONTRULSUB
        SET RULAJCC = RULAJCC - V_REC.VALOARE, RULAJVCC = RULAJVCC - V_REC.VALOAREV
        WHERE CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
      END LOOP;

    END LOOP;

    DELETE FROM JURNAL  WHERE CODDOC = RecID AND TIPDOC = 108;
    DELETE FROM JURNAL1 WHERE CODDOC = RecID AND TIPDOC = 108;

   PERFORM NotifyModif(2, RecId, 'REGOSS');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regoss_sp_gotorecord</obj_name>
  <obj_hashval>0e308140a293f1fbfd817eef4f271f2a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regoss_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  vTrimestru NUMERIC(1);
  vCursReg NUMERIC(23,7);
  vMoneda NUMERIC;
  nrRanduriModif NUMERIC;
BEGIN
  --Florin 08.12.2022 - sinc. Oracle
  --Florin 29.11.2022 - sinc. Oracle (28.11.2022)
  --Florin 23.11.2022 - sinc. Oracle
  --Florin 17.11.2022 - sinc. Oracle (8-16.11.2022)
  --Florin 04.11.2022 - sinc. Oracle
  DELETE FROM TMP_REGOSS;
    INSERT INTO TMP_REGOSS
      (CODREGOSS,
       TIPREG,
       NRDOC,
       DATADOC,
       TRIMESTRUL,
       CODBANK,
       CODMONEDA,
       CURS,
       DIRTY,
       OBS,
       CODSUBUNIT,
       AN,
       LUNA,
       CODGEST,
       CODANALIZA,
       CODANALIZANOD,
       CODCENTRU,
       CURS_IFRS,
       SIMBOLMONEDA,
       SIMBOLBANK)
      (SELECT r.CODREGOSS,
              r.TIPREG,
              r.NRDOC,
              r.DATADOC,
              r.TRIMESTRUL,
              r.CODBANK,
              r.CODMONEDA,
              r.CURS,
              r.DIRTY,
              r.OBS,
              r.CODSUBUNIT,
              r.AN,
              r.LUNA,
              r.CODGEST,
              r.CODANALIZA,
              r.CODANALIZANOD,
              r.CODCENTRU,
              r.CURS_IFRS,
              m.SIMBOL,
              b.SIMBOL
         FROM REGOSS r
         LEFT OUTER JOIN NMONEDE m
           ON m.CODMONEDA = r.CODMONEDA
         LEFT OUTER JOIN NBANK b
           ON b.CODBANK = r.CODBANK
        WHERE r.CODREGOSS = RecID);
    select ross.trimestrul, ross.curs, ross.codmoneda
      into vTrimestru, vCursReg, vMoneda from tmp_regoss ross;
    -- populez TMP_REGOSS1;
    DELETE FROM TMP_REGOSS1;
    INSERT INTO TMP_REGOSS1
      (CODREGOSS1,
       CODREGOSS,
       CODDOC,
       TIPDOC,
       TVADOCVAL,
       TVADOC,
       TVADOCREG,
       CODGEST,
       CONT,
       SIMBOLCONT,
       SEMN,
       CURS,
       SEMNIFICATIE,
       DIFERENTA,
       CODPART,
       DEN_PART,
       DOC,
       SUBUNITATEA,
       CODTVASERV,
       CODTVASERV1,
       modificari)
      select rs1.CODREGOSS1,
             rs1.CODREGOSS,
             rs1.CODDOC,
             rs1.TIPDOC,
             rs1.TVADOCVAL,
             rs1.TVADOC,
             rs1.TVADOCREG,
             rs1.CODGEST,
             rs1.CONT,
             (SELECT wme_result FROM PKG_PLANCONTURI_GETSIMBOLCONT(NULL, rs1.CONT)),
             rs1.SEMN,
             rs1.CURS,
             rs1.SEMNIFICATIE,
             rs1.TVADOCREG - rs1.TVADOCVAL,
             part.codpart,
             part.den_part,
             COALESCE(ies.seriadoc, '')||' '||COALESCE(ies.nrdoc::varchar, '')||'/'||to_char(ies.datadoc, 'dd.mm.yyyy') as doc,
             ies.subunitatea,
             ies.codtvaserv,
             tsr1.codtvaserv1,
             0
        from REGOSS1 rs1
        join iesiri ies on ies.codies = rs1.coddoc
        join npart part on part.codpart = ies.partener
        left join tvaserv tsr on tsr.codtvaserv = ies.codtvaserv
        left join tvaserv1 tsr1 on tsr1.codtvaserv = tsr.codtvaserv and getAnLunaLucru() BETWEEN tsr1.ALSTART AND tsr1.ALSTOP
       where CODREGOSS = RecID;
     INSERT INTO TMP_JURNAL (SELECT * FROM JURNAL WHERE TIPDOC = 108 AND CODDOC = RECID);
     INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = 108 AND CODDOC = RECID);
     DELETE FROM TMP_RULAJ;

  PERFORM pkg_regoss_GenerateDataXTrimestru(vTrimestru, vCursReg, vMoneda);
  select count(*) into nrRanduriModif  from tmp_regoss1 rs1 where coalesce(rs1.modificari,0) = 1;

  if nrRanduriModif = 0 THEN
    select count(*) into nrRanduriModif
    from regoss1 rs1
    left join tmp_regoss1 trs1 on trs1.codregoss1 = rs1.codregoss1
    where rs1.codregoss = RecID and trs1.codregoss1 is null;
  END IF;

  if (nrRanduriModif &gt; 0) THEN
    update jurnal1 j1 set dirty = 1 where j1.TIPDOC = 108 AND j1.CODDOC = RECID;
  end if;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regoss_sp_insertrecord</obj_name>
  <obj_hashval>97296d3e8735b4d48f1ec72ba45f727c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regoss_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 04.11.2022 - sinc. Oracle
  DELETE FROM TMP_REGOSS;
  INSERT INTO TMP_REGOSS (CodRegOSS) VALUES (0);
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regoss_sp_lockrecord</obj_name>
  <obj_hashval>9353c9bc1d652aa6cf90f9a18901bb1e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regoss_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
    tmp NUMERIC(20);
  BEGIN
    SELECT CODREGOSS INTO tmp FROM REGOSS WHERE CODREGOSS = RecID FOR UPDATE NOWAIT;
  END;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_codnextreg</obj_name>
  <obj_hashval>31097cf49ce0a1730187ab61ca3a108e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_codnextreg(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REGPART.CODNEXTREG')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_conditie_avans_facturat</obj_name>
  <obj_hashval>78f12d4ef94b08157e9d4cd63d404962</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_conditie_avans_facturat(INOUT wme_result numeric, INOUT asemnificatie numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  --Bogdan 18.08.2020
  IF aSEMNIFICATIE IN (110, 210, 310, 410) THEN
    select pkg_regpart_getinclusiv_avans_facturat.WME_Result from pkg_regpart_getinclusiv_avans_facturat(null,null) into WME_Result;
    RETURN;
  ELSE
    WME_Result :=  1;
    RETURN;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_conditie_avans_pe_nc</obj_name>
  <obj_hashval>15d5544537b4a02e5aad66d33d8af878</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_conditie_avans_pe_nc(asemnificatie numeric, aicont numeric)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 26.08.2025
   IF  aSEMNIFICATIE IN (1200, 1201) AND  aICONT  IN (12) THEN RETURN current_setting('PKG_REGPART.INCLUSIV_AVANS_FACTURAT')::numeric;
    ELSE RETURN 1;
  END IF;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_conditie_avize</obj_name>
  <obj_hashval>5932a8696d6c5dca7d3da4a2f56a6d9b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_conditie_avize(INOUT wme_result numeric, INOUT aicont numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  --Bogdan 18.08.2020
  IF aICONT IN (6, 7) THEN
    select pkg_regpart_getinclusivavize.WME_Result from pkg_regpart_getinclusivavize(null,null) into WME_Result;
    RETURN;
  ELSE
    WME_Result :=  1;
    RETURN;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_conditie_cecuri</obj_name>
  <obj_hashval>d29a49424e26f0645341d88738e02f3b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_conditie_cecuri(INOUT wme_result numeric, INOUT asemnificatie numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  --Bogdan 18.08.2020
  IF aSEMNIFICATIE IN (500, 600) THEN
    select pkg_regpart_getinclusiv_cecuri.WME_Result from pkg_regpart_getinclusiv_cecuri(null,null) into WME_Result;
    RETURN;
  ELSE
    WME_Result :=  1;
    RETURN;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_conditie_garantii</obj_name>
  <obj_hashval>af0c7545196bb07a308a541fc13fb0ab</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_conditie_garantii(INOUT wme_result numeric, INOUT asemnificatie numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  --Bogdan 18.08.2020
  IF aSEMNIFICATIE IN (120, 220) THEN
    select pkg_regpart_getinclusiv_garantii.WME_Result from pkg_regpart_getinclusiv_garantii(null,null) into WME_Result;
    RETURN;
  ELSE
    WME_Result :=  1;
    RETURN;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_conditie_icont_avans_facturat</obj_name>
  <obj_hashval>efc8b711924f1b369a105a03e831bd0d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_conditie_icont_avans_facturat(INOUT wme_result numeric, INOUT aicont numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  --Bogdan 18.08.2020
  IF aICONT IN (4, 5) THEN
    select pkg_regpart_inclusiv_avans_facturat.WME_Result from pkg_regpart_inclusiv_avans_facturat(null,null) into WME_Result;
    RETURN;
  ELSE
    WME_Result :=  1;
    RETURN;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_conditie_marja_regavize</obj_name>
  <obj_hashval>7e8c6832894db8642d6cce47b9c6510f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_conditie_marja_regavize(INOUT wme_result numeric, INOUT sold numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
declare
  vMarjaRegAvize double precision;
begin
  --BOGDAN 17.08.2020
  select pkg_regpart_getmarjaregavize.WME_Result from pkg_regpart_getmarjaregavize(null,null) into vMarjaRegAvize;
  IF  ABS(SOLD) &gt; ABS(vMarjaRegAvize) THEN
      WME_Result :=  1;
      RETURN;
  ELSE
      WME_Result :=  0;
      RETURN;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_data_doc_corecta</obj_name>
  <obj_hashval>014f6dd8df479c6c6691cca3ab5445a7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_data_doc_corecta(INOUT wme_result numeric, INOUT datadoc date, INOUT datareg date, INOUT datanextreg date)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  RET numeric := 0;
BEGIN
  --Florin 19.03.2021 - fixat 45565
  IF (current_setting('PKG_REGPART.DATANEXTREG', TRUE)) IS NULL THEN
    IF  DATADOC &gt; DATAREG THEN
      RET := 1;
    END IF;
  ELSE
    IF (DATADOC &gt; DATAREG)  and (DATADOC &lt;= (current_setting('PKG_REGPART.DATANEXTREG', TRUE))) THEN
      RET := 1;
    END IF;
  END IF;

  WME_Result :=  RET;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_data_doc_corecta</obj_name>
  <obj_hashval>a51ad7b928e98b3e0e59d70985b91800</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_data_doc_corecta(datadoc date, datareg date, datanextreg date)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
DECLARE
  RET numeric := 0;
begin
  --Bogdan 17.08.2020
  IF (datanextreg IS null) THEN
    IF  DATADOC &gt; DATAREG THEN
      RET := 1;
    END IF;
  ELSE
    IF (DATADOC &gt; DATAREG)  and (DATADOC &lt;= datanextreg) THEN
      RET := 1;
    END IF;
  END IF;
  return RET;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_diferente</obj_name>
  <obj_hashval>84c7f865af5732e7195d5f2845646578</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_diferente(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REGPART.DIFERENTE')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_generarereg</obj_name>
  <obj_hashval>20ed5d5bebb69d67d412890636f22304</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_generarereg()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC              RECORD;
  V_REG1CONT         RECORD;
  REG1_IDX_LOCAL     numeric;
  REG1CONT_IDX_LOCAL numeric;
BEGIN
  --Florin 07.02.2023 - sinc. Oracle
  --Bogdan 18.08.2020
  --Bogdan 22.09.2020
  DELETE FROM TMP_REG1;
  REG1_IDX_LOCAL := 0;

  PERFORM PKG_REGPART_MAKE_REGPART_LUNA();

  FOR V_REC IN (SELECT RP.*, P.DEN_PART FROM TMP_REGPART_LUNA RP LEFT JOIN NPART P ON  P.CODPART = RP.CODPART) LOOP
    IF  ABS( V_REC.SoldDoc * current_setting('PKG_REG.CURS_REG',true)::numeric - V_REC.SoldDocVal) &gt; 0.0000001  THEN
      REG1_IDX_LOCAL := REG1_IDX_LOCAL + 1;
      INSERT INTO TMP_REG1 (
            CodReg1, CodGeneral, Cont, PrefixDoc, NrDoc, DataDoc, CodPart, DenPart, SimbolCont,
            SoldDocVal, SoldDoc, SoldDocReg, Diferenta, Document, CodGest, Semn, Curs,
            Semnificatie, CoefProvizion, SUBUNITATEA, CODOBLIGPIF)
      values (
          -1 * REG1_IDX_LOCAL,
          V_REC.CodGeneral,
          V_REC.ICONT,
          V_REC.PrefixDoc,
          V_REC.NrDoc,
          V_REC.DataDoc,
          V_REC.CodPart,
          V_REC.Den_Part,
          (SELECT WME_RESULT
           FROM PKG_PLANCONTURI_GETSIMBOLCONT(NULL, (SELECT WME_RESULT
                                                     FROM PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(NULL, V_REC.Semnificatie, V_REC.ICont, V_REC.CodIOPart1)))),
          V_REC.SoldDocVal,
          V_REC.SoldDoc,
          V_REC.SoldDoc * current_setting('PKG_REG.CURS_REG',true)::numeric,
          V_REC.SoldDoc * current_setting('PKG_REG.CURS_REG',true)::numeric - V_REC.SoldDocVal,
          (CASE WHEN  V_REC.Semnificatie = 1303 THEN 'Litigii ' || coalesce(V_REC.PREFIXDOC,'') || coalesce(V_REC.NRDOC::varchar,'') || '/' || coalesce(TO_CHAR( V_REC.DATADOC, 'DD.MM.YYYY'),'')
                ELSE coalesce(V_REC.PREFIXDOC,'') || coalesce(V_REC.NRDOC::varchar,'') || '/' || coalesce(TO_CHAR( V_REC.DATADOC, 'DD.MM.YYYY'),'') END ) ,
           V_REC.CodGest,
           1,
           V_REC.Curs,
           V_REC.Semnificatie,
           V_REC.CoefProvizion,
           V_REC.SUBUNITATEA,
           V_REC.CODOBLIGPIF);
    END IF;
  END LOOP;

  FOR V_REC IN (
      SELECT R1.CODREG1,
      (SELECT WME_RESULT FROM PKG_TREZOR_CODCONTCEC(null, O.CONTBANKTRANZACTIE, O.SEMNIFICATIE, T1.TIPDECONT, T1.obiecttranz, GetAnLucru(), GETLunaLUCRU())) CodCont
      FROM TMP_REG1 R1, OBLIGPIF O, GENERAL G, TREZOR1 T1
      WHERE
         R1.CODOBLIGPIF = O.CODOBLIGPIF
         AND O.SEMNIFICATIE IN (500, 600)
         AND  G.CODGENERAL = O.CODGENERAL
         AND  T1.CODTREZOR1 = G.CODDOC
  ) LOOP
    UPDATE TMP_REG1
      SET CONT = V_REC.CODCONT, SIMBOLCONT = PKG_PLANCONTURI_GETSIMBOLCONT(V_REC.CODCONT)
      WHERE CODREG1 = V_REC.CODREG1;
  END LOOP;

  DELETE FROM TMP_REG1CONT;

  REG1CONT_IDX_LOCAL := 0;

  FOR V_REG1CONT IN (
      SELECT SUM( SoldDoc) AS SOLDDOC,
          SUM( SoldDocVal) AS SOLDDOCVAL,
          SUM( SoldDocReg) AS SOLDDOCREG,
          SUM( (  SoldDocReg)  - (  SoldDocVal) ) AS DIFERENTA,
          Cont,
          SimbolCont
      FROM TMP_REG1
      GROUP BY Cont, SimbolCont
  ) LOOP
      REG1CONT_IDX_LOCAL := REG1CONT_IDX_LOCAL + 1;
      INSERT INTO TMP_REG1CONT (CodReg1Cont, SoldDoc, SoldDocVal, SoldDocReg, Diferenta, Cont, SimbolCont)
      values (
        -1 * REG1CONT_IDX_LOCAL,
        V_REG1CONT.SoldDoc,
        V_REG1CONT.SoldDocVal,
        V_REG1CONT.SoldDocReg,
        V_REG1CONT.Diferenta,
        V_REG1CONT.Cont,
        V_REG1CONT.SimbolCont
        );
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_get_curs_reg_provizion</obj_name>
  <obj_hashval>e981dac206a9cc1833c7bee74578880f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_get_curs_reg_provizion(INOUT wme_result numeric, INOUT acodobligpif numeric, INOUT aan numeric, INOUT aluna numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCURS     NUMERIC;   --double precision;
  aCURSREG  NUMERIC;   --double precision;
  aANI      numeric;
  aLUNAI    numeric;
  aCODREG   numeric;
  xAN       numeric;
  xLUNA     numeric;
  ANOBLIG   numeric;
  LUNAOBLIG numeric;
  CURSOBLIG NUMERIC;  --double precision;
BEGIN
  --Adina 14 august 2020
  BEGIN
    SELECT CURS INTO aCURS FROM GENERAL G, OBLIGPIF O WHERE O.CODOBLIGPIF = aCODOBLIGPIF AND  G.CODGENERAL = O.CODGENERAL;
  EXCEPTION WHEN OTHERS THEN
    aCURS := 0;
  END;

  BEGIN
    SELECT C.AN, C.LUNA, G.CURS INTO ANOBLIG, LUNAOBLIG, CURSOBLIG
    FROM COMPENS C, GENERAL G, OBLIGPIF O
    WHERE O.CODOBLIGPIF = aCODOBLIGPIF AND  G.CODGENERAL = O.CODGENERAL AND  G.TIPDOC = 28 AND  C.CODCOMPENS = G.CODDOC;
  EXCEPTION WHEN OTHERS THEN
    ANOBLIG := 0;
    LUNAOBLIG := 0;
  END;

  IF  ANOBLIG = aAN AND  LUNAOBLIG = aLUNA THEN
    WME_Result :=  CURSOBLIG;
    RETURN;
  END IF;

  SELECT ANINITIAL, LUNAINITIALA INTO aANI, aLUNAI FROM FIRMALUNI;

  xAN   := aAN;
  xLuna := aLuna;

  SELECT  NEWAN, newLuna INTO xAN, xLUNA from pkg_globals_Calculeaza_Luna_Precedenta(xAN, xLUNA, xAN, xLUNA);

  WHILE (xAN * 12 + xLUNA) &gt;= (aANI * 12 + aLUNAI) LOOP
      BEGIN
         SELECT  R.CODREG, R.CURS
          INTO  aCODREG,  aCURSREG
        FROM REG R, REG1 R1
        WHERE
          R.AN = xAN
          AND R.LUNA = xLUNA
          AND R1.CODOBLIGPIF = aCODOBLIGPIF
          AND R1.CODREG = R.CODREG
          AND R.TIPREG = 46;
      EXCEPTION WHEN OTHERS THEN aCODREG := 0;
        END;

    IF aCODREG  &gt; 0  THEN
      IF COALESCE(fnc_GetValConstanta('RegProviz', xAN, xLUNA),'0') = '1' THEN
            WME_RESULT := aCURSREG;
            RETURN;
          END  IF;
      END IF;

      SELECT  NEWAN, newLuna INTO xAN, xLUNA from pkg_globals_Calculeaza_Luna_Precedenta(xAN, xLUNA, xAN, xLUNA);
  END LOOP;

  WME_Result :=  aCURS;
  RETURN;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_get_v_regpart_de_stins_sql</obj_name>
  <obj_hashval>b78535cef8d8319103aa3f7158a4ab78</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_get_v_regpart_de_stins_sql()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
declare
  vSQL varchar;
BEGIN
  --Florin 05.09.2023 - fixat 59296
  --Bogdan 17.08.2020
  vSQL := 'SELECT
         CODOBLIGPIF,
         CODGENERAL,
         VALOARE,
         ICONT,
         SEMNIFICATIE,
         CODPART,
         CODIOPART1,
         CODGEST,
         CURS,
         TVA,
         STINS,
        COEFPROVIZION
       FROM
         (
            SELECT
              O.CODOBLIGPIF,
              O.CODGENERAL,
              COALESCE(O.VALOARE, 0) - COALESCE(G.TVA, 0) AS VALOARE,
              O.ICONT,
              O.SEMNIFICATIE,
              O.CODPART,
              IO.CODIOPART1,
              O.CODGEST,
               COALESCE(GREG.CURS, G.CURS) AS CURS,
              G.TVA,
              CASE WHEN O.VALOARE &lt; 0 THEN -S.VALOARE ELSE S.VALOARE END AS STINS,
              O.COEFPROVIZION
            FROM
              OBLIGPIF O
              LEFT OUTER JOIN TMP_STINGERE_LUNA         S    ON S.CODSTINSPIF   = O.CODOBLIGPIF
              LEFT OUTER JOIN TMP_IOPARTLUNA            IO   ON IO.CODPART      = O.CODPART
              LEFT OUTER JOIN GENERAL                   G    ON G.CODGENERAL    = O.CODGENERAL
              LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
              LEFT OUTER JOIN INTRARI                   I    ON  I.CODINTR      = G.CODDOC
            WHERE
             O.SEMNIFICATIE IN (100, 110, 120) AND I.AN = getanlucru() AND I.LUNA = getlunalucru()
             AND (I.OPERAT = 1)AND(I.ANULAT = 0)
             AND G.MONEDA = pkg_reg_getmonedareg()
             AND COALESCE(G.FaraReg, 0) = 0
           UNION ALL
            SELECT
              O.CODOBLIGPIF,
              O.CODGENERAL,
              COALESCE(O.VALOARE, 0) - COALESCE(G.TVA, 0) AS VALOARE,
              O.ICONT,
              O.SEMNIFICATIE,
              O.CODPART,
              IO.CODIOPART1,
              O.CODGEST,
               COALESCE(GREG.CURS, G.CURS) AS CURS,
              G.TVA,
              CASE WHEN O.VALOARE &lt; 0 THEN -S.VALOARE ELSE S.VALOARE END AS STINS,
              O.COEFPROVIZION
            FROM
              OBLIGPIF O
              LEFT OUTER JOIN TMP_STINGERE_LUNA         S    ON S.CODSTINSPIF   = O.CODOBLIGPIF
              LEFT OUTER JOIN TMP_IOPARTLUNA            IO   ON IO.CODPART      = O.CODPART
              LEFT OUTER JOIN GENERAL                   G    ON G.CODGENERAL    = O.CODGENERAL
              LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
              LEFT OUTER JOIN DVI                       D    ON G.CODDOC        = D.CODDVI
              LEFT OUTER JOIN INTRARI                   I    ON I.CODINTR       = D.CODINTR
            WHERE
              O.SEMNIFICATIE IN (130) AND I.AN = getanlucru() AND I.LUNA = getlunalucru()
              AND (I.OPERAT = 1)AND(I.ANULAT = 0)
              AND G.MONEDA = pkg_reg_getmonedareg()
              AND COALESCE(G.FaraReg, 0) = 0
            UNION ALL
              SELECT
                O.CODOBLIGPIF,
                O.CODGENERAL,
                O.VALOARE AS VALOARE,
                O.ICONT,
                O.SEMNIFICATIE,
                O.CODPART,
                IO.CODIOPART1,
                O.CODGEST,
                 COALESCE(GREG.CURS, G.CURS) AS CURS,
                G.TVA,
                S.VALOARE AS STINS,
                   O.COEFPROVIZION
              FROM
                   OBLIGPIF O
                   LEFT OUTER JOIN TMP_STINGERE_LUNA         S    ON S.CODSTINSPIF   = O.CODOBLIGPIF
                   LEFT OUTER JOIN TMP_IOPARTLUNA            IO   ON IO.CODPART      = O.CODPART
                   LEFT OUTER JOIN GENERAL                   G    ON G.CODGENERAL    = O.CODGENERAL
                   LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                   LEFT OUTER JOIN INTRARI                   I    ON  I.CODINTR      = G.CODDOC
              WHERE
                  O.SEMNIFICATIE IN (140) AND I.TIPDOC = 2 AND I.AN = getanlucru() AND I.LUNA = getlunalucru()
                  AND (I.OPERAT = 1)AND(I.ANULAT = 0)
                  AND G.MONEDA = pkg_reg_getmonedareg()
                  AND COALESCE(G.FaraReg, 0) + COALESCE(I.FaraReg, 0) = 0
            UNION ALL
              SELECT
                O.CODOBLIGPIF,
                O.CODGENERAL,
                O.VALOARE AS VALOARE,
                O.ICONT,
                O.SEMNIFICATIE,
                O.CODPART,
                IO.CODIOPART1,
                O.CODGEST,
                 COALESCE(GREG.CURS, G.CURS) AS CURS,
                G.TVA,
                S.VALOARE AS STINS,
                   O.COEFPROVIZION
              FROM
                OBLIGPIF O
                LEFT OUTER JOIN TMP_STINGERE_LUNA         S    ON S.CODSTINSPIF   = O.CODOBLIGPIF
                LEFT OUTER JOIN TMP_IOPARTLUNA            IO   ON IO.CODPART      = O.CODPART
                LEFT OUTER JOIN GENERAL                   G    ON G.CODGENERAL    = O.CODGENERAL
                LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                LEFT OUTER JOIN IESIRI                    I    ON  I.CODIES       = G.CODDOC
              WHERE
                O.SEMNIFICATIE IN (240) AND I.TIPDOC = 20 AND I.AN = getanlucru() AND I.LUNA = getlunalucru()
                AND (I.OPERAT = 1)AND(I.ANULAT = 0)
                AND G.MONEDA = pkg_reg_getmonedareg()
                 AND COALESCE(G.FaraReg, 0) +  COALESCE(I.FaraReg, 0) = 0
            UNION ALL
              SELECT
                O.CODOBLIGPIF,
                O.CODGENERAL,
                COALESCE(O.VALOARE, 0) - COALESCE(G.TVA, 0) AS VALOARE,
                O.ICONT,
                O.SEMNIFICATIE,
                O.CODPART,
                IO.CODIOPART1,
                O.CODGEST,
                 COALESCE(GREG.CURS, G.CURS) AS CURS,
                G.TVA,
                CASE WHEN O.VALOARE &lt; 0 THEN -S.VALOARE ELSE S.VALOARE END AS STINS,
                O.COEFPROVIZION
              FROM
                OBLIGPIF O
                LEFT OUTER JOIN TMP_STINGERE_LUNA         S    ON S.CODSTINSPIF   = O.CODOBLIGPIF
                LEFT OUTER JOIN TMP_IOPARTLUNA            IO   ON IO.CODPART      = O.CODPART
                LEFT OUTER JOIN GENERAL                   G    ON G.CODGENERAL    = O.CODGENERAL
                LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                LEFT OUTER JOIN IESIRI                    I    ON  I.CODIES       = G.CODDOC
              WHERE
                O.SEMNIFICATIE IN (200, 210, 220) AND I.AN = getanlucru() AND I.LUNA = getlunalucru()
                AND (I.OPERAT = 1)AND(I.ANULAT = 0)
                AND G.MONEDA = pkg_reg_getmonedareg()
                AND COALESCE(G.FaraReg, 0) = 0
            UNION ALL
              SELECT
                O.CODOBLIGPIF,
                O.CODGENERAL,
                COALESCE(O.VALOARE, 0) - COALESCE(G.TVA, 0) AS VALOARE,
                O.ICONT,
                O.SEMNIFICATIE,
                O.CODPART,
                IO.CODIOPART1,
                O.CODGEST,
                 COALESCE(GREG.CURS, G.CURS) AS CURS,
                G.TVA,
                CASE WHEN O.VALOARE &lt; 0 THEN -S.VALOARE ELSE S.VALOARE END AS STINS,
                O.COEFPROVIZION
              FROM
                OBLIGPIF O
                LEFT OUTER JOIN TMP_STINGERE_LUNA         S    ON S.CODSTINSPIF   = O.CODOBLIGPIF
                LEFT OUTER JOIN TMP_IOPARTLUNA            IO   ON IO.CODPART      = O.CODPART
                LEFT OUTER JOIN GENERAL                   G    ON G.CODGENERAL    = O.CODGENERAL
                LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                LEFT OUTER JOIN TREZOR1                   T1   ON T1.CODTREZOR1   = G.CODDOC
                LEFT OUTER JOIN TREZOR                    T    ON T.CODTREZOR     = T1.CODTREZOR
              WHERE
               ((T1.INITIALIZARI = 1)OR(COALESCE(T1.INITIALIZARI, 0) &lt;&gt; 1 AND T.OPERAT = 1)) AND
                G.TIPDOC IN (29, 30, 31, 33) AND
                T1.AN = getanlucru() AND
                T1.LUNA = getlunalucru() AND
                G.SEMNIFICATIE IN (310, 410, 330, 430, 500, 600)
                AND G.MONEDA = pkg_reg_getmonedareg()
                AND COALESCE(G.FaraReg, 0) = 0
            UNION ALL
              SELECT
                O.CODOBLIGPIF,
                O.CODGENERAL,
                O.VALOARE,
                O.ICONT,
                O.SEMNIFICATIE,
                O.CODPART,
                IO.CODIOPART1,
                O.CODGEST,
                 COALESCE(GREG.CURS, G.CURS) AS CURS,
                G.TVA,
                CASE WHEN O.VALOARE &lt; 0 THEN -S.VALOARE ELSE S.VALOARE END AS STINS,
                O.COEFPROVIZION
              FROM
                OBLIGPIF O
                LEFT OUTER JOIN TMP_STINGERE_LUNA         S    ON S.CODSTINSPIF   = O.CODOBLIGPIF
                LEFT OUTER JOIN TMP_IOPARTLUNA            IO   ON IO.CODPART      = O.CODPART
                LEFT OUTER JOIN GENERAL                   G    ON G.CODGENERAL    = O.CODGENERAL
                LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                LEFT OUTER JOIN NC1                       N1   ON  N1.CODNC1      = G.CODDOC
              WHERE
                O.SEMNIFICATIE IN (1200, 1201)  AND N1.AN = getanlucru() AND N1.LUNA = getlunalucru()
                AND G.MONEDA = pkg_reg_getmonedareg()
                AND COALESCE(G.FaraReg, 0) = 0
            UNION ALL
              SELECT
                O.CODOBLIGPIF,
                O.CODGENERAL,
                CASE WHEN O.SEMNIFICATIE = 1303 THEN COALESCE(O.VALOARE, 0) ELSE COALESCE(O.VALOARE, 0) - COALESCE(G.TVA, 0) END
                AS VALOARE,
                O.ICONT,
                O.SEMNIFICATIE,
                O.CODPART,
                IO.CODIOPART1,
                O.CODGEST,
                 COALESCE(GREG.CURS, G.CURS) AS CURS,
                G.TVA,
                CASE WHEN O.VALOARE &lt; 0 THEN -S.VALOARE ELSE S.VALOARE END AS STINS,
                O.COEFPROVIZION
              FROM
                OBLIGPIF O
                LEFT OUTER JOIN TMP_STINGERE_LUNA         S    ON S.CODSTINSPIF   = O.CODOBLIGPIF
                LEFT OUTER JOIN TMP_IOPARTLUNA            IO   ON IO.CODPART      = O.CODPART
                LEFT OUTER JOIN GENERAL                   G    ON G.CODGENERAL    = O.CODGENERAL
                LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                LEFT OUTER JOIN COMPENS                   C    ON C.CODCOMPENS    = G.CODDOC
              WHERE
                O.SEMNIFICATIE IN (1301, 1351, 1303) AND C.AN = getanlucru() AND C.LUNA = getlunalucru()
                AND G.MONEDA = pkg_reg_getmonedareg()
                AND COALESCE(G.FaraReg, 0) = 0
          ) I_PG';
  return vSQL;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_get_v_regpart_lunaprec_sql</obj_name>
  <obj_hashval>03028ac7145310415e357660779edecb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_get_v_regpart_lunaprec_sql()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
declare
  vSQL varchar;
begin
  vSQL :=
       'SELECT
          O.CODOBLIGPIF,
          O.CODGENERAL,
          CASE
           WHEN O.SEMNIFICATIE IN (140, 240, 1303) THEN COALESCE(OL.REST, 0)
           ELSE COALESCE(OL.REST, 0) - COALESCE(OL.RESTTVA, 0)
          END AS VALOARE,
          O.ICONT,
          O.SEMNIFICATIE,
          O.CODPART,
          IO.CODIOPART1,
           COALESCE(O.CODGEST, 0) AS CODGEST,
           COALESCE(GREG.CURS, G.CURS) AS CURS,
          G.TVA,
          CASE
            WHEN O.VALOARE &lt; 0 AND (NOT O.SEMNIFICATIE IN (140, 240)) THEN -S.VALOARE
            ELSE S.VALOARE
          END AS STINS,
          O.COEFPROVIZION
        FROM
          OBLIGPIFLUNA OL,
          OBLIGPIF O
          LEFT OUTER JOIN TMP_STINGERE_LUNA  S  ON S.CODSTINSPIF = O.CODOBLIGPIF
          LEFT OUTER JOIN TMP_IOPARTLUNA     IO ON IO.CODPART    = O.CODPART,
          GENERAL G
          LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
        WHERE
          OL.AN       = getanprecedent()
          AND OL.LUNA = getlunaprecedenta()
          AND OL.REST &lt;&gt; 0
          AND OL.CODOBLIGPIF = O.CODOBLIGPIF
          AND G.CODGENERAL   = O.CODGENERAL
          AND G.MONEDA = pkg_reg_getmonedareg()
          AND O.SEMNIFICATIE IN (100, 110, 120, 130, 140, 240, 200, 210, 220, 310, 410, 330, 430, 500, 600, 1200, 1201, 1301, 1351, 1303)
          AND COALESCE(G.FaraReg, 0) = 0
          AND PKG_GLOBALS_ANLUNAAVIZOK(G.TIPDOC, G.CODDOC) = 1';
  return vSQL;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_getcodnextreg</obj_name>
  <obj_hashval>56921ae866f989ac49261fbfdd9d23d8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_getcodnextreg(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REGPART.CODNEXTREG')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_getinclusiv_garantii</obj_name>
  <obj_hashval>8a2b97bb8f683de2d9e51fc6459d3e85</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_getinclusiv_garantii(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REGPART.INCLUSIV_GARANTII')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_getinclusiv_litigii</obj_name>
  <obj_hashval>f21b79c0de6e86943ce3924ab3069a12</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_getinclusiv_litigii(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REGPART.INCLUSIV_LITIGII')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 1;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_getinclusivavize</obj_name>
  <obj_hashval>537883b87bff8c6f1c9f03d9153067ed</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_getinclusivavize(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REGPART.INCLUSIVAVIZE')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_getmarjaregavize</obj_name>
  <obj_hashval>ff240a21b6ec9af9c53ae1b82a3b52cd</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_getmarjaregavize(INOUT wme_result double precision, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REGPART.MARJAREGAVIZE')),'99999999999.9999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_inclusiv_avans_facturat</obj_name>
  <obj_hashval>6b52db97246ebe7baa066dcb92a91a27</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_inclusiv_avans_facturat(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REGPART.INCLUSIV_AVANS_FACTURAT')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 1;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_inclusiv_cecuri</obj_name>
  <obj_hashval>9bf9efd43bc2e99b8c21f59d00257803</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_inclusiv_cecuri(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REGPART.INCLUSIV_CECURI')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_inclusiv_garantii</obj_name>
  <obj_hashval>cfffe448cf4bd4f97aced72dcd2b5cf6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_inclusiv_garantii(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REGPART.INCLUSIV_GARANTII')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_inclusiv_litigii</obj_name>
  <obj_hashval>132b67a7dc9e29c0a9fd342b37883a64</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_inclusiv_litigii(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REGPART.INCLUSIV_LITIGII')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 1;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_inclusivavize</obj_name>
  <obj_hashval>ee7db0d38cc5e3c6337590554bb0b9e8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_inclusivavize(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REGPART.INCLUSIVAVIZE')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_make_info_stinse_luna</obj_name>
  <obj_hashval>74bc63147afaca14e4e145121f53b22b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_make_info_stinse_luna()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_INFOSTINSE;
  INSERT INTO TMP_INFOSTINSE(CODGENERAL, CODDOC, TIPDOC, MONEDA)
  SELECT CODGENERAL, CODDOC, TIPDOC, MONEDA
  FROM (SELECT GSTINS.CODGENERAL, GSTINS.CODDOC, GSTINS.TIPDOC, GSTINS.MONEDA
        FROM STINGERE S, OBLIGPIF O_S, GENERAL G_S, TREZOR1 T1, OBLIGPIF OSTINS, GENERAL GSTINS
        WHERE O_S.CODOBLIGPIF = S.CODSTINGATORPIF AND  G_S.CODGENERAL = O_S.CODGENERAL AND G_S.TIPDOC IN (29, 30, 31, 32, 33) AND  T1.CODTREZOR1 = G_S.CODDOC AND  T1.AN = (SELECT WME_RESULT FROM PKG_GLOBALS_GETANTEMP(NULL,NULL)) AND  T1.LUNA = (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNATEMP(NULL,NULL)) AND  COALESCE( T1.ANULAT, 0) = 0 AND  OSTINS.CODOBLIGPIF = S.CODSTINSPIF AND  GSTINS.CODGENERAL = OSTINS.CODGENERAL AND  GSTINS.MONEDA &lt;&gt; 0 AND  COALESCE( G_S.FaraReg, 0) = 0
        union ALL
        SELECT GSTINS.CODGENERAL, GSTINS.CODDOC, GSTINS.TIPDOC, GSTINS.MONEDA
        FROM STINGERE S, OBLIGPIF O_S, GENERAL G_S, COMPENS C, OBLIGPIF OSTINS, GENERAL GSTINS
        WHERE O_S.CODOBLIGPIF = S.CODSTINGATORPIF AND  G_S.CODGENERAL = O_S.CODGENERAL AND  G_S.TIPDOC = 28 AND  C.CODCOMPENS = G_S.CODDOC AND  C.AN = (SELECT WME_RESULT FROM PKG_GLOBALS_GETANTEMP(NULL,NULL)) AND  C.LUNA = (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNATEMP(NULL,NULL)) AND  OSTINS.CODOBLIGPIF = S.CODSTINSPIF AND  GSTINS.CODGENERAL = OSTINS.CODGENERAL AND  GSTINS.MONEDA &lt;&gt; 0 AND  COALESCE( G_S.FaraReg, 0) = 0
        union ALL
        SELECT GSTINS.CODGENERAL, GSTINS.CODDOC, GSTINS.TIPDOC, GSTINS.MONEDA
        FROM STINGERE S, OBLIGPIF O_S, GENERAL G_S, INTRARI I, OBLIGPIF OSTINS, GENERAL GSTINS
        WHERE O_S.CODOBLIGPIF = S.CODSTINGATORPIF AND  G_S.CODGENERAL = O_S.CODGENERAL AND G_S.TIPDOC IN (1, 2, 3, 4, 5, 6, 7, 8, 9) AND  I.CODINTR = G_S.CODDOC AND  I.AN = (SELECT WME_RESULT FROM PKG_GLOBALS_GETANTEMP(NULL,NULL)) AND  I.LUNA = (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNATEMP(NULL,NULL)) AND  I.OPERAT = 1 AND  I.ANULAT = 0 AND  OSTINS.CODOBLIGPIF = S.CODSTINSPIF AND  GSTINS.CODGENERAL = OSTINS.CODGENERAL AND  GSTINS.MONEDA &lt;&gt; 0 AND  COALESCE( G_S.FaraReg, 0) = 0
        union ALL
        SELECT GSTINS.CODGENERAL, GSTINS.CODDOC, GSTINS.TIPDOC, GSTINS.MONEDA
        FROM STINGERE S, OBLIGPIF O_S, GENERAL G_S, IESIRI I, OBLIGPIF OSTINS, GENERAL GSTINS
        WHERE O_S.CODOBLIGPIF = S.CODSTINGATORPIF AND  G_S.CODGENERAL = O_S.CODGENERAL AND G_S.TIPDOC IN (19, 20, 21, 22, 23, 24, 25, 26) AND  I.CODIES = G_S.CODDOC AND  I.AN = (SELECT WME_RESULT FROM PKG_GLOBALS_GETANTEMP(NULL,NULL)) AND  I.LUNA = (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNATEMP(NULL,NULL)) AND  I.OPERAT = 1 AND  I.ANULAT = 0 AND  OSTINS.CODOBLIGPIF = S.CODSTINSPIF AND  GSTINS.CODGENERAL = OSTINS.CODGENERAL AND  GSTINS.MONEDA &lt;&gt; 0 AND  COALESCE( G_S.FaraReg, 0) = 0
        ) A_PG;

  UPDATE TMP_INFOSTINSE INF
  SET
  (AN, LUNA) = (SELECT AN, LUNA FROM INTRARI I WHERE CODINTR = INF.CODDOC)
  WHERE INF.TIPDOC &gt;= 1 AND  INF.TIPDOC &lt;= 10;

  UPDATE TMP_INFOSTINSE INF
  SET
  (AN, LUNA) = (SELECT AN, LUNA FROM IESIRI I WHERE CODIES = INF.CODDOC)
  WHERE INF.TIPDOC &gt;= 19 AND  INF.TIPDOC &lt;= 26;

  UPDATE TMP_INFOSTINSE INF
  SET
  (AN, LUNA) = (SELECT T.AN, T.LUNA FROM TREZOR T, TREZOR1 T1 WHERE CODTREZOR1 = INF.CODDOC AND  T.CODTREZOR = T1.CODTREZOR)
  WHERE INF.TIPDOC &gt;= 29 AND  INF.TIPDOC &lt;= 33;

  UPDATE TMP_INFOSTINSE INF
  SET
  (AN, LUNA) = (SELECT AN, LUNA FROM COMPENS C WHERE CODCOMPENS = INF.CODDOC)
  WHERE INF.TIPDOC = 28;

  UPDATE TMP_INFOSTINSE INF
  SET
  (AN, LUNA) = (SELECT N.AN, N.LUNA FROM NC N, NC1 N1 WHERE CODNC1 = INF.CODDOC AND  N.CODNC = N1.CODNC)
  WHERE INF.TIPDOC = 35;

  UPDATE TMP_INFOSTINSE INF
  SET
  CURS = (SELECT R.CURS FROM REG R, REG1 R1
          WHERE R1.CODGENERAL = INF.CODGENERAL AND  R1.CODREG = R.CODREG AND  R.TIPREG = 46 AND  R.CODMONEDA = INF.MONEDA
           AND  R.AN * 12 + R.LUNA = (SELECT MAX( AN * 12 + LUNA) FROM REG R2, REG1 R21
                                      WHERE R21.CODGENERAL = INF.CODGENERAL AND  R21.CODREG = R2.CODREG AND  R2.TIPREG = 46 AND  R2.CODMONEDA = INF.MONEDA
                                       AND  R2.AN * 12 + R2.LUNA &gt;= INF.AN * 12 + INF.LUNA AND  R2.AN * 12 + R2.LUNA &lt;= TO_NUMBER((current_setting('PKG_GLOBALS.ANTEMP')),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_GLOBALS.LUNATEMP')),'999999999999999999')
                                     )
         );
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_make_stingere_luna</obj_name>
  <obj_hashval>79548f8f1cd4730ca55c6b48a0730a90</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_make_stingere_luna()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_STINGERE_LUNA;
  INSERT INTO TMP_STINGERE_LUNA(CODSTINSPIF, VALOARE)
  SELECT CODSTINSPIF, SUM( VALOARE) AS VALOARE
  FROM (SELECT S.CODSTINSPIF, COALESCE( S.VALOARE, 0) - COALESCE( G_S.TVA, 0) AS VALOARE
        FROM STINGERE S, OBLIGPIF O_S, GENERAL G_S, TREZOR1 T1
        WHERE  O_S.CODOBLIGPIF = S.CODSTINGATORPIF AND  G_S.CODGENERAL = O_S.CODGENERAL AND G_S.TIPDOC IN (29, 30, 31, 32, 33) AND  T1.CODTREZOR1 = G_S.CODDOC
          AND  T1.AN   = (SELECT WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL))
          AND  T1.LUNA = (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL))
          AND  COALESCE( T1.ANULAT, 0) = 0 AND  COALESCE( G_S.FaraReg, 0) = 0
        union ALL
        SELECT S.CODSTINSPIF, CASE WHEN  O.SEMNIFICATIE = 1303 THEN S.VALOARE ELSE COALESCE( S.VALOARE, 0) - COALESCE( G_S.TVA, 0) END  AS VALOARE
        FROM STINGERE S, OBLIGPIF O_S, GENERAL G_S, COMPENS C, OBLIGPIF O
        WHERE  O_S.CODOBLIGPIF = S.CODSTINGATORPIF AND  G_S.CODGENERAL = O_S.CODGENERAL AND  G_S.TIPDOC = 28 AND  C.CODCOMPENS = G_S.CODDOC
          AND  C.AN   = (SELECT WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL))
          AND  C.LUNA = (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL))
          AND  S.CODSTINSPIF = O.CODOBLIGPIF AND  COALESCE( G_S.FaraReg, 0) = 0
        union ALL
        SELECT S.CODSTINSPIF, COALESCE( S.VALOARE, 0) - COALESCE( G_S.TVA, 0) AS VALOARE
        FROM STINGERE S, OBLIGPIF O_S, GENERAL G_S, INTRARI I
        WHERE  O_S.CODOBLIGPIF = S.CODSTINGATORPIF AND  G_S.CODGENERAL = O_S.CODGENERAL AND G_S.TIPDOC IN (1, 2, 3, 4, 5, 6, 7, 8, 9) AND  I.CODINTR = G_S.CODDOC
          AND  I.AN   = (SELECT WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL))
          AND  I.LUNA = (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL))
          AND  I.OPERAT = 1 AND  I.ANULAT = 0 AND  COALESCE( G_S.FaraReg, 0) = 0
        union ALL
        SELECT S.CODSTINSPIF, COALESCE( S.VALOARE, 0) - COALESCE( G_S.TVA, 0) AS VALOARE
        FROM STINGERE S, OBLIGPIF O_S, GENERAL G_S, IESIRI I
        WHERE  O_S.CODOBLIGPIF = S.CODSTINGATORPIF AND  G_S.CODGENERAL = O_S.CODGENERAL AND G_S.TIPDOC IN (19, 20, 21, 22, 23, 24, 25, 26) AND  I.CODIES = G_S.CODDOC
          AND  I.AN   = (SELECT WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL))
          AND  I.LUNA = (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL))
          AND  I.OPERAT = 1 AND  I.ANULAT = 0 AND  COALESCE( G_S.FaraReg, 0) = 0
        union ALL
        SELECT OSTINS.CODOBLIGPIF AS CODSTINSPIF,
               (I1.PU * I1.CANT + COALESCE( I1STINS.TVA, 0) * (CASE WHEN I1STINS.PU * I1STINS.CANT = 0 THEN 0 ELSE I1.PU * I1.CANT / (I1STINS.PU * I1STINS.CANT) END)) AS VALOARE
        FROM OBLIGPIF O, GENERAL G, INTRARI I, INTRARI1 I1, INTRLINK IL, INTRARI1 I1STINS, INTRARI ISTINS, GENERAL GSTINS, OBLIGPIF OSTINS
        WHERE  O.SEMNIFICATIE = 140 AND  G.CODGENERAL = O.CODGENERAL AND  G.TIPDOC = 9 AND  I.CODINTR = G.CODDOC AND  I1.CODINTR = I.CODINTR AND  IL.CODINTR1 = I1.CODINTR1
          AND  IL.CODLINIEAVIZ = I1STINS.CODINTR1 AND  ISTINS.CODINTR = I1STINS.CODINTR AND  ISTINS.CODINTR = GSTINS.CODDOC AND  ISTINS.TIPDOC = GSTINS.TIPDOC
          AND  OSTINS.CODGENERAL = GSTINS.CODGENERAL AND  I.OPERAT = 1
          AND ((ISTINS.AN * 12 + ISTINS.LUNA &lt; (SELECT WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL)) * 12 + (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL)) AND  I.AN * 12 + I.LUNA = (SELECT WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL)) * 12 + (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL)))
                OR
               (ISTINS.AN * 12 + ISTINS.LUNA = (SELECT WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL)) * 12 + (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL)) AND  I.AN * 12 + I.LUNA &lt;= (SELECT WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL)) * 12 + (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL)))
              )
          AND  COALESCE( G.FaraReg, 0) = 0
        union ALL
        SELECT OSTINS.CODOBLIGPIF AS CODSTINSPIF,
               ( (D1.PRETIMPORT / I.CURS)  * I1.CANT
                 + COALESCE(I1STINS.TVA, 0) * (CASE WHEN I1STINS.PU * I1STINS.CANT = 0 THEN 0
                                                    ELSE (D1.PRETIMPORT / I.CURS) * I1.CANT / (I1STINS.PU * I1STINS.CANT) END)
               )  AS VALOARE
        FROM OBLIGPIF O, GENERAL G, INTRARI I, INTRARI1 I1
             LEFT JOIN DVI1 D1 ON  D1.CODINTR1 = I1.CODINTR1, INTRLINK IL, INTRARI1 I1STINS, INTRARI ISTINS, GENERAL GSTINS, OBLIGPIF OSTINS
        WHERE  O.SEMNIFICATIE = 140 AND  G.CODGENERAL = O.CODGENERAL AND  G.TIPDOC = 5 AND  I.CODINTR = G.CODDOC AND  I1.CODINTR = I.CODINTR AND  IL.CODINTR1 = I1.CODINTR1
          AND  IL.CODLINIEAVIZ = I1STINS.CODINTR1 AND  ISTINS.CODINTR = I1STINS.CODINTR AND  ISTINS.CODINTR = GSTINS.CODDOC AND  ISTINS.TIPDOC = GSTINS.TIPDOC
          AND  OSTINS.CODGENERAL = GSTINS.CODGENERAL AND  I.OPERAT = 1
          AND ((ISTINS.AN * 12 + ISTINS.LUNA &lt; (SELECT WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL)) * 12 + (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL)) AND  I.AN * 12 + I.LUNA = (SELECT WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL)) * 12 + (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL)))
                OR
               (ISTINS.AN * 12 + ISTINS.LUNA = (SELECT WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL)) * 12 + (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL)) AND  I.AN * 12 + I.LUNA &lt;= (SELECT WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL)) * 12 + (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL)))
              )
          AND  COALESCE( G.FaraReg, 0) = 0
        union ALL
        SELECT OSTINS.CODOBLIGPIF AS CODSTINSPIF,
               (I1.PU * I1.CANT * ( (100 + COALESCE( I1.PROCDISC, 0)) / 100)
                + COALESCE( I1STINS.TVA, 0) * (CASE WHEN  I1STINS.PU * I1STINS.CANT = 0 THEN 0
                                                    ELSE I1.PU * I1.CANT * ( (100 + COALESCE( I1.PROCDISC, 0)) / 100) / (I1STINS.PU * I1STINS.CANT)
                                               END )
               )  AS VALOARE
        FROM OBLIGPIF O, GENERAL G, IESIRI I, IESIRI1 I1, IESLINK IL, IESIRI1 I1STINS, IESIRI ISTINS, GENERAL GSTINS, OBLIGPIF OSTINS
        WHERE  O.SEMNIFICATIE = 240 AND  G.CODGENERAL = O.CODGENERAL AND  G.TIPDOC = 26 AND  I.CODIES = G.CODDOC AND  I1.CODIES = I.CODIES AND  IL.CODIES1 = I1.CODIES1
          AND  IL.CODLINIEAVIZ = I1STINS.CODIES1 AND  ISTINS.CODIES = I1STINS.CODIES AND  ISTINS.CODIES = GSTINS.CODDOC AND  ISTINS.TIPDOC = GSTINS.TIPDOC
          AND  OSTINS.CODGENERAL = GSTINS.CODGENERAL AND  I.OPERAT = 1
          AND ((ISTINS.AN * 12 + ISTINS.LUNA &lt; (SELECT WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL)) * 12 + (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL)) AND  I.AN * 12 + I.LUNA = (SELECT WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL)) * 12 + (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL)))
                OR
               (ISTINS.AN * 12 + ISTINS.LUNA = (SELECT WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL)) * 12 + (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL)) AND  I.AN * 12 + I.LUNA &lt;= (SELECT WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL)) * 12 + (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL)))
              )
          AND  COALESCE( G.FaraReg, 0) = 0
        ) A_PG
  GROUP BY CODSTINSPIF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_make_stingeri_la_data</obj_name>
  <obj_hashval>01d382e0a367050cd699463420e55b47</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_make_stingeri_la_data()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_STINGERE_LUNA;
  INSERT INTO TMP_STINGERE_LUNA(CODSTINSPIF, VALOARE)
  SELECT CODSTINSPIF, SUM( VALOARE) AS VALOARE
  FROM (SELECT S.CODSTINSPIF, COALESCE( S.VALOARE, 0) - COALESCE( G_S.TVA, 0) AS VALOARE
        FROM STINGERE S, OBLIGPIF O_S, GENERAL G_S, TREZOR1 T1, TREZOR T
        WHERE  O_S.CODOBLIGPIF = S.CODSTINGATORPIF AND  G_S.CODGENERAL = O_S.CODGENERAL AND G_S.TIPDOC IN (29, 30, 31, 32, 33) AND  T1.CODTREZOR1 = G_S.CODDOC
           AND  T.CODTREZOR = T1.CODTREZOR AND  T.DATADOC &lt;= (SELECT WME_RESULT FROM PKG_GLOBALS_GETDATASOLDPART(NULL,NULL)) AND  COALESCE( T1.ANULAT, 0) = 0
           AND  COALESCE( G_S.FaraReg, 0) = 0
        union ALL
        SELECT S.CODSTINSPIF, COALESCE( S.VALOARE, 0) - COALESCE( G_S.TVA, 0) AS VALOARE
        FROM STINGERE S, OBLIGPIF O_S, GENERAL G_S, COMPENS C
        WHERE  O_S.CODOBLIGPIF = S.CODSTINGATORPIF AND  G_S.CODGENERAL = O_S.CODGENERAL AND  G_S.TIPDOC = 28 AND  C.CODCOMPENS = G_S.CODDOC
          AND  C.DATADOC &lt;= (SELECT WME_RESULT FROM PKG_GLOBALS_GETDATASOLDPART(NULL,NULL)) AND  COALESCE( G_S.FaraReg, 0) = 0
        union ALL
        SELECT S.CODSTINSPIF, COALESCE( S.VALOARE, 0) - COALESCE( G_S.TVA, 0) AS VALOARE
        FROM STINGERE S, OBLIGPIF O_S, GENERAL G_S, INTRARI I
        WHERE  O_S.CODOBLIGPIF = S.CODSTINGATORPIF AND  G_S.CODGENERAL = O_S.CODGENERAL AND G_S.TIPDOC IN (1, 2, 3, 4, 5, 6, 7, 8, 9) AND  I.CODINTR = G_S.CODDOC
          AND  I.DATADOC &lt;= (SELECT WME_RESULT FROM PKG_GLOBALS_GETDATASOLDPART(NULL,NULL)) AND  I.OPERAT = 1 AND  I.ANULAT = 0 AND  COALESCE( G_S.FaraReg, 0) = 0
        union ALL
        SELECT S.CODSTINSPIF, COALESCE( S.VALOARE, 0) - COALESCE( G_S.TVA, 0) AS VALOARE
        FROM STINGERE S, OBLIGPIF O_S, GENERAL G_S, IESIRI I
        WHERE  O_S.CODOBLIGPIF = S.CODSTINGATORPIF AND  G_S.CODGENERAL = O_S.CODGENERAL AND G_S.TIPDOC IN (16, 19, 20, 21, 22, 23, 24, 25, 26) AND  I.CODIES = G_S.CODDOC
          AND  I.DATADOC &lt;= (SELECT WME_RESULT FROM PKG_GLOBALS_GETDATASOLDPART(NULL,NULL)) AND  I.OPERAT = 1 AND  I.ANULAT = 0 AND  COALESCE( G_S.FaraReg, 0) = 0
        union ALL
        SELECT OSTINS.CODOBLIGPIF AS CODSTINSPIF,
               (I1.PU * I1.CANT + COALESCE(I1STINS.TVA, 0) * (CASE WHEN  I1STINS.PU * I1STINS.CANT = 0 THEN 0 ELSE I1.PU * I1.CANT / (I1STINS.PU * I1STINS.CANT) END)) AS VALOARE
        FROM OBLIGPIF O, GENERAL G, INTRARI I, INTRARI1 I1, INTRLINK IL, INTRARI1 I1STINS, INTRARI ISTINS, GENERAL GSTINS, OBLIGPIF OSTINS
        WHERE  O.  SEMNIFICATIE = 140 AND  G.CODGENERAL = O.CODGENERAL AND  G.TIPDOC = 9 AND  I.CODINTR = G.CODDOC AND  I1.CODINTR = I.CODINTR
          AND  IL.CODINTR1 = I1.CODINTR1 AND  IL.CODLINIEAVIZ = I1STINS.CODINTR1 AND  ISTINS.CODINTR = I1STINS.CODINTR AND  ISTINS.CODINTR = GSTINS.CODDOC
          AND  ISTINS.TIPDOC = GSTINS.TIPDOC AND  OSTINS.CODGENERAL = GSTINS.CODGENERAL AND  I.OPERAT = 1
          AND  I.DATADOC &lt;= (SELECT WME_RESULT FROM PKG_GLOBALS_GETDATASOLDPART(NULL,NULL)) AND  COALESCE( G.FaraReg, 0) = 0
        union ALL
        SELECT OSTINS.CODOBLIGPIF AS CODSTINSPIF,
               (I1.PU * I1.CANT * ((100 + COALESCE( I1.PROCDISC, 0)) / 100) + COALESCE(I1STINS.TVA, 0)
                * (CASE WHEN  I1STINS.PU * I1STINS.CANT = 0 THEN 0
                        ELSE I1.PU * I1.CANT * ((100 + COALESCE(I1.PROCDISC, 0)) / 100) / (I1STINS.PU * I1STINS.CANT)
                   END ) )  AS VALOARE
        FROM OBLIGPIF O, GENERAL G, IESIRI I, IESIRI1 I1, IESLINK IL, IESIRI1 I1STINS, IESIRI ISTINS, GENERAL GSTINS, OBLIGPIF OSTINS
        WHERE  O.  SEMNIFICATIE = 240 AND  G.CODGENERAL = O.CODGENERAL AND  G.TIPDOC = 26 AND  I.CODIES = G.CODDOC AND  I1.CODIES = I.CODIES
          AND  IL.CODIES1 = I1.CODIES1 AND  IL.CODLINIEAVIZ = I1STINS.CODIES1 AND  ISTINS.CODIES = I1STINS.CODIES AND  ISTINS.CODIES = GSTINS.CODDOC
          AND  ISTINS.TIPDOC = GSTINS.TIPDOC AND  OSTINS.CODGENERAL = GSTINS.CODGENERAL AND  I.OPERAT = 1
          AND  I.DATADOC &lt;= (SELECT WME_RESULT FROM PKG_GLOBALS_GETDATASOLDPART(NULL,NULL)) AND  COALESCE( G.FaraReg, 0) = 0
        ) A_PG
  GROUP BY CODSTINSPIF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_make_stingeri_la_data_part</obj_name>
  <obj_hashval>a6b2fdabfc74e8acf2687ccdd8fc1d3f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_make_stingeri_la_data_part()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_STINGERE_LUNA;
  INSERT INTO TMP_STINGERE_LUNA(CODSTINSPIF, VALOARE)
  SELECT CODSTINSPIF, SUM( VALOARE) AS VALOARE
  FROM (SELECT S.CODSTINSPIF, COALESCE( S.VALOARE, 0) - COALESCE( G_S.TVA, 0) AS VALOARE
        FROM STINGERE S, OBLIGPIF O_S, GENERAL G_S, TREZOR1 T1, TREZOR T, OBLIGPIF O
        WHERE
           O_S.CODOBLIGPIF = S.CODSTINGATORPIF AND  O.CODOBLIGPIF = S.CODSTINSPIF AND  G_S.CODGENERAL = O_S.CODGENERAL AND G_S.TIPDOC IN (29, 30, 31, 32, 33)
           AND  T1.CODTREZOR1 = G_S.CODDOC AND  T.CODTREZOR = T1.CODTREZOR
           AND  T.DATADOC &lt;= (SELECT WME_RESULT FROM PKG_GLOBALS_GETDATASOLDPART(NULL,NULL)) AND  COALESCE( T1.ANULAT, 0) = 0
           AND  COALESCE( G_S.FaraReg, 0) = 0 AND  O.CODPART = (SELECT WME_RESULT FROM PKG_NOMPART_GET_PART_CURENT(NULL,NULL))
        union ALL
        SELECT S.CODSTINSPIF, COALESCE( S.VALOARE, 0) - COALESCE( G_S.TVA, 0) AS VALOARE
        FROM STINGERE S, OBLIGPIF O_S, GENERAL G_S, COMPENS C, OBLIGPIF O
        WHERE
           O_S.CODOBLIGPIF = S.CODSTINGATORPIF AND  O.CODOBLIGPIF = S.CODSTINSPIF AND  G_S.CODGENERAL = O_S.CODGENERAL AND  G_S.TIPDOC = 28 AND  C.CODCOMPENS = G_S.CODDOC
           AND  C.DATADOC &lt;= (SELECT WME_RESULT FROM PKG_GLOBALS_GETDATASOLDPART(NULL,NULL)) AND  COALESCE( G_S.FaraReg, 0) = 0
           AND  O.CODPART = (SELECT WME_RESULT FROM PKG_NOMPART_GET_PART_CURENT(NULL,NULL))
        union ALL
        SELECT S.CODSTINSPIF, COALESCE( S.VALOARE, 0) - COALESCE( G_S.TVA, 0) AS VALOARE
        FROM STINGERE S, OBLIGPIF O_S, GENERAL G_S, INTRARI I, OBLIGPIF O
        WHERE
           O_S.CODOBLIGPIF = S.CODSTINGATORPIF AND  O.CODOBLIGPIF = S.CODSTINSPIF AND  G_S.CODGENERAL = O_S.CODGENERAL AND G_S.TIPDOC IN (1, 2, 3, 4, 5, 6, 7, 8, 9)
           AND  I.CODINTR = G_S.CODDOC AND  I.DATADOC &lt;= (SELECT WME_RESULT FROM PKG_GLOBALS_GETDATASOLDPART(NULL,NULL)) AND  I.OPERAT = 1 AND  I.ANULAT = 0
           AND  COALESCE( G_S.FaraReg, 0) = 0 AND  O.CODPART = (SELECT WME_RESULT FROM PKG_NOMPART_GET_PART_CURENT(NULL,NULL))
        union ALL
        SELECT S.CODSTINSPIF, COALESCE( S.VALOARE, 0) - COALESCE( G_S.TVA, 0) AS VALOARE
        FROM STINGERE S, OBLIGPIF O_S, GENERAL G_S, IESIRI I, OBLIGPIF O
        WHERE
           O_S.CODOBLIGPIF = S.CODSTINGATORPIF AND  O.CODOBLIGPIF = S.CODSTINSPIF AND  G_S.CODGENERAL = O_S.CODGENERAL AND G_S.TIPDOC IN (16, 19, 20, 21, 22, 23, 24, 25, 26)
           AND  I.CODIES = G_S.CODDOC AND  I.DATADOC &lt;= (SELECT WME_RESULT FROM PKG_GLOBALS_GETDATASOLDPART(NULL,NULL)) AND  I.OPERAT = 1 AND  I.ANULAT = 0
           AND  COALESCE( G_S.FaraReg, 0) = 0 AND  O.CODPART = (SELECT WME_RESULT FROM PKG_NOMPART_GET_PART_CURENT(NULL,NULL))
        union ALL
        SELECT OSTINS.CODOBLIGPIF AS CODSTINSPIF,
               (I1.PU * I1.CANT + COALESCE(I1STINS.TVA, 0) * (CASE WHEN  I1STINS.PU * I1STINS.CANT = 0 THEN 0 ELSE I1.PU * I1.CANT / (I1STINS.PU * I1STINS.CANT) END)) AS VALOARE
        FROM OBLIGPIF O, GENERAL G, INTRARI I, INTRARI1 I1, INTRLINK IL, INTRARI1 I1STINS, INTRARI ISTINS, GENERAL GSTINS, OBLIGPIF OSTINS
        WHERE
           O.  SEMNIFICATIE = 140 AND  G.CODGENERAL = O.CODGENERAL AND  G.TIPDOC = 9 AND  I.CODINTR = G.CODDOC AND  I1.CODINTR = I.CODINTR AND  IL.CODINTR1 = I1.CODINTR1
           AND  IL.CODLINIEAVIZ = I1STINS.CODINTR1 AND  ISTINS.CODINTR = I1STINS.CODINTR AND  ISTINS.CODINTR = GSTINS.CODDOC AND  ISTINS.TIPDOC = GSTINS.TIPDOC
           AND  OSTINS.CODGENERAL = GSTINS.CODGENERAL AND  I.OPERAT = 1 AND  I.DATADOC &lt;= (SELECT WME_RESULT FROM PKG_GLOBALS_GETDATASOLDPART(NULL,NULL))
           AND  COALESCE( G.FaraReg, 0) = 0 AND  OSTINS.CODPART = (SELECT WME_RESULT FROM PKG_NOMPART_GET_PART_CURENT(NULL,NULL))
        union ALL
        SELECT OSTINS.CODOBLIGPIF AS CODSTINSPIF,
               (I1.PU * I1.CANT * ((100 + COALESCE(I1.PROCDISC, 0)) / 100) + COALESCE(I1STINS.TVA, 0)
                * (CASE WHEN  I1STINS.PU * I1STINS.CANT = 0 THEN 0
                        ELSE I1.PU * I1.CANT * ((100 + COALESCE(I1.PROCDISC, 0)) / 100) / (I1STINS.PU * I1STINS.CANT)
                   END ) )  AS VALOARE
        FROM OBLIGPIF O, GENERAL G, IESIRI I, IESIRI1 I1, IESLINK IL, IESIRI1 I1STINS, IESIRI ISTINS, GENERAL GSTINS, OBLIGPIF OSTINS
        WHERE
           O.  SEMNIFICATIE = 240 AND  G.CODGENERAL = O.CODGENERAL AND  G.TIPDOC = 26 AND  I.CODIES = G.CODDOC AND  I1.CODIES = I.CODIES AND  IL.CODIES1 = I1.CODIES1
           AND  IL.CODLINIEAVIZ = I1STINS.CODIES1 AND  ISTINS.CODIES = I1STINS.CODIES AND  ISTINS.CODIES = GSTINS.CODDOC AND  ISTINS.TIPDOC = GSTINS.TIPDOC
           AND  OSTINS.CODGENERAL = GSTINS.CODGENERAL AND  I.OPERAT = 1 AND  I.DATADOC &lt;= (SELECT WME_RESULT FROM PKG_GLOBALS_GETDATASOLDPART(NULL,NULL))
           AND  COALESCE( G.FaraReg, 0) = 0 AND  OSTINS.CODPART = (SELECT WME_RESULT FROM PKG_NOMPART_GET_PART_CURENT(NULL,NULL))
        ) A_PG
  GROUP BY CODSTINSPIF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_marjaregavize</obj_name>
  <obj_hashval>0a619bc34e4630c8981db04c64827804</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_marjaregavize(INOUT wme_result double precision, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REGPART.MARJAREGAVIZE')),'99999999999.9999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_set_inclusiv_avans_facturat</obj_name>
  <obj_hashval>fcdc3baa66d008f2755cfe260217ea30</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_set_inclusiv_avans_facturat(flag numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REGPART.INCLUSIV_AVANS_FACTURAT',to_char(FLAG,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_set_inclusiv_avize</obj_name>
  <obj_hashval>7e3c53b0f5de5f079018611f060ac230</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_set_inclusiv_avize(flag numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REGPART.INCLUSIVAVIZE',to_char(FLAG,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_set_inclusiv_cecuri</obj_name>
  <obj_hashval>a2a783719c9b77aa4f9b32e7af1f1dc5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_set_inclusiv_cecuri(flag numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REGPART.INCLUSIV_CECURI',to_char(FLAG,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_set_inclusiv_garantii</obj_name>
  <obj_hashval>7271538aa3eb8ec82e0965cf3a266937</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_set_inclusiv_garantii(flag numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REGPART.INCLUSIV_GARANTII',to_char(FLAG,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_set_inclusiv_litigii</obj_name>
  <obj_hashval>4d5c9a2f6cdb6cb7beb38e2d625a7915</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_set_inclusiv_litigii(flag numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REGPART.INCLUSIV_LITIGII',to_char(FLAG,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_set_marja_regavize</obj_name>
  <obj_hashval>4f043218adc57f998bf5b4d6cf93c693</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_set_marja_regavize(marja numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REGPART.MARJAREGAVIZE',to_char(MARJA,'99999999999.9999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_setcodnextreg</obj_name>
  <obj_hashval>9a0afc24bb0842e9507419436f4d1e30</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_setcodnextreg(acodnextreg numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REGPART.CODNEXTREG',to_char(aCODNEXTREG,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_setdatanextreg</obj_name>
  <obj_hashval>fcce02eb865c5d55bd832de952d086f5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_setdatanextreg(adatanextreg date)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REGPART.DATANEXTREG',aDATANEXTREG::varchar,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_setdiferente</obj_name>
  <obj_hashval>a2282172b7e5686b0c5be5309513b961</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_setdiferente(adiferente numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Bogdan 17.08.2020
  perform set_config('PKG_REGPART.DIFERENTE',aDIFERENTE::numeric,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_setinclusiv_avans_facturat</obj_name>
  <obj_hashval>d9d7684ca4a335f45a4d7945248138b2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_setinclusiv_avans_facturat(ainclusiv_avans_facturat numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REGPART.INCLUSIV_AVANS_FACTURAT',to_char(aINCLUSIV_AVANS_FACTURAT,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_setinclusiv_garantii</obj_name>
  <obj_hashval>43ca5bef94cb0ab361cd2228f84603e5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_setinclusiv_garantii(ainclusiv_garantii numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REGPART.INCLUSIV_GARANTII',to_char(aINCLUSIV_GARANTII,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_setinclusiv_litigii</obj_name>
  <obj_hashval>8e4e251f7fd494c8c1715a3f6c3deb1c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_setinclusiv_litigii(ainclusiv_litigii numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REGPART.INCLUSIV_LITIGII',to_char(aINCLUSIV_LITIGII,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_setinclusivavize</obj_name>
  <obj_hashval>4cb1698d837e8e71d83b0c7ccc6c0c32</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_setinclusivavize(ainclusivavize numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REGPART.INCLUSIVAVIZE',to_char(aINCLUSIVAVIZE,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_setmarjaregavize</obj_name>
  <obj_hashval>8c79287cda4f11c4076cfe74295f58bf</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_setmarjaregavize(amarjaregavize double precision)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REGPART.MARJAREGAVIZE',to_char(aMARJAREGAVIZE,'99999999999.9999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_sp_deleterecord</obj_name>
  <obj_hashval>3ee55059f568a392eeefe45aef0a6227</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  glb_DATANEXTREG date;
  glb_CODNEXTREG  numeric;
  V_REC           RECORD;
  V_REC_JURN_SUB  RECORD;
begin
  --Bogdan 18.08.2020
  glb_DATANEXTREG := case when current_setting('PKG_REGPART.DATANEXTREG',TRUE) = '' then null
                          else current_setting('PKG_REGPART.DATANEXTREG',TRUE)::date end;

  PERFORM PKG_GLOBALS_MarkDirtyJurnal();
  PERFORM PKG_REGPART_SP_LOCKRECORD( RecID);

  SELECT MIN( DATADOC) INTO glb_DATANEXTREG
  FROM REG
  WHERE
       TIPREG = 46
       AND  DATADOC &gt; (SELECT DATADOC FROM REG WHERE CODREG = RECID)
       AND  CODMONEDA = (SELECT CODMONEDA FROM REG WHERE CODREG = RECID);

  glb_CODNEXTREG := null;
--  perform set_config('PKG_REGPART.CODNEXTREG',to_char(NULL,'999999999999999999'),false);
  IF glb_DATANEXTREG IS NOT NULL THEN
    SELECT CODREG INTO glb_CODNEXTREG
    FROM REG
    WHERE
       DATADOC = glb_DATANEXTREG AND  TIPREG = 46 AND  CODMONEDA = (SELECT CODMONEDA FROM REG WHERE CODREG = RECID);
  END IF;

  FOR V_REC IN (
      SELECT REG1.CURS AS OLDCURSREG, GSTINGATOR.CODGENERAL, GSTINGATOR.CURS AS CURSSTINGATOR, T1.CODTREZOR
      FROM REG REG, REG1 REG1, OBLIGPIF OSTINS, STINGERE S, OBLIGPIF OSTINGATOR, GENERAL GSTINGATOR, TREZOR1 T1
      WHERE
         REG.CODREG = RECID
         AND  REG1.CODREG = REG.CODREG
         AND  OSTINS.CODGENERAL = REG1.CODGENERAL
         AND  S.CODSTINSPIF = OSTINS.CODOBLIGPIF
         AND  OSTINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
         AND  GSTINGATOR.CODGENERAL = OSTINGATOR.CODGENERAL
         AND GSTINGATOR.TIPDOC IN (29, 30, 31, 33)
         AND  T1.CODTREZOR1 = GSTINGATOR.CODDOC
         AND  PKG_REGPART_DATA_DOC_CORECTA(T1.DATADOC, REG.DATADOC, glb_DATANEXTREG) = 1
           AND  REG1.CURS &lt;&gt; GSTINGATOR.CURS
           AND  COALESCE( GSTINGATOR.FaraReg, 0) = 0
  ) LOOP
    UPDATE general set CURS = V_REC.OLDCURSREG WHERE CODGENERAL = V_REC.CODGENERAL;
    UPDATE JURNAL1 set DIRTY = 1 WHERE TIPDOC IN (29, 30, 31, 33) AND  CODDOC = v_rec.codtrezor;
  END LOOP;

  FOR V_REC IN (
    SELECT REG1.CURS AS OLDCURSREG, GSTINGATOR.CODGENERAL, GSTINGATOR.CURS AS CURSSTINGATOR, C.CODCOMPENS
    FROM REG REG, REG1 REG1, OBLIGPIF OSTINS, STINGERE S, OBLIGPIF OSTINGATOR, GENERAL GSTINGATOR, COMPENS C
    WHERE
       REG.CODREG = RECID
       AND  REG1.CODREG = REG.CODREG
       AND  OSTINS.CODGENERAL = REG1.CODGENERAL
       AND  S.CODSTINSPIF = OSTINS.CODOBLIGPIF
       AND  OSTINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
       AND  GSTINGATOR.CODGENERAL = OSTINGATOR.CODGENERAL
       AND  GSTINGATOR.TIPDOC = 28
       AND  C.CODCOMPENS = GSTINGATOR.CODDOC
       AND  PKG_REGPART_DATA_DOC_CORECTA(C.DATADOC, REG.DATADOC, glb_DATANEXTREG) = 1
       AND  COALESCE( GSTINGATOR.FaraReg, 0) = 0
  ) LOOP
    UPDATE JURNAL1 SET  DIRTY = 1 WHERE TIPDOC = 28 AND  CODDOC = V_REC.CODCOMPENS;
  END LOOP;

  IF glb_CODNEXTREG IS NOT null THEN
    UPDATE JURNAL1 set DIRTY = 1 WHERE TIPDOC = 46 AND  CODDOC = glb_CODNEXTREG;

    FOR V_REC IN (
      SELECT R1_CURENT.CURS AS CURSCURENT, R1_NEXT.CODREG1
      FROM REG1 R1_CURENT, REG1 R1_NEXT
      WHERE
         R1_CURENT.CODREG = RECID
             AND  R1_NEXT.CODREG = glb_CODNEXTREG
             AND  R1_CURENT.CODGENERAL = R1_NEXT.CODGENERAL
    ) LOOP
      UPDATE REG1 set CURS = V_REC.CURSCURENT where CODREG1 = V_REC.CODREG1;
    END LOOP;
  END IF;

  DELETE FROM REG1 WHERE CodReg = RecID;
  DELETE FROM REG  WHERE CodReg = RecID;

  FOR V_REC IN (SELECT * FROM JURNAL WHERE CODDOC = RecID AND  TIPDOC = 46) LOOP
      UPDATE NCONTRUL
      SET
        RULAJCD      = RULAJCD      - V_REC.VALOARE,
        RULAJVCD     = RULAJVCD     - V_REC.VALOAREV,
        RULAJC_IFRS  = RULAJC_IFRS  - V_REC.VALOARE_IFRS,
        RULAJVC_IFRS = RULAJVC_IFRS - V_REC.VALOAREV_IFRS
      WHERE
       CODCONT = V_REC.CONTD AND  AN = getAnLucru() AND  LUNA = getLunaLucru();

      FOR V_REC_JURN_SUB IN  (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND  AN = V_REC.AN AND  LUNA = V_REC.LUNA)  loop
        UPDATE NCONTRULSUB
          SET
            RULAJCD      = RULAJCD      - V_REC.VALOARE,
            RULAJVCD     = RULAJVCD     - V_REC.VALOAREV,
            RULAJC_IFRS  = RULAJC_IFRS  - V_REC.VALOARE_IFRS,
            RULAJVC_IFRS = RULAJVC_IFRS - V_REC.VALOAREV_IFRS
        WHERE
           CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND  SUBUNITATEA = V_REC.SUBUNITATEA;
      END LOOP;

      UPDATE NCONTRUL
        SET
          RULAJCC      = RULAJCC      - V_REC.VALOARE,
          RULAJVCC     = RULAJVCC     - V_REC.VALOAREV,
          RULAJC_IFRS  = RULAJC_IFRS  - V_REC.VALOARE_IFRS,
          RULAJVC_IFRS = RULAJVC_IFRS - V_REC.VALOAREV_IFRS
        WHERE
           CODCONT = V_REC.CONTC AND  AN = getAnLucru() AND  LUNA = getLunaLucru();

      FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND  AN = V_REC.AN AND  LUNA = V_REC.LUNA) LOOP
        UPDATE NCONTRULSUB
        SET
          RULAJCC      = RULAJCC      - V_REC.VALOARE,
          RULAJVCC     = RULAJVCC     - V_REC.VALOAREV,
          RULAJC_IFRS  = RULAJC_IFRS  - V_REC.VALOARE_IFRS,
          RULAJVC_IFRS = RULAJVC_IFRS - V_REC.VALOAREV_IFRS
        WHERE
         CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND  SUBUNITATEA = V_REC.SUBUNITATEA;
      END LOOP;
  END LOOP;

  DELETE FROM JURNAL  WHERE CODDOC = RecID AND  TIPDOC = 46;
  DELETE FROM JURNAL1 WHERE CODDOC = RecID AND  TIPDOC = 46;

  PERFORM NotifyModif( 2, RecId, 'REG');
  perform PKG_REGPART_SetDATANEXTREG(glb_DATANEXTREG);
  perform PKG_REGPART_SetCODNEXTREG(glb_CODNEXTREG);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_sp_insertrecord</obj_name>
  <obj_hashval>4ad019ba62c56397bbfb75fef66219ac</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_REG;
  INSERT INTO TMP_REG(CodReg, DataDoc)
  VALUES(0, LAST_DAY( TO_DATE( '01.' || TO_CHAR( (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL)),'9999999999') || '.' || TO_CHAR( (SELECT WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL)),'9999999999'), 'DD.MM.YYYY')));
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_sp_lockrecord</obj_name>
  <obj_hashval>a672422b9cc2b9d45884691224bbe7d9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  tmp numeric;
begin
  SELECT CodReg INTO tmp FROM REG WHERE CodReg = RecID FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpers_curs_in</obj_name>
  <obj_hashval>1f8362298f319f991fea7d5d9163b20a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpers_curs_in(INOUT wme_result double precision, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REGPERS.CURS_IN', true)),'99999999999.9999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpers_generarereg</obj_name>
  <obj_hashval>0c86ffa608b69cd07dbe37ecf6eb7889</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpers_generarereg()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  V_REC             RECORD;
  LunaPrecedentaReg numeric;
  AnPrecedentReg    numeric;
  aSEMN             numeric := 1;
  aTIPCONT          numeric := 0;
begin
  perform PKG_GLOBALS_SETLUNATEMP(current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric, current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric);

  select newAn, newLuna into AnPrecedentReg, LunaPrecedentaReg from  PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA(current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric, current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric, AnPrecedentReg, LunaPrecedentaReg);

  perform PKG_GLOBALS_SETLUNAPRECEDENTA(AnPrecedentReg, LunaPrecedentaReg);

  DELETE FROM TMP_REGPERS1;
  DELETE FROM TMP_REGPERS1;
  DELETE FROM TMP_SOLDPERS_SUB;

  INSERT INTO TMP_SOLDPERS_SUB ( CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, SUBUNITATEA )
  SELECT CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, SUBUNITATEA
  FROM V_SOLDPERS_TRANZACTII_SUB
  WHERE CODMONEDA = current_setting('PKG_REG.moneda_reg', true)::numeric;

  for V_REC in (SELECT * FROM TMP_SOLDPERS_SUB S ) loop
    begin
      SELECT coalesce(TIPCONT, 0) INTO ATIPCONT
      FROM NCONT
      WHERE CODCONT = (SELECT PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG.WME_RESULT
                       FROM   PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(null, 1100, V_REC.ICONT,
                                                                  (SELECT PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA.WME_RESULT
                                                                   FROM PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA(null, V_REC.CODPERS, current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric, current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric))));
    exception
      when others then aTIPCONT := 0;
    end;

    if coalesce(aTIPCONT, 0) = 1 then aSEMN := -1; else aSEMN := 1; end if;

    UPDATE TMP_SOLDPERS_SUB
    SET
    SEMN = aSEMN
    WHERE CODPERS = V_REC.CODPERS and CODMONEDA = V_REC.CODMONEDA and ICONT = V_REC.ICONT ;
  end loop;

  INSERT INTO TMP_REGPERS1 ( CodRegPers1, SoldDoc, SoldDocVal, SoldDocReg, CodPers, CodCont, ICONT, SUBUNITATEA, Diferenta, Den_Pers, Den_Cont )
  select
    -1 * row_number() over(),
    SOLDVALUTA,
    SOLDLEI,
    SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(null, null)),
    CodPers,
    CodCont,
    ICONT,
    SUBUNITATEA,
    SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(null, null)) - SoldLei,
    coalesce(Prenume, '') || ' ' || coalesce(Nume, ''),
    Den_Cont
  from
    (SELECT T1.CODPERS, SOLDVALUTA, SOLDLEI, NUME, PRENUME,
            (SELECT PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT
             FROM PKG_PLANCONTURI_GETSIMBOLCONT(null, (SELECT PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG.WME_RESULT
                                                       FROM PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(null, 1100, ICONT, (SELECT PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA.WME_RESULT
                                                                                                                    FROM PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA(null, T1.CODPERS, current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric, current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric)))))
            ) as DEN_CONT,
            (SELECT PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG.WME_RESULT
             FROM PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(null, 1100, ICONT, (SELECT PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA.WME_RESULT
                                                                          FROM PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA(null, T1.CODPERS, current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric, current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric)))
            ) as CODCONT,
            ICONT, SUBUNITATEA
    FROM (SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SUM(SOLDLEI) SOLDLEI, SUM(SOLDVALUTA) SOLDVALUTA
          FROM (SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, coalesce(SOLDLEI, 0) * coalesce(SEMN, 1) SOLDLEI, coalesce(SOLDVALUTA, 0) * coalesce(SEMN, 1) SOLDVALUTA
                FROM TMP_SOLDPERS_SUB
                 union all
                SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
                FROM V_SOLDPERS_PREC_SUB WHERE CODMONEDA = current_setting('PKG_REG.moneda_reg', true)::numeric
               ) A_PG
          group BY CODPERS, ICONT, CODMONEDA, SUBUNITATEA
         ) T1, NPERS NP
    WHERE
      NP.CodPers = T1.CodPers
      and T1.SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(null, null)) - T1.SoldLei &lt;&gt; 0
   ) B_PG;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpers_setcurs_in</obj_name>
  <obj_hashval>3e4642ebba39ea7ce13800c90d4084ab</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpers_setcurs_in(acurs_in double precision)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REGPERS.CURS_IN',to_char(aCURS_IN,'99999999999.9999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpers_setcurs_in</obj_name>
  <obj_hashval>2a7bdd7123f805488b9c7aeb65a80aa9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpers_setcurs_in(acurs_in numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REGPERS.CURS_IN',aCURS_IN::varchar,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpers_sp_deleterecord</obj_name>
  <obj_hashval>d48bf2fee79b6cd47ce009de837d7ba2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpers_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  V_REC          RECORD;
  V_REC_JURN_SUB RECORD;
begin
  perform PKG_GLOBALS_MarkDirtyJurnal();
  perform PKG_REGPERS_SP_LOCKRECORD(RecID);

  DELETE FROM TMP_REGPERS1_MARTOR;

  INSERT INTO TMP_REGPERS1_MARTOR ( CODPERS, SOLDDOCVAL, ICONT )
  SELECT CODPERS, SOLDDOCVAL, ICONT FROM REGPERS1 WHERE CODREG = RECID;

  DELETE FROM REGPERS1 WHERE CodReg = RecID;
  DELETE FROM REG      WHERE CodReg = RecID;

  for V_REC in (SELECT * FROM JURNAL WHERE CODDOC = RecID and TIPDOC = 47 ) loop
    UPDATE NCONTRUL
    set
      RULAJCD  = RULAJCD  - V_REC.VALOARE,
      RULAJVCD = RULAJVCD - V_REC.VALOAREV
    where
      CODCONT = V_REC.CONTD
      and AN   = current_setting('PKG_GLOBALS.ANLUCRU'  , true)::numeric
      and LUNA = current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric ;

    for V_REC_JURN_SUB in (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD and AN = V_REC.AN and LUNA = V_REC.LUNA ) loop
      UPDATE NCONTRULSUB
      set
        RULAJCD  = RULAJCD  - V_REC.VALOARE,
        RULAJVCD = RULAJVCD - V_REC.VALOAREV
      where
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL and SUBUNITATEA = V_REC.SUBUNITATEA ;
    end loop;

    UPDATE NCONTRUL
    set
      RULAJCC  = RULAJCC  - V_REC.VALOARE,
      RULAJVCC = RULAJVCC - V_REC.VALOAREV
    where
      CODCONT = V_REC.CONTC
      and AN   = current_setting('PKG_GLOBALS.ANLUCRU'  , true)::numeric
      and LUNA = current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric ;

    for V_REC_JURN_SUB in (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC and AN = V_REC.AN and LUNA = V_REC.LUNA ) loop
      UPDATE NCONTRULSUB
      set
        RULAJCC  = RULAJCC  - V_REC.VALOARE,
        RULAJVCC = RULAJVCC - V_REC.VALOAREV
      where
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL and SUBUNITATEA = V_REC.SUBUNITATEA ;
    end loop;
  end loop;

  DELETE FROM JURNAL  WHERE CODDOC = RecID and TIPDOC = 47;
  DELETE FROM JURNAL1 WHERE CODDOC = RecID and TIPDOC = 47;
  DELETE FROM EXPERT1 WHERE CODEXPERT = (SELECT CODEXPERT FROM EXPERT WHERE CODDOC = RecID and TIPDOC = 47 );
  DELETE FROM EXPERT  WHERE CODDOC = RecID and TIPDOC = 47;

  perform NotifyModif(2, RecId, 'REG');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpers_sp_lockrecord</obj_name>
  <obj_hashval>ec2bf6dd9b545de07f952e1d412b9041</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpers_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  tmp numeric;
begin
  SELECT CodReg INTO tmp FROM REG WHERE CodReg = RecID FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regtrezor_curs_in</obj_name>
  <obj_hashval>d3c1a8300e487fa813652c17e8177bc1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regtrezor_curs_in(INOUT wme_result double precision, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REGTREZOR.CURS_IN', true)),'99999999999.9999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regtrezor_generarereg</obj_name>
  <obj_hashval>37c383f252379be3dd48b73ae8d51bbb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regtrezor_generarereg()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  LunaPrecedentaReg numeric;
  AnPrecedentReg    numeric;
begin
  --Bogdan 18.08.2020
  --Florin 27.02.2021 - inlocuit nvl
  PERFORM PKG_GLOBALS_SETLUNATEMP( getAnLucru(), getLunaLucru());

  select  PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA.newan, PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA.newluna
    from PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( getAnLucru(), getLunaLucru(), AnPrecedentReg, LunaPrecedentaReg)
          into AnPrecedentReg, LunaPrecedentaReg;
  PERFORM PKG_GLOBALS_SETLUNAPRECEDENTA( AnPrecedentReg, LunaPrecedentaReg);

  DELETE FROM TMP_REGTREZOR1;
  INSERT INTO TMP_REGTREZOR1(CodRegTrezor1, SoldDoc, SoldDocVal, SoldDocReg, CodBank, CodBankCont, Diferenta, Den_Cont, NrCont, Filiala, Credit, SUBUNITATEA)
  (
  SELECT -1 * row_number() over(), T1.SoldValuta,
        T1.SoldLei,
        T1.SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(NULL,NULL)),
        NBC.CodBank, T1.CodBankCont,
        T1.SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(NULL,NULL)) - T1.SoldLei,
        NBC.Den_Cont, NBC.NrCont, NBC.Filiala, NBC.Credit, NBC.SUBUNITATEA
  FROM (SELECT SoldValuta, SoldLei, CodBankCont FROM V_SOLDURIBANCILUNA) T1
    INNER JOIN NBANKCONT NBC ON  NBC.CodBankCont = T1.CodBankCont AND coalesce(NBC.FARAREG, 0) = 0
  WHERE
     NBC.CodMoneda = pkg_reg_getmonedareg()
     AND  T1.SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(NULL,NULL)) - T1.SoldLei &lt;&gt; 0
  );
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regtrezor_getcurs_in</obj_name>
  <obj_hashval>1a48ea357045a71d0edfabce1022a7c5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regtrezor_getcurs_in(INOUT wme_result double precision, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REGTREZOR.CURS_IN', true)),'99999999999.9999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regtrezor_setcurs_in</obj_name>
  <obj_hashval>cd0a721518f528190d506b64469d8ea2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regtrezor_setcurs_in(acurs_in double precision)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REGTREZOR.CURS_IN',to_char(aCURS_IN,'99999999999.9999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regtrezor_sp_deleterecord</obj_name>
  <obj_hashval>a7136c89c876977ee4cf94b9021781f9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regtrezor_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC          RECORD;
  V_REC_JURN_SUB RECORD;
  V_REC_TREZOR   RECORD;
begin
  PERFORM PKG_GLOBALS_MarkDirtyJurnal();
  PERFORM PKG_REGTREZOR_SP_LOCKRECORD( RecID);

  DELETE FROM TMP_REGTREZOR1_MARTOR;
  INSERT INTO TMP_REGTREZOR1_MARTOR(CODBANKCONT, SOLDDOCVAL)
  SELECT CODBANKCONT, SOLDDOCVAL FROM REGTREZOR1 WHERE CODREG = RECID;

  DELETE FROM REGTREZOR1 WHERE CodReg = RecID;
  DELETE FROM REG        WHERE CodReg = RecID;

  FOR V_REC IN (SELECT * FROM JURNAL WHERE CODDOC = RecID AND  TIPDOC = 45) LOOP
    UPDATE NCONTRUL
    SET
    RULAJCD  = RULAJCD  - V_REC.VALOARE,
    RULAJVCD = RULAJVCD - V_REC.VALOAREV
    WHERE
     CODCONT = V_REC.CONTD AND  AN = TO_NUMBER((current_setting('PKG_GLOBALS.ANLUCRU', true)),'999999999999999999') AND  LUNA = TO_NUMBER((current_setting('PKG_GLOBALS.LUNALUCRU', true)),'999999999999999999');

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND  AN = V_REC.AN AND  LUNA = V_REC.LUNA) LOOP
      UPDATE NCONTRULSUB
      SET
      RULAJCD  = RULAJCD  - V_REC.VALOARE,
      RULAJVCD = RULAJVCD - V_REC.VALOAREV
      WHERE
       CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND  SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;

    UPDATE NCONTRUL
    SET
    RULAJCC  = RULAJCC  - V_REC.VALOARE,
    RULAJVCC = RULAJVCC - V_REC.VALOAREV
    WHERE
     CODCONT = V_REC.CONTC AND  AN = TO_NUMBER((current_setting('PKG_GLOBALS.ANLUCRU', true)),'999999999999999999') AND  LUNA = TO_NUMBER((current_setting('PKG_GLOBALS.LUNALUCRU', true)),'999999999999999999');

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND  AN = V_REC.AN AND  LUNA = V_REC.LUNA) LOOP
      UPDATE NCONTRULSUB
      SET
      RULAJCC  = RULAJCC  - V_REC.VALOARE,
      RULAJVCC = RULAJVCC - V_REC.VALOAREV
      WHERE
       CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND  SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;
  END LOOP;

  DELETE FROM JURNAL  WHERE CODDOC = RecID AND  TIPDOC = 45;
  DELETE FROM JURNAL1 WHERE CODDOC = RecID AND  TIPDOC = 45;

  PERFORM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( TO_NUMBER((current_setting('PKG_GLOBALS.ANLUCRU', true)),'999999999999999999'), TO_NUMBER((current_setting('PKG_GLOBALS.LUNALUCRU', true)),'999999999999999999'), TO_NUMBER((current_setting('PKG_GLOBALS.ANPRECEDENT', true)),'999999999999999999'), TO_NUMBER((current_setting('PKG_GLOBALS.LUNAPRECEDENTA', true)),'999999999999999999'));
  perform set_config('PKG_GLOBALS.ANTEMP',to_char(TO_NUMBER((current_setting('PKG_GLOBALS.ANLUCRU', true)),'999999999999999999'),'999999999999999999'),false);
  perform set_config('PKG_GLOBALS.LUNATEMP',to_char(TO_NUMBER((current_setting('PKG_GLOBALS.LUNALUCRU', true)),'999999999999999999'),'999999999999999999'),false);
  PERFORM PKG_INCHIDERI_MAKE_SOLD_BANK();

  FOR V_REC_TREZOR IN (SELECT T.*
                       FROM TREZOR T, NBANKCONT BC
                       WHERE TIPDOC IN (29, 30, 31) AND  BC.CODBANKCONT = T.CODBANCA AND  BC.CREDIT = 1
                         AND  EXISTS (SELECT CODBANKCONT FROM (SELECT CODBANKCONT FROM TMP_REGTREZOR1_MARTOR) A_PG WHERE CODBANKCONT = T.CODBANCA)
                         AND  AN * 12 + LUNA &gt; TO_NUMBER((current_setting('PKG_GLOBALS.ANLUCRU', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_GLOBALS.LUNALUCRU', true)),'999999999999999999')
                      )
  LOOP
    UPDATE JURNAL1 SET DIRTY = 1 WHERE TIPDOC = V_REC_TREZOR.TIPDOC AND  CODDOC = V_REC_TREZOR.CODTREZOR;
  END LOOP;

  PERFORM NotifyModif( 2, RecId, 'REG');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regtrezor_sp_insertrecord</obj_name>
  <obj_hashval>925a6c499721f625a86ed223a68ae4ff</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regtrezor_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_REGTREZOR1_MARTOR;
  DELETE FROM TMP_REG;

  INSERT INTO TMP_REG(CodReg, DataDoc)
  VALUES(0, LAST_DAY( TO_DATE( '01.' || TO_CHAR( (SELECT PKG_GLOBALS_GETLUNALUCRU.WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL)),'9999999999') || '.' || TO_CHAR( (SELECT PKG_GLOBALS_GETANLUCRU.WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL)),'9999999999'), 'DD.MM.YYYY')));
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regtrezor_sp_lockrecord</obj_name>
  <obj_hashval>2b48d5269691a062aee303d250812763</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regtrezor_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  tmp numeric;
begin
  SELECT CodReg INTO tmp FROM REG WHERE CodReg = RecID FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_remake_sequences_remake_all_sequences</obj_name>
  <obj_hashval>60e5cb13f1794a2c70bd971e12e9de06</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_remake_sequences_remake_all_sequences()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
DECLARE
  vRec    RECORD;
  vRes    VARCHAR;
  sSchema VARCHAR;
BEGIN
  --Florin 29.02.2024 - sinc. Oracle
  --Stef 21.02.2023
  sSchema := lower(getfirmaname());
  IF NULLIF(sSchema, '') IS NULL THEN
    sSchema := public.get_schema();
  END IF;

  CREATE TEMPORARY TABLE if not EXISTS tmp_seq_remake (
    NUME_SEQ   VARCHAR(100),
    NUME_TAB   VARCHAR( 50),
    NUME_COL   VARCHAR( 50),
    VAL_SEQ    BIGINT,
    VAL_COL    BIGINT
  ) ON COMMIT PRESERVE ROWS;
  TRUNCATE tmp_seq_remake;

  INSERT INTO tmp_seq_remake (NUME_SEQ, NUME_TAB, NUME_COL, VAL_SEQ, VAL_COL)
  WITH seq AS (
    SELECT
      sequencename, COALESCE(NULLIF(LAST_VALUE , 0), start_value, min_value) val_seq,
      CASE
        WHEN sequencename = 'seq_alerta_info_codalerteinfo'  THEN 'alerte_info'
        WHEN sequencename = 'seq_alerta_info_rulare'         THEN 'alerte_info'
        WHEN sequencename = 'seq_autorizatii_codautorizatii' THEN 'nautorizatiiauto'
        WHEN sequencename = 'seq_balstocrest_cod'            THEN 'bal_stoc_rest'
        WHEN sequencename = 'seq_comanda1_codcomanda2'       THEN 'comanda2'
        WHEN sequencename = 'seq_comanda2_codcomanda3'       THEN 'comanda3'
        WHEN sequencename = 'seq_descrip_coddescriptor'      THEN 'descriptori'
        WHEN sequencename = 'seq_descript1_coddescriptor1'   THEN 'descriptori1'
        WHEN sequencename = 'seq_dpp_coddifpretprod'         THEN 'difpretprod'
        WHEN sequencename = 'seq_dpp1_coddifpretprod1'       THEN 'difpretprod1'
        WHEN sequencename = 'seq_etichcolet_cod'             THEN 'nartobjcolet'
        WHEN sequencename = 'seq_estprod1m_codestprod1m'     THEN 'estimariprod1m'
        WHEN sequencename = 'seq_estprod1m_codestprod1m'     THEN 'estimariprod1m'
        WHEN sequencename = 'seq_estprod1n_codestprod1n'     THEN 'estimariprod1n'
        WHEN sequencename = 'seq_iesirir_codiesr'            THEN 'iesiriretail'
        WHEN sequencename = 'seq_iesiri1r_codies1r'          THEN 'iesiri1retail'
        WHEN sequencename = 'seq_medext_codmedext'           THEN 'medex_tari'
        WHEN sequencename = 'seq_nelemaero_codelemaero'      THEN 'nelemaeroauto'
        WHEN sequencename = 'seq_ninterv_codinterv'          THEN 'ninterventiiauto'
        WHEN sequencename = 'seq_npartcodfisc_cod_codfiscal' THEN 'npartcodfisc'
        WHEN sequencename = 'seq_npartlc_codnpartlc'         THEN 'npartlstclase'
        WHEN sequencename = 'seq_pmp_all_luna'               THEN 'pmp_all_luna'
        WHEN sequencename = 'seq_prelpret_retail'            THEN 'syncpretretail'
        WHEN sequencename = 'seq_prioritategantt'            THEN 'gantt'
        WHEN sequencename = 'seq_procactdate_codprocact'     THEN 'proc_act_date'
        WHEN sequencename = 'seq_procactdate1_codprocact1'   THEN 'proc_act_date1'
        WHEN sequencename = 'seq_procactdef_codprocdef'      THEN 'proc_act_def'
        WHEN sequencename = 'seq_rapstocmedist'              THEN 'rapstocmedist'
        WHEN sequencename = 'seq_restobiecte_cod'            THEN 'restobiect'
        WHEN sequencename = 'seq_sysnpretretail_codsync'     THEN 'syncpretretail'
        WHEN sequencename = 'seq_tipsedii1_codtipsediu1'     THEN 'ntipsedii1'
        WHEN sequencename = 'seq_user_lists_listid'          THEN 'menuliste'
        WHEN sequencename = 'seq_trigar_modif'               THEN 'trigar_modif'
        WHEN sequencename = 'seq_sintezaemul1_codsinteza1'   THEN 'sintezaemulare1'
        WHEN sequencename = 'seq_sintezaemul2_codsinteza2'   THEN 'sintezaemulare2'
        WHEN sequencename = 'seq_stobjasoc_codstobjasoc'     THEN 'settaskobjasoc'
        WHEN position('_' IN SUBSTRING(sequencename,5)) = 0  THEN SUBSTRING(sequencename, 5)
        ELSE                                                      SUBSTRING(sequencename, 5, length(sequencename) - position('_' IN REVERSE(sequencename)) - 4 )
      END table_name,
      CASE -- in principiu secventa este asociata primei coloane din tabela, iar exceptiile sunt in acest CASE
        WHEN sequencename = 'seq_alerta_info_rulare'         THEN 'codrulare'
        WHEN sequencename = 'seq_etichcolet_cod'             THEN 'idcolet'
        WHEN sequencename = 'seq_emulare_bonid'              THEN 'idbon'
        WHEN sequencename = 'seq_prelpret_retail'            THEN 'idpreluare'
        WHEN sequencename = 'seq_trigar_modif'               THEN 'codmodif'
        WHEN sequencename = 'seq_prioritategantt'            THEN 'prioritate'
        WHEN sequencename = 'SEQ_STAREESTIMARI1_CODSTARE1'  THEN 'CODSTARE1'
        WHEN sequencename = 'SEQ_NMVS_CODNMVS'              THEN 'CODNMVS'
        ELSE null
      END column_name
    FROM pg_sequences
    WHERE schemaname = sSchema
      AND sequencename &lt;&gt; 'seq_condcor2_codcondcor2'
      AND sequencename &lt;&gt; 'seq_inventloc_codinventloc'
      AND sequencename &lt;&gt; 'seq_job_listconfig_codj'
      AND sequencename &lt;&gt; 'seq_job_liste_tableid'
      AND sequencename &lt;&gt; 'seq_jobunic'
      AND sequencename &lt;&gt; 'seq_list_counter'
      AND sequencename &lt;&gt; 'seq_nparc3_codnparc0'
      AND sequencename &lt;&gt; 'seq_npartoportunitati_cpo'
      AND sequencename &lt;&gt; 'seq_nri_cmdinterna'
      AND sequencename &lt;&gt; 'seq_nrinv_mf'
      AND sequencename &lt;&gt; 'seq_pcdistrib_codpcdistrib'
      AND sequencename &lt;&gt; 'seq_pcfirma_codpcfirma'
      AND sequencename &lt;&gt; 'seq_serie_unica'
      AND sequencename &lt;&gt; 'seq_tarifemaster_codtarifm'
      AND sequencename &lt;&gt; 'seq_trezor1reg_codtrez1reg'
      AND sequencename &lt;&gt; 'seq_alerte1_codalerta1'
      AND sequencename &lt;&gt; 'seq_alerte1_def_codalertedef1'
      AND sequencename &lt;&gt; 'seq_cmdtl_codcmdtl'
      AND sequencename &lt;&gt; 'seq_nperstiplucr_codtiplucr'
      AND sequencename &lt;&gt; 'seq_procactdate1_codprocact1'
      AND sequencename &lt;&gt; 'seq_procactdate_codprocact'
      AND sequencename &lt;&gt; 'seq_rac_rezp_cod'
      AND sequencename &lt;&gt; 'seq_rac_rezs_cod'
      AND sequencename &lt;&gt; 'seq_user_lists_listid'
      AND sequencename &lt;&gt; 'seq_natrtrad_codnatrtrad'
      AND sequencename &lt;&gt; 'seq_tvadisc_codtvadisc'
  ),
  col AS (
    SELECT table_name, column_name
    FROM information_schema.COLUMNS
    WHERE table_schema = sSchema
      AND ordinal_position = 1
  )
  SELECT seq.sequencename, col.table_name, coalesce(seq.column_name, col.column_name) column_name, seq.val_seq, 0 val_col
  FROM seq LEFT JOIN col ON col.table_name = seq.table_name;

  -- curatare seqvente din public aiurea
  FOR vRec IN (
    SELECT NUME_SEQ
    FROM pg_sequences seqp INNER JOIN tmp_seq_remake seqs ON seqs.NUME_SEQ = seqp.sequencename
    WHERE seqp.schemaname = 'public'
  ) LOOP
    BEGIN
      EXECUTE 'DROP SEQUENCE public.'||nume_seq;
    EXCEPTION
      WHEN OTHERS THEN NULL;
    END;
  END LOOP;

  UPDATE tmp_seq_remake SET val_col = fnc_seqvalmin(NUME_TAB, NUME_COL)+1;
  UPDATE tmp_seq_remake SET val_seq = setval(sSchema||'.'||nume_seq, val_col::bigint) WHERE val_seq &lt; Coalesce(val_col, 0);
  DELETE FROM tmp_seq_remake WHERE val_seq &gt;= Coalesce(val_col, 0);
  SELECT string_agg(nume_seq,';' ORDER BY nume_seq) INTO vRes FROM tmp_seq_remake;
  RETURN vRes;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_remake_sequences_remake_sequence</obj_name>
  <obj_hashval>106af0b5a87f59d63f1c4e3a1cf6056d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_remake_sequences_remake_sequence(nume_tbl character varying, nume_colcod character varying, nume_seq character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  val_col NUMERIC;
  val_seq NUMERIC;
  sSchema VARCHAR;
BEGIN
  --Stef 27.02.2023
  BEGIN
    EXECUTE 'DROP SEQUENCE public.'||nume_seq; --DROP din public daca exista (erori de creare anterioare)
  EXCEPTION
    WHEN OTHERS THEN NULL;
  END;

  sSchema := lower(getfirmaname());
  IF NULLIF(sSchema, '') IS NULL THEN
    sSchema := public.get_schema();
  END IF;

  EXECUTE 'SELECT MAX('||nume_colcod||')+1 FROM '||nume_tbl INTO val_col;

  BEGIN
    SELECT NEXTVAL(nume_seq) INTO val_seq;
  EXCEPTION
    WHEN OTHERS THEN val_Seq := 101;
  END;

  val_seq := GREATEST(COALESCE(val_seq, 0), COALESCE(val_col, 0), 101);

  BEGIN
    EXECUTE 'DROP SEQUENCE '||sSchema||'.'||nume_seq; --DROP din schema firmei
  EXCEPTION
    WHEN OTHERS THEN NULL;
  END;

  EXECUTE 'CREATE SEQUENCE '||sSchema||'.'||nume_seq||' START WITH '||val_seq::varchar||' INCREMENT BY 1';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_calcualeazadiscount</obj_name>
  <obj_hashval>36c4b776f3825be44966674585606e78</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_calcualeazadiscount(agest numeric, adata_start character varying, adata_end character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  NR numeric := 0;
BEGIN
  --Florin 28.11.2023 - sinc. Oracle
  --Florin 26.05.2022 - to_timestamp
  --Florin 18.05.2022
  DELETE FROM TMP_LIVR_IN_INTERVALUL;
  -- ACTUALIZE VANZARI NEPRELUATE IN INTERVALUL ANALIZAT

  INSERT INTO TMP_LIVR_IN_INTERVALUL(CODOBIECT, CANTNIR)
  SELECT
     NP1.CODOBIECT,
     SUM(NP1.CANT*NP1.PRET*NP1.DISCOUNT/100)
  FROM
    RESTNP NP,
    RESTNP1 NP1,
    RESTCMD C
    LEFT JOIN MESE M ON M.CODMASA = C.CODMASA
    LEFT JOIN SALI S ON S.CODSALA = M.CODSALA
    LEFT JOIN RESTGESTIMPLICITE RG ON RG.CODRESTAURANT = S.CODRESTAURANT
  WHERE
    C.CODRESTCMD = NP.CODRESTCMD AND NP1.CODOBIECT = RG.CODOBIECT
    AND coalesce(NP.DATACREARE, to_timestamp('01.01.2000', 'DD.MM.YYYY')) &gt;= to_timestamp(aData_Start, 'DD.MM.YYYY hh24:mi')
    AND coalesce(NP.DATACREARE, to_timestamp('01.01.2000', 'DD.MM.YYYY')) &lt;= to_timestamp(aData_END,  'DD.MM.YYYY hh24:mi')
    AND coalesce(NP.PROTOCOL, 0) = 0
    AND NP.CODRESTNP = NP1.CODRESTNP
    AND RG.GESTIMPLICITA = aGEST
  GROUP BY NP1.CODOBIECT;

  UPDATE TMP_BALANTA_STOC SD SET DISCOUNT = coalesce(SD.DISCOUNT, 0) + N.CANTNIR FROM TMP_LIVR_IN_INTERVALUL N WHERE N.CODOBIECT = SD.CODOBIECT;

end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_canlockmasa</obj_name>
  <obj_hashval>4e75baf4ef1ace25d67e79eba40ad0df</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_canlockmasa(INOUT wme_result numeric, INOUT acodmasa numeric, INOUT acodospatar numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  NR numeric := 0;
begin
  BEGIN
    SELECT COALESCE( BLOCATA, 0) INTO NR
    FROM MESE
    WHERE
       CODMASA = aCODMASA
       AND (  (USERID &lt;&gt; TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999'))
              OR
              (USERID =  TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999') AND  COALESCE( CODOSPATAR, 0) &lt;&gt; COALESCE( aCODOSPATAR, 0))
           );
  EXCEPTION WHEN OTHERS THEN
    NR := 0;
  END;

  IF  NR &gt; 0 THEN
    WME_Result :=  0;
    RETURN;
  ELSE
    UPDATE MESE
    SET
      BLOCATA     = 1,
      USERID      = TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999'),
      CODOSPATAR  = COALESCE( aCODOSPATAR, 0)
    WHERE CODMASA = aCODMASA;

    WME_Result :=  1;
    RETURN;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_canlocknrcmd</obj_name>
  <obj_hashval>ea582f08b76ed97ba98711375c7930b5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_canlocknrcmd(INOUT wme_result numeric, INOUT acodmasa numeric, INOUT adata character varying, INOUT anrcmd numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  NR numeric := 0;
begin
  IF  aCODMASA &gt; 0 THEN
    SELECT COUNT( *) INTO NR FROM NRCMDRESTLOCK WHERE CODMASA = aCODMASA AND  DATA = TO_DATE( aDATA, 'DD.MM.YYYY') AND  USEDNR =  aNRCMD;
  ELSE
    SELECT COUNT( *) INTO NR FROM NRCMDRESTLOCK WHERE DATA = TO_DATE( aDATA, 'DD.MM.YYYY') AND  USEDNR = aNRCMD;
  END IF;

  IF  NR &gt; 0 THEN
    WME_Result :=  0;
    RETURN;
  ELSE
    INSERT INTO NRCMDRESTLOCK(CODMASA, DATA, USERID, USEDNR)
    VALUES(aCODMASA, TO_DATE( aDATA, 'DD.MM.YYYY'), TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999'), aNRCMD);

    WME_Result :=  1;
    RETURN;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_get_comanda</obj_name>
  <obj_hashval>edb6ea73e09d043533af1f405c136698</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_get_comanda(acodcomanda numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 08.11.2024 - sinc. Oracle
  -- Bogdan 30.06.2023 - sincronizare
  --Florin 29.06.2022 - fnc_getprocenttvaart
  --Florin 17.05.2022 - sinc. Oracle
  DELETE FROM TMP_RESTCMD;
  DELETE FROM TMP_RESTCMD1;
  DELETE FROM TMP_RESTCMD1_INITIAL;

  INSERT INTO TMP_RESTCMD(CODRESTCMD, NRCOMANDA, CODMASA, CODOSPATAR, VALOARE, DESCHIDERE, INCHIDERE, INCHISA, OBS, NRPERS, NUMEPERS)
  SELECT CODRESTCMD, NRCOMANDA, CODMASA, CODOSPATAR, VALOARE, DESCHIDERE, INCHIDERE, INCHISA, R.OBS, NRPERS, P.NUME || ' ' || P.PRENUME
  FROM RESTCMD R
       LEFT JOIN OSPATARI O ON  O.COD     = R.CODOSPATAR
       LEFT JOIN NPERS    P ON  P.CODPERS = O.CODPERS
  WHERE CODRESTCMD = ACODCOMANDA;

  INSERT INTO TMP_RESTCMD1(CODRESTCMD1, CODRESTCMD, INDEXLOCAL, CODOBIECT, UMSEC, PRET, CANT, OBS, DENUMIRE, DUM, VALOARE, CODGEST, LISTAREGEST, FARALISTARE, TIPUM, CANTARIT, PROCTVA, ORDINE, TAXA)
  SELECT R1.CODRESTCMD1, R1.CODRESTCMD, R1.INDEXLOCAL, R1.CODOBIECT, R1.UMSEC, R1.PRET, R1.CANT, R1.OBS, O.DENUMIRE, U1.DEN_UM1, R1.CANT * R1.PRET, R1.CODGEST, R1.LISTAREGEST, R1.FARALISTARE,
  R1.TIPUM, R1.CANTARIT, COALESCE(R1.PROCTVA, fnc_getprocenttvaart(A.CODARTICOL, getANLUCRU(), getLUNALUCRU())),R1.ORDINE, R1.TAXA
  FROM RESTCMD1 R1, NARTOBJ O, NART A, NUM1 U1
  WHERE
     EXISTS (SELECT R.CODRESTCMD FROM TMP_RESTCMD R WHERE R.CODRESTCMD = R1.CODRESTCMD)
     AND  O.CODOBIECT = R1.CODOBIECT
     AND  A.CODARTICOL = O.CODARTICOL
     AND  U1.CODUM1 = R1.UMSEC;

  INSERT INTO TMP_RESTCMD1_INITIAL(CODRESTCMD1) SELECT CODRESTCMD1 FROM TMP_RESTCMD1;

  UPDATE TMP_RESTCMD  SET NEWRECORD = 0;
  UPDATE TMP_RESTCMD1 SET NEWRECORD = 0;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_get_comenzi_masa</obj_name>
  <obj_hashval>c8c325434368a812e5a9c40ef9f6a3de</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_get_comenzi_masa(acodmasa numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 08.11.2024 - sinc. Oracle
  -- Bogdan 30.06.2023 - sincronizare
  --Florin 09.06.2022 - fnc_getprocenttvaart
  --Florin 17.05.2022 - sinc. Oracle
  --Adina 12.02.2021 - modif.Oracle din 10.02.2021
  DELETE FROM TMP_RESTCMD;
  DELETE FROM TMP_RESTCMD1;
  DELETE FROM TMP_RESTCMD1_INITIAL;

  INSERT INTO TMP_RESTCMD(CODRESTCMD, NRCOMANDA, CODMASA, CODOSPATAR, VALOARE, DESCHIDERE, INCHIDERE, INCHISA, OBS, NRPERS, NUMEPERS, ADRESALIVRARE)
  SELECT CODRESTCMD, NRCOMANDA, CODMASA, CODOSPATAR, VALOARE, DESCHIDERE, INCHIDERE, INCHISA, R.OBS, NRPERS, P.NUME || ' ' || P.PRENUME, ADRESALIVRARE
  FROM RESTCMD R
       LEFT JOIN OSPATARI O ON  O.COD     = R.CODOSPATAR
       LEFT JOIN NPERS    P ON  P.CODPERS = O.CODPERS
  WHERE CODMASA = ACODMASA AND  COALESCE( INCHISA, 0) = 0
  ORDER BY CODRESTCMD ;


  INSERT INTO TMP_RESTCMD1(CODRESTCMD1, CODRESTCMD, INDEXLOCAL, CODOBIECT, UMSEC, PRET, CANT, OBS, DENUMIRE, DUM, VALOARE, CODGEST, LISTAREGEST, FARALISTARE, PARITATE, TIPUM, CANTARIT, PROCTVA, ORDINE, TAXA)
  SELECT R1.CODRESTCMD1, R1.CODRESTCMD, R1.INDEXLOCAL, R1.CODOBIECT, R1.UMSEC, R1.PRET, R1.CANT, R1.OBS, O.DENUMIRE, U1.DEN_UM1, R1.CANT * R1.PRET, R1.CODGEST, R1.LISTAREGEST, R1.FARALISTARE,
  U1.PARITATE, R1.TIPUM, R1.CANTARIT, COALESCE(R1.PROCTVA, fnc_getprocenttvaart(A.CODARTICOL, getANLUCRU(), getLUNALUCRU())), R1.ORDINE, R1.TAXA
  FROM RESTCMD1 R1, NARTOBJ O, NART A, NUM1 U1
  WHERE
     EXISTS (SELECT R.CODRESTCMD FROM TMP_RESTCMD R WHERE R.CODRESTCMD = R1.CODRESTCMD)
     AND  O.CODOBIECT = R1.CODOBIECT
     AND  A.CODARTICOL = O.CODARTICOL
     AND  U1.CODUM1 = R1.UMSEC;

  INSERT INTO TMP_RESTCMD1_INITIAL(CODRESTCMD1) SELECT CODRESTCMD1 FROM TMP_RESTCMD1;

  UPDATE TMP_RESTCMD  SET NEWRECORD = 0;
  UPDATE TMP_RESTCMD1 SET NEWRECORD = 0;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_get_gest_ver_list</obj_name>
  <obj_hashval>cfe2ad4b2e8423c6182ada144f0fb9ce</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_get_gest_ver_list()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_RESTGESTLISTVER;

  INSERT INTO TMP_RESTGESTLISTVER(COD, CODGEST, LISTVER, FARALISTARE, DENGEST, DENVER, NEWRECORD)
  SELECT R.COD, R.CODGEST, R.LISTVER, R.FARALISTARE, G.DEN_GEST, L.NAME, 0
  FROM RESTGESTLISTVER R
       LEFT JOIN WINMADMIN.LISTS L ON  L.LISTVER = R.LISTVER AND  L.LISTID = 279,
       NGEST G
  WHERE
     G.CODGEST = R.CODGEST;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_get_gestimplicite</obj_name>
  <obj_hashval>d7837f990380c44cdce2737871b84c6a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_get_gestimplicite(acodrestaurant numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_RESTGESTIMPLICITE;

  INSERT INTO TMP_RESTGESTIMPLICITE(COD, CODRESTAURANT, CODOBIECT, GESTIMPLICITA, NEWRECORD, DENOBIECT, DENGEST, CODCLASA)
  SELECT R.COD, R.CODRESTAURANT, R.CODOBIECT, R.GESTIMPLICITA, 0, O.DENUMIRE, G.DEN_GEST, A.CLASA
  FROM RESTGESTIMPLICITE R
       LEFT JOIN NGEST   G ON  G.CODGEST    = R.GESTIMPLICITA
       LEFT JOIN NARTOBJ O ON  O.CODOBIECT  = R.CODOBIECT
       LEFT JOIN NART    A ON  O.CODARTICOL = A.CODARTICOL
  WHERE CODRESTAURANT = aCODRESTAURANT;

  DELETE FROM TMP_RESTGESTIMPLICITE_INI;
  INSERT INTO TMP_RESTGESTIMPLICITE_INI(COD) SELECT COD FROM TMP_RESTGESTIMPLICITE;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_get_notaplata</obj_name>
  <obj_hashval>38a46518d08198d10f8a6264c1b11828</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_get_notaplata(acodrestcmd numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 30.09.2025 - sinc. Oracle
  --Florin 07.11.2024 - sinc. Oracle
  --Florin 29.06.2022 - fnc_getprocenttvaart
  --Florin 17.05.2022 - sinc. Oracle
  --Adina 12.02.2021 - modif.Oracle din 10.02.2021
  DELETE FROM TMP_RESTNP;
  DELETE FROM TMP_RESTNP1;
  DELETE FROM TMP_RESTNP1_INITIAL;
  DELETE FROM TMP_RESTNP2;
  DELETE FROM TMP_RESTNP2_INITIAL;

  INSERT INTO TMP_RESTNP(CODRESTNP, CODRESTCMD, NRDOC, DATADOC, CARNETDOC, CODPART, VALOARE, VALDISC, PROTOCOL, LISTATCM, TIPCASAMARCAT, TEXTNEFISCAL,
                         NEWRECORD, SALA, MASA, OSPATAR, NRCOMANDA, FACTURARE, LISTAT, ADRESALIVRARE, CODPARTRETAIL
                        )
  SELECT N.CODRESTNP, N.CODRESTCMD, N.NRDOC, N.DATADOC, N.CARNETDOC, N.CODPART, N.VALOARE, N.VALDISC, N.PROTOCOL, N.LISTATCM, N.TIPCASAMARCAT, N.TEXTNEFISCAL,
         0, S.DENUMIRE,
         CASE WHEN M.TEXTAFISARE IS NOT NULL  THEN TEXTAFISARE ELSE TO_CHAR( M.INDEXLOCAL,'9999999999') END ,
         P.NUME || ' ' || P.PRENUME, R.NRCOMANDA, N.FACTURARE, N.LISTAT, R.ADRESALIVRARE, N.CODPARTRETAIL
  FROM RESTNP N, RESTCMD R
       LEFT JOIN OSPATARI O ON  O.COD     = R.CODOSPATAR
       LEFT JOIN NPERS    P ON  P.CODPERS = O.CODPERS,
       SALI S, MESE M
  WHERE
     N.CODRESTCMD = aCODRESTCMD AND  R.CODRESTCMD = aCODRESTCMD AND  M.CODMASA = R.CODMASA AND  S.CODSALA = M.CODSALA;

  DELETE FROM RESTNP1 WHERE CODRESTNP1 = 0;-- buleli firedac

  INSERT INTO TMP_RESTNP1(CODRESTNP1, CODRESTNP, INDEXLOCAL, CODOBIECT, UMSEC, CANT, PRET, DISCOUNT, VALOARE, DENUMIRE, DUM, PROCTVA, NEWRECORD, PARITATE,
    DISCMANUAL,
    TAXA)
  SELECT N1.CODRESTNP1, N1.CODRESTNP, N1.INDEXLOCAL, N1.CODOBIECT, N1.UMSEC, N1.CANT, N1.PRET, N1.DISCOUNT, N1.CANT * N1.PRET, O.DENUMIRE, U1.DEN_UM1,
      COALESCE(N1.PROCTVA, fnc_getprocenttvaart(A.CODARTICOL, getANLUCRU(), getLUNALUCRU())), 0, U1.PARITATE, DISCMANUAL,
    (SELECT MIN(TAXA) FROM RESTCMD1 WHERE CODRESTCMD = aCODRESTCMD AND CODOBIECT = N1.CODOBIECT)
  FROM RESTNP1 N1, NARTOBJ O, NART A, NUM1 U1
  WHERE
     EXISTS (SELECT N.CODRESTNP FROM TMP_RESTNP N WHERE N.CODRESTNP = N1.CODRESTNP)
     AND  O.CODOBIECT = N1.CODOBIECT AND  A.CODARTICOL = O.CODARTICOL AND  U1.CODUM1 = N1.UMSEC;

  INSERT INTO TMP_RESTNP1_INITIAL(CODRESTNP1) SELECT CODRESTNP1 FROM TMP_RESTNP1;

  INSERT INTO TMP_RESTNP2(CODRESTNP2, CODRESTNP, TIPPLATA, VALOARE, DENUMIRE, NEWRECORD)
  SELECT N2.CODRESTNP2, N2.CODRESTNP, N2.TIPPLATA, N2.VALOARE, N2.DENUMIRE, 0
  FROM RESTNP2 N2
  WHERE
     EXISTS (SELECT N.CODRESTNP FROM TMP_RESTNP N WHERE N.CODRESTNP = N2.CODRESTNP);

  INSERT INTO TMP_RESTNP2_INITIAL(CODRESTNP2) SELECT CODRESTNP2 FROM TMP_RESTNP2;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_get_ospatari</obj_name>
  <obj_hashval>9781e8455ebd535422e8ffe38fa27c67</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_get_ospatari(acodrestaurant numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Bogdan 11.10.2023 - 59574 PG - Bug adaugare ospatari
  --Florin 25.05.2022 - fixat 54410
  DELETE FROM TMP_OSPATARI;

  INSERT INTO TMP_OSPATARI(COD, CODPERS, PAROLA, CODRESTAURANT, SUPERVIZOR, VERLISTNP, NUMEPERS, NEWRECORD, DENVERLISTNP)
    SELECT O.COD, O.CODPERS, O.PAROLA, O.CODRESTAURANT, COALESCE( O.SUPERVIZOR, 0), VERLISTNP, P.NUME || ' ' || P.PRENUME, 0, SUBSTR(L.NAME, 1, 50)
  FROM OSPATARI O
    LEFT JOIN WINMADMIN.LISTS L ON L.LISTID =282 AND L.LISTVER = O.VERLISTNP,
    NPERS P
  WHERE P.CODPERS = O.CODPERS AND  CODRESTAURANT = aCODRESTAURANT;

  DELETE FROM TMP_OSPATARI_INI;
  INSERT INTO TMP_OSPATARI_INI(COD) SELECT COD FROM TMP_OSPATARI;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_get_restclase</obj_name>
  <obj_hashval>d54d40d60351904308ee84b38be6fcd5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_get_restclase(acodrestaurant numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_RESTCLASE;
  DELETE FROM TMP_RESTARTINACTIVE;

  INSERT INTO TMP_RESTCLASE(COD, CODCLASEA, CODRESTAURANT, NEWRECORD)
  SELECT COD, CODCLASEA, CODRESTAURANT, 0
  FROM RESTCLASE
  WHERE CODRESTAURANT = aCODRESTAURANT;

  DELETE FROM TMP_RESTCLASE_INI;
  INSERT INTO TMP_RESTCLASE_INI(COD) SELECT COD FROM TMP_RESTCLASE;

  INSERT INTO TMP_RESTARTINACTIVE(CODRESTAURANT, CODOBIECT, CODCLASA, DENUMIRE, INACTIV)
  SELECT CODRESTAURANT, O.CODOBIECT, A.CLASA, O.DENUMIRE, 1
  FROM RESTARTINACTIVE R, NARTOBJ O, NART A
  WHERE CODRESTAURANT = aCODRESTAURANT AND  O.CODOBIECT = R.CODOBIECT AND  A.CODARTICOL = O.CODARTICOL;

  INSERT INTO TMP_RESTARTINACTIVE(CODRESTAURANT, CODOBIECT, CODCLASA, DENUMIRE, INACTIV)
  SELECT aCODRESTAURANT, O.CODOBIECT, A.CLASA, O.DENUMIRE, 0
  FROM NARTOBJ O, NART A
  WHERE A.CODARTICOL = O.CODARTICOL AND  A.CASADEMARCAT = 1
        AND  NOT  EXISTS (SELECT CODOBIECT FROM RESTARTINACTIVE R WHERE R.CODRESTAURANT = aCODRESTAURANT AND  R.CODOBIECT = O.CODOBIECT);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_get_restobsart</obj_name>
  <obj_hashval>d140b03a78a378e7e5fb8de82f549864</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_get_restobsart(acodrestaurant numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 18.05.2022
   DELETE FROM TMP_RESTOBSART;

  INSERT INTO TMP_RESTOBSART(COD, CODRESTAURANT, CODOBIECT, NEWRECORD, SELECTAT, OBS)
  SELECT
    COD,
    CODRESTAURANT,
    CODOBIECT,
    0,
    0,
    OBS
  FROM
   RESTOBSART
  WHERE
    CODRESTAURANT = aCODRESTAURANT   ;

  DELETE FROM TMP_RESTOBSART_INI;

  INSERT INTO TMP_RESTOBSART_INI (COD) SELECT COD FROM TMP_RESTOBSART;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_lock_stoc_cant</obj_name>
  <obj_hashval>39a9c71f9f68d4dd9467d4b470bbefee</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_lock_stoc_cant(acodrestcmd1 numeric, acodobiect numeric, acodgest numeric, acant numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  NR numeric := 0;
begin
  SELECT COUNT(*) INTO NR FROM STOCLOCKREST WHERE USERID = TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999') AND  CODRESTCMD1 = aCODRESTCMD1;

  IF  NR = 0 THEN
    INSERT INTO STOCLOCKREST(USERID, CODRESTCMD1, CODOBIECT, CODGEST, CANT)
    VALUES(TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999'), aCODRESTCMD1, aCODOBIECT, aCODGEST, aCANT);
  ELSE
    UPDATE STOCLOCKREST SET CANT = aCANT
    WHERE USERID = TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999') AND  CODRESTCMD1 = aCODRESTCMD1;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_make_balanta_stoc</obj_name>
  <obj_hashval>2b7714fc813d230d316c364910f99569</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_make_balanta_stoc(agest numeric, adata_start character varying, adata_end character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  v_rec record;
  n_rec record;
BEGIN
  --Florin 28.11.2023 - sinc. Oracle
  --Florin 26.05.2022 - fixat 54409
  --Florin 18.05.2022
  DELETE FROM TMP_BALANTA_STOC;
  PERFORM pkg_restaurant_MAKE_STOC_LA_DATA(aGEST, aDATA_START);
  PERFORM pkg_restaurant_MAKE_MISCARI_IN_INTERVALUL(aGEST, aDATA_START, aDATA_END);

  FOR N_rec IN (SELECT * FROM TMP_NIR_LA_DATA)
  LOOP
    UPDATE TMP_BALANTA_STOC SD
    SET
      codobiect = N_rec.codobiect,
      stocinitial = N_rec.CANTNIR
    WHERE N_rec.CODOBIECT = SD.CODOBIECT;
    IF NOT FOUND THEN
      INSERT INTO TMP_BALANTA_STOC(CODOBIECT, STOCINITIAL, INTRARI, IESIRI) VALUES  (N_rec.CODOBIECT, N_rec.CANTNIR, 0, 0);
    END IF;
  END LOOP;

  FOR N_rec IN (SELECT * FROM TMP_NIR_IN_INTERVALUL)
  LOOP
    UPDATE TMP_BALANTA_STOC SD
      SET INTRARI = N_rec.CANTNIR
    WHERE N_rec.CODOBIECT = SD.CODOBIECT;

    IF NOT FOUND THEN
      INSERT INTO TMP_BALANTA_STOC(CODOBIECT, STOCINITIAL, INTRARI, IESIRI) VALUES (N_rec.CODOBIECT, 0, N_rec.CANTNIR,  0);
    END IF;
  END LOOP;

  FOR N_rec IN (SELECT * FROM TMP_NIR_IN_INTERVALUL)
  LOOP
    UPDATE TMP_BALANTA_STOC SD
      SET IESIRI = N_rec.CANTNIR
    WHERE N_rec.CODOBIECT = SD.CODOBIECT;

    IF NOT FOUND THEN
      INSERT INTO TMP_BALANTA_STOC(CODOBIECT, STOCINITIAL, INTRARI, IESIRI) VALUES (N_rec.CODOBIECT, 0, 0, N_rec.CANTNIR);
    END IF;
  END LOOP;

-- detaliere iesiri pe diverse coloane
  FOR V_REC IN
 (
    SELECT
      CODOBIECT,
      TIPLIVR,
      SUM(CANT) AS CANT
     FROM
    (
       SELECT
         NS.CODOBIECT,
         L.TIPLIVR,
         L1.CANT,
         L.DATALIVR AS DATACREARE
       FROM
         LIVR1 L1,
         LIVR L,
         NIRSTOC NS,
         NIR N,
         NARTOBJ O,
         NART A
       WHERE
         L1.CODNIRSTOC = NS.CODNIRSTOC
         AND L1.CODLIVR = L.CODLIVR
         AND L.TIPLIVR &lt;&gt; 15
         AND NS.CODNIR = N.CODNIR
         AND N.GEST = aGEST
         AND O.CODOBIECT = NS.CODOBIECT
         AND A.CODARTICOL = O.CODARTICOL
         AND coalesce(A.CASADEMARCAT, 0) = 1
       ) a_pg
       WHERE
             coalesce(DATACREARE, to_timestamp('01.01.2000', 'DD.MM.YYYY hh24:mi')) &gt;= to_timestamp(aData_START, 'DD.MM.YYYY hh24:mi')
         AND coalesce(DATACREARE, to_timestamp('01.01.2000', 'DD.MM.YYYY hh24:mi')) &lt;= to_timestamp(aData_END, 'DD.MM.YYYY hh24:mi')
    GROUP BY CODOBIECT, TIPLIVR
     )
  LOOP
    IF V_REC.TIPLIVR = 14 THEN
     UPDATE
       TMP_BALANTA_STOC
     SET
      DIMINUATE = coalesce(DIMINUATE, 0) + V_REC.CANT
     WHERE
      CODOBIECT = V_REC.CODOBIECT;
    ELSE
    IF V_REC.TIPLIVR IN (12, 13, 23) THEN
     UPDATE
       TMP_BALANTA_STOC
     SET
      TRANSFERATE = coalesce(TRANSFERATE, 0) + V_REC.CANT
     WHERE
      CODOBIECT = V_REC.CODOBIECT;
    ELSE
      IF V_REC.TIPLIVR IN (16, 19, 20) THEN
       UPDATE
         TMP_BALANTA_STOC
       SET
        VANDUTE = coalesce(VANDUTE, 0) + V_REC.CANT
       WHERE
        CODOBIECT = V_REC.CODOBIECT;
    ELSE
      IF V_REC.TIPLIVR IN (24) THEN
        UPDATE
          TMP_BALANTA_STOC
        SET
          CONSUMATE = coalesce(CONSUMATE, 0) + V_REC.CANT
        WHERE
          CODOBIECT = V_REC.CODOBIECT;
      END IF;
    END IF;
    END IF;
    END IF;

  END LOOP;

  /*FOR V_REC IN
 (
  SELECT
    NS.CODOBIECT,
    NS.CANTNIR CANT
   FROM
     NIRSTOC NS,
     NIR N,
     NARTOBJ O,
     NART A,
     IOART1 IO1
  WHERE
     NS.CODNIR        = N.CODNIR
     AND N.GEST       = aGEST
     AND O.CODOBIECT  = NS.CODOBIECT
     AND O.CODARTICOL = A.CODARTICOL
     AND coalesce(A.CASADEMARCAT, 1) = 1
     AND IO1.CODIOART = NS.CODIOART
     AND IO1.MG &lt;&gt; 5
     AND coalesce(N.DATANIR, to_timestamp('01.01.2000', 'DD.MM.YYYY hh24:mi')) &gt;= to_timestamp(aData_START, 'DD.MM.YYYY hh24:mi')
     AND coalesce(N.DATANIR, to_timestamp('01.01.2000', 'DD.MM.YYYY hh24:mi')) &lt;= to_timestamp(aData_END, 'DD.MM.YYYY hh24:mi')
     AND N.TIPNIR in (12,13)
     AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) BETWEEN IO1.ALSTART AND IO1.ALSTOP
  ) loop
    UPDATE
       TMP_BALANTA_STOC
     SET
      TRANSFERATE = coalesce(TRANSFERATE, 0) - V_REC.CANT
     WHERE
      CODOBIECT = V_REC.CODOBIECT;
  end loop;*/

  FOR N_rec IN (
  SELECT
    NS.CODOBIECT,
    NS.CANTNIR CANT
   FROM
     NIRSTOC NS,
     NIR N,
     NARTOBJ O,
     NART A,
     IOART1 IO1
  WHERE
     NS.CODNIR        = N.CODNIR
     AND N.GEST       = aGEST
     AND O.CODOBIECT  = NS.CODOBIECT
     AND O.CODARTICOL = A.CODARTICOL
     AND coalesce(A.CASADEMARCAT, 1) = 1
     AND IO1.CODIOART = NS.CODIOART
     AND IO1.MG &lt;&gt; 5
     AND coalesce(N.DATANIR, to_timestamp('01.01.2000', 'DD.MM.YYYY hh24:mi')) &gt; to_timestamp(aData_START, 'DD.MM.YYYY hh24:mi')
     AND coalesce(N.DATANIR, to_timestamp('01.01.2000', 'DD.MM.YYYY hh24:mi')) &lt;= to_timestamp(aData_END, 'DD.MM.YYYY hh24:mi')
     AND N.TIPNIR in (12,13)
     AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) BETWEEN IO1.ALSTART AND IO1.ALSTOP
  )
  LOOP
    UPDATE TMP_BALANTA_STOC SD
      SET TRANSFERATE = coalesce(TRANSFERATE, 0) - N_REC.CANT
    WHERE N_rec.CODOBIECT = SD.CODOBIECT;

    IF NOT FOUND THEN
      INSERT INTO TMP_BALANTA_STOC(CODOBIECT, TRANSFERATE) VALUES (N_rec.CODOBIECT, -N_rec.CANT);
    END IF;
  END LOOP;

end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_make_stoc_data_gest</obj_name>
  <obj_hashval>f96c231a6a38dbb480727d2e603ece76</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_make_stoc_data_gest(adatastart character varying, adatastop character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
 oData date;
vDataStart date;
vDataStop date;
BEGIN
  --Florin 08.11.2024 - sinc. Oracle
  if to_date(aDataStart,'dd.mm.yyyy') &gt; to_date(aDataStop,'dd.mm.yyyy') then
    vDataStart := to_date(aDataStop,'dd.mm.yyyy');
    vDataStop := to_date(aDataStart,'dd.mm.yyyy');
  else
    vDataStart := to_date(aDataStart,'dd.mm.yyyy');
    vDataStop := to_date(aDataStop,'dd.mm.yyyy');
  end if;
  DELETE FROM TMP_STOC_DATA_GEST;
  oData := vDataStart;

  DELETE FROM TMP_STOC_DATA_GEST;
  INSERT INTO TMP_STOC_DATA_GEST (CODGEST, CODIOART, VALOARE, DATASTOC)
  SELECT
    CODGEST,
    CODIOART,
    SUM(VALOARE),
    oData
  FROM
   (
   SELECT
    N.GEST CODGEST,
    NS.CODIOART,
    NS.CANTNIR * NS.PRET VALOARE,
    N.DATANIR AS DATACREARE
   FROM
     NIRSTOC NS,
     NIR N,
     NARTOBJ O,
     NART A,
     IOART1 IO1
  WHERE
     NS.CODNIR = N.CODNIR
     AND N.OPERAT = 1
     AND NVL(N.GEST, 0) &lt;&gt; 0
     AND O.CODOBIECT = NS.CODOBIECT
     AND A.CODARTICOL = O.CODARTICOL
     AND NS.CODIOART = IO1.CODIOART
     AND IO1.MG &lt;&gt; 5
     AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) BETWEEN IO1.ALSTART AND IO1.ALSTOP
     AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) &gt;= (select aninitial*12+lunainitiala from firmaluni)
  UNION ALL
  SELECT
    N.GEST CODGEST,
    NS.CODIOART,
    NS.CANTNIR * NS.PRET VALOARE,
    N.DATANIR AS DATACREARE
  FROM
    NIRSTOC NS,
    NIR N,
    NARTOBJ O,
    NART A
  WHERE
    NS.CODNIR = N.CODNIR
    AND N.OPERAT = 1
    AND NVL(N.GEST, 0) &lt;&gt; 0
    AND O.CODOBIECT = NS.CODOBIECT
    AND A.CODARTICOL = O.CODARTICOL
    AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) &lt; (select aninitial*12+lunainitiala from firmaluni)
  ) A_PG
  WHERE
    NVL(DATACREARE, TO_DATE('01.01.2000', 'DD.MM.YYYY')) &lt; oDATA
  GROUP BY CODGEST, CODIOART;

  DELETE FROM TMP_LIVR_DATA_GEST;
  INSERT INTO TMP_LIVR_DATA_GEST(CODGEST, CODIOART, VALOARE)
  SELECT
    CODGEST,
    CODIOART,
    SUM(VALOARE) AS VALOARE
  FROM
  (
  SELECT
    N.GEST CODGEST,
    NS.CODIOART,
    CASE
      WHEN L.TIPLIVR = 15 THEN  -L1.CANT
      ELSE L1.CANT
    END * NS.PRET VALOARE,
    L.DATALIVR AS DATACREARE
  FROM
    LIVR1 L1,
    LIVR L,
    NIRSTOC NS,
    NIR N,
    NARTOBJ O,
    NART A
  WHERE
    L1.CODNIRSTOC = NS.CODNIRSTOC
    AND L1.CODLIVR = L.CODLIVR
    AND NS.CODNIR = N.CODNIR
    AND NVL(N.GEST, 0) &lt;&gt; 0
    AND O.CODOBIECT = NS.CODOBIECT
    AND A.CODARTICOL = O.CODARTICOL
  ) B_PG
  WHERE
    NVL(DATACREARE, TO_DATE('01.01.2000', 'DD.MM.YYYY')) &lt; oData
  GROUP BY CODGEST, CODIOART;

--  MERGE INTO TMP_STOC_DATA_GEST N
--  USING TMP_LIVR_DATA_GEST L
--  ON ( N.CODGEST = L.CODGEST AND N.CODIOART = L.CODIOART AND N.DATASTOC = oData)
--  WHEN MATCHED THEN UPDATE SET N.VALOARE = N.VALOARE - L.VALOARE;

  WHILE oData &lt;= vDataStop LOOP
    DELETE FROM TMP_NIR_DATA_GEST;
    INSERT INTO TMP_NIR_DATA_GEST (CODGEST, CODIOART, VALOARE)
    SELECT CODGEST, CODIOART, VALOARE
    FROM TMP_STOC_DATA_GEST
    WHERE DATASTOC = ODATA;

    oData := trunc(oData + 1);

    INSERT INTO TMP_STOC_DATA_GEST
    SELECT CODGEST, CODIOART, VALOARE, ODATA
    FROM TMP_NIR_DATA_GEST;

    DELETE FROM TMP_NIR_DATA_GEST;
    INSERT INTO TMP_NIR_DATA_GEST (CODGEST, CODIOART, VALOARE)
    SELECT
      CODGEST,
      CODIOART,
      SUM(VALOARE)
    FROM
     (
     SELECT
      N.GEST CODGEST,
      NS.CODIOART,
      NS.CANTNIR * NS.PRET VALOARE
     FROM
       NIRSTOC NS,
       NIR N,
       NARTOBJ O,
       NART A,
       IOART1 IO1
    WHERE
       NS.CODNIR = N.CODNIR
       AND N.OPERAT = 1
       AND NVL(N.GEST, 0) &lt;&gt; 0
       AND O.CODOBIECT = NS.CODOBIECT
       AND A.CODARTICOL = O.CODARTICOL
       AND NS.CODIOART = IO1.CODIOART
       AND IO1.MG &lt;&gt; 5
       AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) BETWEEN IO1.ALSTART AND IO1.ALSTOP
       AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) &gt;= (select aninitial*12+lunainitiala from firmaluni)
       AND NVL(N.DATANIR, TO_DATE('01.01.2000', 'DD.MM.YYYY')) = oDATA
    UNION ALL
    SELECT
      N.GEST CODGEST,
      NS.CODIOART,
      NS.CANTNIR * NS.PRET VALOARE
    FROM
      NIRSTOC NS,
      NIR N,
      NARTOBJ O,
      NART A
    WHERE
      NS.CODNIR = N.CODNIR
      AND N.OPERAT = 1
      AND NVL(N.GEST, 0) &lt;&gt; 0
      AND O.CODOBIECT = NS.CODOBIECT
      AND A.CODARTICOL = O.CODARTICOL
      AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) &lt; (select aninitial*12+lunainitiala from firmaluni)
      AND NVL(N.DATANIR, TO_DATE('01.01.2000', 'DD.MM.YYYY')) = oDATA
    ) C_PG
    GROUP BY CODGEST, CODIOART;

    DELETE FROM TMP_LIVR_DATA_GEST;
    INSERT INTO TMP_LIVR_DATA_GEST(CODGEST, CODIOART, VALOARE)
    SELECT
      CODGEST,
      CODIOART,
      SUM(VALOARE) AS VALOARE
    FROM
    (
    SELECT
      N.GEST CODGEST,
      NS.CODIOART,
      CASE
        WHEN L.TIPLIVR = 15 THEN  -L1.CANT
        ELSE L1.CANT
      END * NS.PRET VALOARE,
      L.DATALIVR AS DATACREARE
    FROM
      LIVR1 L1,
      LIVR L,
      NIRSTOC NS,
      NIR N,
      NARTOBJ O,
      NART A
    WHERE
      L1.CODNIRSTOC = NS.CODNIRSTOC
      AND L1.CODLIVR = L.CODLIVR
      AND NS.CODNIR = N.CODNIR
      AND NVL(N.GEST, 0) &lt;&gt; 0
      AND O.CODOBIECT = NS.CODOBIECT
      AND A.CODARTICOL = O.CODARTICOL
      AND NVL(L.DATALIVR, TO_DATE('01.01.2000', 'DD.MM.YYYY')) = oDATA
    ) D_PG
    GROUP BY CODGEST, CODIOART;

--    MERGE INTO TMP_STOC_DATA_GEST N
--    USING TMP_NIR_DATA_GEST L
--    ON ( N.CODGEST = L.CODGEST AND N.CODIOART = L.CODIOART AND N.DATASTOC = oData)
--    WHEN MATCHED THEN UPDATE SET N.VALOARE = N.VALOARE + L.VALOARE
--    WHEN NOT MATCHED THEN INSERT (N.CODGEST, N.CODIOART, N.VALOARE, N.DATASTOC)
--    VALUES (L.CODGEST, L.CODIOART, L.VALOARE, ODATA);

--    MERGE INTO TMP_STOC_DATA_GEST N
--    USING TMP_LIVR_DATA_GEST L
--    ON ( N.CODGEST = L.CODGEST AND N.CODIOART = L.CODIOART AND N.DATASTOC = oData)
--    WHEN MATCHED THEN UPDATE SET N.VALOARE = N.VALOARE - L.VALOARE;
  END LOOP;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_memo_balstocrest</obj_name>
  <obj_hashval>e5884aa596b77efec91c7a8407479c64</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_memo_balstocrest(agest numeric, adata_start character varying, adata_end character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
begin
  BEGIN
    INSERT INTO BAL_STOC_REST(COD, CODGEST, DATASTART, DATAEND)
    VALUES(NEXTVAL('SEQ_BALSTOCREST_COD'), aGEST, to_timestamp( aDATA_START, 'DD.MM.YYYY hh24:mi'), to_timestamp( aDATA_END, 'DD.MM.YYYY hh24:mi'));
  EXCEPTION WHEN OTHERS THEN
    NULL;
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_memo_restraportz</obj_name>
  <obj_hashval>4de982e2f34c35d07300c6d0a8da602d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_memo_restraportz(acodpostretail numeric, adata_start character varying, adata_end character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
begin
  BEGIN
    INSERT INTO RESTRAPORTZ(COD, CODPOSTRETAIL, DATASTART, DATAEND)
    VALUES(NEXTVAL('SEQ_RESTRAPORTZ_COD'), aCODPOSTRETAIL, to_timestamp( aDATA_START, 'DD.MM.YYYY hh24:mi'), to_timestamp( aDATA_END, 'DD.MM.YYYY hh24:mi'));
  EXCEPTION WHEN OTHERS THEN
    NULL;
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_muta_pe_alta_cmd</obj_name>
  <obj_hashval>b28377d0fbbc933798c6cb7d8cc8c976</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_muta_pe_alta_cmd(codcmdsursa numeric, codcmddest numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC       RECORD;
  aINDEXLOCAL numeric := 0;
  NR          numeric := 0;
BEGIN
  --Florin 17.05.2022 - sinc. Oracle
  BEGIN
    SELECT MAX( INDEXLOCAL) INTO aINDEXLOCAL FROM RESTCMD1 WHERE CODRESTCMD = CODCMDDEST;
  EXCEPTION WHEN OTHERS THEN
    aINDEXLOCAL := 0;
  END;

  FOR V_REC IN (SELECT M.*, R1.CODOBIECT, R1.UMSEC, R1.PRET, R1.CODGEST, R1.LISTAREGEST, R1.FARALISTARE, R1.TIPUM, R1.CANTARIT
                 FROM TMP_MUTACMD M, RESTCMD1 R1
                 WHERE CANTMUTATA &gt; 0 AND R1.CODRESTCMD1 = M.CODRESTCMD1)
  LOOP
    aINDEXLOCAL := aINDEXLOCAL + 1;
    INSERT INTO RESTCMD1(CODRESTCMD1, CODRESTCMD, INDEXLOCAL, CODOBIECT, UMSEC, PRET, CANT,  CODGEST, LISTAREGEST, FARALISTARE, TIPUM, CANTARIT)
    VALUES (NEXTVAL('SEQ_RESTCMD1_CODRESTCMD1'), CODCMDDEST, aIndexLocal, V_REC.CODOBIECT, V_REC.UMSEC, V_REC.PRET, V_REC.CANTMUTATA, V_REC.CODGEST, V_REC.LISTAREGEST, V_REC.FARALISTARE, V_REC.TIPUM, V_REC.CANTARIT);

    UPDATE RESTCMD1 SET CANT = CANT - V_REC.CANTMUTATA WHERE CODRESTCMD1 = V_REC.CODRESTCMD1;
  END LOOP;

  DELETE FROM RESTCMD1 WHERE CODRESTCMD = CODCMDSURSA AND  CANT = 0;

  SELECT COUNT( *) INTO NR FROM RESTCMD1 WHERE CODRESTCMD = CODCMDSURSA;

  IF  NR = 0 THEN
    DELETE FROM RESTCMD WHERE CODRESTCMD = CODCMDSURSA;
  ELSE
    UPDATE RESTCMD
    SET
      VALOARE = (SELECT SUM( PRET * CANT) FROM RESTCMD1 WHERE CODRESTCMD = CODCMDSURSA)
    WHERE
     CODRESTCMD = CODCMDSURSA;
  END IF;

  UPDATE RESTCMD
  SET
    VALOARE = (SELECT SUM( PRET * CANT) FROM RESTCMD1 WHERE CODRESTCMD = CODCMDDEST)
  WHERE
   CODRESTCMD = CODCMDDEST;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_mutacmd</obj_name>
  <obj_hashval>ba18b029c7285f26921b504dd7f5b487</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_mutacmd(codcmdsursa numeric, masadest numeric, destnrcmd numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC           RECORD;
  DESTCODCMD      numeric := 0;
  OSPATARCMDSURSA numeric := 0;
  aINDEXLOCAL     numeric := 0;
  NR              numeric := 0;
BEGIN
  --Florin 17.05.2022 - sinc. Oracle
  SELECT NEXTVAL('SEQ_RESTCMD_CODRESTCMD') INTO DESTCODCMD;

  BEGIN
    SELECT COALESCE( CODOSPATAR, 0) INTO OSPATARCMDSURSA FROM RESTCMD WHERE CODRESTCMD = CODCMDSURSA;
  EXCEPTION WHEN OTHERS THEN
    OSPATARCMDSURSA := 0;
  END;

  INSERT INTO RESTCMD(CODRESTCMD, NRCOMANDA, CODMASA, CODOSPATAR, DESCHIDERE)
  VALUES(DESTCODCMD, DESTNRCMD, MASADEST, OSPATARCMDSURSA, CURRENT_TIMESTAMP);

  aINDEXLOCAL := 0;
    FOR V_REC IN (SELECT M.*, R1.CODOBIECT, R1.UMSEC, R1.PRET, R1.CODGEST, R1.LISTAREGEST, R1.FARALISTARE, R1.TIPUM, R1.CANTARIT
                  FROM TMP_MUTACMD M, RESTCMD1 R1
                  WHERE CANTMUTATA &gt; 0 AND R1.CODRESTCMD1 = M.CODRESTCMD1)
  LOOP
    aINDEXLOCAL := aINDEXLOCAL + 1;
    INSERT INTO RESTCMD1(CODRESTCMD1, CODRESTCMD, INDEXLOCAL, CODOBIECT, UMSEC, PRET, CANT,  CODGEST, LISTAREGEST, FARALISTARE, TIPUM, CANTARIT)
    VALUES(NEXTVAL('SEQ_RESTCMD1_CODRESTCMD1'), DESTCODCMD, aIndexLocal, V_REC.CODOBIECT, V_REC.UMSEC, V_REC.PRET, V_REC.CANTMUTATA, V_REC.CODGEST, V_REC.LISTAREGEST, V_REC.FARALISTARE, V_REC.TIPUM, V_REC.CANTARIT);
    UPDATE RESTCMD1 SET CANT = CANT - V_REC.CANTMUTATA WHERE CODRESTCMD1 = V_REC.CODRESTCMD1;
  END LOOP;

  DELETE FROM RESTCMD1 WHERE CODRESTCMD = CODCMDSURSA AND  CANT = 0;

  SELECT COUNT( *) INTO NR FROM RESTCMD1 WHERE CODRESTCMD = CODCMDSURSA;

  IF  NR = 0 THEN
    DELETE FROM RESTCMD WHERE CODRESTCMD = CODCMDSURSA;
  ELSE
    UPDATE RESTCMD
    SET
      VALOARE = (SELECT SUM( PRET * CANT) FROM RESTCMD1 WHERE CODRESTCMD = CODCMDSURSA)
    WHERE
     CODRESTCMD = CODCMDSURSA;
  END IF;

  UPDATE RESTCMD
  SET
    VALOARE = (SELECT SUM( PRET * CANT) FROM RESTCMD1 WHERE CODRESTCMD = DESTCODCMD)
  WHERE
   CODRESTCMD = DESTCODCMD;

  UPDATE MESE SET STARE = 2 WHERE CODMASA = MASADEST;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_nepreluate</obj_name>
  <obj_hashval>06681f409656e444cbaedae621cd4811</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_nepreluate(agest numeric, adata_start character varying, adata_end character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 28.11.2023 - sinc. Oracle
  --Florin 18.05.2022
    DELETE FROM TMP_LIVR_IN_INTERVALUL;
  -- ACTUALIZE VANZARI NEPRELUATE IN INTERVALUL ANALIZAT

  INSERT INTO TMP_LIVR_IN_INTERVALUL(CODOBIECT, CANTNIR)
  SELECT
     C1.CODOBIECT,
     SUM(C1.CANT) AS CANT
  FROM
    RESTNP NP
    LEFT JOIN EMULARE E ON E.CODRESTNP = NP.CODRESTNP,
    RESTCMD1 C1,
    RESTCMD C,
    NARTOBJ O
  WHERE
    C.CODRESTCMD = C1.CODRESTCMD
    AND coalesce(NP.DATACREARE, to_timestamp('01.01.2000', 'DD.MM.YYYY')) &gt;= to_timestamp(aData_Start, 'DD.MM.YYYY hh24:mi')
    AND coalesce(NP.DATACREARE, to_timestamp('01.01.2000', 'DD.MM.YYYY')) &lt;= to_timestamp(aData_END,  'DD.MM.YYYY hh24:mi')
    AND (

         (coalesce(E.PRELUAT, 0) + coalesce(NP.protocol, 0) + coalesce(NP.facturare, 0) = 0 ) OR
         ((coalesce(NP.protocol, 0) + coalesce(NP.facturare, 0)  &gt;0 ) and coalesce(C.diminuat,0)= 0)
        )
    AND C1.CODRESTCMD = NP.CODRESTCMD
    AND C1.CODGEST = aGEST
    AND O.CODOBIECT = C1.CODOBIECT
  GROUP BY C1.CODOBIECT;

  UPDATE TMP_BALANTA_STOC SD SET NEPRELUATE  = coalesce(SD.NEPRELUATE, 0)  +  N.CANTNIR FROM TMP_LIVR_IN_INTERVALUL N WHERE N.CODOBIECT = SD.CODOBIECT;

end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_post_bonemulare</obj_name>
  <obj_hashval>a14cadb75e92359e9939fc0a076fc493</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_post_bonemulare()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCODEMULARE numeric;
begin
  SELECT NEXTVAL('SEQ_EMULARE_CODEMULARE') INTO aCODEMULARE;

  INSERT INTO EMULARE(CodEmulare, NrBon, DataBon, Valoare, ValoareDiscount, Listat, Preluat, CodCasaMarcat, TVATOTAL, TVADISCOUNT, TIPCASAMARCAT, USERID, DATACREARE, DATALISTARE, CODPART, CODPERS, CODIES, INCASARECLIENT, CODPOSTRETAIL, CODAECUSTODIE, CODLOCATIE, CODAGENT, OBS, CODRESTNP)
  (SELECT aCODEMULARE, NrBon, DataBon, Valoare, ValoareDiscount, Listat, Preluat, CodCasaMarcat, TVATOTAL, TVADISCOUNT, TIPCASAMARCAT, TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999'), current_timestamp, DATALISTARE, CODPART, CODPERS, CODIES, INCASARECLIENT, CODPOSTRETAIL, CODAECUSTODIE, CODLOCATIE, CODAGENT, OBS, CODRESTNP
   FROM TMP_EMULARE
  );

  INSERT INTO EMULARE1(CodEmulare1, CodEmulare, CodObiect, INDEXLOCAL, PretArt, Pret, Cant, UmSec, Discount, TIPLINIE, TVA, CODGEST, CODIOART, PRETNIRSTOC, CONTSERV, FARASTOC, CODCOMANDA1, TIPLIVRARE, CADOU, PRETPROMO, CODGESTORIG, CODEMULSTINGERE)
  SELECT NEXTVAL('SEQ_EMULARE1_CODEMULARE1'), aCODEMULARE, CodObiect, INDEXLOCAL, PretArt, Pret, Cant, UmSec, Discount, TIPLINIE, TVA, CODGEST, CODIOART, PRETNIRSTOC, CONTSERV, FARASTOC, CODCOMANDA1, TIPLIVRARE, CADOU, PRETPROMO, CODGESTORIG, CODEMULSTINGERE
  FROM TMP_EMULARE1;

  INSERT INTO EMULARE2(CodEmulare2, CodEmulare, TipPlata, Valoare, Denumire)
  SELECT NEXTVAL('SEQ_EMULARE2_CODEMULARE2'), aCODEMULARE, TipPlata, Valoare, Denumire
  FROM TMP_EMULARE2;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_post_comanda</obj_name>
  <obj_hashval>1c49cbc9f18acb1229e05a85085ec2f4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_post_comanda()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
BEGIN
  --Florin 08.11.2024 - sinc. Oracle
  -- Bogdan 30.06.2023 - sincronizare
  --Florin 17.05.2022 - sinc. Oracle
  --Adina 12.02.2021 - modif.Oracle din 10.02.2021
  UPDATE TMP_RESTCMD C
  SET
     VALOARE = (SELECT SUM( PRET * CANT) FROM TMP_RESTCMD1 C1 WHERE C1.CODRESTCMD = C.CODRESTCMD);

  FOR V_REC IN (SELECT * FROM TMP_RESTCMD) LOOP
    IF  COALESCE( V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE RESTCMD
      SET
        NRCOMANDA     = V_REC.NRCOMANDA,
        CODMASA       = V_REC.CODMASA,
        CODOSPATAR    = V_REC.CODOSPATAR,
        VALOARE       = V_REC.VALOARE,
        DESCHIDERE    = V_REC.DESCHIDERE,
        INCHIDERE     = V_REC.INCHIDERE,
        INCHISA       = V_REC.INCHISA,
        OBS           = V_REC.OBS,
        NRPERS        = V_REC.NRPERS,
        ADRESALIVRARE = V_REC.ADRESALIVRARE
      WHERE
       CODRESTCMD = V_REC.CODRESTCMD
      ;
    ELSE
      INSERT INTO RESTCMD(CODRESTCMD, NRCOMANDA, CODMASA, CODOSPATAR, VALOARE, DESCHIDERE, INCHIDERE, INCHISA, OBS, NRPERS, ADRESALIVRARE)
      VALUES(V_REC.CODRESTCMD, V_REC.NRCOMANDA, V_REC.CODMASA, V_REC.CODOSPATAR, V_REC.VALOARE, V_REC.DESCHIDERE, V_REC.INCHIDERE, V_REC.INCHISA, V_REC.OBS, V_REC.NRPERS, V_REC.ADRESALIVRARE);
    END IF;
  END LOOP;

  DELETE FROM RESTCMD1 R1 WHERE CODRESTCMD = (SELECT CODRESTCMD FROM TMP_RESTCMD);

  FOR V_REC IN (SELECT * FROM TMP_RESTCMD1) LOOP
    INSERT INTO RESTCMD1(CODRESTCMD1, CODRESTCMD, INDEXLOCAL, CODOBIECT, UMSEC, PRET, CANT, OBS, CODGEST, LISTAREGEST, FARALISTARE, TIPUM, CANTARIT, PROCTVA, ORDINE, TAXA)
    VALUES (V_REC.CODRESTCMD1, V_REC.CODRESTCMD, V_REC.INDEXLOCAL, V_REC.CODOBIECT, V_REC.UMSEC, V_REC.PRET, V_REC.CANT, V_REC.OBS, V_REC.CODGEST, V_REC.LISTAREGEST, V_REC.FARALISTARE, V_REC.TIPUM, V_REC.CANTARIT, V_REC.PROCTVA, V_REC.ORDINE, V_REC.TAXA);
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_RESTCMD) LOOP
    UPDATE RESTCMD
    SET
      VALOARE = (SELECT SUM( CANT * PRET) FROM RESTCMD1 WHERE CODRESTCMD = V_REC.CODRESTCMD)
    WHERE
     CODRESTCMD = V_REC.CODRESTCMD;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_post_comenzi_masa</obj_name>
  <obj_hashval>855eba9f98c01482e60614c8334fc7fb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_post_comenzi_masa(acodmasa numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
BEGIN
  -- Bogdan 30.06.2023 - sincronizare
  --Florin 17.05.2022 - sinc. Oracle
  FOR V_REC IN (SELECT * FROM RESTCMD R
                WHERE CODMASA = ACODMASA AND  COALESCE( INCHISA, 0) = 0
                      AND  NOT  EXISTS (SELECT CODRESTCMD FROM TMP_RESTCMD RT WHERE RT.CODRESTCMD = R.CODRESTCMD)
               )
  LOOP
    DELETE FROM NRCMDRESTLOCK
    WHERE USERID = TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999') AND  CODMASA = V_REC.CODMASA AND  USEDNR = V_REC.NRCOMANDA;

    DELETE FROM RESTCMD WHERE CODRESTCMD = V_REC.CODRESTCMD;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_RESTCMD) LOOP
    IF  COALESCE( V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE RESTCMD
      SET
        NRCOMANDA  = V_REC.NRCOMANDA,
        CODMASA    = V_REC.CODMASA,
        CODOSPATAR = V_REC.CODOSPATAR,
        VALOARE    = V_REC.VALOARE,
        DESCHIDERE = V_REC.DESCHIDERE,
        INCHIDERE  = V_REC.INCHIDERE,
        INCHISA    = V_REC.INCHISA,
        OBS        = V_REC.OBS,
        NRPERS     = V_REC.NRPERS
      WHERE
       CODRESTCMD = V_REC.CODRESTCMD;
    ELSE
      INSERT INTO RESTCMD(CODRESTCMD, NRCOMANDA, CODMASA, CODOSPATAR, VALOARE, DESCHIDERE, INCHIDERE, INCHISA, OBS, NRPERS)
      VALUES(V_REC.CODRESTCMD, V_REC.NRCOMANDA, V_REC.CODMASA, V_REC.CODOSPATAR, V_REC.VALOARE, V_REC.DESCHIDERE, V_REC.INCHIDERE, V_REC.INCHISA, V_REC.OBS, V_REC.NRPERS);
    END IF;
  END LOOP;

  DELETE FROM RESTCMD1 R1
  WHERE EXISTS (SELECT CODRESTCMD1 FROM TMP_RESTCMD1_INITIAL RI WHERE RI.CODRESTCMD1 = R1.CODRESTCMD1)
        AND  NOT  EXISTS (SELECT CODRESTCMD1 FROM TMP_RESTCMD1 TR1 WHERE TR1.CODRESTCMD1 = R1.CODRESTCMD1);

  FOR V_REC IN (SELECT * FROM TMP_RESTCMD1) LOOP
    IF  COALESCE( V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE RESTCMD1
      SET
      CODRESTCMD  = V_REC.CODRESTCMD,
      INDEXLOCAL  = V_REC.INDEXLOCAL,
      CODOBIECT   = V_REC.CODOBIECT,
      UMSEC       = V_REC.UMSEC,
      PRET        = V_REC.PRET,
      CANT        = V_REC.CANT,
      OBS         = V_REC.OBS,
      CODGEST     = V_REC.CODGEST,
      LISTAREGEST = V_REC.LISTAREGEST,
      FARALISTARE = V_REC.FARALISTARE,
      TIPUM       = V_REC.TIPUM,
      CANTARIT    = V_REC.CANTARIT,
      PROCTVA     = V_REC.PROCTVA,
            ORDINE      = V_REC.ORDINE
      WHERE
       CODRESTCMD1 = V_REC.CODRESTCMD1;
    ELSE
      INSERT INTO RESTCMD1(CODRESTCMD1, CODRESTCMD, INDEXLOCAL, CODOBIECT, UMSEC, PRET, CANT, OBS, CODGEST, LISTAREGEST, FARALISTARE, TIPUM, CANTARIT, PROCTVA, ORDINE)
      VALUES (V_REC.CODRESTCMD1, V_REC.CODRESTCMD, V_REC.INDEXLOCAL, V_REC.CODOBIECT, V_REC.UMSEC, V_REC.PRET /  COALESCE(V_REC.PARITATE, 1), V_REC.CANT *  COALESCE(V_REC.PARITATE, 1), V_REC.OBS, V_REC.CODGEST, V_REC.LISTAREGEST, V_REC.FARALISTARE, V_REC.TIPUM, V_REC.CANTARIT, V_REC.PROCTVA, V_REC.ORDINE);
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_post_gest_ver_list</obj_name>
  <obj_hashval>6a6c3a622d78d75d73c34afcbee2ea58</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_post_gest_ver_list()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  DELETE FROM RESTGESTLISTVER R WHERE NOT EXISTS (SELECT COD FROM TMP_RESTGESTLISTVER RT WHERE RT.COD = R.COD);

  FOR V_REC IN (SELECT * FROM TMP_RESTGESTLISTVER) LOOP
    IF  COALESCE( V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE RESTGESTLISTVER
      SET
        CODGEST     = V_REC.CODGEST,
        LISTVER     = V_REC.LISTVER,
        FARALISTARE = V_REC.FARALISTARE
      WHERE COD = V_REC.COD;
    ELSE
      INSERT INTO RESTGESTLISTVER(COD, CODGEST, LISTVER, FARALISTARE)
      VALUES(V_REC.COD, V_REC.CODGEST, V_REC.LISTVER, V_REC.FARALISTARE);
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_post_notaplata</obj_name>
  <obj_hashval>cd71cb6d8ab553da3f3a49e28bb88373</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_post_notaplata()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
BEGIN
  --Florin 06.03.2025 - sinc. Oracle
  --Florin 12.11.2024 - fixat 63958
  --Florin 07.11.2024 - sinc. Oracle
  --Florin 22.05.2023 - corectie PKG_CARNETEDOC_SOLVENUMARDOC
  --Florin 17.05.2022 - sinc. Oracle
  --Adina 12.02.2021 - modif.Oracle din 10.02.2021
  FOR V_REC IN (SELECT * FROM TMP_RESTNP) LOOP
    IF  COALESCE( V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE RESTNP
      SET
        NRDOC         = V_REC.NRDOC,
        DATADOC       = V_REC.DATADOC,
        CARNETDOC     = V_REC.CARNETDOC,
        CODPART       = V_REC.CODPART,
        CODPARTRETAIL = V_REC.CODPARTRETAIL,
        VALOARE       = V_REC.VALOARE,
        VALDISC       = V_REC.VALDISC,
        PROTOCOL      = V_REC.PROTOCOL,
        LISTATCM      = V_REC.LISTATCM,
        TIPCASAMARCAT = V_REC.TIPCASAMARCAT,
        TEXTNEFISCAL  = V_REC.TEXTNEFISCAL,
        FACTURARE     = V_REC.FACTURARE,
        LISTAT        = V_REC.LISTAT
      WHERE
       CODRESTNP = V_REC.CODRESTNP;
    ELSE
      INSERT INTO RESTNP(CODRESTNP, CODRESTCMD, NRDOC, DATADOC, CARNETDOC, CODPART, CODPARTRETAIL, VALOARE, VALDISC, PROTOCOL, LISTATCM, DATACREARE, TIPCASAMARCAT, TEXTNEFISCAL, FACTURARE)
      VALUES(V_REC.CODRESTNP, V_REC.CODRESTCMD, V_REC.NRDOC, V_REC.DATADOC, V_REC.CARNETDOC, V_REC.CODPART, V_REC.CODPARTRETAIL, V_REC.VALOARE, V_REC.VALDISC, V_REC.PROTOCOL, V_REC.LISTATCM, CURRENT_TIMESTAMP, V_REC.TIPCASAMARCAT, V_REC.TEXTNEFISCAL, V_REC.FACTURARE);
    END IF;
    PERFORM PKG_CARNETEDOC_SOLVENUMARDOC( V_REC.CARNETDOC, V_REC.NRDOC::varchar);
  END LOOP;

  DELETE FROM RESTNP1 N1
  WHERE
   EXISTS (SELECT CODRESTNP1 FROM TMP_RESTNP1_INITIAL NI WHERE NI.CODRESTNP1 = N1.CODRESTNP1)
   AND  NOT  EXISTS (SELECT CODRESTNP1 FROM TMP_RESTNP1 TN1 WHERE TN1.CODRESTNP1 = N1.CODRESTNP1);

  FOR V_REC IN (SELECT * FROM TMP_RESTNP1 WHERE coalesce(CODRESTNP1, 0) &gt; 0) LOOP
    IF  COALESCE( V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE RESTNP1
      SET
        CODRESTNP  = V_REC.CODRESTNP,
        INDEXLOCAL = V_REC.INDEXLOCAL,
        CODOBIECT  = V_REC.CODOBIECT,
        UMSEC      = V_REC.UMSEC,
        PRET       = V_REC.PRET,
        CANT       = V_REC.CANT,
        DISCOUNT   = V_REC.DISCOUNT,
        PROCTVA     = V_REC.PROCTVA,
        DISCMANUAL  = V_REC.DISCMANUAL
      WHERE
       CODRESTNP1 = V_REC.CODRESTNP1;
    ELSE
      INSERT INTO RESTNP1(CODRESTNP1,CODRESTNP, INDEXLOCAL, CODOBIECT, UMSEC, PRET, CANT, DISCOUNT, PROCTVA, DISCMANUAL)
      VALUES(V_REC.CODRESTNP1,V_REC.CODRESTNP, V_REC.INDEXLOCAL, V_REC.CODOBIECT, V_REC.UMSEC, V_REC.PRET /  V_REC.PARITATE, V_REC.CANT *  V_REC.PARITATE, V_REC.DISCOUNT, V_REC.PROCTVA, V_REC.DISCMANUAL);
    END IF;
  END LOOP;

  DELETE FROM RESTNP2 N2
  WHERE
   EXISTS (SELECT CODRESTNP2 FROM TMP_RESTNP2_INITIAL NI WHERE NI.CODRESTNP2 = N2.CODRESTNP2)
   AND  NOT  EXISTS (SELECT CODRESTNP2 FROM TMP_RESTNP2 TN2 WHERE TN2.CODRESTNP2 = N2.CODRESTNP2);

  FOR V_REC IN (SELECT * FROM TMP_RESTNP2) LOOP
    IF  COALESCE( V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE RESTNP2
      SET
        TIPPLATA = V_REC.TIPPLATA,
        VALOARE  = V_REC.VALOARE,
        DENUMIRE = V_REC.DENUMIRE
      WHERE
       CODRESTNP2 = V_REC.CODRESTNP2;
    ELSE
      INSERT INTO RESTNP2(CODRESTNP2, CODRESTNP, TIPPLATA, VALOARE, DENUMIRE)
      VALUES(V_REC.CODRESTNP2, V_REC.CODRESTNP, V_REC.TIPPLATA, V_REC.VALOARE, V_REC.DENUMIRE);
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_post_ospatari</obj_name>
  <obj_hashval>f0843e4a1965b2a98e1ce2ac9d374346</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_post_ospatari()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  --Florin 25.05.2022 - fixat 54410
  DELETE FROM OSPATARI O
  WHERE EXISTS (SELECT COD FROM TMP_OSPATARI_INI OI WHERE OI.COD = O.COD)
        AND  NOT  EXISTS (SELECT COD FROM TMP_OSPATARI OT  WHERE OT.COD = O.COD);

  FOR V_REC IN (SELECT * FROM TMP_OSPATARI) LOOP
    IF COALESCE( V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE OSPATARI
      SET
        CODPERS       = V_REC.CODPERS,
        PAROLA        = V_REC.PAROLA,
        CODRESTAURANT = V_REC.CODRESTAURANT,
        SUPERVIZOR    = V_REC.SUPERVIZOR,
        VERLISTNP     = V_REC.VERLISTNP
      WHERE
       COD = V_REC.COD;
    ELSE
      INSERT INTO OSPATARI(COD, CODPERS, PAROLA, CODRESTAURANT, SUPERVIZOR, VERLISTNP)
      VALUES(V_REC.COD, V_REC.CODPERS, V_REC.PAROLA, V_REC.CODRESTAURANT, V_REC.SUPERVIZOR, V_REC.VERLISTNP);
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_post_restclase</obj_name>
  <obj_hashval>1dfc2ce32efaaba5691dbc73c8970dac</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_post_restclase(acodrestaurant numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC      RECORD;
  aCODOBIECT numeric := 0;
begin
  DELETE FROM RESTCLASE O
  WHERE           EXISTS (SELECT COD FROM TMP_RESTCLASE_INI OI WHERE OI.COD = O.COD)
        AND  NOT  EXISTS (SELECT COD FROM TMP_RESTCLASE OT     WHERE OT.COD = O.COD);

  FOR V_REC IN (SELECT * FROM TMP_RESTCLASE) LOOP
    IF  COALESCE( V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE RESTCLASE SET CODCLASEA = V_REC.CODCLASEA WHERE COD = V_REC.COD;
    ELSE
      INSERT INTO RESTCLASE(COD, CODCLASEA, CODRESTAURANT)
      VALUES(V_REC.COD, V_REC.CODCLASEA, V_REC.CODRESTAURANT);
    END IF;
  END LOOP;

  DELETE FROM RESTARTINACTIVE RAI
  WHERE
   CODRESTAURANT = aCODRESTAURANT AND  NOT  EXISTS (SELECT CODOBIECT FROM TMP_RESTARTINACTIVE TRAI WHERE COALESCE( INACTIV, 0) = 1 AND  TRAI.CODOBIECT = RAI.CODOBIECT);

  FOR V_REC IN (SELECT * FROM TMP_RESTARTINACTIVE WHERE COALESCE( INACTIV, 0) = 1) LOOP
    BEGIN
      SELECT COUNT( *) INTO aCODOBIECT FROM RESTARTINACTIVE WHERE CODRESTAURANT = aCODRESTAURANT AND  CODOBIECT = V_REC.CODOBIECT;
    EXCEPTION WHEN OTHERS THEN
      aCODOBIECT := 0;
    END;

    IF  aCODOBIECT = 0 THEN
      INSERT INTO RESTARTINACTIVE(COD, CODRESTAURANT, CODOBIECT)
      VALUES(NEXTVAL('SEQ_RESTARTINACTIVE_COD'), aCODRESTAURANT, V_REC.CODOBIECT);
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_post_restobsart</obj_name>
  <obj_hashval>6dc5a05602c1f3d89d6bb72a9a499a94</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_post_restobsart(acodrestaurant numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  V_REC RECORD;

aCODOBIECT numeric := 0;

begin
delete
from
  RESTOBSART O
where
  exists (
  select
    COD
  from
    TMP_RESTOBSART_INI OI
  where
    OI.COD = O.COD )
  and not exists (
  select
    COD
  from
    TMP_RESTOBSART OT
  where
    OT.COD = O.COD );

for V_REC in (
select
  *
from
  TMP_RESTOBSART ) loop if coalesce(V_REC.NEWRECORD, 0) = 0 then
update
  RESTOBSART
set
  OBS = V_REC.OBS
where
  COD = V_REC.COD ;
else
insert
  into
  RESTOBSART ( COD, CODRESTAURANT, CODOBIECT, OBS )
values ( V_REC.COD, V_REC.CODRESTAURANT, V_REC.CODOBIECT, V_REC.OBS );
end if;
end loop;
--&lt;sstcommit&gt;
end;

$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_releaselocknrcmd</obj_name>
  <obj_hashval>a5318eecd0ee2707cbaf2721e2f5f94e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_releaselocknrcmd()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
begin
  DELETE FROM NRCMDRESTLOCK
  WHERE
   USERID = TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_restobsart</obj_name>
  <obj_hashval>0bbe909c5a1f3aadf6024bd4f8edf3d6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_restobsart(acodrestaurant numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCODOBIECT NUMERIC(20) := 0;
  v_rec record;
BEGIN
  --Florin 18.05.2022
  DELETE FROM RESTOBSART O
  WHERE
  EXISTS(SELECT COD FROM TMP_RESTOBSART_INI OI WHERE OI.COD = O.COD)
  AND NOT EXISTS(SELECT COD FROM TMP_RESTOBSART OT WHERE OT.COD = O.COD);

  FOR V_REC IN (SELECT * FROM TMP_RESTOBSART)
  LOOP
    IF COALESCE(V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE RESTOBSART
      SET
       OBS = V_REC.OBS
      WHERE
        COD = V_REC.COD;
    ELSE
      INSERT INTO RESTOBSART(COD, CODRESTAURANT, CODOBIECT, OBS)
      VALUES (V_REC.COD, V_REC.CODRESTAURANT, V_REC.CODOBIECT, V_REC.OBS);
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_scadenepreluate</obj_name>
  <obj_hashval>59bca42aff41804f81579f13be022e9c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_scadenepreluate(agest numeric, adata_start character varying, adata_end character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  dData_Start DATE := TO_DATE(aData_Start, 'DD.MM.YYYY hh24:mi');
  dData_End   DATE := TO_DATE(aData_End,   'DD.MM.YYYY hh24:mi');
  vAn   NUMERIC(4) := EXTRACT(YEAR  FROM dData_End);
  vLuna NUMERIC(2) := EXTRACT(MONTH FROM dData_End);
  vArtServValoric VARCHAR(10000) := Coalesce(fnc_GetValConstanta('ArtServValoric',  vAn, vLuna),'-1');
BEGIN
  --Florin 28.11.2023 - sinc. Oracle
  --Florin 16.03.2023 - sinc. Oracle (09.03.2023)
  DELETE FROM tmp_manevra3;
  IF vArtServValoric &lt;&gt; '-1' THEN
    EXECUTE 'INSERT INTO tmp_manevra3(CODUNIC) SELECT DISTINCT CodObiect FROM NARTOBJ WHERE CodObiect IN ('||vArtServValoric||')';
  END IF;

  DELETE FROM TMP_LIVR_LA_DATA;
  -- SCAD DIN STOC INITIAL VANZARI NEPRELUATE ANTERIOARE DATAEI

  INSERT INTO TMP_LIVR_LA_DATA(CODOBIECT, CANTNIR)
  SELECT C1.CODOBIECT, SUM(CASE WHEN T.CODUNIC IS NULL THEN C1.CANT ELSE C1.CANT * C1.PRET END)
  FROM EMULARE E
    INNER JOIN RESTNP       NP ON NP.CODRESTNP  = E.CODRESTNP
    INNER JOIN RESTCMD1     C1 ON C1.CODRESTCMD = NP.CODRESTCMD
    INNER JOIN NARTOBJ      O  ON O.CODOBIECT   = C1.CODOBIECT
    LEFT  JOIN TMP_MANEVRA3 T  ON T.CODUNIC     = C1.CODOBIECT
  WHERE Coalesce(E.DATACREARE, TO_DATE('01.01.2000', 'DD.MM.YYYY')) &lt; dData_Start
    AND Coalesce(E.PRELUAT, 0) = 0
    AND C1.CODGEST = aGEST
  GROUP BY C1.CODOBIECT;

--  MERGE INTO TMP_BALANTA_STOC SD
--  USING TMP_LIVR_LA_DATA N
--  ON (N.CODOBIECT = SD.CODOBIECT)
--  WHEN NOT MATCHED THEN INSERT (CODOBIECT, STOCINITIAL, INTRARI, IESIRI) VALUES (N.CODOBIECT, -N.CANTNIR, 0, 0)
--  WHEN     MATCHED THEN UPDATE SET SD.STOCINITIAL = NVL(SD.STOCINITIAL, 0) -  N.CANTNIR;

  DELETE FROM TMP_LIVR_IN_INTERVALUL;
  -- ACTUALIZE VANZARI NEPRELUATE IN INTERVALUL ANALIZAT

  INSERT INTO TMP_LIVR_IN_INTERVALUL(CODOBIECT, CANTNIR)
  SELECT C1.CODOBIECT, SUM(CASE WHEN T.CODUNIC IS NULL THEN C1.CANT ELSE C1.CANT * C1.PRET END)
  FROM EMULARE E
    INNER JOIN RESTNP       NP ON NP.CODRESTNP  = E.CODRESTNP
    INNER JOIN RESTCMD1     C1 ON C1.CODRESTCMD = NP.CODRESTCMD
    INNER JOIN NARTOBJ      O  ON O.CODOBIECT   = C1.CODOBIECT
    LEFT  JOIN TMP_MANEVRA3 T  ON T.CODUNIC     = C1.CODOBIECT
  WHERE Coalesce(E.DATACREARE, TO_DATE('01.01.2000', 'DD.MM.YYYY')) &gt;=  dData_Start
    AND Coalesce(E.DATACREARE, TO_DATE('01.01.2000', 'DD.MM.YYYY')) &lt;= dData_End
    AND Coalesce(E.PRELUAT, 0) = 0
    AND C1.CODGEST = aGEST
  GROUP BY C1.CODOBIECT;

--  MERGE INTO TMP_BALANTA_STOC SD USING TMP_LIVR_IN_INTERVALUL N ON (N.CODOBIECT = SD.CODOBIECT)
--  WHEN NOT MATCHED THEN INSERT (CODOBIECT, STOCINITIAL, INTRARI, IESIRI, VANDUTE) VALUES (N.CODOBIECT, 0, 0, N.CANTNIR, N.CANTNIR)
--  WHEN     MATCHED THEN UPDATE SET SD.IESIRI = Coalesce(SD.IESIRI, 0) + N.CANTNIR, SD.VANDUTE = Coalesce(SD.VANDUTE, 0) + N.CANTNIR;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_scadeprotocol</obj_name>
  <obj_hashval>6e266cc9b030fedb8ba356af9138cbf9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_scadeprotocol(agest numeric, adata_start character varying, adata_end character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  N RECORD;
BEGIN
  --Florin 28.11.2023 - sinc. Oracle
  DELETE FROM TMP_LIVR_LA_DATA;
  INSERT INTO TMP_LIVR_LA_DATA(CODOBIECT, CANTNIR)
  SELECT C1.CODOBIECT, SUM( C1.CANT) AS CANT
  FROM RESTNP NP, RESTCMD C, RESTCMD1 C1
  WHERE COALESCE( NP.DATACREARE, to_timestamp( '01.01.2000', 'DD.MM.YYYY')) &lt; to_timestamp( aData_Start, 'DD.MM.YYYY hh24:mi') AND
        COALESCE( NP.PROTOCOL, 0) = 1 AND
        NP.CODRESTCMD = C.CODRESTCMD  AND
        C1.CODRESTCMD = NP.CODRESTCMD AND
        COALESCE( C.DIMINUAT, 0) = 0  AND
        C1.CODGEST = aGEST
  GROUP BY C1.CODOBIECT;

  FOR N IN ( SELECT * FROM TMP_LIVR_LA_DATA N) LOOP
    UPDATE  TMP_BALANTA_STOC SD SET STOCINITIAL = COALESCE( SD.STOCINITIAL, 0) - N.CANTNIR WHERE N.CODOBIECT = SD.CODOBIECT;
    IF NOT FOUND THEN
      INSERT INTO TMP_BALANTA_STOC(CODOBIECT, STOCINITIAL, INTRARI, IESIRI) VALUES (N.CODOBIECT, -N.CANTNIR, 0, 0);
    END IF;
  END LOOP;

  DELETE FROM TMP_LIVR_IN_INTERVALUL;
  INSERT INTO TMP_LIVR_IN_INTERVALUL(CODOBIECT, CANTNIR)
  SELECT C1.CODOBIECT, SUM( C1.CANT) AS CANT
  FROM RESTNP NP, RESTCMD C, RESTCMD1 C1
  WHERE COALESCE( NP.DATACREARE, to_timestamp( '01.01.2000', 'DD.MM.YYYY')) &gt;=  to_timestamp( aData_Start, 'DD.MM.YYYY hh24:mi') AND
        COALESCE( NP.DATACREARE, to_timestamp( '01.01.2000', 'DD.MM.YYYY')) &lt;= to_timestamp( aData_END  , 'DD.MM.YYYY hh24:mi') AND
        COALESCE( NP.PROTOCOL, 0) = 1 AND
        NP.CODRESTCMD = C.CODRESTCMD  AND
        C1.CODRESTCMD = NP.CODRESTCMD AND
        COALESCE( C.DIMINUAT, 0) = 0  AND
        C1.CODGEST = aGEST
  GROUP BY C1.CODOBIECT;

  FOR N IN ( SELECT * FROM TMP_LIVR_IN_INTERVALUL N) LOOP
    UPDATE  TMP_BALANTA_STOC SD
     SET
       IESIRI  = COALESCE( SD.IESIRI , 0) + N.CANTNIR,
       VANDUTE = COALESCE( SD.VANDUTE, 0) + N.CANTNIR
    WHERE
     N.CODOBIECT = SD.CODOBIECT;

    IF NOT FOUND THEN
      INSERT INTO TMP_BALANTA_STOC(CODOBIECT, STOCINITIAL, INTRARI, IESIRI, VANDUTE) VALUES (N.CODOBIECT, 0, 0, N.CANTNIR, N.CANTNIR);
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_unlock_mese_restaurant</obj_name>
  <obj_hashval>3551c639459bf57ad0c264d414e25faa</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_unlock_mese_restaurant(acodrestaurant numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
begin
  UPDATE MESE M
  SET
    BLOCATA    = 0,
    USERID     = 0,
    CODOSPATAR = 0
  WHERE
   USERID = TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999') AND
   (SELECT S.CODRESTAURANT FROM SALI S WHERE  S.CODSALA = M.CODSALA) = aCODRESTAURANT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_unlockmasa</obj_name>
  <obj_hashval>ddd0419217f94f6c665aa600b6a22a76</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_unlockmasa(acodmasa numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
begin
  UPDATE MESE
  SET
    BLOCATA    = 0,
    USERID     = 0,
    CODOSPATAR = 0
  WHERE CODMASA = aCODMASA;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restobiecte_sp_gotorecord</obj_name>
  <obj_hashval>b9df267af0d146b7e1f7b5bd4b0d86f7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restobiecte_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_RESTOBIECT(COD, DENUMIRE, CODSALA, X, Y, WIDTH, HEIGHT, COLOR, TEXTAFISARE, FORMA, POZA, IS3D, NIVEL)
  SELECT COD, DENUMIRE, CODSALA, X, Y, WIDTH, HEIGHT, COLOR, TEXTAFISARE, FORMA, POZA, IS3D, NIVEL FROM RESTOBIECT WHERE COD = RecId;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restobiecte_sp_postrecords</obj_name>
  <obj_hashval>e3060b6b369c34a5e541091a66b904a3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restobiecte_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  IF  Operation = 0 THEN
    SELECT COD INTO RecId FROM TMP_RESTOBIECT;

    UPDATE RESTOBIECT
    SET
    (DENUMIRE, CODSALA, X, Y, WIDTH, HEIGHT, COLOR, TEXTAFISARE, FORMA, POZA, IS3D, NIVEL)
    =
    (SELECT DENUMIRE, CODSALA, X, Y, WIDTH, HEIGHT, COLOR, TEXTAFISARE, FORMA, POZA, IS3D, NIVEL FROM TMP_RESTOBIECT)
    WHERE COD = RECID;
  ELSE
    SELECT NEXTVAL('SEQ_RESTOBIECTE_COD') INTO RECID;

    INSERT INTO RESTOBIECT(COD, DENUMIRE, CODSALA, X, Y, WIDTH, HEIGHT, COLOR, TEXTAFISARE, FORMA, POZA, IS3D, NIVEL)
    SELECT RECID, DENUMIRE, CODSALA, X, Y, WIDTH, HEIGHT, COLOR, TEXTAFISARE, FORMA, POZA, IS3D, NIVEL FROM TMP_RESTOBIECT;
  END IF;

  PERFORM NotifyModif( Operation, RecId, 'RESTOBIECT');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_returo_checknewdata</obj_name>
  <obj_hashval>643cce8e22b9caa0dbb35ebd8f466e5b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_returo_checknewdata()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  v_rec record;
BEGIN
  --Florin 17.06.2024 - sinc. Oracle
  --Florin 21.11.2023
  FOR V_REC in (SELECT T.*, R.SESSIONID AS OrigSessionID FROM TMP_RETURO T LEFT JOIN RETURO R ON T.SESSIONID = R.SESSIONID)
  LOOP
    IF V_rec.OrigSessionID IS NULL THEN
      INSERT INTO RETURO(CODRETURO,
                         SESSIONID,
                         STARTEDAT,
                         REFUND,
                         VOUCHERBARCODE,
                         RVM_SERIALNUMBER,
                         RVM_TYPE,
                         LOCATION_CUSTOMERID,
                         LOCATION_NAME,
                         UPLOAD_DATE
                         )
                         VALUES(Nextval('SEQ_RETURO_codreturo'),
                                v_rec.SESSIONID,
                                v_rec.STARTEDAT,
                                v_rec.REFUND,
                                v_rec.VOUCHERBARCODE,
                                v_rec.RVM_SERIALNUMBER,
                                v_rec.RVM_TYPE,
                                v_rec.LOCATION_CUSTOMERID,
                                v_rec.LOCATION_NAME,
                                current_date
                               );


    END IF;
  END LOOP;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_returo_updateusedvouchers</obj_name>
  <obj_hashval>88f153d6efec597597a0b995217b6139</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_returo_updateusedvouchers()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  v_rec record;
  aCODRETURO  NUMERIC(20);
BEGIN
  --Florin 06.01.2024 - fixat 64378
  --Florin 17.06.2024 - sinc. Oracle
  --Florin 21.11.2023
  FOR V_REC IN (SELECT * FROM TMP_RETURO WHERE CODRETURO &gt; 0)
  LOOP
    UPDATE RETURO
    SET
      IS_USED = 1,
      USED_DATE = current_timestamp
    WHERE
      CODRETURO = V_rec.Codreturo;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_RETURO WHERE CODRETURO &lt; 0)
  LOOP
    SELECT MIN(CODRETURO) INTO aCODRETURO
    FROM
      RETURO
    WHERE
      VOUCHERBARCODE = V_rec.VOUCHERBARCODE;

    IF COALESCE(aCODRETURO, 0) &gt; 0 THEN
      UPDATE RETURO
      SET
        IS_USED = 1,
        USED_DATE = current_timestamp
      WHERE
        CODRETURO = aCodReturo;
    ELSE
      INSERT INTO RETURO(CODRETURO, REFUND, VOUCHERBARCODE, IS_USED, USED_DATE)
      VALUES(NEXTVAL('SEQ_RETURO_CODRETURO'), v_rec.refund, V_rec.VOUCHERBARCODE, 1, current_timestamp);
    END IF;
  END LOOP;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rezervari_actualizeazanecesar</obj_name>
  <obj_hashval>424326603ca1b7ef6af7d5224a9f9199</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rezervari_actualizeazanecesar(acodcomanda1 numeric, acodproiectnod numeric, aparitate numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REZ RECORD;
begin
  FOR v_REZ IN (SELECT * FROM TMP_REZ_ProiectNod WHERE CodComanda1 = aCodComanda1 and  NodOriginal = aCodProiectNod) LOOP
    UPDATE TMP_REZ_ProiectNod SET Necesar  = Round( v_REZ.Cant * aParitate, 7) WHERE CodProiectNod = v_REZ.codproiectnod;
    UPDATE TMP_REZ_REZ        SET Rezolvat = Round( Rezolvat + v_REZ.Cant - v_REZ.Cant * aParitate, 7) WHERE CodObiect = v_REZ.codObiect and  CodComanda1 = aCodComanda1;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rezervari_adaugarezervari</obj_name>
  <obj_hashval>e04c6ab2abf7458eed8ebce64830b24d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rezervari_adaugarezervari(INOUT wme_result numeric, INOUT acodcomanda1 numeric, INOUT acodobiect numeric, INOUT acodgest numeric, INOUT acodioart numeric, INOUT acant numeric, INOUT aumsec numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_STOC    RECORD;
  aCantIni  double precision;
  aRest     double precision;
  STOC_Rest double precision;
BEGIN
  --Florin 09.08.2021 - fixat 51003
  --Florin 09.02.2021 - prefix pentru bagarezervare
  IF  aCant &lt;= 0 THEN
    WME_Result :=  0;
    RETURN;
  END IF;

  aCantIni := aCant;
  aRest    := aCant;

  FOR v_STOC IN (SELECT * FROM TMP_REZ_STOC WHERE Rest &gt; 0 and  CodObiect = aCodObiect and  CodGest = aCodGest and  CodIoart = aCodIOart) LOOP
    SELECT Rest INTO STOC_Rest FROM TMP_REZ_STOC WHERE CodNIRStoc = v_Stoc.CodNIRSTOC and  COALESCE( CodNIRSer, 0) = COALESCE( v_STOC.CodNIRSer, 0);

    IF  STOC_Rest &gt; aRest THEN
      UPDATE TMP_REZ_STOC SET Rest = Rest - aRest WHERE CodNIRStoc = v_Stoc.CodNIRSTOC and  COALESCE( CodNIRSer, 0) = COALESCE( v_STOC.CodNIRSer, 0);
      PERFORM PKG_REZERVARI_BAGAREZERVARE( aCodComanda1, 0, v_STOC.CodNirStoc, COALESCE( v_STOC.CodNirSer, 0), aRest::numeric, aUMSec, aCodObiect, 0);
      aRest := 0;
    ELSE
      aRest := aRest - STOC_Rest;
      UPDATE TMP_REZ_STOC SET Rest = 0 WHERE CodNIRStoc = v_Stoc.CodNIRSTOC and  COALESCE( CodNIRSer, 0) = COALESCE( v_STOC.CodNIRSer, 0);
      PERFORM PKG_REZERVARI_BAGAREZERVARE( aCodComanda1, 0, v_STOC.CodNirStoc, COALESCE( v_STOC.CodNirSer, 0), STOC_Rest::numeric, aUMSec, aCodObiect, 0);
    END IF;

    IF  aRest &lt;= 0 THEN
      WME_Result :=  aCantIni;
      RETURN;
    END IF;
  END LOOP;

  WME_Result :=  aCantIni - aRest;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rezervari_bagarezervare</obj_name>
  <obj_hashval>e2ec23674d418b4746d209a849f5a559</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rezervari_bagarezervare(acodcomanda1 numeric, acodcmdprodmat numeric, acodnirstoc numeric, acodnirser numeric, acant numeric, aumsec numeric, acodobiect numeric, acodcomanda1f numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vCodRezervatS numeric;
  aNr           numeric;
  aNr1          numeric;
  vCant         double precision;
begin
  SELECT count( *)
  INTO aNr
  FROM REZERVATS
  WHERE CodComanda1 = aCodComanda1 and  COALESCE( CodNirStoc, 0) = aCodNirStoc and  COALESCE( CodNirSer, 0) = aCodNirSer and  COALESCE( CodObiect, 0) = aCodObiect and  COALESCE( CodComanda1f, 0) = aCodComanda1f;

  IF  aNr = 1 THEN
    UPDATE rezervats
    SET
    RezervatIni = RezervatIni + aCant,
    rest = rest + aCant
    WHERE
     CodComanda1 = aCodComanda1 and  COALESCE( CodNirStoc, 0) = aCodNirStoc and  COALESCE( CodNirSer, 0) = aCodNirSer and  COALESCE( CodObiect, 0) = aCodObiect and  COALESCE( CodComanda1f, 0) = aCodComanda1f;
  ELSE
    IF  aCodNirStoc = 0 and  aCodNirser = 0 and  aCodComanda1f &gt; 0 THEN
      SELECT count( *)
      INTO aNr1
      FROM REZERVATS
      WHERE CodComanda1 = aCodComanda1 and  COALESCE( CodNirStoc, 0) = 0 and  COALESCE( CodNirSer, 0) = 0 and  COALESCE( CodObiect, 0) = aCodObiect and  COALESCE( CodComanda1f, 0) = 0;

      IF  aNr1 = 1 THEN
        SELECT rest
        INTO vCant
        FROM REZERVATS
        WHERE CodComanda1 = aCodComanda1 and  COALESCE( CodNirStoc, 0) = 0 and  COALESCE( CodNirSer, 0) = 0 and  COALESCE( CodObiect, 0) = aCodObiect and  COALESCE( CodComanda1f, 0) = 0 and  rownum = 1;

        IF  vCant &gt; aCant THEN
          UPDATE rezervats
          SET
          RezervatIni = RezervatIni - aCant,
          rest = rest - aCant
          WHERE CodComanda1 = aCodComanda1 and  COALESCE( CodNirStoc, 0) = 0 and  COALESCE( CodNirSer, 0) = 0 and  COALESCE( CodObiect, 0) = aCodObiect and  COALESCE( CodComanda1f, 0) = 0;

          SELECT NEXTVAL('SEQ_REZERVATS_CODREZERVATS') INTO vCodRezervatS;

          INSERT INTO rezervats(codrezervats, codnirstoc, codnirser, RezervatIni, rest, codcomanda1, codcmdprodmat, UMSec, CodObiect, CodComanda1f)
          VALUES(vCodRezervatS, aCodNirStoc, aCodNirSer, aCant, aCant, aCodComanda1, aCodCmdProdMat, aUMSec, aCodObiect, aCodComanda1f);
        ELSE
          IF  vCant = aCant THEN
            UPDATE rezervats
            SET
            RezervatIni = 0,
            rest = 0
            WHERE CodComanda1 = aCodComanda1 and  COALESCE( CodNirStoc, 0) = 0 and  COALESCE( CodNirSer, 0) = 0 and  COALESCE( CodObiect, 0) = aCodObiect and  COALESCE( CodComanda1f, 0) = 0;

            SELECT NEXTVAL('SEQ_REZERVATS_CODREZERVATS') INTO vCodRezervatS;

            INSERT INTO rezervats(codrezervats, codnirstoc, codnirser, RezervatIni, rest, codcomanda1, codcmdprodmat, UMSec, CodObiect, CodComanda1f)
            VALUES(vCodRezervatS, aCodNirStoc, aCodNirSer, aCant, aCant, aCodComanda1, aCodCmdProdMat, aUMSec, aCodObiect, aCodComanda1f);
          END IF;
        END IF;
      ELSE
        IF  aNr1 = 0 THEN
          SELECT NEXTVAL('SEQ_REZERVATS_CODREZERVATS') INTO vCodRezervatS;

          INSERT INTO rezervats(codrezervats, codnirstoc, codnirser, RezervatIni, rest, codcomanda1, codcmdprodmat, UMSec, CodObiect, CodComanda1f)
          VALUES(vCodRezervatS, aCodNirStoc, aCodNirSer, aCant, aCant, aCodComanda1, aCodCmdProdMat, aUMSec, aCodObiect, aCodComanda1f);
        END IF;
      END IF;
    ELSE
      SELECT NEXTVAL('SEQ_REZERVATS_CODREZERVATS') INTO vCodRezervatS;

      INSERT INTO rezervats(codrezervats, codnirstoc, codnirser, RezervatIni, rest, codcomanda1, codcmdprodmat, UMSec, CodObiect, CodComanda1f)
      VALUES(vCodRezervatS, aCodNirStoc, aCodNirSer, aCant, aCant, aCodComanda1, aCodCmdProdMat, aUMSec, aCodObiect, aCodComanda1f);
    END IF;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rezervari_cerere_achizitie</obj_name>
  <obj_hashval>d93592a49d39b796ec51fedc69ce1f81</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rezervari_cerere_achizitie(acodcomanda1 numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_COM          RECORD;
  V_NOD          RECORD;
  V_REZ          RECORD;
  v_rec          record;
  REZ_Rezervat   double precision;
  REZ_TOTAL      double precision;
  CATE_VREAU     double precision;
  aParitate      double precision;
  NOD_Rezervat   double precision;
  NOD_Rezolvat   double precision;
  NOD_Necesar    double precision;
  NOD_RezFurn    double precision;
  NOD_RezCmdFurn double precision;
  aCantIni       double precision;
  aRest          double precision;
  STOC_Rest      double precision;
  aCod           numeric;
  REZ_CodGest    numeric;
  REZ_CodIOArt   numeric;
  REZ_UMSec      numeric;
  Rezervat       numeric;
  Rezolv       numeric;
  Necesar        numeric;
  RezF        numeric;
  RezCmdF     numeric;
BEGIN
  --Florin 09.08.2021 - fixat 51003
  --Adina 09.07.2021 - sinc.Oracle din 08.07.2021
  --Adina 01.07.2021 - sinc.Oracle din 30.06.2021
  --Florin 22.12.20202 - fixat #41827

  -- initializari
  for v_rec in (select * from TMP_REZ_REZ where aCodComanda1 = 0 or Codcomanda1 = aCodcomanda1) loop
    UPDATE TMP_REZ_REZ SET RezFurn = 0 WHERE codcomanda1 = v_rec.codcomanda1;
    DELETE FROM rezervats WHERE codcomanda1 = v_rec.codcomanda1 and codobiect = v_rec.codobiect and coalesce(codnirstoc,0) = 0 and coalesce(codcomanda1f,0) = 0;
  end loop;

  for v_COM in (select CodComanda1 from TMP_REZ_CCOM1 where aCodcomanda1 = 0 or CodComanda1 = aCodComanda1) loop
  -- pentru fiecare linie de comanda
    for v_rez in (select r.* from TMP_REZ_REZ r where  r.CodComanda1 = v_COM.Codcomanda1 and r.Idx = 3) loop
      Rezervat    := v_rez.rez;
      Necesar     := v_rez.necesar;
      Rezolv    := v_rez.rezolvat;
      RezCmdF  := v_rez.rezcmdfurn;
      RezF  := v_rez.RezFurn;
      CATE_VREAU := coalesce(Necesar,0)  - coalesce(Rezolv,0) - coalesce(Rezervat,0) - coalesce(RezF,0) - coalesce(RezCmdF,0);
      if CATE_VREAU &gt; 0 then
        PERFORM PKG_REZERVARI_BAGAREZERVARE(v_COM.CodComanda1, 0::numeric, 0::numeric, 0::numeric, CATE_VREAU::numeric, v_rez.UMSec, v_rez.CodObiect, 0::numeric);

        update TMP_REZ_REZ set RezFurnIni  = RezFurnIni + CATE_VREAU,
                               RestCom     = NecesarIni -Rezolv-RezIni-RezCmdF-RezFurnIni - CATE_VREAU,
                               RezFurn     = RezF + CATE_VREAU
        where CodComanda1 = v_rez.CodComanda1 and CodObiect = v_rez.CodObiect;

        update TMP_REZ_REZ set RestCom     = NecesarIni -Rezolv-RezIni-RezCmdF-RezFurnIni - CATE_VREAU
        where CodComanda1 = v_rez.CodComanda1 and CodObiect = v_rez.CodObiect;
      end if;
    end loop;
  end loop;

/*  -- varianta pana la 01.07.2021
  PERFORM PKG_REZERVARI_GET_TMP_REZ_STOC( aCodComanda1);

  UPDATE TMP_REZ_REZ SET RezFurn = 0 WHERE aCodComanda1 = 0 or  Codcomanda1 = aCodcomanda1;

  FOR v_COM IN (SELECT CodComanda1 FROM TMP_REZ_CCOM1 WHERE aCodcomanda1 = 0 or  CodComanda1 = aCodComanda1) LOOP
    FOR v_NOD IN (SELECT p.*, r.rezcmdfurn
                  FROM TMP_REZ_ProiectNod p, TMP_REZ_REZ r
                  WHERE p.CodComanda1 = v_COM.Codcomanda1 and  r.CodComanda1 = p.CodComanda1 and  r.CodObiect = p.CodObiect and  r.Idx = 3
                 )
    LOOP
      SELECT Rezervat, RezFurn, Necesar, Rezolvat, v_nod.rezcmdfurn
      INTO NOD_Rezervat, NOD_RezFurn, NOD_Necesar, NOD_Rezolvat, NOD_RezCmdFurn
      FROM TMP_REZ_ProiectNod
      WHERE CodComanda1 = v_COM.CodComanda1 and  CodProiectNod = v_NOD.CodProiectNod;

      CATE_VREAU := NOD_Necesar - NOD_Rezolvat - NOD_Rezervat - NOD_RezFurn - NOD_RezCmdFurn;
      IF  CATE_VREAU &gt; 0 THEN
        SELECT UMSec INTO REZ_UMSec FROM TMP_REZ_REZ WHERE CodComanda1 = v_COM.CodComanda1 and  CodObiect = v_NOD.CodObiect;
        PERFORM PKG_REZERVARI_BAGAREZERVARE( v_COM.CodComanda1, 0::NUMERIC, 0::NUMERIC, 0::NUMERIC, CATE_VREAU::NUMERIC, REZ_UMSec, v_NOD.CodObiect, 0::NUMERIC);

        UPDATE TMP_REZ_REZ
        SET
        RezFurnIni = RezFurnIni + CATE_VREAU,
        RestCom    = NecesarIni - Rezolvat - RezIni - RezCmdFurn - RezFurnIni - CATE_VREAU
        WHERE
         CodComanda1 = v_NOD.CodComanda1 and  CodObiect = v_NOD.CodObiect;

        UPDATE TMP_REZ_ProiectNod
        SET
        RezFurn = RezFurn + CATE_VREAU
        WHERE
         CodComanda1 = v_COM.CodComanda1 and  CodProiectNod = v_NOD.CodProiectNod;
      END IF;
    END LOOP;
  END LOOP;
*/
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rezervari_get_tmp_rez_ccom1</obj_name>
  <obj_hashval>dbd9db0e020d06006e59b75f073255f1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rezervari_get_tmp_rez_ccom1()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_COM RECORD;
  V_REC RECORD;
  Cate numeric;
begin
  --Bogdan 15.10.2020
  DELETE FROM TMP_REZ_CCOM1;

  INSERT INTO TMP_REZ_CCOM1 (CODCOMANDA1,
      DENUMIRE,
      TERMEN,
      CODOBIECT,
      UM,
      RESTACCEPTAT,
      CANTACCEPTAT,
      INDEXLOCAL,
      PARITATE,
      CODPROIECT,
      CODRETETA,
      TIPCOMANDA)
  (SELECT codcomanda1,
        Denumire,
        Termen,
        codobiect,
        UM,
        Restacceptat,
        Cantacceptat,
        IndexLocal,
        Paritate,
        CodProiect,
        CodReteta,
        COALESCE (DISPLIVRARE, 0) TIPCOMANDA
   FROM (SELECT c1.codcomanda1,
            c1.termen,
            obj.denumire,
            c1.codobiect,
            umsec.paritate,
            umsec.den_um1 UM,
            c1.restacceptat,
            c1.IndexLocal,
            c1.cantacceptat,
            c1.CodProiect,
            c1.CodReteta,
            C.DISPLIVRARE
         FROM comanda1                          c1
            INNER JOIN tmp_manevra_liniicomenzi tmp   ON c1.codcomanda1 = tmp.codcomanda1
            LEFT JOIN nartobj                   obj   ON obj.codobiect  = C1.codobiect
            LEFT JOIN nart                      art   ON obj.codarticol = art.codarticol
            LEFT JOIN num1                      umsec ON c1.umsec       = umsec.codum1
            LEFT JOIN Comanda                   C     ON C.codComanda   = C1.CodComanda
         WHERE
            c1.codproiect &gt; 0 and c1.culansare = 1
        ) A_PG
  );

  FOR v_COM IN (SELECT CodProiect FROM TMP_REZ_CCOM1) LOOP
    SELECT Count(*) INTO Cate FROM ProiectNod WHERE CodProiect = v_COM.CodProiect and COALESCE (Nivel, 0) = 1;

    IF Cate = 0 THEN
      FOR v_Rec IN (
        with recursive recProc as (
              select p.codproiectnod, 0 as level
              from proiectnod p
              where nodoriginal = 0
              and p.codproiect = v_COM.Codproiect
              union all
              select p2.codproiectnod, rp.level+1
              from proiectnod p2
              join recProc rp on rp.codproiectnod = p2.nodoriginal
              where p2.codproiect = v_COM.Codproiect
            )
        select rPr.codproiectnod, rPr.level from recProc rPr
      )
      LOOP
        UPDATE proiectnod SET nivel = v_rec.nivel WHERE codproiectnod = v_Rec.codproiectnod;
      END LOOP;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rezervari_get_tmp_rez_proiectnod</obj_name>
  <obj_hashval>6805159455b07435225d3b6f48381396</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rezervari_get_tmp_rez_proiectnod()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 29.11.2022 - sinc. Oracle
  --Adina 25.06.2021 - sinc.Oracle
  DELETE FROM TMP_REZ_PROIECTNOD;
  INSERT INTO TMP_REZ_PROIECTNOD(CODCOMANDA1, CODOBIECT, POZITIE, CODPROIECTNOD, NODORIGINAL, NIVEL, INDEXPARINTE, CANT, NECESAR, CODRETETA, REZERVAT, REZFURN, REZOLVAT, ORDINE)
  (SELECT *
   FROM (SELECT c1.codcomanda1, CASE WHEN  COALESCE( ne.codobiect, 0)=0 THEN pn.CodObiect ELSE  ne.CodObiect END  CODOBIECT, pn.pozitie, pn.codproiectnod,
                pn.nodoriginal, PN.Nivel, Substr( PN.INDEXPARINTE, 4, 47),
                1 / PN0.CANT * PN.CANT * CASE WHEN  COALESCE( ne.codobiect, 0)=0 THEN 1 ELSE  ne.paritate END  CANT,
                CASE WHEN  pn.tip = 5 THEN pn.cant ELSE c1.RestAcceptat * umsec.paritate / PN0.CANT * PN.CANT END
                 * CASE WHEN  COALESCE( ne.codobiect, 0)=0 THEN 1 ELSE  ne.paritate END  NECESAR,
                pn.codreteta, 0 REZERVAT, 0 REZFURN, 0 REZOLVAT, COALESCE(o.Ordine*10000 + pn.Pozitie,0)
        FROM comanda1 c1
        INNER JOIN tmp_manevra_liniicomenzi tmp   ON  c1.codcomanda1  = tmp.codcomanda1
        LEFT  JOIN num1                     umsec ON  c1.umsec        = umsec.codum1
        LEFT  JOIN proiectnod               pn    ON  c1.codproiect   = pn.codproiect
        LEFT  JOIN proiectnod               pn0   ON  c1.codproiect   = pn0.codproiect and  COALESCE( pn0.nodoriginal, 0) = 0
        LEFT  JOIN (select
                      distinct px.Nivel,
                      (Select Max(pxx.Nivel) from proiectnod pxx WHERE pxx.CodProiect = px.codproiect) - px.Nivel as Ordine,
                      px.codproiect
                    from proiectnod px Group by px.Nivel,px.codproiect
                   )                        O     ON  O.Nivel         = pn.Nivel and pn.codproiect = O.CodProiect
        LEFT  JOIN prodcomp                 pc    ON  pn.codreteta    = pc.codprodcomp
        LEFT  JOIN nartobj                  obj   ON  pn.codobiect    = obj.codobiect
        LEFT  JOIN nart                     art   ON  obj.codarticol  = art.codarticol
        LEFT  JOIN num                      um    ON  art.um          = um.codum
        left  join num1                     um1   on um1.codum = art.um and um1.secundara = 0
        LEFT  JOIN nodechiv                 ne    ON  ne.codcomanda1  = c1.codcomanda1 and  ne.codproiectnod = pn.codproiectnod
        LEFT  JOIN nartobj                  obje  ON  ne.codobiect    = obje.codobiect
        LEFT  JOIN nart                     arte  ON  obje.codarticol = arte.codarticol
        LEFT  JOIN num                      ume   ON  arte.um         = ume.codum
        WHERE c1.codproiect &gt; 0 and  c1.culansare = 1
       ) A_PG
   WHERE cant &lt;&gt; 0
  );
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rezervari_get_tmp_rez_stoc</obj_name>
  <obj_hashval>b57514d457e106aab3a55ad72ea8f6d1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rezervari_get_tmp_rez_stoc(acodcomanda1 numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  sql varchar;
begin
  --Bogdan 15.10.2020
  DELETE FROM TMP_REZ_STOC;

  sql := 'INSERT INTO TMP_REZ_STOC (CODNIRSER,
          CODNIRSTOC,
          CODOBIECT,
          STOC,
          CODGEST,
          CODIOART,
          REST)
         (SELECT V.CODNIRSER,
            V.CODNIRSTOC,
            V.CODOBIECT,
            V.STOC,
            V.CODGEST,
            V.CODIOART,
            V.stoc REST
          FROM '|| pkg_rezervari_get_V_STOC_PT_REZERVARI() ||' v
          WHERE
            ( SELECT Count(*)
              FROM TMP_REZ_REZ
              WHERE
                ('||coalesce(aCodComanda1,0)::varchar||' = 0 or CodComanda1 = '||coalesce(aCodComanda1,0)::varchar||')
                AND CodObiect = v.CODObiect
                AND CodGest = v.CODGEST
                AND CODIOART = v.CODIOART)
            &gt; 0)';
   execute sql;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rezervari_get_v_stoc_pt_rezervari</obj_name>
  <obj_hashval>3ed53d298dea47d835ebc7019587a229</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rezervari_get_v_stoc_pt_rezervari()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
declare
  sql varchar;
begin
  --Bogdan 15.10.2020
  sql := '(
      SELECT NSE.CODNIRSER,
        NS.CODNIRSTOC,
        NUM.DEN_UM,
        NS.CODOBIECT,
        (CASE WHEN NS.TIPSERIE &gt; 0 THEN ROUND ( (NSE.REST) ::numeric, 10) ELSE ROUND ( (NS.REST) ::numeric, 10) END)
        - COALESCE (REZ.Cant, 0) - COALESCE (Blocat.Cant, 0) AS STOC,
        NIRCURENT.DATANIR                                    AS INTRATLA,
        L.DENUMIRE                                           AS LOCATIE,
        CASE
          WHEN NS.TIPDOCACHIZ = 7 THEN (SELECT DEN_GEST FROM NGEST WHERE CODGEST = NS.CODGESTPROD)
          ELSE (SELECT DEN_PART FROM NPART WHERE CODPART = NS.FURN)
        END AS FURNIZOR,
        coalesce (CASE WHEN NS.TIPDOCACHIZ = 7 THEN (SELECT DEN_GEST FROM NGEST WHERE CODGEST = NS.CODGESTPROD)
                       ELSE (SELECT DEN_PART FROM NPART WHERE CODPART = NS.FURN)
                  END ,'''') || '' '' || coalesce (To_Char (NIRCURENT.DATANIR,''dd.mm.yyyy'') ,'''') AS NIRSTOC,
        G.Den_Gest,
        G.CodGest,
        IOA.CODIOART,
        IOA.DEN_IOART
      FROM NIRSTOC         NS
        INNER JOIN NARTOBJ OBJ ON NS.CODOBIECT   = OBJ.CODOBIECT
        INNER JOIN NART    ART ON OBJ.CODARTICOL = ART.CODARTICOL
        INNER JOIN NUM         ON ART.UM         = NUM.CODUM
        LEFT JOIN NIRSER NSE   ON NSE.CODNIRSTOC = NS.CODNIRSTOC
        LEFT JOIN (SELECT codnirstoc, COALESCE (codnirser, 0) CODNIRSER, sum (rest) CANT
                   FROM rezervats
                   GROUP BY codnirstoc, COALESCE (codnirser, 0)
                  ) REZ ON REZ.CodNirStoc = NS.Codnirstoc AND COALESCE (REZ.CodNirSer, 0) = COALESCE (NSE.CodNirSer, 0)
        LEFT JOIN (SELECT codnirstoc, codnirser, sum (cant) CANT
                   FROM stoclock
                   GROUP BY codnirstoc, codnirser
                  ) Blocat    ON Blocat.CodNirStoc = NS.Codnirstoc AND COALESCE (Blocat.CodNirSer, 0) = COALESCE (NSE.CodNirSer, 0)
        LEFT JOIN NIR          NIRCURENT ON NIRCURENT.CODNIR = NS.CODNIR
        LEFT JOIN NGEST        G         ON G.CODGEST = NIRCURENT.GEST
        LEFT JOIN NLOCATII     L         ON L.CODLOCATIE = NS.CODLOCATIE,
        (SELECT CODIOART, MG
         FROM IOART1 IO1
         WHERE IO1.ANSTART * 12 + IO1.LUNASTART = ( SELECT MAX (IO2.ANSTART * 12 + IO2.LUNASTART)
                                                    FROM IOART1 IO2
                                                    WHERE
                                                      IO2.CODIOART = IO1.CODIOART
                                                      AND IO2.ANSTART * 12 + IO2.LUNASTART &lt;= current_setting (''PKG_GLOBALS.ANLUCRU'', true) ::numeric * 12 + current_setting (''PKG_GLOBALS.LUNALUCRU'', true) ::numeric)
        ) IOALUNA
        LEFT JOIN IOART IOA ON IOALUNA.CODIOART = IOA.CODIOART
      WHERE
        ( (NS.REST &lt;&gt; 0) OR (NS.REST = 0 AND EXISTS (SELECT CODNIRSTOC FROM TMP_LIVR1_INITIAL WHERE CODNIRSTOC = NS.CODNIRSTOC)))
        AND IOALUNA.CODIOART = NS.CODIOART
        AND IOALUNA.MG &lt;&gt; 5
        AND IOALUNA.MG &lt;&gt; 3
        and G.CODSUBUNIT = current_setting (''PKG_GLOBALS.SUBUNITATE'', true) ::numeric
        and (CASE WHEN NS.TIPSERIE &gt; 0 THEN ROUND ( (NSE.REST) ::numeric, 10) ELSE ROUND ( (NS.REST) ::numeric, 10) END) - COALESCE (REZ.Cant, 0) &gt; 0
    )' ;
  return sql;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rezervari_istopitem</obj_name>
  <obj_hashval>17a863975039170a6196e0873f04c7ea</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rezervari_istopitem(INOUT wme_result numeric, INOUT acodcomanda1 numeric, INOUT acodobiect numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  NR numeric := 0;
begin
  BEGIN
    SELECT count( *) INTO NR FROM TMP_REZ_ProiectNod WHERE CodComanda1 = aCodComanda1 and  CodObiect = aCodObiect and  NodOriginal = 0;
  EXCEPTION WHEN OTHERS THEN
    WME_Result :=  0;
    RETURN;
  END;

  WME_Result :=  NR;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rezervari_stergerezervareobiect</obj_name>
  <obj_hashval>1160639824ce407f880062b99493c847</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rezervari_stergerezervareobiect(INOUT wme_result numeric, INOUT acodcomanda1 numeric, INOUT acodobiect numeric, INOUT atip numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_COM RECORD;
  V_REC RECORD;
  aNr   numeric;
BEGIN
  --Adina 24.06.2021 - sinc.Oracle din 23.06.2021
  FOR v_COM IN (SELECT CodComanda1 FROM TMP_REZ_CCOM1 WHERE aCodcomanda1 = 0 or  CodComanda1 = aCodComanda1) LOOP
    SELECT count( S.codscenariu)
    INTO aNr
    FROM scenariilivr s INNER JOIN scenariilivr2 s2 ON  s.codscenariu = s2.codscenariu
    WHERE COALESCE( s.definitiv, 0) = 1 and  s2.codcomanda1 = v_COM.CodComanda1;

--    IF  aNr = 0 THEN  --nu e folosit CodComanda1 in scenarii
      IF  aTip &lt;&gt; 2 THEN
        DELETE FROM rezervats WHERE codcomanda1 = v_COM.CodComanda1 and (   aCodObiect = 0 or  codobiect = aCodObiect)  and  COALESCE( CodComanda1F, 0) = 0;
      END IF;

      IF  aTip &lt;&gt; 1 THEN
        FOR v_Rec IN (SELECT r.codrezervats
                      FROM rezervats r INNER JOIN nirstoc ns ON  r.codnirstoc = ns.codnirstoc
                      WHERE (aCodObiect = 0 or  NS.codobiect = aCodObiect)  and  R.codcomanda1 = v_COM.CodComanda1
                     )
        LOOP
          DELETE FROM rezervats WHERE codrezervats = v_rec.codrezervats;
        END LOOP;
      END IF;
--    END IF;
  END LOOP;

  WME_Result :=  aNR;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_ropharma_do_preluare_tari</obj_name>
  <obj_hashval>01a5898a75e3193b7aa0c504d92537ae</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_ropharma_do_preluare_tari()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_ROPHARMA_PREIA_NOM_TARI( 'ROPH'  , 'ROPH2014');
  PERFORM PKG_ROPHARMA_PREIA_NOM_TARI( 'ROPHBC', 'ROPH2014');
  PERFORM PKG_ROPHARMA_PREIA_NOM_TARI( 'ROPHIS', 'ROPH2014');
  PERFORM PKG_ROPHARMA_PREIA_NOM_TARI( 'MURES' , 'ROPH2014');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_ropharma_get_cod_localit_dest</obj_name>
  <obj_hashval>37b42aaff4be1ed3ae0eaa048904503a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_ropharma_get_cod_localit_dest(INOUT wme_result numeric, INOUT adenlocalit character varying, INOUT atip character varying, INOUT adenjudet character varying, INOUT asimbauto character varying, INOUT acodsiruta numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCODLOCALIT numeric := 0;
begin
  BEGIN
    SELECT CODLOCALIT
    INTO aCODLOCALIT
    FROM NLOCALIT
    WHERE  UPPER( DEN_LOCALIT) = UPPER( aDENLOCALIT)
      AND  COALESCE( UPPER( TIP), '?') = COALESCE( UPPER( aTIP), '?')
      AND  COALESCE( CODJUDET, 0) = (SELECT PKG_ROPHARMA_GETCODJUDET_DEST.WME_RESULT FROM PKG_ROPHARMA_GETCODJUDET_DEST(NULL, 'ROPH2014', aDENJUDET, aSIMBAUTO))
      AND  COALESCE( SIRUTA, 0) = COALESCE( aCODSIRUTA, 0);
  EXCEPTION WHEN OTHERS THEN
    WME_Result :=  0;
    RETURN;
  END;

  WME_Result :=  aCODLOCALIT;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_ropharma_get_cod_of_table</obj_name>
  <obj_hashval>663726c1dec9ef387203b5bb4f938555</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_ropharma_get_cod_of_table(INOUT wme_result numeric, INOUT tabela character varying, INOUT idcolumn character varying, INOUT idcolumn_value character varying, INOUT codcolumn character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  SIR  varchar;
  aCOD numeric;
begin
  SIR := 'SELECT ' || CODCOLUMN || ' FROM ROPH2014.' || TABELA || ' WHERE UPPER(' || IDCOLUMN || ')= ''' || UPPER( IDCOLUMN_VALUE) || '''';
  BEGIN
    EXECUTE Sir;
  EXCEPTION WHEN OTHERS THEN
    aCOD := 0;
  END;
  WME_Result :=  aCOD;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_ropharma_get_cod_of_table_ext</obj_name>
  <obj_hashval>816438e42c9457e424e0a17acae91401</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_ropharma_get_cod_of_table_ext(INOUT wme_result numeric, INOUT tabela character varying, INOUT idcolumn character varying, INOUT idcolumn_value character varying, INOUT codcolumn character varying, INOUT skema character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  SIR  varchar;
  aCOD numeric;
begin
  SIR := 'SELECT ' || CODCOLUMN || ' FROM ' || SKEMA || '.' || TABELA || ' WHERE UPPER(' || IDCOLUMN || ')= ''' || UPPER( IDCOLUMN_VALUE) || '''';
  BEGIN
    EXECUTE Sir;
  EXCEPTION WHEN OTHERS THEN
    aCOD := 0;
  END;
  WME_Result :=  aCOD;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_ropharma_get_umsec_of_object</obj_name>
  <obj_hashval>cf6a4c2a35f602432aba0519fc0b7c94</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_ropharma_get_umsec_of_object(INOUT wme_result numeric, INOUT acodobiect numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  SIR  varchar;
  aCOD numeric;
begin
  SIR := 'SELECT CODUM1 ' || 'FROM ' || '  ROPH2014.NARTOBJ O, ' || '  ROPH2014.NART A,' || ' ROPH2014.NUM1 U1 ' || 'WHERE ' || '  O.CODOBIECT = ' || TO_CHAR( aCODOBIECT,'9999999999') || '  AND O.CODARTICOL = A.CODARTICOL ' || '  AND U1.CODUM = A.UM ' || '  AND U1.SECUNDARA = 0';
  BEGIN
    EXECUTE Sir;
  EXCEPTION WHEN OTHERS THEN
    aCOD := 0;
  END;
  WME_Result :=  aCOD;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_ropharma_getcodjudet_dest</obj_name>
  <obj_hashval>6ded28ed289e7917ba2630ffe910b30d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_ropharma_getcodjudet_dest(INOUT wme_result numeric, INOUT skemadest character varying, INOUT adenjudet character varying, INOUT asimbtara character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  S         varchar := '';
  aCODJUDET numeric := 0;
begin
  BEGIN
    S := 'SELECT CODJUDET ' || '   FROM ' || '     ' || SKEMADEST || '.NJUDET ' || '   WHERE ' || '    UPPER(DEN_JUDET) = ''' || UPPER( aDENJUDET) || '''' || '    AND upper(coalesce(SIMBAUTO, ''?'')) = ''' || upper( COALESCE( aSIMBTARA, '?')) || '''';
    EXECUTE S;
  EXCEPTION WHEN OTHERS THEN
    aCODJUDET := 0;
  END;
  WME_Result :=  aCODJUDET;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_ropharma_preia_judete</obj_name>
  <obj_hashval>fb9d969645f11fb5a8f78f8676f2d7a7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_ropharma_preia_judete(skemasursa character varying, skemadest character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  S  varchar;
  NR numeric := 0;
begin
  s := 'DECLARE NR NUMBER(10) := 0;' || 'BEGIN ' || '  FOR V_REC IN (SELECT J.*, T.DEN_TARA, T.SIMBAUTO AS SIMBAUTOTARA FROM ' || SKEMASURSA || '.NJUDET J LEFT OUTER JOIN ' || SKEMASURSA || '.NTARI T ON T.CODTARA = J.CODTARA WHERE DEN_JUDET IS NOT NULL)' || '  LOOP ' || '     SELECT COUNT(*) INTO NR FROM ' || SKEMADEST || ' .NJUDET ' || '     WHERE ' || '       UPPER(DEN_JUDET) = upper(V_REC.DEN_JUDET); ' || '  IF NR = 0 THEN ' || '   INSERT INTO ' || SKEMADEST || '.NJUDET(CODJUDET, DEN_JUDET, SIMBAUTO,  CODTARA, REGCOM, CODDRP, DENDRP, JS, ITM)' || '   VALUES (' || SKEMADEST || '.SEQ_NTARI_CODTARA.NEXTVAL, V_REC.DEN_JUDET, V_REC.SIMBAUTO, ' || '   PKG_ROPHARMA.GETCODTARA_DEST(''' || SKEMADEST || ''', V_REC.DEN_TARA, V_REC.SIMBAUTOTARA) , ' || '   V_REC.REGCOM, V_REC.CODDRP, V_REC.DENDRP, V_REC.JS, V_REC.ITM);' || '  END IF; ' || '  END LOOP; ' || 'END;';
  EXECUTE s;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_ropharma_preia_localitati</obj_name>
  <obj_hashval>b309056cd7026c0355593998a6429ede</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_ropharma_preia_localitati(skemasursa character varying, skemadest character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  S varchar;
begin
  S := ' DECLARE ' || '  NR NUMBER(10) := 0;' || '  BEGIN ' || '    FOR V_REC IN (SELECT  ' || '                  L.*, J.DEN_JUDET, J.SIMBAUTO, T.DEN_TARA, T.SIMBAUTO AS SIMBAUTOTARA ' || '                  FROM ' || '                    ' || SKEMASURSA || '.NLOCALIT L  ' || '                    LEFT OUTER JOIN ' || SKEMASURSA || '.NJUDET J ON J.CODJUDET = L.CODJUDET ' || '                    LEFT OUTER JOIN ' || SKEMASURSA || '.NTARI T ON T.CODTARA = L.CODTARA ' || '                  WHERE DEN_LOCALIT IS NOT NULL ' || '                )' || '    LOOP ' || '        SELECT COUNT(*) INTO NR FROM ' || SKEMADEST || '.NLOCALIT ' || '        WHERE ' || '          UPPER(DEN_LOCALIT) = UPPER(V_REC.DEN_LOCALIT) ' || '          AND coalesce(UPPER(TIP), ''?'') = coalesce(UPPER(V_REC.TIP), ''?'') ' || '          AND coalesce(SIRUTA, 0) = coalesce(V_REC.SIRUTA, 0) ' || '          AND coalesce(CODJUDET, 0) = ' || SKEMADEST || '.PKG_ROPHARMA.GETCODJUDET_DEST(''' || SKEMADEST || ''', V_REC.DEN_JUDET, V_REC.SIMBAUTO);' || '          IF NR = 0 THEN ' || '            INSERT INTO ' || SKEMADEST || ' .NLOCALIT(CODLOCALIT, DEN_LOCALIT, TIP, CODJUDET, OBS, CODTARA, DENSUP, SIRUTA) ' || '            VALUES(' || SKEMADEST || '.SEQ_NLOCALIT_CODLOCALIT.NEXTVAL, ' || '                   V_REC.DEN_LOCALIT, ' || '                   V_REC.TIP, ' || '                   ' || SKEMADEST || '.PKG_ROPHARMA.GETCODJUDET_DEST(''' || SKEMADEST || ''', V_REC.DEN_JUDET, V_REC.SIMBAUTO), ' || '                   V_REC.OBS, ' || SKEMADEST || '.PKG_ROPHARMA.GETCODTARA_DEST(''' || SKEMADEST || ''', V_REC.DEN_TARA, V_REC.SIMBAUTOTARA), ' || '                   V_REC.DENSUP, V_REC.SIRUTA ' || '                  ); ' || '          END IF; ' || '    END LOOP;' || '    END;';
  EXECUTE S;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_ropharma_preia_nom_tari</obj_name>
  <obj_hashval>b8e2f0da287ec92901ede79610e3df78</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_ropharma_preia_nom_tari(skemasursa character varying, skemadest character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  S varchar;
begin
  S := 'DECLARE  NR NUMBER(10) := 0;' || 'BEGIN ' || 'FOR V_REC IN (SELECT CODTARA, DEN_TARA, SIMBAUTO, STATCOMUNITAR FROM ' || SKEMASURSA || '.NTARI WHERE DEN_TARA IS NOT NULL )' || 'LOOP ' || '  SELECT COUNT(*) INTO NR ' || '  FROM ' || '    ' || SKEMADEST || '.NTARI T ' || '  WHERE ' || '   UPPER(DEN_TARA) = UPPER(V_REC.DEN_TARA) ' || '   AND upper(coalesce(T.SIMBAUTO, ''?'')) = upper(coalesce(V_REC.SIMBAUTO, ''?'')); ' || '   IF NR = 0 THEN ' || '     INSERT INTO ' || SKEMADEST || '.NTARI(CODTARA, DEN_TARA, SIMBAUTO, STATCOMUNITAR) ' || '     VALUES(SEQ_NTARI_CODTARA.NEXTVAL, V_REC.DEN_TARA, V_REC.SIMBAUTO, coalesce(V_REC.STATCOMUNITAR, 0)); ' || '   END IF;  ' || 'END LOOP;  ' || 'END;';
  EXECUTE S;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_an_rupere</obj_name>
  <obj_hashval>75a8661714469cc89bc08faeb2ce6c9f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_an_rupere(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_curata_carnetedoc</obj_name>
  <obj_hashval>da55edb73f38c4a860f57df60b013d7e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_curata_carnetedoc()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  NR    numeric := 0;
  TOTAL numeric := 0;
  vAnLunaRupere numeric := TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
begin
  FOR V_REC IN (SELECT * FROM DOCCARNETE WHERE FREENR = 0) LOOP
    TOTAL := 0;
    SELECT COUNT( *)
    INTO NR
    FROM IESIRI
    WHERE AN * 12 + LUNA &gt;= vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    TOTAL := TOTAL + NR;
    SELECT COUNT( *)
    INTO NR
    FROM COMANDA
    WHERE AN * 12 + LUNA &gt;= vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    TOTAL := TOTAL + NR;
    SELECT COUNT( *)
    INTO NR
    FROM TRANSF
    WHERE AN * 12 + LUNA &gt;= vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    TOTAL := TOTAL + NR;
    SELECT COUNT( *)
    INTO NR
    FROM COMPENS
    WHERE AN * 12 + LUNA &gt;= vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    TOTAL := TOTAL + NR;
    SELECT COUNT( *)
    INTO NR
    FROM NC
    WHERE AN * 12 + LUNA &gt;= vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    TOTAL := TOTAL + NR;
    SELECT COUNT( *)
    INTO NR
    FROM TREZOR1
    WHERE AN * 12 + LUNA &gt;= vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    TOTAL := TOTAL + NR;
    SELECT COUNT( *)
    INTO NR
    FROM PACHETE
    WHERE AN * 12 + LUNA &gt;= vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    TOTAL := TOTAL + NR;
    SELECT COUNT( *)
    INTO NR
    FROM OFERTA
    WHERE AN * 12 + LUNA &gt;= vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    TOTAL := TOTAL + NR;
    SELECT COUNT( *)
    INTO NR
    FROM LIVR L, IESIRI I
    WHERE L.CODIES = I.CODIES AND  L.TIPLIVR = I.TIPDOC AND  I.AN * 12 + I.LUNA &gt;= vAnLunaRupere AND  CARNETLIVR = V_REC.CODCARNET;

    TOTAL := TOTAL + NR;
    SELECT COUNT( *)
    INTO NR
    FROM LIVR L, TRANSF T
    WHERE L.CODTRANSF = T.CODTRANSF AND  L.TIPLIVR = T.TIPDOC AND  T.AN * 12 + T.LUNA &gt;= vAnLunaRupere AND  CARNETLIVR = V_REC.CODCARNET;

    TOTAL := TOTAL + NR;
    SELECT COUNT( *)
    INTO NR
    FROM LIVR L, INTRARI I
    WHERE L.CODINTR = I.CODINTR AND  L.TIPLIVR = I.TIPDOC AND  I.AN * 12 + I.LUNA &gt;= vAnLunaRupere AND  CARNETLIVR = V_REC.CODCARNET;

    TOTAL := TOTAL + NR;
    SELECT COUNT( *)
    INTO NR
    FROM NIR N, IESIRI I
    WHERE N.CODIES = I.CODIES AND  N.TIPNIR = I.TIPDOC AND  I.AN * 12 + I.LUNA &gt;= vAnLunaRupere AND  CARNETNIR = V_REC.CODCARNET;

    TOTAL := TOTAL + NR;
    SELECT COUNT( *)
    INTO NR
    FROM NIR N, TRANSF T
    WHERE N.CODTRANSF = T.CODTRANSF AND  N.TIPNIR = T.TIPDOC AND  T.AN * 12 + T.LUNA &gt;= vAnLunaRupere AND  CARNETNIR = V_REC.CODCARNET;

    TOTAL := TOTAL + NR;
    SELECT COUNT( *)
    INTO NR
    FROM NIR N, INTRARI I
    WHERE N.CODINTR = I.CODINTR AND  N.TIPNIR = I.TIPDOC AND  I.AN * 12 + I.LUNA &gt;= vAnLunaRupere AND  CARNETNIR = V_REC.CODCARNET;

    TOTAL := TOTAL + NR;
    IF  TOTAL = 0 THEN
      DELETE FROM DOCLOCK    WHERE CODCARNET = V_REC.CODCARNET;
      DELETE FROM DOCLINK    WHERE CODCARNET = V_REC.CODCARNET;
      DELETE FROM DOCFREE    WHERE CODCARNET = V_REC.CODCARNET;
      DELETE FROM DOCUSERS   WHERE CODCARNET = V_REC.CODCARNET;
      DELETE FROM DOCCARNETE WHERE CODCARNET = V_REC.CODCARNET;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_curata_comanda1</obj_name>
  <obj_hashval>1d204e578f95670df41a84966e3b536d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_curata_comanda1()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  NRINT numeric := 0;
  NRIES numeric := 0;
  NRTR  numeric := 0;
begin
  FOR V_REC IN
  (
  SELECT C1.CODCOMANDA1, C1.CANTACCEPTAT, C.TIPDOC
  FROM COMANDA1 C1, COMANDA C
  WHERE C.CODCOMANDA = C1.CODCOMANDA AND  C.AN * 12 + C.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
  )
  LOOP
    NRINT := 0;
    NRIES := 0;
    NRTR := 0;
    IF  V_REC.CANTACCEPTAT = 0 THEN
      SELECT COUNT( *) INTO NRIES FROM IESLINK    WHERE CODLINIECOMANDA = V_REC.CODCOMANDA1;
      SELECT COUNT( *) INTO NRINT FROM INTRLINK   WHERE CODLINIECOMANDA = V_REC.CODCOMANDA1;
      SELECT COUNT( *) INTO NRTR  FROM TRANSFLINK WHERE CODLINIECOMANDA = V_REC.CODCOMANDA1;

      IF  NRIES + NRINT + NRTR = 0 THEN
        BEGIN
          DELETE FROM COMANDA1 WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
        EXCEPTION WHEN OTHERS THEN
          NRINT := NRINT + 1;
        END;
      END IF;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_curata_iesiri</obj_name>
  <obj_hashval>b9b8eb1901dc1016e31dcd9efb6b4e15</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_curata_iesiri()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  NR    numeric := 0;
begin
  FOR V_REC IN
  (
  SELECT I.CODIES, I.CARNETDOC, I.NRDOC
  FROM IESIRI I
      LEFT JOIN IESIRI1 I1 ON  I1.CODIES = I.CODIES
      LEFT JOIN GENERAL G  ON  G.TIPDOC  = I.TIPDOC AND  G.CODDOC = I.CODIES
      LEFT JOIN NIR     N  ON  N.TIPNIR  = I.TIPDOC AND  N.CODIES = I.CODIES
      LEFT JOIN LIVR    L  ON  L.TIPLIVR = I.TIPDOC AND  L.CODIES = I.CODIES
  WHERE I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
    AND I1.CODIES1 IS NULL  AND G.CODGENERAL IS NULL  AND N.CODNIR IS NULL  AND L.CODLIVR IS NULL
  )
  LOOP
    SELECT COUNT( *) INTO NR FROM DOCCARNETE WHERE CODCARNET = V_REC.CARNETDOC AND  STARTNR &lt;= V_REC.NRDOC;
    IF  NR = 0 THEN
      DELETE FROM IESIRI WHERE CODIES = V_REC.CODIES;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_curata_intrari1</obj_name>
  <obj_hashval>bb90777c0d7b0fa0322265f49dcc33b5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_curata_intrari1()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  NR    numeric := 0;
begin
  FOR V_REC IN
  (
  SELECT I1.CODINTR1, I1.CANT, I.TIPDOC
  FROM INTRARI1 I1, INTRARI I
  WHERE I.CODINTR = I1.CODINTR AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
    AND  COALESCE( I.TVAINCASARE, 0) = 0
  )
  LOOP
    NR := 0;
    SELECT COUNT( *) INTO NR FROM NIRSTOC WHERE CODINTR1 = V_REC.CODINTR1;
    IF  NR = 0 THEN
      IF  V_REC.TIPDOC = 2 THEN
        IF  V_REC.CANT = 0 THEN
          SELECT COUNT( *) INTO NR FROM INTRLINK WHERE CODLINIEAVIZ = V_REC.CODINTR1;
          IF  NR = 0 THEN
            BEGIN
              DELETE FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1;
            EXCEPTION WHEN OTHERS THEN
              NR := NR + 1;
            END;
          END IF;
        END IF;
      ELSE
        BEGIN
          DELETE FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1;
        EXCEPTION WHEN OTHERS THEN
          NR := NR + 1;
        END;
      END IF;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_curata_jurnale</obj_name>
  <obj_hashval>7c6cf07012b879fce80befd70aa3640a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_curata_jurnale()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM JURNAL
  WHERE AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

  DELETE FROM JURNAL1
  WHERE AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_curata_livr</obj_name>
  <obj_hashval>0888f2f7badab4f0f78694ef3db605ff</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_curata_livr()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  NR    numeric := 0;
begin
  FOR V_REC IN
  (
  SELECT *
  FROM (SELECT L.CODLIVR, L.CARNETLIVR, L.NRLIVR,
               CASE WHEN I.CODINTR   IS NOT NULL  THEN I.AN
                    WHEN E.CODIES    IS NOT NULL  THEN E.AN
                    WHEN T.CODTRANSF IS NOT NULL  THEN T.AN
                    ELSE 0
               END  AS AN,
               CASE WHEN I.CODINTR   IS NOT NULL  THEN I.LUNA
                     WHEN E.CODIES    IS NOT NULL  THEN E.LUNA
                     WHEN T.CODTRANSF IS NOT NULL  THEN T.LUNA
                     ELSE 0
               END  AS LUNA
        FROM LIVR L
            LEFT JOIN IESIRI  E ON  E.CODIES    = L.CODIES    AND  E.TIPDOC = L.TIPLIVR
            LEFT JOIN INTRARI I ON  I.CODINTR   = L.CODINTR   AND  I.TIPDOC = L.TIPLIVR
            LEFT JOIN TRANSF  T ON  T.CODTRANSF = L.CODTRANSF AND  T.TIPDOC = L.TIPLIVR
        WHERE NOT  EXISTS (SELECT CODLIVR FROM LIVR1 WHERE CODLIVR = L.CODLIVR)
       ) A_PG
  WHERE AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + LUNA
  )
  LOOP
    SELECT COUNT( *) INTO NR FROM DOCCARNETE WHERE CODCARNET = V_REC.CARNETLIVR AND  STARTNR &lt;= V_REC.NRLIVR;
    IF  NR = 0 THEN
      DELETE FROM LIVR L WHERE CODLIVR = V_REC.CODLIVR;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_curata_livr1</obj_name>
  <obj_hashval>eb53cdd11890c9318756341d13257569</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_curata_livr1()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_RECLIVR RECORD;
begin
  FOR V_RECLIVR IN
  (
  SELECT *
  FROM (SELECT CODLIVR1, I.CODINTR, E.CODIES, T.CODTRANSF,
               (CASE WHEN I.CODINTR IS NOT NULL  THEN I.AN
                     WHEN E.CODIES IS NOT NULL  THEN E.AN
                     WHEN T.CODTRANSF IS NOT NULL  THEN T.AN
                END )  AS AN,
               (CASE WHEN I.CODINTR IS NOT NULL  THEN I.LUNA
                      WHEN E.CODIES IS NOT NULL  THEN E.LUNA
                      WHEN T.CODTRANSF IS NOT NULL  THEN T.LUNA
                END )  AS LUNA
        FROM LIVR1 L1, LIVR L
            LEFT JOIN INTRARI I ON  I.CODINTR   = L.CODINTR   AND  I.TIPDOC = L.TIPLIVR
            LEFT JOIN TRANSF  T ON  T.CODTRANSF = L.CODTRANSF AND  T.TIPDOC = L.TIPLIVR
            LEFT JOIN IESIRI  E ON  E.CODIES    = L.CODIES    AND  E.TIPDOC = L.TIPLIVR
        WHERE L.CODLIVR = L1.CODLIVR
        ) A_PG
  WHERE AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
  )
  LOOP
    DELETE FROM LIVRVAL WHERE CODLIVR1 = V_RECLIVR.CODLIVR1;
    DELETE FROM LIVR1   WHERE CODLIVR1 = V_RECLIVR.CODLIVR1;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_curata_nir</obj_name>
  <obj_hashval>917dddf2e23b94e1cb75e3838a9e6122</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_curata_nir()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  NR    numeric := 0;
begin
  FOR V_REC IN
  (
  SELECT *
  FROM (SELECT N.CODNIR, N.CARNETNIR, N.NRNIR,
               CASE  WHEN I.CODINTR   IS NOT NULL  THEN I.AN
                     WHEN E.CODIES    IS NOT NULL  THEN E.AN
                     WHEN T.CODTRANSF IS NOT NULL  THEN T.AN
                     ELSE 0
               END  AS AN,
               CASE
                     WHEN I.CODINTR   IS NOT NULL  THEN I.LUNA
                     WHEN E.CODIES    IS NOT NULL  THEN E.LUNA
                     WHEN T.CODTRANSF IS NOT NULL  THEN T.LUNA
                     ELSE 0
               END  AS LUNA
        FROM NIR N
            LEFT JOIN IESIRI  E ON  E.CODIES    = N.CODIES    AND  E.TIPDOC = N.TIPNIR
            LEFT JOIN INTRARI I ON  I.CODINTR   = N.CODINTR   AND  I.TIPDOC = N.TIPNIR
            LEFT JOIN TRANSF  T ON  T.CODTRANSF = N.CODTRANSF AND  T.TIPDOC = N.TIPNIR
        WHERE
           NOT  EXISTS (SELECT CODNIR FROM NIRSTOC WHERE CODNIR = N.CODNIR)
        ) A_PG
  WHERE AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + LUNA
  )
  LOOP
    SELECT COUNT( *) INTO NR FROM DOCCARNETE WHERE CODCARNET = V_REC.CARNETNIR AND  STARTNR &lt;= V_REC.NRNIR;
    IF  NR = 0 THEN
      DELETE FROM NIR N WHERE CODNIR = V_REC.CODNIR;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_curata_nirstoc</obj_name>
  <obj_hashval>153af1c29c5bd54cb6d1c7116aafc362</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_curata_nirstoc()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  NR    numeric;
  aREST double precision;
begin
  FOR V_REC IN
  (
  SELECT *
  FROM (SELECT NS.CODNIRSTOC,
               (CASE WHEN I.CODINTR   IS NOT NULL  THEN I.AN
                     WHEN E.CODIES    IS NOT NULL  THEN E.AN
                     WHEN T.CODTRANSF IS NOT NULL  THEN T.AN
                END )  AS AN,
               (CASE WHEN I.CODINTR   IS NOT NULL  THEN I.LUNA
                     WHEN E.CODIES    IS NOT NULL  THEN E.LUNA
                     WHEN T.CODTRANSF IS NOT NULL  THEN T.LUNA
                END )  AS LUNA
        FROM NIRSTOC NS
            LEFT JOIN TMP_IOART_LUNA IO ON  IO.CODIOART = NS.CODIOART, NIR N
            LEFT JOIN INTRARI        I  ON  I.CODINTR   = N.CODINTR   AND  I.TIPDOC = N.TIPNIR
            LEFT JOIN TRANSF         T  ON  T.CODTRANSF = N.CODTRANSF AND  T.TIPDOC = N.TIPNIR
            LEFT JOIN IESIRI         E  ON  E.CODIES    = N.CODIES    AND  E.TIPDOC = N.TIPNIR
        WHERE N.CODNIR = NS.CODNIR AND  COALESCE( IO.MG, 0) &lt;&gt; 5
        ) A_PG
  WHERE AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
  )
  LOOP
    BEGIN
      SELECT COALESCE( REST, 0)
      INTO aREST
      FROM NIRLUNA
      WHERE CODNIRSTOC = V_REC.CODNIRSTOC AND  AN = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999') AND  LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999');

      SELECT COUNT( *) INTO NR FROM LIVR1 WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    EXCEPTION WHEN OTHERS THEN
      NR    := 0;
      aREST := 1;
    END;

    IF (NR = 0)  and (aREST = 0) THEN
      BEGIN
        DELETE FROM NIRLUNA WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
        DELETE FROM NIRSER  WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
        DELETE FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
      EXCEPTION WHEN OTHERS THEN
        NR := 0;
      END;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_curata_obligpif</obj_name>
  <obj_hashval>82d9a50d968b56388ec901d81121b66b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_curata_obligpif()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  NR    numeric;
begin
  FOR V_REC IN
  (
  SELECT O.CODOBLIGPIF, O.CODGENERAL, O.VALOARE
  FROM OBLIGPIF O
  LEFT JOIN GENERAL G ON  G.CODGENERAL = O.CODGENERAL
  LEFT JOIN INTRARI I ON  I.CODINTR    = G.CODDOC
  WHERE O.SEMNIFICATIE IN (100, 140) AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999') AND (   I.OPERAT = 1)  AND (   I.ANULAT = 0)
  union ALL
  SELECT O.CODOBLIGPIF, O.CODGENERAL, O.VALOARE
  FROM OBLIGPIF O
  LEFT JOIN GENERAL G ON  G.CODGENERAL = O.CODGENERAL
  LEFT JOIN INTRARI I ON  I.CODINTR    = G.CODDOC
  WHERE O.SEMNIFICATIE IN (110) AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999') AND (   I.OPERAT = 1)  AND (   I.ANULAT = 0)
  union ALL
  SELECT O.CODOBLIGPIF, O.CODGENERAL, O.VALOARE
  FROM OBLIGPIF O
  LEFT JOIN GENERAL G ON  G.CODGENERAL = O.CODGENERAL
  LEFT JOIN DVI     D ON  G.CODDOC     = D.CODDVI
  LEFT JOIN INTRARI I ON  I.CODINTR    = D.CODINTR
  WHERE O.SEMNIFICATIE IN (130) AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999') AND (   I.OPERAT = 1)  AND (   I.ANULAT = 0)
  union ALL
  SELECT O.CODOBLIGPIF, O.CODGENERAL, O.VALOARE
  FROM OBLIGPIF O
  LEFT JOIN GENERAL G ON  G.CODGENERAL = O.CODGENERAL
  LEFT JOIN IESIRI  I ON  I.CODIES     = G.CODDOC
  WHERE O.SEMNIFICATIE IN (200, 240) AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999') AND (   I.OPERAT = 1)  AND (   I.ANULAT = 0)
  union ALL
  SELECT O.CODOBLIGPIF, O.CODGENERAL, O.VALOARE
  FROM OBLIGPIF O
  LEFT JOIN GENERAL G ON  G.CODGENERAL = O.CODGENERAL
  LEFT JOIN IESIRI  I ON  I.CODIES     = G.CODDOC
  WHERE O.SEMNIFICATIE IN (210) AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999') AND (   I.OPERAT = 1)  AND (   I.ANULAT = 0)
  union ALL
  SELECT O.CODOBLIGPIF, O.CODGENERAL, O.VALOARE
  FROM OBLIGPIF O
  LEFT JOIN GENERAL G  ON  G.CODGENERAL  = O.CODGENERAL
  LEFT JOIN TREZOR1 T1 ON  T1.CODTREZOR1 = G.CODDOC
  LEFT JOIN TREZOR  T  ON  T.CODTREZOR   = T1.CODTREZOR
  WHERE ((T1.INITIALIZARI = 1)  OR (   COALESCE( T1.INITIALIZARI, 0) &lt;&gt; 1 AND  T.OPERAT = 1) )  AND G.TIPDOC IN (29, 30, 31, 33) AND  T.AN * 12 + T.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999') AND G.SEMNIFICATIE IN (310, 330, 410, 430, 500, 600)
  union ALL
  SELECT O.CODOBLIGPIF, O.CODGENERAL, O.VALOARE
  FROM OBLIGPIF O
  LEFT JOIN GENERAL G  ON  G.CODGENERAL = O.CODGENERAL
  LEFT JOIN NC1     N1 ON  N1.CODNC1    = G.CODDOC
  LEFT JOIN NC      N  ON  N.CODNC      = N1.CODNC
  WHERE O.SEMNIFICATIE IN (1200, 1201) AND  N.AN * 12 + N.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
  union ALL
  SELECT O.CODOBLIGPIF, O.CODGENERAL, O.VALOARE
  FROM OBLIGPIF O
  LEFT JOIN GENERAL G ON  G.CODGENERAL = O.CODGENERAL
  LEFT JOIN COMPENS C ON  C.CODCOMPENS = G.CODDOC
  WHERE O.SEMNIFICATIE IN (1301, 1303, 1351) AND  C.AN * 12 + C.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
  )
  LOOP
    NR := 0;
    IF  V_REC.VALOARE = 0 THEN
      SELECT COUNT( *) INTO NR FROM STINGERE WHERE CODSTINSPIF = V_REC.CODOBLIGPIF;
      IF  NR = 0 THEN
        BEGIN
          DELETE FROM GENERAL  WHERE CODGENERAL  = V_REC.CODGENERAL;
          DELETE FROM OBLIGPIF WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
        EXCEPTION WHEN OTHERS THEN
          NR := NR + 1;
        END;
      END IF;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_curata_transf</obj_name>
  <obj_hashval>7b4d027fe7f6bac1b8dde011c63249e8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_curata_transf()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  NR    numeric := 0;
begin
  FOR V_REC IN
  (
  SELECT T.CODTRANSF, T.CARNETDOC, T.NRDOC
  FROM TRANSF T
  LEFT JOIN TRANSF1 T1 ON  T1.CODTRANSF = T.CODTRANSF
  LEFT JOIN NIR N ON  N.TIPNIR = T.TIPDOC AND  N.CODTRANSF = T.CODTRANSF
  WHERE
     T.AN * 12 + T.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999') AND T1.CODTRANSF1 IS NULL  AND N.CODNIR IS NULL
  )
  LOOP
    SELECT COUNT( *) INTO NR FROM DOCCARNETE WHERE CODCARNET = V_REC.CARNETDOC AND  STARTNR &lt;= V_REC.NRDOC;
    IF  NR = 0 THEN
      DELETE FROM TRANSF WHERE CODTRANSF = V_REC.CODTRANSF;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_curata_transf1</obj_name>
  <obj_hashval>c416c17afbd5f746fd29d7eb131b0ee4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_curata_transf1()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  FOR V_REC IN
  (
  SELECT T.CODTRANSF, T1.CODTRANSF1, L.CODLIVR, N.CODNIR
  FROM TRANSF1 T1
      LEFT JOIN TRANSF T ON  T.CODTRANSF = T1.CODTRANSF
      LEFT JOIN LIVR   L ON  L.CODTRANSF = T.CODTRANSF
      LEFT JOIN NIR    N ON  N.CODTRANSF = T.CODTRANSF
  WHERE T.AN * 12 + T.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999') AND L.CODLIVR IS NULL  AND N.CODNIR IS NULL
  )
  LOOP
    DELETE FROM TRANSF1 WHERE CODTRANSF1 = V_REC.CODTRANSF1;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_do_curata_ioart</obj_name>
  <obj_hashval>13e801e2937278148d7227c302512073</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_do_curata_ioart()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC     RECORD;
  CARACTNOU numeric := 0;
  MAXANLUNA numeric := 0;
begin
  FOR V_REC IN (SELECT * FROM IOART) LOOP
    SELECT COUNT( *)
    INTO CARACTNOU
    FROM IOART1
    WHERE CODIOART = V_REC.CODIOART AND  ANSTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') AND  LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

    IF  CARACTNOU &gt; 0 THEN
      DELETE FROM IOART1
      WHERE CODIOART = V_REC.CODIOART AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
    ELSE
      SELECT COALESCE( MAX( ANSTART * 12 + LUNASTART), 0)
      INTO MAXANLUNA
      FROM IOART1
      WHERE CODIOART = V_REC.CODIOART AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

      IF  MAXANLUNA &gt; 0 THEN
        UPDATE IOART1
        SET
        ANSTART   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE'  , true)),'999999999999999999'),
        LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
        WHERE
         CODIOART = V_REC.CODIOART AND  ANSTART * 12 + LUNASTART = MAXANLUNA;

        DELETE FROM IOART1
        WHERE CODIOART = V_REC.CODIOART AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
      END IF;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_do_curata_iobank</obj_name>
  <obj_hashval>f0418836ae1cd53085c0e27685a6e566</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_do_curata_iobank()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC     RECORD;
  CARACTNOU numeric := 0;
  MAXANLUNA numeric := 0;
begin
  FOR V_REC IN (SELECT * FROM IOBANK) LOOP
    SELECT COUNT( *)
    INTO CARACTNOU
    FROM IOBANK1
    WHERE CODIOBANK = V_REC.CODIOBANK AND  ANSTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') AND  LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

    IF  CARACTNOU &gt; 0 THEN
      DELETE FROM IOBANK1
      WHERE CODIOBANK = V_REC.CODIOBANK AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
    ELSE
      SELECT COALESCE( MAX( ANSTART * 12 + LUNASTART), 0)
      INTO MAXANLUNA
      FROM IOBANK1
      WHERE CODIOBANK = V_REC.CODIOBANK AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

      IF  MAXANLUNA &gt; 0 THEN
        UPDATE IOBANK1
        SET
        ANSTART   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE'  , true)),'999999999999999999'),
        LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
        WHERE
         CODIOBANK = V_REC.CODIOBANK AND  ANSTART * 12 + LUNASTART = MAXANLUNA;

        DELETE FROM IOBANK1
        WHERE CODIOBANK = V_REC.CODIOBANK AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
      END IF;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_do_curata_iofilial</obj_name>
  <obj_hashval>d419cf842e182f8ae27428f9fb569682</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_do_curata_iofilial()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC     RECORD;
  CARACTNOU numeric := 0;
  MAXANLUNA numeric := 0;
begin
  FOR V_REC IN (SELECT * FROM IOFILIAL) LOOP
    SELECT COUNT( *)
    INTO CARACTNOU
    FROM IOFILIAL1
    WHERE CODIOFILIAL = V_REC.CODIOFILIAL AND  ANSTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') AND  LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

    IF  CARACTNOU &gt; 0 THEN
      DELETE FROM IOFILIAL1
      WHERE CODIOFILIAL = V_REC.CODIOFILIAL AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
    ELSE
      SELECT COALESCE( MAX( ANSTART * 12 + LUNASTART), 0)
      INTO MAXANLUNA
      FROM IOFILIAL1
      WHERE CODIOFILIAL = V_REC.CODIOFILIAL AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

      IF  MAXANLUNA &gt; 0 THEN
        UPDATE IOFILIAL1
        SET
        ANSTART   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE'  , true)),'999999999999999999'),
        LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
        WHERE
         CODIOFILIAL = V_REC.CODIOFILIAL AND  ANSTART * 12 + LUNASTART = MAXANLUNA;

        DELETE FROM IOFILIAL1
        WHERE CODIOFILIAL = V_REC.CODIOFILIAL AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
      END IF;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_do_curata_iopart</obj_name>
  <obj_hashval>71bd16de913f42e1ea509ffd2ec761d9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_do_curata_iopart()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC     RECORD;
  CARACTNOU numeric := 0;
  MAXANLUNA numeric := 0;
begin
  FOR V_REC IN (SELECT * FROM IOPART) LOOP
    SELECT COUNT( *)
    INTO CARACTNOU
    FROM IOPART1
    WHERE CODIOPART = V_REC.CODIOPART AND  ANSTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') AND  LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

    IF  CARACTNOU &gt; 0 THEN
      DELETE FROM IOPART1
      WHERE CODIOPART = V_REC.CODIOPART AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
    ELSE
      SELECT COALESCE( MAX( ANSTART * 12 + LUNASTART), 0)
      INTO MAXANLUNA
      FROM IOPART1
      WHERE CODIOPART = V_REC.CODIOPART AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

      IF  MAXANLUNA &gt; 0 THEN
        UPDATE IOPART1
        SET
        ANSTART   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE'  , true)),'999999999999999999'),
        LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
        WHERE
         CODIOPART = V_REC.CODIOPART AND  ANSTART * 12 + LUNASTART = MAXANLUNA;

        DELETE FROM IOPART1
        WHERE CODIOPART = V_REC.CODIOPART AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
      END IF;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_do_curata_nart1</obj_name>
  <obj_hashval>a2442b650315b4d296a6356baad9c7b3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_do_curata_nart1()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC     RECORD;
  CARACTNOU numeric := 0;
  MAXANLUNA numeric := 0;
begin
  FOR V_REC IN (SELECT * FROM NART) LOOP
    SELECT COUNT( *)
    INTO CARACTNOU
    FROM NART1
    WHERE CODARTICOL = V_REC.CODARTICOL AND  ANSTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') AND  LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

    IF  CARACTNOU &gt; 0 THEN
      DELETE FROM NART1
      WHERE CODARTICOL = V_REC.CODARTICOL AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
    ELSE
      SELECT COALESCE( MAX( ANSTART * 12 + LUNASTART), 0)
      INTO MAXANLUNA
      FROM NART1
      WHERE
         CODARTICOL = V_REC.CODARTICOL AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

      IF  MAXANLUNA &gt; 0 THEN
        UPDATE NART1
        SET
        ANSTART   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE'  , true)),'999999999999999999'),
        LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
        WHERE
         CODARTICOL = V_REC.CODARTICOL AND  ANSTART * 12 + LUNASTART = MAXANLUNA;

        DELETE FROM NART1
        WHERE
         CODARTICOL = V_REC.CODARTICOL AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
      END IF;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_do_curata_nartobj1</obj_name>
  <obj_hashval>08fc396baad8c3bc5dc4fe1e89a81159</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_do_curata_nartobj1()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC     RECORD;
  CARACTNOU numeric := 0;
  MAXANLUNA numeric := 0;
begin
  FOR V_REC IN (SELECT * FROM NARTOBJ) LOOP
    SELECT COUNT( *)
    INTO CARACTNOU
    FROM NARTOBJ1
    WHERE CODOBIECT = V_REC.CODOBIECT AND  ANSTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') AND  LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

    IF  CARACTNOU &gt; 0 THEN
      DELETE FROM NARTOBJ1
      WHERE CODOBIECT = V_REC.CODOBIECT AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
    ELSE
      SELECT COALESCE( MAX( ANSTART * 12 + LUNASTART), 0)
      INTO MAXANLUNA
      FROM NARTOBJ1
      WHERE CODOBIECT = V_REC.CODOBIECT AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

      IF  MAXANLUNA &gt; 0 THEN
        UPDATE NARTOBJ1
        SET
        ANSTART   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE'  , true)),'999999999999999999'),
        LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
        WHERE
         CODOBIECT = V_REC.CODOBIECT AND  ANSTART * 12 + LUNASTART = MAXANLUNA;

        DELETE FROM NARTOBJ1
        WHERE CODOBIECT = V_REC.CODOBIECT AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
      END IF;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_do_curata_ncont1</obj_name>
  <obj_hashval>aabb7bad143324dde94927b80496df55</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_do_curata_ncont1()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC     RECORD;
  CARACTNOU numeric := 0;
  MAXANLUNA numeric := 0;
begin
  FOR V_REC IN (SELECT * FROM NCONT) LOOP
    SELECT COUNT( *)
    INTO CARACTNOU
    FROM NCONT1
    WHERE CODCONT = V_REC.CODCONT AND  ANSTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') AND  LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

    IF  CARACTNOU &gt; 0 THEN
      DELETE FROM NCONT1
      WHERE CODCONT = V_REC.CODCONT AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
    ELSE
      SELECT COALESCE( MAX( ANSTART * 12 + LUNASTART), 0)
      INTO MAXANLUNA
      FROM NCONT1
      WHERE CODCONT = V_REC.CODCONT AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

      IF  MAXANLUNA &gt; 0 THEN
        UPDATE NCONT1
        SET
        ANSTART   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999'),
        LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
        WHERE
         CODCONT = V_REC.CODCONT AND  ANSTART * 12 + LUNASTART = MAXANLUNA;

        DELETE FROM NCONT1
        WHERE CODCONT = V_REC.CODCONT AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
      END IF;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_do_curata_npart1</obj_name>
  <obj_hashval>a40589290274d4b4bbfcea9992dbe525</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_do_curata_npart1()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC     RECORD;
  CARACTNOU numeric := 0;
  MAXANLUNA numeric := 0;
begin
  FOR V_REC IN (SELECT * FROM NPART) LOOP
    SELECT COUNT( *)
    INTO CARACTNOU
    FROM NPART1
    WHERE CODPART = V_REC.CODPART AND  ANSTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') AND  LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

    IF  CARACTNOU &gt; 0 THEN
      DELETE FROM NPART1
      WHERE CODPART = V_REC.CODPART AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
    ELSE
      SELECT COALESCE( MAX( ANSTART * 12 + LUNASTART), 0)
      INTO MAXANLUNA
      FROM NPART1
      WHERE CODPART = V_REC.CODPART AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

      IF  MAXANLUNA &gt; 0 THEN
        UPDATE NPART1
        SET
        ANSTART   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE'  , true)),'999999999999999999'),
        LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
        WHERE
         CODPART = V_REC.CODPART AND  ANSTART * 12 + LUNASTART = MAXANLUNA;

        DELETE FROM NPART1
        WHERE CODPART = V_REC.CODPART AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
      END IF;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_do_curata_ntva1</obj_name>
  <obj_hashval>ffa809e92f6d88e80212c6ae63286122</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_do_curata_ntva1()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC     RECORD;
  CARACTNOU numeric := 0;
  MAXANLUNA numeric := 0;
begin
  FOR V_REC IN (SELECT * FROM NTVA) LOOP
    SELECT COUNT( *)
    INTO CARACTNOU
    FROM NTVA1
    WHERE CODTVA = V_REC.CODTVA AND  ANSTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') AND  LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

    IF  CARACTNOU &gt; 0 THEN
      DELETE FROM NTVA1
      WHERE CODTVA = V_REC.CODTVA AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
    ELSE
      SELECT COALESCE( MAX( ANSTART * 12 + LUNASTART), 0)
      INTO MAXANLUNA
      FROM NTVA1
      WHERE CODTVA = V_REC.CODTVA AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

      IF  MAXANLUNA &gt; 0 THEN
        UPDATE NTVA1
        SET
        ANSTART   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE'  , true)),'999999999999999999'),
        LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
        WHERE
         CODTVA = V_REC.CODTVA AND  ANSTART * 12 + LUNASTART = MAXANLUNA;

        DELETE FROM NTVA1
        WHERE CODTVA = V_REC.CODTVA AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
      END IF;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_do_rupere_firma</obj_name>
  <obj_hashval>506dc14d61532c0e98f8ebaa7a29dbd6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_do_rupere_firma()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM INPUTBUFFER;
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' START ');
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' SETARE LUNA LUCRU');
  PERFORM PKG_GLOBALS_SETLUNALUCRU( TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999'), TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999'));
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' MAKE CONFIG LUNA');
  PERFORM PKG_STOC_GENERARE_FACTURI_make_config_luna();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' FIXARI LUNI');
  PERFORM PKG_RUPERE_FIRMA_DO_FIXARI_LUNI();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' REFACERE CARNETE');
  PERFORM PKG_CARNETEDOC_REFACERECARNETE();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' FIXARI STOC INI');
  PERFORM FIXEAZA_STOCURI_INITIALE();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' FIXARI STOCVAL INI');
  PERFORM FIXEAZA_STOCVAL_INITIAL();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' FIXARI SOLD INI');
  PERFORM FIXEAZA_SOLDURI_INITIALE();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' REZOLVA LITIGII');
  PERFORM REZOLVA_LITIGII();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' FIXARI AVIZINT INI');
  PERFORM FIXEAZA_AVIZINT_INITIAL();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' FIXARI AVIZIES INI');
  PERFORM FIXEAZA_AVIZIES_INITIAL();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' FIXARI COMANDA1 INI');
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' SET FIRMALUNI');
  PERFORM SETEAZA_VALORI_FIRMALUNI();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' STERGE FIXARI ANTERIOARE');
  PERFORM STERGE_FIXARI_LUNARE_ANTER();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' SETEZE RESTTVA IN GENERAL');
  PERFORM SET_RESTTVA();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' STERGE DOC ANTERIOARE');
  PERFORM STERGE_DOCUMENTE_LUNI_ANTER();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' GATA  ');
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA IOART');
  PERFORM PKG_RUPERE_FIRMA_DO_CURATA_IOART();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' GATA  ');
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA IOPART');
  PERFORM PKG_RUPERE_FIRMA_DO_CURATA_IOPART();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' GATA  ');
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA IOBANK');
  PERFORM PKG_RUPERE_FIRMA_DO_CURATA_IOBANK();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' GATA  ');
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA IOFILIAL');
  PERFORM PKG_RUPERE_FIRMA_DO_CURATA_IOFILIAL();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' GATA  ');
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA NART1');
  PERFORM PKG_RUPERE_FIRMA_DO_CURATA_NART1();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' GATA  ');
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA NARTOBJ1');
  PERFORM PKG_RUPERE_FIRMA_DO_CURATA_NARTOBJ1();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' GATA  ');
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA NPART1');
  PERFORM PKG_RUPERE_FIRMA_DO_CURATA_NPART1();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' GATA  ');
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA NTVA1');
  PERFORM PKG_RUPERE_FIRMA_DO_CURATA_NTVA1();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' GATA  ');
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA NTVA1');
  PERFORM PKG_RUPERE_FIRMA_DO_CURATA_NCONT1();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' GATA  ');
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA CONSTANTE');
  PERFORM PKG_RUPERE_FIRMA_DO_CURATA_CONSTANTE();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' GATA  ');
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' REZOLVA CURS REGULARIZAT PART ');
  PERFORM DO_SOLVE_CURS_REG_PART();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' GATA  ');
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' SET FLAG INITIALIZARI LA TVAINCASARE');
  PERFORM DO_SET_FLAG_INITIALIZARI();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' GATA  ');
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' BLOCHEAZA DURATA MIFIX');
  PERFORM DO_BLOCHEAZA_DURATA_MIFIX();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' GATA  ');
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' SET INFO TVA INCASARE');
  PERFORM DO_SETINFO_TVAINCASARE();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' GATA  ');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_do_set_flag_initializari</obj_name>
  <obj_hashval>913fc0363bfa584add974f0ae9795e6a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_do_set_flag_initializari()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  UPDATE IESIRI
  SET
  INITIALIZARI = 1
  WHERE
   TVAINCASARE = 1 AND  AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

  UPDATE INTRARI
  SET
  INITIALIZARI = 1
  WHERE
   TVAINCASARE = 1 AND  AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_do_setinfo_tvaincasare</obj_name>
  <obj_hashval>c904068a73e6b3b216c2ad8222c7f67c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_do_setinfo_tvaincasare()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  FOR V_REC IN
  (
  SELECT I.*
  FROM OBLIGPIF O, GENERAL G, INTRARI I
  WHERE O.CODGENERAL = G.CODGENERAL AND  I.CODINTR = G.CODDOC AND  I.TIPDOC = G.TIPDOC AND  G.SEMNIFICATIE = 100 AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999') AND  I.TVAINCASARE = 1 AND I.INITIALIZARI IS NULL
  )
  LOOP
    UPDATE INTRARI SET INITIALIZARI = 1 WHERE CODINTR = V_REC.CODINTR;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_do_solve_curs_reg_part</obj_name>
  <obj_hashval>13bfaad45cbaf37f8cd1a4d3faae606c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_do_solve_curs_reg_part()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  FOR V_REC IN
  (
  SELECT R.CODREG, R1.CODREG1, R1.CODGENERAL, R.CURS
  FROM REG R, REG1 R1
  WHERE TIPREG = 46 AND  R1.CODREG = R.CODREG AND  AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
  ORDER BY AN , LUNA
  )
  LOOP
    UPDATE GENERAL SET CURS = V_REC.CURS WHERE CODGENERAL = V_REC.CODGENERAL;
    DELETE FROM REG1 WHERE CODREG1 = V_REC.CODREG1;
  END LOOP;

  DELETE FROM REG
  WHERE TIPREG = 46 AND  AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_fixeaza_avizies_initial</obj_name>
  <obj_hashval>83085d1a4cf1d3fb8f9007b95d196b5d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_fixeaza_avizies_initial()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC        RECORD;
  V_RECIESLINK RECORD;
  aREST        double precision;
  NR           numeric;
begin
  FOR V_REC IN
  (
  SELECT I1.CODIES1, I.CODIES
  FROM IESIRI1 I1, IESIRI I
  WHERE I1.CODIES = I.CODIES AND  I.TIPDOC = 20 AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
  )
  LOOP
    BEGIN
      SELECT COALESCE( REST, 0)
      INTO aREST
      FROM AVIZIESLUNA
      WHERE CODIES1 = V_REC.CODIES1 AND  AN = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999') AND  LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999');
    EXCEPTION WHEN OTHERS THEN
      aREST := 0;
    END;

    UPDATE IESIRI1
    SET
    TVA      = ROUND( AREST * TVA / CASE WHEN  CANT=0 THEN 1 ELSE  CANT END , 2),
    CANT     = aREST,
    RESTFACT = aREST
    WHERE
     CODIES1 = V_REC.CODIES1;

    UPDATE IESIRI
    SET
    AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
    LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
    WHERE
     CODIES = V_REC.CODIES;

    FOR V_RECIESLINK IN
    (
    SELECT I1.CODIES1, I.CODIES
    FROM IESLINK IL, IESIRI1 I1, IESIRI I
    WHERE IL.CODLINIEAVIZ = V_REC.CODIES1 AND  IL.CODIES1 = I1.CODIES1 AND  I1.CODIES = I.CODIES AND  I.TIPDOC = 26 AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
    )
    LOOP
      DELETE FROM IESLINK WHERE CODIES1 = V_RECIESLINK.CODIES1;
      DELETE FROM IESIRI1 WHERE CODIES1 = V_RECIESLINK.CODIES1;

      UPDATE IESIRI
      SET
      AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
      LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
      WHERE
       CODIES = V_RECIESLINK.CODIES;
    END LOOP;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_fixeaza_avizint_initial</obj_name>
  <obj_hashval>d31f0389db3a04ea0190a3b0b46531d9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_fixeaza_avizint_initial()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC        RECORD;
  V_RECINTLINK RECORD;
  aREST        double precision;
  NR           numeric;
begin
  FOR V_REC IN
  (
  SELECT I1.CODINTR1, I.CODINTR
  FROM INTRARI1 I1, INTRARI I
  WHERE I1.CODINTR = I.CODINTR AND  I.TIPDOC = 2 AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
  )
  LOOP
    BEGIN
      SELECT COALESCE( REST, 0)
      INTO aREST
      FROM AVIZINTLUNA
      WHERE CODINTR1 = V_REC.CODINTR1 AND  AN = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999') AND  LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999');
    EXCEPTION WHEN OTHERS THEN
      aREST := 0;
    END;

  UPDATE INTRARI1
  SET
  TVA      = ROUND( AREST * TVA / CASE WHEN  CANT=0 THEN 1 ELSE  CANT END , 2),
  CANT     = aREST,
  RESTFACT = aREST
  WHERE
   CODINTR1 = V_REC.CODINTR1;

  UPDATE INTRARI
  SET
  AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
  LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
  WHERE
   CODINTR = V_REC.CODINTR;

  FOR V_RECINTLINK IN
  (
  SELECT I1.CODINTR1, I.CODINTR
  FROM INTRLINK IL, INTRARI1 I1, INTRARI I
  WHERE
     IL.CODLINIEAVIZ = V_REC.CODINTR1 AND  IL.CODINTR1 = I1.CODINTR1 AND  I1.CODINTR = I.CODINTR AND  I.TIPDOC = 9 AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
  )
  LOOP
    DELETE FROM INTRLINK WHERE CODINTR1 = V_RECINTLINK.CODINTR1;

    BEGIN
      DELETE FROM INTRARI1 WHERE CODINTR1 = V_RECINTLINK.CODINTR1;
    EXCEPTION WHEN OTHERS THEN
      UPDATE INTRARI1 SET CANT = 0 WHERE CODINTR1 = V_RECINTLINK.CODINTR1;
    END;

    UPDATE INTRARI
    SET
    AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
    LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
    WHERE
     CODINTR = V_RECINTLINK.CODINTR;
    END LOOP;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_fixeaza_comanda1_initial</obj_name>
  <obj_hashval>98e7c7dbc80fa1d485eccd2a52db4f28</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_fixeaza_comanda1_initial()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC           RECORD;
  V_RECINTLINK    RECORD;
  V_RECIESLINK    RECORD;
  V_RECTRANSFLINK RECORD;
  aREST           double precision;
  NR              numeric;
begin
  FOR V_REC IN (SELECT C1.CODCOMANDA1, C.CODCOMANDA, C.TIPDOC
                FROM COMANDA1 C1, COMANDA C
                WHERE C1.CODCOMANDA = C.CODCOMANDA AND  C.AN * 12 + C.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
               )
  LOOP
    BEGIN
      SELECT COALESCE( REST, 0)
      INTO aREST
      FROM COMANDA1LUNA
      WHERE CODCOMANDA1 = V_REC.CODCOMANDA1 AND  AN = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999') AND  LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999');
    EXCEPTION WHEN OTHERS THEN
      aREST := 0;
    END;

    UPDATE COMANDA1
    SET
    CANTACCEPTAT = aREST,
    RESTACCEPTAT = aREST
    WHERE
     CODCOMANDA1 = V_REC.CODCOMANDA1;

    UPDATE COMANDA
    SET
    AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
    LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
    WHERE
     CODCOMANDA = V_REC.CODCOMANDA;

    FOR V_RECINTLINK IN
    (
    SELECT I1.CODINTR1, I.CODINTR
    FROM INTRLINK IL, INTRARI1 I1, INTRARI I
    WHERE IL.CODLINIECOMANDA = V_REC.CODCOMANDA1 AND  IL.CODINTR1 = I1.CODINTR1 AND  I1.CODINTR = I.CODINTR AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
    )
    LOOP
      DELETE FROM INTRLINK WHERE CODINTR1 = V_RECINTLINK.CODINTR1;

      UPDATE INTRARI
      SET
      AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
      LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
      WHERE
       CODINTR = V_RECINTLINK.CODINTR;
    END LOOP;

    FOR V_RECIESLINK IN
    (
    SELECT I1.CODIES1, I.CODIES
    FROM IESLINK IL, IESIRI1 I1, IESIRI I
    WHERE IL.CODLINIECOMANDA = V_REC.CODCOMANDA1 AND  IL.CODIES1 = I1.CODIES1 AND  I1.CODIES = I.CODIES AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
    )
    LOOP
      DELETE FROM IESLINK WHERE CODIES1 = V_RECIESLINK.CODIES1;

      UPDATE IESIRI
      SET
      AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
      LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
      WHERE
       CODIES = V_RECIESLINK.CODIES;
    END LOOP;

    FOR V_RECTRANSFLINK IN
    (
    SELECT T1.CODTRANSF1, T.CODTRANSF
    FROM TRANSFLINK TL, TRANSF1 T1, TRANSF T
    WHERE TL.CODLINIECOMANDA = V_REC.CODCOMANDA1 AND  TL.CODTRANSF1 = T1.CODTRANSF1 AND  T1.CODTRANSF = T.CODTRANSF AND  T.AN * 12 + T.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
    )
    LOOP
      DELETE FROM TRANSFLINK WHERE CODTRANSF1 = V_RECTRANSFLINK.CODTRANSF1;

      UPDATE TRANSF
      SET
      AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
      LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
      WHERE
       CODTRANSF = V_RECTRANSFLINK.CODTRANSF;
    END LOOP;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_fixeaza_startnr</obj_name>
  <obj_hashval>16e1053a0d3ce3f602e71454921593f5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_fixeaza_startnr()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC         RECORD;
  NR_ANTERIOR   numeric := 0;
  NR_ULTERIOR   numeric := 0;
  NEXT_NRDOC    numeric := 0;
  vAnLunaRupere numeric;
BEGIN
  vAnLunaRupere := TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

  FOR V_REC IN (SELECT * FROM DOCCARNETE) LOOP
    DELETE FROM TMP_USED_ANTERIOR;
    DELETE FROM TMP_USED_ULTERIOR;

    INSERT INTO TMP_USED_ANTERIOR(NRDOC)
    SELECT NRDOC FROM IESIRI WHERE AN * 12 + LUNA &lt; vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ULTERIOR(NRDOC)
    SELECT NRDOC NR_ANTERIOR FROM IESIRI WHERE AN * 12 + LUNA &gt;= vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ANTERIOR(NRDOC)
    SELECT NRDOC FROM COMANDA WHERE AN * 12 + LUNA &lt; vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ULTERIOR(NRDOC)
    SELECT NRDOC NR_ANTERIOR FROM COMANDA WHERE AN * 12 + LUNA &gt;= vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ANTERIOR(NRDOC)
    SELECT NRDOC FROM TRANSF WHERE AN * 12 + LUNA &lt; vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ULTERIOR(NRDOC)
    SELECT NRDOC NR_ANTERIOR FROM TRANSF WHERE AN * 12 + LUNA &gt;= vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ANTERIOR(NRDOC)
    SELECT NRDOC FROM COMPENS WHERE AN * 12 + LUNA &lt; vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ULTERIOR(NRDOC)
    SELECT NRDOC NR_ANTERIOR FROM COMPENS WHERE AN * 12 + LUNA &gt;= vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ANTERIOR(NRDOC)
    SELECT NRDOC FROM NC WHERE AN * 12 + LUNA &lt; vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ULTERIOR(NRDOC)
    SELECT NRDOC NR_ANTERIOR FROM NC WHERE AN * 12 + LUNA &gt;= vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ANTERIOR(NRDOC)
    SELECT NRDOC FROM TREZOR1 WHERE AN * 12 + LUNA &lt; vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ULTERIOR(NRDOC)
    SELECT NRDOC NR_ANTERIOR FROM TREZOR1 WHERE AN * 12 + LUNA &gt;= vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ANTERIOR(NRDOC)
    SELECT NRDOC FROM PACHETE WHERE AN * 12 + LUNA &lt; vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ULTERIOR(NRDOC)
    SELECT NRDOC NR_ANTERIOR FROM PACHETE WHERE AN * 12 + LUNA &gt;= vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ANTERIOR(NRDOC)
    SELECT NRDOC FROM OFERTA WHERE AN * 12 + LUNA &lt; vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ULTERIOR(NRDOC)
    SELECT NRDOC NR_ANTERIOR FROM OFERTA WHERE AN * 12 + LUNA &gt;= vAnLunaRupere AND  CARNETDOC = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ANTERIOR(NRDOC)
    SELECT NRLIVR FROM LIVR L, IESIRI I WHERE L.CODIES = I.CODIES AND  L.TIPLIVR = I.TIPDOC AND  I.AN * 12 + I.LUNA &lt; vAnLunaRupere AND  CARNETLIVR = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ULTERIOR(NRDOC)
    SELECT NRLIVR FROM LIVR L, IESIRI I WHERE L.CODIES = I.CODIES AND  L.TIPLIVR = I.TIPDOC AND  I.AN * 12 + I.LUNA &gt;= vAnLunaRupere AND  CARNETLIVR = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ANTERIOR(NRDOC)
    SELECT NRLIVR FROM LIVR L, TRANSF T WHERE L.CODTRANSF = T.CODTRANSF AND  L.TIPLIVR = T.TIPDOC AND  T.AN * 12 + T.LUNA &lt; vAnLunaRupere AND  CARNETLIVR = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ULTERIOR(NRDOC)
    SELECT NRLIVR FROM LIVR L, TRANSF T WHERE L.CODTRANSF = T.CODTRANSF AND  L.TIPLIVR = T.TIPDOC AND  T.AN * 12 + T.LUNA &gt;= vAnLunaRupere AND  CARNETLIVR = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ANTERIOR(NRDOC)
    SELECT NRLIVR FROM LIVR L, INTRARI I WHERE L.CODINTR = I.CODINTR AND  L.TIPLIVR = I.TIPDOC AND  I.AN * 12 + I.LUNA &lt; vAnLunaRupere AND  CARNETLIVR = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ULTERIOR(NRDOC)
    SELECT NRLIVR FROM LIVR L, INTRARI I WHERE L.CODINTR = I.CODINTR AND  L.TIPLIVR = I.TIPDOC AND  I.AN * 12 + I.LUNA &gt;= vAnLunaRupere AND  CARNETLIVR = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ANTERIOR(NRDOC)
    SELECT NRNIR FROM NIR N, IESIRI I WHERE N.CODIES = I.CODIES AND  N.TIPNIR = I.TIPDOC AND  I.AN * 12 + I.LUNA &lt; vAnLunaRupere AND  CARNETNIR = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ULTERIOR(NRDOC)
    SELECT NRNIR FROM NIR N, IESIRI I WHERE N.CODIES = I.CODIES AND  N.TIPNIR = I.TIPDOC AND  I.AN * 12 + I.LUNA &gt;= vAnLunaRupere AND  CARNETNIR = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ANTERIOR(NRDOC)
    SELECT NRNIR FROM NIR N, INTRARI I WHERE N.CODINTR = I.CODINTR AND  N.TIPNIR = I.TIPDOC AND  I.AN * 12 + I.LUNA &lt; vAnLunaRupere AND  CARNETNIR = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ULTERIOR(NRDOC)
    SELECT NRNIR FROM NIR N, INTRARI I WHERE N.CODINTR = I.CODINTR AND  N.TIPNIR = I.TIPDOC AND  I.AN * 12 + I.LUNA &gt;= vAnLunaRupere AND  CARNETNIR = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ANTERIOR(NRDOC)
    SELECT NRNIR FROM NIR N, TRANSF T WHERE N.CODTRANSF = T.CODTRANSF AND  N.TIPNIR = T.TIPDOC AND  T.AN * 12 + T.LUNA &lt; vAnLunaRupere AND  CARNETNIR = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ULTERIOR(NRDOC)
    SELECT NRNIR FROM NIR N, TRANSF T WHERE N.CODTRANSF = T.CODTRANSF AND  N.TIPNIR = T.TIPDOC AND  T.AN * 12 + T.LUNA &gt;= vAnLunaRupere AND  CARNETNIR = V_REC.CODCARNET;

    NEXT_NRDOC := 0;
    SELECT COALESCE( MAX( NRDOC), 0) INTO NR_ANTERIOR FROM TMP_USED_ANTERIOR;
    SELECT COALESCE( MIN( NRDOC), 0) INTO NR_ULTERIOR FROM TMP_USED_ULTERIOR;

    IF  NR_ULTERIOR = 0 THEN
      NEXT_NRDOC := NR_ANTERIOR + 1;
    ELSE
      IF  NR_ULTERIOR &gt; NR_ANTERIOR AND  NR_ANTERIOR &lt;&gt; 0 AND  INTERVAL_CONTINUU = 0 THEN
        NEXT_NRDOC := NR_ULTERIOR;
      END IF;
    END IF;

    IF  NEXT_NRDOC &lt;&gt; 0 THEN
      UPDATE DOCCARNETE
      SET
      STARTNRINI = STARTNR,
      STARTNR    = NEXT_NRDOC
      WHERE
       CODCARNET = V_REC.CODCARNET;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_fixeaza_stocuri_initiale</obj_name>
  <obj_hashval>a34f6bf602401816a04fea1fcba4a48b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_fixeaza_stocuri_initiale()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC       RECORD;
  V_REC_SER   RECORD;
  V_RECLIVR   RECORD;
  aREST       double precision;
  aRESTUM1    double precision;
  aRESTUM2    double precision;
  aRESTSER    double precision;
  aRESTSERUM1 double precision;
  aRESTSERUM2 double precision;
  NR          numeric;
begin
  DELETE FROM STOCINI;
  FOR V_REC IN
  (
  SELECT NS.CODNIRSTOC, N.GEST, I.CODINTR, E.CODIES, T.CODTRANSF,
         (CASE WHEN I.CODINTR IS NOT NULL  THEN I.AN
               WHEN E.CODIES IS NOT NULL  THEN E.AN
               WHEN T.CODTRANSF IS NOT NULL  THEN T.AN
          END )  AS AN,
         (CASE WHEN I.CODINTR IS NOT NULL  THEN I.LUNA
               WHEN E.CODIES IS NOT NULL  THEN E.LUNA
               WHEN T.CODTRANSF IS NOT NULL  THEN T.LUNA
          END )  AS LUNA
  FROM NIRSTOC NS
      LEFT JOIN TMP_IOART_LUNA IO ON  IO.CODIOART = NS.CODIOART, NIR N
      LEFT JOIN INTRARI        I  ON  I.CODINTR   = N.CODINTR AND  I.TIPDOC = N.TIPNIR
      LEFT JOIN TRANSF         T  ON  T.CODTRANSF = N.CODTRANSF AND  T.TIPDOC = N.TIPNIR
      LEFT JOIN IESIRI         E  ON  E.CODIES    = N.CODIES AND  E.TIPDOC = N.TIPNIR
  WHERE N.CODNIR = NS.CODNIR AND  COALESCE( IO.MG, 0) &lt;&gt; 5
  )
  LOOP
    IF  V_REC.AN * 12 + V_REC.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
    THEN
      BEGIN
        SELECT COALESCE( REST, 0), COALESCE( RESTUM1, 0), COALESCE( RESTUM2, 0)
        INTO aREST, aRESTUM1, aRESTUM2
        FROM NIRLUNA
        WHERE CODNIRSTOC = V_REC.CODNIRSTOC AND  AN = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999') AND  LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999');
      EXCEPTION WHEN OTHERS THEN
        aREST    := 0;
        aRESTUM1 := 0;
        aRESTUM2 := 0;
      END;

      UPDATE NIRSTOC
      SET
      CANTNIR = aREST,
      CANTUM1 = aRESTUM1,
      CANTUM2 = aRESTUM2
      WHERE
       CODNIRSTOC = V_REC.CODNIRSTOC;

      FOR V_REC_SER IN (SELECT * FROM NIRSER WHERE CODNIRSTOC = V_REC.CODNIRSTOC) LOOP
        BEGIN
          SELECT COALESCE( REST, 0), COALESCE( RESTUM1, 0), COALESCE( RESTUM2, 0)
          INTO aRESTSER, aRESTSERUM1, aRESTSERUM2
          FROM NIRSERLUNA
          WHERE CODNIRSER = V_REC_SER.CODNIRSER AND  AN = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999') AND  LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999');
        EXCEPTION WHEN OTHERS THEN
          aRESTSER := 0;
          aRESTSERUM1 := 0;
          aRESTSERUM2 := 0;
        END;

        UPDATE NIRSER
        SET
        CANTNIR = aRESTSER,
        CANTUM1 = aRESTSERUM1,
        CANTUM2 = aRESTSERUM2
        WHERE
         CODNIRSER = V_REC_SER.CODNIRSER;
      END LOOP;

      IF  aREST + aRESTUM1 + aRESTUM2 &lt;&gt; 0 THEN
        SELECT COUNT( *) INTO NR FROM STOCINI WHERE CODGEST = V_REC.GEST;
        IF  NR = 0 THEN
          INSERT INTO STOCINI(CODSTOCINI, CODGEST) VALUES(NEXTVAL('SEQ_STOCINI_CODSTOCINI'), V_REC.GEST);
        END IF;
      END IF;

      IF V_REC.CODINTR IS NOT NULL THEN
        UPDATE INTRARI
        SET
        AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
        LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
        WHERE
         CODINTR = V_REC.CODINTR;
      END IF;

      IF V_REC.CODIES IS NOT NULL THEN
        UPDATE IESIRI
        SET
        AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
        LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
        WHERE
         CODIES = V_REC.CODIES;
      END IF;

      IF V_REC.CODTRANSF IS NOT NULL THEN
        UPDATE TRANSF
        SET
        AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
        LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
        WHERE
         CODTRANSF = V_REC.CODTRANSF;
      END IF;

      FOR V_RECLIVR IN (SELECT CODLIVR1, I.CODINTR, E.CODIES, T.CODTRANSF,
                               (CASE WHEN I.CODINTR IS NOT NULL  THEN I.AN
                                     WHEN E.CODIES IS NOT NULL  THEN E.AN
                                     WHEN T.CODTRANSF IS NOT NULL  THEN T.AN
                                END )  AS AN,
                               (CASE WHEN I.CODINTR IS NOT NULL  THEN I.LUNA
                                     WHEN E.CODIES IS NOT NULL  THEN E.LUNA
                                     WHEN T.CODTRANSF IS NOT NULL  THEN T.LUNA
                                END )  AS LUNA
                        FROM LIVR1 L1, LIVR L
                            LEFT JOIN INTRARI I ON  I.CODINTR   = L.CODINTR AND  I.TIPDOC = L.TIPLIVR
                            LEFT JOIN TRANSF  T ON  T.CODTRANSF = L.CODTRANSF AND  T.TIPDOC = L.TIPLIVR
                            LEFT JOIN IESIRI  E ON  E.CODIES    = L.CODIES AND  E.TIPDOC = L.TIPLIVR
                        WHERE CODNIRSTOC = V_REC.CODNIRSTOC AND  L.CODLIVR = L1.CODLIVR
                       )
      LOOP
        IF  V_RECLIVR.AN * 12 + V_RECLIVR.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
        THEN
          UPDATE LIVR1
          SET
          CANT    = 0,
          CANTUM1 = 0,
          CANTUM2 = 0
          WHERE
           CODLIVR1 = V_RECLIVR.CODLIVR1;

          IF V_RECLIVR.CODINTR IS NOT NULL THEN
            UPDATE INTRARI
            SET
            AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
            LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
            WHERE
             CODINTR = V_RECLIVR.CODINTR;
          END IF;

          IF V_RECLIVR.CODIES IS NOT NULL THEN
            UPDATE IESIRI
            SET
            AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
            LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
            WHERE
             CODIES = V_RECLIVR.CODIES;
          END IF;

          IF V_RECLIVR.CODTRANSF IS NOT NULL THEN
            UPDATE TRANSF
            SET
            AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999'),
            LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
            WHERE
             CODTRANSF = V_RECLIVR.CODTRANSF;
          END IF;
        END IF;
      END LOOP;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_fixeaza_stocval_initial</obj_name>
  <obj_hashval>95ee3bee036344301c522d8e345977a3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_fixeaza_stocval_initial()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC    RECORD;
  aREST    double precision;
  aRESTUM1 double precision;
  aRESTUM2 double precision;
  NR       numeric;
  ERR      numeric := 0;
begin
  DELETE FROM STOCVALINI;

  FOR V_REC IN (SELECT GEST FROM STOCVALLUNA
                WHERE AN = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999') AND  LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
               )
  LOOP
    INSERT INTO STOCVALINI(CODSTOCVALINI, GEST) VALUES(NEXTVAL('SEQ_STOCVALINI_CODSTOCVALINI'), V_REC.GEST);
  END LOOP;

  FOR V_REC IN
  (
  SELECT NS.CODNIRSTOC, N.GEST, I.CODINTR, E.CODIES, T.CODTRANSF,
         (CASE WHEN I.CODINTR IS NOT NULL  THEN I.AN
               WHEN E.CODIES IS NOT NULL  THEN E.AN
               WHEN T.CODTRANSF IS NOT NULL  THEN T.AN
          END )  AS AN,
         (CASE WHEN I.CODINTR IS NOT NULL  THEN I.LUNA
               WHEN E.CODIES IS NOT NULL  THEN E.LUNA
               WHEN T.CODTRANSF IS NOT NULL  THEN T.LUNA
          END )  AS LUNA
  FROM NIRSTOC NS
      LEFT JOIN TMP_IOART_LUNA IO ON  IO.CODIOART = NS.CODIOART, NIR N
      LEFT JOIN INTRARI        I  ON  I.CODINTR   = N.CODINTR   AND  I.TIPDOC = N.TIPNIR
      LEFT JOIN TRANSF         T  ON  T.CODTRANSF = N.CODTRANSF AND  T.TIPDOC = N.TIPNIR
      LEFT JOIN IESIRI         E  ON  E.CODIES    = N.CODIES    AND  E.TIPDOC = N.TIPNIR
  WHERE N.CODNIR = NS.CODNIR AND  COALESCE( IO.MG, 0) = 5
  )
  LOOP
    IF  V_REC.AN * 12 + V_REC.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
    THEN
      IF V_REC.CODINTR IS NOT NULL THEN
        UPDATE INTRARI
        SET
        AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999'),
        LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
        WHERE
         CODINTR = V_REC.CODINTR;
      END IF;

      IF V_REC.CODIES IS NOT NULL THEN
        UPDATE IESIRI
        SET
        AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999'),
        LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
        WHERE
         CODIES = V_REC.CODIES;
      END IF;

      IF V_REC.CODTRANSF IS NOT NULL THEN
        UPDATE TRANSF
        SET
        AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999'),
        LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
        WHERE
         CODTRANSF = V_REC.CODTRANSF;
      END IF;

      BEGIN
        DELETE FROM NIRSER  WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
        DELETE FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
      EXCEPTION WHEN OTHERS THEN
        ERR := ERR + 1;
      END;
    END IF;
  END LOOP;

  FOR V_REC IN
  (
  SELECT LV.CODLIVRVAL, LV.CODLIVR1, I.CODINTR, E.CODIES, T.CODTRANSF,
         ( CASE WHEN I.CODINTR   IS NOT NULL  THEN I.AN
                 WHEN E.CODIES    IS NOT NULL  THEN E.AN
                 WHEN T.CODTRANSF IS NOT NULL  THEN T.AN
           END )  AS AN,
         ( CASE WHEN I.CODINTR   IS NOT NULL  THEN I.LUNA
                WHEN E.CODIES    IS NOT NULL  THEN E.LUNA
                 WHEN T.CODTRANSF IS NOT NULL  THEN T.LUNA
           END )  AS LUNA
  FROM LIVRVAL LV, LIVR1 L1, LIVR L
      LEFT JOIN INTRARI I ON  I.CODINTR   = L.CODINTR   AND  I.TIPDOC = L.TIPLIVR
      LEFT JOIN IESIRI  E ON  E.CODIES    = L.CODIES    AND  E.TIPDOC = L.TIPLIVR
      LEFT JOIN TRANSF  T ON  T.CODTRANSF = L.CODTRANSF AND  T.TIPDOC = L.TIPLIVR
  WHERE LV.CODLIVR1 = L1.CODLIVR1 AND  L1.CODLIVR = L.CODLIVR
  )
  LOOP
    IF  V_REC.AN * 12 + V_REC.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
    THEN
      IF V_REC.CODINTR IS NOT NULL THEN
        UPDATE INTRARI
        SET
        AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999'),
        LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
        WHERE
         CODINTR = V_REC.CODINTR;
      END IF;

      IF V_REC.CODIES IS NOT NULL THEN
        UPDATE IESIRI
        SET
        AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999'),
        LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
        WHERE
         CODIES = V_REC.CODIES;
      END IF;

      IF V_REC.CODTRANSF IS NOT NULL THEN
        UPDATE TRANSF
        SET
        AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999'),
        LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
        WHERE
         CODTRANSF = V_REC.CODTRANSF;
      END IF;

      BEGIN
        DELETE FROM LIVRVAL WHERE CODLIVRVAL = V_REC.CODLIVRVAL;
        DELETE FROM LIVR1   WHERE CODLIVR1 = V_REC.CODLIVR1;
      EXCEPTION WHEN OTHERS THEN
        ERR := ERR + 1;
      END;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_getluna_rupere</obj_name>
  <obj_hashval>4b31b329f989ebead11ad6fe097b95a3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_getluna_rupere(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_interval_continuu</obj_name>
  <obj_hashval>85dde13da7e6ed17b8a6114c26d65a48</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_interval_continuu(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  aNR   numeric := 0;
begin
  SELECT COALESCE( MIN( NRDOC), 0) INTO aNR FROM TMP_USED_ULTERIOR;

  FOR V_REC IN (SELECT * FROM TMP_USED_ULTERIOR ORDER BY NRDOC) LOOP
    IF  V_REC.NRDOC - aNR &gt; 1 THEN
      WME_Result :=  0;
      RETURN;
    ELSE
      aNR := V_REC.NRDOC;
    END IF;
  END LOOP;

  WME_Result :=  1;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_luna_initializari</obj_name>
  <obj_hashval>b4a301321f588d2aacc54334af5220ac</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_luna_initializari(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_luna_rupere</obj_name>
  <obj_hashval>11d37ab993cd7b668e063edb25882ae2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_luna_rupere(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_repara_incoerenta_iconturi</obj_name>
  <obj_hashval>ddb299fc2154dbe57ac1d648ea685067</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_repara_incoerenta_iconturi()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  FOR V_REC IN
  (
  SELECT OSTINGATOR.CODOBLIGPIF AS CODOBLIGSTINGATOR, OSTINS.ICONT AS ICONTSTINS, OSTINGATOR.ICONT AS ICONTSTINGATOR, S.VALOARE
  FROM STINGERE S, OBLIGPIF OSTINS, OBLIGPIF OSTINGATOR
  WHERE S.CODSTINSPIF = OSTINS.CODOBLIGPIF AND  S.CODSTINGATORPIF = OSTINGATOR.CODOBLIGPIF AND  OSTINS.ICONT &lt;&gt; OSTINGATOR.ICONT
  )
  LOOP
    UPDATE OBLIGPIF SET ICONT = V_REC.ICONTSTINS WHERE CODOBLIGPIF = V_REC.CODOBLIGSTINGATOR;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_repara_rest_obligpif_initial</obj_name>
  <obj_hashval>eba8598e7b856a25769ef0351caaf638</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_repara_rest_obligpif_initial(aninitial numeric, lunainitiala numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  FOR V_REC IN
  (
  SELECT O.CODOBLIGPIF, O.VALOARE, I.AN, I.LUNA
  FROM OBLIGPIF O, GENERAL G, INTRARI I
  WHERE O.CODGENERAL = G.CODGENERAL AND O.SEMNIFICATIE IN (100, 110, 140, 130) AND  I.TIPDOC = G.TIPDOC AND  I.CODINTR = G.CODDOC AND  I.AN * 12 + I.LUNA &lt; ANINITIAL * 12 + LUNAINITIALA
  )
  LOOP
    DELETE FROM OBLIGPIFLUNA WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF AND  AN = V_REC.AN AND  LUNA = V_REC.LUNA;
    INSERT INTO OBLIGPIFLUNA(CODOBLIGPIF, AN, LUNA, REST)
    VALUES(V_REC.CODOBLIGPIF, V_REC.AN, V_REC.LUNA, V_REC.VALOARE);
  END LOOP;

  FOR V_REC IN
  (
  SELECT O.CODOBLIGPIF, O.VALOARE, I.AN, I.LUNA
  FROM OBLIGPIF O, GENERAL G, IESIRI I
  WHERE O.CODGENERAL = G.CODGENERAL AND O.SEMNIFICATIE IN (200, 210, 240) AND  I.TIPDOC = G.TIPDOC AND  I.CODIES = G.CODDOC AND  I.AN * 12 + I.LUNA &lt; ANINITIAL * 12 + LUNAINITIALA
  )
  LOOP
    DELETE FROM OBLIGPIFLUNA WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF AND  AN = V_REC.AN AND  LUNA = V_REC.LUNA;
    INSERT INTO OBLIGPIFLUNA(CODOBLIGPIF, AN, LUNA, REST)
    VALUES(V_REC.CODOBLIGPIF, V_REC.AN, V_REC.LUNA, V_REC.VALOARE);
  END LOOP;

  FOR V_REC IN
  (
  SELECT O.CODOBLIGPIF, O.VALOARE, T1.AN, T1.LUNA
  FROM OBLIGPIF O, GENERAL G, TREZOR1 T1
  WHERE O.CODGENERAL = G.CODGENERAL AND O.SEMNIFICATIE IN (310, 330, 410, 430, 500, 600) AND G.TIPDOC IN (29, 30, 31, 33) AND  T1.CODTREZOR1 = G.CODDOC AND  T1.AN * 12 + T1.LUNA &lt; ANINITIAL * 12 + LUNAINITIALA
  )
  LOOP
    DELETE FROM OBLIGPIFLUNA WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF AND  AN = V_REC.AN AND  LUNA = V_REC.LUNA;
    INSERT INTO OBLIGPIFLUNA(CODOBLIGPIF, AN, LUNA, REST)
    VALUES(V_REC.CODOBLIGPIF, V_REC.AN, V_REC.LUNA, V_REC.VALOARE);
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_rezolva_litigii</obj_name>
  <obj_hashval>1e6929b12c6b83257e07da17fe311743</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_rezolva_litigii()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC           RECORD;
  CODASOCINI      numeric;
  CODFACTURA      numeric;
  CODLASTSTINGERE numeric;
begin
  FOR V_REC IN
  (
  SELECT O.CODOBLIGPIF, O.CODOBLIGASOCIAT, O.CODGENERAL, C.AN, C.LUNA, C.CODCOMPENS, O.REST
  FROM OBLIGPIF O
      LEFT JOIN GENERAL G ON  G.CODGENERAL = O.CODGENERAL
      LEFT JOIN COMPENS C ON  C.CODCOMPENS = G.CODDOC
  WHERE O.SEMNIFICATIE = 1303 AND  O.REST &lt;&gt; 0 AND  C.AN * 12 + C.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
  )
  LOOP
    CODASOCINI := V_REC.CODOBLIGASOCIAT;
    CODFACTURA := (SELECT PKG_RUPERE_FIRMA_GETCODFACTURALITIGIU.WME_RESULT FROM PKG_RUPERE_FIRMA_GETCODFACTURALITIGIU(NULL, V_REC.CODOBLIGASOCIAT));

    IF  CODASOCINI &lt;&gt; CODFACTURA AND  CODFACTURA &lt;&gt; 0 THEN
      UPDATE OBLIGPIF SET CODOBLIGASOCIAT = CODFACTURA WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;

      BEGIN
        SELECT S.CODSTINGERE
        INTO CODLASTSTINGERE
        FROM GENERAL G_LITIGIU, GENERAL G_STINGATOR, OBLIGPIF O_STINGATOR, STINGERE S
        WHERE  G_LITIGIU.CODGENERAL = V_REC.CODGENERAL AND  G_STINGATOR.CODDOC = G_LITIGIU.CODDOC AND  G_STINGATOR.TIPDOC = 28 AND  G_STINGATOR.SEMNIFICATIE = 1350
          AND  O_STINGATOR.CODGENERAL = G_STINGATOR.CODGENERAL AND  S.CODSTINGATORPIF = O_STINGATOR.CODOBLIGPIF AND  S.CODSTINSPIF = V_REC.CODOBLIGASOCIAT;
      END;

      UPDATE STINGERE
      SET
      CODSTINSPIF = CODFACTURA,
      VALOARE = V_REC.REST
      WHERE CODSTINGERE = CODLASTSTINGERE;

      UPDATE OBLIGPIF SET VALOARE = V_REC.REST WHERE CODOBLIGPIF = CODFACTURA;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_set_resttva</obj_name>
  <obj_hashval>b2f6779fc7c8f3e7ed89ca1877007bd2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_set_resttva()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  FOR V_REC IN
  (
  SELECT G.CODGENERAL, OL.RESTTVA
  FROM OBLIGPIFLUNA OL, OBLIGPIF O, GENERAL G
  WHERE OL.AN * 12 + OL.LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999') AND  O.CODOBLIGPIF = OL.CODOBLIGPIF AND  G.CODGENERAL = O.CODGENERAL AND G.SEMNIFICATIE IN (310, 410)
  )
  LOOP
    UPDATE GENERAL SET TVA = COALESCE( V_REC.RESTTVA, 0) WHERE CODGENERAL = V_REC.CODGENERAL;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_setan_rupere</obj_name>
  <obj_hashval>00331d88d93e3890606f0ab027e0c5ce</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_setan_rupere(aan_rupere numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_RUPERE_FIRMA.AN_RUPERE',to_char(aAN_RUPERE,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_setanlunarupere</obj_name>
  <obj_hashval>8ea99d8528d5009d21abc318ba1096e4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_setanlunarupere(aan numeric, aluna numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vAN_INITIALIZARI   numeric;
  vLUNA_INITIALIZARI numeric;
BEGIN
  --Adina 15.07.2021 - add vAN_INITIALIZARI, vLUNA_INITIALIZARI
  perform set_config('PKG_RUPERE_FIRMA.AN_RUPERE'  ,to_char(aAN  ,'999999999999999999'),false);
  perform set_config('PKG_RUPERE_FIRMA.LUNA_RUPERE',to_char(aLUNA,'999999999999999999'),false);
  PERFORM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999'), TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999'), vAN_INITIALIZARI, vLUNA_INITIALIZARI);
  perform set_config('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  ,to_char(vAN_INITIALIZARI  ,'999999999999999999'),false);
  perform set_config('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI',to_char(vLUNA_INITIALIZARI,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_seteaza_valori_firmaluni</obj_name>
  <obj_hashval>bf6b3b197cbeb1f77095739e3a2d9f5b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_seteaza_valori_firmaluni()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  UPDATE FIRMALUNI
  SET
  ANINITIAL    = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE'  , true)),'999999999999999999'),
  LUNAINITIALA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_setluna_rupere</obj_name>
  <obj_hashval>7c8cd7fdc1e50cb942dd5093b8ddb32e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_setluna_rupere(aluna_rupere numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_RUPERE_FIRMA.LUNA_RUPERE',to_char(aLUNA_RUPERE,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_sterge_documente_luni_anter</obj_name>
  <obj_hashval>03c1bf4e0953c49750bf3b5f624d0caf</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_sterge_documente_luni_anter()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA LIVR1');
  PERFORM PKG_RUPERE_FIRMA_CURATA_LIVR1();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA NIRSTOC');
  PERFORM PKG_RUPERE_FIRMA_CURATA_NIRSTOC();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA OBLIGPIF');
  PERFORM PKG_RUPERE_FIRMA_CURATA_OBLIGPIF();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA INTRARI1');
  PERFORM PKG_RUPERE_FIRMA_CURATA_INTRARI1();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA IESIRI1');
  PERFORM PKG_RUPERE_FIRMA_CURATA_IESIRI1();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA COMANDA1');
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA CARNETDOC');
  PERFORM PKG_RUPERE_FIRMA_CURATA_CARNETEDOC();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' FIXEAZA STARTNR');
  PERFORM PKG_RUPERE_FIRMA_FIXEAZA_STARTNR();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA LIVR');
  PERFORM PKG_RUPERE_FIRMA_CURATA_LIVR();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA NIR');
  PERFORM PKG_RUPERE_FIRMA_CURATA_NIR();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA TRANSF1');
  PERFORM PKG_RUPERE_FIRMA_CURATA_TRANSF1();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA INTRARI');
  PERFORM PKG_RUPERE_FIRMA_CURATA_INTRARI();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA IESIRI');
  PERFORM PKG_RUPERE_FIRMA_CURATA_IESIRI();
  PERFORM PKG_GLOBALS_PUT_LINE( to_char( CURRENT_TIMESTAMP, 'dd.mm.yyyy - hh24:mi:ss') || ' CURATA TRANSF');
  PERFORM PKG_RUPERE_FIRMA_CURATA_TRANSF();
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sablondescript_sp_deleterecord</obj_name>
  <obj_hashval>692260c3c23cb56f0e805e4d88495666</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sablondescript_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_SABLONDESCRIPT_SP_LOCKRECORD(RECID);
  DELETE FROM SABLONDESCRIPT1 WHERE CODSABLON = RECID;
  DELETE FROM SABLONDESCRIPT  WHERE CODSABLON = RECID;
  PERFORM NotifyModif(2, RecId, 'SABLONDESCRIPT');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sablondescript_sp_gotorecord</obj_name>
  <obj_hashval>75e46c164ae88403fd7b7657303700b7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sablondescript_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_SABLONDESCRIPT(CODSABLON, DENUMIRE, SIMBOL, CODDESCRIPTOR)
  SELECT CODSABLON, DENUMIRE, SIMBOL, CODDESCRIPTOR FROM SABLONDESCRIPT WHERE CODSABLON = RECID;

  INSERT INTO TMP_SABLONDESCRIPT1(CODSABLON1, CODSABLON, CODDESCRIPTOR1, PROCENT, Valoare)
  SELECT S1.CODSABLON1, S1.CODSABLON, S1.CODDESCRIPTOR1, S1.PROCENT, D1.Valoare
  FROM SABLONDESCRIPT1 S1 INNER JOIN DESCRIPTORI1 D1 ON  S1.CODDESCRIPTOR1 = D1.CODDESCRIPTOR1
  WHERE S1.CODSABLON = RECID;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sablondescript_sp_lockrecord</obj_name>
  <obj_hashval>f74be94a6263a51caac80ac631b1345f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sablondescript_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMP numeric;
begin
  SELECT CODSABLON INTO TMP FROM SABLONDESCRIPT WHERE CODSABLON = RECID FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sablondescript_sp_postrecords</obj_name>
  <obj_hashval>aa689d0ba63bc3137a1c16fef12ac590</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sablondescript_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  IF  OPERATION = 0 THEN
    SELECT CODSABLON INTO RECID FROM TMP_SABLONDESCRIPT;

    UPDATE SABLONDESCRIPT
    SET
    (DENUMIRE, SIMBOL, CODDESCRIPTOR) = (SELECT DENUMIRE, SIMBOL, CODDESCRIPTOR FROM TMP_SABLONDESCRIPT)
    WHERE CODSABLON = RECID;

    DELETE FROM SABLONDESCRIPT1 WHERE CODSABLON = RECID AND CODSABLON1 NOT IN (SELECT CODSABLON1 FROM TMP_SABLONDESCRIPT1);

    INSERT INTO SABLONDESCRIPT1(CODSABLON1, CODSABLON, CODDESCRIPTOR1, PROCENT)
    SELECT NEXTVAL('SEQ_SABLONDESCRIPT1_CODSABLON1'), RECID, CODDESCRIPTOR1, PROCENT FROM TMP_SABLONDESCRIPT1 WHERE CODSABLON1 &lt;= 0;

    FOR V_REC IN (SELECT * FROM TMP_SABLONDESCRIPT1 WHERE CODSABLON &gt; 0) LOOP
      UPDATE SABLONDESCRIPT1
      SET
      CODDESCRIPTOR1 = V_REC.CODDESCRIPTOR1,
      PROCENT        = V_REC.PROCENT
      WHERE
       CODSABLON1 = V_REC.CODSABLON1;
    END LOOP;
  ELSE
    SELECT NEXTVAL('SEQ_SABLONDESCRIPT_CODSABLON') INTO RECID;

    INSERT INTO SABLONDESCRIPT(CODSABLON, DENUMIRE, SIMBOL, CODDESCRIPTOR)
    SELECT RECID, DENUMIRE, SIMBOL, CODDESCRIPTOR FROM TMP_SABLONDESCRIPT;

    INSERT INTO SABLONDESCRIPT1(CODSABLON1, CODSABLON, CODDESCRIPTOR1, PROCENT)
    SELECT NEXTVAL('SEQ_SABLONDESCRIPT1_CODSABLON1'), RECID, CODDESCRIPTOR1, PROCENT FROM TMP_SABLONDESCRIPT1;
  END IF;

  PERFORM NotifyModif(Operation, RecId, 'SABLONDESCRIPT');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_actulizarecodsaftinncont</obj_name>
  <obj_hashval>a5bba4a98f273da1bc152a75847ec2be</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_actulizarecodsaftinncont()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
  DECLARE vRec record;
BEGIN
  --Stef   15.02.2022 - corectie recursive
  --Florin 14.02.2022 - sinc. Oracle
  FOR vRec IN (
    WITH recursive cRec (CODCONT, CODSAFT) AS (
      SELECT C.CODCONT, C.CODSAFT
      FROM NCONT C
      WHERE Coalesce(c.codparinte, 0) = 0 AND C.CODCONT &lt;&gt; 0
      UNION ALL
      SELECT C.CODCONT, Coalesce(C.CODSAFT, CR.CODSAFT)
      FROM NCONT C INNER JOIN cRec cr ON cr.codcont = C.codparinte
    )
    SELECT CS.CODCONT, CS.CODSAFT
    FROM cRec CS INNER JOIN NCONT C ON C.CODCONT = CS.CODCONT
    WHERE CS.CODSAFT IS NOT NULL AND NULLIF(C.CODSAFT, '') IS NULL
  ) LOOP
    UPDATE NCONT SET CODSAFT = vRec.CODSAFT WHERE CODCONT = VRec.CODCONT;
  END LOOP;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_end_saft</obj_name>
  <obj_hashval>db9c57951a46bbb0b527b9bf5af6daab</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_end_saft()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 17.11.2025 - sinc. Oracle
  --Stef 19.09.2024
  --PERFORM PKG_SAFT_SAVE_TABLES();
   IF (case when current_setting('PKG_SAFT.pSaftDebug', true) is null or current_setting('PKG_SAFT.pSaftDebug', true) = '' then false else current_setting('PKG_SAFT.pSaftDebug', true)::boolean end) THEN
    PERFORM PKG_SAFT_TRUNCATE_TABLES();
  end if;

--PT DEBUG decomentati linia PKG_SAFT_SAVE_TABLES si selectul urmator creeaza tot ce e nevoie:
--SELECT
--'DO $$
--BEGIN
--  SET search_path TO public, '||lower(f.skemafirma::varchar)||', winmadmin;
--  CALL create_wm_temps();
--  PERFORM pkg_globals_setuserid('||p.userid::varchar||');
--  PERFORM pkg_globals_setcodfirma('||p.codfirma::varchar||');
--  PERFORM PKG_SAFT_BEGIN_SAFT('||tip::varchar||', '||anfin::varchar||', '||lunafin::varchar||', '||codsubunit::varchar||');
--END$$;' AS vSQL
--FROM SAV_TMP_SAFT_PARAMS P LEFT JOIN WINMADMIN.FIRMA F ON F.CODFIRMA = P.codfirma;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_firmaplatitortva</obj_name>
  <obj_hashval>3283173056a19cc623263fac436ff3b2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_firmaplatitortva(asubunit numeric, pan numeric, pluna numeric)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
DECLARE
    aHolding        BOOLEAN  := '1' = Coalesce(fnc_GetValConstanta('Holding' ,pAn,pLuna),'2');
    CFisc           Varchar(13);
    aCodFirma       NUMERIC(20):= (SELECT wme_result FROM pkg_globals_getcodfirma(NULL, NULL));
    SubunitTVA      numeric(1);
    v_rec           record;
  BEGIN
    --Florin 30.09.2025 - sinc. Oracle
    --Florin 29.08.2025 - sinc. Oracle
    --Florin 17.07.2025
    Select Coalesce(EFACT,0) into SubunitTVA from NSubunit where CodSubunit = aSubunit;
    IF (aHolding or (SubunitTVA = 1))AND (aSubunit &lt;&gt; 1) THEN
      SELECT S.CIF into CFisc FROM NSUBUNIT S Where S.CODSUBUNIT = aSUBUNIT;
    ELSE
      for v_rec in (
        SELECT F.CODFISCAL FROM WINMADMIN.FIRMA F WHERE F.CODFIRMA = aCODFIRMA
      ) loop
        CFisc := v_rec.codfiscal;
        exit;
      end loop;
    END IF;
    Return InStr(Upper(CFisc),'RO');
  END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_save_tables</obj_name>
  <obj_hashval>09484e64aeec300f97f073d983f9805e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_save_tables()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vRec RECORD;
BEGIN
  --Stef 11.09.2024 - sinc. Oracle
  perform pkg_saft_PUT_INFO('99.A','SAVE_TABLES');
  FOR vRec IN (
    SELECT SURSA           FROM SAFTTAB UNION
    SELECT 'TMP_SAFT_PARAMS'            UNION
    SELECT 'TMP_SAFT_NCONT'             UNION
    SELECT 'TMP_SAFT_CODSAF'            UNION
    SELECT 'TMP_SAFT_TAXINFO'           UNION
    SELECT 'TMP_SAFT_TAXINFO_MP'        UNION
    SELECT 'TMP_SAFT_NPART'             UNION
    SELECT 'TMP_SAFT_NPARTDET'          UNION
    SELECT 'TMP_SAFT_NPARTFUZ'          UNION
    SELECT 'TMP_SAFT_JURNAL'            UNION
    SELECT 'TMP_SAFT_JURNAL1'           UNION
    SELECT 'TMP_SAFT_JURNALDET'         UNION
    SELECT 'TMP_SAFT_MIFIX1'            UNION
    SELECT 'TMP_SAFT_CC4426'            UNION
    SELECT 'TMP_SAFT_STOCKMOVEMENT'     UNION
    SELECT 'TMP_SAFT_EXCL_J1'           UNION
    SELECT 'TMP_SAFT_MANEVRA'
  )
  LOOP
    BEGIN
      EXECUTE 'DROP TABLE '||get_schema()||'.SAV_'||vRec.SURSA;
    EXCEPTION
      WHEN OTHERS THEN NULL;
    END;
    EXECUTE 'CREATE TABLE '||get_schema()||'.SAV_'||vRec.SURSA||' AS SELECT * FROM '||vRec.SURSA;
  END LOOP;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_truncate_tables</obj_name>
  <obj_hashval>2b523bc5c1f4a8746b5da83c1a27d4e2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_truncate_tables()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vRec record;
BEGIN
  --Florin 17.11.2025 - sinc. Oracle
  --Stef 11.09.2024 - sinc. Oracle
  FOR vRec IN (
    SELECT SURSA           FROM SAFTTAB UNION
    SELECT 'TMP_SAFT_PARAMS'            UNION
    SELECT 'TMP_SAFT_NCONT'             UNION
    SELECT 'TMP_SAFT_CODSAF'            UNION
    SELECT 'TMP_SAFT_TAXINFO'           UNION
    SELECT 'TMP_SAFT_TAXINFO_MP'        UNION
    SELECT 'TMP_SAFT_NPART'             UNION
    SELECT 'TMP_SAFT_NPARTDET'          UNION
    SELECT 'TMP_SAFT_NPARTFUZ'          UNION
    SELECT 'TMP_SAFT_JURNAL'            UNION
    SELECT 'TMP_SAFT_JURNAL1'           UNION
    SELECT 'TMP_SAFT_JURNALDET'         UNION
    SELECT 'TMP_SAFT_MIFIX1'            UNION
    SELECT 'TMP_SAFT_CC4426'            UNION
    SELECT 'TMP_SAFT_STOCKMOVEMENT'     UNION
    SELECT 'TMP_SAFT_EXCL_J1'           union
    SELECT 'TMP_SAFT_MANEVRA'
  ) LOOP
    EXECUTE 'TRUNCATE TABLE ' || vRec.SURSA;
  END LOOP;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_manevra_cont_from_const</obj_name>
  <obj_hashval>769ef67b5c7efbbabf2203c6315e85e6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_manevra_cont_from_const(pconst character varying, pan numeric, pluna numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  cValConst text;
  vAL       NUMERIC(5) := pAn*12+pLuna;
BEGIN
   --Stef   26.11.2025 - sinc. Oracle
   --Florin 17.11.2025 - sinc. Oracle
  cValConst := Coalesce(fnc_GetValConstanta(pConst, pAn,pLuna), '-1');
  DELETE FROM TMP_SAFT_MANEVRA WHERE FILTRU = pConst AND AL = vAL;
  EXECUTE
  'INSERT INTO TMP_SAFT_MANEVRA (FILTRU, AL, CODUNIC)
  WITH RECURSIVE tmpc (CODCONT) AS (
    SELECT codcont   FROM ncont WHERE codcont IN ('||cValConst||') AND codcont &lt;&gt; 0 UNION ALL
    SELECT c.codcont FROM tmpc INNER JOIN ncont c ON c.codparinte = tmpc.codcont
  )
  SELECT ' || quote_literal(pConst) || ', ' || to_char(vAL) || ', codcont
  FROM  (SELECT DISTINCT codcont FROM tmpc) t';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_npartdet</obj_name>
  <obj_hashval>998e6f507be5ad62520d3ce1ab8cce88</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_npartdet(palstart numeric, palstop numeric, bsaft boolean DEFAULT false)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  bCNPPersFiz      BOOLEAN := Coalesce(NULLIF(fnc_getvalconstanta('SAFTCodPartPersFiz',0,pALStop),''),'2') = '2';
BEGIN
  --Stef  09.10.2025
  CALL create_wm_temps_flag('TMP_SAFT_NPARTDET');

  IF bSaft THEN
    INSERT INTO TMP_SAFT_NPARTDET (
      CODPART,
      PERSFIZICA, COD_CODFISCAL, CODFISCAL,
      STATCOMUNITAR, SIMBTARA
    )
    SELECT
      P.CODPART,
      Coalesce(P.PERSOANAFIZICA, 0) AS PERSFIZICA, PCF.COD_CODFISCAL, Upper(REPLACE(PCF.CODFISCAL, ' ', '')),
      Coalesce(T.STATCOMUNITAR, 0) AS STATCOMUNITAR, Coalesce(Upper(T.SIMBAUTO), 'X') SimbTara
    FROM (
      SELECT DISTINCT CODPART FROM TMP_SAFT_NPART
    ) TSP
      LEFT JOIN NPART        P   ON P.CODPART    = TSP.CODPART
      LEFT JOIN NPARTCODFISC PCF ON PCF.CODPART  = P.CODPART AND PCF.PRINCIPAL = 1
      LEFT JOIN NAGENDA      A   ON A.CODPART    = P.CODPART AND A.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(A.INACTIV, 0) = 0
      LEFT JOIN NLOCALIT     L   ON L.CODLOCALIT = A.CODLOCALIT
      LEFT JOIN NTARI        T   ON T.CODTARA    = L.CODTARA;
  ELSE
    INSERT INTO TMP_SAFT_NPARTDET (
      CODPART,
      PERSFIZICA, COD_CODFISCAL, CODFISCAL,
      STATCOMUNITAR, SIMBTARA
    )
    SELECT
      P.CODPART,
      Coalesce(P.PERSOANAFIZICA, 0) AS PERSFIZICA, PCF.COD_CODFISCAL, Upper(REPLACE(PCF.CODFISCAL, ' ', '')),
      Coalesce(T.STATCOMUNITAR, 0) AS STATCOMUNITAR, Coalesce(Upper(T.SIMBAUTO), 'X') SimbTara
    FROM NPART P
      LEFT JOIN NPARTCODFISC PCF ON PCF.CODPART  = P.CODPART AND PCF.PRINCIPAL = 1
      LEFT JOIN NAGENDA      A   ON A.CODPART    = P.CODPART AND A.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(A.INACTIV, 0) = 0
      LEFT JOIN NLOCALIT     L   ON L.CODLOCALIT = A.CODLOCALIT
      LEFT JOIN NTARI        T   ON T.CODTARA    = L.CODTARA;
  END IF;

  UPDATE TMP_SAFT_NPARTDET -- daca codul fiscal pare cnp -&gt; PersoanaFizica
  SET PERSFIZICA = 1
  WHERE PERSFIZICA = 0 AND Length(CODFISCAL) = 13 AND REGEXP_REPLACE(CODFISCAL,'\D+','') = CODFISCAL;

  IF NOT bCNPPersFiz THEN
    UPDATE TMP_SAFT_NPARTDET SET COD_CODFISCAL = NULL, CODFISCAL = NULL WHERE PERSFIZICA = 1;
  END IF;

  UPDATE TMP_SAFT_NPARTDET
  SET CODFISCAL = SubStr(CODFISCAL, 3)
  WHERE Length(SimbTara) = 2 AND SubStr(CODFISCAL, 1, 2) = SimbTara;

  UPDATE TMP_SAFT_NPARTDET
  SET CODFISCAL = SubStr(CODFISCAL, 3), SimbTara = SubStr(CODFISCAL, 1, 2)
  WHERE SubStr(CODFISCAL, 1, 2) IN ('AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'EL', 'ES', 'FI', 'FR', 'HR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK');

  UPDATE TMP_SAFT_NPARTDET
  SET StatComunitar = 1
  WHERE SimbTara IN ('AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'EL', 'ES', 'FI', 'FR', 'HR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK');

  UPDATE TMP_SAFT_NPARTDET SET CODFISCAL = REGEXP_REPLACE(CODFISCAL,'\D+','') WHERE SimbTara = 'RO';
  UPDATE TMP_SAFT_NPARTDET SET COD_CODFISCAL = NULL WHERE CODFISCAL IS NULL;

  UPDATE TMP_SAFT_NPARTDET
  SET PartID = CASE
                 WHEN SimbTara = 'RO'   AND PersFizica &lt;&gt; 1       THEN '00'||          Coalesce(CodFiscal,'')
                 WHEN SimbTara = 'RO'   AND CodFiscal IS NOT NULL THEN '03'||          Coalesce(CodFiscal,'')
                 WHEN SimbTara = 'RO'                             THEN '04'||          To_Char(CodPart)
                 WHEN StatComunitar = 1 AND CodFiscal IS NOT NULL THEN '01'||SimbTara||Coalesce(CodFiscal,'')
                 WHEN StatComunitar = 1                           THEN '05'||SimbTara||To_Char(CodPart)
                 WHEN                       CodFiscal IS NOT NULL THEN '02'||SimbTara||Coalesce(CodFiscal,'')
                                                                  ELSE '06'||SimbTara||To_Char(CodPart)
               END;

END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t01</obj_name>
  <obj_hashval>17b68709a4a481ad42e1353b48770830</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t01()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vSubunit NUMERIC(20);
BEGIN
  --Stef  26.06.2025
  PERFORM pkg_saft_PUT_INFO('01.A','UMPLE_T01--SAF_HEADER');

  SELECT CODSUBUNIT INTO vSubunit
  FROM TMP_SAFT_PARAMS;

  IF vSubunit = 1 THEN
    INSERT INTO TMP_SAFT01
    SELECT
      01                           COL01,--CODSAF_HEADER                  NUMBER(20)
      '1.0'                        COL02,--AUDITFILEVERSION               NVARCHAR2(9)
      T.SIMBAUTO                   COL03,--AUDITFILECOUNTRY               NVARCHAR2(2)
      T.SIMBAUTO||'-'||J.SIMBAUTO  COL04,--AUDITFILEREGION                NVARCHAR2(9)
      CURRENT_TIMESTAMP            COL05,--AUDITFILEDATECREATED           DATE
      'TH JUNIOR SRL'              COL06,--SOFTWARECOMPANYNAME            NVARCHAR2(70)
      'WinMENTOR Enterprise'       COL07,--SOFTWAREID                     NVARCHAR2(256)
      To_Char(V.Version, '00D000') COL08,--SOFTWAREVERSION                NVARCHAR2(18)
      06                           COL09,--CODCOMPANYSAF_COMPANYSTRUCTURE NUMBER(20)
      CAST(NULL AS NUMERIC(20))    COL10,--CODPOSTALADDRESSSAF_ADDRESS    NUMBER(20)
      'RON'                        COL11,--DEFAULTCURRENCYCODE            NVARCHAR2(3)
      02                           COL12,--CODSAF_SELECTIONCRITERIA       NUMBER(20)
      CASE SP.TIP
        WHEN 1 THEN 'L'
        WHEN 2 THEN 'T'
        WHEN 3 THEN 'A'
        WHEN 4 THEN 'C'
        WHEN 5 THEN 'NL'
        WHEN 6 THEN 'NT'
        WHEN 7 THEN 'A'
      END                          COL13,--HEADERCOMMENT                  NVARCHAR2(256)
      CAST(1 AS NUMERIC(20))       COL14,--SEGMENTINDEX                   NVARCHAR2(9)
      CAST(1 AS NUMERIC(20))       COL15,--TOTALSEGMENTSINSEQUENCE        NVARCHAR2(9)
      CASE F.TIPCONTA
        WHEN  1 THEN 'A'
        WHEN  2 THEN 'I'
        WHEN  3 THEN 'IFRS'
        WHEN  4 THEN 'BANK'
        WHEN  5 THEN 'INSURANCE'
        WHEN  6 THEN 'NORMA39'
        WHEN  7 THEN 'IFN'
        WHEN  8 THEN 'NORMA14'
        WHEN  9 THEN 'NORMA36'
        WHEN 10 THEN 'ONG'
        WHEN 11 THEN 'ONGE'
      END                          COL16,--TAXACCOUNTINGBASIS             NVARCHAR2(18)
      'Company'                    COL17 --TAXENTITY                      NVARCHAR2(70)
    FROM TMP_SAFT_PARAMS SP
      INNER JOIN WINMADMIN.FIRMA    F ON F.CODFIRMA   = SP.CODFIRMA
      LEFT  JOIN WINMADMIN.NLOCALIT L ON L.CODLOCALIT = F.CODLOCALIT
      LEFT  JOIN WINMADMIN.NJUDET   J ON J.CODJUDET   = L.CODJUDET
      LEFT  JOIN WINMADMIN.NTARI    T ON T.CODTARA    = L.CODTARA
      CROSS JOIN VERSION V;
  ELSE
    INSERT INTO TMP_SAFT01
    SELECT
      01                           COL01,--CODSAF_HEADER                  NUMBER(20)
      '1.0'                        COL02,--AUDITFILEVERSION               NVARCHAR2(9)
      T.SIMBAUTO                   COL03,--AUDITFILECOUNTRY               NVARCHAR2(2)
      T.SIMBAUTO||'-'||J.SIMBAUTO  COL04,--AUDITFILEREGION                NVARCHAR2(9)
      CURRENT_DATE                 COL05,--AUDITFILEDATECREATED           DATE
      'TH JUNIOR SRL'              COL06,--SOFTWARECOMPANYNAME            NVARCHAR2(70)
      'WinMENTOR Enterprise'       COL07,--SOFTWAREID                     NVARCHAR2(256)
      To_Char(V.Version, '00D000') COL08,--SOFTWAREVERSION                NVARCHAR2(18)
      06                           COL09,--CODCOMPANYSAF_COMPANYSTRUCTURE NUMBER(20)
      NULL                         COL10,--CODPOSTALADDRESSSAF_ADDRESS    NUMBER(20)
      'RON'                        COL11,--DEFAULTCURRENCYCODE            NVARCHAR2(3)
      02                           COL12,--CODSAF_SELECTIONCRITERIA       NUMBER(20)
      CASE SP.TIP
        WHEN 1 THEN 'L'
        WHEN 2 THEN 'T'
        WHEN 3 THEN 'A'
        WHEN 4 THEN 'C'
        WHEN 5 THEN 'NL'
        WHEN 6 THEN 'NT'
        WHEN 7 THEN 'A'
      END                          COL13,--HEADERCOMMENT                  NVARCHAR2(256)
      CAST(1 AS NUMERIC(20))       COL14,--SEGMENTINDEX                   NVARCHAR2(9)
      CAST(1 AS NUMERIC(20))       COL15,--TOTALSEGMENTSINSEQUENCE        NVARCHAR2(9)
      CASE F.TIPCONTA
        WHEN  1 THEN 'A'
        WHEN  2 THEN 'I'
        WHEN  3 THEN 'IFRS'
        WHEN  4 THEN 'BANK'
        WHEN  5 THEN 'INSURANCE'
        WHEN  6 THEN 'NORMA39'
        WHEN  7 THEN 'IFN'
        WHEN  8 THEN 'NORMA14'
        WHEN  9 THEN 'NORMA36'
        WHEN 10 THEN 'ONG'
        WHEN 11 THEN 'ONGE'
      END                          COL16,--TAXACCOUNTINGBASIS             NVARCHAR2(18)
      'Company'                    COL17 --TAXENTITY                      NVARCHAR2(70)
    FROM TMP_SAFT_PARAMS SP
      INNER JOIN NSUBUNIT        S ON S.CODSUBUNIT = SP.CODSUBUNIT
      INNER JOIN WINMADMIN.FIRMA F ON F.CODFIRMA   = SP.CODFIRMA
      LEFT  JOIN NAGENDA         A ON A.CODSUBUNIT = SP.CODSUBUNIT
      LEFT  JOIN NLOCALIT        L ON L.CODLOCALIT = A.CODLOCALIT
      LEFT  JOIN NJUDET          J ON J.CODJUDET   = L.CODJUDET
      LEFT  JOIN NTARI           T ON T.CODTARA    = L.CODTARA
      CROSS JOIN VERSION V;
  END IF;

  PERFORM pkg_saft_PUT_INFO('01.Z','UMPLE_T01--SAF_HEADER');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t02</obj_name>
  <obj_hashval>c85a7dc2f4960f5ba9cd6becddfc11ad</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t02()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 21.11.2023 - fixat 60132
  PERFORM pkg_saft_PUT_INFO('02.A','UMPLE_T02--SAF_SELECTIONCRITERIA');
  INSERT INTO TMP_SAFT02
  SELECT
    2                                       COL01,--CODSAF_SELECTIONCRITERIA NUMERIC(20,0)
    CAST(NULL AS VARCHAR(35) )              COL02,--TAXREPORTINGJURISDICTION STRING(35,0)
    CAST(NULL AS VARCHAR(70) )              COL03,--COMPANYENTITY            STRING(70,0)
    Trunc(
      To_Date(SP.ANP::varchar||SP.LUNAINI::varchar, 'yyyymm'),
      'MM'
    )                                       COL04,--SELECTIONSTARTDATE       DATE(10,0)
    LAST_DAY(
      To_Date(SP.ANP::varchar||SP.LUNAFIN::varchar, 'yyyymm')
    )                                       COL05,--SELECTIONENDDATE         DATE(10,0)
    SP.LUNAINI                              COL06,--PERIODSTART              NUMERIC(20,0)
    SP.ANINI                                COL07,--PERIODSTARTYEAR          NUMERIC(20,0)
    SP.LUNAFIN                              COL08,--PERIODEND                NUMERIC(20,0)
    SP.ANFIN                                COL09,--PERIODENDYEAR            NUMERIC(20,0)
    CAST(NULL AS VARCHAR(255))              COL10,--DOCUMENTTYPE             STRING(255,0)
    CAST(NULL AS VARCHAR(255))              COL11 --OTHERCRITERIA            STRING(255,0)
  FROM TMP_SAFT_PARAMS SP;
  PERFORM pkg_saft_PUT_INFO('02.Z','UMPLE_T02');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t05</obj_name>
  <obj_hashval>80c586cee3e5c082eb1a39066cac1d36</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t05()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef   22.10.2025 - 67039
  --Florin 17.10.2025 - fixat 66994
  --Florin 13.10.2025 - sinc. Oracle
  --Florin 23.11.2023 - fixat 60132
  perform pkg_saft_PUT_INFO('05.A','UMPLE_T05--SAF_SUPPLIER');
  INSERT INTO TMP_SAFT05
  SELECT
    NEXTVAL('SEQ_SAFT')                          COL01,--CODSAF_SUPPLIER         NUMERIC(20,0)
    C06.CODSAF                                   COL02,--CODSAF_COMPANYSTRUCTURE NUMERIC(20,0)
    PD.PartID                                    COL03,--SUPPLIERID              STRING(35,0)
    NULL                                         COL04,--SELFBILLINGINDICATOR    STRING(9,0)
    P.CODSAFT                                    COL05,--ACCOUNTID               STRING(70,0)
    CASE
      WHEN P.TIPCONT = 1                                 THEN NULL
      WHEN P.TIPCONT = 2 AND P.SOLDI &lt; 0                 THEN NULL
      WHEN P.TIPCONT = 2 AND P.SOLDI = 0 AND P.SOLDF &lt; 0 THEN NULL
                                                         ELSE P.SOLDI
    END                                          COL06,--OPENINGDEBITBALANCE     NUMERIC(18,2)
    CASE
      WHEN P.TIPCONT = 1                                 THEN -P.SOLDI
      WHEN P.TIPCONT = 2 AND P.SOLDI &lt; 0                 THEN -P.SOLDI
      WHEN P.TIPCONT = 2 AND P.SOLDI = 0 AND P.SOLDF &lt; 0 THEN -P.SOLDI
                                                         ELSE NULL
    END                                          COL07,--OPENINGCREDITBALANCE    NUMERIC(18,2)
    CASE
      WHEN P.TIPCONT = 1                                 THEN NULL
      WHEN P.TIPCONT = 2 AND P.SOLDI &lt; 0                 THEN NULL
      WHEN P.TIPCONT = 2 AND P.SOLDI = 0 AND P.SOLDF &lt; 0 THEN NULL
                                                         ELSE P.SOLDF

    END                                          COL08,--CLOSINGDEBITBALANCE     NUMERIC(18,2)
    CASE
      WHEN P.TIPCONT = 1                                 THEN -P.SOLDF
      WHEN P.TIPCONT = 2 AND P.SOLDI &lt; 0                 THEN -P.SOLDF
      WHEN P.TIPCONT = 2 AND P.SOLDI = 0 AND P.SOLDF &lt; 0 THEN -P.SOLDF
                                                         ELSE NULL
    END                                          COL09 --CLOSINGCREDITBALANCE    NUMERIC(18,2)
  FROM (
    SELECT F.CODPARTFUZ AS CODPART, C.CODSAFT, C.TIPCONT, Sum(TP.SOLDI) SOLDI, Sum(TP.SOLDF) SOLDF
    FROM TMP_SAFT_NPART TP
      INNER JOIN TMP_SAFT_NCONT    C ON C.CODCONT = TP.CODCONT AND C.NO_SOLDPART = 0
      INNER JOIN TMP_SAFT_NPARTFUZ F ON F.CODPART = TP.CODPART
    WHERE TP.FURNIZOR = 1
    GROUP BY F.CODPARTFUZ, C.CODSAFT, C.TIPCONT
  ) P
    INNER JOIN TMP_SAFT_NPARTDET PD  ON PD.CODPART   = P.CODPART
    LEFT  JOIN TMP_SAFT_CODSAF   C06 ON C06.CODSURSA = P.CODPART AND C06.CodSAFTTab = 06;
  perform pkg_saft_PUT_INFO('05.Z','UMPLE_T05--SAF_SUPPLIER');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t06</obj_name>
  <obj_hashval>493480f36b9d615da355b5137c075c84</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t06()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vSubunit NUMERIC(20);
  vTip     NUMERIC(1);
BEGIN
  --Florin 21.13.2023 - gixat 60132
  --Florin 06.10.2022 - sinc. Oracle
  --Florin 09.09.2022 - sinc. Oracle(08.09.2022)
  --Stef 11.05.2022
  --Florin 20.04.2022 - sinc. Oracle (19.04.2022)
  --Stef 18.02.2022
  PERFORM pkg_saft_PUT_INFO('06.A','UMPLE_T06--SAF_COMPANYSTRUCTURE');

  SELECT tip, CODSUBUNIT INTO vTip, vSubunit
  FROM TMP_SAFT_PARAMS;

  IF vSubunit = 1 THEN
    INSERT INTO TMP_SAFT06
    SELECT
      06                                     COL01,--CODSAF_COMPANYSTRUCTURE NUMERIC(20,0)
      F.CODFISCAL                            COL02,--REGISTRATIONNUMBER      STRING(35,0)
      SubStr(F.DENFIRMA, 1, 70)              COL03,--NAME                    STRING(70,0)
      07                                     COL04,--CODSAF_ADDRESS          NUMERIC(20,0)
      08                                     COL05,--CODSAF_CONTACT          NUMERIC(20,0)
      10                                     COL06,--CODSAF_TAXREGISTRATION  NUMERIC(20,0)
      11                                     COL07 --CODSAF_BANKACCOUNT      NUMERIC(20,0)
    FROM TMP_SAFT_PARAMS SP INNER JOIN WINMADMIN.FIRMA F ON F.CODFIRMA   = SP.CODFIRMA;
  ELSE
    INSERT INTO TMP_SAFT06
    SELECT
      06                                     COL01,--CODSAF_COMPANYSTRUCTURE NUMERIC(20,0)
      S.CIF                                  COL02,--REGISTRATIONNUMBER      STRING(35,0)
      SubStr(S.DEN_SUBUNIT, 1, 70)           COL03,--NAME                    STRING(70,0)
      07                                     COL04,--CODSAF_ADDRESS          NUMERIC(20,0)
      08                                     COL05,--CODSAF_CONTACT          NUMERIC(20,0)
      10                                     COL06,--CODSAF_TAXREGISTRATION  NUMERIC(20,0)
      11                                     COL07 --CODSAF_BANKACCOUNT      NUMERIC(20,0)
    FROM TMP_SAFT_PARAMS SP INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = SP.CODSUBUNIT;
  END IF;
  IF vTip &lt;&gt; 4 THEN
    INSERT INTO TMP_SAFT06
    SELECT
      C06.CODSAF                             COL01,--CODSAF_COMPANYSTRUCTURE NUMERIC(20,0)
      PD.PartID                              COL02,--REGISTRATIONNUMBER      STRING(35,0)
      Substr(P.DEN_PART, 1, 70)              COL03,--NAME                    STRING(70,0)
      C07.CODSAF                             COL04,--CODSAF_ADDRESS          NUMERIC(20,0)
      C08.CODSAF                             COL05,--CODSAF_CONTACT          NUMERIC(20,0)
      C10.CODSAF                             COL06,--CODSAF_TAXREGISTRATION  NUMERIC(20,0)
      C11.CODSAF                             COL07 --CODSAF_BANKACCOUNT      NUMERIC(20,0)
    FROM TMP_SAFT_CODSAF C06
      LEFT JOIN TMP_SAFT_NPARTDET PD  ON PD.CODPART   = C06.CODSURSA
      LEFT JOIN NPART             P   ON P.CODPART    = C06.CODSURSA
      LEFT JOIN NAGENDA           A   ON A.CODPART    = C06.CODSURSA     AND A.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(A.INACTIV, 0) = 0
      LEFT JOIN NPARTB            PB  ON PB.CODPART   = C06.CODSURSA     AND PB.IMPLICIT = 1
      LEFT JOIN TMP_SAFT_CODSAF   C07 ON C07.CODSURSA = A.CODAGENDA      AND C07.CodSAFTTab = 07
      LEFT JOIN TMP_SAFT_CODSAF   C08 ON C08.CODSURSA = C06.CODSURSA     AND C08.CodSAFTTab = 08
      LEFT JOIN TMP_SAFT_CODSAF   C10 ON C10.CODSURSA = PD.COD_CODFISCAL AND C10.CodSAFTTab = 10
      LEFT JOIN TMP_SAFT_CODSAF   C11 ON C11.CODSURSA = PB.CODPARTB      AND C11.CodSAFTTab = 11
    WHERE C06.CodSAFTTab = 06;
  END IF;
  PERFORM pkg_saft_PUT_INFO('06.Z','UMPLE_T06--SAF_COMPANYSTRUCTURE');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t07</obj_name>
  <obj_hashval>7ac674e9ebadf74640ec0cffcf7391f6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t07()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
 vSubunit NUMERIC(20);
 vTip     NUMERIC(1);
BEGIN
  --Florin 29.09.2023 - fixat 59581
  --Stef 19.09.2023
  PERFORM  pkg_saft_PUT_INFO('07.A','UMPLE_T07--SAF_ADDRESS');
  SELECT tip, CODSUBUNIT
  INTO STRICT vTip, vSubunit
  FROM TMP_SAFT_PARAMS;

  IF vSubunit = 1 THEN
    INSERT INTO TMP_SAFT07
    SELECT
      07                                               COL01,--CODSAF_ADDRESS          NUMERIC(20,0)
      SUBSTR(Trim(F.STRADA), 1, 70)                    COL02,--STREETNAME              STRING(70,0)
      Coalesce(Trim(F.NR1), '')||
      CASE WHEN Coalesce(Length(Trim(F.NR1)),0) = 0 OR Coalesce(Length(Trim(F.NR2)),0) = 0 THEN '' ELSE '-' END||
      Coalesce(Trim(F.NR2), '')                        COL03,--NUMBERX                 STRING(18,0)
      SubStr(
        CASE WHEN NULLIF(Trim(F.BLOC ), '') IS NULL THEN '' ELSE ', Bl.'||F.BLOC  END||
        CASE WHEN NULLIF(Trim(F.SCARA), '') IS NULL THEN '' ELSE ', Sc.'||F.SCARA END||
        CASE WHEN NULLIF(Trim(F.ETAJ ), '') IS NULL THEN '' ELSE ', Et.'||F.ETAJ  END||
        CASE WHEN NULLIF(Trim(F.AP   ), '') IS NULL THEN '' ELSE ', Ap.'||F.AP    END
        , 3, 70
      )                                                COL04,--ADDITIONALADDRESSDETAIL STRING(70,0)
      NULL                                             COL05,--BUILDING                STRING(35,0)
      SubStr(L.DEN_LOCALIT, 1, 35)                     COL06,--CITY                    STRING(35,0)
      To_Char(F.CodPostal, 'fm9999999990')             COL07,--POSTALCODE              STRING(18,0)
      T.SIMBAUTO||'-'||J.SIMBAUTO                      COL08,--REGION                  STRING(35,0)
      SubStr(Trim(T.SIMBAUTO), 1, 2)                   COL09,--COUNTRY                 STRING(2,0)
      'PostalAddress'                                  COL10 --ADDRESSTYPE             STRING(18,0)
    FROM TMP_SAFT_PARAMS SP
      INNER JOIN WINMADMIN.FIRMA    F ON F.CODFIRMA   = SP.CODFIRMA
      LEFT  JOIN WINMADMIN.NLOCALIT L ON L.CODLOCALIT = F.CODLOCALIT
      LEFT  JOIN WINMADMIN.NJUDET   J ON J.CODJUDET   = L.CODJUDET
      LEFT  JOIN WINMADMIN.NTARI    T ON T.CODTARA    = L.CODTARA;
  ELSE
    INSERT INTO TMP_SAFT07
    SELECT
      07                                               COL01,--CODSAF_ADDRESS          NUMERIC(20,0)
      SUBSTR(Trim(A.STRADA), 1, 70)                    COL02,--STREETNAME              STRING(70,0)
      Coalesce(To_Char(A.NR1, 'fm99999'), '')||
      CASE WHEN Coalesce(A.NR1,0) = 0 OR Coalesce(Length(Trim(A.NR2)),0) = 0 THEN '' ELSE '-' END||
      Coalesce(Trim(A.NR2), '')                        COL03,--NUMBERX                 STRING(18,0)
      SubStr(
        CASE WHEN NULLIF(Trim(A.BLOC ), '') IS NULL THEN '' ELSE ', Bl.'||A.BLOC  END||
        CASE WHEN NULLIF(Trim(A.SCARA), '') IS NULL THEN '' ELSE ', Sc.'||A.SCARA END||
        CASE WHEN NULLIF(Trim(A.ETAJ ), '') IS NULL THEN '' ELSE ', Et.'||A.ETAJ  END||
        CASE WHEN NULLIF(Trim(A.APART   ), '') IS NULL THEN '' ELSE ', Ap.'||A.APART    END
        , 3, 70
      )                                                COL04,--ADDITIONALADDRESSDETAIL STRING(70,0)
      NULL                                             COL05,--BUILDING                STRING(35,0)
      SubStr(L.DEN_LOCALIT, 1, 35)                     COL06,--CITY                    STRING(35,0)
      A.CodPostal                                      COL07,--POSTALCODE              STRING(18,0)
      T.SIMBAUTO||'-'||J.SIMBAUTO                      COL08,--REGION                  STRING(35,0)
      SubStr(Trim(T.SIMBAUTO), 1, 2)                   COL09,--COUNTRY                 STRING(2,0)
      'PostalAddress'                                  COL10 --ADDRESSTYPE             STRING(18,0)
    FROM TMP_SAFT_PARAMS SP
      INNER JOIN NAGENDA  A ON A.CODSUBUNIT = SP.CODSUBUNIT
      LEFT  JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT
      LEFT  JOIN NJUDET   J ON J.CODJUDET   = L.CODJUDET
      LEFT  JOIN NTARI    T ON T.CODTARA    = L.CODTARA;
  END IF;
  IF vTip &lt;&gt; 4 THEN
    INSERT INTO TMP_SAFT07
    SELECT
      C07.CODSAF                                       COL01,--CODSAF_ADDRESS          NUMERIC(20,0)
      SUBSTR(Trim(A.STRADA), 1, 70)                    COL02,--STREETNAME              STRING(70,0)
      CASE WHEN Coalesce(A.NR1,0) = 0 OR Coalesce(Length(Trim(A.NR2)),0) = 0 THEN '' ELSE '-' END||
      Coalesce(Trim(A.NR2), '')                        COL03,--NUMBERX                 STRING(18,0)
      SubStr(
        CASE WHEN NULLIF(Trim(A.BLOC ), '') IS NULL THEN '' ELSE ', Bl.'||A.BLOC  END||
        CASE WHEN NULLIF(Trim(A.SCARA), '') IS NULL THEN '' ELSE ', Sc.'||A.SCARA END||
        CASE WHEN NULLIF(Trim(A.ETAJ ), '') IS NULL THEN '' ELSE ', Et.'||A.ETAJ  END||
        CASE WHEN NULLIF(Trim(A.APART), '') IS NULL THEN '' ELSE ', Ap.'||A.APART END
        , 3, 70
      )                                                COL04,--ADDITIONALADDRESSDETAIL STRING(70,0)
      NULL                                             COL05,--BUILDING                STRING(35,0)
      SubStr(L.DEN_LOCALIT, 1, 35)                     COL06,--CITY                    STRING(35,0)
      A.CodPostal                                      COL07,--POSTALCODE              STRING(18,0)
      T.SIMBAUTO||'-'||J.SIMBAUTO                      COL08,--REGION                  STRING(35,0)
      SubStr(Trim(T.SIMBAUTO), 1, 2)                   COL09,--COUNTRY                 STRING(2,0)
      'PostalAddress'                                  COL10 --ADDRESSTYPE             STRING(18,0)
    FROM TMP_SAFT_CODSAF C07
      LEFT JOIN NAGENDA  A ON A.CODAGENDA  = C07.CODSURSA
      LEFT JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT
      LEFT JOIN NJUDET   J ON J.CODJUDET   = L.CODJUDET
      LEFT JOIN NTARI    T ON T.CODTARA    = L.CODTARA
    WHERE C07.CodSAFTTab = 07;
  END IF;

  UPDATE TMP_SAFT07 SET COL08 = NULL WHERE Coalesce(COL09, n'~') &lt;&gt; 'RO';

  PERFORM pkg_saft_PUT_INFO('07.Z','UMPLE_T07--SAF_ADDRESS');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t08</obj_name>
  <obj_hashval>22040eb19458a38b135e4496f557bc7b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t08()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vTip     NUMERIC(1);
BEGIN
  --Stef 06.09.2024 - sinc. Oracle
  PERFORM pkg_saft_PUT_INFO('08.A','UMPLE_T08--SAF_CONTACT');

  SELECT TIP
  INTO   vTip
  FROM TMP_SAFT_PARAMS;

  INSERT INTO TMP_SAFT08
  SELECT
    08                          COL01,--CODSAF_CONTACT       NUMERIC(20,0)
    09                          COL02,--CODSAF_CONTACTPERSON NUMERIC(20,0)
    SubStr(A.TELEFON, 1, 18)    COL03,--TELEPHONE            STRING(18,0)
    SubStr(A.FAX,     1, 18)    COL04,--FAX                  STRING(18,0)
    SubStr(A.EMAIL,   1, 70)    COL05,--EMAIL                STRING(70,0)
    NULL                        COL06 --WEBSITE              STRING(100,0)
  FROM TMP_SAFT_PARAMS SP
    LEFT JOIN NPERS   P ON P.CODPERS   = SP.PERSCONTACT
    LEFT JOIN NAGENDA A ON A.CODAGENDA = P.AGENDA;

  IF vTip &lt;&gt; 4 THEN
    INSERT INTO TMP_SAFT08
    SELECT
      C08.CODSAF                  COL01,--CODSAF_CONTACT       NUMERIC(20,0)
      C09.CODSAF                  COL02,--CODSAF_CONTACTPERSON NUMERIC(20,0)
      SubStr(PC.TELEFON, 1, 18)   COL03,--TELEPHONE            STRING(18,0)
      NULL                        COL04,--FAX                  STRING(18,0)
      SubStr(PC.EMAIL, 1, 70)     COL05,--EMAIL                STRING(70,0)
      NULL                        COL06 --WEBSITE              STRING(100,0)
    FROM TMP_SAFT_CODSAF C08
      LEFT JOIN NPERSCONTACT    PC  ON PC.CodPart   = C08.CodSursa
      LEFT JOIN TMP_SAFT_CODSAF C09 ON C09.CODSURSA = PC.CODPERSC AND C09.CodSAFTTab = 09
    WHERE C08.CodSAFTTab = 08;
  END IF;
  PERFORM  pkg_saft_PUT_INFO('08.Z','UMPLE_T08--SAF_CONTACT');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t09</obj_name>
  <obj_hashval>60a4b0f20d69585ce69dc8fb688053cb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t09()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vTip     NUMERIC(1);
BEGIN
  --Stef 06.09.2024 - sinc. Oracle
  PERFORM pkg_saft_PUT_INFO('09.A','UMPLE_T09--SAF_CONTACTPERSON');
  SELECT TIP
  INTO   vTip
  FROM TMP_SAFT_PARAMS;

  INSERT INTO TMP_SAFT09
  SELECT
    09                                    COL01,--CODSAF_CONTACTPERSON NUMERIC(20,0)
    NULL                                  COL02,--TITLU                STRING(9,0)
    SubStr(P.PRENUME, 1, 35)              COL03,--FIRSTNAME            STRING(35,0)
    SubStr(P.NUME,    1, 1)||
    SubStr(P.PRENUME, 1, 1)               COL04,--INITIALS             STRING(18,0)
    NULL                                  COL05,--LASTNAMEPREFIX       STRING(18,0)
    SubStr(P.NUME, 1, 70)                 COL06,--LASTNAME             STRING(70,0)
    To_Char(P.DATAN, 'dd.mm.yyyy')        COL07,--BIRTHNAME            STRING(70,0)
    NULL                                  COL08,--SALUTATION           STRING(18,0)
    NULL                                  COL09 --OTHERTITLES          STRING(18,0)
  FROM TMP_SAFT_PARAMS SP LEFT JOIN NPERS P ON P.CODPERS = SP.PERSCONTACT;

  IF vTip &lt;&gt; 4 THEN
    INSERT INTO TMP_SAFT09
    SELECT
      C09.CODSAF                            COL01,--CODSAF_CONTACTPERSON NUMERIC(20,0)
      NULL                                  COL02,--TITLU                STRING(9,0)
      SubStr(PC.PRENUME, 1, 35)             COL03,--FIRSTNAME            STRING(35,0)
      SubStr(PC.NUME,    1, 1)||
      SubStr(PC.PRENUME, 1, 1)              COL04,--INITIALS             STRING(18,0)
      NULL                                  COL05,--LASTNAMEPREFIX       STRING(18,0)
      SubStr(PC.NUME, 1, 70)                COL06,--LASTNAME             STRING(70,0)
      To_Char(PC.DATANASTERE, 'dd.mm.yyyy') COL07,--BIRTHNAME            STRING(70,0)
      NULL                                  COL08,--SALUTATION           STRING(18,0)
      NULL                                  COL09 --OTHERTITLES          STRING(18,0)
    FROM TMP_SAFT_CODSAF C09 LEFT JOIN NPERSCONTACT PC ON PC.CODPERSC = C09.CodSursa
    WHERE C09.CodSAFTTab = 09;
  END IF;

  PERFORM pkg_saft_PUT_INFO('09.Z','UMPLE_T09--SAF_CONTACTPERSON');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t10</obj_name>
  <obj_hashval>2292eaee21b67e422d333e27b1cb5ec3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t10()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vSubunit NUMERIC(20);
  vTip     NUMERIC(1);
BEGIN
  --Florin  06.10.2022 - sinc. Oracle
  --Florin 09.09.2022 - sinc. Oracle (08.09.2022)
  --Stef 11.05.2022
  --Florin 20.04.2022 - sinc. Oracle (19.04.2022)
  --Stef 14.03.2022
  PERFORM pkg_saft_PUT_INFO('10.A','UMPLE_T10--SAF_TAXREGISTRATION');

  SELECT tip, CODSUBUNIT INTO vTip, vSubunit
  FROM TMP_SAFT_PARAMS;

  IF vSubunit = 1 THEN
    INSERT INTO TMP_SAFT10
    SELECT
      10                                     COL01,--CODSAF_TAXREGISTRATION NUMERIC(20,0)
      REGEXP_REPLACE(F.CODFISCAL,'\D+','')   COL02,--TAXREGISTRATIONNUMBER  STRING(35,0)
      CAST(NULL AS VARCHAR(9)  )             COL03,--TAXTYPE                STRING(9,0)
      CAST(NULL AS VARCHAR(35) )             COL04,--TAXNUMBER              STRING(35,0)
      CAST(NULL AS VARCHAR(35) )             COL05,--TAXAUTHORITY           STRING(35,0)
      CAST(NULL AS DATE         )            COL06 --TAXVERIFICATIONDATE    DATE(10,0)
    FROM TMP_SAFT_PARAMS SP INNER JOIN WINMADMIN.FIRMA F ON F.CODFIRMA   = SP.CODFIRMA;
  ELSE
    INSERT INTO TMP_SAFT10
    SELECT
      10                                     COL01,--CODSAF_TAXREGISTRATION NUMERIC(20,0)
      REGEXP_REPLACE(S.CIF,'\D+','')         COL02,--TAXREGISTRATIONNUMBER  STRING(35,0)
      CAST(NULL AS VARCHAR(9)  )             COL03,--TAXTYPE                STRING(9,0)
      CAST(NULL AS VARCHAR(35) )             COL04,--TAXNUMBER              STRING(35,0)
      CAST(NULL AS VARCHAR(35) )             COL05,--TAXAUTHORITY           STRING(35,0)
      CAST(NULL AS DATE         )            COL06 --TAXVERIFICATIONDATE    DATE(10,0)
    FROM TMP_SAFT_PARAMS SP INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = SP.CODSUBUNIT;
  END IF;
  IF vTip &lt;&gt; 4 THEN
    INSERT INTO TMP_SAFT10
    SELECT
      C10.CODSAF                             COL01,--CODSAF_TAXREGISTRATION NUMERIC(20,0)
      PD.PartID                              COL02,--TAXREGISTRATIONNUMBER  STRING(35,0)
      NULL                                   COL03,--TAXTYPE                STRING(9,0)
      NULL                                   COL04,--TAXNUMBER              STRING(35,0)
      NULL                                   COL05,--TAXAUTHORITY           STRING(35,0)
      NULL                                   COL06 --TAXVERIFICATIONDATE    DATE(10,0)
    FROM TMP_SAFT_CODSAF C10
      LEFT JOIN TMP_SAFT_NPARTDET PD ON PD.COD_CODFISCAL = C10.CodSursa
    WHERE C10.CodSAFTTab = 10;
  END IF;

  PERFORM pkg_saft_PUT_INFO('10.A','UMPLE_T10--SAF_TAXREGISTRATION');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t11</obj_name>
  <obj_hashval>7fca55c99301a43477236f157b9d53de</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t11()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vTip     NUMERIC(1);
BEGIN
  --Stef 11.04.2025
  PERFORM pkg_saft_PUT_INFO('11.A','UMPLE_T11--SAF_BANKACCOUNT');

  SELECT TIP INTO vTip FROM TMP_SAFT_PARAMS;
  INSERT INTO TMP_SAFT11
  SELECT
    11                             COL01,--CODSAF_BANKACCOUNT NUMERIC(20,0)
    CASE
      WHEN Coalesce(BC.CODBANKCONT, 0) = 0
      THEN CAST(NULL AS VARCHAR(35) )
      ELSE REPLACE(BC.NRCONT, ' ', '')
    END                            COL02,--IBANNUMBER         STRING(35,0)
    CASE
      WHEN Coalesce(BC.CODBANKCONT, 0) = 0
      THEN 'Fara cont bancar'
      ELSE CAST(NULL AS VARCHAR(70) )
    END                            COL03,--BANKACCOUNTNUMBER  STRING(35,0)
    CAST(NULL AS VARCHAR(70) )     COL04,--BANKACCOUNTNAME    STRING(70,0)
    CAST(NULL AS VARCHAR(18) )     COL05 --SORTCODE           STRING(18,0)
  FROM TMP_SAFT_PARAMS SP
    LEFT JOIN NBANKCONT BC ON BC.CODBANKCONT = SP.CODBANKCONT
    LEFT JOIN NBANK     B  ON B.CODBANK      = BC.CODBANK;

  IF vTip &lt;&gt; 4 THEN
    INSERT INTO TMP_SAFT11
    SELECT DISTINCT
      C11.CODSAF                     COL01,--CODSAF_BANKACCOUNT NUMERIC(20,0)
      CASE
        WHEN C11.CodSursa = 0
      THEN CAST(NULL AS VARCHAR(35) )
        ELSE REPLACE(PB.CONTBANCA, ' ', '')
      END                            COL02,--IBANNUMBER         STRING(35,0)
      CASE
        WHEN C11.CodSursa = 0
        THEN 'Fara cont bancar'
      ELSE CAST(NULL AS VARCHAR(70) )
      END                            COL03,--BANKACCOUNTNUMBER  STRING(35,0)
      CAST(NULL AS VARCHAR(70) )     COL04,--BANKACCOUNTNAME    STRING(70,0)
      CAST(NULL AS VARCHAR(18) )     COL05 --SORTCODE           STRING(18,0)
    FROM TMP_SAFT_CODSAF C11
      LEFT JOIN NPARTB PB ON PB.CODPARTB = C11.CodSursa
      LEFT JOIN NBANK  B  ON B.CODBANK   = PB.CODBANK
    WHERE C11.CodSAFTTab = 11;
  END IF;

  PERFORM pkg_saft_PUT_INFO('11.Z','UMPLE_T11--SAF_BANKACCOUNT');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t12</obj_name>
  <obj_hashval>9a7fa4d6606be3ec9411754ee619b6a7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t12()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 10.10.2022 - sinc. Oracle (09.10.2022)
  --Florin 06.10.2022 - sinc. Oracle
  -- Stef 10.08.2022
  PERFORM pkg_saft_PUT_INFO('12.A','UMPLE_T12--SAF_TAXTABLEENTRY');

  INSERT INTO TMP_SAFT12
  SELECT
    12                             COL01,--CODSAF_TAXTABLEENTRY  NUMBER(20)
    To_Char(TT.COD, 'fm999999000') COL02,--TAXTYPE               NVARCHAR2(9)
    SubStr(TT.Denumire, 1 , 256)   COL03,--DESCRIPTION           NVARCHAR2(256)
    1                              COL04 --DETSAF_TAXCODEDETAILS NUMBER(20)
  FROM WINMADMIN.TAXTYPESAFT TT
  WHERE TT.COD = 0;

  INSERT INTO TMP_SAFT12
  SELECT
    C12.CODSAF                     COL01,--CODSAF_TAXTABLEENTRY  NUMBER(20)
    To_Char(TT.COD, 'fm999999000') COL02,--TAXTYPE               NVARCHAR2(9)
    SubStr(TT.Denumire, 1 , 256)   COL03,--DESCRIPTION           NVARCHAR2(256)
    (
      SELECT Count(1)
      FROM TMP_SAFT_CODSAF C13
      WHERE C13.CodSAFTTab = 13
        AND C13.CodParinte = C12.CODSAF
    )                              COL04 --DETSAF_TAXCODEDETAILS NUMBER(20)
  FROM TMP_SAFT_CODSAF C12 LEFT JOIN WINMADMIN.TAXTYPESAFT TT ON TT.COD = C12.CodSursa
  WHERE C12.CodSAFTTab = 12;

  PERFORM pkg_saft_PUT_INFO('12.Z','UMPLE_T12--SAF_TAXTABLEENTRY');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t13</obj_name>
  <obj_hashval>5b11725ee85384234915df0311787138</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t13()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 10.10.2022 - sinc. Oracle(09.10.2022)
  --Florin 06.10.2022 - sinc. Oracle
  --Stef   15.03.2022 - sinc. Oracle
  --Florin 06.01.2022
  PERFORM pkg_saft_PUT_INFO('13.A','UMPLE_T13--SAF_TAXCODEDETAILS');

  INSERT INTO TMP_SAFT13
  SELECT
    13                             COL01,--CODSAF_TAXCODEDETAILS    NUMBER(20)
    12                             COL02,--CODSAF_MASTER            NUMBER(20)
    To_Char(TC.COD, 'fm999000000') COL03,--TAXCODE                  NVARCHAR2(9)
    NULL                           COL04,--EFFECTIVEDATE            DATE
    NULL                           COL05,--EXPIRATIONDATE           DATE
    SubStr(TC.Denumire, 1 , 256)   COL06,--DESCRIPTION              NVARCHAR2(256)
    Coalesce(TC.ProcTaxa, 0)       COL07,--TAXPERCENTAGE            NUMBER(22,7)
    NULL                           COL08,--CODFLATTAXRATESAF_AMOUNT NUMBER(20)
    1                              COL09,--BASERATE                 NUMBER(5,4)
    'RO'                           COL10,--COUNTRY                  NVARCHAR2(2)
    NULL                           COL11 --REGION                   NVARCHAR2(9)
  FROM WINMADMIN.TAXCODESAFT TC
  WHERE TC.COD = 0;

  INSERT INTO TMP_SAFT13
  SELECT
    C13.CODSAF                     COL01,--CODSAF_TAXCODEDETAILS    NUMBER(20)
    C13.CODPARINTE                 COL02,--CODSAF_MASTER            NUMBER(20)
    To_Char(TC.COD, 'fm999000000') COL03,--TAXCODE                  NVARCHAR2(9)
    NULL                           COL04,--EFFECTIVEDATE            DATE
    NULL                           COL05,--EXPIRATIONDATE           DATE
    SubStr(TC.Denumire, 1 , 256)   COL06,--DESCRIPTION              NVARCHAR2(256)
    Coalesce(TC.ProcTaxa, 0)       COL07,--TAXPERCENTAGE            NUMBER(22,7)
    NULL                           COL08,--CODFLATTAXRATESAF_AMOUNT NUMBER(20)
    1                              COL09,--BASERATE                 NUMBER(5,4)
    'RO'                           COL10,--COUNTRY                  NVARCHAR2(2)
    NULL                           COL11 --REGION                   NVARCHAR2(9)
  FROM TMP_SAFT_CODSAF C13 LEFT JOIN WINMADMIN.TAXCODESAFT TC ON TC.COD = C13.CodSursa
  WHERE C13.CODSAFTTAB = 13;

  PERFORM  pkg_saft_PUT_INFO('13.Z','UMPLE_T13--SAF_TAXCODEDETAILS');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t14</obj_name>
  <obj_hashval>1450c868b602a6820fa318410ea5c718</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t14()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef   16.02.2022 - sinc. Oracle
  INSERT INTO TMP_SAFT14
  SELECT
    C14.CODSAF                COL01,--CODSAF_UOMTABLEENTRY NUMBER(20)
    SUBSTR(UMS.CODSAFT, 1, 9) COL02,--UNITOFMEASURE        NVARCHAR2(9)
    UMS.DENUMIRE              COL03 --DESCRIPTION          NVARCHAR2(256)
  FROM TMP_SAFT_CODSAF C14 LEFT JOIN WINMADMIN.NUMSAFT UMS ON UMS.CODUMSAFT = C14.CodSursa
  WHERE C14.CodSAFTTab = 14;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t15</obj_name>
  <obj_hashval>ae2661251246dde9bf3a842eff542c31</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t15()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  v_ALIni NUMERIC(5);
  v_ALFin NUMERIC(5);
BEGIN
  --Stef 19.09.2024 - Sinc ORA-PG
  PERFORM pkg_saft_PUT_INFO('15.A','UMPLE_T15--SAF_ANALYSISTYPETABLEENTRY');

  SELECT ANINI*12+LUNAINI, ANFIN*12+LUNAFIN INTO v_ALIni, v_ALFin  FROM TMP_SAFT_PARAMS;

  INSERT INTO TMP_SAFT15
  SELECT
    nextval('SEQ_SAFT')            COL01,--CODSAF_ANALYSISTYPETABLEENTRY NUMBER(20)
    To_Char(TIPDOC, 'fm999999990') COL02,--ANALYSISTYPE                  NVARCHAR2(9)
    'JURNALE'                      COL03,--ANALYSISTYPEDESCRIPTION       NVARCHAR2(256)
    CASE
      WHEN J.TIPDOC =  1        THEN 'Facturi furnizori'
      WHEN J.TIPDOC =  3        THEN 'Chitanta / bon fiscal furnizori'
      WHEN J.TIPDOC =  4        THEN 'Bonuri de achizitie persoane fizice'
      WHEN J.TIPDOC =  5        THEN 'Facturi import furnizori'
      WHEN J.TIPDOC =  9        THEN 'Facturi la avize furnizori'
      WHEN J.TIPDOC = 16        THEN 'Monetare'
      WHEN J.TIPDOC = 19        THEN 'Facturi clienti'
      WHEN J.TIPDOC = 21        THEN 'Chitanta/bon clienti'
      WHEN J.TIPDOC = 26        THEN 'Facturi la avize clienti'
      WHEN J.TIPDOC = 28        THEN 'Compensari'
      WHEN J.TIPDOC = 29        THEN 'Tranzactii casa'
      WHEN J.TIPDOC = 30        THEN 'Tranzactii curente banca'
      WHEN J.TIPDOC = 31        THEN 'Tranzactii in curs banca'
      WHEN J.TIPDOC = 33        THEN 'Justificare Avans/Decontare'
      WHEN M.CODMACHETA IS NULL THEN '...nedefinit...'
      ELSE M.NUMEPRESC
    END                            COL04,--ANALYSISID                    NVARCHAR2(35)
    CASE
      WHEN J.TIPDOC =  1        THEN 'Intrari - facturi furnizori'
      WHEN J.TIPDOC =  3        THEN 'Intrari - chitanta / bon fiscal'
      WHEN J.TIPDOC =  4        THEN 'Intrari - bonuri de achizitie persoane fizice'
      WHEN J.TIPDOC =  5        THEN 'Intrari - facturi import furnizori'
      WHEN J.TIPDOC =  9        THEN 'Intrari - facturi la aviz furnizori'
      WHEN J.TIPDOC = 16        THEN 'Monetare'
      WHEN J.TIPDOC = 19        THEN 'Iesiri - facturi clienti'
      WHEN J.TIPDOC = 21        THEN 'Iesiri - chitanta/bon'
      WHEN J.TIPDOC = 26        THEN 'Iesiri - facturi la avize clienti'
      WHEN J.TIPDOC = 28        THEN 'Compensari'
      WHEN J.TIPDOC = 29        THEN 'Trezorerie - tranzactii casa'
      WHEN J.TIPDOC = 30        THEN 'Trezorerie - tranzactii curente banca'
      WHEN J.TIPDOC = 31        THEN 'Trezorerie - tranzactii in curs banca'
      WHEN J.TIPDOC = 33        THEN 'Trezorerie - justificare avans/decontare'
      WHEN M.CODMACHETA IS NULL THEN '...nedefinit...'
      ELSE M.NUMEEXT
    END                            COL05 --ANALYSISIDDESCRIPTION         NVARCHAR2(256)
   FROM (SELECT DISTINCT TIPDOC FROM TMP_SAFT_JURNAL) J LEFT JOIN TMP_MACHETE M ON M.CODMACHETA = J.TIPDOC;

  PERFORM pkg_saft_PUT_INFO('15.Z','UMPLE_T15--SAF_ANALYSISTYPETABLEENTRY');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t16</obj_name>
  <obj_hashval>b805b04c89fbf31d66a20f22f4067186</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t16()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 13.12.2023
  PERFORM pkg_saft_PUT_INFO('16.A','UMPLE_T16--SAF_MOVEMENTTYPETABLEENTRY');
  INSERT INTO TMP_SAFT16
  SELECT
    NEXTVAL('SEQ_SAFT') COL01,--CODSAF_MOVEMENTTYPETABLEENTRY NUMBER(20)
    MOVEMENTTYPE        COL02,--MOVEMENTTYPE                  NVARCHAR2(9)
    CASE MOVEMENTTYPE
      WHEN  '10' THEN 'Achizitie'
      WHEN  '20' THEN 'Productie'
      WHEN  '30' THEN 'Vânzare'
      WHEN  '40' THEN 'Retur produse vândute'
      WHEN  '50' THEN 'Retur produse achizitionate'
      WHEN  '60' THEN 'Reduceri comerciale primite'
      WHEN  '70' THEN 'Consum'
      WHEN  '80' THEN 'Transfer intern'
      WHEN  '90' THEN 'Cheltuieli ulterioare incluse în valoarea de intrare'
      WHEN '100' THEN 'Diferente de pret'
      WHEN '110' THEN 'Plus de inventar'
      WHEN '120' THEN 'Minus de inventar'
      WHEN '130' THEN 'Ajustari pentru deprecierea stocurilor'
      WHEN '140' THEN 'Reluari de ajustari pentru deprecierea stocurilor'
      WHEN '150' THEN 'Bunuri acordate cu titlu gratuit'
      WHEN '160' THEN 'Bunuri degradate'
      WHEN '170' THEN 'Bunuri expirate'
      WHEN '180' THEN 'Alte tranzactii'
    END                 COL03 --DESCRIPTION                   NVARCHAR2(256)
  FROM (SELECT DISTINCT MOVEMENTTYPE FROM TMP_SAFT_STOCKMOVEMENT) subs;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t17</obj_name>
  <obj_hashval>84f301830bb0e84008ef7cc9350f8a0c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t17()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vAL NUMERIC;
BEGIN
  --Florin 21.11.2023 - fixat 60132
  PERFORM pkg_saft_PUT_INFO('17.A','UMPLE_T17--SAF_PRODUCT');

  SELECT ANFIN*12+LUNAFIN INTO vAL FROM TMP_SAFT_PARAMS;

  INSERT INTO TMP_SAFT17
  SELECT
    C17.CODSAF                   COL01,--CODSAF_PRODUCT               NUMBER(20)
    To_Char(O.CodObiect)         COL02,--PRODUCTCODE                  NVARCHAR2(70)
    CAST(NULL AS VARCHAR(9)  )   COL03,--GOODSSERVICESID              NVARCHAR2(9)
    CAST(NULL AS VARCHAR(70) )   COL04,--PRODUCTGROUP                 NVARCHAR2(70)
    O.Denumire                   COL05,--DESCRIPTION                  NVARCHAR2(256)
    Coalesce(CN8.CN, '0')        COL06,--PRODUCTCOMMODITYCODE         NVARCHAR2(35)
    CAST(NULL AS VARCHAR(70) )   COL07,--PRODUCTNUMBERCODE            NVARCHAR2(70)
    CAST(NULL AS VARCHAR(9)  )   COL08,--VALUATIONMETHOD              NVARCHAR2(9)
    SUBSTR(UMS.CODSAFT, 1, 9)    COL09,--UOMBASE                      NVARCHAR2(9)
    SUBSTR(UMS.CODSAFT, 1, 9)    COL10,--UOMSTANDARD                  NVARCHAR2(9)
    U.PARITATEUMSAFT             COL11,--UOMTOUOMBASECONVERSIONFACTOR NUMBER(22,7)
    C18.CODSAF                   COL12 --CODSAF_TAX                   NUMBER(20)
  FROM TMP_SAFT_CODSAF C17
    LEFT JOIN NARTOBJ                O   ON O.CODOBIECT   = C17.CodSursa
    LEFT JOIN NART                   A   ON A.CODARTICOL  = O.CODARTICOL
    LEFT JOIN NArt1                  AL  ON AL.CODARTICOL = O.CODARTICOL     AND vAL BETWEEN AL.ALStart AND AL.ALStop
    LEFT JOIN NTva1                  TL  ON TL.CodTVA     = AL.CodTVA        AND vAL BETWEEN TL.ALStart AND TL.ALStop
    LEFT JOIN WINMADMIN.INTRASTAT_NC CN8 ON CN8.CN        = Trim(O.CODVAMAL)
    LEFT JOIN NUM                    U   ON U.CODUM       = A.UM LEFT JOIN NUM1                   U1  ON U1.CODUM      = U.CODUM          AND U1.SECUNDARA = 0
    LEFT JOIN WINMADMIN.NUMSAFT      UMS ON UMS.CODUMSAFT = U.CODUMSAFT
    LEFT JOIN TMP_SAFT_CODSAF        C18 ON C18.CODSURSA  = TL.CodTVA        AND C18.CODSAFTTAB = 18
      WHERE C17.CODSAFTTAB = 17;

  PERFORM pkg_saft_PUT_INFO('17.Z','UMPLE_T17--SAF_PRODUCT');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t18</obj_name>
  <obj_hashval>98466ea0896a8ccd0841689111186541</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t18()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 06.10.2022 - sinc. Oracle
  --Florin 08.02.2022 - sinc. Oracle
  --Florin 06.01.2022
  PERFORM pkg_saft_PUT_INFO('18.A','UMPLE_T18--SAF_TAX');

  INSERT INTO TMP_SAFT18
  SELECT
    nextval('SEQ_SAFT')                  COL01,--CODSAF_TAX NUMBER(20)
    To_Char(C12.CODSURSA, 'fm999999990') COL02,--TAXTYPE    NVARCHAR2(9)
    To_Char(C13.CODSURSA, 'fm999999990') COL03 --TAXCODE    NVARCHAR2(9)
  FROM TMP_SAFT_CODSAF C13 LEFT JOIN TMP_SAFT_CODSAF C12 ON C12.CODSAF = C13.CODPARINTE
  WHERE C13.CODSAFTTAB = 13;

  PERFORM pkg_saft_PUT_INFO('18.Z','UMPLE_T18--SAF_TAX');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t20</obj_name>
  <obj_hashval>625d43524eb9cffd4811e27a3a4278c5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t20()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 21.11.2023 - fixat 60132
  --Stef   27.07.2023
  PERFORM pkg_saft_PUT_INFO('20.A','UMPLE_T20--SAF_STOCKCHARACTERISTICS');

  INSERT INTO TMP_SAFT20
  SELECT
    20                                COL01,--CODSAF_STOCKCHARACTERISTICS NUMBER(20)
    '0'                               COL02,--STOCKCHARACTERISTIC         NVARCHAR2(18)
    NULL                              COL03;--STOCKCHARACTERISTICVALUE    NVARCHAR2(35)

  INSERT INTO TMP_SAFT20
  SELECT
    C20.CODSAF                        COL01,--CODSAF_STOCKCHARACTERISTICS NUMBER(20)
    Coalesce(O.COL02, SF.COL02, '0')  COL02,--STOCKCHARACTERISTIC         NVARCHAR2(18)
    Coalesce(O.COL03, SF.COL03)       COL03 --STOCKCHARACTERISTICVALUE    NVARCHAR2(35)
  FROM TMP_SAFT_CODSAF C20
    LEFT JOIN (
      SELECT
        O.CODOBIECT,
        CASE A.TIPSTOC
          WHEN 1 THEN 'Blue35'
          WHEN 2 THEN 'Yellow124'
          ELSE '0'
        END AS COL02,
        Substr(
          CASE WHEN Coalesce(O.MASA,  0) &lt;&gt; 0 THEN To_Char(O.MASA) ||'KG' ELSE '' END||
          CASE WHEN Coalesce(O.VOLUM, 0) &lt;&gt; 0 THEN To_Char(O.VOLUM)||'L'  ELSE '' END,
          1, 35
        ) AS COL03
      FROM NARTOBJ O INNER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
      WHERE A.TIPSTOC IN (1, 2)
    ) O ON O.CODOBIECT = C20.CODSURSA
    LEFT JOIN (
      SELECT
        SF.CODOBIECT,
        Max(STOCKCHARACTERISTICS) AS COL02,
        Max(STOCKCHARACTERISTICVALUE) AS COL03
      FROM TMP_SAFT_PARAMS SP
        INNER JOIN STOCFAKE SF ON SF.AN = SP.ANFIN AND SF.LUNA = SP.LUNAFIN
        LEFT  JOIN NARTOBJ  O  ON O.CODOBIECT  = SF.CODOBIECT
        LEFT  JOIN NART     A  ON A.CODARTICOL = O.CODARTICOL
      WHERE A.CODARTICOL IS NOT NULL
        AND Coalesce(SF.STOCKCHARACTERISTICS, '0') &lt;&gt; '0'
      GROUP BY SF.CODOBIECT
    ) SF ON SF.CODOBIECT = C20.CODSURSA;
  PERFORM pkg_saft_PUT_INFO('20.Z','UMPLE_T20--SAF_STOCKCHARACTERISTICS');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t22</obj_name>
  <obj_hashval>499ec94acbb2759891f34bdcdda815bf</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t22()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 30.10.2025 - sinc. Oracle
  --Stef  25.05.2023
  INSERT INTO TMP_SAFT22
  SELECT
    C22.CODSAF                  COL01,--CODSAF_ASSET         NUMBER(20)
    M.NRINVENTAR                COL02,--ASSETID              NVARCHAR2(35)
    C.CODSAFT                   COL03,--ACCOUNTID            NVARCHAR2(70)
    O.DENUMIRE                  COL04,--DESCRIPTION          NVARCHAR2(256)
    C23.CODSAF                  COL05,--CODSAF_ASSETSUPPLIER NUMBER(20)
    NULL                        COL06,--PURCHASEORDERDATE    DATE
    COALESCE(NS.DATAACHIZ, N.DATANIR) COL07,--DATEOFAQUISITION     DATE
    CASE
      WHEN M.ANINTRARE IS NULL
      THEN To_Date(To_Char(M1.ANSTART,  '0000')||To_Char(M1.LUNASTART,  '00')||'01','YYYYMMDD')
      ELSE To_Date(To_Char(M.ANINTRARE, '0000')||To_Char(M.LUNAINTRARE, '00')||'01','YYYYMMDD')
    END                         COL08,--STARTUPDATE          DATE
    C59.CODSAF                  COL09 --CODSAF_VALUATIONS    NUMBER(20)
  FROM TMP_SAFT_CODSAF C22
    LEFT JOIN TMP_SAFT_CODSAF C59 ON C59.CODPARINTE = C22.CODSAF           AND C59.CodSAFTTab = 59
    LEFT JOIN MIFIX           M   ON M.CODMIFIX     = C22.CODSURSA
    LEFT JOIN MIFIX1          M1  ON M1.CODMIFIX1   = C22.CODAUX
    LEFT JOIN NIRSTOC         NS  ON NS.CODNIRSTOC  = M1.CODNIRSTOC
    LEFT JOIN NIR             N   ON N.CODNIR       = NS.CODNIR
    LEFT JOIN TMP_SAFT_CODSAF C23 ON C23.CODSURSA   = Coalesce(NS.FURN, 0) AND C23.CodSAFTTab = 23
    LEFT JOIN NARTOBJ         O   ON O.CODOBIECT    = NS.CODOBIECT
    LEFT JOIN IOART1          I1  ON I1.CODIOART    = NS.CODIOART          AND M1.ANSTART*12+M1.LUNASTART BETWEEN I1.ALSTART AND I1.ALSTOP
    LEFT JOIN TMP_SAFT_NCONT  C   ON C.CODCONT      = I1.CONT
  WHERE C22.CodSAFTTab = 22;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t24</obj_name>
  <obj_hashval>e7e15d3179b8cb0a7ae6bc1e0ed60fbd</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t24()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  SP_ALFIN  NUMERIC;
  CImbMifix text;
  cHolding  numeric;
BEGIN
  --Florin 16.12.2025 - sinc. Oracle
  --Florin 10.12.2025 - sinc. Oracle
  --Florin 27.11.2025 - sinc. Oracle
  --Florin 17.11.2025 - sinc. Oracle
  --Florin 06/07.11.2025 - sinc. Oracle
  --Florin 30.10.2025 - sinc. Oracle
  --Florin 21/22.10.2025 - sinc. Oracle
  --Stef 01.08.2025 - sinc. Oracle
  --Florin 23.05.2025 - sinc. Oracle
  --Stef 29.04.2025 - sinc. Oracle
  perform pkg_saft_PUT_INFO('24.A','UMPLE_T24--SAF_VALUATION');
  SELECT ANFIN*12+LUNAFIN, Coalesce(fnc_GetValConstanta('HOLDING', ANFIN, LUNAFIN),'-1')
  INTO SP_ALFIN          , cHolding
  FROM TMP_SAFT_PARAMS;

  SELECT
    Max(COL01) COL01,
    COL02, COL03,
    Max(COL04) COL04,
    CASE
      WHEN Max(J1I_TIPDOC) = 35 THEN Max(COL05)
      WHEN Max(IDX_GRUP) &gt;1     THEN Max(COL05)
      ELSE                           Sum(COL05)
    END COL05,
    CASE
      WHEN Max(J1I_TIPDOC) = 35 THEN Max(COL06)
      WHEN Max(IDX_GRUP) &gt;1     THEN Max(COL06)
      ELSE                           Sum(COL06)
    END COL06,
    Sum(COL07), Max(COL08), Max(COL09),
    Sum(COL10),
    CASE
      WHEN Max(IDX_GRUP) &gt;1       AND Max(M1_F_STARE) = 7
        AND Max(CONT_TRANSF) &lt;&gt; Max(TNB_CODUNIC)               THEN Sum(COL11)
      WHEN Max(IDX_GRUP) &gt;1       AND Max(M1_F_STARE) = 7
        AND Max(J1I_TIPDOC) = 23                               THEN Sum(COL11)
      WHEN Max(IDX_GRUP) &gt;1       AND Max(M1_F_STARE) = 7      THEN Max(COL11)
      ELSE                                                          Sum(COL11)
    END COL11,
    Sum(COL12), Max(COL13), Max(COL14), Max(COL15),
    CASE
      WHEN Max(M1_I_AMO) &gt; Max(M1_F_AMO)
        AND Max(J1I_TIPDOC) = 35     THEN Max(COL16) - Max(AMORTIZ_EXTRAORD)
      WHEN Max(J1I_TIPDOC) = 35      THEN Max(COL16)
      WHEN Max(M1_F_STARE) IN (8,9)  THEN Sum(COL16)
      WHEN Max(IDX_GRUP) &gt;1          THEN Max(COL16)
      ELSE                                Sum(COL16)
    END COL16,
    Sum(COL17), Max(COL18), Max(COL19),
    --BOOKVALUEEND = BOOKVALUEBEGIN (DOAR PRIMA LINIE) + ASSETADDITION + TRANSFERS + ASSETDISPOSAL + DEPRECIATIONFORPERIOD + APPRECIATIONFORPERIOD
    CASE
      WHEN Max(M1_F_STARE) IN (3, 4, 7, 8, 9, 10) OR Max(J1I_TIPDOC) = 23      THEN 0
      WHEN Max(J1I_TIPDOC) = 12   AND Max(J1I_VALOARE) &lt; 0                     THEN 0
      ELSE (
        CASE
          WHEN Max(J1I_TIPDOC) = 6
          THEN Max(COL13)+ Sum(COL10) + Sum(COL11) + Sum(COL12) + Sum(COL17) - Max(NS_F_PROVIZION) + Max(COL19)
          WHEN Max(J1I_TIPDOC) = 35 AND Max(M1_I_AMO) &lt; Max(M1_F_AMO)
          THEN Max(COL13)+ Sum(COL10) + Sum(COL11) + Sum(COL12) + Max(COL16) + Sum(COL17) - Max(NS_F_PROVIZION) + Min(AMORTIZ_EXTRAORD)
          WHEN Max(J1I_TIPDOC) = 35
          THEN Max(COL13)+ Sum(COL10) + Sum(COL11) + Sum(COL12) + Max(COL16) + Sum(COL17) - Max(NS_F_PROVIZION)
          WHEN Max(IDX_GRUP)&gt;1
          THEN Max(COL13)+ Sum(COL10) + Sum(COL11) + Sum(COL12) + Max(COL16) + Sum(COL17) - Max(NS_F_PROVIZION)
          ELSE (
            CASE WHEN Min(IDX_GRUP) = 1 THEN Max(COL13) ELSE 0 END +
            CASE
              WHEN Max(IDX_GRUP) = 1 AND Max(M1_A_CODMIFIX1) IS NULL AND Max(M1_I_AMO) &gt; 0
                AND Max(M_I_ANINTRARE)*12 + Max(M_I_LUNAINTRARE) &lt; SP_ALINI                   THEN 0
              WHEN Max(IDX_GRUP) = 1 AND Max(M1_A_CODMIFIX1) IS NULL AND Max(M1_I_AMO) &gt; 0    THEN Max(COL19) - Max(COL16)
              ELSE                                                                                 0
              END +
        Sum(COL10) + Sum(COL11) + Sum(COL12) + Sum(COL16) + Sum(COL17) - Max(NS_F_PROVIZION))
        END)
    END COL20 --BOOKVALUEEND                               NUMBER(18,2)
  FROM (
    SELECT
      COL01, COL02, COL03, COL04, COL05, COL06, COL07, COL08, COL09, COL10,
      CASE
        WHEN J1I_TIPDOC = 1                                                                THEN 0
        WHEN J1I_TIPDOC = 6                   AND cHolding = 2                             THEN M1_I_pret
        WHEN J1I_TIPDOC = 15                  AND J1I_TIPTRANZACTIE = 5                    THEN M1_I_pret
        WHEN J1I_TIPDOC = 12                  AND J1I_ASSETTRANSACTIONTYPE = ('100')       THEN 0
       -- WHEN J1I_TIPDOC = 12                  AND M1_F_ALSTART = SP_ALFIN                  THEN M1_I_pret - M1_I_amo
        WHEN J1I_TIPDOC = 12                  AND M1_F_STARE = 7
          AND  CONT_TRANSF &lt;&gt; Coalesce(TNB_CODUNIC,0)                                      THEN - M1_F_PRET
        WHEN J1I_TIPDOC = 12                  AND M1_F_STARE = 7                           THEN M1_F_amo  - M1_F_PRET
        WHEN J1I_TIPDOC = 12                  AND J1I_VALOARE &lt; 0                          THEN - M1_F_PRET
        WHEN J1I_TIPDOC = 7                                                                THEN M1_I_PRET
        WHEN J1I_TIPDOC = 35                                                               THEN 0
        WHEN J1I_TIPDOC = 23                                                               THEN - M1_F_PRET
        WHEN M1_F_STARE = 4                   AND J1I_ASSETTRANSACTIONTYPE =('40')         THEN - Coalesce(M1_F_PRET, 0)
        WHEN J1I_TIPDOC = 13                  AND J1I_TIPTRANZACTIE = 0
         AND J1I_ASSETTRANSACTIONTYPE IN ('40')                                            THEN J1I_VALOARE
        WHEN J1IS_ASSETTRANSACTIONTYPE IN ('20') AND J1IS_VALOARE &lt; 0                      THEN 0
        WHEN J1I_TIPDOC = 13                  AND TM_CODUNIC IS NOT NULL
         AND J1I_ASSETTRANSACTIONTYPE IN ('40')                                            THEN M1_I_PRET
        WHEN J1I_TIPDOC = 13                  AND J1I_ICONTC = 3
         AND J1I_ASSETTRANSACTIONTYPE IN ('40')                                            THEN M1_I_PRET
        WHEN NS_A_CODIOART =  NS_I_CODIOART   AND IDX_GRUP =1
         AND MAX(IDX_GRUP) OVER (PARTITION BY COL02) &gt; 1                                   THEN M1_U_amo  - M1_U_PRET
        WHEN M1_U_CODMIFIX IS NULL            AND M1_F_STARE IN (3,4)                      THEN 0
        WHEN M1_U_CODMIFIX IS NULL            AND NOT M1_F_STARE IN (8, 9)                 THEN M1_F_amo  - M1_F_PRET
        ELSE                                                                                    0
      END                                      COL11,---TRANSFERS                                  NUMBER(18,2)
      COL12, COL13, COL14, COL15, COL16, COL17, COL18, COL19,
      IDX_GRUP, M1_F_STARE, NS_F_PROVIZION, M1_A_CODMIFIX1, M1_I_AMO,J1I_TIPDOC, M_I_ANINTRARE, M_I_LUNAINTRARE,
      AMORTIZ_EXTRAORD, M1_F_AMO, CONT_TRANSF, TNB_CODUNIC, J1I_VALOARE
    FROM (
      SELECT
        C24.CODSAF                             COL01,--CODSAF_VALUATION                           NUMBER(20)
        C24.CODPARINTE                         COL02,--CODSAF_MASTER                              NUMBER(20)
        'CONTABIL'                             COL03,--ASSETVALUATIONTYPE                         NVARCHAR2(18)
        SubStr(Trim(MFCL.SIMBOL),1,18)         COL04,--VALUATIONCLASS                             NVARCHAR2(18)
        CASE
          WHEN J1IS.ASSETTRANSACTIONTYPE =('20')    AND J1IS.VALOARE &lt; 0              THEN 0
          WHEN J1I.TIPDOC = 6                                                         THEN 0
          WHEN M_I.ANINTRARE*12+M_I.LUNAINTRARE &lt; SP_ALINI                            THEN Coalesce(M1_I.PRET, 0)
          WHEN M1_A.CODMIFIX IS NULL                AND Coalesce(J1I.TIPDOC, 0) = 12  THEN 0
          WHEN Coalesce(J1I.TIPDOC, 0) = 12                                           THEN Coalesce(M1_I.PRET, 0)
          WHEN J1I.ASSETTRANSACTIONTYPE =('40')     AND M1_I.STARE = 4                THEN Coalesce(M1_I.PRET, 0)
          WHEN J1I.ASSETTRANSACTIONTYPE =('10')     AND M1_I.STARE IN (8,9)
            AND  M1_I.AMO &gt; 0                                                         THEN Coalesce(M1_I.PRET, 0)
          WHEN (EXTRACT (YEAR FROM NS_I.DATAACHIZ) *12 + EXTRACT (MONTH FROM NS_I.DATAACHIZ)) &lt;  M1_I.ANSTART*12+M1_I.LUNASTART
            AND J1I.TIPDOC = 35                                                       THEN Coalesce(M1_I.PRET, 0)
          WHEN (EXTRACT (YEAR FROM NS_I.DATAACHIZ) *12 + EXTRACT (MONTH FROM NS_I.DATAACHIZ)) &lt;  M1_I.ANSTART*12+M1_I.LUNASTART
            AND J1I.ASSETTRANSACTIONTYPE &lt;&gt;('10')                                     THEN Coalesce(M1_I.PRET, 0)
          WHEN J1I.CODJURNAL1 IS NOT NULL                                             THEN 0
          ELSE                                                                             Coalesce(M1_I.PRET, 0)
        END                                    COL05,--ACQUISITIONANDPRODUCTIONCOSTSBEGIN         NUMBER(18,2)
        CASE
          WHEN M1_F.STARE IN (3, 4, 7, 8, 9,10)     THEN 0
          WHEN J1I.TIPDOC = 23                      THEN 0
          WHEN J1I.TIPDOC = 12 AND J1I.VALOARE &lt; 0  THEN 0
          ELSE                                      Coalesce(M1_F.PRET, 0)
        END                                    COL06,--ACQUISITIONANDPRODUCTIONCOSTSEND           NUMBER(18,2)
        Coalesce(
          (
            SELECT Sum(Coalesce(c1.valoare - c1.amo, 0))
            FROM cheltavans c INNER JOIN cheltavans1 c1 ON c1.codcheltavans = c.codcheltavans
            WHERE c.codmifix = M1_F.CODMIFIX and c1.anstart *12 + c1.lunastart = SP_ALFIN + 1
          ), 0
        )                                      COL07,--INVESTMENTSUPPORT                          NUMBER(18,2)
        Coalesce(MFCL.DURATA, M1_F.DURATAN, 0) COL08,--ASSETLIFEYEAR                              NUMBER(22,7)
        NULL                                   COL09,--ASSETLIFEMONTH                             NUMBER(22,7)
        (
          SELECT Coalesce(Sum(TJ1.VALOARE), 0)
          FROM TMP_SAFT_JURNAL1 TJ1
          WHERE TJ1.CODMIFIX = M1_I.CODMIFIX
            AND TJ1.TIPDOC = 13
            AND TJ1.ASSETTRANSACTIONTYPE IN ('130')
            AND TJ1.AN*12+ TJ1.LUNA BETWEEN M1_I.ANSTART*12+M1_I.LUNASTART  AND M1_F.ANSTART*12+M1_F.LUNASTART
        ) +
        CASE
          --WHEN J1I.ASSETTRANSACTIONTYPE IN ('10') THEN Coalesce(M1_I.PRET, 0)
          WHEN Coalesce(NS_I.CANTNIR, 0) = 0
           AND J1I.ASSETTRANSACTIONTYPE IN ('10') THEN J1I.VALOARE
          WHEN J1I.ASSETTRANSACTIONTYPE IN ('10') THEN J1I.VALOARE / NS_I.CANTNIR
          WHEN J1I.ASSETTRANSACTIONTYPE IN ('40')
           AND TM.CODUNIC IS NOT NULL             THEN 0
          WHEN J1I.ASSETTRANSACTIONTYPE IN ('40')
           AND J1I.ICONTC IN (2,3)                THEN 0
          WHEN J1I.ASSETTRANSACTIONTYPE IN ('80') THEN Coalesce(M1_I.PRET, 0)
          ELSE                                         0
        END                                    COL10,--ASSETADDITION                              NUMBER(18,2)
        (
          SELECT Max(IOA1.CONT)
          FROM TMP_SAFT_JURNAL1 TJ1
          LEFT JOIN TRANSF   T      ON T.CODTRANSF   = TJ1.CODDOC AND T.TIPDOC = TJ1.TIPDOC
          LEFT JOIN TRANSF1  T1     ON T1.CODTRANSF  = T.CODTRANSF
          LEFT JOIN NIRSTOC  NS     ON NS.CODTRANSF1 = T1.CODTRANSF1
          LEFT JOIN IOART    IOA    ON IOA.CODIOART  = NS.CODIOART
          LEFT JOIN IOART1   IOA1   ON IOA1.CODIOART = IOA.CODIOART AND TJ1.AN*12+TJ1.LUNA BETWEEN IOA1.ALSTART  AND IOA1.ALSTOP
          WHERE TJ1.CODMIFIX1 = M1_F.CODMIFIX1 AND TJ1.TIPDOC = 12
          GROUP BY TJ1.CODMIFIX1
            )                                   CONT_TRANSF,
        CASE
          WHEN J1IS.ASSETTRANSACTIONTYPE IN ('20') AND Coalesce(J1IS.VALOARE,0) &lt; 0 THEN Coalesce(M1_I.PRET, 0)
          WHEN M1_F.STARE IN (3)                                                    THEN - Coalesce(M1_F.pret, 0) -- Coalesce(M1_F.amo, 0)
          WHEN M1_F.STARE IN (4)  AND J1I.ASSETTRANSACTIONTYPE IN ('40')            THEN 0
          WHEN M1_F.STARE IN (4)  AND J1I.ASSETTRANSACTIONTYPE IN ('10')
            AND (
            SELECT COUNT(*)
            FROM TMP_SAFT_JURNAL1 TJ1
            WHERE TJ1.CODMIFIX = M1_I.CODMIFIX
                  AND TJ1.ASSETTRANSACTIONTYPE = '40'
            GROUP BY TJ1.CODMIFIX
          ) &gt;= 1                                                                    THEN 0
          WHEN M1_F.STARE IN (4)                                                    THEN - Coalesce(M1_F.pret, 0)
          ELSE                                                                           0
        END                                   COL12,--ASSETDISPOSAL                              NUMBER(18,2)
        CASE
          WHEN J1I.TIPDOC = 6                                           THEN 0
          WHEN (EXTRACT (YEAR FROM NS_I.DATAACHIZ) *12 + EXTRACT (MONTH FROM NS_I.DATAACHIZ)) &lt;  M1_I.ANSTART*12+M1_I.LUNASTART
            AND Coalesce(J1I.TIPDOC, 0) = 35                            THEN Coalesce(M1_I.pret, 0) - Coalesce(M1_I.amo,  0)
          WHEN Coalesce(J1I.TIPDOC, 0) = 12
           AND SP_ALFIN = M1_F.ANSTART *12 + M1_F.LUNASTART             THEN Coalesce(M1_I.pret, 0) - Coalesce(M1_I.amo,  0)
          WHEN Coalesce(J1I.TIPDOC, 0) = 12                             THEN Coalesce(M1_I.pret, 0) - Coalesce(M1_I.amo,  0)
          WHEN (EXTRACT (YEAR FROM NS_I.DATAACHIZ) *12 + EXTRACT (MONTH FROM NS_I.DATAACHIZ)) &lt;  M1_I.ANSTART*12+M1_I.LUNASTART
           AND J1I.ASSETTRANSACTIONTYPE &lt;&gt;('10')                        THEN coalesce(M1_I.pret, 0) - Coalesce(M1_I.amo,  0)
          WHEN J1I.CODJURNAL1 IS NOT NULL                               THEN 0
          WHEN M1_F.STARE IN (4)                                        THEN 0
          WHEN J1IS.ASSETTRANSACTIONTYPE IN ('20')
            AND Coalesce(J1IS.VALOARE,0) &lt; 0                            THEN 0
          ELSE                                                               Coalesce(M1_I.pret, 0) - Coalesce(M1_I.amo,  0)
        END                                    COL13,--BOOKVALUEBEGIN                             NUMBER(18,2)
        CASE
          WHEN M1_F.TIPAMO = 1 THEN 'LINIARA'
          WHEN M1_F.TIPAMO = 2 THEN 'ACCELERATA'
          WHEN M1_F.TIPAMO = 3 THEN 'DEGRESIVA'
          WHEN M1_F.TIPAMO = 4 THEN 'DEGRESIVA'
          ELSE                      '...'
        END                                    COL14,--DEPRECIATIONMETHOD                         NVARCHAR2(35)
        CASE
          WHEN Coalesce(MFCL.DURATA, M1_F.DURATAN, 0) = 0 THEN 0
          ELSE Round(1/Coalesce(MFCL.DURATA, M1_F.DURATAN), 2)
        END                                    COL15,--DEPRECIATIONPERCENTAGE                     NUMBER(22,7)
        CASE
          WHEN M1_F.STARE IN (4)  AND J1I.ASSETTRANSACTIONTYPE IN ('10')
            AND (
            SELECT COUNT(*)
            FROM TMP_SAFT_JURNAL1 TJ1
            WHERE TJ1.CODMIFIX = M1_I.CODMIFIX
                  AND TJ1.ASSETTRANSACTIONTYPE = '40'
            GROUP BY TJ1.CODMIFIX
          ) &gt;= 1                                                                      THEN 0
          WHEN M1_F.STARE = 4 AND Coalesce(M1_I.AMO, 0) - Coalesce(M1_F.AMO, 0) = 0   THEN 0
          WHEN M1_F.STARE = 4                                                         THEN Coalesce(M1_I.AMO,0) - Coalesce(M1_F.AMO,0)
          WHEN COALESCE(M1_I.TIPSTORNO,0) = 0 AND M1_F.Stare = 8
            and J1I.TIPTRANZACTIE = 1                                                 THEN 0
          WHEN (COALESCE(M1_F.TIPSTORNO,0) IN (1,2) AND M1_F.Stare = 8)
            OR (M1_F.Stare IN (9))                                                    THEN (
                         SELECT Sum(-TJ1.VALOARE)
                            FROM TMP_SAFT_JURNAL1 TJ1
                            WHERE TJ1.CODMIFIX = M1_I.CODMIFIX
                                  AND TJ1.TIPDOC = 36
                                  AND TJ1.ASSETTRANSACTIONTYPE = '30'
                            GROUP BY TJ1.CODMIFIX
                            )
          WHEN M1_F.Stare IN (7)                                                      THEN Coalesce(M1_I.AMO, 0) - Coalesce(M1_F.AMO, 0)
          WHEN J1I.TIPDOC = 35                                                        THEN Coalesce(M1_I.AMO, 0) - Coalesce(M1_U.AMO, 0) -
                CASE
                   WHEN TNA.CODUNIC IS NOT NULL                                       THEN(
                          SELECT SUM(-J1.VALOARE)
                             FROM TMP_SAFT_JURNAL1 J1
                             WHERE J1.CODMIFIX = M1_F.CODMIFIX
                                   AND J1.CONTD = (SELECT DISTINCT CODUNIC FROM TMP_SAFT_MANEVRA WHERE FILTRU IN ('CRezRepAmoMifixNC'))
                             GROUP BY J1.CODMIFIX
                          )
                   ELSE                                                                    0
                 END
          WHEN J1I.TIPDOC = 23                                                        THEN Coalesce(M1_I.AMO, 0) - Coalesce(M1_F.AMO, 0)
          WHEN J1I.TIPDOC = 12 AND J1I.VALOARE &lt; 0                                    THEN Coalesce(M1_I.AMO, 0) - Coalesce(M1_F.AMO, 0) -
                                                                                           Round(((Coalesce(M1_F.PRET,0) - Coalesce(M1_F.AMO, 0))/M1_F.DURATAF),3)
          ELSE                                                                             Coalesce(M1_I.AMO, 0) - Coalesce(M1_U.AMO, 0)
        END                                    COL16,--DEPRECIATIONFORPERIOD                      NUMBER(18,2)
        CASE
          WHEN
            EXISTS (
              SELECT 1
              FROM MIFIX1 M1
              WHERE M1.CODMIFIX = M1_I.CODMIFIX
                AND M1.ANSTART*12+M1.LUNASTART BETWEEN M1_I.ANSTART*12+M1_I.LUNASTART AND M1_F.ANSTART*12+M1_F.LUNASTART
                AND M1.TIPREEVAL IN (0, 1)
            )
          THEN Coalesce(NS_F.PRET, 0) - Coalesce(NS_I.PRET, 0)
          ELSE 0
        END                                 COL17,--APPRECIATIONFORPERIOD                      NUMBER(18,2)
        C60.CODSAF                          COL18,--CODSAF_EXTRAORDINARYDEPRECIATIONSFORPERIOD NUMBER(20)
        CASE
          WHEN M1_F.STARE IN (3, 4, 7, 8, 9, 10)       THEN 0
          WHEN J1I.TIPDOC IN (23)                      THEN 0
          WHEN J1I.TIPDOC IN (12) AND J1I.VALOARE &lt; 0  THEN 0
          WHEN M1_U.CODMIFIX IS NULL                   THEN - Coalesce(M1_F.amo, 0)
          ELSE                                              - Coalesce(M1_U.amo, 0)
        END                                 COL19,--ACCUMULATEDDEPRECIATION                    NUMBER(18,2)
        CASE
           WHEN TNA.CODUNIC IS NOT NULL           THEN(
                SELECT SUM(-J1.VALOARE)
                FROM TMP_SAFT_JURNAL1 J1
                WHERE J1.CODMIFIX = M1_F.CODMIFIX
                      AND J1.CONTD = (SELECT DISTINCT CODUNIC FROM TMP_SAFT_MANEVRA WHERE FILTRU IN ('CRezRepAmoMifixNC'))
                GROUP BY J1.CODMIFIX
                          )
           ELSE                                        0
        END                                 AMORTIZ_EXTRAORD,
        Row_Number() OVER (PARTITION BY C24.CODPARINTE ORDER BY M1_I.ANSTART, M1_I.LUNASTART) IDX_GRUP,
        Coalesce(J1I.TIPDOC, 0) J1I_TIPDOC,
        M1_F.ANSTART*12+M1_F.LUNASTART M1_F_ALSTART,
        Coalesce(M1_A.pret,0) M1_A_Pret, Coalesce(M1_A.amo, 0) M1_A_amo, Coalesce(M1_A.CODCLASIF, 0) M1_A_CODCLASIF,  M1_A.CODMIFIX1 M1_A_CODMIFIX1,
        Coalesce(M1_I.pret,0) M1_I_Pret, Coalesce(M1_I.amo, 0) M1_I_amo, Coalesce(M1_I.CODCLASIF, 0) M1_I_CODCLASIF,
        Coalesce(M1_F.pret,0) M1_F_Pret, Coalesce(M1_F.amo, 0) M1_F_amo, Coalesce(M1_F.CODCLASIF, 0) M1_F_CODCLASIF, Coalesce(M1_F.STARE, 0) M1_F_STARE,
        Coalesce(M1_U.pret,0) M1_U_Pret, Coalesce(M1_U.amo, 0) M1_U_amo, Coalesce(M1_U.CODCLASIF, 0) M1_U_CODCLASIF,
        M1_U.CODMIFIX M1_U_CODMIFIX, NS_A.CODIOART NS_A_CODIOART, NS_I.CODIOART NS_I_CODIOART, COALESCE(NS_F.PROVIZION,0) NS_F_PROVIZION,
        J1I.ASSETTRANSACTIONTYPE J1I_ASSETTRANSACTIONTYPE, J1I.ICONTC J1I_ICONTC, TM.CODUNIC TM_CODUNIC, J1I.TIPTRANZACTIE J1I_TIPTRANZACTIE,
        J1IS.ASSETTRANSACTIONTYPE J1IS_ASSETTRANSACTIONTYPE, Coalesce(J1IS.VALOARE,0) J1IS_VALOARE, J1I.VALOARE J1I_VALOARE,
        M_I.ANINTRARE M_I_ANINTRARE, M_I.LUNAINTRARE M_I_LUNAINTRARE, TNB.CODUNIC TNB_CODUNIC
      FROM TMP_SAFT_CODSAF C24
        LEFT  JOIN TMP_SAFT_CODSAF   C59   ON C59.CODSAF      = C24.CODPARINTE -- DISCUTIE -&gt; C29.CODSURSA &lt;&gt; M1_F.CODMIFIX
        LEFT  JOIN TMP_SAFT_CODSAF   C60   ON C60.CODPARINTE  = C24.CODSAF     AND C60.CodSAFTTab = 60
        LEFT  JOIN MIFIX1            M1_I  ON M1_I.CODMIFIX1  = C24.CODAUX
        LEFT  JOIN MIFIX             M_I   ON M_I.CODMIFIX    = M1_I.CODMIFIX
        LEFT  JOIN MIFIX1            M1_A  ON M1_A.CODMIFIX   = M1_I.CODMIFIX  AND M1_A.ANSTART*12+M1_A.LUNASTART = M1_I.ANSTART*12+M1_I.LUNASTART-1
        LEFT  JOIN MIFIX1            M1_F  ON M1_F.CODMIFIX1  = C24.CODSURSA
        LEFT  JOIN MIFIX1            M1_U  ON M1_U.CODMIFIX   = M1_F.CODMIFIX  AND M1_U.ANSTART*12+M1_U.LUNASTART = M1_F.ANSTART*12+M1_F.LUNASTART+1
        LEFT  JOIN NIRSTOC           NS_A  ON NS_A.CODNIRSTOC = M1_A.CODNIRSTOC
        LEFT  JOIN NIRSTOC           NS_I  ON NS_I.CODNIRSTOC = M1_I.CODNIRSTOC
        LEFT  JOIN NIRSTOC           NS_F  ON NS_F.CODNIRSTOC = M1_F.CODNIRSTOC
        LEFT  JOIN MFCLASIF          MFCL  ON MFCL.CODCLASIF  = M1_F.CODCLASIF
        LEFT  JOIN TMP_SAFT_JURNAL1  J1I   ON J1I.CODMIFIX    = M1_I.CODMIFIX AND J1I.TIPDOC IN (1,2,3,4,5,6,7,12,13,15,23,35)
        LEFT  JOIN TMP_SAFT_JURNAL1  J1IS  ON J1IS.CODMIFIX   = M1_I.CODMIFIX AND J1IS.TIPDOC IN (19) AND Coalesce(J1IS.VALOARE,0) &lt; 0
        LEFT  JOIN (
          SELECT DISTINCT CODUNIC FROM TMP_SAFT_MANEVRA WHERE FILTRU IN ('CImbMifix', 'ProvMiFix')
        )                            TM    ON TM.CODUNIC      = J1I.CONTC
        LEFT  JOIN (
          SELECT DISTINCT CODUNIC FROM TMP_SAFT_MANEVRA WHERE FILTRU IN ('CCheltAmoMifixNC')
        )                            TNC   ON TNC.CODUNIC     = J1I.CODDESCRD
        LEFT  JOIN (
          SELECT DISTINCT CODUNIC FROM TMP_SAFT_MANEVRA WHERE FILTRU IN ('CRezRepAmoMifixNC')
        )                            TNA   ON TNA.CODUNIC     = J1I.CODDESCRD
        LEFT  JOIN (
          SELECT DISTINCT CODUNIC FROM TMP_SAFT_MANEVRA WHERE FILTRU IN ('CMifix')
        )                            TNB   ON TNB.CODUNIC     = J1I.CONTD
      WHERE C24.CodSAFTTab = 24
    ) sub_a
  ) sub_b
  GROUP BY COL02, COL03
  ORDER BY COL01 ASC;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t25</obj_name>
  <obj_hashval>4c35cca3fa7011ea0b5f91d8243fe086</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t25()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 16.12.2025 - sinc. Oracle
  --Florin 30.10.2025 - sinc. Oracle
  --Florin 21.10.2025 - sinc. Oracle
  --Stef  25.05.2023
  INSERT INTO TMP_SAFT25
  SELECT
    DISTINCT C25.CODSAF        COL01,--CODSAF_EXTRAORDINARYDEPRECIATIONSFORPERIOD NUMBER(20)
    C25.CODPARINTE             COL02,--CODSAF_MASTER                              NUMBER(20)
    CASE
      WHEN COALESCE(NS.PROVIZION,0) &lt;&gt; 0      THEN 'PROVIZION'
      WHEN J1.ASSETTRANSACTIONTYPE = '130'
        AND J1.ICONTD = 10 AND J1.ICONTC = 0  THEN 'AMORTIZARE TRECUTA PE VENIT'
      WHEN TNA.CODUNIC IS NOT NULL            THEN 'AMORTIZARE AN ANTERIOR'
      ELSE                                         '0'
    END                        COL03,--EXTRAORDINARYDEPRECIATIONMETHOD            NVARCHAR2(35)
    CASE
      WHEN COALESCE(NS.PROVIZION,0) &lt;&gt; 0      THEN -COALESCE(NS.PROVIZION,0)
      WHEN J1.ASSETTRANSACTIONTYPE = '130'
        AND J1.ICONTD = 10 AND J1.ICONTC = 0  THEN J1.VALOARE
      WHEN TNA.CODUNIC IS NOT NULL            THEN - J1.VALOARE
      ELSE                                         0
    END                        COL04 --EXTRAORDINARYDEPRECIATIONAMOUNTFORPERIOD   NUMBER(18,2)
  FROM TMP_SAFT_CODSAF C25
       LEFT JOIN TMP_SAFT_CODSAF       C60   ON  C60.CODPARINTE  = C25.CODSAF     AND C60.CodSAFTTab = 60
       LEFT JOIN MIFIX1                M1    ON  M1.CODMIFIX1    = C25.CODAUX
       LEFT JOIN NIRSTOC               NS    ON  NS.CODNIRSTOC   = M1.CODNIRSTOC
       LEFT JOIN TMP_SAFT_JURNAL1      J1    ON  J1.CODMIFIX     = M1.CODMIFIX
       LEFT  JOIN (
          SELECT DISTINCT CODUNIC FROM TMP_SAFT_MANEVRA WHERE FILTRU IN ('CRezRepAmoMifixNC')
        )                            TNA   ON TNA.CODUNIC     = J1.CONTD
  WHERE C25.CodSAFTTab = 25;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t26</obj_name>
  <obj_hashval>30a4e35487d13b40706c871028e4dfb4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t26()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  v_ALIni   NUMERIC;
  v_ALFin   NUMERIC;
  vCodSAF  NUMERIC;
  vSubunit NUMERIC(20);
  vTip     NUMERIC;
BEGIN
  --Stef 19.09.2024 - Sinc ORA-PG
  PERFORM pkg_saft_PUT_INFO('26.A','UMPLE_T26--SAF_GENERALLEDGERENTRIES');

  SELECT ANINI*12+LUNAINI, ANFIN*12+LUNAFIN, CodSubunit, Tip
  INTO   v_ALIni         , v_ALFin         , vSubunit  , vTip
  FROM TMP_SAFT_PARAMS;

  SELECT CODSAF
  INTO vCodSAF
  FROM TMP_SAFT_CODSAF WHERE CodSAFTTab = 26;

  IF vTip IN(4,7) THEN
    INSERT INTO TMP_SAFT26
    SELECT
      26                COL01,--CODSAF_GENERALLEDGERENTRIES NUMERIC(20,0)
      0                 COL02,--NUMBEROFENTRIES             NUMERIC(20,0)
      0                 COL03,--TOTALDEBIT                  NUMERIC(18,2)
      0                 COL04,--TOTALCREDIT                 NUMERIC(18,2)
      0                 COL05; --DETSAF_JOURNAL              NUMERIC(20,0)
  ELSE
    INSERT INTO TMP_SAFT26
    SELECT
      vCodSAF           COL01,--CODSAF_GENERALLEDGERENTRIES NUMERIC(20,0)
      Count(1)          COL02,--NUMBEROFENTRIES             NUMERIC(20,0)
      Sum(VALOARE)      COL03,--TOTALDEBIT                  NUMERIC(18,2)
      Sum(VALOARE)      COL04,--TOTALCREDIT                 NUMERIC(18,2)
      Count(1)          COL05 --DETSAF_JOURNAL              NUMERIC(20,0)
    FROM TMP_SAFT_JURNAL J
      INNER JOIN NCONT CD ON CD.CODCONT = J.CONTD
      INNER JOIN NCONT CC ON CC.CODCONT = J.CONTC
    WHERE J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
      AND vSubunit = CASE WHEN vSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
      AND NOT(CD.CLASA IN (8,9) AND CC.CLASA IN (8,9));  --ticket 52580 fara clase 8,9
  END IF;
  PERFORM pkg_saft_PUT_INFO('26.Z','UMPLE_T26--SAF_GENERALLEDGERENTRIES');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t27</obj_name>
  <obj_hashval>42d75aab1abc0900f825d9737901ba72</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t27()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vCodMaster NUMERIC;
BEGIN
  --Florin 30.03.2023 - fixat 57815
  --Florin 27.03.2023 - sinc. Oracle
  --Stef   14.02.2023
  PERFORM pkg_saft_PUT_INFO('27.A','UMPLE_T27--SAF_JOURNAL');

  SELECT CODSAF
  INTO vCodMaster
  FROM TMP_SAFT_CODSAF
  WHERE CodSAFTTab = 26;

  INSERT INTO TMP_SAFT27
  SELECT
    C27.CODSAF                                     COL01,--CODSAF_JOURNAL     NUMBER(20)
    vCodMaster                                     COL02,--CODSAF_MASTER      NUMBER(20)
    To_Char(J.CodJurnal,'fm999999999999999999990') COL03,--JOURNALID          NVARCHAR2(18)
    J.DESCRIPTION                                  COL04,--DESCRIPTION        NVARCHAR2(256)
    To_Char(J.TipDoc ,'fm99990')                   COL05,--TYPE               NVARCHAR2(9)
    1                                              COL06 --DETSAF_TRANSACTION NUMBER(20)
  FROM TMP_SAFT_CODSAF C27
    LEFT JOIN TMP_SAFT_JURNAL J  ON J.CODJURNAL   = C27.CODSURSA
  WHERE C27.CodSAFTTab = 27;
  PERFORM pkg_saft_PUT_INFO('27.Z','UMPLE_T27--SAF_JOURNAL');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t29</obj_name>
  <obj_hashval>930683eb22dc69fc65aea8758e932a3e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t29()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  sFirmaID   VARCHAR(35);
  vSubunit   NUMERIC(20);
BEGIN
  --Florin 16.12.2025 - sinc. Oracle
  --Florin 11.12.2025 - sinc. Oracle
  --Stef 28.04.2025 - sinc. Oracle
  PERFORM pkg_saft_PUT_INFO('29.A','UMPLE_T29--SAF_TRANSACTIONLINE');

  SELECT CODSUBUNIT INTO vSubunit
  FROM TMP_SAFT_PARAMS;

  IF vSubunit = 1 THEN
    SELECT '00'||REGEXP_REPLACE(F.CODFISCAL,'\D+','') INTO sFirmaID
    FROM TMP_SAFT_PARAMS SP INNER JOIN WINMADMIN.FIRMA F ON F.CODFIRMA = SP.CODFIRMA;
  ELSE
    SELECT '00'||REGEXP_REPLACE(S.CIF,'\D+','') INTO sFirmaID
    FROM TMP_SAFT_PARAMS SP INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = SP.CODSUBUNIT;
  END IF;

  INSERT INTO TMP_SAFT29
  SELECT
    nextval('SEQ_SAFT')                            COL01,--CODSAF_TRANSACTIONLINE    NUMBER(20)
    S28.COL01                                      COL02,--CODSAF_MASTER             NUMBER(20)
    To_Char(J.DataDoc,'YYYYMMDD')||
    Row_Number() OVER (PARTITION BY J.TIPDOC, J.CODDOC
                       ORDER BY J.CODJURNAL)            COL03,--RECORDID                  NVARCHAR2(18)
    C.CODSAFT                                      COL04,--ACCOUNTID                 NVARCHAR2(70)
    NULL                                           COL05,--CODSAF_ANALYSIS           NUMBER(20)
    NULL                                           COL06,--VALUEDATE                 DATE
    NULL                                           COL07,--SOURCEDOCUMENTID          NVARCHAR2(35)
    CASE
      WHEN P.CODPART IS NULL THEN sFirmaID
      WHEN J.TIPDOC IN (28, 35) AND P.CLIENT = 0   THEN n'0'
      ELSE Coalesce(S28.COL13, n'0')
    END                                                 COL08,--CUSTOMERID                NVARCHAR2(35)
    CASE
      WHEN P.CODPART IS NULL THEN sFirmaID
      WHEN J.TIPDOC IN (28, 35) AND P.FURNIZOR = 0 THEN n'0'
      ELSE Coalesce(S28.COL14, n'0')
    END                                                 COL09,--SUPPLIERID                NVARCHAR2(35)
    J.DESCRIPTION                                       COL10,--DESCRIPTION               NVARCHAR2(256)
    CASE WHEN C31.CodSAFTTab = 3101 THEN C31.CODSAF END COL11,--CODDEBITAMOUNTSAF_AMOUNT  NUMBER(20)
    CASE WHEN C31.CodSAFTTab = 3102 THEN C31.CODSAF END COL12,--CODCREDITAMOUNTSAF_AMOUNT NUMBER(20)
    1                                              COL13 --DETSAF_TAXINFORMATION     NUMBER(20)
  FROM TMP_SAFT_CODSAF C31
    LEFT JOIN TMP_SAFT_JURNAL    J    ON J.CODJURNAL  = C31.CODSURSA
    LEFT JOIN TMP_SAFT_JURNALDET JD   ON JD.CODJURNAL = C31.CODSURSA
    LEFT JOIN TMP_SAFT_NCONT     C    ON C.CODCONT    = CASE WHEN C31.CodSAFTTab = 3101 THEN J.CONTD ELSE J.CONTC END
    LEFT JOIN TMP_SAFT_NCONT     CTVA ON CTVA.CodCont = C.CodCont    AND CTVA.CodSAFT IN ('4426', '4427', '4428')
    LEFT JOIN TMP_SAFT_CODSAF    C28  ON C28.CODSURSA = C31.CODSURSA AND C28.CodSAFTTab = 28
    LEFT JOIN TMP_SAFT28         S28  ON S28.COL01    = C28.CODSAF
    LEFT JOIN (
      SELECT DISTINCT CODPART, CODCONT, CLIENT, FURNIZOR
      FROM TMP_SAFT_NPART
    )                            P    ON P.CODPART    = CASE WHEN C31.CodSAFTTab = 3101 AND J.TIPDOC IN (28, 35) THEN JD.CODPART_2 ELSE JD.CODPART END
                                     AND P.CODCONT    = C.CODCONT
  WHERE C31.CodSAFTTab IN (3101, 3102);

  PERFORM pkg_saft_PUT_INFO('29.Z','UMPLE_T29--SAF_TRANSACTIONLINE');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t31</obj_name>
  <obj_hashval>e06aa2c913853b196891ef0477c1f8aa</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t31()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 03.06.2025 - fixat 65815
  --Stef 27.09.2024 - sinc. Oracle
  PERFORM pkg_saft_PUT_INFO('31.A','UMPLE_T31--SAF_AMOUNT');

  INSERT INTO TMP_SAFT31
  SELECT
    99    COL01,--CODSAF_AMOUNT  NUMBER(20)
    0     COL02,--AMOUNT         NUMBER(18,2)
    'RON' COL03,--CURRENCYCODE   NVARCHAR2(3)
    0     COL04,--CURRENCYAMOUNT NUMBER(18,2)
    1     COL05;--EXCHANGERATE   NUMBER(18,4)

  INSERT INTO TMP_SAFT31
  SELECT
    subs.CODSAF                             COL01,--CODSAF_AMOUNT  NUMBER(20)
    subs.AMOUNT                             COL02,--AMOUNT         NUMBER(18,2)
    subs.CURRENCYCODE                       COL03,--CURRENCYCODE   NVARCHAR2(3)
    CASE
      WHEN subs.CURRENCYCODE &lt;&gt; 'RON'
      THEN subs.AMOUNT/CASE WHEN subs.EXCHANGERATE = 0 THEN 1 ELSE subs.EXCHANGERATE END
      ELSE subs.AMOUNT
    END                                     COL04,--CURRENCYAMOUNT NUMBER(18,2)
    subs.EXCHANGERATE                       COL05 --EXCHANGERATE   NUMBER(18,4)
  FROM (
    SELECT
      C31a.CODSAF,
      J.VALOARE AS AMOUNT,
      J.CURRENCYCODE, J.EXCHANGERATE --, 'RON' CURRENCYCODE, 1 EXCHANGERATE
    FROM TMP_SAFT_CODSAF C31a
      LEFT JOIN TMP_SAFT_JURNAL J  ON J.CODJURNAL = C31a.CODSURSA
    WHERE C31a.CodSAFTTab IN (3101, 3102)
  ) subs;

  INSERT INTO TMP_SAFT31
  SELECT
    subs.CODSAF                             COL01,--CODSAF_AMOUNT  NUMBER(20)
    subs.AMOUNT                             COL02,--AMOUNT         NUMBER(18,2)
    subs.CURRENCYCODE                       COL03,--CURRENCYCODE   NVARCHAR2(3)
    CASE
      WHEN subs.CURRENCYCODE &lt;&gt; 'RON'
      THEN subs.AMOUNT/CASE WHEN subs.EXCHANGERATE = 0 THEN 1 ELSE subs.EXCHANGERATE END
      ELSE subs.AMOUNT
    END                                     COL04,--CURRENCYAMOUNT NUMBER(18,2)
    subs.EXCHANGERATE                       COL05 --EXCHANGERATE   NUMBER(18,4)
  FROM (
    SELECT
      C31b.CODSAF,
      Coalesce(
        CASE
          WHEN J.TIPDOC = 14 AND CC.CodSAFT IN ('4427') THEN 0
          WHEN J.TIPDOC = 35 AND CC.CodSAFT IN ('4426') THEN 0
          WHEN Coalesce(TI.TAXCODE, n'0') = '310327'    THEN 0
          WHEN Coalesce(IES.TIPTVA, 0)    = 10          THEN 0
        END,
        MTI.TAXVAL,
        TI.TAXVAL,
        0
      ) AS AMOUNT,
      J.CURRENCYCODE, J.EXCHANGERATE --, 'RON' CURRENCYCODE, 1 EXCHANGERATE
    FROM  TMP_SAFT_CODSAF C31b
      LEFT JOIN TMP_SAFT_JURNAL     J   ON J.CODJURNAL = C31b.CODSURSA
      LEFT JOIN TMP_SAFT_NCONT      CC  ON CC.CODCONT  = J.CONTC
      LEFT JOIN IESIRI              IES ON IES.CODIES  = J.INDEXLOCAL AND IES.TIPDOC = J.TIPDOC
      LEFT JOIN TMP_SAFT_TAXINFO    TI  ON TI.TIPDOC   = J.TIPDOC AND TI.CODTI = C31b.CODAUX AND TI.CODDOC = CASE WHEN J.TIPDOC IN (29, 30, 31) THEN J.INDEXLOCAL ELSE J.CODDOC END
                                       AND TI.CODCONT  = CASE WHEN C31b.CodSAFTTab = 3103 THEN J.CONTD ELSE J.CONTC END
                                       AND                         CASE WHEN C31b.CodSAFTTab = 3103 THEN J.CONTC ELSE J.CONTD END =
                                           Coalesce(TI.CODCONTDED, CASE WHEN C31b.CodSAFTTab = 3103 THEN J.CONTC ELSE J.CONTD END)
      LEFT JOIN TMP_SAFT_TAXINFO_MP MTI ON MTI.CODTI = C31b.CODAUX AND MTI.IDXLOCAL = C31b.IDXAUX AND MTI.CODCONT = J.CONTD
    WHERE C31b.CodSAFTTab IN (3103, 3104)
  ) subs;
  PERFORM pkg_saft_PUT_INFO('31.Z','UMPLE_T31--SAF_AMOUNT');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t42</obj_name>
  <obj_hashval>cb56bf445c35a7117254d25fdc1b3627</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t42()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 06.01.2022
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t43</obj_name>
  <obj_hashval>5ce43784e0f26ef16c5d8686ea77751c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t43()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 06.01.2022
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t44</obj_name>
  <obj_hashval>6d8d431f53d76e34f22eae6a3046d422</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t44()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 06.01.2022
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t45</obj_name>
  <obj_hashval>93ca10b61e2f86a94298815b2f57d450</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t45()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 06.01.2022
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t46</obj_name>
  <obj_hashval>401461f4e38932cbae913e231787f079</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t46()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 25.05.2023 - corectii dual
  --Stef  25.05.2023
  INSERT INTO TMP_SAFT46
  SELECT
    46 COL01,--CODSAF_PURCHASEINVOICES NUMBER(20)
    NULL COL02,--NUMBEROFENTRIES      NUMBER(20)
    NULL COL03,--TOTALDEBIT           NUMBER(18,2)
    NULL COL04,--TOTALCREDIT          NUMBER(18,2)
    NULL COL05; --DETSAF_INVOICE       NUMBER(20)
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t47</obj_name>
  <obj_hashval>8dba08f95fe11f8d789a665095083a9c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t47()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 25.05.2023 - corectie dual
  --Stef  25.05.2023
  INSERT INTO TMP_SAFT47
  SELECT
    47 COL01,--CODSAF_PAYMENTS NUMBER(20)
    NULL COL02,--NUMBEROFENTRIES      NUMBER(20)
    NULL COL03,--TOTALDEBIT           NUMBER(18,2)
    NULL COL04,--TOTALCREDIT          NUMBER(18,2)
    NULL COL05; --DETSAF_PAYMENT       NUMBER(20)
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t49</obj_name>
  <obj_hashval>3002cc0726d36e785870047be110e25f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t49()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 06.01.2022
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t50</obj_name>
  <obj_hashval>8e88b2f364660188cccc702620b52a39</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t50()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 06.01.2022
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t51</obj_name>
  <obj_hashval>44c59f9c1f77a69421ad599f5dd7f265</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t51()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 06.01.2022
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t52</obj_name>
  <obj_hashval>b7431fb200949726a94dea336a971dda</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t52()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 13.12.2023
  PERFORM pkg_saft_PUT_INFO('52.A','UMPLE_T52--SAF_MOVEMENTOFGOODS');
  INSERT INTO TMP_SAFT52
  SELECT
    COL01,--CODSAF_MOVEMENTOFGOODS NUMBER(20)
    COL02,--NUMBEROFMOVEMENTLINES  NUMBER(20)
    COL03,--TOTALQUANTITYRECEIVED  NUMBER(22,6)
    COL04,--TOTALQUANTITYISSUED    NUMBER(22,6)
    COL05 --DETSAF_STOCKMOVEMENT   NUMBER(20)
  FROM (
    SELECT
      52 AS COL01,
      Sum(LINES_COUNT) COL02,
      Sum(CASE WHEN TAB = 'N' THEN LINES_SUM ELSE 0 END) COL03,
      Sum(CASE WHEN TAB = 'L' THEN LINES_SUM ELSE 0 END) COL04,
      Count(1) COL05
    FROM TMP_SAFT_STOCKMOVEMENT
  ) subs;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t53</obj_name>
  <obj_hashval>cfc2f3907acadb78bc0b92192dda2d8a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t53()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 13.12.2023
  PERFORM pkg_saft_PUT_INFO('53.A','UMPLE_T53--SAF_STOCKMOVEMENT');
  INSERT INTO TMP_SAFT53
  SELECT
    CODSAF                 COL01,--CODSAF_STOCKMOVEMENT     NUMBER(20)
    52                     COL02,--CODSAF_MASTER            NUMBER(20)
    TAB||'.'||
    To_Char(TIPDOC)||'.'||
    To_Char(CODDOC)        COL03,--MOVEMENTREFERENCE        NVARCHAR2(35)
    DATADOC                COL04,--MOVEMENTDATE             DATE
    NULL                   COL05,--MOVEMENTPOSTINGDATE      DATE
    NULL                   COL06,--MOVEMENTPOSTINGTIME      DATE
    NULL                   COL07,--TAXPOINTDATE             DATE
    MOVEMENTTYPE           COL08,--MOVEMENTTYPE             NVARCHAR2(9)
    NULL                   COL09,--SOURCEID                 NVARCHAR2(35)
    NULL                   COL10,--SYSTEMID                 NVARCHAR2(35)
    0                      COL11,--DETSAF_DOCUMENTREFERENCE NUMBER(20)
    1                      COL12 --DETSAF_STOCKMOVEMENTLINE NUMBER(20)
  FROM TMP_SAFT_STOCKMOVEMENT;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t54</obj_name>
  <obj_hashval>1b3cb68f466a89732d2ec7fbdea869f2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t54()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 06.01.2022
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t55</obj_name>
  <obj_hashval>80894660d78944022c38db32ed5b0cdd</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t55()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  v_ALFin  NUMERIC(5);
  sFirmaID VARCHAR(35);
  vSubunit NUMERIC(20);
BEGIN
  --Stef 19.09.2024 - Sinc ORA-PG
  PERFORM pkg_saft_PUT_INFO('55.A','UMPLE_T55--SAF_STOCKMOVEMENTLINE');
  SELECT CODSUBUNIT, ANFIN*12+LUNAFIN  INTO vSubunit, v_ALFin FROM TMP_SAFT_PARAMS;
  IF vSubunit = 1
  THEN SELECT '00'||REGEXP_REPLACE(F.CODFISCAL,'\D+','') INTO sFirmaID FROM TMP_SAFT_PARAMS SP INNER JOIN WINMADMIN.FIRMA F ON F.CODFIRMA   = SP.CODFIRMA;
  ELSE SELECT '00'||REGEXP_REPLACE(S.CIF,'\D+','')       INTO sFirmaID FROM TMP_SAFT_PARAMS SP INNER JOIN NSUBUNIT        S ON S.CODSUBUNIT = SP.CODSUBUNIT;
  END IF;

  INSERT INTO TMP_SAFT55
  SELECT
    NEXTVAL('SEQ_SAFT')       COL01,--CODSAF_STOCKMOVEMENTLINE              NUMBER(20)
    T.CODSAF                  COL02,--CODSAF_MASTER                         NUMBER(20)
    L1.CODLIVR1               COL03,--LINENUMBER                            NVARCHAR2(18)
    C.CODSAFT                 COL04,--ACCOUNTID                             NVARCHAR2(70)
    NULL                      COL05,--TRANSACTIONID                         NVARCHAR2(70)
    Coalesce(PD.PARTID, '0')  COL06,--CUSTOMERID                            NVARCHAR2(35)
    '0'                       COL07,--SUPPLIERID                            NVARCHAR2(35)
    NULL                      COL08,--CODSHIPTOSAF_SHIPPINGPOINT            NUMBER(20)
    NULL                      COL09,--CODSHIPFROMSAF_SHIPPINGPOINT          NUMBER(20)
    To_Char(O.CodObiect)      COL10,--PRODUCTCODE                           NVARCHAR2(70)
    NULL                      COL11,--STOCKACCOUNTNO                        NVARCHAR2(70)
    L1.CANT                   COL12,--QUANTITY                              NUMBER(22,6)
    SUBSTR(UMS.CODSAFT, 1, 9) COL13,--UNITOFMEASURE                         NVARCHAR2(9)
    U.PARITATEUMSAFT          COL14,--UOMTOUOMPHYSICALSTOCKCONVERSIONFACTOR NUMBER(22,7)
    NULL                      COL15,--BOOKVALUE                             NUMBER(18,2)
    MOVEMENTTYPE              COL16,--MOVEMENTSUBTYPE                       NVARCHAR2(9)
    NULL                      COL17,--MOVEMENTCOMMENTS                      NVARCHAR2(256)
    0                         COL18 --DETSAF_TAXINFORMATION                 NUMBER(20)
  FROM TMP_SAFT_STOCKMOVEMENT T
    LEFT JOIN TMP_SAFT_NPARTDET      PD  ON PD.CODPART    = T.CODPART
    LEFT JOIN LIVR1                  L1  ON L1.CODLIVR    = T.CODDOC
    LEFT JOIN NIRSTOC                NS  ON NS.CodNirStoc = L1.CodNirStoc
    LEFT JOIN LIVRVAL                LV  ON LV.CodLivr1   = L1.CodLivr1
    LEFT JOIN IOART1                 IO1 ON IO1.CodIOArt  = Coalesce(lv.codioart, ns.codioart) AND v_ALFin BETWEEN IO1.ALSTART AND IO1.ALSTOP
    LEFT JOIN TMP_SAFT_NCONT         C   ON C.CODCONT     = IO1.CONT
    LEFT JOIN NARTOBJ                O   ON O.CODOBIECT   = Coalesce(lv.codobiect, ns.codobiect)
    LEFT JOIN NART                   A   ON A.CODARTICOL  = O.CODARTICOL
    LEFT JOIN WINMADMIN.INTRASTAT_NC CN8 ON CN8.CN        = Trim(O.CODVAMAL)
    LEFT JOIN NUM                    U   ON U.CODUM       = A.UM
    LEFT JOIN WINMADMIN.NUMSAFT      UMS ON UMS.CODUMSAFT = U.CODUMSAFT
  WHERE T.TAB = 'L';

  INSERT INTO TMP_SAFT55
  SELECT
    NEXTVAL('SEQ_SAFT')       COL01,--CODSAF_STOCKMOVEMENTLINE              NUMBER(20)
    T.CODSAF                  COL02,--CODSAF_MASTER                         NUMBER(20)
    NS.CODNIRSTOC             COL03,--LINENUMBER                            NVARCHAR2(18)
    C.CODSAFT                 COL04,--ACCOUNTID                             NVARCHAR2(70)
    NULL                      COL05,--TRANSACTIONID                         NVARCHAR2(70)
    '0'                       COL06,--CUSTOMERID                            NVARCHAR2(35)
    Coalesce(PD.PARTID, '0')  COL07,--SUPPLIERID                            NVARCHAR2(35)
    NULL                      COL08,--CODSHIPTOSAF_SHIPPINGPOINT            NUMBER(20)
    NULL                      COL09,--CODSHIPFROMSAF_SHIPPINGPOINT          NUMBER(20)
    To_Char(O.CodObiect)      COL10,--PRODUCTCODE                           NVARCHAR2(70)
    NULL                      COL11,--STOCKACCOUNTNO                        NVARCHAR2(70)
    NS.CANTNIR                COL12,--QUANTITY                              NUMBER(22,6)
    SUBSTR(UMS.CODSAFT, 1, 9) COL13,--UNITOFMEASURE                         NVARCHAR2(9)
    U.PARITATEUMSAFT          COL14,--UOMTOUOMPHYSICALSTOCKCONVERSIONFACTOR NUMBER(22,7)
    NULL                      COL15,--BOOKVALUE                             NUMBER(18,2)
    MOVEMENTTYPE              COL16,--MOVEMENTSUBTYPE                       NVARCHAR2(9)
    NULL                      COL17,--MOVEMENTCOMMENTS                      NVARCHAR2(256)
    0                         COL18 --DETSAF_TAXINFORMATION                 NUMBER(20)
  FROM TMP_SAFT_STOCKMOVEMENT T
    LEFT JOIN TMP_SAFT_NPARTDET      PD  ON PD.CODPART    = T.CODPART
    LEFT JOIN NIRSTOC                NS  ON NS.CodNir     = T.Coddoc
    LEFT JOIN IOART1                 IO1 ON IO1.CodIOArt  = ns.codioart AND v_ALFin BETWEEN IO1.ALSTART AND IO1.ALSTOP
    LEFT JOIN TMP_SAFT_NCONT         C   ON C.CODCONT     = IO1.CONT
    LEFT JOIN NARTOBJ                O   ON O.CODOBIECT   = ns.codobiect
    LEFT JOIN NART                   A   ON A.CODARTICOL  = O.CODARTICOL
    LEFT JOIN WINMADMIN.INTRASTAT_NC CN8 ON CN8.CN        = Trim(O.CODVAMAL)
    LEFT JOIN NUM                    U   ON U.CODUM       = A.UM
    LEFT JOIN WINMADMIN.NUMSAFT      UMS ON UMS.CODUMSAFT = U.CODUMSAFT
  WHERE T.TAB = 'N';

  UPDATE TMP_SAFT55
  SET    COL06 = sFirmaID,    COL07 = sFirmaID
  WHERE (COL06 = '0'      AND COL07 = '0'     ) OR
        (COL06 = '0'      AND COL07 = sFirmaID) OR
        (COL06 = sFirmaID AND COL07 = '0'     );

  UPDATE TMP_SAFT53 S53 SET COL12 = (SELECT Count(1) FROM TMP_SAFT55 S55 WHERE S55.COL02 = S53.COL01);
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t56</obj_name>
  <obj_hashval>e1ebff3cdbbd9ed7a1f279220523c83f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t56()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 10.12.2025 - sinc. Oracle
  --Stef  25.05.2023
  INSERT INTO TMP_SAFT56
  SELECT
    56 COL01,--CODSAF_ASSETTRANSACTIONS  NUMBER(20)
    Count(1)       COL02,--NUMBEROFASSETTRANSACTIONS NUMBER(20)
    Count(1)       COL03 --7   NUMBER(20)
  FROM TMP_SAFT_CODSAF C57
  WHERE C57.CodSAFTTab = 57
  GROUP BY C57.CodSAFTTab;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t57</obj_name>
  <obj_hashval>cd4b0681c0c2c1f0f42b5dda89d5666a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t57()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 10.12.2025 - sinc. Oracle
  --Stef  25.05.2023
  INSERT INTO TMP_SAFT57
  SELECT
    C57.CODSAF                                      COL01,--CODSAF_ASSETTRANSACTION           NUMBER(20)
    56                                              COL02,--CODSAF_MASTER                     NUMBER(20)
    To_Char(J1.CodJurnal1,'fm00000000000000000000') COL03,--ASSETTRANSACTIONID                NVARCHAR2(70)
    M.NRINVENTAR                                    COL04,--ASSETID                           NVARCHAR2(35)
    J1.ASSETTRANSACTIONTYPE                         COL05,--ASSETTRANSACTIONTYPE              NVARCHAR2(9)
    CASE J1.ASSETTRANSACTIONTYPE
      WHEN  '10' THEN 'Achizitie'
      WHEN  '20' THEN 'Vânzare'
      WHEN  '30' THEN 'Amortizare'
      WHEN  '40' THEN 'Transfer intern'
      WHEN  '50' THEN 'Casare mijloace fixe'
      WHEN  '60' THEN 'Reevaluare negativa'
      WHEN  '70' THEN 'Reevaluare pozitiva'
      WHEN  '80' THEN 'Plus de inventar'
      WHEN  '90' THEN 'Minus de inventar'
      WHEN '100' THEN 'Ajustare de valoare negativa'
      WHEN '110' THEN 'Reversare ajustare de valoare'
      WHEN '120' THEN 'Bunuri acordate cu titlu gratuit'
      ELSE            'Alte tranzaciii'
    END                                             COL06,--DESCRIPTION                       NVARCHAR2(256)
    J1.DATADOC                                      COL07,--ASSETTRANSACTIONDATE              DATE
    C23.CODSAF                                      COL08,--CODSAF_ASSETSUPPLIER              NUMBER(20)
    To_Char(J1.CodJurnal1,'fm00000000000000000000') COL09,--TRANSACTIONID                     NVARCHAR2(70)
    C61.CODSAF                                      COL10 --CODSAF_ASSETTRANSACTIONVALUATIONS NUMBER(20)
  FROM TMP_SAFT_CODSAF C57
    LEFT JOIN TMP_SAFT_CODSAF  C61 ON C61.CODPARINTE = C57.CODSAF           AND C61.CODSAFTTAB = 61
    INNER JOIN TMP_SAFT_CODSAF  C22 ON C22.CODSAF     = C57.CODPARINTE
    LEFT  JOIN TMP_SAFT_JURNAL1 J1  ON J1.CODJURNAL1  = C57.CODSURSA         AND J1.CODMIFIX1   = C57.CODAUX AND J1.CODMIFIX = C22.CODSURSA
    LEFT JOIN MIFIX1           M1  ON M1.CODMIFIX1   = C57.CODAUX
    LEFT JOIN MIFIX            M   ON M.CODMIFIX     = M1.CODMIFIX
    LEFT JOIN NIRSTOC          NS  ON NS.CODNIRSTOC  = M1.CODNIRSTOC
    LEFT JOIN TMP_SAFT_CODSAF  C23 ON C23.CODSURSA   = Coalesce(NS.FURN, 0) AND C23.CodSAFTTab = 23
  WHERE C57.CodSAFTTab = 57
  ORDER BY C57.CODSAF ASC;

END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t58</obj_name>
  <obj_hashval>08e6404695157048344f1a834cd54935</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t58()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 16.12.2025 - sinc. Oracle
  --Florin 10.12.2025 - sinc. Oracle
  --Florin 06.11.2025 - sinc. Oracle
  --Florin 29.10.2025 - sinc. Oracle
  --Florin 24.10.2025 - sinc. Oracle
  --Florin 17.10.2025 - sinc. Oracle
  --Florin 28.05.2024 - fixat 62145
  --Florin 22/24.05.2024 - sinc. Oracle
  --Stef  25.05.2023
  INSERT INTO TMP_SAFT58
  SELECT
    C58.CODSAF                  COL01,--CODSAF_ASSETTRANSACTIONVALUATION           NUMBER(20)
    C58.CODPARINTE              COL02,--CODSAF_MASTER                              NVARCHAR2(18)
    NULL                        COL03,--ASSETVALUATIONTYPE                         NVARCHAR2(18)
    CASE
      WHEN Coalesce(NS.CANTNIR, 0) = 0 AND
           J1.ASSETTRANSACTIONTYPE IN ('10')       THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('10')       THEN J1.VALOARE / NS.CANTNIR
      WHEN J1.ASSETTRANSACTIONTYPE IN ('40')
        AND J1.TIPDOC IN (6,7)                     THEN J1.VALOARE
      WHEN J1.TIPDOC IN (13)                       THEN J1.VALOARE
      --WHEN J1.ASSETTRANSACTIONTYPE IN ('60', '70') THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('80')       THEN J1.VALOARE
      WHEN J1.TIPDOC IN (15)           AND
           J1.TIPTRANZACTIE = 5                    THEN J1.VALOARE
      ELSE                                              0
    END                         COL04,--ACQUISITIONANDPRODUCTIONCOSTSONTRANSACTION NUMBER(18,2)
   CASE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('20')       THEN Coalesce(M1.AMO,  0) - Coalesce(M1.PRET, 0)
      WHEN J1.ASSETTRANSACTIONTYPE IN ('30')       THEN - J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('40')
        AND J1.TIPDOC IN (6,7,13,15)               THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('40')
        AND J1.TIPDOC IN (23)                      THEN - M1.PRET
      WHEN J1.ASSETTRANSACTIONTYPE IN ('40')
        AND J1.TIPDOC IN (12) AND
        (
         SELECT Count(*)
         FROM TMP_SAFT_JURNAL1
         WHERE CODMIFIX1 = M1.CODMIFIX1
         GROUP BY CODMIFIX1
         ) &gt; 1                                     THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('40')
        AND J1.TIPDOC IN (12)                      THEN - Coalesce(M1.PRET, 0)
      WHEN J1.ASSETTRANSACTIONTYPE IN ('40')       THEN Coalesce(M1.AMO,  0) - Coalesce(M1.PRET, 0)
      WHEN J1.ASSETTRANSACTIONTYPE IN ('50')       THEN - J1.VALOARE
      WHEN Coalesce(NS.CANTNIR, 0) = 0             THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('60')       THEN - J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('70')       THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('100')      THEN - J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('110')      THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('130')
        AND J1.TIPDOC IN (35)                      THEN - J1.VALOARE
      ELSE J1.VALOARE / NS.CANTNIR
    END                         COL05,--BOOKVALUEONTRANSACTION                     NUMBER(18,2)
    CASE
      WHEN Coalesce(NS.CANTNIR, 0) = 0 AND
           J1.ASSETTRANSACTIONTYPE IN ('10')       THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('10')       THEN J1.VALOARE / NS.CANTNIR
      --WHEN J1.ASSETTRANSACTIONTYPE IN ('10')       THEN Coalesce(M1.PRET, 0)
      WHEN J1.ASSETTRANSACTIONTYPE IN ('20')       THEN J1.VALOARE - Coalesce(M1.PRET, 0) + Coalesce(M1.AMO,  0)
      WHEN J1.TIPDOC IN (13)                       THEN J1.VALOARE
      WHEN J1.TIPDOC IN (15)           AND
           J1.TIPTRANZACTIE = 5                    THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('30')       THEN - J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('40')
        AND J1.TIPDOC IN (6,7)                     THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('40')
        AND J1.TIPDOC IN (23)                      THEN - M1.PRET
      WHEN J1.ASSETTRANSACTIONTYPE IN ('40')
        AND J1.TIPDOC IN (12) AND
        (
         SELECT Count(*)
         FROM TMP_SAFT_JURNAL1
         WHERE CODMIFIX1 = M1.CODMIFIX1
         GROUP BY CODMIFIX1
         ) &gt; 1                                     THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('40')
        AND J1.TIPDOC IN (12)                      THEN - Coalesce(M1.PRET, 0)
      WHEN J1.ASSETTRANSACTIONTYPE IN ('40')       THEN Coalesce(M1.AMO,  0) - Coalesce(M1.PRET, 0)
      WHEN J1.ASSETTRANSACTIONTYPE IN ('50')       THEN - J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('60')       THEN - J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('70')       THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('80')       THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('100')      THEN - J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('110')      THEN J1.VALOARE
      WHEN J1.ICONTD = 10             AND
           J1.ICONTC = 0                           THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN ('130')
        AND J1.TIPDOC IN (35)                      THEN - J1.VALOARE
      ELSE                                              0
    END                         COL06 --ASSETTRANSACTIONAMOUNT                     NUMBER(18,2)
  FROM TMP_SAFT_CODSAF C58
    INNER JOIN TMP_SAFT_CODSAF  C61 ON C61.CODSAF    = C58.CODPARINTE
    INNER JOIN TMP_SAFT_CODSAF  C57 ON C57.CODSAF    = C61.CODPARINTE
    INNER JOIN TMP_SAFT_CODSAF  C22 ON C22.CODSAF    = C57.CODPARINTE
    LEFT  JOIN TMP_SAFT_JURNAL1 J1  ON J1.CODJURNAL1 = C58.CODSURSA          AND J1.CODMIFIX1   = C58.CODAUX AND J1.CODMIFIX = C22.CODSURSA
    LEFT  JOIN MIFIX1           M1  ON M1.CODMIFIX1  = C58.CODAUX
    LEFT  JOIN MIFIX            M   ON M.CODMIFIX    = J1.CODMIFIX
    LEFT  JOIN NIRSTOC          NS  ON NS.CODNIRSTOC = M1.CODNIRSTOC
    LEFT  JOIN TMP_SAFT_CODSAF  C23 ON C23.CODSURSA  = Coalesce(NS.FURN, 0) AND C23.CodSAFTTab = 23
  WHERE C58.CodSAFTTab = 58
  ORDER BY C58.CODPARINTE ASC;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t60</obj_name>
  <obj_hashval>46e4d82ea1b3e0163351e6fab255e03e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t60()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef  25.05.2023
  INSERT INTO TMP_SAFT60
  SELECT
    C25.CODPARINTE COL01,--CODSAF_EXTRAORDINARYDEPRECIATIONSFORPERIOD NUMBER(20)
    Count(1)       COL02 --DETSAF_EXTRAORDINARYDEPRECIATIONFORPERIOD  NUMBER(20)
  FROM TMP_SAFT_CODSAF C25
  WHERE C25.CodSAFTTab = 25
  GROUP BY C25.CODPARINTE;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t61</obj_name>
  <obj_hashval>05b537285048ee0aa175356d5b141849</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t61()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef  25.05.2023
  INSERT INTO TMP_SAFT61
  SELECT
    C58.CODPARINTE COL01,--CODSAF_ASSETTRANSACTIONVALUATIONS NUMBER(20)
    Count(1)       COL02 --DETSAF_ASSETTRANSACTIONVALUATION  NUMBER(20)
  FROM TMP_SAFT_CODSAF C58
  WHERE C58.CodSAFTTab = 58
  GROUP BY C58.CODPARINTE;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_updatediscmonluna</obj_name>
  <obj_hashval>ab940ade8891b60b9b818cf1bda89955</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_updatediscmonluna(pan numeric, pluna numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vCount INTEGER;
BEGIN
  --Stef 09.07.2024
  TRUNCATE TABLE TMP_DiscMonetar;
  TRUNCATE TABLE TMP_MANEVRA2;

  INSERT INTO TMP_DiscMonetar  (CODDISCMONETAR, CODIES, PROCTVA, DISCOUNT, TVADISCOUNT)
  WITH D1 AS(
    SELECT CodIes, ProcTVA, Round(Sum(ValDiscPret),2) VDisc, Round(Sum(ValDiscPret)*ProcTVA/(100+ProcTVA),2) TVADisc, Max(CASE WHEN ValDiscPret &lt;&gt; 0 THEN 1 ELSE 0 END) AmDiscPret
    FROM (
      SELECT
        I.CodIes, Coalesce(I1.ValDiscPret,0) ValDiscPret,
        Round(PKG_LIST_BASE_UTILS_CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT, 1),0) ProcTVA
      FROM Iesiri I
        INNER JOIN Iesiri1 I1 ON I1.CodIes = I.CodIes
        LEFT  JOIN nartobj o  ON o.codobiect   = i1.codobiect
        LEFT  JOIN nart1   a1 ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
        LEFT  JOIN ntva1   t1 ON t1.codtva     = a1.codtva    AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
      WHERE i.tipdoc = 16 AND I.An = pAn AND I.Luna = pLuna
        AND Coalesce(I1.ValDiscPret,0) &lt;&gt; 0
    ) subs
    GROUP BY CodIes, ProcTva
  ),
  D2 AS(
    SELECT I.CodIes, DM.PROCTVA, Min(DM.CodDiscMonetar) CodDiscMonetar, Sum(DM.DISCOUNT) VDisc , Sum(DM.TVADISCOUNT) TVADisc
    FROM Iesiri I INNER JOIN DiscMonetar DM ON DM.CodIes = I.Codies
    WHERE i.tipdoc = 16 AND I.An = pAn AND I.Luna = pLuna
    GROUP BY I.CodIes, DM.PROCTVA
  ),
  D AS (
    SELECT
      D2.CodDiscMonetar, Coalesce(D1.Codies, D2.Codies) Codies, Coalesce(D1.ProcTva, D2.ProcTva) ProcTva, D1.VDisc, D1.TVADisc,
      Max(
        CASE
          WHEN Coalesce(D1.VDisc  , 0) &lt;&gt; Coalesce(D2.VDisc  , 0) THEN 1
          WHEN Coalesce(D1.TVADisc, 0) &lt;&gt; Coalesce(D2.TVADisc, 0) THEN 1
          ELSE 0
        END
      )                               OVER (PARTITION BY Coalesce(D1.Codies, D2.Codies)) DifPeProc,
      Max(Coalesce(D1.AmDiscPret, 0)) OVER (PARTITION BY Coalesce(D1.Codies, D2.Codies)) AmDiscPret,
      Sum(Coalesce(D1.VDisc     , 0)) OVER (PARTITION BY Coalesce(D1.Codies, D2.Codies)) S1VDisc,
      Sum(Coalesce(D1.TVADisc   , 0)) OVER (PARTITION BY Coalesce(D1.Codies, D2.Codies)) S1TVADisc,
      Sum(Coalesce(D2.VDisc     , 0)) OVER (PARTITION BY Coalesce(D1.Codies, D2.Codies)) S2VDisc,
      Sum(Coalesce(D2.TVADisc   , 0)) OVER (PARTITION BY Coalesce(D1.Codies, D2.Codies)) S2TVADisc
    FROM d1 FULL JOIN d2 ON d1.CodIes = d2.CodIes AND d1.ProcTVA = d2.ProcTVA
  )
  SELECT D.CodDiscMonetar, D.CodIes, D.ProcTva, D.VDisc, D.TVADisc
  FROM D LEFT JOIN IESIRI I ON I.Codies = D.CodIes
  WHERE (
          Coalesce(D.DifPeProc  ,0) &lt;&gt; 0                       OR
          Coalesce(I.VALDISCOUNT,0) &lt;&gt; Coalesce(D.S1VDisc  ,0) OR
          Coalesce(I.TVADISCOUNT,0) &lt;&gt; Coalesce(D.S1TVADisc,0) OR
          Coalesce(I.VALDISCOUNT,0) &lt;&gt; Coalesce(D.S2VDisc  ,0) OR
          Coalesce(I.TVADISCOUNT,0) &lt;&gt; Coalesce(D.S2TVADisc,0)
        );
  --AND   Coalesce(D.AmDiscPret ,0) &lt;&gt; 1 -- de vazut daca dorim limitare la Monetare care au cel putin o linie cu ValDiscPret &lt;&gt; 0

  INSERT INTO TMP_MANEVRA2(CODUNIC) SELECT DISTINCT CODIES FROM TMP_DiscMonetar;
  SELECT Count(1) INTO vCount FROM TMP_MANEVRA2;
  IF vCount &gt; 0 THEN
    UPDATE Iesiri I
    SET (VALDISCOUNT, TVADISCOUNT) = (SELECT Sum(Coalesce(DISCOUNT,0)) , Sum(Coalesce(TVADISCOUNT,0)) FROM TMP_DiscMonetar T WHERE T.CodIes = I.CodIes)
    WHERE CodIes IN (SELECT CODUNIC FROM TMP_MANEVRA2);

    UPDATE Jurnal1
    SET Dirty = 1
    WHERE TipDoc = 16
      AND CodDoc IN (SELECT CODUNIC FROM TMP_MANEVRA2);

    DELETE FROM TMP_DiscMonetar WHERE DISCOUNT IS NULL;
    DELETE FROM Discmonetar     WHERE CodIes IN (SELECT CODUNIC FROM TMP_MANEVRA2);

    INSERT INTO DiscMonetar(CODDISCMONETAR, CODIES, PROCTVA, DISCOUNT, TVADISCOUNT)
    SELECT Coalesce(CODDISCMONETAR, NextVal('SEQ_DISCMONETAR_CODDISCMONETAR')), CODIES, PROCTVA, DISCOUNT, TVADISCOUNT
    FROM TMP_DiscMonetar;
  END IF;
  TRUNCATE TABLE TMP_DiscMonetar;
  TRUNCATE TABLE TMP_MANEVRA2;
END;

$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_updatetaxdeclluna</obj_name>
  <obj_hashval>2d8256707db786f644adce0e2169d8b2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_updatetaxdeclluna(pan numeric, pluna numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
VREC RECORD;
begin
  --Stef   16.02.2022 - sinc.
  FOR vRec IN (
    SELECT 0 AS CAZ, Codintr   AS CODDOC FROM intrari WHERE an = pAn AND luna = pLuna AND Operat = 1 AND TipDoc IN (1,3,4,5,9) UNION ALL
    SELECT 1 AS CAZ, Codies    AS CODDOC FROM iesiri  WHERE an = pAn AND luna = pLuna AND Operat = 1 AND TipDoc IN (19,21,26)  UNION ALL
    SELECT 2 AS CAZ, Codies    AS CODDOC FROM iesiri  WHERE an = pAn AND luna = pLuna AND Operat = 1 AND TipDoc IN (16)        UNION ALL
    SELECT 3 AS CAZ, CodTrezor AS CODDOC FROM trezor  WHERE an = pAn AND luna = pLuna AND Operat = 1 AND TipDoc IN (29,30,33)

  ) LOOP
    PERFORM PKG_SAFT_UpdateTaxDecl(vRec.CAZ, vRec.CODDOC);
  END LOOP;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_catret_sp_deleterecord</obj_name>
  <obj_hashval>47026df3c662bcdd216fc096addbb5fa</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_catret_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aDoc varchar(500);
BEGIN
  --Florin 04.04.2022 - postLog
  --Florin 01.03.2022
  PERFORM pkg_sal_catret_setct_monitor('MON_5');
  SELECT denumire || '(' || simbol || ')' INTO aDoc FROM TMP_SAL_CATRET;
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_CATRET.CT_MONITOR', true)))
  THEN
    PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit('SAL_CATRET', current_setting ('PKG_GLOBALS.USERNAME', true) , 'M', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
  PERFORM pkg_sal_catret_SP_LOCKRECORD( RecId);
  DELETE FROM SAL_CATRET
  WHERE
    CODCATRET = RecId;

end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_catret_sp_lockrecord</obj_name>
  <obj_hashval>1255729d7c12f72e513d1dd455a4cb23</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_catret_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
BEGIN
  --Florin 23.03.2022
  --Florin 01.03.2022
 SELECT CODCATRET INTO Tmp FROM SAL_CATRET WHERE CODCATRET = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_catret_sp_postrecords</obj_name>
  <obj_hashval>2f2c18a6af9afa18344f2291860207e6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_catret_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aDoc varchar(500);
BEGIN
  --Florin 27.10.2022 - returns record
  --Florin 04.04.2022 - postLog
  --Florin 23.03.2022
  --Florin 01.03.2022
  PERFORM pkg_sal_catret_setct_monitor('MON_5');
  SELECT denumire || '(' || simbol || ')' INTO aDoc FROM TMP_SAL_CATRET;
  IF Operation = 0 THEN  -- UPDATE
-- Master SAL_CATRET
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_CATRET.CT_MONITOR', true)))
  THEN
    PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit('SAL_CATRET', current_setting ('PKG_GLOBALS.USERNAME', true) , 'M', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
    SELECT  CODCATRET INTO RecId FROM TMP_SAL_CATRET;
    UPDATE SAL_CATRET SET (Denumire, Simbol) = ( SELECT Denumire, Simbol FROM TMP_SAL_CATRET )  WHERE CODCATRET = RecId ;
  ELSE  -- INSERT
-- Master SAL_CATRET
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_CATRET.CT_MONITOR', true)))
  THEN
    PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit('SAL_CATRET', current_setting ('PKG_GLOBALS.USERNAME', true) , 'M', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
    SELECT nextval('SEQ_SAL_CATRET_CODCATRET') INTO RecId;
    INSERT INTO  SAL_CATRET ( CODCATRET,Denumire, Simbol ) ( SELECT  RecId, Denumire, Simbol FROM TMP_SAL_CATRET  ) ;
  END IF;
  PERFORM NotifyModif(Operation, RecId, 'SAL_CATRET');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_catspor_sp_deleterecord</obj_name>
  <obj_hashval>32e7ff6ebec472ad8eee043208e4aa64</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_catspor_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aDoc varchar(500);
BEGIN
  --Florin 04.04.2022 - postLog
  --Florin 01.03.2022
  PERFORM pkg_sal_catSPOR_setct_monitor('MON_5');
  SELECT denumire || '(' || simbol || ')' INTO aDoc FROM TMP_SAL_CATSPOR;
IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_CATSPOR.CT_MONITOR', true)))
  THEN
    PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit('SAL_CATSPOR', current_setting ('PKG_GLOBALS.USERNAME', true) , 'M', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
  PERFORM PKG_SAL_CATSPOR_SP_LOCKRECORD( RecId);
  DELETE FROM SAL_CATSPOR
    WHERE CODCATSPOR = RecId;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_catspor_sp_postrecords</obj_name>
  <obj_hashval>41b09ae8efd7cf83835c94103f6f7fdd</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_catspor_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aDoc varchar(500);
BEGIN
  --Florin 27.10.2022 - returns record
  --Florin 04.04.2022 - postLog
  --Florin 01.03.2022
  PERFORM pkg_sal_catSPOR_setct_monitor('MON_5');
  SELECT denumire || '(' || simbol || ')' INTO aDoc FROM TMP_SAL_CATSPOR;
  IF  Operation = 0
  THEN
  SELECT CODCATSPOR
  INTO RecId
  FROM TMP_SAL_CATSPOR;
  UPDATE SAL_CATSPOR
  SET
  (Denumire, Simbol) = (
  SELECT Denumire, Simbol
  FROM TMP_SAL_CATSPOR
  )
  WHERE
   CODCATSPOR = RecId
  ;
  ELSE
  SELECT NEXTVAL('SEQ_SAL_CATSPOR_CODCATSPOR')
  INTO RecId;
  INSERT INTO SAL_CATSPOR
  (
  CODCATSPOR, Denumire, Simbol
  )
  (
  SELECT RecId, Denumire, Simbol
  FROM TMP_SAL_CATSPOR
  );
  END IF;
  PERFORM NotifyModif( Operation, RecId, 'SAL_CATSPOR');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_contrpp_getct_monitor</obj_name>
  <obj_hashval>063cbbc94e930885a80767b7ad024ed5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_contrpp_getct_monitor(wme_result character varying, fakeparam numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 01.03.2022
  WME_Result := current_setting('PKG_SAL_CONTRPP.CT_MONITOR', true);
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
  WME_Result := 'MON_5';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_contrpp_setct_monitor</obj_name>
  <obj_hashval>008b11b64231550e9ac3af50f85e1259</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_contrpp_setct_monitor(act_monitor character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 01.03.2022
  perform set_config('PKG_SAL_CONTRPP.CT_MONITOR',aCT_MONITOR,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_contrpp_sp_deleterecord</obj_name>
  <obj_hashval>be1b0303f185a18acad85ceecc148dfe</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_contrpp_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  adoc varchar;
BEGIN
  --Florin 04.04.2022 - PostLog
  --Florin 01.03.2022
  PERFORM pkg_sal_contrpp_setct_monitor('MON_5');
  SELECT codCONTRPP INTO aDoc FROM TMP_SAL_CONTRPP;
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_CONTRPP.CT_MONITOR', true)))
  THEN
    PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit('SAL_CONTRPP', current_setting ('PKG_GLOBALS.USERNAME', true) , 'S', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;

  PERFORM pkg_sal_contrpp_SP_LOCKRECORD(RecId);
  DELETE FROM SAL_CONTRPP1 WHERE CODCONTRPP = RecId ;
  DELETE FROM SAL_CONTRPP WHERE CODCONTRPP = RecId ;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_contrpp_sp_lockrecord</obj_name>
  <obj_hashval>d543dc9fad0a464bed9d46cb79eb0199</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_contrpp_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
BEGIN
  --Florin 01.03.2022
  SELECT CODCONTRPP
  INTO Tmp
  FROM SAL_CONTRPP
  WHERE
     CODCONTRPP = RecId;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_contrpp_sp_postrecords</obj_name>
  <obj_hashval>4b053c4cc2482e293d4016dcc64ba8a6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_contrpp_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aDoc varchar(500);
BEGIN
  --Florin 27.10.2022 - returns record
  --Florin 04.04.2022 - postLog
  --Florin 01.03.2022
  PERFORM pkg_sal_contrpp_setct_monitor('MON_5');
  SELECT codCONTRPP
  INTO aDoc
  FROM TMP_SAL_CONTRPP;
  SELECT codCONTRPP
  INTO RECID
  FROM TMP_SAL_CONTRPP;
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_CONTRPP.CT_MONITOR', true)))
  THEN
    PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit('SAL_CONTRPP', current_setting ('PKG_GLOBALS.USERNAME', true) , '', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
  IF  Operation = 0
  THEN
  SELECT CODCONTRPP
  INTO RecId
  FROM TMP_SAL_CONTRPP;
  UPDATE SAL_CONTRPP
  SET
  (  SUCURSALA)  = (
  SELECT SUCURSALA
  FROM TMP_SAL_CONTRPP
  )
  WHERE
   CODCONTRPP = RecId
  ;
  DELETE FROM SAL_CONTRPP1
  WHERE
   codCONTRPP = RECID AND codCONTRPP1 NOT IN (
  SELECT codCONTRPP1
  FROM TMP_SAL_CONTRPP1
  );
  INSERT INTO SAL_CONTRPP1
  (
  codCONTRPP1, codCONTRPP, ANGAJAT, NRCONTRACT, DATASTART, DATASTOP, FOND, PLATAFIRMA, CONTBANCAR, MODPLATA, RATA, ZIPLATA, DATAINREG, PLAFONLEI, PLAFONEURO, DIFERENTE, VALRATEAN, RETNEIMPOZ, RETIMPOZ
  )
  SELECT NEXTVAL('SEQ_SAL_CONTRPP1_CODCONTRPP1'), RECID, ANGAJAT, NRCONTRACT, DATASTART, DATASTOP, FOND, PLATAFIRMA, CONTBANCAR, MODPLATA, RATA, ZIPLATA, DATAINREG, PLAFONLEI, PLAFONEURO, DIFERENTE, VALRATEAN, RETNEIMPOZ, RETIMPOZ
  FROM TMP_SAL_CONTRPP1
  WHERE
     codCONTRPP1 &lt; 0;
  ELSE
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_CONTRPP.CT_MONITOR', true)))
  THEN
    PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit('SAL_CONTRPP', current_setting ('PKG_GLOBALS.USERNAME', true) , 'A', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
  SELECT NEXTVAL('SEQ_SAL_CONTRPP_CODCONTRPP')
  INTO RecId;
  INSERT INTO SAL_CONTRPP
  (
  CODCONTRPP, SUCURSALA
  )
  (
  SELECT RecId, SUCURSALA
  FROM TMP_SAL_CONTRPP
  );
  END IF;
  PERFORM NotifyModif( Operation, RecId, 'SAL_CONTRPP');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_dedgen_getct_monitor</obj_name>
  <obj_hashval>46ce29136376adf384f68a2e1863b6a1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_dedgen_getct_monitor(wme_result character varying, fakeparam numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aDoc varchar;
BEGIN
  --Florin 01.03.2022
  WME_Result := current_setting('PKG_SAL_DEDGEN.CT_MONITOR', true);
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
  WME_Result := 'MON_5';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_dedgen_setct_monitor</obj_name>
  <obj_hashval>829a87775096459b78e6fcfe6da89a9d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_dedgen_setct_monitor(act_monitor character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aDoc varchar;
BEGIN
  --Florin 01.03.2022
  perform set_config('PKG_SAL_DEDGEN.CT_MONITOR',aCT_MONITOR,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_dedgen_sp_deleterecord</obj_name>
  <obj_hashval>7ebc6babc15c12593525b2a3e7630b47</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_dedgen_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aDoc varchar;
BEGIN
  --Florin 31.03.2022 - postLog
  --Florin 01.03.2022
  PERFORM pkg_sal_dedgen_setct_monitor('MON_5');
  SELECT denumire
  INTO aDoc
  FROM TMP_SAL_DEDGEN;
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_DEDGEN.CT_MONITOR', true)))
  THEN
    PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit('SAL_DEDGEN', current_setting ('PKG_GLOBALS.USERNAME', true) , 'M', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
  PERFORM pkg_sal_dedgen_SP_LOCKRECORD( RecId);
  DELETE FROM SAL_DEDGEN1
  WHERE
   CODDEDGEN = RecId;
  DELETE FROM SAL_DEDGEN0
  WHERE
   CODDEDGEN = RecId;
  DELETE FROM SAL_DEDGEN
  WHERE
   CODDEDGEN = RecId;
  end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_dedgen_sp_gotorecord</obj_name>
  <obj_hashval>32d771f6cbcd099c897ecd8add7b6713</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_dedgen_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  AANSFARSIT numeric;
  ALUNASFARSIT numeric;
BEGIN
  --Florin 24.03.2022
  --Florin 01.03.2022
  INSERT INTO TMP_SAL_DEDGEN0
  (
  coddedgen0, coddedgen, contract, conventie, conventiecm, cumuls, cumulp, special, specialcv, asimilate, calcul, marime, rot, modrot, coop, internship, anstart, lunastart, alstart, alstop
  )
  (
  SELECT coddedgen0, coddedgen, contract, conventie, conventiecm, cumuls, cumulp, special, specialcv, asimilate, calcul, marime, rot, modrot, coop, internship, anstart, lunastart, alstart, alstop
  FROM SAL_DEDGEN0
  WHERE
     CODDEDGEN = RecId
  );
  INSERT INTO TMP_SAL_DEDGEN1
  (
  CODDEDGEN1, CODDEDGEN0, CODDEDGEN, PERS, LIMSUP, LIMINF, RELATIE
  )
  (
  SELECT CODDEDGEN1, CODDEDGEN0, CODDEDGEN, PERS, LIMSUP, LIMINF, RELATIE
  FROM SAL_DEDGEN1
  WHERE
     CODDEDGEN = RecId
  );
  INSERT INTO TMP_SAL_DEDGEN
  (
  CODDEDGEN, DENUMIRE, BAZA
  )
  (
  SELECT CODDEDGEN, DENUMIRE, BAZA
  FROM SAL_DEDGEN
  WHERE
     CODDEDGEN = RecId
  );
  AANSFARSIT := 0;
  ALUNASFARSIT := 0;
  FOR V_REC IN
  (
  SELECT CODDEDGEN0, ANSTART, LUNASTART
  FROM TMP_SAL_DEDGEN0
  ORDER BY
    ANSTART * 12 + LUNASTART desc
  )
  LOOP
  IF (   AANSFARSIT &lt;&gt; 0)  AND (   ALUNASFARSIT &lt;&gt; 0)
  THEN
  UPDATE TMP_SAL_DEDGEN0
  SET
  ANSFARSIT = AANSFARSIT,
  LUNASFARSIT = ALUNASFARSIT
  WHERE
   coddedgen0 = V_REC.CODDEDGEN0
  ;
  END IF;
  PERFORM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( V_REC.ANSTART, V_REC.LUNASTART, AANSFARSIT, ALUNASFARSIT);
  END LOOP;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_dedgen_sp_lockrecord</obj_name>
  <obj_hashval>59101c14babf28ed9185cdc3849e0618</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_dedgen_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
 DECLARE
  Tmp numeric;
BEGIN
  --Florin 01.03.2022
  SELECT CODDEDGEN
  INTO Tmp
  FROM SAL_DEDGEN
  WHERE
   CODDEDGEN = RecId;
  END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_dedgen_sp_postrecords</obj_name>
  <obj_hashval>0bec8bc913cd0377a40a2679cb3f6a3c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_dedgen_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  aDoc varchar;
  vCod numeric;
BEGIN
  --Florin 27.10.2022 - returns record
  --Florin 31.03.2022 - postLog
  --Florin 01.03.2022
  PERFORM pkg_sal_dedgen_setct_monitor('MON_5');
  SELECT denumire
  INTO aDoc
  FROM TMP_SAL_DEDGEN;
  IF  Operation = 0
  THEN
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_DEDGEN.CT_MONITOR', true)))
  THEN
    PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit('SAL_DEDGEN', current_setting ('PKG_GLOBALS.USERNAME', true) , 'M', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
  SELECT CODDEDGEN
  INTO RecId
  FROM TMP_SAL_DEDGEN;
  UPDATE SAL_DEDGEN
  SET
  (DENUMIRE, BAZA) = (
  SELECT DENUMIRE, BAZA
  FROM TMP_SAL_DEDGEN
  )
  WHERE
   CODDEDGEN = RecId
  ;
  DELETE FROM SAL_DEDGEN0
  WHERE
   coddedgen = RECID AND coddedgen0 NOT IN (
  SELECT ts0.coddedgen0
  FROM TMP_SAL_DEDGEN0 ts0
  );
  DELETE FROM SAL_DEDGEN1
  WHERE
   coddedgen = RECID AND (  coddedgen0 NOT IN (
  SELECT ts0.coddedgen0
  FROM TMP_SAL_DEDGEN0 ts0
  ) or coddedgen1 NOT IN (
  SELECT ts1.coddedgen1
  FROM TMP_SAL_DEDGEN1 ts1
  )) ;
  UPDATE SAL_DEDGEN0 s0
  SET
  (coddedgen0, coddedgen, contract, conventie, conventiecm, cumuls, cumulp, special, specialcv, asimilate, calcul, marime, rot, modrot, coop, internship, anstart, lunastart, alstart, alstop) = (
  SELECT coddedgen0, coddedgen, contract, conventie, conventiecm, cumuls, cumulp, special, specialcv, asimilate, calcul, marime, rot, modrot, coop, internship, anstart, lunastart, alstart, alstop
  FROM TMP_SAL_DEDGEN0 ts
  WHERE
     ts.coddedgen0 &gt; 0 and  ts.coddedgen0 = s0.coddedgen0
  )
  WHERE
   s0.coddedgen = RecId
  ;
  FOR v_rec IN
  (
  SELECT *
  FROM TMP_SAL_DEDGEN0
  WHERE
     coddedgen0 &lt; 0
  )
  LOOP
  SELECT NEXTVAL('SEQ_SAL_DEDGEN0_CODDEDGEN0')
  INTO vcod;
  UPDATE TMP_SAL_DEDGEN1
  SET
  coddedgen0 = vcod
  WHERE
   coddedgen0 = v_rec.coddedgen0
  ;
  INSERT INTO SAL_DEDGEN0
  (
  coddedgen0, coddedgen, contract, conventie, conventiecm, cumuls, cumulp, special, specialcv, asimilate, calcul, marime, rot, modrot, coop, internship, anstart, lunastart, alstart, alstop
  )
  VALUES
  (
  vcod, RecId, v_rec.contract, v_rec.conventie, v_rec.conventiecm, v_rec.cumuls, v_rec.cumulp, v_rec.special, v_rec.specialcv, v_rec.asimilate, v_rec.calcul, v_rec.marime, v_rec.rot, v_rec.modrot, v_rec.coop, v_rec.internship, v_rec.anstart, v_rec.lunastart, v_rec.alstart, v_rec.alstop
  );
  END LOOP;
  UPDATE SAL_DEDGEN1 s1
  SET
  (coddedgen1, coddedgen0, coddedgen, pers, limsup, liminf, relatie) = (
  SELECT coddedgen1, coddedgen0, coddedgen, pers, limsup, liminf, relatie
  FROM TMP_SAL_DEDGEN1 ts1
  WHERE
     ts1.coddedgen1 &gt; 0 and  ts1.coddedgen1 = s1.coddedgen1
  )
  WHERE
  s1.coddedgen1 IN (
  SELECT ti.coddedgen1
  FROM TMP_SAL_DEDGEN1 ti
  WHERE
     ti.coddedgen1 &gt; 0
  )
  ;
  INSERT INTO SAL_DEDGEN1
  (
  coddedgen1, coddedgen0, coddedgen, pers, limsup, liminf, relatie
  )
  SELECT NEXTVAL('SEQ_SAL_DEDGEN1_CODDEDGEN1'), coddedgen0, coddedgen, pers, limsup, liminf, relatie
  FROM TMP_SAL_DEDGEN1
  WHERE
     coddedgen1 &lt; 0;
  ELSE
    IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_DEDGEN.CT_MONITOR', true)))
    THEN
      PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit( 'SAL_DEDGEN', current_setting ('PKG_GLOBALS.USERNAME', true) , 'A', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
    END IF;
  SELECT NEXTVAL('SEQ_SAL_DEDGEN_CODDEDGEN')
  INTO RecId;
  INSERT INTO SAL_DEDGEN
  (
  CODDEDGEN, DENUMIRE, BAZA
  )
  (
  SELECT RecId, DENUMIRE, BAZA
  FROM TMP_SAL_DEDGEN
  );
  FOR v_rec IN
  (
  SELECT *
  FROM TMP_SAL_DEDGEN0
  )
  LOOP
  SELECT NEXTVAL('SEQ_SAL_DEDGEN0_CODDEDGEN0')
  INTO vcod;
  UPDATE TMP_SAL_DEDGEN1
  SET
  coddedgen0 = vcod
  WHERE
   coddedgen0 = v_rec.coddedgen0
  ;
  INSERT INTO SAL_DEDGEN0
  (
  coddedgen0, coddedgen, contract, conventie, conventiecm, cumuls, cumulp, special, specialcv, asimilate, calcul, marime, rot, modrot, coop, internship, anstart, lunastart, alstart, alstop
  )
  VALUES
  (
  vcod, RecId, v_rec.contract, v_rec.conventie, v_rec.conventiecm, v_rec.cumuls, v_rec.cumulp, v_rec.special, v_rec.specialcv, v_rec.asimilate, v_rec.calcul, v_rec.marime, v_rec.rot, v_rec.modrot, v_rec.coop, v_rec.internship, v_rec.anstart, v_rec.lunastart, v_rec.alstart, v_rec.alstop
  );
  END LOOP;
  INSERT INTO SAL_DEDGEN1
  (
  coddedgen1, coddedgen0, coddedgen, pers, limsup, liminf, relatie
  )
  SELECT NEXTVAL('SEQ_SAL_DEDGEN1_CODDEDGEN1'), coddedgen0, RecId, pers, limsup, liminf, relatie
  FROM TMP_SAL_DEDGEN1
  WHERE
     coddedgen0 &gt; 0;
  END IF;
  PERFORM NotifyModif( Operation, RecId, 'SAL_DEDGEN');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_fondp_sp_insertrecord</obj_name>
  <obj_hashval>4d0f5bfabcb497171059e47c01870a3b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_fondp_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
 DECLARE
Tmp numeric;
BEGIN
  --Florin 01.03.2022
   INSERT INTO TMP_SAL_FONDP
  (
  CODFONDP
  )
  VALUES
  (
  0
  );
  END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_fondp_sp_lockrecord</obj_name>
  <obj_hashval>af510e85480a39b2f505b42e163e5ee7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_fondp_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
 DECLARE
Tmp numeric;
BEGIN
  --Florin 01.03.2022
  SELECT CODFONDP
  INTO Tmp
  FROM SAL_FONDP
  WHERE
   CODFONDP = RecId;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_fondp_sp_postrecords</obj_name>
  <obj_hashval>dd0aa2d487a3ba53cb481329573562fc</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_fondp_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aDoc varchar(500);
BEGIN
  --Florin 27.10.2022 - returns record
  --Florin 04.04.2022 - postLog
  --Florin 01.03.2022
  PERFORM pkg_sal_FONDP_setct_monitor('MON_5');
  SELECT denumire INTO aDoc FROM TMP_SAL_FONDP;
  IF  Operation = 0
  THEN
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_FONDP.CT_MONITOR', true)))
  THEN
    PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit('SAL_FONDP', current_setting ('PKG_GLOBALS.USERNAME', true) , 'M', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
  SELECT CODFONDP
  INTO RecId
  FROM TMP_SAL_FONDP;
  UPDATE SAL_FONDP
  SET
  (  Denumire)  = (
  SELECT Denumire
  FROM TMP_SAL_FONDP
  )
  WHERE
   CODFONDP = RecId
  ;
  ELSE
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_FONDP.CT_MONITOR', true)))
  THEN
    PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit('SAL_FONDP', current_setting ('PKG_GLOBALS.USERNAME', true) , 'A', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
  SELECT NEXTVAL('SEQ_SAL_FONDP_CODFONDP')
  INTO RecId;
  INSERT INTO SAL_FONDP
  (
  CODFONDP, Denumire
  )
  (
  SELECT RecId, Denumire
  FROM TMP_SAL_FONDP
  );
  END IF;
  PERFORM NotifyModif( Operation, RecId, 'SAL_FONDP');
  END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_impoz_sp_deleterecord</obj_name>
  <obj_hashval>61d1f85c8c808097f0dc837f8d9a7db0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_impoz_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aDoc varchar;
BEGIN
  --Florin 31.03.2022 - postLog
  --Florin 02.03.2022
  PERFORM pkg_sal_impoz_setct_monitor('MON_5');
  SELECT denumire
  INTO aDoc
  FROM TMP_SAL_IMPOZ;
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true)::numeric, current_setting('PKG_SAL_IMPOZ.CT_MONITOR', true)))
  THEN
    PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit('SAL_IMPOZ', current_setting ('PKG_GLOBALS.USERNAME', true) , 'S', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
  PERFORM PKG_SAL_IMPOZ_SP_LOCKRECORD( RecId);
  DELETE FROM SAL_IMPOZ1
  WHERE
   CODIMPOZ = RecId;
  DELETE FROM SAL_IMPOZ0
  WHERE
   CODIMPOZ = RecId;
  DELETE FROM SAL_IMPOZ
  WHERE
   CODIMPOZ = RecId;
  END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_impoz_sp_gotorecord</obj_name>
  <obj_hashval>b27922b9a8c3bf1fe9fd1c2f079f9c67</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_impoz_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
 DECLARE
  V_REC RECORD;
  AANSFARSIT numeric;
  ALUNASFARSIT numeric;
BEGIN
  --Florin 02.03.2022
  INSERT INTO TMP_SAL_IMPOZ0
  (
  codimpoz0, codimpoz, lacontr, laconv, laconvcm, lacumulsal, lacumulpens, laspecial, laspecialcv, laasimilate, rot, trunchiere, coop, internship, anstart, lunastart, alstart, alstop
  )
  (
  SELECT codimpoz0, codimpoz, lacontr, laconv, laconvcm, lacumulsal, lacumulpens, laspecial, laspecialcv, laasimilate, rot, trunchiere, coop, internship, anstart, lunastart, alstart, alstop
  FROM SAL_IMPOZ0
  WHERE
     CODIMPOZ = RecId
  );
  INSERT INTO TMP_SAL_IMPOZ1
  (
  CODIMPOZ1, CODIMPOZ0, CODIMPOZ, LIMINF, LIMSUP, VALFIXA, PROCENT
  )
  (
  SELECT CODIMPOZ1, CODIMPOZ0, CODIMPOZ, LIMINF, LIMSUP, VALFIXA, PROCENT
  FROM SAL_IMPOZ1
  WHERE
     CODIMPOZ = RecId
  );
  INSERT INTO TMP_SAL_IMPOZ
  (
  CODIMPOZ, DENUMIRE, LUNAR
  )
  (
  SELECT CODIMPOZ, DENUMIRE, LUNAR
  FROM SAL_IMPOZ
  WHERE
     CODIMPOZ = RecId
  );
  AANSFARSIT := 0;
  ALUNASFARSIT := 0;
  FOR V_REC IN
  (
  SELECT CODIMPOZ0, ANSTART, LUNASTART
  FROM TMP_SAL_IMPOZ0
  ORDER BY
    ANSTART * 12 + LUNASTART desc
  )
  LOOP
  IF (   AANSFARSIT &lt;&gt; 0)  AND (   ALUNASFARSIT &lt;&gt; 0)
  THEN
  UPDATE TMP_SAL_IMPOZ0
  SET
  ANSFARSIT = AANSFARSIT,
  LUNASFARSIT = ALUNASFARSIT
  WHERE
   codimpoz0 = V_REC.CODIMPOZ0
  ;
  END IF;
  PERFORM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( V_REC.ANSTART, V_REC.LUNASTART, AANSFARSIT, ALUNASFARSIT);
  END LOOP;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_impoz_sp_insertrecord</obj_name>
  <obj_hashval>e1253a7c388bdd747f117d9e9eac1e40</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_impoz_sp_insertrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 02.03.2022
  INSERT INTO TMP_SAL_IMPOZ
  (
  CODIMPOZ
  )
  VALUES
  (
  0
  );
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_impoz_sp_lockrecord</obj_name>
  <obj_hashval>79fdb6bbb93dfa5f9a4324122b86ac96</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_impoz_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
 DECLARE
  Tmp numeric;
BEGIN
  --Florin 02.03.2022
  SELECT CODIMPOZ
  INTO Tmp
  FROM SAL_IMPOZ
  WHERE
     CODIMPOZ = RecId;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_impoz_sp_postrecords</obj_name>
  <obj_hashval>953ae8a47d9c41b80d1db75fac76450a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_impoz_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
 DECLARE
  V_REC RECORD;
  aDoc varchar;
  vCod numeric;
BEGIN
  --Florin 27.10.2022 - returns record
  --Florin 31.03.2022 - postLog
  --Florin 02.03.2022
  PERFORM pkg_sal_impoz_setct_monitor('MON_5');
  SELECT denumire
  INTO aDoc
  FROM TMP_SAL_IMPOZ;
  IF  Operation = 0
  THEN
    IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true)::numeric, current_setting('PKG_SAL_IMPOZ.CT_MONITOR', true)))
    THEN
      PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit( 'SAL_IMPOZ', current_setting ('PKG_GLOBALS.USERNAME', true) , 'M', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
    END IF;
  SELECT CODIMPOZ
  INTO RecId
  FROM TMP_SAL_IMPOZ;
  UPDATE SAL_IMPOZ
  SET
  (DENUMIRE, LUNAR) = (
  SELECT DENUMIRE, LUNAR
  FROM TMP_SAL_IMPOZ
  )
  WHERE
   CODIMPOZ = RecId
  ;
  DELETE FROM SAL_IMPOZ0
  WHERE
   codimpoz = RECID AND codimpoz0 NOT IN (
  SELECT ts0.codimpoz0
  FROM TMP_SAL_IMPOZ0 ts0
  );
  DELETE FROM SAL_IMPOZ1
  WHERE
   codimpoz = RECID AND (  codimpoz0 NOT IN (
  SELECT ts0.codimpoz0
  FROM TMP_SAL_IMPOZ0 ts0
  ) or codimpoz1 NOT IN (
  SELECT ts1.codimpoz1
  FROM TMP_SAL_IMPOZ1 ts1
  )) ;
  UPDATE SAL_IMPOZ0 s0
  SET
  (codimpoz0, codimpoz, lacontr, laconv, laconvcm, lacumulsal, lacumulpens, laspecial, laspecialcv, laasimilate, rot, trunchiere, coop, internship, anstart, lunastart, alstart, alstop) = (
  SELECT codimpoz0, codimpoz, lacontr, laconv, laconvcm, lacumulsal, lacumulpens, laspecial, laspecialcv, laasimilate, rot, trunchiere, coop, internship, anstart, lunastart, alstart, alstop
  FROM TMP_SAL_IMPOZ0 ts
  WHERE
     ts.codimpoz0 &gt; 0 and  ts.codimpoz0 = s0.codimpoz0
  )
  WHERE
   s0.codimpoz = RecId
  ;
  FOR v_rec IN
  (
  SELECT *
  FROM TMP_SAL_IMPOZ0
  WHERE
     codimpoz0 &lt; 0
  )
  LOOP
  SELECT NEXTVAL('SEQ_SAL_IMPOZ0_CODIMPOZ0')
  INTO vcod;
  UPDATE TMP_SAL_IMPOZ1
  SET
  codimpoz0 = vcod
  WHERE
   codimpoz0 = v_rec.codimpoz0
  ;
  INSERT INTO SAL_IMPOZ0
  (
  codimpoz0, codimpoz, lacontr, laconv, laconvcm, lacumulsal, lacumulpens, laspecial, laspecialcv, laasimilate, rot, trunchiere, coop, internship, anstart, lunastart, alstart, alstop
  )
  VALUES
  (
  vcod, RecId, v_rec.lacontr, v_rec.laconv, v_rec.laconvcm, v_rec.lacumulsal, v_rec.lacumulpens, v_rec.laspecial, v_rec.laspecialcv, v_rec.laasimilate, v_rec.rot, v_rec.trunchiere, v_rec.coop, v_rec.internship, v_rec.anstart, v_rec.lunastart, v_rec.alstart, v_rec.alstop
  );
  END LOOP;
  UPDATE SAL_IMPOZ1 s1
  SET
  (codimpoz1, codimpoz0, codimpoz, liminf, limsup, valfixa, procent) = (
  SELECT codimpoz1, codimpoz0, codimpoz, liminf, limsup, valfixa, procent
  FROM TMP_SAL_IMPOZ1 ts1
  WHERE
     ts1.codimpoz1 &gt; 0 and  ts1.codimpoz1 = s1.codimpoz1
  )
  WHERE
  s1.codimpoz1 IN (
  SELECT ti.codimpoz1
  FROM TMP_SAL_IMPOZ1 ti
  WHERE
     ti.codimpoz1 &gt; 0
  )
  ;
  INSERT INTO SAL_IMPOZ1
  (
  codimpoz1, codimpoz0, codimpoz, liminf, limsup, valfixa, procent
  )
  SELECT NEXTVAL('SEQ_SAL_IMPOZ1_CODIMPOZ1'), codimpoz0, codimpoz, liminf, limsup, valfixa, procent
  FROM TMP_SAL_IMPOZ1
  WHERE
     codimpoz1 &lt; 0;
  ELSE
    IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true)::numeric, current_setting('PKG_SAL_IMPOZ.CT_MONITOR', true)))
      THEN
    PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit( 'SAL_IMPOZ', current_setting ('PKG_GLOBALS.USERNAME', true) , 'A', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
    END IF;
  SELECT NEXTVAL('SEQ_SAL_IMPOZ_CODIMPOZ')
  INTO RecId;
  INSERT INTO SAL_IMPOZ
  (
  CODIMPOZ, DENUMIRE, LUNAR
  )
  (
  SELECT RecId, DENUMIRE, LUNAR
  FROM TMP_SAL_IMPOZ
  );
  FOR v_rec IN
  (
  SELECT *
  FROM TMP_SAL_IMPOZ0
  )
  LOOP
  SELECT NEXTVAL('SEQ_SAL_IMPOZ0_CODIMPOZ0')
  INTO vcod;
  UPDATE TMP_SAL_IMPOZ1
  SET
  codimpoz0 = vcod
  WHERE
   codimpoz0 = v_rec.codimpoz0
  ;
  INSERT INTO SAL_IMPOZ0
  (
  codimpoz0, codimpoz, lacontr, laconv, laconvcm, lacumulsal, lacumulpens, laspecial, laspecialcv, laasimilate, rot, trunchiere, coop, internship, anstart, lunastart, alstart, alstop
  )
  VALUES
  (
  vcod, RecId, v_rec.lacontr, v_rec.laconv, v_rec.laconvcm, v_rec.lacumulsal, v_rec.lacumulpens, v_rec.laspecial, v_rec.laspecialcv, v_rec.laasimilate, v_rec.rot, v_rec.trunchiere, v_rec.coop, v_rec.internship, v_rec.anstart, v_rec.lunastart, v_rec.alstart, v_rec.alstop
  );
  END LOOP;
  INSERT INTO SAL_IMPOZ1
  (
  codimpoz1, codimpoz0, codimpoz, liminf, limsup, valfixa, procent
  )
  SELECT NEXTVAL('SEQ_SAL_IMPOZ1_CODIMPOZ1'), codimpoz0, RecId, liminf, limsup, valfixa, procent
  FROM TMP_SAL_IMPOZ1
  WHERE
     codimpoz0 &gt; 0;
  END IF;
  PERFORM NotifyModif(Operation, RecId, 'SAL_IMPOZ');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_nasig_sp_deleterecord</obj_name>
  <obj_hashval>4519c85c3ac100b6ac999999cb211d63</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_nasig_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aDoc varchar(500);
BEGIN
  --Florin 02.03.2022
  PERFORM pkg_sal_nasig_setct_monitor('MON_5');
  SELECT tip
  INTO aDoc
  FROM TMP_SAL_NASIG;
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true)::numeric, current_setting('PKG_SAL_NASIG.CT_MONITOR', true)))
  THEN
    PERFORM WINMADMIN.pkg_userfirme_postlogcucommit('SAL_NASIG', current_setting ('PKG_GLOBALS.USERNAME', true) , 'M', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
  PERFORM PKG_SAL_NASIG_SP_LOCKRECORD( RecId);
  DELETE FROM SAL_NASIG3 SG3
  WHERE
  SG3.codnasig0 IN (
  SELECT ISG0.codnasig0
  FROM SAL_NASIG0 ISG0
  WHERE
     ISG0.codnasig = RecId
  );
  DELETE FROM SAL_NASIG2 SG2
  WHERE
  SG2.codnasig0 IN (
  SELECT ISG0.codnasig0
  FROM SAL_NASIG0 ISG0
  WHERE
     ISG0.codnasig = RecId
  );
  DELETE FROM SAL_NASIG1 SG1
  WHERE
  SG1.codnasig0 IN (
  SELECT ISG0.codnasig0
  FROM SAL_NASIG0 ISG0
  WHERE
     ISG0.codnasig = RecId
  );
  DELETE FROM SAL_NASIG0
  WHERE
   codnasig = RecId;
  DELETE FROM SAL_NASIG
  WHERE
   codnasig = RecId;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_nasig_sp_gotorecord</obj_name>
  <obj_hashval>f4b959a292dbd1ac1611cdfef7e542fa</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_nasig_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
 DECLARE
  V_REC RECORD;
  AANSFARSIT numeric;
  ALUNASFARSIT numeric;
  codAsig0Debug numeric;
  nrInreg numeric;
BEGIN
  --Florin 02.03.2022
  INSERT INTO TMP_SAL_NASIG
  (
  codnasig, tip, codasig, caracter, intrerupere
  )
  (
  SELECT codnasig, tip, codasig, caracter, intrerupere
  FROM SAL_NASIG
  WHERE
     codnasig = RecId
  );
  INSERT INTO TMP_SAL_NASIG0
  (
  codnasig0, codnasig, Bazacalcul, Angajator, Cont1, Asigurare, Cont2, ContribSalMinEcFirma, ContribSalMinEcCAS, Penalizare, Impozit, CrestereCopil, SuspendareCM, Buget, NoAngajat, NoAngajator, ZilePlataFirma, NeavizatCAS, Plafonare, NoDeducere, Constructii, ANSTART, LUNASTART, ALSTART, ALSTOP
  )
  (
  SELECT codnasig0, codnasig, Bazacalcul, Angajator, Cont1, Asigurare, Cont2, ContribSalMinEcFirma, ContribSalMinEcCAS, Penalizare, Impozit, CrestereCopil, SuspendareCM, Buget, NoAngajat, NoAngajator, ZilePlataFirma, NeavizatCAS, Plafonare, NoDeducere, Constructii, ANSTART, LUNASTART, ALSTART, ALSTOP
  FROM SAL_NASIG0
  WHERE
     codnasig = RecId
  );
  INSERT INTO TMP_SAL_NASIG1
  (
  codnasig1, codnasig0, modcalcul, conditionare, umv, dmodcalc, dcond, dum
  )
  (
  SELECT nasg1.codnasig1, nasg1.codnasig0, nasg1.modcalcul, nasg1.conditionare, nasg1.umv, mdc.denumire, condas.denumire, CASE nasg1.umv
   WHEN 0 THEN ''
   WHEN 1 THEN 'luni'
   WHEN 2 THEN 'ani'
   ELSE '???'
   END  AS DUM
  FROM SAL_NASIG1 nasg1
  LEFT JOIN SAL_NMODC mdc ON  mdc.codmodc = nasg1.modcalcul
  LEFT JOIN SAL_NCONDAS condas ON  condas.codncondas = nasg1.conditionare
  WHERE
    codnasig0 IN (
  SELECT tnasig.codnasig0
  FROM TMP_SAL_NASIG0 tnasig
  )
  );
  INSERT INTO TMP_SAL_NASIG2
  (
  codnasig2, codnasig0, codnasig1, cuantum, liminf, limsup
  )
  (
  SELECT codnasig2, codnasig0, codnasig1, cuantum, liminf, limsup
  FROM SAL_NASIG2
  WHERE
    codnasig0 IN (
  SELECT tnasig.codnasig0
  FROM TMP_SAL_NASIG0 tnasig
  )
  );
  INSERT INTO TMP_SAL_NASIG3
  (
  codnasig3, codnasig0, tip, elemcalcul, multiplicare, codcont, contributie
  )
  (
  SELECT codnasig3, codnasig0, tip, elemcalcul, multiplicare, codcont, contributie
  FROM SAL_NASIG3
  WHERE
    codnasig0 IN (
  SELECT tnasig.codnasig0
  FROM TMP_SAL_NASIG0 tnasig
  )
  );
  AANSFARSIT := 0;
  ALUNASFARSIT := 0;
  FOR V_REC IN
  (
  SELECT codnasig0, ANSTART, LUNASTART
  FROM TMP_SAL_NASIG0
  ORDER BY
    ANSTART * 12 + LUNASTART desc
  )
  LOOP
  IF (   AANSFARSIT &lt;&gt; 0)  AND (   ALUNASFARSIT &lt;&gt; 0)
  THEN
  UPDATE TMP_SAL_NASIG0
  SET
  ANSFARSIT = AANSFARSIT,
  LUNASFARSIT = ALUNASFARSIT
  WHERE
   codnasig0 = V_REC.codnasig0
  ;
  END IF;
  PERFORM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( V_REC.ANSTART, V_REC.LUNASTART, AANSFARSIT, ALUNASFARSIT);
  END LOOP;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_ncontrib_ct_monitor</obj_name>
  <obj_hashval>249572785eed26bc3aa679d03bcbdfb1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_ncontrib_ct_monitor(wme_result character varying, fakeparam numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 02.03.2022
  WME_Result := current_setting('PKG_SAL_NCONTRIB.CT_MONITOR', true);
  RETURN;
  EXCEPTION WHEN undefined_object THEN
  WME_Result := 'MON_5';
  RETURN;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_ncontrib_getct_monitor</obj_name>
  <obj_hashval>090fe4065a7edfeda7132ca7841118aa</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_ncontrib_getct_monitor(wme_result character varying, fakeparam numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 02.03.2022
  WME_Result := current_setting('PKG_SAL_NCONTRIB.CT_MONITOR', true);
  RETURN;
  EXCEPTION WHEN undefined_object THEN
  WME_Result := 'MON_5';
  RETURN;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_ncontrib_setct_monitor</obj_name>
  <obj_hashval>2a23f73ae8e27705d3558e075d1e43f8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_ncontrib_setct_monitor(act_monitor character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 02.03.2022
  perform set_config('PKG_SAL_NCONTRIB.CT_MONITOR',aCT_MONITOR,false);
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_ncontrib_sp_deleterecord</obj_name>
  <obj_hashval>26225c72bb0fb3b8ffd42da66fa4936a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_ncontrib_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
  DECLARE aDoc varchar;
BEGIN
  --Florin 30.03.2022 - PostLog
  --Florin 02.03.2022
  PERFORM pkg_sal_ncontrib_setct_monitor('MON_5');
  SELECT denumire
  INTO aDoc
  FROM TMP_SAL_NCONTRIB;
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true)::numeric, current_setting('PKG_SAL_NCONTRIB.CT_MONITOR', true)))
  THEN
    PERFORM WINMADMIN.pkg_userfirme_postlogcucommit('PKG_SAL_NCONTRIB', current_setting ('PKG_GLOBALS.USERNAME', true) , 'S', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, NULL, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
  PERFORM PKG_SAL_NCONTRIB_SP_LOCKRECORD( RecId);
  DELETE FROM SAL_NCONTRIB1
  WHERE
   codncontrib = RecId;
  DELETE FROM SAL_NCONTRIB
  WHERE
   codncontrib = RecId;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_ncontrib_sp_gotorecord</obj_name>
  <obj_hashval>d6e95e98ef97e89709a2b8c6b3c22c26</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_ncontrib_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
V_REC RECORD;
AANSFARSIT numeric;
ALUNASFARSIT numeric;
BEGIN
  --Florin 22.03.2022
  --Florin 02.03.2022
  INSERT INTO TMP_SAL_NCONTRIB
  (
  codncontrib, Tip, Denumire, TipContributie
  )
  (
  SELECT codncontrib, Tip, Denumire, TipContributie
  FROM SAL_NCONTRIB
  WHERE
     codncontrib = RecId
  );
  INSERT INTO TMP_SAL_NCONTRIB1
  (
  codncontrib1, codncontrib, Marime, Modcalcul, ImpozitatCtr, CodCont, CodContchelt, CodContCAS, CodContAMBP, LaContr, LaConv, LaConvCM, LaCumulSal, LaCumulPens, LaPartSal, LaPreaviz, LaSpecial, LaSpecialCV, LaAsimilate, Grupa1, Grupa2, Grupa3, Grupa4, SpecialCB, ImpozitatCv, ImpozitatCvCM, ImpozitatCS, ImpozitatCP, ImpozitatSpec, ImpozitatSpecCV, ImpozitatAS, VarstaMin, VenitMin, VenitMax, TipContractual, Buget, TipLimitare, Referinta, Multiplic, Constructii, LaCoop, LaInternship, ANSTART, LUNASTART, ALSTART, ALSTOP
  )
  (
  SELECT codncontrib1, codncontrib, Marime, Modcalcul, ImpozitatCtr, CodCont, CodContchelt, CodContCAS, CodContAMBP, LaContr, LaConv, LaConvCM, LaCumulSal, LaCumulPens, LaPartSal, LaPreaviz, LaSpecial, LaSpecialCV, LaAsimilate, Grupa1, Grupa2, Grupa3, Grupa4, SpecialCB, ImpozitatCv, ImpozitatCvCM, ImpozitatCS, ImpozitatCP, ImpozitatSpec, ImpozitatSpecCV, ImpozitatAS, VarstaMin, VenitMin, VenitMax, TipContractual, Buget, TipLimitare, Referinta, Multiplic, Constructii, LaCoop, LaInternship, ANSTART, LUNASTART, ALSTART, ALSTOP
  FROM SAL_NCONTRIB1
  WHERE
     codncontrib = RecId
  );
  AANSFARSIT := 0;
  ALUNASFARSIT := 0;
  FOR V_REC IN
  (
  SELECT codncontrib1, ANSTART, LUNASTART
  FROM TMP_SAL_NCONTRIB1
  ORDER BY
    ANSTART * 12 + LUNASTART desc
  )
  LOOP
  IF (   AANSFARSIT &lt;&gt; 0)  AND (   ALUNASFARSIT &lt;&gt; 0)
  THEN
  UPDATE TMP_SAL_NCONTRIB1
  SET
  ANSFARSIT = AANSFARSIT,
  LUNASFARSIT = ALUNASFARSIT
  WHERE
   codncontrib1 = V_REC.codncontrib1
  ;
  END IF;
  select newan, newluna into AANSFARSIT, ALUNASFARSIT FROM  PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( V_REC.ANSTART, V_REC.LUNASTART, AANSFARSIT, ALUNASFARSIT);
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_ncontrib_sp_postrecords</obj_name>
  <obj_hashval>dead9a13583c2a8ac47c213a19411d21</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_ncontrib_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
aDoc varchar;
BEGIN
  --Florin 30.03.2022 - PostLog
  --Florin 02.03.2022
  PERFORM pkg_sal_ncontrib_setct_monitor('MON_5');
  SELECT denumire
  INTO aDoc
  FROM TMP_SAL_NCONTRIB;
  IF  Operation = 0
    THEN
    SELECT codncontrib
    INTO RECID
    FROM TMP_SAL_NCONTRIB;
    IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true)::numeric, current_setting('PKG_SAL_NCONTRIB.CT_MONITOR', true)))
    THEN
      PERFORM WINMADMIN.pkg_userfirme_postlogcucommit('PKG_SAL_NCONTRIB', current_setting ('PKG_GLOBALS.USERNAME', true) , 'M', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, NULL, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
    END IF;
  UPDATE SAL_NCONTRIB
  SET
  (codncontrib, Tip, Denumire, TipContributie) = (
  SELECT codncontrib, Tip, Denumire, TipContributie
  FROM TMP_SAL_NCONTRIB
  )
  WHERE
   codncontrib = RecId
  ;
  DELETE FROM SAL_NCONTRIB1
  WHERE
   codncontrib = RecId and codncontrib1 NOT IN (
  SELECT codncontrib1
  FROM TMP_SAL_NCONTRIB1
  );
  UPDATE SAL_NCONTRIB1 nc
  SET
  (codncontrib1, codncontrib, Marime, Modcalcul, ImpozitatCtr, CodCont, CodContchelt, CodContCAS, CodContAMBP, LaContr, LaConv, LaConvCM, LaCumulSal, LaCumulPens, LaPartSal, LaPreaviz, LaSpecial, LaSpecialCV, LaAsimilate, Grupa1, Grupa2, Grupa3, Grupa4, SpecialCB, ImpozitatCv, ImpozitatCvCM, ImpozitatCS, ImpozitatCP, ImpozitatSpec, ImpozitatSpecCV, ImpozitatAS, VarstaMin, VenitMin, VenitMax, TipContractual, Buget, TipLimitare, Referinta, Multiplic, Constructii, LaCoop, LaInternship, ANSTART, LUNASTART, ALSTART, ALSTOP) = (
  SELECT codncontrib1, codncontrib, Marime, Modcalcul, ImpozitatCtr, CodCont, CodContchelt, CodContCAS, CodContAMBP, LaContr, LaConv, LaConvCM, LaCumulSal, LaCumulPens, LaPartSal, LaPreaviz, LaSpecial, LaSpecialCV, LaAsimilate, Grupa1, Grupa2, Grupa3, Grupa4, SpecialCB, ImpozitatCv, ImpozitatCvCM, ImpozitatCS, ImpozitatCP, ImpozitatSpec, ImpozitatSpecCV, ImpozitatAS, VarstaMin, VenitMin, VenitMax, TipContractual, Buget, TipLimitare, Referinta, Multiplic, Constructii, LaCoop, LaInternship, ANSTART, LUNASTART, ALSTART, ALSTOP
  FROM TMP_SAL_NCONTRIB1 tnc
  WHERE
     tnc.codncontrib1 &gt; 0 and  tnc.codncontrib1 = nc.codncontrib1
  )
  WHERE
   nc.codncontrib = RecId
  ;
  INSERT INTO SAL_NCONTRIB1
  (
  codncontrib1, codncontrib, Marime, Modcalcul, ImpozitatCtr, CodCont, CodContchelt, CodContCAS, CodContAMBP, LaContr, LaConv, LaConvCM, LaCumulSal, LaCumulPens, LaPartSal, LaPreaviz, LaSpecial, LaSpecialCV, LaAsimilate, Grupa1, Grupa2, Grupa3, Grupa4, SpecialCB, ImpozitatCv, ImpozitatCvCM, ImpozitatCS, ImpozitatCP, ImpozitatSpec, ImpozitatSpecCV, ImpozitatAS, VarstaMin, VenitMin, VenitMax, TipContractual, Buget, TipLimitare, Referinta, Multiplic, Constructii, LaCoop, LaInternship, ANSTART, LUNASTART, ALSTART, ALSTOP
  )
  (
  SELECT NEXTVAL('SEQ_SAL_NCONTRIB1_CODNCONTRIB1'), codncontrib, Marime, Modcalcul, ImpozitatCtr, CodCont, CodContchelt, CodContCAS, CodContAMBP, LaContr, LaConv, LaConvCM, LaCumulSal, LaCumulPens, LaPartSal, LaPreaviz, LaSpecial, LaSpecialCV, LaAsimilate, Grupa1, Grupa2, Grupa3, Grupa4, SpecialCB, ImpozitatCv, ImpozitatCvCM, ImpozitatCS, ImpozitatCP, ImpozitatSpec, ImpozitatSpecCV, ImpozitatAS, VarstaMin, VenitMin, VenitMax, TipContractual, Buget, TipLimitare, Referinta, Multiplic, Constructii, LaCoop, LaInternship, ANSTART, LUNASTART, ALSTART, ALSTOP
  FROM TMP_SAL_NCONTRIB1
  WHERE
     codncontrib1 &lt; 0
  );
  ELSE
    IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true)::numeric, current_setting('PKG_SAL_NCONTRIB.CT_MONITOR', true)))
    THEN
      PERFORM WINMADMIN.pkg_userfirme_postlogcucommit('PKG_SAL_NCONTRIB', current_setting ('PKG_GLOBALS.USERNAME', true) , 'A', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
    END IF;
  SELECT NEXTVAL('SEQ_SAL_NCONTRIB_CODNCONTRIB')
  INTO RecId;
  INSERT INTO SAL_NCONTRIB
  (
  codncontrib, Tip, Denumire, TipContributie
  )
  (
  SELECT RecId, Tip, Denumire, TipContributie
  FROM TMP_SAL_NCONTRIB
  );
  INSERT INTO SAL_NCONTRIB1
  (
  codncontrib1, codncontrib, Marime, Modcalcul, ImpozitatCtr, CodCont, CodContchelt, CodContCAS, CodContAMBP, LaContr, LaConv, LaConvCM, LaCumulSal, LaCumulPens, LaPartSal, LaPreaviz, LaSpecial, LaSpecialCV, LaAsimilate, Grupa1, Grupa2, Grupa3, Grupa4, SpecialCB, ImpozitatCv, ImpozitatCvCM, ImpozitatCS, ImpozitatCP, ImpozitatSpec, ImpozitatSpecCV, ImpozitatAS, VarstaMin, VenitMin, VenitMax, TipContractual, Buget, TipLimitare, Referinta, Multiplic, Constructii, LaCoop, LaInternship, ANSTART, LUNASTART, ALSTART, ALSTOP
  )
  (
  SELECT NEXTVAL('SEQ_SAL_NCONTRIB1_CODNCONTRIB1'), RecId, Marime, Modcalcul, ImpozitatCtr, CodCont, CodContchelt, CodContCAS, CodContAMBP, LaContr, LaConv, LaConvCM, LaCumulSal, LaCumulPens, LaPartSal, LaPreaviz, LaSpecial, LaSpecialCV, LaAsimilate, Grupa1, Grupa2, Grupa3, Grupa4, SpecialCB, ImpozitatCv, ImpozitatCvCM, ImpozitatCS, ImpozitatCP, ImpozitatSpec, ImpozitatSpecCV, ImpozitatAS, VarstaMin, VenitMin, VenitMax, TipContractual, Buget, TipLimitare, Referinta, Multiplic, Constructii, LaCoop, LaInternship, ANSTART, LUNASTART, ALSTART, ALSTOP
  FROM TMP_SAL_NCONTRIB1
  );
  END IF;
  CALL PRC_AL_REFRESH('SAL_NCONTRIB1', RECID);
  PERFORM NotifyModif( Operation, RecId, 'SAL_NCONTRIB');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_ndrep_ct_monitor</obj_name>
  <obj_hashval>a5409225680682c1bba8ee01f5d79820</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_ndrep_ct_monitor(wme_result character varying, fakeparam numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 02.03.2022
  WME_Result := current_setting('PKG_SAL_NDREP.CT_MONITOR', true);
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 'MON_5';
RETURN ;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_ndrep_getct_monitor</obj_name>
  <obj_hashval>bfea505f8a2b85fcd5209b9ed44be91d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_ndrep_getct_monitor(wme_result character varying, fakeparam numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 02.03.2022
  WME_Result := current_setting('PKG_SAL_NDREP.CT_MONITOR', true);
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
  WME_Result := 'MON_5';
  RETURN;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_ndrep_setct_monitor</obj_name>
  <obj_hashval>63f862a2cf659ba15eaa4fe4d3926ab1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_ndrep_setct_monitor(act_monitor character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 02.03.2022
  perform set_config('PKG_SAL_NDREP.CT_MONITOR',aCT_MONITOR,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_ndrep_sp_gotorecord</obj_name>
  <obj_hashval>31bc9a214540cf686bd5c7ff6ea818cd</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_ndrep_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
V_REC RECORD;
AANSFARSIT numeric;
ALUNASFARSIT numeric;
BEGIN
  --Florin 02.03.2022
  INSERT INTO TMP_SAL_NDREP
  (
  codndrep, denumire, tip, modcalc, dataadaug
  )
  (
  SELECT codndrep, denumire, tip, modcalc, dataadaug
  FROM SAL_NDREP
  WHERE
     codndrep = RecId
  );
  INSERT INTO TMP_SAL_NDREP0
  (
  codndrep0, codndrep, art, marime, impozit, deduceri, tva, ziua, gest, codcont, totalcant, totalval, totalcutva, tichetmasa, coddoc, altededuceri, anstart, lunastart, alstart, alstop, art_den
  )
  (
  SELECT dr0.codndrep0, dr0.codndrep, dr0.art, dr0.marime, dr0.impozit, dr0.deduceri, dr0.tva, dr0.ziua, dr0.gest, dr0.codcont, dr0.totalcant, dr0.totalval, dr0.totalcutva, dr0.tichetmasa, dr0.coddoc, dr0.altededuceri, dr0.anstart, dr0.lunastart, dr0.alstart, dr0.alstop, obj.denumire
  FROM SAL_NDREP0 dr0
  LEFT JOIN NARTOBJ obj ON  obj.codobiect = dr0.art
  WHERE
     dr0.codndrep = RecId
  );
  INSERT INTO TMP_SAL_NDREP1
  (
  codndrep1, codndrep0, codndrep, contrib, tip_contrib
  )
  (
  SELECT drp1.codndrep1, drp1.codndrep0, drp1.codndrep, drp1.contrib, nctr.tipcontributie
  FROM SAL_NDREP1 drp1
  LEFT JOIN SAL_NCONTRIB nctr ON  nctr.codncontrib = drp1.contrib
  WHERE
    codndrep0 IN (
  SELECT tnasig.codndrep0
  FROM TMP_SAL_NDREP0 tnasig
  )
  );
  AANSFARSIT := 0;
  ALUNASFARSIT := 0;
  FOR V_REC IN
  (
  SELECT codndrep0, ANSTART, LUNASTART
  FROM TMP_SAL_NDREP0
  ORDER BY
    ANSTART * 12 + LUNASTART desc
  )
  LOOP
  IF (   AANSFARSIT &lt;&gt; 0)  AND (   ALUNASFARSIT &lt;&gt; 0)
  THEN
  UPDATE TMP_SAL_NDREP0
  SET
  ANSFARSIT = AANSFARSIT,
  LUNASFARSIT = ALUNASFARSIT
  WHERE
   codndrep0 = V_REC.codndrep0
  ;
  END IF;
  PERFORM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( V_REC.ANSTART, V_REC.LUNASTART, AANSFARSIT, ALUNASFARSIT);
  END LOOP;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_ndrep_sp_lockrecord</obj_name>
  <obj_hashval>d52a86088a126586dbacb571dfbe9786</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_ndrep_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
Tmp numeric;
BEGIN
  --Florin 02.03.2022
  SELECT codndrep
  INTO Tmp
  FROM SAL_NDREP
  WHERE
     codndrep = RecId;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_ndrep_sp_postrecords</obj_name>
  <obj_hashval>cdabf3d9cee45ef5fdba5d8b027f7f67</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_ndrep_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  aDoc varchar;
  vCod numeric;
BEGIN
  --Florin 08.12.2023 - fixat 60289
  --Florin 31.03.2021 - postLog
  --Florin 02.03.2022
  PERFORM pkg_sal_ndrep_setct_monitor('MON_5');
  SELECT tip
  INTO aDoc
  FROM TMP_SAL_NDREP;
  IF  Operation = 0
  THEN
  SELECT codndrep
  INTO RECID
  FROM TMP_SAL_NDREP;
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_NDREP.CT_MONITOR', true)))
  THEN
    PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit('SAL_NDREP', current_setting ('PKG_GLOBALS.USERNAME', true) , 'M', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
  UPDATE SAL_NDREP
  SET
  (codndrep, denumire, tip, modcalc, dataadaug) = (
  SELECT codndrep, denumire, tip, modcalc, dataadaug
  FROM TMP_SAL_NDREP
  )
  WHERE
   codndrep = RecId
  ;
  DELETE FROM SAL_NDREP1
  WHERE
   codndrep = RecId and codndrep1 NOT IN (
  SELECT codndrep1
  FROM TMP_SAL_NDREP1
  );
  DELETE FROM SAL_NDREP0
  WHERE
   codndrep = RecId and codndrep0 NOT IN (
  SELECT codndrep0
  FROM TMP_SAL_NDREP0
  );
  UPDATE SAL_NDREP0 s0
  SET
  (codndrep0, codndrep, art, marime, impozit, deduceri, tva, ziua, gest, codcont, totalcant, totalval, totalcutva, tichetmasa, coddoc, altededuceri, anstart, lunastart, alstart, alstop) = (
  SELECT codndrep0, codndrep, art, marime, impozit, deduceri, tva, ziua, gest, codcont, totalcant, totalval, totalcutva, tichetmasa, coddoc, altededuceri, anstart, lunastart, alstart, alstop
  FROM TMP_SAL_NDREP0 ts
  WHERE
     ts.codndrep0 &gt; 0 and  ts.codndrep0 = s0.codndrep0
  )
  WHERE
   s0.codndrep = RecId
  ;
  FOR v_rec IN
  (
  SELECT *
  FROM TMP_SAL_NDREP0
  WHERE
     codndrep0 &lt; 0
  )
  LOOP
  SELECT NEXTVAL('SEQ_SAL_NDREP0_CODNDREP0')
  INTO vcod;
  UPDATE TMP_SAL_NDREP1
  SET
  codndrep0 = vcod
  WHERE
   codndrep0 = v_rec.codndrep0
  ;
  INSERT INTO SAL_NDREP0
  (
  codndrep0, codndrep, art, marime, impozit, deduceri, tva, ziua, gest, codcont, totalcant, totalval, totalcutva, tichetmasa, coddoc, altededuceri, anstart, lunastart, alstart, alstop
  )
  VALUES
  (
  vcod, RecId, v_rec.art, v_rec.marime, v_rec.impozit, v_rec.deduceri, v_rec.tva, v_rec.ziua, v_rec.gest, v_rec.codcont, v_rec.totalcant, v_rec.totalval, v_rec.totalcutva, v_rec.tichetmasa, v_rec.coddoc, v_rec.altededuceri, v_rec.anstart, v_rec.lunastart, v_rec.alstart, v_rec.alstop
  );
  END LOOP;
  UPDATE SAL_NDREP1 s1
  SET
  (codndrep1, codndrep0, codndrep, contrib) = (
  SELECT codndrep1, codndrep0, codndrep, contrib
  FROM TMP_SAL_NDREP1 ts1
  WHERE
     ts1.codndrep1 &gt; 0 and  ts1.codndrep1 = s1.codndrep1
  )
  WHERE
  s1.codndrep1 IN (
  SELECT ti.codndrep1
  FROM TMP_SAL_NDREP1 ti
  WHERE
     ti.codndrep1 &gt; 0
  )
  ;
  INSERT INTO SAL_NDREP1
  (
  codndrep1, codndrep0, codndrep, contrib
  )
  SELECT NEXTVAL('SEQ_SAL_NDREP1_CODNDREP1'), t1.codndrep0, t1.codndrep, t1.contrib
  FROM TMP_SAL_NDREP1 t1
  WHERE
     t1.codndrep1 &lt; 0;
  ELSE
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_NDREP.CT_MONITOR', true)))
  THEN
    PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit('SAL_NDREP', current_setting ('PKG_GLOBALS.USERNAME', true) , 'M', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
  SELECT NEXTVAL('SEQ_SAL_NDREP_CODNDREP')
  INTO RecId;
  INSERT INTO SAL_NDREP
  (
  codndrep, denumire, tip, modcalc, dataadaug
  )
  (
  SELECT RecId, denumire, tip, modcalc, dataadaug
  FROM TMP_SAL_NDREP
  );
  FOR v_rec IN
  (
  SELECT *
  FROM TMP_SAL_NDREP0
  )
  LOOP
  SELECT NEXTVAL('SEQ_SAL_NDREP0_CODNDREP0')
  INTO vcod;
  UPDATE TMP_SAL_NDREP1
  SET
  codndrep0 = vcod
  WHERE
   codndrep0 = v_rec.codndrep0
  ;
  INSERT INTO SAL_NDREP0
  (
  codndrep0, codndrep, art, marime, impozit, deduceri, tva, ziua, gest, codcont, totalcant, totalval, totalcutva, tichetmasa, coddoc, altededuceri, anstart, lunastart, alstart, alstop
  )
  VALUES
  (
  vcod, RecId, v_rec.art, v_rec.marime, v_rec.impozit, v_rec.deduceri, v_rec.tva, v_rec.ziua, v_rec.gest, v_rec.codcont, v_rec.totalcant, v_rec.totalval, v_rec.totalcutva, v_rec.tichetmasa, v_rec.coddoc, v_rec.altededuceri, v_rec.anstart, v_rec.lunastart, v_rec.alstart, v_rec.alstop
  );
  END LOOP;
  INSERT INTO SAL_NDREP1
  (
  codndrep1, codndrep0, codndrep, contrib
  )
  SELECT NEXTVAL('SEQ_SAL_NDREP1_CODNDREP1'), codndrep0, RecId, contrib
  FROM TMP_SAL_NDREP1;
  END IF;
  call PRC_AL_REFRESH( 'SAL_NDREP0', RECID);
  PERFORM NotifyModif( Operation, RecId, 'SAL_NDREP');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_retineri_ct_monitor</obj_name>
  <obj_hashval>8b51c20425819800aa8180b9313baea0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_retineri_ct_monitor(wme_result character varying, fakeparam numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 02.03.2022
  WME_Result := current_setting('PKG_SAL_RETINERI.CT_MONITOR', true);
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
  WME_Result := 'MON_5';
  RETURN ;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_retineri_getct_monitor</obj_name>
  <obj_hashval>df850dfc2dd54f30448a3581c910e3a1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_retineri_getct_monitor(wme_result character varying, fakeparam numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 02.03.2022
  WME_Result := current_setting('PKG_SAL_RETINERI.CT_MONITOR', true);
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
  WME_Result := 'MON_5';
  RETURN ;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_retineri_sp_deleterecord</obj_name>
  <obj_hashval>21309d0f76a711f82a67f3aa21b4d16f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_retineri_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aDoc varchar;
BEGIN
  --Florin 01.04.2022 - PostLog
  --Florin 02.03.2022
  PERFORM pkg_sal_retineri_setct_monitor('MON_5');
  SELECT denumire
  INTO aDoc
  FROM TMP_SAL_RETINERI;
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_RETINERI.CT_MONITOR', true)))
  THEN
    PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit('SAL_RETINERI', current_setting ('PKG_GLOBALS.USERNAME', true) , 'S', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
  PERFORM pkg_sal_retineri_SP_LOCKRECORD( RecId);
  DELETE FROM SAL_RETINERI0
  WHERE
   CODRETINERE = RecId;
  DELETE FROM SAL_RETINERI
  WHERE
   CODRETINERE = RecId;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_retineri_sp_lockrecord</obj_name>
  <obj_hashval>e152bdaae4bc3043f5f567b7b0ef1d16</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_retineri_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
Tmp numeric;
BEGIN
  --Florin 02.03.2022
  SELECT CODRETINERE
  INTO Tmp
  FROM SAL_RETINERI
  WHERE
     CODRETINERE = RecId;
  end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_retineri_sp_postrecords</obj_name>
  <obj_hashval>1f5bc5d8e5d684f9f614227b456518c6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_retineri_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
aDoc varchar;
BEGIN
  --Florin 27.10.2022 - records return
  --Florin 01.04.2022 - PostLog
  PERFORM pkg_sal_retineri_setct_monitor('MON_5');
  SELECT denumire
  INTO aDoc
  FROM TMP_SAL_RETINERI;
  IF  Operation = 0
  THEN
  SELECT codretinere
  INTO RECID
  FROM TMP_SAL_RETINERI;
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_RETINERI.CT_MONITOR', true)))
  THEN
    PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit('SAL_RETINERI', current_setting ('PKG_GLOBALS.USERNAME', true) , 'M', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
  SELECT CODRETINERE
  INTO RecId
  FROM TMP_SAL_RETINERI;
  UPDATE SAL_RETINERI
  SET
  (codretinere, denumire, codcatret) = (
  SELECT codretinere, denumire, codcatret
  FROM TMP_SAL_RETINERI
  )
  WHERE
   CODRETINERE = RecId
  ;
  DELETE FROM SAL_RETINERI0
  WHERE
   codretinere = RECID AND codretinere0 NOT IN (
  SELECT ts0.codretinere0
  FROM TMP_SAL_RETINERI0 ts0
  );
  UPDATE SAL_RETINERI0 s0
  SET
  (codretinere0, codretinere, marime, modcalcul, caracter, cont, tert, neimpoz, nrcontr, datacontr, anstart, lunastart, alstart, alstop) = (
  SELECT codretinere0, codretinere, marime, modcalcul, caracter, cont, tert, neimpoz, nrcontr, datacontr, anstart, lunastart, alstart, alstop
  FROM TMP_SAL_RETINERI0 ts
  WHERE
     ts.codretinere0 &gt; 0 and  ts.codretinere0 = s0.codretinere0
  )
  WHERE
   s0.codretinere = RecId
  ;
  INSERT INTO SAL_RETINERI0
  (
  codretinere0, codretinere, marime, modcalcul, caracter, cont, tert, neimpoz, nrcontr, datacontr, anstart, lunastart, alstart, alstop
  )
  (
  SELECT NEXTVAL('SEQ_SAL_RETINERI0_CODRETINERE0'), RecId, marime, modcalcul, caracter, cont, tert, neimpoz, nrcontr, datacontr, anstart, lunastart, alstart, alstop
  FROM TMP_SAL_RETINERI0
  WHERE
     codretinere0 &lt; 0
  );
  ELSE
    IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_RETINERI.CT_MONITOR', true)))
    THEN
      PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit('SAL_RETINERI', current_setting ('PKG_GLOBALS.USERNAME', true) , 'A', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
    END IF;
  SELECT NEXTVAL('SEQ_SAL_RETINERI_CODRETINERE')
  INTO RecId;
  INSERT INTO SAL_RETINERI
  (
  codretinere, denumire, codcatret
  )
  (
  SELECT RecId, denumire, codcatret
  FROM TMP_SAL_RETINERI
  );
  INSERT INTO SAL_RETINERI0
  (
  codretinere0, codretinere, marime, modcalcul, caracter, cont, tert, neimpoz, nrcontr, datacontr, anstart, lunastart, alstart, alstop
  )
  (
  SELECT NEXTVAL('SEQ_SAL_RETINERI0_CODRETINERE0'), RecId, marime, modcalcul, caracter, cont, tert, neimpoz, nrcontr, datacontr, anstart, lunastart, alstart, alstop
  FROM TMP_SAL_RETINERI0
  );
  END IF;
  PERFORM NotifyModif( Operation, RecId, 'SAL_RETINERI');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_sporuri_ct_monitor</obj_name>
  <obj_hashval>5e974dfacf5a87de21af2a874e885f72</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_sporuri_ct_monitor(wme_result character varying, fakeparam numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 02.03.2022
  WME_Result := current_setting('PKG_SAL_SPORURI.CT_MONITOR', true);
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
  WME_Result := 'MON_5';
  RETURN ;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_sporuri_getct_monitor</obj_name>
  <obj_hashval>0e96d7a66ef87551d530fe607690c9a5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_sporuri_getct_monitor(wme_result character varying, fakeparam numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  WME_Result := current_setting('PKG_SAL_SPORURI.CT_MONITOR', true);
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
  WME_Result := 'MON_5';
  RETURN ;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_sporuri_sp_deleterecord</obj_name>
  <obj_hashval>40ce7a6834f830ec1052405ae308fb7c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_sporuri_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aDoc varchar;
BEGIN
  --Florin 01.04.2022 - postLog
  --Florin 02.03.2022
  PERFORM pkg_sal_sporuri_setct_monitor('MON_5');
  SELECT denumire || '(' || simbol || ')'
  INTO aDoc
  FROM TMP_SAL_SPORURI;
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_SPORURI.CT_MONITOR', true)))
  THEN
  PERFORM WINMADMIN.PKG_USERFIRME_PostLogcuCommit('SAL_SPORURI', current_setting ('PKG_GLOBALS.USERNAME', true) , 'A', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
  PERFORM pkg_sal_sporuri_SP_LOCKRECORD( RecId);
  DELETE FROM SAL_SPORURI1
  WHERE
   codspor = RecId;
  DELETE FROM SAL_SPORURI2
  WHERE
   codspor = RecId;
  DELETE FROM SAL_SPORURI0
  WHERE
   codspor = RecId;
  DELETE FROM SAL_SPORURI
  WHERE
   codspor = RecId;
 END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_sporuri_sp_gotorecord</obj_name>
  <obj_hashval>fba7ff7567bd25a0cbddcc40b8e87d23</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_sporuri_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  AANSFARSIT numeric;
  ALUNASFARSIT numeric;
BEGIN
  --Florin 02.03.2022
  INSERT INTO TMP_SAL_SPORURI1
  (
  codspor1, codspor0, codspor, LimInf, Limsup, ValSpor
  )
  (
  SELECT codspor1, codspor0, codspor, LimInf, Limsup, ValSpor
  FROM SAL_SPORURI1
  WHERE
     codspor = RecId
  );
  INSERT INTO TMP_SAL_SPORURI2
  (
  codspor2, codspor0, codspor, codsporexclus, denexcl
  )
  (
  SELECT sp2.codspor2, codspor0, sp2.codspor, sp2.codsporexclus, sp.denumire
  FROM SAL_SPORURI2 sp2
  INNER JOIN SAL_SPORURI sp ON  sp.codspor = sp2.codsporexclus
  WHERE
     sp2.codspor = RecId
  );
  INSERT INTO TMP_SAL_SPORURI0
  (
  codspor0, codspor, tip, tiptransa, tipcalcspor, zilenemo, valoare, buget, itmtip, itmspor, tarifarrefl, intrs, intrc, intrsns, intrsnc, anstart, lunastart, alstart, alstop
  )
  (
  SELECT codspor0, codspor, tip, tiptransa, tipcalcspor, zilenemo, valoare, buget, itmtip, itmspor, tarifarrefl, intrs, intrc, intrsns, intrsnc, anstart, lunastart, alstart, alstop
  FROM SAL_SPORURI0
  WHERE
     codspor = RecId
  );
  INSERT INTO TMP_SAL_SPORURI
  (
  codspor, simbol, denumire, codcatspor, salbaza, nivelsalbaza
  )
  (
  SELECT codspor, simbol, denumire, codcatspor, salbaza, nivelsalbaza
  FROM SAL_SPORURI
  WHERE
     codspor = RecId
  );
  AANSFARSIT := 0;
  ALUNASFARSIT := 0;
  FOR V_REC IN
  (
  SELECT codspor0, ANSTART, LUNASTART
  FROM TMP_SAL_SPORURI0
  ORDER BY
    ANSTART * 12 + LUNASTART desc
  )
  LOOP
  IF (   AANSFARSIT &lt;&gt; 0)  AND (   ALUNASFARSIT &lt;&gt; 0)
  THEN
  UPDATE TMP_SAL_SPORURI0
  SET
  ANSFARSIT = AANSFARSIT,
  LUNASFARSIT = ALUNASFARSIT
  WHERE
   codspor0 = V_REC.codspor0
  ;
  END IF;
  PERFORM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( V_REC.ANSTART, V_REC.LUNASTART, AANSFARSIT, ALUNASFARSIT);
  END LOOP;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_sporuri_sp_lockrecord</obj_name>
  <obj_hashval>2a8e902f7ad9b15845a8b30a30bebed3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_sporuri_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
Tmp numeric;
BEGIN
  --Florin 02.03.2022
  SELECT codspor
  INTO Tmp
  FROM SAL_SPORURI
  WHERE
     codspor = RecId;
  end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_sporuri_sp_postrecords</obj_name>
  <obj_hashval>fb31aaf12ef50fbb2e6f0a4b2a2b69a7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_sporuri_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  aDoc varchar;
  vCod numeric;
BEGIN
  --Florin 08.12.2023 - fixat 60258
  --Florin 01.04.2022 - postLog
  --Florin 23.03.2022
  --Florin 02.03.2022
  PERFORM pkg_sal_sporuri_setct_monitor('MON_5');
  SELECT denumire || '(' || simbol || ')'
  INTO aDoc
  FROM TMP_SAL_SPORURI;
  IF  Operation = 0
  THEN
  SELECT codspor
  INTO RECID
  FROM TMP_SAL_SPORURI;
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_SPORURI.CT_MONITOR', true)))
  THEN
  PERFORM WINMADMIN.PKG_USERFIRME_PostLogcuCommit( 'SAL_SPORURI', current_setting ('PKG_GLOBALS.USERNAME', true) , 'M', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
  SELECT codspor
  INTO RecId
  FROM TMP_SAL_SPORURI;
  UPDATE SAL_SPORURI
  SET
  (codspor, simbol, denumire, codcatspor, salbaza, nivelsalbaza) = (
  SELECT codspor, simbol, denumire, codcatspor, salbaza, nivelsalbaza
  FROM TMP_SAL_SPORURI
  )
  WHERE
   codspor = RecId
  ;
  DELETE FROM SAL_SPORURI1
  WHERE
   codspor = RECID AND codspor1 NOT IN (
  SELECT codspor1
  FROM TMP_SAL_SPORURI1
  );
  DELETE FROM SAL_SPORURI2
  WHERE
   codspor = RECID AND codspor2 NOT IN (
  SELECT codspor2
  FROM TMP_SAL_SPORURI2
  );
  DELETE FROM SAL_SPORURI0
  WHERE
   codspor = RECID AND codspor0 NOT IN (
  SELECT ts0.codspor0
  FROM TMP_SAL_SPORURI0 ts0
  );
  UPDATE SAL_SPORURI0 s0
  SET
  (codspor0, codspor, tip, tiptransa, tipcalcspor, zilenemo, valoare, buget, itmtip, itmspor, tarifarrefl, intrs, intrc, intrsns, intrsnc, anstart, lunastart, alstart, alstop) = (
  SELECT codspor0, codspor, tip, tiptransa, tipcalcspor, zilenemo, valoare, buget, itmtip, itmspor, tarifarrefl, intrs, intrc, intrsns, intrsnc, anstart, lunastart, alstart, alstop
  FROM TMP_SAL_SPORURI0 ts
  WHERE
     ts.codspor0 &gt; 0 and  ts.codspor0 = s0.codspor0
  )
  WHERE
   s0.codspor = RecId
  ;
  FOR v_rec IN
  (
  SELECT *
  FROM TMP_SAL_SPORURI0
  WHERE
     codspor0 &lt; 0
  )
  LOOP
  SELECT NEXTVAL('SEQ_SAL_SPORURI0_CODSPOR0')
  INTO vcod;
  UPDATE TMP_SAL_SPORURI1
  SET
  codspor0 = vcod
  WHERE
   codspor0 = v_rec.codspor0
  ;
  UPDATE TMP_SAL_SPORURI2
  SET
  codspor0 = vcod
  WHERE
   codspor0 = v_rec.codspor0
  ;
  INSERT INTO SAL_SPORURI0
  (
  codspor0, codspor, tip, tiptransa, tipcalcspor, zilenemo, valoare, buget, itmtip, itmspor, tarifarrefl, intrs, intrc, intrsns, intrsnc, anstart, lunastart, alstart, alstop
  )
  VALUES
  (
  vcod, RecId, v_rec.tip, v_rec.tiptransa, v_rec.tipcalcspor, v_rec.zilenemo, v_rec.valoare, v_rec.buget, v_rec.itmtip, v_rec.itmspor, v_rec.tarifarrefl, v_rec.intrs, v_rec.intrc, v_rec.intrsns, v_rec.intrsnc, v_rec.anstart, v_rec.lunastart, v_rec.alstart, v_rec.alstop
  );
  END LOOP;
  UPDATE SAL_SPORURI1 s1
  SET
  (codspor1, codspor0, codspor, LimInf, Limsup, ValSpor) = (
  SELECT codspor1, codspor0, codspor, LimInf, Limsup, ValSpor
  FROM TMP_SAL_SPORURI1 ts1
  WHERE
     ts1.codspor1 &gt; 0 and  ts1.codspor1 = s1.codspor1
  )
  WHERE
  s1.codspor1 IN (
  SELECT ti.codspor1
  FROM TMP_SAL_SPORURI1 ti
  WHERE
     ti.codspor1 &gt; 0
  )
  ;
  INSERT INTO SAL_SPORURI1
  (
  codspor1, codspor0, codspor, LimInf, Limsup, ValSpor
  )
  SELECT NEXTVAL('SEQ_SAL_SPORURI1_CODSPOR1'), codspor0, RECID, LimInf, Limsup, ValSpor
  FROM TMP_SAL_SPORURI1
  WHERE
     codspor1 &lt; 0;
  UPDATE SAL_SPORURI2 s2
  SET
  (codspor2, codspor0, codspor, codsporexclus) = (
  SELECT codspor2, codspor0, codspor, codsporexclus
  FROM TMP_SAL_SPORURI2 ts2
  WHERE
     ts2.codspor2 &gt; 0 and  ts2.codspor2 = s2.codspor2
  )
  WHERE
  s2.codspor2 IN (
  SELECT ti.codspor2
  FROM TMP_SAL_SPORURI2 ti
  WHERE
     ti.codspor2 &gt; 0
  )
  ;
  INSERT INTO SAL_SPORURI2
  (
  codspor2, codspor0, codspor, codsporexclus
  )
  SELECT NEXTVAL('SEQ_SAL_SPORURI2_CODSPOR2'), codspor0, RECID, codsporexclus
  FROM TMP_SAL_SPORURI2
  WHERE
     codspor2 &lt; 0;
  ELSE
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_SPORURI.CT_MONITOR', true)))
  THEN
  PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit('SAL_SPORURI', current_setting ('PKG_GLOBALS.USERNAME', true) , 'A', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
  SELECT NEXTVAL('SEQ_SAL_SPORURI_CODSPOR')
  INTO RecId;
  INSERT INTO SAL_SPORURI
  (
  codspor, simbol, denumire, codcatspor, salbaza, nivelsalbaza
  )
  (
  SELECT RecId, simbol, denumire, codcatspor, salbaza, nivelsalbaza
  FROM TMP_SAL_SPORURI
  );
  FOR v_rec IN
  (
  SELECT *
  FROM TMP_SAL_SPORURI0
  )
  LOOP
  SELECT NEXTVAL('SEQ_SAL_SPORURI0_CODSPOR0')
  INTO vcod;
  UPDATE TMP_SAL_SPORURI1
  SET
  codspor0 = vcod
  WHERE
   codspor0 = v_rec.codspor0
  ;
  UPDATE TMP_SAL_SPORURI2
  SET
  codspor0 = vcod
  WHERE
   codspor0 = v_rec.codspor0
  ;
  INSERT INTO SAL_SPORURI0
  (
  codspor0, codspor, tip, tiptransa, tipcalcspor, zilenemo, valoare, buget, itmtip, itmspor, tarifarrefl, intrs, intrc, intrsns, intrsnc, anstart, lunastart, alstart, alstop
  )
  VALUES
  (
  vcod, RecId, v_rec.tip, v_rec.tiptransa, v_rec.tipcalcspor, v_rec.zilenemo, v_rec.valoare, v_rec.buget, v_rec.itmtip, v_rec.itmspor, v_rec.tarifarrefl, v_rec.intrs, v_rec.intrc, v_rec.intrsns, v_rec.intrsnc, v_rec.anstart, v_rec.lunastart, v_rec.alstart, v_rec.alstop
  );
  END LOOP;
  INSERT INTO SAL_SPORURI1
  (
  codspor1, codspor0, codspor, LimInf, Limsup, ValSpor
  )
  SELECT NEXTVAL('SEQ_SAL_SPORURI1_CODSPOR1'), codspor0, RECID, LimInf, Limsup, ValSpor
  FROM TMP_SAL_SPORURI1
  WHERE
     codspor0 &gt; 0;
  INSERT INTO SAL_SPORURI2
  (
  codspor2, codspor0, codspor, codsporexclus
  )
  SELECT NEXTVAL('SEQ_SAL_SPORURI2_CODSPOR2'), codspor0, RECID, codsporexclus
  FROM TMP_SAL_SPORURI2
  WHERE
     codspor0 &gt; 0;
  END IF;
  PERFORM NotifyModif( Operation, RecId, 'SAL_SPORURI');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sali_sp_postrecords</obj_name>
  <obj_hashval>f6a59c5f7769779b1502d00583710ed3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sali_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  v_rec record;
BEGIN
  --Bogdan 27.06.2023 - sincronizare
  --Florin 18.05.2022
  IF  Operation = 0 THEN
    SELECT CODSALA INTO RecId FROM TMP_SALI;

    UPDATE SALI
    SET
    (CODSALA, DENUMIRE, CODPERS, NUMARMESE, CODRESTAURANT, CODCATPRET) = (SELECT CODSALA, DENUMIRE, CODPERS, NUMARMESE, CODRESTAURANT, CODCATPRET FROM TMP_SALI)
    WHERE
     CODSALA = RECID;
   DELETE FROM SALIUSERI
   WHERE
     CODSALA = RECID
     AND COD NOT IN (SELECT COD FROM TMP_SALIUSERI);

    FOR V_REC IN (SELECT * FROM TMP_SALIUSERI)
    LOOP
      IF V_REC.COD &lt; 0 THEN
        INSERT INTO SALIUSERI(COD, CODSALA, USERNAME)
        VALUES (nextval('SEQ_SALI_CODSALA'), RECID, V_REC.USERNAME);
      ELSE
        UPDATE SALIUSERI
        SET
          USERNAME = V_REC.USERNAME
        WHERE
          COD = V_REC.COD;
      END IF;
    END LOOP;

  ELSE
    SELECT NEXTVAL('SEQ_SALI_CODSALA') INTO RECID;

    INSERT INTO SALI(CODSALA, DENUMIRE, CODPERS, NUMARMESE, CODRESTAURANT, CODCATPRET)
    SELECT RECID, DENUMIRE, CODPERS, NUMARMESE, CODRESTAURANT, CODCATPRET FROM TMP_SALI;

        INSERT INTO SALIUSERI(COD, CODSALA, USERNAME)
        SELECT NEXTVAL('SEQ_SALI_CODSALA'), RECID, USERNAME FROM TMP_SALIUSERI;
  END IF;

  PERFORM NotifyModif( Operation, RecId, 'SALI');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_scadentartl_sp_deleterecord</obj_name>
  <obj_hashval>849b3b4163b9f49daeab440c43197a63</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_scadentartl_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_SCADENTARTL_SP_LOCKRECORD( RecId);
  DELETE FROM NScadTL WHERE CodScadTL = RecId;
  PERFORM NotifyModif( 2, RecId, 'NSCADTL');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_scadentartl_sp_gotorecord</obj_name>
  <obj_hashval>0f8a7a1a130457e0297f24da9ef9ef3e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_scadentartl_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_NScadTL(CodScadTL, CodBanca, NrContr, DataContr, DataExp, Moneda, Valoare, Subunitatea)
  SELECT CodScadTL, CodBanca, NrContr, DataContr, DataExp, Moneda, Valoare, Subunitatea FROM NScadTL WHERE CodScadTL = RecId;

  INSERT INTO TMP_NScadTL1(CodScadTL1, CodScadTL, DataScad, Rata, Dobanda, Total)
  SELECT CodScadTL1, CodScadTL, DataScad, Rata, Dobanda, Total FROM NScadTL1 WHERE CodScadTL = RecId;

  UPDATE TMP_NScadTL
  SET
  (TotRata, TotDobanda) = (SELECT Sum( Rata), Sum( Dobanda) FROM TMP_NScadTL1);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_scadentartl_sp_insertrecord</obj_name>
  <obj_hashval>7dcbbc2a8093ee31a46cca11ef1edafc</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_scadentartl_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_NScadTL (CodScadTL) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_scadentartl_sp_lockrecord</obj_name>
  <obj_hashval>19266f855f320df4764ae7d07c32b9c1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_scadentartl_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CodScadTL INTO Tmp FROM NScadTL WHERE CodScadTL = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_scadentartl_sp_postrecords</obj_name>
  <obj_hashval>93ca1888a71ff968fc252d96cf6273e6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_scadentartl_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  IF  Operation = 0 THEN
    SELECT CodScadTL INTO RecId FROM TMP_NScadTL;

    UPDATE NScadTL
    SET
    (CodScadTL, CodBanca, NrContr, DataContr, DataExp, Moneda, Valoare, Subunitatea)
    =
    (SELECT CodScadTL, CodBanca, NrContr, DataContr, DataExp, COALESCE( Moneda, 0), Valoare, Subunitatea FROM TMP_NScadTL)
    WHERE
     CodScadTL = RecId;

    DELETE FROM NScadTL1 WHERE CodScadTL = RecId AND  NOT CodScadTL1 IN (SELECT CodScadTL1 FROM TMP_NScadTL1);

    FOR V_REC IN (SELECT * FROM TMP_NScadTL1 WHERE CodScadTL1 &gt; 0) LOOP
      UPDATE NScadTL1
      SET
      DATASCAD = V_REC.DATASCAD,
      RATA     = V_REC.RATA,
      DOBANDA  = V_REC.DOBANDA,
      TOTAL    = V_REC.TOTAL
      WHERE
       CODSCADTL1 = V_REC.CODSCADTL1;
    END LOOP;

    INSERT INTO NScadTL1(CODSCADTL1, CODSCADTL, DATASCAD, RATA, DOBANDA, TOTAL)
    SELECT NEXTVAL('SEQ_NSCADTL1_CODSCADTL1'), RECID, DATASCAD, RATA, DOBANDA, TOTAL FROM TMP_NScadTL1 WHERE COALESCE( CodScadTL1, 0) &lt;= 0;
  ELSE
    SELECT NEXTVAL('SEQ_NSCADTL_CODSCADTL') INTO RecId;

    INSERT INTO NScadTL(CodScadTL, CodBanca, NrContr, DataContr, DataExp, Moneda, Valoare, Subunitatea, USERID, DATACREARE)
    SELECT RecId, CodBanca, NrContr, DataContr, DataExp, COALESCE( Moneda, 0), Valoare, Subunitatea, TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999'), current_timestamp
    FROM TMP_NScadTL;

    INSERT INTO NScadTL1(CodScadTL1, CodScadTL, DataScad, Rata, Dobanda, Total)
    SELECT NEXTVAL('SEQ_NSCADTL1_CODSCADTL1'), RecId, DataScad, Rata, Dobanda, Total FROM TMP_NScadTL1;
  END IF;

  PERFORM NotifyModif( Operation, RecId, 'NSCADTL');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_scenariilivr_goto_all</obj_name>
  <obj_hashval>dab52a9e990a75ee91586db608af89ee</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_scenariilivr_goto_all(g_subunit numeric, adata1 character varying, adata2 character varying, nrccli numeric, nrscen numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
Declare
  Data1 date;
  Data2 date;
BEGIN
Data1 := To_Date(aData1, 'DD.MM.YYYY');
 Data2 := To_Date(aData2, 'DD.MM.YYYY') ;

  SELECT Count(*) into NrCCli
  FROM COMANDA  C
  INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
  left join SCENARIILIVR1 S1 on S1.CODCOMANDA1 = C1.CODCOMANDA1
  where C.TipDoc = 18 and C.Operat = 1 and coalesce(C.Inchisa,0) = 0 and C1.RESTACCEPTAT &gt; 0
       and (C.DataDoc between Data1 and Data2 and S1.CodComanda1 is null)
       AND (G_SUBUNIT = 1 OR C.SUBUNITATEA = G_SUBUNIT);

  SELECT Count(*) into NrScen
  FROM SCENARIILIVR1 S1
  inner join SCENARIILIVR S on S.CodScenariu = S1.CodScenariu
  left join LANSARE0 L0 on L0.CODScenariu = S1.CODScenariu
  where S.DStart &gt;= Data1 and S.DEnd &lt;= Data2  and L0.CODScenariu is null
       AND (G_SUBUNIT = 1 OR S.SUBUNITATEA = G_SUBUNIT);
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_scenariilivr_setdocommit</obj_name>
  <obj_hashval>82938c3ad98859b71809da75095778b1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_scenariilivr_setdocommit(adocommit boolean)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SCENARIILIVR.DoCommit',aDoCommit,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_scenariilivr_sp_deleterecord</obj_name>
  <obj_hashval>f9a6df4500023ac486331b6c217f0a9b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_scenariilivr_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_SCENARIILIVR_SP_LOCKRECORD( RecId);

  UPDATE LANSARE0 SET CODSCENARIU = NULL WHERE CODSCENARIU = RECID;

  DELETE FROM NODECHIV1     WHERE CODSCENARIU = RECID;
  DELETE FROM SCENARIILIVR2 WHERE CODSCENARIU = RecId;
  DELETE FROM SCENARIILIVR1 WHERE CODSCENARIU = RecId;
  DELETE FROM SCENARIILIVR  WHERE CODSCENARIU = RecId;

  PERFORM NotifyModif( 2, RecId, 'SCENARIILIVR');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_scenariilivr_sp_gotorecord</obj_name>
  <obj_hashval>cca9fc24602dc48bb3b09b95c0b87635</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_scenariilivr_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  g_SUBUNIT    NUMERIC;
  SCENARIU     NUMERIC;
  aDStart      Date;
  aDEnd        Date;
  DataLivrS    Date := Null;
  DataLivrF    Date := Null;
  DataCmdS     Date := Null;
  DataCmdF     Date := Null;
  aTipData     NUMERIC;
  eDefinitiv   NUMERIC;
BEGIN
  --Adina 24.06.2021 - sinc.Oracle din 23.06.2021
  --Florin 18.02.2021 - fixat 43452
  INSERT INTO TMP_SCENARIILIVR(CODSCENARIU, DEN_SCENARIU, CODTRASEU, TIP, DEFINITIV, OBS, SUBUNITATEA, DStart, DEnd, TipData, Masa, Volum, AN, LUNA, USERID)
  SELECT CODSCENARIU, DEN_SCENARIU, CODTRASEU, TIP, DEFINITIV, OBS, SUBUNITATEA,  DStart, DEnd, TipData, Masa, Volum ,AN, LUNA, USERID
  FROM SCENARIILIVR WHERE CODSCENARIU = RecId;

  SELECT
        CODSCENARIU ,
        SUBUNITATEA ,
        Coalesce(Definitiv,0) ,
        DStart      ,
        DEnd        ,
        TipData
        into
        SCENARIU     ,
        g_SUBUNIT    ,
        eDefinitiv   ,
        aDStart      ,
        aDEnd        ,
        aTipData
   FROM TMP_SCENARIILIVR WHERE CODSCENARIU = RecId  ;

   if aTipData = 0 then
     DataLivrS := aDStart;
     DataLivrF := aDEnd  ;
   else
     DataCmdS  := aDStart;
     DataCmdF  := aDEnd  ;
   end if;

  INSERT INTO TMP_SCENARIILIVR1(CODSCENARIU1, CODSCENARIU, CODCOMANDA1, CANT, LANS)
  SELECT CODSCENARIU1, CODSCENARIU, CODCOMANDA1, CANT, LANS FROM SCENARIILIVR1 WHERE CODSCENARIU = RECID;

  INSERT INTO TMP_SCENARIILIVR2(CODSCENARIU2, CODSCENARIU, CODCOMANDA1, CODPROIECTNOD, DATASTART)
  SELECT CODSCENARIU2, CODSCENARIU, CODCOMANDA1, CODPROIECTNOD, DATASTART FROM SCENARIILIVR2 WHERE CODSCENARIU = RECID;

  INSERT INTO TMP_NODECHIV1(CODSCENARIU, CODCOMANDA1, CODPROIECTNOD, CODOBIECT, CANT, PARITATE, CODOBIECTORIG, NODORIGINAL, CANTECHIVALATA, DENOBIECTECHIV)
  SELECT tmp2.codscenariu, tmp2.codcomanda1, tmp2.codproiectnod, ne1.codobiect, ne1.cant, ne1.paritate, NOD.CODOBIECT, NOD.NODORIGINAL, NE1.CANT / NE1.PARITATE, OBJ.DENUMIRE
  FROM TMP_SCENARIILIVR2 TMP2
      INNER JOIN NODECHIV1  NE1 ON  NE1.CODCOMANDA1   = TMP2.CODCOMANDA1 AND  NE1.CODPROIECTNOD = TMP2.CODPROIECTNOD AND  NE1.CODSCENARIU = TMP2.CODSCENARIU
      INNER JOIN PROIECTNOD NOD ON  NOD.CODPROIECTNOD = NE1.CODPROIECTNOD
      INNER JOIN NARTOBJ    OBJ ON  NE1.CODOBIECT     = OBJ.CODOBIECT;

--  PERFORM PKG_SIMLANS_Populeaza_TMPURI( G_SUBUNIT,
--                                  To_Char(DataLivrS, 'DD,MM,YYYY'), To_Char(DataLivrF, 'DD,MM,YYYY'),
--                                  To_Char(DataCmdS , 'DD,MM,YYYY'), To_Char(DataCmdF , 'DD,MM,YYYY'),
--                                  SCENARIU);
    PERFORM pkg_scenariilivr_populeaza_tmpuri(G_SUBUNIT,
                                              To_Char(DataLivrS, 'DD,MM,YYYY'), To_Char(DataLivrF, 'DD,MM,YYYY'),
                                              To_Char(DataCmdS , 'DD,MM,YYYY'), To_Char(DataCmdF , 'DD,MM,YYYY'),
                                              SCENARIU);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_scenariilivr_sp_insertrecord</obj_name>
  <obj_hashval>adfa73ed3a009de1d597e5dab8ff9299</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_scenariilivr_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_SCENARIILIVR (CODSCENARIU) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_scenariilivr_sp_lockrecord</obj_name>
  <obj_hashval>a5a0cb65a0d31284b7249a13b5a52b35</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_scenariilivr_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CODSCENARIU INTO Tmp FROM SCENARIILIVR WHERE CODSCENARIU = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_scenariilivr_sp_postrecords</obj_name>
  <obj_hashval>ec5996673df55426bd0d8ccce7f58597</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_scenariilivr_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
BEGIN
  --Florin 14.12.2021 - fixat 52292
  --Adina 24.06.2021 - sinc.Oracle din 23.06.2021
  --Florin 22.12.2020 - fixat #41814
  --Florin 18.02.2021 - fixat 43452
  IF  Operation = 0 THEN
    SELECT CODSCENARIU INTO RecId FROM TMP_SCENARIILIVR;

    UPDATE SCENARIILIVR
    SET
    (DEN_SCENARIU, CODTRASEU, TIP, TipData, Masa, Volum, DStart, DEnd, DEFINITIV, OBS)
    =
    (SELECT DEN_SCENARIU, CODTRASEU, TIP, TipData, Masa, Volum, DStart, DEnd, DEFINITIV, OBS FROM TMP_SCENARIILIVR)
    WHERE
     CODSCENARIU = RecId;

    DELETE FROM SCENARIILIVR1 WHERE CODSCENARIU = RecId and CODSCENARIU1 NOT IN (SELECT CODSCENARIU1 FROM TMP_SCENARIILIVR1);
    DELETE FROM SCENARIILIVR2 WHERE CODSCENARIU = RecId and CODSCENARIU2 NOT IN (SELECT CODSCENARIU2 FROM TMP_SCENARIILIVR2);

    INSERT INTO SCENARIILIVR1(CODSCENARIU1, CODSCENARIU, CODCOMANDA1, CANT, LANS)
    SELECT NEXTVAL('SEQ_SCENARIILIVR1_CODSCENARIU1'), RecId, CODCOMANDA1, CANT, LANS FROM TMP_SCENARIILIVR1 WHERE CODSCENARIU1 &lt; 0;

    FOR v_rec IN (SELECT * FROM TMP_SCENARIILIVR1 WHERE COALESCE( CODSCENARIU1, -1) &gt; 0 ORDER BY CODSCENARIU1) LOOP
      UPDATE SCENARIILIVR1
      SET
      CANT        = V_REC.CANT,
      LANS        = V_REC.LANS,
      CODCOMANDA1 = V_REC.CODCOMANDA1
      WHERE
       CODSCENARIU1 = v_rec.CODSCENARIU1;
    END LOOP;

    INSERT INTO SCENARIILIVR2(CODSCENARIU2, CODSCENARIU, CODCOMANDA1, CODPROIECTNOD, DATASTART)
    SELECT NEXTVAL('SEQ_SCENARIILIVR2_CODSCENARIU2'), RecId, CODCOMANDA1, CODPROIECTNOD, DATASTART
    FROM TMP_SCENARIILIVR2 WHERE CODSCENARIU2 &lt; 0;

    FOR v_rec IN (SELECT * FROM TMP_SCENARIILIVR2 WHERE COALESCE( CODSCENARIU2, -1) &gt; 0 ORDER BY CODSCENARIU2) LOOP
      UPDATE SCENARIILIVR2
      SET
      CODPROIECTNOD = V_REC.CODPROIECTNOD,
      DATASTART     = V_REC.DATASTART
      WHERE
       CODSCENARIU2 = v_rec.CODSCENARIU2;
    END LOOP;
  ELSE      -- INSERT
    SELECT NEXTVAL('SEQ_SCENARIILIVR_CODSCENARIU') INTO RecId;

    INSERT INTO SCENARIILIVR(CODSCENARIU, DEN_SCENARIU, CODTRASEU, TIP,  TipData, Masa, Volum, DStart, DEnd, DEFINITIV, OBS, SUBUNITATEA, AN, LUNA, USERID, DATACREARE)
    SELECT RecId, DEN_SCENARIU, CODTRASEU, TIP, TipData, Masa, Volum, DStart, DEnd, DEFINITIV, OBS, SUBUNITATEA, AN, LUNA, TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999'), CURRENT_TIMESTAMP
    FROM TMP_SCENARIILIVR;

    INSERT INTO SCENARIILIVR1(CODSCENARIU1, CODSCENARIU, CODCOMANDA1, CANT, LANS)
    SELECT NEXTVAL('SEQ_SCENARIILIVR1_CODSCENARIU1'), RecId, CODCOMANDA1, CANT, LANS FROM TMP_SCENARIILIVR1;

    INSERT INTO SCENARIILIVR2(CODSCENARIU2, CODSCENARIU, CODCOMANDA1, CODPROIECTNOD, DATASTART)
    SELECT NEXTVAL('SEQ_SCENARIILIVR2_CODSCENARIU2'), RecId, CODCOMANDA1, CODPROIECTNOD, DATASTART FROM TMP_SCENARIILIVR2;
  END IF;

  DELETE FROM NODECHIV1 WHERE CODSCENARIU = RECID;
  INSERT INTO NODECHIV1(CODSCENARIU, CODCOMANDA1, CODPROIECTNOD, CODOBIECT, CANT, PARITATE, TIP)
  SELECT CODSCENARIU, CODCOMANDA1, CODPROIECTNOD, CODOBIECT, CANT, PARITATE, TIP FROM TMP_NODECHIV1;

  PERFORM NotifyModif( Operation, RecId, 'SCENARIILIVR');

  IF (current_setting('PKG_SCENARIILIVR.DoCommit', true)) THEN
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_schedule_updatejob</obj_name>
  <obj_hashval>afde84f3072443ebf9ca3b58d3b251dc</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_schedule_updatejob(operation numeric, INOUT ajobid numeric, numejob character varying, enabled boolean, ora numeric, minut numeric, repetare numeric, zilesapt text, zileluna text, datastart timestamp with time zone, dataend timestamp with time zone, sql text)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
declare
  i            numeric;
  ziInceput    numeric;
  jobclass     numeric;
  sch_minute   bool array[60];
  sch_ore      bool array[24];
  sch_zilesapt bool array[7];
  sch_zileluna bool array[32];
  sch_luni     bool array[12];
  array_zilesapt varchar array;
  array_zileluna numeric array;
begin
  select coalesce(jclid, 0) into jobclass from pgagent.pga_jobclass pj where upper(jclName) = 'WME';
  if jobclass = 0 then
    jobclass := nextval('pgagent.pga_jobclass_jclid_seq');
  end if;

  if operation = 1  then --adaugare
    ajobid := nextval('pgagent.pga_job_jobid_seq');
    insert into pgagent.pga_job (jobid, jobjclid, jobname, jobenabled, jobcreated)
    values(ajobid, jobclass, NumeJob, Enabled, current_timestamp);
  else
    update pgagent.pga_job
    set
      (jobjclid, jobname, jobenabled) = (jobclass, NumeJob, Enabled)
    where
      jobid = ajobid;
    delete from pgagent.pga_schedule where jscjobid = ajobid;
    delete from pgagent.pga_jobstep where jstjobid = ajobid;
  end if;
 -- initializare array-uri
  i := 1; while i &lt;= 60 loop  sch_minute[i]   := false; i:= i + 1; end loop;
  i := 1; while i &lt;= 24 loop  sch_ore[i]      := false; i:= i + 1; end loop;
  i := 1; while i &lt;= 7  loop  sch_zilesapt[i] := false; i:= i + 1; end loop;
  i := 1; while i &lt;= 32 loop  sch_zileluna[i] := false; i:= i + 1; end loop;
  i := 1; while i &lt;= 12 loop  sch_luni[i]     := false; i:= i + 1; end loop;


  if ora is not null then
    sch_ore[ora + 1] := true;
  end if;

  if minut is not null then
    sch_minute[minut + 1] := true;
  end if;

  select string_to_array(zilesapt, ',')  into array_zilesapt;
  select string_to_array(zileluna, ',')  into array_zileluna;



  case
    when repetare = 0 then begin --o singura data
    end;

    when repetare = 1 then begin -- pe zile

      i := 1;
      while i &lt;= array_length(sch_zileluna, 1) loop
        sch_zileluna[i] := true;
        i := i + 1;
      end loop;
      -- ??? pentru parmetrul interval repetare nu am solutie in PG ???

    end;

    when repetare = 2 then begin -- pe saptamani
      i := 1;
      while i &lt;= array_length(array_zilesapt, 1) loop
        -- MON,TUE,WED,THU,FRI,SAT,SUN
         case
           when  trim(array_zilesapt[i]) ='SUN' then sch_zilesapt[1] := true;
           when  trim(array_zilesapt[i]) ='MON' then sch_zilesapt[2] := true;
           when  trim(array_zilesapt[i]) ='TUE' then sch_zilesapt[3] := true;
           when  trim(array_zilesapt[i]) ='WED' then sch_zilesapt[4] := true;
           when  trim(array_zilesapt[i]) ='THU' then sch_zilesapt[5] := true;
           when  trim(array_zilesapt[i]) ='FRI' then sch_zilesapt[6] := true;
           when  trim(array_zilesapt[i]) ='SAT' then sch_zilesapt[7] := true;
        end case;

        i := i + 1;
      end loop;
      -- ??? pentru parmetrul interval repetare nu am solutie in PG ???

    end;

    when repetare = 3 then begin -- pe luni
      i := 1;
      while i &lt;= array_length(array_zileluna, 1) loop
        if array_zileLuna[i] between 1 and 32 then
          sch_zileluna[array_zileLuna[i]]  := true;
        end if;
        i := i + 1;
      end loop;
      -- ??? pentru parmetrul interval repetare nu am solutie in PG ???

    end;

    when repetare = 4 then begin --pe ore
      -- ??? pentru parmetrul interval repetare nu am solutie in PG ???
       i := 1;
       while i &lt;= array_length(sch_ore, 1) loop
         sch_ore[i] := true; i := i + 1;
       end loop;
    end;
  end case;




 insert into pgagent.pga_schedule (jscid, jscjobid, jscname, jscenabled, jscstart, jscend, jscminutes, jschours, jscweekdays, jscmonthdays, jscmonths)
 values (nextval('pgagent.pga_schedule_jscid_seq'), aJobID, numejob, enabled, datastart, dataend,
 sch_minute, sch_ore, sch_zilesapt, sch_zileluna, sch_luni);

  insert into pgagent.pga_jobstep(jstid, jstjobid, jstname, jstenabled, jstkind, jstcode, jstdbname, jstonerror)
  values(nextval('pgagent.pga_jobstep_jstid_seq'), aJobID, 'Pasul 1', enabled, 's', sql, 'postgres', 'f');

 --return aJobID;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_scheduler_drop_job</obj_name>
  <obj_hashval>b360786fa2b44055c07c79b76fa9a22e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_scheduler_drop_job(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 05.01.2021 - jobid -&gt; recid
    delete from pgagent.pga_schedule ps where ps.jscjobid = recid;
    delete from pgagent.pga_jobstep pjs where pjs.jstjobid = recid;
    delete from pgagent.pga_job pj      where pj.jobid = recid;

--EXCEPTION WHEN others THEN
--null;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_scheduler_purge_log</obj_name>
  <obj_hashval>771bd5ef95798d7fa94bf8cddb4adaee</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_scheduler_purge_log(jobid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  v_rec record;
begin
  for v_rec in (select jstid from pgagent.pga_jobstep pj where jstjobid = jobid)
  loop
    delete from pgagent.pga_jobsteplog pj2
    where
      pj2.jsljstid = v_rec.jstid;
  end loop;

end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_scheduler_updatejob</obj_name>
  <obj_hashval>500af68c85475fb71b103785f69163ce</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_scheduler_updatejob(operation numeric, ajobid numeric, numejob character varying, enabled boolean, ora numeric, minut numeric, repetare numeric, zilesapt text, zileluna text, datastart timestamp with time zone, dataend timestamp with time zone, sql text)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
declare
  i            numeric;
  ziInceput    numeric;
  jobclass     numeric;
  sch_minute   bool array[60];
  sch_ore      bool array[24];
  sch_zilesapt bool array[7];
  sch_zileluna bool array[32];
  sch_luni     bool array[12];
  array_zilesapt varchar array;
  array_zileluna numeric array;
begin
  select coalesce(jclid, 0) into jobclass from pgagent.pga_jobclass pj where upper(jclName) = 'WME';
  if coalesce(jobclass, 0) = 0 then
    jobclass := nextval('pgagent.pga_jobclass_jclid_seq');
    insert into pgagent.pga_jobclass(jclid, jclname)
    values(jobclass, 'WME');
  end if;

  if operation = 1  then --adaugare
    ajobid := nextval('pgagent.pga_job_jobid_seq');
    insert into pgagent.pga_job (jobid, jobjclid, jobname, jobenabled, jobcreated)
    values(ajobid, jobclass, NumeJob, Enabled, current_timestamp);
  else
    update pgagent.pga_job
    set
      (jobjclid, jobname, jobenabled) = (jobclass, NumeJob, Enabled)
    where
      jobid = ajobid;
    delete from pgagent.pga_schedule where jscjobid = ajobid;
    delete from pgagent.pga_jobstep where jstjobid = ajobid;
  end if;
 -- initializare array-uri
  i := 1; while i &lt;= 60 loop  sch_minute[i]   := false; i:= i + 1; end loop;
  i := 1; while i &lt;= 24 loop  sch_ore[i]      := false; i:= i + 1; end loop;
  i := 1; while i &lt;= 7  loop  sch_zilesapt[i] := false; i:= i + 1; end loop;
  i := 1; while i &lt;= 32 loop  sch_zileluna[i] := false; i:= i + 1; end loop;
  i := 1; while i &lt;= 12 loop  sch_luni[i]     := false; i:= i + 1; end loop;


  if ora is not null then
    sch_ore[ora + 1] := true;
  end if;

  if minut is not null then
    sch_minute[minut + 1] := true;
  end if;

  select string_to_array(zilesapt, ',')  into array_zilesapt;
  select string_to_array(zileluna, ',')  into array_zileluna;



  case
    when repetare = 0 then begin --o singura data
    end;

    when repetare = 1 then begin -- pe zile

      i := 1;
      while i &lt;= array_length(sch_zileluna, 1) loop
        sch_zileluna[i] := true;
        i := i + 1;
      end loop;
      -- ??? pentru parmetrul interval repetare nu am solutie in PG ???

    end;

    when repetare = 2 then begin -- pe saptamani
      i := 1;
      while i &lt;= array_length(array_zilesapt, 1) loop
        -- MON,TUE,WED,THU,FRI,SAT,SUN
         case
           when  trim(array_zilesapt[i]) ='SUN' then sch_zilesapt[1] := true;
           when  trim(array_zilesapt[i]) ='MON' then sch_zilesapt[2] := true;
           when  trim(array_zilesapt[i]) ='TUE' then sch_zilesapt[3] := true;
           when  trim(array_zilesapt[i]) ='WED' then sch_zilesapt[4] := true;
           when  trim(array_zilesapt[i]) ='THU' then sch_zilesapt[5] := true;
           when  trim(array_zilesapt[i]) ='FRI' then sch_zilesapt[6] := true;
           when  trim(array_zilesapt[i]) ='SAT' then sch_zilesapt[7] := true;
        end case;

        i := i + 1;
      end loop;
      -- ??? pentru parmetrul interval repetare nu am solutie in PG ???

    end;

    when repetare = 3 then begin -- pe luni
      i := 1;
      while i &lt;= array_length(array_zileluna, 1) loop
        if array_zileLuna[i] between 1 and 32 then
          sch_zileluna[array_zileLuna[i]]  := true;
        end if;
        i := i + 1;
      end loop;
      -- ??? pentru parmetrul interval repetare nu am solutie in PG ???

    end;

    when repetare = 4 then begin --pe ore
      -- ??? pentru parmetrul interval repetare nu am solutie in PG ???
       i := 1;
       while i &lt;= array_length(sch_ore, 1) loop
         sch_ore[i] := true; i := i + 1;
       end loop;
    end;
  end case;




 insert into pgagent.pga_schedule (jscid, jscjobid, jscname, jscenabled, jscstart, jscend, jscminutes, jschours, jscweekdays, jscmonthdays, jscmonths)
 values (nextval('pgagent.pga_schedule_jscid_seq'), aJobID, numejob, enabled, datastart, dataend,
 sch_minute, sch_ore, sch_zilesapt, sch_zileluna, sch_luni);

  insert into pgagent.pga_jobstep(jstid, jstjobid, jstname, jstenabled, jstkind, jstcode, jstdbname, jstonerror)
  values(nextval('pgagent.pga_jobstep_jstid_seq'), aJobID, 'Pasul 1', enabled, 's', sql, 'postgres', 'f');

 return aJobID;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_articolpromotional</obj_name>
  <obj_hashval>a28395d2ed110446f4cb734244cf4b49</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_articolpromotional(INOUT wme_result numeric, INOUT acodobiect numeric, INOUT aprocdisc numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  PROMO numeric := 0;
begin
  aPROCDISC := 0;
  BEGIN
    SELECT PROMOTIE, DISCPROMO INTO PROMO, aPROCDISC FROM NARTOBJ WHERE CODOBIECT = aCODOBIECT;
  EXCEPTION WHEN OTHERS THEN
    BEGIN
      PROMO     := 0;
      aPROCDISC := 0;
    END;
  END;

  WME_Result :=  PROMO;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_articolpromotionalretail</obj_name>
  <obj_hashval>374b2edbc84914618575d00e69ef8b55</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_articolpromotionalretail(INOUT wme_result numeric, INOUT acodobiect numeric, INOUT acodpostretail numeric, INOUT aprocdisc numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  PROMO numeric := 0;
begin
  aPROCDISC := 0;

  BEGIN
    SELECT PROMOTIE, COALESCE( RP.DISCPROMO, O.DISCPROMO) AS DISCPROMO
    INTO PROMO, aPROCDISC
    FROM NARTOBJ O LEFT JOIN DISCPROMORETAIL RP ON  RP.CODOBIECT = O.CODOBIECT AND  RP.CODPOSTRETAIL = aCODPOSTRETAIL
    WHERE O.CODOBIECT = aCODOBIECT;
  EXCEPTION WHEN OTHERS THEN
    BEGIN
      PROMO     := 0;
      aPROCDISC := 0;
    END;
  END;

  WME_Result :=  PROMO;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_check_table_for_obiect</obj_name>
  <obj_hashval>aed7bd94744faec44033105c52f33b99</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_check_table_for_obiect(INOUT wme_result numeric, INOUT atablename character varying, INOUT acodobiect numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
declare
  NR numeric := 0;
begin
  execute 'SELECT COUNT(*) FROM ' || aTABLENAME || ' WHERE CODOBIECT = ' || to_char( aCODOBIECT, '9999999999999') into NR;

  WME_Result := NR;
  return;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_clasa_obiect_valid_pe_locatie</obj_name>
  <obj_hashval>147bafea122a96e56a2afe66b7d2d71a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_clasa_obiect_valid_pe_locatie(INOUT wme_result numeric, INOUT acodlocatie numeric, INOUT acodclasa numeric, INOUT acodobiect numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCODTIPSEDIU numeric;
  aICLASA      numeric;
  RES          numeric;
begin
  --Bogdan 03.03.2023
  BEGIN
    SELECT COALESCE( CODTIPSEDIU, 0) into strict aCODTIPSEDIU FROM NAGENDA WHERE CODAGENDA = aCODLOCATIE;
  EXCEPTION WHEN OTHERS THEN
    aCODTIPSEDIU := 0;
  END;

  IF  aCODTIPSEDIU = 0 THEN
    WME_Result :=  1;
    RETURN;
  END IF;

  BEGIN
    SELECT COALESCE( ICLASA, 1) into strict aICLASA FROM NTIPSEDII WHERE CODTIPSEDIU = aCODTIPSEDIU;
  EXCEPTION WHEN OTHERS THEN
    aICLASA := 1;
  END;

  IF  aICLASA = 1 THEN
    WME_Result :=  1;
    RETURN;
  END IF;

  SELECT COUNT( *)
  into RES
  FROM NTIPSEDII1
  WHERE CODTIPSEDIU = aCODTIPSEDIU and ( (COALESCE( CODCLASEA, 0) &lt;&gt; 0 AND  CODCLASEA = aCODCLASA) OR (COALESCE( CODOBIECT, 0) &lt;&gt; 0 AND CODOBIECT = aCODOBIECT) ) ;

  IF  RES &gt; 0 THEN
    WME_Result :=  1;
    RETURN;
  ELSE
    WME_Result :=  0;
    RETURN;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_cod_intr_exclus</obj_name>
  <obj_hashval>d2ebf85e3fd42c08699761dfb34f695d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_cod_intr_exclus(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SELECTARTICOLE.COD_INTR_EXCLUS', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_cod_obiect_analizat</obj_name>
  <obj_hashval>724c75624e3b1fea434a1242b272d2f0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_cod_obiect_analizat(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SELECTARTICOLE.COD_OBIECT_ANALIZAT')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_cod_transf_exclus</obj_name>
  <obj_hashval>bc454d56b41f08eac4dd4c05657aa281</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_cod_transf_exclus(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER(current_setting('PKG_SELECTARTICOLE.COD_TRANSF_EXCLUS', true),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_codarticol</obj_name>
  <obj_hashval>bf92c32e9f143a84eb2ad30db4648eb4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_codarticol(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SELECTARTICOLE.CODARTICOL')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_codclasa</obj_name>
  <obj_hashval>aa3f571b1b0b04da043e432159c863c6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_codclasa(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SELECTARTICOLE.CODCLASA', True)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_conditieclasa</obj_name>
  <obj_hashval>db52e1e2e5417d1e8f654a02028bf10f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_conditieclasa(INOUT wme_result numeric, INOUT oclasa numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  Clasa numeric;
BEGIN
  --Florin 13.04.2023 - fixat 57948
  Clasa := Coalesce(current_setting('PKG_SELECTARTICOLE.CODCLASA',true)::numeric, 0);
  IF  Clasa = 0 THEN
    WME_Result :=  1;
    RETURN;
  ELSE
    BEGIN
      WME_Result :=  (SELECT PKG_GLOBALS_IS_SUBCLAS_OF.WME_RESULT FROM PKG_GLOBALS_IS_SUBCLAS_OF(NULL, OCLASA, Clasa));
      RETURN;
    END;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_conditiereturnabil</obj_name>
  <obj_hashval>1eb22793eed585f651548b1cdedd1fc3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_conditiereturnabil(INOUT wme_result numeric, INOUT areturnabil numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
--IF  TO_NUMBER((current_setting('PKG_SELECTARTICOLE.RETURNABIL')),'999999999999999999') = 0
--THEN
WME_Result :=  1;
--RETURN;
--ELSE
--WME_Result :=  COALESCE( aReturnabil, 0);
RETURN;
--END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_excludstocdinintrarea</obj_name>
  <obj_hashval>27d9a01e3260086fb80b9869ff553e75</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_excludstocdinintrarea(INOUT wme_result numeric, INOUT acodintr numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  IF  TO_NUMBER((current_setting('PKG_SELECTARTICOLE.COD_INTR_EXCLUS',true)),'999999999999999999') = 0 THEN
    WME_Result :=  0;
    RETURN;
  ELSE
    IF  ACODINTR = TO_NUMBER((current_setting('PKG_SELECTARTICOLE.COD_INTR_EXCLUS',true)),'999999999999999999') THEN
      WME_Result :=  1;
      RETURN;
    ELSE
      WME_Result :=  0;
      RETURN;
    END IF;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_excludstocdintransf1</obj_name>
  <obj_hashval>b9a2fdbc7dd383b4a96f05e55c6c46b8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_excludstocdintransf1(INOUT wme_result numeric, INOUT acodtransf1 numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  ACODTRANSF numeric := 0;
begin
  BEGIN
    SELECT CODTRANSF INTO ACODTRANSF FROM TRANSF1 WHERE CODTRANSF1 = ACODTRANSF1;
  EXCEPTION WHEN OTHERS THEN
    ACODTRANSF := 0;
  END;

  WME_Result :=  (SELECT WME_RESULT FROM PKG_SELECTARTICOLE_EXCLUDSTOCDINTRANSFERUL(NULL, ACODTRANSF));
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_excludstocdintransferul</obj_name>
  <obj_hashval>7c9700f367cac00da8bf403affdd2a2e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_excludstocdintransferul(INOUT wme_result numeric, INOUT acodtransf numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  IF  TO_NUMBER((current_setting('PKG_SELECTARTICOLE.COD_TRANSF_EXCLUS')),'999999999999999999') = 0 THEN
    WME_Result :=  0;
    RETURN;
  ELSE
    IF  ACODTRANSF = TO_NUMBER((current_setting('PKG_SELECTARTICOLE.COD_TRANSF_EXCLUS')),'999999999999999999') THEN
      WME_Result :=  1;
      RETURN;
    ELSE
      WME_Result :=  0;
      RETURN;
    END IF;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_get_grupa_obiect_echivalat</obj_name>
  <obj_hashval>2ed9e184fc18ba7c396d302ec00656a7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_get_grupa_obiect_echivalat(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
WME_Result :=  COALESCE( case when current_setting('PKG_SELECTARTICOLE.GRUPA_OBIECT_ECHIVALAT',true) = '' then null else current_setting('PKG_SELECTARTICOLE.GRUPA_OBIECT_ECHIVALAT',true)::numeric end, 0);
RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_get_info_obiect_luna</obj_name>
  <obj_hashval>2bf3074aeacb03878cde76ca1310eb7c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_get_info_obiect_luna(INOUT wme_result refcursor, INOUT acodobiect numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMPCURSOR REFCURSOR;
BEGIN
  --Florin 21.10.2022 - sinc. Oracle
  --Adina 18.02.2021 - sinc.cu modif. Oracle din 17.02.2021
  --PERFORM PKG_STOC_GENERARE_FACTURI_MAKE_CONFIG_LUNA();
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT COALESCE( A.TIPARTICOL, '0') AS TIPARTICOL,
           NTVA.PROCENT,
           NUM1.CODUM1 AS UMSEC,
           NUM1.DEN_UM1,
           NTVA.CODTVA,
           CASE WHEN COALESCE(OI.CONTIMPLICIT    ,0) = 0 THEN AI.CONTIMPLICIT     ELSE COALESCE(OI.CONTIMPLICIT    ,0) END CONTIMPLICIT,
           CASE WHEN COALESCE(OI.GESTIMPLICITA   ,0) = 0 THEN AI.GESTIMPLICITA    ELSE COALESCE(OI.GESTIMPLICITA   ,0) END GESTIMPLICITA,
           CASE WHEN COALESCE(OI.LOCATIEIMPLICITA,0) = 0 THEN AI.LOCATIEIMPLICITA ELSE COALESCE(OI.LOCATIEIMPLICITA,0) END LOCATIEIMPLICITA,
           O.DENUMIRE,
           A.ARETG,
           A.TIPSERIE,
           A.CONTSERVICIU,
           O.CodObiect,
           O.UMAMBALARE,
           UMA.DEN_UM1 AS DEN_UMAMB,
           UMA.PARITATE AS PARITATEAMB,
           O.PROMOTIE,
           O.ROTUNJIRE,
           A.UM
    FROM NARTOBJ O
      LEFT JOIN NARTOBJIMP    OI   ON OI.CODOBIECT    = O.CODOBIECT AND OI.CODSUBUNIT = (SELECT WME_RESULT FROM PKG_GLOBALS_GETSUBUNITATE_DOC(NULL,NULL))
      LEFT JOIN NUM1          UMA  ON  O.UMAMBALARE   = UMA.CODUM1,
      NART A
      LEFT JOIN NARTIMPLICITE AI   ON  AI.CODARTICOL  = A.CODARTICOL AND  AI.CODSUBUNIT = (SELECT WME_RESULT FROM PKG_GLOBALS_GETSUBUNITATE_DOC(NULL,NULL))
      LEFT JOIN TMP_NART_LUNA NAL  ON  NAL.CODARTICOL = A.CODARTICOL
      LEFT JOIN TMP_NTVA_LUNA NTVA ON  NTVA.CODTVA    = NAL.CODTVA
      LEFT JOIN NUM1               ON  NUM1.CODUM     = A.UM AND  NUM1.SECUNDARA = 0
    WHERE
       O.CODOBIECT = aCODOBIECT AND  A.CODARTICOL = O.CODARTICOL;
  EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR SELECT -1;
  END;

  WME_Result :=  TMPCURSOR;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_get_just_denobiect</obj_name>
  <obj_hashval>e5c9925532ff670918f2cbd3750b9814</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_get_just_denobiect(INOUT wme_result character varying, INOUT obiect numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  ACOD numeric;
  DEN  varchar := '';
  LUNG numeric := 0;
begin
  BEGIN
    SELECT O.DENUMIRE, LENGTH( A.DEN_ARTICOL)
    INTO DEN, LUNG
    FROM NARTOBJ O, NART A
    WHERE O.CODOBIECT = OBIECT AND  O.CODARTICOL = A.CODARTICOL;
  EXCEPTION WHEN OTHERS THEN
    WME_Result :=  NULL;
    RETURN;
  END;

  WME_Result :=  TRIM(SUBSTR( DEN, (LUNG + 1)::integer, LENGTH( DEN)::integer));
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_get_obiect_echivalat</obj_name>
  <obj_hashval>49763b69d83240cb4367634158b95479</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_get_obiect_echivalat(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
WME_Result :=  current_setting('PKG_SELECTARTICOLE.OBIECT_ECHIVALAT', true)::numeric;
RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_get_obiect_taxe_facturare</obj_name>
  <obj_hashval>ce023641f5c166832b396fab978bfc94</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_get_obiect_taxe_facturare(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
WME_Result :=  current_setting('PKG_SELECTARTICOLE.OBIECT_TAXE_FACTURARE', true)::numeric;
RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_get_paritate_obiect_echivalat</obj_name>
  <obj_hashval>69d2c31652d93b3367992434fc264dac</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_get_paritate_obiect_echivalat(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  IF  Coalesce( TO_NUMBER((current_setting('PKG_SELECTARTICOLE.PARITATE_OBIECT_ECHIVALAT')),'99999999999.9999999'), 0) = 0 THEN
  perform set_config('PKG_SELECTARTICOLE.PARITATE_OBIECT_ECHIVALAT',to_char(1,'99999999999.9999999'),false);
  END IF;

  WME_Result :=  TO_NUMBER((current_setting('PKG_SELECTARTICOLE.PARITATE_OBIECT_ECHIVALAT')),'99999999999.9999999');
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_get_record_nart</obj_name>
  <obj_hashval>be781a09f3bc52949ba84d1607dca5ce</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_get_record_nart(INOUT wme_result refcursor, INOUT acodart numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMPCURSOR REFCURSOR;
BEGIN
  --Florin 12.09.2022 - sinc. Oracle
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT A.CODARTICOL, DEN_ARTICOL, TIPARTICOL, CLASA, UM, UM1, UM2, TIPSERIE, AI.CONTIMPLICIT, AI.GESTIMPLICITA, AI.LOCATIEIMPLICITA, CERTIFICAT, ARETG,
    EVOLUTIEPRET, CONTSERVICIU, INCREMENTSERIE, A.RELATIEUM1, A.RELATIEUM2, A.D1, A.D2, A.D3, A.CODCENTRU, CLA.DEN_CLASEA, A.ParitateD1, A.ParitateD2, A.ParitateD3,
    A.CODMASCA, A.RiscFiscal
    FROM NART A
        LEFT JOIN NCLASEA       CLA ON  CLA.CODCLASEA = A.CLASA
        LEFT JOIN NARTIMPLICITE AI  ON  AI.CODARTICOL = A.CODARTICOL AND  AI.CODSUBUNIT = (SELECT WME_RESULT FROM PKG_GLOBALS_GETSUBUNITATE_DOC(NULL,NULL))
    WHERE A.CODARTICOL = ACODART;
  EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR SELECT -1;
  END;

  WME_Result :=  TMPCURSOR;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_get_record_nart1</obj_name>
  <obj_hashval>d3959d540b5360cbef1dfeca46176c85</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_get_record_nart1(INOUT wme_result refcursor, INOUT acodart numeric, INOUT aan numeric, INOUT aluna numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMPCURSOR REFCURSOR;
  AL       numeric := aAn*12+aLuna;
begin
  --Laura 28.01.2022 - sinc. Oracle (28.12.2021)
  --Laura 25.01.2022 - sinc. Oracle (27.12.2021)
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT *
    FROM NART1 A1
    WHERE  A1.CODARTICOL = ACODART AND AL BETWEEN A1.ALStart AND A1.ALStop;
  EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR SELECT -1;
  END;

  WME_Result :=  TMPCURSOR;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_get_record_nartobj</obj_name>
  <obj_hashval>180ebb9c17d171d0faa43d361652781a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_get_record_nartobj(INOUT wme_result refcursor, INOUT acodobiect numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMPCURSOR REFCURSOR;
BEGIN
  --Florin 12.09.2022 - sinc. Oracle
  --Laura 25.01.2022 - sinc. Oracle (27.12.2021)
  --Adina 18.02.2021 - sinc.cu modif. Oracle din 17.02.2021
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT O.*,
           A.UM,
           A.TIPARTICOL,
           A.ARETG,
           A.RELATIEUM1,
           A.RELATIEUM2,
           A.TIPSERIE,
           A.UM1,
           A.UM2,
           AI.CODIMPLICIT,
           AI.CODARTICOL,
           AI.CODSUBUNIT,
           CASE WHEN COALESCE(OI.CONTIMPLICIT ,0) = 0 THEN AI.CONTIMPLICIT  ELSE COALESCE(OI.CONTIMPLICIT ,0) END CONTIMPLICIT,
           CASE WHEN COALESCE(OI.GESTIMPLICITA,0) = 0 THEN AI.GESTIMPLICITA ELSE COALESCE(OI.GESTIMPLICITA,0) END GESTIMPLICITA,
           AI.NEVANDABIL,
           CASE WHEN COALESCE(OI.LOCATIEIMPLICITA,0) = 0 THEN AI.LOCATIEIMPLICITA ELSE COALESCE(OI.LOCATIEIMPLICITA,0) END LOCATIEIMPLICITA,
           O1.TIPPRETMAX,
           O1.PRETMAXIMAL,
           O1.PRETREFERINTA.
           NPRT.DEN_PART AS PRODUCATOR,
           NCLS.DEN_CLASEA AS ClasaArticol,
           O.Masa,
           U.Den_UM DUM
    FROM NARTOBJ O
        LEFT JOIN NART             A  ON  A.CODARTICOL  = O.CODARTICOL
        LEFT JOIN NARTIMPLICITE    AI ON  AI.CODARTICOL = A.CODARTICOL AND  AI.CODSUBUNIT = (SELECT WME_RESULT FROM PKG_GLOBALS_GETSUBUNITATE_DOC(NULL,NULL))
        LEFT JOIN NARTOBJIMP      OI ON  OI.CODOBIECT  = O.CODOBIECT  AND  OI.CODSUBUNIT = (SELECT WME_RESULT FROM PKG_GLOBALS_GETSUBUNITATE_DOC(NULL,NULL))
        LEFT JOIN NARTOBJ1         O1 ON  O1.CODOBIECT  = O.CODOBIECT  AND  getAnLunaLucru() BETWEEN O1.ALStart AND O1.ALStop
        LEFT JOIN NPART NPRT          ON O.CODPRODUCATOR = NPRT.CODPART
        LEFT JOIN NCLASEA NCLS        ON NCLS.Codclasea = A.CLASA
        LEFT JOIN NUM U               ON U.CodUM = A.UM
    WHERE
       O.CODOBIECT = ACODOBIECT;
  EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR SELECT -1;
  END;

  WME_Result :=  TMPCURSOR;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_get_record_nartobj1</obj_name>
  <obj_hashval>0569206f0944ba58c2856d42dd7d41c8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_get_record_nartobj1(INOUT wme_result refcursor, INOUT acodobiect numeric, INOUT aan numeric, INOUT aluna numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMPCURSOR REFCURSOR;
  AL       numeric := aAn*12+aLuna;
begin
  --Laura 28.01.2022 - sinc. Oracle (28.12.2021)
  --Laura 25.01.2022 - sinc. Oracle (27.12.2021)
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT *
    FROM NARTOBJ1 O1
    WHERE  O1.CODOBIECT = ACODOBIECT AND AL BETWEEN O1.ALStart AND O1.ALStop;
  EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR SELECT -1;
  END;

  WME_Result :=  TMPCURSOR;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getartofobject</obj_name>
  <obj_hashval>1897df852a880d5d8727e87347acc246</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getartofobject(INOUT wme_result numeric, INOUT codobj numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
declare
  ART numeric;
begin
  ART := 0;

  begin
    SELECT CODARTICOL INTO ART FROM NARTOBJ WHERE CODOBIECT = CODOBJ;
  exception
    when others then ART := 0;
  end;

  WME_Result := ART;
  return;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getclasacurenta</obj_name>
  <obj_hashval>2782787cdae5260d69acbe244fa8c719</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getclasacurenta(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  WME_Result :=  TO_NUMBER((current_setting('PKG_SELECTARTICOLE.CODCLASA', True)),'999999999999999999');
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getclasaofart</obj_name>
  <obj_hashval>b048f1faa1f16d940e2548e844014975</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getclasaofart(INOUT wme_result numeric, INOUT codart numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  OCLASA numeric;
BEGIN
  --Florin 29.09.2022 - fixat 55673
  OCLASA := 0;
  BEGIN
    SELECT CLASA INTO OCLASA FROM NART WHERE CODARTICOL = CODART;
  EXCEPTION WHEN OTHERS THEN
    OCLASA := 0;
  END;
  WME_Result :=  OCLASA;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getcod_intr_exclus</obj_name>
  <obj_hashval>1e052caebec22555b30049c003620e11</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getcod_intr_exclus(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SELECTARTICOLE.COD_INTR_EXCLUS', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getcod_transf_exclus</obj_name>
  <obj_hashval>1a9b8b14682c3fb41bf854ee744eea29</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getcod_transf_exclus(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SELECTARTICOLE.COD_TRANSF_EXCLUS')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getcodartcurent</obj_name>
  <obj_hashval>690f21cc91c4c2ddb53f0976538c4410</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getcodartcurent(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  WME_Result :=  TO_NUMBER((current_setting('PKG_SELECTARTICOLE.CODARTICOL')),'999999999999999999');
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getcodarticol</obj_name>
  <obj_hashval>cedc11c3655e71ef0dca22f7e990bf5c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getcodarticol(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SELECTARTICOLE.CODARTICOL')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getcodclasa</obj_name>
  <obj_hashval>d49913d79aead9e65197b052f7c7501d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getcodclasa(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SELECTARTICOLE.CODCLASA')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getcodintrexclus</obj_name>
  <obj_hashval>7498b927395bd198b044ab10e8424ecb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getcodintrexclus(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
WME_Result :=  TO_NUMBER((current_setting('PKG_SELECTARTICOLE.COD_INTR_EXCLUS', true)),'999999999999999999');
RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getcodtransfexclus</obj_name>
  <obj_hashval>66b7908b5b9652674804e6d3dc377de5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getcodtransfexclus(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SELECTARTICOLE.COD_TRANSF_EXCLUS', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getden_art_obj</obj_name>
  <obj_hashval>a19b15dbfc64e440d20e550959a68067</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getden_art_obj(INOUT wme_result character varying, INOUT denart character varying, INOUT obiect numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  DEN   varchar := '';
begin
  DEN := DENART;

  FOR V_REC IN (SELECT T.VALOARE AS VALOARE FROM NATROBJ O, NATRIB1 T WHERE O.CODOBIECT = OBIECT AND  O.CODVALATR = T.CODVALATR) LOOP
    DEN := DEN || ' ' || V_REC.VALOARE;
  END LOOP;

  WME_Result :=  DEN;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getdengest</obj_name>
  <obj_hashval>2c8e9aee1cddf53ca4e5054deb580aff</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getdengest(INOUT wme_result character varying, INOUT gest numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  DEN varchar := '';
begin
  BEGIN
    SELECT COALESCE( DEN_GEST, '') INTO DEN FROM NGEST WHERE CODGEST = GEST;
  EXCEPTION WHEN OTHERS THEN
    DEN := '';
  END;

  WME_Result :=  DEN;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getdenioart</obj_name>
  <obj_hashval>6f6c71a4185625c3f2bca694d189366b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getdenioart(INOUT wme_result character varying, INOUT ioart numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  DEN varchar := '';
begin
  BEGIN
    SELECT COALESCE( DEN_IOART, '') INTO DEN FROM IOART WHERE CODIOART = IOART;
  EXCEPTION WHEN OTHERS THEN
    DEN := '';
  END;

  WME_Result :=  DEN;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getdenobiect</obj_name>
  <obj_hashval>fcc620ac65ad5e454117f1ddb99adae8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getdenobiect(INOUT wme_result character varying, INOUT obiect numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  DEN   varchar := '';
  NR    numeric := 0;
  I     numeric := 0;
begin
  SELECT COUNT( *) INTO NR FROM NATROBJ WHERE CODOBIECT = OBIECT;

  IF  NR = 0 THEN
    WME_Result :=  '... FARA ATRIBUTE ...';
    RETURN;
  ELSE
    FOR V_REC IN (SELECT T.VALOARE AS VALOARE FROM NATROBJ O, NATRIB1 T WHERE O.CODOBIECT = OBIECT AND  O.CODVALATR = T.CODVALATR) LOOP
      IF  I = 0 THEN
        DEN := V_REC.VALOARE;
      ELSE
        DEN := DEN || ' ' || V_REC.VALOARE;
      END IF;

      I := I + 1;
    END LOOP;

    WME_Result :=  DEN;
    RETURN;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getdenobiectext</obj_name>
  <obj_hashval>fbd89e424d00d15f44a8e82ee4c6a05a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getdenobiectext(INOUT wme_result character varying, INOUT obiect numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  ACOD numeric;
  DEN  varchar := '';
BEGIN
  --Florin 06.04.2021 - fixat 46855
  IF (obiect &lt;&gt;0) THEN
    BEGIN
      SELECT O.CODOBIECT, coalesce(A.DEN_ARTICOL,'') || ' ' || coalesce(STRING_AGG( B.VALOARE,','),'')
      INTO ACOD, DEN
      FROM NARTOBJ O
        LEFT JOIN NART    A ON  A.CODARTICOL = O.CODARTICOL
        LEFT JOIN NATROBJ T ON  T.CODOBIECT  = O.CODOBIECT
        LEFT JOIN NATRIB1 B ON  T.CODVALATR  = B.CODVALATR
      WHERE O.CODOBIECT = OBIECT
      GROUP BY O.CODOBIECT, A.DEN_ARTICOL;
    EXCEPTION WHEN OTHERS THEN
      WME_Result :=  '';
      RETURN;
    END;

    WME_Result :=  DEN;
  ELSE
    WME_Result :=  '';
  END IF;

  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getgrupa_obiect_echivalat</obj_name>
  <obj_hashval>728ae9e2c9e08fbb5444e7764e620a45</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getgrupa_obiect_echivalat(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SELECTARTICOLE.GRUPA_OBIECT_ECHIVALAT')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getgrupaobiect</obj_name>
  <obj_hashval>1730f0a7dfa73c25c088eb22374aebb1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getgrupaobiect(INOUT wme_result character varying, INOUT acodobiect numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aGRUPA varchar := '';
begin
  BEGIN
    SELECT GRUPA INTO aGRUPA FROM TMP_NARTOBJ_LUNA WHERE CODOBIECT = aCODOBIECT;
  EXCEPTION WHEN OTHERS THEN
    aGRUPA := '';
  END;

  WME_Result :=  aGRUPA;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getinfostoc</obj_name>
  <obj_hashval>6d9450facaca4fdcb20a093ccc45522b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getinfostoc(INOUT wme_result refcursor, INOUT acodobiect numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMPCURSOR REFCURSOR;
begin
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT G.DEN_GEST, IO.DEN_IOART, NUM.DEN_UM, SUM( NS.REST) AS STOC
    FROM NIRSTOC NS
        LEFT JOIN TMP_IOART_LUNA IOA ON  IOA.CODIOART = NS.CODIOART,
        NIR N, NGEST G, IOART IO, NARTOBJ O, NART A, NUM
    WHERE  NS.CODOBIECT = ACODOBIECT
      AND  N.CODNIR = NS.CODNIR
      AND  NS.REST &lt;&gt; 0
      AND  G.CODGEST = N.GEST
      AND  NS.CODIOART = IO.CODIOART
      AND  IOA.MG &lt;&gt; 5
      AND  O.CODOBIECT  = ACODOBIECT
      AND  A.CODARTICOL = O.CODARTICOL
      AND  A.UM = NUM.CODUM
    GROUP BY G.DEN_GEST, IO.DEN_IOART, NUM.DEN_UM;
  EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR  SELECT NULL, NULL, 0, NULL;
  END;

  WME_Result :=  TMPCURSOR;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getobiect_echivalat</obj_name>
  <obj_hashval>88a118138db33938d53f8651b2c87592</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getobiect_echivalat(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SELECTARTICOLE.OBIECT_ECHIVALAT')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getobiect_taxe_facturare</obj_name>
  <obj_hashval>484fe596a2a74c9e985add23ebdc2602</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getobiect_taxe_facturare(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SELECTARTICOLE.OBIECT_TAXE_FACTURARE')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getobiectanalizat</obj_name>
  <obj_hashval>ca38e80285838e41227d88b7fea989c2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getobiectanalizat(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
WME_Result :=  TO_NUMBER((current_setting('PKG_SELECTARTICOLE.COD_OBIECT_ANALIZAT')),'999999999999999999');
RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getobiectimplicit</obj_name>
  <obj_hashval>1aceee8d5301da63190061efbe3dbdfb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getobiectimplicit(INOUT wme_result numeric, INOUT artcod numeric, INOUT umambalare numeric, INOUT zileplata numeric, INOUT tippretmax numeric, INOUT pretmaximal numeric, INOUT procadaos numeric, INOUT codextern character varying, INOUT codintern character varying, INOUT blocat numeric, INOUT rotunjire numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  COD numeric := -1;
  aUMAMBALARE numeric := 0;
begin
  --Laura 25.01.2022 - sinc. Oracle (27.12.2021)
  FOR V_REC IN
  (
    SELECT O.CODOBIECT, O.PROCADAOSNIR, O.UMAMBALARE, O.TERMENPLATA, O.CODEXTERN, O.CODINTERN, O.BLOCAT, O.ROTVALUTA, O1.TIPPRETMAX, O1.PRETMAXIMAL
      FROM NARTOBJ O LEFT JOIN NARTOBJ1 O1 ON O1.CODOBIECT = O.CODOBIECT AND getAnLunaLucru() BETWEEN O1.ALStart AND O1.ALStop
      WHERE O.CODARTICOL = ARTCOD
  )
  LOOP
    UMAMBALARE  := V_REC.UMAMBALARE;
    ZILEPLATA   := V_REC.TERMENPLATA;
    TIPPRETMAX  := V_REC.TIPPRETMAX;
    PRETMAXIMAL := V_REC.PRETMAXIMAL;
    PROCADAOS   := V_REC.PROCADAOSNIR;
    CODEXTERN   := V_REC.CODEXTERN;
    CODINTERN   := V_REC.CODINTERN;
    BLOCAT      := V_REC.BLOCAT;
    ROTUNJIRE   := V_REC.ROTVALUTA;

    WME_Result  :=  V_REC.CODOBIECT;
    RETURN;
  END LOOP;

  UMAMBALARE := aUMAMBALARE;
  WME_Result :=  COD;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getparitate_obiect_echivalat</obj_name>
  <obj_hashval>c3e1ab5e93a5b6e5a668958ab580e5f6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getparitate_obiect_echivalat(INOUT wme_result double precision, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SELECTARTICOLE.PARITATE_OBIECT_ECHIVALAT')),'99999999999.9999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 1;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getparitatestocmoment</obj_name>
  <obj_hashval>1a07c36d4c9ad7995715f2639532a6c1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getparitatestocmoment(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
WME_Result :=  TO_NUMBER((current_setting('PKG_SELECTARTICOLE.PARITATESTOCMOMENT')),'99999999999.9999999');
RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getprocenttva</obj_name>
  <obj_hashval>4a34b0e106d88ce4c9407a63ffbbc3d4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getprocenttva(INOUT wme_result numeric, INOUT codart numeric, INOUT an numeric, INOUT luna numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
BEGIN
  WME_Result :=  fnc_getprocenttvaart(codart, an, luna);
  RETURN;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getproctvalunalucru</obj_name>
  <obj_hashval>7f0cb8249dd4da620014fc5c58b8c368</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getproctvalunalucru(INOUT wme_result numeric, INOUT codart numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 29.06.2022 - fnc_getprocenttvaart
  WME_Result :=  fnc_getprocenttvaart(CODART, TO_NUMBER((current_setting('PKG_GLOBALS.ANLUCRU')),'999999999999999999'), TO_NUMBER((current_setting('PKG_GLOBALS.LUNALUCRU')),'999999999999999999'));
RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getrecordioart</obj_name>
  <obj_hashval>b7448ca5b79f61f909ec0abd9203f873</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getrecordioart(INOUT wme_result refcursor, INOUT ioartcod numeric, INOUT an numeric, INOUT luna numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMPCURSOR REFCURSOR;
  AL       numeric := An*Luna;
begin
  --Laura 25.01.2022 - sinc. Oracle (27.12.2021)
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT I1.*, IO.CODVANZARE
    FROM IOART1 I1 LEFT JOIN IOART IO ON  IO.CODIOART = I1.CODIOART
    WHERE I1.CODIOART = IOARTCOD AND AL BETWEEN I1.ALStart AND I1.ALStop;
  EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR SELECT -1;
  END;

  WME_Result :=  TMPCURSOR;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getrecordtva</obj_name>
  <obj_hashval>40e23b914761f8509568d06117cf5b30</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getrecordtva(INOUT wme_result refcursor, INOUT codart numeric, INOUT an numeric, INOUT luna numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  CTVA      numeric := -1;
  TMPCURSOR REFCURSOR;
  AL       numeric := An*Luna;
begin
  --Laura 28.01.2022 - sinc. Oracle (28.12.2021)
  --Laura 25.01.2022 - sinc. Oracle (27.12.2021)
  BEGIN
    SELECT COALESCE( CODTVA, 0)
    INTO CTVA
    FROM NART1 N1
    WHERE N1.CODARTICOL = CODART AND AL BETWEEN N1.ALStart AND N1.ALStop;
  EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR SELECT -1;
  END;

  BEGIN
    IF  CTVA &gt; 0 THEN
      OPEN TMPCURSOR FOR
      SELECT *
      FROM NTVA1 T1
      WHERE T1.CODTVA = CTVA AND AL BETWEEN T1.ALStart AND T1.ALStop;
    ELSE
      OPEN TMPCURSOR FOR SELECT -1;
    END IF;
  EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR SELECT -1;
  END;

  WME_Result :=  TMPCURSOR;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getreturnabil</obj_name>
  <obj_hashval>81dd8c8ff75339d40c62309b907f629e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getreturnabil(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SELECTARTICOLE.RETURNABIL')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getumprincipala</obj_name>
  <obj_hashval>3540102c31023f16fcde4bdc332ba1c5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getumprincipala(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := current_setting('PKG_SELECTARTICOLE.UMPRINCIPALA',TRUE)::NUMERIC;
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_grupa_obiect_echivalat</obj_name>
  <obj_hashval>d1a48619cc0438aa97b6d73f0da884c1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_grupa_obiect_echivalat(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SELECTARTICOLE.GRUPA_OBIECT_ECHIVALAT')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_make_den_obiecte_cu_atribute</obj_name>
  <obj_hashval>d88159ef84893310f0b0e8218bd8c6b9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_make_den_obiecte_cu_atribute()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  VREC_ATR RECORD;
  DEN varchar;
begin
  --Bogdan 07.10.2020
  --Bogdan 04.01.2021
  FOR V_REC IN (SELECT * FROM NARTOBJ O WHERE (SELECT COUNT(*) FROM NATROBJ AO WHERE AO.CODOBIECT = O.CODOBIECT) &gt; 0)  LOOP
     SELECT na.DEN_ARTICOL INTO DEN FROM NART na WHERE na.CODARTICOL = V_REC.CODARTICOL;

    FOR VREC_ATR IN (SELECT A1.VALOARE FROM NATROBJ AO, NARTATR  AA, NATRIB1  A1
                     WHERE AO.CODOBIECT = V_REC.CODOBIECT AND AA.CODARTATR = AO.CODARTATR AND A1.CODVALATR = AO.CODVALATR
                     ORDER BY AA.INDEXLOCAL
                    )
    LOOP
      DEN := coalesce (DEN,'') || ' ' || coalesce (VREC_ATR.VALOARE,'');
    END LOOP;

    UPDATE NARTOBJ SET DENUMIRE = DEN WHERE CODOBIECT = V_REC.CODOBIECT;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_obiect_echivalat</obj_name>
  <obj_hashval>9bc9da729acfa3ea36d7f6d3b202295f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_obiect_echivalat(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SELECTARTICOLE.OBIECT_ECHIVALAT')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_obiect_implicat_in_tranzactii</obj_name>
  <obj_hashval>e25e8f737a68d1c99b3634257de7d82d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_obiect_implicat_in_tranzactii(INOUT wme_result numeric, INOUT acodobiect numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
declare
  NR numeric := 0;
BEGIN
  --Florin 21.10.2022 - sinc. Oracle
  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'NIRSTOC', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'CERTIF', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'CMDPRODMAT', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'CMDPRODREZ', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'COMANDA1', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'CONTRACT1', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'DISCART', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'DVI1', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'EMULARE1', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'IESIRI1', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'INTRARI1', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'INVENTAR1', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'LIVRVAL', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'NECHIV', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'NODECHIV', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'NSERII', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'OFERTA1', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'PLUCASE', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'PMPLUNA', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'PMP_ALL_LUNA', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'PRODCOMP', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'PRODMAT', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'PRODREZ', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'STOCLOCKEMUL', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'STOCPOSURI', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  NR := (SELECT PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT.WME_RESULT FROM PKG_SELECTARTICOLE_CHECK_TABLE_FOR_OBIECT(null, 'TRANSF1', aCODOBIECT));
  if NR &gt; 0 then WME_Result := 1; return; end if;

  WME_Result := 0;
  return;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_obiect_taxe_facturare</obj_name>
  <obj_hashval>546f3fb1c19d80b690de74529fea0408</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_obiect_taxe_facturare(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SELECTARTICOLE.OBIECT_TAXE_FACTURARE')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_paritate_obiect_echivalat</obj_name>
  <obj_hashval>d1f7af0674d1c4b7818005f4a1affe77</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_paritate_obiect_echivalat(INOUT wme_result double precision, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SELECTARTICOLE.PARITATE_OBIECT_ECHIVALAT')),'99999999999.9999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 1;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_paritatestocmoment</obj_name>
  <obj_hashval>f51a48b09b8c83b7960a1b4c5a316c3a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_paritatestocmoment(INOUT wme_result double precision, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SELECTARTICOLE.PARITATESTOCMOMENT')),'99999999999.9999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 1;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_returnabil</obj_name>
  <obj_hashval>217571340fb73d19a47e406ea3f6bbe2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_returnabil(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SELECTARTICOLE.RETURNABIL')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_set_obiect_echivalat</obj_name>
  <obj_hashval>64d24f0a3f332dc92b84bfc282a3e06f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_set_obiect_echivalat(aobiect numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  glb_GRUPA_OBIECT_ECHIVALAT    numeric;
  glb_PARITATE_OBIECT_ECHIVALAT double precision;
begin
  perform set_config('PKG_SELECTARTICOLE.OBIECT_ECHIVALAT',to_char(aObiect,'999999999999999999'),false);

  BEGIN
    SELECT coalesce(CodGrupa, 0), coalesce(Paritate,1)
    INTO glb_GRUPA_OBIECT_ECHIVALAT, glb_PARITATE_OBIECT_ECHIVALAT
    FROM NEchiv WHERE CODOBIECT = aObiect;
  EXCEPTION WHEN OTHERS then
    glb_GRUPA_OBIECT_ECHIVALAT := -1;
    glb_PARITATE_OBIECT_ECHIVALAT := 1;
  END;

  perform PKG_SELECTARTICOLE_SetGRUPA_OBIECT_ECHIVALAT(glb_GRUPA_OBIECT_ECHIVALAT);
  perform PKG_SELECTARTICOLE_SetPARITATE_OBIECT_ECHIVALAT(glb_PARITATE_OBIECT_ECHIVALAT);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_set_obiect_taxe_facturare</obj_name>
  <obj_hashval>101867bba5c2c7ea06ab331fb6ba01bd</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_set_obiect_taxe_facturare(aobiect numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SELECTARTICOLE.OBIECT_TAXE_FACTURARE',to_char(aObiect,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_setclasa</obj_name>
  <obj_hashval>3ee7cff37087a7eeff61eeb04d4470c8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_setclasa(clasa numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SELECTARTICOLE.CODCLASA',to_char(CLASA,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_setcod_intr_exclus</obj_name>
  <obj_hashval>e8df0daf5cad4d9336661689617d6c60</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_setcod_intr_exclus(acod_intr_exclus numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SELECTARTICOLE.COD_INTR_EXCLUS',to_char(aCOD_INTR_EXCLUS,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_setcod_obiect_analizat</obj_name>
  <obj_hashval>aa1c6a07ecb516aded52f362b806b39a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_setcod_obiect_analizat(acod_obiect_analizat numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SELECTARTICOLE.COD_OBIECT_ANALIZAT',to_char(aCOD_OBIECT_ANALIZAT,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_setcod_transf_exclus</obj_name>
  <obj_hashval>8997e5c91abbc1a354ecea0adc47c614</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_setcod_transf_exclus(acod_transf_exclus numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SELECTARTICOLE.COD_TRANSF_EXCLUS',to_char(aCOD_TRANSF_EXCLUS,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_setcodart</obj_name>
  <obj_hashval>ecb78ea6a86601924c3cc8ccaf49dda6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_setcodart(art numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SELECTARTICOLE.CODARTICOL',to_char(ART,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_setcodarticol</obj_name>
  <obj_hashval>3db1203c899f545f7ac5b14cb85b789b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_setcodarticol(acodarticol numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SELECTARTICOLE.CODARTICOL',to_char(aCODARTICOL,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_setcodintrexclus</obj_name>
  <obj_hashval>ddce940ba877f8d877c40adc550c200b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_setcodintrexclus(cod numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SELECTARTICOLE.COD_INTR_EXCLUS',to_char(COD,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_setcodtransfexclus</obj_name>
  <obj_hashval>a321855d19e215d890fa94c082547d5b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_setcodtransfexclus(cod numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SELECTARTICOLE.COD_TRANSF_EXCLUS',to_char(COD,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_setgrupa_obiect_echivalat</obj_name>
  <obj_hashval>8254c92dc7ffb4894c98ba16e50e6927</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_setgrupa_obiect_echivalat(agrupa_obiect_echivalat numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SELECTARTICOLE.GRUPA_OBIECT_ECHIVALAT',to_char(aGRUPA_OBIECT_ECHIVALAT,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_setobiect_echivalat</obj_name>
  <obj_hashval>4d4c1a9d7cbbec02c6538c0c62860377</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_setobiect_echivalat(aobiect_echivalat numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SELECTARTICOLE.OBIECT_ECHIVALAT',to_char(aOBIECT_ECHIVALAT,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_setobiect_taxe_facturare</obj_name>
  <obj_hashval>6c1f4d38ff7267d0aa2ae363204e77ec</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_setobiect_taxe_facturare(aobiect_taxe_facturare numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SELECTARTICOLE.OBIECT_TAXE_FACTURARE',to_char(aOBIECT_TAXE_FACTURARE,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_setobiectanalizat</obj_name>
  <obj_hashval>bcb44654191c108848cb0bd8312e13e8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_setobiectanalizat(acodobiect numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SELECTARTICOLE.COD_OBIECT_ANALIZAT',to_char(aCODOBIECT,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_setparitate_obiect_echivalat</obj_name>
  <obj_hashval>8382f0d52ac32a13d35336eb4402c0ab</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_setparitate_obiect_echivalat(aparitate_obiect_echivalat double precision)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SELECTARTICOLE.PARITATE_OBIECT_ECHIVALAT',to_char(aPARITATE_OBIECT_ECHIVALAT,'99999999999.9999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_setparitatestocmoment</obj_name>
  <obj_hashval>4f50164be2e0c8eb8e8a74cd4bb405a8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_setparitatestocmoment(paritate numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SELECTARTICOLE.PARITATESTOCMOMENT',to_char(PARITATE,'99999999999.9999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_umprincipala</obj_name>
  <obj_hashval>319c63740f79d0887f887c4af9783b51</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_umprincipala(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := current_setting('PKG_SELECTARTICOLE.UMPRINCIPALA',TRUE)::NUMERIC;
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_serii_getmascalastserie</obj_name>
  <obj_hashval>e7f6391885dbf40334a979961b204cfa</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_serii_getmascalastserie(INOUT wme_result character varying, INOUT amasca character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  sSerie varchar := '';
begin
  BEGIN
    WITH
    Ser AS (SELECT * FROM nserii WHERE aMasca = '%' or SERIE LIKE aMasca)
    SELECT Serie
    INTO sSerie
    FROM NSERII
    WHERE CodSerie = (SELECT NS.CodSerie FROM NIRSER NS WHERE NS.CodNIRSer = (SELECT Max( NS.CodNirSer) FROM NirSer NS INNER JOIN Ser ON  NS.CodSerie = Ser.CodSerie));
  EXCEPTION WHEN OTHERS THEN
    sSerie := '';
  END;

  WME_Result :=  sSerie;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_serii_getobiectcurent</obj_name>
  <obj_hashval>5ef62b8d83b1f68353a89807644ea965</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_serii_getobiectcurent(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
WME_Result :=  TO_NUMBER(current_setting('PKG_SERII.OBIECTCURENT', true),'999999999999999999');
RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_serii_obiectcurent</obj_name>
  <obj_hashval>2479545ea80e87def5354b71d44816d4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_serii_obiectcurent(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER(current_setting('PKG_SERII.OBIECTCURENT', true),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_serii_set_seq_serie_unica</obj_name>
  <obj_hashval>0a13224a5fcf7ecafa714030ad45c4f6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_serii_set_seq_serie_unica(nr numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  sInsert varchar;
  X       numeric;
begin
  SELECT NEXTVAL('SEQ_SERIE_UNICA') INTO X;

  IF  X &lt; NR THEN
    sInsert := 'ALTER SEQUENCE SEQ_SERIE_UNICA INCREMENT BY ' || to_char( NR - X,'999999999999999999');
    EXECUTE sInsert;
    SELECT NEXTVAL('SEQ_SERIE_UNICA') INTO X;
    sInsert := 'ALTER SEQUENCE SEQ_SERIE_UNICA INCREMENT BY 1';
    EXECUTE sInsert;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_serii_setobiectcurent</obj_name>
  <obj_hashval>fcc0095392111b052c4e3d63f0699587</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_serii_setobiectcurent(acodobiect numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SERII.OBIECTCURENT',to_char(ACODOBIECT,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_serii_sp_lockrecord</obj_name>
  <obj_hashval>cdc15ae5c5dd02b0fb1a5ef4d7f6954e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_serii_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMP numeric;
begin
  SELECT SERIE INTO TMP FROM NSERII WHERE CODSERIE = RECID FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_serii_sp_postrecords</obj_name>
  <obj_hashval>cb44e178c9e1ce3940e3a2173528e65e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_serii_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  IF  OPERATION = 0 THEN
    SELECT CODSERIE INTO RECID FROM TMP_NSERII;

    UPDATE NSERII
    SET
    (CODSERIE, SERIE, CODOBIECT, OBS) = (SELECT CODSERIE, SERIE, CODOBIECT, OBS FROM TMP_NSERII)
    WHERE CODSERIE = RECID;
  ELSE
    SELECT NEXTVAL('SEQ_NSERII_CODSERIE') INTO RECID;

    INSERT INTO NSERII(CODSERIE, SERIE, CODOBIECT, OBS)
    (SELECT RECID, SERIE, CODOBIECT, OBS FROM TMP_NSERII);
  END IF;

  PERFORM NotifyModif( Operation, RecId, 'NSERII');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sertar_ct_monitor</obj_name>
  <obj_hashval>842811272805ad51b690f88b4c6b09c8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sertar_ct_monitor(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_SERTAR.CT_MONITOR'));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 'MON_68';
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sertar_getct_monitor</obj_name>
  <obj_hashval>73fcfff5432706d296b709e6c2c69817</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sertar_getct_monitor(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_SERTAR.CT_MONITOR'));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 'MON_68';
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sertar_setct_monitor</obj_name>
  <obj_hashval>e4214cc0ab23620397e75d1fb7d9d331</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sertar_setct_monitor(act_monitor character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SERTAR.CT_MONITOR',aCT_MONITOR,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sertar_sp_deleterecord</obj_name>
  <obj_hashval>2bb2acf6229160a31f91fe99fe8fce98</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sertar_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCODSUBUNIT numeric := 0;
  aDATADOC    date    := NULL;
  aDOC        varchar := NULL;
  CT_MONITOR  varchar(10) := 'MON_68';
BEGIN
  --Florin 01.06.2023 - monitor
  --Florin 12.04.2023 - sinc. Oracle (11.04.2023)
  --Florin 09.02.2022 - fixat 52995
  --Bogdan 24.09.2020
  --Florin 30.12.2020 - date varchar
  perform pkg_sertar_setct_monitor('MON_68');
  PERFORM PKG_SERTAR_SP_LOCKRECORD (RecId);

  BEGIN
    SELECT SUBUNITATE, DATADOC, 'SER' INTO aCodSubunit, aDataDoc, aDoc FROM NSERTAR WHERE CODSERTAR = RECID;
  EXCEPTION
  WHEN OTHERS THEN
    NULL;
  END;

  PERFORM PKG_CFGTABLES_EXT_DELETERECORD (recId, 69);
  IF (select wme_result
        from WINMADMIN.PKG_USERFIRME_ValidPostLog (null,current_setting ('PKG_GLOBALS.USERID')::numeric , CT_MONITOR))
  THEN
    PERFORM WINMADMIN.pkg_userfirme_postlogcucommit ('NSERTAR',
                              (current_setting ('PKG_GLOBALS.USERNAME')) , 'S', RECID,
                              (current_setting ('PKG_GLOBALS.FIRMANAME')) ,
                              aCodSubunit, aDataDoc, aDoc, null,
                              (SELECT WME_RESULT FROM PKG_GLOBALS_GET_EXE_VERSION (NULL,NULL)));
  END IF;

  DELETE FROM NSERTAR1 WHERE CodSertar = RecId;
  DELETE FROM NSERTAR  WHERE CodSertar = RecId;

  PERFORM NotifyModif (2, RecId, 'NSERTAR');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sertar_sp_gotorecord</obj_name>
  <obj_hashval>26219e9ca8892936e6e8680b34b89587</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sertar_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 12.04.2023 - sinc. Oracle (11.042023)
  --Florin 29.10.2020 adaugat NRI
  --Florin 16.11.2021 - fixat 52001
  perform pkg_sertar_setct_monitor('MON_68');
  DELETE FROM TMP_NSERTAR;
  INSERT INTO TMP_NSERTAR(CodSertar, CodEmitent, CodPartener, Subunitate, Tip, Decont, Doc, NrDoc, DataDoc, Valoare, DataDecont, Depus, DataCreare, UserID, Obs,
                          DataOblig, Banca, Moneda, Emitent, Partener, NRI)
  (
  SELECT NS.CodSertar, NS.CodEmitent, NS.CodPartener, NS.Subunitate, NS.Tip, NS.Decont, NS.Doc, NS.NrDoc, NS.DataDoc, NS.Valoare, NS.DataDecont, NS.Depus, NS.DataCreare,
         NS.UserID, NS.Obs, NS.DataOblig, NS.Banca, NS.Moneda, NPE.Den_Part, NPP.Den_Part, NS.NRI
  FROM NSERTAR NS
      LEFT JOIN NPART NPE ON  NPE.CodPart = NS.CodEmitent
      LEFT JOIN NPART NPP ON  NPP.CodPart = NS.CodPartener
  WHERE NS.CodSertar = RecId
  );

  DELETE FROM TMP_NSERTAR1;
  INSERT INTO TMP_NSERTAR1(CodSertar1, CodSertar, CodObligPIF, Valoare, DenDocLegatura, CodGeneral)
  (
  SELECT NS1.CodSertar1, NS1.CodSertar, NS1.CodObligPIF, NS1.Valoare, DenDocLegatura, O.CodGeneral
  FROM NSERTAR1 NS1 INNER JOIN OBLIGPIF O ON  O.CodObligPIF = NS1.CodObligPIF
  WHERE CodSertar = RecId
  );

  DELETE FROM TMP_NSERTAR1_INITIAL;
  INSERT INTO TMP_NSERTAR1_INITIAL (SELECT * FROM TMP_NSERTAR1);
  PERFORM PKG_CFGTABLES_EXT_GOTORECORD(69);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sertar_sp_postrecords</obj_name>
  <obj_hashval>cfc59826ee8aaac42b765263f7c6af25</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sertar_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCODSUBUNIT numeric := 0;
  aDATADOC    date    := NULL;
  aDOC        varchar := NULL;
  CT_MONITOR  varchar(10) := 'MON_68';
BEGIN
  --Florin 01.06.2023 - monitor
  --Florin 12.04.2023 - sinc. Oracle (11.04.2023)
  --Florin 09.02.2022 - fixat 52992
  --Bogdan 24.09.2020
  --Florin 29.10.2020 adaugat NRI
  --Florin 30.12.2020 - date varchar
  perform pkg_sertar_setct_monitor('MON_68');
  PERFORM PKG_CFGTABLES_EXT_POSTRECORDS_INIT (69);
  BEGIN
    SELECT SUBUNITATE, DATADOC, 'SER' INTO aCodSubunit, aDataDoc, aDoc FROM TMP_NSERTAR;
  EXCEPTION
  WHEN OTHERS THEN
    NULL;
  END;

  IF Operation = 0 THEN
    SELECT CodSertar INTO RecId FROM TMP_NSERTAR;

    IF (select wme_result from WINMADMIN.PKG_USERFIRME_ValidPostLog (null,current_setting ('PKG_GLOBALS.USERID')::numeric , CT_MONITOR)) then
      PERFORM WINMADMIN.pkg_userfirme_postlogcucommit ('NSERTAR',
                            (current_setting ('PKG_GLOBALS.USERNAME')) ,
                            'M',
                            RECID,
                            (current_setting ('PKG_GLOBALS.FIRMANAME')) ,
                            aCodSubunit, aDataDoc, aDoc, null,
                            (SELECT WME_RESULT FROM PKG_GLOBALS_GET_EXE_VERSION (NULL,NULL)));
    END IF;

    UPDATE NSERTAR
    SET
      (
        CodSertar,
        CodEmitent,
        CodPartener,
        Subunitate,
        Tip,
        Decont,
        Doc,
        NrDoc,
        DataDoc,
        Valoare,
        DataDecont,
        Depus,
        DataCreare,
        UserID,
        Obs,
        DataOblig,
        Banca,
        Moneda,
        NrI
      )
      = (SELECT CodSertar,
          CodEmitent,
          CodPartener,
          Subunitate,
          Tip,
          Decont,
          Doc,
          NrDoc,
          DataDoc,
          Valoare,
          DataDecont,
          Depus,
          DataCreare,
          UserID,
          Obs,
          DataOblig,
          Banca,
          Moneda,
          NrI
        FROM TMP_NSERTAR)
    WHERE
      CodSertar = RecId;

    DELETE FROM NSERTAR1 WHERE CodSertar = RecId;

    INSERT INTO NSERTAR1 (CodSertar1, CodSertar, CodObligPIF, Valoare, DenDocLegatura, CodGeneral)
    (SELECT NEXTVAL ('SEQ_NSERTAR1_CODSERTAR1') , RecId, TNS1.CodObligPIF, COALESCE (TNS1.Valoare, 0) , TNS1.DenDocLegatura, O.CodGeneral
     FROM TMP_NSERTAR1 TNS1 INNER JOIN OBLIGPIF O ON O.CodObligPIF = TNS1.CodObligPIF
    );
  ELSE
    SELECT NEXTVAL ('SEQ_NSERTAR_CODSERTAR') INTO RecId;
    PERFORM PKG_CFGTABLES_EXT_UPDATE_COD_CORESP('NSERTAR', RecId);

    IF (select wme_result from WINMADMIN.PKG_USERFIRME_ValidPostLog (null,current_setting ('PKG_GLOBALS.USERID')::numeric , CT_MONITOR)) THEN
      PERFORM WINMADMIN.pkg_userfirme_postlogcucommit ('NSERTAR',
                            (current_setting ('PKG_GLOBALS.USERNAME')) ,
                            'A',
                            RECID,
                            (current_setting ('PKG_GLOBALS.FIRMANAME')) ,
                            aCodSubunit, aDataDoc, aDoc, null,
                            (SELECT WME_RESULT FROM PKG_GLOBALS_GET_EXE_VERSION (NULL,NULL)));
    END IF;

    INSERT INTO NSERTAR (
        CodSertar,
        CodEmitent,
        CodPartener,
        Subunitate,
        Tip,
        Decont,
        Doc,
        NrDoc,
        DataDoc,
        Valoare,
        DataDecont,
        Depus,
        DataCreare,
        UserID,
        Obs,
        DataOblig,
        Banca,
        Moneda,
        NrI)
    (SELECT RecId,
          CodEmitent,
          CodPartener,
          current_setting ('PKG_GLOBALS.Subunitate')::numeric ,
          Tip,
          Decont,
          Doc,
          NrDoc,
          DataDoc,
          Valoare,
          DataDecont,
          0,
          CURRENT_TIMESTAMP,
          current_setting ('PKG_GLOBALS.UserID')::numeric ,
          Obs,
          DataOblig,
          Banca,
          Moneda,
          NRI
     FROM TMP_NSERTAR);

    INSERT INTO NSERTAR1 (CodSertar1, CodSertar, CodObligPIF, Valoare, DenDocLegatura, CodGeneral)
    (SELECT NEXTVAL ('SEQ_NSERTAR1_CODSERTAR1') , RecId, TNS1.CodObligPIF, COALESCE (TNS1.Valoare, 0) , DenDocLegatura, O.CodGeneral
     FROM TMP_NSERTAR1 TNS1 INNER JOIN OBLIGPIF O ON O.CodObligPIF = TNS1.CodObligPIF
    );
  END IF;

  PERFORM PKG_CFGTABLES_EXT_POSTRECORDS(69);
  PERFORM NotifyModif (Operation, RecId, 'NSERTAR');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_servfact_sp_insertrecord</obj_name>
  <obj_hashval>909c7cc8b4b90997f29ab183ded58792</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_servfact_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_SERVFACT(CODSERVFACT) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_servfact_sp_postrecords</obj_name>
  <obj_hashval>68de3a7366a3e198aa838aed4e43dbb1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_servfact_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC      RECORD;
  vModcalcul numeric;
BEGIN
  --Adina 24.05.2021 - sinc.Oracle din 22.05.2021 - doar martor la zi
  BEGIN
    SELECT MODCALCUL INTO vModcalcul FROM TMP_SERVFACT;
    IF vModcalcul = 5 THEN --VOUCHER..nu are detalii
      DELETE FROM TMP_SERVFACT1;
    END IF;

    IF  OPERATION = 0 THEN
      SELECT CODSERVFACT INTO RECID FROM TMP_SERVFACT;

      UPDATE SERVFACT
      SET
      (DENUMIRE, CODOBIECT, SUMAPORNIREKM, SUMAPORNIRECANT, PROCPORNIREKM, PROCPORNIRECANT, MODCALCUL, COD)
      =
      (SELECT DENUMIRE, CODOBIECT, SUMAPORNIREKM, SUMAPORNIRECANT, PROCPORNIREKM, PROCPORNIRECANT, MODCALCUL, COD FROM TMP_SERVFACT)
      WHERE
       CODSERVFACT = RECID;

      DELETE FROM SERVFACT1 S1 WHERE CODSERVFACT = RECID AND  NOT  EXISTS (SELECT CODSERVFACT1 FROM TMP_SERVFACT1 WHERE CODSERVFACT1 = S1.CODSERVFACT1);

      FOR V_REC IN (SELECT * FROM TMP_SERVFACT1) LOOP
        IF  V_REC.CODSERVFACT1 &lt; 0 THEN
          INSERT INTO SERVFACT1(CODSERVFACT1, CODSERVFACT, PANALA, VALOARE)
          VALUES(NEXTVAL('SEQ_SERVFACT1_CODSERVFACT1'), RECID, V_REC.PANALA, V_REC.VALOARE);
        ELSE
          UPDATE SERVFACT1
          SET
          PANALA  = V_REC.PANALA,
          VALOARE = V_REC.VALOARE
          WHERE
           CODSERVFACT1 = V_REC.CODSERVFACT1;
        END IF;
      END LOOP;
    ELSE
      SELECT NEXTVAL('SEQ_SERVFACT_CODSERVFACT') INTO RECID;

      INSERT INTO SERVFACT(CODSERVFACT, DENUMIRE, CODOBIECT, SUMAPORNIREKM, SUMAPORNIRECANT, PROCPORNIREKM, PROCPORNIRECANT, MODCALCUL, COD)
      SELECT RECID, DENUMIRE, CODOBIECT, SUMAPORNIREKM, SUMAPORNIRECANT, PROCPORNIREKM, PROCPORNIRECANT, MODCALCUL, COD
      FROM TMP_SERVFACT;

      INSERT INTO SERVFACT1(CODSERVFACT1, CODSERVFACT, PANALA, VALOARE)
      SELECT NEXTVAL('SEQ_SERVFACT1_CODSERVFACT1'), RECID, PANALA, VALOARE FROM TMP_SERVFACT1;
    END IF;

    PERFORM NotifyModif( Operation, RecId, 'SERVFACT');
  EXCEPTION WHEN OTHERS THEN
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_act_stoc_mediu</obj_name>
  <obj_hashval>1422b8ac2990742851f478e61e52be93</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_act_stoc_mediu()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  NR    numeric;
BEGIN
  --Adina 20.04.2021 - sinc.Oracle
  FOR V_REC IN (SELECT CODOBIECT, CODSUBUNIT, STOCMEDIUSUBUNIT FROM TMP_ACT_STOCMED) LOOP
    SELECT COUNT( *) INTO NR FROM NARTOBJSUBUNIT WHERE CODOBIECT = V_REC.CODOBIECT
                                                       AND (codgest is null or codgest = 0)
                                                       AND  SUBUNITATE = V_REC.CODSUBUNIT;

    IF  NR = 0 THEN
      INSERT INTO NARTOBJSUBUNIT(CODS, CODOBIECT, SUBUNITATE, STOCMED)
      VALUES(NEXTVAL('SEQ_NARTOBJSUBUNIT_CODS'), V_REC.CODOBIECT, V_REC.CODSUBUNIT, V_REC.STOCMEDIUSUBUNIT);
    ELSE
      UPDATE NARTOBJSUBUNIT SET STOCMED = V_REC.STOCMEDIUSUBUNIT WHERE CODOBIECT = V_REC.CODOBIECT
                                                                       AND (codgest is null or codgest = 0)
                                                                       AND  SUBUNITATE = V_REC.CODSUBUNIT;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_calcul_nirstoc_puval</obj_name>
  <obj_hashval>d61de9bf47d2087a1bab102c4bd7b436</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_calcul_nirstoc_puval()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC   RECORD;
  aAN     numeric := 0;
  aLUNA   numeric := 0;
  aMONEDA numeric := 0;
  aBANCA  numeric := 0;
  aCURS   double precision := 0;
begin
  SELECT EXTRACT( MONTH FROM CURRENT_TIMESTAMP) INTO aLUNA;
  SELECT EXTRACT( YEAR  FROM CURRENT_TIMESTAMP) INTO aAN;

  BEGIN
    SELECT TO_NUMBER( COALESCE( (SELECT PKG_CATEGCONST_GetValConstanta.WME_RESULT FROM PKG_CATEGCONST_GetValConstanta(NULL, 'MONEDASITV', aAN, aLUNA)), '0'))
    INTO aMONEDA;
  EXCEPTION WHEN OTHERS THEN
    aMONEDA := 0;
  END;

  BEGIN
    SELECT TO_NUMBER( COALESCE( (SELECT PKG_CATEGCONST_GetValConstanta.WME_RESULT FROM PKG_CATEGCONST_GetValConstanta(NULL, 'BANCASITV', aAN, aLUNA)), '0'))
    INTO aBANCA;
  EXCEPTION WHEN OTHERS THEN
    aBANCA := 0;
  END;

  IF  aBANCA &lt;&gt; 0 AND  aMONEDA &lt;&gt; 0 THEN
    FOR V_REC IN
    (
    SELECT I.DATADOC, N.DATANIR, NS.CODNIRSTOC, NS.PRET, N.TIPNIR, I.CURS,
           (SELECT PKG_MONEDE_GETCURSMONEDA.WME_RESULT
            FROM PKG_MONEDE_GETCURSMONEDA(NULL, CASE WHEN  COALESCE( I.MONEDA, 0) = 0 THEN aMONEDA ELSE I.MONEDA END , aBANCA, TO_CHAR( N.DATANIR, 'DD.MM.YYYY'))
           ) AS CURSLADATA
    FROM NIRSTOC NS, NIR N, INTRARI I
    WHERE
       N.CODNIR = NS.CODNIR AND N.CODINTR IS NOT NULL  AND (COALESCE( PUVAL, 0) = 0 OR  PRET = COALESCE( PUVAL, 0))  AND N.TIPNIR IN (1, 2, 3, 4, 5) AND  I.CODINTR = N.CODINTR
    )
    LOOP
      aCURS := V_REC.CURSLADATA;
      IF  COALESCE( aCURS, 0) &lt;&gt; 0 THEN
        UPDATE NIRSTOC SET PUVAL = PRET / aCURS WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
      END IF;
    END LOOP;

    FOR V_REC IN
    (
    SELECT I.DATADOC, N.DATANIR, NS.CODNIRSTOC, NS.PRET, N.TIPNIR, I.CURS,
           (SELECT PKG_MONEDE_GETCURSMONEDA.WME_RESULT
            FROM PKG_MONEDE_GETCURSMONEDA(NULL, aMONEDA, aBANCA, TO_CHAR( N.DATANIR, 'DD.MM.YYYY'))
           ) AS CURSLADATA
    FROM NIRSTOC NS, NIR N, IESIRI I
    WHERE
       N.CODNIR = NS.CODNIR AND N.CODINTR IS NOT NULL  AND  COALESCE(PUVAL, 0) = 0 AND N.TIPNIR IN (19, 20) AND  I.CODIES = N.CODIES
    )
    LOOP
      aCURS := V_REC.CURSLADATA;
      IF  COALESCE( aCURS, 0) &lt;&gt; 0 THEN
        UPDATE NIRSTOC SET PUVAL = PRET / aCURS WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
      END IF;
    END LOOP;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_check_reguloss_luna</obj_name>
  <obj_hashval>fb3ac467d6d59544d0297cac031f3a81</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_check_reguloss_luna()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  nrModificari NUMERIC;
  V_REC_MARE record;
BEGIN
  --Florin 07.12.2022 - sinc. Oracle
  --Florin 30.11.2022
  FOR V_REC_MARE IN
   (SELECT * /*+ cardinality(X,1) */
    FROM
      REGOSS, TMP_PKG_GLOBALS X
    WHERE
      TIPREG   = 108
      AND AN   = ANLUCRU
      AND LUNA = LUNALUCRU
    ) LOOP

    DELETE FROM TMP_REGOSS;
    INSERT INTO TMP_REGOSS (CODREGOSS, TIPREG)
      (SELECT r.CODREGOSS,
               r.TIPREG
         FROM REGOSS r
         WHERE r.CODREGOSS = V_REC_MARE.CODREGOSS);

    DELETE FROM TMP_REGOSS1;
    nrModificari := 0;
    INSERT INTO TMP_REGOSS1
      (CODREGOSS1,
       CODREGOSS,
       CODDOC,
       TIPDOC,
       TVADOCVAL,
       TVADOC,
       TVADOCREG,
       CODGEST,
       CONT,
       SEMN,
       CURS,
       SEMNIFICATIE,
       DIFERENTA,
       CODPART,
       DEN_PART,
       DOC,
       SUBUNITATEA,
       modificari)
      select rs1.CODREGOSS1,
             rs1.CODREGOSS,
             rs1.CODDOC,
             rs1.TIPDOC,
             rs1.TVADOCVAL,
             rs1.TVADOC,
             rs1.TVADOCREG,
             rs1.CODGEST,
             rs1.CONT,
             rs1.SEMN,
             rs1.CURS,
             rs1.SEMNIFICATIE,
             rs1.TVADOCREG - rs1.TVADOCVAL,
             part.codpart,
             part.den_part,
             ies.seriadoc||' '||ies.nrdoc||'/'||to_char(ies.datadoc, 'dd.mm.yyyy') as doc,
             ies.subunitatea,
             0
        from REGOSS1 rs1
        join iesiri ies on ies.codies = rs1.coddoc
        join npart part on part.codpart = ies.partener
       where CODREGOSS = V_REC_MARE.CODREGOSS;
       PERFORM pkg_regoss_GenerateDataXTrimestru(V_REC_MARE.Trimestrul, V_REC_MARE.Curs,V_REC_MARE.CODMONEDA);
       select count(*) into nrModificari from TMP_REGOSS1 ros1 where coalesce(ros1.modificari,0) = 1;
       if nrModificari = 0 THEN
         select count(*) into nrModificari
         from regoss1 rs1
         left join tmp_regoss1 trs1 on trs1.codregoss1 = rs1.codregoss1
         where rs1.codregoss = V_REC_MARE.CODREGOSS
          and trs1.codregoss1 is null;
       END IF;
       if nrModificari &gt; 0 then
          update jurnal1 j1 set dirty = 1 where j1.coddoc = V_REC_MARE.CODREGOSS and j1.tipdoc = V_REC_MARE.TIPREG;
       end if;
 END LOOP;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_check_regultrezor_luna</obj_name>
  <obj_hashval>0808f82b30b6244253dcb21a2bfa0b23</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_check_regultrezor_luna()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC_MARE   RECORD;
  V_REC        RECORD;
  V_REC_TREZOR RECORD;
  PARAM_REG_DATA    date;
  PARAM_REG_MONEDA  NUMERIC(20);
  PARAM_REG_CURS    NUMERIC(20,7);
  LunaPrecedentaReg NUMERIC(2);
  AnPrecedentReg    numeric;
  DIFERENTE         numeric := 0;
BEGIN
  --Florin 17.08.2022 - sinc. Oracle
  --Bogdan 18.08.2020
  FOR V_REC_MARE in (SELECT * FROM REG, TMP_PKG_GLOBALS X WHERE TIPREG = 45 AND  AN = ANLUCRU AND  LUNA = LUNALUCRU) LOOP
    SELECT V_REC_MARE.DataDoc, V_REC_MARE.CodMoneda, V_REC_MARE.Curs
    INTO PARAM_REG_DATA, PARAM_REG_MONEDA, PARAM_REG_CURS;

    PERFORM PKG_REG_SetParamsReg( TO_CHAR( PARAM_REG_DATA, 'DD.MM.YYYY'), PARAM_REG_MONEDA, PARAM_REG_CURS::NUMERIC);
    PERFORM PKG_GLOBALS_SETLUNATEMP( V_REC_MARE.ANLUCRU, V_REC_MARE.LUNALUCRU);
    select  PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA.newan, PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA.newluna
    from PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA(V_REC_MARE.ANLUCRU, V_REC_MARE.LUNALUCRU, AnPrecedentReg, LunaPrecedentaReg)
      into AnPrecedentReg, LunaPrecedentaReg;

    PERFORM PKG_GLOBALS_SETLUNAPRECEDENTA( AnPrecedentReg, LunaPrecedentaReg);

    DELETE FROM TMP_REGTREZOR1_MARTOR;
    INSERT INTO TMP_REGTREZOR1_MARTOR(CODBANKCONT, SOLDDOCVAL)
    SELECT CODBANKCONT, SOLDDOCVAL FROM REGTREZOR1 WHERE CODREG = V_REC_MARE.CODREG;


     DELETE FROM TMP_REGTREZOR1;
    INSERT INTO TMP_REGTREZOR1 (CodRegTrezor1, SoldDoc, SoldDocVal, SoldDocReg, CodBank, CodBankCont, Diferenta, Den_Cont, NrCont, Filiala, Credit, SUBUNITATEA)
    ( SELECT -1 * row_number() over(),
            T1.SoldValuta,
            T1.SoldLei,
            T1.SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(NULL,NULL)),
            NBC.CodBank,
            T1.CodBankCont,
            T1.SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(NULL,NULL)) - T1.SoldLei,
            NBC.Den_Cont,
            NBC.NrCont,
            NBC.Filiala,
            NBC.Credit,
            NBC.SUBUNITATEA
      FROM (SELECT SoldValuta, SoldLei, CodBankCont FROM V_SOLDURIBANCILUNA) T1
           INNER JOIN NBANKCONT NBC ON  NBC.CodBankCont = T1.CodBankCont
      WHERE
           NBC.CodMoneda = pkg_reg_getmonedareg()
           AND  T1.SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(NULL,NULL)) - T1.SoldLei &lt;&gt; 0);

       DIFERENTE := 0;
      FOR V_REC in (
            SELECT INTBL.CODBANKCONT, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT
            FROM TMP_REGTREZOR1_MARTOR INTBL
            LEFT JOIN TMP_REGTREZOR1 OUTTBL ON  OUTTBL.CODBANKCONT = INTBL.CODBANKCONT
            union
            SELECT OUTTBL.CODBANKCONT, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT
            FROM TMP_REGTREZOR1 OUTTBL
            LEFT JOIN TMP_REGTREZOR1_MARTOR INTBL ON  INTBL.CODBANKCONT = OUTTBL.CODBANKCONT
      ) LOOP
        IF  COALESCE( V_REC.SOLDIN, 0) &lt;&gt; COALESCE( V_REC.SOLDOUT, 0) THEN
          DIFERENTE := 1;
          EXIT ;
        END IF;
      END LOOP;

      IF  DIFERENTE = 1 then

        UPDATE JURNAL1
        set DIRTY = 1
        where  TIPDOC = 45 AND  CODDOC = V_REC_MARE.CODREG;

        FOR V_REC_TREZOR IN (
                  SELECT T.*
                  FROM TREZOR T, NBANKCONT BC
                  WHERE
                    TIPDOC IN (29, 30, 31)
                    AND  BC.CODBANKCONT = T.CODBANCA
                    AND  BC.CREDIT = 1
                    AND  EXISTS ( SELECT CODBANKCONT
                                  FROM (SELECT CODBANKCONT FROM TMP_REGTREZOR1
                                        union
                                        SELECT CODBANKCONT FROM TMP_REGTREZOR1_MARTOR
                                       ) A_PG
                                  WHERE CODBANKCONT = T.CODBANCA
                                )
                    AND  AN * 12 + LUNA &gt; V_REC_MARE.AN * 12 + V_REC_MARE.LUNA
        ) LOOP
            UPDATE JURNAL1
            SET  DIRTY = 1
            WHERE TIPDOC = V_REC_TREZOR.TIPDOC AND  CODDOC = V_REC_TREZOR.CODTREZOR;
        END LOOP;
      END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_check_struct_extensie_task</obj_name>
  <obj_hashval>13aabaa2901f9953e4358d0732948d97</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_check_struct_extensie_task()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  NR    numeric := 0;
  DT    varchar;
  SIR   varchar;
  VG    varchar;
  NR1   numeric := 0;
  SKEMA varchar;
  sFIRMANAME   varchar;
BEGIN
  --Stef   24.03.2022 - CREATE TEMPORARY (scosGLOBAL fiindca e obsolete si apare/incurca in loguri de BD)
  --Adina 02.06.2021 - scos upper; add sFIRMANAME
  sFIRMANAME := lower(current_setting('PKG_GLOBALS.FIRMANAME', true));

  select  count(*) into  NR
  from  information_schema.Columns
  where TABLE_NAME = 'settaskext' and TABLE_SCHEMA = sFIRMANAME;

  IF NR &gt; 0 THEN
    Sir := 'CREATE TEMPORARY TABLE TMP_SETTASKEXT(';
    FOR V_REC IN (select  * from  information_schema.Columns
                  where TABLE_NAME = 'settaskext' and TABLE_SCHEMA = sFIRMANAME
                  order BY ORDINAL_POSITION
                 )
    LOOP
      IF V_REC.DATA_TYPE = 'character varying' THEN
        DT := ' VARCHAR(' || V_REC.CHARACTER_MAXIMUM_LENGTH::varchar || ') ';
      ELSE
        IF V_REC.DATA_TYPE = 'date' THEN
          DT := ' DATE ';
        ELSE
          DT := ' NUMERIC(' || V_REC.DATA_PRECISION::VARCHAR || ',' || V_REC.DATA_SCALE::VARCHAR || ') ';
        END IF;
      END IF;

      IF V_REC.ORDINAL_POSITION &lt; NR THEN
        VG := ', ';
      ELSE
        VG := '';
      END IF;

      DT  := DT || VG;
      SIR := SIR || ' ' || V_REC.COLUMN_NAME || ' ' || DT;
    END LOOP;

    SIR := SIR || ' ) ON COMMIT PRESERVE ROWS';
    EXECUTE SIR;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_domonitor</obj_name>
  <obj_hashval>52d1675b66de67665d7854d6107c10ea</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_domonitor(codexternmonitor character varying, obs character varying, idver numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  sDoc        varchar;
  denSubunit  varchar;
  oper        varchar;
  aUserName   varchar;
  aFirmaName  varchar;
  aSubunitate varchar;
  aEXEVERSION varchar;
begin
  --Florin 18.11.2021 - fixat 52075
  SELECT UserName, FirmaName, Subunitate, ExeVersion
  INTO aUserName, aFirmaName, aSubunitate, aEXEVERSION
  FROM TMP_PKG_GLOBALS X;

  IF (SELECT PKG_USERFIRME_ValidPostLog.WME_RESULT FROM PKG_USERFIRME_ValidPostLog(NULL, TO_NUMBER(current_setting('PKG_GLOBALS.USERID', true),'999999999999999999'), codExternMonitor))
  THEN
    sDoc := CASE codExternMonitor
     WHEN 'MON_17' THEN 'Refacere jurnal '
     WHEN 'MON_18' THEN 'Actualizare constante '
     WHEN 'MON_19' THEN 'Fixare stocuri / solduri de fina luna '
     WHEN 'MON_20' THEN 'Actualizare rulaj precedent conturi '
     WHEN 'MON_21' THEN 'Refacere stocuri la moment '
     WHEN 'MON_22' THEN 'Verificare repartizare solduri pe analitice noi de cont '
     WHEN 'MON_23' THEN 'Inregistrari cod zero '
     WHEN 'MON_24' THEN 'Refacere carnete de documente '
     WHEN 'MON_25' THEN 'Refacere codificare automata - SysID '
     WHEN 'MON_26' THEN 'Inchidere luna '          || coalesce(Obs,'')
     WHEN 'MON_27' THEN 'Anulare inchidere luna '  || coalesce(Obs,'')
     WHEN 'MON_31' THEN 'Regularizare casa/banca ' || coalesce(SUBSTR( Obs, 1, INSTR( OBS, '|') - 1),'')
     WHEN 'MON_32' THEN 'Regularizare parteneri '  || coalesce(SUBSTR( Obs, 1, INSTR( OBS, '|') - 1),'')
     WHEN 'MON_33' THEN 'Regularizare personal '   || coalesce(SUBSTR( Obs, 1, INSTR( OBS, '|') - 1),'')
     END ;

    oper := CASE codExternMonitor
     WHEN 'MON_17' THEN 'R'
     WHEN 'MON_18' THEN 'C'
     WHEN 'MON_19' THEN 'F'
     WHEN 'MON_20' THEN 'C'
     WHEN 'MON_21' THEN 'R'
     WHEN 'MON_22' THEN 'V'
     WHEN 'MON_23' THEN 'R'
     WHEN 'MON_24' THEN 'R'
     WHEN 'MON_25' THEN 'R'
     WHEN 'MON_26' THEN 'I'
     WHEN 'MON_27' THEN 'D'
     WHEN 'MON_35' THEN 'LST'
     END ;

    IF codExternMonitor IN ('MON_31', 'MON_32', 'MON_33') THEN
      IF  INSTR( obs, '|A') &gt; 0 THEN
        OPER := 'A';
      ELSE
        OPER := 'S';
      END IF;
    END IF;

    IF  IDVer &gt; 0 THEN
      PERFORM winmadmin.PKG_USERFIRME_PostLogCuCommit( null::varchar, aUSERNAME, oper, IDVer::numeric, aFIRMANAME, aSUBUNITATE::numeric, current_date, sDoc, obs, aEXEVERSION);
    ELSE
      PERFORM winmadmin.PKG_USERFIRME_PostLogCuCommit( null::varchar, aUSERNAME, oper, null::numeric, aFIRMANAME, aSUBUNITATE::numeric, current_date, sDoc, obs, aEXEVERSION);
    END IF;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_empty_documente_for_jurnal</obj_name>
  <obj_hashval>5c45e55e2ebbb00621b3288fa243187e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_empty_documente_for_jurnal()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 22.03.2022 - sinc. Oracle (21.03.2022)
  DELETE FROM TMP_INTRARI;
  DELETE FROM TMP_INTRARI1;
  DELETE FROM TMP_DVI;
  DELETE FROM TMP_DVI1;
  DELETE FROM TMP_INTRLINK;
  DELETE FROM TMP_INTRASTEPTLINK;
  DELETE FROM TMP_NIR;
  DELETE FROM TMP_NIRSTOC;
  DELETE FROM TMP_LIVR;
  DELETE FROM TMP_LIVR1;
  DELETE FROM TMP_LIVRTOT;
  DELETE FROM TMP_MODURIPLATI;
  DELETE FROM TMP_DISCMONETAR;
  DELETE FROM TMP_IESDISC;
  DELETE FROM TMP_IOPARTDOC;
  DELETE FROM TMP_IOPARTVAMA;
  DELETE FROM TMP_IESIRI;
  DELETE FROM TMP_IESIRI1;
  DELETE FROM TMP_IESLINK;
  DELETE FROM TMP_LIVR1_INITIAL;
  DELETE FROM TMP_STINGERE_INITIAL;
  DELETE FROM TMP_OBLIGPIF_INITIAL;
  DELETE FROM TMP_INTRLINK_INITIAL;
  DELETE FROM TMP_INTRASTEPTLINK_INITIAL;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_empty_documente_for_mifix</obj_name>
  <obj_hashval>594254080863023fb004d6aecd27966c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_empty_documente_for_mifix()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_MIFIX;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_empty_documente_for_nc</obj_name>
  <obj_hashval>d4f4e37ea8f05616fdecb1b4d2cdd493</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_empty_documente_for_nc()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_NC;
  DELETE FROM TMP_NC1;
  DELETE FROM TMP_GENERAL;
  DELETE FROM TMP_OBLIGPIF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_empty_documente_for_notecredit</obj_name>
  <obj_hashval>d3b5e85daf4db4d0dbeadf58a0e1d93a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_empty_documente_for_notecredit()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_NOTECREDIT;
  DELETE FROM TMP_NOTECREDITT;
  DELETE FROM TMP_NOTECREDITV;
  DELETE FROM TMP_NOTECREDITC;
  DELETE FROM TMP_NOTECREDITP;
  DELETE FROM TMP_NOTECREDITZ;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_empty_documente_for_reg</obj_name>
  <obj_hashval>8ed8aad15e0489c648f7807f77761613</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_empty_documente_for_reg()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_REG;
  DELETE FROM TMP_REG1;
  DELETE FROM TMP_REG1CONT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_empty_documente_for_regpers</obj_name>
  <obj_hashval>72fdb04462b1d1d41c9ec63ca9e023a1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_empty_documente_for_regpers()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_REG;
  DELETE FROM TMP_REGPERS1;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_empty_documente_for_regtrezor</obj_name>
  <obj_hashval>3a692aa537f3cb3c8fd08d2d3b3081e4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_empty_documente_for_regtrezor()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_REG;
  DELETE FROM TMP_REGTREZOR1;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_empty_documente_for_trezor</obj_name>
  <obj_hashval>4afc7d9eab5ca0e5cbb07e35db07e0ee</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_empty_documente_for_trezor()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_TREZOR;
  DELETE FROM TMP_TREZOR1;
  DELETE FROM TMP_GENERAL;
  DELETE FROM TMP_OBLIGPIF;
  DELETE FROM TMP_STINGERE;
  DELETE FROM TMP_STINGERE_INITIAL;
  DELETE FROM TMP_OBLIGPIF_INITIAL;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_cheltavans_recordcount</obj_name>
  <obj_hashval>dbaf1f0dc1c08ff163f0b8ba63b6dce2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_cheltavans_recordcount(INOUT wme_result numeric, INOUT flg_isvenit numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  NR numeric := 0;
begin
  --Stef 03.03.2023
  BEGIN
    SELECT COUNT(*)
    INTO NR
    FROM CHELTAVANS AV
    LEFT JOIN TMP_IOART_LUNA IOL ON  IOL.CODIOART = AV.CODIOART, CHELTAVANS1 AV1
    WHERE
       COALESCE(AV.ISVENIT, 0) = flg_ISVENIT
       AND  AV.CODCHELTAVANS = AV1.CODCHELTAVANS
       AND  AV1.ANSTART * 12 + AV1.LUNASTART = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X)
       AND PKG_SERVICE_IS_DIRTY_DOC(52, AV.CODCHELTAVANS, 106) = 1
       AND (EXISTS (SELECT CONTCHELTAVANS FROM TMP_CONTCHELTAVANS WHERE CONTCHELTAVANS = (IOL.CONT)::varchar)
            OR
            EXISTS (SELECT CONTVENITAVANS FROM TMP_CONTVENITAVANS WHERE CONTVENITAVANS =IOL.CONT)) ;
  --EXCEPTION WHEN OTHERS THEN
  --NR := 0;
  END;

  WME_Result :=  NR;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_compens_recordcount</obj_name>
  <obj_hashval>f51e694a35974cf60d98ef59d4a1e33f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_compens_recordcount(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 03.03.2023
  SELECT COUNT(1) INTO wme_result
  FROM COMPENS
  WHERE AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE_IS_DIRTY_DOC(28, CODCOMPENS) = 1;

  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_contract_for_jurnal</obj_name>
  <obj_hashval>1997b808537ab7f1324233944fac7307</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_contract_for_jurnal(startrec numeric, endrec numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Stef 03.03.2023
  DELETE FROM TMP_CONTRACT;
  DELETE FROM TMP_CONTRACT0;
  DELETE FROM TMP_CONTRACT1;

  INSERT INTO TMP_CONTRACT(CODCONTRACT, NRDOC, DATADOC, Partener, Subunitatea, Anulat, Operat)
  SELECT CODCONTRACT, NRDOC, DATADOC, Partener, Subunitatea, Anulat, Operat
  FROM (
    SELECT row_number() over() RN, S.*
    FROM (
      SELECT C.*
      FROM CONTRACT C
      WHERE TIPDOC = 25 AND PKG_SERVICE_IS_DIRTY_DOC(25, C.CODCONTRACT) = 1
      ORDER BY CODCONTRACT
    ) S
  ) A_PG
  WHERE RN &gt;= STARTREC AND  RN &lt;= ENDREC;

  INSERT INTO TMP_CONTRACT0
  SELECT *
  FROM CONTRACT0 C0
  WHERE EXISTS (SELECT CODCONTRACT FROM TMP_CONTRACT WHERE CODCONTRACT = C0.CODCONTRACT)
    AND  C0.TIPLINIE = 2
    AND  EXTRACT( YEAR FROM DATA) * 12 + EXTRACT( MONTH FROM DATA) = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X);

  INSERT INTO TMP_CONTRACT1(CODCONTRACT, GestAct, Codcentru)
  SELECT CODCONTRACT, GestAct, Codcentru
  FROM CONTRACT1
  WHERE CODCONTRACT IN (SELECT CODCONTRACT FROM TMP_CONTRACT);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_contract_recordcount</obj_name>
  <obj_hashval>fe26aa279180182fbde952a1b5dc71ca</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_contract_recordcount(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 03.03.2023
  SELECT COUNT(1) INTO wme_result
  FROM CONTRACT
  WHERE TIPDOC = 25;

  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_difpretprod_for_jurnal</obj_name>
  <obj_hashval>8b613b95f36c660b92a0fa1f4498e358</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_difpretprod_for_jurnal(startrec numeric, endrec numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Stef 03.03.2023
  --Bogdan 20.08.2020
  DELETE FROM TMP_DIFPretPROD;
  DELETE FROM TMP_DIFPretPROD1;

  INSERT INTO TMP_DIFPretPROD(CodDIFPretPROD, An, Luna, Obs, Operat, Subunitatea, CodGest)
  SELECT CodDIFPretPROD, An, Luna, Obs, Operat, Subunitatea, CodGest
  FROM (SELECT row_number() over() RN, S.*
        FROM (SELECT CodDIFPretPROD, An, Luna, Obs, Operat, Subunitatea, CodGest
              FROM DIFPretPROD PN
              WHERE AN * 12 + LUNA = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X)
                AND PKG_SERVICE_IS_DIRTY_DOC(80, PN.CODDIFPretPROD) = 1
              ORDER BY CodDIFPretPROD
             ) S
       ) A_PG
  WHERE RN &gt;= STARTREC AND  RN &lt;= ENDREC;

  INSERT INTO tmp_DIFPRETPROD1 (
          CODDIFPRETPROD1, CODDIFPRETPROD, CodCOMANDA1, CODNIRSTOC,
          DifPret, CODCENTRU, CODANALIZANOD, DIRTY, Curent, AnLuna,
          INTRARI, IESIRI, XDIFPRET, XCODCENTRU, XCODANALIZANOD, XCurent,
          XINTRARI, XIESIRI, PRET, PretReal, NRDOC, DATADOC,
          CodGest, Codioart, CodObiect, DENUMIRE)
  ( SELECT DP1.codDIFPRETPROD1, DP1.codDIFPRETPROD, DP1.CodCOMANDA1, DP1.CODNIRSTOC,
      DP1.DifPret, DP1.CODCENTRU, DP1.CODANALIZANOD, DP1.DIRTY, DP1.Curent,
      DP1.AnLuna, DP1.INTRARI, DP1.IESIRI, DP0.DIFPRET, DP0.CODCENTRU,
      DP0.CODANALIZANOD, DP0.Curent, DP0.INTRARI, DP0.IESIRI, NS.Pret,
      COALESCE( obj1.ValMat, 0) + (  2 - COALESCE( obj1.TipPret, 1))  * (  COALESCE( obj1.ValMan, 0) + COALESCE( obj1.ValRegie, 0)) ,
      c.nrdoc, c.datadoc, C.CodGest, Ns.Codioart, c1.CodObiect, obj.denumire
    FROM DIFPRETPROD1 DP1
      INNER JOIN comanda1         c1   ON  DP1.CodCOMANDA1 = c1.codcomanda1
      INNER JOIN comanda          c    ON  c1.codcomanda   = c.codcomanda
      INNER JOIN nartobj          obj  ON  obj.codobiect   = c1.codobiect
      INNER JOIN Tmp_Nartobj_Luna obj1 ON  obj1.codobiect  = c1.codobiect
      INNER JOIN NirStoc          Ns   ON  DP1.codNirStoc  = Ns.codNirStoc
      LEFT  JOIN DIFPRETPROD1     DP0  ON  DP0.CodCOMANDA1 = DP1.codcomanda1 and  DP0.CodNirStoc = DP1.CodNirStoc and  DP0.AnLuna = DP1.AnLuna - 1
    WHERE   EXISTS (SELECT CODDIFPretPROD FROM TMP_DIFPretPROD WHERE CODDIFPretPROD = DP1.CODDIFPretPROD)
    );
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_distribchelt_for_jurnal</obj_name>
  <obj_hashval>4e81654612cb94b4328238ae2ea82223</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_distribchelt_for_jurnal(startrec numeric, endrec numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  ANLUNA_START numeric;
  NR           numeric;
begin
  --Florin 06.11.2025 - sinc. Oracle
  --Stef 03.03.2023
  -- Bogdan 20.08.2020
  DELETE FROM TMP_DISTRIBCHELT;
  DELETE FROM TMP_DISTRIBCHELT1;
  DELETE FROM TMP_DISTRIBCHELT2;

  INSERT INTO TMP_DISTRIBCHELT (CODDISTRIBCHELT, TIPDOC, OBS, AN, LUNA, SUBUNITATEA, USERID, DATACREARE, BLOCAT, OPERAT)
  SELECT CODDISTRIBCHELT, TIPDOC, OBS, AN, LUNA, SUBUNITATEA, USERID, DATACREARE, BLOCAT, OPERAT
  FROM (SELECT row_number() over() AS RN, S.*
        FROM (
              SELECT CODDISTRIBCHELT, TIPDOC, OBS, AN, LUNA, SUBUNITATEA, USERID, DATACREARE, BLOCAT, OPERAT
              FROM DISTRIBCHELT DC
              WHERE AN * 12 + LUNA = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X)
                AND PKG_SERVICE_IS_DIRTY_DOC(76, DC.CODDISTRIBCHELT) = 1
              ORDER BY CODDISTRIBCHELT
             ) S
       ) A_PG
  WHERE RN &gt;= STARTREC AND  RN &lt;= ENDREC;

  INSERT INTO TMP_DISTRIBCHELT1 (
      CodDISTRIBCHELT1, CodDISTRIBCHELT, INDEXLOCAL, CODNEST, VAL,
      CODD, CODC, CODCC, CODGEST, DENGEST, CENTRU, DEBIT, CREDIT, BUTON)
  SELECT PCF.CodDISTRIBCHELT1, PCF.CodDISTRIBCHELT, PCF.INDEXLOCAL, PCF.CODNEST,
      PCF.VAL, NS.CODCONTD, NS.CODCONTC, NS.CODCENTRU, NS.CODGEST,
      Substr( G.DEN_GEST, 1, 30), CC.Simbol, Substr( DEBIT.SIMBOL, 1, 20), Substr( CREDIT.SIMBOL, 1, 20), '   c'
  FROM DISTRIBCHELT1 PCF
    LEFT JOIN NESTJURNAL NS     ON  PCF.CODNEST  = NS.CODNESTJURNAL
    LEFT JOIN NGEST      G      ON  G.CODGEST    = NS.CODGEST
    LEFT JOIN CENTRECOST CC     ON  CC.CODCENTRU = NS.CODCENTRU
    LEFT JOIN NCONT      DEBIT  ON  NS.CODCONTD  = DEBIT.CODCONT
    LEFT JOIN NCONT      CREDIT ON  NS.CODCONTC  = CREDIT.CODCONT
  where
    PCF.CodDISTRIBCHELT IN (SELECT CODDISTRIBCHELT FROM TMP_DISTRIBCHELT);

  INSERT INTO TMP_DISTRIBCHELT2 (
      CodDISTRIBCHELT2, CodDISTRIBCHELT1, CodDISTRIBCHELT,
      INDEXLOCAL, CODGEST, CODCENTRU, OBS, PROCENT, DENGEST, CENTRU )
  SELECT PCF.CodDISTRIBCHELT2, PCF.CodDISTRIBCHELT1, PCF.CodDISTRIBCHELT,
        PCF.INDEXLOCAL, PCF.CODGEST, PCF.CODCENTRU, PCF.OBS, PCF.PROCENT, Substr( G.DEN_GEST, 1, 30), CC.Simbol
  FROM DISTRIBCHELT2 PCF
    LEFT JOIN NGEST G ON  G.CODGEST = PCF.CODGEST
    LEFT JOIN CENTRECOST CC ON  CC.CODCENTRU = PCF.CODCENTRU
  WHERE
      PCF.CodDISTRIBCHELT IN (SELECT CODDISTRIBCHELT FROM TMP_DISTRIBCHELT);

  FOR v_rec in (SELECT CodDISTRIBCHELT1 FROM Tmp_DISTRIBCHELT1) LOOP
    SELECT Count( *) INTO Nr
    FROM TMP_DISTRIBCHELT2
    WHERE
         CodDISTRIBCHELT1 = v_rec.CodDISTRIBCHELT1;

    IF  COALESCE( Nr, 0) &gt; 0 THEN
      UPDATE Tmp_DISTRIBCHELT1 set Buton = 'u' WHERE CodDISTRIBCHELT1 = v_rec.CodDISTRIBCHELT1;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_documente_for_jurnal</obj_name>
  <obj_hashval>856ba48b9ed69856efae5c39c58efc43</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_documente_for_jurnal()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_INTRARI;
  DELETE FROM TMP_DVI;
  DELETE FROM TMP_DVI1;
  DELETE FROM TMP_INTRARI1;
  DELETE FROM TMP_INTRLINK;
  DELETE FROM TMP_NIR;
  DELETE FROM TMP_NIRSTOC;
  DELETE FROM TMP_LIVR;
  DELETE FROM TMP_LIVR1;
  DELETE FROM TMP_LIVRTOT;
  DELETE FROM TMP_IOPARTDOC;
  DELETE FROM TMP_IOPARTVAMA;
  DELETE FROM TMP_JURNAL;
  DELETE FROM TMP_JURNAL1;
  DELETE FROM TMP_RULAJ;
  DELETE FROM TMP_IESIRI;
  DELETE FROM TMP_IESIRI1;
  DELETE FROM TMP_IESLINK;
  DELETE FROM TMP_LIVR1_INITIAL;
  DELETE FROM TMP_STINGERE_INITIAL;
  DELETE FROM TMP_OBLIGPIF_INITIAL;
  DELETE FROM TMP_INTRLINK_INITIAL;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_iesiri_recordcount</obj_name>
  <obj_hashval>79f262cf81d4c1eefeeb562d19da2c77</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_iesiri_recordcount(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 09.08.2023 - sinc. Oracle
  --Stef 03.03.2023
  SELECT COUNT(1) INTO wme_result
  FROM IESIRI
  WHERE
    AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS)
    AND COALESCE(INFOCM, 0) = 0
    AND PKG_SERVICE_IS_DIRTY_DOC(TIPDOC, CODIES) = 1;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_intrari_recordcount</obj_name>
  <obj_hashval>d87a940cc11f0028513d1b7571cb73a1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_intrari_recordcount(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 03.03.2023
  SELECT COUNT(1) INTO wme_result
  FROM INTRARI
  WHERE AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE_IS_DIRTY_DOC(TIPDOC, CODINTR) = 1;

  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_mifix_for_jurnal</obj_name>
  <obj_hashval>b6a6b5b5b3cdae2b1a0abc658e6204c4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_mifix_for_jurnal(startrec numeric, endrec numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  NR double precision := 0;
  aCODMIFIXVECHI numeric(20);
  v_rec record;
begin
  --Florin 12.12.2025 - sinc. Oracle
  --Florin 06.11.2025 - sinc. Oracle
  --Stef 03.03.2023
  --Bogdan 15.08.2020
  PERFORM pkg_service_EMPTY_DOCUMENTE_FOR_MIFIX();
  INSERT INTO TMP_MIFIX (
          CODMIFIX, TIP, NRINVENTAR, ANINTRARE, LUNAINTRARE,
          CODMIFIX1, CODNIRSTOC, PRET, CANT, CODCLASIF, TIPAMO,
          STARE, DURATAN, GRADU, DURATAF, AMO, NEUTIL, DFBLOCAT,
          CODPERS, ANSTART, LUNASTART, CODIOART, CODGEST, TIPREEVAL,
          DATAREEVAL, INCLUDRATA, AMOVECHI, PRETVECHI, NEUTILVECHI,
          SUBUNITATEA, CodAnalizaNod, CodCentru, TipStorno, DENUMIRE, DURATANF,
          DURATAFF, AMOF, DURATANG, DURATAFG, AMOG, ANINTRAREG, LUNAINTRAREG,
          DFBlocat_F, DFBlocat_G, REZERVA, AMOREZERVA, AMORBLOCAT
  )
  SELECT CODMIFIX, TIP, NRINVENTAR, ANINTRARE, LUNAINTRARE, CODMIFIX1, CODNIRSTOC,
      PRET, CANT, CODCLASIF, TIPAMO, STARE, DURATAN, GRADU, DURATAF, AMO, NEUTIL,
      DFBLOCAT, CODPERS, ANSTART, LUNASTART, CODIOART, GEST, TIPREEVAL, DATAREEVAL,
      INCLUDRATA, AMOVECHI, PRETVECHI, NEUTILVECHI, CODSUBUNIT, CodAnalizaNod,
      CodCentru, TipStorno, DENUMIRE, DURATANF, DURATAFF, AMOF, DURATANG, DURATAFG, AMOG,
      ANINTRAREG, LUNAINTRAREG, DFBlocat_F, DFBlocat_G, REZERVA, AMOREZERVA, AMORBLOCAT
  FROM (
    SELECT row_number() over () AS RN, MF_LUNA.CODMIFIX, MF_LUNA.TIP, MF_LUNA.NRINVENTAR, MF_LUNA.ANINTRARE,
      MF_LUNA.LUNAINTRARE, MF_LUNA.CODMIFIX1, MF_LUNA.CODNIRSTOC, MF_LUNA.PRET, MF_LUNA.CANT,
      MF_LUNA.CODCLASIF, MF_LUNA.TIPAMO, MF_LUNA.STARE, MF_LUNA.DURATAN, MF_LUNA.GRADU, MF_LUNA.DURATAF,
      MF_LUNA.AMO, MF_LUNA.NEUTIL, MF_LUNA.DFBLOCAT, MF_LUNA.CODPERS, MF_LUNA.ANSTART, MF_LUNA.LUNASTART,
      MF_LUNA.CODIOART, MF_LUNA.GEST, MF_LUNA.TIPREEVAL, MF_LUNA.DATAREEVAL, MF_LUNA.INCLUDRATA,
      MF_LUNA.AMOVECHI, MF_LUNA.PRETVECHI, MF_LUNA.NEUTILVECHI, MF_LUNA.CODSUBUNIT, MF_LUNA.CodAnalizaNod,
      MF_LUNA.CodCentru, MF_LUNA.TipStorno, MF_LUNA.DENUMIRE, MF_LUNA.DURATANF, MF_LUNA.DURATAFF, MF_LUNA.AMOF, MF_LUNA.DURATANG,
      MF_LUNA.DURATAFG, MF_LUNA.AMOG, MF_LUNA.ANINTRAREG, MF_LUNA.LUNAINTRAREG, MF_LUNA.DFBlocat_F,
      MF_LUNA.DFBlocat_G, MF_LUNA.REZERVA, MF_LUNA.AMOREZERVA, MF_LUNA.AMORBLOCAT
    FROM (
        SELECT MF.CODMIFIX, MF.TIP, NRINVENTAR, ANINTRARE, LUNAINTRARE, CODMIFIX1,
          MF1.CODNIRSTOC, MF1.PRET, CANT, CODCLASIF, TIPAMO, STARE, DURATAN, GRADU, DURATAF,
          AMO, NEUTIL, DFBLOCAT, CODPERS, ANSTART, LUNASTART, NS.CODIOART, N.GEST, TIPREEVAL,
          DATAREEVAL, INCLUDRATA, AMOVECHI, PRETVECHI, NEUTILVECHI, G.CODSUBUNIT, mf1.CodAnalizaNod,
          mf1.CodCentru, mf1.TipStorno, O.DENUMIRE, DURATANF, DURATAFF, AMOF, DURATANG, DURATAFG, AMOG, ANINTRAREG,
          LUNAINTRAREG, DFBlocat_F, DFBlocat_G, REZERVA, AMOREZERVA, AMORBLOCAT
        FROM MIFIX MF, MIFIX1 MF1
          LEFT JOIN NIRSTOC NS ON  NS.CODNIRSTOC = MF1.CODNIRSTOC
          LEFT JOIN NIR     N  ON  N.CODNIR  = NS.CODNIR
          LEFT JOIN NGEST   G  ON  G.CODGEST = N.GEST, NARTOBJ O
        WHERE
             MF.CODMIFIX = MF1.CODMIFIX AND  MF1.ANSTART * 12 + MF1.LUNASTART = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X)
            AND  O.CODOBIECT = NS.CODOBIECT
            AND  PKG_SERVICE_IS_DIRTY_DOC(36, MF.CODMIFIX) = 1
        ORDER BY  CODMIFIX
      ) MF_LUNA
    ) A_PG
  WHERE
         RN &gt;= STARTREC AND  RN &lt;= ENDREC;

 FOR v_rec in (SELECT M1.*
                FROM
                  TMP_MIFIX M1
                  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = M1.CODNIRSTOC
                  INNER JOIN NIR N ON N.CODNIR = NS.CODNIR AND N.TIPNIR = 6
               )
  LOOP
    SELECT MIN(CODMIFIX) INTO aCODMIFIXVECHI FROM MIFIX
    WHERE CODMIFIXNOU = V_REC.CODMIFIX and ANLUNAMIFIXNOU = getANLUCRU() * 12 + getLUNALUCRU();
    IF aCODMIFIXVECHI &gt; 0 THEN
      UPDATE TMP_MIFIX
      SET
        CODMIFIXVECHI = aCODMIFIXVECHI,
        NRINVENTARVECHI = (SELECT NRINVENTAR FROM MIFIX WHERE CODMIFIX = aCODMIFIXVECHI)
      WHERE
        CODMIFIX = V_REC.CODMIFIX;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_mifix_recordcount</obj_name>
  <obj_hashval>1a41b41587fd5713e3d15728ddac5394</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_mifix_recordcount(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 03.03.2023
  SELECT COUNT(1) INTO wme_result
  FROM MIFIX1 MF1 INNER JOIN MIFIX  MF  ON MF.CODMIFIX = MF1.CODMIFIX
  WHERE MF1.ANSTART*12+MF1.LUNASTART = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE_IS_DIRTY_DOC(36, MF.CODMIFIX) = 1;

  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_nc_for_jurnal</obj_name>
  <obj_hashval>4d80c8c94738a80b49cb1436f49cb1d9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_nc_for_jurnal(startrec numeric, endrec numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Stef 03.03.2023
  --Bogdan 15.08.2020
  PERFORM pkg_service_EMPTY_DOCUMENTE_FOR_NC();
  INSERT INTO TMP_NC (
    CodNC, Part, JurnalTVA, TipTranz, TipTVA, Valoare, Moneda, Curs, Obs, NrDoc, DataDoc, AN, LUNA, SUBUNITATEA, SABLON
  )
  SELECT CodNC, Part, JurnalTVA, TipTranz, TipTVA, Valoare, Moneda, Curs, Obs, NrDoc, DataDoc, AN, LUNA, SUBUNITATEA, SABLON
  from (
    SELECT row_number() over() AS RN, NC_LUNA.CodNC, NC_LUNA.Part,
      NC_LUNA.JurnalTVA, NC_LUNA.TipTranz, NC_LUNA.TipTVA,
      NC_LUNA.Valoare, NC_LUNA.Moneda, NC_LUNA.Curs, NC_LUNA.Obs,
      NC_LUNA.NrDoc, NC_LUNA.DataDoc, NC_LUNA.AN, NC_LUNA.LUNA,
      NC_LUNA.SUBUNITATEA, NC_LUNA.SABLON
    FROM (
      SELECT row_number() over() RN, CodNC, Part, JurnalTVA, TipTranz,
        TipTVA, Valoare, Moneda, Curs, Obs, NrDoc, DataDoc, AN, LUNA, SUBUNITATEA, SABLON
      FROM NC
      WHERE AN * 12 + LUNA = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X)
        AND PKG_SERVICE_IS_DIRTY_DOC(35, NC.CODNC) = 1
      ORDER BY
        CODNC
      ) NC_LUNA
  ) A_PG
  WHERE
     RN &gt;= STARTREC AND  RN &lt;= ENDREC;

  INSERT INTO TMP_NC1 (
            IndexLocal, PartD, PartC, PersD, PersC, CodNC1,
            CodNC, ContD, ContC, ICONTD, ICONTC, Valoare, Obs,
            Agent, CodCentru, CodGest, CodAnalizaNod, CODPART
            )
  SELECT * FROM (
        SELECT IndexLocal, PartD, PartC, PersD, PersC, CodNC1, CodNC, ContD,
          ContC, ICONTD, ICONTC, Valoare, Obs, Agent, CodCentru, CodGest, CodAnalizaNod, CODPART
        FROM NC1
        WHERE
             EXISTS (SELECT CODNC FROM TMP_NC WHERE CODNC = NC1.CODNC)
        ) B_PG
  ORDER BY
    INDEXLOCAL ;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_nc_recordcount</obj_name>
  <obj_hashval>f134d03784d647832203c794fd9df4ef</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_nc_recordcount(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 03.03.2023
  SELECT COUNT(1) INTO wme_result
  FROM NC
  WHERE AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE_IS_DIRTY_DOC(35, CODNC) = 1;

  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_notecredit_recordcount</obj_name>
  <obj_hashval>d999b859ebe0a53083ef5bc80abfa90f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_notecredit_recordcount(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 03.03.2023
  SELECT COUNT(1) INTO wme_result
  FROM NOTECREDIT
  WHERE AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE_IS_DIRTY_DOC(TIPDOC, CODNCREDIT) = 1;

  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_postcalcul_recordcount</obj_name>
  <obj_hashval>082af3f78a5b3a916ced4ff9221edf0c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_postcalcul_recordcount(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 03.03.2023
  SELECT COUNT(1) INTO wme_result
  FROM PCALCUL
  WHERE AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE_IS_DIRTY_DOC(72, CODPC) = 1;

  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_prodnet_for_jurnal</obj_name>
  <obj_hashval>7a9f8df69bc198faef5541e39a4be197</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_prodnet_for_jurnal(startrec numeric, endrec numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  --Stef 03.03.2023
  --Bogdan 20.08.2020
  DELETE FROM TMP_PRODNET;
  DELETE FROM TMP_PRODNET1;
  INSERT INTO TMP_prodnet (Codprodnet, An, Luna, Obs, Tip, Subunitatea, CodGest)
  SELECT Codprodnet, An, Luna, Obs, Tip, Subunitatea, CodGest
  FROM (
      SELECT row_number() over() AS RN, S.*
      FROM (
        SELECT Codprodnet, An, Luna, Obs, Tip, Subunitatea, CodGest
        FROM prodnet PN
        WHERE AN * 12 + LUNA = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X)
          AND PKG_SERVICE_IS_DIRTY_DOC(71, PN.CODPRODNET) = 1
        ORDER BY Codprodnet
      ) S
    ) A_PG
  WHERE
       RN &gt;= STARTREC AND  RN &lt;= ENDREC;

  FOR v_rec in (SELECT CodProdNet FROM TMP_ProdNet) loop
    PERFORM PKG_PRODNET_REFACEREDIRTY( v_rec.codprodnet, 0);
  END LOOP;

  INSERT INTO tmp_prodnet1 (codprodnet1, codprodnet, coddoc1, explicatii, valmat, valman, codcentru, denumire, nrdoc, datadoc)
  (
    SELECT pn1.codprodnet1, pn1.codprodnet, pn1.coddoc1, pn1.explicatii, pn1.valmat, pn1.valman, pn1.codcentru, obj.denumire, c.nrdoc, c.datadoc
    FROM prodnet1 pn1
      LEFT JOIN comanda1 c1  ON  pn1.coddoc1   = c1.codcomanda1
      LEFT JOIN comanda  c   ON  c1.codcomanda = c.codcomanda
      LEFT JOIN nartobj  obj ON  obj.codobiect = c1.codobiect
    WHERE
         EXISTS (SELECT CODPRODNET FROM TMP_PRODNET WHERE CODPRODNET = PN1.CODPRODNET)
  );
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_prodnet_recordcount</obj_name>
  <obj_hashval>6cc4caf316d15181f9847ea8c20d8807</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_prodnet_recordcount(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 03.03.2023
  SELECT COUNT(1) INTO wme_result
  FROM PRODNET
  WHERE AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE_IS_DIRTY_DOC(71, CODPRODNET) = 1;

  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_reg_recordcount</obj_name>
  <obj_hashval>e822659d3c4469423465b2897c75f41a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_reg_recordcount(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 03.03.2023
  SELECT COUNT(1) INTO wme_result
  FROM REG
  WHERE TIPREG = 46 AND AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE_IS_DIRTY_DOC(TIPREG, CODREG) = 1;

  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_regoss_for_jurnal</obj_name>
  <obj_hashval>cff3c6aa6d39dc133a12d278a3c2a813</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_regoss_for_jurnal(startrec numeric, endrec numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
    REG1CONT_IDX_LOCAL  NUMERIC(10) := 0;
   REG1_IDX_LOCAL     NUMERIC(20);
   PARAM_REG_DATA     DATE;
   PARAM_REG_MONEDA   NUMERIC(20);
   PARAM_REG_CURS     NUMERIC(20,7);
   DIFERENTE          NUMERIC(1) := 0;
   DATANEXTREG        DATE;
   CODNEXTREG         NUMERIC(20);
   AnPrecedentReg     NUMERIC(20);
   LunaPrecedentaReg  NUMERIC(20);
   ATIPCONT           NUMERIC(5) := 0;
   ASEMN              NUMERIC(2) := 1;
   V_REC              record;
BEGIN
  --Stef 03.03.2023
  --Florin 24.11.2022 - sinc. Oracle
   PERFORM pkg_service_EMPTY_DOCUMENTE_FOR_REGOSS();
   INSERT INTO TMP_REGOSS
      (CODREGOSS,TIPREG,NRDOC,DATADOC,TRIMESTRUL,CODMONEDA,CURS,DIRTY,OBS,CODSUBUNIT,AN,LUNA,CODGEST,CODANALIZANOD,CODCENTRU,SIMBOLMONEDA)
    SELECT
       CODREGOSS,TIPREG,NRDOC,DATADOC,TRIMESTRUL,CODMONEDA,CURS,DIRTY,OBS,CODSUBUNIT,AN,LUNA,CODGEST,CODANALIZANOD,CODCENTRU,SIMBOLMONEDA
      FROM
      (
        SELECT /*+ cardinality(X,1) */
          ROWNUM RN,
          CODREGOSS,TIPREG,NRDOC,DATADOC,TRIMESTRUL,r.CODMONEDA,CURS,DIRTY,OBS,CODSUBUNIT,AN,LUNA,CODGEST,CODANALIZANOD,CODCENTRU,m.SIMBOL SIMBOLMONEDA
        FROM
          TMP_PKG_GLOBALS X,REGOSS R
          LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = R.CODMONEDA
        WHERE
          TIPREG = 108
          AND AN = X.ANLUCRU
          AND LUNA = X.LUNALUCRU
          AND PKG_SERVICE_IS_DIRTY_DOC(108, R.CODREGOSS) = 1
      ) a_pg
     WHERE
       RN &gt;= STARTREC AND RN &lt;= ENDREC;
    FOR V_REC in (Select * from TMP_REGOSS)
    loop
        INSERT INTO TMP_REGOSS1
          (CODREGOSS1,
           CODREGOSS,
           CODDOC,
           TIPDOC,
           TVADOCVAL,
           TVADOC,
           TVADOCREG,
           CODGEST,
           CONT,
           SEMN,
           CURS,
           SEMNIFICATIE,
           DIFERENTA,
           CODPART,
           DEN_PART,
           DOC,
           SUBUNITATEA)
          select rs1.CODREGOSS1,
                 rs1.CODREGOSS,
                 rs1.CODDOC,
                 rs1.TIPDOC,
                 rs1.TVADOCVAL,
                 rs1.TVADOC,
                 rs1.TVADOCREG,
                 rs1.CODGEST,
                 rs1.CONT,
                 rs1.SEMN,
                 rs1.CURS,
                 rs1.SEMNIFICATIE,
                 rs1.TVADOCREG - rs1.TVADOCVAL,
                 part.codpart,
                 part.den_part,
                 ies.seriadoc||' '||ies.nrdoc||'/'||to_char(ies.datadoc, 'dd.mm.yyyy') as doc,
                 ies.subunitatea
            from REGOSS1 rs1
            join iesiri ies on ies.codies = rs1.coddoc
            join npart part on part.codpart = ies.partener
        where rs1.CODREGOSS = v_rec.CODREGOSS;
    end loop;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_regoss_recordcount</obj_name>
  <obj_hashval>6d35890709bbfafe2fb39fe258903539</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_regoss_recordcount(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 03.03.2023
  SELECT COUNT(1) INTO wme_result
  FROM REGOSS
  WHERE TIPREG = 108 AND AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE_IS_DIRTY_DOC(TIPREG, CODREGOSS) = 1;

  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_regpers_recordcount</obj_name>
  <obj_hashval>c7170c7768bf4042646e2fbede1f1f34</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_regpers_recordcount(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 03.03.2023
  SELECT COUNT(1) INTO wme_result
  FROM REG
  WHERE TIPREG = 47 AND AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE_IS_DIRTY_DOC(TIPREG, CODREG) = 1;

  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_regtrezor_recordcount</obj_name>
  <obj_hashval>db3d4a7d190ef48590c60ebf113dd023</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_regtrezor_recordcount(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 03.03.2023
  SELECT COUNT(1) INTO wme_result
  FROM REG
  WHERE TIPREG = 45 AND AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE_IS_DIRTY_DOC(TIPREG, CODREG) = 1;

  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_trezor_recordcount</obj_name>
  <obj_hashval>7dc09b7550e08b3c32d5eb2b16fc45f3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_trezor_recordcount(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 03.03.2023
  SELECT COUNT(1) INTO wme_result
  FROM TREZOR
  WHERE AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE_IS_DIRTY_DOC(TIPDOC, CODTREZOR) = 1;

  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_gettipjurnal</obj_name>
  <obj_hashval>8ac1e4041a83979d377da6a212f39459</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_gettipjurnal(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  BEGIN
    WME_Result := TO_NUMBER((current_setting('PKG_SERVICE.TIPJURNAL', true)),'999999999999999999');
    RETURN ;
  EXCEPTION WHEN undefined_object THEN
    WME_Result := 0;
    RETURN ;
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_gettnccadouri</obj_name>
  <obj_hashval>c13ec776848055e0010517f98065b157</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_gettnccadouri(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  BEGIN
    WME_Result := TO_NUMBER((current_setting('PKG_SERVICE.tncCadouri', true)),'999999999999999999');
    RETURN ;
  EXCEPTION WHEN undefined_object THEN
    WME_Result := 4;
    RETURN ;
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_gettnccantitate</obj_name>
  <obj_hashval>f5ada24225855a31d42b900ff63fe8ff</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_gettnccantitate(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  BEGIN
    WME_Result := TO_NUMBER((current_setting('PKG_SERVICE.tncCantitate', true)),'999999999999999999');
    RETURN ;
  EXCEPTION WHEN undefined_object THEN
    WME_Result := 3;
    RETURN ;
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_gettncpenalizari</obj_name>
  <obj_hashval>43c720db809aae7ad0101d19accb1398</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_gettncpenalizari(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  BEGIN
    WME_Result := TO_NUMBER((current_setting('PKG_SERVICE.tncPenalizari', true)),'999999999999999999');
    RETURN ;
  EXCEPTION WHEN undefined_object THEN
    WME_Result := 6;
    RETURN ;
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_gettncprovizioane</obj_name>
  <obj_hashval>e697b11e1127dfb59e83573d6f8d3128</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_gettncprovizioane(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  BEGIN
    WME_Result := TO_NUMBER((current_setting('PKG_SERVICE.tncProvizioane', true)),'999999999999999999');
    RETURN ;
  EXCEPTION WHEN undefined_object THEN
    WME_Result := 5;
    RETURN ;
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_gettnctermen</obj_name>
  <obj_hashval>fdde90d11440a1da79a67e5786e8dc4b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_gettnctermen(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  BEGIN
    WME_Result := TO_NUMBER((current_setting('PKG_SERVICE.tncTermen', true)),'999999999999999999');
    RETURN ;
  EXCEPTION WHEN undefined_object THEN
    WME_Result := 1;
    RETURN ;
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_gettncvolum</obj_name>
  <obj_hashval>4923c17121fafcccea93a9bbcea827b8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_gettncvolum(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  BEGIN
    WME_Result := TO_NUMBER((current_setting('PKG_SERVICE.tncVolum', true)),'999999999999999999');
    RETURN ;
  EXCEPTION WHEN undefined_object THEN
    WME_Result := 2;
    RETURN ;
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_hiword</obj_name>
  <obj_hashval>246137c03cf49ab6349c4bd52685db41</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_hiword(INOUT wme_result numeric, INOUT nr numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aNr numeric;
begin
  BEGIN
    SELECT trunc( Nr / power( 2, 16)) INTO aNr;
  EXCEPTION WHEN others THEN
    aNr := 0;
  END;

  WME_Result :=  aNr;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_indexare_extensii</obj_name>
  <obj_hashval>dd87dd613d19a1f0dbe3755d157a1e33</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_indexare_extensii()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  IF  (SELECT PKG_LIST_STRUCT_TmpExists.WME_RESULT FROM PKG_LIST_STRUCT_TmpExists(NULL, 'COMANDC')) = 1 THEN
    BEGIN
      EXECUTE 'DROP INDEX IDX_COMANDC_CODCOMANDC';
    EXCEPTION WHEN OTHERS THEN
      NULL;
    END;

    EXECUTE 'CREATE INDEX IDX_COMANDC_CODCOMANDC ON COMANDC(CODCOMANDC)';

    BEGIN
      EXECUTE 'DROP INDEX IDX_COMANDC_CODCOMANDA';
    EXCEPTION WHEN OTHERS THEN
      NULL;
    END;

    EXECUTE 'CREATE INDEX IDX_COMANDC_CODCOMANDA ON COMANDC(CODCOMANDA)';
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_is_dirty_doc</obj_name>
  <obj_hashval>0ed07ab53ab35a93d80b88dec2e72082</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_is_dirty_doc(atipdoc numeric, acoddoc numeric, atipdoc1 numeric DEFAULT 0)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
DECLARE
  NR numeric := 0;
BEGIN
  --Stef 03.03.2023
  RETURN
    CASE
      WHEN current_setting('PKG_SERVICE.TIPJURNAL', true)::numeric = 0                                        THEN 1
      WHEN                  EXISTS (SELECT 1 FROM TMP_DOC_DIRTY WHERE CODDOC = aCODDOC AND TIPDOC = aTIPDOC)  THEN 1
      WHEN aTIPDOC1 &gt; 0 AND EXISTS (SELECT 1 FROM TMP_DOC_DIRTY WHERE CODDOC = aCODDOC AND TIPDOC = aTIPDOC1) THEN 1
      ELSE 0
    END;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_loword</obj_name>
  <obj_hashval>3b21b5bb4404fdf75e3ebf0fdb337362</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_loword(INOUT wme_result numeric, INOUT nr numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aNr numeric;
begin
  BEGIN
    SELECT Nr - trunc( Nr / power( 2, 16)) * power( 2, 16) INTO aNr;
  EXCEPTION WHEN others THEN
    aNr := 0;
  END;

  WME_Result :=  aNr;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_make_manevra_dirty_docs</obj_name>
  <obj_hashval>7465a8b3e5fba72fb845f42df257268b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_make_manevra_dirty_docs()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_DOC_DIRTY;
  INSERT INTO TMP_DOC_DIRTY
  (SELECT CODDOC, TIPDOC FROM JURNAL1 WHERE DIRTY &gt; 0 AND  AN * 12 + LUNA = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X));
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_repartizare_solduri_rulaje</obj_name>
  <obj_hashval>17890f23fe64d994b6506e4f035aa5d6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_repartizare_solduri_rulaje(asubunit numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  ANI   numeric := 0;
  LUNAI numeric := 0;
  NR    numeric := 0;
begin
  SELECT ANINITIAL, LUNAINITIALA INTO ANI, LUNAI FROM FIRMALUNI;

  FOR V_REC IN (SELECT * FROM NCONTSOLD WHERE AN = ANI AND  LUNA = 1) LOOP
    DELETE FROM NCONTSOLDSUB WHERE CODCONTSOLD = V_REC.CODCONTSOLD;

    INSERT INTO NCONTSOLDSUB(CODCONTSOLDSUB, CODCONTSOLD, SUBUNITATEA, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP)
    VALUES(NEXTVAL('SEQ_NCONTSOLDSUB_CODSOLDSUB'), V_REC.CODCONTSOLD, aSUBUNIT, V_REC.SOLDID, V_REC.SOLDIC, V_REC.SOLDVID, V_REC.SOLDVIC, V_REC.SOLDI_IFRS, V_REC.SOLDVI_IFRS, V_REC.SOLDI_GRUP, V_REC.SOLDVI_GRUP);
  END LOOP;

  FOR V_REC IN (SELECT * FROM NCONTRUL WHERE AN = ANI AND  LUNA = LUNAI) LOOP
    UPDATE NCONTRULSUB
    SET
    RULAJPD      = 0,
    RULAJPC      = 0,
    RULAJVPD     = 0,
    RULAJVPC     = 0,
    RULAJP_IFRS  = 0,
    RULAJVP_IFRS = 0,
    RULAJP_GRUP  = 0,
    RULAJVP_GRUP = 0
    WHERE
     CODCONTRUL = V_REC.CODCONTRUL;

    SELECT COUNT( *) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC.CODCONTRUL AND  SUBUNITATEA = aSUBUNIT;

    IF  NR = 0 THEN
      INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, SUBUNITATEA, RULAJPD, RULAJPC, RULAJVPD, RULAJVPC, RULAJCD, RULAJCC, RULAJVCD, RULAJVCC, RULAJP_IFRS, RULAJVP_IFRS, RULAJC_IFRS, RULAJVC_IFRS, RULAJP_GRUP, RULAJVP_GRUP, RULAJC_GRUP, RULAJVC_GRUP)
      VALUES(NEXTVAL('SEQ_NCONTRULSUB_CODRULSUB'), V_REC.CODCONTRUL, aSUBUNIT, V_REC.RULAJPD, V_REC.RULAJPC, V_REC.RULAJVPD, V_REC.RULAJVPC, 0, 0, 0, 0, V_REC.RULAJP_IFRS, V_REC.RULAJVP_IFRS, 0, 0, V_REC.RULAJP_GRUP, V_REC.RULAJVP_GRUP, 0, 0);
    ELSE
      UPDATE NCONTRULSUB
      SET
      RULAJPD      = V_REC.RULAJPD,
      RULAJPC      = V_REC.RULAJPC,
      RULAJVPD     = V_REC.RULAJVPD,
      RULAJVPC     = V_REC.RULAJVPC,
      RULAJP_IFRS  = COALESCE( V_REC.RULAJP_IFRS, 0),
      RULAJVP_IFRS = COALESCE( V_REC.RULAJVP_IFRS, 0),
      RULAJP_GRUP  = COALESCE( V_REC.RULAJP_GRUP, 0),
      RULAJVP_GRUP = COALESCE( V_REC.RULAJVP_GRUP, 0)
      WHERE
       CODCONTRUL = V_REC.CODCONTRUL AND  SUBUNITATEA = aSUBUNIT;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_set_tip_refacere_jurnal</obj_name>
  <obj_hashval>33b788a4e6e2b676940558141204e32a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_set_tip_refacere_jurnal(tip numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  perform set_config('PKG_SERVICE.TIPJURNAL',to_char(TIP,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_settipjurnal</obj_name>
  <obj_hashval>88e5ff527cf9a61a4661878a76d82b61</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_settipjurnal(atipjurnal numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  perform set_config('PKG_SERVICE.TIPJURNAL',to_char(aTIPJURNAL,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_settnccadouri</obj_name>
  <obj_hashval>9754d47a9d8186814c307ac5c3809b5c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_settnccadouri(atnccadouri numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  perform set_config('PKG_SERVICE.tncCadouri',to_char(atncCadouri,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_settncprovizioane</obj_name>
  <obj_hashval>35b18d1f5dce4fdc7c86b94846c6d283</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_settncprovizioane(atncprovizioane numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  perform set_config('PKG_SERVICE.tncProvizioane',to_char(atncProvizioane,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_settnctermen</obj_name>
  <obj_hashval>edc92fd98972146fea1b6bb13808d06a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_settnctermen(atnctermen numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  perform set_config('PKG_SERVICE.tncTermen',to_char(atncTermen,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_settncvolum</obj_name>
  <obj_hashval>5508855d0b33d9cadf0c05a0aba165e5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_settncvolum(atncvolum numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  perform set_config('PKG_SERVICE.tncVolum',to_char(atncVolum,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_tipjurnal</obj_name>
  <obj_hashval>70a95d6d6e0f6068fcee2f3499f20a3f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_tipjurnal(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  BEGIN
    WME_Result := TO_NUMBER((current_setting('PKG_SERVICE.TIPJURNAL', true)),'999999999999999999');
    RETURN ;
  EXCEPTION WHEN undefined_object THEN
    WME_Result := 0;
    RETURN ;
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_tnccadouri</obj_name>
  <obj_hashval>dc9dfa7a34b2560182d467f6e4d9b7dd</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_tnccadouri(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  BEGIN
    WME_Result := TO_NUMBER((current_setting('PKG_SERVICE.tncCadouri', true)),'999999999999999999');
    RETURN ;
  EXCEPTION WHEN undefined_object THEN
    WME_Result := 4;
    RETURN ;
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_tnccantitate</obj_name>
  <obj_hashval>31e34f3fb18afbb66c52f9eb78307f83</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_tnccantitate(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  BEGIN
    WME_Result := TO_NUMBER((current_setting('PKG_SERVICE.tncCantitate', true)),'999999999999999999');
    RETURN ;
  EXCEPTION WHEN undefined_object THEN
    WME_Result := 3;
    RETURN ;
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_tncpenalizari</obj_name>
  <obj_hashval>1a98968b03f2963d3017ba6a2d1f301a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_tncpenalizari(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  BEGIN
    WME_Result := TO_NUMBER((current_setting('PKG_SERVICE.tncPenalizari', true)),'999999999999999999');
    RETURN ;
  EXCEPTION WHEN undefined_object THEN
    WME_Result := 6;
    RETURN ;
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_tncprovizioane</obj_name>
  <obj_hashval>2383f57c09e9c8eca04e229d24f0449c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_tncprovizioane(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  BEGIN
    WME_Result := TO_NUMBER((current_setting('PKG_SERVICE.tncProvizioane', true)),'999999999999999999');
    RETURN ;
  EXCEPTION WHEN undefined_object THEN
    WME_Result := 5;
    RETURN ;
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_tnctermen</obj_name>
  <obj_hashval>2a17793b15a35bd1accbd606b77f637c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_tnctermen(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  BEGIN
    WME_Result := TO_NUMBER((current_setting('PKG_SERVICE.tncTermen', true)),'999999999999999999');
    RETURN ;
  EXCEPTION WHEN undefined_object THEN
    WME_Result := 1;
    RETURN ;
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_tncvolum</obj_name>
  <obj_hashval>cc529bae9b3a16763415ecbfc505dae1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_tncvolum(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  BEGIN
    WME_Result := TO_NUMBER((current_setting('PKG_SERVICE.tncVolum', true)),'999999999999999999');
    RETURN ;
  EXCEPTION WHEN undefined_object THEN
    WME_Result := 2;
    RETURN ;
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_unlock_user_records</obj_name>
  <obj_hashval>c47c328597a162996e30ac04984ab087</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_unlock_user_records()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
begin
  DELETE FROM CMDCANTLOCK  WHERE USERID = (SELECT USERID FROM TMP_PKG_GLOBALS X);
  DELETE FROM DOCLOCK      WHERE USERID = (SELECT USERID FROM TMP_PKG_GLOBALS X);
  DELETE FROM NRBONLOCK    WHERE USERID = (SELECT USERID FROM TMP_PKG_GLOBALS X);
  DELETE FROM NRINVLOCK    WHERE USERID = (SELECT USERID FROM TMP_PKG_GLOBALS X);
  DELETE FROM OBLIGPIFLOCK WHERE USERID = (SELECT USERID FROM TMP_PKG_GLOBALS X);
  DELETE FROM STOCLOCK     WHERE USERID = (SELECT USERID FROM TMP_PKG_GLOBALS X);
  DELETE FROM STOCLOCKEMUL WHERE USERID = (SELECT USERID FROM TMP_PKG_GLOBALS X);

  UPDATE COMANDA SET USERIDBLOCAJ = NULL WHERE USERIDBLOCAJ = (SELECT USERID FROM TMP_PKG_GLOBALS X);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_servpost_ct_monitor</obj_name>
  <obj_hashval>032c00a7b813876982d53550c153cdd3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_servpost_ct_monitor(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_SERVPOST.CT_MONITOR'));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 'MON_59';
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_servpost_getct_monitor</obj_name>
  <obj_hashval>7d1d5e26c058bc4206507c2e840f52f1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_servpost_getct_monitor(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_SERVPOST.CT_MONITOR'));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 'MON_59';
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_servpost_setct_monitor</obj_name>
  <obj_hashval>a077211dff8718d82450980f34619575</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_servpost_setct_monitor(act_monitor character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SERVPOST.CT_MONITOR',aCT_MONITOR,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_servpost_sp_deleterecord</obj_name>
  <obj_hashval>00688cbb01ceace55b544bad2142a64f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_servpost_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aDoc varchar;
BEGIN
  --Florin 01.06.2023 - monitor
  --Florin 31.10.2020
  --Florin 23.03.2021 - pkg_userfirme_postlogcucommit
  perform pkg_servpost_setct_monitor('MON_59');
  PERFORM PKG_SERVPOST_SP_LockRecord( RecId);

  IF (SELECT wme_result FROM PKG_USERFIRME_ValidPostLog(NULL, current_setting('PKG_GLOBALS.USERID', TRUE)::NUMERIC, current_setting('PKG_SERVPOST.CT_MONITOR', TRUE)))
  THEN
    SELECT 'Serviciu Pst Vanzare "' || denserviciu || '"' INTO aDoc FROM ServPost WHERE codserviciu = recid;
    PERFORM pkg_userfirme_postlogcucommit('ServPost', current_setting('PKG_GLOBALS.USERNAME', TRUE), 'S', RECID, current_setting('PKG_GLOBALS.FIRMANAME', TRUE), current_setting('PKG_GLOBALS.SUBUNITATE', TRUE)::NUMERIC, null, aDoc, null, (SELECT WME_RESULT FROM PKG_GLOBALS_GET_EXE_VERSION(NULL,NULL)));
  END IF;

  DELETE FROM ServPost WHERE CodServiciu = RecId;

  PERFORM NotifyModif( 2, RecId, 'SERVPOST');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_servpost_sp_gotorecord</obj_name>
  <obj_hashval>ae25f7ef57d72673f3bfe9cc1ce2cd60</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_servpost_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 16.11.2021 - fixat 52001
  perform pkg_servpost_setct_monitor('MON_59');
  INSERT INTO Tmp_ServPost(CodServiciu, DenServiciu, CodObiect, Tarif, Denumire)
  (SELECT SP.CodServiciu, SP.DenServiciu, SP.CodObiect, SP.Tarif, OBJ.DENUMIRE
   FROM ServPost SP INNER JOIN NARTOBJ OBJ ON  SP.CodObiect = OBJ.CODOBIECT
   WHERE SP.CodServiciu = RecId
  );
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_servpost_sp_lockrecord</obj_name>
  <obj_hashval>cc4787484b0ede7c463e13a13dc7229c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_servpost_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CodServiciu INTO Tmp FROM ServPost WHERE CodServiciu = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_servpost_sp_postrecords</obj_name>
  <obj_hashval>7ad46a52b9709ba013ba0d30f9007806</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_servpost_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aDoc varchar;
BEGIN
  --Florin 01.06.2023 - monitor
  --Bogdan 05.08.2022 - 55142 PG - Nomencator - Concurenti / servicii post-vanzare -eroare salvare   pkg_userfirme_postlogcucommit
  --Florin 31.10.2020 - fixat #40764
  --Florin 23.03.2021 - pkg_userfirme_postlogcucommit
  perform pkg_servpost_setct_monitor('MON_59');
  IF  Operation = 0 THEN
    SELECT CodServiciu INTO RecId FROM Tmp_ServPost;

    IF (SELECT wme_result FROM PKG_USERFIRME_ValidPostLog(NULL, current_setting('PKG_GLOBALS.USERID', TRUE)::NUMERIC, current_setting('PKG_SERVPOST.CT_MONITOR', TRUE)))
    THEN
      SELECT 'Serviciu Pst Vanzare "' || denserviciu || '"' INTO aDoc FROM ServPost WHERE codserviciu = recid;
      PERFORM pkg_userfirme_postlogcucommit('ServPost', current_setting('PKG_GLOBALS.USERNAME', TRUE), 'M', RECID, current_setting('PKG_GLOBALS.FIRMANAME', TRUE), current_setting('PKG_GLOBALS.SUBUNITATE', TRUE)::numeric, null, aDoc, null, (SELECT WME_RESULT FROM PKG_GLOBALS_GET_EXE_VERSION(NULL,NULL)));
    END IF;

    UPDATE ServPost
    SET
    (CodServiciu, DenServiciu, CodObiect, Tarif) = (SELECT CodServiciu, DenServiciu, CodObiect, Tarif FROM Tmp_ServPost)
    WHERE
     CodServiciu = RecId;
  ELSE
    SELECT NEXTVAL('SEQ_SERVPOST_CODSERVICIU') INTO RecId;

    INSERT INTO ServPost(CodServiciu, DenServiciu, CodObiect, Tarif)
    (SELECT RecId, DenServiciu, CodObiect, Tarif FROM Tmp_ServPost);

    IF (SELECT wme_result FROM PKG_USERFIRME_ValidPostLog(NULL, current_setting('PKG_GLOBALS.USERID', TRUE)::NUMERIC, current_setting('PKG_SERVPOST.CT_MONITOR', TRUE)))
    THEN
      SELECT 'Serviciu Pst Vanzare "' || denserviciu || '"' INTO aDoc FROM ServPost WHERE codserviciu = recid;
      PERFORM pkg_userfirme_postlogcucommit('ServPost', current_setting('PKG_GLOBALS.USERNAME', TRUE), 'M', RECID, current_setting('PKG_GLOBALS.FIRMANAME', TRUE), current_setting('PKG_GLOBALS.SUBUNITATE', TRUE)::numeric, null, aDoc, null, (SELECT WME_RESULT FROM PKG_GLOBALS_GET_EXE_VERSION(NULL,NULL)));
    END IF;
  END IF;

  PERFORM NotifyModif( Operation, RecId, 'SERVPOST');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_setliste_sp_deleterecord</obj_name>
  <obj_hashval>fb9a27f73b6daf61b6b4658668dc70d6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_setliste_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_SETLISTE_SP_LOCKRECORD( RecId);
  DELETE FROM WINMADMIN.SETUSERS WHERE CODSET = RecId;
  DELETE FROM WINMADMIN.Setliste WHERE CodSet = RecId;
  PERFORM NotifyModif( 2, RecId, 'WINMADMIN.SETLISTE');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_setliste_sp_gotorecord</obj_name>
  <obj_hashval>444ab15db95fae885010f64eeec76629</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_setliste_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 17.12.2024 - fixat 64306
  INSERT INTO TMP_SETLISTE(CodSet, Denumire, DEDICAT)
  (SELECT CodSet, Denumire, DEDICAT FROM WINMADMIN.SETLISTE WHERE CodSet = RecId);

  INSERT INTO TMP_SETUSERS (CODSETUSERS, CODSET, CODUSER, USERNAME)
  (SELECT
     CODSETUSERS, CODSET, CODUSER,
     (SELECT t.USERNAME FROM Tmp_Utilizator t WHERE t.codutilizator = D.CODUSER) USERNAME
   FROM WINMADMIN.SETUSERS D WHERE CODSET = RecId and CODUSER &gt; 0);

  INSERT INTO TMP_SETGROUPS (CODSETUSERS, CODSET, CODUSER, USERNAME)
  (SELECT
     CODSETUSERS, CODSET, -CODUSER,
     (SELECT t.DENGRUPUSER FROM
     WinMADMIN.grupuser t WHERE t.CODGRUPUSER = -D.CODUSER) USERNAME
   FROM WINMADMIN.SETUSERS D WHERE CODSET = RecId and CODUSER &lt; 0) ;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_setliste_sp_insertrecord</obj_name>
  <obj_hashval>7c12b6c41934428fff5a814e5b3fb111</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_setliste_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_SETLISTE (CodSet) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_setliste_sp_lockrecord</obj_name>
  <obj_hashval>9fa1af692b446ee9c6d1a29b84c73509</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_setliste_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CodSet INTO Tmp FROM WINMADMIN.Setliste WHERE CodSet = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_setliste_sp_postrecords</obj_name>
  <obj_hashval>4c09f52633441f4c2797af4f640d9d13</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_setliste_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
BEGIN
  --Florin 09.12.2024 - sinc. Oracle
  --Florin 19.01.2021 - fixat 41830
  IF  Operation = 0 THEN
    SELECT CodSet INTO RecId FROM TMP_SETLISTE;

    DELETE FROM WINMADMIN.SETUSERS WHERE CODSET = RECID AND CODSETUSERS NOT IN (SELECT CODSETUSERS FROM TMP_SETUSERS)
                                                        AND CODSETUSERS NOT IN (SELECT CODSETUSERS FROM TMP_SETGROUPS);

    UPDATE WINMADMIN.SETLISTE
    SET
    (Denumire, DEDICAT) = (SELECT Denumire, DEDICAT FROM TMP_SETLISTE)
    WHERE CodSet = RecId;

    FOR v_rec IN (SELECT * FROM TMP_SETUSERS WHERE COALESCE(CODUSER, 0) &gt; 0) LOOP
      IF  V_REC.CODSETUSERS &lt; 0 THEN
        INSERT INTO WINMADMIN.SETUSERS(CODSETUSERS, CODSET, CODUSER)
        VALUES(NEXTVAL('SEQ_SETUSERS_CODSETUSERS'), RECID, V_REC.CODUSER);
      ELSE
        UPDATE WINMADMIN.SETUSERS
        SET
        CODSET  = V_REC.CODSET,
        CODUSER = V_REC.CODUSER
        WHERE
         CODSETUSERS = V_REC.CODSETUSERS;
      END IF;
    END LOOP;

    FOR v_rec IN (SELECT * FROM TMP_SETGROUPS WHERE COALESCE(CODUSER, 0) &gt; 0) LOOP
      IF  V_REC.CODSETUSERS &lt; 0 THEN
        INSERT INTO WINMADMIN.SETUSERS(CODSETUSERS, CODSET, CODUSER)
        VALUES(NEXTVAL('SEQ_SETUSERS_CODSETUSERS'), RECID, -V_REC.CODUSER);
      ELSE
        UPDATE WINMADMIN.SETUSERS
        SET
        CODSET  = V_REC.CODSET,
        CODUSER = -V_REC.CODUSER
        WHERE
         CODSETUSERS = V_REC.CODSETUSERS;
      END IF;
    END LOOP;
  ELSE
    SELECT NEXTVAL('Seq_Setliste_Codset') INTO RecId;

    INSERT INTO WINMADMIN.SETLISTE(CodSet, Denumire, DEDICAT)
    (SELECT RecId, Denumire, DEDICAT FROM TMP_SETLISTE);

    INSERT INTO WINMADMIN.SETUSERS(CODSETUSERS, CODSET, CODUSER)
    (SELECT NEXTVAL('SEQ_SETUSERS_CODSETUSERS'), RECID, CODUSER FROM TMP_SETUSERS);

    INSERT INTO WINMADMIN.SETUSERS(CODSETUSERS, CODSET, CODUSER)
    (SELECT NEXTVAL('SEQ_SETUSERS_CODSETUSERS'), RECID, -CODUSER FROM TMP_SETGROUPS);
  END IF;

  PERFORM NotifyModif(Operation, RecId, 'WINMADMIN.SETLISTE');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_setluni_creazalunamaxima</obj_name>
  <obj_hashval>4fc8514d44aec446441ef4b64df8c27f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_setluni_creazalunamaxima(an numeric, luna numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Nr    numeric;
  UnAn  numeric;
  OLuna numeric;
begin
  Nr := 0;
  SELECT count( *) INTO nr FROM FIRMALUNI;

  IF  nr = 0 THEN
    INSERT INTO FIRMALUNI values (0, 0, 0, 0, An, Luna, 0, 0);
  ELSE
    UnAn  := 0;
    OLuna := 0;
    SELECT AnMaxim, LunaMaxima INTO UnAn, OLuna FROM FIRMALUNI;

    IF  UnAn * 12 + OLuna &lt; An * 12 + Luna THEN
      UPDATE FIRMALUNI
      SET
        AnMaxim    = An,
        LunaMaxima = Luna;
    END IF;
  END IF;

  perform set_config('PKG_GLOBALS.AnMaxim'   ,An::varchar  ,false);
  perform set_config('PKG_GLOBALS.LunaMaxima',Luna::varchar,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_setluni_getlunacurenta</obj_name>
  <obj_hashval>102e9002d454f84b6046c35bb4b28080</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_setluni_getlunacurenta(INOUT an numeric, INOUT luna numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  --Bogdan 02.09.2020
  An   := 0;
  Luna := 0;
  SELECT AnCurent, LunaCurenta INTO An, Luna FROM FIRMALUNI;

  perform set_config('PKG_GLOBALS.AnCurent'   ,An::varchar  ,false);
  perform set_config('PKG_GLOBALS.LunaCurenta',Luna::varchar,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_setluni_getlunainitiala</obj_name>
  <obj_hashval>79d68f47f241699fb41f5cadd6e6e05b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_setluni_getlunainitiala(INOUT an numeric, INOUT luna numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  --Bogdan 02.09.2020
  An   := 0;
  Luna := 0;
  SELECT AnInitial, LunaInitiala  INTO An, Luna FROM FIRMALUNI;

  perform set_config('PKG_GLOBALS.AnInitial'   ,An::varchar  ,false);
  perform set_config('PKG_GLOBALS.LunaInitiala',Luna::varchar,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_setluni_getlunamaxima</obj_name>
  <obj_hashval>7a74b06e6a3a4a9d22838117e2affb84</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_setluni_getlunamaxima(INOUT an numeric, INOUT luna numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  --Bogdan 02.09.2020
  An   := 0;
  Luna := 0;

  SELECT AnMaxim, LunaMaxima  INTO An, Luna FROM FIRMALUNI;

  perform set_config('PKG_GLOBALS.AnMaxim'   ,An::varchar  ,false);
  perform set_config('PKG_GLOBALS.LunaMaxima',Luna::varchar,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_setluni_setlunacurenta</obj_name>
  <obj_hashval>1f55548fcb048fd189434837922e8c92</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_setluni_setlunacurenta(an numeric, luna numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Nr numeric;
begin
  --Bogdan 02.09.2020
  Nr := 0;
  SELECT count( *) INTO nr FROM FIRMALUNI;

  IF  nr = 0   THEN
    INSERT INTO FIRMALUNI VALUES  (An, Luna, 0, 0, 0, 0, 0, 0  );
  ELSE
    UPDATE FIRMALUNI
    SET
      AnCurent    = An,
      LunaCurenta = Luna  ;
  END IF;

  PERFORM PKG_SETLUNI_SetLunaMaxima( An, Luna);

  perform set_config('PKG_GLOBALS.AnCurent'   ,An::varchar  ,false);
  perform set_config('PKG_GLOBALS.LunaCurenta',Luna::varchar,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_setluni_setlunainitiala</obj_name>
  <obj_hashval>5b03cda4b33736d94038ec509c2cd4d6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_setluni_setlunainitiala(an numeric, luna numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Nr numeric;
begin
  --Bogdan 02.09.2020
  Nr := 0;
  SELECT count(*) INTO nr FROM FIRMALUNI;
  IF  nr = 0 THEN
    INSERT INTO FIRMALUNI VALUES(0, 0, An, Luna, 0, 0, 0, 0);
  ELSE
    UPDATE FIRMALUNI SET AnInitial = An, LunaInitiala = Luna;
  END IF;
  PERFORM PKG_SETLUNI_SetLunaMaxima( An, Luna);

  PERFORM set_config('PKG_GLOBALS.AnInitial'   ,An::varchar  ,false);
  PERFORM set_config('PKG_GLOBALS.LunaInitiala',Luna::varchar,false);
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_setluni_setlunamaxima</obj_name>
  <obj_hashval>b811672a7ec5f107987965905f5efd7e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_setluni_setlunamaxima(an numeric, luna numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Nr    numeric;
  UnAn  numeric;
  OLuna numeric;
begin
  --Bogdan 02.09.2020
  Nr := 0;
  SELECT count( *) INTO nr FROM FIRMALUNI;
  IF  nr = 0 THEN
    INSERT INTO FIRMALUNI VALUES  (0, 0, 0, 0, An, Luna, 0, 0);
  ELSE
    UnAn  := 0;
    OLuna := 0;
    SELECT AnMaxim, LunaMaxima  INTO UnAn, OLuna FROM FIRMALUNI;
    IF  UnAn * 12 + OLuna &lt; An * 12 + Luna  THEN
      UPDATE FIRMALUNI
      SET
        AnMaxim    = An,
        LunaMaxima = Luna;
    END IF;
  END IF;

  perform set_config('PKG_GLOBALS.AnMaxim'   ,An::varchar  ,false);
  perform set_config('PKG_GLOBALS.LunaMaxima',Luna::varchar,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_settask_bagaintasklog</obj_name>
  <obj_hashval>d77706e8c1f2a11266be053fa55fe24e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_settask_bagaintasklog(codlog numeric, codtask numeric, data date, user_src character varying, user_dst character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO SETTASKLOG(CODLOG, CODTASK, DATA, USER_SRC, USER_DST)
  VALUES(CODLOG, CODTASK, DATA, USER_SRC, USER_DST);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_settask_carnetdoc_i</obj_name>
  <obj_hashval>bd3e7432e104e789d984be5a1e7e0dbc</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_settask_carnetdoc_i(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SETTASK.CARNETDOC_I', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_settask_getnrdoc_i</obj_name>
  <obj_hashval>4f2da03891851a2accd2596f363976ac</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_settask_getnrdoc_i(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SETTASK.NRDOC_I', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_settask_import_date</obj_name>
  <obj_hashval>bb3874144f285bc4b95bd3006ae4e61f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_settask_import_date()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vCod          numeric;
  vVal          double precision;
  sAuxObs       varchar;
  aCodSubunit   numeric;
  aCodOferta    numeric;
  aCodPart      numeric;
  aPos          numeric;
  sConstructor  varchar;
  aCodPers      numeric;
  vDataCreare   date;
  aDataA        date;
  aDataC        date;
  aCodPart3     numeric;
  aCodPart1     numeric;
  aCodPart2     numeric;
  aCodPartP     numeric;
  aJudP         numeric;
  aJudC         numeric;
  sConstructor1 varchar;
  sProiectant1  varchar;
  sBeneficiar1  varchar;
begin
  aPos := 0;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_settask_importxls</obj_name>
  <obj_hashval>7edbf534e915db2e22a6e84f906df469</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_settask_importxls(asubunitate character varying, aresponsabil character varying, aproblema character varying, adatacreare character varying, aconstructor character varying, ajudet_c character varying, aproiectant character varying, anrproiect character varying, aproiect character varying, ajudet_p character varying, astadiu character varying, abeneficiar character varying, aaregeo character varying, avaloare character varying, anroferta character varying, adataoferta character varying, adatacontact character varying, adatact character varying, acomentarii character varying, aobservatii character varying, advobservatii character varying, acastigator character varying, aactiuni character varying, aforecast character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aAux varchar;
begin
  aAux := '';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_settask_nrdoc_i</obj_name>
  <obj_hashval>c2ce8154f2d4022fb03e1bfba0034adf</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_settask_nrdoc_i(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SETTASK.NRDOC_I', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_settask_objexists</obj_name>
  <obj_hashval>0072e875cb15c23f450f64b268070660</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_settask_objexists(INOUT wme_result numeric, INOUT tmpname character varying, INOUT tip character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  SIR     varchar;
  sResult numeric;
begin
  IF  Tip = 'TABLE' THEN
    SIR := 'SELECT COUNT(*) FROM ' || TMPNAME;

    BEGIN
      EXECUTE SIR;
      sResult := 1;
    EXCEPTION WHEN others THEN
      sResult := 0;
    END;
  END IF;

  IF  Tip = 'SEQUENCE' THEN
    BEGIN
      EXECUTE 'ALTER SEQUENCE ' || TMPNAME || ' INCREMENT BY 1';
      sResult := 1;
    EXCEPTION WHEN OTHERS THEN
      sResult := 0;
    END;
  END IF;

  WME_Result :=  sResult;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_settask_setnrdoc_i</obj_name>
  <obj_hashval>7228de1f2e829ef2a64581d4e8db3e6f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_settask_setnrdoc_i(anrdoc numeric, acarnet numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SETTASK.CARNETDOC_I',to_char(ACARNET,'999999999999999999'),false);
perform set_config('PKG_SETTASK.NRDOC_I',to_char(ANRDOC,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_settask_sp_gotorecord</obj_name>
  <obj_hashval>bb5e82252114c00ab68c04fe4bd7e13b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_settask_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  SKEMA       varchar;
  aCODFIRMA   numeric;
  aCODCOMANDA numeric;
  aCODFACTURA numeric;
  aCODOFERTA  numeric;
  sSql        varchar := ';
    sSqlx       varchar2(100) := ';
  Nr          numeric;
BEGIN
  --Florin 06.01.2021 - sters trunc de la termen
  --Florin 18.03.2021 - fixat 45447
  BEGIN
    SELECT COALESCE( CODFIRMA, 0), COALESCE( CODCOMANDA, 0), COALESCE( CODFACTURA, 0), COALESCE( CODOFERTA, 0)
    INTO aCODFIRMA, aCODCOMANDA, aCODFACTURA, aCODOFERTA
    FROM SETTASK
    WHERE CODTASK = RecId;
  EXCEPTION WHEN OTHERS THEN
    aCODFIRMA   := 0;
    aCODCOMANDA := 0;
    aCODFACTURA := 0;
    aCODOFERTA  := 0;
  END;

  IF  aCODCOMANDA &gt; 0 THEN
    SELECT count( *) INTO NR FROM COMANDA WHERE CODCOMANDA = aCODCOMANDA;

    IF  Nr = 0 THEN
      UPDATE SETTASK SET CODCOMANDA = 0 WHERE CODTASK = RecId;
    END IF;
  END IF;

  IF  aCODFACTURA &gt; 0 THEN
    SELECT count( *) INTO NR FROM IESIRI WHERE CODIES = aCODFACTURA;

    IF  Nr = 0 THEN
      UPDATE SETTASK SET CODFACTURA = 0, FACTURAT = 0 WHERE CODTASK = RecId;
    END IF;
  END IF;

  IF  aCODOFERTA &gt; 0 THEN
    SELECT count( *) INTO NR FROM OFERTA WHERE CODOFERTA = aCODOFERTA;

    IF  Nr = 0 THEN
      UPDATE SETTASK SET CODOFERTA = 0 WHERE CODTASK = RecId;
    END IF;
  END IF;

  INSERT INTO TMP_SETTASK(CODTASK, PROBLEMA, DESTINATAR, EXECUTANT, USERNAME, TERMEN, DATATASK, DATAREZ, DOMENIU, TIP, REZOLVARE, OBSERVATII, PRIORITATE, DONE,
                          MODIFICAT, MESAJCATRE, PROIECT, CODMAIL, CODMSG1, DOMSG, DOMAIL, ZBEFORE, CODFIRMA, SUBUNITATEA, FACTURABIL, FACTURAT, VALOARE,
                          CODMONEDA, CODCOMANDA, CODFACTURA, CODOFERTA, COMANDA, FACTURA, OFERTA, FIRMA, CODPART, CODPERS, CODSERVICIU, CODCONTRACT1, ORATASK,
                          ORAREZ, VERSIUNE, PREFIXDOC, NRDOC, CARNETDOC, SERIADOC, ARTICOLASOCIAT)
  SELECT CODTASK, PROBLEMA, DESTINATAR, EXECUTANT, USERNAME, TERMEN, DATATASK, DATAREZ, DOMENIU, TIP, REZOLVARE, OBSERVATII, PRIORITATE, DONE, MODIFICAT, MESAJCATRE,
         PROIECT, CODMAIL, CODMSG1, DOMSG, DOMAIL, ZBEFORE, S.CODFIRMA, S.SUBUNITATEA, FACTURABIL, FACTURAT, VALOARE, CODMONEDA, CODCOMANDA, CODFACTURA, CODOFERTA,
         CASE WHEN  COALESCE( CODCOMANDA, 0) = 0 THEN '?' ELSE 'Ok' END ,
         CASE WHEN  COALESCE( CODFACTURA, 0) = 0 THEN '?' ELSE 'Ok' END ,
         CASE WHEN  COALESCE( CODOFERTA , 0) = 0 THEN '?' ELSE 'Ok' END ,
         '', CODPART, S.CODPERS, S.CODSERVICIU, S.CODCONTRACT1, TO_CHAR( DATATASK, 'HH24:MI'), TO_CHAR( DATAREZ, 'HH24:MI'), VERSIUNE, S.PREFIXDOC, S.NRDOC,
         S.CARNETDOC, S.SERIADOC, S.ARTICOLASOCIAT
  FROM SETTASK S
  WHERE CODTASK = RecId;

  INSERT INTO TMP_SETTASKOBJ(CODTASKOBJ, CODTASK, CODOBIECT, CANT, NEPRELUABIL, PRET, CODPERS, INDEXLOCAL)
  SELECT S.CODTASKOBJ, S.CODTASK, S.CODOBIECT, S.CANT, COALESCE( S.NEPRELUABIL, 0), S.PRET, S.CODPERS, S.INDEXLOCAL
  FROM SETTASKOBJ S
  WHERE S.CODTASK = RecId AND  COALESCE( S.CODOBIECT, 0) &gt; 0;

  INSERT INTO TMP_SETTASKOBJASOC(CODTASKOBJASOC, CODTASK, CODOBIECT, SERII, CODINTERN, CODIES1, INDEXLOCAL)
  SELECT CODTASKOBJASOC, CODTASK, CODOBIECT, SERII, CODINTERN, CODIES1, INDEXLOCAL
  FROM SETTASKOBJASOC
  WHERE CODTASK = RECID;

  BEGIN
    UPDATE TMP_SETTASK TMP
    SET
    (CODCONTRACT1, CONTRACT) = (SELECT COALESCE( C1.CODCONTRACT1, 0),
                                       CASE WHEN  COALESCE( C.CODCONTRACT, 0) = 0 THEN '?' ELSE c.seriadoc || ' ' || c.nrdoc || '/' || to_char( c.datadoc, 'dd.mm.yyyy') END
                                FROM CONTRACT C INNER JOIN CONTRACT1 C1 ON  C1.CODCONTRACT = C.CODCONTRACT
                                WHERE TMP.CODCONTRACT1 = C1.CODCONTRACT1
                               );
  EXCEPTION WHEN OTHERS THEN
    NULL;
  END;

  BEGIN
    UPDATE TMP_SETTASK TMP
    SET
    (CODCOMANDA, COMANDA) = (SELECT COALESCE( C.CODCOMANDA, 0),
                                    CASE WHEN  COALESCE( C.CODCOMANDA, 0) = 0 THEN '?' ELSE c.PREFIXDOC || ' ' || c.nrdoc || '/' || to_char( c.datadoc, 'dd.mm.yyyy') END
                             FROM COMANDA C
                             WHERE TMP.CODCOMANDA = C.CODCOMANDA
                            );
  EXCEPTION WHEN OTHERS THEN
    NULL;
  END;

  BEGIN
    UPDATE TMP_SETTASK TMP
    SET
    (CODFACTURA, FACTURA) = (SELECT COALESCE( I.CODIES, 0),
                                    CASE WHEN  COALESCE( I.CODIES, 0) = 0 THEN '?' ELSE i.PREFIXDOC || ' ' || i.nrdoc || '/' || to_char( i.datadoc, 'dd.mm.yyyy') END
                             FROM IESIRI I
                             WHERE TMP.CODFACTURA = I.CODIES
                            );
  EXCEPTION WHEN OTHERS THEN
    NULL;
  END;

  BEGIN
    UPDATE TMP_SETTASK TMP
    SET
    CODOBIECT = (SELECT COALESCE( SP.CODOBIECT, 0) FROM SERVPOST SP WHERE SP.CODSERVICIU = TMP.CODSERVICIU);
  EXCEPTION WHEN OTHERS THEN
    NULL;
  END;

  BEGIN
    UPDATE TMP_SETTASKOBJ TMP
    SET
    (CODOBIECT, DEN_OBIECT) = (SELECT COALESCE( O.CODOBIECT, 0), CASE WHEN  COALESCE( O.CODOBIECT, 0) = 0 THEN '?' ELSE O.DENUMIRE END
                               FROM NARTOBJ O WHERE O.CODOBIECT = TMP.CODOBIECT
                              ),
    (CODPERS, PERSOANA)     = (SELECT COALESCE( P.CODPERS, 0), CASE WHEN  COALESCE( P.CODPERS, 0) = 0 THEN '?' ELSE P.NUME || ' ' || P.PRENUME END
                               FROM NPERS P WHERE P.CODPERS = TMP.CODPERS
                              ),
    VALOARE                 = PRET * CANT,
    DEN_UM                  = (SELECT NUM.DEN_UM
                               FROM NARTOBJ O
                                   INNER JOIN NART A ON  O.CODARTICOL = A.CODARTICOL
                                   INNER JOIN NUM    ON  NUM.CODUM    = A.UM
                               WHERE O.CODOBIECT = TMP.CODOBIECT
                              );
  EXCEPTION WHEN OTHERS THEN
    NULL;
  END;

  BEGIN
    UPDATE TMP_SETTASKOBJ TMP
    SET
    (DEN_OBIECT)  = (SELECT O.DENUMIRE FROM NARTOBJ O WHERE O.CODOBIECT = TMP.CodObiect);
  EXCEPTION WHEN OTHERS THEN
    NULL;
  END;

  BEGIN
    UPDATE TMP_SETTASKOBJASOC TMP
    SET
    DENUMIRE = (SELECT O.DENUMIRE FROM NARTOBJ O WHERE O.CODOBIECT = TMP.CODOBIECT);
  EXCEPTION WHEN OTHERS THEN
    NULL;
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_settask_sp_insertrecord</obj_name>
  <obj_hashval>21f1a7fff201f5fd02fcf80d80cc5e7c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_settask_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  INSERT INTO TMP_SETTASK(CODTASK) VALUES (0);
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_settask_sp_lockrecord</obj_name>
  <obj_hashval>6ae914a3089e0ad7292c04ec5c3a05f5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_settask_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CODTASK INTO Tmp FROM SETTASK WHERE CODTASK = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_settask_sp_postrecords</obj_name>
  <obj_hashval>c6f6636f515d81923c6c522c8ab615a0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_settask_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  T              RECORD;
  V_REC          RECORD;
  OLD_MESAJCATRE varchar;
  NEW_MESAJCATRE varchar;
  aSkema         varchar;
  Cati           numeric;
  aDoMSg         numeric;
  aDoMail        numeric;
  aZBefore1      numeric;
  aZBefore2      numeric;
  Old_DoMail     numeric;
  Old_ZBefore2   numeric;
  MSGID          numeric;
  MSGID1         numeric;
  MAILID         numeric;
  aCodPers       numeric;
  aMesajCatre    varchar;
  aUSERNAME      varchar;
  ExecMSG        numeric := 0;
  ExecMail       numeric := 0;
  aMes           varchar(4000);
  aProblema      varchar;
  aDataMail      date;
  aJobName       varchar;
  aTERMEN        date;
  aCITIT         numeric;
  aSTERS         numeric;
  CateErau       numeric;
  aDATA          date;
  aDATAAfis      date;
  aDESTINATAR    varchar;
  aPROIECT       varchar;
  aEMail         varchar;
  vDataRez       timestamp;
  aCARNETDOC     numeric;
  aNRDOC         numeric;
  aCodLink       numeric;
  aTipLink       numeric;
  aCodFirma      numeric;
  ora            varchar;
BEGIN
  --Florin 22.05.2023 - fixat 58383
  --Florin 27.02.2023 - fixat 57382/57386/37387
  --Florin 21.02.2023 - sinc. Oracle
  --Florin 10.02.2023 - fixat 57123
  --Florin 03.02.2022 - fixat 52524
  --Florin 09.01.2021 - fixat 42103
  --Florin 12.01.2021 - fixat 42069
  --Florin 17.03.2021 - fixat 45291
  --Florin 18.03.2021 - fixat 45447
  ExecMSG   := 0;
  aCodFirma := (SELECT WME_RESULT FROM winmadmin.pkg_userfirme_getcodfirma(NULL,NULL));
  aSkema    := (SELECT WME_RESULT FROM winmadmin.PKG_USERFIRME_GetSkemaFirma(NULL, aCodFirma));

  SELECT COALESCE( CodPers, 0), USERNAME, DESTINATAR, PROIECT, TERMEN, REPLACE(Problema, '', '"'), MesajCatre, COALESCE( CodMail, 0),
         COALESCE( CodMSG1, 0), COALESCE( DoMSg, 0), COALESCE( DoMail, 0), CARNETDOC, NRDOC
  INTO aCodPers, aUSERNAME, aDESTINATAR, aPROIECT, aTERMEN, aProblema, aMesajCatre, MailID, MSGID1, aDoMSg, aDoMail, aCARNETDOC, aNRDOC
  FROM TMP_SETTASK;

  SELECT COUNT(*) INTO CateErau FROM WinMAdmin.MESAJE1 WHERE CODMESAJ1 = MSGID1;
  if CateErau = 0 then MSGID1 := 0; end if;

  SELECT COUNT(*) INTO CateErau FROM WinMAdmin.MESAJE1 WHERE CODMESAJ1 = MSGID1;
  if CateErau = 0 then aDoMSg := 0; MSGID1 := 0; end if;

  aMes := 'Task:'||Chr(13)||aProblema ||
          Case when aTermen is NULL OR aTermen::varchar = '' then '' else '; Termen:'||aTermen end||
          Case when aDESTINATAR is NULL OR aDESTINATAR = '' then '' else '; Dest:'||aDESTINATAR end||
          Case when aPROIECT is null OR aPROIECT = '' then '' else '; Proiect:'||aPROIECT end;

  BEGIN
    SELECT CodLink, TipLink INTO aCodLink, aTipLink FROM TMP_SETTASK;
  EXCEPTION WHEN others THEN
    aCodLink := 0;
  END;

  aEMail := '?';
  IF  aCodPers &gt; 0 THEN
    aEMail := (SELECT wme_result FROM WinMAdmin.PKG_UserFirme_GetEMailFromNPers(NULL, aCodPers, aSkema));
  ELSE
    aEMail := (SELECT wme_result FROM WinMAdmin.PKG_UserFirme_GetEMailFromUtilizator(NULL, aMesajCatre));
  END IF;

  IF  aEMail = '?' THEN
    aEMail := aMesajCatre;
  END IF;

  IF  aDoMSg = -2 THEN
    aDoMsg    := 0;
    aZBefore1 := -1;
  ELSE
    IF  aDoMSg = -1 THEN
      aZBefore1 := -1;
    ELSE
      aZBefore1 := aDoMsg;
    END IF;

    aDoMsg := 1;
  END IF;

  IF  aDoMail = -2 THEN
    aDoMail   := 0;
    aZBefore2 := -1;
  ELSE
    IF  aDoMail = -1 THEN
      aZBefore2 := -1;
    ELSE
      aZBefore2 := aDoMail;
    END IF;

    aDoMail := 1;
  END IF;

  IF  Operation = 0 THEN
    SELECT CODTASK INTO RecId FROM TMP_SETTASK;

    IF  MSGID1 = 0 THEN
      ExecMSG := aDoMsg;
    ELSE
      IF  aDOMSG = 0 THEN
        UPDATE WinMAdmin.Mesaje1 SET Sters = 1 WHERE CodMesaj1 = MSGID1;
      ELSE
        SELECT CODMESAJ, TO_USER, CITIT, STERS
        INTO MSGID, OLD_MESAJCATRE, aCITIT, aSTERS
        FROM WinMAdmin.MESAJE1 WHERE CODMESAJ1 = MSGID1;

        SELECT COUNT( *) INTO CateErau FROM WinMAdmin.MESAJE1 WHERE CODMESAJ = MSGID;

        SELECT DATA, DATAAfis INTO aDATA, aDATAAfis FROM WinMAdmin.MESAJE WHERE CODMESAJ = MSGID;

        SELECT MESAJCATRE INTO NEW_MESAJCATRE FROM TMP_SETTASK WHERE CODTASK = RECID;

        IF  UPPER( NEW_MESAJCATRE) &lt;&gt; UPPER( OLD_MESAJCATRE) THEN
          ExecMSG := 1;
        ELSE
          IF  CateErau = 1 THEN
            IF  aData = aDataAfis THEN
              IF  aZBefore1 = -1 THEN
                ExecMSG := 0;
              ELSE
                ExecMSG := 1;
              END IF;
            ELSE
              IF  aCitit = 0 THEN
                UPDATE WinMAdmin.Mesaje SET DataAfis = add_days(aTERMEN, -aZBefore1::INTEGER) WHERE CodMesaj = MSGID;

                ExecMSG := 0;
              ELSE
                ExecMSG := 1;
              END IF;
            END IF;
          ELSE
            IF  aData = aDataAfis THEN
              IF  aZBefore1 = -1 THEN
                ExecMSG := 0;
              ELSE
                ExecMSG := 1;
              END IF;
            ELSE
              UPDATE WinMAdmin.Mesaje1 SET Sters = 1 WHERE CodMesaj1 = MSGID1;
              ExecMSG := 1;
            END IF;
          END IF;
        END IF;
      END IF;
    END IF;

    IF  ExecMsg = 1 THEN
      IF  aZBefore1 = -1 THEN
        aDataMail := current_date;
      ELSE
        aDataMail := add_days(aTERMEN, -aZBefore1::INTEGER);
      END IF;

      SELECT NEXTVAL('WinMAdmin.SEQ_MESAJE_CODMESAJ') INTO MSGID;

      INSERT INTO WinMAdmin.MESAJE(CODMESAJ, TEXT, FROM_USER, SKEMAFIRMA, DATA, TIP_MESAJ, DATAAFIS)
      SELECT MSGID, aMes, USERNAME, aSKEMA, CURRENT_TIMESTAMP, 2, aDataMail
      FROM TMP_SETTASK;

      MSGID1 := NEXTVAL('WinMAdmin.SEQ_MESAJE1_CODMESAJ1');
      INSERT INTO WinMAdmin.MESAJE1(CODMESAJ1, CODMESAJ, TO_USER, STERS, citit)
      VALUES(MSGID1, MSGID, aMesajCatre, 0, 0);
    END IF;

    IF  MailID = 0 THEN
      ExecMail := aDOMail;
    ELSE
      IF  aDoMail = 1 THEN
        SELECT DoMail, ZBefore INTO Old_DoMail, Old_ZBefore2 FROM SETTASK WHERE CODTASK = RECID;

        IF  Old_DoMail = -2 THEN
          Old_DoMail := 0;
          Old_ZBefore2 := -1;
        ELSE
          IF  Old_DoMail = -1 THEN
            Old_ZBefore2 := -1;
          ELSE
            Old_ZBefore2 := Old_DoMail;
          END IF;

          aDoMail := 1;
        END IF;

        IF  Old_DoMail &lt;&gt; aDoMail or  OLD_ZBefore2 &lt;&gt; aZBefore2 THEN
          aJobName := 'Mail' || WinMAdmin.PKG_UserFirme.GETCODFIRMA || '_' || MailID;
          PERFORM dbms_scheduler.Drop_Job( aJobName);
          ExecMail := 1;
        END IF;
      ELSE
        aJobName := 'Mail' || WinMAdmin.PKG_UserFirme.GETCODFIRMA || '_' || MailID;
        PERFORM dbms_scheduler.Drop_Job( aJobName);
      END IF;
    END IF;

    IF  ExecMail = 1 THEN
      IF  aZBefore2 = -1 THEN
        PERFORM WINMADMIN.PKG_USERFIRME_SendEMail(current_date, True, aSkema, aUSERNAME, aEMail, aMes, aPROBLEMA, MAILID);
      ELSE
        aDataMail := add_days(aTERMEN, -aZBefore2::INTEGER);
        PERFORM WINMADMIN.PKG_USERFIRME_SendEMail( aDataMail, False, aSkema, aUSERNAME, aEMail, aMes, aPROBLEMA, MAILID);
      END IF;
    END IF;

    SELECT datarez INTO vDataRez FROM tmp_settask;

    IF  NOT vDataRez IS NULL THEN
      SELECT TO_TIMESTAMP( TO_CHAR( DATAREZ, 'DD.MM.YYYY') || ' ' || CASE WHEN  ORAREZ = '  :  ' THEN '00:00' ELSE ORAREZ END , 'DD.MM.YYYY HH24:MI')
      INTO vDataRez
      FROM tmp_settask;
    END IF;

    UPDATE SETTASK
    SET
    (PROBLEMA, DESTINATAR, EXECUTANT, USERNAME, TERMEN, DATATASK, DATAREZ, DOMENIU, TIP, REZOLVARE, OBSERVATII, PRIORITATE, DONE, MODIFICAT, MESAJCATRE,
     PROIECT, CODMAIL, CODMSG1, DOMSG, DOMAIL, ZBEFORE, CODFIRMA, SUBUNITATEA, FACTURABIL, FACTURAT, VALOARE, CODMONEDA, CODCOMANDA, CODFACTURA, CODOFERTA,
     CODPART, CODPERS, CODSERVICIU, CODCONTRACT1, VERSIUNE, PREFIXDOC, NRDOC, CARNETDOC, SERIADOC, ARTICOLASOCIAT
    )
    =
    (SELECT PROBLEMA, DESTINATAR, EXECUTANT, USERNAME, TERMEN,
            TO_TIMESTAMP( TO_CHAR( DATATASK, 'DD.MM.YYYY') || ' ' || CASE WHEN  ORATASK = '  :  ' THEN '00:00' ELSE oratask END , 'DD.MM.YYYY HH24:MI'),
            vDataRez, DOMENIU, TIP, REZOLVARE, OBSERVATII, PRIORITATE, DONE, MODIFICAT, MESAJCATRE, PROIECT, MAILID, MSGID1, DOMSG, DOMAIL, ZBEFORE,
            aCODFIRMA, SUBUNITATEA, FACTURABIL, FACTURAT, VALOARE, CODMONEDA, CODCOMANDA, CODFACTURA, CODOFERTA, CODPART, CODPERS, CODSERVICIU, CODCONTRACT1,
            VERSIUNE, PREFIXDOC, NRDOC, CARNETDOC, SERIADOC, ARTICOLASOCIAT
     FROM TMP_SETTASK
    )
    WHERE CODTASK = RecId;

    DELETE FROM SETTASKOBJ WHERE CODTASK = RecId AND CODTASKOBJ IN (SELECT CODTASKOBJ FROM TMP_SETTASKOBJ);

    FOR T IN (SELECT codtaskobj, codtask, codobiect, cant, nepreluabil, pret, codpers, indexlocal FROM TMP_SETTASKOBJ) LOOP
      UPDATE  SETTASKOBJ O
       SET CODOBIECT = T.CODOBIECT, CANT = T.CANT, NEPRELUABIL = T.NEPRELUABIL, PRET = T.PRET, CODPERS = T.CODPERS, INDEXLOCAL = T.INDEXLOCAL
      WHERE T.CODTASKOBJ = O.CODTASKOBJ;

      IF NOT FOUND THEN
        INSERT INTO SETTASKOBJ(codtaskobj, codtask, codobiect, cant, nepreluabil, pret, codpers, indexlocal)
        VALUES (NEXTVAL('SEQ_SETTASKOBJ_CODTASKOBJ'), RecId, T.CodObiect, T.Cant, T.Nepreluabil, T.Pret, T.Codpers, T.IndexLocal) ;
      END IF;
    END LOOP;

    DELETE FROM SETTASKOBJASOC WHERE CODTASK = RecId AND CODTASKOBJASOC IN (SELECT CODTASKOBJASOC FROM TMP_SETTASKOBJASOC);

    FOR T IN (SELECT CODTASKOBJASOC, CODTASK, CODOBIECT, SERII, CODINTERN, CODIES1, INDEXLOCAL FROM TMP_SETTASKOBJASOC) LOOP
      UPDATE  SETTASKOBJASOC O
      SET CODTASK = T.CODTASK, CODOBIECT = T.CODOBIECT, SERII = T.SERII, CODINTERN = T.CODINTERN, CODIES1 = T.CODIES1, INDEXLOCAL = T.INDEXLOCAL
      WHERE T.CODTASKOBJASOC = O.CODTASKOBJASOC;


      IF NOT FOUND THEN
        INSERT INTO SETTASKOBJASOC(CODTASKOBJASOC, CODTASK, CODOBIECT, SERII, CODINTERN, CODIES1, INDEXLOCAL)
        VALUES (NEXTVAL('SEQ_STOBJASOC_CODSTOBJASOC'), RECID, T.CODOBIECT, T.SERII, T.CODINTERN, T.CODIES1, T.INDEXLOCAL) ;
      END IF;
    END LOOP;

  ELSE
    SELECT Count( *) INTO Cati FROM TMP_SETTASK1;

    IF  Cati = 0 THEN
      INSERT INTO TMP_SETTASK1(MESAJCATRE, CodPers)
      (SELECT MESAJCATRE, CodPers FROM TMP_SETTASK);
    END IF;

    IF  aDoMSG = 1 THEN
      IF  aZBefore1 = -1 THEN
        aDataMail := CURRENT_TIMESTAMP;
      ELSE
        aDataMail := add_days(aTERMEN, -aZBefore1::INTEGER);
      END IF;

      SELECT NEXTVAL('winmadmin.SEQ_MESAJE_CODMESAJ') INTO MSGID;

      INSERT INTO winmadmin.MESAJE(CODMESAJ, TEXT, FROM_USER, SKEMAFIRMA, DATA, TIP_MESAJ, DATAAFIS)
      SELECT MSGID, aMes, USERNAME, aSKEMA, CURRENT_TIMESTAMP, 2, aDataMail
      FROM TMP_SETTASK;
    END IF;

    MSGID1 := 0;

    FOR v_rec IN (SELECT * FROM TMP_SetTask1) LOOP
      IF  aDoMSG = 1 THEN
        MSGID1 := NEXTVAL('winmadmin.SEQ_MESAJE1_CODMESAJ1');

        INSERT INTO winmadmin.MESAJE1(CODMESAJ1, CODMESAJ, TO_USER, STERS, citit)
        VALUES(MSGID1, MSGID, v_rec.MesajCatre, 0, 0);
      END IF;

      IF  aDoMail = 1 THEN
        IF  COALESCE( v_rec.CodPers, 0) = 0 THEN
          aEMail := (SELECT wme_result FROM winmadmin.PKG_UserFirme_GetEMailFromUtilizator(NULL, v_rec.MesajCatre));
        END IF;

        IF  aEMail = '?' THEN
          aEMail := v_rec.MesajCatre;
        END IF;

        IF  aZBefore2 = -1 THEN
          PERFORM WINMADMIN.PKG_USERFIRME_SendEMail(current_date, True, aSkema, aUSERNAME, aEMail, 'Task:' || COALESCE(aTermen::varchar, '') || '; Dest:' || COALESCE(aDESTINATAR, '') || '; Proiect:' || COALESCE(aPROIECT, ''), aPROBLEMA, MAILID);
        ELSE
          aDataMail := add_days(aTERMEN, -aZBefore2::INTEGER);
          PERFORM WINMADMIN.PKG_USERFIRME_SendEMail( aDataMail, False, aSkema, aUSERNAME, aEMail, 'Task:' || COALESCE(aTermen::varchar, '') || '; Dest:' || COALESCE(aDESTINATAR, '') || '; Proiect:' || COALESCE(aPROIECT, ''), aPROBLEMA, MAILID);
        END IF;
      END IF;

      SELECT NEXTVAL('SEQ_SETTASK_CODTASK') INTO RecId;

      INSERT INTO SETTASK(CODTASK, PROBLEMA, DESTINATAR, EXECUTANT, USERNAME, TERMEN, DATATASK, DATAREZ, DOMENIU, TIP, REZOLVARE, OBSERVATII, PRIORITATE, DONE,
                          MODIFICAT, MESAJCATRE, PROIECT, CODMSG1, CODMAIL, DOMSG, DOMAIL, ZBEFORE, CODFIRMA, SUBUNITATEA, FACTURABIL, FACTURAT, VALOARE, CODMONEDA,
                          CODCOMANDA, CODFACTURA, CODOFERTA, CODPART, CODPERS, CODSERVICIU, CODCONTRACT1, VERSIUNE, PREFIXDOC, NRDOC, CARNETDOC, SERIADOC, ARTICOLASOCIAT)
      SELECT RecId, PROBLEMA, DESTINATAR, v_rec.MesajCATRE, USERNAME, TERMEN, TO_TIMESTAMP( TO_CHAR( DATATASK, 'DD.MM.YYYY') || ' ' || ORATASK, 'DD.MM.YYYY HH24:MI'),
             CASE WHEN DATAREZ IS NULL THEN NULL ELSE TO_TIMESTAMP( TO_CHAR( DATAREZ, 'DD.MM.YYYY') || ' ' || CASE  WHEN  ORAREZ = '  :  ' THEN '00:00' ELSE ORAREZ END , 'DD.MM.YYYY HH24:MI') END ,
             DOMENIU, TIP, REZOLVARE, OBSERVATII, PRIORITATE, DONE, MODIFICAT, v_rec.MesajCATRE, PROIECT, MSGID1, MAILID, DOMSG, DOMAIL, ZBEFORE, aCODFIRMA, SUBUNITATEA,
             FACTURABIL, FACTURAT, VALOARE, CODMONEDA, CODCOMANDA, CODFACTURA, CODOFERTA, CODPART, CODPERS, CODSERVICIU, CODCONTRACT1, VERSIUNE, PREFIXDOC,
             NRDOC, CARNETDOC, SERIADOC, ARTICOLASOCIAT
      FROM TMP_SETTASK;

      INSERT INTO SETTASKOBJ(CODTASKOBJ, CODTASK, CODOBIECT, CANT, NEPRELUABIL, PRET, CODPERS, INDEXLOCAL)
      SELECT NEXTVAL('SEQ_SETTASKOBJ_CODTASKOBJ'), RecId, CodObiect, CANT, NEPRELUABIL, PRET, CODPERS, INDEXLOCAL FROM TMP_SETTASKOBJ;

      INSERT INTO SETTASKOBJASOC(CODTASKOBJASOC, CODTASK, CODOBIECT, SERII, CODINTERN, CODIES1, INDEXLOCAL)
      SELECT NEXTVAL('SEQ_STOBJASOC_CODSTOBJASOC'), RECID, CODOBIECT, SERII, CODINTERN, CODIES1, INDEXLOCAL FROM TMP_SETTASKOBJASOC;

      INSERT INTO SETTASKLOG(CODLOG, CODTASK, DATA, USER_SRC, USER_DST)
      SELECT NEXTVAL('SEQ_SETTASKLOG_CODLOG'), RecId, CURRENT_TIMESTAMP, USERNAME, v_rec.MesajCatre FROM TMP_SETTASK;

      IF  aCodLink &gt; 0 THEN
        PERFORM PKG_RECLAMATII_UmpleDocAsoc( aCodLink, aTipLink, RECID, 54);
      END IF;
    END LOOP;
  END IF;

  IF (TO_NUMBER((current_setting('PKG_SETTASK.CARNETDOC_I', true)),'999999999999999999') &lt;&gt; 0)  AND (TO_NUMBER((current_setting('PKG_SETTASK.NRDOC_I', true)),'999999999999999999') &lt;&gt; 0)
    AND (ACARNETDOC &lt;&gt; TO_NUMBER((current_setting('PKG_SETTASK.CARNETDOC_I', true)),'999999999999999999') OR ANRDOC &lt;&gt; TO_NUMBER((current_setting('PKG_SETTASK.NRDOC_I', true)),'999999999999999999'))
  THEN
    PERFORM PKG_CARNETEDOC_RELEASENUMARDOC( TO_NUMBER((current_setting('PKG_SETTASK.CARNETDOC_I', true)),'999999999999999999'), TO_NUMBER((current_setting('PKG_SETTASK.NRDOC_I', true)),'999999999999999999'));
    PERFORM PKG_CARNETEDOC_COMPACTEAZAINTERVALE( TO_NUMBER((current_setting('PKG_SETTASK.CARNETDOC_I', true)),'999999999999999999'));
  END IF;

  IF  ACARNETDOC &lt;&gt; 0 THEN
    PERFORM PKG_CARNETEDOC_SOLVENUMARDOC( ACARNETDOC, ANRDOC::varchar);
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_settask_taskuri_noi</obj_name>
  <obj_hashval>cf589c00b4169d4d40c846c0d1845e0d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_settask_taskuri_noi(INOUT wme_result numeric, INOUT ausername character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  iResult numeric;
BEGIN
  --Florin 27.02.2023 - sinc. Oracle (24.02.2023)
  --Florin 21.02.2023 - sinc. Oracle
  SELECT COUNT( 1) INTO iResult FROM settask WHERE UPPER(Executant) = UPPER(aUserName) AND COALESCE(STERS,0) = 0 AND COALESCE(DONE,0) = 0;

  WME_Result :=  iResult;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sgrcolect_sp_deleterecord</obj_name>
  <obj_hashval>75521ce8569e154fdaf41eb59ed67394</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sgrcolect_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 25.10.2024
  PERFORM pkg_sgrcolect_SP_LOCKRECORD(RecId);
  DELETE FROM SGRCOLECT1 WHERE CODSGRCOLECT = RecId ;
  DELETE FROM SGRCOLECT  WHERE CODSGRCOLECT = RecId ;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sgrcolect_sp_gotorecord</obj_name>
  <obj_hashval>6bcc164d51dd8e9dc8b7bff56a8736dc</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sgrcolect_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 25.10.2024
  INSERT INTO  TMP_SGRCOLECT SELECT * FROM SGRCOLECT WHERE CODSGRCOLECT = RECID;
  INSERT INTO TMP_SGRCOLECT1(CODSGRCOLECT1,CODSGRCOLECT,CODOBIECT,PRET,CANT,DENUMIRE, VALOARE)
  SELECT
    C1.CODSGRCOLECT1,
    C1.CODSGRCOLECT,
    C1.CODOBIECT,
    C1.PRET,
    C1.CANT,
    O.DENUMIRE,
    C1.PRET * C1.CANT
  FROM
    SGRCOLECT1 C1
    LEFT JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
  WHERE
    C1.CODSGRCOLECT = RECID;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sgrcolect_sp_lockrecord</obj_name>
  <obj_hashval>66970ba734d8f08a8f1a4e4e27ca48ea</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sgrcolect_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp NUMERIC(20);
BEGIN
  --Florin 25.10.2024
  SELECT CODSGRCOLECT INTO Tmp FROM SGRCOLECT WHERE CODSGRCOLECT = RecId;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sgrcolect_sp_postrecords</obj_name>
  <obj_hashval>1ec2396a7bffe079491617cc34f98df0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sgrcolect_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  v_rec record;
BEGIN
  --Florin 25.10.2024
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT CODSGRCOLECT INTO RECID FROM TMP_SGRCOLECT;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE SGRCOLECT
    SET
     (DATA, VALOARE, CODMARIRE,VOUCHERBARCODE) = (SELECT DATA, VALOARE, CODMARIRE,VOUCHERBARCODE FROM TMP_SGRCOLECT)
    WHERE
      CODSGRCOLECT = RECID;

   FOR V_REC IN (SELECT * FROM TMP_SGRCOLECT1)
   LOOP
     IF V_REC.CODSGRCOLECT1 &lt; 0 THEN
       INSERT INTO SGRCOLECT1(CODSGRCOLECT1, CODSGRCOLECT, CODOBIECT, PRET, CANT)
       VALUES (NEXTVAL('SEQ_SGRCOLECT1_CODSGRCOLECT1'), RECID, V_REC.CODOBIECT, V_REC.PRET, V_REC.CANT);
     ELSE
       UPDATE SGRCOLECT1
       SET
        CODOBIECT = V_REC.CODOBIECT,
        PRET      = V_REC.PRET,
        CANT      = V_REC.CANT
       WHERE
         CODSGRCOLECT1 = V_REC.CODSGRCOLECT1;
     END IF;
   END LOOP;

  ELSE  -- INSERT
    SELECT NextVal('SEQ_SGRCOLECT_CODSGRCOLECT') INTO RecId;
    INSERT INTO SGRCOLECT(CODSGRCOLECT, DATA, VALOARE, CODMARIRE,VOUCHERBARCODE, DATACREARE)
    SELECT RECID, DATA, VALOARE, CODMARIRE,VOUCHERBARCODE, current_date FROM TMP_SGRCOLECT;

    INSERT INTO SGRCOLECT1(CODSGRCOLECT1, CODSGRCOLECT, CODOBIECT, PRET, CANT)
    SELECT NEXTVAL('SEQ_SGRCOLECT1_CODSGRCOLECT1'), RECID, CODOBIECT, PRET, CANT FROM TMP_SGRCOLECT1;
  END IF;

  PERFORM NotifyModif(Operation, RecId, 'SGRCOLECT');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_simlans_exec_debug</obj_name>
  <obj_hashval>66dbb993dde0ef3274d460cb2fd01a8d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_simlans_exec_debug()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_SIMLANS_GET_TMP_SIM_CCOM1(0, 2, '', '', '', '', 1005, 0, 0);
  PERFORM PKG_SIMLANS_GET_TMP_SIM_LANS(2);
  PERFORM PKG_SIMLANS_GET_TMP_SIM_LANS1(2);
  PERFORM PKG_SIMLANS_SolveREZOLVATLansare1(0, 0, 1);
  PERFORM PKG_SIMLANS_GET_PosibilDeLansat(0, 3);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_simlans_get_posibildelansat</obj_name>
  <obj_hashval>658a8283787e344090b7520ddb3ba4c8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_simlans_get_posibildelansat(acodcomanda1 numeric, acaz numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_COM RECORD;
  XX    RECORD;
  Total numeric;
  Cate  numeric;
  Lans  numeric;
  Zec   numeric;
BEGIN
  --Adina 30.12.2020 - sincronizare cu Oracle

  --PERFORM PKG_SIMLANS_SolveREZOLVATLansare1(0, 0, 1);

  FOR v_COM IN
  (
   --SELECT CodComanda1, CodObiect, COALESCE(CANTLANSAT, 0) CANTLANSAT, COALESCE(RESTREZOLVAT, 0) RESTREZOLVAT
   SELECT CodComanda1, CodObiect, COALESCE(LANSSCENARIU, 0) CANTLANSAT, COALESCE(DEREZOLVAT, 0) RESTREZOLVAT
   FROM TMP_SIM_CCOM1
   WHERE COALESCE(Activ, 0) = 1 and (   aCodcomanda1 = 0 or  CodComanda1 = aCodComanda1)
  )
  LOOP
    Total := v_COM.CantLansat + v_COM.RESTREZOLVAT;
    SELECT Count(*) INTO CATE FROM TMP_SIM_LANS1 WHERE CodComanda1 = v_COM.CodComanda1 and  NODORIGINAL &gt; 0 and  COALESCE(Tip, 0) &gt;= aCaz;

    IF  Cate = 0 THEN
      Cate := Total;
    ELSE
      Cate := 0;

      FOR xx IN (SELECT * FROM TMP_SIM_LANS1 WHERE CodComanda1 = v_COM.CodComanda1 and  NODORIGINAL &gt; 0 and  COALESCE(Diferente, 0) &gt; 0 and  COALESCE(Tip, 0) &gt;= aCaz)
      LOOP
        Cate := Cate + COALESCE(xx.Diferente, 0);
      END LOOP;

      SELECT Count(*) INTO CATE FROM TMP_SIM_LANS1 WHERE CodComanda1 = v_COM.CodComanda1 and  NODORIGINAL &gt; 0 and  COALESCE(Diferente, 0) &gt; 0 and  COALESCE(Tip, 0) &gt;= aCaz;

      IF  Cate = 0 THEN
        Cate := Total;
      ELSE
        --SELECT MIN((  COALESCE(Necesar, 0) - COALESCE(Diferente, 0))  / Cant)
        SELECT MIN((  COALESCE(Necesar, 0) - COALESCE(Diferente, 0))  / NecesarP)
        INTO CATE
        FROM TMP_SIM_LANS1
        --WHERE CodComanda1 = v_COM.CodComanda1 and  NODORIGINAL &gt; 0 and  COALESCE(Cant, 0) &lt;&gt; 0 and  COALESCE(Tip, 0) &gt;= aCaz;
        WHERE CodComanda1 = v_COM.CodComanda1 and  NODORIGINAL &gt; 0 and  COALESCE(NecesarP, 0) &lt;&gt; 0 and  COALESCE(Tip, 0) &gt;= aCaz;
      END IF;
    END IF;

    SELECT COALESCE(u.Zecimale, 0) INTO ZEC FROM NUM u, NART a, NARTOBJ o WHERE o.CodObiect = v_COM.CodObiect and  a.CodArticol = o.CodArticol and  u.CODUM = a.UM;

    Lans := Trunc(COALESCE(Cate, 0), ZEC);

    --UPDATE TMP_SIM_CCOM1 SET CANTLANSAT = Lans, RESTREZOLVAT = Total - Lans WHERE CodComanda1 = v_COM.CodComanda1;
    UPDATE TMP_SIM_CCOM1 SET LANSSCENARIU = Lans, DEREZOLVAT = Total - Lans   where CodComanda1 = v_COM.CodComanda1;
  END LOOP;

  --PERFORM PKG_SIMLANS_SolveREZOLVATLansare1(0, 0, -1);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_simlans_populeaza_tmpuri_x</obj_name>
  <obj_hashval>a262b637764c308209b3349c8c75af75</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_simlans_populeaza_tmpuri_x(g_subunit numeric, datalivrs character varying, datalivrf character varying, datacmds character varying, datacmdf character varying, scenariu numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  NOD_Rezervat     numeric;
  NOD_RezFurn      numeric;
  TOT_RestCmd      numeric;
  TOT_RestFurn     numeric;
  Init             numeric;
  Zec              numeric;
  LastProiectNod   numeric;
  RezolvareLansari numeric;
BEGIN
  --Laura 25.11.2021 - sinc Oracle (24.11.2021)
  --Laura 28.10.2021 - sinc Oracle (26.10.2021)
  --Adina 07.07.2021 - sinc.Oracle din 07.07.2021
  --Adina 25.06.2021 - sinc.Oracle din 24.06.2021
  --Adina 30.12.2020 - am pus coalesce(Scenariu,0) in loc de Scenariu pt.ca in Oracle este default 0
  --Florin 22.12.2020 - fixat #41814
  --Florin 28.01.2021 - fixat #41886
   DELETE FROM TMP_SIM_CCOM1;
  DELETE FROM TMP_SIM_LANS;
  DELETE FROM TMP_SIM_LANS1;
  DELETE FROM TMP_SIM_NODECHIV1;

  INSERT INTO TMP_SIM_CCOM1(NRDOC, DATADOC, DENOBIECT, DEN_CLIENT, CODCOMANDA1, CODOBIECT, CODPROIECT, VERSIUNE, CODCOMANDA, TIPDOC, CODCLIENT, TERMEN, MASAO, VOLUMO,
                            CODGRUPA, PARITATEGRUPA, GrupaE, ObjGeneric, CODTARA, DEN_TARA, CODZONA, DEN_ZONA, CODLOCALIT, DEN_LOCALIT, UMSEC, OK, ACTIV, TIPCOMANDA,
                            CODEXTERN, DENMAT, TRASEU, POZTRASEU, HTAG, CANTACCEPTAT, STOCREZERVAT, SCENDEFINITIVE, ALTESCENARII, REST, DEREZOLVAT, LANSSCENARIU, LANSAT,
                            Masa, Volum, TipClient)
  select * from
  (SELECT C.NRDOC, C.DATADOC, NOBJ.DENUMIRE DENOBIECT, NP.DEN_PART DEN_CLIENT, C1.CODCOMANDA1, C1.CODOBIECT, C1.CODPROIECT, PR.VERSIUNE, C.CODCOMANDA,
         C.TIPDOC, NP.CODPART CODCLIENT, C1.TERMEN, NOBJ.MASA MASAO, NOBJ.VOLUM / 1000000 VOLUMO, NE.CODGRUPA, NE.PARITATE PARITATEGRUPA, GE.DENUMIRE GRUPAE,
         NOBJE.DENUMIRE OBJGENERIC, TARA.CODTARA, TARA.DEN_TARA, NZ.CODZONA, NZ.DEN_ZONA, NLOC.CODLOCALIT, NLOC.DEN_LOCALIT, C1.UMSEC, 0 OK,
         CASE WHEN  COALESCE(SCEN1.CANT, 0) = 0 THEN 0 ELSE 1 END  ACTIV,
         C.DISPLIVRARE, NOBJ.CODEXTERN, NOBJMAT.DENUMIRE DENMAT, TR.DENTRASEU TRASEU, NAG.POZTRASEU,
         COALESCE(PR.OBS1, '') || coalesce(COALESCE(PC.OBS1, ''),'') HTAG, C1.CANTACCEPTAT CANTACCEPTAT, REZ.REZERVAT STOCREZERVAT,
         COALESCE(SCDEF.CANT, 0) SCENDEFINITIVE, COALESCE(SC.CANT, 0) ALTESCENARII,
         C1.CANTACCEPTAT - COALESCE(SC.CANT, 0) - COALESCE(SCDEF.CANT, 0) REST,
         C1.CANTACCEPTAT - COALESCE(SC.CANT, 0) - COALESCE(SCDEF.CANT, 0) - COALESCE(SCEN1.LANS, 0) DEREZOLVAT,
         COALESCE(SCEN1.LANS, 0) LANSSCENARIU, COALESCE(CMDINT.CANTCMDINT, 0) LANSAT, COALESCE(NOBJ.MASA, 0) * COALESCE(SCEN1.LANS, 0),
         Round((COALESCE(NOBJ.VOLUM, 0) / 1000000 * COALESCE(SCEN1.LANS, 0))::numeric, 2),
           case when bitand(NP.Strategic,1)=1 then 'strategic ' else '' end ||
           case when bitand(NP.tippartener,1)=1 then 'intern ' else '' end ||
           case when bitand(NP.tippartener,2)=2 then 'extern ' else '' end ||
           case when bitand(NP.tippartener,4)=4 then 'produc. ' else '' end ||
           case when bitand(NP.tippartener,8)=8 then 'asig.' else '' end ||
           case when BITand(NP.tippartener,16)=16 then 'comis.' else '' end as TipClient
  FROM COMANDA C
       INNER JOIN COMANDA1         C1      ON  C.CODCOMANDA      = C1.CODCOMANDA
       INNER JOIN NARTOBJ          NOBJ    ON  NOBJ.CODOBIECT    = C1.CODOBIECT
       LEFT JOIN NPART             NP      ON  NP.CODPART        = C.PARTENER
       LEFT JOIN TMP_SCENARIILIVR1 SCEN1   ON  SCEN1.CODCOMANDA1 = C1.CODCOMANDA1
       LEFT JOIN PROIECT           PR      ON  PR.CODPROIECT     = C1.CODPROIECT
       LEFT JOIN PROIECTNOD        PRN     ON  PRN.CODPROIECT    = PR.CODPROIECT AND  PRN.NODORIGINAL = 0
       LEFT JOIN (SELECT CODPRODCOMP, CODOBIECT FROM PRODMAT WHERE PRINCIPAL = 1
                 )                 MAT     ON  MAT.CODPRODCOMP   = PRN.CODRETETA
       LEFT JOIN NARTOBJ           NOBJMAT ON  NOBJMAT.CODOBIECT = MAT.CODOBIECT
       LEFT JOIN PRODCOMP          PC      ON  PC.CODPRODCOMP    = PRN.CODRETETA
       LEFT OUTER JOIN NECHIV      NE      ON  NE.CODOBIECT      = C1.CODOBIECT
       LEFT OUTER JOIN GRECHIV     GE      ON  GE.CODGRECHIV     = NE.CODGRUPA
       LEFT OUTER JOIN NECHIV      NG      ON  NG.CODGRUPA       = NE.CODGRUPA AND  NG.GENERIC = 1
       LEFT JOIN NARTOBJ           NOBJE   ON  NOBJE.CODOBIECT   = NG.CODOBIECT
       LEFT JOIN NAGENDA           NAG     ON  NAG.CODAGENDA     = C.CODLOCATIE
       LEFT JOIN TRASEULIVR        TR      ON  TR.CODTRASEULIVR  = NAG.CODTRASEU
       LEFT JOIN NLOCALIT          NLOC    ON  NLOC.CODLOCALIT   = NAG.CODLOCALIT
       LEFT JOIN NZONE             NZ      ON  NZ.CODZONA        = NLOC.CODZONA
       LEFT JOIN NTARI             TARA    ON  TARA.CODTARA      = NLOC.CODTARA
       LEFT JOIN (SELECT S1.CODCOMANDA1, SUM(S1.LANS) CANT
                  FROM SCENARIILIVR1 S1 INNER JOIN SCENARIILIVR S ON  S1.CODSCENARIU = S.CODSCENARIU
                  WHERE COALESCE(S.DEFINITIV, 0) = 1 AND  S.CODSCENARIU &lt;&gt; COALESCE(SCENARIU,0)
                  GROUP BY S1.CODCOMANDA1
                 ) SCDEF                   ON  SCDEF.CODCOMANDA1 = C1.CODCOMANDA1
       LEFT JOIN (SELECT S1.CODCOMANDA1, SUM(S1.LANS) CANT
                  FROM SCENARIILIVR1 S1 INNER JOIN SCENARIILIVR S ON  S1.CODSCENARIU = S.CODSCENARIU
                  WHERE COALESCE(S.DEFINITIV, 0) = 0 AND  S.CODSCENARIU &lt;&gt; COALESCE(SCENARIU,0)
                  GROUP BY S1.CODCOMANDA1
                 ) SC                      ON  SC.CODCOMANDA1 = C1.CODCOMANDA1
       LEFT JOIN (SELECT R.CODCOMANDA1, SUM(R.REST) REZERVAT, NS.CODOBIECT
                  FROM REZERVATS R INNER JOIN NIRSTOC NS ON  R.CODNIRSTOC = NS.CODNIRSTOC
                  WHERE COALESCE(CODCMDPRODMAT, 0) = 0
                  GROUP BY R.CODCOMANDA1, NS.CODOBIECT
                 ) REZ                     ON  REZ.CODCOMANDA1 = C1.CODCOMANDA1 AND  NOBJ.CODOBIECT = REZ.CODOBIECT
       LEFT JOIN (SELECT L0.Codcmd1 CMDCLI, C1.CodObiect, L0.CODSCENARIU, SUM(C1.CANTAcceptat) CANTCMDINT
                  FROM LANSARE1 L1
                       INNER JOIN LANSARE0 L0 ON  L0.CodLansare0 = L1.CodLansare0
                       INNER JOIN Comanda1 C1 ON  C1.CODCOMANDA1 = L1.CodCmd1
                  GROUP BY L0.Codcmd1, C1.CodObiect, L0.CODSCENARIU
                 ) CMDINT                  ON  CMDINT.CMDCLI = C1.CODCOMANDA1 and  NOBJ.CODOBIECT = CMDINT.CODOBIECT
  WHERE C.TIPDOC in (18, 44) AND  COALESCE(C1.CULANSARE, 0) = 1 AND (   G_SUBUNIT = 1 OR  ((C.SUBUNITATEA = G_SUBUNIT and C.TIPDOC = 18) OR (C.SUBUNITSURSA = G_SUBUNIT and C.TIPDOC = 44)))
        AND  COALESCE(C1.CodProiect, 0) &gt; 0 AND  C1.RESTACCEPTAT &lt;&gt; 0
        AND (DataLivrS IS NULL OR DataLivrS = '' OR (  C1.TERMEN BETWEEN TO_DATE(DataLivrS, 'DD.MM.YYYY') AND TO_DATE(DataLivrF, 'DD.MM.YYYY')) )
        AND (DataCmdS IS NULL OR DataCmdS = '' OR (  C.DATADOC BETWEEN TO_DATE(DataCmdS , 'DD.MM.YYYY') AND TO_DATE(DataCmdF , 'DD.MM.YYYY')) )
     ) A_PG where Scenariu &gt; 0  or Rest &gt; 0;

  INSERT INTO TMP_SIM_LANS1(DENUMIRE, CODOBIECT, CODCOMANDA1, PREF, NIVEL, POZITIE, CODPROIECTNOD, NODORIGINAL, TIP, NECESARP, NECESAR, REZERVAT, NESOSIT, DataStart, CERERE,
                            STOC, CMDINT, DIFERENTE, ZECIMALE, UMSEC, DEN_UM, MatEchiv, CodExtern, IndexParinte, Rezolvat)
  (
  SELECT DENUMIRE, CODOBIECT, CODCMD1, PREF, NIVEL, POZITIE, CODPROIECTNOD, NODORIGINAL, TIP, COALESCE(NECESARP, 0), 0 NECESAR,
         COALESCE(TotRezervat, 0), COALESCE(RestDeSosit, 0), DataStart, COALESCE(RestCerere, 0), COALESCE(STOC, 0), COALESCE(CantCMDINT, 0),
         0 DIFERENTE, Zecimale, UMSEC, DEN_UM, MatEchiv, CodExtern, IndexParinte, 0
  FROM (
        SELECT Y.DENUMIRE, Y.CODOBIECT, Y.CODCMD1, Y.PREF, Y.NIVEL, Y.POZITIE, Y.CODPROIECTNOD, Y.NODORIGINAL, Y.Tip, Y.CANT, Y.TotRezervat,
               RestFurn.RestDeSosit, RestFurn.DataStart::date DataStart, CEREFURN.RestCerere, Y.STOC, Y.NECESARP, CMDI.CANTCMDINT,
               (SELECT COALESCE(u.Zecimale, 0) FROM NUM u, NART a, NARTOBJ o WHERE o.CodObiect = Y.CodObiect and  a.CodArticol = o.CodArticol and  u.CODUM = a.UM) ZECIMALE,
               0 UMSEC,
               (SELECT DEN_UM FROM NUM u, NART a, NARTOBJ o WHERE o.CodObiect = Y.CodObiect and  a.CodArticol = o.CodArticol and  u.CODUM = a.UM) DEN_UM,
               MatEchiv, CodExtern, Y.IndexParinte
        FROM (
              SELECT NOBJ.DENUMIRE, NOBJ.CODOBIECT, COALESCE(NE.CODCOMANDA1, C1.CODCOMANDA1) CODCMD1, X.PREF, X.NIVEL, X.POZITIE, X.CODPROIECTNOD,
                     X.NODORIGINAL, X.Tip, X.CANT, REZ.TotRezervat, NS.REST * COALESCE(NE.PARITATE, 1) STOC, X.CANT / ORIG.CANT * COALESCE(NE.PARITATE, 1) NECESARP,
                     x.MatEchiv, NOBJ.CodExtern, X.IndexParinte
              FROM COMANDA1 C1
                   INNER JOIN (SELECT PN0.CODPROIECTNOD NODORIG, PN.CODPROIECTNOD, PN.CODPROIECT, PN.CANT, PN.NODORIGINAL, PN.TIP, PN.CODOBIECT,
                                      PN.NIVEL, PN.POZITIE, SUBSTR(PN.INDEXPARINTE, 3, 47) PREF,
                                      CASE WHEN  MECHIV.Nr &gt; 0 THEN PN.Codprodmat ELSE 0 END  MATECHIV,
                                      PN.INDEXPARINTE
                               FROM PROIECTNOD PN
                                    INNER JOIN PROIECTNOD PN0 ON  PN0.CODPROIECT = PN.CODPROIECT AND  PN0.NODORIGINAL = 0
                                    LEFT  JOIN (SELECT count(*) NR, codmat FROM prodmat GROUP BY codmat) MECHIV ON  MECHIV.CODMAT = PN.CODPRODMAT
                              ) X ON  X.CODPROIECT = C1.CODPROIECT
                   LEFT JOIN PROIECTNOD ORIG ON  ORIG.CODPROIECTNOD = X.NODORIG
                   LEFT JOIN NODECHIV   NE   ON  NE.CODCOMANDA1 = C1.CODCOMANDA1 AND  NE.CODPROIECTNOD = X.CODPROIECTNOD
                   LEFT JOIN NARTOBJ    NOBJ ON  NOBJ.CODOBIECT = COALESCE(NE.CODOBIECT, X.CODOBIECT)
                   LEFT JOIN (SELECT sum(NSS.REST) REST, NSS.CODOBIECT
                              FROM NIRSTOC NSS
                                   INNER JOIN NIR      ON  NSS.CODNIR = NIR.CodNIR
                                   INNER JOIN NGEST NG ON  NG.CODGEST = NIR.GEST
                                   WHERE (G_SUBUNIT = 1 OR  NG.CodSubunit = G_SUBUNIT)
                              GROUP BY NSS.CODOBIECT
                             ) NS ON  NS.CODOBIECT = NOBJ.CODOBIECT
                   LEFT JOIN (SELECT R.CodComanda1, NSR.CodObiect, SUM(R.REZERVATINI) TOTREZERVAT
                              FROM REZERVATS R INNER JOIN NIRSTOC NSR ON  R.CODNIRSTOC = NSR.CodNIRSTOC
                              GROUP BY R.CodCOmanda1, NSR.CodObiect
                             ) REZ ON  REZ.CodComanda1 = C1.CodComanda1 AND  NOBJ.CODOBIECT = REZ.CodObiect
              WHERE EXISTS (SELECT TMP.CODPROIECT FROM TMP_SIM_CCOM1 TMP WHERE TMP.CODPROIECT = X.CODPROIECT)
                    AND
                    EXISTS (SELECT TMP.CODCOMANDA1 FROM TMP_SIM_CCOM1 TMP WHERE TMP.CODCOMANDA1 = COALESCE(NE.CODCOMANDA1, C1.CODCOMANDA1))
              ) Y
                LEFT JOIN (SELECT L0.Codcmd1 CMDCLI1, L0.CODSCENARIU, L1.CODPROIECTNOD, SUM(C1.CANTAcceptat) CANTCMDINT
                           FROM LANSARE1 L1
                                INNER JOIN LANSARE0      L0  ON  L0.CodLansare0  = L1.CodLansare0
                                INNER JOIN TMP_SIM_CCOM1 CC1 ON  CC1.CODCOMANDA1 = L0.CodCmd1
                                INNER JOIN Comanda1      C1  ON  C1.CODCOMANDA1  = L1.CodCmd1
                           GROUP BY L0.Codcmd1, L1.CODPROIECTNOD, L0.CODSCENARIU
                          ) CMDI ON  CMDI.CmdCli1 = Y.CodCmd1 and  CMDI.Codproiectnod = Y.CODPROIECTNOD
                LEFT JOIN (SELECT R.CodComanda1, NS.CodObiect, sum(r.rest) RESTDECONSUMAT
                           FROM rezervats r INNER JOIN nirstoc ns ON  ns.codnirstoc = r.codnirstoc
                           WHERE COALESCE(r.codnirstoc, 0) &gt; 0
                           GROUP BY NS.CodObiect, R.CodComanda1
                          ) RESTREZ ON  RESTREZ.CodObiect = Y.CodObiect AND  RESTREZ.CodComanda1 = Y.CodCmd1
                LEFT JOIN (SELECT R.CodComanda1, R.CodObiect, Max(C1.Termen) DataStart, sum(r.rest) RESTDESOSIT
                           FROM rezervats r inner join Comanda1 C1 on C1.CodComanda1 = r.CODCOMANDA1F
                           WHERE COALESCE(r.codnirstoc, 0) = 0 and  COALESCE(r.CODCOMANDA1F, 0) &lt;&gt; 0
                           GROUP BY r.CodObiect, r.codcomanda1
                          ) RESTFURN ON  RESTFURN.CodObiect = Y.CodObiect and  RESTFURN.CodComanda1 = Y.CodCmd1
                LEFT JOIN (SELECT R.CodComanda1, R.CodObiect, sum(r.rest) RESTCERERE
                           FROM rezervats r
                           WHERE COALESCE(r.codnirstoc, 0) = 0 and  COALESCE(r.CODCOMANDA1F, 0) = 0
                           GROUP BY r.CodObiect, r.codcomanda1
                          ) CEREFURN ON  CEREFURN.CodObiect = Y.CodObiect and  CEREFURN.CodComanda1 = Y.CodCmd1
        ORDER BY Y.DENUMIRE
       ) A_PG
  WHERE NecesarP &gt; 0
  );

  INSERT INTO TMP_SIM_NODECHIV1(CODCOMANDA1, CODPROIECTNOD, CODOBIECT, CANT, PARITATE, TIP, CODOBIECTORIG, NODORIGINAL, STOC, CANTECHIVALATA, DENOBIECTECHIV, CODEXTERN)
  SELECT NE1.CODCOMANDA1, NE1.CODPROIECTNOD, NE1.CODOBIECT, NE1.CANT, NE1.PARITATE, NE1.TIP, L1.CODOBIECT, L1.NODORIGINAL,
         COALESCE(NS.REST, 0), NE1.CANT / NE1.PARITATE, OBJ.DENUMIRE, OBJ.CODEXTERN
  FROM TMP_SIM_LANS1 L1
       INNER JOIN NODECHIV1 NE1 ON  L1.CODCOMANDA1 = NE1.CODCOMANDA1 AND  L1.CODPROIECTNOD = NE1.CODPROIECTNOD
       INNER JOIN NARTOBJ   OBJ ON  OBJ.CODOBIECT  = NE1.CODOBIECT
       LEFT JOIN (SELECT sum(NSS.REST) REST, NSS.CODOBIECT
                  FROM NIRSTOC NSS
                       INNER JOIN NIR      ON  NSS.CODNIR = NIR.CodNIR
                       INNER JOIN NGEST NG ON  NG.CODGEST = NIR.GEST
                  WHERE (G_SUBUNIT = 1 OR  NG.CodSubunit = G_SUBUNIT)
                  GROUP BY NSS.CODOBIECT
                 ) NS ON  NS.CODOBIECT = OBJ.CODOBIECT;

  IF  COALESCE(Scenariu,0) = 0 THEN
    RezolvareLansari := 0;
  ELSE
    RezolvareLansari := 1;
  END IF;

  PERFORM PKG_SimLans_LoadScenariiLivr(COALESCE(Scenariu,0));
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_simlans_rezolva</obj_name>
  <obj_hashval>584e2d9efd6132a5203407a0a07618a2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_simlans_rezolva(acodcomanda1 numeric, acodproiectnod numeric, aparitate numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
 vRezervat    numeric;
 vRezolvat    numeric;
 vNecesar     numeric;
 vNod      numeric;
 v_rec      record;
BEGIN
  update tmp_sim_lans1 set rezolvat = necesar * aParitate where codcomanda1 = aCodComanda1 and codproiectnod = aCodProiectNod;
    select rezolvat, rezervat, NodOriginal, Necesar into vRezolvat, vRezervat, vNod, vNecesar from tmp_sim_lans1
    where codcomanda1 = aCodComanda1 and codproiectnod = aCodProiectNod;
    if vNod = 0 then vRezolvat := 0;
    end if;
    for v_rec in (select * from tmp_sim_lans1 where codcomanda1 = aCodComanda1 and NodOriginal = aCodProiectNod) loop
      perform pkg_simlans_rezolva(aCodComanda1, v_rec.codproiectnod, (vRezolvat+vRezervat)/vNecesar);
    end loop;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_simlans_setdatastart</obj_name>
  <obj_hashval>fc639abfb86cafddaa258dba636be65d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_simlans_setdatastart(acodproiectnod numeric, acodcomanda1 numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC  RECORD;
  aCount numeric;
BEGIN
  --Adina 25.06.2021
  SELECT count(*) INTO acount FROM tmp_sim_lans1 WHERE nodoriginal = acodproiectnod and  codcomanda1 = acodcomanda1;

  IF  acount &gt; 0 THEN
    FOR v_Rec IN (SELECT codproiectnod, codcomanda1 FROM tmp_sim_lans1 WHERE nodoriginal = acodproiectnod and  codcomanda1 = acodcomanda1) LOOP
      PERFORM pkg_simlans_setdatastart(v_rec.codproiectnod, v_rec.codcomanda1);
    END LOOP;

    UPDATE tmp_sim_lans1 t
    SET
      datastart = (SELECT max(tt.datastart) FROM tmp_sim_lans1 tt WHERE tt.nodoriginal = acodproiectnod and  codcomanda1 = acodcomanda1)
    WHERE
      t.codproiectnod = acodproiectnod and  t.codcomanda1 = acodcomanda1;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_simlans_solvecantlansare1</obj_name>
  <obj_hashval>26150895d32be7d7f5acc9e052ecec4f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_simlans_solvecantlansare1(acodcomanda1 numeric, rezolvarelansari numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_COM       RECORD;
  V_NOD       RECORD;
  OldDif      numeric;
  NewDif      numeric;
  OldNecesar  numeric;
  NewNecesar  numeric;
  CMD_Cant    numeric;
  COM_Stare   numeric;
  FaraNecesar numeric;
  Lipsa       numeric;
begin
  FOR v_COM IN (SELECT * FROM TMP_SIM_CCOM1 WHERE COALESCE(Activ, 0) = 1 and (aCodcomanda1 = 0 or  CodComanda1 = aCodComanda1)) LOOP
    IF  RezolvareLansari = 1 THEN
      CMD_Cant := v_COM.NECESAR;
    ELSE
      CMD_Cant := v_COM.CANTLANSAT;
    END IF;

    FaraNecesar := 1;
    Lipsa       := 0;

    FOR v_NOD IN (SELECT * FROM TMP_SIM_LANS1 WHERE CodComanda1 = v_COM.Codcomanda1) LOOP
      OldNecesar := v_NOD.Necesar;
      OldDif     := v_NOD.Diferente;
      NewNecesar := v_NOD.NecesarP * CMD_Cant;

      IF  NewNecesar &gt; 0.0 THEN
        FaraNecesar := 0;
      END IF;

      NewDif := NewNecesar - v_NOD.REZERVAT - v_NOD.REZOLVAT - v_NOD.CmdInt;

      IF  NewDif &lt; 0.0 THEN
        NewDif := 0.0;
      END IF;

      IF (NewDif &gt; 0.0)  and  v_NOD.Tip = 3 THEN
        Lipsa := 1;
      END IF;

      IF  NewNecesar = 0.0 THEN
        NewDif := 0;
      END IF;

      UPDATE TMP_SIM_LANS1
      SET
      Necesar   = NewNecesar,
      Diferente = NewDif
      WHERE
       CodComanda1 = v_COM.CodComanda1 and  CodProiectNod = v_NOD.CodProiectNod;
    END LOOP;

    IF  FaraNecesar = 1 THEN
      COM_Stare := 0;
    ELSE
      IF  Lipsa = 1 THEN
        COM_Stare := 2;
      ELSE
        COM_Stare := 1;
      END IF;
    END IF;

    UPDATE TMP_SIM_CCOM1 SET Ok = COM_Stare WHERE CodComanda1 = v_COM.CodComanda1;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_simlans_solverezolvatlansare1</obj_name>
  <obj_hashval>b010c24a5449930f1d425076d2a83e19</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_simlans_solverezolvatlansare1(acodcomanda1 numeric, rezolvarelansari numeric, atip numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_COM                 RECORD;
  V_NOD                 RECORD;
  COM_RESTREZOLVAT      numeric;
  NOD_CANT              numeric;
  NOD_REZOLVAT          numeric;
  NOD_NECESAR           numeric;
  NOD_RESTREZ           numeric;
  NOD_RESTNES           numeric;
  NOD_REZERVAT          numeric;
  NOD_NESOSIT           numeric;
  NOD_NECESARP          numeric;
  NOD_CMDINT            numeric;
  Rezolvat_de_NodCurent numeric;
  aParitate             numeric;
  OldDif                numeric;
  NewDif                numeric;
  OldNecesar            numeric;
  NewNecesar            numeric;
  CMD_Cant              numeric;
  COM_Stare             numeric;
  FaraNecesar           numeric;
  Lipsa                 numeric;
begin
  UPDATE TMP_SIM_LANS1
  SET
  REZOLVAT = 0,
  REZERVAT = 0,
  RestRezervat = TotRezervat
  WHERE aCODCOMANDA1 = 0 or  CodComanda1 = aCODCOMANDA1;

  FOR v_COM IN (SELECT * FROM TMP_SIM_CCOM1 WHERE COALESCE(Activ, 0) = 1 and (aCODCOMANDA1 = 0 or  CodComanda1 = aCODCOMANDA1)) LOOP
    IF  RezolvareLansari = 1 THEN
      CMD_Cant := COALESCE(v_COM.NECESAR, 0);
    ELSE
      CMD_Cant := COALESCE(v_COM.CANTLANSAT, 0);
    END IF;

    IF  aTip = 0 THEN
      COM_RESTREZOLVAT := COALESCE(v_COM.RESTREZOLVAT, 0) + CMD_Cant;
      CMD_Cant         := 0;
    END IF;

    IF  aTip = 1 THEN
      CMD_Cant         := CMD_Cant + COALESCE(v_COM.RESTREZOLVAT, 0);
      COM_RESTREZOLVAT := 0;
    END IF;

    FaraNecesar := 1;
    Lipsa       := 0;

    FOR v_NOD IN (SELECT * FROM TMP_SIM_LANS1 WHERE CodComanda1 = v_COM.Codcomanda1 ORDER BY PREF) LOOP
      OldNecesar := COALESCE(v_NOD.Necesar, 0);
      OldDif     := COALESCE(v_NOD.Diferente, 0);
      NewNecesar := COALESCE(v_NOD.NecesarP, 0) * CMD_Cant;

      IF  NewNecesar &gt; 0.0 THEN
        FaraNecesar := 0;
      END IF;

      SELECT COALESCE(REZOLVAT, 0), COALESCE(RESTREZERVAT, 0)
      INTO NOD_REZOLVAT, NOD_RESTREZ
      FROM TMP_SIM_LANS1
      WHERE CodComanda1 = v_COM.CodComanda1 and  CodProiectNod = v_NOD.CodProiectNod;

      NOD_NECESAR := NEWNECESAR - NOD_REZOLVAT;
      IF  NOD_RESTREZ &gt; NOD_NECESAR THEN
        NOD_REZERVAT := NOD_NECESAR;
      ELSE
        NOD_REZERVAT := NOD_RESTREZ;
      END IF;

      UPDATE TMP_SIM_LANS1 SET REZERVAT = NOD_REZERVAT WHERE CodComanda1 = v_COM.CodComanda1 and  CodProiectNod = v_NOD.CodProiectNod;
      UPDATE TMP_SIM_LANS1 SET RESTREZERVAT = COALESCE(RESTREZERVAT, 0) - NOD_REZERVAT WHERE CodComanda1 = v_COM.CodComanda1 and  CodObiect = v_NOD.CodObiect;

      Rezolvat_de_NodCurent := NOD_REZOLVAT + NOD_REZERVAT;
      aParitate             := Rezolvat_de_NodCurent / v_NOD.CANT;

      UPDATE TMP_SIM_LANS1
      SET
      REZOLVAT = Round((REZOLVAT + aParitate * CANT)::numeric, (v_NOD.Zecimale)::int)
      WHERE CodComanda1 = v_COM.CodComanda1 and  NodOriginal = v_NOD.CodProiectNod;

      NewDif := NewNecesar - NOD_REZERVAT - NOD_REZOLVAT - v_NOD.CmdInt;
      IF  NewDif &lt; 0.0 THEN
        NewDif := 0.0;
      END IF;

      IF (NewDif &gt; 0.0)  and  v_NOD.Tip = 3 THEN
        Lipsa := 1;
      END IF;

      IF  NewNecesar = 0.0 THEN
        NewDif := 0;
      END IF;

      UPDATE TMP_SIM_LANS1
      SET
      Necesar   = NewNecesar,
      Diferente = NewDif
      WHERE
       CodComanda1 = v_COM.CodComanda1 and  CodProiectNod = v_NOD.CodProiectNod;
    END LOOP;

    IF  FaraNecesar = 1 THEN
      COM_Stare := 0;
    ELSE
      IF  Lipsa = 1 THEN
        COM_Stare := 2;
      ELSE
        COM_Stare := 1;
      END IF;
    END IF;

    IF  aTip &lt;&gt; -1 THEN
      IF  RezolvareLansari = 1 THEN
        UPDATE TMP_SIM_CCOM1
        SET
        Ok           = COM_Stare,
        NECESAR      = CMD_Cant,
        RESTREZOLVAT = COM_RESTREZOLVAT
        WHERE
         CodComanda1 = v_COM.CodComanda1;
      ELSE
        UPDATE TMP_SIM_CCOM1
        SET
        Ok           = COM_Stare,
        CANTLANSAT   = CMD_Cant,
        RESTREZOLVAT = COM_RESTREZOLVAT
        WHERE
         CodComanda1 = v_COM.CodComanda1;
      END IF;
    ELSE
      UPDATE TMP_SIM_CCOM1 SET Ok = COM_Stare WHERE CodComanda1 = v_COM.CodComanda1;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_simlans_updatadatastocplus</obj_name>
  <obj_hashval>38803bae807dac4fe4f9845b9009bd79</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_simlans_updatadatastocplus(scenariu numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
BEGIN
  --Adina 06.07.2021 - sinc.Oracle din 05.07.2021
  --Adina 25.06.2021
  FOR V_REC IN (SELECT L1.CODCMD1, Sm1.DATASTART
                FROM scenariilivr2 SL2, lansare0 L0, lansare1 L1, tmp_sim_lans1 sm1
                WHERE SL2.Codscenariu   = SCENARIU
                  and L0.CODSCENARIU    = SL2.Codscenariu
                  and L0.Codcmd1        = SL2.Codcomanda1
                  and sm1.codcomanda1   = sl2.codcomanda1
                  and sm1.codproiectnod = sl2.codproiectnod
                  and L1.CodLansare0    = L0.CodLansare0
                  and L1.CODPROIECTNOD  = SL2.Codproiectnod
                  and sm1.DATASTART is not Null
               )
  LOOP
    UPDATE Comanda1 SET DataStart = V_REC.DataStart WHERE CodComanda1 = V_REC.CodCmd1;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_bool_evaluate</obj_name>
  <obj_hashval>5307aabfa7a692a032a18ee421900174</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_bool_evaluate(INOUT wme_result numeric, INOUT exp character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  Rez     numeric;
  sSelect varchar;
BEGIN
  BEGIN
    sSelect := 'select 1 where ' || Exp;
  EXECUTE sSelect;
    WME_Result :=  1;
    RETURN;
  END;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_completeazasabloane</obj_name>
  <obj_hashval>5898f80c2cb41ffb88601f49b61d9ad3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_completeazasabloane()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 14.01.2021 - adaugat sectiunea set_config
  PERFORM SET_CONFIG('PKG_SITFIN.tcA'             , 1::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcB'             , 2::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcSoldI'         , 3::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcSoldF'         , 4::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcRulCumAC'      , 5::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcRulCumAP'      , 6::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcSoldFInchideri', 7::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcIntrodusa'     , 8::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcPrecSoldI'     , 9::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcPrecSoldIAj'   , 10::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcPrecSoldICuAj' , 11::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcCurSoldI'      , 12::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcCurSoldIAj'    , 13::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcCurSoldICuAj'  , 14::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcPrecRulCum'    , 15::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcPrecRulCumAj'  , 16::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcPrecRulCumCuAj', 17::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcCurRulCum'     , 18::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcCurRulCumAj'   , 19::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcCurRulCumCuAj' , 20::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcPrecTotal'     , 21::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcPrecTotalAj'   , 22::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcPrecTotalCuAj' , 23::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcCurTotal'      , 24::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcCurTotalAj'    , 25::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcCurTotalCuAj'  , 26::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcPrecSoldF'     , 27::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcPrecSoldFAj'   , 28::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcPrecSoldFCuAj' , 29::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcCurSoldF'      , 30::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcCurSoldFAj'    , 31::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcCurSoldFCuAj'  , 32::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcObs'           , 33::VARCHAR, FALSE);
  PERFORM SET_CONFIG('PKG_SITFIN.tcRulAC'         , 35::VARCHAR, FALSE);

  DELETE FROM TMP_SABLCOL;
  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcA', true)::NUMERIC             ,  1, 'A - Denumire indicator');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcB', true)::NUMERIC             ,  2, 'B - Numar rand');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcSoldI', true)::NUMERIC         ,  3, 'Balanta: Solduri initiale');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcSoldF', true)::NUMERIC         ,  4, 'Balanta: Solduri finale');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcRulCumAC', true)::NUMERIC      ,  5, 'Balanta: Rulaje cumulate - an curent');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcRulCumAP', true)::NUMERIC      ,  6, 'Balanta: Rulaje cumulate - an precedent');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcSoldFInchideri', true)::numeric,  7, 'Solduri fara inchiderere');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcIntrodusa', true)::NUMERIC     ,  8, 'Introdusa');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcPrecSoldI', true)::NUMERIC     ,  9, 'Balanta: Solduri initiale - perioada precedenta');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcPrecSoldIAj', true)::NUMERIC   , 10, 'Balanta: Solduri initiale - perioada precedenta - ajustari');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcPrecSoldICuAj', true)::NUMERIC , 11, 'Balanta: Solduri initiale - perioada precedenta - valori cu ajustari');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcCurSoldI', true)::NUMERIC      , 12, 'Balanta: Solduri initiale - perioada actuala');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcCurSoldIAj', true)::NUMERIC    , 13, 'Balanta: Solduri initiale - perioada actuala - ajustari');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcCurSoldICuAj', true)::NUMERIC  , 14, 'Balanta: Solduri initiale - perioada actuala - valori cu ajustari');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcPrecRulCum', true)::NUMERIC    , 15, 'Balanta: Rulaje cumulate - perioada precedenta');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcPrecRulCumAj', true)::NUMERIC  , 16, 'Balanta: Rulaje cumulate - perioada precedenta - ajustari');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcPrecRulCumCuAj', true)::numeric, 17, 'Balanta: Rulaje cumulate - perioada precedenta - valori cu ajustari');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcCurRulCum', true)::NUMERIC     , 18, 'Balanta: Rulaje cumulate - perioada actuala');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcCurRulCumAj', true)::NUMERIC   , 19, 'Balanta: Rulaje cumulate - perioada actuala - ajustari');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcCurRulCumCuAj', true)::NUMERIC , 20, 'Balanta: Rulaje cumulate - perioada actuala - valori cu ajustari');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcPrecTotal', true)::NUMERIC     , 21, 'Balanta: Total sume - perioada precedenta');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcPrecTotalAj', true)::NUMERIC   , 22, 'Balanta: Total sume - perioada precedenta - ajustari');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcPrecTotalCuAj', true)::NUMERIC , 23, 'Balanta: Total sume - perioada precedenta - valori cu ajustari');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcCurTotal', true)::NUMERIC      , 24, 'Balanta: Total sume - perioada actuala');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcCurTotalAj', true)::NUMERIC    , 25, 'Balanta: Total sume - perioada actuala - ajustari');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcCurTotalCuAj', true)::NUMERIC  , 26, 'Balanta: Total sume - perioada actuala - valori cu ajustari');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcPrecSoldF', true)::NUMERIC     , 27, 'Balanta: Solduri finale - perioada precedenta');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcPrecSoldFAj', true)::NUMERIC   , 28, 'Balanta: Solduri finale - perioada precedenta - ajustari');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcPrecSoldFCuAj', true)::NUMERIC , 29, 'Balanta: Solduri finale - perioada precedenta - valori cu ajustari');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcCurSoldF', true)::NUMERIC      , 30, 'Balanta: Solduri finale - perioada actuala');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcCurSoldFAj', true)::NUMERIC    , 31, 'Balanta: Solduri finale - perioada actuala - ajustari');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcCurSoldFCuAj', true)::NUMERIC  , 32, 'Balanta: Solduri finale - perioada actuala - valori cu ajustari');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcObs', true)::NUMERIC           , 33, 'Observatii');

  INSERT INTO TMP_SABLCOL(CodSablon, IndexLocal, Denumire)
  VALUES(current_setting('PKG_SITFIN.tcRulAC', true)::NUMERIC         , 34, 'Balanta: Rulaje curente - an curent');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_evaluate</obj_name>
  <obj_hashval>25d7630ae6dc56873f0240d6f1c00a44</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_evaluate(INOUT wme_result boolean, INOUT expr character varying, INOUT val numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aVal double precision;
BEGIN
  BEGIN
    EXECUTE 'SELECT ' || Expr into AVAL;
    Val := aVal;
    WME_Result :=  True;
    RETURN;
  EXCEPTION WHEN OTHERS THEN
    Val := -1;
    WME_Result :=  False;
    RETURN;
  END;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_getcodsitfinbycodf</obj_name>
  <obj_hashval>873f9271b2d37b60719bb503a378aaec</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_getcodsitfinbycodf(INOUT wme_result numeric, INOUT acodf character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCodSitFin numeric;
BEGIN
  BEGIN
    EXECUTE 'SELECT coalesce(CodSitFin, 0) FROM SITFIN WHEN CodF = ''' || coalesce(aCodF::varchar ,'') || '''' INTO aCodSitFin;
  EXCEPTION WHEN others THEN
    aCodSitFin := 0;
  END;
  WME_Result :=  aCodSitFin;
  RETURN;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_getexprprelucrata</obj_name>
  <obj_hashval>a1fbd115108eadff23c905fc7f90a819</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_getexprprelucrata(INOUT wme_result character varying, INOUT expr character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  i       numeric;
  T       varchar;
  Simbol  varchar;
  Operand varchar;
BEGIN
  i := 1;
  T := '';

  WHILE i &lt;= Length(Expr)
  LOOP
    IF (SUBSTR(Expr, i, 1) = '+') or (SUBSTR(Expr, i, 1) = '-') or (SUBSTR(Expr, i, 1) = '*') or (SUBSTR(Expr, i, 1) = '/')
    OR (SUBSTR(Expr, i, 1) = '(') or (SUBSTR(Expr, i, 1) = ')') THEN
      T := T||SUBSTR(Expr, i, 1);
      i := i + 1;
    ELSE
      Operand := '';
      while ((i &lt;= Length(Expr) and (not ((SUBSTR(Expr, i, 1) = '+') or (SUBSTR(Expr, i, 1) = '-') or (SUBSTR(Expr, i, 1) = '*') or (SUBSTR(Expr, i, 1) = '/')
            or (SUBSTR(Expr, i, 1) = '(') or (SUBSTR(Expr, i, 1) = ')')))))
      loop
        Operand := Operand||SUBSTR(Expr, i, 1);
        i := i + 1;
      end loop;

      if (Substr(Operand, Length(Operand), 1) = 'D') or (Substr(Operand, Length(Operand), 1) = 'C') then
        Simbol := Substr(Operand, 1, Length(Operand) - 1);
        if Simbol &lt;&gt; '' then
          T := T||Simbol||Substr(Operand, Length(Operand), 1);
        else
          T := T||'???'||Substr(Operand, Length(Operand), 1);
        end if;
      else
        T := T||Operand;
      end if;
    end if;
  END LOOP;

  WME_Result :=  T;
  RETURN;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettca</obj_name>
  <obj_hashval>39a13e11bb64318493b71de5347c7e52</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettca(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcA')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 1;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettcb</obj_name>
  <obj_hashval>c61d300aa8b2fd29baa0eddf23afe3e2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettcb(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcB')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 2;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettccurrulcum</obj_name>
  <obj_hashval>eef3f6473596fc371e46a119097d9208</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettccurrulcum(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurRulCum')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 18;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettccurrulcumaj</obj_name>
  <obj_hashval>f0817ebe5b2bcb72610c270ca0551f37</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettccurrulcumaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurRulCumAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 19;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettccurrulcumcuaj</obj_name>
  <obj_hashval>a979aa8e5d42213872fdcc1700bffdf6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettccurrulcumcuaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurRulCumCuAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 20;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettccursoldf</obj_name>
  <obj_hashval>19fbeb61b8fd396bd1543769dd8f5ce2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettccursoldf(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurSoldF')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 30;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettccursoldfaj</obj_name>
  <obj_hashval>e38fc0fbe4111fb216c5fbf2468a9714</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettccursoldfaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurSoldFAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 31;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettccursoldfcuaj</obj_name>
  <obj_hashval>bb24414565e3d0b23abb8931c58db35b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettccursoldfcuaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurSoldFCuAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 32;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettccursoldi</obj_name>
  <obj_hashval>3fe050632be67413554a8715b1f928cf</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettccursoldi(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurSoldI')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 12;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettccursoldiaj</obj_name>
  <obj_hashval>c93ed9a7d64be07a5e927006eb11e573</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettccursoldiaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurSoldIAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 13;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettccursoldicuaj</obj_name>
  <obj_hashval>dd85ebaa4fb7f6fe4c3e2f74e8063580</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettccursoldicuaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurSoldICuAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 14;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettccurtotal</obj_name>
  <obj_hashval>0a2680d8523166187939007f4f8aca0b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettccurtotal(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurTotal')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 24;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettccurtotalaj</obj_name>
  <obj_hashval>7012e0ec9e2baa1d03607e16aea81c76</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettccurtotalaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurTotalAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 25;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettccurtotalcuaj</obj_name>
  <obj_hashval>6e5237cd0d5a174418b1204e33eece90</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettccurtotalcuaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurTotalCuAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 26;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettcintrodusa</obj_name>
  <obj_hashval>3055ca723b8ad1f6862eab9a5b6d4fa6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettcintrodusa(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcIntrodusa')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 8;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettcobs</obj_name>
  <obj_hashval>de2098f103f8be87555bf35b110228bc</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettcobs(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcObs')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 33;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettcprecrulcum</obj_name>
  <obj_hashval>863783a057ef24b97ee521fc055d8655</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettcprecrulcum(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecRulCum')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 15;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettcprecrulcumaj</obj_name>
  <obj_hashval>aba625ff45e6d16d535d4d517b0571aa</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettcprecrulcumaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecRulCumAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 16;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettcprecrulcumcuaj</obj_name>
  <obj_hashval>d133f3c55f48dfb1553ab6dcb02a23b6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettcprecrulcumcuaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecRulCumCuAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 17;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettcprecsoldf</obj_name>
  <obj_hashval>31c9e0b48553112e16f7cb0018edc0a1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettcprecsoldf(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecSoldF')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 27;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettcprecsoldfaj</obj_name>
  <obj_hashval>c1c97e89ed7c88d7f0a2b6df124f6614</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettcprecsoldfaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecSoldFAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 28;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettcprecsoldfcuaj</obj_name>
  <obj_hashval>5e3e8a928fb451cea9030bda884009f7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettcprecsoldfcuaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecSoldFCuAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 29;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettcprecsoldi</obj_name>
  <obj_hashval>58b476898638b5fc308a17fa627306ed</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettcprecsoldi(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecSoldI')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 9;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettcprecsoldiaj</obj_name>
  <obj_hashval>daceea6ad6798902a14c92a531277c34</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettcprecsoldiaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecSoldIAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 10;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettcprecsoldicuaj</obj_name>
  <obj_hashval>e480040a3ea117aaf4dd04d5b04db991</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettcprecsoldicuaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecSoldICuAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 11;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettcprectotal</obj_name>
  <obj_hashval>f49bba572c326a964f76a7c3887808df</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettcprectotal(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecTotal')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 21;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettcprectotalaj</obj_name>
  <obj_hashval>966669ef01272b6c06a3cabe03242fd5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettcprectotalaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecTotalAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 22;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettcprectotalcuaj</obj_name>
  <obj_hashval>98799f565dc83e2172bfea4b8fa84550</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettcprectotalcuaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecTotalCuAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 23;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettcrulac</obj_name>
  <obj_hashval>ba525b6759cdae7d09a4231d69fb075d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettcrulac(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcRulAC')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 35;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettcrulcumac</obj_name>
  <obj_hashval>39d4565d0b37baa515d23f159fc1a6fc</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettcrulcumac(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcRulCumAC')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 5;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettcrulcumap</obj_name>
  <obj_hashval>81088e629582219892ba9b3de43665c3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettcrulcumap(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcRulCumAP')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 6;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettcsoldf</obj_name>
  <obj_hashval>0887bb8bd6779db3e29c54098b219c44</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettcsoldf(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcSoldF')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 4;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettcsoldfinchideri</obj_name>
  <obj_hashval>09818f7c1840ed9184fe58fdab6d9712</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettcsoldfinchideri(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcSoldFInchideri')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 7;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_gettcsoldi</obj_name>
  <obj_hashval>75e35cdcd433f65f2bfa988f61c03105</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_gettcsoldi(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcSoldI')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 3;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settccurrulcum</obj_name>
  <obj_hashval>08862b5b124a705f2a208e249161ee09</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settccurrulcum(atccurrulcum numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcCurRulCum',to_char(atcCurRulCum,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settccurrulcumaj</obj_name>
  <obj_hashval>2c82a2cc0a71f6a58607235f54840797</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settccurrulcumaj(atccurrulcumaj numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcCurRulCumAj',to_char(atcCurRulCumAj,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settccurrulcumcuaj</obj_name>
  <obj_hashval>6a30e73ab9d35abc830a95b08d403b3b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settccurrulcumcuaj(atccurrulcumcuaj numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcCurRulCumCuAj',to_char(atcCurRulCumCuAj,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settccursoldf</obj_name>
  <obj_hashval>b7415d31831b83929b69b732e29899db</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settccursoldf(atccursoldf numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcCurSoldF',to_char(atcCurSoldF,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settccursoldfaj</obj_name>
  <obj_hashval>f5fc3c4fd96b64243ae53146cf281c2a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settccursoldfaj(atccursoldfaj numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcCurSoldFAj',to_char(atcCurSoldFAj,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settccursoldfcuaj</obj_name>
  <obj_hashval>927271dda0ac8600638e290dee7c5543</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settccursoldfcuaj(atccursoldfcuaj numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcCurSoldFCuAj',to_char(atcCurSoldFCuAj,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settccursoldi</obj_name>
  <obj_hashval>39dfd5ec3870864113bb0fff2e8a0649</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settccursoldi(atccursoldi numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcCurSoldI',to_char(atcCurSoldI,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settccursoldiaj</obj_name>
  <obj_hashval>f0f6764ee0959740faff529209f1bc57</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settccursoldiaj(atccursoldiaj numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcCurSoldIAj',to_char(atcCurSoldIAj,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settccursoldicuaj</obj_name>
  <obj_hashval>8d295f4cae358c6d00c8864a342de8ba</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settccursoldicuaj(atccursoldicuaj numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcCurSoldICuAj',to_char(atcCurSoldICuAj,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settcobs</obj_name>
  <obj_hashval>912d85429ca1cde172fb3dd8a978a900</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settcobs(atcobs numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcObs',to_char(atcObs,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settcprecrulcum</obj_name>
  <obj_hashval>c8531d6ca99489ecb8d7e4c7a89cce41</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settcprecrulcum(atcprecrulcum numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcPrecRulCum',to_char(atcPrecRulCum,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settcprecrulcumaj</obj_name>
  <obj_hashval>0324407e2726d743362d11ee76116398</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settcprecrulcumaj(atcprecrulcumaj numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcPrecRulCumAj',to_char(atcPrecRulCumAj,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settcprecsoldf</obj_name>
  <obj_hashval>9bb5a3d6937fb80138208135b48330ee</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settcprecsoldf(atcprecsoldf numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcPrecSoldF',to_char(atcPrecSoldF,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settcprecsoldfaj</obj_name>
  <obj_hashval>30e1a96051ca75f37096dab8b448e065</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settcprecsoldfaj(atcprecsoldfaj numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcPrecSoldFAj',to_char(atcPrecSoldFAj,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settcprecsoldfcuaj</obj_name>
  <obj_hashval>78163cf14a83986065d60d8b6e27de8a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settcprecsoldfcuaj(atcprecsoldfcuaj numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcPrecSoldFCuAj',to_char(atcPrecSoldFCuAj,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settcprecsoldi</obj_name>
  <obj_hashval>b7fdcfb8e326ca2a92ca2f568e9efc5b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settcprecsoldi(atcprecsoldi numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcPrecSoldI',to_char(atcPrecSoldI,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settcprecsoldiaj</obj_name>
  <obj_hashval>f70dde95b53686a4dff730087b6de611</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settcprecsoldiaj(atcprecsoldiaj numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcPrecSoldIAj',to_char(atcPrecSoldIAj,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settcprecsoldicuaj</obj_name>
  <obj_hashval>6c646617a12b7b234e3cfcc4b0357f15</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settcprecsoldicuaj(atcprecsoldicuaj numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcPrecSoldICuAj',to_char(atcPrecSoldICuAj,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settcprectotal</obj_name>
  <obj_hashval>17e5a4369907a5712549778415535072</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settcprectotal(atcprectotal numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcPrecTotal',to_char(atcPrecTotal,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settcprectotalaj</obj_name>
  <obj_hashval>cc094584559d14e4315e1ca174e8eb35</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settcprectotalaj(atcprectotalaj numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcPrecTotalAj',to_char(atcPrecTotalAj,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settcprectotalcuaj</obj_name>
  <obj_hashval>fbd744e8e754de0e2fa23cac9aef0431</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settcprectotalcuaj(atcprectotalcuaj numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcPrecTotalCuAj',to_char(atcPrecTotalCuAj,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settcrulac</obj_name>
  <obj_hashval>b207bf9aa83524e0ce83e788d41bf6bf</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settcrulac(atcrulac numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcRulAC',to_char(atcRulAC,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settcrulcumac</obj_name>
  <obj_hashval>d72665598cf06a957c9fae7127b228b7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settcrulcumac(atcrulcumac numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcRulCumAC',to_char(atcRulCumAC,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settcrulcumap</obj_name>
  <obj_hashval>350f682aeaec94a8582ab9aa2f1be2d1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settcrulcumap(atcrulcumap numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcRulCumAP',to_char(atcRulCumAP,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settcsoldf</obj_name>
  <obj_hashval>5d3a3d1a39534e277898378ae193a6dd</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settcsoldf(atcsoldf numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcSoldF',to_char(atcSoldF,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settcsoldfinchideri</obj_name>
  <obj_hashval>d928f47a7d5f3054d3dccbe6aa7cb679</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settcsoldfinchideri(atcsoldfinchideri numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcSoldFInchideri',to_char(atcSoldFInchideri,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_sp_deleterecord</obj_name>
  <obj_hashval>b02c87f01c8a8fd1fbc1a54e817e7891</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Adina 21.12.2020 - sincronizare cu Oracle
  PERFORM PKG_SITFIN_SP_LOCKRECORD(RecId);
  DELETE FROM CORELAT1    WHERE CodSitFin = RecId;
  DELETE FROM CORELAT2    WHERE CodSitFin = RecId;
  DELETE FROM CONDCOR1    WHERE CodSitFin = RecId;
  DELETE FROM SITFINBUGET WHERE CodSitFin = RecId;
  DELETE FROM SITFINBUGET WHERE CodSitFin = RecId;
  DELETE FROM SITFINLIN   WHERE CodSitFin = RecId;
  DELETE FROM SITFINCOL   WHERE CodSitFin = RecId;
  DELETE FROM SITFINALTE  WHERE CodSitFin = RecId;
  DELETE FROM SITFIN      WHERE CodSitFin = RecId;
  PERFORM NotifyModif(2, RecId, 'SITFIN');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_sp_gotorecord</obj_name>
  <obj_hashval>a7c7dd85be86c5e1002ee5cc802acd7a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 01.08.2025 - sinc. Oracle
  --Adina 04.03.2021 - sinc.Oracle din 03.03.2021
  --Adina 21.12.2020 sincronizare cu Oracle
  PERFORM PKG_SITFIN_CompleteazaSabloane();
  INSERT INTO TMP_SITFIN(CodSitFin, CodF, Denumire, Sectiune, UserId, DataCreare, Tip, TipPlan, PeLuni)
  (
   SELECT CodSitFin, CodF, Denumire, Sectiune, UserId, DataCreare, Tip, COALESCE(TipPlan, 0), COALESCE(PeLuni, 0)
   FROM SITFIN
   WHERE CodSitFin = RecId
  );

  INSERT INTO TMP_SITFINSEC(CodSitFin, CodF, Denumire, Sectiune)
  (SELECT CodSitFin, CodF, Denumire, Sectiune FROM SITFIN WHERE CodSitFin = RecId);

  INSERT INTO TMP_SITFINCOL(CodColoana, CodSitFin, NrCol, Denumire, TipCol, Corelatie, IdentificatorCol, DenTipCol, flgExport, Conta)
  (
   SELECT *
   FROM (SELECT BC.CodColoana CODCOLOANA, BC.CodSitFin CODSITFIN, BC.NrCol NRCOL, BC.Denumire DENUMIRE, BC.TipCol TIPCOL,
                BC.Corelatie CORELATIE, BC.IDENTIFICATORCOL IDENTIFICATORCOL, SC.Denumire DENTIPCOL, BC.Flgexport, coalesce(BC.Conta,0)
         FROM SITFINCOL BC
              INNER JOIN TMP_SABLCOL SC ON  BC.TipCol = SC.CodSablon
         WHERE CodSitFin = RecId
         ORDER BY NrCol
        ) A_PG
  );

  INSERT INTO TMP_SITFINLIN(CodLinie, CodSitFin, NrLinie, Denumire, Total, Corelatie, Rnd, TipConta, CorSimb, Obs, ValSuplim, FaraNegative)
  (
   SELECT *
   FROM (SELECT SF.CodLinie, SF.CodSitFin,
                row_number() over() Num,
                SF.Denumire, SF.Total, SF.Corelatie, SF.Rnd, COALESCE(SF.TipConta, 0), SF.Corelatie CODSIMB, SF.Obs, SF.ValSuplim, SF.FaraNegative
         FROM SITFINLIN SF
         WHERE SF.CodSitFin = RecId
         ORDER BY SF.NrLinie
        ) B_PG
  );

  INSERT INTO tmp_sitfinbuget(codsitfinbuget,codsitfinlin,codsitfin,an,luna,valoare)
  SELECT codsitfinbuget,codsitfinlin,codsitfin,an,luna,valoare
  FROM sitfinbuget
  WHERE codsitfin = recid;

  INSERT INTO TMP_SITFINALTE(CODALTE, CODSITFIN, FUNCTIE, RAND, COLOANA)
  SELECT CODALTE, CODSITFIN, FUNCTIE, RAND, COLOANA
  FROM SITFINALTE
  WHERE CODSITFIN = RECID;

  INSERT INTO TMP_CONDCOR1(CodCondCor1, CodSitFin, IndexLocal, Rnd1, Col1, Rel, Rnd2, Col2)
  (SELECT CodCondCor1, CodSitFin, IndexLocal, Rnd1, Col1, Rel, Rnd2, Col2 FROM CONDCOR1 WHERE CodSitFin = RecId);

  INSERT INTO TMP_CORELAT1(CodCorelat1, CodSitFin, IndexLocal, Rnd1, Col1, Rel, Rnd2, Col2, Cond, IsNumeric)
  (SELECT CodCorelat1, CodSitFin, IndexLocal, Rnd1, Col1, Rel, Rnd2, Col2, Cond, IsNumeric FROM CORELAT1 WHERE CodSitFin = RecId);

  INSERT INTO TMP_CORELAT2(CodCorelat2, CodSitFin, CodF1, Rnd1, Col1, CodF2, Rnd2, Col2, Cod1, Cod2)
  (
   SELECT C2.CodCorelat2, C2.CodSitFin, C2.CodF1, C2.Rnd1, C2.Col1, C2.CodF2, C2.Rnd2, C2.Col2, S1.CODF, S2.CODF
   FROM CORELAT2 C2
        LEFT JOIN SITFIN S1 ON S1.CODSITFIN = C2.CODF1
        LEFT JOIN SITFIN S2 ON S2.CODSITFIN = C2.CODF2
   WHERE C2.CodSitFin = RecId
  );
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_sp_insertrecord</obj_name>
  <obj_hashval>07977c6be2269b39313373d34562fe9a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Adina 20.03.2021 -sinc.Oracle - scos INSERT INTO TMP_CORELAT2
  INSERT INTO TMP_SITFIN (CodSitFin, TipPlan) VALUES(0, 0);

--  INSERT INTO TMP_CORELAT2(CODCORELAT2, CODF1, RND1, COL1, CODF2, RND2, COL2, COD1, COD2)
--  SELECT CODCORELAT2, CODF1, RND1, COL1, CODF2, RND2, COL2, (SELECT PKG_SITFIN_GetCodSitFinByCodF.WME_RESULT FROM PKG_SITFIN_GetCodSitFinByCodF(NULL,CodF1::varchar)), (SELECT PKG_SITFIN_GetCodSitFinByCodF.WME_RESULT FROM PKG_SITFIN_GetCodSitFinByCodF(NULL,CodF2::varchar))
--  FROM CORELAT2;

  PERFORM pkg_sitfin_CompleteazaSabloane();
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tca</obj_name>
  <obj_hashval>d29f5e7797b7090bc4bf461998647a4b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tca(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcA')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 1;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tcb</obj_name>
  <obj_hashval>cd512873e4d3b8a10cf2e35afdeb3238</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tcb(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcB')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 2;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tccurrulcum</obj_name>
  <obj_hashval>4a2637725e5f6d3421868c2c29c802fc</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tccurrulcum(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurRulCum')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 18;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tccurrulcumaj</obj_name>
  <obj_hashval>44d470390f3c8c90d0f20a9c30b20135</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tccurrulcumaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurRulCumAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 19;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tccurrulcumcuaj</obj_name>
  <obj_hashval>e56c96ed7a15592fe4c24190403ace78</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tccurrulcumcuaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurRulCumCuAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 20;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tccursoldf</obj_name>
  <obj_hashval>cf19afed3ef1e701f2a8764e5c377dbb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tccursoldf(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurSoldF')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 30;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tccursoldfaj</obj_name>
  <obj_hashval>1dd189b34b377ce3fce2f412d4fa4f6f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tccursoldfaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurSoldFAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 31;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tccursoldfcuaj</obj_name>
  <obj_hashval>7b4e89aa16aba77525db113e8d5838ca</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tccursoldfcuaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurSoldFCuAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 32;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tccursoldi</obj_name>
  <obj_hashval>073f784a17d03fbb2e6937f2b17dd98a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tccursoldi(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurSoldI')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 12;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tccursoldiaj</obj_name>
  <obj_hashval>292b5092c4817bb0d40047d35d2e7074</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tccursoldiaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurSoldIAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 13;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tccursoldicuaj</obj_name>
  <obj_hashval>0a51a619bb60aee8b603f3e331fc8cb4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tccursoldicuaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurSoldICuAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 14;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tccurtotal</obj_name>
  <obj_hashval>96bf86462092bd55525aac9dda5e782d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tccurtotal(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurTotal')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 24;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tccurtotalaj</obj_name>
  <obj_hashval>2a32ab2f0cfc54b6298a8cbf658f8b6a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tccurtotalaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurTotalAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 25;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tccurtotalcuaj</obj_name>
  <obj_hashval>ddef2e0cba00a309d2199b5d3f9a1819</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tccurtotalcuaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcCurTotalCuAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 26;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tcobs</obj_name>
  <obj_hashval>17f7dbd58b8054b58ebe5b268c66b3cd</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tcobs(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcObs')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 33;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tcprecrulcum</obj_name>
  <obj_hashval>597e7449351a6b81065e978069523756</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tcprecrulcum(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecRulCum')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 15;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tcprecrulcumaj</obj_name>
  <obj_hashval>15c53a9ee23de211b8ef8a59dfddc1b0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tcprecrulcumaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecRulCumAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 16;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tcprecrulcumcuaj</obj_name>
  <obj_hashval>f7f5989afefa38f15a2e8f9aff91f718</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tcprecrulcumcuaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecRulCumCuAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 17;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tcprecsoldf</obj_name>
  <obj_hashval>8549534f62f4153a53a4b34b2bd30ede</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tcprecsoldf(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecSoldF')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 27;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tcprecsoldfaj</obj_name>
  <obj_hashval>aabf4cc21137f804e142050b2acd4308</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tcprecsoldfaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecSoldFAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 28;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tcprecsoldfcuaj</obj_name>
  <obj_hashval>b6418b0ee24004350fc086ea2aa299b8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tcprecsoldfcuaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecSoldFCuAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 29;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tcprecsoldi</obj_name>
  <obj_hashval>d3095278435e1481766dc425870e2342</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tcprecsoldi(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecSoldI')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 9;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tcprecsoldiaj</obj_name>
  <obj_hashval>edd9828959415b490f9433351e09d841</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tcprecsoldiaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecSoldIAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 10;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tcprecsoldicuaj</obj_name>
  <obj_hashval>b19c855193262c57f2bf373ec14ba9d0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tcprecsoldicuaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecSoldICuAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 11;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tcprectotal</obj_name>
  <obj_hashval>05e2e7908cefe66ab902019e4c1c6642</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tcprectotal(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecTotal')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 21;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tcprectotalcuaj</obj_name>
  <obj_hashval>7e6630a413625772f5c0eba9a70f6863</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tcprectotalcuaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecTotalCuAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 23;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tcrulac</obj_name>
  <obj_hashval>01490a57447af0a174ba2f565c00a91f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tcrulac(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcRulAC')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 35;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tcrulcumac</obj_name>
  <obj_hashval>d0cdd3394aed757af223919167e165a9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tcrulcumac(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcRulCumAC')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 5;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tcrulcumap</obj_name>
  <obj_hashval>5fc16006807d6e5fc0c2f3157d393e44</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tcrulcumap(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcRulCumAP')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 6;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tcsoldf</obj_name>
  <obj_hashval>0b39cb88f5ddcbec3830c34fdef5e036</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tcsoldf(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcSoldF')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 4;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tcsoldfinchideri</obj_name>
  <obj_hashval>c16ccd08770670faa37f30326f85ec97</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tcsoldfinchideri(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcSoldFInchideri')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 7;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_testcoloane</obj_name>
  <obj_hashval>66cb5dc182bc2ef2bb9201ab03a7307e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_testcoloane(acodsitfin numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  aCount numeric;
BEGIN
  SELECT count( *) INTO aCount FROM sitfincol WHERE codsitfin = aCodSitFin and  COALESCE( nrcol, 0) = 0;

  IF  aCount &gt; 0 THEN
    FOR v_rec IN (SELECT codcoloana, rownum AS NRCOL
                  FROM (SELECT codcoloana FROM sitfincol WHERE codsitfin = aCodSitFin ORDER BY codcoloana) A_PG
                 )
    LOOP
      UPDATE sitfincol SET nrcol = v_rec.nrcol WHERE codcoloana = v_rec.codcoloana;
    END LOOP;
  END IF;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sms_sendsms_advert</obj_name>
  <obj_hashval>bf2fde5c4e8e32bb1756f45f207c9342</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sms_sendsms_advert(url_wmeservice character varying, telefon character varying, mesaj character varying, authkey character varying)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
declare
 aStatus  varchar;
 aContent varchar;
begin
  perform http_set_curlopt('CURLOPT_CONNECTTIMEOUT', '15');
  perform http_set_curlopt('CURLOPT_TIMEOUT', '15');

  SELECT status, content into astatus, aContent
  FROM http_post(URL_WMESERVICE,
  '{
    "Telefon":"'     || Telefon   ||'",
    "Mesaj":"'       || Mesaj     ||'",
    "AuthKey":"'     || AuthKey   ||'"
  }',

   'application/x-www-form-urlencoded');
   --delete from x;
   --insert into x(view_name) values (aContent);
   if instrb(aContent, '"ok"') &gt; 0 then
    return 1;
   else
    return 0;
   end if;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sms_sendsms_notifica</obj_name>
  <obj_hashval>e15db6f5e318f77a56e086d31e65f625</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sms_sendsms_notifica(url_wmeservice character varying, telefon character varying, mesaj character varying, api_key character varying, api_secret character varying)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
declare
 aStatus  varchar;
 aContent varchar;

begin
  perform http_set_curlopt('CURLOPT_CONNECTTIMEOUT', '15');
  perform http_set_curlopt('CURLOPT_TIMEOUT', '15');

  SELECT status, content into astatus, aContent
  FROM http_post(URL_WMESERVICE,
  '{
    "Telefon":"'     || Telefon    ||'",
    "Mesaj":"'       || Mesaj      ||'",
    "API_Key":"'     || API_Key    ||'",
    "API_Secret":"'  || API_Secret ||'"
  }',

   'application/x-www-form-urlencoded');
   --delete from x;
   --insert into x(view_name) values (aContent);
   if instrb(aContent, '"ok"') &gt; 0 then
    return 1;
   else
    return 0;
   end if;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sms_sendsms_orange</obj_name>
  <obj_hashval>b8a6e55479b31a4c42e30aa0c2b578f4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sms_sendsms_orange(url_wmeservice character varying, telefon character varying, username character varying, mesaj character varying, sender character varying, authkey character varying)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
declare
 aStatus  varchar;
 aContent varchar;

begin
  perform http_set_curlopt('CURLOPT_CONNECTTIMEOUT', '15');
  perform http_set_curlopt('CURLOPT_TIMEOUT', '15');

  SELECT status, content into astatus, aContent
  FROM http_post(URL_WMESERVICE,
  '{
    "Telefon":"'     || Telefon   ||'",
    "UserName":"'    || UserName  ||'",
    "Mesaj":"'       || Mesaj     ||'",
    "Sender":"'      || Sender    ||'",
    "UserName":"'    || UserName  ||'",
    "AuthKey":"'     || AuthKey   ||'"
  }',

   'application/x-www-form-urlencoded');
   --delete from x;
   --insert into x(view_name) values (aContent);
   if instrb(aContent, '"ok"') &gt; 0 then
    return 1;
   else
    return 0;
   end if;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_soldinitial_getoldcodpart</obj_name>
  <obj_hashval>6c9bd22d089cdb6b29669fce0004906a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_soldinitial_getoldcodpart(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SOLDINITIAL.OLDCODPART', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_soldinitial_linii_avize_ini_stinse</obj_name>
  <obj_hashval>cb8facf379025878e487945ef218e94f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_soldinitial_linii_avize_ini_stinse(INOUT wme_result numeric, INOUT acodpart numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  NR    numeric := 0;
begin
  DELETE FROM TMP_GENERAL;
  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
  FROM GENERAL G
  WHERE
    TIPDOC IN (2) AND
    (SELECT PARTENER FROM INTRARI I WHERE CODINTR = G.CODDOC) = aCODPART AND
    (SELECT I.AN * 12 + I.LUNA FROM INTRARI I WHERE CODINTR = G.CODDOC) &lt; TO_NUMBER((current_setting('PKG_GLOBALS.ANINITIAL', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_GLOBALS.LUNAINITIALA', true)),'999999999999999999');

  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
  FROM GENERAL G
  WHERE
    TIPDOC IN (20) AND
    (SELECT PARTENER FROM IESIRI I WHERE CODIES = G.CODDOC) = aCODPART AND
    (SELECT I.AN * 12 + I.LUNA FROM IESIRI I WHERE CODIES = G.CODDOC) &lt; TO_NUMBER((current_setting('PKG_GLOBALS.ANINITIAL', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_GLOBALS.LUNAINITIALA', true)),'999999999999999999');

  FOR V_REC IN (SELECT * FROM TMP_GENERAL) LOOP
    IF  V_REC.TIPDOC = 2 THEN
      NR := (SELECT PKG_INTRARI_AMFACTURALAAVIZ.WME_RESULT FROM PKG_INTRARI_AMFACTURALAAVIZ(NULL, V_REC.CODDOC));
    ELSE
      NR := (SELECT PKG_IESIRI_AMFACTURALAAVIZ.WME_RESULT FROM PKG_IESIRI_AMFACTURALAAVIZ(NULL, V_REC.CODDOC));
    END IF;

    IF  NR &lt;&gt; 0 THEN
      WME_Result :=  NR;
      RETURN;
    END IF;
  END LOOP;

  WME_Result :=  NR;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_soldinitial_oldcodpart</obj_name>
  <obj_hashval>506194fd01d4ec48b3d649775cda3fb9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_soldinitial_oldcodpart(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SOLDINITIAL.OLDCODPART', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_soldinitial_sold_ini_stinse</obj_name>
  <obj_hashval>ac3c1551d7ac54e8ac11a594216759f8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_soldinitial_sold_ini_stinse(INOUT wme_result numeric, INOUT acodpart numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  NR    numeric := 0;
begin
  DELETE FROM TMP_GENERAL;
  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
  FROM GENERAL G
  WHERE
    TIPDOC IN (1, 2, 3, 4, 5, 9) AND
    (SELECT PARTENER FROM INTRARI I WHERE CODINTR = G.CODDOC) = aCODPART AND
    (SELECT I.AN * 12 + I.LUNA FROM INTRARI I WHERE CODINTR = G.CODDOC) &lt; TO_NUMBER((current_setting('PKG_GLOBALS.ANINITIAL', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_GLOBALS.LUNAINITIALA', true)),'999999999999999999');

  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
  FROM GENERAL G
  WHERE
    TIPDOC IN (19, 20, 21, 22, 26) AND
    (SELECT PARTENER FROM IESIRI I WHERE CODIES = G.CODDOC) = aCODPART AND
    (SELECT I.AN * 12 + I.LUNA FROM IESIRI I WHERE CODIES = G.CODDOC) &lt; TO_NUMBER((current_setting('PKG_GLOBALS.ANINITIAL', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_GLOBALS.LUNAINITIALA', true)),'999999999999999999');

  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
  FROM GENERAL G
  WHERE
    TIPDOC IN (29, 30, 31, 33) AND  SEMNIFICATIE &lt;&gt; 800 AND  SEMNIFICATIE &lt;&gt; 801 AND
    (SELECT CODPART FROM TREZOR1 T WHERE CODTREZOR1 = G.CODDOC) = aCODPART AND
    (SELECT T.AN * 12 + T.LUNA FROM TREZOR1 T WHERE CODTREZOR1 = G.CODDOC) &lt; TO_NUMBER((current_setting('PKG_GLOBALS.ANINITIAL', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_GLOBALS.LUNAINITIALA', true)),'999999999999999999');

  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
  FROM GENERAL G, COMPENS C
  WHERE
     SEMNIFICATIE = 1303 AND TIPDOC IN (28) AND  C.CODCOMPENS = G.CODDOC AND  C.PARTD = aCODPART AND  C.PARTC = aCODPART AND
     C.AN * 12 + C.LUNA &lt; TO_NUMBER((current_setting('PKG_GLOBALS.ANINITIAL', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_GLOBALS.LUNAINITIALA', true)),'999999999999999999');

  FOR V_REC IN (SELECT OBF.CODGENERAL
                FROM TMP_GENERAL G, OBLIGPIF O, OBLIGPIF OBF
                WHERE G.SEMNIFICATIE = 1303 AND  O.CODGENERAL = G.CODGENERAL AND  OBF.CODOBLIGPIF = O.CODOBLIGASOCIAT
               )
  LOOP
    DELETE FROM TMP_GENERAL WHERE CODGENERAL = V_REC.CODGENERAL;
  END LOOP;

  SELECT COUNT( *) INTO NR FROM STINGERE
  WHERE VALOARE &lt;&gt; 0 AND
        CODSTINSPIF IN (SELECT CODOBLIGPIF FROM OBLIGPIF WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL));

  DELETE FROM TMP_GENERAL;

  WME_Result :=  NR;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_soldinitial_sp_lockrecord</obj_name>
  <obj_hashval>010c37694c51fd013456fe261f823c96</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_soldinitial_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMP numeric;
begin
  SELECT CODSOLDINI INTO TMP FROM SOLDINI WHERE CODSOLDINI = RECID FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_soldpersini_sp_deleterecord</obj_name>
  <obj_hashval>80c2977ee986ce29097e15f4025e91b9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_soldpersini_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCODPERS numeric;
  ANI      numeric;
  LUNAI    numeric;
BEGIN
  --Florin 14.07.2023 - fixat 58876
  SELECT CODPERS INTO aCODPERS FROM SOLDPERSINI WHERE CODSOLDPERSINI = RecID;

  SELECT NEWAN, NEWLUNA INTO ANI, LUNAI FROM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA(current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric, current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric, ANI, LUNAI);

  DELETE FROM NPERSSOLDLUNA    WHERE CODPERS = aCODPERS AND  AN = ANI AND  LUNA = LUNAI;
  DELETE FROM NPERSSOLDLUNASUB WHERE CODPERS = aCODPERS AND  AN = ANI AND  LUNA = LUNAI;
  DELETE FROM SOLDPERSINI      WHERE CODSOLDPERSINI = RECID;

  PERFORM NotifyModif(2, RecId, 'SOLDPERSINI');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_soldpersini_sp_gotorecord</obj_name>
  <obj_hashval>8d6987ffbc9b8fd40f0e372af4fe7d55</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_soldpersini_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  ANI        numeric;
  LUNAI      numeric;
  aCODPERS   numeric := 0;
  aCODIOPERS numeric := 0;
  NR         numeric := 0;
begin
  INSERT INTO TMP_SOLDPERSINI ( CODSOLDPERSINI, CODPERS )
  SELECT CODSOLDPERSINI, CODPERS FROM SOLDPERSINI WHERE CODSOLDPERSINI = RECID;

  select newan, newluna into ANI, LUNAI FROM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA(current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric, current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric, ANI, LUNAI);

  if RECID &gt; 0 then
    SELECT coalesce(CODPERS, 0) INTO aCODPERS FROM TMP_SOLDPERSINI;
  end if;

  begin
    SELECT count(*) INTO NR FROM NPERSSOLDLUNASUB WHERE CODPERS = aCODPERS and AN = ANI and LUNA = LUNAI;
  exception
    when others then NR := 0;
  end;

  if NR = 0 then
    INSERT INTO TMP_NPERSSOLDLUNA ( CODPERSSOLDLUNA, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA, SUBUNITATEA )
    SELECT CODPERSSOLDLUNA, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA, 2 FROM NPERSSOLDLUNA WHERE CODPERS = aCODPERS and AN = ANI and LUNA = LUNAI;
  else
    INSERT INTO TMP_NPERSSOLDLUNA ( CODPERSSOLDLUNA, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA, SUBUNITATEA )
    SELECT CODPERSSOLDLUNASUB, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA, SUBUNITATEA FROM NPERSSOLDLUNASUB WHERE CODPERS = aCODPERS and AN = ANI and LUNA = LUNAI;
  end if;

  UPDATE TMP_NPERSSOLDLUNA S
  SET
    SIMBOL = (SELECT PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT
              FROM   PKG_PLANCONTURI_GETSIMBOLCONT(null, (SELECT PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG.WME_RESULT
                                                          FROM   PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(null, 1100, S.ICONT,
                                                                                                      (SELECT PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA.WME_RESULT
                                                                                                       FROM   PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA(null, S.CODPERS,
                                                                                                                                                   current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric,
                                                                                                                                                   current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric)))))) ;

  UPDATE TMP_SOLDPERSINI SET SOLDTOTAL = (SELECT sum(SOLDLEI) FROM TMP_NPERSSOLDLUNA ) ;
 end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_soldpersini_sp_insertrecord</obj_name>
  <obj_hashval>8a94086272f7c9463f5b26cfb4e519a0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_soldpersini_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_SOLDPERSINI (CODSOLDPERSINI) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_soldpersini_sp_lockrecord</obj_name>
  <obj_hashval>dd059cb8ceec8ed0f9d5ff87eed6082a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_soldpersini_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMP numeric;
begin
  SELECT CODSOLDPERSINI INTO TMP FROM SOLDPERSINI WHERE CODSOLDPERSINI = RECID FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_soldpersini_sp_postrecords</obj_name>
  <obj_hashval>07bf857c42bd68c2e9f20f346890d7bf</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_soldpersini_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
declare
  aCODPERS numeric;
  ANI      numeric;
  LUNAI    numeric;
begin

  select NEWAN, NEWLUNA into ANI, LUNAI
  FROM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA(current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric, current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric, ANI, LUNAI);

  SELECT CODPERS INTO aCODPERS FROM TMP_SOLDPERSINI;

  if OPERATION = 0 then
    SELECT CODSOLDPERSINI INTO RecId FROM TMP_SOLDPERSINI;

    UPDATE SOLDPERSINI SET CODPERS = aCODPERS WHERE CODSOLDPERSINI = RecID ;

    DELETE FROM NPERSSOLDLUNA    WHERE AN = ANI and LUNA = LUNAI and CODPERS = aCODPERS;
    DELETE FROM NPERSSOLDLUNASUB WHERE AN = ANI and LUNA = LUNAI and CODPERS = aCODPERS;

    INSERT INTO NPERSSOLDLUNA ( CODPERSSOLDLUNA, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA )
    SELECT nextval('SEQ_NPERSSOLDLUNA_CODSOLDLUNA'), CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA
    FROM ( SELECT CODPERS, ICONT, CODMONEDA, AN, LUNA, sum(coalesce(SOLDLEI, 0)) as SOLDLEI, sum(coalesce(SOLDVALUTA, 0)) as SOLDVALUTA
           FROM TMP_NPERSSOLDLUNA group BY CODPERS, ICONT, CODMONEDA, AN, LUNA ) A_PG;

    INSERT INTO NPERSSOLDLUNASUB ( CODPERSSOLDLUNASUB, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA, SUBUNITATEA )
    SELECT nextval('SEQ_NPERSSOLDLUNASUB_COD'), CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA, SUBUNITATEA FROM TMP_NPERSSOLDLUNA;
  ELSE
    SELECT nextval('SEQ_SOLDPERSINI_CODSOLDPERSINI') INTO RECID;

    INSERT INTO SOLDPERSINI SELECT RECID, aCODPERS;

    INSERT INTO NPERSSOLDLUNA ( CODPERSSOLDLUNA, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA )
    SELECT nextval('SEQ_NPERSSOLDLUNA_CODSOLDLUNA'), CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA
    FROM (SELECT CODPERS, ICONT, CODMONEDA, AN, LUNA, sum(coalesce(SOLDLEI, 0)) as SOLDLEI, sum(coalesce(SOLDVALUTA, 0)) as SOLDVALUTA
          FROM TMP_NPERSSOLDLUNA group BY CODPERS, ICONT, CODMONEDA, AN, LUNA ) B_PG;

    INSERT INTO NPERSSOLDLUNASUB ( CODPERSSOLDLUNASUB, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA, SUBUNITATEA )
    SELECT nextval('SEQ_NPERSSOLDLUNASUB_COD'), CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA, SUBUNITATEA
    FROM TMP_NPERSSOLDLUNA;
  end if;

  perform NotifyModif(Operation, RecId, 'SOLDPERSINI');
 end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_splitchelt_sp_deleterecord</obj_name>
  <obj_hashval>e99a7e18967926697458dec7b3612b6c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_splitchelt_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_SPLITCHELT_SP_LOCKRECORD( RecId);
  DELETE FROM SPLITCHELT1 WHERE CodSPLITCHELT = RecId;
  DELETE FROM SPLITCHELT  WHERE CodSPLITCHELT = RecId;
  PERFORM NotifyModif( 2, RecId, 'SPLITCHELT');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_splitchelt_sp_gotorecord</obj_name>
  <obj_hashval>f94e75d11f9891ab8b28636db973bc51</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_splitchelt_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_SPLITCHELT(CODSPLITCHELT, TIPDOC, CODGest, CODCONT, CODCentru, CODOBIECT, OBS, AN, LUNA, SUBUNITATEA, FAZA, USERID, DATACREARE, ACTIV, Den_Obiect)
  (
  SELECT S.CODSPLITCHELT, S.TIPDOC, S.CODGest, S.CODCONT, S.CODCentru, S.CODOBIECT, S.OBS, S.AN, S.LUNA, S.SUBUNITATEA, S.FAZA, S.USERID, S.DATACREARE, S.ACTIV, OBJ.Denumire
  FROM SPLITCHELT S LEFT JOIN NARTOBJ OBJ ON  Obj.CODOBIECT = S.CODOBIECT
  WHERE CodSPLITCHELT = RecId
  );

  INSERT INTO TMP_SPLITCHELT1(CODSPLITCHELT1, CODSPLITCHELT, INDEXLOCAL, CODGEST, CODANALIZANOD, CODCENTRU, CODAUTO, CODFORMATIE, PROCENT, PUNCTE, OBS)
  SELECT CODSPLITCHELT1, CODSPLITCHELT, INDEXLOCAL, CODGEST, CODANALIZANOD, CODCENTRU, CODAUTO, CODFORMATIE, PROCENT, PUNCTE, OBS
  FROM SPLITCHELT1 WHERE CodSPLITCHELT = RecId ORDER BY INDEXLOCAL ;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_splitchelt_sp_lockrecord</obj_name>
  <obj_hashval>9867570c6f91098921509fde6c08e46c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_splitchelt_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CodSPLITCHELT INTO Tmp FROM SPLITCHELT WHERE CodSPLITCHELT = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_splitchelt_sp_postrecords</obj_name>
  <obj_hashval>9ba32904793e26a624434f14296e6d74</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_splitchelt_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  vCod numeric;
begin
  --Bogdan 29.09.2020
  BEGIN
    IF Operation = 0 THEN
      SELECT CodSPLITCHELT INTO RecId FROM TMP_SPLITCHELT;

      UPDATE SPLITCHELT
      SET
        (
          TIPDOC,
          CODGest,
          CODCONT,
          CODCentru,
          CODOBIECT,
          OBS,
          AN,
          LUNA,
          SUBUNITATEA,
          FAZA,
          ACTIV
        )
        = (SELECT TIPDOC,
            CODGest,
            CODCONT,
            CODCentru,
            CODOBIECT,
            OBS,
            AN,
            LUNA,
            SUBUNITATEA,
            FAZA,
            ACTIV
          FROM TMP_SPLITCHELT)
      WHERE
        CodSPLITCHELT = RecId;

      DELETE FROM SPLITCHELT1 WHERE CodSPLITCHELT = RecId AND CodSPLITCHELT1 NOT IN (SELECT CodSPLITCHELT1 FROM TMP_SPLITCHELT1);

      FOR v_rec IN (SELECT * FROM TMP_SPLITCHELT1 ORDER BY INDEXLOCAL) LOOP
        IF v_rec.CodSPLITCHELT1 &lt; 0 THEN
          SELECT NEXTVAL ('SEQ_SPLITCHELT1_CODSPLITCHELT1') INTO vCod;

          INSERT INTO SPLITCHELT1 (CODSPLITCHELT1,
              CODSPLITCHELT,
              INDEXLOCAL,
              CODGEST,
              CODCENTRU,
              CODANALIZANOD,
              CODAUTO,
              CODFORMATIE,
              PROCENT,
              PUNCTE,
              OBS)
            VALUES (vCod,
              RecID,
              v_rec.INDEXLOCAL,
              v_rec.CODGEST,
              v_rec.CODCENTRU,
              v_rec.CODANALIZANOD,
              v_rec.CODAUTO,
              v_rec.CODFORMATIE,
              v_rec.PROCENT,
              v_rec.PUNCTE,
              v_rec.OBS);
        ELSE
          UPDATE SPLITCHELT1
          SET
            INDEXLOCAL  = v_rec. INDEXLOCAL,
            CODGEST     = v_rec. CODGEST,
            CODCENTRU   = v_rec. CODCENTRU,
            CODAUTO     = v_rec. CODAUTO,
            CODFORMATIE = v_rec. CODFORMATIE,
            PUNCTE      = v_rec.PUNCTE,
            PROCENT     = v_rec.PROCENT,
            OBS         = v_rec. OBS
          WHERE
            CodSPLITCHELT1 = v_rec.CodSPLITCHELT1;
        END IF;
      END LOOP;
    ELSE
      SELECT NEXTVAL ('SEQ_SPLITCHELT_CODSPLITCHELT') INTO RECId;

      INSERT INTO SPLITCHELT (CODSPLITCHELT,
          TIPDOC,
          CODGest,
          CODCONT,
          CODCENTRU,
          CODOBIECT,
          OBS,
          AN,
          LUNA,
          SUBUNITATEA,
          FAZA,
          USERID,
          DATACREARE,
          ACTIV)
      SELECT RecId,
        TIPDOC,
        CODGest,
        CODCONT,
        CODCENTRU,
        CODOBIECT,
        OBS,
        AN,
        LUNA,
        SUBUNITATEA,
        FAZA,
        current_setting ('PKG_GLOBALS.USERID', true) ::numeric,
        CURRENT_TIMESTAMP,
        ACTIV
      FROM TMP_SPLITCHELT;

      FOR v_rec IN (SELECT * FROM TMP_SPLITCHELT1 ORDER BY INDEXLOCAL) LOOP
        SELECT NEXTVAL ('SEQ_SPLITCHELT1_CODSPLITCHELT1') INTO vCod;

        INSERT INTO SPLITCHELT1 (CODSPLITCHELT1,
            CODSPLITCHELT,
            INDEXLOCAL,
            CODGEST,
            CODCENTRU,
            CODANALIZANOD,
            CODAUTO,
            CODFORMATIE,
            PROCENT,
            PUNCTE,
            OBS)
          VALUES (vCod,
            RecID,
            v_rec.INDEXLOCAL,
            v_rec.CODGEST,
            v_rec.CODCENTRU,
            v_rec.CODANALIZANOD,
            v_rec.CODAUTO,
            v_rec.CODFORMATIE,
            v_rec.PROCENT,
            v_rec.PUNCTE,
            v_rec.OBS);
      END LOOP;
    END IF;

    PERFORM NotifyModif (Operation, RecId, 'SPLITCHELT');
  EXCEPTION
  WHEN OTHERS THEN
    BEGIN
      raise;
    END;
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_splittva_make_dincaretva_luna</obj_name>
  <obj_hashval>db698562207ebd04e6b610d4fa814e5d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_splittva_make_dincaretva_luna(acodpart numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
BEGIN
  --Adina 24 august 2020 - la aceasta data pe Oracle totul este comentat
/*
  DELETE FROM TMP_STINGERETVA_LUNA;
  IF  aCODPART = 0 THEN
    INSERT INTO TMP_STINGERETVA_LUNA(CODOBLIGPIF)
    SELECT CODOBLIGPIF
    FROM OBLIGPIFLUNA
    WHERE AN = getANTEMP() AND  LUNA = getLUNATEMP();
  ELSE
    INSERT INTO TMP_STINGERETVA_LUNA(CODOBLIGPIF)
    SELECT OL.CODOBLIGPIF
    FROM OBLIGPIFLUNA OL, OBLIGPIF O
    WHERE OL.AN = getANTEMP() AND  OL.LUNA = getLUNATEMP() AND  O.CODOBLIGPIF = OL.CODOBLIGPIF AND  O.CODPART = aCODPART;
  END IF;

  FOR V_REC IN
  (
    SELECT TS.CODOBLIGPIF, O.VALOARE, COALESCE( E.TVADOC, I.TVADOC) AS TVAOBLIG
    FROM  TMP_STINGERETVA_LUNA TS
          INNER JOIN OBLIGPIF O ON  O.CODOBLIGPIF = TS.CODOBLIGPIF
          INNER JOIN GENERAL G ON  G.CODGENERAL = O.CODGENERAL
          LEFT JOIN INTRARI I ON  I.TIPDOC = G.TIPDOC AND  I.CODINTR = G.CODDOC
          LEFT JOIN IESIRI E ON  E.TIPDOC = G.TIPDOC AND  E.CODIES = G.CODDOC
  )
  LOOP
    UPDATE TMP_STINGERETVA_LUNA
    SET
      VALOBLIG = COALESCE( V_REC.VALOARE, 0),
      TVAOBLIG = COALESCE( V_REC.TVAOBLIG, 0)
    WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
  END LOOP;

  UPDATE TMP_STINGERETVA_LUNA TS
  SET
    BEFORESPLIT = (
                    SELECT SUM( TS.TVAOBLIG * S.VALOARE / TS.VALOBLIG)
                    FROM  STINGERE S, OBLIGPIF O_STINGATOR, GENERAL G_STINGATOR
                          LEFT JOIN TREZOR1 T1 ON G_STINGATOR.TIPDOC IN (29, 30, 31) AND  T1.CODTREZOR1 = G_STINGATOR.CODDOC
                          LEFT JOIN COMPENS C ON  G_STINGATOR.TIPDOC = 28 AND  C.CODCOMPENS = G_STINGATOR.CODDOC
                    WHERE S.CODSTINSPIF = TS.CODOBLIGPIF AND
                          S.CODSTINGATORPIF = O_STINGATOR.CODOBLIGPIF AND
                          COALESCE( O_STINGATOR.SPLITTVAACTIV, 0) = 0 AND
                          O_STINGATOR.CODGENERAL = G_STINGATOR.CODGENERAL AND
                          COALESCE( T1.AN, C.AN) = getANTEMP() AND
                          COALESCE( T1.LUNA, C.LUNA) = getLUNATEMP()
                  )
  WHERE COALESCE( VALOBLIG, 0) &lt;&gt; 0;

  UPDATE TMP_STINGERETVA_LUNA TS
  SET
    AFTERSPLIT = (
                  SELECT SUM( COALESCE( S.DINCARETVA, 0))
                  FROM STINGERE S, OBLIGPIF O_STINGATOR, GENERAL G_STINGATOR, TREZOR1 T1
                  WHERE S.CODSTINSPIF = TS.CODOBLIGPIF AND
                        O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF AND
                        O_STINGATOR.CODGENERAL = G_STINGATOR.CODGENERAL AND
                        G_STINGATOR.TIPDOC IN (29, 30, 31) AND
                        T1.CODTREZOR1 = G_STINGATOR.CODDOC AND
                        T1.AN = getANTEMP() AND
                        T1.LUNA = getLUNATEMP()
                ) +
                (
                  SELECT SUM( COALESCE( S.DINCARETVA, 0))
                  FROM STINGERE S, OBLIGPIF O_STINGATOR, GENERAL G_STINGATOR, COMPENS C
                  WHERE S.CODSTINSPIF = TS.CODOBLIGPIF AND
                        O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF AND
                        O_STINGATOR.CODGENERAL = G_STINGATOR.CODGENERAL AND
                        G_STINGATOR.TIPDOC = 28 AND
                        C.CODCOMPENS = G_STINGATOR.CODDOC AND
                        C.AN = getANTEMP() AND
                        C.LUNA = getLUNATEMP()
                );

  FOR V_REC IN
  (
    SELECT OL.CODOBLIGPIF, COALESCE( OL_PREC.DINCARETVA, TS.TVAOBLIG) AS TVAOBLIG, COALESCE( TS.BEFORESPLIT, 0) + COALESCE( TS.AFTERSPLIT, 0) AS TVASTINS
    FROM  OBLIGPIFLUNA OL
          LEFT JOIN OBLIGPIFLUNA OL_PREC ON  OL.CODOBLIGPIF = OL_PREC.CODOBLIGPIF AND  OL_PREC.AN = TO_NUMBER((current_setting('PKG_GLOBALS.ANPRECEDENT', true)),'999999999999999999') AND  OL_PREC.LUNA = TO_NUMBER((current_setting('PKG_GLOBALS.LUNAPRECEDENTA', true)),'999999999999999999'), TMP_STINGERETVA_LUNA TS
    WHERE OL.AN = getANTEMP() AND  OL.LUNA = getLUNATEMP() AND  OL.CODOBLIGPIF = TS.CODOBLIGPIF
  )
  LOOP
    UPDATE OBLIGPIFLUNA OL
    SET DINCARETVA = ROUND( V_REC.TVAOBLIG - V_REC.TVASTINS, 2)
    WHERE OL.CODOBLIGPIF = V_REC.CODOBLIGPIF AND  OL.AN = getANTEMP() AND  OL.LUNA = getLUNATEMP();
  END LOOP;
*/
  NULL;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_splittva_make_dincaretva_luna_all</obj_name>
  <obj_hashval>b47019db9cf85781c3b5321512d33185</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_splittva_make_dincaretva_luna_all(acodpart numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  ANMIN     numeric;
  ANMAX     numeric;
  aANPREC   numeric;
  LUNAMIN   numeric;
  LUNAMAX   numeric;
  aLUNAPREC numeric;
BEGIN
  --Adina 24 august 2020 - la aceasta data pe Oracle totul este comentat
/*
  IF  aCODPART = 0 THEN
    SELECT AN, LUNA INTO ANMIN, LUNAMIN
    FROM obligpifluna
    WHERE an * 12 + luna = (SELECT MIN( AN * 12 + LUNA) FROM OBLIGPIFLUNA);

    SELECT AN, LUNA INTO ANMAX, LUNAMAX
    FROM obligpifluna
    WHERE an * 12 + luna = (SELECT MAX( AN * 12 + LUNA) FROM OBLIGPIFLUNA);
  ELSE
    SELECT AN, LUNA INTO ANMIN, LUNAMIN
    FROM obligpifluna OL, OBLIGPIF O
    WHERE OL.CODOBLIGPIF = O.CODOBLIGPIF AND  O.CODPART = aCODPART AND
          AN * 12 + LUNA = (SELECT MIN( AN * 12 + LUNA)
                            FROM OBLIGPIFLUNA OL, OBLIGPIF O
                            WHERE OL.CODOBLIGPIF = O.CODOBLIGPIF AND  O.CODPART = aCODPART);

    SELECT AN, LUNA INTO ANMAX, LUNAMAX
    FROM OBLIGPIFLUNA OL, OBLIGPIF O
    WHERE OL.CODOBLIGPIF = O.CODOBLIGPIF AND  O.CODPART = aCODPART AND
          AN * 12 + LUNA = (SELECT MAX( AN * 12 + LUNA)
                            FROM OBLIGPIFLUNA OL, OBLIGPIF O
                            WHERE OL.CODOBLIGPIF = O.CODOBLIGPIF AND  O.CODPART = aCODPART);
  END IF;
*/
  NULL;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_splittva_splittva_obligpart_intrari</obj_name>
  <obj_hashval>2959a764afb47856c984a22d7e153566</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_splittva_splittva_obligpart_intrari(acodpart numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  FOR V_REC IN
  (
    SELECT CODOBLIGPIF, VALOBLIG, TVAOBLIG, SUM( COALESCE( VALSTINSA, 0)) AS VALSTINSA, ROUND( SUM( COALESCE( TVASTINS, 0)), 2) AS TVASTINS
    FROM (SELECT O_STINS.CODOBLIGPIF, O_STINS.VALOBLIG, O_STINS.TVAOBLIG, S.VALOARE AS VALSTINSA, O_STINS.TVAOBLIG * S.VALOARE / O_STINS.VALOBLIG AS TVASTINS
          FROM STINGERE S, OBLIGPIF O_STINGATOR,
               (SELECT O.CODOBLIGPIF, O.VALOARE AS VALOBLIG, COALESCE( O.VALOARE * I.TVADOC / I.VALDOC, 0) AS TVAOBLIG
                FROM OBLIGPIF O, GENERAL G, INTRARI I
                WHERE O.CODPART = aCODPART AND O.SEMNIFICATIE IN (100) AND  O.CODGENERAL = G.CODGENERAL AND  G.TIPDOC = I.TIPDOC AND  G.CODDOC = I.CODINTR AND  O.REST &lt;&gt; 0 AND  COALESCE( O.DINCARETVA, 0) = 0
               ) O_STINS
          WHERE S.CODSTINGATORPIF = O_STINGATOR.CODOBLIGPIF AND  COALESCE( O_STINGATOR.SPLITTVAACTIV, 0) = 0 AND  O_STINS.CODOBLIGPIF = S.CODSTINSPIF AND  O_STINS.VALOBLIG &lt;&gt; 0
         ) A_PG
    GROUP BY CODOBLIGPIF, VALOBLIG, TVAOBLIG
  )
  LOOP
    UPDATE OBLIGPIF
    SET
    DINCARETVA = V_REC.TVAOBLIG - V_REC.TVASTINS,
    RESTTVA    = V_REC.TVAOBLIG - V_REC.TVASTINS
    WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_spvarhiva_checknewdata</obj_name>
  <obj_hashval>90b739d8bb487bd17616352d20af0b60</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_spvarhiva_checknewdata()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  V_REC       RECORD;
BEGIN
  --Florin 02.10.2024 - sinc. Oracle
  --Florin 28.08.2024 - sinc. Oracle
  --Florin 21.08.2024 - sinc. Oracle
  --Florin 14.08.2024 - sinc. Oracle
  --Florin 19.02.2024 - sinc. Oracle
  --Florin 14.02.2024 - sinc. Oracle
  --Florin 06.02.2024
  FOR V_REC in (SELECT T.*, SA.IDDESCARCARE AS OrigIdDescarcare,
                            SA.ID_DS AS OrigIDDS,
                            SA.CIF AS OrigCIF,
                            SA.DATADOCSPV AS OrigDataSPV,
                            SA.CIF_PARTENER AS OrigCIF_PARTENER,
                            SA.VAL_DOC_SPV AS OrigVAL_DOC_SPV,
                            SA.TVA_DOC_SPV AS OrigTVA_DOC_SPV,
                            SA.ID_DOC_SPV AS OrigID_DOC_SPV
                            FROM TMP_SPVARHIVA T
                            LEFT JOIN SPVARHIVA SA ON T.IDDESCARCARE = SA.IDDESCARCARE and t.tipdoc = sa.tipdoc)
  LOOP
    IF V_rec.OrigIdDescarcare IS NULL THEN
      INSERT INTO SPVARHIVA(CODSPVARHIVA,
                         AN,
                         LUNA,
                         IDDESCARCARE,
                         DATAINCARCARE,
                         ZIP,
                         TIPDOC,
                         ID_DS,
                         CIF,
                         DATADOCSPV,
                         CIF_PARTENER,
                         VAL_DOC_SPV,
                         TVA_DOC_SPV,
                         ID_DOC_SPV
                         )
                         VALUES(Nextval('SEQ_SPVARHIVA_CODSPVARHIVA'),
                                v_rec.AN,
                                v_rec.LUNA,
                                v_rec.IDDESCARCARE,
                                v_rec.DATAINCARCARE,
                                v_rec.ZIP,
                                v_rec.TIPDOC,
                                v_rec.ID_DS,
                                v_rec.CIF,
                                v_rec.DATADOCSPV,
                                v_rec.CIF_PARTENER,
                                v_rec.VAL_DOC_SPV,
                                v_rec.TVA_DOC_SPV,
                                v_rec.ID_DOC_SPV
                               );
        ELSE
          IF (V_rec.OrigIDDS IS NULL )THEN
                UPDATE SPVARHIVA SV SET ID_DS = v_rec.ID_DS
                           WHERE SV.IDDESCARCARE = V_rec.OrigIdDescarcare and sv.tipdoc = V_rec.tipdoc;
           END IF;
        IF (V_rec.OrigCIF IS NULL) THEN
                 UPDATE SPVARHIVA SV SET CIF = v_rec.CIF
                           WHERE SV.IDDESCARCARE = V_rec.OrigIdDescarcare and sv.tipdoc = V_rec.tipdoc;
        END IF;
        IF (V_rec.OrigDataSPV IS NULL)THEN
                 UPDATE SPVARHIVA SV SET DATADOCSPV = v_rec.DATADOCSPV
                           WHERE SV.IDDESCARCARE = V_rec.OrigIdDescarcare and sv.tipdoc = V_rec.tipdoc;
        END IF;
        IF (V_rec.OrigCIF_PARTENER IS NULL)THEN
            UPDATE SPVARHIVA SV SET CIF_PARTENER = v_rec.CIF_PARTENER
              WHERE SV.IDDESCARCARE = V_rec.OrigIdDescarcare;
        END IF;
        IF (V_rec.OrigVAL_DOC_SPV IS NULL) OR (V_rec.OrigTVA_DOC_SPV IS NULL) THEN
            UPDATE SPVARHIVA SV SET VAL_DOC_SPV = v_rec.VAL_DOC_SPV,
              TVA_DOC_SPV = v_rec.TVA_DOC_SPV
            WHERE SV.IDDESCARCARE = V_rec.OrigIdDescarcare and sv.tipdoc = V_rec.tipdoc;
        END IF;
        IF (V_rec.OrigID_DOC_SPV IS NULL)THEN
          UPDATE SPVARHIVA SV SET ID_DOC_SPV = v_rec.ID_DOC_SPV
          WHERE SV.IDDESCARCARE = V_rec.OrigIdDescarcare and sv.tipdoc = V_rec.tipdoc;
        END IF;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sqrcolect_sp_gotorecord</obj_name>
  <obj_hashval>c7c951d966c535a41fb683df0656feed</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sqrcolect_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 25.10.2024
  INSERT INTO  TMP_SGRCOLECT SELECT * FROM SGRCOLECT WHERE CODSGRCOLECT = RECID;
  INSERT INTO TMP_SGRCOLECT1(CODSGRCOLECT1,CODSGRCOLECT,CODOBIECT,PRET,CANT,DENUMIRE, VALOARE)
  SELECT
    C1.CODSGRCOLECT1,
    C1.CODSGRCOLECT,
    C1.CODOBIECT,
    C1.PRET,
    C1.CANT,
    O.DENUMIRE,
    C1.PRET * C1.CANT
  FROM
    SGRCOLECT1 C1
    LEFT JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
  WHERE
    C1.CODSGRCOLECT = RECID;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_statcon_sp_insertrecord</obj_name>
  <obj_hashval>0d13385001c98d52b9fb844f393133ab</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_statcon_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_StatCon (CodStatCon) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_statcon_sp_lockrecord</obj_name>
  <obj_hashval>e87013825aa067cca43d058ea68896d4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_statcon_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CodStatCon INTO Tmp FROM StatCon WHERE CodStatCon = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_statcon_sp_postrecords</obj_name>
  <obj_hashval>cede307164dff200e2dc1e4f7ce7174f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_statcon_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  IF  Operation = 0 THEN
    BEGIN
      SELECT CodStatCon INTO RECID FROM TMP_StatCon;
    EXCEPTION WHEN OTHERS THEN
      RECID := 0;
    END;

    UPDATE StatCon
    SET
    (CodEvalS, Atribut, Den_evaluare) = (SELECT S.CodEvalS, S.Atribut, I.Nume
                                         FROM TMP_StatCon S
                                            LEFT JOIN EvalS      E ON  E.Codevals      = S.Codevals
                                            LEFT JOIN IdentEvalS I ON  I.CodIdentEvalS = E.CodIdentEvalS
                                        )
    WHERE CodStatCon = RECID;
  ELSE
    SELECT NEXTVAL('SEQ_STATCON_CODSTATCON') INTO RecId;

    INSERT INTO StatCon(CodStatCon, CodEvalS, Atribut, Den_evaluare)
    SELECT RECID, S.CodEvalS, S.Atribut, I.Nume
    FROM TMP_StatCon S
        LEFT JOIN EvalS      E ON  E.Codevals      = S.Codevals
        LEFT JOIN IdentEvalS I ON  I.CodIdentEvalS = E.CodIdentEvalS;
  END IF;

  PERFORM NotifyModif( Operation, RecId, 'StatCon');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_statcor_sp_deleterecord</obj_name>
  <obj_hashval>c43333ca4ba1cd57fbf40d9caeccb0b5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_statcor_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_STATCOR_SP_LOCKRECORD( RecId);
  DELETE FROM StatCor  WHERE CodStatCor = RecId;
  DELETE FROM StatCor1 WHERE CodStatCor = RecId;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_statcor_sp_gotorecord</obj_name>
  <obj_hashval>40846749ac66fc56bc83db31568c0607</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_statcor_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_StatCor(CodStatCor, CodEvalS, Atribut, Den_evaluare)
  SELECT S.CodStatCor, S.CodEvalS, S.Atribut, E.Den_evaluare
  FROM StatCor S LEFT JOIN evals E ON  E.CODEVALS = S.Codevals
  WHERE CodStatCor = RECID;

  INSERT INTO TMP_StatCor1(codstatcor1, codStatcor, CodTesatura, Valoare, Ai, Rii)
  SELECT S1.codstatCor1, S1.codStatCor, T.CodTes, S1.Valoare, S1.Ai, S1.Rii
  FROM StatCor1 S1
      LEFT JOIN StatCor  S ON  S.CodStatCor = S1.CodStatCor
      LEFT JOIN EvalSTes T ON  T.CodEvalS   = S.CodEvalS
  WHERE S1.CodStatCor = RECID;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_statcor_sp_insertrecord</obj_name>
  <obj_hashval>c894feeff88752358745d57e5dce262a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_statcor_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_StatCor (CodStatCor) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_statcor_sp_lockrecord</obj_name>
  <obj_hashval>290d0c1bd12789dc52160c988fa7e0bb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_statcor_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CodStatCor INTO Tmp FROM StatCor WHERE CodStatCor = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_statcor_sp_postrecords</obj_name>
  <obj_hashval>57079db398afe7ef4adbe1f407b971e1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_statcor_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  IF  Operation = 0 THEN
    BEGIN
      SELECT CodStatCor INTO RECID FROM TMP_StatCor;
    EXCEPTION WHEN OTHERS THEN
      RECID := 0;
    END;

    UPDATE StatCor
    SET
    (CodEvalS, Atribut, Den_evaluare) = (SELECT CodEvalS, Atribut, Den_evaluare FROM TMP_StatCor)
    WHERE CodStatCor = RECID;

    DELETE FROM StatCor1 WHERE CODStatCor = RecID and CodStatCor1 IN (SELECT CODStatCor1 FROM Tmp_StatCor1);

    FOR v_rec IN (SELECT * FROM Tmp_StatCor1) LOOP
      IF  V_Rec.CodStatCor1 &lt; 0 THEN
        INSERT INTO StatCor1(codstatcor1, codStatcor, CodTesatura, Valoare, Ai, Rii)
        VALUES(NEXTVAL('SEQ_STATCOR1_CODSTATCOR1'), RecId, V_REC.CodTesatura, V_REC.Valoare, V_REC.Ai, V_REC.Rii);
      ELSE
        UPDATE StatCor1 SET CODStatCor = V_REC.CODStatCor WHERE CodStatCor1 = v_rec.CodStatCor1;
      END IF;
    END LOOP;
  ELSE
    SELECT NEXTVAL('SEQ_STATCOR_CODSTATCOR') INTO RecId;

    INSERT INTO StatCor(CodStatCor, CodEvalS, Atribut, Den_evaluare)
    SELECT RECID, CodEvalS, Atribut, Den_evaluare FROM TMP_StatCor;

    INSERT INTO StatCor1(CodStatCor1, CodStatCor, CodTesatura, Valoare, Ai, Rii)
    SELECT NEXTVAL('SEQ_STATCOR1_CODSTATCOR1'), RECID, CodTesatura, Valoare, Ai, Rii FROM TMP_StatCor1;
  END IF;

  PERFORM NotifyModif( Operation, RecId, 'StatCor');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_dropviewstoc</obj_name>
  <obj_hashval>010e564511cae85633a20f2c6a06216c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_dropviewstoc()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  cnt       numeric;
  gViewName varchar;
begin
  --Bogdan 19.10.2020
  gViewName := current_setting ('PKG_STOC_GENERARE_FACTURI.g_viewName', true);

  if(gViewName is not null and gViewName &lt;&gt; '') then
    EXECUTE 'DROP VIEW IF EXISTS ' || (current_setting ('PKG_STOC_GENERARE_FACTURI.g_viewName', true));
  end if;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_fillcodioartcoresp</obj_name>
  <obj_hashval>8f71223abd79663dc69a5b7ac3e7e20e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_fillcodioartcoresp()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  NR    numeric := 0;
begin
  FOR V_REC IN (SELECT PROCENT FROM TMP_NTVA_LUNA) LOOP
    SELECT COUNT( *) INTO NR FROM CODIOARTCORESP WHERE PROCTVA = V_REC.PROCENT;
    IF  NR = 0 THEN
      INSERT INTO CODIOARTCORESP(COD, PROCTVA)
      VALUES(NEXTVAL('SEQ_CODIOARTCORESP_COD'), V_REC.PROCENT);
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_filtrumedex</obj_name>
  <obj_hashval>89182968350f28cb4a94c8289f9459f5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_filtrumedex(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_STOC_GENERARE_FACTURI.FILTRUMEDEX', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := '';
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_g_viewname</obj_name>
  <obj_hashval>be9cc6ce5da9244046c7b17d70d71e57</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_g_viewname(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_STOC_GENERARE_FACTURI.g_viewName', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_getfiltrumedex</obj_name>
  <obj_hashval>649b38c5047a5b7a6e4a806c7b004df5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_getfiltrumedex(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_STOC_GENERARE_FACTURI.FILTRUMEDEX', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := '';
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_getg_viewname</obj_name>
  <obj_hashval>bf941c424df330ea0a17cd74cdd6dc65</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_getg_viewname(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_STOC_GENERARE_FACTURI.g_viewName', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_getinclusiv_stoc_zero</obj_name>
  <obj_hashval>92e23bf8f8769e8dc7a2d5fbd88dd271</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_getinclusiv_stoc_zero(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_STOC_GENERARE_FACTURI.INCLUSIV_STOC_ZERO', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_getinterfacefilter</obj_name>
  <obj_hashval>ed38fe5714083bc8d863c4ff7f312b89</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_getinterfacefilter(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_STOC_GENERARE_FACTURI.INTERFACEFILTER', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := '';
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_getmodlivrautomata</obj_name>
  <obj_hashval>f3715a6d0b31bb84ae0bb8b4f214bf18</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_getmodlivrautomata(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_STOC_GENERARE_FACTURI.MODLIVRAUTOMATA', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_inclusiv_stoc_zero</obj_name>
  <obj_hashval>c769fb626a056d9b381569668a3902e5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_inclusiv_stoc_zero(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_STOC_GENERARE_FACTURI.INCLUSIV_STOC_ZERO', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_interfacefilter</obj_name>
  <obj_hashval>16ccd43cec89f048505f0efcda8f5628</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_interfacefilter(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_STOC_GENERARE_FACTURI.INTERFACEFILTER', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := '';
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_modlivrautomata</obj_name>
  <obj_hashval>6e56023c55e109116558e012edb443fb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_modlivrautomata(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_STOC_GENERARE_FACTURI.MODLIVRAUTOMATA', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_poststare</obj_name>
  <obj_hashval>c7bb1a77975ed80b8ac9490d4a8bdcb9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_poststare()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_NIRSER)
  LOOP
    UPDATE NIRSER
    SET
       STARE = V_REC.STARE,
       OBS   = V_REC.OBS
    WHERE CODNIRSER = V_REC.CODNIRSER;
  END LOOP;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_set_codliniecomanda</obj_name>
  <obj_hashval>2346d639858aa570917fd675003dc355</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_set_codliniecomanda(acodliniecomanda numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Gabi 10.03.2022
perform set_config('PKG_STOC_GENERARE_FACTURI.CODLINIECOMANDA',aCODLINIECOMANDA::varchar,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_set_filtru_medex</obj_name>
  <obj_hashval>d7908d015648317c198af31fdebc146e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_set_filtru_medex(afilter character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_STOC_GENERARE_FACTURI.FILTRUMEDEX',aFILTER,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_set_inclusiv_stoc_zero</obj_name>
  <obj_hashval>bd5a7cf13504b9a917dd1ec903465fdb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_set_inclusiv_stoc_zero(aflag numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  perform set_config('PKG_STOC_GENERARE_FACTURI.INCLUSIV_STOC_ZERO',to_char(aFLAG,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_set_interface_filter</obj_name>
  <obj_hashval>dbf4cbc1ae5232b6ec7df0341328f239</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_set_interface_filter(afilter character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_STOC_GENERARE_FACTURI.INTERFACEFILTER',aFILTER,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_set_mod_livrare_automata</obj_name>
  <obj_hashval>54317c1648f101111729725b18386436</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_set_mod_livrare_automata(amodlivrare numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_STOC_GENERARE_FACTURI.MODLIVRAUTOMATA',to_char(aMODLIVRARE,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_setfiltrumedex</obj_name>
  <obj_hashval>769ebe32ee3bc4ace752a721bd8e34ab</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_setfiltrumedex(afiltrumedex character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_STOC_GENERARE_FACTURI.FILTRUMEDEX',aFILTRUMEDEX,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_setg_viewname</obj_name>
  <obj_hashval>618715c21dc5082bf120a3ebd1f4bfd1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_setg_viewname(ag_viewname character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_STOC_GENERARE_FACTURI.g_viewName',ag_viewName,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_setinclusiv_stoc_zero</obj_name>
  <obj_hashval>ae702b8971640ae200587ecb8c1b9e3b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_setinclusiv_stoc_zero(ainclusiv_stoc_zero numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  perform set_config('PKG_STOC_GENERARE_FACTURI.INCLUSIV_STOC_ZERO',to_char(aINCLUSIV_STOC_ZERO,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_setinterfacefilter</obj_name>
  <obj_hashval>8886c2398c5fc40abdb98d3d898b2776</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_setinterfacefilter(ainterfacefilter character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_STOC_GENERARE_FACTURI.INTERFACEFILTER',aINTERFACEFILTER,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_setmodlivrautomata</obj_name>
  <obj_hashval>99ad97deb8617b8835d13df23f806051</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_setmodlivrautomata(amodlivrautomata numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_STOC_GENERARE_FACTURI.MODLIVRAUTOMATA',to_char(aMODLIVRAUTOMATA,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_testare</obj_name>
  <obj_hashval>e931bd3a57f75198eb5ab8ba85b5cb82</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_testare()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Adina 30.12.2020 - sincronizare cu Oracle
  PERFORM PKG_GLOBALS_SETUSERID(1);
  PERFORM PKG_GLOBALS_SETSUBUNITATE(2);
  PERFORM PKG_GLOBALS_SETFIRMA_ID(1);
  PERFORM PKG_GLOBALS_SetLunaLucru(2019, 9,NULL);
  PERFORM PKG_STOC_GENERARE_FACTURI_make_config_luna();
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stociniart_propagafurn</obj_name>
  <obj_hashval>78e9fb0704faadefa312042765af9ba1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stociniart_propagafurn(acodnirstoc numeric, afurn numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
BEGIN
  --Adina 17.08.2021 - sinc.Oracle din 17.08.2021
  FOR v_Rec IN (SELECT codnirstoc FROM nirstoc WHERE codnirstocparinte = acodnirstoc) LOOP
    UPDATE nirstoc
    SET
    furn = afurn
    WHERE
     codnirstoc = v_rec.codnirstoc;

    PERFORM pkg_stociniart_PropagaFurn(v_rec.codnirstoc, afurn);
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stociniart_sp_deleterecord</obj_name>
  <obj_hashval>804cf08d4350a30496c497ff40b8106a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stociniart_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  aGEST numeric;
  ANI   numeric;
  LUNAI numeric;
begin
  SELECT CODGEST INTO aGEST FROM STOCINI WHERE CODSTOCINI = RecID;

  DELETE FROM STOCINI WHERE CODSTOCINI = RecID;
  DELETE FROM TMP_NIRSTOCINI;
  INSERT INTO TMP_NIRSTOCINI(CODNIRSTOC, CODNIR, CODINTR1, CODINTR, DATADOC, CODOBIECT, CODIOART, UMSEC, PRETACHIZ, PRETINREG, TVA, TG, TIPSERIE, CANTNIR, CODLOCATIE, FURNIZOR, INITIALIZARI)
  (
  SELECT NS.CODNIRSTOC, NS.CODNIR, I1.CODINTR1, I.CODINTR, I.DATADOC, NS.CODOBIECT, NS.CODIOART, NS.UMSEC, NS.PRET - NS.ADAOS, NS.PRET, NS.TVA, I1.TG, NS.TIPSERIE, NS.CANTNIR, NS.CODLOCATIE, I.PARTENER, I.INITIALIZARI
  FROM NIRSTOC NS
      LEFT JOIN NIR      N  ON  N.CODNIR    = NS.CODNIR
      LEFT JOIN INTRARI1 I1 ON  I1.CODINTR1 = NS.CODINTR1
      LEFT JOIN INTRARI  I  ON  I.CODINTR   = N.CODINTR
  WHERE N.GEST = aGEST AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_GLOBALS.ANINITIAL', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_GLOBALS.LUNAINITIALA', true)),'999999999999999999')
  );

  FOR v_rec IN (SELECT * FROM TMP_NIRSTOCINI) LOOP
    DELETE FROM NIRSER     WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
    DELETE FROM NIRSERLUNA WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
    DELETE FROM NIRLUNA    WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
    DELETE FROM NIRSTOC    WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
  END LOOP;

  PERFORM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( TO_NUMBER((current_setting('PKG_GLOBALS.ANINITIAL', true)),'999999999999999999'), TO_NUMBER((current_setting('PKG_GLOBALS.LUNAINITIALA', true)),'999999999999999999'), ANI, LUNAI);

  DELETE FROM PMPLUNA WHERE AN = ANI AND  LUNA = LUNAI;

  FOR V_REC IN
  (
  SELECT CODOBIECT, CODSUBUNIT, SUM( CANTINTR) AS CANTINTR, SUM( VALINTR) AS VALINTR, SUM( RESTLUNA) AS RESTLUNA, ANI, LUNAI
  FROM (SELECT NS.CODOBIECT, G.CODSUBUNIT, NS.CANTNIR AS CANTINTR, (NS.PRET - COALESCE( NS.ADAOS, 0))  * NS.CANTNIR AS VALINTR,
               NS.CANTNIR - (SELECT PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA.WME_RESULT FROM PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA(NULL, NS.CodNirStoc, ANI, LUNAI)) AS RESTLUNA
        FROM NIRSTOC NS, NIR N, TMP_IOART_LUNA IO, INTRARI I, NGEST G
        WHERE NS.CODIOART = IO.CODIOART AND  IO.MG = 3 AND  NS.CODNIR = N.CODNIR AND N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7) AND  N.ANULAT = 0 AND  N.OPERAT = 1 AND  I.CODINTR = N.CODINTR AND  I.AN = ANI AND  I.LUNA = LUNAI AND  G.CODGEST = N.GEST
       ) A_PG
  GROUP BY CODOBIECT, CODSUBUNIT
  )
  LOOP
    INSERT INTO PMPLUNA(CODPMPLUNA, CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, REST, AN, LUNA)
    VALUES(NEXTVAL('SEQ_PMPLUNA_CODPMPLUNA'), V_REC.CODOBIECT, V_REC.CODSUBUNIT, V_REC.CANTINTR, V_REC.VALINTR, V_REC.RESTLUNA, ANI, LUNAI);
  END LOOP;

  DELETE FROM PMP_ALL_LUNA WHERE AN = ANI AND  LUNA = LUNAI;

  FOR V_REC IN
  (
  SELECT CODOBIECT, SUM( CANTINTR) AS CANTINTR, SUM( VALINTR) AS VALINTR, SUM( RESTLUNA) AS RESTLUNA, ANI, LUNAI
  FROM (SELECT NS.CODOBIECT, NS.CANTNIR AS CANTINTR, (  NS.PRET - COALESCE( NS.ADAOS, 0))  * NS.CANTNIR AS VALINTR,
               NS.CANTNIR - (SELECT PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA.WME_RESULT FROM PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA(NULL, NS.CodNirStoc, ANI, LUNAI)) AS RESTLUNA
        FROM NIRSTOC NS, NIR N, TMP_IOART_LUNA IO, INTRARI I
        WHERE NS.CODIOART = IO.CODIOART AND  IO.MG = 3 AND  NS.CODNIR = N.CODNIR AND N.TIPNIR IN (1, 2, 3, 4, 5, 7) AND  N.ANULAT = 0 AND  N.OPERAT = 1 AND  I.CODINTR = N.CODINTR AND  I.AN = ANI AND  I.LUNA = LUNAI
       ) B_PG
  GROUP BY CODOBIECT
  )
  LOOP
    INSERT INTO PMP_ALL_LUNA(CODPMP_ALL_LUNA, CODOBIECT, CANTINTR, VALINTR, REST, AN, LUNA)
    VALUES(NEXTVAL('SEQ_PMP_ALL_LUNA'), V_REC.CODOBIECT, V_REC.CANTINTR, V_REC.VALINTR, V_REC.RESTLUNA, ANI, LUNAI);
  END LOOP;

  PERFORM NotifyModif( 2, RecId, 'STOCINI');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stociniart_sp_lockrecord</obj_name>
  <obj_hashval>80ce02d53fd35ad6024928b2e47d6347</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stociniart_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMP numeric;
begin
  SELECT CODSTOCINI INTO TMP FROM STOCINI WHERE CODSTOCINI = RECID FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stocinitial_can_lock_codgest</obj_name>
  <obj_hashval>0f459b8c36e9d9ee0105d07dc79394de</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stocinitial_can_lock_codgest(INOUT wme_result numeric, INOUT acod numeric, INOUT auserid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  NR numeric := 0;
begin
  SELECT COUNT( *) INTO NR FROM CODGESTLOCK WHERE GEST = aCOD AND  USERID &lt;&gt; aUSERID;
  IF  NR &gt; 0 THEN
    WME_Result :=  0;
    RETURN;
  ELSE
    INSERT INTO CODGESTLOCK(COD, GEST, USERID)
    VALUES(NEXTVAL('SEQ_CODGESTLOCK_COD'), aCOD, aUSERID);

    WME_Result :=  1;
    RETURN;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stocinitial_sp_lockrecord</obj_name>
  <obj_hashval>d35c45eb4a0abee181686a43af4ee622</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stocinitial_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMP numeric;
begin
  SELECT CODSTOCINI INTO TMP FROM STOCINI WHERE CODSTOCINI = RECID FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stocinitial_unlock_codgest</obj_name>
  <obj_hashval>65729c076d2aea541dbdc1b9e8ae02e9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stocinitial_unlock_codgest(auserid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
begin
  DELETE FROM CODGESTLOCK WHERE USERID = aUSERID OR USERID IS NULL ;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stocposuri_codcatpretposuri</obj_name>
  <obj_hashval>30376cd5803186aba558989ec3b498cb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stocposuri_codcatpretposuri(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_STOCPOSURI.CODCATPRETPOSURI', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stocposuri_getcodcatpretposuri</obj_name>
  <obj_hashval>2bf27f63cf89bcd5a0c3a6b5eb19f7ef</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stocposuri_getcodcatpretposuri(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_STOCPOSURI.CODCATPRETPOSURI', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stocposuri_set_catpret_posuri</obj_name>
  <obj_hashval>5c821d2216ac15e548ddd0f04d3343f6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stocposuri_set_catpret_posuri(acatpret numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_STOCPOSURI.CODCATPRETPOSURI',to_char(aCATPRET,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stocposuri_setcodcatpretposuri</obj_name>
  <obj_hashval>951caf6723313a78842b9f361cb2f1ec</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stocposuri_setcodcatpretposuri(acodcatpretposuri numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_STOCPOSURI.CODCATPRETPOSURI',to_char(aCODCATPRETPOSURI,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stocposuri_sp_goto</obj_name>
  <obj_hashval>ddcebfd33ed019a39f8be4feaa77d45b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stocposuri_sp_goto()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 20.03.2025 - sinc. Oracle
  --Florin 19.03.2025 - sinc. Oracle
  --Florin 04.11.2020 - fixat #40800
  DELETE FROM TMP_STOCPOSURI;
  INSERT INTO TMP_STOCPOSURI(CODSTOCPOS, CODPOS, TIPPOS, CODGEST, CODOBIECT, CODIOART, TVA, PRET, CODDEP, PLU, PRETNOU, STOC, BARCODE, CANTARIBIL, DENOBIECT, SERVICIU,
                             DEN_UM, UMSEC, PROCTVA, CODTVA, CONTSERV, SIMBOLCONTSERV,
                                SIMBOLGEST, DEN_GEST, MODIFICARI)
  SELECT SP.CODSTOCPOS, SP.CODPOS, SP.TIPPOS, SP.CODGEST, SP.CODOBIECT, SP.CODIOART, SP.TVA, SP.PRET, SP.CODDEP, SP.PLU, SP.PRETNOU, SP.STOC, SP.BARCODE,
         U.TipUM, O.DENUMIRE, A.TIPARTICOL::NUMERIC, U1.DEN_UM1, U1.CODUM1, TVAL.PROCENT, TVAL.CODTVA, A.CONTSERVICIU, NC.SIMBOL,
         G.SIMBOL,
         G.DEN_GEST,
         CASE
           WHEN SP.DENOBIECT IS NOT NULL AND SP.DENOBIECT &lt;&gt; O.DENUMIRE THEN 1
           ELSE NVL(SP.MODIFICARI, 0)
         END
  FROM STOCPOSURI SP
      LEFT JOIN NGEST G ON G.CODGEST = SP.CODGEST
      INNER JOIN TMP_MANEVRA M ON M.CODUNIC = SP.CODPOS,
      NARTOBJ O, NART A
      LEFT JOIN TMP_NART_LUNA AL   ON  AL.CODARTICOL = A.CODARTICOL
      LEFT JOIN TMP_NTVA_LUNA TVAL ON  TVAL.CODTVA   = AL.CODTVA
      LEFT JOIN NCONT         NC   ON  NC.CODCONT    = A.CONTSERVICIU, NUM1 U1, NUM U
  WHERE
     SP.CODOBIECT = O.CODOBIECT
     AND  A.CODARTICOL = O.CODARTICOL AND  A.UM = U.CODUM AND  A.UM = U1.CODUM AND  U1.SECUNDARA = 0;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stocposuri_sp_post</obj_name>
  <obj_hashval>759414cb26f9975a41fdb19d29a9282c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stocposuri_sp_post()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC    RECORD;
  NR       numeric := 0;
  aSUBUNIT numeric := 0;
BEGIN
  --Florin 19.03.2025 - sinc. Oracle
  DELETE FROM STOCPOSURI SP WHERE CODPOS IN (SELECT CODUNIC FROM TMP_MANEVRA)
  AND NOT EXISTS (SELECT CODSTOCPOS FROM TMP_STOCPOSURI WHERE CODSTOCPOS = SP.CODSTOCPOS);
  FOR V_REC IN (SELECT * FROM TMP_STOCPOSURI) LOOP
    IF  V_REC.CODSTOCPOS &lt; 0 THEN
      INSERT INTO STOCPOSURI(CODSTOCPOS, CODPOS, TIPPOS, CODGEST, CODOBIECT, CODIOART, TVA, PRET, CODDEP, PLU, PRETNOU, STOC, BARCODE, DENOBIECT, MODIFICARI)
      VALUES(NEXTVAL('SEQ_STOCPOSURI_CODSTOCPOSURI'), V_REC.CODPOS, V_REC.TIPPOS, V_REC.CODGEST, V_REC.CODOBIECT, V_REC.CODIOART, V_REC.TVA, V_REC.PRET, V_REC.CODDEP, V_REC.PLU, V_REC.PRETNOU, V_REC.STOC, V_REC.BARCODE, V_REC.DENOBIECT, NVL(V_REC.MODIFICARI, 0));
    ELSE
      UPDATE STOCPOSURI
      SET
      CODPOS    = V_REC.CODPOS,
      TIPPOS    = V_REC.TIPPOS,
      CODGEST   = V_REC.CODGEST,
      CODOBIECT = V_REC.CODOBIECT,
      CODIOART  = V_REC.CODIOART,
      TVA       = V_REC.TVA,
      PRET      = V_REC.PRET,
      CODDEP    = V_REC.CODDEP,
      PLU       = V_REC.PLU,
      PRETNOU   = V_REC.PRETNOU,
      STOC      = V_REC.STOC,
      BARCODE   = V_REC.BARCODE,
      DENOBIECT = V_REC.DENOBIECT,
      MODIFICARI = NVL(V_REC.MODIFICARI, 0)
      WHERE
       CODSTOCPOS = V_REC.CODSTOCPOS;
    END IF;
  END LOOP;

  SELECT CASE WHEN  (SELECT PKG_GLOBALS_GETSUBUNITATE.WME_RESULT FROM PKG_GLOBALS_GETSUBUNITATE(NULL,NULL))=1 THEN 2
              ELSE  (SELECT PKG_GLOBALS_GETSUBUNITATE.WME_RESULT FROM PKG_GLOBALS_GETSUBUNITATE(NULL,NULL))
         END
  INTO aSUBUNIT;

  FOR V_REC IN (SELECT * FROM TMP_STOCPOSURI) LOOP
    SELECT COUNT( *) INTO NR FROM PLUCASE WHERE CODOBIECT = V_REC.CODOBIECT AND  CODCASA = V_REC.CODPOS;
    IF  NR = 0 THEN
      INSERT INTO PLUCASE(CODPLUCASE, CODCASA, CODOBIECT, CODPLU)
      VALUES(NEXTVAL('SEQ_PLUCASE_CODPLUCASE'), V_REC.CODPOS, V_REC.CODOBIECT, V_REC.PLU);
    ELSE
      UPDATE PLUCASE SET CODPLU = V_REC.PLU WHERE CODOBIECT = V_REC.CODOBIECT AND  CODCASA = V_REC.CODPOS;
    END IF;

    IF  COALESCE( V_REC.PRETUPDATED, 0) &lt;&gt; 0 THEN
      SELECT COUNT( *) INTO NR FROM PRETM
      WHERE CODOBIECT = V_REC.CODOBIECT AND  SUBUNITATEA = aSUBUNIT AND  CODCATPRET = TO_NUMBER((current_setting('PKG_STOCPOSURI.CODCATPRETPOSURI', true)),'999999999999999999');

      IF  NR = 0 THEN
        INSERT INTO PRETM(CODPRETM, CODOBIECT, CODCATPRET, LEI, MONEDA, SUBUNITATEA)
        VALUES(NEXTVAL('SEQ_PRETM_CODPRETM'), V_REC.CODOBIECT, TO_NUMBER((current_setting('PKG_STOCPOSURI.CODCATPRETPOSURI', true)),'999999999999999999'), V_REC.PRETUPDATED, 0, aSUBUNIT);
      ELSE
        UPDATE PRETM
        SET
        LEI = V_REC.PRETUPDATED
        WHERE
         CODOBIECT = V_REC.CODOBIECT AND  SUBUNITATEA = aSUBUNIT AND  CODCATPRET = TO_NUMBER((current_setting('PKG_STOCPOSURI.CODCATPRETPOSURI', true)),'999999999999999999');
      END IF;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stocvalini_sp_gotorecord</obj_name>
  <obj_hashval>78b5637f91ff4f2e4a8a1f2ad45db2f8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stocvalini_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  ANI      numeric;
  LUNAI    numeric;
  aCODGEST numeric := 0;
begin
  --Florin 30.12.2021 - sinc. Oracle (29.12.2021)
  INSERT INTO TMP_STOCVALINI ( CODSTOCVALINI, GEST )
  SELECT CODSTOCVALINI, GEST FROM STOCVALINI WHERE CODSTOCVALINI = RECID;
  --PERFORM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA(current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric, current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric, ANI, LUNAI);
  SELECT NEWAN, NEWLUNA INTO ANI, LUNAI
  FROM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA(current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric, current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric, ANI, LUNAI);

  if RECID &gt; 0 then
    SELECT coalesce(GEST, 0) INTO aCODGEST FROM TMP_STOCVALINI;
  end if;

  INSERT INTO TMP_STOCVALLUNA ( CODSTOCVALLUNA, GEST, CODIOART, TVA, SOLD, ADAOS, SOLDINTR, ADAOSINTR, AN, LUNA )
  SELECT * FROM STOCVALLUNA WHERE GEST = aCODGEST and AN = ANI and LUNA = LUNAI;

  UPDATE TMP_STOCVALLUNA SV
  SET
    VALACHIZ = SOLD - ADAOS,
    (DIFPRET, ARETVANEEX, PUSTANDARD, MG) = (SELECT IO1.DIFPRET, IO1.ARETVANEEX, IO1.PUSTANDARD, IO1.MG
                                             FROM IOART1 IO1
                                                  WHERE IO1.CODIOART = SV.CODIOART AND getANLUNALUCRU() BETWEEN IO1.ALSTART AND IO1.ALSTOP);

  UPDATE TMP_STOCVALINI
  SET
    SOLDTOTAL = (SELECT sum(SOLD) FROM TMP_STOCVALLUNA ) ;
 end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stocvalini_sp_postrecords</obj_name>
  <obj_hashval>373847084902d3229e65e9ad659008e5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stocvalini_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  aCODGEST numeric;
  ANI      numeric;
  LUNAI    numeric;
begin
  --Bogdan 10.02.2021
  select newan, newluna
  from  PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA (current_setting ('PKG_GLOBALS.ANINITIAL', true) ::numeric,
                          current_setting ('PKG_GLOBALS.LUNAINITIALA', true) ::numeric,
                          ANI, LUNAI) into ANI, LUNAI;

  SELECT GEST INTO aCODGEST FROM TMP_STOCVALINI;

  IF OPERATION = 0 THEN
    SELECT CODSTOCVALINI INTO RecId FROM TMP_STOCVALINI;

    UPDATE STOCVALINI SET GEST = aCODGEST WHERE CODSTOCVALINI = RecID;

    DELETE FROM STOCVALLUNA
    WHERE
      AN = ANI
      AND LUNA = LUNAI
      AND GEST = aCODGEST
      AND CODSTOCVALLUNA NOT IN (SELECT CODSTOCVALLUNA FROM TMP_STOCVALLUNA);

    FOR V_REC IN (SELECT * FROM TMP_STOCVALLUNA) LOOP
      IF V_REC.CODSTOCVALLUNA &lt; 0 THEN
        INSERT INTO STOCVALLUNA (CODSTOCVALLUNA, GEST, CODIOART, TVA, SOLD, ADAOS, SOLDINTR, ADAOSINTR, AN, LUNA)
        VALUES (NEXTVAL ('SEQ_STOCVALLUNA_CODSTOCVALLUNA') , V_REC.GEST, V_REC.CODIOART, V_REC.TVA, V_REC.SOLD, V_REC.ADAOS, V_REC.SOLDINTR, V_REC.ADAOSINTR, V_REC.AN, V_REC.LUNA);
      ELSE
        UPDATE STOCVALLUNA
        SET
          GEST      = V_REC.GEST,
          CODIOART  = V_REC.CODIOART,
          TVA       = V_REC.TVA,
          SOLD      = V_REC.SOLD,
          ADAOS     = V_REC.ADAOS,
          SOLDINTR  = V_REC.SOLDINTR,
          ADAOSINTR = V_REC.ADAOSINTR,
          AN        = V_REC.AN,
          LUNA      = V_REC.LUNA
        WHERE
          CODSTOCVALLUNA = V_REC.CODSTOCVALLUNA;
      END IF;
    END LOOP;
  ELSE
    SELECT NEXTVAL ('SEQ_STOCVALINI_CODSTOCVALINI') INTO RECID;

    INSERT INTO STOCVALINI
    SELECT RecID, aCODGEST;

    INSERT INTO STOCVALLUNA (CODSTOCVALLUNA, GEST, CODIOART, TVA, SOLD, ADAOS, SOLDINTR, ADAOSINTR, AN, LUNA)
    SELECT NEXTVAL ('SEQ_STOCVALLUNA_CODSTOCVALLUNA') , GEST, CODIOART, TVA, SOLD, ADAOS, SOLDINTR, ADAOSINTR, AN, LUNA FROM TMP_STOCVALLUNA;
  END IF;

  PERFORM NotifyModif (Operation, RecId, 'STOCVALINI');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_struct_adunacoloanelexview</obj_name>
  <obj_hashval>33749a6c167f7aea8bb52eb615a385a0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_struct_adunacoloanelexview(pviewname character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  --Florin 21.06.2023 - sinc. Oracle (19.06.2023)
  sJoinsTbl view_joins.joinuri%type;
  sViewName view_joins.viewname%type;
  sIdCustomTable varchar(20);
  idCustomTable NUMERIC(10);
  b NUMERIC;
  sJoinTblFromCustomTbl winmadmin.maketeproprii.tblmaster%type;
BEGIN
   --Florin 18.07.2023 - sinc. Oracle
   sViewName := upper(pViewName);
   DELETE FROM tmp_list_cols;
   begin
     select vj.joinuri into sJoinsTbl from view_joins vj where vj.viewname = '' || sViewName || '';
   exception
     WHEN OTHERS THEN sJoinsTbl := null;
   end;
   if coalesce(instr(sViewName, 'CUSTOMFORMDB_'),0) &gt; 0 then
      sViewName := trim(replace(sViewName,  'CUSTOMFORMDB_', ''));
      b := coalesce(instr(sViewName, '_VIEW'),0);
      sIdCustomTable := Substr(sViewName, 1, b-1);
      if length(sIdCustomTable) &gt; 0 then
        begin
           idCustomTable := to_number( sIdCustomTable );
           select mp.tblmaster into sJoinTblFromCustomTbl from winmadmin.maketeproprii mp where mp.iddocument =  idCustomTable;
         exception
            when data_exception then sJoinTblFromCustomTbl := null;
         end;
      end if;
      if sJoinTblFromCustomTbl is not null then
        sJoinTblFromCustomTbl := sJoinTblFromCustomTbl || ' CustM ';
        if sJoinsTbl is null then sJoinsTbl := sJoinTblFromCustomTbl;
                             else sJoinsTbl := sJoinsTbl || ', ' || sJoinTblFromCustomTbl;
        end if;
      end if;
   end if;

   if sJoinsTbl is not null then
     PERFORM pkg_struct_SetTableSpec(sJoinsTbl);
     PERFORM pkg_struct_AdunaColoanele();
   end if;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_structuraretraseu_preluare_traseu</obj_name>
  <obj_hashval>0a1465778c46724d754a30889a2ed1ea</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_structuraretraseu_preluare_traseu(atraseu numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aTipTraseu numeric;
BEGIN
  --Stef 22.07.2022
  DELETE FROM TMP_NAGENDA_TRASEU;

  SELECT COALESCE (Tip, 0) INTO aTipTraseu FROM TraseuLivr WHERE CodTraseuLivr = aTraseu;

  INSERT INTO TMP_NAGENDA_TRASEU (CODAGENDA, FIRMA, SEDIU, ZONA, JUDET, LOCALITATE, POZTRASEU, SSOC, ADRESA, CODTRASEULIVR, Lat, Lng, CodPart)
  SELECT A.CODAGENDA, P.DEN_PART, A.OBS, Z.DEN_ZONA, J.SIMBAUTO, L.DEN_LOCALIT,
        (CASE WHEN aTipTraseu = 0 THEN A.POZTRASEU ELSE A.POZTRASEU1 END) POZTRASEU,
         CASE WHEN A.SEDIUSOCIAL BETWEEN 4 AND 7 THEN 1 ELSE 0 END ,
        (SELECT GETADRESA.WME_RESULT FROM GETADRESA (NULL, A.SECTOR, A.STRADA, A.NR1, A.NR2, A.BLOC, A.SCARA, A.ETAJ, A.APART, A.CODPOSTAL)) ,
        aTraseu, A.Latitudine::numeric, A.Longitudine::numeric, A.CodPart
  FROM NAGENDA         A
    INNER JOIN NPART   P ON P.CODPART    = A.CODPART
    LEFT JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT
    LEFT JOIN NJUDET   J ON J.CODJUDET   = L.CODJUDET
    LEFT JOIN NZONE    Z ON Z.CODZONA    = L.CODZONA
  WHERE ( aTipTraseu = 0 and CODTRASEU = aTraseu) or ( aTipTraseu = 1 and CODTRASEU1 = aTraseu)
    AND Coalesce(A.INACTIV,0) = 0;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_structuraretraseu_salvare_traseu</obj_name>
  <obj_hashval>b50a8acea11b50455c1b58c6208fec05</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_structuraretraseu_salvare_traseu(atraseu numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  vCOUNT     NUMERIC;
  aTipTraseu numeric;
begin
  --Bogdan 05.11.2020
  vCOUNT := 0;
  FOR v_rec IN (SELECT CODAGENDA, POZTRASEU, CODTRASEULIVR FROM TMP_NAGENDA_TRASEU) LOOP
    SELECT COALESCE (Tip, 0) INTO aTipTraseu FROM TraseuLivr WHERE CodTraseuLivr = v_rec.CODTRASEULIVR;

    IF aTipTraseu = 0 THEN
      UPDATE NAGENDA A
      SET
        POZTRASEU = v_rec.PozTraseu,
        CODTRASEU = V_REC.CODTRASEULIVR
      WHERE
        CODAGENDA = v_rec.CodAgenda;
    ELSE
      UPDATE NAGENDA A
      SET
        POZTRASEU1 = v_rec.PozTraseu,
        CODTRASEU1 = V_REC.CODTRASEULIVR
      WHERE
        CODAGENDA = v_rec.CodAgenda;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_subsidiary_aux_tmp</obj_name>
  <obj_hashval>abd8bf1b61d2e9576f9e72411f89f001</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_subsidiary_aux_tmp(INOUT stmp character varying, INOUT sheader character varying, INOUT sfooter character varying, INOUT sfilename character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  vTMP      varchar := Upper( sTMP);
  vLastCol  NUMERIC;
  vCount    NUMERIC;
  vFirstCol NUMERIC;
BEGIN
  --Adina 02.06.2021 - scos upper din information_schema
  SELECT count( 1)
  INTO vLastCol
  FROM information_schema.columns
  WHERE table_name = 'tmp_subsid_' || lower(vTMP);

  sFileName := To_Char( (current_setting('PKG_SUBSIDIARY.vDataFin', true)), 'yymmdd') || '-0380-' || vTMP || '.txt';

  IF  vTMP = 'MAT' THEN
    vFirstCol := 1;
    sHeader := 'Plant|Sales Organization|Distribution Channel|Material|Designation|Procurement Type|' || 'Status|Qty per Inner|Qty per Master|Qty per Layer|Qty per Pallet|MRP Controller|Material Group 1|' || 'Item Category Group|Statistic group|' || 'Material Group 4 Product responible|Price Control Indicator|Valuation Class|Moving Average Price|Standard Price|Currency|Volume Unit|Master Volume|Material Type';

    SELECT Count( 1) INTO vCount FROM TMP_SUBSID_MAT;
  ELSIF vTMP = 'STK' THEN
    vFirstCol := 1;
    sHeader := 'Plant|Company|Sales Organization|Distribution Channel|DAY|Material|Storage location|Supplier|Value|Local Currency|Quantity|Unit';

    SELECT Count( 1) INTO vCount FROM TMP_SUBSID_STK;
  END IF;

  sFooter := 'EOF|' || vCount || '|'
              || To_Char(CASE WHEN vTMP = 'ORD' THEN (current_setting('PKG_SUBSIDIARY.cDataIni', true)) ELSE (current_setting('PKG_SUBSIDIARY.iDataIni', true)) END , 'yyyymmdd')
              || '|'
              || To_Char(CASE WHEN vTMP = 'ORD' THEN (current_setting('PKG_SUBSIDIARY.cDataFin', true)) ELSE (current_setting('PKG_SUBSIDIARY.vDataFin', true)) END , 'yyyymmdd');

  sFooter := RPad( sFooter, Length( sFooter) + vLastCol - vFirstCol - 5, '|');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_subsidiary_cdatafin</obj_name>
  <obj_hashval>1daac7e20e8a15ba86776759673cee2f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_subsidiary_cdatafin(INOUT wme_result date, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_SUBSIDIARY.cDataFin', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_subsidiary_cdataini</obj_name>
  <obj_hashval>b1fba4e329be2390f2881233fe6e6991</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_subsidiary_cdataini(INOUT wme_result date, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_SUBSIDIARY.cDataIni', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_subsidiary_getcdatafin</obj_name>
  <obj_hashval>162f17fe1c131f030d9759c8f77b501e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_subsidiary_getcdatafin(INOUT wme_result date, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_SUBSIDIARY.cDataFin', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_subsidiary_getcdataini</obj_name>
  <obj_hashval>2c7a9a9fb0d22607c135899586861c04</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_subsidiary_getcdataini(INOUT wme_result date, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_SUBSIDIARY.cDataIni', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_subsidiary_getcursortmp</obj_name>
  <obj_hashval>90452cb1400aaae79bd5323892df48d5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_subsidiary_getcursortmp(INOUT wme_result refcursor, INOUT ptmp character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  cResult REFCURSOR;
begin
  IF  Upper( pTMP) = 'MAT' THEN
    OPEN cResult FOR
    SELECT plant || '|' || salesorg || '|' || distr_chan || '|' || material || '|' || maktx || '|' || f || '|' || zmmsta || '|' || znbspcb || '|' || znbpcb || '|' || znbbox || '|' || znbpal || '|' || mrp_contrl || '|' || mat_kondm || '|' || zmtpos || '|' || mat_stgrp || '|' || matl_grp_4 || '|' || zvprsv || '|' || val_class || '|' || zverpr || '|' || zstprs || '|' || currency || '|' || volumeunit || '|' || zvolpcb || '|' || mat_type LINIE
    FROM TMP_SUBSID_MAT;
  ELSIF Upper( pTMP) = 'STK' THEN
    OPEN cResult FOR
    SELECT plant || '|' || comp_code || '|' || salesorg || '|' || distr_chan || '|' || day || '|' || material || '|' || stor_loc || '|' || supplier || '|' || val || '|' || loc_currcy || '|' || qty || '|' || stor_unit LINIE
    FROM TMP_SUBSID_STK;
  END IF;

  WME_Result :=  cResult;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_subsidiary_getidataini</obj_name>
  <obj_hashval>a01ebb51a247ef293dab094590cac3f1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_subsidiary_getidataini(INOUT wme_result date, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_SUBSIDIARY.iDataIni', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_subsidiary_getvdatafin</obj_name>
  <obj_hashval>4fe35cfcc287830dbd7f6004999f9bc6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_subsidiary_getvdatafin(INOUT wme_result date, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_SUBSIDIARY.vDataFin', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_subsidiary_getvdataini</obj_name>
  <obj_hashval>11d1eb0f6e92b5774a9da4dc653490b7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_subsidiary_getvdataini(INOUT wme_result date, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_SUBSIDIARY.vDataIni', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_subsidiary_idataini</obj_name>
  <obj_hashval>a27ee053923bf6d5c2ebf35207ddec57</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_subsidiary_idataini(INOUT wme_result date, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_SUBSIDIARY.iDataIni', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_subsidiary_setidataini</obj_name>
  <obj_hashval>0ea01fc99cebf1018b62bdffad741efa</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_subsidiary_setidataini(aidataini date)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SUBSIDIARY.iDataIni',aiDataIni,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_subsidiary_setvdatafin</obj_name>
  <obj_hashval>ab502a6444c5e489ea7e0ac4f6f18e66</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_subsidiary_setvdatafin(avdatafin date)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SUBSIDIARY.vDataFin',avDataFin,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_subsidiary_setvdataini</obj_name>
  <obj_hashval>f0025bbf816ed6878d59ed2ca989e11c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_subsidiary_setvdataini(avdataini date)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SUBSIDIARY.vDataIni',avDataIni,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_subsidiary_vdatafin</obj_name>
  <obj_hashval>58a3406fd71d211d3b3d00a76f0c0b45</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_subsidiary_vdatafin(INOUT wme_result date, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_SUBSIDIARY.vDataFin', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_subsidiary_vdataini</obj_name>
  <obj_hashval>80bafa2d6434841635cd17d807a2ddb8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_subsidiary_vdataini(INOUT wme_result date, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_SUBSIDIARY.vDataIni', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_targetag_ct_monitor</obj_name>
  <obj_hashval>a8708d7c983881b4ad156a234de3601a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_targetag_ct_monitor(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_TARGETAG.CT_MONITOR', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 'MON_29';
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_targetag_getct_monitor</obj_name>
  <obj_hashval>f74bf3612a18a50f4c846309caa90ce5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_targetag_getct_monitor(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_TARGETAG.CT_MONITOR', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 'MON_29';
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_targetag_limite_interval</obj_name>
  <obj_hashval>58ccb61e20ee7879709a743d0730e64f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_targetag_limite_interval(INOUT wme_result numeric, INOUT acodsubunit numeric, INOUT acodtargetag numeric, INOUT aagent numeric, INOUT aclient numeric, INOUT aclasapart numeric, INOUT adatastart character varying, INOUT adatastop character varying, INOUT atiptarget numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC    RECORD;
  Suprapus numeric;
  DStart   date;
  DStop    date;
begin
  Suprapus := 0;
  FOR v_rec IN (SELECT DATASTART, DATASTOP
                FROM TargetAG
                WHERE (CODTargetAG &lt;&gt; aCODTargetAG)  AND (COALESCE( AGENT, 0) = aAGENT)  AND (COALESCE( CLIENT, 0) = aCLIENT)
                  AND (COALESCE( ClasaPart, 0) = aCLASAPART)  AND (COALESCE( TipTarget, 0) = aTipTarget)  AND (SUBUNITATEA = aCODSubunit)
                  AND (COALESCE( ANULAT, 0) = 0)  AND (COALESCE( OPERAT, 0) = 1)  AND (COALESCE( ACTIV, 0) = 1)
                ORDER BY DATASTART
               )
  LOOP
    DStart := To_Date( aDATASTART, 'dd.mm.yyyy');
    DStop  := To_Date( aDATASTOP , 'dd.mm.yyyy');

    IF DStart BETWEEN v_rec.datastart AND v_rec.datastop THEN
      SUPRAPUS   := 1;
      aDATASTART := To_Char( v_rec.datastop + 1, 'dd.mm.yyyy');
    END IF;

    IF DStop BETWEEN v_rec.datastart AND v_rec.datastop THEN
      SUPRAPUS  := 1;
      aDATASTOP := To_Char( v_rec.datastart - 1, 'dd.mm.yyyy');
    END IF;

    IF  SUPRAPUS = 0 THEN
      IF v_rec.datastart BETWEEN DSTART AND DSTOP THEN
        SUPRAPUS   := 1;
        aDATASTART := To_Char( v_rec.datastop + 1, 'dd.mm.yyyy');
      END IF;

      IF v_rec.datastop BETWEEN DSTART AND DSTOP THEN
        SUPRAPUS  := 1;
        aDATASTOP := To_Char( v_rec.datastart - 1, 'dd.mm.yyyy');
      END IF;
    END IF;
  END LOOP;

  WME_Result :=  Suprapus;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_targetag_setct_monitor</obj_name>
  <obj_hashval>b370d66f68dbae52ca66e4f69795cce6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_targetag_setct_monitor(act_monitor character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_TARGETAG.CT_MONITOR',aCT_MONITOR,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_targetag_sp_deleterecord</obj_name>
  <obj_hashval>a2b0bb0fa793d50e72d6cde9d9ea262c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_targetag_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 11.04.2023 - sinc. Oracle (10.04.2023)
  PERFORM PKG_CFGTABLES_EXT_DELETERECORD (recId, 17);
  PERFORM PKG_TARGETAG_SP_LOCKRECORD( RecId);
  DELETE FROM TARGETAG1 WHERE CodTARGETAG = RecId;
  DELETE FROM TARGETAG  WHERE CodTARGETAG = RecId;
  PERFORM NotifyModif( 2, RecId, 'TARGETAG');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_targetag_sp_insertrecord</obj_name>
  <obj_hashval>2a9958559f160e05017889a273826263</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_targetag_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 11.04.2023 - sinc. Oracle (10.04.2023)
  PERFORM PKG_CFGTABLES_EXT_INSERTRECORD(17);
  INSERT INTO TMP_TARGETAG (CodTARGETAG) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_targetag_sp_postrecords</obj_name>
  <obj_hashval>0da43dfaf7b5a6ad28ef782ecaf34b86</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_targetag_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC       RECORD;
  vRecNo      NUMERIC := 0;
  vCod        numeric;
  vCodPart    numeric;
  vtest       numeric;
  vDenumire   varchar;
  vCodExtern  varchar;
  vUmSec      numeric;
  aCarnetDoc  numeric;
  aNrDoc      numeric;
  aCodSubunit numeric;
  aDataDoc    date;
  aDoc        varchar;
  aTipTarget   NUMERIC;
BEGIN
  --Florin 02.12.2024 - sinc. Oracle
  --Bogdan 12.10.2020
  SELECT CodTARGETAG, Subunitatea, TipTarget INTO RecId, aCodSubunit, aTipTarget FROM TMP_TARGETAG;

  PERFORM PKG_CFGTABLES_EXT_POSTRECORDS_INIT (17);
  IF Operation = 0 THEN
    UPDATE TARGETAG
    SET
      (
        CodTARGETAG,
        TipDoc,
        Anulat,
        Blocat,
        Operat,
        Activ,
        DataStart,
        DataStop,
        TipTarget,
        Moneda,
        Obs,
        Subunitatea,
        UserId,
        DataCreare,
        Agent,
        Client,
        ClasaPart,
        TipPart,
        LunaStart,
        AnStart,
        LunaEnd,
        AnEnd,
        Nrclienti
      )
      = (SELECT CodTARGETAG,
          TipDoc,
          Anulat,
          Blocat,
          Operat,
          Activ,
          DataStart,
          DataStop,
          TipTarget,
          Moneda,
          Obs,
          Subunitatea,
          UserId,
          DataCreare,
          Agent,
          Client,
          ClasaPart,
          TipPart,
          LunaStart,
          AnStart,
          LunaEnd,
          AnEnd,
          Nrclienti
        FROM TMP_TARGETAG)
    WHERE
      CodTARGETAG = RecId;

    DELETE FROM TARGETAG1 C1 WHERE C1.CodTARGETAG = RecID AND NOT EXISTS (SELECT 1 FROM TMP_TARGETAG1 TC1 WHERE TC1.CodTARGETAG1 = C1.CodTARGETAG1);

    FOR v_rec IN (SELECT CodTARGETAG1,
        CodTARGETAG,
        CodObiect,
        CodClasa,
        CodClasaS,
        UmSec,
        Cant * CASE WHEN COALESCE (Paritate, 1) = 0 THEN 1 ELSE COALESCE (Paritate, 1) END CANT,
        Valoare,
        Masa,
        Volum,
        Obs,
        CantMin,
        CantMax
      FROM TMP_TARGETAG1)
    LOOP
      IF COALESCE (v_rec.CodTARGETAG1, 0) &gt; 0 THEN
        UPDATE TARGETAG1
        SET
          CodObiect = v_rec.CodObiect,
          CodClasa  = v_rec.CodClasa,
          CodClasaS = v_rec.CodClasaS,
          UMSec     = v_rec.UMSec,
          Cant      = v_rec.Cant,
          Valoare   = v_rec.Valoare,
          Masa      = v_rec.Masa,
          Volum     = v_rec.Volum,
          Obs       = v_rec.Obs,
          CantMin   = v_rec.CantMin,
          CantMax   = v_rec.CantMax
        WHERE
          CodTARGETAG1 = v_rec.CodTARGETAG1;
      ELSE
        SELECT NEXTVAL ('SEQ_TARGETAG1_CODTARGETAG1') INTO vCod;
        PERFORM PKG_CFGTABLES_EXT_UPDATE_COD_CORESP('TARGETAG1', vCod, v_rec.CodTARGETAG1);
        INSERT INTO TARGETAG1 (CodTARGETAG1,
            CodTARGETAG,
            CodObiect,
            CodClasa,
            CodClasaS,
            UMSec,
            Cant,
            Valoare,
            Masa,
            Volum,
            Obs,
            CantMin,
            CantMax)
          VALUES (vCod,
            RecId,
            v_rec.CodObiect,
            v_rec.CodClasa,
            v_rec.CodClasaS,
            v_rec.UMSec,
            v_rec.Cant,
            v_rec.Valoare,
            v_rec.Masa,
            v_rec.Volum,
            v_rec.Obs,
            v_rec.CantMin,
            v_rec.CantMax);
      END IF;
    END LOOP;
  ELSE
    SELECT NEXTVAL ('SEQ_TARGETAG_CODTARGETAG') INTO RecId;
    PERFORM PKG_CFGTABLES_EXT_UPDATE_COD_CORESP('TARGETAG', RecId);

    INSERT INTO TARGETAG (CodTARGETAG,
        TipDoc,
        Anulat,
        Blocat,
        Operat,
        Activ,
        DataStart,
        DataStop,
        TipTarget,
        Moneda,
        Obs,
        Subunitatea,
        An,
        Luna,
        UserId,
        DataCreare,
        Agent,
        Client,
        ClasaPart,
        TipPart,
        LunaStart,
        AnStart,
        LunaEnd,
        AnEnd,
        Nrclienti)
    SELECT RecId,
      TipDoc,
      Anulat,
      Blocat,
      Operat,
      Activ,
      DataStart,
      DataStop,
      TipTarget,
      Moneda,
      Obs,
      Subunitatea,
      An,
      Luna,
      UserId,
      DataCreare,
      Agent,
      Client,
      ClasaPart,
      TipPart,
      LunaStart,
      AnStart,
      LunaEnd,
      AnEnd,
      Nrclienti
    FROM TMP_TARGETAG;

    SELECT COUNT (1) INTO vRecNo FROM TMP_TARGETAG1;

    FOR v_rec IN (SELECT CodTARGETAG1,
        CodTARGETAG,
        CodObiect,
        CodClasa,
        CodClasaS,
        UmSec,
        Cant * CASE WHEN COALESCE (Paritate, 1) = 0 THEN 1 ELSE COALESCE (Paritate, 1) END CANT,
        Valoare,
        Masa,
        Volum,
        Obs,
        CantMin,
        CantMax
      FROM TMP_TARGETAG1)
    LOOP
      SELECT NEXTVAL ('SEQ_TARGETAG1_CODTARGETAG1') INTO vCod;
      PERFORM PKG_CFGTABLES_EXT_UPDATE_COD_CORESP('TARGETAG1', vCod, v_rec.CodTARGETAG1);

      INSERT INTO TARGETAG1 (CodTARGETAG1,
          CodTARGETAG,
          CodObiect,
          CodClasa,
          CodClasaS,
          UMSec,
          Cant,
          Valoare,
          Masa,
          Volum,
          Obs,
          CantMin,
          CantMax)
        VALUES (vCod,
          RecId,
          v_rec.CodObiect,
          v_rec.CodClasa,
          v_rec.CodClasaS,
          v_rec.UMSec,
          v_rec.Cant,
          v_rec.Valoare,
          v_rec.Masa,
          v_rec.Volum,
          v_rec.Obs,
          v_rec.CantMin,
          v_rec.CantMax);
    END LOOP;
  END IF;

  PERFORM PKG_CFGTABLES_EXT_POSTRECORDS(17);
  PERFORM NotifyModif (Operation, RecId, 'TARGETAG');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tari_sp_gotorecord</obj_name>
  <obj_hashval>fb25c030387a91e7f9c464f1536b3beb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tari_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_NTARI(codtara, den_tara, simbauto, codmoneda, obs, STATCOMUNITAR, CodLimba)
  (SELECT codtara, den_tara, simbauto, codmoneda, obs, STATCOMUNITAR, CodLimba FROM NTARI WHERE codtara = RecId);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tari_sp_lockrecord</obj_name>
  <obj_hashval>c5ae0f27fdaa15b499006786f613d622</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tari_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT codtara INTO Tmp FROM NTARI WHERE codtara = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tari_sp_postrecords</obj_name>
  <obj_hashval>139c6bdc63e9936cadec7b3eed7fbc3a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tari_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  vRecNo NUMERIC := 0;
  vAn    NUMERIC := 0;
  vLuna  NUMERIC := 0;
  vCod   numeric;
begin
  IF  Operation = 0 THEN
    SELECT codtara INTO RecId FROM TMP_NTARI;

    UPDATE NTARI
    SET
    (den_tara, simbauto, codmoneda, obs, STATCOMUNITAR, CodLimba) = (SELECT den_tara, simbauto, codmoneda, obs, STATCOMUNITAR, CodLimba FROM TMP_NTARI)
    WHERE
     codtara = RecId;
  ELSE
    SELECT NEXTVAL('SEQ_NTARI_CODTARA') INTO RecId;

    INSERT INTO NTARI(codtara, den_tara, simbauto, codmoneda, obs, STATCOMUNITAR, CodLimba)
    (SELECT RecId, den_tara, simbauto, codmoneda, obs, STATCOMUNITAR, CodLimba FROM TMP_NTARI);
  END IF;

  PERFORM NotifyModif( Operation, RecId, 'NTARI');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tarifeman_getgowner</obj_name>
  <obj_hashval>40901cd6ddcb319e9becc94c1d15a54e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tarifeman_getgowner(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_TARIFEMAN.gOwner', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tarifeman_gowner</obj_name>
  <obj_hashval>d079d26f470f00c53c3676f769186905</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tarifeman_gowner(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_TARIFEMAN.gOwner', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tarifeman_setgowner</obj_name>
  <obj_hashval>bf66486e78d6bfafed279dca0aac8e6d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tarifeman_setgowner(agowner character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_TARIFEMAN.gOwner',agOwner,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tarifeman_sp_deleterecord</obj_name>
  <obj_hashval>1d1fd6cb530c0281e97f86f03f1f85d2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tarifeman_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM tarifeman1 WHERE codtarif = RecId;
  DELETE FROM tarifeman  WHERE codtarif = RecId;
  PERFORM NotifyModif( 2, RecId, 'tarifeman');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tarifeman_sp_gotorecord</obj_name>
  <obj_hashval>5b735b29eae64eb10937c92113616664</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tarifeman_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC        RECORD;
  aANSFARSIT   numeric;
  aLUNASFARSIT numeric;
BEGIN
  --Florin 09.07.2024 - sinc. Oracle
  --Florin 14.03.2023 - sinc. Oracle (13.03.2023)
  --Bogdan 29.03.2021
   insert into tmp_tarifeman(Codtarif, Denumire, CodExtern, CodMoneda)
         (select Codtarif, Denumire, CodExtern, coalesce(CodMoneda,0) from tarifeman where Codtarif = RecId);

  insert into tmp_tarifeman1
  (codtarif1, codtarif,
   Tarif,
   Tarif1,
   Tarif2,
   Tarif3,
   Tarif4,
   Tarif5,
   Tarif6,
   Tarif7,
   Tarif8,
   Tarif9,
   anstart, lunastart)
  select
    T1.Codtarif1,
    T1.Codtarif,
    T1.Tarif,
    T1.Tarif1,
    T1.Tarif2,
    T1.Tarif3,
    T1.Tarif4,
    T1.Tarif5,
    T1.Tarif6,
    T1.Tarif7,
    T1.Tarif8,
    T1.Tarif9,
    T1.AnStart,
    T1.LunaStart
  from tarifeman1 T1 where Codtarif = RecId;

  FOR V_REC IN (SELECT CodTarif1, Anstart, LUNAstart FROM TMP_tarifeman1 ORDER BY ANstart * 12 + LUNAstart desc) LOOP
    IF (aANSFARSIT &lt;&gt; 0)  AND (aLUNASFARSIT &lt;&gt; 0) THEN
      UPDATE TMP_TARIFEMAN1
      SET
      ANSfarsit   = aANSFARSIT,
      LUNASfarsit = aLUNASFARSIT
      WHERE
       CodTarif1 = V_REC.CodTarif1;
    END IF;

   select newan, newluna
   from  PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( V_REC.ANStart, V_REC.LUNAStart, aANSFARSIT, aLUNASFARSIT) into  aANSFARSIT, aLUNASFARSIT;

  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tarifeman_sp_insertrecord</obj_name>
  <obj_hashval>1e8adb4d4ce024b61890a223b95f6bf0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tarifeman_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_TarifeMan(CodTarif) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tarifeman_sp_lockrecord</obj_name>
  <obj_hashval>18cfa893b5755c52f7b2e393a8ab4967</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tarifeman_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMP numeric;
begin
  SELECT CodTarif INTO tmp FROM tarifeman WHERE codtarif = recid  for update nowait;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tarifeman_sp_postrecords</obj_name>
  <obj_hashval>30022ac7197f73105b05ad935cbbd1a2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tarifeman_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
BEGIN
  --Florin 14.03.2023 - sinc. Oracle (13.03.2023)
  --Adina 15.03.2021 - prc_al_refresh
  --Bogdan 04.12.2020
  IF Operation = 0 then

  select codtarif into recid from tmp_tarifeman;
    UPDATE TarifeMan SET (Denumire, CodExtern, CodMoneda) = (SELECT Denumire, CodExtern, CodMoneda FROM TMP_TarifeMan)
    WHERE codtarif = RecId;

    delete from tarifeman1 where codtarif = recid and codtarif1 not in (select codtarif1 from tmp_tarifeman1);

    for v_rec in (select * from tmp_tarifeman1) loop

    if v_rec.codtarif1 &gt; 0 THEN
     update tarifeman1
        set
          tarif  = v_rec.tarif,
          tarif1 = v_rec.tarif1,
          tarif2 = v_rec.tarif2,
          tarif3 = v_rec.tarif3,
          tarif4 = v_rec.tarif4,
          tarif5 = v_rec.tarif5,
          tarif6 = v_rec.tarif6,
          tarif7 = v_rec.tarif7,
          tarif8 = v_rec.tarif8,
          tarif9 = v_rec.tarif9
        where codtarif1 = v_rec.codtarif1;
      else
        insert into tarifeman1 (codtarif1, codtarif,
         Tarif,
         Tarif1,
         Tarif2,
         Tarif3,
         Tarif4,
         Tarif5,
         Tarif6,
         Tarif7,
         Tarif8,
         Tarif9,
         AnStart, LunaStart)
        values (nextval('seq_tarifeman1_codtarif1'), RecId,
         v_rec.tarif,
         v_rec.Tarif1,
         v_rec.Tarif2,
         v_rec.Tarif3,
         v_rec.Tarif4,
         v_rec.Tarif5,
         v_rec.Tarif6,
         v_rec.Tarif7,
         v_rec.Tarif8,
         v_rec.Tarif9,
         v_rec.AnStart, v_Rec.LunaStart);
      end if;
    END LOOP;
  ELSE
    SELECT NEXTVAL ('SEQ_TARIFEMAN_CODTARIF') INTO RecId;

    INSERT INTO tarifeman (codtarif, Denumire, CodExtern, CodMoneda)
    SELECT RecId, Denumire, CodExtern, CodMoneda FROM tmp_tarifeman;

      insert into tarifeman1
  (codtarif1, codtarif,
   Tarif,
   Tarif1,
   Tarif2,
   Tarif3,
   Tarif4,
   Tarif5,
   Tarif6,
   Tarif7,
   Tarif8,
   Tarif9,
   anstart, lunastart)
  select nextval('seq_tarifeman1_codtarif1'), RecId,
    Tarif,
    Tarif1,
    Tarif2,
    Tarif3,
    Tarif4,
    Tarif5,
    Tarif6,
    Tarif7,
    Tarif8,
    Tarif9,
    AnStart,
    LunaStart
    from tmp_tarifeman1;
  end if;

  CALL PRC_AL_REFRESH('tarifeman1', RecId);
  PERFORM NotifyModif (Operation, RecId, 'tarifeman');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_taxe_accize_pregateste_temporar_accize</obj_name>
  <obj_hashval>4f13a817a2ff794d5e2213699f0f7b33</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_taxe_accize_pregateste_temporar_accize(atip numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  semn NUMERIC;
BEGIN
  --Florin 05.03.2025 - sinc. Oracle
  --Florin 13.09.2023 - sinc. Oracle
  --Florin 16.12.2022 - fixat 56579
  --Florin 09.12.2022 - sinc. Oracle
  DELETE FROM TMP_TAXE_ACCIZE;
  INSERT INTO TMP_TAXE_ACCIZE(CODOBIECT, CODSERVFACT, VALOARE, CODTAXA, LACEAPLIC, MASA, VOLUM, CANT, PRET, BAZAMAX, BAZAMIN, PROC, CODLINIE, ROTVALOARE)
  SELECT *
  FROM (
        (
        SELECT INFOOBIECT.CODOBIECT, TAXELUNA.CODSERVFACT, TAXELUNA.VALOARE, TAXELUNA.CODTAXA, TAXELUNA.LACEAPLIC, INFOOBIECT.MASA, INFOOBIECT.VOLUM, INFOOBIECT.CANT, INFOOBIECT.PRET, TAXELUNA.BazaMax, TAXELUNA.BazaMin, 0 AS PROC, INFOOBIECT.CODLINIE, TAXELUNA.ROTVALOARE
        FROM (SELECT O.CODOBIECT, NART1LUNA.CODACCIZE, NART1LUNA.CODTAXA1, NART1LUNA.CODTAXA2, COALESCE( O.MASA, 0) AS MASA, COALESCE( O.VOLUM, 0) AS VOLUM, O_F.CANT, O_F.PRET, O_F.CODLINIE
              FROM TMP_OBIECTE_FACTURATE O_F, NARTOBJ O LEFT JOIN TMP_NART_LUNA NART1LUNA ON  NART1LUNA.CODARTICOL = O.CODARTICOL
              WHERE O.CODOBIECT = O_F.CODOBIECT
              ) INFOOBIECT,
              (SELECT CODTAXA, CODTAXA1, VALOARE, FACTURABIL, CODSERVFACT, LACEAPLIC, BazaMax, BazaMin, ROTVALOARE
               FROM NTAXE1 T1
               WHERE getANLUNALUCRU() BETWEEN T1.ALSTART AND T1.ALSTOP
               AND  FACTURABIL = 1 AND  COALESCE( CODSERVFACT, 0) &lt;&gt; 0 AND ((aTip = 1 and  COALESCE( JAchiz, 0) = 1)  or (aTip = 2 and  COALESCE( JVanz, 1) = 1) )
              ) TAXELUNA
        WHERE INFOOBIECT.CODACCIZE = TAXELUNA.CODTAXA
        )
        union ALL
        (
        SELECT INFOOBIECT.CODOBIECT, TAXELUNA.CODSERVFACT, TAXELUNA.VALOARE, TAXELUNA.CODTAXA, TAXELUNA.LACEAPLIC, INFOOBIECT.MASA, INFOOBIECT.VOLUM, INFOOBIECT.CANT, INFOOBIECT.PRET, TAXELUNA.BazaMax, TAXELUNA.BazaMin, 0 AS PROC, INFOOBIECT.CODLINIE, TAXELUNA.ROTVALOARE
        FROM (SELECT O.CODOBIECT, NART1LUNA.CODACCIZE, NART1LUNA.CODTAXA1, NART1LUNA.CODTAXA2, COALESCE( O.MASA, 0) AS MASA, COALESCE( O.VOLUM, 0) AS VOLUM, O_F.CANT, O_F.PRET, O_F.CODLINIE
              FROM TMP_OBIECTE_FACTURATE O_F, NARTOBJ O LEFT JOIN TMP_NART_LUNA NART1LUNA ON  NART1LUNA.CODARTICOL = O.CODARTICOL
              WHERE O.CODOBIECT = O_F.CODOBIECT
              ) INFOOBIECT,
              (SELECT CODTAXA, CODTAXA1, VALOARE, FACTURABIL, CODSERVFACT, LACEAPLIC, BazaMax, BazaMin, ROTVALOARE
               FROM NTAXE1 T1
               WHERE getANLUNALUCRU() BETWEEN T1.ALSTART AND T1.ALSTOP
                 AND  FACTURABIL = 1 AND  COALESCE( CODSERVFACT, 0) &lt;&gt; 0 AND ((aTip = 1 and  COALESCE(JAchiz, 0) = 1) or (aTip &gt;= 2 and  COALESCE( JVanz, 1) = 1) )
              ) TAXELUNA
        WHERE INFOOBIECT.CODTAXA1 = TAXELUNA.CODTAXA
        )
        union ALL
        (
        SELECT INFOOBIECT.CODOBIECT, TAXELUNA.CODSERVFACT, TAXELUNA.VALOARE, TAXELUNA.CODTAXA, TAXELUNA.LACEAPLIC, INFOOBIECT.MASA, INFOOBIECT.VOLUM, INFOOBIECT.CANT, INFOOBIECT.PRET, TAXELUNA.BazaMax, TAXELUNA.BazaMin, 0 AS PROC, INFOOBIECT.CODLINIE, TAXELUNA.ROTVALOARE
        FROM (SELECT O.CODOBIECT, NART1LUNA.CODACCIZE, NART1LUNA.CODTAXA1, NART1LUNA.CODTAXA2, COALESCE( O.MASA, 0) AS MASA, COALESCE( O.VOLUM, 0) AS VOLUM, O_F.CANT, O_F.PRET, O_F.CODLINIE
              FROM TMP_OBIECTE_FACTURATE O_F, NARTOBJ O LEFT JOIN TMP_NART_LUNA NART1LUNA ON  NART1LUNA.CODARTICOL = O.CODARTICOL
              WHERE O.CODOBIECT = O_F.CODOBIECT
             ) INFOOBIECT,
             (SELECT CODTAXA, CODTAXA1, VALOARE, FACTURABIL, CODSERVFACT, LACEAPLIC, BazaMax, BazaMin, ROTVALOARE
              FROM NTAXE1 T1
              WHERE getANLUNALUCRU() BETWEEN T1.ALSTART AND T1.ALSTOP
                AND  FACTURABIL = 1 AND  COALESCE( CODSERVFACT, 0) &lt;&gt; 0 AND (  (   aTip = 1 and  COALESCE( JAchiz, 0) = 1)  or (   aTip = 2 and  COALESCE( JVanz, 1) = 1) )
             ) TAXELUNA
        WHERE INFOOBIECT.CODTAXA2 = TAXELUNA.CODTAXA
        )
       ) A_PG;

  IF  aTip = 1 THEN
    Semn := -1;
  ELSE
    Semn := 1;
  END IF;

  UPDATE TMP_TAXE_ACCIZE
  SET
  PROC = Semn * Round( Pret * VALOARE / (  100 + VALOARE) , 2)
  WHERE
   LACEAPLIC = 1;

  UPDATE TMP_TAXE_ACCIZE
  SET
  PROC = Semn * Round( Pret * VALOARE / 100, 2)
  WHERE
   LACEAPLIC = 2;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_teme_sp_deleterecord</obj_name>
  <obj_hashval>934cfbf062c91f12beecef49ef434616</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_teme_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_TEME_SP_LOCKRECORD( RecId);
  DELETE FROM TEME WHERE CodTEMA = RecId;
  PERFORM NotifyModif( 2, RecId, 'TEME');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_teme_sp_gotorecord</obj_name>
  <obj_hashval>02b3b8641ee292c519bee73a9f3e59ff</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_teme_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_TEME (CodTEMA, den_TEMA, ORE, PRET, CodFORMATOR)
  (SELECT CodTEMA, den_TEMA, ORE, PRET, CodFORMATOR FROM TEME WHERE CodTEMA = RecId);

  INSERT INTO TMP_NPERSCURSY (CODNPERSCURS, CODPERS, CODCURS, STARE, NOTA, DATA, DATAPLAN, ORE_REALIZ)
  SELECT - row_number() over(), CODPERS, CODCURS, STARE, NOTA, DATA, DATAPLAN, ORE_REALIZ
  FROM (SELECT NP.CodPers, NP.CodCurs, COALESCE (NP.STARE, 0) STARE, NP.Nota NOTA, NP.Data, NP.DataPlan, NP.ORE_REALIZ
        FROM NPERSCURS NP WHERE NP.CodTema = RecID
       ) A_PG;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_teme_sp_lockrecord</obj_name>
  <obj_hashval>77f6eccdd8e176fbb057d9a868f213ef</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_teme_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CodTEMA INTO Tmp FROM TEME WHERE CodTEMA = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_teme_sp_postrecords</obj_name>
  <obj_hashval>0fa86c5f58805f5e80fff54d055b24f9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_teme_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCurs       numeric;
  aIndexLocal numeric;
begin
  IF  Operation = 0 THEN
    SELECT CodTEMA INTO RecId FROM TMP_TEME;

    UPDATE TEME
    SET
    (den_TEMA, ORE, PRET, CodFORMATOR) = (SELECT den_TEMA, ORE, PRET, CodFORMATOR FROM TMP_TEME)
    WHERE CodTEMA = RecId;
  ELSE
    SELECT NEXTVAL('SEQ_TEME_CODTEMA') INTO RecId;

    INSERT INTO TEME(CodTEMA, den_TEMA, ORE, PRET, CodFORMATOR)
    (SELECT RecId, den_TEMA, ORE, PRET, CodFORMATOR FROM TMP_TEME);

    SELECT COALESCE( CodCurs, 0) INTO aCurs FROM TMP_TEME;

    IF  aCurs &lt;&gt; 0 THEN
      SELECT Count( *) INTO aIndexLocal FROM Cursuri1 WHERE CodCurs = aCurs;

      INSERT INTO CURSURI1(CodCurs1, CodCurs, IndexLocal, CodTema)
      VALUES(NEXTVAL('SEQ_CURSURI1_CODCURS1'), aCurs, aIndexLocal + 1, RecId);
    END IF;
  END IF;

  PERFORM NotifyModif( Operation, RecId, 'TEME');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_teme_teme_getpers</obj_name>
  <obj_hashval>c7c3121a14bd381165f7b80918684a3c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_teme_teme_getpers()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 30.12.2021 - sinc. Oracle (29.12.2021)
  INSERT INTO TMP_NPERSCURS0(CODPERS, NUME, PRENUME, FORMATIE, FUNCTIE, MESERIE, SCHIMB, DataAngajarii, DataPlecarii, Plecat, ACTIV, SELECTAT)
  SELECT CODPERS, NUME, PRENUME, FORMATIE, FUNCTIE, MESERIE, SCHIMB, DataAngajarii, DataPlecarii, CASE WHEN  LuniRamase &lt; 0 THEN 1 ELSE 0 END , ACTIV, SELECTAT
  FROM (SELECT P.CodPers, P.Nume, P.Prenume, C.Den_Formatie FORMATIE, F.DENUMIRE FUNCTIE, M.DEN_MESERIE MESERIE, P1.Schimb, p.DataAngajarii, p.DataPlecarii,
               Extract( YEAR FROM COALESCE( DataPlecarii, CURRENT_TIMESTAMP)) * 12 + Extract( MONTH FROM COALESCE( DataPlecarii, CURRENT_TIMESTAMP)) - (SELECT PKG_GLOBALS_AnLunaLucru.WME_RESULT FROM PKG_GLOBALS_AnLunaLucru(NULL,NULL)) LUNIRAMASE,
               COALESCE( p.ACTIV, 1) ACTIV, 0 SELECTAT
        FROM NPers P
             inner join NPERS1 P1 on P1.CodPers = P.CodPers AND GETANLUNALUCRU() BETWEEN P1.ALSTART AND p1.ALSTOP
             LEFT JOIN Formatii C ON  C.CodFormatie = P1.CodFormatie
             LEFT JOIN Functii  F ON  F.CodFunctie  = P1.CodFunctie
             LEFT JOIN NMESERII M ON  M.CodMeserie  = P1.CodMeserie
  WHERE
    (COALESCE( p.ACTIV, 1) = 1)  or (p.ACTIV = 0 and  Extract( YEAR FROM DataPlecarii) * 12 + Extract( MONTH FROM DataPlecarii) &gt;= (SELECT PKG_GLOBALS_AnLunaLucru.WME_RESULT FROM PKG_GLOBALS_AnLunaLucru(NULL,NULL)))
  ) A_PG
  WHERE LuniRamase &gt;= -1;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_teme_teme_gotorecord</obj_name>
  <obj_hashval>c75fb294f8d7005b8bb9b3ad21f821bd</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_teme_teme_gotorecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Bogdan 18.12.2020
  INSERT INTO TMP_NPERSCURS (CODNPERSCURS, CODPERS, CODFUNCTIE, CODCURS,
      CODTEMA, STARE, DATA, NOTA,
      DATAPLAN, ORE_REALIZ, SUPLIM, DEN_CURS,
      DEN_TEMA, SSTARE, ORE_AFER, Nume,
      Prenume, Activ, DataPlecarii, DataAngajarii,
      Plecat, TipFormare, NivelFormare, CodObiectiv,
      Den_Obiectiv, Sel)
  WITH CF AS
    ( SELECT  DISTINCT P1.CodPers, F1.CodCurs, F1.CodTema, x.Activ, x.DataPlecarii, x.DataAngajarii, x.Plecat, 0 SUPLIM
      FROM NPERS1           P1
        INNER JOIN FUNCTII1 F1 ON F1.CodFunctie = P1.Codfunctie
        INNER JOIN (SELECT CodPers, Activ, DataPlecarii, DataAngajarii, Plecat FROM TMP_NPERSCURS0 WHERE Selectat = 1) X ON X.CodPers = P1.CodPers
    )
    , PC AS
    ( SELECT NP.CodPers, NP.CODNPERSCURS, COALESCE (NP.codfunctie, 0) CODFUNCTIE, NP.CodCurs,
             NP.CodTema, COALESCE (NP.STARE, 0) STARE,
             CASE WHEN COALESCE (NP.codfunctie, 0) = 0 THEN 1 ELSE 0 END SUPLIM, NP.Nota, NP.Data, NP.DataPlan,
             NP.TipFormare, NP.NivelFormare, NP.CodObiectiv, NP.ORE_REALIZ, x.Activ, x.DataPlecarii, x.DataAngajarii, x.Plecat
      FROM NPERSCURS NP
        INNER JOIN (SELECT CodPers, Activ, DataPlecarii, DataAngajarii, Plecat FROM TMP_NPERSCURS0 WHERE Selectat = 1) X ON X.CodPers = NP.CodPers
    )
  SELECT TMP.CODNPERSCURS, TMP.CODPERS, TMP.CodFunctie, TMP.CODCURS,
    TMP.CODTEMA, TMP.STARE, TMP.DATA, TMP.NOTA,
    TMP.DATAPLAN, TMP.ORE_REALIZ, TMP.Suplim, CC.DEN_CURS,
    TT.DEN_TEMA, 'xxxxxxxxxx', TT.ORE, P.Nume,
    P.Prenume, TMP.Activ, TMP.DataPlecarii, TMP.DataAngajarii,
    TMP.Plecat, TMP.TipFormare, TMP.NivelFormare, TMP.CodObiectiv,
    O.Den_Obiectiv, 0 SEL
  FROM (SELECT PC.CODNPERSCURS, PC.CodPers, COALESCE (PC.CodFunctie, 0) CODFUNCTIE, PC.CodCurs,
               PC.CodTema, PC.DATA, PC.DATAPLAN, PC.ORE_REALIZ, COALESCE (PC.STARE, 0) STARE, PC.Nota, PC.Activ, PC.DataPlecarii,
               PC.DataAngajarii, PC.Plecat, PC.Suplim, COALESCE (PC.TipFormare, 0) TIPFORMARE,
               COALESCE (PC.NivelFormare, 0) NIVELFORMARE, COALESCE (PC.CodObiectiv, 0) CODOBIECTIV
        FROM PC
        union ALL
        SELECT - row_number() over() CODNPERSCURS, CF.CODPERS, -1 CODFUNCTIE, COALESCE (CF.CodCurs, 0) CODCURS,
               COALESCE (CF.CodTema, 0) CODTEMA, null AS DATA, null DATAPLAN, 0 ORE_REALIZ, 0 STARE, null NOTA, CF.Activ, CF.DataPlecarii,
               CF.DataAngajarii, CF.Plecat, 0 SUPLIM, 0 TIPFORMARE, 0 NIVELFORMARE, 0 CODOBIECTIV
        FROM CF
        WHERE
          NOT EXISTS (SELECT CodNPERSCURS FROM NPERSCURS WHERE COALESCE (CodFunctie, 0) &lt;&gt; 0 and CodCurs = CF.CodCurs and CodTema = CF.CodTema and Codpers = CF.CodPers)
       ) TMP
    INNER JOIN Npers    P  ON P.Codpers     = TMP.CodPers
    LEFT JOIN CURSURI   CC ON CC.CodCurs    = TMP.CodCurs
    LEFT JOIN TEME      TT ON TT.CodTema    = TMP.CodTEMA
    LEFT JOIN OBIECTIVE O  ON O.CodObiectiv = TMP.CodObiectiv;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tesaturi_sp_deleterecord</obj_name>
  <obj_hashval>24fd8dfdcb6226dc829bc17ecbe939f0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tesaturi_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_TESATURI_SP_LOCKRECORD( RecId);
  DELETE FROM TESATURI WHERE CodTESATURA = RecId;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tesaturi_sp_insertrecord</obj_name>
  <obj_hashval>9224f2e637fb873cbd686fbe5c356cce</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tesaturi_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_TESATURI (CodTESATURA) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tesaturi_sp_lockrecord</obj_name>
  <obj_hashval>19f1f0291172c98aeeae5070e926d6d7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tesaturi_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CodTESATURA INTO Tmp FROM TESATURI WHERE CodTESATURA = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tesaturi_sp_postrecords</obj_name>
  <obj_hashval>f666e1128e351ef8b8376168fc90e4ed</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tesaturi_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  IF  Operation = 0 THEN
    BEGIN
      SELECT CodTESATURA INTO RECID FROM TMP_TESATURI;
    EXCEPTION WHEN OTHERS THEN
      RECID := 0;
    END;

    UPDATE TESATURI
    SET
    (DENUMIRE, COMPOZITIE, MASASPECIFICA, LEGATURA, DESIMEU, DESIMEB, CATEGORIE)
    =
    (SELECT DENUMIRE, COMPOZITIE, MASASPECIFICA, LEGATURA, DESIMEU, DESIMEB, CATEGORIE FROM TMP_TESATURI)
    WHERE
     CodTESATURA = RECID;
  ELSE
    SELECT NEXTVAL('SEQ_TESATURI_CODTESATURA') INTO RecId;

    INSERT INTO TESATURI(CODTESATURA, DENUMIRE, COMPOZITIE, MASASPECIFICA, LEGATURA, DESIMEU, DESIMEB, CATEGORIE)
    SELECT RECID, DENUMIRE, COMPOZITIE, MASASPECIFICA, LEGATURA, DESIMEU, DESIMEB, CATEGORIE FROM TMP_TESATURI;
  END IF;

  PERFORM NotifyModif( Operation, RecId, 'TESATURI');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tipchelt_sp_deleterecord</obj_name>
  <obj_hashval>876f3f3cd4587ecd926281d71796af71</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tipchelt_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TIPCHELT WHERE CODTIPCHELT = RECID;
  PERFORM NotifyModif( 2, RecId, 'TIPCHELT');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tipchelt_sp_gotorecord</obj_name>
  <obj_hashval>d18cdc299ad1f7020dbe157471e9f8b8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tipchelt_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_TIPCHELT(CODTIPCHELT, DENUMIRE, CODCONT)
  SELECT CODTIPCHELT, DENUMIRE, CODCONT FROM TIPCHELT WHERE CODTIPCHELT = RECID;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tipchelt_sp_lockrecord</obj_name>
  <obj_hashval>e4994767cab48435f16d126cc9b4084a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tipchelt_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMP numeric;
begin
  SELECT CODTIPCHELT INTO TMP FROM TIPCHELT WHERE CODTIPCHELT = RECID FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tipchelt_sp_postrecords</obj_name>
  <obj_hashval>3c1307d6f08df175cba9970bc56060db</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tipchelt_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  IF  OPERATION = 0 THEN
    SELECT CODTIPCHELT INTO RECID FROM TMP_TIPCHELT;

    UPDATE TIPCHELT
    SET
    (DENUMIRE, CODCONT) = (SELECT DENUMIRE, CODCONT FROM TMP_TIPCHELT)
    WHERE
     CODTIPCHELT = RECID;
  ELSE
    SELECT NEXTVAL('SEQ_TIPCHELT_CODTIPCHELT') INTO RECID;

    INSERT INTO TIPCHELT(CODTIPCHELT, DENUMIRE, CODCONT)
    SELECT RECID, DENUMIRE, CODCONT FROM TMP_TIPCHELT;
  END IF;

  PERFORM NotifyModif( Operation, RecId, 'TIPCHELT');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tiplucrarisa_sp_deleterecord</obj_name>
  <obj_hashval>faa9cf77b6431cfc5b51671f73fa46ec</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tiplucrarisa_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_TIPLUCRARISA_SP_LOCKRECORD( RecId);
  DELETE FROM TIPLUCRARISA  WHERE CodTipLucrare = RecId;
  DELETE FROM TIPLUCRARISA1 WHERE CodTipLucrare = RecId;
  PERFORM NotifyModif( 2, RECID, 'TIPLUCRARISA');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tiplucrarisa_sp_gotorecord</obj_name>
  <obj_hashval>e1d60c59f3613b9a7dc0eb093196eb1d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tiplucrarisa_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  n numeric;
BEGIN
  --Florin 20.09.2022 - fixat 55622
  INSERT INTO TMP_TIPLUCRARISA(CodTipLucrare, Denumire, ArtServFact, ClasaLucrari, Toti, CodGest, CODINTERVENTIE)
  (SELECT CodTipLucrare, Denumire, ArtServFact, ClasaLucrari, Toti, CodGest, CODINTERVENTIE FROM TIPLUCRARISA WHERE CodTipLucrare = RecId);

  INSERT INTO TMP_TIPLUCRARISA1(CodTipLucrare1, CodTipLucrare, CodPers, nume, prenume, obs)
  (SELECT T.CodTipLucrare1, T.CodTipLucrare, T.CodPers, P.nume, P.prenume, P.obs
   FROM TIPLUCRARISA1 T INNER JOIN NPERS P ON  P.Codpers = T.Codpers
   WHERE CodTipLucrare = RECID
  );
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tiplucrarisa_sp_insertrecord</obj_name>
  <obj_hashval>be6e268091a1be1925f3cba7832f94b6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tiplucrarisa_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_TIPLUCRARISA (CodTipLucrare) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tiplucrarisa_sp_lockrecord</obj_name>
  <obj_hashval>667a562a0547e16e72e35c747dd9ce67</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tiplucrarisa_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CodTipLucrare INTO Tmp FROM TIPLUCRARISA WHERE CodTipLucrare = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tiplucrarisa_sp_postrecords</obj_name>
  <obj_hashval>d9270def94be7db734a54cba8b540606</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tiplucrarisa_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  Cod   numeric;
  n     numeric;
BEGIN
  --Florin 23.09.2022 - fixat 55688
  --Florin 20.09.2022 - fixat 55622
  IF  Operation = 0 THEN
    SELECT CodTipLucrare INTO RECID FROM TMP_TIPLUCRARISA;

    UPDATE TIPLUCRARISA
    SET
    (Denumire, ArtServFact, ClasaLucrari, Toti, CodGest, CODINTERVENTIE) = (SELECT Denumire, ArtServFact, ClasaLucrari, Toti, CodGest, CODINTERVENTIE FROM TMP_TIPLUCRARISA)
    WHERE
     CodTipLucrare = RecId;

    DELETE FROM TIPLUCRARISA1 WHERE CODTIPLUCRARE = RecID and CodTIPLUCRARE1 NOT IN (SELECT CODTIPLUCRARE1 FROM TMP_TIPLUCRARISA1);

    FOR v_rec IN (SELECT * FROM TMP_TIPLUCRARISA1) LOOP
      IF  V_Rec.CodTIPLUCRARE1 &lt; 0 THEN
        INSERT INTO TIPLUCRARISA1(CODTIPLUCRARE1, CODTIPLUCRARE, CODPERS)
        VALUES(NEXTVAL('SEQ_TIPLUCRARISA1_CODTIPLUCR1'), RecId, V_REC.CODPERS);
      ELSE
        UPDATE TIPLUCRARISA1 SET CODPERS = V_REC.CODPERS WHERE CODTIPLUCRARE1 = v_rec.CODTIPLUCRARE1;
      END IF;
    END LOOP;
  ELSE
    SELECT NEXTVAL('SEQ_TIPLUCRARISA_CODTIPLUCRARE') INTO RecId;

    INSERT INTO TIPLUCRARISA(CodTipLucrare, Denumire, ArtServFact, ClasaLucrari, Toti, CodGest, CODINTERVENTIE)
    (SELECT RecId, Denumire, ArtServFact, ClasaLucrari, Toti, CodGest, CODINTERVENTIE FROM TMP_TIPLUCRARISA);

    INSERT INTO TIPLUCRARISA1(CodTipLucrare1, CodTipLucrare, CodPers)
    (SELECT NEXTVAL('SEQ_TIPLUCRARISA1_CODTIPLUCR1'), RECID, CodPers FROM TMP_TIPLUCRARISA1);
  END IF;

  PERFORM NotifyModif( OPERATION, RECID, 'TIPLUCRARISA');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tippartincert_sp_gotorecord</obj_name>
  <obj_hashval>8e88e4cc2a9d0490312a81d52bacac58</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tippartincert_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_TIPPARTINCERT(SELECT * FROM TIPPARTINCERT WHERE CodTIPPARTINCERT = RecId);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tippartincert_sp_insertrecord</obj_name>
  <obj_hashval>73e83417cf1ebcf3f8f7fc3f662ba02f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tippartincert_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_TIPPARTINCERT (CODTIPPARTINCERT) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tippartincert_sp_lockrecord</obj_name>
  <obj_hashval>1e62f4ebba3e77b818d8f530d9ddceae</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tippartincert_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CODTIPPARTINCERT INTO Tmp FROM TIPPARTINCERT WHERE CODTIPPARTINCERT = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tippartincert_sp_postrecords</obj_name>
  <obj_hashval>4b60f7b2c1f06310dc5dcb2a9cd1b159</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tippartincert_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  IF  Operation = 0 THEN
    SELECT CodTIPPARTINCERT INTO RecId FROM TMP_TIPPARTINCERT;

    UPDATE TIPPARTINCERT
    SET
    (TIPCLIENT, TIPIMPOZITARE) = (SELECT TIPCLIENT, TIPIMPOZITARE FROM TMP_TIPPARTINCERT)
    WHERE
     CODTIPPARTINCERT = RecId;
  ELSE
    SELECT NEXTVAL('SEQ_TIPPARTINCERT_COD') INTO RecId;

    INSERT INTO TIPPARTINCERT(CODTIPPARTINCERT, TIPCLIENT, TIPIMPOZITARE)
    (SELECT RecId, TIPCLIENT, TIPIMPOZITARE FROM TMP_TIPPARTINCERT);
  END IF;

  PERFORM NotifyModif( Operation, RecId, 'TIPPARTINCERT');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tipsedii_sp_deleterecord</obj_name>
  <obj_hashval>7a170ac5101ea75c20dd461938af96c3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tipsedii_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_TIPSEDII_SP_LOCKRECORD( RecId);
  DELETE FROM NTIPSEDII1 WHERE CODTIPSEDIU = RecId;
  DELETE FROM NTIPSEDII  WHERE CODTIPSEDIU = RecId;
  PERFORM NotifyModif( 2, RecId, 'NTIPSEDII');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tipsedii_sp_gotorecord</obj_name>
  <obj_hashval>a67b50cfa820517937e419c3e6e40eee</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tipsedii_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 30.05.2024 - sinc. Oracle
  INSERT INTO  TMP_NTIPSEDII (CODTIPSEDIU, DENUMIRE, ICLASA, CONTRONLY, TIPBENEFICIAR )
  SELECT CODTIPSEDIU, DENUMIRE, ICLASA, CONTRONLY, TIPBENEFICIAR
  FROM NTIPSEDII
  WHERE CODTIPSEDIU = RecId;

  INSERT INTO  TMP_NTIPSEDII1 (CODTIPSEDIU1, CODTIPSEDIU, CODCLASEA, CODOBIECT, DENCLASEA, DENOBIECT )
  SELECT N1.CODTIPSEDIU1, N1.CODTIPSEDIU, N1.CODCLASEA, N1.CODOBIECT, A.simbol, O.DENUMIRE
  FROM NTIPSEDII1 N1
    LEFT JOIN NCLASEA A ON N1.CodClasea  = A.CODCLASEA
    LEFT JOIN NARTOBJ O ON N1.CodObiect =  O.CODOBIECT
  WHERE N1.CODTIPSEDIU = RecId AND NVL(N1.CODCLASEA, 0) &lt;&gt; 0;

  INSERT INTO  TMP_NTIPSEDII2 (CODTIPSEDIU1, CODTIPSEDIU, CODCLASEA, CODOBIECT, DENCLASEA, DENOBIECT )
  SELECT N1.CODTIPSEDIU1, N1.CODTIPSEDIU, N1.CODCLASEA, N1.CODOBIECT, A.simbol, O.DENUMIRE
  FROM NTIPSEDII1 N1
    LEFT JOIN NCLASEA A ON N1.CodClasea  = A.CODCLASEA
    LEFT JOIN NARTOBJ O ON N1.CodObiect =  O.CODOBIECT
  WHERE N1.CODTIPSEDIU = RecId AND NVL(N1.CODOBIECT, 0) &lt;&gt; 0;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tipsedii_sp_insertrecord</obj_name>
  <obj_hashval>1ed02e2d385eacf1cf2c619487cfd5f3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tipsedii_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_NTIPSEDII (CODTIPSEDIU, ICLASA) VALUES(0, 0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tipsedii_sp_postrecords</obj_name>
  <obj_hashval>f32ce350680818f8ab49c9d0445dbef2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tipsedii_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  --Florin 30.09.2024 - fixat 63535
  --Florin 30.05.2024 - sinc. Oracle
  IF Operation = 0 THEN  -- UPDATE
    select CODTIPSEDIU into RecId from TMP_NTIPSEDII;
    UPDATE NTIPSEDII SET (DENUMIRE, ICLASA, CONTRONLY, TIPBENEFICIAR) = ( SELECT DENUMIRE, ICLASA, CONTRONLY, TIPBENEFICIAR FROM TMP_NTIPSEDII )
    WHERE CODTIPSEDIU = RecId ;

    DELETE FROM NTIPSEDII1
    WHERE CodTipSediu = RecId
      AND CodTipSediu1 NOT IN (SELECT CodTipSediu1 FROM TMP_NTIPSEDII1 UNION SELECT CodTipSediu1 FROM TMP_NTIPSEDII2);

    INSERT INTO NTIPSEDII1 ( CodTipSediu1, Codtipsediu, CODCLASEA, CODOBIECT)
    SELECT NextVal('seq_tipsedii1_codtipsediu1'), RecId, CodClaseA, CODOBIECT
    FROM TMP_NTIPSEDII1 WHERE CodTipSediu1 &lt; 0;

    INSERT INTO NTIPSEDII1 ( CodTipSediu1, Codtipsediu, CODCLASEA, CODOBIECT)
    SELECT NextVal('seq_tipsedii1_codtipsediu1'), RecId, CodClaseA, CODOBIECT
    FROM TMP_NTIPSEDII2 WHERE CodTipSediu1 &lt; 0;

    FOR v_rec IN (
      SELECT CODTIPSEDIU1, CODTIPSEDIU, CODCLASEA, CODOBIECT FROM tmp_ntipsedii1 WHERE Coalesce(codtipsediu1, 0) &gt; 0 UNION
      SELECT CODTIPSEDIU1, CODTIPSEDIU, CODCLASEA, CODOBIECT FROM tmp_ntipsedii2 WHERE Coalesce(codtipsediu1, 0) &gt; 0
    ) LOOP
      UPDATE NTIPSEDII1
      SET CodTipSediu = v_rec.codtipsediu,
          CodClaseA   = v_rec.codclasea,
          CODOBIECT   = v_rec.Codobiect
      WHERE CodTipSediu1 = v_rec.codtipsediu1;
    END LOOP;
  ELSE  -- INSERT
    SELECT NextVal('SEQ_NTIPSEDII_CODTIPSEDIU') INTO RECID;
    INSERT INTO NTIPSEDII (CODTIPSEDIU, DENUMIRE, ICLASA, CONTRONLY, TIPBENEFICIAR)
    SELECT RecId, DENUMIRE, IClasa, CONTRONLY, TIPBENEFICIAR
    FROM TMP_NTIPSEDII;

    INSERT INTO NTIPSEDII1 (CodTipSediu1, Codtipsediu, CODCLASEA, CODOBIECT)
    SELECT NextVal('seq_tipsedii1_codtipsediu1'), RecId, codclasea, CODOBIECT
    FROM tmp_ntipsedii1;

    INSERT INTO NTIPSEDII1 (CodTipSediu1, Codtipsediu, CODCLASEA, CODOBIECT)
    SELECT NextVal('seq_tipsedii1_codtipsediu1'), RecId, codclasea, CODOBIECT
    FROM tmp_ntipsedii2;
  END IF;
  PERFORM NotifyModif(Operation, RecId, 'NTIPSEDII');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_toword_sp_deleterecord</obj_name>
  <obj_hashval>63c6f12115031fe83d2231263f2d9e08</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_toword_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 12.10.2022
  PERFORM pkg_toWord_SP_LOCKRECORD(RecId);
  DELETE FROM ToWord  WHERE CodToWord = RecId ;
  PERFORM NotifyModif(2, RecId, 'ToWord');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_toword_sp_gotorecord</obj_name>
  <obj_hashval>338013d5768323c53562715e1bd78520</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_toword_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 12.10.2022
   INSERT INTO  TMP_ToWord ( CodToWord, CodDoc, NumeDoc, SQLView, SQLDate, SQLLinii, Cale, NumeView)
    ( SELECT CodToWord, CodDoc, NumeDoc, SQLView, SQLDate, SQLLinii, Cale, NumeView
    FROM ToWord WHERE CodToWord = RecId ) ;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_toword_sp_insertrecord</obj_name>
  <obj_hashval>a048c955f1eed2ebcc6d2edf2db026f3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_toword_sp_insertrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 12.10.2022
   INSERT INTO  TMP_ToWord ( CodToWord ) VALUES (0) ;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_toword_sp_lockrecord</obj_name>
  <obj_hashval>6c60f60ff7042324f320f4f2be31ff05</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_toword_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  tmp numeric(20);
BEGIN
  --Florin 12.10.2022
  SELECT CodToWord INTO Tmp FROM ToWord WHERE CodToWord = RecId FOR UPDATE NOWAIT;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_toword_sp_postrecords</obj_name>
  <obj_hashval>eeb7abfd986459bfb6ba5f03e24e8eee</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_toword_sp_postrecords(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 30.09.2024 - from dual
  --Florin 12.10.2022
  IF Operation = 0 THEN  -- UPDATE
    SELECT CodToWord INTO RecId FROM TMP_ToWord;
    UPDATE ToWord SET ( CodDoc, NumeDoc, SQLView, SQLDate, SQLLinii, Cale, NumeView )
                       = ( SELECT CodDoc, NumeDoc, SQLView, SQLDate, SQLLinii, Cale, NumeView FROM TMP_ToWord )
    WHERE CodToWord = RecId;
  ELSE  -- INSERT
    SELECT nextval('Seq_ToWord_CodToWord') INTO RecId;
    INSERT INTO  ToWord ( CodToWord, CodDoc, NumeDoc, SQLView, SQLDate, SQLLinii, Cale, NumeView)
              ( SELECT  RecId , CodDoc, NumeDoc, SQLView, SQLDate, SQLLinii, Cale, NumeView
                FROM Tmp_ToWord ) ;
  END IF;
  PERFORM NotifyModif(Operation, RecId, 'ToWord');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transeini_geti</obj_name>
  <obj_hashval>c57275cc8964d125c89288c284a5a97b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transeini_geti(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_TRANSEINI.I', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transeini_sp_deleterecord</obj_name>
  <obj_hashval>920311d39d2e37ed1572caa31d39134e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transeini_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC      RECORD;
  V_RECOBLIG RECORD;
  NR         numeric := 0;
begin
  FOR V_REC IN
  (
  SELECT T1.CODTREZOR1, T1.DOC, T1.NRDOC, T1.DATADOC, T1.OBS, T.SUBUNITATEA, T.CODTREZOR
  FROM TREZOR T, NBANKCONT BC, TREZOR1 T1
  WHERE T.TIPDOC = 30 AND  T.AN * 12 + T.LUNA &lt; TO_NUMBER((current_setting('PKG_GLOBALS.ANINITIAL', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_GLOBALS.LUNAINITIALA', true)),'999999999999999999')
   AND  T.CODBANCA = RECID AND  BC.CODBANKCONT = T.CODBANCA AND  BC.CREDIT = 1 AND  T1.CODTREZOR = T.CODTREZOR AND  T1.TIPTRANZ = 0 AND  T1.OBIECTTRANZ = 3
  )
  LOOP
    FOR V_RECOBLIG IN (SELECT G.CODGENERAL, G.CODDOC, G.MONEDA, G.CURS, O.CODOBLIGPIF, O.CODPART, O.ICONT, O.VALOARE
                       FROM GENERAL G, OBLIGPIF O
                       WHERE G.TIPDOC = 30 AND  G.CODDOC = V_REC.CODTREZOR1 AND  G.CODGENERAL = O.CODGENERAL
                      )
    LOOP
      DELETE FROM OBLIGPIF WHERE CODOBLIGPIF = V_RECOBLIG.CODOBLIGPIF;
      DELETE FROM GENERAL  WHERE CODGENERAL = V_RECOBLIG.CODGENERAL;

      SELECT COUNT( *) INTO NR FROM GENERAL WHERE CODGENERAL = V_REC.CODTREZOR1 AND  CODDOC = 30;
      IF  NR = 0 THEN
        DELETE FROM TREZOR1 WHERE CODTREZOR1 = V_REC.CODTREZOR1;

        SELECT COUNT( *) INTO NR FROM TREZOR1 WHERE CODTREZOR = V_REC.CODTREZOR;
        IF  NR = 0 THEN
          DELETE FROM TREZOR WHERE CODTREZOR = V_REC.CODTREZOR;
        END IF;
      END IF;
    END LOOP;
  END LOOP;

  DELETE FROM TRANSEINI WHERE CODBANKCONT = RECID;

  PERFORM NotifyModif( 2, RecId, 'TRANSEINI');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transeini_sp_gotorecord</obj_name>
  <obj_hashval>1baee6177b2939fc4f210a77de4e5482</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transeini_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC      RECORD;
  V_RECOBLIG RECORD;
BEGIN
  --Florin 15.12.2020 - fixat #41623
  INSERT INTO TMP_TRANSEINI(CODBANKCONT, INFOCONT, CODMONEDA)
  SELECT I.CODBANKCONT, B.SIMBOL || '/' || BC.NRCONT || '/' || M.SIMBOL, M.CODMONEDA
  FROM TRANSEINI I, NBANKCONT BC, NBANK B, NMONEDE M
  WHERE I.CODBANKCONT = RECID AND  I.CODBANKCONT = BC.CODBANKCONT AND  B.CODBANK = BC.CODBANK AND  M.CODMONEDA = BC.CODMONEDA;

  FOR V_REC IN
  (
  SELECT T1.CODTREZOR1, T1.DOC, T1.NRDOC, T1.DATADOC, T1.OBS, T.SUBUNITATEA
  FROM TREZOR T, NBANKCONT BC, TREZOR1 T1
  WHERE T.TIPDOC = 30 AND  T.AN * 12 + T.LUNA &lt; TO_NUMBER((current_setting('PKG_GLOBALS.ANINITIAL', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_GLOBALS.LUNAINITIALA', true)),'999999999999999999')
   AND  T.CODBANCA = RECID AND  BC.CODBANKCONT = T.CODBANCA AND  BC.CREDIT = 1 AND  T1.CODTREZOR = T.CODTREZOR AND  T1.TIPTRANZ = 0 AND  T1.OBIECTTRANZ = 3
  )
  LOOP
    FOR V_RECOBLIG IN (SELECT G.CODGENERAL, G.CODDOC, G.MONEDA, G.CURS, O.CODOBLIGPIF, O.CODPART, O.ICONT, O.VALOARE
                       FROM GENERAL G, OBLIGPIF O
                       WHERE G.TIPDOC = 30 AND  G.CODDOC = V_REC.CODTREZOR1 AND  G.CODGENERAL = O.CODGENERAL
                      )
    LOOP
      INSERT INTO TMP_GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS)
      VALUES(V_RECOBLIG.CODGENERAL, 30, V_RECOBLIG.CODDOC, V_RECOBLIG.MONEDA, V_RECOBLIG.CURS);

      INSERT INTO TMP_OBLIGPIF(CODOBLIGPIF, CODGENERAL, INFOTRANSA, NRDOC, DATADOC, SUMAVALUTA, CURS, CODPART, ICONT, OBS)
      VALUES(V_RECOBLIG.CODOBLIGPIF, V_RECOBLIG.CODGENERAL, V_REC.DOC, V_REC.NRDOC, V_REC.DATADOC, V_RECOBLIG.VALOARE, V_RECOBLIG.CURS, V_RECOBLIG.CODPART, V_RECOBLIG.ICONT, V_REC.OBS);
    END LOOP;
  END LOOP;

  UPDATE TMP_OBLIGPIF O
  SET
  DENDOCLEGATURA = (SELECT BK.SIMBOL || ' - ' || BC.NRCONT FROM NBANK BK, NBANKCONT BC WHERE BC.CODBANKCONT = O.CODPART AND  BC.CODBANK = BK.CODBANK),
  SIMBOLCONT     = (SELECT PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT FROM PKG_PLANCONTURI_GETSIMBOLCONT(NULL, (SELECT PKG_CATEGCONST_GETVALCONSTBYCODE.WME_RESULT FROM PKG_CATEGCONST_GETVALCONSTBYCODE(NULL, O.ICONT, getANLUCRU(), getLUNALUCRU()))::numeric));

  DELETE FROM TMP_OBLIGPIF_INITIAL;
  INSERT INTO TMP_OBLIGPIF_INITIAL SELECT * FROM TMP_OBLIGPIF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transeini_sp_lockrecord</obj_name>
  <obj_hashval>68630d0de17da3435c800e404a6bcc92</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transeini_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMP numeric;
begin
  SELECT CODBANKCONT INTO TMP FROM TRANSEINI WHERE CODBANKCONT = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_adatatransport</obj_name>
  <obj_hashval>6aff181f9d033e414991d5cec6a22d76</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_adatatransport(INOUT wme_result timestamp without time zone, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_TRANSPORT.aDataTransport', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_aindicativ</obj_name>
  <obj_hashval>acb72de845b2df8a1efc4d5f7c427af6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_aindicativ(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_TRANSPORT.aINDICATIV', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_getadatatransport</obj_name>
  <obj_hashval>aa02500feab016597ea4b5cb7790ee9d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_getadatatransport(INOUT wme_result timestamp without time zone, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_TRANSPORT.aDataTransport', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_getaindicativ</obj_name>
  <obj_hashval>2f7de01f5fd70ace0bc781c217a6d918</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_getaindicativ(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_TRANSPORT.aINDICATIV', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_getdatatransportindicativ</obj_name>
  <obj_hashval>1b1888159c955ea4055544f51e21b7eb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_getdatatransportindicativ()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
V_REC RECORD;
begin
FOR v_rec IN ( SELECT DataTransport, Indicativ FROM Transport
               WHERE  CODTransport = ( SELECT * FROM ( SELECT CodTransport FROM transport ORDER BY  codtransport desc) A_PG limit 1 offset 0)
            )
LOOP
   perform set_config('PKG_TRANSPORT.aDataTransport', To_char(v_rec.DataTransport, 'dd.mm.yyyy'),false);
   perform set_config('PKG_TRANSPORT.aIndicativ',v_rec.indicativ,false);
END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_getmasafactintr</obj_name>
  <obj_hashval>178ccf22f725b18e2aa932c73750c116</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_getmasafactintr(INOUT wme_result numeric, INOUT acodintr numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aMasa double precision;
begin
  SELECT SUM( COALESCE( O.MASA, 0) * I1.CANT)
  INTO aMASA
  FROM Intrari1 I1, NARTOBJ O
  WHERE I1.CODIntr = aCodIntr AND  O.CODOBIECT = I1.CODOBIECT AND  I1.TIPLINIE = '=';

  WME_Result :=  aMasa;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_getstarerep</obj_name>
  <obj_hashval>73da5a4d0ae572f2d9a64ff54415fafd</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_getstarerep(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
WME_Result :=  TO_NUMBER((current_setting('PKG_TRANSPORT.vStareRepartizare', true)),'999999999999999999');
RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_getvalserv</obj_name>
  <obj_hashval>61d2b7cbc212e5eee1c2d0091180e153</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_getvalserv(INOUT wme_result numeric, INOUT acodintr numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  ArtTransDVI numeric;
  ArtAsigDVI  numeric;
  aVal        double precision;
begin
  ArtTransDVI := fnc_GetValConstantaLucru('ArtTransDVI');
  ArtAsigDVI  := fnc_GetValConstantaLucru('ArtAsigDVI');

  SELECT sum((I1.Cant * I1.PU)  * CASE WHEN COALESCE(i.curs, 0)=0 THEN 1 ELSE  i.curs END)
  INTO aVal
  FROM intrari1 i1 INNER JOIN intrari i ON  i1.codintr = i.codintr
  WHERE i1.codintr = aCodIntr and i1.codobiect IN (ArtTransDVI, ArtAsigDVI);

  WME_Result :=  aVal;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_getvarsuplim</obj_name>
  <obj_hashval>b60dc2e47b19f24da64d3c05a8ccc8f0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_getvarsuplim(INOUT astarerepartizare numeric, INOUT atiprepart numeric, INOUT avalsuplim numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
aStareRepartizare := TO_NUMBER((current_setting('PKG_TRANSPORT.vStareRepartizare', true)),'999999999999999999');
aTipRepart        := TO_NUMBER((current_setting('PKG_TRANSPORT.vTipRepartizare'  , true)),'999999999999999999');
aValSuplim        := TO_NUMBER((current_setting('PKG_TRANSPORT.vValSuplim'       , true)),'99999999999.9999999');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_getvolumfactintr</obj_name>
  <obj_hashval>7f17880ae28b998dfa6f7826192e766d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_getvolumfactintr(INOUT wme_result numeric, INOUT acodintr numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aVolum double precision;
begin
  SELECT SUM( COALESCE( O.VOLUM, 0) * I1.CANT)
  INTO aVOLUM
  FROM Intrari1 I1, NARTOBJ O
  WHERE I1.CODIntr = aCodIntr AND  O.CODOBIECT = I1.CODOBIECT AND  I1.TIPLINIE = '=';

  WME_Result :=  aVolum;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_getvstarerepartizare</obj_name>
  <obj_hashval>58e1f2099843ce4673ae4a7f26230e8b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_getvstarerepartizare(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_TRANSPORT.vStareRepartizare', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_getvtiprepartizare</obj_name>
  <obj_hashval>a0126741ec285712046dd8cd1601f9f9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_getvtiprepartizare(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_TRANSPORT.vTipRepartizare', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_setadatatransport</obj_name>
  <obj_hashval>d18d01a1f03214ce4496685de5863f67</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_setadatatransport(aadatatransport timestamp without time zone)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_TRANSPORT.aDataTransport',aaDataTransport,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_setstarerep</obj_name>
  <obj_hashval>0324a871ab1c014c6fe965179c614b94</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_setstarerep(astarerepartizare numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_TRANSPORT.vStareRepartizare',to_char(aStareRepartizare,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_setvalsuplimindvi</obj_name>
  <obj_hashval>4e34f2ceb3408d6ba43d6282c55f0ce9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_setvalsuplimindvi(acodintr numeric, atiprepart numeric, avalsuplim numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
begin
UPDATE dvi
SET
ValSuplim = aValSuplim,
TipRepSuplim = aTipRepart
WHERE
 DVi.Codintr = aCodIntr
;
--&lt;sstunknown&gt;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_setvarsuplim</obj_name>
  <obj_hashval>223e96710720fc28bf8d3121b6763b44</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_setvarsuplim(astarerepartizare numeric, atiprepart numeric, avalsuplim numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_TRANSPORT.vStareRepartizare',to_char(aStareRepartizare,'999999999999999999'),false);
perform set_config('PKG_TRANSPORT.vTipRepartizare',to_char(aTipRepart,'999999999999999999'),false);
perform set_config('PKG_TRANSPORT.vValSuplim',to_char(aValSuplim,'99999999999.9999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_setvstarerepartizare</obj_name>
  <obj_hashval>22e515f1c6ad34f225e682f52634eecc</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_setvstarerepartizare(avstarerepartizare numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_TRANSPORT.vStareRepartizare',to_char(avStareRepartizare,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_setvvalsuplim</obj_name>
  <obj_hashval>99e2fce0e58237a6fbd59be1ea62ee38</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_setvvalsuplim(avvalsuplim double precision)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_TRANSPORT.vValSuplim',to_char(avValSuplim,'99999999999.9999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_sp_deleterecord</obj_name>
  <obj_hashval>b8b2f1aead2072eae10cb6c0359bde37</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  vTip  numeric;
begin
  PERFORM PKG_TRANSPORT_SP_LOCKRECORD( RecId);

  SELECT tip INTO vtip FROM transport WHERE CodTransport = RecId;
  IF  vTip = 0 THEN
    FOR v_rec IN (SELECT T1.CodTransf1 CODDOC1
                  FROM TRANSPORT1 TR1
                      LEFT JOIN TRANSF  T  ON  TR1.CodDoc  = T.CodTransf
                      LEFT JOIN TRANSF1 T1 ON  T.CodTransf = T1.CodTransf
                  WHERE TR1.CODTRANSPORT = RecId and TR1.TipDoc IN (12, 13)
                 )
    LOOP
      UPDATE TRANSF1 SET CostTransport = 0 WHERE CodTransf1 = v_rec.CodDoc1;
    END LOOP;

    FOR v_rec IN (SELECT I1.CodIes1 CODDOC1
                  FROM TRANSPORT1 TR1
                      LEFT JOIN IESIRI  I  ON  TR1.CodDoc = I.CodIes
                      LEFT JOIN IESIRI1 I1 ON  I.CodIes   = I1.CodIes
                  WHERE TR1.CODTRANSPORT = RecId and TR1.TipDoc IN (12, 13)
                 )
    LOOP
      UPDATE IESIRI1 SET CostTransport = 0 WHERE CodIes1 = v_rec.CodDoc1;
    END LOOP;
  END IF;

  DELETE FROM TRANSPORT2 WHERE CodTransport = RecId;
  DELETE FROM TRANSPORT1 WHERE CodTransport = RecId;
  DELETE FROM TRANSPORT  WHERE CodTransport = RecId;

  PERFORM NotifyModif( 2, RecId, 'TRANSPORT');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_sp_insertrecord</obj_name>
  <obj_hashval>4b3822069d1bd5fc5c6e1de1e5138810</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 07.09.2022 - fixat 55474
  --Florin 27.07.2022 - sinc. Oracle
  PERFORM pkg_transport_GetDataTransportIndicativ();
  INSERT INTO  TMP_TRANSPORT( CodTransport, Rep_Transf, Rep_Subunit, TipLivrare/*, DataTransport, Indicativ */) VALUES (0, 0, 0, 3/*, aDataTransport, aIndicativ*/) ;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_sp_lockrecord</obj_name>
  <obj_hashval>790ca4b746dff665a129ee9eef107fd6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CodTransport INTO Tmp FROM TRANSPORT WHERE CodTransport = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_sp_postrecords</obj_name>
  <obj_hashval>02d8bb33c96e8743e281dba1a486c0b8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC      RECORD;
  vCod       numeric;
  vTip       numeric;
  vTipRepart numeric;
begin
  --Bogdan 04.12.2020
  SELECT tip       INTO vtip       FROM tmp_transport;
  SELECT tiprepart INTO vtiprepart FROM tmp_transport;

  IF Operation = 0 THEN
    SELECT CodTransport INTO RecId FROM TMP_TRANSPORT;

    UPDATE TRANSPORT
    SET
      (
        CodTransport, DataTransport, UserId, DataCreare,
        Subunitate, Indicativ, Operat, Blocat,
        Anulat, An, Luna, Valoare,
        TipRepart, CodParcAuto, CodSofer, Colete,
        Rep_Transf, Rep_Subunit, Tip
      )
      = (SELECT RecId, DataTransport, UserId, DataCreare,
          Subunitate, Indicativ, Operat, Blocat,
          Anulat, An, Luna, Valoare,
          TipRepart, CodParcAuto, CodSofer, Colete,
          Rep_Transf, Rep_Subunit, Tip
        FROM TMP_TRANSPORT)
    WHERE
      CodTransport = RecId;

    DELETE FROM TRANSPORT1 WHERE CodTransport = RecId and CodTransport1 NOT IN (SELECT CodTransport1 FROM TMP_TRANSPORT1);

    INSERT INTO TRANSPORT1 (CodTransport1, CodTransport, CodColet, CodDoc, TipDoc)
    (SELECT NEXTVAL ('SEQ_TRANSPORT1_CODTRANSPORT1') , RecId, CodColet, CodDoc, TipDoc FROM TMP_TRANSPORT1 WHERE COALESCE (CodTransport1, -1) &lt; 0);

    FOR v_rec IN (SELECT * FROM TMP_TRANSPORT1 WHERE COALESCE (CodTransport1, -1) &gt; 0 ORDER BY CodTransport1) LOOP
      UPDATE TRANSPORT1
      SET
      CodColet = v_rec.CodColet,
      CodDoc   = v_rec.CodDoc,
      TipDoc   = v_rec.TipDoc
      WHERE
        CodTransport1 = v_rec.CodTransport1;
    END LOOP;

    IF vTip = 0 THEN
      FOR v_rec IN (SELECT * FROM TMP_TRANSPORT2 WHERE TipDoc IN (12, 13)) LOOP
        UPDATE TRANSF1 SET CostTransport = v_rec.valoare WHERE CodTransf1 = v_rec.CodDoc1;
      END LOOP;

      FOR v_rec IN (SELECT * FROM TMP_TRANSPORT2 WHERE TipDoc NOT IN (12, 13)) LOOP
        UPDATE IESIRI1 SET CostTransport = v_rec.valoare WHERE CodIes1 = v_rec.CodDoc1;
      END LOOP;
    ELSE
      DELETE FROM transport2 WHERE codtransport = recid and codtransport2 NOT IN (SELECT codtransport2 FROM tmp_transport2);

      INSERT INTO transport2 (CODTRANSPORT2, CODTRANSPORT, CODDOC, TIPDOC)
      (SELECT NEXTVAL ('SEQ_TRANSPORT2_CODTRANSPORT2') , RecId, CodDoc, TipDoc FROM tmp_transport2 WHERE COALESCE (codtransport2, -1) &lt; 0);

      FOR v_rec IN (SELECT * FROM TMP_TRANSPORT2 WHERE COALESCE (CodTransport2, -1) &gt; 0 ORDER BY CodTransport2) LOOP
        UPDATE TRANSPORT2 SET CodDoc = v_rec.CodDoc, TipDoc = v_rec.TipDoc WHERE CodTransport2 = v_rec.CodTransport2;
      END LOOP;

      FOR v_rec IN (SELECT * FROM TMP_TRANSPORT2 ORDER BY CodDoc) LOOP
        UPDATE dvi
        SET
        ValSuplim    = v_rec.val,
        TipRepSuplim = vTiprepart
        WHERE
          DVi.Codintr = v_rec.coddoc;
      END LOOP;
    END IF;
  ELSE
    SELECT NEXTVAL ('SEQ_TRANSPORT_CODTRANSPORT') INTO RecId;

    INSERT INTO TRANSPORT (CodTransport, DataTransport, UserId, DataCreare, Subunitate, Indicativ, Operat, Blocat, Anulat, An, Luna, Valoare,
        TipRepart, CodParcAuto, CodSofer, Colete, Rep_Transf, Rep_Subunit, Tip)
    (SELECT RecId, DataTransport, UserId, DataCreare, Subunitate, Indicativ, Operat, Blocat, Anulat, An, Luna, Valoare, TipRepart, CodParcAuto,
          CodSofer, Colete, Rep_Transf, Rep_Subunit, Tip
      FROM TMP_TRANSPORT);

    INSERT INTO TRANSPORT1 (CodTransport1, CodTransport, CodColet, CodDoc, TipDoc)
    (SELECT NEXTVAL ('SEQ_TRANSPORT1_CODTRANSPORT1') , RecId, CodColet, CodDoc, TipDoc FROM TMP_TRANSPORT1);

    FOR v_rec IN (SELECT * FROM TMP_TRANSPORT2 WHERE TipDoc IN (12, 13)) LOOP
      UPDATE TRANSF1 SET CostTransport = v_rec.valoare WHERE CodTransf1 = v_rec.CodDoc1;
    END LOOP;

    FOR v_rec IN (SELECT * FROM TMP_TRANSPORT2 WHERE TipDoc NOT IN (12, 13)) LOOP
      UPDATE IESIRI1 SET CostTransport = v_rec.valoare WHERE CodIes1 = v_rec.CodDoc1;
    END LOOP;

    IF vTip &gt; 0 THEN
      INSERT INTO transport2 (codtransport2, codtransport, coddoc, tipdoc)
      (SELECT NEXTVAL ('SEQ_TRANSPORT2_CODTRANSPORT2') , RecId, coddoc, tipdoc FROM tmp_transport2);

      FOR v_rec IN (SELECT * FROM TMP_TRANSPORT2 ORDER BY CodDoc) LOOP
        UPDATE dvi
        SET
        ValSuplim    = v_rec.val,
        TipRepSuplim = vTiprepart
        WHERE
          DVi.Codintr = v_rec.coddoc;
      END LOOP;
    END IF;
  END IF;

  PERFORM NotifyModif (Operation, RecId, 'TRANSPORT');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_vstarerepartizare</obj_name>
  <obj_hashval>fd4c266c34017256dd7d3899117fa38a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_vstarerepartizare(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_TRANSPORT.vStareRepartizare', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_vtiprepartizare</obj_name>
  <obj_hashval>666b6e6348bc4aca81e37b155e88ee94</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_vtiprepartizare(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_TRANSPORT.vTipRepartizare', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_vvalsuplim</obj_name>
  <obj_hashval>5ea06470b38b90143db9f50f3df1918d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_vvalsuplim(INOUT wme_result double precision, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_TRANSPORT.vValSuplim', true)),'99999999999.9999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_clear_lock_comenzi</obj_name>
  <obj_hashval>226a1d1333ccac302e15081631436065</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_clear_lock_comenzi()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  UPDATE Comanda SET UserIDBlocaj = NULL WHERE UserIDBlocaj = TO_NUMBER((current_setting('PKG_GLOBALS.UserID', true)),'999999999999999999');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_cleartemps</obj_name>
  <obj_hashval>d8f0390d9eba000a41fbf47cd4e073b6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_cleartemps()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_TraseuLivr_Comenzi;
  DELETE FROM TMP_TraseuLivr_TotalArt;
  DELETE FROM TMP_TraseuLivr_ComenziClienti;
  DELETE FROM TMP_TraseuLivr_Incarcare;
  DELETE FROM TMP_TraseuLivr_ArtLivr;
  DELETE FROM TMP_TraseuLivr_Livrare;
  DELETE FROM tmp_traseulivr_allcmd;
  DELETE FROM tmp_traseulivr_allcmd_baza;
  DELETE FROM tmp_traseulivr_auto;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_frommanevra</obj_name>
  <obj_hashval>7c884bdeb4f944abf0bb58d0dc5bf34d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_frommanevra(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_TRASEULIVR.FromManevra', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_get_sysdate</obj_name>
  <obj_hashval>6d2c87eaa2d83b2be438cdf9a1667908</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_get_sysdate(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
WME_Result :=  to_char( CURRENT_TIMESTAMP, 'DD.MM.YYYY');
RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_get_tmp_articolelivrate</obj_name>
  <obj_hashval>ad7b21b4003568f8f116080c9549d80d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_get_tmp_articolelivrate()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_TraseuLivr_ArtLivr;
  INSERT INTO TMP_TraseuLivr_ArtLivr(CodTraseu, Delegat, Insotitor, MIJLOCTRANSP, CodObiect, CodArticol, CodUM, CantComandat, CantAcceptat, Masa, Volum, DenObiect)
  (
  SELECT CodTraseu, Delegat, Insotitor, CODMIJLTRANSP, CodObiect, CodArticol, CodUM, sum( CantComandat), sum( CantAcceptat), sum( Masa), sum( Volum), DenObiect
  FROM TMP_TraseuLivr_Comenzi
  WHERE TRANSPCLIENT &lt;&gt; 2
  GROUP BY CodTraseu, Delegat, Insotitor, CODMIJLTRANSP, CodObiect, CodArticol, CodUM, DenObiect
  );
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_get_tmp_comenziclienti</obj_name>
  <obj_hashval>018c3ed6adceb3fbd44e35830608f3fe</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_get_tmp_comenziclienti(peechiv boolean)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  lPeEchiv numeric;
begin
  lPeEchiv := 0;
  IF peEchiv THEN
    lPeEchiv := 1;
  END IF;

  DELETE FROM TMP_TraseuLivr_ComenziClienti;
  INSERT INTO TMP_TraseuLivr_ComenziClienti(CodClient, CodJudetClient, CodLocalitClient, NrComanda, DataComanda, CodUM, CantComandat, CantAcceptat, CantRezervat, CodObiect, ZecimaleUM, InregNula, CodComanda, CodComanda1, CodAgenda, FlagLucru, Den_Client, TipDoc)
  (
  SELECT CodClient, CodJudet, CodLocalit, NrDoc, DataDoc,
        (CASE WHEN  lPeEchiv = 1 THEN CodUMEchivGen ELSE CodUM END ) ,
        (CASE WHEN  lPeEchiv = 1 THEN sum( CantComandat * ParitateEchivGen) ELSE sum( CantComandat) END ) ,
        (CASE WHEN  lPeEchiv = 1 THEN sum( CantAcceptat * ParitateEchivGen) ELSE sum( CantAcceptat) END ) ,
        (CASE WHEN  lPeEchiv = 1 THEN sum( CantRezervat * ParitateEchivGen) ELSE sum( CantRezervat) END ) ,
        (CASE WHEN  lPeEchiv = 1 THEN CodObiectEchivGen ELSE CodObiect END ) ,
        (CASE WHEN  lPeEchiv = 1 THEN ZecimaleUMEchivGen ELSE ZecimaleUM END ) ,
        InregNula, CodComanda, CodComanda1, CodAgenda, FlagLucru, Den_Client, TipDoc
  FROM TMP_TraseuLivr_Comenzi
  GROUP BY CodClient, CodJudet, CodLocalit, NrDoc, DataDoc,
           (CASE WHEN  lPeEchiv = 1 THEN CodUMEchivGen ELSE CodUM END ) ,
           (CASE WHEN  lPeEchiv = 1 THEN CodObiectEchivGen ELSE CodObiect END ) ,
           (CASE WHEN  lPeEchiv = 1 THEN ZecimaleUMEchivGen ELSE ZecimaleUM END ) ,
           InregNula, CodComanda, CodComanda1, CodAgenda, FlagLucru, Den_Client, TipDoc
  );
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_get_tmp_detaliidistrib</obj_name>
  <obj_hashval>b55ab0ed7ac4718fcbfda2ff2e53acdf</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_get_tmp_detaliidistrib()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_TraseuLivr_Livrare;
  INSERT INTO TMP_TraseuLivr_Livrare(CodComanda, CodClient, CodJudetClient, CodLocalitClient, NrComanda, DataComanda, CodTraseu, Pozitie, Delegat, MIJLOCTRANSP, Insotitor, CodAgenda, Masa, Volum, Den_Client)
  (
  SELECT CodComanda, CodClient, CodJudet, CodLocalit, NrDoc, DataDoc, CodTraseu, PozTraseu, Delegat, CODMIJLTRANSP, Insotitor, CodAgenda, sum( Masa), sum( Volum), Den_Client
  FROM TMP_TraseuLivr_Comenzi
  WHERE TRANSPCLIENT &lt;&gt; 2
  GROUP BY CodComanda, CodClient, CodJudet, CodLocalit, NrDoc, DataDoc, CodTraseu, PozTraseu, Delegat, CODMIJLTRANSP, Insotitor, CodAgenda, Den_Client
  );
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_get_tmp_incarcare</obj_name>
  <obj_hashval>63eb8b08e6cfc7334b7e5eed15cc254c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_get_tmp_incarcare()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_TraseuLivr_Incarcare;

  INSERT INTO TMP_TraseuLivr_Incarcare (TmpIdx, CodTraseu, Delegat, Insotitor, MijlocTransp, DataSosirii, MasaUtila, VolumUtil, Masa, Volum, DifMasa, DifVolum)
  (select row_number() over(),a_pg.*
   from
      (SELECT CodTraseu, Delegat, Insotitor, CODMIJLTRANSP, DataSosirii, MasaU, VolumU, sum (Masa) , sum (Volum) , MasaU - sum (Masa) , VolumU - sum (Volum)
       FROM TMP_TraseuLivr_Comenzi
       WHERE TRANSPCLIENT &lt;&gt; 2
       GROUP BY CodTraseu, Delegat, Insotitor, CODMIJLTRANSP, DataSosirii, MasaU, VolumU
      ) a_pg
  );
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_get_tmp_infocomanda</obj_name>
  <obj_hashval>fb91348b97d58354d214ee7eb440c888</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_get_tmp_infocomanda(acodcomanda numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_TRASEULIVR_COMANDA;
  INSERT INTO TMP_TRASEULIVR_COMANDA(CodComanda, Partener, Den_Partener, Moneda, NrDoc, DataDoc, Obs)
  (
  SELECT C.CodComanda, C.Partener, NP.Den_Part, C.Moneda, C.NrDoc, C.DataDoc, C.Obs
  FROM Comanda C INNER JOIN NPART NP ON  NP.CodPart = C.Partener
  WHERE CodComanda = aCodComanda
  );

  DELETE FROM TMP_TRASEULIVR_COMANDA1;
  INSERT INTO TMP_TRASEULIVR_COMANDA1(CodComanda1, CodComanda, IndexLocal, CodObiect, CodArt, CodUM, CantComandat, CantAcceptat, PU, Valoare, Termen, AdDim, ProcDisc, Consum, CuLansare, Scadenta, Obs, D1, D2, D3, DenObiect)
  (
  SELECT C1.CodComanda1, C1.CodComanda, C1.IndexLocal, C1.CodObiect, NAO.CodArticol, NUM.CodUM, C1.CantComandat, TTLC.CantAcceptat, C1.PU, C1.PU * TTLC.CantAcceptat, C1.Termen, C1.AdDim, C1.ProcDisc, C1.Consum, C1.CuLansare, C1.Scadenta, C1.Obs, C1.D1, C1.D2, C1.D3, NAO.Denumire
  FROM Comanda1 C1
      INNER JOIN NArtObj                NAO  ON  NAO.CodObiect    = C1.CodObiect
      INNER JOIN NArt                   NA   ON  NA.CodArticol    = NAO.CodArticol
      INNER JOIN NUM                         ON  NUM.CodUM        = NA.UM
      INNER JOIN TMP_TraseuLivr_Comenzi TTLC ON  TTLC.CodComanda1 = C1.CodComanda1
  WHERE C1.CodComanda = aCodComanda
  );
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_get_tmp_totalart</obj_name>
  <obj_hashval>11dbe380eb8aa958e0e5df888b02e0d6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_get_tmp_totalart(peechiv boolean)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  lPeEchiv numeric;
BEGIN
  --Florin 22.08.2024 - sinc. Oracle
  lPeEchiv := 0;
  IF peEchiv THEN
    lPeEchiv := 1;
  END IF;

  DELETE FROM TMP_TraseuLivr_TotalArt;

  INSERT INTO TMP_TraseuLivr_TotalArt (CodUM, CantComandat, CantAcceptat, CantDisponibil, CantRezervat, CantComenzi, CodObiect, ZecimaleUM,
                                       InregNula, DenObiect, RestAcceptat, CodGrupa, ParitateGrupa, D1, D2, D3)
  (SELECT (CASE WHEN lPeEchiv = 1 THEN CodUMEchivGen ELSE CodUM END),
          (CASE WHEN lPeEchiv = 1 THEN sum (CantComandat * ParitateEchivGen) ELSE sum (CantComandat) END),
          (CASE WHEN lPeEchiv = 1 THEN sum (CASE WHEN InregNula = 0 THEN CantAcceptat * ParitateEchivGen
                                                 WHEN InregNula = 1 THEN 0
                                            END)
                ELSE sum (CASE WHEN InregNula = 0 THEN CantAcceptat
                               WHEN InregNula = 1 THEN 0
                          END)
           END),
          (CASE WHEN lPeEchiv = 1 THEN sum (CantDisponibil * ParitateEchivGen) ELSE sum (CantDisponibil) END),
          (CASE WHEN lPeEchiv = 1 THEN sum (CantRezervat * ParitateEchivGen)   ELSE sum (CantRezervat)   END),
          (CASE WHEN lPeEchiv = 1 THEN sum (CantComenzi * ParitateEchivGen)    ELSE sum (CantComenzi)    END),
          (CASE WHEN lPeEchiv = 1 THEN CodObiectEchivGen  ELSE CodObiect  END),
          (CASE WHEN lPeEchiv = 1 THEN ZecimaleUMEchivGen ELSE ZecimaleUM END),
          0,
          (CASE WHEN lPeEchiv = 1 THEN DenObiectEchivGen ELSE DenObiect END),
          0, CodGrupa, ParitateGrupa, COALESCE(D1, 0), COALESCE(D2, 0), COALESCE(D3, 0)
      FROM TMP_TraseuLivr_Comenzi
      GROUP BY
        (CASE WHEN lPeEchiv = 1 THEN CodUMEchivGen      ELSE CodUM      END),
        (CASE WHEN lPeEchiv = 1 THEN CodObiectEchivGen  ELSE CodObiect  END),
        (CASE WHEN lPeEchiv = 1 THEN ZecimaleUMEchivGen ELSE ZecimaleUM END),
        (CASE WHEN lPeEchiv = 1 THEN DenObiectEchivGen  ELSE DenObiect  END),
        CodGrupa, ParitateGrupa, COALESCE(D1, 0), COALESCE(D2, 0), COALESCE(D3, 0));

end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_get_tmp_traseuart</obj_name>
  <obj_hashval>760c1f11483afe813c00240d9da7c0bc</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_get_tmp_traseuart(acodtraseu numeric, acodobiect numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_TraseuLivr_TraseuArtInfo;
  INSERT INTO TMP_TraseuLivr_TraseuArtInfo(CodTraseu, DenTraseu, SimbolTraseu, CodObiect)
  (SELECT CodTraseuLivr, DenTraseu, SimbolTraseu, aCodObiect FROM TraseuLivr WHERE CodTraseuLivr = aCodTraseu);

  UPDATE TMP_TraseuLivr_TraseuArtInfo
  SET
  (CodArticol, DenArticol) = (SELECT NAO.CodArticol, NA.Den_Articol
                              FROM NArtObj NAO INNER JOIN NArt NA ON  NA.CodArticol = NAO.CodArticol
                              WHERE NAO.CodObiect = aCodObiect
                             );

  DELETE FROM TMP_TraseuLivr_TraseuArt;
  INSERT INTO TMP_TraseuLivr_TraseuArt(CodClient, NrComanda, DataComanda, CodUM, CantComandat, CantAcceptat, CantRezervat, Masa, Volum, CodObiect, CodComanda1, CodComanda, MasaUM, VolumUM, InregNula)
  (
  SELECT CodClient, NrDoc, DataDoc, CodUM, CantComandat, CantAcceptat, CantRezervat, Masa, Volum, CodObiect, CodComanda1, CodComanda, MasaO, VOlumO, InregNula
  FROM TMP_TraseuLivr_Comenzi
  WHERE CodTraseu = aCodTraseu and  CodObiect = aCodObiect
  );
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_getfrommanevra</obj_name>
  <obj_hashval>8452fbf16faed38ba7ef99996e55e16c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_getfrommanevra(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_TRASEULIVR.FromManevra', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_lock_comenzi</obj_name>
  <obj_hashval>5843634d48be1da6a8eb7ffa6ee1f6cc</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_lock_comenzi(INOUT wme_result character varying, INOUT adatestart character varying, INOUT adateend character varying, INOUT asubunit numeric, INOUT acc boolean, INOUT acs boolean, INOUT acg boolean, INOUT afrommanevra numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  lOraDateStart date;
  lOraDateEnd   date;
  tmp_recid     numeric;
  lOraError     varchar;
begin
  perform set_config ('PKG_TRASEULIVR.FromManevra',aFromManevra::varchar,false);
  lOraDateStart := to_date (aDateStart, 'DD.MM.YYYY');
  lOraDateEnd   := to_date (aDateEnd, 'DD.MM.YYYY');
  lOraError     := '';
  IF aCC THEN
    FOR v_rec IN (SELECT  DISTINCT C.CodComanda, C.NrDoc, COALESCE (C.UserIDBlocaj, 0) AS USERIDBLOCAJ
      FROM Comanda C INNER JOIN Comanda1 C1 ON C1.CodComanda = C.CodComanda
      WHERE
        C.Inchisa = 0
        and C1.Termen BETWEEN lOraDateStart AND lOraDateEnd
        and C.Subunitatea = aSubunit
        and C1.CantAcceptat = C1.RestAcceptat
        and C.TipDoc = 18
        and C1.CantComandat &gt; 0
        and ( (current_setting ('PKG_TRASEULIVR.FromManevra', true) ::numeric = 0)
               or EXISTS (SELECT t.codunic FROM tmp_manevra t WHERE t.codunic = c.codcomanda))
        and coalesce (C.faratransport, 0) = 0)
    LOOP
      BEGIN
        SELECT CodComanda INTO tmp_recid FROM Comanda WHERE CodComanda = v_rec.CodComanda FOR UPDATE NOWAIT;
        IF v_rec.UserIDBlocaj &lt;&gt; 0 and v_rec.UserIDBlocaj &lt;&gt; current_setting ('PKG_GLOBALS.UserID', true) ::numeric THEN
          raise exception using
                    errcode='CMBLK';
        END IF;

        UPDATE Comanda
        SET UserIDBlocaj = current_setting ('PKG_GLOBALS.UserID', true) ::numeric
        WHERE
          CodComanda = v_rec.CodComanda;
      EXCEPTION
      WHEN sqlstate 'CMBLK' then
        lOraError := coalesce (lOraError,'') || coalesce ( (v_rec.NrDoc) ::varchar ,'') || ', ';
      END;
    END LOOP;
  END IF;

  IF aCS THEN
    FOR v_rec IN (SELECT  DISTINCT C.CodComanda, C.NrDoc, COALESCE (C.UserIDBlocaj, 0) AS USERIDBLOCAJ
      FROM Comanda C INNER JOIN Comanda1 C1 ON C1.CodComanda = C.CodComanda
      WHERE
        C.Inchisa = 0
        and C1.Termen BETWEEN lOraDateStart AND lOraDateEnd
        and C.SubunitSursa = aSubunit
        and C1.CantAcceptat = C1.RestAcceptat
        and C.TipDoc = 44
        and C1.CantComandat &gt; 0
        and ( (current_setting ('PKG_TRASEULIVR.FromManevra', true) ::numeric = 0)
               or EXISTS (SELECT t.codunic FROM tmp_manevra t WHERE t.codunic = c.codcomanda))
        and coalesce (C.faratransport, 0) = 0)
    LOOP
      BEGIN
        SELECT CodComanda INTO tmp_recid FROM Comanda WHERE CodComanda = v_rec.CodComanda FOR UPDATE NOWAIT;

        IF v_rec.UserIDBlocaj &lt;&gt; 0 and v_rec.UserIDBlocaj &lt;&gt; current_setting ('PKG_GLOBALS.UserID', true) ::numeric THEN
          raise exception using
                    errcode='CMBLK';
        END IF;

        UPDATE Comanda
        SET UserIDBlocaj = current_setting ('PKG_GLOBALS.UserID', true) ::numeric
        WHERE
          CodComanda = v_rec.CodComanda;
      EXCEPTION
      WHEN sqlstate 'CMBLK' then
        lOraError := coalesce (lOraError,'') || coalesce ( (v_rec.NrDoc) ::varchar::varchar ,'') || ', ';
      END;
    END LOOP;
  END IF;

  IF aCG THEN
    FOR v_rec IN (SELECT  DISTINCT C.CodComanda, C.NrDoc, COALESCE (C.UserIDBlocaj, 0) AS USERIDBLOCAJ
      FROM Comanda C INNER JOIN Comanda1 C1 ON C1.CodComanda = C.CodComanda
      WHERE
        C.Inchisa = 0
        and C1.Termen BETWEEN lOraDateStart AND lOraDateEnd
        and C.Subunitatea = aSubunit
        and C1.CantAcceptat = C1.RestAcceptat
        and C.TipDoc = 43
        and C1.CantComandat &gt; 0
        and ( (current_setting ('PKG_TRASEULIVR.FromManevra', true) ::numeric = 0)
               or EXISTS (SELECT t.codunic FROM tmp_manevra t WHERE t.codunic = c.codcomanda))
        and coalesce (C.faratransport, 0) = 0)
    LOOP
      BEGIN
        SELECT CodComanda INTO tmp_recid FROM Comanda WHERE CodComanda = v_rec.CodComanda FOR UPDATE NOWAIT;

        IF v_rec.UserIDBlocaj &lt;&gt; 0 and v_rec.UserIDBlocaj &lt;&gt; current_setting ('PKG_GLOBALS.UserID', true) ::numeric THEN
          raise exception using
                    errcode='CMBLK';
        END IF;

        UPDATE Comanda
        SET UserIDBlocaj = current_setting ('PKG_GLOBALS.UserID', true) ::numeric
        WHERE
          CodComanda = v_rec.CodComanda;
      EXCEPTION
      WHEN sqlstate 'CMBLK' then lOraError := coalesce (lOraError,'') || coalesce ( (v_rec.NrDoc) ::varchar::varchar ,'') || ', ';
      END;
    END LOOP;
  END IF;

  WME_Result := lOraError;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_set_acceptat</obj_name>
  <obj_hashval>f195004725e468f5c3d5de16926bccbb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_set_acceptat()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  FOR v_rec IN (SELECT CodComanda1, CantAcceptat FROM TMP_TraseuLivr_TraseuArt) LOOP
    UPDATE TMP_TraseuLivr_Comenzi
    SET
    CantAcceptat = v_rec.CantAcceptat,
    Masa         = v_rec.CantAcceptat * MasaO,
    Volum        = v_rec.CantAcceptat * VolumO
    WHERE
     CodComanda1 = v_rec.CodComanda1;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_sp_deleterecord</obj_name>
  <obj_hashval>0d2b93cdcc2eca6fd4eaee9fd1048acc</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_TRASEULIVR_SP_LOCKRECORD( RecId);

  UPDATE NAgenda
  SET
  CodTraseu = 0,
  PozTraseu = null
  WHERE CodTraseu = RecId;

  UPDATE NAgenda
  SET
  CodTraseu1 = 0,
  PozTraseu1 = null
  WHERE CodTraseu1 = RecId;

  DELETE FROM TraseuLivr WHERE CodTraseuLivr = RecId;

  PERFORM NotifyModif( 2, RecId, 'TraseuLivr');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_sp_postrecords</obj_name>
  <obj_hashval>5e748a48b34a1fdc9d89e68ebe0ac451</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  aTipTraseu numeric;
  xTipTraseu numeric;
begin
  --Bogdan 05.11.2020
  SELECT COALESCE (Tip, 0) INTO aTipTraseu FROM TMP_TraseuLivr;

  IF Operation = 0 THEN
    SELECT CodTraseuLivr     INTO RecId      FROM TMP_TraseuLivr;
    SELECT COALESCE (Tip, 0) INTO xTipTraseu FROM TraseuLivr WHERE CodTraseuLivr = RecID;

    UPDATE TraseuLivr
    SET
      (
        DenTraseu,
        SimbolTraseu,
        CodLocalit,
        Opriri,
        Ore,
        Minute,
        Tip,
        Lat,
        Lng
      )
      = (   SELECT DenTraseu,
          SimbolTraseu,
          CodLocalit,
          Opriri,
          Ore,
          Minute,
          Tip,
          Lat,
          Lng
        FROM TMP_TraseuLivr)
    WHERE
      CodTraseuLivr = RecId;

    IF aTipTraseu = 0 THEN
      IF xTipTraseu = 0 THEN
        FOR v_rec IN (SELECT CODAGENDA
                      FROM NAGENDA
                      WHERE CodTraseu = RecID and CodAgenda IN (SELECT CodAgenda FROM TMP_NAGENDA_TRASEU WHERE CodAgenda &lt;&gt; 0)
                     )
        LOOP
          UPDATE NAgenda
          SET
            CodTraseu = 0,
            PozTraseu = null
          WHERE
            CodAgenda = v_rec.CodAgenda;
        END LOOP;
      ELSE
        UPDATE NAgenda
        SET
          CodTraseu1 = 0,
          PozTraseu1 = null
        WHERE
          CodTraseu1 = RecID;
      END IF;

      FOR v_rec IN (SELECT CODAGENDA, PozTraseu, Lat, Lng FROM TMP_NAGENDA_TRASEU WHERE CodAgenda &lt;&gt; 0) LOOP
        UPDATE NAGENDA A
        SET
          Latitudine  = v_rec.Lat::varchar,
          Longitudine = v_rec.Lng::varchar,
          POZTRASEU   = v_rec.PozTraseu,
          CODTRASEU   = RecID
        WHERE
          CODAGENDA = v_rec.CodAgenda;
      END LOOP;
    ELSE
      IF xTipTraseu = 1 THEN
        FOR v_rec IN (SELECT CODAGENDA
                      FROM NAGENDA
                      WHERE CodTraseu1 = RecID and CodAgenda IN (SELECT CodAgenda FROM TMP_NAGENDA_TRASEU WHERE CodAgenda &lt;&gt; 0)
                     )
        LOOP
          UPDATE NAgenda
          SET
            CodTraseu1 = 0,
            PozTraseu1 = null
          WHERE
            CodAgenda = v_rec.CodAgenda;
        END LOOP;
      ELSE
        UPDATE NAgenda
        SET
          CodTraseu = 0,
          PozTraseu = null
        WHERE
          CodTraseu = RecID;
      END IF;

      FOR v_rec IN (SELECT CODAGENDA, PozTraseu, Lat, Lng FROM TMP_NAGENDA_TRASEU WHERE CodAgenda &lt;&gt; 0) LOOP
        UPDATE NAGENDA A
        SET
          Latitudine  = v_rec.Lat::varchar,
          Longitudine = v_rec.Lng::varchar,
          POZTRASEU1  = v_rec.PozTraseu,
          CODTRASEU1  = RecID
        WHERE
          CODAGENDA = v_rec.CodAgenda;
      END LOOP;
    END IF;
  ELSE
    SELECT NEXTVAL ('SEQ_TRASEULIVR_CODTRASEULIVR') INTO RecId;

    INSERT INTO TraseuLivr (CodTraseuLivr,
        DenTraseu,
        SimbolTraseu,
        Opriri,
        Ore,
        Minute,
        Tip,
        Lat,
        Lng)
    (SELECT RecId,
          DenTraseu,
          SimbolTraseu,
          Opriri,
          Ore,
          Minute,
          Tip,
          Lat,
          Lng
        FROM TMP_TraseuLivr);

    FOR v_rec IN (SELECT CODAGENDA, POZTRASEU, CODTRASEULIVR, Lat, Lng FROM TMP_NAGENDA_TRASEU WHERE CodAgenda &lt;&gt; 0) LOOP
      IF aTipTraseu = 0 THEN
        UPDATE NAGENDA A
        SET
          Latitudine  = v_rec.Lat::varchar,
          Longitudine = v_rec.Lng::varchar,
          POZTRASEU   = v_rec.PozTraseu,
          CODTRASEU   = RecID
        WHERE
          CODAGENDA = v_rec.CodAgenda;
      ELSE
        UPDATE NAGENDA A
        SET
          Latitudine  = v_rec.Lat::varchar,
          Longitudine = v_rec.Lng::varchar,
          POZTRASEU1  = v_rec.PozTraseu,
          CODTRASEU1  = RecID
        WHERE
          CODAGENDA = v_rec.CodAgenda;
      END IF;
    END LOOP;
  END IF;

  PERFORM NotifyModif (Operation, RecId, 'TraseuLivr');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_upd_comenziclienti</obj_name>
  <obj_hashval>f4543972c38cdcf464eda4f7fa3e7ab3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_upd_comenziclienti(adateinc character varying, acheckflaglucru numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC       RECORD;
  lOraDateInc date;
  lVal        double precision;
  lDisc       double precision;
  lOldVal     double precision;
  lOldDisc    double precision;
begin
  lOraDateInc := to_date( aDateInc, 'DD.MM.YYYY');

  FOR v_rec IN
  (
    SELECT CodComanda, CodComanda1, CantAcceptat, CodTraseu, PozTraseu, CodMijlTransp, Delegat, Insotitor, DataSosirii, InregNula
    FROM TMP_TraseuLivr_Comenzi
    WHERE (aCheckFlagLucru = 0)  or (FlagLucru = 1)
  )
  LOOP
    SELECT COALESCE( CantAcceptat, 0) * COALESCE( PU, 0),
           -(COALESCE( CantAcceptat, 0) * COALESCE( PU, 0) - COALESCE( CantAcceptat, 0) * COALESCE( PU, 0) * COALESCE( CoefDiscMaj, 1)) ,
           COALESCE( v_rec.CantAcceptat, 0) * COALESCE( PU, 0),
           -(  COALESCE( v_rec.CantAcceptat, 0) * COALESCE( PU, 0) - COALESCE( v_rec.CantAcceptat, 0) * COALESCE( PU, 0) * COALESCE( CoefDiscMaj, 1))
    INTO lOldVal, lOldDisc, lVal, lDisc
    FROM Comanda1
    WHERE CodComanda1 = v_rec.CodComanda1;

    UPDATE Comanda1
    SET
    DataIncarcarii = lOraDateInc,
    CantAcceptat   = v_rec.CantAcceptat,
    RestAcceptat   = v_rec.CantAcceptat
    WHERE
     CodComanda1 = v_rec.CodComanda1;

    UPDATE Comanda
    SET
    CodTraseuLivr = v_rec.CodTraseu,
    OrdineLivrare = v_rec.PozTraseu,
    MijlTransp    = v_rec.CodMijlTransp,
    Insotitor     = v_rec.Insotitor,
    Delegat       = v_rec.Delegat,
    Valoare       = COALESCE(Valoare, 0) - (lOldVal + lOldDisc)  + (lVal + lDisc) ,
    ValDiscount   = COALESCE(ValDiscount, 0) - lOldDisc + lDisc
    WHERE
     CodComanda = v_rec.CodComanda;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_upd_traseeclienti</obj_name>
  <obj_hashval>97771e3884751a9a967bb1085d614a50</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_upd_traseeclienti()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  FOR v_rec IN (SELECT CodTraseu, PozTraseu, CodAgenda FROM TMP_TraseuLivr_Comenzi) LOOP
    UPDATE NAgenda
    SET
    CodTraseu = v_rec.CodTraseu,
    PozTraseu = v_rec.PozTraseu
    WHERE
     CodAgenda = v_rec.CodAgenda;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_codcontcec</obj_name>
  <obj_hashval>43e420939a1f5709e2b033f64f60d695</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_codcontcec(INOUT wme_result numeric, INOUT acodnbankcont numeric, INOUT asemnificatie numeric, INOUT atipdecont numeric, INOUT aobiecttranz numeric, INOUT pan numeric DEFAULT NULL::numeric, INOUT pluna numeric DEFAULT NULL::numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCODCONTCEC     numeric;
  FROMIOBANK      numeric := 0;
  aCODIOBANK      numeric := 0;
  aCODIOBANK1     numeric := 0;
  aCODNBANKCONT1  numeric := 0;
  aTIPTRANZINCURS varchar := '?';
  aSIMBCONST      varchar := '?';
  acontPCEC       numeric := 0;
  acontPEFECTE    numeric := 0;
  acontPEFECTEREM numeric := 0;
  acontICEC       numeric := 0;
  acontIEFECTE    numeric := 0;
  acontIEFECTEREM numeric := 0;
  aAn             numeric := COALESCE(pAn, current_setting('PKG_GLOBALS.AnLUCRU', true)::numeric);
  aLuna           numeric := COALESCE(pLuna, current_setting('PKG_GLOBALS.LunaLUCRU', true)::numeric);
BEGIN
    --Bogdan 55047 : PG - Tranzactii curente banca - afisare cont plata cec aTIPDECONT = 3
  IF  ASEMNIFICATIE = 500 OR (aSEMNIFICATIE = 600 AND  aOBIECTTRANZ = 1) THEN
      IF  aTIPDECONT = 1 THEN aSIMBCONST := 'CPLATICEC';
      ELSIF aTIPDECONT = 2 THEN aSIMBCONST := 'CEFECTEPLATA';
      ELSIF aTIPDECONT = 3 THEN aSIMBCONST := 'CEFECTEREMISEPLATA';
      END IF;
  ELSE
      IF  aTIPDECONT = 1 THEN aSIMBCONST := 'CINCASARICEC';
      ELSIF aTIPDECONT = 2 THEN aSIMBCONST := 'CEFECTEINCASAT';
      ELSIF aTIPDECONT = 3 THEN aSIMBCONST := 'CEFECTEREMISEINCASAT';
      END IF;
  END IF;

  aCODCONTCEC     := fnc_GETVALCONSTANTA(aSIMBCONST, aAn, aLuna)::numeric;
  aTIPTRANZINCURS := COALESCE(fnc_GetValConstanta('TIPTRANZINCURS', aAn, aLuna), '?');

  IF  aTIPTRANZINCURS = '2' THEN
    aCODNBANKCONT1 := (SELECT PKG_CONTURIBANCI_GET_COD_NBANKCONT1.WME_RESULT FROM PKG_CONTURIBANCI_GET_COD_NBANKCONT1(NULL,aCODNBANKCONT, aAn, aLuna));
    IF  aCODNBANKCONT1 &gt; 0 THEN
      BEGIN
        SELECT CODIOBANCA
        INTO aCODIOBANK
        FROM NBANKCONT1
        WHERE CODBANKCONT1 = aCODNBANKCONT1;
      EXCEPTION WHEN OTHERS THEN
        aCODIOBANK := 0;
      END;

      IF  aCODIOBANK &gt; 0 THEN
        aCODIOBANK1 := (SELECT PKG_CONFIGBANK_GETCODCARACTLUNA.WME_RESULT FROM PKG_CONFIGBANK_GETCODCARACTLUNA(NULL,aCODIoBank, aAn, aLuna));
      END IF;
    END IF;
  END IF;

  IF  aTIPTRANZINCURS = '2' AND  aCODIOBANK1 &gt; 0 THEN
    FROMIOBANK := 1;
  END IF;

  IF  FROMIOBANK = 1 THEN
    BEGIN
      SELECT COALESCE(PCEC, 0), COALESCE(PEFECTE, 0), COALESCE(PEFECTEREM, 0), COALESCE(ICEC, 0), COALESCE(IEFECTE, 0), COALESCE(IEFECTEREM, 0)
      INTO acontPCEC, acontPEFECTE, acontPEFECTEREM, acontICEC, acontIEFECTE, acontIEFECTEREM
      FROM IOBANK1
      WHERE CODIOBANK1 = aCODIOBANK1;
    EXCEPTION WHEN OTHERS THEN
      acontPCEC       := 0;
      acontPEFECTE    := 0;
      acontIEFECTEREM := 0;
      acontICEC       := 0;
      acontIEFECTE    := 0;
      acontIEFECTEREM := 0;
    END;

    IF  ASEMNIFICATIE = 500 THEN
      IF  aTIPDECONT = 1 AND  acontPCEC &lt;&gt; 0 THEN
        aCODCONTCEC := acontPCEC;
      ELSIF aTIPDECONT = 2 AND  acontPEFECTE &lt;&gt; 0 THEN
        aCODCONTCEC := acontPEFECTE;
      END IF;
    ELSE
      IF  aTIPDECONT = 1 AND  acontICEC &lt;&gt; 0 THEN
        aCODCONTCEC := acontICEC;
      ELSIF aTIPDECONT = 2 AND  acontIEFECTE &lt;&gt; 0 THEN
        aCODCONTCEC := acontIEFECTE;
      END IF;
    END IF;
  END IF;

  WME_Result :=  COALESCE(aCODCONTCEC, 0);
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_ct_monitor</obj_name>
  <obj_hashval>384e9e1b80d50684d5d40404e44e0ef2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_ct_monitor(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := current_setting('PKG_TREZOR.CT_MONITOR', true);
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 'MON_16';
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_cumuleaza_extrase</obj_name>
  <obj_hashval>f89d6a8ef7a7f90c6aa0b855da7a5e7e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_cumuleaza_extrase(acodmaster numeric, atipdoc numeric, acodbanca numeric, adatadoc character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aIndexLocal NUMERIC;
  nr          NUMERIC;
  v_rec       record;
  v_rec1      record;
begin
  select count(*) into nr from trezor where codtrezor = aCodMaster;
  if nr = 1 then
    select nvl(max(IndexLocal), 0) into aIndexLocal from Trezor1 where codtrezor = aCodMaster;
    for v_rec in (SELECT * FROM TREZOR
                  WHERE
                    CODTREZOR   &lt;&gt; aCODMASTER
                    and TIPDOC   = aTipDoc
                    and CodBanca = aCodBanca
                    and DataDoc  = to_date(aDataDoc, 'dd.mm.yyyy')
                 )
    loop
      for v_rec1 in (SELECT * FROM TREZOR1 WHERE CODTREZOR = V_REC.CODTREZOR ORDER BY INDEXLOCAL)
      loop
        aIndexLocal := aIndexLocal + 1;
        update trezor1
        set
          codtrezor = aCodMaster,
          IndexLocal = aIndexLocal
        where
          codTrezor1 = v_rec1.codtrezor1;
      end loop;

      delete from trezor  where codtrezor = v_rec.codtrezor;
      delete from jurnal  where Coddoc  = v_rec.codtrezor and tipdoc = aTipDoc;
      delete from jurnal1 where Coddoc  = v_rec.codtrezor and tipdoc = aTipDoc;
      update jurnal1 set Dirty = 1
      where
        TipDoc = aTipDoc
        and CodDoc = aCodMaster;
    end loop;
  end if;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_cumuleaza_extrase</obj_name>
  <obj_hashval>94834d2224e773303b45794ccb743fee</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_cumuleaza_extrase(acodmaster numeric, atipdoc numeric, acodbanca numeric, acodsubunit numeric, adatadoc character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aIndexLocal NUMERIC;
  nr          NUMERIC;
  v_rec       record;
  v_rec1      record;
BEGIN
  --Florin 03.03.2025
  select count(*) into nr from trezor where codtrezor = aCodMaster;
  if nr = 1 then
    select nvl(max(IndexLocal), 0) into aIndexLocal from Trezor1 where codtrezor = aCodMaster;
    for v_rec in (SELECT * FROM TREZOR
                  WHERE
                    CODTREZOR   &lt;&gt; aCODMASTER
                    and TIPDOC   = aTipDoc
                    and SUBUNITATEA   = aCodSubunit
                    and CodBanca = aCodBanca
                    and DataDoc  = to_date(aDataDoc, 'dd.mm.yyyy')
                 )
    loop
      for v_rec1 in (SELECT * FROM TREZOR1 WHERE CODTREZOR = V_REC.CODTREZOR ORDER BY INDEXLOCAL)
      loop
        aIndexLocal := aIndexLocal + 1;
        update trezor1
        set
          codtrezor = aCodMaster,
          IndexLocal = aIndexLocal
        where
          codTrezor1 = v_rec1.codtrezor1;
      end loop;

      update documente
      SET
        coddoc = aCodMaster
      WHERE
        coddoc = v_rec.codtrezor
        and tipdoc = aTipDoc;

      update expert
      SET
        coddoc = aCodMaster
      WHERE
        coddoc = v_rec.codtrezor
        and tipdoc = aTipDoc;

      delete from trezor  where codtrezor = v_rec.codtrezor;
      delete from jurnal  where Coddoc  = v_rec.codtrezor and tipdoc = aTipDoc;
      delete from jurnal1 where Coddoc  = v_rec.codtrezor and tipdoc = aTipDoc;
      update jurnal1 set Dirty = 1
      where
        TipDoc = aTipDoc
        and CodDoc = aCodMaster;
    end loop;
  end if;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_existadocumentul</obj_name>
  <obj_hashval>cff463c90c88118d16040e4ef442fb6a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_existadocumentul(INOUT wme_result numeric, INOUT coddoc numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  NR numeric := 0;
begin
  BEGIN
    SELECT COUNT( *) INTO NR FROM TREZOR WHERE CODTREZOR = CODDOC;
  EXCEPTION WHEN OTHERS THEN
    NR := 0;
  END;

  WME_Result :=  NR;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_getcarnetdoc_i</obj_name>
  <obj_hashval>a2644c4ca3769549905c58470b3228f8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_getcarnetdoc_i(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER(current_setting('PKG_TREZOR.CARNETDOC_I', true),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_getdenpartdiectpecont</obj_name>
  <obj_hashval>5b402d3c0d89b3a5586f4328771897f2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_getdenpartdiectpecont(INOUT wme_result character varying, INOUT acodpart numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aDENPART varchar;
begin
  IF  aCODPART = 0 THEN
    WME_Result :=  '';
    RETURN;
  ELSE
    BEGIN
      SELECT DEN_PART INTO aDENPART FROM NPART WHERE CODPART = aCODPART;
    EXCEPTION WHEN OTHERS THEN
      aDENPART := '';
    END;

    WME_Result :=  '(' || aDENPART || ')';
    RETURN;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_getgestevidenta</obj_name>
  <obj_hashval>231da91dec8ee47af9fde3b294ba891e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_getgestevidenta(INOUT wme_result character varying, INOUT agest numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aDENGEST varchar := '';
begin
  WME_Result :=  '(' || aDENGEST || ')';
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_getnrdoc_i</obj_name>
  <obj_hashval>792eb289efce50d4177a92622c430aa4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_getnrdoc_i(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER(current_setting('PKG_TREZOR.NRDOC_I', true),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_notifymodifsoldfact</obj_name>
  <obj_hashval>d8df353d58e1d3f5a7180ccf461e6793</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_notifymodifsoldfact()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  v_rec record;
BEGIN
  --Florin 22.11.2023
  FOR V_REC IN
  (
      SELECT
        stinse_out.coddoc,
        stinse_out.tipdoc,
        stinse_out.valoare,
        nvl(stinse_ini.valoare, 0) as valoare_in
      FROM
      (
      select
        g.coddoc,
        g.tipdoc,
        sum(s.valoare) as valoare
      from
        tmp_stingere s
        inner join obligpif o on o.codobligpif = s.codstinspif and o.semnificatie = 200
        inner join general g on g.codgeneral = o.codgeneral
      group by g.coddoc, g.tipdoc
      ) stinse_out
       left join
      (
      select
        g.coddoc,
        g.tipdoc,
        sum(s.valoare) as valoare
      from
        tmp_stingere_initial s
        inner join obligpif o on o.codobligpif = s.codstinspif and o.semnificatie = 200
        inner join general g on g.codgeneral = o.codgeneral
      group by g.coddoc, g.tipdoc
      ) stinse_ini on stinse_ini.coddoc = stinse_out.coddoc and stinse_ini.tipdoc = stinse_out.tipdoc
    where
      nvl(stinse_ini.valoare, 0) &lt;&gt; nvl(stinse_out.valoare, 0)
  )
  LOOP
    PERFORM NotifyModif(11, v_rec.coddoc, 'IESIRI');
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_nrdoc_i</obj_name>
  <obj_hashval>0709160d0f0fd8b5ef004964796813a8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_nrdoc_i(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER(current_setting('PKG_TREZOR.NRDOC_I', true),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_obligatie_stinsa</obj_name>
  <obj_hashval>b9e478725768cc59694807b997d08367</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_obligatie_stinsa(INOUT wme_result numeric, INOUT acodobligpif numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  NR numeric := 0;
begin
  SELECT COALESCE( COUNT( *), 0) INTO NR FROM STINGERE WHERE CODSTINSPIF = aCODOBLIGPIF AND  VALOARE &lt;&gt; 0;
  IF  NR = 0 THEN
    SELECT COALESCE( COUNT( *), 0) INTO NR FROM NSERTAR1 WHERE CODOBLIGPIF = aCODOBLIGPIF;
  END IF;

  IF  NR = 0 THEN
    SELECT COALESCE( COUNT( *), 0) INTO NR FROM PLATI1 WHERE CODOBLIGPIF = aCODOBLIGPIF;
  END IF;

  WME_Result :=  NR;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_operat_anulat_ok</obj_name>
  <obj_hashval>c5d3b065ef9ca6a4655cf2bd7d601124</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_operat_anulat_ok(INOUT wme_result numeric, INOUT atipdoc numeric, INOUT acoddoc numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aOPERAT numeric := 1;
  aANULAT numeric := 0;
begin
  IF aTIPDOC IN (1, 2, 3, 4, 5, 6, 7) THEN
    BEGIN
      SELECT OPERAT, ANULAT INTO aOPERAT, aANULAT FROM INTRARI WHERE CODINTR = aCODDOC;
    EXCEPTION WHEN OTHERS THEN
      aOPERAT := 0;
      aANULAT := 1;
    END;
  END IF;

  IF aTIPDOC IN (19, 20, 21, 22, 24, 25, 26) THEN
    BEGIN
      SELECT OPERAT, ANULAT INTO aOPERAT, aANULAT FROM IESIRI WHERE CODIES = aCODDOC;
    EXCEPTION WHEN OTHERS THEN
      aOPERAT := 0;
      aANULAT := 1;
    END;
  END IF;

  IF aTIPDOC IN (29, 30, 31, 33) THEN
    BEGIN
      SELECT ANULAT INTO aANULAT FROM TREZOR1 WHERE CODTREZOR1 = aCODDOC;
    EXCEPTION WHEN OTHERS THEN
      aOPERAT := 0;
      aANULAT := 1;
    END;
  END IF;

  IF  aOPERAT = 1 AND  aANULAT = 0 THEN
    WME_Result :=  1;
    RETURN;
  ELSE
    WME_Result :=  0;
    RETURN;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_prelseriadoc</obj_name>
  <obj_hashval>c4fdf099d25d9c4ad451a36a498062dd</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_prelseriadoc(INOUT wme_result character varying, INOUT aseriadoc character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  PRELSER varchar := NULL;
begin
  IF TRIM( aSERIADOC) IS NOT NULL THEN
    WME_Result :=  ' ' || aSERIADOC || ' ';
    RETURN;
  ELSE
    WME_Result :=  '';
    RETURN;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_save_consent_info</obj_name>
  <obj_hashval>85d9410555d3f8d5a2bba4e6a955d37a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_save_consent_info(atipapi numeric, aiban character varying, atoken character varying, aconsentid character varying, aexternalid character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
 nr NUMERIC;
 BEGIN
   --Florin 23.09.2024 - sinc. Oracle
   select count(*) into nr from BANKAUTENTIF
   WHERE
     COALESCE(TIP_API, 0) = aTipAPI
     AND IBAN = aIBAN;

   IF NR = 0 THEN
     INSERT INTO BANKAUTENTIF(COD, TIP_API, IBAN, TOKEN, CONSENTID, EXTERNALID, DATATOKEN)
     VALUES (NEXTVAL('SEQ_BANKAUTENTIF_COD'), aTIPAPI, aIBAN, aTOKEN, aCONSENTID, aExternalID, current_date);
   ELSE
     UPDATE BANKAUTENTIF
     SET
     (TIP_API, IBAN, TOKEN, CONSENTID, EXTERNALID, DATATOKEN) = (SELECT aTIPAPI, aIBAN, aTOKEN, aCONSENTID, aExternalID, current_date)
   WHERE
     COALESCE(TIP_API, 0) = aTipAPI
     AND IBAN = aIBAN;
   END IF;

   end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_setcarnetdoc_i</obj_name>
  <obj_hashval>c648652448f8f6335f2706e1401f7d41</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_setcarnetdoc_i(acarnetdoc_i numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  perform set_config('PKG_TREZOR.CARNETDOC_I',to_char(aCARNETDOC_I,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_setct_monitor</obj_name>
  <obj_hashval>4f71e254df5df26df65175a391ef60d4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_setct_monitor(act_monitor character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  perform set_config('PKG_TREZOR.CT_MONITOR',aCT_MONITOR,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_simbolcontcec</obj_name>
  <obj_hashval>706c9b1cc567c6f60b07901050e84810</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_simbolcontcec(INOUT wme_result character varying, INOUT acodnbankcont numeric, INOUT asemnificatie numeric, INOUT atipdecont numeric, INOUT aobiecttranz numeric, INOUT aan numeric DEFAULT NULL::numeric, INOUT aluna numeric DEFAULT NULL::numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
WME_Result :=  (SELECT PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT FROM PKG_PLANCONTURI_GETSIMBOLCONT(NULL, (SELECT PKG_TREZOR_CODCONTCEC.WME_RESULT FROM PKG_TREZOR_CODCONTCEC(NULL, aCODNBANKCONT, aSEMNIFICATIE, aTIPDECONT, aOBIECTTRANZ, aAn, aLuna))));
RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_sp_lockrecord</obj_name>
  <obj_hashval>fe8fefbb77be3128501ada0d69ffc119</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CODTREZOR INTO Tmp FROM TREZOR WHERE CODTREZOR = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_sp_postrecords</obj_name>
  <obj_hashval>5bc0bcb679176333e45b4518f734f6b9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC           RECORD;
  V_RECAV         RECORD;
  V_RECJURN       RECORD;
  V_REC_SUB       RECORD;
  V_CHELT1        RECORD;
  TIPDOCCASABANCA NUMERIC := 0;
  NR              NUMERIC := 0;
  vCOD            numeric;
  MONEDA          numeric;
  OLDCARNETDOC    numeric := 0;
  OLDNRDOC        numeric := 0;
  aVALOARE        double precision := 0;
  aCodSubunit     numeric;
  aDataDoc        date;
  aDoc            varchar;
  aCREDIT         numeric := 0;
  aCODBANKCONT    numeric := 0;
  aCARNETDOC      numeric := 0;
  aNRDOC          numeric := 0;
BEGIN
  --Florin 22.11.2023 - sinc. Oracle
  --Florin 01.06.2023 - monitor
  --Florin 11.04.2023 - sinc. Oracle (10.04.2023)
  --Florin 18.10.2022 - sinc. Oracle
  --Florin 16.02.2022 - sinc. Oracle
  --Florin 14.02.2022 - sinc. Oracle (13.02.2022)
  --Florin 09.02.2022 - sinc. Oracle
  --Florin 22.11.2021 - fixat 52095
    --Florin 23.03.2021 - pkg_userfirme_postlogcucommit
  perform pkg_trezor_setct_monitor('MON_16');
  UPDATE TMP_TREZOR1 SET TIPTRANZ = 0 WHERE TIPTRANZ = 2;

  BEGIN
    SELECT TIPDOC, SUBUNITATEA, DATADOC, NUMEDOC || '/' || DATADOC, CODBANCA, COALESCE( CARNETDOC, 0), COALESCE( NRDOC, 0)
    INTO TIPDOCCASABANCA, aCodSubunit, aDataDoc, aDoc, aCODBANKCONT, aCARNETDOC, aNRDOC
    FROM TMP_TREZOR;

    SELECT CODMONEDA INTO MONEDA FROM TMP_TREZOR;
    PERFORM PKG_CFGTABLES_EXT_POSTRECORDS_INIT (TIPDOCCASABANCA);
    IF  OPERATION = 0 THEN
      SELECT CODTREZOR INTO RecId FROM TMP_TREZOR;

      IF (SELECT PKG_USERFIRME_ValidPostLog.WME_RESULT FROM PKG_USERFIRME_ValidPostLog(NULL, TO_NUMBER(current_setting('PKG_GLOBALS.USERID', true),'999999999999999999'), current_setting('PKG_TREZOR.CT_MONITOR', true)))
      THEN
        PERFORM pkg_userfirme_postlogcucommit( 'TREZOR', current_setting('PKG_GLOBALS.USERNAME', true), 'M', RECID, current_setting('PKG_GLOBALS.FIRMANAME', true), aCodSubunit, aDataDoc, aDoc, '', (SELECT PKG_GLOBALS_GET_EXE_VERSION.WME_RESULT FROM PKG_GLOBALS_GET_EXE_VERSION(NULL,NULL)));
      END IF;

      FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (900, 901, 950, 951)) LOOP
        IF  (SELECT PKG_CATEGCONST_ESTECHELTAVANS.WME_RESULT FROM PKG_CATEGCONST_ESTECHELTAVANS(NULL, V_REC.ICONT)) + (SELECT PKG_CATEGCONST_ESTEVENITAVANS.WME_RESULT FROM PKG_CATEGCONST_ESTEVENITAVANS(NULL, V_REC.ICONT)) = 0
        THEN
          SELECT COUNT( *) INTO NR FROM MASTERCHELTAVANS WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
          IF  NR &gt; 0 THEN
            FOR V_RECAV IN (SELECT * FROM CHELTAVANS WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF) LOOP
              FOR V_RECJURN IN (SELECT * FROM JURNAL WHERE CODDOC = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106)) LOOP
                UPDATE NCONTRUL
                SET
                RULAJCD      = RULAJCD      - V_RECJURN.VALOARE,
                RULAJVCD     = RULAJVCD     - V_RECJURN.VALOAREV,
                RULAJC_IFRS  = RULAJC_IFRS  - V_RECJURN.VALOARE_IFRS,
                RULAJVC_IFRS = RULAJVC_IFRS - V_RECJURN.VALOAREV_IFRS
                WHERE
                 CODCONT = V_RECJURN.CONTD AND  AN = V_RECJURN.AN AND  LUNA = V_RECJURN.LUNA;

                UPDATE NCONTRUL
                SET
                RULAJCC      = RULAJCC      - V_RECJURN.VALOARE,
                RULAJVCC     = RULAJVCC     - V_RECJURN.VALOAREV,
                RULAJC_IFRS  = RULAJC_IFRS  - V_RECJURN.VALOARE_IFRS,
                RULAJVC_IFRS = RULAJVC_IFRS - V_RECJURN.VALOAREV_IFRS
                WHERE
                 CODCONT = V_RECJURN.CONTC AND  AN = V_RECJURN.AN AND  LUNA = V_RECJURN.LUNA;
              END LOOP;

              DELETE FROM JURNAL1 WHERE CODDOC = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106);
              DELETE FROM JURNAL  WHERE CODDOC = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106);

              DELETE FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
              DELETE FROM CHELTAVANS  WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
            END LOOP;

            DELETE FROM MASTERCHELTAVANS WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
          END IF;
        END IF;
      END LOOP;

      FOR V_REC IN (SELECT * FROM STINGERE
                    WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM OBLIGPIF
                                              WHERE CODGENERAL IN (SELECT CODGENERAL FROM GENERAL
                                                                   WHERE TIPDOC = TIPDOCCASABANCA AND CODDOC IN (SELECT CODTREZOR1 FROM TREZOR1 WHERE CODTREZOR = RecID)
                                                                  )
                                             )
                      AND CODSTINGERE NOT IN (SELECT CODSTINGERE FROM TMP_STINGERE)
                   )
      LOOP
        PERFORM pkg_trezor_NotifyStergereIncasareFact(V_REC.CODSTINGERE);
        DELETE FROM STINGERE WHERE CODSTINGERE = V_REC.CODSTINGERE;

        IF  COALESCE( V_REC.CODPLATA1, 0) &lt;&gt; 0 THEN
          UPDATE PLATI1
          SET
          STINSA = 0,
          REST   = VALOARE
          WHERE
           CODPLATA1 = V_REC.CODPLATA1;
        END IF;
      END LOOP;

      FOR V_REC IN (SELECT * FROM OBLIGPIF
                    WHERE CODGENERAL IN (SELECT CODGENERAL FROM GENERAL
                                         WHERE TIPDOC = TIPDOCCASABANCA AND CODDOC IN (SELECT CODTREZOR1 FROM TREZOR1 WHERE CODTREZOR = RecID)
                                        )
                      AND CODOBLIGPIF NOT IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF)
                   )
      LOOP
        FOR V_RECAV IN (SELECT * FROM CHELTAVANS WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF) LOOP
          FOR V_RECJURN IN (SELECT * FROM JURNAL WHERE CODDOC = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106)) LOOP
            UPDATE NCONTRUL
            SET
            RULAJCD      = RULAJCD      - V_RECJURN.VALOARE,
            RULAJVCD     = RULAJVCD     - V_RECJURN.VALOAREV,
            RULAJC_IFRS  = RULAJC_IFRS  - V_RECJURN.VALOARE_IFRS,
            RULAJVC_IFRS = RULAJVC_IFRS - V_RECJURN.VALOAREV_IFRS
            WHERE
             CODCONT = V_RECJURN.CONTD AND  AN = V_RECJURN.AN AND  LUNA = V_RECJURN.LUNA;

            UPDATE NCONTRUL
            SET
            RULAJCC      = RULAJCC      - V_RECJURN.VALOARE,
            RULAJVCC     = RULAJVCC     - V_RECJURN.VALOAREV,
            RULAJC_IFRS  = RULAJC_IFRS  - V_RECJURN.VALOARE_IFRS,
            RULAJVC_IFRS = RULAJVC_IFRS - V_RECJURN.VALOAREV_IFRS
            WHERE
             CODCONT = V_RECJURN.CONTC AND  AN = V_RECJURN.AN AND  LUNA = V_RECJURN.LUNA;
          END LOOP;

          DELETE FROM JURNAL1 WHERE CODDOC = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106);
          DELETE FROM JURNAL  WHERE CODDOC = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106);

          DELETE FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
          DELETE FROM CHELTAVANS  WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
        END LOOP;

        DELETE FROM MASTERCHELTAVANS WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
        DELETE FROM TAXDECL          WHERE TIPDOC = TIPDOCCASABANCA AND CODDOC1 =  V_REC.CODOBLIGPIF;
        DELETE FROM OBLIGPIF         WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
      END LOOP;

      DELETE FROM GENERAL
      WHERE TIPDOC = TIPDOCCASABANCA AND CODDOC IN (SELECT CODTREZOR1 FROM TREZOR1 WHERE CODTREZOR = RecID)
        AND CODGENERAL NOT IN (SELECT CODGENERAL FROM TMP_GENERAL);

      FOR V_REC IN (SELECT * FROM TREZOR1 WHERE CODTREZOR = RecID AND CODTREZOR1 NOT IN (SELECT CODTREZOR1 FROM TMP_TREZOR1)) LOOP
        IF  V_REC.CARNETDOC &lt;&gt; 0 AND  V_REC.NRDOC &lt;&gt; 0 THEN
          PERFORM PKG_CARNETEDOC_RELEASENUMARDOC( V_REC.CARNETDOC, V_REC.NRDOC);
          PERFORM PKG_CARNETEDOC_COMPACTEAZAINTERVALE( V_REC.CARNETDOC);
        END IF;
        DELETE FROM TAXDECL WHERE TipDoc = TIPDOCCASABANCA and CODDOC = V_REC.CodTrezor1;
        DELETE FROM RETUROSTINS WHERE TipDoc = TIPDOCCASABANCA and CODDOC = V_REC.CodTrezor1;
      END LOOP;

      FOR V_REC IN (SELECT * FROM TREZOR1 WHERE CODTREZOR = RecID AND CODTREZOR1 NOT IN (SELECT CODTREZOR1 FROM TMP_TREZOR1)) LOOP
        DELETE FROM TREZOR1 WHERE CODTREZOR1 = V_REC.CODTREZOR1;

        IF  COALESCE( V_REC.CODSERTAR, 0) &lt;&gt; 0 THEN
          UPDATE NSERTAR SET DEPUS = 0 WHERE CODSERTAR = V_REC.CODSERTAR;
        END IF;

        IF  COALESCE( V_REC.CODPLATA1, 0) &lt;&gt; 0 THEN
          UPDATE PLATI1
          SET
          STINSA = 0,
          REST   = VALOARE
          WHERE
           CODPLATA1 = V_REC.CODPLATA1;
        END IF;
      END LOOP;

      SELECT CODTREZOR INTO RecId FROM TMP_TREZOR;

      UPDATE TREZOR
      SET
      (TIPDOC, CODBANCA, ICONTPERS, MONEDAPERS, DATADOC, NUMEDOC, AN, LUNA, AGENT, OPERAT, BLOCAT, SUBUNITATEA, IDIMPORT, CODANALIZA, CARNETDOC, NRDOC, SERIADOC, LISTAT)
      =
      (SELECT TIPDOC, CODBANCA, ICONTPERS, MONEDAPERS, DATADOC, NUMEDOC, AN, LUNA, AGENT, OPERAT, BLOCAT, SUBUNITATEA, IDIMPORT, CODANALIZA, CARNETDOC, NRDOC, SERIADOC, LISTAT FROM TMP_TREZOR)
      WHERE
       CODTREZOR = RecId;

      FOR v_rec IN (SELECT * FROM TMP_TREZOR1 ORDER BY INDEXLOCAL) LOOP
        IF  v_rec.CODTREZOR1 &gt; 0 THEN
          DELETE FROM RETUROSTINS where tipdoc = TIPDOCCASABANCA
          and coddoc = v_rec.CODTREZOR1
          and CODRETUROSTINS not in (Select CODRETUROSTINS from TMP_RETUROSTINS);
          SELECT COALESCE( CARNETDOC, 0), COALESCE( NRDOC, 0)
          INTO OLDCARNETDOC, OLDNRDOC
          FROM TREZOR1 WHERE COALESCE( CodTREZOR1, 0) = COALESCE( v_rec.CodTREZOR1, 0);

          IF (OLDCARNETDOC &lt;&gt; 0)  AND (OLDNRDOC &lt;&gt; 0)  AND (V_REC.CARNETDOC &lt;&gt; OLDCARNETDOC OR  V_REC.NRDOC &lt;&gt; OLDNRDOC) THEN
            IF  OLDCARNETDOC &lt;&gt; 0 AND  OLDNRDOC &lt;&gt; 0 THEN
              PERFORM PKG_CARNETEDOC_RELEASENUMARDOC( OLDCARNETDOC, OLDNRDOC);
              PERFORM PKG_CARNETEDOC_COMPACTEAZAINTERVALE( OLDCARNETDOC);
            END IF;
          END IF;

          UPDATE TREZOR1
          SET
          INDEXLOCAL  = v_rec.INDEXLOCAL,
          TIPTRANZ    = v_rec.TIPTRANZ,
          CARNETDOC   = v_rec.CARNETDOC,
          DOC         = v_rec.DOC,
          NRDOC       = v_rec.NRDOC,
          DATADOC     = v_rec.DATADOC,
          VALDOC      = v_rec.VALDOC,
          CURS        = v_rec.CURS,
          COMISION    = v_rec.COMISION,
          OBIECTTRANZ = v_rec.OBIECTTRANZ,
          SERIEDOC    = V_REC.SERIEDOC,
          CODPART     = v_rec.CODPART,
          TIPDECONT   = v_rec.TIPDECONT,
          PLATATVA    = V_REC.PLATATVA,
          CODSERTAR   = V_REC.CODSERTAR,
          NRI         = V_REC.NRI,
          CODCOMANDA  = V_REC.CODCOMANDA,
          CODPLATA1   = V_REC.CODPLATA1,
          DATADECONT  = v_rec.DATADECONT,
          AN          = v_rec.AN,
          LUNA        = v_rec.LUNA,
          OBS         = v_rec.OBS,
          AGENT       = v_rec.AGENT,
          ANULAT      = v_rec.ANULAT,
          CODCENTRU   = V_REC.CODCENTRU,
          CODGEST     = V_REC.CODGEST,
          CODCMDINT1  = V_REC.CODCMDINT1
          WHERE
           CODTREZOR1 = v_rec.CODTREZOR1;
        ELSE
          SELECT NEXTVAL('SEQ_TREZOR1_CODTREZOR1') INTO vCOD;

          UPDATE TMP_TREZOR1  SET CODTREZOR1 = vCOD WHERE CODTREZOR1 = v_rec.CODTREZOR1;
          UPDATE TMP_GENERAL  SET CODDOC     = vCOD WHERE CODDOC     = v_rec.CODTREZOR1;
          UPDATE TMP_OBLIGPIF SET CODTREZOR1 = vCOD WHERE CODTREZOR1 = v_rec.CODTREZOR1;
          UPDATE TMP_RETUROSTINS  SET CODDOC = vCOD WHERE CODDOC     = v_rec.CODTREZOR1;
          UPDATE TMP_JURNAL   SET INDEXLOCAL = VCOD WHERE INDEXLOCAL = v_rec.CODTREZOR1;
          UPDATE TMP_JURNAL1  SET INDEXLOCAL = VCOD WHERE INDEXLOCAL = v_rec.CODTREZOR1;


          INSERT INTO TREZOR1(CODTREZOR1, CODTREZOR, INDEXLOCAL, TIPTRANZ, CARNETDOC, DOC, NRDOC, DATADOC, VALDOC, CURS, COMISION, OBIECTTRANZ, SERIEDOC, CODPART, TIPDECONT, PLATATVA, CODSERTAR, NRI, CODCOMANDA, CODPLATA1, DATADECONT, AN, LUNA, OBS, AGENT, ANULAT, USERID, DATACREARE, CODCENTRU, CODGEST, CODCMDINT1)
          VALUES(vCOD, v_rec.CODTREZOR, v_rec.INDEXLOCAL, v_rec.TIPTRANZ, v_rec.CARNETDOC, v_rec.DOC, v_rec.NRDOC, v_rec.DATADOC, v_rec.VALDOC, v_rec.CURS, v_rec.COMISION, v_rec.OBIECTTRANZ, V_REC.SERIEDOC, v_rec.CODPART, v_rec.TIPDECONT, V_REC.PLATATVA, V_REC.CODSERTAR, V_REC.NRI, V_REC.CODCOMANDA, V_REC.CODPLATA1, v_rec.DATADECONT, v_rec.AN, v_rec.LUNA, v_rec.OBS, V_REC.AGENT, V_REC.ANULAT, TO_NUMBER(current_setting('PKG_GLOBALS.userid', true),'999999999999999999'), CURRENT_TIMESTAMP, V_REC.CODCENTRU, v_rec.CODGEST, v_rec.CODCMDINT1);
        END IF;
      END LOOP;

      insert into RETUROSTINS (CODRETUROSTINS,
                                                    CODRETURO,
                                                    CODDOC,
                                                    TIPDOC,
                                                    VALOARE,
                                                    STARTEDAT,
                                                    VOUCHERBARCODE)
       select  Nextval('SEQ_RETUROSTINS_CODRETUROSTINS'),
                  rs.CODRETURO,
                  rs.CODDOC,
                  TIPDOCCASABANCA,
                  rs.VALOARE,
                  rs.STARTEDAT,
                  rs.VOUCHERBARCODE
       from TMP_RETUROSTINS rs where rs.CODRETUROSTINS &lt; 0;

       FOR v_rec IN ( SELECT * FROM TMP_RETUROSTINS WHERE NVL(CODRETUROSTINS,-1) &gt; 0 ORDER BY CODRETUROSTINS ) LOOP
           update RETUROSTINS
            set CODRETURO            = v_rec.CODRETURO,
                  CODDOC                 = v_rec.CODDOC,
                  TIPDOC                   = TIPDOCCASABANCA,
                  VALOARE                 = v_rec.VALOARE,
                  STARTEDAT              = v_rec.STARTEDAT,
                  VOUCHERBARCODE  = v_rec.VOUCHERBARCODE
             WHERE
                   CODRETUROSTINS  = v_rec.CODRETUROSTINS;

       END LOOP;


      FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (310, 410)) LOOP
        UPDATE TMP_OBLIGPIF SET TERMEN = (SELECT DATADOC FROM TMP_TREZOR1 WHERE CODTREZOR1 = V_REC.CODTREZOR1) WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
      END LOOP;

      FOR v_rec IN (SELECT * FROM TMP_GENERAL) LOOP
        IF  v_rec.CODGENERAL &gt; 0 THEN
          UPDATE GENERAL
          SET
          TIPDOC       = v_rec.TIPDOC,
          CODDOC       = v_rec.CODDOC,
          MONEDA       = v_rec.MONEDA,
          CURS         = v_rec.CURS,
          TVA          = v_rec.TVA,
          SEMNIFICATIE = v_rec.SEMNIFICATIE,
          FARAREG      = V_REC.FARAREG
          WHERE
           CODGENERAL = v_rec.CODGENERAL;
        ELSE
          SELECT NEXTVAL('SEQ_GENERAL_CODGENERAL') INTO vCOD;

          UPDATE TMP_OBLIGPIF O SET CODGENERAL = vCOD WHERE O.CODGENERAL = v_rec.CODGENERAL;

          INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, FARAREG)
          VALUES(vCOD, v_rec.TIPDOC, v_rec.CODDOC, v_rec.MONEDA, v_rec.CURS, v_rec.TVA, v_rec.SEMNIFICATIE, V_REC.FARAREG);
        END IF;
      END LOOP;

      DELETE FROM TMP_OBLIGPIF_ASOCIAT;
      INSERT INTO TMP_OBLIGPIF_ASOCIAT(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODTRANSA, COEFPROVIZION, CODCENTRU, CODANALIZANOD, TVANEDED, PROCTVA, RESTTVA)
      (SELECT CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODTRANSA, COEFPROVIZION, CODCENTRU, CODANALIZANOD, TVANEDED, PROCTVA, COALESCE( RESTTVA, 0)
       FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (700, 701, 750, 751)
      );

      DELETE FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (700, 701, 750, 751);

      FOR v_rec IN (SELECT * FROM TMP_OBLIGPIF ORDER BY CODOBLIGPIF) LOOP
        IF  v_rec.CODOBLIGPIF &gt; 0 THEN
          UPDATE OBLIGPIF
          SET
          CODGENERAL         = v_rec.CODGENERAL,
          TERMEN             = v_rec.TERMEN,
          VALOARE            = V_REC.VALOARE,
          CODPART            = v_rec.CODPART,
          ICONT              = v_rec.ICONT,
          TIPPLATA           = v_rec.TIPPLATA,
          MAJORARI           = v_rec.MAJORARI,
          SEMNIFICATIE       = v_rec.SEMNIFICATIE,
          TIP                = v_rec.TIP,
          CONTBANKTRANZACTIE = v_rec.CONTBANKTRANZACTIE,
          CODOBLIGASOCIAT    = v_rec.CODOBLIGASOCIAT,
          VALOAREAFISATA     = v_rec.VALOAREAFISATA,
          TVAAFISAT          = v_rec.TVAAFISAT,
          CODGEST            = v_rec.CODGEST,
          CODNPARCAUT        = V_REC.CODNPARCAUT,
          CODTRANSA          = V_REC.CODTRANSA,
          COEFPROVIZION      = V_REC.COEFPROVIZION,
          CODCENTRU          = V_REC.CODCENTRU,
          CODANALIZANOD      = v_Rec.Codanalizanod,
          TVANEDED           = V_REC.TVANEDED,
          PROCTVA            = V_REC.PROCTVA,
          DINCARETVA         = V_REC.DINCARETVA
          WHERE
           CODOBLIGPIF = v_rec.CODOBLIGPIF;
        ELSE
          SELECT NEXTVAL('SEQ_OBLIGPIF_CODOBLIGPIF') INTO vCOD;

          UPDATE TMP_OBLIGPIF         SET CODOBLIGPIF     = vCOD WHERE CODOBLIGPIF     = v_rec.CODOBLIGPIF;
          UPDATE TMP_STINGERE         SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;
          UPDATE TMP_OBLIGPIF_ASOCIAT SET CODOBLIGASOCIAT = vCOD WHERE CODOBLIGASOCIAT = v_rec.CODOBLIGPIF;

          INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CODNPARCAUT, CODTRANSA, COEFPROVIZION, CODCENTRU, CODANALIZANOD, TVANEDED, PROCTVA, TVAAFISAT, DINCARETVA, RESTTVA)
          VALUES(vCOD, v_rec.CODGENERAL, v_rec.TERMEN, V_REC.VALOARE, V_REC.VALOARE, v_rec.CODPART, v_rec.ICONT, v_rec.TIPPLATA, v_rec.MAJORARI, v_rec.SEMNIFICATIE, v_rec.TIP, v_rec.CONTBANKTRANZACTIE, v_rec.CODOBLIGASOCIAT, V_REC.VALOAREAFISATA, V_REC.CODGEST, V_REC.CODNPARCAUT, V_REC.CODTRANSA, V_REC.COEFPROVIZION, V_REC.CODCENTRU, v_Rec.codanalizanod, V_REC.TVANEDED, V_REC.PROCTVA, V_REC.TVAAFISAT, V_REC.DINCARETVA, COALESCE( V_REC.RESTTVA, 0));
        END IF;
      END LOOP;

      FOR v_rec IN (SELECT * FROM TMP_OBLIGPIF_ASOCIAT) LOOP
        IF  v_rec.CODOBLIGPIF &gt; 0 THEN
          UPDATE OBLIGPIF
          SET
          CODGENERAL         = v_rec.CODGENERAL,
          TERMEN             = v_rec.TERMEN,
          VALOARE            = v_rec.VALOARE,
          REST               = v_rec.REST,
          CODPART            = v_rec.CODPART,
          ICONT              = v_rec.ICONT,
          TIPPLATA           = v_rec.TIPPLATA,
          MAJORARI           = v_rec.MAJORARI,
          SEMNIFICATIE       = v_rec.SEMNIFICATIE,
          TIP                = v_rec.TIP,
          CONTBANKTRANZACTIE = v_rec.CONTBANKTRANZACTIE,
          CODOBLIGASOCIAT    = v_rec.CODOBLIGASOCIAT,
          VALOAREAFISATA     = v_rec.VALOAREAFISATA,
          TVAAFISAT          = v_rec.TVAAFISAT,
          CODGEST            = v_rec.CODGEST,
          CODNPARCAUT        = V_REC.CODNPARCAUT,
          CODTRANSA          = V_REC.CODTRANSA,
          COEFPROVIZION      = V_REC.COEFPROVIZION,
          CODCENTRU          = V_REC.CODCENTRU,
          CODANALIZANOD      = V_REC.CODANALIZANOD,
          TVANEDED           = V_REC.TVANEDED,
          PROCTVA            = V_REC.PROCTVA,
          DINCARETVA         = v_rec.DINCARETVA,
          RESTTVA            = v_rec.RESTTVA
          WHERE
           CODOBLIGPIF = v_rec.CODOBLIGPIF;
        ELSE
          SELECT NEXTVAL('SEQ_OBLIGPIF_CODOBLIGPIF') INTO vCOD;

          UPDATE TMP_STINGERE SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;

          INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CODNPARCAUT, CODTRANSA, COEFPROVIZION, CODCENTRU, CODANALIZANOD, TVANEDED, PROCTVA, TVAAFISAT, DINCARETVA, RESTTVA)
          VALUES(vCOD, v_rec.CODGENERAL, v_rec.TERMEN, v_rec.VALOARE, v_rec.REST, v_rec.CODPART, v_rec.ICONT, v_rec.TIPPLATA, v_rec.MAJORARI, v_rec.SEMNIFICATIE, v_rec.TIP, v_rec.CONTBANKTRANZACTIE, v_rec.CODOBLIGASOCIAT, v_rec.VALOAREAFISATA, V_REC.CODGEST, V_REC.CODNPARCAUT, V_REC.CODTRANSA, V_REC.COEFPROVIZION, V_REC.CODCENTRU, v_Rec.CODANALIZANOD, V_REC.TVANEDED, V_REC.PROCTVA, V_REC.TVAAFISAT, V_REC.DINCARETVA, COALESCE( V_REC.RESTTVA, 0));
        END IF;
      END LOOP;

      FOR v_rec IN (SELECT * FROM TMP_STINGERE) LOOP
        IF  v_rec.CODSTINGERE &gt; 0 THEN
          UPDATE STINGERE
          SET
          CODSTINSPIF     = v_rec.CODSTINSPIF,
          CODSTINGATORPIF = v_rec.CODSTINGATORPIF,
          VALOARE         = v_rec.VALOARE,
          DINCARETVA      = v_rec.DINCARETVA,
          CODPLATA1       = V_REC.CODPLATA1
          WHERE
           CODSTINGERE = v_rec.CODSTINGERE;
        ELSE
          SELECT NEXTVAL('SEQ_STINGERE_CODSTINGERE') INTO vCOD;

          INSERT INTO STINGERE(CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE, CODPLATA1, DINCARETVA)
          VALUES(vCOD, v_rec.CODSTINSPIF, v_rec.CODSTINGATORPIF, v_rec.VALOARE, V_REC.CODPLATA1, V_REC.DINCARETVA);
        END IF;
      END LOOP;

      DELETE FROM JURNAl1 WHERE TIPDOC = TIPDOCCASABANCA AND  CODDOC = RECID AND CODJURNAL1 NOT IN (SELECT CODJURNAL1 FROM TMP_JURNAl1);

      FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
        IF  V_REC.CODJURNAL1 &gt; 0 THEN
          UPDATE JURNAL1
          SET
          CODDOC        = V_REC.CODDOC,
          TIPDOC        = V_REC.TIPDOC,
          INDEXLOCAL    = V_REC.INDEXLOCAL,
          CODBAZAD      = V_REC.CODBAZAD,
          ICONTBAZAD    = V_REC.ICONTBAZAD,
          TIPBAZAD      = V_REC.TIPBAZAD,
          CODBAZAC      = V_REC.CODBAZAC,
          ICONTBAZAC    = V_REC.ICONTBAZAC,
          TIPBAZAC      = V_REC.TIPBAZAC,
          CODDESCRD     = V_REC.CODDESCRD,
          ICONTD        = V_REC.ICONTD,
          TIPCONTD      = V_REC.TIPCONTD,
          ANALITICCONTD = V_REC.ANALITICCONTD,
          CODDESCRC     = V_REC.CODDESCRC,
          ICONTC        = V_REC.ICONTC,
          TIPCONTC      = V_REC.TIPCONTC,
          ANALITICCONTC = V_REC.ANALITICCONTC,
          GEST          = V_REC.GEST,
          VALOARE       = V_REC.VALOARE,
          VALOAREV      = V_REC.VALOAREV,
          VALOARE_IFRS  = V_REC.VALOARE_IFRS,
          VALOAREV_IFRS = V_REC.VALOAREV_IFRS,
          OBS           = V_REC.OBS,
          AN            = V_REC.AN,
          LUNA          = V_REC.LUNA,
          DIRTY         = V_REC.DIRTY,
          SUBUNITATEA   = V_REC.SUBUNITATEA,
          CODCENTRU     = v_rec.CODCENTRU,
          DATADOC       = V_REC.DATADOC,
          DOCUMENT      = V_REC.DOCUMENT,
          CODANALIZANOD = V_REC.CODANALIZANOD
          WHERE
           CODJURNAL1 = V_REC.CODJURNAl1;
        ELSE
          INSERT INTO JURNAL1(CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD, CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT, CODANALIZANOD)
          VALUES(NEXTVAL('SEQ_JURNAL1_CODJURNAL1'), RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CODBAZAD, V_REC.ICONTBAZAD, V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD, V_REC.CODBAZAC, V_REC.ICONTBAZAC, V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.VALOARE_IFRS, V_REC.VALOAREV_IFRS, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, v_rec.CODCENTRU, V_REC.DATADOC, V_REC.DOCUMENT, v_Rec.CODANALIZANOD);
        END IF;
      END LOOP;

      DELETE FROM JURNAL WHERE TIPDOC = TIPDOCCASABANCA AND  CODDOC = RECID AND CODJURNAL NOT IN (SELECT CODJURNAL FROM TMP_JURNAl);

      FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
        IF  V_REC.CODJURNAL &gt; 0 THEN
          UPDATE JURNAL
          SET
          CODDOC        = V_REC.CODDOC,
          TIPDOC        = V_REC.TIPDOC,
          INDEXLOCAL    = V_REC.INDEXLOCAL,
          CONTD         = V_REC.CONTD,
          CONTC         = V_REC.CONTC,
          GEST          = V_REC.GEST,
          VALOARE       = V_REC.VALOARE,
          VALOAREV      = V_REC.VALOAREV,
          VALOARE_IFRS  = V_REC.VALOARE_IFRS,
          VALOAREV_IFRS = V_REC.VALOAREV_IFRS,
          OBS           = V_REC.OBS,
          AN            = V_REC.AN,
          LUNA          = V_REC.LUNA,
          SUBUNITATEA   = V_REC.SUBUNITATEA,
          CODCENTRU     = v_rec.CODCENTRU,
          DATADOC       = V_REC.DATADOC,
          DOCUMENT      = V_REC.DOCUMENT,
          CODANALIZANOD = v_rec.CODANALIZANOD
          WHERE
           CODJURNAL = V_REC.CODJURNAl;
        ELSE
          INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT, CODANALIZANOD)
          VALUES(NEXTVAL('SEQ_JURNAL_CODJURNAL'), RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.VALOARE_IFRS, V_REC.VALOAREV_IFRS, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, v_rec.CODCENTRU, V_REC.DATADOC, V_REC.DOCUMENT, v_rec.CODANALIZANOD);
        END IF;
      END LOOP;
    ELSE
      SELECT NEXTVAL('SEQ_TREZOR_CODTREZOR') INTO RecID;
      PERFORM PKG_CFGTABLES_EXT_UPDATE_COD_CORESP('TREZOR', RecId);

      IF (SELECT PKG_USERFIRME_ValidPostLog.WME_RESULT FROM PKG_USERFIRME_ValidPostLog(NULL, TO_NUMBER(current_setting('PKG_GLOBALS.USERID', true),'999999999999999999'), current_setting('PKG_TREZOR.CT_MONITOR', true)))
      THEN
        PERFORM pkg_userfirme_postlogcucommit( 'TREZOR', current_setting('PKG_GLOBALS.USERNAME', true), 'A', RECID, current_setting('PKG_GLOBALS.FIRMANAME', true), aCodSubunit, aDataDoc, aDoc, '', (SELECT PKG_GLOBALS_GET_EXE_VERSION.WME_RESULT FROM PKG_GLOBALS_GET_EXE_VERSION(NULL,NULL)));
      END IF;

      UPDATE TMP_TREZOR1 SET CODTREZOR = RecID;

      INSERT INTO TREZOR
      (CODTREZOR, TIPDOC, CODBANCA, ICONTPERS, MONEDAPERS, DATADOC, NUMEDOC, AN, LUNA, AGENT, OPERAT, BLOCAT, SUBUNITATEA,userid,datacreare, IDIMPORT, CODANALIZA, CARNETDOC, NRDOC, SERIADOC, LISTAT)
        (SELECT RecId, TIPDOC, CODBANCA, ICONTPERS, MONEDAPERS, DATADOC, NUMEDOC, AN, LUNA, AGENT, OPERAT, BLOCAT, SUBUNITATEA, TO_NUMBER(current_setting('PKG_GLOBALS.USERID', true),'999999999999999999'), CURRENT_TIMESTAMP, IDIMPORT, CODANALIZA, CARNETDOC, NRDOC, SERIADOC, LISTAT FROM TMP_TREZOR
      );

      FOR v_rec IN (SELECT * FROM TMP_TREZOR1 ORDER BY INDEXLOCAL) LOOP
        SELECT NEXTVAL('SEQ_TREZOR1_CODTREZOR1') INTO vCOD;

        UPDATE TMP_TREZOR1  SET CODTREZOR1 = vCOD WHERE CODTREZOR1 = v_rec.CODTREZOR1;
        UPDATE TMP_GENERAL  SET CODDOC     = vCOD WHERE CODDOC     = v_rec.CODTREZOR1;
        UPDATE TMP_OBLIGPIF SET CODTREZOR1 = VCOD WHERE CODTREZOR1 = V_REC.CODTREZOR1;
        UPDATE TMP_RETUROSTINS  SET CODDOC = vCOD WHERE CODDOC     = v_rec.CODTREZOR1;
        UPDATE TMP_JURNAL   SET INDEXLOCAL = VCOD  WHERE INDEXLOCAL = v_rec.CODTREZOR1;
        UPDATE TMP_JURNAL1  SET INDEXLOCAL = VCOD WHERE INDEXLOCAL = v_rec.CODTREZOR1;

        PERFORM PKG_CFGTABLES_EXT_UPDATE_COD_CORESP('TREZOR1', vCOD, v_rec.CODTREZOR1);

        INSERT INTO TREZOR1(CODTREZOR1, CODTREZOR, INDEXLOCAL, TIPTRANZ, CARNETDOC, DOC, NRDOC, DATADOC, VALDOC, CURS, COMISION, OBIECTTRANZ, SERIEDOC, CODPART, TIPDECONT, PLATATVA, CODSERTAR, NRI, CODCOMANDA, CODPLATA1, DATADECONT, AN, LUNA, OBS, AGENT, ANULAT, userid, datacreare, CODCENTRU, CODGEST, CODCMDINT1)
        VALUES(vCod, RecID, v_rec.INDEXLOCAL, v_rec.TIPTRANZ, v_rec.CARNETDOC, v_rec.DOC, v_rec.NRDOC, v_rec.DATADOC, v_rec.VALDOC, v_rec.CURS, v_rec.COMISION, v_rec.OBIECTTRANZ, V_REC.SERIEDOC, v_rec.CODPART, v_rec.TIPDECONT, V_REC.PLATATVA, V_REC.CODSERTAR, V_REC.NRI, V_REC.CODCOMANDA, V_REC.CODPLATA1, v_rec.DATADECONT, v_rec.AN, v_rec.LUNA, v_rec.OBS, V_REC.AGENT, V_REC.ANULAT, TO_NUMBER(current_setting('PKG_GLOBALS.USERID', true),'999999999999999999'), CURRENT_TIMESTAMP, V_REC.CODCENTRU, V_REC.CODGEST, V_REC.CODCMDINT1);
      END LOOP;

      insert into RETUROSTINS (CODRETUROSTINS,
                                                    CODRETURO,
                                                    CODDOC,
                                                    TIPDOC,
                                                    VALOARE,
                                                    STARTEDAT,
                                                    VOUCHERBARCODE)
       select  Nextval('SEQ_RETUROSTINS_CODRETUROSTINS'),
                  rs.CODRETURO,
                  rs.CODDOC,
                  TIPDOCCASABANCA,
                  rs.VALOARE,
                  rs.STARTEDAT,
                  rs.VOUCHERBARCODE
       from TMP_RETUROSTINS rs ;

      FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (310, 410))
      LOOP
        UPDATE TMP_OBLIGPIF
        SET
         TERMEN = (SELECt DATADOC FROM TMP_TREZOR1 WHERE CODTREZOR1 = V_REC.CODTREZOR1)
        WHERE
          CODOBLIGPIF = V_REC.CODOBLIGPIF;
      END LOOP;

      FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (310, 410)) LOOP
        UPDATE TMP_OBLIGPIF SET TERMEN = (SELECT DATADOC FROM TMP_TREZOR1 WHERE CODTREZOR1 = V_REC.CODTREZOR1) WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
      END LOOP;

      FOR v_rec IN (SELECT * FROM TMP_GENERAL) LOOP
        SELECT NEXTVAL('SEQ_GENERAL_CODGENERAL') INTO vCOD;

        UPDATE TMP_OBLIGPIF SET CODGENERAL = vCOD WHERE CODGENERAL = v_rec.CODGENERAL;

        INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, FARAREG)
        VALUES(vCOD, v_rec.TIPDOC, v_rec.CODDOC, v_rec.MONEDA, v_rec.CURS, v_rec.TVA, v_rec.SEMNIFICATIE, V_REC.FARAREG);
      END LOOP;

      DELETE FROM TMP_OBLIGPIF_ASOCIAT;
      INSERT INTO TMP_OBLIGPIF_ASOCIAT(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CODNPARCAUT, CODTRANSA, COEFPROVIZION, CODCENTRU, CODANALIZANOD, TVANEDED, PROCTVA, RESTTVA)
      (SELECT CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CODNPARCAUT, CODTRANSA, COEFPROVIZION, CODCENTRU, CODANALIZANOD, TVANEDED, PROCTVA, COALESCE( RESTTVA, 0)
       FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (700, 701, 750, 751)
      );

      DELETE FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (700, 701, 750, 751);

      FOR v_rec IN (SELECT * FROM TMP_OBLIGPIF ORDER BY CODOBLIGPIF) LOOP
        SELECT NEXTVAL('SEQ_OBLIGPIF_CODOBLIGPIF') INTO vCOD;

        UPDATE TMP_OBLIGPIF         SET CODOBLIGPIF     = vCOD WHERE CODOBLIGPIF     = v_rec.CODOBLIGPIF;
        UPDATE TMP_STINGERE         SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;
        UPDATE TMP_OBLIGPIF_ASOCIAT SET CODOBLIGASOCIAT = vCOD WHERE CODOBLIGASOCIAT = v_rec.CODOBLIGPIF;

        INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CODNPARCAUT, CODTRANSA, COEFPROVIZION, CODCENTRU, CODANALIZANOD, TVANEDED, PROCTVA, TVAAFISAT, DINCARETVA, RESTTVA)
        VALUES(vCOD, v_rec.CODGENERAL, v_rec.TERMEN, V_REC.VALOARE, V_REC.VALOARE, v_rec.CODPART, v_rec.ICONT, v_rec.TIPPLATA, v_rec.MAJORARI, v_rec.SEMNIFICATIE, v_rec.TIP, v_rec.CONTBANKTRANZACTIE, v_rec.CODOBLIGASOCIAT, v_rec.VALOAREAFISATA, V_REC.CODGEST, V_REC.CODNPARCAUT, V_REC.CODTRANSA, V_REC.COEFPROVIZION, V_REC.CODCENTRU, v_Rec.CODANALIZANOD, V_REC.TVANEDED, V_REC.PROCTVA, V_REC.TVAAFISAT, V_REC.DINCARETVA, V_REC.RESTTVA);
      END LOOP;

      FOR v_rec IN (SELECT * FROM TMP_OBLIGPIF_ASOCIAT ORDER BY CODOBLIGPIF) LOOP
        SELECT NEXTVAL('SEQ_OBLIGPIF_CODOBLIGPIF') INTO vCOD;

        UPDATE TMP_STINGERE SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;

        INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CODNPARCAUT, CODANALIZANOD, TVANEDED, PROCTVA, COEFPROVIZION, TVAAFISAT, DINCARETVA, RESTTVA)
        VALUES(vCOD, v_rec.CODGENERAL, v_rec.TERMEN, v_rec.VALOARE, v_rec.REST, v_rec.CODPART, v_rec.ICONT, v_rec.TIPPLATA, v_rec.MAJORARI, v_rec.SEMNIFICATIE, v_rec.TIP, v_rec.CONTBANKTRANZACTIE, v_rec.CODOBLIGASOCIAT, v_rec.VALOAREAFISATA, V_REC.CODGEST, V_REC.CODNPARCAUT, v_Rec.CODANALIZANOD, V_REC.TVANEDED, V_REC.PROCTVA, V_REC.COEFPROVIZION, V_REC.TVAAFISAT, V_REC.DINCARETVA, V_REC.RESTTVA);
      END LOOP;

      FOR v_rec IN (SELECT * FROM TMP_STINGERE) LOOP
        SELECT NEXTVAL('SEQ_STINGERE_CODSTINGERE') INTO VCod;

        INSERT INTO STINGERE(CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE, CODPLATA1, DINCARETVA)
        VALUES(vCod, v_rec.CODSTINSPIF, v_rec.CODSTINGATORPIF, v_rec.VALOARE, V_REC.CODPLATA1, V_REC.DINCARETVA);
      END LOOP;

      INSERT INTO JURNAL1(CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD, CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT, CODANALIZANOD)
      (SELECT NEXTVAL('SEQ_JURNAL1_CODJURNAL1'), RECID, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD, CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT, CODANALIZANOD
       FROM TMP_JURNAL1
      );

      INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT, CODANALIZANOD)
      (SELECT NEXTVAL('SEQ_JURNAL_CODJURNAL'), RECID, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT, CODANALIZANOD
       FROM TMP_JURNAL
      );
    END IF;

    UPDATE OBLIGPIF O
    SET
    REST    = (CASE WHEN  VALOARE &gt;= 0 THEN VALOARE - COALESCE( (SELECT SUM( VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
                    WHEN  VALOARE &lt;  0 THEN VALOARE + COALESCE( (SELECT SUM( VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)

               END ) ,
    RESTTVA = (CASE WHEN  VALOARE &gt;= 0 THEN COALESCE( DINCARETVA, 0) - COALESCE( (SELECT SUM( COALESCE( DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
                    WHEN  VALOARE &lt;  0 THEN COALESCE( DINCARETVA, 0) + COALESCE( (SELECT SUM( COALESCE( DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)

               END )
    WHERE
      O.CODOBLIGPIF IN (SELECT CODSTINSPIF FROM TMP_STINGERE
                        union
                        SELECT CODSTINSPIF FROM TMP_STINGERE_INITIAL
                        union
                        SELECT CODOBLIGPIF AS CODSTINSPIF FROM TMP_OBLIGPIF_INITIAL WHERE SEMNIFICATIE IN (310, 410, 500, 600, 800, 801)
                       );

    FOR V_REC IN (SELECT OI.VALOARE, OI.CODTRANSA FROM TMP_OBLIGPIF_INITIAL OI WHERE OI.SEMNIFICATIE = 801 AND  COALESCE( OI.CODTRANSA, 0) &lt;&gt; 0
                  union
                  SELECT OI.VALOARE, OI.CODTRANSA FROM TMP_OBLIGPIF OI WHERE OI.SEMNIFICATIE = 801 AND  COALESCE( OI.CODTRANSA, 0) &lt;&gt; 0
                 )
    LOOP
      UPDATE OBLIGPIF
      SET
      RESTTRANSA = VALOARE - COALESCE( (SELECT SUM( O.VALOARE * COALESCE( G.CURS, 1) / COALESCE( T1.CURS, 1))
                                        FROM OBLIGPIF O, GENERAL G, TREZOR1 T1
                                        WHERE CODTRANSA = V_REC.CODTRANSA AND  G.CODGENERAL = O.CODGENERAL AND  T1.CODTREZOR1 = G.CODDOC
                                       ), 0)
      WHERE CODOBLIGPIF = V_REC.CODTRANSA;
    END LOOP;

    IF TIPDOCCASABANCA IN (30, 31) THEN
      BEGIN
        SELECT CREDIT INTO aCREDIT FROM NBANKCONT WHERE CODBANKCONT = aCODBANKCONT;
      EXCEPTION WHEN OTHERS THEN
        aCREDIT := 0;
      END;

      IF  aCREDIT = 1 THEN
        FOR V_REC IN (SELECT OI.CODOBLIGPIF FROM TMP_OBLIGPIF_INITIAL OI WHERE OI.SEMNIFICATIE = 800
                      union
                      SELECT OI.CODOBLIGPIF FROM TMP_OBLIGPIF OI WHERE OI.SEMNIFICATIE = 800
                     )
        LOOP
          UPDATE OBLIGPIF
          SET
          RESTTRANSA = VALOARE - COALESCE( (SELECT SUM( O.VALOARE * COALESCE( G.CURS, 1) / COALESCE( T1.CURS, 1))
                                            FROM OBLIGPIF O, GENERAL G, TREZOR1 T1
                                            WHERE CODTRANSA = V_REC.CODOBLIGPIF AND  G.CODGENERAL = O.CODGENERAL AND  T1.CODTREZOR1 = G.CODDOC
                                           ), 0)
          WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
        END LOOP;
      END IF;
    END IF;

    UPDATE OBLIGPIF O
    SET
    REST = (CASE WHEN ((O.SEMNIFICATIE IN (310, 410, 500, 600, 330, 430)) OR (O.SEMNIFICATIE IN (800, 801) AND COALESCE(CONTBANKTRANZACTIE, 0) &lt;&gt; 0)) AND  O.VALOARE &gt;= 0
                   THEN O.VALOARE - COALESCE( (SELECT SUM( VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
                 WHEN ((O.SEMNIFICATIE IN (310, 410, 500, 600, 330, 430)) OR (O.SEMNIFICATIE IN (800, 801) AND COALESCE(CONTBANKTRANZACTIE, 0) &lt;&gt; 0)) AND  O.VALOARE &lt; 0
                   THEN O.VALOARE + COALESCE( (SELECT SUM( VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
                 WHEN O.SEMNIFICATIE NOT IN (310, 410, 500, 600, 800, 801, 1100, 1101, 330, 430) THEN 0
                 WHEN O.SEMNIFICATIE IN (800, 801) AND  COALESCE( CONTBANKTRANZACTIE, 0) = 0     THEN 0
                 WHEN O.SEMNIFICATIE IN (1100, 1101)                                             THEN O.VALOARE
            END )
    WHERE
      O.CODGENERAL IN (SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = TIPDOCCASABANCA AND CODDOC IN (SELECT CODTREZOR1 FROM TREZOR1 WHERE CODTREZOR = RECID));

    FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP
      SELECT COUNT( *)
      INTO NR
      FROM NCONTRUL
      WHERE CODCONT = V_REC.CODCONT AND  AN = TO_NUMBER(current_setting('PKG_GLOBALS.ANLUCRU', true),'999999999999999999') AND  LUNA = TO_NUMBER(current_setting('PKG_GLOBALS.LUNALUCRU', true),'999999999999999999');

      IF  NR = 0 THEN
        INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
        VALUES(NEXTVAL('SEQ_NCONTRUL_CODCONTRUL'), V_REC.CODCONT, 0, 0, 0, 0, 0, 0, 0, 0, TO_NUMBER(current_setting('PKG_GLOBALS.ANLUCRU', true),'999999999999999999'), TO_NUMBER(current_setting('PKG_GLOBALS.LUNALUCRU', true),'999999999999999999'));
      END IF;

      UPDATE NCONTRUL
      SET
      RULAJCD      = RULAJCD      + (CASE WHEN  V_REC.TIP = 'D' THEN V_REC.VALOARE  ELSE 0 END ) ,
      RULAJCC      = RULAJCC      + (CASE WHEN  V_REC.TIP = 'C' THEN V_REC.VALOARE  ELSE 0 END ) ,
      RULAJVCD     = RULAJVCD     + (CASE WHEN  V_REC.TIP = 'D' THEN V_REC.VALOAREV ELSE 0 END ) ,
      RULAJVCC     = RULAJVCC     + (CASE WHEN  V_REC.TIP = 'C' THEN V_REC.VALOAREV ELSE 0 END ) ,
      RULAJC_IFRS  = RULAJC_IFRS  + V_REC.VALOARE_IFRS,
      RULAJVC_IFRS = RULAJVC_IFRS + V_REC.VALOAREV_IFRS
      WHERE
       CODCONT = V_REC.CODCONT AND  AN = TO_NUMBER(current_setting('PKG_GLOBALS.ANLUCRU', true),'999999999999999999') AND  LUNA = TO_NUMBER(current_setting('PKG_GLOBALS.LUNALUCRU', true),'999999999999999999');

      IF  COALESCE( V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
        FOR V_REC_SUB IN (SELECT * FROM NCONTRUL
                          WHERE CODCONT = V_REC.CODCONT AND  AN = TO_NUMBER(current_setting('PKG_GLOBALS.ANLUCRU', true),'999999999999999999') AND  LUNA = TO_NUMBER(current_setting('PKG_GLOBALS.LUNALUCRU', true),'999999999999999999')
                         )
        LOOP
          SELECT COUNT( *) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND  SUBUNITATEA = V_REC.SUBUNITATEA;
          IF  NR = 0 THEN
            INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA)
            VALUES(NEXTVAL('SEQ_NCONTRULSUB_CODRULSUB'), V_REC_SUB.CODCONTRUL, 0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
          END IF;

          UPDATE NCONTRULSUB
          SET
          RULAJCD      = RULAJCD      + (CASE WHEN  V_REC.TIP = 'D' THEN V_REC.VALOARE  ELSE 0 END ) ,
          RULAJCC      = RULAJCC      + (CASE WHEN  V_REC.TIP = 'C' THEN V_REC.VALOARE  ELSE 0 END ) ,
          RULAJVCD     = RULAJVCD     + (CASE WHEN  V_REC.TIP = 'D' THEN V_REC.VALOAREV ELSE 0 END ) ,
          RULAJVCC     = RULAJVCC     + (CASE WHEN  V_REC.TIP = 'C' THEN V_REC.VALOAREV ELSE 0 END ) ,
          RULAJC_IFRS  = RULAJC_IFRS  + V_REC.VALOARE_IFRS,
          RULAJVC_IFRS = RULAJVC_IFRS + V_REC.VALOAREV_IFRS
          WHERE
           CODCONTRUL = V_REC_SUB.CODCONTRUL AND  SUBUNITATEA = V_REC.SUBUNITATEA;
        END LOOP;
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TREZOR1 WHERE CODTREZOR = RecId) LOOP
      IF (   V_REC.CARNETDOC &lt;&gt; 0)  AND (   V_REC.NRDOC &lt;&gt; 0)  THEN
        PERFORM PKG_CARNETEDOC_SOLVENUMARDOC( V_REC.CARNETDOC, (V_REC.NRDOC)::character varying);
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT O.VALOARE, O.CODOBLIGPIF, G.TVA, G.CURS
                  FROM TMP_OBLIGPIF O, TMP_GENERAL G
                  WHERE O.SEMNIFICATIE IN (900, 950, 901, 951) AND  G.CODGENERAL = O.CODGENERAL
                 )
    LOOP
      SELECT COALESCE( V_REC. VALOARE, 0) * CASE WHEN  COALESCE( V_REC.CURS, 0)=0 THEN 1 ELSE  COALESCE( V_REC.CURS, 0) END  - COALESCE( V_REC.TVA, 0)
      INTO aVALOARE;

      FOR V_CHELT1 IN (SELECT CA1.CODCHELTAVANS1, CA1.CODCHELTAVANS
                       FROM CHELTAVANS CA, CHELTAVANS1 CA1
                       WHERE CA.CODOBLIGPIF = V_REC.CODOBLIGPIF AND  CA1.CODCHELTAVANS = CA.CODCHELTAVANS AND  VALOARE &lt;&gt; aVALOARE
                      )
      LOOP
        UPDATE CHELTAVANS1 SET VALOARE = aVALOARE WHERE CODCHELTAVANS1 = V_CHELT1.CODCHELTAVANS1;
        UPDATE JURNAL1     SET DIRTY   = 1        WHERE CODDOC = V_CHELT1.CODCHELTAVANS AND TIPDOC IN (52, 106);
      END LOOP;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_STINGERE_INITIAL WHERE COALESCE( CODPLATA1, 0) &lt;&gt; 0) LOOP
      UPDATE PLATI1
      SET
      STINSA = 0,
      REST   = VALOARE
      WHERE
       CODPLATA1 = V_REC.CODPLATA1;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_STINGERE WHERE COALESCE( CODPLATA1, 0) &lt;&gt; 0) LOOP
      UPDATE PLATI1
      SET
      STINSA = 1,
      REST   = 0
      WHERE
       CODPLATA1 = V_REC.CODPLATA1;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_TREZOR1 WHERE COALESCE( CODSERTAR, 0) &lt;&gt; 0) LOOP
      UPDATE NSERTAR SET DEPUS = 1 WHERE CODSERTAR = V_REC.CODSERTAR;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_TREZOR1 WHERE COALESCE( CODPLATA1, 0) &lt;&gt; 0) LOOP
      UPDATE PLATI1 SET STINSA = 1 WHERE CODPLATA1 = V_REC.CODPLATA1;
    END LOOP;

    PERFORM PKG_GLOBALS_MarkDirtyJurnal();
    PERFORM PKG_TREZOR_UPDATE_VALTRANZ_STINGERI( RECID);
    PERFORM NotifyModif( Operation, RecId, 'TREZOR');

    IF (   TO_NUMBER(current_setting('PKG_TREZOR.CARNETDOC_I', true),'999999999999999999') &lt;&gt; 0)  AND (   TO_NUMBER(current_setting('PKG_TREZOR.NRDOC_I', true),'999999999999999999') &lt;&gt; 0)  AND (   ACARNETDOC &lt;&gt; TO_NUMBER(current_setting('PKG_TREZOR.CARNETDOC_I', true),'999999999999999999') OR  ANRDOC &lt;&gt; TO_NUMBER(current_setting('PKG_TREZOR.NRDOC_I', true),'999999999999999999'))
    THEN
      PERFORM PKG_CARNETEDOC_RELEASENUMARDOC( TO_NUMBER(current_setting('PKG_TREZOR.CARNETDOC_I', true),'999999999999999999'), TO_NUMBER(current_setting('PKG_TREZOR.NRDOC_I', true),'999999999999999999'));
      PERFORM PKG_CARNETEDOC_COMPACTEAZAINTERVALE( TO_NUMBER(current_setting('PKG_TREZOR.CARNETDOC_I', true),'999999999999999999'));
    END IF;

    IF  ACARNETDOC &lt;&gt; 0 THEN
      PERFORM PKG_CARNETEDOC_SOLVENUMARDOC( ACARNETDOC, (ANRDOC)::character varying);
    END IF;

    IF TIPDOCCASABANCA IN (29, 30, 33) THEN
      PERFORM PKG_SAFT_UpdateTaxDecl(3, RecId);
    END IF;
    EXCEPTION WHEN OTHERS THEN
    BEGIN raise; END;
  END;
  PERFORM PKG_CFGTABLES_EXT_POSTRECORDS(TIPDOCCASABANCA, operation);
  PERFORM pkg_trezor_NotifyModifSoldFact();
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_total_stins_obligatie</obj_name>
  <obj_hashval>179d519b615b62a0ecba05df55d21da9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_total_stins_obligatie(INOUT wme_result numeric, INOUT acodobligpif numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  TOTAL double precision := 0;
begin
  SELECT SUM( VALOARE) INTO TOTAL FROM STINGERE WHERE CODSTINSPIF = aCODOBLIGPIF;

  WME_Result :=  TOTAL;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_total_stins_tva</obj_name>
  <obj_hashval>eaa53643a9423ea6193bd4103629531e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_total_stins_tva(INOUT wme_result numeric, INOUT acodobligpif numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  TOTAL double precision := 0;
begin
  SELECT SUM( COALESCE( G.TVA, 0))
  INTO TOTAL
  FROM STINGERE S, OBLIGPIF O, GENERAL G
  WHERE S.CODSTINSPIF = aCODOBLIGPIF AND  O.CODOBLIGPIF = S.CODSTINGATORPIF AND  G.CODGENERAL = O.CODGENERAL
    AND  (SELECT PKG_TREZOR_OPERAT_ANULAT_OK.WME_RESULT FROM PKG_TREZOR_OPERAT_ANULAT_OK(NULL, G.TIPDOC, G.CODDOC)) = 1;

  WME_Result :=  TOTAL;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_update_valtranz_stingeri</obj_name>
  <obj_hashval>f786180fc6fc4f27fa8294ea5c658bbb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_update_valtranz_stingeri(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC      RECORD;
  BANCASITV  numeric := 0;
  MONEDASITV numeric := 0;
begin
  BEGIN
    SELECT fnc_GetValConstantaLucru('BancaSitV') INTO BANCASITV;
  EXCEPTION WHEN OTHERS THEN
    BANCASITV := 0;
  END;

  BEGIN
    SELECT fnc_GetValConstantaLucru('MonedaSitV') INTO MONEDASITV;
  EXCEPTION WHEN OTHERS THEN
    MONEDASITV := 0;
  END;

  FOR V_REC IN (SELECT CODSTINGERE,
                       S.VALOARE * CASE WHEN  COALESCE( GSTINS.CURS, 0)=0 THEN 1
                                        ELSE  COALESCE( GSTINS.CURS, 0)
                                   END  / (SELECT PKG_MONEDE_GETCURSMONEDA.WME_RESULT
                                           FROM PKG_MONEDE_GETCURSMONEDA(NULL, MONEDASITV, BANCASITV, TO_CHAR( I.DATADOC, 'DD.MM.YYYY'))
                                          ) AS VALOAREV
                FROM STINGERE S, OBLIGPIF O_STG, GENERAL G_STG, TREZOR1 T1, OBLIGPIF OSTINS, GENERAL GSTINS, IESIRI I
                WHERE  S.CODSTINGATORPIF = O_STG.CODOBLIGPIF AND  G_STG.CODGENERAL = O_STG.CODGENERAL AND G_STG.TIPDOC IN (29, 30, 31, 33) AND  G_STG.CODDOC = T1.CODTREZOR1
                  AND  T1.CODTREZOR = RECID AND  S.CODSTINSPIF = OSTINS.CODOBLIGPIF AND  OSTINS.SEMNIFICATIE = 200 AND  GSTINS.CODGENERAL = OSTINS.CODGENERAL
                  AND  GSTINS.TIPDOC = I.TIPDOC AND  GSTINS.CODDOC = I.CODIES
               )
  LOOP
    UPDATE STINGERE SET VALTRANZC = V_REC.VALOAREV WHERE CODSTINGERE = V_REC.CODSTINGERE;
  END LOOP;

  FOR V_REC IN (SELECT CODSTINGERE, S.VALOARE * CASE WHEN  COALESCE( GSTINS.CURS, 0)=0 THEN 1
                                                     ELSE  COALESCE( GSTINS.CURS, 0)
                                                END  / (SELECT PKG_MONEDE_GETCURSMONEDA.WME_RESULT
                                                        FROM PKG_MONEDE_GETCURSMONEDA(NULL, MONEDASITV, BANCASITV, TO_CHAR( I.DATADOC, 'DD.MM.YYYY'))
                                                       ) AS VALOAREV
                FROM STINGERE S, OBLIGPIF O_STG, GENERAL G_STG, TREZOR1 T1, OBLIGPIF OSTINS, GENERAL GSTINS, INTRARI I
                WHERE  S.CODSTINGATORPIF = O_STG.CODOBLIGPIF AND  G_STG.CODGENERAL = O_STG.CODGENERAL AND G_STG.TIPDOC IN (29, 30, 31, 33)
                  AND  G_STG.CODDOC = T1.CODTREZOR1 AND  T1.CODTREZOR = RECID AND  S.CODSTINSPIF = OSTINS.CODOBLIGPIF AND  OSTINS.SEMNIFICATIE = 100
                  AND  GSTINS.CODGENERAL = OSTINS.CODGENERAL AND  GSTINS.TIPDOC = I.TIPDOC AND  GSTINS.CODDOC = I.CODINTR
               )
  LOOP
    UPDATE STINGERE SET VALTRANZF = V_REC.VALOAREV WHERE CODSTINGERE = V_REC.CODSTINGERE;
  END LOOP;

  FOR V_REC IN (SELECT CODSTINGERE, S.VALOARE * CASE WHEN  COALESCE( GSTINS.CURS, 0)=0 THEN 1
                                                     ELSE  COALESCE( GSTINS.CURS, 0)
                                                END  / (SELECT PKG_MONEDE_GETCURSMONEDA.WME_RESULT
                                                        FROM PKG_MONEDE_GETCURSMONEDA(NULL, MONEDASITV, BANCASITV, TO_CHAR( D.DATADOC, 'DD.MM.YYYY'))
                                                       ) AS VALOAREV
                FROM STINGERE S, OBLIGPIF O_STG, GENERAL G_STG, TREZOR1 T1, OBLIGPIF OSTINS, GENERAL GSTINS, DVI D
                WHERE  S.CODSTINGATORPIF = O_STG.CODOBLIGPIF AND  G_STG.CODGENERAL = O_STG.CODGENERAL AND G_STG.TIPDOC IN (29, 30, 31, 33)
                  AND  G_STG.CODDOC = T1.CODTREZOR1 AND  T1.CODTREZOR = RECID AND  S.CODSTINSPIF = OSTINS.CODOBLIGPIF AND  OSTINS.SEMNIFICATIE = 130
                  AND  GSTINS.CODGENERAL = OSTINS.CODGENERAL AND  GSTINS.TIPDOC = 5 AND  GSTINS.CODDOC = D.CODDVI
               )
  LOOP
    UPDATE STINGERE SET VALTRANZF = V_REC.VALOAREV WHERE CODSTINGERE = V_REC.CODSTINGERE;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trigar_baga_in_trigar_modif</obj_name>
  <obj_hashval>a276e6b1d4ba0b70b0c10829d3dc98e5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trigar_baga_in_trigar_modif(auserid numeric, acodmaster numeric, acod numeric, atablename character varying, afieldname character varying, aoldvalue character varying, anewvalue character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  insert into trigar_modif(
  DATAMODIF,
  USERMODIF,
  CODMASTER,
  COD,
  TABLENAME,
  FIELDNAME,
  OLDVALUE,
  NEWVALUE,
  CODMODIF )
  values (current_date, aUserID, aCodMaster, aCod, aTableName, aFieldName, aOldValue, aNewValue, nextval('seq_trigar_modif'));
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trigar_get_ddl</obj_name>
  <obj_hashval>b6fa665267002f49c6e76a5301f224d2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trigar_get_ddl(INOUT wme_result character varying, INOUT recid numeric, INOUT pprefix character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  VREC          RECORD;
  s_Prefix      varchar;
  v_Tip         numeric;
  s_TableName   varchar;
  v_Operatie    numeric;
  v_Moment      numeric;
  c_Trig        varchar;
  c_Variabile   varchar;
  s_MasterField varchar;
  s_KeyField    varchar;
  s_AuxCompare  varchar;
  s_AuxInsert   varchar;
  c_DDL         varchar;
  sSchema       varchar;
begin
  --Bogdan 15.03.2022 - 53501 marire campuri OLDVALUE si NEWVALUE (Trigar_Modif) din 30 in 100
  --Adina 02.06.2021 - scos upper din information_schema si add sSchema
  --Florin 21.12.2020 - fixat #41755
  --Florin 25.01.2021 - fixat #42438
  sSchema := Lower(current_setting('PKG_GLOBALS.FIRMANAME', true));
  IF NULLIF(sSchema, '') IS NULL THEN
    sSchema := public.get_schema();
  END IF;

  s_Prefix := Trim( pPrefix);
  IF s_Prefix IS NOT NULL THEN
    IF  SubStr(s_Prefix, -1) &lt;&gt; '.' THEN
      s_Prefix := coalesce(s_Prefix,'') || '.';
    END IF;
  END IF;

  BEGIN
    SELECT t.Tip, t.TableName, t.Operatie, t.Moment, t.Variabile, t.Trig, t.MasterField, c.Column_Name
    INTO v_Tip, s_TableName, v_Operatie, v_Moment, c_Variabile, c_Trig, s_MasterField, s_KeyField
    FROM trigar t
         LEFT JOIN information_schema.columns c ON c.table_schema = sSchema AND c.table_name = lower(t.TableName) AND c.ordinal_position = 1
    WHERE t.codtrigar = RecId;
  EXCEPTION WHEN no_data_found THEN
    v_Tip := 0;
  END;

  IF  v_Tip = 1 THEN
    IF s_MasterField IS NULL THEN
      s_MasterField := s_KeyField;
    END IF;

    c_DDL := 'CREATE OR REPLACE TRIGGER ' || coalesce(s_Prefix,'') || 'WME_' || coalesce(s_TableName,'') || '_' || coalesce(RecId::varchar ,'') || coalesce(Chr(13),'') || '  after update on ' || coalesce(s_Prefix,'') || coalesce(s_TableName,'') || coalesce(Chr(13),'') || '  for each row' || coalesce(Chr(13),'') || 'declare' || coalesce(Chr(13),'') || 'begin';

    FOR vRec IN (SELECT t1.FieldName, tc.Data_Type
                 FROM trigar t
                     INNER JOIN trigar1                    t1 ON  t1.CodTrigar  = t.CodTrigar
                     LEFT  JOIN information_schema.COLUMNS tc ON  tc.table_schema = sSchema AND tc.table_name = lower(t.TableName) AND tc.column_name = lower(t1.FieldName)
                 WHERE t.CodTrigar = RecId
                 ORDER BY codtrigar1
                )
    LOOP
      IF vRec.Data_Type IN ('BLOB', 'CLOB') THEN
        s_AuxCompare := 'dbms_lob.compare(:New.' || coalesce(vRec.FieldName,'') || ',:Old.' || coalesce(vRec.FieldName,'') || ') &lt;&gt; 0';
        s_AuxInsert := 'NULL, NULL';
      ELSE
        s_AuxCompare := ':New.' || coalesce(vRec.FieldName,'') || ' &lt;&gt; :Old.' || coalesce(vRec.FieldName,'');
        s_AuxInsert := 'Substr(:Old.' || coalesce(vRec.FieldName,'') || ',1,100), Substr(:New.' || coalesce(vRec.FieldName,'') || ',1,100)';
      END IF;

      c_DDL := coalesce(c_DDL,'') || coalesce(Chr(13),'') || '  IF (:New.' || coalesce(vRec.FieldName,'') || ' is Null and :Old.' || coalesce(vRec.FieldName,'') || ' is not Null) ' || coalesce(Chr(13),'') || '  OR (:New.' || coalesce(vRec.FieldName,'') || ' is not Null and :Old.' || coalesce(vRec.FieldName,'') || ' is Null) ' || coalesce(Chr(13),'') || '  OR (' || coalesce(s_AuxCompare,'') || ')' || coalesce(Chr(13),'') || '  THEN ' || coalesce(Chr(13),'') || '    INSERT INTO trigar_modif (CodModif, DatAmodif, UserModif, Cod, CodMaster, TableName, FieldName, OldValue, NewValue)' || coalesce(Chr(13),'') || '    VALUES(NextVal(''SEQ_TRIGAR_MODIF'', current_date, GETUSERID, :Old.' || coalesce(s_KeyField,'') || ',:Old.' || coalesce(s_MasterField,'') || ', ''' || coalesce(s_TableName,'') || ''', ''' || coalesce(vRec.FieldName,'') || ''', ' || coalesce(s_AuxInsert,'') || ');' || coalesce(Chr(13),'') || '  END IF;';
    END LOOP;

    c_DDL := coalesce(c_DDL,'') || coalesce(Chr(13),'') || 'END WME_' || coalesce(s_TableName,'') || '_' || coalesce(RecId::varchar ,'') || ';';
  ELSIF v_Tip = 2 THEN
    c_DDL := 'CREATE OR REPLACE TRIGGER ' || coalesce(s_Prefix,'') || 'WME_' || coalesce(s_TableName,'') || '_' || coalesce(RecId::varchar ,'') || coalesce(Chr(13),'') || '  '
             || coalesce(CASE v_Moment WHEN 1 THEN 'before' ELSE 'after' END ,'') || ' '
             || coalesce(CASE v_Operatie WHEN 1 THEN 'insert' WHEN 2 THEN 'update' ELSE 'delete' END ,'') || ' on '
             || coalesce(s_Prefix,'') || coalesce(s_TableName,'') || coalesce(Chr(13),'') || '  for each row' || coalesce(Chr(13),'') || 'declare' || coalesce(Chr(13),'') || coalesce(c_Variabile,'') || coalesce(Chr(13),'') || 'begin' || coalesce(Chr(13),'') || coalesce(c_Trig,'') || coalesce(Chr(13),'') || 'END WME_' || coalesce(s_TableName,'') || '_' || coalesce(RecId::varchar ,'') || ';';
  END IF;

  WME_Result :=  c_DDL;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trigar_get_ddl_activ</obj_name>
  <obj_hashval>08e91c40864d8505be19f73be0fd9278</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trigar_get_ddl_activ(recid numeric, pprefix character varying)
 RETURNS text
 LANGUAGE plpgsql
AS $function$
DECLARE
  s_Prefix       VARCHAR(100);
  s_TableName    VARCHAR(100);
  c_DDL          text;
  sActiv         VARCHAR(50);
  vInactiv       NUMERIC(1);
BEGIN
  s_Prefix := Trim(pPrefix);
  IF s_Prefix IS NOT NULL THEN
    IF SubStr(s_Prefix, -1) &lt;&gt; '.' THEN
      s_Prefix := s_Prefix||'.';
    END IF;
  END IF;

  BEGIN
    SELECT t.TableName, coalesce(t.inactiv,0)
    INTO   s_TableName, vInactiv
    FROM trigar t
      LEFT JOIN user_tab_columns c ON c.table_name = Upper(t.TableName) AND c.column_id = 1
    WHERE t.codtrigar = RecId;
  EXCEPTION
    WHEN no_data_found THEN s_TableName := '';
  END;
  if Length(s_TableName) &gt; 0 then
    if vInactiv = 1 then
      sActiv := ' DISABLE';
    else
      sActiv := ' ENABLE';
    end if;
  end if;

  c_DDL := 'ALTER TRIGGER '||s_Prefix||'WME_'||s_TableName||'_'||RecId||sActiv;
  RETURN c_DDL;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trigar_messagetopers</obj_name>
  <obj_hashval>86eb08b147400cc1e2e25243bcdf54b2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trigar_messagetopers(acodpers numeric, mesaj character varying, sursamesaj character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCodUser numeric;
BEGIN
  --Adina 23.03.2021
  aCodUser := null;
  SELECT LOGONNAME INTO aCodUser FROM NPers WHERE CodPers = aCodPers;

  IF  Coalesce(acodUser, 0) &lt;&gt; 0 THEN
    PERFORM pkg_trigar_MessageToUser(acodUser, Mesaj, SursaMesaj);
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trigar_messagetouser</obj_name>
  <obj_hashval>a88a66e43cce3f156f5d3933821071f4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trigar_messagetouser(acoduser numeric, mesaj character varying, sursamesaj character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aUsername varchar;
BEGIN
  --Florin 05.04.2023 - sinc. Oracle (04.04.2023)
  --Adina 23.03.2021
  SELECT winmadmin.pkg_userfirme_getUserName(aCoduser) INTO aUsername;

  INSERT INTO winmadmin.mesaje(codmesaj, text, from_user, skemafirma, data, tip_mesaj)
  VALUES(nextval('winmadmin.seq_mesaje_codmesaj'), substr(Mesaj, 1, 4000), SursaMesaj, null, CURRENT_TIMESTAMP, 0);

  INSERT INTO winmadmin.mesaje1(codmesaj1, codmesaj, to_user)
  VALUES(nextval('winmadmin.seq_mesaje1_codmesaj1'), currval('winmadmin.seq_mesaje_codmesaj'), aUsername);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trigar_sendsms</obj_name>
  <obj_hashval>7b0690142af3d633491d9297343f6d7b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trigar_sendsms(nrtelefon character varying, mesaj character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  res        numeric;
  MSG_EROARE varchar;
BEGIN
  --Adina 23.03.2021
  res := (SELECT PKG_SMS_SEND_SMS_Full.WME_RESULT FROM PKG_SMS_SEND_SMS_Full(NULL,NRTELEFON, MESAJ, 'Automat', 0, 0, 0, 1, MSG_EROARE));
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trigar_smstopart</obj_name>
  <obj_hashval>6355469716fe981f4211e7a9a2d2d0b9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trigar_smstopart(acodpart numeric, mesaj character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  NrTelefon varchar;
BEGIN
  --Adina 23.03.2021
  SELECT Coalesce(Telefon, '?') INTO NrTelefon FROM NAgenda WHERE codpart = aCodPart;
  PERFORM pkg_trigar_SendSMS(NrTelefon, Mesaj);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trigar_smstopers</obj_name>
  <obj_hashval>629b73b3539c7f1155dcf4a49cb0680e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trigar_smstopers(acodpers numeric, mesaj character varying, nocommit numeric DEFAULT 0)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  NrTelefon varchar;
BEGIN
  --Adina 23.03.2021
  IF  Coalesce(aCodPers, 0) &gt; 0 THEN
    SELECT Coalesce(Telefon, '?') INTO NrTelefon FROM NAgenda a INNER JOIN NPERS p ON  p.Agenda = a.CodAgenda WHERE p.codpers = aCodPers;
    PERFORM pkg_trigar_SendSMS(NrTelefon, Mesaj);
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trigar_smstouser</obj_name>
  <obj_hashval>eede49076eb5e57a0386f276f8c8753f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trigar_smstouser(acoduser numeric, mesaj character varying, nocommit numeric DEFAULT 0)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCodPers numeric;
BEGIN
  --Adina 23.03.2021
  SELECT CodPers INTO aCodPers FROM NPers WHERE LOGONNAME = aCodUser limit 1;
  PERFORM pkg_trigar_SMSToPers(aCodPers, Mesaj, nocommit);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trigar_sp_deleterecord</obj_name>
  <obj_hashval>25be4aa3e609e7bf0eda47cb158f0c4f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trigar_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  tblName varchar;
  SSQL varchar;
BEGIN
  --Florin 25.01.2021 - fixat 42439
  PERFORM PKG_TRIGAR_SP_LOCKRECORD( RecId);
  SELECT tablename INTO TblName FROM TRIGAR WHERE CodTRIGAR = RecId;
  DELETE FROM TRIGAR1 WHERE CodTRIGAR = RecId;
  DELETE FROM TRIGAR  WHERE CodTRIGAR = RecId;
  SSQL := 'DROP TRIGGER IF EXISTS TWME_' || tblname || '_' || trunc(RecID)||' ON '||tblName||';';
  EXECUTE SSQL;
  SSQL := 'DROP FUNCTION IF EXISTS FWME_' || tblname || '_' || trunc(RecID)||';';
  EXECUTE SSQL;
  PERFORM NotifyModif( 2, RecId, 'TRIGAR');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trigar_sp_gotorecord</obj_name>
  <obj_hashval>62cfdeb19c1de9b676a741c3dec89a91</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trigar_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 27.07.2022 - sinc. Oracle (26.07.2022)
  INSERT INTO  TMP_TRIGAR(CodTRIGAR, tablename, masterField, masterTable, mainTable, trig, Variabile,
    Tip, operatie, initiator,destinatar,subiect,antet,final, moment,obs,inactiv)
  SELECT CodTRIGAR, tablename, masterField, masterTable, mainTable, trig, Variabile,
    Tip, operatie, initiator,destinatar,subiect,antet,final, moment,obs,coalesce(inactiv,0)
  FROM TRIGAR WHERE CodTRIGAR = RecId;

  INSERT INTO TMP_TRIGAR1(CodTRIGAR1, CodTRIGAR, FieldName)
  SELECT CodTRIGAR1, CodTRIGAR, FieldName FROM TRIGAR1 WHERE CodTRIGAR = RecId;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trigar_sp_lockrecord</obj_name>
  <obj_hashval>3aabd6ffe75f44e981269fc26ce1d28f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trigar_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CodTRIGAR INTO Tmp FROM TRIGAR WHERE CodTRIGAR = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trigar_sp_postrecords</obj_name>
  <obj_hashval>a569be4a124092177cb43bb08bc52fdd</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trigar_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC  RECORD;
  vRecNo NUMERIC := 0;
  vAn    NUMERIC := 0;
  vLuna  NUMERIC := 0;
  vCod   numeric;
  aSQL   varchar;
BEGIN
  --Florin 27.07.2022 - sinc. Oracle (26.07.2022)
  IF  Operation = 0 THEN
    SELECT CodTRIGAR INTO RecId FROM TMP_TRIGAR;

    UPDATE TRIGAR SET (  tablename, masterField, masterTable, mainTable, trig, Variabile, Tip, operatie, initiator, destinatar, subiect, antet, final, moment, obs, inactiv)
    = ( SELECT  tablename, masterField, masterTable, mainTable, trig, Variabile, Tip, operatie, initiator, destinatar, subiect, antet, final, moment, obs, inactiv FROM TMP_TRIGAR)
      where CODTRIGAR = RECID;

    DELETE FROM TRIGAR1 WHERE CodTRIGAR = RecId and CodTRIGAR1 NOT IN (SELECT CodTRIGAR1 FROM TMP_TRIGAR1);

    FOR v_rec IN (SELECT * FROM TMP_TRIGAR1 WHERE CodTRIGAR1 &gt; 0) LOOP
      UPDATE TRIGAR1 SET FIELDNAME = V_REC.FIELDNAME WHERE CodTRIGAR1 = v_rec.CodTRIGAR1;
    END LOOP;

    INSERT INTO TRIGAR1(CodTRIGAR1, CodTRIGAR, FieldName)
    SELECT NEXTVAL('SEQ_TRIGAR1_CODTRIGAR1'), RecId, FieldName FROM TMP_TRIGAR1 WHERE CodTRIGAR1 &lt; 0;
  ELSE
    SELECT NEXTVAL('SEQ_TRIGAR_CODTRIGAR') INTO RecId;

        INSERT INTO TRIGAR(CodTRIGAR, tablename, masterField, masterTable, mainTable, trig, Variabile, Tip, operatie, initiator, destinatar, subiect, antet, final, moment, obs, inactiv )
        SELECT  RecId , tablename, masterField, masterTable, mainTable, trig, Variabile, Tip, operatie, initiator, destinatar, subiect, antet,final, moment, obs, inactiv
        from tmp_trigar;

    INSERT INTO TRIGAR1(CodTRIGAR1, CodTRIGAR, FieldName)
    SELECT NEXTVAL('SEQ_TRIGAR1_CODTRIGAR1'), RecId, FieldName FROM TMP_TRIGAR1;
  END IF;

  PERFORM NotifyModif( Operation, RecId, 'TRIGAR');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trigar_tasktouser</obj_name>
  <obj_hashval>fa9ae0c332332c098c9bb0c7b5b2842c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trigar_tasktouser(acoduser numeric, acodpart numeric, aproblema character varying, sursamesaj character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aUsername varchar;
  TaskFirma numeric;
BEGIN
  --Adina 23.03.2021
  SELECT COALESCE(fnc_GetValConstanta('TaskFirma', getANLUCRU(), getlunalucru()), '0') INTO TaskFirma;
  SELECT winmadmin.pkg_userfirme_getUserName(aCoduser) INTO ausername;

  IF  TaskFirma = 2 THEN
    INSERT INTO SETTASK(CODTASK, PROBLEMA, Subunitatea, OBSERVATII, PROIECT, DESTINATAR, EXECUTANT, USERNAME, MESAJCATRE, TERMEN, DATATASK, DOMENIU, TIP, PRIORITATE, CODFIRMA, CODPART)
    VALUES(NEXTVAL('SEQ_SETTASK_CODTASK'), aPROBLEMA, 1, 'AUTOMAT', SursaMesaj, 'FIRMA', aUSERNAME, current_setting('PKG_GLOBALS.USERNAME', true), aUSERNAME, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'ORA', 0, 1, current_setting('PKG_GLOBALS.CODFIRMA', true)::numeric, aCodPArt);
  ELSE
    INSERT INTO WINMADMIN.SETTASK(CODTASK, PROBLEMA, OBSERVATII, PROIECT, DESTINATAR, EXECUTANT, USERNAME, MESAJCATRE, TERMEN, DATATASK, DOMENIU, TIP, PRIORITATE, CODFIRMA, CODPART)
    VALUES((SELECT PKG_USERFIRME_getSeqNextVal.WME_RESULT FROM PKG_USERFIRME_getSeqNextVal(NULL,'Seq_SETTASK_CODTASK')), aPROBLEMA, 'AUTOMAT', SursaMesaj, 'FIRMA', aUSERNAME, current_setting('PKG_GLOBALS.USERNAME', true), aUSERNAME, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'ORA', 0, 1, current_setting('PKG_GLOBALS.CODFIRMA', true)::numeric, aCodPArt);
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tvaserv_sp_gotorecord</obj_name>
  <obj_hashval>fd974618ad4f86cb6e1f12a8976a2089</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tvaserv_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aANSFARSIT   NUMERIC(4);
  aLUNASFARSIT NUMERIC(2);
  nrInreg1     NUMERIC;
  V_REC        record;
BEGIN
  --Florin 24.11.2022 - sinc. Oracle
  INSERT INTO TMP_TVASERV(CODTVASERV,DENUMIRE,CODTARA,TIPCOTA,PROCENT,CODCONT,SIMBOL)
  (SELECT CODTVASERV,DENUMIRE,CODTARA,TIPCOTA,PROCENT,CODCONT,SIMBOL
  FROM TVASERV WHERE CodTVASERV = RecId);

   -- Detail TVASERV1
  INSERT INTO  TMP_TVASERV1 (CODTVASERV1,  CODTVASERV, CODCONT, ANSTART, LUNASTART, ALSTART, ALSTOP )
    ( SELECT CODTVASERV1,  CODTVASERV, CODCONT, ANSTART, LUNASTART, ALSTART, ALSTOP
      FROM TVASERV1 WHERE CodTVASERV = RecId);
  aANSFARSIT := 0; aLUNASFARSIT := 0;
  FOR V_REC IN (SELECT CODTVASERV1, ANSTART, LUNASTART FROM TMP_TVASERV1 ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
    IF (aANSFARSIT &lt;&gt; 0)AND(aLUNASFARSIT &lt;&gt; 0) THEN
      UPDATE TMP_TVASERV1
      SET
        ANSFARSIT   = aANSFARSIT,
        LUNASFARSIT = aLUNASFARSIT
       WHERE
       CODTVASERV1 = V_REC.CODTVASERV1;
    END IF;
    select newan, newluna into aANSFARSIT, aLUNASFARSIT FROM  PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, aANSFARSIT, aLUNASFARSIT);
  END LOOP;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tvaserv_sp_postrecords</obj_name>
  <obj_hashval>e56973d16175ff7bb825a67ccf07f2cd</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tvaserv_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  v_rec record;
  tRecId NUMERIC;
BEGIN
  --Florin 28.11.2022 - sinc. Oracle
  --Florin 18.01.2022 - sinc. Oracle
  delete from tmp_manevra;
  IF Operation = 0 then
    select codtvaserv into recid from tmp_tvaserv;
    UPDATE TVASERV
    SET (DENUMIRE,CODTARA,TIPCOTA,PROCENT,CODCONT,SIMBOL) = (SELECT DENUMIRE,CODTARA,TIPCOTA,PROCENT,CODCONT,SIMBOL FROM TMP_TVASERV)
    WHERE CodTVASERV = RecId;
  -- Detail NTVA1
    for v_rec in (select * from TVASERV1
      where CODTVASERV = RecId
      and (CODTVASERV1 not in (Select CODTVASERV1 from TMP_TVASERV1))) LOOP
        PERFORM pkg_tvaserv_makeJurnalDirty(RecId,  v_rec.alstart,  v_rec.alstop);
      END LOOP;
    DELETE FROM TVASERV1 where CODTVASERV = RecId and CODTVASERV1 not in (Select CODTVASERV1 from TMP_TVASERV1);
    for v_rec in (
      SELECT CODCONT, ANSTART, LUNASTART, ALSTART, ALSTOP FROM TMP_TVASERV1 WHERE CODTVASERV1 &lt; 0
      ) LOOP
        tRecId := Nextval('SEQ_TVASERV1_CODTVASERV1');
        INSERT INTO TVASERV1 ( CODTVASERV1,  CODTVASERV, CODCONT, ANSTART, LUNASTART, ALSTART, ALSTOP )
        VALUES( tRecId , RecId , v_rec.CODCONT, v_rec.ANSTART, v_rec.LUNASTART, v_rec.ALSTART, v_rec.ALSTOP);
        INSERT INTO tmp_manevra values(tRecId);
      END LOOP;

    FOR v_rec IN ( SELECT * FROM TMP_TVASERV1 WHERE NVL(CODTVASERV1,-1) &gt; 0 ORDER BY CODTVASERV1 ) LOOP
      SELECT  CASE WHEN CODCONT = v_rec.CODCONT THEN 0 ELSE 1 END , anstart, lunastart INTO vRecNo,vAn,vLuna
      FROM TVASERV1 WHERE CODTVASERV1 = COALESCE(v_rec.CODTVASERV1,0);
      IF (vRecNo &gt; 0) THEN
        IF (v_rec.anstart = vAn) and (v_rec.lunastart = vLuna) THEN
          UPDATE TVASERV1 SET CODCONT = v_rec.CODCONT WHERE CODTVASERV1 = v_rec.CODTVASERV1;
        ELSE
          INSERT INTO TVASERV1 ( CODTVASERV1,  CODTVASERV, CODCONT, ANSTART, LUNASTART, ALSTART, ALSTOP )
          VALUES (NextVal('SEQ_TVASERV1_CODTVASERV1'),RecId,v_rec.CODCONT,v_rec.ANSTART,v_rec.LUNASTART,v_rec.ALSTART,v_rec.ALSTOP );
        END IF;
      END IF;
    END LOOP;

  ELSE --INSERT
    SELECT NEXTVAL('seq_TVASERV_CodTVASERV') INTO RecId;

    INSERT INTO TVASERV(CODTVASERV,DENUMIRE,CODTARA,TIPCOTA,PROCENT,CODCONT,SIMBOL)
    (SELECT RecId,DENUMIRE,CODTARA,TIPCOTA,PROCENT,CODCONT,SIMBOL
    FROM TMP_TVASERV);
    INSERT INTO TVASERV1 ( CODTVASERV1,  CODTVASERV, CODCONT, ANSTART, LUNASTART, ALSTART, ALSTOP )
    SELECT  Nextval('SEQ_TVASERV1_CODTVASERV1'), RecId , CODCONT, ANSTART, LUNASTART, ALSTART, ALSTOP
    FROM TMP_TVASERV1;
  END IF;
  CALL PRC_AL_REFRESH('TVASERV1', RecId);
  for v_rec in (select * from TVASERV1 where CODTVASERV1 in (select tm.codunic from tmp_manevra tm) ) LOOP
    PERFORM pkg_tvaserv_makeJurnalDirty(RecId,  v_rec.alstart,  v_rec.alstop);
    delete from tmp_manevra;
  END LOOP;
  perform NotifyModif(Operation, RecId, 'TVASERV');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_um_getspecificcantum</obj_name>
  <obj_hashval>c7fc9c8b24e85a7b55d6293dd6285ca4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_um_getspecificcantum(INOUT wme_result numeric, INOUT aum numeric, INOUT aum1 numeric, INOUT aprincipala numeric, INOUT aprincipala1 numeric, INOUT arel numeric, INOUT ad1 numeric, INOUT ad2 numeric, INOUT ad3 numeric, INOUT acant1 numeric, INOUT acoef numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  Rez   double precision;
  Coef  double precision;
  Cant1 double precision;
  Rel   double precision;
  D1    double precision;
  D2    double precision;
  D3    double precision;
begin
  D1   := aD1;
  D2   := aD2;
  D3   := aD3;
  Rez  := 0.0;
  Coef := aCoef;

  IF  Coef = 0 THEN Coef := 1; END IF;

  Cant1 := aCant1;
  Cant1 := Cant1 * (SELECT pkg_um_GetCoefUM.WME_RESULT FROM pkg_um_GetCoefUM(NULL, aUM1));
  Rel   := aRel;

  IF Rel IN (1, 2, 3, 7, 8, 9) THEN
    Rez := Cant1 * D1;
    IF Rel IN (2, 3, 8, 9) THEN
      Rez := Rez * D2;
      IF Rel IN (3, 9) THEN Rez := Rez * D3; END IF;
    END IF;
    Rez := Coef * Rez / (SELECT pkg_um_GetCoefUM.WME_RESULT FROM pkg_um_GetCoefUM(NULL, aUM));
  ELSE
    IF Rel IN (4, 5, 6, 10, 11, 12) THEN
      Rez := 0.0;
      IF  D1 &lt;&gt; 0.0 THEN Rez := Cant1 / D1; END IF;
      IF Rel IN (5, 6, 11, 12) THEN
        IF  D2 &lt;&gt; 0.0 THEN Rez := Rez / D2; END IF;
        IF Rel IN (6, 12) THEN
          IF  D3 &lt;&gt; 0.0 THEN Rez := Rez / D3; END IF;
        END IF;
      END IF;
      Rez := Rez / Coef / (SELECT pkg_um_GetCoefUM.WME_RESULT FROM pkg_um_GetCoefUM(NULL, aUM));
    END IF;
  END IF;

  WME_Result :=  Rez;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_um_getspecificcantum1</obj_name>
  <obj_hashval>74746f255253ac6737644801ade9b6ed</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_um_getspecificcantum1(INOUT wme_result numeric, INOUT aum numeric, INOUT aum1 numeric, INOUT aprincipala numeric, INOUT aprincipala1 numeric, INOUT arel numeric, INOUT ad1 numeric, INOUT ad2 numeric, INOUT ad3 numeric, INOUT acant numeric, INOUT acoef numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  Rez  double precision;
  Coef double precision;
  Cant double precision;
  Rel  double precision;
  D1   double precision;
  D2   double precision;
  D3   double precision;
begin
  D1   := aD1;
  D2   := aD2;
  D3   := aD3;
  Rez  := 0.0;
  Coef := aCoef;

  IF  Coef = 0 THEN Coef := 1; END IF;

  Cant := aCant;
  Cant := Cant * (SELECT pkg_um_GetCoefUM.WME_RESULT FROM pkg_um_GetCoefUM(NULL, aUM));
  Rel  := aRel;

  IF Rel IN (1, 2, 3, 7, 8, 9) THEN
    IF  D1 &lt;&gt; 0.0 THEN Rez := Cant / D1; END IF;
    IF Rel IN (2, 3, 8, 9) THEN
      IF  D2 &lt;&gt; 0.0 THEN Rez := Rez / D2; END IF;
      IF Rel IN (3, 9) THEN
        IF  D3 &lt;&gt; 0.0 THEN Rez := Rez / D3; END IF;
      END IF;
    END IF;
    Rez := Rez / Coef / (SELECT pkg_um_GetCoefUM.WME_RESULT FROM pkg_um_GetCoefUM(NULL, aUM1));
  ELSE
    IF Rel IN (4, 5, 6, 10, 11, 12) THEN
      Rez := Cant * D1;
      IF Rel IN (5, 6, 11, 12) THEN
        Rez := Rez * D2;
        IF Rel IN (6, 12) THEN Rez := Rez * D3; END IF;
      END IF;
      Rez := Rez * Coef / (SELECT pkg_um_GetCoefUM.WME_RESULT FROM pkg_um_GetCoefUM(NULL, aUM1));
    END IF;
  END IF;

  WME_Result :=  Rez;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_um_sp_deleterecord</obj_name>
  <obj_hashval>b9e86cf592506ce3d4eea1a2e0fd28f1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_um_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_UM_SP_LOCKRECORD( RecId);
  DELETE FROM num1 WHERE CodUM = recid;
  DELETE FROM NUM  WHERE CodUM = RecId;
  PERFORM NotifyModif( 2, RecId, 'NUM');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_um_sp_gotorecord</obj_name>
  <obj_hashval>352fe723684e71ce6fe2ccbccbc46164</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_um_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Bogdan 15.7.2022 - 54918 SAF-T: Nomenclator unitati de masura
  --Laura 05.10.2021 - sinc Oracle (05.10.2021)
  --Adina 04.03.2021 - sinc.Oracle din 04.03.2021
  --Bogdan 26.01.2021
  -- Master NUM
  INSERT INTO TMP_NUM (CodUM, Den_UM, Tip, Zecimale, TipUM, Coef, ActualizArt, CODUMSAFT, PARITATEUMSAFT)
  SELECT CodUM, Den_UM, Tip, Zecimale, COALESCE (TipUM, 0) , Coef, 0 ACTUALIZART, CODUMSAFT, PARITATEUMSAFT FROM NUM WHERE CodUM = RecId;

  UPDATE TMP_NUM
  SET
    (OBS, CodExtern, Den_EANCom, Den_Intrastat)
    =
    (SELECT OBS, CodExtern, Den_EANCom, Den_Intrastat FROM NUM1 WHERE CodUM = RecId and Secundara = 0);

  -- Detail NUM1
  INSERT INTO TMP_NUM1 (CodUM1, CodUM, Secundara, Den_UM1, Paritate, Zecimale, OBS, CodExtern, Den_EANCom, Den_Intrastat, Inactiv, CodUMSaft, ParitateUMSaft)
  SELECT CodUM1, CodUM, Secundara, Den_UM1, Paritate, Zecimale, OBS, CodExtern, Den_EANCom, Den_Intrastat, Inactiv, CodUMSaft, ParitateUMSaft
  FROM NUM1
  WHERE CodUM = RecId AND Secundara = 1;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_um_sp_insertrecord</obj_name>
  <obj_hashval>3487b30c02330ab7d63828d062fa834a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_um_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_NUM(CodUM) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_um_sp_lockrecord</obj_name>
  <obj_hashval>180fd4822cc4be32618d7cfc51f85c73</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_um_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CodUM INTO Tmp FROM NUM WHERE CodUM = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_um_sp_postrecords</obj_name>
  <obj_hashval>0b83c4c13b1784ec639d525a90b70e02</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_um_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC   RECORD;
  vRecNo  NUMERIC := 0;
  vAn     NUMERIC := 0;
  vLuna   NUMERIC := 0;
  Nr      numeric;
  aTipUM  numeric;
  aCoef   numeric;
  aActArt numeric;
begin
  --Bogdan 15.7.2022 - 54918 SAF-T: Nomenclator unitati de masura
  --Laura 05.10.2021 - sinc Oracle (05.10.2021)
  --Adina 04.03.2021 - sinc.Oracle din 04.03.2021
  --Bogdan 22.10.2020
  IF Operation = 0 THEN   -- UPDATE
    -- Master NUM
    SELECT CodUM, TipUM , Coef , ActualizArt
    INTO   RecId, aTipUM, aCoef, aActArt
    FROM TMP_NUM;

    UPDATE NUM1
    SET
      (Den_UM1, Zecimale, OBS, CodExtern, Den_EANCom, Den_Intrastat, CodUMSaft, ParitateUMSaft)
      =
      (SELECT Den_UM, Zecimale, OBS, CodExtern, Den_EANCom, Den_Intrastat, CodUMSaft, ParitateUMSaft FROM TMP_NUM)
    WHERE
      CodUM = RecId AND Secundara = 0;

    UPDATE NUM
    SET
      (Den_UM, Tip, Zecimale, TipUM, Coef, Codumsaft, Paritateumsaft)
      =
      (SELECT Den_UM, Tip, Zecimale, TipUM, Coef, Codumsaft, Paritateumsaft FROM TMP_NUM)
    WHERE
      CodUM = RecId;

    -- Detail NUM1
    DELETE FROM NUM1
    WHERE CodUM = RecId AND Secundara = 1 AND CodUM1 NOT IN (SELECT CodUM1 FROM TMP_NUM1 WHERE COALESCE (CodUM1, 0) &lt;&gt; 0);

    INSERT INTO NUM1 (CodUM1, CodUM, Secundara, Den_UM1, Paritate, Zecimale, OBS, CodExtern, Den_EANCom, Den_Intrastat, Inactiv, CodUMSaft, ParitateUMSaft)
    SELECT NEXTVAL ('SEQ_NUM1_CODUM1'), RecId, Secundara, Den_UM1, Paritate, Zecimale, OBS, CodExtern, Den_EANCom, Den_Intrastat, Inactiv, CodUMSaft, ParitateUMSaft
    FROM TMP_NUM1
    WHERE CodUM1 &lt; 0;

    FOR v_rec IN (SELECT * FROM TMP_NUM1 WHERE COALESCE (CodUM1, -1) &gt; 0 ORDER BY CodUM1) LOOP
      SELECT Count(*) INTO vRecNo FROM NUM1 WHERE CodUM1 = COALESCE (v_rec.CodUM1, 0);

      IF (vRecNo = 1) THEN
        UPDATE NUM1
        SET
          CodUM = RecId,
          Secundara      = v_rec.Secundara,
          Den_UM1        = v_rec.Den_UM1,
          Paritate       = v_rec.paritate,
          Zecimale       = v_rec.Zecimale,
          Obs            = v_rec.Obs,
          CodExtern      = v_rec.Codextern,
          Den_EANCom     = v_rec.Den_EANCom,
          Den_Intrastat  = v_rec.Den_Intrastat,
          Inactiv        = v_rec.Inactiv,
                    CodUMSaft      = v_rec.CodUMSaft,
                    ParitateUMSaft = v_rec.ParitateUMSaft
        WHERE
          CodUM1 = v_rec.CodUM1;
      END IF;
    END LOOP;

    IF aActArt = 1 AND aCoef &lt;&gt; 0 THEN
      IF aTipUM  = 1 THEN   -- masa
         update nartobj co
         set masa = 1 / aCoef
         from nart na
         where co.codarticol = na.codarticol and na.um=RecId;
      ELSIF aTipUM = 2 THEN   -- volum
         update nartobj co
         set volum = 1 / aCoef
         from nart na
         where co.codarticol = na.codarticol and na.um=RecId;
      END IF;
    END IF;
  ELSE    -- INSERT
    -- Master NUM
    SELECT NEXTVAL ('SEQ_NUM_CODUM') INTO RecId;

    INSERT INTO NUM (CodUM, Den_UM, Tip, Zecimale, TipUM, Coef, Codumsaft, Paritateumsaft)
    SELECT RecId, Den_UM, Tip, Zecimale, TipUM, Coef, Codumsaft, Paritateumsaft
    FROM TMP_NUM;

    -- Detail NUM1
    INSERT INTO NUM1 (CodUM1, CodUM, Secundara, Den_UM1, Paritate, Zecimale, OBS, CodExtern, Den_EANCom, Den_Intrastat, Inactiv, CodUMSaft, ParitateUMSaft)
    SELECT NEXTVAL ('SEQ_NUM1_CODUM1'), RecId, Secundara, Den_UM1, Paritate, Zecimale, OBS, CodExtern, Den_EANCom, Den_Intrastat, Inactiv, CodUMSaft, ParitateUMSaft
    FROM TMP_NUM1
    WHERE Secundara = 1;
  END IF;

  /* inregistrarea cu UM principala */
  SELECT COUNT(*) INTO Nr FROM NUM1 WHERE CodUM = RecID and Secundara = 0;

  IF Nr = 0 THEN
    INSERT INTO NUM1 (CodUM1, CodUM, Secundara, Den_UM1, Paritate, ZECIMALE, OBS, CodExtern, Den_EANCom, Den_Intrastat, CodUMSaft, ParitateUMSaft)
    SELECT NEXTVAL ('SEQ_NUM1_CODUM1'), RecId, 0, Den_UM, 1, ZECIMALE, OBS, CodExtern, Den_EANCom, Den_Intrastat, CodUMSaft, ParitateUMSaft
    FROM TMP_NUM;
  END IF;

  PERFORM NotifyModif (Operation, RecId, 'NUM');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_umsec_getcodumimplicita</obj_name>
  <obj_hashval>30f979c17b57dc30c2b4db253f45f4b9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_umsec_getcodumimplicita(INOUT wme_result numeric, INOUT acodumprincipala numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  CODUMSEC numeric := 0;
begin
  BEGIN
    SELECT CODUM1 INTO CODUMSEC FROM NUM1 WHERE CODUM = ACODUMPRINCIPALA AND  SECUNDARA = 0;
  EXCEPTION WHEN OTHERS THEN
    WME_Result :=  0;
    RETURN;
  END;

  WME_Result :=  COALESCE( CODUMSEC, 0);
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_umsec_getcodumprincipala</obj_name>
  <obj_hashval>0038948ac6731a8bad8f029e07ea301c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_umsec_getcodumprincipala(INOUT wme_result numeric, INOUT acodum1 numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  ACOD numeric;
begin
  BEGIN
    SELECT CODUM INTO ACOD FROM NUM1 WHERE CODUM1 = ACODUM1;
  EXCEPTION WHEN OTHERS THEN
    WME_Result :=  0;
    RETURN;
  END;

  WME_Result :=  COALESCE( ACOD, 0);
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_umsec_getdenum</obj_name>
  <obj_hashval>af27aff20e48b499aad74ed202f1fbf8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_umsec_getdenum(INOUT wme_result character varying, INOUT acodum numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  DEN varchar;
begin
  BEGIN
    SELECT DEN_UM INTO DEN FROM NUM WHERE CODUM = ACODUM;
  EXCEPTION WHEN OTHERS THEN
    DEN := ' ';
  END;

  WME_Result :=  COALESCE( DEN, ' ');
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_umsec_getg_codum1</obj_name>
  <obj_hashval>55f2e57ed402c5889b5a3e267888389c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_umsec_getg_codum1(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_UMSEC.g_codum1', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_umsec_getinfoumimplicita</obj_name>
  <obj_hashval>32edee6322c50c5520bd4fcd1a2ca2ec</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_umsec_getinfoumimplicita(INOUT acodum numeric, INOUT codumsec numeric, INOUT den character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  CODUMSEC := 0;
  DEN      := '';

  BEGIN
    SELECT CODUM1, DEN_UM1 INTO CODUMSEC, DEN FROM NUM1 WHERE CODUM = ACODUM AND  SECUNDARA = 0;
  EXCEPTION WHEN OTHERS THEN
    CODUMSEC := 0;
    DEN      := '';
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_umsec_getinfoumsec</obj_name>
  <obj_hashval>7ea05421bc7818bb96b417ec83ef6482</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_umsec_getinfoumsec(INOUT acodumsec numeric, INOUT den character varying, INOUT parit numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  DEN   := '';
  PARIT := 1;

  BEGIN
    SELECT DEN_UM1, PARITATE INTO DEN, PARIT FROM NUM1 WHERE CODUM1 = ACODUMSEC;
  EXCEPTION WHEN OTHERS THEN
    BEGIN
      DEN   := '';
      PARIT := 1;
    END;
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_umsec_getumsecdupaden</obj_name>
  <obj_hashval>8e6592dc9159bf4ae454f799723c8383</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_umsec_getumsecdupaden(INOUT acodum numeric, INOUT den character varying, INOUT acodumsec numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  ACODUMSEC := 0;

  BEGIN
    SELECT CODUM1 INTO aCODUMSec FROM NUM1 WHERE CODUM = ACODUM AND UPPER( DEN_UM1) LIKE DEN;
  EXCEPTION WHEN OTHERS THEN
    BEGIN
      ACODUMSEC := 0;
    END;
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_umsec_setg_codum1</obj_name>
  <obj_hashval>77562de019ef25a6e9cc630601563dd9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_umsec_setg_codum1(ag_codum1 numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_UMSEC.g_codum1',to_char(ag_codum1,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_umsec_sp_deleterecord</obj_name>
  <obj_hashval>a3fedaecc9d1172e8cb303e94d5c627a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_umsec_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_UMSEC_SP_LOCKRECORD( RECID);
  DELETE FROM NUM1 WHERE CODUM1 = RECID;
  PERFORM NotifyModif( 2, RecId, 'NUM1');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_umsec_sp_gotorecord</obj_name>
  <obj_hashval>1e17ae026de650ff23fd15c78988ecca</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_umsec_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Bogdan 15.7.2022 - 54918 SAF-T: Nomenclator unitati de masura
  INSERT INTO TMP_NUM1(CODUM1, CODUM, SECUNDARA, DEN_UM1, PARITATE, ZECIMALE, OBS, CodUMSaft, ParitateUMSaft)
  (SELECT CODUM1, CODUM, SECUNDARA, DEN_UM1, PARITATE, ZECIMALE, OBS, CodUMSaft, ParitateUMSaft FROM NUM1 WHERE CODUM1 = RECID);
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_umsec_sp_lockrecord</obj_name>
  <obj_hashval>4bbc57b9c2b355c2d4898c82c0b93c11</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_umsec_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMP numeric;
begin
  SELECT CODUM1 INTO TMP FROM NUM1 WHERE CODUM1 = RECID FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_umsec_sp_postrecords</obj_name>
  <obj_hashval>ea2fd32e6222e940925ed4a849c58f37</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_umsec_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  --Bogdan 15.7.2022 - 54918 SAF-T: Nomenclator unitati de masura
  IF  OPERATION = 0 THEN
    SELECT CODUM1 INTO RECID FROM TMP_NUM1;

    UPDATE NUM1
    SET
    (CODUM1, CODUM, SECUNDARA, DEN_UM1, PARITATE, ZECIMALE, OBS, CodUMSaft, ParitateUMSaft) = (SELECT CODUM1, CODUM, SECUNDARA, DEN_UM1, PARITATE, ZECIMALE, OBS, CodUMSaft, ParitateUMSaft FROM TMP_NUM1)
    WHERE
     CODUM1 = RECID;
  ELSE
    SELECT NEXTVAL('SEQ_NUM1_CODUM1') INTO RECID;

    INSERT INTO NUM1(CODUM1, CODUM, SECUNDARA, DEN_UM1, PARITATE, ZECIMALE, OBS, CodUMSaft, ParitateUMSaft)
    (SELECT RECID, CODUM, SECUNDARA, DEN_UM1, PARITATE, ZECIMALE, OBS, CodUMSaft, ParitateUMSaft FROM TMP_NUM1);
  END IF;

  PERFORM NotifyModif( Operation, RecId, 'NUM1');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_aduultimacitire</obj_name>
  <obj_hashval>0f387cce6e61899f264e3bbbe64df844</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_aduultimacitire(INOUT wme_result numeric, INOUT acodutilaj numeric, INOUT ptipindex numeric DEFAULT 0)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  vCod  numeric;
BEGIN
  --Florin 13.02.2023 - sinc. Oracle
  vCod := 0;
  FOR v_rec IN (SELECT codutilaj3 FROM utilaje3 WHERE codutilaj = aCodUtilaj and coalesce(tip_index, 0) = pTipIndex ORDER BY an , luna , databord) LOOP
    vCod := v_rec.codutilaj3;
  END LOOP;

  WME_Result :=  vCod;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_ct_monitor</obj_name>
  <obj_hashval>ecedcfc1e9fdba4b25d7b7d6408e1445</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_ct_monitor(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_UTILAJE.CT_MONITOR', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 'MON_53';
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_genutilaj</obj_name>
  <obj_hashval>681fc5c43ab4901a9017c88b4502f01b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_genutilaj(vcodobiect numeric, vum numeric, vcodpart numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  RecID numeric;
begin
  DELETE FROM tmp_utilaje;
  INSERT INTO tmp_utilaje(codutilaj, CodObiect, UM, CodPart) VALUES(0, vCodObiect, vUM, vCodPart);

  PERFORM PKG_UTILAJE_SP_POSTRECORDS( -1, RecId);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_getcodutilaj2c</obj_name>
  <obj_hashval>075d080b23053b675f6aa0677ae85824</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_getcodutilaj2c(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  WME_Result :=  TO_NUMBER((current_setting('PKG_UTILAJE.vCodUtilaj2C', true)),'999999999999999999');
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_getct_monitor</obj_name>
  <obj_hashval>bf99f51748d14a35a87365a16e5acd41</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_getct_monitor(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_UTILAJE.CT_MONITOR', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 'MON_53';
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_getdensectieinterventie</obj_name>
  <obj_hashval>dbf3ed4b548cc8f5f96ff970436b66ac</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_getdensectieinterventie(INOUT wme_result character varying, INOUT acodprodcomp numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCount numeric;
  aDen   varchar;
begin
  IF  aCodProdComp = 0 THEN
    WME_Result :=  '... nedefinit ...';
    RETURN;
  END IF;

  SELECT count( *)
  INTO acount
  FROM prodcomp pc INNER JOIN prodgest pg ON  pg.codprodcomp = pc.codprodcomp
  WHERE pc.codprodcomp = aCodProdComp;

  IF  acount = 1 THEN
    SELECT g.den_gest
    INTO aDen
    FROM prodcomp pc
        INNER JOIN prodgest pg ON  pg.codprodcomp = pc.codprodcomp
        INNER JOIN ngest    g  ON  g.codgest      = pg.codgest
    WHERE pc.codprodcomp = aCodProdComp;
  END IF;

  WME_Result :=  aDen;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_getlastapeluri</obj_name>
  <obj_hashval>d803be231bc9a4a68753d020f094f2aa</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_getlastapeluri(nrapeluri numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Adina 02.08.2021
  DELETE FROM TMP_APELTELEFON;

  INSERT INTO TMP_APELTELEFON(CODAPEL, IDAPEL, STARE, TELEFON, APELANT, DATAORA, PRELUAT, CLIENT, MODIFICAT)
  SELECT *
  FROM (SELECT CODAPEL, IDAPEL, STARE, TELEFON, APELANT, DATAORA, PRELUAT, CLIENT, 0
        FROM APELTELEFON
        ORDER BY DATAORA desc
       ) A_PG
  limit NRAPELURI;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_initutilajetipindex</obj_name>
  <obj_hashval>4967abca5d45eae6f52846f1de31dbb8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_initutilajetipindex(pcodutilaj numeric, pmaxindexnum numeric DEFAULT 1)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  existingNum NUMERIC(10);
  existingUM   numeric(20);
  existingPlafon NUMERIC(20,7);
  denIndex varchar(100);
BEGIN
  --Florin 14.02.2023 - sinc. Oracle
  --Florin 13.02.2023 - sinc. Oracle
  select count(*) into existingNum from TMP_UTILAJETIPINDEX;
  if existingNum &lt; pMaxIndexNum then
    for i in existingNum .. pMaxIndexNum-1 loop
      existingUM     := null;
      existingPlafon := null;
      denIndex := ' Index '|| i;
      if (i=0) then
        denIndex := 'bord';
        BEGIN
          select tu.um, tu.plafoncantf into existingUM, existingPlafon from tmp_utilaje tu;
        exception
           when others then
                existingUM     := null;
                existingPlafon := null;
          end;
      end if;
      insert into TMP_UTILAJETIPINDEX(CODTINDEX, codutilaj, tip_index, denumire, um, plafoncantf)
                  VALUES (-1, pCodUtilaj, i, denIndex, existingUM, existingPlafon);
    end loop;
  end if;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_postapeluri</obj_name>
  <obj_hashval>00efebe1260a4856fb25b7a5a9be8171</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_postapeluri()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
BEGIN
  --Adina 02.08.2021
  FOR V_REC IN (SELECT * FROM TMP_APELTELEFON WHERE MODIFICAT = 1) LOOP
    IF  V_REC.CODAPEL &lt; 0 THEN
      INSERT INTO APELTELEFON(CODAPEL, IDAPEL, STARE, TELEFON, APELANT, DATAORA, PRELUAT, CLIENT)
      VALUES(NEXTVAL('SEQ_APELTELEFON_CODAPEL'), V_REC.IDAPEL, V_REC.STARE, V_REC.TELEFON, V_REC.APELANT, V_REC.DATAORA, V_REC.PRELUAT, V_REC.CLIENT);
    ELSE
      UPDATE APELTELEFON
      SET
        STARE   = V_REC.STARE,
        PRELUAT = V_REC.PRELUAT
      WHERE
       CODAPEL = V_REC.CODAPEL;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_setct_monitor</obj_name>
  <obj_hashval>ba2ad5c7ac1d9bfbd7064f6de0eded76</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_setct_monitor(act_monitor character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_UTILAJE.CT_MONITOR',aCT_MONITOR,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_setvcodutilaj2c</obj_name>
  <obj_hashval>e8ef24780813cce4d7eda6200ee61a48</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_setvcodutilaj2c(avcodutilaj2c numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_UTILAJE.vCodUtilaj2C',to_char(avCodUtilaj2C,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_sp_deleterecord</obj_name>
  <obj_hashval>fed6199564839d99ed62634e13d77952</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  aDoc  varchar;
BEGIN
  --Florin 08.09.2023 - fixat 59380
  --Florin 01.06.2023 - monitor
  --Florin 12.04.2023 - sinc. Oracle
  --Florin 31.10.2020 - fixat #40752
  --Florin 23.03.2021 - pkg_userfirme_postlogcucommit
  perform pkg_utilaje_setct_monitor('MON_53');
  PERFORM PKG_UTILAJE_SP_LOCKRECORD( RecId);
  PERFORM PKG_CFGTABLES_EXT_DELETERECORD (recId, 508);

  IF (SELECT PKG_USERFIRME_ValidPostLog.WME_RESULT FROM PKG_USERFIRME_ValidPostLog(NULL, TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999'), (current_setting('PKG_UTILAJE.CT_MONITOR', true))))
  THEN
    SELECT 'Utilaj "' || nrinventar || '"' INTO aDoc FROM UTILAJE WHERE codutilaj = recid;
    PERFORM pkg_userfirme_postlogcucommit( 'UTILAJE', (current_setting('PKG_GLOBALS.USERNAME', true)), 'S', RECID, (current_setting('PKG_GLOBALS.FIRMANAME', true)), TO_NUMBER((current_setting('PKG_GLOBALS.SUBUNITATE', true)),'999999999999999999'), null, aDoc, '', (SELECT PKG_GLOBALS_GET_EXE_VERSION.WME_RESULT FROM PKG_GLOBALS_GET_EXE_VERSION(NULL,NULL)));
  END IF;

  UPDATE iesiri1 SET codutilaj = NULL WHERE codutilaj = recid;

  DELETE FROM UTILAJE2P  WHERE CODUTILAJ = RECID;
  DELETE FROM UTILAJE2C  WHERE CODUTILAJ = RECID;
  DELETE FROM UTILAJE2   WHERE CODUTILAJ = RECID;
  DELETE FROM UTILAJEDEV WHERE CODUTILAJ = RECID;

  FOR V_REC IN (SELECT CODUTILAJ20, STARE FROM UTILAJE20 U20 WHERE U20.CODUTILAJ = RecID) LOOP
    DELETE FROM UTILAJE20 WHERE CODUTILAJ20 = V_REC.CODUTILAJ20;
    INSERT INTO UTILAJEMON(CODMONITORIZARE, CODUTILAJ20, USERID, DATAMODIF, STAREV, TIPMODIF)
    VALUES(NEXTVAL('SEQ_UTILAJEMON_CODMONITORIZARE'), V_REC.CODUTILAJ20, (SELECT PKG_GLOBALS_GETUSERID.WME_RESULT FROM PKG_GLOBALS_GETUSERID(NULL,NULL)), CURRENT_TIMESTAMP, V_REC.STARE, 'STERGERE');
  END LOOP;

  DELETE FROM UTILAJE1 WHERE CODUTILAJ = RECID;
  DELETE FROM UTILAJETIPINDEX WHERE CODUTILAJ = RECID;
  DELETE FROM UTILAJE  WHERE CODUTILAJ = RECID;

  PERFORM NotifyModif( 2, RecId, 'UTILAJE');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_sp_insertrecord</obj_name>
  <obj_hashval>dd9f6446cbc8cf4a2a6903924a976c89</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 12.04.2023 - sinc. Oracle
  --Florin 13.02.2023 - sinc. Oracle
  INSERT INTO TMP_UTILAJE(CODUTILAJ, TIP) VALUES(0, 0);
  PERFORM PKG_CFGTABLES_EXT_INSERTRECORD(508);
  PERFORM pkg_utilaje_InitUtilajeTipIndex(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_sp_lockrecord</obj_name>
  <obj_hashval>a51550d0aaf27ee0bae4b318d151224a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMP numeric;
begin
  SELECT CODUTILAJ INTO TMP FROM UTILAJE WHERE CODUTILAJ = RECID FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_vcodutilaj2c</obj_name>
  <obj_hashval>764c825b3040b4e6deaab4e0972c2bc9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_vcodutilaj2c(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_UTILAJE.vCodUtilaj2C', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_vanzari_sp_deleterecord</obj_name>
  <obj_hashval>ebcacc9eb5b03e4301dbbaf8c4d98c60</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_vanzari_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_VANZARI_SP_LOCKRECORD(RecId);
  DELETE FROM VANZARI WHERE CODVANZARE = RecId;
  PERFORM NotifyModif(2, RecId, 'VANZARI');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_vanzari_sp_gotorecord</obj_name>
  <obj_hashval>9468d79846bc263642b81062268a0b26</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_vanzari_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_VANZARI(CODVANZARE, CODPART, DATADOC, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CODEMULARE, CODEMULAREFACT, INFOBON, INFOFACT, CODIES, OBS,
                          VALBON, TVABON, VALDISCBON, TVADISCBON, VALFACTURA, TVAFACTURA, VALDISCFACTURA, TVADISCFACTURA)
  (
  SELECT CODVANZARE, V.CODPART, V.DATADOC, V.VALDOC, V.TVADOC, V.VALDISCOUNT, V.TVADISCOUNT, V.CODEMULARE, V.CODEMULAREFACT, 'Bon ' || coalesce((E.NRBON)::varchar::varchar ,'') || '/' || coalesce(To_Char(TO_CHAR(E.DATABON, 'DD.MM.YYYY'),'dd.mm.yyyy'),''), 'Factura ' || coalesce(I.SERIADOC,'') || ' ' || coalesce((I.NRDOC)::varchar::varchar ,'') || '/' || coalesce(To_Char(TO_CHAR(I.DATADOC, 'DD.MM.YYYY'),'dd.mm.yyyy'),''), I.CODIES, V.OBS, E.VALOARE, E.TVATOTAL, E.VALOAREDISCOUNT, E.TVADISCOUNT, EFACT.VALOARE, EFACT.TVATOTAL, EFACT.VALOAREDISCOUNT, EFACT.TVADISCOUNT
  FROM VANZARI V
      LEFT JOIN EMULARE E     ON  E.CODEMULARE     = V.CODEMULARE
      LEFT JOIN EMULARE EFACT ON  EFACT.CODEMULARE = V.CODEMULAREFACT
      LEFT JOIN IESIRI  I     ON  EFACT.CODIES     = I.CODIES
  WHERE CODVANZARE = RecId
  );

  UPDATE TMP_VANZARI
  SET
  VALDOC      = COALESCE(VALBON, 0)     + COALESCE(VALFACTURA, 0),
  TVADOC      = COALESCE(TVABON, 0)     + COALESCE(TVAFACTURA, 0),
  VALDISCOUNT = COALESCE(VALDISCBON, 0) + COALESCE(VALDISCFACTURA, 0),
  TVADISCOUNT = COALESCE(TVADISCBON, 0) + COALESCE(TVADISCFACTURA, 0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_vanzari_sp_insertrecord</obj_name>
  <obj_hashval>f209c74e4034db67b5f90625a9e0f52a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_vanzari_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_VANZARI (CODVANZARE) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_vanzari_sp_lockrecord</obj_name>
  <obj_hashval>5bb29435591ca2dea1a62329cd979d3e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_vanzari_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT codVanzare INTO Tmp FROM VANZARI WHERE CODVANZARE = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_vanzari_sp_postrecords</obj_name>
  <obj_hashval>137392b0b778a28577be70efc8b073d3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_vanzari_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  vRecNo NUMERIC := 0;
  vAn    NUMERIC := 0;
  vLuna  NUMERIC := 0;
  vCod   numeric;
begin
  IF  Operation = 0 THEN
    SELECT CODVANZARE INTO RecId FROM TMP_VANZARI;

    UPDATE VANZARI
    SET
    (CODPART, DATADOC, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CODEMULARE, CODEMULAREFACT, OBS)
    =
    (SELECT CODPART, DATADOC, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CODEMULARE, CODEMULAREFACT, OBS FROM TMP_VANZARI)
    WHERE
     CODVANZARE = RecId;
  ELSE
    SELECT NEXTVAL('SEQ_VANZARI_CODVANZARE') INTO RecId;

    INSERT INTO VANZARI(CODVANZARE, CODPART, DATADOC, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CODEMULARE, CODEMULAREFACT, OBS)
    (SELECT RecId, CODPART, DATADOC, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CODEMULARE, CODEMULAREFACT, OBS FROM TMP_VANZARI);
  END IF;

  PERFORM NotifyModif(Operation, RecId, 'VANZARI');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_venitavans_ini_sp_deleterecord</obj_name>
  <obj_hashval>c3d4c44e1b95944af7487561c10c7524</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_venitavans_ini_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC    RECORD;
  V_RECIES RECORD;
  NR       numeric := 0;
  aDoc     varchar;
begin
  PERFORM PKG_GLOBALS_MarkDirtyJurnal();
  PERFORM PKG_VENITAVANS_INI_SP_LOCKRECORD(RecId);

  DELETE FROM TMP_MANEVRA;

  FOR V_REC IN (SELECT CV.CODCHELTAVANS, CV1.CODCHELTAVANS1
                FROM CHELTAVANS1 CV1, CHELTAVANS CV
                WHERE CV.CODIES1 = RECID AND  CV.ISVENIT = 1 AND  CV.CODCHELTAVANS = CV1.CODCHELTAVANS
               )
  LOOP
    INSERT INTO TMP_MANEVRA(CODUNIC) VALUES(V_REC.CODCHELTAVANS);
    DELETE FROM CHELTAVANS1 WHERE CODCHELTAVANS1 = V_REC.CODCHELTAVANS1;
  END LOOP;

  FOR V_REC IN (SELECT  DISTINCT CODUNIC FROM TMP_MANEVRA) LOOP
    DELETE FROM CHELTAVANS WHERE CODCHELTAVANS = V_REC.CODUNIC;
  END LOOP;

  DELETE FROM MASTERCHELTAVANS WHERE CODIES1 = RECID;

  FOR V_RECIES IN (SELECT I.CODIES, CODIES1
                   FROM IESIRI I, IESIRI1 I1
                   WHERE I1.CODIES1 = RECID AND  I.CODIES = I1.CODIES AND  I.INITIALIZARI = 1
                  )
  LOOP
    DELETE FROM IESIRI1 WHERE CODIES1 = V_RECIES.CODIES1;
    DELETE FROM IESIRI  WHERE CODIES = V_RECIES.CODIES;
  END LOOP;

  FOR V_REC IN (SELECT * FROM JURNAL J WHERE EXISTS (SELECT CODUNIC FROM TMP_MANEVRA WHERE CODUNIC = J.CODDOC) AND  TIPDOC = 106) LOOP
    UPDATE NCONTRUL
    SET
    RULAJCD  = RULAJCD  - V_REC.VALOARE,
    RULAJVCD = RULAJVCD - V_REC.VALOAREV
    WHERE
     CODCONT = V_REC.CONTD AND  AN = current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric AND  LUNA = current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric;

    UPDATE NCONTRUL
    SET
    RULAJCC  = RULAJCC  - V_REC.VALOARE,
    RULAJVCC = RULAJVCC - V_REC.VALOAREV
    WHERE
     CODCONT = V_REC.CONTC AND  AN = current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric AND  LUNA = current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric;
  END LOOP;

  DELETE FROM JURNAL J  WHERE EXISTS (SELECT CODUNIC FROM TMP_MANEVRA WHERE CODUNIC = J.CODDOC) AND  TIPDOC = 106;
  DELETE FROM JURNAL1 J WHERE EXISTS (SELECT CODUNIC FROM TMP_MANEVRA WHERE CODUNIC = J.CODDOC) AND  TIPDOC = 106;

  PERFORM NotifyModif(2, RecId, 'MASTERCHELTAVANS');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_venitavans_ini_sp_gotorecord</obj_name>
  <obj_hashval>5be1567623d493ff5b26373e6a704b72</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_venitavans_ini_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  NR numeric := 0;
begin
  IF  RECID &gt; 0 THEN
    SELECT COUNT(*) INTO NR FROM MASTERCHELTAVANS WHERE COALESCE(CODIES1, 0) = RecId;

    IF  RECID &gt; 0 AND  NR = 0 THEN
      INSERT INTO MASTERCHELTAVANS(CODIES1) VALUES(RECID);
    END IF;

    SELECT COUNT(*) INTO NR FROM CHELTAVANS WHERE CODIES1 = RECID;

    IF  RECID &gt; 0 AND  NR = 0 THEN
      INSERT INTO CHELTAVANS(CODCHELTAVANS, CODIES1, ANINCEPUT, LUNAINCEPUT, ISVENIT)
      VALUES(NEXTVAL('SEQ_CHELTAVANS_CODCHELTAVANS'), RECID, current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric, current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric, 1);
    END IF;

    INSERT INTO TMP_MASTERCHELTAVANS SELECT * FROM MASTERCHELTAVANS WHERE CODIES1 = RECID;

    INSERT INTO TMP_CHELTAVANS(CODCHELTAVANS, CODIES1, ANINCEPUT, LUNAINCEPUT, CODIOART, CODGEST, DEN_GEST, CODSUBUNIT, NRDOC, DEN_PART, OBS, CODPART, DATADOC, CODOBIECT, CONTSERV, CODINTR, PREFIXDOC, SERIADOC, DATASTART, DATAEND, TIPINTERVAL, OBSERVATII)
    (SELECT CAV.CODCHELTAVANS, CAV.CODIES1, CAV.ANINCEPUT, CAV.LUNAINCEPUT, CAV.CODIOART, G.CODGEST, G.DEN_GEST, I.SUBUNITATEA, I.NRDOC, P.DEN_PART, I1.OBS, I.PARTENER, I.DATADOC, I1.CODOBIECT, I1.CONTSERV, I.CODIES, I.PREFIXDOC, I.SERIADOC, CAV.DATASTART, CAV.DATAEND, 0, CAV.OBSERVATII
      FROM CHELTAVANS CAV, IESIRI I, IESIRI1 I1 LEFT JOIN NGEST G ON  G.CODGEST = I1.GESTACT, NPART P
     WHERE CAV.CODIES1 = RECID AND  I1.CODIES1 = RECID AND  I.CODIES = I1.CODIES AND  P.CODPART = I.PARTENER
    );

    INSERT INTO TMP_CHELTAVANS1(CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, ANSTART, LUNASTART, AMO, CODCENTRU, CODANALIZANOD)
    SELECT CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, ANSTART, LUNASTART, AMO, CODCENTRU, CODANALIZANOD
    FROM CHELTAVANS1 AV1
    WHERE ANSTART = current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric AND  LUNASTART = current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric
      AND  EXISTS (SELECT CODCHELTAVANS FROM TMP_CHELTAVANS WHERE CODCHELTAVANS = AV1.CODCHELTAVANS);

    INSERT INTO TMP_JURNAL
    (SELECT *
     FROM JURNAL J
     WHERE  TIPDOC = 106 AND  EXISTS (SELECT CODCHELTAVANS FROM TMP_CHELTAVANS WHERE CODCHELTAVANS = J.CODDOC)
       AND  AN = current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric AND  LUNA = current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric
    );

    INSERT INTO TMP_JURNAL1
    (SELECT *
     FROM JURNAL1 J
     WHERE  TIPDOC = 106 AND  EXISTS (SELECT CODCHELTAVANS FROM TMP_CHELTAVANS WHERE CODCHELTAVANS = J.CODDOC)
       AND  AN = current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric AND  LUNA = current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric
    );

    DELETE FROM TMP_RULAJ;
    DELETE FROM TMP_MIFIX_INITIAL;

    INSERT INTO TMP_MIFIX_INITIAL(CODMIFIX) SELECT CODCHELTAVANS FROM TMP_CHELTAVANS;

    UPDATE TMP_CHELTAVANS SET TIPINTERVAL = 1 WHERE DATASTART IS NOT NULL  AND DATAEND IS NOT NULL;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_venitavans_ini_sp_lockrecord</obj_name>
  <obj_hashval>81ffb2273f415436e79f029336dc7dae</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_venitavans_ini_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  BEGIN
    SELECT CODIES1 INTO Tmp FROM MASTERCHELTAVANS WHERE CODIES1 = RecId FOR UPDATE NOWAIT;
  EXCEPTION WHEN OTHERS THEN
    TMP := 0;
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_voucher_sp_deleterecord</obj_name>
  <obj_hashval>3f68c269242d1fd1c77dcd66722bc41f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_voucher_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_VOUCHER_SP_LOCKRECORD( RecId);
  DELETE FROM VOUCHER WHERE CodVoucher = RecId;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_voucher_sp_postrecords</obj_name>
  <obj_hashval>5e733271d35c5b2916dde845c3cc1db0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_voucher_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  Cod numeric;
BEGIN
  --Florin 14.11.2023 - sinc. Oracle
  IF  Operation = 0 THEN
    BEGIN
      SELECT CodVOUCHER INTO RECID FROM TMP_VOUCHER;
    EXCEPTION WHEN OTHERS THEN
      RECID := 0;
    END;

    UPDATE VOUCHER
    SET
    (CODVOUCHER, CODPARTENER, OBS, DATASTART, DATASTOP, MONEDA, CodGest, VALOARE, CodCmd, CodIes, OBS1)
    =
    (SELECT CODVOUCHER, CODPARTENER, OBS, DATASTART, DATASTOP, COALESCE( MONEDA, 0), CodGest, VALOARE, CodCmd, CodIes, OBS1 FROM TMP_VOUCHER)
    WHERE
     CodVoucher = RECID;
  ELSE
    SELECT NEXTVAL('SEQ_VOUCHER_CODVOUCHER') INTO RecId;

    INSERT INTO VOUCHER(CODVOUCHER, CODPARTENER, OBS, DATASTART, DATASTOP, MONEDA, CodGest, VALOARE, CodCmd, CodIes, OBS1)
    SELECT RECID, CODPARTENER, OBS, DATASTART, DATASTOP, COALESCE( MONEDA, 0), CodGest, VALOARE, CodCmd, CodIes, OBS1 FROM TMP_VOUCHER;
  END IF;

  PERFORM NotifyModif( Operation, RecId, 'VOUCHER');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_vouchercadou_solvevouchercadou</obj_name>
  <obj_hashval>a39554c2874fd9cb61d6c3628065150e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_vouchercadou_solvevouchercadou(tipoperatie numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Cod numeric;
  nr NUMERIC;
  V_REC record;
BEGIN
  --Florin 07.01.2024 - fixat 64378
  --Florin 20.12.2024 - fixat 64341
  --Florin 19.12.2024
  --Florin 13.12.2024 - sinc. Oracle
  --Florin 12.12.2023 - sinc. Oracle
  IF TIPOPERATIE = 4 THEN
    FOR V_REC IN
     (SELECT V.BARCODE
      FROM
        TMP_VOUCHERCADOU T
        INNER JOIN VOUCHERCADOU V ON V.BARCODE = T.BARCODE
     )
     LOOP
       UPDATE VOUCHERCADOU
       SET
         IS_USED = NULL,
         USED_DATE = NULL
       WHERE
         BARCODE = V_REC.BARCODE;
     END LOOP;
  ELSE
  IF TIPOPERATIE = 3 THEN
    FOR V_REC IN
      (SELECT V.COD
        FROM TMP_VOUCHERCADOU T
      INNER JOIN VOUCHERCADOU V ON V.BARCODE = T.BARCODE
      )
    LOOP
      DELETE FROM VOUCHERCADOU V WHERE  V.COD = V_REC.COD;
    END LOOP;
   ELSE
     IF TIPOPERATIE = 1 THEN
      FOR V_REC IN
       (SELECT  T.BARCODE, T.VALOARE, T.DATASTART, T.DATASTOP
        FROM
          TMP_VOUCHERCADOU T
       )
       LOOP
         SELECT COUNT(*) INTO NR FROM VOUCHERCADOU WHERE BARCODE = V_REC.BARCODE;

         IF NR = 0 THEN
           INSERT INTO VOUCHERCADOU(COD, BARCODE, VALOARE, DATASTART, DATASTOP)
           VALUES (NEXTVAL('SEQ_VOUCHERCADOU_COD'), V_REC.BARCODE, V_REC.VALOARE, V_REC.DATASTART, V_REC.DATASTOP);
         ELSE
           UPDATE VOUCHERCADOU
           SET
             VALOARE    = V_REC.VALOARE,
             DATASTART  = V_REC.DATASTART,
             DATASTOP   = V_REC.DATASTOP,
             IS_USED    = NULL,
             USED_DATE  = NULL
           WHERE
             BARCODE = V_REC.BARCODE
             AND COALESCE(IS_USED, 0) = 0;
         END IF;

       END LOOP;
    ELSE
      FOR V_REC IN
       (SELECT V.COD
        FROM
          TMP_VOUCHERCADOU T
          INNER JOIN VOUCHERCADOU V ON V.BARCODE = T.BARCODE
       )
       LOOP
         UPDATE VOUCHERCADOU V
         SET
           IS_USED   = 1,
           USED_DATE = current_timestamp
         WHERE
           V.COD = V_REC.COD;
       END LOOP;
    END IF;
  END IF;
END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_vouchercadou_sp_gotorecord</obj_name>
  <obj_hashval>132bde40eddcc43496fad34cd04fbd07</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_vouchercadou_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 14.11.2023 - sinc. Oracle
  INSERT INTO  TMP_VOUCHERCADOU SELECT * FROM VOUCHERCADOU WHERE COD = RECID;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_vouchercadou_sp_lockrecord</obj_name>
  <obj_hashval>dfd33c8504fdfd4d0c478b213089a7a0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_vouchercadou_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
BEGIN
  --Florin 12.12.2024
  SELECT COD INTO Tmp FROM VOUCHERCADOU WHERE COD = RecId;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_vouchercadou_sp_postrecords</obj_name>
  <obj_hashval>b5abb34fbb98bbf6526622d07dbc120b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_vouchercadou_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  Cod numeric;
BEGIN
  --Florin 14.11.2023 - sinc. Oracle
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT COD INTO RECID FROM TMP_VOUCHERCADOU;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE VOUCHERCADOU
    SET
     (
       BARCODE,
       VALOARE,
       DATASTART,
       DATASTOP,
       IS_USED,
       USED_DATE
     ) =
     (SELECT
        BARCODE,
        VALOARE,
        DATASTART,
        DATASTOP,
        IS_USED,
        USED_DATE
      FROM
        TMP_VOUCHERCADOU
     )
    WHERE
      COD = RECID;
  ELSE  -- INSERT
    SELECT NextVal('SEQ_VOUCHERCADOU_COD') INTO RecId;
    INSERT INTO VOUCHERCADOU(COD, BARCODE, VALOARE, DATASTART, DATASTOP, IS_USED, USED_DATE)
    SELECT RECID, BARCODE, VALOARE, DATASTART, DATASTOP, IS_USED, USED_DATE FROM TMP_VOUCHERCADOU;
  END IF;

  PERFORM NotifyModif(Operation, RecId, 'VOUCHERCADOU');

end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_weekcashflow_getct_monitor</obj_name>
  <obj_hashval>75a40e8e0c2aadebd1c77e91e623024f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_weekcashflow_getct_monitor(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_WEEKCASHFLOW.CT_MONITOR', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 'MON_65';
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_weekcashflow_sp_deleterecord</obj_name>
  <obj_hashval>6ba7cb5c543d2b314e1769ad699b43a4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_weekcashflow_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC       RECORD;
  aDATADOC    date;
  aCodSubunit numeric;
  aDoc        varchar;
BEGIN
  --Florin 01.06.2023 - monitor
  --Florin 17.11.2020 - fixat #41086
  --Florin 23.03.2021 - pkg_userfirme_postlogcucommit
  perform pkg_weekcashflow_setct_monitor('MON_65');
  PERFORM PKG_WEEKCASHFLOW_SP_LOCKRECORD( RecId);

  SELECT DATADOC, SUBUNITATEA, NRDOC
  INTO ADATADOC, aCodSubunit, aDoc
  FROM WEEKCASHFLOW
  WHERE CODCASHFLOW = RecID;

  IF (SELECT WME_RESULT FROM PKG_USERFIRME_ValidPostLog(NULL, TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999'), (current_setting('PKG_WEEKCASHFLOW.CT_MONITOR', true))))
  THEN
    PERFORM pkg_userfirme_postlogcucommit( 'CODCASHFLOW', (current_setting('PKG_GLOBALS.USERNAME', true)), 'S', RECID, (current_setting('PKG_GLOBALS.FIRMANAME', true)), aCodSubunit, aDataDoc, aDoc, '', (SELECT PKG_GLOBALS_GET_EXE_VERSION.WME_RESULT FROM PKG_GLOBALS_GET_EXE_VERSION(NULL,NULL)));
  END IF;

  FOR V_REC IN (SELECT * FROM WEEKCASHFLOW1 WHERE CODCASHFLOW = RecId) LOOP
    DELETE FROM WEEKCASHPLATI WHERE CODCASHFLOW1 = V_REC.CODCASHFLOW1;
    DELETE FROM WEEKCASHFLOW1 WHERE CODCASHFLOW1 = V_REC.CODCASHFLOW1;
  END LOOP;

  DELETE FROM WEEKCASHFLOW WHERE CODCASHFLOW = RecId;
  DELETE FROM WEEKCASHSOLD WHERE CODCASHFLOW = RecId;

  PERFORM NotifyModif( 2, RecId, 'WEEKCASHFLOW');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_weekcashflow_sp_gotorecord</obj_name>
  <obj_hashval>34b4051d3bd16a2437c66611a50516c8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_weekcashflow_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  --Florin 16.11.2021 - fixat 52001
  perform pkg_weekcashflow_setct_monitor('MON_65');
  INSERT INTO TMP_WEEKCASHFLOW
  SELECT * FROM WEEKCASHFLOW WHERE CODCASHFLOW = RECID;

  INSERT INTO TMP_WEEKCASHFLOW1
  SELECT * FROM WEEKCASHFLOW1 WHERE CODCASHFLOW = RECID;

  INSERT INTO TMP_WEEKCASHSOLD(CODSOLD, CODCASHFLOW, CODBANKCONT, CODLIMCREDIT, SOLD, REST, PLATI, CODMONEDA, DEN_CONT)
  SELECT WS.CODSOLD, WS.CODCASHFLOW, WS.CODBANKCONT, WS.CODLIMCREDIT, WS.SOLD, WS.REST, WS.PLATI, BK.CODMONEDA, BK.DEN_CONT
  FROM WEEKCASHSOLD WS, NBANKCONT BK
  WHERE CODCASHFLOW = RECID AND  WS.CODBANKCONT = BK.CODBANKCONT;

  INSERT INTO TMP_WEEKCASHSOLD(CODSOLD, CODCASHFLOW, CODBANKCONT, CODLIMCREDIT, SOLD, REST, PLATI, CODMONEDA, DEN_CONT)
  SELECT WS.CODSOLD, WS.CODCASHFLOW, WS.CODBANKCONT, WS.CODLIMCREDIT, WS.SOLD, WS.REST, WS.PLATI, L.MONEDA, 'Limita credit ' || ' ' || BK.DENUMIRE
  FROM WEEKCASHSOLD WS, NLIMCREDIT L, NBANK BK
  WHERE CODCASHFLOW = RECID AND  WS.CODLIMCREDIT = L.CODLIMCREDIT AND  BK.CODBANK = L.CODBANCA;

  INSERT INTO TMP_WEEKCASHPLATI(CODCASHPLATI, CODCASHFLOW1, CODOBLIGPIF, DATAPLATA, SUMAPLATA, NRDOC, DATADOC, PREFIXDOC, TERMENOBLIG, RESTOBLIG, CODDOC, TIPDOC, OLDDATAPLATA, OLDSUMAPLATA, RESTOBLIGRAMAS, CODBANKCONT, DEN_CONT, OLDCODBANKCONT)
  SELECT CODCASHPLATI, CODCASHFLOW1, CODOBLIGPIF, DATAPLATA, SUMAPLATA, NRDOC, DATADOC, PREFIXDOC, TERMENOBLIG, RESTOBLIG, CODDOC, TIPDOC, DATAPLATA, SUMAPLATA, RESTOBLIG - SUMAPLATA, P.CODBANKCONT, BK.DEN_CONT, P.CODBANKCONT
  FROM WEEKCASHPLATI P LEFT JOIN NBANKCONT BK ON  BK.CODBANKCONT = P.CODBANKCONT
  WHERE EXISTS (SELECT CODCASHFLOW1 FROM TMP_WEEKCASHFLOW1 T WHERE T.CODCASHFLOW1 = P.CODCASHFLOW1);

  FOR V_REC IN (SELECT CODCASHPLATI, P.DEN_PART, O.CODPART, M.CODMONEDA, M.SIMBOL AS SIMBOLMONEDA, W1.SIMBOLCONT, G.TIPDOC, G.CODDOC
                FROM TMP_WEEKCASHPLATI T, OBLIGPIF O, NPART P, GENERAL G
                     LEFT JOIN NMONEDE M ON  M.CODMONEDA = G.MONEDA, TMP_WEEKCASHFLOW1 W1
                WHERE T.CODOBLIGPIF = O.CODOBLIGPIF AND  G.CODGENERAL = O.CODGENERAL AND  P.CODPART = O.CODPART AND  W1.CODCASHFLOW1 = T.CODCASHFLOW1 AND  COALESCE( T.TIPDOC, 0) &lt;&gt; 8
               )
  LOOP
    UPDATE TMP_WEEKCASHPLATI
    SET
    CODPART      = V_REC.CODPART,
    DEN_PART     = V_REC.DEN_PART,
    CODMONEDA    = V_REC.CODMONEDA,
    SIMBOLMONEDA = V_REC.SIMBOLMONEDA,
    SIMBOLCONT   = V_REC.SIMBOLCONT
    WHERE
     CODCASHPLATI = V_REC.CODCASHPLATI;
  END LOOP;

  FOR V_REC IN (SELECT CODCASHPLATI, P.DEN_PART, P.CODPART, M.CODMONEDA, M.SIMBOL AS SIMBOLMONEDA, W1.SIMBOLCONT
                FROM TMP_WEEKCASHPLATI T, COMANDA C, NPART P, NMONEDE M, TMP_WEEKCASHFLOW1 W1
                WHERE COALESCE( T.TIPDOC, 0) = 8 AND  T.CODDOC = C.CODCOMANDA AND  P.CODPART = C.PARTENER AND  W1.CODCASHFLOW1 = T.CODCASHFLOW1 AND  M.CODMONEDA = COALESCE( C.MONEDA, 0)
               )
  LOOP
    UPDATE TMP_WEEKCASHPLATI
    SET
    CODPART      = V_REC.CODPART,
    DEN_PART     = V_REC.DEN_PART,
    CODMONEDA    = V_REC.CODMONEDA,
    SIMBOLMONEDA = V_REC.SIMBOLMONEDA,
    SIMBOLCONT   = V_REC.SIMBOLCONT
    WHERE
     CODCASHPLATI = V_REC.CODCASHPLATI;
  END LOOP;

  DELETE FROM TMP_WEEKCASHPLATI_INI;
  INSERT INTO TMP_WEEKCASHPLATI_INI SELECT CODCASHPLATI FROM TMP_WEEKCASHPLATI;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_count_clienti</obj_name>
  <obj_hashval>5a3f1e78352fea6c8dbadd371ded4c08</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_count_clienti(INOUT wme_result refcursor, INOUT aden_part character varying, INOUT acodfiscal character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
  DECLARE
    TMPCURSOR REFCURSOR;
  BEGIN
    BEGIN
      OPEN TMPCURSOR FOR
      SELECT COUNT(*) AS        CLIENTCOUNT
      FROM (   SELECT  DISTINCT P.CODPART, P.DEN_PART, COALESCE (M.CODMONEDA, 0) AS CODMONEDA, M.SIMBOL AS SIMBOL_MONEDA,
            CF.COD_CODFISCAL, CF.CODFISCAL
          FROM NAGENDA               A, NPART P
            LEFT JOIN NMONEDE      M  ON M.CODMONEDA = COALESCE (P.CODMONEDA, 0)
            LEFT JOIN NPARTCODFISC CF ON CF.CODPART = P.CODPART AND CF.PRINCIPAL = 1
          WHERE
            A.TIP = 0
            AND A.CODPART = P.CODPART
            AND UPPER (CF.CODFISCAL) LIKE '%'
              || coalesce (UPPER (aCODFISCAL) ::varchar ,'')
              || '%'
            AND UPPER (DEN_PART) LIKE '%'
              || coalesce (UPPER (aDEN_PART) ,'')
              || '%') A_PG;

    EXCEPTION
    WHEN OTHERS THEN
      OPEN TMPCURSOR FOR
      SELECT -1 AS CODPART;

    END;
    WME_Result := TMPCURSOR;
    RETURN;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_count_clienti_4php</obj_name>
  <obj_hashval>0db74105a841ce449a179eefea8f54c4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_count_clienti_4php(refcursor, character varying, character varying)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMPCURSOR REFCURSOR;
begin
  BEGIN
    OPEN $1 FOR
    SELECT COUNT(*) AS        CLIENTCOUNT
    FROM (SELECT  DISTINCT P.CODPART, P.DEN_PART, COALESCE (M.CODMONEDA, 0) AS CODMONEDA, M.SIMBOL AS SIMBOL_MONEDA,
                  CF.COD_CODFISCAL, CF.CODFISCAL
        FROM NAGENDA             A, NPART P
          LEFT JOIN NMONEDE      M  ON M.CODMONEDA = COALESCE (P.CODMONEDA, 0)
          LEFT JOIN NPARTCODFISC CF ON CF.CODPART  = P.CODPART AND CF.PRINCIPAL = 1
        WHERE
          A.TIP = 0
          AND A.CODPART = P.CODPART
          AND UPPER (CF.CODFISCAL) LIKE '%'|| coalesce (UPPER ($3) ::varchar ,'')|| '%'
          AND UPPER (DEN_PART)     LIKE '%'|| coalesce (UPPER ($2) ,'')          || '%') A_PG;
  EXCEPTION
  WHEN OTHERS THEN
    OPEN $1 FOR
    SELECT -1 AS CODPART;
  END;

  return next $1;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_clienti</obj_name>
  <obj_hashval>df7a8b2342e5cff967ba9300b50e741f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_clienti(INOUT wme_result refcursor, INOUT aden_part character varying, INOUT acodfiscal character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMPCURSOR REFCURSOR;
begin
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT  DISTINCT P.CODPART, P.DEN_PART, COALESCE (M.CODMONEDA, 0) AS CODMONEDA, M.SIMBOL AS SIMBOL_MONEDA,
            CF.COD_CODFISCAL, CF.CODFISCAL, P.CODEXTERN
    FROM NAGENDA             A, NPART P
      LEFT JOIN NMONEDE      M  ON M.CODMONEDA = COALESCE (P.CODMONEDA, 0)
      LEFT JOIN NPARTCODFISC CF ON CF.CODPART  = P.CODPART AND CF.PRINCIPAL = 1
    WHERE
      A.TIP = 0
      AND A.CODPART = P.CODPART
      AND UPPER (CF.CODFISCAL) LIKE '%'|| coalesce (UPPER (aCODFISCAL) ::varchar ,'')|| '%'
      AND UPPER (DEN_PART) LIKE '%'|| coalesce (UPPER (aDEN_PART) ,'')|| '%'
    ORDER BY
      P.DEN_PART;
  EXCEPTION
  WHEN OTHERS THEN
    OPEN TMPCURSOR FOR
    SELECT -1 AS CODPART;
  END;

  WME_Result := TMPCURSOR;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_clienti_4php</obj_name>
  <obj_hashval>2fff24c6c0b27b543fbfd5e026364b51</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_clienti_4php(refcursor, character varying, character varying)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMPCURSOR REFCURSOR;
begin
  BEGIN
    OPEN $1 FOR
    SELECT  DISTINCT P.CODPART, P.DEN_PART, COALESCE (M.CODMONEDA, 0) AS CODMONEDA, M.SIMBOL AS SIMBOL_MONEDA,
            CF.COD_CODFISCAL, CF.CODFISCAL, P.CODEXTERN
    FROM NAGENDA             A, NPART P
      LEFT JOIN NMONEDE      M  ON M.CODMONEDA = COALESCE (P.CODMONEDA, 0)
      LEFT JOIN NPARTCODFISC CF ON CF.CODPART = P.CODPART AND CF.PRINCIPAL = 1
    WHERE
      A.TIP = 0
      AND A.CODPART = P.CODPART
      AND UPPER (CF.CODFISCAL) LIKE '%'|| coalesce (UPPER ($3) ::varchar ,'')|| '%'
      AND UPPER (DEN_PART)     LIKE '%'|| coalesce (UPPER ($2) ,'')          || '%'
    ORDER BY
      P.DEN_PART;
  EXCEPTION
  WHEN OTHERS THEN
    OPEN $1 FOR
    SELECT -1 AS CODPART;
  END;

  return next $1;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_clienti_agent</obj_name>
  <obj_hashval>b28a20bf10e95911d163259198b986a5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_clienti_agent(INOUT wme_result refcursor, INOUT acodpers numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMPCURSOR REFCURSOR;
begin
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT  DISTINCT P.CODPART, (SELECT translate(P.DEN_PART, 'ÂâÎî', 'AaIi')   AS DEN_PART), COALESCE (M.CODMONEDA, 0) AS CODMONEDA, M.SIMBOL AS SIMBOL_MONEDA,
            CF.COD_CODFISCAL, CF.CODFISCAL, P.CODEXTERN
    FROM NAGENDA             A, NPART P
      LEFT JOIN NMONEDE      M  ON M.CODMONEDA = COALESCE (P.CODMONEDA, 0)
      LEFT JOIN NPARTCODFISC CF ON CF.CODPART  = P.CODPART AND CF.PRINCIPAL = 1
    WHERE
      A.TIP = 0
      AND COALESCE (A.CODAGENT, 0) = aCODPERS
      AND A.CODPART = P.CODPART
    ORDER BY
      DEN_PART;
  EXCEPTION
  WHEN OTHERS THEN
    OPEN TMPCURSOR FOR
    SELECT -1 AS CODPART;
  END;

  WME_Result := TMPCURSOR;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_clienti_agent_4php</obj_name>
  <obj_hashval>218779a9dc5ab7390a7d0e468fe8d962</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_clienti_agent_4php(refcursor, numeric)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
DECLARE
  TMPCURSOR REFCURSOR;
begin
  BEGIN
    OPEN $1 FOR
    SELECT  DISTINCT P.CODPART, (SELECT translate(P.DEN_PART, 'ÂâÎî', 'AaIi')   AS DEN_PART), COALESCE (M.CODMONEDA, 0) AS CODMONEDA, M.SIMBOL AS SIMBOL_MONEDA,
            CF.COD_CODFISCAL, CF.CODFISCAL, P.CODEXTERN
    FROM NAGENDA             A, NPART P
      LEFT JOIN NMONEDE      M  ON M.CODMONEDA = COALESCE (P.CODMONEDA, 0)
      LEFT JOIN NPARTCODFISC CF ON CF.CODPART = P.CODPART AND CF.PRINCIPAL = 1
    WHERE
      A.TIP = 0
      AND COALESCE (A.CODAGENT, 0) = $2
      AND A.CODPART = P.CODPART
    ORDER BY
      DEN_PART;
  EXCEPTION
  WHEN OTHERS THEN
    OPEN $1 FOR
    SELECT -1 AS CODPART;
  END;

  return next $1;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_detalii_comanda</obj_name>
  <obj_hashval>3e914d17d7b581148069293d5ae0c60e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_detalii_comanda(INOUT wme_result refcursor, INOUT acodcomanda numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
  DECLARE
    S varchar;
    COMANDA1CURSOR REFCURSOR;
  begin
    S := '
      SELECT C1.CODOBIECT, O.DENUMIRE, U1.DEN_UM1, C1.PU,
        C1.CANTCOMANDAT, C1.CANTACCEPTAT , C1.CANTACCEPTAT - C1.RESTACCEPTAT AS FACTURAT, C1.OBS,
        C1.TERMEN, C1.D1, C1.D2, C1.D3,
        C1.ACCEPTUM1, C1.CANTUM1, C1.PROCDISC
      FROM COMANDA1 C1, NARTOBJ O, NUM1 U1
      WHERE
        C1.CODCOMANDA = '
    || coalesce ( (aCODCOMANDA) ::varchar ,'')
    || '

          AND C1.UMSEC = U1.CODUM1

          AND O.CODOBIECT = C1.CODOBIECT';
    OPEN COMANDA1CURSOR FOR execute S;
    WME_Result := COMANDA1CURSOR;
    RETURN;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_detalii_comanda_4php</obj_name>
  <obj_hashval>5f48376a311af5c847a28271c5478168</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_detalii_comanda_4php(refcursor, numeric)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
  DECLARE
    S varchar;
    COMANDA1CURSOR REFCURSOR;
  begin
    S := '
      SELECT C1.CODOBIECT, O.DENUMIRE, U1.DEN_UM1, C1.PU,
        C1.CANTCOMANDAT, C1.CANTACCEPTAT , C1.CANTACCEPTAT - C1.RESTACCEPTAT AS FACTURAT, C1.OBS,
        C1.TERMEN, C1.D1, C1.D2, C1.D3,
        C1.ACCEPTUM1, C1.CANTUM1, C1.PROCDISC,
    O.CODEXTERN, O.CODINTERN
      FROM COMANDA1 C1, NARTOBJ O,
    NUM1 U1, COMANDA C
      WHERE
        C1.CODCOMANDA = '
    || coalesce ( ($2) ::varchar ,'')
    || '
    AND C.CODCOMANDA = C1.CODCOMANDA
          AND C1.UMSEC = U1.CODUM1
          AND O.CODOBIECT = C1.CODOBIECT';
    OPEN $1 FOR EXECUTE S;
    return next $1;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_detalii_comanda_tva</obj_name>
  <obj_hashval>4937c83a3caf42172a62f0a32f9772c8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_detalii_comanda_tva(INOUT wme_result refcursor, INOUT acodcomanda numeric, INOUT atogglevat numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
  DECLARE
    S           varchar;
    AN          numeric;
    LUNA        numeric;
    COMPUTE_VAT varchar := ' coalesce(C1.PU, 0) ';
    COMANDA2CURSOR REFCURSOR;
  begin
    AN   := EXTRACT (YEAR FROM CURRENT_TIMESTAMP);
    LUNA := EXTRACT (MONTH FROM CURRENT_TIMESTAMP);
    PERFORM PKG_GLOBALS_SETLUNALUCRU_SIMPLA (AN, Luna);
    PERFORM PKG_STOC_GENERARE_FACTURI_make_config_luna_EXT();
    IF COALESCE (aToggleVAT, 0) = 1 THEN
      COMPUTE_VAT := ' ROUND(coalesce(C1.PU, 0) * (1 + coalesce(TVAL.PROCENT, 0) / 100), 2) ';
    END IF;
    S := '
        SELECT distinct C1.CODOBIECT, O.DENUMIRE, U1.DEN_UM1, O.CODEXTERN,
          O.CODINTERN, N.CODEXTERNART
            ||N.SUFIXCODEXTERN                                               AS CODCATALOG, C1.PU, coalesce (TVAL.PROCENT, 0) AS TVA, '
    || coalesce (COMPUTE_VAT,'')
    || ' AS PRET_TVA,
          C1.CANTCOMANDAT, C1.CANTACCEPTAT , C1.CANTACCEPTAT - C1.RESTACCEPTAT AS FACTURAT, C1.OBS,
          C1.TERMEN, C1.D1, C1.D2, C1.D3,
          C1.ACCEPTUM1, C1.CANTUM1, C1.PRETORIG, C1.PROCDISC,
          C1.ADDIM
        FROM COMANDA1                     C1, NUM1 U1, NART N, NARTOBJ O
          LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = O.CODARTICOL
          LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA = NAL.CODTVA
        WHERE
          C1.CODCOMANDA = '
    || coalesce ( (aCODCOMANDA) ::varchar::varchar ,'')
    || '
          AND C1.UMSEC = U1.CODUM1
          AND O.CODARTICOL = N.CODARTICOL
          AND O.CODOBIECT = C1.CODOBIECT';
    OPEN COMANDA2CURSOR for EXECUTE S;
    WME_Result := COMANDA2CURSOR;
    RETURN;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_detalii_comanda_tva_4php</obj_name>
  <obj_hashval>dabb426ed565edafc43af82e395a5f2b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_detalii_comanda_tva_4php(refcursor, numeric, numeric)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
  DECLARE
    S           varchar;
    AN          numeric;
    LUNA        numeric;
    COMPUTE_VAT varchar := ' coalesce(C1.PU, 0) ';
    COMANDA2CURSOR REFCURSOR;
  begin
    AN   := EXTRACT (YEAR FROM CURRENT_TIMESTAMP);
    LUNA := EXTRACT (MONTH FROM CURRENT_TIMESTAMP);
    PERFORM PKG_GLOBALS_SETLUNALUCRU_SIMPLA (AN, Luna);
/*    PERFORM PKG_STOC_GENERARE_FACTURI_make_config_luna_EXT(); */
     perform pkg_stoc_generare_facturi_make_config_luna();
    IF COALESCE ($3, 0) = 1 THEN
      COMPUTE_VAT := ' ROUND(coalesce(C1.PU, 0) * (1 + coalesce(TVAL.PROCENT, 0) / 100), 2) ';
    END IF;
    S := '
        SELECT distinct C1.CODOBIECT, O.DENUMIRE, U1.DEN_UM1, O.CODEXTERN,
          O.CODINTERN, N.CODEXTERNART
            ||N.SUFIXCODEXTERN                                               AS CODCATALOG, C1.PU, coalesce (TVAL.PROCENT, 0) AS TVA, '
    || coalesce (COMPUTE_VAT,'')
    || ' AS PRET_TVA,
          C1.CANTCOMANDAT, C1.CANTACCEPTAT , C1.CANTACCEPTAT - C1.RESTACCEPTAT AS FACTURAT, C1.OBS,
          C1.TERMEN, C1.D1, C1.D2, C1.D3,
          C1.ACCEPTUM1, C1.CANTUM1, C1.PRETORIG, C1.PROCDISC,
          C1.ADDIM
        FROM COMANDA1                     C1, NUM1 U1, NART N, NARTOBJ O
          LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = O.CODARTICOL
          LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA = NAL.CODTVA
        WHERE
          C1.CODCOMANDA = '
    || coalesce ( ($2) ::varchar::varchar ,'')
    || '
          AND C1.UMSEC = U1.CODUM1
          AND O.CODARTICOL = N.CODARTICOL
          AND O.CODOBIECT = C1.CODOBIECT';
    OPEN $1 FOR EXECUTE S;
    return next $1;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_detalii_oferta_4php</obj_name>
  <obj_hashval>192ee14d87f455d56966bfe00d563d4a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_detalii_oferta_4php(refcursor, numeric)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
  DECLARE
    S varchar;
    OFERTA1CURSOR REFCURSOR;
  begin
    S := '
      SELECT O1.CODOFERTA1, N.DENUMIRE, O1.PRET, O1.CANTMIN,
        O1.ZILEL, O1.ZILEC, O1.PROCDISCOUNT, O1.OBS,
        O1.CODOBIECT, N.CODARTICOL, U1.DEN_UM1, O1.CODOFERTA,
        O1.UMSEC, O1.PROCADAOS, O1.D1, O1.D2,
        O1.D3, O1.INDEXLOCAL, O1.PRETREF,
    N.CODEXTERN, N.CODINTERN
      FROM OFERTA1 O1, NARTOBJ N,
    NUM1 U1, OFERTA O
      WHERE
        O1.CODOFERTA = '
          || coalesce ( ($2) ::varchar::varchar ,'')
          || '
    AND O.CODOFERTA = O1.CODOFERTA
        AND O1.UMSEC = U1.CODUM1
        AND O1.CODOBIECT = N.CODOBIECT
      ORDER BY
        O1.INDEXLOCAL ';
    OPEN $1 FOR EXECUTE S;
    return next $1;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_detalii_oferta_tva</obj_name>
  <obj_hashval>33db53a071621b9d691061bce6c8a030</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_detalii_oferta_tva(INOUT wme_result refcursor, INOUT acodoferta numeric, INOUT atogglevat numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
  DECLARE
    S           varchar;
    AN          numeric;
    LUNA        numeric;
    COMPUTE_VAT varchar := ' coalesce(O1.PRET, 0) ';
    OFERTA2CURSOR REFCURSOR;
  begin
    AN   := EXTRACT (YEAR FROM CURRENT_TIMESTAMP);
    LUNA := EXTRACT (MONTH FROM CURRENT_TIMESTAMP);
    PERFORM PKG_GLOBALS_SETLUNALUCRU_SIMPLA (AN, Luna);
    PERFORM PKG_STOC_GENERARE_FACTURI_make_config_luna_EXT();
    IF COALESCE (aToggleVAT, 0) = 1 THEN
      COMPUTE_VAT := ' ROUND(coalesce(O1.PRET, 0) * (1 + coalesce(TVAL.PROCENT, 0) / 100), 2) ';
    END IF;
    S := '
        SELECT distinct                                  O1.CODOFERTA1, N.DENUMIRE, O1.PRET, coalesce (TVAL.PROCENT, 0) AS TVA,
          '
            || coalesce (COMPUTE_VAT,'')
            || ' AS PRET_TVA , O1.CANTMIN, O1.ZILEL, O1.ZILEC,
          O1.PROCDISCOUNT, O1.OBS, O1.CODOBIECT, N.CODARTICOL,
          U1.DEN_UM1, O1.CODOFERTA, O1.UMSEC, O1.PROCADAOS,
          O1.D1, O1.D2, O1.D3, O1.INDEXLOCAL,
          O1.PRETREF, NART.CODEXTERNART
            ||NART.SUFIXCODEXTERN     AS CODCATALOG, N.CODEXTERN, N.CODINTERN
        FROM OFERTA1                         O1, NUM1 U1, NART, NARTOBJ N
          LEFT OUTER JOIN TMP_NART_LUNA    NAL  ON NAL.CODARTICOL = N.CODARTICOL
          LEFT OUTER JOIN TMP_NTVA_LUNA    TVAL ON TVAL.CODTVA = NAL.CODTVA
        WHERE
          O1.CODOFERTA = '
            || coalesce ( (aCODOFERTA) ::varchar::varchar ,'')
            || '
          AND O1.UMSEC = U1.CODUM1
          AND O1.CODOBIECT = N.CODOBIECT
          AND N.CODARTICOL = NART.CODARTICOL
        ORDER BY
          O1.INDEXLOCAL ';
    OPEN OFERTA2CURSOR FOR execute S;
    WME_Result := OFERTA2CURSOR;
    RETURN;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_detalii_oferta_tva_4php</obj_name>
  <obj_hashval>66c551bcfedd33bb5444f83c23cb1ece</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_detalii_oferta_tva_4php(refcursor, numeric, numeric)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
  DECLARE
    S           varchar;
    AN          numeric;
    LUNA        numeric;
    COMPUTE_VAT varchar := ' coalesce(O1.PRET, 0) ';
    OFERTA2CURSOR REFCURSOR;
  begin
    AN   := EXTRACT (YEAR FROM CURRENT_TIMESTAMP);
    LUNA := EXTRACT (MONTH FROM CURRENT_TIMESTAMP);
    PERFORM PKG_GLOBALS_SETLUNALUCRU_SIMPLA (AN, Luna);
/*    PERFORM PKG_STOC_GENERARE_FACTURI_make_config_luna_EXT(); */
     perform pkg_stoc_generare_facturi_make_config_luna();
    IF COALESCE ($3, 0) = 1 THEN
      COMPUTE_VAT := ' ROUND(coalesce(O1.PRET, 0) * (1 + coalesce(TVAL.PROCENT, 0) / 100), 2) ';
    END IF;
    S := '
        SELECT distinct                                  O1.CODOFERTA1, N.DENUMIRE, O1.PRET, coalesce (TVAL.PROCENT, 0) AS TVA,
          '
            || coalesce (COMPUTE_VAT,'')
            || ' AS PRET_TVA , O1.CANTMIN, O1.ZILEL, O1.ZILEC,
          O1.PROCDISCOUNT, O1.OBS, O1.CODOBIECT, N.CODARTICOL,
          U1.DEN_UM1, O1.CODOFERTA, O1.UMSEC, O1.PROCADAOS,
          O1.D1, O1.D2, O1.D3, O1.INDEXLOCAL,
          O1.PRETREF, NART.CODEXTERNART
            ||NART.SUFIXCODEXTERN     AS CODCATALOG, N.CODEXTERN, N.CODINTERN
        FROM OFERTA1                         O1, NUM1 U1, NART, NARTOBJ N
          LEFT OUTER JOIN TMP_NART_LUNA    NAL  ON NAL.CODARTICOL = N.CODARTICOL
          LEFT OUTER JOIN TMP_NTVA_LUNA    TVAL ON TVAL.CODTVA = NAL.CODTVA
        WHERE
          O1.CODOFERTA = '
            || coalesce ( ($2) ::varchar::varchar ,'')
            || '
          AND O1.UMSEC = U1.CODUM1
          AND O1.CODOBIECT = N.CODOBIECT
          AND N.CODARTICOL = NART.CODARTICOL
        ORDER BY
          O1.INDEXLOCAL ';
    OPEN $1 FOR EXECUTE S;
  return next $1;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_oferte_agent</obj_name>
  <obj_hashval>4ff36a0f44fc734a34a5bcf0e33350c4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_oferte_agent(INOUT wme_result refcursor, INOUT acodpers numeric, INOUT adenpart character varying, INOUT adataref character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
  DECLARE
    S varchar;
    OFERTACURSOR REFCURSOR;
    FILTRU_PART varchar := '';
  begin
    IF COALESCE (aDENPART, '?') &lt;&gt; '?' THEN
      FILTRU_PART := coalesce (' AND UPPER(DEN_PART) LIKE '
      || '''%','')
      || coalesce (UPPER (aDENPART) ,'')
      || '%''';
    END IF;
    S := '
      SELECT *
      FROM (   SELECT OFE.*
          FROM (   SELECT CODOFERTA, TIPDOC, ANULAT, BLOCAT,
                OPERAT, SERIE, NRDOC, DATASTART,
                DATAEND, PARTENER, AN, LUNA,
                OBS, MONEDA, CODLOCATIE, SUBUNITATEA,
                CODFISCAL, USERID, DATACREARE, DATAOFERTA,
                PE_CLASA, DEN_PART, DEN_MONEDA, DEN_LOCALIT,
                SUBUNITATEDOC, SEDIU, NUMEAGENT, PCNume,
                PCTel, PCEmail, Aprobari, NRI,
                Utilizator, Valoare
              FROM (   SELECT O.CODOFERTA, O.TIPDOC, O.ANULAT, O.BLOCAT,
                    O.OPERAT, C.SERIE, O.NRDOC, O.DATASTART,
                    O.DATAEND, O.PARTENER, O.AN, O.LUNA,
                    O.OBS, O.MONEDA, O.CODLOCATIE, O.SUBUNITATEA,
                    O.CODFISCAL, O.USERID, O.DATACREARE, O.DATAOFERTA,
                    (case when O.TipBeneficiar = 1 then ''DA'' else ''NU'' end) PE_CLASA,
                    Coalesce (P.Den_Part, CP.Den_Clasep, ''...'') Den_Part, M.Den_Moneda, L.Den_Localit,
                    S.DEN_SUBUNIT       SUBUNITATEDOC, SED.OBS SEDIU,
                    (case when A.CodPers = 0 then A.Nume else A.NUME||'' ''||A.PRENUME end) NUMEAGENT,
                    O.NRI, PC.Nume
                      ||'' ''
                      ||PC.Prenume PCNume, PC.TELEFON PCTel, PC.EMAIL PCEmail, UT.UserName Utilizator, (   SELECT Sum (coalesce (O1.CANTMIN * O1.PRET * Coalesce (1 + O1.PROCADAOS / 100,1) * Coalesce (1 + O1.ProcDiscount / 100,1) ,0))
                      FROM OFERTA1 O1
                      WHERE
                        O1.CodOferta = O.CodOferta) Valoare, '' '' AS Aprobari
                  FROM OFERTA                             O
                    LEFT JOIN NPART                     P   ON coalesce (O.Partener, 0) = P.Codpart AND coalesce (TipBeneficiar, 0) = 0
                    LEFT JOIN NCLASEP                   CP  ON coalesce (O.CodClaseP, 0) = CP.CodClaseP AND coalesce (TipBeneficiar, 0) = 1
                    LEFT JOIN NAGENDA                   SED ON SED.Codagenda = O.CodLocatie
                    LEFT JOIN NLOCALIT                  L   ON L.Codlocalit = SED.CodLocalit
                    LEFT JOIN NMONEDE                   M   ON M.CodMoneda = O.Moneda
                    LEFT JOIN NSUBUNIT                  S   ON S.CODSUBUNIT = O.SUBUNITATEA
                    LEFT JOIN NPERS                     A   ON A.CODPERS = coalesce (O.AGENT,0)
                    LEFT JOIN NPERSCONTACT              PC  ON PC.CodPart = P.CodPart AND PC.CodPersC = O.CodPersC
                    LEFT JOIN DOCCARNETE                C   ON C.CODCARNET = O.CARNETDOC
                    LEFT JOIN TMP_UTILIZATOR            UT  ON UT.CODUTILIZATOR = O.USERID
                  WHERE
                    O.TipDoc = 50
                    AND O.AGENT = '
    || coalesce ( (aCODPERS) ::varchar::varchar ,'')
    || '
                    AND DATASTART &lt;= TO_DATE ('''
    || coalesce (To_Char (aDATAREF,'dd.mm.yyyy') ,'')
    || ''',''DD - MM - YYYY'')
                    AND DATAEND &gt;= TO_DATE ('''
    || coalesce (To_Char (aDATAREF,'dd.mm.yyyy') ,'')
    || ''',''DD   - MM - YYYY'')
                    AND (coalesce (O.ToateSubunit,0) = 1
                      or O.SUBUNITATEA = PKG_GLOBALS_GETSUBUNITATE))) OFE)
      WHERE
        1 = 1'
    || coalesce (Filtru_Part,'');
    OPEN OFERTACURSOR for execute S;
    WME_Result := OFERTACURSOR;
    RETURN;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_oferte_agent_4php</obj_name>
  <obj_hashval>7a3ec216fe5e5c1ce22d1855cce204a8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_oferte_agent_4php(refcursor, numeric, character varying, character varying)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
  DECLARE
    S varchar;
    OFERTACURSOR REFCURSOR;
    FILTRU_PART varchar := '';
  begin
    IF COALESCE ($3, '?') &lt;&gt; '?' THEN
      FILTRU_PART := coalesce (' AND UPPER(DEN_PART) LIKE '
      || '''%','')
      || coalesce (UPPER ($3) ,'')
      || '%''';
    END IF;
    S := '
      SELECT *
      FROM (   SELECT OFE.*
          FROM (   SELECT CODOFERTA, TIPDOC, ANULAT, BLOCAT,
                OPERAT, SERIE, NRDOC, DATASTART,
                DATAEND, PARTENER, AN, LUNA,
                OBS, MONEDA, CODLOCATIE, SUBUNITATEA,
                CODFISCAL, USERID, DATACREARE, DATAOFERTA,
                PE_CLASA, DEN_PART, DEN_MONEDA, DEN_LOCALIT,
                SUBUNITATEDOC, SEDIU, NUMEAGENT, PCNume,
                PCTel, PCEmail, Aprobari, NRI,
                Utilizator, Valoare
              FROM (   SELECT O.CODOFERTA, O.TIPDOC, O.ANULAT, O.BLOCAT,
                    O.OPERAT, C.SERIE, O.NRDOC, O.DATASTART,
                    O.DATAEND, O.PARTENER, O.AN, O.LUNA,
                    O.OBS, O.MONEDA, O.CODLOCATIE, O.SUBUNITATEA,
                    O.CODFISCAL, O.USERID, O.DATACREARE, O.DATAOFERTA,
                    (case when O.TipBeneficiar = 1 then ''DA'' else ''NU'' end) PE_CLASA,
                    Coalesce (P.Den_Part, CP.Den_Clasep, ''...'') Den_Part, M.Den_Moneda, L.Den_Localit,
                    S.DEN_SUBUNIT       SUBUNITATEDOC, SED.OBS SEDIU,
                    (case when A.CodPers = 0 then A.Nume else A.NUME||'' ''||A.PRENUME end) NUMEAGENT,
                    O.NRI, PC.Nume
                      ||'' ''
                      ||PC.Prenume PCNume, PC.TELEFON PCTel, PC.EMAIL PCEmail, UT.UserName Utilizator, (   SELECT Sum (coalesce (O1.CANTMIN * O1.PRET * Coalesce (1 + O1.PROCADAOS / 100,1) * Coalesce (1 + O1.ProcDiscount / 100,1) ,0))
                      FROM OFERTA1 O1
                      WHERE
                        O1.CodOferta = O.CodOferta) Valoare, '' '' AS Aprobari
                  FROM OFERTA                             O
                    LEFT JOIN NPART                     P   ON coalesce (O.Partener, 0) = P.Codpart AND coalesce (TipBeneficiar, 0) = 0
                    LEFT JOIN NCLASEP                   CP  ON coalesce (O.CodClaseP, 0) = CP.CodClaseP AND coalesce (TipBeneficiar, 0) = 1
                    LEFT JOIN NAGENDA                   SED ON SED.Codagenda = O.CodLocatie
                    LEFT JOIN NLOCALIT                  L   ON L.Codlocalit = SED.CodLocalit
                    LEFT JOIN NMONEDE                   M   ON M.CodMoneda = O.Moneda
                    LEFT JOIN NSUBUNIT                  S   ON S.CODSUBUNIT = O.SUBUNITATEA
                    LEFT JOIN NPERS                     A   ON A.CODPERS = coalesce (O.AGENT,0)
                    LEFT JOIN NPERSCONTACT              PC  ON PC.CodPart = P.CodPart AND PC.CodPersC = O.CodPersC
                    LEFT JOIN DOCCARNETE                C   ON C.CODCARNET = O.CARNETDOC
                    LEFT JOIN TMP_UTILIZATOR            UT  ON UT.CODUTILIZATOR = O.USERID
                  WHERE
                    O.TipDoc = 50
                    AND O.AGENT = '
    || coalesce ( ($2) ::varchar::varchar ,'')
    || '
                    AND DATASTART &lt;= TO_DATE ('''
    || $4
    || ''',''DD-MM-YYYY'')
                    AND DATAEND &gt;= TO_DATE ('''
    || $4
    || ''',''DD-MM-YYYY'')
                    AND (coalesce (O.ToateSubunit,0) = 1
                      or O.SUBUNITATEA = ' || (current_setting('PKG_GLOBALS.SUBUNITATE', True))::numeric || ')) OF1) OFE) OF2
      WHERE
        1 = 1'
    || coalesce (Filtru_Part,'');
    OPEN $1 FOR EXECUTE S;
  return next $1;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_pret_oferta</obj_name>
  <obj_hashval>db96ef4730c16134c6225d21d1332374</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_pret_oferta(INOUT wme_result refcursor, INOUT acodpart numeric, INOUT acodmoneda numeric, INOUT acodobiect numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
  DECLARE
    S varchar;
    aPRETOFERTA_CURSOR REFCURSOR;
  BEGIN
    --Florin 19.09.2024 - sysdate
    S := '
        SELECT PRET, SIMBOL, NrDoc, DATAOFERTA,
          DATASTART, DATAEND, CANTMIN, ZILEL,
          ZILEC, PROCDISCOUNT, O1.OBS, O1.PROCADAOS
        FROM OFERTA O, OFERTA1 O1, NMONEDE M
        WHERE
          O1.CODOBIECT = '
            || coalesce ( (aCODOBIECT) ::varchar,'')
            || '
          AND O.CODOFERTA = O1.CODOFERTA
          AND O.TIPDOC = 50
          AND O.OPERAT = 1
          AND O.ANULAT = 0
          AND M.CODMONEDA = O.MONEDA
          AND O.MONEDA = '
            || coalesce ( (aCODMONEDA) ::varchar,'')
            || '
          AND O.DATASTART &lt;= current_date
          AND O.DATAEND &gt;= current_date
          AND (PARTENER = '
            || coalesce ( (aCODPART) ::varchar,'')
            || '
            OR coalesce (PARTENER, 0) = 0)
        ORDER BY
          NrDoc';
    OPEN aPRETOFERTA_CURSOR for execute S;
    WME_Result := aPRETOFERTA_CURSOR;
    RETURN;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_pret_oferta_4php</obj_name>
  <obj_hashval>ec7aeb80631334af6e6b5c3e6ddf0cb6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_pret_oferta_4php(refcursor, numeric, numeric, numeric)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
  DECLARE
    S varchar;
    aPRETOFERTA_CURSOR REFCURSOR;
  begin
    S := '
        SELECT PRET, SIMBOL, NrDoc, DATAOFERTA,
          DATASTART, DATAEND, CANTMIN, ZILEL,
          ZILEC, PROCDISCOUNT, O1.OBS, O1.PROCADAOS
        FROM OFERTA O, OFERTA1 O1, NMONEDE M
        WHERE
          O1.CODOBIECT = '
            || coalesce ( ($4) ::varchar,'')
            || '
          AND O.CODOFERTA = O1.CODOFERTA
          AND O.TIPDOC = 50
          AND O.OPERAT = 1
          AND O.ANULAT = 0
          AND M.CODMONEDA = O.MONEDA
          AND O.MONEDA = '
            || coalesce ( ($3) ::varchar,'')
            || '
          AND O.DATASTART &lt;= CURRENT_DATE
          AND O.DATAEND &gt;= CURRENT_DATE
          AND (PARTENER = '
            || coalesce ( ($2) ::varchar,'')
            || '
            OR coalesce (PARTENER, 0) = 0)
        ORDER BY
          NrDoc';
    OPEN $1 FOR EXECUTE S;
  return next $1;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_pret_oferta_agent</obj_name>
  <obj_hashval>69a8e13068c11e95566a9402b6e3d86c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_pret_oferta_agent(INOUT wme_result refcursor, INOUT acodpart numeric, INOUT acodmoneda numeric, INOUT acodobiect numeric, INOUT acodpers numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
  DECLARE
    S varchar;
    aPRETOFERTA_CURSOR REFCURSOR;
  BEGIN
    --Florin 19.09.2024 - sysdate
    S := '
        SELECT PRET, SIMBOL, NrDoc, DATAOFERTA,
          DATASTART, DATAEND, CANTMIN, ZILEL,
          ZILEC, PROCDISCOUNT, O1.OBS, O1.PROCADAOS,
          CODMONEDA
        FROM OFERTA O, OFERTA1 O1, NMONEDE M
        WHERE
          O1.CODOBIECT = '
            || coalesce ( (aCODOBIECT) ::varchar ,'')
            || '
          AND O.CODOFERTA = O1.CODOFERTA
          AND O.TIPDOC = 50
          AND O.OPERAT = 1
          AND O.ANULAT = 0
          AND M.CODMONEDA = O.MONEDA
          AND O.MONEDA = '
            || coalesce ( (aCODMONEDA) ::varchar ,'')
            || '
          AND O.DATASTART &lt;= current_date
          AND O.DATAEND &gt;= current_date
          AND (PARTENER = '
            || coalesce ( (aCODPART) ::varchar ,'')
            || '
            OR coalesce (PARTENER, 0) = 0)
          AND (O.AGENT = '
            || coalesce ( (aCODPERS) ::varchar ,'')
            || '
            OR O.AGENT = 0)
        ORDER BY
          NrDoc';
    OPEN aPRETOFERTA_CURSOR for execute S;
    WME_Result := aPRETOFERTA_CURSOR;
    RETURN;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_pret_oferta_agent_4php</obj_name>
  <obj_hashval>62853e487fe6ce6973bbf42088990870</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_pret_oferta_agent_4php(refcursor, numeric, numeric, numeric, numeric)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
  DECLARE
    S varchar;
    aPRETOFERTA_CURSOR REFCURSOR;
  begin
    S := '
        SELECT PRET, SIMBOL, NrDoc, DATAOFERTA,
          DATASTART, DATAEND, CANTMIN, ZILEL,
          ZILEC, PROCDISCOUNT, O1.OBS, O1.PROCADAOS,
          CODMONEDA, O1.CODOFERTA1
        FROM OFERTA O, OFERTA1 O1, NMONEDE M
        WHERE
          O1.CODOBIECT = '
            || coalesce ( ($4) ::varchar ,'')
            || '
          AND O.CODOFERTA = O1.CODOFERTA
          AND O.TIPDOC = 50
          AND O.OPERAT = 1
          AND O.ANULAT = 0
          AND M.CODMONEDA = O.MONEDA
          AND O.MONEDA = '
            || coalesce ( ($3) ::varchar ,'')
            || '
          AND O.DATASTART &lt;= CURRENT_DATE
          AND O.DATAEND &gt;= CURRENT_DATE
          AND (PARTENER = '
            || coalesce ( ($2) ::varchar ,'')
            || '
            OR coalesce (PARTENER, 0) = 0)
          AND (O.AGENT = '
            || coalesce ( ($5) ::varchar ,'')
            || '
            OR O.AGENT = 0)
        ORDER BY
          NrDoc';
    OPEN $1 FOR EXECUTE S;
  return next $1;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_pret_oferta_agent_valuta</obj_name>
  <obj_hashval>b8ee520feb6ff474ffd84157603a49b7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_pret_oferta_agent_valuta(INOUT wme_result refcursor, INOUT acodpart numeric, INOUT acodobiect numeric, INOUT acodpers numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
  DECLARE
    S varchar;
    aPRETOFERTA_CURSOR REFCURSOR;
  begin
    S := '
        SELECT PRET, SIMBOL, NrDoc, DATAOFERTA,
          DATASTART, DATAEND, CANTMIN, ZILEL,
          ZILEC, PROCDISCOUNT, O1.OBS, O1.PROCADAOS,
          CODMONEDA
        FROM OFERTA O, OFERTA1 O1, NMONEDE M
        WHERE
          O1.CODOBIECT = '
        || coalesce ( (aCODOBIECT) ::varchar ,'')
        || '
          AND O.CODOFERTA = O1.CODOFERTA
          AND O.TIPDOC = 50
          AND O.OPERAT = 1
          AND O.ANULAT = 0
          AND M.CODMONEDA = O.MONEDA
          AND O.DATASTART &lt;= current_date
          AND O.DATAEND &gt;= current_date
          AND (PARTENER = '|| TO_CHAR(aCODPART) ||'  OR NVL(PARTENER, 0) = 0 OR CODCLASEP = (SELECT CODCLASA FROM NPART WHERE CODPART = '|| TO_CHAR(aCODPART) ||')  )
          AND (O.AGENT = ' || TO_CHAR(aCODPERS) || ' OR NVL(O.AGENT, 0) = 0)
        ORDER BY NrDoc';
    OPEN aPRETOFERTA_CURSOR FOR execute S;
    WME_Result := aPRETOFERTA_CURSOR;
    RETURN;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_pret_oferta_agent_valuta_4php</obj_name>
  <obj_hashval>a32cb4150dde2707d7c8227f7b799971</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_pret_oferta_agent_valuta_4php(refcursor, numeric, numeric, numeric)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
  DECLARE
    S varchar;
    aPRETOFERTA_CURSOR REFCURSOR;
  begin
    S := '
        SELECT PRET, SIMBOL, NrDoc, DATAOFERTA,
          DATASTART, DATAEND, CANTMIN, ZILEL,
          ZILEC, PROCDISCOUNT, O1.OBS, O1.PROCADAOS,
          CODMONEDA, O1.CODOFERTA1
        FROM OFERTA O, OFERTA1 O1, NMONEDE M
        WHERE
          O1.CODOBIECT = '
        || coalesce ( ($3) ::varchar ,'')
        || '
          AND O.CODOFERTA = O1.CODOFERTA
          AND O.TIPDOC = 50
          AND O.OPERAT = 1
          AND O.ANULAT = 0
          AND M.CODMONEDA = O.MONEDA
          AND O.DATASTART &lt;= CURRENT_DATE
          AND O.DATAEND &gt;= CURRENT_DATE
          AND (PARTENER = '
        || coalesce ( ($2) ::varchar ,'')
        || '
            OR coalesce (PARTENER, 0) = 0
      OR CODCLASEP = (SELECT CODCLASA FROM NPART WHERE CODPART = ' || coalesce ( ($2) ::varchar ,'') || ')
      )
          AND (O.AGENT = '
        || coalesce ( ($4) ::varchar ,'')
        || '
            OR coalesce(O.AGENT, 0) = 0)
        ORDER BY
          NrDoc';
    OPEN $1 FOR EXECUTE S;
  return next $1;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_sedii_client</obj_name>
  <obj_hashval>6fad4b2e216d5a035f722e438d600780</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_sedii_client(INOUT wme_result refcursor, INOUT acodpart numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
  DECLARE
    TMPCURSOR REFCURSOR;
  begin
    BEGIN
      OPEN TMPCURSOR FOR
      SELECT A.CODAGENDA, A.OBS  AS SEDIU, L.DEN_LOCALIT, (   SELECT getadresa.WME_RESULT
          FROM getadresa (NULL,A.SECTOR, A.STRADA, A.NR1, A.NR2, A.BLOC, A.SCARA, A.ETAJ, A.APART, A.CODPOSTAL)) AS ADRESA
      FROM NAGENDA                                                                                                      A, NLOCALIT L
      WHERE
        A.TIP = 0
        AND A.CODPART = aCODPART
        AND L.CODLOCALIT = A.CODLOCALIT;

    EXCEPTION
    WHEN OTHERS THEN
      OPEN TMPCURSOR FOR
      SELECT -1 AS CODAGENDA;

    END;
    WME_Result := TMPCURSOR;
    RETURN;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_sedii_client_4php</obj_name>
  <obj_hashval>55f792979d126317974211f16d3e13b9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_sedii_client_4php(refcursor, numeric)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
  DECLARE
    TMPCURSOR REFCURSOR;
  begin
    BEGIN
      OPEN $1 FOR
      SELECT A.CODAGENDA, A.OBS  AS SEDIU, L.DEN_LOCALIT, (   SELECT getadresa.WME_RESULT
          FROM getadresa (NULL,A.SECTOR, A.STRADA, A.NR1, A.NR2, A.BLOC, A.SCARA, A.ETAJ, A.APART, A.CODPOSTAL)) AS ADRESA
      FROM NAGENDA A, NLOCALIT L
      WHERE
        A.TIP = 0
        AND A.CODPART = $2
        AND L.CODLOCALIT = A.CODLOCALIT;

    EXCEPTION
    WHEN OTHERS THEN
      OPEN $1 FOR
      SELECT -1 AS CODAGENDA;

    END;
    return next $1;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_sedii_client_for_agent</obj_name>
  <obj_hashval>8248de048b0dd9aa7bc493f66b7a5ae1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_sedii_client_for_agent(INOUT wme_result refcursor, INOUT acodpart numeric, INOUT acodpers numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
  DECLARE
    TMPCURSOR REFCURSOR;
  begin
    BEGIN
      OPEN TMPCURSOR FOR
      SELECT A.CODAGENDA, A.OBS  AS SEDIU, L.DEN_LOCALIT, (   SELECT getadresa.WME_RESULT
          FROM getadresa (NULL,A.SECTOR, A.STRADA, A.NR1, A.NR2, A.BLOC, A.SCARA, A.ETAJ, A.APART, A.CODPOSTAL)) AS ADRESA
      FROM NAGENDA  A, NLOCALIT L
      WHERE
        A.TIP = 0
        AND COALESCE (A.CODAGENT, 0) = aCODPERS
        AND A.CODPART = aCODPART
        AND L.CODLOCALIT = A.CODLOCALIT;

    EXCEPTION
    WHEN OTHERS THEN
      OPEN TMPCURSOR FOR
      SELECT -1 AS CODAGENDA;

    END;
    WME_Result := TMPCURSOR;
    RETURN;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_sedii_client_for_agent_4php</obj_name>
  <obj_hashval>74e232b74933ef982861bf5ceb5a0246</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_sedii_client_for_agent_4php(refcursor, numeric, numeric)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
  DECLARE
    TMPCURSOR REFCURSOR;
  begin
    BEGIN
      OPEN $1 FOR
      SELECT A.CODAGENDA, A.OBS  AS SEDIU, L.DEN_LOCALIT, (   SELECT getadresa.WME_RESULT
          FROM getadresa (NULL,A.SECTOR, A.STRADA, A.NR1, A.NR2, A.BLOC, A.SCARA, A.ETAJ, A.APART, A.CODPOSTAL)) AS ADRESA
      FROM NAGENDA  A, NLOCALIT L
      WHERE
        A.TIP = 0
        AND COALESCE (A.CODAGENT, 0) = $3
        AND A.CODPART = $2
        AND L.CODLOCALIT = A.CODLOCALIT;

    EXCEPTION
    WHEN OTHERS THEN
      OPEN $1 FOR
      SELECT -1 AS CODAGENDA;

    END;
    return next $1;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_getlistagestiuni</obj_name>
  <obj_hashval>ebd8080cffc20d019f5df098fa8c3ead</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_getlistagestiuni(INOUT wme_result refcursor, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
  DECLARE
    NGESTCURSOR REFCURSOR;
  begin
    OPEN NGESTCURSOR FOR
    SELECT G.CODGEST, (   SELECT TRANSLATE(G.DEN_GEST, '–', '-')) AS DEN_GEST, G.SIMBOL
    FROM TMP_GESTDEDICATE                      D, NGEST G
    WHERE
      G.CODGEST = D.CODGEST
      AND G.CODSUBUNIT = current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric
    ORDER BY
      DEN_GEST;

    WME_Result := NGESTCURSOR;
    RETURN;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_getlistagestiuni_4php</obj_name>
  <obj_hashval>0a48caf99c06c5bf6383ce39a4d9d467</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_getlistagestiuni_4php(refcursor, numeric)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
  DECLARE
    NGESTCURSOR REFCURSOR;
  begin
    OPEN $1 FOR
    SELECT G.CODGEST, (   SELECT TRANSLATE(G.DEN_GEST, '–', '-')) AS DEN_GEST, G.SIMBOL
    FROM TMP_GESTDEDICATE D, NGEST G
    WHERE
      G.CODGEST = D.CODGEST
      AND G.CODSUBUNIT = current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric
    ORDER BY
      DEN_GEST;

    return next $1;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_getstocuri_stoc0_fara_partener_4php</obj_name>
  <obj_hashval>bf5805f50014b19571db90449333aeb5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_getstocuri_stoc0_fara_partener_4php(refcursor, character varying, character varying, numeric, character varying, character varying, numeric)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
  DECLARE
    STOCCURSOR REFCURSOR;
    FILTRU_ART   varchar := '';
      FILTRU_CLASA varchar := '';
    FILTRU_GEST  varchar := '';
     FILTRU_CODEXTERN   varchar := '';
      FILTRU_CODINTERN   varchar := '';
      S           varchar;
      AN           numeric(5);
      LUNA         numeric(2);
      aCODCATPRET  numeric := 0;
      COMPUTE_VAT  varchar := ' coalesce(PM.LEI, 0) ';
      REVERSE_VAT  varchar := ' coalesce(PM.LEI, 0) ';
       var_table_varchar varchar array;
  begin
    AN   := EXTRACT(YEAR FROM current_date);
    LUNA := EXTRACT(MONTH FROM current_date);
    perform pkg_globals_setlunalucru_simpla(AN, Luna);
/*    perform pkg_stoc_generare_facturi_make_config_luna_ext(); */
     perform pkg_stoc_generare_facturi_make_config_luna();

    IF coalesce($7, 0) = 1 THEN
      COMPUTE_VAT := ' ROUND(coalesce(PM.LEI, 0) * (1 + coalesce(TVAL.PROCENT, 0) / 100), 2) ';
    END IF;

     IF coalesce($7, 0) = 1 THEN
      REVERSE_VAT := ' ROUND(coalesce(PM.LEI, 0) / (1 + coalesce(TVAL.PROCENT, 0) / 100), 2) ';
    END IF;

    S := ' SELECT distinct * FROM ' ||
         ' ( ' ||
         '    SELECT ' ||
         '      1 AS TIPARTICOL, ' ||
         '      O.DENUMIRE AS DENOBIECT, ' ||
         '      O.CODEXTERN, ' ||
         '      O.CODINTERN,' ||
       '      O.CODARTICOL,' ||
       '      O.INACTIV, ' ||
         '      A.DEN_ARTICOL AS DEN_ART,' ||
         '      A.UM1 AS DUM1,' ||
         '      A.COMENZIONLINE,' ||
         '      U0.DEN_UM1 AS DENUM1,' ||
         '      NULL as DEN_GEST, ' ||
         '      O.CODOBIECT, ' ||
         '      0 as CODGEST, ' ||

          '    CASE ' ||
         '      WHEN CAT.TIP = 1 THEN '|| REVERSE_VAT || ' ' ||
         '      ELSE coalesce(PM.LEI, 0) ' ||
         '    END  AS PRET, ' ||
         '      coalesce(TVAL.PROCENT, 0) AS TVA, ' ||
         '    CASE ' ||
         '      WHEN CAT.TIP = 1 THEN coalesce(PM.LEI, 0) ' ||
         '      ELSE '|| COMPUTE_VAT || ' ' ||
         '    END  AS PRET_TVA, ' ||

         '      0 AS STOC, ' ||
         '      P.DEN_PART AS PRODUCATOR, ' ||
         '      CLAS.DEN_CLASEA AS CLASA, ' ||
         '      U.DEN_UM, ' ||
         '      U1.CODUM1 ' ||
         '    FROM  ' ||
         '      NART A   ' ||
       '      LEFT OUTER JOIN NUM1 U0 ON U0.CODUM1 = A.UM1 ' ||
         '      LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = A.CODARTICOL  ' ||
         '      LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA = NAL.CODTVA ' ||
         '      LEFT OUTER JOIN NUM U ON U.CODUM = A.UM ' ||
         '      LEFT OUTER JOIN NUM1 U1 ON U1.CODUM = U.CODUM AND U1.SECUNDARA = 0' ||
         '      LEFT OUTER JOIN NCLASEA CLAS ON CLAS.CODCLASEA = CLASA, ' ||
         '      NARTOBJ O ' ||
         '      LEFT OUTER JOIN PRETM PM ON PM.CODOBIECT = O.CODOBIECT AND PM.IMPLICIT = 1' ||
         '      LEFT JOIN NCATPRET CAT ON CAT.CODCATPRET = PM.CODCATPRET ' ||
         '      LEFT OUTER JOIN NPART P ON P.CODPART = O.CODPRODUCATOR ' ||
         '    WHERE O.CODARTICOL = A.CODARTICOL AND coalesce(O.INACTIV, 0) &lt;&gt;1 AND coalesce(O.BLOCAT, 0) NOT IN (1, 3) AND ( (A.TIPARTICOL::integer = 1 ) OR (A.TIPARTICOL::integer = 0 AND ((SELECT COUNT(*) FROM NIRSTOC NS WHERE NS.CODOBIECT=O.CODOBIECT) = 0) and 2&gt; 1 ) ) ' ||
         ' UNION ALL ' ||
         ' SELECT ' ||
         '    0 AS TIPARTICOL, ' ||
         '    O.DENUMIRE AS DENOBIECT, ' ||
         '    O.CODEXTERN,' ||
         '    O.CODINTERN, ' ||
       '    O.CODARTICOL,' ||
       '      O.INACTIV, ' ||
         '    A.DEN_ARTICOL AS DEN_ART,' ||
         '    A.UM1 AS DUM1,' ||
         '      A.COMENZIONLINE,' ||
         '    U0.DEN_UM1 AS DENUM1,' ||
         '    G.DEN_GEST, ' ||
         '    STOCVIEW.CODOBIECT, ' ||
         '    STOCVIEW.CODGEST,' ||

         '    CASE ' ||
         '      WHEN CAT.TIP = 1 THEN '|| REVERSE_VAT || ' ' ||
         '      ELSE coalesce(PM.LEI, 0) ' ||
         '    END  AS PRET, ' ||
         '      coalesce(TVAL.PROCENT, 0) AS TVA, ' ||
         '    CASE ' ||
         '      WHEN CAT.TIP = 1 THEN coalesce(PM.LEI, 0) ' ||
         '      ELSE '|| COMPUTE_VAT || ' ' ||
         '    END  AS PRET_TVA, ' ||

         '    STOCVIEW.STOC, ' ||
         '    P.DEN_PART AS PRODUCATOR, ' ||
         '    CLAS.DEN_CLASEA AS CLASA, ' ||
         '    U.DEN_UM, ' ||
         '    U1.CODUM1 ' ||
         ' FROM ' ||
         '    ( ' ||  -- stoc cumulat
         '     SELECT CODOBIECT, CODGEST, SUM(STOC) AS STOC ' ||
         '     FROM ' ||
         '         ( ' ||
         '           SELECT  CODOBIECT, CODGEST, STOC FROM ' ||
         '                (  ' ||
         '                   SELECT ' ||
         '                      NS.CODOBIECT, ' ||
         '                      N.GEST AS CODGEST,' ||
         '                      SUM(NS.REST - coalesce((SELECT SUM(REST) FROM REZERVATS R WHERE R.CODNIRSTOC = NS.CODNIRSTOC), 0)) AS STOC ' ||
         '                   FROM ' ||
         '                      NIRSTOC NS  ' ||
         '                      LEFT OUTER JOIN TMP_IOART_LUNA IOAL ON IOAL.CODIOART = NS.CODIOART, ' ||
         '                      NIR     N ' ||
         '                   WHERE ' ||
  --     '                      NS.REST &gt;= 0 ' ||
         '                      N.CODNIR = NS.CODNIR ' ||
         '                      AND (((SELECT COUNT(*) FROM TMP_GESTDEDICATE) = 0) OR (EXISTS (SELECT CODGEST FROM TMP_GESTDEDICATE WHERE CODGEST = N.GEST))) ' ||
  --       '                      AND IOAL.MG &lt;&gt; 3 AND IOAL.MG &lt;&gt; 5  ' ||
         '                      AND IOAL.MG &lt;&gt; 5  ' ||
         '                      AND coalesce(IOAL.ESTEMIFIX, 0) = 0    ' ||
         '                      AND coalesce(IOAL.ESTEOBINV, 0) = 0    ' ||
         '                   GROUP BY ' ||
         '                      NS.CODOBIECT, ' ||
         '                      N.GEST ' ||
         '                ) sq ' ||
  --       '           WHERE STOC &gt;= 0 ' ||
         '         ) sq1 ' ||
         '     GROUP BY CODOBIECT, CODGEST ' ||
         '    ) STOCVIEW,  ' ||
         '    NARTOBJ O ' ||
         '    LEFT OUTER JOIN PRETM PM ON PM.CODOBIECT = O.CODOBIECT AND PM.IMPLICIT = 1 ' ||
         '    LEFT JOIN NCATPRET CAT ON CAT.CODCATPRET = PM.CODCATPRET ' ||
         '    LEFT OUTER JOIN NART A ON A.CODARTICOL = O.CODARTICOL  ' ||
      '      LEFT OUTER JOIN NUM1 U0 ON U0.CODUM1 = A.UM1 ' ||
         '    LEFT OUTER JOIN NUM U ON U.CODUM = A.UM ' ||
         '    LEFT OUTER JOIN NUM1 U1 ON U1.CODUM = U.CODUM AND U1.SECUNDARA = 0' ||
         '    LEFT OUTER JOIN NCLASEA CLAS ON CLAS.CODCLASEA = CLASA  ' ||
         '    LEFT OUTER JOIN NPART P ON P.CODPART = O.CODPRODUCATOR ' ||
         '    LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = A.CODARTICOL  ' ||
         '    LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA = NAL.CODTVA, ' ||
         '    NGEST G ' ||
         '  WHERE ' ||
         '    G.CODGEST = STOCVIEW.CODGEST ' ||
         '    AND G.CODSUBUNIT =  ' || (current_setting('PKG_GLOBALS.SUBUNITATE', True))::numeric ||
         '    AND O.CODOBIECT = STOCVIEW.CODOBIECT AND coalesce(O.INACTIV, 0) &lt;&gt;1 AND coalesce(O.BLOCAT, 0) NOT IN (1, 3) ' ||
         ' ) subq ' ||
         '  WHERE 1=1';

    IF coalesce($2, '?') not in ('?', '') THEN
    /*
      FILTRU_ART := ' AND UPPER(DENOBIECT) LIKE ' || '''%' || UPPER($2) || '%''';
      */
    /*  var_table_varchar := pkg_wmeonline_TOKENIZE_STRING($2, ' '); */
    var_table_varchar := string_to_array($2, ' ');
          for elem in 1 .. array_length(var_table_varchar, 1)
          loop
           FILTRU_ART := FILTRU_ART || ' AND UPPER(DENOBIECT) LIKE ' || '''%' || UPPER(var_table_varchar[elem]) || '%''';
          end loop;
    END IF;

    IF (coalesce($2, '?') not in ('?', '')) AND SUBSTR($2, 1, 1) = '=' THEN
      FILTRU_ART := ' AND UPPER(DENOBIECT) = ''' ||  LTRIM(UPPER($2), '=') || ''' ';
    END IF;


    IF coalesce($5, '?') not in ('?', '') THEN
      FILTRU_CODEXTERN := ' AND UPPER(CODEXTERN) LIKE ' || '''%' || UPPER($5) || '%''';
    END IF;

    IF (coalesce($5, '?') not in ('?', '')) AND SUBSTR($5, 1, 1) = '=' THEN
      FILTRU_CODEXTERN := ' AND UPPER(CODEXTERN) = ''' ||  LTRIM(UPPER($5), '=') || ''' ';
    END IF;


    IF coalesce($6, '?') not in ('?', '') THEN
      FILTRU_CODINTERN := ' AND UPPER(CODINTERN) LIKE ' || '''%' || UPPER($6) || '%''';
    END IF;

    IF (coalesce($6, '?') not in ('?', '')) AND SUBSTR($6, 1, 1) = '=' THEN
      FILTRU_CODINTERN := ' AND UPPER(CODINTERN) = ''' ||  LTRIM(UPPER($6), '=') || ''' ';
    END IF;


    IF coalesce($3, '?') not in ('?', '') THEN
      FILTRU_CLASA := ' AND UPPER(CLASA) LIKE ' || '''%' || UPPER($3) || '%''';
    END IF;

    IF (coalesce($3, '?') not in ('?', '')) AND SUBSTR($3, 1, 1) = '=' THEN
      FILTRU_CLASA := ' AND UPPER(CLASA) = ''' ||  LTRIM(UPPER($3), '=') || ''' ';
    END IF;


    IF coalesce($4, 0) &lt;&gt; 0 THEN
      FILTRU_GEST := ' AND CODGEST = ' || $4::varchar;
    END IF;


    OPEN $1 FOR execute S || FILTRU_ART || ' ' || FILTRU_CLASA || ' ' || FILTRU_GEST || FILTRU_CODEXTERN || ' ' || FILTRU_CODINTERN || ' ORDER BY DENOBIECT ';
    return next $1;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_getsubunitati_4php</obj_name>
  <obj_hashval>62e8baa0fc76fdb12a1dbad86fe2250b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_getsubunitati_4php(refcursor, numeric, numeric)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
DECLARE
  RESULT_CURSOR REFCURSOR;
begin
  DELETE
  FROM TMP_MANEVRA;

  perform winmadmin.pkg_userfirme_getsubunitati($2, $3);

  insert into tmp_manevra (select CODSUBUNIT from TMP_SUBUNITDEDICATE);

  OPEN $1 FOR
  SELECT S.CODSUBUNIT, S.DEN_SUBUNIT
  FROM TMP_MANEVRA        T
    INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = T.CODUNIC;

  return next $1;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_setgestiuni</obj_name>
  <obj_hashval>b3dc4b30860c658567e9d0e674836201</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_setgestiuni(puser numeric, pfirma numeric, acodpers numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
  DECLARE
    aCODGEST numeric;
    NR       numeric;
begin
  DELETE FROM TMP_GESTDEDICATE;

  BEGIN
    SELECT COALESCE (CODGEST, 0)
    into strict aCODGEST
    FROM NPERS
    WHERE CODPERS = aCODPERS;

  EXCEPTION
  WHEN OTHERS THEN
    aCODGEST := 0;
  END;

  IF aCODGEST &lt;&gt; 0 THEN
    INSERT INTO TMP_GESTDEDICATE (CODGEST)
      VALUES (aCODGEST);

  ELSE
    perform  WINMADMIN.PKG_USERFIRME_getSubunitati (pUser, pFirma);
    perform  WINMADMIN.PKG_USERFIRME_getGestiuni (pUSER, pFIRMA);

    SELECT COUNT(*) into NR FROM TMP_GESTDEDICATE;

    IF NR = 0 THEN
      INSERT INTO TMP_GESTDEDICATE
      SELECT CODGEST
      FROM NGEST;
    END IF;
  END IF;
  --&lt;sstcommit&gt;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_setrecordcmdprodmat</obj_name>
  <obj_hashval>2ce61816776ff29ef61d7b88406bf25c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_setrecordcmdprodmat(INOUT acodobiect numeric, INOUT acodcomanda1 numeric, INOUT acant numeric, INOUT acodcmdprodmat numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
   aCod NUMERIC(20);
   aIndexLocal NUMERIC(10);
BEGIN
  --Florin 30.09.2024 - from dual
  --Florin 20.07.2023 - sinc. Oracle
   begin
    select codcmdprodmat into aCodCmdProdMat from cmdprodmat where codcomanda1 = aCodComanda1 and codobiect = aCodObiect;
  exception when others then aCodCmdProdMat := 0; RETURN;
  end;
  if aCodCmdProdMat &gt; 0 then
    update cmdprodmat set cant = coalesce(cant,0) + aCant where codcmdprodmat = aCodCmdProdMat;
  else
    begin
      select max(indexlocal) + 1 into aIndexLocal from cmdprodmat where codcomanda1 = acodcomanda1;
    exception when others then aIndexLocal := 1;
    end;

    select nextval('seq_cmdprodmat_codcmdprodmat') into aCodCmdProdMat;
    insert into cmdprodmat (codcmdprodmat,
                            codcomanda1,
                            codobiect,
                            cant,
                            pret,
                            rest,
                            tip,
                            indexlocal)
    values (aCodCmdProdMat, aCodComanda1, aCodObiect, aCant, 0, 0, 1, aIndexLocal);
  end if;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_tokenize_string</obj_name>
  <obj_hashval>4fd02402b2e1f5a15ba39efb7c8dd20b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_tokenize_string(INOUT wme_result character varying[], INOUT p_list character varying, INOUT token character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  l_string       varchar := p_list || token;
  l_comma_index  integer;
  l_index        integer := 1;
  l_tab          varchar array;
  array_index    integer := 1;
begin
   LOOP
    l_comma_index := INSTR(l_string, token, l_index);
    EXIT WHEN l_comma_index = 0;
    l_tab[array_index] := SUBSTR(l_string, l_index, l_comma_index - l_index);
    l_index := l_comma_index + 1;
      array_index := array_index+1;
  END LOOP;

  wme_result := l_tab;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_zineluc_get_datafin</obj_name>
  <obj_hashval>6f7d6127941bd9ffdb6022ff4dcc6259</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_zineluc_get_datafin(INOUT wme_result date, INOUT vdatastart date, INOUT vzile numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  vDataFin date;
  vDataAux date;
  vZileAux integer := Ceil (vZile);
begin
  --Bogdan 22.12.2020
  vDataAux := vDataStart;
  vDataFin := vDataStart + vZileAux;
  LOOP
    SELECT Count (1) INTO vZileAux FROM ZiNeluc1 WHERE DATA BETWEEN vDataAux AND vDataFin;

    vDataAux := vDataFin + 1;
    vDataFin := vDataFin + vZileAux;
    EXIT  WHEN vDataAux &gt; vDataFin;
  END LOOP;

  WME_Result := (vDataFin);
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_zineluc_get_datafin_string</obj_name>
  <obj_hashval>dead28b9b17fe3fd3c412859b50df570</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_zineluc_get_datafin_string(INOUT wme_result character varying, INOUT vdatastart character varying, INOUT vzile numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  vData date := To_Date (vDataStart, 'dd.mm.yyyy');

begin
  --Bogdan 22.12.2020
  vData := ( SELECT PKG_ZINELUC_GET_DATAFIN.WME_RESULT FROM PKG_ZINELUC_GET_DATAFIN (NULL, vData, vZile));

  WME_Result := To_Char (vdata, 'dd.mm.yyyy');
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_zineluc_sp_gotorecord</obj_name>
  <obj_hashval>39ad0e6a4d350b20b3424a337107cbe1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_zineluc_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_ZINELUC(CodZiNeluc, An, Luna, AnCal, LunaCal)
  SELECT CodZiNeluc, (SELECT WME_RESULT FROM PKG_GLOBALS_GetAnLucru(NULL,NULL)), (SELECT WME_RESULT FROM PKG_GLOBALS_GetLunaLucru(NULL,NULL)), An, Luna
  FROM ZINELUC WHERE CodZiNeluc = RecId;

  INSERT INTO TMP_ZINELUC1(CodZiNeluc1, CodZiNeluc, Zi, Data)
  SELECT CodZiNeluc1, CodZiNeluc, Zi, DATA FROM ZINELUC1 WHERE CodZiNeluc = RecId;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_zineluc_sp_lockrecord</obj_name>
  <obj_hashval>16cccf5f6e11a250cbaf6590133ca38a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_zineluc_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CodZiNeluc INTO Tmp FROM ZINELUC WHERE CodZiNeluc = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_zineluc_sp_postrecords</obj_name>
  <obj_hashval>ba68cbf29651f3c9577c063d440a2618</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_zineluc_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  dAnLuna date;
  ZiMax   NUMERIC;
begin
  --Bogdan 14.10.2020
  SELECT To_Date (coalesce (AnCal::varchar,'')|| '.'|| coalesce (LunaCal::varchar,'') , 'yyyy.mm') - 1
  INTO dAnLuna
  FROM TMP_ZINELUC;

  ZiMax := To_Char (Last_Day (dAnLuna + 1) , 'DD');
  DELETE FROM TMP_ZINELUC1 WHERE Zi &gt; ZiMax;

  UPDATE TMP_ZINELUC1 SET DATA = dAnLuna + ZI::integer;

  IF Operation = 0 THEN
    SELECT CodZiNeluc INTO RecId FROM TMP_ZINELUC;

    UPDATE ZINELUC
    SET
      (An, Luna) = (SELECT AnCal, LunaCal FROM TMP_ZINELUC)
    WHERE CodZiNeluc = RecId;

    DELETE FROM ZINELUC1 LC1 WHERE LC1.CodZiNeluc = RecId AND Zi NOT IN (SELECT Zi FROM TMP_ZINELUC1);
    DELETE FROM TMP_ZINELUC1 WHERE Zi IN (SELECT Zi FROM ZINELUC1 WHERE CodZiNeluc = RecId);

    UPDATE ZINELUC1 SET DATA = dAnLuna + ZI::integer WHERE CodZiNeluc = RecId AND DATA IS NULL;

    INSERT INTO ZINELUC1 (CodZiNeluc1, CodZiNeluc, Zi, Data)
    SELECT NEXTVAL ('SEQ_ZINELUC1_CODZINELUC1') , RecId, Zi, DATA FROM (SELECT  DISTINCT ZI, DATA FROM TMP_ZINELUC1) A_PG;
  ELSE
    SELECT NEXTVAL ('SEQ_ZINELUC_CODZINELUC') INTO RecId;

    INSERT INTO ZINELUC (CodZiNeluc, An, Luna, UserID, DataCreare)
    SELECT RecId, AnCal, LunaCal, current_setting ('PKG_GLOBALS.UserId', true) ::numeric, CURRENT_TIMESTAMP FROM TMP_ZINELUC;

    INSERT INTO ZINELUC1 (CodZiNeluc1, CodZiNeluc, Zi, Data)
    SELECT NEXTVAL ('SEQ_ZINELUC1_CODZINELUC1') , RecId, Zi, DATA FROM (SELECT  DISTINCT ZI, DATA FROM TMP_ZINELUC1) B_PG;
  END IF;

  PERFORM NotifyModif (Operation, RecId, 'ZINELUC');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>plural</obj_name>
  <obj_hashval>6147230675f6c15d51e429c18d19e2ce</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION plural(sing character varying)
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
DECLARE
  Result VARCHAR := '';
BEGIN
  Result := sing;
    IF sing IS NULL                                                    THEN Result := NULL;
    ELSIF length(sing) &gt; 3 AND SubStr(sing,length(sing)) IN ('r', 't') THEN Result := sing||'i';
    ELSIF length(sing) &gt; 2 AND SubStr(sing,length(sing)-1) = 'nd'      THEN Result := Substr(sing, 1, Length(sing) - 1)||'zi';
    ELSIF SubStr(sing,length(sing)) = 'a'                              THEN Result := SubStr(sing, 1, Length(sing) - 1)||'e';
    ELSIF SubStr(sing,length(sing)) = 'u'                              THEN Result := SubStr(sing, 1, Length(sing) - 1)||'i';
    ELSIF SubStr(sing,length(sing)) = 'n'                              THEN Result := sing||'i';
    END IF;
    RETURN Lower(Result);
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>PROCEDURE</obj_type>
  <obj_name>prc_al_check</obj_name>
  <obj_hashval>90a4a258ed41be396c8aa0e9a41cd74e</obj_hashval>
  <obj_text>CREATE OR REPLACE PROCEDURE prc_al_check(IN ptable character varying, IN pcod numeric DEFAULT 0)
 LANGUAGE plpgsql
AS $procedure$
DECLARE
  vRefresh NUMERIC;
  sALStart varchar;
  sALStop  varchar;
  sCol2    VARCHAR;
  sAnd     VARCHAR := '';
  sSchema  varchar := public.get_schema();
BEGIN
  --Florin 07.04.2022 - fixat 53799
  -- Stef 18.03.2021
  BEGIN
    SELECT COLUMN_NAME INTO STRICT sALStart FROM information_schema.columns WHERE TABLE_NAME = Lower(pTable) AND COLUMN_NAME IN ('alstart', 'anlunastart') AND table_schema = sSchema;
    SELECT COLUMN_NAME INTO STRICT sALStop  FROM information_schema.COLUMNS WHERE TABLE_NAME = Lower(pTable) AND COLUMN_NAME IN ('alstop',  'anlunastop')  AND table_schema = sSchema;
  EXCEPTION
    WHEN No_Data_Found THEN RETURN;
  END;

  IF Coalesce(pCod, 0) &lt;&gt; 0 THEN
    SELECT COLUMN_NAME INTO sCol2 FROM information_schema.columns WHERE TABLE_NAME = Lower(pTable) AND ordinal_position = 2 AND table_schema = sSchema;
    sAnd := ' AND A.'||sCol2||' = '||To_Char(pCod, 'fm9999999999999999999999');
  END IF;

  EXECUTE 'SELECT CASE WHEN EXISTS(SELECT 1 FROM '||pTable||' A WHERE (A.'||sALStart||' IS NULL OR A.'||sALStop||' IS NULL)'||sAnd||') THEN 1 ELSE 0 END::NUMERIC ' INTO vRefresh;
  IF vRefresh = 1 THEN
    CALL PRC_AL_REFRESH(pTable, pCod);
  END IF;
END;
$procedure$
</obj_text>
</row>

<row>
  <obj_type>PROCEDURE</obj_type>
  <obj_name>prc_al_refresh</obj_name>
  <obj_hashval>2184b59912f8b00a299f90cfdeefa926</obj_hashval>
  <obj_text>CREATE OR REPLACE PROCEDURE prc_al_refresh(IN ptable character varying, IN pcod numeric DEFAULT 0)
 LANGUAGE plpgsql
AS $procedure$
DECLARE
  sSQL       varchar;
  sWhere     varchar;
  sCol2      varchar;
  sCol1      varchar;
  sPartition varchar;
  sALIni     varchar;
  sALStart   varchar;
  sALStop    varchar;
  sSchema    varchar  := public.get_schema();
BEGIN
  -- Stef 26.01.2022 Update From -- sintaxa specifica PG
  BEGIN -- daca am temporar e alta schema
    SELECT table_schema INTO STRICT sSchema
    FROM information_schema.tables
    WHERE table_name = lower(ptable) AND ( (table_type = 'LOCAL TEMPORARY' ) OR (table_type = 'BASE TABLE' AND table_schema = sSchema) );
  EXCEPTION
    WHEN No_Data_Found THEN RETURN;
  END;

  BEGIN
    SELECT COLUMN_NAME INTO STRICT sALStart FROM information_schema.columns WHERE TABLE_NAME = Lower(pTable) AND COLUMN_NAME IN ('alstart', 'anlunastart') AND table_schema = sSchema;
    SELECT COLUMN_NAME INTO STRICT sALStop  FROM information_schema.columns WHERE TABLE_NAME = Lower(pTable) AND COLUMN_NAME IN ('alstop',  'anlunastop')  AND table_schema = sSchema;
  EXCEPTION
    WHEN No_Data_Found THEN RETURN;
  END;

  SELECT COLUMN_NAME INTO sCol1 FROM information_schema.columns WHERE TABLE_NAME = Lower(pTable) AND ordinal_position = 1 AND table_schema = sSchema;
  SELECT COLUMN_NAME INTO sCol2 FROM information_schema.columns WHERE TABLE_NAME = Lower(pTable) AND ordinal_position = 2 AND table_schema = sSchema;

  sWhere := '
  WHERE A.'||sCol2||' = '||To_Char(pCod, 'fm9999999999999999999999');
  IF pCod = 0 THEN
    sWhere := '';
  END IF;

  sPartition := 'A.'||sCol2;
  IF Upper(pTable) IN ('CONSTLUNA', 'TMP_CONSTLUNA') THEN
    sPartition := sPartition ||', A.USERID';
  END IF;

  SELECT To_Char(ANINITIAL*12+LUNAINITIALA, 'fm99999') INTO sALIni FROM FIRMALUNI;

  sSQL := '
  INSERT INTO TMP_AL_REFRESH(COD, CODP, ALSTART, ALSTOP)
  SELECT
    A.'||sCol1||', A.'||sCol2||',
    CASE
      WHEN LAG(Coalesce(A.ANSTART*12+A.LUNASTART,0)) OVER (PARTITION BY '||sPartition||' ORDER BY Coalesce(A.ANSTART*12+A.LUNASTART,0)) IS NOT NULL THEN A.ANSTART*12+A.LUNASTART
      WHEN Coalesce(A.ANSTART*12+A.LUNASTART,0) = '||sALIni||' THEN 0
      ELSE Coalesce(A.ANSTART*12+A.LUNASTART,0)
    END ALSTART,
    Coalesce(LEAD(Coalesce(A.ANSTART*12+A.LUNASTART,0)) OVER (PARTITION BY '||sPartition||' ORDER BY Coalesce(A.ANSTART*12+A.LUNASTART,0)) - 1,99999) ALSTOP
  FROM '||pTable||' A'||
  sWhere;

  EXECUTE 'TRUNCATE TABLE TMP_AL_REFRESH';
  EXECUTE sSQL;

  sSQL := 'UPDATE '||pTable||' A SET '||sALStart||' = B.ALSTART, '||sALStop||'= B.ALSTOP FROM TMP_AL_REFRESH B WHERE A.'||sCol1||' = B.COD';
  EXECUTE sSQL;
END;
$procedure$
</obj_text>
</row>

<row>
  <obj_type>PROCEDURE</obj_type>
  <obj_name>prc_makecodident</obj_name>
  <obj_hashval>fc704e8906ab270b1d7fc5c14774ade5</obj_hashval>
  <obj_text>CREATE OR REPLACE PROCEDURE prc_makecodident(IN ptabname character varying, IN pcolcod character varying)
 LANGUAGE plpgsql
AS $procedure$
DECLARE
  cSQL text;
BEGIN
  --Florin 21.02.2025
  cSQL := 'INSERT INTO TMP_'||pTabName||'('||pColCod||', CODIDENT)
  WITH a('||pColCod||', CODIDENT) AS (
    -- Anchor member.
    SELECT '||pColCod||', To_Char('||pColCod||') CODIDENT
    FROM   '||pTabName||'
    WHERE  Coalesce(codparinte,0) = 0 AND '||pColCod||' &gt; 0
    UNION ALL
    SELECT ca.'||pColCod||', a.CODIDENT||''.''||To_Char(ca.'||pColCod||') CODIDENT
    FROM   '||pTabName||' ca
    INNER JOIN a ON a.'||pColCod||' = ca.CODPARINTE
  )
  SELECT '||pColCod||', CODIDENT
  FROM a';

  EXECUTE 'TRUNCATE TABLE TMP_'||pTabName;
  EXECUTE cSQL;
  EXECUTE 'UPDATE '||pTabName||' A SET CODIDENT = (SELECT B.CODIDENT FROM TMP_'||pTabName||' B WHERE B.'||pColCod||' = A.'||pColCod||')';
END;
$procedure$
</obj_text>
</row>

<row>
  <obj_type>PROCEDURE</obj_type>
  <obj_name>prc_um_sp_deleterecord</obj_name>
  <obj_hashval>999f882e579e970346234281e6be0f9e</obj_hashval>
  <obj_text>CREATE OR REPLACE PROCEDURE prc_um_sp_deleterecord(IN recid numeric)
 LANGUAGE plpgsql
AS $procedure$
begin
PERFORM PKG_UM_SP_LOCKRECORD( RecId);
DELETE FROM num1
WHERE
 CodUM = recid;
DELETE FROM NUM
WHERE
 CodUM = RecId;
PERFORM NotifyModif( 2, RecId, 'NUM');
--&lt;sstunknown&gt;
end;
$procedure$
</obj_text>
</row>

<row>
  <obj_type>PROCEDURE</obj_type>
  <obj_name>prc_zineluc_sp_deleterecord</obj_name>
  <obj_hashval>6bd7a4a71e5fa095efa31db8a36de8b7</obj_hashval>
  <obj_text>CREATE OR REPLACE PROCEDURE prc_zineluc_sp_deleterecord(IN recid numeric)
 LANGUAGE plpgsql
AS $procedure$
begin
  DELETE FROM ZINELUC1 WHERE CodZiNeluc = RecId;
  DELETE FROM ZINELUC  WHERE CodZiNeluc = RecId;
end;
$procedure$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pregatire_incarcare_struct</obj_name>
  <obj_hashval>9433cf18632cd7ca1f5e4a1a008faa59</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pregatire_incarcare_struct(cddl_hash text)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vCnt numeric;
BEGIN
  --Adina 23.03.2021 - sinc.Oracle
  -- PROCEDURA SPECIALA PENTRU INCARCAREA STUCTURILOR DE TIP martor
  --VERIFICARE EXISTENTA TABELA HASH
  SELECT Count(1) INTO vCnt FROM information_schema.tables WHERE TABLE_NAME = lower('SRC_SCRIPTS_HASH');

  IF vCnt = 0 THEN
    EXECUTE 'CREATE TABLE SRC_SCRIPTS_HASH(TYPE VARCHAR(30), NAME VARCHAR(30), TEMP VARCHAR(1), REFTABLE  VARCHAR(30), HASHVAL VARCHAR(64), HASHNEW VARCHAR(64) )';
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>restaurant_make_all_stoc_la_data</obj_name>
  <obj_hashval>eda4a54b7d0cb7be5f580986013cabd0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION restaurant_make_all_stoc_la_data(adata character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 28.11.2023
  DELETE FROM TMP_NIR_LA_DATA;
  INSERT INTO TMP_NIR_LA_DATA (CODOBIECT, CANTNIR)
  SELECT
    CODOBIECT,
    SUM(CANTNIR) AS CANTNIR
  FROM
   (
   SELECT
    NS.CODOBIECT,
    CANTNIR,
    N.DATANIR AS DATACREARE
   FROM
     NIRSTOC NS,
     NIR N,
     --LEFT OUTER JOIN IESIRI E ON E.CODIES    = N.CODIES,
     NARTOBJ O,
     NART A,
     IOART1 IO1
  WHERE
     NS.CODNIR = N.CODNIR
     AND N.OPERAT = 1
     AND COALESCE(N.GEST, 0) &lt;&gt; 0
     AND O.CODOBIECT = NS.CODOBIECT
--   AND COALESCE(O.PRODUSPROPRIU, 0) = 0
     AND A.CODARTICOL = O.CODARTICOL
--     AND COALESCE(A.CASADEMARCAT, 0) = 1
     AND NS.CODIOART = IO1.CODIOART
     AND IO1.MG &lt;&gt; 5
     AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) BETWEEN IO1.ALSTART AND IO1.ALSTOP
     AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) &gt;= (select aninitial*12+lunainitiala from firmaluni)
   UNION ALL
   SELECT
    NS.CODOBIECT,
    CANTNIR,
    N.DATANIR AS DATACREARE
   FROM
     NIRSTOC NS,
     NIR N,
     --LEFT OUTER JOIN INTRARI I ON I.CODINTR = N.CODINTR
     --LEFT OUTER JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
     --LEFT OUTER JOIN IESIRI E ON E.CODIES    = N.CODIES,
     NARTOBJ O,
     NART A
  WHERE
     NS.CODNIR = N.CODNIR
     AND N.OPERAT = 1
     AND COALESCE(N.GEST, 0) &lt;&gt; 0
     AND O.CODOBIECT = NS.CODOBIECT
--   AND COALESCE(O.PRODUSPROPRIU, 0) = 0
     AND A.CODARTICOL = O.CODARTICOL
--     AND COALESCE(A.CASADEMARCAT, 0) = 1
     AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) &lt; (select aninitial*12+lunainitiala from firmaluni)
   ) A_PG
   WHERE
     COALESCE(DATACREARE, TO_DATE('01.01.2000', 'DD.MM.YYYY')) &lt; TO_DATE(aDATA, 'DD.MM.YYYY hh24:mi')
   GROUP BY CODOBIECT;

   DELETE FROM TMP_LIVR_LA_DATA;
   INSERT INTO TMP_LIVR_LA_DATA(CODOBIECT, CANTNIR)
   SELECT
     CODOBIECT,
     SUM(CANT) AS CANT
   FROM
   (
   SELECT
     NS.CODOBIECT,
     CASE
       WHEN L.TIPLIVR = 15 THEN  -L1.CANT
       ELSE L1.CANT
     END
      CANT,
      L.DATALIVR AS DATACREARE
   FROM
     LIVR1 L1,
     LIVR L,
     NIRSTOC NS,
     NIR N,
     NARTOBJ O,
     NART A
   WHERE
     L1.CODNIRSTOC = NS.CODNIRSTOC
     AND L1.CODLIVR = L.CODLIVR
     AND NS.CODNIR = N.CODNIR
     AND COALESCE(N.GEST, 0) &lt;&gt; 0
     AND O.CODOBIECT = NS.CODOBIECT
     AND A.CODARTICOL = O.CODARTICOL
--     AND COALESCE(A.CASADEMARCAT, 0) = 1
   ) B_PG
   WHERE
    COALESCE(DATACREARE, TO_DATE('01.01.2000', 'DD.MM.YYYY')) &lt; TO_DATE(aData, 'DD.MM.YYYY hh24:mi')
   GROUP BY CODOBIECT;

--   MERGE INTO TMP_NIR_LA_DATA N
--   USING TMP_LIVR_LA_DATA L
--   ON ( N.CODOBIECT = L.CODOBIECT)
--   WHEN MATCHED THEN UPDATE SET N.CANTNIR = N.CANTNIR - L.CANTNIR;


   END;
 $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>restt</obj_name>
  <obj_hashval>e1f9776df4b96cf3baf2bba17c6a2276</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION restt(recid double precision)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
DELETE FROM NTARI
WHERE
 codtara = RecId;
--&lt;sstunknown&gt;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>reverse</obj_name>
  <obj_hashval>6f7e4d106ed3dc2cbd4f2d1f62611724</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION reverse(str text)
 RETURNS text
 LANGUAGE plpgsql
AS $function$
declare
    i int;
    res text = '';
begin
    for i in 1..length(str) loop
        res:= substr(str, i, 1) || res;
    end loop;
    return res;
end $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>test</obj_name>
  <obj_hashval>01af65910c5a9b819928b65814c92a4b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION test(INOUT param1 numeric, INOUT param2 numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
declare v numeric;
begin
  Param1 := Param1 + Param2;
--  return v;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>PROCEDURE</obj_type>
  <obj_name>test_procedure_proc</obj_name>
  <obj_hashval>165ad8b3f23a6ef88d31079371299e3c</obj_hashval>
  <obj_text>CREATE OR REPLACE PROCEDURE test_procedure_proc()
 LANGUAGE plpgsql
AS $procedure$
declare o numeric;
        r numeric;
begin
  o := 1;
  r := 200;
 call martor.test_procedure(o, r);
 insert into INTRARI (codintr) values (r);
end;
$procedure$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>testxxx</obj_name>
  <obj_hashval>8d7a196ae69bbf5f543cc96cdb98c503</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION testxxx(INOUT wme_result character varying, p_xxx numeric, OUT p_sector numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
Result varchar;
begin
Result := '';
WME_Result :=  (  Result) ;
RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>testxxx</obj_name>
  <obj_hashval>85e0c3e4ed665edc83def77c05552df7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION testxxx(INOUT wme_result character varying, OUT p_sector numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
Result varchar;
begin
Result := '';
WME_Result :=  (  Result) ;
RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>tradutipsediu</obj_name>
  <obj_hashval>e7022c32fa9b49abd685ac1e34c58f2b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION tradutipsediu(psediusocial numeric)
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
DECLARE vTipSediu varchar;
BEGIN
  --Florin 17.11.2020
  vTipSediu := CASE pSediuSocial
                 WHEN 1 THEN 'livrare'
                 WHEN 2 THEN 'facturare'
                 WHEN 3 THEN 'facturare+livrare'
                 WHEN 4 THEN 'social'
                 WHEN 5 THEN 'social+livrare'
                 WHEN 6 THEN 'social+facturare'
                 WHEN 7 THEN 'social+facturare+livrare'
                 WHEN 9 THEN 'livrare la beneficiar'
               END;

  RETURN vTipSediu;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>PROCEDURE</obj_type>
  <obj_name>umple_tmp_const_proctva</obj_name>
  <obj_hashval>4d19d786a79f02893cbfeaaeeb0f38c8</obj_hashval>
  <obj_text>CREATE OR REPLACE PROCEDURE umple_tmp_const_proctva(IN panluna numeric)
 LANGUAGE plpgsql
AS $procedure$
BEGIN
  --Florin 19.09.2025 - sinc. Oracle
  --Florin 20.08.2025 - fixat 66453
  --Stef 20.02.2024
  CALL create_wm_temps_flag('TMP_CONST_PROCTVA');
  EXECUTE 'TRUNCATE TABLE TMP_CONST_PROCTVA';

  INSERT INTO TMP_CONST_PROCTVA (SIMBOL, ORD, TIP, PROCTVA, LIMINF, LIMSUP)
  SELECT
    SIMBOL,
    Row_Number()               OVER (ORDER BY ProcTva ASC NULLS LAST, TIP ASC ) Ord,
    Tip,
    ProcTva,
    (ProcTva + Lag (ProcTva,1) OVER (ORDER BY ProcTva ASC NULLS LAST, TIP ASC )) / 2 LimInf,
    (ProcTva + Lead(ProcTva,1) OVER (ORDER BY ProcTva ASC NULLS LAST, TIP ASC )) / 2 LimSup
  FROM (
    SELECT
      SIMBOL, TIP,
      CASE WHEN ProcTva = Lag(ProcTva,1) OVER (ORDER BY ProcTva ASC NULLS LAST, TIP ASC) THEN NULL ELSE ProcTva END ProcTva
    FROM (
      SELECT
        SIMBOL, NULLIF(TO_NUMBER(case when VALOARE = '' then '0' else valoare end), 0) ProcTva,
          CASE c1.SIMBOL
          WHEN 'PROCTVAMED'  THEN 1 WHEN 'PROCTVAMIN'  THEN 2 WHEN 'PROCTVAMAX'  THEN 3
          WHEN 'PROCTVAREG'  THEN 4 WHEN 'PROCTVAREG2' THEN 5
          WHEN 'PROCTVAREG3' THEN 6 WHEN 'PROCTVAREG4' THEN 7 WHEN 'PROCTVAREG5' THEN 8
        END TIP
      FROM (
        SELECT codconst1, UPPER(SIMBOL) SIMBOL
        FROM const1
        WHERE UPPER(SIMBOL) IN ('PROCTVAMIN','PROCTVAMED','PROCTVAMAX','PROCTVAREG','PROCTVAREG2','PROCTVAREG3','PROCTVAREG4','PROCTVAREG5')
      ) c1
        LEFT JOIN constluna cl ON cl.codconst1    = c1.codconst1 AND pAnLuna BETWEEN CL.ALSTART AND CL.ALSTOP
        LEFT JOIN constval  cv ON cv.codconstluna = cl.codconstluna
    ) a
  ) b;
END;
$procedure$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>umple_tmp_zile</obj_name>
  <obj_hashval>17af0a6a078bd00263eafe8d04bc93aa</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION umple_tmp_zile(adataini date, adatafin date)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vNrZile numeric;
BEGIN
  --Florin 17.11.2021 - fixat 52041
  --Adina 15.10.2020
  EXECUTE 'TRUNCATE TABLE TMP_ZILE';

  vNrZile := DATE_TRUNC('DAY',aDataFin)::date - DATE_TRUNC('DAY',aDataIni)::date + 1;

  INSERT INTO TMP_ZILE
--  SELECT DATE_TRUNC('DAY',aDataIni) + LEVEL - 1 CONNECT BY  LEVEL &lt;= vNrZile
  WITH RECURSIVE aa AS
  (
   SELECT DATE_TRUNC('DAY',aDataIni)::date datarec, 1 nivel
   UNION ALL
   SELECT aa.datarec+1, aa.nivel+1 FROM aa WHERE aa.nivel&lt;vNrZile
  )
  SELECT datarec FROM aa;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>unlockdoceditat</obj_name>
  <obj_hashval>06e6d3a16d300a759d58c0ab21f78ce5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION unlockdoceditat(numetabela character varying, acoddoc numeric, userid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
  NR  numeric;

  NumeRealTabela character varying := numetabela;
  CodDocReal     numeric           := aCodDoc;
  TipDocReal     numeric;
begin
/*
 if upper(NumeRealTabela) = 'MASTERDOC' then
    SELECT current_setting('PKG_DOCUMENTE.gTipDoc', true)::numeric,
           current_setting('PKG_DOCUMENTE.gCodDoc', true)::numeric
    into
           TipDocReal,
           CodDocReal;

  if TipDocReal in (1,2,3,4,5,6,7,9) then
    NumeRealTabela := 'INTRARI';
  end if;

  if TipDocReal in (14,15,16,19,20,21,22,23,24,26) then
    NumeRealTabela := 'IESIRI';
  end if;

  if TipDocReal in (12,13) then
    NumeRealTabela := 'TRANSF';
  end if;

  if TipDocReal in (8,18,43,44,53) then
    NumeRealTabela := 'COMANDA';
  end if;

  if TipDocReal in (10, 25, 27, 34) then
    NumeRealTabela := 'CONTRACT';
  end if;

  if TipDocReal in (29,30,31,33) then
    NumeRealTabela := 'TREZOR';
  end if;

  if TipDocReal in (28) then
    NumeRealTabela := 'COMPENS';
  end if;

  if TipDocReal in (45,46,47) then
    NumeRealTabela := 'REG';
  end if;

  if TipDocReal = 54 then
    NumeRealTabela := 'SETTASK';
  end if;

  if TipDocReal in (63) then
    NumeRealTabela := 'RAPORTP';
  end if;

  if TipDocReal in (97) then
    NumeRealTabela := 'RECLAMATII';
  end if;

  if TipDocReal in (99) then
    NumeRealTabela := 'VOUCHER';
  end if;

  if TipDocReal = 500 then
    NumeRealTabela := 'NPART';
  end if;

  if TipDocReal = 501 then
    NumeRealTabela := 'NART';
  end if;

  if TipDocReal = 502 then
    NumeRealTabela := 'NPERS';
  end if;


  if TipDocReal = 508 then
    NumeRealTabela := 'UTILAJE';
  end if;

  if TipDocReal = 516 then
    NumeRealTabela := 'UTILAJE20';
  end if;


end if;
*/
  select getinfodoclock.numerealtabela,
         getinfodoclock.coddocreal
  FROM
   getinfodoclock(numetabela, null, aCodDoc, null, null, null)
  into
    NumeRealTabela,
    CodDocReal;

  execute ' delete from DOCEDITAT E  WHERE E.TABELA = ''' || coalesce(NumeRealTabela,'') || ''' AND E.CODDOC =' || coalesce((CodDocReal)::varchar ,'') || ' AND E.USERID='||UserID::varchar;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>PROCEDURE</obj_type>
  <obj_name>update_codcont_from_iopart1</obj_name>
  <obj_hashval>8ed43e999fbb85862e3dea7c8adec172</obj_hashval>
  <obj_text>CREATE OR REPLACE PROCEDURE update_codcont_from_iopart1(IN ptable character varying, IN pcolcodcont character varying, IN pcolcodpart character varying, IN pcolicont character varying, IN pcolal character varying, IN pvalal numeric)
 LANGUAGE plpgsql
AS $procedure$
DECLARE
  v_data  TEXT[];
  v_line  TEXT;
  vCNT    INTEGER := 0;
  sAL     VARCHAR(100) := '0';
  sSQL    TEXT;
  sDef    TEXT;
  sSchema VARCHAR;
BEGIN
  --Florin 17.10.2025 - fixat 66994
  -- Construire sAL
  IF Coalesce(pColAL, '') &lt;&gt; '' THEN sAL := 'T.' || pColAL;
  ELSIF Coalesce(pValAL, 0) &gt; 0 THEN sAL := pValAL::TEXT;
  END IF;

  -- Construire query dinamic pentru coloane
  IF sAL &lt;&gt; '0' THEN
    sSchema := Lower(current_setting('PKG_GLOBALS.FIRMANAME', true));
    IF NULLIF(sSchema, '') IS NULL THEN
      sSchema := public.get_schema();
    END IF;

  sDef := 'SELECT array_agg(''WHEN '' || LPAD(T.ICONT::text, 2, ''0'') || '' THEN IP1.'' || ' ||
          '(SELECT distinct COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS C ' ||
          'WHERE C.TABLE_NAME = ''iopart1'' AND C.ORDINAL_POSITION = T.ICONT + 1) ' ||
          'ORDER BY T.ICONT) ' ||
          'FROM (SELECT DISTINCT ' || pColICont || ' AS ICONT FROM TMP_SAFT_NPART) T';
  EXECUTE sDef INTO v_data;

    IF v_data IS NOT NULL THEN
      vCNT := array_length(v_data, 1);
    END IF;
  END IF;

  -- Construire si executare UPDATE/MERGE
  IF vCNT &gt; 0 THEN
    sSQL := 'UPDATE '||pTable||' T '||E'\n'||
            'SET '||pColCodCont||' = SRC.NEW_CODCONT '||E'\n'||
            'FROM ( '||E'\n'||
            '  SELECT '||E'\n'||
            '    T.'||pColCodPart||' AS CODPART, T.'||pColICont||' AS ICONT, '||E'\n'||
            '    CASE T.'||pColICont;
    FOR i IN 1..vCNT LOOP
      sSQL := sSQL || E'\n' ||
            '      '||v_data[i];
    END LOOP;
    sSQL := sSQL ||E'\n'||
            '    END AS NEW_CODCONT '||E'\n'||
            '  FROM TMP_SAFT_NPART T '||E'\n'||
            '    LEFT JOIN NPART1  NP1 ON NP1.CODPART   = T.CODPART     AND '||sAL||' BETWEEN NP1.ALStart AND NP1.ALStop '||E'\n'||
            '    LEFT JOIN IOPART1 IP1 ON IP1.CODIOPART = NP1.CODIOPART AND '||sAL||' BETWEEN IP1.ALStart AND IP1.ALStop '||E'\n'||
            ') SRC '||E'\n'||
            'WHERE T.'||pColCodPart||' = SRC.CODPART AND T.'||pColICont||' = SRC.ICONT';
    EXECUTE sSQL;
  END IF;
END;
$procedure$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>updatenpart1crmstring</obj_name>
  <obj_hashval>5a5130c2648256d2bf359a7378daa399</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION updatenpart1crmstring(camp character varying, valoare character varying, adatastart date)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vCod NUMERIC;
  sString VARCHAR(1000);
  v_rec record;
begin
  for v_rec in (
    select TMP.VALOARE as CODPART,
           NC.CODPART1CRM, NC.CIFRAAFACERI, NC.NRANGAJATI, NC.LEAD, NC.SURSALEAD,
           NC.CODRESPONSABIL, NC.STARE, NC.MODPLATA, NC.CIP, NC.PROFIT
    from TMP_MANEVRA_LISTE TMP
    inner join (
      select NC1.*
      from NPART1CRM NC1
      where NC1.DATASTART = (
        select MAX(NC2.DATASTART)
        from NPART1CRM NC2
        where NC2.CODPART = NC1.CODPART
      )
      and NC1.DATAEND is null
    ) NC on NC.CODPART = TMP.VALOARE
    where TMP.FILTRU = 'CODPART'
  ) loop
    update NPART1CRM
    set DATAEND = aDataStart - 1
    where CODPART1CRM = v_rec.CODPART1CRM;

    select Nextval('seq_NPART1CRM_CodPart1Crm') into vCod from dual;

    insert into NPART1CRM (
      CODPART1CRM, CODPART, DATASTART,
      CIFRAAFACERI, NRANGAJATI, LEAD, SURSALEAD,
      CODRESPONSABIL, STARE, MODPLATA, CIP, PROFIT
    ) values (
      vCod, v_rec.CODPART, aDataStart,
      v_rec.CIFRAAFACERI, v_rec.NRANGAJATI, v_rec.LEAD, v_rec.SURSALEAD,
      v_rec.CODRESPONSABIL, v_rec.STARE, v_rec.MODPLATA, v_rec.CIP, v_rec.PROFIT
    );

    -- Modifica valoarea coloanei
    sString := 'update NPART1CRM set '||Camp||' = '||valoare||' where CODPART1CRM = '||vCod;
    execute sString;
  end loop;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_avans_client_facturabile</obj_name>
  <obj_hashval>79b2454fd0de05021644475828cbed99</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_avans_client_facturabile()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Adina 18.12.2020 tichet 41751
  --Adina 23 septembrie 2020
  RETURN
  '  SELECT
      O.CODOBLIGPIF,
      I.PREFIXDOC AS DOC,
      I.NRDOC,
      I.DATADOC,
      O.VALOARE,
      O.REST,
      O.TERMEN,
      0 As PRELUAT,
      O.REST AS RAMAS,
      0 AS CODSTINGATOR,
      O.SEMNIFICATIE AS SEMNIFCODSTINS,
      PKG_PLANCONTURI_GETSIMBOLCONT(fnc_GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART_GET_PART_COD_CARACT_LUNA(O.CODPART, GETANLUCRU(), GETLUNALUCRU()))) AS SIMBOLCONT,
      O.ICONT,
      G.MONEDA AS CODMONEDA,
      (select PKG_MONEDE_GET_SIMBOL_MONEDA.wme_result from PKG_MONEDE_GET_SIMBOL_MONEDA(null,G.MONEDA)) AS SIMBOLMONEDA,
      G.CURS,
      G.TVA,
      I.CODLOCATIE,
      A.OBS AS SEDIU,
      I.SUBUNITATEA,
      NSUB.DEN_SUBUNIT,
      G.PROCTVAAVANS
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G     ON G.CODGENERAL    = O.CODGENERAL
      LEFT OUTER JOIN IESIRI I      ON I.CODIES        = G.CODDOC
      LEFT OUTER JOIN NAGENDA A     ON A.CODAGENDA     = I.CODLOCATIE
      LEFT OUTER JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT = I.SUBUNITATEA
     WHERE
       I.AN * 12 + I.LUNA &lt;= GETANLUCRU() * 12 + GETLUNALUCRU() AND
      (O.VALOARE &gt; 0) AND
      (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
       O.SEMNIFICATIE = 210 AND
       O.CODPART = PKG_NOMPART_GET_PART_CURENT() AND
      PKG_MONEDE_MONEDA_VALIDA(G.MONEDA) = 1 ';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_avans_client_trezor</obj_name>
  <obj_hashval>565ebf5dcfcc8198966e810093f28d1b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_avans_client_trezor()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Adina 18.12.2020 tichet 41751
  --Adina 23 septembrie 2020
  RETURN
  '  SELECT
      O.CODOBLIGPIF,
      T1.DOC AS DOC,
      T1.NRDOC,
      T1.DATADOC,
      O.VALOARE,
      O.REST,
      O.TERMEN,
      0 As PRELUAT,
      O.REST AS RAMAS,
      0 AS CODSTINGATOR ,
      O.SEMNIFICATIE AS SEMNIFCODSTINS,
      PKG_PLANCONTURI_GETSIMBOLCONT(fnc_GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART_GET_PART_COD_CARACT_LUNA(O.CODPART, GETANLUCRU(), GETLUNALUCRU()))) AS SIMBOLCONT,
      O.ICONT,
      G.MONEDA AS CODMONEDA,
      (select PKG_MONEDE_GET_SIMBOL_MONEDA.wme_result from PKG_MONEDE_GET_SIMBOL_MONEDA(null,G.MONEDA)) AS SIMBOLMONEDA,
      coalesce(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      0 AS CODLOCATIE,
      '''' AS SEDIU,
      T.SUBUNITATEA,
      NSUB.DEN_SUBUNIT,
      G.PROCTVAAVANS
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G                      ON G.CODGENERAL    = O.CODGENERAL
       LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN TREZOR1 T1                     ON T1.CODTREZOR1   = G.CODDOC
       LEFT OUTER JOIN TREZOR  T                      ON T.CODTREZOR     = T1.CODTREZOR
      LEFT OUTER JOIN NSUBUNIT NSUB                  ON NSUB.CODSUBUNIT = T.SUBUNITATEA
    WHERE
       T1.AN * 12 + T1.LUNA &lt;= GETANLUCRU() * 12 + GETLUNALUCRU() AND
      (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
      (O.SEMNIFICATIE = 410)
       AND
      O.CODPART = PKG_NOMPART_GET_PART_CURENT() AND
      PKG_MONEDE_MONEDA_VALIDA(G.MONEDA) = 1 ';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_avans_furn_facturabile</obj_name>
  <obj_hashval>3f3a9f94bd2864f13ba93dfd686027cb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_avans_furn_facturabile()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Adina 18.12.2020 tichet 41751
  --Adina 23 septembrie 2020
  RETURN
  '  SELECT
      O.CODOBLIGPIF,
      I.PREFIXDOC AS DOC,
      I.NRDOC,
      I.DATADOC,
      O.VALOARE,
      O.REST,
      O.TERMEN,
      0 As PRELUAT,
      O.REST AS RAMAS,
      0 AS CODSTINGATOR,
      O.SEMNIFICATIE AS SEMNIFCODSTINS,
      PKG_PLANCONTURI_GETSIMBOLCONT(fnc_GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART_GET_PART_COD_CARACT_LUNA(O.CODPART, GETANLUCRU(), GETLUNALUCRU()))) AS SIMBOLCONT,
      O.ICONT,
      G.MONEDA AS CODMONEDA,
      (select PKG_MONEDE_GET_SIMBOL_MONEDA.wme_result from PKG_MONEDE_GET_SIMBOL_MONEDA(null,G.MONEDA)) AS SIMBOLMONEDA,
      G.CURS,
      G.TVA,
      I.CODLOCATIE,
      A.OBS AS SEDIU,
      I.SUBUNITATEA,
      NSUB.DEN_SUBUNIT,
      G.PROCTVAAVANS
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL  G    ON G.CODGENERAL    = O.CODGENERAL
      LEFT OUTER JOIN INTRARI  I    ON I.CODINTR       = G.CODDOC
      LEFT OUTER JOIN NAGENDA  A    ON A.CODAGENDA     = I.CODLOCATIE
      LEFT OUTER JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT = I.SUBUNITATEA
    WHERE
      I.AN * 12 + I.LUNA &lt;= GETANLUCRU() * 12 + GETLUNALUCRU() AND
      (O.VALOARE &gt; 0) AND
      (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
       O.SEMNIFICATIE = 110 AND
       O.CODPART = PKG_NOMPART_GET_PART_CURENT() AND
      PKG_MONEDE_MONEDA_VALIDA(G.MONEDA) = 1 ';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_avans_furn_trezor</obj_name>
  <obj_hashval>57ab699de73b85520d81a472a07bb2ce</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_avans_furn_trezor()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Adina 18.12.2020 tichet 41751
  --Adina 23 septembrie 2020
  RETURN
  '  SELECT
      O.CODOBLIGPIF,
      T1.DOC AS DOC,
      T1.NRDOC,
      T1.DATADOC,
      O.VALOARE,
      O.REST,
      O.TERMEN,
      0 As PRELUAT,
      O.REST AS RAMAS,
      0 AS CODSTINGATOR ,
      O.SEMNIFICATIE AS SEMNIFCODSTINS,
      PKG_PLANCONTURI_GETSIMBOLCONT(fnc_GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART_GET_PART_COD_CARACT_LUNA(O.CODPART, GETANLUCRU(), GETLUNALUCRU()))) AS SIMBOLCONT,
      O.ICONT,
      G.MONEDA AS CODMONEDA,
      (select PKG_MONEDE_GET_SIMBOL_MONEDA.wme_result from PKG_MONEDE_GET_SIMBOL_MONEDA(null,G.MONEDA)) AS SIMBOLMONEDA,
      coalesce(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      0 AS CODLOCATIE,
      '''' AS SEDIU,
      T.SUBUNITATEA,
      NSUB.DEN_SUBUNIT,
      G.PROCTVAAVANS
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G                      ON G.CODGENERAL    = O.CODGENERAL
       LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN TREZOR1 T1                     ON T1.CODTREZOR1   = G.CODDOC
      LEFT OUTER JOIN TREZOR  T                      ON T.CODTREZOR     = T1.CODTREZOR
      LEFT OUTER JOIN NSUBUNIT  NSUB                 ON NSUB.CODSUBUNIT = T.SUBUNITATEA
    WHERE
       T1.AN * 12 + T1.LUNA &lt;= GETANLUCRU() * 12 + GETLUNALUCRU() AND
      (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
      (O.SEMNIFICATIE = 310)
       AND
      O.CODPART = PKG_NOMPART_GET_PART_CURENT() AND
      PKG_MONEDE_MONEDA_VALIDA(G.MONEDA) = 1 ';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_iesiri_rosu_client</obj_name>
  <obj_hashval>4c3f8c8a70d08beda5d2189373f4dc94</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_iesiri_rosu_client()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Adina 18.12.2020 tichet 41751
  --Adina 23 septembrie 2020
  RETURN
  '  SELECT
      O.CODOBLIGPIF,
      I.PREFIXDOC AS DOC,
      I.NRDOC,
      I.DATADOC,
      ABS(O.VALOARE) AS VALOARE ,
      ABS(O.REST) AS REST,
      O.TERMEN,
      0 As PRELUAT,
      ABS(O.REST) AS RAMAS,
      0 AS CODSTINGATOR,
      O.SEMNIFICATIE AS SEMNIFCODSTINS,
      PKG_PLANCONTURI_GETSIMBOLCONT(fnc_GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART_GET_PART_COD_CARACT_LUNA(O.CODPART, GETANLUCRU(), GETLUNALUCRU()))) AS SIMBOLCONT,
      O.ICONT,
      G.MONEDA AS CODMONEDA,
      (select PKG_MONEDE_GET_SIMBOL_MONEDA.wme_result from PKG_MONEDE_GET_SIMBOL_MONEDA(null,G.MONEDA)) AS SIMBOLMONEDA,
      coalesce(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      I.CODLOCATIE,
      A.OBS AS SEDIU,
      I.SUBUNITATEA,
      NSUB.DEN_SUBUNIT,
      G.PROCTVAAVANS
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL                   G    ON G.CODGENERAL    = O.CODGENERAL
       LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN IESIRI                    I    ON I.CODIES        = G.CODDOC
      LEFT OUTER JOIN NAGENDA                   A    ON A.CODAGENDA     = I.CODLOCATIE
      LEFT OUTER JOIN NSUBUNIT                  NSUB ON NSUB.CODSUBUNIT = I.SUBUNITATEA
    WHERE
      (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
      (O.SEMNIFICATIE = 200 AND O.VALOARE &lt; 0)
       AND O.CODPART = PKG_NOMPART_GET_PART_CURENT() AND
       PKG_MONEDE_MONEDA_VALIDA(G.MONEDA) = 1 ';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_intrari_rosu_furn</obj_name>
  <obj_hashval>ddfd967c952ff7122b14a1706c9dc6ed</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_intrari_rosu_furn()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Adina 18.12.2020 tichet 41751
  --Adina 23 septembrie 2020
  RETURN
  '  SELECT
      O.CODOBLIGPIF,
      I.PREFIXDOC AS DOC,
      I.NRDOC,
      I.DATADOC,
      ABS(O.VALOARE) AS VALOARE ,
      ABS(O.REST) AS REST,
      O.TERMEN,
      0 As PRELUAT,
      ABS(O.REST) AS RAMAS,
      0 AS CODSTINGATOR,
      O.SEMNIFICATIE AS SEMNIFCODSTINS,
      PKG_PLANCONTURI_GETSIMBOLCONT(fnc_GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART_GET_PART_COD_CARACT_LUNA(O.CODPART, GETANLUCRU(), GETLUNALUCRU()))) AS SIMBOLCONT,
      O.ICONT,
      G.MONEDA AS CODMONEDA,
      (select PKG_MONEDE_GET_SIMBOL_MONEDA.wme_result from PKG_MONEDE_GET_SIMBOL_MONEDA(null,G.MONEDA)) AS SIMBOLMONEDA,
      coalesce(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      I.CODLOCATIE,
      A.OBS AS SEDIU,
      I.SUBUNITATEA,
      NSUB.DEN_SUBUNIT,
      G.PROCTVAAVANS
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G                      ON G.CODGENERAL    = O.CODGENERAL
       LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN INTRARI I                      ON I.CODINTR       = G.CODDOC
      LEFT OUTER JOIN NAGENDA A                      ON A.CODAGENDA     = I.CODLOCATIE
      LEFT OUTER JOIN NSUBUNIT NSUB                  ON NSUB.CODSUBUNIT = I.SUBUNITATEA
    WHERE
     I.AN * 12 + I.LUNA &lt;= GETANLUCRU() * 12 + GETLUNALUCRU() AND
    (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
    (O.SEMNIFICATIE = 100 AND O.VALOARE &lt; 0)
     AND
     coalesce(i.subunitatea,1) = (case when GETSUBUNITATE()=1 then coalesce(i.subunitatea,1) else GETSUBUNITATE() end) AND
    O.CODPART = PKG_NOMPART_GET_PART_CURENT() AND
    PKG_MONEDE_MONEDA_VALIDA(G.MONEDA) = 1 ';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_livrari_luna</obj_name>
  <obj_hashval>ea066633a8cfed87d1f530f815ee3cdc</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_livrari_luna()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$ begin
  return
  'select
    L1.CODNIRSTOC,
    -1 * L1.CANT as REST,
    -1 * L1.CANTUM1 as RESTUM1,
    -1 * L1.CANTUM2 as RESTUM2
  from
    LIVR1 L1
    left join LIVR    L on L.CODLIVR = L1.CODLIVR
    left join INTRARI I on I.CODINTR = L.CODINTR,
    NIRSTOC NS,
    NIR N,
    TMP_IOART_LUNA IO
  where
    L.TIPLIVR in (1, 2, 3, 4, 5, 6, 7)
    and L.OPERAT = 1
    and L.ANULAT = 0
    and I.AN          = current_setting(''PKG_GLOBALS.ANTEMP''  , true)::numeric
    and I.LUNA        = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric
    and L1.CODNIRSTOC = NS.CODNIRSTOC
    and NS.CODIOART   = IO.CODIOART
    and N.CODNIR      = NS.CODNIR
    and coalesce(N.OPERAT, 0) = 1
    and IO.MG &lt;&gt; 5
  union all
  select
    L1.CODNIRSTOC,
    -1 * L1.CANT as REST,
    -1 * L1.CANTUM1 as RESTUM1,
    -1 * L1.CANTUM2 as RESTUM2
  from
    LIVR1 L1
    left join LIVR   L on L.CODLIVR = L1.CODLIVR
    left join IESIRI I on I.CODIES  = L.CODIES,
    NIRSTOC NS,
    NIR N,
    TMP_IOART_LUNA IO
  where
    L.TIPLIVR in (14, 16, 19, 20, 21, 23, 24)
    and L.OPERAT = 1
    and L.ANULAT = 0
    and I.AN     = current_setting(''PKG_GLOBALS.ANTEMP''  , true)::numeric
    and I.LUNA   = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric
    and L1.CODNIRSTOC = NS.CODNIRSTOC
    and NS.CODIOART   = IO.CODIOART
    and N.CODNIR      = NS.CODNIR
    and coalesce(N.OPERAT, 0) = 1
    and IO.MG &lt;&gt; 5
  union all
  select
    L1.CODNIRSTOC,
    -1 * L1.CANT as REST,
    -1 * L1.CANTUM1 as RESTUM1,
    -1 * L1.CANTUM2 as RESTUM2
  from
    LIVR1 L1
    left join LIVR   L on L.CODLIVR   = L1.CODLIVR
    left join TRANSF T on T.CODTRANSF = L.CODTRANSF,
    NIRSTOC NS,
    NIR N,
    TMP_IOART_LUNA IO
  where
    L.TIPLIVR in (12, 13)
    and L.OPERAT = 1
    and L.ANULAT = 0
    and T.AN     = current_setting(''PKG_GLOBALS.ANTEMP''  , true)::numeric
    and T.LUNA   = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric
    and L1.CODNIRSTOC = NS.CODNIRSTOC
    and NS.CODIOART   = IO.CODIOART
    and N.CODNIR      = NS.CODNIR
    and coalesce(N.OPERAT, 0) = 1
    and IO.MG &lt;&gt; 5
  union all
  select
    L1.CODNIRSTOC,
    L1.CANT as REST,
    L1.CANTUM1 as RESTUM1,
    L1.CANTUM2 as RESTUM2
  from
    LIVR1 L1
    left join LIVR   L on L.CODLIVR = L1.CODLIVR
    left join IESIRI I on I.CODIES  = L.CODIES,
    NIRSTOC NS,
    NIR N,
    TMP_IOART_LUNA IO
  where
    L.TIPLIVR = 15
    and L.OPERAT = 1
    and L.ANULAT = 0
    and I.AN     = current_setting(''PKG_GLOBALS.ANTEMP''  , true)::numeric
    and I.LUNA   = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric
    and L1.CODNIRSTOC = NS.CODNIRSTOC
    and NS.CODIOART   = IO.CODIOART
    and N.CODNIR      = NS.CODNIR
    and coalesce(N.OPERAT, 0) = 1
    and IO.MG &lt;&gt; 5';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_niruri_luna</obj_name>
  <obj_hashval>83cc8b4c01bd46e17f29f99b3867ad08</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_niruri_luna()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
begin
  return
  'select
    NS.CODNIRSTOC,
    NS.CANTNIR as REST,
    NS.CANTUM1 as RESTUM1,
    NS.CANTUM2 as RESTUM2
  from
    NIRSTOC NS
    left join NIR     N on N.CODNIR  = NS.CODNIR
    left join INTRARI I on I.CODINTR = N.CODINTR,
    TMP_IOART_LUNA IO
  where
    N.TIPNIR in (1, 2, 3, 4, 5, 6, 7)
    and N.ANULAT = 0
    and N.OPERAT = 1
    and I.AN   = current_setting(''PKG_GLOBALS.ANTEMP''  , true)::numeric
    and I.LUNA = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric
    and NS.CODIOART = IO.CODIOART
    and IO.MG &lt;&gt; 5
  union all
  select
    NS.CODNIRSTOC,
    NS.CANTNIR as REST,
    NS.CANTUM1 as RESTUM1,
    NS.CANTUM2 as RESTUM2
  from
    NIRSTOC NS
    left join NIR    N on N.CODNIR = NS.CODNIR
    left join IESIRI I on I.CODIES = N.CODIES,
    TMP_IOART_LUNA IO
  where
    N.TIPNIR in (14, 15, 19, 20, 21, 22, 23, 24, 25)
    and N.ANULAT = 0
    and N.OPERAT = 1
    and I.AN   = current_setting(''PKG_GLOBALS.ANTEMP''  , true)::numeric
    and I.LUNA = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric
    and NS.CODIOART = IO.CODIOART
    and IO.MG &lt;&gt; 5
  union all
  select
    NS.CODNIRSTOC,
    NS.CANTNIR as REST,
    NS.CANTUM1 as RESTUM1,
    NS.CANTUM2 as RESTUM2
  from
    NIRSTOC NS
    left join NIR    N on N.CODNIR    = NS.CODNIR
    left join TRANSF T on T.CODTRANSF = N.CODTRANSF,
    TMP_IOART_LUNA IO
  where
    N.TIPNIR in (12, 13)
    and N.ANULAT = 0
    and N.OPERAT = 1
    and T.AN   = current_setting(''PKG_GLOBALS.ANTEMP''  , true)::numeric
    and T.LUNA = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric
    and NS.CODIOART = IO.CODIOART
    and IO.MG &lt;&gt; 5';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_obj_art_auto</obj_name>
  <obj_hashval>81668ff9628e0ab6e700f457d6a9b9eb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_obj_art_auto()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Adina 22.03.2021 - sinc.Oracle
  RETURN
  'SELECT
  A.CODARTICOL,
  O.CODOBIECT,
  A.DEN_ARTICOL,
  A.UM,
  A.CLASA,
  A.TIPSERIE,
  A.TIPARTICOL,
  A.ARETG,
  CASE WHEN COALESCE(OI.CONTIMPLICIT ,0) = 0 THEN AI.CONTIMPLICIT  ELSE OI.CONTIMPLICIT  END CONTIMPLICIT,
  P.DEN_PART AS PRODUCATOR,
  CASE WHEN COALESCE(OI.GESTIMPLICITA,0) = 0 THEN AI.GESTIMPLICITA ELSE OI.GESTIMPLICITA END GESTIMPLICITA,
  A.CERTIFICAT,
  A.EVOLUTIEPRET,
  A.CONTSERVICIU,
  A.UM1,
  A.UM2,
  O.CODEXTERN,
  O.CODINTERN,
  O.UMAMBALARE,
  O.STOCMIN,
  O.STOCMAX,
  O.RETURNABIL,
  O.TERMENPLATA,
  O.PROCADAOSNIR,
  O.PROMOTIE,
  O.BLOCAT,
  NART1LUNA.CODTVA,
  NART1LUNA.CODACCIZE,
  NART1LUNA.CODTAXA1,
  NART1LUNA.CODTAXA2,
  coalesce(TVALUNA.PROCENT, -1) AS PROCTVA,
  NARTOBJ1LUNA.TIPPRETMAX,
  NARTOBJ1LUNA.PRETMAXIMAL AS PUMAXLUNA,
  O.DENUMIRE
FROM
  NART A
  LEFT OUTER JOIN NARTIMPLICITE    AI           ON AI.CODARTICOL          = A.CODARTICOL AND AI.CODSUBUNIT = GETSUBUNITATE_DOC(),
  NARTOBJ                          O
  LEFT OUTER JOIN NPART            P            ON CODPART                = O.CODPRODUCATOR
  LEFT JOIN NARTOBJIMP             OI           ON OI.CODOBIECT           = O.CODOBIECT  AND OI.CODSUBUNIT = GETSUBUNITATE_DOC()
  LEFT OUTER JOIN TMP_NART_LUNA    NART1LUNA    ON NART1LUNA.CODARTICOL   = O.CODARTICOL
  LEFT OUTER JOIN TMP_NTVA_LUNA    TVALUNA      ON TVALUNA.CODTVA         = NART1LUNA.CODTVA
  LEFT OUTER JOIN TMP_NARTOBJ_LUNA NARTOBJ1LUNA ON NARTOBJ1LUNA.CODOBIECT = O.CODOBIECT
WHERE
  O.CODARTICOL = A.CODARTICOL
  AND (SELECT PKG_SELECTARTICOLE_CONDITIECLASA.wme_result FROM PKG_SELECTARTICOLE_CONDITIECLASA(NULL, A.CLASA)) = 1 ';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_obj_art_serii</obj_name>
  <obj_hashval>a535d426baa7ea09a7e2bf390b8f6e87</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_obj_art_serii()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Adina 22.03.2021 - sinc.Oracle
  RETURN
  'SELECT
      A.CODARTICOL,
      O.CODOBIECT,
      A.DEN_ARTICOL,
      A.UM,
      A.CLASA,
      A.TIPSERIE,
      A.TIPARTICOL,
      A.ARETG,
      CASE WHEN COALESCE(OI.CONTIMPLICIT,0) = 0 THEN AI.CONTIMPLICIT ELSE OI.CONTIMPLICIT END CONTIMPLICIT,
      P.DEN_PART AS PRODUCATOR,
      CASE WHEN COALESCE(OI.GESTIMPLICITA,0) = 0 THEN AI.GESTIMPLICITA ELSE OI.GESTIMPLICITA END GESTIMPLICITA,
      A.CERTIFICAT,
      A.EVOLUTIEPRET,
      A.CONTSERVICIU,
      A.UM1,
      A.UM2,
      O.CODEXTERN,
      O.CODINTERN,
      O.UMAMBALARE,
      O.STOCMIN,
      O.STOCMAX,
      O.RETURNABIL,
      O.TERMENPLATA,
      O.PROCADAOSNIR,
      O.PROMOTIE,
      O.BLOCAT,
      NART1LUNA.CODTVA,
      NART1LUNA.CODACCIZE,
      NART1LUNA.CODTAXA1,
      NART1LUNA.CODTAXA2,
      coalesce(TVALUNA.PROCENT, -1) AS PROCTVA,
      NARTOBJ1LUNA.TIPPRETMAX,
      NARTOBJ1LUNA.PRETMAXIMAL AS PUMAXLUNA,
      O.DENUMIRE AS DENOBIECT,
      A.RELATIEUM1,
      A.RELATIEUM2,
      (
        SELECT PM.LEI
        FROM
          PRETM PM,
          NCATPRET CAT
        WHERE
          PM.CODOBIECT = O.CODOBIECT
          AND CAT.CODCATPRET = PM.CODCATPRET
          AND coalesce(PM.subunitatea,1) = (CASE WHEN GETSUBUNITATE()= 1 THEN coalesce(PM.subunitatea, 1) ELSE GETSUBUNITATE() END)
          AND PM.IMPLICIT = 1
          AND CAT.TIP IN (1, 2)
          LIMIT 1
       ) AS PRETVANZARE,
       A.D1,
       A.D2,
       A.D3,
       O.ROTVALUTA AS ROTUNJIRE
   FROM
      NART A
      LEFT OUTER JOIN NARTIMPLICITE    AI           ON AI.CODARTICOL          = A.CODARTICOL AND AI.CODSUBUNIT = GETSUBUNITATE_DOC(),
      NARTOBJ                          O
      LEFT OUTER JOIN NPART            P            ON CODPART                = O.CODPRODUCATOR
      LEFT JOIN NARTOBJIMP             OI           ON OI.CODOBIECT           = O.CODOBIECT  AND OI.CODSUBUNIT = GETSUBUNITATE_DOC()
      LEFT OUTER JOIN TMP_NART_LUNA    NART1LUNA    ON NART1LUNA.CODARTICOL   = O.CODARTICOL
      LEFT OUTER JOIN TMP_NTVA_LUNA    TVALUNA      ON TVALUNA.CODTVA         = NART1LUNA.CODTVA
      LEFT OUTER JOIN TMP_NARTOBJ_LUNA NARTOBJ1LUNA ON NARTOBJ1LUNA.CODOBIECT = O.CODOBIECT
   WHERE
     O.CODARTICOL = A.CODARTICOL
     AND (SELECT PKG_SELECTARTICOLE_CONDITIECLASA.wme_result FROM PKG_SELECTARTICOLE_CONDITIECLASA(NULL, A.CLASA)) = 1 AND A.Tipserie &gt; 0 ';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_objart_ext</obj_name>
  <obj_hashval>0bfee53b4a5bff79c09939af000d96ad</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_objart_ext()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
begin
  --Adina 22.03.2021
  return
  'SELECT
      A.CODARTICOL,
      O.CODOBIECT,
      A.DEN_ARTICOL,
      A.UM,
      A.CLASA,
      A.TIPSERIE,
      A.TIPARTICOL,
      A.ARETG,
      CASE WHEN COALESCE(OI.CONTIMPLICIT,0) = 0 THEN AI.CONTIMPLICIT ELSE COALESCE(OI.CONTIMPLICIT,0) END CONTIMPLICIT,
      P.DEN_PART AS PRODUCATOR,
      CASE WHEN COALESCE(OI.GESTIMPLICITA,0) = 0 THEN AI.GESTIMPLICITA ELSE COALESCE(OI.GESTIMPLICITA,0) END GESTIMPLICITA,
      A.CERTIFICAT,
      A.EVOLUTIEPRET,
      A.CONTSERVICIU,
      A.UM1,
      A.UM2,
      O.CODEXTERN,
      O.CODINTERN,
      O.UMAMBALARE,
      O.STOCMIN,
      O.STOCMAX,
      O.RETURNABIL,
      O.TERMENPLATA,
      O.PROCADAOSNIR,
      O.PROMOTIE,
      O.BLOCAT,
      O.NEFACTURABIL,
      NART1LUNA.CODTVA,
      NART1LUNA.CODACCIZE,
      NART1LUNA.CODTAXA1,
      NART1LUNA.CODTAXA2,
      coalesce(TVALUNA.PROCENT, -1) AS PROCTVA,
      NARTOBJ1LUNA.TIPPRETMAX,
      NARTOBJ1LUNA.PRETMAXIMAL AS PUMAXLUNA,
      O.DENUMIRE AS DENOBIECT,
      A.RELATIEUM1,
      A.RELATIEUM2,
      (
        SELECT PM.LEI
        FROM
          PRETM PM,
          NCATPRET CAT
        WHERE
          PM.CODOBIECT = O.CODOBIECT
          AND CAT.CODCATPRET = PM.CODCATPRET
          AND coalesce(PM.subunitatea,1) = (CASE WHEN GETSUBUNITATE()= 1 THEN coalesce(PM.subunitatea, 1) ELSE GETSUBUNITATE() END)
          AND PM.IMPLICIT = 1
          AND CAT.TIP IN (1, 2)
          LIMIT 1 --AND ROWNUM &lt;=1
       ) AS PRETVANZARE,
      (
        SELECT PM.VALUTA
        FROM
          PRETM PM,
          NCATPRET CAT
        WHERE
          PM.CODOBIECT = O.CODOBIECT
          AND CAT.CODCATPRET = PM.CODCATPRET
          AND coalesce(PM.subunitatea,1) = (CASE WHEN GETSUBUNITATE()= 1 THEN coalesce(PM.subunitatea, 1) ELSE GETSUBUNITATE() END)
          AND PM.IMPLICIT = 1
          AND CAT.TIP IN (1, 2)
          LIMIT 1   --AND ROWNUM &lt;=1
       ) AS PRETVALUTA,
       A.D1,
       A.D2,
       A.D3,
       O.ROTVALUTA AS ROTUNJIRE,
       coalesce(E.CODGRUPA, 0) CodGrupa,
       U.TipUM CANTARIBIL,
       O.CODVAMAL,
       O.Produspropriu,
       A.CODEXTERNART || A.SUFIXCODEXTERN AS CODEXTERNART
   FROM
      NART A
      inner join num u on u.codum = a.um
      LEFT OUTER JOIN NARTIMPLICITE AI ON AI.CODARTICOL = A.CODARTICOL AND AI.CODSUBUNIT = GETSUBUNITATE_DOC(),
      NARTOBJ O
      LEFT OUTER JOIN NPART            P            ON P.CODPART              = O.CODPRODUCATOR
      LEFT OUTER JOIN TMP_NART_LUNA    NART1LUNA    ON NART1LUNA.CODARTICOL   = O.CODARTICOL
      LEFT OUTER JOIN TMP_NTVA_LUNA    TVALUNA      ON TVALUNA.CODTVA         = NART1LUNA.CODTVA
      LEFT OUTER JOIN TMP_NARTOBJ_LUNA NARTOBJ1LUNA ON NARTOBJ1LUNA.CODOBIECT = O.CODOBIECT
      LEFT OUTER JOIN NECHIV           E            ON E.CODOBIECT            = O.CODOBIECT
      LEFT JOIN NARTOBJIMP             OI           ON OI.CODOBIECT           = O.CODOBIECT AND OI.CODSUBUNIT = GETSUBUNITATE_DOC()
   WHERE
     O.CODARTICOL = A.CODARTICOL
   ';
end;

$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_objart_simplu</obj_name>
  <obj_hashval>4740f1d1b88cf3b06b260152349d1506</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_objart_simplu()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
begin
  --Adina 20.03.2021
  return
  'SELECT
      A.CODARTICOL,
      O.CODOBIECT,
      O.DENUMIRE,
      O.CODEXTERN,
      A.UM,
      O.CODINTERN,
      A.DCI,
      coalesce(E.CODGRUPA, 0) CodGrupa,
      CASE WHEN A.SUFIXCODEXTERN IS NOT NULL THEN A.CODEXTERNART || '' '' || A.SUFIXCODEXTERN ELSE A.CODEXTERNART END CODEXTERNART,
      P.DEN_PART AS PRODUCATOR,
      CLA.SIMBOL AS SIMBOLCLASA,
      O.INACTIV,
      A.TipArticol,
      PMM.LEI AS PRETVANZARE,
      PMM.VALUTA AS PRETVALUTA,
      O.PROMOTIE,
      A.CLASA,
      coalesce(CAR.Culoare, A.Culoare) Culoare, CAR.den_carsupart CaractSupl,
      O.CODVAMAL,
      IOA.DEN_IOART,
      G.DEN_GEST,
      LOC.DENUMIRE AS DENLOCATIE,
      T.DEN_TARA,
      IOA.CODIOART,
      LOC.CODLOCATIE,
      G.CODGEST,
      CLAS.DEN_CLASEAS,
      CLA.DEN_CLASEA
   FROM
      NARTOBJ O
      LEFT OUTER JOIN NART    A    ON A.CODARTICOL  = O.CODARTICOL
      LEFT JOIN NARTIMPLICITE AI   ON AI.CODARTICOL = A.CODARTICOL AND AI.CODSUBUNIT = GETSUBUNITATE_DOC()
      LEFT JOIN NARTOBJIMP    OI   ON OI.CODOBIECT  = O.CODOBIECT  AND OI.CODSUBUNIT = GETSUBUNITATE_DOC()
      LEFT JOIN IOART         IOA  ON CASE WHEN COALESCE(OI.CONTIMPLICIT    ,0) = 0 THEN AI.CONTIMPLICIT     ELSE COALESCE(OI.CONTIMPLICIT    ,0) END = IOA.CODIOART
      LEFT JOIN NLOCATII      LOC  ON CASE WHEN COALESCE(OI.LOCATIEIMPLICITA,0) = 0 THEN AI.LOCATIEIMPLICITA ELSE COALESCE(OI.LOCATIEIMPLICITA,0) END = LOC.CODLOCATIE
      LEFT JOIN NGEST         G    ON CASE WHEN COALESCE(OI.GESTIMPLICITA   ,0) = 0 THEN AI.GESTIMPLICITA    ELSE COALESCE(OI.GESTIMPLICITA   ,0) END = G.CODGEST
      LEFT JOIN NCLASEA       CLA  ON CLA.CODCLASEA    = A.CLASA
      LEFT JOIN NCLASEAS      CLAS ON CLAS.CODCLASEAS  = A.CLASASTATIST
      LEFT JOIN NPART         P    ON P.CODPART        = O.CODPRODUCATOR
      LEFT JOIN NAGENDA       Ag   ON Ag.CODPART       = P.CODPART AND coalesce(ag.Inactiv,0) = 0 AND (BITAND(Ag.SEDIUSOCIAL, 4) &lt;&gt; 0)
      LEFT JOIN NLOCALIT      L    ON L.CODLOCALIT     = Ag.CODLOCALIT
      LEFT JOIN NJUDET        J    ON J.CodJudet       = L.CodJudet
      LEFT JOIN NTARI         T    ON T.CODTARA        = L.CODTARA
      LEFT JOIN NECHIV        E    ON E.CODOBIECT      = O.CODOBIECT
      LEFT JOIN TMP_MANPRETM  PMM  ON PMM.CODOBIECT    = O.CODOBIECT
      LEFT JOIN NCARSUPART    CAR  ON CAR.codcarsupart = O.CODCARACT
   ';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_oblig_client_compens</obj_name>
  <obj_hashval>59e00d7c3ea21a7f58e5a7fe62a91855</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_oblig_client_compens()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Adina 18.12.2020 tichet 41751
  --Adina 23 septembrie 2020
  RETURN
  '  SELECT
      O.CODOBLIGPIF,
       ''PV'' AS DOC,
      C.NRDOC,
      C.DATADOC,
      O.VALOARE,
      O.REST,
      O.TERMEN,
      0 As PRELUAT,
      O.REST AS RAMAS,
      0 AS CODSTINGATOR,
      O.SEMNIFICATIE AS SEMNIFCODSTINS,
      PKG_PLANCONTURI_GETSIMBOLCONT(fnc_GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART_GET_PART_COD_CARACT_LUNA(O.CODPART, GETANLUCRU(), GETLUNALUCRU()))) AS SIMBOLCONT,
      O.ICONT,
      G.MONEDA AS CODMONEDA,
      (select PKG_MONEDE_GET_SIMBOL_MONEDA.wme_result from PKG_MONEDE_GET_SIMBOL_MONEDA(null,G.MONEDA)) AS SIMBOLMONEDA,
      coalesce(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      0 AS CODLOCATIE,
      '''' AS SEDIU,
      C.SUBUNITATEA,
      NS.DEN_SUBUNIT,
      G.PROCTVAAVANS
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G                      ON G.CODGENERAL    = O.CODGENERAL
       LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN COMPENS C                      ON C.CODCOMPENS    = G.CODDOC
      LEFT OUTER JOIN NSUBUNIT NS                    ON NS.CODSUBUNIT   = C.SUBUNITATEA
    WHERE
       C.AN * 12 + C.LUNA &lt;= GETANLUCRU() * 12 + GETLUNALUCRU() AND
      (O.VALOARE &gt; 0) AND
      (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
      O.SEMNIFICATIE IN (1301, 1303, 1351) AND O.ICONT IN (3, 10, 11) AND
      O.CODPART = PKG_NOMPART_GET_PART_CURENT() AND
      PKG_MONEDE_MONEDA_VALIDA(G.MONEDA) = 1 ';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_oblig_client_iesiri</obj_name>
  <obj_hashval>2cab08b768f58729223469418858c7af</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_oblig_client_iesiri()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Adina 18.12.2020 tichet 41751
  --Adina 23 septembrie 2020
  RETURN
  '  SELECT
      O.CODOBLIGPIF,
      I.PREFIXDOC AS DOC,
      I.NRDOC,
      I.DATADOC,
      O.VALOARE,
      O.REST
        - coalesce((SELECT SUM(ES.VALOARE) FROM EMULSTINGERI ES, EMULARE E WHERE ES.CODOBLIGPIF = O.CODOBLIGPIF AND E.CODEMULARE = ES.CODEMULARE AND coalesce(E.PRELUAT, 0) = 0), 0)
      AS REST,
      O.TERMEN,
      0 As PRELUAT,
      O.REST
        - coalesce((SELECT SUM(ES.VALOARE) FROM EMULSTINGERI ES, EMULARE E WHERE ES.CODOBLIGPIF = O.CODOBLIGPIF AND E.CODEMULARE = ES.CODEMULARE AND coalesce(E.PRELUAT, 0) = 0), 0)
       AS RAMAS,
      0 AS CODSTINGATOR,
      O.SEMNIFICATIE AS SEMNIFCODSTINS,
      PKG_PLANCONTURI_GETSIMBOLCONT(fnc_GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART_GET_PART_COD_CARACT_LUNA(O.CODPART, GETANLUCRU(), GETLUNALUCRU()))) AS SIMBOLCONT,
      O.ICONT,
      G.MONEDA AS CODMONEDA,
      (select PKG_MONEDE_GET_SIMBOL_MONEDA.wme_result from PKG_MONEDE_GET_SIMBOL_MONEDA(null,G.MONEDA)) AS SIMBOLMONEDA,
      coalesce(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      I.CODLOCATIE,
      A.OBS AS SEDIU,
      I.SUBUNITATEA,
      NS.DEN_SUBUNIT,
      G.PROCTVAAVANS
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G                      ON G.CODGENERAL    = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN IESIRI I                       ON I.CODIES        = G.CODDOC
      LEFT OUTER JOIN NAGENDA A                      ON A.CODAGENDA     = I.CODLOCATIE
      LEFT OUTER JOIN NSUBUNIT NS                    ON NS.CODSUBUNIT   = I.SUBUNITATEA
    WHERE
       I.AN * 12 + I.LUNA &lt;= GETANLUCRU() * 12 + GETLUNALUCRU() AND
      (O.ICONT NOT IN (6, 7)) AND --fara 408 si 418
      (O.VALOARE &gt;= 0) AND
      (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
       O.SEMNIFICATIE = 200 AND
       O.CODPART = PKG_NOMPART_GET_PART_CURENT() AND
      PKG_MONEDE_MONEDA_VALIDA(G.MONEDA) = 1 ';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_oblig_client_nc</obj_name>
  <obj_hashval>012934ddf1c5fae9abbe9c11127e745a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_oblig_client_nc()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Adina 18.12.2020 tichet 41751
  --Adina 23 septembrie 2020
  RETURN
  '  SELECT
      O.CODOBLIGPIF,
      ''NC'' AS DOC,
       N.NRDOC,
      N.DATADOC,
      O.VALOARE,
      O.REST,
      O.TERMEN,
      0 As PRELUAT,
      O.REST AS RAMAS,
      0 AS CODSTINGATOR,
      O.SEMNIFICATIE AS SEMNIFCODSTINS,
      PKG_PLANCONTURI_GETSIMBOLCONT(fnc_GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART_GET_PART_COD_CARACT_LUNA(O.CODPART, GETANLUCRU(), GETLUNALUCRU()))) AS SIMBOLCONT,
      O.ICONT,
      G.MONEDA AS CODMONEDA,
      (select PKG_MONEDE_GET_SIMBOL_MONEDA.wme_result from PKG_MONEDE_GET_SIMBOL_MONEDA(null,G.MONEDA)) AS SIMBOLMONEDA,
      coalesce(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      0 AS CODLOCATIE,
      '''' AS SEDIU,
      N.SUBUNITATEA,
      NS.DEN_SUBUNIT,
      G.PROCTVAAVANS
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G                      ON G.CODGENERAL    = O.CODGENERAL
       LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN NC1 N1                         ON N1.CODNC1       = G.CODDOC
      LEFT OUTER JOIN NC  N                          ON N.CODNC         = N1.CODNC
      LEFT OUTER JOIN NSUBUNIT NS                    ON NS.CODSUBUNIT   = N.SUBUNITATEA
     WHERE
       N.AN * 12 + N.LUNA &lt;= GETANLUCRU() * 12 + GETLUNALUCRU() AND
      (O.VALOARE &gt; 0) AND
      (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
      O.SEMNIFICATIE IN (1200) AND O.ICONT IN (3, 10, 11) AND
      O.CODPART = PKG_NOMPART_GET_PART_CURENT() AND
      PKG_MONEDE_MONEDA_VALIDA(G.MONEDA) = 1 ';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_oblig_furn</obj_name>
  <obj_hashval>b48e195682658c4a0f5e8b6b19d82205</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_oblig_furn()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Adina 23 septembrie 2020
  RETURN
  'SELECT
    CODOBLIGPIF, DOC, NRDOC, DATADOC, VALOARE, REST, TERMEN, PRELUAT, RAMAS, CODSTINGATOR, SEMNIFCODSTINS, SIMBOLCONT, ICONT,
    CODMONEDA, SIMBOLMONEDA, CURS, TVA, CODLOCATIE, SEDIU, SUBUNITATEA, DEN_SUBUNIT, PROCTVAAVANS
   FROM (' || V_OBLIG_FURN_INTRARI() || ' ) v1
UNION ALL
   SELECT
    CODOBLIGPIF, DOC, NRDOC, DATADOC, VALOARE, REST, TERMEN, PRELUAT, RAMAS, CODSTINGATOR, SEMNIFCODSTINS, SIMBOLCONT, ICONT,
    CODMONEDA, SIMBOLMONEDA, CURS, TVA, CODLOCATIE, SEDIU, SUBUNITATEA, DEN_SUBUNIT, PROCTVAAVANS
   FROM (' || V_OBLIG_FURN_NC() || ' ) v2
UNION ALL
   SELECT
    CODOBLIGPIF, DOC, NRDOC, DATADOC, VALOARE, REST, TERMEN, PRELUAT, RAMAS, CODSTINGATOR, SEMNIFCODSTINS, SIMBOLCONT, ICONT,
    CODMONEDA, SIMBOLMONEDA, CURS, TVA, CODLOCATIE, SEDIU, SUBUNITATEA, DEN_SUBUNIT, PROCTVAAVANS
   FROM (' || V_OBLIG_FURN_COMPENS() || ' ) v3 ';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_oblig_furn_compens</obj_name>
  <obj_hashval>d6e8e1a72506d5b1471e3e35ee987f62</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_oblig_furn_compens()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Adina 18.12.2020 tichet 41751
  --Adina 23 septembrie 2020
  RETURN
  ' SELECT
      O.CODOBLIGPIF,
       ''PV'' AS DOC,
      C.NRDOC,
      C.DATADOC,
      O.VALOARE,
      O.REST,
      O.TERMEN,
      0 AS PRELUAT,
      O.REST AS RAMAS,
      0 AS CODSTINGATOR,
      O.SEMNIFICATIE AS SEMNIFCODSTINS,
      PKG_PLANCONTURI_GETSIMBOLCONT(fnc_GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART_GET_PART_COD_CARACT_LUNA(O.CODPART, GETANLUCRU(), GETLUNALUCRU()))) AS SIMBOLCONT,
      O.ICONT,
      G.MONEDA AS CODMONEDA,
      (select PKG_MONEDE_GET_SIMBOL_MONEDA.wme_result from PKG_MONEDE_GET_SIMBOL_MONEDA(null,G.MONEDA)) AS SIMBOLMONEDA,
      coalesce(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      0 AS CODLOCATIE,
      '''' AS SEDIU,
      C.SUBUNITATEA,
      NSUB.DEN_SUBUNIT,
      G.PROCTVAAVANS
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G                      ON G.CODGENERAL    = O.CODGENERAL
       LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN COMPENS C                      ON C.CODCOMPENS    = G.CODDOC
      LEFT OUTER JOIN NSUBUNIT NSUB                  ON NSUB.CODSUBUNIT = C.SUBUNITATEA
    WHERE
       C.AN * 12 + C.LUNA &lt;= GETANLUCRU() * 12 + GETLUNALUCRU() AND
      (O.VALOARE &gt; 0) AND
      (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
      O.SEMNIFICATIE IN (1351) AND O.ICONT IN (2, 8, 9, 15) AND
      O.CODPART = PKG_NOMPART_GET_PART_CURENT() AND
      PKG_MONEDE_MONEDA_VALIDA(G.MONEDA) = 1 ';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_oblig_furn_intrari</obj_name>
  <obj_hashval>aaac087dc663d2d67e2a4a88f4ffd44b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_oblig_furn_intrari()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Adina 18.12.2020 tichet 41751
  --Adina 23 septembrie 2020
  RETURN
  'SELECT
    O.CODOBLIGPIF,
    I.PREFIXDOC AS DOC,
    I.NRDOC,
    I.DATADOC,
    O.VALOARE,
    O.REST,
    O.TERMEN,
    0 As PRELUAT,
    O.REST AS RAMAS,
    0 AS CODSTINGATOR,
    O.SEMNIFICATIE AS SEMNIFCODSTINS,
    PKG_PLANCONTURI_GETSIMBOLCONT(fnc_GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART_GET_PART_COD_CARACT_LUNA(O.CODPART, GETANLUCRU(), GETLUNALUCRU()))) AS SIMBOLCONT,
    O.ICONT,
    G.MONEDA AS CODMONEDA,
    (select PKG_MONEDE_GET_SIMBOL_MONEDA.wme_result from PKG_MONEDE_GET_SIMBOL_MONEDA(null,G.MONEDA)) AS SIMBOLMONEDA,
    coalesce(GREG.CURS, G.CURS) AS CURS,
    G.TVA,
    I.CODLOCATIE,
    A.OBS AS SEDIU,
    I.SUBUNITATEA,
    NSUB.DEN_SUBUNIT,
    G.PROCTVAAVANS
   FROM
    OBLIGPIF O
    LEFT OUTER JOIN GENERAL G                       ON G.CODGENERAL    = O.CODGENERAL
    LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG   ON GREG.CODGENERAL = G.CODGENERAL
    LEFT OUTER JOIN INTRARI I                       ON I.CODINTR       = G.CODDOC
    LEFT OUTER JOIN NAGENDA A                       ON A.CODAGENDA     = I.CODLOCATIE
    LEFT OUTER JOIN NSUBUNIT NSUB                   ON NSUB.CODSUBUNIT = I.SUBUNITATEA
   WHERE
    (I.OPERAT = 1) AND (I.ANULAT = 0) AND
     I.AN * 12 + I.LUNA &lt;= GETANLUCRU() * 12 + GETLUNALUCRU() AND
    (O.ICONT NOT IN (6, 7)) AND
    (O.VALOARE &gt;= 0) AND
    (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
     O.SEMNIFICATIE = 100 AND
     O.CODPART = PKG_NOMPART_GET_PART_CURENT() AND
    PKG_MONEDE_MONEDA_VALIDA(G.MONEDA) = 1
  UNION  ALL
   SELECT
    O.CODOBLIGPIF,
    ''DVOT'' AS PREFIXDOC,
    D.NRDOC,
    D.DATADOC,
    O.VALOARE,
    O.REST,
    O.TERMEN,
    0 As PRELUAT,
    O.REST AS RAMAS,
    0 AS CODSTINGATOR,
    O.SEMNIFICATIE AS SEMNIFCODSTINS,
    PKG_PLANCONTURI_GETSIMBOLCONT(fnc_GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART_GET_PART_COD_CARACT_LUNA(O.CODPART, GETANLUCRU(), GETLUNALUCRU()))) AS SIMBOLCONT,
    O.ICONT,
    G.MONEDA AS CODMONEDA,
    (select PKG_MONEDE_GET_SIMBOL_MONEDA.wme_result from PKG_MONEDE_GET_SIMBOL_MONEDA(null,G.MONEDA)) AS SIMBOLMONEDA,
    coalesce(GREG.CURS, G.CURS) AS CURS,
    G.TVA,
    I.CODLOCATIE,
    A.OBS AS SEDIU,
    I.SUBUNITATEA,
    NSUB.DEN_SUBUNIT,
    G.PROCTVAAVANS
   FROM
    OBLIGPIF O
    LEFT OUTER JOIN GENERAL G                       ON G.CODGENERAL = O.CODGENERAL
    LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG   ON GREG.CODGENERAL = G.CODGENERAL
    LEFT OUTER JOIN DVI D                           ON D.CODDVI = G.CODDOC
    LEFT OUTER JOIN INTRARI I                       ON I.CODINTR = D.CODINTR
    LEFT OUTER JOIN NAGENDA A                       ON A.CODAGENDA  = I.CODLOCATIE
    LEFT OUTER JOIN NSUBUNIT NSUB                   ON NSUB.CODSUBUNIT= I.SUBUNITATEA
   WHERE
    (I.OPERAT = 1) AND (I.ANULAT = 0) AND
     I.AN * 12 + I.LUNA &lt;= GETANLUCRU() * 12 + GETLUNALUCRU() AND
    (O.ICONT NOT IN (6, 7)) AND
    (O.VALOARE &gt;= 0) AND
    (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
     O.SEMNIFICATIE = 130 AND
     O.CODPART = PKG_NOMPART_GET_PART_CURENT() AND
    PKG_MONEDE_MONEDA_VALIDA(G.MONEDA) = 1 ';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_oblig_furn_nc</obj_name>
  <obj_hashval>995eb360203e0ab73fb1c3147b142ff5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_oblig_furn_nc()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Adina 18.12.2020 tichet 41751
  --Adina 23 septembrie 2020
  RETURN
  ' SELECT
      O.CODOBLIGPIF,
      ''NC'' AS DOC,
       N.NRDOC,
      N.DATADOC,
      O.VALOARE,
      O.REST,
      O.TERMEN,
      0 As PRELUAT,
      O.REST AS RAMAS,
      0 AS CODSTINGATOR,
      O.SEMNIFICATIE AS SEMNIFCODSTINS,
      PKG_PLANCONTURI_GETSIMBOLCONT(fnc_GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART_GET_PART_COD_CARACT_LUNA(O.CODPART, GETANLUCRU(), GETLUNALUCRU()))) AS SIMBOLCONT,
      O.ICONT,
      G.MONEDA AS CODMONEDA,
      (select PKG_MONEDE_GET_SIMBOL_MONEDA.wme_result from PKG_MONEDE_GET_SIMBOL_MONEDA(null,G.MONEDA)) AS SIMBOLMONEDA,
      coalesce(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      0 AS CODLOCATIE,
      '''' AS SEDIU,
       N.SUBUNITATEA,
       NSUB.DEN_SUBUNIT,
       G.PROCTVAAVANS
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G                      ON G.CODGENERAL    = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN NC1 N1                         ON N1.CODNC1       = G.CODDOC
      LEFT OUTER JOIN NC  N                          ON N.CODNC         = N1.CODNC
      LEFT OUTER JOIN NSUBUNIT NSUB                  ON NSUB.CODSUBUNIT = N.SUBUNITATEA
    WHERE
      (O.VALOARE &gt; 0) AND
       N.AN * 12 + N.LUNA &lt;= GETANLUCRU() * 12 + GETLUNALUCRU() AND
      (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
       O.SEMNIFICATIE IN (1201) AND O.ICONT IN (2, 8, 9, 15) AND
       O.CODPART = PKG_NOMPART_GET_PART_CURENT() AND
      PKG_MONEDE_MONEDA_VALIDA(G.MONEDA) = 1 ';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_obligpart_la_data_pe_part</obj_name>
  <obj_hashval>c0d98c5ab75ca8c8a0efc99570c9fc3f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_obligpart_la_data_pe_part()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 13.12.2022 - fixat 56526
  EXECUTE 'CREATE OR REPLACE VIEW V_OBLIGPART_LA_DATA_PE_PART AS
  SELECT
    CODOBLIGPIF,
    CODGENERAL,
    VALOARE,
    ICONT,
    SEMNIFICATIE,
    CODPART,
    CODGEST,
    CURS,
    TVA,
    STINS,
    CODDOC,
    MONEDA,
    TIPDOC,
    TERMEN
   FROM
     (
      -- INTRARI
      SELECT
        O.CODOBLIGPIF,
        O.CODGENERAL,
        coalesce(O.VALOARE, 0) - coalesce(G.TVA, 0) AS VALOARE,
        O.ICONT,
        O.SEMNIFICATIE,
        O.CODPART,
        IO.CODIOPART1,
        O.CODGEST,
         coalesce(GREG.CURS, G.CURS) AS CURS,
        G.TVA,
        CASE
          WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
          ELSE S.VALOARE
        END AS STINS,
        G.CODDOC,
        G.MONEDA,
        G.TIPDOC,
        O.TERMEN
      FROM
        OBLIGPIF O
        LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
        LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
        LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
        LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
        LEFT OUTER JOIN INTRARI I ON  I.CODINTR = G.CODDOC
      WHERE
       O.SEMNIFICATIE IN (100, 110)
       AND I.DATADOC  &lt;= (SELECT wme_result FROM PKG_GLOBALS_GETDATASOLDPART(NULL, NULL))
       AND I.OPERAT = 1 AND I.ANULAT = 0
       AND O.CODPART = PKG_NOMPART_GET_PART_CURENT()
     UNION ALL
  -- obligatii de stins provenite din DVI -uri
      SELECT
        O.CODOBLIGPIF,
        O.CODGENERAL,
        coalesce(O.VALOARE, 0) - coalesce(G.TVA, 0) AS VALOARE,
        O.ICONT,
        O.SEMNIFICATIE,
        O.CODPART,
        IO.CODIOPART1,
        O.CODGEST,
        coalesce(GREG.CURS, G.CURS) AS CURS,
        G.TVA,
        CASE
          WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
          ELSE S.VALOARE
        END AS STINS,
        G.CODDOC,
        G.MONEDA,
        G.TIPDOC,
        O.TERMEN
      FROM
        OBLIGPIF O
        LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
        LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
        LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL = O.CODGENERAL
        LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
        LEFT OUTER JOIN DVI D      ON G.CODDOC     = D.CODDVI
        LEFT OUTER JOIN INTRARI I  ON I.CODINTR    = D.CODINTR
      WHERE
        O.SEMNIFICATIE IN (130)
        AND I.DATADOC  &lt;= (SELECT wme_result FROM PKG_GLOBALS_GETDATASOLDPART(NULL, NULL))
        AND I.OPERAT = 1 AND I.ANULAT = 0
        AND O.CODPART = PKG_NOMPART_GET_PART_CURENT()
      UNION ALL
     -- AVIZE INTRARE DE STINS
      SELECT
        O.CODOBLIGPIF,
        O.CODGENERAL,
        O.VALOARE AS VALOARE,
        O.ICONT,
        O.SEMNIFICATIE,
        O.CODPART,
        IO.CODIOPART1,
        O.CODGEST,
        coalesce(GREG.CURS, G.CURS) AS CURS,
        G.TVA,
        S.VALOARE AS STINS,
        G.CODDOC,
        G.MONEDA,
        G.TIPDOC,
        O.TERMEN
      FROM
           OBLIGPIF O
           LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
           LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
           LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
           LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
           LEFT OUTER JOIN INTRARI I ON  I.CODINTR = G.CODDOC
      WHERE
          O.SEMNIFICATIE IN (140) AND I.TIPDOC = 2
          AND I.DATADOC  &lt;= (SELECT wme_result FROM PKG_GLOBALS_GETDATASOLDPART(NULL, NULL))
          AND I.OPERAT = 1 AND I.ANULAT = 0
          AND O.CODPART = PKG_NOMPART_GET_PART_CURENT()
      UNION ALL
     -- AVIZE IESIRE DE STINS
      SELECT
        O.CODOBLIGPIF,
        O.CODGENERAL,
        O.VALOARE AS VALOARE,
        O.ICONT,
        O.SEMNIFICATIE,
        O.CODPART,
        IO.CODIOPART1,
        O.CODGEST,
        coalesce(GREG.CURS, G.CURS) AS CURS,
        G.TVA,
        S.VALOARE AS STINS,
        G.CODDOC,
        G.MONEDA,
        G.TIPDOC,
        O.TERMEN
      FROM
        OBLIGPIF O
        LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
        LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
        LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
        LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
        LEFT OUTER JOIN IESIRI I   ON  I.CODIES = G.CODDOC
      WHERE
        O.SEMNIFICATIE IN (240)
        AND I.TIPDOC = 20
        AND I.DATADOC  &lt;= (SELECT wme_result FROM PKG_GLOBALS_GETDATASOLDPART(NULL, NULL))
        AND I.OPERAT = 1 AND I.ANULAT = 0
        AND O.CODPART = PKG_NOMPART_GET_PART_CURENT()
      UNION ALL
     -- obligatii de stins provenite din IESIRI
      SELECT
        O.CODOBLIGPIF,
        O.CODGENERAL,
        coalesce(O.VALOARE, 0) - coalesce(G.TVA, 0) AS VALOARE,
        O.ICONT,
        O.SEMNIFICATIE,
        O.CODPART,
        IO.CODIOPART1,
        O.CODGEST,
         coalesce(GREG.CURS, G.CURS) AS CURS,
        G.TVA,
        CASE
          WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
          ELSE S.VALOARE
        END AS STINS,
        G.CODDOC,
        G.MONEDA,
        G.TIPDOC,
        O.TERMEN
      FROM
        OBLIGPIF O
        LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
        LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
        LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
        LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
        LEFT OUTER JOIN IESIRI I   ON  I.CODIES = G.CODDOC
      WHERE
        O.SEMNIFICATIE IN (200, 210)
        AND I.DATADOC  &lt;= (SELECT wme_result FROM PKG_GLOBALS_GETDATASOLDPART(NULL, NULL))
        AND I.OPERAT = 1 AND I.ANULAT = 0
        AND O.CODPART = PKG_NOMPART_GET_PART_CURENT()
      UNION ALL
     -- obligatii de stins provenite din tranzactii CASA/BANCA (plati in avans = 310, incasari in avans = 410)
      SELECT
        O.CODOBLIGPIF,
        O.CODGENERAL,
        coalesce(O.VALOARE, 0) - coalesce(G.TVA, 0) AS VALOARE,
        O.ICONT,
        O.SEMNIFICATIE,
        O.CODPART,
        IO.CODIOPART1,
        O.CODGEST,
        coalesce(GREG.CURS, G.CURS) AS CURS,
        G.TVA,
        CASE
          WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
          ELSE S.VALOARE
        END AS STINS,
           G.CODDOC,
        G.MONEDA,
        G.TIPDOC,
        O.TERMEN
      FROM
        OBLIGPIF O
        LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
        LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
        LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
        LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
        LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
        LEFT OUTER JOIN TREZOR  T  ON T.CODTREZOR   = T1.CODTREZOR
      WHERE
       ((T1.INITIALIZARI = 1)OR(coalesce(T1.INITIALIZARI, 0) &lt;&gt; 1 AND T.OPERAT = 1))AND
        G.TIPDOC IN (29, 30, 31, 33)
        AND coalesce(T.DATADOC, TO_DATE(''01.01.1900'', ''dd.mm.yyyy''))  &lt;= (SELECT wme_result FROM PKG_GLOBALS_GETDATASOLDPART(NULL, NULL))
        AND G.SEMNIFICATIE IN (310, 410, 330, 430)
        AND O.CODPART = PKG_NOMPART_GET_PART_CURENT()
      UNION ALL
     -- obligatii de stins provenite din NOTE CONTABILE
      SELECT
        O.CODOBLIGPIF,
        O.CODGENERAL,
        O.VALOARE,
        O.ICONT,
        O.SEMNIFICATIE,
        O.CODPART,
        IO.CODIOPART1,
        O.CODGEST,
         coalesce(GREG.CURS, G.CURS) AS CURS,
        G.TVA,
        CASE
          WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
          ELSE S.VALOARE
        END AS STINS,
        G.CODDOC,
        G.MONEDA,
        G.TIPDOC,
        O.TERMEN
      FROM
        OBLIGPIF O
        LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
        LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
        LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
        LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
        LEFT OUTER JOIN NC1 N1   ON  N1.CODNC1 = G.CODDOC
        LEFT OUTER JOIN NC N ON N.CODNC = N1.CODNC
      WHERE
        O.SEMNIFICATIE IN (1200, 1201)
        AND N.DATADOC &lt;= (SELECT wme_result FROM PKG_GLOBALS_GETDATASOLDPART(NULL, NULL))
        AND O.CODPART = PKG_NOMPART_GET_PART_CURENT()
      UNION ALL
     -- obligatii de stins provenite din COMPENSARI
      SELECT
        O.CODOBLIGPIF,
        O.CODGENERAL,
        coalesce(O.VALOARE, 0) - coalesce(G.TVA, 0) AS VALOARE,
        O.ICONT,
        O.SEMNIFICATIE,
        O.CODPART,
        IO.CODIOPART1,
        O.CODGEST,
        coalesce(GREG.CURS, G.CURS) AS CURS,
        G.TVA,
        CASE
          WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
          ELSE S.VALOARE
        END AS STINS,
        G.CODDOC,
        G.MONEDA,
        G.TIPDOC,
        O.TERMEN
      FROM
        OBLIGPIF O
        LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
        LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
        LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL = O.CODGENERAL
        LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
        LEFT OUTER JOIN COMPENS C  ON C.CODCOMPENS = G.CODDOC
      WHERE
        O.SEMNIFICATIE IN (1301, 1351, 1303)
        AND C.DATADOC &lt;= (SELECT wme_result FROM PKG_GLOBALS_GETDATASOLDPART(NULL, NULL))
        AND O.CODPART = PKG_NOMPART_GET_PART_CURENT()
  ) a_pg;';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_pmp_iesiri</obj_name>
  <obj_hashval>94d804509316609519c699d32b6c29b6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_pmp_iesiri(vcodobiect numeric DEFAULT 0, vcodsubunit numeric DEFAULT 0)
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
DECLARE
  sView        TEXT;
  sViewTPMP    TEXT := '';
  sSubunit     TEXT;
  sFiltru      TEXT := '';
  valTRANSFPMP TEXT;
  vALtemp      NUMERIC := current_setting('PKG_GLOBALS.ANTEMP', true)::numeric * 12 + current_setting('PKG_GLOBALS.LUNATEMP', true)::NUMERIC;
BEGIN
  --Stef 29.09.2025
  IF vcodsubunit = 1
  THEN sSubunit  := '1';
  ELSE sSubunit  := 'D.SUBUNITATEA';
  END IF;

  IF COALESCE(vcodobiect, 0) &gt; 0 THEN
    sFiltru := sFiltru ||'
          AND NS.CODOBIECT = '||vcodobiect::TEXT;
  END IF;
  IF COALESCE(vcodsubunit, 0) &gt; 1 THEN
    sFiltru := sFiltru ||'
          AND D.SUBUNITATEA = '||vcodsubunit::TEXT;
  END IF;

  BEGIN
    SELECT K.VALOARE INTO STRICT valTRANSFPMP FROM TMP_CONSTANTE K WHERE K.SIMBOL = 'TRANSFPMP' AND K.AnLuna = vALtemp;
  EXCEPTION
    WHEN OTHERS THEN valTRANSFPMP = '2';
  END;

  IF valTRANSFPMP &lt;&gt; '3' THEN
    sViewTPMP := '
        UNION ALL
        SELECT
          NS.CODOBIECT, '||sSubunit||' AS CODSUBUNIT,
          NS.CANTNIR AS CANTINTR,
          0 AS RESTLUNA,
          COALESCE(NS.PRET,0)-COALESCE(NS.ADAOS, 0) AS PU, COALESCE(NS.PUVAL, 0) AS PUVAL
        FROM TRANSF D
          INNER JOIN NIR     N   ON N.CODTRANSF    = D.CODTRANSF  AND N.TIPNIR = D.TIPDOC
          INNER JOIN NIRSTOC NS  ON NS.CODNIR      = N.CODNIR
          INNER JOIN NIRSTOC NSP ON NSP.CODNIRSTOC = NS.CODNIRSTOCPARINTE
        WHERE D.AN = current_setting(''PKG_GLOBALS.ANTEMP'', true)::numeric AND D.LUNA = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric AND D.ANULAT = 0 AND D.OPERAT = 1
          AND N.ANULAT = 0 AND N.OPERAT = 1
          AND NOT NS.CODIOART IN (SELECT CODIOART FROM TMP_IOART_LUNA WHERE MG = 3)
          AND    NSP.CODIOART IN (SELECT CODIOART FROM TMP_IOART_LUNA WHERE MG = 3)'||
          sFiltru;
  END IF;

  sView := '
      SELECT CODOBIECT, CODSUBUNIT, SUM(CANTINTR) AS CANTINTR, SUM(CANTINTR*PU) AS VALINTR, SUM(RESTLUNA) AS RESTLUNA, SUM(CANTINTR*PUVAL) AS VALVALUTA
      FROM (
        SELECT
          NS.CODOBIECT, '||sSubunit||' AS CODSUBUNIT,
          CASE '||CASE WHEN valTRANSFPMP = '3' THEN '
            WHEN D.TipDoc = 23                          THEN -L1.CANT' ELSE '' END|| '
            WHEN N.CodIes = L.CodIes AND L.Tiplivr = 15 THEN  L1.CANT
            WHEN N.CodIes = L.CodIes                    THEN -L1.CANT
            ELSE 0
          END AS CANTINTR,
          CASE WHEN D.TIPDOC = 15 THEN L1.CANT ELSE -L1.CANT END AS RESTLUNA,
          COALESCE(NS.PRET,0)-COALESCE(NS.ADAOS, 0) AS PU, COALESCE(NS.PUVAL, 0) AS PUVAL
        FROM IESIRI D
          INNER JOIN LIVR    L  ON L.TIPLIVR     = D.TIPDOC AND L.CODIES = D.CODIES
          INNER JOIN LIVR1   L1 ON L1.CODLIVR    = L.CODLIVR
          INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
          INNER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR
        WHERE D.AN = current_setting(''PKG_GLOBALS.ANTEMP'', true)::numeric AND D.LUNA = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric AND D.ANULAT = 0 AND D.OPERAT = 1
          AND L.ANULAT = 0 AND L.OPERAT = 1
          AND NS.CODIOART IN (SELECT CODIOART FROM TMP_IOART_LUNA WHERE MG = 3)'||
          sFiltru||'
        UNION ALL
        SELECT
          NS.CODOBIECT, '||sSubunit||' AS CODSUBUNIT,
          '||CASE WHEN valTRANSFPMP = '3' THEN '-L1.CANT' ELSE '0' END||' AS CANTINTR,
          -L1.CANT AS RESTLUNA,
          COALESCE(NS.PRET,0)-COALESCE(NS.ADAOS, 0) AS PU, COALESCE(NS.PUVAL, 0) AS PUVAL
        FROM INTRARI D
          INNER JOIN LIVR    L  ON L.TIPLIVR     = D.TIPDOC AND L.CODINTR = D.CODINTR
          INNER JOIN LIVR1   L1 ON L1.CODLIVR    = L.CODLIVR
          INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
          INNER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR
        WHERE D.AN = current_setting(''PKG_GLOBALS.ANTEMP'', true)::numeric AND D.LUNA = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric AND D.ANULAT = 0 AND D.OPERAT = 1
          AND L.ANULAT = 0 AND L.OPERAT = 1
          AND NS.CODIOART IN (SELECT CODIOART FROM TMP_IOART_LUNA WHERE MG = 3)'||
          sFiltru||'
        UNION ALL
        SELECT
          NS.CODOBIECT, '||sSubunit||' AS CODSUBUNIT,
          -L1.CANT AS CANTINTR,
          -L1.CANT AS RESTLUNA,
          COALESCE(NS.PRET,0)-COALESCE(NS.ADAOS, 0) AS PU, COALESCE(NS.PUVAL, 0) AS PUVAL
        FROM TRANSF D
          INNER JOIN LIVR    L  ON L.TIPLIVR     = D.TIPDOC AND L.CODTRANSF = D.CODTRANSF
          INNER JOIN LIVR1   L1 ON L1.CODLIVR    = L.CODLIVR
          INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
          INNER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR
        WHERE D.AN = current_setting(''PKG_GLOBALS.ANTEMP'', true)::numeric AND D.LUNA = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric AND D.ANULAT = 0 AND D.OPERAT = 1
          AND L.ANULAT = 0 AND L.OPERAT = 1
          AND NS.CODIOART IN (SELECT CODIOART FROM TMP_IOART_LUNA WHERE MG = 3)'||
          sFiltru||
        sViewTPMP||'
      ) A_PG
      GROUP BY CODOBIECT, CODSUBUNIT';

  RETURN sView;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_pmp_intrari</obj_name>
  <obj_hashval>a13da14f55641cd94c67fd6d649f6632</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_pmp_intrari(vcodobiect numeric DEFAULT 0, vcodsubunit numeric DEFAULT 0)
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
DECLARE
  sView     TEXT;
  sSubunit  TEXT;
  sFiltru   TEXT := '';
BEGIN
  --Stef 03.03.2023
   IF vcodsubunit = 1
  THEN sSubunit  := '1';
  ELSE sSubunit  := 'D.SUBUNITATEA';
  END IF;

  IF COALESCE(vcodobiect, 0) &gt; 0 THEN
    sFiltru := sFiltru ||'
          AND NS.CODOBIECT = '||vcodobiect::TEXT;
  END IF;
  IF COALESCE(vcodsubunit, 0) &gt; 1 THEN
    sFiltru := sFiltru ||'
          AND D.SUBUNITATEA = '||vcodsubunit::TEXT;
  END IF;

  sView := '
      SELECT CODOBIECT, CODSUBUNIT, SUM(CANTINTR) AS CANTINTR, SUM(CANTINTR*PU) AS VALINTR, SUM(RESTLUNA) AS RESTLUNA, SUM(CANTINTR*PUVAL) AS VALVALUTA
      FROM (
        SELECT NS.CODOBIECT, '||sSubunit||' AS CODSUBUNIT, NS.CANTNIR AS CANTINTR, NS.CANTNIR AS RESTLUNA, COALESCE(NS.PRET,0)-COALESCE(NS.ADAOS, 0) AS PU, COALESCE(NS.PUVAL, 0) AS PUVAL
        FROM INTRARI D
          INNER JOIN NIR     N  ON N.TIPNIR  = D.TIPDOC AND N.CODINTR = D.CODINTR
          INNER JOIN NIRSTOC NS ON NS.CODNIR = N.CODNIR
        WHERE D.AN = current_setting(''PKG_GLOBALS.ANTEMP'', true)::numeric AND D.LUNA = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric AND D.ANULAT = 0 AND D.OPERAT = 1
          AND N.ANULAT = 0 AND N.OPERAT = 1
          AND NS.CODIOART IN (SELECT CODIOART FROM TMP_IOART_LUNA WHERE MG = 3)'||
          sFiltru||'
        UNION ALL
        SELECT NS.CODOBIECT, '||sSubunit||' AS CODSUBUNIT, NS.CANTNIR AS CANTINTR, NS.CANTNIR AS RESTLUNA, COALESCE(NS.PRET,0)-COALESCE(NS.ADAOS, 0) AS PU, COALESCE(NS.PUVAL, 0) AS PUVAL
        FROM TRANSF D
          INNER JOIN NIR     N  ON N.TIPNIR  = D.TIPDOC AND N.CODTRANSF = D.CODTRANSF
          INNER JOIN NIRSTOC NS ON NS.CODNIR = N.CODNIR
        WHERE D.AN = current_setting(''PKG_GLOBALS.ANTEMP'', true)::numeric AND D.LUNA = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric AND D.ANULAT = 0 AND D.OPERAT = 1
          AND N.ANULAT = 0 AND N.OPERAT = 1
          AND NS.CODIOART IN (SELECT CODIOART FROM TMP_IOART_LUNA WHERE MG = 3)'||
          sFiltru||'
      ) A_PG
      GROUP BY CODOBIECT, CODSUBUNIT';

  RETURN sView;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_pmp_intrari_doc</obj_name>
  <obj_hashval>1c42c2692b60bb94d53406619a5fa918</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_pmp_intrari_doc()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 10.01.2021 - fixat 52544
  return
  'SELECT
     CODOBIECT,
     CODSUBUNIT,
     SUM(RESTLUNA) AS RESTLUNA,
     SUM(VALRESTLUNA) AS VALRESTLUNA,
     SUM(VALRESTLUNAV) AS VALRESTLUNAV
   FROM (
   SELECT * FROM
   (
   SELECT -- INTRARI IN STOC
     NS.CODOBIECT,
     G.CODSUBUNIT,
     NS.CANTNIR AS RESTLUNA,
    (NS.PRET  - coalesce(NS.ADAOS, 0)) * NS.CANTNIR AS VALRESTLUNA,
     NS.PUVAL * NS.CANTNIR AS VALRESTLUNAV,
     CASE
       WHEN I.CODINTR IS NOT NULL THEN I.AN
       ELSE T.AN
     END AS AN,
     CASE
       WHEN I.CODINTR IS NOT NULL THEN I.LUNA
       ELSE T.LUNA
     END AS LUNA
   FROM
     NIRSTOC NS,
     NIR N
     LEFT OUTER JOIN INTRARI I ON I.CODINTR    = N.CODINTR   AND N.TIPNIR = I.TIPDOC
     LEFT OUTER JOIN TRANSF  T ON T.CODTRANSF  = N.CODTRANSF AND N.TIPNIR = T.TIPDOC,
     TMP_IOART_LUNA IO,
     NGEST G
   WHERE
     NS.CODIOART = IO.CODIOART
     AND IO.MG = 3
     AND NS.CODNIR = N.CODNIR
     AND N.ANULAT = 0 AND N.OPERAT = 1
     AND G.CODGEST = N.GEST
  ) A_PG
  WHERE
   AN = current_setting(''PKG_GLOBALS.ANTEMP'', true)::numeric AND  LUNA = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric
  ) B_PG
  GROUP BY CODOBIECT, CODSUBUNIT';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_pmp_luna_doc</obj_name>
  <obj_hashval>bcb862d6b36377c0699fc6549cf16cbc</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_pmp_luna_doc()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 10.01.2022 - fixat 52544
  return
   'SELECT
      CODOBIECT, CODSUBUNIT, SUM(RESTLUNA) AS CANTINTR,
                             SUM(VALRESTLUNA) AS VALINTR,
                             SUM(VALRESTLUNAV) AS VALVALUTA
      FROM
      (
       SELECT
         CODOBIECT, CODSUBUNIT, RESTLUNA, VALRESTLUNA, VALRESTLUNAV
       FROM
        ( ' || V_PMP_INTRARI_DOC() || ') A '||'
       UNION ALL
       SELECT
         CODOBIECT, CODSUBUNIT, RESTLUNA, VALRESTLUNA, VALRESTLUNAV
       FROM
        ( ' || V_PMP_IESIRI_DOC() || ') A '||'
      ) a_pg
      GROUP BY
      CODOBIECT, CODSUBUNIT';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_pmp_obiect_iesiri</obj_name>
  <obj_hashval>ddad6ce5e4fa4cfb3f073653f76b722d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_pmp_obiect_iesiri()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 01.03.2023 - fixat 57422
  return
   'SELECT
     CODOBIECT,
     CODSUBUNIT,
     SUM(CANTINTR) AS CANTINTR,
     SUM(VALINTR) AS VALINTR,
     SUM(RESTLUNA) AS RESTLUNA,
     SUM(VALVALUTA) AS VALVALUTA
   FROM
    (
       SELECT * FROM
       (
          SELECT
               NS.CODOBIECT,
               G.CODSUBUNIT,
               (
               CASE
                 WHEN (T.CODTRANSF IS NOT NULL)
                      OR((E.CodIes is not null) and (E.TipDoc = 23) AND (K.VALOARE = ''3''))
                      OR (I.CODINTR IS NOT NULL AND (K.VALOARE = ''3''))
                 THEN -L1.CANT
                 WHEN N.CODIES = L.CodIES and (E.CodIes is not null) THEN
                   CASE
                     WHEN L.Tiplivr = 15 THEN L1.CANT
                     ELSE -L1.CANT
                   END
                 ELSE  0
               END)
               AS CANTINTR,
               CASE
                 WHEN (T.CODTRANSF IS NOT NULL)
                      OR((E.CodIes is not null) and (E.TipDoc = 23) AND (K.VALOARE = ''3''))
                      OR (I.CODINTR IS NOT NULL AND (K.VALOARE = ''3''))
                 THEN  (NS.PRET  - coalesce(NS.ADAOS, 0)) * (-L1.CANT)
                 WHEN N.CODIES = L.CodIES and (E.CodIes is not null) THEN
                   CASE
                     WHEN L.Tiplivr = 15 THEN (NS.PRET  - coalesce(NS.ADAOS, 0)) * (L1.CANT)
                     ELSE (NS.PRET  - coalesce(NS.ADAOS, 0)) * (-L1.CANT)
                   END
                 ELSE 0
               END
               AS VALINTR,
               CASE
                 WHEN (E.CODIES IS NOT NULL)and(E.TIPDOC = 15) THEN L1.CANT
                 ELSE -L1.CANT
               END
               AS RESTLUNA,
              CASE
                WHEN I.CODINTR IS NOT NULL THEN I.AN
                WHEN E.CODIES IS NOT NULL THEN E.AN
                ELSE T.AN
              END AS AN,
              CASE
                WHEN I.CODINTR IS NOT NULL THEN I.LUNA
                WHEN E.CODIES IS NOT NULL THEN E.LUNA
                ELSE T.LUNA
              END AS LUNA,
              CASE
                 WHEN (T.CODTRANSF IS NOT NULL)
                      OR ((E.CodIes is not null) and (E.TipDoc = 23) AND (K.VALOARE = ''3''))
                 THEN  (coalesce(NS.PUVAL,0)) * (-L1.CANT)
                 WHEN N.CODIES = L.CodIES and (E.CodIes is not null) THEN
                   CASE
                     WHEN L.Tiplivr = 15 THEN (coalesce(NS.PUVAL,0)) * L1.CANT
                     ELSE (coalesce(NS.PUVAL,0)) * (-L1.CANT)
                   END
                 ELSE 0
               END
               AS VALVALUTA
          FROM
            LIVR1 L1,
            LIVR L
            LEFT OUTER JOIN IESIRI  E ON E.CODIES    = L.CODIES    AND E.TIPDOC = L.TIPLIVR
            LEFT OUTER JOIN INTRARI I ON I.CODINTR   = L.CODINTR   AND I.TIPDOC = L.TIPLIVR
            LEFT OUTER JOIN TRANSF  T ON T.CODTRANSF = L.CODTRANSF AND T.TIPDOC = L.TIPLIVR,
            TMP_CONSTANTE K,
            NIRSTOC NS,
            TMP_IOART_LUNA IO,
            NIR N,
            NGEST G
          WHERE
           K.SIMBOL = ''TRANSFPMP'' and K.AnLuna = GETANTEMP() * 12 + GETLUNATEMP()
           AND
           L1.CODLIVR = L.CODLIVR
           AND L.OPERAT = 1 AND L.ANULAT = 0
           AND NS.CODNIRSTOC = L1.CODNIRSTOC
           AND NS.CODOBIECT = (select wme_result from PKG_INCHIDERI_GET_CODOBIECT_PMP(null, null))
           AND NS.CODIOART = IO.CODIOART
           AND IO.MG = 3
           AND N.CODNIR = NS.CODNIR
           AND N.GEST = G.CODGEST
      ) a_pg WHERE
        AN = GETANTEMP() AND  LUNA = GETLUNATEMP()
    ) b_pg
    GROUP BY
    CODOBIECT, CODSUBUNIT
    UNION ALL
    SELECT
         CODOBIECT,
         CODSUBUNIT,
         SUM(CANTINTR) AS CANTINTR,
         SUM(VALINTR) AS VALINTR,
         SUM(RESTLUNA) AS RESTLUNA,
         SUM(VALVALUTA) AS VALVALUTA
       FROM
    (
       SELECT * FROM
       (
          SELECT
               NS.CODOBIECT,
               G.CODSUBUNIT,
               NS.CANTNIR AS CANTINTR,
               (NS.PRET  - coalesce(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
               0  AS RESTLUNA,
               T.AN,
               T.LUNA,
               (coalesce(NS.PUVAL,0)) * NS.CANTNIR  AS VALVALUTA
          FROM
            NIRSTOC NS,
            NIRSTOC NSP,
            NIR N,
            TRANSF T,
            TMP_IOART_LUNA IO,
            TMP_IOART_LUNA IOP,
            NGEST G,
            TMP_CONSTANTE K
          WHERE
            K.SIMBOL = ''TRANSFPMP'' and K.AnLuna = (GETANTEMP() * 12 + GETLUNATEMP()) AND K.VALOARE &lt;&gt; ''3''
            AND NS.CODOBIECT = (select wme_result from PKG_INCHIDERI_GET_CODOBIECT_PMP(null, null))
            AND NS.CODNIR = N.CODNIR
            AND N.TIPNIR = 12
            AND T.CODTRANSF = N.CODTRANSF
            AND NSP.CODNIRSTOC = NS.CODNIRSTOCPARINTE
            AND NS.CODIOART = IO.CODIOART
            AND IO.MG &lt;&gt; 3
            AND NSP.CODIOART = IOP.CODIOART
            AND IOP.MG = 3
            AND N.OPERAT = 1 AND N.ANULAT = 0
            AND N.GEST = G.CODGEST
      ) c_pg
      WHERE
        AN = GETANTEMP() AND  LUNA = GETLUNATEMP()
    ) d_pg
    GROUP BY
    CODOBIECT, CODSUBUNIT';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_pmp_obiect_intrari</obj_name>
  <obj_hashval>91afd64d81822d96239df0cc98e39f32</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_pmp_obiect_intrari()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 01.03.2023 - fixat 57422
  return
   'SELECT
     CODOBIECT,
     CODSUBUNIT,
     SUM(CANTINTR) AS CANTINTR,
     SUM(VALINTR) AS VALINTR,
     SUM(RESTLUNA) AS RESTLUNA,
     SUM(VALVALUTA) AS VALVALUTA
   FROM
  (
     SELECT * FROM
     (
     SELECT -- INTRARI IN STOC
       NS.CODOBIECT,
       G.CODSUBUNIT,
       NS.CANTNIR AS CANTINTR,
      (NS.PRET  - coalesce(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
       NS.CANTNIR AS RESTLUNA,
       CASE
         WHEN I.CODINTR IS NOT NULL THEN I.AN
         ELSE T.AN
       END AS AN,
       CASE
         WHEN I.CODINTR IS NOT NULL THEN I.LUNA
         ELSE T.LUNA
       END AS LUNA,
       (coalesce(NS.PUVAL,0)) * NS.CANTNIR AS VALVALUTA
     FROM
       NIRSTOC NS,
       NIR N
       LEFT OUTER JOIN INTRARI I ON I.CODINTR    = N.CODINTR   AND N.TIPNIR = I.TIPDOC
       LEFT OUTER JOIN TRANSF  T ON T.CODTRANSF  = N.CODTRANSF AND N.TIPNIR = T.TIPDOC,
       TMP_IOART_LUNA IO,
       NGEST G
     WHERE
       NS.CODIOART = IO.CODIOART
       AND NS.CODOBIECT = (select wme_result from PKG_INCHIDERI_GET_CODOBIECT_PMP(null, null))
       AND IO.MG = 3
       AND NS.CODNIR = N.CODNIR
       AND N.ANULAT = 0 AND N.OPERAT = 1
       AND G.CODGEST = N.GEST
    ) a_pg
    WHERE
     AN = GETANTEMP() AND  LUNA = GETLUNATEMP()
  ) b_pg
  GROUP BY CODOBIECT, CODSUBUNIT';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_pmp_obiect_luna</obj_name>
  <obj_hashval>c0a9ba22aa37c2812a84baf2fc0d0390</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_pmp_obiect_luna()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
begin
  --Bogdan 20.04.2023 - corectie sum
  --Florin 01.03.2023 - fixat 57422
  return
   'SELECT CODOBIECT, CODSUBUNIT, SUM(CANTINTR) AS CANTINTR,
                       SUM(VALINTR) AS VALINTR,
                       SUM(RESTLUNA) AS RESTLUNA,
                       SUM(VALVALUTA) AS VALVALUTA
   FROM (
     SELECT
     CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, RESTLUNA,VALVALUTA
       FROM (' ||
        V_PMP_OBIECT_INTRARI() ||
       ') e_pg
       UNION ALL
       SELECT
         CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, RESTLUNA,VALVALUTA
       FROM (' ||
        V_PMP_OBIECT_IESIRI() ||
      ') f_pg
    ) g_pg
    GROUP BY
    CODOBIECT, CODSUBUNIT';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_soldpart_stingeri</obj_name>
  <obj_hashval>4bf0c6188d277d87257fe22f34697802</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_soldpart_stingeri()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
begin
  --Adina 26.04.2021
  return
  ' SELECT CODPART, ICONT, CODMONEDA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
    FROM
        (
         SELECT CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA FROM ( '||V_SOLDPART_STINGERI_TREZOR() ||' ) AA1
        UNION ALL
         SELECT CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA FROM ( '||V_SOLDPART_STINGERI_COMPENS()||' ) AA2
        UNION ALL
         (   -- STORNO AVANSURI PE FACTURA INTRARI
           SELECT CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA FROM
            (
              SELECT O_STINGATOR.CODPART, O_STINGATOR.ICONT, G.MONEDA AS CODMONEDA,
                CASE
                  WHEN G.MONEDA  = 0 THEN -(O_STINGATOR.VALOARE - coalesce(G.TVA, 0))
                  WHEN G.MONEDA &lt;&gt; 0 THEN -(O_STINGATOR.VALOARE - coalesce(G.TVA, 0)) * coalesce(GREG.CURS, GEN.CURS)
                END AS SOLDLEI,
                CASE
                  WHEN G.MONEDA  = 0 THEN  0
                  WHEN G.MONEDA &lt;&gt; 0 THEN -(O_STINGATOR.VALOARE - coalesce(G.TVA, 0))
                END AS SOLDVALUTA
              FROM
                 STINGERE S
                 LEFT OUTER JOIN OBLIGPIF       O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
                 LEFT OUTER JOIN GENERAL        G           ON G.CODGENERAL            = O_STINGATOR.CODGENERAL
                 LEFT OUTER JOIN INTRARI        I           ON I.CODINTR               = G.CODDOC AND I.TIPDOC = G.TIPDOC
                 LEFT OUTER JOIN OBLIGPIF       O_STINS     ON O_STINS.CODOBLIGPIF     = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL        GEN         ON GEN.CODGENERAL          = O_STINS.CODGENERAL
                 LEFT OUTER JOIN TMP_INFOSTINSE GREG        ON GREG.CODGENERAL         = GEN.CODGENERAL
              WHERE O_STINGATOR.SEMNIFICATIE IN (111) AND I.AN = '||current_setting('PKG_GLOBALS.ANTEMP',true)||' AND I.LUNA = '||current_setting('PKG_GLOBALS.LUNATEMP',true)||'
                AND (I.OPERAT = 1) AND (I.ANULAT = 0)
                AND (SELECT wme_result FROM PKG_NOMPART_CODPART_SOLD_ANALIZAT_VALID(null, O_STINGATOR.CODPART)) = 1
            ) AA_PG
         )
        UNION ALL
         (
         -- STORNO AVANSURI PE FACTURA IESIRE
         -- STINGERE SEMNIFICATIE 400 (MONETARE)
           SELECT CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA FROM
            (
              SELECT O_STINGATOR.CODPART, O_STINGATOR.ICONT, G.MONEDA AS CODMONEDA,
                CASE
                  WHEN G.MONEDA = 0  THEN  O_STINGATOR.VALOARE - coalesce(G.TVA, 0)
                  WHEN G.MONEDA &lt;&gt; 0 THEN (O_STINGATOR.VALOARE - coalesce(G.TVA, 0)) * coalesce(GREG.CURS, GEN.CURS)
                END  * CASE WHEN O_STINGATOR.SEMNIFICATIE IN (400) THEN -1 ELSE 1 END AS SOLDLEI,
                CASE
                  WHEN G.MONEDA  = 0 THEN  0
                  WHEN G.MONEDA &lt;&gt; 0 THEN O_STINGATOR.VALOARE - coalesce(G.TVA, 0)
                END * CASE WHEN O_STINGATOR.SEMNIFICATIE IN (400) THEN -1 ELSE 1 END AS SOLDVALUTA
              FROM
                STINGERE S
                LEFT OUTER JOIN OBLIGPIF       O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
                LEFT OUTER JOIN GENERAL        G           ON G.CODGENERAL            = O_STINGATOR.CODGENERAL
                LEFT OUTER JOIN IESIRI         I           ON I.CODIES                = G.CODDOC AND I.TIPDOC = G.TIPDOC
                LEFT OUTER JOIN OBLIGPIF       O_STINS     ON O_STINS.CODOBLIGPIF     = S.CODSTINSPIF
                LEFT OUTER JOIN GENERAL        GEN         ON GEN.CODGENERAL          = O_STINS.CODGENERAL
                LEFT OUTER JOIN TMP_INFOSTINSE GREG        ON GREG.CODGENERAL         = GEN.CODGENERAL
              WHERE O_STINGATOR.SEMNIFICATIE IN (211, 400) AND I.AN = '||current_setting('PKG_GLOBALS.ANTEMP',true)||' AND I.LUNA = '||current_setting('PKG_GLOBALS.LUNATEMP',true)||'
                AND (I.OPERAT = 1) AND (I.ANULAT = 0)
                AND (SELECT wme_result FROM PKG_NOMPART_CODPART_SOLD_ANALIZAT_VALID(null, O_STINGATOR.CODPART)) = 1
            ) CC_PG
        )
        ) EE_PG
    GROUP BY CODPART, ICONT, CODMONEDA
    ';
end;

$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_soldpart_stingeri_compens</obj_name>
  <obj_hashval>030d0ed2ff6a31c80341377b6f98d014</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_soldpart_stingeri_compens()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
begin
  --Adina 26.04.2021
  return
  ' SELECT CODPART, ICONT, CODMONEDA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
    FROM
    (
      -- stingeri prin compensari
      SELECT
       O_STINS.CODPART, O_STINS.ICONT, G.MONEDA AS CODMONEDA,
       (
         CASE
           -- STINGERE obligatii plata furn +  STINGERE AVANS CLIENT
           WHEN O_STINS.SEMNIFICATIE  IN (100, 130, 200, 1200, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA = 0  THEN S.VALOARE
           WHEN O_STINS.SEMNIFICATIE  IN (100, 130, 200, 1200, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA &lt;&gt; 0 THEN S.VALOARE *  coalesce(GREG.CURS, GEN.CURS)
           WHEN O_STINS.SEMNIFICATIE  IN (410, 430) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA = 0  THEN  S.VALOARE - coalesce(G.TVA, 0)
           WHEN O_STINS.SEMNIFICATIE  IN( 410, 430) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA &lt;&gt; 0 THEN (S.VALOARE - coalesce(G.TVA, 0)) *  coalesce(GREG.CURS, GEN.CURS)
           -- STINGERE AVANS furn  + STINGERE obligatii incasare client
           WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 200, 1200, 1201, 1301, 1303)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA = 0  THEN -S.VALOARE
           WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 200, 1200, 1201, 1301, 1303)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA &lt;&gt; 0 THEN -S.VALOARE *  coalesce(GREG.CURS, GEN.CURS)
           WHEN (O_STINS.SEMNIFICATIE IN (310, 330)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA = 0  THEN -(S.VALOARE - coalesce(G.TVA, 0))
           WHEN (O_STINS.SEMNIFICATIE IN (310, 330)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA &lt;&gt; 0 THEN -(S.VALOARE - coalesce(G.TVA, 0))  *  coalesce(GREG.CURS, GEN.CURS)
         END
       ) AS SOLDLEI,
       (
         CASE
           -- STINGERE obligatii plata furn + STINGERE AVANS CLIENT
           WHEN O_STINS.SEMNIFICATIE IN (100, 130, 200, 1200, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA = 0  THEN 0
           WHEN O_STINS.SEMNIFICATIE IN (100, 130, 200, 1200, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA &lt;&gt; 0 THEN S.VALOARE
           WHEN O_STINS.SEMNIFICATIE IN (410, 430) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA = 0  THEN 0
           WHEN O_STINS.SEMNIFICATIE IN (410, 430) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA &lt;&gt; 0 THEN S.VALOARE - coalesce(G.TVA, 0)
           -- STINGERE AVANS furn + STINGERE obligatii incasare client
           WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 200, 1200, 1201, 1301, 1303)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA = 0  THEN 0
           WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 200, 1200, 1201, 1301, 1303)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA &lt;&gt; 0 THEN -S.VALOARE
           WHEN (O_STINS.SEMNIFICATIE IN (310, 330)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA = 0  THEN 0
           WHEN (O_STINS.SEMNIFICATIE IN (310, 330)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA &lt;&gt; 0 THEN -(S.VALOARE - coalesce(G.TVA, 0))
         END
       ) AS SOLDVALUTA
      FROM
        STINGERE S
        LEFT OUTER JOIN OBLIGPIF       O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
        LEFT OUTER JOIN GENERAL        G           ON G.CODGENERAL            = O_STINGATOR.CODGENERAL
        LEFT OUTER JOIN COMPENS        CO          ON CO.CODCOMPENS           = G.CODDOC
        LEFT OUTER JOIN OBLIGPIF       O_STINS     ON O_STINS.CODOBLIGPIF     = S.CODSTINSPIF
        LEFT OUTER JOIN GENERAL        GEN         ON GEN.CODGENERAL          = O_STINS.CODGENERAL
        LEFT OUTER JOIN TMP_INFOSTINSE GREG        ON GREG.CODGENERAL         = GEN.CODGENERAL
      WHERE
        G.TIPDOC = 28 AND CO.AN = '||current_setting('PKG_GLOBALS.ANTEMP',true)||' AND CO.LUNA = '||current_setting('PKG_GLOBALS.LUNATEMP',true)||'
        AND (SELECT wme_result FROM PKG_NOMPART_CODPART_SOLD_ANALIZAT_VALID(null, O_STINS.CODPART)) = 1
    ) AA_PG
    GROUP BY CODPART, ICONT, CODMONEDA
    ';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_soldpart_stingeri_trezor</obj_name>
  <obj_hashval>87e26c2daee22c0e80c1031229468524</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_soldpart_stingeri_trezor()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
begin
  --Adina 26.04.2021
  return
  ' SELECT CODPART, ICONT, CODMONEDA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
    FROM
    (
      -- stingeri prin tranzactii casa/banca
      SELECT
       O_STINS.CODPART, O_STINS.ICONT, G.MONEDA AS CODMONEDA,
       (
         CASE
           -- STINGERE obligatii plata furn
           WHEN O_STINS.SEMNIFICATIE  IN (100, 130, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (300, 700) AND G.MONEDA = 0  THEN S.VALOARE
           WHEN O_STINS.SEMNIFICATIE  IN (100, 130, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (300, 700) AND G.MONEDA &lt;&gt; 0 THEN S.VALOARE *  coalesce(GREG.CURS, GEN.CURS)
           -- STINGERE AVANS furn
           WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 310, 330, 1200, 1301)) AND (O_STINGATOR.SEMNIFICATIE IN (320, 701)) AND G.MONEDA = 0  THEN -(S.VALOARE - coalesce(G.TVA, 0))
           WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 310, 330, 1200, 1301)) AND (O_STINGATOR.SEMNIFICATIE IN (320, 701)) AND G.MONEDA &lt;&gt; 0 THEN -(S.VALOARE - coalesce(G.TVA, 0)) *  coalesce(GREG.CURS, GEN.CURS)
           -- STINGERE obligatii incasare client
           WHEN O_STINS.SEMNIFICATIE  IN (200, 1200, 1301, 1303) AND O_STINGATOR.SEMNIFICATIE IN (400, 750) AND G.MONEDA = 0  THEN -S.VALOARE
           WHEN O_STINS.SEMNIFICATIE  IN (200, 1200, 1301, 1303) AND O_STINGATOR.SEMNIFICATIE IN (400, 750) AND G.MONEDA &lt;&gt; 0 THEN -S.VALOARE *  coalesce(GREG.CURS, GEN.CURS)
           -- STINGERE AVANS CLIENT
           WHEN (O_STINS.SEMNIFICATIE IN (200, 410, 430, 1201, 1351)) AND (O_STINGATOR.SEMNIFICATIE IN (420, 751)) AND G.MONEDA = 0  THEN S.VALOARE  - coalesce(G.TVA, 0)
           WHEN (O_STINS.SEMNIFICATIE IN (200, 410, 430, 1201, 1351)) AND (O_STINGATOR.SEMNIFICATIE IN (420, 751)) AND G.MONEDA &lt;&gt; 0 THEN (S.VALOARE - coalesce(G.TVA, 0)) *  coalesce(GREG.CURS, GEN.CURS)
         END
       ) AS SOLDLEI,
       (
         CASE
           -- STINGERE obligatii plata furn
           WHEN O_STINS.SEMNIFICATIE IN (100, 130, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (300, 700) AND G.MONEDA = 0  THEN 0
           WHEN O_STINS.SEMNIFICATIE IN (100, 130, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (300, 700) AND G.MONEDA &lt;&gt; 0 THEN S.VALOARE
           -- STINGERE AVANS furn
           WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 310, 330, 1200, 1301)) AND (O_STINGATOR.SEMNIFICATIE IN (320, 701)) AND G.MONEDA = 0  THEN 0
           WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 310, 330, 1200, 1301)) AND (O_STINGATOR.SEMNIFICATIE IN (320, 701)) AND G.MONEDA &lt;&gt; 0 THEN -(S.VALOARE - coalesce(G.TVA, 0))
           -- STINGERE obligatii incasare client
           WHEN O_STINS.SEMNIFICATIE IN (200, 1200, 1301, 1303) AND O_STINGATOR.SEMNIFICATIE IN (400, 750) AND G.MONEDA = 0  THEN 0
           WHEN O_STINS.SEMNIFICATIE IN (200, 1200, 1301, 1303) AND O_STINGATOR.SEMNIFICATIE IN (400, 750) AND G.MONEDA &lt;&gt; 0 THEN -S.VALOARE
           -- STINGERE AVANS CLIENT
           WHEN (O_STINS.SEMNIFICATIE IN (200, 410, 430, 1201, 1351)) AND (O_STINGATOR.SEMNIFICATIE IN (420, 751)) AND G.MONEDA = 0  THEN 0
           WHEN (O_STINS.SEMNIFICATIE IN (200, 410, 430, 1201, 1351)) AND (O_STINGATOR.SEMNIFICATIE IN (420, 751)) AND G.MONEDA &lt;&gt; 0 THEN S.VALOARE - coalesce(G.TVA, 0)
         END
       ) AS SOLDVALUTA
      FROM
        STINGERE S
        LEFT OUTER JOIN OBLIGPIF       O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
        LEFT OUTER JOIN GENERAL        G           ON G.CODGENERAL            = O_STINGATOR.CODGENERAL
        LEFT OUTER JOIN TREZOR1        T1          ON T1.CODTREZOR1           = G.CODDOC
        LEFT OUTER JOIN TREZOR         T           ON T.CODTREZOR             = T1.CODTREZOR
        LEFT OUTER JOIN OBLIGPIF       O_STINS     ON O_STINS.CODOBLIGPIF     = S.CODSTINSPIF
        LEFT OUTER JOIN GENERAL        GEN         ON GEN.CODGENERAL          = O_STINS.CODGENERAL
        LEFT OUTER JOIN TMP_INFOSTINSE GREG        ON GREG.CODGENERAL         = GEN.CODGENERAL
      WHERE
       T.OPERAT = 1 AND
       G.TIPDOC IN (29, 30, 31, 33) AND T1.AN = '||current_setting('PKG_GLOBALS.ANTEMP',true)||' AND T1.LUNA = '||current_setting('PKG_GLOBALS.LUNATEMP',true)||'
       AND O_STINS.SEMNIFICATIE NOT IN (500, 600, 800, 801)
       AND (SELECT wme_result FROM PKG_NOMPART_CODPART_SOLD_ANALIZAT_VALID(null, O_STINS.CODPART)) = 1
    ) AA_PG
    GROUP BY CODPART, ICONT, CODMONEDA
    ';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_soldpart_tranzactii</obj_name>
  <obj_hashval>cb464b5d4d1f4212ba176d78906df2a8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_soldpart_tranzactii()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
begin
  --Adina 26.04.2021
  return
  ' SELECT CODPART, ICONT, CODMONEDA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
    FROM
        (
         SELECT CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA FROM V_SOLDPART_DE_STINS
         UNION ALL
         SELECT CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA FROM ( '||V_SOLDPART_STINGERI()||' ) BBB_PG
        ) AAA_PG
    GROUP BY CODPART, ICONT, CODMONEDA
    ';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_soldpartprec_ext</obj_name>
  <obj_hashval>df12202774c149ff067bcecdc27d8dbf</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_soldpartprec_ext()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
begin
  --Adina 26.04.2021
  return
  ' SELECT
     CODPART,
     ICONT,
     CODMONEDA,
     SUM(SOLDLEI) AS SOLDLEI,
     SUM(SOLDVALUTA) AS SOLDVALUTA
    FROM
    (
      SELECT
       CODPART,
       ICONT,
       CODMONEDA,
       CASE WHEN coalesce(CODMONEDA, 0)  = 0 THEN REST ELSE REST * CURS END AS SOLDLEI,
       CASE WHEN coalesce(CODMONEDA, 0) &lt;&gt; 0 THEN REST ELSE 0           END AS SOLDVALUTA
      FROM
      (
        SELECT
          O.CODPART,
          O.ICONT,
          CASE
            WHEN O.SEMNIFICATIE IN (100, 130)           THEN -OL.REST
            WHEN O.SEMNIFICATIE = 140 AND G.TIPDOC = 2  THEN -OL.REST
            WHEN O.SEMNIFICATIE = 110                   THEN OL.REST - coalesce(OL.RESTTVA, 0)
            WHEN O.SEMNIFICATIE = 200                   THEN OL.REST
            WHEN O.SEMNIFICATIE = 240 AND G.TIPDOC = 20 THEN OL.REST
            WHEN O.SEMNIFICATIE = 210                   THEN -(OL.REST - coalesce(OL.RESTTVA, 0))
            WHEN O.SEMNIFICATIE IN (310, 330)           THEN   OL.REST - coalesce(OL.RESTTVA, 0)
            WHEN O.SEMNIFICATIE IN (410, 430)           THEN -(OL.REST - coalesce(OL.RESTTVA, 0))
            WHEN O.SEMNIFICATIE IN (1200, 1201)        AND O.ICONT IN (2, 5, 6, 8, 9, 15, 17)          THEN -OL.REST
            WHEN O.SEMNIFICATIE IN (1200, 1201)        AND O.ICONT IN (3, 4, 7,10, 11, 12, 13, 14)     THEN OL.REST
            WHEN O.SEMNIFICATIE IN (1301, 1351, 1303)  AND O.ICONT IN (2, 5, 8, 9, 15)                 THEN -OL.REST
            WHEN O.SEMNIFICATIE IN (1301, 1351, 1303)  AND O.ICONT IN (3, 4, 6, 7, 10, 11, 12, 13, 14) THEN OL.REST
          END AS REST,
          G.MONEDA AS CODMONEDA,
          coalesce(REG.CURS, G.CURS) AS CURS
        FROM
          OBLIGPIFLUNA OL,
          OBLIGPIF O,
          GENERAL G
          LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA REG ON REG.CODGENERAL = G.CODGENERAL
        WHERE
          OL.REST &lt;&gt; 0
          AND O.SEMNIFICATIE IN (100, 110, 130, 140, 200, 210, 240, 310, 330, 410, 430, 1200, 1201, 1301, 1351, 1303)
          AND OL.AN   = '||current_setting('PKG_GLOBALS.ANPRECEDENT')   ||'
          AND OL.LUNA = '||current_setting('PKG_GLOBALS.LUNAPRECEDENTA')||'
          AND O.CODOBLIGPIF = OL.CODOBLIGPIF
          AND G.CODGENERAL  = O.CODGENERAL
          AND (SELECT wme_result FROM PKG_NOMPART_CODPART_SOLD_ANALIZAT_VALID(null,O.CODPART)) = 1
       ) B_PG
     ) A_PG
    GROUP BY CODPART, ICONT, CODMONEDA
    ';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_stoc_luna</obj_name>
  <obj_hashval>c4c3f8a58ba5da1c1cf4a2c69efaff40</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_stoc_luna()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 10.11.2022 - fixat 56209
  --Florin 24.10.2022 - sinc. oracle
  --Adina aug.2020
  return
  'SELECT CODNIRSTOC, SUM(REST) REST, SUM(RESTUM1) RESTUM1,SUM(RESTUM2) RESTUM2
FROM (
  SELECT N.CODNIRSTOC, N.REST, N.RESTUM1, N.RESTUM2
  FROM NIRLUNA N
    INNER JOIN NIRSTOC NS ON N.CODNIRSTOC = NS.CODNIRSTOC
  WHERE N.AN = (SELECT wme_result FROM PKG_GLOBALS_GETANPRECEDENT(NULL, NULL)) AND N.LUNA = (SELECT wme_result FROM PKG_GLOBALS_GETLUNAPRECEDENTA(NULL, NULL))
    AND (current_setting(''PKG_LIST_SELFISAMAG.p_flgArt'',true)::boolean OR ns.codobiect::varchar IN (SELECT valoare FROM tmp_manevra_liste tmp WHERE filtru = ''CODOBIECT''))
    AND (current_setting(''PKG_LIST_SELFISAMAG.p_flgTipCont'',true)::boolean OR NS.CODIOART::varchar IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = ''CODIOART'') )
  UNION ALL -- NIRURI LUNA
  SELECT NS.CODNIRSTOC, NS.CANTNIR AS REST, NS.CANTUM1 AS RESTUM1, NS.CANTUM2 AS RESTUM2
  FROM NIRSTOC NS
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    LEFT  JOIN INTRARI I ON I.CODINTR = N.CODINTR
    LEFT  JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
  WHERE N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
    AND  N.DATANIR::date &lt;=  to_date( (current_setting(''PKG_LIST_SELFISAMAG.p_dataStoc'',true)), ''dd.mm.yyyy'')
    AND COALESCE(I.AN,T.AN) = (SELECT wme_result FROM PKG_GLOBALS_GETANTEMP(NULL, NULL))
    AND COALESCE(I.LUNA,T.LUNA ) = (SELECT wme_result FROM PKG_GLOBALS_GETLUNATEMP(NULL, NULL))
    AND (current_setting(''PKG_LIST_SELFISAMAG.p_flgArt'',true)::boolean OR ns.codobiect::varchar IN (SELECT valoare FROM tmp_manevra_liste tmp WHERE filtru = ''CODOBIECT''))
    AND (current_setting(''PKG_LIST_SELFISAMAG.p_flgTipCont'',true)::boolean OR NS.CODIOART::varchar IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = ''CODIOART'') )
  UNION ALL
  SELECT
    L1.CODNIRSTOC,
    CASE WHEN L.TIPLIVR = 15 THEN L1.CANT ELSE -1 * L1.CANT END  REST,
    CASE WHEN L.TIPLIVR = 15 THEN L1.CANTUM1 ELSE -1 * L1.CANTUM1 END RESTUM1,
    CASE WHEN L.TIPLIVR = 15 THEN L1.CANTUM2 ELSE -1 * L1.CANTUM2 END RESTUM2
  FROM LIVR L
    INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
    INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
    LEFT JOIN INTRARI I ON I.CODINTR = L.CODINTR
    LEFT JOIN IESIRI IES ON IES.CODIES = L.CODIES
    LEFT JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
  WHERE L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15 ,16, 19, 20, 21, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0
    AND L.DATALIVR::date &lt;= to_date((current_setting(''PKG_LIST_SELFISAMAG.p_dataStoc'',true)), ''dd.mm.yyyy'')
    AND COALESCE(I.AN,IES.AN,T.AN) = (SELECT wme_result FROM PKG_GLOBALS_GETANTEMP(NULL, NULL))
    AND COALESCE(I.LUNA,IES.LUNA,T.LUNA ) = (SELECT wme_result FROM PKG_GLOBALS_GETLUNATEMP(NULL, null))
    AND (current_setting(''PKG_LIST_SELFISAMAG.p_flgArt'',true)::boolean OR ns.codobiect::varchar IN (SELECT valoare FROM tmp_manevra_liste tmp WHERE filtru = ''CODOBIECT''))
    AND (current_setting(''PKG_LIST_SELFISAMAG.p_flgTipCont'',true)::boolean OR NS.CODIOART::varchar IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = ''CODIOART'') )
) a_pg
GROUP BY CODNIRSTOC';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_stoc_luna_prec</obj_name>
  <obj_hashval>554e4bf5f40a3d55251d6ae663cd87e7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_stoc_luna_prec()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
begin
  return
  'SELECT NL.CODNIRSTOC, NL.REST, NL.RESTUM1, NL.RESTUM2
   FROM NIRLUNA NL, NIRSTOC NS, TMP_IOART_LUNA IO
   WHERE
          NL.AN   = current_setting(''PKG_GLOBALS.ANPRECEDENT''   , true)::numeric
      AND NL.LUNA = current_setting(''PKG_GLOBALS.LUNAPRECEDENTA'', true)::numeric
      AND (COALESCE(NL.REST, 0) &lt;&gt; 0 OR  COALESCE(NL.RESTUM1, 0) &lt;&gt; 0 OR  COALESCE(NL.RESTUM2, 0) &lt;&gt; 0)
      AND NL.CODNIRSTOC = NS.CODNIRSTOC
      AND NS.CODIOART = IO.CODIOART
      AND IO.MG &lt;&gt; 5
    ';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_stoc_luna_ser</obj_name>
  <obj_hashval>9d5528d01c1b668420e98ab68976a121</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_stoc_luna_ser()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 17.11.2022 - fixat 56280
  --Florin 24.10.2022 - sinc. Oracle
  --Adina aug.2020
  return
  'SELECT
  STOC.CODNIRSTOC, STOC.CODNIRSER,
  SUM(STOC.REST) REST,
  SUM(STOC.RESTUM1) RESTUM1,
  SUM(STOC.RESTUM2) RESTUM2
FROM (
  SELECT
    NS.CODNIRSTOC, NE.CODNIRSER,
    CASE WHEN coalesce(NE.CODNIRSER, 0) = 0 THEN N.REST    ELSE NE.REST    END REST,
    CASE WHEN coalesce(NE.CODNIRSER, 0) = 0 THEN N.RESTUM1 ELSE NE.RESTUM1 END RESTUM1,
    CASE WHEN coalesce(NE.CODNIRSER, 0) = 0 THEN N.RESTUM2 ELSE NE.RESTUM2 END RESTUM2
  FROM NIRLUNA N
    INNER JOIN NIRSTOC NS ON N.CODNIRSTOC = NS.CODNIRSTOC
    LEFT JOIN NIRSERLUNA NE ON N.CODNIRSTOC = NE.CODNIRSTOC AND N.AN = NE.AN AND N.LUNA = NE.LUNA
  WHERE N.AN = (SELECT wme_result FROM PKG_GLOBALS_GETANPRECEDENT(NULL, NULL)) AND N.LUNA = (SELECT wme_result FROM PKG_GLOBALS_GETLUNAPRECEDENTA(NULL, NULL))
    AND (current_setting(''PKG_LIST_SELFISAMAG.p_flgArt'',true)::boolean OR ns.codobiect::varchar IN (SELECT valoare FROM tmp_manevra_liste tmp WHERE filtru = ''CODOBIECT''))
    AND (current_setting(''PKG_LIST_SELFISAMAG.p_flgTipCont'',true)::boolean OR NS.CODIOART::varchar IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = ''CODIOART''))
  UNION ALL -- NIRURI LUNA
  SELECT
    NS.CODNIRSTOC, NSE.CODNIRSER,
    CASE WHEN coalesce(NSE.CODNIRSER, 0) = 0 THEN NS.CANTNIR ELSE NSE.CANTNIR END REST,
    CASE WHEN coalesce(NSE.CODNIRSER, 0) = 0 THEN NS.CANTUM1 ELSE NSE.CANTUM1 END RESTUM1,
    CASE WHEN coalesce(NSE.CODNIRSER, 0) = 0 THEN NS.CANTUM2 ELSE NSE.CANTUM2 END RESTUM2
  FROM NIRSTOC NS
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    LEFT JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC
    LEFT JOIN INTRARI I ON I.CODINTR = N.CODINTR
    LEFT JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
  WHERE N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
    AND N.DATANIR::date &lt;= to_date((current_setting(''PKG_LIST_SELFISAMAG.p_dataStoc'',true)), ''dd.mm.yyyy'')
    AND COALESCE(I.AN,T.AN) = (SELECT wme_result FROM PKG_GLOBALS_GETANTEMP(NULL, NULL))
    AND COALESCE(I.LUNA,T.LUNA ) = (SELECT wme_result FROM PKG_GLOBALS_GETLUNATEMP(NULL, NULL))
    AND (current_setting(''PKG_LIST_SELFISAMAG.p_flgArt'',true)::boolean OR ns.codobiect::varchar IN (SELECT valoare FROM tmp_manevra_liste tmp WHERE filtru = ''CODOBIECT''))
    AND (current_setting(''PKG_LIST_SELFISAMAG.p_flgTipCont'',true)::boolean OR NS.CODIOART::varchar IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = ''CODIOART'') )
  UNION ALL
  SELECT
    NS.CODNIRSTOC, NSE.CODNIRSER,
    CASE WHEN L.TIPLIVR = 15 THEN L1.CANT    ELSE -L1.CANT    END REST,
    CASE WHEN L.TIPLIVR = 15 THEN L1.CANTUM1 ELSE -L1.CANTUM1 END RESTUM1,
    CASE WHEN L.TIPLIVR = 15 THEN L1.CANTUM2 ELSE -L1.CANTUM2 END RESTUM2
  FROM LIVR1 L1
    INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
    INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
    LEFT JOIN NIRSER NSE ON NSE.CODNIRSER = L1.CODNIRSER
    LEFT JOIN INTRARI I ON I.CODINTR = L.CODINTR
    LEFT JOIN IESIRI IES ON IES.CODIES = L.CODIES
    LEFT JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
  WHERE L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15 ,16, 19, 20, 21, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0
    AND L.DATALIVR::date &lt;= to_date((current_setting(''PKG_LIST_SELFISAMAG.p_dataStoc'',true)), ''dd.mm.yyyy'')
    AND COALESCE(I.AN,IES.AN,T.AN) = (SELECT wme_result FROM PKG_GLOBALS_GETANTEMP(NULL, NULL))
    AND COALESCE(I.LUNA,IES.LUNA,T.LUNA ) = (SELECT wme_result FROM PKG_GLOBALS_GETLUNATEMP(NULL, NULL))
    AND (current_setting(''PKG_LIST_SELFISAMAG.p_flgArt'',true)::boolean OR ns.codobiect::varchar IN (SELECT valoare FROM tmp_manevra_liste tmp WHERE filtru = ''CODOBIECT''))
    AND (current_setting(''PKG_LIST_SELFISAMAG.p_flgTipCont'',true)::boolean OR NS.CODIOART::varchar IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = ''CODIOART'') )
) STOC
GROUP BY STOC.CODNIRSTOC, STOC.CODNIRSER
  ';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_stocluna</obj_name>
  <obj_hashval>e1d9fa086d702d9e21f1bdff7fddb6b6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_stocluna()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
begin
  --Adina aug.2020
  return
  'SELECT CODNIRSTOC, SUM(REST) AS REST, SUM(RESTUM1) AS RESTUM1, SUM(RESTUM2) AS RESTUM2
   FROM
      (
      SELECT CODNIRSTOC, REST, RESTUM1, RESTUM2 FROM ('||V_STOC_LUNA_PREC()      ||') aa_pg
      UNION ALL
      SELECT CODNIRSTOC, REST, RESTUM1, RESTUM2 FROM ('||V_STOC_TRANZACTII_LUNA()||') bb_pg
      ) cc_pg
   GROUP BY CODNIRSTOC
  ';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_stocser_luna_prec</obj_name>
  <obj_hashval>b1414421628dc52a5ed350447843ea47</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_stocser_luna_prec()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$ begin
  return
  'select
    NL.CODNIRSER,
    NL.CODNIRSTOC,
    NL.REST,
    NL.RESTUM1,
    NL.RESTUM2
  from
    NIRSERLUNA NL,
    NIRSTOC NS,
    TMP_IOART_LUNA IO
  where
    NL.AN       = current_setting(''PKG_GLOBALS.ANPRECEDENT''   , true)::numeric
    and NL.LUNA = current_setting(''PKG_GLOBALS.LUNAPRECEDENTA'', true)::numeric
    and coalesce(NL.REST, 0) + coalesce(NL.RESTUM1, 0) + coalesce(NL.RESTUM2, 0) &lt;&gt; 0
    and NL.CODNIRSTOC = NS.CODNIRSTOC
    and NS.CODIOART   = IO.CODIOART
    and IO.MG &lt;&gt; 5';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_urmarire_preturi</obj_name>
  <obj_hashval>3022a717e5e5efa8958c82b200a40b56</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_urmarire_preturi()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  RETURN '
   SELECT
    TAB.CODOBIECT,
    TAB.DATADOC,
    TAB.CODDOC,
    TAB.PACHIZ_RON,
    MON.DEN_MONEDA,
    TAB.PACHIZ_VAL,
    NUM1.DEN_UM1,
    COALESCE(NG.DEN_GEST, NP.DEN_PART) FURNIZOR,
    TAB.PREFIXDOC,
    TAB.NRDOC,
    TAB.CURS,
    TAB.TIPNIR,
    CASE WHEN COALESCE(MONEDA, 0) = 0 THEN NULL ELSE ROUND(TAB.PU, 4) END AS PVAL_DOC,
    TAB.CANT,
    TAB.DATANIR,
    S.DEN_SUBUNIT,
    TAB.DEN_GEST,
    TAB.OBS,
    TAB.PACHIZ_RON_FS,
    COALESCE (NP.CODPART, 0) CODPART,
    COALESCE (NG.CODGEST, 0) CODGEST,
    TAB.OBSDOC
   FROM (
    SELECT
        CODOBIECT,
        DATADOC,
        CODDOC,
        PARTENER,
        MONEDA,
        PACHIZ_RON,
        PACHIZ_VAL,
        CURS ,
        TIPNIR,
        UMSEC,
        PREFIXDOC,
        NRDOC,
        DATANIR,
        SUBUNITATEA,
        DEN_GEST,
        OBS,
        PU,
        PACHIZ_RON_FS,
        OBSDOC,
        SUM(CANT) AS CANT
    FROM (
      SELECT
        NS.CODOBIECT, COALESCE(INTR.DATADOC,IES.DATADOC) DATADOC, COALESCE(INTR.CODINTR,IES.CODIES) CODDOC,
        CASE WHEN N.TIPNIR IN (7,24) THEN COALESCE(INTR.CODGESTPROD, IES.CODGESTPROD) ELSE COALESCE(INTR.PARTENER,IES.PARTENER) END PARTENER,
        COALESCE(COALESCE(IES.MONEDA,INTR.MONEDA),0) MONEDA,
        (NS.PRET - NS.ADAOS) PACHIZ_RON,
        NS.PUVAL PACHIZ_VAL,
        COALESCE(COALESCE(INTR.CURS,IES.CURS),1)CURS ,
        N.TIPNIR,
        NS.UMSEC,
        COALESCE(INTR.PREFIXDOC, IES.PREFIXDOC) || COALESCE(INTR.SERIADOC, IES.SERIADOC) PREFIXDOC,
        COALESCE(INTR.NRDOC,IES.NRDOC) NRDOC,
        NS.CANTNIR AS CANT,
        N.DATANIR,
        COALESCE(INTR.SUBUNITATEA,IES.SUBUNITATEA) SUBUNITATEA,
        G.DEN_GEST, INTR1.OBS,
        CASE
          WHEN NS.CODINTR1 IS NOT NULL THEN (SELECT PU FROM INTRARI1 WHERE CODINTR1 = NS.CODINTR1)
          WHEN NS.CODDVI1  IS NOT NULL THEN (SELECT PU FROM INTRARI1 WHERE CODINTR1 = (SELECT CODINTR1 FROM DVI1 WHERE CODDVI1 = NS.CODDVI1))
        END PU,
        CASE
          WHEN  COALESCE(SUPLIMENT, 0) &lt;&gt; 0 AND COALESCE(CANTNIR, 0) &lt;&gt; 0 THEN (NS.PRET - NS.ADAOS) - COALESCE(SUPLIMENT, 0) / COALESCE(CANTNIR, 0)
          ELSE  (NS.PRET - NS.ADAOS)
        END PACHIZ_RON_FS,
        COALESCE(INTR.OBS, IES.OBS) AS OBSDOC
      FROM TMP_NIRSTOC_MAN NS
        INNER JOIN NIR N          ON NS.CODNIR      = N.CODNIR AND COALESCE(N.OPERAT, 0) = 1 AND COALESCE(N.ANULAT, 0) = 0
        INNER JOIN NGEST G        ON G.CODGEST      = N.GEST
        LEFT  JOIN INTRARI1 INTR1 ON INTR1.CODINTR1 = NS.CODINTR1 AND N.TIPNIR IN (1,2,3,4,7)
        LEFT  JOIN DVI1           ON DVI1.CODDVI1   = NS.CODDVI1 AND N.TIPNIR IN (5)
        LEFT  JOIN INTRARI INTR   ON INTR.CODINTR   = N.CODINTR
        LEFT  JOIN DVI D          ON D.CODINTR      = INTR.CODINTR AND D.CODDVI = DVI1.CODDVI
        LEFT  JOIN LIVR1 L1       ON L1.CODNIRSTOC  = NS.CODNIRSTOC AND L1.CANT &lt; 0 AND N.TIPNIR IN (19,20,21,22,24)
        LEFT  JOIN IESIRI1 IES1   ON IES1.CODIES1   = L1.CODIES1 AND N.TIPNIR IN (19,20,21,22,24)
        LEFT  JOIN IESIRI IES     ON IES.CODIES     = IES1.CODIES
      WHERE
        N.TIPNIR IN (1,2,3,4,5,7,19,20,21,22,24)
      ORDER BY DATADOC DESC
    ) TB
    GROUP BY
      CODOBIECT,
      DATADOC,
      CODDOC,
      PARTENER,
      MONEDA,
      PACHIZ_RON,
      PACHIZ_VAL,
      CURS ,
      TIPNIR,
      UMSEC,
      PREFIXDOC,
      NRDOC,
      DATANIR,
      SUBUNITATEA,
      DEN_GEST,
      OBS,
      PU,
      PACHIZ_RON_FS,
      OBSDOC
  ) TAB
    LEFT JOIN NPART NP    ON TAB.PARTENER  = NP.CODPART AND NOT TAB.TIPNIR IN (7,24)
    LEFT JOIN NGEST NG    ON TAB.PARTENER  = NG.CODGEST AND TAB.TIPNIR IN (7,24)
    LEFT JOIN NMONEDE MON ON MON.CODMONEDA = TAB.MONEDA
    LEFT JOIN NUM1 NUM1X  ON NUM1X.CODUM1  = TAB.UMSEC
    LEFT JOIN NUM1        ON NUM1.CODUM    = NUM1X.CODUM AND NUM1.SECUNDARA=0
    LEFT JOIN NSUBUNIT S  ON S.CODSUBUNIT  = TAB.SUBUNITATEA
  ORDER BY TAB.DATADOC DESC';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_urmarire_preturi_transfval</obj_name>
  <obj_hashval>448602ab787c8c7e878d6daadba338c6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_urmarire_preturi_transfval()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  RETURN '
    SELECT
      CODOBIECT,
      DATADOC,
      CODDOC,
      PRET - ADAOS PACHIZ_RON,
      (SELECT DEN_MONEDA FROM NMONEDE WHERE CODMONEDA = 0) DEN_MONEDA,
      0 AS PACHIZ_VAL,
      DEN_UM1,
      FURNIZOR,
      PREFIXDOC,
      NRDOC,
      1 AS CURS,
      TIPNIR,
      NULL AS PVAL_DOC,
      CANT,
      DATANIR,
      DEN_SUBUNIT,
      DEN_GEST,
      OBS,
      PACHIZ_RON_FS,
      0 CODPPART,
      COALESCE(CODGEST, 0) CODGEST,
      OBSDOC
    FROM (
          SELECT
            ( SELECT Max(MG)
              FROM (SELECT I1.MG, dense_rank() over(PARTITION BY I1.CODIOART ORDER BY I1.ANSTART*12+I1.LUNASTART desc) NR
                    FROM IOART1 I1
                    WHERE I1.CODIOART = NS.CODIOART AND I1.ANSTART*12+I1.LUNASTART &lt;= T.AN*12+T.LUNA
                   ) AA
              WHERE NR=1
            ) MGDEST,
            NS.CODOBIECT,
            NS.CODIOART,
            COALESCE(NS.PRET, 0) AS PRET,
            COALESCE(NS.ADAOS, 0) AS ADAOS,
            NS.UMSEC,
            T.NRDOC,
            T.DATADOC,
            T.CODTRANSF AS CODDOC,
            T.AN,
            T.LUNA,
            G.DEN_GEST AS FURNIZOR,
            U1.DEN_UM1,
            T.PREFIXDOC,
            N.TIPNIR,
            NS.CANTNIR AS CANT,
            N.DATANIR,
            S.DEN_SUBUNIT,
            G.DEN_GEST,
            INTR1.OBS,
            CASE
              WHEN COALESCE(NS.SUPLIMENT, 0) &lt;&gt; 0 AND COALESCE(NS.CANTNIR, 0) &lt;&gt; 0 THEN (NS.PRET - NS.ADAOS) - COALESCE(NS.SUPLIMENT, 0) / COALESCE(NS.CANTNIR, 0)
              ELSE (NS.PRET - NS.ADAOS)
            END PACHIZ_RON_FS,
            G.CODGEST,
            T.OBS AS OBSDOC
          FROM NIRSTOC NS
            INNER JOIN TMP_MANEVRA MAN ON MAN.CODUNIC = NS.CODOBIECT
            INNER JOIN NIR N           ON N.CODNIR    = NS.CODNIR
            INNER JOIN TRANSF T        ON N.CODTRANSF = T.CODTRANSF
            INNER JOIN LIVR1 L1        ON L1.CODLIVR1 = NS.CODLIVR1
            INNER JOIN LIVRVAL LV      ON LV.CODLIVR1 = L1.CODLIVR1
            INNER JOIN NUM1 U1X        ON U1X.CODUM1  = NS.UMSEC
            INNER JOIN NUM1 U1         ON U1.CODUM    = U1X.CODUM AND U1.Secundara = 0
            INNER JOIN NGEST G         ON G.CODGEST   = N.GEST
            INNER JOIN NSUBUNIT S      ON S.CODSUBUNIT   = T.SUBUNITATEA
            LEFT  JOIN INTRARI1 INTR1  ON INTR1.CODINTR1 = NS.CODINTR1
          WHERE N.TIPNIR = 12
         ) AA_PG WHERE MGDEST &lt;&gt; 5';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_urmarire_preturi_vanzare</obj_name>
  <obj_hashval>e0c226aea04d4ef93ba069923b47bd17</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_urmarire_preturi_vanzare()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  RETURN '
    SELECT
      TAB.CODOBIECT,
      TAB.DATADOC,
      TAB.CODDOC,
      ROUND(TAB.PACHIZ_RON,4) AS PACHIZ_RON,
      MON.DEN_MONEDA,
      ROUND(TAB.PACHIZ_VAL,4) AS PACHIZ_VAL,
      NUM1.DEN_UM1,
      NP.DEN_PART CLIENT,
      TAB.PREFIXDOC,
      TAB.NRDOC,
      TAB.CURS,
      TAB.TIPLIVR,
      ROUND(TAB.PU, 4) PU_DOC,
      ROUND(TAB.CANT, 5) CANT,
      TAB.DATANIR,
      S.DEN_SUBUNIT,
      TAB.DEN_GEST,
      TAB.OBS,
      TAB.CURSDOC AS CURSTRANSF,
      MON_TRANSF.SIMBOL AS MONTRANSF,
      ROUND(TAB.PUTRANSF, 4) AS PUTRANSF,
      COALESCE (NP.CODPART, 0) CODPART,
      TAB.OBSDOC
    FROM (
      SELECT
        CODOBIECT,
        DATADOC,
        CODDOC,
        PARTENER,
        MONEDA,
        PACHIZ_RON,
        PACHIZ_VAL,
        CURS ,
        TIPLIVR,
        UMSEC,
        PREFIXDOC,
        NRDOC,
        DATANIR,
        SUBUNITATEA,
        DEN_GEST,
        OBS,
        PU,
        CURSDOC,
        MONEDATRANSF,
        PUTRANSF,
        OBSDOC,
        SUM(CANT) AS CANT
      FROM  (
        SELECT
          NS.CODOBIECT,
          ES.DATADOC,
          ES.CODIES AS CODDOC,
          ES.PARTENER,
          coalesce(ES.MONEDA ,0) MONEDA,
          (NS.PRET - NS.ADAOS) PACHIZ_RON,
          NS.PUVAL PACHIZ_VAL,
          coalesce(ES.CURS,1) CURS ,
          LIV.TIPLIVR,
          NS.UMSEC,
          ES.PREFIXDOC || ES.SERIADOC PREFIXDOC,
          ES.NRDOC,
          LIV1.CANT,
          N.DATANIR,
          coalesce(ES.SUBUNITATEA,0) SUBUNITATEA,
          G.DEN_GEST,
          ES1.OBS,
          ES1.PU,
          ES.CURSDOC,
          ES.MONEDATRANSF,
          ES1.PU / (case when coalesce(ES.CURSDOC, 1)= 0 then 1 else coalesce(ES.CURSDOC, 1) end) AS PUTRANSF,
          ES.OBS AS OBSDOC
        FROM
          MAN_IESIRI1        ES1
          inner join LIVR1   Liv1 ON Liv1.CodIes1    = ES1.CodIes1
          inner join IESIRI  ES   on  ES1.CodIes     = ES.CodIes
          inner join LIVR    LIV  on Liv1.CodLivr    = LIV.CodLivr AND LIV.TIPLIVR IN (16, 19, 20, 21, 22)
          inner join NIRSTOC NS   on Liv1.CodNirStoc = NS.CodNirStoc
          INNER JOIN NIR     N    ON NS.CODNIR       = N.CODNIR
          INNER JOIN NGEST   G    ON G.CODGEST       = N.GEST
        ORDER BY DATADOC DESC
      ) TB
      GROUP BY
        CODOBIECT,
        DATADOC,
        CODDOC,
        PARTENER,
        MONEDA,
        PACHIZ_RON,
        PACHIZ_VAL,
        CURS ,
        TIPLIVR,
        UMSEC,
        PREFIXDOC,
        NRDOC,
        DATANIR,
        SUBUNITATEA,
        DEN_GEST,
        OBS,
        PU,
        CURSDOC,
        MONEDATRANSF,
        PUTRANSF,
        OBSDOC
    ) TAB
      LEFT JOIN NPART NP           ON TAB.PARTENER         = NP.CODPART
      LEFT JOIN NMONEDE MON        ON MON.CODMONEDA        = TAB.MONEDA
      LEFT JOIN NMONEDE MON_TRANSF ON MON_TRANSF.CODMONEDA = TAB.MONEDATRANSF
      LEFT JOIN NUM1 NUM1X         ON NUM1X.CODUM1         = TAB.UMSEC
      LEFT JOIN NUM1               ON NUM1.CODUM           = NUM1X.CODUM AND NUM1.SECUNDARA=0
      LEFT JOIN NSUBUNIT S         ON S.CODSUBUNIT         = TAB.SUBUNITATEA
    ORDER BY TAB.DATADOC DESC';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>validpostlog</obj_name>
  <obj_hashval>c2fc3e97c7954ffc1d77353cba72bcb8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION validpostlog(amonitorname character varying, aoperation character varying, recid numeric, asubunitatea numeric, adatadoc date, adoc character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 23.03.2021 - PKG_USERFIRME_PostLogcucommit
  IF ( SELECT PKG_USERFIRME_ValidPostLog.WME_RESULT
      FROM PKG_USERFIRME_ValidPostLog(  NULL,
                                        TO_NUMBER(CURRENT_SETTING('PKG_GLOBALS.USERID', TRUE), '999999999999999999'),
                                        CURRENT_SETTING(aMonitorName, TRUE)))
  THEN PERFORM
    PKG_USERFIRME_PostLogcucommit(atablename,
                          CURRENT_SETTING('PKG_GLOBALS.USERNAME', TRUE),
                          aOperation,
                          RECID,
                          CURRENT_SETTING('PKG_GLOBALS.FIRMANAME', TRUE),
                          aSubunitatea,
                          aDataDoc,
                          aDoc,
                          NULL,
                          (SELECT PKG_GLOBALS_GET_EXE_VERSION.WME_RESULT FROM PKG_GLOBALS_GET_EXE_VERSION(NULL, NULL))
                         );
  END IF;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_agenda</obj_name>
  <obj_hashval>69eed59704a5ffb513812966007b4b4c</obj_hashval>
  <obj_text>SELECT codagenda,
    tip,
    codlocalit,
    sediusocial,
    telefon,
    fax,
    email,
    sector,
    strada,
    nr1,
    nr2,
    bloc,
    scara,
    etaj,
    apart,
    codpostal,
    km,
    obs,
    codbankcont,
    codpart,
    codgest,
    codsubunit,
    codtipsediu,
    codfiscal,
    codagent,
    codclient,
    codtraseu,
    poztraseu,
    inactiv,
    codcoresp,
    transpclient,
    coefutilaje,
    suprafata,
    modservire,
    idsediu,
    cod_codfiscal,
    telefonp,
    edi_exptip,
    edi_parttip,
    edi_partid,
    edi_objtip,
    gln,
    gestlivrare,
    longitudine,
    latitudine,
    obs2,
    edi_imptip,
    edi_furntip,
    edi_furnid,
    edi_objtipimp,
    ( SELECT getadresa.wme_result
           FROM martor.getadresa(NULL::character varying, a.sector, a.strada, a.nr1, a.nr2, a.bloc, a.scara, a.etaj, a.apart, a.codpostal) getadresa(wme_result, p_sector, p_strada, p_nr1, p_nr2, p_bloc, p_scara, p_etaj, p_apart, p_codpostal)) AS adresa
   FROM martor.nagenda a;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_bi_articole</obj_name>
  <obj_hashval>1175d70ffd2c725a5dc86545f5dbe9e5</obj_hashval>
  <obj_text>SELECT o.codobiect::character varying AS codobiect,
    o.codintern,
    o.codextern,
    o.denumire AS articol,
    a.tiparticol,
    ca.den_clasea AS denclasaart,
    ca.simbol AS simbclasaart,
    u.den_um AS um,
    u1.den_um AS um1,
    u2.den_um AS um2,
    CURRENT_DATE AS datasystem
   FROM martor.nartobj o
     LEFT JOIN martor.nart a ON a.codarticol = o.codarticol
     LEFT JOIN martor.num u ON u.codum = a.um
     LEFT JOIN martor.num u1 ON u1.codum = a.um1
     LEFT JOIN martor.num u2 ON u2.codum = a.um2
     LEFT JOIN martor.nclasea ca ON ca.codclasea = a.clasa;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_bi_claseax</obj_name>
  <obj_hashval>e6323cbd8af1bdd9b615b09c14e0a8b8</obj_hashval>
  <obj_text>WITH RECURSIVE x_bi_clasea(codclasea, nivel, codident, niv1, niv2, niv3, niv4, niv5, den1, den2, den3, den4, den5) AS (
         SELECT nclasea.codclasea,
            1 AS nivel,
            nclasea.codident,
            nclasea.simbol AS niv1,
            NULL::character varying AS niv2,
            NULL::character varying AS niv3,
            NULL::character varying AS niv4,
            NULL::character varying AS niv5,
            nclasea.den_clasea AS den1,
            NULL::character varying AS den2,
            NULL::character varying AS den3,
            NULL::character varying AS den4,
            NULL::character varying AS den5
           FROM martor.nclasea
          WHERE COALESCE(nclasea.codparinte, 0::numeric) = 0::numeric AND nclasea.codclasea &gt; 0::numeric
        UNION ALL
         SELECT cls.codclasea,
            pc.nivel + 1 AS nivel,
            cls.codident,
            pc.niv1,
                CASE
                    WHEN pc.nivel = 1 THEN cls.simbol
                    ELSE pc.niv2
                END AS niv2,
                CASE
                    WHEN pc.nivel = 2 THEN cls.simbol
                    ELSE pc.niv3
                END AS niv3,
                CASE
                    WHEN pc.nivel = 3 THEN cls.simbol
                    ELSE pc.niv4
                END AS niv4,
                CASE
                    WHEN pc.nivel = 4 THEN cls.simbol
                    ELSE pc.niv5
                END AS niv5,
            pc.den1,
                CASE
                    WHEN pc.nivel = 1 THEN cls.den_clasea
                    ELSE pc.den2
                END AS den2,
                CASE
                    WHEN pc.nivel = 2 THEN cls.den_clasea
                    ELSE pc.den3
                END AS den3,
                CASE
                    WHEN pc.nivel = 3 THEN cls.den_clasea
                    ELSE pc.den4
                END AS den4,
                CASE
                    WHEN pc.nivel = 4 THEN cls.den_clasea
                    ELSE pc.den5
                END AS den5
           FROM x_bi_clasea pc
             JOIN martor.nclasea cls ON cls.codparinte = pc.codclasea
        )
 SELECT codclasea,
    nivel,
    codident,
    niv1,
    niv2,
    niv3,
    niv4,
    niv5,
    den1,
    den2,
    den3,
    den4,
    den5
   FROM x_bi_clasea
  ORDER BY codident;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_bi_clasepx</obj_name>
  <obj_hashval>b77cf67c40851a8de0595d37f3cf9093</obj_hashval>
  <obj_text>WITH RECURSIVE x_bi_clasep(codclasep, nivel, codident, niv1, niv2, niv3, niv4, niv5, den1, den2, den3, den4, den5) AS (
         SELECT nclasep.codclasep,
            1 AS nivel,
            nclasep.codident,
            nclasep.simbol AS niv1,
            NULL::character varying AS niv2,
            NULL::character varying AS niv3,
            NULL::character varying AS niv4,
            NULL::character varying AS niv5,
            nclasep.den_clasep AS den1,
            NULL::character varying AS den2,
            NULL::character varying AS den3,
            NULL::character varying AS den4,
            NULL::character varying AS den5
           FROM martor.nclasep
          WHERE COALESCE(nclasep.codparinte, 0::numeric) = 0::numeric AND nclasep.codclasep &gt; 0::numeric
        UNION ALL
         SELECT cls.codclasep,
            pc.nivel + 1 AS nivel,
            cls.codident,
            pc.niv1,
                CASE
                    WHEN pc.nivel = 1 THEN cls.simbol
                    ELSE pc.niv2
                END AS niv2,
                CASE
                    WHEN pc.nivel = 2 THEN cls.simbol
                    ELSE pc.niv3
                END AS niv3,
                CASE
                    WHEN pc.nivel = 3 THEN cls.simbol
                    ELSE pc.niv4
                END AS niv4,
                CASE
                    WHEN pc.nivel = 4 THEN cls.simbol
                    ELSE pc.niv5
                END AS niv5,
            pc.den1,
                CASE
                    WHEN pc.nivel = 1 THEN cls.den_clasep
                    ELSE pc.den2
                END AS den2,
                CASE
                    WHEN pc.nivel = 2 THEN cls.den_clasep
                    ELSE pc.den3
                END AS den3,
                CASE
                    WHEN pc.nivel = 3 THEN cls.den_clasep
                    ELSE pc.den4
                END AS den4,
                CASE
                    WHEN pc.nivel = 4 THEN cls.den_clasep
                    ELSE pc.den5
                END AS den5
           FROM x_bi_clasep pc
             JOIN martor.nclasep cls ON cls.codparinte = pc.codclasep
        )
 SELECT codclasep,
    nivel,
    codident,
    niv1,
    niv2,
    niv3,
    niv4,
    niv5,
    den1,
    den2,
    den3,
    den4,
    den5
   FROM x_bi_clasep
  ORDER BY codident;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_bi_j_chelt_etx1</obj_name>
  <obj_hashval>62177b7497414a55e000c7a47950880a</obj_hashval>
  <obj_text>SELECT i1.codobiect,
    o.denumire,
    cls.den_clasea AS clasa,
    0 AS codcmdint1,
    NULL::text AS nr_cmdint,
    NULL::text AS data_cmdint,
    0 AS cantcomandat,
    i1.codcmdint1 AS ccomandi1,
    cd.simbol AS simbol_debit,
    cc.simbol AS simbol_credit,
    j1.codjurnal1,
    j1.coddoc,
    j1.tipdoc,
    j1.indexlocal,
    j1.codbazad,
    j1.tipbazad,
    j1.icontbazad,
    j1.coddescrd,
    j1.icontd,
    j1.tipcontd,
    j1.analiticcontd,
    j1.codbazac,
    j1.tipbazac,
    j1.icontbazac,
    j1.coddescrc,
    j1.icontc,
    j1.tipcontc,
    j1.analiticcontc,
    j1.gest,
    j1.valoare,
    j1.valoarev,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoare
            ELSE j1.valoare
        END AS val_cont,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoarev
            ELSE j1.valoarev
        END AS valv_cont,
    j1.obs,
    j1.an,
    j1.luna,
    j1.dirty,
    j1.subunitatea,
    j1.an * 100::numeric + j1.luna AS anluna,
    j1.datadoc,
    j1.document,
    j1.codcentru,
    j1.valoaregrup,
    j1.codanalizanod,
    j1.valoare_ifrs,
    j1.valoarev_ifrs,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoare_ifrs
            ELSE j1.valoare_ifrs
        END AS val_ifrs_cont,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoarev_ifrs
            ELSE j1.valoarev_ifrs
        END AS valv_ifrs_cont
   FROM martor.jurnal1 j1
     JOIN martor.ncont cd ON cd.codcont = (( SELECT pkg_jurnal_getcontforjurnal.wme_result
           FROM martor.pkg_jurnal_getcontforjurnal(NULL::numeric, j1.coddescrd, j1.icontd, j1.tipcontd, j1.analiticcontd, j1.an, j1.luna) pkg_jurnal_getcontforjurnal(wme_result, coddescriere, icont, tipcont, analiticcont, aan, aluna)))
     JOIN martor.ncont cc ON cc.codcont = (( SELECT pkg_jurnal_getcontforjurnal.wme_result
           FROM martor.pkg_jurnal_getcontforjurnal(NULL::numeric, j1.coddescrc, j1.icontc, j1.tipcontc, j1.analiticcontc, j1.an, j1.luna) pkg_jurnal_getcontforjurnal(wme_result, coddescriere, icont, tipcont, analiticcont, aan, aluna)))
     JOIN martor.intrari1 i1 ON i1.codintr1 = j1.indexlocal
     JOIN martor.intrari i ON i.codintr = i1.codintr AND j1.coddoc = i.codintr AND j1.tipdoc = i.tipdoc
     LEFT JOIN martor.nartobj o ON o.codobiect = i1.codobiect
     LEFT JOIN martor.nart a ON a.codarticol = o.codarticol
     LEFT JOIN martor.nclasea cls ON cls.codclasea = a.clasa
  WHERE j1.an &gt; 2017::numeric AND i1.codobiect &gt; 0::numeric AND (cd.simbol::text &lt;&gt; ALL (ARRAY['601'::character varying::text, '607'::character varying::text, '665'::character varying::text, '681.01'::character varying::text, '681.02'::character varying::text, '681.03'::character varying::text, '681.04'::character varying::text, '691'::character varying::text])) AND (cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text) AND COALESCE(i1.codcmdint1, 0::numeric) = 0::numeric
UNION ALL
 SELECT dvi1.codobiect,
    o.denumire,
    cls.den_clasea AS clasa,
    0 AS codcmdint1,
    NULL::text AS nr_cmdint,
    NULL::text AS data_cmdint,
    0 AS cantcomandat,
    i1.codcmdint1 AS ccomandi1,
    cd.simbol AS simbol_debit,
    cc.simbol AS simbol_credit,
    j1.codjurnal1,
    j1.coddoc,
    j1.tipdoc,
    j1.indexlocal,
    j1.codbazad,
    j1.tipbazad,
    j1.icontbazad,
    j1.coddescrd,
    j1.icontd,
    j1.tipcontd,
    j1.analiticcontd,
    j1.codbazac,
    j1.tipbazac,
    j1.icontbazac,
    j1.coddescrc,
    j1.icontc,
    j1.tipcontc,
    j1.analiticcontc,
    j1.gest,
    j1.valoare,
    j1.valoarev,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoare
            ELSE j1.valoare
        END AS val_cont,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoarev
            ELSE j1.valoarev
        END AS valv_cont,
    j1.obs,
    j1.an,
    j1.luna,
    j1.dirty,
    j1.subunitatea,
    j1.an * 100::numeric + j1.luna AS anluna,
    j1.datadoc,
    j1.document,
    j1.codcentru,
    j1.valoaregrup,
    j1.codanalizanod,
    j1.valoare_ifrs,
    j1.valoarev_ifrs,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoare_ifrs
            ELSE j1.valoare_ifrs
        END AS val_ifrs_cont,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoarev_ifrs
            ELSE j1.valoarev_ifrs
        END AS valv_ifrs_cont
   FROM martor.jurnal1 j1
     JOIN martor.ncont cd ON cd.codcont = (( SELECT pkg_jurnal_getcontforjurnal.wme_result
           FROM martor.pkg_jurnal_getcontforjurnal(NULL::numeric, j1.coddescrd, j1.icontd, j1.tipcontd, j1.analiticcontd, j1.an, j1.luna) pkg_jurnal_getcontforjurnal(wme_result, coddescriere, icont, tipcont, analiticcont, aan, aluna)))
     JOIN martor.ncont cc ON cc.codcont = (( SELECT pkg_jurnal_getcontforjurnal.wme_result
           FROM martor.pkg_jurnal_getcontforjurnal(NULL::numeric, j1.coddescrc, j1.icontc, j1.tipcontc, j1.analiticcontc, j1.an, j1.luna) pkg_jurnal_getcontforjurnal(wme_result, coddescriere, icont, tipcont, analiticcont, aan, aluna)))
     JOIN martor.dvi1 ON dvi1.coddvi1 = j1.indexlocal
     JOIN martor.intrari1 i1 ON dvi1.codintr1 = i1.codintr1
     JOIN martor.dvi ON dvi.coddvi = dvi1.coddvi
     JOIN martor.intrari i ON i.codintr = i1.codintr AND i.codintr = dvi.codintr AND i.codintr = j1.coddoc AND i.tipdoc = j1.tipdoc
     JOIN martor.nartobj o ON o.codobiect = dvi1.codobiect
     JOIN martor.nart a ON a.codarticol = o.codarticol
     LEFT JOIN martor.nclasea cls ON cls.codclasea = a.clasa
  WHERE j1.an &gt; 2017::numeric AND dvi1.codobiect &gt; 0::numeric AND (cd.simbol::text &lt;&gt; ALL (ARRAY['601'::character varying::text, '607'::character varying::text, '665'::character varying::text, '681.01'::character varying::text, '681.02'::character varying::text, '681.03'::character varying::text, '681.04'::character varying::text, '691'::character varying::text])) AND (cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text) AND COALESCE(i1.codcmdint1, 0::numeric) = 0::numeric
UNION ALL
 SELECT t1.codobiect,
    o.denumire,
    cls.den_clasea AS clasa,
    0 AS codcmdint1,
    NULL::text AS nr_cmdint,
    NULL::text AS data_cmdint,
    0 AS cantcomandat,
    0 AS ccomandi1,
    cd.simbol AS simbol_debit,
    cc.simbol AS simbol_credit,
    j1.codjurnal1,
    j1.coddoc,
    j1.tipdoc,
    j1.indexlocal,
    j1.codbazad,
    j1.tipbazad,
    j1.icontbazad,
    j1.coddescrd,
    j1.icontd,
    j1.tipcontd,
    j1.analiticcontd,
    j1.codbazac,
    j1.tipbazac,
    j1.icontbazac,
    j1.coddescrc,
    j1.icontc,
    j1.tipcontc,
    j1.analiticcontc,
    j1.gest,
    j1.valoare,
    j1.valoarev,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoare
            ELSE j1.valoare
        END AS val_cont,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoarev
            ELSE j1.valoarev
        END AS valv_cont,
    j1.obs,
    j1.an,
    j1.luna,
    j1.dirty,
    j1.subunitatea,
    j1.an * 100::numeric + j1.luna AS anluna,
    j1.datadoc,
    j1.document,
    j1.codcentru,
    j1.valoaregrup,
    j1.codanalizanod,
    j1.valoare_ifrs,
    j1.valoarev_ifrs,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoare_ifrs
            ELSE j1.valoare_ifrs
        END AS val_ifrs_cont,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoarev_ifrs
            ELSE j1.valoarev_ifrs
        END AS valv_ifrs_cont
   FROM martor.jurnal1 j1
     JOIN martor.ncont cd ON cd.codcont = (( SELECT pkg_jurnal_getcontforjurnal.wme_result
           FROM martor.pkg_jurnal_getcontforjurnal(NULL::numeric, j1.coddescrd, j1.icontd, j1.tipcontd, j1.analiticcontd, j1.an, j1.luna) pkg_jurnal_getcontforjurnal(wme_result, coddescriere, icont, tipcont, analiticcont, aan, aluna)))
     JOIN martor.ncont cc ON cc.codcont = (( SELECT pkg_jurnal_getcontforjurnal.wme_result
           FROM martor.pkg_jurnal_getcontforjurnal(NULL::numeric, j1.coddescrc, j1.icontc, j1.tipcontc, j1.analiticcontc, j1.an, j1.luna) pkg_jurnal_getcontforjurnal(wme_result, coddescriere, icont, tipcont, analiticcont, aan, aluna)))
     JOIN martor.transf1 t1 ON t1.codtransf1 = j1.indexlocal
     JOIN martor.transf t ON t.codtransf = t1.codtransf AND j1.tipdoc = t.tipdoc AND t.codtransf = j1.coddoc
     JOIN martor.nartobj o ON o.codobiect = t1.codobiect
     JOIN martor.nart a ON a.codarticol = o.codarticol
     LEFT JOIN martor.nclasea cls ON cls.codclasea = a.clasa
  WHERE j1.an &gt; 2017::numeric AND t1.codobiect &gt; 0::numeric AND (cd.simbol::text &lt;&gt; ALL (ARRAY['601'::character varying::text, '607'::character varying::text, '665'::character varying::text, '681.01'::character varying::text, '681.02'::character varying::text, '681.03'::character varying::text, '681.04'::character varying::text, '691'::character varying::text])) AND (cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text)
UNION ALL
 SELECT ies1.codobiect,
    o.denumire,
    cls.den_clasea AS clasa,
    ies1.codcmdint1,
    NULL::text AS nr_cmdint,
    NULL::text AS data_cmdint,
    0 AS cantcomandat,
    0 AS ccomandi1,
    cd.simbol AS simbol_debit,
    cc.simbol AS simbol_credit,
    j1.codjurnal1,
    j1.coddoc,
    j1.tipdoc,
    j1.indexlocal,
    j1.codbazad,
    j1.tipbazad,
    j1.icontbazad,
    j1.coddescrd,
    j1.icontd,
    j1.tipcontd,
    j1.analiticcontd,
    j1.codbazac,
    j1.tipbazac,
    j1.icontbazac,
    j1.coddescrc,
    j1.icontc,
    j1.tipcontc,
    j1.analiticcontc,
    j1.gest,
    j1.valoare,
    j1.valoarev,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoare
            ELSE j1.valoare
        END AS val_cont,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoarev
            ELSE j1.valoarev
        END AS valv_cont,
    j1.obs,
    j1.an,
    j1.luna,
    j1.dirty,
    j1.subunitatea,
    j1.an * 100::numeric + j1.luna AS anluna,
    j1.datadoc,
    j1.document,
    j1.codcentru,
    j1.valoaregrup,
    j1.codanalizanod,
    j1.valoare_ifrs,
    j1.valoarev_ifrs,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoare_ifrs
            ELSE j1.valoare_ifrs
        END AS val_ifrs_cont,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoarev_ifrs
            ELSE j1.valoarev_ifrs
        END AS valv_ifrs_cont
   FROM martor.jurnal1 j1
     JOIN martor.ncont cd ON cd.codcont = (( SELECT pkg_jurnal_getcontforjurnal.wme_result
           FROM martor.pkg_jurnal_getcontforjurnal(NULL::numeric, j1.coddescrd, j1.icontd, j1.tipcontd, j1.analiticcontd, j1.an, j1.luna) pkg_jurnal_getcontforjurnal(wme_result, coddescriere, icont, tipcont, analiticcont, aan, aluna)))
     JOIN martor.ncont cc ON cc.codcont = (( SELECT pkg_jurnal_getcontforjurnal.wme_result
           FROM martor.pkg_jurnal_getcontforjurnal(NULL::numeric, j1.coddescrc, j1.icontc, j1.tipcontc, j1.analiticcontc, j1.an, j1.luna) pkg_jurnal_getcontforjurnal(wme_result, coddescriere, icont, tipcont, analiticcont, aan, aluna)))
     JOIN martor.iesiri1 ies1 ON ies1.codies1 = j1.indexlocal
     JOIN martor.iesiri ies ON ies.codies = ies1.codies AND j1.tipdoc = ies.tipdoc AND j1.coddoc = ies.codies
     JOIN martor.nartobj o ON o.codobiect = ies1.codobiect
     LEFT JOIN martor.nart a ON a.codarticol = o.codarticol
     LEFT JOIN martor.nclasea cls ON cls.codclasea = a.clasa
  WHERE j1.an &gt; 2017::numeric AND ies1.codobiect &gt; 0::numeric AND (cd.simbol::text &lt;&gt; ALL (ARRAY['601'::character varying::text, '607'::character varying::text, '665'::character varying::text, '681.01'::character varying::text, '681.02'::character varying::text, '681.03'::character varying::text, '681.04'::character varying::text, '691'::character varying::text])) AND (cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text) AND COALESCE(ies1.codcmdint1, 0::numeric) = 0::numeric
UNION ALL
 SELECT 0 AS codobiect,
    '...nedefinit...'::character varying AS denumire,
    '...nedefinit...'::character varying AS clasa,
    0 AS codcmdint1,
    NULL::text AS nr_cmdint,
    NULL::text AS data_cmdint,
    0 AS cantcomandat,
    0 AS ccomandi1,
    cd.simbol AS simbol_debit,
    cc.simbol AS simbol_credit,
    j1.codjurnal1,
    j1.coddoc,
    j1.tipdoc,
    j1.indexlocal,
    j1.codbazad,
    j1.tipbazad,
    j1.icontbazad,
    j1.coddescrd,
    j1.icontd,
    j1.tipcontd,
    j1.analiticcontd,
    j1.codbazac,
    j1.tipbazac,
    j1.icontbazac,
    j1.coddescrc,
    j1.icontc,
    j1.tipcontc,
    j1.analiticcontc,
    j1.gest,
    j1.valoare,
    j1.valoarev,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoare
            ELSE j1.valoare
        END AS val_cont,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoarev
            ELSE j1.valoarev
        END AS valv_cont,
    j1.obs,
    j1.an,
    j1.luna,
    j1.dirty,
    j1.subunitatea,
    j1.an * 100::numeric + j1.luna AS anluna,
    j1.datadoc,
    j1.document,
    j1.codcentru,
    j1.valoaregrup,
    j1.codanalizanod,
    j1.valoare_ifrs,
    j1.valoarev_ifrs,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoare_ifrs
            ELSE j1.valoare_ifrs
        END AS val_ifrs_cont,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoarev_ifrs
            ELSE j1.valoarev_ifrs
        END AS valv_ifrs_cont
   FROM martor.jurnal1 j1
     JOIN martor.ncont cd ON cd.codcont = (( SELECT pkg_jurnal_getcontforjurnal.wme_result
           FROM martor.pkg_jurnal_getcontforjurnal(NULL::numeric, j1.coddescrd, j1.icontd, j1.tipcontd, j1.analiticcontd, j1.an, j1.luna) pkg_jurnal_getcontforjurnal(wme_result, coddescriere, icont, tipcont, analiticcont, aan, aluna)))
     JOIN martor.ncont cc ON cc.codcont = (( SELECT pkg_jurnal_getcontforjurnal.wme_result
           FROM martor.pkg_jurnal_getcontforjurnal(NULL::numeric, j1.coddescrc, j1.icontc, j1.tipcontc, j1.analiticcontc, j1.an, j1.luna) pkg_jurnal_getcontforjurnal(wme_result, coddescriere, icont, tipcont, analiticcont, aan, aluna)))
     JOIN martor.trezor1 t1 ON t1.codtrezor1 = j1.indexlocal
     JOIN martor.trezor t ON t.codtrezor = j1.coddoc AND t.codtrezor = t1.codtrezor AND t.tipdoc = j1.tipdoc
  WHERE j1.an &gt; 2017::numeric AND (cd.simbol::text &lt;&gt; ALL (ARRAY['601'::character varying::text, '607'::character varying::text, '665'::character varying::text, '681.01'::character varying::text, '681.02'::character varying::text, '681.03'::character varying::text, '681.04'::character varying::text, '691'::character varying::text])) AND (cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text)
UNION ALL
 SELECT 0 AS codobiect,
    '...nedefinit...'::character varying AS denumire,
    '...nedefinit...'::character varying AS clasa,
    0 AS codcmdint1,
    NULL::text AS nr_cmdint,
    NULL::text AS data_cmdint,
    0 AS cantcomandat,
    0 AS ccomandi1,
    cd.simbol AS simbol_debit,
    cc.simbol AS simbol_credit,
    j1.codjurnal1,
    j1.coddoc,
    j1.tipdoc,
    j1.indexlocal,
    j1.codbazad,
    j1.tipbazad,
    j1.icontbazad,
    j1.coddescrd,
    j1.icontd,
    j1.tipcontd,
    j1.analiticcontd,
    j1.codbazac,
    j1.tipbazac,
    j1.icontbazac,
    j1.coddescrc,
    j1.icontc,
    j1.tipcontc,
    j1.analiticcontc,
    j1.gest,
    j1.valoare,
    j1.valoarev,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoare
            ELSE j1.valoare
        END AS val_cont,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoarev
            ELSE j1.valoarev
        END AS valv_cont,
    j1.obs,
    j1.an,
    j1.luna,
    j1.dirty,
    j1.subunitatea,
    j1.an * 100::numeric + j1.luna AS anluna,
    j1.datadoc,
    j1.document,
    j1.codcentru,
    j1.valoaregrup,
    j1.codanalizanod,
    j1.valoare_ifrs,
    j1.valoarev_ifrs,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoare_ifrs
            ELSE j1.valoare_ifrs
        END AS val_ifrs_cont,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoarev_ifrs
            ELSE j1.valoarev_ifrs
        END AS valv_ifrs_cont
   FROM martor.jurnal1 j1
     JOIN martor.ncont cd ON cd.codcont = (( SELECT pkg_jurnal_getcontforjurnal.wme_result
           FROM martor.pkg_jurnal_getcontforjurnal(NULL::numeric, j1.coddescrd, j1.icontd, j1.tipcontd, j1.analiticcontd, j1.an, j1.luna) pkg_jurnal_getcontforjurnal(wme_result, coddescriere, icont, tipcont, analiticcont, aan, aluna)))
     JOIN martor.ncont cc ON cc.codcont = (( SELECT pkg_jurnal_getcontforjurnal.wme_result
           FROM martor.pkg_jurnal_getcontforjurnal(NULL::numeric, j1.coddescrc, j1.icontc, j1.tipcontc, j1.analiticcontc, j1.an, j1.luna) pkg_jurnal_getcontforjurnal(wme_result, coddescriere, icont, tipcont, analiticcont, aan, aluna)))
     JOIN martor.nc1 ON nc1.codnc1 = j1.indexlocal
     JOIN martor.nc ON nc.codnc = j1.coddoc AND j1.tipdoc = 35::numeric AND nc.codnc = nc1.codnc
  WHERE j1.an &gt; 2017::numeric AND (cd.simbol::text &lt;&gt; ALL (ARRAY['601'::character varying::text, '607'::character varying::text, '665'::character varying::text, '681.01'::character varying::text, '681.02'::character varying::text, '681.03'::character varying::text, '681.04'::character varying::text, '691'::character varying::text])) AND (cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text)
UNION ALL
 SELECT 0 AS codobiect,
    '...nedefinit...'::character varying AS denumire,
    '...nedefinit...'::character varying AS clasa,
    0 AS codcmdint1,
    NULL::text AS nr_cmdint,
    NULL::text AS data_cmdint,
    0 AS cantcomandat,
    0 AS ccomandi1,
    cd.simbol AS simbol_debit,
    cc.simbol AS simbol_credit,
    j1.codjurnal1,
    j1.coddoc,
    j1.tipdoc,
    j1.indexlocal,
    j1.codbazad,
    j1.tipbazad,
    j1.icontbazad,
    j1.coddescrd,
    j1.icontd,
    j1.tipcontd,
    j1.analiticcontd,
    j1.codbazac,
    j1.tipbazac,
    j1.icontbazac,
    j1.coddescrc,
    j1.icontc,
    j1.tipcontc,
    j1.analiticcontc,
    j1.gest,
    j1.valoare,
    j1.valoarev,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoare
            ELSE j1.valoare
        END AS val_cont,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoarev
            ELSE j1.valoarev
        END AS valv_cont,
    j1.obs,
    j1.an,
    j1.luna,
    j1.dirty,
    j1.subunitatea,
    j1.an * 100::numeric + j1.luna AS anluna,
    j1.datadoc,
    j1.document,
    j1.codcentru,
    j1.valoaregrup,
    j1.codanalizanod,
    j1.valoare_ifrs,
    j1.valoarev_ifrs,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoare_ifrs
            ELSE j1.valoare_ifrs
        END AS val_ifrs_cont,
        CASE
            WHEN cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text THEN - j1.valoarev_ifrs
            ELSE j1.valoarev_ifrs
        END AS valv_ifrs_cont
   FROM martor.jurnal1 j1
     JOIN martor.ncont cd ON cd.codcont = (( SELECT pkg_jurnal_getcontforjurnal.wme_result
           FROM martor.pkg_jurnal_getcontforjurnal(NULL::numeric, j1.coddescrd, j1.icontd, j1.tipcontd, j1.analiticcontd, j1.an, j1.luna) pkg_jurnal_getcontforjurnal(wme_result, coddescriere, icont, tipcont, analiticcont, aan, aluna)))
     JOIN martor.ncont cc ON cc.codcont = (( SELECT pkg_jurnal_getcontforjurnal.wme_result
           FROM martor.pkg_jurnal_getcontforjurnal(NULL::numeric, j1.coddescrc, j1.icontc, j1.tipcontc, j1.analiticcontc, j1.an, j1.luna) pkg_jurnal_getcontforjurnal(wme_result, coddescriere, icont, tipcont, analiticcont, aan, aluna)))
     JOIN martor.cheltavans ca ON ca.codcheltavans = j1.coddoc AND j1.tipdoc = 52::numeric
  WHERE j1.an &gt; 2017::numeric AND (cd.simbol::text &lt;&gt; ALL (ARRAY['601'::character varying::text, '607'::character varying::text, '665'::character varying::text, '681.01'::character varying::text, '681.02'::character varying::text, '681.03'::character varying::text, '681.04'::character varying::text, '691'::character varying::text])) AND (cd.simbol::text ~~ '6%'::text OR cd.simbol::text ~~ '709'::text);</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_bi_jurnal_1</obj_name>
  <obj_hashval>cbc5c9b0d29ff8cba7dfa024098e4c03</obj_hashval>
  <obj_text>SELECT
        CASE
            WHEN j.tipdoc = ANY (ARRAY[32::numeric, 36::numeric]) THEN NULL::numeric
            ELSE j.tipdoc
        END AS tipdoc,
        CASE
            WHEN j.tipdoc = ANY (ARRAY[32::numeric, 36::numeric]) THEN NULL::numeric
            ELSE j.coddoc
        END AS coddoc,
    j.indexlocal AS indexdoc,
    j.codjurnal AS "COD INREGISTRARE",
    NULL::numeric AS "NOTA COD",
    NULL::character varying AS "NOTA DESCRIERE",
    NULL::numeric AS "JURNAL COD",
    NULL::character varying AS "JURNAL DESCRIERE",
    j.datadoc AS data,
    cd.simbol AS "CONT DEBIT SIMBOL",
    cd.den_cont AS "CONT DEBIT DESCRIERE",
    cc.simbol AS "CONT CREDIT SIMBOL",
    cc.den_cont AS "CONT CREDIT DESCRIERE",
    j.valoare,
    j.valoarev,
    g.den_gest AS gestiune,
    j.obs AS observatii,
    j.an * 10::numeric + j.luna AS anlunalucru,
    j.document,
    csd.simbol AS simbolcontsecundardebit,
    csd.den_cont AS denumirecontsecundardebit,
    csc.simbol AS simbolcontsecundarcredit,
    csc.den_cont AS denumirecontsecundarcredit,
    s.den_subunit AS subunitatea
   FROM martor.jurnal j
     JOIN martor.ncont cd ON cd.codcont = j.contd
     JOIN martor.ncont cc ON cc.codcont = j.contc
     JOIN martor.ncont1 cd1 ON cd1.codcont = cd.codcont
     JOIN martor.ncont1 cc1 ON cc1.codcont = cc.codcont
     LEFT JOIN martor.nconts csd ON csd.codconts = cd1.contsecundar
     LEFT JOIN martor.nconts csc ON csc.codconts = cc1.contsecundar
     LEFT JOIN martor.ngest g ON g.codgest = j.gest
     LEFT JOIN martor.nsubunit s ON s.codsubunit = g.codsubunit
  WHERE (cd1.anstart * 12::numeric + cd1.lunastart) = (( SELECT max(cd2.anstart * 12::numeric + cd2.lunastart) AS max
           FROM martor.ncont1 cd2
          WHERE cd2.codcont = cd1.codcont AND (cd2.anstart * 12::numeric + cd2.lunastart) &lt;= (j.an * 12::numeric + j.luna))) AND (cc1.anstart * 12::numeric + cc1.lunastart) = (( SELECT max(cc2.anstart * 12::numeric + cc2.lunastart) AS max
           FROM martor.ncont1 cc2
          WHERE cc2.codcont = cc1.codcont AND (cc2.anstart * 12::numeric + cc2.lunastart) &lt;= (j.an * 12::numeric + j.luna)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_bi_jurnal_2</obj_name>
  <obj_hashval>78778049a84d2cd257cc602cc4310412</obj_hashval>
  <obj_text>SELECT row_number() OVER (ORDER BY j.codjurnal) AS rec_id,
    'DEBITARE'::text AS operatie,
    c.codcont AS "cod intern",
    c.codparinte AS "cod parinte",
        CASE
            WHEN j.tipdoc = ANY (ARRAY[32::numeric, 36::numeric]) THEN NULL::numeric
            ELSE j.tipdoc
        END AS tipdoc,
        CASE
            WHEN j.tipdoc = ANY (ARRAY[32::numeric, 36::numeric]) THEN NULL::numeric
            ELSE j.coddoc
        END AS coddoc,
    j.indexlocal AS indexdoc,
        CASE c.tipcont
            WHEN 0 THEN 'Debitor'::text
            WHEN 1 THEN 'Creditor'::text
            ELSE 'Debitor/Creditor'::text
        END AS "tip cont",
    j.codjurnal AS "cod inregistrare",
    NULL::numeric AS "nota cod",
    NULL::character varying AS "nota descriere",
    NULL::numeric AS "jurnal cod",
    NULL::character varying AS "jurnal descriere",
    j.datadoc AS data,
    c.simbol AS "cont simbol",
    c.den_cont AS "cont descriere",
    j.valoare,
    j.valoarev,
    g.den_gest AS gestiune,
    j.obs AS observatii,
    j.document,
    j.an * 10::numeric + j.luna AS anlunalucru,
        CASE
            WHEN c.vizibilbalanta = 1::numeric THEN 'DA'::text
            ELSE 'NU'::text
        END AS "vizibil balanta",
        CASE
            WHEN c.balantasintetica = 1::numeric THEN 'DA'::text
            ELSE 'NU'::text
        END AS "balanta sintetica"
   FROM martor.jurnal j
     LEFT JOIN martor.ncont c ON c.codcont = j.contd
     LEFT JOIN martor.ngest g ON g.codgest = j.gest
UNION ALL
 SELECT row_number() OVER (ORDER BY j.codjurnal) AS rec_id,
    'CREDITARE'::text AS operatie,
    c.codcont AS "cod intern",
    c.codparinte AS "cod parinte",
        CASE
            WHEN j.tipdoc = ANY (ARRAY[32::numeric, 36::numeric]) THEN NULL::numeric
            ELSE j.tipdoc
        END AS tipdoc,
        CASE
            WHEN j.tipdoc = ANY (ARRAY[32::numeric, 36::numeric]) THEN NULL::numeric
            ELSE j.coddoc
        END AS coddoc,
    j.indexlocal AS indexdoc,
        CASE c.tipcont
            WHEN 0 THEN 'Debitor'::text
            WHEN 1 THEN 'Creditor'::text
            ELSE 'Debitor/Creditor'::text
        END AS "tip cont",
    j.codjurnal AS "cod inregistrare",
    NULL::numeric AS "nota cod",
    NULL::character varying AS "nota descriere",
    NULL::numeric AS "jurnal cod",
    NULL::character varying AS "jurnal descriere",
    j.datadoc AS data,
    c.simbol AS "cont simbol",
    c.den_cont AS "cont descriere",
    j.valoare,
    j.valoarev,
    g.den_gest AS gestiune,
    j.obs AS observatii,
    j.document,
    j.an * 10::numeric + j.luna AS anlunalucru,
        CASE
            WHEN c.vizibilbalanta = 1::numeric THEN 'DA'::text
            ELSE 'NU'::text
        END AS "vizibil balanta",
        CASE
            WHEN c.balantasintetica = 1::numeric THEN 'DA'::text
            ELSE 'NU'::text
        END AS "balanta sintetica"
   FROM martor.jurnal j
     LEFT JOIN martor.ncont c ON c.codcont = j.contc
     LEFT JOIN martor.ngest g ON g.codgest = j.gest
UNION ALL
 SELECT tmp.nr + row_number() OVER (ORDER BY cr.codcontrul) AS rec_id,
    'SOLD DEBITOR'::text AS operatie,
    c.codcont AS "cod intern",
    c.codparinte AS "cod parinte",
    NULL::numeric AS tipdoc,
    NULL::numeric AS coddoc,
    NULL::numeric AS indexdoc,
        CASE c.tipcont
            WHEN 0 THEN 'Debitor'::text
            WHEN 1 THEN 'Creditor'::text
            ELSE 'Debitor/Creditor'::text
        END AS "tip cont",
    NULL::numeric AS "cod inregistrare",
    NULL::numeric AS "nota cod",
    NULL::character varying AS "nota descriere",
    NULL::numeric AS "jurnal cod",
    NULL::character varying AS "jurnal descriere",
    to_date(to_char(cr.an, 'fm0000'::text) || to_char(cr.luna, 'fm00'::text), 'yyyymm'::text) AS data,
    c.simbol AS "cont simbol",
    c.den_cont AS "cont descriere",
        CASE
            WHEN c.clasa = ANY (ARRAY[6::numeric, 7::numeric]) THEN 0::numeric
            ELSE COALESCE(cs.soldid, 0::numeric) + COALESCE(cr.rulajpd, 0::numeric)
        END AS valoare,
        CASE
            WHEN c.clasa = ANY (ARRAY[6::numeric, 7::numeric]) THEN 0::numeric
            ELSE COALESCE(cs.soldvid, 0::numeric) + COALESCE(cr.rulajvpd, 0::numeric)
        END AS valoarev,
    NULL::character varying AS gestiune,
    NULL::character varying AS observatii,
    NULL::character varying AS document,
    cr.an * 10::numeric + cr.luna AS anlunalucru,
        CASE
            WHEN c.vizibilbalanta = 1::numeric THEN 'DA'::text
            ELSE 'NU'::text
        END AS "vizibil balanta",
        CASE
            WHEN c.balantasintetica = 1::numeric THEN 'DA'::text
            ELSE 'NU'::text
        END AS "balanta sintetica"
   FROM martor.ncontrul cr
     JOIN martor.ncontsold cs ON cs.codcont = cr.codcont AND cs.an = cr.an
     JOIN martor.ncont c ON c.codcont = cr.codcont
     CROSS JOIN ( SELECT count(1) AS nr
           FROM martor.jurnal) tmp
UNION ALL
 SELECT tmp.nr + row_number() OVER (ORDER BY cr.codcontrul) AS rec_id,
    'SOLD CREDITOR'::text AS operatie,
    c.codcont AS "cod intern",
    c.codparinte AS "cod parinte",
    NULL::numeric AS tipdoc,
    NULL::numeric AS coddoc,
    NULL::numeric AS indexdoc,
        CASE c.tipcont
            WHEN 0 THEN 'Debitor'::text
            WHEN 1 THEN 'Creditor'::text
            ELSE 'Debitor/Creditor'::text
        END AS "tip cont",
    NULL::numeric AS "cod inregistrare",
    NULL::numeric AS "nota cod",
    NULL::character varying AS "nota descriere",
    NULL::numeric AS "jurnal cod",
    NULL::character varying AS "jurnal descriere",
    to_date(to_char(cr.an, 'fm0000'::text) || to_char(cr.luna, 'fm00'::text), 'yyyymm'::text) AS data,
    c.simbol AS "cont simbol",
    c.den_cont AS "cont descriere",
        CASE
            WHEN c.clasa = ANY (ARRAY[6::numeric, 7::numeric]) THEN 0::numeric
            ELSE COALESCE(cs.soldic, 0::numeric) + COALESCE(cr.rulajpc, 0::numeric)
        END AS valoare,
        CASE
            WHEN c.clasa = ANY (ARRAY[6::numeric, 7::numeric]) THEN 0::numeric
            ELSE COALESCE(cs.soldvic, 0::numeric) + COALESCE(cr.rulajvpc, 0::numeric)
        END AS valoarev,
    NULL::character varying AS gestiune,
    NULL::character varying AS observatii,
    NULL::character varying AS document,
    cr.an * 10::numeric + cr.luna AS anlunalucru,
        CASE
            WHEN c.vizibilbalanta = 1::numeric THEN 'DA'::text
            ELSE 'NU'::text
        END AS "vizibil balanta",
        CASE
            WHEN c.balantasintetica = 1::numeric THEN 'DA'::text
            ELSE 'NU'::text
        END AS "balanta sintetica"
   FROM martor.ncontrul cr
     JOIN martor.ncontsold cs ON cs.codcont = cr.codcont AND cs.an = cr.an
     JOIN martor.ncont c ON c.codcont = cr.codcont
     CROSS JOIN ( SELECT count(1) AS nr
           FROM martor.jurnal) tmp;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_bi_jurnal1_cu_articol</obj_name>
  <obj_hashval>8771c587d4a3d87680b10bc30d2c2354</obj_hashval>
  <obj_text>SELECT
        CASE
            WHEN j1.tipdoc = ANY (ARRAY[1::numeric, 2::numeric, 3::numeric, 4::numeric, 6::numeric, 7::numeric, 9::numeric]) THEN i1.codobiect
            WHEN j1.tipdoc = 5::numeric THEN dvi1.codobiect
            WHEN j1.tipdoc = ANY (ARRAY[12::numeric, 13::numeric]) THEN t1.codobiect
            WHEN j1.tipdoc = ANY (ARRAY[14::numeric, 15::numeric, 19::numeric, 20::numeric, 21::numeric, 22::numeric, 23::numeric, 24::numeric, 26::numeric]) THEN ies1.codobiect
            ELSE NULL::numeric
        END AS codobiect,
    o.denumire,
    cls.den_clasea AS clasa,
    cd.simbol AS simbol_debit,
    cc.simbol AS simbol_credit,
    j1.codjurnal1,
    j1.coddoc,
    j1.tipdoc,
    j1.indexlocal,
    j1.codbazad,
    j1.tipbazad,
    j1.icontbazad,
    j1.coddescrd,
    j1.icontd,
    j1.tipcontd,
    j1.analiticcontd,
    j1.codbazac,
    j1.tipbazac,
    j1.icontbazac,
    j1.coddescrc,
    j1.icontc,
    j1.tipcontc,
    j1.analiticcontc,
    j1.gest,
    j1.valoare,
    j1.valoarev,
    j1.obs,
    j1.an,
    j1.luna,
    j1.dirty,
    j1.subunitatea,
    j1.datadoc,
    j1.document,
    j1.codcentru,
    j1.valoaregrup,
    j1.codanalizanod,
    j1.valoare_ifrs,
    j1.valoarev_ifrs
   FROM martor.jurnal1 j1
     JOIN martor.ncont cd ON cd.codcont = (( SELECT pkg_jurnal_getcontforjurnal.wme_result
           FROM martor.pkg_jurnal_getcontforjurnal(NULL::numeric, j1.coddescrd, j1.icontd, j1.tipcontd, j1.analiticcontd, j1.an, j1.luna) pkg_jurnal_getcontforjurnal(wme_result, coddescriere, icont, tipcont, analiticcont, aan, aluna)))
     JOIN martor.ncont cc ON cc.codcont = (( SELECT pkg_jurnal_getcontforjurnal.wme_result
           FROM martor.pkg_jurnal_getcontforjurnal(NULL::numeric, j1.coddescrc, j1.icontc, j1.tipcontc, j1.analiticcontc, j1.an, j1.luna) pkg_jurnal_getcontforjurnal(wme_result, coddescriere, icont, tipcont, analiticcont, aan, aluna)))
     LEFT JOIN martor.intrari1 i1 ON i1.codintr1 = j1.indexlocal
     LEFT JOIN martor.dvi1 ON dvi1.coddvi1 = j1.indexlocal
     LEFT JOIN martor.transf1 t1 ON t1.codtransf1 = j1.indexlocal
     LEFT JOIN martor.iesiri1 ies1 ON ies1.codies1 = j1.indexlocal
     LEFT JOIN martor.nartobj o ON o.codobiect = COALESCE(i1.codobiect, dvi1.codobiect, t1.codobiect, ies1.codobiect)
     LEFT JOIN martor.nart a ON a.codarticol = o.codarticol
     LEFT JOIN martor.nclasea cls ON cls.codclasea = a.clasa
  WHERE COALESCE(i1.codobiect, dvi1.codobiect, t1.codobiect, ies1.codobiect) &gt; 0::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_bi_miscint</obj_name>
  <obj_hashval>2d609502a12b33677bcccb42599ed668</obj_hashval>
  <obj_text>SELECT xm.numepresc AS numedoc,
    i.codies::character varying AS coddoc,
    i.tipdoc,
    i.prefixdoc,
    dc.serie AS seriedoc,
    i.nrdoc::character varying AS nrdoc,
        CASE
            WHEN i.datadoc &gt;= to_date('1970'::text, 'yyyy'::text) AND i.datadoc &lt;= martor.add_months(CURRENT_DATE, 120) THEN i.datadoc
            ELSE NULL::timestamp without time zone
        END AS datadoc,
    i1.codobiect::character varying AS codobiect,
    round(COALESCE(l1.cant, i1.cant), 4) AS cant,
    round(i1.pu, 4) AS pu,
    round(
        CASE
            WHEN COALESCE(i1.cant, 0::numeric) = 0::numeric THEN 0::numeric
            ELSE i1.tva * COALESCE(l1.cant, i1.cant) / i1.cant
        END, 4) AS tvalin,
    i1.indexlocal AS indexdoc,
    COALESCE(l1.codlivr1, 0::numeric)::character varying AS coddoc1,
    l.nrlivr::character varying AS nrlivrec,
        CASE
            WHEN l.datalivr &gt;= to_date('1970'::text, 'yyyy'::text) AND l.datalivr &lt;= martor.add_months(CURRENT_DATE, 120) THEN l.datalivr
            ELSE NULL::date
        END AS datalivrec,
    round(COALESCE(lv.pretachiz, ns.pret - ns.adaos), 4) AS pretachiz,
    round(COALESCE(lv.pretinreg, ns.pret), 4) AS pretinreg,
        CASE
            WHEN ns.dataachiz &gt;= to_date('1970'::text, 'yyyy'::text) AND ns.dataachiz &lt;= martor.add_months(CURRENT_DATE, 120) THEN ns.dataachiz
            ELSE NULL::date
        END AS dataachiz,
    f.den_part AS furnizor,
    date_trunc('day'::text, vf.vechime::timestamp with time zone) AS vechimefurnizor,
    g.den_gest AS gestiune,
    loc.denumire AS locatie,
    nc.simbol AS cont,
    nc.den_cont,
    ioa.den_ioart AS tipcontabil,
    CURRENT_DATE AS datasystem,
    ioa1.mg,
    i.an * 100::numeric + i.luna AS anluna
   FROM martor.iesiri i
     JOIN martor.livr l ON l.codies = i.codies AND l.tiplivr = i.tipdoc
     JOIN martor.livr1 l1 ON l1.codlivr = l.codlivr
     JOIN martor.iesiri1 i1 ON i1.codies1 = l1.codies1
     LEFT JOIN martor.machete xm ON xm.codmacheta = i.tipdoc
     LEFT JOIN martor.livrval lv ON lv.codlivr1 = l1.codlivr1
     LEFT JOIN martor.nirstoc ns ON ns.codnirstoc = l1.codnirstoc
     LEFT JOIN martor.doccarnete dc ON dc.codcarnet = i.carnetdoc
     LEFT JOIN martor.num1 u1 ON u1.codum1 = i1.umsec
     LEFT JOIN martor.npart f ON f.codpart = ns.furn
     LEFT JOIN martor.nir n ON n.codnir = ns.codnir
     LEFT JOIN martor.ngest g ON g.codgest = COALESCE(n.gest, lv.gest)
     LEFT JOIN martor.nlocatii loc ON loc.codlocatie = ns.codlocatie
     LEFT JOIN martor.ioart ioa ON ioa.codioart = COALESCE(lv.codioart, ns.codioart)
     LEFT JOIN martor.ioart1 ioa1 ON ioa1.codioart = ioa.codioart
     LEFT JOIN martor.ncont nc ON nc.codcont = COALESCE(ioa1.cont, i1.cont)
     LEFT JOIN ( SELECT nirstoc.furn,
            min(nirstoc.dataachiz) AS vechime
           FROM martor.nirstoc
          WHERE nirstoc.furn IS NOT NULL AND nirstoc.dataachiz &gt;= to_date('1970'::text, 'yyyy'::text) AND nirstoc.dataachiz &lt;= martor.add_months(CURRENT_DATE, 120)
          GROUP BY nirstoc.furn) vf ON vf.furn = ns.furn
  WHERE COALESCE(i.operat, 0::numeric) = 1::numeric AND COALESCE(i.anulat, 0::numeric) = 0::numeric AND (ioa1.anstart * 12::numeric + ioa1.lunastart) = (( SELECT max(ioart1.anstart * 12::numeric + ioart1.lunastart) AS max
           FROM martor.ioart1
          WHERE ioart1.codioart = ioa.codioart AND (ioart1.anstart * 12::numeric + ioart1.lunastart) &lt;= (i.an * 12::numeric + i.luna))) AND (i1.tiplinie::text = ANY (ARRAY['='::character varying::text, 'S'::character varying::text, 'V'::character varying::text])) AND (i.tipdoc = ANY (ARRAY[14::numeric, 15::numeric]))
UNION ALL
 SELECT xm.numepresc AS numedoc,
    t.codtransf::character varying AS coddoc,
    t.tipdoc,
    t.prefixdoc,
    dc.serie AS seriedoc,
    t.nrdoc::character varying AS nrdoc,
        CASE
            WHEN t.datadoc &gt;= to_date('1970'::text, 'yyyy'::text) AND t.datadoc &lt;= martor.add_months(CURRENT_DATE, 120) THEN t.datadoc
            ELSE NULL::date
        END AS datadoc,
    t1.codobiect::character varying AS codobiect,
    - round(COALESCE(l1.cant, t1.cant), 4) AS cant,
    round(t1.pu, 4) AS pu,
    - round(
        CASE
            WHEN COALESCE(t1.cant, 0::numeric) = 0::numeric THEN 0::numeric
            ELSE t1.tva * COALESCE(l1.cant, t1.cant) / t1.cant
        END, 4) AS tvalin,
    t1.indexlocal AS indexdoc,
    COALESCE(l1.codlivr1, 0::numeric)::character varying AS coddoc1,
    l.nrlivr::character varying AS nrlivrec,
        CASE
            WHEN l.datalivr &gt;= to_date('1970'::text, 'yyyy'::text) AND l.datalivr &lt;= martor.add_months(CURRENT_DATE, 120) THEN l.datalivr
            ELSE NULL::date
        END AS datalivrec,
    round(COALESCE(lv.pretachiz, ns.pret - ns.adaos), 4) AS pretachiz,
    round(COALESCE(lv.pretinreg, ns.pret), 4) AS pretinreg,
        CASE
            WHEN ns.dataachiz &gt;= to_date('1970'::text, 'yyyy'::text) AND ns.dataachiz &lt;= martor.add_months(CURRENT_DATE, 120) THEN ns.dataachiz
            ELSE NULL::date
        END AS dataachiz,
    f.den_part AS furnizor,
    date_trunc('day'::text, vf.vechime::timestamp with time zone) AS vechimefurnizor,
    g.den_gest AS gestiune,
    loc.denumire AS locatie,
    nc.simbol AS cont,
    nc.den_cont,
    ioa.den_ioart AS tipcontabil,
    CURRENT_DATE AS datasystem,
    ioa1.mg,
    t.an * 100::numeric + t.luna AS anluna
   FROM martor.transf t
     JOIN martor.livr l ON l.codtransf = t.codtransf AND l.tiplivr = t.tipdoc
     JOIN martor.livr1 l1 ON l1.codlivr = l.codlivr
     JOIN martor.transf1 t1 ON t1.codtransf = t.codtransf AND t1.codtransf1 = l1.codies1
     LEFT JOIN martor.machete xm ON xm.codmacheta = t.tipdoc
     LEFT JOIN martor.doccarnete dc ON dc.codcarnet = t.carnetdoc
     LEFT JOIN martor.nirstoc ns ON ns.codnirstoc = l1.codnirstoc
     LEFT JOIN martor.livrval lv ON l1.codlivr1 = lv.codlivr1
     LEFT JOIN martor.num1 u1 ON u1.codum1 = t1.umsec
     LEFT JOIN martor.npart f ON f.codpart = ns.furn
     LEFT JOIN martor.nir n ON n.codnir = ns.codnir
     LEFT JOIN martor.ngest g ON g.codgest = COALESCE(n.gest, lv.gest)
     LEFT JOIN martor.nlocatii loc ON loc.codlocatie = ns.codlocatie
     LEFT JOIN martor.ioart ioa ON ioa.codioart = COALESCE(lv.codioart, ns.codioart)
     LEFT JOIN martor.ioart1 ioa1 ON ioa1.codioart = ioa.codioart
     LEFT JOIN martor.ncont nc ON nc.codcont = COALESCE(ioa1.cont, t1.codcont)
     LEFT JOIN ( SELECT nirstoc.furn,
            min(nirstoc.dataachiz) AS vechime
           FROM martor.nirstoc
          WHERE nirstoc.furn IS NOT NULL AND nirstoc.dataachiz &gt;= to_date('1970'::text, 'yyyy'::text) AND nirstoc.dataachiz &lt;= martor.add_months(CURRENT_DATE, 120)
          GROUP BY nirstoc.furn) vf ON vf.furn = ns.furn
  WHERE COALESCE(t.operat, 0::numeric) = 1::numeric AND COALESCE(t.anulat, 0::numeric) = 0::numeric AND (ioa1.anstart * 12::numeric + ioa1.lunastart) = (( SELECT max(ioart1.anstart * 12::numeric + ioart1.lunastart) AS max
           FROM martor.ioart1
          WHERE ioart1.codioart = ioa.codioart AND (ioart1.anstart * 12::numeric + ioart1.lunastart) &lt;= (t.an * 12::numeric + t.luna)))
UNION ALL
 SELECT xm.numepresc AS numedoc,
    t.codtransf::character varying AS coddoc,
    t.tipdoc,
    t.prefixdoc,
    dc.serie AS seriedoc,
    t.nrdoc::character varying AS nrdoc,
        CASE
            WHEN t.datadoc &gt;= to_date('1970'::text, 'yyyy'::text) AND t.datadoc &lt;= martor.add_months(CURRENT_DATE, 120) THEN t.datadoc
            ELSE NULL::date
        END AS datadoc,
    t1.codobiect::character varying(32) AS codobiect,
    round(COALESCE(ns.cantnir, t1.cant), 4) AS cant,
    round(t1.pu, 4) AS pu,
    round(
        CASE
            WHEN COALESCE(t1.cant, 0::numeric) = 0::numeric THEN 0::numeric
            ELSE t1.tva * COALESCE(ns.cantnir, t1.cant) / t1.cant
        END, 4) AS tvalin,
    t1.indexlocal AS indexdoc,
    COALESCE(ns.codnirstoc, 0::numeric)::character varying AS coddoc1,
    n.nrnir::character varying AS nrlivrec,
        CASE
            WHEN n.datanir &gt;= to_date('1970'::text, 'yyyy'::text) AND n.datanir &lt;= martor.add_months(CURRENT_DATE, 120) THEN n.datanir
            ELSE NULL::date
        END AS datalivrec,
    round(ns.pret - ns.adaos, 4) AS pretachiz,
    round(ns.pret, 4) AS pretinreg,
        CASE
            WHEN ns.dataachiz &gt;= to_date('1970'::text, 'yyyy'::text) AND ns.dataachiz &lt;= martor.add_months(CURRENT_DATE, 120) THEN ns.dataachiz
            ELSE NULL::date
        END AS dataachiz,
    f.den_part AS furnizor,
    date_trunc('day'::text, vf.vechime::timestamp with time zone) AS vechimefurnizor,
    g.den_gest AS gestiune,
    loc.denumire AS locatie,
    nc.simbol AS cont,
    nc.den_cont,
    ioa.den_ioart AS tipcontabil,
    CURRENT_DATE AS datasystem,
    ioa1.mg,
    t.an * 100::numeric + t.luna AS anluna
   FROM martor.transf t
     JOIN martor.transf1 t1 ON t1.codtransf = t.codtransf
     JOIN martor.nir n ON t.codtransf = n.codtransf
     JOIN martor.nirstoc ns ON ns.codtransf1 = t1.codtransf1 AND ns.codnir = n.codnir
     LEFT JOIN martor.machete xm ON xm.codmacheta = t.tipdoc
     LEFT JOIN martor.doccarnete dc ON dc.codcarnet = t.carnetdoc
     LEFT JOIN martor.num1 u1 ON u1.codum1 = t1.umsec
     LEFT JOIN martor.npart f ON f.codpart = ns.furn
     LEFT JOIN martor.ngest g ON g.codgest = n.gest
     LEFT JOIN martor.nlocatii loc ON loc.codlocatie = ns.codlocatie
     LEFT JOIN martor.ioart ioa ON ioa.codioart = ns.codioart
     LEFT JOIN martor.ioart1 ioa1 ON ioa1.codioart = ioa.codioart
     LEFT JOIN martor.ncont nc ON nc.codcont = COALESCE(ioa1.cont, t1.codcont)
     LEFT JOIN ( SELECT nirstoc.furn,
            min(nirstoc.dataachiz) AS vechime
           FROM martor.nirstoc
          WHERE nirstoc.furn IS NOT NULL AND nirstoc.dataachiz &gt;= to_date('1970'::text, 'yyyy'::text) AND nirstoc.dataachiz &lt;= martor.add_months(CURRENT_DATE, 120)
          GROUP BY nirstoc.furn) vf ON vf.furn = ns.furn
  WHERE COALESCE(t.operat, 0::numeric) = 1::numeric AND COALESCE(t.anulat, 0::numeric) = 0::numeric AND (ioa1.anstart * 12::numeric + ioa1.lunastart) = (( SELECT max(ioart1.anstart * 12::numeric + ioart1.lunastart) AS max
           FROM martor.ioart1
          WHERE ioart1.codioart = ioa.codioart AND (ioart1.anstart * 12::numeric + ioart1.lunastart) &lt;= (t.an * 12::numeric + t.luna)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_bi_stoc</obj_name>
  <obj_hashval>56518cbfc7c3e8d9b73e6518b7f00cfd</obj_hashval>
  <obj_text>SELECT ns.codobiect::character varying AS codobiect,
    nl.rest,
    nl.restum1,
    nl.restum2,
    last_day(to_date((nl.an::character varying::text || '.'::text) || nl.luna::character varying::text, 'yyyy.mm'::text)) AS datastoc,
    round(ns.pret - ns.adaos, 4) AS pachiz,
    ns.pret AS pinreg,
        CASE
            WHEN ns.dataachiz &gt;= to_date('1970'::text, 'yyyy'::text) AND ns.dataachiz &lt;= martor.add_months(CURRENT_DATE, 120) THEN ns.dataachiz
            ELSE NULL::date
        END AS dataachiz,
    f.den_part AS furnizor,
    date_trunc('day'::text, vf.vechime::timestamp with time zone) AS vechimefurnizor,
    g.den_gest AS gestiune,
    loc.denumire AS locatie,
    nc.simbol AS cont,
    nc.den_cont,
    ioa.den_ioart AS tipcontabil,
    CURRENT_DATE AS datasystem,
    ioa1.mg,
    nl.an * 100::numeric + nl.luna AS anluna
   FROM martor.nirluna nl
     JOIN martor.nirstoc ns ON ns.codnirstoc = nl.codnirstoc
     JOIN martor.nartobj o ON o.codobiect = ns.codobiect
     JOIN martor.ioart ioa ON ioa.codioart = ns.codioart
     JOIN ( SELECT x.codioart,
            x.mg,
            x.cont,
                CASE
                    WHEN (x.anstart * 12::numeric + x.lunastart) = (fl.aninitial * 12::numeric + fl.lunainitiala) THEN 0::numeric
                    ELSE x.anstart * 12::numeric + x.lunastart
                END AS alstart,
            COALESCE(lead(x.anstart * 12::numeric + x.lunastart) OVER (PARTITION BY x.codioart ORDER BY (x.anstart * 12::numeric + x.lunastart)) - 1::numeric, fl.anmaxim * 12::numeric + fl.lunamaxima) AS alstop
           FROM martor.ioart1 x
             CROSS JOIN martor.firmaluni fl) ioa1 ON ioa1.codioart = ns.codioart AND (nl.an * 12::numeric + nl.luna) &gt;= ioa1.alstart AND (nl.an * 12::numeric + nl.luna) &lt;= ioa1.alstop
     LEFT JOIN martor.ncont nc ON nc.codcont = ioa1.cont
     LEFT JOIN martor.nart a ON a.codarticol = o.codarticol
     LEFT JOIN martor.num u ON u.codum = a.um
     LEFT JOIN martor.num u1 ON u1.codum = a.um1
     LEFT JOIN martor.num u2 ON u2.codum = a.um2
     LEFT JOIN martor.nclasea ca ON ca.codclasea = a.clasa
     LEFT JOIN martor.npart f ON f.codpart = ns.furn
     LEFT JOIN martor.nir n ON n.codnir = ns.codnir
     LEFT JOIN martor.ngest g ON g.codgest = n.gest
     LEFT JOIN martor.nlocatii loc ON loc.codlocatie = ns.codlocatie
     LEFT JOIN ( SELECT nirstoc.furn,
            min(nirstoc.dataachiz) AS vechime
           FROM martor.nirstoc
          WHERE nirstoc.furn IS NOT NULL AND nirstoc.dataachiz &gt;= to_date('1970'::text, 'yyyy'::text) AND nirstoc.dataachiz &lt;= martor.add_months(CURRENT_DATE, 120)
          GROUP BY nirstoc.furn) vf ON vf.furn = ns.furn
  WHERE (nl.an * 12::numeric + nl.luna) &lt;= (( SELECT firmaluni.ancurent * 12::numeric + firmaluni.lunacurenta - 1::numeric
           FROM martor.firmaluni)) AND (COALESCE(nl.rest, 0::numeric) + COALESCE(nl.restum1, 0::numeric) + COALESCE(nl.restum2, 0::numeric)) &lt;&gt; 0::numeric AND ioa1.mg &lt;&gt; 5::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_carnete_sub</obj_name>
  <obj_hashval>a589d74d474d8bfc77cf9ef5632bee3c</obj_hashval>
  <obj_text>SELECT codcarnet,
    simbol,
    denumire,
    serie,
    startnr,
    endnr,
    freenr,
    inactiv,
    subunitatea,
    codpostretail
   FROM martor.doccarnete d
  WHERE (codcarnet IN ( SELECT doclink.codcarnet
           FROM martor.doclink
          WHERE doclink.codmacheta = (( SELECT pkg_carnetedoc_getmachetacurenta.wme_result
                   FROM martor.pkg_carnetedoc_getmachetacurenta(NULL::numeric, NULL::numeric) pkg_carnetedoc_getmachetacurenta(wme_result, fakeparam))))) AND COALESCE(subunitatea, 1::numeric) = (( SELECT pkg_globals_getsubunitate_doc.wme_result
           FROM martor.pkg_globals_getsubunitate_doc(NULL::numeric, NULL::numeric) pkg_globals_getsubunitate_doc(wme_result, fakeparam))) AND (COALESCE(dedicat, 0::numeric) = 0::numeric OR (EXISTS ( SELECT docusers.coddocusers
           FROM martor.docusers
          WHERE docusers.coduser = (( SELECT pkg_globals_getuserid.wme_result
                   FROM martor.pkg_globals_getuserid(NULL::numeric, NULL::numeric) pkg_globals_getuserid(wme_result, fakeparam))) AND docusers.codcarnet = d.codcarnet)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_carnetemacheta</obj_name>
  <obj_hashval>b6cef383a667b1a63c803ff0cba39d3d</obj_hashval>
  <obj_text>SELECT d.codcarnet,
    d.simbol,
    d.denumire,
    d.serie,
    d.startnr,
    d.endnr,
    d.freenr,
    d.inactiv,
    d.subunitatea,
    d.codpostretail,
    s.den_subunit
   FROM martor.doccarnete d,
    martor.nsubunit s
  WHERE d.subunitatea = s.codsubunit AND (d.codcarnet IN ( SELECT doclink.codcarnet
           FROM martor.doclink
          WHERE doclink.codmacheta = current_setting('PKG_CARNETEDOC.MACHETACURENTA'::text, true)::numeric)) AND (COALESCE(d.subunitatea, 1::numeric) =
        CASE
            WHEN current_setting('PKG_GLOBALS.SUBUNITATE'::text, true)::numeric = 1::numeric THEN COALESCE(d.subunitatea, 1::numeric)
            ELSE current_setting('PKG_GLOBALS.SUBUNITATE'::text, true)::numeric
        END OR COALESCE(d.allsubunit, 0::numeric) = 1::numeric) AND (COALESCE(d.dedicat, 0::numeric) = 0::numeric OR (EXISTS ( SELECT docusers.coddocusers
           FROM martor.docusers
          WHERE docusers.coduser = current_setting('PKG_GLOBALS.USERID'::text, true)::numeric AND docusers.codcarnet = d.codcarnet)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_carnetemacheta_0</obj_name>
  <obj_hashval>412120eb84821ab98611a637a715c3f5</obj_hashval>
  <obj_text>SELECT d.codcarnet,
    d.simbol,
    d.denumire,
    d.serie,
    d.startnr,
    d.endnr,
    d.freenr,
    d.inactiv,
    d.subunitatea,
    d.codpostretail,
    s.den_subunit
   FROM martor.doccarnete d,
    martor.nsubunit s
  WHERE d.subunitatea = s.codsubunit AND (d.codcarnet IN ( SELECT doclink.codcarnet
           FROM martor.doclink
          WHERE doclink.codmacheta = (( SELECT pkg_carnetedoc_getmachetacurenta.wme_result
                   FROM martor.pkg_carnetedoc_getmachetacurenta(NULL::numeric, NULL::numeric) pkg_carnetedoc_getmachetacurenta(wme_result, fakeparam))))) AND (COALESCE(d.subunitatea, 1::numeric) =
        CASE
            WHEN martor.getsubunitate() = 1::numeric THEN COALESCE(d.subunitatea, 1::numeric)
            ELSE martor.getsubunitate()
        END OR COALESCE(d.allsubunit, 0::numeric) = 1::numeric) AND (COALESCE(d.dedicat, 0::numeric) = 0::numeric OR (EXISTS ( SELECT docusers.coddocusers
           FROM martor.docusers
          WHERE docusers.coduser = martor.getuserid() AND docusers.codcarnet = d.codcarnet)))
UNION ALL
 SELECT 0 AS codcarnet,
    ''::character varying AS simbol,
    '...nedefinit...'::character varying AS denumire,
    ''::character varying AS serie,
    NULL::numeric AS startnr,
    NULL::numeric AS endnr,
    NULL::numeric AS freenr,
    0 AS inactiv,
    0 AS subunitatea,
    0 AS codpostretail,
    ''::character varying AS den_subunit;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_cmdintactive</obj_name>
  <obj_hashval>d3bd0672aa82233ac8e971a0801c87e2</obj_hashval>
  <obj_text>SELECT c1.codcomanda1,
    c.codcomanda,
    ((((COALESCE(c.prefixdoc, ''::character varying)::text || COALESCE(c.seriadoc, ''::character varying)::text) || COALESCE(c.nrdoc::character varying, ''::character varying)::text) || '/'::character varying::text) || COALESCE(to_char(c.datadoc::timestamp with time zone, 'dd.mm.yyyy'::text), ''::text))::character varying AS comanda,
    c.datadoc,
    date_part('day'::text, c.datadoc) AS ziua,
    kc1.codcomanda1 AS codcomandacli1,
    kc.codcomanda AS codcomandacli,
    ((((COALESCE(kc.prefixdoc, ''::character varying)::text || COALESCE(kc.seriadoc, ''::character varying)::text) || COALESCE(kc.nrdoc::character varying, ''::character varying)::text) || '/'::character varying::text) || COALESCE(to_char(kc.datadoc::timestamp with time zone, 'dd.mm.yyyy'::text), ''::text))::character varying AS cmdcli,
    p.den_part AS client,
    g.den_gest,
    f.den_formatie,
    c.schimb,
    c1.nivel,
    o.denumire AS produs,
    c1.termen AS termencmdint,
    kc1.termen AS termencmdcli,
    c1.codreteta,
    r.obs AS reteta,
    c.an,
    c.luna,
    c.subunitatea,
    c.codgest,
    c1.cantacceptat,
    c1.umsec,
    c1.termen
   FROM martor.comanda c
     JOIN martor.comanda1 c1 ON c1.codcomanda = c.codcomanda
     JOIN martor.cmdprodmat mat ON mat.codcomanda1 = c1.codcomanda1 AND COALESCE(mat.codprodmat, 0::numeric) = 0::numeric
     JOIN martor.nartobj o ON o.codobiect = c1.codobiect
     JOIN martor.prodcomp r ON r.codprodcomp = c1.codreteta
     LEFT JOIN martor.ngest g ON g.codgest = c.codgest
     LEFT JOIN martor.formatii f ON f.codformatie = c.codformatie
     LEFT JOIN martor.cmdlink k ON k.codcomanda1 = c1.codcomanda1
     LEFT JOIN martor.comanda1 kc1 ON kc1.codcomanda1 = k.codliniecomanda
     LEFT JOIN martor.comanda kc ON kc.codcomanda = kc1.codcomanda
     LEFT JOIN martor.npart p ON p.codpart = kc.partener
  WHERE c.tipdoc = 53::numeric AND c.operat = 1::numeric AND c.anulat = 0::numeric AND COALESCE(c.inchisa, 0::numeric) = 0::numeric AND c1.consum &lt;&gt; 0::numeric AND mat.rest &gt; 0::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_const_gramada</obj_name>
  <obj_hashval>8f055f6061399170de2418a23e712b4a</obj_hashval>
  <obj_text>SELECT DISTINCT codcateg,
    codconst1,
    denumire,
    simbol,
    indexlocal,
    sectiune,
        CASE tipcateg
            WHEN 'G'::text THEN 'General'::character varying
            WHEN 'U'::text THEN ( SELECT getusername.wme_result
               FROM martor.getusername(NULL::character varying, a_pg.userid) getusername(wme_result, puser))
            ELSE '..'::character varying
        END AS utilizator,
    tip,
    tipcateg,
    userid,
    ( SELECT pkg_categconst_getvalafis.wme_result
           FROM martor.pkg_categconst_getvalafis(NULL::character varying, a_pg.tip, a_pg.codconstluna) pkg_categconst_getvalafis(wme_result, ptip, pcodconstluna)) AS valoare,
    1 AS gramada
   FROM ( SELECT row_number() OVER (PARTITION BY c1.codconst1 ORDER BY (cl.anstart * 12::numeric + cl.lunastart) DESC) AS rnum,
            c.codcateg,
            c1.codconst1,
            c1.denumire,
            c1.simbol,
            c1.indexlocal,
            c.denumire AS sectiune,
            c1.tip,
            c.tipcateg,
            cl.userid,
            cl.codconstluna
           FROM martor.categconst c
             JOIN martor.const1 c1 ON c1.codcateg = c.codcateg
             LEFT JOIN martor.constluna cl ON cl.codconst1 = c1.codconst1
          WHERE COALESCE(cl.anstart * 12::numeric + cl.lunastart, 0::numeric) &lt;= COALESCE(current_setting('PKG_GLOBALS.ANLUCRU'::text, true)::numeric * 12::numeric + current_setting('PKG_GLOBALS.LUNALUCRU'::text, true)::numeric, 0::numeric) AND c1.tip &lt;&gt; 0::numeric AND COALESCE(cl.userid, 0::numeric) =
                CASE
                    WHEN c.tipcateg::text = 'G'::text THEN 0::numeric
                    ELSE current_setting('PKG_GLOBALS.USERID'::text, true)::numeric
                END) a_pg
  WHERE rnum = 1;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_convert_soldpers_in</obj_name>
  <obj_hashval>7431939441b34365b42fb2dd36e223df</obj_hashval>
  <obj_text>SELECT codpers,
    icontpers AS icont,
    moneda_in AS codmoneda,
    COALESCE(- sum(soldlei), 0::numeric) AS soldlei,
    COALESCE(- sum(soldvaluta_in), 0::numeric) AS soldvaluta
   FROM martor.convertcurspers
  WHERE an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric
  GROUP BY codpers, icontpers, moneda_in;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_convert_soldpers_in_sub</obj_name>
  <obj_hashval>44ee0106d267d02e26de0a662deeb869</obj_hashval>
  <obj_text>SELECT codpers,
    icontpers AS icont,
    moneda_in AS codmoneda,
    subunitatea,
    COALESCE(- sum(soldlei), 0::numeric) AS soldlei,
    COALESCE(- sum(soldvaluta_in), 0::numeric) AS soldvaluta
   FROM martor.convertcurspers
  WHERE an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric
  GROUP BY codpers, icontpers, moneda_in, subunitatea;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_convert_soldpers_luna_in</obj_name>
  <obj_hashval>9cfd403fead4fe3c99e05f0d5405c20f</obj_hashval>
  <obj_text>SELECT codpers,
    icontpers AS icont,
    moneda_in AS codmoneda,
    COALESCE(- sum(soldlei), 0::numeric) AS soldlei,
    COALESCE(- sum(soldvaluta_in), 0::numeric) AS soldvaluta
   FROM martor.convertcurspers
  WHERE an = martor.getantemp() AND luna = martor.getlunatemp() AND codpers = martor.pkg_nompers_get_persoana_curenta() AND icontpers = martor.pkg_nompers_get_icontpers_curent() AND moneda_in = martor.pkg_nompers_get_monedapers_curent()
  GROUP BY codpers, icontpers, moneda_in;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_convert_soldpers_luna_out</obj_name>
  <obj_hashval>f60ad2df8cd5feb6ff93881547cc5688</obj_hashval>
  <obj_text>SELECT codpers,
    icontpers AS icont,
    moneda_out AS codmoneda,
    COALESCE(sum(soldlei), 0::numeric) AS soldlei,
    COALESCE(sum(soldvaluta_out), 0::numeric) AS soldvaluta
   FROM martor.convertcurspers
  WHERE an = martor.getantemp() AND luna = martor.getlunatemp() AND codpers = martor.pkg_nompers_get_persoana_curenta() AND icontpers = martor.pkg_nompers_get_icontpers_curent() AND moneda_out = martor.pkg_nompers_get_monedapers_curent()
  GROUP BY codpers, icontpers, moneda_out;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_convert_soldpers_out</obj_name>
  <obj_hashval>b90d541a94aabe7958c52eb33859fa64</obj_hashval>
  <obj_text>SELECT codpers,
    icontpers AS icont,
    moneda_out AS codmoneda,
    COALESCE(sum(soldlei), 0::numeric) AS soldlei,
    COALESCE(sum(soldvaluta_out), 0::numeric) AS soldvaluta
   FROM martor.convertcurspers
  WHERE an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric
  GROUP BY codpers, icontpers, moneda_out;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_convert_soldpers_out_sub</obj_name>
  <obj_hashval>1fd2d69cc7c97b3263d8fd37484c9822</obj_hashval>
  <obj_text>SELECT codpers,
    icontpers AS icont,
    moneda_out AS codmoneda,
    subunitatea,
    COALESCE(sum(soldlei), 0::numeric) AS soldlei,
    COALESCE(sum(soldvaluta_out), 0::numeric) AS soldvaluta
   FROM martor.convertcurspers
  WHERE an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric
  GROUP BY codpers, icontpers, moneda_out, subunitatea;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_decode_descript</obj_name>
  <obj_hashval>f24ffa12d452dcfa396be317eead9cd1</obj_hashval>
  <obj_text>SELECT d.coddescriptor,
    d.den_descriptor,
    a1.codanaliza,
    a1.indexlocal
   FROM martor.analiza1 a1
     JOIN martor.descriptori d ON a1.coddescriptor = d.coddescriptor
  ORDER BY a1.indexlocal;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_denanaliza</obj_name>
  <obj_hashval>039251624c076ee1ae9a36cfb58ddb32</obj_hashval>
  <obj_text>WITH RECURSIVE reca(codanalizanod, nivel, denumire, simbol) AS (
         SELECT an.codanalizanod,
            0 AS nivel,
                CASE
                    WHEN aa.tip = 1::numeric THEN ((an.simbolnod::text || '='::text) || an.dennod::text)::character varying
                    ELSE d1.valoare
                END AS denumire,
                CASE
                    WHEN aa.tip = 1::numeric THEN an.simbolnod::text
                    ELSE lpad('''AN.POZITIE'''::text, 2, '0'::text)
                END AS simbol
           FROM martor.analizanod an
             LEFT JOIN martor.analiza aa ON aa.codanaliza = an.codanaliza
             LEFT JOIN martor.descriptori1 d1 ON an.coddescriptor1 = d1.coddescriptor1
          WHERE an.nodparinte = 0::numeric
        UNION ALL
         SELECT an.codanalizanod,
            reca.nivel + 1 AS nivel,
                CASE
                    WHEN aa.tip = 1::numeric THEN ((an.simbolnod::text || '='::text) || an.dennod::text)::character varying
                    ELSE d1.valoare
                END AS denumire,
                CASE
                    WHEN aa.tip = 1::numeric THEN an.simbolnod::text
                    WHEN reca.nivel = 0 THEN lpad('''AN.POZITIE'''::text, 2, '0'::text)
                    ELSE (reca.simbol || '.'::text) || lpad('''AN.POZITIE'''::text, 2, '0'::text)
                END AS simbol
           FROM reca
             JOIN martor.analizanod an ON an.nodparinte = reca.codanalizanod
             LEFT JOIN martor.analiza aa ON aa.codanaliza = an.codanaliza
             LEFT JOIN martor.descriptori1 d1 ON an.coddescriptor1 = d1.coddescriptor1
        )
 SELECT codanalizanod,
    denumire,
    simbol
   FROM reca v;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_descriptori</obj_name>
  <obj_hashval>74e638a43d6a39824eb097573128c9c5</obj_hashval>
  <obj_text>SELECT coddescriptor,
    den_descriptor,
    simbol,
        CASE
            WHEN tip = 0::numeric THEN 'Diverse'::text
            WHEN tip = 80::numeric THEN 'Tari'::text
            WHEN tip = 81::numeric THEN 'Judete'::text
            WHEN tip = 82::numeric THEN 'Orase'::text
            WHEN tip = 85::numeric THEN 'Activitati'::text
            WHEN tip = 70::numeric THEN 'Subunitati'::text
            WHEN tip = 86::numeric THEN 'Gestiuni'::text
            WHEN tip = 87::numeric THEN 'Centre cost'::text
            WHEN tip = 90::numeric THEN 'Formatii'::text
            WHEN tip = 100::numeric THEN 'Clase articole'::text
            WHEN tip = 22::numeric THEN 'Articole'::text
            WHEN tip = 75::numeric THEN 'Parc auto'::text
            WHEN tip = 2::numeric THEN 'Conturi'::text
            WHEN tip = 60::numeric THEN 'Parteneri'::text
            WHEN tip = 50::numeric THEN 'Personal'::text
            WHEN tip = 11::numeric THEN 'Monede'::text
            WHEN tip = 101::numeric THEN 'Utilaje'::text
            ELSE '...nedefinit...'::text
        END::character varying AS tip
   FROM martor.descriptori d;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_distanta</obj_name>
  <obj_hashval>21d587bd90dea00e40c9d6bff1bda006</obj_hashval>
  <obj_text>SELECT d.coddistanta,
    g1.codgest AS codgeststart,
    g1.den_gest AS dengeststart,
    g2.codgest AS codgeststop,
    g2.den_gest AS dengeststop,
    l1.codlocalit AS codlocalitstart,
    l1.den_localit AS denlocalitstart,
    l2.codlocalit AS codlocalitstop,
    l2.den_localit AS denlocalitstop,
    d.km,
    m.codmoneda,
    m.simbol AS smoneda,
    d.valoare
   FROM martor.distanta d
     JOIN martor.nmonede m ON m.codmoneda = COALESCE(d.moneda, 0::numeric)
     JOIN martor.ngest g1 ON g1.codgest = COALESCE(d.codgest_start, 0::numeric)
     JOIN martor.ngest g2 ON g2.codgest = COALESCE(d.codgest_stop, 0::numeric)
     JOIN martor.nlocalit l1 ON l1.codlocalit = COALESCE(d.codlocalit_start, 0::numeric)
     JOIN martor.nlocalit l2 ON l2.codlocalit = COALESCE(d.codlocalit_stop, 0::numeric);</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_elembuget</obj_name>
  <obj_hashval>beda40d797a22b45b700ae3ee6665477</obj_hashval>
  <obj_text>SELECT codelembuget,
    element,
    simbol,
        CASE
            WHEN tip = 1::numeric THEN 'Element de cheltuiala'::text
            ELSE 'Element de venit'::text
        END AS tip,
        CASE
            WHEN functie = 0::numeric THEN 'Estimare costuri si venituri din productie pe clase articole'::text
            WHEN functie = 1::numeric THEN 'Estimare plati si incasari saptamale'::text
            WHEN functie = 2::numeric THEN 'Estimare variatie stoc pe clase articole'::text
            ELSE NULL::text
        END AS functie,
        CASE
            WHEN functie = ANY (ARRAY[0::numeric, 2::numeric]) THEN ( SELECT string_agg(cls.den_clasea::text, ','::text) AS string_agg
               FROM martor.elembuget1 b1
                 JOIN martor.nclasea cls ON cls.codclasea = b1.codclasea
              WHERE b1.codelembuget = b.codelembuget)
            ELSE NULL::text
        END AS clase
   FROM martor.elembuget b;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_elemente</obj_name>
  <obj_hashval>e5661bca4c2e18196a5c51c41103d932</obj_hashval>
  <obj_text>SELECT codelement,
    den_element,
        CASE
            WHEN tip = 0::numeric THEN 'Chelt'::character varying
            WHEN tip = 1::numeric THEN 'Venit'::character varying
            WHEN tip = 2::numeric THEN 'Bifunc'::character varying
            ELSE NULL::character varying
        END AS dentip,
    tip,
    simbol,
    coddescriptorbaza
   FROM martor.elemente;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_elemente_analiza</obj_name>
  <obj_hashval>143a991d8bb206c255f05cb422a92ce7</obj_hashval>
  <obj_text>SELECT e.codelement,
    e.den_element,
    e.simbol,
    e.tip,
    e.coddescriptorbaza,
    0 AS sel
   FROM martor.elemente e
     JOIN martor.elementem em ON e.codelement = em.codelement
     JOIN martor.elementec ec ON ec.codelementm = em.codelementm
     JOIN martor.elementea ea ON e.codelement = ea.codelement
  WHERE instr(( SELECT pkg_elemente_get_simbol.wme_result
           FROM martor.pkg_elemente_get_simbol(NULL::character varying, NULL::numeric) pkg_elemente_get_simbol(wme_result, fakeparam)), ec.masca) = 1 AND em.tipdoc = (( SELECT pkg_elemente_get_tipdoc.wme_result
           FROM martor.pkg_elemente_get_tipdoc(NULL::numeric, NULL::numeric) pkg_elemente_get_tipdoc(wme_result, fakeparam))) AND ea.codanaliza = (( SELECT pkg_elemente_get_codanaliza.wme_result
           FROM martor.pkg_elemente_get_codanaliza(NULL::numeric, NULL::numeric) pkg_elemente_get_codanaliza(wme_result, fakeparam))) AND (e.tip = 2::numeric OR e.tip = (( SELECT pkg_elemente_get_tipcont.wme_result
           FROM martor.pkg_elemente_get_tipcont(NULL::numeric, NULL::numeric) pkg_elemente_get_tipcont(wme_result, fakeparam))));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_elemente_analiza_all</obj_name>
  <obj_hashval>0774101d5b97574c27dc91480b731761</obj_hashval>
  <obj_text>SELECT e.codelement,
    e.den_element,
    e.simbol,
    e.tip,
    e.coddescriptorbaza,
    0 AS sel
   FROM martor.elemente e
     JOIN martor.elementem em ON e.codelement = em.codelement
     JOIN martor.elementea ea ON e.codelement = ea.codelement
  WHERE em.tipdoc = (( SELECT pkg_elemente_get_tipdoc.wme_result
           FROM martor.pkg_elemente_get_tipdoc(NULL::numeric, NULL::numeric) pkg_elemente_get_tipdoc(wme_result, fakeparam))) AND ea.codanaliza = (( SELECT pkg_elemente_get_codanaliza.wme_result
           FROM martor.pkg_elemente_get_codanaliza(NULL::numeric, NULL::numeric) pkg_elemente_get_codanaliza(wme_result, fakeparam))) AND (e.tip = 2::numeric OR e.tip = (( SELECT pkg_elemente_get_tipcont.wme_result
           FROM martor.pkg_elemente_get_tipcont(NULL::numeric, NULL::numeric) pkg_elemente_get_tipcont(wme_result, fakeparam))));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_emulare_nedescarcata</obj_name>
  <obj_hashval>686e29dc3e8561ea64112845d4220a9a</obj_hashval>
  <obj_text>SELECT e1.codobiect,
    e1.codgest,
    sum(e1.cant) AS cant
   FROM martor.emulare e,
    martor.emulare1 e1
  WHERE COALESCE(e.preluat, 0::numeric) = 0::numeric AND COALESCE(e.facturare, 0::numeric) = 0::numeric AND e1.codemulare = e.codemulare AND COALESCE(e1.codgest, 0::numeric) &lt;&gt; 0::numeric
  GROUP BY e1.codobiect, e1.codgest;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_estimariprod</obj_name>
  <obj_hashval>eda9f43591b51cdb093942ef37f5fcbb</obj_hashval>
  <obj_text>SELECT es1.codestimareprod1,
    es.codestimareprod,
    es.an,
    es.luna,
    es.subunitatea,
    es.userid,
    es.datacreare,
    es.obs,
    COALESCE(es.anulat, 0::numeric) AS anulat,
    COALESCE(es.operat, 0::numeric) AS operat,
    COALESCE(es.blocat, 0::numeric) AS blocat,
    es.saptamana,
    es.nrdoc,
    es.datadoc,
    es.carnetdoc,
    es.seriadoc,
    es.prefixdoc,
    es.animport
   FROM martor.estimariprod es
     JOIN ( SELECT min(estimariprod1.codestimareprod1) AS codestimareprod1,
            estimariprod1.codestimareprod
           FROM martor.estimariprod1
          GROUP BY estimariprod1.codestimareprod) es1 ON es1.codestimareprod = es.codestimareprod;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_expertdefecte</obj_name>
  <obj_hashval>e0813bcfc092b7b56f9f4491e2f02df2</obj_hashval>
  <obj_text>WITH exp AS (
         SELECT DISTINCT c_pg.codexpert,
            c_pg.cate,
            c_pg.coddoc,
            c_pg.tipdoc,
            c_pg.indexlocal,
            c_pg.gest,
            c_pg.subunitatea,
            c_pg.contd,
            c_pg.contc,
            c_pg.codcentru,
            c_pg.codanalizanod,
            sum(c_pg.arejurn) AS arejurn,
            sum(c_pg.areexp) AS areexp,
            sum(c_pg.difjurn) AS difjurn
           FROM ( SELECT b_pg.codexpert,
                    b_pg.cate,
                    b_pg.coddoc,
                    b_pg.tipdoc,
                    b_pg.indexlocal,
                    b_pg.gest,
                    b_pg.subunitatea,
                    b_pg.contd,
                    b_pg.contc,
                    b_pg.codcentru,
                    b_pg.codanalizanod,
                        CASE
                            WHEN b_pg.valjurn = 0::numeric THEN 0
                            ELSE 1
                        END AS arejurn,
                        CASE
                            WHEN b_pg.valexpert = 0::numeric THEN 0
                            ELSE 1
                        END AS areexp,
                        CASE
                            WHEN b_pg.valjurn = b_pg.valexpert THEN 0
                            ELSE 1
                        END AS difjurn
                   FROM ( SELECT sum(a_pg.codexpert) AS codexpert,
                            sum(a_pg.cate) AS cate,
                            a_pg.coddoc,
                            a_pg.tipdoc,
                            a_pg.indexlocal,
                            a_pg.gest,
                            a_pg.subunitatea,
                            a_pg.contd,
                            a_pg.contc,
                            a_pg.codcentru,
                            a_pg.codanalizanod,
                            sum(a_pg.valexpert) AS valexpert,
                            sum(a_pg.valjurn) AS valjurn
                           FROM ( SELECT e1.codexpert,
                                    1 AS cate,
                                    e.coddoc,
                                    e.tipdoc,
                                    e1.indexjurn AS indexlocal,
                                    e1.gestjurn AS gest,
                                    e1.subunitjurn AS subunitatea,
                                    e1.contd,
                                    e1.contc,
                                    e1.codcentru,
                                    e1.analizanodjurn AS codanalizanod,
                                    sum(e1.valoare) AS valexpert,
                                    0 AS valjurn
                                   FROM martor.expert1 e1,
                                    martor.expert e
                                  WHERE (e.an * 12::numeric + e.luna) = martor.getanlunalucru() AND e.codanaliza = (( SELECT pkg_expert_getcodanaliza.wme_result
   FROM martor.pkg_expert_getcodanaliza(NULL::numeric, NULL::numeric) pkg_expert_getcodanaliza(wme_result, fakeparam))) AND e1.codexpert = e.codexpert
                                  GROUP BY e1.codexpert, e.coddoc, e.tipdoc, e1.indexjurn, e1.gestjurn, e1.subunitjurn, e1.contd, e1.contc, e1.codcentru, e1.analizanodjurn
                                UNION ALL
                                 SELECT 0 AS codexpert,
                                    0 AS cate,
                                    jurnal.coddoc,
                                    jurnal.tipdoc,
                                    jurnal.indexlocal,
                                    jurnal.gest,
                                    jurnal.subunitatea,
                                    jurnal.contd,
                                    jurnal.contc,
                                    jurnal.codcentru,
                                    jurnal.codanalizanod,
                                    0 AS valexpert,
                                    sum(jurnal.valoare) AS valjurn
                                   FROM martor.jurnal
                                  WHERE (jurnal.an * 12::numeric + jurnal.luna) = martor.getanlunalucru()
                                  GROUP BY jurnal.coddoc, jurnal.tipdoc, jurnal.indexlocal, jurnal.gest, jurnal.subunitatea, jurnal.contd, jurnal.contc, jurnal.codcentru, jurnal.codanalizanod
                                UNION ALL
                                 SELECT 0 AS codexpert,
                                    0 AS cate,
                                    d1.coddocsuplim AS coddoc,
                                    d.tipdoc,
                                    d1.coddocsuplim1,
                                    0,
                                    d.subunitatea,
                                    0,
                                    0,
                                    0,
                                    0,
                                    0 AS valexpert,
                                    sum(d1.valoare) AS valjurn
                                   FROM martor.docsuplim1 d1
                                     JOIN martor.docsuplim d ON d.coddocsuplim = d1.coddocsuplim
                                  WHERE (d.an * 12::numeric + d.luna) = martor.getanlunalucru()
                                  GROUP BY d1.coddocsuplim, d.tipdoc, d1.coddocsuplim1, d.subunitatea) a_pg
                          GROUP BY a_pg.coddoc, a_pg.tipdoc, a_pg.indexlocal, a_pg.gest, a_pg.subunitatea, a_pg.contd, a_pg.contc, a_pg.codcentru, a_pg.codanalizanod) b_pg
                  WHERE round(b_pg.valexpert - b_pg.valjurn, 2) &lt;&gt; 0::numeric) c_pg
          GROUP BY c_pg.codexpert, c_pg.cate, c_pg.coddoc, c_pg.tipdoc, c_pg.indexlocal, c_pg.gest, c_pg.subunitatea, c_pg.contd, c_pg.contc, c_pg.codcentru, c_pg.codanalizanod
        )
 SELECT codunic,
    coddoc,
    tipdoc,
    indexlocal,
    datadoc,
    document,
    obs,
    den_subunit,
    numedoc,
    arejurn,
    areexp,
    difjurn,
        CASE
            WHEN cate &gt; 0 THEN codexpert / cate::numeric
            ELSE 0::numeric
        END AS codexpert,
    contd,
    contc,
    gest,
    codcentru,
    codanalizanod,
    valoare,
    valoarev,
    subunitatea
   FROM ( SELECT row_number() OVER () AS codunic,
            e.coddoc,
            e.tipdoc,
            e.indexlocal,
            COALESCE(j.datadoc, d.datadoc) AS datadoc,
            COALESCE(j.document, d.dendoc) AS document,
            COALESCE(j.obs, d.nrdoc::character varying) AS obs,
            s.den_subunit,
            martor.pkg_list_base_utils_decode_tipdoc(e.tipdoc) AS numedoc,
            e.arejurn,
            e.areexp,
            e.difjurn,
            e.codexpert,
            e.cate,
            e.contd,
            e.contc,
            e.gest,
            e.codcentru,
            e.codanalizanod,
            COALESCE(j.valoare, 0::numeric) AS valoare,
            0 AS valoarev,
            e.subunitatea
           FROM exp e
             LEFT JOIN martor.nsubunit s ON s.codsubunit = e.subunitatea
             LEFT JOIN martor.jurnal j ON j.coddoc = e.coddoc AND j.tipdoc = e.tipdoc AND j.indexlocal = e.indexlocal AND j.gest = e.gest AND j.subunitatea = e.subunitatea AND j.contd = e.contd AND j.contc = e.contc AND j.codcentru = e.codcentru AND j.codanalizanod = e.codanalizanod AND (j.an * 12::numeric + j.luna) = martor.getanlunalucru()
             LEFT JOIN martor.docsuplim d ON d.tipdoc = e.tipdoc AND d.coddocsuplim = e.coddoc) d_pg
  WHERE (( SELECT pkg_expert_gettipanaliza.wme_result
           FROM martor.pkg_expert_gettipanaliza(NULL::numeric, NULL::numeric) pkg_expert_gettipanaliza(wme_result, fakeparam))) = 0::numeric AND tipdoc &lt;&gt; 32::numeric OR tipdoc = (( SELECT pkg_expert_gettipanaliza.wme_result
           FROM martor.pkg_expert_gettipanaliza(NULL::numeric, NULL::numeric) pkg_expert_gettipanaliza(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_expertincomplete</obj_name>
  <obj_hashval>6b7d6854debbd873022507234fef0448</obj_hashval>
  <obj_text>WITH exp AS (
         SELECT DISTINCT c_pg.codexpert1,
            c_pg.codexpert,
            c_pg.coddoc,
            c_pg.tipdoc,
            c_pg.indexlocal,
            c_pg.gest,
            c_pg.subunitatea,
            c_pg.contd,
            c_pg.contc,
            c_pg.codcentru,
            c_pg.codanalizanod,
            sum(c_pg.arejurn) AS arejurn,
            sum(c_pg.areexp) AS areexp,
            sum(c_pg.difjurn) AS difjurn
           FROM ( SELECT b_pg.codexpert1,
                    b_pg.codexpert,
                    b_pg.coddoc,
                    b_pg.tipdoc,
                    b_pg.indexlocal,
                    b_pg.gest,
                    b_pg.subunitatea,
                    b_pg.contd,
                    b_pg.contc,
                    b_pg.codcentru,
                    b_pg.codanalizanod,
                        CASE
                            WHEN b_pg.valjurn = 0 THEN 0
                            ELSE 1
                        END AS arejurn,
                        CASE
                            WHEN b_pg.valexpert = 0::numeric THEN 0
                            ELSE 1
                        END AS areexp,
                        CASE
                            WHEN b_pg.valjurn::numeric = b_pg.valexpert THEN 0
                            ELSE 1
                        END AS difjurn
                   FROM ( SELECT sum(a_pg.codexpert1) AS codexpert1,
                            sum(a_pg.codexpert) AS codexpert,
                            a_pg.coddoc,
                            a_pg.tipdoc,
                            a_pg.indexlocal,
                            a_pg.gest,
                            a_pg.subunitatea,
                            a_pg.contd,
                            a_pg.contc,
                            a_pg.codcentru,
                            a_pg.codanalizanod,
                            sum(a_pg.valexpert) AS valexpert,
                            sum(a_pg.valjurn) AS valjurn
                           FROM ( SELECT e1.codexpert1,
                                    e1.codexpert,
                                    e.coddoc,
                                    e.tipdoc,
                                    e1.indexjurn AS indexlocal,
                                    e1.gestjurn AS gest,
                                    e1.subunitjurn AS subunitatea,
                                    e1.contd,
                                    e1.contc,
                                    e1.codcentru,
                                    e1.analizanodjurn AS codanalizanod,
                                    sum(e1.valoare) AS valexpert,
                                    0 AS valjurn
                                   FROM martor.expert1 e1,
                                    martor.expert e
                                  WHERE (e.an * 12::numeric + e.luna) = martor.getanlunalucru() AND e.codanaliza = (( SELECT pkg_expert_getcodanaliza.wme_result
   FROM martor.pkg_expert_getcodanaliza(NULL::numeric, NULL::numeric) pkg_expert_getcodanaliza(wme_result, fakeparam))) AND e1.codexpert = e.codexpert AND COALESCE(e1.codanalizanod, 0::numeric) = 0::numeric
                                  GROUP BY e1.codexpert1, e1.codexpert, e.coddoc, e.tipdoc, e1.indexjurn, e1.gestjurn, e1.subunitjurn, e1.contd, e1.contc, e1.codcentru, e1.analizanodjurn) a_pg
                          GROUP BY a_pg.coddoc, a_pg.tipdoc, a_pg.indexlocal, a_pg.gest, a_pg.subunitatea, a_pg.contd, a_pg.contc, a_pg.codcentru, a_pg.codanalizanod) b_pg) c_pg
          GROUP BY c_pg.codexpert1, c_pg.codexpert, c_pg.coddoc, c_pg.tipdoc, c_pg.indexlocal, c_pg.gest, c_pg.subunitatea, c_pg.contd, c_pg.contc, c_pg.codcentru, c_pg.codanalizanod
        )
 SELECT codunic AS "CODUNIC",
    coddoc AS "CODDOC",
    tipdoc AS "TIPDOC",
    indexlocal AS "INDEXLOCAL",
    datadoc AS "DATADOC",
    document AS "DOCUMENT",
    obs AS "OBS",
    den_subunit AS "DEN_SUBUNIT",
    numedoc AS "NUMEDOC",
    arejurn AS "AREJURN",
    areexp AS "AREEXP",
    difjurn AS "DIFJURN",
    codexpert1 AS "CODEXPERT1",
    codexpert AS "CODEXPERT",
    contd AS "CONTD",
    contc AS "CONTC",
    gest AS "GEST",
    codcentru AS "CODCENTRU",
    codanalizanod AS "CODANALIZANOD",
    valoare AS "VALOARE",
    valoarev AS "VALOAREV",
    subunitatea AS "SUBUNITATEA"
   FROM ( SELECT row_number() OVER () AS codunic,
            e.coddoc,
            e.tipdoc,
            e.indexlocal,
            COALESCE(j.datadoc, d.datadoc) AS datadoc,
            COALESCE(j.document, d.dendoc) AS document,
            COALESCE(j.obs, d.nrdoc::character varying) AS obs,
            s.den_subunit,
            martor.pkg_list_base_utils_decode_tipdoc(e.tipdoc) AS numedoc,
            e.arejurn,
            e.areexp,
            e.difjurn,
            e.codexpert1,
            e.codexpert,
            e.contd,
            e.contc,
            e.gest,
            e.codcentru,
            e.codanalizanod,
            COALESCE(j.valoare, 0::numeric) AS valoare,
            0 AS valoarev,
            e.subunitatea
           FROM exp e
             LEFT JOIN martor.nsubunit s ON s.codsubunit = e.subunitatea
             LEFT JOIN martor.jurnal j ON j.coddoc = e.coddoc AND j.tipdoc = e.tipdoc AND j.indexlocal = e.indexlocal AND j.gest = e.gest AND j.subunitatea = e.subunitatea AND j.contd = e.contd AND j.contc = e.contc AND j.codcentru = e.codcentru AND j.codanalizanod = e.codanalizanod AND (j.an * 12::numeric + j.luna) = martor.getanlunalucru()
             LEFT JOIN martor.docsuplim d ON d.tipdoc = e.tipdoc AND d.coddocsuplim = e.coddoc) d_pg
  WHERE (( SELECT pkg_expert_gettipanaliza.wme_result
           FROM martor.pkg_expert_gettipanaliza(NULL::numeric, NULL::numeric) pkg_expert_gettipanaliza(wme_result, fakeparam))) = 0::numeric AND tipdoc &lt;&gt; 32::numeric OR tipdoc = (( SELECT pkg_expert_gettipanaliza.wme_result
           FROM martor.pkg_expert_gettipanaliza(NULL::numeric, NULL::numeric) pkg_expert_gettipanaliza(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_ioart</obj_name>
  <obj_hashval>0a0f73514fa6ff6e03dbec1c7fda5dc2</obj_hashval>
  <obj_text>SELECT i.codioart,
    i.den_ioart,
    i.simbol,
    COALESCE(( SELECT max(i1.anstart * 12::numeric + i1.lunastart) AS max
           FROM martor.ioart1 i1
          WHERE i1.codioart = i.codioart AND (i1.anstart * 12::numeric + i1.lunastart) &lt;= ((( SELECT pkg_globals_getanlucru.wme_result
                   FROM martor.pkg_globals_getanlucru(NULL::numeric, NULL::numeric) pkg_globals_getanlucru(wme_result, fakeparam))) * 12::numeric + (( SELECT pkg_globals_getlunalucru.wme_result
                   FROM martor.pkg_globals_getlunalucru(NULL::numeric, NULL::numeric) pkg_globals_getlunalucru(wme_result, fakeparam))))), 0::numeric) AS activ,
    ( SELECT pkg_planconturi_getsimbolcont.wme_result
           FROM martor.pkg_planconturi_getsimbolcont(NULL::character varying, COALESCE(ioaluna.cont, 0::numeric)) pkg_planconturi_getsimbolcont(wme_result, cont)) AS simbolcont,
    ioaluna.mg,
    i.codvanzare,
    ioaluna.descarcareg,
        CASE ioaluna.mg
            WHEN 1 THEN 'FIFO - primul intrat, primul iesit'::text
            WHEN 2 THEN 'LIFO - ultimul intrat, primul iesit'::text
            WHEN 3 THEN 'PMP - pret mediu ponderat'::text
            WHEN 4 THEN 'IDS - identificare specifica'::text
            WHEN 5 THEN 'VALORIC - fara evidenta cantitativa'::text
            ELSE ''::text
        END::character varying AS metoda_gest,
    ( SELECT count(*) AS count
           FROM martor.ioartlink il
          WHERE il.codioart = i.codioart) AS nrlinkuri
   FROM martor.ioart i
     LEFT JOIN ( SELECT io1.codioart,
            io1.cont,
            io1.mg,
            io1.descarcareg
           FROM martor.ioart1 io1
          WHERE (io1.anstart * 12::numeric + io1.lunastart) = (( SELECT max(io2.anstart * 12::numeric + io2.lunastart) AS max
                   FROM martor.ioart1 io2
                  WHERE io2.codioart = io1.codioart AND (io2.anstart * 12::numeric + io2.lunastart) &lt;= ((( SELECT pkg_globals_getanlucru.wme_result
                           FROM martor.pkg_globals_getanlucru(NULL::numeric, NULL::numeric) pkg_globals_getanlucru(wme_result, fakeparam))) * 12::numeric + (( SELECT pkg_globals_getlunalucru.wme_result
                           FROM martor.pkg_globals_getlunalucru(NULL::numeric, NULL::numeric) pkg_globals_getlunalucru(wme_result, fakeparam))))))) ioaluna ON ioaluna.codioart = i.codioart;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_ioart_mf</obj_name>
  <obj_hashval>02a4387b6ea3b72a423d654a3c5adcd8</obj_hashval>
  <obj_text>SELECT i.codioart,
    i.den_ioart,
    i.simbol,
    COALESCE(( SELECT max(i1.anstart * 12::numeric + i1.lunastart) AS max
           FROM martor.ioart1 i1
          WHERE i1.codioart = i.codioart AND (i1.anstart * 12::numeric + i1.lunastart) &lt;= (( SELECT pkg_globals_anlunalucru.wme_result
                   FROM martor.pkg_globals_anlunalucru(NULL::numeric, NULL::numeric) pkg_globals_anlunalucru(wme_result, fakeparam)))), 0::numeric) AS activ,
    ( SELECT pkg_planconturi_getsimbolcont.wme_result
           FROM martor.pkg_planconturi_getsimbolcont(NULL::character varying, COALESCE(ioaluna.cont, 0::numeric)) pkg_planconturi_getsimbolcont(wme_result, cont)) AS simbolcont,
    ioaluna.mg,
    i.codvanzare,
    ioaluna.descarcareg,
        CASE ioaluna.mg
            WHEN 1 THEN 'FIFO - primul intrat, primul iesit'::text
            WHEN 2 THEN 'LIFO - ultimul intrat, primul iesit'::text
            WHEN 3 THEN 'PMP - pret mediu ponderat'::text
            WHEN 4 THEN 'IDS - identificare specifica'::text
            WHEN 5 THEN 'VALORIC - fara evidenta cantitativa'::text
            ELSE ''::text
        END AS metoda_gest,
    ( SELECT count(*) AS count
           FROM martor.ioartlink il
          WHERE il.codioart = i.codioart) AS nrlinkuri,
    ( SELECT pkg_categconst_estemifix.wme_result
           FROM martor.pkg_categconst_estemifix(NULL::numeric, ioaluna.cont) pkg_categconst_estemifix(wme_result, acodcont)) AS tipmf,
    ( SELECT pkg_categconst_esteimbunatatiremifix.wme_result
           FROM martor.pkg_categconst_esteimbunatatiremifix(NULL::numeric, ioaluna.cont) pkg_categconst_esteimbunatatiremifix(wme_result, acodcont)) AS tipimob
   FROM martor.ioart i
     LEFT JOIN ( SELECT io1.codioart,
            io1.cont,
            io1.mg,
            io1.descarcareg
           FROM martor.ioart1 io1
          WHERE (io1.anstart * 12::numeric + io1.lunastart) = (( SELECT max(io2.anstart * 12::numeric + io2.lunastart) AS max
                   FROM martor.ioart1 io2
                  WHERE io2.codioart = io1.codioart AND (io2.anstart * 12::numeric + io2.lunastart) &lt;= (( SELECT pkg_globals_anlunalucru.wme_result
                           FROM martor.pkg_globals_anlunalucru(NULL::numeric, NULL::numeric) pkg_globals_anlunalucru(wme_result, fakeparam)))))) ioaluna ON ioaluna.codioart = i.codioart
  WHERE (( SELECT pkg_categconst_estemifix.wme_result
           FROM martor.pkg_categconst_estemifix(NULL::numeric, ioaluna.cont) pkg_categconst_estemifix(wme_result, acodcont))) &gt; 0::numeric OR (( SELECT pkg_categconst_esteimbunatatiremifix.wme_result
           FROM martor.pkg_categconst_esteimbunatatiremifix(NULL::numeric, ioaluna.cont) pkg_categconst_esteimbunatatiremifix(wme_result, acodcont))) &gt; 0::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_ioart1_lunalucru</obj_name>
  <obj_hashval>6928aded144363dcd3d8fe77bf1bcc9d</obj_hashval>
  <obj_text>SELECT i1.codioart1,
    i1.codioart,
    i1.cont,
    i1.diferente,
    i1.cheltuieli,
    i1.venituri,
    i1.plusinventar,
    i1.minusinventar,
    i1.chelttvacolectat,
    i1.controtunjiri,
    i1.diverse,
    i1.custodie,
    i1.accizelatransfer,
    i1.descarcareg,
    i1.contabgest,
    i1.baza,
    i1.difpret,
    i1.aretvaneex,
    i1.tvaneex,
    i1.mg,
    i1.anstart,
    i1.lunastart,
    i1.pustandard,
    io.codvanzare,
    ( SELECT count(*) AS count
           FROM martor.ioartlink il
          WHERE il.codioart = io.codioart) AS nrlinkuri
   FROM martor.ioart1 i1,
    martor.ioart io
  WHERE (i1.anstart * 12::numeric + i1.lunastart) = (( SELECT max(i2.anstart * 12::numeric + i2.lunastart) AS max
           FROM martor.ioart1 i2
          WHERE i2.codioart = i1.codioart AND (i2.anstart * 12::numeric + i2.lunastart) &lt;= (( SELECT pkg_globals_anlunalucru.wme_result
                   FROM martor.pkg_globals_anlunalucru(NULL::numeric, NULL::numeric) pkg_globals_anlunalucru(wme_result, fakeparam))))) AND io.codioart = i1.codioart;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_iobank</obj_name>
  <obj_hashval>e207118ce8724b99ea5ecf74d232d4c0</obj_hashval>
  <obj_text>SELECT DISTINCT i.codiobank,
    i.den_iobank,
    COALESCE(( SELECT max(i1_1.anstart * 12::numeric + i1_1.lunastart) AS max
           FROM martor.iobank1 i1_1
          WHERE i1_1.codiobank = i.codiobank AND (i1_1.anstart * 12::numeric + i1_1.lunastart) &lt;= martor.getanlunalucru()), 0::numeric) AS activ,
    last_value(nc.simbol) OVER (PARTITION BY i1.codiobank ORDER BY (i1.anstart * 12::numeric + i1.lunastart) RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS cont
   FROM martor.iobank i
     LEFT JOIN martor.iobank1 i1 ON i.codiobank = i1.codiobank
     LEFT JOIN martor.ncont nc ON nc.codcont = i1.cont
  WHERE i1.codiobank IS NULL OR (i1.anstart * 12::numeric + i1.lunastart) &lt;= martor.getanlunalucru();</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_iopart</obj_name>
  <obj_hashval>59af6411f3daf4306b77fc586b3c4564</obj_hashval>
  <obj_text>SELECT i.codiopart,
    i.den_iopart,
    COALESCE(( SELECT max(i1.anstart * 12::numeric + i1.lunastart) AS max
           FROM martor.iopart1 i1
          WHERE i1.codiopart = i.codiopart AND (i1.anstart * 12::numeric + i1.lunastart) &lt;= (( SELECT pkg_globals_anlunalucru.wme_result
                   FROM martor.pkg_globals_anlunalucru(NULL::numeric, NULL::numeric) pkg_globals_anlunalucru(wme_result, fakeparam)))), 0::numeric) AS activ,
    ( SELECT pkg_planconturi_getsimbolcont.wme_result
           FROM martor.pkg_planconturi_getsimbolcont(NULL::character varying, COALESCE(iopartluna.contfurnizor, 0::numeric)) pkg_planconturi_getsimbolcont(wme_result, cont)) AS simbcontfurnizor,
    ( SELECT pkg_planconturi_getsimbolcont.wme_result
           FROM martor.pkg_planconturi_getsimbolcont(NULL::character varying, COALESCE(iopartluna.contclient, 0::numeric)) pkg_planconturi_getsimbolcont(wme_result, cont)) AS simbcontclient,
    ( SELECT pkg_planconturi_getsimbolcont.wme_result
           FROM martor.pkg_planconturi_getsimbolcont(NULL::character varying, COALESCE(iopartluna.contfurnavans, 0::numeric)) pkg_planconturi_getsimbolcont(wme_result, cont)) AS simbcontfurnavans,
    ( SELECT pkg_planconturi_getsimbolcont.wme_result
           FROM martor.pkg_planconturi_getsimbolcont(NULL::character varying, COALESCE(iopartluna.contclientavans, 0::numeric)) pkg_planconturi_getsimbolcont(wme_result, cont)) AS simbcontclientavans,
    ( SELECT pkg_planconturi_getsimbolcont.wme_result
           FROM martor.pkg_planconturi_getsimbolcont(NULL::character varying, COALESCE(iopartluna.contfurnaviz, 0::numeric)) pkg_planconturi_getsimbolcont(wme_result, cont)) AS simbcontfurnaviz,
    ( SELECT pkg_planconturi_getsimbolcont.wme_result
           FROM martor.pkg_planconturi_getsimbolcont(NULL::character varying, COALESCE(iopartluna.contclientaviz, 0::numeric)) pkg_planconturi_getsimbolcont(wme_result, cont)) AS simbcontclientaviz
   FROM martor.iopart i
     LEFT JOIN ( SELECT io1.codiopart1,
            io1.codiopart,
            io1.contfurnizor,
            io1.contclient,
            io1.contfurnavans,
            io1.contclientavans,
            io1.contfurnaviz,
            io1.contclientaviz,
            io1.contfurnmf,
            io1.contcreditd,
            io1.contdebitd,
            io1.contlitigii,
            io1.contfurnavs,
            io1.contfurnavic,
            io1.contfurnavin,
            io1.contterti,
            io1.contfurnleas,
            io1.contncrf,
            io1.contncrc,
            io1.contcheltavans,
            io1.contvenitavans,
            io1.contgarantieef,
            io1.contgarantietf,
            io1.contgarantieec,
            io1.contgarantietc,
            io1.contsuplimf1,
            io1.contsuplimf2,
            io1.contsuplimf3,
            io1.contsuplimf4,
            io1.contsuplimf5,
            io1.contsuplimc1,
            io1.contsuplimc2,
            io1.contsuplimc3,
            io1.contsuplimc4,
            io1.contsuplimc5,
            io1.contsuplimf6,
            io1.contsuplimf7,
            io1.contsuplimf8,
            io1.contsuplimf9,
            io1.contsuplimf10,
            io1.contsuplimf11,
            io1.contsuplimf12,
            io1.contsuplimf13,
            io1.contsuplimf14,
            io1.contsuplimf15,
            io1.contsuplimf16,
            io1.contsuplimf17,
            io1.contsuplimf18,
            io1.contsuplimf19,
            io1.contsuplimf20,
            io1.contsuplimf21,
            io1.contsuplimf22,
            io1.contsuplimf23,
            io1.contsuplimf24,
            io1.contsuplimf25,
            io1.contsuplimf26,
            io1.contsuplimf27,
            io1.contsuplimf28,
            io1.contsuplimf29,
            io1.contsuplimf30,
            io1.tvaneexf,
            io1.tvaneexc,
            io1.tvaneexp,
            io1.tvaneexi,
            io1.tip,
            io1.anstart,
            io1.lunastart
           FROM martor.iopart1 io1
          WHERE (io1.anstart * 12::numeric + io1.lunastart) = (( SELECT max(io2.anstart * 12::numeric + io2.lunastart) AS max
                   FROM martor.iopart1 io2
                  WHERE io2.codiopart = io1.codiopart AND (io2.anstart * 12::numeric + io2.lunastart) &lt;= (( SELECT pkg_globals_anlunalucru.wme_result
                           FROM martor.pkg_globals_anlunalucru(NULL::numeric, NULL::numeric) pkg_globals_anlunalucru(wme_result, fakeparam)))))) iopartluna ON iopartluna.codiopart = i.codiopart
  WHERE (( SELECT pkg_configpart_cod_iopart_editat_valid.wme_result
           FROM martor.pkg_configpart_cod_iopart_editat_valid(NULL::numeric, i.codiopart) pkg_configpart_cod_iopart_editat_valid(wme_result, acodpart))) = 1::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_iopers</obj_name>
  <obj_hashval>32899a57bc73ce96f705465132dcbcc3</obj_hashval>
  <obj_text>SELECT i.codiopers,
    i.den_iopers,
    COALESCE(( SELECT max(i1.anstart * 12::numeric + i1.lunastart) AS max
           FROM martor.iopers1 i1
          WHERE i1.codiopers = i.codiopers AND (i1.anstart * 12::numeric + i1.lunastart) &lt;= (( SELECT pkg_globals_anlunalucru.wme_result
                   FROM martor.pkg_globals_anlunalucru(NULL::numeric, NULL::numeric) pkg_globals_anlunalucru(wme_result, fakeparam)))), 0::numeric) AS activ,
    ( SELECT pkg_planconturi_getsimbolcont.wme_result
           FROM martor.pkg_planconturi_getsimbolcont(NULL::character varying, COALESCE(iopersluna.contavansdecont, 0::numeric)) pkg_planconturi_getsimbolcont(wme_result, cont)) AS cavansdecont,
    ( SELECT pkg_planconturi_getsimbolcont.wme_result
           FROM martor.pkg_planconturi_getsimbolcont(NULL::character varying, COALESCE(iopersluna.contimputatii, 0::numeric)) pkg_planconturi_getsimbolcont(wme_result, cont)) AS cimputatii,
    ( SELECT pkg_planconturi_getsimbolcont.wme_result
           FROM martor.pkg_planconturi_getsimbolcont(NULL::character varying, COALESCE(iopersluna.contgarantii, 0::numeric)) pkg_planconturi_getsimbolcont(wme_result, cont)) AS cgarantii,
    ( SELECT pkg_planconturi_getsimbolcont.wme_result
           FROM martor.pkg_planconturi_getsimbolcont(NULL::character varying, COALESCE(iopersluna.contalteretineri, 0::numeric)) pkg_planconturi_getsimbolcont(wme_result, cont)) AS calte
   FROM martor.iopers i
     LEFT JOIN ( SELECT io1.codiopers1,
            io1.codiopers,
            io1.contavansdecont,
            io1.contimputatii,
            io1.contgarantii,
            io1.contalteretineri,
            io1.contavans,
            io1.contliki,
            io1.contneridicate,
            io1.contboala,
            io1.contpartsal,
            io1.contnatura,
            io1.contechipament,
            io1.contimpozit,
            io1.anstart,
            io1.lunastart
           FROM martor.iopers1 io1
          WHERE (io1.anstart * 12::numeric + io1.lunastart) = (( SELECT max(io2.anstart * 12::numeric + io2.lunastart) AS max
                   FROM martor.iopers1 io2
                  WHERE io2.codiopers = io1.codiopers AND (io2.anstart * 12::numeric + io2.lunastart) &lt;= (( SELECT pkg_globals_anlunalucru.wme_result
                           FROM martor.pkg_globals_anlunalucru(NULL::numeric, NULL::numeric) pkg_globals_anlunalucru(wme_result, fakeparam)))))) iopersluna ON iopersluna.codiopers = i.codiopers;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_jurnal</obj_name>
  <obj_hashval>2be82b9f8d5ef67c7d6d7c1f323e515c</obj_hashval>
  <obj_text>SELECT 1 AS tipinreg,
    j.codcentru AS centrucost,
    cd.simbol AS simbcontdebit,
    cc.simbol AS simbconcredit,
    j.valoare AS v,
    j.codjurnal,
    j.coddoc,
    j.tipdoc,
    j.indexlocal,
    j.contd,
    j.contc,
    j.gest,
    j.valoare,
    j.valoarev,
    j.obs,
    j.an,
    j.luna,
    j.subunitatea,
    j.datadoc,
    j.document,
    j.codcentru,
    j.valoaregrup,
    j.valoare_ifrs,
    j.valoarev_ifrs
   FROM martor.jurnal j
     JOIN martor.ncont cd ON cd.codcont = j.contd
     JOIN martor.ncont cc ON cc.codcont = j.contc
  WHERE (j.an * 12::numeric + j.luna) &gt;= (( SELECT pkg_list_base_regjurnal_lunaini.wme_result
           FROM martor.pkg_list_base_regjurnal_lunaini(NULL::numeric, NULL::numeric) pkg_list_base_regjurnal_lunaini(wme_result, fakeparam))) AND (j.an * 12::numeric + j.luna) &lt;= (( SELECT pkg_list_base_regjurnal_lunafin.wme_result
           FROM martor.pkg_list_base_regjurnal_lunafin(NULL::numeric, NULL::numeric) pkg_list_base_regjurnal_lunafin(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_jurnal_s</obj_name>
  <obj_hashval>eb812fa64bbaf4c91bf51a88d3b7c2ad</obj_hashval>
  <obj_text>SELECT 2 AS tipinreg,
        CASE
            WHEN COALESCE(c1d.codcentrus, 0::numeric) &lt;&gt; 0::numeric THEN c1d.codcentrus
            WHEN COALESCE(c1c.codcentrus, 0::numeric) &lt;&gt; 0::numeric THEN c1c.codcentrus
            ELSE COALESCE(j.codcentru, 0::numeric)
        END AS centrucost,
    cd.simbol AS simbcontdebit,
    cc.simbol AS simbconcredit,
    j.valoare AS v,
    j.codjurnal,
    j.coddoc,
    j.tipdoc,
    j.indexlocal,
    j.contd,
    j.contc,
    j.gest,
    j.valoare,
    j.valoarev,
    j.obs,
    j.an,
    j.luna,
    j.subunitatea,
    j.datadoc,
    j.document,
    j.codcentru,
    j.valoaregrup,
    j.valoare_ifrs,
    j.valoarev_ifrs
   FROM martor.jurnal j
     JOIN martor.ncont1 c1d ON c1d.codcont1 = (( SELECT pkg_planconturi_get_cont_cod_caract_luna.wme_result
           FROM martor.pkg_planconturi_get_cont_cod_caract_luna(NULL::numeric, j.contd, j.an, j.luna) pkg_planconturi_get_cont_cod_caract_luna(wme_result, acodcont, aan, aluna)))
     JOIN martor.ncont1 c1c ON c1c.codcont1 = (( SELECT pkg_planconturi_get_cont_cod_caract_luna.wme_result
           FROM martor.pkg_planconturi_get_cont_cod_caract_luna(NULL::numeric, j.contc, j.an, j.luna) pkg_planconturi_get_cont_cod_caract_luna(wme_result, acodcont, aan, aluna)))
     JOIN martor.nconts cd ON cd.codconts = c1d.contsecundar
     JOIN martor.nconts cc ON cc.codconts = c1c.contsecundar
  WHERE (j.an * 12::numeric + j.luna) &gt;= (( SELECT pkg_list_base_regjurnal_lunaini.wme_result
           FROM martor.pkg_list_base_regjurnal_lunaini(NULL::numeric, NULL::numeric) pkg_list_base_regjurnal_lunaini(wme_result, fakeparam))) AND (j.an * 12::numeric + j.luna) &lt;= (( SELECT pkg_list_base_regjurnal_lunafin.wme_result
           FROM martor.pkg_list_base_regjurnal_lunafin(NULL::numeric, NULL::numeric) pkg_list_base_regjurnal_lunafin(wme_result, fakeparam))) AND COALESCE(c1d.contsecundar, 0::numeric) &gt; 0::numeric AND COALESCE(c1c.contsecundar, 0::numeric) &gt; 0::numeric AND (EXISTS ( SELECT 1
           FROM martor.nconts1 cs1d
          WHERE cs1d.codconts = cd.codconts AND (cs1d.anstart * 12::numeric + cs1d.lunastart) &lt;= (( SELECT pkg_list_base_regjurnal_lunafin.wme_result
                   FROM martor.pkg_list_base_regjurnal_lunafin(NULL::numeric, NULL::numeric) pkg_list_base_regjurnal_lunafin(wme_result, fakeparam))))) AND (EXISTS ( SELECT 1
           FROM martor.nconts1 cs1c
          WHERE cs1c.codconts = cc.codconts AND (cs1c.anstart * 12::numeric + cs1c.lunastart) &lt;= (( SELECT pkg_list_base_regjurnal_lunafin.wme_result
                   FROM martor.pkg_list_base_regjurnal_lunafin(NULL::numeric, NULL::numeric) pkg_list_base_regjurnal_lunafin(wme_result, fakeparam)))))
UNION ALL
 SELECT 3 AS tipinreg,
        CASE
            WHEN COALESCE(c1d.codcentrusg, 0::numeric) &lt;&gt; 0::numeric THEN c1d.codcentrusg
            WHEN COALESCE(c1c.codcentrusg, 0::numeric) &lt;&gt; 0::numeric THEN c1c.codcentrusg
            ELSE COALESCE(j.codcentru, 0::numeric)
        END AS centrucost,
    cd.simbol AS simbcontdebit,
    cc.simbol AS simbconcredit,
    COALESCE(j.valoaregrup, j.valoare) AS v,
    j.codjurnal,
    j.coddoc,
    j.tipdoc,
    j.indexlocal,
    j.contd,
    j.contc,
    j.gest,
    j.valoare,
    j.valoarev,
    j.obs,
    j.an,
    j.luna,
    j.subunitatea,
    j.datadoc,
    j.document,
    j.codcentru,
    j.valoaregrup,
    j.valoare_ifrs,
    j.valoarev_ifrs
   FROM martor.jurnal j
     JOIN martor.ncont1 c1d ON c1d.codcont1 = (( SELECT pkg_planconturi_get_cont_cod_caract_luna.wme_result
           FROM martor.pkg_planconturi_get_cont_cod_caract_luna(NULL::numeric, j.contd, j.an, j.luna) pkg_planconturi_get_cont_cod_caract_luna(wme_result, acodcont, aan, aluna)))
     JOIN martor.ncont1 c1c ON c1c.codcont1 = (( SELECT pkg_planconturi_get_cont_cod_caract_luna.wme_result
           FROM martor.pkg_planconturi_get_cont_cod_caract_luna(NULL::numeric, j.contc, j.an, j.luna) pkg_planconturi_get_cont_cod_caract_luna(wme_result, acodcont, aan, aluna)))
     JOIN martor.nconts cd ON cd.codconts = c1d.contsecundarg
     JOIN martor.nconts cc ON cc.codconts = c1c.contsecundarg
  WHERE (j.an * 12::numeric + j.luna) &gt;= (( SELECT pkg_list_base_regjurnal_lunaini.wme_result
           FROM martor.pkg_list_base_regjurnal_lunaini(NULL::numeric, NULL::numeric) pkg_list_base_regjurnal_lunaini(wme_result, fakeparam))) AND (j.an * 12::numeric + j.luna) &lt;= (( SELECT pkg_list_base_regjurnal_lunafin.wme_result
           FROM martor.pkg_list_base_regjurnal_lunafin(NULL::numeric, NULL::numeric) pkg_list_base_regjurnal_lunafin(wme_result, fakeparam))) AND COALESCE(c1d.contsecundarg, 0::numeric) &gt; 0::numeric AND COALESCE(c1c.contsecundarg, 0::numeric) &gt; 0::numeric AND (EXISTS ( SELECT 1
           FROM martor.nconts1 cs1d
          WHERE cs1d.codconts = cd.codconts AND (cs1d.anstart * 12::numeric + cs1d.lunastart) &lt;= (( SELECT pkg_list_base_regjurnal_lunafin.wme_result
                   FROM martor.pkg_list_base_regjurnal_lunafin(NULL::numeric, NULL::numeric) pkg_list_base_regjurnal_lunafin(wme_result, fakeparam))))) AND (EXISTS ( SELECT 1
           FROM martor.nconts1 cs1c
          WHERE cs1c.codconts = cc.codconts AND (cs1c.anstart * 12::numeric + cs1c.lunastart) &lt;= (( SELECT pkg_list_base_regjurnal_lunafin.wme_result
                   FROM martor.pkg_list_base_regjurnal_lunafin(NULL::numeric, NULL::numeric) pkg_list_base_regjurnal_lunafin(wme_result, fakeparam)))))
UNION ALL
 SELECT 4 AS tipinreg,
        CASE
            WHEN COALESCE(c1d.codcentrusgo, 0::numeric) &lt;&gt; 0::numeric THEN c1d.codcentrusgo
            WHEN COALESCE(c1c.codcentrusgo, 0::numeric) &lt;&gt; 0::numeric THEN c1c.codcentrusgo
            ELSE COALESCE(j.codcentru, 0::numeric)
        END AS centrucost,
    cd.simbol AS simbcontdebit,
    cc.simbol AS simbconcredit,
    COALESCE(j.valoaregrup, j.valoare) AS v,
    j.codjurnal,
    j.coddoc,
    j.tipdoc,
    j.indexlocal,
    j.contd,
    j.contc,
    j.gest,
    j.valoare,
    j.valoarev,
    j.obs,
    j.an,
    j.luna,
    j.subunitatea,
    j.datadoc,
    j.document,
    j.codcentru,
    j.valoaregrup,
    j.valoare_ifrs,
    j.valoarev_ifrs
   FROM martor.jurnal j
     JOIN martor.ncont1 c1d ON c1d.codcont1 = (( SELECT pkg_planconturi_get_cont_cod_caract_luna.wme_result
           FROM martor.pkg_planconturi_get_cont_cod_caract_luna(NULL::numeric, j.contc, j.an, j.luna) pkg_planconturi_get_cont_cod_caract_luna(wme_result, acodcont, aan, aluna)))
     JOIN martor.ncont1 c1c ON c1c.codcont1 = (( SELECT pkg_planconturi_get_cont_cod_caract_luna.wme_result
           FROM martor.pkg_planconturi_get_cont_cod_caract_luna(NULL::numeric, j.contd, j.an, j.luna) pkg_planconturi_get_cont_cod_caract_luna(wme_result, acodcont, aan, aluna)))
     JOIN martor.nconts cd ON cd.codconts = c1d.contsecundargo
     JOIN martor.nconts cc ON cc.codconts = c1c.contsecundargo
  WHERE (j.an * 12::numeric + j.luna) &gt;= (( SELECT pkg_list_base_regjurnal_lunaini.wme_result
           FROM martor.pkg_list_base_regjurnal_lunaini(NULL::numeric, NULL::numeric) pkg_list_base_regjurnal_lunaini(wme_result, fakeparam))) AND (j.an * 12::numeric + j.luna) &lt;= (( SELECT pkg_list_base_regjurnal_lunafin.wme_result
           FROM martor.pkg_list_base_regjurnal_lunafin(NULL::numeric, NULL::numeric) pkg_list_base_regjurnal_lunafin(wme_result, fakeparam))) AND COALESCE(c1d.contsecundargo, 0::numeric) &gt; 0::numeric AND COALESCE(c1c.contsecundargo, 0::numeric) &gt; 0::numeric AND (EXISTS ( SELECT 1
           FROM martor.nconts1 cs1d
          WHERE cs1d.codconts = cd.codconts AND (cs1d.anstart * 12::numeric + cs1d.lunastart) &lt;= (( SELECT pkg_list_base_regjurnal_lunafin.wme_result
                   FROM martor.pkg_list_base_regjurnal_lunafin(NULL::numeric, NULL::numeric) pkg_list_base_regjurnal_lunafin(wme_result, fakeparam))))) AND (EXISTS ( SELECT 1
           FROM martor.nconts1 cs1c
          WHERE cs1c.codconts = cc.codconts AND (cs1c.anstart * 12::numeric + cs1c.lunastart) &lt;= (( SELECT pkg_list_base_regjurnal_lunafin.wme_result
                   FROM martor.pkg_list_base_regjurnal_lunafin(NULL::numeric, NULL::numeric) pkg_list_base_regjurnal_lunafin(wme_result, fakeparam)))));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lansz</obj_name>
  <obj_hashval>e595dab2cdf5e0b434bc29c94d619165</obj_hashval>
  <obj_text>SELECT lz.codlansz,
    lz.saptamana,
    sub.den_subunit,
    g.den_gest,
    lz.obs,
    ( SELECT iso_week_to_date.wme_result
           FROM martor.iso_week_to_date(NULL::date, lz.an, lz.saptamana) iso_week_to_date(wme_result, pyear, pweek)) AS datastart,
    (( SELECT iso_week_to_date.wme_result
           FROM martor.iso_week_to_date(NULL::date, lz.an, lz.saptamana) iso_week_to_date(wme_result, pyear, pweek))) + 6 AS datastop,
    lz.subunitatea,
    lz.finalizat
   FROM martor.lansz lz
     JOIN martor.nsubunit sub ON sub.codsubunit = lz.subunitatea
     JOIN martor.ngest g ON lz.codgest = g.codgest
  WHERE lz.an = (( SELECT pkg_globals_getanlucru.wme_result
           FROM martor.pkg_globals_getanlucru(NULL::numeric, NULL::numeric) pkg_globals_getanlucru(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_asigurari</obj_name>
  <obj_hashval>b15a7ed59a1a767035e2aa7aa4952cfd</obj_hashval>
  <obj_text>SELECT codasigurare,
    nrdoc,
    codpart,
    datastart,
    termen,
    codclasemf,
    obs,
    subunitatea,
    userid,
    datacreare,
    an,
    luna,
    valoare
   FROM martor.asigurari
  WHERE codasigurare = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_auto</obj_name>
  <obj_hashval>3f0b22f70d4abd186f7ac2bceabb6bea</obj_hashval>
  <obj_text>SELECT codnparcaut,
    codart,
    nrinv,
    nrinreg,
    sofer,
    kmpornire,
    tip,
    datainreg,
    marca,
    model,
    anf,
    seriec,
    culoare,
    lung,
    lat,
    inalt,
    tipmotor,
    seriem,
    motor,
    cilindree,
    putere,
    cmm,
    cmu,
    cme,
    tipincarc,
    greutate,
    masam,
    masau,
    masaurdf,
    masaurfdf,
    loct,
    locf,
    locs,
    locp,
    anvrecomf,
    anvrecoms,
    anvopt1f,
    anvopt1s,
    anvopt2f,
    anvopt2s,
    kg,
    kgr,
    sarcina,
    codputere,
    grupauto,
    tiprem,
    instsp,
    aer,
    rezervor,
    volumu,
    culoarec,
    sursae
   FROM martor.nparcaut
  WHERE codnparcaut = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_bcar</obj_name>
  <obj_hashval>49cbf90090c40afc56e77351c5d7696d</obj_hashval>
  <obj_text>SELECT codbcar,
    operat,
    codcantarin,
    codcantarout,
    tipdoc,
    coddoc1,
    prefixdoc,
    nrdoc,
    datadoc,
    carnetdoc,
    prefixavizin,
    nravizin,
    nravizout,
    dataavizin,
    isumiditate,
    iaumiditate,
    isstraine,
    iastraine,
    isincoltit,
    iaincoltit,
    ishectolitrica,
    iahectolitrica,
    isgluten,
    iagluten,
    isfuzaritate,
    iafuzaritate,
    iscadere,
    iacadere,
    isdeformare,
    iadeformare,
    issticlozitate,
    iasticlozitate,
    issparturi,
    iasparturi,
    codobiect,
    brutkg,
    tara,
    netkg,
    utilkg,
    pretachiz,
    pretuscare,
    codpartener,
    codsediu,
    coddelegat,
    codsubunitate,
    userid,
    datacreare,
    codserie,
    retur,
    modcantar,
    useridblocaj,
    tipbcar,
    codgestimpl,
    codlocatimpl,
    observatii,
    codpers,
    mijltransp,
    nrtransp,
    codauto,
    icumiditate,
    icstraine,
    icincoltit,
    ichectolitrica,
    icgluten,
    icfuzaritate,
    iccadere,
    icdeformare,
    icsticlozitate,
    icsparturi,
    netkgclient,
    utilkgclient,
    infoclient,
    coddoc1storno,
    codbcardest,
    codcontract1,
    nrremorca,
    codremorca,
    utilstaskg,
    pretconfirmat,
    isproteina,
    isaflatoxina,
    isatac_plosnita,
    iscontinut_ulei,
    isaciditate,
    iaproteina,
    iaaflatoxina,
    iaatac_plosnita,
    iacontinut_ulei,
    iaaciditate,
    icproteina,
    icaflatoxina,
    icatac_plosnita,
    iccontinut_ulei,
    icaciditate
   FROM martor.bcar
  WHERE codbcar = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_cc</obj_name>
  <obj_hashval>aff042ca2cfd0fd62366b8271a9b7bbb</obj_hashval>
  <obj_text>SELECT codcentru,
    simbol,
    denumire,
    tipchelt,
    tipaloc,
    tip,
    inactiv,
    domeniu
   FROM martor.centrecost
  WHERE codcentru = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_certif</obj_name>
  <obj_hashval>13765c355629493fbf402482bff79982</obj_hashval>
  <obj_text>SELECT codcertif,
    nrcertif,
    dataprimire,
    fisier,
    codpart,
    codobiect,
    codserie,
    numefisier,
    ext,
    subunitate,
    userid,
    datacreare,
    codtara,
    provenienta,
    obs,
    tippart
   FROM martor.certif
  WHERE codcertif = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_comanda</obj_name>
  <obj_hashval>1e7d43aaaf2f84084c63bd051c36ea37</obj_hashval>
  <obj_text>SELECT codcomanda,
    tipdoc,
    anulat,
    blocat,
    operat,
    prefixdoc,
    nrdoc,
    carnetdoc,
    datadoc,
    partener,
    valoare,
    an,
    luna,
    obs,
    moneda,
    codcontract,
    codcmdparinte,
    delegat,
    agent,
    valdiscount,
    codlocatie,
    subunitatea,
    codfiscal,
    userid,
    datacreare,
    codgest,
    inchisa,
    subunitsursa,
    scadentav,
    seriadoc,
    useridblocaj,
    nri,
    codtraseulivr,
    ordinelivrare,
    mijltransp,
    insotitor,
    displivrare,
    verificat,
    codies,
    faratransport,
    platapeloc,
    datainreg,
    facturabil,
    curs,
    schimb,
    codformatie,
    idimport,
    listat,
    factura_apl_ext,
    codpers_apl_ext,
    lot,
    nrtransp,
    codiesavans,
    farafactura,
    dinonline,
    pretcuamanunt,
    codanaliza,
    tiptranzactie,
    subunitdest,
    nrmaxaprobari,
    stadiuwms,
    codpersc
   FROM martor.comanda
  WHERE codcomanda = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_compens</obj_name>
  <obj_hashval>d6c3fa91af487580ed06d8208a57404e</obj_hashval>
  <obj_text>SELECT codcompens,
    datadoc,
    carnetdoc,
    nrdoc,
    an,
    luna,
    partd,
    partc,
    obsd,
    obsc,
    subunitatea,
    userid,
    datacreare,
    codgest,
    tipcompens,
    codcentru,
    agent,
    codanaliza,
    codtippartincert
   FROM martor.compens
  WHERE codcompens = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_contracte</obj_name>
  <obj_hashval>55d4692713fabd0da63f73cb49e09dc0</obj_hashval>
  <obj_text>SELECT codcontract,
    tipdoc,
    anulat,
    blocat,
    operat,
    activ,
    carnetdoc,
    seriadoc,
    nrdoc,
    datadoc,
    datastart,
    datastop,
    tipcontract,
    tiptarget,
    partener,
    codlocatie,
    codfiscal,
    codpersc,
    moneda,
    pertarget,
    nrluni,
    perfact,
    zifact,
    procmaj,
    percitire,
    zicitire,
    transppart,
    obs,
    subunitatea,
    an,
    luna,
    userid,
    datacreare,
    agent,
    curs,
    avans,
    dobanda,
    tipdobanda,
    calcdobanda,
    reziduala,
    rezidualaseparat,
    factlei,
    asiganual,
    lunigratie,
    gratiefaradob,
    codbanca,
    procmajcurs,
    autoprelungire,
    luniprelungire,
    tiparticol,
    tipum,
    tiptargetv,
    semnat,
    explicatii,
    stopaj,
    suma1,
    discount1,
    suma2,
    discount2,
    suma3,
    discount3,
    suma4,
    discount4,
    nri,
    cass,
    codanaliza,
    maxreplsimultane,
    maxzilerepla
   FROM martor.contract
  WHERE codcontract = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_deviz_utilaj</obj_name>
  <obj_hashval>24cc3bef6ebeab50e8a2cc3711b0309e</obj_hashval>
  <obj_text>SELECT codutilaj20,
    codutilaj,
    nrdoc,
    datadoc,
    descriere,
    stare,
    operator,
    obs,
    codies,
    codlocalit,
    adresa
   FROM martor.utilaje20
  WHERE codutilaj20 = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_dvi</obj_name>
  <obj_hashval>93711b3cb2938abf830dc85a5a0d6105</obj_hashval>
  <obj_text>SELECT codintr,
    tipdoc,
    anulat,
    blocat,
    operat,
    prefixdoc,
    nrdoc,
    datadoc,
    partener,
    nraviz,
    carnetdoc,
    valdoc,
    tvadoc,
    majorari,
    an,
    luna,
    obs,
    complex,
    satelit,
    initializari,
    codsubunit,
    codfiscal,
    seriadoc,
    bugetare,
    valsuplim,
    contsuplim,
    tiprepsuplim,
    codlocatie,
    tipfactura,
    codgestprod,
    subunitatea,
    tiptva,
    moneda,
    curs,
    userid,
    datacreare,
    tiptranzactie,
    discvol,
    discter,
    nri,
    schimb,
    codformatie,
    idimport,
    delegat,
    mijltransp,
    nrtransp,
    farareg,
    exclusplata,
    codauto,
    prorata,
    codcontract,
    codanaliza,
    tvaincasare,
    tvaincasare_f,
    cursdoc,
    transportator,
    valtransport,
    custodie,
    factsimplif,
    agent,
    cursnir,
    stadiuwms,
    datarefscad,
    autofacturare
   FROM martor.intrari
  WHERE codintr = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_emulare</obj_name>
  <obj_hashval>9ecfedb01a9d5c3659acde07c1587d6b</obj_hashval>
  <obj_text>SELECT codemulare,
    nrbon,
    databon,
    valoare,
    valoarediscount,
    listat,
    preluat,
    codcasamarcat,
    tvatotal,
    tvadiscount,
    tipcasamarcat,
    userid,
    datacreare,
    datalistare,
    codies,
    codpart,
    incasareclient,
    codmonetar,
    codpers,
    codpostretail,
    codaecustodie,
    codlocatie,
    codagent,
    obs,
    codrestnp,
    codpartcomis,
    textnefiscal,
    factsimplif,
    idbon,
    facturare,
    delegat,
    exclusdiscount,
    codpartretail,
    codiesretail,
    codsediuretail,
    punctecumul,
    valpunctecumul
   FROM martor.emulare
  WHERE codemulare = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_evidentamf</obj_name>
  <obj_hashval>caa54dc5d42e76a039dcb921804e7960</obj_hashval>
  <obj_text>SELECT codmifix,
    tip,
    nrinventar,
    anintrare,
    lunaintrare,
    obs,
    anintrareg,
    lunaintrareg,
    serieinv,
    codmifiximb,
    restimbmf
   FROM martor.mifix
  WHERE codmifix = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_expert</obj_name>
  <obj_hashval>c01b0cd154c57a2ec5dd7cace624800f</obj_hashval>
  <obj_text>SELECT codexpert,
    coddoc,
    tipdoc,
    an,
    luna,
    subunitatea,
    userid,
    datacreare,
    dirty,
    codanaliza
   FROM martor.expert
  WHERE codexpert = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_faz</obj_name>
  <obj_hashval>57f58318675c1eb4372e8b74fbc0c333</obj_hashval>
  <obj_text>SELECT fz.codfaz,
    fz.nrdoc,
    fz.datadoc,
    obj.denumire,
    auto.nrinreg,
    sub.den_subunit,
    ( SELECT martor.fnc_array_to_vc3200(array_agg(DISTINCT (p.nume::text || ' '::text) || p.prenume::text)::character varying[]) AS fnc_array_to_vc3200
           FROM martor.faz0
             JOIN martor.npers p ON p.codpers = faz0.codpers
          WHERE faz0.codfaz = fz.codfaz) AS sofer,
    fz.kmplecare,
    fz.kmsosire,
    fz.operat,
    fz.blocat,
    fz.anulat
   FROM martor.faz fz
     JOIN martor.nparcaut auto ON fz.codauto = auto.codnparcaut
     JOIN martor.nartobj obj ON obj.codobiect = auto.codart
     JOIN martor.nsubunit sub ON sub.codsubunit = fz.subunitatea
     LEFT JOIN martor.npers s ON s.codpers = fz.codpers
  WHERE fz.codfaz = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_iesiri</obj_name>
  <obj_hashval>fdaa3a7a90058a1533f9f2e178eaec68</obj_hashval>
  <obj_text>SELECT DISTINCT codies,
    tipdoc,
    anulat,
    blocat,
    operat,
    prefixdoc,
    carnetdoc,
    nrdoc,
    datadoc,
    partener,
    carnetae,
    nrae,
    valdoc,
    tvadoc,
    valdiscount,
    tvadiscount,
    contdiscount,
    accize,
    delegat,
    agent,
    majorari,
    obs,
    an,
    luna,
    initializari,
    codsubunit,
    codfiscal,
    seriadoc,
    bugetare,
    codlocatie,
    tipfactura,
    codgestprod,
    contintermed,
    tiptva,
    subunitatea,
    tipconsumator,
    codauto,
    partcustodie,
    codcmdinterna,
    codpers,
    comision,
    codbankcont,
    tipcasamarcat,
    moneda,
    curs,
    userid,
    datacreare,
    tiptranzactie,
    mijltransp,
    nrtransp,
    listat,
    infocm,
    cursdoc,
    discvol,
    discter,
    monedatransf,
    nri,
    contsuplim,
    datainreg,
    custodie,
    faratransport,
    tipchelt,
    carnetcertif,
    nrcertif,
    seriacertif,
    starerestituire,
    idimport,
    listatcertif,
    farareg,
    codpersc,
    exclusplata,
    codiesmamb,
    proctvadoc,
    codanaliza,
    codaecustodie,
    tvaincasare,
    datatva,
    codcontract,
    factsimplif,
    transportator,
    stadiuwms,
    codmonetar,
    numarbonuri,
    emisadeclient,
        CASE
            WHEN tipdoc = 23::numeric THEN ( SELECT COALESCE(sum(intr1.cant), 0::numeric) AS "coalesce"
               FROM martor.intrari intr,
                martor.intrari1 intr1
              WHERE intr.subunitatea = i.codsubunit AND intr.nrdoc = i.nrdoc AND (intr.seriadoc IS NULL OR i.seriadoc::text = intr.seriadoc::text) AND intr1.codintr = intr.codintr AND intr.tipdoc = 6::numeric)
            ELSE 0::numeric
        END AS cantprel
   FROM martor.iesiri i
  WHERE codies = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_intrari</obj_name>
  <obj_hashval>83d5fb8363e30a21dbd831caf0b706ea</obj_hashval>
  <obj_text>SELECT DISTINCT codintr,
    tipdoc,
    anulat,
    blocat,
    operat,
    prefixdoc,
    nrdoc,
    datadoc,
    partener,
    nraviz,
    carnetdoc,
    valdoc,
    tvadoc,
    majorari,
    an,
    luna,
    obs,
    complex,
    satelit,
    initializari,
    codsubunit,
    codfiscal,
    seriadoc,
    bugetare,
    valsuplim,
    contsuplim,
    tiprepsuplim,
    codlocatie,
    tipfactura,
    codgestprod,
    subunitatea,
    tiptva,
    moneda,
    curs,
    userid,
    datacreare,
    tiptranzactie,
    discvol,
    discter,
    nri,
    schimb,
    codformatie,
    idimport,
    delegat,
    mijltransp,
    nrtransp,
    farareg,
    exclusplata,
    codauto,
    prorata,
    codcontract,
    codanaliza,
    tvaincasare,
    tvaincasare_f,
    cursdoc,
    transportator,
    valtransport,
    custodie,
    factsimplif,
    agent,
    cursnir,
    stadiuwms,
    datarefscad,
    autofacturare
   FROM martor.intrari
  WHERE codintr = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_lansari</obj_name>
  <obj_hashval>46e8fe14fd33ed8044fec4afb79e1e83</obj_hashval>
  <obj_text>SELECT codlansare,
    codcmd1,
    nrdoc,
    carnetdoc,
    datadoc,
    cant,
    codproiect,
    subunitatea,
    userid,
    datacreare,
    anulat,
    operat,
    blocat,
    automat,
    codscenariu,
    obs
   FROM martor.lansare
  WHERE codlansare = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_mariri_dimin</obj_name>
  <obj_hashval>5e628597344012676d50943b8a426cd0</obj_hashval>
  <obj_text>SELECT codies,
    tipdoc,
    anulat,
    blocat,
    operat,
    prefixdoc,
    carnetdoc,
    nrdoc,
    datadoc,
    partener,
    carnetae,
    nrae,
    valdoc,
    tvadoc,
    valdiscount,
    tvadiscount,
    contdiscount,
    accize,
    delegat,
    agent,
    majorari,
    obs,
    an,
    luna,
    initializari,
    codsubunit,
    codfiscal,
    seriadoc,
    bugetare,
    codlocatie,
    tipfactura,
    codgestprod,
    contintermed,
    tiptva,
    subunitatea,
    tipconsumator,
    codauto,
    partcustodie,
    codcmdinterna,
    codpers,
    comision,
    codbankcont,
    tipcasamarcat,
    moneda,
    curs,
    userid,
    datacreare,
    tiptranzactie,
    mijltransp,
    nrtransp,
    listat,
    infocm,
    cursdoc,
    discvol,
    discter,
    monedatransf,
    nri,
    contsuplim,
    datainreg,
    custodie,
    faratransport,
    tipchelt,
    carnetcertif,
    nrcertif,
    seriacertif,
    starerestituire,
    idimport,
    listatcertif,
    farareg,
    codpersc,
    exclusplata,
    codiesmamb,
    proctvadoc,
    codanaliza,
    codaecustodie,
    tvaincasare,
    datatva,
    codcontract,
    factsimplif,
    transportator,
    stadiuwms,
    codmonetar,
    numarbonuri,
    emisadeclient
   FROM martor.iesiri
  WHERE codies = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_mifix</obj_name>
  <obj_hashval>8b7f7746033eac200554f745c483d631</obj_hashval>
  <obj_text>SELECT codnirstoc,
    pret,
    denumire AS den_obj,
    den_gest,
    codgest,
    den_ioart,
    datanir,
    stoc,
    detaliuluna,
    rezolvat,
        CASE
            WHEN stoc = rezolvat THEN 1
            ELSE 0
        END AS ok,
    den_subunit,
    codsubunit
   FROM ( SELECT ns.codnirstoc,
            ns.pret,
            o.denumire,
            g.den_gest,
            g.codgest,
            io.den_ioart,
            n.datanir,
            ( SELECT pkg_intrari_get_rest_stoc_in_luna.wme_result
                   FROM martor.pkg_intrari_get_rest_stoc_in_luna(NULL::numeric, ns.codnirstoc, martor.getanlucru(), martor.getlunalucru()) pkg_intrari_get_rest_stoc_in_luna(wme_result, acodnirstoc, aan, aluna)) AS stoc,
            COALESCE(( SELECT sum(mifix1.cant) AS sum
                   FROM martor.mifix1
                  WHERE mifix1.codnirstoc = ns.codnirstoc AND mifix1.anstart = martor.getanlucru() AND mifix1.lunastart = martor.getlunalucru() AND (mifix1.stare = ANY (ARRAY[1::numeric, 2::numeric, 5::numeric]))), 0::numeric) AS rezolvat,
            COALESCE(( SELECT count(*) AS count
                   FROM martor.mifix1
                  WHERE mifix1.codnirstoc = ns.codnirstoc AND mifix1.anstart = martor.getanlucru() AND mifix1.lunastart = martor.getlunalucru()), 0::bigint) AS detaliuluna,
            sub.den_subunit,
            sub.codsubunit
           FROM martor.nirstoc ns
             JOIN martor.nir n ON n.codnir = ns.codnir
             JOIN martor.ngest g ON n.gest = g.codgest
             JOIN martor.nsubunit sub ON sub.codsubunit = g.codsubunit
             JOIN martor.nartobj o ON ns.codobiect = o.codobiect
             JOIN martor.ioart io ON ns.codioart = io.codioart
          WHERE ns.codnirstoc = current_setting('PKG_GLOBALS.RECID_DOC_LISTARE'::text, true)::numeric AND (date_part('year'::text, n.datanir) * 12::double precision + date_part('month'::text, n.datanir)) &lt;= martor.getanlunalucru()::double precision) mifix
  WHERE stoc &lt;&gt; 0::numeric OR (stoc = 0::numeric OR stoc IS NULL) AND rezolvat &lt;&gt; 0::numeric OR (stoc = 0::numeric OR stoc IS NULL) AND rezolvat = 0::numeric AND detaliuluna &gt; 0;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_miscari</obj_name>
  <obj_hashval>05a7bb2a69c72f039ab2c194c073f97f</obj_hashval>
  <obj_text>SELECT codtransf,
    tipdoc,
    anulat,
    blocat,
    operat,
    prefixdoc,
    carnetdoc,
    nrdoc,
    datadoc,
    carnetae,
    nrae,
    valdoc,
    tvadoc,
    an,
    luna,
    valsuplim,
    contsuplim,
    tiprepsuplim,
    obs,
    subunitatea,
    delegat,
    codpart,
    tipmodifpret,
    storno,
    userid,
    datacreare,
    mijltransp,
    nrtransp,
    codgestcmd,
    listat,
    reevaluare,
    seriadoc,
    idimport,
    codanaliza,
    ajustvalstoc,
    stadiuwms,
    subunitdest
   FROM martor.transf
  WHERE codtransf = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_nart</obj_name>
  <obj_hashval>fc9c41ef4cb2ca4975d19bb2f18033c7</obj_hashval>
  <obj_text>SELECT codarticol,
    codobiect,
    codproducator,
    codextern,
    codintern,
    codvamal,
    masa,
    volum,
    stocmin,
    stocmax,
    returnabil,
    lunigarantie,
    obs,
    procadaosnir,
    rotunjire,
    adaosexceptie,
    promotie,
    rotvaluta,
    denumire,
    umambalare,
    pretminim,
    termenplata,
    dataadaugarii,
    codplu,
    usestocmed,
    durmaxaprov,
    codcnas,
    codcaract,
    blocat,
    discpromo,
    taraorigine,
    zilevalabil,
    ziledistrib,
    codperisabil,
    nefacturabil
   FROM martor.nartobj
  WHERE codarticol = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_ngest</obj_name>
  <obj_hashval>202d674fa90d893e8800fa7e68d5adec</obj_hashval>
  <obj_text>SELECT codgest,
    den_gest,
    simbol,
    codclasa,
    codactivit,
    codcont,
    codcatpret,
    codgestionar,
    custodie,
    codsubunit,
    verdisplivr,
    verdisplivrtransf,
    verdisplivrsubunit,
    vernir,
    vernirtransf,
    vernirsubunit,
    tip,
    gmaster,
    nrschimburi,
    oreschimb,
    orastart,
    coefcheltmat,
    coefcheltman,
    veremulare,
    codpostretail,
    analiticcont,
    cantitate,
    inactiv,
    verfacties,
    verchitanta,
    codcaensec,
    codgesttr
   FROM martor.ngest
  WHERE codgest = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_notecredit_cu_dif</obj_name>
  <obj_hashval>089894107ea4c63ac01484a1442ce28c</obj_hashval>
  <obj_text>SELECT codncredit,
    nrdoc,
    seriadoc,
    codcontract2,
    codpart,
    tipdoc,
    den_part,
    datastart,
    datastop,
    an,
    luna,
    contract,
    diferente,
    corectie
   FROM ( SELECT nc.codncredit,
            nc.nrdoc,
            nc.seriadoc,
            nc.codcontract2,
            nc.codpart,
            nc.tipdoc,
            p.den_part,
            nc.datastart,
            nc.datastop,
            nc.an,
            nc.luna,
                CASE
                    WHEN COALESCE(c.codcontract, 0::numeric) = 0::numeric THEN
                    CASE
                        WHEN COALESCE(cc.codcontract, 0::numeric) = 0::numeric THEN '...fara...'::text
                        ELSE (((cc.nrdoc || '/'::text) || to_char(cc.datastart::timestamp with time zone, 'DD.MM.YYYY'::text)) || '-'::text) || to_char(cc.datastop::timestamp with time zone, 'DD.MM.YYYY'::text)
                    END
                    ELSE (((c.nrdoc || '/'::text) || to_char(c.datastart::timestamp with time zone, 'DD.MM.YYYY'::text)) || '-'::text) || to_char(c.datastop::timestamp with time zone, 'DD.MM.YYYY'::text)
                END::character varying AS contract,
                CASE
                    WHEN nc.corectie = 1::numeric THEN - round(COALESCE(rep.valoare, 0::numeric) + COALESCE(facturat.valoare, 0::numeric), 2)
                    ELSE round(COALESCE(rep.valoare, 0::numeric) - COALESCE(facturat.valoare, 0::numeric) - COALESCE(cor.valoare, 0::numeric), 2)
                END AS diferente,
            COALESCE(nc.corectie, 0::numeric) AS corectie
           FROM martor.notecredit nc
             JOIN martor.npart p ON nc.codpart = p.codpart
             LEFT JOIN martor.contract2 c2 ON nc.codcontract2 = c2.codcontract2
             LEFT JOIN martor.contract c ON c2.codcontract = c.codcontract
             LEFT JOIN martor.contract cc ON nc.codcontract = cc.codcontract
             LEFT JOIN ( SELECT nc_1.codncredit,
                    sum(nvl(nc1.valoare, 0::numeric) - nvl(nc1.valoareold, 0::numeric)) AS valoare
                   FROM martor.notecredit nc_1
                     JOIN martor.notecredit1 nc1 ON nc_1.codncredit = nc1.codncredit
                  GROUP BY nc_1.codncredit) rep ON rep.codncredit = nc.codncredit
             LEFT JOIN ( SELECT ncf.codncredit,
                    sum(ncf.valdoc) AS valoare
                   FROM martor.notecredit nc_1
                     JOIN martor.notecreditfact ncf ON ncf.codncredit = nc_1.codncredit
                     JOIN martor.iesiri i ON ncf.coddoc = i.codies AND ncf.tipdoc = i.tipdoc
                  GROUP BY ncf.codncredit
                UNION ALL
                 SELECT ncf.codncredit,
                    sum(ncf.valdoc) AS valoare
                   FROM martor.notecredit nc_1
                     JOIN martor.notecreditfact ncf ON ncf.codncredit = nc_1.codncredit
                     JOIN martor.intrari1 i1 ON ncf.coddoc1 = i1.codintr1
                     JOIN martor.intrari i ON i.codintr = i1.codintr AND ncf.tipdoc = i.tipdoc
                  GROUP BY ncf.codncredit
                UNION ALL
                 SELECT ncf.codncredit,
                    sum(ncf.valdoc) AS valoare
                   FROM martor.notecredit nc_1
                     JOIN martor.notecreditfact ncf ON ncf.codncredit = nc_1.codncredit
                     JOIN martor.intrari i ON ncf.coddoc = i.codintr AND ncf.tipdoc = i.tipdoc
                  GROUP BY ncf.codncredit) facturat ON facturat.codncredit = nc.codncredit
             LEFT JOIN ( SELECT cor_1.codnccorectie AS codncredit,
                    sum(nc1.valoareold - nc1.valoare) AS valoare
                   FROM martor.notecredit cor_1
                     JOIN martor.notecredit1 nc1 ON cor_1.codncredit = nc1.codncredit
                  WHERE cor_1.corectie = 1::numeric
                  GROUP BY cor_1.codnccorectie) cor ON cor.codncredit = nc.codncredit
          WHERE nc.subunitatea = martor.getsubunitate_doc() AND round(nvl(rep.valoare, 0::numeric) - nvl(facturat.valoare, 0::numeric) - nvl(cor.valoare, 0::numeric), 2) &lt;&gt; 0::numeric AND (nvl(nc.corectie, 0::numeric) = ANY (ARRAY[0::numeric, 2::numeric]))) a_pg;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_npart</obj_name>
  <obj_hashval>7627cbf746c60e11f6c8fe1c3ce4b2c3</obj_hashval>
  <obj_text>SELECT codpart,
    den_part,
    regcom,
    codextern,
    codmoneda,
    autorizatie,
    codintern,
    codclasa,
    codcategpret,
    tippart,
    scadentac,
    scadentav,
    discount,
    codcategdisc,
    blocat,
    tippartener,
    dataadaugarii,
    obs,
    poza,
    persoanafizica,
    verfact,
    verdisplivr,
    coldiscount
   FROM martor.npart
  WHERE codpart = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_npers</obj_name>
  <obj_hashval>f565e2872523164b04e8020572348cee</obj_hashval>
  <obj_text>SELECT codpers,
    marca,
    nume,
    prenume,
    cnp,
    biseria,
    binr,
    locnastere,
    adresa,
    prenumet,
    prenumem,
    localitn,
    datan,
    scivila,
    smilitar,
    activ,
    strainatate,
    agent,
    delegat,
    agenda,
    bieliberatde,
    ladatade,
    taran,
    cetatenie,
    poza,
    logonname,
    accmas,
    comision,
    codgest,
    codanalizanod,
    codsubunit
   FROM martor.npers
  WHERE codpers = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_oport</obj_name>
  <obj_hashval>82fb2da1544c735e1fb8b46c7206e271</obj_hashval>
  <obj_text>SELECT codoportunitate,
    prefixdoc,
    nrdoc,
    datadoc,
    codcarnetdoc,
    codpartener,
    codmoneda,
    tip,
    codagent,
    codcampanie,
    venitest,
    venitprob,
    codsubunitate,
    codoferta,
    codcomanda,
    an,
    luna,
    probvanz,
    datasemnare,
    codcontract,
    seriadoc,
    codlead,
    codtask
   FROM martor.oportunitati
  WHERE codoportunitate = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_opreg</obj_name>
  <obj_hashval>e99c161790196017b24e9010834e36e8</obj_hashval>
  <obj_text>SELECT codop,
    codpart,
    codbanca,
    obs,
    tiptranz,
    tipdecont,
    zidecont,
    codmoneda,
    valoare,
    an_start,
    luna_start,
    an_max,
    luna_max,
    subunitatea
   FROM martor.opreg
  WHERE codop = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_pachete</obj_name>
  <obj_hashval>fb6764e8c63a115ae7b77d1c8ec3acff</obj_hashval>
  <obj_text>SELECT codpachete,
    datap,
    userid,
    datacreare,
    subunitate,
    gestiune,
    carnetdoc,
    nrdoc,
    colector,
    datacolectare,
    verificator,
    dataverificare,
    transportator,
    datatransport,
    nrpachete,
    operat,
    blocat,
    anulat,
    identificatorp,
    listat,
    an,
    luna,
    codpart,
    tippart,
    sediu,
    delegat,
    tiplivrare,
    tippachet
   FROM martor.pachete
  WHERE codpachete = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_planifprod</obj_name>
  <obj_hashval>6b4bdd4fa99d1389bf640e3cbcec9532</obj_hashval>
  <obj_text>SELECT codplanifprod,
    codlansprod,
    an,
    luna,
    subunitatea,
    userid,
    datacreare,
    obs,
    anulat,
    blocat,
    operat,
    saptamana,
    nrdoc,
    datadoc,
    carnetdoc,
    seriadoc,
    prefixdoc,
    insaptamana
   FROM martor.planifprod
  WHERE codplanifprod = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_plati</obj_name>
  <obj_hashval>80ccdea2ba69211f57da14b72fd7d6ad</obj_hashval>
  <obj_text>SELECT DISTINCT codplata,
    data,
    codbankcont,
    valoare,
    carnetdoc,
    nrdoc,
    an,
    luna,
    subunitatea,
    valoarederepartizat,
    aprobat,
    tipdoc,
    userid,
    datacreare,
    codanaliza,
    obs,
    curs
   FROM martor.plati p
  WHERE codplata = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_prodcomp</obj_name>
  <obj_hashval>ba768b289376f13d84607af888abdb92</obj_hashval>
  <obj_text>SELECT codprodcomp,
    codobiect,
    obs,
    data,
    anulat,
    blocat,
    operat,
    cant,
    d1,
    d2,
    d3,
    tipreteta,
    cantum1,
    pret,
    coefindirecte,
    implicit,
    descriere,
    inactiv,
    gest,
    identificator,
    datadocumentatie,
    arhiva,
    observatii,
    proiectant,
    codclasaprod,
    invizibila,
    generic,
    durata,
    userid,
    datacreare,
    hfactor,
    valmat,
    valman,
    valregie,
    tippret,
    codproiect,
    obs1,
    obs2,
    obs3,
    obs4,
    obs5,
    obs6,
    codmoneda,
    pretvaluta,
    ag,
    valag,
    profit,
    valprofit,
    pretfinal,
    valprofitv,
    pretfinalv,
    totpretcoef,
    totpretfix,
    totpretcoefv,
    totpretfixv,
    valregieman
   FROM martor.prodcomp
  WHERE codprodcomp = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_promo</obj_name>
  <obj_hashval>e0090f1bec332d4dbe50775c0d87ff49</obj_hashval>
  <obj_text>SELECT codpromo,
    tipdoc,
    anulat,
    blocat,
    operat,
    carnetdoc,
    seriadoc,
    nrdoc,
    datastart,
    dataend,
    partener,
    codlocatie,
    codfiscal,
    codpersc,
    moneda,
    tippromotie,
    tipconditie,
    obs,
    subunitatea,
    an,
    luna,
    userid,
    datacreare,
    tipclasep,
    tipservire,
    demana,
    valmin,
    praguri,
    cantmin,
    orastart,
    orastop
   FROM martor.promo
  WHERE codpromo = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_regoss</obj_name>
  <obj_hashval>ab8a6c03a253773874f2e0e307a9f292</obj_hashval>
  <obj_text>SELECT codregoss,
    tipreg,
    nrdoc,
    datadoc,
    trimestrul,
    codbank,
    codmoneda,
    curs,
    dirty,
    obs,
    codsubunit,
    an,
    luna,
    codgest,
    codanaliza,
    codanalizanod,
    codcentru,
    curs_ifrs
   FROM martor.regoss
  WHERE codregoss = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_sertar</obj_name>
  <obj_hashval>61001fc48bf9375904a2b5d0201c5a87</obj_hashval>
  <obj_text>SELECT codsertar,
    codemitent,
    codpartener,
    subunitate,
    tip,
    decont,
    doc,
    nrdoc,
    datadoc,
    valoare,
    datadecont,
    depus,
    datacreare,
    userid,
    obs,
    dataoblig,
    banca,
    moneda
   FROM martor.nsertar
  WHERE codsertar = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_taskuriloco</obj_name>
  <obj_hashval>9d9588bad3fe4674fbf6cbe44f5109c2</obj_hashval>
  <obj_text>SELECT codtask,
    problema,
    destinatar,
    executant,
    username,
    termen,
    datatask,
    datarez,
    domeniu,
    tip,
    rezolvare,
    observatii,
    prioritate,
    done,
    modificat,
    mesajcatre,
    sters,
    proiect
   FROM martor.settask
  WHERE codtask = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_trezor</obj_name>
  <obj_hashval>fd8023b5c5d176699c3c549515c78719</obj_hashval>
  <obj_text>SELECT codtrezor,
    tipdoc,
    codbanca,
    icontpers,
    monedapers,
    datadoc,
    numedoc,
    an,
    luna,
    agent,
    operat,
    blocat,
    subunitatea,
    userid,
    datacreare,
    datainreg,
    idimport,
    codanaliza
   FROM martor.trezor
  WHERE codtrezor = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_utilaje</obj_name>
  <obj_hashval>3630872e96a0561ddcc582d71d6d9186</obj_hashval>
  <obj_text>SELECT codutilaj,
    codobiect,
    nrinventar,
    eticheta,
    tiputilaj,
    flota,
    model,
    anf,
    serief,
    incarcare,
    datagarantie,
    ingarantie,
    lungime,
    latime,
    inaltime,
    obs,
    inactiv,
    corectieindex,
    um,
    plafoncantf,
    codgest,
    codpart,
    codies1,
    datagarantiei,
    aprobat,
    datastart,
    nrcontr,
    datacontr,
    codfurnizor,
    doc,
    tip,
    codlocalit,
    adresa,
    hfactor,
    agent
   FROM martor.utilaje
  WHERE codutilaj = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_livrari_luna</obj_name>
  <obj_hashval>e29b823a80642d3f183f02cf79f8d8b2</obj_hashval>
  <obj_text>SELECT l1.codnirstoc,
    '-1'::integer::numeric * l1.cant AS rest,
    '-1'::integer::numeric * l1.cantum1 AS restum1,
    '-1'::integer::numeric * l1.cantum2 AS restum2
   FROM martor.intrari i
     JOIN martor.livr l ON l.codintr = i.codintr AND l.tiplivr = i.tipdoc
     JOIN martor.livr1 l1 ON l.codlivr = l1.codlivr
     JOIN martor.nirstoc ns ON ns.codnirstoc = l1.codnirstoc
     JOIN martor.nir n ON n.codnir = ns.codnir
     JOIN martor.ioart1 io ON io.codioart = ns.codioart AND (i.an * 12::numeric + i.luna) &gt;= io.alstart AND (i.an * 12::numeric + i.luna) &lt;= io.alstop
  WHERE i.operat = 1::numeric AND i.anulat = 0::numeric AND (i.tipdoc = ANY (ARRAY[1::numeric, 2::numeric, 3::numeric, 4::numeric, 5::numeric, 6::numeric, 7::numeric])) AND i.an = (( SELECT pkg_globals_getantemp.wme_result
           FROM martor.pkg_globals_getantemp(NULL::numeric, NULL::numeric) pkg_globals_getantemp(wme_result, fakeparam))) AND i.luna = (( SELECT pkg_globals_getlunatemp.wme_result
           FROM martor.pkg_globals_getlunatemp(NULL::numeric, NULL::numeric) pkg_globals_getlunatemp(wme_result, fakeparam))) AND l.operat = 1::numeric AND l.anulat = 0::numeric AND COALESCE(n.operat, 0::numeric) = 1::numeric AND io.mg &lt;&gt; 5::numeric
UNION ALL
 SELECT l1.codnirstoc,
    '-1'::integer::numeric * l1.cant AS rest,
    '-1'::integer::numeric * l1.cantum1 AS restum1,
    '-1'::integer::numeric * l1.cantum2 AS restum2
   FROM martor.iesiri i
     JOIN martor.livr l ON l.codies = i.codies AND l.tiplivr = i.tipdoc
     JOIN martor.livr1 l1 ON l.codlivr = l1.codlivr
     JOIN martor.nirstoc ns ON ns.codnirstoc = l1.codnirstoc
     JOIN martor.nir n ON n.codnir = ns.codnir
     JOIN martor.ioart1 io ON io.codioart = ns.codioart AND (i.an * 12::numeric + i.luna) &gt;= io.alstart AND (i.an * 12::numeric + i.luna) &lt;= io.alstop
  WHERE i.operat = 1::numeric AND i.anulat = 0::numeric AND (i.tipdoc = ANY (ARRAY[14::numeric, 16::numeric, 19::numeric, 20::numeric, 21::numeric, 23::numeric, 24::numeric])) AND i.an = (( SELECT pkg_globals_getantemp.wme_result
           FROM martor.pkg_globals_getantemp(NULL::numeric, NULL::numeric) pkg_globals_getantemp(wme_result, fakeparam))) AND i.luna = (( SELECT pkg_globals_getlunatemp.wme_result
           FROM martor.pkg_globals_getlunatemp(NULL::numeric, NULL::numeric) pkg_globals_getlunatemp(wme_result, fakeparam))) AND l.operat = 1::numeric AND l.anulat = 0::numeric AND COALESCE(n.operat, 0::numeric) = 1::numeric AND io.mg &lt;&gt; 5::numeric
UNION ALL
 SELECT l1.codnirstoc,
    '-1'::integer::numeric * l1.cant AS rest,
    '-1'::integer::numeric * l1.cantum1 AS restum1,
    '-1'::integer::numeric * l1.cantum2 AS restum2
   FROM martor.transf t
     JOIN martor.livr l ON l.codtransf = t.codtransf AND l.tiplivr = t.tipdoc
     JOIN martor.livr1 l1 ON l.codlivr = l1.codlivr
     JOIN martor.nirstoc ns ON ns.codnirstoc = l1.codnirstoc
     JOIN martor.nir n ON n.codnir = ns.codnir
     JOIN martor.ioart1 io ON io.codioart = ns.codioart AND (t.an * 12::numeric + t.luna) &gt;= io.alstart AND (t.an * 12::numeric + t.luna) &lt;= io.alstop
  WHERE t.operat = 1::numeric AND t.anulat = 0::numeric AND (t.tipdoc = ANY (ARRAY[12::numeric, 13::numeric])) AND t.an = (( SELECT pkg_globals_getantemp.wme_result
           FROM martor.pkg_globals_getantemp(NULL::numeric, NULL::numeric) pkg_globals_getantemp(wme_result, fakeparam))) AND t.luna = (( SELECT pkg_globals_getlunatemp.wme_result
           FROM martor.pkg_globals_getlunatemp(NULL::numeric, NULL::numeric) pkg_globals_getlunatemp(wme_result, fakeparam))) AND l.operat = 1::numeric AND l.anulat = 0::numeric AND COALESCE(n.operat, 0::numeric) = 1::numeric AND io.mg &lt;&gt; 5::numeric
UNION ALL
 SELECT l1.codnirstoc,
    l1.cant AS rest,
    l1.cantum1 AS restum1,
    l1.cantum2 AS restum2
   FROM martor.iesiri i
     JOIN martor.livr l ON l.codies = i.codies AND l.tiplivr = i.tipdoc
     JOIN martor.livr1 l1 ON l.codlivr = l1.codlivr
     JOIN martor.nirstoc ns ON ns.codnirstoc = l1.codnirstoc
     JOIN martor.nir n ON n.codnir = ns.codnir
     JOIN martor.ioart1 io ON io.codioart = ns.codioart AND (i.an * 12::numeric + i.luna) &gt;= io.alstart AND (i.an * 12::numeric + i.luna) &lt;= io.alstop
  WHERE i.operat = 1::numeric AND i.anulat = 0::numeric AND i.tipdoc = 15::numeric AND i.an = (( SELECT pkg_globals_getantemp.wme_result
           FROM martor.pkg_globals_getantemp(NULL::numeric, NULL::numeric) pkg_globals_getantemp(wme_result, fakeparam))) AND i.luna = (( SELECT pkg_globals_getlunatemp.wme_result
           FROM martor.pkg_globals_getlunatemp(NULL::numeric, NULL::numeric) pkg_globals_getlunatemp(wme_result, fakeparam))) AND l.operat = 1::numeric AND l.anulat = 0::numeric AND COALESCE(n.operat, 0::numeric) = 1::numeric AND io.mg &lt;&gt; 5::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_locatiipart</obj_name>
  <obj_hashval>015b2868b15a888b2ef6de01ab417edd</obj_hashval>
  <obj_text>SELECT a.codagenda,
    a.obs,
    a.codagent,
    a.sediusocial,
    a.transpclient,
    ( SELECT getadresa.wme_result
           FROM martor.getadresa(NULL::character varying, a.sector, a.strada, a.nr1, a.nr2, a.bloc, a.scara, a.etaj, a.apart, a.codpostal) getadresa(wme_result, p_sector, p_strada, p_nr1, p_nr2, p_bloc, p_scara, p_etaj, p_apart, p_codpostal)) AS adresalocatie,
    l.den_localit,
    ((p.nume::text || ' '::text) || p.prenume::text)::character varying AS agentimplicit,
    a.codpart,
    a.cod_codfiscal,
    a.tip,
    a.codcoresp,
    cf.codfiscal,
    a.codclient,
    a.idsediu,
    a.gestlivrare,
    a.email,
    a.codtraseu,
        CASE
            WHEN a.sediusocial = 1::numeric THEN 'L'::text
            WHEN a.sediusocial = 2::numeric THEN 'F'::text
            WHEN a.sediusocial = 3::numeric THEN 'L+F'::text
            WHEN a.sediusocial = 4::numeric THEN 'SS'::text
            WHEN a.sediusocial = 5::numeric THEN 'SS+L'::text
            WHEN a.sediusocial = 6::numeric THEN 'SS+F'::text
            WHEN a.sediusocial = 7::numeric THEN 'SS+L+F'::text
            WHEN a.sediusocial = 9::numeric THEN 'Livrare la beneficiar'::text
            ELSE NULL::text
        END::character varying AS ssoc
   FROM martor.nagenda a
     LEFT JOIN martor.npartcodfisc cf ON cf.cod_codfiscal = a.cod_codfiscal
     LEFT JOIN martor.nlocalit l ON l.codlocalit = a.codlocalit
     LEFT JOIN martor.npers p ON p.codpers = a.codagent
  WHERE a.tip = 0::numeric AND a.codpart = (( SELECT pkg_nompart_get_part_curent_locatii.wme_result
           FROM martor.pkg_nompart_get_part_curent_locatii(NULL::numeric, NULL::numeric) pkg_nompart_get_part_curent_locatii(wme_result, fakeparam))) AND COALESCE(a.inactiv, 0::numeric) = 0::numeric AND (a.sediusocial::integer &amp; 1) &lt;&gt; 0;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_manoperagantt</obj_name>
  <obj_hashval>e16b17e70d04a1055d545820b69626ac</obj_hashval>
  <obj_text>SELECT codcomanda1,
    codcomanda,
    codgest,
    codloc,
    codreteta,
    den_gest,
    locmunca,
    round(tu /
        CASE
            WHEN COALESCE(orezi, 0::numeric) = 0::numeric THEN 8::numeric
            ELSE orezi
        END / 60::numeric * cantacceptat / cantprod, 5) AS zile,
    round(tu /
        CASE
            WHEN COALESCE(orezi, 0::numeric) = 0::numeric THEN 8::numeric
            ELSE orezi
        END / 60::numeric * (cantacceptat - COALESCE(realizat, 0::numeric) + COALESCE(rebutat, 0::numeric)) / cantprod, 5) AS zilerest,
    round(tu / 60::numeric * (cantacceptat / cantprod), 5) AS ore,
    round(tu / 60::numeric * (cantacceptat - COALESCE(realizat, 0::numeric) + COALESCE(rebutat, 0::numeric)) / cantprod, 5) AS orerest,
    codoperatie,
    realizat,
    rebutat,
    refacut,
    idxgest,
    nrschimburi,
    oreschimb,
    orastart,
    operatie,
    tiplm,
    tu,
    orezi,
    idx,
    nivel,
    datastart,
    lansat,
    document,
    datadoc,
    denobiect,
    documentcli,
    den_part,
    reteta,
    cantacceptat,
    restacceptat,
    termen,
    termencc,
    datadoccc,
    um,
    umsec,
    d1,
    d2,
    d3,
    cantum1,
    um1,
    den_um1,
    relatieum1,
    cantprod,
    codcmdprodman,
    lansat - COALESCE(realizat, 0::numeric) + COALESCE(rebutat, 0::numeric) AS rest,
    codcomandacli
   FROM ( SELECT ((COALESCE(c.prefixdoc, ''::character varying)::text || COALESCE(c.nrdoc::character varying, ''::character varying)::text) || '.'::text) || COALESCE(to_char(c.datadoc::timestamp with time zone, 'dd.mm.yyyy'::text), ''::text) AS document,
            c.datadoc,
            ((COALESCE(cl.prefixdoc, ''::character varying)::text || COALESCE(cl.nrdoc::character varying, ''::character varying)::text) || '.'::text) || COALESCE(to_char(cl.datadoc::timestamp with time zone, 'dd.mm.yyyy'::text), ''::text) AS documentcli,
            p.den_part,
            o.denumire AS denobiect,
            pc.obs AS reteta,
            cm.rest AS restacceptat,
            cm.cant AS cantacceptat,
            c1.termen,
            cl1.termen AS termencc,
            c1.codcomanda1,
            c1.codcomanda,
            c1.prioritate AS idx,
            pm.nivel,
            COALESCE(to_timestamp((to_char(pm.datastart, 'DD.MM.YYYY'::text) || ' '::text) || to_char(g.orastart, 'HH24:MI:SS'::text), 'DD.MM.YYYY HH24:MI:SS'::text)::timestamp without time zone, to_timestamp((to_char(c1.datastart, 'DD.MM.YYYY'::text) || ' '::text) || to_char(g.orastart, 'HH24:MI:SS'::text), 'DD.MM.YYYY HH24:MI:SS'::text)::timestamp without time zone) AS datastart,
            c1.codreteta,
            c1.umsec,
            c1.d1,
            c1.d2,
            c1.d3,
                CASE
                    WHEN COALESCE(c1.cantacceptat, 0::numeric) = 0::numeric THEN 0::numeric
                    ELSE COALESCE(c1.acceptum1, 0::numeric) * COALESCE(c1.restacceptat, 0::numeric) / COALESCE(c1.cantacceptat, 0::numeric)
                END AS cantum1,
            a.um1,
            a.relatieum1,
            pm.codcmdprodman,
            pm.cant AS lansat,
            pc.cant AS cantprod,
            ( SELECT sum(COALESCE(raportp2.realizat, 0::numeric)) AS sum
                   FROM martor.raportp2
                  WHERE raportp2.codcomanda1 = c1.codcomanda1 AND raportp2.codman = pm.codman) AS realizat,
            ( SELECT sum(COALESCE(raportp2.rebut, 0::numeric)) AS sum
                   FROM martor.raportp2
                  WHERE raportp2.codcomanda1 = c1.codcomanda1 AND raportp2.codman = pm.codman) AS rebutat,
            ( SELECT sum(COALESCE(raportp2.refacut, 0::numeric)) AS sum
                   FROM martor.raportp2
                  WHERE raportp2.codcomanda1 = c1.codcomanda1 AND raportp2.codman = pm.codman) AS refacut,
            1 AS idxgest,
            g.codgest,
            g.den_gest,
            g.nrschimburi,
            g.oreschimb,
            g.orastart - to_date('01.01.1900'::text, 'dd.mm.yyyy'::text)::timestamp without time zone AS orastart,
            ((lpad(COALESCE(pm.nrop, 0::numeric)::character varying::text, 2, '_'::text) || '/'::text) || COALESCE(op.denumire, ''::character varying)::text)::character varying AS operatie,
            lm.codloc,
            lm.denumire AS locmunca,
                CASE
                    WHEN COALESCE(lm.tip, 0::numeric) = 0::numeric THEN 'Manual'::text
                    WHEN COALESCE(lm.tip, 0::numeric) = 1::numeric THEN 'Utilaj'::text
                    WHEN COALESCE(lm.tip, 0::numeric) = 2::numeric THEN 'Mifix'::text
                    ELSE NULL::text
                END::character varying AS tiplm,
            pm.tu,
            op.codop AS codoperatie,
            u.den_um AS um,
            uu.den_um AS den_um1,
                CASE
                    WHEN (( SELECT sum(COALESCE(lm1.ore, 0::numeric)) AS sum
                       FROM martor.locmunca1 lm1
                      WHERE lm1.codloc = lm.codloc)) &gt; 0::numeric THEN ( SELECT sum(COALESCE(lm1.ore, 0::numeric)) AS sum
                       FROM martor.locmunca1 lm1
                      WHERE lm1.codloc = lm.codloc)
                    ELSE COALESCE(g.nrschimburi * g.oreschimb, 8::numeric)
                END AS orezi,
            cl.codcomanda AS codcomandacli,
            cl.datadoc AS datadoccc
           FROM martor.comanda1 c1
             JOIN martor.comanda c ON c.codcomanda = c1.codcomanda
             JOIN martor.cmdprodmat cm ON cm.codcomanda1 = c1.codcomanda1 AND cm.tip = 0::numeric
             JOIN martor.prodcomp pc ON pc.codprodcomp = c1.codreteta
             LEFT JOIN martor.cmdlink ck ON ck.codcomanda1 = c1.codcomanda1
             LEFT JOIN martor.comanda1 cl1 ON ck.codliniecomanda = cl1.codcomanda1
             LEFT JOIN martor.comanda cl ON cl.codcomanda = cl1.codcomanda
             LEFT JOIN martor.npart p ON p.codpart = cl.partener
             LEFT JOIN martor.nartobj o ON o.codobiect = c1.codobiect
             LEFT JOIN martor.nart a ON a.codarticol = o.codarticol
             LEFT JOIN martor.num u ON u.codum = a.um
             LEFT JOIN martor.num uu ON uu.codum = a.um1
             LEFT JOIN martor.cmdprodman pm ON pm.codcomanda1 = c1.codcomanda1
             LEFT JOIN martor.ngest g ON g.codgest = c.codgest
             LEFT JOIN martor.noper op ON op.codop = pm.codop
             LEFT JOIN martor.locmunca lm ON lm.codloc = pm.codloc
          WHERE c.tipdoc = 53::numeric AND c.operat = 1::numeric AND COALESCE(c.inchisa, 0::numeric) = 0::numeric) x;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_miscari_interne</obj_name>
  <obj_hashval>7ce00bcb59a51b85c7b0e608d7962014</obj_hashval>
  <obj_text>SELECT codtransf,
    tipdoc,
    anulat,
    blocat,
    operat,
    prefixdoc,
    carnetdoc,
    nrdoc,
    datadoc,
    carnetae,
    nrae,
    valdoc,
    tvadoc,
    obs,
    an,
    luna,
    listat
   FROM martor.transf t
  WHERE tipdoc = current_setting('PKG_GLOBALS.TIPMISCAREINTERNA'::text, true)::numeric AND COALESCE(subunitatea, 1::numeric) =
        CASE
            WHEN martor.getsubunitate() = 1::numeric THEN COALESCE(subunitatea, 1::numeric)
            ELSE martor.getsubunitate()
        END AND (an * 12::numeric + luna) = martor.getanlunalucru();</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_nc_sabloane</obj_name>
  <obj_hashval>3501384601bfb1bd9d3401275bc9ca2b</obj_hashval>
  <obj_text>SELECT n.codnc,
    n.nrdoc,
    n.datadoc,
    n.part,
    n.jurnaltva,
    n.tiptranz,
    n.tiptva,
    n.moneda,
    n.obs,
    n.valoare,
        CASE COALESCE(n.jurnaltva, 0::numeric)
            WHEN 1 THEN 'nu apare in jurnal TVA'::text
            WHEN 2 THEN 'Jurnal cumparari'::text
            WHEN 3 THEN 'Jurnal vanzari'::text
            ELSE '-'::text
        END::character varying AS ajurnaltva,
        CASE
            WHEN COALESCE(n.jurnaltva, 0::numeric) = 1::numeric THEN '-'::text::character varying
            ELSE
            CASE COALESCE(n.tiptranz, 0::numeric)
                WHEN 1 THEN 'Tranzactie interna'::text
                WHEN 2 THEN 'Livrare intracominitara'::text
                WHEN 3 THEN 'Export'::text
                ELSE '-'::text
            END::character varying
        END AS atiptranz,
        CASE
            WHEN COALESCE(n.jurnaltva, 0::numeric) = 1::numeric THEN '-'::text::character varying
            ELSE
            CASE COALESCE(n.tiptva, 0::numeric)
                WHEN 1 THEN 'taxare normala'::text
                WHEN 2 THEN 'taxare inversa'::text
                WHEN 3 THEN 'tranzactie triunghiulara'::text
                WHEN 4 THEN 'locul livrarii/prestarii in afara Romaniei'::text
                WHEN 5 THEN 'intracom.,scutit, cu drept de ded.(lit.a/d)'::text
                WHEN 6 THEN 'intracom.,scutit, cu drept de ded.(lit.b/c)'::text
                ELSE '-'::text
            END::character varying
        END AS atiptva,
    dm.den_moneda AS denmoneda,
    p.den_part
   FROM martor.nc n
     LEFT JOIN martor.npart p ON p.codpart = n.part
     LEFT JOIN martor.nmonede dm ON dm.codmoneda = n.moneda
  WHERE COALESCE(n.sablon, 0::numeric) = 1::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_nclaseart</obj_name>
  <obj_hashval>09c30b963654bfa85b73e7a6a6a3fcaf</obj_hashval>
  <obj_text>WITH RECURSIVE a(codclasea, den_clasea, simbol, prefix, nivel, lev, nranalitice, codparinte, verlistsuplfact, verlistsupltoall, codident, verlistsuplaviz, discofe) AS (
         SELECT nclasea.codclasea,
            nclasea.den_clasea,
            nclasea.simbol,
            nclasea.prefix,
            nclasea.nivel,
            nclasea.nivel,
            nclasea.nranalitice,
            nclasea.codparinte,
            nclasea.verlistsuplfact,
            nclasea.verlistsupltoall,
            nclasea.codident,
            nclasea.verlistsuplaviz,
            nclasea.discofe
           FROM martor.nclasea
          WHERE COALESCE(nclasea.codparinte, 0::numeric) = 0::numeric AND nclasea.codclasea &lt;&gt; 0::numeric
        UNION ALL
         SELECT c.codclasea,
            c.den_clasea,
            c.simbol,
            c.prefix,
            c.nivel,
            c.nivel,
            c.nranalitice,
            c.codparinte,
            c.verlistsuplfact,
            c.verlistsupltoall,
            c.codident,
            c.verlistsuplaviz,
            c.discofe
           FROM martor.nclasea c
             JOIN a ON COALESCE(a.codclasea, 0::numeric) = COALESCE(c.codparinte, 0::numeric)
        )
 SELECT a.codclasea,
    a.den_clasea,
    a.simbol,
    a.prefix,
    a.nivel,
    a.lev,
    a.nranalitice,
    a.codparinte,
    a.verlistsuplfact,
    a.verlistsupltoall,
    a.codident,
    a.verlistsuplaviz,
    a.discofe
   FROM a
UNION ALL
 SELECT nclasea.codclasea,
    nclasea.den_clasea,
    nclasea.simbol,
    nclasea.prefix,
    nclasea.nivel,
    0 AS lev,
    nclasea.nranalitice,
    nclasea.codparinte,
    nclasea.verlistsuplfact,
    nclasea.verlistsupltoall,
    nclasea.codident,
    nclasea.verlistsuplaviz,
    nclasea.discofe
   FROM martor.nclasea
  WHERE nclasea.codclasea = 0::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_nclasearts</obj_name>
  <obj_hashval>e442ed956d9218a6836b08852297a328</obj_hashval>
  <obj_text>WITH RECURSIVE a(codclaseas, den_claseas, simbol, prefix, nivel, lev, nranalitice, codparinte, verlistsuplfact, verlistsupltoall, tip) AS (
         SELECT nclaseas.codclaseas,
            nclaseas.den_claseas,
            nclaseas.simbol,
            nclaseas.prefix,
            nclaseas.nivel,
            nclaseas.nivel,
            nclaseas.nranalitice,
            nclaseas.codparinte,
            nclaseas.verlistsuplfact,
            nclaseas.verlistsupltoall,
            nclaseas.tip,
            nclaseas.codident
           FROM martor.nclaseas
          WHERE COALESCE(nclaseas.codparinte, 0::numeric) = 0::numeric AND nclaseas.codclaseas &lt;&gt; 0::numeric
        UNION ALL
         SELECT c.codclaseas,
            c.den_claseas,
            c.simbol,
            c.prefix,
            c.nivel,
            c.nivel,
            c.nranalitice,
            c.codparinte,
            c.verlistsuplfact,
            c.verlistsupltoall,
            c.tip,
            c.codident
           FROM martor.nclaseas c
             JOIN a ON COALESCE(a.codclaseas, 0::numeric) = COALESCE(c.codparinte, 0::numeric)
        )
 SELECT a.codclaseas,
    a.den_claseas,
    a.simbol,
    a.prefix,
    a.nivel,
    a.lev,
    a.nranalitice,
    a.codparinte,
    a.verlistsuplfact,
    a.verlistsupltoall,
    a.tip,
    a.codident
   FROM a
UNION ALL
 SELECT nclaseas.codclaseas,
    nclaseas.den_claseas,
    nclaseas.simbol,
    nclaseas.prefix,
    nclaseas.nivel,
    0 AS lev,
    nclaseas.nranalitice,
    nclaseas.codparinte,
    nclaseas.verlistsuplfact,
    nclaseas.verlistsupltoall,
    nclaseas.tip,
    nclaseas.codident
   FROM martor.nclaseas
  WHERE nclaseas.codclaseas = 0::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_nclasedisc</obj_name>
  <obj_hashval>f76cc8e744dfef54d92e45f698e57547</obj_hashval>
  <obj_text>WITH RECURSIVE fg_tree AS (
         SELECT nclasedisc_1.codclasedisc,
            nclasedisc_1.codclasedisc AS codparinte
           FROM martor.nclasedisc nclasedisc_1
          WHERE nclasedisc_1.codclasedisc = 0::numeric
        UNION ALL
         SELECT c.codclasedisc,
            p.codparinte
           FROM martor.nclasedisc c
             JOIN fg_tree p ON p.codclasedisc = c.codparinte
        )
 SELECT codclasedisc,
    den_clasedisc,
    simbol,
    nivel,
    nranalitice,
    codparinte
   FROM martor.nclasedisc;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_nclaseint</obj_name>
  <obj_hashval>f32c704b7dc26bca54bc52a0a8539415</obj_hashval>
  <obj_text>WITH RECURSIVE a(codclaseint, den_claseint, simbol, prefix, nivel, nranalitice, codparinte) AS (
         SELECT nclaseint.codclaseint,
            nclaseint.den_claseint,
            nclaseint.simbol,
            nclaseint.prefix,
            nclaseint.nivel,
            nclaseint.nranalitice,
            nclaseint.codparinte
           FROM martor.nclaseint
          WHERE COALESCE(nclaseint.codparinte, 0::numeric) = 0::numeric
        UNION ALL
         SELECT n.codclaseint,
            n.den_claseint,
            n.simbol,
            n.prefix,
            n.nivel,
            n.nranalitice,
            n.codparinte
           FROM martor.nclaseint n
             JOIN a a_1 ON a_1.codclaseint = n.codparinte
        )
 SELECT codclaseint,
    den_claseint,
    simbol,
    prefix,
    nivel,
    nranalitice,
    codparinte
   FROM a;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_nclasemf</obj_name>
  <obj_hashval>e03e2ac93b36d11ef746702dfd009d5a</obj_hashval>
  <obj_text>WITH RECURSIVE a(codclasemf, den_clasemf, simbol, prefix, nivel, nranalitice, codparinte, lev) AS (
         SELECT nclasemf.codclasemf,
            nclasemf.den_clasemf,
            nclasemf.simbol,
            nclasemf.prefix,
            nclasemf.nivel,
            nclasemf.nranalitice,
            nclasemf.codparinte,
            0 AS lev
           FROM martor.nclasemf
          WHERE COALESCE(nclasemf.codparinte, 0::numeric) = 0::numeric
        UNION ALL
         SELECT n.codclasemf,
            n.den_clasemf,
            n.simbol,
            n.prefix,
            n.nivel,
            n.nranalitice,
            n.codparinte,
            a_1.lev + 1 AS lev
           FROM martor.nclasemf n
             JOIN a a_1 ON a_1.codclasemf = n.codparinte
        )
 SELECT codclasemf,
    den_clasemf,
    simbol,
    prefix,
    nivel,
    nranalitice,
    codparinte,
    lev
   FROM a;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_nclasepart</obj_name>
  <obj_hashval>23f450d05662c22ac76b26c616c41447</obj_hashval>
  <obj_text>WITH RECURSIVE fg_tree AS (
         SELECT nclasep_1.codclasep,
            nclasep_1.codclasep AS codparinte
           FROM martor.nclasep nclasep_1
          WHERE nclasep_1.codclasep = 0::numeric
        UNION ALL
         SELECT c.codclasep,
            p.codparinte
           FROM martor.nclasep c
             JOIN fg_tree p ON p.codclasep = c.codparinte
        )
 SELECT codclasep,
    den_clasep,
    simbol,
    nivel,
    nranalitice,
    codparinte,
    codident
   FROM martor.nclasep;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_nclaseprod</obj_name>
  <obj_hashval>0ceb2c1fd7ab20c78566a40ca82f5e3d</obj_hashval>
  <obj_text>WITH RECURSIVE a AS (
         SELECT nclaseprod.codclaseprod,
            nclaseprod.den_claseprod,
            nclaseprod.simbol,
            nclaseprod.prefix,
            nclaseprod.nivel,
            nclaseprod.nranalitice,
            nclaseprod.codparinte,
            1 AS lev
           FROM martor.nclaseprod
          WHERE COALESCE(nclaseprod.codparinte, 0::numeric) = 0::numeric
        UNION ALL
         SELECT n.codclaseprod,
            n.den_claseprod,
            n.simbol,
            n.prefix,
            n.nivel,
            n.nranalitice,
            n.codparinte,
            a_1.lev + 1
           FROM martor.nclaseprod n
             JOIN a a_1 ON a_1.codclaseprod = n.codparinte
        )
 SELECT codclaseprod,
    den_claseprod,
    simbol,
    prefix,
    nivel,
    nranalitice,
    codparinte,
    lev
   FROM a;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_ncont_ext</obj_name>
  <obj_hashval>a0fc0ecd6341230e562efa10d1a394da</obj_hashval>
  <obj_text>SELECT codcont,
    simbol,
    clasa,
    den_cont,
    name,
    tipcont,
    tip,
    vizibilbalanta,
    balantasintetica,
    nivel,
    codparinte,
    activ,
    anlunainactiv,
    copil,
    copiiactivi,
    ( SELECT min(ncontechiv.an * 12::numeric + ncontechiv.luna) AS min
           FROM martor.ncontechiv
          WHERE ncontechiv.contvechi = b_pg.codcont) AS echivalat,
    simbolsitfin,
    simboltertiar,
    codsaft,
    taxtype,
    simb_contsecundar,
    simb_contsecundarg,
    simb_contsecundargo,
    simb_codcentrus,
    simb_codcentrusg,
    simb_codcentrusgo,
    taxcode,
    impozit
   FROM ( SELECT a_pg.codcont,
            a_pg.simbol,
            a_pg.clasa,
            a_pg.den_cont,
            a_pg.name,
            a_pg.tipcont,
            a_pg.tip,
            a_pg.vizibilbalanta,
            a_pg.balantasintetica,
            a_pg.nivel,
            a_pg.codparinte,
            a_pg.activ,
            a_pg.anlunainactiv,
            a_pg.copil,
            min(a_pg.anstart * 12::numeric + a_pg.lunastart) AS copiiactivi,
            a_pg.simbolsitfin,
            a_pg.simboltertiar,
            a_pg.codsaft,
            a_pg.taxtype,
            a_pg.simb_contsecundar,
            a_pg.simb_contsecundarg,
            a_pg.simb_contsecundargo,
            a_pg.simb_codcentrus,
            a_pg.simb_codcentrusg,
            a_pg.simb_codcentrusgo,
            a_pg.taxcode,
            a_pg.impozit
           FROM ( SELECT v.codcont,
                    v.simbol,
                    v.clasa,
                    v.den_cont,
                    v.name,
                    v.tipcont,
                        CASE
                            WHEN COALESCE(v.tipcont, 0::numeric) = 0::numeric THEN 'ACTIV'::character varying
                            WHEN COALESCE(v.tipcont, 0::numeric) = 1::numeric THEN 'PASIV'::character varying
                            WHEN COALESCE(v.tipcont, 0::numeric) = 2::numeric THEN 'BIFUNC'::character varying
                            ELSE NULL::character varying
                        END AS tip,
                    v.vizibilbalanta,
                    v.balantasintetica,
                    v.nivel,
                    v.codparinte,
                    COALESCE(n1.codcont, 0::numeric) AS activ,
                    COALESCE(n2.codparinte, 0::numeric) AS copil,
                    n4.anstart,
                    n4.lunastart,
                    COALESCE(v.aninactiv, 0::numeric) * 12::numeric + COALESCE(v.lunainactiv, 0::numeric) AS anlunainactiv,
                    v.simbolsitfin,
                    n5.simbol AS simboltertiar,
                    v.codsaft,
                    v.taxtype,
                    n5.simb_contsecundar,
                    n5.simb_contsecundarg,
                    n5.simb_contsecundargo,
                    n5.simb_codcentrus,
                    n5.simb_codcentrusg,
                    n5.simb_codcentrusgo,
                    v.taxcode,
                    v.impozit
                   FROM ( SELECT ncont.codcont,
                            ncont.simbol,
                            ncont.clasa,
                            ncont.den_cont,
                            ncont.name,
                            ncont.tipcont,
                            ncont.vizibilbalanta,
                            ncont.balantasintetica,
                            ncont.nivel,
                            ncont.codparinte,
                            ncont.simbolsitfin,
                            ncont.aninactiv,
                            ncont.lunainactiv,
                            ncont.codsaft,
                            ncont.taxtype,
                            ncont.taxcode,
                            ncont.impozit
                           FROM martor.ncont) v
                     LEFT JOIN martor.ncont1 n1 ON n1.codcont = v.codcont AND (n1.anstart * 12::numeric + n1.lunastart) &lt;= (( SELECT pkg_globals_anlunalucru.wme_result
                           FROM martor.pkg_globals_anlunalucru(NULL::numeric, NULL::numeric) pkg_globals_anlunalucru(wme_result, fakeparam)))
                     LEFT JOIN martor.ncont n2 ON n2.codparinte = v.codcont
                     LEFT JOIN martor.ncont1 n4 ON n4.codcont = n2.codcont
                     LEFT JOIN ( SELECT inr.codcont,
                            ntt.simbol,
                            ncts1.simbol AS simb_contsecundar,
                            ncts2.simbol AS simb_contsecundarg,
                            ncts3.simbol AS simb_contsecundargo,
                            ccs1.simbol AS simb_codcentrus,
                            ccs2.simbol AS simb_codcentrusg,
                            ccs3.simbol AS simb_codcentrusgo
                           FROM ( SELECT DISTINCT first_value(nct1.conttertiar) OVER (PARTITION BY nct1.codcont ORDER BY (nct1.anstart * 12::numeric + nct1.lunastart) DESC) AS conttertiar,
                                    first_value(nct1.contsecundar) OVER (PARTITION BY nct1.codcont ORDER BY (nct1.anstart * 12::numeric + nct1.lunastart) DESC) AS contsecundar,
                                    first_value(nct1.contsecundarg) OVER (PARTITION BY nct1.codcont ORDER BY (nct1.anstart * 12::numeric + nct1.lunastart) DESC) AS contsecundarg,
                                    first_value(nct1.contsecundargo) OVER (PARTITION BY nct1.codcont ORDER BY (nct1.anstart * 12::numeric + nct1.lunastart) DESC) AS contsecundargo,
                                    first_value(nct1.codcentrus) OVER (PARTITION BY nct1.codcont ORDER BY (nct1.anstart * 12::numeric + nct1.lunastart) DESC) AS codcentrus,
                                    first_value(nct1.codcentrusg) OVER (PARTITION BY nct1.codcont ORDER BY (nct1.anstart * 12::numeric + nct1.lunastart) DESC) AS codcentrusg,
                                    first_value(nct1.codcentrusgo) OVER (PARTITION BY nct1.codcont ORDER BY (nct1.anstart * 12::numeric + nct1.lunastart) DESC) AS codcentrusgo,
                                    nct1.codcont
                                   FROM martor.ncont1 nct1
                                  WHERE (nct1.anstart * 12::numeric + nct1.lunastart) &lt;= (( SELECT pkg_globals_anlunalucru.wme_result
   FROM martor.pkg_globals_anlunalucru(NULL::numeric, NULL::numeric) pkg_globals_anlunalucru(wme_result, fakeparam)))) inr
                             LEFT JOIN martor.ncontt ntt ON ntt.codcontt = inr.conttertiar
                             LEFT JOIN martor.nconts ncts1 ON ncts1.codconts = inr.contsecundar
                             LEFT JOIN martor.nconts ncts2 ON ncts2.codconts = inr.contsecundarg
                             LEFT JOIN martor.nconts ncts3 ON ncts3.codconts = inr.contsecundargo
                             LEFT JOIN martor.centrecost ccs1 ON ccs1.codcentru = inr.codcentrus
                             LEFT JOIN martor.centrecost ccs2 ON ccs2.codcentru = inr.codcentrusg
                             LEFT JOIN martor.centrecost ccs3 ON ccs3.codcentru = inr.codcentrusgo) n5 ON n5.codcont = v.codcont) a_pg
          GROUP BY a_pg.codcont, a_pg.simbol, a_pg.clasa, a_pg.den_cont, a_pg.name, a_pg.tipcont, a_pg.tip, a_pg.vizibilbalanta, a_pg.balantasintetica, a_pg.nivel, a_pg.codparinte, a_pg.activ, a_pg.anlunainactiv, a_pg.copil, a_pg.simbolsitfin, a_pg.simboltertiar, a_pg.codsaft, a_pg.taxtype, a_pg.simb_contsecundar, a_pg.simb_contsecundarg, a_pg.simb_contsecundargo, a_pg.simb_codcentrus, a_pg.simb_codcentrusg, a_pg.simb_codcentrusgo, a_pg.taxcode, a_pg.impozit) b_pg;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_ncontrep</obj_name>
  <obj_hashval>68a025bc0ef5b74e8045416a03aac2d4</obj_hashval>
  <obj_text>SELECT codcontrep,
    codcont
   FROM martor.ncontrep
  WHERE codcont = (( SELECT pkg_planconturi_getcodcontrep.wme_result
           FROM martor.pkg_planconturi_getcodcontrep(NULL::numeric, NULL::numeric) pkg_planconturi_getcodcontrep(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_nconts</obj_name>
  <obj_hashval>79b56991f441bff96ab4a110ff301431</obj_hashval>
  <obj_text>WITH RECURSIVE a AS (
         SELECT v.codconts,
            v.simbol,
            v.clasa,
            v.den_cont,
            v.name,
                CASE
                    WHEN COALESCE(v.tipcont, 0::numeric) = 0::numeric THEN 'ACTIV'::character varying
                    WHEN COALESCE(v.tipcont, 0::numeric) = 1::numeric THEN 'PASIV'::character varying
                    WHEN COALESCE(v.tipcont, 0::numeric) = 2::numeric THEN 'BIFUNC'::character varying
                    ELSE NULL::character varying
                END AS tip,
            v.vizibilbalanta,
            v.balantasintetica,
            v.nivel,
            v.codparinte,
            1 AS lev,
            COALESCE(n1.codconts, 0::numeric) AS activ,
            COALESCE(n2.codparinte, 0::numeric) AS copil,
            n4.anstart,
            n4.lunastart,
            n4.anstart * 12::numeric + n4.lunastart AS copiiactivi
           FROM martor.nconts v
             LEFT JOIN martor.nconts1 n1 ON n1.codconts = v.codconts AND (n1.anstart * 12::numeric + n1.lunastart) &lt;= martor.getanlunalucru()
             LEFT JOIN martor.nconts n2 ON n2.codparinte = v.codconts
             LEFT JOIN martor.nconts1 n4 ON n4.codconts = n2.codconts
          WHERE v.codparinte IS NULL
        UNION ALL
         SELECT v1.codconts,
            v1.simbol,
            v1.clasa,
            v1.den_cont,
            v1.name,
                CASE
                    WHEN COALESCE(v1.tipcont, 0::numeric) = 0::numeric THEN 'ACTIV'::character varying
                    WHEN COALESCE(v1.tipcont, 0::numeric) = 1::numeric THEN 'PASIV'::character varying
                    WHEN COALESCE(v1.tipcont, 0::numeric) = 2::numeric THEN 'BIFUNC'::character varying
                    ELSE NULL::character varying
                END AS tip,
            v1.vizibilbalanta,
            v1.balantasintetica,
            v1.nivel,
            v1.codparinte,
            a_1.lev + 1,
            COALESCE(n11.codconts, 0::numeric) AS activ,
            COALESCE(n21.codparinte, 0::numeric) AS copil,
            n41.anstart,
            n41.lunastart,
            n41.anstart * 12::numeric + n41.lunastart AS copiiactivi
           FROM martor.nconts v1
             LEFT JOIN martor.nconts1 n11 ON n11.codconts = v1.codconts AND (n11.anstart * 12::numeric + n11.lunastart) &lt;= martor.getanlunalucru()
             LEFT JOIN martor.nconts n21 ON n21.codparinte = v1.codconts
             LEFT JOIN martor.nconts1 n41 ON n41.codconts = n21.codconts
             JOIN a a_1 ON a_1.codconts = v1.codparinte
        )
 SELECT codconts,
    simbol,
    clasa,
    den_cont,
    name,
    tip,
    vizibilbalanta,
    balantasintetica,
    nivel,
    codparinte,
    lev,
    activ,
    copil,
    min(copiiactivi) AS copiiactivi
   FROM a
  GROUP BY codconts, simbol, clasa, den_cont, name, tip, vizibilbalanta, balantasintetica, nivel, codparinte, lev, activ, copil;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_ncontt</obj_name>
  <obj_hashval>8899fb8c7c83f21d0ef1282223f0ff3c</obj_hashval>
  <obj_text>SELECT codcontt,
    simbol,
    clasa,
    den_cont,
    name,
    tip,
    vizibilbalanta,
    balantasintetica,
    nivel,
    codparinte,
    lev,
    activ,
    copil,
    min(anstart * 12::numeric + lunastart) AS copiiactivi
   FROM ( WITH RECURSIVE ncontrec AS (
                 SELECT v1.codcontt,
                    v1.simbol,
                    v1.clasa,
                    v1.den_cont,
                    v1.name,
                    v1.tipcont,
                    v1.vizibilbalanta,
                    v1.balantasintetica,
                    v1.nivel,
                    v1.codparinte,
                    0 AS lev
                   FROM martor.ncontt v1
                  WHERE v1.codparinte IS NULL
                UNION ALL
                 SELECT v2.codcontt,
                    v2.simbol,
                    v2.clasa,
                    v2.den_cont,
                    v2.name,
                    v2.tipcont,
                    v2.vizibilbalanta,
                    v2.balantasintetica,
                    v2.nivel,
                    v2.codparinte,
                    nr.lev + 1
                   FROM martor.ncontt v2
                     JOIN ncontrec nr ON nr.codcontt = v2.codparinte
                )
         SELECT v.codcontt,
            v.simbol,
            v.clasa,
            v.den_cont,
            v.name,
                CASE
                    WHEN COALESCE(v.tipcont, 0::numeric) = 0::numeric THEN 'ACTIV'::text
                    WHEN COALESCE(v.tipcont, 0::numeric) = 1::numeric THEN 'PASIV'::text
                    WHEN COALESCE(v.tipcont, 0::numeric) = 2::numeric THEN 'BIFUNC'::text
                    ELSE NULL::text
                END::character varying AS tip,
            v.vizibilbalanta,
            v.balantasintetica,
            v.nivel,
            v.codparinte,
            v.lev,
            COALESCE(n1.codcontt, 0::numeric) AS activ,
            COALESCE(n2.codparinte, 0::numeric) AS copil,
            n4.anstart,
            n4.lunastart
           FROM ncontrec v
             LEFT JOIN martor.ncontt1 n1 ON n1.codcontt = v.codcontt AND (n1.anstart * 12::numeric + n1.lunastart) &lt;= (( SELECT pkg_globals_anlunalucru.wme_result
                   FROM martor.pkg_globals_anlunalucru(NULL::numeric, NULL::numeric) pkg_globals_anlunalucru(wme_result, fakeparam)))
             LEFT JOIN martor.ncontt n2 ON n2.codparinte = v.codcontt
             LEFT JOIN martor.ncontt1 n4 ON n4.codcontt = n2.codcontt) a_pg
  GROUP BY codcontt, simbol, clasa, den_cont, name, tip, vizibilbalanta, balantasintetica, nivel, codparinte, lev, activ, copil;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_ngest</obj_name>
  <obj_hashval>f46e711b1c4aa40ed46b12703befd7d5</obj_hashval>
  <obj_text>SELECT t1.codgest,
    t1.den_gest,
    t1.simbol,
    t1.codactivit,
    t2.den_localit,
    t3.den_judet,
    t3.simbauto,
    t4.den_activit,
    t1.codcatpret,
    sub.den_subunit,
        CASE COALESCE(g.tip, 0::numeric)
            WHEN 0 THEN 'Depozit sau Auxiliare'::text
            WHEN 1 THEN 'Magazin'::text
            WHEN 2 THEN 'Sectie productie'::text
            WHEN 3 THEN 'Depozit de sectie'::text
            WHEN 4 THEN 'Stocuri neconforme'::text
            WHEN 5 THEN 'Parcela agricola'::text
            WHEN 6 THEN 'Camera'::text
            WHEN 7 THEN 'Parc auto'::text
            ELSE NULL::text
        END::character varying AS tip,
    t1.obs_gest,
    t1.clasa_caract,
    t1.inactiv,
    t1.gest_principal
   FROM ( SELECT a.codgest,
            a.den_gest,
            a.simbol,
            a.codactivit,
            a.codcatpret,
            a.codsubunit,
            b.codlocalit,
            count(*) AS nrinreg,
            a.obs AS obs_gest,
            ncl.den_claseg AS clasa_caract,
            a.inactiv,
            a.gmaster AS gest_principal
           FROM martor.ngest a
             LEFT JOIN martor.nagenda b ON a.codgest = b.codgest
             LEFT JOIN martor.ncatpret cat ON cat.codcatpret = a.codcatpret
             LEFT JOIN martor.nclaseg ncl ON ncl.codclaseg = a.codclasa
          WHERE (( SELECT pkg_nomgest_gestiune_dedicata.wme_result
                   FROM martor.pkg_nomgest_gestiune_dedicata(NULL::numeric, a.codgest) pkg_nomgest_gestiune_dedicata(wme_result, acodgest))) = 1::numeric AND (martor.fnc_getvalconstantalucru('Holding'::character varying)::text &lt;&gt; '1'::text OR martor.fnc_getvalconstantalucru('Holding'::character varying)::text = '1'::text AND (a.codsubunit = martor.getsubunitate() OR martor.getsubunitate() = 1::numeric))
          GROUP BY a.codgest, a.den_gest, a.simbol, a.codactivit, a.codcatpret, a.codsubunit, b.codlocalit, a.obs, ncl.den_claseg, a.inactiv, a.gmaster) t1
     JOIN martor.ngest g ON t1.codgest = g.codgest
     LEFT JOIN martor.nlocalit t2 ON t1.codlocalit = t2.codlocalit
     LEFT JOIN martor.njudet t3 ON t2.codjudet = t3.codjudet
     LEFT JOIN martor.nactivit t4 ON t1.codactivit = t4.codactivit
     LEFT JOIN martor.nsubunit sub ON t1.codsubunit = sub.codsubunit
  WHERE t1.nrinreg = 1;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_niruri_luna</obj_name>
  <obj_hashval>5da05594eef7b887529ef97b04a47dd3</obj_hashval>
  <obj_text>SELECT ns.codnirstoc,
    ns.cantnir AS rest,
    ns.cantum1 AS restum1,
    ns.cantum2 AS restum2
   FROM martor.intrari i
     JOIN martor.nir n ON n.codintr = i.codintr AND n.tipnir = i.tipdoc
     JOIN martor.nirstoc ns ON ns.codnir = n.codnir
     JOIN martor.ioart1 io ON io.codioart = ns.codioart AND (i.an * 12::numeric + i.luna) &gt;= io.alstart AND (i.an * 12::numeric + i.luna) &lt;= io.alstop
  WHERE i.operat = 1::numeric AND i.anulat = 0::numeric AND (i.tipdoc = ANY (ARRAY[1::numeric, 2::numeric, 3::numeric, 4::numeric, 5::numeric, 6::numeric, 7::numeric])) AND i.an = (( SELECT pkg_globals_getantemp.wme_result
           FROM martor.pkg_globals_getantemp(NULL::numeric, NULL::numeric) pkg_globals_getantemp(wme_result, fakeparam))) AND i.luna = (( SELECT pkg_globals_getlunatemp.wme_result
           FROM martor.pkg_globals_getlunatemp(NULL::numeric, NULL::numeric) pkg_globals_getlunatemp(wme_result, fakeparam))) AND n.anulat = 0::numeric AND n.operat = 1::numeric AND io.mg &lt;&gt; 5::numeric
UNION ALL
 SELECT ns.codnirstoc,
    ns.cantnir AS rest,
    ns.cantum1 AS restum1,
    ns.cantum2 AS restum2
   FROM martor.iesiri i
     JOIN martor.nir n ON n.codies = i.codies AND n.tipnir = i.tipdoc
     JOIN martor.nirstoc ns ON ns.codnir = n.codnir
     JOIN martor.ioart1 io ON io.codioart = ns.codioart AND (i.an * 12::numeric + i.luna) &gt;= io.alstart AND (i.an * 12::numeric + i.luna) &lt;= io.alstop
  WHERE i.operat = 1::numeric AND i.anulat = 0::numeric AND (i.tipdoc = ANY (ARRAY[14::numeric, 15::numeric, 19::numeric, 20::numeric, 21::numeric, 22::numeric, 23::numeric, 24::numeric, 25::numeric])) AND i.an = (( SELECT pkg_globals_getantemp.wme_result
           FROM martor.pkg_globals_getantemp(NULL::numeric, NULL::numeric) pkg_globals_getantemp(wme_result, fakeparam))) AND i.luna = (( SELECT pkg_globals_getlunatemp.wme_result
           FROM martor.pkg_globals_getlunatemp(NULL::numeric, NULL::numeric) pkg_globals_getlunatemp(wme_result, fakeparam))) AND n.anulat = 0::numeric AND n.operat = 1::numeric AND io.mg &lt;&gt; 5::numeric
UNION ALL
 SELECT ns.codnirstoc,
    ns.cantnir AS rest,
    ns.cantum1 AS restum1,
    ns.cantum2 AS restum2
   FROM martor.transf t
     JOIN martor.nir n ON n.codtransf = t.codtransf AND n.tipnir = t.tipdoc
     JOIN martor.nirstoc ns ON ns.codnir = n.codnir
     JOIN martor.ioart1 io ON io.codioart = ns.codioart AND (t.an * 12::numeric + t.luna) &gt;= io.alstart AND (t.an * 12::numeric + t.luna) &lt;= io.alstop
  WHERE t.operat = 1::numeric AND t.anulat = 0::numeric AND (t.tipdoc = ANY (ARRAY[12::numeric, 13::numeric])) AND t.an = (( SELECT pkg_globals_getantemp.wme_result
           FROM martor.pkg_globals_getantemp(NULL::numeric, NULL::numeric) pkg_globals_getantemp(wme_result, fakeparam))) AND t.luna = (( SELECT pkg_globals_getlunatemp.wme_result
           FROM martor.pkg_globals_getlunatemp(NULL::numeric, NULL::numeric) pkg_globals_getlunatemp(wme_result, fakeparam))) AND n.anulat = 0::numeric AND n.operat = 1::numeric AND io.mg &lt;&gt; 5::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_nmeserii</obj_name>
  <obj_hashval>2deaf5c7dac61a68782daa0f1160e48d</obj_hashval>
  <obj_text>SELECT codmeserie,
    den_meserie
   FROM martor.nmeserii;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_nodurianaliza</obj_name>
  <obj_hashval>878018141963dd743a294ef61713a582</obj_hashval>
  <obj_text>WITH RECURSIVE reca(codanalizanod, codanaliza, coddescriptor1, nodparinte, inactiv, simbolnod, tip, nivel, codasociat, simbol, denumire, sepa) AS (
         SELECT an.codanalizanod,
            an.codanaliza,
            an.coddescriptor1,
            an.nodparinte,
            an.inactiv,
            an.simbolnod,
            COALESCE(an.tip, d.tip) AS tip,
            0 AS nivel,
            d1.codasociat,
                CASE
                    WHEN aa.tip = 1::numeric THEN an.simbolnod::text
                    ELSE lpad(an.pozitie::text, 2, '0'::text)
                END::character varying AS simbol,
                CASE
                    WHEN aa.tip = 1::numeric THEN an.dennod
                    ELSE d1.valoare
                END AS denumire,
            gsa.sepa
           FROM martor.analizanod an
             LEFT JOIN martor.analiza aa ON aa.codanaliza = an.codanaliza
             LEFT JOIN martor.descriptori1 d1 ON an.coddescriptor1 = d1.coddescriptor1
             LEFT JOIN martor.descriptori d ON d.coddescriptor = d1.coddescriptor
             CROSS JOIN ( SELECT pkg_globals_getseparatoradancime.wme_result AS sepa
                   FROM martor.pkg_globals_getseparatoradancime(NULL::bpchar, NULL::numeric) pkg_globals_getseparatoradancime(wme_result, fakeparam)) gsa
          WHERE an.nodparinte = 0::numeric
        UNION ALL
         SELECT an.codanalizanod,
            an.codanaliza,
            an.coddescriptor1,
            an.nodparinte,
            an.inactiv,
            an.simbolnod,
            COALESCE(an.tip, d.tip) AS tip,
            reca.nivel + 1 AS nivel,
            d1.codasociat,
                CASE
                    WHEN aa.tip = 1::numeric THEN an.simbolnod::text
                    WHEN reca.nivel = 0 THEN lpad(an.pozitie::text, 2, '0'::text)
                    ELSE (reca.simbol::text || '.'::text) || lpad(an.pozitie::text, 2, '0'::text)
                END::character varying AS simbol,
                CASE
                    WHEN aa.tip = 1::numeric THEN an.dennod::text
                    WHEN reca.nivel = 0 THEN d1.valoare::text
                    ELSE (reca.denumire::text || reca.sepa::text) || d1.valoare::text
                END::character varying AS denumire,
            reca.sepa
           FROM reca
             JOIN martor.analizanod an ON an.nodparinte = reca.codanalizanod
             LEFT JOIN martor.analiza aa ON aa.codanaliza = an.codanaliza
             LEFT JOIN martor.descriptori1 d1 ON an.coddescriptor1 = d1.coddescriptor1
             LEFT JOIN martor.descriptori d ON d.coddescriptor = d1.coddescriptor
        )
 SELECT DISTINCT v.codanalizanod,
    v.simbol,
    v.denumire,
    v.nivel,
    v.nodparinte,
    COALESCE(n.nodparinte, 0::numeric) AS copil,
    v.codanaliza,
    v.codasociat,
    v.tip,
    v.simbolnod,
    d1.valoare AS dennod
   FROM reca v
     JOIN martor.analizanod a ON a.codanalizanod = v.codanalizanod
     LEFT JOIN martor.descriptori1 d1 ON d1.coddescriptor1 = a.coddescriptor1
     LEFT JOIN martor.analizanod n ON n.nodparinte = v.codanalizanod
  WHERE COALESCE(v.nodparinte, 0::numeric) &lt;&gt; 0::numeric AND COALESCE(v.inactiv, 0::numeric) &lt;&gt; 1::numeric
UNION ALL
 SELECT 0 AS codanalizanod,
    '0'::text AS simbol,
    '... nedefinita ...'::character varying AS denumire,
    0 AS nivel,
    0 AS nodparinte,
    0 AS copil,
    0 AS codanaliza,
    0 AS codasociat,
    0 AS tip,
    '?'::character varying AS simbolnod,
    '... nedefinita ...'::character varying AS dennod;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_nparcaut</obj_name>
  <obj_hashval>5b1452cdde7064d3d30d5018e6340c61</obj_hashval>
  <obj_text>SELECT pa.codnparcaut,
    pa.codart,
    COALESCE(pa.tip, 0::numeric) AS tip,
    pa.nrinv,
    pa.nrinreg,
    pa.sofer,
    ((npers.nume::text || ' '::character varying::text) || npers.prenume::text)::character varying AS densofer,
    npers.marca,
    nartobj.denumire AS denart,
    pa.masau,
    pa.volumu,
    pa.lung,
    pa.lat,
    pa.inalt,
    NULL::text AS codmifix,
    pa.putere,
    pa.tipincarc,
    pa.cmm,
    pa.extern,
    pa.partener,
    pa.model AS codmodel,
    pa.marca AS codmarca,
    nma.marca AS marcaauto,
    nmo.model AS modelauto,
    sub.den_subunit,
    COALESCE(pa.codgest, 0::numeric) AS codgest,
    COALESCE(g.codsubunit, 0::numeric) AS codsubunit,
    e.codgrupa,
    gre.denumire AS denclasa,
    COALESCE(gre.ind, 0::numeric) AS ind,
    g.den_gest,
    COALESCE(pa.inactiv, 0::numeric) AS inactiv,
        CASE COALESCE(pa.inactiv, 0::numeric)
            WHEN 0 THEN 'Activ'::character varying
            WHEN 2 THEN 'Conservare'::character varying
            WHEN 3 THEN 'Dauna totala'::character varying
            WHEN 4 THEN 'La vanzare'::character varying
            WHEN 1 THEN 'Vandut'::character varying
            WHEN 5 THEN 'Radiat'::character varying
            ELSE NULL::character varying
        END AS stare,
    pa.seriec,
    e.generic,
    pa.nrcontr,
    rem.spor_150_1,
    rem.spor_150_2,
    rem.spor150_215_1,
    rem.spor150_215_2,
    rem.spor215_1,
    rem.spor215_2,
    pa.consstath,
    p.den_part,
    dl.den_part AS dealer
   FROM martor.nparcaut pa
     LEFT JOIN martor.npers ON pa.sofer = npers.codpers
     LEFT JOIN martor.nartobj ON pa.codart = nartobj.codobiect
     LEFT JOIN martor.nechiv e ON e.codobiect = nartobj.codobiect
     LEFT JOIN martor.grechiv gre ON gre.codgrechiv = e.codgrupa
     LEFT JOIN martor.nmarciauto nma ON nma.codmarciauto = pa.marca
     LEFT JOIN martor.nmodeleauto nmo ON nmo.codmodeleauto = pa.model
     LEFT JOIN martor.ngest g ON g.codgest = pa.codgest
     LEFT JOIN martor.npart p ON p.codpart = pa.partener
     LEFT JOIN martor.npart dl ON dl.codpart = pa.coddealer
     LEFT JOIN martor.nsubunit sub ON sub.codsubunit = g.codsubunit
     LEFT JOIN martor.nremauto rem ON rem.codremauto = pa.tiprem;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_nparcaut_sofer</obj_name>
  <obj_hashval>520e167a47170ff0b045c6e32348ba01</obj_hashval>
  <obj_text>SELECT nparcaut.codnparcaut,
    nparcaut.codart,
    nparcaut.nrinv,
    nparcaut.nrinreg,
    nparcaut.sofer,
    (npers.nume::text || ' '::text) || npers.prenume::text AS densofer,
    nartobj.denumire AS denart,
    COALESCE(nparcaut.inactiv, 0::numeric) AS inactiv
   FROM martor.nparcaut
     LEFT JOIN martor.npers ON nparcaut.sofer = npers.codpers
     LEFT JOIN martor.nartobj ON nparcaut.codart = nartobj.codobiect
  WHERE nparcaut.sofer = (( SELECT pkg_nompers_get_persoana_curenta.wme_result
           FROM martor.pkg_nompers_get_persoana_curenta(NULL::numeric, NULL::numeric) pkg_nompers_get_persoana_curenta(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_npart</obj_name>
  <obj_hashval>1d18bb613eafeddaa213380683ac184f</obj_hashval>
  <obj_text>SELECT p.codpart,
    p.den_part,
    p.codextern,
    p.codintern,
    a.codagent,
    p.codmoneda,
    l.den_localit,
    f.cod_codfiscal,
    f.codfiscal,
    p.blocat,
    p.scadentac,
    p.scadentav,
    t.statcomunitar,
    t.den_tara,
    cat.tip AS tipcatpret,
    cat.codcatpret,
    p.tippartener,
    p.autorizatie,
    p.strategic,
    p.lead,
    j.simbauto,
    p.codclasa,
    crm.cifraafaceri,
    dax.dendomeniuact::character varying AS dendomeniuact,
    ((np.prenume::text || ' '::text) || np.nume::text)::character varying AS responsabilsrv,
    crm.nrangajati,
    p.regcom,
    j.den_judet,
    (npa.prenume::text || ' '::text) || npa.nume::text AS agent,
    c.dencampanie,
    ( SELECT pkg_nompart_get_partactivit.wme_result
           FROM martor.pkg_nompart_get_partactivit(NULL::character varying, p.codpart) pkg_nompart_get_partactivit(wme_result, acodpart)) AS activitproprie,
    clp.simbol AS simbolclasa,
    p.obs,
    p.iescucomanda,
    pb.contbanca,
    p.persoanafizica,
    p.dataadaugarii
   FROM martor.npart p
     LEFT JOIN martor.ncatpret cat ON cat.codcatpret = p.codcategpret
     LEFT JOIN martor.npartcodfisc f ON f.codpart = p.codpart AND f.principal = 1::numeric
     LEFT JOIN martor.nagenda a ON a.codpart = p.codpart AND COALESCE(a.inactiv, 0::numeric) = 0::numeric AND (a.sediusocial::integer &amp; 4) &lt;&gt; 0
     LEFT JOIN martor.nlocalit l ON l.codlocalit = a.codlocalit
     LEFT JOIN martor.njudet j ON j.codjudet = l.codjudet
     LEFT JOIN martor.ntari t ON t.codtara = l.codtara
     LEFT JOIN martor.domeniiact da ON da.coddomeniuact = p.coddomeniuact
     LEFT JOIN martor.npers np ON np.codpers = p.codresponsabil
     LEFT JOIN martor.npers npa ON npa.codpers = a.codagent
     LEFT JOIN martor.nclasep clp ON clp.codclasep = p.codclasa
     LEFT JOIN martor.npartb pb ON pb.codpart = p.codpart AND COALESCE(pb.implicit, 0::numeric) = 1::numeric
     LEFT JOIN ( SELECT DISTINCT ON (ccp.codpart) ccp.codpart,
            ccp.codcampaniepart
           FROM martor.campaniipart ccp
             JOIN martor.campanii cc ON cc.codcampanie = ccp.codcampanie
          ORDER BY ccp.codpart, cc.datainit DESC) xc ON xc.codpart = p.codpart
     LEFT JOIN ( SELECT string_agg(d.dendomeniuact::text, ';'::text) AS dendomeniuact,
            n1.codpart
           FROM martor.npartdomact nd
             JOIN martor.npart1crm n1 ON nd.codpart1crm = n1.codpart1crm AND n1.codpart = nd.codpart
             JOIN martor.domeniiact d ON d.coddomeniuact = nd.coddomeniuact
          WHERE last_day(to_date((('01.'::text || lpad(martor.getlunalucru()::character varying::text, 2, '0'::text)) || '.'::text) || martor.getanlucru()::character varying::text, 'dd.mm.yyyy'::text)) &gt;= n1.datastart AND last_day(to_date((('01.'::text || lpad(martor.getlunalucru()::character varying::text, 2, '0'::text)) || '.'::text) || martor.getanlucru()::character varying::text, 'dd.mm.yyyy'::text)) &lt;= n1.dataend OR last_day(to_date((('01.'::text || lpad(martor.getlunalucru()::character varying::text, 2, '0'::text)) || '.'::text) || martor.getanlucru()::character varying::text, 'dd.mm.yyyy'::text)) &gt;= n1.datastart AND n1.dataend IS NULL
          GROUP BY n1.codpart) dax ON dax.codpart = p.codpart
     LEFT JOIN ( SELECT n1.codpart,
            n1.nrangajati,
            n1.cifraafaceri
           FROM martor.npart1crm n1
          WHERE last_day(to_date((('01.'::text || lpad(martor.getlunalucru()::character varying::text, 2, '0'::text)) || '.'::text) || martor.getanlucru()::character varying::text, 'dd.mm.yyyy'::text)) &gt;= n1.datastart AND last_day(to_date((('01.'::text || lpad(martor.getlunalucru()::character varying::text, 2, '0'::text)) || '.'::text) || martor.getanlucru()::character varying::text, 'dd.mm.yyyy'::text)) &lt;= n1.dataend OR last_day(to_date((('01.'::text || lpad(martor.getlunalucru()::character varying::text, 2, '0'::text)) || '.'::text) || martor.getanlucru()::character varying::text, 'dd.mm.yyyy'::text)) &gt;= n1.datastart AND n1.dataend IS NULL) crm ON crm.codpart = p.codpart
     LEFT JOIN martor.campaniipart cp ON cp.codcampaniepart = xc.codcampaniepart
     LEFT JOIN martor.campanii c ON c.codcampanie = cp.codcampanie;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_npart_leads</obj_name>
  <obj_hashval>a35a9d0bb1aecf2b6819774c10b34040</obj_hashval>
  <obj_text>SELECT p.codpart,
    p.den_part,
    p.codextern,
    p.codintern,
    a.codagent,
    p.codmoneda,
    l.den_localit,
    f.cod_codfiscal,
    f.codfiscal,
    p.blocat,
    p.scadentac,
    p.scadentav,
    t.statcomunitar,
    t.den_tara,
    cat.tip AS tipcatpret,
    cat.codcatpret,
    p.tippartener,
    p.autorizatie,
    p.strategic,
    COALESCE(leads.lead, 0::numeric) AS lead,
    j.simbauto,
    p.codclasa,
    p.cifraafaceri,
    dax.dendomeniuact,
    ((np.prenume::text || ' '::character varying::text) || np.nume::text)::character varying AS responsabilsrv,
    p.nrangajati,
    p.regcom,
    j.den_judet,
    ((npa.prenume::text || ' '::character varying::text) || npa.nume::text)::character varying AS agent,
    c.dencampanie,
    ( SELECT pkg_nompart_get_partactivit.wme_result
           FROM martor.pkg_nompart_get_partactivit(NULL::character varying, p.codpart) pkg_nompart_get_partactivit(wme_result, acodpart)) AS activitproprie,
    cp.simbol AS simbolclasa,
    p.obs,
    p.iescucomanda,
    pb.contbanca
   FROM martor.npart p
     LEFT JOIN martor.ncatpret cat ON cat.codcatpret = p.codcategpret
     LEFT JOIN martor.npartcodfisc f ON f.codpart = p.codpart AND f.principal = 1::numeric
     LEFT JOIN martor.nagenda a ON a.codpart = p.codpart AND COALESCE(a.inactiv, 0::numeric) = 0::numeric AND (a.sediusocial::integer &amp; 4) &lt;&gt; 0
     LEFT JOIN martor.nlocalit l ON l.codlocalit = a.codlocalit
     LEFT JOIN martor.njudet j ON j.codjudet = l.codjudet
     LEFT JOIN martor.ntari t ON t.codtara = l.codtara
     LEFT JOIN martor.domeniiact da ON da.coddomeniuact = p.coddomeniuact
     LEFT JOIN martor.npers np ON np.codpers = p.codresponsabil
     LEFT JOIN martor.npers npa ON npa.codpers = a.codagent
     LEFT JOIN martor.nclasep cp ON cp.codclasep = p.codclasa
     LEFT JOIN martor.npartb pb ON pb.codpart = p.codpart AND COALESCE(pb.implicit, 0::numeric) = 1::numeric
     LEFT JOIN ( SELECT aa.codpart,
            max(aa.codcampaniepart) AS codcampaniepart
           FROM ( SELECT ccp.codpart,
                    ccp.codcampaniepart,
                    dense_rank() OVER (PARTITION BY ccp.codpart ORDER BY cc.datainit DESC) AS nr
                   FROM martor.campaniipart ccp
                     JOIN martor.campanii cc ON cc.codcampanie = ccp.codcampanie) aa
          WHERE aa.nr = 1
          GROUP BY aa.codpart) xc ON xc.codpart = p.codpart
     LEFT JOIN ( SELECT string_agg(d.dendomeniuact::text, ','::text)::character varying AS dendomeniuact,
            n1.codpart
           FROM martor.npartdomact nd
             JOIN martor.npart1crm n1 ON nd.codpart1crm = n1.codpart1crm AND n1.codpart = nd.codpart
             JOIN martor.domeniiact d ON d.coddomeniuact = nd.coddomeniuact
          WHERE last_day(to_date((('01.'::text || lpad(martor.getlunalucru()::character varying::text, 2, '0'::text)) || '.'::text) || martor.getanlucru()::character varying::text, 'dd.mm.yyyy'::text)) &gt;= n1.datastart AND last_day(to_date((('01.'::text || lpad(martor.getlunalucru()::character varying::text, 2, '0'::text)) || '.'::text) || martor.getanlucru()::character varying::text, 'dd.mm.yyyy'::text)) &lt;= COALESCE(n1.dataend, last_day(to_date((('01.'::text || lpad(martor.getlunalucru()::character varying::text, 2, '0'::text)) || '.'::text) || martor.getanlucru()::character varying::text, 'dd.mm.yyyy'::text)))
          GROUP BY n1.codpart) dax ON dax.codpart = p.codpart
     LEFT JOIN ( SELECT DISTINCT n1.codpart,
            last_value(n1.lead) OVER (PARTITION BY n1.codpart) AS lead
           FROM martor.npart1crm n1
          WHERE last_day(to_date((('01.'::text || lpad(martor.getlunalucru()::character varying::text, 2, '0'::text)) || '.'::text) || martor.getanlucru()::character varying::text, 'dd.mm.yyyy'::text)) &gt;= n1.datastart AND last_day(to_date((('01.'::text || lpad(martor.getlunalucru()::character varying::text, 2, '0'::text)) || '.'::text) || martor.getanlucru()::character varying::text, 'dd.mm.yyyy'::text)) &lt;= COALESCE(n1.dataend, last_day(to_date((('01.'::text || lpad(martor.getlunalucru()::character varying::text, 2, '0'::text)) || '.'::text) || martor.getanlucru()::character varying::text, 'dd.mm.yyyy'::text)))) leads ON leads.codpart = p.codpart
     LEFT JOIN martor.campaniipart cap ON cap.codcampaniepart = xc.codcampaniepart
     LEFT JOIN martor.campanii c ON c.codcampanie = cap.codcampanie;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_npart_luna</obj_name>
  <obj_hashval>bbda6e6c8c1b1c3b339285a87caa2afa</obj_hashval>
  <obj_text>SELECT n.codpart,
    n1.codpart1,
    n.den_part,
    COALESCE(n1.codiopart, 0::numeric) AS codiopart,
    n1.creditclient,
    n1.volumtranzc,
    n1.creditfurn,
    n1.volumtranzf,
    io1.codiopart1,
    io.den_iopart,
    io1.contfurnizor,
    io1.contclient,
    io1.contfurnavans,
    io1.contclientavans,
    io1.contfurnaviz,
    io1.contclientaviz,
    io1.contfurnmf,
    io1.contcreditd,
    io1.contdebitd,
    io1.contlitigii,
    io1.contfurnavs,
    io1.contfurnavic,
    io1.contfurnavin,
    io1.contterti,
    io1.contfurnleas,
    io1.contncrf,
    io1.contncrc,
    io1.contcheltavans,
    io1.contvenitavans,
    io1.contgarantieef,
    io1.contgarantietf,
    io1.contgarantieec,
    io1.contgarantietc,
    io1.contsuplimf1,
    io1.contsuplimf2,
    io1.contsuplimf3,
    io1.contsuplimf4,
    io1.contsuplimf5,
    io1.contsuplimc1,
    io1.contsuplimc2,
    io1.contsuplimc3,
    io1.contsuplimc4,
    io1.contsuplimc5,
    io1.tvaneexf,
    io1.tvaneexc,
    io1.tip,
    n1.cassbazamin,
    n1.simbolcass,
    io1.tvaneexp,
    io1.tvaneexi
   FROM martor.npart n
     LEFT JOIN martor.npart1 n1 ON n.codpart = n1.codpart
     LEFT JOIN martor.iopart io ON COALESCE(n1.codiopart, 0::numeric) = COALESCE(io.codiopart, 0::numeric)
     LEFT JOIN martor.iopart1 io1 ON io.codiopart = io1.codiopart
  WHERE (n1.anstart * 12::numeric + n1.lunastart) = (( SELECT max(np1.anstart * 12::numeric + np1.lunastart) AS max
           FROM martor.npart1 np1
          WHERE np1.codpart = n1.codpart AND (np1.anstart * 12::numeric + np1.lunastart) &lt;= (( SELECT pkg_globals_anlunalucru.wme_result
                   FROM martor.pkg_globals_anlunalucru(NULL::numeric, NULL::numeric) pkg_globals_anlunalucru(wme_result, fakeparam))))) AND (io1.anstart * 12::numeric + io1.lunastart) = (( SELECT max(i1.anstart * 12::numeric + i1.lunastart) AS max
           FROM martor.iopart1 i1
          WHERE i1.codiopart = io1.codiopart AND (i1.anstart * 12::numeric + i1.lunastart) &lt;= (( SELECT pkg_globals_anlunalucru.wme_result
                   FROM martor.pkg_globals_anlunalucru(NULL::numeric, NULL::numeric) pkg_globals_anlunalucru(wme_result, fakeparam)))));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_nsubunit</obj_name>
  <obj_hashval>a76e704aebfbf6163b1b0aea14fa6034</obj_hashval>
  <obj_text>SELECT t1.codsubunit,
    t1.den_subunit,
    t2.den_localit,
    t3.den_judet,
    t3.simbauto,
    t4.simbauto AS simbautotara,
    t4.statcomunitar,
    nbk.den_cont,
    nbk.nrcont,
    t2.codlocalit
   FROM ( SELECT a.codsubunit,
            a.codbankcont,
            a.den_subunit,
            count(*) AS nrinreg,
            b.codlocalit
           FROM martor.nsubunit a
             LEFT JOIN martor.nagenda b ON a.codsubunit = b.codsubunit
          WHERE a.codsubunit &lt;&gt; 1::numeric
          GROUP BY a.codsubunit, a.codbankcont, a.den_subunit, b.codlocalit) t1
     LEFT JOIN martor.nlocalit t2 ON t1.codlocalit = t2.codlocalit
     LEFT JOIN martor.njudet t3 ON t2.codjudet = t3.codjudet
     LEFT JOIN martor.ntari t4 ON t2.codtara = t4.codtara
     LEFT JOIN martor.nbankcont nbk ON t1.codbankcont = nbk.codbankcont
  WHERE t1.nrinreg = 1;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_ntva</obj_name>
  <obj_hashval>345ad92e799c031e14184ebe1a5b187c</obj_hashval>
  <obj_text>SELECT DISTINCT t.codtva,
    t.den_tva,
    COALESCE(t1.codtva, 0::numeric) AS activ,
    COALESCE(t1.procent, 0::numeric) AS procent
   FROM martor.ntva t
     LEFT JOIN martor.ntva1 t1 ON t1.codtva = t.codtva
  WHERE (t1.anstart * 12::numeric + t1.lunastart) = (( SELECT max(t2.anstart * 12::numeric + t2.lunastart) AS max
           FROM martor.ntva1 t2
          WHERE t2.codtva = t.codtva AND (t2.anstart * 12::numeric + t2.lunastart) &lt;= (( SELECT pkg_globals_anlunalucru.wme_result
                   FROM martor.pkg_globals_anlunalucru(NULL::numeric, NULL::numeric) pkg_globals_anlunalucru(wme_result, fakeparam)))));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_obiecteechivalente</obj_name>
  <obj_hashval>eda6570b46c55e2bfc8b1780345d526c</obj_hashval>
  <obj_text>SELECT o.codextern,
    o.codintern,
    o.denumire AS den_obiect,
        CASE
            WHEN a.sufixcodextern IS NOT NULL THEN ((COALESCE(a.codexternart, ''::character varying)::text || ' '::text) || COALESCE(a.sufixcodextern, ''::character varying)::text)::character varying
            ELSE a.codexternart
        END AS codexternart
   FROM martor.nartobj o
     LEFT JOIN martor.nart a ON a.codarticol = o.codarticol;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_obiecteechivalente_cumul</obj_name>
  <obj_hashval>e7ae0bb0b9511da80e1ac516bf6ac2de</obj_hashval>
  <obj_text>SELECT o.codobiect,
    o.denumire AS denobiect,
    o.codextern,
    e.paritate,
    0 AS codgrupa,
    e.paritate * 0::numeric AS necesar,
    'ECH.RETETA'::character varying AS tip
   FROM martor.prodmatechiv e
     JOIN martor.nartobj o ON e.codobiect = o.codobiect
  WHERE e.codmat = (( SELECT pkg_prodcomp_get_mat_echivalat.wme_result
           FROM martor.pkg_prodcomp_get_mat_echivalat(NULL::numeric, NULL::numeric) pkg_prodcomp_get_mat_echivalat(wme_result, fakeparam)))
UNION ALL
 SELECT o.codobiect,
    o.denumire AS denobiect,
    o.codextern,
    e.paritate,
    e.codgrupa,
    e.paritate * 0::numeric AS necesar,
    'ECH.GRUPA'::character varying AS tip
   FROM martor.nechiv e
     JOIN martor.nartobj o ON e.codobiect = o.codobiect
  WHERE e.codgrupa = (( SELECT pkg_selectarticole_get_grupa_obiect_echivalat.wme_result
           FROM martor.pkg_selectarticole_get_grupa_obiect_echivalat(NULL::numeric, NULL::numeric) pkg_selectarticole_get_grupa_obiect_echivalat(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_obiecteechivalente_simplu</obj_name>
  <obj_hashval>4e8354647e689f7273dcfb79833ebc94</obj_hashval>
  <obj_text>SELECT o.codobiect,
    o.denumire AS denobiect,
    o.codextern,
    e.paritate / (( SELECT pkg_selectarticole_get_paritate_obiect_echivalat.wme_result
           FROM martor.pkg_selectarticole_get_paritate_obiect_echivalat(NULL::numeric, NULL::numeric) pkg_selectarticole_get_paritate_obiect_echivalat(wme_result, fakeparam))) AS paritate,
    e.codgrupa,
    e.paritate * 0::numeric AS necesar,
    o.codintern
   FROM martor.nechiv e
     JOIN martor.nartobj o ON e.codobiect = o.codobiect
  WHERE e.codgrupa = (( SELECT pkg_selectarticole_get_grupa_obiect_echivalat.wme_result
           FROM martor.pkg_selectarticole_get_grupa_obiect_echivalat(NULL::numeric, NULL::numeric) pkg_selectarticole_get_grupa_obiect_echivalat(wme_result, fakeparam)))
UNION ALL
 SELECT 0 AS codobiect,
    '..nedefinit..'::character varying AS denobiect,
    NULL::character varying AS codextern,
    1 AS paritate,
    0 AS codgrupa,
    1 AS necesar,
    NULL::character varying AS codintern;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_objart_simplu</obj_name>
  <obj_hashval>cb7953f349c5e9f1c1f7a6b7aae92a1d</obj_hashval>
  <obj_text>SELECT o.denumire,
    o.codextern,
    o.codintern,
        CASE
            WHEN a.sufixcodextern IS NOT NULL THEN ((COALESCE(a.codexternart, ''::character varying)::text || ' '::text) || COALESCE(a.sufixcodextern, ''::character varying)::text)::character varying
            ELSE a.codexternart
        END AS codexternart
   FROM martor.nartobj o
     LEFT JOIN martor.nart a ON a.codarticol = o.codarticol;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_obligpif_de_stins_luna</obj_name>
  <obj_hashval>3465ba17d021c46f21c151e7acdbbb1b</obj_hashval>
  <obj_text>SELECT o.codobligpif,
    o.valoare AS rest,
    COALESCE(g.tva, 0::numeric) AS resttva,
    COALESCE(o.dincaretva, 0::numeric) AS restsplittva
   FROM martor.obligpif o
     LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
     LEFT JOIN martor.intrari i ON i.codintr = g.coddoc
  WHERE o.semnificatie = 100::numeric AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND i.operat = 1::numeric AND i.anulat = 0::numeric
UNION ALL
 SELECT o.codobligpif,
    o.valoare AS rest,
    COALESCE(g.tva, 0::numeric) AS resttva,
    COALESCE(o.dincaretva, 0::numeric) AS restsplittva
   FROM martor.obligpif o
     LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
     LEFT JOIN martor.intrari i ON i.codintr = g.coddoc
  WHERE o.semnificatie = 140::numeric AND i.tipdoc = 2::numeric AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND i.operat = 1::numeric AND i.anulat = 0::numeric
UNION ALL
 SELECT o.codobligpif,
    o.valoare AS rest,
        CASE
            WHEN (o.valoare * COALESCE(g.tva, 0::numeric)) = 0::numeric THEN 0::numeric
            WHEN (( SELECT sum(os.valoare) AS sum
               FROM martor.obligpif os
              WHERE os.codgeneral = o.codgeneral)) = 0::numeric THEN 0::numeric
            ELSE o.valoare * COALESCE(g.tva, 0::numeric) / (( SELECT sum(os.valoare) AS sum
               FROM martor.obligpif os
              WHERE os.codgeneral = o.codgeneral))
        END AS resttva,
    COALESCE(o.dincaretva, 0::numeric) AS restsplittva
   FROM martor.obligpif o
     LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
     LEFT JOIN martor.intrari i ON i.codintr = g.coddoc
  WHERE (o.semnificatie = ANY (ARRAY[110::numeric, 120::numeric])) AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND i.operat = 1::numeric AND i.anulat = 0::numeric
UNION ALL
 SELECT o.codobligpif,
    o.valoare AS rest,
    COALESCE(g.tva, 0::numeric) AS resttva,
    COALESCE(o.dincaretva, 0::numeric) AS restsplittva
   FROM martor.obligpif o
     LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
     LEFT JOIN martor.dvi d ON g.coddoc = d.coddvi
     LEFT JOIN martor.intrari i ON i.codintr = d.codintr
  WHERE o.semnificatie = 130::numeric AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND i.operat = 1::numeric AND i.anulat = 0::numeric
UNION ALL
 SELECT o.codobligpif,
    o.valoare AS rest,
    COALESCE(g.tva, 0::numeric) AS resttva,
    COALESCE(o.dincaretva, 0::numeric) AS restsplittva
   FROM martor.obligpif o
     LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
     LEFT JOIN martor.iesiri i ON i.codies = g.coddoc
  WHERE o.semnificatie = 200::numeric AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND i.operat = 1::numeric AND i.anulat = 0::numeric
UNION ALL
 SELECT o.codobligpif,
    o.valoare AS rest,
    COALESCE(g.tva, 0::numeric) AS resttva,
    COALESCE(o.dincaretva, 0::numeric) AS restsplittva
   FROM martor.obligpif o
     LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
     LEFT JOIN martor.iesiri i ON i.codies = g.coddoc
  WHERE o.semnificatie = 240::numeric AND i.tipdoc = 20::numeric AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND i.operat = 1::numeric AND i.anulat = 0::numeric
UNION ALL
 SELECT o.codobligpif,
    o.valoare AS rest,
        CASE
            WHEN (o.valoare * COALESCE(g.tva, 0::numeric)) = 0::numeric THEN 0::numeric
            WHEN (( SELECT sum(os.valoare) AS sum
               FROM martor.obligpif os
              WHERE os.codgeneral = o.codgeneral)) = 0::numeric THEN 0::numeric
            ELSE o.valoare * COALESCE(g.tva, 0::numeric) / (( SELECT sum(os.valoare) AS sum
               FROM martor.obligpif os
              WHERE os.codgeneral = o.codgeneral))
        END AS resttva,
    COALESCE(o.dincaretva, 0::numeric) AS restsplittva
   FROM martor.obligpif o
     LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
     LEFT JOIN martor.iesiri i ON i.codies = g.coddoc
  WHERE (o.semnificatie = ANY (ARRAY[210::numeric, 220::numeric])) AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND i.operat = 1::numeric AND i.anulat = 0::numeric
UNION ALL
 SELECT o.codobligpif,
    o.valoare AS rest,
    COALESCE(g.tva, 0::numeric) AS resttva,
    COALESCE(o.dincaretva, 0::numeric) AS restsplittva
   FROM martor.obligpif o
     LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
     LEFT JOIN martor.trezor1 t1 ON t1.codtrezor1 = g.coddoc
     LEFT JOIN martor.trezor t ON t.codtrezor = t1.codtrezor
  WHERE (t1.initializari = 1::numeric OR COALESCE(t1.initializari, 0::numeric) &lt;&gt; 1::numeric AND t.operat = 1::numeric) AND (g.tipdoc = ANY (ARRAY[29::numeric, 30::numeric, 31::numeric, 33::numeric])) AND t1.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND t1.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND (g.semnificatie = ANY (ARRAY[310::numeric, 330::numeric, 410::numeric, 430::numeric, 500::numeric, 600::numeric]))
UNION ALL
 SELECT o.codobligpif,
    o.valoare AS rest,
    COALESCE(g.tva, 0::numeric) AS resttva,
    COALESCE(o.dincaretva, 0::numeric) AS restsplittva
   FROM martor.obligpif o
     LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
     LEFT JOIN martor.nc1 n1 ON n1.codnc1 = g.coddoc
  WHERE (o.semnificatie = ANY (ARRAY[1200::numeric, 1201::numeric, 1250::numeric, 1251::numeric])) AND n1.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND n1.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric
UNION ALL
 SELECT o.codobligpif,
    o.valoare AS rest,
    COALESCE(g.tva, 0::numeric) AS resttva,
    COALESCE(o.dincaretva, 0::numeric) AS restsplittva
   FROM martor.obligpif o
     LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
     LEFT JOIN martor.compens c ON c.codcompens = g.coddoc
  WHERE (o.semnificatie = ANY (ARRAY[1301::numeric, 1303::numeric, 1351::numeric])) AND c.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND c.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_obligpif_stingeri_luna</obj_name>
  <obj_hashval>923a3ff9a62a0b6faf81fa5b34e3618d</obj_hashval>
  <obj_text>SELECT ostins.codobligpif,
    - (i1.pu * i1.cant + COALESCE(i1stins.tva, 0::numeric) *
        CASE
            WHEN (i1stins.pu * i1stins.cant) = 0::numeric THEN 0::numeric
            ELSE i1.pu * i1.cant / (i1stins.pu * i1stins.cant)
        END) AS rest,
    0 AS resttva,
    0 AS restsplittva
   FROM martor.obligpif o,
    martor.general g,
    martor.intrari i,
    martor.intrari1 i1,
    martor.intrlink il,
    martor.intrari1 i1stins,
    martor.intrari istins,
    martor.general gstins,
    martor.obligpif ostins
  WHERE o.semnificatie = 140::numeric AND g.codgeneral = o.codgeneral AND g.tipdoc = 9::numeric AND i.codintr = g.coddoc AND i1.codintr = i.codintr AND il.codintr1 = i1.codintr1 AND il.codlinieaviz = i1stins.codintr1 AND istins.codintr = i1stins.codintr AND istins.codintr = gstins.coddoc AND istins.tipdoc = gstins.tipdoc AND gstins.semnificatie = 140::numeric AND COALESCE(i1stins.custodie, 0::numeric) = 0::numeric AND ostins.codgeneral = gstins.codgeneral AND i.operat = 1::numeric AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric
UNION ALL
 SELECT a_pg.codobligpif,
    round(sum(a_pg.rest), 2) AS rest,
    0 AS resttva,
    0 AS restsplittva
   FROM ( SELECT ostins.codobligpif,
            - (round(d1.pretimport / i.curs, 6) * i1.cant + COALESCE(i1stins.tva, 0::numeric) *
                CASE
                    WHEN (i1stins.pu * i1stins.cant) = 0::numeric THEN 0::numeric
                    ELSE round(d1.pretimport / i.curs, 6) * i1.cant / (i1stins.pu * i1stins.cant)
                END) AS rest,
            0 AS resttva
           FROM martor.obligpif o,
            martor.general g,
            martor.intrari i,
            martor.intrari1 i1
             LEFT JOIN martor.dvi1 d1 ON d1.codintr1 = i1.codintr1,
            martor.intrlink il,
            martor.intrari1 i1stins,
            martor.intrari istins,
            martor.general gstins,
            martor.obligpif ostins
          WHERE o.semnificatie = 140::numeric AND g.codgeneral = o.codgeneral AND g.tipdoc = 5::numeric AND i.codintr = g.coddoc AND i1.codintr = i.codintr AND il.codintr1 = i1.codintr1 AND il.codlinieaviz = i1stins.codintr1 AND istins.codintr = i1stins.codintr AND istins.codintr = gstins.coddoc AND istins.tipdoc = gstins.tipdoc AND ostins.codgeneral = gstins.codgeneral AND i.operat = 1::numeric AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric) a_pg
  GROUP BY a_pg.codobligpif
UNION ALL
 SELECT ostins.codobligpif,
    - (i1.pu * i1.cant *
        CASE
            WHEN COALESCE(i1stins.procdisc, 0::numeric) &lt;&gt; 0::numeric THEN (100::numeric + COALESCE(i1stins.procdisc, 0::numeric)) / 100::numeric
            ELSE 1::numeric
        END + COALESCE(i1stins.tva, 0::numeric) *
        CASE
            WHEN (i1stins.pu * i1stins.cant) = 0::numeric THEN 0::numeric
            ELSE i1.pu * i1.cant *
            CASE
                WHEN COALESCE(i1stins.procdisc, 0::numeric) &lt;&gt; 0::numeric THEN (100::numeric + COALESCE(i1stins.procdisc, 0::numeric)) / 100::numeric
                ELSE 1::numeric
            END / (i1stins.pu * i1stins.cant)
        END) AS rest,
    0 AS resttva,
    0 AS restsplittva
   FROM martor.obligpif o,
    martor.general g,
    martor.iesiri i,
    martor.iesiri1 i1,
    martor.ieslink il,
    martor.iesiri1 i1stins,
    martor.iesiri istins,
    martor.general gstins,
    martor.obligpif ostins
  WHERE o.semnificatie = 240::numeric AND g.codgeneral = o.codgeneral AND g.tipdoc = 26::numeric AND i.codies = g.coddoc AND i1.codies = i.codies AND il.codies1 = i1.codies1 AND il.codlinieaviz = i1stins.codies1 AND istins.codies = i1stins.codies AND COALESCE(istins.custodie, 0::numeric) = 0::numeric AND istins.codies = gstins.coddoc AND istins.tipdoc = gstins.tipdoc AND gstins.semnificatie = 240::numeric AND ostins.codgeneral = gstins.codgeneral AND i.operat = 1::numeric AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric
UNION ALL
 SELECT o_stins.codobligpif,
        CASE
            WHEN o_stins.valoare &gt;= 0::numeric THEN - (s.valoare + COALESCE(s.dincaretva, 0::numeric))
            ELSE s.valoare + COALESCE(s.dincaretva, 0::numeric)
        END AS rest,
        CASE
            WHEN o_stins.valoare &gt;= 0::numeric THEN COALESCE(- g.tva, 0::numeric)
            ELSE COALESCE(g.tva, 0::numeric)
        END AS resttva,
        CASE
            WHEN o_stins.valoare &gt;= 0::numeric THEN - COALESCE(s.dincaretva, 0::numeric)
            ELSE COALESCE(s.dincaretva, 0::numeric)
        END AS restsplittva
   FROM martor.stingere s
     LEFT JOIN martor.obligpif o_stingator ON o_stingator.codobligpif = s.codstingatorpif
     LEFT JOIN martor.general g ON g.codgeneral = o_stingator.codgeneral
     LEFT JOIN martor.trezor1 t1 ON t1.codtrezor1 = g.coddoc
     LEFT JOIN martor.trezor t ON t.codtrezor = t1.codtrezor
     LEFT JOIN martor.obligpif o_stins ON o_stins.codobligpif = s.codstinspif
  WHERE t.operat = 1::numeric AND (g.tipdoc = ANY (ARRAY[29::numeric, 30::numeric, 31::numeric, 33::numeric])) AND t.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND t.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND (o_stins.semnificatie &lt;&gt; ALL (ARRAY[800::numeric, 801::numeric]))
UNION ALL
 SELECT o_stins.codobligpif,
        CASE
            WHEN o_stins.valoare &gt;= 0::numeric THEN - (s.valoare + COALESCE(s.dincaretva, 0::numeric))
            ELSE s.valoare + COALESCE(s.dincaretva, 0::numeric)
        END AS rest,
        CASE
            WHEN o_stins.valoare &gt;= 0::numeric THEN COALESCE(- g.tva, 0::numeric)
            ELSE COALESCE(g.tva, 0::numeric)
        END AS resttva,
        CASE
            WHEN o_stins.valoare &gt;= 0::numeric THEN - COALESCE(s.dincaretva, 0::numeric)
            ELSE COALESCE(s.dincaretva, 0::numeric)
        END AS restsplittva
   FROM martor.stingere s
     LEFT JOIN martor.obligpif o_stingator ON o_stingator.codobligpif = s.codstingatorpif
     LEFT JOIN martor.general g ON g.codgeneral = o_stingator.codgeneral
     LEFT JOIN martor.compens co ON co.codcompens = g.coddoc
     LEFT JOIN martor.obligpif o_stins ON o_stins.codobligpif = s.codstinspif
  WHERE g.tipdoc = 28::numeric AND co.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND co.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric
UNION ALL
 SELECT o_stins.codobligpif,
        CASE
            WHEN o_stins.valoare &gt;= 0::numeric THEN - s.valoare
            ELSE s.valoare
        END AS rest,
        CASE
            WHEN o_stins.valoare &gt;= 0::numeric THEN COALESCE(- g.tva, 0::numeric)
            ELSE COALESCE(g.tva, 0::numeric)
        END AS resttva,
    0 AS restsplittva
   FROM martor.stingere s
     LEFT JOIN martor.obligpif o_stingator ON o_stingator.codobligpif = s.codstingatorpif
     LEFT JOIN martor.general g ON g.codgeneral = o_stingator.codgeneral
     LEFT JOIN martor.intrari i ON i.codintr = g.coddoc
     LEFT JOIN martor.obligpif o_stins ON o_stins.codobligpif = s.codstinspif
  WHERE (g.semnificatie = ANY (ARRAY[111::numeric, 121::numeric])) AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND i.operat = 1::numeric AND i.anulat = 0::numeric
UNION ALL
 SELECT o_stins.codobligpif,
        CASE
            WHEN o_stins.valoare &gt;= 0::numeric THEN - s.valoare
            ELSE s.valoare
        END AS rest,
        CASE
            WHEN o_stins.valoare &gt;= 0::numeric THEN COALESCE(- g.tva, 0::numeric)
            ELSE COALESCE(g.tva, 0::numeric)
        END AS resttva,
        CASE
            WHEN o_stins.valoare &gt;= 0::numeric THEN - COALESCE(s.dincaretva, 0::numeric)
            ELSE COALESCE(s.dincaretva, 0::numeric)
        END AS restsplittva
   FROM martor.stingere s
     LEFT JOIN martor.obligpif o_stingator ON o_stingator.codobligpif = s.codstingatorpif
     LEFT JOIN martor.general g ON g.codgeneral = o_stingator.codgeneral
     LEFT JOIN martor.iesiri i ON i.codies = g.coddoc AND i.tipdoc = g.tipdoc
     LEFT JOIN martor.obligpif o_stins ON o_stins.codobligpif = s.codstinspif
  WHERE (g.semnificatie = ANY (ARRAY[211::numeric, 221::numeric, 400::numeric])) AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND i.operat = 1::numeric AND i.anulat = 0::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_orar</obj_name>
  <obj_hashval>15828b60263cc926216b704cfca7cd70</obj_hashval>
  <obj_text>SELECT codorar,
    denumire,
    obs,
        CASE
            WHEN martor.pkg_orar_expirat(codorar) = 1::numeric THEN 'DA'::text
            ELSE 'NU'::text
        END::character varying AS expirat
   FROM martor.orar o;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_planifprod</obj_name>
  <obj_hashval>cdaf7ba0cda36aeb3387080f424a492c</obj_hashval>
  <obj_text>SELECT p.codplanifprod,
    p.codlansprod,
    p.saptamana,
    sub.den_subunit,
    p.obs,
    ( SELECT iso_week_to_date.wme_result
           FROM martor.iso_week_to_date(NULL::date, p.an, p.saptamana) iso_week_to_date(wme_result, pyear, pweek)) AS datastart,
    (( SELECT iso_week_to_date.wme_result
           FROM martor.iso_week_to_date(NULL::date, p.an, p.saptamana) iso_week_to_date(wme_result, pyear, pweek))) + 6 AS datastop,
    p.nrdoc,
    p.datadoc,
    p.subunitatea,
    COALESCE(p.insaptamana, 1::numeric) AS insaptamana,
    p.an,
    p.operat
   FROM martor.planifprod p
     JOIN martor.nsubunit sub ON sub.codsubunit = p.subunitatea
  WHERE p.an = (( SELECT pkg_globals_getanlucru.wme_result
           FROM martor.pkg_globals_getanlucru(NULL::numeric, NULL::numeric) pkg_globals_getanlucru(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_prodcomp</obj_name>
  <obj_hashval>833330bc17538b6bd43886a6aa45b545</obj_hashval>
  <obj_text>SELECT codprodcomp,
    codobiect,
    obs,
    data,
    anulat,
    blocat,
    operat,
    denumire,
    cant,
    den_um,
    codarticol,
    tipreteta,
    pret,
    coefindirecte,
    implicit,
    tipstring,
    codintern,
    inactiv,
    ascuns
   FROM ( SELECT p.codprodcomp,
            p.codobiect,
            p.obs,
            p.data,
            p.anulat,
            p.blocat,
            p.operat,
            obj.denumire,
            p.cant,
            num.den_um,
            art.codarticol,
            p.tipreteta,
            p.pret,
            p.coefindirecte,
            p.implicit,
                CASE
                    WHEN p.tipreteta = 2::numeric THEN 'Dezagregare'::text
                    ELSE 'Agregare'::text
                END AS tipstring,
            obj.codintern,
            p.inactiv,
            p.ascuns
           FROM martor.prodcomp p
             JOIN martor.nartobj obj ON p.codobiect = obj.codobiect
             JOIN martor.nart art ON obj.codarticol = art.codarticol
             JOIN martor.num ON art.um = num.codum
          WHERE p.operat = 1::numeric AND p.blocat &lt;&gt; 1::numeric AND p.anulat &lt;&gt; 1::numeric) a_pg;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_rac_cars</obj_name>
  <obj_hashval>fbf255cdc29f3b4c9ae0db88a3c8a334</obj_hashval>
  <obj_text>SELECT p.codnparcaut AS codauto,
    npg.data,
    COALESCE(npg.codgest, 0::numeric) AS codgest,
    ng.den_gest AS gestiune,
    ng.codsubunit AS subunitate,
    ng.codclasa,
    COALESCE(npg.status, 0::numeric) AS inactiv,
    COALESCE(p.extern, 0::numeric) AS extern,
    p.codart AS codobiect,
    p.nrinreg AS nrauto,
    ma.marca,
    mo.model,
    p.anf,
    COALESCE(g.codgrechiv, 0::numeric) AS codgrechiv,
    COALESCE(g.ind, 0::numeric) AS ind,
    g.denumire AS clasa,
    COALESCE(e.generic, 0::numeric) AS generic
   FROM martor.nparcaut p
     JOIN martor.nparcg npg ON npg.codnparcaut = p.codnparcaut
     LEFT JOIN martor.nechiv e ON e.codobiect = p.codart
     LEFT JOIN martor.grechiv g ON g.codgrechiv = e.codgrupa
     LEFT JOIN martor.nmodeleauto mo ON mo.codmodeleauto = p.model
     LEFT JOIN martor.nmarciauto ma ON ma.codmarciauto = p.marca
     LEFT JOIN martor.ngest ng ON ng.codgest = npg.codgest
  WHERE npg.data = (( SELECT max(xnpg.data) AS max
           FROM martor.nparcg xnpg
          WHERE xnpg.codnparcaut = p.codnparcaut AND ((( SELECT pkg_rac_rez_rac_datacuora.wme_result
                   FROM martor.pkg_rac_rez_rac_datacuora(NULL::numeric, NULL::numeric) pkg_rac_rez_rac_datacuora(wme_result, fakeparam))) = 1::numeric AND xnpg.data &lt;= (( SELECT pkg_rac_rez_rac_datastart.wme_result
                   FROM martor.pkg_rac_rez_rac_datastart(NULL::date, NULL::numeric) pkg_rac_rez_rac_datastart(wme_result, fakeparam))) OR date_trunc('DAY'::text, xnpg.data::timestamp with time zone) &lt;= (( SELECT pkg_rac_rez_rac_datastart.wme_result
                   FROM martor.pkg_rac_rez_rac_datastart(NULL::date, NULL::numeric) pkg_rac_rez_rac_datastart(wme_result, fakeparam))))));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_rac_catp</obj_name>
  <obj_hashval>ef4bd0c8a3e33670e773532eaeff3430</obj_hashval>
  <obj_text>SELECT r.codrac_catp,
    r.obs,
    p.codpart,
    s.codagenda,
    0 AS codgest,
    0 AS codsubunit,
    r.datastart,
    r.datastop,
    p.den_part AS part,
    g.gest,
    s.obs AS sediu,
    sb.subunit,
    r.codsediu,
    COALESCE(r.abonament, 0::numeric) AS abonament
   FROM martor.rac_catp r
     LEFT JOIN martor.npart p ON p.codpart = COALESCE(r.codpartener, 0::numeric)
     LEFT JOIN martor.nagenda s ON s.codagenda = COALESCE(r.codsediu, 0::numeric)
     LEFT JOIN ( SELECT a_pg.codrac_catp,
            string_agg(a_pg.den_gest::text, ''::text)::character varying AS gest
           FROM ( SELECT DISTINCT r_1.codrac_catp,
                    g_1.den_gest
                   FROM martor.rac_catp2 r_1
                     JOIN martor.ngest g_1 ON g_1.codgest = r_1.codgest
                  WHERE COALESCE(r_1.codgest, 0::numeric) &gt; 0::numeric) a_pg
          GROUP BY a_pg.codrac_catp) g ON g.codrac_catp = r.codrac_catp
     LEFT JOIN ( SELECT b_pg.codrac_catp,
            string_agg(b_pg.den_subunit::text, ''::text)::character varying AS subunit
           FROM ( SELECT DISTINCT r_1.codrac_catp,
                    s_1.den_subunit
                   FROM martor.rac_catp2 r_1
                     JOIN martor.nsubunit s_1 ON s_1.codsubunit = r_1.codsubunitate
                  WHERE COALESCE(r_1.codsubunitate, 0::numeric) &gt; 0::numeric) b_pg
          GROUP BY b_pg.codrac_catp) sb ON sb.codrac_catp = r.codrac_catp;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_semnificatii</obj_name>
  <obj_hashval>6d1cd2eb805793cfd037c346682c2def</obj_hashval>
  <obj_text>WITH c AS (
         SELECT xicont.icont,
            '-1'::integer AS semn
           FROM ( SELECT unnest(ARRAY[2, 5, 6, 8, 9, 15, 16, 17, 20, 25, 26, 27, 28, 29]) AS icont) xicont
        UNION ALL
         SELECT xicont.icont,
            1 AS semn
           FROM ( SELECT unnest(ARRAY[3, 4, 7, 10, 11, 12, 13, 14, 19, 30, 31, 32, 33, 34]) AS icont) xicont
        ), n AS (
         SELECT xicont.icont,
            '-1'::integer AS semn
           FROM ( SELECT unnest(ARRAY[2, 5, 8, 9, 15, 18]) AS icont) xicont
        UNION ALL
         SELECT xicont.icont,
            1 AS semn
           FROM ( SELECT unnest(ARRAY[3, 4, 6, 7, 10, 11, 12, 13, 14, 17]) AS icont) xicont
        )
 SELECT 100 AS semnificatie,
    '-1'::integer AS semn,
    0 AS tva,
    0 AS icont,
    'tsObligFurn'::text AS simb,
    '{provenita din Intrari de bunuri si servicii}'::text AS obs
UNION ALL
 SELECT 110 AS semnificatie,
    1 AS semn,
    1 AS tva,
    0 AS icont,
    'tsAvansFurn'::text AS simb,
    '{provenita din linii de avans de pe Intrari}'::text AS obs
UNION ALL
 SELECT 111 AS semnificatie,
    '-1'::integer AS semn,
    0 AS tva,
    0 AS icont,
    'tsStornoAvansFurn'::text AS simb,
    '{provenita din linii de avans in rosu de pe Intrari}'::text AS obs
UNION ALL
 SELECT 120 AS semnificatie,
    '-1'::integer AS semn,
    1 AS tva,
    0 AS icont,
    'tsGarantieFurn'::text AS simb,
    NULL::text AS obs
UNION ALL
 SELECT 121 AS semnificatie,
    '-1'::integer AS semn,
    0 AS tva,
    0 AS icont,
    'tsStornoGarantieFurn'::text AS simb,
    NULL::text AS obs
UNION ALL
 SELECT 130 AS semnificatie,
    '-1'::integer AS semn,
    0 AS tva,
    0 AS icont,
    'tsObligVama'::text AS simb,
    NULL::text AS obs
UNION ALL
 SELECT 140 AS semnificatie,
    '-1'::integer AS semn,
    0 AS tva,
    0 AS icont,
    'tsAvizeFurn'::text AS simb,
    '{provenita din Avize de Intrare}'::text AS obs
UNION ALL
 SELECT 200 AS semnificatie,
    1 AS semn,
    0 AS tva,
    0 AS icont,
    'tsObligClient'::text AS simb,
    '{provenita din Iesiri de bunuri si servicii}'::text AS obs
UNION ALL
 SELECT 210 AS semnificatie,
    '-1'::integer AS semn,
    1 AS tva,
    0 AS icont,
    'tsAvansClient'::text AS simb,
    '{provenita din linii de avans de pe Iesiri}'::text AS obs
UNION ALL
 SELECT 211 AS semnificatie,
    1 AS semn,
    1 AS tva,
    0 AS icont,
    'tsStornoAvansClient'::text AS simb,
    '{provenita din linii de avans in rosu de pe Iesiri}'::text AS obs
UNION ALL
 SELECT 220 AS semnificatie,
    1 AS semn,
    1 AS tva,
    0 AS icont,
    'tsGarantieClient'::text AS simb,
    NULL::text AS obs
UNION ALL
 SELECT 221 AS semnificatie,
    1 AS semn,
    0 AS tva,
    0 AS icont,
    'tsStornoGarantieClient'::text AS simb,
    NULL::text AS obs
UNION ALL
 SELECT 240 AS semnificatie,
    1 AS semn,
    0 AS tva,
    0 AS icont,
    'tsAvizeClient'::text AS simb,
    '{provenita din Avize de Iesire}'::text AS obs
UNION ALL
 SELECT 300 AS semnificatie,
    1 AS semn,
    0 AS tva,
    0 AS icont,
    'tsPlataFurn'::text AS simb,
    '{stinge 100 sau 500}'::text AS obs
UNION ALL
 SELECT 310 AS semnificatie,
    1 AS semn,
    1 AS tva,
    0 AS icont,
    'tsPlataInAvansFurn'::text AS simb,
    '{creaza Obligatie de incasat de stins}'::text AS obs
UNION ALL
 SELECT 320 AS semnificatie,
    '-1'::integer AS semn,
    1 AS tva,
    0 AS icont,
    'tsReturFurnizor'::text AS simb,
    '{stinge 100 in rosu , 310 iar pe Tranzactii in curs stinge 500}'::text AS obs
UNION ALL
 SELECT 330 AS semnificatie,
    1 AS semn,
    1 AS tva,
    0 AS icont,
    'tsPlataInAvansReturClient'::text AS simb,
    '{creaza Obligatie de incasat de stins}'::text AS obs
UNION ALL
 SELECT 400 AS semnificatie,
    '-1'::integer AS semn,
    0 AS tva,
    0 AS icont,
    'tsIncasareClient'::text AS simb,
    '{stinge 200 sau 600}'::text AS obs
UNION ALL
 SELECT 410 AS semnificatie,
    '-1'::integer AS semn,
    1 AS tva,
    0 AS icont,
    'tsIncasareInAvansClient'::text AS simb,
    '{creaza Obligatie de plata de stins}'::text AS obs
UNION ALL
 SELECT 420 AS semnificatie,
    1 AS semn,
    1 AS tva,
    0 AS icont,
    'tsReturClient'::text AS simb,
    '{stinge 200 in rosu, 410 iar pe Tranzactii in curs stinge 600}'::text AS obs
UNION ALL
 SELECT 430 AS semnificatie,
    '-1'::integer AS semn,
    1 AS tva,
    0 AS icont,
    'tsIncasareInAvansReturFurn'::text AS simb,
    '{creaza Obligatie de incasat de stins}'::text AS obs
UNION ALL
 SELECT 500 AS semnificatie,
    0 AS semn,
    0 AS tva,
    0 AS icont,
    'tsPlataInCurs'::text AS simb,
    '{ plata cu CEC ce urmeaza a fi stins}'::text AS obs
UNION ALL
 SELECT 600 AS semnificatie,
    0 AS semn,
    0 AS tva,
    0 AS icont,
    'tsIncasareInCurs'::text AS simb,
    '{ incasare cu CEC ce urmeaza a fi stins}'::text AS obs
UNION ALL
 SELECT 700 AS semnificatie,
    1 AS semn,
    0 AS tva,
    0 AS icont,
    'tsReturCECFurn_Fact'::text AS simb,
    '{linie ce reactiveaza in urma unui retur de cec furnizor factura stinsa de cec}'::text AS obs
UNION ALL
 SELECT 701 AS semnificatie,
    '-1'::integer AS semn,
    0 AS tva,
    0 AS icont,
    'tsReturCECFurn_AnulareAvans'::text AS simb,
    '{linie ce anuleaza in urma unui retur de cec furnizor avansul generat de cec}'::text AS obs
UNION ALL
 SELECT 750 AS semnificatie,
    '-1'::integer AS semn,
    0 AS tva,
    0 AS icont,
    'tsReturCECClient_Fact'::text AS simb,
    '{linie ce reactiveaza in urma unui retur de cec client factura stinsa de cec}'::text AS obs
UNION ALL
 SELECT 751 AS semnificatie,
    1 AS semn,
    0 AS tva,
    0 AS icont,
    'tsReturCECClient_AnulareAvans'::text AS simb,
    '{linie ce anuleaza in urma unui retur de cec client avansul generat de cec}'::text AS obs
UNION ALL
 SELECT 800 AS semnificatie,
    0 AS semn,
    0 AS tva,
    0 AS icont,
    'tsPlataVirament'::text AS simb,
    '{plata Virament ce stinge sau urmeaza a fi stins}'::text AS obs
UNION ALL
 SELECT 801 AS semnificatie,
    0 AS semn,
    0 AS tva,
    0 AS icont,
    'tsIncasareVirament'::text AS simb,
    '{incasare Virament ce stinge sau urmeaza a fi stins}'::text AS obs
UNION ALL
 SELECT 900 AS semnificatie,
    0 AS semn,
    0 AS tva,
    0 AS icont,
    'tsDirectPeCheltuieli'::text AS simb,
    '{*Direct pe cheltuieli(TVA)}'::text AS obs
UNION ALL
 SELECT 901 AS semnificatie,
    0 AS semn,
    0 AS tva,
    0 AS icont,
    'tsDirectPeVenituri'::text AS simb,
    '{*Direct pe venituri(TVA)}'::text AS obs
UNION ALL
 SELECT 950 AS semnificatie,
    0 AS semn,
    0 AS tva,
    0 AS icont,
    'tsDatoriiTaxeImpozite'::text AS simb,
    '{Datorii, taxe, impoz}'::text AS obs
UNION ALL
 SELECT 951 AS semnificatie,
    0 AS semn,
    0 AS tva,
    0 AS icont,
    'tsImprumuturiSubventii'::text AS simb,
    '{imprumuturi, subventii}'::text AS obs
UNION ALL
 SELECT 1000 AS semnificatie,
    0 AS semn,
    0 AS tva,
    0 AS icont,
    'tsDobanda'::text AS simb,
    '{Dobanzi; Obiecttranz = 6}'::text AS obs
UNION ALL
 SELECT 1100 AS semnificatie,
    0 AS semn,
    0 AS tva,
    0 AS icont,
    'tsPlataAngajat'::text AS simb,
    '{Plata personal angajat}'::text AS obs
UNION ALL
 SELECT 1101 AS semnificatie,
    0 AS semn,
    0 AS tva,
    0 AS icont,
    'tsIncasareAngajat'::text AS simb,
    '{Incasare personal angajat}'::text AS obs
UNION ALL
 SELECT 1200 AS semnificatie,
    c.semn,
    0 AS tva,
    c.icont,
    'tsNotaContabilaDebit'::text AS simb,
    '{provenita din note contabile Debit}'::text AS obs
   FROM c
  WHERE c.semn &lt;&gt; 0
UNION ALL
 SELECT 1201 AS semnificatie,
    c.semn,
    0 AS tva,
    c.icont,
    'tsNotaContabilaCredit'::text AS simb,
    '{provenita din note contabile Credit}'::text AS obs
   FROM c
  WHERE c.semn &lt;&gt; 0
UNION ALL
 SELECT 1250 AS semnificatie,
    0 AS semn,
    0 AS tva,
    0 AS icont,
    'tsNotaContabilaAjustareDebit'::text AS simb,
    '{provenita din note contabile Debit}'::text AS obs
UNION ALL
 SELECT 1251 AS semnificatie,
    0 AS semn,
    0 AS tva,
    0 AS icont,
    'tsNotaContabilaAjustareCredit'::text AS simb,
    '{provenita din note contabile Credit}'::text AS obs
UNION ALL
 SELECT 1300 AS semnificatie,
    1 AS semn,
    1 AS tva,
    0 AS icont,
    'tsCompensDebit'::text AS simb,
    '{provenita din compensari Debit, partener}'::text AS obs
UNION ALL
 SELECT 1301 AS semnificatie,
    n.semn,
    0 AS tva,
    n.icont,
    'tsCompensDebitFaraLeg'::text AS simb,
    '{provenita din compensari Debit, partener, fara leg}'::text AS obs
   FROM n
  WHERE n.semn &lt;&gt; 0
UNION ALL
 SELECT 1302 AS semnificatie,
    0 AS semn,
    0 AS tva,
    0 AS icont,
    'tsCompensDebitPeCont'::text AS simb,
    '{provenita din compensari Debit, direct pe cont}'::text AS obs
UNION ALL
 SELECT 1303 AS semnificatie,
    n.semn,
    0 AS tva,
    n.icont,
    'tsCompensDebitLitigii'::text AS simb,
    '{provenita din compensari Debit, litigii}'::text AS obs
   FROM n
  WHERE n.semn &lt;&gt; 0
UNION ALL
 SELECT 1350 AS semnificatie,
    '-1'::integer AS semn,
    1 AS tva,
    0 AS icont,
    'tsCompensCredit'::text AS simb,
    '{provenita din compensari Credit, partener}'::text AS obs
UNION ALL
 SELECT 1351 AS semnificatie,
    n.semn,
    0 AS tva,
    n.icont,
    'tsCompensCreditFaraLeg'::text AS simb,
    '{provenita din compensari Credit, partener, fara leg}'::text AS obs
   FROM n
  WHERE n.semn &lt;&gt; 0
UNION ALL
 SELECT 1352 AS semnificatie,
    0 AS semn,
    0 AS tva,
    0 AS icont,
    'tsCompensCreditPeCont'::text AS simb,
    '{provenita din compensari Credit, direct pe cont}'::text AS obs
UNION ALL
 SELECT 1353 AS semnificatie,
    0 AS semn,
    0 AS tva,
    0 AS icont,
    'tsCompensCreditLitigii'::text AS simb,
    '{provenita din compensari Credit, litigii}'::text AS obs;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldbank_tranzactii</obj_name>
  <obj_hashval>356dc88f694c93fa9d4f2fd5d057117f</obj_hashval>
  <obj_text>SELECT codbankcont,
    sum(soldlei) AS soldlei,
    sum(soldvaluta) AS soldvaluta
   FROM ( SELECT t.codbanca AS codbankcont,
            sum(
                CASE
                    WHEN t1.tiptranz = 0::numeric AND m.codmoneda = 0::numeric THEN (- t1.valdoc) *
                    CASE
                        WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                        ELSE '-1'::integer
                    END::numeric
                    WHEN t1.tiptranz = 1::numeric AND m.codmoneda = 0::numeric THEN t1.valdoc *
                    CASE
                        WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                        ELSE '-1'::integer
                    END::numeric
                    WHEN t1.tiptranz = 0::numeric AND m.codmoneda &lt;&gt; 0::numeric THEN (- t1.valdoc) * t1.curs *
                    CASE
                        WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                        ELSE '-1'::integer
                    END::numeric
                    WHEN t1.tiptranz = 1::numeric AND m.codmoneda &lt;&gt; 0::numeric THEN t1.valdoc * t1.curs *
                    CASE
                        WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                        ELSE '-1'::integer
                    END::numeric
                    ELSE NULL::numeric
                END) + sum(
                CASE
                    WHEN m.codmoneda = 0::numeric THEN (- COALESCE(t1.comision, 0::numeric)) *
                    CASE
                        WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                        ELSE '-1'::integer
                    END::numeric
                    WHEN m.codmoneda &lt;&gt; 0::numeric THEN (- COALESCE(t1.comision, 0::numeric)) * t1.curs *
                    CASE
                        WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                        ELSE '-1'::integer
                    END::numeric
                    ELSE NULL::numeric
                END) AS soldlei,
            sum(
                CASE
                    WHEN t1.tiptranz = 0::numeric AND m.codmoneda = 0::numeric THEN 0::numeric
                    WHEN t1.tiptranz = 1::numeric AND m.codmoneda = 0::numeric THEN 0::numeric
                    WHEN t1.tiptranz = 0::numeric AND m.codmoneda &lt;&gt; 0::numeric THEN (- t1.valdoc) *
                    CASE
                        WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                        ELSE '-1'::integer
                    END::numeric
                    WHEN t1.tiptranz = 1::numeric AND m.codmoneda &lt;&gt; 0::numeric THEN t1.valdoc *
                    CASE
                        WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                        ELSE '-1'::integer
                    END::numeric
                    ELSE NULL::numeric
                END) + sum(
                CASE
                    WHEN m.codmoneda = 0::numeric THEN 0::numeric
                    WHEN m.codmoneda &lt;&gt; 0::numeric THEN (- COALESCE(t1.comision, 0::numeric)) *
                    CASE
                        WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                        ELSE '-1'::integer
                    END::numeric
                    ELSE NULL::numeric
                END) AS soldvaluta
           FROM martor.trezor t
             LEFT JOIN martor.trezor1 t1 ON t1.codtrezor = t.codtrezor
             LEFT JOIN martor.nbankcont bc ON bc.codbankcont = t.codbanca
             LEFT JOIN martor.nbank nb ON nb.codbank = bc.codbank
             LEFT JOIN martor.nmonede m ON m.codmoneda = bc.codmoneda
          WHERE (t.tipdoc &lt;&gt; ALL (ARRAY[31::numeric, 33::numeric])) AND t.operat = 1::numeric AND t1.anulat = 0::numeric AND t.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND t.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND t.codbanca = current_setting('PKG_CONTURIBANCI.CONTBANCACURENT'::text, true)::numeric
          GROUP BY t.codbanca
        UNION ALL
         SELECT m.codbankcont,
            sum(m.valoare *
                CASE
                    WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                    ELSE '-1'::integer
                END::numeric) AS soldlei,
            0 AS soldvaluta
           FROM martor.iesiri i
             JOIN martor.moduriplati m ON m.codies = i.codies
             JOIN martor.nbankcont bc ON bc.codbankcont = m.codbankcont
          WHERE i.anulat = 0::numeric AND i.operat = 1::numeric AND i.tipdoc = 16::numeric AND (i.an * 12::numeric + i.luna) = (current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric * 12::numeric + current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric) AND m.codbankcont = current_setting('PKG_CONTURIBANCI.CONTBANCACURENT'::text, true)::numeric
          GROUP BY m.codbankcont) a_pg
  GROUP BY codbankcont;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldbanklunaprec</obj_name>
  <obj_hashval>347a92b6a28dc8d05f5196779c9aa148</obj_hashval>
  <obj_text>SELECT codbankcont,
    soldlei,
    soldvaluta
   FROM martor.nbanksoldluna
  WHERE an = current_setting('PKG_GLOBALS.ANPRECEDENT'::text, true)::numeric AND luna = current_setting('PKG_GLOBALS.LUNAPRECEDENTA'::text, true)::numeric AND codbankcont = current_setting('PKG_CONTURIBANCI.CONTBANCACURENT'::text, true)::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpart_ext</obj_name>
  <obj_hashval>4b1f300eaabdca42574647b28fba874b</obj_hashval>
  <obj_text>SELECT codpart,
    icont,
    codmoneda,
    sum(soldlei) AS soldlei,
    sum(soldval) AS soldvaluta,
    sum(rtvalei) AS resttvalei,
    sum(rtvaval) AS resttvavaluta,
    sum(sold_ifrs) AS sold_ifrs
   FROM ( SELECT a_pg.codpart,
            a_pg.icont,
            a_pg.codmoneda,
                CASE
                    WHEN a_pg.codmoneda = 0::numeric THEN a_pg.rest
                    ELSE a_pg.rest * a_pg.curs
                END AS soldlei,
                CASE
                    WHEN a_pg.codmoneda = 0::numeric THEN 0::numeric
                    ELSE a_pg.rest
                END AS soldval,
                CASE
                    WHEN a_pg.codmoneda = 0::numeric THEN a_pg.rtva
                    ELSE a_pg.rtva * a_pg.curs
                END AS rtvalei,
                CASE
                    WHEN a_pg.codmoneda = 0::numeric THEN 0::numeric
                    ELSE a_pg.rtva
                END AS rtvaval,
                CASE
                    WHEN a_pg.codmoneda &lt;&gt; 0::numeric THEN a_pg.rest * a_pg.dif_curs
                    ELSE 0::numeric
                END AS sold_ifrs
           FROM ( SELECT o.codpart,
                    o.icont,
                    COALESCE(g.moneda, 0::numeric) AS codmoneda,
                    COALESCE(reg.curs, g.curs, 1::numeric) AS curs,
                        CASE
                            WHEN COALESCE(reg.curs_ifrs, 0::numeric) &lt;&gt; 0::numeric THEN reg.curs_ifrs - reg.curs
                            ELSE 0::numeric
                        END AS dif_curs,
                        CASE
                            WHEN o.semnificatie = ANY (ARRAY[100::numeric, 130::numeric]) THEN - ol.rest
                            WHEN o.semnificatie = 110::numeric THEN ol.rest - COALESCE(ol.resttva, 0::numeric)
                            WHEN o.semnificatie = 120::numeric THEN - (ol.rest - COALESCE(ol.resttva, 0::numeric))
                            WHEN o.semnificatie = 140::numeric AND g.tipdoc = 2::numeric THEN - ol.rest
                            WHEN o.semnificatie = 200::numeric THEN ol.rest
                            WHEN o.semnificatie = 210::numeric THEN - (ol.rest - COALESCE(ol.resttva, 0::numeric))
                            WHEN o.semnificatie = 220::numeric THEN ol.rest - COALESCE(ol.resttva, 0::numeric)
                            WHEN o.semnificatie = 240::numeric AND g.tipdoc = 20::numeric THEN ol.rest
                            WHEN o.semnificatie = ANY (ARRAY[310::numeric, 330::numeric]) THEN ol.rest - COALESCE(ol.resttva, 0::numeric)
                            WHEN o.semnificatie = ANY (ARRAY[410::numeric, 430::numeric]) THEN - (ol.rest - COALESCE(ol.resttva, 0::numeric))
                            WHEN (o.semnificatie = ANY (ARRAY[1200::numeric, 1201::numeric])) AND (o.icont = ANY (ARRAY[2::numeric, 5::numeric, 6::numeric, 8::numeric, 9::numeric, 15::numeric, 16::numeric, 17::numeric, 20::numeric, 21::numeric, 22::numeric, 25::numeric, 26::numeric, 27::numeric, 28::numeric, 29::numeric, 35::numeric, 36::numeric, 37::numeric, 38::numeric, 39::numeric, 40::numeric, 41::numeric, 42::numeric, 43::numeric, 44::numeric, 45::numeric, 46::numeric, 47::numeric, 48::numeric, 49::numeric, 50::numeric, 51::numeric, 52::numeric, 53::numeric, 54::numeric, 55::numeric, 56::numeric, 57::numeric, 58::numeric, 59::numeric])) THEN - ol.rest
                            WHEN (o.semnificatie = ANY (ARRAY[1301::numeric, 1351::numeric, 1303::numeric])) AND (o.icont = ANY (ARRAY[2::numeric, 5::numeric, 8::numeric, 9::numeric, 15::numeric, 16::numeric, 18::numeric, 20::numeric, 25::numeric, 26::numeric, 27::numeric, 28::numeric, 29::numeric, 35::numeric, 36::numeric, 37::numeric, 38::numeric, 39::numeric, 40::numeric, 41::numeric, 42::numeric, 43::numeric, 44::numeric, 45::numeric, 46::numeric, 47::numeric, 48::numeric, 49::numeric, 50::numeric, 51::numeric, 52::numeric, 53::numeric, 54::numeric, 55::numeric, 56::numeric, 57::numeric, 58::numeric, 59::numeric])) THEN - ol.rest
                            WHEN (o.semnificatie = ANY (ARRAY[1200::numeric, 1201::numeric])) AND (o.icont = ANY (ARRAY[3::numeric, 4::numeric, 7::numeric, 10::numeric, 11::numeric, 12::numeric, 13::numeric, 14::numeric, 18::numeric, 19::numeric, 23::numeric, 24::numeric, 30::numeric, 31::numeric, 32::numeric, 33::numeric, 34::numeric])) THEN ol.rest
                            WHEN (o.semnificatie = ANY (ARRAY[1301::numeric, 1351::numeric, 1303::numeric])) AND (o.icont = ANY (ARRAY[3::numeric, 4::numeric, 6::numeric, 7::numeric, 10::numeric, 11::numeric, 12::numeric, 13::numeric, 14::numeric, 17::numeric, 19::numeric, 30::numeric, 31::numeric, 32::numeric, 33::numeric, 34::numeric])) THEN ol.rest
                            ELSE 0::numeric
                        END AS rest,
                        CASE
                            WHEN o.semnificatie = 110::numeric THEN COALESCE(ol.resttva, 0::numeric)
                            WHEN o.semnificatie = 120::numeric THEN - COALESCE(ol.resttva, 0::numeric)
                            WHEN o.semnificatie = 210::numeric THEN - COALESCE(ol.resttva, 0::numeric)
                            WHEN o.semnificatie = 220::numeric THEN COALESCE(ol.resttva, 0::numeric)
                            WHEN o.semnificatie = ANY (ARRAY[310::numeric, 330::numeric]) THEN COALESCE(ol.resttva, 0::numeric)
                            WHEN o.semnificatie = ANY (ARRAY[410::numeric, 430::numeric]) THEN - COALESCE(ol.resttva, 0::numeric)
                            ELSE 0::numeric
                        END AS rtva
                   FROM martor.obligpifluna ol
                     JOIN martor.obligpif o ON o.codobligpif = ol.codobligpif
                     JOIN martor.general g ON g.codgeneral = o.codgeneral
                     LEFT JOIN ( SELECT r1.codgeneral,
                            r.curs,
                            r.curs_ifrs,
                            row_number() OVER (PARTITION BY r1.codgeneral ORDER BY r.datadoc DESC) AS idx
                           FROM martor.reg r
                             JOIN martor.reg1 r1 ON r1.codreg = r.codreg
                          WHERE r.tipreg = 46::numeric AND (r.an * 12::numeric + r.luna) &lt;= (current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric * 12::numeric + current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric)) reg ON reg.codgeneral = g.codgeneral AND reg.idx = 1
                  WHERE ol.rest &lt;&gt; 0::numeric AND ol.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND ol.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND (o.semnificatie = ANY (ARRAY[100::numeric, 110::numeric, 120::numeric, 130::numeric, 140::numeric, 200::numeric, 210::numeric, 220::numeric, 240::numeric, 310::numeric, 330::numeric, 410::numeric, 430::numeric, 1200::numeric, 1201::numeric, 1301::numeric, 1351::numeric, 1303::numeric])) AND (( SELECT pkg_nompart_codpart_sold_analizat_valid.wme_result
                           FROM martor.pkg_nompart_codpart_sold_analizat_valid(0::numeric, o.codpart) pkg_nompart_codpart_sold_analizat_valid(wme_result, acodpart))) = 1::numeric) a_pg) b_pg
  GROUP BY codpart, icont, codmoneda;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpart_ifrs</obj_name>
  <obj_hashval>deb6a69f24c2ceecbdd64d66451cc16b</obj_hashval>
  <obj_text>SELECT codpart,
    icont,
    sum(sold_ifrs) AS sold_ifrs
   FROM ( SELECT npartsoldluna.codpart,
            npartsoldluna.icont,
            sum(npartsoldluna.sold_ifrs) AS sold_ifrs
           FROM martor.npartsoldluna
          WHERE npartsoldluna.an = current_setting('PKG_GLOBALS.ANPRECEDENT'::text, true)::numeric AND npartsoldluna.luna = current_setting('PKG_GLOBALS.LUNAPRECEDENTA'::text, true)::numeric AND npartsoldluna.codmoneda = 0::numeric AND COALESCE(npartsoldluna.sold_ifrs, 0::numeric) &lt;&gt; 0::numeric
          GROUP BY npartsoldluna.codpart, npartsoldluna.icont
        UNION ALL
         SELECT a_pg.codpart,
            a_pg.icont,
            sum(a_pg.soldlei) AS sold_ifrs
           FROM ( SELECT o.codpart,
                    o.icont,
                        CASE
                            WHEN (o.semnificatie = ANY (ARRAY[1250::numeric, 1251::numeric])) AND (o.icont = ANY (ARRAY[2::numeric, 5::numeric, 6::numeric, 8::numeric, 9::numeric, 15::numeric, 17::numeric])) THEN - o.valoare
                            WHEN (o.semnificatie = ANY (ARRAY[1250::numeric, 1251::numeric])) AND (o.icont = ANY (ARRAY[3::numeric, 4::numeric, 7::numeric, 10::numeric, 11::numeric, 12::numeric, 13::numeric, 14::numeric])) THEN o.valoare
                            ELSE NULL::numeric
                        END AS soldlei
                   FROM martor.obligpif o,
                    martor.general g,
                    martor.nc1 n1,
                    martor.nc n
                  WHERE (o.semnificatie = ANY (ARRAY[1250::numeric, 1251::numeric])) AND g.codgeneral = o.codgeneral AND n1.codnc1 = g.coddoc AND n.codnc = n1.codnc AND g.moneda = 0::numeric AND n.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND n.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric) a_pg
          GROUP BY a_pg.codpart, a_pg.icont) b_pg
  GROUP BY codpart, icont;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpartsub_ext</obj_name>
  <obj_hashval>02da4960ad168c2d0e553ea4ece44262</obj_hashval>
  <obj_text>SELECT codpart,
    icont,
    codmoneda,
    subunitatea,
    sum(soldlei) AS soldlei,
    sum(soldval) AS soldvaluta,
    sum(rtvalei) AS resttvalei,
    sum(rtvaval) AS resttvavaluta,
    sum(sold_ifrs) AS sold_ifrs
   FROM ( SELECT a_pg.codpart,
            a_pg.icont,
            a_pg.codmoneda,
            a_pg.subunitatea,
                CASE
                    WHEN a_pg.codmoneda = 0::numeric THEN a_pg.rest
                    ELSE a_pg.rest * a_pg.curs
                END AS soldlei,
                CASE
                    WHEN a_pg.codmoneda = 0::numeric THEN 0::numeric
                    ELSE a_pg.rest
                END AS soldval,
                CASE
                    WHEN a_pg.codmoneda = 0::numeric THEN a_pg.rtva
                    ELSE a_pg.rtva * a_pg.curs
                END AS rtvalei,
                CASE
                    WHEN a_pg.codmoneda = 0::numeric THEN 0::numeric
                    ELSE a_pg.rtva
                END AS rtvaval,
                CASE
                    WHEN a_pg.codmoneda &lt;&gt; 0::numeric THEN a_pg.rest * a_pg.dif_curs
                    ELSE 0::numeric
                END AS sold_ifrs
           FROM ( SELECT o.codpart,
                    o.icont,
                    COALESCE(g.moneda, 0::numeric) AS codmoneda,
                    COALESCE(reg.curs, g.curs, 1::numeric) AS curs,
                        CASE
                            WHEN COALESCE(reg.curs_ifrs, 0::numeric) &lt;&gt; 0::numeric THEN reg.curs_ifrs - reg.curs
                            ELSE 0::numeric
                        END AS dif_curs,
                        CASE
                            WHEN o.semnificatie = ANY (ARRAY[100::numeric, 110::numeric, 120::numeric, 140::numeric]) THEN ( SELECT i.subunitatea
                               FROM martor.intrari i
                              WHERE i.codintr = g.coddoc AND i.tipdoc = g.tipdoc)
                            WHEN o.semnificatie = 130::numeric THEN ( SELECT i.subunitatea
                               FROM martor.dvi d
                                 JOIN martor.intrari i ON i.codintr = d.codintr
                              WHERE d.coddvi = g.coddoc AND g.tipdoc = 5::numeric)
                            WHEN o.semnificatie = ANY (ARRAY[200::numeric, 210::numeric, 220::numeric, 240::numeric]) THEN ( SELECT i.subunitatea
                               FROM martor.iesiri i
                              WHERE i.codies = g.coddoc AND i.tipdoc = g.tipdoc)
                            WHEN o.semnificatie = ANY (ARRAY[310::numeric, 330::numeric, 410::numeric, 430::numeric]) THEN ( SELECT t.subunitatea
                               FROM martor.trezor t,
                                martor.trezor1 t1
                              WHERE t1.codtrezor1 = g.coddoc AND t.codtrezor = t1.codtrezor)
                            WHEN o.semnificatie = ANY (ARRAY[1200::numeric, 1201::numeric]) THEN ( SELECT n.subunitatea
                               FROM martor.nc n,
                                martor.nc1 n1
                              WHERE n1.codnc1 = g.coddoc AND n.codnc = n1.codnc)
                            WHEN o.semnificatie = ANY (ARRAY[1301::numeric, 1351::numeric, 1303::numeric]) THEN ( SELECT c.subunitatea
                               FROM martor.compens c
                              WHERE c.codcompens = g.coddoc)
                            ELSE NULL::numeric
                        END AS subunitatea,
                        CASE
                            WHEN o.semnificatie = ANY (ARRAY[100::numeric, 130::numeric]) THEN - ol.rest
                            WHEN o.semnificatie = 110::numeric THEN ol.rest - COALESCE(ol.resttva, 0::numeric)
                            WHEN o.semnificatie = 120::numeric THEN - (ol.rest - COALESCE(ol.resttva, 0::numeric))
                            WHEN o.semnificatie = 140::numeric AND g.tipdoc = 2::numeric THEN - ol.rest
                            WHEN o.semnificatie = 200::numeric THEN ol.rest
                            WHEN o.semnificatie = 210::numeric THEN - (ol.rest - COALESCE(ol.resttva, 0::numeric))
                            WHEN o.semnificatie = 220::numeric THEN ol.rest - COALESCE(ol.resttva, 0::numeric)
                            WHEN o.semnificatie = 240::numeric AND g.tipdoc = 20::numeric THEN ol.rest
                            WHEN o.semnificatie = ANY (ARRAY[310::numeric, 330::numeric]) THEN ol.rest - COALESCE(ol.resttva, 0::numeric)
                            WHEN o.semnificatie = ANY (ARRAY[410::numeric, 430::numeric]) THEN - (ol.rest - COALESCE(ol.resttva, 0::numeric))
                            WHEN (o.semnificatie = ANY (ARRAY[1200::numeric, 1201::numeric])) AND (o.icont = ANY (ARRAY[2::numeric, 5::numeric, 6::numeric, 8::numeric, 9::numeric, 15::numeric, 16::numeric, 17::numeric, 20::numeric, 21::numeric, 22::numeric, 25::numeric, 26::numeric, 27::numeric, 28::numeric, 29::numeric, 35::numeric, 36::numeric, 37::numeric, 38::numeric, 39::numeric, 40::numeric, 41::numeric, 42::numeric, 43::numeric, 44::numeric, 45::numeric, 46::numeric, 47::numeric, 48::numeric, 49::numeric, 50::numeric, 51::numeric, 52::numeric, 53::numeric, 54::numeric, 55::numeric, 56::numeric, 57::numeric, 58::numeric, 59::numeric])) THEN - ol.rest
                            WHEN (o.semnificatie = ANY (ARRAY[1301::numeric, 1351::numeric, 1303::numeric])) AND (o.icont = ANY (ARRAY[2::numeric, 5::numeric, 8::numeric, 9::numeric, 15::numeric, 16::numeric, 18::numeric, 20::numeric, 25::numeric, 26::numeric, 27::numeric, 28::numeric, 29::numeric, 35::numeric, 36::numeric, 37::numeric, 38::numeric, 39::numeric, 40::numeric, 41::numeric, 42::numeric, 43::numeric, 44::numeric, 45::numeric, 46::numeric, 47::numeric, 48::numeric, 49::numeric, 50::numeric, 51::numeric, 52::numeric, 53::numeric, 54::numeric, 55::numeric, 56::numeric, 57::numeric, 58::numeric, 59::numeric])) THEN - ol.rest
                            WHEN (o.semnificatie = ANY (ARRAY[1200::numeric, 1201::numeric])) AND (o.icont = ANY (ARRAY[3::numeric, 4::numeric, 7::numeric, 10::numeric, 11::numeric, 12::numeric, 13::numeric, 14::numeric, 18::numeric, 19::numeric, 23::numeric, 24::numeric, 30::numeric, 31::numeric, 32::numeric, 33::numeric, 34::numeric])) THEN ol.rest
                            WHEN (o.semnificatie = ANY (ARRAY[1301::numeric, 1351::numeric, 1303::numeric])) AND (o.icont = ANY (ARRAY[3::numeric, 4::numeric, 6::numeric, 7::numeric, 10::numeric, 11::numeric, 12::numeric, 13::numeric, 14::numeric, 17::numeric, 19::numeric, 30::numeric, 31::numeric, 32::numeric, 33::numeric, 34::numeric])) THEN ol.rest
                            ELSE 0::numeric
                        END AS rest,
                        CASE
                            WHEN o.semnificatie = 110::numeric THEN COALESCE(ol.resttva, 0::numeric)
                            WHEN o.semnificatie = 120::numeric THEN - COALESCE(ol.resttva, 0::numeric)
                            WHEN o.semnificatie = 210::numeric THEN - COALESCE(ol.resttva, 0::numeric)
                            WHEN o.semnificatie = 220::numeric THEN COALESCE(ol.resttva, 0::numeric)
                            WHEN o.semnificatie = ANY (ARRAY[310::numeric, 330::numeric]) THEN COALESCE(ol.resttva, 0::numeric)
                            WHEN o.semnificatie = ANY (ARRAY[410::numeric, 430::numeric]) THEN - COALESCE(ol.resttva, 0::numeric)
                            ELSE 0::numeric
                        END AS rtva
                   FROM martor.obligpifluna ol
                     JOIN martor.obligpif o ON o.codobligpif = ol.codobligpif
                     JOIN martor.general g ON g.codgeneral = o.codgeneral
                     LEFT JOIN ( SELECT DISTINCT r1.codgeneral,
                            last_value(r.curs) OVER (ORDER BY r.datadoc) AS curs,
                            last_value(r.curs_ifrs) OVER (ORDER BY r.datadoc) AS curs_ifrs
                           FROM martor.reg r
                             JOIN martor.reg1 r1 ON r1.codreg = r.codreg
                          WHERE r.tipreg = 46::numeric AND (r.an * 12::numeric + r.luna) &lt;= (current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric * 12::numeric + current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric)) reg ON reg.codgeneral = g.codgeneral
                  WHERE ol.rest &lt;&gt; 0::numeric AND (o.semnificatie = ANY (ARRAY[100::numeric, 110::numeric, 120::numeric, 130::numeric, 140::numeric, 200::numeric, 210::numeric, 220::numeric, 240::numeric, 310::numeric, 330::numeric, 410::numeric, 430::numeric, 1200::numeric, 1201::numeric, 1301::numeric, 1351::numeric, 1303::numeric])) AND ol.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND ol.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND (( SELECT pkg_nompart_codpart_sold_analizat_valid.wme_result
                           FROM martor.pkg_nompart_codpart_sold_analizat_valid(NULL::numeric, o.codpart) pkg_nompart_codpart_sold_analizat_valid(wme_result, acodpart))) = 1::numeric) a_pg) b_pg
  GROUP BY codpart, icont, codmoneda, subunitatea;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpers_avans</obj_name>
  <obj_hashval>78291cdbcfc2514f168d33b88fb6578c</obj_hashval>
  <obj_text>SELECT o.codpart AS codpers,
    o.icont,
    g.moneda AS codmoneda,
    sum(
        CASE
            WHEN o.semnificatie = 1100::numeric AND g.moneda = 0::numeric THEN o.rest
            WHEN o.semnificatie = 1101::numeric AND g.moneda = 0::numeric THEN - o.rest
            WHEN o.semnificatie = 1100::numeric AND g.moneda &lt;&gt; 0::numeric THEN o.rest * g.curs
            WHEN o.semnificatie = 1101::numeric AND g.moneda &lt;&gt; 0::numeric THEN (- o.rest) * g.curs
            ELSE NULL::numeric
        END) AS soldlei,
    sum(
        CASE
            WHEN o.semnificatie = 1100::numeric THEN o.rest
            WHEN o.semnificatie = 1101::numeric THEN - o.rest
            ELSE NULL::numeric
        END) AS soldvaluta
   FROM martor.obligpif o
     LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
     LEFT JOIN martor.trezor1 t1 ON t1.codtrezor1 = g.coddoc
     LEFT JOIN martor.trezor t ON t1.codtrezor = t.codtrezor
  WHERE (o.semnificatie = ANY (ARRAY[1100::numeric, 1101::numeric])) AND t1.anulat &lt;&gt; 1::numeric AND t.operat = 1::numeric AND t.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND t.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric
  GROUP BY o.codpart, o.icont, g.moneda;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpers_avans_sub</obj_name>
  <obj_hashval>39f1fa741393d7f74681d2b3ef82640d</obj_hashval>
  <obj_text>SELECT o.codpart AS codpers,
    o.icont,
    g.moneda AS codmoneda,
    t.subunitatea,
    sum(
        CASE
            WHEN o.semnificatie = 1100::numeric AND g.moneda = 0::numeric THEN o.rest
            WHEN o.semnificatie = 1101::numeric AND g.moneda = 0::numeric THEN - o.rest
            WHEN o.semnificatie = 1100::numeric AND g.moneda &lt;&gt; 0::numeric THEN o.rest * g.curs
            WHEN o.semnificatie = 1101::numeric AND g.moneda &lt;&gt; 0::numeric THEN (- o.rest) * g.curs
            ELSE NULL::numeric
        END) AS soldlei,
    sum(
        CASE
            WHEN o.semnificatie = 1100::numeric THEN o.rest
            WHEN o.semnificatie = 1101::numeric THEN - o.rest
            ELSE NULL::numeric
        END) AS soldvaluta
   FROM martor.obligpif o
     LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
     LEFT JOIN martor.trezor1 t1 ON t1.codtrezor1 = g.coddoc
     LEFT JOIN martor.trezor t ON t.codtrezor = t1.codtrezor
  WHERE (o.semnificatie = ANY (ARRAY[1100::numeric, 1101::numeric])) AND t1.anulat &lt;&gt; 1::numeric AND t.operat = 1::numeric AND t.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND t.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric
  GROUP BY o.codpart, o.icont, g.moneda, t.subunitatea;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpers_justif</obj_name>
  <obj_hashval>e076e50a9006754352972d5a4febd438</obj_hashval>
  <obj_text>SELECT t.codbanca AS codpers,
    t.icontpers AS icont,
    t.monedapers AS codmoneda,
    sum(
        CASE
            WHEN t1.tiptranz = 0::numeric AND t.monedapers = 0::numeric THEN - t1.valdoc
            WHEN t1.tiptranz = 1::numeric AND t.monedapers = 0::numeric THEN t1.valdoc
            WHEN t1.tiptranz = 0::numeric AND t.monedapers &lt;&gt; 0::numeric THEN (- t1.valdoc) * t1.curs
            WHEN t1.tiptranz = 1::numeric AND t.monedapers &lt;&gt; 0::numeric THEN t1.valdoc * t1.curs
            ELSE NULL::numeric
        END) AS soldlei,
    sum(
        CASE
            WHEN t1.tiptranz = 0::numeric THEN - t1.valdoc
            WHEN t1.tiptranz = 1::numeric THEN t1.valdoc
            ELSE NULL::numeric
        END) AS soldvaluta
   FROM martor.trezor t
     LEFT JOIN martor.trezor1 t1 ON t1.codtrezor = t.codtrezor
  WHERE t.tipdoc = 33::numeric AND t.operat = 1::numeric AND t1.anulat &lt;&gt; 1::numeric AND t.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND t.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric
  GROUP BY t.codbanca, t.icontpers, t.monedapers;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpers_justif_sub</obj_name>
  <obj_hashval>41c1dd359c183024628e3b8d205e9373</obj_hashval>
  <obj_text>SELECT t.codbanca AS codpers,
    t.icontpers AS icont,
    t.monedapers AS codmoneda,
    t.subunitatea,
    sum(
        CASE
            WHEN t1.tiptranz = 0::numeric AND t.monedapers = 0::numeric THEN - t1.valdoc
            WHEN t1.tiptranz = 1::numeric AND t.monedapers = 0::numeric THEN t1.valdoc
            WHEN t1.tiptranz = 0::numeric AND t.monedapers &lt;&gt; 0::numeric THEN (- t1.valdoc) * t1.curs
            WHEN t1.tiptranz = 1::numeric AND t.monedapers &lt;&gt; 0::numeric THEN t1.valdoc * t1.curs
            ELSE NULL::numeric
        END) AS soldlei,
    sum(
        CASE
            WHEN t1.tiptranz = 0::numeric THEN - t1.valdoc
            WHEN t1.tiptranz = 1::numeric THEN t1.valdoc
            ELSE NULL::numeric
        END) AS soldvaluta
   FROM martor.trezor t
     LEFT JOIN martor.trezor1 t1 ON t1.codtrezor = t.codtrezor
  WHERE t.tipdoc = 33::numeric AND t.operat = 1::numeric AND t1.anulat &lt;&gt; 1::numeric AND t.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND t.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric
  GROUP BY t.codbanca, t.icontpers, t.monedapers, t.subunitatea;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpers_nc_credit</obj_name>
  <obj_hashval>8c8ae5a485f014cc52adf612d7b534db</obj_hashval>
  <obj_text>SELECT nc1.agent AS codpers,
    nc1.icontc AS icont,
    nc.moneda AS codmoneda,
    sum(
        CASE
            WHEN nc.moneda = 0::numeric THEN - nc1.valoare
            WHEN nc.moneda &lt;&gt; 0::numeric THEN (- nc1.valoare) * nc.curs
            ELSE NULL::numeric
        END) AS soldlei,
    sum(- nc1.valoare) AS soldvaluta
   FROM martor.nc1,
    martor.nc
  WHERE nc.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND nc.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND nc.codnc = nc1.codnc AND COALESCE(nc1.agent, 0::numeric) &lt;&gt; 0::numeric AND COALESCE(nc1.icontc, 0::numeric) &lt;&gt; 0::numeric AND COALESCE(nc1.persc, 0::numeric) &lt;&gt; 0::numeric
  GROUP BY nc1.agent, nc1.icontc, nc.moneda;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpers_nc_credit_sub</obj_name>
  <obj_hashval>2e655da271eb3fa93517a4edbd44476f</obj_hashval>
  <obj_text>SELECT nc1.agent AS codpers,
    nc1.icontc AS icont,
    nc.moneda AS codmoneda,
    nc.subunitatea,
    sum(
        CASE
            WHEN nc.moneda = 0::numeric THEN - nc1.valoare
            WHEN nc.moneda &lt;&gt; 0::numeric THEN (- nc1.valoare) * nc.curs
            ELSE NULL::numeric
        END) AS soldlei,
    sum(- nc1.valoare) AS soldvaluta
   FROM martor.nc1,
    martor.nc
  WHERE nc.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND nc.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND nc.codnc = nc1.codnc AND COALESCE(nc1.agent, 0::numeric) &lt;&gt; 0::numeric AND COALESCE(nc1.icontc, 0::numeric) &lt;&gt; 0::numeric AND COALESCE(nc1.persc, 0::numeric) &lt;&gt; 0::numeric
  GROUP BY nc1.agent, nc1.icontc, nc.moneda, nc.subunitatea;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpers_nc_debit_sub</obj_name>
  <obj_hashval>42d184e6249637107229413f1b8f3b97</obj_hashval>
  <obj_text>SELECT nc1.agent AS codpers,
    nc1.icontd AS icont,
    nc.moneda AS codmoneda,
    nc.subunitatea,
    sum(
        CASE
            WHEN nc.moneda = 0::numeric THEN nc1.valoare
            WHEN nc.moneda &lt;&gt; 0::numeric THEN nc1.valoare * nc.curs
            ELSE NULL::numeric
        END) AS soldlei,
    sum(nc1.valoare) AS soldvaluta
   FROM martor.nc1,
    martor.nc
  WHERE nc.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND nc.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND nc.codnc = nc1.codnc AND COALESCE(nc1.agent, 0::numeric) &lt;&gt; 0::numeric AND COALESCE(nc1.icontd, 0::numeric) &lt;&gt; 0::numeric AND COALESCE(nc1.persd, 0::numeric) &lt;&gt; 0::numeric
  GROUP BY nc1.agent, nc1.icontd, nc.moneda, nc.subunitatea;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpers_prec_sub</obj_name>
  <obj_hashval>50a08c83751d0a9e55417685410ad36c</obj_hashval>
  <obj_text>SELECT codpers,
    icont,
    codmoneda,
    subunitatea,
    soldlei,
    soldvaluta
   FROM martor.nperssoldlunasub
  WHERE an = current_setting('PKG_GLOBALS.ANPRECEDENT'::text, true)::numeric AND luna = current_setting('PKG_GLOBALS.LUNAPRECEDENTA'::text, true)::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpersoana_luna_avans</obj_name>
  <obj_hashval>c4aae3b90c8bcd6aa00c7ee6d63e3d62</obj_hashval>
  <obj_text>SELECT o.codpart AS codpers,
    o.icont,
    g.moneda AS codmoneda,
    sum(
        CASE
            WHEN o.semnificatie = 1100::numeric AND g.moneda = 0::numeric THEN o.rest
            WHEN o.semnificatie = 1101::numeric AND g.moneda = 0::numeric THEN - o.rest
            WHEN o.semnificatie = 1100::numeric AND g.moneda &lt;&gt; 0::numeric THEN o.rest * g.curs
            WHEN o.semnificatie = 1101::numeric AND g.moneda &lt;&gt; 0::numeric THEN (- o.rest) * g.curs
            ELSE NULL::numeric
        END) AS soldlei,
    sum(
        CASE
            WHEN (o.semnificatie = ANY (ARRAY[1100::numeric, 1101::numeric])) AND g.moneda = 0::numeric THEN 0::numeric
            WHEN o.semnificatie = 1100::numeric AND g.moneda &lt;&gt; 0::numeric THEN o.rest
            WHEN o.semnificatie = 1101::numeric AND g.moneda &lt;&gt; 0::numeric THEN - o.rest
            ELSE NULL::numeric
        END) AS soldvaluta
   FROM martor.obligpif o
     LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
     LEFT JOIN martor.trezor1 t1 ON t1.codtrezor1 = g.coddoc
  WHERE (o.semnificatie = ANY (ARRAY[1100::numeric, 1101::numeric])) AND t1.an = martor.getantemp() AND t1.luna = martor.getlunatemp() AND o.codpart = martor.pkg_nompers_get_persoana_curenta() AND o.icont = martor.pkg_nompers_get_icontpers_curent() AND g.moneda = martor.pkg_nompers_get_monedapers_curent()
  GROUP BY o.codpart, o.icont, g.moneda;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpersoana_luna_justif</obj_name>
  <obj_hashval>d7d0579206509094f94fd0e6de570441</obj_hashval>
  <obj_text>SELECT t.codbanca AS codpers,
    t.icontpers AS icont,
    t.monedapers AS codmoneda,
    sum(
        CASE
            WHEN t1.tiptranz = 0::numeric AND t.monedapers = 0::numeric THEN - t1.valdoc
            WHEN t1.tiptranz = 1::numeric AND t.monedapers = 0::numeric THEN t1.valdoc
            WHEN t1.tiptranz = 0::numeric AND t.monedapers &lt;&gt; 0::numeric THEN (- t1.valdoc) * t1.curs
            WHEN t1.tiptranz = 1::numeric AND t.monedapers &lt;&gt; 0::numeric THEN t1.valdoc * t1.curs
            ELSE NULL::numeric
        END) AS soldlei,
    sum(
        CASE
            WHEN t1.tiptranz = 0::numeric AND t.monedapers = 0::numeric THEN 0::numeric
            WHEN t1.tiptranz = 1::numeric AND t.monedapers = 0::numeric THEN 0::numeric
            WHEN t1.tiptranz = 0::numeric AND t.monedapers &lt;&gt; 0::numeric THEN - t1.valdoc
            WHEN t1.tiptranz = 1::numeric AND t.monedapers &lt;&gt; 0::numeric THEN t1.valdoc
            ELSE NULL::numeric
        END) AS soldvaluta
   FROM martor.trezor t
     LEFT JOIN martor.trezor1 t1 ON t1.codtrezor = t.codtrezor
  WHERE t.tipdoc = 33::numeric AND t.an = martor.getantemp() AND t.luna = martor.getlunatemp() AND t.codbanca = martor.pkg_nompers_get_persoana_curenta() AND t.icontpers = martor.pkg_nompers_get_icontpers_curent() AND t.monedapers = martor.pkg_nompers_get_monedapers_curent()
  GROUP BY t.codbanca, t.icontpers, t.monedapers;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpersoana_luna_nc_credit</obj_name>
  <obj_hashval>baa43a67ea61389a48abdcb57a4638e1</obj_hashval>
  <obj_text>SELECT nc1.agent AS codpers,
    nc1.icontc AS icont,
    nc.moneda AS codmoneda,
    sum(
        CASE
            WHEN nc.moneda = 0::numeric THEN nc1.valoare
            WHEN nc.moneda &lt;&gt; 0::numeric THEN nc1.valoare * nc.curs
            ELSE NULL::numeric
        END) AS soldlei,
    sum(
        CASE
            WHEN nc.moneda = 0::numeric THEN 0::numeric
            WHEN nc.moneda &lt;&gt; 0::numeric THEN nc1.valoare
            ELSE NULL::numeric
        END) AS soldvaluta
   FROM martor.nc1,
    martor.nc
  WHERE nc.an = martor.getantemp() AND nc.luna = martor.getlunatemp() AND nc.codnc = nc1.codnc AND COALESCE(nc1.agent, 0::numeric) &lt;&gt; 0::numeric AND COALESCE(nc1.icontc, 0::numeric) &lt;&gt; 0::numeric AND COALESCE(nc1.persc, 0::numeric) &lt;&gt; 0::numeric AND COALESCE(nc1.agent, 0::numeric) = martor.pkg_nompers_get_persoana_curenta() AND COALESCE(nc1.icontc, 0::numeric) = martor.pkg_nompers_get_icontpers_curent() AND nc.moneda = martor.pkg_nompers_get_monedapers_curent()
  GROUP BY nc1.agent, nc1.icontc, nc.moneda;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpersoana_luna_nc_debit</obj_name>
  <obj_hashval>14e471aa9b6638a8674c5c159c7d9f87</obj_hashval>
  <obj_text>SELECT nc1.agent AS codpers,
    nc1.icontd AS icont,
    nc.moneda AS codmoneda,
    sum(
        CASE
            WHEN nc.moneda = 0::numeric THEN nc1.valoare
            WHEN nc.moneda &lt;&gt; 0::numeric THEN nc1.valoare * nc.curs
            ELSE NULL::numeric
        END) AS soldlei,
    sum(
        CASE
            WHEN nc.moneda = 0::numeric THEN 0::numeric
            WHEN nc.moneda &lt;&gt; 0::numeric THEN nc1.valoare
            ELSE NULL::numeric
        END) AS soldvaluta
   FROM martor.nc1,
    martor.nc
  WHERE nc.an = martor.getantemp() AND nc.luna = martor.getlunatemp() AND nc.codnc = nc1.codnc AND COALESCE(nc1.agent, 0::numeric) &lt;&gt; 0::numeric AND COALESCE(nc1.icontd, 0::numeric) &lt;&gt; 0::numeric AND COALESCE(nc1.persd, 0::numeric) &lt;&gt; 0::numeric AND COALESCE(nc1.agent, 0::numeric) = martor.pkg_nompers_get_persoana_curenta() AND COALESCE(nc1.icontd, 0::numeric) = martor.pkg_nompers_get_icontpers_curent() AND nc.moneda = martor.pkg_nompers_get_monedapers_curent()
  GROUP BY nc1.agent, nc1.icontd, nc.moneda;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_solduribanci_la_data</obj_name>
  <obj_hashval>633eacfc47ec04ab6c00038b6c65d871</obj_hashval>
  <obj_text>SELECT codbankcont,
    sum(soldlei) AS soldlei,
    sum(soldvaluta) AS soldvaluta
   FROM ( SELECT nbanksoldluna.codbankcont,
            nbanksoldluna.soldlei,
            nbanksoldluna.soldvaluta
           FROM martor.nbanksoldluna
          WHERE nbanksoldluna.an = (( SELECT pkg_globals_getanprecedent.wme_result
                   FROM martor.pkg_globals_getanprecedent(NULL::numeric, NULL::numeric) pkg_globals_getanprecedent(wme_result, fakeparam))) AND nbanksoldluna.luna = (( SELECT pkg_globals_getlunaprecedenta.wme_result
                   FROM martor.pkg_globals_getlunaprecedenta(NULL::numeric, NULL::numeric) pkg_globals_getlunaprecedenta(wme_result, fakeparam)))
        UNION ALL
         SELECT t.codbanca AS codbankcont,
            sum(
                CASE
                    WHEN t1.tiptranz = 0::numeric AND m.codmoneda = 0::numeric THEN (- (t1.valdoc + COALESCE(t1.comision, 0::numeric))) *
                    CASE
                        WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                        ELSE '-1'::integer
                    END::numeric
                    WHEN t1.tiptranz = 1::numeric AND m.codmoneda = 0::numeric THEN (t1.valdoc - COALESCE(t1.comision, 0::numeric)) *
                    CASE
                        WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                        ELSE '-1'::integer
                    END::numeric
                    WHEN t1.tiptranz = 0::numeric AND m.codmoneda &lt;&gt; 0::numeric THEN (- (t1.valdoc + COALESCE(t1.comision, 0::numeric))) * t1.curs *
                    CASE
                        WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                        ELSE '-1'::integer
                    END::numeric
                    WHEN t1.tiptranz = 1::numeric AND m.codmoneda &lt;&gt; 0::numeric THEN (t1.valdoc - COALESCE(t1.comision, 0::numeric)) * t1.curs *
                    CASE
                        WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                        ELSE '-1'::integer
                    END::numeric
                    ELSE NULL::numeric
                END) AS soldlei,
            sum(
                CASE
                    WHEN t1.tiptranz = 0::numeric AND m.codmoneda = 0::numeric THEN 0::numeric
                    WHEN t1.tiptranz = 1::numeric AND m.codmoneda = 0::numeric THEN 0::numeric
                    WHEN t1.tiptranz = 0::numeric AND m.codmoneda &lt;&gt; 0::numeric THEN (- (t1.valdoc + COALESCE(t1.comision, 0::numeric))) *
                    CASE
                        WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                        ELSE '-1'::integer
                    END::numeric
                    WHEN t1.tiptranz = 1::numeric AND m.codmoneda &lt;&gt; 0::numeric THEN (t1.valdoc - COALESCE(t1.comision, 0::numeric)) *
                    CASE
                        WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                        ELSE '-1'::integer
                    END::numeric
                    ELSE NULL::numeric
                END) AS soldvaluta
           FROM martor.trezor t
             LEFT JOIN martor.trezor1 t1 ON t1.codtrezor = t.codtrezor
             LEFT JOIN martor.nbankcont bc ON bc.codbankcont = t.codbanca
             LEFT JOIN martor.nbank nb ON nb.codbank = bc.codbank
             LEFT JOIN martor.nmonede m ON m.codmoneda = bc.codmoneda
          WHERE (t.tipdoc = ANY (ARRAY[29::numeric, 30::numeric])) AND t.operat = 1::numeric AND COALESCE(t1.anulat, 0::numeric) = 0::numeric AND (t.an * 12::numeric + t.luna) = ((( SELECT pkg_globals_getantemp.wme_result
                   FROM martor.pkg_globals_getantemp(NULL::numeric, NULL::numeric) pkg_globals_getantemp(wme_result, fakeparam))) * 12::numeric + (( SELECT pkg_globals_getlunatemp.wme_result
                   FROM martor.pkg_globals_getlunatemp(NULL::numeric, NULL::numeric) pkg_globals_getlunatemp(wme_result, fakeparam)))) AND COALESCE(t.datadoc::timestamp without time zone, to_date('01.01.1900'::text, 'dd.mm.yyyy'::text)::timestamp without time zone) &lt;= (( SELECT pkg_globals_getdatasoldbanci.wme_result
                   FROM martor.pkg_globals_getdatasoldbanci(NULL::date, NULL::numeric) pkg_globals_getdatasoldbanci(wme_result, fakeparam))) AND t.codbanca = (( SELECT pkg_conturibanci_getcontbancacurent.wme_result
                   FROM martor.pkg_conturibanci_getcontbancacurent(NULL::numeric, NULL::numeric) pkg_conturibanci_getcontbancacurent(wme_result, fakeparam)))
          GROUP BY t.codbanca
        UNION ALL
         SELECT m.codbankcont,
            sum(m.valoare *
                CASE
                    WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                    ELSE '-1'::integer
                END::numeric) AS soldlei,
            0 AS soldvaluta
           FROM martor.iesiri i
             LEFT JOIN martor.moduriplati m ON m.codies = i.codies,
            martor.nbankcont bc
          WHERE i.anulat = 0::numeric AND i.operat = 1::numeric AND i.tipdoc = 16::numeric AND (i.an * 12::numeric + i.luna) = ((( SELECT pkg_globals_getantemp.wme_result
                   FROM martor.pkg_globals_getantemp(NULL::numeric, NULL::numeric) pkg_globals_getantemp(wme_result, fakeparam))) * 12::numeric + (( SELECT pkg_globals_getlunatemp.wme_result
                   FROM martor.pkg_globals_getlunatemp(NULL::numeric, NULL::numeric) pkg_globals_getlunatemp(wme_result, fakeparam)))) AND COALESCE(i.datadoc, to_date('01.01.1900'::text, 'dd.mm.yyyy'::text)::timestamp without time zone) &lt;= (( SELECT pkg_globals_getdatasoldbanci.wme_result
                   FROM martor.pkg_globals_getdatasoldbanci(NULL::date, NULL::numeric) pkg_globals_getdatasoldbanci(wme_result, fakeparam))) AND bc.codbankcont = m.codbankcont AND m.valoare &lt;&gt; 0::numeric AND m.codbankcont = (( SELECT pkg_conturibanci_getcontbancacurent.wme_result
                   FROM martor.pkg_conturibanci_getcontbancacurent(NULL::numeric, NULL::numeric) pkg_conturibanci_getcontbancacurent(wme_result, fakeparam)))
          GROUP BY m.codbankcont) a_pg
  GROUP BY codbankcont;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_solduribanci_tranzactii</obj_name>
  <obj_hashval>1f1bba5fa8a248811230de4dce36c35e</obj_hashval>
  <obj_text>SELECT codbankcont,
    sum(soldlei) AS soldlei,
    sum(soldvaluta) AS soldvaluta
   FROM ( SELECT t.codbanca AS codbankcont,
            sum(
                CASE
                    WHEN t1.tiptranz = 0::numeric AND m.codmoneda = 0::numeric THEN (- (t1.valdoc + COALESCE(t1.comision, 0::numeric))) *
                    CASE
                        WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                        ELSE '-1'::integer
                    END::numeric
                    WHEN t1.tiptranz = 1::numeric AND m.codmoneda = 0::numeric THEN (t1.valdoc - COALESCE(t1.comision, 0::numeric)) *
                    CASE
                        WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                        ELSE '-1'::integer
                    END::numeric
                    WHEN t1.tiptranz = 0::numeric AND m.codmoneda &lt;&gt; 0::numeric THEN (- (t1.valdoc + COALESCE(t1.comision, 0::numeric))) *
                    CASE
                        WHEN COALESCE(t1.curs, 0::numeric) = 0::numeric THEN 1::numeric
                        ELSE t1.curs
                    END *
                    CASE
                        WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                        ELSE '-1'::integer
                    END::numeric
                    WHEN t1.tiptranz = 1::numeric AND m.codmoneda &lt;&gt; 0::numeric THEN (t1.valdoc - COALESCE(t1.comision, 0::numeric)) *
                    CASE
                        WHEN COALESCE(t1.curs, 0::numeric) = 0::numeric THEN 1::numeric
                        ELSE t1.curs
                    END *
                    CASE
                        WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                        ELSE '-1'::integer
                    END::numeric
                    ELSE NULL::numeric
                END) AS soldlei,
            sum(
                CASE
                    WHEN t1.tiptranz = 0::numeric AND m.codmoneda = 0::numeric THEN 0::numeric
                    WHEN t1.tiptranz = 1::numeric AND m.codmoneda = 0::numeric THEN 0::numeric
                    WHEN t1.tiptranz = 0::numeric AND m.codmoneda &lt;&gt; 0::numeric THEN (- (t1.valdoc + COALESCE(t1.comision, 0::numeric))) *
                    CASE
                        WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                        ELSE '-1'::integer
                    END::numeric
                    WHEN t1.tiptranz = 1::numeric AND m.codmoneda &lt;&gt; 0::numeric THEN (t1.valdoc - COALESCE(t1.comision, 0::numeric)) *
                    CASE
                        WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                        ELSE '-1'::integer
                    END::numeric
                    ELSE NULL::numeric
                END) AS soldvaluta
           FROM martor.trezor t
             LEFT JOIN martor.trezor1 t1 ON t1.codtrezor = t.codtrezor
             LEFT JOIN martor.nbankcont bc ON bc.codbankcont = t.codbanca
             LEFT JOIN martor.nbank nb ON nb.codbank = bc.codbank
             LEFT JOIN martor.nmonede m ON m.codmoneda = bc.codmoneda
          WHERE (t.tipdoc = ANY (ARRAY[29::numeric, 30::numeric])) AND t.operat = 1::numeric AND COALESCE(t1.anulat, 0::numeric) = 0::numeric AND t.an = martor.getantemp() AND t.luna = martor.getlunatemp()
          GROUP BY t.codbanca
        UNION ALL
         SELECT m.codbankcont,
            sum(m.valoare *
                CASE
                    WHEN COALESCE(bc.credit, 0::numeric) = 0::numeric THEN 1
                    ELSE '-1'::integer
                END::numeric) AS soldlei,
            0 AS soldvaluta
           FROM martor.iesiri i
             LEFT JOIN martor.moduriplati m ON m.codies = i.codies,
            martor.nbankcont bc
          WHERE i.anulat = 0::numeric AND i.operat = 1::numeric AND i.tipdoc = 16::numeric AND i.an = martor.getantemp() AND i.luna = martor.getlunatemp() AND bc.codbankcont = m.codbankcont AND m.valoare &lt;&gt; 0::numeric
          GROUP BY m.codbankcont) a_pg
  GROUP BY codbankcont;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_stoc_ini</obj_name>
  <obj_hashval>067d33da5134359a5ccd755fea7ca3b9</obj_hashval>
  <obj_text>SELECT i.codstocini,
    i.codgest,
    g.den_gest,
    ((p.nume::text || ' '::text) || p.prenume::text)::character varying AS operator
   FROM martor.stocini i
     LEFT JOIN martor.ngest g ON i.codgest = g.codgest
     LEFT JOIN martor.npers p ON i.codpers = p.codpers
  WHERE COALESCE(g.codsubunit, 1::numeric) =
        CASE
            WHEN (( SELECT pkg_globals_getsubunitate.wme_result
               FROM martor.pkg_globals_getsubunitate(NULL::numeric, NULL::numeric) pkg_globals_getsubunitate(wme_result, fakeparam))) = 1::numeric THEN COALESCE(g.codsubunit, 1::numeric)
            ELSE ( SELECT pkg_globals_getsubunitate.wme_result
               FROM martor.pkg_globals_getsubunitate(NULL::numeric, NULL::numeric) pkg_globals_getsubunitate(wme_result, fakeparam))
        END;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_stoc_ini_necesar2</obj_name>
  <obj_hashval>5f1eb47fe549ca0ec0f5370a0b317fbf</obj_hashval>
  <obj_text>SELECT codnirstoc,
    sum(rest) AS rest
   FROM ( SELECT ns.codnirstoc,
                CASE
                    WHEN COALESCE(ne.codnirser, 0::numeric) = 0::numeric THEN n.rest
                    ELSE ne.rest
                END AS rest
           FROM martor.nirluna n
             JOIN martor.nirstoc ns ON n.codnirstoc = ns.codnirstoc
             JOIN martor.nir ON ns.codnir = nir.codnir
             LEFT JOIN martor.nirserluna ne ON n.codnirstoc = ne.codnirstoc AND n.an = ne.an AND n.luna = ne.luna
             LEFT JOIN martor.nirser nse ON nse.codnirser = ne.codnirser AND nse.codnirstoc = ns.codnirstoc
             LEFT JOIN martor.rezervats r ON r.codnirstoc = ns.codnirstoc AND r.codnirser = nse.codnirser
          WHERE n.an = martor.getanprecedent() AND n.luna = martor.getlunaprecedenta()
        UNION ALL
         SELECT ns.codnirstoc,
                CASE
                    WHEN COALESCE(nse.codnirser, 0::numeric) = 0::numeric THEN ns.cantnir
                    ELSE nse.cantnir
                END AS rest
           FROM martor.nirstoc ns
             JOIN martor.nir n ON n.codnir = ns.codnir
             LEFT JOIN martor.nirser nse ON ns.codnirstoc = nse.codnirstoc
             LEFT JOIN martor.intrari i ON i.codintr = n.codintr
             LEFT JOIN martor.transf t ON t.codtransf = n.codtransf
          WHERE (n.tipnir = ANY (ARRAY[1::numeric, 2::numeric, 3::numeric, 4::numeric, 5::numeric, 6::numeric, 7::numeric, 12::numeric, 13::numeric])) AND n.anulat = 0::numeric AND n.operat = 1::numeric AND (i.an = martor.getantemp() AND i.luna = martor.getlunatemp() OR t.an = martor.getantemp() AND t.luna = martor.getlunatemp()) AND n.datanir &lt; to_date(current_setting('PKG_LIST_SELFISAMAG.p_dataStoc'::text, true)::character varying::text, 'dd.mm.yyyy'::text)
        UNION ALL
         SELECT ns.codnirstoc,
                CASE
                    WHEN l.tiplivr = 15::numeric THEN l1.cant
                    ELSE '-1'::integer::numeric * l1.cant
                END AS rest
           FROM martor.livr1 l1
             JOIN martor.livr l ON l.codlivr = l1.codlivr
             JOIN martor.nirstoc ns ON ns.codnirstoc = l1.codnirstoc
             JOIN martor.nir n ON n.codnir = ns.codnir
             LEFT JOIN martor.nirser ne ON l1.codnirser = ne.codnirser
             LEFT JOIN martor.intrari i ON i.codintr = l.codintr
             LEFT JOIN martor.iesiri ies ON ies.codies = l.codies
             LEFT JOIN martor.transf t ON t.codtransf = l.codtransf
          WHERE (l.tiplivr = ANY (ARRAY[1::numeric, 2::numeric, 3::numeric, 4::numeric, 5::numeric, 6::numeric, 7::numeric, 12::numeric, 13::numeric, 14::numeric, 15::numeric, 16::numeric, 19::numeric, 20::numeric, 21::numeric, 23::numeric, 24::numeric])) AND l.operat = 1::numeric AND l.anulat = 0::numeric AND (i.an = martor.getantemp() AND i.luna = martor.getlunatemp() OR ies.an = martor.getantemp() AND ies.luna = martor.getlunatemp() OR t.an = martor.getantemp() AND t.luna = martor.getlunatemp()) AND l.datalivr &lt; to_date(current_setting('PKG_LIST_SELFISAMAG.p_dataStoc'::text, true)::character varying::text, 'dd.mm.yyyy'::text)) stoc
  GROUP BY codnirstoc;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_stoc_ini_planif</obj_name>
  <obj_hashval>fd8cdcc5e7ab861e7298b4e6c878ac63</obj_hashval>
  <obj_text>SELECT codobiect,
    tg,
    codserie,
    sum(rest) AS rest,
    sum(cantrez) AS cantrez,
    codgest
   FROM ( SELECT ns.codobiect,
            COALESCE(nse.tg, ns.tg) AS tg,
            COALESCE(nse.codserie, 0::numeric) AS codserie,
                CASE
                    WHEN COALESCE(ne.codnirser, 0::numeric) = 0::numeric THEN n.rest
                    ELSE ne.rest
                END AS rest,
            nir.gest AS codgest,
            COALESCE(r.rest, 0::numeric) AS cantrez
           FROM martor.nirluna n
             JOIN martor.nirstoc ns ON n.codnirstoc = ns.codnirstoc
             JOIN martor.nir ON ns.codnir = nir.codnir
             LEFT JOIN martor.nirserluna ne ON n.codnirstoc = ne.codnirstoc AND n.an = ne.an AND n.luna = ne.luna
             LEFT JOIN martor.nirser nse ON nse.codnirser = ne.codnirser AND nse.codnirstoc = ns.codnirstoc
             LEFT JOIN martor.rezervats r ON r.codnirstoc = ns.codnirstoc AND r.codnirser = nse.codnirser
          WHERE n.an = martor.getanprecedent() AND n.luna = martor.getlunaprecedenta()
        UNION ALL
         SELECT ns.codobiect,
            COALESCE(nse.tg, ns.tg) AS tg,
            COALESCE(nse.codserie, 0::numeric) AS codserie,
                CASE
                    WHEN COALESCE(nse.codnirser, 0::numeric) = 0::numeric THEN ns.cantnir
                    ELSE nse.cantnir
                END AS rest,
            n.gest AS codgest,
            COALESCE(r.rest, 0::numeric) AS cantrez
           FROM martor.nirstoc ns
             JOIN martor.nir n ON n.codnir = ns.codnir
             LEFT JOIN martor.nirser nse ON ns.codnirstoc = nse.codnirstoc
             LEFT JOIN martor.rezervats r ON r.codnirstoc = ns.codnirstoc AND r.codnirser = nse.codnirser
             LEFT JOIN martor.intrari i ON i.codintr = n.codintr
             LEFT JOIN martor.transf t ON t.codtransf = n.codtransf
          WHERE (n.tipnir = ANY (ARRAY[1::numeric, 2::numeric, 3::numeric, 4::numeric, 5::numeric, 6::numeric, 7::numeric, 12::numeric, 13::numeric])) AND n.anulat = 0::numeric AND n.operat = 1::numeric AND (i.an = martor.getantemp() AND i.luna = martor.getlunatemp() OR t.an = martor.getantemp() AND t.luna = martor.getlunatemp()) AND n.datanir &lt; to_date(current_setting('PKG_LIST_SELFISAMAG.p_dataStoc'::text, true), 'dd.mm.yyyy'::text)
        UNION ALL
         SELECT ns.codobiect,
            COALESCE(ne.tg, ns.tg) AS tg,
            COALESCE(ne.codserie, 0::numeric) AS codserie,
                CASE
                    WHEN l.tiplivr = 15::numeric THEN l1.cant
                    ELSE '-1'::integer::numeric * l1.cant
                END AS rest,
            n.gest AS codgest,
            COALESCE(r.rest, 0::numeric) AS cantrez
           FROM martor.livr1 l1
             JOIN martor.livr l ON l.codlivr = l1.codlivr
             JOIN martor.nirstoc ns ON ns.codnirstoc = l1.codnirstoc
             JOIN martor.nir n ON n.codnir = ns.codnir
             LEFT JOIN martor.nirser ne ON l1.codnirser = ne.codnirser
             LEFT JOIN martor.rezervats r ON r.codnirstoc = ns.codnirstoc AND ne.codnirser = r.codnirser
             LEFT JOIN martor.intrari i ON i.codintr = l.codintr
             LEFT JOIN martor.iesiri ies ON ies.codies = l.codies
             LEFT JOIN martor.transf t ON t.codtransf = l.codtransf
          WHERE (l.tiplivr = ANY (ARRAY[1::numeric, 2::numeric, 3::numeric, 4::numeric, 5::numeric, 6::numeric, 7::numeric, 12::numeric, 13::numeric, 14::numeric, 15::numeric, 16::numeric, 19::numeric, 20::numeric, 21::numeric, 23::numeric, 24::numeric])) AND l.operat = 1::numeric AND l.anulat = 0::numeric AND (i.an = martor.getantemp() AND i.luna = martor.getlunatemp() OR ies.an = martor.getantemp() AND ies.luna = martor.getlunatemp() OR t.an = martor.getantemp() AND t.luna = martor.getlunatemp()) AND l.datalivr &lt; to_date(current_setting('PKG_LIST_SELFISAMAG.p_dataStoc'::text, true), 'dd.mm.yyyy'::text)) stoc
  GROUP BY codobiect, tg, codserie, codgest;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_stoc_luna_prec</obj_name>
  <obj_hashval>dfd3090ce2b7b39f890037d01aa03d0b</obj_hashval>
  <obj_text>SELECT nl.codnirstoc,
    nl.rest,
    nl.restum1,
    nl.restum2
   FROM martor.nirluna nl
     JOIN martor.nirstoc ns ON nl.codnirstoc = ns.codnirstoc
     JOIN martor.ioart1 io ON io.codioart = ns.codioart
  WHERE nl.an = (( SELECT pkg_globals_getanprecedent.wme_result
           FROM martor.pkg_globals_getanprecedent(NULL::numeric, NULL::numeric) pkg_globals_getanprecedent(wme_result, fakeparam))) AND nl.luna = (( SELECT pkg_globals_getlunaprecedenta.wme_result
           FROM martor.pkg_globals_getlunaprecedenta(NULL::numeric, NULL::numeric) pkg_globals_getlunaprecedenta(wme_result, fakeparam))) AND (COALESCE(nl.rest, 0::numeric) &lt;&gt; 0::numeric OR COALESCE(nl.restum1, 0::numeric) &lt;&gt; 0::numeric OR COALESCE(nl.restum2, 0::numeric) &lt;&gt; 0::numeric) AND (nl.an * 12::numeric + nl.luna) &gt;= io.alstart AND (nl.an * 12::numeric + nl.luna) &lt;= io.alstop AND io.mg &lt;&gt; 5::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_stocval_livrari</obj_name>
  <obj_hashval>67068f98f5a3da53d06eee5c1a59c666</obj_hashval>
  <obj_text>SELECT gest,
    codioart,
    tva,
    sum(sold) AS sold,
    sum(adaos) AS adaos,
    sum(soldintr) AS soldintr,
    sum(adaosintr) AS adaosintr
   FROM ( SELECT lv.gest,
            lv.codioart,
            lv.tvaneex AS tva,
            (- lv.pretinreg) * l1.cant AS sold,
            (- (lv.pretinreg - lv.pretachiz)) * l1.cant AS adaos,
            0 AS soldintr,
            0 AS adaosintr
           FROM martor.livrval lv
             LEFT JOIN martor.livr1 l1 ON l1.codlivr1 = lv.codlivr1
             LEFT JOIN martor.livr l ON l.codlivr = l1.codlivr
             LEFT JOIN martor.intrari i ON i.codintr = l.codintr
          WHERE (l.tiplivr = ANY (ARRAY[1::numeric, 2::numeric, 3::numeric, 4::numeric, 5::numeric, 6::numeric, 7::numeric])) AND l.operat = 1::numeric AND l.anulat = 0::numeric AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND (( SELECT pkg_globals_filtru_stocval_tranzactii_ok.wme_result
                   FROM martor.pkg_globals_filtru_stocval_tranzactii_ok(NULL::numeric, lv.gest, lv.codioart, lv.tvaneex, l.datalivr::timestamp without time zone) pkg_globals_filtru_stocval_tranzactii_ok(wme_result, agest, acodioart, aproctva, adatadoc))) = 1::numeric
        UNION ALL
         SELECT lv.gest,
            lv.codioart,
            lv.tvaneex AS tva,
            (- lv.pretinreg) * l1.cant AS sold,
            (- (lv.pretinreg - lv.pretachiz)) * l1.cant AS adaos,
            0 AS soldintr,
            0 AS adaosintr
           FROM martor.livrval lv
             LEFT JOIN martor.livr1 l1 ON l1.codlivr1 = lv.codlivr1
             LEFT JOIN martor.livr l ON l.codlivr = l1.codlivr
             LEFT JOIN martor.iesiri i ON i.codies = l.codies
          WHERE (l.tiplivr = ANY (ARRAY[14::numeric, 16::numeric, 19::numeric, 20::numeric, 21::numeric, 22::numeric, 23::numeric, 24::numeric])) AND l.operat = 1::numeric AND l.anulat = 0::numeric AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND (( SELECT pkg_globals_filtru_stocval_tranzactii_ok.wme_result
                   FROM martor.pkg_globals_filtru_stocval_tranzactii_ok(NULL::numeric, lv.gest, lv.codioart, lv.tvaneex, l.datalivr::timestamp without time zone) pkg_globals_filtru_stocval_tranzactii_ok(wme_result, agest, acodioart, aproctva, adatadoc))) = 1::numeric
        UNION ALL
         SELECT lv.gest,
            lv.codioart,
            lv.tvaneex AS tva,
            (- lv.pretinreg) * l1.cant AS sold,
            (- (lv.pretinreg - lv.pretachiz)) * l1.cant AS adaos,
            0 AS soldintr,
            0 AS adaosintr
           FROM martor.livrval lv
             LEFT JOIN martor.livr1 l1 ON l1.codlivr1 = lv.codlivr1
             LEFT JOIN martor.livr l ON l.codlivr = l1.codlivr
             LEFT JOIN martor.transf t ON t.codtransf = l.codtransf
          WHERE (l.tiplivr = ANY (ARRAY[12::numeric, 13::numeric])) AND l.operat = 1::numeric AND l.anulat = 0::numeric AND t.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND t.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND (( SELECT pkg_globals_filtru_stocval_tranzactii_ok.wme_result
                   FROM martor.pkg_globals_filtru_stocval_tranzactii_ok(NULL::numeric, lv.gest, lv.codioart, lv.tvaneex, l.datalivr::timestamp without time zone) pkg_globals_filtru_stocval_tranzactii_ok(wme_result, agest, acodioart, aproctva, adatadoc))) = 1::numeric
        UNION ALL
         SELECT lv.gest,
            lv.codioart,
            lv.tvaneex AS tva,
            lv.pretinreg * l1.cant AS sold,
            (lv.pretinreg - lv.pretachiz) * l1.cant AS adaos,
            lv.pretinreg * l1.cant AS soldintr,
            (lv.pretinreg - lv.pretachiz) * l1.cant AS adaosintr
           FROM martor.livrval lv
             LEFT JOIN martor.livr1 l1 ON l1.codlivr1 = lv.codlivr1
             LEFT JOIN martor.livr l ON l.codlivr = l1.codlivr
             LEFT JOIN martor.iesiri i ON i.codies = l.codies
          WHERE l.tiplivr = 15::numeric AND l.operat = 1::numeric AND l.anulat = 0::numeric AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND (( SELECT pkg_globals_filtru_stocval_tranzactii_ok.wme_result
                   FROM martor.pkg_globals_filtru_stocval_tranzactii_ok(NULL::numeric, lv.gest, lv.codioart, lv.tvaneex, l.datalivr::timestamp without time zone) pkg_globals_filtru_stocval_tranzactii_ok(wme_result, agest, acodioart, aproctva, adatadoc))) = 1::numeric) a_pg
  GROUP BY gest, codioart, tva;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_stocval_niruri</obj_name>
  <obj_hashval>4477bed0410a9edc6ccd3155e8ecb3ac</obj_hashval>
  <obj_text>SELECT n.gest,
    ns.codioart,
    ns.tva,
    ns.cantnir * ns.pret AS sold,
    ns.cantnir * ns.adaos AS adaos,
    ns.cantnir * ns.pret AS soldintr,
    ns.cantnir * ns.adaos AS adaosintr
   FROM martor.nirstoc ns
     LEFT JOIN ( SELECT io1.codioart,
            io1.mg,
            io1.difpret,
            io1.aretvaneex
           FROM martor.ioart1 io1
          WHERE (io1.anstart * 12::numeric + io1.lunastart) = (( SELECT max(io2.anstart * 12::numeric + io2.lunastart) AS max
                   FROM martor.ioart1 io2
                  WHERE io2.codioart = io1.codioart AND (io2.anstart * 12::numeric + io2.lunastart) &lt;= (current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric * 12::numeric + current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric)))) ioaluna ON ioaluna.codioart = ns.codioart
     LEFT JOIN martor.nir n ON n.codnir = ns.codnir
     LEFT JOIN martor.intrari i ON i.codintr = n.codintr
  WHERE ioaluna.mg = 5::numeric AND (n.tipnir = ANY (ARRAY[1::numeric, 2::numeric, 3::numeric, 4::numeric, 5::numeric, 6::numeric, 7::numeric])) AND n.anulat = 0::numeric AND n.operat = 1::numeric AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND (( SELECT pkg_globals_filtru_stocval_tranzactii_ok.wme_result
           FROM martor.pkg_globals_filtru_stocval_tranzactii_ok(NULL::numeric, n.gest, ns.codioart, ns.tva, n.datanir::timestamp without time zone) pkg_globals_filtru_stocval_tranzactii_ok(wme_result, agest, acodioart, aproctva, adatadoc))) = 1::numeric
UNION ALL
 SELECT n.gest,
    ns.codioart,
    ns.tva,
    ns.cantnir * ns.pret AS sold,
    ns.cantnir * ns.adaos AS adaos,
    ns.cantnir * ns.pret AS soldintr,
    ns.cantnir * ns.adaos AS adaosintr
   FROM martor.nirstoc ns
     LEFT JOIN ( SELECT io1.codioart,
            io1.mg,
            io1.difpret,
            io1.aretvaneex
           FROM martor.ioart1 io1
          WHERE (io1.anstart * 12::numeric + io1.lunastart) = (( SELECT max(io2.anstart * 12::numeric + io2.lunastart) AS max
                   FROM martor.ioart1 io2
                  WHERE io2.codioart = io1.codioart AND (io2.anstart * 12::numeric + io2.lunastart) &lt;= (current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric * 12::numeric + current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric)))) ioaluna ON ioaluna.codioart = ns.codioart
     LEFT JOIN martor.nir n ON n.codnir = ns.codnir
     LEFT JOIN martor.transf t ON t.codtransf = n.codtransf
  WHERE ioaluna.mg = 5::numeric AND (n.tipnir = ANY (ARRAY[12::numeric, 13::numeric])) AND n.anulat = 0::numeric AND n.operat = 1::numeric AND t.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND t.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND (( SELECT pkg_globals_filtru_stocval_tranzactii_ok.wme_result
           FROM martor.pkg_globals_filtru_stocval_tranzactii_ok(NULL::numeric, n.gest, ns.codioart, ns.tva, n.datanir::timestamp without time zone) pkg_globals_filtru_stocval_tranzactii_ok(wme_result, agest, acodioart, aproctva, adatadoc))) = 1::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_stocval_prec</obj_name>
  <obj_hashval>9dac47c7a720944f7308dee2292ca0d6</obj_hashval>
  <obj_text>SELECT gest,
    codioart,
    tva,
    sold,
    adaos,
    soldintr,
    adaosintr
   FROM martor.stocvalluna
  WHERE an = current_setting('PKG_GLOBALS.ANPRECEDENT'::text, true)::numeric AND luna = current_setting('PKG_GLOBALS.LUNAPRECEDENTA'::text, true)::numeric AND (( SELECT pkg_globals_filtru_stocval_lunaprec_ok.wme_result
           FROM martor.pkg_globals_filtru_stocval_lunaprec_ok(NULL::numeric, stocvalluna.gest, stocvalluna.codioart, stocvalluna.tva) pkg_globals_filtru_stocval_lunaprec_ok(wme_result, agest, acodioart, aproctva))) = 1::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_tarifeman</obj_name>
  <obj_hashval>f758c361ea0fd89a831f84bd14235b1c</obj_hashval>
  <obj_text>SELECT t.codtarif,
    t.denumire,
    COALESCE(( SELECT max(t1.anstart * 12::numeric + t1.lunastart) AS max
           FROM martor.tarifeman1 t1
          WHERE t1.codtarif = t.codtarif AND (t1.anstart * 12::numeric + t1.lunastart) &lt;= (( SELECT pkg_globals_anlunalucru.wme_result
                   FROM martor.pkg_globals_anlunalucru(NULL::numeric, NULL::numeric) pkg_globals_anlunalucru(wme_result, fakeparam)))), 0::numeric) AS activ,
    tarifluna.tarif,
    tarifluna.codtarif1,
    t.codextern,
    COALESCE(t.codmoneda, 0::numeric) AS codmoneda,
    m.den_moneda
   FROM martor.tarifeman t
     LEFT JOIN ( SELECT t1.codtarif1,
            t1.codtarif,
            t1.tarif
           FROM martor.tarifeman1 t1
          WHERE (t1.anstart * 12::numeric + t1.lunastart) = (( SELECT max(t2.anstart * 12::numeric + t2.lunastart) AS max
                   FROM martor.tarifeman1 t2
                  WHERE t2.codtarif = t1.codtarif AND (t2.anstart * 12::numeric + t2.lunastart) &lt;= (( SELECT pkg_globals_anlunalucru.wme_result
                           FROM martor.pkg_globals_anlunalucru(NULL::numeric, NULL::numeric) pkg_globals_anlunalucru(wme_result, fakeparam)))))) tarifluna ON tarifluna.codtarif = t.codtarif
     LEFT JOIN martor.nmonede m ON m.codmoneda = COALESCE(t.codmoneda, 0::numeric);</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_tiplucrarisa</obj_name>
  <obj_hashval>d95a7d95df1d45b20d73c63d5ab29381</obj_hashval>
  <obj_text>SELECT t.codtiplucrare,
    t.denumire,
    t.artservfact,
    t.clasalucrari,
    n.den_gest,
    ia.denumire AS deninterv,
    t.codinterventie
   FROM martor.tiplucrarisa t
     LEFT JOIN martor.ngest n ON n.codgest = t.codgest
     LEFT JOIN martor.ninterventiiauto ia ON ia.codinterventiiauto = t.codinterventie;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_tranz_trez</obj_name>
  <obj_hashval>092aed0e5339c2cd3426d63a489827b2</obj_hashval>
  <obj_text>SELECT t1.codtrezor1,
    t1.codtrezor,
    t1.indexlocal,
    t1.tiptranz,
    t1.carnetdoc,
    t1.doc,
    t1.nrdoc,
    t1.datadoc,
    t1.valdoc,
    t1.curs,
    t1.comision,
    t1.obiecttranz,
    t1.codpart,
    t1.tipdecont,
    t1.datadecont,
    t1.an,
    t1.luna,
    t1.obs,
    t1.initializari,
    t1.agent,
    t1.anulat,
        CASE
            WHEN t1.tiptranz = 0::numeric AND t1.obiecttranz = 0::numeric THEN 'Furnizor '::text
            WHEN t1.tiptranz = 0::numeric AND t1.obiecttranz = 1::numeric THEN 'Retur Client '::text
            WHEN (t1.tiptranz = ANY (ARRAY[0::numeric, 1::numeric])) AND t1.obiecttranz = 3::numeric THEN 'Viramente interne '::text
            WHEN t1.tiptranz = 1::numeric AND t1.obiecttranz = 0::numeric THEN 'Client '::text
            WHEN t1.tiptranz = 1::numeric AND t1.obiecttranz = 1::numeric THEN 'Retur Furnizor '::text
            WHEN t1.obiecttranz = 2::numeric THEN 'Personal angajat '::text
            WHEN t1.tiptranz = 0::numeric AND t1.obiecttranz = 4::numeric THEN 'Servicii, articole fara NIR...'::text
            WHEN t1.tiptranz = 1::numeric AND t1.obiecttranz = 4::numeric THEN 'Direct pe venituri...'::text
            WHEN t1.tiptranz = 0::numeric AND t1.obiecttranz = 5::numeric THEN 'Datorii, taxe, impozite '::text
            WHEN t1.tiptranz = 1::numeric AND t1.obiecttranz = 5::numeric THEN 'Imprumuturi, subventii '::text
            WHEN t1.tiptranz = 1::numeric AND t1.obiecttranz = 6::numeric THEN 'Dobanda la depozit'::text
            ELSE NULL::text
        END::character varying AS dobiecttranz,
        CASE
            WHEN t1.tiptranz = 0::numeric THEN 'Plata'::text
            ELSE 'Incasare'::text
        END::character varying AS dtiptranz,
        CASE
            WHEN t1.tiptranz = 0::numeric AND t1.obiecttranz = 0::numeric THEN ( SELECT p.den_part
               FROM martor.npart p
              WHERE p.codpart = t1.codpart)
            WHEN t1.tiptranz = 0::numeric AND t1.obiecttranz = 1::numeric THEN ( SELECT p.den_part
               FROM martor.npart p
              WHERE p.codpart = t1.codpart)
            WHEN (t1.tiptranz = ANY (ARRAY[0::numeric, 1::numeric])) AND t1.obiecttranz = 3::numeric THEN (( SELECT (b.simbol::text || ' - '::text) || bc.nrcont::text
               FROM martor.nbankcont bc
                 LEFT JOIN martor.nbank b ON b.codbank = bc.codbank
              WHERE bc.codbankcont = t1.codpart))::character varying
            WHEN t1.tiptranz = 1::numeric AND t1.obiecttranz = 0::numeric THEN COALESCE(( SELECT p.den_part
               FROM martor.npart p
              WHERE p.codpart = t1.codpart), ''::character varying)
            WHEN t1.tiptranz = 1::numeric AND t1.obiecttranz = 1::numeric THEN COALESCE(( SELECT p.den_part
               FROM martor.npart p
              WHERE p.codpart = t1.codpart), ''::character varying)
            WHEN t1.obiecttranz = 2::numeric THEN COALESCE(( SELECT (p.nume::text || ' '::text) || p.prenume::text
               FROM martor.npers p
              WHERE p.codpers = t1.codpart), ''::text)::character varying
            ELSE NULL::character varying
        END AS benefplatitor,
    t.userid
   FROM martor.trezor t,
    martor.trezor1 t1
  WHERE (( SELECT pkg_globals_getcoddoccasabanca.wme_result
           FROM martor.pkg_globals_getcoddoccasabanca(NULL::numeric, NULL::numeric) pkg_globals_getcoddoccasabanca(wme_result, fakeparam))) &gt; 0::numeric AND t.codtrezor = (( SELECT pkg_globals_getcoddoccasabanca.wme_result
           FROM martor.pkg_globals_getcoddoccasabanca(NULL::numeric, NULL::numeric) pkg_globals_getcoddoccasabanca(wme_result, fakeparam))) OR t.tipdoc = (( SELECT pkg_globals_gettipdoccasabanca.wme_result
           FROM martor.pkg_globals_gettipdoccasabanca(NULL::numeric, NULL::numeric) pkg_globals_gettipdoccasabanca(wme_result, fakeparam))) AND (t.an * 12::numeric + t.luna) = martor.getanlunalucru() AND t1.codtrezor = t.codtrezor AND COALESCE(t.subunitatea, 1::numeric) =
        CASE
            WHEN martor.getsubunitate() = 1::numeric THEN COALESCE(t.subunitatea, 1::numeric)
            ELSE martor.getsubunitate()
        END;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_trigar</obj_name>
  <obj_hashval>8343b099f433f9f7cb1beec815f1be65</obj_hashval>
  <obj_text>SELECT t.codtrigar,
    t.tablename,
    string_agg(t1.fieldname::text, ','::text)::character varying AS fieldname,
    COALESCE(t.inactiv, 0::numeric) AS inactiv,
    t.obs
   FROM martor.trigar t
     LEFT JOIN martor.trigar1 t1 ON t1.codtrigar = t.codtrigar
  GROUP BY t.codtrigar, t.tablename, (COALESCE(t.inactiv, 0::numeric)), t.obs;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_umsec</obj_name>
  <obj_hashval>5a940c4d052a0d46b8a3cacd59d4aea8</obj_hashval>
  <obj_text>SELECT codum1,
    codum,
    secundara,
    den_um1,
    paritate,
    zecimale,
    obs
   FROM martor.num1
  WHERE (( SELECT pkg_selectarticole_conditieumprincipala.wme_result
           FROM martor.pkg_selectarticole_conditieumprincipala(NULL::numeric, num1.codum) pkg_selectarticole_conditieumprincipala(wme_result, ump))) = 1::numeric AND COALESCE(inactiv, 0::numeric) = 0::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_utilaje</obj_name>
  <obj_hashval>cc794ccccf5936a99fd4aed3c8ad3021</obj_hashval>
  <obj_text>SELECT u.codutilaj,
    nobj.denumire,
        CASE
            WHEN u.nrinventar = 0::numeric THEN NULL::numeric
            ELSE u.nrinventar
        END AS nrinventar,
    u.eticheta,
    u.tiputilaj,
    u.flota,
    u.inactiv,
    u.codobiect,
    g.codgest,
    g.den_gest,
    g.oreschimb,
    m.codmifix,
    g.nrschimburi,
    u.um,
    um.den_um,
    u.model,
    u.serief,
    COALESCE(u.aprobat, 0::numeric) AS aprobat,
    COALESCE(p.den_part, '?'::character varying) AS furnizor,
        CASE
            WHEN u.doc IS NULL AND i.codies &gt; 0::numeric THEN ((i.nrdoc || '/'::text) || to_char(i.datadoc::timestamp with time zone, 'DD.MM.YYYY'::text))::character varying
            ELSE u.doc
        END AS doc,
    COALESCE(cli.den_part, '?'::character varying) AS client,
    u.codpart,
    u.codies1,
    u.datagarantiei,
    u.datagarantie,
        CASE
            WHEN u.ingarantie = 1::numeric THEN 'DA'::text
            ELSE 'NU'::text
        END::character varying AS ingarantiestr,
        CASE
            WHEN u.tip = 0::numeric THEN 'Utilaj propriu'::text
            WHEN u.tip = 1::numeric THEN 'Utilaj in custodie la client'::text
            WHEN u.tip = 2::numeric THEN 'Utilaj client cu vanzare proprie'::text
            WHEN u.tip = 3::numeric THEN 'Utilaj client cu alt furnizor'::text
            WHEN u.tip = 4::numeric THEN 'Utilaj inchiriat clientului'::text
            ELSE NULL::text
        END::character varying AS tip,
    u.tip AS tipn,
    ((ag.nume::text || ' '::text) || ag.prenume::text)::character varying AS agent,
    u.nrcontr,
    u.datacontr,
    u.anf,
    nobj.codextern,
    nobj.codintern,
    prod.den_part AS producator,
    cli.codextern AS codexterncli,
    cli.codintern AS codinterncli,
    loc.den_localit,
    u.adresa,
    mdf.data_last_modif,
    u.obs
   FROM martor.utilaje u
     JOIN martor.nartobj nobj ON u.codobiect = nobj.codobiect
     LEFT JOIN martor.npers ag ON ag.codpers = u.agent
     LEFT JOIN martor.num um ON um.codum = u.um
     LEFT JOIN martor.mifix m ON m.nrinventar = u.nrinventar AND m.tip::text = 'MF'::text
     LEFT JOIN martor.mifix1 m1 ON m.codmifix = m1.codmifix AND (m1.anstart * 12::numeric + m1.lunastart) = (( SELECT pkg_globals_anlunalucru.wme_result
           FROM martor.pkg_globals_anlunalucru(NULL::numeric, NULL::numeric) pkg_globals_anlunalucru(wme_result, fakeparam)))
     LEFT JOIN martor.nirstoc ns ON ns.codnirstoc = m1.codnirstoc
     LEFT JOIN martor.nir ON nir.codnir = ns.codnir
     LEFT JOIN martor.ngest g ON g.codgest = nir.gest
     LEFT JOIN martor.iesiri1 i1 ON i1.codies1 = u.codies1
     LEFT JOIN martor.iesiri i ON i1.codies = i.codies
     LEFT JOIN martor.npart p ON u.codfurnizor = p.codpart
     LEFT JOIN martor.npart prod ON COALESCE(u.codproducator, nobj.codproducator, 0::numeric) = prod.codpart
     LEFT JOIN martor.npart cli ON u.codpart = cli.codpart
     LEFT JOIN martor.nlocalit loc ON loc.codlocalit = u.codlocalit
     LEFT JOIN ( SELECT DISTINCT modif.codmaster,
            last_value(modif.datamodif) OVER (PARTITION BY modif.codmaster ORDER BY modif.datamodif RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS data_last_modif
           FROM martor.modificari modif
          WHERE modif.tablename::text = 'UTILAJE'::text) mdf ON mdf.codmaster = u.codutilaj;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_utilaje_contor</obj_name>
  <obj_hashval>21e43da67cb3d80432ab87e2be43401e</obj_hashval>
  <obj_text>SELECT u.codutilaj,
    u.codobiect,
        CASE
            WHEN u.tip = 0::numeric THEN 'Utilaj propriu'::text
            WHEN u.tip = 1::numeric THEN 'Utilaj in custodie la client'::text
            WHEN u.tip = 2::numeric THEN 'Utilaj client cu vanzare proprie'::text
            WHEN u.tip = 3::numeric THEN 'Utilaj client cu alt furnizor'::text
            WHEN u.tip = 4::numeric THEN 'Utilaj inchiriat clientului'::text
            ELSE NULL::text
        END AS tip,
    nobj.denumire,
    u.model,
    u.serief,
    NULLIF(u.nrinventar, 0::numeric) AS nrinventar,
    u.eticheta,
    u.tiputilaj,
    u.flota,
    u.inactiv,
    COALESCE(u.aprobat, 0::numeric) AS aprobat,
    u.tip AS tipn,
    u.datagarantiei,
    u.datagarantie,
        CASE
            WHEN u.ingarantie = 1::numeric THEN 'DA'::text
            ELSE 'NU'::text
        END AS ingarantiestr,
    u.nrcontr,
    u.datacontr,
    u.anf,
    u.codpart,
    u.codies1,
    prod.den_part AS producator,
    COALESCE(furn.den_part, '?'::character varying) AS furnizor,
    COALESCE(cli.den_part, '?'::character varying) AS client,
    (ag.nume::text || ' '::text) || ag.prenume::text AS agent,
    um.codum AS um,
    um.den_um,
    u.adresa,
    loc.den_localit,
    COALESCE(uidx.tip_index, 0::numeric) AS tip_index,
    uidx.denumire AS dencontor,
    uidx.plafoncantf
   FROM martor.utilaje u
     JOIN martor.nartobj nobj ON nobj.codobiect = u.codobiect
     LEFT JOIN martor.utilajetipindex uidx ON uidx.codutilaj = u.codutilaj
     LEFT JOIN martor.num um ON um.codum = COALESCE(uidx.um, u.um)
     LEFT JOIN martor.npart furn ON furn.codpart = u.codfurnizor
     LEFT JOIN martor.npart prod ON prod.codpart = COALESCE(u.codproducator, nobj.codproducator, 0::numeric)
     LEFT JOIN martor.npart cli ON cli.codpart = u.codpart
     LEFT JOIN martor.npers ag ON ag.codpers = u.agent
     LEFT JOIN martor.nlocalit loc ON loc.codlocalit = u.codlocalit;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>vnpart</obj_name>
  <obj_hashval>6f2ab1f866937f568074357a1b334acd</obj_hashval>
  <obj_text>SELECT p.codpart,
    p.den_part,
    p.regcom,
    p.codextern,
    p.codmoneda,
    p.autorizatie,
    p.codintern,
    p.codclasa,
    p.codcategpret,
    p.tippart,
    p.scadentac,
    p.scadentav,
    p.discount,
    p.codcategdisc,
    p.blocat,
    p.tippartener,
    p.dataadaugarii,
    p.obs,
    p.poza,
    p.persoanafizica,
    p.verfact,
    p.verdisplivr,
    p.coldiscount,
    p.infoblocat,
    p.expirareautoriz,
    p.codstatisticbnr,
    p.musaicolet,
    p.strategic,
    p.cifraafaceri,
    p.domeniuactiv,
    p.nrangajati,
    p.sursalead,
    p.lead,
    p.tvalaincasare,
    p.modaplicprocdisc,
    p.proccurstransf,
    p.verproforma,
    p.fidelizare,
    p.majorari,
    p.tipblocaj,
    p.poprire_anaf,
    p.codresponsabil,
    p.coddomeniuact,
    p.docdefonorcom,
    p.modpromofactcom,
    p.validarepretoferta,
    p.iescucomanda,
    p.verfactaviz,
    p.valmincmd,
    p.cantmincmd,
    p.ziaproviz,
    p.peraproviz,
    p.codcontractcadru,
    p.datanastere,
    p.splittva,
    p.gdpr,
    p.zilelivrare,
    f.codfiscal
   FROM martor.npart p
     LEFT JOIN martor.npartcodfisc f ON f.codpart = p.codpart AND f.principal = 1::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_rest_obligpif_luna</obj_name>
  <obj_hashval>ef15a9083ad3396cf91d172c39ed23c2</obj_hashval>
  <obj_text>SELECT codobligpif,
    sum(rest) AS rest,
    sum(resttva) AS resttva,
    sum(COALESCE(restsplittva, 0::numeric)) AS restsplittva
   FROM ( SELECT v_rest_obligpif_prec.codobligpif,
            v_rest_obligpif_prec.rest,
            v_rest_obligpif_prec.resttva,
            v_rest_obligpif_prec.restsplittva
           FROM martor.v_rest_obligpif_prec
        UNION ALL
         SELECT v_obligpif_de_stins_luna.codobligpif,
            v_obligpif_de_stins_luna.rest,
            v_obligpif_de_stins_luna.resttva,
            v_obligpif_de_stins_luna.restsplittva
           FROM martor.v_obligpif_de_stins_luna
        UNION ALL
         SELECT v_obligpif_stingeri_luna.codobligpif,
            v_obligpif_stingeri_luna.rest,
            v_obligpif_stingeri_luna.resttva,
            v_obligpif_stingeri_luna.restsplittva
           FROM martor.v_obligpif_stingeri_luna) a_pg
  GROUP BY codobligpif;</obj_text>
  <obj_nivel>1</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_solduribanciluna</obj_name>
  <obj_hashval>6dc1beffec49ca7191a1fdc0e56793ac</obj_hashval>
  <obj_text>SELECT codbankcont,
    sum(soldlei) AS soldlei,
    sum(soldvaluta) AS soldvaluta
   FROM ( SELECT v_solduribanci_tranzactii.codbankcont,
            v_solduribanci_tranzactii.soldlei,
            v_solduribanci_tranzactii.soldvaluta
           FROM martor.v_solduribanci_tranzactii
        UNION ALL
         SELECT v_solduribancilunaprec.codbankcont,
            v_solduribancilunaprec.soldlei,
            v_solduribancilunaprec.soldvaluta
           FROM martor.v_solduribancilunaprec) a_pg
  GROUP BY codbankcont;</obj_text>
  <obj_nivel>1</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_stocval_tranzactii</obj_name>
  <obj_hashval>576374e90ffce55a63de6eeec6be07e0</obj_hashval>
  <obj_text>SELECT gest,
    codioart,
    tva,
    sum(sold) AS sold,
    sum(adaos) AS adaos,
    sum(soldintr) AS soldintr,
    sum(adaosintr) AS adaosintr
   FROM ( SELECT v_stocval_niruri.gest,
            v_stocval_niruri.codioart,
            v_stocval_niruri.tva,
            v_stocval_niruri.sold,
            v_stocval_niruri.adaos,
            v_stocval_niruri.soldintr,
            v_stocval_niruri.adaosintr
           FROM martor.v_stocval_niruri
        UNION ALL
         SELECT v_stocval_livrari.gest,
            v_stocval_livrari.codioart,
            v_stocval_livrari.tva,
            v_stocval_livrari.sold,
            v_stocval_livrari.adaos,
            v_stocval_livrari.soldintr,
            v_stocval_livrari.adaosintr
           FROM martor.v_stocval_livrari) a_pg
  GROUP BY gest, codioart, tva;</obj_text>
  <obj_nivel>1</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_stoc_tranzactii_luna</obj_name>
  <obj_hashval>c266cc4032f13e4117209506bbf081b8</obj_hashval>
  <obj_text>SELECT codnirstoc,
    sum(rest) AS rest,
    sum(restum1) AS restum1,
    sum(restum2) AS restum2
   FROM ( SELECT v_niruri_luna.codnirstoc,
            v_niruri_luna.rest,
            v_niruri_luna.restum1,
            v_niruri_luna.restum2
           FROM martor.v_niruri_luna
        UNION ALL
         SELECT v_livrari_luna.codnirstoc,
            v_livrari_luna.rest,
            v_livrari_luna.restum1,
            v_livrari_luna.restum2
           FROM martor.v_livrari_luna) a_pg
  GROUP BY codnirstoc;</obj_text>
  <obj_nivel>1</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpers_tranzactii</obj_name>
  <obj_hashval>5000fca8341f08875501c8327ca4b203</obj_hashval>
  <obj_text>SELECT codpers,
    icont,
    codmoneda,
    sum(soldlei) AS soldlei,
    sum(soldvaluta) AS soldvaluta
   FROM ( SELECT v_soldpers_justif.codpers,
            v_soldpers_justif.icont,
            v_soldpers_justif.codmoneda,
            v_soldpers_justif.soldlei,
            v_soldpers_justif.soldvaluta
           FROM martor.v_soldpers_justif
        UNION ALL
         SELECT v_soldpers_avans.codpers,
            v_soldpers_avans.icont,
            v_soldpers_avans.codmoneda,
            v_soldpers_avans.soldlei,
            v_soldpers_avans.soldvaluta
           FROM martor.v_soldpers_avans
        UNION ALL
         SELECT v_soldpers_nc_debit.codpers,
            v_soldpers_nc_debit.icont,
            v_soldpers_nc_debit.codmoneda,
            v_soldpers_nc_debit.soldlei,
            v_soldpers_nc_debit.soldvaluta
           FROM martor.v_soldpers_nc_debit
        UNION ALL
         SELECT v_soldpers_nc_credit.codpers,
            v_soldpers_nc_credit.icont,
            v_soldpers_nc_credit.codmoneda,
            v_soldpers_nc_credit.soldlei,
            v_soldpers_nc_credit.soldvaluta
           FROM martor.v_soldpers_nc_credit
        UNION ALL
         SELECT v_convert_soldpers_in.codpers,
            v_convert_soldpers_in.icont,
            v_convert_soldpers_in.codmoneda,
            v_convert_soldpers_in.soldlei,
            v_convert_soldpers_in.soldvaluta
           FROM martor.v_convert_soldpers_in
        UNION ALL
         SELECT v_convert_soldpers_out.codpers,
            v_convert_soldpers_out.icont,
            v_convert_soldpers_out.codmoneda,
            v_convert_soldpers_out.soldlei,
            v_convert_soldpers_out.soldvaluta
           FROM martor.v_convert_soldpers_out) a_pg
  GROUP BY codpers, icont, codmoneda;</obj_text>
  <obj_nivel>1</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpersoana_luna</obj_name>
  <obj_hashval>3f23abeac9ccf820526c0571150dc7ca</obj_hashval>
  <obj_text>SELECT codpers,
    icont,
    codmoneda,
    sum(soldlei) AS soldlei,
    sum(soldvaluta) AS soldvaluta
   FROM ( SELECT v_soldpersoana_luna_tranzactii.codpers,
            v_soldpersoana_luna_tranzactii.icont,
            v_soldpersoana_luna_tranzactii.codmoneda,
            v_soldpersoana_luna_tranzactii.soldlei,
            v_soldpersoana_luna_tranzactii.soldvaluta
           FROM martor.v_soldpersoana_luna_tranzactii
        UNION ALL
         SELECT v_soldpersoana_luna_prec.codpers,
            v_soldpersoana_luna_prec.icont,
            v_soldpersoana_luna_prec.codmoneda,
            v_soldpersoana_luna_prec.soldlei,
            v_soldpersoana_luna_prec.soldvaluta
           FROM martor.v_soldpersoana_luna_prec) a_pg
  GROUP BY codpers, icont, codmoneda;</obj_text>
  <obj_nivel>2</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpers_tranzactii_sub</obj_name>
  <obj_hashval>638584ed3ef104b317f979062c0a7dbe</obj_hashval>
  <obj_text>SELECT codpers,
    icont,
    codmoneda,
    subunitatea,
    sum(soldlei) AS soldlei,
    sum(soldvaluta) AS soldvaluta
   FROM ( SELECT v_soldpers_justif_sub.codpers,
            v_soldpers_justif_sub.icont,
            v_soldpers_justif_sub.codmoneda,
            v_soldpers_justif_sub.subunitatea,
            v_soldpers_justif_sub.soldlei,
            v_soldpers_justif_sub.soldvaluta
           FROM martor.v_soldpers_justif_sub
        UNION ALL
         SELECT v_soldpers_avans_sub.codpers,
            v_soldpers_avans_sub.icont,
            v_soldpers_avans_sub.codmoneda,
            v_soldpers_avans_sub.subunitatea,
            v_soldpers_avans_sub.soldlei,
            v_soldpers_avans_sub.soldvaluta
           FROM martor.v_soldpers_avans_sub
        UNION ALL
         SELECT v_soldpers_nc_debit_sub.codpers,
            v_soldpers_nc_debit_sub.icont,
            v_soldpers_nc_debit_sub.codmoneda,
            v_soldpers_nc_debit_sub.subunitatea,
            v_soldpers_nc_debit_sub.soldlei,
            v_soldpers_nc_debit_sub.soldvaluta
           FROM martor.v_soldpers_nc_debit_sub
        UNION ALL
         SELECT v_soldpers_nc_credit_sub.codpers,
            v_soldpers_nc_credit_sub.icont,
            v_soldpers_nc_credit_sub.codmoneda,
            v_soldpers_nc_credit_sub.subunitatea,
            v_soldpers_nc_credit_sub.soldlei,
            v_soldpers_nc_credit_sub.soldvaluta
           FROM martor.v_soldpers_nc_credit_sub
        UNION ALL
         SELECT v_convert_soldpers_in_sub.codpers,
            v_convert_soldpers_in_sub.icont,
            v_convert_soldpers_in_sub.codmoneda,
            v_convert_soldpers_in_sub.subunitatea,
            v_convert_soldpers_in_sub.soldlei,
            v_convert_soldpers_in_sub.soldvaluta
           FROM martor.v_convert_soldpers_in_sub
        UNION ALL
         SELECT v_convert_soldpers_out_sub.codpers,
            v_convert_soldpers_out_sub.icont,
            v_convert_soldpers_out_sub.codmoneda,
            v_convert_soldpers_out_sub.subunitatea,
            v_convert_soldpers_out_sub.soldlei,
            v_convert_soldpers_out_sub.soldvaluta
           FROM martor.v_convert_soldpers_out_sub) a_pg
  GROUP BY codpers, icont, codmoneda, subunitatea;</obj_text>
  <obj_nivel>1</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldbankluna</obj_name>
  <obj_hashval>23ef09bf846693d12a0f48c4e1a01da5</obj_hashval>
  <obj_text>SELECT codbankcont,
    sum(soldlei) AS soldlei,
    sum(soldvaluta) AS soldvaluta
   FROM ( SELECT v_soldbank_tranzactii.codbankcont,
            v_soldbank_tranzactii.soldlei,
            v_soldbank_tranzactii.soldvaluta
           FROM martor.v_soldbank_tranzactii
        UNION ALL
         SELECT v_soldbanklunaprec.codbankcont,
            v_soldbanklunaprec.soldlei,
            v_soldbanklunaprec.soldvaluta
           FROM martor.v_soldbanklunaprec) a_pg
  GROUP BY codbankcont;</obj_text>
  <obj_nivel>1</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_stocval</obj_name>
  <obj_hashval>8aef36a3bcbd8691095114bf2f7b9cd9</obj_hashval>
  <obj_text>SELECT gest,
    codioart,
    tva,
    sum(sold) AS sold,
    sum(adaos) AS adaos,
    sum(soldintr) AS soldintr,
    sum(adaosintr) AS adaosintr
   FROM ( SELECT v_stocval_tranzactii.gest,
            v_stocval_tranzactii.codioart,
            v_stocval_tranzactii.tva,
            v_stocval_tranzactii.sold,
            v_stocval_tranzactii.adaos,
            v_stocval_tranzactii.soldintr,
            v_stocval_tranzactii.adaosintr
           FROM martor.v_stocval_tranzactii
        UNION ALL
         SELECT v_stocval_prec.gest,
            v_stocval_prec.codioart,
            v_stocval_prec.tva,
            v_stocval_prec.sold,
            v_stocval_prec.adaos,
            v_stocval_prec.soldintr,
            v_stocval_prec.adaosintr
           FROM martor.v_stocval_prec) a_pg
  GROUP BY gest, codioart, tva;</obj_text>
  <obj_nivel>2</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_rac_transfer</obj_name>
  <obj_hashval>ca0071a6ef917a6690d57345c198479c</obj_hashval>
  <obj_text>SELECT x.codgestsursa,
    x.codgestdest,
    x.codauto,
    x.datastart,
    x.datastop,
    x.datapred
   FROM ( SELECT r.codgestsursa,
            r.codgestdest,
            COALESCE(c.mijltransp, 0::numeric) AS codauto,
            r.datastart,
            r.datastop,
            r.datapred
           FROM martor.rac_rez r
             JOIN martor.comanda c ON r.codcomanda = c.codcomanda
          WHERE COALESCE(c.operat, 0::numeric) = 1::numeric AND COALESCE(r.predat, 0::numeric) = 1::numeric AND r.codgestsursa &lt;&gt; r.codgestdest AND (( SELECT pkg_rac_rez_rac_datastart.wme_result
                   FROM martor.pkg_rac_rez_rac_datastart(NULL::date, NULL::numeric) pkg_rac_rez_rac_datastart(wme_result, fakeparam))) &gt; r.datapred
        UNION ALL
         SELECT x_1.codgestdest AS codgestsursa,
            r.codgestsursa AS codgestdest,
            COALESCE(c.mijltransp, 0::numeric) AS codauto,
            r.datastart,
            r.datastop,
            r.datapred
           FROM martor.rac_rez r
             JOIN martor.comanda c ON r.codcomanda = c.codcomanda
             JOIN martor.comanda xx ON xx.codcomanda = r.codrezervare
             JOIN martor.rac_rez x_1 ON x_1.codcomanda = xx.codcomanda
          WHERE COALESCE(c.operat, 0::numeric) = 1::numeric AND COALESCE(r.predat, 0::numeric) = 1::numeric AND COALESCE(r.codrezervare, 0::numeric) &gt; 0::numeric AND COALESCE(xx.mijltransp, 0::numeric) = COALESCE(c.mijltransp, 0::numeric) AND r.codgestsursa &lt;&gt; r.codgestdest AND (( SELECT pkg_rac_rez_rac_datastart.wme_result
                   FROM martor.pkg_rac_rez_rac_datastart(NULL::date, NULL::numeric) pkg_rac_rez_rac_datastart(wme_result, fakeparam))) &gt; r.datapred) x
     JOIN martor.v_rac_cars p ON p.codauto = x.codauto;</obj_text>
  <obj_nivel>1</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpersoana_luna_tranzactii</obj_name>
  <obj_hashval>1270092be3016e023e9d108ab2ad2e86</obj_hashval>
  <obj_text>SELECT codpers,
    icont,
    codmoneda,
    sum(soldlei) AS soldlei,
    sum(soldvaluta) AS soldvaluta
   FROM ( SELECT v_soldpersoana_luna_justif.codpers,
            v_soldpersoana_luna_justif.icont,
            v_soldpersoana_luna_justif.codmoneda,
            v_soldpersoana_luna_justif.soldlei,
            v_soldpersoana_luna_justif.soldvaluta
           FROM martor.v_soldpersoana_luna_justif
        UNION ALL
         SELECT v_soldpersoana_luna_avans.codpers,
            v_soldpersoana_luna_avans.icont,
            v_soldpersoana_luna_avans.codmoneda,
            v_soldpersoana_luna_avans.soldlei,
            v_soldpersoana_luna_avans.soldvaluta
           FROM martor.v_soldpersoana_luna_avans
        UNION ALL
         SELECT v_soldpersoana_luna_nc_debit.codpers,
            v_soldpersoana_luna_nc_debit.icont,
            v_soldpersoana_luna_nc_debit.codmoneda,
            v_soldpersoana_luna_nc_debit.soldlei,
            v_soldpersoana_luna_nc_debit.soldvaluta
           FROM martor.v_soldpersoana_luna_nc_debit
        UNION ALL
         SELECT v_soldpersoana_luna_nc_credit.codpers,
            v_soldpersoana_luna_nc_credit.icont,
            v_soldpersoana_luna_nc_credit.codmoneda,
            v_soldpersoana_luna_nc_credit.soldlei,
            v_soldpersoana_luna_nc_credit.soldvaluta
           FROM martor.v_soldpersoana_luna_nc_credit
        UNION ALL
         SELECT v_convert_soldpers_luna_in.codpers,
            v_convert_soldpers_luna_in.icont,
            v_convert_soldpers_luna_in.codmoneda,
            v_convert_soldpers_luna_in.soldlei,
            v_convert_soldpers_luna_in.soldvaluta
           FROM martor.v_convert_soldpers_luna_in
        UNION ALL
         SELECT v_convert_soldpers_luna_out.codpers,
            v_convert_soldpers_luna_out.icont,
            v_convert_soldpers_luna_out.codmoneda,
            v_convert_soldpers_luna_out.soldlei,
            v_convert_soldpers_luna_out.soldvaluta
           FROM martor.v_convert_soldpers_luna_out) a_pg
  GROUP BY codpers, icont, codmoneda;</obj_text>
  <obj_nivel>1</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_auto</obj_name>
  <obj_hashval>29f7994fc5bd08c0642c2173bdc06926</obj_hashval>
  <obj_text>WITH pg AS (
         SELECT p.codnparcaut AS codauto,
            COALESCE(p.codgestini, 0::numeric) AS codgestini,
            p.codgest,
            COALESCE(p.codcmd, 0::numeric) AS codcmd,
            p.data
           FROM ( SELECT nparcg.codnparcg,
                    nparcg.codnparcaut,
                    nparcg.codgestini,
                    nparcg.codgest,
                    nparcg.codcmd,
                    nparcg.status,
                    nparcg.data
                   FROM martor.nparcg
                  WHERE COALESCE(nparcg.codgest, 0::numeric) &gt; 0::numeric
                  ORDER BY nparcg.codnparcaut, nparcg.data) p
        ), ptransf AS (
         SELECT x_1.codcmd,
            x_1.codauto,
            x_1.data,
            x_1.codgest,
            x_1.codgestini AS codgestprec
           FROM pg x_1
          WHERE x_1.codcmd = 0::numeric
        ), cars AS (
         SELECT COALESCE(nparcaut.codgest, 0::numeric) AS codgest,
            nparcaut.codnparcaut AS codauto,
            nparcaut.codart AS codobiect
           FROM martor.nparcaut
          WHERE COALESCE(nparcaut.extern, 0::numeric) = 0::numeric AND COALESCE(nparcaut.codgest, 0::numeric) &gt; 0::numeric
        ), vractransfer AS (
         SELECT v_rac_transfer.codgestsursa,
            v_rac_transfer.codgestdest,
            v_rac_transfer.codauto,
            v_rac_transfer.datastart,
            v_rac_transfer.datastop,
            v_rac_transfer.datapred
           FROM martor.v_rac_transfer
        )
 SELECT x.codauto,
    x.codobiect,
    x.codgest,
    x.transferat,
    x.q,
    x.datastart,
    x.datastop,
    gg.codclasa
   FROM ( SELECT t.codauto,
            c.codobiect,
            t.codgestsursa AS codgest,
            1 AS transferat,
            '-1'::integer AS q,
            t.datastart,
            t.datastop
           FROM vractransfer t
             JOIN cars c ON c.codauto = t.codauto
        UNION ALL
         SELECT t.codauto,
            c.codobiect,
            t.codgestdest AS codgest,
            1 AS transferat,
            + 1 AS q,
            t.datastart,
            t.datastop
           FROM vractransfer t
             JOIN cars c ON c.codauto = t.codauto
        UNION ALL
         SELECT t.codauto,
            c.codobiect,
            t.codgestprec AS codgest,
            0 AS transferat,
            '-1'::integer AS q,
            t.data AS datastart,
            t.data AS datastop
           FROM ptransf t
             JOIN cars c ON c.codauto = t.codauto
          WHERE t.codgestprec &lt;&gt; 0::numeric
        UNION ALL
         SELECT t.codauto,
            c.codobiect,
            t.codgest,
            0 AS transferat,
            + 1 AS q,
            t.data AS datastart,
            t.data AS datastop
           FROM ptransf t
             JOIN cars c ON c.codauto = t.codauto) x
     JOIN martor.ngest gg ON gg.codgest = x.codgest;</obj_text>
  <obj_nivel>2</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_stocluna</obj_name>
  <obj_hashval>c595bee8a150608b79eb873e36a90091</obj_hashval>
  <obj_text>SELECT codnirstoc,
    sum(rest) AS rest,
    sum(restum1) AS restum1,
    sum(restum2) AS restum2
   FROM ( SELECT v_stoc_luna_prec.codnirstoc,
            v_stoc_luna_prec.rest,
            v_stoc_luna_prec.restum1,
            v_stoc_luna_prec.restum2
           FROM martor.v_stoc_luna_prec
        UNION ALL
         SELECT v_stoc_tranzactii_luna.codnirstoc,
            v_stoc_tranzactii_luna.rest,
            v_stoc_tranzactii_luna.restum1,
            v_stoc_tranzactii_luna.restum2
           FROM martor.v_stoc_tranzactii_luna) a_pg
  GROUP BY codnirstoc;</obj_text>
  <obj_nivel>2</obj_nivel>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_prodestprj_setjoinuri</obj_name>
  <obj_hashval>06c8a31b148043c9ab3b0af195e581c0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_prodestprj_setjoinuri()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 03.06.2025
  PERFORM Pkg_List_Struct_SetTableSpec(current_setting('PKG_LIST_BASE_PRODESTPRJ.gSuplCols', true));
  PERFORM Pkg_List_Struct_AdunaColoanele();
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_restsitlistgest_setjoinuri</obj_name>
  <obj_hashval>254c10d0209f3e77a190a55ee4ad9841</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_restsitlistgest_setjoinuri()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 21.05.2025
  PERFORM pkg_list_struct_SetTableSpec((current_setting('PKG_LIST_BASE_RESTSITLISTGEST.gSuplCols', true)));
  PERFORM pkg_list_struct_AdunaColoanele();
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rapstocmed_vnewdata</obj_name>
  <obj_hashval>44dda8765f48fc2f828c389227850d72</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rapstocmed_vnewdata(INOUT wme_result date, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := current_setting('PKG_RAPSTOCMED.vNewData', true);
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reclamatii_carnetdoc_i</obj_name>
  <obj_hashval>02a9193b6d55dc918e20554aae9982d0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reclamatii_carnetdoc_i(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_RECLAMATII.CARNETDOC_I', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reclamatii_setcarnetdoc_i</obj_name>
  <obj_hashval>55b7f716656291ad259e00c41c349a2f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reclamatii_setcarnetdoc_i(acarnetdoc_i numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_RECLAMATII.CARNETDOC_I',to_char(aCARNETDOC_I,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_data_reg</obj_name>
  <obj_hashval>62fbd689eff98a5a640fab5051a7982c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_data_reg(INOUT wme_result date, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_REG.data_reg', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_setcursparamsreg</obj_name>
  <obj_hashval>0bb5ab45636fa96d74a7ad1b77ecf742</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_setcursparamsreg(data_p character varying, bank_p numeric, moneda_p numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_REG_SetDataReg( data_p);
  PERFORM PKG_REG_SetBankReg( bank_p);
  PERFORM PKG_REG_SetMonedaReg( moneda_p);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_setcursreg</obj_name>
  <obj_hashval>e0f759ac822c89a4c69b150580208cbb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_setcursreg(curs_p numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REG.curs_reg',to_char(curs_p,'99999999999.9999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_getdiferente</obj_name>
  <obj_hashval>7d8d77ce68d2a65e20bd6117e72fb1fb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_getdiferente(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REGPART.DIFERENTE')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_getinclusiv_avans_facturat</obj_name>
  <obj_hashval>63eafd20d0a7d6c8ec155fb98a4f7609</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_getinclusiv_avans_facturat(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REGPART.INCLUSIV_AVANS_FACTURAT')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 1;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_make_regpart_luna</obj_name>
  <obj_hashval>4eb8365c7b49ff2fe68897b3e944bb80</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_make_regpart_luna()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC           RECORD;
  aPREFIXDOC      varchar := NULL;
  aDATADOC        date := NULL;
  aNRDOC          numeric := NULL;
  aSUBUNITATEA    numeric := NULL;
  vSQL            varchar;
  -- globals
  vAnPrecedent    numeric;
  vLunaPrecedenta numeric;
  ContRegAvans    numeric(5) := 0;
begin
  --Florin 16.10.2025 - sinc. Oracle
  --Florin 26.08.2025 - sinc. Oracle
  --Bogdan 17.08.2020
  DELETE FROM TMP_REGPART_LUNA;

  select PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA.newan, PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA.newluna
  from   PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric,
                          current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric,
                          vAnPrecedent, vLunaPrecedenta) into vAnPrecedent, vLunaPrecedenta;

  perform set_config('PKG_GLOBALS.ANPRECEDENT',vAnPrecedent::varchar,false);
  perform set_config('PKG_GLOBALS.LUNAPRECEDENTA',vLunaPrecedenta::varchar,false);

  PERFORM PKG_GLOBALS_MAKE_IOPART_LUNA();
  PERFORM PKG_NOMPART_MAKE_CURS_GENERAL_LUNA( '01.' || current_setting('PKG_GLOBALS.LUNALUCRU',true) || '.' || current_setting('PKG_GLOBALS.ANLUCRU',true));
  PERFORM PKG_REGPART_MAKE_STINGERE_LUNA();

  vSQL := '  INSERT INTO TMP_REGPART_LUNA (
            CODGENERAL, SOLDDOCVAL, SOLDDOC, ICONT, SEMNIFICATIE, CODPART,
            CODIOPART1, CODGEST, CURS, TVA, COEFPROVIZION, CODOBLIGPIF
        ) SELECT RG.CODGENERAL,
              (  VALOARE - ROUND( COALESCE( STINS, 0), 7))  * CURS,
              VALOARE - ROUND( COALESCE( STINS, 0), 7) AS SOLDDOC,
              RG.ICONT,
              RG.SEMNIFICATIE,
              RG.CODPART,
              RG.CODIOPART1,
              RG.CODGEST,
              RG.CURS,
              RG.TVA,
              RG.COEFPROVIZION,
              RG.CODOBLIGPIF
          FROM (SELECT *
                FROM (' ||pkg_regpart_get_V_REGPART_LUNAPREC_SQL()|| ') a_pg
                union ALL
                SELECT *
                FROM  (' ||pkg_regpart_get_V_REGPART_DE_STINS_SQL()|| '  ) b_pg
                ) RG
          WHERE
               (SELECT WME_RESULT
                FROM PKG_REGPART_CONDITIE_MARJA_REGAVIZE(NULL, ROUND( COALESCE( VALOARE, 0), 4) - ROUND( COALESCE( STINS, 0), 4))) = 1
              AND  (SELECT WME_RESULT FROM PKG_REGPART_CONDITIE_AVIZE               (NULL, RG.ICONT)) = 1
              AND  (SELECT WME_RESULT FROM PKG_REGPART_CONDITIE_AVANS_FACTURAT      (NULL, RG.SEMNIFICATIE)) = 1
              AND  (SELECT WME_RESULT FROM PKG_REGPART_CONDITIE_LITIGII             (NULL, RG.SEMNIFICATIE)) = 1
              AND  (SELECT WME_RESULT FROM PKG_REGPART_CONDITIE_GARANTII            (NULL, RG.SEMNIFICATIE)) = 1
              AND  (SELECT WME_RESULT FROM PKG_REGPART_CONDITIE_ICONT_AVANS_FACTURAT(NULL, RG.ICONT)) = 1
              AND  PKG_REGPART_CONDITIE_AVANS_PE_NC(RG.SEMNIFICATIE, RG.ICONT) = 1
              AND  (SELECT WME_RESULT FROM PKG_REGPART_CONDITIE_CECURI              (NULL, RG.SEMNIFICATIE)) = 1';
   execute vSQL;

   select count(*) INTO ContRegAvans -- testez daca nu este armata constanta care spune ce conturi de avans se regularizeaza
    from
      const1 C1
      INNER JOIN CONSTLUNA CL ON CL.CODCONST1 = C1.CODCONST1
      INNER JOIN CONSTVAL CV ON CL.ALSTART &lt;= getAnlucru() * 12 + getLunaLucru()  AND CL.ALSTOP &gt;=  getAnlucru() * 12 + getLunaLucru() AND CV.CODCONSTLUNA = CL.CODCONSTLUNA
    where
      upper(c1.simbol) = 'CREGAVANSCONTURI'
      AND CV.VALOARE IS NOT NULL;

    if ContRegAvans &gt; 0 then --  daca constanta este armata sterg avansurile care nu sunt in conatanta
      FOR V_REC IN
        (SELECT
          CODGENERAL,
          CODOBLIGPIF,
          ContAvansConst.VALOARE
         FROM
           TMP_REGPART_LUNA
           LEFT JOIN
           (
           select CV.VALOARE
            from
              const1 C1
              INNER JOIN CONSTLUNA CL ON CL.CODCONST1 = C1.CODCONST1
              INNER JOIN CONSTVAL CV ON CL.ALSTART &lt;= getAnlucru() * 12 + getLunaLucru() AND CL.ALSTOP &gt;= getAnlucru() * 12 + getLunaLucru() AND CV.CODCONSTLUNA = CL.CODCONSTLUNA
         where
              upper(c1.simbol) = 'CREGAVANSCONTURI'
           ) ContAvansConst ON ContAvansConst.VALOARE = (select wme_result from PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(null, SEMNIFICATIE, ICONT, CodIOPart1))::varchar
          WHERE
            SEMNIFICATIE IN (110, 210, 310, 410)
         )
         LOOP
           IF V_REC.valoare is null then
             DELETE FROM TMP_REGPART_LUNA WHERE CODGENERAL = V_REC.CODGENERAL AND CODOBLIGPIF = V_REC.CODOBLIGPIF;
           end if;
         END LOOP;
    end if;

   FOR V_REC IN (SELECT * FROM TMP_REGPART_LUNA ) LOOP
    aPREFIXDOC   := NULL;
    aDATADOC     := NULL;
    aNRDOC       := NULL;
    aSUBUNITATEA := NULL;
    IF V_REC.SEMNIFICATIE IN (100, 110, 120, 140) THEN
      BEGIN
        SELECT PREFIXDOC, DATADOC, NRDOC, SUBUNITATEA
        INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA
        FROM INTRARI I, GENERAL G
        WHERE G.CODGENERAL = V_REC.CODGENERAL AND  CODINTR = G.CODDOC;
      EXCEPTION WHEN OTHERS THEN
        aPREFIXDOC   := NULL;
        aDATADOC     := NULL;
        aNRDOC       := NULL;
        aSUBUNITATEA := NULL;
      END;
    ELSE
      IF V_REC.SEMNIFICATIE IN (130) THEN
        BEGIN
          SELECT 'DVI', I.DATADOC, I.NRDOC, INTR.SUBUNITATEA
            INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA
          FROM DVI I, GENERAL G, INTRARI INTR
          WHERE G.CODGENERAL = V_REC.CODGENERAL AND  CODDVI = G.CODDOC AND  INTR.CODINTR = I.CODINTR;
        EXCEPTION WHEN OTHERS THEN
          aPREFIXDOC   := NULL;
          aDATADOC     := NULL;
          aNRDOC       := NULL;
          aSUBUNITATEA := NULL;
        END;
      ELSE
        IF V_REC.SEMNIFICATIE IN (200, 210, 220, 240) THEN
          BEGIN
            SELECT PREFIXDOC, DATADOC, NRDOC, SUBUNITATEA
              INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA
            FROM IESIRI I, GENERAL G
            WHERE G.CODGENERAL = V_REC.CODGENERAL AND  CODIES = G.CODDOC;
          EXCEPTION WHEN OTHERS THEN
            aPREFIXDOC := NULL;
            aDATADOC   := NULL;
            aNRDOC     := NULL;
          END;
        ELSE
          IF V_REC.SEMNIFICATIE IN (310, 410, 330, 430, 500, 600) THEN
            BEGIN
              SELECT SUBSTR( T1.DOC, 1, 2), T1.DATADOC, T1.NRDOC, T.SUBUNITATEA
                INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA
              FROM TREZOR1 T1, GENERAL G, TREZOR T
              WHERE G.CODGENERAL = V_REC.CODGENERAL AND  CODTREZOR1 = G.CODDOC AND  T.CODTREZOR = T1.CODTREZOR;
            EXCEPTION WHEN OTHERS THEN
              aPREFIXDOC   := NULL;
              aDATADOC     := NULL;
              aNRDOC       := NULL;
              aSUBUNITATEA := NULL;
            END;
          ELSE
            IF V_REC.SEMNIFICATIE IN (1200, 1201) THEN
              BEGIN
                SELECT 'NC', DATADOC, NRDOC, SUBUNITATEA
                  INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA
                FROM NC1 N1, GENERAL G, NC N
                WHERE G.CODGENERAL = V_REC.CODGENERAL AND  CODNC1 = G.CODDOC AND  N1.CODNC = N.CODNC;
              EXCEPTION WHEN OTHERS THEN
                aPREFIXDOC   := NULL;
                aDATADOC     := NULL;
                aNRDOC       := NULL;
                aSUBUNITATEA := NULL;
              END;
            ELSE
              IF  V_REC.SEMNIFICATIE = 1303 THEN
                BEGIN
                  SELECT I.PREFIXDOC, I.DATADOC, I.NRDOC, I.SUBUNITATEA
                    INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA
                  FROM OBLIGPIF O
                    LEFT JOIN GENERAL  G  ON  G.CODGENERAL   = O.CODGENERAL
                    LEFT JOIN OBLIGPIF OA ON  OA.CODOBLIGPIF = O.CODOBLIGASOCIAT
                    LEFT JOIN GENERAL  GA ON  GA.CODGENERAL  = OA.CODGENERAL
                    LEFT JOIN IESIRI   I  ON  I.CODIES       = GA.CODDOC
                  WHERE G.CODGENERAL = V_REC.CODGENERAL;
                EXCEPTION WHEN OTHERS THEN
                  aPREFIXDOC := NULL;
                  aDATADOC   := NULL;
                  aNRDOC     := NULL;
                  END;
              ELSE
                BEGIN
                  SELECT 'PV', DATADOC, NRDOC, SUBUNITATEA
                    INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA
                  FROM COMPENS, GENERAL G
                  WHERE G.CODGENERAL = V_REC.CODGENERAL AND  CODCOMPENS = G.CODDOC;
                EXCEPTION WHEN OTHERS THEN
                  aPREFIXDOC   := NULL;
                  aDATADOC     := NULL;
                  aNRDOC       := NULL;
                  aSUBUNITATEA := NULL;
                END;
              END IF;
            END IF;
          END IF;
        END IF;
      END IF;
    END IF;

    UPDATE TMP_REGPART_LUNA
    SET
      PREFIXDOC   = aPREFIXDOC,
      DATADOC     = aDATADOC,
      NRDOC       = aNRDOC,
      SUBUNITATEA = aSUBUNITATEA
    WHERE CODGENERAL = V_REC.CODGENERAL ;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_sp_gotorecord</obj_name>
  <obj_hashval>8cba89de6916059c2730d04932fc5c72</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REG1CONT         RECORD;
  V_REC              RECORD;
  REG1_IDX_LOCAL     numeric;
  REG1CONT_IDX_LOCAL numeric;
  PARAM_REG_DATA     date;
  PARAM_REG_MONEDA   numeric;
  PARAM_REG_CURS     double precision;
  COUNTIN            numeric := 0;
  COUNTOUT           numeric := 0;
  NR                 numeric := 0;
BEGIN
  --Florin 21.02.2023 - fixat 57309
  --Florin 07.02.2023 - sinc. Oracle
  --Bogdan 17.08.2020
  --Bogdan 22.09.2020
  PERFORM PKG_STOC_GENERARE_FACTURI_MAKE_CONFIG_LUNA();
  DELETE FROM TMP_REG1CONT_MARTOR;
  DELETE FROM TMP_REG1_INITIAL;

  IF  RecID &gt; 0 THEN
    INSERT INTO TMP_REG1_INITIAL (CODGENERAL, SOLDDOCVAL, SOLDDOCREG, CODOBLIGPIF)
    ( SELECT CODGENERAL, SOLDDOCVAL, SOLDDOCREG, CODOBLIGPIF FROM REG1 WHERE CODREG = RECID );
  END IF;

  REG1CONT_IDX_LOCAL := 0;
  FOR V_REG1CONT IN (
      SELECT SUM( SoldDoc)    AS SOLDDOC,
             SUM( SoldDocVal) AS SOLDDOCVAL,
             SUM( SoldDocReg) AS SOLDDOCREG,
             SUM( (SoldDocReg) - (SoldDocVal) ) AS DIFERENTA,
             Cont
      FROM REG1
      WHERE    REG1.CODREG = RECID
      GROUP BY   Cont
  ) LOOP
    REG1CONT_IDX_LOCAL := REG1CONT_IDX_LOCAL + 1;
    INSERT INTO TMP_REG1CONT_MARTOR (CodReg1Cont, SoldDoc, SoldDocVal, SoldDocReg, Diferenta, Cont )
    values (-1 * REG1CONT_IDX_LOCAL, V_REG1CONT.SoldDoc, V_REG1CONT.SoldDocVal, V_REG1CONT.SoldDocReg, V_REG1CONT.Diferenta, V_REG1CONT.Cont);
  END LOOP;

  DELETE FROM TMP_REG;
  INSERT INTO TMP_REG (
          CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs,
          CodSubunit, SimbolMoneda, SimbolBank, Provizion, An, Luna, CODGEST,
          CodAnaliza, CodCentru, CURS_IFRS, CodAnalizaNod )
  ( SELECT R.CodReg, R.TipReg, R.NrDoc, R.DataDoc, R.CodBank, R.CodMoneda, R.Curs,
        R.Dirty, R.Obs, R.CodSubunit, M.Simbol, B.Simbol, R.Provizion, R.An, R.Luna,
        R.CODGEST, R.CodAnaliza, R.CodCentru, R.CURS_IFRS, R.CodAnalizaNod
    FROM REG R
      LEFT JOIN NMONEDE M ON  M.CODMONEDA = R.CODMONEDA
      LEFT JOIN NBANK   B ON  B.CODBANK   = R.CODBANK
    WHERE    R.CodReg = RecID );

  SELECT DataDoc, CodMoneda, Curs
    INTO PARAM_REG_DATA, PARAM_REG_MONEDA, PARAM_REG_CURS
  FROM TMP_REG;

  PERFORM PKG_REG_SetParamsReg( TO_CHAR( PARAM_REG_DATA, 'DD.MM.YYYY'), PARAM_REG_MONEDA, PARAM_REG_CURS::NUMERIC);

  DELETE FROM TMP_REG1;

  REG1_IDX_LOCAL := 0;

  PERFORM PKG_REGPART_MAKE_REGPART_LUNA();

  FOR V_REC IN (SELECT RP.*, P.DEN_PART FROM TMP_REGPART_LUNA RP LEFT JOIN NPART P ON  P.CODPART = RP.CODPART) LOOP
    IF  ABS( V_REC.SoldDoc * current_setting('PKG_REG.CURS_REG')::numeric - V_REC.SoldDocVal) &gt; 0.0000001 THEN
      REG1_IDX_LOCAL := REG1_IDX_LOCAL + 1;
      INSERT INTO TMP_REG1 (
            CodReg1, CodGeneral, Cont, PrefixDoc, NrDoc, DataDoc, CodPart,
            DenPart, SimbolCont, SoldDocVal, SoldDoc, SoldDocReg, Diferenta,
            Document, CodGest, CodCentru, CodAnalizaNod, Semn, Curs,
            Semnificatie, CoefProvizion, SUBUNITATEA, CODOBLIGPIF )
      values (
        -1 * REG1_IDX_LOCAL, V_REC.CodGeneral, V_REC.ICONT, V_REC.PrefixDoc,
        V_REC.NrDoc, V_REC.DataDoc, V_REC.CodPart, V_REC.Den_Part,
        (SELECT WME_RESULT
          FROM PKG_PLANCONTURI_GETSIMBOLCONT(NULL, (SELECT WME_RESULT FROM PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(NULL, V_REC.Semnificatie, V_REC.ICont, V_REC.CodIOPart1)))),
        V_REC.SoldDocVal, V_REC.SoldDoc,
        V_REC.SoldDoc * PARAM_REG_CURS,
        V_REC.SoldDoc * PARAM_REG_CURS - V_REC.SoldDocVal,
        (CASE WHEN  V_REC.Semnificatie = 1303 THEN 'Litigii ' || coalesce(V_REC.PREFIXDOC,'') || coalesce( V_REC.NRDOC::varchar,'') || '/' || coalesce(TO_CHAR( V_REC.DATADOC, 'DD.MM.YYYY'),'')
              ELSE coalesce(V_REC.PREFIXDOC,'') || coalesce( V_REC.NRDOC::varchar,'') || '/' || coalesce(TO_CHAR( V_REC.DATADOC, 'DD.MM.YYYY'),'')
          END ) ,
         V_REC.CodGest, 0, 0, 1, V_REC.Curs, V_REC.Semnificatie, V_REC.CoefProvizion, V_REC.SUBUNITATEA, V_REC.CODOBLIGPIF
      );
    END IF;
  END LOOP;

  FOR V_REC IN (
        SELECT R1.CODREG1, (SELECT wme_result FROM PKG_TREZOR_CODCONTCEC(NULL, O.CONTBANKTRANZACTIE, O.SEMNIFICATIE, T1.TIPDECONT, T1.obiecttranz, GetAnLucru(), GETLunaLUCRU())) CodCont
        FROM TMP_REG1 R1, OBLIGPIF O, GENERAL G, TREZOR1 T1
        WHERE
           R1.CODOBLIGPIF = O.CODOBLIGPIF
           AND O.SEMNIFICATIE IN (500, 600)
           AND  G.CODGENERAL = O.CODGENERAL
           AND  T1.CODTREZOR1 = G.CODDOC
  ) LOOP
    UPDATE TMP_REG1
      SET CONT = V_REC.CODCONT, SIMBOLCONT = PKG_PLANCONTURI_GETSIMBOLCONT(V_REC.CODCONT)
    WHERE CODREG1 = V_REC.CODREG1;
  END LOOP;

  DELETE FROM TMP_REG1CONT;
  REG1CONT_IDX_LOCAL := 0;

  FOR V_REG1CONT IN  (
      SELECT SUM( SoldDoc) AS SOLDDOC,
             SUM( SoldDocVal) AS SOLDDOCVAL,
             SUM( SoldDocReg) AS SOLDDOCREG,
             SUM( (  SoldDocReg)  - (  SoldDocVal) ) AS DIFERENTA,
             Cont
      FROM TMP_REG1
      GROUP BY   Cont
  ) LOOP
    REG1CONT_IDX_LOCAL := REG1CONT_IDX_LOCAL + 1;
    INSERT INTO TMP_REG1CONT (CodReg1Cont, SoldDoc, SoldDocVal, SoldDocReg, Diferenta, Cont )
    values (-1 * REG1CONT_IDX_LOCAL, V_REG1CONT.SoldDoc, V_REG1CONT.SoldDocVal, V_REG1CONT.SoldDocReg, V_REG1CONT.Diferenta, V_REG1CONT.Cont );
  END LOOP;

  INSERT INTO TMP_JURNAL  (SELECT * FROM JURNAL  WHERE TIPDOC = 46 AND  CODDOC = RECID);
  INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = 46 AND  CODDOC = RECID);

  DELETE FROM TMP_RULAJ;

  perform set_config('PKG_REGPART.DIFERENTE',0::varchar,false);

  SELECT COUNT( *) INTO COUNTIN FROM TMP_REG1CONT_MARTOR;

  SELECT COUNT( *) INTO COUNTOUT FROM TMP_REG1CONT;

  IF  COUNTIN &lt;&gt; COUNTOUT THEN
    perform set_config('PKG_REGPART.DIFERENTE',1::varchar,false);
  ELSE
    FOR V_REC IN (
        SELECT INTBL.CONT, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT, INTBL.SOLDDOCREG SOLDREGIN, OUTTBL.SOLDDOCREG SOLDREGOUT
        FROM TMP_REG1CONT_MARTOR INTBL LEFT JOIN TMP_REG1CONT OUTTBL ON  OUTTBL.CONT = INTBL.CONT
        union
        SELECT OUTTBL.CONT, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT, INTBL.SOLDDOCREG SOLDREGIN, OUTTBL.SOLDDOCREG SOLDREGOUT
        FROM TMP_REG1CONT OUTTBL LEFT JOIN TMP_REG1CONT_MARTOR INTBL ON  INTBL.CONT = OUTTBL.CONT
    ) LOOP
      IF    (COALESCE( V_REC.SOLDIN, 0) &lt;&gt; COALESCE( V_REC.SOLDOUT, 0))
         OR (COALESCE( V_REC.SOLDREGIN, 0) &lt;&gt; COALESCE( V_REC.SOLDREGOUT, 0))
      THEN
        perform set_config('PKG_REGPART.DIFERENTE',1::varchar,false);
        EXIT ;
      END IF;
    END LOOP;
  END IF;

  IF  current_setting('PKG_REGPART.DIFERENTE',true)::numeric = 1 THEN
    SELECT COUNT( *) INTO NR FROM TMP_JURNAL1;

    IF  NR = 0 THEN
      INSERT INTO TMP_JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, DIRTY )
      values (NEXTVAL('SEQ_JURNAL1_CODJURNAL1'), RECID, 46, -2, 1 );

      INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, DIRTY, An, Luna, Subunitatea )
      values (NEXTVAL('SEQ_JURNAL1_CODJURNAL1'), RECID, 46, -2, 1,
              (SELECT WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL)), (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL)), 2);

      INSERT INTO JURNAL (CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, ContD, ContC, An, Luna, Subunitatea )
      values (NEXTVAL('SEQ_JURNAL_CODJURNAL'), RECID, 46, -2, 0, 0,
              (SELECT WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL)), (SELECT WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL)), 2);
    ELSE
      FOR V_REC IN (SELECT * FROM TMP_JURNAl1) LOOP
        UPDATE TMP_JURNAL1 set DIRTY = 1 WHERE CODJURNAL1 = V_REC.CODJURNAL1;
        UPDATE JURNAL1     set DIRTY = 1 WHERE CODJURNAL1 = V_REC.CODJURNAL1;
        END LOOP;
    END IF;
  END IF;

  FOR V_REC IN (
      SELECT R1.CODREG1, RI.CODGENERAL AS CODGENERAL_INI, R1.SOLDDOCVAL, RI.SOLDDOCVAL AS SOLDDOCVAL_INI, R1.SOLDDOCREG, RI.SOLDDOCREG AS SOLDDOCREG_INI
      FROM TMP_REG1 R1
        LEFT JOIN TMP_REG1_INITIAL RI ON  RI.CODGENERAL = R1.CODGENERAL AND  COALESCE( R1.CODOBLIGPIF, 0) = COALESCE( RI.CODOBLIGPIF, 0)
  ) LOOP
    IF  COALESCE( V_REC.CODGENERAL_INI, 0) = 0
      OR  COALESCE( V_REC.SOLDDOCVAL, 0) &lt;&gt; COALESCE( V_REC.SOLDDOCVAL_INI, 0)
      OR  COALESCE( V_REC.SOLDDOCREG, 0) &lt;&gt; COALESCE( V_REC.SOLDDOCREG_INI, 0)
    THEN
      UPDATE TMP_REG1 SET MODIFICARI = 1 WHERE CODREG1 = V_REC.CODREG1;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_sp_postrecords</obj_name>
  <obj_hashval>87b6f72a8226a4ec584ab8cdc121864d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  glb_DATANEXTREG date;
  glb_CODNEXTREG  numeric;
  V_REC           RECORD;
  V_REC_SUB       RECORD;
  TMP_NR          numeric;
  NR              numeric;
  cod1            NUMERIC(20);
BEGIN
  --Florin 10.05.2023 - sinc. oracle (09.05.2023)
  --Florin 18.06.2021 - fixat 50575
  --Bogdan 17.08.2020
  glb_CODNEXTREG  := case when current_setting('PKG_REGPART.CODNEXTREG',TRUE) = '' then null
                          else current_setting('PKG_REGPART.CODNEXTREG',TRUE)::numeric end;
  glb_DATANEXTREG := case when current_setting('PKG_REGPART.DATANEXTREG',TRUE) = '' then null
                          else current_setting('PKG_REGPART.DATANEXTREG',TRUE)::date end;
  IF  Operation = 0 THEN
    SELECT CodReg INTO RecID FROM TMP_REG;

    UPDATE REG
      set (TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit,
        Provizion, An, Luna, CODGEST, Codanaliza, CodCentru, CURS_IFRS, CodAnalizaNod) = (
          SELECT TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit,
              Provizion, An, Luna, CODGEST, Codanaliza, CodCentru, CURS_IFRS, CodAnalizaNod
          FROM TMP_REG )
    WHERE CodReg = RecID;

    DELETE FROM REG1 WHERE CodReg = RecID;

    for v_rec in (select * from tmp_reg1) LOOP
      select NEXTVAL('SEQ_REG1_CODREG1') into cod1;
      INSERT INTO REG1 (CodReg1, CodReg, CodGeneral, SoldDocVal, SoldDoc, SoldDocReg, CodGest, CodCentru, CodAnalizaNod, Cont, Semn, Curs, Semnificatie, SUBUNITATEA, CODOBLIGPIF)
      values (cod1, RecID, v_rec.CodGeneral, v_rec.SoldDocVal, v_rec.SoldDoc, v_rec.SoldDocReg, v_rec.CodGest, v_rec.CodCentru, v_rec.CodAnalizaNod, v_rec.Cont, v_rec.Semn, v_rec.Curs, v_rec.Semnificatie, v_rec.SUBUNITATEA, v_rec.CODOBLIGPIF);
      update tmp_jurnal set indexlocal = cod1 where indexlocal = v_rec.codreg1;
      update tmp_jurnal1 set indexlocal = cod1 where indexlocal = v_rec.codreg1;
    END LOOP;

    DELETE FROM JURNAL1
    where  TIPDOC = 46 AND  CODDOC = RECID AND not CODJURNAL1 IN (SELECT CODJURNAL1 FROM TMP_JURNAl1);

    FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
      IF  V_REC.CODJURNAL1 &gt; 0 THEN
        UPDATE JURNAL1 SET
                CODDOC        = V_REC.CODDOC,
                TIPDOC        = V_REC.TIPDOC,
                INDEXLOCAL    = V_REC.INDEXLOCAL,
                CODBAZAD      = V_REC.CODBAZAD,
                ICONTBAZAD    = V_REC.ICONTBAZAD,
                TIPBAZAD      = V_REC.TIPBAZAD,
                CODBAZAC      = V_REC.CODBAZAC,
                ICONTBAZAC    = V_REC.ICONTBAZAC,
                TIPBAZAC      = V_REC.TIPBAZAC,
                CODDESCRD     = V_REC.CODDESCRD,
                ICONTD        = V_REC.ICONTD,
                TIPCONTD      = V_REC.TIPCONTD,
                ANALITICCONTD = V_REC.ANALITICCONTD,
                CODDESCRC     = V_REC.CODDESCRC,
                ICONTC        = V_REC.ICONTC,
                TIPCONTC      = V_REC.TIPCONTC,
                ANALITICCONTC = V_REC.ANALITICCONTC,
                GEST          = V_REC.GEST,
                VALOARE       = V_REC.VALOARE,
                VALOAREV      = V_REC.VALOAREV,
                VALOARE_IFRS  = V_REC.VALOARE_IFRS,
                VALOAREV_IFRS = V_REC.VALOAREV_IFRS,
                OBS           = V_REC.OBS,
                AN            = V_REC.AN,
                LUNA          = V_REC.LUNA,
                DIRTY         = V_REC.DIRTY,
                SUBUNITATEA   = V_REC.SUBUNITATEA,
                CODCENTRU     = V_REC.CODCENTRU,
                DATADOC       = V_REC.DATADOC,
                DOCUMENT      = V_REC.DOCUMENT,
                CODANALIZANOD = V_REC.CODANALIZANOD
        WHERE CODJURNAL1 = V_REC.CODJURNAl1 ;
      ELSE
        INSERT INTO JURNAL1 (
          CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD,
          CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD, CODBAZAC, ICONTBAZAC, TIPBAZAC,
          CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS,
          VALOAREV_IFRS, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, DOCUMENT, CODCENTRU, CODANALIZANOD)
        values (
              NEXTVAL('SEQ_JURNAL1_CODJURNAL1'), RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CODBAZAD,
              V_REC.ICONTBAZAD, V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,
              V_REC.CODBAZAC, V_REC.ICONTBAZAC, V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC,
              V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.VALOARE_IFRS, V_REC.VALOAREV_IFRS,
              V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT,
              V_Rec.CODCENTRU, v_rec.CODANALIZANOD);
      END IF;
    END LOOP;

    DELETE FROM JURNAL where  TIPDOC = 46 AND  CODDOC = RECID AND CODJURNAL NOT IN (SELECT CODJURNAL FROM TMP_JURNAl);

    FOR V_REC IN (SELECT * FROM TMP_JURNAL ) LOOP
      IF  V_REC.CODJURNAL &gt; 0 THEN
        UPDATE JURNAL
          set
          CODDOC        = V_REC.CODDOC,
          TIPDOC        = V_REC.TIPDOC,
          INDEXLOCAL    = V_REC.INDEXLOCAL,
          CONTD         = V_REC.CONTD,
          CONTC         = V_REC.CONTC,
          GEST          = V_REC.GEST,
          VALOARE       = V_REC.VALOARE,
          VALOAREV      = V_REC.VALOAREV,
          VALOARE_IFRS  = V_REC.VALOARE_IFRS,
          VALOAREV_IFRS = V_REC.VALOAREV_IFRS,
          OBS           = V_REC.OBS,
          AN            = V_REC.AN,
          LUNA          = V_REC.LUNA,
          SUBUNITATEA   = V_REC.SUBUNITATEA,
          DATADOC       = V_REC.DATADOC,
          CODCENTRU     = V_REC.CODCENTRU,
          CODANALIZANOD = V_REC.CODANALIZANOD,
          DOCUMENT      = V_REC.DOCUMENT
        WHERE
         CODJURNAL = V_REC.CODJURNAl;
      ELSE
        INSERT INTO JURNAL (CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS,
                            VALOAREV_IFRS, OBS, AN, LUNA, SUBUNITATEA, DATADOC, DOCUMENT, CODCENTRU, CODANALIZANOD)
        values (
            NEXTVAL('SEQ_JURNAL_CODJURNAL'), RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC,
            V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.VALOARE_IFRS, V_REC.VALOAREV_IFRS, V_REC.OBS, V_REC.AN,
            V_REC.LUNA, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT, V_REC.CODCENTRU, V_REC.CODANALIZANOD
        );
      END IF;
    END LOOP;
  ELSE
    SELECT NEXTVAL('SEQ_REG_CODREG') INTO RecID;

    INSERT INTO REG(
        CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs,
        CodSubunit, Provizion, An, Luna, CODGEST, Codanaliza, CURS_IFRS, CODCENTRU, CODANALIZANOD)
    (SELECT RecID, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit,
        Provizion, An, Luna, CODGEST, Codanaliza, CURS_IFRS, CODCENTRU, CODANALIZANOD
    FROM TMP_REG);

    for v_rec in (select * from tmp_reg1) LOOP
      select NEXTVAL('SEQ_REG1_CODREG1') into cod1;
      INSERT INTO REG1 (CodReg1, CodReg, CodGeneral, SoldDocVal, SoldDoc, SoldDocReg, CodGest, CodCentru, CodAnalizaNod, Cont, Semn, Curs, Semnificatie, SUBUNITATEA, CODOBLIGPIF)
      values(cod1, RecID, v_rec.CodGeneral, v_rec.SoldDocVal, v_rec.SoldDoc, v_rec.SoldDocReg, v_rec.CodGest, v_rec.CodCentru, v_rec.CodAnalizaNod, v_rec.Cont, v_rec.Semn, v_rec.Curs, v_rec.Semnificatie, v_rec.SUBUNITATEA, v_rec.CODOBLIGPIF);
      update tmp_jurnal set indexlocal = cod1 where indexlocal = v_rec.codreg1;
      update tmp_jurnal1 set indexlocal = cod1 where indexlocal = v_rec.codreg1;
    END LOOP;

    INSERT INTO JURNAL1(
        CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD,
        ICONTD, TIPCONTD, ANALITICCONTD, CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC,
        TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS,
        AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, CODCENTRU, CODANALIZANOD)
    (SELECT NEXTVAL('SEQ_JURNAL1_CODJURNAL1'), RECID, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD,
        TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD, CODBAZAC, ICONTBAZAC, TIPBAZAC,
        CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS,
        VALOAREV_IFRS, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, CODCENTRU, CODANALIZANOD
    FROM TMP_JURNAL1);

    INSERT INTO JURNAL(
          CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV,
          OBS, AN, LUNA, SUBUNITATEA, DATADOC, CODCENTRU, CODANALIZANOD)
    (SELECT NEXTVAL('SEQ_JURNAL_CODJURNAL'), RECID, TIPDOC, INDEXLOCAL, CONTD,
    CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, DATADOC, CODCENTRU, CODANALIZANOD
    FROM TMP_JURNAL);
  END IF;
--
  IF  RECID &gt; 0 THEN
    perform set_config('PKG_REGPART.DIFERENTE',0::varchar,false);
    FOR V_REC IN (
        SELECT INTBL.CONT, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT, INTBL.SOLDDOCREG SOLDREGIN, OUTTBL.SOLDDOCREG SOLDREGOUT
        FROM TMP_REG1CONT_MARTOR INTBL LEFT JOIN TMP_REG1CONT OUTTBL ON  OUTTBL.CONT = INTBL.CONT
        union
        SELECT OUTTBL.CONT, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT, INTBL.SOLDDOCREG SOLDREGIN, OUTTBL.SOLDDOCREG SOLDREGOUT
        FROM TMP_REG1CONT OUTTBL LEFT JOIN TMP_REG1CONT_MARTOR INTBL ON  INTBL.CONT = OUTTBL.CONT
    )  LOOP
        IF   (COALESCE( V_REC.SOLDIN, 0) &lt;&gt; COALESCE( V_REC.SOLDOUT, 0))
          OR (COALESCE( V_REC.SOLDREGIN, 0) &lt;&gt; COALESCE( V_REC.SOLDREGOUT, 0)) THEN
          perform set_config('PKG_REGPART.DIFERENTE',1::varchar,false);
          EXIT ;
        END IF;
    END LOOP;

    SELECT MIN( DATADOC)
      INTO glb_DATANEXTREG
    FROM REG
    WHERE  TIPREG = 46 AND  DATADOC &gt; (SELECT DATADOC FROM TMP_REG)
            AND  CODMONEDA = (SELECT CODMONEDA FROM TMP_REG);

--    perform set_config('PKG_REGPART.CODNEXTREG',null::VARCHAR,false);
    glb_CODNEXTREG := null;
    IF glb_DATANEXTREG IS NOT NULL THEN
      SELECT CODREG
        INTO glb_CODNEXTREG
      FROM REG
      WHERE
         DATADOC = glb_DATANEXTREG
         AND  TIPREG = 46
         AND  CODMONEDA = (SELECT CODMONEDA FROM TMP_REG);
    END IF;

    FOR V_REC IN (
          SELECT REG.CURS AS CURSREG, GSTINGATOR.CODGENERAL, GSTINGATOR.CURS AS CURSSTINGATOR, T1.CODTREZOR
          FROM REG REG, REG1 REG1, OBLIGPIF OSTINS, STINGERE S, OBLIGPIF OSTINGATOR, GENERAL GSTINGATOR, TREZOR1 T1
          WHERE
             REG.CODREG = RECID
             AND  REG1.CODREG = REG.CODREG
             AND  OSTINS.CODGENERAL = REG1.CODGENERAL
             AND  S.CODSTINSPIF = OSTINS.CODOBLIGPIF
             AND  OSTINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
             AND  GSTINGATOR.CODGENERAL = OSTINGATOR.CODGENERAL
             AND GSTINGATOR.TIPDOC IN (29, 30, 31, 33)
             AND  T1.CODTREZOR1 = GSTINGATOR.CODDOC
             AND  (PKG_REGPART_DATA_DOC_CORECTA(T1.DATADOC, REG.DATADOC, glb_DATANEXTREG)) = 1
             AND  REG.CURS &lt;&gt; GSTINGATOR.CURS
             AND  COALESCE( GSTINGATOR.FaraReg, 0) = 0
    )  LOOP
          UPDATE GENERAL SET CURS = V_REC.CURSREG WHERE CODGENERAL = V_REC.CODGENERAL;
          UPDATE JURNAL1 SET DIRTY = 1 WHERE TIPDOC IN (29, 30, 31, 33) AND  CODDOC = v_rec.codtrezor;
      END LOOP;

    FOR V_REC IN (
          SELECT REG.CURS AS CURSREG, GSTINGATOR.CODGENERAL, GSTINGATOR.CURS AS CURSSTINGATOR, C.CODCOMPENS
          FROM REG REG, REG1 REG1, OBLIGPIF OSTINS, STINGERE S, OBLIGPIF OSTINGATOR, GENERAL GSTINGATOR, COMPENS C
          WHERE
             REG.CODREG = RECID
             AND  REG1.CODREG = REG.CODREG
             AND  OSTINS.CODGENERAL = REG1.CODGENERAL
             AND  S.CODSTINSPIF = OSTINS.CODOBLIGPIF
             AND  OSTINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
             AND  GSTINGATOR.CODGENERAL = OSTINGATOR.CODGENERAL
             AND  GSTINGATOR.TIPDOC = 28
             AND  C.CODCOMPENS = GSTINGATOR.CODDOC
             AND  (PKG_REGPART_DATA_DOC_CORECTA(C.DATADOC, REG.DATADOC, glb_DATANEXTREG)) = 1
            AND  COALESCE( GSTINGATOR.FaraReg, 0) = 0
    ) LOOP
        UPDATE JURNAL1 set DIRTY = 1 WHERE TIPDOC = 28 AND  CODDOC = V_REC.CODCOMPENS;
    END LOOP;

    IF  current_setting('PKG_REGPART.DIFERENTE',TRUE)::NUMERIC = 1 THEN

      IF glb_CODNEXTREG IS NOT NULL THEN
          UPDATE JURNAL1 set DIRTY = 1 where  TIPDOC = 46 AND  CODDOC = glb_CODNEXTREG;

          UPDATE REG1 R1
          set CURS = (SELECT CURS FROM TMP_REG)
          WHERE
             CODREG = glb_CODNEXTREG
             AND  EXISTS ( SELECT CODGENERAL FROM TMP_REG1 WHERE CODGENERAL = R1.CODGENERAL);
      END IF;
    END IF;
  END IF;

  FOR V_REC in (
    SELECT I.CODIES AS CODFACTAVIZ
    FROM IESIRI I, IESIRI1 I1, IESLINK IL, IESIRI1 I1Aviz, GENERAL GAviz
    WHERE
       I.TIPDOC = 26
       AND  I1.CODIES = I.CODIES
       AND  IL.CODIES1 = I1.CODIES1
       AND  IL.CODLINIEAVIZ = I1Aviz.Codies1
       AND  I1Aviz.Codies = GAviz.Coddoc
       AND  GAviz.Semnificatie = 240
       AND  GAviz.TIPDOC = 20
       AND  EXISTS ( SELECT CODGENERAL FROM REG1 R1 WHERE R1.CODGENERAL = GAviz.Codgeneral AND  R1.CODREG = RECID)
  ) LOOP
    UPDATE JURNAL1 set DIRTY = 1 WHERE TIPDOC = 26 AND  CODDOC = V_REC.CODFACTAVIZ;
  END LOOP;

  FOR V_REC IN (
    SELECT I.CODIES AS CODFACTAVIZ
    FROM IESIRI I, IESIRI1 I1, IESLINK IL, IESIRI1 I1Aviz, GENERAL GAviz
    WHERE
       I.TIPDOC = 9
       AND  I1.CODIES = I.CODIES
       AND  IL.CODIES1 = I1.CODIES1
       AND  IL.CODLINIEAVIZ = I1Aviz.Codies1
       AND  I1Aviz.Codies = GAviz.Coddoc
       AND  GAviz.Semnificatie = 140
       AND  GAviz.TIPDOC = 2
       AND  EXISTS (SELECT CODGENERAL FROM REG1 R1 WHERE R1.CODGENERAL = GAviz.Codgeneral AND  R1.CODREG = RECID)
  ) LOOP
    UPDATE JURNAL1 set  DIRTY = 1 WHERE TIPDOC = 9 AND  CODDOC = V_REC.CODFACTAVIZ;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP
    SELECT COUNT( *)
    INTO TMP_NR
    FROM NCONTRUL
    WHERE
       CODCONT = V_REC.CODCONT
       AND  AN = current_setting('PKG_GLOBALS.ANLUCRU',true)::numeric
       AND  LUNA = current_setting('PKG_GLOBALS.LUNALUCRU',true)::numeric;

    IF  TMP_NR = 0  THEN
      INSERT INTO NCONTRUL (CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA )
      values (
        NEXTVAL('SEQ_NCONTRUL_CODCONTRUL'),
        V_REC.CODCONT, 0, 0, 0, 0, 0, 0, 0, 0,
        current_setting('PKG_GLOBALS.ANLUCRU',true)::numeric,
        current_setting('PKG_GLOBALS.LUNALUCRU',true)::numeric);
    END IF;

    UPDATE NCONTRUL SET
      RULAJCD      = RULAJCD      + (CASE  WHEN  V_REC.TIP = 'D' THEN V_REC.VALOARE  ELSE 0 END ) ,
      RULAJCC      = RULAJCC      + (CASE  WHEN  V_REC.TIP = 'C' THEN V_REC.VALOARE  ELSE 0 END ) ,
      RULAJVCD     = RULAJVCD     + (CASE  WHEN  V_REC.TIP = 'D' THEN V_REC.VALOAREV ELSE 0 END ) ,
      RULAJVCC     = RULAJVCC     + (CASE  WHEN  V_REC.TIP = 'C' THEN V_REC.VALOAREV ELSE 0 END ) ,
      RULAJC_IFRS  = RULAJC_IFRS  + V_REC.VALOARE_IFRS,
      RULAJVC_IFRS = RULAJVC_IFRS + V_REC.VALOAREV_IFRS
    WHERE
       CODCONT = V_REC.CODCONT
       AND  AN = current_setting('PKG_GLOBALS.ANLUCRU',true)::numeric
       AND  LUNA = current_setting('PKG_GLOBALS.LUNALUCRU',true)::numeric;

    IF  COALESCE( V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
      FOR V_REC_SUB IN (
                SELECT *
                FROM NCONTRUL
                WHERE
                   CODCONT = V_REC.CODCONT
                   AND  AN = current_setting('PKG_GLOBALS.ANLUCRU',true)::numeric
                   AND  LUNA = current_setting('PKG_GLOBALS.LUNALUCRU',true)::numeric
      ) LOOP
          SELECT COUNT( *) INTO NR
          FROM NCONTRULSUB
          WHERE
             CODCONTRUL = V_REC_SUB.CODCONTRUL AND  SUBUNITATEA = V_REC.SUBUNITATEA;

          IF  NR = 0  THEN
            INSERT INTO NCONTRULSUB (CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA
            ) values (NEXTVAL('SEQ_NCONTRULSUB_CODRULSUB'), V_REC_SUB.CODCONTRUL, 0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
          END IF;

          UPDATE NCONTRULSUB SET
              RULAJCD      = RULAJCD     + (CASE WHEN  V_REC.TIP = 'D' THEN V_REC.VALOARE  ELSE 0  END ) ,
              RULAJCC      = RULAJCC     + (CASE WHEN  V_REC.TIP = 'C' THEN V_REC.VALOARE  ELSE 0  END ) ,
              RULAJVCD     = RULAJVCD    + (CASE WHEN  V_REC.TIP = 'D' THEN V_REC.VALOAREV ELSE 0 END ) ,
              RULAJVCC     = RULAJVCC    + (CASE WHEN  V_REC.TIP = 'C' THEN V_REC.VALOAREV ELSE 0 END ) ,
              RULAJC_IFRS  = RULAJC_IFRS + V_REC.VALOARE_IFRS,  RULAJVC_IFRS = RULAJVC_IFRS + V_REC.VALOAREV_IFRS
          WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND  SUBUNITATEA = V_REC.SUBUNITATEA ;
      END LOOP;
    END IF;
  END LOOP;

  PERFORM PKG_GLOBALS_MarkDirtyJurnal();
--  PERFORM NotifyModif( Operation, RecId, 'REG');
--  --&lt;sstunknown&gt;
  perform PKG_REGPART_SetDATANEXTREG(glb_DATANEXTREG);
  perform PKG_REGPART_SetCODNEXTREG(glb_CODNEXTREG);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpers_sp_gotorecord</obj_name>
  <obj_hashval>981b10c1b23976ace0e469bb4a3e6d77</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpers_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  V_REC             RECORD;
  PARAM_REG_DATA    date;
  PARAM_REG_MONEDA  numeric;
  PARAM_REG_CURS    numeric;
  LunaPrecedentaReg numeric;
  AnPrecedentReg    numeric;
  DIFERENTE         numeric := 0;
  aSEMN             numeric := 1;
  aTIPCONT          numeric := 0;
begin
  perform PKG_STOC_GENERARE_FACTURI_MAKE_CONFIG_LUNA();

  DELETE FROM TMP_REG;

  INSERT INTO TMP_REG ( CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, SimbolMoneda, SimbolBank, Provizion, Luna, An, CodAnaliza, CodCentru, CodAnalizaNod )
  (
  SELECT R.CodReg, R.TipReg, R.NrDoc, R.DataDoc, R.CodBank, R.CodMoneda, R.Curs, R.Dirty, R.Obs, R.CodSubunit, M.Simbol, B.Simbol, R.Provizion, R.Luna, R.An, CodAnaliza, CodCentru, CodAnalizaNod
  FROM REG R
    left join NMONEDE M ON M.CODMONEDA = R.CODMONEDA
    left join NBANK   B ON B.CODBANK   = R.CODBANK
  WHERE R.CodReg = RecID
  );


  SELECT DataDoc, CodMoneda, Curs INTO PARAM_REG_DATA, PARAM_REG_MONEDA, PARAM_REG_CURS FROM TMP_REG;

  perform PKG_REG_SetParamsReg(TO_CHAR(PARAM_REG_DATA, 'DD.MM.YYYY'), PARAM_REG_MONEDA, PARAM_REG_CURS);
  perform set_config('PKG_REGPERS.CURS_IN',(PARAM_REG_CURS)::varchar, false);
  perform PKG_GLOBALS_SETLUNATEMP(current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric, current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric);

  select NEWAN, NEWLUNA into AnPrecedentReg, LunaPrecedentaReg FROM  PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA(current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric, current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric, AnPrecedentReg, LunaPrecedentaReg);

  perform PKG_GLOBALS_SETLUNAPRECEDENTA(AnPrecedentReg, LunaPrecedentaReg);

  DELETE FROM TMP_REGPERS1_MARTOR;

  INSERT INTO TMP_REGPERS1_MARTOR ( CODPERS, ICONT, SOLDDOCVAL )
  SELECT CODPERS, ICONT, SUM(SOLDDOCVAL) FROM REGPERS1 WHERE CODREG = RECID group BY CODPERS, ICONT;

  DELETE FROM TMP_REGPERS1;
  DELETE FROM TMP_SOLDPERS_SUB;

  INSERT INTO TMP_SOLDPERS_SUB ( CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA )
  SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
  FROM V_SOLDPERS_TRANZACTII_SUB
  WHERE CODMONEDA = current_setting('PKG_REG.moneda_reg', true)::numeric;

  for V_REC in (SELECT * FROM TMP_SOLDPERS_SUB S ) loop
    begin
      SELECT coalesce(TIPCONT, 0) INTO ATIPCONT
      FROM NCONT
      WHERE CODCONT = (SELECT PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG.WME_RESULT
                       FROM PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(null, 1100, V_REC.ICONT, (SELECT PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA.WME_RESULT
                                                                                          FROM PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA(null, V_REC.CODPERS, current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric, current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric)))
                      );
    exception
      when others then aTIPCONT := 0;
    end;

    if coalesce(aTIPCONT, 0) = 1 then aSEMN := -1; else aSEMN := 1; end if;

    UPDATE TMP_SOLDPERS_SUB
    set
      SEMN = aSEMN
    where
      CODPERS = V_REC.CODPERS and CODMONEDA = V_REC.CODMONEDA and ICONT = V_REC.ICONT ;
  end loop;

  INSERT INTO TMP_REGPERS1 ( CodRegPers1, SoldDoc, SoldDocVal, SoldDocReg, CodPers, CodCont, ICONT, SUBUNITATEA, Diferenta, Den_Pers, Den_Cont )
  select
    -1 * row_number() over(),
    SOLDVALUTA,
    SOLDLEI,
    SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(null, null)),
    CodPers,
    CodCont,
    ICONT,
    SUBUNITATEA,
    SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(null, null)) - SoldLei,
    coalesce(Prenume, '') || ' ' || coalesce(Nume, ''),
    Den_Cont
  from
    (SELECT T1.CODPERS, SOLDVALUTA, SOLDLEI, NUME, PRENUME, ICONT, SUBUNITATEA,
            (SELECT PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT
             FROM PKG_PLANCONTURI_GETSIMBOLCONT(null, (SELECT PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG.WME_RESULT
                                                       FROM PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(null, 1100, ICONT, (SELECT PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA.WME_RESULT
                                                                                                                    FROM PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA(null, T1.CODPERS, current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric, current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric)))))
            ) as DEN_CONT,
            (SELECT PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG.WME_RESULT
             FROM PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(null, 1100, ICONT,
                                                       (SELECT PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA.WME_RESULT
                                                        FROM PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA(null, T1.CODPERS, current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric, current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric)))
            ) as CODCONT
     FROM (SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SUM(SOLDLEI) SOLDLEI, SUM(SOLDVALUTA) SOLDVALUTA
           FROM (SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, coalesce(SOLDLEI, 0) * coalesce(SEMN, 1) SOLDLEI, coalesce(SOLDVALUTA, 0) * coalesce(SEMN, 1) SOLDVALUTA
                 FROM TMP_SOLDPERS_SUB
                  union all
                 SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
                 FROM V_SOLDPERS_PREC_SUB WHERE CODMONEDA = current_setting('PKG_REG.moneda_reg', true)::numeric ) A_PG
           group BY CODPERS, ICONT, CODMONEDA, SUBUNITATEA
          ) T1, NPERS NP
     WHERE NP.CodPers = T1.CodPers
      and CODMONEDA = (SELECT PKG_REG_GetMonedaReg.WME_RESULT FROM PKG_REG_GetMonedaReg(null, null))
      and T1.SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(null, null)) - T1.SoldLei &lt;&gt; 0
    ) B_PG;


  INSERT INTO TMP_JURNAL  (SELECT * FROM JURNAL  WHERE TIPDOC = 47 and CODDOC = RECID );
  INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = 47 and CODDOC = RECID );

  DELETE FROM TMP_RULAJ;

  for V_REC in (SELECT INTBL.CODPERS, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT
                FROM TMP_REGPERS1_MARTOR INTBL
                    left join (SELECT CODPERS, ICONT, SUM(SOLDDOCVAL) as SOLDDOCVAL FROM TMP_REGPERS1 group BY CODPERS, ICONT
                              ) OUTTBL ON OUTTBL.CODPERS = INTBL.CODPERS and OUTTBL.ICONT = INTBL.ICONT
                union
                SELECT OUTTBL.CODPERS, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT
                FROM (SELECT CODPERS, ICONT, SUM(SOLDDOCVAL) as SOLDDOCVAL FROM TMP_REGPERS1 group BY CODPERS, ICONT) OUTTBL
                    left join TMP_REGPERS1_MARTOR INTBL ON INTBL.CODPERS = OUTTBL.CODPERS and INTBL.ICONT = OUTTBL.ICONT
               )
  loop
    if coalesce(V_REC.SOLDIN, 0) &lt;&gt; coalesce(V_REC.SOLDOUT, 0) then
      DIFERENTE := 1;
      exit ;
    end if;
  end loop;

  if DIFERENTE = 1 then
    for V_REC in (SELECT * FROM TMP_JURNAL1 ) loop
      UPDATE TMP_JURNAL1 SET DIRTY = 1 WHERE CODJURNAL1 = V_REC.CODJURNAL1 ;
      UPDATE JURNAL1     SET DIRTY = 1 WHERE CODJURNAL1 = V_REC.CODJURNAL1 ;
    end loop;
  end if;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpers_sp_insertrecord</obj_name>
  <obj_hashval>1eb6d58d958eb313753e0e4ae42c0eff</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpers_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_REGPERS1_MARTOR;
  DELETE FROM TMP_REG;

  INSERT INTO TMP_REG(CodReg, DataDoc)
  VALUES(0, LAST_DAY(TO_DATE('01.' || coalesce((current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric)::varchar,'') || '.' || coalesce((current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric)::varchar,''), 'DD.MM.YYYY')));
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restobiecte_sp_insertrecord</obj_name>
  <obj_hashval>1d415df8465c6c931c2643346653d77b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restobiecte_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_RESTOBIECT (COD) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rezervari_get_tmp_manevra_liniicomenzi</obj_name>
  <obj_hashval>d6e5cdd7570af68e7451300fbbb1a90e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rezervari_get_tmp_manevra_liniicomenzi(acodcomanda numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_MANEVRA_LINIICOMENZI;
  INSERT INTO TMP_MANEVRA_LINIICOMENZI(CodComanda1, Cant)
  (SELECT CodComanda1, CantAcceptat FROM Comanda1 WHERE codcomanda = aCodComanda and  cuLansare = 1 and  COALESCE( CodProiect, 0) &gt; 0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rezervari_get_tmp_rezuri</obj_name>
  <obj_hashval>0a41d7ec04bd059e8d57db31cf9f5a4d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rezervari_get_tmp_rezuri()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_REZERVARI_GET_TMP_REZ_CCOM1();
  PERFORM PKG_REZERVARI_GET_TMP_REZ_REZ();
  PERFORM PKG_REZERVARI_GET_TMP_REZ_PROIECTNOD();
  PERFORM PKG_REZERVARI_GET_TMP_REZ_STOC( 0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_ropharma_get_subunitate_dest</obj_name>
  <obj_hashval>b200ac1f3821fa26fe898f2113e39f6a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_ropharma_get_subunitate_dest(INOUT wme_result numeric, INOUT acodsubunit numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCOD numeric := 2;
begin
  WME_Result :=  aCOD;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_do_blocheaza_durata_mifix</obj_name>
  <obj_hashval>4d88ac4c6a167cb0125907ffc62c7bb3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_do_blocheaza_durata_mifix()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  UPDATE MIFIX1
  SET
  DFBLOCAT   = 1,
  DFBLOCAT_F = 1,
  DFBLOCAT_G = 1,
  AMOBLOCAT  = 1
  WHERE ANSTART * 12 + LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_do_curata_constante</obj_name>
  <obj_hashval>d4cb3f1486da99a46768990c741e6b5e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_do_curata_constante()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC_CONSTLUNA RECORD;
  V_REC           RECORD;
  ARE_DESCRIERE_ANTERIOARA numeric := 0;
  ARE_DECRIERE_PRIMA_LUNA  numeric := 0;
begin
  FOR V_REC_CONSTLUNA IN (SELECT * FROM CONSTLUNA WHERE USERID IS NULL) LOOP
    DELETE FROM CONSTVAL    WHERE CODCONSTLUNA = V_REC_CONSTLUNA.CODCONSTLUNA;
    DELETE FROM CONSTVALPOS WHERE CODCONSTLUNA = V_REC_CONSTLUNA.CODCONSTLUNA;
    DELETE FROM CONSTLUNA   WHERE CODCONSTLUNA = V_REC_CONSTLUNA.CODCONSTLUNA;
  END LOOP;

  FOR V_REC IN (SELECT codconst1, userid FROM constluna ORDER BY codconst1) LOOP
    SELECT COALESCE( MAX( ANSTART * 12 + LUNASTART), 0)
    INTO ARE_DESCRIERE_ANTERIOARA
    FROM CONSTLUNA
    WHERE CODCONST1 = V_REC.CODCONST1 AND  USERID = V_REC.USERID AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

    SELECT COUNT( *)
    INTO ARE_DECRIERE_PRIMA_LUNA
    FROM CONSTLUNA
    WHERE CODCONST1 = V_REC.CODCONST1 AND  USERID = V_REC.USERID AND  ANSTART * 12 + LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

    IF  ARE_DESCRIERE_ANTERIOARA + ARE_DECRIERE_PRIMA_LUNA &gt; 0 THEN
      IF  ARE_DECRIERE_PRIMA_LUNA = 0 THEN
        UPDATE CONSTLUNA
        SET
        ANSTART   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE'  , true)),'999999999999999999'),
        LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
        WHERE
         CODCONST1 = V_REC.CODCONST1 AND  USERID = V_REC.USERID AND  ANSTART * 12 + LUNASTART = ARE_DESCRIERE_ANTERIOARA;
      END IF;

      FOR V_REC_CONSTLUNA IN (SELECT * FROM CONSTLUNA
                              WHERE CODCONST1 = V_REC.CODCONST1 AND  USERID = V_REC.USERID AND  ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
                             )
      LOOP
        DELETE FROM CONSTVAL    WHERE CODCONSTLUNA = V_REC_CONSTLUNA.CODCONSTLUNA;
        DELETE FROM CONSTVALPOS WHERE CODCONSTLUNA = V_REC_CONSTLUNA.CODCONSTLUNA;
        DELETE FROM CONSTLUNA   WHERE CODCONSTLUNA = V_REC_CONSTLUNA.CODCONSTLUNA;
      END LOOP;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_do_fixari_luni</obj_name>
  <obj_hashval>c332cadb3a62d0e4f134d8daff3800cf</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_do_fixari_luni()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  ANTMP   numeric;
  LUNATMP numeric;
  ANP     numeric;
  LUNAP   numeric;
begin
  BEGIN
    SELECT ANINITIAL, LUNAINITIALA INTO ANTMP, LUNATMP FROM FIRMALUNI;
  EXCEPTION WHEN OTHERS THEN
    ANTMP   := 0;
    LUNATMP := 0;
  END;

  PERFORM PKG_RUPERE_FIRMA_REPARA_INCOERENTA_ICONTURI();
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_get_an_rupere</obj_name>
  <obj_hashval>e087054048cdfddff27fc6f4bfb7995d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_get_an_rupere(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
WME_Result :=  TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999');
RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_get_luna_rupere</obj_name>
  <obj_hashval>e320e4bec0075c067f90eb2713d01d93</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_get_luna_rupere(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
WME_Result :=  TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_getcodfacturalitigiu</obj_name>
  <obj_hashval>aa629a2cb9de236717e758828604f3b6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_getcodfacturalitigiu(INOUT wme_result numeric, INOUT acodobligasociat numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  RES  numeric;
  K    numeric := 0;
  CO   numeric;
  TEMP numeric;
begin
  CO := aCODOBLIGASOCIAT;
  k  := 0;

  WME_Result :=  RES;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_reset_seq</obj_name>
  <obj_hashval>b47957a1d70cd252452fae5f743f2ea2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_reset_seq()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vValSeq numeric;
  vCNT    NUMERIC(5);
BEGIN
  --Florin 12.05.2025 - sinc. OrACLE
  --Stef 22.11.2023
  PERFORM pkg_saft_UPDATE_SAFT_RESET_SEQ();
  SELECT Count(1) INTO vCNT FROM SAFT_RESET_SEQ;
  IF vCNT &lt;= 1 THEN
    vValSeq := setval('SEQ_SAFT', 100);
    vValSeq := setval('SEQ_SAFT_TI', 100);
  END IF;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t32</obj_name>
  <obj_hashval>33b7f64dbc30b07e711b80ba5fcf116f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t32()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 04.02.2025 - sinc. Oracle
  PERFORM pkg_saft_PUT_INFO('32.A','UMPLE_T32--SAF_TAXINFORMATION');
  INSERT INTO TMP_SAFT32
  SELECT
    NEXTVAL('SEQ_SAFT')       COL01,--CODSAF_TAXINFORMATION  NUMBER(20)
    S29.COL01                 COL02,--CODSAF_MASTER          NUMBER(20)
    Coalesce(
      TI.TAXTYPE,
      TID.TAXTYPE,
      TIP.TAXTYPE,
      TI5.TAXTYPE,
      TIT.TAXTYPE,
      TI14.TAXTYPE,
      TI35.TAXTYPE,
      '000'
    )                         COL03,--TAXTYPE                NVARCHAR2(9)
    Coalesce(
      TI.TAXCODE,
      TID.TAXCODE,
      TIP.TAXCODE,
      TI5.TAXCODE,
      TIT.TAXCODE,
      TI14.TAXCODE,
      TI35.TAXCODE,
      '000000'
    )                         COL04,--TAXCODE                NVARCHAR2(9)
    Coalesce(
      CASE
        WHEN J.TIPDOC = 14 AND CC.CodSAFT IN ('4427') THEN 0
        WHEN J.TIPDOC = 35 AND CC.CodSAFT IN ('4426') THEN 0
        WHEN Coalesce(IES.TIPTVA, 0)    = 10          THEN 0
        WHEN S29.COL04 IN ('4426', '4427', '4428')    THEN 0
      END,
      TI.TAXPERCENTAGE
    )                         COL05,--TAXPERCENTAGE          NUMBER(22,4)
    COALESCE(
      CASE
        WHEN J.TIPDOC = 14 AND CC.CodSAFT IN ('4427') THEN 0
        WHEN J.TIPDOC = 35 AND CC.CodSAFT IN ('4426') THEN 0
        WHEN Coalesce(IES.TIPTVA, 0)    = 10          THEN 0
        WHEN S29.COL04 IN ('4426', '4427', '4428')    THEN 0
      END,
      MTI.TAXBASE,
      TI.CHEIE_BAZATVAMARJA,
      TI.TAXBASE
    )                         COL06,--TAXBASE                NUMBER(22,4)
    Coalesce(
      TI.TAXBASEDESCRIPTION,
      TID.TAXBASEDESCRIPTION,
      TIP.TAXBASEDESCRIPTION,
      TI5.TAXBASEDESCRIPTION,
      TIT.TAXBASEDESCRIPTION,
      TI14.TAXBASEDESCRIPTION,
      TI35.TAXBASEDESCRIPTION
    )                         COL07,--TAXBASEDESCRIPTION     NVARCHAR2(70)
    Coalesce(C31b.CODSAF, 99) COL08,--CODTAXAMOUNTSAF_AMOUNT NUMBER(20)
    TI.TAXEXEMPTIONREASON     COL09,--TAXEXEMPTIONREASON     NVARCHAR2(70)
    TI.TAXDECLARATIONPERIOD   COL10 --TAXDECLARATIONPERIOD   NVARCHAR2(35)
  FROM TMP_SAFT29 S29
    LEFT JOIN TMP_SAFT_CODSAF     C31a ON C31a.CODSAF = Coalesce(S29.COL11, S29.COL12)
    LEFT JOIN TMP_SAFT_JURNAL     J    ON J.CODJURNAL = C31a.CODSURSA
    LEFT JOIN TMP_SAFT_NCONT      CD   ON CD.CODCONT  = J.CONTD
    LEFT JOIN TMP_SAFT_NCONT      CC   ON CC.CODCONT  = J.CONTC
    LEFT JOIN TMP_SAFT_CC4426     TSC  ON TSC.CodCont = J.CONTC
    LEFT JOIN TMP_SAFT_TAXINFO    TI   ON TI.TIPDOC   = J.TIPDOC
                                      AND CASE
                                            WHEN J.TIPDOC = 29 THEN J.INDEXLOCAL
                                            WHEN J.TIPDOC = 81 THEN J.CODJURNAL
                                            ELSE                    J.CODDOC
                                          END = TI.CODDOC
                                      AND CASE
                                            WHEN J.TIPDOC = 81 AND J.CODDOC = 1 AND C31a.CodSAFTTab = 3101 THEN TI.CODCONT
                                            WHEN J.TIPDOC = 81 AND J.CODDOC = 2 AND C31a.CodSAFTTab = 3102 THEN TI.CODCONT
                                            WHEN                                    C31a.CodSAFTTab = 3101 THEN J.CONTD
                                            ELSE                                                                J.CONTC
                                          END = Coalesce(TI.CODCONTDED, TI.CODCONT)
                                      -- urmatoarele linii sunt pentru cazul TvaDeductibil care se duce pe credit 4426
                                      -- mai putin cazul tipdoc = 32 Nota de inchidere TVA - ca se strica ticketul 54924
                                      AND CASE WHEN J.TIPDOC = 32 THEN 0 WHEN TI.CODCONTDED IS NULL THEN 0                        ELSE TI.CODCONTDED END =
                                          CASE WHEN J.TIPDOC = 32 THEN 0 WHEN TI.CODCONTDED IS NULL THEN 0                        ELSE J.CONTC       END
                                      AND CASE WHEN J.TIPDOC = 32 THEN 0 WHEN TI.CODCONTDED IS NULL THEN 0                        ELSE TI.CODCONT    END =
                                          CASE WHEN J.TIPDOC = 32 THEN 0 WHEN TI.CODCONTDED IS NULL THEN 0                        ELSE J.CONTD       END
                                      AND CASE WHEN J.TIPDOC = 32 THEN 0 WHEN TI.CODCONTDED IS NULL THEN J.CONTC                  ELSE 0             END &lt;&gt;
                                          CASE WHEN J.TIPDOC = 32 THEN 1 WHEN TI.CODCONTDED IS NULL THEN Coalesce(TSC.CodCont, 0) ELSE 1             END
                                      AND J.EXCL_TAXINFO = 0
    LEFT JOIN (
      SELECT DISTINCT TIPDOC, CODDOC, CHEIE_CODCONTDED, CHEIE_CODCONTCOL, TAXTYPE, TAXCODE, TAXBASEDESCRIPTION
      FROM TMP_SAFT_TAXINFO
    )                             TID  ON TID.TIPDOC   = J.TIPDOC AND TID.CODDOC  = J.CODDOC AND TID.CHEIE_CODCONTDED = J.CONTD AND TID.CHEIE_CODCONTCOL = J.CONTC
    LEFT JOIN (
      SELECT DISTINCT TIPDOC, CODDOC, CHEIE_CODCONTDED, CHEIE_CODCONTCOL, TAXTYPE, TAXCODE, TAXBASEDESCRIPTION
      FROM TMP_SAFT_TAXINFO
    )                             TIP  ON TIP.TIPDOC   = J.TIPDOC AND TIP.CODDOC  = J.CODDOC AND TIP.CHEIE_CODCONTCOL = J.CONTC AND S29.COL04 IN ('4426')
    LEFT JOIN (
      SELECT DISTINCT TIPDOC, CODDOC, CODCONTDED, TAXTYPE, TAXCODE, TAXBASEDESCRIPTION
      FROM TMP_SAFT_TAXINFO
      WHERE TIPDOC = 5
    )                             TI5  ON TI5.TIPDOC   = J.TIPDOC AND TI5.CODDOC  = J.CODDOC AND TI5.CODCONTDED       = J.CONTD
    LEFT JOIN (
      SELECT DISTINCT TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXBASEDESCRIPTION
      FROM TMP_SAFT_TAXINFO
      WHERE TIPDOC = 14
    )                             TI14 ON TI14.TIPDOC  = J.TIPDOC AND TI14.CODDOC = J.CODDOC AND TI14.CODCONT         = J.CONTD AND CC.CodSAFT IN ('4427')
    LEFT JOIN (
      SELECT DISTINCT TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXBASEDESCRIPTION
      FROM TMP_SAFT_TAXINFO
      WHERE TIPDOC = 35
    )                             TI35 ON TI35.TIPDOC  = J.TIPDOC AND TI35.CODDOC = J.CODDOC AND TI35.CODCONT         = J.CONTD AND CC.CodSAFT IN ('4426')
    LEFT JOIN INTRARI             INTT ON INTT.CODINTR = J.INDEXLOCAL AND J.TIPDOC = 81 AND J.CODDOC = 1 AND TI.TAXTYPE IS NULL
    LEFT JOIN IESIRI              IEST ON IEST.CODIES  = J.INDEXLOCAL AND J.TIPDOC = 81 AND J.CODDOC = 2 AND TI.TAXTYPE IS NULL
    LEFT JOIN (
      SELECT DISTINCT TIPDOC, CODDOC, TAXTYPE, TAXCODE, TAXBASEDESCRIPTION
      FROM TMP_SAFT_TAXINFO
      WHERE TAXBASE &lt;&gt; 0
    )                             TIT  ON TIT.TIPDOC   = Coalesce(INTT.TIPDOC, IEST.TIPDOC) AND TIT.CODDOC   = J.INDEXLOCAL
    LEFT JOIN IESIRI              IES  ON IES.CODIES   = J.INDEXLOCAL AND IES.TIPDOC = J.TIPDOC
    LEFT JOIN TMP_SAFT_TAXINFO_MP MTI  ON MTI.CODTI    = TI.CODTI AND MTI.CODCONT = J.CONTD
    LEFT JOIN TMP_SAFT_CODSAF     C31b ON C31b.CodSAFTTab IN (3103, 3104) AND C31b.CodSursa  = C31a.CodSursa AND C31b.CodParinte = C31a.CODSAF AND C31b.CODAUX = TI.CODTI
                                      AND Coalesce(MTI.IDXLOCAL, 0) = Coalesce(C31b.IDXAUX, 0);
  PERFORM pkg_saft_PUT_INFO('32.Z','UMPLE_T32--SAF_TAXINFORMATION');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t33</obj_name>
  <obj_hashval>14d2f0510206c8366ead4ea541f1c1ca</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t33()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 25.05.2023 - corectii
  --Stef  25.05.2023
  INSERT INTO TMP_SAFT33
  SELECT
    33   COL01,--CODSAF_SALESINVOICES NUMBER(20)
    NULL COL02,--NUMBEROFENTRIES      NUMBER(20)
    NULL COL03,--TOTALDEBIT           NUMBER(18,2)
    NULL COL04,--TOTALCREDIT          NUMBER(18,2)
    NULL COL05; --DETSAF_INVOICE       NUMBER(20)
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_update_saft_reset_seq</obj_name>
  <obj_hashval>248ab0c0902451aeae64656eb982acda</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_update_saft_reset_seq()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 12.05.2025 - sinc. OrACLE
    DELETE FROM SAFT_RESET_SEQ WHERE CURRENT_TIMESTAMP - APEL_TIMESTAMP &gt; INTERVAL '2' HOUR;
    INSERT INTO SAFT_RESET_SEQ VALUES (CURRENT_TIMESTAMP);
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_catret_setct_monitor</obj_name>
  <obj_hashval>b1b6139436391f523b26c0d54202625b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_catret_setct_monitor(act_monitor character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 05.04.2022
  perform set_config('PKG_SAL_catret.CT_MONITOR',aCT_MONITOR,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_catspor_sp_gotorecord</obj_name>
  <obj_hashval>325dd4a50c5c824292e91498596c759e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_catspor_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp double precision;
BEGIN
  --Florin 01.03.2022
  INSERT INTO TMP_SAL_CATSPOR
  (
  CODCATSPOR, Denumire, Simbol
  )
  (
  SELECT CODCATSPOR, Denumire, Simbol
  FROM SAL_CATSPOR
  WHERE
     CODCATSPOR = RecId);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_catspor_sp_insertrecord</obj_name>
  <obj_hashval>c6841b58b00014a448e05a3410ca6672</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_catspor_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 01.03.2022
  INSERT INTO TMP_SAL_CATSPOR
  (
  CODCATSPOR
  )
  VALUES
  (
  0
  );
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_nasig_sp_insertrecord</obj_name>
  <obj_hashval>6192dffcbd5374d9445f64afff7f9654</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_nasig_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
 DECLARE
 V_REC RECORD;
  aDoc varchar;
  vCod numeric;
BEGIN
  --Florin 02.03.2022
  INSERT INTO TMP_SAL_NASIG
  (
  codnasig
  )
  VALUES
  (
  0
  );
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_ndrep_sp_deleterecord</obj_name>
  <obj_hashval>ce09491396b4947676f504f746200313</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_ndrep_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aDoc varchar;
BEGIN
  --Florin 31.03.2021 - postLog
  --Florin 02.03.2022
  PERFORM pkg_sal_ndrep_setct_monitor('MON_5');
  SELECT tip
  INTO aDoc
  FROM TMP_SAL_NDREP;
  SELECT codndrep
  INTO RECID
  FROM TMP_SAL_NDREP;
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting('PKG_SAL_NDREP.CT_MONITOR', true)))
  THEN
    PERFORM WINMADMIN.PKG_USERFIRME_PostLogcucommit('SAL_NDREP', current_setting ('PKG_GLOBALS.USERNAME', true) , 'S', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
  PERFORM PKG_SAL_NDREP_SP_LOCKRECORD( RecId);
  DELETE FROM SAL_NDREP1
  WHERE
   codndrep = RecId;
  DELETE FROM SAL_NDREP0
  WHERE
   codndrep = RecId;
  DELETE FROM SAL_NDREP
  WHERE
   codndrep = RecId;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_retineri_sp_insertrecord</obj_name>
  <obj_hashval>885c264ab9bf5054ae8e7cf39aeeb191</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_retineri_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 02.03.2022
  INSERT INTO TMP_SAL_RETINERI
  (
  CODRETINERE
  )
  VALUES
  (
  0
  );
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_sporuri_setct_monitor</obj_name>
  <obj_hashval>a17c3fd7255b6f05a73cb44e2f3391b6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_sporuri_setct_monitor(act_monitor character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 02.03.2022
  perform set_config('PKG_SAL_SPORURI.CT_MONITOR',aCT_MONITOR,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sali_sp_deleterecord</obj_name>
  <obj_hashval>18ecbe2e95b11a538c456691e66e9148</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sali_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  --Bogdan 27.06.2023 - sincronizare
  PERFORM PKG_SALI_SP_LOCKRECORD( RecId);

  FOR V_REC IN (SELECT * FROM MESE WHERE CODSALA = RECID) LOOP
    DELETE FROM MESE WHERE CODMASA = V_REC.CODMASA;
  END LOOP;

  DELETE FROM SALIUSERI WHERE CODSALA = RecId ;
    DELETE FROM SALI WHERE CODSALA = RecId;

  PERFORM NotifyModif( 2, RecId, 'SALI');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sali_sp_gotorecord</obj_name>
  <obj_hashval>d0a65b93406bd5aec72189eb8e6c0fa0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sali_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Bogdan 27.06.2023 - sincronizare
  --Florin 19.05.2022
  INSERT INTO TMP_SALI(CODSALA, DENUMIRE, CODPERS, NUMARMESE, CODRESTAURANT, CODCATPRET)
  SELECT CODSALA, DENUMIRE, CODPERS, NUMARMESE, CODRESTAURANT, CODCATPRET FROM SALI WHERE CODSALA = RecId;

  INSERT INTO TMP_SALIUSERI
    SELECT * FROM SALIUSERI WHERE CODSALA = RECID;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_scenariilivr_docommit</obj_name>
  <obj_hashval>1ce7bf4159b72a25d58727bbe3de82ca</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_scenariilivr_docommit(INOUT wme_result boolean, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_SCENARIILIVR.DoCommit'));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := true;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_scenariilivr_getdocommit</obj_name>
  <obj_hashval>fd0e6935a37323c7d065ec436ff21cdc</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_scenariilivr_getdocommit(INOUT wme_result boolean, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_SCENARIILIVR.DoCommit'));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := true;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_serii_sp_deleterecord</obj_name>
  <obj_hashval>feeffb68423763789fda9ae7946bb848</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_serii_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_SERII_SP_LOCKRECORD( RECID);
  DELETE FROM NSERII WHERE CODSERIE = RECID;
  PERFORM NotifyModif( 2, RecId, 'NSERII');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_serii_sp_gotorecord</obj_name>
  <obj_hashval>fe562fc08a34bdcebc9de9ae4338edd7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_serii_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_NSERII(CODSERIE, SERIE, CODOBIECT, OBS)
  (SELECT CODSERIE, SERIE, CODOBIECT, OBS FROM NSERII WHERE CODSERIE = RECID);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_serii_sp_insertrecord</obj_name>
  <obj_hashval>ff0032c0902e267a8e5f8866e60eaec4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_serii_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_NSERII (CODSERIE) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_servfact_sp_deleterecord</obj_name>
  <obj_hashval>db43e295ea2242c235fba703f4b74429</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_servfact_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_SERVFACT_SP_LOCKRECORD( RecId);
  DELETE FROM SERVFACT1 WHERE CODSERVFACT = RecId;
  DELETE FROM SERVFACT  WHERE CODSERVFACT = RecId;
  PERFORM NotifyModif( 2, RecId, 'SERVFACT');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_servfact_sp_gotorecord</obj_name>
  <obj_hashval>8759f6e24d29d52eb2819c0a7697b63c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_servfact_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Adina 24.05.2021 - sinc.Oracle din 22.05.2021 - doar martor la zi
  INSERT INTO TMP_SERVFACT(CODSERVFACT, DENUMIRE, CODOBIECT, SUMAPORNIREKM, SUMAPORNIRECANT, PROCPORNIREKM, PROCPORNIRECANT, MODCALCUL, COD)
  SELECT CODSERVFACT, DENUMIRE, CODOBIECT, SUMAPORNIREKM, SUMAPORNIRECANT, PROCPORNIREKM, PROCPORNIRECANT, MODCALCUL, COD
  FROM SERVFACT WHERE CODSERVFACT = RECID;

  INSERT INTO TMP_SERVFACT1(CODSERVFACT1, CODSERVFACT, PANALA, VALOARE)
  SELECT CODSERVFACT1, CODSERVFACT, PANALA, VALOARE FROM SERVFACT1 WHERE CODSERVFACT = RECID ORDER BY PANALA ;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_empty_documente_for_compens</obj_name>
  <obj_hashval>6ed762a44dacbd2bb595ff2ee2d7a393</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_empty_documente_for_compens()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_COMPENS;
  DELETE FROM TMP_GENERAL;
  DELETE FROM TMP_OBLIGPIF;
  DELETE FROM TMP_OBLIGPIF_ASOCIAT;
  DELETE FROM TMP_OBLIGPIF_INITIAL;
  DELETE FROM TMP_STINGERE;
  DELETE FROM TMP_STINGERE_ASOCIAT;
  DELETE FROM TMP_STINGERE_INITIAL;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_cheltavans_for_jurnal</obj_name>
  <obj_hashval>06440a4f9873ea88f1f2ca25f360420c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_cheltavans_for_jurnal(startrec numeric, endrec numeric, flg_isvenit numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  NR    numeric := 0;
  sTipRefacere varchar;
BEGIN
  --Florin 06.08.2024 - sinc. Oracle
  --Gabi 29.03.2023 optimizare refacere completa
  --Stef 03.03.2023
  PERFORM PKG_SERVICE_EMPTY_DOCUMENTE_FOR_CHELTAVANS();

   sTipRefacere := trim(current_setting('PKG_SERVICE.TIPJURNAL', false));

  INSERT INTO TMP_CHELTAVANS(CODCHELTAVANS, CODINTR1, ANINCEPUT, LUNAINCEPUT, CODIOART, CODGEST, DEN_GEST, CODSUBUNIT, NRDOC, DEN_PART, OBS, PREFIXDOC, SERIADOC, DATASTART, DATAEND, TIPINTERVAL, IsVenit)
  (SELECT CODCHELTAVANS, CODINTR1, ANINCEPUT, LUNAINCEPUT, CODIOART, CODGEST, DEN_GEST, SUBUNITATEA, NRDOC, DEN_PART, OBS, PREFIXDOC, SERIADOC, DATASTART, DATAEND, 0, IsVenit
   FROM (SELECT row_number() over() as RN, S.*
         FROM (SELECT CHELTAV.*
               FROM (SELECT AV.CODCHELTAVANS, AV.CODINTR1, AV.CODOBLIGPIF, AV.CODNC1, AV.ANINCEPUT, AV.LUNAINCEPUT, AV.CODIOART, G.CODGEST, G.DEN_GEST, I.SUBUNITATEA, I.NRDOC, P.DEN_PART, I1.OBS, I.PREFIXDOC, I.SERIADOC, AV.DATASTART, AV.DATAEND, AV.IsVenit
                     FROM CHELTAVANS AV
                          LEFT JOIN TMP_IOART_LUNA IOL ON  IOL.CODIOART = AV.CODIOART, CHELTAVANS1 AV1, INTRARI I, INTRARI1 I1
                          LEFT JOIN NGEST          G   ON  G.CODGEST    = I1.GESTACT, NPART P
                     WHERE  COALESCE(AV.ISVENIT, 0) = flg_ISVENIT
                       AND  AV1.CODCHELTAVANS = AV.CODCHELTAVANS
                       AND  I1.CODINTR1 = AV.CODINTR1
                       AND  I.CODINTR = I1.CODINTR
                       AND  AV1.ANSTART * 12 + AV1.LUNASTART = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X)
                       AND ( case
                              when sTipRefacere = '0' then 1
                              else PKG_SERVICE_IS_DIRTY_DOC(52, AV.CODCHELTAVANS, 106)
                            end) = 1
                       AND  P.CODPART = I.PARTENER
                       AND (EXISTS (SELECT CONTCHELTAVANS FROM TMP_CONTCHELTAVANS WHERE CONTCHELTAVANS = (IOL.CONT)::varchar)
                            OR
                            EXISTS (SELECT CONTVENITAVANS FROM TMP_CONTVENITAVANS WHERE CONTVENITAVANS = IOL.CONT))
                     union ALL
                     SELECT AV.CODCHELTAVANS, AV.CODINTR1, AV.CODOBLIGPIF, AV.CODNC1, AV.ANINCEPUT, AV.LUNAINCEPUT, AV.CODIOART, G.CODGEST, G.DEN_GEST, I.SUBUNITATEA, I.NRDOC, P.DEN_PART, I1.OBS, I.PREFIXDOC, I.SERIADOC, AV.DATASTART, AV.DATAEND, AV.IsVenit
                     FROM CHELTAVANS AV
                          LEFT JOIN TMP_IOART_LUNA IOL ON  IOL.CODIOART = AV.CODIOART,
                          CHELTAVANS1 AV1, IESIRI I
                          LEFT JOIN NPART P ON P.CODPART = I.PARTENER AND I.TIPDOC IN (19, 20, 21, 26),
                          IESIRI1 I1
                          LEFT JOIN NGEST G ON  G.CODGEST = I1.GESTACT
                          --NPART P
                     WHERE  COALESCE(AV.ISVENIT, 0) = flg_ISVENIT
                       AND  AV1.CODCHELTAVANS = AV.CODCHELTAVANS
                       AND  I1.CODIES1 = AV.CODIES1
                       AND  I.CODIES = I1.CODIES
                       AND  AV1.ANSTART * 12 + AV1.LUNASTART = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X)
--                       AND  PKG_SERVICE_IS_DIRTY_DOC(52, AV.CODCHELTAVANS, 106) = 1
                       AND ( case
                              when sTipRefacere = '0' then 1
                              else PKG_SERVICE_IS_DIRTY_DOC(52, AV.CODCHELTAVANS, 106)
                            end) = 1
                       --AND  P.CODPART = I.PARTENER
                       AND (EXISTS (SELECT CONTCHELTAVANS FROM TMP_CONTCHELTAVANS WHERE CONTCHELTAVANS = (IOL.CONT)::varchar)
                            OR
                            EXISTS (SELECT CONTVENITAVANS FROM TMP_CONTVENITAVANS WHERE CONTVENITAVANS = IOL.CONT))
                     union ALL
                     SELECT AV.CODCHELTAVANS, AV.CODINTR1, AV.CODOBLIGPIF, AV.CODNC1, AV.ANINCEPUT, AV.LUNAINCEPUT, AV.CODIOART, O.CODGEST, NG.DEN_GEST, T.SUBUNITATEA, T1.NRDOC, NULL AS DEN_PART, T1.OBS, T1.DOC, NULL AS SERIADOC, AV.DATASTART, AV.DATAEND, AV.IsVenit
                     FROM CHELTAVANS AV
                          LEFT JOIN TMP_IOART_LUNA IOL ON  IOL.CODIOART = AV.CODIOART, CHELTAVANS1 AV1, OBLIGPIF O
                          LEFT JOIN NGEST NG ON  NG.CODGEST = O.CODGEST, GENERAL G, TREZOR1 T1, TREZOR T
                     WHERE  COALESCE(AV.ISVENIT, 0) = flg_ISVENIT
                       AND  AV1.CODCHELTAVANS = AV.CODCHELTAVANS
                       AND  O.CODOBLIGPIF = AV.CODOBLIGPIF
                       AND  G.CODGENERAL = O.CODGENERAL
                       AND  T1.CODTREZOR1 = G.CODDOC
                       AND  T.CODTREZOR = T1.CODTREZOR
                       AND (EXISTS (SELECT CONTCHELTAVANS FROM TMP_CONTCHELTAVANS WHERE CONTCHELTAVANS = (IOL.CONT)::varchar)
                            OR
                            EXISTS (SELECT CONTVENITAVANS FROM TMP_CONTVENITAVANS WHERE CONTVENITAVANS = IOL.CONT))
                       AND  AV1.ANSTART * 12 + AV1.LUNASTART = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X)
                       AND ( case
                              when sTipRefacere = '0' then 1
                              else PKG_SERVICE_IS_DIRTY_DOC(52, AV.CODCHELTAVANS, 106)
                            end) = 1
                       --                       AND PKG_SERVICE_IS_DIRTY_DOC(52, AV.CODCHELTAVANS, 106) = 1
                     union ALL
                     SELECT AV.CODCHELTAVANS, AV.CODINTR1, AV.CODOBLIGPIF, AV.CODNC1, AV.ANINCEPUT, AV.LUNAINCEPUT, AV.CODIOART, N1.CODGEST, NG.DEN_GEST, N.SUBUNITATEA, N.NRDOC, NULL AS DEN_PART, N1.OBS, 'NC' AS DOC, NULL AS SERIADOC, AV.DATASTART, AV.DATAEND, AV.IsVenit
                     FROM CHELTAVANS AV
                          LEFT JOIN TMP_IOART_LUNA IOL ON  IOL.CODIOART = AV.CODIOART,
                          CHELTAVANS1 AV1, NC1 N1
                          LEFT JOIN NGEST NG ON  NG.CODGEST = N1.CODGEST, NC N
                     WHERE  COALESCE(AV.ISVENIT, 0) = flg_ISVENIT
                       AND  AV1.CODCHELTAVANS = AV.CODCHELTAVANS
                       AND  N1.CODNC1 = AV.CODNC1
                       AND  N.CODNC = N1.CODNC
                       AND (EXISTS (SELECT CONTCHELTAVANS FROM TMP_CONTCHELTAVANS WHERE CONTCHELTAVANS = (IOL.CONT)::varchar)
                            OR
                            EXISTS (SELECT CONTVENITAVANS FROM TMP_CONTVENITAVANS WHERE CONTVENITAVANS = IOL.CONT))
                       AND  AV1.ANSTART * 12 + AV1.LUNASTART = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X)
--                       AND PKG_SERVICE_IS_DIRTY_DOC(52, AV.CODCHELTAVANS, 106) = 1
                       AND ( case
                              when sTipRefacere = '0' then 1
                              else PKG_SERVICE_IS_DIRTY_DOC(52, AV.CODCHELTAVANS, 106)
                            end) = 1
                    ) CHELTAV
                  ORDER BY CODCHELTAVANS
                ) S
              ) A_PG
            WHERE RN &gt;= STARTREC AND  RN &lt;= ENDREC
          );

  INSERT INTO TMP_CHELTAVANS1(CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, ANSTART, LUNASTART, AMO, CODCENTRU, CODGEST, CODANALIZANOD, DATAENDNOUA, DATAENDBLOCATA)
  SELECT CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, ANSTART, LUNASTART, AMO, CODCENTRU, CODGEST, CODANALIZANOD, DATAENDNOUA, DATAENDBLOCATA
  FROM CHELTAVANS1 AV1
  WHERE
     AV1.ANSTART * 12 + AV1.LUNASTART = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X)
     AND  EXISTS (SELECT CODCHELTAVANS FROM TMP_CHELTAVANS WHERE CODCHELTAVANS = AV1.CODCHELTAVANS);

  UPDATE TMP_CHELTAVANS C
  SET
  TIPINTERVAL = 1
  WHERE
      DATASTART IS NOT NULL
  AND (DATAEND  IS NOT NULL
       OR
       (SELECT COUNT(*) FROM TMP_CHELTAVANS1 C1 WHERE C1.CODCHELTAVANS = C.CODCHELTAVANS AND DATAENDNOUA IS NOT NULL) &gt; 0
      );

  FOR V_REC IN (SELECT * FROM TMP_CHELTAVANS1) LOOP
    IF V_REC.DATAENDNOUA IS NOT NULL THEN
      UPDATE TMP_CHELTAVANS SET DATAEND = V_REC.DATAENDNOUA WHERE CODCHELTAVANS = V_REC.CODCHELTAVANS;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_compens_for_jurnal</obj_name>
  <obj_hashval>946dd912247fc3390a8b19a03a01c4a8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_compens_for_jurnal(startrec numeric, endrec numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC            RECORD;
  aCODSUBUNITSTINS numeric := 0;
begin
  --Stef 03.03.2023
  PERFORM PKG_SERVICE_EMPTY_DOCUMENTE_FOR_COMPENS();

  INSERT INTO TMP_COMPENS(CODCOMPENS, DATADOC, CARNETDOC, NRDOC, AN, LUNA, PARTD, PARTC, OBSD, OBSC, VALDEBIT, VALCREDIT, SUBUNITATEA, CODGEST, TIPCOMPENS, CODCENTRU, CODANALIZA)
  SELECT CODCOMPENS, DATADOC, CARNETDOC, NRDOC, AN, LUNA, PARTD, PARTC, OBSD, OBSC, 0, 0, SUBUNITATEA, CODGEST, TIPCOMPENS, CODCENTRU, CODANALIZA
  FROM (SELECT row_number() over() RN, S.*
        FROM (SELECT CODCOMPENS, DATADOC, CARNETDOC, NRDOC, AN, LUNA, PARTD, PARTC, OBSD, OBSC, 0 AS VALDEBIT, 0 AS VALCREDIT, SUBUNITATEA, CODGEST, TIPCOMPENS, CODCENTRU, CODANALIZA
              FROM COMPENS C
              WHERE AN * 12 + LUNA = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X)
                AND PKG_SERVICE_IS_DIRTY_DOC(28, C.CODCOMPENS) = 1
              ORDER BY CODCOMPENS
             ) S
       ) A_PG
  WHERE RN &gt;= STARTREC AND  RN &lt;= ENDREC;

  INSERT INTO TMP_GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
  FROM GENERAL G
  WHERE
     TIPDOC = 28 AND  EXISTS (SELECT CODCOMPENS FROM TMP_COMPENS WHERE CODCOMPENS = G.CODDOC);

  INSERT INTO TMP_OBLIGPIF(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, COEFPROVIZION, VALPROVIZION, CODCENTRU)
  SELECT *
  FROM (SELECT CODOBLIGPIF, CODGENERAL, TERMEN, (SELECT PKG_COMPENSARI_SEMNCOMPENS.WME_RESULT FROM PKG_COMPENSARI_SEMNCOMPENS(NULL, O.SEMNIFICATIE, O.ICONT)) * VALOARE, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, COEFPROVIZION, 0, CODCENTRU
        FROM OBLIGPIF O
        WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL ) AND SEMNIFICATIE IN (1300, 1301, 1302, 1303)
       ) B_PG
  ORDER BY CODOBLIGPIF ;

  INSERT INTO TMP_OBLIGPIF_ASOCIAT(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, COEFPROVIZION, VALPROVIZION, CODCENTRU)
  SELECT *
  FROM (SELECT CODOBLIGPIF, CODGENERAL, TERMEN, (SELECT PKG_COMPENSARI_SEMNCOMPENS.WME_RESULT FROM PKG_COMPENSARI_SEMNCOMPENS(NULL, O.SEMNIFICATIE, O.ICONT)) * VALOARE, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, COEFPROVIZION, 0, CODCENTRU
        FROM OBLIGPIF O
        WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL) AND SEMNIFICATIE IN (1350, 1351, 1352)
       ) C_PG
  ORDER BY CODOBLIGPIF ;

  INSERT INTO TMP_STINGERE(CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
  (SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE
   FROM STINGERE
   WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF)
  );

  INSERT INTO TMP_STINGERE_ASOCIAT(CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
  (SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE
   FROM STINGERE
   WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF_ASOCIAT)
  );

  DELETE FROM TMP_OBLIGPIF_INITIAL;
  INSERT INTO TMP_OBLIGPIF_INITIAL(SELECT * FROM TMP_OBLIGPIF);
  INSERT INTO TMP_OBLIGPIF_INITIAL(SELECT * FROM TMP_OBLIGPIF_ASOCIAT);
  DELETE FROM TMP_STINGERE_INITIAL;
  INSERT INTO TMP_STINGERE_INITIAL(SELECT * FROM TMP_STINGERE UNION SELECT * FROM TMP_STINGERE_ASOCIAT);

  UPDATE TMP_OBLIGPIF OB
      set
      CURS = (select case  when coalesce( CURS, 0)= 0 then 1 else CURS end
                from TMP_GENERAL
                where CODGENERAL = OB.CODGENERAL ),
      TVA  = (select coalesce( TVA, 0) from TMP_GENERAL where CODGENERAL = OB.CODGENERAL),
      MONEDA  = coalesce( ( select MONEDA from TMP_GENERAL where CODGENERAL = OB.CODGENERAL ), 0),
      SUMALEI = ROUND( coalesce( ( select CURS from TMP_GENERAL where CODGENERAL = OB.CODGENERAL ), 1) * OB.VALOARE, 6),
      VALPROVIZION = ROUND( ROUND( coalesce( ( select CURS from TMP_GENERAL where CODGENERAL = OB.CODGENERAL ), 1) * OB.VALOARE, 6) * OB.COEFPROVIZION, 6),
      CURSISTORIC  = coalesce( (select G.CURS
                                from STINGERE S
                                     left join OBLIGPIF O on O.CODOBLIGPIF = S.CODSTINSPIF
                                     left join general G on G.CODGENERAL = O.CODGENERAL
                                where S.CODSTINGATORPIF = OB.CODOBLIGPIF limit 1),
                      0),
      SEMNIFCODSTINS = coalesce( ( select coalesce( O.SEMNIFICATIE, 0) from STINGERE S left join OBLIGPIF O on O.CODOBLIGPIF = S.CODSTINSPIF where S.CODSTINGATORPIF = OB.CODOBLIGPIF ), 0),
      CURSDOCSTINS   = coalesce( ( select coalesce( GREG.CURS, G.CURS) from STINGERE S left join OBLIGPIF O on O.CODOBLIGPIF = S.CODSTINSPIF left join general G on G.CODGENERAL = O.CODGENERAL left join TMP_CURS_REGULARIZAT_LUNA GREG on GREG.CODGENERAL = G.CODGENERAL where S.CODSTINGATORPIF = OB.CODOBLIGPIF ), 0) ;

  UPDATE TMP_OBLIGPIF_ASOCIAT OB
  SET
  CURS = (SELECT CASE WHEN  COALESCE( CURS, 0)=0 THEN 1 ELSE  CURS END FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL),
  TVA  = (SELECT COALESCE( TVA, 0) FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL),
  MONEDA  = COALESCE( (SELECT MONEDA FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 0),
  SUMALEI = ROUND( COALESCE( (SELECT CURS FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 1) * OB.VALOARE, 6),
  VALPROVIZION = ROUND( ROUND( COALESCE( (SELECT CURS FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 1) * OB.VALOARE, 6) * OB.COEFPROVIZION, 6),
  SEMNIFCODSTINS = COALESCE( (SELECT COALESCE( O.SEMNIFICATIE, 0)
                              FROM STINGERE S
                                   LEFT JOIN OBLIGPIF O ON  O.CODOBLIGPIF = S.CODSTINSPIF
                              WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF
                   ), 0),
  CURSISTORIC = COALESCE( (SELECT G.CURS
                           FROM STINGERE S
                                LEFT JOIN OBLIGPIF O ON  O.CODOBLIGPIF = S.CODSTINSPIF
                                LEFT JOIN GENERAL  G ON  G.CODGENERAL  = O.CODGENERAL
                           WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF
                ), 1),
  CURSDOCSTINS = COALESCE( (SELECT COALESCE( GREG.CURS, G.CURS)
                            FROM STINGERE S
                                 LEFT JOIN OBLIGPIF O ON  O.CODOBLIGPIF = S.CODSTINSPIF
                                 LEFT JOIN GENERAL  G ON  G.CODGENERAL  = O.CODGENERAL
                                 LEFT JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON  GREG.CODGENERAL = G.CODGENERAL
                            WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF
                 ), 0)
  ;

  FOR V_REC IN
  (
  SELECT S.CODSTINGERE, G.TIPDOC, G.CODDOC, G.SEMNIFICATIE
  FROM TMP_STINGERE S, OBLIGPIF O, GENERAL G
  WHERE
     S.CODSTINSPIF = O.CODOBLIGPIF AND  G.CODGENERAL = O.CODGENERAL
  )
  LOOP
    aCODSUBUNITSTINS := 0;
    IF V_REC.SEMNIFICATIE IN (100, 110, 130) THEN
      BEGIN
        SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM INTRARI WHERE CODINTR = V_REC.CODDOC AND  TIPDOC = V_REC.TIPDOC;
      EXCEPTION WHEN OTHERS THEN
        aCODSUBUNITSTINS := 0;
      END;
    ELSE
      IF V_REC.SEMNIFICATIE IN (200, 210) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM IESIRI WHERE CODIES = V_REC.CODDOC AND  TIPDOC = V_REC.TIPDOC;
        EXCEPTION WHEN OTHERS THEN
          aCODSUBUNITSTINS := 0;
        END;
      ELSE
        IF V_REC.SEMNIFICATIE IN (1200, 1201) THEN
          BEGIN
            SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM NC N, NC1 N1 WHERE N1.CODNC1 = V_REC.CODDOC AND  N.CODNC = N1.CODNC;
          EXCEPTION WHEN OTHERS THEN
            aCODSUBUNITSTINS := 0;
          END;
        ELSE
          IF V_REC.SEMNIFICATIE IN (310, 330, 410, 430) THEN
            BEGIN
              SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM TREZOR T, TREZOR1 T1 WHERE T1.CODTREZOR1 = V_REC.CODDOC AND  T.CODTREZOR = T1.CODTREZOR;
            EXCEPTION WHEN OTHERS THEN
              aCODSUBUNITSTINS := 0;
            END;
          ELSE
            IF V_REC.SEMNIFICATIE IN (1300, 1301, 1302, 1303, 1350, 1351, 1352) THEN
              BEGIN
                SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM COMPENS C WHERE C.CODCOMPENS = V_REC.CODDOC;
              EXCEPTION WHEN OTHERS THEN
                aCODSUBUNITSTINS := 0;
              END;
            END IF;
          END IF;
        END IF;
      END IF;
    END IF;

    UPDATE TMP_STINGERE SET CODSUBUNITSTINS = aCODSUBUNITSTINS WHERE CODSTINGERE = V_REC.CODSTINGERE;
  END LOOP;

  FOR V_REC IN
  (
  SELECT S.CODSTINGERE, G.TIPDOC, G.CODDOC, G.SEMNIFICATIE
  FROM TMP_STINGERE_ASOCIAT S, OBLIGPIF O, GENERAL G
  WHERE
     S.CODSTINSPIF = O.CODOBLIGPIF AND  G.CODGENERAL = O.CODGENERAL
  )
  LOOP
    aCODSUBUNITSTINS := 0;
    IF V_REC.SEMNIFICATIE IN (100, 110, 130) THEN
      BEGIN
        SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM INTRARI WHERE CODINTR = V_REC.CODDOC AND  TIPDOC = V_REC.TIPDOC;
      EXCEPTION WHEN OTHERS THEN
        aCODSUBUNITSTINS := 0;
      END;
    ELSE
      IF V_REC.SEMNIFICATIE IN (200, 210) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM IESIRI WHERE CODIES = V_REC.CODDOC AND  TIPDOC = V_REC.TIPDOC;
        EXCEPTION WHEN OTHERS THEN
          aCODSUBUNITSTINS := 0;
        END;
      ELSE
        IF V_REC.SEMNIFICATIE IN (1200, 1201) THEN
          BEGIN
            SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM NC N, NC1 N1 WHERE N1.CODNC1 = V_REC.CODDOC AND  N.CODNC = N1.CODNC;
          EXCEPTION WHEN OTHERS THEN
            aCODSUBUNITSTINS := 0;
          END;
        ELSE
          IF V_REC.SEMNIFICATIE IN (310, 330, 410, 430) THEN
            BEGIN
              SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM TREZOR T, TREZOR1 T1 WHERE T1.CODTREZOR1 = V_REC.CODDOC AND  T.CODTREZOR = T1.CODTREZOR;
            EXCEPTION WHEN OTHERS THEN
              aCODSUBUNITSTINS := 0;
            END;
          ELSE
            IF V_REC.SEMNIFICATIE IN (1300, 1301, 1302, 1303, 1350, 1351, 1352) THEN
              BEGIN
                SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM COMPENS C WHERE C.CODCOMPENS = V_REC.CODDOC;
              EXCEPTION WHEN OTHERS THEN
                aCODSUBUNITSTINS := 0;
              END;
            END IF;
          END IF;
        END IF;
      END IF;
    END IF;

    UPDATE TMP_STINGERE_ASOCIAT SET CODSUBUNITSTINS = aCODSUBUNITSTINS WHERE CODSTINGERE = V_REC.CODSTINGERE;
  END LOOP;

  UPDATE TMP_OBLIGPIF O         SET CODTREZOR1 = (SELECT CODDOC FROM GENERAL G WHERE G.CODGENERAL = O.CODGENERAL);
  UPDATE TMP_OBLIGPIF_ASOCIAT O SET CODTREZOR1 = (SELECT CODDOC FROM GENERAL G WHERE G.CODGENERAL = O.CODGENERAL);
  UPDATE TMP_OBLIGPIF_INITIAL O SET CODTREZOR1 = (SELECT CODDOC FROM GENERAL G WHERE G.CODGENERAL = O.CODGENERAL);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_difpretprod_recordcount</obj_name>
  <obj_hashval>fcfb916f918789ea9ee001ebf03d6f14</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_difpretprod_recordcount(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 03.03.2023
  SELECT COUNT(1) INTO wme_result
  FROM DIFPretPROD
  WHERE AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE_IS_DIRTY_DOC(80, CODDifPretProd) = 1;

  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_distribchelt_recordcount</obj_name>
  <obj_hashval>593aad794fe4e40ddbfa29e50d0afe71</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_distribchelt_recordcount(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 03.03.2023
  SELECT COUNT(1) INTO wme_result
  FROM DISTRIBCHELT
  WHERE AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE_IS_DIRTY_DOC(76, CODDISTRIBCHELT) = 1;

  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_iesiri_for_coefdiscmaj</obj_name>
  <obj_hashval>3976d03d5b7a0f77858c46813887bd78</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_iesiri_for_coefdiscmaj(aan numeric, aluna numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 10.01.2023 - sinc. Oracle
  --Florin 29.06.2022 - fnc_getprocenttvaart
  --Laura 27.01.2022 - sinc. Oracle (29.12.2021)
  perform PKG_SERVICE_EMPTY_DOCUMENTE_FOR_JURNAL();

  INSERT INTO TMP_IESIRI ( CODIES,
    TIPDOC,
    ANULAT,
    BLOCAT,
    OPERAT,
    PREFIXDOC,
    CARNETDOC,
    NRDOC,
    DATADOC,
    PARTENER,
    CODSUBUNIT,
    CARNETAE,
    NRAE,
    VALDOC,
    TVADOC,
    VALDISCOUNT,
    TVADISCOUNT,
    CONTDISCOUNT,
    ACCIZE,
    DELEGAT,
    AGENT,
    MAJORARI,
    OBS,
    AN,
    LUNA,
    CODFISCAL,
    SERIADOC,
    BUGETARE,
    CODLOCATIE,
    TIPFACTURA,
    CODGESTPROD,
    CONTINTERMED,
    MONEDA,
    TIPCHELT,
    TipTVA,
    CURS,
    SUBUNITATEA,
    INFOCM,
    CONTSUPLIM,
    CUSTODIE,
    TVAIncasare,
    DataTVA,
    TIPTRANZACTIE )
  select
    CODIES,
    TIPDOC,
    ANULAT,
    BLOCAT,
    OPERAT,
    PREFIXDOC,
    CARNETDOC,
    NRDOC,
    DATADOC,
    PARTENER,
    CODSUBUNIT,
    CARNETAE,
    NRAE,
    VALDOC,
    TVADOC,
    VALDISCOUNT,
    TVADISCOUNT,
    CONTDISCOUNT,
    ACCIZE,
    DELEGAT,
    AGENT,
    MAJORARI,
    OBS,
    AN,
    LUNA,
    CODFISCAL,
    SERIADOC,
    BUGETARE,
    CODLOCATIE,
    TIPFACTURA,
    CODGESTPROD,
    CONTINTERMED,
    MONEDA,
    TIPCHELT,
    TipTVA,
    CURS,
    SUBUNITATEA,
    INFOCM,
    CONTSUPLIM,
    CUSTODIE,
    TVAIncasare,
    DataTVA,
    TIPTRANZACTIE
  FROM IESIRI I
  where
    AN * 12 + LUNA = aAN * 12 + aLUNA
    and TIPDOC in (19, 20, 26)
    and OPERAT = 1
    and ANULAT = 0
  order BY CODIES ;

  DELETE FROM IESIRI1_MAN;

  INSERT INTO IESIRI1_MAN
  SELECT * FROM IESIRI1 I1
  WHERE exists (SELECT * FROM TMP_IESIRI WHERE CODIES = I1.CODIES );

  INSERT INTO TMP_IESIRI1 ( CODIES1,
    CODIES,
    INDEXLOCAL,
    TIPLINIE,
    UMSEC,
    CodCentru,
    CONTSERV,
    GESTACT,
    CODOBIECT,
    PRETORIG,
    PU,
    CANT,
    TVA,
    CONT,
    PROCDISC,
    ADDIM,
    RESTFACT,
    PUMAXIMAL,
    GARANTIE,
    DENUM,
    VALOARE,
    PARITATE,
    PROCTVA,
    CODOBLIGSTORNO,
    CURSFACTURAAVANS,
    TipLivrare,
    CUSTODIEINTRARE,
    CODTVA,
    CODACCIZE,
    CODTAXA1,
    CODTAXA2,
    CODCMDINT1,
    DENOBIECT,
    SIMBOLCONTSERV,
    CONTDISCOUNT,
    CODANALIZANOD,
    MIFIX,
    CODMIFIX,
    ICONTPART,
    TAXA)
  select
    *
  from
    (
    select
      I1.CODIES1,
      I1.CODIES,
      I1.INDEXLOCAL,
      I1.TIPLINIE,
      I1.UMSEC,
      i1.CodCentru,
      I1.CONTSERV,
      I1.GESTACT,
      I1.CODOBIECT,
      I1.PRETORIG * coalesce(U1.PARITATE, 1),
      I1.PU * coalesce(U1.PARITATE, 1),
      I1.CANT / coalesce(U1.PARITATE, 1),
      I1.TVA,
      I1.CONT,
      I1.PROCDISC,
      I1.ADDIM,
      I1.RESTFACT,
      I1.PUMAXIMAL,
      I1.GARANTIE,
      CASE when I1.TIPLINIE in ('G', 'T') then '%' else U1.DEN_UM1 end ,
      (CASE when I1.TIPLINIE in ('=', 'S', 'V') then I1.CANT * I1.PU else I1.RESTFACT end ) ,
      U1.PARITATE,
      CASE when I1.TIPLINIE in ('=', 'S', 'V') then fnc_getprocenttvaart(A.CODARTICOL, TG.ANLUCRU, TG.LUNALUCRU)
           else 0
      end ,
      I1.CODOBLIGSTORNO,
      I1.CURSFACTURAAVANS,
      I1.TipLivrare,
      I1.CUSTODIEINTRARE,
      NART1LUNA.CODTVA,
      NART1LUNA.CODACCIZE,
      NART1LUNA.CODTAXA1,
      NART1LUNA.CODTAXA2,
      I1.CODCMDINT1,
      O.DENUMIRE,
      CASE when TIPLINIE in ('G', 'T') and coalesce(I1.CODOBIECT, 0) = 0 then '(' || coalesce(C.SIMBOL, '') || ')'
           when TIPLINIE in ('S', 'V') then '(' || coalesce((select PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT from PKG_PLANCONTURI_GETSIMBOLCONT(null, I1.CONTSERV)), '') || ')'
           else ''
      end ,
      I1.CONTDISCOUNT,
      I1.CODANALIZANOD,
      I1.MIFIX,
      I1.CODMIFIX,
      I1.ICONTPART,
      I1.TAXA
    FROM IESIRI1_MAN I1
      CROSS JOIN TMP_PKG_GLOBALS TG
      left  join NARTOBJ O      ON O.CODOBIECT = I1.CODOBIECT
      left  join NART    A      ON A.CODARTICOL = O.CODARTICOL
      left  join NART1   NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP
      left  join NUM1    U1      ON U1.CODUM1 = I1.UMSEC
      left  join NCONT   C      ON C.CODCONT = I1.CONTDISCOUNT
      ) A_PG
  order BY CODIES , INDEXLOCAL ;

  UPDATE TMP_IESIRI1 I1
  SET
    NRDOCLINK = (SELECT coalesce(II.PREFIXDOC, '') || coalesce((II.NRDOC)::varchar , '')
                 FROM IESLINK IL
                      left join IESIRI1 II1 ON II1.CODIES1 = IL.CODLINIEAVIZ
                      left join IESIRI  II  ON II.CODIES   = II1.CODIES
                 WHERE IL.CODIES1 = I1.CODIES1 )
  WHERE I1.TIPLINIE in ('S', '=')
    and coalesce(( select TIPDOC from TMP_IESIRI where CODIES = I1.CODIES ), 0) = 26 ;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_iesiri_for_jurnal</obj_name>
  <obj_hashval>a4375ba420fb06b13d1cd963d04fe070</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_iesiri_for_jurnal(startrec numeric, endrec numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  v_LT               RECORD;
  V_REC            RECORD;
  NR               double precision := 0;
  LUNAREF          REFCURSOR;
  IOPART1REC       RECORD;
  aCODSUBUNITSTINS numeric;
BEGIN
  --Florin 03.09.2025 - fixat 66537
  --Florin 04.07.2025 - sinc. Oracle
  --Florin 13.11.2023 - sinc. Oracle
  --Florin 24.10.2023 - sinc. Oracle
  --Florin 09.08.2023 - sinc. Oracle
  --Florin 12.05.2023 - corectie (sinc. 20.04.2023)
  --Gabi 02.05.2023 - optimizare sincronizare tmp_livr1-tmp_livrtot
  --Florin 20.04.2023 - sinc. Oracle
  --Stef 03.03.2023
  --Florin 11.01.2023 - sinc. Oracle
  --Florin 29.11.2022 - sinc. Oracle (28.11.2022)
  --Florin 24.11.2022 - sinc. Oracle
  --Florin 29.06.2022 - fnc_getprocenttvaart
  --Florin 22.06.2022 - sinc. Oracle
  --Florin 22.03.2022 - sinc. Oracle (21.03.2021)
  --Florin 11.03.2022 - fixat 53275/53470
  --Laura 27.01.2022 - sinc. Oracle (29.12.2021)
  --Florin 22.12.2021 - sinc. Oracle
  PERFORM pkg_service_EMPTY_DOCUMENTE_FOR_JURNAL();

  INSERT INTO TMP_IESIRI(CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC, RotEFact, NRDOC, DATADOC, PARTENER, CODSUBUNIT, CARNETAE, NRAE, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CONTDISCOUNT, ACCIZE, DELEGAT, AGENT, MAJORARI, OBS, AN, LUNA, CODFISCAL, SERIADOC, BUGETARE, CODLOCATIE, TIPFACTURA, CODGESTPROD, CONTINTERMED, NUMEDELEGAT, MONEDA, TIPCHELT, TipTVA,
    CODTVASERV, CODCONTTVAOSS,CURS, SUBUNITATEA, INFOCM, CONTSUPLIM, CUSTODIE, TVAIncasare, DataTVA, TIPTRANZACTIE, NOACCIZE, FLAGS)
  SELECT CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC, RotEFact, NRDOC, DATADOC, PARTENER, CODSUBUNIT, CARNETAE, NRAE, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CONTDISCOUNT, ACCIZE, DELEGAT, AGENT, MAJORARI, OBS, AN, LUNA, CODFISCAL, SERIADOC, BUGETARE, CODLOCATIE, TIPFACTURA, CODGESTPROD, CONTINTERMED, NUMEDELEGAT, MONEDA, TIPCHELT, TipTVA,
    CODTVASERV, CODCONTTVAOSS,CURS, SUBUNITATEA, INFOCM, CONTSUPLIM, CUSTODIE, TVAIncasare, DataTVA, TIPTRANZACTIE, NOACCIZE, FLAGS
  FROM (SELECT row_number() over()AS RN, S.*
        FROM (SELECT CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC, RotEFact, NRDOC, DATADOC, PARTENER,
                     CODSUBUNIT, CARNETAE, NRAE, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CONTDISCOUNT,
                     ACCIZE, DELEGAT, AGENT, MAJORARI, OBS, AN, LUNA, CODFISCAL, SERIADOC, BUGETARE, CODLOCATIE,
                     TIPFACTURA, CODGESTPROD, CONTINTERMED,
                     COALESCE( (SELECT SUBSTR( DELEGAT, 1, 50) FROM NPARTTR WHERE CODPARTTR = I.DELEGAT), '') AS NUMEDELEGAT,
                     I.MONEDA, I.TIPCHELT, I.TipTVA, I.CODTVASERV, tsr1.codcont as CODCONTTVAOSS,
                     I.CURS, I.SUBUNITATEA, I.INFOCM, I.CONTSUPLIM, I.CUSTODIE, I.TVAIncasare, I.DataTVA, I.TIPTRANZACTIE, i.NOACCIZE, i.FLAGS
              FROM IESIRI I
              LEFT JOIN tvaserv1 tsr1 on tsr1.codtvaserv = I.Codtvaserv
              and (i.an*12+i.luna) BETWEEN tsr1.ALSTART AND tsr1.ALSTOP
              WHERE AN * 12 + LUNA = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X)
                AND COALESCE(INFOCM, 0) = 0
                AND PKG_SERVICE_IS_DIRTY_DOC(I.TIPDOC, I.CODIES) = 1
              ORDER BY CODIES
             ) S
        ) A_PG
  WHERE
     RN &gt;= STARTREC AND  RN &lt;= ENDREC;

  UPDATE tmp_iesiri e
    set TotDiscOffInvoiceC = (SELECT Sum( COALESCE( d.Procent, 0)) FROM Iesdisc d where d.CodIes = e.CodIes and  d.OffInvoice = 2),
      TotDiscOffInvoiceF   = (SELECT Sum( COALESCE( d.Procent, 0)) FROM Iesdisc d WHERE d.CodIes = e.CodIes and  d.OffInvoice = 3);

  DELETE FROM IESIRI1_MAN;
  INSERT INTO IESIRI1_MAN
  SELECT * FROM IESIRI1 I1 WHERE EXISTS (SELECT * FROM TMP_IESIRI WHERE CODIES = I1.CODIES);

  INSERT INTO TMP_IESIRI1(CODIES1, CODIES, INDEXLOCAL, TIPLINIE, UMSEC, ValDiscPret, CodCentru, CONTSERV, GESTACT, CODOBIECT, PRETORIG, PU, CANT, TVA, CONT, PROCDISC, ADDIM, RESTFACT, PUMAXIMAL, GARANTIE, DENUM, VALOARE, PARITATE, PROCTVA, CODOBLIGSTORNO, CURSFACTURAAVANS, TipLivrare, CUSTODIEINTRARE, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2, CODCMDINT1, DENOBIECT, SIMBOLCONTSERV, CONTDISCOUNT, CODANALIZANOD, MIFIX, CODMIFIX, ICONTPART)
  SELECT *
  FROM (SELECT I1.CODIES1, I1.CODIES, I1.INDEXLOCAL, I1.TIPLINIE, I1.UMSEC, I1.ValDiscPret, i1.CodCentru, I1.CONTSERV,
               I1.GESTACT, I1.CODOBIECT, I1.PRETORIG, I1.PU * COALESCE( U1.PARITATE, 1),
               I1.CANT / COALESCE( U1.PARITATE, 1), I1.TVA, I1.CONT, I1.PROCDISC, I1.ADDIM, I1.RESTFACT,
               I1.PUMAXIMAL, I1.GARANTIE,
               CASE WHEN I1.TIPLINIE IN ('G', 'T') THEN '%' ELSE U1.DEN_UM1 END ,
               (CASE WHEN I1.TIPLINIE IN ('=', 'S', 'V') THEN I1.CANT * I1.PU ELSE I1.RESTFACT END) ,
               U1.PARITATE,
               CASE WHEN I1.TIPLINIE IN ('=', 'S', 'V') THEN fnc_getprocenttvaart(A.CODARTICOL, TG.ANLUCRU, TG.LUNALUCRU)
                    ELSE 0
               END ,
               I1.CODOBLIGSTORNO, I1.CURSFACTURAAVANS, I1.TipLivrare, I1.CUSTODIEINTRARE, NART1LUNA.CODTVA,
               NART1LUNA.CODACCIZE, NART1LUNA.CODTAXA1, NART1LUNA.CODTAXA2, I1.CODCMDINT1, O.DENUMIRE,
               CASE WHEN TIPLINIE IN ('G', 'T') AND  COALESCE( I1.CODOBIECT, 0) = 0 THEN '(' || C.SIMBOL || ')'
                    WHEN TIPLINIE IN ('S', 'V') THEN '(' || (SELECT PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT FROM PKG_PLANCONTURI_GETSIMBOLCONT(NULL, I1.CONTSERV)) || ')'
                    ELSE ''
               END ,
               I1.CONTDISCOUNT, I1.CODANALIZANOD, I1.MIFIX, I1.CODMIFIX, I1.ICONTPART
        FROM IESIRI1_MAN I1
          CROSS JOIN TMP_PKG_GLOBALS TG
      LEFT JOIN NARTOBJ O         ON  O.CODOBIECT = I1.CODOBIECT
      LEFT JOIN NART    A         ON  A.CODARTICOL = O.CODARTICOL
          LEFT JOIN NART1   NART1LUNA ON  NART1LUNA.CODARTICOL = O.CODARTICOL AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP
          LEFT JOIN NUM1    U1        ON  U1.CODUM1 = I1.UMSEC
          LEFT JOIN NCONT   C         ON  C.CODCONT = I1.CONTDISCOUNT
      ) B_PG
  ORDER BY CODIES , INDEXLOCAL ;

  UPDATE TMP_IESIRI1 I1
  SET
  NRDOCLINK = (SELECT COALESCE(II.PREFIXDOC, '') || COALESCE(II.NRDOC::varchar, '')
               FROM IESLINK IL
                    LEFT JOIN IESIRI1 II1 ON  II1.CODIES1 = IL.CODLINIEAVIZ
                    LEFT JOIN IESIRI II ON  II.CODIES = II1.CODIES
               WHERE IL.CODIES1 = I1.CODIES1
              )
  WHERE I1.TIPLINIE IN ('S', '=') AND  COALESCE( (SELECT TIPDOC FROM TMP_IESIRI WHERE CODIES = I1.CODIES), 0) = 26;

  UPDATE TMP_IESIRI1 I1 SET VALOARE = Round(Valoare, 2)
    WHERE  COALESCE((SELECT ROTEFACT FROM TMP_IESIRI WHERE CODIES = I1.CODIES), 0) = 1;

  INSERT INTO TMP_IESLINK (CODIES1, CODLINIEAVIZ, CANT, MONEDAAVIZ, CURSAVIZ, PRETAVIZ, CANTAVIZ, TVAAVIZ, CUSTODIE, DATAAVIZ, SUBUNITAVIZ, PROCDISCAVIZ, FLAGS)
  (
    SELECT L.CODIES1, L.CODLINIEAVIZ, L.CANT, IA.MONEDA, COALESCE( GREG.CURS, G.CURS), I1A.PU, I1A.CANT, I1A.TVA, IA.CUSTODIE, IA.DATADOC, IA.SUBUNITATEA, I1A.PROCDISC, IA.FLAGS
    FROM TMP_IESIRI1 I1, TMP_IESIRI I, IESLINK L, IESIRI1 I1A, IESIRI IA
         LEFT JOIN general G ON G.TIPDOC = 20 AND G.CODDOC = IA.CODIES
             and G.CODGENERAL = (select MAX(CODGENERAL) from general where Tipdoc = 20 and coddoc = IA.CODIES)
         LEFT JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON  GREG.CODGENERAL = G.CODGENERAL
    WHERE
       I1.CODIES1 = L.CODIES1
       AND  I.CODIES = I1.CODIES
       AND  I.TIPDOC = 26
       AND  L.CODLINIEAVIZ = I1A.CODIES1
       AND  IA.CODIES = I1A.CODIES
  );

  INSERT INTO TMP_LIVR(CODLIVR, CODIES, CODINTR, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT)
  (
   SELECT CODLIVR, CODIES, CODINTR, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT
   FROM LIVR L
   WHERE EXISTS (SELECT * FROM TMP_IESIRI WHERE CODIES = L.CODIES)
  );

  INSERT INTO TMP_LIVR1(CODLIVR1, CODLIVR, CODIES1, CODNIRSTOC, CANT, CODNIRSER, PMP, UMSEC, DENUM, PARITATE, GEST, CODIOART, CONTINTERMED, CODPROIECT, CODOBIECT, DENOBIECT, CODLIVRTOT, TIPLINIE, PRETINREG, ADAOS, TVANEEX, PRETACHIZ, TIPSERIE, CODSERIE, SERIE, PROVIZION)
  (
   SELECT L1.CODLIVR1, L1.CODLIVR, L1.CODIES1, L1.CODNIRSTOC, L1.CANT / U1.PARITATE, L1.CODNIRSER, L1.PMP,
          L1.UMSEC, U1.DEN_UM1, U1.PARITATE,
          CASE WHEN LV.CODLIVR1 IS NULL  THEN N.GEST ELSE LV.GEST END ,
          CASE WHEN LV.CODLIVR1 IS NULL  THEN NS.CODIOART ELSE LV.CODIOART END ,
          COALESCE( L1.CONTINTERMED, 0), COALESCE( L1.CODPROIECT, 0),
          CASE WHEN LV.CODLIVR1 IS NULL  THEN NS.CODOBIECT ELSE LV.CODOBIECT END ,
          CASE WHEN LV.CODLIVR1 IS NULL  THEN (SELECT PKG_SELECTARTICOLE_GETDENOBIECTEXT.WME_RESULT FROM PKG_SELECTARTICOLE_GETDENOBIECTEXT(NULL, NS.CODOBIECT))
               ELSE (SELECT PKG_SELECTARTICOLE_GETDENOBIECTEXT.WME_RESULT FROM PKG_SELECTARTICOLE_GETDENOBIECTEXT(NULL, LV.CODOBIECT))
          END ,
          0, '=',
          CASE WHEN LV.CODLIVR1 IS NULL  THEN NS.PRET * U1.PARITATE ELSE LV.PRETINREG * U1.PARITATE END ,
          CASE WHEN LV.CODLIVR1 IS NULL  THEN NS.ADAOS * U1.PARITATE ELSE (  LV.PRETINREG - LV.PRETACHIZ)  * U1.PARITATE END ,
          CASE WHEN LV.CODLIVR1 IS NULL  THEN NS.TVA ELSE LV.TVANEEX END ,
          CASE WHEN LV.CODLIVR1 IS NULL  THEN (  NS.PRET - COALESCE( NS.ADAOS, 0))  * U1.PARITATE
               ELSE LV.PRETACHIZ * U1.PARITATE
          END ,
          CASE WHEN LV.CODLIVR1 IS NULL  THEN NS.TIPSERIE ELSE 0 END ,
          (SELECT CODSERIE FROM NIRSER WHERE CODNIRSER = L1.CODNIRSER),
          (SELECT SERIE FROM NSERII WHERE CODSERIE = (SELECT CODSERIE FROM NIRSER WHERE CODNIRSER = L1.CODNIRSER)),
          NS.PROVIZION
   FROM LIVR1 L1
        LEFT JOIN NIRSTOC NS ON  NS.CODNIRSTOC = L1.CODNIRSTOC
        LEFT JOIN LIVRVAL LV ON  LV.CODLIVR1   = L1.CODLIVR1
        LEFT JOIN NIR     N  ON  N.CODNIR      = NS.CODNIR
        LEFT JOIN LIVR    L  ON  L.CODLIVR     = L1.CODLIVR, NUM1 U1
   WHERE
     EXISTS ( SELECT * FROM TMP_IESIRI where   CODIES = L.CODIES ) AND  U1.CODUM1 = L1.UMSEC
  );

  INSERT INTO TMP_LIVRTOT (CODLIVRTOT, CODLIVR, CODIESINT1, UMSEC, GEST, CODIOART, CONTINTERMED, CODPROIECT, CODOBIECT, DENUM, PARITATE, DIFPRET, ARETVANEEX, MG, CONT, PROCTVA, CANT, PRETINREG, PRETACHIZ)
    SELECT row_number() over(), CODLIVR, CODIESINT1, UMSEC, GEST, CODIOART, CONTINTERMED, CODPROIECT, CODOBIECT, DENUM, PARITATE, DIFPRET, ARETVANEEX, MG, CONT, PROCTVA, CANT, PRETINREG, PRETACHIZ
    FROM (
        SELECT  L1.CODLIVR as CODLIVR,
            L1.CODIES1 as CODIESINT1,
            L1.UMSEC as UMSEC,
            L1.GEST as GEST,
            L1.CODIOART as CODIOART,
            COALESCE( L1.CONTINTERMED, 0) as CONTINTERMED,
            COALESCE( L1.CODPROIECT, 0) as CODPROIECT,
            L1.CODOBIECT as CODOBIECT,
            L1.DENUM as DENUM,
            L1.PARITATE as PARITATE,
            IOALUNA.DIFPRET as DIFPRET,
            IOALUNA.ARETVANEEX as ARETVANEEX,
            IOALUNA.MG as MG,
            IOALUNA.CONT as CONT,
            NTVALUNA.PROCENT as PROCTVA,
            SUM( L1.CANT) as CANT,
            SUM( L1.PRETINREG * L1.CANT) / CASE WHEN  SUM( L1.CANT)=0 THEN 1 ELSE  SUM( L1.CANT) END as PRETINREG,
            SUM( L1.PRETACHIZ * L1.CANT) / case WHEN  SUM( L1.CANT)=0 THEN 1 ELSE  SUM( L1.CANT) END as PRETACHIZ
        FROM TMP_LIVR1 L1
          CROSS JOIN TMP_PKG_GLOBALS TG
          LEFT  JOIN NARTOBJ  O       ON  O.CODOBIECT  = L1.CODOBIECT
          LEFT  JOIN NART     A       ON  A.CODARTICOL = O.CODARTICOL
          LEFT  JOIN IOART1   IOALUNA   ON  IOALUNA.CODIOART = L1.CODIOART AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN IOALUNA.ALSTART AND IOALUNA.ALSTOP
          LEFT  JOIN NGEST    G        ON  G.CODGEST = L1.GEST
          LEFT  JOIN IOART    IO       ON  IO.CODIOART = L1.CODIOART
          LEFT  JOIN NART1    NART1LUNA   ON  NART1LUNA.CODARTICOL = O.CODARTICOL AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP
          LEFT  JOIN NTVA1    NTVALUNA    ON  NTVALUNA.CODTVA = NART1LUNA.CODTVA AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN NTVALUNA.ALSTART AND NTVALUNA.ALSTOP
      GROUP BY
        L1.CODLIVR, L1.CODIES1, L1.CODOBIECT, L1.UMSEC, L1.GEST, L1.CODIOART, COALESCE( L1.CONTINTERMED, 0), COALESCE( L1.CODPROIECT, 0), L1.DENUM, L1.PARITATE, IOALUNA.DIFPRET, IOALUNA.ARETVANEEX, IOALUNA.MG, IOALUNA.CONT, NTVALUNA.PROCENT
     ) C_PG
     ORDER BY CODLIVR , CODIESINT1 ;


/*
   FOR LT IN ( SELECT * FROM TMP_LIVRTOT LT) LOOP
    UPDATE  TMP_LIVR1 L1
    SET CODLIVRTOT = LT.CODLIVRTOT
    WHERE
      COALESCE( LT.CODLIVR, 0)           = COALESCE( L1.CODLIVR, 0)
      AND  COALESCE( LT.CODIESINT1, 0)   = COALESCE( L1.CODIES1, 0)
      AND  COALESCE( LT.UMSEC, 0)        = COALESCE( L1.UMSEC, 0)
      AND  COALESCE( LT.PARITATE, 0)     = COALESCE( L1.PARITATE, 0)
      AND  COALESCE( LT.GEST, 0)         = COALESCE( L1.GEST, 0)
      AND  COALESCE( LT.CODIOART, 0)     = COALESCE( L1.CODIOART, 0)
      AND  COALESCE( LT.CONTINTERMED, 0) = COALESCE( L1.CONTINTERMED, 0)
      AND  COALESCE( LT.CODPROIECT, 0)   = COALESCE( L1.CODPROIECT, 0);
  END LOOP;
*/



for v_lt in
(
select l1.CODLIVR1, LT.codlivrtot from tmp_livr1 l1
inner join tmp_livrtot lt
on
      COALESCE( LT.CODLIVR, 0)           = COALESCE( L1.CODLIVR, 0)
      AND  COALESCE( LT.CODIESINT1, 0)   = COALESCE( L1.CODIES1, 0)
      AND  COALESCE( LT.UMSEC, 0)        = COALESCE( L1.UMSEC, 0)
      AND  COALESCE( LT.PARITATE, 0)     = COALESCE( L1.PARITATE, 0)
      AND  COALESCE( LT.GEST, 0)         = COALESCE( L1.GEST, 0)
      AND  COALESCE( LT.CODIOART, 0)     = COALESCE( L1.CODIOART, 0)
      AND  COALESCE( LT.CONTINTERMED, 0) = COALESCE( L1.CONTINTERMED, 0)
      AND  COALESCE( LT.CODPROIECT, 0)   = COALESCE( L1.CODPROIECT, 0)
 )
 loop
  update tmp_livr1 -- musai index pe tmp_livr1.codlivr1 altfel merge greu
  set
   codlivrtot = v_lt.codlivrtot
  where
    codlivr1 = v_lt.codlivr1;
 end loop;



  INSERT INTO TMP_NIR(CODNIR, CODINTR, CODIES, DATANIR, GEST, TIPNIR, ANULAT, BLOCAT, OPERAT)
  SELECT CODNIR, CODINTR, CODIES, DATANIR, GEST, TIPNIR, ANULAT, BLOCAT, OPERAT
  FROM NIR N
  WHERE EXISTS (SELECT * FROM TMP_IESIRI WHERE CODIES = N.CODIES AND  TIPDOC = N.TIPNIR);

  INSERT INTO TMP_NIRSTOC(CODNIRSTOC, CODNIR, CODINTR1, CANTNIR, REST, UMSEC, CODOBIECT, CODIOART, PRET, ADAOS, TVA, TIPSERIE)
  SELECT CODNIRSTOC, CODNIR, CODINTR1, CANTNIR, REST, UMSEC, CODOBIECT, CODIOART, PRET, ADAOS, TVA, TIPSERIE
  FROM NIRSTOC NS
  WHERE CODNIR IN (SELECT CODNIR FROM TMP_NIR);

  FOR V_REC IN
  (
  SELECT Y.*, X.AnLucru ANX, X.LunaLucru LUNAX
  FROM TMP_IESIRI Y, TMP_PKG_GLOBALS X
  WHERE
    Y.TIPDOC IN (19, 20, 21, 22, 26)
  )
  LOOP
    SELECT COUNT( *) INTO NR FROM TMP_IOPARTDOC WHERE CODPART = V_REC.PARTENER;

    IF  NR = 0 THEN
      LUNAREF := (SELECT PKG_NOMPART_GET_RECORD_PART_CARACT_LUNA.WME_RESULT FROM PKG_NOMPART_GET_RECORD_PART_CARACT_LUNA(NULL, V_REC.PARTENER, V_REC.AnX, V_REC.LunaX));
      LOOP
        FETCH LUNAREF INTO IOPART1REC;
        EXIT  WHEN not found;
        IF  IOPART1REC.CODIOPART1 &gt; 0 THEN
          INSERT INTO TMP_IOPARTDOC(CODPART, CODIOPART1, CODIOPART, CONTFURNIZOR, CONTCLIENT, CONTFURNAVANS, CONTCLIENTAVANS, CONTFURNAVIZ, CONTCLIENTAVIZ, CONTFURNMF, CONTCREDITD, CONTDEBITD, CONTLITIGII, CONTFURNAVS, CONTFURNAVIC, CONTFURNAVIN, contgarantieEF, contgarantieTF, contgarantieEC, contgarantieTC, CONTTERTI, TvaNeexF, TvaNeexP, TvaNeexI, TVANEEXC, TIP)
          VALUES(V_REC.PARTENER, IOPART1REC.CODIOPART1, IOPART1REC.CODIOPART, IOPART1REC.CONTFURNIZOR, IOPART1REC.CONTCLIENT, IOPART1REC.CONTFURNAVANS, IOPART1REC.CONTCLIENTAVANS, IOPART1REC.CONTFURNAVIZ, IOPART1REC.CONTCLIENTAVIZ, IOPART1REC.CONTFURNMF, IOPART1REC.CONTCREDITD, IOPART1REC.CONTDEBITD, IOPART1REC.CONTLITIGII, IOPART1REC.CONTFURNAVS, IOPART1REC.CONTFURNAVIC, IOPART1REC.CONTFURNAVIN, IOPART1REC.contgarantieEF, IOPART1REC.contgarantieTF, IOPART1REC.contgarantieEC, IOPART1REC.contgarantieTC, IOPART1REC.CONTTERTI, IOPART1REC.TvaNeexF, IOPART1REC.TvaNeexP, IOPART1REC.TvaNeexI, IOPART1REC.TVANEEXC, IOPART1REC.TIP);
        END IF;
      END LOOP;
    END IF;
  END LOOP;

  INSERT INTO TMP_MODURIPLATI(CODMODPLATA, CODIES, TIPPLATA, CODBANKCONT, VALOARE, DENMODPLATA)
  SELECT * FROM MODURIPLATI WHERE CODIES IN (SELECT CODIES FROM TMP_IESIRI);

  INSERT INTO TMP_DISCMONETAR(CODDISCMONETAR, CODIES, PROCTVA, DISCOUNT, TVADISCOUNT)
  SELECT CODDISCMONETAR, CODIES, PROCTVA, DISCOUNT, TVADISCOUNT
  FROM DISCMONETAR WHERE CODIES IN (SELECT CODIES FROM TMP_IESIRI);

  INSERT INTO TMP_IESDISC (CODIESDISC, CODIES, CODDISCOUNT, OFFINVOICE, PROCENT, CODOBIECT, Valoare, Cumulat)
  SELECT I.*, C.Cumulat FROM IESDISC I,  Discount D, CriteriiDisc C
  WHERE CODIES IN (SELECT CODIES FROM TMP_IESIRI)
  and D.CodDiscount = I.CodDiscount and D.CODCRITERIU = C.CODCRITERIU;

  DELETE FROM TMP_GENERAL;
  INSERT INTO TMP_GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS)
  (
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS
  FROM GENERAL G
  WHERE EXISTS (SELECT CODIES FROM TMP_IESIRI WHERE CODIES = G.CODDOC AND  TIPDOC = G.TIPDOC)
  );

  DELETE FROM TMP_OBLIGPIF;
  INSERT INTO TMP_OBLIGPIF(CODOBLIGPIF, CODGENERAL)
  (
  SELECT CODOBLIGPIF, CODGENERAL
  FROM OBLIGPIF
  WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL)
  );

  DELETE FROM TMP_STINGERE;
  INSERT INTO TMP_STINGERE(CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
  (
  SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE
  FROM STINGERE
  WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF)
  );

  FOR V_REC IN
  (
  SELECT S.CODSTINGERE, G.TIPDOC, G.CODDOC, G.SEMNIFICATIE
  FROM TMP_STINGERE S, OBLIGPIF O, GENERAL G
  WHERE
     S.CODSTINSPIF = O.CODOBLIGPIF AND  G.CODGENERAL = O.CODGENERAL
  )
  LOOP
    aCODSUBUNITSTINS := 0;
    IF V_REC.SEMNIFICATIE IN (210) THEN
      BEGIN
        SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM IESIRI WHERE CODIES = V_REC.CODDOC AND  TIPDOC = V_REC.TIPDOC;
      EXCEPTION WHEN OTHERS THEN
        aCODSUBUNITSTINS := 0;
      END;

      UPDATE TMP_STINGERE SET CODSUBUNITSTINS = aCODSUBUNITSTINS WHERE CODSTINGERE = V_REC.CODSTINGERE;
    END IF;
  END LOOP;

  FOR V_REC IN (SELECT CODIES1 FROM TMP_IESIRI1 I1, TMP_IESIRI I WHERE I.TIPDOC = 26 AND  I1.CODIES = I.CODIES)
  LOOP
    UPDATE TMP_IESIRI1 I1
    set CUSTODIE = (SELECT CUSTODIE FROM TMP_IESLINK IL WHERE  IL.CODIES1 = I1.CODIES1 limit 1)
    WHERE
     CODIES1 = V_REC.CODIES1;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_reg_for_jurnal</obj_name>
  <obj_hashval>3ce4754da3ec54048e8690f612a1cae4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_reg_for_jurnal(startrec numeric, endrec numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC_MARE RECORD;
  V_REG1CONT RECORD;
  V_REC      RECORD;
  REG1CONT_IDX_LOCAL numeric(10) := 0;
  REG1_IDX_LOCAL     NUMERIC(20);
  PARAM_REG_DATA     date;
  PARAM_REG_MONEDA   NUMERIC(20);
  PARAM_REG_CURS     NUMERIC(20,7);
  DIFERENTE          numeric(1) := 0;
  DATANEXTREG        date;
  CODNEXTREG         NUMERIC(20);
BEGIN
  --Stef 03.03.2023
  --Florin 07.02.2023 - sinc. Oracle
  --Florin 17.08.2022 - sinc. Oracle
  --Bogdan 20.08.2020
  PERFORM pkg_service_EMPTY_DOCUMENTE_FOR_REG();
  DELETE FROM TMP_REG;
  INSERT INTO TMP_REG(
      CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, CURS_IFRS,
      Dirty, Obs, CodSubunit, SimbolMoneda, SimbolBank, Provizion, An,
      Luna, CODGEST, CodCentru, CodAnalizaNod)
  SELECT CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, CURS_IFRS,
      Dirty, Obs, CodSubunit, SimbolMoneda, SimbolBank, Provizion,
      An, Luna, CODGEST, CodCentru, CodAnalizaNod
  FROM (
      SELECT row_number() over() RN,
        R.CodReg, R.TipReg, R.NrDoc, R.DataDoc, R.CodBank, R.CodMoneda, R.Curs,
        R.CURS_IFRS, R.Dirty, R.Obs, R.CodSubunit, M.Simbol AS SIMBOLMONEDA,
        B.Simbol AS SIMBOLBANK, R.Provizion, R.An, R.Luna, R.CODGEST,
        R.CodCentru, R.CodAnalizaNod
      FROM REG R
        LEFT JOIN NMONEDE M ON  M.CODMONEDA = R.CODMONEDA
        LEFT JOIN NBANK B ON  B.CODBANK = R.CODBANK
      where
        TIPREG = 46 AND  AN * 12 + LUNA = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X)
        AND PKG_SERVICE_IS_DIRTY_DOC(46, R.CODREG) = 1
    ) A_PG
  WHERE
       RN &gt;= STARTREC AND  RN &lt;= ENDREC;

  DELETE FROM TMP_REG1;

  FOR V_REC_MARE in (SELECT * FROM TMP_REG)  LOOP
      DELETE FROM TMP_REG1CONT_MARTOR;
      REG1CONT_IDX_LOCAL := 0;

      FOR V_REG1CONT IN (
        SELECT SUM(SoldDoc) AS SOLDDOC, SUM(SoldDocVal) AS SOLDDOCVAL,
               SUM(SoldDocReg) AS SOLDDOCREG, SUM( (SoldDocReg) - (SoldDocVal) ) AS DIFERENTA, Cont
        FROM REG1 R1
        WHERE R1.CODREG = V_REC_MARE.CODREG
        GROUP BY Cont
      ) LOOP
          REG1CONT_IDX_LOCAL := REG1CONT_IDX_LOCAL + 1;
          INSERT INTO TMP_REG1CONT_MARTOR (CodReg1Cont, SoldDoc, SoldDocVal, SoldDocReg, Diferenta, Cont)
          values (
            -1 * REG1CONT_IDX_LOCAL, V_REG1CONT.SoldDoc, V_REG1CONT.SoldDocVal,
            V_REG1CONT.SoldDocReg, V_REG1CONT.Diferenta, V_REG1CONT.Cont);
      END LOOP;

      SELECT V_REC_MARE.DataDoc, V_REC_MARE.CodMoneda, V_REC_MARE.Curs
      INTO PARAM_REG_DATA, PARAM_REG_MONEDA, PARAM_REG_CURS;
      PERFORM PKG_REG_SetParamsReg( TO_CHAR( PARAM_REG_DATA, 'DD.MM.YYYY'), PARAM_REG_MONEDA, PARAM_REG_CURS::NUMERIC);
      REG1_IDX_LOCAL := 0;

      PERFORM PKG_REGPART_MAKE_REGPART_LUNA();

      FOR V_REC in (SELECT RP.*, P.DEN_PART FROM TMP_REGPART_LUNA RP LEFT JOIN NPART P ON  P.CODPART = RP.CODPART)
      LOOP
        IF  ABS( V_REC.SoldDoc * TO_NUMBER((current_setting('PKG_REG.CURS_REG', true)),'99999999999.9999999') - V_REC.SoldDocVal) &gt; 0.0000001 THEN
          REG1_IDX_LOCAL := REG1_IDX_LOCAL + 1;
          INSERT INTO TMP_REG1 (
                CODREG, CodReg1, CodGeneral, Cont, PrefixDoc, NrDoc, DataDoc, CodPart, DenPart,
                SimbolCont, SoldDocVal, SoldDoc, SoldDocReg, Diferenta, Document, CodGest, Semn,
                Curs, Semnificatie, CoefProvizion, SUBUNITATEA, CODOBLIGPIF)
          values (
              V_REC_MARE.CODREG, -1 * REG1_IDX_LOCAL, V_REC.CodGeneral, V_REC.ICONT, V_REC.PrefixDoc,
              V_REC.NrDoc, V_REC.DataDoc, V_REC.CodPart, V_REC.Den_Part,
              (SELECT PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT
               FROM PKG_PLANCONTURI_GETSIMBOLCONT(NULL,
                      (SELECT PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG.WME_RESULT
                       FROM PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(NULL,
                                        V_REC.Semnificatie,
                                        V_REC.ICont,
                                        V_REC.CodIOPart1)))),
              V_REC.SoldDocVal, V_REC.SoldDoc,
              V_REC.SoldDoc * PARAM_REG_CURS,
              V_REC.SoldDoc * PARAM_REG_CURS - V_REC.SoldDocVal,
              V_REC.PREFIXDOC || TO_CHAR( V_REC.NRDOC,'9999999999') || '/' || TO_CHAR( V_REC.DATADOC, 'DD.MM.YYYY'),
              V_REC.CodGest, 1, V_REC.Curs, V_REC.Semnificatie,
              V_REC.CoefProvizion, V_REC.SUBUNITATEA, V_REC.CODOBLIGPIF);
        END IF;
      END LOOP;
    END LOOP;

    FOR V_REC in (
        SELECT R1.CODREG1, R1.CODREG, O.CONTBANKTRANZACTIE, O.SEMNIFICATIE, T1.TIPDECONT, X.LUNALUCRU, X.ANLUCRU
        FROM TMP_PKG_GLOBALS X, TMP_REG1 R1, OBLIGPIF O, GENERAL G, TREZOR1 T1
        WHERE
             R1.CODOBLIGPIF = O.CODOBLIGPIF
                 AND O.SEMNIFICATIE IN (500, 600)
                 AND  G.CODGENERAL = O.CODGENERAL
                 AND  T1.CODTREZOR1 = G.CODDOC
      )
    LOOP
      UPDATE TMP_REG1
      SET
        CONT = (SELECT PKG_TREZOR_CODCONTCEC.WME_RESULT
                FROM PKG_TREZOR_CODCONTCEC(NULL,
                              V_REC.CONTBANKTRANZACTIE,
                              V_REC.SEMNIFICATIE,
                              V_REC.TIPDECONT,
                              V_REC.OBIECTTRANZ,
                              V_REC.AnLucru,
                              V_REC.LunaLUCRU,
                              NULL))
      where
        CODREG1 = V_REC.CODREG1 AND  CODREG = V_REC.CODREG;
    END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_regpers_for_jurnal</obj_name>
  <obj_hashval>c27f95dabf086c2f51422aae76d3df67</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_regpers_for_jurnal(startrec numeric, endrec numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC      RECORD;
  V_REC_MARE RECORD;
  REG1CONT_IDX_LOCAL numeric(10) := 0;
  REG1_IDX_LOCAL     NUMERIC(20);
  PARAM_REG_DATA     date;
  PARAM_REG_MONEDA   NUMERIC(20);
  PARAM_REG_CURS     NUMERIC(20,7);
  DIFERENTE          numeric(1) := 0;
  DATANEXTREG        date;
  CODNEXTREG         NUMERIC(20);
  AnPrecedentReg     NUMERIC(20);
  LunaPrecedentaReg  NUMERIC(20);
  ATIPCONT           numeric(5) := 0;
  ASEMN              numeric(2) := 1;
BEGIN
  --Stef 03.03.2023
  --Florin 17.08.2022 - sinc. Oracle
  --Bogdan 18.08.2020
  PERFORM pkg_service_EMPTY_DOCUMENTE_FOR_REGPERS();
  DELETE FROM TMP_REG;

  INSERT INTO TMP_REG (
      CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda,
      Curs, Dirty, Obs, CodSubunit, SimbolMoneda, SimbolBank,
      Provizion, Luna, An, CODGEST, CodCentru, CodAnalizaNod)
  SELECT CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs,
    Dirty, Obs, CodSubunit, SimbolMoneda, SimbolBAnk, Provizion,
    Luna, An, CODGEST, CodCentru, CodAnalizaNod
  FROM (
    SELECT row_number() over() RN,
      R.CodReg, R.TipReg, R.NrDoc, R.DataDoc, R.CodBank, R.CodMoneda,
      R.Curs, R.Dirty, R.Obs, R.CodSubunit, M.Simbol SIMBOLMONEDA, B.Simbol SIMBOLBANK,
      R.Provizion, R.Luna, R.An, R.CODGEST, R.CodCentru, R.CodAnalizaNod
    FROM TMP_PKG_GLOBALS X, REG R
      LEFT JOIN NMONEDE M ON  M.CODMONEDA = R.CODMONEDA
      LEFT JOIN NBANK   B ON  B.CODBANK   = R.CODBANK
    WHERE
       TIPREG = 47
       AND  AN = X.ANLUCRU
       AND  LUNA = X.LUNALUCRU
       AND PKG_SERVICE_IS_DIRTY_DOC(47, R.CODREG) = 1
    ) A_PG
  WHERE  RN &gt;= STARTREC AND  RN &lt;= ENDREC;

  DELETE FROM TMP_REGPERS1;
  DELETE FROM TMP_SOLDPERS_SUB;
  INSERT INTO TMP_SOLDPERS_SUB (CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, SUBUNITATEA )
  SELECT CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, SUBUNITATEA
  FROM V_SOLDPERS_TRANZACTII_SUB;

  FOR V_REC IN (SELECT * FROM TMP_SOLDPERS_SUB S, TMP_PKG_GLOBALS X) LOOP
    BEGIN
      SELECT COALESCE( TIPCONT, 0)
      INTO ATIPCONT
      FROM NCONT
      WHERE
         CODCONT = (SELECT PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG.WME_RESULT
                    FROM PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(NULL,
                                      1100,
                                      V_REC.ICONT,
                                      (SELECT PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA.WME_RESULT
                                       FROM PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA(NULL,
                                                          V_REC.CODPERS,
                                                          V_REC.ANLUCRU,
                                                          V_REC.LUNALUCRU))));
      EXCEPTION WHEN OTHERS THEN
        aTIPCONT := 0;
    END;

    IF  COALESCE( aTIPCONT, 0) = 1 THEN
      aSEMN := -1;
    ELSE
      aSEMN := 1;
    END IF;

    UPDATE TMP_SOLDPERS_SUB
    set SEMN = aSEMN
    WHERE
       CODPERS = V_REC.CODPERS AND  CODMONEDA = V_REC.CODMONEDA AND  ICONT = V_REC.ICONT;
  END LOOP;

  FOR V_REC_MARE IN (SELECT * FROM TMP_REG) LOOP
    DELETE FROM TMP_REGPERS1_MARTOR;
    INSERT INTO TMP_REGPERS1_MARTOR (CODPERS, SOLDDOCVAL, ICONT)
    SELECT CODPERS, SOLDDOCVAL, ICONT FROM REGPERS1 WHERE CODREG = V_REC_MARE.CODREG;

    SELECT V_REC_MARE.DataDoc, V_REC_MARE.CodMoneda, V_REC_MARE.Curs
    INTO PARAM_REG_DATA, PARAM_REG_MONEDA, PARAM_REG_CURS;

    PERFORM PKG_REG_SetParamsReg( TO_CHAR( PARAM_REG_DATA, 'DD.MM.YYYY'), PARAM_REG_MONEDA, PARAM_REG_CURS::NUMERIC);
    PERFORM PKG_GLOBALS_SETLUNATEMP(getAnLucru(), getLunaLucru());
    select  PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA.newan, PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA.newluna
      from PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( getAnLucru(), getLunaLucru(), AnPrecedentReg, LunaPrecedentaReg)
            into AnPrecedentReg, LunaPrecedentaReg;
    PERFORM PKG_GLOBALS_SETLUNAPRECEDENTA( AnPrecedentReg, LunaPrecedentaReg);

    INSERT INTO TMP_REGPERS1 (
      CodRegPers1, CODREG, SoldDoc, SoldDocVal, SoldDocReg,
      CodPers, CodCont, ICONT, SUBUNITATEA, Diferenta, Den_Pers, Den_Cont)
    SELECT -1 * row_number() over(),
          V_REC_MARE.CODREG,
          SOLDVALUTA,
          SOLDLEI,
          SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(NULL,NULL)),
          CodPers, CodCont, ICONT, SUBUNITATEA,
          SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(NULL,NULL)) - SoldLei, Prenume || ' ' || Nume,
          Den_Cont
    FROM (
      SELECT T1.CODPERS, SOLDVALUTA, SOLDLEI, NUME, ICONT, SUBUNITATEA, PRENUME,
        (SELECT PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT
         FROM PKG_PLANCONTURI_GETSIMBOLCONT(NULL,
                            (SELECT PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG.WME_RESULT
                             FROM PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(NULL,
                                                  1100,
                                                  ICONT,
                                                  (SELECT PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA.WME_RESULT
                                                    FROM PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA(NULL, T1.CODPERS, X.ANLUCRU, X.LUNALUCRU)))))) AS DEN_CONT,
        (SELECT PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG.WME_RESULT
         FROM PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(NULL,
                              1100,
                              ICONT,
                              (SELECT PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA.WME_RESULT
                                FROM PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA(NULL, T1.CODPERS, X.ANLUCRU, X.LUNALUCRU)))) AS CODCONT
      FROM TMP_PKG_GLOBALS X,
        (SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SUM( SOLDLEI) SOLDLEI, SUM( SOLDVALUTA) SOLDVALUTA
          FROM (
              SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA,
                COALESCE( SOLDLEI, 0) * COALESCE( SEMN, 1) SOLDLEI,
                COALESCE( SOLDVALUTA, 0) * COALESCE( SEMN, 1) SOLDVALUTA
              FROM TMP_SOLDPERS_SUB
              union ALL
              SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
              FROM V_SOLDPERS_PREC_SUB
            ) B_PG
        GROUP BY
            CODPERS, ICONT, CODMONEDA, SUBUNITATEA
        ) T1, NPERS NP
      WHERE
         NP.CodPers = T1.CodPers
         AND  CODMONEDA = pkg_reg_getmonedareg()
         AND  T1.SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(NULL,NULL)) - T1.SoldLei &lt;&gt; 0
    ) C_PG;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_settask_check_struct_extensie</obj_name>
  <obj_hashval>09804a1a0f1f2a747f0992cfe584a470</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_settask_check_struct_extensie(codskema numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  V_REC RECORD;
  NR    numeric := 0;
  DT    varchar;
  SIR   varchar;
  VG    varchar;
  NR1   numeric := 0;
  SKEMA varchar;

  vTaskFirma NUMERIC;
  sFIRMANAME varchar;
BEGIN
  --Stef   24.03.2022 - CREATE TEMPORARY (scosGLOBAL fiindca e obsolete si apare/incurca in loguri de BD)
  --Adina 02.06.2021 - scos upper; add sFIRMANAME
  --STEF   04.01.2021
  --Florin 12.11.2020 - fixat #41670
  sFIRMANAME := lower(current_setting('PKG_GLOBALS.FIRMANAME', true));

 /*
  BEGIN
    SELECT SKEMAFIRMA
    INTO STRICT SKEMA
    FROM winmadmin.FIRMA
    WHERE CODFIRMA = CODSKEMA;
  EXCEPTION
    WHEN OTHERS THEN
      SKEMA := '?';
  END;


  IF WINMADMIN.PKG_SETTASK_ObjExists ('SETTASKEXT', 'TABLE', SKEMA) = 0 THEN
    EXECUTE 'CREATE TABLE '||SKEMA||'.SETTASKEXT(CODSETTASKEXT NUMERIC, CODTASK NUMERIC) ';
    PERFORM WINMADMIN.PKG_SETTASK_SETGRANTMODUL ('SETTASKEXT', SKEMA);
  END IF;
  IF WINMADMIN.PKG_SETTASK_ObjExists ('SEQ_SETTASKEXT_CODSETTASKEXT', 'SEQUENCE', SKEMA) = 0 THEN
    PERFORM WINMADMIN.PKG_SETTASK_REMAKE_SEQUENCE ('SETTASKEXT', 'CODSETTASKEXT', 'SEQ_SETTASKEXT_CODSETTASKEXT', SKEMA);
  END IF;


  IF (WINMADMIN.PKG_SETTASK_ObjExists ('TMP_SETTASKEXT', 'TABLE'. '') = 1 THEN
    NR1 := WINMADMIN.PKG_SETTASK_OBJEXISTS ('SETTASKEXT', 'TABLE', SKEMA);
    NR  := WINMADMIN.PKG_SETTASK_OBJEXISTS ('SETTASK',    'TABLE', SKEMA);
    IF NR1 &lt;&gt; NR THEN
      EXECUTE 'DROP TABLE TMP_SETTASKEXT';
      --&lt;sstunknown&gt;
    END IF;
  END IF;
  IF WINMADMIN.PKG_SETTASK_ObjExists ('TMP_SETTASKEXT', 'TABLE', '') = 0 THEN
    Sir := 'DO $$ BEGIN PERFORM '|| SKEMA|| '.PKG_SERVICE_CHECK_STRUCT_EXTENSIE_TASK(); END$$;';
    EXECUTE SIR;
  END IF;


  vTaskFirma  := Coalesce(fnc_getvalconstantalucru('TaskFirma'), '1')::numeric;

  BEGIN
    EXECUTE 'DROP TABLE TMP_SETTASKEXT';
  EXCEPTION
    WHEN OTHERS THEN NULL;
  END;

  SIR := '';
  --IF vTaskFirma = 2 THEN
    IF WINMADMIN.PKG_SETTASK_OBJEXISTS ('SETTASKEXT', 'TABLE', SKEMA) = 1 THEN
      SIR := 'CREATE TEMPORARY TABLE TMP_SETTASKEXT ON COMMIT PRESERVE ROWS AS SELECT * FROM '|| SKEMA||'.'||'SETTASKEXT WHERE 1=0';
    END IF;
  ELSE
    IF WINMADMIN.PKG_SETTASK_OBJEXISTS ('SETTASKEXT', 'TABLE', 'WINMADMIN') = 1 THEN
      SIR := 'CREATE TEMPORARY TABLE TMP_SETTASKEXT ON COMMIT PRESERVE ROWS AS SELECT * FROM WINMADMIN.SETTASKEXT WHERE 1=0';
    END IF;
  END IF;

  IF SIR = '' THEN
    SIR := 'CREATE TEMPORARY TABLE TMP_SETTASKEXT (CODSETTASKEXT NUMERIC, CODTASK NUMERIC) ON COMMIT PRESERVE ROWS';
  END IF;

  BEGIN
    EXECUTE SIR;
  EXCEPTION
    WHEN OTHERS THEN NULL;
  END;
  */
  if (fnc_TmpExists('SETTASKEXT')) = 0 then
    execute 'CREATE TABLE ' || (current_setting('PKG_GLOBALS.FIRMANAME',true)) || '.SETTASKEXT (CODSETTASKEXT NUMERIC(20), CODSETTASK NUMERIC(20) ) ';
    perform PKG_CFGTABLES_SETGRANTMODUL( 'SETTASKEXT',(current_setting('PKG_GLOBALS.FIRMANAME',true)));
  end if;

  select  count(*) into NR
  from pg_statio_all_sequences
  where relname = 'seq_settaskext_codsettaskext' AND schemaname = sFIRMANAME;

  if NR = 0 then
    perform PKG_REMAKE_SEQUENCES_REMAKE_SEQUENCE( 'SETTASKEXT','CODSETTASKEXT','SEQ_SETTASKEXT_CODSETTASKEXT');
  end if;

  if (fnc_TmpExists('TMP_SETTASKEXT')) = 1 then
    select  count(*) into  NR1
    from  information_schema.Columns
    where TABLE_NAME = 'settaskext' AND TABLE_SCHEMA = sFIRMANAME;

    select  count(*) into  NR
    from  information_schema.Columns
    where TABLE_NAME = 'tmp_settaskext' ;

    if NR1 &lt;&gt; NR then
      execute 'DROP TABLE TMP_SETTASKEXT';
    end if;
  end if;
--
  if (fnc_TmpExists('TMP_SETTASKEXT')) = 0 then
    Sir := 'CREATE TEMPORARY TABLE TMP_SETTASKEXT (';
    select  count(*) into  NR from  information_schema.Columns
    where TABLE_NAME = 'settaskext' AND TABLE_SCHEMA = sFIRMANAME;

    for V_REC in (select * from  information_schema.Columns
                  where TABLE_NAME = 'settaskext' AND TABLE_SCHEMA = sFIRMANAME
                  order BY ORDINAL_POSITION
                 )
    loop
      if V_REC.DATA_TYPE = 'character varying' then
        DT := ' VARCHAR(' || V_REC.CHARACTER_MAXIMUM_LENGTH::varchar || ') ';
      else
        if V_REC.DATA_TYPE = 'date' then
          DT := ' DATE ';
        else
          DT := ' NUMERIC(' || V_REC.NUMERIC_PRECISION::varchar || ',' || V_REC.NUMERIC_SCALE::varchar || ') ';
        end if;
      end if;

      if V_REC.ORDINAL_POSITION &lt; NR then
        VG := ', ';
      else
        VG := '';
      end if;

      DT  := DT || VG;
      SIR := SIR || ' ' || V_REC.COLUMN_NAME || ' ' || DT;
      --insert into x values('ss',sir);
    end loop;

    SIR := SIR || ' ) ON COMMIT PRESERVE ROWS';
    execute SIR;

    perform PKG_CFGTABLES_SETGRANTMODUL( 'TMP_SETTASKEXT',(current_setting('PKG_GLOBALS.FIRMANAME', true)));
  end if;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_settask_getcarnetdoc_i</obj_name>
  <obj_hashval>6bb3079a9c73d083cc240dbbb0745633</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_settask_getcarnetdoc_i(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SETTASK.CARNETDOC_I', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sgrcolect_sp_insertrecord</obj_name>
  <obj_hashval>0db4e9b77e8d914a2fd4529595c729ce</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sgrcolect_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 25.10.2024 -
  INSERT INTO  TMP_SGRCOLECT( CODSGRCOLECT ) VALUES (0) ;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settca</obj_name>
  <obj_hashval>f49eed463ffafe9783d09c738f3fd369</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settca(atca numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcA',to_char(atcA,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settcprecrulcumcuaj</obj_name>
  <obj_hashval>58dfb9c4fcc92f83be4f0b5a6e24d3b1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settcprecrulcumcuaj(atcprecrulcumcuaj numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcPrecRulCumCuAj',to_char(atcPrecRulCumCuAj,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_sp_postrecords</obj_name>
  <obj_hashval>437230251c4ab04e43dba719eb105c1e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  vcod  numeric(20);
BEGIN
  --Florin 01.08.2025 - sinc. Oracle
  --Adina 04.03.2021 - sinc.Oracle din 03.03.2021
  --Adina 12.02.2021 - modif.Oracle din 10.02.2021
  --Adina 21.12.2020 - sincronizare cu Oracle
  FOR v_rec IN (SELECT c.*, row_number() over(order by c.nrcol) NEWNR  FROM tmp_sitfincol c)
  LOOP
    UPDATE tmp_sitfincol SET nrcol = v_rec.newnr WHERE codcoloana = v_rec.codcoloana;
  END LOOP;

  IF  Operation = 0 THEN
    SELECT CodSitFin INTO RecId FROM TMP_SITFIN;

    UPDATE SITFIN
    SET (CodF, Denumire, Sectiune, Tip, TipPlan, PeLuni) = (SELECT CodF, Denumire, Sectiune, Tip, TipPlan, PeLuni FROM TMP_SITFIN)
    WHERE CodSitFin = RecId;

    DELETE FROM SITFINCOL WHERE CodSitFin = RecId AND CodColoana NOT IN (SELECT CodColoana FROM TMP_SITFINCOL );

    FOR v_rec IN (SELECT * FROM TMP_SITFINCOL ORDER BY CodColoana)
    LOOP
      IF  v_rec.CodColoana &lt; 0 THEN
        INSERT INTO SITFINCOL(CodColoana, CodSitFin, NrCol, Denumire, TipCol, Corelatie, IdentificatorCol, flgExport, Conta)
        VALUES(  NEXTVAL('SEQ_SITFINCOL_CODCOLOANA'), RecId, v_rec.NrCol, v_rec.Denumire, v_rec.TipCol, v_rec.Corelatie,
                v_rec.IdentificatorCol, v_rec.flgexport, v_rec.Conta
              );
      ELSE
        UPDATE SITFINCOL
        SET
           NrCol            = v_rec.NrCol,
           Denumire         = v_rec.Denumire,
           TipCol           = v_rec.TipCol,
           Corelatie        = v_rec.Corelatie,
           IdentificatorCol = v_rec.IdentificatorCol,
           flgExport        = v_rec.flgExport,
           Conta            = v_rec.Conta
        WHERE CodColoana    = v_rec.CodColoana;
      END IF;
    END LOOP;

    DELETE FROM SITFINLIN WHERE CodSitFin = RecId AND CodLinie NOT IN (SELECT CodLinie FROM TMP_SITFINLIN);

    FOR v_rec IN (SELECT * FROM TMP_SITFINLIN ORDER BY CodLinie)
    LOOP
      IF  v_rec.CodLinie &lt; 0 THEN
        vcod := NEXTVAL('SEQ_SITFINLIN_CODLINIE');
        UPDATE tmp_sitfinbuget set codsitfinlin = vcod where codsitfinlin = v_rec.codlinie;

        INSERT INTO SITFINLIN(CodLinie, CodSitFin, NrLinie, Denumire, Total, Corelatie, Rnd, TipConta, Obs, ValSuplim, FaraNegative)
        VALUES(vcod, RecId, v_rec.NrLinie, v_rec.Denumire, v_rec.Total, v_rec.Corelatie, v_rec.Rnd, v_rec.TipConta, v_rec.Obs, v_rec.ValSuplim, v_rec.FaraNegative);
      ELSE
        UPDATE SITFINLIN
        SET
          NrLinie   = v_rec.NrLinie,
          Denumire  = v_rec.Denumire,
          Total     = v_rec.Total,
          Corelatie = v_rec.Corelatie,
          Rnd       = v_rec.Rnd,
          TipConta  = v_rec.TipConta,
          Obs       = v_rec.Obs,
          ValSuplim = v_rec.ValSuplim,
          FaraNegative = v_rec.FaraNegative
        WHERE CodLinie = v_rec.CodLinie;
      END IF;
    END LOOP;

    DELETE FROM SITFINBUGET WHERE CodSitFin = RecId AND CodSitFinBuget NOT IN (SELECT CodSitFinBuget FROM TMP_SITFINBUGET);

    FOR v_rec IN (SELECT * FROM TMP_SITFINBUGET)
    LOOP
      IF v_rec.CodSitFinBuget &lt; 0 THEN
        INSERT INTO SITFINBUGET(CodSitFinBuget, CodSitFinLin, CodSitFin, An, Luna, Valoare)
        VALUES(NEXTVAL('SEQ_SITFINBUGET_CODSITFINBUGET'), CodSitFinLin, RecId, v_rec.An, v_rec.Luna, V_rec.Valoare);
      ELSE
        UPDATE CONDCOR1
        SET
          CodSitFinLin       = v_rec.CodSitFinLin,
          CodSitFin          = v_rec.CodSitFin,
          An                 = v_rec.An,
          Luna               = v_rec.Luna,
          Valoare            = v_rec.Valoare
        WHERE CodSitFinBuget = v_rec.CodSitFinBuget;
      END IF;
    END LOOP;

    DELETE FROM CONDCOR1 WHERE CodSitFin = RecId AND CodCondCor1 NOT IN (SELECT CodCondCor1 FROM TMP_CONDCOR1);

    FOR v_rec IN (SELECT * FROM TMP_CONDCOR1 ORDER BY CodCondCor1)
    LOOP
      IF  v_rec.CodCondCor1 &lt; 0 THEN
        INSERT INTO CONDCOR1(CodCondCor1, CodSitFin, IndexLocal, Rnd1, Col1, Rel, Rnd2, Col2)
        VALUES(NEXTVAL('SEQ_CONDCOR1_CODCONDCOR1'), RecId, v_rec.IndexLocal, v_rec.Rnd1::numeric,
                       v_rec.Col1::numderic, v_rec.Rel, v_rec.Rnd2::numeric, v_rec.Col2::numeric
              );
      ELSE
        UPDATE CONDCOR1
        SET
          IndexLocal = v_rec.IndexLocal,
          Rnd1       = v_rec.Rnd1::numeric,
          Col1       = v_rec.Col1::numeric,
          Rel        = v_rec.Rel,
          Rnd2       = v_rec.Rnd2::numeric,
          Col2       = v_rec.Col2::numeric
        WHERE CodCondCor1 = v_rec.CodCondCor1;
      END IF;
    END LOOP;

    DELETE FROM CORELAT1 WHERE CodSitFin = RecId AND CodCorelat1 NOT IN (SELECT CodCorelat1 FROM TMP_CORELAT1);

    FOR v_rec IN (SELECT * FROM TMP_CORELAT1 ORDER BY CodCorelat1)
    LOOP
      IF  v_rec.CodCorelat1 &lt; 0 THEN
        INSERT INTO CORELAT1(CodCorelat1, CodSitFin, IndexLocal, Rnd1, Col1, Rel, Rnd2, Col2, Cond, IsNumeric)
        VALUES(NEXTVAL('SEQ_CORELAT1_CODCORELAT1'), RecId, v_rec.IndexLocal, v_rec.Rnd1::varchar,
               v_rec.Col1::varchar, v_rec.Rel, v_rec.Rnd2::varchar, v_rec.Col2::varchar, v_rec.Cond, v_rec.IsNumeric
              );
      ELSE
        UPDATE CORELAT1
        SET
          IndexLocal = v_rec.IndexLocal,
          Rnd1       = v_rec.Rnd1::varchar,
          Col1       = v_rec.Col1::varchar,
          Rel        = v_rec.Rel,
          Rnd2       = v_rec.Rnd2::varchar,
          Col2       = v_rec.Col2::varchar,
          Cond       = v_rec.Cond,
          IsNumeric  = v_rec.IsNumeric
        WHERE CodCorelat1 = v_rec.CodCorelat1;
      END IF;
    END LOOP;

    DELETE FROM CORELAT2 WHERE CodSitFin = RecId AND CodCorelat2 NOT IN (SELECT CodCorelat2 FROM TMP_CORELAT2);

    FOR v_rec IN (SELECT * FROM TMP_CORELAT2 ORDER BY CodCorelat2)
    LOOP
      IF  v_rec.CodCorelat2 &lt; 0 THEN
        INSERT INTO CORELAT2(CodCorelat2, CodSitFin, CodF1, Rnd1, Col1, CodF2, Rnd2, Col2)
        VALUES(NEXTVAL('SEQ_CORELAT2_CODCORELAT2'), RecId, v_rec.CodF1, v_rec.Rnd1::varchar, v_rec.Col1::varchar,
               v_rec.CodF2, v_rec.Rnd2::varchar, v_rec.Col2::varchar
              );
      ELSE
        UPDATE CORELAT2
        SET
          CodF1 = v_rec.CodF1,
          Rnd1  = v_rec.Rnd1::varchar,
          Col1  = v_rec.Col1::varchar,
          CodF2 = v_rec.CodF2,
          Rnd2  = v_rec.Rnd2::varchar,
          Col2  = v_rec.Col2::varchar
        WHERE CodCorelat2 = v_rec.CodCorelat2;
      END IF;
    END LOOP;

    DELETE FROM SITFINALTE WHERE CodSitFin = RecId AND CodAlte NOT IN (SELECT CodAlte FROM TMP_SITFINALTE);

    FOR v_rec IN (SELECT * FROM TMP_SITFINALTE)
    LOOP
      IF  v_rec.CODALTE &lt; 0 THEN
        INSERT INTO SITFINALTE(CODALTE, CODSITFIN, FUNCTIE, RAND, COLOANA)
        VALUES(NEXTVAL('SEQ_SITFINALTE_CODALTE'), RecId, upper(v_rec.FUNCTIE), v_rec.RAND, v_rec.COLOANA);
      ELSE
        UPDATE SITFINALTE
        SET
          FUNCTIE = upper(V_REC.FUNCTIE),
          RAND    = V_REC.RAND,
          COLOANA = V_REC.COLOANA
        WHERE CODALTE = v_rec.CODALTE;
      END IF;
    END LOOP;
  ELSE
    SELECT NEXTVAL('SEQ_SITFIN_CODSITFIN') INTO RecId;
    INSERT INTO SITFIN(CodSitFin, CodF, Denumire, Sectiune, UserId, DataCreare, Tip, TipPlan, PeLuni)
    (
     SELECT RecId, CodF, Denumire, Sectiune, current_setting('PKG_GLOBALS.USERID', true)::numeric, CURRENT_TIMESTAMP, Tip, TipPlan, PeLuni
     FROM TMP_SITFIN
    );



  INSERT INTO SITFINCOL(CodColoana, CodSitFin, NrCol, Denumire, TipCol, Corelatie, IdentificatorCol, flgExport, Conta)
    (
     SELECT NEXTVAL('SEQ_SITFINCOL_CODCOLOANA'), RecId, NrCol, Denumire, TipCol, Corelatie, IdentificatorCol, flgExport, Conta
     FROM TMP_SITFINCOL
    );



    FOR v_rec IN (SELECT * FROM tmp_sitfinlin)
    LOOP
      vcod := NEXTVAL('SEQ_SITFINLIN_CODLINIE');
      UPDATE tmp_sitfinbuget SET codsitfinlin = vcod WHERE codsitfinlin = v_rec.codlinie;

      INSERT INTO SITFINLIN(CodLinie, CodSitFin, NrLinie, Denumire, Total, Corelatie, Rnd, TipConta, Obs, ValSuplim, FaraNegative)
      --(SELECT vcod, RecId, NrLinie, Denumire, Total, Corelatie, Rnd, TipConta, Obs, ValSuplim FROM TMP_SITFINLIN)  -- 21.12.2020
      VALUES(vCod,
             RecId,
             v_rec.NrLinie,
             v_rec.Denumire,
             v_rec.Total,
             v_rec.Corelatie,
             v_rec.Rnd,
             v_rec.TipConta,
             v_rec.Obs,
             v_rec.ValSuplim,
             v_rec.FaraNegative);
    END LOOP;



    INSERT INTO SITFINBUGET(CodSitFinBuget, CodSitFinLin, CodSitFin, An, Luna, Valoare)
    SELECT NEXTVAL('SEQ_SITFINBUGET_CODSITFINBUGET'), CodSitFinLin, RecId, An, Luna, Valoare
    FROM tmp_sitfinbuget;



    INSERT INTO CONDCOR1(CodCondCor1, CodSitFin, IndexLocal, Rnd1, Col1, Rel, Rnd2, Col2)
    (SELECT NEXTVAL('SEQ_CONDCOR1_CODCONDCOR1'), RecId, IndexLocal, Rnd1::numeric, Col1::numeric, Rel, Rnd2::numeric, Col2::numeric
     FROM TMP_CONDCOR1
    );




    INSERT INTO CORELAT1(CodCorelat1, CodSitFin, IndexLocal, Rnd1, Col1, Rel, Rnd2, Col2, Cond, IsNumeric)
    (SELECT NEXTVAL('SEQ_CORELAT1_CODCORELAT1'), RecId, IndexLocal, Rnd1::varchar, Col1::varchar, Rel, Rnd2::varchar, Col2::varchar, Cond, IsNumeric
     FROM TMP_CORELAT1
    );




    INSERT INTO CORELAT2(CodCorelat2, CodSitFin, CodF1, Rnd1, Col1, CodF2, Rnd2, Col2)
    (SELECT NEXTVAL('SEQ_CORELAT2_CODCORELAT2'), RecId, CodF1, Rnd1::varchar, Col1::varchar, CodF2, Rnd2::varchar, Col2::varchar
     FROM TMP_CORELAT2
    );

    INSERT INTO SITFINALTE(CODALTE, CODSITFIN, FUNCTIE, RAND, COLOANA)
    SELECT NEXTVAL('SEQ_SITFINALTE_CODALTE'), RecId, upper(FUNCTIE), RAND, COLOANA
    FROM TMP_SITFINALTE;
  END IF;

  PERFORM NotifyModif(Operation, RecId, 'SITFIN');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tcsoldi</obj_name>
  <obj_hashval>f8771fdaeaa11efc45fcb18a4bb2c72b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tcsoldi(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcSoldI')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 3;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_make_config_luna</obj_name>
  <obj_hashval>9412a787c075c79faecd9db87573ed3a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_make_config_luna()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  AnLunaLucru     numeric;
  aUSER_ID        numeric := -1;
  aNART_FLG       numeric := 0;
  aNARTObj_FLG    numeric := 0;
  aIOART_FLG      numeric := 0;
  aNTVA_FLG       numeric := 0;
  aNTAXE_FLG      numeric := 0;
  aTARIFE_FLG     numeric := 0;
  aPRETM_FLG      numeric := 0;
  aIOPART_FLG     numeric := 0;
  aIOFILIAL_FLG   numeric := 0;
  aIOBANK_FLG     numeric := 0;
  aIOPERS_FLG     numeric := 0;

  isWMRETAIL      numeric := 0;
  vPrPtRetail     numeric := 0;

  NEEDREFRESHART  numeric := 1;
  aValConst       numeric := 0;
  sCodCatPretEmul VARCHAR := NULL;
  CODCATPRETEMUL  numeric = 0;
  aSUBUNIT        numeric;
  CATPRET_11      NUMERIC(10);
  sInsert         varchar := '';
  sValuta         varchar;
  SJoin_PACHVAL   varchar;
BEGIN
  --Stef   02.06.2025 - corectie PG
  --Florin 13.05.2025 - sinc. Oracle
  --Florin 03.02.2025 - fixat 64625
  --Florin 31.01.2025 - sinc. Oracle
  --Florin 02.12.2024 - fixat 64170
  --Florin 25.03.2022 - fixat 53644
  -- Bogdan 25.01.2022 - corectie TMP_LASTPRETACHIZ
  --Laura 25.01.2022 - sinc. Oracle (28.12.2021)
  --Adina 30.12.2020 - sincronizare cu Oracle
  perform set_config('PKG_GLOBALS.DATA0', '30.12.1899',false);
  NEEDREFRESHART    := 1;

  BEGIN
    aValConst := Coalesce(fnc_GetValConstanta('ManualRefreshNart', getANLUCRU(), getLUNALUCRU()), '0')::numeric;
  EXCEPTION
    WHEN OTHERS THEN aValConst := 0;
  END;

  IF aValConst = 1 THEN NEEDREFRESHART := 0; END IF;

  BEGIN
    SELECT Coalesce( USERID, -1), Coalesce( NART_FLG, 0), Coalesce( NARTOBJ_FLG, 0), Coalesce( IOART_FLG, 0), Coalesce( NTVA_FLG, 0), Coalesce( NTAXE_FLG, 0), Coalesce( TARIFE_FLG, 0), Coalesce( PRETM_FLG, 0),
           Coalesce( IOPART_FLG, 0), Coalesce( IOFILIAL_FLG, 0), Coalesce( IOBANK_FLG, 0), Coalesce( IOPERS_FLG, 0)
    INTO aUSER_ID, aNART_FLG, aNARTObj_FLG, aIOART_FLG, aNTVA_FLG, aNTAXE_FLG, aTARIFE_FLG, aPRETM_FLG, aIOPART_FLG, aIOFILIAL_FLG, aIOBANK_FLG, aIOPERS_FLG
    FROM LUNA_RECORDS_FLAGS
    WHERE USERID = (SELECT USERID FROM TMP_PKG_GLOBALS );
  EXCEPTION WHEN OTHERS THEN
    aUSER_ID = -1;
  END;

  IF (NOT fnc_tmpexists('TMP_LUNA_RECORDS_FLAGS') = 1) then
    CALL create_wm_temp('TMP_LUNA_RECORDS_FLAGS');
  END IF;
  IF (NOT fnc_tmpexists('TMP_IOART_LUNA') = 1) then
    CALL create_wm_temp('TMP_IOART_LUNA');
  END IF;
  IF (NOT fnc_tmpexists('TMP_IOPART_CFGLUNA') = 1) then
    CALL create_wm_temp('TMP_IOPART_CFGLUNA');
  END IF;
  IF (NOT fnc_tmpexists('TMP_IOFILIAL_LUNA') = 1) then
    CALL create_wm_temp('TMP_IOFILIAL_LUNA');
  END IF;
  IF (NOT fnc_tmpexists('TMP_IOBANK_LUNA') = 1) then
    CALL create_wm_temp('TMP_IOBANK_LUNA');
  END IF;
  IF (NOT fnc_tmpexists('TMP_IOPERS_CFGLUNA') = 1) then
    CALL create_wm_temp('TMP_IOPERS_CFGLUNA');
  END IF;
  IF (NOT fnc_tmpexists('TMP_NART_LUNA') = 1) then
    CALL create_wm_temp('TMP_NART_LUNA');
  END IF;
  IF (NOT fnc_tmpexists('TMP_NTVA_LUNA') = 1) then
    CALL create_wm_temp('TMP_NTVA_LUNA');
  END IF;
  IF (NOT fnc_tmpexists('TMP_MANPRETM') = 1) then
    CALL create_wm_temp('TMP_MANPRETM');
  END IF;
  IF (NOT fnc_tmpexists('tmp_lastpretachiz') = 1) then
    CALL create_wm_temp('tmp_lastpretachiz');
  END IF;
  IF (NOT fnc_tmpexists('tmp_ntaxe_luna') = 1) then
    CALL create_wm_temp('tmp_ntaxe_luna');
  END IF;
  IF (NOT fnc_tmpexists('tmp_nartobj_luna') = 1) then
    CALL create_wm_temp('tmp_nartobj_luna');
  END IF;
  IF (NOT fnc_tmpexists('tmp_tarifeman_luna') = 1) then
    CALL create_wm_temp('tmp_tarifeman_luna');
  END IF;

  IF  coalesce(aUSER_ID, -1) = -1 THEN
    INSERT INTO LUNA_RECORDS_FLAGS(USERID, NART_FLG, NARTOBJ_FLG, IOART_FLG, NTVA_FLG, NTAXE_FLG, TARIFE_FLG, PRETM_FLG, IOPART_FLG, IOFILIAL_FLG, IOBANK_FLG, IOPERS_FLG,
                                   NART_FLG_CONTA,
                                   NARTOBJ_FLG_CONTA,
                                   IOART_FLG_CONTA,
                                   NTVA_FLG_CONTA,
                                   NTAXE_FLG_CONTA,
                                   IOPART_FLG_CONTA,
                                   IOPERS_FLG_CONTA,
                                   IOFILIAL_FLG_CONTA,
                                   IOBANK_FLG_CONTA,
                                   NGEST1_FLG_CONTA,
                                   NPART1_FLG_CONTA,
                                   NPERS1_FLG_CONTA,
                                   NBANK1_FLG_CONTA
    )
    VALUES(  (SELECT USERID FROM TMP_PKG_GLOBALS), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

    INSERT INTO TMP_LUNA_RECORDS_FLAGS(USERID, NART_FLG, NARTOBJ_FLG, IOART_FLG, NTVA_FLG, NTAXE_FLG, TARIFE_FLG, PRETM_FLG, IOPART_FLG, IOFILIAL_FLG, IOBANK_FLG, IOPERS_FLG)
    VALUES( (SELECT USERID FROM TMP_PKG_GLOBALS), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    NEEDREFRESHART := 1;
  END IF;

  AnLunaLucru := GETANLUCRU() * 12 + GETLUNALUCRU();

  IF  coalesce(aIOART_FLG, 0) = 0 or  TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0 THEN
    TRUNCATE TABLE tmp_ioart_luna;

    sInsert := '
    INSERT INTO TMP_IOART_LUNA (
      CODIOART1, CODIOART, CONT, DIFERENTE, CHELTUIELI, VENITURI, PLUSINVENTAR, MINUSINVENTAR, CHELTTVACOLECTAT, CONTROTUNJIRI, DIVERSE, CUSTODIE, ACCIZELATRANSFER,
      DESCARCAREG, CONTABGEST, BAZA, DIFPRET, ARETVANEEX, TVANEEX, MG, ANSTART, LUNASTART, PUSTANDARD, PROVIZION, CHELTPROVIZION, VENITPROVIZION, DEN_IOART,
      ESTEMIFIX,
      ESTEOBINV,
      ESTECUSTODIE)
    SELECT
      IO1.CODIOART1, IO1.CODIOART, IO1.CONT, IO1.DIFERENTE, IO1.CHELTUIELI, IO1.VENITURI, IO1.PLUSINVENTAR, IO1.MINUSINVENTAR, IO1.CHELTTVACOLECTAT, IO1.CONTROTUNJIRI, IO1.DIVERSE, IO1.CUSTODIE, IO1.ACCIZELATRANSFER,
      IO1.DESCARCAREG, IO1.CONTABGEST, IO1.BAZA, IO1.DIFPRET, IO1.ARETVANEEX, IO1.TVANEEX, IO1.MG, IO1.ANSTART, IO1.LUNASTART, IO1.PUSTANDARD, IO1.PROVIZION, IO1.CHELTPROVIZION, IO1.VENITPROVIZION, IO.DEN_IOART,
      CASE
        WHEN coalesce(CMF.CODCONT, 0) &lt;&gt; 0 THEN 1
        ELSE 0
      END,
      CASE
        WHEN coalesce(COBINV.CODCONT, 0) &lt;&gt; 0 THEN 1
        ELSE 0
      END,
      CASE
        WHEN coalesce(CCUST.CODCONT, 0) &lt;&gt; 0 THEN 1
        ELSE 0
      END
    FROM
      IOART IO
      INNER JOIN IOART1           IO1    ON IO.CODIOART = IO1.CODIOART
      LEFT  JOIN TMP_CONTMIFIX    CMF    ON IO1.CONT = CMF.CODCONT
      LEFT  JOIN TMP_CONTOBINV    COBINV ON IO1.CONT = COBINV.CODCONT
      LEFT  JOIN TMP_CONTCUSTODIE CCUST  ON IO1.CONT = CCUST.CODCONT
    WHERE '||ANLUNALUCRU::varchar||' BETWEEN IO1.ALSTART AND IO1.ALSTOP';
    EXECUTE sInsert;

    UPDATE LUNA_RECORDS_FLAGS     SET IOART_FLG = 1 WHERE UserID = (SELECT USERID FROM TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET IOART_FLG = 0;
  END IF;

  IF  coalesce(aIOPART_FLG, 0) = 0 or  TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0 THEN
    TRUNCATE TABLE TMP_IOPART_CFGLUNA;

   INSERT INTO TMP_IOPART_CFGLUNA
    (
     CODIOPART1, CODIOPART, CONTFURNIZOR, CONTCLIENT, CONTFURNAVANS, CONTCLIENTAVANS, CONTFURNAVIZ, CONTCLIENTAVIZ, CONTFURNMF, CONTCREDITD, CONTDEBITD,
     CONTLITIGII, CONTFURNAVS, CONTFURNAVIC, CONTFURNAVIN, CONTTERTI, CONTFURNLEAS, CONTNCRF, CONTNCRC, CONTCHELTAVANS, CONTVENITAVANS, contgarantieEF,
     contgarantieTF, contgarantieEC, contgarantieTC, ContSuplimF1, ContSuplimF2, ContSuplimF3, ContSuplimF4, ContSuplimF5, ContSuplimC1, ContSuplimC2, ContSuplimC3, ContSuplimC4, ContSuplimC5, ContSuplimF6, ContSuplimF7, ContSuplimF8, ContSuplimF9,
      ContSuplimF10, ContSuplimF11, ContSuplimF12, ContSuplimF13, ContSuplimF14, ContSuplimF15, ContSuplimF16, ContSuplimF17, ContSuplimF18, ContSuplimF19, ContSuplimF20, ContSuplimF21, ContSuplimF22,
      ContSuplimF23, ContSuplimF24, ContSuplimF25, ContSuplimF26, ContSuplimF27, ContSuplimF28, ContSuplimF29, ContSuplimF30,
      TVANEEXF, TVANEEXC, TVANEEXP, TVANEEXI, TIP
    )
    SELECT CODIOPART1, CODIOPART, CONTFURNIZOR, CONTCLIENT, CONTFURNAVANS, CONTCLIENTAVANS, CONTFURNAVIZ, CONTCLIENTAVIZ, CONTFURNMF, CONTCREDITD, CONTDEBITD,
           CONTLITIGII, CONTFURNAVS, CONTFURNAVIC, CONTFURNAVIN, CONTTERTI, CONTFURNLEAS, CONTNCRF, CONTNCRC, CONTCHELTAVANS, CONTVENITAVANS, contgarantieEF,
           contgarantieTF, contgarantieEC, contgarantieTC,  ContSuplimF1, ContSuplimF2, ContSuplimF3, ContSuplimF4, ContSuplimF5, ContSuplimC1, ContSuplimC2, ContSuplimC3, ContSuplimC4, ContSuplimC5, ContSuplimF6, ContSuplimF7, ContSuplimF8, ContSuplimF9,
           ContSuplimF10, ContSuplimF11, ContSuplimF12, ContSuplimF13, ContSuplimF14, ContSuplimF15, ContSuplimF16, ContSuplimF17, ContSuplimF18, ContSuplimF19, ContSuplimF20, ContSuplimF21, ContSuplimF22,
           ContSuplimF23, ContSuplimF24, ContSuplimF25, ContSuplimF26, ContSuplimF27, ContSuplimF28, ContSuplimF29, ContSuplimF30,
           TVANEEXF, TVANEEXC, TVANEEXP, TVANEEXI, TIP
    FROM IOPART1 n1
    WHERE AnLunaLucru BETWEEN N1.ALSTART AND N1.ALSTOP;

    UPDATE LUNA_RECORDS_FLAGS     SET IOPART_FLG = 1 WHERE USERID = (SELECT USERID FROM TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET IOPART_FLG = 0;
  END IF;

  IF  coalesce(aIOFILIAL_FLG, 0) = 0 or  TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0 THEN
    TRUNCATE TABLE TMP_IOFILIAL_LUNA;

    INSERT INTO TMP_IOFILIAL_LUNA(CODIOFILIAL1, CODIOFILIAL, CONTDECONTARE, CONTDECONTAREF, ISFIRMA, CONTDECONTSERV, CONTDECONTCB, CONTDECONTCMP)
    SELECT CODIOFILIAL1, CODIOFILIAL, CONTDECONTARE, CONTDECONTAREF, ISFIRMA, CONTDECONTSERV, CONTDECONTCB, CONTDECONTCMP
    FROM IOFILIAL1 n1
    WHERE AnLunaLucru BETWEEN N1.ALSTART AND N1.ALSTOP;

    UPDATE LUNA_RECORDS_FLAGS     SET IOFILIAL_FLG = 1 WHERE USERID = (SELECT USERID FROM TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET IOFILIAL_FLG = 0;
  END IF;

  IF  coalesce(aIOBANK_FLG, 0) = 0 or  TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0 THEN
    TRUNCATE TABLE TMP_IOBANK_LUNA;

    INSERT INTO TMP_IOBANK_LUNA(CODIOBANK1, CODIOBANK, CONT, DOBANDA, COMISION, CHELTUIELICV, VENITURICV, PCEC, PEFECTE, PEFECTEREM, ICEC, IEFECTE, IEFECTEREM)
    SELECT CODIOBANK1, CODIOBANK, CONT, DOBANDA, COMISION, CHELTUIELICV, VENITURICV, PCEC, PEFECTE, PEFECTEREM, ICEC, IEFECTE, IEFECTEREM
    FROM IOBANK1 n1
    WHERE AnLunaLucru BETWEEN N1.ALSTART AND N1.ALSTOP;

    UPDATE LUNA_RECORDS_FLAGS     SET IOBANK_FLG = 1 WHERE USERID = (SELECT USERID FROM TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET IOBANK_FLG = 0;
  END IF;

  IF  coalesce(aIOPERS_FLG, 0) = 0 or  TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0 THEN
    TRUNCATE TABLE TMP_IOPERS_CFGLUNA;

    INSERT INTO TMP_IOPERS_CFGLUNA(CODIOPERS1, CODIOPERS, CONTAVANSDECONT, CONTIMPUTATII, CONTGARANTII, CONTALTERETINERI, CONTAVANS, CONTLIKI,
                                   CONTNERIDICATE, CONTBOALA, CONTPARTSAL, CONTNATURA, CONTECHIPAMENT, CONTIMPOZIT
                                  )
    SELECT CODIOPERS1, CODIOPERS, CONTAVANSDECONT, CONTIMPUTATII, CONTGARANTII, CONTALTERETINERI, CONTAVANS, CONTLIKI,
           CONTNERIDICATE, CONTBOALA, CONTPARTSAL, CONTNATURA, CONTECHIPAMENT, CONTIMPOZIT
     FROM IOPERS1 n1
    WHERE AnLunaLucru BETWEEN N1.ALSTART AND N1.ALSTOP;

    UPDATE LUNA_RECORDS_FLAGS     SET IOPERS_FLG = 1 WHERE USERID = (SELECT USERID FROM TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET IOPERS_FLG = 0;
  END IF;

  IF (NEEDREFRESHART = 1) AND (COALESCE(aNART_FLG,0) = 0 or TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0) THEN
    --NART1
    TRUNCATE TABLE tmp_nart_luna;

    sInsert := '
    INSERT INTO tmp_nart_luna(codarticol1,codarticol,codtva,codaccize,codaccizedvi,codtaxa1,codtaxa2,anstart,lunastart)
    SELECT codarticol1,codarticol,codtva,codaccize,codaccizedvi,codtaxa1,codtaxa2,anstart,lunastart
    FROM nart1 n1
    WHERE '||ANLUNALUCRU::varchar||' BETWEEN N1.ALSTART AND N1.ALSTOP';

    EXECUTE sInsert;

    UPDATE LUNA_RECORDS_FLAGS     SET NART_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET NART_FLG = 0;
  END IF;

  IF COALESCE(aNTVA_FLG,0) = 0 or TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0 THEN
    --NTVA1
    TRUNCATE TABLE tmp_ntva_luna;

    sInsert := '
    INSERT INTO tmp_ntva_luna(codtva1,codtva,procent,codcontded,codcontcole,codcontneex,anstart,lunastart,den_tva)
    SELECT n1.codtva1,n1.codtva,n1.procent,n1.codcontded,n1.codcontcole,n1.codcontneex,n1.anstart,n1.lunastart,n.den_tva
    FROM ntva1 n1 INNER JOIN ntva n ON n1.codtva = n.codtva
    WHERE '||ANLUNALUCRU::varchar||' BETWEEN N1.ALSTART AND N1.ALSTOP';
    EXECUTE sInsert;

    UPDATE LUNA_RECORDS_FLAGS     SET NTVA_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET NTVA_FLG = 0;
  END IF;

  IF (NEEDREFRESHART = 1) AND (COALESCE(aPRETM_FLG,0) = 0 or TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0)  THEN
    BEGIN
      ISWMRETAIL := Coalesce((SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_GET_FIRMA_ISWMRETAIL(NULL,current_setting('PKG_GLOBALS.CODFIRMA', true)::numeric)), 0);
    EXCEPTION
      WHEN OTHERS THEN ISWMRETAIL := 0;
    END;

    TRUNCATE TABLE TMP_MANPRETM;

    IF ISWMRETAIL = 1 THEN
      sCodCatPretEmul := Coalesce(fnc_GetValConstanta('CodCatPretEmulUsr', getANLUCRU(), getLUNALUCRU()), '0');
      IF sCodCatPretEmul = '0' THEN
        sCodCatPretEmul := Coalesce(fnc_GetValConstanta('CodCatPretEmul', getANLUCRU(), getLUNALUCRU()), '0');
      END IF;

      BEGIN
        CODCATPRETEMUL := sCodCatPretEmul::numeric;
      EXCEPTION
        WHEN OTHERS THEN CODCATPRETEMUL := 0;
      END;

      sInsert := '
      INSERT INTO TMP_MANPRETM
      SELECT
        PM.CODOBIECT,
        CASE
          WHEN CAT.TIP = 1 THEN LEI
          WHEN CAT.TIP = 2 THEN ROUND(LEI * (1 + Coalesce(T.PROCENT, 0) / 100), 2)
          ELSE NULL
        END LEI,
        VALUTA,
        SUBUNITATEA
      FROM PRETM PM, NARTOBJ O, TMP_NART_LUNA A, TMP_NTVA_LUNA T, NCATPRET CAT
      WHERE CAT.CODCATPRET = PM.CODCATPRET
        AND O.CODOBIECT = PM.CODOBIECT
        AND A.CODARTICOL = O.CODARTICOL
        AND A.CODTVA = T.CODTVA
        AND Coalesce(PM.subunitatea, 0) = '||To_Char(Coalesce(GETSUBUNITATE(),0))||'
        AND CAT.CODCATPRET = '||To_Char(CODCATPRETEMUL);
        EXECUTE sInsert;
    ELSE
      IF  GETSUBUNITATE() = 1
      THEN aSUBUNIT := Coalesce(GETSUBUNITATE_DOC(), 0);
      ELSE aSUBUNIT := Coalesce(GETSUBUNITATE(), 0);
      END IF;

      BEGIN
        SELECT COUNT(*) INTO CATPRET_11 FROM PRETM PM INNER JOIN NCATPRET CP ON CP.CODCATPRET = PM.CODCATPRET AND CP.TIP = 11;
        EXCEPTION WHEN OTHERS THEN CATPRET_11 := 0;
      END;

      IF CATPRET_11 &gt; 0 THEN
        SValuta := '
        CASE
          WHEN CAT.TIP = 11 THEN Coalesce(PUACHVAL.PUVAL, 0) * (1 + Coalesce(Lei, 0) / 100)
          ELSE VALUTA
        END VALUTA,';
        SJoin_PACHVAL := '
        LEFT JOIN (
          SELECT DISTINCT
            CODOBIECT,
            MONEDA,
            FIRST_VALUE(PUVAL)   OVER (PARTITION BY CODOBIECT, MONEDA ORDER BY DATANIR DESC) PUVAL,
            FIRST_VALUE(DATANIR) OVER (PARTITION BY CODOBIECT, MONEDA ORDER BY DATANIR DESC) DATANIR
          FROM (
            SELECT NS.CODOBIECT, I.MONEDA, NS.PRET - Coalesce(NS.ADAOS,0) / COALESCE(NULLIF(I.CURS, 0), 1)  PUVAL, N.DATANIR
            FROM NIRSTOC NS
              INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
              INNER JOIN INTRARI I ON I.CODINTR = N.CODINTR
            WHERE TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 15) AND I.MONEDA &lt;&gt; 0 AND N.OPERAT = 1 AND N.ANULAT = 0
          ) ss
        ) PUACHVAL ON PUACHVAL.CODOBIECT = PM.CODOBIECT AND PUACHVAL.MONEDA = PM.MONEDA ';
      ELSE
        SValuta := ' VALUTA,';
        SJoin_PACHVAL := '';
      END IF;


      DELETE FROM TMP_LASTPRETACHIZ;
      INSERT INTO TMP_LASTPRETACHIZ
      SELECT DISTINCT ON (ns.codobiect)
       ns.codobiect,
       ns.pret - COALESCE(ns.adaos, 0) AS pretachiz
        FROM nirstoc ns
        JOIN nir n
          ON n.codnir = ns.codnir
        JOIN pretm pm
          ON pm.codobiect = ns.codobiect
        JOIN ncatpret cp
          ON cp.codcatpret = pm.codcatpret
        WHERE n.tipnir   IN (1,2,3,4,5,7,8,9,15)
          AND n.operat   = 1
          AND n.anulat   = 0
          AND pm.subunitatea = aSUBUNIT
          AND pm.implicit    = 1
          AND cp.tip         = 10
        ORDER BY
        ns.codobiect, n.datanir DESC, (ns.pret - COALESCE(ns.adaos,0)) DESC;

      vPrPtRetail := Coalesce((SELECT wme_result FROM PKG_GLOBALS_PretPentruRetail(NULL, NULL)), 0);
      sInsert := '
      INSERT INTO TMP_MANPRETM
      SELECT
        PM.CODOBIECT,
        CASE
          WHEN CAT.TIP =  1 THEN LEI
          WHEN CAT.TIP =  2 AND '||To_Char(vPrPtRetail)||' = 1 THEN ROUND(LEI * (1 + Coalesce(T.PROCENT, 0) / 100), 2)
          WHEN CAT.TIP =  2 AND '||To_Char(vPrPtRetail)||' = 0 THEN Lei
          WHEN CAT.TIP = 10 THEN  Coalesce(PACH.PRETACHIZ, 0) * (1 + Coalesce(Lei, 0) / 100)
        END LEI,'||
        sVAluta ||'
        SUBUNITATEA
      FROM PRETM PM
        INNER JOIN NCATPRET CAT ON CAT.CODCATPRET = PM.CODCATPRET
        LEFT JOIN TMP_LASTPRETACHIZ PACH ON PACH.CODOBIECT = PM.CODOBIECT '||
        SJoin_PACHVAL ||'
        INNER JOIN NARTOBJ O ON O.CODOBIECT = PM.CODOBIECT
        INNER JOIN NART1 A ON A.CODARTICOL = O.CODARTICOL AND '||To_Char(ANLUNALUCRU)||' BETWEEN A.ALSTART AND A.ALSTOP
        INNER JOIN NTVA1 T ON A.CODTVA     = T.CODTVA     AND '||To_Char(ANLUNALUCRU)||' BETWEEN T.ALSTART AND T.ALSTOP
      WHERE Coalesce(PM.subunitatea, 0) = '||To_Char(aSUBUNIT)||' AND Coalesce(PM.IMPLICIT, 0) = 1 AND CAT.TIP IN (1, 2, 10, 11)';
      EXECUTE sInsert;
    END IF;

    UPDATE LUNA_RECORDS_FLAGS     SET PRETM_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET PRETM_FLG = 0;
  END IF;

  IF COALESCE(aNTAXE_FLG,0) = 0 or TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0 THEN
    --NTAXE1
    TRUNCATE TABLE tmp_ntaxe_luna;

    sInsert := '
    INSERT INTO tmp_ntaxe_luna(
      CODTAXA1,CODTAXA,VALOARE,LACEAPLIC,CODCONT,CODCONTCHELT,ORICARETIP,CODIOARTEXCL,
      EXCLUSACCIZE,EXCLUSEXPORT,JACHIZ,JVANZ,CUMJACHIZ,CUMJVANZ,BazaMax,BazaMin,CODSERVFACT,
      FACTURABIL,STOPAJ,ANSTART,LUNASTART,SERVICIUMONETAR, ProcDiminuareB, DEN_TAXA, Rotvaloare)
    SELECT
      n1.CODTAXA1,n1.CODTAXA,n1.VALOARE,n1.LACEAPLIC,n1.CODCONT,n1.CODCONTCHELT,n1.ORICARETIP,n1.CODIOARTEXCL,
      n1.EXCLUSACCIZE,n1.EXCLUSEXPORT,n1.JACHIZ,n1.JVANZ,n1.CUMJACHIZ,n1.CUMJVANZ,n1.BazaMax,n1.BazaMin,n1.CODSERVFACT,
      n1.FACTURABIL,n1.STOPAJ,n1.ANSTART,n1.LUNASTART,n1.SERVICIUMONETAR,n1.ProcDiminuareB, n.den_taxa, N1.ROTVALOARE
    FROM ntaxe1 n1 INNER JOIN ntaxe n ON n1.codtaxa = n.codtaxa
    WHERE '||ANLUNALUCRU::varchar||' BETWEEN N1.ALSTART AND N1.ALSTOP';
    EXECUTE sInsert;

    UPDATE LUNA_RECORDS_FLAGS     SET NTAXE_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET NTAXE_FLG = 0;
  END IF;

  IF (NEEDREFRESHART = 1) AND (COALESCE(aNARTOBJ_FLG,0) = 0 or TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0) THEN
    --nartobj1
    TRUNCATE TABLE TMP_NARTOBJ_LUNA;

    sInsert := '
    INSERT INTO TMP_NARTOBJ_LUNA (
      CODOBIECT1,CODOBIECT,PRETMAXIMAL,PROCADAOSMAXIMAL,ADAOSLA,ANSTART,LUNASTART, PRETREFERINTA,TIPPRETMAX,COMPENSAT,TIPCOMPENSARE, GRUPA, UPLIFT, CODMONEDA,
      PUNCTE, Umiditate, CORPURI_STRAINE, Incoltit, Hectolitrica, Gluten, Fuzaritate, Cadere, Deformare, Sticlozitate, Sparturi, PUNCTESECTIE, TIPPRET,
      VALMAT, VALMAN, VALREGIE, D390EXCLUS, COST, CANTSERVAUTO,proteina, aflatoxina, atac_plosnita, continut_ulei, aciditate )
    SELECT
      CODOBIECT1,CODOBIECT,PRETMAXIMAL,PROCADAOSMAXIMAL,ADAOSLA,ANSTART,LUNASTART, PRETREFERINTA,TIPPRETMAX,COMPENSAT,TIPCOMPENSARE, GRUPA, UPLIFT, CODMONEDA,
      PUNCTE, Umiditate, CORPURI_STRAINE, Incoltit, Hectolitrica, Gluten, Fuzaritate, Cadere, Deformare, Sticlozitate, Sparturi, PUNCTESECTIE, TIPPRET,
      VALMAT, VALMAN, VALREGIE, D390EXCLUS, COST, CANTSERVAUTO,proteina, aflatoxina, atac_plosnita, continut_ulei, aciditate
    FROM nartobj1
    WHERE '||ANLUNALUCRU::varchar||' BETWEEN ALSTART AND ALSTOP';

    EXECUTE sInsert;

    UPDATE LUNA_RECORDS_FLAGS     SET NARTOBJ_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET NARTOBJ_FLG = 0;
  END IF;

  IF COALESCE(aTARIFE_FLG,0) = 0 or TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0 THEN
    --nartobj1
    TRUNCATE TABLE TMP_TARIFEMAN_LUNA;

    sInsert := '
    INSERT INTO TMP_TARIFEMAN_LUNA ( CODTARIF1, CODTARIF, TARIF, ANSTART, LUNASTART )
    SELECT T1.CODTARIF1, T1.CODTARIF, T1.TARIF, T1.ANSTART, T1.LUNASTART
    FROM tarifeman1 t1
    WHERE '||ANLUNALUCRU::varchar||' BETWEEN T1.ALSTART AND T1.ALSTOP';
    EXECUTE sInsert;

    UPDATE LUNA_RECORDS_FLAGS     SET TARIFE_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET TARIFE_FLG = 0;
  END IF;

  perform set_config('PKG_GLOBALS.LUNARECORDSFLAG',to_char(1,'999999999999999999'),false);
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_make_config_luna_ext</obj_name>
  <obj_hashval>66f7e69ecade8a3d7a5543d2c58fe4ef</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_make_config_luna_ext()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  AnLunaLucru   numeric;
  aUSER_ID      numeric := -1;
  aNART_FLG     numeric := 0;
  aNARTObj_FLG  numeric := 0;
  aIOART_FLG    numeric := 0;
  aNTVA_FLG     numeric := 0;
  aNTAXE_FLG    numeric := 0;
  aTARIFE_FLG   numeric := 0;
  aPRETM_FLG    numeric := 0;
  aIOPART_FLG   numeric := 0;
  aIOFILIAL_FLG numeric := 0;
  aIOBANK_FLG   numeric := 0;
  aIOPERS_FLG   numeric := 0;
begin
  perform set_config('PKG_GLOBALS.DATA0', '30.12.1899',false);

  BEGIN
    SELECT Coalesce( USERID, -1), Coalesce( NART_FLG, 0), Coalesce( NARTOBJ_FLG, 0), Coalesce( IOART_FLG, 0), Coalesce( NTVA_FLG, 0), Coalesce( NTAXE_FLG, 0),
           Coalesce( TARIFE_FLG, 0), Coalesce( PRETM_FLG, 0), Coalesce( IOPART_FLG, 0), Coalesce( IOFILIAL_FLG, 0), Coalesce( IOBANK_FLG, 0), Coalesce( IOPERS_FLG, 0)
    INTO aUSER_ID, aNART_FLG, aNARTObj_FLG, aIOART_FLG, aNTVA_FLG, aNTAXE_FLG, aTARIFE_FLG, aPRETM_FLG, aIOPART_FLG, aIOFILIAL_FLG, aIOBANK_FLG, aIOPERS_FLG
    FROM LUNA_RECORDS_FLAGS
    WHERE USERID = (SELECT USERID FROM TMP_PKG_GLOBALS);
  EXCEPTION WHEN OTHERS THEN
    NULL;
  END;

  IF  aUSER_ID = -1 THEN
    INSERT INTO LUNA_RECORDS_FLAGS(USERID, NART_FLG, NARTOBJ_FLG, IOART_FLG, NTVA_FLG, NTAXE_FLG, TARIFE_FLG, PRETM_FLG, IOPART_FLG, IOFILIAL_FLG, IOBANK_FLG, IOPERS_FLG)
    VALUES((SELECT USERID FROM TMP_PKG_GLOBALS), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

    INSERT INTO TMP_LUNA_RECORDS_FLAGS(USERID, NART_FLG, NARTOBJ_FLG, IOART_FLG, NTVA_FLG, NTAXE_FLG, TARIFE_FLG, PRETM_FLG, IOPART_FLG, IOFILIAL_FLG, IOBANK_FLG, IOPERS_FLG)
    VALUES((SELECT USERID FROM TMP_PKG_GLOBALS), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  END IF;

  AnLunaLucru := (SELECT PKG_GLOBALS_GETANLUCRU.WME_RESULT FROM PKG_GLOBALS_GETANLUCRU(NULL,NULL)) * 12 + (SELECT PKG_GLOBALS_GETLUNALUCRU.WME_RESULT FROM PKG_GLOBALS_GETLUNALUCRU(NULL,NULL));

  IF  aIOART_FLG = 0 or  TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0 THEN
    DELETE FROM tmp_ioart_luna;
    INSERT INTO TMP_IOART_LUNA(CODIOART1, CODIOART, CONT, DIFERENTE, CHELTUIELI, VENITURI, PLUSINVENTAR, MINUSINVENTAR, CHELTTVACOLECTAT, CONTROTUNJIRI, DIVERSE, CUSTODIE, ACCIZELATRANSFER, DESCARCAREG, CONTABGEST, BAZA, DIFPRET, ARETVANEEX, TVANEEX, MG, ANSTART, LUNASTART, PUSTANDARD, PROVIZION, CHELTPROVIZION, VENITPROVIZION, DEN_IOART, ESTEMIFIX, ESTEOBINV, ESTECUSTODIE)
    SELECT IO1.CODIOART1, IO1.CODIOART, IO1.CONT, IO1.DIFERENTE, IO1.CHELTUIELI, IO1.VENITURI, IO1.PLUSINVENTAR, IO1.MINUSINVENTAR, IO1.CHELTTVACOLECTAT, IO1.CONTROTUNJIRI, IO1.DIVERSE, IO1.CUSTODIE, IO1.ACCIZELATRANSFER, IO1.DESCARCAREG, IO1.CONTABGEST, IO1.BAZA, IO1.DIFPRET, IO1.ARETVANEEX, IO1.TVANEEX, IO1.MG, IO1.ANSTART, IO1.LUNASTART, IO1.PUSTANDARD, IO1.PROVIZION, IO1.CHELTPROVIZION, IO1.VENITPROVIZION, IO.DEN_IOART, (SELECT PKG_CATEGCONST_ESTEMIFIX.WME_RESULT FROM PKG_CATEGCONST_ESTEMIFIX(NULL, IO1.CONT)), (SELECT PKG_CATEGCONST_ESTEOBINV.WME_RESULT FROM PKG_CATEGCONST_ESTEOBINV(NULL, IO1.CONT)), (SELECT PKG_CATEGCONST_ESTECUSTODIE.WME_RESULT FROM PKG_CATEGCONST_ESTECUSTODIE(NULL, IO1.CONT))
    FROM IOART IO INNER JOIN IOART1 IO1 ON  IO.CODIOART = IO1.CODIOART
    WHERE ANLUNALUCRU BETWEEN IO1.ALStart AND IO1.ALStop;

    UPDATE LUNA_RECORDS_FLAGS     SET IOART_FLG = 1 WHERE UserID = (SELECT USERID FROM TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET IOART_FLG = 0;
  END IF;

  IF  aIOPART_FLG = 0 or  TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0 THEN
    DELETE FROM TMP_IOPART_CFGLUNA;
    INSERT INTO TMP_IOPART_CFGLUNA(CODIOPART1, CODIOPART, CONTFURNIZOR, CONTCLIENT, CONTFURNAVANS, CONTCLIENTAVANS, CONTFURNAVIZ, CONTCLIENTAVIZ, CONTFURNMF, CONTCREDITD, CONTDEBITD, CONTLITIGII, CONTFURNAVS, CONTFURNAVIC, CONTFURNAVIN, CONTTERTI, CONTFURNLEAS, CONTNCRF, CONTNCRC, CONTCHELTAVANS, CONTVENITAVANS, contgarantieEF, contgarantieTF, contgarantieEC, contgarantieTC, ContSuplimF1, ContSuplimF2, ContSuplimF3, ContSuplimF4, ContSuplimF5, ContSuplimC1, ContSuplimC2, ContSuplimC3, ContSuplimC4, ContSuplimC5, TVANEEXF, TVANEEXC, TVANEEXP, TVANEEXI, TIP)
    SELECT CODIOPART1, CODIOPART, CONTFURNIZOR, CONTCLIENT, CONTFURNAVANS, CONTCLIENTAVANS, CONTFURNAVIZ, CONTCLIENTAVIZ, CONTFURNMF, CONTCREDITD, CONTDEBITD, CONTLITIGII, CONTFURNAVS, CONTFURNAVIC, CONTFURNAVIN, CONTTERTI, CONTFURNLEAS, CONTNCRF, CONTNCRC, CONTCHELTAVANS, CONTVENITAVANS, contgarantieEF, contgarantieTF, contgarantieEC, contgarantieTC, ContSuplimF1, ContSuplimF2, ContSuplimF3, ContSuplimF4, ContSuplimF5, ContSuplimC1, ContSuplimC2, ContSuplimC3, ContSuplimC4, ContSuplimC5, TVANEEXF, TVANEEXC, TVANEEXP, TVANEEXI, TIP
    FROM IOPART1 n1
    WHERE AnLunaLucru BETWEEN N1.ALStart AND N1.ALStop;

    UPDATE LUNA_RECORDS_FLAGS     SET IOPART_FLG = 1 WHERE  USERID = (SELECT USERID FROM TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET IOPART_FLG = 0;
  END IF;

  IF  aIOFILIAL_FLG = 0 or  TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0 THEN
    DELETE FROM TMP_IOFILIAL_LUNA;
    INSERT INTO TMP_IOFILIAL_LUNA(CODIOFILIAL1, CODIOFILIAL, CONTDECONTARE, CONTDECONTAREF, ISFIRMA, CONTDECONTSERV, CONTDECONTCB, CONTDECONTCMP)
    SELECT CODIOFILIAL1, CODIOFILIAL, CONTDECONTARE, CONTDECONTAREF, ISFIRMA, CONTDECONTSERV, CONTDECONTCB, CONTDECONTCMP
    FROM IOFILIAL1 n1
    WHERE AnLunaLucru BETWEEN N1.ALStart AND N1.ALStop;

    UPDATE LUNA_RECORDS_FLAGS     SET IOFILIAL_FLG = 1 WHERE USERID = (SELECT USERID FROM TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET IOFILIAL_FLG = 0;
  END IF;

  IF  aIOBANK_FLG = 0 or  TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0 THEN
    DELETE FROM TMP_IOBANK_LUNA;
    INSERT INTO TMP_IOBANK_LUNA(CODIOBANK1, CODIOBANK, CONT, DOBANDA, COMISION, CHELTUIELICV, VENITURICV, PCEC, PEFECTE, PEFECTEREM, ICEC, IEFECTE, IEFECTEREM)
    SELECT CODIOBANK1, CODIOBANK, CONT, DOBANDA, COMISION, CHELTUIELICV, VENITURICV, PCEC, PEFECTE, PEFECTEREM, ICEC, IEFECTE, IEFECTEREM
    FROM IOBANK1 n1
    WHERE AnLunaLucru BETWEEN N1.ALStart AND N1.ALStop;

    UPDATE LUNA_RECORDS_FLAGS     SET IOBANK_FLG = 1 WHERE USERID = (SELECT USERID FROM TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET IOBANK_FLG = 0;
  END IF;

  IF  aIOPERS_FLG = 0 or  TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0 THEN
    DELETE FROM TMP_IOPERS_CFGLUNA;
    INSERT INTO TMP_IOPERS_CFGLUNA(CODIOPERS1, CODIOPERS, CONTAVANSDECONT, CONTIMPUTATII, CONTGARANTII, CONTALTERETINERI, CONTAVANS, CONTLIKI, CONTNERIDICATE, CONTBOALA, CONTPARTSAL, CONTNATURA, CONTECHIPAMENT, CONTIMPOZIT)
    SELECT CODIOPERS1, CODIOPERS, CONTAVANSDECONT, CONTIMPUTATII, CONTGARANTII, CONTALTERETINERI, CONTAVANS, CONTLIKI, CONTNERIDICATE, CONTBOALA, CONTPARTSAL, CONTNATURA, CONTECHIPAMENT, CONTIMPOZIT
    FROM IOPERS1 n1
    WHERE AnLunaLucru BETWEEN N1.ALStart AND N1.ALStop;

    UPDATE LUNA_RECORDS_FLAGS     SET IOPERS_FLG = 1 WHERE USERID = (SELECT USERID FROM TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET IOPERS_FLG = 0;
  END IF;

  IF  aPRETM_FLG = 0 or  TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0 THEN
    DELETE FROM TMP_MANPRETM;
    IF  Coalesce( (SELECT pkg_globals_GETSUBUNITATE.WME_RESULT FROM pkg_globals_GETSUBUNITATE(NULL,NULL)), 0) &lt;&gt; 1 THEN
      INSERT INTO TMP_MANPRETM
      SELECT CODOBIECT, LEI, VALUTA, SUBUNITATEA
      FROM PRETM PM, NCATPRET CAT
      WHERE CAT.CODCATPRET = PM.CODCATPRET AND  Coalesce( PM.subunitatea, 0) = Coalesce( (SELECT pkg_globals_GETSUBUNITATE.WME_RESULT FROM pkg_globals_GETSUBUNITATE(NULL,NULL)), 0) AND  Coalesce( PM.IMPLICIT, 0) = 1 AND CAT.TIP IN (1, 2);

      UPDATE LUNA_RECORDS_FLAGS     SET PRETM_FLG = 1 WHERE USERID = (SELECT USERID FROM TMP_PKG_GLOBALS);
      UPDATE TMP_LUNA_RECORDS_FLAGS SET PRETM_FLG = 0;
    END IF;
  END IF;

  IF  aNART_FLG = 0 or  TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0 THEN
    DELETE FROM tmp_nart_luna;
    INSERT INTO tmp_nart_luna(codarticol1, codarticol, codtva, codaccize, codtaxa1, codtaxa2, anstart, lunastart)
    SELECT codarticol1, codarticol, codtva, codaccize, codtaxa1, codtaxa2, anstart, lunastart
    FROM nart1 n1
    WHERE AnLunaLucru BETWEEN N1.ALStart AND N1.ALStop;

    UPDATE LUNA_RECORDS_FLAGS     SET NART_FLG = 1 WHERE USERID = (SELECT USERID FROM TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET NART_FLG = 0;
  END IF;

  IF  aNTVA_FLG = 0 or  TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0 THEN
    DELETE FROM tmp_ntva_luna;
    INSERT INTO tmp_ntva_luna(codtva1, codtva, procent, codcontded, codcontcole, codcontneex, anstart, lunastart, den_tva)
    SELECT n1.codtva1, n1.codtva, n1.procent, n1.codcontded, n1.codcontcole, n1.codcontneex, n1.anstart, n1.lunastart, n.den_tva
    FROM ntva1 n1 INNER JOIN ntva n ON  n1.codtva = n.codtva
    WHERE AnLunaLucru BETWEEN N1.ALStart AND N1.ALStop;

    UPDATE LUNA_RECORDS_FLAGS     SET NTVA_FLG = 1 WHERE USERID = (SELECT USERID FROM TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET NTVA_FLG = 0;
  END IF;

  IF  aNTAXE_FLG = 0 or  TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0 THEN
    DELETE FROM tmp_ntaxe_luna;
    INSERT INTO tmp_ntaxe_luna(CODTAXA1, CODTAXA, VALOARE, LACEAPLIC, CODCONT, CODCONTCHELT, ORICARETIP, CODIOARTEXCL, EXCLUSACCIZE, EXCLUSEXPORT, JACHIZ, JVANZ, CUMJACHIZ, CUMJVANZ, BazaMax, BazaMin, CODSERVFACT, FACTURABIL, STOPAJ, ANSTART, LUNASTART, SERVICIUMONETAR, ProcDiminuareB, DEN_TAXA, Rotvaloare)
    SELECT n1.CODTAXA1, n1.CODTAXA, n1.VALOARE, n1.LACEAPLIC, n1.CODCONT, n1.CODCONTCHELT, n1.ORICARETIP, n1.CODIOARTEXCL, n1.EXCLUSACCIZE, n1.EXCLUSEXPORT, n1.JACHIZ, n1.JVANZ, n1.CUMJACHIZ, n1.CUMJVANZ, n1.BazaMax, n1.BazaMin, n1.CODSERVFACT, n1.FACTURABIL, n1.STOPAJ, n1.ANSTART, n1.LUNASTART, n1.SERVICIUMONETAR, n1.ProcDiminuareB, n.den_taxa, N1.ROTVALOARE
    FROM ntaxe1 n1 INNER JOIN ntaxe n ON  n1.codtaxa = n.codtaxa
    WHERE AnLunaLucru BETWEEN N1.ALStart AND N1.ALStop;

    UPDATE LUNA_RECORDS_FLAGS     SET NTAXE_FLG = 1 WHERE USERID = (SELECT USERID FROM TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET NTAXE_FLG = 0;
  END IF;

  IF  aNARTOBJ_FLG = 0 or  TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0 THEN
    DELETE FROM TMP_NARTOBJ_LUNA;
    INSERT INTO TMP_NARTOBJ_LUNA(CODOBIECT1, CODOBIECT, PRETMAXIMAL, PROCADAOSMAXIMAL, ADAOSLA, ANSTART, LUNASTART,
                                 PRETREFERINTA, TIPPRETMAX, COMPENSAT, TIPCOMPENSARE, GRUPA, UPLIFT, codmoneda, PUNCTE, Umiditate, CORPURI_STRAINE, Incoltit, Hectolitrica, Gluten, Fuzaritate, Cadere, Deformare, Sticlozitate, Sparturi, PUNCTESECTIE, TIPPRET,
                                 VALMAT, VALMAN, VALREGIE, D390EXCLUS, COST, CANTSERVAUTO, proteina, aflatoxina, atac_plosnita, continut_ulei, aciditate, SISTAVE, REFRACTIE, INDICE_W, TOXINA_DON, BOABE_TOXICE)
    SELECT CODOBIECT1,CODOBIECT,PRETMAXIMAL,PROCADAOSMAXIMAL,ADAOSLA,ANSTART,LUNASTART,
           PRETREFERINTA,TIPPRETMAX,COMPENSAT,TIPCOMPENSARE, GRUPA, UPLIFT,codmoneda, PUNCTE, Umiditate, CORPURI_STRAINE, Incoltit, Hectolitrica, Gluten, Fuzaritate, Cadere, Deformare, Sticlozitate, Sparturi, PUNCTESECTIE, TIPPRET,
           VALMAT, VALMAN, VALREGIE, D390EXCLUS, COST, CANTSERVAUTO,proteina, aflatoxina, atac_plosnita, continut_ulei, aciditate, SISTAVE, REFRACTIE, INDICE_W, TOXINA_DON, BOABE_TOXICE
    FROM nartobj1 n1
    WHERE AnLunaLucru BETWEEN N1.ALStart AND N1.ALStop;

    UPDATE LUNA_RECORDS_FLAGS     SET NARTOBJ_FLG = 1 WHERE USERID = (SELECT USERID FROM TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET NARTOBJ_FLG = 0;
  END IF;

  IF  aTARIFE_FLG = 0 or  TO_NUMBER((current_setting('PKG_GLOBALS.LUNARECORDSFLAG', true)),'999999999999999999') = 0 THEN
    DELETE FROM TMP_TARIFEMAN_LUNA;
    INSERT INTO TMP_TARIFEMAN_LUNA ( CODTARIF1, CODTARIF, TARIF, ANSTART, LUNASTART )
    SELECT T1.CODTARIF1, T1.CODTARIF, T1.TARIF, T1.ANSTART, T1.LUNASTART
    FROM tarifeman1 t1
    WHERE AnLunaLucru BETWEEN t1.ALStart AND t1.ALStop;


    UPDATE LUNA_RECORDS_FLAGS SET TARIFE_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET TARIFE_FLG = 0;
  END IF;

  perform set_config('PKG_GLOBALS.LUNARECORDSFLAG',to_char(1,'999999999999999999'),false);
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_make_stoc_generare_facturi</obj_name>
  <obj_hashval>1c095e4931e1df6f807e52b4f5596346</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_make_stoc_generare_facturi()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  sInsert       varchar;
  sFilter       varchar :='';
  nr            numeric;
  subDedicata   numeric;
  pUserName     varchar;
  pUser         varchar;
  CONDITIE_STOC varchar;
  aCODLINIECOMANDA numeric :=  Coalesce (current_setting ('PKG_STOC_GENERARE_FACTURI.CODLINIECOMANDA', true)::numeric , 0);
BEGIN
  --Florin 11.11.2022 - sinc. Oracle
  --Gabi 10.03.2022
  --Florin 04.12.2020 - fixat #41146
  --Florin 05.02.2021 - fixat #42583
  --Florin 11.01.2022 - sinc. Oracle
  --Bogdan 02.02.2022 - 52903 PG - Generator comenzi clienti - eroare
  PERFORM PKG_STOC_GENERARE_FACTURI_make_config_luna();



   IF Coalesce (current_setting ('PKG_STOC_GENERARE_FACTURI.INCLUSIV_STOC_ZERO', true)::numeric , 0) = 1 THEN
    CONDITIE_STOC := ' 1 = 1 ';
  ELSE
    CONDITIE_STOC := ' NS.REST &lt;&gt; 0 ';
  END IF;



  sInsert := 'SELECT * FROM(
            SELECT O.DENUMIRE AS DENOBIECT,
              O.CODEXTERN,
              O.CODINTERN,
              U1.DEN_UM1 AS DENUMSTOCARE,
              U.DEN_UM   AS DENUM,
              U.CODUM,
              NS.CODNIRSTOC,
              NS.UMSEC,
              NS.CODOBIECT,
              NS.CODIOART,
              NIRCURENT.GEST,
              NS.PRET - Coalesce (NS.ADAOS, 0) AS PRETACHIZ,
              NS.PRET                          AS PRET,
              Coalesce (NS.ADAOS, 0)           AS ADAOS,
              NS.TVA,
              NS.TIPSERIE,
              CASE
                WHEN NS.TIPSERIE &gt; 0
                    THEN NSE.REST - Coalesce((SELECT SUM(CANT) FROM STOCLOCK WHERE CODNIRSER  = NSE.CODNIRSER), 0) - Coalesce((SELECT SUM(REST) FROM REZERVATS WHERE CODNIRSER  = NSE.CODNIRSER AND CODCOMANDA1 &lt;&gt; ' || aCODLINIECOMANDA::varchar ||' ), 0)
                    ELSE NS.REST  - Coalesce((SELECT SUM(CANT) FROM STOCLOCK WHERE CODNIRSTOC = NS.CODNIRSTOC), 0) - Coalesce((SELECT SUM(REST) FROM REZERVATS WHERE CODNIRSTOC = NS.CODNIRSTOC AND CODCOMANDA1 &lt;&gt; ' || aCODLINIECOMANDA::varchar ||' ), 0)
                END AS STOC,
              NS.PROCENTADAOS,
              NIRCURENT.DATANIR AS INTRATLA,
              Coalesce (NSE.TG, NS.TG)  TG,
              NS.PUMAXIMAL,
              NS.FURN AS CODPART,
              CASE
                WHEN NS.TIPSERIE &gt; 0 THEN (SELECT SERIE FROM NSERII WHERE CODSERIE = NSE.CODSERIE)
                ELSE ''''
              END  AS SERIE,
              Coalesce (NSE.CODNIRSER, 0)    CODNIRSER,
              NSE.CODSERIE,
              NS.DATAACHIZ,
              NS.TIPDOCACHIZ,
              NIRCURENT.TIPNIR AS TIPINTRARESTOC,
              L.DENUMIRE       AS LOCATIE,
              NART1LUNA.CODTVA,
              Coalesce (TVALUNA.PROCENT, -1) AS PROCTVA,
              NART1LUNA.CODACCIZE,
              NART1LUNA.CODTAXA1,
              NART1LUNA.CODTAXA2,
              A.TIPARTICOL,
              O.TERMENPLATA,
              O.ADAOSEXCEPTIE,
              P.DEN_PART AS DENFURN,
              ('' '')::varchar      AS SUPLIMENT,
              CAR.DEN_CARSUPART,
              NARTOBJ1LUNA.TIPCOMPENSARE,
              G.DEN_GEST,
              IOART.DEN_IOART,
              PROD.DEN_PART AS PRODUCATOR,
              O.ROTUNJIRE   AS ROTLEI,
              NARTOBJ1LUNA.GRUPA,
              O.BLOCAT,
              O.PROMOTIE,
              CL.DEN_CLASEA,
              A.CLASA,
              NS.DISCLIKISTOC,
              A.UM1,
              A.RELATIEUM1,
              NS.RESTUM1,
              NS.D1,
              NS.D2,
              NS.D3,
              NSE.CODCERTIF,
              C.NRCERTIF,
              NSE.STARE,
              NSE.DATAPROD,
              NSE.OBS,
              IOALUNA.DIFPRET,
              NS.CODGESTPROD,
              GPROD.DEN_GEST AS DENGESTPROD,
              O.NEFACTURABIL,
              NS.PROVIZION,
              A.DCI,
              NS.CODLOCATIE,
              G.CODSUBUNIT,
              S.DEN_SUBUNIT
            FROM NIRSTOC                 NS
              LEFT JOIN NGEST            GPROD        ON GPROD.CODGEST  = NS.CODGESTPROD
              LEFT JOIN NPART            P            ON P.CODPART      = NS.FURN
              LEFT JOIN NIRSER           NSE          ON NSE.CODNIRSTOC = NS.CODNIRSTOC
              LEFT JOIN NLOCATII         L            ON L.CODLOCATIE   = Coalesce (NS.CODLOCATIE, 0)
              LEFT JOIN CERTIF           C            ON C.CODCERTIF    = NSE.CODCERTIF
              INNER JOIN NIR              NIRCURENT    ON NIRCURENT.CODNIR       = NS.CODNIR
          INNER JOIN NGEST            G            ON G.CODGEST              = NIRCURENT.GEST
          INNER JOIN NSUBUNIT         S            ON G.CODSUBUNIT           = S.CODSUBUNIT
          INNER JOIN NARTOBJ          O            ON O.CODOBIECT            = NS.CODOBIECT
          INNER JOIN NART             A            ON A.CODARTICOL           = O.CODARTICOL
              LEFT JOIN NPART            PROD         ON PROD.CODPART           = O.CODPRODUCATOR
              LEFT JOIN tmp_nartobj_luna NARTOBJ1LUNA ON NARTOBJ1LUNA.CODOBIECT = o.codobiect
              LEFT JOIN NCARSUPART       CAR          ON CODCARSUPART           = O.CODCARACT
              LEFT JOIN tmp_nart_luna    NART1LUNA    ON NART1LUNA.CODARTICOL = A.CODARTICOL
              LEFT JOIN tmp_ntva_luna    TVALUNA      ON TVALUNA.CODTVA       = NART1LUNA.CODTVA
              LEFT JOIN NCLASEA          CL           ON CL.CODCLASEA         = A.CLASA
              INNER JOIN NUM1             U1           ON U1.CODUM1              = NS.UMSEC
              INNER JOIN NUM              U            ON U.CODUM                = U1.CODUM
              INNER JOIN IOART                         ON IOART.CODIOART         = NS.CODIOART
              INNER JOIN tmp_ioart_luna   ioaluna      ON IOALUNA.CODIOART       = NS.CODIOART
            WHERE
              ' || CONDITIE_STOC || '
              AND (SELECT COUNT(*) FROM REZERVATS R WHERE REST &gt; 0 AND Coalesce (R.CODINVENTAR1, 0) &lt;&gt; 0 AND R.CODNIRSTOC = NS.CODNIRSTOC) = 0
              AND (IOALUNA.MG &lt;&gt; 5)'
          || (coalesce(current_setting ('PKG_STOC_GENERARE_FACTURI.FILTRUMEDEX', true),''));

  IF current_setting ('PKG_CONFIGART.CODIOART_FILTRU_GENERATOR', true)::numeric&gt; 0 THEN
    sFilter := ' AND IOALUNA.CODIOART= ' || coalesce(current_setting ('PKG_CONFIGART.CODIOART_FILTRU_GENERATOR', true),'');
  END IF;

  IF current_setting ('PKG_NOMGEST.GEST_FILTRU_GENERATOR', true)::numeric &gt; 0 THEN
    sFilter := sFilter || ' AND NIRCURENT.GEST= ' || coalesce(current_setting ('PKG_NOMGEST.GEST_FILTRU_GENERATOR', true),'');
  END IF;

  IF current_setting ('PKG_CLASEART.CODCLASA_FILTRU_GENERATOR', true)::numeric &gt; 0 THEN
    sFilter := sFilter
    || ' AND A.CLASA = ' || coalesce(current_setting ('PKG_CLASEART.CODCLASA_FILTRU_GENERATOR', true),'');
  END IF;

  SELECT COUNT ( *) INTO nr FROM tmp_gestdedicate;

  IF nr &gt; 0 THEN
    sFilter := sFilter || ' AND EXISTS (SELECT CODGEST FROM TMP_GESTDEDICATE WHERE CODGEST = NIRCURENT.GEST) ';
  END IF;

  subDedicata := (   SELECT PKG_GLOBALS_GETSUBUNITATE.WME_RESULT FROM PKG_GLOBALS_GETSUBUNITATE (NULL,NULL));
  IF subDedicata &gt; 1 THEN
    sFilter := sFilter || ' AND G.CODSUBUNIT = ' || coalesce(subDedicata::varchar,'');
  END IF;

  sInsert := sInsert || sFilter || ') a_pg ';

  IF length (trim ( (current_setting ('PKG_STOC_GENERARE_FACTURI.INTERFACEFILTER', true)))) &gt; 0 THEN
    sInsert := sInsert || ' WHERE ' || (current_setting ('PKG_STOC_GENERARE_FACTURI.INTERFACEFILTER', true));
  END IF;

  IF current_setting ('PKG_STOC_GENERARE_FACTURI.MODLIVRAUTOMATA', true)::numeric = 0 THEN
    SINSERT := SINSERT || ' ORDER BY DENOBIECT, Coalesce(TG, TO_DATE(''01.01.1900'', ''dd.mm.yyyy'')), DATAACHIZ, SERIE';
  ELSE
    SINSERT := SINSERT || ' ORDER BY DENOBIECT, DATAACHIZ, SERIE';
  END IF;

  SELECT (current_setting ('PKG_GLOBALS.USERNAME', true)) INTO pUserName;

  SELECT (SELECT USERID FROM TMP_PKG_GLOBALS) INTO pUser;

  perform set_config ('PKG_STOC_GENERARE_FACTURI.g_viewName','V_STOC_GEN_FACT_' || pUser,false);

  EXECUTE 'CREATE OR REPLACE VIEW ' || (current_setting ('PKG_STOC_GENERARE_FACTURI.g_ViewName', true))
  || ' AS '
  || sInsert;

  EXECUTE 'GRANT SELECT ON '
  || (current_setting ('PKG_STOC_GENERARE_FACTURI.g_viewName', true))
  || ' TO '
  || pUserName;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stociniart_sp_gotorecord</obj_name>
  <obj_hashval>c94e9760cdd2089837188a16e24362ac</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stociniart_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCODGEST numeric;
BEGIN
  --Florin 29.06.2022
  PERFORM PKG_STOC_GENERARE_FACTURI_MAKE_CONFIG_LUNA();

  INSERT INTO TMP_STOCINI
  SELECT * FROM STOCINI WHERE CODSTOCINI = RECID;

  IF  RECID &gt; 0 THEN
    SELECT COALESCE( CODGEST, 0) INTO aCODGEST FROM TMP_STOCINI;
  END IF;

  INSERT INTO TMP_OBJSTOCINI(CODOBIECT, DENOBIECT, TIPSERIE, ARETG, CERTIFICAT, CONTIMPLICIT, PUMAXIMAL, D1, D2, D3, STOCTOTAL)
  (
  SELECT NS.CODOBIECT, O.DENUMIRE, A.TIPSERIE, A.ARETG, A.CERTIFICAT, A.CONTIMPLICIT, OBJLUNA.PRETMAXIMAL, A.D1, A.D2, A.D3, SUM( CANTNIR)
  FROM NIRSTOC NS, NARTOBJ O LEFT JOIN TMP_NARTOBJ_LUNA OBJLUNA ON  OBJLUNA.CODOBIECT = O.CODOBIECT, NART A
  WHERE O.CODOBIECT = NS.CODOBIECT AND  A.CODARTICOL = O.CODARTICOL
    AND (EXISTS (SELECT CODNIR FROM NIR N
                 WHERE N.CODNIR = NS.CODNIR AND  GEST = aCODGEST
                   AND  EXISTS (SELECT CODINTR FROM INTRARI
                                WHERE CODINTR = N.CODINTR AND  AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_GLOBALS.ANINITIAL', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_GLOBALS.LUNAINITIALA', true)),'999999999999999999')
                               )
                )
         OR
         EXISTS (SELECT CODNIR FROM NIR N
                  WHERE N.CODNIR = NS.CODNIR AND  GEST = aCODGEST
                    AND  EXISTS (SELECT CODTRANSF FROM TRANSF
                                WHERE CODTRANSF = N.CODTRANSF AND  AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_GLOBALS.ANINITIAL', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_GLOBALS.LUNAINITIALA', true)),'999999999999999999')
                               )
                )
        )
  GROUP BY NS.CODOBIECT, O.DENUMIRE, A.TIPSERIE, A.ARETG, A.CERTIFICAT, A.CONTIMPLICIT, OBJLUNA.PRETMAXIMAL, a.D1, a.D2, a.D3
  );

  UPDATE TMP_OBJSTOCINI O
  SET
  CODOBJSTOCINI = ROWNUM,
  DENUM         = (SELECT PKG_UMSEC_GETDENUM.WME_RESULT
                   FROM PKG_UMSEC_GETDENUM(NULL, (SELECT UM FROM NART WHERE CODARTICOL = (SELECT PKG_SELECTARTICOLE_GETARTOFOBJECT.WME_RESULT FROM PKG_SELECTARTICOLE_GETARTOFOBJECT(NULL, CODOBIECT))))
                  ),
  UMSEC         = (SELECT PKG_UMSEC_GETCODUMIMPLICITA.WME_RESULT
                   FROM PKG_UMSEC_GETCODUMIMPLICITA(NULL, (SELECT UM FROM NART WHERE CODARTICOL = (SELECT PKG_SELECTARTICOLE_GETARTOFOBJECT.WME_RESULT FROM PKG_SELECTARTICOLE_GETARTOFOBJECT(NULL, CODOBIECT))))
                  ),
  TVA           = fnc_getprocenttvaart(
    (SELECT PKG_SELECTARTICOLE_GETARTOFOBJECT.WME_RESULT FROM PKG_SELECTARTICOLE_GETARTOFOBJECT(NULL, CODOBIECT)),
    TO_NUMBER((current_setting('PKG_GLOBALS.ANINITIAL', true)),'999999999999999999'),
    TO_NUMBER((current_setting('PKG_GLOBALS.LUNAINITIALA', true)),'999999999999999999')) / 100,
  (UM1, UM2, RELATIEUM1, RELATIEUM2) = (SELECT COALESCE( UM1, 0), COALESCE( UM2, 0), COALESCE( RELATIEUM1, 0), COALESCE( RELATIEUM2, 0) FROM NART A
                                        WHERE A.CODARTICOL = (SELECT PKG_SELECTARTICOLE_GETARTOFOBJECT.WME_RESULT FROM PKG_SELECTARTICOLE_GETARTOFOBJECT(NULL, O.CODOBIECT))
                                       );

  INSERT INTO TMP_NIRSTOCINI(CODNIRSTOC, CODNIR, CODINTR1, CODINTR, DATADOC, CODOBIECT, CODIOART, UMSEC, PRETACHIZ, PRETINREG, TVA, TG, TIPSERIE, CANTNIR, CODLOCATIE, FURNIZOR, INITIALIZARI, PUMAXIMAL, CANTUM1, CANTUM2, PROCENTADAOS, DENUM, PARITATE, D1, D2, D3, NRCERTIF)
  (
  SELECT NS.CODNIRSTOC, NS.CODNIR, I1.CODINTR1, I.CODINTR, I.DATADOC, NS.CODOBIECT, NS.CODIOART, NS.UMSEC, (  NS.PRET - NS.ADAOS)  * U1.PARITATE, NS.PRET * U1.PARITATE, NS.TVA, NS.TG, NS.TIPSERIE, NS.CANTNIR / U1.PARITATE, NS.CODLOCATIE, I.PARTENER, I.INITIALIZARI, NS.PUMAXIMAL * U1.PARITATE, NS.CANTUM1, NS.CANTUM2, NS.PROCENTADAOS, U1.DEN_UM1, U1.PARITATE, NS.D1, NS.D2, NS.D3, I1.NRCERTIF
  FROM NIRSTOC NS
      LEFT JOIN NIR      N  ON  N.CODNIR    = NS.CODNIR
      LEFT JOIN INTRARI1 I1 ON  I1.CODINTR1 = NS.CODINTR1
      LEFT JOIN INTRARI  I  ON  I.CODINTR   = N.CODINTR, NUM1 U1
  WHERE N.GEST = aCODGEST AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_GLOBALS.ANINITIAL', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_GLOBALS.LUNAINITIALA', true)),'999999999999999999') AND  NS.UMSEC = U1.CODUM1 AND  N.TIPNIR &lt; 10
  );

  INSERT INTO TMP_NIRSTOCINI(CODNIRSTOC, CODNIR, CODINTR1, CODINTR, DATADOC, CODOBIECT, CODIOART, UMSEC, PRETACHIZ, PRETINREG, TVA, TG, TIPSERIE, CANTNIR, CODLOCATIE, FURNIZOR, INITIALIZARI, PUMAXIMAL, CANTUM1, CANTUM2, PROCENTADAOS, DENUM, PARITATE, D1, D2, D3, NRCERTIF)
  (
  SELECT NS.CODNIRSTOC, NS.CODNIR, I1.CODINTR1, I.CODINTR, I.DATADOC, NS.CODOBIECT, NS.CODIOART, NS.UMSEC, (  NS.PRET - NS.ADAOS)  * U1.PARITATE, NS.PRET * U1.PARITATE, NS.TVA, NS.TG, NS.TIPSERIE, NS.CANTNIR / U1.PARITATE, NS.CODLOCATIE, I.PARTENER, I.INITIALIZARI, NS.PUMAXIMAL * U1.PARITATE, NS.CANTUM1, NS.CANTUM2, NS.PROCENTADAOS, U1.DEN_UM1, U1.PARITATE, NS.D1, NS.D2, NS.D3, I1.NRCERTIF
  FROM NIRSTOC NS
      LEFT JOIN NIR       N  ON  N.CODNIR    = NS.CODNIR
      LEFT JOIN INTRARI1  I1 ON  I1.CODINTR1 = NS.CODINTR1
      LEFT JOIN INTRARI   I  ON  I.CODINTR   = N.CODINTR
      LEFT JOIN IESIRI    E  ON  E.CODIES    = N.CODIES, NUM1 U1
  WHERE N.GEST = aCODGEST AND  E.AN * 12 + E.LUNA &lt; TO_NUMBER((current_setting('PKG_GLOBALS.ANINITIAL', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_GLOBALS.LUNAINITIALA', true)),'999999999999999999') AND  NS.UMSEC = U1.CODUM1 AND  N.TIPNIR &gt;= 14
  );

  INSERT INTO TMP_NIRSTOCINI(CODNIRSTOC, CODNIR, CODTRANSF1, CODTRANSF, DATADOC, CODOBIECT, CODIOART, UMSEC, PRETACHIZ, PRETINREG, TVA, TG, TIPSERIE, CANTNIR, CODLOCATIE, FURNIZOR, PUMAXIMAL, CANTUM1, CANTUM2, PROCENTADAOS, DENUM, PARITATE)
  (
  SELECT NS.CODNIRSTOC, NS.CODNIR, T1.CODTRANSF1, T.CODTRANSF, T.DATADOC, NS.CODOBIECT, NS.CODIOART, NS.UMSEC, (  NS.PRET - NS.ADAOS)  * U1.PARITATE, NS.PRET * U1.PARITATE, NS.TVA, NS.TG, NS.TIPSERIE, NS.CANTNIR / U1.PARITATE, NS.CODLOCATIE, NS.FURN, NS.PUMAXIMAL * U1.PARITATE, NS.CANTUM1, NS.CANTUM2, NS.PROCENTADAOS, U1.DEN_UM1, U1.PARITATE
  FROM NIRSTOC NS
      LEFT JOIN NIR     N  ON  N.CODNIR      = NS.CODNIR
      LEFT JOIN TRANSF1 T1 ON  T1.CODTRANSF1 = NS.CODTRANSF1
      LEFT JOIN TRANSF  T  ON  T.CODTRANSF   = N.CODTRANSF, NUM1 U1
  WHERE N.GEST = aCODGEST AND  T.AN * 12 + T.LUNA &lt; TO_NUMBER((current_setting('PKG_GLOBALS.ANINITIAL', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_GLOBALS.LUNAINITIALA', true)),'999999999999999999') AND  NS.UMSEC = U1.CODUM1 AND N.TIPNIR IN (12, 13)
  );

  INSERT INTO TMP_NIRSERINI(CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, CANTUM1, CANTUM2, OBS, CodCertif, DataProd, Stare, SERIE, NRCERTIF, TG)
  (
  SELECT CODNIRSER, CODNIRSTOC, NS.CODSERIE, CANTNIR, CANTUM1, CANTUM2, NS.OBS, NS.CodCertif, NS.DataProd, NS.Stare,
         COALESCE( (SELECT SERIE FROM NSERII WHERE CODSERIE = NS.CODSERIE), ''), C.NRCERTIF, NS.TG
  FROM NIRSER NS LEFT JOIN CERTIF C ON  C.CODCERTIF = NS.CODCERTIF
  WHERE CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_NIRSTOCINI));

  UPDATE TMP_NIRSTOCINI NS
  SET
  CODOBJSTOCINI = (SELECT CODOBJSTOCINI FROM TMP_OBJSTOCINI WHERE CODOBIECT = NS.CODOBIECT),
  (MG, DIFPRET, ARETVANEEX, PUSTANDARD) = (SELECT MG, DIFPRET, ARETVANEEX, PUSTANDARD FROM TMP_IOART_LUNA I1 WHERE I1.CODIOART = NS.CODIOART);

  UPDATE TMP_NIRSERINI NSE
  SET
  PARITATE = COALESCE( (SELECT PARITATE FROM TMP_NIRSTOCINI WHERE CODNIRSTOC = NSE.CODNIRSTOC LIMIT 1), 1),
  CANTNIR  = CANTNIR / COALESCE( (SELECT PARITATE FROM TMP_NIRSTOCINI WHERE CODNIRSTOC = NSE.CODNIRSTOC LIMIT 1), 1),
  CANTUM1  = CANTUM1 / COALESCE( (SELECT PARITATE FROM TMP_NIRSTOCINI WHERE CODNIRSTOC = NSE.CODNIRSTOC LIMIT 1), 1),
  CANTUM2  = CANTUM2 / COALESCE( (SELECT PARITATE FROM TMP_NIRSTOCINI WHERE CODNIRSTOC = NSE.CODNIRSTOC LIMIT 1), 1);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stociniart_sp_postrecords</obj_name>
  <obj_hashval>1ce34ceef934874b296627c04a95d59e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stociniart_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC       RECORD;
  V_RECNIRSER RECORD;
  ANI         numeric;
  LUNAI       numeric;
  vCODINTR    numeric;
  vCODINTR1   numeric;
  vCODNIR     numeric;
  vCODNIRSTOC numeric;
  aGEST       numeric;
  aPERS       numeric;
  aCODSERIE   numeric;
  NOMSERIE    varchar;
  vCODNIRSER  numeric;
BEGIN
  --Adina 17.08.2021 - sinc.Oracle din 17.08.2021
  PERFORM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( TO_NUMBER((current_setting('PKG_GLOBALS.ANINITIAL', true)),'999999999999999999'), TO_NUMBER((current_setting('PKG_GLOBALS.LUNAINITIALA', true)),'999999999999999999'), ANI, LUNAI);

  SELECT CODGEST, CODPERS INTO aGEST, aPERS FROM TMP_STOCINI;
  IF  OPERATION = 0 THEN
    SELECT CODSTOCINI INTO RecId FROM TMP_STOCINI;

    UPDATE STOCINI
    SET
    CODGEST = aGEST,
    CODPERS = aPERS
    WHERE
     CODSTOCINI = RecID;

    FOR V_REC IN (SELECT * FROM NIRSER
                  WHERE CODNIRSTOC IN (SELECT NS.CODNIRSTOC
                                       FROM NIRSTOC NS
                                          LEFT JOIN NIR     N ON  N.CODNIR  = NS.CODNIR
                                          LEFT JOIN INTRARI I ON  I.CODINTR = N.CODINTR
                                       WHERE N.GEST = aGEST AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_GLOBALS.ANINITIAL', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_GLOBALS.LUNAINITIALA', true)),'999999999999999999')
                                      )
                    AND CODNIRSER  IN (SELECT CODNIRSER FROM TMP_NIRSERINI)
                 )
    LOOP
      DELETE FROM NIRSERLUNA WHERE CODNIRSER = v_rec.CODNIRSER;
      DELETE FROM NIRSER     WHERE CODNIRSER = V_REC.CODNIRSER;
    END LOOP;

    FOR V_REC IN (SELECT NS.CODNIRSTOC, NS.CODNIR, I1.CODINTR1, I.CODINTR
                  FROM NIRSTOC NS
                      LEFT JOIN NIR      N  ON  N.CODNIR    = NS.CODNIR
                      LEFT JOIN INTRARI1 I1 ON  I1.CODINTR1 = NS.CODINTR1
                      LEFT JOIN INTRARI  I  ON  I.CODINTR   = N.CODINTR
                  WHERE N.GEST = aGEST AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_GLOBALS.ANINITIAL', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_GLOBALS.LUNAINITIALA', true)),'999999999999999999')
                    AND NS.CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_NIRSTOCINI)
                 )
    LOOP
      DELETE FROM NIRSER  WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
      DELETE FROM NIRLUNA WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
      DELETE FROM NIRSTOC WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_NIRSTOCINI) LOOP
      IF  V_REC.CODNIRSTOC &lt; 0 THEN
        SELECT NEXTVAL('SEQ_INTRARI_CODINTR')    INTO vCODINTR;
        SELECT NEXTVAL('SEQ_INTRARI1_CODINTR1')  INTO vCODINTR1;
        SELECT NEXTVAL('SEQ_NIR_CODNIR')         INTO vCODNIR;
        SELECT NEXTVAL('SEQ_NIRSTOC_CODNIRSTOC') INTO vCODNIRSTOC;

        INSERT INTO INTRARI(CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, DATADOC, PARTENER, AN, LUNA, SUBUNITATEA)
        VALUES(vCODINTR, 1, 0, 0, 1, 'F', v_rec.DATADOC, v_rec.FURNIZOR, ANI, LUNAI, TO_NUMBER((current_setting('PKG_GLOBALS.SUBUNITATE_DOC', true)),'999999999999999999'));

        INSERT INTO INTRARI1(CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, UMSEC, AN, LUNA, CODOBIECT, PRETORIG, PU, CANT, TG, PUMAXIMAL, NRCERTIF)
        VALUES(vCODINTR1, vCODINTR, 1, '=', V_REC.UMSEC, ANI, LUNAI, v_rec.CODOBIECT, v_rec.PRETACHIZ / V_REC.PARITATE, v_rec.PRETACHIZ / V_REC.PARITATE, v_rec.CANTNIR * V_REC.PARITATE, v_rec.TG, V_REC.PUMAXIMAL / V_REC.PARITATE, V_REC.NRCERTIF);

        INSERT INTO NIR(CODNIR, CODINTR, DATANIR, GEST, TIPNIR, ANULAT, BLOCAT, OPERAT)
        VALUES(vCODNIR, vCODINTR, v_rec.DATADOC, aGEST, 1, 0, 0, 1);

        INSERT INTO NIRSTOC(CODNIRSTOC, CODNIR, CODINTR1, CANTNIR, REST, UMSEC, CODOBIECT, CODIOART, PRET, ADAOS, TVA, TIPSERIE, FURN, DATAACHIZ, TIPDOCACHIZ, PUMAXIMAL, CODLOCATIE, TG, CANTUM1, RESTUM1, CANTUM2, RESTUM2, PROCENTADAOS, D1, D2, D3)
        VALUES(vCODNIRSTOC, vCODNIR, vCODINTR1, v_rec.CANTNIR * V_REC.PARITATE, v_rec.CANTNIR * V_REC.PARITATE, V_REC.UMSEC, V_REC.CODOBIECT, V_REC.CODIOART, V_REC.PRETINREG / V_REC.PARITATE, (  V_REC.PRETINREG - V_REC.PRETACHIZ)  / V_REC.PARITATE, V_REC.TVA, V_REC.TIPSERIE, V_REC.FURNIZOR, V_REC.DATADOC, 1, V_REC.PUMAXIMAL / V_REC.PARITATE, V_REC.CODLOCATIE, V_REC.TG, V_REC.CANTUM1, V_REC.CANTUM1, V_REC.CANTUM2, V_REC.CANTUM2, V_REC.PROCENTADAOS, V_REC.D1, V_REC.D2, V_REC.D3);

        INSERT INTO NIRLUNA(CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
        VALUES(vCODNIRSTOC, ANI, LUNAI, v_rec.CANTNIR * V_REC.PARITATE, V_REC.CANTUM1, V_REC.CANTUM2);

        FOR V_RECNIRSER IN (SELECT * FROM TMP_NIRSERINI WHERE CODNIRSTOC = V_REC.CODNIRSTOC) LOOP
          IF  V_RECNIRSER.CODSERIE &lt; 0 THEN
            BEGIN
              SELECT COALESCE( CODSERIE, 0)
              INTO aCODSERIE
              FROM NSERII
              WHERE SERIE = V_RECNIRSER.SERIE AND  CODOBIECT = (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC);
            EXCEPTION WHEN OTHERS THEN
              aCODSERIE := 0;
            END;

            IF  COALESCE( aCODSERIE, 0) = 0 THEN
              SELECT NEXTVAL('SEQ_NSERII_CODSERIE') INTO aCODSERIE;

              INSERT INTO NSERII(CODSERIE, SERIE, CODOBIECT)
              VALUES(aCODSERIE, V_RECNIRSER.SERIE, V_REC.CODOBIECT);
            END IF;
          ELSE
            aCODSERIE := V_RECNIRSER.CODSERIE;
            SELECT COALESCE( SERIE, '') INTO NOMSERIE FROM NSERII WHERE CODSERIE = aCODSERIE;
            IF  COALESCE( NOMSERIE, '') &lt;&gt; V_RECNIRSER.SERIE THEN
              UPDATE NSERII SET SERIE = V_RECNIRSER.SERIE WHERE CODSERIE = aCODSERIE;
            END IF;
          END IF;

          SELECT NEXTVAL('SEQ_NIRSER_CODNIRSER') INTO vCODNIRSER;

          INSERT INTO NIRSER(CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, REST, CANTUM1, RESTUM1, CANTUM2, RESTUM2, OBS, CodCertif, DataProd, Stare, TG)
          VALUES(vCODNIRSER, vCODNIRSTOC, aCODSERIE, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM2, V_RECNIRSER.CANTUM2, V_RECNIRSER.OBS, V_RECNIRSER.CodCertif, V_RECNIRSER.DataProd, V_RECNIRSER.Stare, V_RECNIRSER.TG);

          INSERT INTO NIRSERLUNA(CODNIRSER, CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
          VALUES(vCODNIRSER, vCODNIRSTOC, ANI, LUNAI, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_REC.CANTUM1, V_REC.CANTUM2);
        END LOOP;
      ELSE
        UPDATE INTRARI
        SET
        DATADOC  = v_rec.DATADOC,
        PARTENER = v_rec.FURNIZOR
        WHERE CODINTR = (SELECT CODINTR FROM NIR WHERE CODNIR = v_rec.CODNIR);

        UPDATE INTRARI1
        SET
        UMSEC     = V_REC.UMSEC,
        PRETORIG  = v_rec.PRETACHIZ / v_rec.PARITATE,
        PU        = v_rec.PRETACHIZ / v_rec.PARITATE,
        CANT      = v_rec.CANTNIR * v_rec.PARITATE,
        TG        = v_rec.TG,
        NRCERTIF  = V_REC.NRCERTIF,
        PUMAXIMAL = v_rec.PUMaximal / v_rec.PARITATE
        WHERE
         CODINTR1 = v_rec.CODINTR1;

        UPDATE NIR
        SET
        DATANIR = v_rec.DATADOC,
        GEST    = aGEST
        WHERE CODNIR = v_rec.CODNIR;

        UPDATE NIRSTOC
        SET
        CANTNIR      = V_REC.CANTNIR * V_REC.PARITATE,
        CANTUM1      = V_REC.CANTUM1,
        CANTUM2      = V_REC.CANTUM2,
        CODIOART     = V_REC.CODIOART,
        UMSEC        = V_REC.UMSEC,
        PRET         = V_REC.PRETINREG / v_rec.PARITATE,
        ADAOS        = (V_REC.PRETINREG - V_REC.PRETACHIZ)  / v_rec.PARITATE,
        TVA          = V_REC.TVA,
        REST         = (SELECT PKG_INTRARI_GET_REST_STOC.WME_RESULT     FROM PKG_INTRARI_GET_REST_STOC    (NULL, V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTNIR * v_rec.PARITATE)),
        RESTUM1      = (SELECT PKG_INTRARI_GET_REST_STOC_UM1.WME_RESULT FROM PKG_INTRARI_GET_REST_STOC_UM1(NULL, V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTUM1)),
        RESTUM2      = (SELECT PKG_INTRARI_GET_REST_STOC_UM2.WME_RESULT FROM PKG_INTRARI_GET_REST_STOC_UM2(NULL, V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTUM2)),
        FURN         = V_REC.FURNIZOR,
        DATAACHIZ    = V_REC.DATADOC,
        TIPDOCACHIZ  = 1,
        PUMAXIMAL    = V_REC.PUMAXIMAL / v_rec.PARITATE,
        CODLOCATIE   = V_REC.CODLOCATIE,
        TG           = V_REC.TG,
        PROCENTADAOS = V_REC.PROCENTADAOS,
        D1           = V_REC.D1,
        D2           = V_REC.D2,
        D3           = V_REC.D3
        WHERE
         CODNIRSTOC = v_rec.CODNIRSTOC;

        --propag din nou furnizorul pe pozitiile de stoc generate prin transfer
        PERFORM pkg_stociniart_PropagaFurn(v_rec.codnirstoc, v_rec.furnizor);

        FOR V_RECNIRSER IN (SELECT * FROM TMP_NIRSERINI WHERE CODNIRSTOC = V_REC.CODNIRSTOC) LOOP
          IF  V_RECNIRSER.CODSERIE &lt; 0 THEN
            BEGIN
              SELECT COALESCE( CODSERIE, 0)
              INTO aCODSERIE
              FROM NSERII
              WHERE SERIE = V_RECNIRSER.SERIE AND  CODOBIECT = (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC);
            EXCEPTION WHEN OTHERS THEN
              aCODSERIE := 0;
            END;

            IF  COALESCE( aCODSERIE, 0) = 0 THEN
              SELECT NEXTVAL('SEQ_NSERII_CODSERIE') INTO aCODSERIE;

              INSERT INTO NSERII(CODSERIE, SERIE, CODOBIECT) VALUES(aCODSERIE, V_RECNIRSER.SERIE, V_REC.CODOBIECT);
            END IF;
          ELSE
            aCODSERIE := V_RECNIRSER.CODSERIE;
            SELECT COALESCE( SERIE, '') INTO NOMSERIE FROM NSERII WHERE CODSERIE = aCODSERIE;
            IF  COALESCE( NOMSERIE, '') &lt;&gt; V_RECNIRSER.SERIE THEN
              UPDATE NSERII SET SERIE = V_RECNIRSER.SERIE WHERE CODSERIE = aCODSERIE;
            END IF;
          END IF;

          IF  V_RECNIRSER.CODNIRSER &lt; 0 THEN
            SELECT NEXTVAL('SEQ_NIRSER_CODNIRSER') INTO vCODNIRSER;

            INSERT INTO NIRSER(CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, REST, CANTUM1, RESTUM1, CANTUM2, RESTUM2, Obs, CodCertif, DataProd, Stare, TG)
            VALUES(vCODNIRSER, V_REC.CODNIRSTOC, aCODSERIE, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM2, V_RECNIRSER.CANTUM2, V_RECNIRSER.Obs, V_RECNIRSER.CodCertif, V_RECNIRSER.DataProd, V_RECNIRSER.Stare, V_RECNIRSER.TG);

            INSERT INTO NIRSERLUNA(CODNIRSER, CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
            VALUES(vCODNIRSER, V_REC.CODNIRSTOC, ANI, LUNAI, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM2);
          ELSE
            UPDATE NIRSER
            SET
            CODSERIE  = aCODSERIE,
            CANTNIR   = V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE,
            CANTUM1   = V_RECNIRSER.CANTUM1,
            CANTUM2   = V_RECNIRSER.CANTUM2,
            OBS       = V_RECNIRSER.Obs,
            CodCertif = V_RECNIRSER.CodCertif,
            DataProd  = V_RECNIRSER.DataProd,
            Stare     = V_RECNIRSER.Stare,
            TG        = V_RECNIRSER.TG,
            REST      = (SELECT PKG_INTRARI_GET_REST_STOC_SERIE.WME_RESULT
                         FROM   PKG_INTRARI_GET_REST_STOC_SERIE(NULL,
                                                                (SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC),
                                                                V_RECNIRSER.CodNirSer, V_RECNIRSER.CantNir * V_RECNIRSER.PARITATE)
                        ),
            RESTUM1   = (SELECT PKG_INTRARI_GET_REST_STOC_SERIE_UM1.WME_RESULT
                         FROM   PKG_INTRARI_GET_REST_STOC_SERIE_UM1(NULL,
                                                                    (SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC),
                                                                    V_RECNIRSER.CodNirSer, V_RECNIRSER.CantUM1)
                        ),
            RESTUM2   = (SELECT PKG_INTRARI_GET_REST_STOC_SERIE_UM2.WME_RESULT
                         FROM   PKG_INTRARI_GET_REST_STOC_SERIE_UM2(NULL,
                                                                    (SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC),
                                                                    V_RECNIRSER.CodNirSer, V_RECNIRSER.CantUM2)
                        )
            WHERE
             CODNIRSER = V_RECNIRSER.CODNIRSER;

            UPDATE NIRSERLUNA
            SET
            REST    = (SELECT PKG_INTRARI_GET_REST_STOC_SERIE.WME_RESULT
                       FROM PKG_INTRARI_GET_REST_STOC_SERIE(NULL, (SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC),
                                                            V_RECNIRSER.CodNirSer, V_RECNIRSER.CantNir * V_RECNIRSER.PARITATE)
                      ),
            RESTUM1 = (SELECT PKG_INTRARI_GET_REST_STOC_SERIE_UM1.WME_RESULT
                       FROM PKG_INTRARI_GET_REST_STOC_SERIE_UM1(NULL, (SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC),
                                                                V_RECNIRSER.CodNirSer, V_RECNIRSER.CantUM1)
                      ),
            RESTUM2 = (SELECT PKG_INTRARI_GET_REST_STOC_SERIE_UM2.WME_RESULT
                       FROM PKG_INTRARI_GET_REST_STOC_SERIE_UM2(NULL, (SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC),
                                                                V_RECNIRSER.CodNirSer, V_RECNIRSER.CantUM2)
                      )
            WHERE CODNIRSER = V_RECNIRSER.CODNIRSER;
          END IF;
        END LOOP;

        UPDATE NIRLUNA
        SET
        REST    = V_REC.CANTNIR * V_REC.PARITATE,
        RESTUM1 = V_REC.CANTUM1,
        RESTUM2 = V_REC.CANTUM2
        WHERE
         CODNIRSTOC = v_rec.CODNIRSTOC;
      END IF;
    END LOOP;
  ELSE
    SELECT NEXTVAL('SEQ_STOCINI_CODSTOCINI') INTO RECID;

    INSERT INTO STOCINI(SELECT RECID, CODGEST, CODPERS FROM TMP_STOCINI);

    FOR V_REC IN (SELECT * FROM TMP_NIRSTOCINI) LOOP
      SELECT NEXTVAL('SEQ_INTRARI_CODINTR')    INTO vCODINTR;
      SELECT NEXTVAL('SEQ_INTRARI1_CODINTR1')  INTO vCODINTR1;
      SELECT NEXTVAL('SEQ_NIR_CODNIR')         INTO vCODNIR;
      SELECT NEXTVAL('SEQ_NIRSTOC_CODNIRSTOC') INTO vCODNIRSTOC;

      INSERT INTO INTRARI(CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, DATADOC, PARTENER, AN, LUNA, SUBUNITATEA)
      VALUES(vCODINTR, 1, 0, 0, 1, 'F', v_rec.DATADOC, v_rec.FURNIZOR, ANI, LUNAI, TO_NUMBER((current_setting('PKG_GLOBALS.SUBUNITATE_DOC', true)),'999999999999999999'));

      INSERT INTO INTRARI1(CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, UMSEC, AN, LUNA, CODOBIECT, PRETORIG, PU, CANT, TG, PUMaximal, NRCERTIF)
      VALUES(vCODINTR1, vCODINTR, 1, '=', V_REC.UMSEC, ANI, LUNAI, v_rec.CODOBIECT, v_rec.PRETACHIZ / V_REC.PARITATE, v_rec.PRETACHIZ / V_REC.PARITATE, v_rec.CANTNIR * V_REC.PARITATE, v_rec.TG, V_REC.PUMAXIMAL / V_REC.PARITATE, V_REC.NRCERTIF);

      INSERT INTO NIR(CODNIR, CODINTR, DATANIR, GEST, TIPNIR, ANULAT, BLOCAT, OPERAT)
      VALUES(vCODNIR, vCODINTR, v_rec.DATADOC, aGEST, 1, 0, 0, 1);

      INSERT INTO NIRSTOC(CODNIRSTOC, CODNIR, CODINTR1, CANTNIR, REST, UMSEC, CODOBIECT, CODIOART, PRET, ADAOS, TVA, TIPSERIE, FURN, DATAACHIZ, TIPDOCACHIZ, PUMAXIMAL, CODLOCATIE, TG, CANTUM1, RESTUM1, CANTUM2, RESTUM2, PROCENTADAOS, D1, D2, D3)
      VALUES(vCODNIRSTOC, vCODNIR, vCODINTR1, v_rec.CANTNIR * V_REC.PARITATE, v_rec.CANTNIR * V_REC.PARITATE, V_REC.UMSEC, V_REC.CODOBIECT, V_REC.CODIOART, V_REC.PRETINREG / V_REC.PARITATE, (  V_REC.PRETINREG - V_REC.PRETACHIZ)  / V_REC.PARITATE, V_REC.TVA, V_REC.TIPSERIE, V_REC.FURNIZOR, V_REC.DATADOC, 1, V_REC.PUMAXIMAL / V_REC.PARITATE, V_REC.CODLOCATIE, V_REC.TG, V_REC.CANTUM1, V_REC.CANTUM1, V_REC.CANTUM2, V_REC.CANTUM2, V_REC.PROCENTADAOS, V_REC.D1, V_REC.D2, V_REC.D3);

      INSERT INTO NIRLUNA(CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
      VALUES(vCODNIRSTOC, ANI, LUNAI, V_REC.CANTNIR * V_REC.PARITATE, V_REC.CANTUM1, V_REC.CANTUM2);

      FOR V_RECNIRSER IN (SELECT * FROM TMP_NIRSERINI WHERE CODNIRSTOC = V_REC.CODNIRSTOC) LOOP
        IF  V_RECNIRSER.CODSERIE &lt; 0 THEN
          BEGIN
            SELECT COALESCE( CODSERIE, 0)
            INTO aCODSERIE
            FROM NSERII
            WHERE SERIE = V_RECNIRSER.SERIE AND  CODOBIECT = (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC);
          EXCEPTION WHEN OTHERS THEN
            aCODSERIE := 0;
          END;

          IF  COALESCE( aCODSERIE, 0) = 0 THEN
            SELECT NEXTVAL('SEQ_NSERII_CODSERIE') INTO aCODSERIE;

            INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES(aCODSERIE, V_RECNIRSER.SERIE, V_REC.CODOBIECT);
          END IF;
        ELSE
          aCODSERIE := V_RECNIRSER.CODSERIE;
          SELECT COALESCE( SERIE, '') INTO NOMSERIE FROM NSERII WHERE CODSERIE = aCODSERIE;
          IF  COALESCE( NOMSERIE, '') &lt;&gt; V_RECNIRSER.SERIE THEN
            UPDATE NSERII SET SERIE = V_RECNIRSER.SERIE WHERE CODSERIE = aCODSERIE;
          END IF;
        END IF;

        SELECT NEXTVAL('SEQ_NIRSER_CODNIRSER') INTO VCODNIRSER;

        INSERT INTO NIRSERLUNA(CODNIRSER, CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
        VALUES(vCODNIRSER, vCODNIRSTOC, ANI, LUNAI, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM2);

        INSERT INTO NIRSER(CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, REST, CANTUM1, RESTUM1, CANTUM2, RESTUM2, Obs, CodCertif, DataProd, Stare, TG)
        VALUES(vCODNIRSER, vCODNIRSTOC, aCODSERIE, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM2, V_RECNIRSER.CANTUM2, V_RECNIRSER.Obs, V_RECNIRSER.CodCertif, V_RECNIRSER.DataProd, V_RECNIRSER.Stare, V_RECNIRSER.TG);
      END LOOP;
    END LOOP;
  END IF;

  DELETE FROM PMPLUNA WHERE AN = ANI AND  LUNA = LUNAI;

  FOR V_REC IN
  (
  SELECT CODOBIECT, CODSUBUNIT, SUM( CANTINTR) AS CANTINTR, SUM( VALINTR) AS VALINTR, SUM( RESTLUNA) AS RESTLUNA, ANI, LUNAI
  FROM (SELECT NS.CODOBIECT, G.CODSUBUNIT, NS.CANTNIR AS CANTINTR, (NS.PRET - COALESCE( NS.ADAOS, 0))  * NS.CANTNIR AS VALINTR,
               NS.CANTNIR - (SELECT PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA.WME_RESULT FROM PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA(NULL, NS.CodNirStoc, ANI, LUNAI)) AS RESTLUNA
        FROM NIRSTOC NS, NIR N, TMP_IOART_LUNA IO, INTRARI I, NGEST G
        WHERE NS.CODIOART = IO.CODIOART AND  IO.MG = 3 AND  NS.CODNIR = N.CODNIR AND N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7) AND  N.ANULAT = 0 AND  N.OPERAT = 1 AND  I.CODINTR = N.CODINTR AND  I.AN = ANI AND  I.LUNA = LUNAI AND  G.CODGEST = N.GEST
       ) A_PG
  GROUP BY CODOBIECT, CODSUBUNIT
  )
  LOOP
    INSERT INTO PMPLUNA(CODPMPLUNA, CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, REST, AN, LUNA)
    VALUES(NEXTVAL('SEQ_PMPLUNA_CODPMPLUNA'), V_REC.CODOBIECT, V_REC.CODSUBUNIT, V_REC.CANTINTR, V_REC.VALINTR, V_REC.RESTLUNA, ANI, LUNAI);
  END LOOP;

  DELETE FROM PMP_ALL_LUNA WHERE AN = ANI AND  LUNA = LUNAI;

  FOR V_REC IN
  (
  SELECT CODOBIECT, SUM( CANTINTR) AS CANTINTR, SUM( VALINTR) AS VALINTR, SUM( RESTLUNA) AS RESTLUNA, ANI, LUNAI
  FROM (SELECT NS.CODOBIECT, NS.CANTNIR AS CANTINTR, (  NS.PRET - COALESCE( NS.ADAOS, 0))  * NS.CANTNIR AS VALINTR,
               NS.CANTNIR - (SELECT PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA.WME_RESULT FROM PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA(NULL, NS.CodNirStoc, ANI, LUNAI)) AS RESTLUNA
        FROM NIRSTOC NS, NIR N, TMP_IOART_LUNA IO, INTRARI I
        WHERE NS.CODIOART = IO.CODIOART AND  IO.MG = 3 AND  NS.CODNIR = N.CODNIR AND N.TIPNIR IN (1, 2, 3, 4, 5, 7) AND  N.ANULAT = 0 AND  N.OPERAT = 1 AND  I.CODINTR = N.CODINTR AND  I.AN = ANI AND  I.LUNA = LUNAI
       ) B_PG
  GROUP BY CODOBIECT
  )
  LOOP
    INSERT INTO PMP_ALL_LUNA(CODPMP_ALL_LUNA, CODOBIECT, CANTINTR, VALINTR, REST, AN, LUNA)
    VALUES(NEXTVAL('SEQ_PMP_ALL_LUNA'), V_REC.CODOBIECT, V_REC.CANTINTR, V_REC.VALINTR, V_REC.RESTLUNA, ANI, LUNAI);
  END LOOP;

  PERFORM NotifyModif( Operation, RecId, 'STOCINI');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_subsidiary_get_zcliehier3</obj_name>
  <obj_hashval>cb29e3f2f8899579e7d1ffd2d32ac68a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_subsidiary_get_zcliehier3(INOUT wme_result character varying, INOUT pcodpart numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  vRESULT varchar;
begin
  EXECUTE 'SELECT MAX(HIER3) FROM NPARTDET WHERE CODPART = :1 ';
  WME_Result :=  vResult;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_subsidiary_setcdatafin</obj_name>
  <obj_hashval>b98d6253e4b85c465114c2c99ef2b854</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_subsidiary_setcdatafin(acdatafin date)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SUBSIDIARY.cDataFin',acDataFin,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tari_sp_insertrecord</obj_name>
  <obj_hashval>516a3ff622ba2049d3559e59b01831b2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tari_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_NTARI (codtara) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_teme_sp_insertrecord</obj_name>
  <obj_hashval>70f059a8294925fb4ee406ccde696884</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_teme_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_TEME (CodTEMA) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tipchelt_sp_insertrecord</obj_name>
  <obj_hashval>63d237d0282a56df8517e43d16fd55f7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tipchelt_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_TIPCHELT(CODTIPCHELT) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transeini_seti</obj_name>
  <obj_hashval>5c9cd0557c48c767183dfc1a9be9dff2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transeini_seti(ai numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_TRANSEINI.I',to_char(aI,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transeini_sp_insertrecord</obj_name>
  <obj_hashval>33cd5876b606ba47466299e59809bafc</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transeini_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_TRANSEINI (CODBANKCONT) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_sp_gotorecord</obj_name>
  <obj_hashval>31540dadb76f740e373250819e461785</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aTip numeric;
begin
  INSERT INTO TMP_TRANSPORT(CodTransport, DataTransport, UserId, DataCreare, Subunitate, Indicativ, Operat, Blocat, Anulat, An, Luna, Valoare, TipRepart, CodParcAuto, CodSofer, Colete, rep_transf, Rep_Subunit, Tip, Masina, Sarcina, Volum, DataStart, DataStop, DataStartDVI, DataStopDVI, TipLivrare)
  (
  SELECT TR.CodTransport, TR.DataTransport, TR.UserId, TR.DataCreare, TR.Subunitate, TR.Indicativ, TR.Operat, TR.Blocat, TR.Anulat, TR.An, TR.Luna, TR.Valoare, TR.TipRepart, TR.CodParcAuto, TR.CodSofer, TR.Colete, TR.Rep_Transf, tr.rep_subunit, TR.Tip, OBJ.DENUMIRE, Round( COALESCE( PA.MasaU, 0), 5), Round( COALESCE( PA.Lung, 0) * COALESCE( PA.Lat, 0) * COALESCE( PA.Inalt, 0) / 1000000, 5), to_date( '01.' || to_char( (SELECT pkg_globals_GetLUNALUCRU.WME_RESULT FROM pkg_globals_GetLUNALUCRU(NULL,NULL)),'9999999999') || '.' || to_char( (SELECT pkg_globals_GetANLUCRU.WME_RESULT FROM pkg_globals_GetANLUCRU(NULL,NULL)),'9999999999'), 'DD.MM.YYYY'), last_day( to_date( '01.' || to_char( (SELECT pkg_globals_GetLUNALUCRU.WME_RESULT FROM pkg_globals_GetLUNALUCRU(NULL,NULL)),'9999999999') || '.' || to_char( (SELECT pkg_globals_GetANLUCRU.WME_RESULT FROM pkg_globals_GetANLUCRU(NULL,NULL)),'9999999999'), 'DD.MM.YYYY')), to_date( '01.' || to_char( (SELECT pkg_globals_GetLUNALUCRU.WME_RESULT FROM pkg_globals_GetLUNALUCRU(NULL,NULL)),'9999999999') || '.' || to_char( (SELECT pkg_globals_GetANLUCRU.WME_RESULT FROM pkg_globals_GetANLUCRU(NULL,NULL)),'9999999999'), 'DD.MM.YYYY'), last_day( to_date( '01.' || to_char( (SELECT pkg_globals_GetLUNALUCRU.WME_RESULT FROM pkg_globals_GetLUNALUCRU(NULL,NULL)),'9999999999') || '.' || to_char( (SELECT pkg_globals_GetANLUCRU.WME_RESULT FROM pkg_globals_GetANLUCRU(NULL,NULL)),'9999999999'), 'DD.MM.YYYY')), 3
  FROM TRANSPORT TR
      LEFT JOIN NPARCAUT PA ON  TR.CodParcAuto = PA.CODNPARCAUT
      LEFT JOIN NARTOBJ OBJ ON  PA.CODART      = OBJ.CODOBIECT
  WHERE CodTransport = RecId
  );

  SELECT COALESCE( Tip, 0) INTO aTip FROM tmp_transport;
  IF  aTip = 0 THEN
    INSERT INTO TMP_TRANSPORT1(CodTransport1, CodTransport, CodColet, CodDoc, TipDoc, SerieColet, NrColet, DataColet, SerieDoc, NrDoc, DataDoc, TipPartener, CodPart, Partener, PrefixDoc)
    (SELECT T1.CodTransport1, T1.CodTransport, T1.CodColet, T1.CodDoc, T1.TipDoc, DOCPK.Serie, PK.NrDoc, PK.DataP,
            CASE WHEN T1.TipDoc IN (12, 13) THEN DOCT.Serie ELSE DOCIES.Serie END ,
            CASE WHEN T1.TipDoc IN (12, 13) THEN T.NrDoc    ELSE I.NrDoc      END ,
            CASE WHEN T1.TipDoc IN (12, 13) THEN T.DataDoc  ELSE I.DataDoc    END ,
            CASE WHEN  T1.TipDoc = 12 THEN 'GESTIUNE'
                 WHEN  T1.TipDoc = 13 THEN '...NEDEFINIT...'
                 WHEN  T1.TipDoc = 23 THEN 'SUBUNITATE'
                 ELSE 'PARTENER'
            END ,
            CASE WHEN  T1.TipDoc = 12 THEN G.CodGest
                 WHEN  T1.TipDoc = 13 THEN 0
                 WHEN  T1.TipDoc = 23 THEN S.CodSubunit
                 ELSE P.CodPart
            END ,
            CASE WHEN  T1.TipDoc = 12 THEN G.Den_Gest
                 WHEN  T1.TipDoc = 13 THEN '...NEDEFINIT...'
                 WHEN  T1.TipDoc = 23 THEN S.Den_Subunit
                 ELSE P.Den_Part
            END ,
            COALESCE( I.PREFIXDOC, T.PREFIXDOC)
    FROM TRANSPORT1 T1
        LEFT JOIN PACHETE    PK     ON  T1.CodColet  = PK.CODPACHETE
        LEFT JOIN DOCCARNETE DOCPK  ON  PK.Carnetdoc = DOCPK.CODCARNET
        LEFT JOIN IESIRI     I      ON  T1.CodDoc    = I.CodIes AND  COALESCE( I.Anulat, 0) &lt;&gt; 1
        LEFT JOIN DOCCARNETE DOCIES ON  I.CarnetDoc  = DOCIES.CODCARNET
        LEFT JOIN NPART      P      ON  I.Partener   = P.Codpart
        LEFT JOIN NSUBUNIT   S      ON  I.CodSubunit = S.Codsubunit
        LEFT JOIN TRANSF     T      ON  T1.CodDoc    = T.Codtransf AND  COALESCE( T.Anulat, 0) &lt;&gt; 1
        LEFT JOIN DOCCARNETE DOCT   ON  T.CarnetDoc  = DOCT.CodCarnet
        LEFT JOIN NGEST      G      ON  T.CodGestCmd = G.CodGest
    WHERE T1.CodTransport = RecId
    );

    INSERT INTO TMP_TRANSPORT1_INI(CodTransport1, CodTransport, CodColet, CodDoc, TipDoc, SerieColet, NrColet, DataColet, SerieDoc, NrDoc, DataDoc, TipPartener, CodPart, Partener)
    (
    SELECT T1.CodTransport1, T1.CodTransport, T1.CodColet, T1.CodDoc, T1.TipDoc, DOCPK.Serie, PK.NrDoc, PK.DataP,
           CASE WHEN T1.TipDoc IN (12, 13) THEN DOCT.Serie ELSE DOCIES.Serie END ,
           CASE WHEN T1.TipDoc IN (12, 13) THEN T.NrDoc    ELSE I.NrDoc      END ,
           CASE WHEN T1.TipDoc IN (12, 13) THEN T.DataDoc  ELSE I.DataDoc    END ,
           CASE WHEN  T1.TipDoc = 12 THEN 'GESTIUNE'
                WHEN  T1.TipDoc = 13 THEN '...NEDEFINIT...'
                WHEN  T1.TipDoc = 23 THEN 'SUBUNITATE'
                ELSE 'PARTENER'
           END ,
           CASE WHEN  T1.TipDoc = 12 THEN G.CodGest
                WHEN  T1.TipDoc = 13 THEN 0
                WHEN  T1.TipDoc = 23 THEN S.CodSubunit
                ELSE P.CodPart
           END ,
           CASE WHEN  T1.TipDoc = 12 THEN G.Den_Gest
                WHEN  T1.TipDoc = 13 THEN '...NEDEFINIT...'
                WHEN  T1.TipDoc = 23 THEN S.Den_Subunit
                ELSE P.Den_Part
           END
    FROM TRANSPORT1 T1
        LEFT JOIN PACHETE    PK     ON  T1.CodColet  = PK.CODPACHETE
        LEFT JOIN DOCCARNETE DOCPK  ON  PK.Carnetdoc = DOCPK.CODCARNET
        LEFT JOIN IESIRI     I      ON  T1.CodDoc    = I.CodIes AND  COALESCE( I.Anulat, 0) &lt;&gt; 1
        LEFT JOIN DOCCARNETE DOCIES ON  I.CarnetDoc  = DOCIES.CODCARNET
        LEFT JOIN NPART      P      ON  I.Partener   = P.Codpart
        LEFT JOIN NSUBUNIT   S      ON  I.CodSubunit = S.Codsubunit
        LEFT JOIN TRANSF     T      ON  T1.CodDoc    = T.Codtransf AND  COALESCE( T.Anulat, 0) &lt;&gt; 1
        LEFT JOIN DOCCARNETE DOCT   ON  T.CarnetDoc  = DOCT.CodCarnet
        LEFT JOIN NGEST      G      ON  T.CodGestCmd = G.CodGest
    WHERE T1.CodTransport = RecId
    );

    INSERT INTO TMP_TRANSPORT2(CodTransport2, CodTransport1, CodDoc1, TipDoc, Articol, Cant, Den_UM1, Document, Valoare, Val, Masa, Volum, operat)
    (
    SELECT row_number() over() CODTRANPORT2, TR1.CodTransport1,
           CASE WHEN TR1.TipDoc IN (12, 13) THEN T1.CodTransf1 ELSE I1.CodIes1 END  CODDOC1,
           TR1.TipDoc,
           CASE WHEN TR1.TipDoc IN (12, 13) THEN TOBJ.Denumire ELSE IOBJ.Denumire END  ARTICOL,
           CASE WHEN TR1.TipDoc IN (12, 13) THEN T1.Cant ELSE I1.Cant END  CANT,
           CASE WHEN TR1.TipDoc IN (12, 13) THEN TUM1.Den_UM1 ELSE IUM1.Den_UM1 END  DEN_UM1,
           CASE WHEN TR1.TipDoc IN (12, 13) THEN T.PREFIXDOC || T.NrDoc || '/' || TO_CHAR( T.DATADOC, 'DD.MM.YYYY')
                ELSE I.PREFIXDOC || I.NrDoc || '/' || TO_CHAR( I.DATADOC, 'DD.MM.YYYY')
           END  AS DOCUMENT,
           CASE WHEN TR1.TipDoc IN (12, 13) THEN T1.CostTransport ELSE I1.CostTransport END  VALOARE,
           CASE WHEN TR1.TipDoc IN (12, 13) THEN T1.Cant * T1.Pu  ELSE I1.Cant * I1.PU  END  VAL,
           CASE WHEN TR1.TipDoc IN (12, 13) THEN CASE WHEN  COALESCE( AMBT.CODAMB, -1) = -1 THEN TOBJ.Masa ELSE AMBT.Masa END
                ELSE CASE WHEN  COALESCE( AMBI.CODAMB, -1) = -1 THEN IOBJ.Masa ELSE AMBI.Masa END
           END  * CASE WHEN TR1.TipDoc IN (12, 13) THEN T1.Cant ELSE I1.Cant END  MASA,
           CASE WHEN TR1.TipDoc IN (12, 13) THEN CASE WHEN  COALESCE( AMBT.CODAMB, -1) = -1 THEN TOBJ.Volum
                                                      ELSE COALESCE( AMBT.Inaltime, 0) * COALESCE( AMBT.Lungime, 0) * COALESCE( AMBT.Latime, 0)
                                                 END
                ELSE CASE WHEN  COALESCE( AMBI.CODAMB, -1) = -1 THEN IOBJ.Volum
                          ELSE COALESCE( AMBI.Inaltime, 0) * COALESCE( AMBI.Lungime, 0) * COALESCE( AMBI.Latime, 0)
                     END
           END  * CASE WHEN TR1.TipDoc IN (12, 13) THEN T1.Cant ELSE I1.Cant END  VOLUM,
           CASE WHEN TR1.TipDoc IN (12, 13) THEN T.Operat ELSE I.Operat END  OPERAT
    FROM TRANSPORT1 TR1
        LEFT JOIN IESIRI     I    ON  TR1.CodDoc     = I.CodIes
        LEFT JOIN DOCCARNETE DOCI ON  I.CARNETDOC    = DOCI.CodCarnet
        LEFT JOIN IESIRI1    I1   ON  I.CodIes       = I1.CodIes
        LEFT JOIN NARTOBJ    IOBJ ON  I1.CodObiect   = IOBJ.CodObiect
        LEFT JOIN NUM1       IUM1 ON  I1.UMSec       = IUM1.CodUM1
        LEFT JOIN NARTAMB    AMBI ON  IOBJ.CodObiect = AMBI.CodOBiect AND  I1.UMSec = AMBI.UMSec
        LEFT JOIN TRANSF     T    ON  TR1.CodDoc     = T.CodTransf
        LEFT JOIN DOCCARNETE DOCT ON  T.CARNETDOC    = DOCT.CodCarnet
        LEFT JOIN TRANSF1    T1   ON  T.CodTransf    = T1.CodTransf
        LEFT JOIN NARTOBJ    TOBJ ON  T1.CodObiect   = TOBJ.CodObiect
        LEFT JOIN NUM1       TUM1 ON  T1.UMSec       = TUM1.CodUM1
        LEFT JOIN NARTAMB    AMBT ON  TOBJ.CodObiect = AMBT.CodOBiect AND  T1.UMSec = AMBT.UMSec
    WHERE TR1.CODTRANSPORT = RecId
    );
  ELSE
    INSERT INTO TMP_TRANSPORT1(CODTRANSPORT1, CODTRANSPORT, CODDOC, TIPDOC, SERIEDOC, NRDOC, DATADOC, CODPART, PARTENER, PREFIXDOC, VALOARE)
    (
    SELECT T1.CodTransport1, T1.CodTransport, T1.CodDoc, T1.TipDoc, DOC.Serie, I.NrDoc, I.DataDoc, P.CodPart, P.Den_Part, I.PrefixDoc, (SELECT pkg_transport_GetValServ.WME_RESULT FROM pkg_transport_GetValServ(NULL, I.CodIntr))
    FROM TRANSPORT1 T1
        LEFT JOIN INTRARI    I   ON  T1.CodDoc   = I.CodIntr AND  COALESCE( I.Anulat, 0) &lt;&gt; 1
        LEFT JOIN DOCCARNETE DOC ON  I.CarnetDoc = DOC.CODCARNET
        LEFT JOIN NPART      P   ON  I.Partener  = P.Codpart
    WHERE T1.CodTransport = RecId
    );

    INSERT INTO TMP_TRANSPORT2(CODTRANSPORT2, CODTRANSPORT, CODDOC, TIPDOC, VALOARE, VAL, MASA, VOLUM, SERIEDOC, NRDOC, DATADOC, CODPART, PARTENER, PREFIXDOC, OPERAT)
    (
    SELECT TR2.CodTransport2, TR2.CodTransport, TR2.CodDoc, TR2.TipDoc, I.ValDoc * I.Curs, DVI.ValSuplim, (SELECT pkg_TRANsPORT_GetMasaFactIntr.WME_RESULT FROM pkg_TRANsPORT_GetMasaFactIntr(NULL, TR2.CodDoc)), (SELECT pkg_TRANsPORT_GetVolumFactIntr.WME_RESULT FROM pkg_TRANsPORT_GetVolumFactIntr(NULL, TR2.CodDoc)), DOC.SERIE, I.NRDOC, I.DATADOC, P.CODPART, P.DEN_PART, I.PREFIXDOC, I.OPERAT
    FROM TRANSPORT2 TR2
        INNER JOIN INTRARI    I   ON  TR2.CodDoc  = I.CodIntr
        INNER JOIN DVI            ON  DVI.CODINTR = I.CodIntr
        INNER JOIN NPART      P   ON  I.PARTENER  = P.CodPart
        LEFT  JOIN DOCCARNETE DOC ON  I.CARNETDOC = DOC.CodCarnet
    WHERE TR2.CODTRANSPORT = RecId
    );
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_sp_insertrecord</obj_name>
  <obj_hashval>38998b9b7081adef711746399749c7a1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_TraseuLivr(CodTraseuLivr) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_set_skipanalizasold</obj_name>
  <obj_hashval>fc7a4e8344e5d1b1bf8cc5ffe2f66d8a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_set_skipanalizasold(flag numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 10.07.2023 - sinc. Oracle (05.07.2023)
  perform set_config('PKG_TREZOR.SkipAnalizaSOld' ,(FLAG)::varchar ,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trigar_set_ddl_trg</obj_name>
  <obj_hashval>ee981c3f1418fa278d5992fc7a8b6133</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trigar_set_ddl_trg(recid numeric, pprefix character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  VREC          RECORD;
  s_Prefix      varchar;
  v_Tip         numeric;
  s_TableName   varchar;
  v_Operatie    numeric;
  v_Moment      numeric;
  c_Trig        varchar;
  c_Variabile   varchar;
  s_MasterField varchar;
  s_KeyField    varchar;
  s_AuxCompare  varchar;
  s_AuxInsert   varchar;
  c_DDL         varchar;
  sSchema       varchar;
  s_Operatii    varchar;
  sActiv        VARCHAR(50);
  vInactiv      NUMERIC(1);
BEGIN
  --Florin 27.07.2022 - sinc. Oracle (26.07.2022)
  --Bogdan 15.03.2022 - 53501 marire campuri OLDVALUE si NEWVALUE (Trigar_Modif) din 30 in 100
  --Adina 02.06.2021 - scos upper din information_schema si add sSchema
  --Florin 21.12.2020 - fixat #41755
  --Florin 25.01.2021 - fixat #42438
  sSchema := Lower(current_setting('PKG_GLOBALS.FIRMANAME', true));
  IF NULLIF(sSchema, '') IS NULL THEN
    sSchema := public.get_schema();
  END IF;

  s_Prefix := Trim( pPrefix);
  IF s_Prefix IS NOT NULL THEN
    IF  SubStr(s_Prefix, -1) &lt;&gt; '.' THEN
      s_Prefix := coalesce(s_Prefix,'') || '.';
    END IF;
  END IF;

  BEGIN
    SELECT t.Tip, t.TableName, t.Operatie, t.Moment, t.Variabile, t.Trig, t.MasterField, c.Column_Name,coalesce(t.inactiv,0)
    INTO   v_Tip, s_TableName, v_Operatie, v_Moment, c_Variabile, c_Trig, s_MasterField, s_KeyField, vInactiv
    FROM trigar t
         LEFT JOIN information_schema.columns c ON c.table_schema = sSchema AND c.table_name = lower(t.TableName) AND c.ordinal_position = 1
    WHERE t.codtrigar = RecId;
  EXCEPTION WHEN no_data_found THEN
    v_Tip := 0;
  END;

  if vInactiv = 1 THEN
    sActiv := ' DISABLE';
  ELSE
    sActiv := ' ENABLE';
  end if;

  IF  v_Tip = 1 THEN
    IF s_MasterField IS NULL THEN
      s_MasterField := s_KeyField;
    END IF;

    c_DDL :=  'CREATE OR REPLACE FUNCTION '||s_Prefix::VARCHAR||'FWME_'||s_TableName::VARCHAR||'_'||trunc(RecId)::VARCHAR||'()'||
              '  RETURNS TRIGGER '||
              '  LANGUAGE PLPGSQL AS $$ '||
              'begin';

    FOR vRec IN (SELECT t1.FieldName, tc.Data_Type
                 FROM trigar t
                     INNER JOIN trigar1                    t1 ON  t1.CodTrigar  = t.CodTrigar
                     LEFT  JOIN information_schema.COLUMNS tc ON  tc.table_schema = sSchema AND tc.table_name = lower(t.TableName) AND tc.column_name = lower(t1.FieldName)
                 WHERE t.CodTrigar = RecId
                 ORDER BY codtrigar1
                )
    LOOP
      s_AuxCompare := 'New.' || coalesce(vRec.FieldName,'') || ' &lt;&gt; Old.' || coalesce(vRec.FieldName,'');
      s_AuxInsert := 'Substr(Old.' || coalesce(vRec.FieldName,'') || '::varchar,1,100), Substr(New.' || coalesce(vRec.FieldName,'') || '::varchar,1,100)';

      c_DDL := c_DDL||
              '  IF (New.'||vRec.FieldName||' is Null and Old.'||vRec.FieldName||' is not Null) '||
              '  OR (New.'||vRec.FieldName||' is not Null and Old.'||vRec.FieldName||' is Null) '||
              '  OR ('||s_AuxCompare||')'||
              '  THEN '||
              '    INSERT INTO trigar_modif (CodModif, DatAmodif, UserModif, Cod, CodMaster, TableName, FieldName, OldValue, NewValue)'||
              '    VALUES(nextval (''SEQ_TRIGAR_MODIF''), current_timestamp, current_setting (''PKG_GLOBALS.USERID'', true) ::numeric, Old.'||s_KeyField||',Old.'||s_MasterField||', '''||s_TableName||''', '''||vRec.FieldName||''', '||s_AuxInsert||');'||
              '  END IF;';
    END LOOP;

    c_DDL := c_DDL||
              ' RETURN NEW; END '||
              '$$;';
  ELSIF v_Tip = 2 THEN
    c_DDL :=  'CREATE OR REPLACE FUNCTION '||s_Prefix::VARCHAR||'FWME_'||s_TableName::VARCHAR||'_'||trunc(RecId)::VARCHAR||'()'||
              ' RETURNS TRIGGER '||
              ' LANGUAGE PLPGSQL AS $$ '||
              ' declare '||
              c_Variabile||
              ' begin '||
              c_Trig||
              ' RETURN NEW; END '||
              ' $$;';
  END IF;

  execute c_DDL;

  s_Operatii := '';
  IF BITand(v_Operatie,1) = 1 THEN s_Operatii := 'insert'; end if;
  if BITand(v_Operatie,2) = 2 then
    if Length(s_Operatii) &gt; 0 then
      s_Operatii := s_Operatii||' or update';
    else
      s_Operatii := 'update';
    end if;
  end if;
  if BITand(v_Operatie,4) = 4 then
    if Length(s_Operatii) &gt; 0 then
      s_Operatii := s_Operatii||' or delete';
    else
      s_Operatii := 'delete';
    end if;
  end if;
  c_DDL :=  ' DO $$ '||
            ' BEGIN DROP TRIGGER IF EXISTS TWME_'||s_TableName::VARCHAR||'_'||trunc(RecId)::VARCHAR||' ON '||s_Prefix::VARCHAR||s_TableName::VARCHAR||'; '||
            ' CREATE TRIGGER TWME_'||s_TableName::VARCHAR||'_'||trunc(RecId)::VARCHAR||
            '  '||CASE v_Moment WHEN 1 THEN 'before' ELSE 'after' END||' '||s_Operatii||' on '||s_Prefix::VARCHAR||s_TableName::VARCHAR||
            '  for each row '||
            '  EXECUTE PROCEDURE '||s_Prefix||'FWME_'||s_TableName||'_'||trunc(RecId)::VARCHAR||'();'||chr(13)||
            '  ALTER TABLE '||s_Prefix||s_TableName||sActiv||' TRIGGER TWME_'||s_TableName||'_'||trunc(RecId)::VARCHAR||';'||chr(13)||
            ' END $$;';
  EXECUTE c_DDL;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trigar_sp_insertrecord</obj_name>
  <obj_hashval>744f59b927a1d4478d7fa383efb87247</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trigar_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_TRIGAR (CodTRIGAR) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_importxls</obj_name>
  <obj_hashval>1ee7c88821f1fb9b043e6180c5727aa6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_importxls()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  oData    timestamp;
  vdatag   date;
  vdatagi  date;
  vdatac   date;
  vdatapif date;
begin
  SELECT CURRENT_TIMESTAMP INTO oData;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_vouchercadou_sp_deleterecord</obj_name>
  <obj_hashval>eddeb6eeb2fd48864b482ec63b28458f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_vouchercadou_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 12.12.2024
  PERFORM pkg_vouchercadou_SP_LOCKRECORD(RecId);
  DELETE FROM VOUCHERCADOU WHERE COD = RecId ;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_weekcashflow_sp_insertrecord</obj_name>
  <obj_hashval>d2f0ae344b2c23852799e3f19a4cc0a4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_weekcashflow_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_WEEKCASHFLOW (CODCASHFLOW) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_weekcashflow_sp_lockrecord</obj_name>
  <obj_hashval>95c961939d39e0fe695348419d0d33f0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_weekcashflow_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CODCASHFLOW INTO Tmp FROM WEEKCASHFLOW WHERE CODCASHFLOW = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_weekcashflow_sp_postrecords</obj_name>
  <obj_hashval>34676663c708969880fb1f66f53568bd</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_weekcashflow_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC       RECORD;
  vCOD        numeric;
  aDATADOC    date;
  aCodSubunit numeric;
  aDoc        varchar;
BEGIN
  --Florin 01.06.2023 - monitor
  --Florin 21.04.2023 - fixat 57939
  --Florin 26.11.2021/30.11.2021 - fixat 52160
  --Florin 17.11.2020 - fixat #41086
  --Florin 23.03.2021 - PKG_USERFIRME_PostLogcucommit
  perform pkg_weekcashflow_setct_monitor('MON_65');
  SELECT DATADOC, SUBUNITATEA, NRDOC INTO ADATADOC, aCodSubunit, aDoc FROM TMP_WEEKCASHFLOW;

  IF  Operation = 0 THEN
    SELECT CODCASHFLOW INTO RECID FROM TMP_WEEKCASHFLOW;

    IF (SELECT WME_RESULT FROM PKG_USERFIRME_ValidPostLog(NULL, TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999'), (current_setting('PKG_WEEKCASHFLOW.CT_MONITOR', true))))
    THEN
      PERFORM PKG_USERFIRME_PostLogcucommit( 'WEEKCASHFLOW', (current_setting('PKG_GLOBALS.USERNAME', true)), 'M', RECID, (current_setting('PKG_GLOBALS.FIRMANAME', true)), aCodSubunit, aDataDoc, aDoc, '', (SELECT PKG_GLOBALS_GET_EXE_VERSION.WME_RESULT FROM PKG_GLOBALS_GET_EXE_VERSION(NULL,NULL)));
    END IF;

    UPDATE WEEKCASHFLOW
    SET
    (NRDOC, DATADOC, SAPTAMANA, SUBUNITATEA, TIP) = (SELECT NRDOC, DATADOC, SAPTAMANA, SUBUNITATEA, TIP FROM TMP_WEEKCASHFLOW)
    WHERE CODCASHFLOW = RECID;

    DELETE FROM WEEKCASHFLOW1 WHERE CODCASHFLOW = RECID AND CODCASHFLOW1 not IN (SELECT CODCASHFLOW1 FROM TMP_WEEKCASHFLOW1);

    FOR V_REC IN (SELECT * FROM TMP_WEEKCASHFLOW1) LOOP
      IF  V_REC.CODCASHFLOW1 &gt; 0 THEN
        UPDATE WEEKCASHFLOW1
        SET
        CODCASHFLOW   = RECID,
        INDEXTIPLINIE = V_REC.INDEXTIPLINIE,
        INDEXLOCAL    = V_REC.INDEXLOCAL,
        INDEXSECUNDAR = V_REC.INDEXSECUNDAR,
        TITLU         = V_REC.TITLU,
        DENUMIRE      = V_REC.DENUMIRE,
        SIMBOLCONT    = V_REC.SIMBOLCONT,
        VALOARE       = V_REC.VALOARE,
        RESTANTE      = V_REC.RESTANTE,
        VIZIBIL       = V_REC.VIZIBIL,
        AREDETALII    = V_REC.AREDETALII,
        EXPANDAT      = V_REC.EXPANDAT,
        ESTETOTAL     = V_REC.ESTETOTAL,
        EDITABIL      = V_REC.EDITABIL,
        OBS           = V_REC.OBS,
        DETALIU       = V_REC.DETALIU,
        CODPART       = V_REC.CODPART,
        HEADERFOOTER  = V_REC.HEADERFOOTER,
        WEEK1  = V_REC.WEEK1,
        WEEK2  = V_REC.WEEK2,
        WEEK3  = V_REC.WEEK3,
        WEEK4  = V_REC.WEEK4,
        WEEK5  = V_REC.WEEK5,
        WEEK6  = V_REC.WEEK6,
        WEEK7  = V_REC.WEEK7,
        WEEK8  = V_REC.WEEK8,
        WEEK9  = V_REC.WEEK9,
        WEEK10 = V_REC.WEEK10,
        WEEK11 = V_REC.WEEK11,
        WEEK12 = V_REC.WEEK12,
        WEEK13 = V_REC.WEEK13,
        WEEK14 = V_REC.WEEK14,
        WEEK15 = V_REC.WEEK15,
        WEEK16 = V_REC.WEEK16,
        WEEK17 = V_REC.WEEK17,
        WEEK18 = V_REC.WEEK18,
        WEEK19 = V_REC.WEEK19,
        WEEK20 = V_REC.WEEK20,
        WEEK21 = V_REC.WEEK21,
        WEEK22 = V_REC.WEEK22,
        WEEK23 = V_REC.WEEK23,
        WEEK24 = V_REC.WEEK24,
        WEEK25 = V_REC.WEEK25,
        WEEK26 = V_REC.WEEK26,
        WEEK27 = V_REC.WEEK27,
        WEEK28 = V_REC.WEEK28,
        WEEK29 = V_REC.WEEK29,
        WEEK30 = V_REC.WEEK30,
        WEEK31 = V_REC.WEEK31,
        WEEK32 = V_REC.WEEK32,
        WEEK33 = V_REC.WEEK33,
        WEEK34 = V_REC.WEEK34,
        WEEK35 = V_REC.WEEK35,
        WEEK36 = V_REC.WEEK36,
        WEEK37 = V_REC.WEEK37,
        WEEK38 = V_REC.WEEK38,
        WEEK39 = V_REC.WEEK39,
        WEEK40 = V_REC.WEEK40,
        WEEK41 = V_REC.WEEK41,
        WEEK42 = V_REC.WEEK42,
        WEEK43 = V_REC.WEEK43,
        WEEK44 = V_REC.WEEK44,
        WEEK45 = V_REC.WEEK45,
        WEEK46 = V_REC.WEEK46,
        WEEK47 = V_REC.WEEK47,
        WEEK48 = V_REC.WEEK48,
        WEEK49 = V_REC.WEEK49,
        WEEK50 = V_REC.WEEK50,
        WEEK51 = V_REC.WEEK51,
        WEEK52 = V_REC.WEEK52,
        PESTE52 = V_REC.PESTE52,
        CODDOC = V_REC.CODDOC
        WHERE
         CODCASHFLOW1 = V_REC.CODCASHFLOW1;
      ELSE
        VCOD := NEXTVAL('SEQ_WEEKCASHFLOW1_CODCASHFLOW1');

        UPDATE TMP_WEEKCASHPLATI SET CODCASHFLOW1 = VCOD WHERE CODCASHFLOW1 = V_REC.CODCASHFLOW1;

        INSERT INTO WEEKCASHFLOW1(CODCASHFLOW1, CODCASHFLOW, INDEXTIPLINIE, INDEXLOCAL, INDEXSECUNDAR, TITLU, DENUMIRE, SIMBOLCONT, VALOARE, RESTANTE, VIZIBIL, AREDETALII, EXPANDAT, ESTETOTAL, EDITABIL, OBS, DETALIU, CODPART, HEADERFOOTER, WEEK1, WEEK2, WEEK3, WEEK4, WEEK5, WEEK6, WEEK7, WEEK8, WEEK9, WEEK10, WEEK11, WEEK12, WEEK13, WEEK14, WEEK15, WEEK16, WEEK17, WEEK18, WEEK19, WEEK20, WEEK21, WEEK22, WEEK23, WEEK24, WEEK25, WEEK26, WEEK27, WEEK28, WEEK29, WEEK30, WEEK31, WEEK32, WEEK33, WEEK34, WEEK35, WEEK36, WEEK37, WEEK38, WEEK39, WEEK40, WEEK41, WEEK42, WEEK43, WEEK44, WEEK45, WEEK46, WEEK47, WEEK48, WEEK49, WEEK50, WEEK51, WEEK52, PESTE52, CODDOC)
        VALUES(VCOD, RECID, V_REC.INDEXTIPLINIE, V_REC.INDEXLOCAL, V_REC.INDEXSECUNDAR, V_REC.TITLU, V_REC.DENUMIRE, V_REC.SIMBOLCONT, V_REC.VALOARE, V_REC.RESTANTE, V_REC.VIZIBIL, V_REC.AREDETALII, V_REC.EXPANDAT, V_REC.ESTETOTAL, V_REC.EDITABIL, V_REC.OBS, V_REC.DETALIU, V_REC.CODPART, V_REC.HEADERFOOTER, V_REC.WEEK1, V_REC.WEEK2, V_REC.WEEK3, V_REC.WEEK4, V_REC.WEEK5, V_REC.WEEK6, V_REC.WEEK7, V_REC.WEEK8, V_REC.WEEK9, V_REC.WEEK10, V_REC.WEEK11, V_REC.WEEK12, V_REC.WEEK13, V_REC.WEEK14, V_REC.WEEK15, V_REC.WEEK16, V_REC.WEEK17, V_REC.WEEK18, V_REC.WEEK19, V_REC.WEEK20, V_REC.WEEK21, V_REC.WEEK22, V_REC.WEEK23, V_REC.WEEK24, V_REC.WEEK25, V_REC.WEEK26, V_REC.WEEK27, V_REC.WEEK28, V_REC.WEEK29, V_REC.WEEK30, V_REC.WEEK31, V_REC.WEEK32, V_REC.WEEK33, V_REC.WEEK34, V_REC.WEEK35, V_REC.WEEK36, V_REC.WEEK37, V_REC.WEEK38, V_REC.WEEK39, V_REC.WEEK40, V_REC.WEEK41, V_REC.WEEK42, V_REC.WEEK43, V_REC.WEEK44, V_REC.WEEK45, V_REC.WEEK46, V_REC.WEEK47, V_REC.WEEK48, V_REC.WEEK49, V_REC.WEEK50, V_REC.WEEK51, V_REC.WEEK52, V_REC.PESTE52, V_REC.CODDOC);
      END IF;
    END LOOP;

    DELETE FROM WEEKCASHPLATI WHERE CODCASHPLATI IN (SELECT CODCASHPLATI FROM TMP_WEEKCASHPLATI_INI) AND CODCASHPLATI not IN (SELECT CODCASHPLATI FROM TMP_WEEKCASHPLATI);

    FOR V_REC IN (SELECT * FROM TMP_WEEKCASHPLATI) LOOP
      IF  V_REC.CODCASHPLATI &gt; 0 THEN
        UPDATE WEEKCASHPLATI
        SET
        CODCASHFLOW1 = V_REC.CODCASHFLOW1,
        CODOBLIGPIF  = V_REC.CODOBLIGPIF,
        DATAPLATA    = V_REC.DATAPLATA,
        SUMAPLATA    = V_REC.SUMAPLATA,
        PREFIXDOC    = V_REC.PREFIXDOC,
        NRDOC        = V_REC.NRDOC,
        DATADOC      = V_REC.DATADOC,
        RESTOBLIG    = V_REC.RESTOBLIG,
        CODDOC       = V_REC.CODDOC,
        TIPDOC       = V_REC.TIPDOC,
        TERMENOBLIG  = V_REC.TERMENOBLIG,
        CODBANKCONT  = V_REC.CODBANKCONT
        WHERE
         CODCASHPLATI = V_REC.CODCASHPLATI;
      ELSE
        INSERT INTO WEEKCASHPLATI(CODCASHPLATI, CODCASHFLOW1, CODOBLIGPIF, DATAPLATA, SUMAPLATA, PREFIXDOC, NRDOC, DATADOC, RESTOBLIG, CODDOC, TIPDOC, TERMENOBLIG, CODBANKCONT)
        VALUES(NEXTVAL('SEQ_WEEKCASHPLATI_CODCASHPLATI'), V_REC.CODCASHFLOW1, V_REC.CODOBLIGPIF, V_REC.DATAPLATA, V_REC.SUMAPLATA, V_REC.PREFIXDOC, V_REC.NRDOC, V_REC.DATADOC, V_REC.RESTOBLIG, V_REC.CODDOC, V_REC.TIPDOC, V_REC.TERMENOBLIG, V_REC.CODBANKCONT);
      END IF;
    END LOOP;

    DELETE FROM WEEKCASHSOLD WHERE CODCASHFLOW = RECID AND CODSOLD not IN (SELECT CODSOLD FROM TMP_WEEKCASHSOLD);

    FOR V_REC IN (SELECT * FROM TMP_WEEKCASHSOLD) LOOP
      IF  V_REC.CODSOLD &lt; 0 THEN
        INSERT INTO WEEKCASHSOLD(CODSOLD, CODCASHFLOW, CODBANKCONT, SOLD, REST, PLATI, CODLIMCREDIT)
        VALUES(NEXTVAL('SEQ_WEEKCASHSOLD_CODSOLD'), RECID, V_REC.CODBANKCONT, V_REC.SOLD, V_REC.REST, V_REC.PLATI, V_REC.CODLIMCREDIT);
      ELSE
        UPDATE WEEKCASHSOLD
        SET
        CODBANKCONT  = V_REC.CODBANKCONT,
        CODLIMCREDIT = V_REC.CODLIMCREDIT,
        SOLD         = V_REC.SOLD,
        PLATI        = V_REC.PLATI,
        REST         = V_REC.REST
        WHERE
         CODSOLD = V_REC.CODSOLD;
      END IF;
    END LOOP;
  ELSE
    SELECT NEXTVAL('SEQ_WEEKCASHFLOW_CODCASHFLOW') INTO RecID;

    IF (SELECT WME_RESULT FROM PKG_USERFIRME_ValidPostLog(NULL, TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999'), (current_setting('PKG_WEEKCASHFLOW.CT_MONITOR', true))))
    THEN
      PERFORM PKG_USERFIRME_PostLogcucommit( 'WEEKCASHFLOW', (current_setting('PKG_GLOBALS.USERNAME', true)), 'A', RECID, (current_setting('PKG_GLOBALS.FIRMANAME', true)), aCodSubunit, aDataDoc, aDoc, '', (SELECT PKG_GLOBALS_GET_EXE_VERSION.WME_RESULT FROM PKG_GLOBALS_GET_EXE_VERSION(NULL,NULL)));
    END IF;

    INSERT INTO WEEKCASHFLOW(CODCASHFLOW, NRDOC, DATADOC, SAPTAMANA, SUBUNITATEA, TIP)
    SELECT RECID, NRDOC, DATADOC, SAPTAMANA, SUBUNITATEA, TIP FROM TMP_WEEKCASHFLOW;

    FOR V_REC IN (SELECT * FROM TMP_WEEKCASHFLOW1) LOOP
      VCOD := NEXTVAL('SEQ_WEEKCASHFLOW1_CODCASHFLOW1');
      UPDATE TMP_WEEKCASHPLATI SET CODCASHFLOW1 = VCOD WHERE CODCASHFLOW1 = V_REC.CODCASHFLOW1;

      INSERT INTO WEEKCASHFLOW1(CODCASHFLOW1, CODCASHFLOW, INDEXTIPLINIE, INDEXLOCAL, INDEXSECUNDAR, TITLU, DENUMIRE, SIMBOLCONT, VALOARE, RESTANTE, VIZIBIL, AREDETALII, EXPANDAT, ESTETOTAL, EDITABIL, OBS, DETALIU, CODPART, HEADERFOOTER, WEEK1, WEEK2, WEEK3, WEEK4, WEEK5, WEEK6, WEEK7, WEEK8, WEEK9, WEEK10, WEEK11, WEEK12, WEEK13, WEEK14, WEEK15, WEEK16, WEEK17, WEEK18, WEEK19, WEEK20, WEEK21, WEEK22, WEEK23, WEEK24, WEEK25, WEEK26, WEEK27, WEEK28, WEEK29, WEEK30, WEEK31, WEEK32, WEEK33, WEEK34, WEEK35, WEEK36, WEEK37, WEEK38, WEEK39, WEEK40, WEEK41, WEEK42, WEEK43, WEEK44, WEEK45, WEEK46, WEEK47, WEEK48, WEEK49, WEEK50, WEEK51, WEEK52, PESTE52, CODDOC)
      VALUES(VCOD, RECID, V_REC.INDEXTIPLINIE, V_REC.INDEXLOCAL, V_REC.INDEXSECUNDAR, V_REC.TITLU, V_REC.DENUMIRE, V_REC.SIMBOLCONT, V_REC.VALOARE, V_REC.RESTANTE, V_REC.VIZIBIL, V_REC.AREDETALII, V_REC.EXPANDAT, V_REC.ESTETOTAL, V_REC.EDITABIL, V_REC.OBS, V_REC.DETALIU, V_REC.CODPART, V_REC.HEADERFOOTER, V_REC.WEEK1, V_REC.WEEK2, V_REC.WEEK3, V_REC.WEEK4, V_REC.WEEK5, V_REC.WEEK6, V_REC.WEEK7, V_REC.WEEK8, V_REC.WEEK9, V_REC.WEEK10, V_REC.WEEK11, V_REC.WEEK12, V_REC.WEEK13, V_REC.WEEK14, V_REC.WEEK15, V_REC.WEEK16, V_REC.WEEK17, V_REC.WEEK18, V_REC.WEEK19, V_REC.WEEK20, V_REC.WEEK21, V_REC.WEEK22, V_REC.WEEK23, V_REC.WEEK24, V_REC.WEEK25, V_REC.WEEK26, V_REC.WEEK27, V_REC.WEEK28, V_REC.WEEK29, V_REC.WEEK30, V_REC.WEEK31, V_REC.WEEK32, V_REC.WEEK33, V_REC.WEEK34, V_REC.WEEK35, V_REC.WEEK36, V_REC.WEEK37, V_REC.WEEK38, V_REC.WEEK39, V_REC.WEEK40, V_REC.WEEK41, V_REC.WEEK42, V_REC.WEEK43, V_REC.WEEK44, V_REC.WEEK45, V_REC.WEEK46, V_REC.WEEK47, V_REC.WEEK48, V_REC.WEEK49, V_REC.WEEK50, V_REC.WEEK51, V_REC.WEEK52, V_REC.PESTE52, V_REC.CODDOC);
    END LOOP;

    INSERT INTO WEEKCASHPLATI(CODCASHPLATI, CODCASHFLOW1, CODOBLIGPIF, DATAPLATA, SUMAPLATA, PREFIXDOC, NRDOC, DATADOC, RESTOBLIG, TERMENOBLIG, CODBANKCONT)
    SELECT NEXTVAL('SEQ_WEEKCASHPLATI_CODCASHPLATI'), CODCASHFLOW1, CODOBLIGPIF, DATAPLATA, SUMAPLATA, PREFIXDOC, NRDOC, DATADOC, RESTOBLIG, TERMENOBLIG, CODBANKCONT
    FROM TMP_WEEKCASHPLATI;

    INSERT INTO WEEKCASHSOLD(CODSOLD, CODCASHFLOW, CODBANKCONT, SOLD, REST, PLATI, CODLIMCREDIT)
    SELECT NEXTVAL('SEQ_WEEKCASHSOLD_CODSOLD'), RECID, CODBANKCONT, SOLD, REST, PLATI, CODLIMCREDIT FROM TMP_WEEKCASHSOLD;
  END IF;

  PERFORM NotifyModif( Operation, RecId, 'WEEKCASHFLOW');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_comenzi_agent</obj_name>
  <obj_hashval>64c325ca93e6ba4e74790e8d589240ef</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_comenzi_agent(INOUT wme_result refcursor, INOUT acodpers numeric, INOUT adenpart character varying, INOUT datastart character varying, INOUT aobs character varying, INOUT astare character varying, INOUT anrdoc character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  S             varchar;
  COMANDACURSOR REFCURSOR;
  FILTRU_PART   varchar := '';
  FILTRU_DATA   varchar := '';
  FILTRU_OBS    varchar := '';
  FILTRU_STARE  varchar := '';
  FILTRU_NRDOC  varchar := '';
BEGIN
  --Florin 19.09.2024 - sinc. Oracle
  IF COALESCE (aDENPART, '?') &lt;&gt; '?' THEN
    FILTRU_PART := coalesce (' AND UPPER(DEN_PART) LIKE '|| '''%','')|| coalesce (UPPER (aDENPART) ,'')|| '%''';
  END IF;
  IF COALESCE (DATASTART, '?') &lt;&gt; '?' THEN
    FILTRU_DATA := ' AND TO_DATE(DATADOC, ''DD-MM-YYYY'') &gt;= TO_DATE('''|| coalesce (To_Char (DATASTART,'dd.mm.yyyy') ,'')|| ''',''DD-MM-YYYY'') ';
  END IF;
  IF COALESCE (aOBS, '?') &lt;&gt; '?' THEN
    FILTRU_OBS := coalesce (' AND UPPER(OBS) LIKE '|| '''%','')|| coalesce (UPPER (aOBS) ,'')|| '%''';
  END IF;
  IF COALESCE (aSTARE, '?') &lt;&gt; '?' THEN
    FILTRU_STARE := coalesce (' AND UPPER(STARECOMANDA) LIKE '|| '''%','')|| coalesce (UPPER (aSTARE) ,'')|| '%''';
  END IF;
  IF NVL(aSTARE, '?') &lt;&gt; '?' THEN
    IF UPPER(aSTARE) = 'TOATE' THEN
      FILTRU_STARE := '';
    END IF;
  END IF;
  IF COALESCE (aNRDOC, '?') &lt;&gt; '?' THEN
    FILTRU_NRDOC := coalesce (' AND UPPER(NRDOC) LIKE '|| '''%','')|| coalesce (UPPER (aNRDOC) ::varchar ,'')|| '%''';
  END IF;

  S := coalesce ('SELECT * FROM '
  || '(SELECT ','')
  || '   CODCOMANDA, '
  || '   TIPDOC, '
  || '   ANULAT, '
  || '   BLOCAT, '
  || '   OPERAT, '
  || '   PREFIXDOC, '
  || '   INCHISA, '
  || '   NRDOC, '
  || '   DATADOC, '
  || '   NUMEAGENT, '
  || '   DEN_LOCALIT, '
  || '   to_char(DATACREARE, ''dd.mm.yyyy hh24:mi'') DATACREARE, '
  || '   VERIFICAT, '
  || '   FACTURABIL, '
  || '   NRI,  '
  || '   SERIADOC, '
  || '   PARTENER,'
  || '   VALOARE, '
  || '   AN, '
  || '   LUNA,  '
  || '   OBS, '
  || '   MONEDA, '
  || '   DEN_PART, '
  || '   SIMBOL, '
  || '   SUBUNITATEDOC, '
  || '   SEDIULIVRARE, '
  || '   DELEGAT, '
  || '   PC_CODPERSC, '
  || '   PC_NUME, '
  || '   PC_PRENUME, '
  || '   PC_TELEFON, '
  || '   PC_EMAIL, '
  || '   PC_CNP, '
  || '    (  '
  || '   CASE '
  || '     WHEN FARAFACTURA  = 1 THEN ''FARA FACTURARE'' '
  || '     WHEN CANTACCEPTAT = 0 THEN ''NECONFIRMATA'' '
  || '     WHEN CANTACCEPTAT =  RESTACCEPTAT      THEN ''NEFACTURATA''  '
  || '     WHEN CANTACCEPTAT &lt;&gt; 0 AND CU_REST = 0 THEN ''FACTURATA INTEGRAL''  '
  || '     WHEN CANTACCEPTAT &gt; RESTACCEPTAT       THEN ''FACTURATA PARTIAL'' '
  || '     ELSE '''' '
  || '   END '
  || '    ) AS STARECOMANDA  '
  || '   FROM  '
  || '   ( '
  || '  SELECT '
  || '    c.CODCOMANDA, c.TIPDOC, c.ANULAT, c.BLOCAT, c.OPERAT, c.PREFIXDOC, c.NRDOC, C.INCHISA, C.DATACREARE, C.VERIFICAT, C.FACTURABIL, coalesce(C.FARAFACTURA, 0) FARAFACTURA, C.NRI, C.LISTAT, C.SERIADOC,  '
  || '    c.DATADOC, c.PARTENER, c.VALOARE, c.AN, c.LUNA, PER.NUME || '' '' || PER.PRENUME AS NUMEAGENT, L.DEN_LOCALIT,  '
  || '    NPC.CODPERSC PC_CODPERSC, NPC.NUME PC_NUME, NPC.PRENUME PC_PRENUME, NPC.TELEFON PC_TELEFON, NPC.EMAIL PC_EMAIL, NPC.CNP PC_CNP, '
  || '    (SELECT (case when COUNT(*) = 0 then 0 else 1 end) FROM DOCUMENTE D WHERE D.TIPDOC = C.TIPDOC AND D.CODDOC = C.CODCOMANDA) AS ATASAMENT,  '
  || '    c.OBS, c.MONEDA, c.CODCONTRACT, c.CODCMDPARINTE, p.Den_Part,  M.SIMBOL, SUB.DEN_SUBUNIT AS SUBUNITATEDOC,  A.OBS AS SEDIULIVRARE, D.DELEGAT, '
  || '    (SELECT coalesce(SUM(CANTACCEPTAT), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) AS CANTACCEPTAT, '
  || '    (SELECT coalesce(SUM(RESTACCEPTAT), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) AS RESTACCEPTAT, '
  || '    (SELECT coalesce(COUNT(*), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA AND coalesce(CANTACCEPTAT, 0) &gt; 0 AND coalesce(RESTACCEPTAT, 0) &gt; 0) AS CU_REST '
  || '  FROM  '
  || '     COMANDA c
           LEFT OUTER JOIN NPART        P   ON P.CODPART      = C.PARTENER  '
  || '     LEFT OUTER JOIN NCLASEP      CP  ON CP.CODCLASEP   = P.CODCLASA '
  || '     LEFT OUTER JOIN NAGENDA      A   ON A.CODAGENDA    = C.CODLOCATIE '
  || '     LEFT OUTER JOIN NLOCALIT     L   ON L.CODLOCALIT   = A.CODLOCALIT '
  || '     LEFT OUTER JOIN NMONEDE      M   ON M.CODMONEDA    = coalesce(C.MONEDA, 0) '
  || '     LEFT OUTER JOIN NSUBUNIT     SUB ON SUB.CODSUBUNIT = C.SUBUNITATEA '
  || '     LEFT OUTER JOIN NPERS        PER ON PER.CODPERS    = C.AGENT '
  || '     LEFT OUTER JOIN NPARTTR      D   ON D.CODPARTTR    = C.DELEGAT '
  || '     LEFT OUTER JOIN NPERSCONTACT NPC ON NPC.CODPERSC   = C.CODPERSC '
  || '  WHERE '
  || '     coalesce(C.DISPLIVRARE,0) = 0 '
  || '      AND C.TIPDOC =  18 '
  || '      AND C.AGENT = '|| coalesce ( (aCODPERS) ::varchar::varchar ,'')
  || '      AND c.SUBUNITATEA =PKG_GLOBALS_GETSUBUNITATE '
  || '  ) '
  || ') '
  || ' WHERE '
  || ' 1 = 1 '
  || coalesce (Filtru_Part,'')
  || coalesce (To_Char (FILTRU_DATA,'dd.mm.yyyy') ,'')
  || coalesce (FILTRU_OBS,'')
  || coalesce (FILTRU_STARE,'')
  || coalesce (FILTRU_NRDOC::varchar ,'')
  || ' ORDER BY DATADOC';

  OPEN COMANDACURSOR FOR EXECUTE S;
  WME_Result := COMANDACURSOR;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_comenzi_agent_4php</obj_name>
  <obj_hashval>f97492de7f4655926e56b1a88239376a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_comenzi_agent_4php(refcursor, numeric, character varying, character varying, character varying, character varying, character varying)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
DECLARE
  S varchar;
  COMANDACURSOR REFCURSOR;
  FILTRU_PART  varchar := '';
  FILTRU_DATA  varchar := '';
  FILTRU_OBS   varchar := '';
  FILTRU_STARE varchar := '';
  FILTRU_NRDOC varchar := '';
begin
  IF COALESCE ($3, '?') not in ('?', '') THEN
    FILTRU_PART := coalesce (' AND UPPER(DEN_PART) LIKE '|| '''%','')|| coalesce (UPPER ($3) ,'')|| '%''';
  END IF;
  IF COALESCE ($4, '?') not in ('?', '') THEN
    FILTRU_DATA := ' AND DATADOC &gt;= TO_DATE('''|| $4|| ''',''DD-MM-YYYY'') ';
  END IF;
  IF COALESCE ($5, '?') not in ('?', '') THEN
    FILTRU_OBS := coalesce (' AND UPPER(OBS) LIKE '|| '''%','')|| coalesce (UPPER ($5) ,'')|| '%''';
  END IF;
  IF COALESCE ($6, '?') not in ('?', '') THEN
    FILTRU_STARE := coalesce (' AND UPPER(STARECOMANDA) LIKE '|| '''%','')|| coalesce (UPPER ($6) ,'')|| '%''';
     IF UPPER($6) = 'TOATE' THEN
    FILTRU_STARE := '';
  END IF;
  END IF;
  IF COALESCE ($7, '?') not in ('?', '') THEN
    FILTRU_NRDOC := coalesce (' AND UPPER(NRDOC::varchar) LIKE '|| '''%','')|| coalesce (UPPER ($7) ::varchar ,'')|| '%''';
  END IF;

  S := coalesce ('SELECT * FROM '
  || '(SELECT ','')
  || '   CODCOMANDA, '
  || '   TIPDOC, '
  || '   ANULAT, '
  || '   BLOCAT, '
  || '   OPERAT, '
  || '   PREFIXDOC, '
  || '   INCHISA, '
  || '   NRDOC, '
  || '   DATADOC, '
  || '   NUMEAGENT, '
  || '   DEN_LOCALIT, '
  || '   to_char(DATACREARE, ''dd.mm.yyyy hh24:mi'') DATACREARE, '
  || '   VERIFICAT, '
  || '   FACTURABIL, '
  || '   NRI,  '
  || '   SERIADOC, '
  || '   PARTENER,'
  || '   VALOARE, '
  || '   AN, '
  || '   LUNA,  '
  || '   OBS, '
  || '   MONEDA, '
  || '   DEN_PART, '
  || '   SIMBOL, '
  || '   SUBUNITATEDOC, '
  || '   SEDIULIVRARE, '
  || '   DELEGAT, '
  || '   PC_CODPERSC, '
  || '   PC_NUME, '
  || '   PC_PRENUME, '
  || '   PC_TELEFON, '
  || '   PC_EMAIL, '
  || '   PC_CNP, '
  || '    (  '
  || '   CASE '
  || '     WHEN FARAFACTURA = 1 THEN ''FARA FACTURARE'' '
  || '     WHEN CANTACCEPTAT = 0 THEN ''NECONFIRMATA'' '
  || '     WHEN CANTACCEPTAT =  RESTACCEPTAT THEN ''NEFACTURATA''  '
  || '     WHEN CANTACCEPTAT &lt;&gt; 0 AND CU_REST = 0 THEN ''FACTURATA INTEGRAL''  '
  || '     WHEN CANTACCEPTAT &gt; RESTACCEPTAT  THEN ''FACTURATA PARTIAL'' '
  || '     ELSE '''' '
  || '   END '
  || '    ) AS STARECOMANDA  '
  || '   FROM  '
  || '   ( '
  || '  SELECT '
  || '    c.CODCOMANDA, c.TIPDOC, c.ANULAT, c.BLOCAT, c.OPERAT, c.PREFIXDOC, c.NRDOC, C.INCHISA, C.DATACREARE, C.VERIFICAT, C.FACTURABIL, coalesce(C.FARAFACTURA, 0) FARAFACTURA, C.NRI, C.LISTAT, C.SERIADOC,  '
  || '    c.DATADOC, c.PARTENER, c.VALOARE, c.AN, c.LUNA, PER.NUME || '' '' || PER.PRENUME AS NUMEAGENT, L.DEN_LOCALIT,  '
  || '    NPC.CODPERSC PC_CODPERSC, NPC.NUME PC_NUME, NPC.PRENUME PC_PRENUME, NPC.TELEFON PC_TELEFON, NPC.EMAIL PC_EMAIL, NPC.CNP PC_CNP, '
  || '    (SELECT (case when COUNT(*) = 0 then 0 else 1 end) FROM DOCUMENTE D WHERE D.TIPDOC = C.TIPDOC AND D.CODDOC = C.CODCOMANDA) AS ATASAMENT,  '
  || '    c.OBS, c.MONEDA, c.CODCONTRACT, c.CODCMDPARINTE, p.Den_Part,  M.SIMBOL, SUB.DEN_SUBUNIT AS SUBUNITATEDOC,  A.OBS AS SEDIULIVRARE, D.DELEGAT, '
  || '    (SELECT coalesce(SUM(CANTACCEPTAT), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) AS CANTACCEPTAT, '
  || '    (SELECT coalesce(SUM(RESTACCEPTAT), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) AS RESTACCEPTAT, '
  || '    (SELECT coalesce(COUNT(*), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA AND coalesce(CANTACCEPTAT, 0) &gt; 0 AND coalesce(RESTACCEPTAT, 0) &gt; 0) AS CU_REST '
  || '  FROM  '
  || '     COMANDA c
           LEFT OUTER JOIN NPART        P   ON P.CODPART      = C.PARTENER  '
  || '     LEFT OUTER JOIN NCLASEP      CP  ON CP.CODCLASEP   = P.CODCLASA '
  || '     LEFT OUTER JOIN NAGENDA      A   ON A.CODAGENDA    = C.CODLOCATIE '
  || '     LEFT OUTER JOIN NLOCALIT     L   ON L.CODLOCALIT   = A.CODLOCALIT '
  || '     LEFT OUTER JOIN NMONEDE      M   ON M.CODMONEDA    = coalesce(C.MONEDA, 0) '
  || '     LEFT OUTER JOIN NSUBUNIT     SUB ON SUB.CODSUBUNIT = C.SUBUNITATEA '
  || '     LEFT OUTER JOIN NPERS        PER ON PER.CODPERS    = C.AGENT '
  || '     LEFT OUTER JOIN NPARTTR      D   ON D.CODPARTTR    = C.DELEGAT '
  || '     LEFT OUTER JOIN NPERSCONTACT NPC ON NPC.CODPERSC   = C.CODPERSC '
  || '  WHERE '
  || '     coalesce(C.DISPLIVRARE,0) = 0 '
  || '      AND C.TIPDOC =  18 '
  || '      AND C.AGENT = '|| coalesce ( ($2) ::varchar::varchar ,'')
  || '      AND c.SUBUNITATEA = ' || (current_setting('PKG_GLOBALS.SUBUNITATE', True))::numeric
  || '  ) sq '
  || ') sq1 '
  || ' WHERE '
  || ' 1 = 1 '
  || coalesce (Filtru_Part,'')
  || coalesce (FILTRU_DATA,'')
  || coalesce (FILTRU_OBS,'')
  || coalesce (FILTRU_STARE,'')
  || coalesce (FILTRU_NRDOC::varchar ,'')
  || ' ORDER BY DATADOC DESC, NRDOC DESC';

  OPEN $1 FOR EXECUTE S;
  return next $1;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_comenzi_client</obj_name>
  <obj_hashval>7b67c2fad8b96a828a920db2d7e31516</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_comenzi_client(INOUT wme_result refcursor, INOUT acodpart numeric, INOUT datastart character varying, INOUT asediulivrare character varying, INOUT aobs character varying, INOUT astare character varying, INOUT anrdoc character varying, INOUT afacturabil character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  S varchar;
  COMANDACURSOR REFCURSOR;
  FILTRU_DATA       varchar := '';
  FILTRU_SEDIU      varchar := '';
  FILTRU_OBS        varchar := '';
  FILTRU_STARE      varchar := '';
  FILTRU_NRDOC      varchar := '';
  FILTRU_FACTURABIL varchar := '';
begin
  IF COALESCE (DATASTART, '?') &lt;&gt; '?' THEN
    FILTRU_DATA := ' AND TO_DATE(DATADOC, ''DD-MM-YYYY'') &gt;= TO_DATE('''|| coalesce (To_Char (DATASTART,'dd.mm.yyyy') ,'')|| ''',''DD-MM-YYYY'') ';
  END IF;
  IF COALESCE (aSEDIULIVRARE, '?') &lt;&gt; '?' THEN
    FILTRU_SEDIU := coalesce (' AND UPPER(SEDIULIVRARE) LIKE '|| '''%','')|| coalesce (UPPER (aSEDIULIVRARE) ,'')|| '%''';
  END IF;
  IF COALESCE (aOBS, '?') &lt;&gt; '?' THEN
    FILTRU_OBS := coalesce (' AND UPPER(OBS) LIKE '|| '''%','')|| coalesce (UPPER (aOBS) ,'')|| '%''';
  END IF;
  IF COALESCE (aSTARE, '?') &lt;&gt; '?' THEN
    FILTRU_STARE := coalesce (' AND UPPER(STARECOMANDA) LIKE '|| '''%','')|| coalesce (UPPER (aSTARE) ,'')|| '%''';
  END IF;
  IF COALESCE (aNRDOC, '?') &lt;&gt; '?' THEN
    FILTRU_NRDOC := coalesce (' AND UPPER(NRDOC) LIKE '|| '''%','')|| coalesce (UPPER (aNRDOC) ::varchar ,'')|| '%''';
  END IF;
  IF COALESCE (aFACTURABIL, '?') &lt;&gt; '?' THEN
    FILTRU_FACTURABIL := coalesce (' AND TO_CHAR(FACTURABIL) LIKE '|| '''%','')|| coalesce (aFACTURABIL,'')|| '%''';
  END IF;

  S := coalesce ('SELECT * FROM '
  || '(SELECT ','')
  || '   CODCOMANDA, '
  || '   TIPDOC, '
  || '   ANULAT, '
  || '   BLOCAT, '
  || '   OPERAT, '
  || '   PREFIXDOC, '
  || '   INCHISA, '
  || '   NRDOC, '
  || '   DATADOC, '
  || '   NUMEAGENT, '
  || '   DEN_LOCALIT, '
  || '   to_char(DATACREARE, ''dd.mm.yyyy hh24:mi'') DATACREARE, '
  || '   VERIFICAT, '
  || '   FACTURABIL, '
  || '   NRI,  '
  || '   SERIADOC, '
  || '   PARTENER,'
  || '   VALOARE, '
  || '   AN, '
  || '   LUNA,  '
  || '   OBS, '
  || '   MONEDA, '
  || '   DEN_MONEDA, '
  || '   DEN_PART, '
  || '   SIMBOL, '
  || '   SUBUNITATEDOC, '
  || '   SEDIULIVRARE, '
  || '   DELEGAT, '
  || '    (  '
  || '   CASE '
  || '     WHEN FARAFACTURA = 1 THEN ''FARA FACTURARE'' '
  || '     WHEN CANTACCEPTAT = 0 THEN ''NECONFIRMATA'' '
  || '     WHEN CANTACCEPTAT =  RESTACCEPTAT THEN ''NEFACTURATA''  '
  || '     WHEN CANTACCEPTAT &lt;&gt; 0 AND CU_REST = 0 THEN ''FACTURATA INTEGRAL''  '
  || '     WHEN CANTACCEPTAT &gt; RESTACCEPTAT  THEN ''FACTURATA PARTIAL'' '
  || '     ELSE '''' '
  || '   END '
  || '    ) AS STARECOMANDA  '
  || '   FROM  '
  || '   ( '
  || '  SELECT '
  || '    c.CODCOMANDA, c.TIPDOC, c.ANULAT, c.BLOCAT, c.OPERAT, c.PREFIXDOC, c.NRDOC, C.INCHISA, C.DATACREARE, C.VERIFICAT, C.FACTURABIL, coalesce(C.FARAFACTURA, 0) FARAFACTURA, C.NRI, C.LISTAT, C.SERIADOC,  '
  || '    c.DATADOC, c.PARTENER, c.VALOARE, c.AN, c.LUNA, PER.NUME || '' '' || PER.PRENUME AS NUMEAGENT, L.DEN_LOCALIT,  '
  || '    (SELECT ( case when COUNT(*) = 0 then 0 else 1 end) FROM DOCUMENTE D WHERE D.TIPDOC = C.TIPDOC AND D.CODDOC = C.CODCOMANDA) AS ATASAMENT,  '
  || '    c.OBS, c.MONEDA, c.CODCONTRACT, c.CODCMDPARINTE, p.Den_Part,  M.SIMBOL, M.DEN_MONEDA, SUB.DEN_SUBUNIT AS SUBUNITATEDOC,  A.OBS AS SEDIULIVRARE, D.DELEGAT, '
  || '    (SELECT coalesce(SUM(CANTACCEPTAT), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) AS CANTACCEPTAT, '
  || '    (SELECT coalesce(SUM(RESTACCEPTAT), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) AS RESTACCEPTAT, '
  || '    (SELECT coalesce(COUNT(*), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA AND coalesce(CANTACCEPTAT, 0) &gt; 0 AND coalesce(RESTACCEPTAT, 0) &gt; 0) AS CU_REST '
  || '  FROM  '
  || '     COMANDA c
           LEFT OUTER JOIN NPART    P   ON P.CODPART      = C.PARTENER  '
  || '     LEFT OUTER JOIN NCLASEP  CP  ON CP.CODCLASEP   = P.CODCLASA '
  || '     LEFT OUTER JOIN NAGENDA  A   ON A.CODAGENDA    = C.CODLOCATIE '
  || '     LEFT OUTER JOIN NLOCALIT L   ON L.CODLOCALIT   = A.CODLOCALIT '
  || '     LEFT OUTER JOIN NMONEDE  M   ON M.CODMONEDA    = coalesce(C.MONEDA, 0) '
  || '     LEFT OUTER JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = C.SUBUNITATEA '
  || '     LEFT OUTER JOIN NPERS    PER ON PER.CODPERS    = C.AGENT '
  || '     LEFT OUTER JOIN NPARTTR  D   ON D.CODPARTTR    = C.DELEGAT '
  || '  WHERE '
  || '     coalesce(C.DISPLIVRARE,0) = 0 '
  || '      AND C.TIPDOC =  18 '
  || '      AND C.PARTENER = '|| coalesce ( (aCODPART) ::varchar::varchar ,'')
  || '      AND c.SUBUNITATEA =PKG_GLOBALS_GETSUBUNITATE '
  || '  ) '
  || ') '
  || ' WHERE '
  || ' 1 = 1 '
  || coalesce (To_Char (FILTRU_DATA,'dd.mm.yyyy') ,'')
  || coalesce (FILTRU_SEDIU,'')
  || coalesce (FILTRU_OBS,'')
  || coalesce (FILTRU_STARE,'')
  || coalesce (FILTRU_NRDOC::varchar ,'')
  || coalesce (FILTRU_FACTURABIL,'')
  || ' ORDER BY DATADOC';

  OPEN COMANDACURSOR for execute S;
  WME_Result := COMANDACURSOR;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_comenzi_client_4php</obj_name>
  <obj_hashval>0049d577519a7491f252ce0f691b7a56</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_comenzi_client_4php(refcursor, numeric, character varying, character varying, character varying, character varying, character varying, character varying, character varying)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
  DECLARE
    S varchar;
    COMANDACURSOR REFCURSOR;
    FILTRU_DATA       varchar := '';
    FILTRU_SEDIU      varchar := '';
    FILTRU_OBS        varchar := '';
    FILTRU_STARE      varchar := '';
    FILTRU_NRDOC      varchar := '';
    FILTRU_FACTURABIL varchar := '';
  FILTRU_NRI varchar := '';
  begin
    IF COALESCE ($3, '?') not in ('?', '') THEN
      FILTRU_DATA := ' AND DATADOC &gt;= TO_DATE('''
    || $3
      || ''',''DD-MM-YYYY'') ';
    END IF;
    IF COALESCE ($4, '?') not in ('?', '') THEN
      FILTRU_SEDIU := coalesce (' AND UPPER(SEDIULIVRARE) LIKE '
      || '''%','')
      || coalesce (UPPER ($4) ,'')
      || '%''';
    END IF;
    IF COALESCE ($5, '?') not in ('?', '') THEN
      FILTRU_OBS := coalesce (' AND UPPER(OBS) LIKE '
      || '''%','')
      || coalesce (UPPER ($5) ,'')
      || '%''';
    END IF;
    IF COALESCE ($6, '?') not in ('?', '') THEN
      FILTRU_STARE := coalesce (' AND UPPER(STARECOMANDA) LIKE '
      || '''%','')
      || coalesce (UPPER ($6) ,'')
      || '%''';
      IF UPPER($6) = 'FIC' THEN
    FILTRU_STARE := ' AND ( UPPER(STARECOMANDA) = ''NEFACTURATA'' OR UPPER(STARECOMANDA) = ''FACTURATA PARTIAL'' ) ';
    END IF;
    IF UPPER($6) = 'ANULATA' THEN
    FILTRU_STARE := ' AND ANULAT = 1 ';
    END IF;
    IF UPPER($6) = 'INCHISA' THEN
    FILTRU_STARE := ' AND INCHISA = 1 ';
    END IF;
    IF UPPER($6) = 'TOATE' THEN
    FILTRU_STARE := '';
    END IF;
    END IF;
    IF COALESCE ($7, '?') not in ('?', '') THEN
      FILTRU_NRDOC := coalesce (' AND UPPER(NRDOC::varchar) LIKE '
      || '''%','')
      || coalesce (UPPER ($7) ::varchar ,'')
      || '%''';
    END IF;
    IF COALESCE ($8, '?') not in ('?', '') THEN
      FILTRU_FACTURABIL := ' AND FACTURABIL = ' || $8 || ' ';
    END IF;
  IF COALESCE ($9, '?') not in ('?', '') THEN
      FILTRU_NRI := coalesce (' AND UPPER(NRI::varchar) LIKE '
      || '''%','')
      || coalesce (UPPER ($9) ::varchar ,'')
      || '%''';
    END IF;
    S := coalesce ('SELECT * FROM '
    || '(SELECT ','')
    || '   CODCOMANDA, '
    || '   TIPDOC, '
    || '   ANULAT, '
    || '   BLOCAT, '
    || '   OPERAT, '
    || '   PREFIXDOC, '
    || '   INCHISA, '
    || '   NRDOC, '
    || '   DATADOC, '
    || '   NUMEAGENT, '
    || '   DEN_LOCALIT, '
    || '   to_char(DATACREARE, ''dd.mm.yyyy hh24:mi'') DATACREARE, '
    || '   VERIFICAT, '
    || '   FACTURABIL, '
    || '   NRI,  '
    || '   SERIADOC, '
    || '   PARTENER,'
    || '   VALOARE, '
    || '   AN, '
    || '   LUNA,  '
    || '   OBS, '
    || '   MONEDA, '
    || '   DEN_MONEDA, '
    || '   DEN_PART, '
    || '   SIMBOL, '
    || '   SUBUNITATEDOC, '
    || '   SEDIULIVRARE, '
    || '   DELEGAT, '
    || '    (  '
    || '   CASE '
    || '     WHEN ANULAT = 1 THEN ''ANULATA'' '
  || '     WHEN INCHISA = 1 THEN ''INCHISA'' '
    || '     WHEN FARAFACTURA = 1 THEN ''FARA FACTURARE'' '
    || '     WHEN CANTACCEPTAT = 0 THEN ''NECONFIRMATA'' '
    || '     WHEN CANTACCEPTAT =  RESTACCEPTAT THEN ''NEFACTURATA''  '
    || '     WHEN CANTACCEPTAT &lt;&gt; 0 AND CU_REST = 0 THEN ''FACTURATA INTEGRAL''  '
    || '     WHEN CANTACCEPTAT &gt; RESTACCEPTAT  THEN ''FACTURATA PARTIAL'' '
    || '     ELSE '''' '
    || '   END '
    || '    ) AS STARECOMANDA  '
    || '   FROM  '
    || '   ( '
    || '  SELECT '
    || '    c.CODCOMANDA, c.TIPDOC, c.ANULAT, c.BLOCAT, c.OPERAT, c.PREFIXDOC, c.NRDOC, C.INCHISA, C.DATACREARE, C.VERIFICAT, C.FACTURABIL, coalesce(C.FARAFACTURA, 0) FARAFACTURA, C.NRI, C.LISTAT, C.SERIADOC,  '
    || '    c.DATADOC, c.PARTENER, c.VALOARE, c.AN, c.LUNA, PER.NUME || '' '' || PER.PRENUME AS NUMEAGENT, L.DEN_LOCALIT,  '
    || '    (SELECT ( case when COUNT(*) = 0 then 0 else 1 end) FROM DOCUMENTE D WHERE D.TIPDOC = C.TIPDOC AND D.CODDOC = C.CODCOMANDA) AS ATASAMENT,  '
    || '    c.OBS, c.MONEDA, c.CODCONTRACT, c.CODCMDPARINTE, p.Den_Part,  M.SIMBOL, M.DEN_MONEDA, SUB.DEN_SUBUNIT AS SUBUNITATEDOC,  A.OBS AS SEDIULIVRARE, D.DELEGAT, '
    || '    (SELECT coalesce(SUM(CANTACCEPTAT), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) AS CANTACCEPTAT, '
    || '    (SELECT coalesce(SUM(RESTACCEPTAT), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) AS RESTACCEPTAT, '
    || '    (SELECT coalesce(COUNT(*), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA AND coalesce(CANTACCEPTAT, 0) &gt; 0 AND coalesce(RESTACCEPTAT, 0) &gt; 0) AS CU_REST '
    || '  FROM  '
    || '     COMANDA c LEFT OUTER JOIN NPART P ON P.CODPART = C.PARTENER  '
    || '     LEFT OUTER JOIN NCLASEP CP ON CP.CODCLASEP = P.CODCLASA '
    || '     LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = C.CODLOCATIE '
    || '     LEFT OUTER JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT '
    || '     LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = coalesce(C.MONEDA, 0) '
    || '     LEFT OUTER JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = C.SUBUNITATEA '
    || '     LEFT OUTER JOIN NPERS PER ON PER.CODPERS = C.AGENT '
    || '     LEFT OUTER JOIN NPARTTR D ON D.CODPARTTR = C.DELEGAT '
    || '  WHERE '
    || '     coalesce(C.DISPLIVRARE,0) = 0 '
    || '      AND C.TIPDOC =  18 '
    || '      AND C.PARTENER = '
    || coalesce ( ($2) ::varchar::varchar ,'')
    || '      AND c.SUBUNITATEA = ' || (current_setting('PKG_GLOBALS.SUBUNITATE', True))::numeric
    || '  ) sq '
    || ') sq1 '
    || ' WHERE '
    || ' 1 = 1 '
  || coalesce (FILTRU_DATA,'')
    || coalesce (FILTRU_SEDIU,'')
    || coalesce (FILTRU_OBS,'')
    || coalesce (FILTRU_STARE,'')
    || coalesce (FILTRU_NRDOC::varchar ,'')
    || coalesce (FILTRU_FACTURABIL,'')
  || coalesce (FILTRU_NRI::varchar ,'')
    || ' ORDER BY DATADOC';
    OPEN $1 FOR EXECUTE S;
    return next $1;
  end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_comenzi_client_interval</obj_name>
  <obj_hashval>7f65b88e1f192ba00c54e8b67f1c677b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_comenzi_client_interval(INOUT wme_result refcursor, INOUT acodpart numeric, INOUT datastart character varying, INOUT dataend character varying, INOUT asediulivrare character varying, INOUT aobs character varying, INOUT astare character varying, INOUT anrdoc character varying, INOUT afacturabil character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
  DECLARE
    S varchar;
    COMANDACURSOR REFCURSOR;
    FILTRU_DATA1      varchar := '';
    FILTRU_DATA2      varchar := '';
    FILTRU_SEDIU      varchar := '';
    FILTRU_OBS        varchar := '';
    FILTRU_STARE      varchar := '';
    FILTRU_NRDOC      varchar := '';
    FILTRU_FACTURABIL varchar := '';
  begin
    IF COALESCE (DATASTART, '?') &lt;&gt; '?' THEN
      FILTRU_DATA1 := ' AND TO_DATE(DATADOC, ''DD-MM-YYYY'') &gt;= TO_DATE('''
      || coalesce (To_Char (DATASTART,'dd.mm.yyyy') ,'')
      || ''',''DD-MM-YYYY'') ';
    END IF;
    IF COALESCE (DATAEND, '?') &lt;&gt; '?' THEN
      FILTRU_DATA2 := ' AND TO_DATE(DATADOC, ''DD-MM-YYYY'') &lt;= TO_DATE('''
      || coalesce (To_Char (DATAEND,'dd.mm.yyyy') ,'')
      || ''',''DD-MM-YYYY'') ';
    END IF;
    IF COALESCE (aSEDIULIVRARE, '?') &lt;&gt; '?' THEN
      FILTRU_SEDIU := coalesce (' AND UPPER(SEDIULIVRARE) LIKE '
      || '''%','')
      || coalesce (UPPER (aSEDIULIVRARE) ,'')
      || '%''';
    END IF;
    IF COALESCE (aOBS, '?') &lt;&gt; '?' THEN
      FILTRU_OBS := coalesce (' AND UPPER(OBS) LIKE '
      || '''%','')
      || coalesce (UPPER (aOBS) ,'')
      || '%''';
    END IF;
    IF COALESCE (aSTARE, '?') &lt;&gt; '?' THEN
      FILTRU_STARE := coalesce (' AND UPPER(STARECOMANDA) LIKE '
      || '''%','')
      || coalesce (UPPER (aSTARE) ,'')
      || '%''';
    END IF;
    IF COALESCE (aNRDOC, '?') &lt;&gt; '?' THEN
      FILTRU_NRDOC := coalesce (' AND UPPER(NRDOC) LIKE '
      || '''%','')
      || coalesce (UPPER (aNRDOC) ::varchar ,'')
      || '%''';
    END IF;
    IF COALESCE (aFACTURABIL, '?') &lt;&gt; '?' THEN
      FILTRU_FACTURABIL := coalesce (' AND TO_CHAR(FACTURABIL) LIKE '
      || '''%','')
      || coalesce (aFACTURABIL,'')
      || '%''';
    END IF;
    S := coalesce ('SELECT * FROM '
    || '(SELECT ','')
    || '   CODCOMANDA, '
    || '   TIPDOC, '
    || '   ANULAT, '
    || '   BLOCAT, '
    || '   OPERAT, '
    || '   PREFIXDOC, '
    || '   INCHISA, '
    || '   NRDOC, '
    || '   DATADOC, '
    || '   NUMEAGENT, '
    || '   DEN_LOCALIT, '
    || '   to_char(DATACREARE, ''dd.mm.yyyy hh24:mi'') DATACREARE, '
    || '   VERIFICAT, '
    || '   FACTURABIL, '
    || '   NRI,  '
    || '   SERIADOC, '
    || '   PARTENER,'
    || '   VALOARE, '
    || '   AN, '
    || '   LUNA,  '
    || '   OBS, '
    || '   MONEDA, '
    || '   DEN_MONEDA, '
    || '   DEN_PART, '
    || '   SIMBOL, '
    || '   SUBUNITATEDOC, '
    || '   SEDIULIVRARE, '
    || '   DELEGAT, '
    || '    (  '
    || '   CASE '
    || '     WHEN FARAFACTURA = 1 THEN ''FARA FACTURARE'' '
    || '     WHEN CANTACCEPTAT = 0 THEN ''NECONFIRMATA'' '
    || '     WHEN CANTACCEPTAT =  RESTACCEPTAT THEN ''NEFACTURATA''  '
    || '     WHEN CANTACCEPTAT &lt;&gt; 0 AND CU_REST = 0 THEN ''FACTURATA INTEGRAL''  '
    || '     WHEN CANTACCEPTAT &gt; RESTACCEPTAT  THEN ''FACTURATA PARTIAL'' '
    || '     ELSE '''' '
    || '   END '
    || '    ) AS STARECOMANDA  '
    || '   FROM  '
    || '   ( '
    || '  SELECT '
    || '    c.CODCOMANDA, c.TIPDOC, c.ANULAT, c.BLOCAT, c.OPERAT, c.PREFIXDOC, c.NRDOC, C.INCHISA, C.DATACREARE, C.VERIFICAT, C.FACTURABIL, coalesce(C.FARAFACTURA, 0) FARAFACTURA, C.NRI, C.LISTAT, C.SERIADOC,  '
    || '    c.DATADOC, c.PARTENER, c.VALOARE, c.AN, c.LUNA, PER.NUME || '' '' || PER.PRENUME AS NUMEAGENT, L.DEN_LOCALIT,  '
    || '    (SELECT ( case when COUNT(*) = 0 then 0 else 1 end) FROM DOCUMENTE D WHERE D.TIPDOC = C.TIPDOC AND D.CODDOC = C.CODCOMANDA) AS ATASAMENT,  '
    || '    c.OBS, c.MONEDA, c.CODCONTRACT, c.CODCMDPARINTE, p.Den_Part,  M.SIMBOL, M.DEN_MONEDA, SUB.DEN_SUBUNIT AS SUBUNITATEDOC,  A.OBS AS SEDIULIVRARE, D.DELEGAT, '
    || '    (SELECT coalesce(SUM(CANTACCEPTAT), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) AS CANTACCEPTAT, '
    || '    (SELECT coalesce(SUM(RESTACCEPTAT), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) AS RESTACCEPTAT, '
    || '    (SELECT coalesce(COUNT(*), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA AND coalesce(CANTACCEPTAT, 0) &gt; 0 AND coalesce(RESTACCEPTAT, 0) &gt; 0) AS CU_REST '
    || '  FROM  '
    || '     COMANDA c LEFT OUTER JOIN NPART P ON P.CODPART = C.PARTENER  '
    || '     LEFT OUTER JOIN NCLASEP CP ON CP.CODCLASEP = P.CODCLASA '
    || '     LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = C.CODLOCATIE '
    || '     LEFT OUTER JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT '
    || '     LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = coalesce(C.MONEDA, 0) '
    || '     LEFT OUTER JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = C.SUBUNITATEA '
    || '     LEFT OUTER JOIN NPERS PER ON PER.CODPERS = C.AGENT '
    || '     LEFT OUTER JOIN NPARTTR D ON D.CODPARTTR = C.DELEGAT '
    || '  WHERE '
    || '     coalesce(C.DISPLIVRARE,0) = 0 '
    || '      AND C.TIPDOC =  18 '
    || '      AND C.PARTENER = '
    || coalesce ( (aCODPART) ::varchar::varchar ,'')
    || '      AND c.SUBUNITATEA =PKG_GLOBALS_GETSUBUNITATE '
    || '  ) '
    || ') '
    || ' WHERE '
    || ' 1 = 1 '
    || coalesce (To_Char (FILTRU_DATA1,'dd.mm.yyyy') ,'')
    || coalesce (To_Char (FILTRU_DATA2,'dd.mm.yyyy') ,'')
    || coalesce (FILTRU_SEDIU,'')
    || coalesce (FILTRU_OBS,'')
    || coalesce (FILTRU_STARE,'')
    || coalesce (FILTRU_NRDOC::varchar ,'')
    || coalesce (FILTRU_FACTURABIL,'')
    || ' ORDER BY DATADOC';
    OPEN COMANDACURSOR for execute S;
    WME_Result := COMANDACURSOR;
    RETURN;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_comenzi_client_interval_4php</obj_name>
  <obj_hashval>0f6608e4385d40634d358b7411b8d8f0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_comenzi_client_interval_4php(refcursor, numeric, character varying, character varying, character varying, character varying, character varying, character varying, character varying, character varying)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
  DECLARE
    S varchar;
    COMANDACURSOR REFCURSOR;
    FILTRU_DATA1      varchar := '';
    FILTRU_DATA2      varchar := '';
    FILTRU_SEDIU      varchar := '';
    FILTRU_OBS        varchar := '';
    FILTRU_STARE      varchar := '';
    FILTRU_NRDOC      varchar := '';
    FILTRU_FACTURABIL varchar := '';
  FILTRU_NRI varchar := '';
  begin
    IF COALESCE ($3, '?') not in ('?', '') THEN
      FILTRU_DATA1 := ' AND DATADOC &gt;= TO_DATE('''
      || $3
      || ''',''DD-MM-YYYY'') ';
    END IF;
    IF COALESCE ($4, '?') not in ('?', '') THEN
      FILTRU_DATA2 := ' AND DATADOC &lt;= TO_DATE('''
      || $4
      || ''',''DD-MM-YYYY'') ';
    END IF;
    IF COALESCE ($5, '?') not in ('?', '') THEN
      FILTRU_SEDIU := coalesce (' AND UPPER(SEDIULIVRARE) LIKE '
      || '''%','')
      || coalesce (UPPER ($5) ,'')
      || '%''';
    END IF;
    IF COALESCE ($6, '?') not in ('?', '') THEN
      FILTRU_OBS := coalesce (' AND UPPER(OBS) LIKE '
      || '''%','')
      || coalesce (UPPER ($6) ,'')
      || '%''';
    END IF;
    IF COALESCE ($7, '?') not in ('?', '') THEN
      FILTRU_STARE := coalesce (' AND UPPER(STARECOMANDA) LIKE '
      || '''%','')
      || coalesce (UPPER ($7) ,'')
      || '%''';
      IF UPPER($7) = 'FIC' THEN
    FILTRU_STARE := ' AND ( UPPER(STARECOMANDA) = ''NEFACTURATA'' OR UPPER(STARECOMANDA) = ''FACTURATA PARTIAL'' ) ';
    END IF;
    IF UPPER($7) = 'ANULATA' THEN
    FILTRU_STARE := ' AND ANULAT = 1 ';
    END IF;
    IF UPPER($7) = 'INCHISA' THEN
    FILTRU_STARE := ' AND INCHISA = 1 ';
    END IF;
    IF UPPER($7) = 'TOATE' THEN
    FILTRU_STARE := '';
    END IF;
    END IF;
    IF COALESCE ($8, '?') not in ('?', '') THEN
      FILTRU_NRDOC := coalesce (' AND UPPER(NRDOC::varchar) LIKE '
      || '''%','')
      || coalesce (UPPER ($8) ::varchar ,'')
      || '%''';
    END IF;
    IF COALESCE ($9, '?') not in ('?', '') THEN
      FILTRU_FACTURABIL := ' AND FACTURABIL = ' || $9 || ' ';
    END IF;
  IF COALESCE ($10, '?') not in ('?', '') THEN
      FILTRU_NRI := coalesce (' AND UPPER(NRI::varchar) LIKE '
      || '''%','')
      || coalesce (UPPER ($10) ::varchar ,'')
      || '%''';
    END IF;
    S := coalesce ('SELECT * FROM '
    || '(SELECT ','')
    || '   CODCOMANDA, '
    || '   TIPDOC, '
    || '   ANULAT, '
    || '   BLOCAT, '
    || '   OPERAT, '
    || '   PREFIXDOC, '
    || '   INCHISA, '
    || '   NRDOC, '
    || '   DATADOC, '
    || '   NUMEAGENT, '
    || '   DEN_LOCALIT, '
    || '   to_char(DATACREARE, ''dd.mm.yyyy hh24:mi'') DATACREARE, '
    || '   VERIFICAT, '
    || '   FACTURABIL, '
    || '   NRI,  '
    || '   SERIADOC, '
    || '   PARTENER,'
    || '   VALOARE, '
    || '   AN, '
    || '   LUNA,  '
    || '   OBS, '
    || '   MONEDA, '
    || '   DEN_MONEDA, '
    || '   DEN_PART, '
    || '   SIMBOL, '
    || '   SUBUNITATEDOC, '
    || '   SEDIULIVRARE, '
    || '   DELEGAT, '
    || '    (  '
    || '   CASE '
    || '     WHEN ANULAT = 1 THEN ''ANULATA'' '
  || '     WHEN INCHISA = 1 THEN ''INCHISA'' '
    || '     WHEN FARAFACTURA = 1 THEN ''FARA FACTURARE'' '
    || '     WHEN CANTACCEPTAT = 0 THEN ''NECONFIRMATA'' '
    || '     WHEN CANTACCEPTAT =  RESTACCEPTAT THEN ''NEFACTURATA''  '
    || '     WHEN CANTACCEPTAT &lt;&gt; 0 AND CU_REST = 0 THEN ''FACTURATA INTEGRAL''  '
    || '     WHEN CANTACCEPTAT &gt; RESTACCEPTAT  THEN ''FACTURATA PARTIAL'' '
    || '     ELSE '''' '
    || '   END '
    || '    ) AS STARECOMANDA  '
    || '   FROM  '
    || '   ( '
    || '  SELECT '
    || '    c.CODCOMANDA, c.TIPDOC, c.ANULAT, c.BLOCAT, c.OPERAT, c.PREFIXDOC, c.NRDOC, C.INCHISA, C.DATACREARE, C.VERIFICAT, C.FACTURABIL, coalesce(C.FARAFACTURA, 0) FARAFACTURA, C.NRI, C.LISTAT, C.SERIADOC,  '
    || '    c.DATADOC, c.PARTENER, c.VALOARE, c.AN, c.LUNA, PER.NUME || '' '' || PER.PRENUME AS NUMEAGENT, L.DEN_LOCALIT,  '
    || '    (SELECT ( case when COUNT(*) = 0 then 0 else 1 end) FROM DOCUMENTE D WHERE D.TIPDOC = C.TIPDOC AND D.CODDOC = C.CODCOMANDA) AS ATASAMENT,  '
    || '    c.OBS, c.MONEDA, c.CODCONTRACT, c.CODCMDPARINTE, p.Den_Part,  M.SIMBOL, M.DEN_MONEDA, SUB.DEN_SUBUNIT AS SUBUNITATEDOC,  A.OBS AS SEDIULIVRARE, D.DELEGAT, '
    || '    (SELECT coalesce(SUM(CANTACCEPTAT), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) AS CANTACCEPTAT, '
    || '    (SELECT coalesce(SUM(RESTACCEPTAT), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) AS RESTACCEPTAT, '
    || '    (SELECT coalesce(COUNT(*), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA AND coalesce(CANTACCEPTAT, 0) &gt; 0 AND coalesce(RESTACCEPTAT, 0) &gt; 0) AS CU_REST '
    || '  FROM  '
    || '     COMANDA c LEFT OUTER JOIN NPART P ON P.CODPART = C.PARTENER  '
    || '     LEFT OUTER JOIN NCLASEP CP ON CP.CODCLASEP = P.CODCLASA '
    || '     LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = C.CODLOCATIE '
    || '     LEFT OUTER JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT '
    || '     LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = coalesce(C.MONEDA, 0) '
    || '     LEFT OUTER JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = C.SUBUNITATEA '
    || '     LEFT OUTER JOIN NPERS PER ON PER.CODPERS = C.AGENT '
    || '     LEFT OUTER JOIN NPARTTR D ON D.CODPARTTR = C.DELEGAT '
    || '  WHERE '
    || '     coalesce(C.DISPLIVRARE,0) = 0 '
    || '      AND C.TIPDOC =  18 '
    || '      AND C.PARTENER = '
    || coalesce ( ($2) ::varchar::varchar ,'')
    || '      AND c.SUBUNITATEA = ' || (current_setting('PKG_GLOBALS.SUBUNITATE', True))::numeric
    || '  ) sq '
    || ') sq1 '
    || ' WHERE '
    || ' 1 = 1 '
  || coalesce (FILTRU_DATA1,'')
  || coalesce (FILTRU_DATA2,'')
    || coalesce (FILTRU_SEDIU,'')
    || coalesce (FILTRU_OBS,'')
    || coalesce (FILTRU_STARE,'')
    || coalesce (FILTRU_NRDOC::varchar ,'')
    || coalesce (FILTRU_FACTURABIL,'')
  || coalesce (FILTRU_NRI::varchar ,'')
    || ' ORDER BY DATADOC';
    OPEN $1 FOR EXECUTE S;
    return next $1;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_oferte_agent_si_fara_agent</obj_name>
  <obj_hashval>f3225eca8ee573379c006e296a8f94d9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_oferte_agent_si_fara_agent(INOUT wme_result refcursor, INOUT acodpers numeric, INOUT adenpart character varying, INOUT adataref character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
  DECLARE
    S varchar;
    OFERTACURSOR REFCURSOR;
    FILTRU_PART varchar := '';
    FILTRU_NRDOC VARCHAR(500) := '';
    FILTRU_DATASTART VARCHAR(500) := '';
    FILTRU_DATAEND VARCHAR(500) := '';
    FILTRU_OBS VARCHAR(500) := '';
  begin
    IF COALESCE (aDENPART, '?') &lt;&gt; '?' THEN
      FILTRU_PART := coalesce (' AND (UPPER(DEN_PART) LIKE '
      || '''%','')
      || coalesce (UPPER (aDENPART) ,'')
      || '%'' OR coalesce(PARTENER, 0) = 0)';
    END IF;

  IF NVL(aDATASTART, '?') &lt;&gt; '?' THEN
    FILTRU_DATASTART := ' AND DATASTART = TO_DATE(''' || aDATASTART || ''',''DD-MM-YYYY'') ';
  END IF;
  IF NVL(aDATAEND, '?') &lt;&gt; '?' THEN
    FILTRU_DATAEND := ' AND DATAEND = TO_DATE(''' || aDATAEND || ''',''DD-MM-YYYY'') ';
  END IF;
  IF NVL(aNRDOC, '?') &lt;&gt; '?' THEN
    FILTRU_NRDOC := ' AND UPPER(NRDOC) LIKE ' || '''%' || UPPER(aNRDOC) || '%''';
  END IF;
  IF NVL(aOBS, '?') &lt;&gt; '?' THEN
    FILTRU_OBS := ' AND UPPER(OBS) LIKE ' || '''%' || UPPER(aOBS) || '%''';
  END IF;

    S := '
        SELECT *
        FROM (   SELECT OFE.*
            FROM (   SELECT CODOFERTA, TIPDOC, ANULAT, BLOCAT,
                  OPERAT, SERIE, NRDOC, DATASTART,
                  DATAEND, PARTENER, AN, LUNA,
                  OBS, MONEDA, CODLOCATIE, SUBUNITATEA,
                  CODFISCAL, USERID, DATACREARE, DATAOFERTA,
                  PE_CLASA, DEN_PART, DEN_MONEDA, DEN_LOCALIT,
                  SUBUNITATEDOC, SEDIU, NUMEAGENT, PCNume,
                  PCTel, PCEmail, Aprobari, NRI,
                  Utilizator, Valoare
                FROM (   SELECT O.CODOFERTA, O.TIPDOC, O.ANULAT, O.BLOCAT,
                      O.OPERAT, C.SERIE, O.NRDOC, O.DATASTART,
                      O.DATAEND, O.PARTENER, O.AN, O.LUNA,
                      O.OBS, O.MONEDA, O.CODLOCATIE, O.SUBUNITATEA,
                      O.CODFISCAL, O.USERID, O.DATACREARE, O.DATAOFERTA,
                      (case when O.TipBeneficiar = 1 then ''DA'' else ''NU'' end) PE_CLASA,
                      Coalesce (P.Den_Part, CP.Den_Clasep, ''...'') Den_Part, M.Den_Moneda, L.Den_Localit,
                      S.DEN_SUBUNIT       SUBUNITATEDOC, SED.OBS SEDIU,
                      (case when A.CodPers = 0 then A.Nume else A.NUME ||'' '' ||A.PRENUME end) NUMEAGENT, O.NRI, PC.Nume
                        ||'' ''
                        ||PC.Prenume PCNume, PC.TELEFON PCTel, PC.EMAIL PCEmail, UT.UserName Utilizator, (   SELECT Sum (coalesce (O1.CANTMIN * O1.PRET * Coalesce (1 + O1.PROCADAOS / 100,1) * Coalesce (1 + O1.ProcDiscount / 100,1) ,0))
                        FROM OFERTA1 O1
                        WHERE
                          O1.CodOferta = O.CodOferta) Valoare, '' '' AS Aprobari
                    FROM OFERTA                             O
                      LEFT JOIN NPART                     P   ON coalesce (O.Partener, 0) = P.Codpart AND coalesce (TipBeneficiar, 0) = 0
                      LEFT JOIN NCLASEP                   CP  ON coalesce (O.CodClaseP, 0) = CP.CodClaseP AND coalesce (TipBeneficiar, 0) = 1
                      LEFT JOIN NAGENDA                   SED ON SED.Codagenda = O.CodLocatie
                      LEFT JOIN NLOCALIT                  L   ON L.Codlocalit = SED.CodLocalit
                      LEFT JOIN NMONEDE                   M   ON M.CodMoneda = O.Moneda
                      LEFT JOIN NSUBUNIT                  S   ON S.CODSUBUNIT = O.SUBUNITATEA
                      LEFT JOIN NPERS                     A   ON A.CODPERS = coalesce (O.AGENT,0)
                      LEFT JOIN NPERSCONTACT              PC  ON PC.CodPart = P.CodPart AND PC.CodPersC = O.CodPersC
                      LEFT JOIN DOCCARNETE                C   ON C.CODCARNET = O.CARNETDOC
                      LEFT JOIN TMP_UTILIZATOR            UT  ON UT.CODUTILIZATOR = O.USERID
                    WHERE
                      O.TipDoc = 50
                      AND O.OFERTAT = 1
                      AND (O.AGENT = '
            || coalesce ( (aCODPERS) ::varchar::varchar ,'')
            || '
                        OR coalesce (O.AGENT, 0) = 0)
                      AND DATASTART &lt;= TO_DATE ('''
            || coalesce (To_Char (aDATAREF,'dd.mm.yyyy') ,'')
            || ''',''DD - MM - YYYY'')
                      AND DATAEND &gt;= TO_DATE ('''
            || coalesce (To_Char (aDATAREF,'dd.mm.yyyy') ,'')
            || ''',''DD   - MM - YYYY'')
                      AND (coalesce (O.ToateSubunit,0) = 1
                        or O.SUBUNITATEA = PKG_GLOBALS_GETSUBUNITATE))) OFE)
        WHERE
          1 = 1'||
          COALESCE(Filtru_Part, '') || COALESCE(FILTRU_NRDOC, '') || COALESCE(FILTRU_DATASTART, '') || COALESCE(FILTRU_DATAEND, '') || COALESCE(FILTRU_OBS, '');

    OPEN OFERTACURSOR for execute S;
    WME_Result := OFERTACURSOR;
    RETURN;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_getstocuri</obj_name>
  <obj_hashval>473ffe51b5bc9acdf359ef8801ec6a5b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_getstocuri(INOUT wme_result refcursor, INOUT acodpart numeric, INOUT adenobiect character varying, INOUT adenclasa character varying, INOUT acodgest numeric, INOUT acodextern character varying, INOUT acodintern character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
  DECLARE
    STOCCURSOR REFCURSOR;
    FILTRU_ART   varchar := '';
      FILTRU_CLASA varchar := '';
    FILTRU_GEST  varchar := '';
     FILTRU_CODEXTERN   varchar := '';
      FILTRU_CODINTERN   varchar := '';
      S           varchar;
      AN           numeric(5);
      LUNA         numeric(2);
      aCODCATPRET  numeric := 0;
  begin
    AN   := EXTRACT(YEAR FROM current_date);
    LUNA := EXTRACT(MONTH FROM current_date);
    perform pkg_globals_setlunalucru_simpla(AN, Luna);
    perform pkg_stoc_generare_facturi_make_config_luna_ext();
    BEGIN
      SELECT coalesce(CODCATEGPRET, 0) into strict aCODCATPRET FROM NPART WHERE CODPART = aCODPART;
      EXCEPTION WHEN OTHERS THEN aCODCATPRET := 0;
    END;

    S := ' SELECT * FROM ' ||
         ' ( ' ||
         '    SELECT ' ||
         '      1 AS TIPARTICOL, ' ||
         '      O.DENUMIRE AS DENOBIECT, ' ||
         '      O.CODEXTERN, ' ||
         '      O.CODINTERN,' ||
       '      O.CODARTICOL,' ||
       '      O.INACTIV, ' ||
         '      A.DEN_ARTICOL AS DEN_ART,' ||
         '      A.UM1 AS DUM1,' ||
         '      A.COMENZIONLINE,' ||
         '      U0.DEN_UM1 AS DENUM1,' ||
         '      NULL as DEN_GEST, ' ||
         '      O.CODOBIECT, ' ||
         '      0 as CODGEST, ' ||
         '      CASE ' ||
         '        WHEN CAT.TIP = 1 THEN ROUND(coalesce(PM.LEI, 0) / (1 + coalesce(TVAL.PROCENT, 0) / 100), 2) ' ||
         '        ELSE coalesce(PM.LEI, 0) ' ||
         '      END  AS PRET, ' ||
         '      0 AS STOC, ' ||
         '      P.DEN_PART AS PRODUCATOR, ' ||
         '      CLAS.DEN_CLASEA AS CLASA, ' ||
         '      U.DEN_UM, ' ||
         '      U1.CODUM1 ' ||
         '    FROM  ' ||
         '      NART A   ' ||
       '      LEFT OUTER JOIN NUM1 U0 ON U0.CODUM1 = A.UM1 ' ||
         '      LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = A.CODARTICOL  ' ||
         '      LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA = NAL.CODTVA ' ||
         '      LEFT OUTER JOIN NUM U ON U.CODUM = A.UM ' ||
         '      LEFT OUTER JOIN NUM1 U1 ON U1.CODUM = U.CODUM AND U1.SECUNDARA = 0' ||
         '      LEFT OUTER JOIN NCLASEA CLAS ON CLAS.CODCLASEA = CLASA, ' ||
         '      NARTOBJ O ' ||
         '      LEFT OUTER JOIN PRETM PM ON PM.CODOBIECT = O.CODOBIECT AND PM.SUBUNITATEA = ' || coalesce(getsubunitate(), 0)::varchar ||
         '      AND CODCATPRET = ' ||aCODCATPRET::varchar ||
         '      LEFT JOIN NCATPRET CAT ON CAT.CODCATPRET = PM.CODCATPRET ' ||
         '      LEFT OUTER JOIN NPART P ON P.CODPART = O.CODPRODUCATOR ' ||
         '    WHERE O.CODARTICOL = A.CODARTICOL AND A.TIPARTICOL = 1 AND coalesce(A.COMENZIONLINE, 0) = 1 ' ||
         ' UNION ALL ' ||
         ' SELECT ' ||
         '    0 AS TIPARTICOL, ' ||
         '    O.DENUMIRE AS DENOBIECT, ' ||
         '    O.CODEXTERN,' ||
         '    O.CODINTERN, ' ||
       '    O.CODARTICOL,' ||
       '      O.INACTIV, ' ||
         '    A.DEN_ARTICOL AS DEN_ART,' ||
         '    A.UM1 AS DUM1,' ||
         '      A.COMENZIONLINE,' ||
         '    U0.DEN_UM1 AS DENUM1,' ||
         '    G.DEN_GEST, ' ||
         '    STOCVIEW.CODOBIECT, ' ||
         '    STOCVIEW.CODGEST,' ||
         '    CASE ' ||
         '      WHEN CAT.TIP = 1 THEN ROUND(coalesce(PM.LEI, 0) / (1 + coalesce(TVAL.PROCENT, 0) / 100), 2) ' ||
         '      ELSE coalesce(PM.LEI, 0) ' ||
         '    END  AS PRET, ' ||
         '    STOCVIEW.STOC, ' ||
         '    P.DEN_PART AS PRODUCATOR, ' ||
         '    CLAS.DEN_CLASEA AS CLASA, ' ||
         '    U.DEN_UM, ' ||
         '    U1.CODUM1 ' ||
         ' FROM ' ||
         '    ( ' ||  -- stoc cumulat
         '     SELECT CODOBIECT, CODGEST, SUM(STOC) AS STOC ' ||
         '     FROM ' ||
         '         ( ' ||
         '           SELECT  CODOBIECT, CODGEST, STOC FROM ' ||
         '                (  ' ||
         '                   SELECT ' ||
         '                      NS.CODOBIECT, ' ||
         '                      N.GEST AS CODGEST,' ||
         '                      SUM(NS.REST - coalesce((SELECT SUM(REST) FROM REZERVATS R WHERE R.CODNIRSTOC = NS.CODNIRSTOC), 0)) AS STOC ' ||
         '                   FROM ' ||
         '                      NIRSTOC NS  ' ||
         '                      LEFT OUTER JOIN TMP_IOART_LUNA IOAL ON IOAL.CODIOART = NS.CODIOART, ' ||
         '                      NIR     N ' ||
         '                   WHERE ' ||
         '                      NS.REST &gt; 0 ' ||
         '                      AND N.CODNIR = NS.CODNIR ' ||
         '                      AND (((SELECT COUNT(*) FROM TMP_GESTDEDICATE) = 0) OR (EXISTS (SELECT CODGEST FROM TMP_GESTDEDICATE WHERE CODGEST = N.GEST))) ' ||
         '                      AND IOAL.MG &lt;&gt; 3 AND IOAL.MG &lt;&gt; 5  ' ||
         '                      AND coalesce(IOAL.ESTEMIFIX, 0) = 0    ' ||
         '                      AND coalesce(IOAL.ESTEOBINV, 0) = 0    ' ||
         '                   GROUP BY ' ||
         '                      NS.CODOBIECT, ' ||
         '                      N.GEST ' ||
         '                ) ' ||
         '           WHERE STOC &gt;= 0 ' ||
         '         ) ' ||
         '     GROUP BY CODOBIECT, CODGEST ' ||
         '    ) STOCVIEW,  ' ||
         '    NARTOBJ O ' ||
         '    LEFT OUTER JOIN PRETM PM ON PM.CODOBIECT = O.CODOBIECT AND PM.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE AND CODCATPRET = ' || aCODCATPRET::varchar ||
         '    LEFT JOIN NCATPRET CAT ON CAT.CODCATPRET = PM.CODCATPRET ' ||
         '    LEFT OUTER JOIN NART A ON A.CODARTICOL = O.CODARTICOL  ' ||
      '      LEFT OUTER JOIN NUM1 U0 ON U0.CODUM1 = A.UM1 ' ||
         '    LEFT OUTER JOIN NUM U ON U.CODUM = A.UM ' ||
         '    LEFT OUTER JOIN NUM1 U1 ON U1.CODUM = U.CODUM AND U1.SECUNDARA = 0' ||
         '    LEFT OUTER JOIN NCLASEA CLAS ON CLAS.CODCLASEA = CLASA  ' ||
         '    LEFT OUTER JOIN NPART P ON P.CODPART = O.CODPRODUCATOR ' ||
         '    LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = A.CODARTICOL  ' ||
         '    LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA = NAL.CODTVA, ' ||
         '    NGEST G ' ||
         '  WHERE ' ||
         '    G.CODGEST = STOCVIEW.CODGEST ' ||
         '    AND G.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE ' ||
         '    AND O.CODOBIECT = STOCVIEW.CODOBIECT ' ||
         ' ) ' ||
         '  WHERE 1=1';

    IF coalesce(aDENOBIECT, '?') &lt;&gt; '?' THEN
      FILTRU_ART := ' AND UPPER(DENOBIECT) LIKE ' || '''%' || UPPER(aDENOBIECT) || '%''';
    END IF;

    IF coalesce(aCODEXTERN, '?') &lt;&gt; '?' THEN
      FILTRU_CODEXTERN := ' AND UPPER(CODEXTERN) LIKE ' || '''%' || UPPER(aCODEXTERN) || '%''';
    END IF;


    IF coalesce(aCODINTERN, '?') &lt;&gt; '?' THEN
      FILTRU_CODINTERN := ' AND UPPER(CODINTERN) LIKE ' || '''%' || UPPER(aCODINTERN) || '%''';
    END IF;


    IF coalesce(aDENCLASA, '?') &lt;&gt; '?' THEN
      FILTRU_CLASA := ' AND UPPER(CLASA) LIKE ' || '''%' || UPPER(aDENCLASA) || '%''';
    END IF;

    IF coalesce(aCODGEST, 0) &lt;&gt; 0 THEN
      FILTRU_GEST := ' AND CODGEST = ' || TO_CHAR(aCODGEST);
    END IF;

    OPEN STOCCURSOR FOR execute S || FILTRU_ART || ' ' || FILTRU_CLASA || ' ' || FILTRU_GEST || FILTRU_CODEXTERN || ' ' || FILTRU_CODINTERN || ' ORDER BY DENOBIECT ';
  WME_Result := STOCCURSOR;
    RETURN;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>safe_to_date</obj_name>
  <obj_hashval>7753518ffb42bcda9837b93da0801cec</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION safe_to_date(p_val text, p_format text DEFAULT 'DD.MM.YYYY'::text)
 RETURNS date
 LANGUAGE plpgsql
 IMMUTABLE
AS $function$
DECLARE
    l_date DATE;
BEGIN
    l_date := to_date(p_val, p_format);
    RETURN l_date;
EXCEPTION
    WHEN others THEN
        RETURN NULL;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>safe_to_number</obj_name>
  <obj_hashval>6668b1f51488d3c5fa8e6fb2396b6940</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION safe_to_number(p_val text)
 RETURNS numeric
 LANGUAGE plpgsql
 IMMUTABLE
AS $function$
DECLARE
    l_num NUMERIC;
BEGIN
    l_num := p_val::NUMERIC;
    RETURN l_num;
EXCEPTION
    WHEN others THEN
        RETURN NULL;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>sp_cleartable</obj_name>
  <obj_hashval>5188304b9d8cabd59f962220f1c22c3e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION sp_cleartable(tablename text)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  BEGIN
    EXECUTE 'delete FROM ' || TableName ||';';
  END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>PROCEDURE</obj_type>
  <obj_name>test_procedure</obj_name>
  <obj_hashval>c50ff5f3764b3ae074aac8a5450d3362</obj_hashval>
  <obj_text>CREATE OR REPLACE PROCEDURE test_procedure(IN operation numeric, INOUT recid numeric)
 LANGUAGE plpgsql
AS $procedure$
begin
  recid := operation + 100;
end;
$procedure$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_list_stoc</obj_name>
  <obj_hashval>8ba4a60e87269f88d3181bd9dc0a490a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_list_stoc()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
begin
  --Adina aug.2020
  return
  'SELECT
      NS.CODNIRSTOC, NS.UMSEC, NS.CODOBIECT, NS.CODIOART, N.GEST,
      ROUND((NS.PRET - coalesce(NS.ADAOS, 0)),10) PRETACHIZ, ROUND(NS.PRET, 10) PRET, NS.ADAOS, NS.TVA, NS.TIPSERIE,
      ROUND(V.REST,10) REST, ROUND(V.REST,10) STOC, 0.0 PRELUAT, NS.PROCENTADAOS, NS.DATAACHIZ INTRATLA, NS.TG, NS.PUMAXIMAL, NS.FURN CODPART,
      N.CODNIR CODNIR, NS.CODINTR1 CODINTR1, N.CODINTR CODINTR,
      0 FLAG, NS.CODTRANSF1, NS.DATAACHIZ, NS.TIPDOCACHIZ, N.TIPNIR TIPINTRARESTOC, L.DENUMIRE LOCATIE,
      V.RESTUM1, V.RESTUM1 STOCUM1, 0.0 PRELUATUM1, V.RESTUM2, V.RESTUM2 STOCUM2, 0.0 PRELUATUM2,
      NS.CODGESTPROD, NS.SUBUNITATEA,
      CASE
        WHEN NS.TIPDOCACHIZ = 7 THEN (SELECT DEN_GEST FROM NGEST WHERE CODGEST = NS.CODGESTPROD)
        ELSE (SELECT DEN_PART FROM NPART WHERE CODPART = NS.FURN)
      END FURNIZOR,
      NS.FURN CODFURNIZOR, NS.CODLOCATIE, NS.CODDVI1, T.CODTRANSF, N.TIPNIR, N.CODIES,
      CASE
        WHEN COALESCE(I.AN,T.AN,IES.AN) * 12 + COALESCE(I.LUNA,T.LUNA,IES.LUNA) &lt; (FL.ANINITIAL * 12 + FL.LUNAINITIALA)
        THEN FL.ANINITIAL
        ELSE COALESCE(I.AN,T.AN,IES.AN)
      END AN,
      CASE
        WHEN COALESCE(I.AN,T.AN,IES.AN) * 12 + COALESCE(I.LUNA,T.LUNA,IES.LUNA) &lt; (FL.ANINITIAL * 12 + FL.LUNAINITIALA)
        THEN FL.LUNAINITIALA
        ELSE COALESCE(I.LUNA,T.LUNA,IES.LUNA)
      END LUNA,
      CASE
        WHEN COALESCE(I.AN,T.AN,IES.AN) * 12 + COALESCE(I.LUNA,T.LUNA,IES.LUNA) &lt; (FL.ANINITIAL * 12 + FL.LUNAINITIALA)
        THEN 1
        ELSE 0
      END INITIALIZARI,
      NS.D1, NS.D2, NS.D3,NS.PUVAL,NS.PROVIZION
   FROM ('||v_stoc_luna() ||') v
      INNER JOIN nirstoc ns ON v.CODNIRSTOC = NS.CODNIRSTOC
      INNER JOIN NIR N      ON N.CODNIR     = NS.CODNIR
      LEFT  JOIN NGEST G    ON G.CODGEST    = N.GEST
      LEFT  JOIN INTRARI I  ON I.CODINTR    = N.CODINTR   AND I.TIPDOC   = N.TIPNIR
      LEFT  JOIN IESIRI IES ON IES.CODIES   = N.CODIES    AND IES.TIPDOC = N.TIPNIR
      LEFT  JOIN NLOCATII L ON L.CODLOCATIE = NS.CODLOCATIE
      LEFT  JOIN TRANSF T   ON T.CODTRANSF  = N.CODTRANSF AND T.TIPDOC   = N.TIPNIR
      CROSS JOIN FIRMALUNI FL
   WHERE v.REST &lt;&gt; 0
     AND ((Select wme_result From pkg_list_selfisamag_getNumToateGest(null,null)) = 1 OR N.GEST::varchar IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = ''CODGEST''))
    ';
end;

$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_pmp_iesiri_doc</obj_name>
  <obj_hashval>50495f22b42a03997692bb05b38c64fa</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_pmp_iesiri_doc()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 24.11.2025 - fixat 67397
  --Stef   26.09.2025
  --Florin 10.01.2021 - fixat 52544
  RETURN
  'SELECT CODOBIECT, CODSUBUNIT, SUM(RESTLUNA) AS RESTLUNA, SUM(VALRESTLUNA) AS VALRESTLUNA, SUM(VALRESTLUNAV) AS VALRESTLUNAV
  FROM (
    SELECT CODOBIECT, CODSUBUNIT, RESTLUNA, VALRESTLUNA, VALRESTLUNAV, AN, LUNA
      FROM (
        SELECT
          NS.CODOBIECT, G.CODSUBUNIT,
          CASE WHEN (E.CODIES IS NOT NULL)and(E.TIPDOC = 15) THEN L1.CANT                 ELSE -L1.CANT                 END AS RESTLUNA,
          CASE WHEN (E.CODIES IS NOT NULL)and(E.TIPDOC = 15) THEN L1.CANT*L1.PMPDOC       ELSE -L1.CANT*L1.PMPDOC       END AS VALRESTLUNA,
          CASE WHEN (E.CODIES IS NOT NULL)and(E.TIPDOC = 15) THEN L1.CANT*L1.PMPVALUTADOC ELSE -L1.CANT*L1.PMPVALUTADOC END AS VALRESTLUNAV,
          CASE WHEN I.CODINTR IS NOT NULL THEN I.AN   WHEN E.CODIES IS NOT NULL THEN E.AN   ELSE T.AN   END AS AN,
          CASE WHEN I.CODINTR IS NOT NULL THEN I.LUNA WHEN E.CODIES IS NOT NULL THEN E.LUNA ELSE T.LUNA END AS LUNA
        FROM LIVR L
          INNER JOIN LIVR1          L1 ON L1.CODLIVR    = L.CODLIVR
          INNER JOIN NIRSTOC        NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
          INNER JOIN TMP_IOART_LUNA IO ON IO.CODIOART   = NS.CODIOART
          INNER JOIN NIR            N  ON N.CODNIR      = NS.CODNIR
          INNER JOIN NGEST          G  ON G.CODGEST     = N.GEST
          LEFT  JOIN IESIRI         E  ON E.CODIES      = L.CODIES    AND E.TIPDOC = L.TIPLIVR AND E.CodIes    &lt;&gt; (select wme_result from PKG_GLOBALS_GetPMPCodIes(null, null))
          LEFT  JOIN INTRARI        I  ON I.CODINTR     = L.CODINTR   AND I.TIPDOC = L.TIPLIVR AND I.Codintr   &lt;&gt; (select wme_result from PKG_GLOBALS_GetPMPCodIntr(null, null))
          LEFT  JOIN TRANSF         T  ON T.CODTRANSF   = L.CODTRANSF AND T.TIPDOC = L.TIPLIVR AND T.CODTRANSF &lt;&gt; (select wme_result from PKG_GLOBALS_GetPMPCodTransf(null, null))
        WHERE L.OPERAT = 1 AND L.ANULAT = 0
          AND IO.MG = 3
      ) ssub1
      WHERE AN = current_setting(''PKG_GLOBALS.ANTEMP'', true)::numeric AND LUNA = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric
    ) ssub2
    GROUP BY CODOBIECT, CODSUBUNIT';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_soldpart</obj_name>
  <obj_hashval>3f03d0eaf36e3dfe9d205324d41a0fac</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_soldpart()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
begin
  --Adina 26.04.2021
  return
  ' SELECT CODPART, ICONT, CODMONEDA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
    FROM
        (
         SELECT CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA FROM ( '||V_SOLDPART_TRANZACTII()||' ) V1
         UNION ALL
         SELECT CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA FROM ( '||V_SOLDPARTPREC_EXT()||' ) V2
        ) JJ_PG
    GROUP BY CODPART, ICONT, CODMONEDA
  ';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_bi_stoc_moment</obj_name>
  <obj_hashval>0fced3b398936c024e4a38f9e253b798</obj_hashval>
  <obj_text>SELECT ns.codnirstoc,
    ns.umsec,
    ns.codobiect,
    ns.codioart,
    nircurent.gest,
    round(ns.pret - COALESCE(ns.adaos, 0::numeric), 10) AS pretachiz,
    round(ns.pret, 10) AS pret,
    ns.adaos,
    ns.tva,
    ns.tipserie,
        CASE
            WHEN ns.tipserie &gt; 0::numeric THEN round(nse.rest, 10)
            ELSE round(ns.rest, 10)
        END AS stoc,
    0.0 AS preluat,
    ns.procentadaos,
    nircurent.datanir AS intratla,
    ns.tg,
    ns.pumaximal,
    ns.furn AS codpart,
        CASE
            WHEN ns.tipserie &gt; 0::numeric THEN ( SELECT nserii.serie
               FROM martor.nserii
              WHERE nserii.codserie = nse.codserie)
            ELSE ''::character varying
        END AS serie,
    COALESCE(nse.codnirser, 0::numeric) AS codnirser,
    nse.codserie,
    0 AS codnir,
    0 AS codintr1,
    0 AS codintr,
    0 AS flag,
    ns.codtransf1,
    ns.dataachiz,
    ns.tipdocachiz,
    nircurent.tipnir AS tipintrarestoc,
    l.denumire AS locatie,
    ns.restum1,
    ns.restum1 AS stocum1,
    0.0 AS preluatum1,
    ns.restum2,
    ns.restum2 AS stocum2,
    0.0 AS preluatum2,
    ns.codgestprod,
    ns.subunitatea,
        CASE
            WHEN ns.tipdocachiz = 7::numeric THEN ( SELECT ngest.den_gest
               FROM martor.ngest
              WHERE ngest.codgest = ns.codgestprod)
            ELSE NULL::character varying
        END AS furnizor,
    ns.codlocatie,
    s.den_subunit
   FROM martor.nirstoc ns
     JOIN martor.nir nircurent ON nircurent.codnir = ns.codnir
     JOIN martor.ngest g ON g.codgest = nircurent.gest
     JOIN martor.nsubunit s ON s.codsubunit = g.codsubunit
     LEFT JOIN martor.nlocatii l ON l.codlocatie = ns.codlocatie
     LEFT JOIN martor.nirser nse ON nse.codnirstoc = ns.codnirstoc,
    ( SELECT io1.codioart,
            io1.mg
           FROM martor.ioart1 io1
          WHERE (io1.anstart * 12::numeric + io1.lunastart) = (( SELECT max(io2.anstart * 12::numeric + io2.lunastart) AS max
                   FROM martor.ioart1 io2
                  WHERE io2.codioart = io1.codioart AND (io2.anstart * 12::numeric + io2.lunastart) &lt;= (( SELECT firmaluni.anmaxim * 12::numeric + firmaluni.lunamaxima
                           FROM martor.firmaluni))))) ioaluna
  WHERE ns.rest &lt;&gt; 0::numeric AND ioaluna.codioart = ns.codioart AND ioaluna.mg &lt;&gt; 5::numeric AND ioaluna.mg &lt;&gt; 3::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_nc</obj_name>
  <obj_hashval>2ee98eb47feed683972bfadecad7237b</obj_hashval>
  <obj_text>SELECT codnc,
    nrdoc,
    datadoc,
    part,
    jurnaltva,
    tiptranz,
    tiptva,
    valoare,
    moneda,
    curs,
    obs,
    an,
    luna,
    subunitatea,
    userid,
    datacreare,
    sablon,
    carnetdoc,
    codanaliza
   FROM martor.nc
  WHERE codnc = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_reclamatii</obj_name>
  <obj_hashval>2c066e3585e666803164aa9024fef12e</obj_hashval>
  <obj_text>SELECT codreclamatie AS coddoc,
    anulat,
    blocat,
    operat,
    tipdoc,
    nrdoc,
    seriadoc,
    datadoc,
    carnetdoc,
    codsubunit,
    codutilizator,
    motiv,
    reclamatie,
    codpart,
    coddocr,
    tipdocr,
    rezolvat,
    datarez,
    codresp,
    imputabila,
    tipimput,
    codpimput
   FROM martor.reclamatii
  WHERE codreclamatie = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_reg</obj_name>
  <obj_hashval>0f9200dc6f3d57dfa259bcb4cddf6a03</obj_hashval>
  <obj_text>SELECT codreg,
    tipreg,
    nrdoc,
    datadoc,
    codbank,
    codmoneda,
    curs,
    dirty,
    obs,
    codsubunit,
    provizion,
    an,
    luna,
    codgest,
    codanaliza,
    codanalizanod,
    codcentru,
    curs_ifrs
   FROM martor.reg
  WHERE codreg = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_locatiipartretail</obj_name>
  <obj_hashval>fafe061dee008c3e3aa608ab9a097198</obj_hashval>
  <obj_text>SELECT a.codsediu,
    a.codpartretail,
    a.denumire,
    a.codlocalit,
    a.denlocalit,
    a.codjudet,
    a.codtara,
    a.telefon,
    a.fax,
    a.email,
    a.strada,
    a.nr1,
    a.nr2,
    a.bloc,
    a.scara,
    a.etaj,
    a.apart,
    a.sector,
    a.codpostal,
    a.sediusocial,
    a.codagenda,
    ( SELECT getadresa.wme_result
           FROM martor.getadresa(NULL::character varying, a.sector, a.strada, a.nr1, a.nr2, a.bloc, a.scara, a.etaj, a.apart, a.codpostal) getadresa(wme_result, p_sector, p_strada, p_nr1, p_nr2, p_bloc, p_scara, p_etaj, p_apart, p_codpostal)) AS adresasediu,
    COALESCE(t.simbauto, 'RO'::character varying) AS tara,
    COALESCE(t.statcomunitar, 0::numeric) AS ue
   FROM martor.nsediipartretail a
     LEFT JOIN martor.ntari t ON t.codtara = a.codtara
  WHERE a.codpartretail = (( SELECT pkg_nompart_get_part_curent_locatii.wme_result
           FROM martor.pkg_nompart_get_part_curent_locatii(NULL::numeric, NULL::numeric) pkg_nompart_get_part_curent_locatii(wme_result, fakeparam))) AND (a.sediusocial::integer &amp; 1) &lt;&gt; 0;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_nartobj</obj_name>
  <obj_hashval>53fe09252b0e4b97b569a91813b787f2</obj_hashval>
  <obj_text>SELECT codarticol,
    codobiect,
    den_articol,
    um,
    clasa,
    tipserie,
    tiparticol,
    aretg,
    contimplicit,
    producator,
    gestimplicita,
    certificat,
    evolutiepret,
    contserviciu,
    um1,
    um2,
    codexternart,
    sufixcodextern,
    culoare,
    codvamal,
    codextern,
    codintern,
    umambalare,
    stocmin,
    stocmax,
    termenplata,
    procadaosnir,
    promotie,
    blocat,
    rotunjire,
    nefacturabil,
    cantaribil,
    codtva,
    codaccize,
    codaccizedvi,
    codtaxa1,
    codtaxa2,
    tippretmax,
    pumaxluna,
    proctva,
    COALESCE(string_agg(denobiect::text, ' '::text ORDER BY indexlocal), '... fara atribute ...'::text)::character varying AS denobiect,
    produspropriu,
    inactiv,
    faracmdfurn,
    relatieum1,
    d1,
    d2,
    d3,
    dci,
    denlocatie,
    denumiretrad,
    den_ioart,
    den_gest,
    min(codatrobj) AS codatrobj,
    farastoc
   FROM ( SELECT a.codarticol,
            o.codobiect,
            a.den_articol,
            a.um,
            a.clasa,
            a.tipserie,
            a.tiparticol,
            a.aretg,
                CASE
                    WHEN COALESCE(oi.contimplicit, 0::numeric) = 0::numeric THEN ai.contimplicit
                    ELSE COALESCE(oi.contimplicit, 0::numeric)
                END AS contimplicit,
            p.den_part AS producator,
                CASE
                    WHEN COALESCE(oi.gestimplicita, 0::numeric) = 0::numeric THEN ai.gestimplicita
                    ELSE COALESCE(oi.gestimplicita, 0::numeric)
                END AS gestimplicita,
            a.certificat,
            a.evolutiepret,
            a.contserviciu,
            a.um1,
            a.um2,
            a.codexternart,
            a.sufixcodextern,
            a.culoare,
            o.codvamal,
            o.codextern,
            o.codintern,
            o.umambalare,
            o.stocmin,
            o.stocmax,
            o.termenplata,
            o.procadaosnir,
            o.promotie,
            o.blocat,
            o.rotvaluta AS rotunjire,
            o.nefacturabil,
            u.tipum AS cantaribil,
            nart1luna.codtva,
            nart1luna.codaccize,
            nart1luna.codaccizedvi,
            nart1luna.codtaxa1,
            nart1luna.codtaxa2,
            nartobj1luna.tippretmax,
            nartobj1luna.pretmaximal AS pumaxluna,
            COALESCE(tvaluna.procent, '-1'::integer::numeric) AS proctva,
            COALESCE(b.valoare, '... fara atribute ...'::character varying) AS denobiect,
            o.produspropriu,
            o.inactiv,
            o.faracmdfurn,
            a.relatieum1,
            a.d1,
            a.d2,
            a.d3,
            a.dci,
            loc.denumire AS denlocatie,
            trad.denumiretrad,
            ioa.den_ioart,
            gi.den_gest,
            COALESCE(t.codobiect, 0::numeric) AS codatrobj,
            COALESCE(t.indexlocal, 0::numeric) AS indexlocal,
            COALESCE(o.farastoc, 0::numeric) AS farastoc
           FROM martor.nartobj o
             JOIN martor.nart a ON o.codarticol = a.codarticol
             JOIN martor.num u ON u.codum = a.um
             LEFT JOIN martor.nartimplicite ai ON ai.codarticol = a.codarticol AND ai.codsubunit = (( SELECT pkg_globals_getsubunitate_doc.wme_result
                   FROM martor.pkg_globals_getsubunitate_doc(NULL::numeric, NULL::numeric) pkg_globals_getsubunitate_doc(wme_result, fakeparam)))
             LEFT JOIN martor.nartobjimp oi ON oi.codobiect = o.codobiect AND oi.codsubunit = martor.getsubunitate_doc()
             LEFT JOIN martor.nlocatii loc ON
                CASE
                    WHEN COALESCE(oi.locatieimplicita, 0::numeric) = 0::numeric THEN ai.locatieimplicita
                    ELSE COALESCE(oi.locatieimplicita, 0::numeric)
                END = loc.codlocatie
             LEFT JOIN martor.npart p ON p.codpart = o.codproducator
             LEFT JOIN martor.natrobj t ON t.codobiect = o.codobiect
             LEFT JOIN martor.natrib1 b ON t.codvalatr = b.codvalatr
             LEFT JOIN martor.nartobjtrad trad ON trad.codobiect = o.codobiect AND trad.codlimba = (( SELECT pkg_globals_getlimbadenart.wme_result
                   FROM martor.pkg_globals_getlimbadenart(NULL::numeric, NULL::numeric) pkg_globals_getlimbadenart(wme_result, fakeparam)))
             LEFT JOIN martor.ioart ioa ON
                CASE
                    WHEN COALESCE(oi.contimplicit, 0::numeric) = 0::numeric THEN ai.contimplicit
                    ELSE COALESCE(oi.contimplicit, 0::numeric)
                END = ioa.codioart
             LEFT JOIN martor.ngest gi ON gi.codgest =
                CASE
                    WHEN COALESCE(oi.gestimplicita, 0::numeric) = 0::numeric THEN ai.gestimplicita
                    ELSE COALESCE(oi.gestimplicita, 0::numeric)
                END
             LEFT JOIN ( SELECT a1.codarticol,
                    a1.codtva,
                    a1.codaccize,
                    a1.codtaxa1,
                    a1.codtaxa2,
                    a1.codaccizedvi
                   FROM martor.nart1 a1
                  WHERE (a1.anstart * 12::numeric + a1.lunastart) = (( SELECT max(a11.anstart * 12::numeric + a11.lunastart) AS max
                           FROM martor.nart1 a11
                          WHERE a11.codarticol = a1.codarticol AND (a11.anstart * 12::numeric + a11.lunastart) &lt;= ((( SELECT pkg_globals_getanlucru.wme_result
                                   FROM martor.pkg_globals_getanlucru(NULL::numeric, NULL::numeric) pkg_globals_getanlucru(wme_result, fakeparam))) * 12::numeric + (( SELECT pkg_globals_getlunalucru.wme_result
                                   FROM martor.pkg_globals_getlunalucru(NULL::numeric, NULL::numeric) pkg_globals_getlunalucru(wme_result, fakeparam))))))) nart1luna ON nart1luna.codarticol = o.codarticol
             LEFT JOIN ( SELECT n.codtva,
                    n1.codtva1,
                    n.den_tva,
                    n1.procent,
                    n1.codcontded,
                    n1.codcontcole,
                    n1.codcontneex
                   FROM martor.ntva n
                     LEFT JOIN martor.ntva1 n1 ON n.codtva = n1.codtva
                  WHERE (n1.anstart * 12::numeric + n1.lunastart) = (( SELECT max(nt1.anstart * 12::numeric + nt1.lunastart) AS max
                           FROM martor.ntva1 nt1
                          WHERE nt1.codtva = n1.codtva AND (nt1.anstart * 12::numeric + nt1.lunastart) &lt;= (( SELECT pkg_globals_anlunalucru.wme_result
                                   FROM martor.pkg_globals_anlunalucru(NULL::numeric, NULL::numeric) pkg_globals_anlunalucru(wme_result, fakeparam)))))) tvaluna ON tvaluna.codtva = nart1luna.codtva
             LEFT JOIN ( SELECT o1.codobiect,
                    o1.tippretmax,
                    o1.pretmaximal
                   FROM martor.nartobj1 o1
                  WHERE (o1.anstart * 12::numeric + o1.lunastart) = (( SELECT max(o11.anstart * 12::numeric + o11.lunastart) AS max
                           FROM martor.nartobj1 o11
                          WHERE o11.codobiect = o1.codobiect AND (o11.anstart * 12::numeric + o11.lunastart) &lt;= ((( SELECT pkg_globals_getanlucru.wme_result
                                   FROM martor.pkg_globals_getanlucru(NULL::numeric, NULL::numeric) pkg_globals_getanlucru(wme_result, fakeparam))) * 12::numeric + (( SELECT pkg_globals_getlunalucru.wme_result
                                   FROM martor.pkg_globals_getlunalucru(NULL::numeric, NULL::numeric) pkg_globals_getlunalucru(wme_result, fakeparam))))))) nartobj1luna ON nartobj1luna.codobiect = o.codobiect
          WHERE o.codarticol = (( SELECT pkg_selectarticole_getcodartcurent.wme_result
                   FROM martor.pkg_selectarticole_getcodartcurent(NULL::numeric, NULL::numeric) pkg_selectarticole_getcodartcurent(wme_result, fakeparam)))
          ORDER BY (COALESCE(t.indexlocal, 0::numeric))) a_pg
  GROUP BY codarticol, codobiect, den_articol, um, clasa, tipserie, tiparticol, aretg, contimplicit, producator, gestimplicita, certificat, evolutiepret, contserviciu, um1, um2, codexternart, sufixcodextern, codvamal, codextern, codintern, umambalare, stocmin, stocmax, termenplata, procadaosnir, promotie, blocat, rotunjire, nefacturabil, cantaribil, codtva, codaccize, codaccizedvi, codtaxa1, codtaxa2, tippretmax, pumaxluna, proctva, produspropriu, inactiv, faracmdfurn, relatieum1, d1, d2, d3, dci, denlocatie, denumiretrad, den_ioart, den_gest, culoare, farastoc;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_nmodeleauto</obj_name>
  <obj_hashval>c0b5ed1196dda8fc331f165d5bb3e066</obj_hashval>
  <obj_text>SELECT a.codmodeleauto,
    b.codmarciauto,
    b.marca,
    a.model
   FROM martor.nmodeleauto a
     LEFT JOIN martor.nmarciauto b ON b.codmarciauto = a.codmarciauto;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_ntaxe</obj_name>
  <obj_hashval>71e8c04892336b9ef4929e78e5ecb78c</obj_hashval>
  <obj_text>SELECT codtaxa,
    den_taxa,
    COALESCE(( SELECT max(ntaxe1.anstart * 12::numeric + ntaxe1.lunastart) AS max
           FROM martor.ntaxe1
          WHERE ntaxe1.codtaxa = t.codtaxa AND (ntaxe1.anstart * 12::numeric + ntaxe1.lunastart) &lt;= (( SELECT pkg_globals_anlunalucru.wme_result
                   FROM martor.pkg_globals_anlunalucru(NULL::numeric, NULL::numeric) pkg_globals_anlunalucru(wme_result, fakeparam)))), 0::numeric) AS activ
   FROM martor.ntaxe t;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_opreg</obj_name>
  <obj_hashval>5ee3ae5b35558278a4dc35bbe1d44538</obj_hashval>
  <obj_text>SELECT o.codop,
    o.tiptranz,
    o.zidecont,
    o.tipdecont,
    o.codmoneda,
    o.codpart,
    o.valoare,
    o.an_max,
    o.luna_max,
    p.den_part
   FROM martor.opreg o
     JOIN martor.npart p ON o.codpart = p.codpart;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_perisabil</obj_name>
  <obj_hashval>231e85febf95b621f604dab14c51b5da</obj_hashval>
  <obj_text>SELECT codperisabil,
    denumire,
    obs
   FROM martor.perisabil;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_rac_p</obj_name>
  <obj_hashval>3bab3d4d6c3ff5e9cc5940dffbfd0a10</obj_hashval>
  <obj_text>SELECT r.codrac_p,
    r.obs,
    m.simbol AS smoneda,
        CASE
            WHEN r.tip = 0::numeric THEN 'Zile'::text
            WHEN r.tip = 1::numeric THEN 'Km'::text
            WHEN r.tip = 2::numeric THEN 'Ore'::text
            WHEN r.tip = 3::numeric THEN 'Buc'::text
            ELSE '?'::text
        END::character varying AS tipc,
    r.tip AS codtip
   FROM martor.rac_p r
     JOIN martor.nmonede m ON m.codmoneda = COALESCE(r.moneda, 0::numeric);</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_rest_obligpif_prec</obj_name>
  <obj_hashval>27a2ba82c554cf057637bd2b3f6da315</obj_hashval>
  <obj_text>SELECT codobligpif,
    rest,
    resttva,
    restsplittva
   FROM martor.obligpifluna
  WHERE an = COALESCE(current_setting('PKG_GLOBALS.ANPRECEDENT'::text, true)::numeric, 0::numeric) AND luna = COALESCE(current_setting('PKG_GLOBALS.LUNAPRECEDENTA'::text, true)::numeric, 0::numeric) AND (COALESCE(rest, 0::numeric) + COALESCE(resttva, 0::numeric) + COALESCE(restsplittva, 0::numeric)) &lt;&gt; 0::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_sablondescript</obj_name>
  <obj_hashval>80864f1ea2c9aba37e7e98997609f80a</obj_hashval>
  <obj_text>SELECT s.codsablon,
    s.denumire AS den_sablon,
    s.simbol,
    d.den_descriptor,
    d.coddescriptor,
    s.denumire
   FROM martor.sablondescript s
     JOIN martor.descriptori d ON s.coddescriptor = d.coddescriptor;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpart_de_stins</obj_name>
  <obj_hashval>a418ff42ed8af8cab91d52dc15bc3fd3</obj_hashval>
  <obj_text>SELECT codpart,
    icont,
    codmoneda,
    sum(soldlei) AS soldlei,
    sum(soldvaluta) AS soldvaluta
   FROM ( SELECT o.codpart,
            o.icont,
            g.moneda AS codmoneda,
                CASE
                    WHEN g.moneda = 0::numeric THEN - o.valoare
                    WHEN g.moneda &lt;&gt; 0::numeric THEN (- o.valoare) * COALESCE(greg.curs, g.curs)
                    ELSE NULL::numeric
                END AS soldlei,
                CASE
                    WHEN g.moneda = 0::numeric THEN 0::numeric
                    WHEN g.moneda &lt;&gt; 0::numeric THEN - o.valoare
                    ELSE NULL::numeric
                END AS soldvaluta
           FROM martor.obligpif o
             LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
             LEFT JOIN ( SELECT r1.codgeneral,
                    r.curs,
                    r1.cont
                   FROM martor.reg1 r1,
                    martor.reg r
                  WHERE r.codreg = r1.codreg AND r.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND r.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND r.tipreg = 46::numeric) greg ON greg.codgeneral = g.codgeneral AND greg.cont = o.icont
             LEFT JOIN martor.intrari i ON i.codintr = g.coddoc
          WHERE (o.semnificatie = 100::numeric OR o.semnificatie = 140::numeric AND i.tipdoc = 2::numeric) AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND i.operat = 1::numeric AND i.anulat = 0::numeric AND (( SELECT pkg_nompart_codpart_sold_analizat_valid.wme_result
                   FROM martor.pkg_nompart_codpart_sold_analizat_valid(NULL::numeric, o.codpart) pkg_nompart_codpart_sold_analizat_valid(wme_result, acodpart))) = 1::numeric
        UNION ALL
         SELECT o.codpart,
            o.icont,
            g.moneda AS codmoneda,
                CASE
                    WHEN g.moneda = 0::numeric THEN i1.pu * i1.cant + COALESCE(i1stins.tva, 0::numeric) *
                    CASE
                        WHEN (i1stins.pu * i1stins.cant) = 0::numeric THEN 0::numeric
                        ELSE i1.pu * i1.cant / (i1stins.pu * i1stins.cant)
                    END
                    WHEN g.moneda &lt;&gt; 0::numeric THEN (i1.pu * i1.cant + COALESCE(i1stins.tva, 0::numeric) *
                    CASE
                        WHEN (i1stins.pu * i1stins.cant) = 0::numeric THEN 0::numeric
                        ELSE i1.pu * i1.cant / (i1stins.pu * i1stins.cant)
                    END) * COALESCE(greg.curs, gstins.curs)
                    ELSE NULL::numeric
                END AS soldlei,
                CASE
                    WHEN g.moneda = 0::numeric THEN 0::numeric
                    WHEN g.moneda &lt;&gt; 0::numeric THEN i1.pu * i1.cant + COALESCE(i1stins.tva, 0::numeric) *
                    CASE
                        WHEN (i1stins.pu * i1stins.cant) = 0::numeric THEN 0::numeric
                        ELSE i1.pu * i1.cant / (i1stins.pu * i1stins.cant)
                    END
                    ELSE NULL::numeric
                END AS soldvaluta
           FROM martor.obligpif o
             LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
             LEFT JOIN martor.intrari i ON i.codintr = g.coddoc
             LEFT JOIN martor.intrari1 i1 ON i1.codintr = i.codintr
             LEFT JOIN martor.intrlink il ON il.codintr1 = i1.codintr1
             LEFT JOIN martor.intrari1 i1stins ON i1stins.codintr1 = il.codlinieaviz
             LEFT JOIN martor.intrari istins ON istins.codintr = i1stins.codintr
             LEFT JOIN martor.general gstins ON gstins.coddoc = istins.codintr AND gstins.tipdoc = istins.tipdoc
             LEFT JOIN ( SELECT r1.codgeneral,
                    r.curs
                   FROM martor.reg1 r1,
                    martor.reg r
                  WHERE r.codreg = r1.codreg AND r.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND r.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND r.tipreg = 46::numeric) greg ON greg.codgeneral = gstins.codgeneral
          WHERE o.semnificatie = 140::numeric AND i.tipdoc = 9::numeric AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND i.operat = 1::numeric AND i.anulat = 0::numeric AND (( SELECT pkg_nompart_codpart_sold_analizat_valid.wme_result
                   FROM martor.pkg_nompart_codpart_sold_analizat_valid(NULL::numeric, o.codpart) pkg_nompart_codpart_sold_analizat_valid(wme_result, acodpart))) = 1::numeric
        UNION ALL
         SELECT dviaviz.codpart,
            dviaviz.icont,
            dviaviz.codmoneda,
            (- dviaviz.valoare) * COALESCE(greg.curs, gstins.curs) AS soldlei,
            - dviaviz.valoare AS soldvaluta
           FROM ( SELECT o.codpart,
                    o.icont,
                    g.moneda AS codmoneda,
                    o.valoare,
                    ( SELECT i1stins.codintr
                           FROM martor.intrari1 i1,
                            martor.intrlink il,
                            martor.intrari1 i1stins
                          WHERE i1.codintr = i.codintr AND il.codintr1 = i1.codintr1 AND i1stins.codintr1 = il.codlinieaviz
                         LIMIT 1) AS codaviz
                   FROM martor.obligpif o,
                    martor.general g,
                    martor.intrari i
                  WHERE o.semnificatie = 140::numeric AND o.codgeneral = g.codgeneral AND g.tipdoc = 5::numeric AND i.codintr = g.coddoc AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND i.operat = 1::numeric AND i.anulat = 0::numeric AND (( SELECT pkg_nompart_codpart_sold_analizat_valid.wme_result
                           FROM martor.pkg_nompart_codpart_sold_analizat_valid(NULL::numeric, o.codpart) pkg_nompart_codpart_sold_analizat_valid(wme_result, acodpart))) = 1::numeric) dviaviz,
            martor.general gstins
             LEFT JOIN ( SELECT r1.codgeneral,
                    r.curs
                   FROM martor.reg1 r1,
                    martor.reg r
                  WHERE r.codreg = r1.codreg AND r.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND r.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND r.tipreg = 46::numeric) greg ON greg.codgeneral = gstins.codgeneral
          WHERE dviaviz.codaviz = gstins.coddoc AND gstins.tipdoc = 2::numeric
        UNION ALL
         SELECT o.codpart,
            o.icont,
            g.moneda AS codmoneda,
                CASE
                    WHEN g.moneda = 0::numeric THEN o.valoare - COALESCE(g.tva, 0::numeric)
                    WHEN g.moneda &lt;&gt; 0::numeric THEN (o.valoare - COALESCE(g.tva, 0::numeric)) * COALESCE(greg.curs, g.curs)
                    ELSE NULL::numeric
                END AS soldlei,
                CASE
                    WHEN g.moneda = 0::numeric THEN 0::numeric
                    WHEN g.moneda &lt;&gt; 0::numeric THEN o.valoare - COALESCE(g.tva, 0::numeric)
                    ELSE NULL::numeric
                END AS soldvaluta
           FROM martor.obligpif o
             LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
             LEFT JOIN ( SELECT r1.codgeneral,
                    r.curs
                   FROM martor.reg1 r1,
                    martor.reg r
                  WHERE r.codreg = r1.codreg AND r.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND r.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND r.tipreg = 46::numeric) greg ON greg.codgeneral = g.codgeneral
             LEFT JOIN martor.intrari i ON i.codintr = g.coddoc
          WHERE o.semnificatie = 110::numeric AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND i.operat = 1::numeric AND i.anulat = 0::numeric AND (( SELECT pkg_nompart_codpart_sold_analizat_valid.wme_result
                   FROM martor.pkg_nompart_codpart_sold_analizat_valid(NULL::numeric, o.codpart) pkg_nompart_codpart_sold_analizat_valid(wme_result, acodpart))) = 1::numeric
        UNION ALL
         SELECT o.codpart,
            o.icont,
            g.moneda AS codmoneda,
                CASE
                    WHEN g.moneda = 0::numeric THEN - o.valoare
                    WHEN g.moneda &lt;&gt; 0::numeric THEN (- o.valoare) * COALESCE(greg.curs, g.curs)
                    ELSE NULL::numeric
                END AS soldlei,
                CASE
                    WHEN g.moneda = 0::numeric THEN 0::numeric
                    WHEN g.moneda &lt;&gt; 0::numeric THEN - o.valoare
                    ELSE NULL::numeric
                END AS soldvaluta
           FROM martor.obligpif o
             LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
             LEFT JOIN ( SELECT r1.codgeneral,
                    r.curs
                   FROM martor.reg1 r1,
                    martor.reg r
                  WHERE r.codreg = r1.codreg AND r.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND r.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND r.tipreg = 46::numeric) greg ON greg.codgeneral = g.codgeneral
             LEFT JOIN martor.dvi d ON g.coddoc = d.coddvi
             LEFT JOIN martor.intrari i ON i.codintr = d.codintr
          WHERE o.semnificatie = 130::numeric AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND i.operat = 1::numeric AND i.anulat = 0::numeric AND (( SELECT pkg_nompart_codpart_sold_analizat_valid.wme_result
                   FROM martor.pkg_nompart_codpart_sold_analizat_valid(NULL::numeric, o.codpart) pkg_nompart_codpart_sold_analizat_valid(wme_result, acodpart))) = 1::numeric
        UNION ALL
         SELECT o.codpart,
            o.icont,
            g.moneda AS codmoneda,
                CASE
                    WHEN g.moneda = 0::numeric THEN o.valoare
                    WHEN g.moneda &lt;&gt; 0::numeric THEN o.valoare * COALESCE(greg.curs, g.curs)
                    ELSE NULL::numeric
                END AS soldlei,
                CASE
                    WHEN g.moneda = 0::numeric THEN 0::numeric
                    WHEN g.moneda &lt;&gt; 0::numeric THEN o.valoare
                    ELSE NULL::numeric
                END AS soldvaluta
           FROM martor.obligpif o
             LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
             LEFT JOIN ( SELECT r1.codgeneral,
                    r.curs
                   FROM martor.reg1 r1,
                    martor.reg r
                  WHERE r.codreg = r1.codreg AND r.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND r.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND r.tipreg = 46::numeric) greg ON greg.codgeneral = g.codgeneral
             LEFT JOIN martor.iesiri i ON i.codies = g.coddoc
          WHERE (o.semnificatie = 200::numeric OR o.semnificatie = 240::numeric AND i.tipdoc = 20::numeric) AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND i.operat = 1::numeric AND i.anulat = 0::numeric AND COALESCE(i.infocm, 0::numeric) = 0::numeric AND (( SELECT pkg_nompart_codpart_sold_analizat_valid.wme_result
                   FROM martor.pkg_nompart_codpart_sold_analizat_valid(NULL::numeric, o.codpart) pkg_nompart_codpart_sold_analizat_valid(wme_result, acodpart))) = 1::numeric
        UNION ALL
         SELECT o.codpart,
            o.icont,
            g.moneda AS codmoneda,
                CASE
                    WHEN g.moneda = 0::numeric THEN - (i1.pu * i1.cant * ((100::numeric + COALESCE(i1.procdisc, 0::numeric)) / 100::numeric) + COALESCE(i1stins.tva, 0::numeric) *
                    CASE
                        WHEN (i1stins.pu * i1stins.cant) = 0::numeric THEN 0::numeric
                        ELSE i1.pu * i1.cant * ((100::numeric + COALESCE(i1.procdisc, 0::numeric)) / 100::numeric) / (i1stins.pu * i1stins.cant)
                    END)
                    WHEN g.moneda &lt;&gt; 0::numeric THEN (- (i1.pu * i1.cant * ((100::numeric + COALESCE(i1.procdisc, 0::numeric)) / 100::numeric) + COALESCE(i1stins.tva, 0::numeric) *
                    CASE
                        WHEN (i1stins.pu * i1stins.cant) = 0::numeric THEN 0::numeric
                        ELSE i1.pu * i1.cant * ((100::numeric + COALESCE(i1.procdisc, 0::numeric)) / 100::numeric) / (i1stins.pu * i1stins.cant)
                    END)) * COALESCE(greg.curs, gstins.curs)
                    ELSE NULL::numeric
                END AS soldlei,
                CASE
                    WHEN g.moneda = 0::numeric THEN 0::numeric
                    WHEN g.moneda &lt;&gt; 0::numeric THEN - (i1.pu * i1.cant * ((100::numeric + COALESCE(i1.procdisc, 0::numeric)) / 100::numeric) + COALESCE(i1stins.tva, 0::numeric) *
                    CASE
                        WHEN (i1stins.pu * i1stins.cant) = 0::numeric THEN 0::numeric
                        ELSE i1.pu * i1.cant * ((100::numeric + COALESCE(i1.procdisc, 0::numeric)) / 100::numeric) / (i1stins.pu * i1stins.cant)
                    END)
                    ELSE NULL::numeric
                END AS soldvaluta
           FROM martor.obligpif o
             LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
             LEFT JOIN martor.iesiri i ON i.codies = g.coddoc
             LEFT JOIN martor.iesiri1 i1 ON i1.codies = i.codies
             LEFT JOIN martor.ieslink il ON il.codies1 = i1.codies1
             LEFT JOIN martor.iesiri1 i1stins ON i1stins.codies1 = il.codlinieaviz
             LEFT JOIN martor.iesiri istins ON istins.codies = i1stins.codies
             LEFT JOIN martor.general gstins ON gstins.coddoc = istins.codies AND gstins.tipdoc = istins.tipdoc
             LEFT JOIN ( SELECT r1.codgeneral,
                    r.curs
                   FROM martor.reg1 r1,
                    martor.reg r
                  WHERE r.codreg = r1.codreg AND r.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND r.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND r.tipreg = 46::numeric) greg ON greg.codgeneral = gstins.codgeneral
          WHERE o.semnificatie = 240::numeric AND i.tipdoc = 26::numeric AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND i.operat = 1::numeric AND i.anulat = 0::numeric AND (( SELECT pkg_nompart_codpart_sold_analizat_valid.wme_result
                   FROM martor.pkg_nompart_codpart_sold_analizat_valid(NULL::numeric, o.codpart) pkg_nompart_codpart_sold_analizat_valid(wme_result, acodpart))) = 1::numeric
        UNION ALL
         SELECT o.codpart,
            o.icont,
            g.moneda AS codmoneda,
                CASE
                    WHEN g.moneda = 0::numeric THEN - (o.valoare - COALESCE(g.tva, 0::numeric))
                    WHEN g.moneda &lt;&gt; 0::numeric THEN (- (o.valoare - COALESCE(g.tva, 0::numeric))) * COALESCE(greg.curs, g.curs)
                    ELSE NULL::numeric
                END AS soldlei,
                CASE
                    WHEN g.moneda = 0::numeric THEN 0::numeric
                    WHEN g.moneda &lt;&gt; 0::numeric THEN - (o.valoare - COALESCE(g.tva, 0::numeric))
                    ELSE NULL::numeric
                END AS soldvaluta
           FROM martor.obligpif o
             LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
             LEFT JOIN ( SELECT r1.codgeneral,
                    r.curs
                   FROM martor.reg1 r1,
                    martor.reg r
                  WHERE r.codreg = r1.codreg AND r.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND r.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND r.tipreg = 46::numeric) greg ON greg.codgeneral = g.codgeneral
             LEFT JOIN martor.iesiri i ON i.codies = g.coddoc
          WHERE o.semnificatie = 210::numeric AND i.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND i.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND i.operat = 1::numeric AND i.anulat = 0::numeric AND (( SELECT pkg_nompart_codpart_sold_analizat_valid.wme_result
                   FROM martor.pkg_nompart_codpart_sold_analizat_valid(NULL::numeric, o.codpart) pkg_nompart_codpart_sold_analizat_valid(wme_result, acodpart))) = 1::numeric
        UNION ALL
         SELECT o.codpart,
            o.icont,
            g.moneda AS codmoneda,
                CASE
                    WHEN g.moneda = 0::numeric AND (g.semnificatie = ANY (ARRAY[310::numeric, 330::numeric])) THEN o.valoare - COALESCE(g.tva, 0::numeric)
                    WHEN g.moneda = 0::numeric AND (g.semnificatie = ANY (ARRAY[410::numeric, 430::numeric])) THEN - (o.valoare - COALESCE(g.tva, 0::numeric))
                    WHEN g.moneda &lt;&gt; 0::numeric AND (g.semnificatie = ANY (ARRAY[310::numeric, 330::numeric])) THEN (o.valoare - COALESCE(g.tva, 0::numeric)) * COALESCE(greg.curs, g.curs)
                    WHEN g.moneda &lt;&gt; 0::numeric AND (g.semnificatie = ANY (ARRAY[410::numeric, 430::numeric])) THEN (- (o.valoare - COALESCE(g.tva, 0::numeric))) * COALESCE(greg.curs, g.curs)
                    ELSE NULL::numeric
                END AS soldlei,
                CASE
                    WHEN g.moneda = 0::numeric THEN 0::numeric
                    WHEN g.moneda &lt;&gt; 0::numeric AND (g.semnificatie = ANY (ARRAY[310::numeric, 330::numeric])) THEN o.valoare - COALESCE(g.tva, 0::numeric)
                    WHEN g.moneda &lt;&gt; 0::numeric AND (g.semnificatie = ANY (ARRAY[410::numeric, 430::numeric])) THEN - (o.valoare - COALESCE(g.tva, 0::numeric))
                    ELSE NULL::numeric
                END AS soldvaluta
           FROM martor.obligpif o
             LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
             LEFT JOIN ( SELECT r1.codgeneral,
                    r.curs
                   FROM martor.reg1 r1,
                    martor.reg r
                  WHERE r.codreg = r1.codreg AND r.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND r.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND r.tipreg = 46::numeric) greg ON greg.codgeneral = g.codgeneral
             LEFT JOIN martor.trezor1 t1 ON t1.codtrezor1 = g.coddoc
             LEFT JOIN martor.trezor t ON t.codtrezor = t1.codtrezor
          WHERE (t1.initializari = 1::numeric OR COALESCE(t1.initializari, 0::numeric) &lt;&gt; 1::numeric AND t.operat = 1::numeric) AND (g.tipdoc = ANY (ARRAY[29::numeric, 30::numeric, 31::numeric, 33::numeric])) AND t1.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND t1.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND (g.semnificatie = ANY (ARRAY[310::numeric, 410::numeric, 330::numeric, 430::numeric])) AND (( SELECT pkg_nompart_codpart_sold_analizat_valid.wme_result
                   FROM martor.pkg_nompart_codpart_sold_analizat_valid(NULL::numeric, o.codpart) pkg_nompart_codpart_sold_analizat_valid(wme_result, acodpart))) = 1::numeric
        UNION ALL
         SELECT o.codpart,
            o.icont,
            g.moneda AS codmoneda,
                CASE
                    WHEN (o.icont = ANY (ARRAY[2::numeric, 5::numeric, 6::numeric, 8::numeric, 9::numeric, 15::numeric, 17::numeric])) AND g.moneda = 0::numeric THEN - o.valoare
                    WHEN (o.icont = ANY (ARRAY[3::numeric, 4::numeric, 7::numeric, 10::numeric, 11::numeric, 12::numeric, 13::numeric, 14::numeric])) AND g.moneda = 0::numeric THEN o.valoare
                    WHEN (o.icont = ANY (ARRAY[2::numeric, 5::numeric, 6::numeric, 8::numeric, 9::numeric, 15::numeric, 17::numeric])) AND g.moneda &lt;&gt; 0::numeric THEN (- o.valoare) * COALESCE(greg.curs, g.curs)
                    WHEN (o.icont = ANY (ARRAY[3::numeric, 4::numeric, 7::numeric, 10::numeric, 11::numeric, 12::numeric, 13::numeric, 14::numeric])) AND g.moneda &lt;&gt; 0::numeric THEN o.valoare * COALESCE(greg.curs, g.curs)
                    ELSE NULL::numeric
                END AS soldlei,
                CASE
                    WHEN g.moneda = 0::numeric THEN 0::numeric
                    WHEN (o.icont = ANY (ARRAY[2::numeric, 5::numeric, 6::numeric, 8::numeric, 9::numeric, 15::numeric, 17::numeric])) AND g.moneda &lt;&gt; 0::numeric THEN - o.valoare
                    WHEN (o.icont = ANY (ARRAY[3::numeric, 4::numeric, 7::numeric, 10::numeric, 11::numeric, 12::numeric, 13::numeric, 14::numeric])) AND g.moneda &lt;&gt; 0::numeric THEN o.valoare
                    ELSE NULL::numeric
                END AS soldvaluta
           FROM martor.obligpif o
             LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
             LEFT JOIN ( SELECT r1.codgeneral,
                    r.curs
                   FROM martor.reg1 r1,
                    martor.reg r
                  WHERE r.codreg = r1.codreg AND r.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND r.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND r.tipreg = 46::numeric) greg ON greg.codgeneral = g.codgeneral
             LEFT JOIN martor.nc1 n1 ON n1.codnc1 = g.coddoc
          WHERE (o.semnificatie = ANY (ARRAY[1200::numeric, 1201::numeric])) AND n1.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND n1.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND (( SELECT pkg_nompart_codpart_sold_analizat_valid.wme_result
                   FROM martor.pkg_nompart_codpart_sold_analizat_valid(NULL::numeric, o.codpart) pkg_nompart_codpart_sold_analizat_valid(wme_result, acodpart))) = 1::numeric
        UNION ALL
         SELECT o.codpart,
            o.icont,
            g.moneda AS codmoneda,
                CASE
                    WHEN (o.icont = ANY (ARRAY[2::numeric, 5::numeric, 8::numeric, 9::numeric, 15::numeric])) AND g.moneda = 0::numeric THEN - o.valoare
                    WHEN (o.icont = ANY (ARRAY[3::numeric, 4::numeric, 6::numeric, 7::numeric, 10::numeric, 11::numeric, 12::numeric, 13::numeric, 14::numeric])) AND g.moneda = 0::numeric THEN o.valoare
                    WHEN (o.icont = ANY (ARRAY[2::numeric, 5::numeric, 8::numeric, 9::numeric, 15::numeric])) AND g.moneda &lt;&gt; 0::numeric THEN (- o.valoare) * COALESCE(greg.curs, g.curs)
                    WHEN (o.icont = ANY (ARRAY[3::numeric, 4::numeric, 6::numeric, 7::numeric, 10::numeric, 11::numeric, 12::numeric, 13::numeric, 14::numeric])) AND g.moneda &lt;&gt; 0::numeric THEN o.valoare * COALESCE(greg.curs, g.curs)
                    ELSE NULL::numeric
                END AS soldlei,
                CASE
                    WHEN g.moneda = 0::numeric THEN 0::numeric
                    WHEN (o.icont = ANY (ARRAY[2::numeric, 5::numeric, 8::numeric, 9::numeric, 15::numeric])) AND g.moneda &lt;&gt; 0::numeric THEN - o.valoare
                    WHEN (o.icont = ANY (ARRAY[3::numeric, 4::numeric, 6::numeric, 7::numeric, 10::numeric, 11::numeric, 12::numeric, 13::numeric, 14::numeric])) AND g.moneda &lt;&gt; 0::numeric THEN o.valoare
                    ELSE NULL::numeric
                END AS soldvaluta
           FROM martor.obligpif o
             LEFT JOIN martor.general g ON g.codgeneral = o.codgeneral
             LEFT JOIN ( SELECT r1.codgeneral,
                    r.curs
                   FROM martor.reg1 r1,
                    martor.reg r
                  WHERE r.codreg = r1.codreg AND r.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND r.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND r.tipreg = 46::numeric) greg ON greg.codgeneral = g.codgeneral
             LEFT JOIN martor.compens c ON c.codcompens = g.coddoc
          WHERE (o.semnificatie = ANY (ARRAY[1301::numeric, 1351::numeric, 1303::numeric])) AND c.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND c.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND (( SELECT pkg_nompart_codpart_sold_analizat_valid.wme_result
                   FROM martor.pkg_nompart_codpart_sold_analizat_valid(NULL::numeric, o.codpart) pkg_nompart_codpart_sold_analizat_valid(wme_result, acodpart))) = 1::numeric) aa_pg
  GROUP BY codpart, icont, codmoneda;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpart_prec</obj_name>
  <obj_hashval>dc2f2428607c8a1c97326f17c192ceec</obj_hashval>
  <obj_text>SELECT p.codpart,
    p.icont,
    p.codmoneda,
        CASE
            WHEN r.curs IS NULL THEN p.soldlei
            ELSE p.soldvaluta * r.curs
        END AS soldlei,
    p.soldvaluta
   FROM martor.npartsoldluna p
     LEFT JOIN martor.reg r ON r.codmoneda = p.codmoneda AND r.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND r.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND r.tipreg = 46::numeric
  WHERE p.an = current_setting('PKG_GLOBALS.ANPRECEDENT'::text)::numeric AND p.luna = current_setting('PKG_GLOBALS.LUNAPRECEDENTA'::text)::numeric AND (( SELECT pkg_nompart_codpart_sold_analizat_valid.wme_result
           FROM martor.pkg_nompart_codpart_sold_analizat_valid(NULL::numeric, p.codpart) pkg_nompart_codpart_sold_analizat_valid(wme_result, acodpart))) = 1::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpers_ini</obj_name>
  <obj_hashval>769e8c783ee808e67a70552adc63d780</obj_hashval>
  <obj_text>SELECT i.codsoldpersini,
    i.codpers,
    p.nume,
    p.prenume,
    ( SELECT sum(ns.soldlei) AS sum
           FROM martor.nperssoldluna ns
          WHERE ns.codpers = i.codpers AND ns.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND ns.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric) AS soldtotal
   FROM martor.soldpersini i
     LEFT JOIN martor.npers p ON i.codpers = p.codpers;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpersoana_luna_prec</obj_name>
  <obj_hashval>71fb18b152ae852503af93298851b247</obj_hashval>
  <obj_text>SELECT codpers,
    icont,
    codmoneda,
    soldlei,
    soldvaluta
   FROM martor.nperssoldluna
  WHERE an = martor.getanprecedent() AND luna = martor.getlunaprecedenta() AND codpers = martor.pkg_nompers_get_persoana_curenta() AND icont = martor.pkg_nompers_get_icontpers_curent() AND codmoneda = martor.pkg_nompers_get_monedapers_curent();</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_utilizator_codutilizator</obj_name>
  <obj_hashval>298340aa8bd12cce4c3acc1f9f6e1653</obj_hashval>
  <obj_text>SELECT codutilizator
   FROM winmadmin.utilizator
  ORDER BY codutilizator;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_bi_incasari</obj_name>
  <obj_hashval>4aca8d667973f2f7187ba3b069e778f2</obj_hashval>
  <obj_text>SELECT g.coddoc,
    g.tipdoc,
    xm.numepresc AS numedoc,
    COALESCE(intr.valdoc, ies.valdoc, t1.valdoc, nc1.valoare, o.valoare) AS valdoc,
    COALESCE(intr.nrdoc, ies.nrdoc, c.nrdoc, t1.nrdoc, nc.nrdoc)::character varying AS nrdoc,
    COALESCE(intr.datadoc::timestamp without time zone, ies.datadoc, c.datadoc::timestamp without time zone, t1.datadoc::timestamp without time zone, nc.datadoc::timestamp without time zone) AS datadoc,
    o.codobligpif AS codoblig,
    o.semnificatie AS tipoblig,
    xs.simb AS simboblig,
    xs.obs AS obsoblig,
    xs.semn::numeric * (o.valoare - xs.tva::numeric * COALESCE(g.tva, 0::numeric)) AS valoblig,
    (xs.semn * xs.tva)::numeric * COALESCE(g.tva, 0::numeric) AS tvaoblig,
        CASE
            WHEN o.termen IS NULL THEN COALESCE(intr.datadoc::timestamp without time zone, ies.datadoc, c.datadoc::timestamp without time zone, t1.datadoc::timestamp without time zone, nc.datadoc::timestamp without time zone)::date + COALESCE(p.scadentav, 0::numeric)::integer
            WHEN o.termen &gt;= COALESCE(intr.datadoc::timestamp without time zone, ies.datadoc, c.datadoc::timestamp without time zone, t1.datadoc::timestamp without time zone, nc.datadoc::timestamp without time zone) THEN o.termen
            ELSE COALESCE(intr.datadoc::timestamp without time zone, ies.datadoc, c.datadoc::timestamp without time zone, t1.datadoc::timestamp without time zone, nc.datadoc::timestamp without time zone)::date + COALESCE(p.scadentav, 0::numeric)::integer
        END AS termenoblig,
    m.simbol AS moneda,
    COALESCE(reg.curs, g.curs, 1::numeric) AS curs,
    o.codpart,
    p.den_part AS partener,
    gs.coddoc AS coddocstingere,
    gs.tipdoc AS tipdocstingere,
    xms.numepresc AS numedocstingere,
    xss.semn::numeric * (os.valoare - xss.tva::numeric * COALESCE(gs.tva, 0::numeric)) AS valstingere,
    (xss.semn * xss.tva)::numeric * COALESCE(gs.tva, 0::numeric) AS tvastingere,
    os.codobligpif AS codstingere,
    os.semnificatie AS tipstingere,
    xss.simb AS simbstingere,
    xss.obs AS obsstingere,
    COALESCE(intrs.datadoc::timestamp without time zone, iess.datadoc, cs.datadoc::timestamp without time zone, t1s.datadoc::timestamp without time zone) AS datastingere,
    COALESCE(intrs.nrdoc, iess.nrdoc, cs.nrdoc, t1s.nrdoc) AS nrdocstingere,
        CASE
            WHEN gs.tipdoc = 31::numeric THEN ( SELECT
                    CASE
                        WHEN t1x.datadoc IS NULL THEN COALESCE(intrs.datadoc::timestamp without time zone, iess.datadoc, cs.datadoc::timestamp without time zone, t1s.datadoc::timestamp without time zone)
                        WHEN COALESCE(intrs.datadoc::timestamp without time zone, iess.datadoc, cs.datadoc::timestamp without time zone, t1s.datadoc::timestamp without time zone) IS NULL THEN t1x.datadoc::timestamp without time zone
                        ELSE GREATEST(t1x.datadoc::timestamp without time zone, COALESCE(intrs.datadoc::timestamp without time zone, iess.datadoc, cs.datadoc::timestamp without time zone, t1s.datadoc::timestamp without time zone))
                    END AS "greatest"
               FROM martor.general gc
                 JOIN martor.obligpif oc ON oc.codgeneral = gc.codgeneral
                 JOIN martor.stingere sc ON sc.codstinspif = oc.codobligpif
                 JOIN martor.obligpif osc ON osc.codobligpif = sc.codstingatorpif
                 JOIN martor.general gsc ON gsc.codgeneral = osc.codgeneral
                 JOIN martor.trezor1 t1x ON t1x.codtrezor1 = gsc.coddoc
              WHERE (gc.semnificatie = ANY (ARRAY[500::numeric, 600::numeric])) AND gc.tipdoc = 31::numeric AND gc.coddoc = gs.coddoc)
            ELSE COALESCE(intrs.datadoc::timestamp without time zone, iess.datadoc, cs.datadoc::timestamp without time zone, t1s.datadoc::timestamp without time zone)
        END AS datadecont,
    CURRENT_DATE AS datasystem,
    COALESCE(intr.an * 100::numeric + intr.luna, ies.an * 100::numeric + ies.luna, c.an * 100::numeric + c.luna, t.an * 100::numeric + t.luna, nc.an * 100::numeric + nc.luna) AS anluna,
    martor.numeprenume(agd.nume, agd.prenume) AS agentdoc,
    martor.numeprenume(ags.nume, ags.prenume) AS agentsting,
    COALESCE(intrs.an * 100::numeric + intrs.luna, iess.an * 100::numeric + iess.luna, cs.an * 100::numeric + cs.luna, ts.an * 100::numeric + ts.luna) AS anlunasting,
    COALESCE(g.curs, 1::numeric) AS cursorig,
    sub.den_subunit AS subunitate_doc,
    clsp.codclasep AS codclasa,
    clsp.den_clasep
   FROM martor.obligpif o
     JOIN martor.v_semnificatii xs ON xs.semnificatie::numeric = o.semnificatie AND
        CASE xs.icont
            WHEN 0 THEN 1
            WHEN o.icont THEN 1
            ELSE 0
        END = 1
     JOIN martor.general g ON g.codgeneral = o.codgeneral
     LEFT JOIN martor.nmonede m ON m.codmoneda = COALESCE(g.moneda, 0::numeric)
     LEFT JOIN martor.machete xm ON xm.codmacheta = g.tipdoc
     LEFT JOIN martor.dvi ON g.coddoc = dvi.coddvi AND o.semnificatie = 130::numeric
     LEFT JOIN martor.intrari intr ON intr.codintr = COALESCE(dvi.codintr, g.coddoc) AND intr.tipdoc = g.tipdoc
     LEFT JOIN martor.iesiri ies ON ies.codies = g.coddoc AND ies.tipdoc = g.tipdoc
     LEFT JOIN martor.compens c ON c.codcompens = g.coddoc AND g.tipdoc = 28::numeric AND (o.semnificatie = ANY (ARRAY[1301::numeric, 1351::numeric, 1303::numeric]))
     LEFT JOIN martor.trezor1 t1 ON t1.codtrezor1 = g.coddoc AND (g.tipdoc = ANY (ARRAY[29::numeric, 30::numeric, 31::numeric, 33::numeric])) AND (g.semnificatie = ANY (ARRAY[310::numeric, 410::numeric, 330::numeric, 430::numeric]))
     LEFT JOIN martor.trezor t ON t.codtrezor = t1.codtrezor
     LEFT JOIN martor.nc1 ON nc1.codnc1 = g.coddoc AND g.tipdoc = 35::numeric AND (o.semnificatie = ANY (ARRAY[1200::numeric, 1201::numeric]))
     LEFT JOIN martor.nc ON nc.codnc = nc1.codnc
     LEFT JOIN martor.nsubunit sub ON sub.codsubunit = COALESCE(intr.subunitatea, ies.subunitatea, t.subunitatea, nc.subunitatea)
     LEFT JOIN martor.npart p ON p.codpart = o.codpart
     LEFT JOIN martor.nclasep clsp ON clsp.codclasep = p.codclasa
     LEFT JOIN ( SELECT aa_pg.codgeneral,
            max(aa_pg.curs) AS curs
           FROM ( SELECT r1.codgeneral,
                    r.curs,
                    dense_rank() OVER (PARTITION BY r1.codgeneral ORDER BY r.datadoc DESC) AS nr
                   FROM martor.reg r
                     JOIN martor.reg1 r1 ON r1.codreg = r.codreg
                  WHERE r.tipreg = 46::numeric) aa_pg
          WHERE aa_pg.nr = 1
          GROUP BY aa_pg.codgeneral) reg ON reg.codgeneral = g.codgeneral
     LEFT JOIN martor.stingere s ON s.codstinspif = o.codobligpif
     LEFT JOIN martor.obligpif os ON os.codobligpif = s.codstingatorpif
     LEFT JOIN martor.general gs ON gs.codgeneral = os.codgeneral
     LEFT JOIN martor.v_semnificatii xss ON xss.semnificatie::numeric = os.semnificatie AND
        CASE xss.icont
            WHEN 0 THEN 1
            WHEN os.icont THEN 1
            ELSE 0
        END = 1
     LEFT JOIN martor.machete xms ON xms.codmacheta = gs.tipdoc
     LEFT JOIN martor.intrari intrs ON intrs.codintr = gs.coddoc AND intrs.tipdoc = gs.tipdoc
     LEFT JOIN martor.iesiri iess ON iess.codies = gs.coddoc AND iess.tipdoc = gs.tipdoc
     LEFT JOIN martor.compens cs ON cs.codcompens = gs.coddoc AND gs.tipdoc = 28::numeric
     LEFT JOIN martor.trezor1 t1s ON t1s.codtrezor1 = gs.coddoc AND (gs.tipdoc = ANY (ARRAY[29::numeric, 30::numeric, 31::numeric, 33::numeric]))
     LEFT JOIN martor.trezor ts ON ts.codtrezor = t1s.codtrezor
     LEFT JOIN martor.npers agd ON agd.codpers = COALESCE(intr.agent, ies.agent, c.agent, t1.agent, t.agent)
     LEFT JOIN martor.npers ags ON ags.codpers = COALESCE(intrs.agent, iess.agent, cs.agent, t1s.agent, ts.agent)
  WHERE (o.semnificatie = ANY (ARRAY[100::numeric, 110::numeric, 120::numeric, 130::numeric, 200::numeric, 210::numeric, 220::numeric, 310::numeric, 330::numeric, 410::numeric, 430::numeric, 1200::numeric, 1201::numeric, 1301::numeric, 1303::numeric, 1351::numeric])) AND (g.tipdoc &lt;&gt; ALL (ARRAY[2::numeric, 20::numeric])) AND COALESCE(intrs.an, iess.an, cs.an, ts.an) = 2019::numeric
  ORDER BY o.codobligpif;</obj_text>
  <obj_nivel>1</obj_nivel>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>pk_discexceptii</obj_name>
  <obj_reftable>discexceptii</obj_reftable>
  <obj_hashval>9e33915443d93b5841d1adeb24086d37</obj_hashval>
  <obj_text>CREATE UNIQUE INDEX pk_discexceptii ON discexceptii USING btree (coddiscexceptie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>pk_doceditat</obj_name>
  <obj_reftable>doceditat</obj_reftable>
  <obj_hashval>3aee63b8bc91d7aa76aa3f53028565d0</obj_hashval>
  <obj_text>CREATE UNIQUE INDEX pk_doceditat ON doceditat USING btree (coddoceditat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>pk_plati2</obj_name>
  <obj_reftable>plati2</obj_reftable>
  <obj_hashval>f3fb788616608cfc11d6d29086d1942d</obj_hashval>
  <obj_text>CREATE UNIQUE INDEX pk_plati2 ON plati2 USING btree (codplata2)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>pk_stocfake</obj_name>
  <obj_reftable>stocfake</obj_reftable>
  <obj_hashval>9d68c3b531683d428968db6ff7308075</obj_hashval>
  <obj_text>CREATE UNIQUE INDEX pk_stocfake ON stocfake USING btree (codstocfake)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>cmdlink_cmd</obj_name>
  <obj_reftable>cmdlink</obj_reftable>
  <obj_hashval>72995356585dabe303d6261105a888e4</obj_hashval>
  <obj_text>CREATE INDEX cmdlink_cmd ON cmdlink USING btree (codliniecomanda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>doi</obj_name>
  <obj_reftable>natrobj</obj_reftable>
  <obj_hashval>678108afd4e179ecfa1fc7a2d9562b05</obj_hashval>
  <obj_text>CREATE INDEX doi ON natrobj USING btree (codvalatr)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>fk_bugetmf1_codbugetmf</obj_name>
  <obj_reftable>bugetmf1</obj_reftable>
  <obj_hashval>8f442ef21efaa681259189a204d26d88</obj_hashval>
  <obj_text>CREATE INDEX fk_bugetmf1_codbugetmf ON bugetmf1 USING btree (codbugetmf)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>fk_fazintr_codfaz</obj_name>
  <obj_reftable>fazintr</obj_reftable>
  <obj_hashval>00d87cd300c25a992fc9250246a49be6</obj_hashval>
  <obj_text>CREATE INDEX fk_fazintr_codfaz ON fazintr USING btree (codfaz)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>fk_raportp3_motive</obj_name>
  <obj_reftable>raportp3</obj_reftable>
  <obj_hashval>33c4f2b7f993e25668a5c5c4d8773a9b</obj_hashval>
  <obj_text>CREATE INDEX fk_raportp3_motive ON raportp3 USING btree (codmotiv)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>fk_raportp3_raportp</obj_name>
  <obj_reftable>raportp3</obj_reftable>
  <obj_hashval>19cca0b1c13259fd64bb081b170d5fef</obj_hashval>
  <obj_text>CREATE INDEX fk_raportp3_raportp ON raportp3 USING btree (codraportp)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>fk_raportp3_raportp1</obj_name>
  <obj_reftable>raportp3</obj_reftable>
  <obj_hashval>01b62a4c3efd3dd22f920d4d5c421883</obj_hashval>
  <obj_text>CREATE INDEX fk_raportp3_raportp1 ON raportp3 USING btree (codraportp1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx</obj_name>
  <obj_reftable>ioart</obj_reftable>
  <obj_hashval>6cfdf4b8a04395465dbc52d3095ccb5c</obj_hashval>
  <obj_text>CREATE INDEX idx ON ioart USING btree (den_ioart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_adaosm1_codadaosm</obj_name>
  <obj_reftable>adaosm1</obj_reftable>
  <obj_hashval>da894244dd1268f517152b773b14c8a0</obj_hashval>
  <obj_text>CREATE INDEX idx_adaosm1_codadaosm ON adaosm1 USING btree (codadaosm)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_aviziesluna</obj_name>
  <obj_reftable>aviziesluna</obj_reftable>
  <obj_hashval>d84844c4102abe9a30cc98cc084b796d</obj_hashval>
  <obj_text>CREATE INDEX idx_aviziesluna ON aviziesluna USING btree (an, luna, codies1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_avizintluna</obj_name>
  <obj_reftable>avizintluna</obj_reftable>
  <obj_hashval>1dc92cbabf23e6366c5b2b11408ebf9a</obj_hashval>
  <obj_text>CREATE INDEX idx_avizintluna ON avizintluna USING btree (an, luna, codintr1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_awbcomanda_codcomanda</obj_name>
  <obj_reftable>awbcomanda</obj_reftable>
  <obj_hashval>00bd0f23b35d219f2f92035a93d7d22c</obj_hashval>
  <obj_text>CREATE INDEX idx_awbcomanda_codcomanda ON awbcomanda USING btree (codcomanda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_bankautentif_iban</obj_name>
  <obj_reftable>bankautentif</obj_reftable>
  <obj_hashval>5ead0be184b0751b7399e86ecc0e0b7a</obj_hashval>
  <obj_text>CREATE INDEX idx_bankautentif_iban ON bankautentif USING btree (iban)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_bonlinkerr_codies</obj_name>
  <obj_reftable>bonlinkerr</obj_reftable>
  <obj_hashval>a6d6ff91aaf2efafa637a264439f0a44</obj_hashval>
  <obj_text>CREATE INDEX idx_bonlinkerr_codies ON bonlinkerr USING btree (codies)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_bugetcap_codbp</obj_name>
  <obj_reftable>bugetcap</obj_reftable>
  <obj_hashval>c9bb41e5d507af7a1f875df2093bc651</obj_hashval>
  <obj_text>CREATE INDEX idx_bugetcap_codbp ON bugetcap USING btree (codbugetprod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_bugetcap1_codbp</obj_name>
  <obj_reftable>bugetcap1</obj_reftable>
  <obj_hashval>af5b6aca0c520d9bb6b96e6b9462fb0b</obj_hashval>
  <obj_text>CREATE INDEX idx_bugetcap1_codbp ON bugetcap1 USING btree (codbugetprod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_bugetcap1_codcls</obj_name>
  <obj_reftable>bugetcap1</obj_reftable>
  <obj_hashval>776769630b6c8e21a677fdd6e5f514b6</obj_hashval>
  <obj_text>CREATE INDEX idx_bugetcap1_codcls ON bugetcap1 USING btree (codclasea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_bugetcl_codbugetprod</obj_name>
  <obj_reftable>bugetcl</obj_reftable>
  <obj_hashval>b39533e08950e01ac2025a94bc7b2b81</obj_hashval>
  <obj_text>CREATE INDEX idx_bugetcl_codbugetprod ON bugetcl USING btree (codbugetprod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_bugetcl_codelembuget</obj_name>
  <obj_reftable>bugetcl</obj_reftable>
  <obj_hashval>960ef74dd64772669219a359db93185e</obj_hashval>
  <obj_text>CREATE INDEX idx_bugetcl_codelembuget ON bugetcl USING btree (codelembuget)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_bugetstoc_codbugetprod</obj_name>
  <obj_reftable>bugetstoc</obj_reftable>
  <obj_hashval>c9d385b830ddfabd5611cc90f8898cd0</obj_hashval>
  <obj_text>CREATE INDEX idx_bugetstoc_codbugetprod ON bugetstoc USING btree (codbugetprod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_bugetstoc_codclasea</obj_name>
  <obj_reftable>bugetstoc</obj_reftable>
  <obj_hashval>2b1aac2cc5a0a3879e49bd5df5b48418</obj_hashval>
  <obj_text>CREATE INDEX idx_bugetstoc_codclasea ON bugetstoc USING btree (codclasea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_bugetstoc_codobiect</obj_name>
  <obj_reftable>bugetstoc</obj_reftable>
  <obj_hashval>38faa5ae44b168f6c99190f75f29d252</obj_hashval>
  <obj_text>CREATE INDEX idx_bugetstoc_codobiect ON bugetstoc USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_bugetvcl_codbugetprod</obj_name>
  <obj_reftable>bugetvcl</obj_reftable>
  <obj_hashval>34a38139a391103b1ed5237c7a25ec96</obj_hashval>
  <obj_text>CREATE INDEX idx_bugetvcl_codbugetprod ON bugetvcl USING btree (codbugetprod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_bugetvcl_codclasea</obj_name>
  <obj_reftable>bugetvcl</obj_reftable>
  <obj_hashval>4b1dd13613394e825812278aa2c3c2d9</obj_hashval>
  <obj_text>CREATE INDEX idx_bugetvcl_codclasea ON bugetvcl USING btree (codclasea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_bugetvcl_codobiect</obj_name>
  <obj_reftable>bugetvcl</obj_reftable>
  <obj_hashval>1987948df8855098ef7d778845584d4e</obj_hashval>
  <obj_text>CREATE INDEX idx_bugetvcl_codobiect ON bugetvcl USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_bugetvl_codbugetprod</obj_name>
  <obj_reftable>bugetvl</obj_reftable>
  <obj_hashval>f469e4825bdcee5e90857540d9acc921</obj_hashval>
  <obj_text>CREATE INDEX idx_bugetvl_codbugetprod ON bugetvl USING btree (codbugetprod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_bugetvl_codelembuget</obj_name>
  <obj_reftable>bugetvl</obj_reftable>
  <obj_hashval>2b868bd649511648973e8780a0f4a2d9</obj_hashval>
  <obj_text>CREATE INDEX idx_bugetvl_codelembuget ON bugetvl USING btree (codelembuget)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cantar_coddoc1</obj_name>
  <obj_reftable>cantar</obj_reftable>
  <obj_hashval>eef3e411e15c37618f9aa73021016b63</obj_hashval>
  <obj_text>CREATE INDEX idx_cantar_coddoc1 ON cantar USING btree (coddoc1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cantar_codobiect</obj_name>
  <obj_reftable>cantar</obj_reftable>
  <obj_hashval>748d7618301b42bc550146dc52a94c48</obj_hashval>
  <obj_text>CREATE INDEX idx_cantar_codobiect ON cantar USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cantar_serie</obj_name>
  <obj_reftable>cantar</obj_reftable>
  <obj_hashval>7a685a88d0eab983f2ff2c459883e22a</obj_hashval>
  <obj_text>CREATE INDEX idx_cantar_serie ON cantar USING btree (serie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cantar_useridblocaj</obj_name>
  <obj_reftable>cantar</obj_reftable>
  <obj_hashval>ebc12ab177c3b7562387d9cf02fb08e3</obj_hashval>
  <obj_text>CREATE INDEX idx_cantar_useridblocaj ON cantar USING btree (useridblocaj)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_centrecost_tipaloc</obj_name>
  <obj_reftable>centrecost</obj_reftable>
  <obj_hashval>b0489100166ae2fcfb5d9965b5151499</obj_hashval>
  <obj_text>CREATE INDEX idx_centrecost_tipaloc ON centrecost USING btree (tipaloc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_centrecost_tipchelt</obj_name>
  <obj_reftable>centrecost</obj_reftable>
  <obj_hashval>b48c06236ec71890996cbcec6a47160b</obj_hashval>
  <obj_text>CREATE INDEX idx_centrecost_tipchelt ON centrecost USING btree (tipchelt)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cfgactions</obj_name>
  <obj_reftable>cfgactions</obj_reftable>
  <obj_hashval>9035726e6d601677e2c281be043e6907</obj_hashval>
  <obj_text>CREATE INDEX idx_cfgactions ON cfgactions USING btree (tipdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cheltavans_codies1</obj_name>
  <obj_reftable>cheltavans</obj_reftable>
  <obj_hashval>cfdd27e39a7563eeb6e8676e0a538cbb</obj_hashval>
  <obj_text>CREATE INDEX idx_cheltavans_codies1 ON cheltavans USING btree (codies1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cheltavans_codintr1</obj_name>
  <obj_reftable>cheltavans</obj_reftable>
  <obj_hashval>8ed70b2da993da802a05dc2e82335e0b</obj_hashval>
  <obj_text>CREATE INDEX idx_cheltavans_codintr1 ON cheltavans USING btree (codintr1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cheltavans_codnc1</obj_name>
  <obj_reftable>cheltavans</obj_reftable>
  <obj_hashval>106921c310448d3c6e5af4de96b717d4</obj_hashval>
  <obj_text>CREATE INDEX idx_cheltavans_codnc1 ON cheltavans USING btree (codnc1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cheltavans_codobligpif</obj_name>
  <obj_reftable>cheltavans</obj_reftable>
  <obj_hashval>41461b7dbe4faa5cb1d3934c3f24ff8f</obj_hashval>
  <obj_text>CREATE INDEX idx_cheltavans_codobligpif ON cheltavans USING btree (codobligpif)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cheltavans1_anstart</obj_name>
  <obj_reftable>cheltavans1</obj_reftable>
  <obj_hashval>b97fa1ac6d5adc432e9b49a41c391e3e</obj_hashval>
  <obj_text>CREATE INDEX idx_cheltavans1_anstart ON cheltavans1 USING btree (anstart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cheltavans1_codcheltavans</obj_name>
  <obj_reftable>cheltavans1</obj_reftable>
  <obj_hashval>fe10ab4b1c5f5a25ee1e5cb9786e70da</obj_hashval>
  <obj_text>CREATE INDEX idx_cheltavans1_codcheltavans ON cheltavans1 USING btree (codcheltavans)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cheltavans1_lunastart</obj_name>
  <obj_reftable>cheltavans1</obj_reftable>
  <obj_hashval>de062582cabc2b918da875a61e14094f</obj_hashval>
  <obj_text>CREATE INDEX idx_cheltavans1_lunastart ON cheltavans1 USING btree (lunastart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cheltoper1_codobiect</obj_name>
  <obj_reftable>cheltoper1</obj_reftable>
  <obj_hashval>8352310f3c8be49520dcf366bbdf40c7</obj_hashval>
  <obj_text>CREATE INDEX idx_cheltoper1_codobiect ON cheltoper1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cmdprobari_coddoc</obj_name>
  <obj_reftable>cmdaprobari</obj_reftable>
  <obj_hashval>2e71593d861fe421f14367e50296de6e</obj_hashval>
  <obj_text>CREATE INDEX idx_cmdprobari_coddoc ON cmdaprobari USING btree (coddoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cmdprobari_tipdoc</obj_name>
  <obj_reftable>cmdaprobari</obj_reftable>
  <obj_hashval>d074ebc08a8000011b18a2187cc33380</obj_hashval>
  <obj_text>CREATE INDEX idx_cmdprobari_tipdoc ON cmdaprobari USING btree (tipdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cmdprodman_codcomanda1</obj_name>
  <obj_reftable>cmdprodman</obj_reftable>
  <obj_hashval>ac4625f4b9a856db83df4c4ee73aadf6</obj_hashval>
  <obj_text>CREATE INDEX idx_cmdprodman_codcomanda1 ON cmdprodman USING btree (codcomanda1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cmdprodman_codloc</obj_name>
  <obj_reftable>cmdprodman</obj_reftable>
  <obj_hashval>5fac06e26cb0ab8a1e916efcb5f5ef7a</obj_hashval>
  <obj_text>CREATE INDEX idx_cmdprodman_codloc ON cmdprodman USING btree (codloc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cmdprodman_codman</obj_name>
  <obj_reftable>cmdprodman</obj_reftable>
  <obj_hashval>4ea3d5775b7fc44d8213492c2425dd04</obj_hashval>
  <obj_text>CREATE INDEX idx_cmdprodman_codman ON cmdprodman USING btree (codman)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cmdprodman_codop</obj_name>
  <obj_reftable>cmdprodman</obj_reftable>
  <obj_hashval>97b5059739fc054758c1469ce8123769</obj_hashval>
  <obj_text>CREATE INDEX idx_cmdprodman_codop ON cmdprodman USING btree (codop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cmdprodman_codprodgest</obj_name>
  <obj_reftable>cmdprodman</obj_reftable>
  <obj_hashval>9d8707fde1e995b7ffc1b9251b49039a</obj_hashval>
  <obj_text>CREATE INDEX idx_cmdprodman_codprodgest ON cmdprodman USING btree (codprodgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cmdprodman_codtarif</obj_name>
  <obj_reftable>cmdprodman</obj_reftable>
  <obj_hashval>2578de1d7770fd3ac568ad1bb66f2210</obj_hashval>
  <obj_text>CREATE INDEX idx_cmdprodman_codtarif ON cmdprodman USING btree (codtarif)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cmdprodman_nrop</obj_name>
  <obj_reftable>cmdprodman</obj_reftable>
  <obj_hashval>e386babc3bcf625bfdea621e19380bff</obj_hashval>
  <obj_text>CREATE INDEX idx_cmdprodman_nrop ON cmdprodman USING btree (nrop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cmdprodmat_codcomanda1</obj_name>
  <obj_reftable>cmdprodmat</obj_reftable>
  <obj_hashval>7545d9b9316e9677761145b4ff1e05a7</obj_hashval>
  <obj_text>CREATE INDEX idx_cmdprodmat_codcomanda1 ON cmdprodmat USING btree (codcomanda1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cmdprodmat_codobiect</obj_name>
  <obj_reftable>cmdprodmat</obj_reftable>
  <obj_hashval>e75a0747e7d6ac86cd3721dcba1452e9</obj_hashval>
  <obj_text>CREATE INDEX idx_cmdprodmat_codobiect ON cmdprodmat USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cmdprodmat_codprodmat</obj_name>
  <obj_reftable>cmdprodmat</obj_reftable>
  <obj_hashval>3f35a39f6164095c24f63f869ebcd504</obj_hashval>
  <obj_text>CREATE INDEX idx_cmdprodmat_codprodmat ON cmdprodmat USING btree (codprodmat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_cmdprodmat_tip</obj_name>
  <obj_reftable>cmdprodmat</obj_reftable>
  <obj_hashval>895cc1be09b476d5fdc7a7b90ab1ddcb</obj_hashval>
  <obj_text>CREATE INDEX idx_cmdprodmat_tip ON cmdprodmat USING btree (tip)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_codcatpret</obj_name>
  <obj_reftable>syncpretretail</obj_reftable>
  <obj_hashval>bb5f9cb0d57e58ee5d9a4b80c063ad78</obj_hashval>
  <obj_text>CREATE INDEX idx_codcatpret ON syncpretretail USING btree (codcatpret)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_codcomanda</obj_name>
  <obj_reftable>cmdavans</obj_reftable>
  <obj_hashval>f7348f3722a563af69744bdb4770d453</obj_hashval>
  <obj_text>CREATE INDEX idx_codcomanda ON cmdavans USING btree (codcomanda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_codextalt_cod_codobj</obj_name>
  <obj_reftable>codextalt</obj_reftable>
  <obj_hashval>cebe199d7f9c995d9a992e177c887309</obj_hashval>
  <obj_text>CREATE INDEX idx_codextalt_cod_codobj ON codextalt USING btree (codobiect, cod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_codextalt_codobiect</obj_name>
  <obj_reftable>codextalt</obj_reftable>
  <obj_hashval>8f14dc05c1b907e84eac60bddbc19c16</obj_hashval>
  <obj_text>CREATE INDEX idx_codextalt_codobiect ON codextalt USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_codiesavans</obj_name>
  <obj_reftable>cmdavans</obj_reftable>
  <obj_hashval>49da380ca37a3d1b9148fcca115b99ba</obj_hashval>
  <obj_text>CREATE INDEX idx_codiesavans ON cmdavans USING btree (codiesavans)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_codintalt_codobiect</obj_name>
  <obj_reftable>codintalt</obj_reftable>
  <obj_hashval>d8a38a046edd7f8037b9e8273cb7b8b2</obj_hashval>
  <obj_text>CREATE INDEX idx_codintalt_codobiect ON codintalt USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_codobiect</obj_name>
  <obj_reftable>syncpretretail</obj_reftable>
  <obj_hashval>512442370e911002b19f254cc7e7ff9a</obj_hashval>
  <obj_text>CREATE INDEX idx_codobiect ON syncpretretail USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_codpostretail</obj_name>
  <obj_reftable>syncpretretail</obj_reftable>
  <obj_hashval>5062649dfbb794e2f03a45b46184d862</obj_hashval>
  <obj_text>CREATE INDEX idx_codpostretail ON syncpretretail USING btree (codpostretail)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_codsala</obj_name>
  <obj_reftable>saliuseri</obj_reftable>
  <obj_hashval>6c9cdfe0ce947e6810eedd1f82ecf9aa</obj_hashval>
  <obj_text>CREATE INDEX idx_codsala ON saliuseri USING btree (codsala)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda_agent</obj_name>
  <obj_reftable>comanda</obj_reftable>
  <obj_hashval>4ca69e27fe505cd9a91911011df0d2dc</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda_agent ON comanda USING btree (agent)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda_anluna</obj_name>
  <obj_reftable>comanda</obj_reftable>
  <obj_hashval>255818056811a33255617a9c98508dba</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda_anluna ON comanda USING btree ((((an * (12)::numeric) + luna)))</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda_anulat</obj_name>
  <obj_reftable>comanda</obj_reftable>
  <obj_hashval>55acaa0e7d7f21cb5a74a776bf528148</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda_anulat ON comanda USING btree (anulat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda_codgest</obj_name>
  <obj_reftable>comanda</obj_reftable>
  <obj_hashval>3cd457b746af17f550e961bd484b8f07</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda_codgest ON comanda USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda_codlocatie</obj_name>
  <obj_reftable>comanda</obj_reftable>
  <obj_hashval>e87475212e85cf80b58b5a04b7f84340</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda_codlocatie ON comanda USING btree (codlocatie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda_delegat</obj_name>
  <obj_reftable>comanda</obj_reftable>
  <obj_hashval>2c1be061dcefe097be1b50b63417aa9c</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda_delegat ON comanda USING btree (delegat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda_displivrare</obj_name>
  <obj_reftable>comanda</obj_reftable>
  <obj_hashval>f331b19efb2d24dd4c4b0f843c7c87b7</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda_displivrare ON comanda USING btree (displivrare)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda_inchisa</obj_name>
  <obj_reftable>comanda</obj_reftable>
  <obj_hashval>487a74f2a61bffab67bdd2aed8a1c3b6</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda_inchisa ON comanda USING btree (inchisa)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda_operat</obj_name>
  <obj_reftable>comanda</obj_reftable>
  <obj_hashval>b67652dc6e0e75036ac08d61612d4e2c</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda_operat ON comanda USING btree (operat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda_partener</obj_name>
  <obj_reftable>comanda</obj_reftable>
  <obj_hashval>7588c6f1e8db235bf4fbcf4369c58097</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda_partener ON comanda USING btree (partener)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda_subunitatea</obj_name>
  <obj_reftable>comanda</obj_reftable>
  <obj_hashval>a380907e6bab76ce23420c6c419ce26a</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda_subunitatea ON comanda USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda_tipdoc</obj_name>
  <obj_reftable>comanda</obj_reftable>
  <obj_hashval>a3dbc1686eb288a16d42b693059f85f7</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda_tipdoc ON comanda USING btree (tipdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda_userid</obj_name>
  <obj_reftable>comanda</obj_reftable>
  <obj_hashval>82df3b2cb4734c7f74c2dad62c5e1a0a</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda_userid ON comanda USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda1_cantacceptat</obj_name>
  <obj_reftable>comanda1</obj_reftable>
  <obj_hashval>1953ce0cee5bafa942b0d99278a419a7</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda1_cantacceptat ON comanda1 USING btree (cantacceptat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda1_codcomanda</obj_name>
  <obj_reftable>comanda1</obj_reftable>
  <obj_hashval>9d5395d5cc9c84cef333d919edf50d3a</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda1_codcomanda ON comanda1 USING btree (codcomanda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda1_codnorma</obj_name>
  <obj_reftable>comanda1</obj_reftable>
  <obj_hashval>4e631a47bffc491d3b3d79af4826519b</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda1_codnorma ON comanda1 USING btree (codnorma)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda1_codobiect</obj_name>
  <obj_reftable>comanda1</obj_reftable>
  <obj_hashval>0739c1808a09b3f3a3e65bc628769d1f</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda1_codobiect ON comanda1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda1_codproiect</obj_name>
  <obj_reftable>comanda1</obj_reftable>
  <obj_hashval>9437902b04cf70c7ea4410f60aef9703</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda1_codproiect ON comanda1 USING btree (codproiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda1_codreteta</obj_name>
  <obj_reftable>comanda1</obj_reftable>
  <obj_hashval>ef4e7def1615b48f706b920ddda7618b</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda1_codreteta ON comanda1 USING btree (codreteta)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda1_restacceptat</obj_name>
  <obj_reftable>comanda1</obj_reftable>
  <obj_hashval>186a61bf7c2a1067713ec397cf5b4aec</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda1_restacceptat ON comanda1 USING btree (restacceptat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda1_termen</obj_name>
  <obj_reftable>comanda1</obj_reftable>
  <obj_hashval>5e1c9e7ce37769ca1f00ba0d4a44e4cb</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda1_termen ON comanda1 USING btree (termen)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda1_umsec</obj_name>
  <obj_reftable>comanda1</obj_reftable>
  <obj_hashval>b0d310728adc888180b66d16bb2cf12a</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda1_umsec ON comanda1 USING btree (umsec)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda1et_codcomanda1</obj_name>
  <obj_reftable>comanda1et</obj_reftable>
  <obj_hashval>efa7f039fdddb668b1dc2cb9040f80e3</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda1et_codcomanda1 ON comanda1et USING btree (codcomanda1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda1luna_an</obj_name>
  <obj_reftable>comanda1luna</obj_reftable>
  <obj_hashval>3aadf5de60d555f9722f89c14a0394ae</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda1luna_an ON comanda1luna USING btree (an)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda1luna_codcomanda1</obj_name>
  <obj_reftable>comanda1luna</obj_reftable>
  <obj_hashval>30f1e61e28b8c783d5ef8c2e7043383e</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda1luna_codcomanda1 ON comanda1luna USING btree (codcomanda1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda1luna_luna</obj_name>
  <obj_reftable>comanda1luna</obj_reftable>
  <obj_hashval>b409cf64bbd69bb55c37965787a8cebe</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda1luna_luna ON comanda1luna USING btree (luna)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda3_codcomanda1</obj_name>
  <obj_reftable>comanda3</obj_reftable>
  <obj_hashval>bd59c064926e64a9239a48ee4b727d88</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda3_codcomanda1 ON comanda3 USING btree (codcomanda1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_comanda3_codoperatie</obj_name>
  <obj_reftable>comanda3</obj_reftable>
  <obj_hashval>7f8445227b993dc8b01b1f8354bc468e</obj_hashval>
  <obj_text>CREATE INDEX idx_comanda3_codoperatie ON comanda3 USING btree (codoperatie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_compens_codgest</obj_name>
  <obj_reftable>compens</obj_reftable>
  <obj_hashval>7045c8e7d52a526aa9dd0bd31c1136c4</obj_hashval>
  <obj_text>CREATE INDEX idx_compens_codgest ON compens USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_compens_partc</obj_name>
  <obj_reftable>compens</obj_reftable>
  <obj_hashval>0e4b8c3fc50427ee53cbfd8ff2f473b0</obj_hashval>
  <obj_text>CREATE INDEX idx_compens_partc ON compens USING btree (partc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_compens_partd</obj_name>
  <obj_reftable>compens</obj_reftable>
  <obj_hashval>66a6c8115194640ba6c3e5857579b003</obj_hashval>
  <obj_text>CREATE INDEX idx_compens_partd ON compens USING btree (partd)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_compens_subunitatea</obj_name>
  <obj_reftable>compens</obj_reftable>
  <obj_hashval>a956709f3cac1fa5f27001953b1b5c51</obj_hashval>
  <obj_text>CREATE INDEX idx_compens_subunitatea ON compens USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_const1_codcateg</obj_name>
  <obj_reftable>const1</obj_reftable>
  <obj_hashval>91916cb70059b3e69f34db15d1d79277</obj_hashval>
  <obj_text>CREATE INDEX idx_const1_codcateg ON const1 USING btree (codcateg)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_const1_simbol</obj_name>
  <obj_reftable>const1</obj_reftable>
  <obj_hashval>31bee48c4561ccd3d3dc61baebea5b2e</obj_hashval>
  <obj_text>CREATE INDEX idx_const1_simbol ON const1 USING btree (upper((simbol)::text))</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_constluna</obj_name>
  <obj_reftable>constluna</obj_reftable>
  <obj_hashval>a578378a3ec5fdaab07e77b83ce36fe5</obj_hashval>
  <obj_text>CREATE INDEX idx_constluna ON constluna USING btree (codconst1, userid, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_constmaketa_codconst1</obj_name>
  <obj_reftable>constmaketa</obj_reftable>
  <obj_hashval>65a1f9191d8446d8c754ef843eb6ba30</obj_hashval>
  <obj_text>CREATE INDEX idx_constmaketa_codconst1 ON constmaketa USING btree (codconst1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_constmaketa_codmaketa</obj_name>
  <obj_reftable>constmaketa</obj_reftable>
  <obj_hashval>7f3c7d00c694eecb5a57e5b9c8a8b470</obj_hashval>
  <obj_text>CREATE INDEX idx_constmaketa_codmaketa ON constmaketa USING btree (codmaketa)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_constval_codconstluna</obj_name>
  <obj_reftable>constval</obj_reftable>
  <obj_hashval>e82e21e650e286c56f9094104515df9e</obj_hashval>
  <obj_text>CREATE INDEX idx_constval_codconstluna ON constval USING btree (codconstluna)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_constval_valoare</obj_name>
  <obj_reftable>constval</obj_reftable>
  <obj_hashval>a0a1c3de3df5caaac576c2374ed195ec</obj_hashval>
  <obj_text>CREATE INDEX idx_constval_valoare ON constval USING btree (COALESCE(valoare, '0'::character varying))</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_constvalpos_codconstluna</obj_name>
  <obj_reftable>constvalpos</obj_reftable>
  <obj_hashval>c6ea48cea4e891b65a09952c18c56b5b</obj_hashval>
  <obj_text>CREATE INDEX idx_constvalpos_codconstluna ON constvalpos USING btree (codconstluna, idx)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_contract_codgeneric</obj_name>
  <obj_reftable>contract</obj_reftable>
  <obj_hashval>2b714e857410f713e8bcdb337df1933c</obj_hashval>
  <obj_text>CREATE INDEX idx_contract_codgeneric ON contract USING btree (codgeneric)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_contract_moneda</obj_name>
  <obj_reftable>contract</obj_reftable>
  <obj_hashval>86b2dbfe971a87eee594f1da09b558d7</obj_hashval>
  <obj_text>CREATE INDEX idx_contract_moneda ON contract USING btree (moneda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_contract_partener</obj_name>
  <obj_reftable>contract</obj_reftable>
  <obj_hashval>0e44c83dbe69d1b78da4a0797f9477d0</obj_hashval>
  <obj_text>CREATE INDEX idx_contract_partener ON contract USING btree (partener)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_contract_subunitatea</obj_name>
  <obj_reftable>contract</obj_reftable>
  <obj_hashval>1c579e0fd226a87729cb794ef3c6a58f</obj_hashval>
  <obj_text>CREATE INDEX idx_contract_subunitatea ON contract USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_contract_tipdoc</obj_name>
  <obj_reftable>contract</obj_reftable>
  <obj_hashval>b1d98c20f897d62cff9062390a3f490f</obj_hashval>
  <obj_text>CREATE INDEX idx_contract_tipdoc ON contract USING btree (tipdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_contract0_codcontract</obj_name>
  <obj_reftable>contract0</obj_reftable>
  <obj_hashval>d0a1b25a486022acea1700979e53d135</obj_hashval>
  <obj_text>CREATE INDEX idx_contract0_codcontract ON contract0 USING btree (codcontract)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_contract1_codcontract</obj_name>
  <obj_reftable>contract1</obj_reftable>
  <obj_hashval>f998c33912392737f5dbf493ffda9746</obj_hashval>
  <obj_text>CREATE INDEX idx_contract1_codcontract ON contract1 USING btree (codcontract)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_contract1_codobiect</obj_name>
  <obj_reftable>contract1</obj_reftable>
  <obj_hashval>7a78578da6840dd683485efc0b859638</obj_hashval>
  <obj_text>CREATE INDEX idx_contract1_codobiect ON contract1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_contract1_umsec</obj_name>
  <obj_reftable>contract1</obj_reftable>
  <obj_hashval>780d70dc7ff5fad2f054a9143b5a830a</obj_hashval>
  <obj_text>CREATE INDEX idx_contract1_umsec ON contract1 USING btree (umsec)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_contract2_codcontract</obj_name>
  <obj_reftable>contract2</obj_reftable>
  <obj_hashval>2e202cacf9eafc56cadb1621f8c19931</obj_hashval>
  <obj_text>CREATE INDEX idx_contract2_codcontract ON contract2 USING btree (codcontract)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_contractc_codcontract1</obj_name>
  <obj_reftable>contractc</obj_reftable>
  <obj_hashval>c91a9b35d4c0560f57dbc4830be827f3</obj_hashval>
  <obj_text>CREATE INDEX idx_contractc_codcontract1 ON contractc USING btree (codcontract1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_contractc0_codcontract</obj_name>
  <obj_reftable>contractc0</obj_reftable>
  <obj_hashval>1a4cb50fef1872c7875607e580642392</obj_hashval>
  <obj_text>CREATE INDEX idx_contractc0_codcontract ON contractc0 USING btree (codcontract)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_contractt_codcontract</obj_name>
  <obj_reftable>contractt</obj_reftable>
  <obj_hashval>d4ad5462f31738cadd98fc1061850f21</obj_hashval>
  <obj_text>CREATE INDEX idx_contractt_codcontract ON contractt USING btree (codcontract1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_contractv_codcontract</obj_name>
  <obj_reftable>contractv</obj_reftable>
  <obj_hashval>b4134880acfaf42f6c2d71e58f7f4d66</obj_hashval>
  <obj_text>CREATE INDEX idx_contractv_codcontract ON contractv USING btree (codcontract)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_contractx_codcontract1</obj_name>
  <obj_reftable>contractx</obj_reftable>
  <obj_hashval>087884908293d71d291afe7f3fb419ef</obj_hashval>
  <obj_text>CREATE INDEX idx_contractx_codcontract1 ON contractx USING btree (codcontract1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_contractxx_codcontract1</obj_name>
  <obj_reftable>contractxx</obj_reftable>
  <obj_hashval>ef3f8d74343224bb7aaa4905cce41640</obj_hashval>
  <obj_text>CREATE INDEX idx_contractxx_codcontract1 ON contractxx USING btree (codcontract1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_d39416rns3_codd39416rn1</obj_name>
  <obj_reftable>d39416rns3</obj_reftable>
  <obj_hashval>cd06e888292623b1f717dcae2f304cff</obj_hashval>
  <obj_text>CREATE INDEX idx_d39416rns3_codd39416rn1 ON d39416rns3 USING btree (codd39416rn1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_d39416rns3_codd39416rns2</obj_name>
  <obj_reftable>d39416rns3</obj_reftable>
  <obj_hashval>6b9565882e9791105e5f2ab64cc0fe3d</obj_hashval>
  <obj_text>CREATE INDEX idx_d39416rns3_codd39416rns2 ON d39416rns3 USING btree (codd39416rns2)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_debug_userid</obj_name>
  <obj_reftable>debug_liste</obj_reftable>
  <obj_hashval>b8828662e9e529207fa74a263d326156</obj_hashval>
  <obj_text>CREATE INDEX idx_debug_userid ON debug_liste USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_dflansz_saptamana</obj_name>
  <obj_reftable>dflansz1</obj_reftable>
  <obj_hashval>e6cff8ce7e948a28d27ccb4a82c5320b</obj_hashval>
  <obj_text>CREATE INDEX idx_dflansz_saptamana ON dflansz1 USING btree (saptamana)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_dflansz1_an</obj_name>
  <obj_reftable>dflansz1</obj_reftable>
  <obj_hashval>dfbfe3f88891fb1303f043a9b7a18f81</obj_hashval>
  <obj_text>CREATE INDEX idx_dflansz1_an ON dflansz1 USING btree (an)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_dflansz1_codlansz</obj_name>
  <obj_reftable>dflansz1</obj_reftable>
  <obj_hashval>75e54c1a48dd3b103527b3899ec9f2ee</obj_hashval>
  <obj_text>CREATE INDEX idx_dflansz1_codlansz ON dflansz1 USING btree (codlansz)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_dflansz1_codobiect</obj_name>
  <obj_reftable>dflansz1</obj_reftable>
  <obj_hashval>e480ffdf16299d61f8e1e71c46328da0</obj_hashval>
  <obj_text>CREATE INDEX idx_dflansz1_codobiect ON dflansz1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_dflansz1_codreteta</obj_name>
  <obj_reftable>dflansz1</obj_reftable>
  <obj_hashval>557f3a2413e08fd597a00d36abfa4301</obj_hashval>
  <obj_text>CREATE INDEX idx_dflansz1_codreteta ON dflansz1 USING btree (codreteta)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_disamf_coddoc1</obj_name>
  <obj_reftable>fisamf</obj_reftable>
  <obj_hashval>62b355c08665b1972a3008b5fb4b7a8b</obj_hashval>
  <obj_text>CREATE INDEX idx_disamf_coddoc1 ON fisamf USING btree (coddoc1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_discart_codclasa</obj_name>
  <obj_reftable>discart</obj_reftable>
  <obj_hashval>f89da2a769447dfa112166d36038dae8</obj_hashval>
  <obj_text>CREATE INDEX idx_discart_codclasa ON discart USING btree (codclasa)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_discart_coddiscount</obj_name>
  <obj_reftable>discart</obj_reftable>
  <obj_hashval>980d3cd356ec7cb6726296c7e0af5021</obj_hashval>
  <obj_text>CREATE INDEX idx_discart_coddiscount ON discart USING btree (coddiscount)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_discart_codobiect</obj_name>
  <obj_reftable>discart</obj_reftable>
  <obj_hashval>e1e3988f5d4f002f7fff7f6a83eeb544</obj_hashval>
  <obj_text>CREATE INDEX idx_discart_codobiect ON discart USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_discexceptii_coddiscount</obj_name>
  <obj_reftable>discexceptii</obj_reftable>
  <obj_hashval>61300c983b9fa95dffaf43c5202f5294</obj_hashval>
  <obj_text>CREATE INDEX idx_discexceptii_coddiscount ON discexceptii USING btree (coddiscount)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_discexceptii_codobiect</obj_name>
  <obj_reftable>discexceptii</obj_reftable>
  <obj_hashval>680e3522263d8d472c042274a5b3dbaa</obj_hashval>
  <obj_text>CREATE INDEX idx_discexceptii_codobiect ON discexceptii USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_discinterval_coddiscount</obj_name>
  <obj_reftable>discinterval</obj_reftable>
  <obj_hashval>cfb64e65f53128ea72cd8cbd9bb7c5f0</obj_hashval>
  <obj_text>CREATE INDEX idx_discinterval_coddiscount ON discinterval USING btree (coddiscount)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_discmonetar_codies</obj_name>
  <obj_reftable>discmonetar</obj_reftable>
  <obj_hashval>a68c9ca38459b64948b80ea124f45a00</obj_hashval>
  <obj_text>CREATE INDEX idx_discmonetar_codies ON discmonetar USING btree (codies)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_discount_codcriteriu</obj_name>
  <obj_reftable>discount</obj_reftable>
  <obj_hashval>4d1403ad83e1af13340fd881039daca3</obj_hashval>
  <obj_text>CREATE INDEX idx_discount_codcriteriu ON discount USING btree (codcriteriu)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_distribchelt_subunitatea</obj_name>
  <obj_reftable>distribchelt</obj_reftable>
  <obj_hashval>04fcee1ad55d21d8586b506db1ca9063</obj_hashval>
  <obj_text>CREATE INDEX idx_distribchelt_subunitatea ON distribchelt USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_distribchelt2_cod</obj_name>
  <obj_reftable>distribchelt2</obj_reftable>
  <obj_hashval>71978d0a7f0513da8e06730ed067488d</obj_hashval>
  <obj_text>CREATE INDEX idx_distribchelt2_cod ON distribchelt2 USING btree (coddistribchelt)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_distribchelt2_codgest</obj_name>
  <obj_reftable>distribchelt2</obj_reftable>
  <obj_hashval>4f49d0b7658e5e20581a2ac5c2ded4d7</obj_hashval>
  <obj_text>CREATE INDEX idx_distribchelt2_codgest ON distribchelt2 USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_docasoc_coddoc</obj_name>
  <obj_reftable>docasoc</obj_reftable>
  <obj_hashval>6c978a9b6f3e391f8c1bc60f32c9fcb0</obj_hashval>
  <obj_text>CREATE INDEX idx_docasoc_coddoc ON docasoc USING btree (coddoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_docasoc_coddocasoc</obj_name>
  <obj_reftable>docasoc</obj_reftable>
  <obj_hashval>d33efbda6897a9dea75ab8fd3d576cff</obj_hashval>
  <obj_text>CREATE INDEX idx_docasoc_coddocasoc ON docasoc USING btree (coddocasoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_docasoc_tipdoc</obj_name>
  <obj_reftable>docasoc</obj_reftable>
  <obj_hashval>7c94d3eef099f6287a7661d485adde9a</obj_hashval>
  <obj_text>CREATE INDEX idx_docasoc_tipdoc ON docasoc USING btree (tipdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_docasoc_tipdocasoc</obj_name>
  <obj_reftable>docasoc</obj_reftable>
  <obj_hashval>f6470fab8b12a840f24c561b9ad9f136</obj_hashval>
  <obj_text>CREATE INDEX idx_docasoc_tipdocasoc ON docasoc USING btree (tipdocasoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_doceditat_coddoc</obj_name>
  <obj_reftable>doceditat</obj_reftable>
  <obj_hashval>9694c95ac1a07b3e1e557474d4dee612</obj_hashval>
  <obj_text>CREATE INDEX idx_doceditat_coddoc ON doceditat USING btree (coddoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_doceditat_tabela</obj_name>
  <obj_reftable>doceditat</obj_reftable>
  <obj_hashval>f7411dc2a10ffbf169552ec8788952d1</obj_hashval>
  <obj_text>CREATE INDEX idx_doceditat_tabela ON doceditat USING btree (tabela)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_doceditat_userid</obj_name>
  <obj_reftable>doceditat</obj_reftable>
  <obj_hashval>9e963b609d3361983a0e2a6a429d5376</obj_hashval>
  <obj_text>CREATE INDEX idx_doceditat_userid ON doceditat USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_docfree_codcarnet</obj_name>
  <obj_reftable>docfree</obj_reftable>
  <obj_hashval>d7566bd4804ac136356ec897de881d81</obj_hashval>
  <obj_text>CREATE INDEX idx_docfree_codcarnet ON docfree USING btree (codcarnet, startnr, endnr)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_docfreex_endnr</obj_name>
  <obj_reftable>docfreex</obj_reftable>
  <obj_hashval>fc9e8179856dac651987e644a804d84a</obj_hashval>
  <obj_text>CREATE INDEX idx_docfreex_endnr ON docfreex USING btree (endnr)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_doclink_codcarnet</obj_name>
  <obj_reftable>doclink</obj_reftable>
  <obj_hashval>86533b0412eba04262556d008cfa5482</obj_hashval>
  <obj_text>CREATE INDEX idx_doclink_codcarnet ON doclink USING btree (codcarnet)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_doclock_codcarnet</obj_name>
  <obj_reftable>doclock</obj_reftable>
  <obj_hashval>918cf8bf5b7dcd14a33c2c23292127b4</obj_hashval>
  <obj_text>CREATE INDEX idx_doclock_codcarnet ON doclock USING btree (codcarnet)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_documente_tipdoc</obj_name>
  <obj_reftable>documente</obj_reftable>
  <obj_hashval>ecc2e3f98445de3940eaae6270e5e51d</obj_hashval>
  <obj_text>CREATE INDEX idx_documente_tipdoc ON documente USING btree (tipdoc, coddoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_docusers_codcarnet</obj_name>
  <obj_reftable>docusers</obj_reftable>
  <obj_hashval>b462adccaca2849b9143676b599d8200</obj_hashval>
  <obj_text>CREATE INDEX idx_docusers_codcarnet ON docusers USING btree (codcarnet)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_dprofitc_coddprofit</obj_name>
  <obj_reftable>dprofitc</obj_reftable>
  <obj_hashval>4ebad0681075d9f3e39e3f8cd97bd261</obj_hashval>
  <obj_text>CREATE INDEX idx_dprofitc_coddprofit ON dprofitc USING btree (coddprofit)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_dprofitv_coddprofit</obj_name>
  <obj_reftable>dprofitv</obj_reftable>
  <obj_hashval>2d66b1ed94c0c006feb1e1bf119a1805</obj_hashval>
  <obj_text>CREATE INDEX idx_dprofitv_coddprofit ON dprofitv USING btree (coddprofit)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_dvi_conttva</obj_name>
  <obj_reftable>dvi</obj_reftable>
  <obj_hashval>39051ad5cfb041aa1cd9293e811e29ae</obj_hashval>
  <obj_text>CREATE INDEX idx_dvi_conttva ON dvi USING btree (conttva)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_dvi1_codobiect</obj_name>
  <obj_reftable>dvi1</obj_reftable>
  <obj_hashval>f7611fc435e7616676253259f4478c77</obj_hashval>
  <obj_text>CREATE INDEX idx_dvi1_codobiect ON dvi1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_dvi1_umsec</obj_name>
  <obj_reftable>dvi1</obj_reftable>
  <obj_hashval>68e4f4e2944351404a111d97a726659a</obj_hashval>
  <obj_text>CREATE INDEX idx_dvi1_umsec ON dvi1 USING btree (umsec)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_elembuget1_codelembuget</obj_name>
  <obj_reftable>elembuget1</obj_reftable>
  <obj_hashval>d9e73ac0735e5151cee96e66c71aa564</obj_hashval>
  <obj_text>CREATE INDEX idx_elembuget1_codelembuget ON elembuget1 USING btree (codelembuget)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_elembuget2_codelembuget</obj_name>
  <obj_reftable>elembuget2</obj_reftable>
  <obj_hashval>2484ddce927db5adcaa69faa56c5df54</obj_hashval>
  <obj_text>CREATE INDEX idx_elembuget2_codelembuget ON elembuget2 USING btree (codelembuget)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_emulare_codies</obj_name>
  <obj_reftable>emulare</obj_reftable>
  <obj_hashval>5ee5380c860471335cbc055cf93cce3c</obj_hashval>
  <obj_text>CREATE INDEX idx_emulare_codies ON emulare USING btree (codies)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_emulare_databcodcasa</obj_name>
  <obj_reftable>emulare</obj_reftable>
  <obj_hashval>854e123e0c10325985eeb6662a58a025</obj_hashval>
  <obj_text>CREATE INDEX idx_emulare_databcodcasa ON emulare USING btree (databon, codcasamarcat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_emulare_databon</obj_name>
  <obj_reftable>emulare</obj_reftable>
  <obj_hashval>68b198b2ee2f3c056cfa216ec8a69ebd</obj_hashval>
  <obj_text>CREATE INDEX idx_emulare_databon ON emulare USING btree (databon)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_emulare_facturare</obj_name>
  <obj_reftable>emulare</obj_reftable>
  <obj_hashval>2b79328f58bad825af56c2ecef520308</obj_hashval>
  <obj_text>CREATE INDEX idx_emulare_facturare ON emulare USING btree (facturare)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_emulare_preluat</obj_name>
  <obj_reftable>emulare</obj_reftable>
  <obj_hashval>a63208632b6b47dfaacf56a6f5a71546</obj_hashval>
  <obj_text>CREATE INDEX idx_emulare_preluat ON emulare USING btree (preluat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_emulare1_codemulare</obj_name>
  <obj_reftable>emulare1</obj_reftable>
  <obj_hashval>9b71d329bd87a20f4fe8504075f26428</obj_hashval>
  <obj_text>CREATE INDEX idx_emulare1_codemulare ON emulare1 USING btree (codemulare)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_emulare1_codgest</obj_name>
  <obj_reftable>emulare1</obj_reftable>
  <obj_hashval>4a80a54d3fbb56338e13f2fd8bca8f56</obj_hashval>
  <obj_text>CREATE INDEX idx_emulare1_codgest ON emulare1 USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_emulare1_codioart</obj_name>
  <obj_reftable>emulare1</obj_reftable>
  <obj_hashval>d0ca148a07178c71e5840ec1bca89b98</obj_hashval>
  <obj_text>CREATE INDEX idx_emulare1_codioart ON emulare1 USING btree (codioart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_emulare1_codobiect</obj_name>
  <obj_reftable>emulare1</obj_reftable>
  <obj_hashval>6013cc4a4e1beaafd29078c9f9c1ae60</obj_hashval>
  <obj_text>CREATE INDEX idx_emulare1_codobiect ON emulare1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_emulare1_pretnirstoc</obj_name>
  <obj_reftable>emulare1</obj_reftable>
  <obj_hashval>c64ce2d955947879de3015d12f1fbbe3</obj_hashval>
  <obj_text>CREATE INDEX idx_emulare1_pretnirstoc ON emulare1 USING btree (pretnirstoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_emulare2_codemulare</obj_name>
  <obj_reftable>emulare2</obj_reftable>
  <obj_hashval>c3b711eece1c5cc4003a529d2219348a</obj_hashval>
  <obj_text>CREATE INDEX idx_emulare2_codemulare ON emulare2 USING btree (codemulare)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_an</obj_name>
  <obj_reftable>estimarinod</obj_reftable>
  <obj_hashval>e90d19c3373a5c3b8743faf4b8ccb0dd</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_an ON estimarinod USING btree (an)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_c1_codestprod</obj_name>
  <obj_reftable>estimarinod_c1</obj_reftable>
  <obj_hashval>4154592ed156f3a0c020e9f7658e630d</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_c1_codestprod ON estimarinod_c1 USING btree (codestimareprod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_c1_codestprod1</obj_name>
  <obj_reftable>estimarinod_c1</obj_reftable>
  <obj_hashval>4aae3d497fcddfda159c2faa0b2d76ee</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_c1_codestprod1 ON estimarinod_c1 USING btree (codestimareprod1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_c1_codobiect</obj_name>
  <obj_reftable>estimarinod_c1</obj_reftable>
  <obj_hashval>9d51679917f329084aed1faae0a3c7b7</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_c1_codobiect ON estimarinod_c1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_c1_codprodmat</obj_name>
  <obj_reftable>estimarinod_c1</obj_reftable>
  <obj_hashval>77a9117f5724a9e01a6aa87ea00ca5af</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_c1_codprodmat ON estimarinod_c1 USING btree (codprodmat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_c1_codreteta</obj_name>
  <obj_reftable>estimarinod_c1</obj_reftable>
  <obj_hashval>9d747110ef72b188b3f998d982b983b7</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_c1_codreteta ON estimarinod_c1 USING btree (codreteta)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_c1_nodoriginal</obj_name>
  <obj_reftable>estimarinod_c1</obj_reftable>
  <obj_hashval>c510a95adcd94999969ed0b486e3295f</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_c1_nodoriginal ON estimarinod_c1 USING btree (nodoriginal)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_c1_tip</obj_name>
  <obj_reftable>estimarinod_c1</obj_reftable>
  <obj_hashval>42f0c67bd460560a19e81a0c0dbec55b</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_c1_tip ON estimarinod_c1 USING btree (tip)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_c2_codestprod</obj_name>
  <obj_reftable>estimarinod_c2</obj_reftable>
  <obj_hashval>bd2441104ec20f3dea5af3fce96e1cb7</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_c2_codestprod ON estimarinod_c2 USING btree (codestimareprod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_c2_codestprod1</obj_name>
  <obj_reftable>estimarinod_c2</obj_reftable>
  <obj_hashval>e97323acfeb4a27662c01af74d736d0a</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_c2_codestprod1 ON estimarinod_c2 USING btree (codestimareprod1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_c2_codobiect</obj_name>
  <obj_reftable>estimarinod_c2</obj_reftable>
  <obj_hashval>e827943dd0bd053b96ca2fd17f14e77b</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_c2_codobiect ON estimarinod_c2 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_c2_codprodmat</obj_name>
  <obj_reftable>estimarinod_c2</obj_reftable>
  <obj_hashval>f59960877dc95246d3a86458dbfb42c5</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_c2_codprodmat ON estimarinod_c2 USING btree (codprodmat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_c2_codreteta</obj_name>
  <obj_reftable>estimarinod_c2</obj_reftable>
  <obj_hashval>93a2e8cfb286e8b847863e6a6fa63d63</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_c2_codreteta ON estimarinod_c2 USING btree (codreteta)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_c2_nodoriginal</obj_name>
  <obj_reftable>estimarinod_c2</obj_reftable>
  <obj_hashval>cfb5402fcb4e182384757eaa3df2a186</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_c2_nodoriginal ON estimarinod_c2 USING btree (nodoriginal)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_c2_tip</obj_name>
  <obj_reftable>estimarinod_c2</obj_reftable>
  <obj_hashval>ec8036d0823c3b3b3c0050238be8307c</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_c2_tip ON estimarinod_c2 USING btree (tip)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_codestprod</obj_name>
  <obj_reftable>estimarinod</obj_reftable>
  <obj_hashval>1455e6e0a6f3e05403dc3b78530699b2</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_codestprod ON estimarinod USING btree (codestimareprod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_codestprod1</obj_name>
  <obj_reftable>estimarinod</obj_reftable>
  <obj_hashval>35e795100bed52b043a5b8c80ad5bdf8</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_codestprod1 ON estimarinod USING btree (codestimareprod1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_codobiect</obj_name>
  <obj_reftable>estimarinod</obj_reftable>
  <obj_hashval>eddf93215b8f9c587299949ff9a8a0b7</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_codobiect ON estimarinod USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_codprodmat</obj_name>
  <obj_reftable>estimarinod</obj_reftable>
  <obj_hashval>a1d44cf45a658019a94ffd199377df8a</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_codprodmat ON estimarinod USING btree (codprodmat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_codreteta</obj_name>
  <obj_reftable>estimarinod</obj_reftable>
  <obj_hashval>1116113ff374aaa61f9c28f3d900805c</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_codreteta ON estimarinod USING btree (codreteta)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_nodoriginal</obj_name>
  <obj_reftable>estimarinod</obj_reftable>
  <obj_hashval>0bdc55ec5fd5ba248f56bb5b48b13d56</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_nodoriginal ON estimarinod USING btree (nodoriginal)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_saptamana</obj_name>
  <obj_reftable>estimarinod</obj_reftable>
  <obj_hashval>80e62e10f49e337ffae4f2ec73f29562</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_saptamana ON estimarinod USING btree (saptamana)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estimarinod_tip</obj_name>
  <obj_reftable>estimarinod</obj_reftable>
  <obj_hashval>0c1767f4be9dd68afc5433303a8daafc</obj_hashval>
  <obj_text>CREATE INDEX idx_estimarinod_tip ON estimarinod USING btree (tip)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estprod1m_codestimareprod</obj_name>
  <obj_reftable>estimariprod1m</obj_reftable>
  <obj_hashval>b0d35ed7211d5ccc65d5488f6c9545e9</obj_hashval>
  <obj_text>CREATE INDEX idx_estprod1m_codestimareprod ON estimariprod1m USING btree (codestimareprod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estprod1m_codobiect</obj_name>
  <obj_reftable>estimariprod1m</obj_reftable>
  <obj_hashval>da15903eec78e18fc96716327259b094</obj_hashval>
  <obj_text>CREATE INDEX idx_estprod1m_codobiect ON estimariprod1m USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estprod1n_codestprod</obj_name>
  <obj_reftable>estimariprod1n</obj_reftable>
  <obj_hashval>0e3a661fb8c93df62682667c55119fac</obj_hashval>
  <obj_text>CREATE INDEX idx_estprod1n_codestprod ON estimariprod1n USING btree (codestimareprod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_estprod1n_codobiect</obj_name>
  <obj_reftable>estimariprod1n</obj_reftable>
  <obj_hashval>88556512f3ce4c77bf134c9592945638</obj_hashval>
  <obj_text>CREATE INDEX idx_estprod1n_codobiect ON estimariprod1n USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_factsalink_codclasea</obj_name>
  <obj_reftable>factsalink</obj_reftable>
  <obj_hashval>4afdc22309638d4a2643e1e20bdc1866</obj_hashval>
  <obj_text>CREATE INDEX idx_factsalink_codclasea ON factsalink USING btree (codclasea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_factsalink_codcomanda</obj_name>
  <obj_reftable>factsalink</obj_reftable>
  <obj_hashval>424103bab55ae6cdd4a14a3976502699</obj_hashval>
  <obj_text>CREATE INDEX idx_factsalink_codcomanda ON factsalink USING btree (codcomanda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_fisamf_codmifix</obj_name>
  <obj_reftable>fisamf</obj_reftable>
  <obj_hashval>76dc37318823eab53a61252fdb6c51cc</obj_hashval>
  <obj_text>CREATE INDEX idx_fisamf_codmifix ON fisamf USING btree (codmifix)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_fisamf_codoperatie</obj_name>
  <obj_reftable>fisamf</obj_reftable>
  <obj_hashval>3c828832baea5716c229e437b1b9fd26</obj_hashval>
  <obj_text>CREATE INDEX idx_fisamf_codoperatie ON fisamf USING btree (codoperatie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_fisamf_tipdoc</obj_name>
  <obj_reftable>fisamf</obj_reftable>
  <obj_hashval>19c02cb0402a5d48ccaef7cc0560aa2e</obj_hashval>
  <obj_text>CREATE INDEX idx_fisamf_tipdoc ON fisamf USING btree (tipdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_fuzart</obj_name>
  <obj_reftable>fuzart</obj_reftable>
  <obj_hashval>13a0fd4696a9dabd0c05c2beefc202e9</obj_hashval>
  <obj_text>CREATE INDEX idx_fuzart ON fuzart USING btree (userid, userstr, data)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gantt_codcmdprodman</obj_name>
  <obj_reftable>gantt</obj_reftable>
  <obj_hashval>6e0b2e2400c77294ba091b42134326b6</obj_hashval>
  <obj_text>CREATE INDEX idx_gantt_codcmdprodman ON gantt USING btree (codcmdprodman)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gantt_codcomanda1</obj_name>
  <obj_reftable>gantt</obj_reftable>
  <obj_hashval>6d1043c0a7885be7d9d3bf1c9bfcd8db</obj_hashval>
  <obj_text>CREATE INDEX idx_gantt_codcomanda1 ON gantt USING btree (codcomanda1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gantt_codgantt</obj_name>
  <obj_reftable>gantt1</obj_reftable>
  <obj_hashval>bee34fb10f83f96fd6f2ceeb7311ed9c</obj_hashval>
  <obj_text>CREATE INDEX idx_gantt_codgantt ON gantt1 USING btree (codgantt)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gc_anluna</obj_name>
  <obj_reftable>tmp_manevra_intr1_grupc</obj_reftable>
  <obj_hashval>e12c6c344bdcecc24835d845749d4354</obj_hashval>
  <obj_text>CREATE INDEX idx_gc_anluna ON tmp_manevra_intr1_grupc USING btree (anluna)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gc_cod_mat</obj_name>
  <obj_reftable>tmp_manevra_intr1_grupc</obj_reftable>
  <obj_hashval>d66aab84cfd5ac8669f6488d9bc759f8</obj_hashval>
  <obj_text>CREATE INDEX idx_gc_cod_mat ON tmp_manevra_intr1_grupc USING btree (codcmdprodmat_mat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gc_codcmdprodmat</obj_name>
  <obj_reftable>tmp_manevra_intr1_grupc</obj_reftable>
  <obj_hashval>64a64f7f2f5c7fceea1c2d9b35779ce1</obj_hashval>
  <obj_text>CREATE INDEX idx_gc_codcmdprodmat ON tmp_manevra_intr1_grupc USING btree (codcmdprodmat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gc_coddoc</obj_name>
  <obj_reftable>tmp_manevra_intr1_grupc</obj_reftable>
  <obj_hashval>ab2668d74f01972cfc10c32c49d8a01b</obj_hashval>
  <obj_text>CREATE INDEX idx_gc_coddoc ON tmp_manevra_intr1_grupc USING btree (coddoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gc_codobiect</obj_name>
  <obj_reftable>tmp_manevra_intr1_grupc</obj_reftable>
  <obj_hashval>930c58fdc1a418455d62899e1f354e3e</obj_hashval>
  <obj_text>CREATE INDEX idx_gc_codobiect ON tmp_manevra_intr1_grupc USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gc_codobiectorig</obj_name>
  <obj_reftable>tmp_manevra_intr1_grupc</obj_reftable>
  <obj_hashval>09e90345b41a7244bad4d0373dd81485</obj_hashval>
  <obj_text>CREATE INDEX idx_gc_codobiectorig ON tmp_manevra_intr1_grupc USING btree (codobiectorig)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gc_codsemi</obj_name>
  <obj_reftable>tmp_manevra_intr1_grupc</obj_reftable>
  <obj_hashval>ce1c64e30e90e13e9d9e3229ede3aad6</obj_hashval>
  <obj_text>CREATE INDEX idx_gc_codsemi ON tmp_manevra_intr1_grupc USING btree (codcmdprodmat_semi)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gc_cont</obj_name>
  <obj_reftable>tmp_manevra_intr1_grupc</obj_reftable>
  <obj_hashval>bd18f3596046cb3a2d1548566fad18a7</obj_hashval>
  <obj_text>CREATE INDEX idx_gc_cont ON tmp_manevra_intr1_grupc USING btree (cont)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gc_gestiune</obj_name>
  <obj_reftable>tmp_manevra_intr1_grupc</obj_reftable>
  <obj_hashval>3c0527d1a5ab8eafb8b50aa840113ea3</obj_hashval>
  <obj_text>CREATE INDEX idx_gc_gestiune ON tmp_manevra_intr1_grupc USING btree (gestiune)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gc_nsconsum</obj_name>
  <obj_reftable>tmp_manevra_intr1_grupc</obj_reftable>
  <obj_hashval>8f7a1d40ecb191e79c153446feb0abc3</obj_hashval>
  <obj_text>CREATE INDEX idx_gc_nsconsum ON tmp_manevra_intr1_grupc USING btree (codnirstocconsum)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gc_tipdoc</obj_name>
  <obj_reftable>tmp_manevra_intr1_grupc</obj_reftable>
  <obj_hashval>f3d7b6f7adc53cbd910d7a77c155d706</obj_hashval>
  <obj_text>CREATE INDEX idx_gc_tipdoc ON tmp_manevra_intr1_grupc USING btree (tipdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gc_tiplinie</obj_name>
  <obj_reftable>tmp_manevra_intr1_grupc</obj_reftable>
  <obj_hashval>e0db9655b7fb12c190b3fe25db37fd8b</obj_hashval>
  <obj_text>CREATE INDEX idx_gc_tiplinie ON tmp_manevra_intr1_grupc USING btree (tiplinie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_general_datatva</obj_name>
  <obj_reftable>general</obj_reftable>
  <obj_hashval>ecb63d63f327cdeb4c8f53abb3b95a7a</obj_hashval>
  <obj_text>CREATE INDEX idx_general_datatva ON general USING btree (datatva)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_general_moneda</obj_name>
  <obj_reftable>general</obj_reftable>
  <obj_hashval>78d69f28477d0ccbb64a4edd990b77d2</obj_hashval>
  <obj_text>CREATE INDEX idx_general_moneda ON general USING btree (moneda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_general_tipcodsemnificatie</obj_name>
  <obj_reftable>general</obj_reftable>
  <obj_hashval>1ac35677ccfa7aeca3cdcab95a2282f8</obj_hashval>
  <obj_text>CREATE INDEX idx_general_tipcodsemnificatie ON general USING btree (tipdoc, coddoc, semnificatie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gl_anluna</obj_name>
  <obj_reftable>tmp_manevra_intr1_grupl</obj_reftable>
  <obj_hashval>614a0817388e8ae125654c2a32466411</obj_hashval>
  <obj_text>CREATE INDEX idx_gl_anluna ON tmp_manevra_intr1_grupl USING btree (anluna)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gl_codcmdprodmat</obj_name>
  <obj_reftable>tmp_manevra_intr1_grupl</obj_reftable>
  <obj_hashval>db580ebd94af4552f8adea39af86b774</obj_hashval>
  <obj_text>CREATE INDEX idx_gl_codcmdprodmat ON tmp_manevra_intr1_grupl USING btree (codcmdprodmat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gnpcmd1_codcomanda1</obj_name>
  <obj_reftable>tmp_gennp_cmd1</obj_reftable>
  <obj_hashval>d81d2574a8370c17b879486c16efc632</obj_hashval>
  <obj_text>CREATE INDEX idx_gnpcmd1_codcomanda1 ON tmp_gennp_cmd1 USING btree (codcomanda1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gnpcmd1_codgest</obj_name>
  <obj_reftable>tmp_gennp_cmd1</obj_reftable>
  <obj_hashval>a8038f4992293b94777f9e4d9e501a5b</obj_hashval>
  <obj_text>CREATE INDEX idx_gnpcmd1_codgest ON tmp_gennp_cmd1 USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gnpcmd1_codpers</obj_name>
  <obj_reftable>tmp_gennp_cmd1</obj_reftable>
  <obj_hashval>016ba8051e1a346ee923db8625b8ccbe</obj_hashval>
  <obj_text>CREATE INDEX idx_gnpcmd1_codpers ON tmp_gennp_cmd1 USING btree (codpers)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gnpcmd1_codprogramf1</obj_name>
  <obj_reftable>tmp_gennp_cmd1</obj_reftable>
  <obj_hashval>661a6d404b5789f60c0c9cc8c16a2b69</obj_hashval>
  <obj_text>CREATE INDEX idx_gnpcmd1_codprogramf1 ON tmp_gennp_cmd1 USING btree (codprogramf1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gnpcmd1_userid</obj_name>
  <obj_reftable>tmp_gennp_cmd1</obj_reftable>
  <obj_hashval>c0965df6960203c48b36e90b8c49856a</obj_hashval>
  <obj_text>CREATE INDEX idx_gnpcmd1_userid ON tmp_gennp_cmd1 USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gnpcrs_codcmdprodmat</obj_name>
  <obj_reftable>tmp_gennp_crs</obj_reftable>
  <obj_hashval>75c8cd68693d5d8e2a547bc9cfc3478d</obj_hashval>
  <obj_text>CREATE INDEX idx_gnpcrs_codcmdprodmat ON tmp_gennp_crs USING btree (codcmdprodmat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gnpcrs_codobiect</obj_name>
  <obj_reftable>tmp_gennp_crs</obj_reftable>
  <obj_hashval>7105c016d0c8b88c0baeb03101a58fea</obj_hashval>
  <obj_text>CREATE INDEX idx_gnpcrs_codobiect ON tmp_gennp_crs USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gnpcrs_codprogramf1</obj_name>
  <obj_reftable>tmp_gennp_crs</obj_reftable>
  <obj_hashval>a2778a47c8ea6a1b9e4043f379533b0c</obj_hashval>
  <obj_text>CREATE INDEX idx_gnpcrs_codprogramf1 ON tmp_gennp_crs USING btree (codprogramf1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gnpcrs_tip</obj_name>
  <obj_reftable>tmp_gennp_crs</obj_reftable>
  <obj_hashval>3ebb8fd030c7686dc000bccefa5dbc17</obj_hashval>
  <obj_text>CREATE INDEX idx_gnpcrs_tip ON tmp_gennp_crs USING btree (tip)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gnpcrs_userid</obj_name>
  <obj_reftable>tmp_gennp_crs</obj_reftable>
  <obj_hashval>466b52023e149b7f2fa9d64fa5dea4fc</obj_hashval>
  <obj_text>CREATE INDEX idx_gnpcrs_userid ON tmp_gennp_crs USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gnpman_codcmdprodman</obj_name>
  <obj_reftable>tmp_gennp_cmdman</obj_reftable>
  <obj_hashval>ca87368e210db71704af433bb1f5d5b2</obj_hashval>
  <obj_text>CREATE INDEX idx_gnpman_codcmdprodman ON tmp_gennp_cmdman USING btree (codcmdprodman)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_gnpman_userid</obj_name>
  <obj_reftable>tmp_gennp_cmdman</obj_reftable>
  <obj_hashval>7802b13e7e2d0644a081a64a2cbd8a75</obj_hashval>
  <obj_text>CREATE INDEX idx_gnpman_userid ON tmp_gennp_cmdman USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri</obj_name>
  <obj_reftable>iesiri</obj_reftable>
  <obj_hashval>6d2a23d033654b52399a547a8360c6ad</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri ON iesiri USING btree (an, luna, operat, anulat, tipdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri_anluna</obj_name>
  <obj_reftable>iesiri</obj_reftable>
  <obj_hashval>5dfb45404d0fe35a895b9b8cb2e4e702</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri_anluna ON iesiri USING btree ((((an * (12)::numeric) + luna)))</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri_codlocatie</obj_name>
  <obj_reftable>iesiri</obj_reftable>
  <obj_hashval>9e850790cc5adc724f847a0946d1b33f</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri_codlocatie ON iesiri USING btree (codlocatie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri_codmonetar</obj_name>
  <obj_reftable>iesiri</obj_reftable>
  <obj_hashval>f1f9d9cc6851a858f8ad9d922b24c578</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri_codmonetar ON iesiri USING btree (codmonetar)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri_codsubunit</obj_name>
  <obj_reftable>iesiri</obj_reftable>
  <obj_hashval>7f3040c1d59e62b9aac6cc65055dd4b8</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri_codsubunit ON iesiri USING btree (codsubunit)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri_contdiscount</obj_name>
  <obj_reftable>iesiri</obj_reftable>
  <obj_hashval>2bc6c0c316de05f230a2a8efa3f4a1e1</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri_contdiscount ON iesiri USING btree (contdiscount)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri_contintermed</obj_name>
  <obj_reftable>iesiri</obj_reftable>
  <obj_hashval>6dabfc242bd39e618aa0e92312cfba36</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri_contintermed ON iesiri USING btree (contintermed)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri_datadoc</obj_name>
  <obj_reftable>iesiri</obj_reftable>
  <obj_hashval>e658921d57e58ce7b8f06fd42f11bd04</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri_datadoc ON iesiri USING btree (datadoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri_nrdoc</obj_name>
  <obj_reftable>iesiri</obj_reftable>
  <obj_hashval>64000589140d9911bd9ae979b167e84a</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri_nrdoc ON iesiri USING btree (nrdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri_partener</obj_name>
  <obj_reftable>iesiri</obj_reftable>
  <obj_hashval>383de0affaf9e4e363f2fb0f23814c9e</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri_partener ON iesiri USING btree (partener)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri_seriadoc</obj_name>
  <obj_reftable>iesiri</obj_reftable>
  <obj_hashval>197acb5b29ec95e05b47a7719000dbe4</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri_seriadoc ON iesiri USING btree (seriadoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri_subunitatea</obj_name>
  <obj_reftable>iesiri</obj_reftable>
  <obj_hashval>f8aea75accc687fd745727bdddaa0097</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri_subunitatea ON iesiri USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri_tipdoc</obj_name>
  <obj_reftable>iesiri</obj_reftable>
  <obj_hashval>3169124faab8685e270119d006d020c9</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri_tipdoc ON iesiri USING btree (tipdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri1_codcmdint1</obj_name>
  <obj_reftable>iesiri1</obj_reftable>
  <obj_hashval>32cc738d15735cbdc102d76fb4f80133</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri1_codcmdint1 ON iesiri1 USING btree (codcmdint1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri1_codies</obj_name>
  <obj_reftable>iesiri1</obj_reftable>
  <obj_hashval>dd5eebbd52af0a923bee588f4b1ba117</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri1_codies ON iesiri1 USING btree (codies)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri1_codies1storno</obj_name>
  <obj_reftable>iesiri1</obj_reftable>
  <obj_hashval>c393608401fbf45a5beea988e907ebb8</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri1_codies1storno ON iesiri1 USING btree (codies1storno)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri1_codliniedocimp</obj_name>
  <obj_reftable>iesiri1</obj_reftable>
  <obj_hashval>bd893d71636312dd95c8bf48f9848811</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri1_codliniedocimp ON iesiri1 USING btree (codliniedocimp, tipdocimp)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri1_codobiect</obj_name>
  <obj_reftable>iesiri1</obj_reftable>
  <obj_hashval>c16db965ddaee7183d310428de8cad1a</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri1_codobiect ON iesiri1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri1_cont</obj_name>
  <obj_reftable>iesiri1</obj_reftable>
  <obj_hashval>a58cf1ba6a7a3cd79577d67881bd902c</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri1_cont ON iesiri1 USING btree (cont)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri1_contserv</obj_name>
  <obj_reftable>iesiri1</obj_reftable>
  <obj_hashval>2928bf42ff53fef3d226767d42477b3e</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri1_contserv ON iesiri1 USING btree (contserv)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri1_restfact</obj_name>
  <obj_reftable>iesiri1</obj_reftable>
  <obj_hashval>12fda8e20a0678ea942faaf44c10c631</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri1_restfact ON iesiri1 USING btree (restfact)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri1_umsec</obj_name>
  <obj_reftable>iesiri1</obj_reftable>
  <obj_hashval>584f6bf009a063ff51bb61dc9fb6907e</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri1_umsec ON iesiri1 USING btree (umsec)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri1retail_codiesretail</obj_name>
  <obj_reftable>iesiri1retail</obj_reftable>
  <obj_hashval>798f52d9d116d3cd657b3503ddfdf691</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri1retail_codiesretail ON iesiri1retail USING btree (codiesretail)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri1retail_codobiect</obj_name>
  <obj_reftable>iesiri1retail</obj_reftable>
  <obj_hashval>d9661997fd402e6901683c9f39261dd0</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri1retail_codobiect ON iesiri1retail USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri1retail_cont</obj_name>
  <obj_reftable>iesiri1retail</obj_reftable>
  <obj_hashval>e6cdf6622fd3544d7f99108e1d2e7439</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri1retail_cont ON iesiri1retail USING btree (cont)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri1retail_contserv</obj_name>
  <obj_reftable>iesiri1retail</obj_reftable>
  <obj_hashval>6bdd27a57bffbf5eb84bfabfe72ab832</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri1retail_contserv ON iesiri1retail USING btree (contserv)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiri1retail_umsec</obj_name>
  <obj_reftable>iesiri1retail</obj_reftable>
  <obj_hashval>4ddea4eb747148e07c4cbdaa40c6bfa0</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiri1retail_umsec ON iesiri1retail USING btree (umsec)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiriretail_anluna</obj_name>
  <obj_reftable>iesiriretail</obj_reftable>
  <obj_hashval>b7626e404dff684b33978ead4d83a5ad</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiriretail_anluna ON iesiriretail USING btree ((((an * (12)::numeric) + luna)))</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiriretail_anulat</obj_name>
  <obj_reftable>iesiriretail</obj_reftable>
  <obj_hashval>9f0fb93f200ad9ab3fa7a9404c303794</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiriretail_anulat ON iesiriretail USING btree (anulat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiriretail_codies</obj_name>
  <obj_reftable>iesiriretail</obj_reftable>
  <obj_hashval>20ea6da3dcd48b32305320f3bbf42d7d</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiriretail_codies ON iesiriretail USING btree (codies)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiriretail_codsediu</obj_name>
  <obj_reftable>iesiriretail</obj_reftable>
  <obj_hashval>27a346e65480cdf8bbecdcff845e9568</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiriretail_codsediu ON iesiriretail USING btree (codsediuretail)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiriretail_nrdoc</obj_name>
  <obj_reftable>iesiriretail</obj_reftable>
  <obj_hashval>bc141e69068514824a76368ef9926815</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiriretail_nrdoc ON iesiriretail USING btree (nrdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiriretail_operat</obj_name>
  <obj_reftable>iesiriretail</obj_reftable>
  <obj_hashval>a84a2574c788d0ac3dc4fb0f2c3ea182</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiriretail_operat ON iesiriretail USING btree (operat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiriretail_partener</obj_name>
  <obj_reftable>iesiriretail</obj_reftable>
  <obj_hashval>880a7ee057c9a9afa9ac5f993bca2950</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiriretail_partener ON iesiriretail USING btree (codpartretail)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiriretail_seriadoc</obj_name>
  <obj_reftable>iesiriretail</obj_reftable>
  <obj_hashval>dc7758400720c12e866a2a672d1bcfea</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiriretail_seriadoc ON iesiriretail USING btree (seriadoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiriretail_subunitatea</obj_name>
  <obj_reftable>iesiriretail</obj_reftable>
  <obj_hashval>3303f3ed6161d23c348cbedf78455aa7</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiriretail_subunitatea ON iesiriretail USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iesiriretail_tipdoc</obj_name>
  <obj_reftable>iesiriretail</obj_reftable>
  <obj_hashval>cae7530cdf83331e1281441f7a51c832</obj_hashval>
  <obj_text>CREATE INDEX idx_iesiriretail_tipdoc ON iesiriretail USING btree (tipdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ieslink_codlinieaviz</obj_name>
  <obj_reftable>ieslink</obj_reftable>
  <obj_hashval>8d67e8bddadf672a01bd20a65e9994a4</obj_hashval>
  <obj_text>CREATE INDEX idx_ieslink_codlinieaviz ON ieslink USING btree (codlinieaviz)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ieslink_codliniecomanda</obj_name>
  <obj_reftable>ieslink</obj_reftable>
  <obj_hashval>6d99e0802a8558fced49fba6a96757c5</obj_hashval>
  <obj_text>CREATE INDEX idx_ieslink_codliniecomanda ON ieslink USING btree (codliniecomanda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iespuncte_codies</obj_name>
  <obj_reftable>iespuncte</obj_reftable>
  <obj_hashval>be2da71ca178cd73efcbf6d1b7231008</obj_hashval>
  <obj_text>CREATE INDEX idx_iespuncte_codies ON iespuncte USING btree (codies)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_inactivretail_codobiect</obj_name>
  <obj_reftable>inactivretail</obj_reftable>
  <obj_hashval>b4864b0bb9f8b19b40cf61e599c017f7</obj_hashval>
  <obj_text>CREATE INDEX idx_inactivretail_codobiect ON inactivretail USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_inactivretail_postretail</obj_name>
  <obj_reftable>inactivretail</obj_reftable>
  <obj_hashval>62b563da1e01cc620d5ede4bfb83b936</obj_hashval>
  <obj_text>CREATE INDEX idx_inactivretail_postretail ON inactivretail USING btree (codpostretail)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_interfataklg_idmesaj</obj_name>
  <obj_reftable>interfataklg</obj_reftable>
  <obj_hashval>c95047c0ec04ecc2b8bee3015fcb758c</obj_hashval>
  <obj_text>CREATE INDEX idx_interfataklg_idmesaj ON interfataklg USING btree (idmesaj)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_intrari</obj_name>
  <obj_reftable>intrari</obj_reftable>
  <obj_hashval>c8f1ea59289c0e1900a605d71309a7dd</obj_hashval>
  <obj_text>CREATE INDEX idx_intrari ON intrari USING btree (an, luna, operat, anulat, tipdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_intrari_anluna</obj_name>
  <obj_reftable>intrari</obj_reftable>
  <obj_hashval>04eb8c1d02ac28da8afa592ab56f2a9f</obj_hashval>
  <obj_text>CREATE INDEX idx_intrari_anluna ON intrari USING btree ((((an * (12)::numeric) + luna)))</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_intrari_codlocatie</obj_name>
  <obj_reftable>intrari</obj_reftable>
  <obj_hashval>b12f264b38c78d89493eed474d6a6cda</obj_hashval>
  <obj_text>CREATE INDEX idx_intrari_codlocatie ON intrari USING btree (codlocatie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_intrari_codsubunit</obj_name>
  <obj_reftable>intrari</obj_reftable>
  <obj_hashval>75ce589fb5a0c5a0431370d33ce46fb1</obj_hashval>
  <obj_text>CREATE INDEX idx_intrari_codsubunit ON intrari USING btree (codsubunit)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_intrari_contsuplim</obj_name>
  <obj_reftable>intrari</obj_reftable>
  <obj_hashval>291f69ea163482257c0f25b7717ad47c</obj_hashval>
  <obj_text>CREATE INDEX idx_intrari_contsuplim ON intrari USING btree (contsuplim)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_intrari_datadoc</obj_name>
  <obj_reftable>intrari</obj_reftable>
  <obj_hashval>74e2ba3d3adb6d4781ac890e9b9247e1</obj_hashval>
  <obj_text>CREATE INDEX idx_intrari_datadoc ON intrari USING btree (datadoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_intrari_iddescarcare</obj_name>
  <obj_reftable>intrari</obj_reftable>
  <obj_hashval>e6f40fccfc653ca56376dd377c272cdc</obj_hashval>
  <obj_text>CREATE INDEX idx_intrari_iddescarcare ON intrari USING btree (iddescarcare)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_intrari_partener</obj_name>
  <obj_reftable>intrari</obj_reftable>
  <obj_hashval>4f9c881b1d97dd0fa1fec3c93502a1ca</obj_hashval>
  <obj_text>CREATE INDEX idx_intrari_partener ON intrari USING btree (partener)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_intrari_subunitatea</obj_name>
  <obj_reftable>intrari</obj_reftable>
  <obj_hashval>069e902722c4332c1c1826fafa2dc686</obj_hashval>
  <obj_text>CREATE INDEX idx_intrari_subunitatea ON intrari USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_intrari_tipdoc</obj_name>
  <obj_reftable>intrari</obj_reftable>
  <obj_hashval>0cb311613501592a123371dab9a4c417</obj_hashval>
  <obj_text>CREATE INDEX idx_intrari_tipdoc ON intrari USING btree (tipdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_intrari1_codcmdint1</obj_name>
  <obj_reftable>intrari1</obj_reftable>
  <obj_hashval>eb0bc560c7d559d1b50b04d49a81ffdb</obj_hashval>
  <obj_text>CREATE INDEX idx_intrari1_codcmdint1 ON intrari1 USING btree (codcmdint1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_intrari1_codintr</obj_name>
  <obj_reftable>intrari1</obj_reftable>
  <obj_hashval>774d6f1382a0f0aed377e7c9309c2dde</obj_hashval>
  <obj_text>CREATE INDEX idx_intrari1_codintr ON intrari1 USING btree (codintr)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_intrari1_codintr1storno</obj_name>
  <obj_reftable>intrari1</obj_reftable>
  <obj_hashval>0f46604027898d755ecdde8859b96aec</obj_hashval>
  <obj_text>CREATE INDEX idx_intrari1_codintr1storno ON intrari1 USING btree (codintr1storno)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_intrari1_codobiect</obj_name>
  <obj_reftable>intrari1</obj_reftable>
  <obj_hashval>1cb976ae6b25d23b54477e7f58effb21</obj_hashval>
  <obj_text>CREATE INDEX idx_intrari1_codobiect ON intrari1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_intrari1_contserv</obj_name>
  <obj_reftable>intrari1</obj_reftable>
  <obj_hashval>526499551b59bde8ebeef41badf9c1d6</obj_hashval>
  <obj_text>CREATE INDEX idx_intrari1_contserv ON intrari1 USING btree (contserv)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_intrari1_umsec</obj_name>
  <obj_reftable>intrari1</obj_reftable>
  <obj_hashval>8b6bbf8949d721a202f23bdf17230e52</obj_hashval>
  <obj_text>CREATE INDEX idx_intrari1_umsec ON intrari1 USING btree (umsec)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_intrlink_codlinieaviz</obj_name>
  <obj_reftable>intrlink</obj_reftable>
  <obj_hashval>a51c14e9ba45e16cf6fdfc947232a084</obj_hashval>
  <obj_text>CREATE INDEX idx_intrlink_codlinieaviz ON intrlink USING btree (codlinieaviz)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_intrlink_codliniecomanda</obj_name>
  <obj_reftable>intrlink</obj_reftable>
  <obj_hashval>03dd4eb9cd7da1c1e7eda5ece5cc5853</obj_hashval>
  <obj_text>CREATE INDEX idx_intrlink_codliniecomanda ON intrlink USING btree (codliniecomanda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_inventar1_codinventar</obj_name>
  <obj_reftable>inventar1</obj_reftable>
  <obj_hashval>a8cf339a7532348ca8c83a8a77ad8f9f</obj_hashval>
  <obj_text>CREATE INDEX idx_inventar1_codinventar ON inventar1 USING btree (codinventar)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_inventstoc_codinventar</obj_name>
  <obj_reftable>inventstoc</obj_reftable>
  <obj_hashval>4eeb326504d1a762d99c5173fd866ad9</obj_hashval>
  <obj_text>CREATE INDEX idx_inventstoc_codinventar ON inventstoc USING btree (codinventar)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ioart1_al</obj_name>
  <obj_reftable>ioart1</obj_reftable>
  <obj_hashval>39acfc684e3e70e55635e5d3c94a1953</obj_hashval>
  <obj_text>CREATE INDEX idx_ioart1_al ON ioart1 USING btree (codioart, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ioart1_anluna</obj_name>
  <obj_reftable>ioart1</obj_reftable>
  <obj_hashval>c4429b693c2b9158c500472e886403f1</obj_hashval>
  <obj_text>CREATE INDEX idx_ioart1_anluna ON ioart1 USING btree ((((anstart * (12)::numeric) + lunastart)))</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ioart1_chelttvacolectat</obj_name>
  <obj_reftable>ioart1</obj_reftable>
  <obj_hashval>f7547748f5c190a2e0d33327227cd01b</obj_hashval>
  <obj_text>CREATE INDEX idx_ioart1_chelttvacolectat ON ioart1 USING btree (chelttvacolectat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ioart1_cheltuieli</obj_name>
  <obj_reftable>ioart1</obj_reftable>
  <obj_hashval>7b57646ffb811e5040a5b8e4a56e7062</obj_hashval>
  <obj_text>CREATE INDEX idx_ioart1_cheltuieli ON ioart1 USING btree (cheltuieli)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ioart1_codioart</obj_name>
  <obj_reftable>ioart1</obj_reftable>
  <obj_hashval>6060f9db02a766469d8a9a87c7c1c5b7</obj_hashval>
  <obj_text>CREATE INDEX idx_ioart1_codioart ON ioart1 USING btree (codioart, anstart, lunastart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ioart1_cont</obj_name>
  <obj_reftable>ioart1</obj_reftable>
  <obj_hashval>8fd16643460600952d9305eb72b44459</obj_hashval>
  <obj_text>CREATE INDEX idx_ioart1_cont ON ioart1 USING btree (cont)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ioart1_controtunjiri</obj_name>
  <obj_reftable>ioart1</obj_reftable>
  <obj_hashval>46f577f101eea958d870219cc00fc87e</obj_hashval>
  <obj_text>CREATE INDEX idx_ioart1_controtunjiri ON ioart1 USING btree (controtunjiri)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ioart1_diferente</obj_name>
  <obj_reftable>ioart1</obj_reftable>
  <obj_hashval>90010fe94a87f614afe0840ef6f78396</obj_hashval>
  <obj_text>CREATE INDEX idx_ioart1_diferente ON ioart1 USING btree (diferente)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ioart1_diverse</obj_name>
  <obj_reftable>ioart1</obj_reftable>
  <obj_hashval>a14ac49e54de3f5ccae4af38ec52552d</obj_hashval>
  <obj_text>CREATE INDEX idx_ioart1_diverse ON ioart1 USING btree (diverse)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ioart1_minusinventar</obj_name>
  <obj_reftable>ioart1</obj_reftable>
  <obj_hashval>091c9d7a8b2c936e76cf0abec1954f31</obj_hashval>
  <obj_text>CREATE INDEX idx_ioart1_minusinventar ON ioart1 USING btree (minusinventar)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ioart1_plusinventar</obj_name>
  <obj_reftable>ioart1</obj_reftable>
  <obj_hashval>5b38903688abad551b79a53818771013</obj_hashval>
  <obj_text>CREATE INDEX idx_ioart1_plusinventar ON ioart1 USING btree (plusinventar)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ioart1_venituri</obj_name>
  <obj_reftable>ioart1</obj_reftable>
  <obj_hashval>7008a2769cafe1bd8517e2ea4d830ed1</obj_hashval>
  <obj_text>CREATE INDEX idx_ioart1_venituri ON ioart1 USING btree (venituri)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ioartlink_codioart</obj_name>
  <obj_reftable>ioartlink</obj_reftable>
  <obj_hashval>6dd4604f0d65fb32b6eaaae60126155b</obj_hashval>
  <obj_text>CREATE INDEX idx_ioartlink_codioart ON ioartlink USING btree (codioart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iobank1_al</obj_name>
  <obj_reftable>iobank1</obj_reftable>
  <obj_hashval>f076e9a20a1210f9e0658c38f98321b0</obj_hashval>
  <obj_text>CREATE INDEX idx_iobank1_al ON iobank1 USING btree (codiobank, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iofilial1_al</obj_name>
  <obj_reftable>iofilial1</obj_reftable>
  <obj_hashval>191fe2815f6761161d33ff2516d7aad0</obj_hashval>
  <obj_text>CREATE INDEX idx_iofilial1_al ON iofilial1 USING btree (codiofilial, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iofilial1_contcb</obj_name>
  <obj_reftable>iofilial1</obj_reftable>
  <obj_hashval>9d759115a7efe8e78b2f6a49e536143d</obj_hashval>
  <obj_text>CREATE INDEX idx_iofilial1_contcb ON iofilial1 USING btree (contdecontcb)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iofilial1_contcmp</obj_name>
  <obj_reftable>iofilial1</obj_reftable>
  <obj_hashval>ebd914f41103c2ab31af55e51c0f4e1c</obj_hashval>
  <obj_text>CREATE INDEX idx_iofilial1_contcmp ON iofilial1 USING btree (contdecontcmp)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iofilial1_contdecontare</obj_name>
  <obj_reftable>iofilial1</obj_reftable>
  <obj_hashval>357f13294accbfe7ca36c90b25d5295a</obj_hashval>
  <obj_text>CREATE INDEX idx_iofilial1_contdecontare ON iofilial1 USING btree (contdecontare)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iofilial1_contserv</obj_name>
  <obj_reftable>iofilial1</obj_reftable>
  <obj_hashval>8dde845707b444f644e991301bba4a64</obj_hashval>
  <obj_text>CREATE INDEX idx_iofilial1_contserv ON iofilial1 USING btree (contdecontserv)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iopart1_al</obj_name>
  <obj_reftable>iopart1</obj_reftable>
  <obj_hashval>7779a347779a0f3a0001ae6ec2ad97b9</obj_hashval>
  <obj_text>CREATE INDEX idx_iopart1_al ON iopart1 USING btree (codiopart, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iopart1_x_al</obj_name>
  <obj_reftable>iopart1_x</obj_reftable>
  <obj_hashval>9c5e63c7671817ed552ebb5e70836868</obj_hashval>
  <obj_text>CREATE INDEX idx_iopart1_x_al ON iopart1_x USING btree (codiopart, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iopart1x_al</obj_name>
  <obj_reftable>iopart1x</obj_reftable>
  <obj_hashval>78812060d28b89a016e437732e4042b8</obj_hashval>
  <obj_text>CREATE INDEX idx_iopart1x_al ON iopart1x USING btree (codiopart, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iopers1_al</obj_name>
  <obj_reftable>iopers1</obj_reftable>
  <obj_hashval>35c052058856bcb7edeee0de7c4a91ec</obj_hashval>
  <obj_text>CREATE INDEX idx_iopers1_al ON iopers1 USING btree (codiopers, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iopers1_codiopers</obj_name>
  <obj_reftable>iopers1</obj_reftable>
  <obj_hashval>bbb775463220829eadb697ac07acc5e4</obj_hashval>
  <obj_text>CREATE INDEX idx_iopers1_codiopers ON iopers1 USING btree (codiopers)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iopers1_contalteretineri</obj_name>
  <obj_reftable>iopers1</obj_reftable>
  <obj_hashval>f848b3332d37cdc7a8f85b38c98d9819</obj_hashval>
  <obj_text>CREATE INDEX idx_iopers1_contalteretineri ON iopers1 USING btree (contalteretineri)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iopers1_contavans</obj_name>
  <obj_reftable>iopers1</obj_reftable>
  <obj_hashval>6ae06f4cc51ec920048d4feed8cffe78</obj_hashval>
  <obj_text>CREATE INDEX idx_iopers1_contavans ON iopers1 USING btree (contavans)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iopers1_contavansdecont</obj_name>
  <obj_reftable>iopers1</obj_reftable>
  <obj_hashval>80dfc6b960d94d3a39063a6e7d2cc9ba</obj_hashval>
  <obj_text>CREATE INDEX idx_iopers1_contavansdecont ON iopers1 USING btree (contavansdecont)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iopers1_contboala</obj_name>
  <obj_reftable>iopers1</obj_reftable>
  <obj_hashval>0e6f4783828674ca8a5e451d9010866f</obj_hashval>
  <obj_text>CREATE INDEX idx_iopers1_contboala ON iopers1 USING btree (contboala)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iopers1_contechipament</obj_name>
  <obj_reftable>iopers1</obj_reftable>
  <obj_hashval>f567039680511ff59cd8d37cf7da2e81</obj_hashval>
  <obj_text>CREATE INDEX idx_iopers1_contechipament ON iopers1 USING btree (contechipament)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iopers1_contgarantii</obj_name>
  <obj_reftable>iopers1</obj_reftable>
  <obj_hashval>2e4154956bab0b2d0183add7450403c7</obj_hashval>
  <obj_text>CREATE INDEX idx_iopers1_contgarantii ON iopers1 USING btree (contgarantii)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iopers1_contimpozit</obj_name>
  <obj_reftable>iopers1</obj_reftable>
  <obj_hashval>306b293ebaaf08cd5beb042ba5dcb209</obj_hashval>
  <obj_text>CREATE INDEX idx_iopers1_contimpozit ON iopers1 USING btree (contimpozit)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iopers1_contimputatii</obj_name>
  <obj_reftable>iopers1</obj_reftable>
  <obj_hashval>91c22930f326069adb60cfed8958e96d</obj_hashval>
  <obj_text>CREATE INDEX idx_iopers1_contimputatii ON iopers1 USING btree (contimputatii)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iopers1_contliki</obj_name>
  <obj_reftable>iopers1</obj_reftable>
  <obj_hashval>cb99777756293482a00ddd022cf16721</obj_hashval>
  <obj_text>CREATE INDEX idx_iopers1_contliki ON iopers1 USING btree (contliki)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iopers1_contnatura</obj_name>
  <obj_reftable>iopers1</obj_reftable>
  <obj_hashval>79c10fba00a2bfa5e865e7203af0cf5c</obj_hashval>
  <obj_text>CREATE INDEX idx_iopers1_contnatura ON iopers1 USING btree (contnatura)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_iopers1_contneridicate</obj_name>
  <obj_reftable>iopers1</obj_reftable>
  <obj_hashval>1ac3af0dccf523d2f3a65a41e4416072</obj_hashval>
  <obj_text>CREATE INDEX idx_iopers1_contneridicate ON iopers1 USING btree (contneridicate)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_jurnal</obj_name>
  <obj_reftable>jurnal</obj_reftable>
  <obj_hashval>09698c969383e68263cc261bd3f9459c</obj_hashval>
  <obj_text>CREATE INDEX idx_jurnal ON jurnal USING btree (an, luna, tipdoc, coddoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_jurnal_anluna</obj_name>
  <obj_reftable>jurnal</obj_reftable>
  <obj_hashval>76aaf5e5301f5c2f38d0f4d1a3900348</obj_hashval>
  <obj_text>CREATE INDEX idx_jurnal_anluna ON jurnal USING btree ((((an * (12)::numeric) + luna)))</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_jurnal_contc</obj_name>
  <obj_reftable>jurnal</obj_reftable>
  <obj_hashval>04fd196b6d3cfcbfe75e6efc83b1b27d</obj_hashval>
  <obj_text>CREATE INDEX idx_jurnal_contc ON jurnal USING btree (contc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_jurnal_contd</obj_name>
  <obj_reftable>jurnal</obj_reftable>
  <obj_hashval>25076af26747a3126c058392fdaf12cf</obj_hashval>
  <obj_text>CREATE INDEX idx_jurnal_contd ON jurnal USING btree (contd)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_jurnal_doc</obj_name>
  <obj_reftable>jurnal</obj_reftable>
  <obj_hashval>2eb2bc6b59549bc886320499e5aa9745</obj_hashval>
  <obj_text>CREATE INDEX idx_jurnal_doc ON jurnal USING btree (tipdoc, coddoc, indexlocal)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_jurnal_gest</obj_name>
  <obj_reftable>jurnal</obj_reftable>
  <obj_hashval>e6f4e4271788559e88f80f2255ff2cfe</obj_hashval>
  <obj_text>CREATE INDEX idx_jurnal_gest ON jurnal USING btree (gest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_jurnal1</obj_name>
  <obj_reftable>jurnal1</obj_reftable>
  <obj_hashval>ee51fe1c8842df25999af65a9980fb14</obj_hashval>
  <obj_text>CREATE INDEX idx_jurnal1 ON jurnal1 USING btree (an, luna, tipdoc, coddoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_jurnal1_anluna</obj_name>
  <obj_reftable>jurnal1</obj_reftable>
  <obj_hashval>84c3acce1446587e9dee6695c96001b4</obj_hashval>
  <obj_text>CREATE INDEX idx_jurnal1_anluna ON jurnal1 USING btree ((((an * (12)::numeric) + luna)))</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_jurnal1_doc</obj_name>
  <obj_reftable>jurnal1</obj_reftable>
  <obj_hashval>984f4716a68a59ca04268e99cd899e18</obj_hashval>
  <obj_text>CREATE INDEX idx_jurnal1_doc ON jurnal1 USING btree (tipdoc, coddoc, indexlocal)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_jurnal1_gest</obj_name>
  <obj_reftable>jurnal1</obj_reftable>
  <obj_hashval>d5c27256c9c91833dd9e1bea0a607d24</obj_hashval>
  <obj_text>CREATE INDEX idx_jurnal1_gest ON jurnal1 USING btree (gest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansare_anulat</obj_name>
  <obj_reftable>lansare</obj_reftable>
  <obj_hashval>cb56d38d4b1b35d669f8cbfce1dd4a53</obj_hashval>
  <obj_text>CREATE INDEX idx_lansare_anulat ON lansare USING btree (anulat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansare_automat</obj_name>
  <obj_reftable>lansare</obj_reftable>
  <obj_hashval>7ec2023d3a55ea0cfc515987d0a910cd</obj_hashval>
  <obj_text>CREATE INDEX idx_lansare_automat ON lansare USING btree (codscenariu, automat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansare_blocat</obj_name>
  <obj_reftable>lansare</obj_reftable>
  <obj_hashval>71efe73e00ee74523aafcbb9910a5c8d</obj_hashval>
  <obj_text>CREATE INDEX idx_lansare_blocat ON lansare USING btree (blocat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansare_codcmd1</obj_name>
  <obj_reftable>lansare</obj_reftable>
  <obj_hashval>b3551ddb486f356f3762b619214e9fe4</obj_hashval>
  <obj_text>CREATE INDEX idx_lansare_codcmd1 ON lansare USING btree (codcmd1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansare_codscenariu</obj_name>
  <obj_reftable>lansare</obj_reftable>
  <obj_hashval>057eeb71d542f8448bf6b8d35297c103</obj_hashval>
  <obj_text>CREATE INDEX idx_lansare_codscenariu ON lansare USING btree (codscenariu)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansare_datadoc</obj_name>
  <obj_reftable>lansare</obj_reftable>
  <obj_hashval>b1878803b91eb181c99305af8c9d37d1</obj_hashval>
  <obj_text>CREATE INDEX idx_lansare_datadoc ON lansare USING btree (datadoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansare_operat</obj_name>
  <obj_reftable>lansare</obj_reftable>
  <obj_hashval>8d26a0c3dcff264f9a6e7a0993dabbab</obj_hashval>
  <obj_text>CREATE INDEX idx_lansare_operat ON lansare USING btree (operat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansare0_codcmd1</obj_name>
  <obj_reftable>lansare0</obj_reftable>
  <obj_hashval>54f6953d939d7f0fad06ddf54415057c</obj_hashval>
  <obj_text>CREATE INDEX idx_lansare0_codcmd1 ON lansare0 USING btree (codcmd1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansare0_codlansare</obj_name>
  <obj_reftable>lansare0</obj_reftable>
  <obj_hashval>109905c6e85358102498ed1757279a91</obj_hashval>
  <obj_text>CREATE INDEX idx_lansare0_codlansare ON lansare0 USING btree (codlansare)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansare0_codproiect</obj_name>
  <obj_reftable>lansare0</obj_reftable>
  <obj_hashval>d809eac447ea695f5bb635722424d024</obj_hashval>
  <obj_text>CREATE INDEX idx_lansare0_codproiect ON lansare0 USING btree (codproiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansare0_termen</obj_name>
  <obj_reftable>lansare0</obj_reftable>
  <obj_hashval>863d2b9003979e1eefc07ba75440f095</obj_hashval>
  <obj_text>CREATE INDEX idx_lansare0_termen ON lansare0 USING btree (termen)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansare1_codcmd1</obj_name>
  <obj_reftable>lansare1</obj_reftable>
  <obj_hashval>a1811299227a6995ed22520dab3bd072</obj_hashval>
  <obj_text>CREATE INDEX idx_lansare1_codcmd1 ON lansare1 USING btree (codcmd1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansare1_codlansare</obj_name>
  <obj_reftable>lansare1</obj_reftable>
  <obj_hashval>1806e29b185442582371cb46c9d0007d</obj_hashval>
  <obj_text>CREATE INDEX idx_lansare1_codlansare ON lansare1 USING btree (codlansare)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansare1_codlansare0</obj_name>
  <obj_reftable>lansare1</obj_reftable>
  <obj_hashval>3e1a2b9e714f9c103fc29a8d8cbd9c37</obj_hashval>
  <obj_text>CREATE INDEX idx_lansare1_codlansare0 ON lansare1 USING btree (codlansare0)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansare1_codproiectnod</obj_name>
  <obj_reftable>lansare1</obj_reftable>
  <obj_hashval>1363d960dffece1fff6a51d4ab4a3af3</obj_hashval>
  <obj_text>CREATE INDEX idx_lansare1_codproiectnod ON lansare1 USING btree (codproiectnod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansare1_tip</obj_name>
  <obj_reftable>lansare1</obj_reftable>
  <obj_hashval>b0093e596f580533d51f62f4c840d016</obj_hashval>
  <obj_text>CREATE INDEX idx_lansare1_tip ON lansare1 USING btree (tip)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansarenec_codlansare0</obj_name>
  <obj_reftable>lansarenec</obj_reftable>
  <obj_hashval>5932dd7360dac4b674f2e4389a973296</obj_hashval>
  <obj_text>CREATE INDEX idx_lansarenec_codlansare0 ON lansarenec USING btree (codlansare0)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansarenec_codobiect</obj_name>
  <obj_reftable>lansarenec</obj_reftable>
  <obj_hashval>acf6b10dadc2bf3fff8a4edfe6dec1f9</obj_hashval>
  <obj_text>CREATE INDEX idx_lansarenec_codobiect ON lansarenec USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansarenec_codproiectnod</obj_name>
  <obj_reftable>lansarenec</obj_reftable>
  <obj_hashval>930a7570178af3ec7eb808c08bb9e2c3</obj_hashval>
  <obj_text>CREATE INDEX idx_lansarenec_codproiectnod ON lansarenec USING btree (codproiectnod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansgest_codlansprod</obj_name>
  <obj_reftable>lansgest</obj_reftable>
  <obj_hashval>b5d4b719b754b9322ff1af62a706819d</obj_hashval>
  <obj_text>CREATE INDEX idx_lansgest_codlansprod ON lansgest USING btree (codlansprod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansprod_anluna</obj_name>
  <obj_reftable>lansprod</obj_reftable>
  <obj_hashval>fbf823529555f1fd4bdc45cfa57389f7</obj_hashval>
  <obj_text>CREATE INDEX idx_lansprod_anluna ON lansprod USING btree ((((an * (12)::numeric) + luna)))</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansprod_anulat</obj_name>
  <obj_reftable>lansprod</obj_reftable>
  <obj_hashval>188209663412cc5a2efc748f8f9c57be</obj_hashval>
  <obj_text>CREATE INDEX idx_lansprod_anulat ON lansprod USING btree (anulat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansprod_operat</obj_name>
  <obj_reftable>lansprod</obj_reftable>
  <obj_hashval>ae69b03a296e21e52ac24fa1a55d52dd</obj_hashval>
  <obj_text>CREATE INDEX idx_lansprod_operat ON lansprod USING btree (operat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansprod_saptamana</obj_name>
  <obj_reftable>lansprod</obj_reftable>
  <obj_hashval>643e29ddedf79df9bf887e414bc25551</obj_hashval>
  <obj_text>CREATE INDEX idx_lansprod_saptamana ON lansprod USING btree (saptamana)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansprod_subunitatea</obj_name>
  <obj_reftable>lansprod</obj_reftable>
  <obj_hashval>a75ee27e2b18075b52d9498127b626da</obj_hashval>
  <obj_text>CREATE INDEX idx_lansprod_subunitatea ON lansprod USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansprod1_codlansprod</obj_name>
  <obj_reftable>lansprod1</obj_reftable>
  <obj_hashval>d34f1338ff6ce997385a8b0d76eee265</obj_hashval>
  <obj_text>CREATE INDEX idx_lansprod1_codlansprod ON lansprod1 USING btree (codlansprod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansprod1_codobiect</obj_name>
  <obj_reftable>lansprod1</obj_reftable>
  <obj_hashval>d6f95f535a6956327fc0c49b2bc07aaf</obj_hashval>
  <obj_text>CREATE INDEX idx_lansprod1_codobiect ON lansprod1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansprod2_codgest</obj_name>
  <obj_reftable>lansprod2</obj_reftable>
  <obj_hashval>c7013fbaa2b2e4f92b2e636424611e49</obj_hashval>
  <obj_text>CREATE INDEX idx_lansprod2_codgest ON lansprod2 USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansprod2_codlansprod</obj_name>
  <obj_reftable>lansprod2</obj_reftable>
  <obj_hashval>ef9a3ede31430332f74b87eed8300e4b</obj_hashval>
  <obj_text>CREATE INDEX idx_lansprod2_codlansprod ON lansprod2 USING btree (codlansprod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansprod2_codlansprod1</obj_name>
  <obj_reftable>lansprod2</obj_reftable>
  <obj_hashval>9c5ae35a462d716bdda72dde3541d33d</obj_hashval>
  <obj_text>CREATE INDEX idx_lansprod2_codlansprod1 ON lansprod2 USING btree (codlansprod1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansprod2_codobiect</obj_name>
  <obj_reftable>lansprod2</obj_reftable>
  <obj_hashval>9d07fe0d41615c50e5deef68e032bdbf</obj_hashval>
  <obj_text>CREATE INDEX idx_lansprod2_codobiect ON lansprod2 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansprod2s_codgest</obj_name>
  <obj_reftable>lansprod2s</obj_reftable>
  <obj_hashval>d595ce1249e1757df32fe92fda1603cf</obj_hashval>
  <obj_text>CREATE INDEX idx_lansprod2s_codgest ON lansprod2s USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansprod2s_codlansprod</obj_name>
  <obj_reftable>lansprod2s</obj_reftable>
  <obj_hashval>2586a0b2dd14920b17277ca5f38ce74c</obj_hashval>
  <obj_text>CREATE INDEX idx_lansprod2s_codlansprod ON lansprod2s USING btree (codlansprod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz_an</obj_name>
  <obj_reftable>lansz</obj_reftable>
  <obj_hashval>f397afaf50b72b5213a66f0364f7f65f</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz_an ON lansz USING btree (an)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz_anluna</obj_name>
  <obj_reftable>lansz</obj_reftable>
  <obj_hashval>14bfa7669606c563b87e9c5807eff639</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz_anluna ON lansz USING btree ((((an * (12)::numeric) + luna)))</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz_anulat</obj_name>
  <obj_reftable>lansz</obj_reftable>
  <obj_hashval>9ea36705b891fc360fa67ccb32084fe8</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz_anulat ON lansz USING btree (anulat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz_codgest</obj_name>
  <obj_reftable>lansz</obj_reftable>
  <obj_hashval>c7403125cbbdb69d96d2e1fe37ad3db7</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz_codgest ON lansz USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz_codplanifprod</obj_name>
  <obj_reftable>lansz</obj_reftable>
  <obj_hashval>b5a898a99442cfd66bae78cda9df41cb</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz_codplanifprod ON lansz USING btree (codplanifprod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz_finalizat</obj_name>
  <obj_reftable>lansz</obj_reftable>
  <obj_hashval>a71cff48a80142fac2f22334b6061641</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz_finalizat ON lansz USING btree (finalizat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz_operat</obj_name>
  <obj_reftable>lansz</obj_reftable>
  <obj_hashval>0e706413e317c4e57ec79b3be4d98cee</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz_operat ON lansz USING btree (operat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz_saptamana</obj_name>
  <obj_reftable>lansz</obj_reftable>
  <obj_hashval>179dc783fb32cc6d486ee4a51d7f9561</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz_saptamana ON lansz USING btree (saptamana)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz_subunitatea</obj_name>
  <obj_reftable>lansz</obj_reftable>
  <obj_hashval>e5e1e7cbd68c9e8d60cdd4eab9b17638</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz_subunitatea ON lansz USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1_codcmd1_duminica</obj_name>
  <obj_reftable>lansz1</obj_reftable>
  <obj_hashval>6b8f42071b7fc34193f318fa7e0c7cfa</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1_codcmd1_duminica ON lansz1 USING btree (codcmd1_duminica)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1_codcmd1_joi</obj_name>
  <obj_reftable>lansz1</obj_reftable>
  <obj_hashval>74aaeb9c4fe17fee8c71fad4d5dab70d</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1_codcmd1_joi ON lansz1 USING btree (codcmd1_joi)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1_codcmd1_luni</obj_name>
  <obj_reftable>lansz1</obj_reftable>
  <obj_hashval>5d263031b0654ac7e37b71acc28cc289</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1_codcmd1_luni ON lansz1 USING btree (codcmd1_luni)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1_codcmd1_marti</obj_name>
  <obj_reftable>lansz1</obj_reftable>
  <obj_hashval>d873a2cd3ec24207a043a4b4b3df8b7a</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1_codcmd1_marti ON lansz1 USING btree (codcmd1_marti)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1_codcmd1_miercuri</obj_name>
  <obj_reftable>lansz1</obj_reftable>
  <obj_hashval>198f46f28ecaf376d25bc6d66df3c144</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1_codcmd1_miercuri ON lansz1 USING btree (codcmd1_miercuri)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1_codcmd1_sambata</obj_name>
  <obj_reftable>lansz1</obj_reftable>
  <obj_hashval>01abeeab6258733c0fc91b6edd2c0465</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1_codcmd1_sambata ON lansz1 USING btree (codcmd1_sambata)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1_codcmd1_vineri</obj_name>
  <obj_reftable>lansz1</obj_reftable>
  <obj_hashval>9107f92d8dc16640f576d2cdac2ed596</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1_codcmd1_vineri ON lansz1 USING btree (codcmd1_vineri)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1_codformatie</obj_name>
  <obj_reftable>lansz1</obj_reftable>
  <obj_hashval>2e9e0bd7fc97c01ee02a0cd0dc90d74c</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1_codformatie ON lansz1 USING btree (codformatie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1_codlansz</obj_name>
  <obj_reftable>lansz1</obj_reftable>
  <obj_hashval>36621cb8f122d6d51609fa222a5e50e0</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1_codlansz ON lansz1 USING btree (codlansz)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1_codobiect</obj_name>
  <obj_reftable>lansz1</obj_reftable>
  <obj_hashval>010ca9a756e95830023e4ffcb3a8ca51</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1_codobiect ON lansz1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1_codreteta</obj_name>
  <obj_reftable>lansz1</obj_reftable>
  <obj_hashval>8ebb4c91d261be2dd86a92857caf9819</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1_codreteta ON lansz1 USING btree (codreteta)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1_schimb</obj_name>
  <obj_reftable>lansz1</obj_reftable>
  <obj_hashval>29e2650538dbefc6023e1429a05d89b1</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1_schimb ON lansz1 USING btree (schimb)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m_codcmd1_duminica</obj_name>
  <obj_reftable>lansz1_manevra</obj_reftable>
  <obj_hashval>0ce942f3de48db035240ba6dddeb1d6c</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m_codcmd1_duminica ON lansz1_manevra USING btree (codcmd1_duminica)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m_codcmd1_joi</obj_name>
  <obj_reftable>lansz1_manevra</obj_reftable>
  <obj_hashval>ba15c5e3ebf29dbfde48193171787f1f</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m_codcmd1_joi ON lansz1_manevra USING btree (codcmd1_joi)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m_codcmd1_luni</obj_name>
  <obj_reftable>lansz1_manevra</obj_reftable>
  <obj_hashval>1c6cf2671133a4d7dbae6db0190a7534</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m_codcmd1_luni ON lansz1_manevra USING btree (codcmd1_luni)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m_codcmd1_marti</obj_name>
  <obj_reftable>lansz1_manevra</obj_reftable>
  <obj_hashval>f8c1e263ecf6b2ab089e7d0dc72cf7a5</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m_codcmd1_marti ON lansz1_manevra USING btree (codcmd1_marti)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m_codcmd1_miercuri</obj_name>
  <obj_reftable>lansz1_manevra</obj_reftable>
  <obj_hashval>858e9936ca7fd00cef9f5b0f8219ebe1</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m_codcmd1_miercuri ON lansz1_manevra USING btree (codcmd1_miercuri)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m_codcmd1_sambata</obj_name>
  <obj_reftable>lansz1_manevra</obj_reftable>
  <obj_hashval>647395c775262b63edbaa3cb298e4ce9</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m_codcmd1_sambata ON lansz1_manevra USING btree (codcmd1_sambata)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m_codcmd1_vineri</obj_name>
  <obj_reftable>lansz1_manevra</obj_reftable>
  <obj_hashval>ae91c3873f223465d7c716ced45e8046</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m_codcmd1_vineri ON lansz1_manevra USING btree (codcmd1_vineri)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m_codformatie</obj_name>
  <obj_reftable>lansz1_manevra</obj_reftable>
  <obj_hashval>2eafc1f46caa0aabc9fd2656ed8fc22e</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m_codformatie ON lansz1_manevra USING btree (codformatie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m_codgest</obj_name>
  <obj_reftable>lansz1_manevra</obj_reftable>
  <obj_hashval>8e9b064fa4dda59456f8bb16f578a964</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m_codgest ON lansz1_manevra USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m_codlansz</obj_name>
  <obj_reftable>lansz1_manevra</obj_reftable>
  <obj_hashval>6f6c658bebd1166a4c68b7c13cfde1ec</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m_codlansz ON lansz1_manevra USING btree (codlansz)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m_codlansz1</obj_name>
  <obj_reftable>lansz1_manevra</obj_reftable>
  <obj_hashval>f5086a1e53bc0b5e3e0fa831c2698276</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m_codlansz1 ON lansz1_manevra USING btree (codlansz1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m_codnorma</obj_name>
  <obj_reftable>lansz1_manevra</obj_reftable>
  <obj_hashval>24b1723cbbc5ba43d96c6e19b378edd6</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m_codnorma ON lansz1_manevra USING btree (codnorma)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m_codobiect</obj_name>
  <obj_reftable>lansz1_manevra</obj_reftable>
  <obj_hashval>0b04afb68d7fd5e736039fcf58162e06</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m_codobiect ON lansz1_manevra USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m_codprodcomp</obj_name>
  <obj_reftable>lansz1_manevra</obj_reftable>
  <obj_hashval>5b074ad5ecbfe49cc4ff40fc0d09c778</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m_codprodcomp ON lansz1_manevra USING btree (codprodcomp)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m_codreteta</obj_name>
  <obj_reftable>lansz1_manevra</obj_reftable>
  <obj_hashval>cb02e8f60ba50563eec5c0bde339447b</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m_codreteta ON lansz1_manevra USING btree (codreteta)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m_ordine</obj_name>
  <obj_reftable>lansz1_manevra</obj_reftable>
  <obj_hashval>359734665183802571cbd81dfc900b10</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m_ordine ON lansz1_manevra USING btree (ordine)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m_schimb</obj_name>
  <obj_reftable>lansz1_manevra</obj_reftable>
  <obj_hashval>a317be3c4307ff9148a34ba5081acb4e</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m_schimb ON lansz1_manevra USING btree (schimb)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m_userid</obj_name>
  <obj_reftable>lansz1_manevra</obj_reftable>
  <obj_hashval>d947601b6414f7ce95a76a9afd795ce0</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m_userid ON lansz1_manevra USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1_codcmd1_duminica</obj_name>
  <obj_reftable>lansz1_manevra1</obj_reftable>
  <obj_hashval>8d21455533989d28be9472a153fc1e11</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1_codcmd1_duminica ON lansz1_manevra1 USING btree (codcmd1_duminica)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1_codcmd1_joi</obj_name>
  <obj_reftable>lansz1_manevra1</obj_reftable>
  <obj_hashval>3219fe63ef2b8f79c09127dabd81c027</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1_codcmd1_joi ON lansz1_manevra1 USING btree (codcmd1_joi)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1_codcmd1_luni</obj_name>
  <obj_reftable>lansz1_manevra1</obj_reftable>
  <obj_hashval>ec876fa8fd81380e8e3d5c7857d5e63a</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1_codcmd1_luni ON lansz1_manevra1 USING btree (codcmd1_luni)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1_codcmd1_marti</obj_name>
  <obj_reftable>lansz1_manevra1</obj_reftable>
  <obj_hashval>863b3425521196b27efdbdb96227b544</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1_codcmd1_marti ON lansz1_manevra1 USING btree (codcmd1_marti)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1_codcmd1_miercuri</obj_name>
  <obj_reftable>lansz1_manevra1</obj_reftable>
  <obj_hashval>a92dc995d5abd14414db832cedb7c285</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1_codcmd1_miercuri ON lansz1_manevra1 USING btree (codcmd1_miercuri)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1_codcmd1_sambata</obj_name>
  <obj_reftable>lansz1_manevra1</obj_reftable>
  <obj_hashval>1020266be9442d04c3e09505d208bde3</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1_codcmd1_sambata ON lansz1_manevra1 USING btree (codcmd1_sambata)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1_codcmd1_vineri</obj_name>
  <obj_reftable>lansz1_manevra1</obj_reftable>
  <obj_hashval>f9ffd9a7a93a85fc6cc9daf7b2958c42</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1_codcmd1_vineri ON lansz1_manevra1 USING btree (codcmd1_vineri)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1_codformatie</obj_name>
  <obj_reftable>lansz1_manevra1</obj_reftable>
  <obj_hashval>77520a72416e0be73ecccbd2fe111914</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1_codformatie ON lansz1_manevra1 USING btree (codformatie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1_codgest</obj_name>
  <obj_reftable>lansz1_manevra1</obj_reftable>
  <obj_hashval>fb1705a5946dde118f3aaaf898119498</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1_codgest ON lansz1_manevra1 USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1_codlansz</obj_name>
  <obj_reftable>lansz1_manevra1</obj_reftable>
  <obj_hashval>2704ad6f183e3b7a02331ec50fbf9839</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1_codlansz ON lansz1_manevra1 USING btree (codlansz)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1_codlansz1</obj_name>
  <obj_reftable>lansz1_manevra1</obj_reftable>
  <obj_hashval>64c652760922d78cd89e7678e790815e</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1_codlansz1 ON lansz1_manevra1 USING btree (codlansz1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1_codnorma</obj_name>
  <obj_reftable>lansz1_manevra1</obj_reftable>
  <obj_hashval>c4b23fb4d8101dc7de89862a1f98bb7c</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1_codnorma ON lansz1_manevra1 USING btree (codnorma)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1_codobiect</obj_name>
  <obj_reftable>lansz1_manevra1</obj_reftable>
  <obj_hashval>037850c2ef2328619c051f05ef1a4e62</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1_codobiect ON lansz1_manevra1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1_codprodcomp</obj_name>
  <obj_reftable>lansz1_manevra1</obj_reftable>
  <obj_hashval>9ad2e5ecf93987fbcdc0df8d213a593a</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1_codprodcomp ON lansz1_manevra1 USING btree (codprodcomp)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1_codreteta</obj_name>
  <obj_reftable>lansz1_manevra1</obj_reftable>
  <obj_hashval>e642ef464ed170f3da4236d4041b936a</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1_codreteta ON lansz1_manevra1 USING btree (codreteta)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1_ordine</obj_name>
  <obj_reftable>lansz1_manevra1</obj_reftable>
  <obj_hashval>2e62003189059b54bd9c08163ff4f113</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1_ordine ON lansz1_manevra1 USING btree (ordine)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1_schimb</obj_name>
  <obj_reftable>lansz1_manevra1</obj_reftable>
  <obj_hashval>e11d165280387870dae9d082a8695be6</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1_schimb ON lansz1_manevra1 USING btree (schimb)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1_userid</obj_name>
  <obj_reftable>lansz1_manevra1</obj_reftable>
  <obj_hashval>6cad2364444f2e81a933d172668d1783</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1_userid ON lansz1_manevra1 USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1l_codcmd1_duminica</obj_name>
  <obj_reftable>lansz1_manevra1_l</obj_reftable>
  <obj_hashval>f735731e5ac5de0f93c2d117718e56ff</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1l_codcmd1_duminica ON lansz1_manevra1_l USING btree (codcmd1_duminica)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1l_codcmd1_joi</obj_name>
  <obj_reftable>lansz1_manevra1_l</obj_reftable>
  <obj_hashval>1f4b14ff5d7022968e25e91c3c2a6a08</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1l_codcmd1_joi ON lansz1_manevra1_l USING btree (codcmd1_joi)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1l_codcmd1_luni</obj_name>
  <obj_reftable>lansz1_manevra1_l</obj_reftable>
  <obj_hashval>872662916b1e0e7f19de1ce9fcaa1b0f</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1l_codcmd1_luni ON lansz1_manevra1_l USING btree (codcmd1_luni)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1l_codcmd1_marti</obj_name>
  <obj_reftable>lansz1_manevra1_l</obj_reftable>
  <obj_hashval>e6d0e77e99ed35ed12b00a31ffb55488</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1l_codcmd1_marti ON lansz1_manevra1_l USING btree (codcmd1_marti)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1l_codcmd1_miercuri</obj_name>
  <obj_reftable>lansz1_manevra1_l</obj_reftable>
  <obj_hashval>ba1335ae40469687d9a90546ddbd9a97</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1l_codcmd1_miercuri ON lansz1_manevra1_l USING btree (codcmd1_miercuri)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1l_codcmd1_sambata</obj_name>
  <obj_reftable>lansz1_manevra1_l</obj_reftable>
  <obj_hashval>224d0c7af19813d9bb305ddbbdae95a2</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1l_codcmd1_sambata ON lansz1_manevra1_l USING btree (codcmd1_sambata)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1l_codcmd1_vineri</obj_name>
  <obj_reftable>lansz1_manevra1_l</obj_reftable>
  <obj_hashval>c3c02903cc970e621c3165dd13623842</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1l_codcmd1_vineri ON lansz1_manevra1_l USING btree (codcmd1_vineri)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1l_codformatie</obj_name>
  <obj_reftable>lansz1_manevra1_l</obj_reftable>
  <obj_hashval>a7912d351352fceec1e95800d96f2e42</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1l_codformatie ON lansz1_manevra1_l USING btree (codformatie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1l_codgest</obj_name>
  <obj_reftable>lansz1_manevra1_l</obj_reftable>
  <obj_hashval>12df14f7b14c80eb6f757c3ab4221015</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1l_codgest ON lansz1_manevra1_l USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1l_codlansz</obj_name>
  <obj_reftable>lansz1_manevra1_l</obj_reftable>
  <obj_hashval>280999080f9ac553bd08fefdf8772742</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1l_codlansz ON lansz1_manevra1_l USING btree (codlansz)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1l_codlansz1</obj_name>
  <obj_reftable>lansz1_manevra1_l</obj_reftable>
  <obj_hashval>ec39f8b307bb8edd74dd6fd5c2051cc9</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1l_codlansz1 ON lansz1_manevra1_l USING btree (codlansz1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1l_codnorma</obj_name>
  <obj_reftable>lansz1_manevra1_l</obj_reftable>
  <obj_hashval>c8193503eb7e27a38c758b09a94e8285</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1l_codnorma ON lansz1_manevra1_l USING btree (codnorma)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1l_codobiect</obj_name>
  <obj_reftable>lansz1_manevra1_l</obj_reftable>
  <obj_hashval>4e4695e2482017d049e1e4174d11fdb6</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1l_codobiect ON lansz1_manevra1_l USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1l_codprodcomp</obj_name>
  <obj_reftable>lansz1_manevra1_l</obj_reftable>
  <obj_hashval>6213583f1fdb529eb7a827c564d464be</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1l_codprodcomp ON lansz1_manevra1_l USING btree (codprodcomp)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1l_codreteta</obj_name>
  <obj_reftable>lansz1_manevra1_l</obj_reftable>
  <obj_hashval>1bf5e7c20b5d415ab01fd2da2b7accbe</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1l_codreteta ON lansz1_manevra1_l USING btree (codreteta)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1l_schimb</obj_name>
  <obj_reftable>lansz1_manevra1_l</obj_reftable>
  <obj_hashval>4971d2b64a94b562cb34daa2e102ceea</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1l_schimb ON lansz1_manevra1_l USING btree (schimb)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1m1l_userid</obj_name>
  <obj_reftable>lansz1_manevra1_l</obj_reftable>
  <obj_hashval>ae26481202790e33acda5ed06e001987</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1m1l_userid ON lansz1_manevra1_l USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1ml_codcmd1_duminica</obj_name>
  <obj_reftable>lansz1_manevra_l</obj_reftable>
  <obj_hashval>685d40658941ad2cbbb267960acdac0f</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1ml_codcmd1_duminica ON lansz1_manevra_l USING btree (codcmd1_duminica)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1ml_codcmd1_joi</obj_name>
  <obj_reftable>lansz1_manevra_l</obj_reftable>
  <obj_hashval>54a99eb1e515bfb452a611d68dae8853</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1ml_codcmd1_joi ON lansz1_manevra_l USING btree (codcmd1_joi)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1ml_codcmd1_luni</obj_name>
  <obj_reftable>lansz1_manevra_l</obj_reftable>
  <obj_hashval>35e75bbe5bcc825d06a6836ac337148c</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1ml_codcmd1_luni ON lansz1_manevra_l USING btree (codcmd1_luni)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1ml_codcmd1_marti</obj_name>
  <obj_reftable>lansz1_manevra_l</obj_reftable>
  <obj_hashval>e873a99280329be397173872e2604888</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1ml_codcmd1_marti ON lansz1_manevra_l USING btree (codcmd1_marti)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1ml_codcmd1_miercuri</obj_name>
  <obj_reftable>lansz1_manevra_l</obj_reftable>
  <obj_hashval>9773eb863466fbe27277bbc3ce770d2a</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1ml_codcmd1_miercuri ON lansz1_manevra_l USING btree (codcmd1_miercuri)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1ml_codcmd1_sambata</obj_name>
  <obj_reftable>lansz1_manevra_l</obj_reftable>
  <obj_hashval>d1a0186128184fabb2a57afafb1ae094</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1ml_codcmd1_sambata ON lansz1_manevra_l USING btree (codcmd1_sambata)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1ml_codcmd1_vineri</obj_name>
  <obj_reftable>lansz1_manevra_l</obj_reftable>
  <obj_hashval>de79156f9938d49c1d6c15a57ee6bae1</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1ml_codcmd1_vineri ON lansz1_manevra_l USING btree (codcmd1_vineri)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1ml_codformatie</obj_name>
  <obj_reftable>lansz1_manevra_l</obj_reftable>
  <obj_hashval>e0855abcb69ce4e5f4dec52e9b5478c8</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1ml_codformatie ON lansz1_manevra_l USING btree (codformatie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1ml_codgest</obj_name>
  <obj_reftable>lansz1_manevra_l</obj_reftable>
  <obj_hashval>9b08f53d638900369d6c8499d0911b54</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1ml_codgest ON lansz1_manevra_l USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1ml_codlansz</obj_name>
  <obj_reftable>lansz1_manevra_l</obj_reftable>
  <obj_hashval>f80feccb06b2c48d37217cada414f7b4</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1ml_codlansz ON lansz1_manevra_l USING btree (codlansz)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1ml_codlansz1</obj_name>
  <obj_reftable>lansz1_manevra_l</obj_reftable>
  <obj_hashval>b38aaca16295d9a614e05138f38df446</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1ml_codlansz1 ON lansz1_manevra_l USING btree (codlansz1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1ml_codnorma</obj_name>
  <obj_reftable>lansz1_manevra_l</obj_reftable>
  <obj_hashval>3dc5ed5011be2bbfd872e16c3044053c</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1ml_codnorma ON lansz1_manevra_l USING btree (codnorma)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1ml_codobiect</obj_name>
  <obj_reftable>lansz1_manevra_l</obj_reftable>
  <obj_hashval>970d0f36400aab481b7b9cc915ae76da</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1ml_codobiect ON lansz1_manevra_l USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1ml_codprodcomp</obj_name>
  <obj_reftable>lansz1_manevra_l</obj_reftable>
  <obj_hashval>f1e4871a3561d60e655db791220fd410</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1ml_codprodcomp ON lansz1_manevra_l USING btree (codprodcomp)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1ml_codreteta</obj_name>
  <obj_reftable>lansz1_manevra_l</obj_reftable>
  <obj_hashval>1fdf3b76d79326691413881341eadcdf</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1ml_codreteta ON lansz1_manevra_l USING btree (codreteta)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1ml_schimb</obj_name>
  <obj_reftable>lansz1_manevra_l</obj_reftable>
  <obj_hashval>41207da09295e708274efcdba1d8423d</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1ml_schimb ON lansz1_manevra_l USING btree (schimb)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lansz1ml_userid</obj_name>
  <obj_reftable>lansz1_manevra_l</obj_reftable>
  <obj_hashval>dccbd63aa1a5367adacbaa60ec4ea223</obj_hashval>
  <obj_text>CREATE INDEX idx_lansz1ml_userid ON lansz1_manevra_l USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lasz1_cmd_codcomanda1</obj_name>
  <obj_reftable>lansz1_cmd</obj_reftable>
  <obj_hashval>fb5c7676b09a77e515f94144c37f698a</obj_hashval>
  <obj_text>CREATE INDEX idx_lasz1_cmd_codcomanda1 ON lansz1_cmd USING btree (codcomanda1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_lasz1_cmd_codlansz1</obj_name>
  <obj_reftable>lansz1_cmd</obj_reftable>
  <obj_hashval>465e44734837f6a9f604dfa35ff44127</obj_hashval>
  <obj_text>CREATE INDEX idx_lasz1_cmd_codlansz1 ON lansz1_cmd USING btree (codlansz1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_livr_codies</obj_name>
  <obj_reftable>livr</obj_reftable>
  <obj_hashval>5c1afacb36cf8d2eb161fd37e7521e1b</obj_hashval>
  <obj_text>CREATE INDEX idx_livr_codies ON livr USING btree (codies)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_livr_codintr</obj_name>
  <obj_reftable>livr</obj_reftable>
  <obj_hashval>55169d958bfa1cb8b7ba80f7e43c92ff</obj_hashval>
  <obj_text>CREATE INDEX idx_livr_codintr ON livr USING btree (codintr)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_livr_codtransf</obj_name>
  <obj_reftable>livr</obj_reftable>
  <obj_hashval>add71e0aff37a123d1ced7105f3bc15a</obj_hashval>
  <obj_text>CREATE INDEX idx_livr_codtransf ON livr USING btree (codtransf)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_livr_tiplivr</obj_name>
  <obj_reftable>livr</obj_reftable>
  <obj_hashval>751faf05f7b5ed375ef5da9f83940d84</obj_hashval>
  <obj_text>CREATE INDEX idx_livr_tiplivr ON livr USING btree (tiplivr)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_livr1_codies1</obj_name>
  <obj_reftable>livr1</obj_reftable>
  <obj_hashval>5cada0cbf9cb7f8e880ce7aa99290758</obj_hashval>
  <obj_text>CREATE INDEX idx_livr1_codies1 ON livr1 USING btree (codies1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_livr1_codlivr</obj_name>
  <obj_reftable>livr1</obj_reftable>
  <obj_hashval>84ad8b059dc1c6780cb78b04408f7757</obj_hashval>
  <obj_text>CREATE INDEX idx_livr1_codlivr ON livr1 USING btree (codlivr)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_livr1_codnirser</obj_name>
  <obj_reftable>livr1</obj_reftable>
  <obj_hashval>f9857cf02e9c11ac730d88f41f841417</obj_hashval>
  <obj_text>CREATE INDEX idx_livr1_codnirser ON livr1 USING btree (codnirser)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_livr1_codnirstoc</obj_name>
  <obj_reftable>livr1</obj_reftable>
  <obj_hashval>c1a15d4279c8d47a7f5d6a9f86715e66</obj_hashval>
  <obj_text>CREATE INDEX idx_livr1_codnirstoc ON livr1 USING btree (codnirstoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_livr1_umsec</obj_name>
  <obj_reftable>livr1</obj_reftable>
  <obj_hashval>6c4595d755dcd2f154d2468b8686d0ce</obj_hashval>
  <obj_text>CREATE INDEX idx_livr1_umsec ON livr1 USING btree (umsec)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_livr11_coddvi1</obj_name>
  <obj_reftable>livr1</obj_reftable>
  <obj_hashval>cf9c8cdbf96c91634de3521dd5066e31</obj_hashval>
  <obj_text>CREATE INDEX idx_livr11_coddvi1 ON livr1 USING btree (coddvi1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_livr11_codntr1</obj_name>
  <obj_reftable>livr1</obj_reftable>
  <obj_hashval>b0476733b529854d62b4914a4683e1c2</obj_hashval>
  <obj_text>CREATE INDEX idx_livr11_codntr1 ON livr1 USING btree (codintr1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_livrval_codioart</obj_name>
  <obj_reftable>livrval</obj_reftable>
  <obj_hashval>03a6146d21009afcc8d1a57e884eb256</obj_hashval>
  <obj_text>CREATE INDEX idx_livrval_codioart ON livrval USING btree (codioart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_livrval_codlivr1</obj_name>
  <obj_reftable>livrval</obj_reftable>
  <obj_hashval>2f704aa21dfa7c54a6ec4839facf6393</obj_hashval>
  <obj_text>CREATE INDEX idx_livrval_codlivr1 ON livrval USING btree (codlivr1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_livrval_codobiect</obj_name>
  <obj_reftable>livrval</obj_reftable>
  <obj_hashval>434746959c7293595ca0cda8f5a19c0e</obj_hashval>
  <obj_text>CREATE INDEX idx_livrval_codobiect ON livrval USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_livrval_gest</obj_name>
  <obj_reftable>livrval</obj_reftable>
  <obj_hashval>6f16d6daa4e74904b0b6c2e5b1d23e70</obj_hashval>
  <obj_text>CREATE INDEX idx_livrval_gest ON livrval USING btree (gest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_mailuri_codtipdoc</obj_name>
  <obj_reftable>mailuri</obj_reftable>
  <obj_hashval>6bc0f5384d92b85a753228e61ea4a9a5</obj_hashval>
  <obj_text>CREATE INDEX idx_mailuri_codtipdoc ON mailuri USING btree (coddoc, tipdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_man_i1_codcmdprodmat</obj_name>
  <obj_reftable>tmp_manevra_intr1</obj_reftable>
  <obj_hashval>bdf7a9237d602d06a7184045882f194c</obj_hashval>
  <obj_text>CREATE INDEX idx_man_i1_codcmdprodmat ON tmp_manevra_intr1 USING btree (codcmdprodmat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_man_i1_codintr1</obj_name>
  <obj_reftable>tmp_manevra_intr1</obj_reftable>
  <obj_hashval>7e4d8c52c78aed27efdc5669d7df76b0</obj_hashval>
  <obj_text>CREATE INDEX idx_man_i1_codintr1 ON tmp_manevra_intr1 USING btree (codintr1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_man_i1_codnirstoc</obj_name>
  <obj_reftable>tmp_manevra_intr1</obj_reftable>
  <obj_hashval>5159e81ffa69cc09bbd33eb9cf460265</obj_hashval>
  <obj_text>CREATE INDEX idx_man_i1_codnirstoc ON tmp_manevra_intr1 USING btree (codnirstoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_man_i1_codobiect</obj_name>
  <obj_reftable>tmp_manevra_intr1</obj_reftable>
  <obj_hashval>c7f6dbcfa763b3df81f20bd770f92b86</obj_hashval>
  <obj_text>CREATE INDEX idx_man_i1_codobiect ON tmp_manevra_intr1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_mancons_mat</obj_name>
  <obj_reftable>manevra_consum</obj_reftable>
  <obj_hashval>b5a95a003a5c91d8442698f2f1301724</obj_hashval>
  <obj_text>CREATE INDEX idx_mancons_mat ON manevra_consum USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_mancons_prod</obj_name>
  <obj_reftable>manevra_consum</obj_reftable>
  <obj_hashval>dc67ea2b6720462e39760134bbdcffdc</obj_hashval>
  <obj_text>CREATE INDEX idx_mancons_prod ON manevra_consum USING btree (produs)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_mancons_semi</obj_name>
  <obj_reftable>manevra_consum</obj_reftable>
  <obj_hashval>ef864876783be11adefdd2dbd62ccbe3</obj_hashval>
  <obj_text>CREATE INDEX idx_mancons_semi ON manevra_consum USING btree (nodparinte)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_manevra_unic_codunic</obj_name>
  <obj_reftable>manevra_unic</obj_reftable>
  <obj_hashval>f81ad4a314557c3093c390a97f4fb055</obj_hashval>
  <obj_text>CREATE INDEX idx_manevra_unic_codunic ON manevra_unic USING btree (codunic)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_manevra_unic_userid</obj_name>
  <obj_reftable>manevra_unic</obj_reftable>
  <obj_hashval>7f23efbf26b0f0aec7dec2ffa2afd61d</obj_hashval>
  <obj_text>CREATE INDEX idx_manevra_unic_userid ON manevra_unic USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_manprodlink_codcmdprodman</obj_name>
  <obj_reftable>manprodlink</obj_reftable>
  <obj_hashval>d15623b5879fff7918d1222db9fc3a37</obj_hashval>
  <obj_text>CREATE INDEX idx_manprodlink_codcmdprodman ON manprodlink USING btree (codcmdprodman)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_mascaserart1_codmasca</obj_name>
  <obj_reftable>mascaserart1</obj_reftable>
  <obj_hashval>3d4feb33b3f23fcba8563db8c7539aa4</obj_hashval>
  <obj_text>CREATE INDEX idx_mascaserart1_codmasca ON mascaserart1 USING btree (codmasca)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_mastermifix_codnirstoc</obj_name>
  <obj_reftable>mastermifix</obj_reftable>
  <obj_hashval>c3a3435c144c7dd7f955ea3f31fda78f</obj_hashval>
  <obj_text>CREATE INDEX idx_mastermifix_codnirstoc ON mastermifix USING btree (codnirstoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_mese_codsala</obj_name>
  <obj_reftable>mese</obj_reftable>
  <obj_hashval>0005bed77b92dbdf9fa8f58932f720b2</obj_hashval>
  <obj_text>CREATE INDEX idx_mese_codsala ON mese USING btree (codsala)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_mese1_codmasa</obj_name>
  <obj_reftable>mese1</obj_reftable>
  <obj_hashval>e2466ad8e1198cc0b0e51b73fe8d3b02</obj_hashval>
  <obj_text>CREATE INDEX idx_mese1_codmasa ON mese1 USING btree (codmasa)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_mifix1_anluna</obj_name>
  <obj_reftable>mifix1</obj_reftable>
  <obj_hashval>5f4019863471d4d465999c240029c5d0</obj_hashval>
  <obj_text>CREATE INDEX idx_mifix1_anluna ON mifix1 USING btree ((((anstart * (12)::numeric) + lunastart)))</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_mifix1_anstart</obj_name>
  <obj_reftable>mifix1</obj_reftable>
  <obj_hashval>effa1e86b9a954224faac1b918632441</obj_hashval>
  <obj_text>CREATE INDEX idx_mifix1_anstart ON mifix1 USING btree (anstart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_mifix1_codclasif</obj_name>
  <obj_reftable>mifix1</obj_reftable>
  <obj_hashval>d4f438082076f588de164f5e37f7b41e</obj_hashval>
  <obj_text>CREATE INDEX idx_mifix1_codclasif ON mifix1 USING btree (codclasif)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_mifix1_codmifix</obj_name>
  <obj_reftable>mifix1</obj_reftable>
  <obj_hashval>69d9659e501ad2ce3310659929f08586</obj_hashval>
  <obj_text>CREATE INDEX idx_mifix1_codmifix ON mifix1 USING btree (codmifix, (((anstart * (12)::numeric) + lunastart)))</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_mifix1_codnirstoc</obj_name>
  <obj_reftable>mifix1</obj_reftable>
  <obj_hashval>aa77e378f63ebdf57bfe62f1856eca38</obj_hashval>
  <obj_text>CREATE INDEX idx_mifix1_codnirstoc ON mifix1 USING btree (codnirstoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_mifix1_codpers</obj_name>
  <obj_reftable>mifix1</obj_reftable>
  <obj_hashval>29276f630b572e8a41b1b1d04c42cdb4</obj_hashval>
  <obj_text>CREATE INDEX idx_mifix1_codpers ON mifix1 USING btree (codpers)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_mifix1_lunastart</obj_name>
  <obj_reftable>mifix1</obj_reftable>
  <obj_hashval>d349072836f7c90ea822752dc22e7ed6</obj_hashval>
  <obj_text>CREATE INDEX idx_mifix1_lunastart ON mifix1 USING btree (lunastart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_modi_state_doc</obj_name>
  <obj_reftable>modi_state</obj_reftable>
  <obj_hashval>4d20ce56fcb55a213ed5bfdf7f405370</obj_hashval>
  <obj_text>CREATE INDEX idx_modi_state_doc ON modi_state USING btree (tablename, codmaster)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_modi_state_modidate</obj_name>
  <obj_reftable>modi_state</obj_reftable>
  <obj_hashval>f5253838d2b6c10ab9e35754c8ceb74f</obj_hashval>
  <obj_text>CREATE INDEX idx_modi_state_modidate ON modi_state USING btree (modidate)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_modi_state_tablename</obj_name>
  <obj_reftable>modi_state</obj_reftable>
  <obj_hashval>6aef2b3cdf82e356a0ebed076b402ea5</obj_hashval>
  <obj_text>CREATE INDEX idx_modi_state_tablename ON modi_state USING btree (tablename, modidate)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_modificari_tcd</obj_name>
  <obj_reftable>modificari</obj_reftable>
  <obj_hashval>567e9fa70b600c92da543208454fba6c</obj_hashval>
  <obj_text>CREATE INDEX idx_modificari_tcd ON modificari USING btree (tablename, codmaster, datamodif)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_modplata2_codcard</obj_name>
  <obj_reftable>modplata2</obj_reftable>
  <obj_hashval>1c712eed9c2040fc67cac8fc928cdc3b</obj_hashval>
  <obj_text>CREATE INDEX idx_modplata2_codcard ON modplata2 USING btree (codcard)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_modplata2_codies</obj_name>
  <obj_reftable>modplata2</obj_reftable>
  <obj_hashval>29cedce8bbd4014828eb04c088047d1e</obj_hashval>
  <obj_text>CREATE INDEX idx_modplata2_codies ON modplata2 USING btree (codies)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_moduriplati_codies</obj_name>
  <obj_reftable>moduriplati</obj_reftable>
  <obj_hashval>05510c13465c44e2dc3f543bf76f6c1d</obj_hashval>
  <obj_text>CREATE INDEX idx_moduriplati_codies ON moduriplati USING btree (codies)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nagenda_codgest</obj_name>
  <obj_reftable>nagenda</obj_reftable>
  <obj_hashval>c567d195513217b9040fa3ba5cb1afa3</obj_hashval>
  <obj_text>CREATE INDEX idx_nagenda_codgest ON nagenda USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nagenda_codlocalit</obj_name>
  <obj_reftable>nagenda</obj_reftable>
  <obj_hashval>0dc532d4930ffc9c3829268a6eb99079</obj_hashval>
  <obj_text>CREATE INDEX idx_nagenda_codlocalit ON nagenda USING btree (codlocalit)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nagenda_codpart</obj_name>
  <obj_reftable>nagenda</obj_reftable>
  <obj_hashval>af7ea7ec05075b01229943fab7dd3a23</obj_hashval>
  <obj_text>CREATE INDEX idx_nagenda_codpart ON nagenda USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nagenda1_al</obj_name>
  <obj_reftable>nagenda1</obj_reftable>
  <obj_hashval>9857e2aedc2feb0903582397d5a76cad</obj_hashval>
  <obj_text>CREATE INDEX idx_nagenda1_al ON nagenda1 USING btree (codagenda, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nagenti1_codpers</obj_name>
  <obj_reftable>nagenti1</obj_reftable>
  <obj_hashval>7e43bd9f3a233de2c9fb0fbcb824da85</obj_hashval>
  <obj_text>CREATE INDEX idx_nagenti1_codpers ON nagenti1 USING btree (codpers)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nagentiproc_codagent1</obj_name>
  <obj_reftable>nagentiproc</obj_reftable>
  <obj_hashval>a2b8f6c7dd5892d0f829754b6bc7560f</obj_hashval>
  <obj_text>CREATE INDEX idx_nagentiproc_codagent1 ON nagentiproc USING btree (codagent1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nagentiproc_codobiect</obj_name>
  <obj_reftable>nagentiproc</obj_reftable>
  <obj_hashval>098ff62c625604e374cee1965b1312ec</obj_hashval>
  <obj_text>CREATE INDEX idx_nagentiproc_codobiect ON nagentiproc USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nagentiproc_codpart</obj_name>
  <obj_reftable>nagentiproc</obj_reftable>
  <obj_hashval>3c1335bc258e4b79ee590c8974dac718</obj_hashval>
  <obj_text>CREATE INDEX idx_nagentiproc_codpart ON nagentiproc USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nagentiproc_codpers</obj_name>
  <obj_reftable>nagentiproc</obj_reftable>
  <obj_hashval>a50727b91594eaff1cee16636dc3d171</obj_hashval>
  <obj_text>CREATE INDEX idx_nagentiproc_codpers ON nagentiproc USING btree (codpers)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nagentiproc_peclasea</obj_name>
  <obj_reftable>nagentiproc</obj_reftable>
  <obj_hashval>5c44025a5c3aaf23478ecc12e28c8d14</obj_hashval>
  <obj_text>CREATE INDEX idx_nagentiproc_peclasea ON nagentiproc USING btree (peclasea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nagentiproc_peclasep</obj_name>
  <obj_reftable>nagentiproc</obj_reftable>
  <obj_hashval>4bfca98ebb4647b39fbfeb086e00c2bf</obj_hashval>
  <obj_text>CREATE INDEX idx_nagentiproc_peclasep ON nagentiproc USING btree (peclasep)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nagentival_codagent1</obj_name>
  <obj_reftable>nagentival</obj_reftable>
  <obj_hashval>c8de15f08e73845d55ceb71d53574e87</obj_hashval>
  <obj_text>CREATE INDEX idx_nagentival_codagent1 ON nagentival USING btree (codagent1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nagentival_codmoneda</obj_name>
  <obj_reftable>nagentival</obj_reftable>
  <obj_hashval>218fa8682f4fdc0f95264bd29b1a4e1c</obj_hashval>
  <obj_text>CREATE INDEX idx_nagentival_codmoneda ON nagentival USING btree (codmoneda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nagentival_codpers</obj_name>
  <obj_reftable>nagentival</obj_reftable>
  <obj_hashval>ce731b358d8c5ba96241957324a07665</obj_hashval>
  <obj_text>CREATE INDEX idx_nagentival_codpers ON nagentival USING btree (codpers)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nart_casademarcat</obj_name>
  <obj_reftable>nart</obj_reftable>
  <obj_hashval>622ae9433a0c9f34357490b02998cc48</obj_hashval>
  <obj_text>CREATE INDEX idx_nart_casademarcat ON nart USING btree (casademarcat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nart_clasa</obj_name>
  <obj_reftable>nart</obj_reftable>
  <obj_hashval>ec2fc1f897069031f734a7204da6b3aa</obj_hashval>
  <obj_text>CREATE INDEX idx_nart_clasa ON nart USING btree (clasa)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nart_contserviciu</obj_name>
  <obj_reftable>nart</obj_reftable>
  <obj_hashval>8455948a7ca2074117659d5f0257a9a2</obj_hashval>
  <obj_text>CREATE INDEX idx_nart_contserviciu ON nart USING btree (contserviciu)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nart_gestimplicita</obj_name>
  <obj_reftable>nart</obj_reftable>
  <obj_hashval>60d61ba7d2e69dfff2bf56e49b5c2cc4</obj_hashval>
  <obj_text>CREATE INDEX idx_nart_gestimplicita ON nart USING btree (gestimplicita)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nart_tiparticol</obj_name>
  <obj_reftable>nart</obj_reftable>
  <obj_hashval>d6b8d2d01706999a912ff89d33a70cb2</obj_hashval>
  <obj_text>CREATE INDEX idx_nart_tiparticol ON nart USING btree (tiparticol)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nart_um</obj_name>
  <obj_reftable>nart</obj_reftable>
  <obj_hashval>0cbede8ea91ac9e9c95df9a750a6dd8c</obj_hashval>
  <obj_text>CREATE INDEX idx_nart_um ON nart USING btree (um)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nart_um1</obj_name>
  <obj_reftable>nart</obj_reftable>
  <obj_hashval>01f54a397dbd25e66a54cdd8ed6d935c</obj_hashval>
  <obj_text>CREATE INDEX idx_nart_um1 ON nart USING btree (um1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nart_um2</obj_name>
  <obj_reftable>nart</obj_reftable>
  <obj_hashval>4b60c29057ce3d52cacc843b870240a0</obj_hashval>
  <obj_text>CREATE INDEX idx_nart_um2 ON nart USING btree (um2)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nart1_al</obj_name>
  <obj_reftable>nart1</obj_reftable>
  <obj_hashval>72d521a735bf49b669afc8a6ca512443</obj_hashval>
  <obj_text>CREATE INDEX idx_nart1_al ON nart1 USING btree (codarticol, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nart1_anluna</obj_name>
  <obj_reftable>nart1</obj_reftable>
  <obj_hashval>2427a3685ea860f3e542d09c24eb3b0a</obj_hashval>
  <obj_text>CREATE INDEX idx_nart1_anluna ON nart1 USING btree ((((anstart * (12)::numeric) + lunastart)))</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nart1_codaccize</obj_name>
  <obj_reftable>nart1</obj_reftable>
  <obj_hashval>56ad8cdb6c9fbc5ae1cac98afde9a608</obj_hashval>
  <obj_text>CREATE INDEX idx_nart1_codaccize ON nart1 USING btree (codaccize)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nart1_codaccizedvi</obj_name>
  <obj_reftable>nart1</obj_reftable>
  <obj_hashval>a8059a747f9c19c880fb6ac731ba1d28</obj_hashval>
  <obj_text>CREATE INDEX idx_nart1_codaccizedvi ON nart1 USING btree (codaccizedvi)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nart1_codarticol</obj_name>
  <obj_reftable>nart1</obj_reftable>
  <obj_hashval>3fb8271bbe493db7ac22c6cf1bc5d142</obj_hashval>
  <obj_text>CREATE INDEX idx_nart1_codarticol ON nart1 USING btree (codarticol)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nart1_codtaxa1</obj_name>
  <obj_reftable>nart1</obj_reftable>
  <obj_hashval>bb6f034542cddc478f583ee3e25b54fd</obj_hashval>
  <obj_text>CREATE INDEX idx_nart1_codtaxa1 ON nart1 USING btree (codtaxa1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nart1_codtaxa2</obj_name>
  <obj_reftable>nart1</obj_reftable>
  <obj_hashval>d9e260a117916f42ce215e214abb3acb</obj_hashval>
  <obj_text>CREATE INDEX idx_nart1_codtaxa2 ON nart1 USING btree (codtaxa2)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nart1_codtva</obj_name>
  <obj_reftable>nart1</obj_reftable>
  <obj_hashval>8d51917f6e5f4fbab37a48e93bc74c56</obj_hashval>
  <obj_text>CREATE INDEX idx_nart1_codtva ON nart1 USING btree (codtva)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartamb_codobiect</obj_name>
  <obj_reftable>nartamb</obj_reftable>
  <obj_hashval>4d3a46c3bdfa7df70739f5020b2ded96</obj_hashval>
  <obj_text>CREATE INDEX idx_nartamb_codobiect ON nartamb USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartatr_codarticol</obj_name>
  <obj_reftable>nartatr</obj_reftable>
  <obj_hashval>4f58130596ee23e60b476e4eadea40bb</obj_hashval>
  <obj_text>CREATE INDEX idx_nartatr_codarticol ON nartatr USING btree (codarticol)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartatr_codatribut</obj_name>
  <obj_reftable>nartatr</obj_reftable>
  <obj_hashval>baed11575d8d2859e67c6249df1d28f4</obj_hashval>
  <obj_text>CREATE INDEX idx_nartatr_codatribut ON nartatr USING btree (codatribut)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartatr_codvalpredef</obj_name>
  <obj_reftable>nartatr</obj_reftable>
  <obj_hashval>1a9b4159ec3153734f82b9df863fc04a</obj_hashval>
  <obj_text>CREATE INDEX idx_nartatr_codvalpredef ON nartatr USING btree (codvalpredef)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartcli_codextern</obj_name>
  <obj_reftable>nartcli</obj_reftable>
  <obj_hashval>b9f8df25ad94825d022110de573cbe41</obj_hashval>
  <obj_text>CREATE INDEX idx_nartcli_codextern ON nartcli USING btree (codextern)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartcli_codobiect</obj_name>
  <obj_reftable>nartcli</obj_reftable>
  <obj_hashval>95b5160f069dfe199a0fee00753da53a</obj_hashval>
  <obj_text>CREATE INDEX idx_nartcli_codobiect ON nartcli USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartcli_codpart</obj_name>
  <obj_reftable>nartcli</obj_reftable>
  <obj_hashval>88a37edcf0d6a1d60418e49d0ad0d545</obj_hashval>
  <obj_text>CREATE INDEX idx_nartcli_codpart ON nartcli USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartcli_umsec</obj_name>
  <obj_reftable>nartcli</obj_reftable>
  <obj_hashval>e9ef41779f55fd39973d8a32840aa472</obj_hashval>
  <obj_text>CREATE INDEX idx_nartcli_umsec ON nartcli USING btree (umsec)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartdim_codarticol</obj_name>
  <obj_reftable>nartdim</obj_reftable>
  <obj_hashval>5bd35446cfd18e24cf586a82dbbc0b75</obj_hashval>
  <obj_text>CREATE INDEX idx_nartdim_codarticol ON nartdim USING btree (codarticol)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartimplicite_codarticol</obj_name>
  <obj_reftable>nartimplicite</obj_reftable>
  <obj_hashval>28046c04a4a91076115a4d54a0f4b279</obj_hashval>
  <obj_text>CREATE INDEX idx_nartimplicite_codarticol ON nartimplicite USING btree (codarticol)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartimplicite_codsubunit</obj_name>
  <obj_reftable>nartimplicite</obj_reftable>
  <obj_hashval>f00eb9c89efdc99f9dd12ff43a557b2b</obj_hashval>
  <obj_text>CREATE INDEX idx_nartimplicite_codsubunit ON nartimplicite USING btree (codsubunit)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartimplicite_contimpl</obj_name>
  <obj_reftable>nartimplicite</obj_reftable>
  <obj_hashval>e921c72294adede79c21ae860f11cb13</obj_hashval>
  <obj_text>CREATE INDEX idx_nartimplicite_contimpl ON nartimplicite USING btree (contimplicit)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartimplicite_gestimpl</obj_name>
  <obj_reftable>nartimplicite</obj_reftable>
  <obj_hashval>0702a1d9ff68a1cc63c90beb5d2326ac</obj_hashval>
  <obj_text>CREATE INDEX idx_nartimplicite_gestimpl ON nartimplicite USING btree (gestimplicita)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartimplicite_locatieimpl</obj_name>
  <obj_reftable>nartimplicite</obj_reftable>
  <obj_hashval>fa41ed62e82cf6440daf0151262e56a2</obj_hashval>
  <obj_text>CREATE INDEX idx_nartimplicite_locatieimpl ON nartimplicite USING btree (locatieimplicita)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartobj_codarticol</obj_name>
  <obj_reftable>nartobj</obj_reftable>
  <obj_hashval>a282dd81e628a6c548ddf8b4229dcbd0</obj_hashval>
  <obj_text>CREATE INDEX idx_nartobj_codarticol ON nartobj USING btree (codarticol)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartobj_codextern</obj_name>
  <obj_reftable>nartobj</obj_reftable>
  <obj_hashval>18dee47062d9a242eba795200cb900b9</obj_hashval>
  <obj_text>CREATE INDEX idx_nartobj_codextern ON nartobj USING btree (codextern)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartobj_codintern</obj_name>
  <obj_reftable>nartobj</obj_reftable>
  <obj_hashval>44f8865ece54d28f67e440e308390d14</obj_hashval>
  <obj_text>CREATE INDEX idx_nartobj_codintern ON nartobj USING btree (codintern)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartobj_codproducator</obj_name>
  <obj_reftable>nartobj</obj_reftable>
  <obj_hashval>bd2502802264684c0a777c64922765d3</obj_hashval>
  <obj_text>CREATE INDEX idx_nartobj_codproducator ON nartobj USING btree (codproducator)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartobj1_al</obj_name>
  <obj_reftable>nartobj1</obj_reftable>
  <obj_hashval>ef496b464549887cc1d1a5d759de797c</obj_hashval>
  <obj_text>CREATE INDEX idx_nartobj1_al ON nartobj1 USING btree (codobiect, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartobj1_anluna</obj_name>
  <obj_reftable>nartobj1</obj_reftable>
  <obj_hashval>7d7d31f79998e267725e25adb3c194a2</obj_hashval>
  <obj_text>CREATE INDEX idx_nartobj1_anluna ON nartobj1 USING btree ((((anstart * (12)::numeric) + lunastart)))</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartobj1_codobiect</obj_name>
  <obj_reftable>nartobj1</obj_reftable>
  <obj_hashval>fe353b01b25dc0b71b467ecdeb20d340</obj_hashval>
  <obj_text>CREATE INDEX idx_nartobj1_codobiect ON nartobj1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartobjgest_codgest</obj_name>
  <obj_reftable>nartobjgest</obj_reftable>
  <obj_hashval>b3fd93b1cb547819740465b6ba7fccc5</obj_hashval>
  <obj_text>CREATE INDEX idx_nartobjgest_codgest ON nartobjgest USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartobjgest_codobiect</obj_name>
  <obj_reftable>nartobjgest</obj_reftable>
  <obj_hashval>f309e27b247996c9ea9672724839d2f1</obj_hashval>
  <obj_text>CREATE INDEX idx_nartobjgest_codobiect ON nartobjgest USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartobjimp_codsubunit</obj_name>
  <obj_reftable>nartobjimp</obj_reftable>
  <obj_hashval>eab8f9d5e2b07aa9cc66af2b61597579</obj_hashval>
  <obj_text>CREATE INDEX idx_nartobjimp_codsubunit ON nartobjimp USING btree (codsubunit)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartobjsubunit</obj_name>
  <obj_reftable>nartobjsubunit</obj_reftable>
  <obj_hashval>808d427f04e4ef725c536d14cf4c72e0</obj_hashval>
  <obj_text>CREATE INDEX idx_nartobjsubunit ON nartobjsubunit USING btree (codobiect, subunitate, codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartobjtrad_codobiect</obj_name>
  <obj_reftable>nartobjtrad</obj_reftable>
  <obj_hashval>3d6b3e730cef538a6d9ca00cd725ba69</obj_hashval>
  <obj_text>CREATE INDEX idx_nartobjtrad_codobiect ON nartobjtrad USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nartopt_codobiect</obj_name>
  <obj_reftable>nartopt</obj_reftable>
  <obj_hashval>1fcc1cbf9f6c797e81e499e33da4cdac</obj_hashval>
  <obj_text>CREATE INDEX idx_nartopt_codobiect ON nartopt USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_natrib1_codatribut</obj_name>
  <obj_reftable>natrib1</obj_reftable>
  <obj_hashval>dcd88070dd0da3496dfd7896bab4914a</obj_hashval>
  <obj_text>CREATE INDEX idx_natrib1_codatribut ON natrib1 USING btree (codatribut)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_natrobj_codartatr</obj_name>
  <obj_reftable>natrobj</obj_reftable>
  <obj_hashval>11af6d0d3e81e3c8e2e842fe411401a3</obj_hashval>
  <obj_text>CREATE INDEX idx_natrobj_codartatr ON natrobj USING btree (codartatr)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_natrobj_codobiect</obj_name>
  <obj_reftable>natrobj</obj_reftable>
  <obj_hashval>0375c930ce146ad7455cb22bec0c310a</obj_hashval>
  <obj_text>CREATE INDEX idx_natrobj_codobiect ON natrobj USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nbankcont_codlocalitate</obj_name>
  <obj_reftable>nbankcont</obj_reftable>
  <obj_hashval>7591a2cd010ae025a204b61c93e3a999</obj_hashval>
  <obj_text>CREATE INDEX idx_nbankcont_codlocalitate ON nbankcont USING btree (codlocalitate)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nbankcont_codmoneda</obj_name>
  <obj_reftable>nbankcont</obj_reftable>
  <obj_hashval>0dc12a83e5a2430a82c92e23e7a2fb2f</obj_hashval>
  <obj_text>CREATE INDEX idx_nbankcont_codmoneda ON nbankcont USING btree (codmoneda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nbankcont1_al</obj_name>
  <obj_reftable>nbankcont1</obj_reftable>
  <obj_hashval>19ef3c31ca8e707dd21c461f76f3cd9b</obj_hashval>
  <obj_text>CREATE INDEX idx_nbankcont1_al ON nbankcont1 USING btree (codbankcont, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nbankcont1_codbankcont</obj_name>
  <obj_reftable>nbankcont1</obj_reftable>
  <obj_hashval>3e66926842edbd437cdbbaa3dfa46cca</obj_hashval>
  <obj_text>CREATE INDEX idx_nbankcont1_codbankcont ON nbankcont1 USING btree (codbankcont)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nbankcont1_codiobanca</obj_name>
  <obj_reftable>nbankcont1</obj_reftable>
  <obj_hashval>706cd0dd899ce1babe070578dcd78ffd</obj_hashval>
  <obj_text>CREATE INDEX idx_nbankcont1_codiobanca ON nbankcont1 USING btree (codiobanca)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nbanksoldluna</obj_name>
  <obj_reftable>nbanksoldluna</obj_reftable>
  <obj_hashval>9b78e38343b0aa4a3dd7272e83af47a5</obj_hashval>
  <obj_text>CREATE INDEX idx_nbanksoldluna ON nbanksoldluna USING btree (an, luna, codbankcont)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nc_moneda</obj_name>
  <obj_reftable>nc</obj_reftable>
  <obj_hashval>13f847f6ddf87ac08e5bfd7860d36a06</obj_hashval>
  <obj_text>CREATE INDEX idx_nc_moneda ON nc USING btree (moneda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nc_part</obj_name>
  <obj_reftable>nc</obj_reftable>
  <obj_hashval>e3d8d9d847a0a5a34eb8ac3d01b584bb</obj_hashval>
  <obj_text>CREATE INDEX idx_nc_part ON nc USING btree (part)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nc_subunitatea</obj_name>
  <obj_reftable>nc</obj_reftable>
  <obj_hashval>857a21d7bc32b6d58441407b3c8de706</obj_hashval>
  <obj_text>CREATE INDEX idx_nc_subunitatea ON nc USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nc1_codgest</obj_name>
  <obj_reftable>nc1</obj_reftable>
  <obj_hashval>bc99e3c96be1863e7f3b959713b3e77d</obj_hashval>
  <obj_text>CREATE INDEX idx_nc1_codgest ON nc1 USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nc1_codnc</obj_name>
  <obj_reftable>nc1</obj_reftable>
  <obj_hashval>8f000594481763a581307bfd048a3d5d</obj_hashval>
  <obj_text>CREATE INDEX idx_nc1_codnc ON nc1 USING btree (codnc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nc1_contc</obj_name>
  <obj_reftable>nc1</obj_reftable>
  <obj_hashval>a34da53a2af48cf5a8c5ec56a99edfae</obj_hashval>
  <obj_text>CREATE INDEX idx_nc1_contc ON nc1 USING btree (contc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nc1_contd</obj_name>
  <obj_reftable>nc1</obj_reftable>
  <obj_hashval>bdd1ee0fae77cab453d62f4c813008d3</obj_hashval>
  <obj_text>CREATE INDEX idx_nc1_contd ON nc1 USING btree (contd)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nclasea_codparinte</obj_name>
  <obj_reftable>nclasea</obj_reftable>
  <obj_hashval>d38a7eefaf32bd5b2c9d492fd1aff65f</obj_hashval>
  <obj_text>CREATE INDEX idx_nclasea_codparinte ON nclasea USING btree (codparinte)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nclaseas_codparinte</obj_name>
  <obj_reftable>nclaseas</obj_reftable>
  <obj_hashval>c49461862c88062d38b55b9609fe50e0</obj_hashval>
  <obj_text>CREATE INDEX idx_nclaseas_codparinte ON nclaseas USING btree (codparinte)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nclaseg_codparinte</obj_name>
  <obj_reftable>nclaseg</obj_reftable>
  <obj_hashval>495fb4fd11d6e557ee27f5eaf74aa4cc</obj_hashval>
  <obj_text>CREATE INDEX idx_nclaseg_codparinte ON nclaseg USING btree (codparinte)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nclaseint_codparinte</obj_name>
  <obj_reftable>nclaseint</obj_reftable>
  <obj_hashval>8067aa17ed0c108a143ccc4a4ed91076</obj_hashval>
  <obj_text>CREATE INDEX idx_nclaseint_codparinte ON nclaseint USING btree (codparinte)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nclasemf_codparinte</obj_name>
  <obj_reftable>nclasemf</obj_reftable>
  <obj_hashval>5c0e2f9d60ed143421bc67d15923d6fe</obj_hashval>
  <obj_text>CREATE INDEX idx_nclasemf_codparinte ON nclasemf USING btree (codparinte)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nclasep_codparinte</obj_name>
  <obj_reftable>nclasep</obj_reftable>
  <obj_hashval>0be23b9fd4742fc5727e03f5c83af9d9</obj_hashval>
  <obj_text>CREATE INDEX idx_nclasep_codparinte ON nclasep USING btree (codparinte)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nclaseprod_codparinte</obj_name>
  <obj_reftable>nclaseprod</obj_reftable>
  <obj_hashval>00ac724222d292e0378dc73d59b12c1c</obj_hashval>
  <obj_text>CREATE INDEX idx_nclaseprod_codparinte ON nclaseprod USING btree (codparinte)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncodfiscretail_codfiscal</obj_name>
  <obj_reftable>ncodfiscretail</obj_reftable>
  <obj_hashval>ca165dc92eefe6d2b6db667c7f0e1069</obj_hashval>
  <obj_text>CREATE INDEX idx_ncodfiscretail_codfiscal ON ncodfiscretail USING btree (cod_codfiscal)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncont_codparinte</obj_name>
  <obj_reftable>ncont</obj_reftable>
  <obj_hashval>7768f125a6d6c63461e39676370cd9c7</obj_hashval>
  <obj_text>CREATE INDEX idx_ncont_codparinte ON ncont USING btree (codparinte)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncont1_al</obj_name>
  <obj_reftable>ncont1</obj_reftable>
  <obj_hashval>a13f65ea6caa71817812f9e6080e3962</obj_hashval>
  <obj_text>CREATE INDEX idx_ncont1_al ON ncont1 USING btree (codcont, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncont1_codcont</obj_name>
  <obj_reftable>ncont1</obj_reftable>
  <obj_hashval>eabfa37e5f06c94dd8baaf67feb2e6c1</obj_hashval>
  <obj_text>CREATE INDEX idx_ncont1_codcont ON ncont1 USING btree (codcont)</obj_text>
</row>

<row>
  <obj_type>TYPE</obj_type>
  <obj_name>t_objatrib</obj_name>
  <obj_hashval>848b8ab427910a90b4200a552aa20e10</obj_hashval>
  <obj_text>CREATE TYPE t_objatrib AS (
  "den" character varying,
  "cod" character varying,
  "val" character varying
);</obj_text>
</row>

<row>
  <obj_type>TYPE</obj_type>
  <obj_name>termene_contract</obj_name>
  <obj_hashval>c42aa8eff3f78bd266f61b7b7442e846</obj_hashval>
  <obj_text>CREATE TYPE termene_contract AS (
  "tip" character varying,
  "termen1" date,
  "termen2" date,
  "termen3" character varying,
  "disc1" numeric,
  "disc2" numeric,
  "disc3" character varying
);</obj_text>
</row>

<row>
  <obj_type>TYPE</obj_type>
  <obj_name>test</obj_name>
  <obj_hashval>b053f30a46fef88ee1d079ece24116f7</obj_hashval>
  <obj_text>CREATE TYPE test AS (
  "term1" date,
  "term2" character varying(100),
  "disc1" numeric(20,0),
  "disc2" numeric,
  "disc3" character varying
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>adaosm</obj_name>
  <obj_hashval>74f47ac86378f6df4404cbcccda29a22</obj_hashval>
  <obj_text>CREATE TABLE adaosm (
  "codadaosm" numeric(20,0) NOT NULL,
  "data" date
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>adaosm1</obj_name>
  <obj_hashval>5ed58d0a4980ba2c6c41247bc11744a4</obj_hashval>
  <obj_text>CREATE TABLE adaosm1 (
  "codadaosm1" numeric(20,0) NOT NULL,
  "codadaosm" numeric(20,0),
  "limsup" numeric(20,7),
  "cotaadaost" numeric(20,7),
  "cotaadaosd" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>al_tables</obj_name>
  <obj_hashval>16bfdbb8088132174b0ff377647cc8a0</obj_hashval>
  <obj_text>CREATE TABLE al_tables (
  "table_name" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>alerte</obj_name>
  <obj_hashval>d8014c2a2b6fb3472b28a5bc2a810d79</obj_hashval>
  <obj_text>CREATE TABLE alerte (
  "codalerta" numeric(20,0) NOT NULL,
  "denumire" character varying(200),
  "codintern" character varying(200),
  "tipalerta" numeric(1,0),
  "obs" character varying(200),
  "userid" numeric(20,0),
  "datacreare" date,
  "codorar" numeric(20,0),
  "mailto" character varying(1000),
  "custommessage" text,
  "mail_individual" numeric(1,0),
  "customsubject" character varying(200),
  "subunitatea" numeric(20,0),
  "sql" text,
  "codfirma" numeric(20,0),
  "customfooter" text,
  "fielduri" character varying(1000),
  "titluxls" character varying(100),
  "tipexport" numeric(2,0),
  "ordonare" character varying(200),
  "sqlcusms" numeric(1,0),
  "jobid" numeric(20,0),
  "webserver" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncont1_continkidsold</obj_name>
  <obj_reftable>ncont1</obj_reftable>
  <obj_hashval>a2aaad1b2f1a7a6676a54db974e63755</obj_hashval>
  <obj_text>CREATE INDEX idx_ncont1_continkidsold ON ncont1 USING btree (continkidsold)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>alerte0</obj_name>
  <obj_hashval>bed6bf1ad95d8d918f94a07141bc471f</obj_hashval>
  <obj_text>CREATE TABLE alerte0 (
  "codalerta0" numeric(20,0) NOT NULL,
  "codalerta" numeric(20,0),
  "username" character varying(50),
  "userid" numeric(20,0),
  "recipient" character varying(200),
  "email" numeric(1,0),
  "mess" numeric(1,0),
  "task" numeric(1,0),
  "sms" numeric(1,0),
  "tel" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>alerte_info</obj_name>
  <obj_hashval>28639de83e67f31e769203154a617cb6</obj_hashval>
  <obj_text>CREATE TABLE alerte_info (
  "codalertainfo" numeric(20,0),
  "codalerta" numeric(20,0),
  "dataexec" timestamp(0) without time zone,
  "rezultat" text,
  "info_filtre" text,
  "codrulare" numeric(20,0),
  "mailto" character varying(500),
  "taskto" character varying(100),
  "messto" character varying(100),
  "smsto" character varying(50),
  "filename" character varying(50),
  "filebody" bytea
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>analiza</obj_name>
  <obj_hashval>2bdedb29b227aedb36d3a115a3fb33dc</obj_hashval>
  <obj_text>CREATE TABLE analiza (
  "codanaliza" numeric(20,0) NOT NULL,
  "den_analiza" character varying(100),
  "idelement" numeric(10,0),
  "idcentru" numeric(10,0),
  "inactiv" numeric(1,0),
  "tip" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>analiza1</obj_name>
  <obj_hashval>775b21f750f57d4d69b77efeb171ea0e</obj_hashval>
  <obj_text>CREATE TABLE analiza1 (
  "codanaliza1" numeric(20,0) NOT NULL,
  "codanaliza" numeric(20,0),
  "coddescriptor" numeric(20,0),
  "indexlocal" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>analizanod</obj_name>
  <obj_hashval>b37fe70e2460d71e7fac9eafc4813f82</obj_hashval>
  <obj_text>CREATE TABLE analizanod (
  "codanalizanod" numeric(20,0) NOT NULL,
  "codanaliza" numeric(20,0),
  "nodparinte" numeric(20,0),
  "codanaliza1" numeric(20,0),
  "coddescriptor1" numeric(20,0),
  "pozitie" numeric(10,0),
  "inactiv" numeric(1,0),
  "simbolnod" character varying(100),
  "dennod" character varying(200),
  "tip" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>apeltelefon</obj_name>
  <obj_hashval>9b0ed2d62d26afa2d7014b68f31bfc3d</obj_hashval>
  <obj_text>CREATE TABLE apeltelefon (
  "codapel" numeric(20,0) NOT NULL,
  "idapel" character varying(20),
  "stare" character varying(20),
  "telefon" character varying(20),
  "apelant" character varying(100),
  "dataora" timestamp(6) without time zone,
  "preluat" numeric(1,0),
  "client" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>asigurari</obj_name>
  <obj_hashval>c8e963d250e99433b00b13617ca30931</obj_hashval>
  <obj_text>CREATE TABLE asigurari (
  "codasigurare" numeric(20,0) NOT NULL,
  "nrdoc" character varying(50),
  "codpart" numeric(20,0),
  "datastart" date,
  "termen" date,
  "codclasemf" numeric(20,0),
  "obs" character varying(250),
  "subunitatea" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "valoare" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>asigurari1</obj_name>
  <obj_hashval>eeeb9da2b258a5138eb19df783be4dee</obj_hashval>
  <obj_text>CREATE TABLE asigurari1 (
  "codasigurare1" numeric(20,0) NOT NULL,
  "codasigurare" numeric(20,0),
  "indexlocal" numeric(10,0),
  "codmifix" numeric(20,0),
  "valasig" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>avariecaroserie</obj_name>
  <obj_hashval>babdd328a4c5828f621d86bc60b34730</obj_hashval>
  <obj_text>CREATE TABLE avariecaroserie (
  "codavarie" numeric(20,0) NOT NULL,
  "codcomanda" numeric(10,0),
  "defect" numeric(1,0),
  "cand" numeric(1,0),
  "x" numeric(5,0),
  "y" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>avizcantlock</obj_name>
  <obj_hashval>5424cfbe7677a6eae1cabbed6bed19d8</obj_hashval>
  <obj_text>CREATE TABLE avizcantlock (
  "codlinieaviz" numeric(20,0),
  "codliniefact" numeric(20,0),
  "tipaviz" numeric(2,0),
  "cant" numeric(20,7),
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>aviziesluna</obj_name>
  <obj_hashval>5c86693770a3cfb265935b0b20d62c91</obj_hashval>
  <obj_text>CREATE TABLE aviziesluna (
  "codies1" numeric(20,0),
  "rest" numeric(20,7),
  "an" numeric(5,0),
  "luna" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>avizintluna</obj_name>
  <obj_hashval>d1fd9ebe03c9c1b4c1472778a5a4a27a</obj_hashval>
  <obj_text>CREATE TABLE avizintluna (
  "codintr1" numeric(20,0),
  "rest" numeric(20,7),
  "an" numeric(5,0),
  "luna" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>awbcomanda</obj_name>
  <obj_hashval>f4c275e31f4185d8964f51dbfb53a0a7</obj_hashval>
  <obj_text>CREATE TABLE awbcomanda (
  "codawbcomanda" numeric(20,0) NOT NULL,
  "codcomanda" numeric(20,0),
  "curier" numeric(2,0),
  "numar" character varying(30),
  "doc" text,
  "pdf" bytea,
  "infostadiu" character varying(500),
  "postat" numeric(1,0),
  "datapostare" timestamp(0) without time zone,
  "tarif" numeric(10,2),
  "tva" numeric(10,2),
  "tipdoc" numeric(5,0),
  "shipmentid" numeric(20,0),
  "parcelsid" text
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>bal_stoc_rest</obj_name>
  <obj_hashval>96146c000a78f5348bac3a0558c12630</obj_hashval>
  <obj_text>CREATE TABLE bal_stoc_rest (
  "cod" numeric(20,0),
  "codgest" numeric(20,0),
  "datastart" timestamp(6) without time zone,
  "dataend" timestamp(6) without time zone
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>bankautentif</obj_name>
  <obj_hashval>71fbdcaf85045379f8e8c26387a8227d</obj_hashval>
  <obj_text>CREATE TABLE bankautentif (
  "cod" numeric(20,0) NOT NULL,
  "tip_api" numeric(2,0),
  "iban" character varying(30),
  "token" character varying(2000),
  "consentid" character varying(100),
  "externalid" character varying(100),
  "datatoken" date
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>bcar</obj_name>
  <obj_hashval>318f2293af4620e57216add8a89d938c</obj_hashval>
  <obj_text>CREATE TABLE bcar (
  "codbcar" numeric(20,0) NOT NULL,
  "operat" numeric(1,0),
  "codcantarin" numeric(20,0),
  "codcantarout" numeric(20,0),
  "tipdoc" numeric(20,0),
  "coddoc1" numeric(20,0),
  "prefixdoc" character varying(10),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "carnetdoc" numeric(20,0),
  "prefixavizin" character varying(2),
  "nravizin" numeric(20,0),
  "nravizout" numeric(20,0),
  "dataavizin" date,
  "isumiditate" numeric(20,7),
  "iaumiditate" numeric(20,7),
  "isstraine" numeric(20,7),
  "iastraine" numeric(20,7),
  "isincoltit" numeric(20,7),
  "iaincoltit" numeric(20,7),
  "ishectolitrica" numeric(20,7),
  "iahectolitrica" numeric(20,7),
  "isgluten" numeric(20,7),
  "iagluten" numeric(20,7),
  "isfuzaritate" numeric(20,7),
  "iafuzaritate" numeric(20,7),
  "iscadere" numeric(20,7),
  "iacadere" numeric(20,7),
  "isdeformare" numeric(20,7),
  "iadeformare" numeric(20,7),
  "issticlozitate" numeric(20,7),
  "iasticlozitate" numeric(20,7),
  "issparturi" numeric(20,7),
  "iasparturi" numeric(20,7),
  "codobiect" numeric(20,0),
  "brutkg" numeric(20,7),
  "tara" numeric(20,7),
  "netkg" numeric(20,7),
  "utilkg" numeric(20,7),
  "pretachiz" numeric(20,7),
  "pretuscare" numeric(20,7),
  "codpartener" numeric(20,0),
  "codsediu" numeric(20,0),
  "coddelegat" numeric(20,0),
  "codsubunitate" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "codserie" numeric(20,0),
  "retur" numeric(1,0),
  "modcantar" numeric(1,0),
  "useridblocaj" numeric(20,0),
  "tipbcar" numeric(1,0),
  "codgestimpl" numeric(20,0),
  "codlocatimpl" numeric(20,0),
  "observatii" character varying(40),
  "codpers" numeric(20,0),
  "mijltransp" character varying(15),
  "nrtransp" character varying(30),
  "codauto" numeric(20,0),
  "icumiditate" numeric(20,7),
  "icstraine" numeric(20,7),
  "icincoltit" numeric(20,7),
  "ichectolitrica" numeric(20,7),
  "icgluten" numeric(20,7),
  "icfuzaritate" numeric(20,7),
  "iccadere" numeric(20,7),
  "icdeformare" numeric(20,7),
  "icsticlozitate" numeric(20,7),
  "icsparturi" numeric(20,7),
  "netkgclient" numeric(20,7),
  "utilkgclient" numeric(20,7),
  "infoclient" numeric(1,0),
  "coddoc1storno" numeric(20,0),
  "codbcardest" numeric(20,0),
  "codcontract1" numeric(20,0),
  "nrremorca" character varying(15),
  "codremorca" numeric(20,0),
  "utilstaskg" numeric(20,7),
  "pretconfirmat" numeric(20,7),
  "isproteina" numeric(20,7),
  "isaflatoxina" numeric(20,7),
  "isatac_plosnita" numeric(20,7),
  "iscontinut_ulei" numeric(20,7),
  "isaciditate" numeric(20,7),
  "iaproteina" numeric(20,7),
  "iaaflatoxina" numeric(20,7),
  "iaatac_plosnita" numeric(20,7),
  "iacontinut_ulei" numeric(20,7),
  "iaaciditate" numeric(20,7),
  "icproteina" numeric(20,7),
  "icaflatoxina" numeric(20,7),
  "icatac_plosnita" numeric(20,7),
  "iccontinut_ulei" numeric(20,7),
  "icaciditate" numeric(20,7),
  "iasistave" numeric(20,7),
  "iarefractie" numeric(20,7),
  "iaindice_w" numeric(20,7),
  "iatoxina_don" numeric(20,7),
  "iaboabe_toxice" numeric(20,7),
  "issistave" numeric(20,7),
  "isrefractie" numeric(20,7),
  "isindice_w" numeric(20,7),
  "istoxina_don" numeric(20,7),
  "isboabe_toxice" numeric(20,7),
  "icsistave" numeric(20,7),
  "icrefractie" numeric(20,7),
  "icindice_w" numeric(20,7),
  "ictoxina_don" numeric(20,7),
  "icboabe_toxice" numeric(20,7),
  "pierderiteh" numeric(20,7),
  "moneda" numeric(20,0),
  "curs" numeric(22,4),
  "id_citire1" character varying(20),
  "id_citire2" character varying(20)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>bonlinkerr</obj_name>
  <obj_hashval>3cccd364112e81ab79c109b424d44695</obj_hashval>
  <obj_text>CREATE TABLE bonlinkerr (
  "codbonlinkerr" numeric(20,0) NOT NULL,
  "codies" numeric(20,0),
  "bonuri" text
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>bonmasa</obj_name>
  <obj_hashval>cd066f98e2237fdd99f220cc4b1daaed</obj_hashval>
  <obj_text>CREATE TABLE bonmasa (
  "cod" numeric(20,0),
  "denumire" character varying(50),
  "valoare" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>bugetanaliza</obj_name>
  <obj_hashval>d867ea9d1ae52e651c066ba70659e931</obj_hashval>
  <obj_text>CREATE TABLE bugetanaliza (
  "codanaliza" numeric(20,0),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "codanalizanod" numeric(20,0),
  "codcentru" numeric(20,0),
  "codelement" numeric(20,0),
  "buget" numeric(20,7),
  "tip" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>bugetcap</obj_name>
  <obj_hashval>43b6450c142a57b4f628299525a46635</obj_hashval>
  <obj_text>CREATE TABLE bugetcap (
  "codbugetcap" numeric(20,0) NOT NULL,
  "codbugetprod" numeric(20,0),
  "tipcap" numeric(5,0),
  "codclasea" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncont1_conttransfc</obj_name>
  <obj_reftable>ncont1</obj_reftable>
  <obj_hashval>234945ab6e8164aaf8eed323ed9d5999</obj_hashval>
  <obj_text>CREATE INDEX idx_ncont1_conttransfc ON ncont1 USING btree (conttransfc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncont1_conttransfd</obj_name>
  <obj_reftable>ncont1</obj_reftable>
  <obj_hashval>15c729c46ded666a7809e63786a7d5f4</obj_hashval>
  <obj_text>CREATE INDEX idx_ncont1_conttransfd ON ncont1 USING btree (conttransfd)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncont1_sincronizare</obj_name>
  <obj_reftable>ncont1</obj_reftable>
  <obj_hashval>62a07be2803a9df8126217c41ad8fd7f</obj_hashval>
  <obj_text>CREATE INDEX idx_ncont1_sincronizare ON ncont1 USING btree (sincronizare)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncontechiv_contnou</obj_name>
  <obj_reftable>ncontechiv</obj_reftable>
  <obj_hashval>1d183110328c2da09963db36eef94369</obj_hashval>
  <obj_text>CREATE INDEX idx_ncontechiv_contnou ON ncontechiv USING btree (contnou)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncontechiv_contvechi</obj_name>
  <obj_reftable>ncontechiv</obj_reftable>
  <obj_hashval>150acc8ff8e8d502f9b74fa15966ff50</obj_hashval>
  <obj_text>CREATE INDEX idx_ncontechiv_contvechi ON ncontechiv USING btree (contvechi)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>bugetcap1</obj_name>
  <obj_hashval>ec251fc1ce72f1165225ca4150e3da7f</obj_hashval>
  <obj_text>CREATE TABLE bugetcap1 (
  "codbugetcap1" numeric(20,0) NOT NULL,
  "codbugetprod" numeric(20,0),
  "codclasea" numeric(20,0),
  "s1" numeric(20,7),
  "s2" numeric(20,7),
  "s3" numeric(20,7),
  "s4" numeric(20,7),
  "s5" numeric(20,7),
  "s6" numeric(20,7),
  "s7" numeric(20,7),
  "s8" numeric(20,7),
  "s9" numeric(20,7),
  "s10" numeric(20,7),
  "s11" numeric(20,7),
  "s12" numeric(20,7),
  "s13" numeric(20,7),
  "s14" numeric(20,7),
  "s15" numeric(20,7),
  "s16" numeric(20,7),
  "s17" numeric(20,7),
  "s18" numeric(20,7),
  "s19" numeric(20,7),
  "s20" numeric(20,7),
  "s21" numeric(20,7),
  "s22" numeric(20,7),
  "s23" numeric(20,7),
  "s24" numeric(20,7),
  "s25" numeric(20,7),
  "s26" numeric(20,7),
  "s27" numeric(20,7),
  "s28" numeric(20,7),
  "s29" numeric(20,7),
  "s30" numeric(20,7),
  "s31" numeric(20,7),
  "s32" numeric(20,7),
  "s33" numeric(20,7),
  "s34" numeric(20,7),
  "s35" numeric(20,7),
  "s36" numeric(20,7),
  "s37" numeric(20,7),
  "s38" numeric(20,7),
  "s39" numeric(20,7),
  "s40" numeric(20,7),
  "s41" numeric(20,7),
  "s42" numeric(20,7),
  "s43" numeric(20,7),
  "s44" numeric(20,7),
  "s45" numeric(20,7),
  "s46" numeric(20,7),
  "s47" numeric(20,7),
  "s48" numeric(20,7),
  "s49" numeric(20,7),
  "s50" numeric(20,7),
  "s51" numeric(20,7),
  "s52" numeric(20,7),
  "s53" numeric(20,7),
  "l1" numeric(20,7),
  "l2" numeric(20,7),
  "l3" numeric(20,7),
  "l4" numeric(20,7),
  "l5" numeric(20,7),
  "l6" numeric(20,7),
  "l7" numeric(20,7),
  "l8" numeric(20,7),
  "l9" numeric(20,7),
  "l10" numeric(20,7),
  "l11" numeric(20,7),
  "l12" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>bugetcl</obj_name>
  <obj_hashval>a2ff9844fca6cdb38a1f9b6c9fe32a84</obj_hashval>
  <obj_text>CREATE TABLE bugetcl (
  "codbugetcl" numeric(20,0) NOT NULL,
  "codbugetprod" numeric(20,0),
  "codelembuget" numeric(20,0),
  "l1" numeric(20,7),
  "l2" numeric(20,7),
  "l3" numeric(20,7),
  "l4" numeric(20,7),
  "l5" numeric(20,7),
  "l6" numeric(20,7),
  "l7" numeric(20,7),
  "l8" numeric(20,7),
  "l9" numeric(20,7),
  "l10" numeric(20,7),
  "l11" numeric(20,7),
  "l12" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>bugetmf</obj_name>
  <obj_hashval>b958bfb0e011751e80c60d369609b68e</obj_hashval>
  <obj_text>CREATE TABLE bugetmf (
  "codbugetmf" numeric(20,0) NOT NULL,
  "codmifix" numeric(20,0),
  "userid" numeric(20,0),
  "subunitatea" numeric(20,0),
  "datacreare" timestamp(6) without time zone
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>bugetmf1</obj_name>
  <obj_hashval>81651005b02e92534ec424c547dbc324</obj_hashval>
  <obj_text>CREATE TABLE bugetmf1 (
  "codbugetmf1" numeric(20,0) NOT NULL,
  "codbugetmf" numeric(20,0),
  "indexlocal" numeric(10,0),
  "denumire" character varying(200),
  "valoare" numeric(20,7),
  "databuget" date,
  "obs" character varying(250),
  "stadiu" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>bugetprod</obj_name>
  <obj_hashval>91fc9be23cf6081f82348ed4f0f4832e</obj_hashval>
  <obj_text>CREATE TABLE bugetprod (
  "codbugetprod" numeric(20,0) NOT NULL,
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "subunitatea" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "obs" character varying(400),
  "anulat" numeric(1,0),
  "blocat" numeric(1,0),
  "operat" numeric(1,0),
  "saptamana" numeric(2,0),
  "animport" numeric(4,0),
  "saptamanaf" numeric(2,0),
  "anf" numeric(4,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>bugetprodp</obj_name>
  <obj_hashval>644aec4463099f263d3651321c596b4a</obj_hashval>
  <obj_text>CREATE TABLE bugetprodp (
  "codbugetprodp" numeric(20,0) NOT NULL,
  "codbugetprod" numeric(20,0),
  "codobiect" numeric(20,0),
  "s1" numeric(20,7),
  "s2" numeric(20,7),
  "s3" numeric(20,7),
  "s4" numeric(20,7),
  "s5" numeric(20,7),
  "s6" numeric(20,7),
  "s7" numeric(20,7),
  "s8" numeric(20,7),
  "s9" numeric(20,7),
  "s10" numeric(20,7),
  "s11" numeric(20,7),
  "s12" numeric(20,7),
  "s13" numeric(20,7),
  "s14" numeric(20,7),
  "s15" numeric(20,7),
  "s16" numeric(20,7),
  "s17" numeric(20,7),
  "s18" numeric(20,7),
  "s19" numeric(20,7),
  "s20" numeric(20,7),
  "s21" numeric(20,7),
  "s22" numeric(20,7),
  "s23" numeric(20,7),
  "s24" numeric(20,7),
  "s25" numeric(20,7),
  "s26" numeric(20,7),
  "s27" numeric(20,7),
  "s28" numeric(20,7),
  "s29" numeric(20,7),
  "s30" numeric(20,7),
  "s31" numeric(20,7),
  "s32" numeric(20,7),
  "s33" numeric(20,7),
  "s34" numeric(20,7),
  "s35" numeric(20,7),
  "s36" numeric(20,7),
  "s37" numeric(20,7),
  "s38" numeric(20,7),
  "s39" numeric(20,7),
  "s40" numeric(20,7),
  "s41" numeric(20,7),
  "s42" numeric(20,7),
  "s43" numeric(20,7),
  "s44" numeric(20,7),
  "s45" numeric(20,7),
  "s46" numeric(20,7),
  "s47" numeric(20,7),
  "s48" numeric(20,7),
  "s49" numeric(20,7),
  "s50" numeric(20,7),
  "s51" numeric(20,7),
  "s52" numeric(20,7),
  "s53" numeric(20,7),
  "l1" numeric(20,7),
  "l2" numeric(20,7),
  "l3" numeric(20,7),
  "l4" numeric(20,7),
  "l5" numeric(20,7),
  "l6" numeric(20,7),
  "l7" numeric(20,7),
  "l8" numeric(20,7),
  "l9" numeric(20,7),
  "l10" numeric(20,7),
  "l11" numeric(20,7),
  "l12" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>bugetprodt</obj_name>
  <obj_hashval>ba24dce04884b4ddfae335efa3df4a69</obj_hashval>
  <obj_text>CREATE TABLE bugetprodt (
  "codbugetprodt" numeric(20,0) NOT NULL,
  "codbugetprod" numeric(20,0),
  "codobiect" numeric(20,0),
  "s1" numeric(20,7),
  "s2" numeric(20,7),
  "s3" numeric(20,7),
  "s4" numeric(20,7),
  "s5" numeric(20,7),
  "s6" numeric(20,7),
  "s7" numeric(20,7),
  "s8" numeric(20,7),
  "s9" numeric(20,7),
  "s10" numeric(20,7),
  "s11" numeric(20,7),
  "s12" numeric(20,7),
  "s13" numeric(20,7),
  "s14" numeric(20,7),
  "s15" numeric(20,7),
  "s16" numeric(20,7),
  "s17" numeric(20,7),
  "s18" numeric(20,7),
  "s19" numeric(20,7),
  "s20" numeric(20,7),
  "s21" numeric(20,7),
  "s22" numeric(20,7),
  "s23" numeric(20,7),
  "s24" numeric(20,7),
  "s25" numeric(20,7),
  "s26" numeric(20,7),
  "s27" numeric(20,7),
  "s28" numeric(20,7),
  "s29" numeric(20,7),
  "s30" numeric(20,7),
  "s31" numeric(20,7),
  "s32" numeric(20,7),
  "s33" numeric(20,7),
  "s34" numeric(20,7),
  "s35" numeric(20,7),
  "s36" numeric(20,7),
  "s37" numeric(20,7),
  "s38" numeric(20,7),
  "s39" numeric(20,7),
  "s40" numeric(20,7),
  "s41" numeric(20,7),
  "s42" numeric(20,7),
  "s43" numeric(20,7),
  "s44" numeric(20,7),
  "s45" numeric(20,7),
  "s46" numeric(20,7),
  "s47" numeric(20,7),
  "s48" numeric(20,7),
  "s49" numeric(20,7),
  "s50" numeric(20,7),
  "s51" numeric(20,7),
  "s52" numeric(20,7),
  "s53" numeric(20,7),
  "l1" numeric(20,7),
  "l2" numeric(20,7),
  "l3" numeric(20,7),
  "l4" numeric(20,7),
  "l5" numeric(20,7),
  "l6" numeric(20,7),
  "l7" numeric(20,7),
  "l8" numeric(20,7),
  "l9" numeric(20,7),
  "l10" numeric(20,7),
  "l11" numeric(20,7),
  "l12" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>bugetprodv</obj_name>
  <obj_hashval>7e3e403dea6ba8b14b72a5b045bd8ed7</obj_hashval>
  <obj_text>CREATE TABLE bugetprodv (
  "codbugetprodv" numeric(20,0) NOT NULL,
  "codbugetprod" numeric(20,0),
  "codobiect" numeric(20,0),
  "s1" numeric(20,7),
  "s2" numeric(20,7),
  "s3" numeric(20,7),
  "s4" numeric(20,7),
  "s5" numeric(20,7),
  "s6" numeric(20,7),
  "s7" numeric(20,7),
  "s8" numeric(20,7),
  "s9" numeric(20,7),
  "s10" numeric(20,7),
  "s11" numeric(20,7),
  "s12" numeric(20,7),
  "s13" numeric(20,7),
  "s14" numeric(20,7),
  "s15" numeric(20,7),
  "s16" numeric(20,7),
  "s17" numeric(20,7),
  "s18" numeric(20,7),
  "s19" numeric(20,7),
  "s20" numeric(20,7),
  "s21" numeric(20,7),
  "s22" numeric(20,7),
  "s23" numeric(20,7),
  "s24" numeric(20,7),
  "s25" numeric(20,7),
  "s26" numeric(20,7),
  "s27" numeric(20,7),
  "s28" numeric(20,7),
  "s29" numeric(20,7),
  "s30" numeric(20,7),
  "s31" numeric(20,7),
  "s32" numeric(20,7),
  "s33" numeric(20,7),
  "s34" numeric(20,7),
  "s35" numeric(20,7),
  "s36" numeric(20,7),
  "s37" numeric(20,7),
  "s38" numeric(20,7),
  "s39" numeric(20,7),
  "s40" numeric(20,7),
  "s41" numeric(20,7),
  "s42" numeric(20,7),
  "s43" numeric(20,7),
  "s44" numeric(20,7),
  "s45" numeric(20,7),
  "s46" numeric(20,7),
  "s47" numeric(20,7),
  "s48" numeric(20,7),
  "s49" numeric(20,7),
  "s50" numeric(20,7),
  "s51" numeric(20,7),
  "s52" numeric(20,7),
  "s53" numeric(20,7),
  "l1" numeric(20,7),
  "l2" numeric(20,7),
  "l3" numeric(20,7),
  "l4" numeric(20,7),
  "l5" numeric(20,7),
  "l6" numeric(20,7),
  "l7" numeric(20,7),
  "l8" numeric(20,7),
  "l9" numeric(20,7),
  "l10" numeric(20,7),
  "l11" numeric(20,7),
  "l12" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>bugetvcl</obj_name>
  <obj_hashval>d639341840c198a34cbb4fd0f1dc8826</obj_hashval>
  <obj_text>CREATE TABLE bugetvcl (
  "codbugetvcl" numeric(20,0) NOT NULL,
  "codbugetprod" numeric(20,0),
  "codobiect" numeric(20,0),
  "codclasea" numeric(20,0),
  "tipcap" numeric(1,0),
  "coefum" numeric(20,7),
  "l1_cap" numeric(20,7),
  "l1_stoc" numeric(20,7),
  "l1_vanz" numeric(20,7),
  "l1_target" numeric(20,7),
  "l1_npcant" numeric(20,7),
  "l1_pret" numeric(20,7),
  "l1_npval" numeric(20,7),
  "l1_coefcap" numeric(20,7),
  "l1_npfcant" numeric(20,7),
  "l1_npfval" numeric(20,7),
  "l1_pretmmr" numeric(20,7),
  "l1_pretmat" numeric(20,7),
  "l1_var" numeric(20,7),
  "l1_est" numeric(20,7),
  "l2_cap" numeric(20,7),
  "l2_stoc" numeric(20,7),
  "l2_vanz" numeric(20,7),
  "l2_target" numeric(20,7),
  "l2_npcant" numeric(20,7),
  "l2_pret" numeric(20,7),
  "l2_npval" numeric(20,7),
  "l2_coefcap" numeric(20,7),
  "l2_npfcant" numeric(20,7),
  "l2_npfval" numeric(20,7),
  "l2_pretmmr" numeric(20,7),
  "l2_pretmat" numeric(20,7),
  "l2_var" numeric(20,7),
  "l2_est" numeric(20,7),
  "l3_cap" numeric(20,7),
  "l3_stoc" numeric(20,7),
  "l3_vanz" numeric(20,7),
  "l3_target" numeric(20,7),
  "l3_npcant" numeric(20,7),
  "l3_pret" numeric(20,7),
  "l3_npval" numeric(20,7),
  "l3_coefcap" numeric(20,7),
  "l3_npfcant" numeric(20,7),
  "l3_npfval" numeric(20,7),
  "l3_pretmmr" numeric(20,7),
  "l3_pretmat" numeric(20,7),
  "l3_var" numeric(20,7),
  "l3_est" numeric(20,7),
  "l4_cap" numeric(20,7),
  "l4_stoc" numeric(20,7),
  "l4_vanz" numeric(20,7),
  "l4_target" numeric(20,7),
  "l4_npcant" numeric(20,7),
  "l4_pret" numeric(20,7),
  "l4_npval" numeric(20,7),
  "l4_coefcap" numeric(20,7),
  "l4_npfcant" numeric(20,7),
  "l4_npfval" numeric(20,7),
  "l4_pretmmr" numeric(20,7),
  "l4_pretmat" numeric(20,7),
  "l4_var" numeric(20,7),
  "l4_est" numeric(20,7),
  "l5_cap" numeric(20,7),
  "l5_stoc" numeric(20,7),
  "l5_vanz" numeric(20,7),
  "l5_target" numeric(20,7),
  "l5_npcant" numeric(20,7),
  "l5_pret" numeric(20,7),
  "l5_npval" numeric(20,7),
  "l5_coefcap" numeric(20,7),
  "l5_npfcant" numeric(20,7),
  "l5_npfval" numeric(20,7),
  "l5_pretmmr" numeric(20,7),
  "l5_pretmat" numeric(20,7),
  "l5_var" numeric(20,7),
  "l5_est" numeric(20,7),
  "l6_cap" numeric(20,7),
  "l6_stoc" numeric(20,7),
  "l6_vanz" numeric(20,7),
  "l6_target" numeric(20,7),
  "l6_npcant" numeric(20,7),
  "l6_pret" numeric(20,7),
  "l6_npval" numeric(20,7),
  "l6_coefcap" numeric(20,7),
  "l6_npfcant" numeric(20,7),
  "l6_npfval" numeric(20,7),
  "l6_pretmmr" numeric(20,7),
  "l6_pretmat" numeric(20,7),
  "l6_var" numeric(20,7),
  "l6_est" numeric(20,7),
  "l7_cap" numeric(20,7),
  "l7_stoc" numeric(20,7),
  "l7_vanz" numeric(20,7),
  "l7_target" numeric(20,7),
  "l7_npcant" numeric(20,7),
  "l7_pret" numeric(20,7),
  "l7_npval" numeric(20,7),
  "l7_coefcap" numeric(20,7),
  "l7_npfcant" numeric(20,7),
  "l7_npfval" numeric(20,7),
  "l7_pretmmr" numeric(20,7),
  "l7_pretmat" numeric(20,7),
  "l7_var" numeric(20,7),
  "l7_est" numeric(20,7),
  "l8_cap" numeric(20,7),
  "l8_stoc" numeric(20,7),
  "l8_vanz" numeric(20,7),
  "l8_target" numeric(20,7),
  "l8_npcant" numeric(20,7),
  "l8_pret" numeric(20,7),
  "l8_npval" numeric(20,7),
  "l8_coefcap" numeric(20,7),
  "l8_npfcant" numeric(20,7),
  "l8_npfval" numeric(20,7),
  "l8_pretmmr" numeric(20,7),
  "l8_pretmat" numeric(20,7),
  "l8_var" numeric(20,7),
  "l8_est" numeric(20,7),
  "l9_cap" numeric(20,7),
  "l9_stoc" numeric(20,7),
  "l9_vanz" numeric(20,7),
  "l9_target" numeric(20,7),
  "l9_npcant" numeric(20,7),
  "l9_pret" numeric(20,7),
  "l9_npval" numeric(20,7),
  "l9_coefcap" numeric(20,7),
  "l9_npfcant" numeric(20,7),
  "l9_npfval" numeric(20,7),
  "l9_pretmmr" numeric(20,7),
  "l9_pretmat" numeric(20,7),
  "l9_var" numeric(20,7),
  "l9_est" numeric(20,7),
  "l10_cap" numeric(20,7),
  "l10_stoc" numeric(20,7),
  "l10_vanz" numeric(20,7),
  "l10_target" numeric(20,7),
  "l10_npcant" numeric(20,7),
  "l10_pret" numeric(20,7),
  "l10_npval" numeric(20,7),
  "l10_coefcap" numeric(20,7),
  "l10_npfcant" numeric(20,7),
  "l10_npfval" numeric(20,7),
  "l10_pretmmr" numeric(20,7),
  "l10_pretmat" numeric(20,7),
  "l10_var" numeric(20,7),
  "l10_est" numeric(20,7),
  "l11_cap" numeric(20,7),
  "l11_stoc" numeric(20,7),
  "l11_vanz" numeric(20,7),
  "l11_target" numeric(20,7),
  "l11_npcant" numeric(20,7),
  "l11_pret" numeric(20,7),
  "l11_npval" numeric(20,7),
  "l11_coefcap" numeric(20,7),
  "l11_npfcant" numeric(20,7),
  "l11_npfval" numeric(20,7),
  "l11_pretmmr" numeric(20,7),
  "l11_pretmat" numeric(20,7),
  "l11_var" numeric(20,7),
  "l11_est" numeric(20,7),
  "l12_cap" numeric(20,7),
  "l12_stoc" numeric(20,7),
  "l12_vanz" numeric(20,7),
  "l12_target" numeric(20,7),
  "l12_npcant" numeric(20,7),
  "l12_pret" numeric(20,7),
  "l12_npval" numeric(20,7),
  "l12_coefcap" numeric(20,7),
  "l12_npfcant" numeric(20,7),
  "l12_npfval" numeric(20,7),
  "l12_pretmmr" numeric(20,7),
  "l12_pretmat" numeric(20,7),
  "l12_var" numeric(20,7),
  "l12_est" numeric(20,7),
  "l1_npfval_orig" numeric(20,7),
  "l2_npfval_orig" numeric(20,7),
  "l3_npfval_orig" numeric(20,7),
  "l4_npfval_orig" numeric(20,7),
  "l5_npfval_orig" numeric(20,7),
  "l6_npfval_orig" numeric(20,7),
  "l7_npfval_orig" numeric(20,7),
  "l8_npfval_orig" numeric(20,7),
  "l9_npfval_orig" numeric(20,7),
  "l10_npfval_orig" numeric(20,7),
  "l11_npfval_orig" numeric(20,7),
  "l12_npfval_orig" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>bugetvl</obj_name>
  <obj_hashval>2de30789ef313c6453919dfb603fffdb</obj_hashval>
  <obj_text>CREATE TABLE bugetvl (
  "codbugetvl" numeric(20,0) NOT NULL,
  "codbugetprod" numeric(20,0),
  "codelembuget" numeric(20,0),
  "l1" numeric(20,7),
  "l2" numeric(20,7),
  "l3" numeric(20,7),
  "l4" numeric(20,7),
  "l5" numeric(20,7),
  "l6" numeric(20,7),
  "l7" numeric(20,7),
  "l8" numeric(20,7),
  "l9" numeric(20,7),
  "l10" numeric(20,7),
  "l11" numeric(20,7),
  "l12" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>caensec</obj_name>
  <obj_hashval>6fb837cab2e0427f6cbe81e9c26e19a1</obj_hashval>
  <obj_text>CREATE TABLE caensec (
  "codcaensec" numeric(20,0) NOT NULL,
  "caen" numeric(20,0),
  "denumire" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>campanii</obj_name>
  <obj_hashval>311ab9fed430c3a69f926b518348e1fa</obj_hashval>
  <obj_text>CREATE TABLE campanii (
  "codcampanie" numeric(20,0) NOT NULL,
  "dencampanie" character varying(200),
  "obiectiv" character varying(2000),
  "target" character varying(200),
  "datainit" date,
  "datafin" date,
  "codmoneda" numeric(20,0),
  "codresponsabil" numeric(20,0),
  "costestimat" numeric(20,7),
  "venitestimat" numeric(20,7),
  "codsubunitate" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncontechivsub_codcontechiv</obj_name>
  <obj_reftable>ncontechivsub</obj_reftable>
  <obj_hashval>ea385d8957ffaeb2ea923c364768a42b</obj_hashval>
  <obj_text>CREATE INDEX idx_ncontechivsub_codcontechiv ON ncontechivsub USING btree (codcontechiv)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>campaniicost</obj_name>
  <obj_hashval>c1925e9eeb7a1f42970983bc538db052</obj_hashval>
  <obj_text>CREATE TABLE campaniicost (
  "codcampaniecost" numeric(20,0) NOT NULL,
  "codcampanie" numeric(20,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(20,0),
  "indexlocal" numeric(20,0),
  "nrdoc" character varying(50),
  "datadoc" date,
  "valdoc" numeric(20,7),
  "prefixdoc" character varying(10),
  "codpart" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>campaniipart</obj_name>
  <obj_hashval>ba5992850eff4d4a0b0d6d95fa3c73f9</obj_hashval>
  <obj_text>CREATE TABLE campaniipart (
  "codcampaniepart" numeric(20,0) NOT NULL,
  "codcampanie" numeric(20,0),
  "codpart" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>campaniivenit</obj_name>
  <obj_hashval>3feab83fb68c2be8727a561bb0cbfcee</obj_hashval>
  <obj_text>CREATE TABLE campaniivenit (
  "codcampanievenit" numeric(20,0) NOT NULL,
  "codcampanie" numeric(20,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(20,0),
  "indexlocal" numeric(20,0),
  "nrdoc" character varying(50),
  "datadoc" date,
  "valdoc" numeric(20,7),
  "prefixdoc" character varying(10),
  "codpart" numeric(20,0),
  "valfact" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>canamed</obj_name>
  <obj_hashval>e44716a779ea911bfc907536e72d78ef</obj_hashval>
  <obj_text>CREATE TABLE canamed (
  "codcanamed" numeric(20,0) NOT NULL,
  "datalista" date,
  "obs" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>canamed1</obj_name>
  <obj_hashval>c26a8093effbc9a271400d9ede305843</obj_hashval>
  <obj_text>CREATE TABLE canamed1 (
  "codcanamed1" numeric(20,0) NOT NULL,
  "codcanamed" numeric(20,0),
  "codcnpm" character varying(20),
  "codcim" character varying(20),
  "denprodus" character varying(250),
  "forma" character varying(250),
  "concentr" character varying(150),
  "firma" character varying(250),
  "dci" character varying(250),
  "ambalaj" character varying(350),
  "grupa" character varying(100),
  "pretprod" numeric(20,7),
  "pretrid" numeric(20,7),
  "pretam" numeric(20,7),
  "statutfrm" character varying(50),
  "statutanm" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cantar</obj_name>
  <obj_hashval>989c4ccc1f64c1b055b8232a1cd873a3</obj_hashval>
  <obj_text>CREATE TABLE cantar (
  "codcantar" numeric(20,0) NOT NULL,
  "codobiect" numeric(20,0),
  "tipdoc" numeric(20,0),
  "coddoc1" numeric(20,0),
  "total_kg" numeric(20,7),
  "tara_kg" numeric(20,7),
  "net_kg" numeric(20,7),
  "amb1_cod" numeric(20,0),
  "amb1_kg" numeric(20,7),
  "amb1_cant" numeric(20,0),
  "amb1_returnabil" numeric(1,0),
  "amb2_cod" numeric(20,0),
  "amb2_kg" numeric(20,7),
  "amb2_cant" numeric(20,0),
  "amb2_returnabil" numeric(1,0),
  "amb3_cod" numeric(20,0),
  "amb3_kg" numeric(20,7),
  "amb3_cant" numeric(20,0),
  "amb3_returnabil" numeric(1,0),
  "amb4_cod" numeric(20,0),
  "amb4_kg" numeric(20,7),
  "amb4_cant" numeric(20,0),
  "amb4_returnabil" numeric(1,0),
  "palet_kg" numeric(20,7),
  "transp1_cod" numeric(20,0),
  "transp1_kg" numeric(20,7),
  "transp1_cant" numeric(20,0),
  "transp2_cod" numeric(20,0),
  "transp2_kg" numeric(20,7),
  "transp2_cant" numeric(20,0),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "subunitatea" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "useridblocaj" numeric(20,0),
  "anulat" numeric(1,0),
  "indexcantar" numeric(2,0),
  "retur" numeric(1,0),
  "serie" numeric(20,0),
  "idcantar" numeric(20,0),
  "furnizor" numeric(20,0),
  "nraviz" numeric(20,0),
  "destinatie" numeric(1,0),
  "client" numeric(20,0),
  "subunitate" numeric(20,0),
  "gestiune" numeric(20,0),
  "carnetdoc" numeric(20,0),
  "seriadoc" character varying(20),
  "codcmd1" numeric(20,0),
  "amb5_cod" numeric(20,0),
  "amb5_kg" numeric(20,7),
  "amb5_cant" numeric(20,0),
  "amb5_returnabil" numeric(1,0),
  "amb6_cod" numeric(20,0),
  "amb6_kg" numeric(20,7),
  "amb6_cant" numeric(20,0),
  "amb6_returnabil" numeric(1,0),
  "id_cantarire" character varying(20),
  "transportator" character varying(50),
  "nrvehicol" character varying(20),
  "nrremorca" character varying(20),
  "cantdoc" numeric(20,7),
  "serieaviz" character varying(20)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cantare</obj_name>
  <obj_hashval>aefec6bfa09594dd909392bf09323cd9</obj_hashval>
  <obj_text>CREATE TABLE cantare (
  "codcantar" numeric(20,0),
  "tip" numeric(5,0),
  "denumire" character varying(50),
  "ip" character varying(20),
  "direxport" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>carduri</obj_name>
  <obj_hashval>4336aff62f19c8d7b6b1b28982ec1428</obj_hashval>
  <obj_text>CREATE TABLE carduri (
  "codcard" numeric(20,0) NOT NULL,
  "simbol" character varying(100),
  "denumire" character varying(250),
  "obs" character varying(500)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cashflow</obj_name>
  <obj_hashval>edbc730b49bd3a73825c18d98921af01</obj_hashval>
  <obj_text>CREATE TABLE cashflow (
  "codcashflow" numeric(20,0),
  "data" date,
  "codbankcont" numeric(20,0),
  "valoare" numeric(20,7),
  "carnetdoc" numeric(20,0),
  "nrdoc" numeric(20,0),
  "an" numeric(5,0),
  "luna" numeric(2,0),
  "subunitatea" numeric(20,0),
  "valoarederepartizat" numeric(20,0),
  "aprobat" numeric(1,0),
  "zile" numeric(5,0),
  "codmoneda" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cashflow1</obj_name>
  <obj_hashval>fff17f9f08e70b6de0a53cfefac57793</obj_hashval>
  <obj_text>CREATE TABLE cashflow1 (
  "codcashflow1" numeric(20,0),
  "codcashflow" numeric(20,0),
  "codobligpif" numeric(20,0),
  "valoare" numeric(20,7),
  "rest" numeric(20,7),
  "codmoneda" numeric(20,0),
  "indexlocal" numeric(20,0),
  "restconv" numeric(20,7),
  "datapropusa" date,
  "codop1" numeric(20,0),
  "codcontract2" numeric(20,0),
  "codncredit" numeric(20,0),
  "codpart" numeric(20,0),
  "doc" character varying(20),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "termen" date,
  "tip" numeric(1,0),
  "obs" character varying(300)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cashflow2</obj_name>
  <obj_hashval>51a7df2bebd91cdde3fc862f683d01e3</obj_hashval>
  <obj_text>CREATE TABLE cashflow2 (
  "codcashflow2" numeric(20,0),
  "codcashflow" numeric(20,0),
  "codobligpif" numeric(20,0),
  "valoare" numeric(20,7),
  "rest" numeric(20,7),
  "codmoneda" numeric(20,0),
  "indexlocal" numeric(20,0),
  "restconv" numeric(20,7),
  "datapropusa" date,
  "codop1" numeric(20,0),
  "codcontract2" numeric(20,0),
  "codncredit" numeric(20,0),
  "codpart" numeric(20,0),
  "doc" character varying(20),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "termen" date,
  "tip" numeric(1,0),
  "obs" character varying(300)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>castot_cursprepay</obj_name>
  <obj_hashval>8c5245f0f5a6fb44871b0368c121c7e3</obj_hashval>
  <obj_text>CREATE TABLE castot_cursprepay (
  "idfurnizor" numeric(10,0),
  "furnizor" character varying(50),
  "curs" numeric(20,7),
  "tipserviciu" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>castot_prepay</obj_name>
  <obj_hashval>8436f9fc14afae0737eb0dadbda77e26</obj_hashval>
  <obj_text>CREATE TABLE castot_prepay (
  "cod_castotprepay" numeric(20,0) NOT NULL,
  "furnizor" character varying(50),
  "idfurnizor" numeric(10,0),
  "serviciu" character varying(50),
  "idserviciu" character varying(50),
  "telefon" character varying(20),
  "moneda" character varying(5),
  "valoare" numeric(20,7),
  "valoareron" numeric(20,7),
  "trackingnumber" character varying(20),
  "datatranzactie" timestamp(6) without time zone,
  "pincode" character varying(20),
  "pincodevalid" character varying(10),
  "listatcm" numeric(1,0),
  "listatchitanta" numeric(1,0),
  "codemulare" numeric(20,0),
  "jsonresponse" text,
  "cod_scala" character varying(25),
  "pincode_serialno" character varying(25),
  "footer_text" text,
  "idtranzactie" character varying(25),
  "nrtranzwme" character varying(25),
  "tipincarcare" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>castot_utility</obj_name>
  <obj_hashval>f036cbcbd753949720a42ba0a5df0edf</obj_hashval>
  <obj_text>CREATE TABLE castot_utility (
  "cod_castotutility" numeric(20,0) NOT NULL,
  "furnizor" character varying(80),
  "serviciu" character varying(80),
  "deplata" numeric(20,7),
  "platit" numeric(20,7),
  "platit_text" character varying(80),
  "cod_scala" character varying(50),
  "datatranzactie" timestamp(6) without time zone,
  "codclient" character varying(50),
  "telefon" character varying(20),
  "nrfactura" character varying(30),
  "datafactura" timestamp(6) without time zone,
  "sucursala" character varying(30),
  "atmcod" character varying(30),
  "customcode1" character varying(30),
  "custompaymentfield3" character varying(30),
  "jsonresponse" text,
  "listat" numeric(1,0),
  "listatcm" numeric(1,0),
  "codemulare" numeric(20,0),
  "card" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>categartti</obj_name>
  <obj_hashval>91cc4581045aeda317b3fdd3fd5d59f3</obj_hashval>
  <obj_text>CREATE TABLE categartti (
  "codcategartti" numeric(20,0) NOT NULL,
  "denumire" character varying(200),
  "simbolp" numeric(20,0),
  "simboln" numeric(20,0),
  "simbolp1" numeric(20,0),
  "datastart" date,
  "datastop" date,
  "denumirep" character varying(200),
  "codp" numeric(20,0),
  "codn_stoc" numeric(20,0),
  "codn_serv" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>categconst</obj_name>
  <obj_hashval>2d2d218a5c2eef466fa657b49f81e04a</obj_hashval>
  <obj_text>CREATE TABLE categconst (
  "codcateg" numeric(20,0) NOT NULL,
  "denumire" character varying(100),
  "indexlocal" character varying(10),
  "tipcateg" character varying(1)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>centralizarenc</obj_name>
  <obj_hashval>e2d767ad81302e2a5999eaf8f4422719</obj_hashval>
  <obj_text>CREATE TABLE centralizarenc (
  "codcentralizare" numeric(20,0) NOT NULL,
  "codncredit" numeric(20,0),
  "codarticol" numeric(20,0),
  "codobiect" numeric(20,0),
  "codobiectasoc" numeric(20,0),
  "codobiectasocsec" numeric(20,0),
  "umsec" numeric(20,0),
  "diferente" numeric(20,7),
  "tiparticol" numeric(20,0),
  "facturat" numeric(20,7),
  "proctva" numeric(6,3),
  "codcentru" numeric(20,0),
  "obs" character varying(450),
  "cant" numeric(20,7),
  "codanalizanod" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>centrecost</obj_name>
  <obj_hashval>13dbb2ec7addb41eb49b8879406e4ebe</obj_hashval>
  <obj_text>CREATE TABLE centrecost (
  "codcentru" numeric(20,0) NOT NULL,
  "simbol" character varying(100),
  "denumire" character varying(100),
  "tipchelt" numeric(2,0),
  "tipaloc" numeric(2,0),
  "tip" numeric(1,0),
  "inactiv" numeric(1,0),
  "domeniu" character varying(20),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>centrecosta</obj_name>
  <obj_hashval>8d84155ba71437d7359ccceac4c3d580</obj_hashval>
  <obj_text>CREATE TABLE centrecosta (
  "codcentrua" numeric(20,0) NOT NULL,
  "codcentru" numeric(20,0),
  "codanaliza" numeric(20,0),
  "nodmaximanaliza1" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>certif</obj_name>
  <obj_hashval>7ca6a369f8a00bc75040d1f0fd10c17f</obj_hashval>
  <obj_text>CREATE TABLE certif (
  "codcertif" numeric(20,0) NOT NULL,
  "nrcertif" character varying(100),
  "dataprimire" date,
  "fisier" bytea,
  "codpart" numeric(20,0),
  "codobiect" numeric(20,0),
  "codserie" numeric(20,0),
  "numefisier" character varying(250),
  "ext" character varying(4),
  "subunitate" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "provenienta" character varying(250),
  "codtara" numeric(20,0),
  "obs" character varying(250),
  "tippart" numeric(1,0),
  "codgest" numeric(20,0),
  "carnetdoc" numeric(20,0),
  "seriadoc" character varying(20)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cfgactions</obj_name>
  <obj_hashval>9bbb43511965206e8f9fcfe58c4b1f34</obj_hashval>
  <obj_text>CREATE TABLE cfgactions (
  "codcfgactions" numeric(20,0) NOT NULL,
  "tipdoc" numeric(5,0),
  "tipsql" numeric(1,0),
  "tip" numeric(1,0),
  "id" numeric(5,0),
  "sqlite" text,
  "mesaj" character varying(150)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cfgtables</obj_name>
  <obj_hashval>615c578e0a3ef1385e894f43a791aa3d</obj_hashval>
  <obj_text>CREATE TABLE cfgtables (
  "codcfgtable" numeric(20,0),
  "numetabela" character varying(20),
  "tipconfig" numeric(1,0),
  "master" character varying(20),
  "linkkey" character varying(20),
  "tiplink" numeric(1,0),
  "descriere" character varying(100),
  "suplimsql" text,
  "updatesql" text
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cfgtables1</obj_name>
  <obj_hashval>11e919076350cc60770c67ec369a301c</obj_hashval>
  <obj_text>CREATE TABLE cfgtables1 (
  "codcfgtable1" numeric(20,0),
  "codcfgtable" numeric(20,0),
  "indexlocal" numeric(6,0),
  "numecamp" character varying(20),
  "caption" character varying(30),
  "tip" character varying(1),
  "marime" numeric(6,0),
  "zecimale" numeric(6,0),
  "colwidth" numeric(6,0),
  "color" numeric(10,0),
  "obligatoriu" numeric(1,0),
  "nomlink" numeric(10,0),
  "lookupdisplay" character varying(50),
  "tipfiltruafis" numeric(2,0),
  "filtruafis" character varying(2000),
  "hastotal" numeric(1,0),
  "tmp" numeric(1,0),
  "tobeupdated" numeric(1,0),
  "sqlonchange" character varying(3000)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cfgtables2</obj_name>
  <obj_hashval>65bd382b8a23800ed4c39cf9dec77e7b</obj_hashval>
  <obj_text>CREATE TABLE cfgtables2 (
  "codcfgtable2" numeric(20,0),
  "codcfgtable1" numeric(20,0),
  "valoare" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cheltavans</obj_name>
  <obj_hashval>4520b1c87f84f72669e22cb537687b6c</obj_hashval>
  <obj_text>CREATE TABLE cheltavans (
  "codcheltavans" numeric(20,0) NOT NULL,
  "codintr1" numeric(20,0),
  "aninceput" numeric(5,0),
  "lunainceput" numeric(2,0),
  "codioart" numeric(20,0),
  "codobligpif" numeric(20,0),
  "codnc1" numeric(20,0),
  "datastart" date,
  "dataend" date,
  "observatii" character varying(100),
  "codies1" numeric(20,0),
  "isvenit" numeric(1,0),
  "codmifix" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cheltavans1</obj_name>
  <obj_hashval>69c2947b97b2a7087aab07b4ae74a3f1</obj_hashval>
  <obj_text>CREATE TABLE cheltavans1 (
  "codcheltavans1" numeric(20,0) NOT NULL,
  "codcheltavans" numeric(20,0),
  "valoare" numeric(20,7),
  "duratan" numeric(10,0),
  "durataf" numeric(10,0),
  "dfblocat" numeric(1,0),
  "anstart" numeric(5,0),
  "lunastart" numeric(2,0),
  "amo" numeric(20,7),
  "codcentru" numeric(20,0),
  "codanalizanod" numeric(20,0),
  "codauto" numeric(20,0),
  "dataendnoua" date,
  "dataendblocata" numeric(1,0),
  "codgest" numeric(20,0),
  "codcmdint1" numeric(20,0),
  "centrublocat" numeric(1,0),
  "codgestblocat" numeric(1,0),
  "codanalizablocat" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cheltoper</obj_name>
  <obj_hashval>52fe29de7b010736b309fd4893599602</obj_hashval>
  <obj_text>CREATE TABLE cheltoper (
  "codcheltoper" numeric(20,0) NOT NULL,
  "denumire" character varying(100),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "anstop" numeric(4,0),
  "lunastop" numeric(2,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cheltoper1</obj_name>
  <obj_hashval>d604d3f89e185d1c99d1c7021988ea0f</obj_hashval>
  <obj_text>CREATE TABLE cheltoper1 (
  "codcheltoper1" numeric(20,0) NOT NULL,
  "codcheltoper" numeric(20,0),
  "codobiect" numeric(20,0),
  "umsec" numeric(20,0),
  "valoare" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cmdaprobari</obj_name>
  <obj_hashval>d68c31e48023f20a23f49948ae5a0f03</obj_hashval>
  <obj_text>CREATE TABLE cmdaprobari (
  "cod" numeric(20,0),
  "tipdoc" numeric(20,0),
  "coddoc" numeric(20,0),
  "nivel" numeric(3,0),
  "stare" numeric(20,0),
  "obs" character varying(100),
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cmdavans</obj_name>
  <obj_hashval>7e2ae7b5f3d8955f985ef50ec9fb9183</obj_hashval>
  <obj_text>CREATE TABLE cmdavans (
  "codcmdavans" numeric(20,0),
  "codcomanda" numeric(20,0),
  "codiesavans" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cmdcantlock</obj_name>
  <obj_hashval>2cab0491975591e6b1330990ac315527</obj_hashval>
  <obj_text>CREATE TABLE cmdcantlock (
  "codliniecomanda" numeric(20,0),
  "codliniestingatoare" numeric(20,0),
  "cant" numeric(20,7),
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cmdlink</obj_name>
  <obj_hashval>d0c7c042e53eb937174d0dbb157965c7</obj_hashval>
  <obj_text>CREATE TABLE cmdlink (
  "codcomanda1" numeric(20,0) NOT NULL,
  "codliniecomanda" numeric(20,0),
  "cant" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cmdlivrlink</obj_name>
  <obj_hashval>099c8844683c02658ec3752009ce428e</obj_hashval>
  <obj_text>CREATE TABLE cmdlivrlink (
  "codcomanda1" numeric(20,0) NOT NULL,
  "codliniecomanda" numeric(20,0),
  "cant" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cmdprodman</obj_name>
  <obj_hashval>e94af04d7ef70432159ba2047b6f15b2</obj_hashval>
  <obj_text>CREATE TABLE cmdprodman (
  "codcmdprodman" numeric(20,0) NOT NULL,
  "codcomanda1" numeric(20,0),
  "codman" numeric(20,0),
  "nrop" numeric(10,0),
  "codop" numeric(20,0),
  "codloc" numeric(20,0),
  "codtarif" numeric(20,0),
  "tu" numeric(20,7),
  "cant" numeric(20,7),
  "rest" numeric(20,7),
  "valoare" numeric(20,7),
  "codprodgest" numeric(20,0),
  "indexlocal" numeric(10,0),
  "dsv" numeric(20,7),
  "bps" numeric(20,7),
  "tpi" numeric(20,7),
  "obs" character varying(1000),
  "detalii" numeric(10,0),
  "datastart" timestamp(0) without time zone,
  "codcomanda3" numeric(20,0),
  "fix" numeric(1,0),
  "nivel" numeric(5,0),
  "codutilaj" numeric(20,0),
  "decalaj" numeric(10,0),
  "incepere" numeric(20,7),
  "coefbps" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cmdprodmat</obj_name>
  <obj_hashval>0493b3acf233052c29d9a41fee4fcb35</obj_hashval>
  <obj_text>CREATE TABLE cmdprodmat (
  "codcmdprodmat" numeric(20,0) NOT NULL,
  "codcomanda1" numeric(20,0),
  "codobiect" numeric(20,0),
  "cant" numeric(20,7),
  "pret" numeric(20,7),
  "rest" numeric(20,7),
  "tip" numeric(1,0),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7),
  "indexlocal" numeric(10,0),
  "reziduu" numeric(1,0),
  "codprodmat" numeric(20,0),
  "paritateechiv" numeric(20,7),
  "tipechiv" numeric(1,0),
  "cumsec" numeric(20,0),
  "ccant" numeric(20,7),
  "codcmdprodman" numeric(20,0),
  "cantum1" numeric(20,7),
  "codcomanda3" numeric(20,0),
  "umsec" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cmdprodrez</obj_name>
  <obj_hashval>5c30037f862fec4a48f324b828108435</obj_hashval>
  <obj_text>CREATE TABLE cmdprodrez (
  "codcmdprodrez" numeric(20,0) NOT NULL,
  "codcomanda1" numeric(20,0),
  "codobiect" numeric(20,0),
  "cant" numeric(20,7),
  "pret" numeric(20,7),
  "rest" numeric(20,7),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7),
  "indexlocal" numeric(10,0),
  "codcomanda3" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cmdproiectrez</obj_name>
  <obj_hashval>1ef4f09bebc85a0bc57f4a0862aa9745</obj_hashval>
  <obj_text>CREATE TABLE cmdproiectrez (
  "codcmdproiectrez" numeric(20,0) NOT NULL,
  "codcomanda1" numeric(20,0),
  "codproiectnod" numeric(20,0),
  "cant" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>codextalt</obj_name>
  <obj_hashval>bfd32f568abdc4112fd9f7dd7717f2f6</obj_hashval>
  <obj_text>CREATE TABLE codextalt (
  "cod" numeric(20,0),
  "codobiect" numeric(20,0),
  "codextern" character varying(80),
  "codpart" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>codextartlock</obj_name>
  <obj_hashval>68def2a2a319b11ef7dd6034d16b93b6</obj_hashval>
  <obj_text>CREATE TABLE codextartlock (
  "cod" numeric(20,0),
  "codextern" numeric(30,0),
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>codextpartlock</obj_name>
  <obj_hashval>6dfdb89f86f73dc8e12481307a2c7f19</obj_hashval>
  <obj_text>CREATE TABLE codextpartlock (
  "cod" numeric(20,0),
  "codextern" numeric(30,0),
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>codgestlock</obj_name>
  <obj_hashval>232e266c74e2862bcf4fed9fd9baa83a</obj_hashval>
  <obj_text>CREATE TABLE codgestlock (
  "cod" numeric(20,0),
  "gest" numeric(20,0),
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>codintalt</obj_name>
  <obj_hashval>d0250bc4d0aad8fa207f763900d4ab10</obj_hashval>
  <obj_text>CREATE TABLE codintalt (
  "cod" numeric(20,0),
  "codobiect" numeric(20,0),
  "codintern" character varying(80),
  "codpart" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>codintartlock</obj_name>
  <obj_hashval>65d8644eeeec09df78f16eb6549a83b5</obj_hashval>
  <obj_text>CREATE TABLE codintartlock (
  "cod" numeric(20,0),
  "codintern" numeric(30,0),
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>codintpartlock</obj_name>
  <obj_hashval>99bba956ecd26310d7c3f7c64333aa92</obj_hashval>
  <obj_text>CREATE TABLE codintpartlock (
  "cod" numeric(20,0),
  "codintern" numeric(30,0),
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>codioartcoresp</obj_name>
  <obj_hashval>85e0f8d7d4c175fe51d533df9fd07d22</obj_hashval>
  <obj_text>CREATE TABLE codioartcoresp (
  "cod" numeric(20,0),
  "proctva" numeric(20,7),
  "codioart" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>comanda</obj_name>
  <obj_hashval>f180908b81b72993bbb62f21be3e4d16</obj_hashval>
  <obj_text>CREATE TABLE comanda (
  "codcomanda" numeric(20,0) NOT NULL,
  "tipdoc" numeric(20,0),
  "anulat" numeric(20,0),
  "blocat" numeric(20,0),
  "operat" numeric(20,0),
  "prefixdoc" character varying(2),
  "nrdoc" numeric(20,0),
  "carnetdoc" numeric(20,0),
  "datadoc" timestamp(0) without time zone,
  "partener" numeric(20,0),
  "valoare" numeric(20,7),
  "an" numeric(20,0),
  "luna" numeric(20,0),
  "obs" character varying(500),
  "moneda" numeric(20,0),
  "codcontract" numeric(20,0),
  "codcmdparinte" numeric(20,0),
  "delegat" numeric(20,0),
  "agent" numeric(20,0),
  "valdiscount" numeric(20,7),
  "codlocatie" numeric(20,0),
  "subunitatea" numeric(20,0),
  "codfiscal" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "codgest" numeric(20,0),
  "inchisa" numeric(1,0),
  "subunitsursa" numeric(20,0),
  "scadentav" numeric(5,0),
  "seriadoc" character varying(20),
  "useridblocaj" numeric(20,0),
  "nri" character varying(30),
  "codtraseulivr" numeric(20,0),
  "ordinelivrare" numeric(20,0),
  "mijltransp" numeric(20,0),
  "insotitor" numeric(20,0),
  "displivrare" numeric(1,0),
  "verificat" numeric(1,0),
  "codies" numeric(20,0),
  "faratransport" numeric(1,0),
  "platapeloc" numeric(1,0),
  "datainreg" timestamp(6) without time zone,
  "facturabil" numeric(1,0),
  "curs" numeric(20,7),
  "schimb" numeric(1,0),
  "codformatie" numeric(20,0),
  "idimport" character varying(30),
  "listat" numeric(10,0),
  "factura_apl_ext" numeric(1,0),
  "codpers_apl_ext" numeric(20,0),
  "lot" numeric(10,0),
  "nrtransp" character varying(30),
  "codiesavans" numeric(20,0),
  "farafactura" numeric(1,0),
  "dinonline" numeric(1,0),
  "pretcuamanunt" numeric(1,0),
  "codanaliza" numeric(20,0),
  "tiptranzactie" numeric(1,0),
  "subunitdest" numeric(20,0),
  "nrmaxaprobari" numeric(10,0),
  "stadiuwms" numeric(2,0),
  "codpersc" numeric(20,0),
  "motivinchidere" character varying(80),
  "codpartcomis" numeric(20,0),
  "tiplivrare" numeric(2,0),
  "majorari" numeric(20,7),
  "gratie" numeric(10,0),
  "exportklg" numeric(1,0),
  "exportatklg" timestamp(6) without time zone,
  "modinchidere" numeric(1,0),
  "platforma_online" numeric(2,0),
  "remorca" numeric(20,0),
  "rotefact" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>comanda1</obj_name>
  <obj_hashval>4bdb279746ac083e8180d087b36feb9e</obj_hashval>
  <obj_text>CREATE TABLE comanda1 (
  "codcomanda1" numeric(20,0) NOT NULL,
  "codcomanda" numeric(20,0),
  "indexlocal" numeric(5,0),
  "codobiect" numeric(20,0),
  "umsec" numeric(10,0),
  "pu" numeric(21,7),
  "cantcomandat" numeric(20,7),
  "cantacceptat" numeric(20,7),
  "restacceptat" numeric(20,7),
  "culansare" numeric(1,0),
  "restlansat" numeric(20,7),
  "termen" timestamp(0) without time zone,
  "anulat" numeric(1,0),
  "addim" numeric(20,7),
  "procdisc" numeric(20,7),
  "obs" character varying(200),
  "pretorig" numeric(20,7),
  "coefdiscmaj" numeric(20,7),
  "scadenta" numeric(5,0),
  "codcatpret" numeric(20,0),
  "consum" numeric(20,0),
  "rezervatini" numeric(20,7),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7),
  "tipsursa" numeric(5,0),
  "codsursa" numeric(20,0),
  "cantum1" numeric(20,7),
  "coefindirecte" numeric(20,7),
  "dataincarcarii" date,
  "cantreturnat" numeric(20,7),
  "acceptum1" numeric(20,7),
  "tipplata" numeric(1,0),
  "cadou" numeric(20,0),
  "pretpromo" numeric(1,0),
  "cadoulink" numeric(5,0),
  "codreteta" numeric(20,0),
  "umcorelat" numeric(20,0),
  "pucorelat" numeric(20,7),
  "codcadou" numeric(20,0),
  "codproiect" numeric(20,0),
  "nivel" numeric(10,0),
  "pozitie" numeric(10,0),
  "tiplivrare" numeric(1,0),
  "codanalizanod" numeric(20,0),
  "exceptional" numeric(1,0),
  "codcontract1" numeric(20,0),
  "gestact" numeric(20,0),
  "codcentru" numeric(20,0),
  "codoferta1" numeric(20,0),
  "pretum1" numeric(20,7),
  "codnorma" numeric(20,0),
  "modinchidere" numeric(1,0),
  "taxa" numeric(1,0),
  "termencontract" date,
  "codmifix" numeric(20,0),
  "tipliniesa" numeric(1,0),
  "prioritate" numeric(5,0),
  "datastart" timestamp(6) without time zone,
  "codpromo1" numeric(20,0),
  "subunitsursa" numeric(20,0),
  "codliniedocimp" numeric(20,0),
  "tipdocimp" numeric(5,0),
  "discmanual" numeric(1,0),
  "furnizor" numeric(20,0),
  "puprod" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>comanda1et</obj_name>
  <obj_hashval>66131f871fed5d14e578b7570cae438f</obj_hashval>
  <obj_text>CREATE TABLE comanda1et (
  "codcomanda1et" numeric(20,0) NOT NULL,
  "codcomanda1" numeric(20,0),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "codcolet" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>comanda1luna</obj_name>
  <obj_hashval>8fc22c273b574e3f63daba918792f231</obj_hashval>
  <obj_text>CREATE TABLE comanda1luna (
  "codcomanda1" numeric(20,0),
  "rest" numeric(20,7),
  "an" numeric(5,0),
  "luna" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>comanda2</obj_name>
  <obj_hashval>27644db266d7728e102f1f0fc38f6a6f</obj_hashval>
  <obj_text>CREATE TABLE comanda2 (
  "codcomanda2" numeric(20,0) NOT NULL,
  "codcomanda" numeric(10,0),
  "codlucrare" numeric(20,0),
  "obs" character varying(100),
  "codpart" numeric(20,0),
  "garantie" numeric(1,0),
  "codnparcaut" numeric(20,0),
  "codlocatie" numeric(20,0),
  "codrezervare" numeric(20,0),
  "codinterventie" numeric(20,0),
  "ore" numeric(10,4)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncontechivsub_codsubunit</obj_name>
  <obj_reftable>ncontechivsub</obj_reftable>
  <obj_hashval>bcbf78f45eba7146776fec7a8b276179</obj_hashval>
  <obj_text>CREATE INDEX idx_ncontechivsub_codsubunit ON ncontechivsub USING btree (codsubunit)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>comanda3</obj_name>
  <obj_hashval>98ca21eea45b9da394662f67c4693578</obj_hashval>
  <obj_text>CREATE TABLE comanda3 (
  "codcomanda3" numeric(20,0) NOT NULL,
  "codcomanda2" numeric(20,0),
  "codoperatie" numeric(20,0),
  "cant" numeric(20,7),
  "pret" numeric(20,7),
  "obs" character varying(100),
  "tip" numeric(1,0),
  "executat" numeric(1,0),
  "codcomanda" numeric(20,0),
  "codrezervare" numeric(20,0),
  "data" timestamp(0) without time zone,
  "codintr1_1" numeric(20,0),
  "codintr1_2" numeric(20,0),
  "codintr1_3" numeric(20,0),
  "codcomanda1" numeric(20,0),
  "durata" numeric(10,0),
  "valoare" numeric(20,7),
  "tarif" numeric(20,7),
  "datastart" timestamp(0) without time zone,
  "categpret" numeric(5,0),
  "codprestatie" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>comanda4</obj_name>
  <obj_hashval>690166d183bce4dc7fde7887c6ad1179</obj_hashval>
  <obj_text>CREATE TABLE comanda4 (
  "codcomanda4" numeric(20,0) NOT NULL,
  "codcomanda3" numeric(20,0),
  "codpers" numeric(20,0),
  "datastart" timestamp(0) without time zone,
  "datastop" timestamp(0) without time zone,
  "obs" character varying(200),
  "codcomanda" numeric(20,0),
  "eliberat" numeric(1,0),
  "ore" numeric(10,2),
  "codcomanda2" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>compens</obj_name>
  <obj_hashval>37251291be656ae028a4d5725d42ae03</obj_hashval>
  <obj_text>CREATE TABLE compens (
  "codcompens" numeric(20,0) NOT NULL,
  "datadoc" date,
  "carnetdoc" numeric(20,0),
  "nrdoc" numeric(20,0),
  "an" numeric(5,0),
  "luna" numeric(2,0),
  "partd" numeric(20,0),
  "partc" numeric(20,0),
  "obsd" character varying(100),
  "obsc" character varying(100),
  "subunitatea" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "codgest" numeric(20,0),
  "tipcompens" numeric(1,0),
  "codcentru" numeric(20,0),
  "agent" numeric(20,0),
  "codanaliza" numeric(20,0),
  "codtippartincert" numeric(20,0),
  "flags" numeric(2,0),
  "exclussaft" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>concurenti</obj_name>
  <obj_hashval>b59645089f82255f56589cc08b561564</obj_hashval>
  <obj_text>CREATE TABLE concurenti (
  "codconcurent" numeric(20,0) NOT NULL,
  "denconcurent" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>condcor1</obj_name>
  <obj_hashval>c1cf398ea15e9ce295ebe6630ec7a6c1</obj_hashval>
  <obj_text>CREATE TABLE condcor1 (
  "codcondcor1" numeric(20,0) NOT NULL,
  "codsitfin" numeric(20,0),
  "indexlocal" numeric(10,0),
  "rnd1" numeric(10,0),
  "col1" numeric(10,0),
  "rel" character varying(2),
  "rnd2" numeric(10,0),
  "col2" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>const1</obj_name>
  <obj_hashval>14662c33202fdcf6e848c2c6ac44de46</obj_hashval>
  <obj_text>CREATE TABLE const1 (
  "codconst1" numeric(20,0) NOT NULL,
  "codcateg" numeric(10,0),
  "indexlocal" character varying(10),
  "simbol" character varying(20),
  "denumire" character varying(100),
  "tip" numeric(10,0),
  "descriere" text
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>constluna</obj_name>
  <obj_hashval>6bebe68de3d154803611dd9f95253657</obj_hashval>
  <obj_text>CREATE TABLE constluna (
  "codconstluna" numeric(20,0) NOT NULL,
  "codconst1" numeric(10,0),
  "anstart" numeric(10,0),
  "lunastart" numeric(2,0),
  "userid" numeric(10,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>constmaketa</obj_name>
  <obj_hashval>a4bfb88326e9f359824c0c85250c0643</obj_hashval>
  <obj_text>CREATE TABLE constmaketa (
  "codconstmaketa" numeric(20,0) NOT NULL,
  "codmaketa" numeric(20,0),
  "codconst1" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>constnmakete</obj_name>
  <obj_hashval>207fb170014dcc365364a0b332e5b6b0</obj_hashval>
  <obj_text>CREATE TABLE constnmakete (
  "codconstmaketa" numeric(20,0),
  "codmaketa" numeric(20,0),
  "codconst1" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>constusercheck</obj_name>
  <obj_hashval>8ab37a4b6ac598003afb8754dfc07ee4</obj_hashval>
  <obj_text>CREATE TABLE constusercheck (
  "userid" numeric(20,0) NOT NULL
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>constval</obj_name>
  <obj_hashval>4f08c14678abe1daa0fd2dc4a4b3eae6</obj_hashval>
  <obj_text>CREATE TABLE constval (
  "valoare" character varying(300),
  "codconstluna" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>constvalpos</obj_name>
  <obj_hashval>8a1a7361b7065031cd9c5ae0652437c2</obj_hashval>
  <obj_text>CREATE TABLE constvalpos (
  "cod" numeric(20,0) NOT NULL,
  "idx" numeric(10,0),
  "valposibile" character varying(300),
  "codconstluna" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>contract</obj_name>
  <obj_hashval>020e97e0257339ec21974231c34443f0</obj_hashval>
  <obj_text>CREATE TABLE contract (
  "codcontract" numeric(20,0) NOT NULL,
  "tipdoc" numeric(20,0),
  "anulat" numeric(1,0),
  "blocat" numeric(1,0),
  "operat" numeric(1,0),
  "activ" numeric(1,0),
  "carnetdoc" numeric(20,0),
  "seriadoc" character varying(20),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "datastart" date,
  "datastop" date,
  "tipcontract" numeric(1,0),
  "tiptarget" numeric(1,0),
  "partener" numeric(20,0),
  "codlocatie" numeric(20,0),
  "codfiscal" numeric(20,0),
  "codpersc" numeric(20,0),
  "moneda" numeric(20,0),
  "pertarget" numeric(1,0),
  "nrluni" numeric(20,0),
  "perfact" numeric(2,0),
  "zifact" numeric(2,0),
  "procmaj" numeric(8,5),
  "percitire" numeric(2,0),
  "zicitire" numeric(2,0),
  "transppart" numeric(1,0),
  "obs" character varying(250),
  "subunitatea" numeric(20,0),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "userid" numeric,
  "datacreare" timestamp(6) without time zone,
  "agent" numeric(20,0),
  "curs" numeric(22,4),
  "avans" numeric(20,2),
  "dobanda" numeric(8,5),
  "tipdobanda" numeric(1,0),
  "calcdobanda" numeric(1,0),
  "reziduala" numeric(20,2),
  "rezidualaseparat" numeric(1,0),
  "factlei" numeric(1,0),
  "asiganual" numeric(20,2),
  "lunigratie" numeric(2,0),
  "gratiefaradob" numeric(1,0),
  "codbanca" numeric(20,0),
  "procmajcurs" numeric(8,5),
  "autoprelungire" numeric(1,0),
  "luniprelungire" numeric(4,0),
  "tiparticol" numeric(1,0),
  "tipum" numeric(1,0),
  "tiptargetv" numeric(1,0),
  "semnat" numeric(1,0),
  "explicatii" character varying(50),
  "stopaj" numeric(20,0),
  "suma1" numeric(20,7),
  "discount1" numeric(20,7),
  "suma2" numeric(20,7),
  "discount2" numeric(20,7),
  "suma3" numeric(20,7),
  "discount3" numeric(20,7),
  "suma4" numeric(20,7),
  "discount4" numeric(20,7),
  "nri" character varying(30),
  "cass" numeric(20,0),
  "codanaliza" numeric(20,0),
  "maxreplsimultane" numeric(5,0),
  "maxzilerepla" numeric(5,0),
  "tiplivrare" numeric(2,0),
  "tipperfact" numeric(1,0),
  "majorari" numeric(20,7),
  "gratie" numeric(10,0),
  "codgeneric" numeric(20,0),
  "factpretstandard" numeric(1,0),
  "credite_plafon" numeric(20,7),
  "credite_pu" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>contract0</obj_name>
  <obj_hashval>f343bcad131b9901cb90e4b2fcfa8115</obj_hashval>
  <obj_text>CREATE TABLE contract0 (
  "codcontract0" numeric(20,0) NOT NULL,
  "codcontract" numeric(20,0),
  "tiplinie" numeric(1,0),
  "data" date,
  "curs" numeric(20,7),
  "suma" numeric(20,7),
  "facturat" numeric(1,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(20,0),
  "dobanda" numeric(20,0),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "oldcurs" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>contract1</obj_name>
  <obj_hashval>ebcda9cb1a99273156afde9ec4a96f2b</obj_hashval>
  <obj_text>CREATE TABLE contract1 (
  "codcontract1" numeric(20,0) NOT NULL,
  "codcontract" numeric(20,0),
  "codobiect" numeric(20,0),
  "umsec" numeric(20,0),
  "cant" numeric(20,7),
  "pret" numeric(20,7),
  "procdisc" numeric(5,2),
  "zilel" numeric(5,0),
  "zilec" numeric(5,0),
  "lansare" numeric(1,0),
  "anexa" numeric(20,0),
  "datastart" date,
  "datastop" date,
  "obs" character varying(200),
  "gestact" numeric(20,0),
  "tva" numeric(20,7),
  "valtarget" numeric(20,7),
  "limitacadou" numeric(20,7),
  "cantcadou" numeric(20,7),
  "codcadou" numeric(20,0),
  "codobiectsec" numeric(20,0),
  "limitacadousec" numeric(20,7),
  "termenfix" date,
  "tippret" numeric(1,0),
  "sediulivrare" numeric(20,0),
  "tipdiscount" numeric(1,0),
  "tipdiscountt" numeric(1,0),
  "tipdiscountc" numeric(1,0),
  "sumafixa" numeric(20,7),
  "tipdiscountt1" numeric(1,0),
  "codclasa" numeric(20,0),
  "disctcumulat" numeric(1,0),
  "disct" numeric(20,7),
  "codcontr1cadru" numeric(20,0),
  "addim" numeric(20,7),
  "cantoptim" numeric(20,7),
  "codcentru" numeric(20,0),
  "indexlocal" numeric(10,0),
  "tipobiect" numeric(1,0),
  "cantglobal" numeric(20,7),
  "pretstandard" numeric(20,7),
  "stare" numeric(1,0),
  "datalivr" date,
  "codauto" numeric(20,0),
  "codutilaj" numeric(20,0),
  "plafoncantf" numeric(20,7),
  "codanalizanod" numeric(20,0),
  "indexparinte" numeric(10,0),
  "taxauscare" numeric(20,7),
  "taxaconditionare" numeric(20,7),
  "codioart" numeric(20,0),
  "codoferta1" numeric(20,0),
  "utilaj_tip_index" numeric(2,0),
  "verifuma" numeric(1,0),
  "luscare" numeric(20,7),
  "lconditionare" numeric(20,7),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7),
  "cantum1" numeric(20,7),
  "pretum1" numeric(20,7),
  "paritatecredit" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>contract2</obj_name>
  <obj_hashval>195afbdb5c6aa73720ef07f9bf2733a4</obj_hashval>
  <obj_text>CREATE TABLE contract2 (
  "codcontract2" numeric(20,0) NOT NULL,
  "codcontract" numeric(20,0),
  "data" date,
  "datastop" date,
  "suma" numeric(20,7),
  "dobanda" numeric(20,7),
  "asigurare" numeric(20,7),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(20,0),
  "suspendat" numeric(1,0),
  "sediulivrare" numeric(20,0),
  "indexlocal" numeric(12,2),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "coddoct" numeric(20,0),
  "tipdoct" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>contractc</obj_name>
  <obj_hashval>56caf12877a36a790fd1778fa8d4b9c9</obj_hashval>
  <obj_text>CREATE TABLE contractc (
  "codcontractc" numeric(20,0) NOT NULL,
  "codcontract1" numeric(20,0),
  "cantmin" numeric(20,7),
  "discount" numeric(20,7),
  "valdiscount" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>contractc0</obj_name>
  <obj_hashval>324c9e64b49073542c76f73b10c75030</obj_hashval>
  <obj_text>CREATE TABLE contractc0 (
  "codcontractc0" numeric(20,0) NOT NULL,
  "codcontract" numeric(20,0),
  "cantmin" numeric(20,7),
  "discount" numeric(20,7),
  "valdiscount" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>contractt</obj_name>
  <obj_hashval>6b5af29575dde04245a2a9e1770a76a0</obj_hashval>
  <obj_text>CREATE TABLE contractt (
  "codcontractt" numeric(20,0) NOT NULL,
  "codcontract1" numeric(20,0),
  "zile" numeric(20,7),
  "discount" numeric(20,7),
  "valdiscount" numeric(20,7),
  "termenfix" date,
  "procvaldoc" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>contractv</obj_name>
  <obj_hashval>a71d059791da46c1afd51b3c04f7c4f8</obj_hashval>
  <obj_text>CREATE TABLE contractv (
  "codcontractv" numeric(20,0) NOT NULL,
  "codcontract" numeric(20,0),
  "suma" numeric(20,7),
  "discount" numeric(20,7),
  "valdiscount" numeric(20,7),
  "codcontract1" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>contractx</obj_name>
  <obj_hashval>91aa699a557f1322d4f26a506d5910d4</obj_hashval>
  <obj_text>CREATE TABLE contractx (
  "codcontractx" numeric(20,0) NOT NULL,
  "codcontract1" numeric(20,0),
  "parametru" numeric(2,0),
  "valmin" numeric(20,7),
  "procpu" numeric(20,7),
  "corectiepu" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>contractxx</obj_name>
  <obj_hashval>f56164202aa242eb80561ade7406e8cb</obj_hashval>
  <obj_text>CREATE TABLE contractxx (
  "codcontractxx" numeric(20,0) NOT NULL,
  "codcontract1" numeric(20,0),
  "parametru" numeric(2,0),
  "valstart" numeric(20,7),
  "valstop" numeric(20,7),
  "abatere" numeric(20,7),
  "startproc" numeric(20,7),
  "startcorectie" numeric(20,7),
  "proc" numeric(20,7),
  "corectie" numeric(20,7),
  "generare" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>convertcurspers</obj_name>
  <obj_hashval>ed326764327742a5550a0fac90892453</obj_hashval>
  <obj_text>CREATE TABLE convertcurspers (
  "codconvert" numeric(20,0),
  "codpers" numeric(20,0),
  "icontpers" numeric(3,0),
  "moneda_in" numeric(20,0),
  "moneda_out" numeric(20,0),
  "soldvaluta_in" numeric(20,7),
  "soldlei" numeric(20,7),
  "soldvaluta_out" numeric(20,7),
  "cursconversie" numeric(20,7),
  "datadoc" date,
  "an" numeric(5,0),
  "luna" numeric(2,0),
  "subunitatea" numeric(20,0),
  "obs" character varying(500)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>corelat1</obj_name>
  <obj_hashval>b79ef5a29856a5e5d23870888fa04da6</obj_hashval>
  <obj_text>CREATE TABLE corelat1 (
  "codcorelat1" numeric(20,0) NOT NULL,
  "codsitfin" numeric(20,0),
  "indexlocal" numeric(10,0),
  "rnd1" character varying(250),
  "col1" character varying(20),
  "rel" character varying(2),
  "rnd2" character varying(250),
  "col2" character varying(20),
  "cond" character varying(100),
  "isnumeric" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>corelat2</obj_name>
  <obj_hashval>94bddd066f0d57d384d39a07320f8d89</obj_hashval>
  <obj_text>CREATE TABLE corelat2 (
  "codcorelat2" numeric(20,0) NOT NULL,
  "codsitfin" numeric(20,0),
  "codf1" numeric(20,0),
  "rnd1" character varying(250),
  "col1" character varying(20),
  "codf2" numeric(20,0),
  "rnd2" character varying(250),
  "col2" character varying(20)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>creante</obj_name>
  <obj_hashval>1ab1e82a98e20d56e1347f4e42e97443</obj_hashval>
  <obj_text>CREATE TABLE creante (
  "codcreanta" numeric(20,0) NOT NULL,
  "anc" numeric(4,0),
  "lunac" numeric(2,0),
  "obs" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>creante1</obj_name>
  <obj_hashval>9a861d537ac800a9dc74aa443e10474d</obj_hashval>
  <obj_text>CREATE TABLE creante1 (
  "codcreanta1" numeric(20,0) NOT NULL,
  "codcreanta" numeric(20,0),
  "cod" numeric(20,0),
  "codcont" numeric(20,0),
  "indexlocal" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>criteriidisc</obj_name>
  <obj_hashval>0bff664e28e09a622718e21fa77de5b9</obj_hashval>
  <obj_text>CREATE TABLE criteriidisc (
  "codcriteriu" numeric(20,0) NOT NULL,
  "dencriteriu" character varying(40),
  "excludvoltr" numeric(1,0),
  "excludcantfact" numeric(1,0),
  "excludtermen" numeric(1,0),
  "excludvaldoc" numeric(1,0),
  "excluddistanta" numeric(1,0),
  "peclase" numeric(1,0),
  "cumulat" numeric(1,0),
  "offinvoice" numeric(1,0),
  "nivel" numeric(5,0),
  "clasa" numeric(20,0),
  "tipinterval" numeric(10,0),
  "puncte" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>criteriidisc1</obj_name>
  <obj_hashval>50bd1937f192edb4280bdd25e2403822</obj_hashval>
  <obj_text>CREATE TABLE criteriidisc1 (
  "codcriteriu1" numeric(20,0),
  "codcriteriu" numeric(20,0),
  "datastart" date,
  "subunitatea" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cronocashflow</obj_name>
  <obj_hashval>fd0e7fa38fb05671eec29b91907b5e00</obj_hashval>
  <obj_text>CREATE TABLE cronocashflow (
  "codcrono" numeric(20,0),
  "codcashflow" numeric(20,0),
  "data" date,
  "sold" numeric(20,7),
  "plati" numeric(20,7),
  "soldfinal" numeric(20,7),
  "incasari" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>curscashflow</obj_name>
  <obj_hashval>140d98cbd1b4a678d944e347bb457ea6</obj_hashval>
  <obj_text>CREATE TABLE curscashflow (
  "codcurs" numeric(20,0),
  "codcashflow" numeric(20,0),
  "codmoneda" numeric(20,0),
  "curs" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cursuri</obj_name>
  <obj_hashval>5b2590151a89df1afb5ab5f57434244b</obj_hashval>
  <obj_text>CREATE TABLE cursuri (
  "codcurs" numeric(20,0) NOT NULL,
  "den_curs" character varying(30),
  "formator" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>cursuri1</obj_name>
  <obj_hashval>fec911202f2ac6574f7165ae55d5e762</obj_hashval>
  <obj_text>CREATE TABLE cursuri1 (
  "codcurs1" numeric(20,0) NOT NULL,
  "codcurs" numeric(20,0),
  "indexlocal" numeric(20,0),
  "codtema" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d300</obj_name>
  <obj_hashval>f9c2d9cb0454173ac0846301a24a939c</obj_hashval>
  <obj_text>CREATE TABLE d300 (
  "codd300" numeric(20,0) NOT NULL,
  "subunitatea" numeric(20,0),
  "an" numeric(4,0),
  "lunad" numeric(2,0),
  "bifa_interne" numeric(1,0),
  "nume" character varying(75),
  "prenume" character varying(75),
  "functia" character varying(50),
  "obs" character varying(250),
  "cistva" numeric(10,0),
  "dencontrib" character varying(200),
  "domfisccontrib" character varying(1000),
  "tel" character varying(15),
  "fax" character varying(15),
  "email" character varying(200),
  "banca" character varying(50),
  "cont" character varying(50),
  "caen" character varying(5),
  "tip_decont" character varying(1),
  "pro_rata" numeric(7,2),
  "bifa_cereale" character varying(1),
  "solicit_ramb" character varying(1),
  "nr_evid" character varying(23),
  "v_01_0" numeric(15,0),
  "v_02_0" numeric(15,0),
  "v_03_0" numeric(15,0),
  "v_03_1" numeric(15,0),
  "v_04_0" numeric(15,0),
  "v_05_0" numeric(15,0),
  "t_05_0" numeric(15,0),
  "v_05_1" numeric(15,0),
  "t_05_1" numeric(15,0),
  "v_06_0" numeric(15,0),
  "t_06_0" numeric(15,0),
  "v_07_0" numeric(15,0),
  "t_07_0" numeric(15,0),
  "v_07_1" numeric(15,0),
  "t_07_1" numeric(15,0),
  "v_08_0" numeric(15,0),
  "t_08_0" numeric(15,0),
  "v_09_0" numeric(15,0),
  "t_09_0" numeric(15,0),
  "v_10_0" numeric(15,0),
  "t_10_0" numeric(15,0),
  "v_11_0" numeric(15,0),
  "t_11_0" numeric(15,0),
  "v_12_0" numeric(15,0),
  "t_12_0" numeric(15,0),
  "v_13_0" numeric(15,0),
  "v_14_0" numeric(15,0),
  "v_15_0" numeric(15,0),
  "v_16_0" numeric(15,0),
  "t_16_0" numeric(15,0),
  "v_17_0" numeric(15,0),
  "t_17_0" numeric(15,0),
  "v_18_0" numeric(15,0),
  "t_18_0" numeric(15,0),
  "v_18_1" numeric(15,0),
  "t_18_1" numeric(15,0),
  "v_19_0" numeric(15,0),
  "t_19_0" numeric(15,0),
  "v_20_0" numeric(15,0),
  "t_20_0" numeric(15,0),
  "v_20_1" numeric(15,0),
  "t_20_1" numeric(15,0),
  "v_21_0" numeric(15,0),
  "t_21_0" numeric(15,0),
  "v_22_0" numeric(15,0),
  "t_22_0" numeric(15,0),
  "v_23_0" numeric(15,0),
  "t_23_0" numeric(15,0),
  "v_24_0" numeric(15,0),
  "t_24_0" numeric(15,0),
  "v_25_0" numeric(15,0),
  "t_25_0" numeric(15,0),
  "v_26_0" numeric(15,0),
  "v_26_1" numeric(15,0),
  "v_27_0" numeric(15,0),
  "t_27_0" numeric(15,0),
  "t_28_0" numeric(15,0),
  "t_29_0" numeric(15,0),
  "v_30_0" numeric(15,0),
  "t_30_0" numeric(15,0),
  "t_31_0" numeric(15,0),
  "t_32_0" numeric(15,0),
  "t_33_0" numeric(15,0),
  "t_34_0" numeric(15,0),
  "t_35_0" numeric(15,0),
  "t_36_0" numeric(15,0),
  "t_37_0" numeric(15,0),
  "t_38_0" numeric(15,0),
  "t_39_0" numeric(15,0),
  "t_40_0" numeric(15,0),
  "t_41_0" numeric(15,0),
  "t_42_0" numeric(15,0),
  "nr_facturi" numeric(15,0),
  "baza" numeric(15,0),
  "tva" numeric(15,0),
  "v_a" numeric(15,0),
  "t_a" numeric(15,0),
  "v_b" numeric(15,0),
  "t_b" numeric(15,0),
  "temei" numeric(1,0),
  "bifa_mob" character varying(1),
  "bifa_disp" character varying(1),
  "bifa_cons" character varying(1),
  "v_12_1" numeric(15,0),
  "t_12_1" numeric(15,0),
  "v_12_2" numeric(15,0),
  "t_12_2" numeric(15,0),
  "v_12_3" numeric(15,0),
  "t_12_3" numeric(15,0),
  "v_25_1" numeric(15,0),
  "t_25_1" numeric(15,0),
  "v_25_2" numeric(15,0),
  "t_25_2" numeric(15,0),
  "v_25_3" numeric(15,0),
  "t_25_3" numeric(15,0),
  "nr_facturi_p" numeric(15,0),
  "baza_p" numeric(15,0),
  "tva_p" numeric(15,0),
  "v_a1" numeric(15,0),
  "t_a1" numeric(15,0),
  "v_b1" numeric(15,0),
  "t_b1" numeric(15,0),
  "t_43_0" numeric(15,0),
  "t_44_0" numeric(15,0),
  "v_64_0" numeric(15,0),
  "t_64_0" numeric(15,0),
  "v_65_0" numeric(15,0),
  "t_65_0" numeric(15,0),
  "tot_precedent" numeric(15,0),
  "tot_curent" numeric(15,0),
  "nr_facturi_e" numeric(15,0),
  "baza_e" numeric(15,0),
  "tva_e" numeric(15,0),
  "depusreprez" numeric(1,0),
  "v_14_1" numeric(15,0),
  "v_14_2" numeric(15,0),
  "etva" numeric(1,0),
  "v_09_1" numeric(15,0),
  "t_09_1" numeric(15,0),
  "v_10_1" numeric(15,0),
  "t_10_1" numeric(15,0),
  "v_11_1" numeric(15,0),
  "t_11_1" numeric(15,0),
  "v_12_4" numeric(15,0),
  "t_12_4" numeric(15,0),
  "v_12_5" numeric(15,0),
  "t_12_5" numeric(15,0),
  "v_22_1" numeric(15,0),
  "t_22_1" numeric(15,0),
  "v_23_1" numeric(15,0),
  "t_23_1" numeric(15,0),
  "v_25_4" numeric(15,0),
  "t_25_4" numeric(15,0),
  "v_25_5" numeric(15,0),
  "t_25_5" numeric(15,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d390</obj_name>
  <obj_hashval>a54d893a3b377db5b6010d3ef7f00122</obj_hashval>
  <obj_text>CREATE TABLE d390 (
  "codd390" numeric(20,0) NOT NULL,
  "tipd390" numeric(1,0),
  "subunitatea" numeric(20,0),
  "an" numeric(4,0),
  "lunad" numeric(2,0),
  "cistva" character varying(15),
  "dencontrib" character varying(100),
  "domfisccontrib" character varying(1000),
  "tel" character varying(30),
  "fax" character varying(30),
  "email" character varying(80),
  "nrtotop" numeric(20,0),
  "bazal" numeric(20,7),
  "bazat" numeric(20,7),
  "bazaa" numeric(20,7),
  "bazap" numeric(20,7),
  "bazas" numeric(20,7),
  "totalbaza" numeric(20,7),
  "nume" character varying(75),
  "prenume" character varying(75),
  "functia" character varying(50),
  "obs" character varying(450),
  "nrfirmecds" numeric(20,0),
  "bazar" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d390ca</obj_name>
  <obj_hashval>39d7825bc29f72c061ec8c6272a6b77c</obj_hashval>
  <obj_text>CREATE TABLE d390ca (
  "codd390ca" numeric(20,0) NOT NULL,
  "codd390" numeric(20,0),
  "tara_m1" character varying(2),
  "cod_m1" character varying(15)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d390cb</obj_name>
  <obj_hashval>0e840710b556462274b1cf93a196b9d0</obj_hashval>
  <obj_text>CREATE TABLE d390cb (
  "codd390cb" numeric(20,0) NOT NULL,
  "codd390" numeric(20,0),
  "tara_m1" character varying(2),
  "cod_m1" character varying(15),
  "motiv" numeric(2,0),
  "tara_m2" character varying(2),
  "cod_m2" character varying(15)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d390d</obj_name>
  <obj_hashval>e008584e5eda4fa18d5e6d2f60eca54c</obj_hashval>
  <obj_text>CREATE TABLE d390d (
  "codd390d" numeric(20,0) NOT NULL,
  "codd390o" numeric(20,0),
  "codd390" numeric(20,0),
  "idxfirma" numeric(20,0),
  "codsursa" numeric(20,0),
  "tipsursa" numeric(20,0),
  "doc" character varying(50),
  "monedadoc" character varying(50),
  "tip" character varying(1),
  "bazaval" numeric(20,7),
  "curs" numeric(20,7),
  "bazalei" numeric(20,7),
  "obs" character varying(500),
  "sters" numeric(1,0),
  "cazspecial" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d390o</obj_name>
  <obj_hashval>50767c1673d8a2279bf2d677dd722d7a</obj_hashval>
  <obj_text>CREATE TABLE d390o (
  "codd390o" numeric(20,0) NOT NULL,
  "codd390" numeric(20,0),
  "tip" character varying(1),
  "tara" character varying(2),
  "codo" character varying(15),
  "deno" character varying(100),
  "baza" numeric(20,7),
  "obs" character varying(500),
  "cazspecial" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncontrep_codcont</obj_name>
  <obj_reftable>ncontrep</obj_reftable>
  <obj_hashval>b0f5d4e76efe3f70a85b37143640597f</obj_hashval>
  <obj_text>CREATE INDEX idx_ncontrep_codcont ON ncontrep USING btree (codcont)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d394</obj_name>
  <obj_hashval>d9d5e302e733712007ba278c8d93cf7b</obj_hashval>
  <obj_text>CREATE TABLE d394 (
  "codd394" numeric(20,0) NOT NULL,
  "tipd394" character varying(1),
  "an" numeric(4,0),
  "lunad" numeric(2,0),
  "cistva" character varying(15),
  "dencontrib" character varying(100),
  "domfisccontrib" character varying(1000),
  "tel" character varying(30),
  "fax" character varying(30),
  "email" character varying(80),
  "cifreprfisc" character varying(15),
  "denreprfisc" character varying(100),
  "domfiscreprfisc" character varying(1000),
  "telreprfisc" character varying(30),
  "faxreprfisc" character varying(30),
  "emailreprfisc" character varying(80),
  "nrtotfb" numeric(20,0),
  "bazalivr" numeric(20,7),
  "tvalivr" numeric(20,7),
  "bazaachiz" numeric(20,7),
  "tvaachiz" numeric(20,7),
  "bazav" numeric(20,7),
  "tvav" numeric(20,7),
  "bazavc" numeric(20,7),
  "tvavc" numeric(20,7),
  "bazac" numeric(20,7),
  "tvac" numeric(20,7),
  "bazacc" numeric(20,7),
  "tvacc" numeric(20,7),
  "sumacontrol" numeric(20,0),
  "subunitatea" numeric(20,0),
  "nume" character varying(75),
  "prenume" character varying(75),
  "functia" character varying(50),
  "centralizat" numeric(1,0),
  "tip" numeric(1,0),
  "semestru" character varying(2),
  "obs" character varying(250),
  "nrfactl" numeric(15,0),
  "nrfacta" numeric(15,0),
  "nrfactv" numeric(15,0),
  "nrfactc" numeric(15,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416</obj_name>
  <obj_hashval>62aea05c3b40394f653ead5dce20da3b</obj_hashval>
  <obj_text>CREATE TABLE d39416 (
  "codd39416" numeric(20,0) NOT NULL,
  "subunitatea" numeric(20,0),
  "tipd" character varying(1),
  "an" numeric(4,0),
  "lunad" numeric(2,0),
  "cui" character varying(50),
  "den" character varying(100),
  "caen" character varying(5),
  "adresa" character varying(160),
  "telefon" character varying(15),
  "fax" character varying(15),
  "email" character varying(80),
  "cifr" character varying(13),
  "denr" character varying(100),
  "adresar" character varying(160),
  "telefonr" character varying(15),
  "faxr" character varying(15),
  "emailr" character varying(80),
  "calitater" character varying(50),
  "tipi" numeric(1,0),
  "deni" character varying(100),
  "codi" character varying(13),
  "functiei" character varying(35),
  "calitatei" character varying(50),
  "tvaincas" numeric(1,0),
  "opefectuate" numeric(1,0),
  "acordaccesp" numeric(1,0),
  "acordaccesc" numeric(1,0),
  "sumacontrol" numeric(20,0),
  "rpno" numeric(20,0),
  "rnno" numeric(20,0),
  "ueno" numeric(20,0),
  "nonueno" numeric(20,0),
  "opefcfgen" numeric(1,0),
  "dataxmlvalid" date,
  "obs" character varying(200),
  "nerezident" numeric(1,0),
  "prsafiliat" numeric(1,0),
  "editmanual" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416_anaf</obj_name>
  <obj_hashval>23a4911c550daadeff28b71fbe8226ac</obj_hashval>
  <obj_text>CREATE TABLE d39416_anaf (
  "cui" numeric(20,0) NOT NULL,
  "data" date NOT NULL,
  "contribuabil" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416g</obj_name>
  <obj_hashval>d501ce35febc02c20c2ca6845558d25c</obj_hashval>
  <obj_text>CREATE TABLE d39416g (
  "codd39416g" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "tiptranz" numeric(20,0),
  "bf" numeric(20,0),
  "valoare" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416g1</obj_name>
  <obj_hashval>3997ade6a4de51dbfe6abc100086f96b</obj_hashval>
  <obj_text>CREATE TABLE d39416g1 (
  "codd39416g1" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "tiptranz" numeric(20,0),
  "proctva" numeric(20,0),
  "bi" numeric(20,0),
  "tva" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416g2</obj_name>
  <obj_hashval>dd723f79cfb2b292a6810a4c3776959f</obj_hashval>
  <obj_text>CREATE TABLE d39416g2 (
  "codd39416g2" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "tiptranz" numeric(20,0),
  "luna" numeric(2,0),
  "nramef" numeric(20,0),
  "bf" numeric(20,0),
  "valoare" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416g3</obj_name>
  <obj_hashval>178eb137e0d4eb2969ca3c95fcebcd73</obj_hashval>
  <obj_text>CREATE TABLE d39416g3 (
  "codd39416g3" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "tiptranz" numeric(20,0),
  "luna" numeric(2,0),
  "proctva" numeric(20,0),
  "bi" numeric(20,0),
  "tva" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416i</obj_name>
  <obj_hashval>90cdd537897e05aee040081c4d9fb073</obj_hashval>
  <obj_text>CREATE TABLE d39416i (
  "codd39416i" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "totalfact" numeric(20,0),
  "totalfactben" numeric(20,0),
  "totalfactterti" numeric(20,0),
  "solicit" numeric(20,0),
  "achizpe" numeric(20,0),
  "achizcr" numeric(20,0),
  "achizcb" numeric(20,0),
  "achizci" numeric(20,0),
  "achiza" numeric(20,0),
  "achizb24" numeric(20,0),
  "achizb20" numeric(20,0),
  "achizb19" numeric(20,0),
  "achizb9" numeric(20,0),
  "achizb5" numeric(20,0),
  "achizs24" numeric(20,0),
  "achizs20" numeric(20,0),
  "achizs19" numeric(20,0),
  "achizs9" numeric(20,0),
  "achizs5" numeric(20,0),
  "importb" numeric(20,0),
  "acinecorp" numeric(20,0),
  "livraribi" numeric(20,0),
  "livrarib24" numeric(20,0),
  "livrarib20" numeric(20,0),
  "livrarib19" numeric(20,0),
  "livrarib9" numeric(20,0),
  "livrarib5" numeric(20,0),
  "livrarib0" numeric(20,0),
  "livrariti" numeric(20,0),
  "prest24" numeric(20,0),
  "prest20" numeric(20,0),
  "prest19" numeric(20,0),
  "prest9" numeric(20,0),
  "prest5" numeric(20,0),
  "prest0" numeric(20,0),
  "livrariue" numeric(20,0),
  "prestue" numeric(20,0),
  "export" numeric(20,0),
  "livinecorp" numeric(20,0),
  "efectuat" numeric(20,0),
  "achizb21" numeric(20,0),
  "achizb11" numeric(20,0),
  "achizs21" numeric(20,0),
  "achizs11" numeric(20,0),
  "livrarib21" numeric(20,0),
  "livrarib11" numeric(20,0),
  "prest21" numeric(20,0),
  "prest11" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416i1</obj_name>
  <obj_hashval>6e7b86a51fea2ebc270612b695d01bcc</obj_hashval>
  <obj_text>CREATE TABLE d39416i1 (
  "codd39416i1" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "proctva" numeric(20,0),
  "bazafslcod" numeric(20,7),
  "tvafslcod" numeric(20,7),
  "bazafsl" numeric(20,7),
  "tvafsl" numeric(20,7),
  "bazafsa" numeric(20,7),
  "tvafsa" numeric(20,7),
  "bazafsai" numeric(20,7),
  "tvafsai" numeric(20,7),
  "bazabfai" numeric(20,7),
  "tvabfai" numeric(20,7),
  "tvaded" numeric(20,7),
  "tvadedi" numeric(20,7),
  "tvacol" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416i2</obj_name>
  <obj_hashval>661b4309ffbb9f6c808f69d57f4ff15c</obj_hashval>
  <obj_text>CREATE TABLE d39416i2 (
  "codd39416i2" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "indexlocal" numeric(20,0),
  "serie" character varying(20),
  "startnr" numeric(20,0),
  "endnr" numeric(20,0),
  "numarf" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416i2a</obj_name>
  <obj_hashval>ec3d6be41ce679cac5b1269d79c96a40</obj_hashval>
  <obj_text>CREATE TABLE d39416i2a (
  "codd39416i2a" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "indexlocal" numeric(20,0),
  "serie" character varying(20),
  "startnr" numeric(20,0),
  "endnr" numeric(20,0),
  "numarf" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416i3</obj_name>
  <obj_hashval>aee18f7192be759f5097887c7fb43db8</obj_hashval>
  <obj_text>CREATE TABLE d39416i3 (
  "codd39416i3" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "tipfactura" numeric(20,0),
  "serief" character varying(20),
  "numarf" numeric(20,0),
  "cui" character varying(50),
  "denp" character varying(100),
  "proctva" numeric(20,0),
  "bi" numeric(20,7),
  "tva" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416i4</obj_name>
  <obj_hashval>5030e82062aeeea89a105c90fde5f352</obj_hashval>
  <obj_text>CREATE TABLE d39416i4 (
  "codd39416i4" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "caen" character varying(5),
  "tipoper" numeric(20,0),
  "proctva" numeric(20,0),
  "valoare" numeric(20,7),
  "tva" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416n</obj_name>
  <obj_hashval>a7adc6fa37248523e1a6c4e6cd5340e2</obj_hashval>
  <obj_text>CREATE TABLE d39416n (
  "codd39416n" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "tiptranz" numeric(20,0),
  "proctva" numeric(20,0),
  "f" numeric(20,0),
  "bi" numeric(20,7),
  "tva" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416ns2</obj_name>
  <obj_hashval>3d1646b00003dceea3adb8c98e9d642a</obj_hashval>
  <obj_text>CREATE TABLE d39416ns2 (
  "codd39416ns2" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "tiptranz" numeric(20,0),
  "regscutire" numeric(20,0),
  "proctva" numeric(20,0),
  "cui" character varying(50),
  "denp" character varying(100),
  "f" numeric(20,0),
  "bi" numeric(20,7),
  "marja" numeric(20,7),
  "tva" numeric(20,7),
  "tvamarja" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416r</obj_name>
  <obj_hashval>2375171b0b3e3cf90d2301842ad385b1</obj_hashval>
  <obj_text>CREATE TABLE d39416r (
  "codd39416r" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "proctva" numeric(20,0),
  "livrarif" numeric(20,0),
  "livrarib" numeric(20,7),
  "livraritva" numeric(20,7),
  "achizf" numeric(20,0),
  "achizb" numeric(20,7),
  "achiztva" numeric(20,7),
  "achizif" numeric(20,0),
  "achizib" numeric(20,7),
  "achizitva" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416rn</obj_name>
  <obj_hashval>1a11cf3e3810b900cae17ee2f927e5a9</obj_hashval>
  <obj_text>CREATE TABLE d39416rn (
  "codd39416rn" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "tiptranz" numeric(20,0),
  "proctva" numeric(20,0),
  "tipdoc" numeric(20,0),
  "f" numeric(20,0),
  "bi" numeric(20,7),
  "tva" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416rn0</obj_name>
  <obj_hashval>84f0f976b675bad3eebae46b308baef5</obj_hashval>
  <obj_text>CREATE TABLE d39416rn0 (
  "codd39416rn0" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "l_pf_f" numeric(20,0),
  "l_pf_bi24" numeric(20,7),
  "l_pf_tva24" numeric(20,7),
  "l_pf_bi20" numeric(20,7),
  "l_pf_tva20" numeric(20,7),
  "l_pf_bi19" numeric(20,7),
  "l_pf_tva19" numeric(20,7),
  "l_pf_bi9" numeric(20,7),
  "l_pf_tva9" numeric(20,7),
  "l_pf_bi5" numeric(20,7),
  "l_pf_tva5" numeric(20,7),
  "ls_pf_f" numeric(20,0),
  "ls_pf_val" numeric(20,7),
  "l_pf_bi21" numeric(20,7),
  "l_pf_tva21" numeric(20,7),
  "l_pf_bi11" numeric(20,7),
  "l_pf_tva11" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416rn1</obj_name>
  <obj_hashval>9b935ba1f575aa8b9b8e34dcbcca0e7f</obj_hashval>
  <obj_text>CREATE TABLE d39416rn1 (
  "codd39416rn1" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "tiptranz" numeric(20,0),
  "proctva" numeric(20,0),
  "tipdoc" numeric(20,0),
  "categtxinv" numeric(20,0),
  "f" numeric(20,0),
  "valoare" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416rns2</obj_name>
  <obj_hashval>07bc0ca1c845ee8bb13b40000e2cb0a4</obj_hashval>
  <obj_text>CREATE TABLE d39416rns2 (
  "codd39416rns2" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "tiptranz" numeric(20,0),
  "regscutire" numeric(20,0),
  "proctva" numeric(20,0),
  "cui" character varying(50),
  "denp" character varying(100),
  "codlocalit" numeric(20,0),
  "strp" character varying(75),
  "nrp" character varying(15),
  "blp" character varying(30),
  "app" character varying(10),
  "tipdoc" numeric(20,0),
  "f" numeric(20,0),
  "bi" numeric(20,7),
  "marja" numeric(20,7),
  "tva" numeric(20,7),
  "tvamarja" numeric(20,7),
  "detp" character varying(100),
  "cuivalid" numeric(1,0),
  "locp" character varying(50),
  "judp" character varying(2),
  "tarap" character varying(3),
  "sajudp" character varying(2)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416rns3</obj_name>
  <obj_hashval>c08f1ff7cbd126dc027e2f5c1c9baf79</obj_hashval>
  <obj_text>CREATE TABLE d39416rns3 (
  "codd39416rns3" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "codd39416rn1" numeric(20,0),
  "codd39416rns2" numeric(20,0),
  "f" numeric(20,0),
  "valoare" numeric(20,7),
  "codd394" character varying(8)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416rp</obj_name>
  <obj_hashval>37dfcea8f68b4452461f3394971fbc71</obj_hashval>
  <obj_text>CREATE TABLE d39416rp (
  "codd39416rp" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "tiptranz" numeric(20,0),
  "proctva" numeric(20,0),
  "f" numeric(20,0),
  "bi" numeric(20,7),
  "tva" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416rp1</obj_name>
  <obj_hashval>d83f990578a8b541f26743c7cc941c34</obj_hashval>
  <obj_text>CREATE TABLE d39416rp1 (
  "codd39416rp1" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "tiptranz" numeric(20,0),
  "proctva" numeric(20,0),
  "categtxinv" numeric(20,0),
  "f" numeric(20,0),
  "bi" numeric(20,7),
  "tva" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416rps2</obj_name>
  <obj_hashval>55911b0ce862500a0c07507f82c59ab6</obj_hashval>
  <obj_text>CREATE TABLE d39416rps2 (
  "codd39416rps2" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "tiptranz" numeric(20,0),
  "regscutire" numeric(20,0),
  "proctva" numeric(20,0),
  "cui" character varying(50),
  "denp" character varying(100),
  "f" numeric(20,0),
  "bi" numeric(20,7),
  "marja" numeric(20,7),
  "tva" numeric(20,7),
  "tvamarja" numeric(20,7),
  "cuivalid" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416rps3</obj_name>
  <obj_hashval>4d310656ab980f7fe50bf8ef4dd7da15</obj_hashval>
  <obj_text>CREATE TABLE d39416rps3 (
  "codd39416rps3" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "tiptranz" numeric(20,0),
  "proctva" numeric(20,0),
  "cui" character varying(50),
  "categtxinv" numeric(20,0),
  "codd394" character varying(8),
  "f" numeric(20,0),
  "bi" numeric(20,7),
  "tva" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416ue</obj_name>
  <obj_hashval>66a3f52788aa274d327d78a18774b4f6</obj_hashval>
  <obj_text>CREATE TABLE d39416ue (
  "codd39416ue" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "tiptranz" numeric(20,0),
  "proctva" numeric(20,0),
  "f" numeric(20,0),
  "bi" numeric(20,7),
  "tva" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d39416ues2</obj_name>
  <obj_hashval>890d86271c0b2b76b294ba9aa5c94d20</obj_hashval>
  <obj_text>CREATE TABLE d39416ues2 (
  "codd39416ues2" numeric(20,0) NOT NULL,
  "codd39416" numeric(20,0),
  "tiptranz" numeric(20,0),
  "regscutire" numeric(20,0),
  "proctva" numeric(20,0),
  "cui" character varying(50),
  "denp" character varying(100),
  "f" numeric(20,0),
  "bi" numeric(20,7),
  "marja" numeric(20,7),
  "tva" numeric(20,7),
  "tvamarja" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d394a</obj_name>
  <obj_hashval>29aca5f1dab1a169e22bed025edcf10c</obj_hashval>
  <obj_text>CREATE TABLE d394a (
  "codd394a" numeric(20,0) NOT NULL,
  "codd394" numeric(20,0),
  "tipoperatiune" character varying(2),
  "cistvabfp" character varying(15),
  "denbfp" character varying(100),
  "baza" numeric(20,7),
  "tva" numeric(20,7),
  "generat" numeric(20,0),
  "cftext" character varying(20),
  "codsursa" numeric(20,0),
  "tipsursa" numeric(20,0),
  "obs" character varying(250),
  "nrfact" numeric(15,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d394c</obj_name>
  <obj_hashval>8f365941d7105f9218aaa6b08778c6c3</obj_hashval>
  <obj_text>CREATE TABLE d394c (
  "codd394c" numeric(20,0) NOT NULL,
  "codd394" numeric(20,0),
  "tipoperatiune" character varying(2),
  "cistvabfp" character varying(15),
  "denbfp" character varying(200),
  "baza" numeric(20,7),
  "tva" numeric(20,7),
  "generat" numeric(20,0),
  "cftext" character varying(20),
  "codsursa" numeric(20,0),
  "tipsursa" numeric(20,0),
  "obs" character varying(250),
  "nrfact" numeric(15,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d394cc</obj_name>
  <obj_hashval>745f134229d49c023ad0d33307d18581</obj_hashval>
  <obj_text>CREATE TABLE d394cc (
  "codd394cc" numeric(20,0) NOT NULL,
  "codd394c" numeric(20,0),
  "denprodus" character varying(200),
  "codnc" character varying(8),
  "baza" numeric(20,7),
  "tva" numeric(20,7),
  "codsursa1" numeric(20,0),
  "obs" character varying(250)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d394l</obj_name>
  <obj_hashval>8ce3f7ce7d2de0ab549bea12820b45da</obj_hashval>
  <obj_text>CREATE TABLE d394l (
  "codd394l" numeric(20,0) NOT NULL,
  "codd394" numeric(20,0),
  "tipoperatiune" character varying(2),
  "cistvabfp" character varying(15),
  "denbfp" character varying(100),
  "baza" numeric(20,7),
  "tva" numeric(20,7),
  "generat" numeric(20,0),
  "cftext" character varying(20),
  "codsursa" numeric(20,0),
  "tipsursa" numeric(20,0),
  "obs" character varying(250),
  "nrfact" numeric(15,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d394v</obj_name>
  <obj_hashval>ab405934a94de1df3eba2ba2f6925059</obj_hashval>
  <obj_text>CREATE TABLE d394v (
  "codd394v" numeric(20,0) NOT NULL,
  "codd394" numeric(20,0),
  "tipoperatiune" character varying(2),
  "cistvabfp" character varying(15),
  "denbfp" character varying(200),
  "baza" numeric(20,7),
  "tva" numeric(20,7),
  "generat" numeric(20,0),
  "cftext" character varying(20),
  "codsursa" numeric(20,0),
  "tipsursa" numeric(20,0),
  "obs" character varying(250),
  "nrfact" numeric(15,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>d394vc</obj_name>
  <obj_hashval>2899f2ddf619b3000b1692d2a280b795</obj_hashval>
  <obj_text>CREATE TABLE d394vc (
  "codd394vc" numeric(20,0) NOT NULL,
  "codd394v" numeric(20,0),
  "denprodus" character varying(200),
  "codnc" character varying(8),
  "baza" numeric(20,7),
  "tva" numeric(20,7),
  "codsursa1" numeric(20,0),
  "obs" character varying(250)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>datawarehouse</obj_name>
  <obj_hashval>f94ac525331696155a16617cac6cf73d</obj_hashval>
  <obj_text>CREATE TABLE datawarehouse (
  "cod" numeric(20,0),
  "codjob1" numeric(20,0),
  "tabla" character varying(100),
  "subunitatea" numeric(20,0),
  "skemafirma" character varying(100),
  "listaname" character varying(1000),
  "datagen" date,
  "table_type" numeric(1,0),
  "deponame" character varying(20)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>debug_liste</obj_name>
  <obj_hashval>5bc0c2015a48c2bce24ecff6b9178348</obj_hashval>
  <obj_text>CREATE TABLE debug_liste (
  "userid" numeric(20,0),
  "sql_lista" text,
  "listid" numeric(20,0),
  "listver" numeric(20,0),
  "sql_time" timestamp(6) without time zone,
  "sql_err" text
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>dep_status</obj_name>
  <obj_hashval>38e9da1cd9e16a733d4c8f4bc75f10e9</obj_hashval>
  <obj_text>CREATE TABLE dep_status (
  "activ" numeric(1,0),
  "al" numeric(5,0),
  "datadep" date,
  "hashval" character varying(64),
  "obs" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>dep_tables</obj_name>
  <obj_hashval>c53f61f17d9d591724c5f599d839abea</obj_hashval>
  <obj_text>CREATE TABLE dep_tables (
  "tabname" character varying(50),
  "sel" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>descriptori</obj_name>
  <obj_hashval>2ad887341b11a650e5c152246de8dcf5</obj_hashval>
  <obj_text>CREATE TABLE descriptori (
  "coddescriptor" numeric(20,0) NOT NULL,
  "den_descriptor" character varying(50),
  "simbol" character varying(10),
  "tip" numeric(30,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>descriptori1</obj_name>
  <obj_hashval>7aa0d282c8b4592f361e814fa91251ba</obj_hashval>
  <obj_text>CREATE TABLE descriptori1 (
  "coddescriptor1" numeric(20,0) NOT NULL,
  "coddescriptor" numeric(20,0),
  "valoare" character varying(50),
  "codasociat" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>destinatii</obj_name>
  <obj_hashval>2aca1f087b2f13ad9a7c193cf4bbf719</obj_hashval>
  <obj_text>CREATE TABLE destinatii (
  "coddestinatie" numeric(20,0),
  "numedestinatie" character varying(200),
  "pentru" character varying(200),
  "sezon" character varying(200),
  "articol" character varying(200),
  "activitate" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>detailmak</obj_name>
  <obj_hashval>a6ed5767a2015537a54b2ddd99591b6f</obj_hashval>
  <obj_text>CREATE TABLE detailmak (
  "coddetailmak" numeric(20,0) NOT NULL,
  "codmastermak" numeric(20,0),
  "coddoc" numeric(20,0),
  "cod1" numeric(20,0),
  "cod2" numeric(20,0),
  "cod3" numeric(20,0),
  "cod4" numeric(20,0),
  "cod5" numeric(20,0),
  "v1" numeric(20,7),
  "v2" numeric(20,7),
  "v3" numeric(20,7),
  "v4" numeric(20,7),
  "v5" numeric(20,7),
  "data1" date,
  "data2" date,
  "obs1" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>detaliiet</obj_name>
  <obj_hashval>0d62eb923e21e53460a6ede357d8c895</obj_hashval>
  <obj_text>CREATE TABLE detaliiet (
  "coddetaliu" numeric(20,0) NOT NULL,
  "coddoc" numeric(20,0),
  "tipdoc" numeric(20,0),
  "codlocinc" numeric(20,0),
  "adresainc" character varying(150),
  "datatransport" date,
  "codlocdesc" numeric(20,0),
  "adresadesc" character varying(150),
  "codptf" numeric(20,0),
  "codbv" numeric(20,0),
  "codparttr" numeric(20,0),
  "nrauto" character varying(15),
  "nrremorca1" character varying(15),
  "nrremorca2" character varying(15),
  "codpartretailtr" numeric(20,0),
  "greutate_bruta" numeric(10,2),
  "tiplocinc" numeric(5,0),
  "tiplocdesc" numeric(5,0),
  "codptfdesc" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>detaliiet1</obj_name>
  <obj_hashval>504634107cb8b7cc06588b21287afd87</obj_hashval>
  <obj_text>CREATE TABLE detaliiet1 (
  "coddetaliuet1" numeric(20,0) NOT NULL,
  "coddetaliuet" numeric(20,0),
  "datatransport" timestamp(6) without time zone,
  "nrauto" character varying(15),
  "nrremorca1" character varying(15),
  "nrremorca2" character varying(15),
  "obs" character varying(1000)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>dezasamblari</obj_name>
  <obj_hashval>36a563b5a78f3e2846679d0f2d69b459</obj_hashval>
  <obj_text>CREATE TABLE dezasamblari (
  "codlivr1" numeric(20,0) NOT NULL,
  "codnirstoc" numeric(20,0),
  "valoare" numeric(20,7),
  "inchisa" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>dezasamblari1</obj_name>
  <obj_hashval>2cca0d52d9aad6e6c4d8f36542ac0a94</obj_hashval>
  <obj_text>CREATE TABLE dezasamblari1 (
  "codintrlink" numeric(20,0) NOT NULL,
  "codlivr1" numeric(20,0),
  "valoare" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>dificultati</obj_name>
  <obj_hashval>a5af889ef37205679c957ec2d6d04335</obj_hashval>
  <obj_text>CREATE TABLE dificultati (
  "coddif" numeric(20,0) NOT NULL,
  "denumire" character varying(150)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>difpretprod</obj_name>
  <obj_hashval>d90d3208d0cb2302443553dfb2244af3</obj_hashval>
  <obj_text>CREATE TABLE difpretprod (
  "coddifpretprod" numeric(20,0) NOT NULL,
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "obs" character varying(150),
  "operat" numeric(1,0),
  "subunitatea" numeric(20,0),
  "codgest" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>difpretprod1</obj_name>
  <obj_hashval>3c695ecf510c781ba49521fcbf5a62ef</obj_hashval>
  <obj_text>CREATE TABLE difpretprod1 (
  "coddifpretprod1" numeric(20,0) NOT NULL,
  "coddifpretprod" numeric(20,0),
  "codcomanda1" numeric(20,0),
  "codnirstoc" numeric(20,0),
  "anluna" numeric(5,0),
  "difpret" numeric(20,7),
  "codcentru" numeric(20,0),
  "codanalizanod" numeric(20,0),
  "dirty" numeric(1,0),
  "curent" numeric(1,0),
  "intrari" numeric(20,7),
  "iesiri" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>dintrastat</obj_name>
  <obj_hashval>c156f3bdbd5e81f9f71610532912b352</obj_hashval>
  <obj_text>CREATE TABLE dintrastat (
  "coddintrastat" numeric(20,0) NOT NULL,
  "subunitatea" numeric(20,0),
  "an" numeric(4,0),
  "lunad" numeric(2,0),
  "tipa" numeric(1,0),
  "tipd" numeric(1,0),
  "vatnr" character varying(30),
  "firmname" character varying(100),
  "cplastname" character varying(200),
  "cpfirstname" character varying(200),
  "cpposition" character varying(50),
  "cpphone" character varying(15),
  "cpfax" character varying(15),
  "cpemail" character varying(80),
  "dtp" numeric(1,0),
  "dtpvatnr" character varying(30),
  "dtpfirmname" character varying(100),
  "dtpstreet" character varying(100),
  "dtpstreetnumber" character varying(15),
  "dtpblock" character varying(5),
  "dtpstairs" character varying(5),
  "dtpapartment" character varying(10),
  "dtpcodlocalit" numeric(20,0),
  "dtppostalcode" character varying(10),
  "obs" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncontreprul_codcont</obj_name>
  <obj_reftable>ncontreprul</obj_reftable>
  <obj_hashval>f057447030abac684a7d89fd5158c316</obj_hashval>
  <obj_text>CREATE INDEX idx_ncontreprul_codcont ON ncontreprul USING btree (codcont)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncontrepsold_codcont</obj_name>
  <obj_reftable>ncontrepsold</obj_reftable>
  <obj_hashval>2bfe1a3681fd548711a02651f2a62da6</obj_hashval>
  <obj_text>CREATE INDEX idx_ncontrepsold_codcont ON ncontrepsold USING btree (codcont)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncontrul_alc</obj_name>
  <obj_reftable>ncontrul</obj_reftable>
  <obj_hashval>5bd0e42b4297b3510b99b510c91e78c5</obj_hashval>
  <obj_text>CREATE INDEX idx_ncontrul_alc ON ncontrul USING btree (an, luna, codcont)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>dintrastata</obj_name>
  <obj_hashval>4cc4eae4ab3860efce2bd1bf0f5c8636</obj_hashval>
  <obj_text>CREATE TABLE dintrastata (
  "coddintrastata" numeric(20,0) NOT NULL,
  "coddintrastat" numeric(20,0),
  "cn8code" character varying(8),
  "invoicevalue" numeric(20,0),
  "statisticalvalue" numeric(20,0),
  "netmass" numeric(20,0),
  "natureoftransactionacode" character varying(3),
  "natureoftransactionbcode" character varying(3),
  "deliverytermscode" character varying(3),
  "modeoftransportcode" character varying(3),
  "countryoforigin" character varying(3),
  "supplunitcode" character varying(15),
  "qtyinsupplunits" numeric(20,0),
  "countryofconsignment" character varying(3)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>dintrastatd</obj_name>
  <obj_hashval>2b3d61554d1d60b97d4dcabfdfbb5251</obj_hashval>
  <obj_text>CREATE TABLE dintrastatd (
  "coddintrastatd" numeric(20,0) NOT NULL,
  "coddintrastat" numeric(20,0),
  "cn8code" character varying(8),
  "invoicevalue" numeric(20,0),
  "statisticalvalue" numeric(20,0),
  "netmass" numeric(20,0),
  "natureoftransactionacode" character varying(3),
  "natureoftransactionbcode" character varying(3),
  "deliverytermscode" character varying(3),
  "modeoftransportcode" character varying(3),
  "countryoforigin" character varying(3),
  "supplunitcode" character varying(15),
  "qtyinsupplunits" numeric(20,0),
  "countryofdestination" character varying(3),
  "partnercountrycode" character varying(3),
  "partnervatnr" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>dirtyjurnal</obj_name>
  <obj_hashval>d55f73f9669dad76b5938c1aafe65a21</obj_hashval>
  <obj_text>CREATE TABLE dirtyjurnal (
  "anluna" numeric(5,0) NOT NULL
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>discart</obj_name>
  <obj_hashval>48eff2b32b2c57f2f7e03220ca2921f4</obj_hashval>
  <obj_text>CREATE TABLE discart (
  "coddiscart" numeric(20,0) NOT NULL,
  "coddiscount" numeric(20,0),
  "codobiect" numeric(20,0),
  "codclasa" numeric(20,0),
  "grupa" character varying(20)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>discexceptii</obj_name>
  <obj_hashval>57d08d9b69a578c21eb259810df2cd65</obj_hashval>
  <obj_text>CREATE TABLE discexceptii (
  "coddiscexceptie" numeric(20,0),
  "coddiscount" numeric(20,0),
  "codobiect" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>discinterval</obj_name>
  <obj_hashval>96d519f358f7bbcd9d749ee180432438</obj_hashval>
  <obj_text>CREATE TABLE discinterval (
  "coddiscinterval" numeric(20,0) NOT NULL,
  "coddiscount" numeric(20,0),
  "liminf" numeric(20,7),
  "limsup" numeric(20,7),
  "procent" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>discmonetar</obj_name>
  <obj_hashval>b0be947e977bf686538085c30f7b8aa8</obj_hashval>
  <obj_text>CREATE TABLE discmonetar (
  "coddiscmonetar" numeric(20,0),
  "codies" numeric(20,0),
  "proctva" numeric(20,7),
  "discount" numeric(20,7),
  "tvadiscount" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>discount</obj_name>
  <obj_hashval>9dd68cabbfed50afd4468c9f2e6fcee1</obj_hashval>
  <obj_text>CREATE TABLE discount (
  "coddiscount" numeric(20,0) NOT NULL,
  "codcriteriu" numeric(10,0),
  "subunitatea" numeric(20,0),
  "codcriteriu1" numeric(20,0),
  "codtipsediu" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>discpromoretail</obj_name>
  <obj_hashval>0acffe599adec61ab55da0ea5d4524c7</obj_hashval>
  <obj_text>CREATE TABLE discpromoretail (
  "cod" numeric(20,0),
  "codpostretail" numeric(20,0),
  "codobiect" numeric(20,0),
  "discpromo" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>distanta</obj_name>
  <obj_hashval>89e109f3e4f1fbf6fd8b34b253b4e230</obj_hashval>
  <obj_text>CREATE TABLE distanta (
  "coddistanta" numeric(20,0) NOT NULL,
  "codgest_start" numeric(20,0),
  "codgest_stop" numeric(20,0),
  "codlocalit_start" numeric(20,0),
  "codlocalit_stop" numeric(20,0),
  "km" numeric(20,0),
  "moneda" numeric(20,0),
  "valoare" numeric(22,2)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>distrib</obj_name>
  <obj_hashval>e4c5dfc28eed6a5038e267d81d6bc3c3</obj_hashval>
  <obj_text>CREATE TABLE distrib (
  "coddistrib" numeric(20,0) NOT NULL,
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "zi" numeric(2,0),
  "subunitatea" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>distrib1</obj_name>
  <obj_hashval>8d59f6f49d1a9dd32ad035556908d65b</obj_hashval>
  <obj_text>CREATE TABLE distrib1 (
  "coddistrib1" numeric(20,0) NOT NULL,
  "coddistrib" numeric(20,0),
  "codpers" numeric(20,0),
  "codauto" numeric(20,0),
  "codtraseu" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>distrib2</obj_name>
  <obj_hashval>f1852b5b9ce2ef9d2732abc73151c070</obj_hashval>
  <obj_text>CREATE TABLE distrib2 (
  "coddistrib2" numeric(20,0) NOT NULL,
  "coddistrib" numeric(20,0),
  "coddistrib1" numeric(20,0),
  "codagenda" numeric(20,0),
  "sold" numeric(20,7),
  "poztraseu" numeric(20,0),
  "den_part" character varying(50),
  "obs" character varying(30),
  "adresa" character varying(200),
  "den_judet" character varying(30),
  "den_localit" character varying(50),
  "codpart" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>distrib3</obj_name>
  <obj_hashval>d0c3572cc51be6bf3185f4c21867b97b</obj_hashval>
  <obj_text>CREATE TABLE distrib3 (
  "coddistrib3" numeric(20,0) NOT NULL,
  "coddistrib" numeric(20,0),
  "coddistrib1" numeric(20,0),
  "coddistrib2" numeric(20,0),
  "doc" character varying(100),
  "nrdoc" numeric(10,0),
  "datadoc" date,
  "valreal" numeric(20,7),
  "restreal" numeric(20,7),
  "termen" date,
  "zilescadente" numeric(10,0),
  "simbolcont" character varying(100),
  "den_subunit" character varying(150),
  "prefixdoc" character varying(20)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>distribchelt</obj_name>
  <obj_hashval>6c356f0f5fe05996cd3880de2f08b449</obj_hashval>
  <obj_text>CREATE TABLE distribchelt (
  "coddistribchelt" numeric(20,0) NOT NULL,
  "tipdoc" numeric(2,0),
  "obs" character varying(50),
  "an" numeric(5,0),
  "luna" numeric(2,0),
  "subunitatea" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "blocat" numeric(1,0),
  "operat" numeric(1,0),
  "faza" numeric(1,0),
  "codgest" numeric(20,0),
  "coefprod" numeric(20,7),
  "codcentru" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>distribchelt1</obj_name>
  <obj_hashval>c72e4f838b21f8c6b7f495bb59fffcb9</obj_hashval>
  <obj_text>CREATE TABLE distribchelt1 (
  "coddistribchelt1" numeric(20,0) NOT NULL,
  "coddistribchelt" numeric(20,0),
  "codnest" numeric(20,0),
  "val" numeric(20,7),
  "indexlocal" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>distribchelt2</obj_name>
  <obj_hashval>4c36f08145ed0f7f5eafc9a1c4d050ed</obj_hashval>
  <obj_text>CREATE TABLE distribchelt2 (
  "coddistribchelt2" numeric(20,0) NOT NULL,
  "coddistribchelt1" numeric(20,0),
  "coddistribchelt" numeric(20,0),
  "indexlocal" numeric(5,0),
  "codgest" numeric(20,0),
  "codcentru" numeric(20,0),
  "obs" character varying(50),
  "procent" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>diverse</obj_name>
  <obj_hashval>8cdf007996c012c06a60f76251e4f314</obj_hashval>
  <obj_text>CREATE TABLE diverse (
  "tip" numeric(3,0),
  "cod" numeric(20,0),
  "obs" character varying(100),
  "tipdoc" numeric(3,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>docasoc</obj_name>
  <obj_hashval>34b6caa1ba4fa6b86f7eca64633a0edf</obj_hashval>
  <obj_text>CREATE TABLE docasoc (
  "coddoc" numeric(20,0),
  "tipdoc" numeric(20,0),
  "coddocasoc" numeric(20,0),
  "tipdocasoc" numeric(20,0),
  "obs" character varying(400)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>doccarnete</obj_name>
  <obj_hashval>40eb8a492e931c6058d6a2952fdd2a5d</obj_hashval>
  <obj_text>CREATE TABLE doccarnete (
  "codcarnet" numeric(20,0) NOT NULL,
  "simbol" character varying(10),
  "denumire" character varying(50),
  "serie" character varying(20),
  "startnr" numeric(20,0),
  "endnr" numeric(20,0),
  "freenr" numeric(20,0),
  "inactiv" numeric(1,0),
  "subunitatea" numeric(20,0),
  "limita" numeric(20,0),
  "startnrini" numeric(20,0),
  "dedicat" numeric(1,0),
  "comenzionline" numeric(1,0),
  "codpostretail" numeric(20,0),
  "farasalvare" numeric(1,0),
  "in_update" numeric(1,0),
  "allsubunit" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>doceditat</obj_name>
  <obj_hashval>240abcb3fd12877b85d47a74f419103f</obj_hashval>
  <obj_text>CREATE TABLE doceditat (
  "coddoceditat" numeric(20,0),
  "coddoc" numeric(10,0),
  "tabela" character varying(30),
  "userid" numeric
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>docextra</obj_name>
  <obj_hashval>0cb7001d6c88736419c29f595fe14acf</obj_hashval>
  <obj_text>CREATE TABLE docextra (
  "tipdoc" numeric(20,0) NOT NULL,
  "coddoc" numeric(20,0) NOT NULL,
  "export_edi" numeric(1,0),
  "export_edi_data" timestamp(6) without time zone
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>docfree</obj_name>
  <obj_hashval>c510194ba5f852d60f089f46f6d843ac</obj_hashval>
  <obj_text>CREATE TABLE docfree (
  "coddocfree" numeric(20,0) NOT NULL,
  "codcarnet" numeric(20,0),
  "startnr" numeric(20,0),
  "endnr" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>doclink</obj_name>
  <obj_hashval>e5be79b4d15cbe68f6d25d0b8ea449ab</obj_hashval>
  <obj_text>CREATE TABLE doclink (
  "coddoclink" numeric(20,0) NOT NULL,
  "codcarnet" numeric(20,0),
  "codmacheta" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>doclock</obj_name>
  <obj_hashval>c94d6130d5b26ee5db82722883ddd8f5</obj_hashval>
  <obj_text>CREATE TABLE doclock (
  "coddoclock" numeric(20,0) NOT NULL,
  "codcarnet" numeric(20,0),
  "usedno" numeric(20,0),
  "userid" numeric(20,0),
  "connindex" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>docsuplim</obj_name>
  <obj_hashval>6a1ab31c40fe8d6072eaa1fece6f7ab3</obj_hashval>
  <obj_text>CREATE TABLE docsuplim (
  "coddocsuplim" numeric(20,0) NOT NULL,
  "tipdoc" numeric(2,0),
  "dendoc" character varying(30),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "subunitatea" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>docsuplim1</obj_name>
  <obj_hashval>2cf5febb73a906381997c273100c2bfe</obj_hashval>
  <obj_text>CREATE TABLE docsuplim1 (
  "coddocsuplim1" numeric(20,0) NOT NULL,
  "coddocsuplim" numeric(20,0),
  "denlinie" character varying(50),
  "valoare" numeric(20,7),
  "valoarev" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>documente</obj_name>
  <obj_hashval>1ff734c51dbe53569711a0f149eaa2b7</obj_hashval>
  <obj_text>CREATE TABLE documente (
  "coddocument" numeric(20,0) NOT NULL,
  "coddoc" numeric(20,0),
  "tipdoc" numeric(20,0),
  "filename" character varying(200),
  "doc" bytea,
  "obs" character varying(4000),
  "userid" numeric(20,0),
  "datacreare" timestamp(0) without time zone,
  "coddosar" numeric(20,0),
  "coddepozit" numeric(20,0),
  "tipdocument" numeric(2,0),
  "expefact" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>docusers</obj_name>
  <obj_hashval>97023c744c918f0ae917a51a08064ee9</obj_hashval>
  <obj_text>CREATE TABLE docusers (
  "coddocusers" numeric(20,0) NOT NULL,
  "codcarnet" numeric(20,0),
  "coduser" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>domeniiact</obj_name>
  <obj_hashval>643da9a87dece61cf83dff337bf8663f</obj_hashval>
  <obj_text>CREATE TABLE domeniiact (
  "coddomeniuact" numeric(20,0) NOT NULL,
  "dendomeniuact" character varying(160),
  "codcaen" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>dosare</obj_name>
  <obj_hashval>48c4f8df2644290283c47c5233f64143</obj_hashval>
  <obj_text>CREATE TABLE dosare (
  "coddosar" numeric(6,0) NOT NULL,
  "denumire" character varying(30),
  "dulap" character varying(20),
  "raft" character varying(20),
  "tip" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncontrul_codcont</obj_name>
  <obj_reftable>ncontrul</obj_reftable>
  <obj_hashval>d8716446efc25c59654ad87027862808</obj_hashval>
  <obj_text>CREATE INDEX idx_ncontrul_codcont ON ncontrul USING btree (codcont)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>dprofit</obj_name>
  <obj_hashval>74902e4be4b60399ce58b88915bcf74f</obj_hashval>
  <obj_text>CREATE TABLE dprofit (
  "coddprofit" numeric(20,0) NOT NULL,
  "tipprofit" numeric(5,0),
  "tipan" numeric(5,0),
  "elemsimvenit" numeric(20,7),
  "elemsimchelt" numeric(20,7),
  "deduceri" numeric(20,7),
  "dedrezleg" numeric(20,7),
  "dedprofitr" numeric(20,7),
  "dedalte" numeric(20,7),
  "cheltafvenit" numeric(20,7),
  "cheltpradm" numeric(20,7),
  "cheltprneded" numeric(20,7),
  "pierdere" numeric(20,7),
  "profitconta" numeric(20,7),
  "profitimpoz" numeric(20,7),
  "sumamax" numeric(20,7),
  "cheltsponsor" numeric(20,7),
  "impozitprofit" numeric(20,7),
  "impozitprofitd" numeric(20,7),
  "an" numeric(4,0),
  "trimestru" numeric(1,0),
  "totalrulajv" numeric(20,7),
  "totalvenituri" numeric(20,7),
  "totalsumev" numeric(20,7),
  "totalrulajc" numeric(20,7),
  "totalchelt" numeric(20,7),
  "totalsumec" numeric(20,7),
  "obs" character varying(250),
  "subunitatea" numeric(20,0),
  "amofisc" numeric(20,7),
  "cheltdobprec" numeric(20,7),
  "provfisc" numeric(20,7),
  "creditfiscext" numeric(20,7),
  "impprofreinv" numeric(20,7),
  "altescutiri" numeric(20,7),
  "cifraafaceri" numeric(20,7),
  "creditfiscal" numeric(20,7),
  "impozitprofitc" numeric(20,7),
  "impprofdif" numeric(20,7),
  "angenerare" numeric(4,0),
  "lunagenerare" numeric(2,0),
  "sponsorreport" numeric(20,7),
  "codnc" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "trimestrut" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>dprofitc</obj_name>
  <obj_hashval>02515184e75ff5bbcf3501e834c46ffe</obj_hashval>
  <obj_text>CREATE TABLE dprofitc (
  "coddprofitc" numeric(20,0) NOT NULL,
  "coddprofit" numeric(20,0),
  "codcont" numeric(20,0),
  "rulaj" numeric(20,7),
  "cheltuieli" numeric(20,7),
  "suma" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>dprofitv</obj_name>
  <obj_hashval>56960695bfa4f3fddbe169d48361cfc3</obj_hashval>
  <obj_text>CREATE TABLE dprofitv (
  "coddprofitv" numeric(20,0) NOT NULL,
  "coddprofit" numeric(20,0),
  "codcont" numeric(20,0),
  "rulaj" numeric(20,7),
  "venituri" numeric(20,7),
  "suma" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>dvi</obj_name>
  <obj_hashval>e2ebdbf8e9a602b6c8fee144cf8d8355</obj_hashval>
  <obj_text>CREATE TABLE dvi (
  "coddvi" numeric(20,0) NOT NULL,
  "codintr" numeric(20,0),
  "codvama" numeric(20,0),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "contchelt" numeric(20,0),
  "conttva" numeric(20,0),
  "taxeincluse" numeric(1,0),
  "fisavama" numeric(1,0),
  "taxepechelt" numeric(1,0),
  "tiprepsuplim" numeric(1,0),
  "valsuplim" numeric(20,7),
  "contsuplim" numeric(20,0),
  "obs" character varying(100),
  "tipimport" numeric(1,0),
  "valdocvama" numeric(20,7),
  "tvadocvama" numeric(20,7),
  "farareg" numeric(1,0),
  "exclusplata" numeric(1,0),
  "tvaincasare" numeric(1,0),
  "seriadoc" character varying(20)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>dvi1</obj_name>
  <obj_hashval>a69c90680a134f005ec755b1ba885205</obj_hashval>
  <obj_text>CREATE TABLE dvi1 (
  "coddvi1" numeric(20,0) NOT NULL,
  "coddvi" numeric(20,0),
  "codintr1" numeric(20,0),
  "tiplinie" character varying(1),
  "indexlocal" numeric(7,0),
  "pretimport" numeric(20,7),
  "pretvaluta" numeric(20,7),
  "pretoriginal" numeric(20,7),
  "tva" numeric(20,7),
  "umsec" numeric(10,0),
  "addim" numeric(20,7),
  "codobiect" numeric(20,0),
  "cant" numeric(20,7),
  "valoaretaxa" numeric(20,7),
  "contdiscount" numeric(20,0),
  "pumaximal" numeric(20,7),
  "tvaneded" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>efact_custom</obj_name>
  <obj_hashval>cca9fc0df90cb3d0a0c90e653ad6e13f</obj_hashval>
  <obj_text>CREATE TABLE efact_custom (
  "codefactc" numeric(20,0),
  "den_efcustom" character varying(200),
  "sqlcampuri" text,
  "sqlcampuri1" text
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>efcustom</obj_name>
  <obj_hashval>55593f41095d8f9d784d2986a8f20478</obj_hashval>
  <obj_text>CREATE TABLE efcustom (
  "codefcustom" numeric(20,0) NOT NULL,
  "den_efcustom" character varying(30),
  "sqlcampuri" text,
  "sqlcampuri1" text
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>elembuget</obj_name>
  <obj_hashval>ffa1e798de21f212bd63b335a7a09f33</obj_hashval>
  <obj_text>CREATE TABLE elembuget (
  "codelembuget" numeric(20,0) NOT NULL,
  "element" character varying(250),
  "simbol" character varying(30),
  "tip" numeric(5,0),
  "functie" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>elembuget1</obj_name>
  <obj_hashval>bb36a01a82ec7d2e4b5e9a16a3fa9cbf</obj_hashval>
  <obj_text>CREATE TABLE elembuget1 (
  "codelembuget1" numeric(20,0) NOT NULL,
  "codelembuget" numeric(20,0),
  "codclasea" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>elembuget2</obj_name>
  <obj_hashval>cd4e48902f56d96ac9be5a6181465f1e</obj_hashval>
  <obj_text>CREATE TABLE elembuget2 (
  "codelembuget2" numeric(20,0) NOT NULL,
  "codelembuget" numeric(20,0),
  "an" numeric(4,0),
  "s1" numeric(20,7),
  "s2" numeric(20,7),
  "s3" numeric(20,7),
  "s4" numeric(20,7),
  "s5" numeric(20,7),
  "s6" numeric(20,7),
  "s7" numeric(20,7),
  "s8" numeric(20,7),
  "s9" numeric(20,7),
  "s10" numeric(20,7),
  "s11" numeric(20,7),
  "s12" numeric(20,7),
  "s13" numeric(20,7),
  "s14" numeric(20,7),
  "s15" numeric(20,7),
  "s16" numeric(20,7),
  "s17" numeric(20,7),
  "s18" numeric(20,7),
  "s19" numeric(20,7),
  "s20" numeric(20,7),
  "s21" numeric(20,7),
  "s22" numeric(20,7),
  "s23" numeric(20,7),
  "s24" numeric(20,7),
  "s25" numeric(20,7),
  "s26" numeric(20,7),
  "s27" numeric(20,7),
  "s28" numeric(20,7),
  "s29" numeric(20,7),
  "s30" numeric(20,7),
  "s31" numeric(20,7),
  "s32" numeric(20,7),
  "s33" numeric(20,7),
  "s34" numeric(20,7),
  "s35" numeric(20,7),
  "s36" numeric(20,7),
  "s37" numeric(20,7),
  "s38" numeric(20,7),
  "s39" numeric(20,7),
  "s40" numeric(20,7),
  "s41" numeric(20,7),
  "s42" numeric(20,7),
  "s43" numeric(20,7),
  "s44" numeric(20,7),
  "s45" numeric(20,7),
  "s46" numeric(20,7),
  "s47" numeric(20,7),
  "s48" numeric(20,7),
  "s49" numeric(20,7),
  "s50" numeric(20,7),
  "s51" numeric(20,7),
  "s52" numeric(20,7),
  "s53" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>elemente</obj_name>
  <obj_hashval>3ff071cc3fb7ef63cfa6323f018fe34d</obj_hashval>
  <obj_text>CREATE TABLE elemente (
  "codelement" numeric(20,0) NOT NULL,
  "den_element" character varying(100),
  "tip" numeric(2,0),
  "coddescriptorbaza" numeric(20,0),
  "simbol" character varying(10),
  "cv" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>elementea</obj_name>
  <obj_hashval>0c548426dd8a57f7c416a1b25d4dcbed</obj_hashval>
  <obj_text>CREATE TABLE elementea (
  "codelementa" numeric(20,0) NOT NULL,
  "codelement" numeric(20,0),
  "codanaliza" numeric(20,0),
  "nodmaximanaliza1" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>elementec</obj_name>
  <obj_hashval>509fd333cc6125c43b6ca507859ccdfa</obj_hashval>
  <obj_text>CREATE TABLE elementec (
  "codelementc" numeric(20,0) NOT NULL,
  "codelementm" numeric(20,0),
  "masca" character varying(20)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>elementem</obj_name>
  <obj_hashval>5ebccfaca088816286019fd4a2bf379c</obj_hashval>
  <obj_text>CREATE TABLE elementem (
  "codelementm" numeric(20,0) NOT NULL,
  "codelement" numeric(20,0),
  "tipdoc" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>emulare</obj_name>
  <obj_hashval>6f2795aec60d10997389badf53f99f7e</obj_hashval>
  <obj_text>CREATE TABLE emulare (
  "codemulare" numeric(20,0) NOT NULL,
  "nrbon" numeric(20,0),
  "databon" date,
  "valoare" numeric(20,7),
  "valoarediscount" numeric(20,7),
  "listat" numeric(1,0),
  "preluat" numeric(1,0),
  "codcasamarcat" numeric(20,0),
  "tvatotal" numeric(20,7),
  "tvadiscount" numeric(20,7),
  "tipcasamarcat" numeric(5,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "datalistare" timestamp(6) without time zone,
  "codies" numeric(20,0),
  "codpart" numeric(20,0),
  "incasareclient" numeric(1,0),
  "codmonetar" numeric(20,0),
  "codpers" numeric(20,0),
  "codpostretail" numeric(20,0),
  "codaecustodie" numeric(20,0),
  "codlocatie" numeric(20,0),
  "codagent" numeric(20,0),
  "obs" character varying(100),
  "codrestnp" numeric(20,0),
  "codpartcomis" numeric(20,0),
  "textnefiscal" character varying(100),
  "factsimplif" numeric(1,0),
  "idbon" numeric,
  "facturare" numeric(1,0),
  "delegat" numeric(20,0),
  "exclusdiscount" numeric(1,0),
  "codpartretail" numeric(20,0),
  "codiesretail" numeric(20,0),
  "codsediuretail" numeric(20,0),
  "punctecumul" numeric(20,0),
  "valpunctecumul" numeric(20,7),
  "delegatretail" numeric(20,0),
  "codpartretailcomis" numeric(20,0),
  "valvaluta" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncontruls_codconts</obj_name>
  <obj_reftable>ncontruls</obj_reftable>
  <obj_hashval>5d9b8074eac229ebeab3345536fdf6d3</obj_hashval>
  <obj_text>CREATE INDEX idx_ncontruls_codconts ON ncontruls USING btree (codconts)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>emulare1</obj_name>
  <obj_hashval>4eef7b705011b1ffa94d63bc630b30d4</obj_hashval>
  <obj_text>CREATE TABLE emulare1 (
  "codemulare1" numeric(20,0) NOT NULL,
  "codemulare" numeric(20,0),
  "codobiect" numeric(20,0),
  "indexlocal" numeric(10,0),
  "pretart" numeric(20,7),
  "pret" numeric(20,7),
  "cant" numeric(20,7),
  "umsec" numeric(20,0),
  "discount" numeric(20,7),
  "codioart" numeric(20,0),
  "codgest" numeric(20,0),
  "tva" numeric(20,7),
  "tiplinie" character varying(1),
  "pretnirstoc" numeric(20,7),
  "contserv" numeric(20,0),
  "codemulstingere" numeric(20,0),
  "farastoc" numeric(1,0),
  "codcomanda1" numeric(20,0),
  "tiplivrare" numeric(1,0),
  "cadou" numeric(20,0),
  "pretpromo" numeric(1,0),
  "codgestorig" numeric(20,0),
  "codnirstocrez" numeric(20,0),
  "codnirserrez" numeric(20,0),
  "discmanual" numeric(1,0),
  "codpostretail" numeric(20,0),
  "codserie" numeric(20,0),
  "codtransf1" numeric(20,0),
  "pretnepromo" numeric(20,7),
  "promotionat" numeric(1,0),
  "forcepromo" numeric(1,0),
  "infopromo" character varying(100),
  "infopromodisc" character varying(100),
  "codpromo1" numeric(20,0),
  "proctvabon" numeric(20,7),
  "taxa" numeric(1,0),
  "codemul1avans" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>emulare1retail</obj_name>
  <obj_hashval>5a9bf9626f8e9b7b1c28f93387c4fe21</obj_hashval>
  <obj_text>CREATE TABLE emulare1retail (
  "codemulare1" numeric(20,0),
  "codemulare" numeric(20,0),
  "codobiect" numeric(20,0),
  "indexlocal" numeric(10,0),
  "pretart" numeric(20,7),
  "pret" numeric(20,7),
  "cant" numeric(20,7),
  "umsec" numeric(20,0),
  "discount" numeric(20,7),
  "codioart" numeric(20,0),
  "codgest" numeric(20,0),
  "tva" numeric(20,7),
  "tiplinie" character varying(1),
  "pretnirstoc" numeric(20,7),
  "contserv" numeric(20,0),
  "codemulstingere" numeric(20,0),
  "farastoc" numeric(1,0),
  "codcomanda1" numeric(20,0),
  "tiplivrare" numeric(1,0),
  "cadou" numeric(20,0),
  "pretpromo" numeric(1,0),
  "codgestorig" numeric(20,0),
  "codnirstocrez" numeric(20,0),
  "codnirserrez" numeric(20,0),
  "discmanual" numeric(1,0),
  "codpostretail" numeric(20,0),
  "codserie" numeric(20,0),
  "codtransf1" numeric(20,0),
  "pretnepromo" numeric(20,7),
  "promotionat" numeric(1,0),
  "forcepromo" numeric(1,0),
  "infopromo" character varying(100),
  "infopromodisc" character varying(100),
  "codpromo1" numeric(20,0),
  "proctvabon" numeric(20,7),
  "taxa" numeric(1,0),
  "codemul1avans" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>emulare2</obj_name>
  <obj_hashval>b455605838433f3de73a2014cf6e58c2</obj_hashval>
  <obj_text>CREATE TABLE emulare2 (
  "codemulare2" numeric(20,0) NOT NULL,
  "codemulare" numeric(20,0),
  "tipplata" numeric(10,0),
  "valoare" numeric(20,7),
  "denumire" character varying(250),
  "codbankcont" numeric(20,0),
  "codpostretail" numeric(20,0),
  "codcard" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>emulare2retail</obj_name>
  <obj_hashval>be4f14bcdef2bc3f9896480357f4ba81</obj_hashval>
  <obj_text>CREATE TABLE emulare2retail (
  "codemulare2" numeric(20,0),
  "codemulare" numeric(20,0),
  "tipplata" numeric(10,0),
  "valoare" numeric(20,7),
  "denumire" character varying(250),
  "codbankcont" numeric(20,0),
  "codpostretail" numeric(20,0),
  "codcard" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>emulareretail</obj_name>
  <obj_hashval>60f38a294b04f24d8052a2233e1cd921</obj_hashval>
  <obj_text>CREATE TABLE emulareretail (
  "codemulare" numeric(20,0) NOT NULL,
  "nrbon" numeric(20,0),
  "databon" date,
  "valoare" numeric(20,7),
  "valoarediscount" numeric(20,7),
  "listat" numeric(1,0),
  "preluat" numeric(1,0),
  "codcasamarcat" numeric(20,0),
  "tvatotal" numeric(20,7),
  "tvadiscount" numeric(20,7),
  "tipcasamarcat" numeric(5,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "datalistare" timestamp(6) without time zone,
  "codies" numeric(20,0),
  "codpart" numeric(20,0),
  "incasareclient" numeric(1,0),
  "codmonetar" numeric(20,0),
  "codpers" numeric(20,0),
  "codpostretail" numeric(20,0),
  "codaecustodie" numeric(20,0),
  "codlocatie" numeric(20,0),
  "codagent" numeric(20,0),
  "obs" character varying(100),
  "codrestnp" numeric(20,0),
  "codpartcomis" numeric(20,0),
  "textnefiscal" character varying(100),
  "factsimplif" numeric(1,0),
  "idbon" numeric,
  "facturare" numeric(1,0),
  "delegat" numeric(20,0),
  "exclusdiscount" numeric(1,0),
  "codpartretail" numeric(20,0),
  "codiesretail" numeric(20,0),
  "codsediuretail" numeric(20,0),
  "punctecumul" numeric(20,0),
  "valpunctecumul" numeric(20,7),
  "delegatretail" numeric(20,0),
  "codpartretailcomis" numeric(20,0),
  "valvaluta" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>emuleditat</obj_name>
  <obj_hashval>6fbe7742579e60f53323dbc68f38b6e4</obj_hashval>
  <obj_text>CREATE TABLE emuleditat (
  "userid" numeric(20,0),
  "codemulare" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>emulpuncteused</obj_name>
  <obj_hashval>87ad9c0def65f4476034877b55c422ab</obj_hashval>
  <obj_text>CREATE TABLE emulpuncteused (
  "cod" numeric(20,0),
  "codemulare" numeric(20,0),
  "codpunctaj" numeric(20,0),
  "puncteused" numeric(20,7),
  "valacordata" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>emulstingeri</obj_name>
  <obj_hashval>57d5d321f1cba1a8ad211b12b1e3212b</obj_hashval>
  <obj_text>CREATE TABLE emulstingeri (
  "codemulstingere" numeric(20,0),
  "codemulare" numeric(20,0),
  "codobligpif" numeric(20,7),
  "valoare" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>errorsdelete</obj_name>
  <obj_hashval>3a89e786054cfb74c27b40ab5bc62cf0</obj_hashval>
  <obj_text>CREATE TABLE errorsdelete (
  "numetabela" character varying(30),
  "cod" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>estimarinod</obj_name>
  <obj_hashval>f36049a1f37f06b5266e50e4572c3a1d</obj_hashval>
  <obj_text>CREATE TABLE estimarinod (
  "codestimarenod" numeric(20,0) NOT NULL,
  "codestimareprod" numeric(20,0),
  "codestimareprod1" numeric(20,0),
  "cant" numeric(20,7),
  "nodoriginal" numeric(20,0),
  "pozitie" numeric(10,0),
  "codreteta" numeric(20,0),
  "tip" numeric(1,0),
  "codobiect" numeric(20,0),
  "indexparinte" character varying(50),
  "codprodmat" numeric(20,0),
  "nivel" numeric(10,0),
  "ordine" numeric(5,0),
  "codproiectnod" numeric(20,0),
  "versiune" numeric(1,0),
  "cantprodreteta" numeric(20,7),
  "cantmatreteta" numeric(20,7),
  "necesar" numeric(20,7),
  "saptamana" numeric(2,0),
  "an" numeric(4,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>estimarinod_c1</obj_name>
  <obj_hashval>f58a740624b9760e433c0c36361dc3df</obj_hashval>
  <obj_text>CREATE TABLE estimarinod_c1 (
  "codestimarenod" numeric(20,0) NOT NULL,
  "codestimareprod" numeric(20,0),
  "codestimareprod1" numeric(20,0),
  "cant" numeric(20,7),
  "nodoriginal" numeric(20,0),
  "pozitie" numeric(10,0),
  "codreteta" numeric(20,0),
  "tip" numeric(1,0),
  "codobiect" numeric(20,0),
  "indexparinte" character varying(50),
  "codprodmat" numeric(20,0),
  "nivel" numeric(10,0),
  "ordine" numeric(5,0),
  "codproiectnod" numeric(20,0),
  "versiune" numeric(1,0),
  "cantprodreteta" numeric(20,7),
  "cantmatreteta" numeric(20,7),
  "necesar" numeric(20,7),
  "saptamana" numeric(2,0),
  "an" numeric(4,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>estimarinod_c2</obj_name>
  <obj_hashval>d1721355c061b11d971335deb4ff7b1f</obj_hashval>
  <obj_text>CREATE TABLE estimarinod_c2 (
  "codestimarenod" numeric(20,0),
  "codestimareprod" numeric(20,0),
  "codestimareprod1" numeric(20,0),
  "cant" numeric(20,7),
  "nodoriginal" numeric(20,0),
  "pozitie" numeric(10,0),
  "codreteta" numeric(20,0),
  "tip" numeric(1,0),
  "codobiect" numeric(20,0),
  "indexparinte" character varying(50),
  "codprodmat" numeric(20,0),
  "nivel" numeric(10,0),
  "ordine" numeric(5,0),
  "codproiectnod" numeric(20,0),
  "versiune" numeric(1,0),
  "cantprodreteta" numeric(20,7),
  "cantmatreteta" numeric(20,7),
  "necesar" numeric(20,7),
  "saptamana" numeric(2,0),
  "an" numeric(4,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>estimariprod</obj_name>
  <obj_hashval>69c548fcd2b4cebe8162e4e10ee49a54</obj_hashval>
  <obj_text>CREATE TABLE estimariprod (
  "codestimareprod" numeric(20,0) NOT NULL,
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "subunitatea" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "obs" character varying(400),
  "anulat" numeric(1,0),
  "blocat" numeric(1,0),
  "operat" numeric(1,0),
  "saptamana" numeric(2,0),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "carnetdoc" numeric(20,0),
  "seriadoc" character varying(20),
  "prefixdoc" character varying(10),
  "animport" numeric(4,0),
  "saptamanaf" numeric(2,0),
  "anf" numeric(4,0),
  "codoferta" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>estimariprod1</obj_name>
  <obj_hashval>065d58a98fa3bfa490b131061003ea90</obj_hashval>
  <obj_text>CREATE TABLE estimariprod1 (
  "codestimareprod1" numeric(20,0) NOT NULL,
  "codestimareprod" numeric(20,0),
  "codobiect" numeric(20,0),
  "c1" numeric(20,7),
  "c2" numeric(20,7),
  "c3" numeric(20,7),
  "c4" numeric(20,7),
  "c5" numeric(20,7),
  "c6" numeric(20,7),
  "c7" numeric(20,7),
  "c8" numeric(20,7),
  "c9" numeric(20,7),
  "c10" numeric(20,7),
  "c11" numeric(20,7),
  "c12" numeric(20,7),
  "c13" numeric(20,7),
  "c14" numeric(20,7),
  "c15" numeric(20,7),
  "c16" numeric(20,7),
  "c17" numeric(20,7),
  "c18" numeric(20,7),
  "c19" numeric(20,7),
  "c20" numeric(20,7),
  "c21" numeric(20,7),
  "c22" numeric(20,7),
  "c23" numeric(20,7),
  "c24" numeric(20,7),
  "c25" numeric(20,7),
  "c26" numeric(20,7),
  "c27" numeric(20,7),
  "c28" numeric(20,7),
  "c29" numeric(20,7),
  "c30" numeric(20,7),
  "c31" numeric(20,7),
  "c32" numeric(20,7),
  "c33" numeric(20,7),
  "c34" numeric(20,7),
  "c35" numeric(20,7),
  "c36" numeric(20,7),
  "c37" numeric(20,7),
  "c38" numeric(20,7),
  "c39" numeric(20,7),
  "c40" numeric(20,7),
  "c41" numeric(20,7),
  "c42" numeric(20,7),
  "c43" numeric(20,7),
  "c44" numeric(20,7),
  "c45" numeric(20,7),
  "c46" numeric(20,7),
  "c47" numeric(20,7),
  "c48" numeric(20,7),
  "c49" numeric(20,7),
  "c50" numeric(20,7),
  "c51" numeric(20,7),
  "c52" numeric(20,7),
  "n1" numeric(20,7),
  "n2" numeric(20,7),
  "n3" numeric(20,7),
  "n4" numeric(20,7),
  "n5" numeric(20,7),
  "n6" numeric(20,7),
  "n7" numeric(20,7),
  "n8" numeric(20,7),
  "n9" numeric(20,7),
  "n10" numeric(20,7),
  "n11" numeric(20,7),
  "n12" numeric(20,7),
  "n13" numeric(20,7),
  "n14" numeric(20,7),
  "n15" numeric(20,7),
  "n16" numeric(20,7),
  "n17" numeric(20,7),
  "n18" numeric(20,7),
  "n19" numeric(20,7),
  "n20" numeric(20,7),
  "n21" numeric(20,7),
  "n22" numeric(20,7),
  "n23" numeric(20,7),
  "n24" numeric(20,7),
  "n25" numeric(20,7),
  "n26" numeric(20,7),
  "n27" numeric(20,7),
  "n28" numeric(20,7),
  "n29" numeric(20,7),
  "n30" numeric(20,7),
  "n31" numeric(20,7),
  "n32" numeric(20,7),
  "n33" numeric(20,7),
  "n34" numeric(20,7),
  "n35" numeric(20,7),
  "n36" numeric(20,7),
  "n37" numeric(20,7),
  "n38" numeric(20,7),
  "n39" numeric(20,7),
  "n40" numeric(20,7),
  "n41" numeric(20,7),
  "n42" numeric(20,7),
  "n43" numeric(20,7),
  "n44" numeric(20,7),
  "n45" numeric(20,7),
  "n46" numeric(20,7),
  "n47" numeric(20,7),
  "n48" numeric(20,7),
  "n49" numeric(20,7),
  "n50" numeric(20,7),
  "n51" numeric(20,7),
  "n52" numeric(20,7),
  "c53" numeric(20,7),
  "n53" numeric(20,7),
  "pret" numeric(20,7),
  "scadenta" numeric(5,0),
  "val_c1" numeric(20,7),
  "val_c2" numeric(20,7),
  "val_c3" numeric(20,7),
  "val_c4" numeric(20,7),
  "val_c5" numeric(20,7),
  "val_c6" numeric(20,7),
  "val_c7" numeric(20,7),
  "val_c8" numeric(20,7),
  "val_c9" numeric(20,7),
  "val_c10" numeric(20,7),
  "val_c11" numeric(20,7),
  "val_c12" numeric(20,7),
  "val_c13" numeric(20,7),
  "val_c14" numeric(20,7),
  "val_c15" numeric(20,7),
  "val_c16" numeric(20,7),
  "val_c17" numeric(20,7),
  "val_c18" numeric(20,7),
  "val_c19" numeric(20,7),
  "val_c20" numeric(20,7),
  "val_c21" numeric(20,7),
  "val_c22" numeric(20,7),
  "val_c23" numeric(20,7),
  "val_c24" numeric(20,7),
  "val_c25" numeric(20,7),
  "val_c26" numeric(20,7),
  "val_c27" numeric(20,7),
  "val_c28" numeric(20,7),
  "val_c29" numeric(20,7),
  "val_c30" numeric(20,7),
  "val_c31" numeric(20,7),
  "val_c32" numeric(20,7),
  "val_c33" numeric(20,7),
  "val_c34" numeric(20,7),
  "val_c35" numeric(20,7),
  "val_c36" numeric(20,7),
  "val_c37" numeric(20,7),
  "val_c38" numeric(20,7),
  "val_c39" numeric(20,7),
  "val_c40" numeric(20,7),
  "val_c41" numeric(20,7),
  "val_c42" numeric(20,7),
  "val_c43" numeric(20,7),
  "val_c44" numeric(20,7),
  "val_c45" numeric(20,7),
  "val_c46" numeric(20,7),
  "val_c47" numeric(20,7),
  "val_c48" numeric(20,7),
  "val_c49" numeric(20,7),
  "val_c50" numeric(20,7),
  "val_c51" numeric(20,7),
  "val_c52" numeric(20,7),
  "val_c53" numeric(20,7),
  "val_n1" numeric(20,7),
  "val_n2" numeric(20,7),
  "val_n3" numeric(20,7),
  "val_n4" numeric(20,7),
  "val_n5" numeric(20,7),
  "val_n6" numeric(20,7),
  "val_n7" numeric(20,7),
  "val_n8" numeric(20,7),
  "val_n9" numeric(20,7),
  "val_n10" numeric(20,7),
  "val_n11" numeric(20,7),
  "val_n12" numeric(20,7),
  "val_n13" numeric(20,7),
  "val_n14" numeric(20,7),
  "val_n15" numeric(20,7),
  "val_n16" numeric(20,7),
  "val_n17" numeric(20,7),
  "val_n18" numeric(20,7),
  "val_n19" numeric(20,7),
  "val_n20" numeric(20,7),
  "val_n21" numeric(20,7),
  "val_n22" numeric(20,7),
  "val_n23" numeric(20,7),
  "val_n24" numeric(20,7),
  "val_n25" numeric(20,7),
  "val_n26" numeric(20,7),
  "val_n27" numeric(20,7),
  "val_n28" numeric(20,7),
  "val_n29" numeric(20,7),
  "val_n30" numeric(20,7),
  "val_n31" numeric(20,7),
  "val_n32" numeric(20,7),
  "val_n33" numeric(20,7),
  "val_n34" numeric(20,7),
  "val_n35" numeric(20,7),
  "val_n36" numeric(20,7),
  "val_n37" numeric(20,7),
  "val_n38" numeric(20,7),
  "val_n39" numeric(20,7),
  "val_n40" numeric(20,7),
  "val_n41" numeric(20,7),
  "val_n42" numeric(20,7),
  "val_n43" numeric(20,7),
  "val_n44" numeric(20,7),
  "val_n45" numeric(20,7),
  "val_n46" numeric(20,7),
  "val_n47" numeric(20,7),
  "val_n48" numeric(20,7),
  "val_n49" numeric(20,7),
  "val_n50" numeric(20,7),
  "val_n51" numeric(20,7),
  "val_n52" numeric(20,7),
  "val_n53" numeric(20,7),
  "depasire" numeric(20,7),
  "val_t1" numeric(20,7),
  "val_t2" numeric(20,7),
  "val_t3" numeric(20,7),
  "val_t4" numeric(20,7),
  "val_t5" numeric(20,7),
  "val_t6" numeric(20,7),
  "val_t7" numeric(20,7),
  "val_t8" numeric(20,7),
  "val_t9" numeric(20,7),
  "val_t10" numeric(20,7),
  "val_t11" numeric(20,7),
  "val_t12" numeric(20,7),
  "val_t13" numeric(20,7),
  "val_t14" numeric(20,7),
  "val_t15" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>estimariprod1m</obj_name>
  <obj_hashval>e5081228e1c42c1ba6322267c25b6fc7</obj_hashval>
  <obj_text>CREATE TABLE estimariprod1m (
  "codestimareprod1m" numeric(20,0) NOT NULL,
  "codestimareprod" numeric(20,0),
  "codobiect" numeric(20,0),
  "c1" numeric(20,7),
  "c2" numeric(20,7),
  "c3" numeric(20,7),
  "c4" numeric(20,7),
  "c5" numeric(20,7),
  "c6" numeric(20,7),
  "c7" numeric(20,7),
  "c8" numeric(20,7),
  "c9" numeric(20,7),
  "c10" numeric(20,7),
  "c11" numeric(20,7),
  "c12" numeric(20,7),
  "c13" numeric(20,7),
  "c14" numeric(20,7),
  "c15" numeric(20,7),
  "c16" numeric(20,7),
  "c17" numeric(20,7),
  "c18" numeric(20,7),
  "c19" numeric(20,7),
  "c20" numeric(20,7),
  "c21" numeric(20,7),
  "c22" numeric(20,7),
  "c23" numeric(20,7),
  "c24" numeric(20,7),
  "c25" numeric(20,7),
  "c26" numeric(20,7),
  "c27" numeric(20,7),
  "c28" numeric(20,7),
  "c29" numeric(20,7),
  "c30" numeric(20,7),
  "c31" numeric(20,7),
  "c32" numeric(20,7),
  "c33" numeric(20,7),
  "c34" numeric(20,7),
  "c35" numeric(20,7),
  "c36" numeric(20,7),
  "c37" numeric(20,7),
  "c38" numeric(20,7),
  "c39" numeric(20,7),
  "c40" numeric(20,7),
  "c41" numeric(20,7),
  "c42" numeric(20,7),
  "c43" numeric(20,7),
  "c44" numeric(20,7),
  "c45" numeric(20,7),
  "c46" numeric(20,7),
  "c47" numeric(20,7),
  "c48" numeric(20,7),
  "c49" numeric(20,7),
  "c50" numeric(20,7),
  "c51" numeric(20,7),
  "c52" numeric(20,7),
  "n1" numeric(20,7),
  "n2" numeric(20,7),
  "n3" numeric(20,7),
  "n4" numeric(20,7),
  "n5" numeric(20,7),
  "n6" numeric(20,7),
  "n7" numeric(20,7),
  "n8" numeric(20,7),
  "n9" numeric(20,7),
  "n10" numeric(20,7),
  "n11" numeric(20,7),
  "n12" numeric(20,7),
  "n13" numeric(20,7),
  "n14" numeric(20,7),
  "n15" numeric(20,7),
  "n16" numeric(20,7),
  "n17" numeric(20,7),
  "n18" numeric(20,7),
  "n19" numeric(20,7),
  "n20" numeric(20,7),
  "n21" numeric(20,7),
  "n22" numeric(20,7),
  "n23" numeric(20,7),
  "n24" numeric(20,7),
  "n25" numeric(20,7),
  "n26" numeric(20,7),
  "n27" numeric(20,7),
  "n28" numeric(20,7),
  "n29" numeric(20,7),
  "n30" numeric(20,7),
  "n31" numeric(20,7),
  "n32" numeric(20,7),
  "n33" numeric(20,7),
  "n34" numeric(20,7),
  "n35" numeric(20,7),
  "n36" numeric(20,7),
  "n37" numeric(20,7),
  "n38" numeric(20,7),
  "n39" numeric(20,7),
  "n40" numeric(20,7),
  "n41" numeric(20,7),
  "n42" numeric(20,7),
  "n43" numeric(20,7),
  "n44" numeric(20,7),
  "n45" numeric(20,7),
  "n46" numeric(20,7),
  "n47" numeric(20,7),
  "n48" numeric(20,7),
  "n49" numeric(20,7),
  "n50" numeric(20,7),
  "n51" numeric(20,7),
  "n52" numeric(20,7),
  "c53" numeric(20,7),
  "n53" numeric(20,7),
  "nec_c1" numeric(20,7),
  "nec_c2" numeric(20,7),
  "nec_c3" numeric(20,7),
  "nec_c4" numeric(20,7),
  "nec_c5" numeric(20,7),
  "nec_c6" numeric(20,7),
  "nec_c7" numeric(20,7),
  "nec_c8" numeric(20,7),
  "nec_c9" numeric(20,7),
  "nec_c10" numeric(20,7),
  "nec_c11" numeric(20,7),
  "nec_c12" numeric(20,7),
  "nec_c13" numeric(20,7),
  "nec_c14" numeric(20,7),
  "nec_c15" numeric(20,7),
  "nec_c16" numeric(20,7),
  "nec_c17" numeric(20,7),
  "nec_c18" numeric(20,7),
  "nec_c19" numeric(20,7),
  "nec_c20" numeric(20,7),
  "nec_c21" numeric(20,7),
  "nec_c22" numeric(20,7),
  "nec_c23" numeric(20,7),
  "nec_c24" numeric(20,7),
  "nec_c25" numeric(20,7),
  "nec_c26" numeric(20,7),
  "nec_c27" numeric(20,7),
  "nec_c28" numeric(20,7),
  "nec_c29" numeric(20,7),
  "nec_c30" numeric(20,7),
  "nec_c31" numeric(20,7),
  "nec_c32" numeric(20,7),
  "nec_c33" numeric(20,7),
  "nec_c34" numeric(20,7),
  "nec_c35" numeric(20,7),
  "nec_c36" numeric(20,7),
  "nec_c37" numeric(20,7),
  "nec_c38" numeric(20,7),
  "nec_c39" numeric(20,7),
  "nec_c40" numeric(20,7),
  "nec_c41" numeric(20,7),
  "nec_c42" numeric(20,7),
  "nec_c43" numeric(20,7),
  "nec_c44" numeric(20,7),
  "nec_c45" numeric(20,7),
  "nec_c46" numeric(20,7),
  "nec_c47" numeric(20,7),
  "nec_c48" numeric(20,7),
  "nec_c49" numeric(20,7),
  "nec_c50" numeric(20,7),
  "nec_c51" numeric(20,7),
  "nec_c52" numeric(20,7),
  "nec_n1" numeric(20,7),
  "nec_n2" numeric(20,7),
  "nec_n3" numeric(20,7),
  "nec_n4" numeric(20,7),
  "nec_n5" numeric(20,7),
  "nec_n6" numeric(20,7),
  "nec_n7" numeric(20,7),
  "nec_n8" numeric(20,7),
  "nec_n9" numeric(20,7),
  "nec_n10" numeric(20,7),
  "nec_n11" numeric(20,7),
  "nec_n12" numeric(20,7),
  "nec_n13" numeric(20,7),
  "nec_n14" numeric(20,7),
  "nec_n15" numeric(20,7),
  "nec_n16" numeric(20,7),
  "nec_n17" numeric(20,7),
  "nec_n18" numeric(20,7),
  "nec_n19" numeric(20,7),
  "nec_n20" numeric(20,7),
  "nec_n21" numeric(20,7),
  "nec_n22" numeric(20,7),
  "nec_n23" numeric(20,7),
  "nec_n24" numeric(20,7),
  "nec_n25" numeric(20,7),
  "nec_n26" numeric(20,7),
  "nec_n27" numeric(20,7),
  "nec_n28" numeric(20,7),
  "nec_n29" numeric(20,7),
  "nec_n30" numeric(20,7),
  "nec_n31" numeric(20,7),
  "nec_n32" numeric(20,7),
  "nec_n33" numeric(20,7),
  "nec_n34" numeric(20,7),
  "nec_n35" numeric(20,7),
  "nec_n36" numeric(20,7),
  "nec_n37" numeric(20,7),
  "nec_n38" numeric(20,7),
  "nec_n39" numeric(20,7),
  "nec_n40" numeric(20,7),
  "nec_n41" numeric(20,7),
  "nec_n42" numeric(20,7),
  "nec_n43" numeric(20,7),
  "nec_n44" numeric(20,7),
  "nec_n45" numeric(20,7),
  "nec_n46" numeric(20,7),
  "nec_n47" numeric(20,7),
  "nec_n48" numeric(20,7),
  "nec_n49" numeric(20,7),
  "nec_n50" numeric(20,7),
  "nec_n51" numeric(20,7),
  "nec_n52" numeric(20,7),
  "nec_c53" numeric(20,7),
  "nec_n53" numeric(20,7),
  "cf_c1" numeric(20,7),
  "cf_c2" numeric(20,7),
  "cf_c3" numeric(20,7),
  "cf_c4" numeric(20,7),
  "cf_c5" numeric(20,7),
  "cf_c6" numeric(20,7),
  "cf_c7" numeric(20,7),
  "cf_c8" numeric(20,7),
  "cf_c9" numeric(20,7),
  "cf_c10" numeric(20,7),
  "cf_c11" numeric(20,7),
  "cf_c12" numeric(20,7),
  "cf_c13" numeric(20,7),
  "cf_c14" numeric(20,7),
  "cf_c15" numeric(20,7),
  "cf_c16" numeric(20,7),
  "cf_c17" numeric(20,7),
  "cf_c18" numeric(20,7),
  "cf_c19" numeric(20,7),
  "cf_c20" numeric(20,7),
  "cf_c21" numeric(20,7),
  "cf_c22" numeric(20,7),
  "cf_c23" numeric(20,7),
  "cf_c24" numeric(20,7),
  "cf_c25" numeric(20,7),
  "cf_c26" numeric(20,7),
  "cf_c27" numeric(20,7),
  "cf_c28" numeric(20,7),
  "cf_c29" numeric(20,7),
  "cf_c30" numeric(20,7),
  "cf_c31" numeric(20,7),
  "cf_c32" numeric(20,7),
  "cf_c33" numeric(20,7),
  "cf_c34" numeric(20,7),
  "cf_c35" numeric(20,7),
  "cf_c36" numeric(20,7),
  "cf_c37" numeric(20,7),
  "cf_c38" numeric(20,7),
  "cf_c39" numeric(20,7),
  "cf_c40" numeric(20,7),
  "cf_c41" numeric(20,7),
  "cf_c42" numeric(20,7),
  "cf_c43" numeric(20,7),
  "cf_c44" numeric(20,7),
  "cf_c45" numeric(20,7),
  "cf_c46" numeric(20,7),
  "cf_c47" numeric(20,7),
  "cf_c48" numeric(20,7),
  "cf_c49" numeric(20,7),
  "cf_c50" numeric(20,7),
  "cf_c51" numeric(20,7),
  "cf_c52" numeric(20,7),
  "cf_c53" numeric(20,7),
  "cf_n1" numeric(20,7),
  "cf_n2" numeric(20,7),
  "cf_n3" numeric(20,7),
  "cf_n4" numeric(20,7),
  "cf_n5" numeric(20,7),
  "cf_n6" numeric(20,7),
  "cf_n7" numeric(20,7),
  "cf_n8" numeric(20,7),
  "cf_n9" numeric(20,7),
  "cf_n10" numeric(20,7),
  "cf_n11" numeric(20,7),
  "cf_n12" numeric(20,7),
  "cf_n13" numeric(20,7),
  "cf_n14" numeric(20,7),
  "cf_n15" numeric(20,7),
  "cf_n16" numeric(20,7),
  "cf_n17" numeric(20,7),
  "cf_n18" numeric(20,7),
  "cf_n19" numeric(20,7),
  "cf_n20" numeric(20,7),
  "cf_n21" numeric(20,7),
  "cf_n22" numeric(20,7),
  "cf_n23" numeric(20,7),
  "cf_n24" numeric(20,7),
  "cf_n25" numeric(20,7),
  "cf_n26" numeric(20,7),
  "cf_n27" numeric(20,7),
  "cf_n28" numeric(20,7),
  "cf_n29" numeric(20,7),
  "cf_n30" numeric(20,7),
  "cf_n31" numeric(20,7),
  "cf_n32" numeric(20,7),
  "cf_n33" numeric(20,7),
  "cf_n34" numeric(20,7),
  "cf_n35" numeric(20,7),
  "cf_n36" numeric(20,7),
  "cf_n37" numeric(20,7),
  "cf_n38" numeric(20,7),
  "cf_n39" numeric(20,7),
  "cf_n40" numeric(20,7),
  "cf_n41" numeric(20,7),
  "cf_n42" numeric(20,7),
  "cf_n43" numeric(20,7),
  "cf_n44" numeric(20,7),
  "cf_n45" numeric(20,7),
  "cf_n46" numeric(20,7),
  "cf_n47" numeric(20,7),
  "cf_n48" numeric(20,7),
  "cf_n49" numeric(20,7),
  "cf_n50" numeric(20,7),
  "cf_n51" numeric(20,7),
  "cf_n52" numeric(20,7),
  "cf_n53" numeric(20,7),
  "stoc" numeric(20,7),
  "stocoptim" numeric(20,7),
  "coefum" numeric(20,7),
  "pret" numeric(20,7),
  "scadenta" numeric(5,0),
  "val_c1" numeric(20,7),
  "val_c2" numeric(20,7),
  "val_c3" numeric(20,7),
  "val_c4" numeric(20,7),
  "val_c5" numeric(20,7),
  "val_c6" numeric(20,7),
  "val_c7" numeric(20,7),
  "val_c8" numeric(20,7),
  "val_c9" numeric(20,7),
  "val_c10" numeric(20,7),
  "val_c11" numeric(20,7),
  "val_c12" numeric(20,7),
  "val_c13" numeric(20,7),
  "val_c14" numeric(20,7),
  "val_c15" numeric(20,7),
  "val_c16" numeric(20,7),
  "val_c17" numeric(20,7),
  "val_c18" numeric(20,7),
  "val_c19" numeric(20,7),
  "val_c20" numeric(20,7),
  "val_c21" numeric(20,7),
  "val_c22" numeric(20,7),
  "val_c23" numeric(20,7),
  "val_c24" numeric(20,7),
  "val_c25" numeric(20,7),
  "val_c26" numeric(20,7),
  "val_c27" numeric(20,7),
  "val_c28" numeric(20,7),
  "val_c29" numeric(20,7),
  "val_c30" numeric(20,7),
  "val_c31" numeric(20,7),
  "val_c32" numeric(20,7),
  "val_c33" numeric(20,7),
  "val_c34" numeric(20,7),
  "val_c35" numeric(20,7),
  "val_c36" numeric(20,7),
  "val_c37" numeric(20,7),
  "val_c38" numeric(20,7),
  "val_c39" numeric(20,7),
  "val_c40" numeric(20,7),
  "val_c41" numeric(20,7),
  "val_c42" numeric(20,7),
  "val_c43" numeric(20,7),
  "val_c44" numeric(20,7),
  "val_c45" numeric(20,7),
  "val_c46" numeric(20,7),
  "val_c47" numeric(20,7),
  "val_c48" numeric(20,7),
  "val_c49" numeric(20,7),
  "val_c50" numeric(20,7),
  "val_c51" numeric(20,7),
  "val_c52" numeric(20,7),
  "val_c53" numeric(20,7),
  "val_n1" numeric(20,7),
  "val_n2" numeric(20,7),
  "val_n3" numeric(20,7),
  "val_n4" numeric(20,7),
  "val_n5" numeric(20,7),
  "val_n6" numeric(20,7),
  "val_n7" numeric(20,7),
  "val_n8" numeric(20,7),
  "val_n9" numeric(20,7),
  "val_n10" numeric(20,7),
  "val_n11" numeric(20,7),
  "val_n12" numeric(20,7),
  "val_n13" numeric(20,7),
  "val_n14" numeric(20,7),
  "val_n15" numeric(20,7),
  "val_n16" numeric(20,7),
  "val_n17" numeric(20,7),
  "val_n18" numeric(20,7),
  "val_n19" numeric(20,7),
  "val_n20" numeric(20,7),
  "val_n21" numeric(20,7),
  "val_n22" numeric(20,7),
  "val_n23" numeric(20,7),
  "val_n24" numeric(20,7),
  "val_n25" numeric(20,7),
  "val_n26" numeric(20,7),
  "val_n27" numeric(20,7),
  "val_n28" numeric(20,7),
  "val_n29" numeric(20,7),
  "val_n30" numeric(20,7),
  "val_n31" numeric(20,7),
  "val_n32" numeric(20,7),
  "val_n33" numeric(20,7),
  "val_n34" numeric(20,7),
  "val_n35" numeric(20,7),
  "val_n36" numeric(20,7),
  "val_n37" numeric(20,7),
  "val_n38" numeric(20,7),
  "val_n39" numeric(20,7),
  "val_n40" numeric(20,7),
  "val_n41" numeric(20,7),
  "val_n42" numeric(20,7),
  "val_n43" numeric(20,7),
  "val_n44" numeric(20,7),
  "val_n45" numeric(20,7),
  "val_n46" numeric(20,7),
  "val_n47" numeric(20,7),
  "val_n48" numeric(20,7),
  "val_n49" numeric(20,7),
  "val_n50" numeric(20,7),
  "val_n51" numeric(20,7),
  "val_n52" numeric(20,7),
  "val_n53" numeric(20,7),
  "depasire" numeric(20,7),
  "val_t1" numeric(20,7),
  "val_t2" numeric(20,7),
  "val_t3" numeric(20,7),
  "val_t4" numeric(20,7),
  "val_t5" numeric(20,7),
  "val_t6" numeric(20,7),
  "val_t7" numeric(20,7),
  "val_t8" numeric(20,7),
  "val_t9" numeric(20,7),
  "val_t10" numeric(20,7),
  "val_t11" numeric(20,7),
  "val_t12" numeric(20,7),
  "val_t13" numeric(20,7),
  "val_t14" numeric(20,7),
  "val_t15" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>estimariprod1n</obj_name>
  <obj_hashval>ea61718313f3339d4188c6bd7d22786a</obj_hashval>
  <obj_text>CREATE TABLE estimariprod1n (
  "codestimareprod1n" numeric(20,0) NOT NULL,
  "codestimareprod" numeric(20,0),
  "codobiect" numeric(20,0),
  "nec_c1" numeric(20,7),
  "nec_c2" numeric(20,7),
  "nec_c3" numeric(20,7),
  "nec_c4" numeric(20,7),
  "nec_c5" numeric(20,7),
  "nec_c6" numeric(20,7),
  "nec_c7" numeric(20,7),
  "nec_c8" numeric(20,7),
  "nec_c9" numeric(20,7),
  "nec_c10" numeric(20,7),
  "nec_c11" numeric(20,7),
  "nec_c12" numeric(20,7),
  "nec_c13" numeric(20,7),
  "nec_c14" numeric(20,7),
  "nec_c15" numeric(20,7),
  "nec_c16" numeric(20,7),
  "nec_c17" numeric(20,7),
  "nec_c18" numeric(20,7),
  "nec_c19" numeric(20,7),
  "nec_c20" numeric(20,7),
  "nec_c21" numeric(20,7),
  "nec_c22" numeric(20,7),
  "nec_c23" numeric(20,7),
  "nec_c24" numeric(20,7),
  "nec_c25" numeric(20,7),
  "nec_c26" numeric(20,7),
  "nec_c27" numeric(20,7),
  "nec_c28" numeric(20,7),
  "nec_c29" numeric(20,7),
  "nec_c30" numeric(20,7),
  "nec_c31" numeric(20,7),
  "nec_c32" numeric(20,7),
  "nec_c33" numeric(20,7),
  "nec_c34" numeric(20,7),
  "nec_c35" numeric(20,7),
  "nec_c36" numeric(20,7),
  "nec_c37" numeric(20,7),
  "nec_c38" numeric(20,7),
  "nec_c39" numeric(20,7),
  "nec_c40" numeric(20,7),
  "nec_c41" numeric(20,7),
  "nec_c42" numeric(20,7),
  "nec_c43" numeric(20,7),
  "nec_c44" numeric(20,7),
  "nec_c45" numeric(20,7),
  "nec_c46" numeric(20,7),
  "nec_c47" numeric(20,7),
  "nec_c48" numeric(20,7),
  "nec_c49" numeric(20,7),
  "nec_c50" numeric(20,7),
  "nec_c51" numeric(20,7),
  "nec_c52" numeric(20,7),
  "nec_n1" numeric(20,7),
  "nec_n2" numeric(20,7),
  "nec_n3" numeric(20,7),
  "nec_n4" numeric(20,7),
  "nec_n5" numeric(20,7),
  "nec_n6" numeric(20,7),
  "nec_n7" numeric(20,7),
  "nec_n8" numeric(20,7),
  "nec_n9" numeric(20,7),
  "nec_n10" numeric(20,7),
  "nec_n11" numeric(20,7),
  "nec_n12" numeric(20,7),
  "nec_n13" numeric(20,7),
  "nec_n14" numeric(20,7),
  "nec_n15" numeric(20,7),
  "nec_n16" numeric(20,7),
  "nec_n17" numeric(20,7),
  "nec_n18" numeric(20,7),
  "nec_n19" numeric(20,7),
  "nec_n20" numeric(20,7),
  "nec_n21" numeric(20,7),
  "nec_n22" numeric(20,7),
  "nec_n23" numeric(20,7),
  "nec_n24" numeric(20,7),
  "nec_n25" numeric(20,7),
  "nec_n26" numeric(20,7),
  "nec_n27" numeric(20,7),
  "nec_n28" numeric(20,7),
  "nec_n29" numeric(20,7),
  "nec_n30" numeric(20,7),
  "nec_n31" numeric(20,7),
  "nec_n32" numeric(20,7),
  "nec_n33" numeric(20,7),
  "nec_n34" numeric(20,7),
  "nec_n35" numeric(20,7),
  "nec_n36" numeric(20,7),
  "nec_n37" numeric(20,7),
  "nec_n38" numeric(20,7),
  "nec_n39" numeric(20,7),
  "nec_n40" numeric(20,7),
  "nec_n41" numeric(20,7),
  "nec_n42" numeric(20,7),
  "nec_n43" numeric(20,7),
  "nec_n44" numeric(20,7),
  "nec_n45" numeric(20,7),
  "nec_n46" numeric(20,7),
  "nec_n47" numeric(20,7),
  "nec_n48" numeric(20,7),
  "nec_n49" numeric(20,7),
  "nec_n50" numeric(20,7),
  "nec_n51" numeric(20,7),
  "nec_n52" numeric(20,7),
  "nec_c53" numeric(20,7),
  "nec_n53" numeric(20,7),
  "stoc" numeric(20,7),
  "stocoptim" numeric(20,7),
  "coefum" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>etva</obj_name>
  <obj_hashval>5dd0705fa02ddbaa61b04e32db7b1e65</obj_hashval>
  <obj_text>CREATE TABLE etva (
  "codetva" numeric(20,0) NOT NULL,
  "cif" character varying(75),
  "an" numeric(20,0),
  "luna" numeric(20,0),
  "data_incarcare" date,
  "denumire" character varying(200),
  "id" character varying(50),
  "consolidat" character varying(50),
  "data_spv" date,
  "id_spv" character varying(50),
  "domiciliu" character varying(150),
  "subunitatea" numeric(20,0),
  "rd1_1_val_etrans" numeric(20,7),
  "rd1_val" numeric(20,7),
  "rd1_val_390" numeric(20,7),
  "rd10_tva" numeric(20,7),
  "rd10_tva_394" numeric(20,7),
  "rd10_tva_amef" numeric(20,7),
  "rd10_tva_efct" numeric(20,7),
  "rd10_val" numeric(20,7),
  "rd10_val_394" numeric(20,7),
  "rd10_val_amef" numeric(20,7),
  "rd10_val_efct" numeric(20,7),
  "rd101_tva_regac" numeric(20,7),
  "rd101_val_regac" numeric(20,7),
  "rd11_tva" numeric(20,7),
  "rd11_tva_394" numeric(20,7),
  "rd11_tva_amef" numeric(20,7),
  "rd11_tva_efct" numeric(20,7),
  "rd11_val" numeric(20,7),
  "rd11_val_394" numeric(20,7),
  "rd11_val_amef" numeric(20,7),
  "rd11_val_efct" numeric(20,7),
  "rd111_tva_regac" numeric(20,7),
  "rd111_val_regac" numeric(20,7),
  "rd12_tva" numeric(20,7),
  "rd12_tva_394" numeric(20,7),
  "rd12_tva_efct" numeric(20,7),
  "rd12_val" numeric(20,7),
  "rd12_val_394" numeric(20,7),
  "rd12_val_efct" numeric(20,7),
  "rd121_tva" numeric(20,7),
  "rd121_tva_394" numeric(20,7),
  "rd121_val" numeric(20,7),
  "rd121_val_394" numeric(20,7),
  "rd122_tva" numeric(20,7),
  "rd122_tva_394" numeric(20,7),
  "rd122_val" numeric(20,7),
  "rd122_val_394" numeric(20,7),
  "rd123_tva" numeric(20,7),
  "rd123_tva_394" numeric(20,7),
  "rd123_val" numeric(20,7),
  "rd123_val_394" numeric(20,7),
  "rd13_val" numeric(20,7),
  "rd13_val_efct" numeric(20,7),
  "rd14_15_val" numeric(20,7),
  "rd14_15_val_amef" numeric(20,7),
  "rd14_15_val_efct" numeric(20,7),
  "rd14_15_val_vama" numeric(20,7),
  "rd2_val" numeric(20,7),
  "rd2_val_390" numeric(20,7),
  "rd20_tva" numeric(20,7),
  "rd20_val" numeric(20,7),
  "rd201_tva" numeric(20,7),
  "rd201_val" numeric(20,7),
  "rd21_tva" numeric(20,7),
  "rd21_val" numeric(20,7),
  "rd22_tva" numeric(20,7),
  "rd22_val" numeric(20,7),
  "rd221_tva" numeric(20,7),
  "rd221_val" numeric(20,7),
  "rd23_tva" numeric(20,7),
  "rd23_val" numeric(20,7),
  "rd24_tva" numeric(20,7),
  "rd24_tva_394" numeric(20,7),
  "rd24_tva_efct_i" numeric(20,7),
  "rd24_tva_efct_n" numeric(20,7),
  "rd24_tva_efct_t" numeric(20,7),
  "rd24_tva_vama" numeric(20,7),
  "rd24_val" numeric(20,7),
  "rd24_val_394" numeric(20,7),
  "rd24_val_efct_i" numeric(20,7),
  "rd24_val_efct_n" numeric(20,7),
  "rd24_val_efct_t" numeric(20,7),
  "rd24_val_vama" numeric(20,7),
  "rd25_tva" numeric(20,7),
  "rd25_tva_394" numeric(20,7),
  "rd25_tva_efct_i" numeric(20,7),
  "rd25_tva_efct_n" numeric(20,7),
  "rd25_tva_efct_t" numeric(20,7),
  "rd25_tva_vama" numeric(20,7),
  "rd25_val" numeric(20,7),
  "rd25_val_394" numeric(20,7),
  "rd25_val_efct_i" numeric(20,7),
  "rd25_val_efct_n" numeric(20,7),
  "rd25_val_efct_t" numeric(20,7),
  "rd25_val_vama" numeric(20,7),
  "rd26_tva" numeric(20,7),
  "rd26_tva_394" numeric(20,7),
  "rd26_tva_efct_i" numeric(20,7),
  "rd26_tva_efct_n" numeric(20,7),
  "rd26_tva_efct_t" numeric(20,7),
  "rd26_tva_vama" numeric(20,7),
  "rd26_val" numeric(20,7),
  "rd26_val_394" numeric(20,7),
  "rd26_val_efct_i" numeric(20,7),
  "rd26_val_efct_n" numeric(20,7),
  "rd26_val_efct_t" numeric(20,7),
  "rd26_val_vama" numeric(20,7),
  "rd27_tva" numeric(20,7),
  "rd27_val" numeric(20,7),
  "rd271_tva" numeric(20,7),
  "rd271_val" numeric(20,7),
  "rd272_tva" numeric(20,7),
  "rd272_val" numeric(20,7),
  "rd273_tva" numeric(20,7),
  "rd273_val" numeric(20,7),
  "rd28_tva" numeric(20,7),
  "rd28_tva_efct" numeric(20,7),
  "rd3_val" numeric(20,7),
  "rd3_val_390" numeric(20,7),
  "rd30_val" numeric(20,7),
  "rd30_val_efct" numeric(20,7),
  "rd30_val_vama" numeric(20,7),
  "rd31_val" numeric(20,7),
  "rd31_val_390" numeric(20,7),
  "rd4_val" numeric(20,7),
  "rd4_val_390" numeric(20,7),
  "rd5_tva" numeric(20,7),
  "rd5_tva_390" numeric(20,7),
  "rd5_val" numeric(20,7),
  "rd5_val_390" numeric(20,7),
  "rd51_tva" numeric(20,7),
  "rd51_tva_390" numeric(20,7),
  "rd51_val" numeric(20,7),
  "rd51_val_390" numeric(20,7),
  "rd52_tva_etrans" numeric(20,7),
  "rd52_val_etrans" numeric(20,7),
  "rd6_tva" numeric(20,7),
  "rd6_tva_390" numeric(20,7),
  "rd6_val" numeric(20,7),
  "rd6_val_390" numeric(20,7),
  "rd7_tva" numeric(20,7),
  "rd7_tva_390" numeric(20,7),
  "rd7_tva_vama" numeric(20,7),
  "rd7_val" numeric(20,7),
  "rd7_val_390" numeric(20,7),
  "rd7_val_vama" numeric(20,7),
  "rd71_tva" numeric(20,7),
  "rd71_tva_390" numeric(20,7),
  "rd71_val" numeric(20,7),
  "rd71_val_390" numeric(20,7),
  "rd8_tva" numeric(20,7),
  "rd8_tva_390" numeric(20,7),
  "rd8_val" numeric(20,7),
  "rd8_val_390" numeric(20,7),
  "rd9_tva" numeric(20,7),
  "rd9_tva_394" numeric(20,7),
  "rd9_tva_amef" numeric(20,7),
  "rd9_tva_efct" numeric(20,7),
  "rd9_val" numeric(20,7),
  "rd9_val_394" numeric(20,7),
  "rd9_val_amef" numeric(20,7),
  "rd9_val_efct" numeric(20,7),
  "rd9_1_tva" numeric(20,7),
  "rd9_1_tva_394" numeric(20,7),
  "rd9_1_tva_amef" numeric(20,7),
  "rd9_1_tva_efct" numeric(20,7),
  "rd9_1_val" numeric(20,7),
  "rd9_1_val_394" numeric(20,7),
  "rd9_1_val_amef" numeric(20,7),
  "rd9_1_val_efct" numeric(20,7),
  "rd11_1_tva" numeric(20,7),
  "rd11_1_tva_394" numeric(20,7),
  "rd11_1_tva_amef" numeric(20,7),
  "rd11_1_tva_efct" numeric(20,7),
  "rd11_1_val" numeric(20,7),
  "rd11_1_val_394" numeric(20,7),
  "rd11_1_val_amef" numeric(20,7),
  "rd11_1_val_efct" numeric(20,7),
  "rd111_1_tva_regac" numeric(20,7),
  "rd111_1_val_regac" numeric(20,7),
  "rd124_tva" numeric(20,7),
  "rd124_tva_394" numeric(20,7),
  "rd124_val" numeric(20,7),
  "rd124_val_394" numeric(20,7),
  "rd125_tva" numeric(20,7),
  "rd125_tva_394" numeric(20,7),
  "rd125_val" numeric(20,7),
  "rd125_val_394" numeric(20,7),
  "rd24_1_tva" numeric(20,7),
  "rd24_1_tva_394" numeric(20,7),
  "rd24_1_tva_efct_i" numeric(20,7),
  "rd24_1_tva_efct_n" numeric(20,7),
  "rd24_1_tva_efct_t" numeric(20,7),
  "rd24_1_tva_vama" numeric(20,7),
  "rd24_1_val" numeric(20,7),
  "rd24_1_val_394" numeric(20,7),
  "rd24_1_val_efct_i" numeric(20,7),
  "rd24_1_val_efct_n" numeric(20,7),
  "rd24_1_val_efct_t" numeric(20,7),
  "rd24_1_val_vama" numeric(20,7),
  "rd25_1_tva" numeric(20,7),
  "rd25_1_tva_394" numeric(20,7),
  "rd25_1_tva_efct_i" numeric(20,7),
  "rd25_1_tva_efct_n" numeric(20,7),
  "rd25_1_tva_efct_t" numeric(20,7),
  "rd25_1_tva_vama" numeric(20,7),
  "rd25_1_val" numeric(20,7),
  "rd25_1_val_394" numeric(20,7),
  "rd25_1_val_efct_i" numeric(20,7),
  "rd25_1_val_efct_n" numeric(20,7),
  "rd25_1_val_efct_t" numeric(20,7),
  "rd25_1_val_vama" numeric(20,7),
  "rd274_tva" numeric(20,7),
  "rd274_val" numeric(20,7),
  "rd275_tva" numeric(20,7),
  "rd275_val" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>etva_390_394</obj_name>
  <obj_hashval>a2437e723edf94b71aa21bc94bed8c3b</obj_hashval>
  <obj_text>CREATE TABLE etva_390_394 (
  "codetva_390_394" numeric(20,0) NOT NULL,
  "codetva" numeric(20,0),
  "tip" character varying(10),
  "numar_inregistrare" character varying(75),
  "data_inregistrare" date,
  "an" numeric(20,0),
  "luna" numeric(20,0),
  "tip_duk" character varying(20)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>etva_amef</obj_name>
  <obj_hashval>82760fe379f61ef987842fb7b763b227</obj_hashval>
  <obj_text>CREATE TABLE etva_amef (
  "codetva_amef" numeric(20,0) NOT NULL,
  "codetva" numeric(20,0),
  "data_z" date,
  "nui" character varying(20),
  "nr_z" character varying(20),
  "valoare_19" numeric(20,7),
  "tva_19" numeric(20,7),
  "valoare_9" numeric(20,7),
  "tva_9" numeric(20,7),
  "valoare_5" numeric(20,7),
  "tva_5" numeric(20,7),
  "valoare_0" numeric(20,7),
  "tva_0" numeric(20,7),
  "valoare_21" numeric(20,7),
  "tva_21" numeric(20,7),
  "valoare_11" numeric(20,7),
  "tva_11" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>etva_etransport</obj_name>
  <obj_hashval>25b99f987a4867261d23a32675409d36</obj_hashval>
  <obj_text>CREATE TABLE etva_etransport (
  "codetva_etransport" numeric(20,0) NOT NULL,
  "codetva" numeric(20,0),
  "denumire" character varying(100),
  "domiciliu" character varying(150),
  "numar_trn" character varying(20),
  "pc_cod" character varying(75),
  "pc_denumire" character varying(100),
  "pc_cod_tara" character varying(5),
  "tip" character varying(100),
  "scop" character varying(100),
  "valoare" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>etva_factura</obj_name>
  <obj_hashval>b1557be88363262f6fb29d4384856711</obj_hashval>
  <obj_text>CREATE TABLE etva_factura (
  "codetva_factura" numeric(20,0) NOT NULL,
  "codetva" numeric(20,0),
  "data_selectie" date,
  "data_inceput" date,
  "den_cumparator" character varying(200),
  "nr_factura" character varying(50),
  "tip_factura" numeric(20,0),
  "cump_cui" character varying(75),
  "data_sfarsit" date,
  "tip" character varying(10),
  "data_emitere" date,
  "vanz_cui" character varying(75),
  "den_vanzator" character varying(200),
  "an" numeric(20,0),
  "luna" numeric(20,0),
  "id" character varying(20),
  "cif" character varying(75),
  "data_inregistrare" date,
  "data_livrare" date,
  "data_scadenta" date,
  "cod_data_exigibila" numeric(3,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>etva_factura_tva</obj_name>
  <obj_hashval>8715fc9003699616d6b8666425f78724</obj_hashval>
  <obj_text>CREATE TABLE etva_factura_tva (
  "codetva_factura_tva" numeric(20,0) NOT NULL,
  "codetva_factura" numeric(20,0),
  "codetva" numeric(20,0),
  "baza_lei" numeric(20,7),
  "baza_calcul" numeric(20,7),
  "cota_tva" numeric(20,7),
  "categ_tva" character varying(20),
  "tva_lei" numeric(20,7),
  "curs" numeric(20,7),
  "tva" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>etva_locuinte</obj_name>
  <obj_hashval>5285669c0979bc6bf1582c428141e057</obj_hashval>
  <obj_text>CREATE TABLE etva_locuinte (
  "codetva_locuinte" numeric(20,0) NOT NULL,
  "codetva" numeric(20,0),
  "denumire" character varying(200),
  "domiciliu" character varying(200),
  "data_inregistrare" date,
  "numar_incheiere_autentif" character varying(50),
  "data_incheiere_autentif" date,
  "valoare_locuinta" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>etva_vama_import</obj_name>
  <obj_hashval>5081622a8309ab3910b26e048a12dfda</obj_hashval>
  <obj_text>CREATE TABLE etva_vama_import (
  "codetva_vama_import" numeric(20,0) NOT NULL,
  "codetva" numeric(20,0),
  "nr_mrn" character varying(100),
  "data_mrn" date,
  "articol" character varying(100),
  "val_impozabila" numeric(20,7),
  "cota_tva" numeric(2,0),
  "tva" numeric(20,7),
  "tip_plata" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>euro</obj_name>
  <obj_hashval>8fd70ac09032f602ec59b76121ee7459</obj_hashval>
  <obj_text>CREATE TABLE euro (
  "cod" numeric(20,0) NOT NULL,
  "codcasa" numeric(20,0),
  "plu" numeric(10,0),
  "dep" numeric(10,0),
  "tvacasa" numeric(10,0),
  "obiect" numeric(20,0),
  "gestiune" numeric(20,0),
  "cont" numeric(20,0),
  "tva" numeric(20,7),
  "pret" numeric(20,7),
  "stoc" numeric(20,7),
  "faractrl" numeric(1,0),
  "vandut" numeric(20,7),
  "barcod" character varying(30),
  "plulink" numeric(20,0),
  "descriptiv" numeric(1,0),
  "serviciu" numeric(1,0),
  "cantar" numeric(1,0),
  "sters" numeric(1,0),
  "selectat" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>evals</obj_name>
  <obj_hashval>9162f9c85aba4041a777572de170fc24</obj_hashval>
  <obj_text>CREATE TABLE evals (
  "codevals" numeric(20,0),
  "codidentevals" numeric(20,0),
  "den_evaluare" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>evalsev</obj_name>
  <obj_hashval>95d94bb60ecebcafb03fcc4f9a5b8619</obj_hashval>
  <obj_text>CREATE TABLE evalsev (
  "codevalsev" numeric(20,0),
  "codevals" numeric(20,0),
  "codevaluator" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>evalstes</obj_name>
  <obj_hashval>2259e828ee74c6388d7791f8a918a93e</obj_hashval>
  <obj_text>CREATE TABLE evalstes (
  "codevalstes" numeric(20,0),
  "codevals" numeric(20,0),
  "codtes" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>evaluari</obj_name>
  <obj_hashval>659ff10230ba9952c92511f130ca0349</obj_hashval>
  <obj_text>CREATE TABLE evaluari (
  "codevaluare" numeric(20,0),
  "codevaluator" numeric(20,0),
  "dataora" date,
  "rundaevaluare" numeric(20,0),
  "nrevaluatori" numeric(20,0),
  "nresantioane" numeric(20,0),
  "codtesatura" numeric(20,0),
  "coddestinatie" numeric(20,0),
  "numetesatura" character varying(200),
  "obs" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>evaluatori</obj_name>
  <obj_hashval>d766d639c084ab75c52870adfc093a75</obj_hashval>
  <obj_text>CREATE TABLE evaluatori (
  "codevaluator" numeric(20,0),
  "nume" character varying(200),
  "ordine" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>evidentamf</obj_name>
  <obj_hashval>700924fc1473a7ec65b289db0479bded</obj_hashval>
  <obj_text>CREATE TABLE evidentamf (
  "codmifix" numeric(20,0) NOT NULL,
  "codpart1" numeric(20,0),
  "codpart2" numeric(20,0),
  "codpart3" numeric(20,0),
  "datastart" date
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>evolutie</obj_name>
  <obj_hashval>9d67a5e3c6340752577892b924776f0e</obj_hashval>
  <obj_text>CREATE TABLE evolutie (
  "userid" numeric(20,0),
  "total" numeric(20,0),
  "curent" numeric(20,0),
  "actiune" character varying(100),
  "id" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>expcocacola</obj_name>
  <obj_hashval>b798fd7b5ae57b578cb5375f11aaf6f4</obj_hashval>
  <obj_text>CREATE TABLE expcocacola (
  "sto1" timestamp(6) without time zone,
  "sto2" timestamp(6) without time zone,
  "sto3" timestamp(6) without time zone,
  "others" timestamp(6) without time zone
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>expert</obj_name>
  <obj_hashval>fe8a5964aa62b854808e88b9bffb2bcb</obj_hashval>
  <obj_text>CREATE TABLE expert (
  "codexpert" numeric(20,0) NOT NULL,
  "coddoc" numeric(20,0),
  "tipdoc" numeric(20,0),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "subunitatea" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "dirty" numeric(1,0),
  "codanaliza" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>expert1</obj_name>
  <obj_hashval>4694cdcc5153323f7713960d9b226da0</obj_hashval>
  <obj_text>CREATE TABLE expert1 (
  "codexpert1" numeric(20,0) NOT NULL,
  "codexpert" numeric(20,0),
  "indexlocal" numeric(10,0),
  "indexjurn" numeric(20,0),
  "gestjurn" numeric(20,0),
  "subunitjurn" numeric(20,0),
  "contd" numeric(20,0),
  "contc" numeric(20,0),
  "valoare" numeric(20,7),
  "valoarev" numeric(20,7),
  "tipcont" numeric(1,0),
  "codelement" numeric(20,0),
  "coddescriptor1" numeric(20,0),
  "codanalizanod" numeric(20,0),
  "codanaliza" numeric(20,0),
  "codcentru" numeric(20,0),
  "analizanodjurn" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>exportwme</obj_name>
  <obj_hashval>2ab56db2498a12139add54cd95c11a40</obj_hashval>
  <obj_text>CREATE TABLE exportwme (
  "codexport" numeric(20,0),
  "tipdocument" character varying(20),
  "ancontabil" numeric(5,0),
  "lunacontabila" numeric(2,0),
  "dataora" timestamp(6) without time zone,
  "dateexport" text,
  "procesat" numeric(1,0),
  "importat" numeric(1,0),
  "erori" text,
  "subunitatea" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>factsalink</obj_name>
  <obj_hashval>32126e4ae2dea199b4200e5ee03c483e</obj_hashval>
  <obj_text>CREATE TABLE factsalink (
  "codies1" numeric(20,0) NOT NULL,
  "codcomanda" numeric(20,0),
  "codclasea" numeric(20,0),
  "valoare" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>faz</obj_name>
  <obj_hashval>a48fe0be7ed5a309bfc245b7afb68c78</obj_hashval>
  <obj_text>CREATE TABLE faz (
  "codfaz" numeric(20,0) NOT NULL,
  "carnetdoc" numeric(20,0),
  "seriadoc" character varying(20),
  "prefixdoc" character varying(5),
  "nrdoc" numeric(10,0),
  "datadoc" date,
  "operat" numeric(1,0),
  "blocat" numeric(1,0),
  "anulat" numeric(1,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "subunitatea" numeric(20,0),
  "codauto" numeric(20,0),
  "codpers" numeric(20,0),
  "diagrama" numeric(20,0),
  "alimpompa" numeric(20,7),
  "alimbcf" numeric(20,7),
  "alimavans" numeric(20,7),
  "kmplecare" numeric(10,0),
  "kmsosire" numeric(10,0),
  "kmn" numeric(10,0),
  "csarcina" numeric(20,7),
  "csarcinar" numeric(20,7),
  "cstart" numeric(20,7),
  "cimotor" numeric(20,7),
  "ccurse" numeric(20,7),
  "craer" numeric(20,7),
  "ciarna" numeric(20,7),
  "oreregie" numeric(20,7),
  "oreacord" numeric(20,7),
  "oren" numeric(20,7),
  "tones" numeric(20,7),
  "ores" numeric(20,7),
  "tstart" numeric(20,0),
  "timotor" numeric(20,0),
  "tcurse" numeric(20,0),
  "raer" numeric(1,0),
  "parcursn" numeric(1,0),
  "rezervorplecare" numeric(20,7),
  "codfazs" numeric(20,0),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "consum" numeric(20,7),
  "rezervorcalc" numeric(20,7),
  "rezervor" numeric(20,7),
  "obs" character varying(250),
  "tipparcurs" numeric(10,0),
  "codbc" numeric(20,0),
  "coddecont" numeric(20,0),
  "codauto1" numeric(20,0),
  "codauto2" numeric(20,0),
  "parcursr1" numeric(20,7),
  "parcursr2" numeric(20,7),
  "parcurs1" numeric(20,7),
  "parcurs2" numeric(20,7),
  "t1" numeric(20,7),
  "t2" numeric(20,7),
  "echiv1" numeric(20,7),
  "echiv2" numeric(20,7),
  "codgrauto" numeric(20,0),
  "parcursb" numeric(20,7),
  "parcursm" numeric(20,7),
  "parcurso" numeric(20,7),
  "b" numeric(20,7),
  "m" numeric(20,7),
  "o" numeric(20,7),
  "echivb" numeric(20,7),
  "echivm" numeric(20,7),
  "echivo" numeric(20,7),
  "tipaerodin" numeric(20,0),
  "nrrem" numeric(20,7),
  "parcursaero" numeric(20,7),
  "aerosr" numeric(20,7),
  "echivaero" numeric(20,7),
  "echivinst" numeric(20,7),
  "codintr" numeric(20,0),
  "codies" numeric(20,0),
  "codtrezor" numeric(20,0),
  "cmm" numeric(20,7),
  "consstat" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>faz0</obj_name>
  <obj_hashval>1bcbd0ea8c1f9546b43927a861b8fb52</obj_hashval>
  <obj_text>CREATE TABLE faz0 (
  "codfaz0" numeric(20,0) NOT NULL,
  "codfaz" numeric(20,0),
  "indexlocal" numeric(10,0),
  "kmplecare" numeric(20,7),
  "kmsosire" numeric(20,7),
  "dataplecare" date,
  "codpers" numeric(20,0),
  "codpart" numeric(20,0),
  "tipdoc" character varying(30),
  "nrdoc" character varying(30),
  "ruta" character varying(200),
  "tiptransport" character varying(50),
  "cant" numeric(20,7),
  "kminc" numeric(20,7),
  "kmgol" numeric(20,7),
  "obs" character varying(250),
  "codanalizanod" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>faz1</obj_name>
  <obj_hashval>0602e223310db9314390ec8573a5b1a7</obj_hashval>
  <obj_text>CREATE TABLE faz1 (
  "codfaz1" numeric(20,0) NOT NULL,
  "codfaz" numeric(20,0),
  "indexlocal" numeric(10,0),
  "km" numeric(20,7),
  "incarcat" numeric(1,0),
  "tipsursa" numeric(20,0),
  "catdrum" numeric(20,0),
  "coef" numeric(20,7),
  "codfaz0" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>faz2</obj_name>
  <obj_hashval>d13dbdd3ea45b1c1236390094e497aac</obj_hashval>
  <obj_text>CREATE TABLE faz2 (
  "codfaz2" numeric(20,0) NOT NULL,
  "codfaz" numeric(20,0),
  "indexlocal" numeric(20,0),
  "codinstauto" numeric(20,0),
  "cant" numeric(20,7),
  "spor" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>faz3</obj_name>
  <obj_hashval>b6100ab67e0bfb3c117f54123b028f00</obj_hashval>
  <obj_text>CREATE TABLE faz3 (
  "codfaz3" numeric(20,0) NOT NULL,
  "codfaz" numeric(20,0),
  "indexlocal" numeric(10,0),
  "codtraseu" numeric(20,0),
  "parcurgeri" numeric(10,0),
  "kmtraseu" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>fazintr</obj_name>
  <obj_hashval>42b805c31e4f9c1487ec45e7841e5fbb</obj_hashval>
  <obj_text>CREATE TABLE fazintr (
  "codfazintr" numeric(20,0) NOT NULL,
  "codfaz" numeric(20,0),
  "indexlocal" numeric(10,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(10,0),
  "cantcomb" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>firmaluni</obj_name>
  <obj_hashval>5874adf08e6af93ad68f739094794d67</obj_hashval>
  <obj_text>CREATE TABLE firmaluni (
  "ancurent" numeric(4,0),
  "lunacurenta" numeric(2,0),
  "aninitial" numeric(4,0),
  "lunainitiala" numeric(2,0),
  "anmaxim" numeric(4,0),
  "lunamaxima" numeric(2,0),
  "anblocat" numeric(4,0),
  "lunablocata" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>firmecuplate</obj_name>
  <obj_hashval>80435c3f4f14812d30f4d6093262f37d</obj_hashval>
  <obj_text>CREATE TABLE firmecuplate (
  "cod" numeric(20,0),
  "id" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>fisaevalp</obj_name>
  <obj_hashval>f05ce212851103c4bda00692e42cf7f7</obj_hashval>
  <obj_text>CREATE TABLE fisaevalp (
  "codfisa" numeric(20,0),
  "codevaluare" numeric(20,0),
  "cr" numeric(2,0),
  "en" numeric(2,0),
  "mt" numeric(2,0),
  "fr" numeric(2,0),
  "sg" numeric(2,0),
  "na" numeric(2,0),
  "an" numeric(2,0),
  "ug" numeric(2,0),
  "numetesatura" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>fisaevalt</obj_name>
  <obj_hashval>bfde9e1c020d2e7647b5839d23f60aaa</obj_hashval>
  <obj_text>CREATE TABLE fisaevalt (
  "codfisa" numeric(20,0),
  "codevaluare" numeric(20,0),
  "nota" numeric(2,0),
  "numetesatura" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>fisainf</obj_name>
  <obj_hashval>a3d611646404891e59804f3132f2ee2a</obj_hashval>
  <obj_text>CREATE TABLE fisainf (
  "codfisainf" numeric(20,0) NOT NULL,
  "codfisasup" numeric(20,0),
  "poznom" numeric(10,0),
  "codobiectinf" numeric(20,0),
  "codgeneric" numeric(20,0),
  "cantinsup" numeric(20,7),
  "umsec" numeric(20,0),
  "pret" numeric(20,7),
  "dimt" character varying(50),
  "complex" numeric(1,0),
  "material" numeric(1,0),
  "codfisapro" numeric(20,0),
  "umdimt" numeric(20,0),
  "consumator" numeric(20,0),
  "masa" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>fisaman</obj_name>
  <obj_hashval>988a01b1bd16c5821a60e2f143268807</obj_hashval>
  <obj_text>CREATE TABLE fisaman (
  "codfisaman" numeric(20,0) NOT NULL,
  "codtraseu" numeric(20,0),
  "nrop" numeric(20,0),
  "codop" numeric(20,0),
  "codlocm" numeric(20,0),
  "coddif" numeric(10,0),
  "dsv" numeric(10,0),
  "tpi" numeric(10,0),
  "tu" numeric(10,0),
  "bps" numeric(10,0),
  "final" numeric(1,0),
  "blocat" numeric(1,0),
  "codfisateh" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>fisamand</obj_name>
  <obj_hashval>a02ec6ffd45d30c42fe320e004b20a02</obj_hashval>
  <obj_text>CREATE TABLE fisamand (
  "codfisamand" numeric(20,0) NOT NULL,
  "codfisaman" numeric(20,0),
  "codop" numeric(20,0),
  "coddif" numeric(20,0),
  "tpi" numeric(10,0),
  "tu" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>fisamas</obj_name>
  <obj_hashval>720c2dbc91b467aec01a6019ccc97ad0</obj_hashval>
  <obj_text>CREATE TABLE fisamas (
  "codfisamas" numeric(20,0),
  "codintr1" numeric(20,0),
  "nrdoc" numeric(10,0),
  "datadoc" date,
  "codresponsabil" numeric(20,0),
  "codinspector" numeric(20,0),
  "obs" character varying(250),
  "aprobat" numeric(1,0),
  "carnetdoc" numeric(20,0),
  "seriadoc" character varying(20)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>fisamas1</obj_name>
  <obj_hashval>fe27540e2bd9ce5a5b95ed0760f9f45f</obj_hashval>
  <obj_text>CREATE TABLE fisamas1 (
  "codfisamas1" numeric(20,0),
  "codfisamas" numeric(20,0),
  "codprodmas" numeric(20,0),
  "valoare" numeric(20,7),
  "stare" numeric(10,0),
  "obs" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>fisamf</obj_name>
  <obj_hashval>7bdfddc79ef7be548f0c5eb891bf80f2</obj_hashval>
  <obj_text>CREATE TABLE fisamf (
  "codfisamf" numeric(20,0) NOT NULL,
  "codmifix" numeric(20,0),
  "codoperatie" numeric(5,0),
  "dataoperatie" date,
  "gestsursa" numeric(20,0),
  "gestdest" numeric(20,0),
  "preti" numeric(20,7),
  "prete" numeric(20,7),
  "prefixdoc" character varying(2),
  "nrdoc" numeric(20,0),
  "cant" numeric(20,7),
  "obs" character varying(100),
  "coddoc1" numeric(20,0),
  "tipdoc" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>fisarez</obj_name>
  <obj_hashval>421c51f9b6659ce99945f89cb82ecd3b</obj_hashval>
  <obj_text>CREATE TABLE fisarez (
  "codfisarez" numeric(20,0) NOT NULL,
  "codtraseu" numeric(20,0),
  "codprez" numeric(20,0),
  "codgeneric" numeric(20,0),
  "cant" numeric(20,7),
  "umsec" numeric(20,0),
  "pret" numeric(20,7),
  "codfisateh" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>fisasdv</obj_name>
  <obj_hashval>7798e02dac66b568d7ae25fdc692cf06</obj_hashval>
  <obj_text>CREATE TABLE fisasdv (
  "codfisasdv" numeric(20,0) NOT NULL,
  "codfisaman" numeric(20,0),
  "indexlocal" numeric(10,0),
  "codsdv" numeric(20,0),
  "codgeneric" numeric(20,0),
  "cant" numeric(20,7),
  "pret" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>fisasup</obj_name>
  <obj_hashval>59b57b779425f198e3515ec0398d8839</obj_hashval>
  <obj_text>CREATE TABLE fisasup (
  "codfisasup" numeric(20,0) NOT NULL,
  "codproiectnod" numeric(20,0),
  "codobiectnod" numeric(20,0),
  "identificator" character varying(100),
  "datadocumentatie" date,
  "arhiva" character varying(50),
  "obs" character varying(3000),
  "proiectant" numeric(20,0),
  "nivel" numeric(10,0),
  "blocat" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>fisateh</obj_name>
  <obj_hashval>aab2203ecd8ef95cb253eacb4112992f</obj_hashval>
  <obj_text>CREATE TABLE fisateh (
  "codfisateh" numeric(20,0) NOT NULL,
  "codfisasup" numeric(20,0),
  "intocmita" numeric(20,0),
  "datafisa" date,
  "finalizata" numeric(1,0),
  "blocata" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>formatii</obj_name>
  <obj_hashval>5df7a06388bb6b48f05a1bfe48293721</obj_hashval>
  <obj_text>CREATE TABLE formatii (
  "codformatie" numeric(20,0) NOT NULL,
  "den_formatie" character varying(100),
  "simbol" character varying(50),
  "codgest" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>formatii1</obj_name>
  <obj_hashval>dc7988b167d9f2b9078751b249534560</obj_hashval>
  <obj_text>CREATE TABLE formatii1 (
  "codformatie1" numeric(20,0) NOT NULL,
  "codformatie" numeric(20,0),
  "locmunca" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>formatori</obj_name>
  <obj_hashval>fbdefa76603eadf28c590e6fbd08d535</obj_hashval>
  <obj_text>CREATE TABLE formatori (
  "codformator" numeric(20,0) NOT NULL,
  "den_formator" character varying(30),
  "email" character varying(100),
  "telefon" character varying(20),
  "codpers" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>functii</obj_name>
  <obj_hashval>7259b32cf5f1ba6618b3ff8f8f4f280f</obj_hashval>
  <obj_text>CREATE TABLE functii (
  "codfunctie" numeric(20,0) NOT NULL,
  "denumire" character varying(100),
  "codextern" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>functii1</obj_name>
  <obj_hashval>57cfdc53ba5536585dcda3f8620dd8d8</obj_hashval>
  <obj_text>CREATE TABLE functii1 (
  "codfunctie1" numeric(20,0) NOT NULL,
  "codfunctie" numeric(20,0),
  "indexlocal" numeric(20,0),
  "codcurs" numeric(20,0),
  "codtema" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>fuzart</obj_name>
  <obj_hashval>6feb68cf72c0c2b674e560bbafe4c405</obj_hashval>
  <obj_text>CREATE TABLE fuzart (
  "codartinit" numeric(20,0),
  "codartfin" numeric(20,0),
  "codobjinit" numeric(20,0),
  "codobjfin" numeric(20,0),
  "codexterninit" character varying(80),
  "codexternfin" character varying(80),
  "prodinit" character varying(50),
  "prodfin" character varying(50),
  "infoinit" character varying(250),
  "infofin" character varying(250),
  "userid" numeric(20,0),
  "userstr" character varying(250),
  "data" date,
  "codinterninit" character varying(80),
  "codinternfin" character varying(80)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>fuzauto</obj_name>
  <obj_hashval>fe5a909bf715162d80cb633f286da089</obj_hashval>
  <obj_text>CREATE TABLE fuzauto (
  "codautoinit" numeric(20,0),
  "codautofin" numeric(20,0),
  "infoinit" character varying(250),
  "infofin" character varying(250),
  "userid" numeric(20,0),
  "userstr" character varying(250),
  "data" date
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>fuzgest</obj_name>
  <obj_hashval>b3065de54e20c4d20bd18176c8da08f3</obj_hashval>
  <obj_text>CREATE TABLE fuzgest (
  "codgestinit" numeric(20,0),
  "codgestfin" numeric(20,0),
  "subunitinit" character varying(100),
  "subunitfin" character varying(100),
  "infoinit" character varying(250),
  "infofin" character varying(250),
  "userid" numeric(20,0),
  "userstr" character varying(250),
  "data" date
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>fuzlocalit</obj_name>
  <obj_hashval>9d920585fc2776ce9a20c72fcec5f66d</obj_hashval>
  <obj_text>CREATE TABLE fuzlocalit (
  "codlocalitinit" numeric(20,0),
  "codlocalitfin" numeric(20,0),
  "simbautoinit" character varying(2),
  "simbautofin" character varying(2),
  "densupinit" character varying(50),
  "densupfin" character varying(50),
  "infoinit" character varying(250),
  "infofin" character varying(250),
  "userid" numeric(20,0),
  "userstr" character varying(250),
  "data" date
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>fuzpart</obj_name>
  <obj_hashval>3fcb413f64e6aa16f5f77386c0491028</obj_hashval>
  <obj_text>CREATE TABLE fuzpart (
  "codpartinit" numeric(20,0),
  "codpartfin" numeric(20,0),
  "codlocinit" numeric(20,0),
  "codlocfin" numeric(20,0),
  "codextinit" character varying(50),
  "codextfin" character varying(50),
  "codfiscinit" character varying(75),
  "codfiscfin" character varying(75),
  "localitinit" character varying(50),
  "localitfin" character varying(50),
  "infoinit" character varying(250),
  "infofin" character varying(250),
  "userid" numeric(20,0),
  "userstr" character varying(250),
  "data" date,
  "telefoninit" character varying(40),
  "telefonfin" character varying(40)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>fuzpers</obj_name>
  <obj_hashval>e25558d60078eb4b47f58fa3538396dc</obj_hashval>
  <obj_text>CREATE TABLE fuzpers (
  "codpersinit" numeric(20,0),
  "codpersfin" numeric(20,0),
  "subunitinit" character varying(100),
  "subunitfin" character varying(100),
  "infoinit" character varying(750),
  "infofin" character varying(750),
  "userid" numeric(20,0),
  "userstr" character varying(250),
  "data" date
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncontrulsub_codcontrul</obj_name>
  <obj_reftable>ncontrulsub</obj_reftable>
  <obj_hashval>5ca85359a2ec806ef3f2a51c140c9469</obj_hashval>
  <obj_text>CREATE INDEX idx_ncontrulsub_codcontrul ON ncontrulsub USING btree (codcontrul, subunitatea)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>gantt</obj_name>
  <obj_hashval>c86fdf5ffb6f107ae0f69127c3858c73</obj_hashval>
  <obj_text>CREATE TABLE gantt (
  "codgantt" numeric(20,0) NOT NULL,
  "codcmdprodman" numeric(20,0),
  "codcomanda1" numeric(20,0),
  "dstart" date,
  "cant" numeric(10,0),
  "nstart" date,
  "ostart" numeric(7,3),
  "prioritate" numeric(20,0),
  "directie" numeric(1,0),
  "ostop" numeric(7,3),
  "blocat" numeric(1,0),
  "ordine" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>gantt1</obj_name>
  <obj_hashval>01000c86acb56bbfb7752a18e9a902b6</obj_hashval>
  <obj_text>CREATE TABLE gantt1 (
  "codgantt1" numeric(20,0) NOT NULL,
  "codgantt" numeric(20,0),
  "deplasare" numeric,
  "cant" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>general</obj_name>
  <obj_hashval>4c837f8a6ebdb929e835ef626e970d38</obj_hashval>
  <obj_text>CREATE TABLE general (
  "codgeneral" numeric(20,0) NOT NULL,
  "tipdoc" numeric(20,0),
  "coddoc" numeric(20,0),
  "moneda" numeric(20,0),
  "curs" numeric(20,7),
  "tva" numeric(20,7),
  "semnificatie" numeric(20,0),
  "icontavans" numeric(20,0),
  "proctvaavans" numeric(20,7),
  "farareg" numeric(1,0),
  "exclusplata" numeric(1,0),
  "datatva" date
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>general_reg</obj_name>
  <obj_hashval>9d03f1787dc5a042d24e72c6031c4cc7</obj_hashval>
  <obj_text>CREATE TABLE general_reg (
  "codreg" numeric(20,0),
  "codgeneral" numeric(20,0),
  "curs" numeric(20,7),
  "data" date
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>genmonetareretail</obj_name>
  <obj_hashval>848fb25324de9a3ec7926809184d9f96</obj_hashval>
  <obj_text>CREATE TABLE genmonetareretail (
  "codpostretail" numeric(20,0),
  "carnetdoc" numeric(20,0),
  "carnetlivr" numeric(20,0),
  "carnetcmd" numeric(20,0),
  "carnetnp" numeric(20,0),
  "carnetbc" numeric(20,0),
  "carnetnir" numeric(20,0),
  "contintermed" numeric(20,0),
  "contcash" numeric(20,0),
  "contcec" numeric(20,0),
  "contcard" numeric(20,0),
  "conttichet" numeric(20,0),
  "descarcareprod" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>grechiv</obj_name>
  <obj_hashval>e25d74e3c8c2e878521298582a7d7550</obj_hashval>
  <obj_text>CREATE TABLE grechiv (
  "codgrechiv" numeric(20,0) NOT NULL,
  "denumire" character varying(250),
  "cod" character varying(32),
  "ind" numeric(10,0),
  "info" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>grupedrum</obj_name>
  <obj_hashval>7c24fceb5303ad7334f293c002a695ad</obj_hashval>
  <obj_text>CREATE TABLE grupedrum (
  "codgrupa" numeric(20,0) NOT NULL,
  "denumire" character varying(100),
  "simbol" character varying(50),
  "coef" numeric(20,7),
  "descriere" text
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>identevals</obj_name>
  <obj_hashval>e4a39e6eb736679ea86522eb9c3fbbd5</obj_hashval>
  <obj_text>CREATE TABLE identevals (
  "codidentevals" numeric(20,0),
  "nume" character varying(50),
  "dataora" date,
  "nrevaluatori" numeric(3,0),
  "nresantioane" numeric(3,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>idsediulock</obj_name>
  <obj_hashval>329091d2870b7b747eebdf9b5ebf2674</obj_hashval>
  <obj_text>CREATE TABLE idsediulock (
  "cod" numeric(20,0),
  "idsediu" character varying(20),
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>iesdisc</obj_name>
  <obj_hashval>7299e48365b11a21a21bea3e29cf9374</obj_hashval>
  <obj_text>CREATE TABLE iesdisc (
  "codiesdisc" numeric(20,0) NOT NULL,
  "codies" numeric(20,0),
  "coddiscount" numeric(20,0),
  "offinvoice" numeric(1,0),
  "procent" numeric(20,7),
  "codobiect" numeric(20,0),
  "valoare" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>iesiri</obj_name>
  <obj_hashval>3f5c47052f0b9a4ab043d0835db6e7c0</obj_hashval>
  <obj_text>CREATE TABLE iesiri (
  "codies" numeric(20,0) NOT NULL,
  "tipdoc" numeric(20,0),
  "anulat" numeric(20,0),
  "blocat" numeric(20,0),
  "operat" numeric(20,0),
  "prefixdoc" character varying(2),
  "carnetdoc" numeric(20,0),
  "nrdoc" numeric(20,0),
  "datadoc" timestamp(0) without time zone,
  "partener" numeric(20,0),
  "carnetae" numeric(20,0),
  "nrae" numeric(20,0),
  "valdoc" numeric(20,7),
  "tvadoc" numeric(20,7),
  "valdiscount" numeric(20,7),
  "tvadiscount" numeric(20,7),
  "contdiscount" numeric(20,0),
  "accize" numeric(20,7),
  "delegat" numeric(20,0),
  "agent" numeric(20,0),
  "majorari" numeric(20,7),
  "obs" character varying(500),
  "an" numeric(20,0),
  "luna" numeric(20,0),
  "initializari" numeric(1,0),
  "codsubunit" numeric(20,0),
  "codfiscal" numeric(20,0),
  "seriadoc" character varying(20),
  "bugetare" numeric(1,0),
  "codlocatie" numeric(20,0),
  "tipfactura" numeric(10,0),
  "codgestprod" numeric(20,0),
  "contintermed" numeric(20,0),
  "tiptva" numeric(2,0),
  "subunitatea" numeric(20,0),
  "tipconsumator" numeric(2,0),
  "codauto" numeric(20,0),
  "partcustodie" numeric(20,0),
  "codcmdinterna" numeric(20,0),
  "codpers" numeric(20,0),
  "comision" numeric(20,7),
  "codbankcont" numeric(20,0),
  "tipcasamarcat" numeric(5,0),
  "moneda" numeric(20,0),
  "curs" numeric(20,7),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "tiptranzactie" numeric(5,0),
  "mijltransp" character varying(15),
  "nrtransp" character varying(30),
  "listat" numeric(1,0),
  "infocm" numeric(1,0),
  "cursdoc" numeric(20,7),
  "discvol" numeric(20,7),
  "discter" numeric(20,7),
  "monedatransf" numeric(20,7),
  "nri" character varying(50),
  "contsuplim" numeric(20,0),
  "datainreg" timestamp(6) without time zone,
  "custodie" numeric(1,0),
  "faratransport" numeric(1,0),
  "tipchelt" numeric(20,0),
  "carnetcertif" numeric(20,0),
  "nrcertif" numeric(20,0),
  "seriacertif" character varying(10),
  "starerestituire" numeric(1,0),
  "idimport" character varying(30),
  "listatcertif" numeric(1,0),
  "farareg" numeric(1,0),
  "codpersc" numeric(20,0),
  "exclusplata" numeric(1,0),
  "codiesmamb" numeric(20,0),
  "proctvadoc" numeric(20,7),
  "codanaliza" numeric(20,0),
  "codaecustodie" numeric(20,0),
  "tvaincasare" numeric(1,0),
  "datatva" date,
  "codcontract" numeric(20,0),
  "factsimplif" numeric(1,0),
  "transportator" numeric(20,0),
  "stadiuwms" numeric(2,0),
  "codmonetar" numeric(20,0),
  "numarbonuri" numeric(5,0),
  "emisadeclient" numeric(1,0),
  "nrinfocm" numeric(5,0),
  "nrincasult" numeric(5,0),
  "nrincasim" numeric(5,0),
  "codparttert" numeric(20,0),
  "tiplivrare" numeric(2,0),
  "naturatranz" numeric(2,0),
  "modtransp" numeric(2,0),
  "splittva" numeric(1,0),
  "gratie" numeric(10,0),
  "tipsaft" numeric(2,0),
  "codtvaserv" numeric(20,0),
  "proctvaoss" numeric(6,3),
  "tipet" numeric(6,0),
  "is_etransp" numeric(1,0),
  "noaccize" numeric(1,0),
  "nrnir" character varying(20),
  "datanir" date,
  "platforma_online" numeric(2,0),
  "rotefact" numeric(1,0),
  "flags" numeric(5,0),
  "iddescarcare" numeric(20,0),
  "valdocefact" numeric(20,7),
  "remorca" numeric(20,0),
  "proiect" character varying(20),
  "contract" character varying(20),
  "comanda" character varying(20),
  "exclusintrastat" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>iesiri1</obj_name>
  <obj_hashval>be6f72991f2e97d1404b8cb99e633dca</obj_hashval>
  <obj_text>CREATE TABLE iesiri1 (
  "codies1" numeric(20,0) NOT NULL,
  "codies" numeric(20,0),
  "indexlocal" numeric(20,0),
  "tiplinie" character varying(2),
  "umsec" numeric(20,0),
  "contserv" numeric(20,0),
  "gestact" numeric(20,0),
  "codobiect" numeric(20,0),
  "pretorig" numeric(20,7),
  "pu" numeric(20,7),
  "cant" numeric(20,7),
  "tva" numeric(20,7),
  "cont" numeric(20,7),
  "addim" numeric(20,7),
  "procdisc" numeric(20,7),
  "restfact" numeric(20,7),
  "pumaximal" numeric(20,7),
  "tiplivrare" numeric(1,0),
  "garantie" numeric(20,0),
  "codobligstorno" numeric(20,0),
  "cursfacturaavans" numeric(20,7),
  "coefdiscmaj" numeric(20,7),
  "obs" character varying(450),
  "codobiectorig" numeric(20,0),
  "paritateorig" numeric(20,7),
  "contdiscount" numeric(20,0),
  "codcriteriu" numeric(20,0),
  "mifix" numeric(1,0),
  "zile" numeric(5,0),
  "costtransport" numeric(20,7),
  "zilecmd" numeric(20,0),
  "codlivr1prodval" numeric(20,0),
  "codies1storno" numeric(20,0),
  "codoferta1" numeric(20,0),
  "cadou" numeric(20,0),
  "tipplata" numeric(1,0),
  "pretpromo" numeric(1,0),
  "cadoulink" numeric(5,0),
  "codioartcust" numeric(20,0),
  "umcorelat" numeric(20,0),
  "cantcorelat" numeric(20,7),
  "pucorelat" numeric(20,7),
  "codcentru" numeric(20,0),
  "codcadou" numeric(20,0),
  "codobligmonetar" numeric(20,0),
  "taxa" numeric(1,0),
  "termencontract" date,
  "codliniedocimp" numeric(20,0),
  "tipdocimp" numeric(5,0),
  "codcmdint1" numeric(20,0),
  "codanalizanod" numeric(20,0),
  "d1d3bcs" numeric(1,0),
  "codobligmajorat" numeric(20,0),
  "codagentemulare" numeric(20,0),
  "codpromo1" numeric(20,0),
  "codcontract1" numeric(20,0),
  "valdiscpret" numeric(20,7),
  "preluat" numeric(1,0),
  "codmifix" numeric(20,0),
  "restimbmf" numeric(20,7),
  "custodieintrare" numeric(1,0),
  "codauto" numeric(20,0),
  "icontpart" numeric(2,0),
  "cantconstatat" numeric(20,7),
  "discmanual" numeric(1,0),
  "codutilaj" numeric(20,0),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7),
  "cantum1" numeric(20,7),
  "impozabil" numeric(1,0),
  "pretum1" numeric(20,7),
  "codserie" numeric(20,0),
  "codpartcomisemul" numeric(20,0),
  "admax" numeric(20,7),
  "valfin" numeric(20,7),
  "tvafin" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>iesiri1retail</obj_name>
  <obj_hashval>203910df79f18f8ffbf973562b315d9e</obj_hashval>
  <obj_text>CREATE TABLE iesiri1retail (
  "codies1retail" numeric(20,0) NOT NULL,
  "codiesretail" numeric(20,0),
  "indexlocal" numeric(20,0),
  "tiplinie" character varying(2),
  "umsec" numeric(20,0),
  "contserv" numeric(20,0),
  "gestact" numeric(20,0),
  "codobiect" numeric(20,0),
  "pretorig" numeric(20,7),
  "pu" numeric(20,7),
  "cant" numeric(20,7),
  "tva" numeric(20,7),
  "cont" numeric(20,7),
  "addim" numeric(20,7),
  "procdisc" numeric(20,7),
  "restfact" numeric(20,7),
  "pumaximal" numeric(20,7),
  "garantie" numeric(20,0),
  "coefdiscmaj" numeric(20,7),
  "obs" character varying(450),
  "contdiscount" numeric(20,0),
  "codcriteriu" numeric(20,0),
  "zile" numeric(5,0),
  "cadou" numeric(20,0),
  "codcadou" numeric(20,0),
  "taxa" numeric(1,0),
  "codagentemulare" numeric(20,0),
  "valdiscpret" numeric(20,7),
  "discmanual" numeric(1,0),
  "codutilaj" numeric(20,0),
  "codgest" numeric(20,0),
  "codioartval" numeric(20,0),
  "tvaneex" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncontrulsub_subunitatea</obj_name>
  <obj_reftable>ncontrulsub</obj_reftable>
  <obj_hashval>854231f81f0072214817a3a32dfbe5e8</obj_hashval>
  <obj_text>CREATE INDEX idx_ncontrulsub_subunitatea ON ncontrulsub USING btree (subunitatea, codcontrul)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncontrult_codcontt</obj_name>
  <obj_reftable>ncontrult</obj_reftable>
  <obj_hashval>0a6384f3903ea7f6ad7e70af487384d4</obj_hashval>
  <obj_text>CREATE INDEX idx_ncontrult_codcontt ON ncontrult USING btree (codcontt)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nconts_codparinte</obj_name>
  <obj_reftable>nconts</obj_reftable>
  <obj_hashval>8fd117f6b666ce5518509154e8be5f72</obj_hashval>
  <obj_text>CREATE INDEX idx_nconts_codparinte ON nconts USING btree (codparinte)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nconts1_al</obj_name>
  <obj_reftable>nconts1</obj_reftable>
  <obj_hashval>33700e2e21b4065eedf2378f42bea50c</obj_hashval>
  <obj_text>CREATE INDEX idx_nconts1_al ON nconts1 USING btree (codconts, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nconts1_codconts</obj_name>
  <obj_reftable>nconts1</obj_reftable>
  <obj_hashval>08242d5313a06ba356705e9770b1fdd8</obj_hashval>
  <obj_text>CREATE INDEX idx_nconts1_codconts ON nconts1 USING btree (codconts)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncontsold_codcont</obj_name>
  <obj_reftable>ncontsold</obj_reftable>
  <obj_hashval>bf8e605457ed4e377d0c7031d430b732</obj_hashval>
  <obj_text>CREATE INDEX idx_ncontsold_codcont ON ncontsold USING btree (codcont)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncontsolds_codconts</obj_name>
  <obj_reftable>ncontsolds</obj_reftable>
  <obj_hashval>db6b2a52199405963f8948810424d37b</obj_hashval>
  <obj_text>CREATE INDEX idx_ncontsolds_codconts ON ncontsolds USING btree (codconts)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncontsoldsub_codcontsold</obj_name>
  <obj_reftable>ncontsoldsub</obj_reftable>
  <obj_hashval>7cce4ecfd2844d009643a17befee77a6</obj_hashval>
  <obj_text>CREATE INDEX idx_ncontsoldsub_codcontsold ON ncontsoldsub USING btree (codcontsold)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncontsoldsub_subunitatea</obj_name>
  <obj_reftable>ncontsoldsub</obj_reftable>
  <obj_hashval>c94463d0f34a36412f19abf324e3eb74</obj_hashval>
  <obj_text>CREATE INDEX idx_ncontsoldsub_subunitatea ON ncontsoldsub USING btree (subunitatea, codcontsold)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>iesiriretail</obj_name>
  <obj_hashval>2c79bc2f956cb424546fa395e9c6ee12</obj_hashval>
  <obj_text>CREATE TABLE iesiriretail (
  "codiesretail" numeric(20,0) NOT NULL,
  "codies" numeric(20,0),
  "tipdoc" numeric(20,0),
  "anulat" numeric(20,0),
  "blocat" numeric(20,0),
  "operat" numeric(20,0),
  "prefixdoc" character varying(2),
  "carnetdoc" numeric(20,0),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "codpartretail" numeric(20,0),
  "partener" numeric(20,0),
  "valdoc" numeric(20,7),
  "tvadoc" numeric(20,7),
  "valdiscount" numeric(20,7),
  "tvadiscount" numeric(20,7),
  "delegatretail" numeric(20,0),
  "delegat" numeric(20,0),
  "obs" character varying(450),
  "an" numeric(20,0),
  "luna" numeric(20,0),
  "codfiscalretail" numeric(20,0),
  "codfiscal" numeric(20,0),
  "seriadoc" character varying(20),
  "codsediuretail" numeric(20,0),
  "codlocatie" numeric(20,0),
  "tiptva" numeric(2,0),
  "subunitatea" numeric(20,0),
  "moneda" numeric(20,0),
  "curs" numeric(20,7),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "mijltransp" character varying(15),
  "nrtransp" character varying(30),
  "listat" numeric(1,0),
  "infocm" numeric(1,0),
  "cursdoc" numeric(20,7),
  "nri" character varying(30),
  "faratransport" numeric(1,0),
  "tipchelt" numeric(20,0),
  "exclusplata" numeric(1,0),
  "proctvadoc" numeric(20,7),
  "datatva" date,
  "tipmodif" character varying(1),
  "agent" numeric(20,0),
  "carnetlivr" numeric(20,0),
  "nrlivr" numeric(20,0),
  "codpartcomis" numeric(20,0),
  "codpartretailcomis" numeric(20,0),
  "tipet" numeric(6,0),
  "is_etransp" numeric(1,0),
  "rotefact" numeric(1,0),
  "flags" numeric(5,0),
  "iddescarcare" numeric(20,0),
  "valdocefact" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>iesprodlink</obj_name>
  <obj_hashval>d77e11da0f982e76dd50fab4174f7360</obj_hashval>
  <obj_text>CREATE TABLE iesprodlink (
  "codies1" numeric(20,0) NOT NULL,
  "codcmdprodmat" numeric(20,0),
  "cant" numeric(20,7),
  "codprogramf1" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>iespuncte</obj_name>
  <obj_hashval>29554d931f28961978236ec498c3e3b3</obj_hashval>
  <obj_text>CREATE TABLE iespuncte (
  "codiespuncte" numeric(20,0) NOT NULL,
  "codies" numeric(20,0),
  "punctedoc" numeric(20,7),
  "puncteanulate" numeric(20,7),
  "punctestinse" numeric(20,7),
  "blocat" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncontsoldt_codcontt</obj_name>
  <obj_reftable>ncontsoldt</obj_reftable>
  <obj_hashval>4fbed1513e5b2da0cf95c45b30e74c33</obj_hashval>
  <obj_text>CREATE INDEX idx_ncontsoldt_codcontt ON ncontsoldt USING btree (codcontt)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>iesvallink</obj_name>
  <obj_hashval>2b6e1f89624a147ab7e8a634a3656339</obj_hashval>
  <obj_text>CREATE TABLE iesvallink (
  "codies1" numeric(20,0),
  "codlivr1" numeric(20,0),
  "cant" numeric(20,7),
  "codies" numeric(20,0),
  "tiplink" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>imbmifixlink</obj_name>
  <obj_hashval>984d638f37db1d79fbaf628a6e16cdc2</obj_hashval>
  <obj_text>CREATE TABLE imbmifixlink (
  "codimbmifixlink" numeric(20,0),
  "codtransf1" numeric(20,0),
  "codintr1" numeric(20,0),
  "cant" numeric(20,7),
  "codies1" numeric(20,0),
  "codnc1" numeric(20,0),
  "codmifix" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>imp_codp</obj_name>
  <obj_hashval>ef515e7837ad5d6131081e21e69e22d4</obj_hashval>
  <obj_text>CREATE TABLE imp_codp (
  "siruta" character varying(500),
  "codpostal" character varying(500)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>imp_um</obj_name>
  <obj_hashval>b1cd775c5680fd1017ce0a3a3919fb78</obj_hashval>
  <obj_text>CREATE TABLE imp_um (
  "codsaft" character varying(500),
  "name" character varying(1000),
  "denumire" character varying(1000)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>inactivretail</obj_name>
  <obj_hashval>f6ed05438911f11a1f4a2e41800ae33a</obj_hashval>
  <obj_text>CREATE TABLE inactivretail (
  "codinactivretail" numeric(20,0) NOT NULL,
  "codobiect" numeric(20,0),
  "codpostretail" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>infoactualconst</obj_name>
  <obj_hashval>b424ca954fc0edf71472593e57ccd11e</obj_hashval>
  <obj_text>CREATE TABLE infoactualconst (
  "codconst1" numeric(20,0),
  "denconst" character varying(100),
  "simbol" character varying(100),
  "indexconst" character varying(10),
  "tipoper" character varying(1),
  "valoare" character varying(300),
  "tipconst" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>infobuffer</obj_name>
  <obj_hashval>6864221919bf810b04e9a411f9cecd52</obj_hashval>
  <obj_text>CREATE TABLE infobuffer (
  "infotime" timestamp(6) without time zone,
  "infoline" character varying(200),
  "detalii" text
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>inputbuffer</obj_name>
  <obj_hashval>bf80208aef88402d021aa4b94bb4f84f</obj_hashval>
  <obj_text>CREATE TABLE inputbuffer (
  "line" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>interfataklg</obj_name>
  <obj_hashval>603c090be62b959ae45b2dbba7b058d4</obj_hashval>
  <obj_text>CREATE TABLE interfataklg (
  "cod" numeric(20,0) NOT NULL,
  "tipmesaj" character varying(30),
  "data" timestamp(6) without time zone,
  "numefisier" character varying(50),
  "xml" text,
  "idmesaj" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>intrari</obj_name>
  <obj_hashval>d0201f0abe6d4d91f4d33c46d3f16e0f</obj_hashval>
  <obj_text>CREATE TABLE intrari (
  "codintr" numeric(20,0) NOT NULL,
  "tipdoc" numeric(20,0),
  "anulat" numeric(20,0),
  "blocat" numeric(20,0),
  "operat" numeric(20,0),
  "prefixdoc" character varying(2),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "partener" numeric(20,0),
  "nraviz" numeric(20,0),
  "carnetdoc" numeric(20,0),
  "valdoc" numeric(20,7),
  "tvadoc" numeric(20,7),
  "majorari" numeric(20,7),
  "an" numeric(20,0),
  "luna" numeric(20,0),
  "obs" character varying(500),
  "complex" numeric(1,0),
  "satelit" numeric(1,0),
  "initializari" numeric(1,0),
  "codsubunit" numeric(20,0),
  "codfiscal" numeric(20,0),
  "seriadoc" character varying(20),
  "bugetare" numeric(1,0),
  "valsuplim" numeric(20,7),
  "contsuplim" numeric(20,0),
  "tiprepsuplim" numeric(1,0),
  "codlocatie" numeric(20,0),
  "tipfactura" numeric(10,0),
  "codgestprod" numeric(20,0),
  "subunitatea" numeric(20,0),
  "tiptva" numeric(2,0),
  "moneda" numeric(20,0),
  "curs" numeric(20,7),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "tiptranzactie" numeric(5,0),
  "discvol" numeric(20,7),
  "discter" numeric(20,7),
  "nri" character varying(20),
  "schimb" numeric(1,0),
  "codformatie" numeric(20,0),
  "idimport" character varying(30),
  "delegat" numeric(20,0),
  "mijltransp" character varying(15),
  "nrtransp" character varying(30),
  "farareg" numeric(1,0),
  "exclusplata" numeric(1,0),
  "codauto" numeric(20,0),
  "prorata" numeric(3,0),
  "codcontract" numeric(20,0),
  "codanaliza" numeric(20,0),
  "tvaincasare" numeric(1,0),
  "tvaincasare_f" numeric(1,0),
  "cursdoc" numeric(20,7),
  "transportator" numeric(20,0),
  "valtransport" numeric(20,7),
  "custodie" numeric(1,0),
  "factsimplif" numeric(1,0),
  "agent" numeric(20,0),
  "cursnir" numeric(20,7),
  "stadiuwms" numeric(2,0),
  "datarefscad" date,
  "autofacturare" numeric(1,0),
  "tiplivrare" numeric(2,0),
  "naturatranz" numeric(2,0),
  "modtransp" numeric(2,0),
  "splittva" numeric(1,0),
  "ordonantat" numeric(1,0),
  "exportklg" numeric(1,0),
  "exportatklg" timestamp(6) without time zone,
  "procstopaj" numeric(5,2),
  "tipsaft" numeric(2,0),
  "tipet" numeric(6,0),
  "is_etransp" numeric(1,0),
  "rotefact" numeric(1,0),
  "iddescarcare" character varying(20),
  "valdocefact" numeric(20,7),
  "datatva" date,
  "aprobat" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>intrari1</obj_name>
  <obj_hashval>644237a03719e7e40bf1fa2464ae7151</obj_hashval>
  <obj_text>CREATE TABLE intrari1 (
  "codintr1" numeric(20,0) NOT NULL,
  "codintr" numeric(20,0),
  "indexlocal" numeric(5,0),
  "tiplinie" character varying(1),
  "umsec" numeric(10,0),
  "an" numeric(5,0),
  "luna" numeric(2,0),
  "contserv" numeric(10,0),
  "gestact" numeric(10,0),
  "codobiect" numeric(20,0),
  "pretorig" numeric(20,7),
  "pu" numeric(20,7),
  "cant" numeric(20,7),
  "tva" numeric(20,7),
  "addim" numeric(20,7),
  "restfact" numeric(20,7),
  "nrcertif" character varying(25),
  "tg" date,
  "pumaximal" numeric(20,7),
  "puridicata" numeric(20,7),
  "procadaos" numeric(20,7),
  "furnavizsubunit" numeric(20,0),
  "dataachizavizsubunit" date,
  "codobligstorno" numeric(20,0),
  "cursfacturaavans" numeric(20,7),
  "mifix" numeric(1,0),
  "coefdiscmaj" numeric(20,7),
  "obs" character varying(200),
  "codobiectorig" numeric(20,0),
  "paritateorig" numeric(20,7),
  "contdiscount" numeric(20,0),
  "zile" numeric(5,0),
  "codcmd1ae" numeric(20,0),
  "zilecmd" numeric(5,0),
  "codmifix" numeric(20,0),
  "restimbmf" numeric(20,7),
  "codintr1storno" numeric(20,0),
  "codoferta1" numeric(20,0),
  "codcentru" numeric(20,0),
  "custodie" numeric(1,0),
  "restasteptare" numeric(20,7),
  "contasteptare" numeric(20,0),
  "codauto" numeric(20,0),
  "tvaneded" numeric(1,0),
  "codcmdint1" numeric(20,0),
  "codanalizanod" numeric(20,0),
  "codcontract1" numeric(20,0),
  "taxa" numeric(1,0),
  "preluat" numeric(1,0),
  "termencontract" date,
  "pretum1" numeric(20,7),
  "icontpart" numeric(2,0),
  "rotvaltaxa" numeric(2,0),
  "codintr1link" numeric(20,0),
  "codnimob" numeric(20,0),
  "gestprodavizsub" numeric(20,0),
  "codliniedocimp" numeric(20,0),
  "impozabil" numeric(1,0),
  "tipdocimp" numeric(5,0),
  "admax" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>intrasteptlink</obj_name>
  <obj_hashval>5ce5135f825196a2a4594296c8e603bf</obj_hashval>
  <obj_text>CREATE TABLE intrasteptlink (
  "codintr1" numeric(20,0),
  "codliniefactura" numeric(20,0),
  "cant" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>intrdoctransp</obj_name>
  <obj_hashval>4bfeffc618b9e679580be6525a80a5b0</obj_hashval>
  <obj_text>CREATE TABLE intrdoctransp (
  "cod" numeric(20,0),
  "codintr" numeric(20,0),
  "codintrlink" numeric(20,0),
  "valtransport" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>intrlink</obj_name>
  <obj_hashval>9c746fdd44d35fabf3621d1e2accde7a</obj_hashval>
  <obj_text>CREATE TABLE intrlink (
  "codintr1" numeric(20,0) NOT NULL,
  "codliniecomanda" numeric(20,0),
  "codlinieaviz" numeric(20,0),
  "cant" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>intrprodlink</obj_name>
  <obj_hashval>36d01255227b2c589e90c72c9892843e</obj_hashval>
  <obj_text>CREATE TABLE intrprodlink (
  "codintr1" numeric(20,0) NOT NULL,
  "codliniecomanda" numeric(20,0),
  "codlinieaviz" numeric(20,0),
  "cant" numeric(20,7),
  "codprogramf1" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>inventar</obj_name>
  <obj_hashval>83d5706576d73742295370b2d506a1b3</obj_hashval>
  <obj_text>CREATE TABLE inventar (
  "codinventar" numeric(20,0) NOT NULL,
  "nrinventar" numeric(10,0),
  "datainventar" date,
  "gestiune" numeric(20,0),
  "responsabil" numeric(20,0),
  "observatii" character varying(250),
  "tip" numeric(1,0),
  "diminuare" numeric(20,0),
  "marire" numeric(20,0),
  "facturare" numeric(20,0),
  "iart" numeric(1,0),
  "itipcont" numeric(1,0),
  "subunitate" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "tiprezolvare" numeric(10,0),
  "flgpalm" numeric(1,0),
  "blocat" numeric(1,0),
  "iclase" numeric(1,0),
  "iprod" numeric(1,0),
  "iclases" numeric(1,0),
  "iclasew" numeric(1,0),
  "rezdif" numeric(1,0),
  "marja" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>inventar1</obj_name>
  <obj_hashval>83d9c24d1d36c268cf80330cacd80a88</obj_hashval>
  <obj_text>CREATE TABLE inventar1 (
  "codinventar1" numeric(20,0) NOT NULL,
  "codinventar" numeric(20,0),
  "codlocatie" numeric(20,0),
  "codobiect" numeric(20,0),
  "codserie" numeric(20,0),
  "scriptic" numeric(20,7),
  "faptic" numeric(20,7),
  "scripticum1" numeric(20,7),
  "fapticum1" numeric(20,7),
  "scripticum2" numeric(20,7),
  "fapticum2" numeric(20,7),
  "expirare" date,
  "rezolvat" numeric(1,0),
  "valoare" numeric(20,7),
  "ordine" numeric(20,0),
  "um1" numeric(20,0),
  "blocat" numeric(1,0),
  "tipserie" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>inventclase</obj_name>
  <obj_hashval>87634fd1bd94ea4dbe0c778787e9125b</obj_hashval>
  <obj_text>CREATE TABLE inventclase (
  "codinventclase" numeric(20,0) NOT NULL,
  "codinventar" numeric(20,0),
  "codclasea" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>inventclases</obj_name>
  <obj_hashval>6eab14971134974d82d93bc399e76171</obj_hashval>
  <obj_text>CREATE TABLE inventclases (
  "codinventclases" numeric(20,0) NOT NULL,
  "codinventar" numeric(20,0),
  "codclaseas" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>inventcont</obj_name>
  <obj_hashval>5ab9df70666b67c760c426f14e1a8a29</obj_hashval>
  <obj_text>CREATE TABLE inventcont (
  "codinventcont" numeric(20,0) NOT NULL,
  "codinventar" numeric(20,0),
  "codtipcont" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>inventprod</obj_name>
  <obj_hashval>f6b5554ceee65ccd1cb2dee796bba3b7</obj_hashval>
  <obj_text>CREATE TABLE inventprod (
  "codinventprod" numeric(20,0) NOT NULL,
  "codinventar" numeric(20,0),
  "codpart" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncontt_codparinte</obj_name>
  <obj_reftable>ncontt</obj_reftable>
  <obj_hashval>bc2757d253ea44693c204834ec28bcfa</obj_hashval>
  <obj_text>CREATE INDEX idx_ncontt_codparinte ON ncontt USING btree (codparinte)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>inventrez</obj_name>
  <obj_hashval>e1811d0d454af8371b4cfb8f3fb3d711</obj_hashval>
  <obj_text>CREATE TABLE inventrez (
  "codrezolvare" numeric(20,0) NOT NULL,
  "codinventar1" numeric(20,0),
  "codnirstoc" numeric(20,0),
  "rezolvat" numeric(20,7),
  "rezolvatum1" numeric(20,7),
  "rezolvatum2" numeric(20,7),
  "pretachiz" numeric(20,7),
  "pretinreg" numeric(20,7),
  "codioart" numeric(20,0),
  "codpart" numeric(20,0),
  "codnirser" numeric(20,0),
  "tva" numeric(10,7),
  "tg" timestamp(6) without time zone,
  "pretmaximal" numeric(20,7),
  "codlocatie" numeric(20,0),
  "codgest" numeric(20,0),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7),
  "puval" numeric(20,7),
  "dataachiz" date
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>inventstoc</obj_name>
  <obj_hashval>eb61d47c037be91296a53e4953494af5</obj_hashval>
  <obj_text>CREATE TABLE inventstoc (
  "codinventstoc" numeric(20,0) NOT NULL,
  "codinventar1" numeric(20,0),
  "codinventar" numeric(20,0),
  "codnirstoc" numeric(20,0),
  "codnirser" numeric(20,0),
  "pret" numeric(20,7),
  "rest" numeric(20,7),
  "restum1" numeric(20,7),
  "restum2" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ioart</obj_name>
  <obj_hashval>c3c5261bce0f8516f9af7136a203227d</obj_hashval>
  <obj_text>CREATE TABLE ioart (
  "codioart" numeric(20,0) NOT NULL,
  "den_ioart" character varying(60),
  "simbol" character varying(15),
  "codvanzare" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ioart1</obj_name>
  <obj_hashval>7ed97a6ae476a6a5e4ca3c3d25f810be</obj_hashval>
  <obj_text>CREATE TABLE ioart1 (
  "codioart1" numeric(20,0) NOT NULL,
  "codioart" numeric(20,0),
  "cont" numeric(20,0),
  "diferente" numeric(20,0),
  "cheltuieli" numeric(20,0),
  "venituri" numeric(20,0),
  "plusinventar" numeric(20,0),
  "minusinventar" numeric(20,0),
  "chelttvacolectat" numeric(20,0),
  "controtunjiri" numeric(20,0),
  "diverse" numeric(20,0),
  "custodie" numeric(20,0),
  "accizelatransfer" numeric(1,0),
  "descarcareg" numeric(1,0),
  "contabgest" numeric(1,0),
  "baza" numeric(1,0),
  "difpret" numeric(1,0),
  "aretvaneex" numeric(1,0),
  "tvaneex" character varying(10),
  "mg" numeric(1,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "pustandard" numeric(1,0),
  "provizion" numeric(20,0),
  "cheltprovizion" numeric(20,0),
  "venitprovizion" numeric(20,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ioartlink</obj_name>
  <obj_hashval>0a8ce54fde00c4ae17bc9ea46fec8549</obj_hashval>
  <obj_text>CREATE TABLE ioartlink (
  "codioartlink" numeric(20,0) NOT NULL,
  "codioart" numeric(20,0),
  "codmacheta" numeric(10,0),
  "codioartechiv" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>iobank</obj_name>
  <obj_hashval>94512c4d2248dd58b2edd7eb3a7421d7</obj_hashval>
  <obj_text>CREATE TABLE iobank (
  "codiobank" numeric(20,0) NOT NULL,
  "den_iobank" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>iobank1</obj_name>
  <obj_hashval>adf103daa3f75be65dec504c2a62c7d1</obj_hashval>
  <obj_text>CREATE TABLE iobank1 (
  "codiobank1" numeric(30,0),
  "codiobank" numeric(20,0),
  "cont" numeric(20,0),
  "dobanda" numeric(20,0),
  "comision" numeric(20,0),
  "cheltuielicv" numeric(20,0),
  "venituricv" numeric(20,0),
  "pcec" numeric(20,0),
  "pefecte" numeric(20,0),
  "pefecterem" numeric(20,0),
  "icec" numeric(20,0),
  "iefecte" numeric(20,0),
  "iefecterem" numeric(20,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>iofilial</obj_name>
  <obj_hashval>5ea4b576d06449671563b4374f262e4c</obj_hashval>
  <obj_text>CREATE TABLE iofilial (
  "codiofilial" numeric(20,0) NOT NULL,
  "den_iofilial" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>iofilial1</obj_name>
  <obj_hashval>b26841a91e62afd7487d2e6af18e1f63</obj_hashval>
  <obj_text>CREATE TABLE iofilial1 (
  "codiofilial1" numeric(20,0) NOT NULL,
  "codiofilial" numeric(10,0),
  "contdecontare" numeric(20,0),
  "contdecontserv" numeric(20,0),
  "contdecontcb" numeric(20,0),
  "contdecontcmp" numeric(20,0),
  "contdecontaref" numeric(20,0),
  "isfirma" numeric(1,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>iopart</obj_name>
  <obj_hashval>92012ceb8ef92c094f777c13ee0113f1</obj_hashval>
  <obj_text>CREATE TABLE iopart (
  "codiopart" numeric(20,0) NOT NULL,
  "den_iopart" character varying(30),
  "simbol" character varying(15)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>iopart1</obj_name>
  <obj_hashval>fef2a77cb33820a4fb585e78e85b6a63</obj_hashval>
  <obj_text>CREATE TABLE iopart1 (
  "codiopart1" numeric(20,0),
  "codiopart" numeric(20,0),
  "contfurnizor" numeric(20,0),
  "contclient" numeric(20,0),
  "contfurnavans" numeric(20,0),
  "contclientavans" numeric(20,0),
  "contfurnaviz" numeric(20,0),
  "contclientaviz" numeric(20,0),
  "contfurnmf" numeric(20,0),
  "contcreditd" numeric(20,0),
  "contdebitd" numeric(20,0),
  "contlitigii" numeric(20,0),
  "contfurnavs" numeric(20,0),
  "contfurnavic" numeric(20,0),
  "contfurnavin" numeric(20,0),
  "contterti" numeric(20,0),
  "contfurnleas" numeric(20,0),
  "contncrf" numeric(20,0),
  "contncrc" numeric(20,0),
  "contcheltavans" numeric(20,0),
  "contvenitavans" numeric(20,0),
  "contgarantieef" numeric(20,0),
  "contgarantietf" numeric(20,0),
  "contgarantieec" numeric(20,0),
  "contgarantietc" numeric(20,0),
  "contsuplimf1" numeric(20,0),
  "contsuplimf2" numeric(20,0),
  "contsuplimf3" numeric(20,0),
  "contsuplimf4" numeric(20,0),
  "contsuplimf5" numeric(20,0),
  "contsuplimc1" numeric(20,0),
  "contsuplimc2" numeric(20,0),
  "contsuplimc3" numeric(20,0),
  "contsuplimc4" numeric(20,0),
  "contsuplimc5" numeric(20,0),
  "contsuplimf6" numeric(20,0),
  "contsuplimf7" numeric(20,0),
  "contsuplimf8" numeric(20,0),
  "contsuplimf9" numeric(20,0),
  "contsuplimf10" numeric(20,0),
  "contsuplimf11" numeric(20,0),
  "contsuplimf12" numeric(20,0),
  "contsuplimf13" numeric(20,0),
  "contsuplimf14" numeric(20,0),
  "contsuplimf15" numeric(20,0),
  "contsuplimf16" numeric(20,0),
  "contsuplimf17" numeric(20,0),
  "contsuplimf18" numeric(20,0),
  "contsuplimf19" numeric(20,0),
  "contsuplimf20" numeric(20,0),
  "contsuplimf21" numeric(20,0),
  "contsuplimf22" numeric(20,0),
  "contsuplimf23" numeric(20,0),
  "contsuplimf24" numeric(20,0),
  "contsuplimf25" numeric(20,0),
  "contsuplimf26" numeric(20,0),
  "contsuplimf27" numeric(20,0),
  "contsuplimf28" numeric(20,0),
  "contsuplimf29" numeric(20,0),
  "contsuplimf30" numeric(20,0),
  "tvaneexf" character varying(10),
  "tvaneexc" character varying(10),
  "tvaneexp" character varying(10),
  "tvaneexi" character varying(10),
  "tip" numeric(1,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>iopart1_x</obj_name>
  <obj_hashval>9c4681aa86fb35a565bb8fc18983f304</obj_hashval>
  <obj_text>CREATE TABLE iopart1_x (
  "codiopart1" numeric(20,0),
  "codiopart" numeric(20,0),
  "contfurnizor" numeric(20,0),
  "contclient" numeric(20,0),
  "contfurnavans" numeric(20,0),
  "contclientavans" numeric(20,0),
  "contfurnaviz" numeric(20,0),
  "contclientaviz" numeric(20,0),
  "contfurnmf" numeric(20,0),
  "contcreditd" numeric(20,0),
  "contdebitd" numeric(20,0),
  "contlitigii" numeric(20,0),
  "contfurnavs" numeric(20,0),
  "contfurnavic" numeric(20,0),
  "contfurnavin" numeric(20,0),
  "contterti" numeric(20,0),
  "contfurnleas" numeric(20,0),
  "contncrf" numeric(20,0),
  "contncrc" numeric(20,0),
  "contcheltavans" numeric(20,0),
  "contvenitavans" numeric(20,0),
  "contgarantieef" numeric(20,0),
  "contgarantietf" numeric(20,0),
  "contgarantieec" numeric(20,0),
  "contgarantietc" numeric(20,0),
  "contsuplimf1" numeric(20,0),
  "contsuplimf2" numeric(20,0),
  "contsuplimf3" numeric(20,0),
  "contsuplimf4" numeric(20,0),
  "contsuplimf5" numeric(20,0),
  "contsuplimc1" numeric(20,0),
  "contsuplimc2" numeric(20,0),
  "contsuplimc3" numeric(20,0),
  "contsuplimc4" numeric(20,0),
  "contsuplimc5" numeric(20,0),
  "tvaneexf" character varying(10),
  "tvaneexc" character varying(10),
  "tvaneexp" character varying(10),
  "tvaneexi" character varying(10),
  "tip" numeric(1,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>iopart1x</obj_name>
  <obj_hashval>bae2b61bd6ac0a5e9850ef854cccb045</obj_hashval>
  <obj_text>CREATE TABLE iopart1x (
  "codiopart1" numeric(20,0),
  "codiopart" numeric(20,0),
  "contfurnizor" numeric(20,0),
  "contclient" numeric(20,0),
  "contfurnavans" numeric(20,0),
  "contclientavans" numeric(20,0),
  "contfurnaviz" numeric(20,0),
  "contclientaviz" numeric(20,0),
  "contfurnmf" numeric(20,0),
  "contcreditd" numeric(20,0),
  "contdebitd" numeric(20,0),
  "contlitigii" numeric(20,0),
  "contfurnavs" numeric(20,0),
  "contfurnavic" numeric(20,0),
  "contfurnavin" numeric(20,0),
  "contterti" numeric(20,0),
  "contfurnleas" numeric(20,0),
  "contncrf" numeric(20,0),
  "contncrc" numeric(20,0),
  "contcheltavans" numeric(20,0),
  "contvenitavans" numeric(20,0),
  "contgarantieef" numeric(20,0),
  "contgarantietf" numeric(20,0),
  "contgarantieec" numeric(20,0),
  "contgarantietc" numeric(20,0),
  "contsuplimf1" numeric(20,0),
  "contsuplimf2" numeric(20,0),
  "contsuplimf3" numeric(20,0),
  "contsuplimf4" numeric(20,0),
  "contsuplimf5" numeric(20,0),
  "contsuplimc1" numeric(20,0),
  "contsuplimc2" numeric(20,0),
  "contsuplimc3" numeric(20,0),
  "contsuplimc4" numeric(20,0),
  "contsuplimc5" numeric(20,0),
  "tvaneexf" character varying(10),
  "tvaneexc" character varying(10),
  "tvaneexp" character varying(10),
  "tvaneexi" character varying(10),
  "tip" numeric(1,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>iopers</obj_name>
  <obj_hashval>e41317f903d86e6f888529e616ced2c7</obj_hashval>
  <obj_text>CREATE TABLE iopers (
  "codiopers" numeric(20,0) NOT NULL,
  "den_iopers" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>iopers1</obj_name>
  <obj_hashval>122e43abf403a7ff43c9f725c1ade285</obj_hashval>
  <obj_text>CREATE TABLE iopers1 (
  "codiopers1" numeric(20,0) NOT NULL,
  "codiopers" numeric(20,0),
  "contavansdecont" numeric(20,0),
  "contimputatii" numeric(20,0),
  "contgarantii" numeric(20,0),
  "contalteretineri" numeric(20,0),
  "contavans" numeric(20,0),
  "contliki" numeric(20,0),
  "contneridicate" numeric(20,0),
  "contboala" numeric(20,0),
  "contpartsal" numeric(20,0),
  "contnatura" numeric(20,0),
  "contechipament" numeric(20,0),
  "contimpozit" numeric(20,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>job_dinamic_cols</obj_name>
  <obj_hashval>9aee01b3ea2741cfa2e2fe0d0199a368</obj_hashval>
  <obj_text>CREATE TABLE job_dinamic_cols (
  "tablename" character varying(100),
  "fieldname" character varying(50),
  "display" character varying(200),
  "indexlocal" numeric(20,0),
  "ftype" numeric(1,0),
  "fsize" numeric(4,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>jobcorel</obj_name>
  <obj_hashval>954aba6c7780d5c46a137dba18ec7c6f</obj_hashval>
  <obj_text>CREATE TABLE jobcorel (
  "codcorel" numeric(20,0) NOT NULL,
  "codjob" numeric(20,0),
  "codjob1_1" numeric(20,0),
  "tabla1" character varying(50),
  "lookupfield1" character varying(50),
  "valdescrip1" character varying(1000),
  "codjob1_2" numeric(20,0),
  "tabla2" character varying(50),
  "lookupfield2" character varying(50),
  "valdescrip2" character varying(1000),
  "stare" numeric(2,0),
  "zecimale" numeric(2,0),
  "lookupfield11" character varying(50),
  "lookupfield21" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>jobcorelrez</obj_name>
  <obj_hashval>896497b6b1d5707a96ab747d4eff516f</obj_hashval>
  <obj_text>CREATE TABLE jobcorelrez (
  "codcorelrez" numeric(20,0) NOT NULL,
  "codcorel" numeric(20,0),
  "identificator" character varying(300),
  "valoare1" numeric(20,7),
  "valoare2" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>jobliste</obj_name>
  <obj_hashval>ab7346ab27ef66cf016e4e594ca966e2</obj_hashval>
  <obj_text>CREATE TABLE jobliste (
  "codjob" numeric(20,0) NOT NULL,
  "userid" numeric(20,0),
  "denumire" character varying(200),
  "codorar" numeric(20,0),
  "tipjob" numeric(1,0),
  "subunitatea" numeric(20,0),
  "newdepo" numeric(1,0),
  "webserver" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>jobliste1</obj_name>
  <obj_hashval>6c37852e2033fc2944d1f07fdc3cabd2</obj_hashval>
  <obj_text>CREATE TABLE jobliste1 (
  "codjob1" numeric(20,0) NOT NULL,
  "codjob" numeric(20,0),
  "listaid" numeric(20,0),
  "listaver" numeric(10,0),
  "tipexecutie" numeric(1,0),
  "dataexecutie" timestamp(6) without time zone,
  "perioada" numeric(10,0),
  "executata" numeric(1,0),
  "printare" numeric(1,0),
  "action" numeric(37,0),
  "fisier_export" character varying(200),
  "export" numeric(1,0),
  "obs" character varying(3000),
  "activ" numeric(1,0),
  "areconfig" numeric(1,0),
  "tipinterval" numeric(1,0),
  "tabla" character varying(200),
  "email" character varying(200),
  "jobid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>joblisteconfig</obj_name>
  <obj_hashval>6fb98fd720cb2c3b493b48fbe5c5947f</obj_hashval>
  <obj_text>CREATE TABLE joblisteconfig (
  "codjobconfig" numeric(20,0),
  "codjob1" numeric(20,0),
  "filename" character varying(100),
  "fileconfig" bytea
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>joblistefin</obj_name>
  <obj_hashval>79e2094b30a4f1d119afb68ad39fe982</obj_hashval>
  <obj_text>CREATE TABLE joblistefin (
  "codjoblistefin" numeric(20,0),
  "codjob1" numeric(20,0),
  "tabla" character varying(100),
  "subunitatea" numeric(20,0),
  "skemafirma" character varying(100),
  "listaname" character varying(1000),
  "datagen" date,
  "table_type" numeric(1,0),
  "tipdepo" numeric(3,0),
  "deponame" character varying(50),
  "listid" numeric(20,0),
  "listver" numeric(20,0),
  "dataini" date,
  "datafin" date,
  "faratotal" character varying(3200),
  "ceamselectat" character varying(3200)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>jurnal</obj_name>
  <obj_hashval>bb625bd9911c62eb609f1e627907e8d6</obj_hashval>
  <obj_text>CREATE TABLE jurnal (
  "codjurnal" numeric(20,0) NOT NULL,
  "coddoc" numeric(20,0),
  "tipdoc" numeric(20,0),
  "indexlocal" numeric(20,0),
  "contd" numeric(20,0),
  "contc" numeric(20,0),
  "gest" numeric(20,0),
  "valoare" numeric(20,7),
  "valoarev" numeric(20,7),
  "obs" character varying(200),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "subunitatea" numeric(20,0),
  "datadoc" date,
  "document" character varying(100),
  "codcentru" numeric(20,0),
  "valoaregrup" numeric(20,7),
  "codanalizanod" numeric(20,0),
  "valoare_ifrs" numeric(20,7),
  "valoarev_ifrs" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>jurnal1</obj_name>
  <obj_hashval>d07701c871855ada4554ad764ddc9506</obj_hashval>
  <obj_text>CREATE TABLE jurnal1 (
  "codjurnal1" numeric(20,0) NOT NULL,
  "coddoc" numeric(20,0),
  "tipdoc" numeric(20,0),
  "indexlocal" numeric(10,0),
  "codbazad" numeric(20,0),
  "tipbazad" numeric(5,0),
  "icontbazad" numeric(20,0),
  "coddescrd" numeric(20,0),
  "icontd" numeric(20,0),
  "tipcontd" numeric(5,0),
  "analiticcontd" character varying(10),
  "codbazac" numeric(20,0),
  "tipbazac" numeric(5,0),
  "icontbazac" numeric(20,0),
  "coddescrc" numeric(20,0),
  "icontc" numeric(20,0),
  "tipcontc" numeric(5,0),
  "analiticcontc" character varying(10),
  "gest" numeric(20,0),
  "valoare" numeric(20,7),
  "valoarev" numeric(20,7),
  "obs" character varying(200),
  "an" numeric(7,0),
  "luna" numeric(2,0),
  "dirty" numeric(1,0),
  "subunitatea" numeric(20,0),
  "datadoc" date,
  "document" character varying(100),
  "codcentru" numeric(20,0),
  "valoaregrup" numeric(20,7),
  "codanalizanod" numeric(20,0),
  "valoare_ifrs" numeric(20,7),
  "valoarev_ifrs" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>jurnals</obj_name>
  <obj_hashval>0cb8796592b09e91632f8072b1ab13de</obj_hashval>
  <obj_text>CREATE TABLE jurnals (
  "codjurnal" numeric(20,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(20,0),
  "indexlocal" numeric(20,0),
  "contd" numeric(20,0),
  "contc" numeric(20,0),
  "gest" numeric(20,0),
  "valoare" numeric(20,7),
  "valoarev" numeric(20,7),
  "obs" character varying(200),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "subunitatea" numeric(20,0),
  "datadoc" date,
  "document" character varying(35),
  "codcentru" numeric(20,0),
  "valoaregrup" numeric(20,7),
  "codanalizanod" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>jurnals1</obj_name>
  <obj_hashval>cebcfb783b23d005d7bbf19d668e292f</obj_hashval>
  <obj_text>CREATE TABLE jurnals1 (
  "codjurnal1" numeric(20,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(20,0),
  "indexlocal" numeric(10,0),
  "codbazad" numeric(20,0),
  "tipbazad" numeric(5,0),
  "icontbazad" numeric(5,0),
  "coddescrd" numeric(20,0),
  "icontd" numeric(20,0),
  "tipcontd" numeric(5,0),
  "analiticcontd" character varying(10),
  "codbazac" numeric(20,0),
  "tipbazac" numeric(5,0),
  "icontbazac" numeric(5,0),
  "coddescrc" numeric(20,0),
  "icontc" numeric(20,0),
  "tipcontc" numeric(5,0),
  "analiticcontc" character varying(10),
  "gest" numeric(20,0),
  "valoare" numeric(20,7),
  "valoarev" numeric(20,7),
  "obs" character varying(200),
  "an" numeric(7,0),
  "luna" numeric(2,0),
  "dirty" numeric(1,0),
  "subunitatea" numeric(20,0),
  "datadoc" date,
  "document" character varying(35),
  "codcentru" numeric(20,0),
  "valoaregrup" numeric(20,7),
  "codanalizanod" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>jurnetalon</obj_name>
  <obj_hashval>0748a6a5e331257d3cd9f0bcc0d0bb97</obj_hashval>
  <obj_text>CREATE TABLE jurnetalon (
  "codjurnal" numeric(20,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(20,0),
  "indexlocal" numeric(20,0),
  "contd" numeric(20,0),
  "contc" numeric(20,0),
  "gest" numeric(20,0),
  "valoare" numeric(20,7),
  "valoarev" numeric(20,7),
  "obs" character varying(200),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "subunitatea" numeric(20,0),
  "datadoc" date,
  "document" character varying(100),
  "codcentru" numeric(20,0),
  "valoaregrup" numeric(20,7),
  "codanalizanod" numeric(20,0),
  "valoare_ifrs" numeric(20,7),
  "valoarev_ifrs" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>jurnrefac</obj_name>
  <obj_hashval>458f16bb5f260445b2e6fbbbb63ab5bc</obj_hashval>
  <obj_text>CREATE TABLE jurnrefac (
  "userid" numeric(20,0),
  "anluna" numeric(20,0),
  "tip" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncontt1_al</obj_name>
  <obj_reftable>ncontt1</obj_reftable>
  <obj_hashval>c922e4fa87684a42c3d69c68ee272b74</obj_hashval>
  <obj_text>CREATE INDEX idx_ncontt1_al ON ncontt1 USING btree (codcontt, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ncontt1_codcontt</obj_name>
  <obj_reftable>ncontt1</obj_reftable>
  <obj_hashval>42a3f3a06454dd0475a945f645cf9458</obj_hashval>
  <obj_text>CREATE INDEX idx_ncontt1_codcontt ON ncontt1 USING btree (codcontt)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>lansare</obj_name>
  <obj_hashval>5c00cf857a97084f16c5e9d1ce8925a3</obj_hashval>
  <obj_text>CREATE TABLE lansare (
  "codlansare" numeric(20,0) NOT NULL,
  "codcmd1" numeric(20,0),
  "nrdoc" numeric(20,0),
  "carnetdoc" numeric(20,0),
  "datadoc" date,
  "cant" numeric(20,7),
  "codproiect" numeric(20,0),
  "subunitatea" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "anulat" numeric(1,0),
  "operat" numeric(1,0),
  "blocat" numeric(1,0),
  "automat" numeric(1,0),
  "codscenariu" numeric(20,0),
  "obs" character varying(450)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>lansare0</obj_name>
  <obj_hashval>dce4d0809e90e64422d58bf5f262326b</obj_hashval>
  <obj_text>CREATE TABLE lansare0 (
  "codlansare0" numeric(20,0) NOT NULL,
  "codlansare" numeric(20,0),
  "codcmd1" numeric(20,0),
  "cant" numeric(20,7),
  "codproiect" numeric(20,0),
  "codscenariu" numeric(20,0),
  "termen" date,
  "cantum1" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>lansare1</obj_name>
  <obj_hashval>4814e7272e9d254ca7924ac6b62d3b66</obj_hashval>
  <obj_text>CREATE TABLE lansare1 (
  "codlansare1" numeric(20,0) NOT NULL,
  "codlansare" numeric(20,0),
  "codproiectnod" numeric(20,0),
  "tip" numeric(1,0),
  "codcmd1" numeric(20,0),
  "cant" numeric(20,7),
  "codrezervats" numeric(20,0),
  "codlansare0" numeric(20,0),
  "obs" character varying(500),
  "nodparinte" numeric(20,0),
  "codcmd1p" numeric(20,0),
  "decalaj" numeric(10,0),
  "incepere" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>lansarenec</obj_name>
  <obj_hashval>1b7a4f2e322f08f698b7adb396e82364</obj_hashval>
  <obj_text>CREATE TABLE lansarenec (
  "codlansare0" numeric(20,0),
  "codproiectnod" numeric(20,0),
  "cant" numeric(20,7),
  "necesarp" numeric(20,7),
  "necesar" numeric(20,7),
  "rezolvat" numeric(20,7),
  "rezervat" numeric(20,7),
  "nesosit" numeric(20,7),
  "restrezervat" numeric(20,7),
  "restnesosit" numeric(20,7),
  "totrezervat" numeric(20,7),
  "totnesosit" numeric(20,7),
  "stoc" numeric(20,7),
  "cmdint" numeric(20,7),
  "diferente" numeric(20,7),
  "paritateechiv" numeric(20,7),
  "codobiect" numeric(20,0),
  "codlansare" numeric(20,0),
  "datastart" date
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>lansgest</obj_name>
  <obj_hashval>1d67f78270d3bc25d4459304d6f6ce96</obj_hashval>
  <obj_text>CREATE TABLE lansgest (
  "codlansgest" numeric(20,0) NOT NULL,
  "codlansprod" numeric(20,0),
  "codgest" numeric(20,0),
  "nrschimburi" numeric(5,0),
  "capacitate" numeric(10,0),
  "incarcare" numeric(10,0),
  "incarcarer" numeric(10,0),
  "den_gest" character varying(100),
  "simbol" character varying(15),
  "oreschimb" numeric(4,2)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>lansprod</obj_name>
  <obj_hashval>8403aaaa86b93be2a0c301af834b69d3</obj_hashval>
  <obj_text>CREATE TABLE lansprod (
  "codlansprod" numeric(20,0) NOT NULL,
  "saptamana" numeric(10,0),
  "subunitatea" numeric(20,0),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "userid" numeric(20,0),
  "datacreare" date,
  "anulat" numeric(1,0),
  "blocat" numeric(1,0),
  "operat" numeric(1,0),
  "obs" character varying(250),
  "dirty" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>lansprod1</obj_name>
  <obj_hashval>2d87deab030b4385c5558f8c94d925cb</obj_hashval>
  <obj_text>CREATE TABLE lansprod1 (
  "codlansprod1" numeric(20,0) NOT NULL,
  "codlansprod" numeric(20,0),
  "codobiect" numeric(20,0),
  "cantcomandat" numeric(20,7),
  "cantcomandatf" numeric(20,7),
  "stoc" numeric(20,7),
  "cantlansat" numeric(20,7),
  "stocestimat" numeric(20,7),
  "stocoptim" numeric(20,7),
  "cantcomandatn" numeric(20,7),
  "necesar" numeric(20,7),
  "obs" character varying(250),
  "necesart" numeric(20,7),
  "predari" numeric(20,7),
  "pret" numeric(20,7),
  "coefum" numeric(20,7),
  "valoare" numeric(20,7),
  "valoareacc" numeric(20,7),
  "codgest" numeric(20,0),
  "timpest" numeric(20,7),
  "restd" numeric(20,7),
  "exclus" numeric(1,0),
  "stocmax" numeric(20,7),
  "accprev" numeric(20,7),
  "avgspi" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>lansprod2</obj_name>
  <obj_hashval>b8321399f00e1627bdc68cecea19a2ef</obj_hashval>
  <obj_text>CREATE TABLE lansprod2 (
  "codlansprod2" numeric(20,0) NOT NULL,
  "codlansprod1" numeric(20,0),
  "codlansprod" numeric(20,0),
  "cant" numeric(20,7),
  "timp" numeric(20,7),
  "codgest" numeric(20,0),
  "codobiect" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>lansprod2s</obj_name>
  <obj_hashval>528e6d973795e0a7a9177b543de50ffb</obj_hashval>
  <obj_text>CREATE TABLE lansprod2s (
  "codlansprod2s" numeric(20,0) NOT NULL,
  "codlansprod1" numeric(20,0),
  "codlansprod" numeric(20,0),
  "codgest" numeric(20,0),
  "indexlocal" numeric(10,0),
  "timpest" numeric(20,7),
  "cant" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>lansz</obj_name>
  <obj_hashval>8d64b13aae8ddd7ca8b6a8a6c50ae59d</obj_hashval>
  <obj_text>CREATE TABLE lansz (
  "codlansz" numeric(20,0) NOT NULL,
  "codgest" numeric(20,0),
  "codplanifprod" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "subunitatea" numeric(20,0),
  "operat" numeric(1,0),
  "anulat" numeric(1,0),
  "blocat" numeric(1,0),
  "obs" character varying(250),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "saptamana" numeric(10,0),
  "dirty" numeric(1,0),
  "finalizat" numeric(1,0),
  "allgest" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>lansz1</obj_name>
  <obj_hashval>608b3869b35ab22da6e4c71b8848ea56</obj_hashval>
  <obj_text>CREATE TABLE lansz1 (
  "codlansz1" numeric(20,0) NOT NULL,
  "codlansz" numeric(20,0),
  "codformatie" numeric(20,0),
  "schimb" numeric(10,0),
  "codreteta" numeric(20,0),
  "codobiect" numeric(20,0),
  "luni" numeric(20,7),
  "marti" numeric(20,7),
  "miercuri" numeric(20,7),
  "joi" numeric(20,7),
  "vineri" numeric(20,7),
  "sambata" numeric(20,7),
  "duminica" numeric(20,7),
  "nextweek" numeric(20,7),
  "codplanifnod" numeric(20,0),
  "codcmd1_luni" numeric(20,0),
  "codcmd1_marti" numeric(20,0),
  "codcmd1_miercuri" numeric(20,0),
  "codcmd1_joi" numeric(20,0),
  "codcmd1_vineri" numeric(20,0),
  "codcmd1_sambata" numeric(20,0),
  "codcmd1_duminica" numeric(20,0),
  "total" numeric(20,7),
  "lastweek" numeric(20,7),
  "totaldelansat" numeric(20,7),
  "totallansat" numeric(20,7),
  "report" numeric(20,7),
  "refweek" numeric(20,7),
  "lans_luni" numeric(20,7),
  "lans_marti" numeric(20,7),
  "lans_miercuri" numeric(20,7),
  "lans_joi" numeric(20,7),
  "lans_vineri" numeric(20,7),
  "lans_sambata" numeric(20,7),
  "lans_duminica" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>lansz1_cmd</obj_name>
  <obj_hashval>1cae6ca7aff78a7592198a433fa1fc71</obj_hashval>
  <obj_text>CREATE TABLE lansz1_cmd (
  "codlansz1" numeric(20,0),
  "codcomanda1" numeric(20,0),
  "zi" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>lansz1_manevra</obj_name>
  <obj_hashval>ed5f9c9b3d9a3d2974c791b74187f4be</obj_hashval>
  <obj_text>CREATE TABLE lansz1_manevra (
  "codlansz1" numeric(20,0),
  "codlansz" numeric(20,0),
  "codformatie" numeric(20,0),
  "schimb" numeric(10,0),
  "codreteta" numeric(20,0),
  "codobiect" numeric(20,0),
  "luni" numeric(20,7),
  "marti" numeric(20,7),
  "miercuri" numeric(20,7),
  "joi" numeric(20,7),
  "vineri" numeric(20,7),
  "sambata" numeric(20,7),
  "duminica" numeric(20,7),
  "nextweek" numeric(20,7),
  "codplanifnod" numeric(20,0),
  "codcmd1_luni" numeric(20,0),
  "codcmd1_marti" numeric(20,0),
  "codcmd1_miercuri" numeric(20,0),
  "codcmd1_joi" numeric(20,0),
  "codcmd1_vineri" numeric(20,0),
  "codcmd1_sambata" numeric(20,0),
  "codcmd1_duminica" numeric(20,0),
  "total" numeric(20,7),
  "lastweek" numeric(20,7),
  "totaldelansat" numeric(20,7),
  "totallansat" numeric(20,7),
  "report" numeric(20,7),
  "refweek" numeric(20,7),
  "userid" numeric(20,0),
  "codgest" numeric(20,7),
  "codintern" character varying(80),
  "codextern" character varying(80),
  "obs1" character varying(250),
  "obs2" character varying(250),
  "obs3" character varying(250),
  "obs4" character varying(250),
  "obs5" character varying(250),
  "obs6" character varying(250),
  "gestimplicita" character varying(100),
  "gestreteta" character varying(100),
  "codnorma" numeric(20,0),
  "codprodcomp" numeric(20,0),
  "ordine" numeric(10,0),
  "den_claseas" character varying(50),
  "reteta" character varying(250),
  "den_claseprod" character varying(50),
  "denumire" character varying(200),
  "lans_luni" numeric(20,7),
  "lans_marti" numeric(20,7),
  "lans_miercuri" numeric(20,7),
  "lans_joi" numeric(20,7),
  "lans_vineri" numeric(20,7),
  "lans_sambata" numeric(20,7),
  "lans_duminica" numeric(20,7),
  "alte" numeric(20,7),
  "reportalte" numeric(20,7),
  "restdelansat" numeric(20,7),
  "dirty" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>lansz1_manevra1</obj_name>
  <obj_hashval>19e8607edac98ed750898818d8415cae</obj_hashval>
  <obj_text>CREATE TABLE lansz1_manevra1 (
  "codlansz1" numeric(20,0),
  "codlansz" numeric(20,0),
  "codformatie" numeric(20,0),
  "schimb" numeric(10,0),
  "codreteta" numeric(20,0),
  "codobiect" numeric(20,0),
  "luni" numeric(20,7),
  "marti" numeric(20,7),
  "miercuri" numeric(20,7),
  "joi" numeric(20,7),
  "vineri" numeric(20,7),
  "sambata" numeric(20,7),
  "duminica" numeric(20,7),
  "nextweek" numeric(20,7),
  "codplanifnod" numeric(20,0),
  "codcmd1_luni" numeric(20,0),
  "codcmd1_marti" numeric(20,0),
  "codcmd1_miercuri" numeric(20,0),
  "codcmd1_joi" numeric(20,0),
  "codcmd1_vineri" numeric(20,0),
  "codcmd1_sambata" numeric(20,0),
  "codcmd1_duminica" numeric(20,0),
  "total" numeric(20,7),
  "lastweek" numeric(20,7),
  "totaldelansat" numeric(20,7),
  "totallansat" numeric(20,7),
  "report" numeric(20,7),
  "refweek" numeric(20,7),
  "userid" numeric(20,0),
  "codgest" numeric(20,7),
  "codintern" character varying(80),
  "codextern" character varying(80),
  "obs1" character varying(250),
  "obs2" character varying(250),
  "obs3" character varying(250),
  "obs4" character varying(250),
  "obs5" character varying(250),
  "obs6" character varying(250),
  "gestimplicita" character varying(100),
  "gestreteta" character varying(100),
  "codnorma" numeric(20,0),
  "codprodcomp" numeric(20,0),
  "ordine" numeric(10,0),
  "den_claseas" character varying(50),
  "reteta" character varying(250),
  "den_claseprod" character varying(50),
  "denumire" character varying(200),
  "lans_luni" numeric(20,7),
  "lans_marti" numeric(20,7),
  "lans_miercuri" numeric(20,7),
  "lans_joi" numeric(20,7),
  "lans_vineri" numeric(20,7),
  "lans_sambata" numeric(20,7),
  "lans_duminica" numeric(20,7),
  "alte" numeric(20,7),
  "reportalte" numeric(20,7),
  "restdelansat" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>lansz1_manevra1_l</obj_name>
  <obj_hashval>165551e37cdc57147016c24eec88ddee</obj_hashval>
  <obj_text>CREATE TABLE lansz1_manevra1_l (
  "codlansz1" numeric(20,0),
  "codlansz" numeric(20,0),
  "codformatie" numeric(20,0),
  "schimb" numeric(10,0),
  "codreteta" numeric(20,0),
  "codobiect" numeric(20,0),
  "luni" numeric(20,7),
  "marti" numeric(20,7),
  "miercuri" numeric(20,7),
  "joi" numeric(20,7),
  "vineri" numeric(20,7),
  "sambata" numeric(20,7),
  "duminica" numeric(20,7),
  "nextweek" numeric(20,7),
  "codplanifnod" numeric(20,0),
  "codcmd1_luni" numeric(20,0),
  "codcmd1_marti" numeric(20,0),
  "codcmd1_miercuri" numeric(20,0),
  "codcmd1_joi" numeric(20,0),
  "codcmd1_vineri" numeric(20,0),
  "codcmd1_sambata" numeric(20,0),
  "codcmd1_duminica" numeric(20,0),
  "total" numeric(20,7),
  "lastweek" numeric(20,7),
  "totaldelansat" numeric(20,7),
  "totallansat" numeric(20,7),
  "report" numeric(20,7),
  "refweek" numeric(20,7),
  "userid" numeric(20,0),
  "codgest" numeric(20,7),
  "codintern" character varying(80),
  "codextern" character varying(80),
  "obs1" character varying(250),
  "obs2" character varying(250),
  "obs3" character varying(250),
  "obs4" character varying(250),
  "obs5" character varying(250),
  "obs6" character varying(250),
  "gestimplicita" character varying(100),
  "gestreteta" character varying(100),
  "codnorma" numeric(20,0),
  "codprodcomp" numeric(20,0),
  "ordine" numeric(10,0),
  "den_claseas" character varying(50),
  "reteta" character varying(250),
  "den_claseprod" character varying(50),
  "denumire" character varying(200),
  "lans_luni" numeric(20,7),
  "lans_marti" numeric(20,7),
  "lans_miercuri" numeric(20,7),
  "lans_joi" numeric(20,7),
  "lans_vineri" numeric(20,7),
  "lans_sambata" numeric(20,7),
  "lans_duminica" numeric(20,7),
  "alte" numeric(20,7),
  "reportalte" numeric(20,7),
  "restdelansat" numeric(20,7),
  "dirty" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>lansz1_manevra_l</obj_name>
  <obj_hashval>da463e1bc5af1ba42772af4cfae8dbf9</obj_hashval>
  <obj_text>CREATE TABLE lansz1_manevra_l (
  "codlansz1" numeric(20,0),
  "codlansz" numeric(20,0),
  "codformatie" numeric(20,0),
  "schimb" numeric(10,0),
  "codreteta" numeric(20,0),
  "codobiect" numeric(20,0),
  "luni" numeric(20,7),
  "marti" numeric(20,7),
  "miercuri" numeric(20,7),
  "joi" numeric(20,7),
  "vineri" numeric(20,7),
  "sambata" numeric(20,7),
  "duminica" numeric(20,7),
  "nextweek" numeric(20,7),
  "codplanifnod" numeric(20,0),
  "codcmd1_luni" numeric(20,0),
  "codcmd1_marti" numeric(20,0),
  "codcmd1_miercuri" numeric(20,0),
  "codcmd1_joi" numeric(20,0),
  "codcmd1_vineri" numeric(20,0),
  "codcmd1_sambata" numeric(20,0),
  "codcmd1_duminica" numeric(20,0),
  "total" numeric(20,7),
  "lastweek" numeric(20,7),
  "totaldelansat" numeric(20,7),
  "totallansat" numeric(20,7),
  "report" numeric(20,7),
  "refweek" numeric(20,7),
  "userid" numeric(20,0),
  "codgest" numeric(20,7),
  "codintern" character varying(80),
  "codextern" character varying(80),
  "obs1" character varying(250),
  "obs2" character varying(250),
  "obs3" character varying(250),
  "obs4" character varying(250),
  "obs5" character varying(250),
  "obs6" character varying(250),
  "gestimplicita" character varying(100),
  "gestreteta" character varying(100),
  "codnorma" numeric(20,0),
  "codprodcomp" numeric(20,0),
  "ordine" numeric(10,0),
  "den_claseas" character varying(50),
  "reteta" character varying(250),
  "den_claseprod" character varying(50),
  "denumire" character varying(200),
  "lans_luni" numeric(20,7),
  "lans_marti" numeric(20,7),
  "lans_miercuri" numeric(20,7),
  "lans_joi" numeric(20,7),
  "lans_vineri" numeric(20,7),
  "lans_sambata" numeric(20,7),
  "lans_duminica" numeric(20,7),
  "alte" numeric(20,7),
  "reportalte" numeric(20,7),
  "restdelansat" numeric(20,7),
  "dirty" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>listcols</obj_name>
  <obj_hashval>6fdbd72a463ad0bd490419b62f9e2d78</obj_hashval>
  <obj_text>CREATE TABLE listcols (
  "codlistcols" numeric(20,0),
  "listid" numeric(20,0),
  "listver" numeric(20,0),
  "codjob1" numeric(20,0),
  "fieldname" character varying(50),
  "fieldtype" numeric(2,0),
  "fieldsize" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>livr</obj_name>
  <obj_hashval>dbcfe3076d107ec23f291b42d0bfb36f</obj_hashval>
  <obj_text>CREATE TABLE livr (
  "codlivr" numeric(20,0) NOT NULL,
  "codies" numeric(20,0),
  "codintr" numeric(20,0),
  "codtransf" numeric(20,0),
  "carnetlivr" numeric(20,0),
  "nrlivr" numeric(20,0),
  "datalivr" date,
  "obs" character varying(100),
  "tiplivr" numeric(2,0),
  "anulat" numeric(1,0),
  "blocat" numeric(1,0),
  "operat" numeric(1,0),
  "exportat" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>livr1</obj_name>
  <obj_hashval>9179568aa1d4e547e26ae485f8979607</obj_hashval>
  <obj_text>CREATE TABLE livr1 (
  "codlivr1" numeric(20,0) NOT NULL,
  "codlivr" numeric(20,0),
  "codies1" numeric(20,0),
  "codintr1" numeric(20,0),
  "coddvi1" numeric(20,0),
  "codnirstoc" numeric(20,0),
  "cant" numeric(30,17),
  "codnirser" numeric(20,0),
  "pmp" numeric(20,7),
  "umsec" numeric(20,0),
  "cantum1" numeric(20,7),
  "cantum2" numeric(20,7),
  "restiesval" numeric(20,7),
  "cantrezervat" numeric(30,17),
  "codcertif" numeric(20,0),
  "codprodcomp" numeric(20,0),
  "pmpvaluta" numeric(20,7),
  "pmpdoc" numeric(20,7),
  "pmpvalutadoc" numeric(20,7),
  "contintermed" numeric(20,0),
  "codproiect" numeric(20,0),
  "codgestorig" numeric(20,0),
  "blocatum1" numeric(1,0),
  "codlivr1parinte" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>livrval</obj_name>
  <obj_hashval>cf0df0bb4572ab59a04c263081617722</obj_hashval>
  <obj_text>CREATE TABLE livrval (
  "codlivrval" numeric(20,0) NOT NULL,
  "codlivr1" numeric(20,0),
  "codobiect" numeric(20,0),
  "codioart" numeric(20,0),
  "gest" numeric(20,0),
  "pretinreg" numeric(20,7),
  "pretachiz" numeric(20,7),
  "tvaneex" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>lockpostretail</obj_name>
  <obj_hashval>5e2d8314467f98369fe4e18c77c2577d</obj_hashval>
  <obj_text>CREATE TABLE lockpostretail (
  "userid" numeric(20,0),
  "codpostretail" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>locmunca</obj_name>
  <obj_hashval>10fb9adeab40a967107a1ebaa70eceac</obj_hashval>
  <obj_text>CREATE TABLE locmunca (
  "codloc" numeric(20,0) NOT NULL,
  "simbol" character varying(10),
  "denumire" character varying(250),
  "tip" numeric(1,0),
  "dsv" numeric(10,0),
  "activi" numeric(10,0),
  "special" numeric(1,0),
  "codlocdef" numeric(20,0),
  "minuteon" numeric(4,0),
  "minuteoff" numeric(4,0),
  "fara_gant" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>locmunca1</obj_name>
  <obj_hashval>bd57b122fb6f16360c1d8b6f2ac26282</obj_hashval>
  <obj_text>CREATE TABLE locmunca1 (
  "codloc1" numeric(20,0) NOT NULL,
  "codloc" numeric(20,0),
  "codmifix" numeric(20,0),
  "ore" numeric(10,7),
  "codutilaj" numeric(20,0),
  "codgest" numeric(20,0),
  "codlocatie" numeric(20,0),
  "nickname" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>locmunca2</obj_name>
  <obj_hashval>ed8d02af917525e8fa375f4953e1a8bf</obj_hashval>
  <obj_text>CREATE TABLE locmunca2 (
  "codloc2" numeric(20,0) NOT NULL,
  "codloc1" numeric(20,0),
  "codloc" numeric(20,0),
  "codloc1asoc" numeric(20,0),
  "orestart" numeric(7,3),
  "datastart" date,
  "orestop" numeric(7,3),
  "datastop" date,
  "minuneon" numeric(4,0),
  "minuneoff" numeric(4,0),
  "oreactiv" numeric(7,3)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>locurimuncaobs</obj_name>
  <obj_hashval>56b539b460fbfd6efa141bbc49d25b57</obj_hashval>
  <obj_text>CREATE TABLE locurimuncaobs (
  "idobs" numeric(20,0),
  "codprogramf1" numeric(20,0),
  "codlocmunca" numeric(20,0),
  "obs" character varying(3000)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>logimportdoc</obj_name>
  <obj_hashval>8fecc1f765115cbf8a7b8c938380974a</obj_hashval>
  <obj_text>CREATE TABLE logimportdoc (
  "cod" numeric(20,0),
  "tipdoc" numeric(5,0),
  "idimport" character varying(30),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "dataimport" timestamp(6) without time zone,
  "codpart" numeric(20,0),
  "codobiect" numeric(20,0),
  "tipoperatie" character varying(1),
  "cantvechi" numeric(20,7),
  "cantnou" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>logusertab</obj_name>
  <obj_hashval>4878a88fbf16b7fbfdeab2a896d18e64</obj_hashval>
  <obj_text>CREATE TABLE logusertab (
  "numeuser" character varying(50) NOT NULL,
  "ancurent" numeric(4,0),
  "lunacurenta" numeric(2,0),
  "aninitial" numeric(4,0),
  "lunainitiala" numeric(2,0),
  "anmaxim" numeric(4,0),
  "lunamaxima" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>luna_records_flags</obj_name>
  <obj_hashval>92c2988d6fbd502f07f353efe35400b2</obj_hashval>
  <obj_text>CREATE TABLE luna_records_flags (
  "userid" numeric(20,0),
  "nart_flg" numeric(1,0),
  "nartobj_flg" numeric(1,0),
  "ioart_flg" numeric(1,0),
  "ntva_flg" numeric(1,0),
  "ntaxe_flg" numeric(1,0),
  "iopart_flg" numeric(1,0),
  "iopers_flg" numeric(1,0),
  "tarife_flg" numeric(1,0),
  "pretm_flg" numeric(1,0),
  "iofilial_flg" numeric(1,0),
  "iobank_flg" numeric(1,0),
  "nart_flg_conta" numeric(1,0),
  "nartobj_flg_conta" numeric(1,0),
  "ioart_flg_conta" numeric(1,0),
  "ntva_flg_conta" numeric(1,0),
  "ntaxe_flg_conta" numeric(1,0),
  "iopart_flg_conta" numeric(1,0),
  "iopers_flg_conta" numeric(1,0),
  "iofilial_flg_conta" numeric(1,0),
  "iobank_flg_conta" numeric(1,0),
  "ngest1_flg_conta" numeric(1,0),
  "npart1_flg_conta" numeric(1,0),
  "npers1_flg_conta" numeric(1,0),
  "nbank1_flg_conta" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>machete</obj_name>
  <obj_hashval>8c7a72182723e977fdd8ff04d5f125e4</obj_hashval>
  <obj_text>CREATE TABLE machete (
  "codmacheta" numeric(20,0),
  "prefix" character varying(3),
  "numepresc" character varying(15),
  "numeext" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>mailuri</obj_name>
  <obj_hashval>76f85fbc213c347145677aabf6d8e36d</obj_hashval>
  <obj_text>CREATE TABLE mailuri (
  "codmail" numeric(20,0) NOT NULL,
  "sender" character varying(200),
  "recipients" character varying(500),
  "subject" character varying(200),
  "message" character varying(3000),
  "userid" numeric(20,0),
  "data" date,
  "status" numeric(1,0),
  "eroare" character varying(3000),
  "host" character varying(200),
  "port" numeric(20,0),
  "domain" character varying(200),
  "codfirma" numeric(20,0),
  "codserver" numeric(20,0),
  "msg" text,
  "coddoc1" numeric(20,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(10,0),
  "webserver" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>mailuri1</obj_name>
  <obj_hashval>b29fd56550d17fa2a3a990e427bdcc68</obj_hashval>
  <obj_text>CREATE TABLE mailuri1 (
  "codmail1" numeric(20,0) NOT NULL,
  "codmail" numeric(20,0),
  "filename" character varying(100),
  "attachfile" bytea
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>mailuridocs</obj_name>
  <obj_hashval>d1c980fb76daa299489561264958cfaa</obj_hashval>
  <obj_text>CREATE TABLE mailuridocs (
  "codmaildoc" numeric(20,0) NOT NULL,
  "codmail" numeric(20,0),
  "coddoc1" numeric(20,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(10,0),
  "codagenda" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>man_alerte</obj_name>
  <obj_hashval>c942028a943a39e077bceaf52aba1f0e</obj_hashval>
  <obj_text>CREATE TABLE man_alerte (
  "userid" numeric(20,0),
  "mesaj" character varying(3200),
  "ordine" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>man_jurnal</obj_name>
  <obj_hashval>ef53bdb746b0ec232b0a25a9e80f15ec</obj_hashval>
  <obj_text>CREATE TABLE man_jurnal (
  "codjurnal" numeric(20,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(20,0),
  "indexlocal" numeric(20,0),
  "contd" numeric(20,0),
  "contc" numeric(20,0),
  "gest" numeric(20,0),
  "valoare" numeric(20,7),
  "valoarev" numeric(20,7),
  "obs" character varying(200),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "subunitatea" numeric(20,0),
  "datadoc" date,
  "document" character varying(30),
  "codcentru" numeric(20,0),
  "valoaregrup" numeric(20,7),
  "codanalizanod" numeric(20,0),
  "valoare_ifrs" numeric(20,7),
  "valoarev_ifrs" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>man_jurnal1</obj_name>
  <obj_hashval>4e92ef5817c226a444cb84218628704e</obj_hashval>
  <obj_text>CREATE TABLE man_jurnal1 (
  "codjurnal1" numeric(20,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(20,0),
  "indexlocal" numeric(10,0),
  "codbazad" numeric(20,0),
  "tipbazad" numeric(5,0),
  "icontbazad" numeric(20,0),
  "coddescrd" numeric(20,0),
  "icontd" numeric(20,0),
  "tipcontd" numeric(5,0),
  "analiticcontd" character varying(10),
  "codbazac" numeric(20,0),
  "tipbazac" numeric(5,0),
  "icontbazac" numeric(20,0),
  "coddescrc" numeric(20,0),
  "icontc" numeric(20,0),
  "tipcontc" numeric(5,0),
  "analiticcontc" character varying(10),
  "gest" numeric(20,0),
  "valoare" numeric(20,7),
  "valoarev" numeric(20,7),
  "obs" character varying(200),
  "an" numeric(7,0),
  "luna" numeric(2,0),
  "dirty" numeric(1,0),
  "subunitatea" numeric(20,0),
  "datadoc" date,
  "document" character varying(30),
  "codcentru" numeric(20,0),
  "valoaregrup" numeric(20,7),
  "codanalizanod" numeric(20,0),
  "valoare_ifrs" numeric(20,7),
  "valoarev_ifrs" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>manevra_consum</obj_name>
  <obj_hashval>ef9642b54ce738536e1613b79ab2b3fb</obj_hashval>
  <obj_text>CREATE TABLE manevra_consum (
  "codobiect" numeric(20,0),
  "valoare" numeric(20,7),
  "cant" numeric(20,7),
  "valret" numeric(20,7),
  "cantret" numeric(20,7),
  "nodparinte" numeric(20,0),
  "produs" numeric(20,0),
  "cant_prod" numeric(20,7),
  "s_idx" character varying(1000)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>manevra_notecredit</obj_name>
  <obj_hashval>b337103e21c59b7516030d946275a20c</obj_hashval>
  <obj_text>CREATE TABLE manevra_notecredit (
  "codobiect" numeric(20,0),
  "codcontract1" numeric(20,0),
  "valoare" numeric(20,7),
  "userid" numeric(20,0),
  "codncredit" numeric(20,0),
  "valoare_b" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>manevra_preturi</obj_name>
  <obj_hashval>cf7910f85769f95614e5f3da12be9d35</obj_hashval>
  <obj_text>CREATE TABLE manevra_preturi (
  "codobiect" numeric(20,0),
  "pret" numeric(20,7),
  "stare" numeric(1,0),
  "codarticol" numeric(20,0),
  "codatribut" numeric(20,0),
  "codobiectekiv" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>manevra_preturi_d</obj_name>
  <obj_hashval>1ffffa8ee1d11b98529c72e12b6a4a34</obj_hashval>
  <obj_text>CREATE TABLE manevra_preturi_d (
  "codobiect" numeric(20,0),
  "pret" numeric(20,7),
  "codnirstoc" numeric(20,7),
  "stare" numeric(1,0),
  "ordine" numeric(10,0),
  "cant" numeric(20,7),
  "dataachiz" date,
  "codarticol" numeric(20,0),
  "codatribut" numeric(20,0),
  "codobiectgeneric" numeric(20,0),
  "obj_codextern" character varying(80),
  "obj_codintern" character varying(80)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>manevra_preturi_d_p</obj_name>
  <obj_hashval>73c713e5abb70738da1c40676ab7dcd6</obj_hashval>
  <obj_text>CREATE TABLE manevra_preturi_d_p (
  "codobiect" numeric(20,0),
  "pret" numeric(20,7),
  "codnirstoc" numeric(20,7),
  "stare" numeric(1,0),
  "ordine" numeric(10,0),
  "cant" numeric(20,7),
  "dataachiz" date,
  "codarticol" numeric(20,0),
  "codatribut" numeric(20,0),
  "codobiectgeneric" numeric(20,0),
  "obj_codextern" character varying(80),
  "obj_codintern" character varying(80)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>manevra_preturi_p</obj_name>
  <obj_hashval>8e74f50befa139c0ccb0a2dac45c88b3</obj_hashval>
  <obj_text>CREATE TABLE manevra_preturi_p (
  "codobiect" numeric(20,0),
  "pret" numeric(20,7),
  "stare" numeric(1,0),
  "codarticol" numeric(20,0),
  "codatribut" numeric(20,0),
  "codobiectekiv" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>manevra_prodcomp_clona</obj_name>
  <obj_hashval>0e1bfac416cc910605bda594a5412c2f</obj_hashval>
  <obj_text>CREATE TABLE manevra_prodcomp_clona (
  "codprodcomp" numeric(20,0),
  "codobiect" numeric(20,0),
  "pret_v" numeric(20,7),
  "pret_n" numeric(20,7),
  "valmat" numeric(20,7),
  "valman" numeric(20,7),
  "valregie" numeric(20,7),
  "valregieman" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>manevra_prodcomp_clona_p</obj_name>
  <obj_hashval>6079dd810bce596f670ecced9b6051dc</obj_hashval>
  <obj_text>CREATE TABLE manevra_prodcomp_clona_p (
  "codprodcomp" numeric(20,0),
  "codobiect" numeric(20,0),
  "pret_v" numeric(20,7),
  "pret_n" numeric(20,7),
  "valmat" numeric(20,7),
  "valman" numeric(20,7),
  "valregie" numeric(20,7),
  "valregieman" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>manevra_prodman_clona</obj_name>
  <obj_hashval>04e9eb54770ec9e653d91e27bc7c41e5</obj_hashval>
  <obj_text>CREATE TABLE manevra_prodman_clona (
  "codman" numeric(20,0),
  "codprodcomp" numeric(20,0),
  "valoare_v" numeric(20,7),
  "valoare_n" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>manevra_prodman_clona_p</obj_name>
  <obj_hashval>86fa5c714aece2352becb203ee3b045d</obj_hashval>
  <obj_text>CREATE TABLE manevra_prodman_clona_p (
  "codman" numeric(20,0),
  "codprodcomp" numeric(20,0),
  "valoare_v" numeric(20,7),
  "valoare_n" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>manevra_prodmat_clona</obj_name>
  <obj_hashval>ffc0bebb0666d1cf846daf7c567f5be4</obj_hashval>
  <obj_text>CREATE TABLE manevra_prodmat_clona (
  "codmat" numeric(20,0),
  "codprodcomp" numeric(20,0),
  "codobiect" numeric(20,0),
  "pret_v" numeric(20,7),
  "pret_n" numeric(20,7),
  "valmat" numeric(20,7),
  "valman" numeric(20,7),
  "valregie" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>manevra_prodmat_clona_p</obj_name>
  <obj_hashval>27713d2bafd1afc7c106f8fb229db4ff</obj_hashval>
  <obj_text>CREATE TABLE manevra_prodmat_clona_p (
  "codmat" numeric(20,0),
  "codprodcomp" numeric(20,0),
  "codobiect" numeric(20,0),
  "pret_v" numeric(20,7),
  "pret_n" numeric(20,7),
  "valmat" numeric(20,7),
  "valman" numeric(20,7),
  "valregie" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>manevra_unic</obj_name>
  <obj_hashval>66a94a23cb3e4ce1489d9cd1842dd312</obj_hashval>
  <obj_text>CREATE TABLE manevra_unic (
  "codunic" numeric(20,0),
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>manprodlink</obj_name>
  <obj_hashval>6e44a71f0c7c2d6fa5515591ec3150fb</obj_hashval>
  <obj_text>CREATE TABLE manprodlink (
  "codraportp2" numeric(20,0) NOT NULL,
  "codcmdprodman" numeric(20,0),
  "cant" numeric(20,7),
  "codprogramf1" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>marcalock</obj_name>
  <obj_hashval>337475c0cd575c5f5f886313be2b6f4a</obj_hashval>
  <obj_text>CREATE TABLE marcalock (
  "cod" numeric(20,0),
  "marca" numeric(20,0),
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>mascaserart</obj_name>
  <obj_hashval>b61156aba2588aa20a2e74895ed62f37</obj_hashval>
  <obj_text>CREATE TABLE mascaserart (
  "codmasca" numeric(20,0) NOT NULL,
  "masca" character varying(500)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>mascaserart1</obj_name>
  <obj_hashval>6b65d80efe9e16f4355ceb0f80376504</obj_hashval>
  <obj_text>CREATE TABLE mascaserart1 (
  "codmasca1" numeric(20,0) NOT NULL,
  "codmasca" numeric(20,0),
  "denelement" character varying(100),
  "valori" character varying(100),
  "element" character varying(10),
  "lungime" numeric(10,0),
  "fill" character varying(10)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>mastercheltavans</obj_name>
  <obj_hashval>a035153bd849ff4d0efde1eb70d412a5</obj_hashval>
  <obj_text>CREATE TABLE mastercheltavans (
  "codintr1" numeric(20,0),
  "codobligpif" numeric(20,0),
  "codnc1" numeric(20,0),
  "codies1" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>mastermak</obj_name>
  <obj_hashval>a9994d7bbf71abdcd5f24c13f55b2b62</obj_hashval>
  <obj_text>CREATE TABLE mastermak (
  "codmastermak" numeric(20,0) NOT NULL,
  "coddoc" numeric(20,0),
  "tipdoc" numeric(6,0),
  "cod1" numeric(20,0),
  "cod2" numeric(20,0),
  "cod3" numeric(20,0),
  "cod4" numeric(20,0),
  "cod5" numeric(20,0),
  "v1" numeric(20,7),
  "v2" numeric(20,7),
  "v3" numeric(20,7),
  "v4" numeric(20,7),
  "v5" numeric(20,7),
  "data1" date,
  "data2" date,
  "obs1" character varying(50),
  "obs2" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>mastermifix</obj_name>
  <obj_hashval>31461f70fb910be8fdc1046cbd4dd021</obj_hashval>
  <obj_text>CREATE TABLE mastermifix (
  "codnirstoc" numeric(20,0),
  "codclasif" numeric(20,0),
  "duratan" numeric(10,0),
  "duratanf" numeric(10,0),
  "duratang" numeric(10,0),
  "codanaliza" numeric(20,0),
  "codclasifblocat" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>medex1</obj_name>
  <obj_hashval>5750f7ecf78a46f626fefe18e2249778</obj_hashval>
  <obj_text>CREATE TABLE medex1 (
  "codmedex1" numeric(20,0) NOT NULL,
  "codmedex" numeric(20,0),
  "codcim" character varying(20),
  "denumire" character varying(500),
  "prezentare" character varying(500),
  "narcotic" numeric(1,0),
  "fractional" numeric(1,0),
  "special" numeric(1,0),
  "arebioechivalent" numeric(1,0),
  "cant" numeric(10,0),
  "pretam" numeric(20,7),
  "pretrid" numeric(20,7),
  "prescriere" character varying(100),
  "validdela" date,
  "validpanala" date,
  "dci" character varying(250),
  "conc" character varying(250),
  "formafarm" character varying(500),
  "producator" character varying(250),
  "tara" character varying(50),
  "grupa" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>medex2</obj_name>
  <obj_hashval>4a2a90b5a2146ff2ed09bc5517b2f57a</obj_hashval>
  <obj_text>CREATE TABLE medex2 (
  "codmedex2" numeric(20,0) NOT NULL,
  "codmedex" numeric(20,0),
  "tipcompens" character varying(10),
  "codcim" character varying(20),
  "codboala" character varying(10),
  "pretam" numeric(20,7),
  "pretamut" numeric(20,7),
  "coplata" numeric(20,7),
  "coplata90" numeric(20,7),
  "pretrid" numeric(20,7),
  "pretref" numeric(20,7),
  "legispeciale" numeric(1,0),
  "aprobare" character varying(10),
  "valpeste" numeric(20,7),
  "specialitate" numeric(1,0),
  "insulina" character varying(10),
  "dci" character varying(250),
  "grupa" character varying(50),
  "validdela" date,
  "validpanala" date,
  "nhpcode" character varying(20)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>medex_tari</obj_name>
  <obj_hashval>443fd298eb9324d62e64a25291ed4e5b</obj_hashval>
  <obj_text>CREATE TABLE medex_tari (
  "codmedext" numeric(20,0) NOT NULL,
  "codmedex" numeric(20,0),
  "cod" character varying(50),
  "tara" character varying(250)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>menudash</obj_name>
  <obj_hashval>641c377bfd8df814f9ae1018b8641a70</obj_hashval>
  <obj_text>CREATE TABLE menudash (
  "codmenudash" numeric(20,0) NOT NULL,
  "caption" character varying(250),
  "modul" numeric(2,0),
  "menu" numeric(2,0),
  "prog" numeric(2,0),
  "uni" numeric(1,0),
  "listid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>menudash0</obj_name>
  <obj_hashval>3c77eb518694ebfa5390bb689e056f89</obj_hashval>
  <obj_text>CREATE TABLE menudash0 (
  "codmenudash0" numeric(20,0) NOT NULL,
  "codmenudash" numeric(20,0),
  "autoshow" numeric(2,0),
  "userid" numeric(20,0),
  "config" bytea
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>menudash1</obj_name>
  <obj_hashval>09b9ef6727d80871d5f7fd9e3473541b</obj_hashval>
  <obj_text>CREATE TABLE menudash1 (
  "codmenudash1" numeric(20,0) NOT NULL,
  "codmenudash" numeric(20,0),
  "codjob1" numeric(20,0),
  "lunastart" numeric(2,0),
  "anstart" numeric(4,0),
  "nume" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>menudate</obj_name>
  <obj_hashval>041d94582d89c2179645977aa53060cd</obj_hashval>
  <obj_text>CREATE TABLE menudate (
  "codmenudate" numeric(20,0) NOT NULL,
  "den_menu" character varying(100),
  "userid" character varying(20),
  "nrbuton" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>menudate1</obj_name>
  <obj_hashval>74c4d4add12279010244a5d74465072b</obj_hashval>
  <obj_text>CREATE TABLE menudate1 (
  "codmenudate1" numeric(20,0) NOT NULL,
  "codmenudate" numeric(20,0),
  "den_menu" character varying(100),
  "action" character varying(100),
  "indexlocal" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>menuliste1</obj_name>
  <obj_hashval>b73498e465efff3b2c1bc6a38ea5df0b</obj_hashval>
  <obj_text>CREATE TABLE menuliste1 (
  "codmenu1" numeric(20,0) NOT NULL,
  "codmenu" numeric(20,0),
  "codjob1" numeric(20,0),
  "lunastart" numeric(2,0),
  "anstart" numeric(4,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>mesaje</obj_name>
  <obj_hashval>f3bccce733b957457aab23d1ff885ad0</obj_hashval>
  <obj_text>CREATE TABLE mesaje (
  "idmesaj" numeric(20,0),
  "text" character varying(3000),
  "usern" character varying(100),
  "tip_mesaj" numeric(3,0),
  "data" timestamp(6) without time zone
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>mese</obj_name>
  <obj_hashval>65611390f0bdadb975aeefe36f02fd79</obj_hashval>
  <obj_text>CREATE TABLE mese (
  "codmasa" numeric(20,0) NOT NULL,
  "codsala" numeric(20,0),
  "indexlocal" numeric(5,0),
  "stare" numeric(5,0),
  "x" numeric(10,0),
  "y" numeric(10,0),
  "width" numeric(10,0),
  "height" numeric(10,0),
  "numarlocuri" numeric(10,0),
  "textafisare" character varying(100),
  "forma" numeric(1,0),
  "blocata" numeric(1,0),
  "userid" numeric(20,0),
  "codospatar" numeric(20,0),
  "modplataimplicit" numeric(3,0),
  "protocol" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>mese1</obj_name>
  <obj_hashval>b714edb308931dd053dd900c28104f13</obj_hashval>
  <obj_text>CREATE TABLE mese1 (
  "codmasa1" numeric(20,0) NOT NULL,
  "codmasa" numeric(20,0),
  "codospatar" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>mfclasif</obj_name>
  <obj_hashval>f8996394c014450309506518bf48c769</obj_hashval>
  <obj_text>CREATE TABLE mfclasif (
  "codclasif" numeric(20,0) NOT NULL,
  "denumire" character varying(1200),
  "simbol" character varying(20),
  "durata" numeric(6,0),
  "durataf" numeric(6,0),
  "duratag" numeric(6,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>mifix</obj_name>
  <obj_hashval>0f160cd98ca9ba51e71f6314ac2e2d39</obj_hashval>
  <obj_text>CREATE TABLE mifix (
  "codmifix" numeric(20,0) NOT NULL,
  "tip" character varying(2),
  "nrinventar" numeric(20,0),
  "anintrare" numeric(4,0),
  "lunaintrare" numeric(2,0),
  "obs" character varying(30),
  "anintrareg" numeric(4,0),
  "lunaintrareg" numeric(2,0),
  "serieinv" character varying(30),
  "codmifiximb" numeric(20,0),
  "restimbmf" numeric(20,7),
  "anstopdegresiv" numeric(4,0),
  "lunastopdegresiv" numeric(2,0),
  "codmifixnou" numeric(20,0),
  "anlunamifixnou" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ndelegatretail_codparttr</obj_name>
  <obj_reftable>ndelegatretail</obj_reftable>
  <obj_hashval>4872cc829b510774717ecbe36af722ec</obj_hashval>
  <obj_text>CREATE INDEX idx_ndelegatretail_codparttr ON ndelegatretail USING btree (codparttr)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nec5_codobiect</obj_name>
  <obj_reftable>necesar5</obj_reftable>
  <obj_hashval>af6fb82d387884b77fad576eb94d9e32</obj_hashval>
  <obj_text>CREATE INDEX idx_nec5_codobiect ON necesar5 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nec5_nrindicator</obj_name>
  <obj_reftable>necesar5</obj_reftable>
  <obj_hashval>f890d89f03042e37358f75c6cad9acd4</obj_hashval>
  <obj_text>CREATE INDEX idx_nec5_nrindicator ON necesar5 USING btree (nrindicator)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nec5_ordine</obj_name>
  <obj_reftable>necesar5</obj_reftable>
  <obj_hashval>5f9ee2fe08496f98dfb936404d702395</obj_hashval>
  <obj_text>CREATE INDEX idx_nec5_ordine ON necesar5 USING btree (ordine)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nec5_userid</obj_name>
  <obj_reftable>necesar5</obj_reftable>
  <obj_hashval>b50b0e2b49ed136a05359a715594e041</obj_hashval>
  <obj_text>CREATE INDEX idx_nec5_userid ON necesar5 USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_necesarcmd_codcomanda1</obj_name>
  <obj_reftable>necesarcmd</obj_reftable>
  <obj_hashval>03144d908c6024e8eaa1bc520ab09c6a</obj_hashval>
  <obj_text>CREATE INDEX idx_necesarcmd_codcomanda1 ON necesarcmd USING btree (codcomanda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_necesarcmd_codnecesar</obj_name>
  <obj_reftable>necesarcmd</obj_reftable>
  <obj_hashval>6bdf14bb3a96eb1a5815ed5b53e4cf55</obj_hashval>
  <obj_text>CREATE INDEX idx_necesarcmd_codnecesar ON necesarcmd USING btree (codnecesar)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>mifix1</obj_name>
  <obj_hashval>e71af44b967db4f053d3a16674d76615</obj_hashval>
  <obj_text>CREATE TABLE mifix1 (
  "codmifix1" numeric(20,0) NOT NULL,
  "codmifix" numeric(20,0),
  "codnirstoc" numeric(20,0),
  "pret" numeric(20,7),
  "cant" numeric(20,7),
  "codclasif" numeric(20,0),
  "tipamo" numeric(3,0),
  "stare" numeric(3,0),
  "duratan" numeric(10,0),
  "gradu" numeric(8,4),
  "durataf" numeric(10,0),
  "amo" numeric(20,7),
  "neutil" numeric(20,7),
  "dfblocat" numeric(1,0),
  "codpers" numeric(20,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "codnirser" numeric(20,0),
  "tipreeval" numeric(1,0),
  "datareeval" date,
  "includrata" numeric(1,0),
  "amovechi" numeric(20,7),
  "pretvechi" numeric(20,7),
  "neutilvechi" numeric(20,7),
  "codpart" numeric(20,0),
  "codlocatie" numeric(20,0),
  "codanalizanod" numeric(20,0),
  "codcentru" numeric(20,0),
  "duratanf" numeric(10,0),
  "durataff" numeric(10,0),
  "amof" numeric(20,7),
  "duratang" numeric(10,0),
  "duratafg" numeric(10,0),
  "amog" numeric(20,7),
  "dfblocat_f" numeric(1,0),
  "dfblocat_g" numeric(1,0),
  "pretinitial" numeric(20,7),
  "rezerva" numeric(20,7),
  "rezervablocat" numeric(1,0),
  "codsablon" numeric(20,0),
  "amoblocat" numeric(1,0),
  "centrublocat" numeric(1,0),
  "codclasifblocat" numeric(1,0),
  "codpersblocat" numeric(1,0),
  "nodanalizablocat" numeric(1,0),
  "codauto" numeric(20,0),
  "amorezerva" numeric(20,7),
  "amorblocat" numeric(1,0),
  "amofblocat" numeric(1,0),
  "amogblocat" numeric(1,0),
  "pretiniblocat" numeric(1,0),
  "pretinitial_f" numeric(20,7),
  "pretinitial_fblocat" numeric(1,0),
  "tipstorno" numeric(1,0),
  "amoanprec" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>modi_state</obj_name>
  <obj_hashval>8bb6b1b9023703f616695a16b0d47da4</obj_hashval>
  <obj_text>CREATE TABLE modi_state (
  "codmodi_state" numeric(20,0) NOT NULL,
  "codmaster" numeric(20,0),
  "tablename" character varying(20),
  "modidate" timestamp(6) without time zone,
  "tipmodif" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>modificari</obj_name>
  <obj_hashval>6831abe0526a3b85af4b343c1bc9ea60</obj_hashval>
  <obj_text>CREATE TABLE modificari (
  "codmodificare" numeric(20,0) NOT NULL,
  "codmaster" numeric(20,0),
  "tablename" character varying(20),
  "datamodif" timestamp(0) without time zone,
  "usermodif" numeric(10,0),
  "tipmodif" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>modificaripret</obj_name>
  <obj_hashval>87ed63aa097da3ecdf18b16ffa8df02e</obj_hashval>
  <obj_text>CREATE TABLE modificaripret (
  "codmodif" numeric(20,0),
  "codobiect" numeric(20,0),
  "codcatpret" numeric(20,0),
  "pretnou" numeric(20,7),
  "data" timestamp(0) without time zone,
  "subunitatea" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>modplata2</obj_name>
  <obj_hashval>78bc051a70ed684c6d402f2ce2858aab</obj_hashval>
  <obj_text>CREATE TABLE modplata2 (
  "codmodplata2" numeric(20,0) NOT NULL,
  "codies" numeric(20,0),
  "codcard" numeric(20,0),
  "valoare" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>modplataiesretail</obj_name>
  <obj_hashval>797bba5cf7d9a0a2129e25980784a39a</obj_hashval>
  <obj_text>CREATE TABLE modplataiesretail (
  "cod" numeric(20,0),
  "codiesretail" numeric(20,0),
  "tipplata" numeric(10,0),
  "valoare" numeric(20,7),
  "codbankcont" numeric(20,0),
  "vouchersgr" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>moduriplati</obj_name>
  <obj_hashval>b8026afb1fa94fc6088ae0198bf53df1</obj_hashval>
  <obj_text>CREATE TABLE moduriplati (
  "codmodplata" numeric(20,0) NOT NULL,
  "codies" numeric(20,0),
  "tipplata" numeric(5,0),
  "codbankcont" numeric(20,0),
  "valoare" numeric(20,7),
  "denmodplata" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>motive</obj_name>
  <obj_hashval>7096096861cdcda99f0c7326c67ce9fc</obj_hashval>
  <obj_text>CREATE TABLE motive (
  "codmotiv" numeric(20,0) NOT NULL,
  "continut" character varying(200),
  "tip" numeric(2,0),
  "cod" character varying(50),
  "motiv" character varying(1000)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>motivep</obj_name>
  <obj_hashval>04690f042755205bcf7b1263a728c093</obj_hashval>
  <obj_text>CREATE TABLE motivep (
  "codmotiv" numeric(20,0) NOT NULL,
  "denmotiv" character varying(80),
  "motiv" character varying(240)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_necesardoc_codnecesar</obj_name>
  <obj_reftable>necesardoc</obj_reftable>
  <obj_hashval>e16efd764a6466b9481006acac2f4033</obj_hashval>
  <obj_text>CREATE INDEX idx_necesardoc_codnecesar ON necesardoc USING btree (codnecesar)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>mpbcar</obj_name>
  <obj_hashval>29ba23fd1406381206d0be5a58d74447</obj_hashval>
  <obj_text>CREATE TABLE mpbcar (
  "codmpbcar" numeric(20,0) NOT NULL,
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "codpart" numeric(20,0),
  "codsediu" numeric(20,0),
  "tipbcar" numeric(1,0),
  "codobiect" numeric(20,0),
  "obs" character varying(500)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>mpbcar1</obj_name>
  <obj_hashval>d8361127825bcb674f5179b2b4acb9ac</obj_hashval>
  <obj_text>CREATE TABLE mpbcar1 (
  "codmpbcar1" numeric(20,0) NOT NULL,
  "codmpbcar" numeric(20,0),
  "codbcar" numeric(20,0),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "denobiect" character varying(200),
  "codobiect" numeric(20,0),
  "netkg" numeric(20,7),
  "utilkg" numeric(20,7),
  "pretachiz" numeric(20,7),
  "pretuscare" numeric(20,7),
  "pretlastas" numeric(20,7),
  "tipbcar" numeric(1,0),
  "pretachiznou" numeric(20,7),
  "codcontract1" numeric(20,0),
  "moneda" numeric(20,0),
  "curs" numeric(22,4),
  "iaumiditate" numeric(20,7),
  "iastraine" numeric(20,7),
  "iaincoltit" numeric(20,7),
  "iahectolitrica" numeric(20,7),
  "iagluten" numeric(20,7),
  "iafuzaritate" numeric(20,7),
  "iacadere" numeric(20,7),
  "iadeformare" numeric(20,7),
  "iasticlozitate" numeric(20,7),
  "iasparturi" numeric(20,7),
  "iaproteina" numeric(20,7),
  "iaaflatoxina" numeric(20,7),
  "iaatac_plosnita" numeric(20,7),
  "iacontinut_ulei" numeric(20,7),
  "iaaciditate" numeric(20,7),
  "iasistave" numeric(20,7),
  "iarefractie" numeric(20,7),
  "iaindice_w" numeric(20,7),
  "iatoxina_don" numeric(20,7),
  "iaboabe_toxice" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>mpbcar2</obj_name>
  <obj_hashval>dba1dae6605a68c6cce4e62c6042fd7c</obj_hashval>
  <obj_text>CREATE TABLE mpbcar2 (
  "codmpbcar2" numeric(20,0) NOT NULL,
  "codmpbcar" numeric(20,0),
  "iaumiditate" numeric(20,7),
  "iastraine" numeric(20,7),
  "iaincoltit" numeric(20,7),
  "iahectolitrica" numeric(20,7),
  "iagluten" numeric(20,7),
  "iafuzaritate" numeric(20,7),
  "iacadere" numeric(20,7),
  "iadeformare" numeric(20,7),
  "iasticlozitate" numeric(20,7),
  "iasparturi" numeric(20,7),
  "iaproteina" numeric(20,7),
  "iaaflatoxina" numeric(20,7),
  "iaatac_plosnita" numeric(20,7),
  "iacontinut_ulei" numeric(20,7),
  "iaaciditate" numeric(20,7),
  "iasistave" numeric(20,7),
  "iarefractie" numeric(20,7),
  "iaindice_w" numeric(20,7),
  "iatoxina_don" numeric(20,7),
  "iaboabe_toxice" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>mures_ns</obj_name>
  <obj_hashval>c68b6e104bab66962a8b7c1ad69f18fe</obj_hashval>
  <obj_text>CREATE TABLE mures_ns (
  "old" numeric(20,0),
  "new" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>mures_ob</obj_name>
  <obj_hashval>d5de66591ba3a2b460a103433214f556</obj_hashval>
  <obj_text>CREATE TABLE mures_ob (
  "old" numeric(20,0),
  "new" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nactivit</obj_name>
  <obj_hashval>74d60f1bb8ec7ed7be12300087fb4d6d</obj_hashval>
  <obj_text>CREATE TABLE nactivit (
  "codactivit" numeric(20,0) NOT NULL,
  "den_activit" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nagenda</obj_name>
  <obj_hashval>a8d538e67e9961ac61f7d61800b270da</obj_hashval>
  <obj_text>CREATE TABLE nagenda (
  "codagenda" numeric(20,0) NOT NULL,
  "tip" numeric(1,0),
  "codlocalit" numeric(20,0),
  "sediusocial" numeric(1,0),
  "telefon" character varying(40),
  "fax" character varying(20),
  "email" character varying(350),
  "sector" numeric(2,0),
  "strada" character varying(100),
  "nr1" numeric(5,0),
  "nr2" character varying(10),
  "bloc" character varying(30),
  "scara" character varying(5),
  "etaj" character varying(10),
  "apart" character varying(10),
  "codpostal" character varying(10),
  "km" numeric(7,2),
  "obs" character varying(100),
  "codbankcont" numeric(20,0),
  "codpart" numeric(20,0),
  "codgest" numeric(20,0),
  "codsubunit" numeric(20,0),
  "codtipsediu" numeric(20,0),
  "codfiscal" character varying(75),
  "codagent" numeric(20,0),
  "codclient" character varying(50),
  "codtraseu" numeric(20,0),
  "poztraseu" numeric(20,0),
  "inactiv" numeric(1,0),
  "codcoresp" numeric(20,0),
  "transpclient" numeric(1,0),
  "coefutilaje" numeric(7,2),
  "suprafata" numeric(10,2),
  "modservire" numeric(1,0),
  "idsediu" character varying(20),
  "cod_codfiscal" numeric(20,0),
  "telefonp" character varying(40),
  "edi_exptip" numeric(1,0),
  "edi_parttip" numeric(1,0),
  "edi_partid" character varying(20),
  "edi_objtip" numeric(1,0),
  "gln" character varying(13),
  "gestlivrare" numeric(20,0),
  "longitudine" character varying(50),
  "latitudine" character varying(50),
  "obs2" character varying(400),
  "edi_imptip" numeric(1,0),
  "edi_furntip" numeric(1,0),
  "edi_furnid" character varying(20),
  "edi_objtipimp" numeric(1,0),
  "edi_expcumul" numeric(1,0),
  "edi_expean" numeric(1,0),
  "edi_objtip2" numeric(1,0),
  "codtraseu1" numeric(20,0),
  "poztraseu1" numeric(20,0),
  "codantrepozit" character varying(20),
  "ziletransport" numeric(3,0),
  "edi_denum" numeric(1,0),
  "edi_subdirexp" character varying(30),
  "verfact" numeric(10,0),
  "verdisplivr" numeric(10,0),
  "verproforma" numeric(10,0),
  "verfactaviz" numeric(10,0),
  "veravizies" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nagenda1</obj_name>
  <obj_hashval>f935a52bef96f6f5c777b68291aa1efc</obj_hashval>
  <obj_text>CREATE TABLE nagenda1 (
  "codagenda1" numeric(20,0) NOT NULL,
  "codagenda" numeric(20,0),
  "anstart" numeric(5,0),
  "lunastart" numeric(2,0),
  "creditclient" numeric(18,2),
  "ziledepasire" numeric(10,0),
  "nrfactsold" numeric(10,0),
  "scadentav" numeric(5,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nagenti1</obj_name>
  <obj_hashval>d02b4df9970145d8bef2d9fc0c18010d</obj_hashval>
  <obj_text>CREATE TABLE nagenti1 (
  "codagent1" numeric(20,0) NOT NULL,
  "codpers" numeric(20,0),
  "datastart" date
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nagentiproc</obj_name>
  <obj_hashval>b18ad1ebeb42687d56ec8d76a39ff163</obj_hashval>
  <obj_text>CREATE TABLE nagentiproc (
  "codagentproc" numeric(20,0) NOT NULL,
  "codagent1" numeric(20,0),
  "codpers" numeric(20,0),
  "codobiect" numeric(20,0),
  "peclasea" numeric(1,0),
  "codpart" numeric(20,0),
  "peclasep" numeric(1,0),
  "proc" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nagentival</obj_name>
  <obj_hashval>00f52720999826dca7cb836d7f8e0a60</obj_hashval>
  <obj_text>CREATE TABLE nagentival (
  "codagentval" numeric(20,0) NOT NULL,
  "codagent1" numeric(20,0),
  "codpers" numeric(20,0),
  "codmoneda" numeric(20,0),
  "valmax" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nart</obj_name>
  <obj_hashval>54712eed8877696ba2c49e10f45a5124</obj_hashval>
  <obj_text>CREATE TABLE nart (
  "codarticol" numeric(20,0) NOT NULL,
  "den_articol" character varying(100),
  "tiparticol" character varying(1),
  "clasa" numeric(20,0),
  "um" numeric(20,0),
  "um1" numeric(20,0),
  "um2" numeric(20,0),
  "tipserie" numeric(1,0),
  "contimplicit" numeric(20,0),
  "gestimplicita" numeric(20,0),
  "certificat" numeric(1,0),
  "aretg" numeric(1,0),
  "evolutiepret" numeric(1,0),
  "contserviciu" numeric(20,0),
  "incrementserie" numeric(10,0),
  "relatieum1" numeric(2,0),
  "relatieum2" numeric(2,0),
  "casademarcat" numeric(1,0),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7),
  "clasastatist" numeric(20,0),
  "comenzionline" numeric(1,0),
  "codexternart" character varying(30),
  "sufixcodextern" character varying(60),
  "restneglijcmd" numeric(10,5),
  "musaicalitate" numeric(1,0),
  "nrzilestocmediu" numeric(4,0),
  "codcentru" numeric(20,0),
  "dci" character varying(100),
  "paritated1" numeric(12,7),
  "paritated2" numeric(12,7),
  "paritated3" numeric(12,7),
  "culoare" numeric(8,0),
  "clasaw" numeric(20,0),
  "checkisautentic" numeric(1,0),
  "procperisab" numeric(8,4),
  "codmasca" numeric(20,0),
  "tipstoc" numeric(2,0),
  "constructienoua" numeric(1,0),
  "riscfiscal" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nart1</obj_name>
  <obj_hashval>aada60e4f400f40968536a1718ed9863</obj_hashval>
  <obj_text>CREATE TABLE nart1 (
  "codarticol1" numeric(20,0) NOT NULL,
  "codarticol" numeric(20,0),
  "codtva" numeric(20,0),
  "codaccize" numeric(20,0),
  "codtaxa1" numeric(20,0),
  "codtaxa2" numeric(20,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "codaccizedvi" numeric(20,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0),
  "taxcode" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nartamb</obj_name>
  <obj_hashval>c0ea34953ed45cfe9763747cfd265211</obj_hashval>
  <obj_text>CREATE TABLE nartamb (
  "codamb" numeric(20,0) NOT NULL,
  "codobiect" numeric(20,0),
  "codobiectreturn" numeric(20,0),
  "cant" numeric(20,7),
  "cantmin" numeric(20,7),
  "umsec" numeric(20,0),
  "codextern" character varying(40),
  "codplu" numeric(20,0),
  "codintern" character varying(32),
  "masa" numeric(20,7),
  "lungime" numeric(20,7),
  "latime" numeric(20,7),
  "inaltime" numeric(20,7),
  "lxlat" numeric(1,0),
  "lxh" numeric(1,0),
  "latxh" numeric(1,0),
  "greutspecifica" numeric(20,7),
  "implicittipdoc" numeric(20,0),
  "tip" numeric(1,0),
  "returnabil" numeric(1,0),
  "nr_randuri" numeric(3,0),
  "admax" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nartatr</obj_name>
  <obj_hashval>b8ddbc6c1ba4a7a0f8fb144bd6b0df94</obj_hashval>
  <obj_text>CREATE TABLE nartatr (
  "codartatr" numeric(20,0) NOT NULL,
  "codarticol" numeric(20,0),
  "codatribut" numeric(20,0),
  "activ" numeric(1,0),
  "codvalpredef" numeric(20,0),
  "obligatoriu" numeric(1,0),
  "selectie" numeric(1,0),
  "facturabil" numeric(1,0),
  "indexlocal" numeric(5,0),
  "obs" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_necesardoc_codplanifprod</obj_name>
  <obj_reftable>necesardoc</obj_reftable>
  <obj_hashval>18989ca0ea93fbe4e7a47c53aa9091b2</obj_hashval>
  <obj_text>CREATE INDEX idx_necesardoc_codplanifprod ON necesardoc USING btree (codplanifprod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_necesarobj_codnecesar</obj_name>
  <obj_reftable>necesarobj</obj_reftable>
  <obj_hashval>54d8628fd516944f9d27c1ae71f47a90</obj_hashval>
  <obj_text>CREATE INDEX idx_necesarobj_codnecesar ON necesarobj USING btree (codnecesar)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_necesarobj_codobiect</obj_name>
  <obj_reftable>necesarobj</obj_reftable>
  <obj_hashval>0f3594fcc865eaf63438fdef0cbfb2cf</obj_hashval>
  <obj_text>CREATE INDEX idx_necesarobj_codobiect ON necesarobj USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nartcli</obj_name>
  <obj_hashval>b99a52d16be8eaeeb101079cba313102</obj_hashval>
  <obj_text>CREATE TABLE nartcli (
  "codartcli" numeric(20,0) NOT NULL,
  "codobiect" numeric(20,0),
  "codpart" numeric(20,0),
  "denumire" character varying(200),
  "codextern" character varying(30),
  "umsec" numeric(20,0),
  "codmoneda" numeric(20,0),
  "pret" numeric(20,7),
  "tipcodafisat" numeric(1,0),
  "umcorelat" numeric(20,0),
  "implicit" numeric(1,0),
  "codlaclient" character varying(30),
  "codclasep" numeric(20,0),
  "codgama" numeric(20,0),
  "codintern" character varying(30),
  "obs" character varying(100),
  "obs2" character varying(400),
  "umsecimpdoc" numeric(20,0),
  "duratatr" numeric(20,7),
  "zilestoc" numeric(20,7),
  "gln" character varying(13),
  "idspecific" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nartdeleted</obj_name>
  <obj_hashval>3984400e19dd55a1dab2ded07a9b1df0</obj_hashval>
  <obj_text>CREATE TABLE nartdeleted (
  "codarticol" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nartdim</obj_name>
  <obj_hashval>e5fa6c0581a438fb44eeeaf2da62b280</obj_hashval>
  <obj_text>CREATE TABLE nartdim (
  "codartdim" numeric(20,0) NOT NULL,
  "codarticol" numeric(20,0),
  "tip" numeric(1,0),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7),
  "codobiect" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nartimplicite</obj_name>
  <obj_hashval>af37e2e5e18f56fbc0a574987dd4a199</obj_hashval>
  <obj_text>CREATE TABLE nartimplicite (
  "codimplicit" numeric(20,0) NOT NULL,
  "codarticol" numeric(20,0),
  "codsubunit" numeric(20,0),
  "contimplicit" numeric(20,0),
  "gestimplicita" numeric(20,0),
  "locatieimplicita" numeric(20,0),
  "nevandabil" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nartobj</obj_name>
  <obj_hashval>c71193e67ae0dca64c90ffe48d9fe834</obj_hashval>
  <obj_text>CREATE TABLE nartobj (
  "codobiect" numeric(20,0) NOT NULL,
  "codarticol" numeric(20,0),
  "codproducator" numeric(20,0),
  "codextern" character varying(80),
  "codintern" character varying(80),
  "codvamal" character varying(80),
  "masa" numeric(20,5),
  "volum" numeric(20,5),
  "stocmin" numeric(20,5),
  "stocmax" numeric(20,5),
  "returnabil" numeric(1,0),
  "lunigarantie" numeric(4,0),
  "obs" character varying(300),
  "procadaosnir" numeric(5,2),
  "rotunjire" numeric(2,0),
  "adaosexceptie" numeric(5,2),
  "promotie" numeric(1,0),
  "rotvaluta" numeric(2,0),
  "denumire" character varying(200),
  "umambalare" numeric(20,0),
  "pretminim" numeric(20,5),
  "termenplata" numeric(5,0),
  "dataadaugarii" date,
  "codplu" numeric(20,0),
  "usestocmed" numeric(1,0),
  "durmaxaprov" numeric(10,0),
  "codcnas" character varying(20),
  "codcaract" numeric(20,0),
  "blocat" numeric(1,0),
  "discpromo" numeric(20,7),
  "taraorigine" numeric(20,0),
  "zilevalabil" numeric(10,0),
  "ziledistrib" numeric(10,0),
  "codperisabil" numeric(20,0),
  "nefacturabil" numeric(1,0),
  "greutspecifica" numeric(20,7),
  "stocmed" numeric(20,5),
  "inactivcmdonline" numeric(1,0),
  "produspropriu" numeric(1,0),
  "mesajinactiv" character varying(100),
  "autorizatie" character varying(20),
  "expirareautoriz" date,
  "traducartgeneric" numeric(1,0),
  "codd394" character varying(8),
  "inactiv" numeric(1,0),
  "faracmdfurn" numeric(1,0),
  "faranivelaprob" numeric(1,0),
  "descarcareintegrala" numeric(1,0),
  "farastoc" numeric(1,0),
  "codcategartti" numeric(20,0),
  "coefcnas" numeric(20,7),
  "exportemcs" numeric(1,0),
  "codnc" character varying(10),
  "codaccizabil" character varying(10),
  "rapcnas" numeric(1,0),
  "lansimp" numeric(1,0),
  "exportklg" numeric(1,0),
  "exportatklg" timestamp(6) without time zone,
  "codanalizanod" numeric(20,0),
  "saft_export" numeric(1,0),
  "cantvanz" numeric(20,7),
  "codcpv" character varying(10),
  "excluslistarecm" numeric(1,0),
  "antibiotic" numeric(1,0),
  "certif_dds" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nartobj1</obj_name>
  <obj_hashval>7cc4c318fa6b06d8142b96bed06bb321</obj_hashval>
  <obj_text>CREATE TABLE nartobj1 (
  "codobiect1" numeric(20,0) NOT NULL,
  "codobiect" numeric(20,0),
  "pretmaximal" numeric(24,7),
  "procadaosmaximal" numeric(24,7),
  "adaosla" numeric(1,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "pretreferinta" numeric(24,7),
  "tippretmax" numeric(1,0),
  "compensat" numeric(1,0),
  "tipcompensare" character varying(10),
  "grupa" character varying(20),
  "uplift" numeric(10,7),
  "codmoneda" numeric(20,0),
  "puncte" numeric(10,0),
  "umiditate" numeric(20,7),
  "corpuri_straine" numeric(20,7),
  "incoltit" numeric(20,7),
  "hectolitrica" numeric(20,7),
  "gluten" numeric(20,7),
  "fuzaritate" numeric(20,7),
  "cadere" numeric(20,7),
  "deformare" numeric(20,7),
  "sticlozitate" numeric(20,7),
  "sparturi" numeric(20,7),
  "punctesectie" numeric(10,0),
  "tippret" numeric(1,0),
  "valmat" numeric(20,7),
  "valman" numeric(20,7),
  "valregie" numeric(20,7),
  "d390exclus" numeric(1,0),
  "cost" numeric(20,7),
  "cantservauto" numeric(20,7),
  "proteina" numeric(20,7),
  "aflatoxina" numeric(20,7),
  "atac_plosnita" numeric(20,7),
  "continut_ulei" numeric(20,7),
  "aciditate" numeric(20,7),
  "sistave" numeric(20,7),
  "refractie" numeric(20,7),
  "indice_w" numeric(20,7),
  "toxina_don" numeric(20,7),
  "boabe_toxice" numeric(20,7),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0),
  "max_umiditate" numeric(20,7),
  "max_corpuri_straine" numeric(20,7),
  "max_incoltit" numeric(20,7),
  "max_hectolitrica" numeric(20,7),
  "max_gluten" numeric(20,7),
  "max_fuzaritate" numeric(20,7),
  "max_cadere" numeric(20,7),
  "max_deformare" numeric(20,7),
  "max_sticlozitate" numeric(20,7),
  "max_sparturi" numeric(20,7),
  "max_proteina" numeric(20,7),
  "max_aflatoxina" numeric(20,7),
  "max_atac_plosnita" numeric(20,7),
  "max_continut_ulei" numeric(20,7),
  "max_aciditate" numeric(20,7),
  "max_sistave" numeric(20,7),
  "max_refractie" numeric(20,7),
  "max_indice_w" numeric(20,7),
  "max_toxina_don" numeric(20,7),
  "max_boabe_toxice" numeric(20,7),
  "min_umiditate" numeric(20,7),
  "min_corpuri_straine" numeric(20,7),
  "min_incoltit" numeric(20,7),
  "min_hectolitrica" numeric(20,7),
  "min_gluten" numeric(20,7),
  "min_fuzaritate" numeric(20,7),
  "min_cadere" numeric(20,7),
  "min_deformare" numeric(20,7),
  "min_sticlozitate" numeric(20,7),
  "min_sparturi" numeric(20,7),
  "min_proteina" numeric(20,7),
  "min_aflatoxina" numeric(20,7),
  "min_atac_plosnita" numeric(20,7),
  "min_continut_ulei" numeric(20,7),
  "min_aciditate" numeric(20,7),
  "min_sistave" numeric(20,7),
  "min_refractie" numeric(20,7),
  "min_indice_w" numeric(20,7),
  "min_toxina_don" numeric(20,7),
  "min_boabe_toxice" numeric(20,7),
  "pretprod" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nartobjcolet</obj_name>
  <obj_hashval>d2093a39a3efaa3942229904f7b1faa7</obj_hashval>
  <obj_text>CREATE TABLE nartobjcolet (
  "codobjcolet" numeric(20,0),
  "codobiect" numeric(20,0),
  "indexlocal" numeric(5,0),
  "continut" character varying(30),
  "idcolet" character varying(10),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nartobjgest</obj_name>
  <obj_hashval>8edf41dfb8a925c260fdd14186832a6d</obj_hashval>
  <obj_text>CREATE TABLE nartobjgest (
  "codobiect" numeric(20,0),
  "codgest" numeric(20,0),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7),
  "d4" numeric(20,7),
  "d5" numeric(20,7),
  "d6" numeric(20,7),
  "d7" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nartobjimp</obj_name>
  <obj_hashval>9203a112417ed97946318abaa87fff20</obj_hashval>
  <obj_text>CREATE TABLE nartobjimp (
  "codobjimp" numeric(20,0) NOT NULL,
  "codobiect" numeric(20,0),
  "codsubunit" numeric(20,0),
  "gestimplicita" numeric(20,0),
  "locatieimplicita" numeric(20,0),
  "durmaxaprov" numeric(10,0),
  "contimplicit" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nartobjsubunit</obj_name>
  <obj_hashval>cb1c1f8097b13a9c2eaed6758ad66c54</obj_hashval>
  <obj_text>CREATE TABLE nartobjsubunit (
  "cods" numeric(20,0) NOT NULL,
  "codobiect" numeric(20,0),
  "subunitate" numeric(20,0),
  "stocmin" numeric(20,7),
  "stocmax" numeric(20,7),
  "stocmed" numeric(20,7),
  "procstocmin" numeric(20,7),
  "procstocmax" numeric(20,7),
  "procstocmed" numeric(20,7),
  "codgest" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nartobjtrad</obj_name>
  <obj_hashval>79a1e7fa21a43f9b166d67a85658d3a5</obj_hashval>
  <obj_text>CREATE TABLE nartobjtrad (
  "codobiecttrad" numeric(20,0) NOT NULL,
  "codobiect" numeric(20,0),
  "codlimba" numeric(20,0),
  "denumiretrad" character varying(200),
  "descriere" text,
  "avertizare" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nartopt</obj_name>
  <obj_hashval>e93ffa4d4c05eded6c9e799c96faceef</obj_hashval>
  <obj_text>CREATE TABLE nartopt (
  "codopt" numeric(20,0) NOT NULL,
  "codobiect" numeric(20,0),
  "codobiectopt" numeric(20,0),
  "standard" numeric(1,0),
  "cant" numeric(20,7),
  "obs" character varying(100),
  "codtiplocatie" numeric(20,0),
  "forcelei" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nartoptiuni</obj_name>
  <obj_hashval>3e332b2a7aba81477062c357968eb3ec</obj_hashval>
  <obj_text>CREATE TABLE nartoptiuni (
  "codoptiune" numeric(20,0),
  "codobiect" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>natrib</obj_name>
  <obj_hashval>74d81c717c9f804a1065d5a4387d3d0f</obj_hashval>
  <obj_text>CREATE TABLE natrib (
  "codatribut" numeric(20,0) NOT NULL,
  "denumire" character varying(50),
  "tipvaloare" numeric(1,0),
  "prefix" character varying(20),
  "colsuplim" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>natrib1</obj_name>
  <obj_hashval>4cf97651c273983ea63a4a6685dfb108</obj_hashval>
  <obj_text>CREATE TABLE natrib1 (
  "codvalatr" numeric(20,0) NOT NULL,
  "codatribut" numeric(20,0),
  "valoare" character varying(50),
  "codobiectasoc" numeric(20,0),
  "codextern" character varying(10),
  "grupa" character varying(5),
  "inactiv" numeric(1,0),
  "procmajpu" numeric(8,5),
  "inactivcmdonline" numeric(1,0),
  "mesajinactiv" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>natrib1trad</obj_name>
  <obj_hashval>81465aa8274ac4afccad38355714fc01</obj_hashval>
  <obj_text>CREATE TABLE natrib1trad (
  "codatrib1trad" numeric(20,0),
  "codvalatr" numeric(20,0),
  "codlimba" numeric(20,0),
  "mesajinactiv" character varying(100),
  "denumire" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>natrib2</obj_name>
  <obj_hashval>b1cb723137275a1595a6adba10f51f6a</obj_hashval>
  <obj_text>CREATE TABLE natrib2 (
  "codatrib2" numeric(20,0),
  "codvalatr" numeric(20,0),
  "codarticol" numeric(20,0),
  "procmaj" numeric(8,5)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>natrobj</obj_name>
  <obj_hashval>e45444456419d98be13130b626fb92dd</obj_hashval>
  <obj_text>CREATE TABLE natrobj (
  "codatrobj" numeric(20,0) NOT NULL,
  "codobiect" numeric(20,0),
  "codartatr" numeric(20,0),
  "codvalatr" numeric(20,0),
  "indexlocal" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nautorizatiiauto</obj_name>
  <obj_hashval>b5ac5a0f65787e3e29fd0f0f648ae453</obj_hashval>
  <obj_text>CREATE TABLE nautorizatiiauto (
  "codautorizatii" numeric(20,0) NOT NULL,
  "denumire" character varying(50),
  "atentionare" numeric(10,0),
  "codserviciu" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nbanciretail</obj_name>
  <obj_hashval>c14a79a6dc7445c287bfa74daa73c15b</obj_hashval>
  <obj_text>CREATE TABLE nbanciretail (
  "cod" numeric(20,0),
  "codpartretail" numeric(20,0),
  "codbank" numeric(20,0),
  "implicit" numeric(1,0),
  "codlocalit" numeric(20,0),
  "contbanca" character varying(30),
  "sucursala" character varying(20),
  "codmoneda" numeric(20,0),
  "denbanca" character varying(50),
  "denlocalit" character varying(50),
  "codpartb" numeric(20,0),
  "codjudet" numeric(20,0),
  "codtara" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nbank</obj_name>
  <obj_hashval>3741f301cc1b78798d64de8fdd17d8c2</obj_hashval>
  <obj_text>CREATE TABLE nbank (
  "codbank" numeric(20,0) NOT NULL,
  "denumire" character varying(50),
  "simbol" character varying(30),
  "codswift" character varying(30),
  "codbnr" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nbankcont</obj_name>
  <obj_hashval>0a795cbffcca0be0fedceac18bd64839</obj_hashval>
  <obj_text>CREATE TABLE nbankcont (
  "codbankcont" numeric(20,0) NOT NULL,
  "codbank" numeric(20,0),
  "den_cont" character varying(30),
  "codlocalitate" numeric(20,0),
  "nrcont" character varying(30),
  "codmoneda" numeric(20,0),
  "filiala" character varying(20),
  "datadeskis" date,
  "datainkis" date,
  "credit" numeric(1,0),
  "subunitatea" numeric(20,0),
  "pos" numeric(1,0),
  "posid" character varying(30),
  "conttva" numeric(1,0),
  "farareg" numeric(1,0),
  "fara_cash_flow" numeric(1,0),
  "obs" character varying(300),
  "implicitef" numeric(1,0),
  "institpublice" numeric(1,0),
  "ordine" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nbankcont1</obj_name>
  <obj_hashval>3c4ccebb7f9ab94166f6349e81fd6684</obj_hashval>
  <obj_text>CREATE TABLE nbankcont1 (
  "codbankcont1" numeric(20,0) NOT NULL,
  "codbankcont" numeric(20,0),
  "codiobanca" numeric(20,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nbanksoldluna</obj_name>
  <obj_hashval>4f18fbf9659b3157779ff2bf30da6ef8</obj_hashval>
  <obj_text>CREATE TABLE nbanksoldluna (
  "codbanksoldluna" numeric(20,0) NOT NULL,
  "codbankcont" numeric(20,0),
  "soldlei" numeric(24,7),
  "soldvaluta" numeric(24,7),
  "an" numeric(4,0),
  "luna" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nc</obj_name>
  <obj_hashval>4bab529d7429556fc2383c51e29d1ffc</obj_hashval>
  <obj_text>CREATE TABLE nc (
  "codnc" numeric(20,0) NOT NULL,
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "part" numeric(20,0),
  "jurnaltva" numeric(5,0),
  "tiptranz" numeric(5,0),
  "tiptva" numeric(5,0),
  "valoare" numeric(20,3),
  "moneda" numeric(21,0),
  "curs" numeric(20,7),
  "obs" character varying(100),
  "an" numeric(5,0),
  "luna" numeric(2,0),
  "subunitatea" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "sablon" numeric(1,0),
  "carnetdoc" numeric(20,0),
  "codanaliza" numeric(20,0),
  "aprobat" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nc1</obj_name>
  <obj_hashval>4509cf71511d311603875acefd2dc076</obj_hashval>
  <obj_text>CREATE TABLE nc1 (
  "codnc1" numeric(20,0) NOT NULL,
  "codnc" numeric(20,0),
  "contd" numeric(20,0),
  "contc" numeric(20,0),
  "valoare" numeric(20,3),
  "obs" character varying(80),
  "codgest" numeric(20,0),
  "partd" numeric(1,0),
  "partc" numeric(1,0),
  "indexlocal" numeric(5,0),
  "an" numeric(5,0),
  "luna" numeric(2,0),
  "icontd" numeric(3,0),
  "icontc" numeric(3,0),
  "tiplinietva" numeric(5,0),
  "codcentru" numeric(20,0),
  "codauto" numeric(20,0),
  "agent" numeric(20,0),
  "codanalizanod" numeric(20,0),
  "codformatie" numeric(20,0),
  "persd" numeric(1,0),
  "persc" numeric(1,0),
  "codpart" numeric(20,0),
  "codmifix" numeric(20,0),
  "restimbmf" numeric(20,7),
  "codcmdint1" numeric(20,0),
  "mfsaft" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncarsupart</obj_name>
  <obj_hashval>9229e19d6430be87a50f59e66bc91626</obj_hashval>
  <obj_text>CREATE TABLE ncarsupart (
  "codcarsupart" numeric(20,0) NOT NULL,
  "den_carsupart" character varying(80),
  "culoare" numeric(8,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncasemarcat</obj_name>
  <obj_hashval>d544c0bffd8e6e5d4fc4a3b3c8c2d938</obj_hashval>
  <obj_text>CREATE TABLE ncasemarcat (
  "codcasemarcat" numeric(20,0) NOT NULL,
  "denumire" character varying(200),
  "numar" numeric(10,0),
  "port" numeric(20,0),
  "tip" numeric(10,0),
  "model" numeric(10,0),
  "codfiscal" character varying(12),
  "codbarecantar" numeric(1,0),
  "plumaxcantar" numeric(20,0),
  "nrmaxplu" numeric(20,0),
  "lungimetext" numeric(5,0),
  "tipdriver" numeric(5,0),
  "rata" numeric(2,0),
  "subunitatea" numeric(20,0),
  "gestdesttransf" numeric(20,0),
  "codioartdesttransf" numeric(20,0),
  "tipinfoart" numeric(2,0),
  "codcarnettransf" numeric(20,0),
  "textpromo" character varying(300),
  "codcarnetnir" numeric(20,0),
  "inactiv" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncasemarcat1</obj_name>
  <obj_hashval>ae62c1b10cc696cf5619de88338d772d</obj_hashval>
  <obj_text>CREATE TABLE ncasemarcat1 (
  "codcasemarcat1" numeric(20,0) NOT NULL,
  "codcasemarcat" numeric(20,0),
  "codgestiune" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncasemarcat2</obj_name>
  <obj_hashval>b9d343b280394473b5f023ede8bab726</obj_hashval>
  <obj_text>CREATE TABLE ncasemarcat2 (
  "codcasemarcat2" numeric(20,0) NOT NULL,
  "codcasemarcat" numeric(20,0),
  "procent_tva" numeric(20,7),
  "paramcasa" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncatpret</obj_name>
  <obj_hashval>4576619acf00105403ce5832a3ae6790</obj_hashval>
  <obj_text>CREATE TABLE ncatpret (
  "codcatpret" numeric(20,0) NOT NULL,
  "den_catpret" character varying(30),
  "tip" numeric(2,0),
  "simbol" character varying(10),
  "procdinimplicit" numeric(20,7),
  "sumafixaimplicit" numeric(20,7),
  "codcatmaster" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nccadouri</obj_name>
  <obj_hashval>ea45e6f20e67f14f95eba65240679dbb</obj_hashval>
  <obj_text>CREATE TABLE nccadouri (
  "codnccadouri" numeric(20,0) NOT NULL,
  "codncredit" numeric(20,0),
  "codobiect" numeric(20,0),
  "codobiectasoc" numeric(20,0),
  "codarticol" numeric(20,0),
  "umsec" numeric(20,0),
  "diferente" numeric(20,7),
  "codobiectasocsec" numeric(20,0),
  "cant" numeric(20,7),
  "cantfact" numeric(20,7),
  "codanalizanod" numeric(20,0),
  "codcentru" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nclasea</obj_name>
  <obj_hashval>992dba16089a4b349cfc9db6ae096127</obj_hashval>
  <obj_text>CREATE TABLE nclasea (
  "codclasea" numeric(20,0) NOT NULL,
  "den_clasea" character varying(150),
  "simbol" character varying(50),
  "prefix" numeric(1,0),
  "nivel" numeric(3,0),
  "nranalitice" numeric(3,0),
  "codparinte" numeric(20,0),
  "verlistsuplfact" numeric(10,0),
  "verlistsupltoall" numeric(1,0),
  "codident" character varying(250),
  "verlistsuplaviz" numeric(20,0),
  "discofe" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nclaseas</obj_name>
  <obj_hashval>cc5eb0066f769578f2191d1b1e1d2d7b</obj_hashval>
  <obj_text>CREATE TABLE nclaseas (
  "codclaseas" numeric(20,0) NOT NULL,
  "den_claseas" character varying(250),
  "simbol" character varying(250),
  "prefix" numeric(1,0),
  "nivel" numeric(3,0),
  "nranalitice" numeric(3,0),
  "codparinte" numeric(20,0),
  "verlistsuplfact" numeric(10,0),
  "verlistsupltoall" numeric(1,0),
  "tip" numeric(1,0),
  "codident" character varying(250)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nclasedisc</obj_name>
  <obj_hashval>00ad856e060f2e0fb695c0255173d480</obj_hashval>
  <obj_text>CREATE TABLE nclasedisc (
  "codclasedisc" numeric(20,0),
  "den_clasedisc" character varying(50),
  "simbol" character varying(30),
  "nivel" numeric(3,0),
  "nranalitice" numeric(3,0),
  "codparinte" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nclaseg</obj_name>
  <obj_hashval>cb5394b8e6c79bd8c38f7f2a78c46791</obj_hashval>
  <obj_text>CREATE TABLE nclaseg (
  "codclaseg" numeric(20,0) NOT NULL,
  "den_claseg" character varying(50),
  "simbol" character varying(30),
  "nivel" numeric(3,0),
  "nranalitice" numeric(3,0),
  "codparinte" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nclaseint</obj_name>
  <obj_hashval>e1f5f587cc0497d704129be70528c40b</obj_hashval>
  <obj_text>CREATE TABLE nclaseint (
  "codclaseint" numeric(20,0) NOT NULL,
  "den_claseint" character varying(50),
  "simbol" character varying(30),
  "prefix" numeric(1,0),
  "nivel" numeric(3,0),
  "nranalitice" numeric(3,0),
  "codparinte" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nclasemf</obj_name>
  <obj_hashval>90d6b15469ddeb70acc35d4c2856f93e</obj_hashval>
  <obj_text>CREATE TABLE nclasemf (
  "codclasemf" numeric(20,0) NOT NULL,
  "den_clasemf" character varying(50),
  "simbol" character varying(30),
  "prefix" numeric(1,0),
  "nivel" numeric(3,0),
  "nranalitice" numeric(3,0),
  "codparinte" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nclasep</obj_name>
  <obj_hashval>531fa702af0d7f93de32d2de94cccc2a</obj_hashval>
  <obj_text>CREATE TABLE nclasep (
  "codclasep" numeric(20,0) NOT NULL,
  "den_clasep" character varying(30),
  "simbol" character varying(30),
  "nivel" numeric(2,0),
  "nranalitice" numeric(3,0),
  "codparinte" numeric(20,0),
  "codident" character varying(250)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nclaseprod</obj_name>
  <obj_hashval>c136dec1147dc4e7962d7dd2942c1e9b</obj_hashval>
  <obj_text>CREATE TABLE nclaseprod (
  "codclaseprod" numeric(20,0) NOT NULL,
  "den_claseprod" character varying(50),
  "simbol" character varying(30),
  "prefix" numeric(1,0),
  "nivel" numeric(3,0),
  "nranalitice" numeric(3,0),
  "codparinte" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncodfiscretail</obj_name>
  <obj_hashval>fe9bc7875575c0795aabf04e47960548</obj_hashval>
  <obj_text>CREATE TABLE ncodfiscretail (
  "cod" numeric(20,0),
  "codpartretail" numeric(20,0),
  "codfiscal" character varying(75),
  "principal" numeric(1,0),
  "cod_codfiscal" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncont</obj_name>
  <obj_hashval>6617935ca93efca50914180979060a86</obj_hashval>
  <obj_text>CREATE TABLE ncont (
  "codcont" numeric(20,0) NOT NULL,
  "simbol" character varying(100),
  "clasa" numeric(1,0),
  "den_cont" character varying(200),
  "name" character varying(150),
  "tipcont" numeric(1,0),
  "vizibilbalanta" numeric(1,0),
  "balantasintetica" numeric(1,0),
  "nivel" numeric(2,0),
  "codparinte" numeric(20,0),
  "simbolsitfin" character varying(50),
  "aninactiv" numeric(5,0),
  "lunainactiv" numeric(2,0),
  "codsaft" character varying(70),
  "taxtype" numeric(20,0),
  "taxcode" numeric(20,0),
  "impozit" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nechiv_codobiect</obj_name>
  <obj_reftable>nechiv</obj_reftable>
  <obj_hashval>877f281b00f98aaf461976ad96cb2179</obj_hashval>
  <obj_text>CREATE INDEX idx_nechiv_codobiect ON nechiv USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ngest_codactivit</obj_name>
  <obj_reftable>ngest</obj_reftable>
  <obj_hashval>87e0dfe6a3d7fff26a26da32bf48e794</obj_hashval>
  <obj_text>CREATE INDEX idx_ngest_codactivit ON ngest USING btree (codactivit)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncont1</obj_name>
  <obj_hashval>baf54ff663e6fac7d2b6c35e0f645f4d</obj_hashval>
  <obj_text>CREATE TABLE ncont1 (
  "codcont1" numeric(20,0) NOT NULL,
  "codcont" numeric(20,0),
  "nranalitice" numeric(3,0),
  "conttransfd" numeric(20,0),
  "conttransfc" numeric(20,0),
  "continkidsold" numeric(20,0),
  "participatiune" numeric(1,0),
  "sincronizare" numeric(20,0),
  "contsecundar" numeric(20,0),
  "conttertiar" numeric(20,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "conttransfcdim" numeric(20,0),
  "tipinchidere" numeric(1,0),
  "contsecundarg" numeric(20,0),
  "contsecundargo" numeric(20,0),
  "codcentru" numeric(20,0),
  "codcentrus" numeric(20,0),
  "codcentrusg" numeric(20,0),
  "codcentrusgo" numeric(20,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0),
  "codanalizanod" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncont1_socbank</obj_name>
  <obj_hashval>8481ab46a686349a9c9f9d8e90dbb602</obj_hashval>
  <obj_text>CREATE TABLE ncont1_socbank (
  "codcont1" numeric(20,0),
  "codcont" numeric(20,0),
  "nranalitice" numeric(3,0),
  "conttransfd" numeric(20,0),
  "conttransfc" numeric(20,0),
  "continkidsold" numeric(20,0),
  "participatiune" numeric(1,0),
  "sincronizare" numeric(20,0),
  "contsecundar" numeric(20,0),
  "conttertiar" numeric(20,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "conttransfcdim" numeric(20,0),
  "tipinchidere" numeric(1,0),
  "contsecundarg" numeric(20,0),
  "contsecundargo" numeric(20,0),
  "codcentru" numeric(20,0),
  "codcentrus" numeric(20,0),
  "codcentrusg" numeric(20,0),
  "codcentrusgo" numeric(20,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0),
  "codanalizanod" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncont1sub</obj_name>
  <obj_hashval>89785c59d24d8da0a0fcca32a68a849a</obj_hashval>
  <obj_text>CREATE TABLE ncont1sub (
  "cod" numeric(20,0),
  "codcont1" numeric(20,0),
  "subunitatea" numeric(20,0),
  "tipinchidere" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncont_bak</obj_name>
  <obj_hashval>fce9af000f886d801fc5861e63537d5f</obj_hashval>
  <obj_text>CREATE TABLE ncont_bak (
  "codcont" numeric(20,0) NOT NULL,
  "simbol" character varying(100),
  "clasa" numeric(1,0),
  "den_cont" character varying(50),
  "name" character varying(50),
  "tipcont" numeric(1,0),
  "vizibilbalanta" numeric(1,0),
  "balantasintetica" numeric(1,0),
  "nivel" numeric(2,0),
  "codparinte" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncont_newentry</obj_name>
  <obj_hashval>4f20b0b83b19bf4bbd9530459684b720</obj_hashval>
  <obj_text>CREATE TABLE ncont_newentry (
  "codcont" numeric(5,0),
  "simbol" character varying(100),
  "den_cont" character varying(200),
  "name" character varying(150),
  "tipcont" numeric(1,0),
  "anstart" numeric(5,0),
  "lunastart" numeric(2,0),
  "done" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncont_socbank</obj_name>
  <obj_hashval>eda23dcc9ae8ee263c2407dbfcb0bdde</obj_hashval>
  <obj_text>CREATE TABLE ncont_socbank (
  "codcont" numeric(20,0),
  "simbol" character varying(100),
  "clasa" numeric(1,0),
  "den_cont" character varying(200),
  "name" character varying(150),
  "tipcont" numeric(1,0),
  "vizibilbalanta" numeric(1,0),
  "balantasintetica" numeric(1,0),
  "nivel" numeric(2,0),
  "codparinte" numeric(20,0),
  "simbolsitfin" character varying(50),
  "aninactiv" numeric(5,0),
  "lunainactiv" numeric(2,0),
  "codsaft" character varying(70),
  "taxtype" numeric(20,0),
  "taxcode" numeric(20,0),
  "impozit" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ngest_codcatpret</obj_name>
  <obj_reftable>ngest</obj_reftable>
  <obj_hashval>32fdb3a5b9777729080fd942eab79aee</obj_hashval>
  <obj_text>CREATE INDEX idx_ngest_codcatpret ON ngest USING btree (codcatpret)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ngest_codclasa</obj_name>
  <obj_reftable>ngest</obj_reftable>
  <obj_hashval>c366014afe6143682d728440ec697215</obj_hashval>
  <obj_text>CREATE INDEX idx_ngest_codclasa ON ngest USING btree (codclasa)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ngest_tip</obj_name>
  <obj_reftable>ngest</obj_reftable>
  <obj_hashval>559dc8a35dc2a985a5466b823632eba0</obj_hashval>
  <obj_text>CREATE INDEX idx_ngest_tip ON ngest USING btree (tip)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncontcomun</obj_name>
  <obj_hashval>939268316f38d0730496feae2683f2be</obj_hashval>
  <obj_text>CREATE TABLE ncontcomun (
  "codcont" numeric(20,0),
  "simbol" character varying(100),
  "clasa" numeric(1,0),
  "tipcont" numeric(1,0),
  "balsint" numeric(1,0),
  "nivel" numeric(2,0),
  "soldid" numeric(20,3),
  "soldvid" numeric(20,3),
  "soldic" numeric(20,3),
  "soldvic" numeric(20,3),
  "rulajpd" numeric(20,3),
  "rulajvpd" numeric(20,3),
  "rulajpc" numeric(20,3),
  "rulajvpc" numeric(20,3),
  "rulajcd" numeric(20,3),
  "rulajvcd" numeric(20,3),
  "rulajcc" numeric(20,3),
  "rulajvcc" numeric(20,3),
  "codparinte" numeric(20,0),
  "den_cont" character varying(200),
  "nranalitice" numeric(3,0),
  "vizibilbalanta" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncontechiv</obj_name>
  <obj_hashval>ca7bc68241a9080680e753a8d62358fd</obj_hashval>
  <obj_text>CREATE TABLE ncontechiv (
  "codcontechiv" numeric(20,0),
  "contvechi" numeric(20,0),
  "contnou" numeric(20,0),
  "soldid" numeric(20,3),
  "soldic" numeric(20,3),
  "soldvid" numeric(20,3),
  "soldvic" numeric(20,3),
  "soldi_ifrs" numeric(20,3),
  "soldvi_ifrs" numeric(20,3),
  "soldi_grup" numeric(20,3),
  "soldvi_grup" numeric(20,3),
  "an" numeric(5,0),
  "luna" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncontechivsub</obj_name>
  <obj_hashval>79e1d24b957fb8c58756e495ad34fea6</obj_hashval>
  <obj_text>CREATE TABLE ncontechivsub (
  "codcontechivsub" numeric(20,0),
  "codcontechiv" numeric(20,0),
  "codsubunit" numeric(20,0),
  "soldid" numeric(20,3),
  "soldic" numeric(20,3),
  "soldvid" numeric(20,3),
  "soldvic" numeric(20,3),
  "soldi_ifrs" numeric(20,3),
  "soldvi_ifrs" numeric(20,3),
  "soldi_grup" numeric(20,3),
  "soldvi_grup" numeric(20,3)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncontfirmecupl</obj_name>
  <obj_hashval>a7ec031ec06b7739bf1935b4b381f7c7</obj_hashval>
  <obj_text>CREATE TABLE ncontfirmecupl (
  "codunic" numeric(20,0),
  "codfirmacupl" numeric(20,0),
  "codcont" numeric(20,0),
  "codcontcomun" numeric(20,0),
  "simbol" character varying(100),
  "clasa" numeric(1,0),
  "tipcont" numeric(1,0),
  "balsint" numeric(1,0),
  "nivel" numeric(2,0),
  "soldid" numeric(20,3),
  "soldvid" numeric(20,3),
  "soldic" numeric(20,3),
  "soldvic" numeric(20,3),
  "rulajpd" numeric(20,3),
  "rulajvpd" numeric(20,3),
  "rulajpc" numeric(20,3),
  "rulajvpc" numeric(20,3),
  "rulajcd" numeric(20,3),
  "rulajvcd" numeric(20,3),
  "rulajcc" numeric(20,3),
  "rulajvcc" numeric(20,3),
  "codparinte" numeric(20,0),
  "den_cont" character varying(200),
  "nranalitice" numeric(3,0),
  "simbolcontcomun" character varying(30),
  "legaturainvalida" numeric(1,0),
  "vizibilbalanta" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncontrep</obj_name>
  <obj_hashval>bf155b7b004ae433ea57c4b07bf9a5f1</obj_hashval>
  <obj_text>CREATE TABLE ncontrep (
  "codcontrep" numeric(20,0) NOT NULL,
  "codcont" numeric(20,0),
  "an" numeric(4,0),
  "luna" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncontreprul</obj_name>
  <obj_hashval>f29375dbd6f6ea25038bce9682d78ef2</obj_hashval>
  <obj_text>CREATE TABLE ncontreprul (
  "codcontreprul" numeric(20,0) NOT NULL,
  "codcont" numeric(20,0),
  "codparinte" numeric(20,0),
  "rulajpd" numeric(20,3),
  "rulajpc" numeric(20,3),
  "rulajvpd" numeric(20,3),
  "rulajvpc" numeric(20,3),
  "rulajp_ifrs" numeric(20,3),
  "rulajc_ifrs" numeric(20,3),
  "rulajvp_ifrs" numeric(20,3),
  "rulajvc_ifrs" numeric(20,3),
  "rulajp_grup" numeric(20,3),
  "rulajc_grup" numeric(20,3),
  "rulajvp_grup" numeric(20,3),
  "rulajvc_grup" numeric(20,3)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncontreprulsub</obj_name>
  <obj_hashval>66f0f60e9c2b17792f8623ded34cdbb1</obj_hashval>
  <obj_text>CREATE TABLE ncontreprulsub (
  "codreprulsub" numeric(20,0),
  "codcontreprul" numeric(20,0),
  "subunitatea" numeric(20,0),
  "rulajpd" numeric(20,7),
  "rulajpc" numeric(20,7),
  "rulajvpd" numeric(20,7),
  "rulajvpc" numeric(20,7),
  "rulajp_ifrs" numeric(20,7),
  "rulajc_ifrs" numeric(20,7),
  "rulajvp_ifrs" numeric(20,7),
  "rulajvc_ifrs" numeric(20,7),
  "rulajp_grup" numeric(20,7),
  "rulajc_grup" numeric(20,7),
  "rulajvp_grup" numeric(20,7),
  "rulajvc_grup" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncontrepsold</obj_name>
  <obj_hashval>18a8b22b440f8e693e18d2bea579abb1</obj_hashval>
  <obj_text>CREATE TABLE ncontrepsold (
  "codcontrepsold" numeric(20,0) NOT NULL,
  "codcont" numeric(20,0),
  "codparinte" numeric(20,0),
  "soldid" numeric(20,3),
  "soldic" numeric(20,3),
  "soldvid" numeric(20,3),
  "soldvic" numeric(20,3),
  "soldi_ifrs" numeric(20,3),
  "soldvi_ifrs" numeric(20,3),
  "soldi_grup" numeric(20,3),
  "soldvi_grup" numeric(20,3)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncontrepsoldsub</obj_name>
  <obj_hashval>6bc0e8f74eef6e12a571055889f26dd2</obj_hashval>
  <obj_text>CREATE TABLE ncontrepsoldsub (
  "codrepsoldsub" numeric(20,0),
  "codcontrepsold" numeric(20,0),
  "subunitatea" numeric(20,0),
  "soldid" numeric(20,7),
  "soldic" numeric(20,7),
  "soldvid" numeric(20,7),
  "soldvic" numeric(20,7),
  "soldi_ifrs" numeric(20,7),
  "soldvi_ifrs" numeric(20,7),
  "soldi_grup" numeric(20,7),
  "soldvi_grup" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncontrul</obj_name>
  <obj_hashval>680ad99bd2b94ba480e0d198aa5addb7</obj_hashval>
  <obj_text>CREATE TABLE ncontrul (
  "codcontrul" numeric(20,0) NOT NULL,
  "codcont" numeric(20,0),
  "rulajpd" numeric(20,3),
  "rulajpc" numeric(20,3),
  "rulajcd" numeric(20,3),
  "rulajcc" numeric(20,3),
  "rulajvpd" numeric(20,3),
  "rulajvpc" numeric(20,3),
  "rulajvcd" numeric(20,3),
  "rulajvcc" numeric(20,3),
  "rulajp_ifrs" numeric(20,3),
  "rulajc_ifrs" numeric(20,3),
  "rulajvp_ifrs" numeric(20,3),
  "rulajvc_ifrs" numeric(20,3),
  "rulajp_grup" numeric(20,3),
  "rulajc_grup" numeric(20,3),
  "rulajvp_grup" numeric(20,3),
  "rulajvc_grup" numeric(20,3),
  "an" numeric(4,0),
  "luna" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncontruls</obj_name>
  <obj_hashval>68876e81b34db2d4876b5f5d49a6d427</obj_hashval>
  <obj_text>CREATE TABLE ncontruls (
  "codcontruls" numeric(20,0) NOT NULL,
  "codconts" numeric(20,0),
  "rulajpd" numeric(20,3),
  "rulajpc" numeric(20,3),
  "rulajcd" numeric(20,3),
  "rulajcc" numeric(20,3),
  "rulajvpd" numeric(20,3),
  "rulajvpc" numeric(20,3),
  "rulajvcd" numeric(20,3),
  "rulajvcc" numeric(20,3),
  "an" numeric(4,0),
  "luna" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncontrulsub</obj_name>
  <obj_hashval>04a010e0ffd7d1f5061f9a0dd991f8a3</obj_hashval>
  <obj_text>CREATE TABLE ncontrulsub (
  "codcontrulsub" numeric(20,0),
  "codcontrul" numeric(20,0),
  "subunitatea" numeric(20,0),
  "rulajpd" numeric(20,3),
  "rulajpc" numeric(20,3),
  "rulajcd" numeric(20,3),
  "rulajcc" numeric(20,3),
  "rulajvpd" numeric(20,3),
  "rulajvpc" numeric(20,3),
  "rulajvcd" numeric(20,3),
  "rulajvcc" numeric(20,3),
  "rulajp_ifrs" numeric(20,3),
  "rulajc_ifrs" numeric(20,3),
  "rulajvp_ifrs" numeric(20,3),
  "rulajvc_ifrs" numeric(20,3),
  "rulajp_grup" numeric(20,3),
  "rulajc_grup" numeric(20,3),
  "rulajvp_grup" numeric(20,3),
  "rulajvc_grup" numeric(20,3)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncontrult</obj_name>
  <obj_hashval>d0d334d0fbd769ef8e18afa7d092e5ed</obj_hashval>
  <obj_text>CREATE TABLE ncontrult (
  "codcontrult" numeric(20,0) NOT NULL,
  "codcontt" numeric(20,0),
  "rulajpd" numeric(20,3),
  "rulajpc" numeric(20,3),
  "rulajcd" numeric(20,3),
  "rulajcc" numeric(20,3),
  "rulajvpd" numeric(20,3),
  "rulajvpc" numeric(20,3),
  "rulajvcd" numeric(20,3),
  "rulajvcc" numeric(20,3),
  "an" numeric(4,0),
  "luna" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ngest1_al</obj_name>
  <obj_reftable>ngest1</obj_reftable>
  <obj_hashval>736a7b246d416c7f1000baef2a4ae6fb</obj_hashval>
  <obj_text>CREATE INDEX idx_ngest1_al ON ngest1 USING btree (codgest, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ngest1_cheltuieli</obj_name>
  <obj_reftable>ngest1</obj_reftable>
  <obj_hashval>68ae6c9c1394faea1b0ae33f41009f10</obj_hashval>
  <obj_text>CREATE INDEX idx_ngest1_cheltuieli ON ngest1 USING btree (cheltuieli)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nconts</obj_name>
  <obj_hashval>d3ffa21a0d7af6c0bb8d6bd69a07473a</obj_hashval>
  <obj_text>CREATE TABLE nconts (
  "codconts" numeric(20,0) NOT NULL,
  "simbol" character varying(30),
  "clasa" numeric(1,0),
  "den_cont" character varying(50),
  "name" character varying(50),
  "tipcont" numeric(1,0),
  "vizibilbalanta" numeric(1,0),
  "balantasintetica" numeric(1,0),
  "nivel" numeric(2,0),
  "codparinte" numeric(20,0),
  "simbolsitfin" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nconts1</obj_name>
  <obj_hashval>793df2d50ff01be2751ef8916b16a1a5</obj_hashval>
  <obj_text>CREATE TABLE nconts1 (
  "codconts1" numeric(20,0) NOT NULL,
  "codconts" numeric(20,0),
  "nranalitice" numeric(3,0),
  "conttransfd" numeric(20,0),
  "conttransfc" numeric(20,0),
  "continkidsold" numeric(20,0),
  "participatiune" numeric(1,0),
  "sincronizare" numeric(20,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "conttransfcdim" numeric(20,0),
  "suplcentre" numeric(1,0),
  "codcont" numeric(20,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncontsold</obj_name>
  <obj_hashval>8d477ac65bf7e3d26789f938dfd61c1e</obj_hashval>
  <obj_text>CREATE TABLE ncontsold (
  "codcontsold" numeric(20,0) NOT NULL,
  "codcont" numeric(20,0),
  "soldid" numeric(20,3),
  "soldic" numeric(20,3),
  "soldvid" numeric(20,3),
  "soldvic" numeric(20,3),
  "soldi_ifrs" numeric(20,3),
  "soldvi_ifrs" numeric(20,3),
  "soldi_grup" numeric(20,3),
  "soldvi_grup" numeric(20,3),
  "an" numeric(5,0),
  "luna" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncontsolds</obj_name>
  <obj_hashval>1de7c3e5932460f5c72b04bddbad98b8</obj_hashval>
  <obj_text>CREATE TABLE ncontsolds (
  "codcontsolds" numeric(20,0) NOT NULL,
  "codconts" numeric(20,0),
  "soldid" numeric(20,3),
  "soldic" numeric(20,3),
  "soldvid" numeric(20,3),
  "soldvic" numeric(20,0),
  "an" numeric(4,0),
  "luna" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncontsoldsub</obj_name>
  <obj_hashval>5ba88b3a863163357fd9a865e1440e51</obj_hashval>
  <obj_text>CREATE TABLE ncontsoldsub (
  "codcontsoldsub" numeric(20,0) NOT NULL,
  "codcontsold" numeric(20,0),
  "subunitatea" numeric(20,0),
  "soldid" numeric(20,3),
  "soldic" numeric(20,3),
  "soldvid" numeric(20,3),
  "soldvic" numeric(20,3),
  "soldi_ifrs" numeric(20,3),
  "soldvi_ifrs" numeric(20,3),
  "soldi_grup" numeric(20,3),
  "soldvi_grup" numeric(20,3)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncontsoldt</obj_name>
  <obj_hashval>59c8d0c24f8e6dfa90d1b37e7b0a19e3</obj_hashval>
  <obj_text>CREATE TABLE ncontsoldt (
  "codcontsoldt" numeric(20,0) NOT NULL,
  "codcontt" numeric(20,0),
  "soldid" numeric(20,0),
  "soldic" numeric(20,0),
  "soldvid" numeric(20,0),
  "soldvic" numeric(20,0),
  "an" numeric(4,0),
  "luna" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncontt</obj_name>
  <obj_hashval>0e77b3ad1429bd48d7edad67fcf72850</obj_hashval>
  <obj_text>CREATE TABLE ncontt (
  "codcontt" numeric(20,0) NOT NULL,
  "simbol" character varying(30),
  "clasa" numeric(1,0),
  "den_cont" character varying(50),
  "name" character varying(50),
  "tipcont" numeric(1,0),
  "vizibilbalanta" numeric(1,0),
  "balantasintetica" numeric(1,0),
  "nivel" numeric(2,0),
  "codparinte" numeric(20,0),
  "simbolsitfin" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncontt1</obj_name>
  <obj_hashval>b0334a388caedd5776688555151a68ce</obj_hashval>
  <obj_text>CREATE TABLE ncontt1 (
  "codcontt1" numeric(20,0) NOT NULL,
  "codcontt" numeric(20,0),
  "nranalitice" numeric(3,0),
  "conttransfd" numeric(20,0),
  "conttransfc" numeric(20,0),
  "continkidsold" numeric(20,0),
  "participatiune" numeric(1,0),
  "sincronizare" numeric(20,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "conttransfcdim" numeric(20,0),
  "suplcentre" numeric(1,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ncreante</obj_name>
  <obj_hashval>dbfc9d9e07354e3ba6d8173759ec0710</obj_hashval>
  <obj_text>CREATE TABLE ncreante (
  "cod" numeric(20,0),
  "simbol" numeric(10,0),
  "denumire" character varying(90),
  "tip" numeric(10,0),
  "contb" character varying(10),
  "perioadar" character varying(1),
  "scadenta" numeric(10,0),
  "rapmultipla" numeric(1,0),
  "deductibil" numeric(1,0),
  "derestituit" numeric(1,0),
  "datastart" date,
  "datastop" date,
  "sursa" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ndelegatretail</obj_name>
  <obj_hashval>73f3520ed0fc36391cbaa307047a8295</obj_hashval>
  <obj_text>CREATE TABLE ndelegatretail (
  "cod" numeric(20,0) NOT NULL,
  "codpartretail" numeric(20,0),
  "delegat" character varying(150),
  "cnp" character varying(30),
  "doc" character varying(2),
  "seriedoc" character varying(20),
  "nrdoc" character varying(10),
  "eliberat" character varying(50),
  "mijltransp" character varying(15),
  "nrtransp" character varying(100),
  "datadoc" date,
  "activ" numeric(1,0),
  "implicit" numeric(1,0),
  "obs" character varying(250),
  "codparttr" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>necesar</obj_name>
  <obj_hashval>739b7b57941a9fda5bbf551dd91c05df</obj_hashval>
  <obj_text>CREATE TABLE necesar (
  "codnecesar" numeric(20,0) NOT NULL,
  "carnetdoc" numeric(20,0),
  "nrdoc" numeric(20,0),
  "seriadoc" character varying(20),
  "datadoc" date,
  "obs" character varying(250),
  "saptamana" numeric(10,0),
  "subunitatea" numeric(20,0),
  "valpmp" numeric(20,7),
  "tipnecesar" numeric(1,0),
  "supliment" numeric(1,0),
  "an" numeric(4,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>necesar5</obj_name>
  <obj_hashval>6e82f04597edfbc164b23a694f21e9ed</obj_hashval>
  <obj_text>CREATE TABLE necesar5 (
  "codobiect" numeric(20,0),
  "denumire" character varying(250),
  "furnizor" character varying(250),
  "nrindicator" numeric(2,0),
  "indicator" character varying(200),
  "stocmin" numeric(20,7),
  "cantmin" numeric(20,7),
  "pret" numeric(20,7),
  "ordine" numeric(1,0),
  "l1" numeric(20,7),
  "l2" numeric(20,7),
  "l3" numeric(20,7),
  "l4" numeric(20,7),
  "l5" numeric(20,7),
  "l6" numeric(20,7),
  "l7" numeric(20,7),
  "l8" numeric(20,7),
  "l9" numeric(20,7),
  "l10" numeric(20,7),
  "l11" numeric(20,7),
  "l12" numeric(20,7),
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>necesarcmd</obj_name>
  <obj_hashval>9ad1b51a5f4afdc994f694071244c3ed</obj_hashval>
  <obj_text>CREATE TABLE necesarcmd (
  "codnecesar" numeric(20,0),
  "codcomanda" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>necesardoc</obj_name>
  <obj_hashval>15d59cd883ecb40ada688d12249ca322</obj_hashval>
  <obj_text>CREATE TABLE necesardoc (
  "codnecesar" numeric(20,0),
  "codplanifprod" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>necesarobj</obj_name>
  <obj_hashval>5959ede2c2a64b6c7f8f77b458361af8</obj_hashval>
  <obj_text>CREATE TABLE necesarobj (
  "codnecesar" numeric(20,0),
  "codobiect" numeric(20,0),
  "acceptat" numeric(20,7),
  "acceptatum1" numeric(20,7),
  "planifper" numeric(20,7),
  "planifprec" numeric(20,7),
  "stoc" numeric(20,7),
  "stocmin" numeric(20,7),
  "stocoptim" numeric(20,7),
  "stocmax" numeric(20,7),
  "rezervat" numeric(20,7),
  "cc" numeric(20,7),
  "cf" numeric(20,7),
  "ciies" numeric(20,7),
  "ccpanala" numeric(20,7),
  "ciiespanala" numeric(20,7),
  "pmp" numeric(20,7),
  "valpmp" numeric(20,7),
  "cfper" numeric(20,7),
  "necesar" numeric(20,7),
  "cfnext" numeric(20,7),
  "planif" numeric(20,7),
  "consum" numeric(20,7),
  "consumprec" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nechiv</obj_name>
  <obj_hashval>2fa3252aff3bbd9fe8a6434c850cd613</obj_hashval>
  <obj_text>CREATE TABLE nechiv (
  "codechiv" numeric(20,0) NOT NULL,
  "codobiect" numeric(20,0),
  "paritate" numeric(20,7),
  "codgrupa" numeric(20,0),
  "generic" numeric(1,0),
  "indexlocal" numeric(7,0),
  "ind" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nelemaeroauto</obj_name>
  <obj_hashval>f0e39625c11fd5cf019c6521448cb3d7</obj_hashval>
  <obj_text>CREATE TABLE nelemaeroauto (
  "codelemaeroauto" numeric(20,0) NOT NULL,
  "element" character varying(200),
  "spor" numeric(20,2)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nestjurnal</obj_name>
  <obj_hashval>ef81b084b3943b123d70d4e1baa8a1f1</obj_hashval>
  <obj_text>CREATE TABLE nestjurnal (
  "codnestjurnal" numeric(20,0) NOT NULL,
  "codcontd" numeric(20,0),
  "codcontc" numeric(20,0),
  "codgest" numeric(20,0),
  "codcentru" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ngameart</obj_name>
  <obj_hashval>9e72f090b1996064f2875bc87c7fd940</obj_hashval>
  <obj_text>CREATE TABLE ngameart (
  "codgama" numeric(20,0),
  "denumire" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ngest1_codgest</obj_name>
  <obj_reftable>ngest1</obj_reftable>
  <obj_hashval>a80c05d4848b1285743ed76e7abcc683</obj_hashval>
  <obj_text>CREATE INDEX idx_ngest1_codgest ON ngest1 USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ngest1_venituri</obj_name>
  <obj_reftable>ngest1</obj_reftable>
  <obj_hashval>d8fae3133da4f057f0dcfc31c2f8b25d</obj_hashval>
  <obj_text>CREATE INDEX idx_ngest1_venituri ON ngest1 USING btree (venituri)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nir_codies</obj_name>
  <obj_reftable>nir</obj_reftable>
  <obj_hashval>4dca2e0b918347d1b386f077887a8bd3</obj_hashval>
  <obj_text>CREATE INDEX idx_nir_codies ON nir USING btree (codies)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nir_codintr</obj_name>
  <obj_reftable>nir</obj_reftable>
  <obj_hashval>be21b3f4350df11097e590a39d1d1d98</obj_hashval>
  <obj_text>CREATE INDEX idx_nir_codintr ON nir USING btree (codintr)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ngest</obj_name>
  <obj_hashval>582343026818a44161ad2e21adb96af3</obj_hashval>
  <obj_text>CREATE TABLE ngest (
  "codgest" numeric(20,0) NOT NULL,
  "den_gest" character varying(100),
  "simbol" character varying(50),
  "codclasa" numeric(20,0),
  "codactivit" numeric(20,0),
  "codcont" numeric(20,0),
  "codcatpret" numeric(20,0),
  "codgestionar" numeric(20,0),
  "custodie" numeric(1,0),
  "codsubunit" numeric(20,0),
  "verdisplivr" numeric(10,0),
  "verdisplivrtransf" numeric(10,0),
  "verdisplivrsubunit" numeric(10,0),
  "vernir" numeric(10,0),
  "vernirtransf" numeric(10,0),
  "vernirsubunit" numeric(10,0),
  "tip" numeric(1,0),
  "gmaster" numeric(1,0),
  "nrschimburi" numeric(5,0),
  "oreschimb" numeric(4,2),
  "orastart" timestamp(0) without time zone,
  "coefcheltmat" numeric(20,7),
  "coefcheltman" numeric(20,7),
  "veremulare" numeric(10,0),
  "codpostretail" numeric(20,0),
  "analiticcont" character varying(10),
  "cantitate" numeric(20,7),
  "inactiv" numeric(1,0),
  "verfacties" numeric(20,0),
  "verchitanta" numeric(20,0),
  "codcaensec" numeric(20,0),
  "codgesttr" numeric(20,0),
  "ziletermen" numeric(10,0),
  "zilelucr" numeric(5,0),
  "codantrepozit" character varying(20),
  "capprod" numeric(20,7),
  "carnetcmdint" numeric(20,0),
  "carnetbc" numeric(20,0),
  "carnetnp" numeric(20,0),
  "carnetrp" numeric(20,0),
  "obs" character varying(300)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ngest1</obj_name>
  <obj_hashval>5bf6bb3e691234adb01cad6ed9f3ec1b</obj_hashval>
  <obj_text>CREATE TABLE ngest1 (
  "codgest1" numeric(20,0) NOT NULL,
  "codgest" numeric(20,0),
  "tipgest" numeric(2,0),
  "cheltuieli" numeric(20,0),
  "cheltuieliaux" numeric(20,0),
  "cheltuieliind" numeric(20,0),
  "cheltuieliadmin" numeric(20,0),
  "cheltuielidesf" numeric(20,0),
  "venituri" numeric(20,0),
  "veniturik" numeric(20,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "suprafata" numeric(20,7),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ngrupeauto</obj_name>
  <obj_hashval>33519838c8c3ed9563ae84b005c3a7fc</obj_hashval>
  <obj_text>CREATE TABLE ngrupeauto (
  "codgrupeauto" numeric(20,0) NOT NULL,
  "grupa" character varying(200),
  "sporb" numeric(20,7),
  "sporres" numeric(20,7),
  "sporalte" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nimob</obj_name>
  <obj_hashval>216311ea75a1c75abbac134fffc01212</obj_hashval>
  <obj_text>CREATE TABLE nimob (
  "codnimob" numeric(20,0) NOT NULL,
  "denumire" character varying(200),
  "datastart" date,
  "datastop" date
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ninstauto</obj_name>
  <obj_hashval>1e73a0c3fc55eaaf34446a13dfdc9ca7</obj_hashval>
  <obj_text>CREATE TABLE ninstauto (
  "codinstauto" numeric(20,0) NOT NULL,
  "instalatie" character varying(200),
  "prestatie" character varying(200),
  "spor" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ninterventiiauto</obj_name>
  <obj_hashval>c18300042ce38b9f0b602e90c3ad1b1f</obj_hashval>
  <obj_text>CREATE TABLE ninterventiiauto (
  "codinterventiiauto" numeric(20,0) NOT NULL,
  "denumire" character varying(200),
  "pertip" numeric(1,0),
  "perdurata" numeric(10,0),
  "perkm" numeric(10,0),
  "atentionarezile" numeric(10,0),
  "atentionarekm" numeric(10,0),
  "tip" numeric(1,0),
  "serviciu" numeric(20,0),
  "codreteta" numeric(20,0),
  "accidentala" numeric(1,0),
  "clasa" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nintrastat</obj_name>
  <obj_hashval>975269cdb3a696d0a64fd32d53f0d222</obj_hashval>
  <obj_text>CREATE TABLE nintrastat (
  "codnintrastat" numeric(20,0) NOT NULL,
  "tip" numeric(2,0),
  "alegere" numeric(1,0),
  "simbol" character varying(50),
  "denumire" character varying(300),
  "obs" character varying(300),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nir</obj_name>
  <obj_hashval>ff21295d58617ad422dcaf4dd2445880</obj_hashval>
  <obj_text>CREATE TABLE nir (
  "codnir" numeric(20,0) NOT NULL,
  "codintr" numeric(20,0),
  "codtransf" numeric(20,0),
  "codies" numeric(20,0),
  "carnetnir" numeric(20,0),
  "nrnir" numeric(20,0),
  "datanir" date,
  "gest" numeric(20,0),
  "obs" character varying(100),
  "tipnir" numeric(3,0),
  "anulat" numeric(1,0),
  "blocat" numeric(1,0),
  "operat" numeric(1,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nir1</obj_name>
  <obj_hashval>a31224085b46ab28fb465200c5eb8bb7</obj_hashval>
  <obj_text>CREATE TABLE nir1 (
  "codnirstoc" numeric(20,0),
  "indexlocal" numeric(20,0),
  "diferenta" numeric(20,6),
  "tipdif" character varying(1),
  "cuiimput" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nirluna</obj_name>
  <obj_hashval>a2bd0506027c034467c07d724553ed2f</obj_hashval>
  <obj_text>CREATE TABLE nirluna (
  "codnirstoc" numeric(20,0),
  "an" numeric(5,0),
  "luna" numeric(2,0),
  "rest" numeric(20,7),
  "restum1" numeric(20,7),
  "restum2" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nirser</obj_name>
  <obj_hashval>26d95fb4537e4b1e2903ee99d5c27f15</obj_hashval>
  <obj_text>CREATE TABLE nirser (
  "codnirser" numeric(20,0) NOT NULL,
  "codnirstoc" numeric(20,0),
  "codserie" numeric(20,0),
  "cantnir" numeric(20,7),
  "rest" numeric(20,7),
  "obs" character varying(200),
  "cantum1" numeric(20,7),
  "restum1" numeric(20,7),
  "cantum2" numeric(20,7),
  "restum2" numeric(20,7),
  "codcertif" numeric(20,0),
  "dataprod" date,
  "stare" numeric(2,0),
  "tg" date,
  "divizor" numeric(10,0),
  "bucati" numeric(10,0),
  "dataprod1" date,
  "tg1" date,
  "codproducator" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nirserluna</obj_name>
  <obj_hashval>dc5260acc63c565a337d4777f6d69068</obj_hashval>
  <obj_text>CREATE TABLE nirserluna (
  "codnirser" numeric(20,0),
  "codnirstoc" numeric(20,0),
  "an" numeric(5,0),
  "luna" numeric(2,0),
  "rest" numeric(20,7),
  "restum1" numeric(20,7),
  "restum2" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nir_codtransf</obj_name>
  <obj_reftable>nir</obj_reftable>
  <obj_hashval>0ef5352b7fb04a67a143534c27efcb92</obj_hashval>
  <obj_text>CREATE INDEX idx_nir_codtransf ON nir USING btree (codtransf)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nir_datanir</obj_name>
  <obj_reftable>nir</obj_reftable>
  <obj_hashval>4aeb60e30a5617326bbf13fe9086768e</obj_hashval>
  <obj_text>CREATE INDEX idx_nir_datanir ON nir USING btree (datanir)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nir_gest</obj_name>
  <obj_reftable>nir</obj_reftable>
  <obj_hashval>3b5de117e81a01a6b06a821e4b1cbe39</obj_hashval>
  <obj_text>CREATE INDEX idx_nir_gest ON nir USING btree (gest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nir_tipnir</obj_name>
  <obj_reftable>nir</obj_reftable>
  <obj_hashval>b0af47da1fb926012fddf6bf9c0e02ba</obj_hashval>
  <obj_text>CREATE INDEX idx_nir_tipnir ON nir USING btree (tipnir)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nirluna</obj_name>
  <obj_reftable>nirluna</obj_reftable>
  <obj_hashval>1fa37dbe0ef52f99439b6d435c293ca7</obj_hashval>
  <obj_text>CREATE INDEX idx_nirluna ON nirluna USING btree (an, luna, codnirstoc)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nirstoc</obj_name>
  <obj_hashval>2a449ec2481d3eeffd9a147953435cc2</obj_hashval>
  <obj_text>CREATE TABLE nirstoc (
  "codnirstoc" numeric(20,0) NOT NULL,
  "codnir" numeric(20,0),
  "codintr1" numeric(20,0),
  "codtransf1" numeric(20,0),
  "coddvi1" numeric(20,0),
  "codnirstocparinte" numeric(20,0),
  "cantnir" numeric(20,7),
  "umsec" numeric(20,0),
  "codobiect" numeric(20,0),
  "codioart" numeric(20,0),
  "pret" numeric(20,7),
  "adaos" numeric(20,7),
  "tva" numeric(20,7),
  "tipserie" numeric(1,0),
  "codlivr1" numeric(20,0),
  "rest" numeric(20,7),
  "procentadaos" numeric(20,7),
  "supliment" numeric(20,7),
  "cantfurn" numeric(20,7),
  "rotlei" numeric(2,0),
  "rotvaluta" numeric(2,0),
  "codlocatie" numeric(20,0),
  "cantum1" numeric(20,7),
  "cantum2" numeric(20,7),
  "restum1" numeric(20,7),
  "restum2" numeric(20,7),
  "tg" date,
  "pumaximal" numeric(20,7),
  "furn" numeric(20,0),
  "dataachiz" date,
  "tipdocachiz" numeric(20,0),
  "codgestprod" numeric(20,0),
  "subunitatea" numeric(20,0),
  "disclikistoc" numeric(20,7),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7),
  "puval" numeric(20,7),
  "provizion" numeric(20,7),
  "suplneded" numeric(20,7),
  "serielot" character varying(100),
  "admax" numeric(20,7),
  "eudr_rn" character varying(20),
  "eudr_vn" character varying(20)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nirstoc1</obj_name>
  <obj_hashval>7d8f1a906a5ac2116daf9e04c4b2d2fc</obj_hashval>
  <obj_text>CREATE TABLE nirstoc1 (
  "codnirstoc" numeric(20,0) NOT NULL,
  "codnirstocorig" numeric(20,0),
  "tipdoc" numeric(10,0),
  "pretmat" numeric(20,7),
  "dirty" numeric(1,0),
  "dinstoc" numeric(1,0),
  "codcomanda1" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>njudet</obj_name>
  <obj_hashval>a40650abdece7e2531d730d640be58c7</obj_hashval>
  <obj_text>CREATE TABLE njudet (
  "codjudet" numeric(20,0) NOT NULL,
  "den_judet" character varying(30),
  "simbauto" character varying(2),
  "obs" character varying(500),
  "codtara" numeric(20,0),
  "regcom" numeric(3,0),
  "coddrp" numeric(3,0),
  "dendrp" character varying(15),
  "js" numeric(3,0),
  "itm" numeric(3,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nlimba</obj_name>
  <obj_hashval>a1ad011b6c27303aaf2fbbe3390413cf</obj_hashval>
  <obj_text>CREATE TABLE nlimba (
  "codlimba" numeric(20,0) NOT NULL,
  "denlimba" character varying(100),
  "codtara" numeric(20,0),
  "extlink" character varying(2)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nlimcredit</obj_name>
  <obj_hashval>359fea80f995f40977cae02a544872fb</obj_hashval>
  <obj_text>CREATE TABLE nlimcredit (
  "codlimcredit" numeric(20,0) NOT NULL,
  "codbanca" numeric(20,0),
  "nrcontr" numeric(20,0),
  "datacontr" date,
  "dataexp" date,
  "moneda" numeric(20,0),
  "valoare" numeric(20,7),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "subunitatea" numeric(20,0),
  "investitie" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nlimcredit1</obj_name>
  <obj_hashval>18f68156492a3b6920384c299fc36219</obj_hashval>
  <obj_text>CREATE TABLE nlimcredit1 (
  "codlimcredit1" numeric(20,0),
  "codlimcredit" numeric(20,0),
  "indexlocal" numeric(5,0),
  "data" date,
  "suma" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nlocalit</obj_name>
  <obj_hashval>d27f4498b6ea840e2a760d9f74b90e55</obj_hashval>
  <obj_text>CREATE TABLE nlocalit (
  "codlocalit" numeric(20,0) NOT NULL,
  "den_localit" character varying(50),
  "tip" character varying(20),
  "codjudet" numeric(20,0),
  "obs" character varying(300),
  "codtara" numeric(20,0),
  "densup" character varying(50),
  "siruta" numeric(10,0),
  "codzona" numeric(20,0),
  "latitudine" numeric(20,7),
  "longitudine" numeric(20,7),
  "codpostal" character varying(10)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nlocatii</obj_name>
  <obj_hashval>900c515b91294fbe692ff5243cad2a40</obj_hashval>
  <obj_text>CREATE TABLE nlocatii (
  "codlocatie" numeric(20,0) NOT NULL,
  "codgest" numeric(20,0),
  "denumire" character varying(30),
  "indexlocal" numeric(10,0),
  "nrcelule" numeric(10,0),
  "descriere" character varying(200),
  "codextern" character varying(20),
  "tiplocatie" numeric(1,0),
  "codlocfixa" numeric(20,0),
  "codvecinleft" numeric(20,0),
  "codvecinright" numeric(20,0),
  "coordx" numeric(10,0),
  "inactiv" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nmakete</obj_name>
  <obj_hashval>64ac1ccfdc2cf27ce80563218c6c8b9f</obj_hashval>
  <obj_text>CREATE TABLE nmakete (
  "codmaketa" numeric(20,0) NOT NULL,
  "estelista" numeric(1,0),
  "denmaketa" character varying(30),
  "display" character varying(75),
  "codparinte" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nmarciauto</obj_name>
  <obj_hashval>fcee1bb13759e0af434b38a11acb22c7</obj_hashval>
  <obj_text>CREATE TABLE nmarciauto (
  "codmarciauto" numeric(20,0) NOT NULL,
  "marca" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nmeserii</obj_name>
  <obj_hashval>35c3ca2755c00fcf7207327f60da5687</obj_hashval>
  <obj_text>CREATE TABLE nmeserii (
  "codmeserie" numeric(20,0) NOT NULL,
  "den_meserie" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nmodeleauto</obj_name>
  <obj_hashval>64533c7f7c3cf2fc916a6f0f003998df</obj_hashval>
  <obj_text>CREATE TABLE nmodeleauto (
  "codmodeleauto" numeric(20,0) NOT NULL,
  "model" character varying(50),
  "codmarciauto" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nmonede</obj_name>
  <obj_hashval>819f68b7314a242c3ef271f73c46be2e</obj_hashval>
  <obj_text>CREATE TABLE nmonede (
  "codmoneda" numeric(20,0) NOT NULL,
  "den_moneda" character varying(30),
  "simbol" character varying(5),
  "sdenumire" character varying(30),
  "ssimbol" character varying(5),
  "zecimale" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nmonede1</obj_name>
  <obj_hashval>b08ddef27fab698496ee75c2497dcb04</obj_hashval>
  <obj_text>CREATE TABLE nmonede1 (
  "codmoneda1" numeric(20,0) NOT NULL,
  "codmoneda" numeric(20,0),
  "codbanca" numeric(20,0),
  "data" date,
  "valoare" numeric(23,6)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nmvs</obj_name>
  <obj_hashval>77abede8a991ba521a784ac450e890b1</obj_hashval>
  <obj_text>CREATE TABLE nmvs (
  "userid" numeric(20,0),
  "subunitatea" numeric(20,0),
  "dataverif" timestamp(6) without time zone,
  "gtin" character varying(100),
  "dataexp" character varying(100),
  "lot" character varying(100),
  "sn" character varying(100),
  "skemetype" character varying(100),
  "mesaj" character varying(1000),
  "codmesaj" character varying(100),
  "status" character varying(100),
  "motiv" character varying(100),
  "codfunctie" character varying(100),
  "gln" character varying(50),
  "codnmvs" numeric(20,0) NOT NULL
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nodechiv</obj_name>
  <obj_hashval>7e1426a326438fea5e18a22576c39ddb</obj_hashval>
  <obj_text>CREATE TABLE nodechiv (
  "codcomanda1" numeric(20,0),
  "codproiectnod" numeric(20,0),
  "codobiect" numeric(20,0),
  "paritate" numeric(20,7),
  "tip" numeric(1,0),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7),
  "cantum1" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nodechiv1</obj_name>
  <obj_hashval>4e0dba37a93888bf92b26338dbe2320a</obj_hashval>
  <obj_text>CREATE TABLE nodechiv1 (
  "codscenariu" numeric(20,0),
  "codcomanda1" numeric(20,0),
  "codproiectnod" numeric(20,0),
  "codobiect" numeric(20,0),
  "cant" numeric(20,7),
  "paritate" numeric(20,7),
  "tip" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>noper</obj_name>
  <obj_hashval>a6952870c78846e52c8d3cff1b31350a</obj_hashval>
  <obj_text>CREATE TABLE noper (
  "codop" numeric(20,0) NOT NULL,
  "codextern" character varying(15),
  "denumire" character varying(60),
  "clasaop" numeric(20,0),
  "tip" numeric(1,0),
  "activ" numeric(1,0),
  "codserviciu" numeric(20,0),
  "codtarif" numeric(20,0),
  "locmunca" numeric(20,0),
  "marcaauto" numeric(20,0),
  "modelauto" numeric(20,0),
  "facturabil" numeric(2,0),
  "durata" numeric(20,0),
  "codtiplucrare" numeric(20,0),
  "subunitatea" numeric(20,0),
  "codprestatie" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>noper1</obj_name>
  <obj_hashval>2bbc5c3d804b84541f069073a57cdbf1</obj_hashval>
  <obj_text>CREATE TABLE noper1 (
  "codop1" numeric(20,0) NOT NULL,
  "codop" numeric(20,0),
  "codobiect" numeric(20,0),
  "cant" numeric(10,0),
  "umsec" numeric(20,0),
  "pret" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nirluna_codnirstoc</obj_name>
  <obj_reftable>nirluna</obj_reftable>
  <obj_hashval>50b8e7e6b676bda3a6ad9e64a9efc3dc</obj_hashval>
  <obj_text>CREATE INDEX idx_nirluna_codnirstoc ON nirluna USING btree (codnirstoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nirser_codnirstoc</obj_name>
  <obj_reftable>nirser</obj_reftable>
  <obj_hashval>94c75db893529b55612bb60c9cd58d31</obj_hashval>
  <obj_text>CREATE INDEX idx_nirser_codnirstoc ON nirser USING btree (codnirstoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nirser_codserie</obj_name>
  <obj_reftable>nirser</obj_reftable>
  <obj_hashval>d1c9ff31c68317b5cf5da34259ca6791</obj_hashval>
  <obj_text>CREATE INDEX idx_nirser_codserie ON nirser USING btree (codserie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nirserluna</obj_name>
  <obj_reftable>nirserluna</obj_reftable>
  <obj_hashval>0b4b0dd505a1fa3a4b9c83fafccd4b90</obj_hashval>
  <obj_text>CREATE INDEX idx_nirserluna ON nirserluna USING btree (an, luna, codnirstoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nirserluna_codnirser</obj_name>
  <obj_reftable>nirserluna</obj_reftable>
  <obj_hashval>fb3038914ce3f599d09cb90c1e2e49c9</obj_hashval>
  <obj_text>CREATE INDEX idx_nirserluna_codnirser ON nirserluna USING btree (codnirser)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>notecredit</obj_name>
  <obj_hashval>b333709c787c34f532b3a0e4ed4b86bf</obj_hashval>
  <obj_text>CREATE TABLE notecredit (
  "codncredit" numeric(20,0) NOT NULL,
  "codcontract2" numeric(20,0),
  "codpart" numeric(20,0),
  "tipdoc" numeric(20,0),
  "subunitatea" numeric(20,0),
  "datastart" date,
  "datastop" date,
  "codcontv" numeric(20,0),
  "codcontt" numeric(20,0),
  "codcontc" numeric(20,0),
  "codcontp" numeric(20,0),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "datafact" date,
  "tiparticol" numeric(1,0),
  "obs" character varying(300),
  "codcontract" numeric(20,0),
  "codmoneda" numeric(20,0),
  "volumpearticole" numeric(1,0),
  "codcontz" numeric(20,0),
  "pretbrutc" numeric(1,0),
  "pretbrutv" numeric(1,0),
  "codcarnet" numeric(20,0),
  "trimestriala" numeric(1,0),
  "corectie" numeric(1,0),
  "codnccorectie" numeric(20,0),
  "carnetdoc" numeric(20,0),
  "prefixdoc" character varying(3),
  "nrdoc" numeric(20,0),
  "seriadoc" character varying(20),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "previzionare" numeric(1,0),
  "iesiripevolum" numeric(1,0),
  "curs" numeric(20,7),
  "inchisa" numeric(20,0),
  "valorigter" numeric(1,0),
  "codanaliza" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>notecredit1</obj_name>
  <obj_hashval>e64a1aafa34dbca749f96a9afcf90405</obj_hashval>
  <obj_text>CREATE TABLE notecredit1 (
  "codncredit1" numeric(20,0) NOT NULL,
  "codncredit" numeric(20,0),
  "tipoper" character varying(1),
  "valoare" numeric(20,7),
  "codobligstins" numeric(20,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(20,0),
  "codobligstingator" numeric(20,0),
  "obs" character varying(200),
  "valdif" numeric(20,7),
  "valoareold" numeric(20,7),
  "codclasedisc" numeric(20,0),
  "codncredit1orig" numeric(20,0),
  "previzionat" numeric(20,7),
  "coddiscount" numeric(20,0),
  "valdoc" numeric(20,7),
  "vallei" numeric(20,7),
  "tip" numeric(1,0),
  "proctva" numeric(6,3),
  "obsnav" character varying(450),
  "codanalizanod" numeric(20,0),
  "codcentru" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>notecreditfact</obj_name>
  <obj_hashval>8c0f6962a68f09ab1a2843dba01fe454</obj_hashval>
  <obj_text>CREATE TABLE notecreditfact (
  "codncfact" numeric(20,0) NOT NULL,
  "codncredit" numeric(20,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(10,0),
  "prefixdoc" character varying(2),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "valdoc" numeric(20,7),
  "valt" numeric(20,7),
  "coddoc1" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nparc0</obj_name>
  <obj_hashval>5f601cc7cee57307c2c76d56db3b1eb2</obj_hashval>
  <obj_text>CREATE TABLE nparc0 (
  "codnparc0" numeric(20,0) NOT NULL,
  "codnparcaut" numeric(20,0),
  "databord" timestamp(0) without time zone,
  "kmbord" numeric(10,0),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "obs" character varying(150),
  "codpers" numeric(20,0),
  "codfaz" numeric(20,0),
  "codcmd" numeric(20,0),
  "comb" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nparc1</obj_name>
  <obj_hashval>f39a293b8ba413c9b6141f51416ecdb9</obj_hashval>
  <obj_text>CREATE TABLE nparc1 (
  "codnparc1" numeric(20,0) NOT NULL,
  "indexlocal" numeric(10,0),
  "art" numeric(20,0),
  "cant" numeric(10,0),
  "pozitie" numeric(1,0),
  "bordinstal" numeric(10,0),
  "atentie" numeric(10,0),
  "cod" numeric(20,0),
  "codpart" numeric(20,0),
  "montat" numeric(1,0),
  "anotimp" numeric(1,0),
  "adancime" numeric(2,0),
  "latime" numeric(4,0),
  "inaltime" numeric(3,0),
  "diametru" numeric(3,0),
  "gama" numeric(1,0),
  "runflat" numeric(1,0),
  "suv" numeric(1,0),
  "offroad" numeric(1,0),
  "xl" numeric(1,0),
  "ms" numeric(1,0),
  "obs" character varying(500),
  "seria" character varying(75),
  "dot" numeric(4,0),
  "borddem" numeric(10,0),
  "codnirstoc" numeric(20,0),
  "codnirser" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nparc2</obj_name>
  <obj_hashval>5b256ca8d0c9bbd36ec41faf3b6cd6f7</obj_hashval>
  <obj_text>CREATE TABLE nparc2 (
  "codnparc2" numeric(20,0) NOT NULL,
  "indexlocal" numeric(20,0),
  "doc" numeric(20,0),
  "sn" character varying(20),
  "eliberat" date,
  "expira" date,
  "atentie" numeric(10,0),
  "cod" numeric(20,0),
  "obs" character varying(500),
  "valoare" numeric(20,7),
  "codintr1" numeric(20,0),
  "denumire" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nparc3</obj_name>
  <obj_hashval>570fa40c3bfcfda50132d00bd3d77828</obj_hashval>
  <obj_text>CREATE TABLE nparc3 (
  "codnparc3" numeric(20,0) NOT NULL,
  "cod" numeric(20,0),
  "interventie" numeric(20,0),
  "datau" timestamp(0) without time zone,
  "kmu" numeric(10,0),
  "datav" timestamp(0) without time zone,
  "kmv" numeric(10,0),
  "dataa" timestamp(0) without time zone,
  "kma" numeric(10,0),
  "valoare" numeric(20,7),
  "codcmd" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nparcaut</obj_name>
  <obj_hashval>432ca78271a8a99b45caabc2a95add65</obj_hashval>
  <obj_text>CREATE TABLE nparcaut (
  "codnparcaut" numeric(20,0) NOT NULL,
  "codart" numeric(20,0),
  "nrinv" numeric(20,0),
  "nrinreg" character varying(20),
  "sofer" numeric(20,0),
  "kmpornire" numeric(20,0),
  "tip" numeric(1,0),
  "datainreg" date,
  "marca" numeric(20,0),
  "model" numeric(20,0),
  "anf" numeric(4,0),
  "seriec" character varying(20),
  "culoare" numeric(20,0),
  "lung" numeric(10,0),
  "lat" numeric(10,0),
  "inalt" numeric(10,0),
  "tipmotor" character varying(20),
  "seriem" character varying(20),
  "motor" numeric(20,0),
  "cilindree" numeric(10,0),
  "putere" numeric(10,0),
  "cmm" numeric(10,2),
  "cmu" numeric(10,2),
  "cme" numeric(10,2),
  "tipincarc" numeric(1,0),
  "greutate" numeric(10,0),
  "masam" numeric(10,0),
  "masau" numeric(10,0),
  "masaurdf" numeric(10,0),
  "masaurfdf" numeric(10,0),
  "loct" numeric(4,0),
  "locf" numeric(4,0),
  "locs" numeric(4,0),
  "locp" numeric(4,0),
  "anvrecomf" character varying(15),
  "anvrecoms" character varying(15),
  "anvopt1f" character varying(15),
  "anvopt1s" character varying(15),
  "anvopt2f" character varying(15),
  "anvopt2s" character varying(15),
  "kg" numeric(10,2),
  "kgr" numeric(10,2),
  "sarcina" numeric(20,0),
  "codputere" numeric(20,0),
  "grupauto" numeric(20,0),
  "tiprem" numeric(20,0),
  "instsp" numeric(20,0),
  "aer" numeric(20,0),
  "rezervor" numeric(20,7),
  "volumu" numeric(20,7),
  "culoarec" character varying(50),
  "sursae" character varying(50),
  "extern" numeric(1,0),
  "partener" numeric(20,0),
  "inactiv" numeric(1,0),
  "codgest" numeric(20,0),
  "partleas" numeric(20,0),
  "nrcontr" character varying(50),
  "moneda" numeric(20,0),
  "rataleas" numeric(10,2),
  "ratarca" numeric(10,2),
  "ratacasco" numeric(10,2),
  "dataachiz" date,
  "dataendleas" date,
  "partutiliz" numeric(20,0),
  "persutiliz" numeric(20,0),
  "obs" character varying(200),
  "tipulei" character varying(50),
  "tipvehicul" numeric(1,0),
  "coddealer" numeric(20,0),
  "limitakm" numeric(8,0),
  "dotari" character varying(500),
  "codradio" character varying(15),
  "transmisie" numeric(1,0),
  "tractiune" numeric(1,0),
  "gps" numeric(1,0),
  "gpl" numeric(1,0),
  "frigo" numeric(1,0),
  "codpartgps" numeric(20,0),
  "codextern" character varying(100),
  "codartcomb" numeric(20,0),
  "consstath" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nparccom</obj_name>
  <obj_hashval>14c249968aaabbc3a63d8169b4b97924</obj_hashval>
  <obj_text>CREATE TABLE nparccom (
  "codnparccom" numeric(20,0) NOT NULL,
  "codcomanda" numeric(20,0),
  "codnparcaut" numeric(20,0),
  "kmbord" numeric(10,0),
  "tipcomsa" numeric(1,0),
  "datainchiderii" timestamp(0) without time zone,
  "inmatrrom" numeric(1,0),
  "inspectie" numeric(1,0),
  "pieseclient" numeric(1,0),
  "probadrum" numeric(1,0),
  "spalare" numeric(1,0),
  "dz" numeric(1,0),
  "nivrezervor" numeric(2,0),
  "nrdosardaune" character varying(30),
  "nrautrep" character varying(30),
  "dataautrep" date,
  "kmgarantie" numeric(6,0),
  "datagarantie" date,
  "tipcomanda" character varying(20),
  "asigurator" numeric(20,0),
  "distanta" numeric(5,0),
  "adresasediu" character varying(30),
  "obs" character varying(1500),
  "recomandari" character varying(500),
  "nrore" numeric(20,7),
  "categpret" numeric(5,0),
  "kmborde" numeric(10,0),
  "idrar" numeric(20,0),
  "anulatrar" numeric(5,0),
  "finalizatrar" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nparcg</obj_name>
  <obj_hashval>fda48dfde3690346d61925f84e6f77ae</obj_hashval>
  <obj_text>CREATE TABLE nparcg (
  "codnparcg" numeric(20,0) NOT NULL,
  "codnparcaut" numeric(20,0),
  "codgestini" numeric(20,0),
  "codgest" numeric(20,0),
  "codcmd" numeric(20,0),
  "status" numeric(1,0),
  "data" timestamp(0) without time zone
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>npart</obj_name>
  <obj_hashval>551ddc5126e5644f435d09039f6028b4</obj_hashval>
  <obj_text>CREATE TABLE npart (
  "codpart" numeric(20,0) NOT NULL,
  "den_part" character varying(100),
  "regcom" character varying(20),
  "codextern" character varying(50),
  "codmoneda" numeric(20,0),
  "autorizatie" character varying(50),
  "codintern" character varying(50),
  "codclasa" numeric(20,0),
  "codcategpret" numeric(20,0),
  "tippart" numeric(1,0),
  "scadentac" numeric(5,0),
  "scadentav" numeric(5,0),
  "discount" numeric(6,3),
  "codcategdisc" numeric(20,0),
  "blocat" numeric(1,0),
  "tippartener" numeric(2,0),
  "dataadaugarii" date,
  "obs" character varying(300),
  "poza" bytea,
  "persoanafizica" numeric(1,0),
  "verfact" numeric(10,0),
  "verdisplivr" numeric(10,0),
  "coldiscount" numeric(1,0),
  "infoblocat" character varying(100),
  "expirareautoriz" date,
  "codstatisticbnr" character varying(20),
  "musaicolet" numeric(1,0),
  "strategic" numeric(1,0),
  "cifraafaceri" numeric(20,7),
  "domeniuactiv" character varying(200),
  "nrangajati" numeric(20,0),
  "sursalead" numeric(20,0),
  "lead" numeric(1,0),
  "tvalaincasare" numeric(1,0),
  "modaplicprocdisc" numeric(1,0),
  "proccurstransf" numeric(20,7),
  "verproforma" numeric(10,0),
  "fidelizare" numeric(1,0),
  "majorari" numeric(20,7),
  "tipblocaj" numeric(1,0),
  "poprire_anaf" numeric(1,0),
  "codresponsabil" numeric(20,0),
  "coddomeniuact" numeric(20,0),
  "docdefonorcom" numeric(1,0),
  "modpromofactcom" numeric(1,0),
  "validarepretoferta" numeric(1,0),
  "iescucomanda" numeric(1,0),
  "verfactaviz" numeric(10,0),
  "valmincmd" numeric(20,7),
  "cantmincmd" numeric(20,7),
  "ziaproviz" numeric(10,0),
  "peraproviz" numeric(10,0),
  "codcontractcadru" numeric(20,0),
  "datanastere" date,
  "splittva" numeric(1,0),
  "gdpr" numeric(1,0),
  "zilelivrare" numeric(5,0),
  "saft_export" numeric(1,0),
  "farapenalizari" numeric(1,0),
  "inactiv" numeric(1,0),
  "preofefurnvar" numeric(1,0),
  "tipanalizapret" numeric(1,0),
  "veravizies" numeric(10,0),
  "ef_item" numeric(1,0),
  "ef_party" numeric(1,0),
  "ef_impartgen" numeric(1,0),
  "ef_custom" numeric(20,0),
  "ef_taxe" numeric(1,0),
  "categtarif" numeric(2,0),
  "ef_proiect" character varying(20),
  "zileachiz" numeric(5,0),
  "culoare" numeric(8,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nirserluna_codnirstoc</obj_name>
  <obj_reftable>nirserluna</obj_reftable>
  <obj_hashval>58e8baf634376ef7884c757c82faa9b3</obj_hashval>
  <obj_text>CREATE INDEX idx_nirserluna_codnirstoc ON nirserluna USING btree (codnirstoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nirstoc_coddvi1</obj_name>
  <obj_reftable>nirstoc</obj_reftable>
  <obj_hashval>e58627b410991ce9c457a4cc75763798</obj_hashval>
  <obj_text>CREATE INDEX idx_nirstoc_coddvi1 ON nirstoc USING btree (coddvi1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nirstoc_codintr1</obj_name>
  <obj_reftable>nirstoc</obj_reftable>
  <obj_hashval>4ef1cdf6c1794c9a367c589ff4e42b88</obj_hashval>
  <obj_text>CREATE INDEX idx_nirstoc_codintr1 ON nirstoc USING btree (codintr1)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>npart1</obj_name>
  <obj_hashval>1213cebaa385c95684668422819676d6</obj_hashval>
  <obj_text>CREATE TABLE npart1 (
  "codpart1" numeric(20,0) NOT NULL,
  "codpart" numeric(20,0),
  "codiopart" numeric(20,0),
  "creditclient" numeric(18,2),
  "volumtranzc" numeric(18,2),
  "creditfurn" numeric(18,2),
  "volumtranzf" numeric(16,2),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "scadentav" numeric(5,0),
  "scadentac" numeric(5,0),
  "discount" numeric(6,3),
  "cassbazamin" numeric(1,0),
  "simbolcass" character varying(2),
  "gdpr" numeric(1,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>npart1crm</obj_name>
  <obj_hashval>18187933d9336e02e5e942c0c647a518</obj_hashval>
  <obj_text>CREATE TABLE npart1crm (
  "codpart1crm" numeric(20,0) NOT NULL,
  "codpart" numeric(20,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "cifraafaceri" numeric(20,7),
  "nrangajati" numeric(20,0),
  "lead" numeric(1,0),
  "sursalead" numeric(20,0),
  "codresponsabil" numeric(20,0),
  "stare" numeric(2,0),
  "modplata" numeric(20,0),
  "cip" numeric(1,0),
  "datastart" date,
  "dataend" date,
  "profit" numeric(20,7),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>npartactivit</obj_name>
  <obj_hashval>6a124d2a2ad8c342ece85ffe2de232b7</obj_hashval>
  <obj_text>CREATE TABLE npartactivit (
  "codpartactivit" numeric(20,0) NOT NULL,
  "codpart" numeric(20,0),
  "codactivit" numeric(20,0),
  "dim" numeric(10,2),
  "codpart1crm" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>npartb</obj_name>
  <obj_hashval>4d72b1b99a3f6a35c9e2e0cb2aa14e81</obj_hashval>
  <obj_text>CREATE TABLE npartb (
  "codpartb" numeric(20,0) NOT NULL,
  "codpart" numeric(20,0),
  "codbank" numeric(20,0),
  "implicit" numeric(1,0),
  "codlocalit" numeric(20,0),
  "contbanca" character varying(30),
  "sucursala" character varying(20),
  "codswift" character varying(30),
  "codmoneda" numeric(20,0),
  "tipcomision" numeric(1,0),
  "obs" character varying(100),
  "conttva" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>npartcodfisc</obj_name>
  <obj_hashval>31d0d19b570a407b482c10def2d08a57</obj_hashval>
  <obj_text>CREATE TABLE npartcodfisc (
  "cod_codfiscal" numeric(20,0) NOT NULL,
  "codpart" numeric(20,0),
  "codfiscal" character varying(75),
  "principal" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>npartconcurenti</obj_name>
  <obj_hashval>c101e35e6bf51d30f24bf9f5e6a531c6</obj_hashval>
  <obj_text>CREATE TABLE npartconcurenti (
  "codpartconcurent" numeric(20,0) NOT NULL,
  "codpart" numeric(20,0),
  "codconcurent" numeric(20,0),
  "codpart1crm" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>npartdisc</obj_name>
  <obj_hashval>f32751c7b76a029f8cdcd4d655fc1e15</obj_hashval>
  <obj_text>CREATE TABLE npartdisc (
  "codpartdisc" numeric(20,0) NOT NULL,
  "codpart" numeric(20,0),
  "codcategdisc" numeric(20,0),
  "indexlocal" numeric(4,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>npartdiscretail</obj_name>
  <obj_hashval>e3547265003f86bf130c0ea3987371a4</obj_hashval>
  <obj_text>CREATE TABLE npartdiscretail (
  "cod" numeric(20,0),
  "codpartretail" numeric(20,0),
  "codcategdisc" numeric(20,0),
  "indexlocal" numeric(4,0),
  "codpartdisc" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>npartdomact</obj_name>
  <obj_hashval>ceea78e682fba3059502571ed8a6ce99</obj_hashval>
  <obj_text>CREATE TABLE npartdomact (
  "codpartdomact" numeric(20,0) NOT NULL,
  "codpart" numeric(20,0),
  "coddomeniuact" numeric(20,0),
  "codpart1crm" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>npartlstclase</obj_name>
  <obj_hashval>775489be20ed951e57289aef15b7e6d7</obj_hashval>
  <obj_text>CREATE TABLE npartlstclase (
  "codnpartlstclase" numeric(20,0) NOT NULL,
  "codpart" numeric(20,0),
  "codclasa" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>npartretail</obj_name>
  <obj_hashval>4a4dbc63b49055beb2b0a9f535d89f04</obj_hashval>
  <obj_text>CREATE TABLE npartretail (
  "codpartretail" numeric(20,0),
  "codpart" numeric(20,0),
  "denumire" character varying(100),
  "regcom" character varying(20),
  "obs" character varying(300),
  "codextern" character varying(50),
  "codintern" character varying(50),
  "tippart" numeric(1,0),
  "coldiscount" numeric(1,0),
  "datacreare" timestamp(6) without time zone,
  "userid" numeric(20,0),
  "tipmodif" character varying(1),
  "codclasa" numeric(20,0),
  "fidelizare" numeric(1,0),
  "datanastere" date,
  "blocat" numeric(1,0),
  "infoblocat" character varying(100),
  "codcategpret" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>npartsoldluna</obj_name>
  <obj_hashval>87779e24abb9f4dd98f6633bb8495cc6</obj_hashval>
  <obj_text>CREATE TABLE npartsoldluna (
  "codpartsoldluna" numeric(20,0) NOT NULL,
  "codpart" numeric(20,0),
  "icont" numeric(20,0),
  "codmoneda" numeric(20,0),
  "soldlei" numeric(20,3),
  "soldvaluta" numeric(20,3),
  "sold_ifrs" numeric(20,3),
  "an" numeric(4,0),
  "luna" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>npartsoldlunasub</obj_name>
  <obj_hashval>8771574cbec60c724c662df2b7057ede</obj_hashval>
  <obj_text>CREATE TABLE npartsoldlunasub (
  "codpartsoldlunasub" numeric(20,0),
  "codpart" numeric(20,0),
  "icont" numeric(20,0),
  "codmoneda" numeric(20,0),
  "soldlei" numeric(20,3),
  "soldvaluta" numeric(20,3),
  "sold_ifrs" numeric(20,3),
  "subunitatea" numeric(20,0),
  "an" numeric(4,0),
  "luna" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>npartsubunit</obj_name>
  <obj_hashval>9195a8b4ac7703728f3e20da7f466efb</obj_hashval>
  <obj_text>CREATE TABLE npartsubunit (
  "codpartsubunit" numeric(20,0) NOT NULL,
  "codpart" numeric(20,0),
  "subunitatea" numeric(20,0),
  "ziaproviz" numeric(10,0),
  "peraproviz" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nparttr</obj_name>
  <obj_hashval>772e99e6656844851a6c47533d33a67c</obj_hashval>
  <obj_text>CREATE TABLE nparttr (
  "codparttr" numeric(20,0) NOT NULL,
  "codpart" numeric(20,0),
  "delegat" character varying(150),
  "cnp" character varying(30),
  "doc" character varying(2),
  "seriedoc" character varying(20),
  "nrdoc" character varying(10),
  "eliberat" character varying(50),
  "mijltransp" character varying(15),
  "nrtransp" character varying(100),
  "activ" numeric(1,0),
  "datadoc" date,
  "codpers" numeric(20,0),
  "codauto" numeric(20,0),
  "implicit" numeric(1,0),
  "obs" character varying(250),
  "permis" character varying(20),
  "nrpass" character varying(12),
  "codtara" character varying(3),
  "adresa" character varying(100),
  "codlocalit" numeric(20,0),
  "telefon" character varying(20),
  "email" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nparttr_lnk</obj_name>
  <obj_hashval>f68881a77c14fa857bd0d3604b1a7165</obj_hashval>
  <obj_text>CREATE TABLE nparttr_lnk (
  "codparttrlnk" numeric(20,0),
  "codparttr" numeric(20,0),
  "codpart" numeric(20,0),
  "sedii" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nparttr_lnk1</obj_name>
  <obj_hashval>f35ce68400dbcb824cc8566db22e412e</obj_hashval>
  <obj_text>CREATE TABLE nparttr_lnk1 (
  "codparttrlnk1" numeric(20,0),
  "codparttrlnk" numeric(20,0),
  "codagenda" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>npers</obj_name>
  <obj_hashval>51847e66092183a85ea3749021dcd470</obj_hashval>
  <obj_text>CREATE TABLE npers (
  "codpers" numeric(20,0) NOT NULL,
  "marca" numeric(20,0),
  "nume" character varying(200),
  "prenume" character varying(200),
  "cnp" character varying(30),
  "biseria" character varying(3),
  "binr" character varying(8),
  "locnastere" numeric(20,0),
  "adresa" character varying(200),
  "prenumet" character varying(100),
  "prenumem" character varying(100),
  "localitn" numeric(20,0),
  "datan" date,
  "scivila" numeric(1,0),
  "smilitar" numeric(1,0),
  "activ" numeric(1,0),
  "strainatate" numeric(1,0),
  "agent" numeric(1,0),
  "delegat" numeric(1,0),
  "agenda" numeric(20,0),
  "bieliberatde" character varying(100),
  "ladatade" date,
  "taran" numeric(20,0),
  "cetatenie" numeric(1,0),
  "poza" bytea,
  "logonname" numeric(20,0),
  "accmas" character varying(100),
  "comision" numeric(20,7),
  "codgest" numeric(20,0),
  "codanalizanod" numeric(20,0),
  "codsubunit" numeric(20,0),
  "codloc" numeric(20,0),
  "dataplecarii" date,
  "dataangajarii" date,
  "obs" character varying(250),
  "orepezi" numeric(4,2),
  "codcentru" numeric(20,0),
  "codcatpret" numeric(20,0),
  "iban" character varying(30),
  "codbank" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>npers1</obj_name>
  <obj_hashval>bed5262d82d417c4821560ef25cabfef</obj_hashval>
  <obj_text>CREATE TABLE npers1 (
  "codpers1" numeric(20,0) NOT NULL,
  "codpers" numeric(20,0),
  "codiopers" numeric(20,0),
  "anstart" numeric(5,0),
  "lunastart" numeric(2,0),
  "codformatie" numeric(20,0),
  "codfunctie" numeric(20,0),
  "codmeserie" numeric(20,0),
  "schimb" numeric(2,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nirstoc_codlivr1</obj_name>
  <obj_reftable>nirstoc</obj_reftable>
  <obj_hashval>66d755d9104e220c67ff14c9afe6592b</obj_hashval>
  <obj_text>CREATE INDEX idx_nirstoc_codlivr1 ON nirstoc USING btree (codlivr1)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nperscontact</obj_name>
  <obj_hashval>4ea497e775550ca3cbaca68a79cab19d</obj_hashval>
  <obj_text>CREATE TABLE nperscontact (
  "codpersc" numeric(20,0) NOT NULL,
  "nume" character varying(20),
  "prenume" character varying(40),
  "telefon" character varying(40),
  "email" character varying(100),
  "functie" character varying(100),
  "datanastere" date,
  "rzona" numeric(1,0),
  "id" numeric(10,0),
  "tip" numeric(1,0),
  "codbankcont" numeric(20,0),
  "codpart" numeric(20,0),
  "implicit" numeric(1,0),
  "seriebi" character varying(3),
  "nrbi" character varying(10),
  "eliberatbi" character varying(100),
  "databi" date,
  "cnp" character varying(30),
  "obs" character varying(240),
  "codlocatie" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nperscurs</obj_name>
  <obj_hashval>bfe5d1b367e756416feb5242b10f70c5</obj_hashval>
  <obj_text>CREATE TABLE nperscurs (
  "codnperscurs" numeric(20,0) NOT NULL,
  "codpers" numeric(20,0),
  "codcurs" numeric(20,0),
  "codtema" numeric(20,0),
  "stare" numeric(1,0),
  "data" date,
  "nota" numeric(10,0),
  "dataplan" date,
  "ore_realiz" numeric(10,0),
  "tipformare" numeric(1,0),
  "nivelformare" numeric(1,0),
  "codobiectiv" numeric(20,0),
  "codfunctie" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nperscvlocm</obj_name>
  <obj_hashval>ce3889e3a0dafd28684aef21db1eb37a</obj_hashval>
  <obj_text>CREATE TABLE nperscvlocm (
  "codperscvlocm" numeric(20,0) NOT NULL,
  "codpers" numeric(20,0),
  "indexlocal" numeric(20,0),
  "dela" date,
  "panala" date,
  "locmunca" character varying(30),
  "codfiscal" character varying(75)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nperscvpas</obj_name>
  <obj_hashval>ef96132c867eb3c86e2a045a64556cae</obj_hashval>
  <obj_text>CREATE TABLE nperscvpas (
  "codperscvpas" numeric(20,0) NOT NULL,
  "codpers" numeric(20,0),
  "indexlocal" numeric(20,0),
  "pasiune" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nperscvscol</obj_name>
  <obj_hashval>10ef79a77638d3ebe83b97145417d2c3</obj_hashval>
  <obj_text>CREATE TABLE nperscvscol (
  "codperscvscol" numeric(20,0) NOT NULL,
  "codpers" numeric(20,0),
  "indexlocal" numeric(20,0),
  "dela" date,
  "panala" date,
  "scoala" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nperscvskil</obj_name>
  <obj_hashval>e0648bd2c3b661f6423825001250e323</obj_hashval>
  <obj_text>CREATE TABLE nperscvskil (
  "codperscvskil" numeric(20,0) NOT NULL,
  "codpers" numeric(20,0),
  "indexlocal" numeric(20,0),
  "skill" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nperssoldluna</obj_name>
  <obj_hashval>2e25289d35f4a3691092f1b02b794c21</obj_hashval>
  <obj_text>CREATE TABLE nperssoldluna (
  "codperssoldluna" numeric(20,0) NOT NULL,
  "codpers" numeric(20,0),
  "icont" numeric(20,0),
  "codmoneda" numeric(20,0),
  "soldlei" numeric(20,3),
  "soldvaluta" numeric(20,3),
  "an" numeric(4,0),
  "luna" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nperssoldlunasub</obj_name>
  <obj_hashval>ede9ceac5b5448726621d9b61cf7f543</obj_hashval>
  <obj_text>CREATE TABLE nperssoldlunasub (
  "codperssoldlunasub" numeric(20,0),
  "codpers" numeric(20,0),
  "icont" numeric(20,0),
  "codmoneda" numeric(20,0),
  "soldlei" numeric(20,3),
  "soldvaluta" numeric(20,3),
  "subunitatea" numeric(20,0),
  "an" numeric(4,0),
  "luna" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nplink</obj_name>
  <obj_hashval>b27d703ec652d42e7c97fdd91174b619</obj_hashval>
  <obj_text>CREATE TABLE nplink (
  "codnirstoc" numeric(20,0),
  "codlivr1" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nrbonlock</obj_name>
  <obj_hashval>f002317b493fa0ebe9ea1244d4f61ddf</obj_hashval>
  <obj_text>CREATE TABLE nrbonlock (
  "codcasamarcat" numeric(20,0),
  "userid" numeric(20,0),
  "usedno" numeric(20,0),
  "connindex" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nrcmdrestlock</obj_name>
  <obj_hashval>b6e1b54959081611578eba77ed7a5b33</obj_hashval>
  <obj_text>CREATE TABLE nrcmdrestlock (
  "codmasa" numeric(20,0),
  "data" date,
  "userid" numeric(20,0),
  "usednr" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nremauto</obj_name>
  <obj_hashval>8cef499cdcbbef4f85bdc47d5b0ca1d2</obj_hashval>
  <obj_text>CREATE TABLE nremauto (
  "codremauto" numeric(20,0) NOT NULL,
  "tipuriremorci" character varying(200),
  "spor_150_1" numeric(10,2),
  "spor_150_2" numeric(10,2),
  "spor150_215_1" numeric(10,2),
  "spor150_215_2" numeric(10,2),
  "spor215_1" numeric(10,2),
  "spor215_2" numeric(10,2)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nrinvlock</obj_name>
  <obj_hashval>80107eb4a8f3fcf485aba5bba5363b23</obj_hashval>
  <obj_text>CREATE TABLE nrinvlock (
  "codinvlock" numeric(20,0) NOT NULL,
  "tip" character varying(2),
  "usedno" numeric(20,0),
  "userid" numeric(20,0),
  "subunitatea" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nscadtl</obj_name>
  <obj_hashval>8744d2241e34db6cb714388805243a08</obj_hashval>
  <obj_text>CREATE TABLE nscadtl (
  "codscadtl" numeric(20,0) NOT NULL,
  "codbanca" numeric(20,0),
  "nrcontr" numeric(20,0),
  "datacontr" date,
  "dataexp" date,
  "moneda" numeric(20,0),
  "valoare" numeric(20,7),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "subunitatea" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nscadtl1</obj_name>
  <obj_hashval>0ce8d10fc94b9bf98b25f47e2b49397b</obj_hashval>
  <obj_text>CREATE TABLE nscadtl1 (
  "codscadtl1" numeric(20,0) NOT NULL,
  "codscadtl" numeric(20,0),
  "datascad" date,
  "rata" numeric(20,7),
  "dobanda" numeric(20,7),
  "total" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nsediipartretail</obj_name>
  <obj_hashval>1eb5d59c6c536622bf2edfe17c7cb930</obj_hashval>
  <obj_text>CREATE TABLE nsediipartretail (
  "codsediu" numeric(20,0) NOT NULL,
  "codpartretail" numeric(20,0),
  "denumire" character varying(100),
  "codlocalit" numeric(20,0),
  "denlocalit" character varying(50),
  "codjudet" numeric(20,0),
  "codtara" numeric(20,0),
  "telefon" character varying(40),
  "fax" character varying(20),
  "email" character varying(350),
  "strada" character varying(100),
  "nr1" numeric(5,0),
  "nr2" character varying(10),
  "bloc" character varying(30),
  "scara" character varying(5),
  "etaj" character varying(10),
  "apart" character varying(10),
  "sector" numeric(2,0),
  "codpostal" character varying(10),
  "sediusocial" numeric(1,0),
  "codagenda" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nserii</obj_name>
  <obj_hashval>98ec30da74c2b9a9482bd920df9bffac</obj_hashval>
  <obj_text>CREATE TABLE nserii (
  "codserie" numeric(20,0) NOT NULL,
  "serie" character varying(75),
  "codobiect" numeric(20,0),
  "obs" character varying(100),
  "codparinte" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nsertar</obj_name>
  <obj_hashval>34bcd33a00946eac620da3516d3dab6f</obj_hashval>
  <obj_text>CREATE TABLE nsertar (
  "codsertar" numeric(20,0) NOT NULL,
  "codemitent" numeric(20,0),
  "codpartener" numeric(20,0),
  "subunitate" numeric(20,0),
  "tip" numeric(1,0),
  "decont" numeric(1,0),
  "doc" character varying(20),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "valoare" numeric(20,7),
  "datadecont" date,
  "depus" numeric(1,0),
  "datacreare" date,
  "userid" numeric(20,0),
  "obs" character varying(500),
  "dataoblig" date,
  "banca" numeric(20,0),
  "moneda" numeric(20,0),
  "nri" character varying(30),
  "indexlocal" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nsubunit</obj_name>
  <obj_hashval>6d9f8d210cd651ffda931234bc7abe39</obj_hashval>
  <obj_text>CREATE TABLE nsubunit (
  "codsubunit" numeric(20,0) NOT NULL,
  "den_subunit" character varying(100),
  "cif" character varying(30),
  "regcom" character varying(20),
  "codbankcont" numeric(20,0),
  "codcatpret" numeric(20,0),
  "satelitwm" numeric(1,0),
  "anpornire" numeric(5,0),
  "lunapornire" numeric(2,0),
  "numepresc" character varying(8),
  "noeconomicactiv" numeric(1,0),
  "codsiui" character varying(15),
  "codcasa" numeric(20,0),
  "capital_social" numeric(20,2),
  "codbankconttrez" numeric(20,0),
  "efact" numeric(1,0),
  "tipunitjuridica" numeric(1,0),
  "codpers" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nsubunit1</obj_name>
  <obj_hashval>73fda0c96664487204bc6d4eb10b7b3b</obj_hashval>
  <obj_text>CREATE TABLE nsubunit1 (
  "codsubunit1" numeric(20,0) NOT NULL,
  "codsubunit" numeric(20,0),
  "codiofilial" numeric(20,0),
  "codcatpret" numeric(20,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "tvalaincasare" numeric(1,0),
  "caen" character varying(5),
  "codtva" numeric(20,0),
  "isfirma" numeric(1,0),
  "grdeclaratie" numeric(3,0),
  "modeditarejurnal" numeric(1,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0),
  "prelcantbcar" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ntari</obj_name>
  <obj_hashval>4d80ac520d9ab41dece2dbad3cfccc3d</obj_hashval>
  <obj_text>CREATE TABLE ntari (
  "codtara" numeric(20,0) NOT NULL,
  "den_tara" character varying(30),
  "simbauto" character varying(3),
  "codmoneda" numeric(20,0),
  "obs" character varying(300),
  "statcomunitar" numeric(1,0),
  "codlimba" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ntaxe</obj_name>
  <obj_hashval>ad93a1b3215996698aadc7c494aecafb</obj_hashval>
  <obj_text>CREATE TABLE ntaxe (
  "codtaxa" numeric(20,0) NOT NULL,
  "den_taxa" character varying(30),
  "centralizat" numeric(1,0),
  "tippart" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ntaxe1</obj_name>
  <obj_hashval>0c84b80fdd230a03b107680cce911ac9</obj_hashval>
  <obj_text>CREATE TABLE ntaxe1 (
  "codtaxa1" numeric(20,0) NOT NULL,
  "codtaxa" numeric(20,0),
  "valoare" numeric(20,7),
  "laceaplic" numeric(1,0),
  "codcont" numeric(20,0),
  "codcontchelt" numeric(20,0),
  "oricaretip" numeric(1,0),
  "codioartexcl" numeric(20,0),
  "exclusaccize" numeric(1,0),
  "exclusexport" numeric(1,0),
  "jachiz" numeric(1,0),
  "jvanz" numeric(1,0),
  "cumjachiz" numeric(1,0),
  "cumjvanz" numeric(1,0),
  "bazamax" numeric(20,7),
  "bazamin" numeric(20,7),
  "codservfact" numeric(20,0),
  "facturabil" numeric(1,0),
  "stopaj" numeric(1,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "serviciumonetar" numeric(20,0),
  "procdiminuareb" numeric(12,2),
  "rotvaloare" numeric(2,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0),
  "bazamed" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ntipsedii</obj_name>
  <obj_hashval>dcfa554a5109378a4947297e29d9971b</obj_hashval>
  <obj_text>CREATE TABLE ntipsedii (
  "codtipsediu" numeric(20,0) NOT NULL,
  "denumire" character varying(30),
  "iclasa" numeric(1,0),
  "contronly" numeric(1,0),
  "tipbeneficiar" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ntipsedii1</obj_name>
  <obj_hashval>fa41d26151d12dfb562173661a26dacb</obj_hashval>
  <obj_text>CREATE TABLE ntipsedii1 (
  "codtipsediu1" numeric(20,0) NOT NULL,
  "codtipsediu" numeric(20,0),
  "codclasea" numeric(20,0),
  "codobiect" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ntva</obj_name>
  <obj_hashval>5467bbc219c7b74fd924ddec19d9f608</obj_hashval>
  <obj_text>CREATE TABLE ntva (
  "codtva" numeric(20,0) NOT NULL,
  "den_tva" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ntva1</obj_name>
  <obj_hashval>82f3e6c8a85a01a2823930eb6e261132</obj_hashval>
  <obj_text>CREATE TABLE ntva1 (
  "codtva1" numeric(20,0) NOT NULL,
  "codtva" numeric(20,0),
  "procent" numeric(6,3),
  "codcontded" numeric(20,0),
  "codcontcole" numeric(20,0),
  "codcontneex" numeric(20,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>num</obj_name>
  <obj_hashval>ae71f0e5f6045ff1acdcbfa68e8d7301</obj_hashval>
  <obj_text>CREATE TABLE num (
  "codum" numeric(20,0) NOT NULL,
  "den_um" character varying(15),
  "tip" character varying(20),
  "zecimale" numeric(4,0),
  "tipum" numeric(1,0),
  "coef" numeric(20,5),
  "codumsaft" numeric(20,0),
  "paritateumsaft" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>num1</obj_name>
  <obj_hashval>89c28c9db2e45febf720a0e3184e9069</obj_hashval>
  <obj_text>CREATE TABLE num1 (
  "codum1" numeric(20,0) NOT NULL,
  "codum" numeric(20,0),
  "secundara" numeric(1,0),
  "den_um1" character varying(15),
  "paritate" numeric(30,15),
  "zecimale" numeric(4,0),
  "obs" character varying(200),
  "codextern" character varying(40),
  "den_eancom" character varying(15),
  "den_intrastat" character varying(15),
  "inactiv" numeric(1,0),
  "codumsaft" numeric(20,0),
  "paritateumsaft" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nzone</obj_name>
  <obj_hashval>3f6e38dc40cbd79bdfc025d1ee952102</obj_hashval>
  <obj_text>CREATE TABLE nzone (
  "codzona" numeric(20,0) NOT NULL,
  "den_zona" character varying(50),
  "simbol" character varying(10),
  "obs" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>obiective</obj_name>
  <obj_hashval>248dfe7ab2e3912a45d8f13eb16c3681</obj_hashval>
  <obj_text>CREATE TABLE obiective (
  "codobiectiv" numeric(20,0) NOT NULL,
  "tip" numeric(1,0),
  "den_obiectiv" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>obj_cmdint1</obj_name>
  <obj_hashval>f8174e3e8b70e00a912083f4f8a83119</obj_hashval>
  <obj_text>CREATE TABLE obj_cmdint1 (
  "codobiect" numeric(20,0),
  "codcmdint1" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>obligpif</obj_name>
  <obj_hashval>62813893dda0200c4f59c38a2a582346</obj_hashval>
  <obj_text>CREATE TABLE obligpif (
  "codobligpif" numeric(20,0) NOT NULL,
  "codgeneral" numeric(20,0),
  "termen" date,
  "valoare" numeric(20,7),
  "rest" numeric(20,7),
  "codpart" numeric(20,0),
  "icont" numeric(20,0),
  "tipplata" numeric(2,0),
  "majorari" numeric(20,7),
  "semnificatie" numeric(20,0),
  "tip" character varying(1),
  "contbanktranzactie" numeric(20,0),
  "codobligasociat" numeric(20,0),
  "valoareafisata" numeric(20,7),
  "gratie" numeric(10,0),
  "codgest" numeric(20,0),
  "codnparcaut" numeric(20,0),
  "codtransa" numeric(20,0),
  "resttransa" numeric(20,7),
  "coefprovizion" numeric(20,7),
  "adaosdoc" numeric(20,7),
  "codcentru" numeric(20,0),
  "codanalizanod" numeric(20,0),
  "tvaneded" numeric(1,0),
  "proctva" numeric(20,7),
  "dincaretva" numeric(20,7),
  "resttva" numeric(20,7),
  "tvaafisat" numeric(20,7),
  "splittva" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>obligpiflock</obj_name>
  <obj_hashval>b63a96a8b07185db47501dfe036f741e</obj_hashval>
  <obj_text>CREATE TABLE obligpiflock (
  "codobligpif" numeric(20,0),
  "codstingatorpif" numeric(20,0),
  "valoare" numeric(20,7),
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>obligpifluna</obj_name>
  <obj_hashval>12a9921ff2058db561d8065ef93a7c11</obj_hashval>
  <obj_text>CREATE TABLE obligpifluna (
  "codobligpif" numeric(20,0),
  "an" numeric(5,0),
  "luna" numeric(2,0),
  "rest" numeric(20,7),
  "resttva" numeric(20,7),
  "restsplittva" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>oferta</obj_name>
  <obj_hashval>5d8663440a57d0910884fa71e1f9e414</obj_hashval>
  <obj_text>CREATE TABLE oferta (
  "codoferta" numeric(20,0) NOT NULL,
  "tipdoc" numeric(20,0),
  "anulat" numeric(20,0),
  "blocat" numeric(20,0),
  "operat" numeric(20,0),
  "nrdoc" numeric(20,0),
  "datastart" date,
  "dataend" date,
  "partener" numeric(20,0),
  "an" numeric(20,0),
  "luna" numeric(20,0),
  "obs" character varying(500),
  "moneda" numeric(20,0),
  "codlocatie" numeric(20,0),
  "subunitatea" numeric(20,0),
  "codfiscal" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "carnetdoc" numeric(20,0),
  "seriadoc" character varying(20),
  "codpersc" numeric(20,0),
  "datacerere" date,
  "dataoferta" date,
  "ofertat" numeric(1,0),
  "toatesubunit" numeric(1,0),
  "agent" numeric(20,0),
  "tiplivrare" numeric(2,0),
  "nrmaxaprobari" numeric(5,0),
  "tipbeneficiar" numeric(1,0),
  "codclasep" numeric(20,0),
  "nri" character varying(30),
  "codnparcaut" numeric(20,0),
  "codpartcomis" numeric(20,0),
  "procdisc" numeric(20,7),
  "codanaliza" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>oferta1</obj_name>
  <obj_hashval>910650c48b99dcf05513e3d3956d7d3f</obj_hashval>
  <obj_text>CREATE TABLE oferta1 (
  "codoferta1" numeric(20,0) NOT NULL,
  "codoferta" numeric(20,0),
  "codobiect" numeric(20,0),
  "umsec" numeric(20,0),
  "cantmin" numeric(20,7),
  "pret" numeric(20,7),
  "obs" character varying(200),
  "zilel" numeric(10,0),
  "zilec" numeric(10,0),
  "procadaos" numeric(20,2),
  "procdiscount" numeric(25,7),
  "codextofe" character varying(30),
  "cantminum1" numeric(20,7),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7),
  "cantoptim" numeric(20,7),
  "cantmax" numeric(20,7),
  "codcatpret" numeric(20,0),
  "pretum1" numeric(20,7),
  "cantoptimum1" numeric(20,7),
  "codarticol" numeric(20,0),
  "codproiect" numeric(20,0),
  "pretref" numeric(20,7),
  "indexlocal" numeric(5,0),
  "datacertifi" date,
  "datacertiff" date,
  "codcentru" numeric(20,0),
  "pretachiz" numeric(20,7),
  "codanalizanod" numeric(20,0),
  "gestact" numeric(20,0),
  "codliniedocimp" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>oportunitati</obj_name>
  <obj_hashval>67b6af945b9868063a3f7375e2af7099</obj_hashval>
  <obj_text>CREATE TABLE oportunitati (
  "codoportunitate" numeric(20,0) NOT NULL,
  "prefixdoc" character varying(2),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "codcarnetdoc" numeric(20,0),
  "codpartener" numeric(20,0),
  "codmoneda" numeric(20,0),
  "tip" numeric(1,0),
  "codagent" numeric(20,0),
  "codcampanie" numeric(20,0),
  "venitest" numeric(20,7),
  "venitprob" numeric(3,0),
  "codsubunitate" numeric(20,0),
  "codoferta" numeric(20,0),
  "codcomanda" numeric(20,0),
  "an" numeric(20,0),
  "luna" numeric(20,0),
  "probvanz" numeric(3,0),
  "datasemnare" date,
  "codcontract" numeric(20,0),
  "seriadoc" character varying(20),
  "codlead" numeric(20,0),
  "codtask" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" date,
  "codproiectcrm" numeric(20,0),
  "codclaseopt" numeric(20,0),
  "codlocatie" numeric(20,0),
  "obs" character varying(500),
  "curs" numeric(20,7),
  "codfiscal" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>opper</obj_name>
  <obj_hashval>c6402bfd736c087ac7cbf52768d3a737</obj_hashval>
  <obj_text>CREATE TABLE opper (
  "codopper" numeric(20,0),
  "obs" character varying(100),
  "an" numeric(4,0),
  "valoare" numeric(20,7),
  "subunitatea" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>opper1</obj_name>
  <obj_hashval>66e5bc2f01ab0afa28cca3f86efd7afe</obj_hashval>
  <obj_text>CREATE TABLE opper1 (
  "codopper1" numeric(20,0),
  "codopper" numeric(20,0),
  "saptamana" numeric(2,0),
  "tipoper" numeric(2,0),
  "valoare" numeric(20,7),
  "termen" date,
  "obs" character varying(250),
  "codelembuget" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>opreg</obj_name>
  <obj_hashval>644b1f8d737f24cbc184c7db30f33cff</obj_hashval>
  <obj_text>CREATE TABLE opreg (
  "codop" numeric(20,0) NOT NULL,
  "codpart" numeric(20,0),
  "codbanca" numeric(20,0),
  "obs" character varying(100),
  "tiptranz" numeric(1,0),
  "tipdecont" numeric(3,0),
  "zidecont" numeric(2,0),
  "codmoneda" numeric(20,0),
  "valoare" numeric(20,7),
  "an_start" numeric(4,0),
  "luna_start" numeric(2,0),
  "an_max" numeric(4,0),
  "luna_max" numeric(2,0),
  "subunitatea" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>opreg1</obj_name>
  <obj_hashval>e8c25411c957ac0bb71171d811945aa9</obj_hashval>
  <obj_text>CREATE TABLE opreg1 (
  "codop1" numeric(20,0) NOT NULL,
  "codop" numeric(20,0),
  "termen" date,
  "stins" numeric(1,0),
  "obs" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>orar</obj_name>
  <obj_hashval>8d92bf05ec83bd4cbafd279c73fc54a0</obj_hashval>
  <obj_text>CREATE TABLE orar (
  "codorar" numeric(20,0) NOT NULL,
  "denumire" character varying(50),
  "obs" character varying(50),
  "repetare" numeric(1,0),
  "interval" numeric(4,0),
  "ora" numeric(2,0),
  "min" numeric(2,0),
  "zile_sapt" character varying(30),
  "zile_luna" character varying(300),
  "data_start" timestamp(0) without time zone,
  "data_fin" timestamp(0) without time zone,
  "datacreare" timestamp(0) without time zone,
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>orelm</obj_name>
  <obj_hashval>24a8cc1317e7a7699f22b5da46ff4704</obj_hashval>
  <obj_text>CREATE TABLE orelm (
  "codorelm" numeric(20,0) NOT NULL,
  "datalm" date NOT NULL,
  "codlm" numeric(20,0),
  "codlm1" numeric(20,0),
  "ore" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>orepontaj</obj_name>
  <obj_hashval>62b59ae07e8c669d70defbaabc0d7e89</obj_hashval>
  <obj_text>CREATE TABLE orepontaj (
  "codformatie" numeric(20,0) NOT NULL,
  "codpers" numeric(20,0),
  "ore" numeric(5,0),
  "salar" numeric(20,7),
  "an" numeric(5,0),
  "luna" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ospatari</obj_name>
  <obj_hashval>36d2da33796598dcb1b00e5c3cd8546f</obj_hashval>
  <obj_text>CREATE TABLE ospatari (
  "cod" numeric(20,0),
  "codpers" numeric(20,0),
  "parola" character varying(50),
  "codrestaurant" numeric(20,0),
  "supervizor" numeric(1,0),
  "verlistnp" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nirstoc_codlocatie</obj_name>
  <obj_reftable>nirstoc</obj_reftable>
  <obj_hashval>cbb913fc36c562d677b1326e788ed55c</obj_hashval>
  <obj_text>CREATE INDEX idx_nirstoc_codlocatie ON nirstoc USING btree (codlocatie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nirstoc_codnir</obj_name>
  <obj_reftable>nirstoc</obj_reftable>
  <obj_hashval>078b8fcd46232935558119a22db6c4ca</obj_hashval>
  <obj_text>CREATE INDEX idx_nirstoc_codnir ON nirstoc USING btree (codnir)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nirstoc_codnirstocparinte</obj_name>
  <obj_reftable>nirstoc</obj_reftable>
  <obj_hashval>7ed597178c8e368369b61cba986ded42</obj_hashval>
  <obj_text>CREATE INDEX idx_nirstoc_codnirstocparinte ON nirstoc USING btree (COALESCE(codnirstocparinte, (0)::numeric))</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>pachete</obj_name>
  <obj_hashval>4ce270d0f26ebb73a7d7fa5be2feaaaa</obj_hashval>
  <obj_text>CREATE TABLE pachete (
  "codpachete" numeric(20,0) NOT NULL,
  "datap" timestamp(6) without time zone,
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "subunitate" numeric(20,0),
  "gestiune" numeric(20,0),
  "carnetdoc" numeric(20,0),
  "nrdoc" numeric(10,0),
  "colector" numeric(20,0),
  "datacolectare" timestamp(6) without time zone,
  "verificator" numeric(20,0),
  "dataverificare" timestamp(6) without time zone,
  "transportator" numeric(20,0),
  "datatransport" timestamp(6) without time zone,
  "nrpachete" numeric(10,0),
  "operat" numeric(1,0),
  "blocat" numeric(1,0),
  "anulat" numeric(1,0),
  "identificatorp" character varying(50),
  "listat" numeric(1,0),
  "an" numeric(20,0),
  "luna" numeric(20,0),
  "codpart" numeric(20,0),
  "tippart" character varying(100),
  "sediu" numeric(20,0),
  "delegat" numeric(20,0),
  "tiplivrare" numeric(10,0),
  "tippachet" numeric(1,0),
  "sponsorizare" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>pachete1</obj_name>
  <obj_hashval>66010e4b45c42208b1b3f682eea75220</obj_hashval>
  <obj_text>CREATE TABLE pachete1 (
  "codpachete1" numeric(20,0) NOT NULL,
  "codpachete" numeric(20,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>pachetedllink</obj_name>
  <obj_hashval>aadce1b36854818fe5638b48684d2df0</obj_hashval>
  <obj_text>CREATE TABLE pachetedllink (
  "codcomanda1" numeric(20,0) NOT NULL,
  "codpacheteobj" numeric(20,0),
  "cant" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>pachetelink</obj_name>
  <obj_hashval>b2acf40f1cd94d19d24d92713f50665d</obj_hashval>
  <obj_text>CREATE TABLE pachetelink (
  "codies1" numeric(20,0) NOT NULL,
  "codpacheteobj" numeric(20,0),
  "cant" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>pacheteobj</obj_name>
  <obj_hashval>1cccfc05113f2e8bd2c660a48cac7e70</obj_hashval>
  <obj_text>CREATE TABLE pacheteobj (
  "codpacheteobj" numeric(20,0) NOT NULL,
  "codpachete" numeric(20,0),
  "codnirstoc" numeric(20,0),
  "cant" numeric(20,7),
  "rest" numeric(20,7),
  "cantum1" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>pacheteobjl</obj_name>
  <obj_hashval>b256de2c25bd3c1637c0a24c14c40c4e</obj_hashval>
  <obj_text>CREATE TABLE pacheteobjl (
  "codpacheteobjl" numeric(20,0) NOT NULL,
  "codpachete" numeric(20,0),
  "codlivr1" numeric(20,0),
  "cant" numeric(20,7),
  "rest" numeric(20,7),
  "cantum1" numeric(20,7),
  "pachet" numeric(10,0),
  "codrezervats" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>pacheteobjlink</obj_name>
  <obj_hashval>42aa759a889350dd6051039fa875bf88</obj_hashval>
  <obj_text>CREATE TABLE pacheteobjlink (
  "codies1" numeric(20,0) NOT NULL,
  "codpacheteobjl" numeric(20,0),
  "cant" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>packing</obj_name>
  <obj_hashval>cfcef55fdd8e9a903f672083b0f58de8</obj_hashval>
  <obj_text>CREATE TABLE packing (
  "codpacking" numeric(20,0) NOT NULL,
  "coddoc" numeric(20,0),
  "tipdoc" numeric(20,0),
  "obs" character varying(200),
  "dirty" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>packing2</obj_name>
  <obj_hashval>9b69d376efd0e041fa8d799eefc69a78</obj_hashval>
  <obj_text>CREATE TABLE packing2 (
  "codpacking2" numeric(20,0) NOT NULL,
  "codpacking1" numeric(20,0),
  "sscc" character varying(18),
  "obs" character varying(2500),
  "codamb_final" numeric(20,0),
  "cantobj" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>packing3</obj_name>
  <obj_hashval>14b7e9bdddd2dea8d319c086a3446668</obj_hashval>
  <obj_text>CREATE TABLE packing3 (
  "codpacking3" numeric(20,0) NOT NULL,
  "codpacking2" numeric(20,0),
  "codrezervats" numeric(20,0),
  "cant" numeric(20,7),
  "umsec" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>paramliste</obj_name>
  <obj_hashval>840597e61e45fb3bf124e52c71429ded</obj_hashval>
  <obj_text>CREATE TABLE paramliste (
  "codparamliste" numeric(20,0) NOT NULL,
  "userid" numeric(20,0),
  "listid" numeric(20,0),
  "listver" numeric(20,0),
  "data1" date,
  "data2" date,
  "an1" numeric(4,0),
  "luna1" numeric(2,0),
  "an2" numeric(4,0),
  "luna2" numeric(2,0),
  "int1data1" date,
  "int1data2" date,
  "int1an1" numeric(4,0),
  "int1luna1" numeric(2,0),
  "int1an2" numeric(4,0),
  "int1luna2" numeric(2,0),
  "int2data1" date,
  "int2data2" date,
  "int2an1" numeric(4,0),
  "int2luna1" numeric(2,0),
  "int2an2" numeric(4,0),
  "int2luna2" numeric(2,0),
  "int3data1" date,
  "int3data2" date,
  "int3an1" numeric(4,0),
  "int3luna1" numeric(2,0),
  "int3an2" numeric(4,0),
  "int3luna2" numeric(2,0),
  "int4data1" date,
  "int4data2" date,
  "int4an1" numeric(4,0),
  "int4luna1" numeric(2,0),
  "int4an2" numeric(4,0),
  "int4luna2" numeric(2,0),
  "int5data1" date,
  "int5data2" date,
  "int5an1" numeric(4,0),
  "int5luna1" numeric(2,0),
  "int5an2" numeric(4,0),
  "int5luna2" numeric(2,0),
  "val1" character varying(100),
  "val2" character varying(100),
  "val3" character varying(100),
  "val4" character varying(100),
  "val5" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>particip</obj_name>
  <obj_hashval>aa323675935592463393f9794696bbbe</obj_hashval>
  <obj_text>CREATE TABLE particip (
  "cod" numeric(20,0),
  "denumire" character varying(200),
  "procent" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>partpuncte</obj_name>
  <obj_hashval>bbd452431ae7c51797716cb663ce0fe4</obj_hashval>
  <obj_text>CREATE TABLE partpuncte (
  "cod" numeric(20,0),
  "codpart" numeric(20,0),
  "data" date,
  "codemulare" numeric(20,0),
  "puncte" numeric(20,0),
  "codpunctaj" numeric(20,0),
  "valoare" numeric(20,7),
  "codpostretail" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>parttot</obj_name>
  <obj_hashval>2a00121e58bfe6bc7793b10ee80dcdde</obj_hashval>
  <obj_text>CREATE TABLE parttot (
  "codparttot" numeric(20,0) NOT NULL,
  "codpart" numeric(20,0),
  "soldreal" numeric(20,2),
  "neoperat" numeric(20,2),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>pass_modif</obj_name>
  <obj_hashval>0ea76eb04d9bf50a01e6681d45edaab5</obj_hashval>
  <obj_text>CREATE TABLE pass_modif (
  "datamodif" timestamp(0) without time zone,
  "persmodif" numeric(10,0),
  "codmaster" numeric(20,0),
  "tablename" character varying(20),
  "fieldname" character varying(20),
  "oldvalue" character varying(30),
  "newvalue" character varying(30),
  "explic" text
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nirstoc_codobiect</obj_name>
  <obj_reftable>nirstoc</obj_reftable>
  <obj_hashval>87160e73b4bbdc2ef0abb2d6b36f8728</obj_hashval>
  <obj_text>CREATE INDEX idx_nirstoc_codobiect ON nirstoc USING btree (codobiect, rest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nirstoc_codsubunit</obj_name>
  <obj_reftable>nirstoc</obj_reftable>
  <obj_hashval>20895386054cb40913fb803061380ccf</obj_hashval>
  <obj_text>CREATE INDEX idx_nirstoc_codsubunit ON nirstoc USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>pcalcul</obj_name>
  <obj_hashval>d3db8acc078eb606ac1135fd8f2bc859</obj_hashval>
  <obj_text>CREATE TABLE pcalcul (
  "codpc" numeric(20,0) NOT NULL,
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "subunitatea" numeric(20,0),
  "cumulat" numeric(1,0),
  "operat" numeric(1,0),
  "varianta" numeric(20,0),
  "datadoc" date,
  "tippunct" numeric(3,0),
  "observatii" character varying(50),
  "tipaloc" numeric(2,0),
  "valf" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>pcart</obj_name>
  <obj_hashval>5cdb8c6f4badc139ce1965c2acffbc41</obj_hashval>
  <obj_text>CREATE TABLE pcart (
  "codpcart" numeric(20,0) NOT NULL,
  "codpc" numeric(20,0),
  "codcmd1" numeric(20,0),
  "codioart" numeric(20,0),
  "cant" numeric(20,7),
  "val" numeric(20,7),
  "vals" numeric(20,7),
  "vali" numeric(20,7),
  "vala" numeric(20,7),
  "valc" numeric(20,7),
  "valg" numeric(20,7),
  "mat" numeric(20,7),
  "puncte" numeric(20,7),
  "codgest" numeric(20,0),
  "codcc" numeric(20,0),
  "codformatie" numeric(20,0),
  "coef" numeric(20,7),
  "man" numeric(20,7),
  "valman" numeric(20,7),
  "canttot" numeric(20,7),
  "codcmdprodmat" numeric(20,0),
  "valtot" numeric(20,7),
  "vallinie" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>pcdir</obj_name>
  <obj_hashval>9a179deac0244ac76bc423a6adafc323</obj_hashval>
  <obj_text>CREATE TABLE pcdir (
  "codpcdir" numeric(20,0) NOT NULL,
  "codpc" numeric(20,0),
  "codnest" numeric(20,0),
  "codcmd1" numeric(20,0),
  "val" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>pcgest</obj_name>
  <obj_hashval>c4017479323f308cf35006d5e55bd50a</obj_hashval>
  <obj_text>CREATE TABLE pcgest (
  "codpcgest" numeric(20,0) NOT NULL,
  "codpc" numeric(20,0),
  "codgest" numeric(20,0),
  "mans" numeric(20,7),
  "vali" numeric(20,7),
  "vala" numeric(20,7),
  "valc" numeric(20,7),
  "valg" numeric(20,7),
  "valmat" numeric(20,7),
  "valman" numeric(20,7),
  "puncte" numeric(20,7),
  "valmatn" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>pcsectii</obj_name>
  <obj_hashval>56716464e1636546ca818f3a181f0217</obj_hashval>
  <obj_text>CREATE TABLE pcsectii (
  "codpcsectii" numeric(20,0) NOT NULL,
  "codpc" numeric(20,0),
  "codnest" numeric(20,0),
  "val" numeric(20,7),
  "faza" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>perisabil</obj_name>
  <obj_hashval>30d84159d2f5bce564da83aae26ade00</obj_hashval>
  <obj_text>CREATE TABLE perisabil (
  "codperisabil" numeric(20,0) NOT NULL,
  "denumire" character varying(200),
  "obs" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>perisabil1</obj_name>
  <obj_hashval>6a8bbcdf7dee2c375e81d5a6f3462b27</obj_hashval>
  <obj_text>CREATE TABLE perisabil1 (
  "codperisabil1" numeric(20,0) NOT NULL,
  "codperisabil" numeric(20,0),
  "luna_ini" numeric(20,0),
  "luna_fin" numeric(20,0),
  "nrzile" numeric(3,0),
  "obs1" character varying(200),
  "nrziledir" numeric(3,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>perisabil2</obj_name>
  <obj_hashval>6a52d4a21e3301ba85c55b72b94ee0f5</obj_hashval>
  <obj_text>CREATE TABLE perisabil2 (
  "codperisabil2" numeric(20,0) NOT NULL,
  "codperisabil" numeric(20,0),
  "luna_ini" numeric(2,0),
  "luna_fin" numeric(2,0),
  "zi_ini" numeric(2,0),
  "zi_fin" numeric(2,0),
  "stocmediu" numeric(20,7),
  "tipsezon" numeric(1,0),
  "obs1" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>pgs</obj_name>
  <obj_hashval>4dbef2f009931394d7ee6c98b28316d3</obj_hashval>
  <obj_text>CREATE TABLE pgs (
  "codpgs" numeric(20,0) NOT NULL,
  "denumire" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>pgs1</obj_name>
  <obj_hashval>c2c2fe3ab5afd7e2097877e8347ebf5b</obj_hashval>
  <obj_text>CREATE TABLE pgs1 (
  "codpgs1" numeric(20,0) NOT NULL,
  "codpgs" numeric(20,0),
  "indexlocal" numeric(20,0),
  "codcurs" numeric(20,0),
  "codtema" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>plancurs</obj_name>
  <obj_hashval>d5c7eae289460980ad658800e1a73333</obj_hashval>
  <obj_text>CREATE TABLE plancurs (
  "codplancurs" numeric(20,0) NOT NULL,
  "codpers" numeric(20,0),
  "nr" numeric(20,0),
  "datacurs" date,
  "tip" character varying(100),
  "an" numeric(4,0),
  "luna" character varying(20)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>plancurs1</obj_name>
  <obj_hashval>5d3024687f62ec8f8ded329c6f245b19</obj_hashval>
  <obj_text>CREATE TABLE plancurs1 (
  "codplancurs1" numeric(20,0) NOT NULL,
  "codplancurs" numeric(20,0),
  "codtema" numeric(20,0),
  "dataplan" date,
  "stare" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>planiflink</obj_name>
  <obj_hashval>9fa056620304176b3b848061fa6f2237</obj_hashval>
  <obj_text>CREATE TABLE planiflink (
  "codcomanda1" numeric(20,0),
  "codstare1" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>planiflock</obj_name>
  <obj_hashval>0c941531b06b44ca66c0db8601db2265</obj_hashval>
  <obj_text>CREATE TABLE planiflock (
  "userid" numeric(20,0),
  "codgest" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>planifprod</obj_name>
  <obj_hashval>bc653ced6ad13d80519f08c2f5aa4847</obj_hashval>
  <obj_text>CREATE TABLE planifprod (
  "codplanifprod" numeric(20,0) NOT NULL,
  "codlansprod" numeric(20,0),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "subunitatea" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" date,
  "obs" character varying(250),
  "anulat" numeric(1,0),
  "blocat" numeric(1,0),
  "operat" numeric(1,0),
  "saptamana" numeric(10,0),
  "nrdoc" numeric(10,0),
  "datadoc" date,
  "carnetdoc" numeric(20,0),
  "seriadoc" character varying(20),
  "prefixdoc" character varying(3),
  "insaptamana" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>planifprod1</obj_name>
  <obj_hashval>5492cc190d2d278acb6c98069dc4d046</obj_hashval>
  <obj_text>CREATE TABLE planifprod1 (
  "codplanifprod1" numeric(20,0) NOT NULL,
  "codplanifprod" numeric(20,0),
  "codlansprod1" numeric(20,0),
  "codobiect" numeric(20,0),
  "codreteta" numeric(20,0),
  "obs" character varying(250),
  "necesar" numeric(20,7),
  "cant" numeric(20,7),
  "cuproiect" numeric(1,0),
  "codproiect" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>planifprodlun</obj_name>
  <obj_hashval>0e75f08bf0e4bf7fe584a7a501b2303a</obj_hashval>
  <obj_text>CREATE TABLE planifprodlun (
  "codobiect" numeric(20,0),
  "plweek1" numeric(20,7),
  "plweek2" numeric(20,7),
  "plweek3" numeric(20,7),
  "plweek4" numeric(20,7),
  "plweek5" numeric(20,7),
  "anluna" numeric(20,0),
  "planificat" numeric(20,7),
  "lansare" numeric(20,7),
  "codgest" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>planifstruct</obj_name>
  <obj_hashval>507db8dbc68cced889491b9a21994db7</obj_hashval>
  <obj_text>CREATE TABLE planifstruct (
  "codobiect" numeric(20,0),
  "codreteta" numeric(20,0),
  "an" numeric(4,0),
  "saptamana" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>plati</obj_name>
  <obj_hashval>b9c5624370fe137cc2d959fcf1044003</obj_hashval>
  <obj_text>CREATE TABLE plati (
  "codplata" numeric(20,0),
  "data" date,
  "codbankcont" numeric(20,0),
  "valoare" numeric(20,7),
  "carnetdoc" numeric(20,0),
  "nrdoc" numeric(20,0),
  "an" numeric(5,0),
  "luna" numeric(2,0),
  "subunitatea" numeric(20,0),
  "valoarederepartizat" numeric(20,0),
  "aprobat" numeric(1,0),
  "tipdoc" numeric(2,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "codanaliza" numeric(20,0),
  "obs" character varying(500),
  "curs" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>plati1</obj_name>
  <obj_hashval>08c80c4a292378e7519363ff7a75f89c</obj_hashval>
  <obj_text>CREATE TABLE plati1 (
  "codplata1" numeric(20,0),
  "codplata" numeric(20,0),
  "codobligpif" numeric(20,0),
  "valoare" numeric(20,7),
  "codmoneda" numeric(20,0),
  "contdest" character varying(50),
  "adresafurn" character varying(200),
  "indexlocal" numeric(20,0),
  "stinsa" numeric(1,0),
  "codswift" character varying(30),
  "codbnr" character varying(30),
  "codstatisticbnr" character varying(30),
  "codbank" numeric(20,0),
  "tipcomision" character varying(6),
  "codpart" numeric(20,0),
  "splittva" numeric(1,0),
  "rest" numeric(20,7),
  "dincaretva" numeric(20,7),
  "codanalizanodx" numeric(20,0),
  "codpers" numeric(20,0),
  "codcont" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>plati2</obj_name>
  <obj_hashval>26b1473126c77b9d461c95871fe0515f</obj_hashval>
  <obj_text>CREATE TABLE plati2 (
  "codplata2" numeric(20,0),
  "codplata" numeric(20,0),
  "codpers" numeric(20,0),
  "contdest" character varying(30),
  "codswift" character varying(30),
  "valoare" numeric(20,7),
  "nrdoc" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>plucase</obj_name>
  <obj_hashval>15dc009c33f2b29602764dbb9f025dc8</obj_hashval>
  <obj_text>CREATE TABLE plucase (
  "codplucase" numeric(20,0),
  "codcasa" numeric(20,0),
  "codobiect" numeric(20,0),
  "codplu" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nirstoc_codtransf1</obj_name>
  <obj_reftable>nirstoc</obj_reftable>
  <obj_hashval>28401f75fd543c83897045dd8d86ba1d</obj_hashval>
  <obj_text>CREATE INDEX idx_nirstoc_codtransf1 ON nirstoc USING btree (codtransf1)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>pmp_all_luna</obj_name>
  <obj_hashval>5c5e6d6bf944ec84a1f31229c95c2ecf</obj_hashval>
  <obj_text>CREATE TABLE pmp_all_luna (
  "codpmp_all_luna" numeric(20,0),
  "codobiect" numeric(20,0),
  "cantintr" numeric(20,7),
  "valintr" numeric(20,7),
  "rest" numeric(20,7),
  "an" numeric(5,0),
  "luna" numeric(2,0),
  "valvaluta" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>pmpluna</obj_name>
  <obj_hashval>91ac2b146e655c0e814c37c9f1186c88</obj_hashval>
  <obj_text>CREATE TABLE pmpluna (
  "codpmpluna" numeric(20,0),
  "codobiect" numeric(20,0),
  "codsubunit" numeric(20,0),
  "cantintr" numeric(20,7),
  "valintr" numeric(20,7),
  "rest" numeric(20,7),
  "an" numeric(5,0),
  "luna" numeric(2,0),
  "valvaluta" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>posbancar</obj_name>
  <obj_hashval>fb0e85ec0010835cbd9b93abaafc4792</obj_hashval>
  <obj_text>CREATE TABLE posbancar (
  "codposbancar" numeric(5,0) NOT NULL,
  "indexlocal" numeric(2,0),
  "tippos" numeric(3,0),
  "portserial" numeric(2,0),
  "ip" character varying(50),
  "inactiv" numeric(1,0),
  "userid" numeric(20,0),
  "remote" numeric(1,0),
  "ipserverpos" character varying(50),
  "portserverpos" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>postretail</obj_name>
  <obj_hashval>30b0efb0141b6c64189690e124418136</obj_hashval>
  <obj_text>CREATE TABLE postretail (
  "cod" numeric(20,0),
  "denumire" character varying(50),
  "id" numeric(3,0),
  "numefirma" character varying(30),
  "subunitatea" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>pplink</obj_name>
  <obj_hashval>9a51216e4614c642bcac1697cbbc9b1e</obj_hashval>
  <obj_text>CREATE TABLE pplink (
  "idinreg" numeric(20,0) NOT NULL,
  "codcomanda1" numeric(20,0),
  "codintr1" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>precmdlink</obj_name>
  <obj_hashval>52010859f50d129eddf445ca8c134a8c</obj_hashval>
  <obj_text>CREATE TABLE precmdlink (
  "codcomanda1" numeric(20,0) NOT NULL,
  "codprecomanda1" numeric(20,0),
  "cant" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>precomanda</obj_name>
  <obj_hashval>c0145cf7ad1852ec090a8baf27a234a6</obj_hashval>
  <obj_text>CREATE TABLE precomanda (
  "codprecomanda" numeric(20,0) NOT NULL,
  "tipdoc" numeric(20,0),
  "anulat" numeric(20,0),
  "blocat" numeric(20,0),
  "operat" numeric(20,0),
  "prefixdoc" character varying(2),
  "nrdoc" numeric(20,0),
  "carnetdoc" numeric(20,0),
  "datadoc" date,
  "valoare" numeric(20,7),
  "an" numeric(20,0),
  "luna" numeric(20,0),
  "obs" character varying(200),
  "moneda" numeric(20,0),
  "subunitatea" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "inchisa" numeric(1,0),
  "seriadoc" character varying(20),
  "verificat" numeric(1,0),
  "codstare1" numeric(20,0),
  "saptamanac" numeric(2,0),
  "anc" numeric(4,0),
  "saptamanag" numeric(10,0),
  "ang" numeric(4,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>precomanda1</obj_name>
  <obj_hashval>10168cc3de4850b3838d0c74cff5360d</obj_hashval>
  <obj_text>CREATE TABLE precomanda1 (
  "codprecomanda1" numeric(20,0) NOT NULL,
  "codprecomanda" numeric(20,0),
  "indexlocal" numeric(5,0),
  "codobiect" numeric(20,0),
  "umsec" numeric(10,0),
  "pu" numeric(21,7),
  "cant" numeric(20,7),
  "rest" numeric(20,7),
  "termen" date,
  "addim" numeric(20,7),
  "procdisc" numeric(20,7),
  "obs" character varying(200),
  "pretorig" numeric(20,7),
  "coefdiscmaj" numeric(20,7),
  "scadenta" numeric(5,0),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7),
  "cantum1" numeric(20,7),
  "codcontract1" numeric(20,0),
  "codcentru" numeric(20,0),
  "codoferta1" numeric(20,0),
  "pretum1" numeric(20,7),
  "codpart" numeric(20,0),
  "codpromo1" numeric(20,0),
  "moneda" numeric(20,0),
  "codstare1" numeric(20,0),
  "codlocatie" numeric(20,0),
  "cantmin" numeric(20,7),
  "datastart" date
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>predariplus</obj_name>
  <obj_hashval>4f6a98d338525980a5dfaaf7a22ceee9</obj_hashval>
  <obj_text>CREATE TABLE predariplus (
  "idinreg" numeric(20,0) NOT NULL,
  "nrdoc" character varying(50),
  "datadoc" date,
  "codafa" character varying(50),
  "codextern" character varying(100),
  "ua" character varying(15),
  "sectie" character varying(15),
  "cantitate" numeric(20,7),
  "datamodif" timestamp(6) without time zone,
  "nrcmd" character varying(50),
  "datacmd" date,
  "fsc" character varying(500),
  "schimb" character varying(50),
  "formatie" character varying(100),
  "nrnp" character varying(50),
  "datanp" date,
  "useridblocaj" numeric(20,0),
  "codcomanda1" numeric(20,0),
  "cantitatewme" numeric(20,7),
  "datawme" timestamp(6) without time zone,
  "linia" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>pretm</obj_name>
  <obj_hashval>bf7c25c1a533d834aeadc860f4d79a25</obj_hashval>
  <obj_text>CREATE TABLE pretm (
  "codpretm" numeric(20,0) NOT NULL,
  "codobiect" numeric(20,0),
  "codcatpret" numeric(20,0),
  "lei" numeric(20,7),
  "valuta" numeric(20,7),
  "moneda" numeric(20,0),
  "implicit" numeric(1,0),
  "proc" numeric(20,7),
  "indexlocal" numeric(5,0),
  "subunitatea" numeric(20,0),
  "grupa" character varying(10),
  "rotunjire" numeric(2,0),
  "sumafixaimplicit" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>pretm_autoupd_log</obj_name>
  <obj_hashval>dc6dec2a29781be20d5deeb27ab856e7</obj_hashval>
  <obj_text>CREATE TABLE pretm_autoupd_log (
  "cod_moneda" numeric NOT NULL,
  "cod_banca" numeric NOT NULL,
  "run_date" date NOT NULL,
  "started_by" character varying(30) NOT NULL,
  "start_ts" timestamp(6) without time zone NOT NULL,
  "end_ts" timestamp(6) without time zone,
  "status" character varying(10) NOT NULL,
  "error_msg" character varying(4000)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>pretmamb</obj_name>
  <obj_hashval>cf815294232bd939c0863b0f1e5459c4</obj_hashval>
  <obj_text>CREATE TABLE pretmamb (
  "codpretmamb" numeric(20,0) NOT NULL,
  "codpretm" numeric(20,0),
  "codamb" numeric(20,0),
  "lei" numeric(20,7),
  "valuta" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>proc_act_def</obj_name>
  <obj_hashval>292f7a8dc9e24c9d0d7f1b7ee6aaa9b2</obj_hashval>
  <obj_text>CREATE TABLE proc_act_def (
  "codprocactdef" numeric(20,0),
  "denumire" character varying(200),
  "codintern" character varying(200),
  "sql" text
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nirstoc_pret</obj_name>
  <obj_reftable>nirstoc</obj_reftable>
  <obj_hashval>f0b3f04d6dcda624b96e058788719ee4</obj_hashval>
  <obj_text>CREATE INDEX idx_nirstoc_pret ON nirstoc USING btree (pret)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nirstoc_umsec</obj_name>
  <obj_reftable>nirstoc</obj_reftable>
  <obj_hashval>5286773ed724a3e78ae8c5e6aeb33f9e</obj_hashval>
  <obj_text>CREATE INDEX idx_nirstoc_umsec ON nirstoc USING btree (umsec)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>prodcomp</obj_name>
  <obj_hashval>b2eaf0192f3dbe8e8f88135a57e98aed</obj_hashval>
  <obj_text>CREATE TABLE prodcomp (
  "codprodcomp" numeric(20,0) NOT NULL,
  "codobiect" numeric(20,0),
  "obs" character varying(250),
  "data" date,
  "anulat" numeric(1,0),
  "blocat" numeric(1,0),
  "operat" numeric(1,0),
  "cant" numeric(20,7),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7),
  "tipreteta" numeric(1,0),
  "cantum1" numeric(20,7),
  "pret" numeric(20,7),
  "coefindirecte" numeric(20,7),
  "implicit" numeric(1,0),
  "descriere" text,
  "inactiv" numeric(1,0),
  "gest" numeric(20,0),
  "identificator" character varying(100),
  "datadocumentatie" date,
  "arhiva" character varying(50),
  "observatii" character varying(3000),
  "proiectant" numeric(20,0),
  "codclasaprod" numeric(20,0),
  "invizibila" numeric(1,0),
  "generic" numeric(1,0),
  "durata" numeric(20,7),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "hfactor" numeric(2,0),
  "valmat" numeric(20,7),
  "valman" numeric(20,7),
  "valregie" numeric(20,7),
  "tippret" numeric(1,0),
  "codproiect" numeric(20,0),
  "obs1" character varying(250),
  "obs2" character varying(250),
  "obs3" character varying(250),
  "obs4" character varying(250),
  "obs5" character varying(250),
  "obs6" character varying(250),
  "codmoneda" numeric(20,0),
  "pretvaluta" numeric(20,7),
  "ag" numeric(20,7),
  "valag" numeric(20,7),
  "profit" numeric(20,7),
  "valprofit" numeric(20,7),
  "pretfinal" numeric(20,7),
  "valprofitv" numeric(20,7),
  "pretfinalv" numeric(20,7),
  "totpretcoef" numeric(20,7),
  "totpretfix" numeric(20,7),
  "totpretcoefv" numeric(20,7),
  "totpretfixv" numeric(20,7),
  "valregieman" numeric(20,7),
  "ascuns" numeric(1,0),
  "codutilizare" numeric(20,0),
  "nohfactor" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>prodgest</obj_name>
  <obj_hashval>8e1882bcfead696a7118675eb8c591ab</obj_hashval>
  <obj_text>CREATE TABLE prodgest (
  "codprodgest" numeric(20,0) NOT NULL,
  "codprodcomp" numeric(20,0),
  "indexlocal" numeric(10,0),
  "codgest" numeric(20,0),
  "coefmat" numeric(20,7),
  "coefman" numeric(20,7),
  "timpest" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>prodman</obj_name>
  <obj_hashval>2316d8d0b83b8d44bda8095620fa398c</obj_hashval>
  <obj_text>CREATE TABLE prodman (
  "codman" numeric(20,0) NOT NULL,
  "codprodcomp" numeric(20,0),
  "nrop" numeric(10,0),
  "codop" numeric(20,0),
  "codloc" numeric(20,0),
  "codtarif" numeric(20,0),
  "tu" numeric(20,7),
  "valoare" numeric(20,7),
  "codprodgest" numeric(20,0),
  "indexlocal" numeric(10,0),
  "dsv" numeric(20,7),
  "bps" numeric(20,7),
  "tpi" numeric(20,7),
  "obs" character varying(1000),
  "detalii" numeric(10,0),
  "fix" numeric(1,0),
  "nivel" numeric(5,0),
  "decalaj" numeric(10,0),
  "incepere" numeric(20,7),
  "coefbps" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>prodmas</obj_name>
  <obj_hashval>6fd69b520357fceb68eefcca6b74db06</obj_hashval>
  <obj_text>CREATE TABLE prodmas (
  "codprodmas" numeric(20,0) NOT NULL,
  "codprodcomp" numeric(20,0),
  "codprodgest" numeric(20,0),
  "descriere" character varying(200),
  "frecventa" character varying(20),
  "metoda" character varying(150),
  "codobiect" numeric(20,0),
  "indexlocal" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>prodmat</obj_name>
  <obj_hashval>e377f1b9ba2c85d40ed04b97ced426c3</obj_hashval>
  <obj_text>CREATE TABLE prodmat (
  "codmat" numeric(20,0) NOT NULL,
  "codprodcomp" numeric(20,0),
  "codobiect" numeric(20,0),
  "cant" numeric(20,7),
  "pret" numeric(20,7),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7),
  "indexlocal" numeric(10,0),
  "cantum1" numeric(20,7),
  "codprodgest" numeric(20,0),
  "tip" numeric(1,0),
  "codatribut" numeric(20,0),
  "valmat" numeric(20,7),
  "valman" numeric(20,7),
  "valregie" numeric(20,7),
  "obs" character varying(300),
  "adddim" numeric(20,7),
  "adddim_transp" numeric(20,7),
  "pretorig" numeric(20,7),
  "procreal" numeric(20,7),
  "valoare" numeric(20,7),
  "codreteta" numeric(20,0),
  "codman" numeric(20,0),
  "copyd1" numeric(12,7),
  "copyd2" numeric(12,7),
  "copyd3" numeric(12,7),
  "etapa" numeric(10,0),
  "pretv" numeric(20,7),
  "principal" numeric(1,0),
  "consum" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>prodmatechiv</obj_name>
  <obj_hashval>d354c31bf6fd8795dbe81238e9ca76d2</obj_hashval>
  <obj_text>CREATE TABLE prodmatechiv (
  "codmatechiv" numeric(20,0) NOT NULL,
  "codprodcomp" numeric(20,0),
  "codmat" numeric(20,0),
  "codobiect" numeric(20,0),
  "paritate" numeric(20,7),
  "ordine" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>prodnet</obj_name>
  <obj_hashval>28a54d51248bbb69aa1e47e3648b4f78</obj_hashval>
  <obj_text>CREATE TABLE prodnet (
  "codprodnet" numeric(20,0) NOT NULL,
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "obs" character varying(150),
  "tip" numeric(1,0),
  "subunitatea" numeric(20,0),
  "codgest" numeric(20,0),
  "codcentru" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>prodnet1</obj_name>
  <obj_hashval>234a3845c5f79f0062383c3da4b2d067</obj_hashval>
  <obj_text>CREATE TABLE prodnet1 (
  "codprodnet1" numeric(20,0) NOT NULL,
  "codprodnet" numeric(20,0),
  "tip" numeric(1,0),
  "coddoc1" numeric(20,0),
  "explicatii" character varying(150),
  "valmat" numeric(20,7),
  "valman" numeric(20,7),
  "codcentru" numeric(20,0),
  "codanalizanod" numeric(20,0),
  "codcmdprodmat" numeric(20,0),
  "difcant" numeric(20,7),
  "cantreal" numeric(20,7),
  "pret" numeric(20,7),
  "codies1" numeric(20,0),
  "dirty" numeric(1,0),
  "codgest" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>prodnorme</obj_name>
  <obj_hashval>fe01688ba5aaa8938575e99156cb0f2a</obj_hashval>
  <obj_text>CREATE TABLE prodnorme (
  "codnorma" numeric(20,0) NOT NULL,
  "codprodcomp" numeric(20,0),
  "norma" character varying(250),
  "indexlocal" numeric(10,0),
  "implicit" numeric(1,0),
  "activ" numeric(1,0),
  "dataactiv" date,
  "datainactiv" date
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>prodrez</obj_name>
  <obj_hashval>bca305c2ddb1cc51b73c8771cf480419</obj_hashval>
  <obj_text>CREATE TABLE prodrez (
  "codrez" numeric(20,0) NOT NULL,
  "codprodcomp" numeric(20,0),
  "codobiect" numeric(20,0),
  "cant" numeric(20,7),
  "pret" numeric(20,7),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7),
  "indexlocal" numeric(10,0),
  "reziduu" numeric(1,0),
  "cantum1" numeric(20,7),
  "codprodgest" numeric(20,0),
  "obs" character varying(300)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>prodsdv</obj_name>
  <obj_hashval>6869653b72592a9e8712c7eeffd5f021</obj_hashval>
  <obj_text>CREATE TABLE prodsdv (
  "codprodsdv" numeric(20,0) NOT NULL,
  "codprodman" numeric(20,0),
  "indexlocal" numeric(10,0),
  "codsdv" numeric(20,0),
  "codgeneric" numeric(20,0),
  "cant" numeric(20,7),
  "pret" numeric(20,7),
  "codprodcomp" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>programf</obj_name>
  <obj_hashval>55902ee43f3d10903d2d3e4052fca6a9</obj_hashval>
  <obj_text>CREATE TABLE programf (
  "codprogramf" numeric(20,0) NOT NULL,
  "datainreg" date,
  "vdela" timestamp(0) without time zone,
  "vpanala" timestamp(0) without time zone,
  "operat" numeric(1,0),
  "blocat" numeric(1,0),
  "anulat" numeric(1,0),
  "tip" numeric(1,0),
  "codformatie" numeric(20,0),
  "subunitatea" numeric(20,0),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "tipdurata" numeric(1,0),
  "nrdoc" numeric(10,0),
  "obs" character varying(200),
  "prefixdoc" character varying(2),
  "carnetdoc" numeric(20,0),
  "seriadoc" character varying(20),
  "allgest" numeric(1,0),
  "alltipcont" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>programf1</obj_name>
  <obj_hashval>74779fc3416b243910c598d15d14d7b3</obj_hashval>
  <obj_text>CREATE TABLE programf1 (
  "codprogramf1" numeric(20,0) NOT NULL,
  "codprogramf" numeric(20,0),
  "codcomanda1" numeric(20,0),
  "codgest" numeric(20,0),
  "prioritate" numeric(10,0),
  "termen" date,
  "cantprogramat" numeric(20,7),
  "codformatie" numeric(20,0),
  "schimb" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>programfcont</obj_name>
  <obj_hashval>e428c230b3572e8c2e2c42c63bd739c6</obj_hashval>
  <obj_text>CREATE TABLE programfcont (
  "codprogramf" numeric(20,0),
  "codioart" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>programfgest</obj_name>
  <obj_hashval>24258fa389fd2ea8cd1f65317650a246</obj_hashval>
  <obj_text>CREATE TABLE programfgest (
  "codprogramf" numeric(20,0),
  "codgest" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>programflmc</obj_name>
  <obj_hashval>16270b95b8f4462c705f8f6a413e8d23</obj_hashval>
  <obj_text>CREATE TABLE programflmc (
  "codlmc" numeric(20,0) NOT NULL,
  "codprogramf" numeric(20,0),
  "codgest" numeric(20,0),
  "codloc" numeric(20,0),
  "codcomanda1" numeric(20,0),
  "dataprogramare" date,
  "codop" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_njudet_codtara</obj_name>
  <obj_reftable>njudet</obj_reftable>
  <obj_hashval>10a3ba2a1e1999cf04bbd1b944d19bfc</obj_hashval>
  <obj_text>CREATE INDEX idx_njudet_codtara ON njudet USING btree (codtara)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>programfman</obj_name>
  <obj_hashval>1661c505e79c111ce10058c6a31b89f1</obj_hashval>
  <obj_text>CREATE TABLE programfman (
  "codpfman" numeric(20,0) NOT NULL,
  "codprogramf" numeric(20,0),
  "codcmdprodman" numeric(20,0),
  "cant" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>programfsdv</obj_name>
  <obj_hashval>217a9f9aad4a469454813906288d08ef</obj_hashval>
  <obj_text>CREATE TABLE programfsdv (
  "codprogramfsdv" numeric(20,0) NOT NULL,
  "codprogramf" numeric(20,0),
  "codgest" numeric(20,0),
  "codobiect" numeric(20,0),
  "cant" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>proiect</obj_name>
  <obj_hashval>c4548052098d45be8f4574ec7f65520e</obj_hashval>
  <obj_text>CREATE TABLE proiect (
  "codproiect" numeric(20,0) NOT NULL,
  "codversiune" numeric(10,0),
  "codobiectprod" numeric(20,0),
  "versiune" character varying(100),
  "intocmita" numeric(20,0),
  "dataproiect" date,
  "clasa" numeric(20,0),
  "procesare" numeric(1,0),
  "complex" numeric(1,0),
  "activ" numeric(1,0),
  "finalizat" numeric(1,0),
  "blocat" numeric(1,0),
  "invizibila" numeric(1,0),
  "generic" numeric(1,0),
  "implicit" numeric(1,0),
  "durata" numeric(20,7),
  "marjaordine" numeric(20,7),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "obs1" character varying(250),
  "obs2" character varying(250),
  "obs3" character varying(250),
  "obs4" character varying(250),
  "obs5" character varying(250),
  "obs6" character varying(250),
  "codextern" character varying(80),
  "ascuns" numeric(1,0),
  "codutilizare" numeric(20,0),
  "codidentificare" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>proiectcrm</obj_name>
  <obj_hashval>717b77e5329c358230ad08ca0af8cb62</obj_hashval>
  <obj_text>CREATE TABLE proiectcrm (
  "codproiectcrm" numeric(20,0) NOT NULL,
  "denumire" character varying(30),
  "descriere" character varying(500),
  "valoare" numeric(20,7),
  "moneda" numeric(20,0),
  "codpers" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>proiectnod</obj_name>
  <obj_hashval>c87e39e3b7067458a92b9b299ac67f95</obj_hashval>
  <obj_text>CREATE TABLE proiectnod (
  "codproiectnod" numeric(20,0) NOT NULL,
  "codproiect" numeric(20,0),
  "cant" numeric(20,7),
  "nodoriginal" numeric(20,0),
  "pozitie" numeric(10,0),
  "codreteta" numeric(20,0),
  "tip" numeric(1,0),
  "codobiect" numeric(20,0),
  "indexparinte" character varying(50),
  "codprodmat" numeric(20,0),
  "nivel" numeric(10,0),
  "ordine" numeric(5,0),
  "decalaj" numeric(10,0),
  "incepere" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nlimcredit1_codlimcredit</obj_name>
  <obj_reftable>nlimcredit1</obj_reftable>
  <obj_hashval>26029c6c752018bbc2222c42441a0ac3</obj_hashval>
  <obj_text>CREATE INDEX idx_nlimcredit1_codlimcredit ON nlimcredit1 USING btree (codlimcredit)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nlocalit_codjudet</obj_name>
  <obj_reftable>nlocalit</obj_reftable>
  <obj_hashval>c645db204a8422c4f891d0e6cd0a649c</obj_hashval>
  <obj_text>CREATE INDEX idx_nlocalit_codjudet ON nlocalit USING btree (codjudet)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nlocalit_codtara</obj_name>
  <obj_reftable>nlocalit</obj_reftable>
  <obj_hashval>7204175cc26fc2813a01fbb84c219511</obj_hashval>
  <obj_text>CREATE INDEX idx_nlocalit_codtara ON nlocalit USING btree (codtara)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nlocalit_codzona</obj_name>
  <obj_reftable>nlocalit</obj_reftable>
  <obj_hashval>ca412eea67a8a47f233acfa9f2fe01af</obj_hashval>
  <obj_text>CREATE INDEX idx_nlocalit_codzona ON nlocalit USING btree (codzona)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>promo</obj_name>
  <obj_hashval>95aef964134ae99b9f9da223060ef38f</obj_hashval>
  <obj_text>CREATE TABLE promo (
  "codpromo" numeric(20,0) NOT NULL,
  "tipdoc" numeric(20,0),
  "anulat" numeric(1,0),
  "blocat" numeric(1,0),
  "operat" numeric(1,0),
  "carnetdoc" numeric(20,0),
  "seriadoc" character varying(20),
  "nrdoc" numeric(20,0),
  "datastart" date,
  "dataend" date,
  "partener" numeric(20,0),
  "codlocatie" numeric(20,0),
  "codfiscal" numeric(20,0),
  "codpersc" numeric(20,0),
  "moneda" numeric(20,0),
  "tippromotie" numeric(1,0),
  "tipconditie" numeric(1,0),
  "obs" character varying(200),
  "subunitatea" numeric(20,0),
  "an" numeric(20,0),
  "luna" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "tipclasep" numeric(1,0),
  "tipservire" numeric(1,0),
  "demana" numeric(1,0),
  "valmin" numeric(20,7),
  "praguri" numeric(1,0),
  "cantmin" numeric(20,7),
  "orastart" character varying(5),
  "orastop" character varying(5),
  "exclaltepromo" numeric(1,0),
  "pretcuamanunt" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>promo1</obj_name>
  <obj_hashval>d90cb5ac3ce1026b52235e1432fcf001</obj_hashval>
  <obj_text>CREATE TABLE promo1 (
  "codpromo1" numeric(20,0),
  "codpromo" numeric(20,0),
  "codobiect" numeric(20,0),
  "umsec" numeric(20,0),
  "cant" numeric(20,7),
  "pret" numeric(20,7),
  "procdisc" numeric(20,7),
  "zilec" numeric(5,0),
  "tiplimita" numeric(1,0),
  "tg_max" date,
  "zile_exp" numeric(5,0),
  "grupapret" character varying(5),
  "valmin" numeric(20,7),
  "pretamanunt" numeric(20,7),
  "cantoptim" numeric(20,7),
  "codarticol" numeric(20,0),
  "codclasea" numeric(20,0),
  "modaplic" numeric(1,0),
  "valdisc" numeric(20,7),
  "cuechivalente" numeric(1,0),
  "cant_max" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>promo1cadou</obj_name>
  <obj_hashval>0d76bc155428d19faf3ea6a736ff56d7</obj_hashval>
  <obj_text>CREATE TABLE promo1cadou (
  "codcadou" numeric(20,0) NOT NULL,
  "codpromo1" numeric(20,0),
  "codobiect" numeric(20,0),
  "umsec" numeric(20,0),
  "cant" numeric(20,7),
  "tiplimita" numeric(1,0),
  "tg_max" date,
  "zile_exp" numeric(5,0),
  "codpromo" numeric(20,0),
  "valmin" numeric(20,7),
  "cantmin" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>promo1cadouser</obj_name>
  <obj_hashval>41863a389ff85f1a675b793952622673</obj_hashval>
  <obj_text>CREATE TABLE promo1cadouser (
  "codcadous" numeric(20,0) NOT NULL,
  "codcadou" numeric(20,0),
  "serie" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>promo1ser</obj_name>
  <obj_hashval>712e21f4fd7b2316fd5dd42a0d1af945</obj_hashval>
  <obj_text>CREATE TABLE promo1ser (
  "codpromo1s" numeric(20,0) NOT NULL,
  "codpromo1" numeric(20,0),
  "serie" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>promopart</obj_name>
  <obj_hashval>3879085b33956d3768c91879e17386fa</obj_hashval>
  <obj_text>CREATE TABLE promopart (
  "codpromopart" numeric(20,0) NOT NULL,
  "codpromo" numeric(20,0),
  "codclasep" numeric(20,0),
  "partener" numeric(20,0),
  "codlocatie" numeric(20,0),
  "codfiscal" numeric(20,0),
  "codpersc" numeric(20,0),
  "prioritar" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>promoprag</obj_name>
  <obj_hashval>382a812d78eebfffafa372db74233f8e</obj_hashval>
  <obj_text>CREATE TABLE promoprag (
  "codprag" numeric(20,0) NOT NULL,
  "codpromo" numeric(20,0),
  "valmin" numeric(20,7),
  "procdisc" numeric(20,2),
  "cantmin" numeric(20,7),
  "valdisc" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>promosub</obj_name>
  <obj_hashval>07e1b907b4b8759389aee38549524ab9</obj_hashval>
  <obj_text>CREATE TABLE promosub (
  "codpromosub" numeric(20,0) NOT NULL,
  "codpromo" numeric(20,0),
  "subunitatea" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>puncteuse</obj_name>
  <obj_hashval>751e2885db73c7afd8a9f31380a2f76a</obj_hashval>
  <obj_text>CREATE TABLE puncteuse (
  "cod" numeric(20,0) NOT NULL,
  "codpunctaj" numeric(20,0),
  "puncte" numeric(20,0),
  "valacordata" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>rac_auto</obj_name>
  <obj_hashval>bf3b3cd98c48c6be0815d09a203388bf</obj_hashval>
  <obj_text>CREATE TABLE rac_auto (
  "codauto" numeric,
  "codobiect" numeric(20,0),
  "codgest" numeric,
  "transferat" numeric,
  "q" numeric,
  "datastart" timestamp(0) without time zone,
  "datastop" timestamp(0) without time zone,
  "codclasa" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>rac_auto_cen</obj_name>
  <obj_hashval>4366b9b88d3cc151683f3765db8ad5f6</obj_hashval>
  <obj_text>CREATE TABLE rac_auto_cen (
  "codauto" numeric,
  "codgest" numeric,
  "q" numeric
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>rac_cars</obj_name>
  <obj_hashval>3cefc89c9effbb9896af5e1edf780cde</obj_hashval>
  <obj_text>CREATE TABLE rac_cars (
  "codauto" numeric(20,0) NOT NULL,
  "data" timestamp(0) without time zone,
  "codgest" numeric,
  "gestiune" character varying(100),
  "subunitate" numeric(20,0),
  "codclasa" numeric(20,0),
  "inactiv" numeric,
  "extern" numeric,
  "codobiect" numeric(20,0),
  "nrauto" character varying(20),
  "marca" character varying(50),
  "model" character varying(50),
  "anf" numeric(4,0),
  "codgrechiv" numeric,
  "ind" numeric,
  "clasa" character varying(250),
  "generic" numeric
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>rac_catp</obj_name>
  <obj_hashval>6bc8f7bfe15a41fe4175fe10b7851e83</obj_hashval>
  <obj_text>CREATE TABLE rac_catp (
  "codrac_catp" numeric(20,0) NOT NULL,
  "codpartener" numeric(20,0),
  "codsediu" numeric(20,0),
  "codgest" numeric(20,0),
  "codsubunitate" numeric(20,0),
  "datastart" timestamp(0) without time zone,
  "datastop" timestamp(0) without time zone,
  "obs" character varying(50),
  "codcontract" numeric(20,0),
  "abonament" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>rac_catp1</obj_name>
  <obj_hashval>96387e4281ec20b9ca48322273798a5a</obj_hashval>
  <obj_text>CREATE TABLE rac_catp1 (
  "codrac_catp1" numeric(20,0) NOT NULL,
  "codrac_catp" numeric(20,0),
  "codrac_p" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>rac_catp2</obj_name>
  <obj_hashval>0ef80aa419ec00361adc883ee5d1f9c4</obj_hashval>
  <obj_text>CREATE TABLE rac_catp2 (
  "codrac_catp2" numeric(20,0) NOT NULL,
  "codrac_catp" numeric(20,0),
  "codgest" numeric(20,0),
  "codsubunitate" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>rac_emu</obj_name>
  <obj_hashval>5e66eb38ef1128455449a18c79f43bdb</obj_hashval>
  <obj_text>CREATE TABLE rac_emu (
  "codcomanda" numeric(20,0),
  "cant" numeric
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>rac_p</obj_name>
  <obj_hashval>dded9450a05addeab33ffaa23ee322e6</obj_hashval>
  <obj_text>CREATE TABLE rac_p (
  "codrac_p" numeric(20,0) NOT NULL,
  "obs" character varying(100),
  "tip" numeric(1,0),
  "moneda" numeric(20,0),
  "i1" numeric(6,0),
  "i2" numeric(6,0),
  "i3" numeric(6,0),
  "i4" numeric(6,0),
  "i5" numeric(6,0),
  "i6" numeric(6,0),
  "valfixa" numeric(20,7),
  "liniar" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>rac_p0</obj_name>
  <obj_hashval>afedbd7bba248b66cfdc7dfbacb442e8</obj_hashval>
  <obj_text>CREATE TABLE rac_p0 (
  "codrac_p0" numeric(20,0) NOT NULL,
  "codrac_p" numeric(20,0),
  "datastart" timestamp(0) without time zone
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>rac_p1</obj_name>
  <obj_hashval>46bf140117a906ee3008eec1bdc6989a</obj_hashval>
  <obj_text>CREATE TABLE rac_p1 (
  "codrac_p1" numeric(20,0) NOT NULL,
  "codrac_p0" numeric(20,0),
  "codgrupa" numeric(20,0),
  "p1" numeric(20,7),
  "p2" numeric(20,7),
  "p3" numeric(20,7),
  "p4" numeric(20,7),
  "p5" numeric(20,7),
  "p6" numeric(20,7),
  "fix" numeric(20,7),
  "garantie" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nlocatii_codgest</obj_name>
  <obj_reftable>nlocatii</obj_reftable>
  <obj_hashval>ee89c065aa1776f0fd31dfcd4ff43cec</obj_hashval>
  <obj_text>CREATE INDEX idx_nlocatii_codgest ON nlocatii USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nmonede1_codbanca</obj_name>
  <obj_reftable>nmonede1</obj_reftable>
  <obj_hashval>b76bc29a96fe23f88823af32cfafc351</obj_hashval>
  <obj_text>CREATE INDEX idx_nmonede1_codbanca ON nmonede1 USING btree (codbanca)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nmonede1_codmoneda</obj_name>
  <obj_reftable>nmonede1</obj_reftable>
  <obj_hashval>a04b388452a3f67c11924c962ea786b7</obj_hashval>
  <obj_text>CREATE INDEX idx_nmonede1_codmoneda ON nmonede1 USING btree (codmoneda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nodechiv_codcomanda1</obj_name>
  <obj_reftable>nodechiv</obj_reftable>
  <obj_hashval>1e1c3f72b16f5765a7c7d6a071f3c9ca</obj_hashval>
  <obj_text>CREATE INDEX idx_nodechiv_codcomanda1 ON nodechiv USING btree (codcomanda1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nodechiv_codobiect</obj_name>
  <obj_reftable>nodechiv</obj_reftable>
  <obj_hashval>12a21b6a5cca1ea5dd6b03a89bc85880</obj_hashval>
  <obj_text>CREATE INDEX idx_nodechiv_codobiect ON nodechiv USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nodechiv_codproiectnod</obj_name>
  <obj_reftable>nodechiv</obj_reftable>
  <obj_hashval>856a1daa137a1e8130d4abb36bee54fa</obj_hashval>
  <obj_text>CREATE INDEX idx_nodechiv_codproiectnod ON nodechiv USING btree (codproiectnod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nodechiv_tip</obj_name>
  <obj_reftable>nodechiv</obj_reftable>
  <obj_hashval>134c68afe2563fbf2a544ad61813b654</obj_hashval>
  <obj_text>CREATE INDEX idx_nodechiv_tip ON nodechiv USING btree (tip)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_normemat_codnorma</obj_name>
  <obj_reftable>normemat</obj_reftable>
  <obj_hashval>60b07ee3af1a97d39f9f5a84c1f3f3fc</obj_hashval>
  <obj_text>CREATE INDEX idx_normemat_codnorma ON normemat USING btree (codnorma)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_normemat_codobiect</obj_name>
  <obj_reftable>normemat</obj_reftable>
  <obj_hashval>92a85a48b639275703368fd97add600e</obj_hashval>
  <obj_text>CREATE INDEX idx_normemat_codobiect ON normemat USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_normemat_codprodcomp</obj_name>
  <obj_reftable>normemat</obj_reftable>
  <obj_hashval>27692e9ec3ed33ac3e005b192b459dae</obj_hashval>
  <obj_text>CREATE INDEX idx_normemat_codprodcomp ON normemat USING btree (codprodcomp)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>rac_rez</obj_name>
  <obj_hashval>727759f6d2be28c32fb5a8d4cca22bf1</obj_hashval>
  <obj_text>CREATE TABLE rac_rez (
  "codrac_rez" numeric(20,0) NOT NULL,
  "codcomanda" numeric(20,0),
  "nr_ref" character varying(100),
  "codcomisionar" numeric(20,0),
  "codlocalit_prel" numeric(20,0),
  "adresa_prel" character varying(150),
  "codlocalit_livr" numeric(20,0),
  "adresa_livr" character varying(150),
  "nr_zbor" character varying(20),
  "codcontr_prelivr" numeric(20,0),
  "factlunara" numeric(1,0),
  "sumagarantie" numeric(20,7),
  "codcmdaccident" numeric(20,0),
  "nume_card" character varying(100),
  "expira_card" date,
  "codccv" numeric(20,0),
  "obs_contract" character varying(100),
  "codtipasig" numeric(20,0),
  "email" character varying(100),
  "telefon" character varying(100),
  "tiprezervare" numeric(1,0),
  "datastart" timestamp(0) without time zone,
  "datastop" timestamp(0) without time zone,
  "coddelegat1" numeric(20,0),
  "coddelegat2" numeric(20,0),
  "codgestsursa" numeric(20,0),
  "codgestdest" numeric(20,0),
  "codinterventie" numeric(20,0),
  "kmin" numeric(10,0),
  "kmout" numeric(10,0),
  "combin" numeric(10,0),
  "combout" numeric(10,0),
  "kmnextrev" numeric(10,0),
  "codsediucomis" numeric(20,0),
  "codrezervare" numeric(20,0),
  "codmodel" numeric(20,0),
  "codmarca" numeric(20,0),
  "datafact" date,
  "codpartext" numeric(20,0),
  "proccedat" numeric(5,2),
  "datapred" timestamp(0) without time zone,
  "codvoucher" numeric(20,0),
  "predat" numeric(1,0),
  "codsofer" numeric(20,0),
  "valsofercm" numeric(20,7),
  "valsoferf" numeric(20,7),
  "valclientcm" numeric(20,7),
  "valclientf" numeric(20,7),
  "codsofer1" numeric(20,0),
  "codsofer2" numeric(20,0),
  "faratva" numeric(1,0),
  "sursaclient" character varying(20)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>rac_transfer</obj_name>
  <obj_hashval>f187955952d3baa1d7b98239cfe4ac5c</obj_hashval>
  <obj_text>CREATE TABLE rac_transfer (
  "codgestsursa" numeric(20,0),
  "codgestdest" numeric(20,0),
  "codauto" numeric,
  "datastart" timestamp(0) without time zone,
  "datastop" timestamp(0) without time zone,
  "datapred" timestamp(0) without time zone
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>racdashman_doc</obj_name>
  <obj_hashval>a5958694b210e91cc9e1283e160f76ad</obj_hashval>
  <obj_text>CREATE TABLE racdashman_doc (
  "cod" numeric(3,0) NOT NULL,
  "gest" character varying(100),
  "data" character varying(10),
  "analiza" character varying(100),
  "cantitate" character varying(15),
  "zilerez" character varying(15),
  "duratamedie" character varying(15),
  "rpd" character varying(15),
  "venittotal" character varying(15)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>racdashop_doc</obj_name>
  <obj_hashval>cd0d3bb35b3315453b7fc6a1fa546e9a</obj_hashval>
  <obj_text>CREATE TABLE racdashop_doc (
  "cod" numeric(3,0) NOT NULL,
  "gest" character varying(100),
  "data" character varying(10),
  "detaliu" character varying(100),
  "valoare" character varying(15)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>racdetaliereinfo</obj_name>
  <obj_hashval>646d624dc36d2339a316c319ee906ddd</obj_hashval>
  <obj_text>CREATE TABLE racdetaliereinfo (
  "cod" numeric(20,0) NOT NULL,
  "subunitate" character varying(100),
  "gestiune" character varying(100),
  "locatie" character varying(100),
  "clasa" character varying(50),
  "nrauto" character varying(30),
  "marca" character varying(20),
  "model" character varying(40),
  "anfab" character varying(10),
  "kmbord" character varying(20),
  "comb" character varying(100),
  "databord" character varying(100),
  "status" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>racdetaliereinfog</obj_name>
  <obj_hashval>7278f45b637409afefca0a9714ae66a7</obj_hashval>
  <obj_text>CREATE TABLE racdetaliereinfog (
  "cod" numeric(20,0) NOT NULL,
  "subunitate" character varying(100),
  "gestiune" character varying(100),
  "locatie" character varying(100),
  "clasa" character varying(50),
  "nrauto" character varying(30),
  "marca" character varying(20),
  "model" character varying(40),
  "datasosire" character varying(40),
  "status" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>raportp</obj_name>
  <obj_hashval>8ac3c3fb5f59ccce312abad670642827</obj_hashval>
  <obj_text>CREATE TABLE raportp (
  "codraportp" numeric(20,0) NOT NULL,
  "nrdoc" numeric(20,0),
  "datai" timestamp(0) without time zone,
  "datas" timestamp(0) without time zone,
  "pe_formatie" numeric(1,0),
  "sectie" numeric(20,0),
  "formatie" numeric(20,0),
  "programf" numeric(20,0),
  "subunitatea" numeric(20,0),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "intreruperi" numeric(20,7),
  "codcentru" numeric(20,0),
  "prefixdoc" character varying(2),
  "carnetdoc" numeric(20,0),
  "seriadoc" character varying(20),
  "schimb" numeric(1,0),
  "obs" character varying(500)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>raportp0</obj_name>
  <obj_hashval>0e93aa82bddf24a738cb80bf03daa39a</obj_hashval>
  <obj_text>CREATE TABLE raportp0 (
  "codraportp0" numeric(20,0) NOT NULL,
  "codraportp" numeric(20,0),
  "codcomanda1" numeric(20,0),
  "realizat" numeric(20,7),
  "rebut" numeric(20,7),
  "obs" character varying(400)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>raportp1</obj_name>
  <obj_hashval>46e8ff610ed95db4328c4ced9ae5730a</obj_hashval>
  <obj_text>CREATE TABLE raportp1 (
  "codraportp1" numeric(20,0) NOT NULL,
  "codraportp0" numeric(20,0),
  "codraportp" numeric(20,0),
  "angajat" numeric(20,0),
  "realizat" numeric(20,7),
  "rebut" numeric(20,7),
  "indice" numeric(20,7),
  "prodrealizat" numeric(20,7),
  "prodrebut" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>raportp2</obj_name>
  <obj_hashval>4caa8aca42b1a934185a9570a5c71d2d</obj_hashval>
  <obj_text>CREATE TABLE raportp2 (
  "codraportp2" numeric(20,0) NOT NULL,
  "codraportp1" numeric(20,0),
  "codcomanda1" numeric(20,0),
  "codobiect" numeric(20,0),
  "codman" numeric(20,0),
  "realizat" numeric(20,7),
  "rebut" numeric(20,7),
  "codop" numeric(20,0),
  "codloc" numeric(20,0),
  "codtarif" numeric(20,0),
  "tu" numeric(20,7),
  "codutilaj" numeric(20,0),
  "datastart" timestamp(0) without time zone,
  "datastop" timestamp(0) without time zone,
  "refacut" numeric(20,7),
  "codies1" numeric(20,0),
  "obs" character varying(1000)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>raportp3</obj_name>
  <obj_hashval>78e972695a1233f7052f6576b246f7a1</obj_hashval>
  <obj_text>CREATE TABLE raportp3 (
  "codraportp3" numeric(20,0) NOT NULL,
  "codraportp1" numeric(20,0),
  "codraportp" numeric(20,0),
  "codmotiv" numeric(20,0),
  "ore" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>rapstocmedist</obj_name>
  <obj_hashval>42f95f129f2235e4f85b1833166523f6</obj_hashval>
  <obj_text>CREATE TABLE rapstocmedist (
  "codrapmedist" numeric(20,0) NOT NULL,
  "codentitate" character varying(20),
  "codworkplace" character varying(20),
  "data" date,
  "cod" numeric(20,0),
  "mesaj" character varying(400),
  "idtranzactie" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>rec_list_balanta</obj_name>
  <obj_hashval>f22da214e9445e94bc879202e1a3bf05</obj_hashval>
  <obj_text>CREATE TABLE rec_list_balanta (
  "codcont" numeric(20,0),
  "codcontp" numeric(20,0),
  "codconts" numeric(20,0),
  "codcontt" numeric(20,0),
  "clasa" numeric(1,0),
  "simbol" character varying(100),
  "den_cont" character varying(200),
  "tipcont" character varying(15),
  "name" character varying(200),
  "balantasintetica" numeric(1,0),
  "nivel" numeric(2,0),
  "codsintetic" numeric(20,0),
  "codparinte" numeric(20,0),
  "soldid" numeric(20,3),
  "soldic" numeric(20,3),
  "soldiifrs" numeric(20,3),
  "soldiifrsd" numeric(20,3),
  "soldiifrsc" numeric(20,3),
  "soldigrup" numeric(20,3),
  "rulajpd" numeric(20,3),
  "rulajpc" numeric(20,3),
  "rulajpifrs" numeric(20,3),
  "rulajpifrsd" numeric(20,3),
  "rulajpifrsc" numeric(20,3),
  "rulajpgrup" numeric(20,3),
  "totalcpd" numeric(20,3),
  "totalcpc" numeric(20,3),
  "rulajd" numeric(20,3),
  "rulajc" numeric(20,3),
  "rulajifrs" numeric(20,3),
  "rulajifrsd" numeric(20,3),
  "rulajifrsc" numeric(20,3),
  "rulajgrup" numeric(20,3),
  "rulajcd" numeric(20,3),
  "rulajcc" numeric(20,3),
  "totalcd" numeric(20,3),
  "totalcc" numeric(20,3),
  "soldfd" numeric(20,3),
  "soldfc" numeric(20,3),
  "soldfifrs" numeric(20,3),
  "soldfifrsd" numeric(20,3),
  "soldfifrsc" numeric(20,3),
  "soldfgrup" numeric(20,3),
  "centrucost" character varying(100),
  "simbcentrucost" character varying(100),
  "simbolsitfin" character varying(50),
  "simbplanp" character varying(3200),
  "simbsintetic" character varying(100),
  "den_sintetic" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_notacredit1_codnc1orig</obj_name>
  <obj_reftable>notecredit1</obj_reftable>
  <obj_hashval>5023b29f72a1801777bcaaea83f355d9</obj_hashval>
  <obj_text>CREATE INDEX idx_notacredit1_codnc1orig ON notecredit1 USING btree (codncredit1orig)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_notecredit_anluna</obj_name>
  <obj_reftable>notecredit</obj_reftable>
  <obj_hashval>9c2a481ede08969b4c7827ba55cc8841</obj_hashval>
  <obj_text>CREATE INDEX idx_notecredit_anluna ON notecredit USING btree ((((an * (12)::numeric) + luna)))</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_notecredit_codcontract</obj_name>
  <obj_reftable>notecredit</obj_reftable>
  <obj_hashval>23187e3a84060cf0fcfd4dbc928f4dc8</obj_hashval>
  <obj_text>CREATE INDEX idx_notecredit_codcontract ON notecredit USING btree (codcontract)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_notecredit_codmoneda</obj_name>
  <obj_reftable>notecredit</obj_reftable>
  <obj_hashval>97e5a84ccb042d40351e6153b6fa1c79</obj_hashval>
  <obj_text>CREATE INDEX idx_notecredit_codmoneda ON notecredit USING btree (codmoneda)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>reclamatii</obj_name>
  <obj_hashval>29bf840858157db2ba0415a74ed66a1d</obj_hashval>
  <obj_text>CREATE TABLE reclamatii (
  "codreclamatie" numeric(20,0) NOT NULL,
  "anulat" numeric(20,0),
  "blocat" numeric(20,0),
  "operat" numeric(20,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(20,0),
  "nrdoc" numeric(20,0),
  "seriadoc" character varying(20),
  "datadoc" timestamp(0) without time zone,
  "carnetdoc" numeric(20,0),
  "codsubunit" numeric(20,0),
  "codutilizator" numeric(20,0),
  "motiv" character varying(500),
  "reclamatie" character varying(300),
  "codpart" numeric(20,0),
  "coddocr" numeric(20,0),
  "tipdocr" numeric(20,0),
  "rezolvat" numeric(1,0),
  "datarez" timestamp(0) without time zone,
  "codresp" numeric(20,0),
  "imputabila" numeric(1,0),
  "tipimput" numeric(1,0),
  "codpimput" numeric(20,0),
  "codpersc" numeric(20,0),
  "codlocatie" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>reclamatii1</obj_name>
  <obj_hashval>740bed9f0333c391b973cfbb538ba41e</obj_hashval>
  <obj_text>CREATE TABLE reclamatii1 (
  "codreclamatie1" numeric(20,0) NOT NULL,
  "codreclamatie" numeric(20,0),
  "coddoc1" numeric(20,0),
  "cant" numeric(20,7),
  "obs" character varying(300),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7),
  "cantums" numeric(20,7),
  "pu" numeric(20,7),
  "imputabil" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>reclamatii2</obj_name>
  <obj_hashval>df6b575765c7439227e9bca945008202</obj_hashval>
  <obj_text>CREATE TABLE reclamatii2 (
  "codreclamatie2" numeric(20,0) NOT NULL,
  "codreclamatie" numeric(20,0),
  "codpers" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>reg</obj_name>
  <obj_hashval>b6a340f2084e3de10c92ccc26ffba65f</obj_hashval>
  <obj_text>CREATE TABLE reg (
  "codreg" numeric(20,0) NOT NULL,
  "tipreg" numeric(10,0),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "codbank" numeric(20,0),
  "codmoneda" numeric(20,0),
  "curs" numeric(23,7),
  "dirty" numeric(1,0),
  "obs" character varying(300),
  "codsubunit" numeric(20,0),
  "provizion" numeric(1,0),
  "an" numeric(20,0),
  "luna" numeric(2,0),
  "codgest" numeric(20,0),
  "codanaliza" numeric(20,0),
  "codanalizanod" numeric(20,0),
  "codcentru" numeric(20,0),
  "curs_ifrs" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>reg1</obj_name>
  <obj_hashval>21dcddffa4908492b8ae65fa4a96c48c</obj_hashval>
  <obj_text>CREATE TABLE reg1 (
  "codreg1" numeric(20,0) NOT NULL,
  "codreg" numeric(20,0),
  "codgeneral" numeric(20,0),
  "solddocval" numeric(20,7),
  "solddoc" numeric(20,7),
  "solddocreg" numeric(20,7),
  "codgest" numeric(20,0),
  "cont" numeric(20,0),
  "semn" numeric(1,0),
  "curs" numeric(23,7),
  "semnificatie" numeric(20,0),
  "subunitatea" numeric(20,0),
  "codcentru" numeric(20,0),
  "codanalizanod" numeric(20,0),
  "codobligpif" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>regleas1</obj_name>
  <obj_hashval>3dfbd79b6ea38ec029902c96d1990696</obj_hashval>
  <obj_text>CREATE TABLE regleas1 (
  "codregleas1" numeric(20,0) NOT NULL,
  "codreg" numeric(20,0),
  "soldreg" numeric(20,7),
  "codcontract" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>regoss</obj_name>
  <obj_hashval>9e88df4d4124494310d80a591dcde224</obj_hashval>
  <obj_text>CREATE TABLE regoss (
  "codregoss" numeric(20,0) NOT NULL,
  "tipreg" numeric(10,0),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "trimestrul" numeric(1,0),
  "codbank" numeric(20,0),
  "codmoneda" numeric(20,0),
  "curs" numeric(23,7),
  "dirty" numeric(1,0),
  "obs" character varying(300),
  "codsubunit" numeric(20,0),
  "an" numeric(20,0),
  "luna" numeric(2,0),
  "codgest" numeric(20,0),
  "codanaliza" numeric(20,0),
  "codanalizanod" numeric(20,0),
  "codcentru" numeric(20,0),
  "curs_ifrs" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>regoss1</obj_name>
  <obj_hashval>d070bb0cf5e6c0ac8c1bd8f839799b44</obj_hashval>
  <obj_text>CREATE TABLE regoss1 (
  "codregoss1" numeric(20,0) NOT NULL,
  "codregoss" numeric(20,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(20,0),
  "tvadocval" numeric(20,7),
  "tvadoc" numeric(20,7),
  "tvadocreg" numeric(20,7),
  "codgest" numeric(20,0),
  "cont" numeric(20,0),
  "semn" numeric(1,0),
  "curs" numeric(23,7),
  "semnificatie" numeric(20,0),
  "subunitatea" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>regpers1</obj_name>
  <obj_hashval>33f839094f934920c6a4fd974aab8147</obj_hashval>
  <obj_text>CREATE TABLE regpers1 (
  "codregpers1" numeric(20,0) NOT NULL,
  "codreg" numeric(20,0),
  "solddoc" numeric(20,7),
  "solddocval" numeric(20,7),
  "solddocreg" numeric(20,7),
  "codpers" numeric(20,0),
  "codcont" numeric(20,0),
  "icont" numeric(20,0),
  "subunitatea" numeric(20,0),
  "codgest" numeric(20,0),
  "codcentru" numeric(20,0),
  "codanalizanod" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>regtrezor1</obj_name>
  <obj_hashval>0564d11871bded6ffae4cb27ada79b4d</obj_hashval>
  <obj_text>CREATE TABLE regtrezor1 (
  "codregtrezor1" numeric(20,0) NOT NULL,
  "codreg" numeric(20,0),
  "solddocval" numeric(20,7),
  "solddoc" numeric(20,7),
  "solddocreg" numeric(20,7),
  "codbank" numeric(20,0),
  "codbankcont" numeric(20,0),
  "codgest" numeric(20,0),
  "codcentru" numeric(20,0),
  "codanalizanod" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>restartinactive</obj_name>
  <obj_hashval>9c8ad268f698213bdd023dd77269aaf1</obj_hashval>
  <obj_text>CREATE TABLE restartinactive (
  "cod" numeric(20,0) NOT NULL,
  "codrestaurant" numeric(20,0),
  "codobiect" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>restaurante</obj_name>
  <obj_hashval>d8f3e9bed6ba23f388482c0f89a0cff0</obj_hashval>
  <obj_text>CREATE TABLE restaurante (
  "codrestaurant" numeric(20,0) NOT NULL,
  "denumire" character varying(50),
  "subunitatea" numeric(20,0),
  "tiporar" numeric(1,0),
  "orastart" timestamp(6) without time zone,
  "oraend" timestamp(6) without time zone,
  "tipunicitate" numeric(1,0),
  "tipgestimplicita" numeric(1,0),
  "postwmretail" numeric(1,0),
  "codpostretail" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>restclase</obj_name>
  <obj_hashval>423946ab15b5662c221fe04438d05d7d</obj_hashval>
  <obj_text>CREATE TABLE restclase (
  "cod" numeric(20,0),
  "codclasea" numeric(20,0),
  "codrestaurant" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>restcmd</obj_name>
  <obj_hashval>4ea1f8710dbb338f2f8691f79368a29d</obj_hashval>
  <obj_text>CREATE TABLE restcmd (
  "codrestcmd" numeric(20,0),
  "nrcomanda" numeric(20,0),
  "codmasa" numeric(20,0),
  "codospatar" numeric(20,0),
  "valoare" numeric(20,7),
  "deschidere" timestamp(6) without time zone,
  "inchidere" timestamp(6) without time zone,
  "inchisa" numeric(1,0),
  "obs" character varying(100),
  "nrpers" numeric(5,0),
  "diminuat" numeric(1,0),
  "adresalivrare" character varying(400)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>restcmd1</obj_name>
  <obj_hashval>dead105db6d4b2480b04996626495060</obj_hashval>
  <obj_text>CREATE TABLE restcmd1 (
  "codrestcmd1" numeric(20,0),
  "codrestcmd" numeric(20,0),
  "indexlocal" numeric(10,0),
  "codobiect" numeric(20,0),
  "umsec" numeric(20,0),
  "pret" numeric(20,7),
  "cant" numeric(20,7),
  "obs" character varying(100),
  "codgest" numeric(20,0),
  "listaregest" numeric(1,0),
  "faralistare" numeric(1,0),
  "tipum" numeric(1,0),
  "cantarit" numeric(1,0),
  "proctva" numeric(20,7),
  "ordine" numeric(3,0),
  "taxa" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>restgestimplicite</obj_name>
  <obj_hashval>4a9d0ee95c02b34b718812d56fdbe3a4</obj_hashval>
  <obj_text>CREATE TABLE restgestimplicite (
  "cod" numeric(20,0),
  "codrestaurant" numeric(20,0),
  "codobiect" numeric(20,0),
  "gestimplicita" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>restgestlistver</obj_name>
  <obj_hashval>b2d1066241914d245ea245827c1cd623</obj_hashval>
  <obj_text>CREATE TABLE restgestlistver (
  "cod" numeric(20,0),
  "codgest" numeric(20,0),
  "listver" numeric(20,0),
  "faralistare" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>restlistgest</obj_name>
  <obj_hashval>af8f32d945f9db7145651db9b5618d2d</obj_hashval>
  <obj_text>CREATE TABLE restlistgest (
  "codrestlistgest" numeric(20,0),
  "codrestcmd1" numeric(20,0),
  "cant" numeric(20,7),
  "obs" character varying(250),
  "dataora" timestamp(6) without time zone
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>restnp</obj_name>
  <obj_hashval>f58dbdb4e16e8b3001655542a7641170</obj_hashval>
  <obj_text>CREATE TABLE restnp (
  "codrestnp" numeric(20,0),
  "codrestcmd" numeric(20,0),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "carnetdoc" numeric(20,0),
  "codpart" numeric(20,0),
  "valoare" numeric(20,7),
  "valdisc" numeric(20,7),
  "protocol" numeric(1,0),
  "listatcm" numeric(1,0),
  "datacreare" timestamp(6) without time zone,
  "tipcasamarcat" numeric(10,0),
  "textnefiscal" character varying(100),
  "facturare" numeric(1,0),
  "listat" numeric(1,0),
  "codpartretail" numeric(20,0),
  "valmartor_cmd" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_notecredit_codpart</obj_name>
  <obj_reftable>notecredit</obj_reftable>
  <obj_hashval>3b5b7c84cb0bdb31147357070fb00699</obj_hashval>
  <obj_text>CREATE INDEX idx_notecredit_codpart ON notecredit USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>restnp1</obj_name>
  <obj_hashval>cd3e40b0ec73c71c7a1f9b73e3b745cd</obj_hashval>
  <obj_text>CREATE TABLE restnp1 (
  "codrestnp1" numeric(20,0),
  "codrestnp" numeric(20,0),
  "indexlocal" numeric(20,0),
  "codobiect" numeric(20,0),
  "umsec" numeric(20,0),
  "cant" numeric(20,7),
  "pret" numeric(20,7),
  "discount" numeric(20,7),
  "proctva" numeric(20,7),
  "discmanual" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>restnp2</obj_name>
  <obj_hashval>4864401b2c6c5c9dfa92959684528d35</obj_hashval>
  <obj_text>CREATE TABLE restnp2 (
  "codrestnp2" numeric(20,0),
  "codrestnp" numeric(20,0),
  "tipplata" numeric(10,0),
  "valoare" numeric(20,7),
  "denumire" character varying(250)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>restobiect</obj_name>
  <obj_hashval>c78d0251b02aebe8abbdfbb4a49ea050</obj_hashval>
  <obj_text>CREATE TABLE restobiect (
  "cod" numeric(20,0),
  "denumire" character varying(100),
  "codsala" numeric(20,0),
  "x" numeric(20,0),
  "y" numeric(20,0),
  "width" numeric(20,0),
  "height" numeric(20,0),
  "color" numeric(20,0),
  "textafisare" character varying(100),
  "forma" numeric(1,0),
  "poza" bytea,
  "is3d" numeric(1,0),
  "nivel" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>restobsart</obj_name>
  <obj_hashval>ed30c95ebc99df697a59cbdf1dfc3bdf</obj_hashval>
  <obj_text>CREATE TABLE restobsart (
  "cod" numeric(20,0) NOT NULL,
  "codrestaurant" numeric(20,0),
  "codobiect" numeric(20,0),
  "obs" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>restraportz</obj_name>
  <obj_hashval>765541bb99869bd3639f2f20b39d122f</obj_hashval>
  <obj_text>CREATE TABLE restraportz (
  "cod" numeric(20,0),
  "codpostretail" numeric(20,0),
  "datastart" timestamp(6) without time zone,
  "dataend" timestamp(6) without time zone
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>returo</obj_name>
  <obj_hashval>bb8de9915ffc1a381cf5d97574aa6b21</obj_hashval>
  <obj_text>CREATE TABLE returo (
  "codreturo" numeric(20,0) NOT NULL,
  "sessionid" character varying(100),
  "startedat" timestamp(6) without time zone,
  "refund" numeric(20,7),
  "voucherbarcode" character varying(100),
  "rvm_serialnumber" character varying(100),
  "rvm_type" character varying(100),
  "location_customerid" character varying(100),
  "location_name" character varying(100),
  "is_used" numeric(1,0),
  "used_date" timestamp(6) without time zone,
  "coddoc" numeric(20,0),
  "tipdoc" numeric(20,0),
  "upload_date" timestamp(6) without time zone
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>returostins</obj_name>
  <obj_hashval>e32112bd9bcf498a489063d34e64672c</obj_hashval>
  <obj_text>CREATE TABLE returostins (
  "codreturostins" numeric(20,0) NOT NULL,
  "codreturo" numeric(20,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(20,0),
  "valoare" numeric(20,7),
  "startedat" timestamp(6) without time zone,
  "voucherbarcode" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>rezervats</obj_name>
  <obj_hashval>731a05cb646905bf17f5edd58bb227d8</obj_hashval>
  <obj_text>CREATE TABLE rezervats (
  "codrezervats" numeric(20,0) NOT NULL,
  "codcomanda1" numeric(20,0),
  "codnirstoc" numeric(20,0),
  "codnirser" numeric(20,0),
  "rest" numeric(30,17),
  "umsec" numeric(20,0),
  "codcmdprodmat" numeric(20,0),
  "rezervatini" numeric(30,17),
  "codobiect" numeric(20,0),
  "codcomanda1f" numeric(20,0),
  "codinventar1" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>rezervats1</obj_name>
  <obj_hashval>50718b6af60f45ce21c3f77546b230a9</obj_hashval>
  <obj_text>CREATE TABLE rezervats1 (
  "codrezervats1" numeric(20,0),
  "codrezervats" numeric(20,0),
  "codpart" numeric(20,0),
  "cant" numeric(30,17),
  "umsec" numeric(20,0),
  "termen" date
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>rf_ctc_auxcod</obj_name>
  <obj_hashval>a0662d463d218e27064f6372b7ca083a</obj_hashval>
  <obj_text>CREATE TABLE rf_ctc_auxcod (
  "cod" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sablondescript</obj_name>
  <obj_hashval>b42fd7a04e2b5169b3694f8c0360827e</obj_hashval>
  <obj_text>CREATE TABLE sablondescript (
  "codsablon" numeric(20,0) NOT NULL,
  "denumire" character varying(200),
  "simbol" character varying(50),
  "coddescriptor" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sablondescript1</obj_name>
  <obj_hashval>c8dd5ab9d5f8feb26df4279c6ce95401</obj_hashval>
  <obj_text>CREATE TABLE sablondescript1 (
  "codsablon1" numeric(20,0) NOT NULL,
  "codsablon" numeric(20,0),
  "coddescriptor1" numeric(20,0),
  "procent" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sablonnc</obj_name>
  <obj_hashval>5da7d9154f24228abf4acef334a922c5</obj_hashval>
  <obj_text>CREATE TABLE sablonnc (
  "tipdoc" numeric(2,0),
  "indexlocal" numeric(2,0),
  "d" character varying(10),
  "c" character varying(10),
  "obs" character varying(200),
  "nrnota" numeric(20,0),
  "numenota" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>saft_info</obj_name>
  <obj_hashval>70bbd5b0441963302e169b79b4edb5cb</obj_hashval>
  <obj_text>CREATE TABLE saft_info (
  "infotime" timestamp(6) without time zone,
  "infoline" character varying(200),
  "detalii" text
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>saft_reset_seq</obj_name>
  <obj_hashval>ccec73d91f8af4df315cf7e47f2a12e5</obj_hashval>
  <obj_text>CREATE TABLE saft_reset_seq (
  "apel_timestamp" timestamp(6) without time zone
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>saftcol</obj_name>
  <obj_hashval>5d3e9ededc63d3af380a16fbfdc700f7</obj_hashval>
  <obj_text>CREATE TABLE saftcol (
  "codsafttab" numeric(20,0) NOT NULL,
  "idxlocal" numeric(5,0) NOT NULL,
  "denumire" character varying(100),
  "tip" character varying(100),
  "sursa" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>safttab</obj_name>
  <obj_hashval>3f6a06a147b31505d64e59a91e899a87</obj_hashval>
  <obj_text>CREATE TABLE safttab (
  "codsafttab" numeric(20,0) NOT NULL,
  "denumire" character varying(100),
  "sursa" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>safttip</obj_name>
  <obj_hashval>3da3faf53ea6aace60acda364f6e5a72</obj_hashval>
  <obj_text>CREATE TABLE safttip (
  "denumire" character varying(100),
  "delphitip" character varying(100),
  "delphilen" numeric(3,0),
  "oracletip" character varying(100),
  "strformat" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_catret</obj_name>
  <obj_hashval>b8e83ffc0ba07f744d153de5d99021f2</obj_hashval>
  <obj_text>CREATE TABLE sal_catret (
  "codcatret" numeric(20,0) NOT NULL,
  "denumire" character varying(30),
  "simbol" character varying(7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_catspor</obj_name>
  <obj_hashval>936de1083f7f01aa813325a07d78ed66</obj_hashval>
  <obj_text>CREATE TABLE sal_catspor (
  "codcatspor" numeric(20,0) NOT NULL,
  "denumire" character varying(30),
  "simbol" character varying(7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_contrpp</obj_name>
  <obj_hashval>cb128218bf24c774704159273b9fa1bd</obj_hashval>
  <obj_text>CREATE TABLE sal_contrpp (
  "codcontrpp" numeric(20,0) NOT NULL,
  "sucursala" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_contrpp1</obj_name>
  <obj_hashval>8a30e574c61b094a1b0e3d0875bf9319</obj_hashval>
  <obj_text>CREATE TABLE sal_contrpp1 (
  "codcontrpp1" numeric(2,0) NOT NULL,
  "codcontrpp" numeric(2,0),
  "angajat" numeric(20,0),
  "nrcontract" character varying(15),
  "datastart" date,
  "datastop" date,
  "fond" numeric(2,0),
  "platafirma" numeric(1,0),
  "contbancar" character varying(30),
  "modplata" numeric(2,0),
  "rata" numeric(2,0),
  "ziplata" numeric(2,0),
  "datainreg" date,
  "plafonlei" numeric(2,0),
  "plafoneuro" numeric(2,0),
  "diferente" numeric(2,0),
  "valratean" numeric(2,0),
  "retneimpoz" numeric(2,0),
  "retimpoz" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_dedgen</obj_name>
  <obj_hashval>e2ed4a5714eb9c0f8364f5039117f0fe</obj_hashval>
  <obj_text>CREATE TABLE sal_dedgen (
  "coddedgen" numeric(20,0) NOT NULL,
  "denumire" character varying(30),
  "baza" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_dedgen0</obj_name>
  <obj_hashval>d09a5d00115516bd3a5ddde8284f8cbb</obj_hashval>
  <obj_text>CREATE TABLE sal_dedgen0 (
  "coddedgen0" numeric(20,0) NOT NULL,
  "coddedgen" numeric(20,0),
  "contract" numeric(1,0),
  "conventie" numeric(1,0),
  "conventiecm" numeric(1,0),
  "cumuls" numeric(1,0),
  "cumulp" numeric(1,0),
  "special" numeric(1,0),
  "specialcv" numeric(1,0),
  "asimilate" numeric(1,0),
  "calcul" numeric(2,0),
  "marime" numeric(20,7),
  "rot" numeric(20,7),
  "modrot" numeric(2,0),
  "coop" numeric(1,0),
  "internship" numeric(1,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_dedgen1</obj_name>
  <obj_hashval>040c881298de828abe357d94bcff836a</obj_hashval>
  <obj_text>CREATE TABLE sal_dedgen1 (
  "coddedgen1" numeric(20,0) NOT NULL,
  "coddedgen0" numeric(20,0),
  "coddedgen" numeric(20,0),
  "pers" numeric(2,0),
  "limsup" numeric(20,7),
  "liminf" numeric(20,7),
  "relatie" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_fondp</obj_name>
  <obj_hashval>cf8d747dd649556925d162fc673f7209</obj_hashval>
  <obj_text>CREATE TABLE sal_fondp (
  "codfondp" numeric(20,0) NOT NULL,
  "denumire" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_impoz</obj_name>
  <obj_hashval>25d9cd99eacb96b0239536d6522f2db5</obj_hashval>
  <obj_text>CREATE TABLE sal_impoz (
  "codimpoz" numeric(20,0) NOT NULL,
  "denumire" character varying(30),
  "lunar" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_impoz0</obj_name>
  <obj_hashval>f2c7acd09892ac374d5d75ab11730961</obj_hashval>
  <obj_text>CREATE TABLE sal_impoz0 (
  "codimpoz0" numeric(20,0) NOT NULL,
  "codimpoz" numeric(20,0),
  "lacontr" numeric(1,0),
  "laconv" numeric(1,0),
  "laconvcm" numeric(1,0),
  "lacumulsal" numeric(1,0),
  "lacumulpens" numeric(1,0),
  "laspecial" numeric(1,0),
  "laspecialcv" numeric(1,0),
  "laasimilate" numeric(1,0),
  "rot" numeric(20,0),
  "trunchiere" numeric(1,0),
  "coop" numeric(1,0),
  "internship" numeric(1,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_impoz1</obj_name>
  <obj_hashval>a63cc1ed408d6835ad790a41d09259e8</obj_hashval>
  <obj_text>CREATE TABLE sal_impoz1 (
  "codimpoz1" numeric(20,0) NOT NULL,
  "codimpoz0" numeric(20,0),
  "codimpoz" numeric(20,0),
  "liminf" numeric(20,7),
  "limsup" numeric(20,7),
  "valfixa" numeric(20,7),
  "procent" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_intrerup</obj_name>
  <obj_hashval>48062cf82b6c8810c5ca5007c02448e5</obj_hashval>
  <obj_text>CREATE TABLE sal_intrerup (
  "codintrerup" numeric(20,0) NOT NULL,
  "simbol" character varying(3),
  "denumire" character varying(30),
  "vechtot" numeric(1,0),
  "vechfirma" numeric(1,0),
  "modcalcul" numeric(6,0),
  "asigsoc" numeric(1,0),
  "in_spor" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_nasig</obj_name>
  <obj_hashval>f2587ff2a1c905b9c041e85528a569ae</obj_hashval>
  <obj_text>CREATE TABLE sal_nasig (
  "codnasig" numeric(20,0) NOT NULL,
  "tip" character varying(50),
  "codasig" numeric(20,0),
  "caracter" numeric(2,0),
  "intrerupere" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_nasig0</obj_name>
  <obj_hashval>d08a59322ed763a182a0b2e6c06634f6</obj_hashval>
  <obj_text>CREATE TABLE sal_nasig0 (
  "codnasig0" numeric(20,0) NOT NULL,
  "codnasig" numeric(20,0),
  "bazacalcul" numeric(6,0),
  "angajator" numeric(1,0),
  "cont1" numeric(20,0),
  "asigurare" numeric(1,0),
  "cont2" numeric(20,0),
  "contribsalminecfirma" numeric(6,0),
  "contribsalmineccas" numeric(6,0),
  "penalizare" numeric(20,7),
  "impozit" numeric(1,0),
  "cresterecopil" numeric(1,0),
  "suspendarecm" numeric(1,0),
  "buget" numeric(6,0),
  "noangajat" numeric(1,0),
  "noangajator" numeric(1,0),
  "zileplatafirma" numeric(6,0),
  "neavizatcas" numeric(1,0),
  "plafonare" numeric(6,0),
  "nodeducere" numeric(1,0),
  "constructii" numeric(1,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_nasig1</obj_name>
  <obj_hashval>24af270f0e2282d64b93a92a1b71d7af</obj_hashval>
  <obj_text>CREATE TABLE sal_nasig1 (
  "codnasig1" numeric(20,0) NOT NULL,
  "codnasig0" numeric(20,0),
  "modcalcul" numeric(2,0),
  "conditionare" numeric(2,0),
  "umv" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_nasig2</obj_name>
  <obj_hashval>ba6d8f5aefdab7d36a77b66f58b3c1b6</obj_hashval>
  <obj_text>CREATE TABLE sal_nasig2 (
  "codnasig2" numeric(20,0) NOT NULL,
  "codnasig0" numeric(20,0),
  "codnasig1" numeric(20,0),
  "cuantum" numeric(20,7),
  "liminf" numeric(20,7),
  "limsup" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_nasig3</obj_name>
  <obj_hashval>cc93ac35ba686e1eda771547cffc1ba4</obj_hashval>
  <obj_text>CREATE TABLE sal_nasig3 (
  "codnasig3" numeric(20,0) NOT NULL,
  "codnasig0" numeric(20,0),
  "tip" numeric(2,0),
  "elemcalcul" numeric(2,0),
  "multiplicare" numeric(20,7),
  "codcont" numeric(20,0),
  "contributie" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_nbazacal</obj_name>
  <obj_hashval>15c92d6f859dccbea2342b54d5f8cef7</obj_hashval>
  <obj_text>CREATE TABLE sal_nbazacal (
  "codnbazacal" numeric(20,0) NOT NULL,
  "denumire" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_ncondas</obj_name>
  <obj_hashval>239f2cf00c302e36d8c1324650743f32</obj_hashval>
  <obj_text>CREATE TABLE sal_ncondas (
  "codncondas" numeric(20,0) NOT NULL,
  "denumire" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_ncontrib</obj_name>
  <obj_hashval>b059c31f0e072dc6a2c634f526ebc4c6</obj_hashval>
  <obj_text>CREATE TABLE sal_ncontrib (
  "codncontrib" numeric(20,0) NOT NULL,
  "tip" numeric(2,0),
  "denumire" character varying(30),
  "tipcontributie" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_notecredit_corectie</obj_name>
  <obj_reftable>notecredit</obj_reftable>
  <obj_hashval>95612c3af899a3b4d2b0abfc1552cbf5</obj_hashval>
  <obj_text>CREATE INDEX idx_notecredit_corectie ON notecredit USING btree (corectie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_notecredit_subunitatea</obj_name>
  <obj_reftable>notecredit</obj_reftable>
  <obj_hashval>bb5a56eb689950fd9ff5bfe51a4113ee</obj_hashval>
  <obj_text>CREATE INDEX idx_notecredit_subunitatea ON notecredit USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_notecredit_tipdoc</obj_name>
  <obj_reftable>notecredit</obj_reftable>
  <obj_hashval>d7d25e1560d0baade840b9ef3b9ed88e</obj_hashval>
  <obj_text>CREATE INDEX idx_notecredit_tipdoc ON notecredit USING btree (tipdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_notecredit1_coddoc</obj_name>
  <obj_reftable>notecredit1</obj_reftable>
  <obj_hashval>6bfb4c53f95a33b15cdb55eb12806969</obj_hashval>
  <obj_text>CREATE INDEX idx_notecredit1_coddoc ON notecredit1 USING btree (coddoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_notecredit1_codncredit</obj_name>
  <obj_reftable>notecredit1</obj_reftable>
  <obj_hashval>851a2bf0f7b3f76e9e4955b58187cbc6</obj_hashval>
  <obj_text>CREATE INDEX idx_notecredit1_codncredit ON notecredit1 USING btree (codncredit)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_notecredit1_tip</obj_name>
  <obj_reftable>notecredit1</obj_reftable>
  <obj_hashval>6cecf144d6f3f5f8a716246b2d696635</obj_hashval>
  <obj_text>CREATE INDEX idx_notecredit1_tip ON notecredit1 USING btree (tip)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_notecredit1_tipdoc</obj_name>
  <obj_reftable>notecredit1</obj_reftable>
  <obj_hashval>f84160b42365d6903b5525cc22f689b3</obj_hashval>
  <obj_text>CREATE INDEX idx_notecredit1_tipdoc ON notecredit1 USING btree (tipdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nparccom_codcomanda</obj_name>
  <obj_reftable>nparccom</obj_reftable>
  <obj_hashval>a316b4118a9fe23c8e2cd15e70bebad5</obj_hashval>
  <obj_text>CREATE INDEX idx_nparccom_codcomanda ON nparccom USING btree (codcomanda)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_ncontrib1</obj_name>
  <obj_hashval>d55ff1950a99281780caa356a0a3563f</obj_hashval>
  <obj_text>CREATE TABLE sal_ncontrib1 (
  "codncontrib1" numeric(20,0) NOT NULL,
  "codncontrib" numeric(20,0),
  "marime" numeric(20,7),
  "modcalcul" numeric(2,0),
  "impozitatctr" numeric(1,0),
  "codcont" numeric(20,0),
  "codcontchelt" numeric(20,0),
  "codcontcas" numeric(20,0),
  "codcontambp" numeric(20,0),
  "lacontr" numeric(1,0),
  "laconv" numeric(1,0),
  "laconvcm" numeric(1,0),
  "lacumulsal" numeric(1,0),
  "lacumulpens" numeric(1,0),
  "lapartsal" numeric(1,0),
  "lapreaviz" numeric(1,0),
  "laspecial" numeric(1,0),
  "laspecialcv" numeric(1,0),
  "laasimilate" numeric(1,0),
  "grupa1" numeric(1,0),
  "grupa2" numeric(1,0),
  "grupa3" numeric(1,0),
  "grupa4" numeric(1,0),
  "specialcb" numeric(1,0),
  "impozitatcv" numeric(1,0),
  "impozitatcvcm" numeric(1,0),
  "impozitatcs" numeric(1,0),
  "impozitatcp" numeric(1,0),
  "impozitatspec" numeric(1,0),
  "impozitatspeccv" numeric(1,0),
  "impozitatas" numeric(1,0),
  "varstamin" numeric(2,0),
  "venitmin" numeric(20,7),
  "venitmax" numeric(20,7),
  "tipcontractual" numeric(2,0),
  "buget" numeric(2,0),
  "tiplimitare" numeric(2,0),
  "referinta" numeric(2,0),
  "multiplic" numeric(20,7),
  "constructii" numeric(1,0),
  "lacoop" numeric(1,0),
  "lainternship" numeric(1,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_ndrep0</obj_name>
  <obj_hashval>29acd6cb222d5b88ad0269b13069d52e</obj_hashval>
  <obj_text>CREATE TABLE sal_ndrep0 (
  "codndrep0" numeric(20,0) NOT NULL,
  "codndrep" numeric(20,0),
  "art" numeric(20,0),
  "marime" numeric(20,7),
  "impozit" numeric(1,0),
  "deduceri" numeric(1,0),
  "tva" numeric(1,0),
  "ziua" numeric(20,0),
  "gest" numeric(20,0),
  "codcont" numeric(20,0),
  "totalcant" numeric(20,7),
  "totalval" numeric(20,7),
  "totalcutva" numeric(20,7),
  "tichetmasa" numeric(1,0),
  "coddoc" numeric(20,0),
  "altededuceri" numeric(1,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_ndrep1</obj_name>
  <obj_hashval>2630ae2e51975cab8b366fe6e524059d</obj_hashval>
  <obj_text>CREATE TABLE sal_ndrep1 (
  "codndrep1" numeric(20,0) NOT NULL,
  "codndrep0" numeric(20,0),
  "codndrep" numeric(20,0),
  "contrib" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_nmodc</obj_name>
  <obj_hashval>92018881cf9c1c2b612fdd97dfb2a71d</obj_hashval>
  <obj_text>CREATE TABLE sal_nmodc (
  "codmodc" numeric(20,0) NOT NULL,
  "denumire" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_ra21</obj_name>
  <obj_hashval>efbae62012f0193a2ad3042041360097</obj_hashval>
  <obj_text>CREATE TABLE sal_ra21 (
  "cod" numeric(6,0) NOT NULL,
  "denumire" character varying(100),
  "codspor" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_ra24</obj_name>
  <obj_hashval>88ac3d4d203deba79da344a5d627bc76</obj_hashval>
  <obj_text>CREATE TABLE sal_ra24 (
  "cod" numeric(6,0) NOT NULL,
  "denumire" character varying(36),
  "codtipsp" character varying(17)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_retineri</obj_name>
  <obj_hashval>298d8339d5c5cccf0ad6494f09ccd1fd</obj_hashval>
  <obj_text>CREATE TABLE sal_retineri (
  "codretinere" numeric(20,0) NOT NULL,
  "denumire" character varying(30),
  "codcatret" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_retineri0</obj_name>
  <obj_hashval>061f535d37edf338de3bf6051cba8a78</obj_hashval>
  <obj_text>CREATE TABLE sal_retineri0 (
  "codretinere0" numeric(20,0) NOT NULL,
  "codretinere" numeric(20,0),
  "marime" numeric(20,7),
  "modcalcul" numeric(2,0),
  "caracter" numeric(2,0),
  "cont" numeric(2,0),
  "tert" numeric(20,0),
  "neimpoz" numeric(1,0),
  "nrcontr" character varying(15),
  "datacontr" date,
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_sporuri</obj_name>
  <obj_hashval>592d6de5cb3ba658cad0634c6e63c335</obj_hashval>
  <obj_text>CREATE TABLE sal_sporuri (
  "codspor" numeric(20,0) NOT NULL,
  "denumire" character varying(30),
  "simbol" character varying(7),
  "codcatspor" numeric(20,0),
  "salbaza" numeric(1,0),
  "nivelsalbaza" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_sporuri0</obj_name>
  <obj_hashval>eb42128eddc5d0b16bb3f7a99cebfb1d</obj_hashval>
  <obj_text>CREATE TABLE sal_sporuri0 (
  "codspor0" numeric(20,0) NOT NULL,
  "codspor" numeric(20,0),
  "tip" numeric(2,0),
  "tiptransa" numeric(2,0),
  "tipcalcspor" numeric(2,0),
  "zilenemo" numeric(3,0),
  "valoare" numeric(20,7),
  "buget" numeric(2,0),
  "itmtip" numeric(6,0),
  "itmspor" numeric(6,0),
  "tarifarrefl" numeric(1,0),
  "intrs" character varying(50),
  "intrc" character varying(50),
  "intrsns" character varying(50),
  "intrsnc" character varying(50),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_sporuri1</obj_name>
  <obj_hashval>4979295761f859c5c8ca58e970c63663</obj_hashval>
  <obj_text>CREATE TABLE sal_sporuri1 (
  "codspor1" numeric(20,0) NOT NULL,
  "codspor" numeric(20,0),
  "liminf" numeric(20,7),
  "limsup" numeric(20,7),
  "valspor" numeric(20,7),
  "codspor0" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_sporuri2</obj_name>
  <obj_hashval>2aadfe77cdf97bfdfe3deebe970982e4</obj_hashval>
  <obj_text>CREATE TABLE sal_sporuri2 (
  "codspor2" numeric(20,0) NOT NULL,
  "codspor" numeric(20,0),
  "codsporexclus" numeric(20,0),
  "codspor0" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sali</obj_name>
  <obj_hashval>9df9f94d67842e57945dc978a3e4f5fc</obj_hashval>
  <obj_text>CREATE TABLE sali (
  "codsala" numeric(20,0) NOT NULL,
  "denumire" character varying(30),
  "codpers" numeric(20,0),
  "numarmese" numeric(5,0),
  "codrestaurant" numeric(20,0),
  "codcatpret" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>saliuseri</obj_name>
  <obj_hashval>14eea8010f27864c5f973a88f1f54104</obj_hashval>
  <obj_text>CREATE TABLE saliuseri (
  "cod" numeric(20,0),
  "codsala" numeric(20,0),
  "username" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>scenariilivr</obj_name>
  <obj_hashval>dfcdb0b26c4b471ad6f6c54a1a782b85</obj_hashval>
  <obj_text>CREATE TABLE scenariilivr (
  "codscenariu" numeric(20,0) NOT NULL,
  "den_scenariu" character varying(50),
  "codtraseu" numeric(20,0),
  "tip" numeric(1,0),
  "obs" character varying(200),
  "subunitatea" numeric(20,0),
  "an" numeric(20,0),
  "luna" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "definitiv" numeric(1,0),
  "dstart" date,
  "dend" date,
  "tipdata" numeric(1,0),
  "masa" numeric(20,7),
  "volum" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>scenariilivr1</obj_name>
  <obj_hashval>acd629793656971b21263a7f2b194e58</obj_hashval>
  <obj_text>CREATE TABLE scenariilivr1 (
  "codscenariu1" numeric(20,0) NOT NULL,
  "codscenariu" numeric(20,0),
  "codcomanda1" numeric(20,0),
  "cant" numeric(30,17),
  "lans" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>scenariilivr2</obj_name>
  <obj_hashval>78b1b77a70424c17f28c87419f5ddc1e</obj_hashval>
  <obj_text>CREATE TABLE scenariilivr2 (
  "codscenariu2" numeric(20,0) NOT NULL,
  "codscenariu" numeric(20,0),
  "codcomanda1" numeric(20,0),
  "codproiectnod" numeric(20,0),
  "datastart" date
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>seriicmd</obj_name>
  <obj_hashval>d72ef6ce27c207ee64088bc075102ea1</obj_hashval>
  <obj_text>CREATE TABLE seriicmd (
  "codseriecmd" numeric(20,0),
  "codcomanda" numeric(20,0),
  "codobiect" numeric(20,0),
  "codserie" numeric(20,0),
  "dataexp" character varying(10),
  "raspuns" character varying(500),
  "status" character varying(50),
  "dataverif" date,
  "gtin" character varying(100),
  "codraspuns" character varying(50),
  "schemetype" character varying(10),
  "gln" character varying(50),
  "userid" numeric(20,0),
  "motiv" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>seriiies</obj_name>
  <obj_hashval>c476385aa5c0e851feb4c70ef6971e43</obj_hashval>
  <obj_text>CREATE TABLE seriiies (
  "codserieies" numeric(20,0),
  "codies" numeric(20,0),
  "codobiect" numeric(20,0),
  "codserie" numeric(20,0),
  "dataexp" character varying(10),
  "raspuns" character varying(500),
  "status" character varying(50),
  "dataverif" date,
  "gtin" character varying(100),
  "codraspuns" character varying(50),
  "schemetype" character varying(10),
  "gln" character varying(50),
  "userid" numeric(20,0),
  "motiv" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>seriiintr</obj_name>
  <obj_hashval>91893ac892d498b3d99123682b133855</obj_hashval>
  <obj_text>CREATE TABLE seriiintr (
  "codserieintr" numeric(20,0),
  "codintr" numeric(20,0),
  "codobiect" numeric(20,0),
  "codserie" numeric(20,0),
  "dataexp" character varying(10),
  "raspuns" character varying(500),
  "status" character varying(50),
  "dataverif" date,
  "gtin" character varying(100),
  "codraspuns" character varying(50),
  "schemetype" character varying(10),
  "gln" character varying(50),
  "userid" numeric(20,0),
  "motiv" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>seriitransf</obj_name>
  <obj_hashval>318dd2add16e86ae394f49463536f6e2</obj_hashval>
  <obj_text>CREATE TABLE seriitransf (
  "codserietransf" numeric(20,0),
  "codtransf" numeric(20,0),
  "codobiect" numeric(20,0),
  "codserie" numeric(20,0),
  "dataexp" character varying(10),
  "raspuns" character varying(500),
  "status" character varying(50),
  "dataverif" date,
  "gtin" character varying(100),
  "codraspuns" character varying(50),
  "schemetype" character varying(10),
  "gln" character varying(50),
  "userid" numeric(20,0),
  "motiv" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>servfact1</obj_name>
  <obj_hashval>5736d721e49bcc1b4a811b41b64df725</obj_hashval>
  <obj_text>CREATE TABLE servfact1 (
  "codservfact1" numeric(20,0),
  "codservfact" numeric(20,0),
  "panala" numeric(20,7),
  "valoare" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>servpost</obj_name>
  <obj_hashval>78169b28fa80e07fe97bf345863aa193</obj_hashval>
  <obj_text>CREATE TABLE servpost (
  "codserviciu" numeric(20,0) NOT NULL,
  "denserviciu" character varying(160),
  "codobiect" numeric(20,0),
  "tarif" numeric(20,4)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>settask</obj_name>
  <obj_hashval>dc7a7e5be80eeebc61375047c411e907</obj_hashval>
  <obj_text>CREATE TABLE settask (
  "codtask" numeric(20,0) NOT NULL,
  "problema" character varying(4000),
  "destinatar" character varying(30),
  "executant" character varying(30),
  "username" character varying(30),
  "termen" date,
  "datatask" timestamp(0) without time zone,
  "datarez" timestamp(0) without time zone,
  "domeniu" character varying(50),
  "tip" character varying(50),
  "rezolvare" character varying(4000),
  "observatii" character varying(4000),
  "prioritate" numeric(6,0),
  "done" numeric(1,0),
  "modificat" numeric(1,0),
  "mesajcatre" character varying(30),
  "sters" numeric(1,0),
  "proiect" character varying(50),
  "domsg" numeric(1,0),
  "codmsg1" numeric(20,0),
  "domail" numeric(1,0),
  "codmail" numeric(20,0),
  "zbefore" numeric(2,0),
  "codfirma" numeric(20,0),
  "codpart" numeric(20,0),
  "facturabil" numeric(1,0),
  "facturat" numeric(1,0),
  "valoare" numeric(20,2),
  "codmoneda" numeric(20,0),
  "codcomanda" numeric(20,0),
  "codfactura" numeric(20,0),
  "codoferta" numeric(20,0),
  "codpers" numeric(20,0),
  "codserviciu" numeric(20,0),
  "codcontract1" numeric(20,0),
  "versiune" numeric(7,3),
  "prefixdoc" character varying(5),
  "nrdoc" numeric(20,0),
  "carnetdoc" numeric(20,0),
  "seriadoc" character varying(20),
  "articolasociat" numeric(20,0),
  "subunitatea" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>settasklog</obj_name>
  <obj_hashval>4b078d64ff218a53a02c752dd69d9779</obj_hashval>
  <obj_text>CREATE TABLE settasklog (
  "codlog" numeric(20,0),
  "codtask" numeric(20,0),
  "data" date,
  "user_src" character varying(30),
  "user_dst" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>settaskobj</obj_name>
  <obj_hashval>2a5d11866767a64130a7e8912ba6e48c</obj_hashval>
  <obj_text>CREATE TABLE settaskobj (
  "codtaskobj" numeric(20,0) NOT NULL,
  "codtask" numeric(20,0),
  "codobiect" numeric(20,0),
  "cant" numeric(20,7),
  "nepreluabil" numeric(1,0),
  "pret" numeric(20,7),
  "codpers" numeric(20,0),
  "indexlocal" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>settaskobjasoc</obj_name>
  <obj_hashval>82e0970b96100ef924add4879805b992</obj_hashval>
  <obj_text>CREATE TABLE settaskobjasoc (
  "codtaskobjasoc" numeric(20,0) NOT NULL,
  "codtask" numeric(20,0),
  "codobiect" numeric(20,0),
  "serii" character varying(2500),
  "codintern" character varying(250),
  "codies1" numeric(20,0),
  "indexlocal" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sgrcolect</obj_name>
  <obj_hashval>d969ba479ed2fe658b90e48655fd32bf</obj_hashval>
  <obj_text>CREATE TABLE sgrcolect (
  "codsgrcolect" numeric(20,0) NOT NULL,
  "data" date,
  "valoare" numeric(20,7),
  "datacreare" timestamp(6) without time zone,
  "codmarire" numeric(20,0),
  "voucherbarcode" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sgrcolect1</obj_name>
  <obj_hashval>f4d027d3a967eb407b0b617f41f2753c</obj_hashval>
  <obj_text>CREATE TABLE sgrcolect1 (
  "codsgrcolect1" numeric(20,0) NOT NULL,
  "codsgrcolect" numeric(20,0),
  "codobiect" numeric(20,0),
  "pret" numeric(10,2),
  "cant" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sintezaemulare</obj_name>
  <obj_hashval>20c14eb5434e13830bc953453dde8e0b</obj_hashval>
  <obj_text>CREATE TABLE sintezaemulare (
  "codsinteza" numeric(20,0),
  "codemulare" numeric(20,0) NOT NULL,
  "nrbon" numeric(20,0),
  "databon" date,
  "valoare" numeric(20,7),
  "valoarediscount" numeric(20,7),
  "listat" numeric(1,0),
  "preluat" numeric(1,0),
  "codcasamarcat" numeric(20,0),
  "tvatotal" numeric(20,7),
  "tvadiscount" numeric(20,7),
  "datacreare" timestamp(6) without time zone,
  "datalistare" timestamp(6) without time zone,
  "codies" numeric(20,0),
  "codpart" numeric(20,0),
  "codpers" numeric(20,0),
  "codpostretail" numeric(20,0),
  "codlocatie" numeric(20,0),
  "codagent" numeric(20,0),
  "obs" character varying(100),
  "idbon" numeric,
  "delegat" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sintezaemulare1</obj_name>
  <obj_hashval>a0bf219328f1c28c6bf687e0840246a6</obj_hashval>
  <obj_text>CREATE TABLE sintezaemulare1 (
  "codsinteza1" numeric(20,0),
  "codsinteza" numeric(20,0),
  "codemulare1" numeric(20,0),
  "codpostretail" numeric(20,0),
  "codobiect" numeric(20,0),
  "indexlocal" numeric(10,0),
  "pretart" numeric(20,7),
  "pret" numeric(20,7),
  "cant" numeric(20,7),
  "umsec" numeric(20,0),
  "discount" numeric(20,7),
  "tva" numeric(20,7),
  "tiplinie" character varying(1),
  "contserv" numeric(20,0),
  "cadou" numeric(20,0),
  "pretpromo" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sintezaemulare2</obj_name>
  <obj_hashval>d17fadc509a5cbd38a40dfab2d3e8aa0</obj_hashval>
  <obj_text>CREATE TABLE sintezaemulare2 (
  "codsinteza2" numeric(20,0),
  "codsinteza" numeric(20,0),
  "codemulare2" numeric(20,0),
  "codpostretail" numeric(20,0),
  "tipplata" numeric(10,0),
  "valoare" numeric(20,7),
  "denumire" character varying(250),
  "codbankcont" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sitfin</obj_name>
  <obj_hashval>0ae08eddf4bb71d78018c6bd683290f0</obj_hashval>
  <obj_text>CREATE TABLE sitfin (
  "codsitfin" numeric(20,0) NOT NULL,
  "codf" character varying(10),
  "denumire" character varying(100),
  "sectiune" character varying(50),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "tip" numeric(1,0),
  "tipplan" numeric(1,0),
  "peluni" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sitfinalte</obj_name>
  <obj_hashval>f1258d3488a990c3b9ed60d60081ac70</obj_hashval>
  <obj_text>CREATE TABLE sitfinalte (
  "codalte" numeric(20,0) NOT NULL,
  "codsitfin" numeric(20,0),
  "functie" character varying(250),
  "rand" numeric(10,0),
  "coloana" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sitfinbuget</obj_name>
  <obj_hashval>09740af79a4accfbf6065253e5e6f3b7</obj_hashval>
  <obj_text>CREATE TABLE sitfinbuget (
  "codsitfinbuget" numeric(20,0) NOT NULL,
  "codsitfinlin" numeric(20,0),
  "codsitfin" numeric(20,0),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "valoare" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sitfincol</obj_name>
  <obj_hashval>91dfb9fbe1a3eabd95af120f179a95e9</obj_hashval>
  <obj_text>CREATE TABLE sitfincol (
  "codcoloana" numeric(20,0) NOT NULL,
  "codsitfin" numeric(20,0),
  "nrcol" numeric(10,0),
  "denumire" character varying(100),
  "tipcol" numeric(5,0),
  "corelatie" character varying(100),
  "identificatorcol" character varying(10),
  "flgexport" numeric(1,0),
  "conta" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sitfinlin</obj_name>
  <obj_hashval>bcc70c1bf1e6cf9ac45d5a429f1499f4</obj_hashval>
  <obj_text>CREATE TABLE sitfinlin (
  "codlinie" numeric(20,0) NOT NULL,
  "codsitfin" numeric(20,0),
  "nrlinie" numeric(10,0),
  "denumire" character varying(250),
  "total" numeric(1,0),
  "corelatie" character varying(1500),
  "rnd" numeric(10,0),
  "tipconta" numeric(5,0),
  "obs" character varying(250),
  "valsuplim" numeric(20,7),
  "faranegative" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>skemebi</obj_name>
  <obj_hashval>faea5262f43dd6587a4b9d5a9775c492</obj_hashval>
  <obj_text>CREATE TABLE skemebi (
  "skema" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>smsuri</obj_name>
  <obj_hashval>a9820d966a2bf1dce150409c0bf696fc</obj_hashval>
  <obj_text>CREATE TABLE smsuri (
  "codsms" numeric(20,0) NOT NULL,
  "data" date,
  "userid" numeric(20,0),
  "telefon" character varying(20),
  "mesaj" character varying(1000),
  "eroare" character varying(50),
  "coddoc1" numeric(20,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(10,0),
  "status" numeric(1,0),
  "nume" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>soldcashflow</obj_name>
  <obj_hashval>70b6f105a8c958e84c3304bea03816b7</obj_hashval>
  <obj_text>CREATE TABLE soldcashflow (
  "codsold" numeric(20,0),
  "codcashflow" numeric(20,0),
  "codbankcont" numeric(20,0),
  "sold" numeric(20,7),
  "soldconv" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>soldini</obj_name>
  <obj_hashval>e9e7c4fd469f2e955eea4de1a47a5cbd</obj_hashval>
  <obj_text>CREATE TABLE soldini (
  "codsoldini" numeric(20,0) NOT NULL,
  "codpart" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>soldpart</obj_name>
  <obj_hashval>6c33e36f5c432a207898dd435fb6960d</obj_hashval>
  <obj_text>CREATE TABLE soldpart (
  "codsoldpart" numeric(20,0) NOT NULL,
  "codpart" numeric(20,0),
  "codcont" numeric(20,0),
  "codmoneda" numeric(20,0),
  "soldlei" numeric(20,3),
  "soldvaluta" numeric(20,3),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>soldpartluna</obj_name>
  <obj_hashval>24defb201a0e4ec3f4a1957438837797</obj_hashval>
  <obj_text>CREATE TABLE soldpartluna (
  "codpart" numeric(20,0),
  "icont" numeric(20,0),
  "codmoneda" numeric(20,0),
  "soldlei" numeric(20,3),
  "soldvaluta" numeric(20,3),
  "an" numeric(4,0),
  "luna" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>soldpersini</obj_name>
  <obj_hashval>4bfb372f847f13c7a850b6f63a4d3db0</obj_hashval>
  <obj_text>CREATE TABLE soldpersini (
  "codsoldpersini" numeric(20,0) NOT NULL,
  "codpers" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>soldpersluna</obj_name>
  <obj_hashval>9894fee54cd7e82991f0587d93b0759f</obj_hashval>
  <obj_text>CREATE TABLE soldpersluna (
  "codpers" numeric(20,0),
  "icont" numeric(20,0),
  "codmoneda" numeric(20,0),
  "soldlei" numeric(20,3),
  "soldvaluta" numeric(20,3),
  "an" numeric(4,0),
  "luna" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>splitchelt</obj_name>
  <obj_hashval>2ed423d104b9761b16c3741d394c0b08</obj_hashval>
  <obj_text>CREATE TABLE splitchelt (
  "codsplitchelt" numeric(20,0) NOT NULL,
  "tipdoc" numeric(2,0),
  "codobiect" numeric(20,0),
  "codgest" numeric(20,0),
  "codcentru" numeric(20,0),
  "obs" character varying(50),
  "an" numeric(5,0),
  "luna" numeric(2,0),
  "subunitatea" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "activ" numeric(1,0),
  "codcont" numeric(20,0),
  "faza" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>splitchelt1</obj_name>
  <obj_hashval>2a10f928adc356b7b3be178dcf30a231</obj_hashval>
  <obj_text>CREATE TABLE splitchelt1 (
  "codsplitchelt1" numeric(20,0) NOT NULL,
  "codsplitchelt" numeric(20,0),
  "indexlocal" numeric(5,0),
  "codgest" numeric(20,0),
  "codcentru" numeric(20,0),
  "codauto" numeric(20,0),
  "obs" character varying(50),
  "an" numeric(5,0),
  "luna" numeric(2,0),
  "procent" numeric(20,7),
  "codanalizanod" numeric(20,0),
  "codformatie" numeric(20,0),
  "puncte" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>spvarhiva</obj_name>
  <obj_hashval>e04a54e714b885c3046d8c2491905c46</obj_hashval>
  <obj_text>CREATE TABLE spvarhiva (
  "codspvarhiva" numeric(20,0) NOT NULL,
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "iddescarcare" character varying(20),
  "dataincarcare" timestamp(6) without time zone,
  "zip" bytea,
  "tipdoc" numeric(3,0),
  "id_ds" character varying(20),
  "cif" character varying(30),
  "coddocwme" numeric(20,0),
  "datadocspv" date,
  "cif_partener" character varying(75),
  "val_doc_spv" numeric(20,7),
  "tva_doc_spv" numeric(20,7),
  "id_doc_spv" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>src_doccarnete</obj_name>
  <obj_hashval>17a9fe460106bb24617665dca7c0eefc</obj_hashval>
  <obj_text>CREATE TABLE src_doccarnete (
  "codcarnet" numeric(20,0),
  "simbol" character varying(10),
  "denumire" character varying(50),
  "serie" character varying(20),
  "startnr" numeric(20,0),
  "endnr" numeric(20,0),
  "freenr" numeric(20,0),
  "inactiv" numeric(1,0),
  "subunitatea" numeric(20,0),
  "limita" numeric(20,0),
  "startnrini" numeric(20,0),
  "dedicat" numeric(1,0),
  "comenzionline" numeric(1,0),
  "codpostretail" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>src_docfree</obj_name>
  <obj_hashval>7243878579542e3286286bee327f755a</obj_hashval>
  <obj_text>CREATE TABLE src_docfree (
  "coddocfree" numeric(20,0),
  "codcarnet" numeric(20,0),
  "startnr" numeric(20,0),
  "endnr" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>src_doclink</obj_name>
  <obj_hashval>1f299f291f83ca8abdc4bb15df450e68</obj_hashval>
  <obj_text>CREATE TABLE src_doclink (
  "coddoclink" numeric(20,0),
  "codcarnet" numeric(20,0),
  "codmacheta" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>stareestimari</obj_name>
  <obj_hashval>f418eea159917557803b6e2a6e04bc5c</obj_hashval>
  <obj_text>CREATE TABLE stareestimari (
  "codstare" numeric(20,0) NOT NULL,
  "saptamana" numeric(10,0),
  "an" numeric(4,0),
  "saptamanag" numeric(10,0),
  "ang" numeric(4,0),
  "datacreare" timestamp(6) without time zone,
  "userid" numeric(20,0),
  "subunitatea" numeric(20,0),
  "obs" character varying(250),
  "codoferta" numeric(20,0),
  "dirty" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>stareestimari1</obj_name>
  <obj_hashval>cafa1329aa309abc7c5f3317c4a055de</obj_hashval>
  <obj_text>CREATE TABLE stareestimari1 (
  "codstare" numeric(20,0),
  "codobiect" numeric(20,0),
  "necesar" numeric(20,7),
  "estimat" numeric(20,7),
  "stocmin" numeric(20,7),
  "codstare1" numeric(20,0) NOT NULL,
  "pret" numeric(20,7),
  "necesaracc" numeric(20,7),
  "part1nec" numeric(20,7),
  "dirty" numeric(10,0),
  "acceptatts" numeric(20,7),
  "cmdf" numeric(20,7),
  "stocini" numeric(20,7),
  "dirtycmdf" numeric(10,0),
  "blocat" numeric(10,0),
  "blocat1" numeric(10,0),
  "consum" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>stareestimari2</obj_name>
  <obj_hashval>c05b70db529fff52fac707b2ca3ef077</obj_hashval>
  <obj_text>CREATE TABLE stareestimari2 (
  "codstare2" numeric(20,0) NOT NULL,
  "codstare" numeric(20,0),
  "codcomanda1" numeric(20,0),
  "datadoc" date,
  "nrdoc" numeric(20,0),
  "codpart" numeric(20,0),
  "codobiect" numeric(20,0),
  "umsec" numeric(20,0),
  "restacceptat" numeric(20,7),
  "pu" numeric(20,7),
  "codmoneda" numeric(20,0),
  "termen" date,
  "saptamana" numeric(2,0),
  "codstare1" numeric(20,0),
  "proprie" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>statcon</obj_name>
  <obj_hashval>182b43419d9a22ae43cf26502693191f</obj_hashval>
  <obj_text>CREATE TABLE statcon (
  "codstatcon" numeric(20,0),
  "codevals" numeric(20,0),
  "atribut" numeric(1,0),
  "den_evaluare" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>statcor</obj_name>
  <obj_hashval>bd05fac635d7c7246ace8291cd152af8</obj_hashval>
  <obj_text>CREATE TABLE statcor (
  "codstatcor" numeric(20,0),
  "codevals" numeric(20,0),
  "atribut" numeric(1,0),
  "den_evaluare" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>statcor1</obj_name>
  <obj_hashval>519ca4bb0f6b608b7b166c649b13eba3</obj_hashval>
  <obj_text>CREATE TABLE statcor1 (
  "codstatcor1" numeric(20,0),
  "codstatcor" numeric(20,0),
  "codtesatura" numeric(20,0),
  "valoare" numeric(10,8),
  "ai" numeric(2,1),
  "rii" numeric(2,1)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>statusdecl</obj_name>
  <obj_hashval>2d8d92dc1a7358829cf69609e52fee5f</obj_hashval>
  <obj_text>CREATE TABLE statusdecl (
  "codstatusdecl" numeric(20,0) NOT NULL,
  "tipdoc" numeric(5,0),
  "coddoc" numeric(20,0),
  "idincarcare" character varying(20),
  "iddescarcare" character varying(20),
  "dataincarcare" timestamp(6) without time zone,
  "stare" character varying(20),
  "tipmediu" numeric(1,0),
  "username" character varying(20),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "compname" character varying(20),
  "filename" character varying(250),
  "mesaje" text,
  "cif" character varying(20),
  "serie_certif" character varying(250),
  "uit" character varying(20)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>stingere</obj_name>
  <obj_hashval>dcbe95d6335883b1dd76cfeb4665e3ab</obj_hashval>
  <obj_text>CREATE TABLE stingere (
  "codstingere" numeric(20,0) NOT NULL,
  "codstinspif" numeric(20,0),
  "codstingatorpif" numeric(20,0),
  "valoare" numeric(20,7),
  "codplata1" numeric(20,0),
  "valtranzf" numeric(20,7),
  "valtranzc" numeric(20,7),
  "dincaretva" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>stocfake</obj_name>
  <obj_hashval>ee546fb560f925d1b30d26458d2e9699</obj_hashval>
  <obj_text>CREATE TABLE stocfake (
  "codstocfake" numeric(20,0),
  "codobiect" numeric(20,0) NOT NULL,
  "cant" numeric(20,7),
  "pret" numeric(20,7),
  "warehouseid" character varying(35),
  "locationid" character varying(18),
  "productcode" character varying(70),
  "stockaccountno" character varying(70),
  "producttype" character varying(18),
  "productstatus" character varying(18),
  "stockaccountcommoditycode" character varying(35),
  "ownerid" character varying(35),
  "uomphysicalstock" character varying(9),
  "uomtouombaseconversionfactor" character varying(2),
  "unitprice" numeric(18,2),
  "openingstockquantity" numeric(22,6),
  "openingstockvalue" numeric(18,2),
  "closingstockquantity" numeric(22,6),
  "closingstockvalue" numeric(18,2),
  "stockcharacteristics" character varying(18),
  "stockcharacteristicvalue" character varying(35),
  "an" numeric(20,0),
  "luna" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nparccom_codnparcaut</obj_name>
  <obj_reftable>nparccom</obj_reftable>
  <obj_hashval>602315243e5bff1071bc7d0b9534cbb9</obj_hashval>
  <obj_text>CREATE INDEX idx_nparccom_codnparcaut ON nparccom USING btree (codnparcaut)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nparcg</obj_name>
  <obj_reftable>nparcg</obj_reftable>
  <obj_hashval>4df59b0ec8d6786dc28b095a6b8f84b2</obj_hashval>
  <obj_text>CREATE INDEX idx_nparcg ON nparcg USING btree (codnparcaut, data)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npart_codextern</obj_name>
  <obj_reftable>npart</obj_reftable>
  <obj_hashval>918929620d34d44e26e193ed45e58189</obj_hashval>
  <obj_text>CREATE INDEX idx_npart_codextern ON npart USING btree (codextern)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npart_codintern</obj_name>
  <obj_reftable>npart</obj_reftable>
  <obj_hashval>8f3495a32e32cffd6571c1d68a9ef29f</obj_hashval>
  <obj_text>CREATE INDEX idx_npart_codintern ON npart USING btree (codintern)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npart1_al</obj_name>
  <obj_reftable>npart1</obj_reftable>
  <obj_hashval>bce92526efbaf9420d2c889b2945d703</obj_hashval>
  <obj_text>CREATE INDEX idx_npart1_al ON npart1 USING btree (codpart, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npart1_codpart</obj_name>
  <obj_reftable>npart1</obj_reftable>
  <obj_hashval>7fc55ccb18499f9809351fbaa0e0d276</obj_hashval>
  <obj_text>CREATE INDEX idx_npart1_codpart ON npart1 USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npart1crm_al</obj_name>
  <obj_reftable>npart1crm</obj_reftable>
  <obj_hashval>75d9ef1fccdb54ccfb51e89c14cdcea8</obj_hashval>
  <obj_text>CREATE INDEX idx_npart1crm_al ON npart1crm USING btree (codpart, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npart1crm_codpart</obj_name>
  <obj_reftable>npart1crm</obj_reftable>
  <obj_hashval>31dca33f985300aebbc355f0f1951143</obj_hashval>
  <obj_text>CREATE INDEX idx_npart1crm_codpart ON npart1crm USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npart1x_al</obj_name>
  <obj_reftable>npart1x</obj_reftable>
  <obj_hashval>06c63812f9809dcadf948d86868b16ef</obj_hashval>
  <obj_text>CREATE INDEX idx_npart1x_al ON npart1x USING btree (codpart, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>stocfake1</obj_name>
  <obj_hashval>44b55bc4ab4714c399929a81cc307152</obj_hashval>
  <obj_text>CREATE TABLE stocfake1 (
  "codstocfake1" numeric(20,0) NOT NULL,
  "codstocfake" numeric(20,0),
  "tg" date,
  "serie" character varying(75),
  "idgestiune" character varying(15),
  "cant" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>stocini</obj_name>
  <obj_hashval>c4e1214af0e3df4c8e66683641189d88</obj_hashval>
  <obj_text>CREATE TABLE stocini (
  "codstocini" numeric(20,0) NOT NULL,
  "codgest" numeric(20,0),
  "codpers" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>stociniart</obj_name>
  <obj_hashval>d0b982d326f88c047961f809e526a7f8</obj_hashval>
  <obj_text>CREATE TABLE stociniart (
  "codobiect" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>stoclock</obj_name>
  <obj_hashval>86c88e46cc63703cdf477ae41e172dd1</obj_hashval>
  <obj_text>CREATE TABLE stoclock (
  "userid" numeric(20,0),
  "codnirstoc" numeric(20,0),
  "codnirser" numeric(20,0),
  "cant" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npartactivit_codpart</obj_name>
  <obj_reftable>npartactivit</obj_reftable>
  <obj_hashval>551e558f71ac048cd84c6e8234e5674c</obj_hashval>
  <obj_text>CREATE INDEX idx_npartactivit_codpart ON npartactivit USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>stoclockemul</obj_name>
  <obj_hashval>f9e731b83bfc15d11601b275f5c65585</obj_hashval>
  <obj_text>CREATE TABLE stoclockemul (
  "userid" numeric(20,0),
  "codemulare1" numeric(20,0),
  "codobiect" numeric(20,0),
  "codgest" numeric(20,0),
  "codioart" numeric(20,0),
  "pret" numeric(20,7),
  "cant" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>stoclockrest</obj_name>
  <obj_hashval>4ef3cb30918dcd26e4ef6651cf0128d2</obj_hashval>
  <obj_text>CREATE TABLE stoclockrest (
  "userid" numeric(20,0),
  "codrestcmd1" numeric(20,0),
  "codobiect" numeric(20,0),
  "codgest" numeric(20,0),
  "cant" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>stocmpart</obj_name>
  <obj_hashval>82826d8ddd823c50e1b2a4d7ecbada2d</obj_hashval>
  <obj_text>CREATE TABLE stocmpart (
  "codlocatie" numeric(20,0),
  "codextern" character varying(30),
  "stocmin" numeric(20,7),
  "stocmax" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npartb_codlocalit</obj_name>
  <obj_reftable>npartb</obj_reftable>
  <obj_hashval>d7aa34152a1e200e150d6feb26ef3da8</obj_hashval>
  <obj_text>CREATE INDEX idx_npartb_codlocalit ON npartb USING btree (codlocalit)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npartb_codpart</obj_name>
  <obj_reftable>npartb</obj_reftable>
  <obj_hashval>21853f79420ca291b1d45b5681dafa9c</obj_hashval>
  <obj_text>CREATE INDEX idx_npartb_codpart ON npartb USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npartcodfisc_codpart</obj_name>
  <obj_reftable>npartcodfisc</obj_reftable>
  <obj_hashval>8659288949852d5a41e892cc96ccda9c</obj_hashval>
  <obj_text>CREATE INDEX idx_npartcodfisc_codpart ON npartcodfisc USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npartdisc_codpart</obj_name>
  <obj_reftable>npartdisc</obj_reftable>
  <obj_hashval>eb20282c6e7335ea8fab8841734bf0bb</obj_hashval>
  <obj_text>CREATE INDEX idx_npartdisc_codpart ON npartdisc USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npartdomact_coddomeniuact</obj_name>
  <obj_reftable>npartdomact</obj_reftable>
  <obj_hashval>76019763a779cbd54b5291c0ef570b41</obj_hashval>
  <obj_text>CREATE INDEX idx_npartdomact_coddomeniuact ON npartdomact USING btree (coddomeniuact)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npartdomact_codpart</obj_name>
  <obj_reftable>npartdomact</obj_reftable>
  <obj_hashval>5aaa2ae206d3bb7ed61bbabca2b1b20c</obj_hashval>
  <obj_text>CREATE INDEX idx_npartdomact_codpart ON npartdomact USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npartlstclase_codpart</obj_name>
  <obj_reftable>npartlstclase</obj_reftable>
  <obj_hashval>1e51093442858f1391a24a20e5ff3840</obj_hashval>
  <obj_text>CREATE INDEX idx_npartlstclase_codpart ON npartlstclase USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npartretail_codpart</obj_name>
  <obj_reftable>npartretail</obj_reftable>
  <obj_hashval>2f513c79cf229d03b4eb1d4bb43fc820</obj_hashval>
  <obj_text>CREATE INDEX idx_npartretail_codpart ON npartretail USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npartsoldluna</obj_name>
  <obj_reftable>npartsoldluna</obj_reftable>
  <obj_hashval>b94e68fedab19128b498a6c446c832d1</obj_hashval>
  <obj_text>CREATE INDEX idx_npartsoldluna ON npartsoldluna USING btree (an, luna, codpart, icont, codmoneda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npartsoldlunasub</obj_name>
  <obj_reftable>npartsoldlunasub</obj_reftable>
  <obj_hashval>c546354fa9812f86c2e40a91150746cf</obj_hashval>
  <obj_text>CREATE INDEX idx_npartsoldlunasub ON npartsoldlunasub USING btree (an, luna, codpart, icont, codmoneda, subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npartsubunit_codpart</obj_name>
  <obj_reftable>npartsubunit</obj_reftable>
  <obj_hashval>a2d2561bd2992970063719b1037aa503</obj_hashval>
  <obj_text>CREATE INDEX idx_npartsubunit_codpart ON npartsubunit USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npartsubunit_subunitatea</obj_name>
  <obj_reftable>npartsubunit</obj_reftable>
  <obj_hashval>69bd422d1570568dca3280628a5a074a</obj_hashval>
  <obj_text>CREATE INDEX idx_npartsubunit_subunitatea ON npartsubunit USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nparttr_codpart</obj_name>
  <obj_reftable>nparttr</obj_reftable>
  <obj_hashval>33eaf264352c417943494df7dcb5d727</obj_hashval>
  <obj_text>CREATE INDEX idx_nparttr_codpart ON nparttr USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nparttrlnk_codparttrlnk</obj_name>
  <obj_reftable>nparttr_lnk</obj_reftable>
  <obj_hashval>8cf30eef378bffe4caa023216cf8f7b1</obj_hashval>
  <obj_text>CREATE INDEX idx_nparttrlnk_codparttrlnk ON nparttr_lnk USING btree (codparttrlnk)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npers1_al</obj_name>
  <obj_reftable>npers1</obj_reftable>
  <obj_hashval>7ab5abb0e98fe7694c88ff5cab64bbb7</obj_hashval>
  <obj_text>CREATE INDEX idx_npers1_al ON npers1 USING btree (codpers, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_npers1_codpers</obj_name>
  <obj_reftable>npers1</obj_reftable>
  <obj_hashval>e68511184e1286d2b2634bcdbf8b4993</obj_hashval>
  <obj_text>CREATE INDEX idx_npers1_codpers ON npers1 USING btree (codpers)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nperscontact_codpart</obj_name>
  <obj_reftable>nperscontact</obj_reftable>
  <obj_hashval>80623f395d03c47560b492a6e52c5b71</obj_hashval>
  <obj_text>CREATE INDEX idx_nperscontact_codpart ON nperscontact USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nperssoldluna</obj_name>
  <obj_reftable>nperssoldluna</obj_reftable>
  <obj_hashval>bead33952fa78244d4a21ca3c0be49f8</obj_hashval>
  <obj_text>CREATE INDEX idx_nperssoldluna ON nperssoldluna USING btree (an, luna, codpers, codmoneda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nperssoldluna_codmoneda</obj_name>
  <obj_reftable>nperssoldluna</obj_reftable>
  <obj_hashval>84e26a9652de48d3c5d8a0d1bf2da926</obj_hashval>
  <obj_text>CREATE INDEX idx_nperssoldluna_codmoneda ON nperssoldluna USING btree (codmoneda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nperssoldluna_codpers</obj_name>
  <obj_reftable>nperssoldluna</obj_reftable>
  <obj_hashval>94e4810589b413c1884450b035a7832b</obj_hashval>
  <obj_text>CREATE INDEX idx_nperssoldluna_codpers ON nperssoldluna USING btree (codpers)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nperssoldluna_icont</obj_name>
  <obj_reftable>nperssoldluna</obj_reftable>
  <obj_hashval>dbe041a86ede62f4cd6fd73984a330bf</obj_hashval>
  <obj_text>CREATE INDEX idx_nperssoldluna_icont ON nperssoldluna USING btree (icont)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nperssoldlunasub</obj_name>
  <obj_reftable>nperssoldlunasub</obj_reftable>
  <obj_hashval>ee9dc8018e87f3c4bdc9bef4605f6d2a</obj_hashval>
  <obj_text>CREATE INDEX idx_nperssoldlunasub ON nperssoldlunasub USING btree (an, luna, codpers, codmoneda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nplink_codlivr1</obj_name>
  <obj_reftable>nplink</obj_reftable>
  <obj_hashval>0d5c450844102aeccd45fe2ddf1cd3c5</obj_hashval>
  <obj_text>CREATE INDEX idx_nplink_codlivr1 ON nplink USING btree (codlivr1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nplink_codnirstoc</obj_name>
  <obj_reftable>nplink</obj_reftable>
  <obj_hashval>4ba25cfce6c9dc04431ab1afa00f5a6b</obj_hashval>
  <obj_text>CREATE INDEX idx_nplink_codnirstoc ON nplink USING btree (codnirstoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nscadentartl1_codscadtl</obj_name>
  <obj_reftable>nscadtl1</obj_reftable>
  <obj_hashval>59665518d19b6fee14945d93f0828b45</obj_hashval>
  <obj_text>CREATE INDEX idx_nscadentartl1_codscadtl ON nscadtl1 USING btree (codscadtl)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nsediipartretail_codagenda</obj_name>
  <obj_reftable>nsediipartretail</obj_reftable>
  <obj_hashval>76b7c9009e5caf02cf196a298ff47364</obj_hashval>
  <obj_text>CREATE INDEX idx_nsediipartretail_codagenda ON nsediipartretail USING btree (codagenda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nserii_codobiect</obj_name>
  <obj_reftable>nserii</obj_reftable>
  <obj_hashval>8e070757ea2e0e593236dfc9a8dc98d1</obj_hashval>
  <obj_text>CREATE INDEX idx_nserii_codobiect ON nserii USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_nsubunit1_al</obj_name>
  <obj_reftable>nsubunit1</obj_reftable>
  <obj_hashval>c4ba7ff60b7136b0e46aa8f664e4f969</obj_hashval>
  <obj_text>CREATE INDEX idx_nsubunit1_al ON nsubunit1 USING btree (codsubunit, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ntaxe1_al</obj_name>
  <obj_reftable>ntaxe1</obj_reftable>
  <obj_hashval>828893bc7c3c22f8a0888c76b8e575a1</obj_hashval>
  <obj_text>CREATE INDEX idx_ntaxe1_al ON ntaxe1 USING btree (codtaxa, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ntaxe1_anluna</obj_name>
  <obj_reftable>ntaxe1</obj_reftable>
  <obj_hashval>e563487a93fcc1e2f41f88c0f6e6efd8</obj_hashval>
  <obj_text>CREATE INDEX idx_ntaxe1_anluna ON ntaxe1 USING btree ((((anstart * (12)::numeric) + lunastart)))</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ntaxe1_codcont</obj_name>
  <obj_reftable>ntaxe1</obj_reftable>
  <obj_hashval>1d1bbae46005d69dd8cc37d3b78bf1c2</obj_hashval>
  <obj_text>CREATE INDEX idx_ntaxe1_codcont ON ntaxe1 USING btree (codcont)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ntaxe1_codcontchelt</obj_name>
  <obj_reftable>ntaxe1</obj_reftable>
  <obj_hashval>3bba60e594ae2cb8ed7a7599c2d51922</obj_hashval>
  <obj_text>CREATE INDEX idx_ntaxe1_codcontchelt ON ntaxe1 USING btree (codcontchelt)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ntva1_al</obj_name>
  <obj_reftable>ntva1</obj_reftable>
  <obj_hashval>3b9b346c9a89c15f00fb8393ccdf55fe</obj_hashval>
  <obj_text>CREATE INDEX idx_ntva1_al ON ntva1 USING btree (codtva, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ntva1_anluna</obj_name>
  <obj_reftable>ntva1</obj_reftable>
  <obj_hashval>8ef7c0da2c77f39a04da7286b653d799</obj_hashval>
  <obj_text>CREATE INDEX idx_ntva1_anluna ON ntva1 USING btree ((((anstart * (12)::numeric) + lunastart)))</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ntva1_codcontcole</obj_name>
  <obj_reftable>ntva1</obj_reftable>
  <obj_hashval>91fdae4ac65ded931509ea7425a7818e</obj_hashval>
  <obj_text>CREATE INDEX idx_ntva1_codcontcole ON ntva1 USING btree (codcontcole)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ntva1_codcontded</obj_name>
  <obj_reftable>ntva1</obj_reftable>
  <obj_hashval>b192c1be8c4006664d495273c6abbeb9</obj_hashval>
  <obj_text>CREATE INDEX idx_ntva1_codcontded ON ntva1 USING btree (codcontded)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ntva1_codcontneex</obj_name>
  <obj_reftable>ntva1</obj_reftable>
  <obj_hashval>5f77a6b8ac9f214f3e5f14e348e31d26</obj_hashval>
  <obj_text>CREATE INDEX idx_ntva1_codcontneex ON ntva1 USING btree (codcontneex)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ntva1_codtva</obj_name>
  <obj_reftable>ntva1</obj_reftable>
  <obj_hashval>b9bdd89d9e524e516bd58f92ae289ac2</obj_hashval>
  <obj_text>CREATE INDEX idx_ntva1_codtva ON ntva1 USING btree (codtva)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_num1_codum</obj_name>
  <obj_reftable>num1</obj_reftable>
  <obj_hashval>1a25ce17f620c8549d6df96a2da2375a</obj_hashval>
  <obj_text>CREATE INDEX idx_num1_codum ON num1 USING btree (codum)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_obj_cmdint1_codcmdint1</obj_name>
  <obj_reftable>obj_cmdint1</obj_reftable>
  <obj_hashval>027bea61e1af9ab2baafdd1195268ec8</obj_hashval>
  <obj_text>CREATE INDEX idx_obj_cmdint1_codcmdint1 ON obj_cmdint1 USING btree (codcmdint1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_obj_cmdint1_codobiect</obj_name>
  <obj_reftable>obj_cmdint1</obj_reftable>
  <obj_hashval>30df8d67944b72a3337fd2c54d0bbf1d</obj_hashval>
  <obj_text>CREATE INDEX idx_obj_cmdint1_codobiect ON obj_cmdint1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_obligpif_codgeneral</obj_name>
  <obj_reftable>obligpif</obj_reftable>
  <obj_hashval>deaad94ca197aaf36480e98309622392</obj_hashval>
  <obj_text>CREATE INDEX idx_obligpif_codgeneral ON obligpif USING btree (codgeneral)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_obligpif_codobligasociat</obj_name>
  <obj_reftable>obligpif</obj_reftable>
  <obj_hashval>d0d8223731866278594a245ad4ac09bc</obj_hashval>
  <obj_text>CREATE INDEX idx_obligpif_codobligasociat ON obligpif USING btree (codobligasociat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_obligpif_codpart</obj_name>
  <obj_reftable>obligpif</obj_reftable>
  <obj_hashval>eb4dce3281b4d2e9bd6f9c966a5568cc</obj_hashval>
  <obj_text>CREATE INDEX idx_obligpif_codpart ON obligpif USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_obligpif_semnificatie</obj_name>
  <obj_reftable>obligpif</obj_reftable>
  <obj_hashval>a655bc89694f4aa89ec736fcd9eeac33</obj_hashval>
  <obj_text>CREATE INDEX idx_obligpif_semnificatie ON obligpif USING btree (semnificatie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_obligpifluna_alr</obj_name>
  <obj_reftable>obligpifluna</obj_reftable>
  <obj_hashval>351ae58940f02d6261f7c1055acfed61</obj_hashval>
  <obj_text>CREATE INDEX idx_obligpifluna_alr ON obligpifluna USING btree (an, luna, rest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_obligpifluna_anluna</obj_name>
  <obj_reftable>obligpifluna</obj_reftable>
  <obj_hashval>5335422cdf3f8022031587cdf89848bf</obj_hashval>
  <obj_text>CREATE INDEX idx_obligpifluna_anluna ON obligpifluna USING btree (((((12)::numeric * an) + luna)))</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_obligpifluna_cal</obj_name>
  <obj_reftable>obligpifluna</obj_reftable>
  <obj_hashval>07083b3a730fa91dd3da6f292f51af63</obj_hashval>
  <obj_text>CREATE INDEX idx_obligpifluna_cal ON obligpifluna USING btree (codobligpif, an, luna)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_oferta_locatie</obj_name>
  <obj_reftable>oferta</obj_reftable>
  <obj_hashval>3eb9a34dc090a8064f553ae85cab26b1</obj_hashval>
  <obj_text>CREATE INDEX idx_oferta_locatie ON oferta USING btree (codlocatie)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>stocposuri</obj_name>
  <obj_hashval>804c48363bc86d8458befd0fb0b65293</obj_hashval>
  <obj_text>CREATE TABLE stocposuri (
  "codstocpos" numeric(20,0) NOT NULL,
  "codpos" numeric(20,0),
  "tippos" numeric(2,0),
  "codgest" numeric(20,0),
  "codobiect" numeric(20,0),
  "codioart" numeric(20,0),
  "tva" numeric(20,7),
  "pret" numeric(20,7),
  "coddep" numeric(3,0),
  "plu" numeric(20,0),
  "pretnou" numeric(20,7),
  "stoc" numeric(20,7),
  "barcode" character varying(30),
  "denobiect" character varying(200),
  "modificari" numeric(1,0),
  "pretart" numeric(20,7),
  "difpret" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>stocvalini</obj_name>
  <obj_hashval>d677f0eaa7917a810d468126fc1c222f</obj_hashval>
  <obj_text>CREATE TABLE stocvalini (
  "codstocvalini" numeric(20,0) NOT NULL,
  "gest" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_oferta_partener</obj_name>
  <obj_reftable>oferta</obj_reftable>
  <obj_hashval>380b86abf6b2be1a6070ef81a538abd3</obj_hashval>
  <obj_text>CREATE INDEX idx_oferta_partener ON oferta USING btree (partener)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>stocvalluna</obj_name>
  <obj_hashval>5f78229c4d436bec17386f2a2cb79b66</obj_hashval>
  <obj_text>CREATE TABLE stocvalluna (
  "codstocvalluna" numeric(20,0) NOT NULL,
  "gest" numeric(20,0),
  "codioart" numeric(20,0),
  "tva" numeric(20,7),
  "sold" numeric(20,7),
  "adaos" numeric(20,7),
  "soldintr" numeric(20,7),
  "adaosintr" numeric(20,7),
  "an" numeric(5,0),
  "luna" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>stornocmdf</obj_name>
  <obj_hashval>6828c383b9656dc518a427ce01a24fb3</obj_hashval>
  <obj_text>CREATE TABLE stornocmdf (
  "cod" numeric(20,0),
  "codcomanda1" numeric(20,0),
  "codliniecomanda" numeric(20,0),
  "codintr1" numeric(20,0),
  "cant" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>syncpartretail</obj_name>
  <obj_hashval>701aaf416b00b6fc1eb83e391adb429d</obj_hashval>
  <obj_text>CREATE TABLE syncpartretail (
  "codsyncpart" numeric(20,0),
  "codpart" numeric(20,0),
  "codpostretail" numeric(20,0),
  "sincronizat" numeric(1,0),
  "data" date
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>syncpretretail</obj_name>
  <obj_hashval>701a3ec56c306b150ea69945df717daa</obj_hashval>
  <obj_text>CREATE TABLE syncpretretail (
  "codsync" numeric(20,0) NOT NULL,
  "codpostretail" numeric(20,0),
  "codobiect" numeric(20,0),
  "codcatpret" numeric(20,0),
  "pretvechi" numeric(20,7),
  "pretnou" numeric(20,7),
  "data" timestamp(0) without time zone,
  "sincronizat" numeric(1,0),
  "idpreluare" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_oferta_subunitatea</obj_name>
  <obj_reftable>oferta</obj_reftable>
  <obj_hashval>4cae7fa121a95a04ebba727634831af8</obj_hashval>
  <obj_text>CREATE INDEX idx_oferta_subunitatea ON oferta USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_oferta1_codobiect</obj_name>
  <obj_reftable>oferta1</obj_reftable>
  <obj_hashval>96d9d7721736e87837cf837a66ddb97b</obj_hashval>
  <obj_text>CREATE INDEX idx_oferta1_codobiect ON oferta1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>syncpromoretail</obj_name>
  <obj_hashval>6dc930ffd39218845be954aaf71aeda6</obj_hashval>
  <obj_text>CREATE TABLE syncpromoretail (
  "codsyncpromo" numeric(20,0) NOT NULL,
  "codpromo" numeric(20,0),
  "codpostretail" numeric(20,0),
  "sincronizat" numeric(1,0),
  "data" date,
  "tipmodif" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tabimpcod</obj_name>
  <obj_hashval>2d5bf4fb6b04430c022f8775d3b2d26a</obj_hashval>
  <obj_text>CREATE TABLE tabimpcod (
  "imptabname" character varying(30),
  "imppkval" numeric(20,0),
  "tabname" character varying(30),
  "tabpkval" numeric(20,0),
  "impcolval" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tabimpcodwm</obj_name>
  <obj_hashval>8b45bd81be8df40322fc047292b8b21a</obj_hashval>
  <obj_text>CREATE TABLE tabimpcodwm (
  "imptabname" character varying(30),
  "imppkval" numeric(20,0),
  "tabname" character varying(30),
  "tabpkval" numeric(20,0),
  "impcolval" numeric(20,0),
  "subunitatea" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_oferta1_codoferta</obj_name>
  <obj_reftable>oferta1</obj_reftable>
  <obj_hashval>bbb281137417c9e1ea1c3f142e0a158b</obj_hashval>
  <obj_text>CREATE INDEX idx_oferta1_codoferta ON oferta1 USING btree (codoferta)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_oferta1_umsec</obj_name>
  <obj_reftable>oferta1</obj_reftable>
  <obj_hashval>ee0a59716e1f8cdd9f5cf2b78d98344c</obj_hashval>
  <obj_text>CREATE INDEX idx_oferta1_umsec ON oferta1 USING btree (umsec)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_orelm_data</obj_name>
  <obj_reftable>orelm</obj_reftable>
  <obj_hashval>2e50181823e654a324d095e777d305fc</obj_hashval>
  <obj_text>CREATE INDEX idx_orelm_data ON orelm USING btree (datalm)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>targetag</obj_name>
  <obj_hashval>0b06b2cfad0c844f19c1fbfed432ba53</obj_hashval>
  <obj_text>CREATE TABLE targetag (
  "codtargetag" numeric(20,0) NOT NULL,
  "tipdoc" numeric(20,0),
  "anulat" numeric(1,0),
  "blocat" numeric(1,0),
  "operat" numeric(1,0),
  "activ" numeric(1,0),
  "agent" numeric(20,0),
  "moneda" numeric(20,0),
  "datastart" date,
  "datastop" date,
  "tiptarget" numeric(1,0),
  "obs" character varying(250),
  "subunitatea" numeric(20,0),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "userid" numeric,
  "datacreare" timestamp(6) without time zone,
  "lunastart" numeric(2,0),
  "anstart" numeric(4,0),
  "lunaend" numeric(2,0),
  "anend" numeric(4,0),
  "nrclienti" numeric(10,0),
  "client" numeric(20,0),
  "clasapart" numeric(20,0),
  "tippart" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_orepontaj_codformatie</obj_name>
  <obj_reftable>orepontaj</obj_reftable>
  <obj_hashval>ed33ff9dd1c05afb32099515ab9b440f</obj_hashval>
  <obj_text>CREATE INDEX idx_orepontaj_codformatie ON orepontaj USING btree (codformatie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_orepontaj_codpers</obj_name>
  <obj_reftable>orepontaj</obj_reftable>
  <obj_hashval>a74e1e407405e274ab72ec50a8277c60</obj_hashval>
  <obj_text>CREATE INDEX idx_orepontaj_codpers ON orepontaj USING btree (codpers)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>targetag1</obj_name>
  <obj_hashval>85fb35af33618bca81de02efc7df100d</obj_hashval>
  <obj_text>CREATE TABLE targetag1 (
  "codtargetag1" numeric(20,0) NOT NULL,
  "codtargetag" numeric(20,0),
  "codobiect" numeric(20,0),
  "codclasa" numeric(20,0),
  "umsec" numeric(20,0),
  "cant" numeric(20,7),
  "valoare" numeric(20,7),
  "obs" character varying(200),
  "masa" numeric(20,7),
  "cantmin" numeric(20,7),
  "cantmax" numeric(20,7),
  "codclasas" numeric(20,0),
  "volum" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tarife_master</obj_name>
  <obj_hashval>5c146bf7d38f00db06ca825f7d9c1b99</obj_hashval>
  <obj_text>CREATE TABLE tarife_master (
  "codtarifm" numeric(20,0) NOT NULL
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tarifeman</obj_name>
  <obj_hashval>ba7448a51fb0280843380a9cd19cbc24</obj_hashval>
  <obj_text>CREATE TABLE tarifeman (
  "codtarif" numeric(20,0) NOT NULL,
  "denumire" character varying(150),
  "codextern" character varying(80),
  "codmoneda" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pachdllink_codpacheteobj</obj_name>
  <obj_reftable>pachetedllink</obj_reftable>
  <obj_hashval>a953a4ce8025beaff638f5275dc6075b</obj_hashval>
  <obj_text>CREATE INDEX idx_pachdllink_codpacheteobj ON pachetedllink USING btree (codpacheteobj)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pachete1_coddoc</obj_name>
  <obj_reftable>pachete1</obj_reftable>
  <obj_hashval>9536883239dfe924ae7bd6b1ce53fa8a</obj_hashval>
  <obj_text>CREATE INDEX idx_pachete1_coddoc ON pachete1 USING btree (coddoc)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tarifeman1</obj_name>
  <obj_hashval>ba9dbf00d32a1513a354334a16aeae71</obj_hashval>
  <obj_text>CREATE TABLE tarifeman1 (
  "codtarif1" numeric(20,0) NOT NULL,
  "codtarif" numeric(20,0),
  "tarif" numeric(20,7),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0),
  "tarif1" numeric(20,7),
  "tarif2" numeric(20,7),
  "tarif3" numeric(20,7),
  "tarif4" numeric(20,7),
  "tarif5" numeric(20,7),
  "tarif6" numeric(20,7),
  "tarif7" numeric(20,7),
  "tarif8" numeric(20,7),
  "tarif9" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pachete1_codpachete</obj_name>
  <obj_reftable>pachete1</obj_reftable>
  <obj_hashval>2983f04b961b7fb74d1b02d253feb9d5</obj_hashval>
  <obj_text>CREATE INDEX idx_pachete1_codpachete ON pachete1 USING btree (codpachete)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pachete1_tipdoc</obj_name>
  <obj_reftable>pachete1</obj_reftable>
  <obj_hashval>25f3eea4c9ede04035e3a85bd19bd5c2</obj_hashval>
  <obj_text>CREATE INDEX idx_pachete1_tipdoc ON pachete1 USING btree (tipdoc)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>taxdecl</obj_name>
  <obj_hashval>bfc9775e44a22f61edd2fb7abe71978f</obj_hashval>
  <obj_text>CREATE TABLE taxdecl (
  "codtaxdecl" numeric(20,0) NOT NULL,
  "tipdoc" numeric(5,0),
  "coddoc" numeric(20,0),
  "coddoc1" numeric(20,0),
  "taxcode" numeric(20,0),
  "taxbase" numeric(22,7),
  "cheia" character varying(400),
  "manual" numeric(1,0),
  "codcont" numeric(20,0),
  "taxval" numeric(22,7),
  "anluna" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pachetelink_codpacheteobj</obj_name>
  <obj_reftable>pachetelink</obj_reftable>
  <obj_hashval>45fe38e9b7f2e8e5e5a6277014bb89ca</obj_hashval>
  <obj_text>CREATE INDEX idx_pachetelink_codpacheteobj ON pachetelink USING btree (codpacheteobj)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>teme</obj_name>
  <obj_hashval>33312012740e0df589b5d2c1bcd7cea0</obj_hashval>
  <obj_text>CREATE TABLE teme (
  "codtema" numeric(20,0) NOT NULL,
  "den_tema" character varying(60),
  "ore" numeric(10,0),
  "pret" numeric(20,7),
  "codformator" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_packing_codamb_primar</obj_name>
  <obj_reftable>packing1</obj_reftable>
  <obj_hashval>d47e2abe196f45f3ac494e90cfeabedc</obj_hashval>
  <obj_text>CREATE INDEX idx_packing_codamb_primar ON packing1 USING btree (codamb_primar)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>termenecmd</obj_name>
  <obj_hashval>5b7c473178bcbf80123ab22631059842</obj_hashval>
  <obj_text>CREATE TABLE termenecmd (
  "codtermen" numeric(20,0),
  "codcomanda" numeric(20,0),
  "zile" numeric(5,0),
  "procent" numeric(20,7),
  "tipplata" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_packing_codamb_secundar</obj_name>
  <obj_reftable>packing1</obj_reftable>
  <obj_hashval>79892d0ff07e4726679ca736bceda04e</obj_hashval>
  <obj_text>CREATE INDEX idx_packing_codamb_secundar ON packing1 USING btree (codamb_secundar)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_packing_codamb_tertiar</obj_name>
  <obj_reftable>packing1</obj_reftable>
  <obj_hashval>69379bc1eec5edd537b2c868cd37e379</obj_hashval>
  <obj_text>CREATE INDEX idx_packing_codamb_tertiar ON packing1 USING btree (codamb_tertiar)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_packing_coddoc_tipdoc</obj_name>
  <obj_reftable>packing</obj_reftable>
  <obj_hashval>e5901b1ab2464a9cdca3d416e84665a5</obj_hashval>
  <obj_text>CREATE INDEX idx_packing_coddoc_tipdoc ON packing USING btree (coddoc, tipdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_packing_codpacking</obj_name>
  <obj_reftable>packing1</obj_reftable>
  <obj_hashval>1863f3a69000254f4f54c30b53792d5d</obj_hashval>
  <obj_text>CREATE INDEX idx_packing_codpacking ON packing1 USING btree (codpacking)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_parttot_codpart</obj_name>
  <obj_reftable>parttot</obj_reftable>
  <obj_hashval>0616d99b59052ee04b453e226b3e523a</obj_hashval>
  <obj_text>CREATE INDEX idx_parttot_codpart ON parttot USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pc_man_codobiect</obj_name>
  <obj_reftable>tmp_prodcomp_man</obj_reftable>
  <obj_hashval>e414b7a70698eb967245ea1f44ccb2c1</obj_hashval>
  <obj_text>CREATE INDEX idx_pc_man_codobiect ON tmp_prodcomp_man USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pc_man_codprodcomp</obj_name>
  <obj_reftable>tmp_prodcomp_man</obj_reftable>
  <obj_hashval>82d3912cf3e4b99525df6ee26d2c7858</obj_hashval>
  <obj_text>CREATE INDEX idx_pc_man_codprodcomp ON tmp_prodcomp_man USING btree (codprodcomp)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pc_man_userid</obj_name>
  <obj_reftable>tmp_prodcomp_man</obj_reftable>
  <obj_hashval>6adae1b150c708a631115478702dbece</obj_hashval>
  <obj_text>CREATE INDEX idx_pc_man_userid ON tmp_prodcomp_man USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tesaturi</obj_name>
  <obj_hashval>6a7d1030518aa128262f082ba28cf841</obj_hashval>
  <obj_text>CREATE TABLE tesaturi (
  "codtesatura" numeric(20,0),
  "denumire" character varying(100),
  "compozitie" character varying(300),
  "masaspecifica" character varying(200),
  "legatura" character varying(200),
  "desimeu" character varying(200),
  "desimeb" character varying(200),
  "categorie" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tipchelt</obj_name>
  <obj_hashval>9f393eb91ed3e20ec08eaddb1844c854</obj_hashval>
  <obj_text>CREATE TABLE tipchelt (
  "codtipchelt" numeric(20,0) NOT NULL,
  "denumire" character varying(200),
  "codcont" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planiflink_codcomanda1</obj_name>
  <obj_reftable>planiflink</obj_reftable>
  <obj_hashval>26f5232d43bca90984885d36abb3d1c2</obj_hashval>
  <obj_text>CREATE INDEX idx_planiflink_codcomanda1 ON planiflink USING btree (codcomanda1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planiflink_codstare1</obj_name>
  <obj_reftable>planiflink</obj_reftable>
  <obj_hashval>671cba0ad2139a511ccabaf14ce9651e</obj_hashval>
  <obj_text>CREATE INDEX idx_planiflink_codstare1 ON planiflink USING btree (codstare1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planiflock_codgest</obj_name>
  <obj_reftable>planiflock</obj_reftable>
  <obj_hashval>2ec28b8b9b88546ec443d757b660339e</obj_hashval>
  <obj_text>CREATE INDEX idx_planiflock_codgest ON planiflock USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planiflock_userid</obj_name>
  <obj_reftable>planiflock</obj_reftable>
  <obj_hashval>b9678bda61f5d97f81a0526b82c01abc</obj_hashval>
  <obj_text>CREATE INDEX idx_planiflock_userid ON planiflock USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifnod_codobiect</obj_name>
  <obj_reftable>planifnod</obj_reftable>
  <obj_hashval>582b578b93847e94e118bc33d339167b</obj_hashval>
  <obj_text>CREATE INDEX idx_planifnod_codobiect ON planifnod USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifnod_codplanifprod</obj_name>
  <obj_reftable>planifnod</obj_reftable>
  <obj_hashval>62bc65f5ca47f62b27d4567be72f58c4</obj_hashval>
  <obj_text>CREATE INDEX idx_planifnod_codplanifprod ON planifnod USING btree (codplanifprod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifnod_codplanifprod1</obj_name>
  <obj_reftable>planifnod</obj_reftable>
  <obj_hashval>076840f0053fa72266aa27b51eb9b056</obj_hashval>
  <obj_text>CREATE INDEX idx_planifnod_codplanifprod1 ON planifnod USING btree (codplanifprod1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifnod_codprodmat</obj_name>
  <obj_reftable>planifnod</obj_reftable>
  <obj_hashval>784e6dabb6a68c6673c2517981cbb0f6</obj_hashval>
  <obj_text>CREATE INDEX idx_planifnod_codprodmat ON planifnod USING btree (codprodmat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifnod_codreteta</obj_name>
  <obj_reftable>planifnod</obj_reftable>
  <obj_hashval>ef066fcec38d7489143c07e715724049</obj_hashval>
  <obj_text>CREATE INDEX idx_planifnod_codreteta ON planifnod USING btree (codreteta)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tiplucrarisa</obj_name>
  <obj_hashval>5d999fb5eabe22ae4730b4da8f0909b1</obj_hashval>
  <obj_text>CREATE TABLE tiplucrarisa (
  "codtiplucrare" numeric(20,0) NOT NULL,
  "denumire" character varying(60),
  "artservfact" numeric(20,0),
  "clasalucrari" character varying(40),
  "codgest" numeric(20,0),
  "codinterventie" numeric(20,0),
  "toti" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tiplucrarisa1</obj_name>
  <obj_hashval>f5faf413de7e61297e1037007333bacf</obj_hashval>
  <obj_text>CREATE TABLE tiplucrarisa1 (
  "codtiplucrare1" numeric(20,0) NOT NULL,
  "codtiplucrare" numeric(20,0),
  "codpers" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tippartincert</obj_name>
  <obj_hashval>0089b58e7d372c6f415b1cd6d6b85764</obj_hashval>
  <obj_text>CREATE TABLE tippartincert (
  "codtippartincert" numeric(20,0),
  "tipclient" character varying(50),
  "tipimpozitare" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifnod_nodoriginal</obj_name>
  <obj_reftable>planifnod</obj_reftable>
  <obj_hashval>d212e841f553272830f74427f96edcbe</obj_hashval>
  <obj_text>CREATE INDEX idx_planifnod_nodoriginal ON planifnod USING btree (nodoriginal)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifnod_tip</obj_name>
  <obj_reftable>planifnod</obj_reftable>
  <obj_hashval>27818aad9b366fa2081bf5aa2f6113fc</obj_hashval>
  <obj_text>CREATE INDEX idx_planifnod_tip ON planifnod USING btree (tip)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tipuriplati</obj_name>
  <obj_hashval>70bd3e6302e1821f7a2a88cc9f7541b9</obj_hashval>
  <obj_text>CREATE TABLE tipuriplati (
  "codtipplata" numeric(20,0) NOT NULL,
  "tipcasa" numeric(5,0),
  "tipplata" numeric(5,0),
  "denplata" character varying(30),
  "invizibil" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_cfgactions_tmp</obj_name>
  <obj_hashval>2d893605fb57062d64f9aba7522195e0</obj_hashval>
  <obj_text>CREATE TABLE tmp_cfgactions_tmp (
  "codcfgactions" numeric(20,0),
  "tipdoc" numeric(5,0),
  "tipsql" numeric(1,0),
  "tip" numeric(1,0),
  "id" numeric(5,0),
  "sqlite" text,
  "mesaj" character varying(150)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifprod_anluna</obj_name>
  <obj_reftable>planifprod</obj_reftable>
  <obj_hashval>3a21d476b7bc4f2590451ba933d42809</obj_hashval>
  <obj_text>CREATE INDEX idx_planifprod_anluna ON planifprod USING btree ((((an * (12)::numeric) + luna)))</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifprod_anulat</obj_name>
  <obj_reftable>planifprod</obj_reftable>
  <obj_hashval>f52d35ef07cfbcb8e2447f47bface822</obj_hashval>
  <obj_text>CREATE INDEX idx_planifprod_anulat ON planifprod USING btree (anulat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifprod_codlansprod</obj_name>
  <obj_reftable>planifprod</obj_reftable>
  <obj_hashval>943f676ef652523bede0d05a06435c9f</obj_hashval>
  <obj_text>CREATE INDEX idx_planifprod_codlansprod ON planifprod USING btree (codlansprod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifprod_nrdoc</obj_name>
  <obj_reftable>planifprod</obj_reftable>
  <obj_hashval>409c4350fe75940e6a7bac8061765a05</obj_hashval>
  <obj_text>CREATE INDEX idx_planifprod_nrdoc ON planifprod USING btree (nrdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifprod_operat</obj_name>
  <obj_reftable>planifprod</obj_reftable>
  <obj_hashval>d2fbee9b849367e34e44a34856c7ebdb</obj_hashval>
  <obj_text>CREATE INDEX idx_planifprod_operat ON planifprod USING btree (operat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifprod_saptamana</obj_name>
  <obj_reftable>planifprod</obj_reftable>
  <obj_hashval>dc25a186baf862495d28bb6d5c31767c</obj_hashval>
  <obj_text>CREATE INDEX idx_planifprod_saptamana ON planifprod USING btree (saptamana)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifprod_seriadoc</obj_name>
  <obj_reftable>planifprod</obj_reftable>
  <obj_hashval>40fde53d52c46129ca97dc46c49cf474</obj_hashval>
  <obj_text>CREATE INDEX idx_planifprod_seriadoc ON planifprod USING btree (seriadoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifprod_subunitatea</obj_name>
  <obj_reftable>planifprod</obj_reftable>
  <obj_hashval>cf00d1a03a00c7f07ade3d197fda63ec</obj_hashval>
  <obj_text>CREATE INDEX idx_planifprod_subunitatea ON planifprod USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifprod1_codlansprod1</obj_name>
  <obj_reftable>planifprod1</obj_reftable>
  <obj_hashval>650ac23d4e09a94ee1bd45653ded4781</obj_hashval>
  <obj_text>CREATE INDEX idx_planifprod1_codlansprod1 ON planifprod1 USING btree (codlansprod1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifprod1_codobiect</obj_name>
  <obj_reftable>planifprod1</obj_reftable>
  <obj_hashval>455cf91830187cea76c8159983bca5e9</obj_hashval>
  <obj_text>CREATE INDEX idx_planifprod1_codobiect ON planifprod1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifprod1_codplanifprod</obj_name>
  <obj_reftable>planifprod1</obj_reftable>
  <obj_hashval>4636207854a841f8d947d73968fc2277</obj_hashval>
  <obj_text>CREATE INDEX idx_planifprod1_codplanifprod ON planifprod1 USING btree (codplanifprod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifprod1_codproiect</obj_name>
  <obj_reftable>planifprod1</obj_reftable>
  <obj_hashval>a1e58dbb80153b439ea9fa893bcd1124</obj_hashval>
  <obj_text>CREATE INDEX idx_planifprod1_codproiect ON planifprod1 USING btree (codproiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifprod1_codreteta</obj_name>
  <obj_reftable>planifprod1</obj_reftable>
  <obj_hashval>ed81d66412e87d8291fead22226a293e</obj_hashval>
  <obj_text>CREATE INDEX idx_planifprod1_codreteta ON planifprod1 USING btree (codreteta)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifprod1_cuproiect</obj_name>
  <obj_reftable>planifprod1</obj_reftable>
  <obj_hashval>a9134b575c73ea72a0b0073500211e09</obj_hashval>
  <obj_text>CREATE INDEX idx_planifprod1_cuproiect ON planifprod1 USING btree (cuproiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifprodlun_anluna</obj_name>
  <obj_reftable>planifprodlun</obj_reftable>
  <obj_hashval>92b5cab35ef090acc70a2f587ff56301</obj_hashval>
  <obj_text>CREATE INDEX idx_planifprodlun_anluna ON planifprodlun USING btree (anluna)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifprodlun_codgest</obj_name>
  <obj_reftable>planifprodlun</obj_reftable>
  <obj_hashval>dfe625d0b733c831182950dbfa12be5c</obj_hashval>
  <obj_text>CREATE INDEX idx_planifprodlun_codgest ON planifprodlun USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_planifprodlun_codobiect</obj_name>
  <obj_reftable>planifprodlun</obj_reftable>
  <obj_hashval>b26d8a78fdfe5974f0672924b2facf63</obj_hashval>
  <obj_text>CREATE INDEX idx_planifprodlun_codobiect ON planifprodlun USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_plati1_codobligpif</obj_name>
  <obj_reftable>plati1</obj_reftable>
  <obj_hashval>15fd32ef9ae3355e133f4f44e21a4291</obj_hashval>
  <obj_text>CREATE INDEX idx_plati1_codobligpif ON plati1 USING btree (codobligpif)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_plati1_codplata</obj_name>
  <obj_reftable>plati1</obj_reftable>
  <obj_hashval>ca315d9864d13dc818ddc89e9fa9eb4e</obj_hashval>
  <obj_text>CREATE INDEX idx_plati1_codplata ON plati1 USING btree (codplata)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_plati1_stinsa</obj_name>
  <obj_reftable>plati1</obj_reftable>
  <obj_hashval>961ca9a2b908ca974da383e734ca694a</obj_hashval>
  <obj_text>CREATE INDEX idx_plati1_stinsa ON plati1 USING btree (stinsa)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_plati2_codplata</obj_name>
  <obj_reftable>plati2</obj_reftable>
  <obj_hashval>ba6c17e38300c9ecc687592346c57b11</obj_hashval>
  <obj_text>CREATE INDEX idx_plati2_codplata ON plati2 USING btree (codplata)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_plstr_an</obj_name>
  <obj_reftable>planifstruct</obj_reftable>
  <obj_hashval>477f773b4ab449ef8aba668b7783958e</obj_hashval>
  <obj_text>CREATE INDEX idx_plstr_an ON planifstruct USING btree (an)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_plstr_codobiect</obj_name>
  <obj_reftable>planifstruct</obj_reftable>
  <obj_hashval>d355314681b94fdb946162d56f5f7ad6</obj_hashval>
  <obj_text>CREATE INDEX idx_plstr_codobiect ON planifstruct USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_plstr_codreteta</obj_name>
  <obj_reftable>planifstruct</obj_reftable>
  <obj_hashval>31a70ba6361464f972b4857e21e7816b</obj_hashval>
  <obj_text>CREATE INDEX idx_plstr_codreteta ON planifstruct USING btree (codreteta)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_plstr_saptamana</obj_name>
  <obj_reftable>planifstruct</obj_reftable>
  <obj_hashval>63e7a3a83aebd2f8a5a0915fd5590459</obj_hashval>
  <obj_text>CREATE INDEX idx_plstr_saptamana ON planifstruct USING btree (saptamana)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pmpluna</obj_name>
  <obj_reftable>pmpluna</obj_reftable>
  <obj_hashval>ef8d2d39a4c1f03e49e18d5b586f89a7</obj_hashval>
  <obj_text>CREATE INDEX idx_pmpluna ON pmpluna USING btree (an, luna, codobiect, codsubunit)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_cfgtables1_tmp</obj_name>
  <obj_hashval>841d59a55ae19525e3e2d9910571fc37</obj_hashval>
  <obj_text>CREATE TABLE tmp_cfgtables1_tmp (
  "codcfgtable1" numeric(20,0),
  "codcfgtable" numeric(20,0),
  "indexlocal" numeric(6,0),
  "numecamp" character varying(20),
  "caption" character varying(30),
  "tip" character varying(1),
  "marime" numeric(6,0),
  "zecimale" numeric(6,0),
  "colwidth" numeric(6,0),
  "color" numeric(10,0),
  "obligatoriu" numeric(1,0),
  "nomlink" numeric(10,0),
  "lookupdisplay" character varying(50),
  "tipfiltruafis" numeric(2,0),
  "filtruafis" character varying(2000),
  "hastotal" numeric(1,0),
  "tmp" numeric(1,0),
  "tobeupdated" numeric(1,0),
  "sqlonchange" character varying(3000),
  "valpredef" character varying(1),
  "referinte" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_cfgtables2_tmp</obj_name>
  <obj_hashval>47ebd56bab68f5984ace89d31c15077a</obj_hashval>
  <obj_text>CREATE TABLE tmp_cfgtables2_tmp (
  "codcfgtable2" numeric(20,0),
  "codcfgtable1" numeric(20,0),
  "valoare" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_cfgtables_tmp</obj_name>
  <obj_hashval>a8ec91da12651ddb430604c20fc57284</obj_hashval>
  <obj_text>CREATE TABLE tmp_cfgtables_tmp (
  "codcfgtable" numeric(20,0),
  "numetabela" character varying(20),
  "tipconfig" numeric(1,0),
  "master" character varying(20),
  "linkkey" character varying(20),
  "tiplink" numeric(1,0),
  "descriere" character varying(100),
  "suplimsql" text
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pn_man_codobiect</obj_name>
  <obj_reftable>tmp_proiectnod_man</obj_reftable>
  <obj_hashval>ffc697333c5be610ce1c191d97b50186</obj_hashval>
  <obj_text>CREATE INDEX idx_pn_man_codobiect ON tmp_proiectnod_man USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pn_man_codproiect</obj_name>
  <obj_reftable>tmp_proiectnod_man</obj_reftable>
  <obj_hashval>2c638505c0645f0d693663108471fdf9</obj_hashval>
  <obj_text>CREATE INDEX idx_pn_man_codproiect ON tmp_proiectnod_man USING btree (codproiect)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_cmd</obj_name>
  <obj_hashval>87d0af0f4bb11544959c70fdd742122a</obj_hashval>
  <obj_text>CREATE TABLE tmp_cmd (
  "codobiect" numeric(20,0),
  "cantc" numeric(20,7),
  "canta" numeric(20,7),
  "resta" numeric(20,7),
  "tip" character varying(20),
  "userid" numeric(20,0),
  "auxfield" character varying(2500),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_cmd1</obj_name>
  <obj_hashval>ff390da9f390d109b65189a7fff14435</obj_hashval>
  <obj_text>CREATE TABLE tmp_cmd1 (
  "codobiect" numeric(20,0),
  "cantc" numeric(20,7),
  "canta" numeric(20,7),
  "resta" numeric(20,7),
  "tip" character varying(20),
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_cmd2</obj_name>
  <obj_hashval>8d2c6ef80f5eea2629c99d7f6b32c65d</obj_hashval>
  <obj_text>CREATE TABLE tmp_cmd2 (
  "codobiect" numeric(20,0),
  "cantc" numeric(20,7),
  "canta" numeric(20,7),
  "resta" numeric(20,7),
  "tip" character varying(20),
  "userid" numeric(20,0),
  "auxfield" character varying(2500)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pn_man_codproiectnod</obj_name>
  <obj_reftable>tmp_proiectnod_man</obj_reftable>
  <obj_hashval>c7937ca48f99091490d10c4bfa7faf32</obj_hashval>
  <obj_text>CREATE INDEX idx_pn_man_codproiectnod ON tmp_proiectnod_man USING btree (codproiectnod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pn_man_userid</obj_name>
  <obj_reftable>tmp_proiectnod_man</obj_reftable>
  <obj_hashval>3d614a54dc2bcc20d7d0d303ea2fafa4</obj_hashval>
  <obj_text>CREATE INDEX idx_pn_man_userid ON tmp_proiectnod_man USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pnodztl_codobiect</obj_name>
  <obj_reftable>tmp_planifnodztl</obj_reftable>
  <obj_hashval>8ecc487d7871371002421c7ff0cd235f</obj_hashval>
  <obj_text>CREATE INDEX idx_pnodztl_codobiect ON tmp_planifnodztl USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pnodztl_codreteta</obj_name>
  <obj_reftable>tmp_planifnodztl</obj_reftable>
  <obj_hashval>652a7fe8f377fa6282f911a41c23807c</obj_hashval>
  <obj_text>CREATE INDEX idx_pnodztl_codreteta ON tmp_planifnodztl USING btree (codreteta)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pnodztl_userid</obj_name>
  <obj_reftable>tmp_planifnodztl</obj_reftable>
  <obj_hashval>41759d35f205ff83819a322447c91de3</obj_hashval>
  <obj_text>CREATE INDEX idx_pnodztl_userid ON tmp_planifnodztl USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_posbancar_userid</obj_name>
  <obj_reftable>posbancar</obj_reftable>
  <obj_hashval>e298c5c525057e5bfc91e190ee6ec805</obj_hashval>
  <obj_text>CREATE INDEX idx_posbancar_userid ON posbancar USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_cmd_pluna</obj_name>
  <obj_hashval>15253a79c3c09d89e682a7d937421df6</obj_hashval>
  <obj_text>CREATE TABLE tmp_cmd_pluna (
  "codcomanda1" numeric(20,0),
  "cant1" numeric(20,7),
  "cant2" numeric(20,7),
  "cant3" numeric(20,7),
  "cant4" numeric(20,7),
  "termen" date,
  "week" numeric(2,0),
  "codprogramf1" numeric(20,0),
  "userid" numeric(20,0),
  "tip" numeric(5,0),
  "codobiect" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pplink_codcomanda1</obj_name>
  <obj_reftable>pplink</obj_reftable>
  <obj_hashval>64d2c4064fd3650ae85f18d23e1126ec</obj_hashval>
  <obj_text>CREATE INDEX idx_pplink_codcomanda1 ON pplink USING btree (codcomanda1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pplink_codintr1</obj_name>
  <obj_reftable>pplink</obj_reftable>
  <obj_hashval>c23f7f9313986ea6d457814da3cf3eb8</obj_hashval>
  <obj_text>CREATE INDEX idx_pplink_codintr1 ON pplink USING btree (codintr1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_precomanda_anulat</obj_name>
  <obj_reftable>precomanda</obj_reftable>
  <obj_hashval>8b1cc19f8c2550b7000f1a4e2305ed41</obj_hashval>
  <obj_text>CREATE INDEX idx_precomanda_anulat ON precomanda USING btree (anulat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_precomanda_inchisa</obj_name>
  <obj_reftable>precomanda</obj_reftable>
  <obj_hashval>03a66081c390ec392f9e1efc570ffda6</obj_hashval>
  <obj_text>CREATE INDEX idx_precomanda_inchisa ON precomanda USING btree (inchisa)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_precomanda_operat</obj_name>
  <obj_reftable>precomanda</obj_reftable>
  <obj_hashval>3548ba3c870dae950c1f34f3ce2cce58</obj_hashval>
  <obj_text>CREATE INDEX idx_precomanda_operat ON precomanda USING btree (operat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_precomanda_subunitatea</obj_name>
  <obj_reftable>precomanda</obj_reftable>
  <obj_hashval>517717257d425c8c719da4c1e787e623</obj_hashval>
  <obj_text>CREATE INDEX idx_precomanda_subunitatea ON precomanda USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_precomanda1_codobiect</obj_name>
  <obj_reftable>precomanda1</obj_reftable>
  <obj_hashval>f4091407833084ccc0d13535fe6f933c</obj_hashval>
  <obj_text>CREATE INDEX idx_precomanda1_codobiect ON precomanda1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_precomanda1_codprecomanda</obj_name>
  <obj_reftable>precomanda1</obj_reftable>
  <obj_hashval>366bdb56cd39a4744a44d02ddd49db65</obj_hashval>
  <obj_text>CREATE INDEX idx_precomanda1_codprecomanda ON precomanda1 USING btree (codprecomanda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_precomanda1_codstare1</obj_name>
  <obj_reftable>precomanda1</obj_reftable>
  <obj_hashval>bb418edc5cb9bf78666d73082beba747</obj_hashval>
  <obj_text>CREATE INDEX idx_precomanda1_codstare1 ON precomanda1 USING btree (codstare1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_precomanda1_termen</obj_name>
  <obj_reftable>precomanda1</obj_reftable>
  <obj_hashval>49d7b3a498e10450594ef39c767e46c8</obj_hashval>
  <obj_text>CREATE INDEX idx_precomanda1_termen ON precomanda1 USING btree (termen)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_precomanda1_umsec</obj_name>
  <obj_reftable>precomanda1</obj_reftable>
  <obj_hashval>568f6f5ea9c17268b9d5e78120aa8efa</obj_hashval>
  <obj_text>CREATE INDEX idx_precomanda1_umsec ON precomanda1 USING btree (umsec)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pred_codobiect</obj_name>
  <obj_reftable>tmp_predari_lansprod</obj_reftable>
  <obj_hashval>5e92b6340593a05e1698c4719e8ea2c0</obj_hashval>
  <obj_text>CREATE INDEX idx_pred_codobiect ON tmp_predari_lansprod USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_predariplus_codextern</obj_name>
  <obj_reftable>predariplus</obj_reftable>
  <obj_hashval>36fdd7a66bf40e6e7940704ef3d9fc59</obj_hashval>
  <obj_text>CREATE INDEX idx_predariplus_codextern ON predariplus USING btree (codextern)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_cmd_pluna2</obj_name>
  <obj_hashval>fc2e783b1f33ccf81fa4dee4c489a7d9</obj_hashval>
  <obj_text>CREATE TABLE tmp_cmd_pluna2 (
  "codcomanda1" numeric(20,0),
  "cant1" numeric(20,7),
  "cant2" numeric(20,7),
  "cant3" numeric(20,7),
  "cant4" numeric(20,7),
  "termen" date,
  "week" numeric(2,0),
  "codprogramf1" numeric(20,0),
  "userid" numeric(20,0),
  "tip" numeric(5,0),
  "codobiect" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_cmdtl</obj_name>
  <obj_hashval>9e98bafdecc811e0b465b941d7d461d5</obj_hashval>
  <obj_text>CREATE TABLE tmp_cmdtl (
  "codobiect" numeric(20,0),
  "cantc" numeric(20,7),
  "canta" numeric(20,7),
  "resta" numeric(20,7),
  "tip" numeric(5,0),
  "userid" numeric(20,0),
  "codcmdtl" numeric(20,0) NOT NULL
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_predariplus_datadoc</obj_name>
  <obj_reftable>predariplus</obj_reftable>
  <obj_hashval>b1a65651935937895cbae4cad9970df7</obj_hashval>
  <obj_text>CREATE INDEX idx_predariplus_datadoc ON predariplus USING btree (datadoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_predariplus_datamodif</obj_name>
  <obj_reftable>predariplus</obj_reftable>
  <obj_hashval>2ceda7b96ad2f42070c53768d687d97d</obj_hashval>
  <obj_text>CREATE INDEX idx_predariplus_datamodif ON predariplus USING btree (datamodif)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_predariplus_nrcmd</obj_name>
  <obj_reftable>predariplus</obj_reftable>
  <obj_hashval>75f2eb64b6b1217f97f29b21cc2f8223</obj_hashval>
  <obj_text>CREATE INDEX idx_predariplus_nrcmd ON predariplus USING btree (nrcmd)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_predariplus_sectie</obj_name>
  <obj_reftable>predariplus</obj_reftable>
  <obj_hashval>3d9711fe96629d31a5fbc41979fe6447</obj_hashval>
  <obj_text>CREATE INDEX idx_predariplus_sectie ON predariplus USING btree (sectie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_predariplus_useridblocaj</obj_name>
  <obj_reftable>predariplus</obj_reftable>
  <obj_hashval>441dd98421d2bf4d99794ad60d66174f</obj_hashval>
  <obj_text>CREATE INDEX idx_predariplus_useridblocaj ON predariplus USING btree (useridblocaj)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pretm_codcatpret</obj_name>
  <obj_reftable>pretm</obj_reftable>
  <obj_hashval>27a7231df97720a9cb5486504bc031e4</obj_hashval>
  <obj_text>CREATE INDEX idx_pretm_codcatpret ON pretm USING btree (codcatpret)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pretm_codobiect</obj_name>
  <obj_reftable>pretm</obj_reftable>
  <obj_hashval>e5dca2b468d334c6c734852ed26d93db</obj_hashval>
  <obj_text>CREATE INDEX idx_pretm_codobiect ON pretm USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pretm_subunitatea</obj_name>
  <obj_reftable>pretm</obj_reftable>
  <obj_hashval>47b4afcd2a33b84caf55f1ef267a9310</obj_hashval>
  <obj_text>CREATE INDEX idx_pretm_subunitatea ON pretm USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_pretmamb_codpretm</obj_name>
  <obj_reftable>pretmamb</obj_reftable>
  <obj_hashval>38471972d09660755491c97176b1c63e</obj_hashval>
  <obj_text>CREATE INDEX idx_pretmamb_codpretm ON pretmamb USING btree (codpretm)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_prodcomp_codobiect</obj_name>
  <obj_reftable>prodcomp</obj_reftable>
  <obj_hashval>bb9ae06548cbac555a7f5bb17eacf549</obj_hashval>
  <obj_text>CREATE INDEX idx_prodcomp_codobiect ON prodcomp USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_prodman_codloc</obj_name>
  <obj_reftable>prodman</obj_reftable>
  <obj_hashval>6290ed6abc5610494eaaf76726a85566</obj_hashval>
  <obj_text>CREATE INDEX idx_prodman_codloc ON prodman USING btree (codloc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_prodman_codop</obj_name>
  <obj_reftable>prodman</obj_reftable>
  <obj_hashval>e5ca778fd11afe2606ca005edf801c16</obj_hashval>
  <obj_text>CREATE INDEX idx_prodman_codop ON prodman USING btree (codop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_prodman_codprodcomp</obj_name>
  <obj_reftable>prodman</obj_reftable>
  <obj_hashval>1b5c01de2a47775c61835c1ee0c2c554</obj_hashval>
  <obj_text>CREATE INDEX idx_prodman_codprodcomp ON prodman USING btree (codprodcomp)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_prodman_codprodgest</obj_name>
  <obj_reftable>prodman</obj_reftable>
  <obj_hashval>4a440b3f97628de501bba4f348f3d01c</obj_hashval>
  <obj_text>CREATE INDEX idx_prodman_codprodgest ON prodman USING btree (codprodgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_prodman_codtarif</obj_name>
  <obj_reftable>prodman</obj_reftable>
  <obj_hashval>521812cc3e2a430614ac70621bfed3ed</obj_hashval>
  <obj_text>CREATE INDEX idx_prodman_codtarif ON prodman USING btree (codtarif)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_prodmat_codatribut</obj_name>
  <obj_reftable>prodmat</obj_reftable>
  <obj_hashval>190700ed12702498c6c7d1b0ce720d60</obj_hashval>
  <obj_text>CREATE INDEX idx_prodmat_codatribut ON prodmat USING btree (codatribut)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_prodmat_codobiect</obj_name>
  <obj_reftable>prodmat</obj_reftable>
  <obj_hashval>4025a52b11e48a97272edfc6e13e72c2</obj_hashval>
  <obj_text>CREATE INDEX idx_prodmat_codobiect ON prodmat USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_prodmat_codprodcomp</obj_name>
  <obj_reftable>prodmat</obj_reftable>
  <obj_hashval>15e492cf5936a6eef1fb55df3959f216</obj_hashval>
  <obj_text>CREATE INDEX idx_prodmat_codprodcomp ON prodmat USING btree (codprodcomp)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_prodmat_codprodgest</obj_name>
  <obj_reftable>prodmat</obj_reftable>
  <obj_hashval>b87c08c95953ede309c76ca601925c49</obj_hashval>
  <obj_text>CREATE INDEX idx_prodmat_codprodgest ON prodmat USING btree (codprodgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_prodmatechiv_codmat</obj_name>
  <obj_reftable>prodmatechiv</obj_reftable>
  <obj_hashval>8ad498a826ee912c8850a3b91208391a</obj_hashval>
  <obj_text>CREATE INDEX idx_prodmatechiv_codmat ON prodmatechiv USING btree (codmat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_prodmatechiv_codobiect</obj_name>
  <obj_reftable>prodmatechiv</obj_reftable>
  <obj_hashval>d7fea775fdd4862d291b3b6e3c63cf18</obj_hashval>
  <obj_text>CREATE INDEX idx_prodmatechiv_codobiect ON prodmatechiv USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_prodmatechiv_codprodcomp</obj_name>
  <obj_reftable>prodmatechiv</obj_reftable>
  <obj_hashval>859b887699059205b8976828073496d6</obj_hashval>
  <obj_text>CREATE INDEX idx_prodmatechiv_codprodcomp ON prodmatechiv USING btree (codprodcomp)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_prodnorme_codprodcomp</obj_name>
  <obj_reftable>prodnorme</obj_reftable>
  <obj_hashval>3c9d63257e7c17660d07dcf19a8c6e9c</obj_hashval>
  <obj_text>CREATE INDEX idx_prodnorme_codprodcomp ON prodnorme USING btree (codprodcomp)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_prodnorme_implicit</obj_name>
  <obj_reftable>prodnorme</obj_reftable>
  <obj_hashval>400b187cee388f8a2a69300b04db32ec</obj_hashval>
  <obj_text>CREATE INDEX idx_prodnorme_implicit ON prodnorme USING btree (implicit)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_prodsdv_codprodcomp</obj_name>
  <obj_reftable>prodsdv</obj_reftable>
  <obj_hashval>2428cd4610e1aa54678e0db1eb0e4213</obj_hashval>
  <obj_text>CREATE INDEX idx_prodsdv_codprodcomp ON prodsdv USING btree (codprodcomp)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_programf1_codcomanda1</obj_name>
  <obj_reftable>programf1</obj_reftable>
  <obj_hashval>7567950396574b811d2029e69c89f754</obj_hashval>
  <obj_text>CREATE INDEX idx_programf1_codcomanda1 ON programf1 USING btree (codcomanda1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_programf1_codgest</obj_name>
  <obj_reftable>programf1</obj_reftable>
  <obj_hashval>947703f8b71e5ea7341ff57881665fe0</obj_hashval>
  <obj_text>CREATE INDEX idx_programf1_codgest ON programf1 USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_programf1_codprogramf</obj_name>
  <obj_reftable>programf1</obj_reftable>
  <obj_hashval>0bbc1620af24c9106441524edd2097f3</obj_hashval>
  <obj_text>CREATE INDEX idx_programf1_codprogramf ON programf1 USING btree (codprogramf)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_programfsdv_codgest</obj_name>
  <obj_reftable>programfsdv</obj_reftable>
  <obj_hashval>f9f9764a2bd5767e03cd33f78a3dc1f2</obj_hashval>
  <obj_text>CREATE INDEX idx_programfsdv_codgest ON programfsdv USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_programfsdv_codobiect</obj_name>
  <obj_reftable>programfsdv</obj_reftable>
  <obj_hashval>3c3aa0b71de616daa56fbec0e8117424</obj_hashval>
  <obj_text>CREATE INDEX idx_programfsdv_codobiect ON programfsdv USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_proiectnod_codobiect</obj_name>
  <obj_reftable>proiectnod</obj_reftable>
  <obj_hashval>e7ede011fe07886b085b519232b275a8</obj_hashval>
  <obj_text>CREATE INDEX idx_proiectnod_codobiect ON proiectnod USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_proiectnod_codproiect</obj_name>
  <obj_reftable>proiectnod</obj_reftable>
  <obj_hashval>3a3a95478c3f584881084feea74fb32f</obj_hashval>
  <obj_text>CREATE INDEX idx_proiectnod_codproiect ON proiectnod USING btree (codproiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_promo_locatie</obj_name>
  <obj_reftable>promo</obj_reftable>
  <obj_hashval>f305a0a5d7a1b37c2c0fa5f2087c1364</obj_hashval>
  <obj_text>CREATE INDEX idx_promo_locatie ON promo USING btree (codlocatie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_promo_partener</obj_name>
  <obj_reftable>promo</obj_reftable>
  <obj_hashval>bd8ab5f000b37ac810f3e17f52c72e85</obj_hashval>
  <obj_text>CREATE INDEX idx_promo_partener ON promo USING btree (partener)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_promo_subunitatea</obj_name>
  <obj_reftable>promo</obj_reftable>
  <obj_hashval>79a32d08c5f001035604a20526850838</obj_hashval>
  <obj_text>CREATE INDEX idx_promo_subunitatea ON promo USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_promopart_clasap</obj_name>
  <obj_reftable>promopart</obj_reftable>
  <obj_hashval>aa47afea14b659dc8945890b1c3054e1</obj_hashval>
  <obj_text>CREATE INDEX idx_promopart_clasap ON promopart USING btree (codclasep)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_promopart_locatie</obj_name>
  <obj_reftable>promopart</obj_reftable>
  <obj_hashval>1f3fe1c16d557afd447226f4025a5b3e</obj_hashval>
  <obj_text>CREATE INDEX idx_promopart_locatie ON promopart USING btree (codlocatie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_promopart_partener</obj_name>
  <obj_reftable>promopart</obj_reftable>
  <obj_hashval>fd100a8347bf80812f3a53636a6ecd7a</obj_hashval>
  <obj_text>CREATE INDEX idx_promopart_partener ON promopart USING btree (partener)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_promosub_subunitatea</obj_name>
  <obj_reftable>promosub</obj_reftable>
  <obj_hashval>8ae003acaeb74d858cdc47b372676944</obj_hashval>
  <obj_text>CREATE INDEX idx_promosub_subunitatea ON promosub USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_raportp_subunitatea</obj_name>
  <obj_reftable>raportp</obj_reftable>
  <obj_hashval>a90107faaf572fa5637649de26ea61f5</obj_hashval>
  <obj_text>CREATE INDEX idx_raportp_subunitatea ON raportp USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_raportp1_codraportp</obj_name>
  <obj_reftable>raportp1</obj_reftable>
  <obj_hashval>5ad2939914ab7800503a50d039ae04b6</obj_hashval>
  <obj_text>CREATE INDEX idx_raportp1_codraportp ON raportp1 USING btree (codraportp)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_raportp2_codraportp1</obj_name>
  <obj_reftable>raportp2</obj_reftable>
  <obj_hashval>a70f3f7a06c6c37ea2855b8c46190aec</obj_hashval>
  <obj_text>CREATE INDEX idx_raportp2_codraportp1 ON raportp2 USING btree (codraportp1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_regoss1_codregoss</obj_name>
  <obj_reftable>regoss1</obj_reftable>
  <obj_hashval>92d652a25d166e00bc753afe35e31c00</obj_hashval>
  <obj_text>CREATE INDEX idx_regoss1_codregoss ON regoss1 USING btree (codregoss)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_regpers1_codreg</obj_name>
  <obj_reftable>regpers1</obj_reftable>
  <obj_hashval>396b72c5f06f377619e2f94cc09b2f92</obj_hashval>
  <obj_text>CREATE INDEX idx_regpers1_codreg ON regpers1 USING btree (codreg)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_regtrezor1_codreg</obj_name>
  <obj_reftable>regtrezor1</obj_reftable>
  <obj_hashval>3df3c356d0dee364848f39e69088f1bc</obj_hashval>
  <obj_text>CREATE INDEX idx_regtrezor1_codreg ON regtrezor1 USING btree (codreg)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_restartinactive_codobiect</obj_name>
  <obj_reftable>restartinactive</obj_reftable>
  <obj_hashval>474b30c0f2a3189a2b70f37c0786a68b</obj_hashval>
  <obj_text>CREATE INDEX idx_restartinactive_codobiect ON restartinactive USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_restartinactive_codrest</obj_name>
  <obj_reftable>restartinactive</obj_reftable>
  <obj_hashval>06fca7604494c21ac864fda4cf08d7c4</obj_hashval>
  <obj_text>CREATE INDEX idx_restartinactive_codrest ON restartinactive USING btree (codrestaurant)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_returo_sessionid</obj_name>
  <obj_reftable>returo</obj_reftable>
  <obj_hashval>f0d7c09fa2595f5c05f413948a37a079</obj_hashval>
  <obj_text>CREATE INDEX idx_returo_sessionid ON returo USING btree (sessionid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_returo_voucherbarcode</obj_name>
  <obj_reftable>returo</obj_reftable>
  <obj_hashval>9529899fd9f97918db11617ee8f4d37e</obj_hashval>
  <obj_text>CREATE INDEX idx_returo_voucherbarcode ON returo USING btree (voucherbarcode)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_returostins_codreturo</obj_name>
  <obj_reftable>returostins</obj_reftable>
  <obj_hashval>5a88b8cc6a65a9a3f17d8e5b3cec8b7b</obj_hashval>
  <obj_text>CREATE INDEX idx_returostins_codreturo ON returostins USING btree (codreturo)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_returostins_tipdoccoddoc</obj_name>
  <obj_reftable>returostins</obj_reftable>
  <obj_hashval>78a0b5aae26e18c3a131b447af079222</obj_hashval>
  <obj_text>CREATE INDEX idx_returostins_tipdoccoddoc ON returostins USING btree (tipdoc, coddoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_rezervats_codcmdprodmat</obj_name>
  <obj_reftable>rezervats</obj_reftable>
  <obj_hashval>92471cf25a87d7b6a059faf860900a37</obj_hashval>
  <obj_text>CREATE INDEX idx_rezervats_codcmdprodmat ON rezervats USING btree (codcmdprodmat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_rezervats_codcomanda1</obj_name>
  <obj_reftable>rezervats</obj_reftable>
  <obj_hashval>fe19ef360f7a9da25bc54b2d9d7cc61e</obj_hashval>
  <obj_text>CREATE INDEX idx_rezervats_codcomanda1 ON rezervats USING btree (codcomanda1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_rezervats_codcomanda1f</obj_name>
  <obj_reftable>rezervats</obj_reftable>
  <obj_hashval>4de949fb827078770743d6a90c6e2f45</obj_hashval>
  <obj_text>CREATE INDEX idx_rezervats_codcomanda1f ON rezervats USING btree (codcomanda1f)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_rezervats_codinventar1</obj_name>
  <obj_reftable>rezervats</obj_reftable>
  <obj_hashval>193823c02da6b2c0c09f31833d39b082</obj_hashval>
  <obj_text>CREATE INDEX idx_rezervats_codinventar1 ON rezervats USING btree (codinventar1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_rezervats_codnirser</obj_name>
  <obj_reftable>rezervats</obj_reftable>
  <obj_hashval>acfb50fcd06ba48ea2bfb2b4bbd10a24</obj_hashval>
  <obj_text>CREATE INDEX idx_rezervats_codnirser ON rezervats USING btree (codnirser)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_rezervats_codnirstoc</obj_name>
  <obj_reftable>rezervats</obj_reftable>
  <obj_hashval>9d19d9241cb7397e7add191c92ee319d</obj_hashval>
  <obj_text>CREATE INDEX idx_rezervats_codnirstoc ON rezervats USING btree (codnirstoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_rezervats_codobiect</obj_name>
  <obj_reftable>rezervats</obj_reftable>
  <obj_hashval>d69ef8b089efd115c2ed20ab4fc722a1</obj_hashval>
  <obj_text>CREATE INDEX idx_rezervats_codobiect ON rezervats USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_rezervats_umsec</obj_name>
  <obj_reftable>rezervats</obj_reftable>
  <obj_hashval>a3080d8527bfbad54357d5394d571618</obj_hashval>
  <obj_text>CREATE INDEX idx_rezervats_umsec ON rezervats USING btree (umsec)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_rf_ctc_auxcod</obj_name>
  <obj_reftable>rf_ctc_auxcod</obj_reftable>
  <obj_hashval>53e092bc7209bda6b1b22170cf9c3b98</obj_hashval>
  <obj_text>CREATE INDEX idx_rf_ctc_auxcod ON rf_ctc_auxcod USING btree (cod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_dedgen0_coddedgen</obj_name>
  <obj_reftable>sal_dedgen0</obj_reftable>
  <obj_hashval>08bb908f6b989f1d0bb592a85a5f1860</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_dedgen0_coddedgen ON sal_dedgen0 USING btree (coddedgen)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_dedgen1_coddedgen</obj_name>
  <obj_reftable>sal_dedgen1</obj_reftable>
  <obj_hashval>d4b69baf35dabef3baf38d1dba5f6247</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_dedgen1_coddedgen ON sal_dedgen1 USING btree (coddedgen)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_dedgen1_coddedgen0</obj_name>
  <obj_reftable>sal_dedgen1</obj_reftable>
  <obj_hashval>c2f2bccd9b8a55defb130267621edc8c</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_dedgen1_coddedgen0 ON sal_dedgen1 USING btree (coddedgen0)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_impoz0_codimpoz</obj_name>
  <obj_reftable>sal_impoz0</obj_reftable>
  <obj_hashval>5106cd6020e1c3bfd8b84f5b35097964</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_impoz0_codimpoz ON sal_impoz0 USING btree (codimpoz)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_impoz1_codimpoz</obj_name>
  <obj_reftable>sal_impoz1</obj_reftable>
  <obj_hashval>53ee695eb6f76f19dc7f804f363567e4</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_impoz1_codimpoz ON sal_impoz1 USING btree (codimpoz)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_impoz1_codimpoz0</obj_name>
  <obj_reftable>sal_impoz1</obj_reftable>
  <obj_hashval>fb456fc484ffb6877c3caf5cfc6ccef3</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_impoz1_codimpoz0 ON sal_impoz1 USING btree (codimpoz0)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_gennp_cmd1</obj_name>
  <obj_hashval>5dde6b7a82c6fe0c015642cf99bd5300</obj_hashval>
  <obj_text>CREATE TABLE tmp_gennp_cmd1 (
  "codprogramf1" numeric(20,0),
  "codcomanda1" numeric(20,0),
  "codobiect" numeric(20,0),
  "prioritate" numeric(20,0),
  "codgest" numeric(20,0),
  "codpers" numeric(20,0),
  "codformatie" numeric(20,0),
  "schimb" numeric(10,0),
  "termen" date,
  "cant" numeric(20,7),
  "userid" numeric(20,0),
  "rebut" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_gennp_cmdman</obj_name>
  <obj_hashval>3f411910fd9f7e26f5f440f8e962e677</obj_hashval>
  <obj_text>CREATE TABLE tmp_gennp_cmdman (
  "codcmdprodman" numeric(20,0),
  "cant" numeric(20,7),
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_gennp_crs</obj_name>
  <obj_hashval>96aa2a5e0682ce5085701d2a1a695be9</obj_hashval>
  <obj_text>CREATE TABLE tmp_gennp_crs (
  "codcmdprodmat" numeric(20,0),
  "codprogramf1" numeric(20,0),
  "cant" numeric(20,7),
  "userid" numeric(20,0),
  "tip" numeric(10,0),
  "codobiect" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_lipsa_coresp_planp</obj_name>
  <obj_hashval>ebf239bab9655495f9946b775f3b7076</obj_hashval>
  <obj_text>CREATE TABLE tmp_lipsa_coresp_planp (
  "simbol" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_locurimuncaobs</obj_name>
  <obj_hashval>de440b3b973c862810a06b34901bdbf3</obj_hashval>
  <obj_text>CREATE TABLE tmp_locurimuncaobs (
  "idobs" numeric(20,0),
  "codprogramf1" numeric(20,0),
  "codlocmunca" numeric(20,0),
  "obs" character varying(3000)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_intrerup_simbol</obj_name>
  <obj_reftable>sal_intrerup</obj_reftable>
  <obj_hashval>25db6b63a932079e6b580d98d932f5d9</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_intrerup_simbol ON sal_intrerup USING btree (simbol)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_nasig_cod</obj_name>
  <obj_reftable>sal_nasig</obj_reftable>
  <obj_hashval>2a5f3fc5983206bc7886d83472d2d25b</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_nasig_cod ON sal_nasig USING btree (codasig)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_nasig_tip</obj_name>
  <obj_reftable>sal_nasig</obj_reftable>
  <obj_hashval>a06c1e28b3264b6a2c2f77620c83cd7a</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_nasig_tip ON sal_nasig USING btree (tip)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_nasig0_zpf</obj_name>
  <obj_reftable>sal_nasig0</obj_reftable>
  <obj_hashval>691b4042b6ddb20cc909500e8fecd3ef</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_nasig0_zpf ON sal_nasig0 USING btree (zileplatafirma)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_nasig1_cod0</obj_name>
  <obj_reftable>sal_nasig1</obj_reftable>
  <obj_hashval>854b259ca03258f83c63b13a2de7b3be</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_nasig1_cod0 ON sal_nasig1 USING btree (codnasig0)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_nasig2_cod0</obj_name>
  <obj_reftable>sal_nasig2</obj_reftable>
  <obj_hashval>d5487130e52d3ab943db5d15bbb6dc1f</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_nasig2_cod0 ON sal_nasig2 USING btree (codnasig0)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_nasig2_cod1</obj_name>
  <obj_reftable>sal_nasig2</obj_reftable>
  <obj_hashval>36f80b3f6f78aadff4c04939bbd7a0d4</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_nasig2_cod1 ON sal_nasig2 USING btree (codnasig1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_nasig3_cod0</obj_name>
  <obj_reftable>sal_nasig3</obj_reftable>
  <obj_hashval>1c3b1d61055a8f0d934f9d1ab8d0e4b2</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_nasig3_cod0 ON sal_nasig3 USING btree (codnasig0)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_ncontrib_denumire</obj_name>
  <obj_reftable>sal_ncontrib</obj_reftable>
  <obj_hashval>5fe368f403036a1ad5dbf81dc4e23374</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_ncontrib_denumire ON sal_ncontrib USING btree (denumire)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_ncontrib_tip</obj_name>
  <obj_reftable>sal_ncontrib</obj_reftable>
  <obj_hashval>dc70847c3889526f220b6dbb386fd3b6</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_ncontrib_tip ON sal_ncontrib USING btree (tip)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_ncontrib1_tipctr</obj_name>
  <obj_reftable>sal_ncontrib1</obj_reftable>
  <obj_hashval>3053374e427a3c85b0fff0a0e334e494</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_ncontrib1_tipctr ON sal_ncontrib1 USING btree (tipcontractual)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_ndrep_cod</obj_name>
  <obj_reftable>sal_ndrep</obj_reftable>
  <obj_hashval>f506ba17ebe285fac3cabf1c3a4ac58e</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_ndrep_cod ON sal_ndrep USING btree (tip)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_ndrep_tip</obj_name>
  <obj_reftable>sal_ndrep</obj_reftable>
  <obj_hashval>5cf644bc228db631dbafb9cc1f6ebe2a</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_ndrep_tip ON sal_ndrep USING btree (denumire)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_ndrep1_ndrep</obj_name>
  <obj_reftable>sal_ndrep1</obj_reftable>
  <obj_hashval>7a9cbcbcdb25eaac6c37d2c1b66068a2</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_ndrep1_ndrep ON sal_ndrep1 USING btree (codndrep)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_ndrep1_ndrep0</obj_name>
  <obj_reftable>sal_ndrep1</obj_reftable>
  <obj_hashval>5d822c111cb62a6f80f8888c587f5801</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_ndrep1_ndrep0 ON sal_ndrep1 USING btree (codndrep0)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_ra21_codspor</obj_name>
  <obj_reftable>sal_ra21</obj_reftable>
  <obj_hashval>32ede15d200f2e22f6755186ad6a8a1e</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_ra21_codspor ON sal_ra21 USING btree (codspor)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_ra21_denumire</obj_name>
  <obj_reftable>sal_ra21</obj_reftable>
  <obj_hashval>724a998f4fed13c91ae619ceaaabf9cd</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_ra21_denumire ON sal_ra21 USING btree (denumire)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_ra24_codtipsp</obj_name>
  <obj_reftable>sal_ra24</obj_reftable>
  <obj_hashval>b77c53db36aaefe2eb1a1084b17b5011</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_ra24_codtipsp ON sal_ra24 USING btree (codtipsp)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_ra24_denumire</obj_name>
  <obj_reftable>sal_ra24</obj_reftable>
  <obj_hashval>3a80a9df6f0f37e02a7906b23d0726cc</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_ra24_denumire ON sal_ra24 USING btree (denumire)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_retineri_denumire</obj_name>
  <obj_reftable>sal_retineri</obj_reftable>
  <obj_hashval>c4db65b54966c1735f90fa4676127d08</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_retineri_denumire ON sal_retineri USING btree (denumire)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_retineri0_codretinere</obj_name>
  <obj_reftable>sal_retineri0</obj_reftable>
  <obj_hashval>bb0d410139e9a5ea10e638903605d388</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_retineri0_codretinere ON sal_retineri0 USING btree (codretinere)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_sporuri_denumire</obj_name>
  <obj_reftable>sal_sporuri</obj_reftable>
  <obj_hashval>6cde22ab3eef150265c7a9a73f6723eb</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_sporuri_denumire ON sal_sporuri USING btree (denumire)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_sporuri0_codspor</obj_name>
  <obj_reftable>sal_sporuri0</obj_reftable>
  <obj_hashval>4a70c2b13a4d9534292d16584a156d3f</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_sporuri0_codspor ON sal_sporuri0 USING btree (codspor)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_sporuri0_tipcod</obj_name>
  <obj_reftable>sal_sporuri0</obj_reftable>
  <obj_hashval>cb6cae2774a91573e73922da64e56024</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_sporuri0_tipcod ON sal_sporuri0 USING btree (tip, codspor0)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_sporuri1_codspor</obj_name>
  <obj_reftable>sal_sporuri1</obj_reftable>
  <obj_hashval>f0226c47aacd1a767506de386c36bd95</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_sporuri1_codspor ON sal_sporuri1 USING btree (codspor)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sal_sporuri2_codspor</obj_name>
  <obj_reftable>sal_sporuri2</obj_reftable>
  <obj_hashval>5dcef50c1a4a0e8898da05e73c0b48ae</obj_hashval>
  <obj_text>CREATE INDEX idx_sal_sporuri2_codspor ON sal_sporuri2 USING btree (codspor)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_seriicmd_codcomanda</obj_name>
  <obj_reftable>seriicmd</obj_reftable>
  <obj_hashval>8018b313a8559a751df8e650f64cfcfb</obj_hashval>
  <obj_text>CREATE INDEX idx_seriicmd_codcomanda ON seriicmd USING btree (codcomanda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_seriicmd_codobiect</obj_name>
  <obj_reftable>seriicmd</obj_reftable>
  <obj_hashval>111e163795c62b9fdc87ed20ef97d340</obj_hashval>
  <obj_text>CREATE INDEX idx_seriicmd_codobiect ON seriicmd USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_seriiies_codies</obj_name>
  <obj_reftable>seriiies</obj_reftable>
  <obj_hashval>6ffcd6bb0a1ef0d9d3dad6ca27a7ad3a</obj_hashval>
  <obj_text>CREATE INDEX idx_seriiies_codies ON seriiies USING btree (codies)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_seriiies_codobiect</obj_name>
  <obj_reftable>seriiies</obj_reftable>
  <obj_hashval>adc09316dde1aaa58ea847d77701c345</obj_hashval>
  <obj_text>CREATE INDEX idx_seriiies_codobiect ON seriiies USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_seriiintr_codintr</obj_name>
  <obj_reftable>seriiintr</obj_reftable>
  <obj_hashval>a4245f88bd76628ad4f96606e4118be9</obj_hashval>
  <obj_text>CREATE INDEX idx_seriiintr_codintr ON seriiintr USING btree (codintr)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_seriiintr_codobiect</obj_name>
  <obj_reftable>seriiintr</obj_reftable>
  <obj_hashval>25abcc19e077ad5b4d88642fa23d8dee</obj_hashval>
  <obj_text>CREATE INDEX idx_seriiintr_codobiect ON seriiintr USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_seriitransf_codobiect</obj_name>
  <obj_reftable>seriitransf</obj_reftable>
  <obj_hashval>89ad3b2723eaf71092a293870b7aba69</obj_hashval>
  <obj_text>CREATE INDEX idx_seriitransf_codobiect ON seriitransf USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_seriitransf_codtransf</obj_name>
  <obj_reftable>seriitransf</obj_reftable>
  <obj_hashval>b6e2d0e1b01f3e1e6bf20242cdac2493</obj_hashval>
  <obj_text>CREATE INDEX idx_seriitransf_codtransf ON seriitransf USING btree (codtransf)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_settaskobj_codtask</obj_name>
  <obj_reftable>settaskobj</obj_reftable>
  <obj_hashval>77a96f5b88943da9c69963885c4f0e91</obj_hashval>
  <obj_text>CREATE INDEX idx_settaskobj_codtask ON settaskobj USING btree (codtask)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_settaskobjasoc_codies1</obj_name>
  <obj_reftable>settaskobjasoc</obj_reftable>
  <obj_hashval>6ca308c49c4df256b71f92606ab89c11</obj_hashval>
  <obj_text>CREATE INDEX idx_settaskobjasoc_codies1 ON settaskobjasoc USING btree (codies1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_settaskobjasoc_codtask</obj_name>
  <obj_reftable>settaskobjasoc</obj_reftable>
  <obj_hashval>b38fcac29641ae7ca22468422870225f</obj_hashval>
  <obj_text>CREATE INDEX idx_settaskobjasoc_codtask ON settaskobjasoc USING btree (codtask)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sgrcolect1_codsgrcolect</obj_name>
  <obj_reftable>sgrcolect1</obj_reftable>
  <obj_hashval>cfb0f08831a6208b43a3e4ea3b176e39</obj_hashval>
  <obj_text>CREATE INDEX idx_sgrcolect1_codsgrcolect ON sgrcolect1 USING btree (codsgrcolect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sincronizat</obj_name>
  <obj_reftable>syncpretretail</obj_reftable>
  <obj_hashval>2eaa0454572293b0af4ea211ac3c1654</obj_hashval>
  <obj_text>CREATE INDEX idx_sincronizat ON syncpretretail USING btree (sincronizat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sintezaemul1_codemulare1</obj_name>
  <obj_reftable>sintezaemulare1</obj_reftable>
  <obj_hashval>c6c5af78205c13756e998c82f15689e8</obj_hashval>
  <obj_text>CREATE INDEX idx_sintezaemul1_codemulare1 ON sintezaemulare1 USING btree (codemulare1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sintezaemul1_codpostretail</obj_name>
  <obj_reftable>sintezaemulare1</obj_reftable>
  <obj_hashval>26d9336682790b9dfee790274883c6cb</obj_hashval>
  <obj_text>CREATE INDEX idx_sintezaemul1_codpostretail ON sintezaemulare1 USING btree (codpostretail)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sintezaemul1_codsinteza</obj_name>
  <obj_reftable>sintezaemulare1</obj_reftable>
  <obj_hashval>3ae592b93ef3e4e7b5879e931d25d428</obj_hashval>
  <obj_text>CREATE INDEX idx_sintezaemul1_codsinteza ON sintezaemulare1 USING btree (codsinteza)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sintezaemul2_codemulare2</obj_name>
  <obj_reftable>sintezaemulare2</obj_reftable>
  <obj_hashval>6fe7748d9875d26c952412b88016e81d</obj_hashval>
  <obj_text>CREATE INDEX idx_sintezaemul2_codemulare2 ON sintezaemulare2 USING btree (codemulare2)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sintezaemul2_codpostretail</obj_name>
  <obj_reftable>sintezaemulare2</obj_reftable>
  <obj_hashval>d788843e3cc82cd1cc9720d3002f1c6a</obj_hashval>
  <obj_text>CREATE INDEX idx_sintezaemul2_codpostretail ON sintezaemulare2 USING btree (codpostretail)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sintezaemul2_codsinteza</obj_name>
  <obj_reftable>sintezaemulare2</obj_reftable>
  <obj_hashval>ebade145cf5ca7662eb7d71089a33581</obj_hashval>
  <obj_text>CREATE INDEX idx_sintezaemul2_codsinteza ON sintezaemulare2 USING btree (codsinteza)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sintezaemulare_codemulare</obj_name>
  <obj_reftable>sintezaemulare</obj_reftable>
  <obj_hashval>ae44fb88ccccc947d7c68bf6da1cf9ac</obj_hashval>
  <obj_text>CREATE INDEX idx_sintezaemulare_codemulare ON sintezaemulare USING btree (codemulare)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sitfinalte_coloana</obj_name>
  <obj_reftable>sitfinalte</obj_reftable>
  <obj_hashval>28769b66de38294547562446e9cbcf80</obj_hashval>
  <obj_text>CREATE INDEX idx_sitfinalte_coloana ON sitfinalte USING btree (coloana)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_sitfinalte_rand</obj_name>
  <obj_reftable>sitfinalte</obj_reftable>
  <obj_hashval>0e164c9a5f0272b6415dddc8aa4c693c</obj_hashval>
  <obj_text>CREATE INDEX idx_sitfinalte_rand ON sitfinalte USING btree (rand)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_soldpart_codpart</obj_name>
  <obj_reftable>soldpart</obj_reftable>
  <obj_hashval>37b01f5f36ad2214e77d058bed2c785c</obj_hashval>
  <obj_text>CREATE INDEX idx_soldpart_codpart ON soldpart USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_soldpartluna_codpart</obj_name>
  <obj_reftable>soldpartluna</obj_reftable>
  <obj_hashval>b833616ba47a30fb0da4d4116b225025</obj_hashval>
  <obj_text>CREATE INDEX idx_soldpartluna_codpart ON soldpartluna USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_splitchelt_codobiect</obj_name>
  <obj_reftable>splitchelt</obj_reftable>
  <obj_hashval>c2b1d91ecae680ccd14b2a35c21a20ff</obj_hashval>
  <obj_text>CREATE INDEX idx_splitchelt_codobiect ON splitchelt USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_splitchelt_subunitatea</obj_name>
  <obj_reftable>splitchelt</obj_reftable>
  <obj_hashval>de974750e6b4ff385b79fc8b035830db</obj_hashval>
  <obj_text>CREATE INDEX idx_splitchelt_subunitatea ON splitchelt USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_splitchelt1_codgest</obj_name>
  <obj_reftable>splitchelt1</obj_reftable>
  <obj_hashval>a4a9025f0713af92738d215f69c39fd5</obj_hashval>
  <obj_text>CREATE INDEX idx_splitchelt1_codgest ON splitchelt1 USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_splitchelt1_codsplitchelt</obj_name>
  <obj_reftable>splitchelt1</obj_reftable>
  <obj_hashval>ce98ab0c23fe31bc97c7d93aafa8a7a9</obj_hashval>
  <obj_text>CREATE INDEX idx_splitchelt1_codsplitchelt ON splitchelt1 USING btree (codsplitchelt)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_spvarhiva_anluna</obj_name>
  <obj_reftable>spvarhiva</obj_reftable>
  <obj_hashval>cb77149e16a25f0e1ef1e62ceecfb699</obj_hashval>
  <obj_text>CREATE INDEX idx_spvarhiva_anluna ON spvarhiva USING btree (an, luna)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_spvarhiva_cif</obj_name>
  <obj_reftable>spvarhiva</obj_reftable>
  <obj_hashval>8a7ce54ff03dddc0a12276e7448e626d</obj_hashval>
  <obj_text>CREATE INDEX idx_spvarhiva_cif ON spvarhiva USING btree (cif)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_spvarhiva_dataincarcare</obj_name>
  <obj_reftable>spvarhiva</obj_reftable>
  <obj_hashval>2e070c541f28ce3b0b9f1fec28d7b65e</obj_hashval>
  <obj_text>CREATE INDEX idx_spvarhiva_dataincarcare ON spvarhiva USING btree (dataincarcare)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_spvarhiva_iddescarcare</obj_name>
  <obj_reftable>spvarhiva</obj_reftable>
  <obj_hashval>734fd194104492105a199d0573e1d31e</obj_hashval>
  <obj_text>CREATE INDEX idx_spvarhiva_iddescarcare ON spvarhiva USING btree (iddescarcare)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_lst_fisaimob</obj_name>
  <obj_hashval>0563063f77987755b9073a52432af92b</obj_hashval>
  <obj_text>CREATE TABLE tmp_lst_fisaimob (
  "codnirstoc" numeric(20,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(10,0),
  "coddocsec" numeric(20,0),
  "tipdocsec" numeric(10,0),
  "indexlocal" numeric(20,0),
  "denumire" character varying(250),
  "nrinventar" numeric(20,0),
  "den_part" character varying(250),
  "codmifix" numeric(20,0),
  "codoperatie" numeric(5,0),
  "dataoperatie" date,
  "gestsursa" numeric(20,0),
  "gestdest" numeric(20,0),
  "preti" numeric(20,7),
  "prete" numeric(20,7),
  "prefixdoc" character varying(50),
  "nrdoc" numeric(20,0),
  "cant" numeric(20,7),
  "valoare" numeric(20,7),
  "tva" numeric(20,7),
  "datadoc" date,
  "obs" character varying(400),
  "mf" numeric(1,0),
  "imbmf" numeric(1,0),
  "tipoperatie" character varying(100),
  "dirty" numeric(5,0),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "codpart" numeric(20,0),
  "codpartsec" numeric(20,0),
  "coddoc1" numeric(20,0),
  "codns" numeric(20,0),
  "codioart1" numeric(20,0),
  "codmifix1" numeric(20,0),
  "imbunatatire" numeric(20,0),
  "dataop" date,
  "ordine" numeric(5,0),
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_manevra_intr1_grupc</obj_name>
  <obj_hashval>348e1a25023bdf2cd561c5887004727c</obj_hashval>
  <obj_text>CREATE TABLE tmp_manevra_intr1_grupc (
  "codcmdprodmat" numeric(20,0),
  "cant" numeric(20,7),
  "pretconsum" numeric(20,7),
  "codnirstocconsum" numeric(20,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(10,0),
  "codobiect" numeric(20,0),
  "bc" character varying(50),
  "tiplinie" numeric(10,0),
  "cont" character varying(60),
  "codcmdprodmat_mat" numeric(20,0),
  "cant_mat" numeric(20,7),
  "cant_ret" numeric(20,7),
  "pret_ret" numeric(20,7),
  "cantk" numeric(20,7),
  "pret_contabil" numeric(20,7),
  "val_contabila" numeric(20,7),
  "gestiune" character varying(100),
  "nps" character varying(50),
  "anluna" numeric(10,0),
  "codcmdprodmat_semi" numeric(20,0),
  "codobiectorig" numeric(20,0),
  "cmds" character varying(50),
  "seriibc" character varying(2500)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_manevra_intr1_grupl</obj_name>
  <obj_hashval>077221c0c7cfca7472bd6876e691359b</obj_hashval>
  <obj_text>CREATE TABLE tmp_manevra_intr1_grupl (
  "codcmdprodmat" numeric(20,0),
  "cantpredata" numeric(20,7),
  "cantlansata" numeric(20,7),
  "cmd" character varying(50),
  "anluna" numeric(10,0),
  "pret_ret" numeric(20,7),
  "ump" character varying(15)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stareest2_codcomanda1</obj_name>
  <obj_reftable>stareestimari2</obj_reftable>
  <obj_hashval>63442911cf2dfc2eb591189a6c6c9f42</obj_hashval>
  <obj_text>CREATE INDEX idx_stareest2_codcomanda1 ON stareestimari2 USING btree (codcomanda1)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_nparc0_man</obj_name>
  <obj_hashval>b9e9defb57fbe59f44b8139321d6a0c9</obj_hashval>
  <obj_text>CREATE TABLE tmp_nparc0_man (
  "codnparc0" numeric(20,0),
  "codnparcaut" numeric(20,0),
  "databord" timestamp(0) without time zone,
  "kmbord" numeric(10,0),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "obs" character varying(150),
  "codpers" numeric(20,0),
  "codfaz" numeric(20,0),
  "codcmd" numeric(20,0),
  "comb" numeric(5,0),
  "sofer" character varying(400),
  "faz" character varying(50),
  "cmd" character varying(50),
  "datacitires" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_planifcmdmat</obj_name>
  <obj_hashval>ccb1aac57cb2e32880b47871a9215fbf</obj_hashval>
  <obj_text>CREATE TABLE tmp_planifcmdmat (
  "codobiect" numeric(20,0),
  "stoc" numeric(20,7),
  "stocmin" numeric(20,0),
  "pret" numeric(20,7),
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_planifnodztl</obj_name>
  <obj_hashval>ce47c6291f3c6fd358872abca948f89e</obj_hashval>
  <obj_text>CREATE TABLE tmp_planifnodztl (
  "codreteta" numeric(20,0),
  "codobiect" numeric(20,0),
  "necesar" numeric(20,7),
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_pluna</obj_name>
  <obj_hashval>65de5fb7c54268f4081f3a6de8a9cb75</obj_hashval>
  <obj_text>CREATE TABLE tmp_pluna (
  "codcmdpl" numeric(20,0) NOT NULL,
  "codobiect" numeric(20,0),
  "stoc" numeric(20,7),
  "mediev" numeric(20,7),
  "cantcc" numeric(20,7),
  "cantci" numeric(20,7),
  "week1" numeric(20,7),
  "week2" numeric(20,7),
  "week3" numeric(20,7),
  "week4" numeric(20,7),
  "week5" numeric(20,7),
  "pret" numeric(20,7),
  "userid" numeric(20,0),
  "restcmdint" numeric(20,7),
  "codmoneda" numeric(20,0),
  "prweek1" numeric(20,7),
  "prweek2" numeric(20,7),
  "prweek3" numeric(20,7),
  "prweek4" numeric(20,7),
  "prweek5" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_predari_lansprod</obj_name>
  <obj_hashval>4aa8170572f245910da97e56c4f3ea04</obj_hashval>
  <obj_text>CREATE TABLE tmp_predari_lansprod (
  "cant" numeric(20,7),
  "codobiect" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stareest2_codmoneda</obj_name>
  <obj_reftable>stareestimari2</obj_reftable>
  <obj_hashval>dfa8414b60261a02c88e532009b24f16</obj_hashval>
  <obj_text>CREATE INDEX idx_stareest2_codmoneda ON stareestimari2 USING btree (codmoneda)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_prodcomp_man</obj_name>
  <obj_hashval>57a1482f7cfb19399c71e4cb88a3b6b9</obj_hashval>
  <obj_text>CREATE TABLE tmp_prodcomp_man (
  "codprodcomp" numeric(20,0),
  "cant" numeric(20,7),
  "pret" numeric(20,7),
  "userid" numeric(20,0),
  "codobiect" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_proiectnod_man</obj_name>
  <obj_hashval>92bc9eddd2144eb17189ebabe8bf0296</obj_hashval>
  <obj_text>CREATE TABLE tmp_proiectnod_man (
  "codproiectnod" numeric(20,0),
  "codproiect" numeric(20,0),
  "cant" numeric(20,7),
  "codobiect" numeric(20,0),
  "necesar" numeric(20,7),
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stareest2_codobiect</obj_name>
  <obj_reftable>stareestimari2</obj_reftable>
  <obj_hashval>06f045d1e86ed05fa26c1d8f3f7b3683</obj_hashval>
  <obj_text>CREATE INDEX idx_stareest2_codobiect ON stareestimari2 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stareest2_codpart</obj_name>
  <obj_reftable>stareestimari2</obj_reftable>
  <obj_hashval>e41d21b25cb6db124bf3753013a5e433</obj_hashval>
  <obj_text>CREATE INDEX idx_stareest2_codpart ON stareestimari2 USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stareest2_codstare</obj_name>
  <obj_reftable>stareestimari2</obj_reftable>
  <obj_hashval>5a76452439ee81ba82bd18461664efa0</obj_hashval>
  <obj_text>CREATE INDEX idx_stareest2_codstare ON stareestimari2 USING btree (codstare)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stareest2_codstare1</obj_name>
  <obj_reftable>stareestimari2</obj_reftable>
  <obj_hashval>209d7bcb7efb07182869f9876ed25434</obj_hashval>
  <obj_text>CREATE INDEX idx_stareest2_codstare1 ON stareestimari2 USING btree (codstare1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stareest2_saptamana</obj_name>
  <obj_reftable>stareestimari2</obj_reftable>
  <obj_hashval>01c2cb075bb77ac84839376c3be8529e</obj_hashval>
  <obj_text>CREATE INDEX idx_stareest2_saptamana ON stareestimari2 USING btree (saptamana)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stareestimari_an</obj_name>
  <obj_reftable>stareestimari</obj_reftable>
  <obj_hashval>3d09afc1a1be3fcb10e4f0f7f9f0067a</obj_hashval>
  <obj_text>CREATE INDEX idx_stareestimari_an ON stareestimari USING btree (an)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stareestimari_ang</obj_name>
  <obj_reftable>stareestimari</obj_reftable>
  <obj_hashval>cb62755e1ccdabbcd99160d5d1482658</obj_hashval>
  <obj_text>CREATE INDEX idx_stareestimari_ang ON stareestimari USING btree (ang)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stareestimari_saptamana</obj_name>
  <obj_reftable>stareestimari</obj_reftable>
  <obj_hashval>1b4f22869daadada9d127c8aad369478</obj_hashval>
  <obj_text>CREATE INDEX idx_stareestimari_saptamana ON stareestimari USING btree (saptamana)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_stareestimari1_centr</obj_name>
  <obj_hashval>48b1f4b3f94bc5e66bcd8c42c213cf33</obj_hashval>
  <obj_text>CREATE TABLE tmp_stareestimari1_centr (
  "codstare" numeric(20,0),
  "codstare1" numeric(20,0),
  "codobiect" numeric(20,0),
  "stocmin" numeric(20,7),
  "stocini" numeric(20,7),
  "stocprec" numeric(20,7),
  "estimari" numeric(20,7),
  "cmdf" numeric(20,7),
  "necesar" numeric(20,7),
  "stocfinal" numeric(20,7),
  "pret" numeric(20,7),
  "stocval" numeric(20,7),
  "denumire" character varying(200),
  "cmdfp" numeric(20,7),
  "restprecmd" numeric(20,7),
  "indexlocal" numeric(10,0),
  "necesaracc" numeric(20,7),
  "restprecmda" numeric(20,7),
  "restnecesar" numeric(20,7),
  "cmdfts" numeric(20,7),
  "acceptatts" numeric(20,7),
  "stocdc" numeric(20,7),
  "umsec" numeric(20,0),
  "um1" numeric(20,0),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7),
  "necesarum1" numeric(20,7),
  "relatieum1" numeric(2,0),
  "den_umsec" character varying(50),
  "den_um1" character varying(50),
  "valnecesar" numeric(20,0),
  "consum" numeric(20,7),
  "an" numeric(4,0),
  "saptamana" numeric(2,0),
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_stocreal_nec5</obj_name>
  <obj_hashval>b54f6435699cf5bb7cbf8a8a60e82090</obj_hashval>
  <obj_text>CREATE TABLE tmp_stocreal_nec5 (
  "codobiect" numeric(20,0),
  "cant" numeric(20,7),
  "tip" character varying(20),
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stareestimari_saptamanag</obj_name>
  <obj_reftable>stareestimari</obj_reftable>
  <obj_hashval>5719399e2b8662fa9df43c01030f4283</obj_hashval>
  <obj_text>CREATE INDEX idx_stareestimari_saptamanag ON stareestimari USING btree (saptamanag)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stareestimari1_codobiect</obj_name>
  <obj_reftable>stareestimari1</obj_reftable>
  <obj_hashval>f47ce0bc07e2c34d27138d9c518c26b5</obj_hashval>
  <obj_text>CREATE INDEX idx_stareestimari1_codobiect ON stareestimari1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stareestimari1_codstare</obj_name>
  <obj_reftable>stareestimari1</obj_reftable>
  <obj_hashval>1d1d97be1959f685d931212c5808220e</obj_hashval>
  <obj_text>CREATE INDEX idx_stareestimari1_codstare ON stareestimari1 USING btree (codstare)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stingere_codstingatorpif</obj_name>
  <obj_reftable>stingere</obj_reftable>
  <obj_hashval>4e8645f54f02c9825e454ff6359ebb14</obj_hashval>
  <obj_text>CREATE INDEX idx_stingere_codstingatorpif ON stingere USING btree (codstingatorpif)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stingere_codstinspif</obj_name>
  <obj_reftable>stingere</obj_reftable>
  <obj_hashval>6a46ccb119187f6f14014aad5effc2e9</obj_hashval>
  <obj_text>CREATE INDEX idx_stingere_codstinspif ON stingere USING btree (codstinspif)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stocfake1_codstocfake</obj_name>
  <obj_reftable>stocfake1</obj_reftable>
  <obj_hashval>2f53a826cd0bf41d90c47a1a6ff5ec1c</obj_hashval>
  <obj_text>CREATE INDEX idx_stocfake1_codstocfake ON stocfake1 USING btree (codstocfake)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stocini_codgest</obj_name>
  <obj_reftable>stocini</obj_reftable>
  <obj_hashval>15a6c8504bc9f577d4bbb4e6b87ac72b</obj_hashval>
  <obj_text>CREATE INDEX idx_stocini_codgest ON stocini USING btree (codgest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stocmpart_codextern</obj_name>
  <obj_reftable>stocmpart</obj_reftable>
  <obj_hashval>fd08bf427625f7479020a34a07c2a086</obj_hashval>
  <obj_text>CREATE INDEX idx_stocmpart_codextern ON stocmpart USING btree (codextern)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stocmpart_codlocatie</obj_name>
  <obj_reftable>stocmpart</obj_reftable>
  <obj_hashval>1fbdc4cc9b5049f15707c58db9500db4</obj_hashval>
  <obj_text>CREATE INDEX idx_stocmpart_codlocatie ON stocmpart USING btree (codlocatie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stocnec5_codobiect</obj_name>
  <obj_reftable>tmp_stocreal_nec5</obj_reftable>
  <obj_hashval>43c4b644821bd1ad3f1540d4dcacf57b</obj_hashval>
  <obj_text>CREATE INDEX idx_stocnec5_codobiect ON tmp_stocreal_nec5 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stocnec5_tip</obj_name>
  <obj_reftable>tmp_stocreal_nec5</obj_reftable>
  <obj_hashval>881dbdbb6d1291e7a2409f0ee3a6033b</obj_hashval>
  <obj_text>CREATE INDEX idx_stocnec5_tip ON tmp_stocreal_nec5 USING btree (tip)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stocnec5_userid</obj_name>
  <obj_reftable>tmp_stocreal_nec5</obj_reftable>
  <obj_hashval>5c23e4217d400d686d9511e49113f0b8</obj_hashval>
  <obj_text>CREATE INDEX idx_stocnec5_userid ON tmp_stocreal_nec5 USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stocvalini_gest</obj_name>
  <obj_reftable>stocvalini</obj_reftable>
  <obj_hashval>b72923b99eccbdf409a38600dbc465c0</obj_hashval>
  <obj_text>CREATE INDEX idx_stocvalini_gest ON stocvalini USING btree (gest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stocvalluna</obj_name>
  <obj_reftable>stocvalluna</obj_reftable>
  <obj_hashval>c0add4e4d29834ed2c3c8088e6f6578b</obj_hashval>
  <obj_text>CREATE INDEX idx_stocvalluna ON stocvalluna USING btree (an, luna, gest, codioart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_stocvalluna_gest</obj_name>
  <obj_reftable>stocvalluna</obj_reftable>
  <obj_hashval>f1acbb5684f6d2629f94e7bc0c62a28b</obj_hashval>
  <obj_text>CREATE INDEX idx_stocvalluna_gest ON stocvalluna USING btree (gest)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_syncpartretail_codpart</obj_name>
  <obj_reftable>syncpartretail</obj_reftable>
  <obj_hashval>e44fab9e28140184111c51d4be225198</obj_hashval>
  <obj_text>CREATE INDEX idx_syncpartretail_codpart ON syncpartretail USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_stt</obj_name>
  <obj_hashval>ce9fc9cef0a176648c9ae4f6785af399</obj_hashval>
  <obj_text>CREATE TABLE tmp_stt (
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "codbankcont" numeric(20,0),
  "tipdoc" numeric(20,0),
  "coddoc" numeric(20,0),
  "coddoc1" numeric(20,0),
  "indexlocal" numeric(20,0),
  "datadoc" date,
  "carnetdoc" numeric(20,0),
  "seriedoc" character varying(20),
  "nrdoc" numeric(20,0),
  "document" character varying(100),
  "cursdoc" numeric(20,7),
  "incasari" numeric(20,7),
  "plati" numeric(20,7),
  "soldin" numeric(20,7),
  "incasarilei" numeric(20,7),
  "platilei" numeric(20,7),
  "soldinlei" numeric(20,7),
  "explicatii" character varying(500)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_sttreg</obj_name>
  <obj_hashval>ce540002b730c27c7c624f9c275fcf76</obj_hashval>
  <obj_text>CREATE TABLE tmp_sttreg (
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "codmoneda" numeric(20,0),
  "curs" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_sttsolddoc</obj_name>
  <obj_hashval>44bb31dbde866fe05451b2bb0dbf277e</obj_hashval>
  <obj_text>CREATE TABLE tmp_sttsolddoc (
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "codbankcont" numeric(20,0),
  "datadoc" date,
  "soldin" numeric(20,7),
  "soldinlei" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>totalpuncte</obj_name>
  <obj_hashval>281cbe8add9bdd49de5aa87c01ffaf63</obj_hashval>
  <obj_text>CREATE TABLE totalpuncte (
  "cod" numeric(20,0),
  "codpart" numeric(20,0),
  "codpunctaj" numeric(20,0),
  "puncte" numeric(20,0),
  "valoare" numeric(20,7),
  "codpostretail" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_syncpromo_codpostretail</obj_name>
  <obj_reftable>syncpromoretail</obj_reftable>
  <obj_hashval>362d7d731a6ce99f5dcaf41b41f0356d</obj_hashval>
  <obj_text>CREATE INDEX idx_syncpromo_codpostretail ON syncpromoretail USING btree (codpostretail)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_syncpromo_codpromo</obj_name>
  <obj_reftable>syncpromoretail</obj_reftable>
  <obj_hashval>d28c48d37b70803e2fb9660226f8d71d</obj_hashval>
  <obj_text>CREATE INDEX idx_syncpromo_codpromo ON syncpromoretail USING btree (codpromo)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_syncpromo_sincronizat</obj_name>
  <obj_reftable>syncpromoretail</obj_reftable>
  <obj_hashval>7421ae0b620a222f051505cda6720a9f</obj_hashval>
  <obj_text>CREATE INDEX idx_syncpromo_sincronizat ON syncpromoretail USING btree (sincronizat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_targetag_moneda</obj_name>
  <obj_reftable>targetag</obj_reftable>
  <obj_hashval>2c8c5c51811c4474138f8e2ed7dbc6de</obj_hashval>
  <obj_text>CREATE INDEX idx_targetag_moneda ON targetag USING btree (moneda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_targetag_subunitatea</obj_name>
  <obj_reftable>targetag</obj_reftable>
  <obj_hashval>fe330dbe866109737c9f6899ab12c535</obj_hashval>
  <obj_text>CREATE INDEX idx_targetag_subunitatea ON targetag USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_targetag_tipdoc</obj_name>
  <obj_reftable>targetag</obj_reftable>
  <obj_hashval>d0735ade1d502143fcc442f26d367108</obj_hashval>
  <obj_text>CREATE INDEX idx_targetag_tipdoc ON targetag USING btree (tipdoc)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>toword</obj_name>
  <obj_hashval>2a00d5bf8bf13f7ac78ae045fe8a1bcc</obj_hashval>
  <obj_text>CREATE TABLE toword (
  "codtoword" numeric(20,0) NOT NULL,
  "coddoc" numeric(20,0),
  "numedoc" character varying(50),
  "sqlview" character varying(200),
  "sqldate" character varying(200),
  "sqllinii" character varying(200),
  "cale" character varying(200),
  "numeview" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>transacard</obj_name>
  <obj_hashval>bbe4b0a2a806256af67bb6e215569a0d</obj_hashval>
  <obj_text>CREATE TABLE transacard (
  "codtransacard" numeric(20,0) NOT NULL,
  "codemulare" numeric(20,0),
  "valoare" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>transeini</obj_name>
  <obj_hashval>c6d4fbde87d067bffa25988a0120452f</obj_hashval>
  <obj_text>CREATE TABLE transeini (
  "codbankcont" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_targetag1_codclasa</obj_name>
  <obj_reftable>targetag1</obj_reftable>
  <obj_hashval>2a18dcd0b1a359b2a260def7d777ee5e</obj_hashval>
  <obj_text>CREATE INDEX idx_targetag1_codclasa ON targetag1 USING btree (codclasa)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>transf</obj_name>
  <obj_hashval>84d46ccf638c333f3f0703430672c37f</obj_hashval>
  <obj_text>CREATE TABLE transf (
  "codtransf" numeric(20,0) NOT NULL,
  "tipdoc" numeric(20,0),
  "anulat" numeric(20,0),
  "blocat" numeric(20,0),
  "operat" numeric(20,0),
  "prefixdoc" character varying(2),
  "carnetdoc" numeric(20,0),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "carnetae" numeric(20,0),
  "nrae" numeric(20,0),
  "valdoc" numeric(20,7),
  "tvadoc" numeric(20,7),
  "an" numeric(20,0),
  "luna" numeric(20,0),
  "valsuplim" numeric(20,7),
  "contsuplim" numeric(20,0),
  "tiprepsuplim" numeric(1,0),
  "obs" character varying(250),
  "subunitatea" numeric(20,0),
  "delegat" numeric(20,0),
  "codpart" numeric(20,0),
  "tipmodifpret" numeric(1,0),
  "storno" numeric(1,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "mijltransp" character varying(15),
  "nrtransp" character varying(30),
  "codgestcmd" numeric(20,0),
  "listat" numeric(1,0),
  "reevaluare" numeric(1,0),
  "seriadoc" character varying(20),
  "idimport" character varying(30),
  "codanaliza" numeric(20,0),
  "ajustvalstoc" numeric(1,0),
  "stadiuwms" numeric(2,0),
  "subunitdest" numeric(20,0),
  "codauto" numeric(20,0),
  "tipet" numeric(6,0),
  "is_etransp" numeric(1,0),
  "corectie" numeric(6,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_targetag1_codobiect</obj_name>
  <obj_reftable>targetag1</obj_reftable>
  <obj_hashval>fe99845451e071459650aeb05a2f31c4</obj_hashval>
  <obj_text>CREATE INDEX idx_targetag1_codobiect ON targetag1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_targetag1_codtargetag</obj_name>
  <obj_reftable>targetag1</obj_reftable>
  <obj_hashval>5e8e799315d05ad2e34a2a230aec52ec</obj_hashval>
  <obj_text>CREATE INDEX idx_targetag1_codtargetag ON targetag1 USING btree (codtargetag)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_targetag1_umsec</obj_name>
  <obj_reftable>targetag1</obj_reftable>
  <obj_hashval>139bb2d9c1f9ce517f1669fbae608a3b</obj_hashval>
  <obj_text>CREATE INDEX idx_targetag1_umsec ON targetag1 USING btree (umsec)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tarifeman1_al</obj_name>
  <obj_reftable>tarifeman1</obj_reftable>
  <obj_hashval>922824b84821ca0b4b9caad52453e3eb</obj_hashval>
  <obj_text>CREATE INDEX idx_tarifeman1_al ON tarifeman1 USING btree (codtarif, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_taxdecl</obj_name>
  <obj_reftable>taxdecl</obj_reftable>
  <obj_hashval>96059b34e2ab269f8886758568ac6fbb</obj_hashval>
  <obj_text>CREATE INDEX idx_taxdecl ON taxdecl USING btree (tipdoc, coddoc, coddoc1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_taxdecl2</obj_name>
  <obj_reftable>taxdecl</obj_reftable>
  <obj_hashval>ecd3ecf082e2f36487366938dd95faf7</obj_hashval>
  <obj_text>CREATE INDEX idx_taxdecl2 ON taxdecl USING btree (tipdoc, coddoc1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmd</obj_name>
  <obj_reftable>tmp_cmd</obj_reftable>
  <obj_hashval>b5c453d47445cc19095b6e85f4f99cdf</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmd ON tmp_cmd USING btree (userid, tip, codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmd_codobiect</obj_name>
  <obj_reftable>tmp_cmd</obj_reftable>
  <obj_hashval>fe9d48c7798ce28c39200cda2f84c684</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmd_codobiect ON tmp_cmd USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmd_duri</obj_name>
  <obj_reftable>tmp_cmd</obj_reftable>
  <obj_hashval>95411b275629d0ef9415a8ee4a79063a</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmd_duri ON tmp_cmd USING btree (d1, d2, d3)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmd_pluna_codcomanda1</obj_name>
  <obj_reftable>tmp_cmd_pluna</obj_reftable>
  <obj_hashval>3b377460e6d33f83739375b080d28027</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmd_pluna_codcomanda1 ON tmp_cmd_pluna USING btree (codcomanda1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmd_pluna_codobiect</obj_name>
  <obj_reftable>tmp_cmd_pluna</obj_reftable>
  <obj_hashval>ca54bd5d1646b15f9171180e132bbb4e</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmd_pluna_codobiect ON tmp_cmd_pluna USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmd_pluna_termen</obj_name>
  <obj_reftable>tmp_cmd_pluna</obj_reftable>
  <obj_hashval>7d6f33f41b3c145292769e8e57d18c78</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmd_pluna_termen ON tmp_cmd_pluna USING btree (termen)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmd_pluna_userid</obj_name>
  <obj_reftable>tmp_cmd_pluna</obj_reftable>
  <obj_hashval>5885eadd434f2b3b0c732bae7bf3c5b6</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmd_pluna_userid ON tmp_cmd_pluna USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmd_pluna_week</obj_name>
  <obj_reftable>tmp_cmd_pluna</obj_reftable>
  <obj_hashval>3dc007422603e08af4c4b01d6a3a5195</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmd_pluna_week ON tmp_cmd_pluna USING btree (week)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmd_pluna2_codcomanda1</obj_name>
  <obj_reftable>tmp_cmd_pluna2</obj_reftable>
  <obj_hashval>edaed9051b7c91b295761653ee4b5f6e</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmd_pluna2_codcomanda1 ON tmp_cmd_pluna2 USING btree (codcomanda1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmd_pluna2_codobiect</obj_name>
  <obj_reftable>tmp_cmd_pluna2</obj_reftable>
  <obj_hashval>7a9b4089f383fea894c95fac2de0b60d</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmd_pluna2_codobiect ON tmp_cmd_pluna2 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmd_pluna2_termen</obj_name>
  <obj_reftable>tmp_cmd_pluna2</obj_reftable>
  <obj_hashval>022c3e239d90b3f2676934b537533e30</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmd_pluna2_termen ON tmp_cmd_pluna2 USING btree (termen)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmd_pluna2_userid</obj_name>
  <obj_reftable>tmp_cmd_pluna2</obj_reftable>
  <obj_hashval>5d85635f45ec9c914d75dd8102a689a0</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmd_pluna2_userid ON tmp_cmd_pluna2 USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmd_pluna2_week</obj_name>
  <obj_reftable>tmp_cmd_pluna2</obj_reftable>
  <obj_hashval>3dbff0c1ac6b8240ccba3a55ebe4f0a7</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmd_pluna2_week ON tmp_cmd_pluna2 USING btree (week)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmd_tip</obj_name>
  <obj_reftable>tmp_cmd</obj_reftable>
  <obj_hashval>ff246b9bef98dd56e7f8c4b2d3d27ca7</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmd_tip ON tmp_cmd USING btree (tip)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmd_userid</obj_name>
  <obj_reftable>tmp_cmd</obj_reftable>
  <obj_hashval>8f9ec7f05855b68b3bbbcfe164704282</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmd_userid ON tmp_cmd USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmd1_codobiect</obj_name>
  <obj_reftable>tmp_cmd1</obj_reftable>
  <obj_hashval>53b17328edfa9fa31ed6ba5a76bfcff6</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmd1_codobiect ON tmp_cmd1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmd1_tip</obj_name>
  <obj_reftable>tmp_cmd1</obj_reftable>
  <obj_hashval>11bd5ee42bcd1eebe4af9d7af9875145</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmd1_tip ON tmp_cmd1 USING btree (tip)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmd1_userid</obj_name>
  <obj_reftable>tmp_cmd1</obj_reftable>
  <obj_hashval>3b46853ce76a6f2d095753792c7b1b71</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmd1_userid ON tmp_cmd1 USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmd2_codobiect</obj_name>
  <obj_reftable>tmp_cmd2</obj_reftable>
  <obj_hashval>829e69bfea54590b1a41576fd8b9071e</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmd2_codobiect ON tmp_cmd2 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmd2_tip</obj_name>
  <obj_reftable>tmp_cmd2</obj_reftable>
  <obj_hashval>27cde8c2ddd9375e50cc4b2b54ad0391</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmd2_tip ON tmp_cmd2 USING btree (tip)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmd2_userid</obj_name>
  <obj_reftable>tmp_cmd2</obj_reftable>
  <obj_hashval>a7f51ca20efe505d16a143092a3350f2</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmd2_userid ON tmp_cmd2 USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmdtl_codobiect</obj_name>
  <obj_reftable>tmp_cmdtl</obj_reftable>
  <obj_hashval>963d18d173d68162c62a4f3d5014a786</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmdtl_codobiect ON tmp_cmdtl USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmdtl_tip</obj_name>
  <obj_reftable>tmp_cmdtl</obj_reftable>
  <obj_hashval>b3ddc02c52c9e3f297c281141353d4ca</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmdtl_tip ON tmp_cmdtl USING btree (tip)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_cmdtl_userid</obj_name>
  <obj_reftable>tmp_cmdtl</obj_reftable>
  <obj_hashval>f8337e95a096cd37ce7e563a2e3d8860</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_cmdtl_userid ON tmp_cmdtl USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_planifcmdmat_codobiect</obj_name>
  <obj_reftable>tmp_planifcmdmat</obj_reftable>
  <obj_hashval>586974d6f50d9daeb3cf1c589b4efd13</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_planifcmdmat_codobiect ON tmp_planifcmdmat USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_planifcmdmat_userid</obj_name>
  <obj_reftable>tmp_planifcmdmat</obj_reftable>
  <obj_hashval>bf9a1497031d32363719cc3611fc33bb</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_planifcmdmat_userid ON tmp_planifcmdmat USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_pluna_codobiect</obj_name>
  <obj_reftable>tmp_pluna</obj_reftable>
  <obj_hashval>86a1371e615a4c620b33665df7b5c167</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_pluna_codobiect ON tmp_pluna USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_pluna_userid</obj_name>
  <obj_reftable>tmp_pluna</obj_reftable>
  <obj_hashval>a2db88edf833ba5ed8e5626b11a85932</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_pluna_userid ON tmp_pluna USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_se1_centr_codstare</obj_name>
  <obj_reftable>tmp_stareestimari1_centr</obj_reftable>
  <obj_hashval>676c45398e58aadc08cc681d76bc261f</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_se1_centr_codstare ON tmp_stareestimari1_centr USING btree (codstare)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_se1_centr_codstare1</obj_name>
  <obj_reftable>tmp_stareestimari1_centr</obj_reftable>
  <obj_hashval>81c3c90d925443205dc2bc6741ad3f8a</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_se1_centr_codstare1 ON tmp_stareestimari1_centr USING btree (codstare1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmp_se1_centr_userid</obj_name>
  <obj_reftable>tmp_stareestimari1_centr</obj_reftable>
  <obj_hashval>6c2a85aaebb7ce5b8184d722ee1e7859</obj_hashval>
  <obj_text>CREATE INDEX idx_tmp_se1_centr_userid ON tmp_stareestimari1_centr USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmpfisa_coddoc1</obj_name>
  <obj_reftable>tmp_lst_fisaimob</obj_reftable>
  <obj_hashval>aae1636131fbea0170fad97671861fba</obj_hashval>
  <obj_text>CREATE INDEX idx_tmpfisa_coddoc1 ON tmp_lst_fisaimob USING btree (coddoc1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmpfisa_codioart1</obj_name>
  <obj_reftable>tmp_lst_fisaimob</obj_reftable>
  <obj_hashval>7b30d24b9e89477bb4057b6f4c0472c2</obj_hashval>
  <obj_text>CREATE INDEX idx_tmpfisa_codioart1 ON tmp_lst_fisaimob USING btree (codioart1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmpfisa_codmifix</obj_name>
  <obj_reftable>tmp_lst_fisaimob</obj_reftable>
  <obj_hashval>b923f9ed1c93de318fcb6de05ae06200</obj_hashval>
  <obj_text>CREATE INDEX idx_tmpfisa_codmifix ON tmp_lst_fisaimob USING btree (codmifix)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmpfisa_codmifix1</obj_name>
  <obj_reftable>tmp_lst_fisaimob</obj_reftable>
  <obj_hashval>48d46285d0c38e2203eb0146a9162202</obj_hashval>
  <obj_text>CREATE INDEX idx_tmpfisa_codmifix1 ON tmp_lst_fisaimob USING btree (codmifix1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmpfisa_codoperatie</obj_name>
  <obj_reftable>tmp_lst_fisaimob</obj_reftable>
  <obj_hashval>3c2120ba3482f1230a660c9f420509fa</obj_hashval>
  <obj_text>CREATE INDEX idx_tmpfisa_codoperatie ON tmp_lst_fisaimob USING btree (codoperatie)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmpfisa_datadoc</obj_name>
  <obj_reftable>tmp_lst_fisaimob</obj_reftable>
  <obj_hashval>ac039e4562a88609f96c9e5ca8bc6e50</obj_hashval>
  <obj_text>CREATE INDEX idx_tmpfisa_datadoc ON tmp_lst_fisaimob USING btree (dataop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmpfisa_imbunatatire</obj_name>
  <obj_reftable>tmp_lst_fisaimob</obj_reftable>
  <obj_hashval>a72bfe55364aa48b337b4eb3a27247e5</obj_hashval>
  <obj_text>CREATE INDEX idx_tmpfisa_imbunatatire ON tmp_lst_fisaimob USING btree (imbunatatire)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmpfisa_mf</obj_name>
  <obj_reftable>tmp_lst_fisaimob</obj_reftable>
  <obj_hashval>bdc6400dc868d2c0d79d75b3a765dca4</obj_hashval>
  <obj_text>CREATE INDEX idx_tmpfisa_mf ON tmp_lst_fisaimob USING btree (mf)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmpfisa_ordine</obj_name>
  <obj_reftable>tmp_lst_fisaimob</obj_reftable>
  <obj_hashval>f720cbb9ae74932d3797f10f7352e617</obj_hashval>
  <obj_text>CREATE INDEX idx_tmpfisa_ordine ON tmp_lst_fisaimob USING btree (ordine)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tmpfisa_userid</obj_name>
  <obj_reftable>tmp_lst_fisaimob</obj_reftable>
  <obj_hashval>775c32145bd9bb0acc7a3dbddf28b0ba</obj_hashval>
  <obj_text>CREATE INDEX idx_tmpfisa_userid ON tmp_lst_fisaimob USING btree (userid)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_transacard_codemulare</obj_name>
  <obj_reftable>transacard</obj_reftable>
  <obj_hashval>d743e4917617897c714d8d1d18495295</obj_hashval>
  <obj_text>CREATE INDEX idx_transacard_codemulare ON transacard USING btree (codemulare)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_transf</obj_name>
  <obj_reftable>transf</obj_reftable>
  <obj_hashval>72c0d159c2a1c29f47be1c7d11ef1ba6</obj_hashval>
  <obj_text>CREATE INDEX idx_transf ON transf USING btree (an, luna, operat, anulat, tipdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_transf_contsuplim</obj_name>
  <obj_reftable>transf</obj_reftable>
  <obj_hashval>3abbf8e5e0ba1e8b3ddce611b6300866</obj_hashval>
  <obj_text>CREATE INDEX idx_transf_contsuplim ON transf USING btree (contsuplim)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_transf_subunitatea</obj_name>
  <obj_reftable>transf</obj_reftable>
  <obj_hashval>bcd8e19e056d7473bcc2ff05c9b6ff15</obj_hashval>
  <obj_text>CREATE INDEX idx_transf_subunitatea ON transf USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_transf1_codobiect</obj_name>
  <obj_reftable>transf1</obj_reftable>
  <obj_hashval>7fbc1490d512bb0fdf86718be1524994</obj_hashval>
  <obj_text>CREATE INDEX idx_transf1_codobiect ON transf1 USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_transf1_codtransf</obj_name>
  <obj_reftable>transf1</obj_reftable>
  <obj_hashval>dd85f830c260cd795d4ede60cae86fbf</obj_hashval>
  <obj_text>CREATE INDEX idx_transf1_codtransf ON transf1 USING btree (codtransf)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_transf1_umsec</obj_name>
  <obj_reftable>transf1</obj_reftable>
  <obj_hashval>eee2c4372d31dc70092db4b4c2e760f3</obj_hashval>
  <obj_text>CREATE INDEX idx_transf1_umsec ON transf1 USING btree (umsec)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_transflink_codliniecomanda</obj_name>
  <obj_reftable>transflink</obj_reftable>
  <obj_hashval>2579081c95eec0c294afb518b6aafd18</obj_hashval>
  <obj_text>CREATE INDEX idx_transflink_codliniecomanda ON transflink USING btree (codliniecomanda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_transflink_codtransf1</obj_name>
  <obj_reftable>transflink</obj_reftable>
  <obj_hashval>428517b1924f3de6405bf558a288ec92</obj_hashval>
  <obj_text>CREATE INDEX idx_transflink_codtransf1 ON transflink USING btree (codtransf1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_trezor_codbanca</obj_name>
  <obj_reftable>trezor</obj_reftable>
  <obj_hashval>193f5d06cfdb392fd9d97d422fdcebf4</obj_hashval>
  <obj_text>CREATE INDEX idx_trezor_codbanca ON trezor USING btree (codbanca)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_trezor_subunitatea</obj_name>
  <obj_reftable>trezor</obj_reftable>
  <obj_hashval>878d4db2e7dd854f64092e9c81dacbc0</obj_hashval>
  <obj_text>CREATE INDEX idx_trezor_subunitatea ON trezor USING btree (subunitatea)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_trezor_tipdoc</obj_name>
  <obj_reftable>trezor</obj_reftable>
  <obj_hashval>2fc843525f9e559c0a4ebfef5789020b</obj_hashval>
  <obj_text>CREATE INDEX idx_trezor_tipdoc ON trezor USING btree (tipdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_trezor1_codpart</obj_name>
  <obj_reftable>trezor1</obj_reftable>
  <obj_hashval>4ec04fe5d257a29b29fdaf8f17b20940</obj_hashval>
  <obj_text>CREATE INDEX idx_trezor1_codpart ON trezor1 USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_trezor1_codtrezor</obj_name>
  <obj_reftable>trezor1</obj_reftable>
  <obj_hashval>249cad39bba4fe117baf4b681f5623f6</obj_hashval>
  <obj_text>CREATE INDEX idx_trezor1_codtrezor ON trezor1 USING btree (codtrezor)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tvaserv1_al</obj_name>
  <obj_reftable>tvaserv1</obj_reftable>
  <obj_hashval>dd2549e9c8417743eb345e28acd41805</obj_hashval>
  <obj_text>CREATE INDEX idx_tvaserv1_al ON tvaserv1 USING btree (codtvaserv, alstart, alstop)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tvaserv1_anluna</obj_name>
  <obj_reftable>tvaserv1</obj_reftable>
  <obj_hashval>566b22f0cd3f13519dc5c148c8bf1ac3</obj_hashval>
  <obj_text>CREATE INDEX idx_tvaserv1_anluna ON tvaserv1 USING btree ((((anstart * (12)::numeric) + lunastart)))</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_tvaserv1_codcont</obj_name>
  <obj_reftable>tvaserv1</obj_reftable>
  <obj_hashval>5b6b85f143140d6bb28fa1c6fdd61f1c</obj_hashval>
  <obj_text>CREATE INDEX idx_tvaserv1_codcont ON tvaserv1 USING btree (codcont)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ut20mon_codutilaj</obj_name>
  <obj_reftable>utilaje20_mon</obj_reftable>
  <obj_hashval>6c4f072d31beabe7d84507442d096f77</obj_hashval>
  <obj_text>CREATE INDEX idx_ut20mon_codutilaj ON utilaje20_mon USING btree (codutilaj)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_ut20mon_codutilaj20</obj_name>
  <obj_reftable>utilaje20_mon</obj_reftable>
  <obj_hashval>4227ce8e721f4bc24ff44b06465f3944</obj_hashval>
  <obj_text>CREATE INDEX idx_ut20mon_codutilaj20 ON utilaje20_mon USING btree (codutilaj20)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_utilaje20_codutilaj</obj_name>
  <obj_reftable>utilaje20</obj_reftable>
  <obj_hashval>45b7369573cde8f42df70afbe0b47d30</obj_hashval>
  <obj_text>CREATE INDEX idx_utilaje20_codutilaj ON utilaje20 USING btree (codutilaj)</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>transf1</obj_name>
  <obj_hashval>75d585b7af1d864c126b53240873355a</obj_hashval>
  <obj_text>CREATE TABLE transf1 (
  "codtransf1" numeric(20,0) NOT NULL,
  "codtransf" numeric(20,0),
  "indexlocal" numeric(20,0),
  "tiplinie" character varying(1),
  "umsec" numeric(20,0),
  "codobiect" numeric(20,0),
  "pu" numeric(20,7),
  "cant" numeric(20,7),
  "tva" numeric(20,7),
  "obs" text,
  "codcont" numeric(20,0),
  "pumaximal" numeric(20,7),
  "costtransport" numeric(20,7),
  "codmifix" numeric(20,0),
  "puval" numeric(20,7),
  "codcentru" numeric(20,0),
  "codreteta" numeric(20,0),
  "codcomanda1" numeric(20,0),
  "codanalizanod" numeric(20,0),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7),
  "cantum1" numeric(20,7),
  "preluat" numeric(1,0),
  "codobiectorig" numeric(20,0),
  "paritateorig" numeric(20,7),
  "cantum2" numeric(20,7),
  "codauto" numeric(20,0),
  "codemulare1" numeric(20,0),
  "tipdocimp" numeric(5,0),
  "codliniedocimp" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_utilaje2c_codcomanda1</obj_name>
  <obj_reftable>utilaje2c</obj_reftable>
  <obj_hashval>7806aa854e40319ffac6d5ea72e3156a</obj_hashval>
  <obj_text>CREATE INDEX idx_utilaje2c_codcomanda1 ON utilaje2c USING btree (codcomanda1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_utilaje2c_codutilaj</obj_name>
  <obj_reftable>utilaje2c</obj_reftable>
  <obj_hashval>92e19b39fb8b155da2f0d11dbbce19b8</obj_hashval>
  <obj_text>CREATE INDEX idx_utilaje2c_codutilaj ON utilaje2c USING btree (codutilaj)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_utilaje2c_codutilaj2</obj_name>
  <obj_reftable>utilaje2c</obj_reftable>
  <obj_hashval>00ed731d3d4490e2f1bdc516acc80775</obj_hashval>
  <obj_text>CREATE INDEX idx_utilaje2c_codutilaj2 ON utilaje2c USING btree (codutilaj2)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_utilaje2p_codpers</obj_name>
  <obj_reftable>utilaje2p</obj_reftable>
  <obj_hashval>5f62bbdfd7788762293d7b6317ef96a8</obj_hashval>
  <obj_text>CREATE INDEX idx_utilaje2p_codpers ON utilaje2p USING btree (codpers)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_utilaje2p_codutilaj</obj_name>
  <obj_reftable>utilaje2p</obj_reftable>
  <obj_hashval>27789fa9d7f10bbdc81269c5c867fd6a</obj_hashval>
  <obj_text>CREATE INDEX idx_utilaje2p_codutilaj ON utilaje2p USING btree (codutilaj)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_utilaje2p_codutilaj2</obj_name>
  <obj_reftable>utilaje2p</obj_reftable>
  <obj_hashval>f03d1831be61ef3f5c3f5015d4dcba5e</obj_hashval>
  <obj_text>CREATE INDEX idx_utilaje2p_codutilaj2 ON utilaje2p USING btree (codutilaj2)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_utilajedev_codies1</obj_name>
  <obj_reftable>utilajedev</obj_reftable>
  <obj_hashval>76600da9cd453f979f8f99c81e8f5453</obj_hashval>
  <obj_text>CREATE INDEX idx_utilajedev_codies1 ON utilajedev USING btree (codies1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_utilajedev_codobiect</obj_name>
  <obj_reftable>utilajedev</obj_reftable>
  <obj_hashval>b3cf647cf550ce3b8083196400879e89</obj_hashval>
  <obj_text>CREATE INDEX idx_utilajedev_codobiect ON utilajedev USING btree (codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_utilajedev_codutilaj</obj_name>
  <obj_reftable>utilajedev</obj_reftable>
  <obj_hashval>1ae81f3c2b9c8397c775fbd815add56c</obj_hashval>
  <obj_text>CREATE INDEX idx_utilajedev_codutilaj ON utilajedev USING btree (codutilaj)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_utilajedev_codutilaj20</obj_name>
  <obj_reftable>utilajedev</obj_reftable>
  <obj_hashval>b5223098d3f948baec3d333bc0e1e12a</obj_hashval>
  <obj_text>CREATE INDEX idx_utilajedev_codutilaj20 ON utilajedev USING btree (codutilaj20)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_utilajemon_codutilaj20</obj_name>
  <obj_reftable>utilajemon</obj_reftable>
  <obj_hashval>b975b4f962e3424f615d8a7c8016d99c</obj_hashval>
  <obj_text>CREATE INDEX idx_utilajemon_codutilaj20 ON utilajemon USING btree (codutilaj20)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_vanzari_codemulare</obj_name>
  <obj_reftable>vanzari</obj_reftable>
  <obj_hashval>7de85ebe4be8e4f6674c62687983b84b</obj_hashval>
  <obj_text>CREATE INDEX idx_vanzari_codemulare ON vanzari USING btree (codemulare)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_vanzari_codpart</obj_name>
  <obj_reftable>vanzari</obj_reftable>
  <obj_hashval>d64c162d713d8401984b8360c105352a</obj_hashval>
  <obj_text>CREATE INDEX idx_vanzari_codpart ON vanzari USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_vouchercadou_barcode</obj_name>
  <obj_reftable>vouchercadou</obj_reftable>
  <obj_hashval>5d83de0f2d9e7e88bcc899c98f8b41be</obj_hashval>
  <obj_text>CREATE INDEX idx_vouchercadou_barcode ON vouchercadou USING btree (barcode)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_vouchercadoulink_coddoc</obj_name>
  <obj_reftable>vouchercadoulink</obj_reftable>
  <obj_hashval>1245c0b2c29b18572b65ab1f2724c77f</obj_hashval>
  <obj_text>CREATE INDEX idx_vouchercadoulink_coddoc ON vouchercadoulink USING btree (coddoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_vouchercadoulink_tipdoc</obj_name>
  <obj_reftable>vouchercadoulink</obj_reftable>
  <obj_hashval>0075896805c44d87412ba10940098206</obj_hashval>
  <obj_text>CREATE INDEX idx_vouchercadoulink_tipdoc ON vouchercadoulink USING btree (tipdoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_weekcashflow1_codcashflow</obj_name>
  <obj_reftable>weekcashflow1</obj_reftable>
  <obj_hashval>8ff67d8803d84c75baf4f314e22a37e5</obj_hashval>
  <obj_text>CREATE INDEX idx_weekcashflow1_codcashflow ON weekcashflow1 USING btree (codcashflow)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_weekcashplati_codcashflow1</obj_name>
  <obj_reftable>weekcashplati</obj_reftable>
  <obj_hashval>6c2e176b954f8f9ce3529505b5367da7</obj_hashval>
  <obj_text>CREATE INDEX idx_weekcashplati_codcashflow1 ON weekcashplati USING btree (codcashflow1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_zineluc1_data</obj_name>
  <obj_reftable>zineluc1</obj_reftable>
  <obj_hashval>301a4222e924775787dd18cf6dc62a51</obj_hashval>
  <obj_text>CREATE INDEX idx_zineluc1_data ON zineluc1 USING btree (data)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>iesprodlink_cmd</obj_name>
  <obj_reftable>iesprodlink</obj_reftable>
  <obj_hashval>3b742b3ad173e13e0cc5d09f4510c959</obj_hashval>
  <obj_text>CREATE INDEX iesprodlink_cmd ON iesprodlink USING btree (codcmdprodmat)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>intrprodlink_cmd</obj_name>
  <obj_reftable>intrprodlink</obj_reftable>
  <obj_hashval>152866ab114ae9c6bcf1c0d2a143c11e</obj_hashval>
  <obj_text>CREATE INDEX intrprodlink_cmd ON intrprodlink USING btree (codliniecomanda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>natrobj_fk</obj_name>
  <obj_reftable>natrobj</obj_reftable>
  <obj_hashval>a809290522e6c75452f2beae70db4b58</obj_hashval>
  <obj_text>CREATE INDEX natrobj_fk ON natrobj USING btree (codatrobj, codobiect)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>nirstoc1_ck</obj_name>
  <obj_reftable>nirstoc1</obj_reftable>
  <obj_hashval>597dac3360a50eee7875849aec01c191</obj_hashval>
  <obj_text>CREATE INDEX nirstoc1_ck ON nirstoc1 USING btree (codcomanda1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>nirstoc1_ok</obj_name>
  <obj_reftable>nirstoc1</obj_reftable>
  <obj_hashval>3bee29e74745606db21f72311eefca6d</obj_hashval>
  <obj_text>CREATE INDEX nirstoc1_ok ON nirstoc1 USING btree (codnirstocorig)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>nparc2_codnparcaut</obj_name>
  <obj_reftable>nparc2</obj_reftable>
  <obj_hashval>2fdd359ffd449a995b7970fe481a7626</obj_hashval>
  <obj_text>CREATE INDEX nparc2_codnparcaut ON nparc2 USING btree (cod)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>pacheteobj_codnirstoc</obj_name>
  <obj_reftable>pacheteobj</obj_reftable>
  <obj_hashval>2f19645ccdc3a1591881efea6a62b96a</obj_hashval>
  <obj_text>CREATE INDEX pacheteobj_codnirstoc ON pacheteobj USING btree (codnirstoc)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>pacheteobj_codpachete</obj_name>
  <obj_reftable>pacheteobj</obj_reftable>
  <obj_hashval>b59ccdd5135d8ef62fcaa49a3135dca1</obj_hashval>
  <obj_text>CREATE INDEX pacheteobj_codpachete ON pacheteobj USING btree (codpachete)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>pacheteobjl_codlivr1</obj_name>
  <obj_reftable>pacheteobjl</obj_reftable>
  <obj_hashval>73450835da1e20ceea889f792757e99b</obj_hashval>
  <obj_text>CREATE INDEX pacheteobjl_codlivr1 ON pacheteobjl USING btree (codlivr1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>pacheteobjl_codpachete</obj_name>
  <obj_reftable>pacheteobjl</obj_reftable>
  <obj_hashval>1b966a43b72b82dc2d0e3bb1221e4253</obj_hashval>
  <obj_text>CREATE INDEX pacheteobjl_codpachete ON pacheteobjl USING btree (codpachete)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>precmdlink_cmd</obj_name>
  <obj_reftable>precmdlink</obj_reftable>
  <obj_hashval>794ee5959a55c3845940e3b7f310fed7</obj_hashval>
  <obj_text>CREATE INDEX precmdlink_cmd ON precmdlink USING btree (codprecomanda1)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>programfman_codcmdprodmat</obj_name>
  <obj_reftable>programfman</obj_reftable>
  <obj_hashval>b74390cc90e64aa7a990d71a0b01e052</obj_hashval>
  <obj_text>CREATE INDEX programfman_codcmdprodmat ON programfman USING btree (codcmdprodman)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>programfman_codprogramf</obj_name>
  <obj_reftable>programfman</obj_reftable>
  <obj_hashval>be426b2eea9bb1c754edabb005141354</obj_hashval>
  <obj_text>CREATE INDEX programfman_codprogramf ON programfman USING btree (codprogramf)</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>etva_390_394_cod</obj_name>
  <obj_hashval>c27edb414631bafc1d217ad7a22795fa</obj_hashval>
  <obj_text>CREATE SEQUENCE etva_390_394_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>transport</obj_name>
  <obj_hashval>265920100a02dce91ed7ee7eb0665e41</obj_hashval>
  <obj_text>CREATE TABLE transport (
  "codtransport" numeric(20,0) NOT NULL,
  "datatransport" timestamp(6) without time zone,
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "subunitate" numeric(20,0),
  "indicativ" character varying(100),
  "operat" numeric(1,0),
  "blocat" numeric(1,0),
  "anulat" numeric(1,0),
  "an" numeric(20,0),
  "luna" numeric(20,0),
  "valoare" numeric(20,7),
  "tiprepart" numeric(1,0),
  "codparcauto" numeric(20,0),
  "codsofer" numeric(20,0),
  "colete" numeric(1,0),
  "rep_transf" numeric(1,0),
  "rep_subunit" numeric(1,0),
  "tip" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>transport1</obj_name>
  <obj_hashval>a27d4318d70746485f9469997b30053a</obj_hashval>
  <obj_text>CREATE TABLE transport1 (
  "codtransport1" numeric(20,0) NOT NULL,
  "codtransport" numeric(20,0),
  "codcolet" numeric(20,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>transport2</obj_name>
  <obj_hashval>785c121b57c9602678622abbd6971202</obj_hashval>
  <obj_text>CREATE TABLE transport2 (
  "codtransport2" numeric(20,0) NOT NULL,
  "codtransport" numeric(20,0),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>traseu</obj_name>
  <obj_hashval>38592dd3f83c40b443392823c6a796e1</obj_hashval>
  <obj_text>CREATE TABLE traseu (
  "codtraseu" numeric(20,0) NOT NULL,
  "codfisasup" numeric(20,0),
  "indexlocal" numeric(10,0),
  "pozt" numeric(10,0),
  "executant" numeric(20,0),
  "clasateh" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>traseulivr</obj_name>
  <obj_hashval>ff7a0270635d1020547e74e7a93279c9</obj_hashval>
  <obj_text>CREATE TABLE traseulivr (
  "codtraseulivr" numeric(20,0) NOT NULL,
  "dentraseu" character varying(100),
  "simboltraseu" character varying(20),
  "opriri" numeric(10,0),
  "ore" numeric(10,0),
  "minute" numeric(2,0),
  "tip" numeric(2,0),
  "lat" numeric(20,7),
  "lng" numeric(20,7),
  "codlocalit" numeric(20,0),
  "adresa" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>etva_amef_cod</obj_name>
  <obj_hashval>b88f6316dc7ef44904f3b68f0a9203b5</obj_hashval>
  <obj_text>CREATE SEQUENCE etva_amef_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>etva_cod</obj_name>
  <obj_hashval>61ce3ff96dec1188c722ce51ebb3e1b8</obj_hashval>
  <obj_text>CREATE SEQUENCE etva_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>etva_etransport_cod</obj_name>
  <obj_hashval>ed18996ab8ee8534f4bebfa3af9fb8d4</obj_hashval>
  <obj_text>CREATE SEQUENCE etva_etransport_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>etva_factura_cod</obj_name>
  <obj_hashval>6282eccc4d98baf42ea2f3236386fa63</obj_hashval>
  <obj_text>CREATE SEQUENCE etva_factura_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>etva_factura_tva_cod</obj_name>
  <obj_hashval>5f61168fe4c140b278e7d2607fafae82</obj_hashval>
  <obj_text>CREATE SEQUENCE etva_factura_tva_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>trezor</obj_name>
  <obj_hashval>06925be602ad1c06be0d68c48707ffa3</obj_hashval>
  <obj_text>CREATE TABLE trezor (
  "codtrezor" numeric(20,0) NOT NULL,
  "tipdoc" numeric(20,0),
  "codbanca" numeric(20,0),
  "icontpers" numeric(20,0),
  "monedapers" numeric(20,0),
  "datadoc" date,
  "numedoc" character varying(50),
  "an" numeric(5,0),
  "luna" numeric(2,0),
  "agent" numeric(20,0),
  "operat" numeric(1,0),
  "blocat" numeric(1,0),
  "subunitatea" numeric(20,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "datainreg" timestamp(6) without time zone,
  "idimport" character varying(30),
  "codanaliza" numeric(20,0),
  "carnetdoc" numeric(20,0),
  "nrdoc" numeric(20,0),
  "seriadoc" character varying(20),
  "listat" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>etva_locuinte_cod</obj_name>
  <obj_hashval>a904a44919d2ecfa490138b3a56168fc</obj_hashval>
  <obj_text>CREATE SEQUENCE etva_locuinte_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>etva_vama_export_cod</obj_name>
  <obj_hashval>85ce8f35f5f3053608d00c678a7340af</obj_hashval>
  <obj_text>CREATE SEQUENCE etva_vama_export_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>etva_vama_import_cod</obj_name>
  <obj_hashval>473a5396e5695caaeb5b19d7247e72a4</obj_hashval>
  <obj_text>CREATE SEQUENCE etva_vama_import_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_adaosm_codadaosm</obj_name>
  <obj_hashval>9144b13e660dfe7dfcf42a71c9bf4e01</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_adaosm_codadaosm INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_adaosm1_codadaosm1</obj_name>
  <obj_hashval>f29f1de9c16c7e014242c3994b3e9462</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_adaosm1_codadaosm1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_alerta_info_codalerteinfo</obj_name>
  <obj_hashval>633c5af65fa78800ed08143f61becbf4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_alerta_info_codalerteinfo INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_alerta_info_rulare</obj_name>
  <obj_hashval>1b04ec4804e8714619e902c7464eb26a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_alerta_info_rulare INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 221 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_alerte_codalerta</obj_name>
  <obj_hashval>72a02f73477c61478e143fb09b3d9244</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_alerte_codalerta INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_alerte_def_codalertedef</obj_name>
  <obj_hashval>e13fd32b75a8c9837a91e2264f85a3b0</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_alerte_def_codalertedef INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 166 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_alerte0_codalerta0</obj_name>
  <obj_hashval>2fb2e54d9ee96a591939ad87bb07312d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_alerte0_codalerta0 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_alerte1_codalerta1</obj_name>
  <obj_hashval>50429cda79f883d569d7f38bc514708c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_alerte1_codalerta1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_alerte1_def_codalertedef1</obj_name>
  <obj_hashval>f535b518b3c413981a9f3539214dfed6</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_alerte1_def_codalertedef1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 167 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_analiza_codanaliza</obj_name>
  <obj_hashval>a98bdea4d0879ca5744a3c409cf9f92b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_analiza_codanaliza INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_analiza1_codanaliza1</obj_name>
  <obj_hashval>86be127471a22c8cb47d716ae9c1c4f8</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_analiza1_codanaliza1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_analizanod_codanalizanod</obj_name>
  <obj_hashval>5bd723436b6dc08158abff15e90abeb2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_analizanod_codanalizanod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_apeltelefon_codapel</obj_name>
  <obj_hashval>cf889069f66e0736caa94a0412fee30e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_apeltelefon_codapel INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_asigurari_codasigurare</obj_name>
  <obj_hashval>a53191e2178e6fd78ef281f86233116a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_asigurari_codasigurare INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_asigurari1_codasigurare1</obj_name>
  <obj_hashval>c307654baa5cc3a8fffdc8fd1025e86e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_asigurari1_codasigurare1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_autorizatii_codautorizatii</obj_name>
  <obj_hashval>b5f15e721d55106878357562da4fbfba</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_autorizatii_codautorizatii INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_avariecaroserie_codavarie</obj_name>
  <obj_hashval>4fdbeacf1ca887a8231d63d41e47cab6</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_avariecaroserie_codavarie INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_awbcomanda_codawbcomanda</obj_name>
  <obj_hashval>e4c351a2da3c47fb0a3268855e974b04</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_awbcomanda_codawbcomanda INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_balstocrest_cod</obj_name>
  <obj_hashval>ecf9c00faa70fd81dc8e31a180818db2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_balstocrest_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_bankautentif_cod</obj_name>
  <obj_hashval>44498f9a40919d65e8984faa5a71a38b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_bankautentif_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_bcar_codbcar</obj_name>
  <obj_hashval>46b028dd4a64b6b776d8bbe0768896e7</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_bcar_codbcar INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_bonlinkerr_codbonlinkerr</obj_name>
  <obj_hashval>51ba6acf49440af219fc8b13cb59b6d6</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_bonlinkerr_codbonlinkerr INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_bonmasa_cod</obj_name>
  <obj_hashval>1c0dcc01eeca0886b59da6e4138dc0f7</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_bonmasa_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_bugetcap_codbugetcap</obj_name>
  <obj_hashval>de37dc56edb5d843606645e74d36c183</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_bugetcap_codbugetcap INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_bugetcap1_codbugetcap1</obj_name>
  <obj_hashval>309e649e6aa484803038156d47a8a3ea</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_bugetcap1_codbugetcap1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_bugetcl_codbugetcl</obj_name>
  <obj_hashval>bd41529c55b944deeace54427139ca21</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_bugetcl_codbugetcl INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_bugetmf_codbugetmf</obj_name>
  <obj_hashval>1aee3ee9fad212c65fe4a436d727e1b3</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_bugetmf_codbugetmf INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_bugetmf1_codbugetmf1</obj_name>
  <obj_hashval>76de8c77b97908c8df99a4cf8ae149a8</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_bugetmf1_codbugetmf1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_bugetprod_cod</obj_name>
  <obj_hashval>77afa905c0f63b02b471e4da70f86f2f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_bugetprod_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_bugetprodp_codp</obj_name>
  <obj_hashval>e7a20bf425667b106f6774b5c4b14b5d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_bugetprodp_codp INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_bugetprodt_codt</obj_name>
  <obj_hashval>0ccdbaa6c8cbd60d8c9ab0b75257dba2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_bugetprodt_codt INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_bugetprodv_codv</obj_name>
  <obj_hashval>4cf3e3eb322e10cd9f88bd12171fd5c9</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_bugetprodv_codv INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_bugetrectif_codbugetrect</obj_name>
  <obj_hashval>5a3a7f80c4f7c2c534030a4331bcf93d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_bugetrectif_codbugetrect INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_bugetrectif1_codbugetrect1</obj_name>
  <obj_hashval>7cb6d8dbab5981d7095a5327b3582b31</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_bugetrectif1_codbugetrect1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_bugetstoc_codbugetstoc</obj_name>
  <obj_hashval>fec03cf6ce28433f9fa5238660e3c691</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_bugetstoc_codbugetstoc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_bugetvcl_codbugetvcl</obj_name>
  <obj_hashval>ceab39dae9863294aac13263733d9bb3</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_bugetvcl_codbugetvcl INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_bugetvl_codbugetvl</obj_name>
  <obj_hashval>f0e8f8bbbfb701cc01ada1cedf1dfed5</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_bugetvl_codbugetvl INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_caensec_codcaensec</obj_name>
  <obj_hashval>a64bf856957b03a04321df106362856b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_caensec_codcaensec INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_campanii_codcampanie</obj_name>
  <obj_hashval>8f671388234291bd8b3adfc6b4e9f348</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_campanii_codcampanie INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_campaniicost_codcc</obj_name>
  <obj_hashval>1d46ca19b0b02388e8daf7436cbfcdbc</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_campaniicost_codcc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_campaniipart_codcp</obj_name>
  <obj_hashval>06b60622c6ca79a43650976a552b36ce</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_campaniipart_codcp INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_campaniivenit_codcv</obj_name>
  <obj_hashval>04fc3802a5930fcc1482ecb12662cf9e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_campaniivenit_codcv INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_canamed_codcanamed</obj_name>
  <obj_hashval>9cbc97d0598be9b6ae1551e3bcdef98f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_canamed_codcanamed INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_canamed1_codcanamed1</obj_name>
  <obj_hashval>6aaa7e093e4dff3e18be9024c8c6ca56</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_canamed1_codcanamed1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cantar_codcantar</obj_name>
  <obj_hashval>389eafad4fd37ea3cf1b06598c644757</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cantar_codcantar INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cantare_codcantar</obj_name>
  <obj_hashval>4799f0fe9bc374ce24f96d1ac61adfab</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cantare_codcantar INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_carduri_codcard</obj_name>
  <obj_hashval>4f9df677595dd63a49d0decf0e837f42</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_carduri_codcard INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cashflow_codcashflow</obj_name>
  <obj_hashval>ea46bdb02a3fce103af037f210173487</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cashflow_codcashflow INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cashflow1_codcashflow1</obj_name>
  <obj_hashval>23895b51d9f65838b12dab61a1259c23</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cashflow1_codcashflow1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cashflow2_codcashflow2</obj_name>
  <obj_hashval>64ed8ca200a6dfa341ac7776da849c67</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cashflow2_codcashflow2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_castotprepay_cod</obj_name>
  <obj_hashval>a4993934b27748236acb89aaa80b77ca</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_castotprepay_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_castotutility_cod</obj_name>
  <obj_hashval>0b35655b2345570a3bd31fc8a3674b9e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_castotutility_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_categartti_codcategartti</obj_name>
  <obj_hashval>4fdeff8526ab58f51295f0c5dd650971</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_categartti_codcategartti INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_categconst_codcateg</obj_name>
  <obj_hashval>ca0e2b8885953bcc508812250c0d9426</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_categconst_codcateg INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 255 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_centralizarenc_codc</obj_name>
  <obj_hashval>9997ee7d01ddd4c007a21d34d2a45ba4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_centralizarenc_codc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_centrecost_codcentru</obj_name>
  <obj_hashval>14a22e33e0dad5fe1b4b06251f6b86d4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_centrecost_codcentru INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 105 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_centrecosta_codcentrua</obj_name>
  <obj_hashval>676a7ec4bc5b253005eb204140725730</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_centrecosta_codcentrua INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_certif_codcertif</obj_name>
  <obj_hashval>9e88f434705220b4a84e932b3f115728</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_certif_codcertif INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cfgactions</obj_name>
  <obj_hashval>fabba760116ef150432eab94a518feac</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cfgactions INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cfgtables_codcfgtable</obj_name>
  <obj_hashval>04457a838aaff5c72beabe09d4a579ad</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cfgtables_codcfgtable INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>trezor1</obj_name>
  <obj_hashval>67806aa467052ac49dd5487ab85e35ab</obj_hashval>
  <obj_text>CREATE TABLE trezor1 (
  "codtrezor1" numeric(20,0) NOT NULL,
  "codtrezor" numeric(20,0),
  "indexlocal" numeric(5,0),
  "tiptranz" numeric(1,0),
  "carnetdoc" numeric(20,0),
  "doc" character varying(30),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "valdoc" numeric(20,7),
  "curs" numeric(20,7),
  "comision" numeric(20,7),
  "obiecttranz" numeric(20,0),
  "codpart" numeric(10,0),
  "tipdecont" numeric(1,0),
  "datadecont" date,
  "an" numeric(7,0),
  "luna" numeric(2,0),
  "obs" character varying(200),
  "initializari" numeric(1,0),
  "agent" numeric(20,0),
  "anulat" numeric(1,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "codlocatie" numeric(20,0),
  "codcentru" numeric(20,0),
  "seriedoc" character varying(20),
  "codsertar" numeric(20,0),
  "nri" character varying(40),
  "codcomanda" numeric(20,0),
  "platatva" numeric(1,0),
  "codgest" numeric(20,0),
  "codcmdint1" numeric(20,0),
  "codplata1" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>trezor1_reg</obj_name>
  <obj_hashval>11894c20882f7ab1f19d8eba99a72dc7</obj_hashval>
  <obj_text>CREATE TABLE trezor1_reg (
  "codreg" numeric(20,0),
  "codtrezor1" numeric(20,0),
  "curs" numeric(20,4),
  "data" date
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>trezorretail</obj_name>
  <obj_hashval>a40bd961f21546854d69c26da619fb8e</obj_hashval>
  <obj_text>CREATE TABLE trezorretail (
  "codtrezor" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>trigar</obj_name>
  <obj_hashval>61a72cb4fa5527340ae4c4614931e209</obj_hashval>
  <obj_text>CREATE TABLE trigar (
  "codtrigar" numeric(20,0) NOT NULL,
  "tablename" character varying(20),
  "trig" text,
  "variabile" text,
  "tip" numeric(1,0),
  "operatie" numeric(1,0),
  "moment" numeric(1,0),
  "masterfield" character varying(20),
  "mastertable" character varying(20),
  "maintable" character varying(20),
  "initiator" numeric(20,0),
  "destinatar" character varying(300),
  "subiect" character varying(200),
  "antet" character varying(2000),
  "final" character varying(2000),
  "obs" character varying(500),
  "inactiv" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>trigar1</obj_name>
  <obj_hashval>0bc8c12cdb21023580623bfe6b7bd0cb</obj_hashval>
  <obj_text>CREATE TABLE trigar1 (
  "codtrigar1" numeric(20,0) NOT NULL,
  "codtrigar" numeric(20,0),
  "fieldname" character varying(20)
);</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cfgtables1_codcfgtable1</obj_name>
  <obj_hashval>30f522feef24856ab3774a7cb47f8d35</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cfgtables1_codcfgtable1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>trigar_modif</obj_name>
  <obj_hashval>8eac6ce2b1ca74b1088487d47d088914</obj_hashval>
  <obj_text>CREATE TABLE trigar_modif (
  "datamodif" timestamp(0) without time zone,
  "usermodif" numeric(10,0),
  "codmaster" numeric(20,0),
  "cod" numeric(20,0),
  "tablename" character varying(20),
  "fieldname" character varying(20),
  "oldvalue" character varying(100),
  "newvalue" character varying(100),
  "codmodif" numeric(20,0) NOT NULL
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tvamonetar</obj_name>
  <obj_hashval>1abbf6fd3b5a5bebcf435d9412a27953</obj_hashval>
  <obj_text>CREATE TABLE tvamonetar (
  "codtvamonetar" numeric(20,0),
  "codies" numeric(20,0),
  "bonuri" numeric(5,0),
  "codtva" numeric(20,0),
  "valoare" numeric(20,7),
  "tva" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tvaserv</obj_name>
  <obj_hashval>7416b94ff8c22c3cc2c1f66f3df6fc51</obj_hashval>
  <obj_text>CREATE TABLE tvaserv (
  "codtvaserv" numeric(20,0) NOT NULL,
  "denumire" character varying(200),
  "codtara" numeric(20,0),
  "tipcota" numeric(10,0),
  "procent" numeric(20,7),
  "codcont" numeric(20,0),
  "simbol" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tvaserv1</obj_name>
  <obj_hashval>1766db0410ae301c5e7b56c720cf7947</obj_hashval>
  <obj_text>CREATE TABLE tvaserv1 (
  "codtvaserv1" numeric(20,0) NOT NULL,
  "codtvaserv" numeric(20,0),
  "codcont" numeric(20,0),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>usersql</obj_name>
  <obj_hashval>1465c005fb5eaf937130cd5d88f7ae76</obj_hashval>
  <obj_text>CREATE TABLE usersql (
  "codsql" numeric(20,0),
  "denumire" character varying(100),
  "obs" character varying(200),
  "userid" numeric(20,0),
  "datacreare" date,
  "sqltext" text,
  "whereclause" character varying(1000),
  "rezultat" character varying(1000)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>usersql1</obj_name>
  <obj_hashval>a1dc2e8c1f88a36c9d7b57677def6505</obj_hashval>
  <obj_text>CREATE TABLE usersql1 (
  "codsql1" numeric(20,0),
  "codsql" numeric(20,0),
  "tabla" character varying(50),
  "nume" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>usersql2</obj_name>
  <obj_hashval>4146ad7968ae6eed1ee1af21a032a388</obj_hashval>
  <obj_text>CREATE TABLE usersql2 (
  "codsql2" numeric(20,0),
  "codsql" numeric(20,0),
  "codsql1" numeric(20,0),
  "tipjoin" numeric(1,0),
  "joinon" character varying(100),
  "joinwhere" character varying(100)
);</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cfgtables2_codcfgtable2</obj_name>
  <obj_hashval>06b7b68cdf73cc400e3d785a71f10142</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cfgtables2_codcfgtable2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cheltavans_codcheltavans</obj_name>
  <obj_hashval>6f1344b63864b76fcaa016b7f3e2d8c0</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cheltavans_codcheltavans INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cheltavans1_codcheltavans1</obj_name>
  <obj_hashval>4abe3ce9192534617eeb080faa4e6b9a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cheltavans1_codcheltavans1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cheltoper_codcheltoper</obj_name>
  <obj_hashval>9f475c248cc25e5f1e6488e79b7a421f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cheltoper_codcheltoper INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cheltoper1_codcheltoper1</obj_name>
  <obj_hashval>da3c8fd7ec6bedeac0337b0eb82ff520</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cheltoper1_codcheltoper1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cmdaprobari_cod</obj_name>
  <obj_hashval>5e2ccef243ec7d3f6f981698a95084d7</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cmdaprobari_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cmdavans_codcmdavans</obj_name>
  <obj_hashval>adc92f8e4c44d637fed3cc0f36d7b128</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cmdavans_codcmdavans INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cmdprodman_codcmdprodman</obj_name>
  <obj_hashval>9836344dbcea53ac5f9a83b364884360</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cmdprodman_codcmdprodman INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cmdprodmat_codcmdprodmat</obj_name>
  <obj_hashval>a5097165541dbc7d5984e7167d1a540c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cmdprodmat_codcmdprodmat INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cmdprodrez_codcmdprodrez</obj_name>
  <obj_hashval>f6193e19f9d3592da5c032437bcc49bf</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cmdprodrez_codcmdprodrez INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cmdtl_codcmdtl</obj_name>
  <obj_hashval>93c9e3ece0696a3d1cc49bfb57f639f0</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cmdtl_codcmdtl INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_codextalt_cod</obj_name>
  <obj_hashval>1209a3169048f8d774fa24878c61189b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_codextalt_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_codextartlock_cod</obj_name>
  <obj_hashval>6dc4e9a927622798c35eba6d1257ca71</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_codextartlock_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 121 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_codextpartlock_cod</obj_name>
  <obj_hashval>70483a9e5f1dffc6a58b3bac461d0b43</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_codextpartlock_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_codgestlock_cod</obj_name>
  <obj_hashval>c3b771a124c1991959cdf677315a939d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_codgestlock_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_codintalt_cod</obj_name>
  <obj_hashval>c5db802a12850062ecd2b983e0abd55b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_codintalt_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_codintartlock_cod</obj_name>
  <obj_hashval>22ca96f21d8617c4a82e4bde43231700</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_codintartlock_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_codintpartlock_cod</obj_name>
  <obj_hashval>555d57a558a6c7c68ee93011cdf3ca5d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_codintpartlock_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 119 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_codioartcoresp_cod</obj_name>
  <obj_hashval>ffb211c5e957ea8606e0df778d9d3be9</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_codioartcoresp_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_comanda_codcomanda</obj_name>
  <obj_hashval>3ecedd9101081c27522ada60e11693d2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_comanda_codcomanda INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_comanda1_codcomanda1</obj_name>
  <obj_hashval>1d02bc67457bf9e5779aecf19cd3e6eb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_comanda1_codcomanda1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_comanda1_codcomanda2</obj_name>
  <obj_hashval>91ec4348bff82f66ff04a34edbeafb6f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_comanda1_codcomanda2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_comanda1et_codcomanda1et</obj_name>
  <obj_hashval>80b31249891b3702c5f5db32cfb16137</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_comanda1et_codcomanda1et INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_comanda2_codcomanda3</obj_name>
  <obj_hashval>d52e1c8c13c089337edbea1146423c72</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_comanda2_codcomanda3 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_comanda4_codcomanda4</obj_name>
  <obj_hashval>9d94daaa67c7165613e6affabd8f2563</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_comanda4_codcomanda4 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 286 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_comenzionline_nrdoc</obj_name>
  <obj_hashval>0ca15cf46d645650b698bae7bc3a5324</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_comenzionline_nrdoc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_compens_codcompens</obj_name>
  <obj_hashval>192dec3a67a9c4daec9e82af868687c7</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_compens_codcompens INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_concurenti_codconcurent</obj_name>
  <obj_hashval>aac8854a56400510c95922c2d944e168</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_concurenti_codconcurent INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_condcor1_codcondcor1</obj_name>
  <obj_hashval>484c969f06e2379057f58561b3cad054</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_condcor1_codcondcor1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_const1_codconst1</obj_name>
  <obj_hashval>c9ed99592fee00551fdc07ab34202d7a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_const1_codconst1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 6499 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_constluna_codconstluna</obj_name>
  <obj_hashval>e09382f933d01444ddba0240c02bc4b2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_constluna_codconstluna INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 6310 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_constmaketa_codconstmaketa</obj_name>
  <obj_hashval>81af68da70a05476d8648226121fdddf</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_constmaketa_codconstmaketa INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_constvalpos_cod</obj_name>
  <obj_hashval>4eb3beed4cc1acb08537baaa2ce9fc23</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_constvalpos_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 6818 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_contract_codcontract</obj_name>
  <obj_hashval>31a24a6b5ade8449dfcbde33fcf3ffb1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_contract_codcontract INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_contract0_codcontract0</obj_name>
  <obj_hashval>900614d78df664e9e5bbac1b9033df1c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_contract0_codcontract0 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_contract1_codcontract1</obj_name>
  <obj_hashval>23c25399c9ce0a1bcc815bbc0a495a9d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_contract1_codcontract1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_contract2_codcontract2</obj_name>
  <obj_hashval>8895d549bbb68d2916e198e5078f8e5d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_contract2_codcontract2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_contractc_codcontractc</obj_name>
  <obj_hashval>110e1424291b58dad7aa8577cd8b3e77</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_contractc_codcontractc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 119 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_contractc0_codcontractc0</obj_name>
  <obj_hashval>11f98f54fd0eab9335ba4a03b7fa121e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_contractc0_codcontractc0 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_contractt_codcontractt</obj_name>
  <obj_hashval>b533a619247ae387416157fea71a253b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_contractt_codcontractt INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 117 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_contractv_codcontractv</obj_name>
  <obj_hashval>557125aa8a6c59ad934eaf1a12708520</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_contractv_codcontractv INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 117 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_contractx_codcontractx</obj_name>
  <obj_hashval>0a926f4c98a741308425f9d53c2caa70</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_contractx_codcontractx INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 117 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_contractxx_codcontractxx</obj_name>
  <obj_hashval>c20821aa84aaf444c33ad7d3fe43923c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_contractxx_codcontractxx INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_convertcurspers_codconvert</obj_name>
  <obj_hashval>ab522cbfae8b7e6fad0489bfa9302d3c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_convertcurspers_codconvert INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_corelat1_codcorelat1</obj_name>
  <obj_hashval>66d85ea4efba7ad656d1b476cde5c53b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_corelat1_codcorelat1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_corelat2_codcorelat2</obj_name>
  <obj_hashval>e46f13d64a3fc7e2a2021dd5b1fe33a9</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_corelat2_codcorelat2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_creante_codcreanta</obj_name>
  <obj_hashval>d54445fb23fe5716c0cfd9a2b6bb49eb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_creante_codcreanta INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_creante1_codcreanta1</obj_name>
  <obj_hashval>809410a407bc34c3c1bb08a8acd09a79</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_creante1_codcreanta1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_criteriidisc_codcriteriu</obj_name>
  <obj_hashval>6f41b8b210ac18989efd5ab461182742</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_criteriidisc_codcriteriu INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 109 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_criteriidisc1_codcriteriu1</obj_name>
  <obj_hashval>8787f31d511665ac5d5108bbf5bdc343</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_criteriidisc1_codcriteriu1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cronocashflow_codcrono</obj_name>
  <obj_hashval>77d054c5913f45a4fd00d3d6172316ce</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cronocashflow_codcrono INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_curscashflow_codcurs</obj_name>
  <obj_hashval>618db5cedd8ca8fd1164dbe8d12db6b7</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_curscashflow_codcurs INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cursuri_codcurs</obj_name>
  <obj_hashval>8699730d5004ab5a09caa246f4218530</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cursuri_codcurs INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_cursuri1_codcurs1</obj_name>
  <obj_hashval>e10c15a9b4f68ab46454fccf96710d9a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_cursuri1_codcurs1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_custodieini_codcustodie</obj_name>
  <obj_hashval>3c6cacb3230d115ba44ac61aef0e9811</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_custodieini_codcustodie INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d300_codd300</obj_name>
  <obj_hashval>1de1b45fd1d9164d08b3cf8f54cacb79</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d300_codd300 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d390_codd390</obj_name>
  <obj_hashval>56f3bb7868118f987cf8944f94cf729a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d390_codd390 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d390ca_codd390ca</obj_name>
  <obj_hashval>abdd3e7177ea45a97db3b45e14f36c98</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d390ca_codd390ca INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d390cb_codd390cb</obj_name>
  <obj_hashval>3730a5951df80986a8b67760c6e1e18b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d390cb_codd390cb INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d390d_codd390d</obj_name>
  <obj_hashval>ffac74ac8553e4116ad2764bc5805ed9</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d390d_codd390d INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d390o_codd390o</obj_name>
  <obj_hashval>35853395a2b65873f9ff6ffa2b2f506b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d390o_codd390o INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d394_codd394</obj_name>
  <obj_hashval>9e5a11822bb6334769fc473250e6c8dd</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d394_codd394 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416_codd39416</obj_name>
  <obj_hashval>c68c19f1f50aa1ee4f1ce8fe2f04c4aa</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416_codd39416 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416g_codd39416g</obj_name>
  <obj_hashval>ab6dc1e6d4462367cb677408d6c89470</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416g_codd39416g INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416g1_codd39416g1</obj_name>
  <obj_hashval>2dac63609d6e32c01c3f89af97b4d26e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416g1_codd39416g1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416g2_codd39416g2</obj_name>
  <obj_hashval>25c967e76d49716022f9bed923ede58c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416g2_codd39416g2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416g3_codd39416g3</obj_name>
  <obj_hashval>45f65009226081850ecdc6105d832b8a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416g3_codd39416g3 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416i_codd39416i</obj_name>
  <obj_hashval>01cb606f1a6be93a38fc57e6045823ad</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416i_codd39416i INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416i1_codd39416i1</obj_name>
  <obj_hashval>dcb903d86d1321e934745689c0352e82</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416i1_codd39416i1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416i2_codd39416i2</obj_name>
  <obj_hashval>a1f1de3bbabfd7e11b56b032647d60be</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416i2_codd39416i2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416i2a_codd39416i2a</obj_name>
  <obj_hashval>527ca2b25df8c184b2b4de12922a0c21</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416i2a_codd39416i2a INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416i3_codd39416i3</obj_name>
  <obj_hashval>3bc7c849c05dfa05504cd816162de919</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416i3_codd39416i3 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416i4_codd39416i4</obj_name>
  <obj_hashval>39fbd179d0bcfb37819900d4ec5bde1d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416i4_codd39416i4 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416n_codd39416n</obj_name>
  <obj_hashval>ec87991e52b1da7fade3bfb0605bfe78</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416n_codd39416n INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416ns2_codd39416ns2</obj_name>
  <obj_hashval>317f1ecfa999429c6ad11b3d89e4333a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416ns2_codd39416ns2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416r_codd39416r</obj_name>
  <obj_hashval>57d3449f145d4e503d0fc86c47c16fdb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416r_codd39416r INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416rn_codd39416rn</obj_name>
  <obj_hashval>1e18720fe825fc2853e156b498d2763a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416rn_codd39416rn INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416rn0_codd39416rn0</obj_name>
  <obj_hashval>75791d3ce81f45fc8219f6768c47d269</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416rn0_codd39416rn0 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416rn1_codd39416rn1</obj_name>
  <obj_hashval>062f076cbbe83834e42bb24495511ae2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416rn1_codd39416rn1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416rns2_codd39416rns2</obj_name>
  <obj_hashval>306a6b78e2c83636af43b7e0e3a06041</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416rns2_codd39416rns2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416rns3_codd39416rns3</obj_name>
  <obj_hashval>4b3705199c8d69e15c9efbc2da3feb8f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416rns3_codd39416rns3 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416rp_codd39416rp</obj_name>
  <obj_hashval>6a1958133466c2198a15274fd95615c0</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416rp_codd39416rp INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416rp1_codd39416rp1</obj_name>
  <obj_hashval>5221e0824ff42adce2d3d7174f42a51f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416rp1_codd39416rp1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416rps2_codd39416rps2</obj_name>
  <obj_hashval>d8d1f7ced8276b806dd488bfc6508f9b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416rps2_codd39416rps2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416rps3_codd39416rps3</obj_name>
  <obj_hashval>0e3ee6b3b3f71d1acc3bde5e7ffd3afb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416rps3_codd39416rps3 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416ue_codd39416ue</obj_name>
  <obj_hashval>acbd581c056737b4673dc35f9e75ce4b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416ue_codd39416ue INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d39416ues2_codd39416ues2</obj_name>
  <obj_hashval>490c9bb89776757531d010f91373104e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d39416ues2_codd39416ues2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d394a_codd394a</obj_name>
  <obj_hashval>4bb05ea56d47461ef9ba073629c02bbf</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d394a_codd394a INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d394c_codd394c</obj_name>
  <obj_hashval>76ba0752af2f4ab8064615d0b60774b0</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d394c_codd394c INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d394cc_codd394cc</obj_name>
  <obj_hashval>da8aa51f130781c6a93fb8dc0a192289</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d394cc_codd394cc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d394l_codd394l</obj_name>
  <obj_hashval>b7e26969cab24fc272bf0c0c29f7936c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d394l_codd394l INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d394v_codd394v</obj_name>
  <obj_hashval>92b583467b7f53ecd7908e8e73575c6c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d394v_codd394v INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_d394vc_codd394vc</obj_name>
  <obj_hashval>b57838d0f005b886e6bfd238368fd1c8</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_d394vc_codd394vc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_datawarehouse_cod</obj_name>
  <obj_hashval>ed3c1c29d0a35b211bdfc69663dbf8d8</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_datawarehouse_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_descrip_coddescriptor</obj_name>
  <obj_hashval>1dd5fc63ba02a4e5635d13d172c8821b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_descrip_coddescriptor INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_descript1_coddescriptor1</obj_name>
  <obj_hashval>b8ba6bf06c1b4d1119cc8f82532a154e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_descript1_coddescriptor1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_destinatii_coddestinatie</obj_name>
  <obj_hashval>d02d97fa69fd085866b0a0c080fb59a8</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_destinatii_coddestinatie INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 107 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_detaliiet_coddetaliu</obj_name>
  <obj_hashval>39e1de5dbf507deb186c6d4e1bdb2b2d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_detaliiet_coddetaliu INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_detaliiet1_coddetaliuet1</obj_name>
  <obj_hashval>696967ae003c41a30f115ce3aa66a6ec</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_detaliiet1_coddetaliuet1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_dificultati_coddif</obj_name>
  <obj_hashval>b227582e6a77864035b6aeface5bcd93</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_dificultati_coddif INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_dintrastat_coddintrastat</obj_name>
  <obj_hashval>150d68922087f1b2f03a54232c033e3a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_dintrastat_coddintrastat INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_dintrastata_coddintrastata</obj_name>
  <obj_hashval>da4825e56f6cb15246493843673b6817</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_dintrastata_coddintrastata INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_dintrastatd_coddintrastatd</obj_name>
  <obj_hashval>836144b1c9ca7a41affef87203874945</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_dintrastatd_coddintrastatd INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_discart_coddiscart</obj_name>
  <obj_hashval>f17e05574107ddacbe23bee665902ab9</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_discart_coddiscart INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_discexceptii_cod</obj_name>
  <obj_hashval>af4b06d9b908de272640e0b6f1bdc7d7</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_discexceptii_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_discinterval_coddiscinterv</obj_name>
  <obj_hashval>2a752db215d63d794f4492bfde739273</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_discinterval_coddiscinterv INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_discmonetar_coddiscmonetar</obj_name>
  <obj_hashval>a04b9ee2c975201109e1e7ae60b69a48</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_discmonetar_coddiscmonetar INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_discount_coddiscount</obj_name>
  <obj_hashval>a3594f9809536529164bab4aea309fd7</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_discount_coddiscount INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_discpromoretail_cod</obj_name>
  <obj_hashval>9c043662948026492ea680ed3f99109d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_discpromoretail_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_distanta_coddistanta</obj_name>
  <obj_hashval>b846ee20507898884ada35389a7cc0b8</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_distanta_coddistanta INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 115 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_distrib_coddistrib</obj_name>
  <obj_hashval>9ab35cfb80ec3451cb0828fecda77e2c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_distrib_coddistrib INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_distrib1_coddistrib1</obj_name>
  <obj_hashval>fc6faa6775ab7a4537a7973a2bab69dd</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_distrib1_coddistrib1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_distrib2_coddistrib2</obj_name>
  <obj_hashval>05b4d455efbccc7abd327428c62c1590</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_distrib2_coddistrib2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_distrib3_coddistrib3</obj_name>
  <obj_hashval>4405c7b0f24825634be497c7b5efc21a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_distrib3_coddistrib3 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_distribchelt_coddc</obj_name>
  <obj_hashval>0dd51b8d61bbc66f3d6124c4a1a84984</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_distribchelt_coddc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_distribchelt1_coddc1</obj_name>
  <obj_hashval>a4993b7b7191165139c0d1a1f041e1ca</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_distribchelt1_coddc1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_distribchelt2_coddc2</obj_name>
  <obj_hashval>eb2bf8c6b13bb3910919fa5e928b5935</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_distribchelt2_coddc2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_doccarnete_codcarnet</obj_name>
  <obj_hashval>ce20ea9e3e27745139ffca0ebce292d1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_doccarnete_codcarnet INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 135 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_doceditat_coddoceditat</obj_name>
  <obj_hashval>54fdbf06148625bca9478c02901d50b4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_doceditat_coddoceditat INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_docfree_coddocfree</obj_name>
  <obj_hashval>1059c2d93e316736674abef6b379060e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_docfree_coddocfree INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 135 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_doclink_coddoclink</obj_name>
  <obj_hashval>d6f55e43f0e05a82efe0262839901966</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_doclink_coddoclink INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 139 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_doclock_coddoclock</obj_name>
  <obj_hashval>ecdbfe6d665d64aac6fee432a69eb92f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_doclock_coddoclock INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_docsuplim_coddocsuplim</obj_name>
  <obj_hashval>5b2d8bec24a10cb93816676156335a93</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_docsuplim_coddocsuplim INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_docsuplim1_coddocsuplim1</obj_name>
  <obj_hashval>337af44c2aa90f5e3a5ba34565b591ce</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_docsuplim1_coddocsuplim1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_documente_coddocument</obj_name>
  <obj_hashval>e1da7b27948286020cbaf8403409e0c4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_documente_coddocument INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_docusers_coddocusers</obj_name>
  <obj_hashval>5ed6bb66d2a098f439a6ed671af61858</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_docusers_coddocusers INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 126 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_domeniiact_coddomeniuact</obj_name>
  <obj_hashval>c24ff3eda2b2e749f67cd0f9f2ccbec5</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_domeniiact_coddomeniuact INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_dosare_coddosar</obj_name>
  <obj_hashval>bae86f5ee8298b632c72a2cf4d65d3cc</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_dosare_coddosar INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 402 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_dpp_coddifpretprod</obj_name>
  <obj_hashval>e10158f6c5e9f994c5f647416d058d8b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_dpp_coddifpretprod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 117 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_dpp1_coddifpretprod1</obj_name>
  <obj_hashval>98ab3018b9a1f1b013b10300537ad225</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_dpp1_coddifpretprod1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 117 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_dprofit_coddprofit</obj_name>
  <obj_hashval>293a961193416ba20f4a36615f1f73d7</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_dprofit_coddprofit INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_dprofitc_coddprofitc</obj_name>
  <obj_hashval>aeeda20871e47f2f37530d808ced9e12</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_dprofitc_coddprofitc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_dprofitv_coddprofitv</obj_name>
  <obj_hashval>39dc5ce063748d33d4b20ec401786f9b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_dprofitv_coddprofitv INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_dvi_coddvi</obj_name>
  <obj_hashval>f11c248b3f939d7e0c0f0f9bacf5a910</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_dvi_coddvi INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_dvi1_coddvi1</obj_name>
  <obj_hashval>8b303cf442f69e6215431349db963966</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_dvi1_coddvi1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_efact_custom_codefactc</obj_name>
  <obj_hashval>39f7590e917e7ba2605556ab7753fc15</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_efact_custom_codefactc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_efcustom_codefcustom</obj_name>
  <obj_hashval>35fc580ffde19b218865c4e2d2540758</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_efcustom_codefcustom INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_elembuget_codelembuget</obj_name>
  <obj_hashval>215ddf52daeb44e7b2e1e3a0186de57f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_elembuget_codelembuget INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_elembuget1_codelembuget1</obj_name>
  <obj_hashval>93038715313e2b3dbf1e945de305f3d4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_elembuget1_codelembuget1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_elembuget2_codelembuget2</obj_name>
  <obj_hashval>748d811648af4c0ec35d4c67c82af075</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_elembuget2_codelembuget2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_elemente_codelement</obj_name>
  <obj_hashval>c14b035a02051b7c3dc815d5fb568e0e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_elemente_codelement INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_elementea_codelementa</obj_name>
  <obj_hashval>51ca0e9e3da12a6fb5e33a96b59f7070</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_elementea_codelementa INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_elementec_codelementc</obj_name>
  <obj_hashval>b1f49921e487d97b191ada4148b5dd29</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_elementec_codelementc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_elementem_codelementm</obj_name>
  <obj_hashval>004fb194a97ab0ec94c125db1076c68c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_elementem_codelementm INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_emulare_bonid</obj_name>
  <obj_hashval>a1def752123d70fa88cddfc39fa9922e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_emulare_bonid INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_emulare_codemulare</obj_name>
  <obj_hashval>c5768bbd8acfa2f921222136f51b1f1c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_emulare_codemulare INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>utilaje</obj_name>
  <obj_hashval>a1139117118f8b4e821542117dd6156a</obj_hashval>
  <obj_text>CREATE TABLE utilaje (
  "codutilaj" numeric(20,0) NOT NULL,
  "codobiect" numeric(20,0),
  "nrinventar" numeric(20,0),
  "eticheta" character varying(50),
  "tiputilaj" character varying(50),
  "flota" character varying(50),
  "model" character varying(50),
  "anf" numeric(4,0),
  "serief" character varying(50),
  "incarcare" numeric(10,0),
  "datagarantie" date,
  "ingarantie" numeric(1,0),
  "lungime" numeric(20,7),
  "latime" numeric(20,7),
  "inaltime" numeric(20,7),
  "obs" character varying(300),
  "inactiv" numeric(1,0),
  "corectieindex" numeric(10,0),
  "um" numeric(20,0),
  "plafoncantf" numeric(20,7),
  "codgest" numeric(20,0),
  "codpart" numeric(20,0),
  "codies1" numeric(20,0),
  "datagarantiei" date,
  "aprobat" numeric(1,0),
  "datastart" date,
  "nrcontr" character varying(50),
  "datacontr" date,
  "codfurnizor" numeric(20,0),
  "doc" character varying(50),
  "tip" numeric(5,0),
  "codlocalit" numeric(20,0),
  "adresa" character varying(250),
  "hfactor" numeric(2,0),
  "agent" numeric(20,0),
  "codproducator" numeric(20,0),
  "codlocatie" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>utilaje1</obj_name>
  <obj_hashval>7427800983ccfadeec983f7740990204</obj_hashval>
  <obj_text>CREATE TABLE utilaje1 (
  "codutilaj1" numeric(20,0) NOT NULL,
  "codutilaj" numeric(20,0),
  "nrcontr" character varying(20),
  "carnetcontr" character varying(20),
  "status_part" numeric(1,0),
  "status_depo" numeric(1,0),
  "codpart" numeric(20,0),
  "codlocatie" numeric(20,0),
  "data" date,
  "userid" numeric(20,0),
  "datacreare" date,
  "obs" character varying(200),
  "status_service" numeric(1,0),
  "indexlocal" numeric(10,0),
  "codpers" numeric(20,0),
  "estetic" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>utilaje2</obj_name>
  <obj_hashval>a92753a56e766ab87c0ee7e94d49f682</obj_hashval>
  <obj_text>CREATE TABLE utilaje2 (
  "codutilaj2" numeric(20,0) NOT NULL,
  "codutilaj" numeric(20,0),
  "interventie" numeric(20,0),
  "codcomanda1" numeric(20,0),
  "codutilaj20" numeric(20,0),
  "codauto" numeric(20,0),
  "kmparcursi" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>utilaje20</obj_name>
  <obj_hashval>40e07cb84115e1bf467bffeb38ed4735</obj_hashval>
  <obj_text>CREATE TABLE utilaje20 (
  "codutilaj20" numeric(20,0) NOT NULL,
  "codutilaj" numeric(20,0),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "descriere" character varying(2500),
  "stare" numeric(5,0),
  "operator" numeric(20,0),
  "obs" character varying(500),
  "codies" numeric(20,0),
  "codlocalit" numeric(20,0),
  "adresa" character varying(250),
  "codpersc" numeric(20,0),
  "callcenter" numeric(1,0),
  "codbc" numeric(20,0),
  "prioritate" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_emulare1_codemulare1</obj_name>
  <obj_hashval>b322aa44abe8da9c316f636f8dfadc83</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_emulare1_codemulare1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_emulare2_codemulare2</obj_name>
  <obj_hashval>dc2d519a419db810662600d85cc278b4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_emulare2_codemulare2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>utilaje20_mon</obj_name>
  <obj_hashval>6b82d65596eab131c5ee0883ebd70324</obj_hashval>
  <obj_text>CREATE TABLE utilaje20_mon (
  "codutilaj20" numeric(20,0),
  "codutilaj" numeric(20,0),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "descriere" character varying(2500),
  "stare" numeric(5,0),
  "operator" numeric(20,0),
  "obs" character varying(500),
  "codies" numeric(20,0),
  "codlocalit" numeric(20,0),
  "adresa" character varying(250),
  "denoperator" character varying(50),
  "facturare" character varying(50),
  "deviz" numeric(1,0),
  "datamodif" date,
  "codbc" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>utilaje2c</obj_name>
  <obj_hashval>db3b35280175dc8d7dce20f26b6326b8</obj_hashval>
  <obj_text>CREATE TABLE utilaje2c (
  "codutilaj2c" numeric(20,0) NOT NULL,
  "codutilaj2" numeric(20,0),
  "codutilaj" numeric(20,0),
  "indexc" numeric(10,0),
  "dataindexc" date,
  "codcomanda1" numeric(20,0),
  "explicatii" text,
  "datastart" timestamp(6) without time zone,
  "dataend" timestamp(6) without time zone,
  "indexv" numeric(10,0),
  "datav" date,
  "resetat" numeric(1,0),
  "indexlocal" numeric(10,0),
  "orestart" numeric(7,3),
  "orestop" numeric(7,3)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>utilaje2p</obj_name>
  <obj_hashval>d7ee9f3976c9dce869272fc75eb81c12</obj_hashval>
  <obj_text>CREATE TABLE utilaje2p (
  "codutilaj2p" numeric(20,0) NOT NULL,
  "codutilaj2" numeric(20,0),
  "codutilaj" numeric(20,0),
  "codpers" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_emulpuncteused_cod</obj_name>
  <obj_hashval>ade4b0271ef35ede664af4e31a768217</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_emulpuncteused_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_emulstingeri_cod</obj_name>
  <obj_hashval>22437d8a86f665da7676f71a6cd3ada9</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_emulstingeri_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_estimarinod_codestimarenod</obj_name>
  <obj_hashval>6b9802631769204c6f760d15aeb492bf</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_estimarinod_codestimarenod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>utilaje3</obj_name>
  <obj_hashval>0214840606f68eb5332cc2c8569f3f18</obj_hashval>
  <obj_text>CREATE TABLE utilaje3 (
  "codutilaj3" numeric(20,0) NOT NULL,
  "codutilaj" numeric(20,0),
  "databord" date,
  "indexbord" numeric(20,7),
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "corectieindex" numeric(10,0),
  "tip_index" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>utilajedev</obj_name>
  <obj_hashval>2b54468bdb43792926d67a8637d93444</obj_hashval>
  <obj_text>CREATE TABLE utilajedev (
  "codutilajdev" numeric(20,0) NOT NULL,
  "codutilaj" numeric(20,0),
  "codutilaj20" numeric(20,0),
  "codobiect" numeric(20,0),
  "cant" numeric(20,7),
  "pret" numeric(20,7),
  "cantfact" numeric(20,7),
  "facturabil" numeric(1,0),
  "codies1" numeric(20,0),
  "codutilaj2" numeric(20,0),
  "tiplivrare" numeric(20,0),
  "tva" numeric(20,7),
  "consumabil" numeric(1,0),
  "cantcons" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_estimariprod_codestprod</obj_name>
  <obj_hashval>d97384251edfca06778f59aa5dc1bb19</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_estimariprod_codestprod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_estimariprod1_codestprod1</obj_name>
  <obj_hashval>25f475560b86b38b0570084f841c72f7</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_estimariprod1_codestprod1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_estprod1m_codestprod1m</obj_name>
  <obj_hashval>6b82a989fb54b12e7522e155b74d2a5a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_estprod1m_codestprod1m INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>utilajemon</obj_name>
  <obj_hashval>8c05ca157937b0f94dd315229bf83d4d</obj_hashval>
  <obj_text>CREATE TABLE utilajemon (
  "codmonitorizare" numeric(20,0) NOT NULL,
  "codutilaj20" numeric(20,0),
  "userid" numeric(20,0),
  "datamodif" timestamp(6) without time zone,
  "starev" numeric(5,0),
  "staren" numeric(5,0),
  "tipmodif" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>utilajetipindex</obj_name>
  <obj_hashval>bdf5358230c0b30c001046cd42b57f16</obj_hashval>
  <obj_text>CREATE TABLE utilajetipindex (
  "codtindex" numeric(20,0) NOT NULL,
  "codutilaj" numeric(20,0),
  "tip_index" numeric(1,0),
  "denumire" character varying(100),
  "um" numeric(20,0),
  "plafoncantf" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>valatrexceptii</obj_name>
  <obj_hashval>f30677cab01a9fd5cfa91ee378be793d</obj_hashval>
  <obj_text>CREATE TABLE valatrexceptii (
  "codexceptie" numeric(20,0),
  "codvalatr" numeric(20,0),
  "codarticol" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>vanzari</obj_name>
  <obj_hashval>4678f12ee61865289096c61124e54f54</obj_hashval>
  <obj_text>CREATE TABLE vanzari (
  "codvanzare" numeric(20,0),
  "codpart" numeric(20,0),
  "datadoc" timestamp(6) without time zone,
  "valdoc" numeric(20,7),
  "tvadoc" numeric(20,7),
  "valdiscount" numeric(20,7),
  "tvadiscount" numeric(20,7),
  "codemulare" numeric(20,0),
  "codemularefact" numeric(20,0),
  "obs" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>variabile_sesiune</obj_name>
  <obj_hashval>3bc693cd47de354d9b25da45e5c2b93a</obj_hashval>
  <obj_text>CREATE TABLE variabile_sesiune (
  "codjob1" numeric(20,0),
  "sql_exec" character varying(4000),
  "tip_sql" numeric(1,0),
  "ordine" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>version</obj_name>
  <obj_hashval>4a99ea99a3660d0a2ff05735d8163c8f</obj_hashval>
  <obj_text>CREATE TABLE version (
  "version" numeric(10,8) NOT NULL,
  "jobok" numeric(1,0),
  "minretail" numeric(10,8),
  "minrestaurant" numeric(10,8)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>view_joins</obj_name>
  <obj_hashval>0dd668126048c02275d93462490258b4</obj_hashval>
  <obj_text>CREATE TABLE view_joins (
  "codview_joins" numeric(20,0) NOT NULL,
  "viewname" character varying(50),
  "joinuri" character varying(3000)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>voucher</obj_name>
  <obj_hashval>be1e2862543c3c95d210739bdb8dbeb6</obj_hashval>
  <obj_text>CREATE TABLE voucher (
  "codvoucher" numeric(20,0) NOT NULL,
  "codpartener" numeric(20,0),
  "obs" character varying(100),
  "datastart" timestamp(0) without time zone,
  "datastop" timestamp(0) without time zone,
  "moneda" numeric(20,0),
  "valoare" numeric(20,7),
  "codcmd" numeric(20,0),
  "codies" numeric(20,0),
  "codgest" numeric(20,0),
  "obs1" character varying(500)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>vouchercadou</obj_name>
  <obj_hashval>f65edc91e8dc04249a440d5dd9a6b3bf</obj_hashval>
  <obj_text>CREATE TABLE vouchercadou (
  "cod" numeric(20,0) NOT NULL,
  "barcode" character varying(50),
  "valoare" numeric(20,7),
  "datastart" timestamp(6) without time zone,
  "datastop" timestamp(6) without time zone,
  "is_used" numeric(1,0),
  "used_date" timestamp(6) without time zone
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>vouchercadoulink</obj_name>
  <obj_hashval>5a192b1dec540f7a1cc8bc442ded5b75</obj_hashval>
  <obj_text>CREATE TABLE vouchercadoulink (
  "cod" numeric(20,0) NOT NULL,
  "tipdoc" numeric(5,0),
  "coddoc" numeric(20,0),
  "tipoperatie" numeric(1,0),
  "barcode" character varying(50),
  "valoare" numeric(20,7),
  "datastart" timestamp(6) without time zone,
  "datastop" timestamp(6) without time zone,
  "zilevalabil" numeric(5,0),
  "codobiect" numeric(20,0),
  "postat" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>voucherlink</obj_name>
  <obj_hashval>5575217e2bc4df2fba5469ab1aeb1c62</obj_hashval>
  <obj_text>CREATE TABLE voucherlink (
  "codvlink" numeric(20,0) NOT NULL,
  "codvoucher" numeric(20,0) NOT NULL,
  "codcmd" numeric(20,0),
  "codies" numeric(20,0),
  "valoare" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>weekcashflow</obj_name>
  <obj_hashval>9f9e867570a7fb9ff7017a9eeb646a0c</obj_hashval>
  <obj_text>CREATE TABLE weekcashflow (
  "codcashflow" numeric(20,0) NOT NULL,
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "saptamana" numeric(2,0),
  "subunitatea" numeric(20,0),
  "tip" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_estprod1n_codestprod1n</obj_name>
  <obj_hashval>c5003e2da76b46124f08b17e99b7f377</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_estprod1n_codestprod1n INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_etichcolet_cod</obj_name>
  <obj_hashval>c8f3bc55375e29c463be59a3e601fef3</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_etichcolet_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>weekcashflow1</obj_name>
  <obj_hashval>799bf28273eb4c0da322bc52c9cc2af9</obj_hashval>
  <obj_text>CREATE TABLE weekcashflow1 (
  "codcashflow1" numeric(20,0) NOT NULL,
  "codcashflow" numeric(20,0),
  "indextiplinie" character varying(10),
  "indexlocal" character varying(10),
  "indexsecundar" character varying(10),
  "titlu" character varying(10),
  "denumire" character varying(100),
  "simbolcont" character varying(100),
  "valoare" numeric(20,7),
  "restante" numeric(20,7),
  "vizibil" numeric(1,0),
  "codpart" numeric(20,0),
  "headerfooter" numeric(1,0),
  "aredetalii" numeric(1,0),
  "detaliu" numeric(1,0),
  "expandat" numeric(1,0),
  "estetotal" numeric(1,0),
  "editabil" numeric(1,0),
  "obs" character varying(50),
  "week1" numeric(20,7),
  "week2" numeric(20,7),
  "week3" numeric(20,7),
  "week4" numeric(20,7),
  "week5" numeric(20,7),
  "week6" numeric(20,7),
  "week7" numeric(20,7),
  "week8" numeric(20,7),
  "week9" numeric(20,7),
  "week10" numeric(20,7),
  "week11" numeric(20,7),
  "week12" numeric(20,7),
  "week13" numeric(20,7),
  "week14" numeric(20,7),
  "week15" numeric(20,7),
  "week16" numeric(20,7),
  "week17" numeric(20,7),
  "week18" numeric(20,7),
  "week19" numeric(20,7),
  "week20" numeric(20,7),
  "week21" numeric(20,7),
  "week22" numeric(20,7),
  "week23" numeric(20,7),
  "week24" numeric(20,7),
  "week25" numeric(20,7),
  "week26" numeric(20,7),
  "week27" numeric(20,7),
  "week28" numeric(20,7),
  "week29" numeric(20,7),
  "week30" numeric(20,7),
  "week31" numeric(20,7),
  "week32" numeric(20,7),
  "week33" numeric(20,7),
  "week34" numeric(20,7),
  "week35" numeric(20,7),
  "week36" numeric(20,7),
  "week37" numeric(20,7),
  "week38" numeric(20,7),
  "week39" numeric(20,7),
  "week40" numeric(20,7),
  "week41" numeric(20,7),
  "week42" numeric(20,7),
  "week43" numeric(20,7),
  "week44" numeric(20,7),
  "week45" numeric(20,7),
  "week46" numeric(20,7),
  "week47" numeric(20,7),
  "week48" numeric(20,7),
  "week49" numeric(20,7),
  "week50" numeric(20,7),
  "week51" numeric(20,7),
  "week52" numeric(20,7),
  "peste52" numeric(20,7),
  "coddoc" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_euro_cod</obj_name>
  <obj_hashval>18669fa4bea05bd4a04debdff46b8fb3</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_euro_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_evals_codevals</obj_name>
  <obj_hashval>205b761b377558e41943461b99a8e338</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_evals_codevals INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>weekcashplati</obj_name>
  <obj_hashval>7f00849d4784476c9b6cdbaf02d01036</obj_hashval>
  <obj_text>CREATE TABLE weekcashplati (
  "codcashplati" numeric(20,0),
  "codcashflow1" numeric(20,0),
  "codobligpif" numeric(20,0),
  "dataplata" date,
  "sumaplata" numeric(20,7),
  "prefixdoc" character varying(2),
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "termenoblig" date,
  "restoblig" numeric(20,7),
  "coddoc" numeric(20,0),
  "tipdoc" numeric(5,0),
  "codbankcont" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>weekcashsold</obj_name>
  <obj_hashval>e9f24bbf6a75a0302ce98147310d8de7</obj_hashval>
  <obj_text>CREATE TABLE weekcashsold (
  "codsold" numeric(20,0),
  "codcashflow" numeric(20,0),
  "codbankcont" numeric(20,0),
  "sold" numeric(20,7),
  "plati" numeric(20,7),
  "rest" numeric(20,7),
  "codlimcredit" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>wm_col_tmp</obj_name>
  <obj_hashval>35e926a602f64c3aaffc7388dca48b80</obj_hashval>
  <obj_text>CREATE TABLE wm_col_tmp (
  "tmp_name" character varying(30) NOT NULL,
  "col_ord" numeric(5,0) NOT NULL,
  "col_def" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>wm_flag_tmp</obj_name>
  <obj_hashval>8c4060a6606341661f6d755740af176a</obj_hashval>
  <obj_text>CREATE TABLE wm_flag_tmp (
  "tmp_name" character varying(30),
  "flag" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>wm_idx_tmp</obj_name>
  <obj_hashval>93ce102ff2e61c3a4b056474391238c3</obj_hashval>
  <obj_text>CREATE TABLE wm_idx_tmp (
  "tmp_name" character varying(30) NOT NULL,
  "idx_def" text
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>wm_view_tmp</obj_name>
  <obj_hashval>513eccb0e20427d0e2612f946c0161f5</obj_hashval>
  <obj_text>CREATE TABLE wm_view_tmp (
  "v_name" character varying(30) NOT NULL,
  "v_def" text,
  "v_nivel" numeric(5,0),
  "v_valid" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>wme_flags</obj_name>
  <obj_hashval>85c218b2f2cdfd004006febad05f678f</obj_hashval>
  <obj_text>CREATE TABLE wme_flags (
  "spv_efact_readall" numeric(1,0),
  "cif" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>xxx</obj_name>
  <obj_hashval>6fe9e529c7d98a32bae658fccb0899ad</obj_hashval>
  <obj_text>CREATE TABLE xxx (
  "xxx" character varying(1)
);</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_evalsev_codevalsev</obj_name>
  <obj_hashval>d9da99f651adf928aac67e303891f5ca</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_evalsev_codevalsev INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_evalstes_codevalstes</obj_name>
  <obj_hashval>bcfa6bff6912b5a6b3935058b54db708</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_evalstes_codevalstes INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_evaluari_codevaluare</obj_name>
  <obj_hashval>19605bf50cc02846f054efb7c030ee0f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_evaluari_codevaluare INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 267 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>zeuro</obj_name>
  <obj_hashval>ae2b3f3fd9eb848ee000da665d345e10</obj_hashval>
  <obj_text>CREATE TABLE zeuro (
  "cod" numeric(20,0) NOT NULL,
  "codcasa" numeric(20,0),
  "plu" numeric(20,7),
  "dep" numeric(10,0),
  "obiect" numeric(20,0),
  "gestiune" numeric(20,0),
  "cont" numeric(20,0),
  "tva" numeric(20,7),
  "pret" numeric(20,7),
  "stoc" numeric(20,7),
  "vandut" numeric(20,7),
  "codmonetar" numeric(20,0),
  "z" numeric(20,0),
  "dataz" date
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>zineluc</obj_name>
  <obj_hashval>25151204227a4b4ecc4276d958e5d2f0</obj_hashval>
  <obj_text>CREATE TABLE zineluc (
  "codzineluc" numeric(20,0) NOT NULL,
  "an" numeric(4,0),
  "luna" numeric(2,0),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>zineluc1</obj_name>
  <obj_hashval>8a8f557c9562a3b1a1dd55d6f49744e7</obj_hashval>
  <obj_text>CREATE TABLE zineluc1 (
  "codzineluc1" numeric(20,0) NOT NULL,
  "codzineluc" numeric(20,0),
  "zi" numeric(2,0),
  "data" date
);</obj_text>
</row>

<row>
  <obj_type>CONSTRAINT</obj_type>
  <obj_name>pk_inactivretail</obj_name>
  <obj_reftable>inactivretail</obj_reftable>
  <obj_hashval>a0953e2f1b2d1e066cad292ecc1b428f</obj_hashval>
  <obj_text>ALTER TABLE inactivretail ADD CONSTRAINT pk_inactivretail PRIMARY KEY (codinactivretail)</obj_text>
  <obj_nivel>1</obj_nivel>
</row>

<row>
  <obj_type>CONSTRAINT</obj_type>
  <obj_name>pk_mpbcar</obj_name>
  <obj_reftable>mpbcar</obj_reftable>
  <obj_hashval>82001b8e8525980c8aaafbfc74b931d5</obj_hashval>
  <obj_text>ALTER TABLE mpbcar ADD CONSTRAINT pk_mpbcar PRIMARY KEY (codmpbcar)</obj_text>
  <obj_nivel>1</obj_nivel>
</row>

<row>
  <obj_type>CONSTRAINT</obj_type>
  <obj_name>pk_mpbcar1</obj_name>
  <obj_reftable>mpbcar1</obj_reftable>
  <obj_hashval>bc1a3d0b08fed2b769b2ffce2a56b794</obj_hashval>
  <obj_text>ALTER TABLE mpbcar1 ADD CONSTRAINT pk_mpbcar1 PRIMARY KEY (codmpbcar1)</obj_text>
  <obj_nivel>1</obj_nivel>
</row>

<row>
  <obj_type>CONSTRAINT</obj_type>
  <obj_name>pk_mpbcar2</obj_name>
  <obj_reftable>mpbcar2</obj_reftable>
  <obj_hashval>e707cefac6edb8210521fae8b0697665</obj_hashval>
  <obj_text>ALTER TABLE mpbcar2 ADD CONSTRAINT pk_mpbcar2 PRIMARY KEY (codmpbcar2)</obj_text>
  <obj_nivel>1</obj_nivel>
</row>

<row>
  <obj_type>CONSTRAINT</obj_type>
  <obj_name>pk_ncasemarcat</obj_name>
  <obj_reftable>ncasemarcat</obj_reftable>
  <obj_hashval>dc7a4f0759dbbef55f627e4501244558</obj_hashval>
  <obj_text>ALTER TABLE ncasemarcat ADD CONSTRAINT pk_ncasemarcat PRIMARY KEY (codcasemarcat)</obj_text>
  <obj_nivel>1</obj_nivel>
</row>

<row>
  <obj_type>CONSTRAINT</obj_type>
  <obj_name>pk_pretm_autoupd_log</obj_name>
  <obj_reftable>pretm_autoupd_log</obj_reftable>
  <obj_hashval>29ab05a19dcb347cccc6c533c2d39f01</obj_hashval>
  <obj_text>ALTER TABLE pretm_autoupd_log ADD CONSTRAINT pk_pretm_autoupd_log PRIMARY KEY (cod_moneda, cod_banca, run_date)</obj_text>
  <obj_nivel>1</obj_nivel>
</row>

<row>
  <obj_type>CONSTRAINT</obj_type>
  <obj_name>pk_syncpretretail</obj_name>
  <obj_reftable>syncpretretail</obj_reftable>
  <obj_hashval>562f3068f8a6993dbba55090d1f99693</obj_hashval>
  <obj_text>ALTER TABLE syncpretretail ADD CONSTRAINT pk_syncpretretail PRIMARY KEY (codsync)</obj_text>
  <obj_nivel>1</obj_nivel>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_evaluatori_codevaluator</obj_name>
  <obj_hashval>53aa87d2a6ede22946d6db46aef73721</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_evaluatori_codevaluator INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 135 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_expert_codexpert</obj_name>
  <obj_hashval>5712f8521b3a65563ca2013ad42f0cc3</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_expert_codexpert INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_expert1_codexpert1</obj_name>
  <obj_hashval>13fce1c8d6b5012f6c1857aa97d817d9</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_expert1_codexpert1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_faz_codfaz</obj_name>
  <obj_hashval>da94eb6249a4aefd8bdb900bf8c632d3</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_faz_codfaz INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_faz0_codfaz0</obj_name>
  <obj_hashval>a117bbc6df61b39d946796b421066805</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_faz0_codfaz0 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_faz1_codfaz1</obj_name>
  <obj_hashval>3185c22c34b2f2961fd89016c2ed8dfa</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_faz1_codfaz1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_faz2_codfaz2</obj_name>
  <obj_hashval>757fae34337acec858d7b331ffd72820</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_faz2_codfaz2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_faz3_codfaz3</obj_name>
  <obj_hashval>388b1fd77e4849f2145056d910be5641</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_faz3_codfaz3 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_fazintr_codfazintr</obj_name>
  <obj_hashval>dd3c236b8d12879fe1dd428e40e51211</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_fazintr_codfazintr INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_firmecuplate_cod</obj_name>
  <obj_hashval>647d601cee22e1bce4a417a0d4f71eb0</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_firmecuplate_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_fisaevalp_codfisa</obj_name>
  <obj_hashval>b556b5d78c502daabd52ef56cdcb0ce0</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_fisaevalp_codfisa INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 285 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_fisaevalt_codfisa</obj_name>
  <obj_hashval>8e74d01229aa7b2cdd61a2e0ee163176</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_fisaevalt_codfisa INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 182 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_fisainf_codfisainf</obj_name>
  <obj_hashval>2d80cb461e17ce4ee9af500d6b5c175d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_fisainf_codfisainf INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_fisaman_codfisaman</obj_name>
  <obj_hashval>1886db1cace2e00c454274174e5576c7</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_fisaman_codfisaman INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_fisamand_codfisamand</obj_name>
  <obj_hashval>af06f7682b7f431b1ebde48552bc9d0e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_fisamand_codfisamand INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_fisamas_codfisamas</obj_name>
  <obj_hashval>48d48ae28c5bb50a0956964bd52e7c53</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_fisamas_codfisamas INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_fisamas1_codfisamas1</obj_name>
  <obj_hashval>5e7807df9d2132cee87e16d0a7fe5c7e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_fisamas1_codfisamas1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_fisamf_codfisamf</obj_name>
  <obj_hashval>ae72d90ca3639bf206888a2f13a78f7f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_fisamf_codfisamf INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_fisarez_codfisarez</obj_name>
  <obj_hashval>36c19754974007b08912574a88286eb6</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_fisarez_codfisarez INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_fisasdv_codfisasdv</obj_name>
  <obj_hashval>3955105a0efb5ea57b539977b132fdb1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_fisasdv_codfisasdv INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_fisasup_codfisasup</obj_name>
  <obj_hashval>d3a95f351a46794d8ed116446c99c142</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_fisasup_codfisasup INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_fisateh_codfisateh</obj_name>
  <obj_hashval>d41f669043fba76035f3c9cb1fcdaf72</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_fisateh_codfisateh INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_formatii_codformatie</obj_name>
  <obj_hashval>ea1e7fac76da14b3b43fa1a36bd11b00</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_formatii_codformatie INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_formatii1_codformatie1</obj_name>
  <obj_hashval>6af3804abeeee93f6c671e1b70680e2d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_formatii1_codformatie1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_formatori_codformator</obj_name>
  <obj_hashval>bca4c21ec05ac6b60cf993211bc359b0</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_formatori_codformator INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_functii_codfunctie</obj_name>
  <obj_hashval>ca983d718d47aaf887cadb1acb3c59fb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_functii_codfunctie INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 107 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_functii1_codfunctie1</obj_name>
  <obj_hashval>efce14096f4dbced888adc9851727db6</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_functii1_codfunctie1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 112 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_gantt</obj_name>
  <obj_hashval>8aee19253305af07d3e06894ffe57f83</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_gantt INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 221 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_gantt1</obj_name>
  <obj_hashval>aca53fac05a9524c9b75784e42aa7f0e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_gantt1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 3776 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_general_codgeneral</obj_name>
  <obj_hashval>7e67877c663f639cdc154d22dcb63d29</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_general_codgeneral INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_grechiv_codgrechiv</obj_name>
  <obj_hashval>b2263805b968e9bfbbeb735973bb5d4e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_grechiv_codgrechiv INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_grupedrum_codgrupa</obj_name>
  <obj_hashval>e1765445664b5fb16d73148206e40f79</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_grupedrum_codgrupa INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 123 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_idcantar</obj_name>
  <obj_hashval>5f97099f012af5de3e43a1cc7b1e650a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_idcantar INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_identevals_codidentevals</obj_name>
  <obj_hashval>d26e0d0ad04c5e1040e5e5fe67f5e831</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_identevals_codidentevals INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_idsediulock_cod</obj_name>
  <obj_hashval>d38925132bc250e9558ec4eb89bfaf7b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_idsediulock_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_iesdisc_codiesdisc</obj_name>
  <obj_hashval>60c7d922da05b96ff7129b22705c8fba</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_iesdisc_codiesdisc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_iesiri_codies</obj_name>
  <obj_hashval>c53c229bb1ad678d2f60ab3fa33e60a9</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_iesiri_codies INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_iesiri1_codies1</obj_name>
  <obj_hashval>432e324349454dd47807567c66959eb5</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_iesiri1_codies1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_iesiri1r_codies1r</obj_name>
  <obj_hashval>0f53308339bce3121e8d2ed9ab68bb74</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_iesiri1r_codies1r INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_iesirir_codiesr</obj_name>
  <obj_hashval>df760f6ce8e7495a4ce09efe079537e6</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_iesirir_codiesr INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_iespuncte_codiespuncte</obj_name>
  <obj_hashval>03359a8f5bb7eb22429ed34230f910d8</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_iespuncte_codiespuncte INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_imbmifixlink_codimbmf</obj_name>
  <obj_hashval>50dc1771c09fbc9658df3f812405a7f7</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_imbmifixlink_codimbmf INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_inactivretail_codinactiv</obj_name>
  <obj_hashval>d40c13e6a04dcc8899b50610c37c42cd</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_inactivretail_codinactiv INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_interfataklg_cod</obj_name>
  <obj_hashval>2aec3e44c0e15a8e5d8fa9ad9e0ae3e7</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_interfataklg_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_intrari_codintr</obj_name>
  <obj_hashval>76447f3343776139b497f73aefe13d94</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_intrari_codintr INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_intrari1_codintr1</obj_name>
  <obj_hashval>38d5cafe50900e9755e977fcda7a0f4e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_intrari1_codintr1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_intrdoctransp_cod</obj_name>
  <obj_hashval>0ae08d44c04c9263841dcba0e9096ffa</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_intrdoctransp_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_inventar_codinventar</obj_name>
  <obj_hashval>74bb68dca751bc1e87fd5ce4c2be3815</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_inventar_codinventar INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_inventar1_codinventar1</obj_name>
  <obj_hashval>da7e0cdd51c0fdff494cd3235dc12614</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_inventar1_codinventar1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_inventclase_codinventclase</obj_name>
  <obj_hashval>05bc515e83b2430a9d5ee237c0fbbbf2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_inventclase_codinventclase INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_inventclases_codinvclases</obj_name>
  <obj_hashval>66d70dbb4dda97121f76f293ef54ff23</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_inventclases_codinvclases INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_inventcont_codinventcont</obj_name>
  <obj_hashval>1b25d5f652d32459d61db9b179685dea</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_inventcont_codinventcont INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_inventloc_codinventloc</obj_name>
  <obj_hashval>2455036fb42fe73fe34f6e412f093dc4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_inventloc_codinventloc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_inventprod_codinventprod</obj_name>
  <obj_hashval>91664a8c78f11af6ad94a95cb72c82ed</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_inventprod_codinventprod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_inventrez_codrezolvare</obj_name>
  <obj_hashval>2057d957365596cb4456e74d84efb21c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_inventrez_codrezolvare INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_inventstoc_codinventstoc</obj_name>
  <obj_hashval>a735e5f138228d0987c19089116c63f1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_inventstoc_codinventstoc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ioart_codioart</obj_name>
  <obj_hashval>d5e3c2fa2e916b734e643678a554abd9</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ioart_codioart INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 134 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ioart1_codioart1</obj_name>
  <obj_hashval>d5eab3c31b2c4380de516dbfe23a681e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ioart1_codioart1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 133 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ioartlink_codioartlink</obj_name>
  <obj_hashval>18f305460619b38b21df014e320a68de</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ioartlink_codioartlink INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_iobank_codiobank</obj_name>
  <obj_hashval>b35bf7b13c5305f518e4286eb3696874</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_iobank_codiobank INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 116 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_iobank1_codiobank1</obj_name>
  <obj_hashval>36ca98ec478ec82accae8cd646453d6c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_iobank1_codiobank1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 108 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_iofilial_codiofilial</obj_name>
  <obj_hashval>d086199bc5fd076f42995cc52c8c9ff3</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_iofilial_codiofilial INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_iofilial1_codiofilial1</obj_name>
  <obj_hashval>38c476cfdaca2c26e911a7dfb5b15c86</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_iofilial1_codiofilial1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_iopart_codiopart</obj_name>
  <obj_hashval>d04ecdcb512e1fb663a9065ac09fba29</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_iopart_codiopart INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_iopart1_codiopart1</obj_name>
  <obj_hashval>7333e70c2d28ed3505214945798515ac</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_iopart1_codiopart1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 105 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_iopers_codiopers</obj_name>
  <obj_hashval>822d296405b5bf9ea9ab17f417b0b986</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_iopers_codiopers INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_iopers1_codiopers1</obj_name>
  <obj_hashval>f2a1b6ba05c2e5a748734f760fe15beb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_iopers1_codiopers1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_job_listconfig_codj</obj_name>
  <obj_hashval>10b6a5dad1ff443b7bec81090c274380</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_job_listconfig_codj INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_job_liste_tableid</obj_name>
  <obj_hashval>08f7250fff36ffb98d776e4d9bdce366</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_job_liste_tableid INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_jobcorel_codcorel</obj_name>
  <obj_hashval>1f95efd51cd7e64a8994c17ba5f1927b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_jobcorel_codcorel INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 432 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_jobcorelrez_codcorelrez</obj_name>
  <obj_hashval>cbc71550cebf871d553505f813b90fef</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_jobcorelrez_codcorelrez INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_jobliste_codjob</obj_name>
  <obj_hashval>a9fcaf079be2c92ea1fc4299ea13fc63</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_jobliste_codjob INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 122 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_jobliste1_codjob1</obj_name>
  <obj_hashval>49a2d5c7d56dde3cfa569c3820b11285</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_jobliste1_codjob1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 122 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_joblistefin_codjoblistefin</obj_name>
  <obj_hashval>d8a2c21c2d5ac395f495bae22fba5a8c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_joblistefin_codjoblistefin INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_jobunic</obj_name>
  <obj_hashval>d4f167b0e49eb01589769a63ec989f5d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_jobunic INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_jurnal_codjurnal</obj_name>
  <obj_hashval>673889bb8f5767ca15eb9f0ca8b23ba4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_jurnal_codjurnal INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_jurnal1_codjurnal1</obj_name>
  <obj_hashval>ba26218b3a3090982ba933799f5789c9</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_jurnal1_codjurnal1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_lansare_codlansare</obj_name>
  <obj_hashval>1ab355aa474e002b56455efb4f7d45aa</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_lansare_codlansare INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_lansare0_codlansare0</obj_name>
  <obj_hashval>c26ce073f0d49331530d5aa5efa1b827</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_lansare0_codlansare0 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_lansare1_codlansare1</obj_name>
  <obj_hashval>872c7acb8de82bfbf67f18aa02957b43</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_lansare1_codlansare1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_lansgest_codlansgest</obj_name>
  <obj_hashval>e326134ab911401504eaa5a85aa21c96</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_lansgest_codlansgest INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_lansprod_codlansprod</obj_name>
  <obj_hashval>282c3dad8ab96d275a913288390349ae</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_lansprod_codlansprod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 129 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_lansprod1_codlansprod1</obj_name>
  <obj_hashval>1d69299724f0dd051ace77b0ee3b00be</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_lansprod1_codlansprod1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 229 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_lansprod2_codlansprod2</obj_name>
  <obj_hashval>ca4ebe93f3bb824d47a5060793722231</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_lansprod2_codlansprod2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_lansprod2s_codlansprod2s</obj_name>
  <obj_hashval>a04aadd169682f2ca50ef26fc27819ea</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_lansprod2s_codlansprod2s INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_lansz_codlansz</obj_name>
  <obj_hashval>57fdca99f9dde166d7bfdd4529851cb6</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_lansz_codlansz INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_lansz1_codlansz1</obj_name>
  <obj_hashval>77034a47cf3b35ae9f2565c149457a02</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_lansz1_codlansz1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_list_counter</obj_name>
  <obj_hashval>6f5576892832ceb405363545fadd4869</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_list_counter INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_livr_codlivr</obj_name>
  <obj_hashval>b73aa52d8f0c4335c79c60e5fbbab50d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_livr_codlivr INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 105 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_livr1_codlivr1</obj_name>
  <obj_hashval>14867c320f14853b2ba221ffe06b3ed4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_livr1_codlivr1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_livrval_codlivrval</obj_name>
  <obj_hashval>5128fcb8494607469ac34da9fc3f2f0c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_livrval_codlivrval INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_locmunca_codloc</obj_name>
  <obj_hashval>6e914d893968206a0165686b4a42b241</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_locmunca_codloc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_locmunca1_codloc1</obj_name>
  <obj_hashval>e5c8acff260644e97a82bad78b65293f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_locmunca1_codloc1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_locmunca2_codloc2</obj_name>
  <obj_hashval>ae1aa41dc9d7d89e6fc27614d199f09b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_locmunca2_codloc2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 121 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_locurimuncaobs_id</obj_name>
  <obj_hashval>76bd488f1ca5a502141711f839ee8771</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_locurimuncaobs_id INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_logimportdoc_cod</obj_name>
  <obj_hashval>f20febfa34df89403c732d184607ed27</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_logimportdoc_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_mailuri_codmail</obj_name>
  <obj_hashval>cbc8e7aae35d1a4d5c3017c6011a553b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_mailuri_codmail INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_mailuri1_codmail1</obj_name>
  <obj_hashval>1bcd2908bdadaa8f3584d47d8a2777a2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_mailuri1_codmail1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_mailuridocs_codmaildoc</obj_name>
  <obj_hashval>fdf3795b8bf12e3bf8c3666237366b22</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_mailuridocs_codmaildoc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_marcalock_cod</obj_name>
  <obj_hashval>5e3b1db2dcbcdcfe208298f3308f6435</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_marcalock_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_mascaserart_codmasca</obj_name>
  <obj_hashval>0c9fe3991af237e48afb071651bbd482</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_mascaserart_codmasca INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_mascaserart1_codmasca1</obj_name>
  <obj_hashval>1cf5e8727576f2b6080f548972acf039</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_mascaserart1_codmasca1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_medex_codmedex</obj_name>
  <obj_hashval>069b85a88893e21c31da10240dea3c2e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_medex_codmedex INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_medex1_codmedex1</obj_name>
  <obj_hashval>b7a6d995d3c08a4d853d10899f79f251</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_medex1_codmedex1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_medex2_codmedex2</obj_name>
  <obj_hashval>7fb0ec865e6db6eb0fe7f16c63d1d2d7</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_medex2_codmedex2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_medext_codmedext</obj_name>
  <obj_hashval>02a6a921e93b6b3326eca1073e975ae2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_medext_codmedext INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_menudash_codmenudash</obj_name>
  <obj_hashval>ddbc430feec6f316d3f770f42de3d4c5</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_menudash_codmenudash INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 106 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_menudash0_codmenudash0</obj_name>
  <obj_hashval>1efa0488664e668585ce7be4402890fc</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_menudash0_codmenudash0 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 729 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_menudash1_codmenudash1</obj_name>
  <obj_hashval>c02e5a259bf195e360a3e2b9ae4aa3e8</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_menudash1_codmenudash1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 107 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_menudate_codmenudate</obj_name>
  <obj_hashval>bd13b371788923d38d86952bad767090</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_menudate_codmenudate INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_menudate1_codmenudate1</obj_name>
  <obj_hashval>bf49c6c7fc12150080254b8dedfc70eb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_menudate1_codmenudate1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_mesaje_klg</obj_name>
  <obj_hashval>79f3e158477350297f34bda91053036c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_mesaje_klg INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_mese_codmasa</obj_name>
  <obj_hashval>a00eb19029be012aa030de25476f23fc</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_mese_codmasa INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_mese1_codmasa1</obj_name>
  <obj_hashval>646de07e3c6589746f55be2f38d70b7a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_mese1_codmasa1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_mfclasif_codclasif</obj_name>
  <obj_hashval>cd5e7fc770591bc92355c97196435d10</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_mfclasif_codclasif INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 609 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_mifix_codmifix</obj_name>
  <obj_hashval>f761728d86d7f2fb8dcd8b2f0657b198</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_mifix_codmifix INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_mifix1_codmifix1</obj_name>
  <obj_hashval>86e088783ddc8adecd96514c9c9e2c51</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_mifix1_codmifix1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_modificari_codmodificare</obj_name>
  <obj_hashval>9f331b7d66e54d6b6dc5e34e806d7732</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_modificari_codmodificare INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 2505 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_modificaripret_codmodif</obj_name>
  <obj_hashval>498a506085f8a03eb00a04e76d9176cb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_modificaripret_codmodif INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_modplata2_codmodplata2</obj_name>
  <obj_hashval>1be72d7c2c30c541ed8bb40e734379bb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_modplata2_codmodplata2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_modplataiesretail_cod</obj_name>
  <obj_hashval>b2785555c2fe61cc1cde6288d94ffccb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_modplataiesretail_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_moduriplati_codmodplata</obj_name>
  <obj_hashval>476b68955dba71b07d6aad7d4472a098</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_moduriplati_codmodplata INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_motive_codmotiv</obj_name>
  <obj_hashval>91409716b640a6cf4cb1c714147034d5</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_motive_codmotiv INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_motivep_codmotiv</obj_name>
  <obj_hashval>399dfdd9a1cdd44568b30aeb4583ba4e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_motivep_codmotiv INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_mpbcar_codmpbcar</obj_name>
  <obj_hashval>899f273135a6bca5c1a99f48c2b915df</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_mpbcar_codmpbcar INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_mpbcar1_codmpbcar1</obj_name>
  <obj_hashval>5fe3da51f73b38c7f9c81f86817610f2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_mpbcar1_codmpbcar1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_mpbcar2_codmpbcar2</obj_name>
  <obj_hashval>42f546166ec3fcdeaaf67ec7ad5b2747</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_mpbcar2_codmpbcar2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nactivit_codactivit</obj_name>
  <obj_hashval>c1aa4578284babd2524e614f25f54e41</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nactivit_codactivit INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nagenda_codagenda</obj_name>
  <obj_hashval>d84155087aefac03f653c0353e2cba43</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nagenda_codagenda INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nagenda1_codagenda1</obj_name>
  <obj_hashval>956c528976aeed8dbf0578af0df68b70</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nagenda1_codagenda1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nagenti1_codagent1</obj_name>
  <obj_hashval>65f15d4c9b91126d4c481df2f112ea91</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nagenti1_codagent1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nagentiproc_codagentproc</obj_name>
  <obj_hashval>f0b94c69b5c9a8f89c94c8ec2cd0aaf1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nagentiproc_codagentproc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nagentival_codagentval</obj_name>
  <obj_hashval>8c43467c72aafae12e72fdd849f44a96</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nagentival_codagentval INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nart_codarticol</obj_name>
  <obj_hashval>8642e3b9c1b2114256342b24ec7aaaa2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nart_codarticol INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nart1_codarticol1</obj_name>
  <obj_hashval>cf535247e2d93aef68ec4bfab7f4d737</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nart1_codarticol1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nartamb_codamb</obj_name>
  <obj_hashval>488d6fcea39da06846a5020591d15416</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nartamb_codamb INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nartatr_codartatr</obj_name>
  <obj_hashval>a70d5f8930e2a3a7cf7c11591e027a67</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nartatr_codartatr INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nartcli_codartcli</obj_name>
  <obj_hashval>da3c07feb9aa11f57f040b9dcedc167a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nartcli_codartcli INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nartdim_codartdim</obj_name>
  <obj_hashval>73ff438dfcce5004a8cdfc637033d5e7</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nartdim_codartdim INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nartimplicite_codimplicit</obj_name>
  <obj_hashval>cd177d060164a223da2bfc85a7e2c2bf</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nartimplicite_codimplicit INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nartobj_codobiect</obj_name>
  <obj_hashval>84628140243161e72b1bb8edc0ae49d1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nartobj_codobiect INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nartobj1_codobiect1</obj_name>
  <obj_hashval>555528db82d629f529bdf32d116c7c30</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nartobj1_codobiect1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nartobjcolet_cod</obj_name>
  <obj_hashval>28af5895b77ca26ce53d0ada380a8f98</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nartobjcolet_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nartobjimp_codobjimp</obj_name>
  <obj_hashval>d9a459f979206fd7dfc9138b7b2c333d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nartobjimp_codobjimp INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nartobjsubunit_cods</obj_name>
  <obj_hashval>f85134d38681ab8ab774a119f04349a6</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nartobjsubunit_cods INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nartobjtrad_codobiecttrad</obj_name>
  <obj_hashval>9e13c3442dfb7486dd0aa74e6fe6a449</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nartobjtrad_codobiecttrad INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nartopt_codopt</obj_name>
  <obj_hashval>d58112bae341a3d593fd507cae053389</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nartopt_codopt INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_natrib_codatribut</obj_name>
  <obj_hashval>1900c763aaa4a1e6371b0d439d06fcd5</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_natrib_codatribut INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_natrib1_codvalatr</obj_name>
  <obj_hashval>36819fa6baa67144a5db7bba91dd787e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_natrib1_codvalatr INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_natrib1trad_codatrib1trad</obj_name>
  <obj_hashval>3102d606c8460bc2ee93df753f16da2b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_natrib1trad_codatrib1trad INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_natrib2_cod</obj_name>
  <obj_hashval>e42f809ac236032fe7c451eb447e09a2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_natrib2_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_natrobj_codatrobj</obj_name>
  <obj_hashval>1482bcefc6058504933a8994bcfbdf34</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_natrobj_codatrobj INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_natrtrad_codnatrtrad</obj_name>
  <obj_hashval>81ffea6db013fbae6f75ff2bc983c35f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_natrtrad_codnatrtrad INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 122 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nbanciretail_cod</obj_name>
  <obj_hashval>8250bb24203d32fc62b85c8d5f67dcaa</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nbanciretail_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nbank_codbank</obj_name>
  <obj_hashval>29ab336a2f993f6937d3ca1bce12c6da</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nbank_codbank INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 137 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nbankcont_codbankcont</obj_name>
  <obj_hashval>db7e6617a3426c02eaddafc2e01389e1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nbankcont_codbankcont INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nbankcont1_codbankcont1</obj_name>
  <obj_hashval>0c8ef2ed9f9add827d4a30dca133064b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nbankcont1_codbankcont1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 122 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nbanksoldluna_codsoldluna</obj_name>
  <obj_hashval>f66d74b67bfc63f4d3be2e9e1ccb6cdb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nbanksoldluna_codsoldluna INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nc_codnc</obj_name>
  <obj_hashval>48323f483da83edceb56f50664399f98</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nc_codnc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nc1_codnc1</obj_name>
  <obj_hashval>970386c6ded36c0553c627de423c0789</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nc1_codnc1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncarsupart_codcarsupart</obj_name>
  <obj_hashval>e8b5e545c87a78df9c5a0ba34336c868</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncarsupart_codcarsupart INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncasemarcat_codcase</obj_name>
  <obj_hashval>9a7e9a0b11e04b4b45cf15d34a6f133e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncasemarcat_codcase INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 144 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncasemarcat1_codcase1</obj_name>
  <obj_hashval>105de08f93ba09a14f8693a1f2733762</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncasemarcat1_codcase1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 122 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncasemarcat2_codcase2</obj_name>
  <obj_hashval>4a7c103fefe2ac763e2392427cf04283</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncasemarcat2_codcase2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 142 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncatpret_codcatpret</obj_name>
  <obj_hashval>26fed78f2c8956d436bae167e0335632</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncatpret_codcatpret INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nccadouri_codnccadouri</obj_name>
  <obj_hashval>bc4e1f3628aacb6b241bfee2c6e55edb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nccadouri_codnccadouri INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nclasea_codclasea</obj_name>
  <obj_hashval>7f1bdc422dfe2f407ee5ea155e73f5f3</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nclasea_codclasea INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nclaseas_codclaseas</obj_name>
  <obj_hashval>7d19e5043050322f59ac7167067e3810</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nclaseas_codclaseas INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nclasedisc_codclasedisc</obj_name>
  <obj_hashval>351152399267b1fbbb60bcb0343b48cf</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nclasedisc_codclasedisc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nclaseg_codclaseg</obj_name>
  <obj_hashval>1686e3d101b0ed137ff66a35a202a5cb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nclaseg_codclaseg INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nclaseint_codclaseint</obj_name>
  <obj_hashval>1238807f14c677149b637bead88910b5</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nclaseint_codclaseint INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nclasemf_codclasemf</obj_name>
  <obj_hashval>c6696983fb77cdd35e75372787439d3f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nclasemf_codclasemf INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nclaseop_codclaseop</obj_name>
  <obj_hashval>3d78a8af8a99b4e58d359a6800a0dd53</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nclaseop_codclaseop INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nclaseopt_codclaseopt</obj_name>
  <obj_hashval>92d48c86bcab28f1018c87f1c69c9af5</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nclaseopt_codclaseopt INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nclasep_codclasep</obj_name>
  <obj_hashval>67e05522d1b4c3b973198f64c719160e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nclasep_codclasep INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nclaseprod_codclaseprod</obj_name>
  <obj_hashval>a0287a264c43135115a58c599b590a39</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nclaseprod_codclaseprod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncodfiscretail_cod</obj_name>
  <obj_hashval>47f4b574504756e21edaba820917f8d3</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncodfiscretail_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncont_codcont</obj_name>
  <obj_hashval>dc43c9d4ed365b0756ccc90f740555cb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncont_codcont INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 11230 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncont1_codcont1</obj_name>
  <obj_hashval>833b78b59de882668437e6fb19ce1c24</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncont1_codcont1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 1579 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncont1sub_cod</obj_name>
  <obj_hashval>2a64844f827b242d0ae36d494e3f2b2e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncont1sub_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncontcomun_cod</obj_name>
  <obj_hashval>fc11444892bf62f2f3f792fb4a2177de</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncontcomun_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncontechiv_codcontechiv</obj_name>
  <obj_hashval>a1e9f90ef675cdf5ef4655a331bfa84c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncontechiv_codcontechiv INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncontechivsub_cod</obj_name>
  <obj_hashval>cc8a19916dc985d5736163741b94b684</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncontechivsub_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncontfirmecupl_codunic</obj_name>
  <obj_hashval>aee3b6dfc9c5fce916a068018b6aca4c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncontfirmecupl_codunic INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncontrep_codcontrep</obj_name>
  <obj_hashval>23d17e001e5b794d2d8035b73e8aeede</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncontrep_codcontrep INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncontreprul_codcontreprul</obj_name>
  <obj_hashval>15efb3c005df9e1b9d0c783e8028c5cd</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncontreprul_codcontreprul INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncontreprulsub_cod</obj_name>
  <obj_hashval>2290d47d3a9c934444ac4ebcced1eda1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncontreprulsub_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncontrepsold_codcontreps</obj_name>
  <obj_hashval>fe561b9577a8d9750a36a04de4d921f2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncontrepsold_codcontreps INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncontrepsoldsub_cod</obj_name>
  <obj_hashval>55288a01da67e6e019cdcc57a09e52b6</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncontrepsoldsub_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncontrul_codcontrul</obj_name>
  <obj_hashval>01c28f19bff509867f3f2a7f5e6170ec</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncontrul_codcontrul INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 14790 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncontruls_codcontruls</obj_name>
  <obj_hashval>0842008ff7c6e1a17a1cb4db341d6367</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncontruls_codcontruls INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncontrulsub_codrulsub</obj_name>
  <obj_hashval>96f280ff6a62d374fcc39b7c99a05582</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncontrulsub_codrulsub INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncontrult_codcontrult</obj_name>
  <obj_hashval>c350fe640bc9ef6a9f44f7ee6889e4ab</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncontrult_codcontrult INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nconts_codconts</obj_name>
  <obj_hashval>1fcd5985d18f7a6d76d82cfee08308de</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nconts_codconts INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nconts1_codconts1</obj_name>
  <obj_hashval>33154ab56c0009d773ba623b3c9ff6c1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nconts1_codconts1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncontsold_codcontsold</obj_name>
  <obj_hashval>185b13a5ce19c9221ace92875f81954c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncontsold_codcontsold INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 1400 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncontsolds_codcontsolds</obj_name>
  <obj_hashval>6e415a01fa78985f54a699e67202f466</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncontsolds_codcontsolds INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncontsoldsub_codsoldsub</obj_name>
  <obj_hashval>3ffac988e04b315c6f6c26aa75e92b9d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncontsoldsub_codsoldsub INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncontsoldt_codcontsoldt</obj_name>
  <obj_hashval>7e928e4dbe1690e1978997a49c1a6814</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncontsoldt_codcontsoldt INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncontt_codcontt</obj_name>
  <obj_hashval>79e02d859234d75e7776134033489277</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncontt_codcontt INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ncontt1_codcontt1</obj_name>
  <obj_hashval>137f0c1e5d6a0a2b91e7da86f85d9ca8</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ncontt1_codcontt1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ndelegatretail_cod</obj_name>
  <obj_hashval>ddf4adecb4adc5238cc617056f1e4d46</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ndelegatretail_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_necesar_codnecesar</obj_name>
  <obj_hashval>742cfa0889c3e384c567191d112ffae4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_necesar_codnecesar INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nechiv_codechiv</obj_name>
  <obj_hashval>109908529c526cf9d525437db5e3ce4f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nechiv_codechiv INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nelemaero_codelemaero</obj_name>
  <obj_hashval>5def551cf6995aaa04aba8f7adb0ccba</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nelemaero_codelemaero INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nestjurnal_codnestjurnal</obj_name>
  <obj_hashval>309414fa1e4366732a3a4225ec37a968</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nestjurnal_codnestjurnal INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ngameart_codgama</obj_name>
  <obj_hashval>e5bccc66b5b887f6b0f79961e3ea6568</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ngameart_codgama INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ngest_codgest</obj_name>
  <obj_hashval>4edfdcc38ea9dccc6823bc20075a41f5</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ngest_codgest INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ngest1_codgest1</obj_name>
  <obj_hashval>7a6fd050d5f96bbff235eac5b5ee41b8</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ngest1_codgest1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ngrupeauto_codgrupeauto</obj_name>
  <obj_hashval>a4b9f35e2b17643567023a660cb8b308</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ngrupeauto_codgrupeauto INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nimob_codnimob</obj_name>
  <obj_hashval>177b8f40ea213f9fbc89ebd6d80e87a4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nimob_codnimob INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ninstauto_codinstauto</obj_name>
  <obj_hashval>097aeb4316bbea79a7dc6794e4686ddf</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ninstauto_codinstauto INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ninterv_codinterv</obj_name>
  <obj_hashval>3b39e69eb2ac0eccbd5717119fe865c9</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ninterv_codinterv INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nir_codnir</obj_name>
  <obj_hashval>4dcc467279e1f4db67117b0272b4ca19</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nir_codnir INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nirser_codnirser</obj_name>
  <obj_hashval>c3ea5e1c7f95e1145045369fb4228658</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nirser_codnirser INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nirstoc_codnirstoc</obj_name>
  <obj_hashval>0111d554f84a117ad404e18146edb5cb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nirstoc_codnirstoc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_njudet_codjudet</obj_name>
  <obj_hashval>86cabe1acff1a83f00c3d8ef80284f61</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_njudet_codjudet INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 144 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nlimba_codlimba</obj_name>
  <obj_hashval>e11f7d701ddfe91b75b61d1cf55c7d27</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nlimba_codlimba INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nlimcredit_codlimcredit</obj_name>
  <obj_hashval>55501099096aa7e36d26655ed82f30fe</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nlimcredit_codlimcredit INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nlimcredit1_codlimcredit1</obj_name>
  <obj_hashval>3500772ef878d14f9e54249f075f06f3</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nlimcredit1_codlimcredit1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nlocalit_codlocalit</obj_name>
  <obj_hashval>c3ee352b911451fa63cc5211c1bf0361</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nlocalit_codlocalit INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 13855 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nlocatii_codlocatie</obj_name>
  <obj_hashval>3a824788ffe65894b123c5cbc2ed4417</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nlocatii_codlocatie INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nmakete_codmaketa</obj_name>
  <obj_hashval>27f82eb9f13f7ad3e5417930045dc40b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nmakete_codmaketa INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 511 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nmarciauto_codmarciauto</obj_name>
  <obj_hashval>0b96bb0db4b13fdbff032a6e28657869</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nmarciauto_codmarciauto INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nmeserii_codmeserie</obj_name>
  <obj_hashval>f9ba48654b100c8fd25c875124086856</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nmeserii_codmeserie INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nmodeleauto_codmodeleauto</obj_name>
  <obj_hashval>4f9f63eb9104133fdc1b15b8478020df</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nmodeleauto_codmodeleauto INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nmonede_codmoneda</obj_name>
  <obj_hashval>55f243e53c6f7c687941b623bb3d7119</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nmonede_codmoneda INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nmonede1_codmoneda1</obj_name>
  <obj_hashval>b3edc3db813acb4b71891409b00ca8ac</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nmonede1_codmoneda1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nmvs_codnmvs</obj_name>
  <obj_hashval>66fe2bfc72de74042b9f141c58f6c22f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nmvs_codnmvs INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_noper_codop</obj_name>
  <obj_hashval>8d120955de333a17f5959142399ac51b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_noper_codop INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_noper1_codop1</obj_name>
  <obj_hashval>aed8e36f7bee31d01e014c87a0bb4a23</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_noper1_codop1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_normemat_codnormemat</obj_name>
  <obj_hashval>7a56203c4f4f7ca77b9c9e0171363cc4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_normemat_codnormemat INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_notecredit_codncredit</obj_name>
  <obj_hashval>11f7ba5feae72b13bca99ee46dd9bdb7</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_notecredit_codncredit INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_notecredit1_codncredit1</obj_name>
  <obj_hashval>8a9d93ebbc94b0497f521a5d43c90d2a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_notecredit1_codncredit1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_notecreditfact_codncfact</obj_name>
  <obj_hashval>35cde69ea7725e3109e7dc4aed4ec0b0</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_notecreditfact_codncfact INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nparc0_codnparc0</obj_name>
  <obj_hashval>85388d1786af71cb2fde20e2b5630661</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nparc0_codnparc0 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nparc1_codnparc1</obj_name>
  <obj_hashval>76967cbaec198c0fbe8206ce56c6cc06</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nparc1_codnparc1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nparc2_codnparc2</obj_name>
  <obj_hashval>bf3b93fd1660810169bd55d9a6257a85</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nparc2_codnparc2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nparc3_codnparc0</obj_name>
  <obj_hashval>42733c64c1553e67f9b5d2f0cbf78bfa</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nparc3_codnparc0 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nparc3_codnparc3</obj_name>
  <obj_hashval>4ea086cc64f0780e0d2a02dde3c8619d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nparc3_codnparc3 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nparcaut_codnparcaut</obj_name>
  <obj_hashval>7fd7e96a9e708ba8562440a0aa000bbc</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nparcaut_codnparcaut INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nparccom_codnparccom</obj_name>
  <obj_hashval>b99cf9a34a6360f10dfc7e03c5c1dee6</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nparccom_codnparccom INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nparcg_codnparcg</obj_name>
  <obj_hashval>547c8a7de9d2b61290a747fcccfd9fa3</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nparcg_codnparcg INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_npart_codpart</obj_name>
  <obj_hashval>bd61495a40426f217ef01d452650da26</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_npart_codpart INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_npart1_codpart1</obj_name>
  <obj_hashval>a4bb8ed594843e8c858be9377a0a63c0</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_npart1_codpart1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_npart1crm_codpart1crm</obj_name>
  <obj_hashval>44df53bf0477dc7232c539f2b6144247</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_npart1crm_codpart1crm INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_npartactivit_cpa</obj_name>
  <obj_hashval>8b106cbc71ba5275f7fe63790627bda1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_npartactivit_cpa INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_npartb_codpartb</obj_name>
  <obj_hashval>bd4565aae2e8ac7c72c0517254da7ee6</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_npartb_codpartb INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_npartcodfisc_cod_codfiscal</obj_name>
  <obj_hashval>2e1c8c09e2bd6057ad35538e09aba000</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_npartcodfisc_cod_codfiscal INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_npartconcurenti_cpc</obj_name>
  <obj_hashval>d5e037f5098b93ab3809354433c6e5d9</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_npartconcurenti_cpc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_npartdisc_codpartdisc</obj_name>
  <obj_hashval>5ceef72890acd6b6a72d0c0b915f0d44</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_npartdisc_codpartdisc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_npartdiscretail_cod</obj_name>
  <obj_hashval>443783632499ccfa376136591aa53cda</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_npartdiscretail_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_npartdomact_codpartdomact</obj_name>
  <obj_hashval>622ac11b302d477422ec738e2672dd36</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_npartdomact_codpartdomact INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_npartlc_codnpartlc</obj_name>
  <obj_hashval>914e31d9207bfe3ded7c5c091f283979</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_npartlc_codnpartlc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_npartoportunitati_cpo</obj_name>
  <obj_hashval>2e1c36fff8ff65fcb1287c16b934a0a8</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_npartoportunitati_cpo INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_npartretail_codpartretail</obj_name>
  <obj_hashval>fbe5186c8e1bee77017638830f66b3aa</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_npartretail_codpartretail INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_npartsoldluna_codsoldluna</obj_name>
  <obj_hashval>ededf4adb645a2c5c845deb09bcae0d4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_npartsoldluna_codsoldluna INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_npartsoldlunasub_cod</obj_name>
  <obj_hashval>8dc7f28129c75da77fd71e6d494d2ec6</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_npartsoldlunasub_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_npartsubunit_codparts</obj_name>
  <obj_hashval>48120fdfa7ce1b2d15274b98c44623fe</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_npartsubunit_codparts INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nparttr_codparttr</obj_name>
  <obj_hashval>dd1453ab4302f2f573c3e38945ad8550</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nparttr_codparttr INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nparttr_lnk_codparttrlnk</obj_name>
  <obj_hashval>3c240a7a30b29967419e57f02b72ddb4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nparttr_lnk_codparttrlnk INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nparttr_lnk1_codparttrlnk1</obj_name>
  <obj_hashval>19c0035b3236444904af27589dfa1e90</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nparttr_lnk1_codparttrlnk1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_npers_codpers</obj_name>
  <obj_hashval>05207ae1a6dcf695f9fd2ce131648a04</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_npers_codpers INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_npers1_codpers1</obj_name>
  <obj_hashval>eb9fe9c989c97049cb711657050bb824</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_npers1_codpers1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nperscontact_codpersc</obj_name>
  <obj_hashval>2f4d892f8ad57fc0e8027f12f49cd276</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nperscontact_codpersc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nperscurs_codnperscurs</obj_name>
  <obj_hashval>449ed100aa970f432f12d06ebceb7314</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nperscurs_codnperscurs INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nperscvlocm_codperscvlocm</obj_name>
  <obj_hashval>efdbcb6f1f8dc17467571d530a2744e3</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nperscvlocm_codperscvlocm INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nperscvpas_codperscvpas</obj_name>
  <obj_hashval>45e9b21627399523be40a5acf7649c08</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nperscvpas_codperscvpas INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nperscvscol_codperscvscol</obj_name>
  <obj_hashval>b69eafc109bc31f7581ce699aa47e4e4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nperscvscol_codperscvscol INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nperscvskil_codperscvskil</obj_name>
  <obj_hashval>bbdac3bac8687b791827097e27bb3be6</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nperscvskil_codperscvskil INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nperssoldluna_codsoldluna</obj_name>
  <obj_hashval>c98e9c69786321b54786fb81d6b66002</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nperssoldluna_codsoldluna INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nperssoldlunasub_cod</obj_name>
  <obj_hashval>be5f046fdbbc7d01374f821e3c3aa5c0</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nperssoldlunasub_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nperstiplucr_codtiplucr</obj_name>
  <obj_hashval>d0028364220a199875fbcc72bc6613a6</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nperstiplucr_codtiplucr INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nremauto_codremauto</obj_name>
  <obj_hashval>cdd166f687a562888bc928f1dfcbbbf4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nremauto_codremauto INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nri_cmdinterna</obj_name>
  <obj_hashval>49c993868c4be807df33e6b910ddfe8a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nri_cmdinterna INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 1000 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nrinv_mf</obj_name>
  <obj_hashval>1ad28ac991aed7080f3137df0b5c60f6</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nrinv_mf INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nrinvlock_codinvlock</obj_name>
  <obj_hashval>0762e4b061ecb2e3ab75da9274d8c78d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nrinvlock_codinvlock INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nscadtl_codscadtl</obj_name>
  <obj_hashval>8989c9e2c7b165a085141e15330fb45a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nscadtl_codscadtl INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nscadtl1_codscadtl1</obj_name>
  <obj_hashval>3925543ce112b995cd95839ab94cd027</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nscadtl1_codscadtl1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nsediipartretail_codsediu</obj_name>
  <obj_hashval>c1daf5ea02d6740303aa5570be693756</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nsediipartretail_codsediu INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nserii_codserie</obj_name>
  <obj_hashval>00f2d4343a70226e8c2f87ae192d4469</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nserii_codserie INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nsertar_codsertar</obj_name>
  <obj_hashval>44e251bbf568cd22ad17cee2952e6737</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nsertar_codsertar INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nsertar1_codsertar1</obj_name>
  <obj_hashval>4221cd010f0e9f1870e148e0be84fd10</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nsertar1_codsertar1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nsubunit_codsubunit</obj_name>
  <obj_hashval>863b248a6ae6f5b5bb9d3ba4f6624485</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nsubunit_codsubunit INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nsubunit1_codsubunit1</obj_name>
  <obj_hashval>29ae3a940df4bfb7b20cac1e24c77870</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nsubunit1_codsubunit1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ntari_codtara</obj_name>
  <obj_hashval>84223ed7219a7cb5f12f4ffbc610201b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ntari_codtara INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 362 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ntaxe_codtaxa</obj_name>
  <obj_hashval>910fbb729d10d70e6e80d2625e60510a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ntaxe_codtaxa INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ntaxe1_codtaxa1</obj_name>
  <obj_hashval>54bb1c70d5b430b65a555bcc6ba47f5f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ntaxe1_codtaxa1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ntipsedii_codtipsediu</obj_name>
  <obj_hashval>1fcba19a4dd0ecb5728c81907fbb2c96</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ntipsedii_codtipsediu INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ntva_codtva</obj_name>
  <obj_hashval>adcd4836c5e746051a96c67607103184</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ntva_codtva INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 116 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ntva1_codtva1</obj_name>
  <obj_hashval>14f34bfb362b039c70f85e763f5c5e65</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ntva1_codtva1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 106 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_num_codum</obj_name>
  <obj_hashval>2b691f3caadf05da57808cc22e8cf935</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_num_codum INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 117 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_num1_codum1</obj_name>
  <obj_hashval>d595fe5f77035314c5f5487e79e95aa1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_num1_codum1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 119 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_nzone_codzona</obj_name>
  <obj_hashval>14fa0188f264c44f3739d25b262387b2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_nzone_codzona INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_obiective_codobiectiv</obj_name>
  <obj_hashval>0c4c80f7f8c236f2ce1c3566c1c891f8</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_obiective_codobiectiv INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_obligpif_codobligpif</obj_name>
  <obj_hashval>89c59dbd3135be25e22e3ffb3f97400e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_obligpif_codobligpif INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_oferta_codoferta</obj_name>
  <obj_hashval>7ae159d02db5f99d73abdc4fc900532f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_oferta_codoferta INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_oferta1_codoferta1</obj_name>
  <obj_hashval>26d43cf7878acff7db231afa5a117bbd</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_oferta1_codoferta1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_oportunitati_co</obj_name>
  <obj_hashval>6260116cfdb96357c4118fba378fd5f2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_oportunitati_co INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_oportunitati1_co1</obj_name>
  <obj_hashval>5f9e526fe0ccbc48cf9bee4a2f25b007</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_oportunitati1_co1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_opper_codopper</obj_name>
  <obj_hashval>c9549c61911d4ba08f77c96162133069</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_opper_codopper INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_opper1_codopper1</obj_name>
  <obj_hashval>7e1d8d45759c93cf8a3b5ae37229429b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_opper1_codopper1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_opreg_codop</obj_name>
  <obj_hashval>fa5c6d4e74a884d39bf34899d3fe1669</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_opreg_codop INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_opreg1_codopreg1</obj_name>
  <obj_hashval>77ec51c4fe706146cc4ad7c25778e5fe</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_opreg1_codopreg1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_orar_codorar</obj_name>
  <obj_hashval>8164d46b244bb03d323be4ac53c63074</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_orar_codorar INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_orelm_codorelm</obj_name>
  <obj_hashval>f6dacec691d60521298432302951f5b0</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_orelm_codorelm INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_ospatari_cod</obj_name>
  <obj_hashval>1d0235fa5258cb2150ee4ff1843b5e12</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_ospatari_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_pachete_codpachete</obj_name>
  <obj_hashval>44ee5ec95658ee643f0f90988a6ac963</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_pachete_codpachete INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_pachete1_codpachete1</obj_name>
  <obj_hashval>34655c7f9614a1a477289c67e0d126f1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_pachete1_codpachete1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_pacheteobj_codpacheteobj</obj_name>
  <obj_hashval>2237d39b239bd544ccc89f8a325a5ecb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_pacheteobj_codpacheteobj INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_pacheteobjl_codpacheteobjl</obj_name>
  <obj_hashval>c5ad0a948e3ea62ab04a091002c88e2e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_pacheteobjl_codpacheteobjl INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_packing_codpacking</obj_name>
  <obj_hashval>ea8a3396bef042b0c995a634bcd6d5a0</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_packing_codpacking INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_packing1_codpacking1</obj_name>
  <obj_hashval>65dfc2ec7ecb5b1aef55a805b018405c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_packing1_codpacking1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_packing2_codpacking2</obj_name>
  <obj_hashval>ce5f456c30ffec55e2c6e8aaac01d37e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_packing2_codpacking2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_packing3_codpacking3</obj_name>
  <obj_hashval>9d82e2140f7dce52c745e32b3e544cc2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_packing3_codpacking3 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_paramliste</obj_name>
  <obj_hashval>ff40641b34b3ec0b2680095d9a61989e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_paramliste INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_particip_cod</obj_name>
  <obj_hashval>f409cb9dca8400cfcdf740dbf2e5412b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_particip_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_partpuncte_cod</obj_name>
  <obj_hashval>794c6520a24cfb9f008a2957affd464b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_partpuncte_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_parttot_codparttot</obj_name>
  <obj_hashval>e2011705124f9630957b5405bc6c16ba</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_parttot_codparttot INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_pcalcul_codpc</obj_name>
  <obj_hashval>ab1670e6a9e0831202958021104bd037</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_pcalcul_codpc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_pcart_codpcart</obj_name>
  <obj_hashval>682e7221d94636d3c1699d9e62a585ae</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_pcart_codpcart INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_pcdir_codpcdir</obj_name>
  <obj_hashval>b4d633d9ab035aa6875b4a648ce80f0d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_pcdir_codpcdir INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_pcdistrib_codpcdistrib</obj_name>
  <obj_hashval>d47ee6fd07749e56dd00505e04695ce1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_pcdistrib_codpcdistrib INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_pcfirma_codpcfirma</obj_name>
  <obj_hashval>3451c1d96d15bdaede4ec3f4ff733fb1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_pcfirma_codpcfirma INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_pcgest_codpcgest</obj_name>
  <obj_hashval>5c2f3dc31f90ac9c5fc8d50e099c4b69</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_pcgest_codpcgest INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_pcsectii_codpcsectii</obj_name>
  <obj_hashval>99dd792e35ff9f9015a9b3df5fa6a7da</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_pcsectii_codpcsectii INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_perisabil_codperisabil</obj_name>
  <obj_hashval>363cb6475e3fa8bb4718a088f5e38ccc</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_perisabil_codperisabil INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_perisabil1_codperisabil1</obj_name>
  <obj_hashval>b286fdfb9a1054348144be3a6e9b6dd4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_perisabil1_codperisabil1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_perisabil2_codperisabil2</obj_name>
  <obj_hashval>7cd84eee6995fc9bd2a275be7d37118e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_perisabil2_codperisabil2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_pgs_codpgs</obj_name>
  <obj_hashval>9afc259ee549d0c4860926cfbee60a19</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_pgs_codpgs INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 109 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_pgs1_codpgs1</obj_name>
  <obj_hashval>f4ffd6cbb72d6ae277da14e1ef87d176</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_pgs1_codpgs1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 114 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_plancurs_codplancurs</obj_name>
  <obj_hashval>47378de8816dbb153afe91843ea01336</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_plancurs_codplancurs INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_plancurs1_codplancurs1</obj_name>
  <obj_hashval>117326dd0500b5b5cc506855eebfe908</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_plancurs1_codplancurs1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_planifnod_codplanifnod</obj_name>
  <obj_hashval>a9602e967f3163796fe8dd1a7a9bb8d5</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_planifnod_codplanifnod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_planifprod_codplanifprod</obj_name>
  <obj_hashval>b01261c243818c0864ea8e10d331c31e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_planifprod_codplanifprod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 329 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_planifprod1_codplanifprod1</obj_name>
  <obj_hashval>0bdea39c939716179faaacb6ec51728a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_planifprod1_codplanifprod1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 429 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_plati_codplata</obj_name>
  <obj_hashval>94d9c516ee422f2d3f321b688c43a5bf</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_plati_codplata INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_plati1_codplata1</obj_name>
  <obj_hashval>e0ca6a4c4e40f767f2aa7d2c02720f74</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_plati1_codplata1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_plati2_codplata2</obj_name>
  <obj_hashval>cec1301fd9f513eafef14b876e6aa447</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_plati2_codplata2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_plucase_codplucase</obj_name>
  <obj_hashval>533b9727ced639b01fa9331be5a00c4a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_plucase_codplucase INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_pmp_all_luna</obj_name>
  <obj_hashval>00f44035052cb1361dadf2fde8b1adb8</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_pmp_all_luna INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_pmpluna_codpmpluna</obj_name>
  <obj_hashval>d3be3b7733c3708b039fb779b2e12dfc</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_pmpluna_codpmpluna INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_posbancar_codposbancar</obj_name>
  <obj_hashval>4807f9e569eb0ee292b9cd4516978a62</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_posbancar_codposbancar INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_postretail_cod</obj_name>
  <obj_hashval>5beafa61cefe302a216f9823fda75632</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_postretail_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_precomanda_codprecomanda</obj_name>
  <obj_hashval>bc9870d6fefc503390fedbd1121da249</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_precomanda_codprecomanda INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_precomanda1_codprecomanda1</obj_name>
  <obj_hashval>7c2a32d81825b02eda3144c0b4e51ce4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_precomanda1_codprecomanda1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_predariplus_idinreg</obj_name>
  <obj_hashval>aadf68bfe7a5387ed876f839c4172cbd</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_predariplus_idinreg INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_prelpret_retail</obj_name>
  <obj_hashval>625bdc08565e622735994af260c695a7</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_prelpret_retail INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_prestatii_codprestatie</obj_name>
  <obj_hashval>8bac702295fb6fcf30b7c06f7716dd41</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_prestatii_codprestatie INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_pretm_codpretm</obj_name>
  <obj_hashval>e4616b7efffffc201f6671a802b236ed</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_pretm_codpretm INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_pretmamb_codpretmamb</obj_name>
  <obj_hashval>2519364300cec6912d26cd833153b240</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_pretmamb_codpretmamb INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_prioritategantt</obj_name>
  <obj_hashval>f11799f306090b97c7796306e6a5c48d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_prioritategantt INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_procactdate_codprocact</obj_name>
  <obj_hashval>35dfdbcf5ed62ef603a46150ed875148</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_procactdate_codprocact INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_procactdate1_codprocact1</obj_name>
  <obj_hashval>8e5307790da140730a94570647e538c0</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_procactdate1_codprocact1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_procactdef_codprocdef</obj_name>
  <obj_hashval>4941c6cc6858f82bf85d880b83a26001</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_procactdef_codprocdef INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 105 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_prodcomp_codprodcomp</obj_name>
  <obj_hashval>758d8bdec22478b044a1af0d186737d9</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_prodcomp_codprodcomp INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_prodgest_codprodgest</obj_name>
  <obj_hashval>4f59e6eaa35907360f5fec0a370b7abf</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_prodgest_codprodgest INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_prodman_codman</obj_name>
  <obj_hashval>bda578d64877c855b11a2c621daa14de</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_prodman_codman INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_prodmas_codprodmas</obj_name>
  <obj_hashval>6d97e7aafe69759b465d7b24c5aae889</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_prodmas_codprodmas INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_prodmat_codmat</obj_name>
  <obj_hashval>2b654852af8353ace810b8ddeac958fc</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_prodmat_codmat INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_prodmatechiv_codmatechiv</obj_name>
  <obj_hashval>d6ec357462ce9195e70e10d0d8a1444c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_prodmatechiv_codmatechiv INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_prodnet_codprodnet</obj_name>
  <obj_hashval>bde1ea204f7f71bb1466e49bc7e96522</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_prodnet_codprodnet INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_prodnet1_codprodnet1</obj_name>
  <obj_hashval>cd12ac69f829d1718b3930106157aa32</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_prodnet1_codprodnet1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_prodnorme_codnorma</obj_name>
  <obj_hashval>6b4a14b639afccb7a7d517ac59f72d1c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_prodnorme_codnorma INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_prodrez_codrez</obj_name>
  <obj_hashval>d7b2d75d40f8dd63b324ae7fd51ca195</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_prodrez_codrez INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_prodsdv_codprodsdv</obj_name>
  <obj_hashval>57bdcfab609600f523d7684cc686c74f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_prodsdv_codprodsdv INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_programf_codprogramf</obj_name>
  <obj_hashval>978280700a640211ab285f90bd426944</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_programf_codprogramf INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_programf1_codprogramf1</obj_name>
  <obj_hashval>1e5b1678239ae8a4ae5e9305fbbca785</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_programf1_codprogramf1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_programflmc_codlmc</obj_name>
  <obj_hashval>495704be8abeb16c4839a70a8d520a39</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_programflmc_codlmc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_programfman_codprogramfman</obj_name>
  <obj_hashval>17fb9cdf9c58f588234b4936ee43d086</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_programfman_codprogramfman INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_programfsdv_codprogramfsdv</obj_name>
  <obj_hashval>2d99476da0a5d64d80df2c76cc7e923d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_programfsdv_codprogramfsdv INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_proiect_codproiect</obj_name>
  <obj_hashval>258de7343d91ce82a2ed75f46fcd2b7a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_proiect_codproiect INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_proiectcrm_codproiectcrm</obj_name>
  <obj_hashval>96e4e2e8450d75b35904525feefb95ef</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_proiectcrm_codproiectcrm INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_proiectnod_codproiectnod</obj_name>
  <obj_hashval>6c954832336ba87908be0a17e7f3da61</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_proiectnod_codproiectnod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_promo_codpromo</obj_name>
  <obj_hashval>9d1ac89b298695ff1fd7774b914559d6</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_promo_codpromo INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_promo1_codpromo1</obj_name>
  <obj_hashval>a8e1d541084ffa36b6aeb7e2ac15ded4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_promo1_codpromo1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_promo1cadou_codcadou</obj_name>
  <obj_hashval>2261e281072b8745fdf240aa33c2a2fc</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_promo1cadou_codcadou INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_promo1cadouser_codcadous</obj_name>
  <obj_hashval>beba5035c863d68bbdf43b94ddc635aa</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_promo1cadouser_codcadous INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_promo1ser_codpromo1s</obj_name>
  <obj_hashval>4833c3da2f0971d041101861308ce517</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_promo1ser_codpromo1s INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_promopart_codpromopart</obj_name>
  <obj_hashval>6dac8061811cb752e1987463d8d41953</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_promopart_codpromopart INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_promoprag_codprag</obj_name>
  <obj_hashval>9d31684b38c83910677038ced6cb1730</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_promoprag_codprag INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_promosub_codpromosub</obj_name>
  <obj_hashval>0aae7587b1434214855f47995db8b77a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_promosub_codpromosub INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_punctaje_codpunctaj</obj_name>
  <obj_hashval>16044afb136a8594df30ba058c3300c0</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_punctaje_codpunctaj INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_punctajvaldoc_cod</obj_name>
  <obj_hashval>051970f5f1ea238490092405b1d45904</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_punctajvaldoc_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_puncteuse_cod</obj_name>
  <obj_hashval>391712eba17ab05e19c72a40b58ae65c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_puncteuse_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_rac_catp_cod</obj_name>
  <obj_hashval>c667a959e3b36899bb7d80e1c3d1bf74</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_rac_catp_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_rac_catp1_cod</obj_name>
  <obj_hashval>82fc1029030310b8e44504b53b3c22fd</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_rac_catp1_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_rac_catp2_cod</obj_name>
  <obj_hashval>39185ae211a18dd98726adb63f89a895</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_rac_catp2_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 131 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_rac_p_cod</obj_name>
  <obj_hashval>30db0e6d028200d86731a96552bd70e8</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_rac_p_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_rac_p0_cod</obj_name>
  <obj_hashval>4dd85d77ad4ec519bea9b9b38e749f2d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_rac_p0_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_rac_p1_cod</obj_name>
  <obj_hashval>3c2bfdebfcefe85f54b96730ab288054</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_rac_p1_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_rac_rez_cod</obj_name>
  <obj_hashval>50770f4f4dae7e7935ae45a7e5ab243f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_rac_rez_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_rac_rezp_cod</obj_name>
  <obj_hashval>3d4b386bdaba3bb47c906901e3eca528</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_rac_rezp_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_rac_rezs_cod</obj_name>
  <obj_hashval>74bf2eb6d6d87e5c4b1395f797530fdf</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_rac_rezs_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_raportp_codraportp</obj_name>
  <obj_hashval>f8a122a07ff910dfff817a883ef2e1cb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_raportp_codraportp INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_raportp0_codraportp0</obj_name>
  <obj_hashval>490ace32bb6b33ccd874b12f11a1057a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_raportp0_codraportp0 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_raportp1_codraportp1</obj_name>
  <obj_hashval>d1f69635b8217429ece163d432407f18</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_raportp1_codraportp1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_raportp2_codraportp2</obj_name>
  <obj_hashval>fb718d4336ccc134cad8de3f83096c45</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_raportp2_codraportp2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_raportp3_codraportp3</obj_name>
  <obj_hashval>2a007be13e239c6384c6ccfc0bddbbdd</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_raportp3_codraportp3 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_rapstocmedist</obj_name>
  <obj_hashval>2d32f561ad0fd4939917e8f613d4d62d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_rapstocmedist INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_reclamatii_codreclamatie</obj_name>
  <obj_hashval>c7a63dbd888d160cb4d8a2d48f5b1625</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_reclamatii_codreclamatie INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 114 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_reclamatii1_codreclamatie1</obj_name>
  <obj_hashval>cce42a0b91ff26b084f851a26fb7da9c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_reclamatii1_codreclamatie1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 114 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_reclamatii2_codreclamatie2</obj_name>
  <obj_hashval>cbe2e60925b62db1d2a57d9730bb4af4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_reclamatii2_codreclamatie2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 262 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_reg_codreg</obj_name>
  <obj_hashval>c5bf4071f061c40644e64974af66bcee</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_reg_codreg INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_reg1_codreg1</obj_name>
  <obj_hashval>d2cbb068251adb78517369d3fad594a1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_reg1_codreg1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_regoss_codregoss</obj_name>
  <obj_hashval>a9223a060b771d91297e85e8b60776cc</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_regoss_codregoss INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_regoss1_codregoss1</obj_name>
  <obj_hashval>cb2b89232e80b42e62764dcaa9f40417</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_regoss1_codregoss1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_regpers1_codregpers1</obj_name>
  <obj_hashval>b93b1cc148341da7a838e091d3e1d66e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_regpers1_codregpers1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_regtrezor1_codregtrezor1</obj_name>
  <obj_hashval>973cf9fc95eb1380b60c5003ce0da61c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_regtrezor1_codregtrezor1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_restartinactive_cod</obj_name>
  <obj_hashval>ffdc2248507ad082947617c2a20f0816</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_restartinactive_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_restaurante_codrestaurant</obj_name>
  <obj_hashval>b080b660223ff3e38f87b21af50881d1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_restaurante_codrestaurant INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_restclase_cod</obj_name>
  <obj_hashval>3f7a99efd6842b0641ebf3ecef9ee6f4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_restclase_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_restcmd_codrestcmd</obj_name>
  <obj_hashval>a4d6f1d6f6f7074f55d8b4a3f9715f8d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_restcmd_codrestcmd INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_restcmd1_codrestcmd1</obj_name>
  <obj_hashval>38d0ab84a565b6d4caf46ce600099f05</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_restcmd1_codrestcmd1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_restgestimplicite_cod</obj_name>
  <obj_hashval>e82d01600dc3b997eafaf95c2e15ade2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_restgestimplicite_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_restgestlistver_cod</obj_name>
  <obj_hashval>94d81292a75b054191f636751a3b83c6</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_restgestlistver_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_restlistgest_cod</obj_name>
  <obj_hashval>4fbd9f9e1c6c3b041c41ee4c60bb63e0</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_restlistgest_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_restnp_codrestnp</obj_name>
  <obj_hashval>d2eb10bceb4b607fd2ea533d60ade404</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_restnp_codrestnp INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_restnp1_codrestnp1</obj_name>
  <obj_hashval>6ca995df675d02e70b9473b1c691e6fb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_restnp1_codrestnp1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_restnp2_codrestnp2</obj_name>
  <obj_hashval>c7db2ac35f9f6d2f812ed2a00c386441</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_restnp2_codrestnp2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_restobiecte_cod</obj_name>
  <obj_hashval>6bdca3af0dd15110d5429e2e97480b72</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_restobiecte_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_restobsart_cod</obj_name>
  <obj_hashval>29496c344e4ec25d24ca943336edf273</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_restobsart_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_restraportz_cod</obj_name>
  <obj_hashval>9da60bf7c2c5c7aeda012278b4ff80b1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_restraportz_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_returo_codreturo</obj_name>
  <obj_hashval>5298dcdb14efe937025ecdadb4c7c9e1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_returo_codreturo INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_returostins_codreturostins</obj_name>
  <obj_hashval>c7162429d7f9487d47fb5cbb709530fb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_returostins_codreturostins INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_rezervats_codrezervats</obj_name>
  <obj_hashval>81bc9678ec81a08e8845b3097db95f24</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_rezervats_codrezervats INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sablondescript_codsablon</obj_name>
  <obj_hashval>f9f6f6aa6284e1b91b7d96e4d768bc24</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sablondescript_codsablon INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sablondescript1_codsablon1</obj_name>
  <obj_hashval>fdabbacc1dd5e06c88eccfc24d193c5e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sablondescript1_codsablon1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_saft</obj_name>
  <obj_hashval>f0f236f3183b7f0b4f26ea72655b8914</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_saft INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_saft_ti</obj_name>
  <obj_hashval>f7cb8b6353f1b1b7460c1a35f3ac3c38</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_saft_ti INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_catret_codcatret</obj_name>
  <obj_hashval>c5e78c110a8ba42f69f958d3bbe552fc</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_catret_codcatret INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_catspor_codcatspor</obj_name>
  <obj_hashval>9e82c888a53b81529d811e4b52a1326d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_catspor_codcatspor INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_contrpp_codcontrpp</obj_name>
  <obj_hashval>5a06ce8dac91417a382f97aaa80849a9</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_contrpp_codcontrpp INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_contrpp1_codcontrpp1</obj_name>
  <obj_hashval>a4d512c5f468498c31cd23cbe1eb5000</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_contrpp1_codcontrpp1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_dedgen_coddedgen</obj_name>
  <obj_hashval>8e16d1a11a7f83eb28aad878d6c76101</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_dedgen_coddedgen INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_dedgen0_coddedgen0</obj_name>
  <obj_hashval>1bd610f6a30c3652a8bbe09c48938e07</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_dedgen0_coddedgen0 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_dedgen1_coddedgen1</obj_name>
  <obj_hashval>9ea49d97a26b4e091f7f3b92115080f9</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_dedgen1_coddedgen1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_fondp_codfondp</obj_name>
  <obj_hashval>e32ea1c4a3b19365c1da1d425a0d9700</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_fondp_codfondp INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_impoz_codimpoz</obj_name>
  <obj_hashval>a0f4527974bec90edb33c6e9e7fc3b14</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_impoz_codimpoz INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_impoz0_codimpoz0</obj_name>
  <obj_hashval>f9c8f247afb7b983f5dd3d23cf6be83d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_impoz0_codimpoz0 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_impoz1_codimpoz1</obj_name>
  <obj_hashval>4eac7c403bf96913ea48b424724f4fc5</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_impoz1_codimpoz1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_nasig_codnasig</obj_name>
  <obj_hashval>253362673c15696a9e5c6e90991abddb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_nasig_codnasig INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_nasig0_codnasig0</obj_name>
  <obj_hashval>fcf5e64c400e1138412433843f66751f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_nasig0_codnasig0 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_nasig1_codnasig1</obj_name>
  <obj_hashval>d9ebad6b38c38a5b574847b9ab3b2a76</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_nasig1_codnasig1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_nasig2_codnasig2</obj_name>
  <obj_hashval>4a7fa72dfa7f2f90a087c68a069e5023</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_nasig2_codnasig2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_nasig3_codnasig3</obj_name>
  <obj_hashval>26d56d488aa282ac1449cd7f083fc5df</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_nasig3_codnasig3 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_ncontrib_codncontrib</obj_name>
  <obj_hashval>f3b1b81f54551617fcd38504e619126f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_ncontrib_codncontrib INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_ncontrib1_codncontrib1</obj_name>
  <obj_hashval>700cca1b3db611301b9fc1124639066f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_ncontrib1_codncontrib1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_ndrep_codndrep</obj_name>
  <obj_hashval>421eecced89b72908c6d5e05eba1fc5d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_ndrep_codndrep INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_ndrep0_codndrep0</obj_name>
  <obj_hashval>47680e887324126fecbfbb1e028b55c2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_ndrep0_codndrep0 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_ndrep1_codndrep1</obj_name>
  <obj_hashval>00ffcdd453f24bd2e67e30346921981c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_ndrep1_codndrep1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_retineri_codretinere</obj_name>
  <obj_hashval>b7caa97f1b4ea48643624e897cee08b7</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_retineri_codretinere INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_retineri0_codretinere0</obj_name>
  <obj_hashval>520e95f2db31880eca1c1782e98cb1ea</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_retineri0_codretinere0 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_sporuri_codspor</obj_name>
  <obj_hashval>0b51714f8198766ff8e65cbc5fbb0ae4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_sporuri_codspor INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_sporuri0_codspor0</obj_name>
  <obj_hashval>f4130c51b8364580768a688bcaaf4664</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_sporuri0_codspor0 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_sporuri1_codspor1</obj_name>
  <obj_hashval>3443e1ec59b1d29dc7bffbc3a4f0eed2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_sporuri1_codspor1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sal_sporuri2_codspor2</obj_name>
  <obj_hashval>16532f9efa768dbefd6b4186a09ec800</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sal_sporuri2_codspor2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sali_codsala</obj_name>
  <obj_hashval>78e9faede4cc63eb2794fcbf8a181cc1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sali_codsala INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_saliuseri_cod</obj_name>
  <obj_hashval>a598d5b18ae8004577168a3b22291df2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_saliuseri_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_scenariilivr_codscenariu</obj_name>
  <obj_hashval>c686258c929cbd142c48c00e760c8ac4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_scenariilivr_codscenariu INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_scenariilivr1_codscenariu1</obj_name>
  <obj_hashval>54b8dfa5cf50be51f930e72b44b2731d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_scenariilivr1_codscenariu1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_scenariilivr2_codscenariu2</obj_name>
  <obj_hashval>ca34ad502bc429b9b8b8d144ab75f8f3</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_scenariilivr2_codscenariu2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 109 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_serie_unica</obj_name>
  <obj_hashval>68169285be6bdbb057e8211a4ba5b597</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_serie_unica INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 249 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_seriicmd_codseriecmd</obj_name>
  <obj_hashval>937937d01bb192416d74c6cfc33ff107</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_seriicmd_codseriecmd INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_seriiies_codserieies</obj_name>
  <obj_hashval>ef448bcc2dfdecc909828d9bfacb21ca</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_seriiies_codserieies INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_seriiintr_codserieintr</obj_name>
  <obj_hashval>00bb8c87c6694eab986996ab94b1289b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_seriiintr_codserieintr INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_seriitransf_codserietransf</obj_name>
  <obj_hashval>6968df8bbff74043fc2872db73337171</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_seriitransf_codserietransf INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_servfact_codservfact</obj_name>
  <obj_hashval>91640121fda07f52095ab1604553f4a4</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_servfact_codservfact INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_servfact1_codservfact1</obj_name>
  <obj_hashval>04e682fc6a4d67d7e8dbeb9bfe62f376</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_servfact1_codservfact1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_servpost_codserviciu</obj_name>
  <obj_hashval>89e45a29ab9d4437f9a521a69bc63073</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_servpost_codserviciu INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_settask_codtask</obj_name>
  <obj_hashval>1e8e25225547e7c622bc611675fce19f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_settask_codtask INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 320 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_settasklog_codlog</obj_name>
  <obj_hashval>8649ceb941c5d9b1600257610241984c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_settasklog_codlog INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_settaskobj_codtaskobj</obj_name>
  <obj_hashval>499138bf6025d14e4c4691998cd455f6</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_settaskobj_codtaskobj INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sgrcolect_codsgrcolect</obj_name>
  <obj_hashval>be00100dc6f0a01bd3228331d0330f2a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sgrcolect_codsgrcolect INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sgrcolect1_codsgrcolect1</obj_name>
  <obj_hashval>79b856bc6dccef80706cde54077a178e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sgrcolect1_codsgrcolect1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sintezaemul1_codsinteza1</obj_name>
  <obj_hashval>7936c8b44706a2ba8496112170d44beb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sintezaemul1_codsinteza1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sintezaemul2_codsinteza2</obj_name>
  <obj_hashval>7990b1adbdfe72b75d46eb71790f3203</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sintezaemul2_codsinteza2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sintezaemulare_codsinteza</obj_name>
  <obj_hashval>9adb9bdc018870401d23f17e81fe0cbc</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sintezaemulare_codsinteza INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sitfin_codsitfin</obj_name>
  <obj_hashval>cdb2e55b7936e3473692aa6215dd914b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sitfin_codsitfin INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sitfinalte_codalte</obj_name>
  <obj_hashval>9015adc6685e7ff3dcb8e1a499918d2a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sitfinalte_codalte INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sitfinbuget_codsitfinbuget</obj_name>
  <obj_hashval>6a7b8ef8d7ff8e5fc4fa79f5550670a1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sitfinbuget_codsitfinbuget INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sitfincol_codcoloana</obj_name>
  <obj_hashval>3e174988e278199210cba3bf5bacf9e9</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sitfincol_codcoloana INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sitfinlin_codlinie</obj_name>
  <obj_hashval>eecc86e65abeaedd14a50722fed02776</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sitfinlin_codlinie INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_smsuri_codsms</obj_name>
  <obj_hashval>753a3e85baa68bf999d171accf1898e5</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_smsuri_codsms INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_soldcashflow_codsold</obj_name>
  <obj_hashval>beea68ee64cb5aa7063b9737a0ad5121</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_soldcashflow_codsold INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_soldini_codsoldini</obj_name>
  <obj_hashval>c03740b3d6669c6f0a82a002c9fe9466</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_soldini_codsoldini INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_soldpart_codsoldpart</obj_name>
  <obj_hashval>110be0fe42593dcc177544468c5490d8</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_soldpart_codsoldpart INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_soldpersini_codsoldpersini</obj_name>
  <obj_hashval>4628c23aa2ebc7a8605d911aa0816d9f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_soldpersini_codsoldpersini INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_splitchelt_codsplitchelt</obj_name>
  <obj_hashval>3150d537c964da98c4e2a3f0c3c061e2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_splitchelt_codsplitchelt INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_splitchelt1_codsplitchelt1</obj_name>
  <obj_hashval>1651ffb0414a291d93ed37367e411279</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_splitchelt1_codsplitchelt1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_spvarhiva_codspvarhiva</obj_name>
  <obj_hashval>6193726ae93bcec187a30ca999b062de</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_spvarhiva_codspvarhiva INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_stareestimari_codstare</obj_name>
  <obj_hashval>302bb58cafd5b60d4a869ae14615e5fd</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_stareestimari_codstare INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_stareestimari1_codstare1</obj_name>
  <obj_hashval>391406705b895d089123beeab7d9d0cb</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_stareestimari1_codstare1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_stareestimari2_codstare2</obj_name>
  <obj_hashval>6dca6543f17e754ec9cf0b86b7163d9c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_stareestimari2_codstare2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_statcon_codstatcon</obj_name>
  <obj_hashval>872ae0962c6bafaa610da1e6e9188d73</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_statcon_codstatcon INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_statcor_codstatcor</obj_name>
  <obj_hashval>eab1154f1791e50948c5bf3ab157921b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_statcor_codstatcor INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_statcor1_codstatcor1</obj_name>
  <obj_hashval>7733bb0b298287e24c038932446c8c3a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_statcor1_codstatcor1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 103 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_statusdecl</obj_name>
  <obj_hashval>4e396b48425005157e75a612f90effe7</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_statusdecl INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 166 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_stingere_codstingere</obj_name>
  <obj_hashval>540c108e05f96410b38ca9def093e295</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_stingere_codstingere INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_stobjasoc_codstobjasoc</obj_name>
  <obj_hashval>632b751182348dd4c93d5fd517ea5930</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_stobjasoc_codstobjasoc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_stocfake_codstocfake</obj_name>
  <obj_hashval>74c3328b4459300a5a87bf62063e4e75</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_stocfake_codstocfake INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_stocfake1_codstocfake1</obj_name>
  <obj_hashval>0180b285154e6f70438cbc3cfa66469a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_stocfake1_codstocfake1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_stocini_codstocini</obj_name>
  <obj_hashval>73eb9d489a8a304ebaf52b91f445dc46</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_stocini_codstocini INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_stocposuri_codstocposuri</obj_name>
  <obj_hashval>b38a2ba4e4059b6859a935be3ae4a1c2</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_stocposuri_codstocposuri INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_stocvalini_codstocvalini</obj_name>
  <obj_hashval>50e0c0859f46037eae7ed33635d17952</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_stocvalini_codstocvalini INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_stocvalluna_codstocvalluna</obj_name>
  <obj_hashval>247f5649370f618cf459cd9e9d65a93d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_stocvalluna_codstocvalluna INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_stornocmdf_cod</obj_name>
  <obj_hashval>a9ef631db781f6af5a4663dbc84caa43</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_stornocmdf_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_syncpartretail_codsyncpart</obj_name>
  <obj_hashval>1237dc6c8e69c231db11d1c8fa2c58af</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_syncpartretail_codsyncpart INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_syncpromoretail_codsync</obj_name>
  <obj_hashval>5ee1d07804c5fd36f796cc918cb15d84</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_syncpromoretail_codsync INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_sysnpretretail_codsync</obj_name>
  <obj_hashval>a6abc7d663e9cb3337e953c772c5dcc9</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_sysnpretretail_codsync INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_targetag_codtargetag</obj_name>
  <obj_hashval>6a0f08ec67ad16d46e8e94b81905c545</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_targetag_codtargetag INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 123 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_targetag1_codtargetag1</obj_name>
  <obj_hashval>25a2e6ae50aee871f46c3942f4e1880c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_targetag1_codtargetag1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 123 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_tarifeman_codtarif</obj_name>
  <obj_hashval>41dec91491622c93fe707e09260e5a9c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_tarifeman_codtarif INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_tarifeman1_codtarif1</obj_name>
  <obj_hashval>9fe7e491ea19a268a75da6b95aa37690</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_tarifeman1_codtarif1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_tarifemaster_codtarifm</obj_name>
  <obj_hashval>e78452069878c0bcf515b6e380bcbdcd</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_tarifemaster_codtarifm INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_taxdecl_codtaxdecl</obj_name>
  <obj_hashval>7104d0b6005adfaea986ec12b2bf748d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_taxdecl_codtaxdecl INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_teme_codtema</obj_name>
  <obj_hashval>038f2ffb95a591c8f1347249bc627f8c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_teme_codtema INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_termenecmd_codtermen</obj_name>
  <obj_hashval>6cec65c7bba5bbfcaf21ee616211a52d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_termenecmd_codtermen INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_tesaturi_codtesatura</obj_name>
  <obj_hashval>c43c9d3b6d448e601b7f430e9eb723a8</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_tesaturi_codtesatura INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 143 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_tipchelt_codtipchelt</obj_name>
  <obj_hashval>779e641d1ee49868439fd46e856e2746</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_tipchelt_codtipchelt INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_tiplucrarisa_codtiplucrare</obj_name>
  <obj_hashval>2de501018dc785bb396f9b577d639ae5</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_tiplucrarisa_codtiplucrare INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 104 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_tiplucrarisa1_codtiplucr1</obj_name>
  <obj_hashval>33c55b617e0905a16a80257ab029d5ec</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_tiplucrarisa1_codtiplucr1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 130 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_tippartincert_cod</obj_name>
  <obj_hashval>dcbf90e32f0a7e5e6148608a634c985d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_tippartincert_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_tipsedii1_codtipsediu1</obj_name>
  <obj_hashval>e672ec5423dbbf828f402339ef5cb396</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_tipsedii1_codtipsediu1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_tipuriplati_codtipplata</obj_name>
  <obj_hashval>b69408b6bd5688bfe61818d2e767a51c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_tipuriplati_codtipplata INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_tmp_pluna_codpluna</obj_name>
  <obj_hashval>40e749d0bacdbada8ae5348f6aae2491</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_tmp_pluna_codpluna INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 2381 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_totalpuncte_cod</obj_name>
  <obj_hashval>6f66e65880a5794a5611e4fb0a7dddd1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_totalpuncte_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_toword_codtoword</obj_name>
  <obj_hashval>4613ed1062ff47c52617593c49d9bd01</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_toword_codtoword INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_transacard_codtransacard</obj_name>
  <obj_hashval>c9363bef5ccebcee8f5dff8a1624a709</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_transacard_codtransacard INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_transf_codtransf</obj_name>
  <obj_hashval>9b63ad5a867ad816b78de124c2654e14</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_transf_codtransf INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_transf1_codtransf1</obj_name>
  <obj_hashval>94a9ae8f8fac4ec67d3e2acb10165741</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_transf1_codtransf1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_transport_codtransport</obj_name>
  <obj_hashval>75c3d4b9ee65635de6869c40768dd42e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_transport_codtransport INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_transport1_codtransport1</obj_name>
  <obj_hashval>3a9220351c48e2cac917748fd628831b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_transport1_codtransport1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_transport2_codtransport2</obj_name>
  <obj_hashval>d7bd748545467e629b77e5b0b8d60bf0</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_transport2_codtransport2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_traseu_codtraseu</obj_name>
  <obj_hashval>918592e60af5ac9695cd4f0846a04e0b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_traseu_codtraseu INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_traseulivr_codtraseulivr</obj_name>
  <obj_hashval>85c363fbb6e7cf87223bd0d96a7e87dc</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_traseulivr_codtraseulivr INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_trezor_codtrezor</obj_name>
  <obj_hashval>32eb8d85fbb13d3e70dd614b984a539e</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_trezor_codtrezor INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_trezor1_codtrezor1</obj_name>
  <obj_hashval>8603b7d07652120a33e9758ece80bc84</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_trezor1_codtrezor1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_trigar_codtrigar</obj_name>
  <obj_hashval>1360c5914ed751d7bc78db797e75bae6</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_trigar_codtrigar INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_trigar1_codtrigar1</obj_name>
  <obj_hashval>ecc47a685f3b2f08cbafca89c944aeaa</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_trigar1_codtrigar1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_tvadisc_codtvadisc</obj_name>
  <obj_hashval>b1895036e9f07f96407f216cd8061da1</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_tvadisc_codtvadisc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_tvamonetar_codtvamonetar</obj_name>
  <obj_hashval>ad112ace696068c5f24539f0433c060a</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_tvamonetar_codtvamonetar INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_tvaserv_codtvaserv</obj_name>
  <obj_hashval>ef1451cdd5d09ee98079ec4372014f25</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_tvaserv_codtvaserv INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_tvaserv1_codtvaserv1</obj_name>
  <obj_hashval>1168d6a61cf2b8e19b20ad54526a1288</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_tvaserv1_codtvaserv1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_user_lists_listid</obj_name>
  <obj_hashval>9c15867bb4d7b7871cbc44771fad1747</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_user_lists_listid INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 10001 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_usersql_codsql</obj_name>
  <obj_hashval>96c1520e7fa56bf57c9aae5200364064</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_usersql_codsql INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_usersql1_codsql1</obj_name>
  <obj_hashval>540bfad58d191e3d0afa1de90a4a2fed</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_usersql1_codsql1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_usersql2_codsql2</obj_name>
  <obj_hashval>763c94639bf37ac492dd72223d5c7d61</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_usersql2_codsql2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_utilaje_codutilaj</obj_name>
  <obj_hashval>966d39654654af252cd3f8377cd3c500</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_utilaje_codutilaj INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_utilaje1_codutilaj1</obj_name>
  <obj_hashval>98ba3b0267cd10d8e40376f07d8aa295</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_utilaje1_codutilaj1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_utilaje2_codutilaj2</obj_name>
  <obj_hashval>98894891d1c5bc737b6c8a999eb79754</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_utilaje2_codutilaj2 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_utilaje20_codutilaj20</obj_name>
  <obj_hashval>8e455805b62c0b5b05dbdb8f9404379c</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_utilaje20_codutilaj20 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_utilaje2c_codutilaj2c</obj_name>
  <obj_hashval>e3c0f7973656e61ca2cf28e643d74255</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_utilaje2c_codutilaj2c INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_utilaje2p_codutilaj2p</obj_name>
  <obj_hashval>a61cee4a739b956551883b57f7fcc781</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_utilaje2p_codutilaj2p INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_utilaje3_codutilaj3</obj_name>
  <obj_hashval>7959dad617cb58b99683f3d4d366b48f</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_utilaje3_codutilaj3 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_utilajemon_codmonitorizare</obj_name>
  <obj_hashval>7b159549728b19928ba28e092c4f51be</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_utilajemon_codmonitorizare INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_utilajetipindex_codtindex</obj_name>
  <obj_hashval>eb7ea78728ea97f63ff5d5c8365a7def</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_utilajetipindex_codtindex INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_valatrexceptii_cod</obj_name>
  <obj_hashval>eeb519dd1efa2c4b7e6c2aeecc201629</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_valatrexceptii_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_vanzari_codvanzare</obj_name>
  <obj_hashval>fb8e05b70db9f6b260e2e234401a42c3</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_vanzari_codvanzare INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_view_joins_codview_joins</obj_name>
  <obj_hashval>2d5884f4a3d58073a810ff2dca88ceef</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_view_joins_codview_joins INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 118 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_voucher_codvoucher</obj_name>
  <obj_hashval>b28bdd2a8b92bbe3a7143723ad52f123</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_voucher_codvoucher INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 113 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_vouchercadou_cod</obj_name>
  <obj_hashval>a227f5cdb7941626db5175dc3854e313</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_vouchercadou_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_vouchercadoulink_cod</obj_name>
  <obj_hashval>0262a0cfeefdec9c4a643ad54f86f9e8</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_vouchercadoulink_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_voucherlink_cod</obj_name>
  <obj_hashval>45b06de6a4107f9779d6e9861243134b</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_voucherlink_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_weekcashflow_codcashflow</obj_name>
  <obj_hashval>c6353bac44488a83749aae0782811e10</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_weekcashflow_codcashflow INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_weekcashflow1_codcashflow1</obj_name>
  <obj_hashval>c0b013d2636dfa3225ede651ae0cd0ea</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_weekcashflow1_codcashflow1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_weekcashplati_codcashplati</obj_name>
  <obj_hashval>b29efdcb353b9259af9e1a0e3305535d</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_weekcashplati_codcashplati INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_weekcashsold_codsold</obj_name>
  <obj_hashval>17db028112d2bbde330027793fd30413</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_weekcashsold_codsold INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_zeuro_cod</obj_name>
  <obj_hashval>3f2c67f083ed4a89c3f46cf9e85a5296</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_zeuro_cod INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_zineluc_codzineluc</obj_name>
  <obj_hashval>4629eb8464bef15a1e1be724afc71931</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_zineluc_codzineluc INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_zineluc1_codzineluc1</obj_name>
  <obj_hashval>db7329f279e013aeb81b49922ba57072</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_zineluc1_codzineluc1 INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 102 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_prodestprj_processlist</obj_name>
  <obj_hashval>464f4b6e6cc63904c2d81361d42b7073</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_prodestprj_processlist(tmpname character varying, alistid numeric DEFAULT 0, alistver numeric DEFAULT 0)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  sInsert     VARCHAR(1000);
  sWith       VARCHAR(10000);
  sSelect     VARCHAR(30000);
  AnLunaLucru numeric(20);
  VUSERID     numeric(20);
  vSelStocReal VARCHAR(5000);
  NivelMaxim numeric(5);
  CanProd boolean;
  vStoc numeric(20,7);
  i numeric(5);
  gUserFields      VARCHAR := '';
  gUserAlias       VARCHAR := '';
  gNullAlias       VARCHAR := '';
  gSuplJoins       VARCHAR := '';
  gSuplCols        varchar:= 'tmp_proiectnod_lans tmp, nartobj o';
  v_rec            record;
  v_mat            record;
BEGIN
  --Florin 18.12.2025 - fixat 67614
  --Florin 03.06.2025
  VUSERID := GETUSERID();
  call pkg_list_struct_startsuplcols();
  CALL pkg_list_struct_getsuplcols(aLISTID, alistver, gUserFields, gUserAlias, gNullAlias, gSuplJoins, gSuplCols);
  PERFORM set_config('PKG_LIST_BASE_PRODESTPRJ.gSuplCols',gSuplCols,false);
  gUserFields := coalesce(gUserFields,'');
  gUserAlias  := coalesce(gUserAlias ,'');
  gNullAlias  := coalesce(gNullAlias ,'');
  gSuplJoins  := coalesce(gSuplJoins ,'');
  gSuplCols   := coalesce(gSuplCols  ,'');
  delete FROM tmp_proiectnod_lans;
  insert into tmp_proiectnod_lans(
    codproiectnod,codproiect,cant,nodoriginal,pozitie,codreteta,
    tip,codobiect,indexparinte,codprodmat,nivel,ordine,decalaj,
    denumire,obs,identificator,datadocumentatie,arhiva,
    proiectant,necesar,codgest,denum,umsec,codextern,
    d1,d2,d3,relatieum1,paritated1,paritated2,paritated3,cantum1,
    totalrezervat, totalrealizat)
  SELECT
    PN.CODPROIECTNOD,PN.CODPROIECT,PN.CANT,coalesce(PN.NODORIGINAL,0),coalesce(PN.POZITIE,0),PN.CODRETETA,
    PN.TIP,OBJ.CodObiect,PN.IndexParinte,PN.CODPRODMAT,coalesce(PN.Nivel,0), PN.Ordine,PN.DECALAJ,
    OBJ.DENUMIRE,PC.OBS,PC.IDENTIFICATOR,PC.DATADOCUMENTATIE,PC.ARHIVA,
    PC.PROIECTANT,0,retete.CodGest,NUM.DEN_UM,NUM1.CodUM1,OBJ.CODEXTERN,
    PMAT.D1,PMAT.D2,PMAT.D3,NART.RELATIEUM1,NVL(NART.PARITATED1,0),NVL(NART.PARITATED2,0),NVL(NART.PARITATED3,0),nart.um1,
    0,0
  FROM PROIECTNOD PN
       INNER JOIN PROIECT P ON PN.Codproiect = P.CodProiect
       INNER JOIN PROIECTNOD PN0 ON P.CODPROIECT = PN0.CODPROIECT AND nvl(PN0.NODORIGINAL, 0) = 0
       LEFT  JOIN NARTOBJ OBJ ON PN.CODOBIECT = OBJ.CODOBIECT
       LEFT  JOIN NART ON OBJ.CODARTICOL = NART.CodARTICOL
       LEFT  JOIN NUM ON NART.Um = NUM.CODUM
       LEFT  JOIN NUM1 ON NUM.CODUM = NUM1.CODUM and NVL(NUM1.SECUNDARA, 0) = 0
       LEFT  JOIN PRODCOMP PC ON PN.CodReteta = PC.CodProdComp
       LEFT  JOIN PRODMAT PMAT ON PMAT.CodMAT = PN.CodProdMAT
       LEFT  JOIN (select RET.CodProdComp, PG.CodGest
                   from prodcomp ret
                        left join prodgest pg on pg.codprodcomp = ret.codprodcomp and NVL(pg.indexlocal,1) = 1
                  ) retete on PN.Codreteta = retete.codprodcomp
  WHERE pn.codproiect = current_setting('PKG_LIST_BASE_NAPROVIZ1.vCodProiect', true)::numeric;
  update tmp_proiectnod_lans set denumire = lpad(denumire,length(denumire)+nivel*4, ' ');
  update tmp_proiectnod_lans set indexparinte = case when substr(indexparinte,1,1) = '.' then substr(indexparinte,2,length(indexparinte) - 1) else indexparinte end;
  update tmp_proiectnod_lans l set copii = (select sum(1) from tmp_proiectnod_lans c where c.nodoriginal = l.codproiectnod);
  vSelStocReal := '
      SELECT NS.CODOBIECT, SUM(NS.REST) CANT
      FROM NIRSTOC NS
        INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
        INNER JOIN NGEST G ON G.CodGest = N.GEST
        INNER JOIN NARTOBJ O ON O.CodObiect = NS.CodObiect
      WHERE NS.REST &gt; 0 AND COALESCE(O.INACTIV,0) = 0 AND NS.CODOBIECT IN (SELECT CODOBIECT FROM TMP_PROIECTNOD_LANS)';
  vSelStocReal := vSelStocReal || '
        AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = ''CODGEST'' AND VALOARE = N.GEST::varchar) ';
  if current_setting('PKG_LIST_BASE_NAPROVIZ1.vAllIOArt', true)::boolean then
    vSelStocReal := vSelStocReal || '
        AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = ''CODIOART'' AND VALOARE = NS.CODIOART::varchar ) ';
  end if;
  vSelStocReal := vSelStocReal ||'
      GROUP BY NS.CODOBIECT';

  DELETE FROM TMP_STOCREAL;
  sSelect := 'insert into tmp_stocreal(codobiect,cant) '||vSelStocReal;
  PERFORM LIST_EXECUTE_IMMEDIATE(sselect, aListID, aListVer);

  update tmp_proiectnod_lans tmp
  set
    tip = case
            when COALESCE(tmp.nodoriginal, 0) = 0 then 0
            when (select count(*) from proiectnod p where p.nodoriginal = tmp.codproiectnod) &gt; 0 then 1
            else 3
          end;
  update tmp_proiectnod_lans tmp
  set
    stoc = (select s.cant from tmp_stocreal s where s.codobiect = tmp.codobiect);

 if pkg_list_base_prodestprj_Estimeaza() then
    update tmp_proiectnod_lans tmp
    set
      stocmin = (select s.cant from tmp_stocreal s where s.codobiect = tmp.codobiect);
  else
    update tmp_proiectnod_lans set totalrezervat = 0, totalrealizat = 0, necesar = 0, necesaraut = 0;
    update tmp_stocreal set cantum1 = 0;
    PERFORM pkg_list_base_prodestprj_Rezolva();
    update tmp_proiectnod_lans tmp
    set
      stocmin = (select s.cant from tmp_stocreal s where s.codobiect = tmp.codobiect);
  end if;

  sInsert :=
   'INSERT INTO '||tmpName ||'
     (
      Denumire,
      UM,
      Cant,
      CodExtern,
      CodIntern,
      Producator,
      Nivel,
      Pozitie,
      IndexParinte,
      Stoc,
      StocMin,
      Lansat,
      Necesar,
      NecesarAut,
      Copii '||gUserFields||')';

  sSelect := '
    select
      tmp.Denumire,
      tmp.denUM,
      tmp.Cant,
      o.CodExtern,
      o.CodIntern,
      prod.den_part,
      tmp.Nivel,
      tmp.Pozitie,
      tmp.IndexParinte,
      coalesce(tmp.stoc,0),
      coalesce(s.cant,0),
      tmp.Lansat,
      tmp.necesar,
      tmp.necesaraut,
      tmp.Copii '||gUserAlias||'
      from tmp_proiectnod_lans tmp
           inner join nartobj o on tmp.codobiect = o.codobiect
           left join npart prod on prod.codpart = o.codproducator
           left join tmp_stocreal s on s.codobiect = tmp.codobiect
        '||gSuplJoins;

  PERFORM LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  PERFORM LIST_EXECUTE_IMMEDIATE('update '||tmpName||' set codextern = lpad(codextern,length(codextern)+nivel*4, '' '')', aListID, aListVer);
  PERFORM LIST_EXECUTE_IMMEDIATE('update '||tmpName||' set codintern = lpad(codintern,length(codintern)+nivel*4, '' '')', aListID, aListVer);
  PERFORM LIST_EXECUTE_IMMEDIATE('update '||tmpName||' set stocs = case when stoc &gt; 0 then case when stoc = trunc(stoc) then to_char(stoc,''fm9999999999'') else to_char(stoc,''fm9999999990D9999999'') end end', aListID, aListVer);
  PERFORM LIST_EXECUTE_IMMEDIATE('update '||tmpName||' set stocmins = case when stocmin &gt; 0 then case when stocmin = trunc(stocmin) then to_char(stocmin,''fm9999999999'') else to_char(stocmin,''fm9999999990D9999999'') end end', aListID, aListVer);
  PERFORM LIST_EXECUTE_IMMEDIATE('update '||tmpName||' set lansats = case when lansat &gt; 0 then case when lansat = trunc(lansat) then to_char(lansat,''fm9999999999'') else to_char(lansat,''fm9999999990D9999999'') end end', aListID, aListVer);
  PERFORM LIST_EXECUTE_IMMEDIATE('update '||tmpName||' set necesars = case when necesar &gt; 0 then case when necesar = trunc(necesar) then to_char(necesar,''fm9999999999'') else to_char(necesar,''fm9999999990D9999999'') end end', aListID, aListVer);
  PERFORM LIST_EXECUTE_IMMEDIATE('update '||tmpName||' set necesarauts = case when necesaraut &gt; 0 then case when necesaraut = trunc(necesaraut) then to_char(necesaraut,''fm9999999999'') else to_char(necesaraut,''fm9999999990D9999999'') end end', aListID, aListVer);
  PERFORM LIST_EXECUTE_IMMEDIATE('update '||tmpName||' set cants = case when cant &gt; 0 then case when cant = trunc(cant) then to_char(cant,''fm9999999999'') else to_char(cant,''fm9999999990D9999999'') end end', aListID, aListVer);
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regoss_sp_postrecords</obj_name>
  <obj_hashval>34ba2406a4ef946f077c184a4e05ff46</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regoss_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  NR NUMERIC(20);
  TMP_NR NUMERIC(20);
  v_rec record;
  V_REC_SUB record;
BEGIN
  --Florin 05.12.2022 - fixat 56437, 56443, 56444
  --Florin 30.11.2022 - sinc Oracle (23-28.12.2022)
  --Florin 24.11.2022 - sinc. Oracle
  --Florin 17.11.2022 - sinc. Oracle (8-16.11.2022)
  --Florin 04.11.2022 - sinc. Oracle
  IF Operation = 0 THEN
      -- UPDATE
      SELECT CodRegOSS INTO RecID FROM TMP_REGOSS;
      UPDATE REGOSS
         SET (CODREGOSS,
              TIPREG,
              NRDOC,
              DATADOC,
              TRIMESTRUL,
              CODBANK,
              CODMONEDA,
              CURS,
              DIRTY,
              OBS,
              CODSUBUNIT,
              AN,
              LUNA,
              CODGEST,
              CODANALIZA,
              CODANALIZANOD,
              CODCENTRU,
              CURS_IFRS) =
             (SELECT CODREGOSS,
                     TIPREG,
                     NRDOC,
                     DATADOC,
                     TRIMESTRUL,
                     CODBANK,
                     CODMONEDA,
                     CURS,
                     DIRTY,
                     OBS,
                     CODSUBUNIT,
                     AN,
                     LUNA,
                     CODGEST,
                     CODANALIZA,
                     CODANALIZANOD,
                     CODCENTRU,
                     CURS_IFRS
                FROM TMP_REGOSS)
       WHERE CODREGOSS = RecID;

      DELETE FROM REGOSS1 WHERE CODREGOSS = RecID;

      INSERT INTO REGOSS1
        (CODREGOSS1,
         CODREGOSS,
         CODDOC,
         TIPDOC,
         TVADOCVAL,
         TVADOC,
         TVADOCREG,
         CODGEST,
         CONT,
         SEMN,
         CURS,
         SEMNIFICATIE)
        (SELECT NEXTVAL('SEQ_REG1_CODREG1'),
                RecID,
                CODDOC,
                TIPDOC,
                TVADOCVAL,
                TVADOC,
                TVADOCREG,
                CODGEST,
                CONT,
                SEMN,
                CURS,
                SEMNIFICATIE
           FROM TMP_REGOSS1);
      DELETE FROM JURNAL1 WHERE TIPDOC = 108 AND CODDOC = RECID AND CODJURNAL1 NOT IN (SELECT CODJURNAL1 FROM TMP_JURNAl1);
      FOR V_REC IN
        (SELECT * FROM TMP_JURNAL1)
      LOOP
        IF V_REC.CODJURNAL1 &gt; 0 THEN
          UPDATE JURNAL1
          SET
            CODDOC = V_REC.CODDOC,
            TIPDOC = V_REC.TIPDOC,
            INDEXLOCAL = V_REC.INDEXLOCAL,
            CODBAZAD = V_REC.CODBAZAD,
            ICONTBAZAD = V_REC.ICONTBAZAD,
            TIPBAZAD = V_REC.TIPBAZAD,
            CODBAZAC = V_REC.CODBAZAC,
            ICONTBAZAC = V_REC.ICONTBAZAC,
            TIPBAZAC = V_REC.TIPBAZAC,
            CODDESCRD = V_REC.CODDESCRD,
            ICONTD = V_REC.ICONTD,
            TIPCONTD = V_REC.TIPCONTD,
            ANALITICCONTD = V_REC.ANALITICCONTD,
            CODDESCRC = V_REC.CODDESCRC,
            ICONTC = V_REC.ICONTC,
            TIPCONTC = V_REC.TIPCONTC,
            ANALITICCONTC = V_REC.ANALITICCONTC,
            GEST = V_REC.GEST,
            VALOARE = V_REC.VALOARE,
            VALOAREV = V_REC.VALOAREV,
            OBS = V_REC.OBS,
            AN = V_REC.AN,
            LUNA = V_REC.LUNA,
            DIRTY = V_REC.DIRTY,
            SUBUNITATEA = V_REC.SUBUNITATEA,
            CODCENTRU     = V_REC.CODCENTRU,
            CODANALIZANOD = V_REC.CODANALIZANOD,
            DATADOC = V_REC.DATADOC,
            DOCUMENT = V_REC.DOCUMENT
          WHERE CODJURNAL1 = V_REC.CODJURNAL1;
        ELSE
          INSERT INTO JURNAL1
            (
              CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL,
              CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,
              CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC,
              GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, DOCUMENT,CODCENTRU,CODANALIZANOD
            )
          VALUES
            (
              NEXTVAL('SEQ_JURNAL1_CODJURNAL1'), RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL,
              V_REC.CODBAZAD, V_REC.ICONTBAZAD, V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,
              V_REC.CODBAZAC, V_REC.ICONTBAZAC, V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC,
              V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT,V_REC.CODCENTRU,V_REC.CODANALIZANOD
            );
        END IF;
      END LOOP;

      DELETE FROM JURNAL WHERE TIPDOC = 108 AND CODDOC = RECID AND CODJURNAL NOT IN (SELECT CODJURNAL FROM TMP_JURNAl);

      FOR V_REC IN
        (SELECT * FROM TMP_JURNAL)
      LOOP
        IF V_REC.CODJURNAL &gt; 0 THEN
          UPDATE JURNAL
          SET
            CODDOC = V_REC.CODDOC,
            TIPDOC = V_REC.TIPDOC,
            INDEXLOCAL = V_REC.INDEXLOCAL,
            CONTD = V_REC.CONTD,
            CONTC = V_REC.CONTC,
            GEST = V_REC.GEST,
            VALOARE = V_REC.VALOARE,
            VALOAREV = V_REC.VALOAREV,
            OBS = V_REC.OBS,
            AN = V_REC.AN,
            LUNA = V_REC.LUNA,
            SUBUNITATEA = V_REC.SUBUNITATEA,
            DATADOC = V_REC.DATADOC,
        CODCENTRU     = V_REC.CODCENTRU,
        CODANALIZANOD = V_REC.CODANALIZANOD,
            DOCUMENT = V_REC.DOCUMENT
          WHERE CODJURNAL = V_REC.CODJURNAl;
        ELSE
          INSERT INTO JURNAL
            (
              CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL,
              CONTD, CONTC, GEST, VALOARE, VALOAREV,
              OBS, AN, LUNA, SUBUNITATEA, DATADOC, DOCUMENT,CODCENTRU,CODANALIZANOD
            )
          VALUES
            (
              NEXTVAL('SEQ_JURNAL_CODJURNAL'), RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL,
              V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV,
              V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT,V_REC.CODCENTRU,V_REC.CODANALIZANOD
            );
        END IF;
      END LOOP;
    ELSE
      -- INSERT
      SELECT NEXTVAL('SEQ_REGOSS_CODREGOSS') INTO RecID;
      INSERT INTO REGOSS
        (CODREGOSS,
         TIPREG,
         NRDOC,
         DATADOC,
         TRIMESTRUL,
         CODBANK,
         CODMONEDA,
         CURS,
         DIRTY,
         OBS,
         CODSUBUNIT,
         AN,
         LUNA,
         CODGEST,
         CODANALIZA,
         CODANALIZANOD,
         CODCENTRU,
         CURS_IFRS)
        (SELECT RecID,
                TIPREG,
                NRDOC,
                DATADOC,
                TRIMESTRUL,
                CODBANK,
                CODMONEDA,
                CURS,
                DIRTY,
                OBS,
                CODSUBUNIT,
                AN,
                LUNA,
                CODGEST,
                CODANALIZA,
                CODANALIZANOD,
                CODCENTRU,
                CURS_IFRS
           FROM TMP_REGOSS);

      INSERT INTO REGOSS1
        (CODREGOSS1,
         CODREGOSS,
         CODDOC,
         TIPDOC,
         TVADOCVAL,
         TVADOC,
         TVADOCREG,
         CODGEST,
         CONT,
         SEMN,
         CURS,
         SEMNIFICATIE)
        (SELECT NEXTVAL('SEQ_REG1_CODREG1'),
                RecID,
                CODDOC,
                TIPDOC,
                TVADOCVAL,
                TVADOC,
                TVADOCREG,
                CODGEST,
                CONT,
                SEMN,
                CURS,
                SEMNIFICATIE
           FROM TMP_REGOSS1);
      INSERT INTO JURNAL1
          (
            CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL,
            CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,
            CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC,
            GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC,CODCENTRU,CODANALIZANOD
          )
          (
            SELECT
              NEXTVAL('SEQ_JURNAL1_CODJURNAL1'), RECID, TIPDOC, INDEXLOCAL,
              CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,
              CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC,
              GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC,CODCENTRU,CODANALIZANOD
            FROM TMP_JURNAL1
          );
        INSERT INTO JURNAL
          (
            CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL,
            CONTD, CONTC, GEST, VALOARE, VALOAREV,
            OBS, AN, LUNA, SUBUNITATEA, DATADOC,CODCENTRU,CODANALIZANOD
          )
          (
            SELECT
              NEXTVAL('SEQ_JURNAL_CODJURNAL'), RECID, TIPDOC, INDEXLOCAL,
              CONTD, CONTC, GEST, VALOARE, VALOAREV,
              OBS, AN, LUNA, SUBUNITATEA, DATADOC,CODCENTRU,CODANALIZANOD
            FROM
              TMP_JURNAL
          );
    END IF;

      -- ACTUALIZARE RULAJE CONTURI
    FOR V_REC IN
      (SELECT * FROM TMP_RULAJ)
    LOOP
      SELECT COUNT(*) INTO TMP_NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = getANLUCRU() AND LUNA = getLUNALUCRU();
      IF TMP_NR = 0 THEN
        INSERT INTO NCONTRUL
          (
            CODCONTRUL, CODCONT,
            RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
            AN, LUNA
          )
        VALUES
          (
            NEXTVAL('SEQ_NCONTRUL_CODCONTRUL'), V_REC.CODCONT,
            0, 0, 0, 0, 0, 0, 0, 0,
            getANLUCRU(), getLUNALUCRU()
          );
      END IF;
      UPDATE NCONTRUL SET
        RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = 'D' THEN V_REC.VALOARE ELSE 0 END),
        RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = 'C' THEN V_REC.VALOARE ELSE 0 END),
        RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = 'D' THEN V_REC.VALOAREV ELSE 0 END),
        RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = 'C' THEN V_REC.VALOAREV ELSE 0 END)
      WHERE
        CODCONT = V_REC.CODCONT AND AN = getANLUCRU() AND LUNA = getLUNALUCRU();

     IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
       FOR V_REC_SUB IN
         (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = getANLUCRU() AND LUNA = getLUNALUCRU())
       LOOP
         SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
         IF NR = 0 THEN
           INSERT INTO NCONTRULSUB
             (
               CODCONTRULSUB, CODCONTRUL,
               RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
               SUBUNITATEA
             )
           VALUES
             (
               NEXTVAL('SEQ_NCONTRULSUB_CODRULSUB'), V_REC_SUB.CODCONTRUL,
               0, 0, 0, 0, 0, 0, 0, 0,
               V_REC.SUBUNITATEA
             );
         END IF;
         UPDATE NCONTRULSUB
         SET
           RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = 'D' THEN V_REC.VALOARE  ELSE 0 END),
           RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = 'C' THEN V_REC.VALOARE  ELSE 0 END),
           RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = 'D' THEN V_REC.VALOAREV ELSE 0 END),
           RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = 'C' THEN V_REC.VALOAREV ELSE 0 END)
         WHERE
           CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
       END LOOP;
     END IF;
   END LOOP;
    PERFORM PKG_GLOBALS_MarkDirtyJurnal();
    PERFORM NotifyModif(Operation, RecId, 'REGOSS');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_begin_saft</obj_name>
  <obj_hashval>74c5700aecd2881ac01012a1534e7b40</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_begin_saft(ptip numeric, pan numeric, pluna numeric, psubunit integer DEFAULT 1)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vRec               RECORD;
  vAnIni             NUMERIC:= pAn;
  vLunaIni           NUMERIC:= pLuna;
  vAnFin             NUMERIC:= pAn;
  vLunaFin           NUMERIC:= pLuna;
  v_ALIni            NUMERIC;
  v_ALFin            NUMERIC;
  vAnP               NUMERIC;
  vLunaP             NUMERIC;
  sHolding           VARCHAR(10) := Coalesce(fnc_GetValConstanta('Holding', pAn, pLuna),'2');
  bHolding           BOOLEAN := ('1' =  sHolding);
  bPartContact       BOOLEAN := ('2' =     Coalesce(NULLIF(fnc_getvalconstanta('SAFTPartContact'  ,pAn,pLuna),''),'2'));
  bPartBanca         BOOLEAN := ('2' =     Coalesce(NULLIF(fnc_getvalconstanta('SAFTPartBanca'    ,pAn,pLuna),''),'2'));
  vCodPersContact    NUMERIC;
  vCodBankCont       NUMERIC;
  vTipTVAMixt100     NUMERIC := To_Number(Coalesce(NULLIF(fnc_getvalconstanta('TipTVAMixt100'    ,pAn,pLuna),''),'0'));
  vCCheltTVADed      NUMERIC := To_Number(Coalesce(NULLIF(fnc_getvalconstanta('CCheltTVADed'     ,pAn,pLuna),''),'0'));
  vCIntermedMarja    NUMERIC;
  vLSAC_CNT          NUMERIC;
  vLSAC_C_Val        NUMERIC;
  vLSAC_C_AL         NUMERIC;
  vLSAC_P_Val        NUMERIC;
  vLSAC_P_AL         NUMERIC;
  cSQL               TEXT;
  vCont401           NUMERIC;
  sSAFTPartConturi   TEXT;
  sCMifix            TEXT;
  vAnTmp             NUMERIC;
  vLunaTMP           NUMERIC;
  v_ALTMP            Numeric(5);
  vCount             NUMERIC;
BEGIN
  --Florin 10.12.2025 - sinc. Oracle
  --Florin 25/27.11.2025 - sinc. Oracle
  --Florin 17.11.2025 - sinc. Oracle
  --Florin 06.11.2025 - sinc. Oracle
  --Stef   23.10.2025 - parteneri cu Plata sau Incasare in curs
  --Florin 22.10.2025 - sinc. Oracle
  --Stef   22.10.2025 - 67039
  --Florin 17.10.2025 - fixat 66994
  --Stef   09.10.2025
  --Stef   26.09.2025
  --Stef   25.09.2025
  --Stef   24.09.2025
  --Stef   30.07.2025
  --Florin 30.07.2025 - sinc. Oracle
  --Stef 29.05.2025 - sinc. Oracle -&gt; DISTINCT
  --Florin 23.05.2025 - sinc. oracle
  --Florin 14.05.2025 - sinc. Oracle
  --Stef 28.04.2025 - sinc. Oracle
  perform set_config('PKG_SAFT.pSaftDebug', false::varchar, false);
  EXECUTE 'TRUNCATE TABLE SAFT_INFO';
  CALL create_wm_temps_flag('PKG_SAFT');
  PERFORM PKG_SAFT_TRUNCATE_TABLES();
  PERFORM PKG_SAFT_RESET_SEQ();

  IF    pTip = 1/*(L)  Lunara                  */ OR
        pTip = 4/*(C)  La cerere               */ OR
        pTip = 5/*(NL) Nerezidenti lunar       */ THEN vLunaIni := vLunaFin;
  ELSIF pTip = 2/*(T)  Trimestriala            */ OR
        pTip = 6/*(NT) Nerezidenti trimestrial */ THEN vLunaIni := CASE WHEN vLunaFin &gt; 9 THEN 10 WHEN vLunaFin &gt; 6 THEN 7 WHEN vLunaFin &gt; 3 THEN 4 ELSE 1 END;
  ELSIF pTip = 3/*(A)  Anuala                  */ THEN vLunaIni := 1;
  ELSIF pTip = 7/*(A)  Anuala - Active         */ THEN
    SELECT
      Max(vIdx) Cnt,
      Max(CASE WHEN vIdx = 1 THEN valoare ELSE 0 END) Valoare_C,
      Max(CASE WHEN vIdx = 1 THEN alstart ELSE 0 END) ALStart_C,
      Max(CASE WHEN vIdx = 2 THEN valoare ELSE 0 END) Valoare_P,
      Max(CASE WHEN vIdx = 2 THEN alstart ELSE 0 END) AlStart_P
    INTO
      vLSAC_CNT,
      vLSAC_C_Val,
      vLSAC_C_AL,
      vLSAC_P_Val,
      vLSAC_P_AL
    FROM (
      SELECT Row_Number() over (ORDER BY cl.alstart DESC) vIDX, cl.alstart, cl.alstop, To_Number(cv.valoare) valoare
      FROM const1 c1
        LEFT JOIN constluna cl ON cl.codconst1 = c1.codconst1
        LEFT JOIN constval cv ON cv.codconstluna = cl.codconstluna
      WHERE Upper(simbol) = 'LUNASTARTANCONTAB'
        AND cl.alstart &lt; pAn*12+pLuna
    ) ssub
    WHERE vIDX &lt;= 2;

    vLunaIni := vLSAC_C_Val;
    vAnIni   := pAn - CASE WHEN vLunaFin &lt; vLunaIni THEN 1 ELSE 0 END;

    -- daca se modifica LunaStartAnContab pe perioada care afecteaza declaratia se extinde intervalul
    IF (vLSAC_CNT &gt; 1) AND (vLSAC_C_Val &lt;&gt; vLSAC_P_Val) AND (vLSAC_C_AL BETWEEN v_ALIni-11 AND v_ALIni) THEN
      vAnIni   := vAnIni - CASE WHEN vLSAC_C_Val &lt; vLSAC_P_Val THEN 1 ELSE 0 END;
      vLunaIni := vLSAC_P_Val;
    END IF;
  END IF;
  v_ALIni := vAnIni*12+vLunaIni;
  v_ALFin := vAnFin*12+vLunaFin;

  SELECT  NewAn, NewLuna INTO vAnP, vLunaP from pkg_globals_Calculeaza_Luna_Precedenta(vAnIni, vLunaIni, vAnP, vLunaP);

  IF bHolding AND (pSubunit &lt;&gt; 1) THEN
    SELECT CODBANKCONT,  CODPERS
    INTO   vCodBankCont, vCodPersContact
    FROM   nsubunit
    WHERE  CODSUBUNIT = pSubunit;
  ELSE
    vCodPersContact := To_Number(Coalesce(NULLIF(fnc_getvalconstanta('SAFTPersContactFirma',pAn,pLuna),''),'0'));
    vCodBankCont    := To_Number(Coalesce(NULLIF(fnc_getvalconstanta('BancaImplicita'      ,pAn,pLuna),''),'0'));
  END IF;

  INSERT INTO TMP_SAFT_PARAMS( CODFIRMA,  USERID,  TIP,  ANINI,  LUNAINI,  ANFIN,  LUNAFIN,  ANP,  LUNAP,  CODBANKCONT,  CODSUBUNIT, PERSCONTACT)
  VALUES                     ((SELECT WME_RESULT FROM PKG_GLOBALS_GETCODFIRMA(NULL, NULL)), GETUSERID(), pTip, vAnIni, vLunaIni, vAnFin, vLunaFin, vAnP, vLunaP, vCodBankCont, pSubunit,   vCodPersContact);

  INSERT INTO TMP_SAFT_CC4426 SELECT CodCont FROM ncont WHERE CodSaft = '4426';

  PERFORM pkg_saft_PUT_INFO('00.A01','BEGIN_SAFT--TMP_SAFT_JURNAL');
  PERFORM pkg_saft_ActulizareCodSaftInNCont();

  perform pkg_saft_PUT_INFO('00.A11','BEGIN_SAFT--Completare TMP_SAFT_MANEVRA');
  perform pkg_saft_UMPLE_MANEVRA_CONT_FROM_CONST('CObInventar', vLunaFin,vLunaFin);
  perform pkg_saft_UMPLE_MANEVRA_CONT_FROM_CONST('CMifix',      vLunaFin,vLunaFin);
  perform pkg_saft_UMPLE_MANEVRA_CONT_FROM_CONST('CImbMifix',   vLunaFin,vLunaFin);
  perform pkg_saft_UMPLE_MANEVRA_CONT_FROM_CONST('ProvMiFix',   vLunaFin,vLunaFin);

  IF pTip = 7 THEN -- Anuala - Active
    vAnTmp   := vAnIni;
    vLunaTmp := vLunaIni;
    v_ALTMP  := v_ALIni;
    PERFORM pkg_saft_PUT_INFO('00.B01','BEGIN_SAFT--TMP_SAFT_MIFIX1');
    WHILE vAnTmp*12+vLunaTmp &lt;= vAnFin*12+vLunaFin
    LOOP
      perform pkg_saft_UMPLE_MANEVRA_CONT_FROM_CONST('CMifix',            vAnTmp,vLunaTMP);
      perform pkg_saft_UMPLE_MANEVRA_CONT_FROM_CONST('CCheltAmoMifixNC',  vAnTmp,vLunaTMP);
      perform pkg_saft_UMPLE_MANEVRA_CONT_FROM_CONST('CRezRepAmoMifixNC', vAnTmp,vLunaTMP);

      INSERT INTO TMP_SAFT_MIFIX1(CODMIFIX1, CODMIFIX, AN, LUNA, CONT)
      SELECT M1.CODMIFIX1, M1.CODMIFIX, M1.ANSTART, M1.LUNASTART, I1.CONT
      FROM mifix1 m1
        INNER JOIN nirstoc      ns ON ns.codnirstoc = m1.codnirstoc
        INNER JOIN nir          n  ON n.codnir      = ns.codnir
        INNER JOIN ngest        ng ON ng.codgest    = n.gest
        INNER JOIN ioart1       i1 ON i1.codioart   = ns.codioart AND m1.anstart*12+m1.lunastart BETWEEN i1.alstart AND i1.alstop
        INNER JOIN (
          SELECT DISTINCT codunic FROM TMP_SAFT_MANEVRA WHERE FILTRU = 'CMifix' AND AL = v_ALTMP
        )                       t2 ON t2.codunic    = i1.cont

      WHERE m1.anstart = vAnTmp AND m1.lunastart = vLunaTMP
        AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE NG.CODSUBUNIT END;

      SELECT  NewAn, newluna INTO vAnTmp, vLunaTmp FROM pkg_globals_Calculeaza_Luna_Urmatoare(vAnTmp, vLunaTmp, vAnTmp, vLunaTmp);
      v_ALTMP := v_ALTMP + 1;
    END LOOP;

    PERFORM pkg_saft_PUT_INFO('00.B02','BEGIN_SAFT--TMP_SAFT_JURNAL1 - amortizari');
    INSERT INTO TMP_SAFT_JURNAL1(
      CODJURNAL1, CODMIFIX1, CODMIFIX, AN, LUNA, TIPDOC, CODDOC,
      VALOARE, DATADOC, TIPREEVAL,
      CodDescrD, IcontD, TipContD, AnaliticContD,
      CodDescrC, IcontC, TipContC, AnaliticContC,
      SEMN
    )
    SELECT
      J1.CODJURNAL1, M1.CODMIFIX1, M1.CODMIFIX, J1.AN, J1.LUNA, J1.TIPDOC, J1.CODDOC,
      J1.VALOARE, J1.DATADOC, Coalesce(M1.TIPREEVAL, -1) TIPREEVAL,
      j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD,
      j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC,
      1 SEMN
    FROM TMP_SAFT_MIFIX1 TM1
      INNER JOIN MIFIX1  M1 ON M1.CODMIFIX1 = TM1.CODMIFIX1
      INNER JOIN JURNAL1 J1 ON J1.AN        = TM1.AN
                           AND J1.LUNA      = TM1.LUNA
                           AND J1.TIPDOC    = 36
                           AND J1.CODDOC    = TM1.CODMIFIX
    WHERE J1.ICONTD = 4 OR (J1.ICONTD = 10 AND J1.ICONTC = 0) AND Abs(J1.VALOARE) &gt;= 0.01
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J1.SUBUNITATEA END;

    perform pkg_saft_PUT_INFO('00.B03','BEGIN_SAFT--TMP_SAFT_JURNAL1 - casare si reevaluare');
    INSERT INTO TMP_SAFT_JURNAL1(
      CODJURNAL1, CODMIFIX1, CODMIFIX, AN, LUNA, TIPDOC, CODDOC,
      VALOARE, DATADOC, TIPREEVAL,
      CodDescrD, IcontD, TipContD, AnaliticContD,
      CodDescrC, IcontC, TipContC, AnaliticContC,
      SEMN
    )
    SELECT
      J1.CODJURNAL1, M1.CODMIFIX1, M1.CODMIFIX, J1.AN, J1.LUNA, J1.TIPDOC, J1.CODDOC,
      J1.VALOARE, J1.DATADOC, Coalesce(M1.TIPREEVAL, -1) TIPREEVAL,
      j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD,
      j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC,
      1 SEMN
    FROM TMP_SAFT_MIFIX1 TM1
      INNER JOIN MIFIX1  M1 ON M1.CODMIFIX1 = TM1.CODMIFIX1
      INNER JOIN JURNAL1 J1 ON J1.AN        = TM1.AN
                           AND J1.LUNA      = TM1.LUNA
                           AND J1.TIPDOC    = 36
                           AND J1.CODDOC    = TM1.CODMIFIX
           WHERE ((J1.ICONTD = 0 AND J1.ICONTC = 2 AND NOT M1.STARE IN (4)) OR (J1.ICONTD IN (2) AND J1.ICONTC IN (0, 6))
      OR (J1.ICONTD IN (10) AND J1.ICONTC IN (2) AND J1.TIPDOC = 14)) AND Abs(J1.VALOARE) &gt;= 0.01
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J1.SUBUNITATEA END;

    perform pkg_saft_PUT_INFO('00.B04','BEGIN_SAFT--TMP_SAFT_JURNAL1 - note contabile corectie amortizari');
    INSERT INTO TMP_SAFT_JURNAL1(
      CODJURNAL1, CODMIFIX1, CODMIFIX, AN, LUNA, TIPDOC, CODDOC,
      VALOARE, DATADOC, TIPREEVAL,
      CodDescrD, IcontD, TipContD, AnaliticContD,
      CodDescrC, IcontC, TipContC, AnaliticContC,
      SEMN
    )
    SELECT
      DISTINCT J1.CODJURNAL1, M1.CODMIFIX1, M1.CODMIFIX, J1.AN, J1.LUNA, J1.TIPDOC, J1.CODDOC,
      J1.VALOARE, J1.DATADOC, Coalesce(M1.TIPREEVAL, -1) TIPREEVAL,
      j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD,
      j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC,
      1 SEMN
    FROM TMP_SAFT_MIFIX1 TM1
      INNER JOIN MIFIX1  M1  ON M1.CODMIFIX1 = TM1.CODMIFIX1
      LEFT  JOIN NC1     NC1 ON NC1.MFSAFT   = M1.CODMIFIX
      LEFT  JOIN NC      NC  ON NC.CODNC     = NC1.CODNC
      INNER JOIN JURNAL1 J1  ON J1.AN        = TM1.AN        AND J1.LUNA = TM1.LUNA AND J1.TIPDOC = 35 AND J1.CODDOC = NC.CODNC AND J1.INDEXLOCAL = NC1.CODNC1
      INNER JOIN (
          SELECT DISTINCT codunic FROM TMP_SAFT_MANEVRA WHERE FILTRU IN ( 'CCheltAmoMifixNC', 'CRezRepAmoMifixNC' )
      )                  T4  ON T4.CODUNIC   = J1.CODDESCRD
    WHERE Abs(J1.VALOARE) &gt;= 0.01 AND NOT T4.CODUNIC IS NULL
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J1.SUBUNITATEA END;

    perform pkg_saft_PUT_INFO('00.B05','BEGIN_SAFT--TMP_SAFT_JURNAL1 - ajustari negative de valoare');
    INSERT INTO TMP_SAFT_JURNAL1(
      CODJURNAL1, CODMIFIX1, CODMIFIX, AN, LUNA, TIPDOC, CODDOC,
      VALOARE, DATADOC, TIPREEVAL,
      CodDescrD, IcontD, TipContD, AnaliticContD,
      CodDescrC, IcontC, TipContC, AnaliticContC,
      SEMN
    )
    SELECT
      J1.CODJURNAL1, M1.CODMIFIX1, M1.CODMIFIX, J1.AN, J1.LUNA, J1.TIPDOC, J1.CODDOC,
      J1.VALOARE, J1.DATADOC, Coalesce(M1.TIPREEVAL, -1) TIPREEVAL,
      j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD,
      j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC,
      1 SEMN
    FROM TMP_SAFT_MIFIX1 TM1
      INNER JOIN MIFIX1  M1    ON M1.CODMIFIX1  = TM1.CODMIFIX1
      LEFT JOIN NIRSTOC NS     ON NS.CODNIRSTOC = M1.CODNIRSTOC
      LEFT JOIN NIR   N        ON N.CODNIR      = NS.CODNIR
      LEFT JOIN TRANSF T       ON T.CODTRANSF   = N.CODTRANSF
      INNER JOIN JURNAL1 J1    ON  J1.TIPDOC    = T.TIPDOC
                               AND J1.CODDOC    = T.CODTRANSF
                               AND J1.AN        = TM1.AN
                               AND J1.LUNA      = TM1.LUNA
    WHERE J1.ICONTC = 23 AND Abs(J1.VALOARE) &gt;= 0.01
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J1.SUBUNITATEA END;

    perform pkg_saft_PUT_INFO('00.B05','BEGIN_SAFT--TMP_SAFT_JURNAL1 - intrari');
    INSERT INTO TMP_SAFT_JURNAL1(
      CODJURNAL1, CODMIFIX1, CODMIFIX, AN, LUNA, TIPDOC, CODDOC,
      VALOARE, DATADOC, TIPREEVAL, TIPTRANZACTIE,
      CodDescrD, IcontD, TipContD, AnaliticContD,
      CodDescrC, IcontC, TipContC, AnaliticContC,
      SEMN
    )
    WITH recursive wm1 (CODMIFIX1, CODMIFIX, ANSTART, LUNASTART, TIPREEVAL, CODNIRSTOC, CODNIRSTOCPARINTE) AS (  --pentru mai multe operatii facute IN aceeasi luna
      SELECT  M1.CODMIFIX1, M1.CODMIFIX, M1.ANSTART, M1.LUNASTART, Coalesce(M1.TIPREEVAL, -1) TIPREEVAL, NS.CODNIRSTOC, NS.CODNIRSTOCPARINTE
      FROM TMP_SAFT_MIFIX1 TM1
        INNER JOIN MIFIX1  M1 ON M1.CODMIFIX1  = TM1.CODMIFIX1
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = M1.CODNIRSTOC
      UNION ALL
      SELECT wm1.CODMIFIX1, wm1.CODMIFIX, wm1.ANSTART, wm1.LUNASTART, wm1.TIPREEVAL, NS.CODNIRSTOC, NS.CODNIRSTOCPARINTE
      FROM wm1 INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = wm1.CODNIRSTOCPARINTE
    )
    SELECT
      J1.CODJURNAL1, WM1.CODMIFIX1, WM1.CODMIFIX, J1.AN, J1.LUNA, J1.TIPDOC, J1.CODDOC,
      J1.VALOARE*CASE WHEN J1.ICONTD = 2 THEN 1 ELSE -1 END AS VALOARE, J1.DATADOC, WM1.TIPREEVAL, Coalesce(I.TipTranzactie, 0) TIPTRANZACTIE,
      j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD,
      j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC,
      CASE WHEN Coalesce(I1.Cant, 0) &lt; 0 THEN -1 ELSE 1 END SEMN
    FROM wm1
      INNER JOIN NIRSTOC  NS ON NS.CODNIRSTOC = WM1.CODNIRSTOC
      INNER JOIN NIR      N  ON N.CODNIR      = NS.CODNIR
      LEFT  JOIN INTRARI  I  ON I.CODINTR     = N.CODINTR
      LEFT  JOIN INTRARI1 I1 ON I1.CODINTR1   = NS.CODINTR1
      INNER JOIN JURNAL1  J1 ON J1.AN         = WM1.ANSTART
                            AND J1.LUNA       = WM1.LUNASTART
                            AND J1.TIPDOC     = N.TIPNIR
                            AND J1.CODDOC     = Coalesce(n.codintr,   n.codtransf,   n.codies)
                            AND J1.INDEXLOCAL = Coalesce(ns.codintr1, ns.codtransf1, ns.coddvi1)
    WHERE (J1.ICONTD = 2 OR J1.ICONTC = 2) AND J1.ICONTD &lt;&gt; 3 AND Abs(J1.VALOARE) &gt;= 0.01
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J1.SUBUNITATEA END;

   perform pkg_saft_PUT_INFO('00.B06','BEGIN_SAFT--TMP_SAFT_JURNAL1 - intrari');
    INSERT INTO TMP_SAFT_JURNAL1(
      CODJURNAL1, CODMIFIX1, CODMIFIX, AN, LUNA, TIPDOC, CODDOC,
      VALOARE, DATADOC, TIPREEVAL, TIPTRANZACTIE,
      CodDescrD, IcontD, TipContD, AnaliticContD,
      CodDescrC, IcontC, TipContC, AnaliticContC,
      SEMN
    )
    WITH recursive wm1 (CODMIFIX1, CODMIFIX, CODMIFIXNEW, ANSTART, LUNASTART, TIPREEVAL, CODNIRSTOC, CODNIRSTOCPARINTE) AS (  --pentru mai multe operatii facute IN aceeasi luna
      SELECT M1.CODMIFIX1, TM1.CODMIFIX, M1.CODMIFIX CODMIFIXNEW, M1.ANSTART, M1.LUNASTART, Coalesce(M1.TIPREEVAL, -1) TIPREEVAL, NS.CODNIRSTOC, NS.CODNIRSTOCPARINTE
      FROM TMP_SAFT_MIFIX1 TM1
        INNER JOIN MIFIX1  M1 ON M1.CODMIFIX1  = TM1.CODMIFIX1
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = M1.CODNIRSTOC
      UNION ALL
      SELECT wm1.CODMIFIX1, wm1.CODMIFIX, wm1.CODMIFIXNEW, wm1.ANSTART, wm1.LUNASTART,  wm1.TIPREEVAL, NS.CODNIRSTOC, NS.CODNIRSTOCPARINTE
      FROM wm1 INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = wm1.CODNIRSTOCPARINTE
    )
    SELECT
      J1.CODJURNAL1, WM1.CODMIFIX1, WM1.CODMIFIX, J1.AN, J1.LUNA, J1.TIPDOC, J1.CODDOC,
      J1.VALOARE*CASE WHEN J1.ICONTD = 2 THEN 1 ELSE -1 END*CASE WHEN wm1.CODMIFIX = wm1.CODMIFIXNEW THEN 1 ELSE -1 END  AS VALOARE,
      J1.DATADOC, WM1.TIPREEVAL, Coalesce(I.TipTranzactie, 0) TIPTRANZACTIE,
      j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD,
      j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC,
      CASE WHEN Coalesce(I1.Cant, 0) &lt; 0 THEN -1 ELSE 1 END SEMN
    FROM wm1
      INNER JOIN MIFIX    M  ON M.CODMIFIX    = WM1.CODMIFIX
      INNER JOIN NIRSTOC  NS ON NS.CODNIRSTOC = WM1.CODNIRSTOC
      INNER JOIN NIR      N  ON N.CODNIR      = NS.CODNIR
      LEFT  JOIN INTRARI  I  ON I.CODINTR     = N.CODINTR
      LEFT  JOIN INTRARI1 I1 ON I1.CODINTR1   = NS.CODINTR1
      INNER JOIN JURNAL1  J1 ON J1.AN         = WM1.ANSTART
                            AND J1.LUNA       = WM1.LUNASTART
                            AND J1.TIPDOC     = N.TIPNIR
                            AND J1.CODDOC     = Coalesce(n.codintr,   n.codtransf,   n.codies)
                            AND J1.INDEXLOCAL = Coalesce(ns.codintr1, ns.codtransf1, ns.coddvi1)
    WHERE ((J1.ICONTD = 2 OR J1.ICONTC = 2) AND J1.ICONTD &lt;&gt; 3)
        AND Abs(J1.VALOARE) &gt;= 0.01
        AND (
              J1.TIPDOC &lt;&gt; 6
              OR
              (J1.TIPDOC = 6 AND WM1.CODMIFIX &lt;&gt; COALESCE(M.CODMIFIXNOU,0) AND COALESCE(M.CODMIFIXNOU,0) = 0)
            )
        AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J1.SUBUNITATEA END;

   PERFORM pkg_saft_PUT_INFO('00.B07','BEGIN_SAFT--TMP_SAFT_JURNAL1 - iesiri');
   INSERT INTO TMP_SAFT_JURNAL1(
      CODJURNAL1, CODMIFIX1, CODMIFIX, AN, LUNA, TIPDOC, CODDOC,
      VALOARE, DATADOC, TIPREEVAL, TIPTRANZACTIE,
      CodDescrD, IcontD, TipContD, AnaliticContD,
      CodDescrC, IcontC, TipContC, AnaliticContC,
      SEMN
    )
    SELECT
      J1.CODJURNAL1, M1.CODMIFIX1, M1.CODMIFIX, J1.AN, J1.LUNA, J1.TIPDOC, J1.CODDOC,
      J1.VALOARE, J1.DATADOC, Coalesce(M1.TIPREEVAL, -1) TIPREEVAL, Coalesce(I.TipTranzactie, 0) TIPTRANZACTIE,
      j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD,
      j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC,
      CASE WHEN Coalesce(I1.Cant, 0) &lt; 0 THEN -1 ELSE 1 END SEMN
    FROM TMP_SAFT_MIFIX1 TM1
      LEFT JOIN MIFIX1  M1 ON M1.CODMIFIX1 = TM1.CODMIFIX1
      LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = M1.CODNIRSTOC
      LEFT JOIN LIVR1   L1 ON L1.CODNIRSTOC = NS.CODNIRSTOC
      LEFT JOIN LIVR    L  ON L.CODLIVR     = L1.CODLIVR
      LEFT JOIN IESIRI  I  ON I.CODIES      = L.CODIES
      LEFT JOIN IESIRI1 I1 ON I1.CODIES1    = L1.CODIES1
      LEFT JOIN JURNAL1 J1 ON J1.AN         = M1.ANSTART
                          AND J1.LUNA       = M1.LUNASTART
                          AND J1.TIPDOC     = L.TIPLIVR
                          AND J1.CODDOC     = Coalesce(l.codies,   l.codintr,   l.codtransf)
                          AND J1.INDEXLOCAL = Coalesce(l1.codies1, l1.codintr1, l1.coddvi1)
   WHERE ((COALESCE(J1.ICONTD, 0) IN (2, 23) OR (Coalesce(J1.ICONTC, 0) = 5) AND NOT J1.TIPCONTC IN (200))
      OR (NOT J1.TIPDOC IN (12, 19, 20, 21, 23) AND (COALESCE(J1.ICONTD, 0) = 10)))
      AND Abs(Coalesce(J1.VALOARE, 0)) &gt;= 0.01
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE Coalesce(J1.SUBUNITATEA, 0) END;

    perform pkg_saft_PUT_INFO('00.B08','BEGIN_SAFT--TMP_SAFT_JURNAL1 - fisamf - miscari multiple in luna');
    INSERT INTO TMP_SAFT_JURNAL1(
      CODJURNAL1, CODMIFIX1, CODMIFIX, AN, LUNA, TIPDOC, CODDOC,
      VALOARE, DATADOC, TIPREEVAL, TIPTRANZACTIE,
      CodDescrD, IcontD, TipContD, AnaliticContD,
      CodDescrC, IcontC, TipContC, AnaliticContC,
      SEMN
    )
    SELECT
      J1.CODJURNAL1, M1.CODMIFIX1, M1.CODMIFIX, J1.AN, J1.LUNA, J1.TIPDOC, J1.CODDOC,
      J1.VALOARE, J1.DATADOC, Coalesce(M1.TIPREEVAL, -1) TIPREEVAL,  coalesce( dies.TipTranzactie, dint.TipTranzactie, 0) TIPTRANZACTIE,
      j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD,
      j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC,
      1 SEMN
    FROM TMP_SAFT_MIFIX1 TM1
      INNER JOIN mifix1  m1   ON m1.codmifix1   = tm1.codmifix1
      INNER JOIN nirstoc ns   ON ns.codnirstoc  = m1.codnirstoc
      INNER JOIN nir     n    ON n.codnir       = ns.codnir
      INNER JOIN transf  t    ON t.codtransf    = n.codtransf
                             AND t.an           = m1.anstart
                             AND t.luna         = m1.lunastart
      INNER JOIN fisamf  f    ON f.tipdoc       = n.tipnir
                             AND f.codmifix     = m1.codmifix
                             AND f.dataoperatie = n.datanir
      INNER JOIN nirstoc nsp  ON nsp.codnirstoc = ns.codnirstocparinte
      INNER JOIN nir     np   ON np.codnir      = nsp.codnir
      INNER JOIN fisamf  fp   ON fp.tipdoc      = np.tipnir
                             AND fp.codmifix    = m1.codmifix
      INNER JOIN jurnal1 j1   ON j1.an          = m1.anstart
                             AND j1.luna        = m1.lunastart
                             AND j1.tipdoc      = fp.tipdoc
                             AND j1.indexlocal  = fp.coddoc1
      LEFT  JOIN iesiri  dies ON dies.codies    = np.codies
      LEFT  JOIN intrari dint ON dint.codintr   = np.codintr
    WHERE Trunc(f.dataoperatie, 'mm') = Trunc(fp.dataoperatie, 'mm')
      AND (COALESCE(J1.ICONTD, 0) = 2 OR Coalesce(J1.ICONTC, 0) = 5) AND Abs(Coalesce(J1.VALOARE, 0)) &gt;= 0.01
      AND NOT EXISTS (SELECT 1 FROM TMP_SAFT_JURNAL1 TJ1 WHERE TJ1.CODJURNAL1 = Coalesce(J1.CODJURNAL1,0));

    UPDATE TMP_SAFT_JURNAL1 T
    SET CONTD                = (select wme_result from PKG_JURNAL_GETCONTFORJURNAL(null, CodDescrD, IcontD, TipContD, AnaliticContD, An, Luna)),
        CONTC                = (select wme_result from PKG_JURNAL_GETCONTFORJURNAL(null, CodDescrC, IcontC, TipContC, AnaliticContC, An, Luna)),
        ASSETTRANSACTIONTYPE =  CASE
                                  WHEN TIPDOC IN (1,2,3,4,5)                                          THEN  '10' --Achizitie
                                  WHEN TIPDOC IN (6)             AND sHolding = '1'                   THEN  '10' --Achizitie
                                  WHEN TIPDOC IN (6)                                                  THEN  '40' --Transfer intern
                                  WHEN TIPDOC IN (19,20,21)      AND IcontD = 23                      THEN '110' --Reversare ajustare de valoare
                                  WHEN TIPDOC IN (19,20,21)                                           THEN  '20' --V?nzare
                                  WHEN TIPDOC IN (23)            AND sHolding = '1'                   THEN  '20' --V?nzare
                                  WHEN TIPDOC IN (23)                                                 THEN  '40' --Transfer intern
                                  WHEN TIPDOC = 36               AND IcontD = 4                       THEN  '30' --Amortizare
                                  WHEN TIPDOC = 35                                                    THEN  '30' --Amortizare
                                  WHEN TIPDOC = 12 AND IContC = 23                                    THEN '100' --Ajustare de valoare negativa
                                  WHEN TIPDOC IN (7)                                                  THEN  '40' --Transfer intern
                                  WHEN TIPDOC = 15               AND TIPTRANZACTIE IN (5)             THEN  '40' --Transfer intern
                                  WHEN TIPDOC = 12                                                    THEN  '40' --Transfer intern
                                  WHEN TIPDOC = 13 AND TIPREEVAL IN (  -1) AND VALOARE &gt; 0            THEN  '40' --Transfer intern - prin modificare de pret
                                  WHEN TIPDOC = 36               AND IcontC = 2                       THEN
                                    (
                                       SELECT
                                         CASE
                                           WHEN M1.STARE = 3                                          THEN  '50' --Casare mijloace fixe
                                           WHEN M1.STARE IN (8,9)                                     THEN  '10' --Achizitie
                                           WHEN M1.TIPREEVAL IN (0, 1) AND M1.PRET &lt; M1.PRETVECHI     THEN  '60' --Reevaluare negativa
                                           WHEN M1.TIPREEVAL IN (0, 1) AND M1.PRET &gt; M1.PRETVECHI     THEN  '70' --Reevaluare pozitiva
                                           ELSE                                                            '130' --Alte tranzactii
                                          END
                                       FROM MIFIX1 M1
                                       WHERE M1.CodMifix1 = T.CodMifix1
                                     )
                                  WHEN TIPDOC = 36               AND IcontD = 2                       THEN
                                    (
                                       SELECT
                                         CASE
                                           WHEN M1.TIPREEVAL IN (0, 1) AND M1.PRET &gt; M1.PRETVECHI     THEN  '70' --Reevaluare pozitiva
                                           ELSE                                                            '130' --Alte tranzactii
                                          END
                                       FROM MIFIX1 M1
                                       WHERE M1.CodMifix1 = T.CodMifix1
                                     )
                                  WHEN TIPDOC = 14                                                    THEN  '50' --Casare mijloace fixe
                                  WHEN TIPDOC = 13 AND TIPREEVAL IN (0, 1) AND VALOARE &lt; 0            THEN  '60' --Reevaluare negativa
                                  WHEN TIPDOC = 13 AND TIPREEVAL IN (0, 1) AND VALOARE &gt; 0            THEN  '70' --Reevaluare pozitiva
                                  WHEN TIPDOC = 15                                                    THEN  '80' --Plus de inventar
                                  WHEN TIPDOC = 14                                                    THEN  '90' --Minus de inventar
                                  --WHEN TIPDOC = 36      '120' --Bunuri acordate cu titlu gratuit
                                  ELSE                                                                     '130' --Alte tranzactii
                                END;

    PERFORM pkg_saft_PUT_INFO('00.B07','BEGIN_SAFT--TMP_SAFT_JURNAL - asset');
    UPDATE TMP_SAFT_JURNAL1 J1
    SET CODJURNAL = (
                      SELECT Min(J.CODJURNAL)
                      FROM JURNAL J
                      WHERE J.AN = J1.AN AND J.LUNA = J1.LUNA AND J.TIPDOC = J1.TIPDOC AND J.CODDOC = J1.CODDOC AND J.CONTD = J1.CONTD AND J.CONTC = J1.CONTC
                    );

    INSERT INTO TMP_SAFT_JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, VALOARE, AN, LUNA, SUBUNITATEA, DATADOC, DOCUMENT)
    SELECT                      CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, VALOARE, AN, LUNA, SUBUNITATEA, DATADOC, DOCUMENT
    FROM JURNAL J
    WHERE J.CODJURNAL IN (SELECT DISTINCT CODJURNAL FROM TMP_SAFT_JURNAL1);

  ELSE
    PERFORM pkg_saft_PUT_INFO('00.B10','BEGIN_SAFT--TMP_SAFT_JURNAL');
    INSERT INTO TMP_SAFT_JURNAL(CODJURNAL,  CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC,     VALOARE,  AN, LUNA, SUBUNITATEA, DATADOC,     DOCUMENT)
    SELECT                  Min(CODJURNAL), CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, Sum(VALOARE), AN, LUNA, SUBUNITATEA, DATADOC, Min(DOCUMENT)
    FROM JURNAL J
    WHERE J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
      AND CASE
            WHEN j.tipdoc =  32  AND Coalesce(j.Valoare, 0) = 0 THEN 0
            WHEN j.tipdoc &lt;&gt; 35 THEN 1
            WHEN EXISTS(SELECT 1 FROM NC WHERE NC.CODNC = J.CODDOC AND NC.SABLON = -1) THEN 0 -- j.tipdoc = 35 si SABLON = -1
            ELSE 1
          END = 1
    GROUP BY CODDOC, TIPDOC, CONTD, INDEXLOCAL, CONTC, AN, LUNA, SUBUNITATEA, DATADOC;
  END IF;

  UPDATE TMP_SAFT_JURNAL J
  SET DESCRIPTION =
        Coalesce((SELECT TD.NUMEEXT FROM TMP_MACHETE TD WHERE TD.CODMACHETA = J.TIPDOC), 'Jurnal contabil')||
        CASE
          WHEN J.TIPDOC IN (32, 36)                                                           THEN '/'||To_Char(J.DataDoc,'dd.mm.yyyy')
          WHEN J.DOCUMENT IS NULL                                                             THEN '/'||To_Char(J.DataDoc,'dd.mm.yyyy')
          WHEN J.TIPDOC IN (25)                                                               THEN ' '||J.DOCUMENT
          WHEN J.TIPDOC IN (52, 76)                                                           THEN ' '||J.DOCUMENT||'/'||To_Char(J.DataDoc,'dd.mm.yyyy')
          WHEN J.TIPDOC = 81 AND InStr(J.DOCUMENT,' din ') = 0                                THEN ' '||J.DOCUMENT
          WHEN J.TIPDOC = 81                                                                  THEN ' '||SubStr(J.DOCUMENT, InStr(J.DOCUMENT,' din ') + 5)
          WHEN Length(J.DOCUMENT) &lt; 10                                                        THEN ' '||J.DOCUMENT||'/'||To_Char(J.DataDoc,'dd.mm.yyyy')
          WHEN SubStr(J.DOCUMENT,Length(J.DOCUMENT)- 9, 10) = To_Char(J.DataDoc,'dd.mm.yyyy') THEN ' '||J.DOCUMENT
          WHEN SubStr(J.DOCUMENT,Length(J.DOCUMENT)-10,  1) = '/'                             THEN ' '||J.DOCUMENT
                                                                                              ELSE ' '||J.DOCUMENT||'/'||To_Char(J.DataDoc,'dd.mm.yyyy')
        END;

  UPDATE TMP_SAFT_JURNAL J SET (CODMONEDA, EXCHANGERATE) = (SELECT i.moneda, i.curs FROM intrari i  WHERE i.codintr = j.coddoc)   WHERE TIPDOC IN ( 1, 2, 3, 4, 5, 9);
  UPDATE TMP_SAFT_JURNAL J SET (CODMONEDA, EXCHANGERATE) = (SELECT i.moneda, i.curs FROM iesiri  i  WHERE i.codies  = j.coddoc)   WHERE TIPDOC IN (19,20,21,22,26);
  UPDATE TMP_SAFT_JURNAL J SET (CODMONEDA, EXCHANGERATE) = (SELECT g.moneda, g.curs
                                                            FROM compens c
                                                              LEFT JOIN general   g  ON g.coddoc = c.codcompens AND g.tipdoc = 28
                                                            WHERE c.codcompens  = j.coddoc
                                                            LIMIT 1
                                                           )                                                                      WHERE TIPDOC = 28;
  UPDATE TMP_SAFT_JURNAL J SET (CODMONEDA, EXCHANGERATE) = (SELECT bc.codmoneda, t1.curs
                                                            FROM trezor1 t1
                                                              LEFT JOIN trezor    t  ON t.codtrezor    = t1.codtrezor
                                                              LEFT JOIN nbankcont bc ON bc.codbankcont = t.codbanca
                                                            WHERE t1.codtrezor1  = j.indexlocal
                                                            LIMIT 1
                                                           )                                                                      WHERE TIPDOC IN (29,30,31);
  UPDATE TMP_SAFT_JURNAL J SET CODMONEDA = 0, CURRENCYCODE = 'RON', EXCHANGERATE = 1                                              WHERE COALESCE(CODMONEDA, 0)  = 0;
  UPDATE TMP_SAFT_JURNAL J SET (CURRENCYCODE) = (SELECT Upper(SubStr(SIMBOL,1,3)) FROM nmonede m WHERE m.codmoneda = j.codmoneda) WHERE COALESCE(CODMONEDA, 0) &lt;&gt; 0;

  INSERT INTO TMP_SAFT_JURNALDET (
    CODJURNAL,
    CODPART,
    CODPART_2,
    DATADOC,
    DATACREARE,
    TIPTRANZ, OBIECTTRANZ)
  SELECT DISTINCT
    J.CODJURNAL,
    Coalesce(
      IES.PARTENER, INTR.PARTENER, TREZ1.CODPART,
      CASE WHEN J.TIPDOC = 35 AND NC1.PARTD = 1 THEN NULLIF(NC1.CODPART,   0) END,
      CASE WHEN J.TIPDOC = 35 AND NC1.PARTD = 1 THEN NULLIF(NC.PART,       0) END,
      CASE WHEN J.TIPDOC = 46                   THEN NULLIF(OBR.CODPART,   0) END,
      CASE WHEN J.TIPDOC = 59                   THEN NULLIF(NCRED.CODPART, 0) END,
      COMP.PARTC
    ) AS CODPART,
    Coalesce(
      CASE WHEN J.TIPDOC = 35 AND NC1.PARTC = 1 THEN NULLIF(NC1.CODPART,   0) END,
      CASE WHEN J.TIPDOC = 35 AND NC1.PARTC = 1 THEN NULLIF(NC.PART,       0) END,
      COMP.PARTD
    ) AS CODPART_2,
    Coalesce(IES.DATADOC,   INTR.DATADOC,   TRAN.DATADOC,   COMP.DATADOC,   TREZ.DATADOC,   NC.DATADOC,   J.DATADOC)        AS DATADOC,
    Coalesce(IES.DATACREARE,INTR.DATACREARE,TRAN.DATACREARE,COMP.DATACREARE,TREZ.DATACREARE,NC.DATACREARE,NCRED.DATACREARE) AS DATACREARE,
    TREZ1.TIPTRANZ, TREZ1.OBIECTTRANZ
  FROM TMP_SAFT_JURNAL   J
    LEFT JOIN IESIRI            IES   ON IES.CODIES       = J.CODDOC       AND IES.TIPDOC       = J.TIPDOC
    LEFT JOIN INTRARI           INTR  ON INTR.CODINTR     = J.CODDOC       AND INTR.TIPDOC      = J.TIPDOC
    LEFT JOIN TRANSF            TRAN  ON TRAN.CODTRANSF   = J.CODDOC       AND TRAN.TIPDOC      = J.TIPDOC
    LEFT JOIN COMPENS           COMP  ON COMP.CODCOMPENS  = J.CODDOC       AND J.TIPDOC         = 28
    LEFT JOIN TREZOR            TREZ  ON TREZ.CODTREZOR   = J.CODDOC       AND TREZ.TIPDOC      = J.TIPDOC
    LEFT JOIN TREZOR1           TREZ1 ON TREZ1.CODTREZOR  = TREZ.CODTREZOR AND TREZ1.CODTREZOR1 = J.INDEXLOCAL
    LEFT JOIN NC                NC    ON NC.CODNC         = J.CODDOC       AND J.TIPDOC         = 35
    LEFT JOIN NC1               NC1   ON NC1.CODNC1       = J.INDEXLOCAL   AND J.TIPDOC         = 35
    LEFT JOIN REG1              R1    ON R1.CODREG1       = J.INDEXLOCAL   AND J.TIPDOC         = 46
    LEFT JOIN OBLIGPIF          OBR   ON OBR.CODOBLIGPIF  = R1.CODOBLIGPIF
    LEFT JOIN NOTECREDIT        NCRED ON NCRED.CODNCREDIT = J.CODDOC       AND J.TIPDOC         = 59;

  INSERT INTO TMP_SAFT_EXCL_J1(
    TIPDOC, CODDOC, AN, LUNA,
    CodDescrD, IcontD, TipContD, AnaliticContD,
    CodDescrC, IcontC, TipContC, AnaliticContC
  )
  SELECT DISTINCT
    J1.TIPDOC, J1.CODDOC, J1.AN, J1.LUNA,
    j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD,
    j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC
  FROM INTRARI I
    INNER JOIN JURNAL1 J1 ON J1.TIPDOC = I.TIPDOC AND J1.CODDOC = I.CODINTR
  WHERE I.AN*12+I.LUNA BETWEEN v_ALIni AND v_ALFin
    AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE I.SUBUNITATEA END
    AND ( (j1.tipbazad = 700 AND j1.tipbazac =   0 AND j1.tipcontc = 800) OR -- supliment receptie NIRSTOC
          (j1.tipbazac = 700 AND j1.tipbazad =   0 AND j1.tipcontc = 300) OR -- intrari cu diferente rotunjire pret
          (j1.tipbazad = 700 AND j1.tipbazac =   0 AND j1.tipcontc = 300) OR -- intrari cu adaos si TVA neexigibil - adaos
 --63846--(j1.tipbazad = 700 AND j1.tipbazac = 200 AND j1.tipcontc = 200) OR -- intrari cu adaos si TVA neexigibil - TVA
          (j1.tipbazad = 900 AND j1.tipbazac = 100 AND j1.tipcontc = 800) OR -- diferente curs valutare la stornare avans - venit
          (j1.tipbazac = 900 AND j1.tipbazad = 100 AND j1.tipcontd = 800)    -- diferente curs valutare la stornare avans - cheltuiala
        );

  INSERT INTO TMP_SAFT_EXCL_J1(
    TIPDOC, CODDOC, AN, LUNA,
    CodDescrD, IcontD, TipContD, AnaliticContD,
    CodDescrC, IcontC, TipContC, AnaliticContC
  )
  SELECT DISTINCT
    J1.TIPDOC, J1.CODDOC, J1.AN, J1.LUNA,
    j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD,
    j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC
  FROM IESIRI I
    INNER JOIN JURNAL1 J1 ON J1.TIPDOC = I.TIPDOC AND J1.CODDOC = I.CODIES
  WHERE I.AN*12+I.LUNA BETWEEN v_ALIni AND v_ALFin
    AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE I.SUBUNITATEA END
    AND ( (j1.tipbazad = 900 AND j1.tipbazac = 100 AND j1.tipcontc = 800) OR -- diferente curs valutare la stornare avans - venit
          (j1.tipbazac = 900 AND j1.tipbazad = 100 AND j1.tipcontd = 800)    -- diferente curs valutare la stornare avans - cheltuiala
        );

  INSERT INTO TMP_SAFT_EXCL_J1(
    TIPDOC, CODDOC, AN, LUNA,
    CodDescrD, IcontD, TipContD, AnaliticContD,
    CodDescrC, IcontC, TipContC, AnaliticContC
  )
  SELECT DISTINCT
    J1.TIPDOC, J1.CODDOC, J1.AN, J1.LUNA,
    j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD,
    j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC
  FROM TREZOR T
    INNER JOIN TREZOR1 T1 ON T1.CODTREZOR = T.CODTREZOR
    INNER JOIN JURNAL1 J1 ON J1.TIPDOC = T.TIPDOC AND J1.CODDOC = T.CODTREZOR AND J1.INDEXLOCAL = T1.CODTREZOR1
  WHERE T.AN*12+T.LUNA BETWEEN v_ALIni AND v_ALFin
    AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE T.SUBUNITATEA END
    AND (j1.icontd = 2 AND j1.icontc = 2) -- stingere documente
  ;

  UPDATE TMP_SAFT_EXCL_J1
  SET CONTD = (SELECT wme_result FROM PKG_JURNAL_GETCONTFORJURNAL(NULL, CodDescrD, IcontD, TipContD, AnaliticContD, An, Luna)),
      CONTC = (SELECT wme_result FROM PKG_JURNAL_GETCONTFORJURNAL(NULL, CodDescrC, IcontC, TipContC, AnaliticContC, An, Luna));

  UPDATE TMP_SAFT_JURNAL J
  SET EXCL_TAXINFO = 0;

  UPDATE TMP_SAFT_JURNAL J
  SET EXCL_TAXINFO = 1
  WHERE EXCL_TAXINFO = 0
    AND EXISTS (SELECT 1 FROM TMP_SAFT_EXCL_J1 EJ1 WHERE EJ1.TIPDOC  = J.TIPDOC AND EJ1.CODDOC = J.CODDOC AND EJ1.CONTD = J.CONTD AND EJ1.CONTC = J.CONTC);

  FOR vRec IN (
    SELECT DISTINCT AN, LUNA
    FROM TMP_SAFT_JURNAL
    WHERE TIPDOC IN (19, 26)
  ) LOOP
    vCIntermedMarja := To_Number(Coalesce(fnc_getvalconstanta('CIntermedMarja' ,vRec.AN,vRec.Luna),'0'));
    IF vCIntermedMarja &lt;&gt; 0 THEN
      UPDATE TMP_SAFT_JURNAL
      SET EXCL_TAXINFO = 1
      WHERE EXCL_TAXINFO = 0
        AND TIPDOC IN (19, 26)
        AND AN = vRec.AN AND LUNA = vRec.Luna
        AND vCIntermedMarja IN (CONTD, CONTC);
    END IF;
  END LOOP;

  PERFORM pkg_saft_PUT_INFO('00.C01','BEGIN_SAFT--ActulizareCodSaftInNCont');
  IF pSubunit = 1 THEN
   -- caz 1 din NPARTSOLDLUNA
    PERFORM pkg_saft_PUT_INFO('00.C11','BEGIN_SAFT--TMP_SAFT_NPART');
    INSERT INTO TMP_SAFT_NPART (CODPART, ICONT, SOLDI, SOLDF)
    SELECT CODPART, ICONT, Sum(Coalesce(SOLDI, 0)), Sum(Coalesce(SOLDF, 0))
    FROM (
      SELECT CODPART, ICONT, SOLDLEI AS SOLDI, 0       AS SOLDF FROM NPARTSOLDLUNA WHERE AN = vAnP   AND LUNA = vLunaP   AND Round(SOLDLEI,2) &lt;&gt; 0 AND CODPART &lt;&gt; 0 AND ICONT &lt;&gt; 0 UNION ALL
      SELECT CODPART, ICONT, 0       AS SOLDI, SOLDLEI AS SOLDF FROM NPARTSOLDLUNA WHERE AN = vAnFin AND LUNA = vLunaFin AND Round(SOLDLEI,2) &lt;&gt; 0 AND CODPART &lt;&gt; 0 AND ICONT &lt;&gt; 0
    ) subs
    GROUP BY CODPART, ICONT;

    -- caz 2 din OBLIGPIFLUNA unde au fost modificari
    PERFORM pkg_saft_PUT_INFO('00.C12','BEGIN_SAFT--TMP_SAFT_NPART');
    INSERT INTO TMP_SAFT_NPART (CODPART, ICONT, CLIENT, FURNIZOR, SOLDI, SOLDF)
    SELECT subs.CODPART, subs.ICONT, Max(subs.CLIENT), Max(subs.FURNIZOR), 0 AS SOLDI, 0 AS SOLDF
    FROM (
      SELECT
        O.CODPART, O.ICONT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 600 THEN 1 ELSE 0 END AS CLIENT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 500 THEN 1 ELSE 0 END AS FURNIZOR,
        0 AS SOLDI, 0 AS SOLDF
      FROM OBLIGPIFLUNA OL
        INNER JOIN OBLIGPIF     O   ON O.CODOBLIGPIF   = OL.CODOBLIGPIF
        INNER JOIN GENERAL      G   ON G.CODGENERAL    = O.CODGENERAL
        LEFT  JOIN IESIRI       I   ON I.CODIES        = G.CODDOC AND I.TIPDOC = G.TIPDOC
        INNER JOIN NPART        P   ON P.CODPART       = O.CODPART
        LEFT  JOIN OBLIGPIFLUNA OLP ON OLP.CODOBLIGPIF = OL.CODOBLIGPIF AND OLP.AN = OL.AN - CASE WHEN OL.LUNA = 1 THEN 1 ELSE 0 END AND OLP.LUNA = CASE WHEN OL.LUNA = 1 THEN 12 ELSE OL.LUNA-1 END
      WHERE O.SEMNIFICATIE IN (100, 110, 120, 130, 140, 200, 210, 220, 240, 310, 330, 410, 430, 500, 600, 1200, 1201, 1301, 1351, 1303)
        AND OL.AN*12+OL.LUNA BETWEEN v_ALIni AND v_ALFin
        AND NOT ( Coalesce(O.Valoare , 0) = 0 AND Coalesce(I.CUSTODIE, 0) = 1 )
        AND NOT EXISTS (SELECT 1 FROM TMP_SAFT_NPART T WHERE T.CODPART = O.CODPART AND T.ICONT = O.ICONT)
        AND O.CODPART &lt;&gt; 0 AND O.ICONT &lt;&gt; 0
        AND NOT ( Coalesce(O.Valoare , 0) = 0 AND Coalesce(I.CUSTODIE, 0) = 1 )
        AND ( (OLP.CODOBLIGPIF IS NULL) OR (OL.REST &lt;&gt; OLP.REST) )
    ) subs
    GROUP BY subs.CODPART, subs.ICONT;

    -- caz 3 din OBLIGPIFLUNA unde nu au fost modificari - de analizat daca are rost acest caz (si nu ar trebui sa fie deja incluse in cazul 1)
    PERFORM pkg_saft_PUT_INFO('00.C13','BEGIN_SAFT--TMP_SAFT_NPART');
    INSERT INTO TMP_SAFT_NPART (CODPART, ICONT, CLIENT, FURNIZOR, SOLDI, SOLDF)
    SELECT subs.CODPART, subs.ICONT, Max(subs.CLIENT), Max(subs.FURNIZOR), 0 AS SOLDI, 0 AS SOLDF
    FROM (
      SELECT
        O.CODPART, O.ICONT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 600 THEN 1 ELSE 0 END AS CLIENT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 500 THEN 1 ELSE 0 END AS FURNIZOR,
        OL.REST, Sum(OL.REST) OVER (PARTITION BY O.CODPART, O.ICONT) RestPartICont, O.CODOBLIGPIF
      FROM OBLIGPIFLUNA OL
        INNER JOIN OBLIGPIF     O   ON O.CODOBLIGPIF   = OL.CODOBLIGPIF
        INNER JOIN GENERAL      G   ON G.CODGENERAL    = O.CODGENERAL
        LEFT  JOIN IESIRI       I   ON I.CODIES        = G.CODDOC AND I.TIPDOC = G.TIPDOC
        INNER JOIN NPART        P   ON P.CODPART       = O.CODPART
        LEFT  JOIN OBLIGPIFLUNA OLP ON OLP.CODOBLIGPIF = OL.CODOBLIGPIF AND OLP.AN = OL.AN - CASE WHEN OL.LUNA = 1 THEN 1 ELSE 0 END AND OLP.LUNA = CASE WHEN OL.LUNA = 1 THEN 12 ELSE OL.LUNA-1 END
      WHERE O.SEMNIFICATIE IN (100, 110, 120, 130, 140, 200, 210, 220, 240, 310, 330, 410, 430, 500, 600, 1200, 1201, 1301, 1351, 1303)
        AND OL.AN*12+OL.LUNA BETWEEN v_ALIni AND v_ALFin
        AND NOT ( Coalesce(O.Valoare , 0) = 0 AND Coalesce(I.CUSTODIE, 0) = 1 )
        AND NOT EXISTS (SELECT 1 FROM TMP_SAFT_NPART T WHERE T.CODPART = O.CODPART AND T.ICONT = O.ICONT)
        AND O.CODPART &lt;&gt; 0 AND O.ICONT &lt;&gt; 0
    ) subs
    WHERE subs.RestPartICont &lt;&gt; 0
    GROUP BY subs.CODPART, subs.ICONT;

 -- caz 4 din OBLIGPIFLUNA plati incasarie trezorerie
    perform pkg_saft_PUT_INFO('00.C14','BEGIN_SAFT--TMP_SAFT_NPART');
    INSERT INTO TMP_SAFT_NPART (CODPART, ICONT, CLIENT, FURNIZOR, SOLDI, SOLDF)
    SELECT subs.CODPART, subs.ICONT, Max(subs.CLIENT), Max(subs.FURNIZOR), 0 AS SOLDI, 0 AS SOLDF
    FROM (
      SELECT
        O.CODPART, O.ICONT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 400 THEN 1 ELSE 0 END AS CLIENT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 300 THEN 1 ELSE 0 END AS FURNIZOR
      FROM OBLIGPIF O
        INNER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
        INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
        INNER JOIN TREZOR  T  ON T.CODTREZOR   = T1.CODTREZOR AND T.TIPDOC = G.TIPDOC
        INNER JOIN NPART   P  ON P.CODPART     = O.CODPART
      WHERE O.SEMNIFICATIE IN (300, 400)
        AND T.AN*12+T.LUNA BETWEEN v_ALIni AND v_ALFin
        AND Coalesce(O.Valoare , 0) &lt;&gt; 0
        AND NOT EXISTS (SELECT 1 FROM TMP_SAFT_NPART T WHERE T.CODPART = O.CODPART AND T.ICONT = O.ICONT)
        AND O.CODPART &lt;&gt; 0 AND O.ICONT &lt;&gt; 0
    ) subs
    GROUP BY subs.CODPART, subs.ICONT;
  ELSE
    -- caz 1 din NPARTSOLDLUNASUB
    PERFORM pkg_saft_PUT_INFO('00.C21','BEGIN_SAFT--TMP_SAFT_NPART');
    INSERT INTO TMP_SAFT_NPART (CODPART, ICONT, SOLDI, SOLDF)
    SELECT CODPART, ICONT, Sum(Coalesce(SOLDI, 0)), Sum(Coalesce(SOLDF, 0))
    FROM (
      SELECT CODPART, ICONT, SOLDLEI AS SOLDI, 0       AS SOLDF FROM NPARTSOLDLUNASUB WHERE AN = vAnP   AND LUNA = vLunaP   AND SUBUNITATEA = pSubunit AND Round(SOLDLEI,2) &lt;&gt; 0 AND CODPART &lt;&gt; 0 AND ICONT &lt;&gt; 0 UNION ALL
      SELECT CODPART, ICONT, 0       AS SOLDI, SOLDLEI AS SOLDF FROM NPARTSOLDLUNASUB WHERE AN = vAnFin AND LUNA = vLunaFin AND SUBUNITATEA = pSubunit AND Round(SOLDLEI,2) &lt;&gt; 0 AND CODPART &lt;&gt; 0 AND ICONT &lt;&gt; 0
    ) subs
    GROUP BY CODPART, ICONT;

    -- caz 2 din OBLIGPIFLUNA unde au fost modificari
    PERFORM pkg_saft_PUT_INFO('00.C22','BEGIN_SAFT--TMP_SAFT_NPART');
    INSERT INTO TMP_SAFT_NPART (CODPART, ICONT, CLIENT, FURNIZOR, SOLDI, SOLDF)
    SELECT subs.CODPART, subs.ICONT, Max(subs.CLIENT), Max(subs.FURNIZOR), 0 AS SOLDI, 0 AS SOLDF
    FROM (
      SELECT
        O.CODPART, O.ICONT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 600 THEN 1 ELSE 0 END AS CLIENT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 500 THEN 1 ELSE 0 END AS FURNIZOR,
        CASE
          WHEN O.SEMNIFICATIE IN (100, 110, 120, 140) THEN (SELECT SUBUNITATEA FROM INTRARI I            WHERE I.TIPDOC = G.TIPDOC AND I.CODINTR     = G.CODDOC)
          WHEN O.SEMNIFICATIE = 130                   THEN (SELECT SUBUNITATEA FROM DVI D, INTRARI I     WHERE 5        = G.TIPDOC AND D.CODDVI      = G.CODDOC AND I.CODINTR   = D.CODINTR)
          WHEN O.SEMNIFICATIE IN (200, 210, 220, 240) THEN (SELECT SUBUNITATEA FROM IESIRI I             WHERE I.TIPDOC = G.TIPDOC AND I.CODIES      = G.CODDOC)
          WHEN O.SEMNIFICATIE IN (310, 330, 410, 430) THEN (SELECT SUBUNITATEA FROM TREZOR T, TREZOR1 T1 WHERE T.TIPDOC = G.TIPDOC AND T1.CODTREZOR1 = G.CODDOC AND T.CODTREZOR = T1.CODTREZOR)
          WHEN O.SEMNIFICATIE IN (1200, 1201)         THEN (SELECT SUBUNITATEA FROM NC N, NC1 N1         WHERE 35       = G.TIPDOC AND N1.CODNC1     = G.CODDOC AND N.CODNC     = N1.CODNC)
          WHEN O.SEMNIFICATIE IN (1301, 1351, 1303)   THEN (SELECT SUBUNITATEA FROM COMPENS C            WHERE 28       = G.TIPDOC AND C.CODCOMPENS  = G.CODDOC)
        END AS SUBUNITATEA
      FROM OBLIGPIFLUNA OL
        INNER JOIN OBLIGPIF     O   ON O.CODOBLIGPIF   = OL.CODOBLIGPIF
        INNER JOIN GENERAL      G   ON G.CODGENERAL    = O.CODGENERAL
        LEFT  JOIN IESIRI       I   ON I.CODIES        = G.CODDOC AND I.TIPDOC = G.TIPDOC
        INNER JOIN NPART        P   ON P.CODPART       = O.CODPART
        LEFT  JOIN OBLIGPIFLUNA OLP ON OLP.CODOBLIGPIF = OL.CODOBLIGPIF AND OLP.AN = OL.AN - CASE WHEN OL.LUNA = 1 THEN 1 ELSE 0 END AND OLP.LUNA = CASE WHEN OL.LUNA = 1 THEN 12 ELSE OL.LUNA-1 END
     WHERE O.SEMNIFICATIE IN (100, 110, 120, 130, 140, 200, 210, 220, 240, 300, 310, 330, 400, 410, 430, 500, 600, 1200, 1201, 1301, 1351, 1303)
        AND OL.AN*12+OL.LUNA BETWEEN v_ALIni AND v_ALFin
        AND NOT ( Coalesce(O.Valoare , 0) = 0 AND Coalesce(I.CUSTODIE, 0) = 1 )
        AND NOT EXISTS (SELECT 1 FROM TMP_SAFT_NPART T WHERE T.CODPART = O.CODPART AND T.ICONT = O.ICONT)
        AND O.CODPART &lt;&gt; 0 AND O.ICONT &lt;&gt; 0
        AND ( (OLP.CODOBLIGPIF IS NULL) OR (OL.REST &lt;&gt; OLP.REST) )
    ) subs
    WHERE subs.SUBUNITATEA = pSubunit
    GROUP BY subs.CODPART, subs.ICONT;

    -- caz 3 din OBLIGPIFLUNA unde nu au fost modificari - de analizat daca are rost acest caz (si nu ar trebui sa fie deja incluse in cazul 1)
    PERFORM pkg_saft_PUT_INFO('00.C23','BEGIN_SAFT--TMP_SAFT_NPART');
    INSERT INTO TMP_SAFT_NPART (CODPART, ICONT, CLIENT, FURNIZOR, SOLDI, SOLDF)
    SELECT subs.CODPART, subs.ICONT, Max(subs.CLIENT), Max(subs.FURNIZOR), 0 AS SOLDI, 0 AS SOLDF
    FROM (
      SELECT
        O.CODPART, O.ICONT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 600 THEN 1 ELSE 0 END AS CLIENT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 500 THEN 1 ELSE 0 END AS FURNIZOR,
        CASE
          WHEN O.SEMNIFICATIE IN (100, 110, 120, 140) THEN (SELECT SUBUNITATEA FROM INTRARI I            WHERE I.TIPDOC = G.TIPDOC AND I.CODINTR     = G.CODDOC)
          WHEN O.SEMNIFICATIE = 130                   THEN (SELECT SUBUNITATEA FROM DVI D, INTRARI I     WHERE 5        = G.TIPDOC AND D.CODDVI      = G.CODDOC AND I.CODINTR   = D.CODINTR)
          WHEN O.SEMNIFICATIE IN (200, 210, 220, 240) THEN (SELECT SUBUNITATEA FROM IESIRI I             WHERE I.TIPDOC = G.TIPDOC AND I.CODIES      = G.CODDOC)
          WHEN O.SEMNIFICATIE IN (310, 330, 410, 430) THEN (SELECT SUBUNITATEA FROM TREZOR T, TREZOR1 T1 WHERE T.TIPDOC = G.TIPDOC AND T1.CODTREZOR1 = G.CODDOC AND T.CODTREZOR = T1.CODTREZOR)
          WHEN O.SEMNIFICATIE IN (1200, 1201)         THEN (SELECT SUBUNITATEA FROM NC N, NC1 N1         WHERE 35       = G.TIPDOC AND N1.CODNC1     = G.CODDOC AND N.CODNC     = N1.CODNC)
          WHEN O.SEMNIFICATIE IN (1301, 1351, 1303)   THEN (SELECT SUBUNITATEA FROM COMPENS C            WHERE 28       = G.TIPDOC AND C.CODCOMPENS  = G.CODDOC)
        END AS SUBUNITATEA,
        OL.REST, Sum(OL.REST) OVER (PARTITION BY O.CODPART, O.ICONT) RestPartICont, O.CODOBLIGPIF
      FROM OBLIGPIFLUNA OL
        INNER JOIN OBLIGPIF     O   ON O.CODOBLIGPIF   = OL.CODOBLIGPIF
        INNER JOIN GENERAL      G   ON G.CODGENERAL    = O.CODGENERAL
        LEFT  JOIN IESIRI       I   ON I.CODIES        = G.CODDOC AND I.TIPDOC = G.TIPDOC
        INNER JOIN NPART        P   ON P.CODPART       = O.CODPART
        LEFT  JOIN OBLIGPIFLUNA OLP ON OLP.CODOBLIGPIF = OL.CODOBLIGPIF AND OLP.AN = OL.AN - CASE WHEN OL.LUNA = 1 THEN 1 ELSE 0 END AND OLP.LUNA = CASE WHEN OL.LUNA = 1 THEN 12 ELSE OL.LUNA-1 END
      WHERE O.SEMNIFICATIE IN (100, 110, 120, 130, 140, 200, 210, 220, 240, 310, 330, 410, 430, 500, 600, 1200, 1201, 1301, 1351, 1303)
        AND OL.AN*12+OL.LUNA BETWEEN v_ALIni AND v_ALFin
        AND NOT ( Coalesce(O.Valoare , 0) = 0 AND Coalesce(I.CUSTODIE, 0) = 1 )
        AND NOT EXISTS (SELECT 1 FROM TMP_SAFT_NPART T WHERE T.CODPART = O.CODPART AND T.ICONT = O.ICONT)
        AND O.CODPART &lt;&gt; 0 AND O.ICONT &lt;&gt; 0
    ) subs
    WHERE subs.SUBUNITATEA = pSubunit
      AND subs.RestPartICont &lt;&gt; 0
    GROUP BY subs.CODPART, subs.ICONT;

 -- caz 4 din OBLIGPIFLUNA plati incasarie trezorerie
    perform pkg_saft_PUT_INFO('00.C24','BEGIN_SAFT--TMP_SAFT_NPART');
    INSERT INTO TMP_SAFT_NPART (CODPART, ICONT, CLIENT, FURNIZOR, SOLDI, SOLDF)
    SELECT subs.CODPART, subs.ICONT, Max(subs.CLIENT), Max(subs.FURNIZOR), 0 AS SOLDI, 0 AS SOLDF
    FROM (
      SELECT
        O.CODPART, O.ICONT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 400 THEN 1 ELSE 0 END AS CLIENT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 300 THEN 1 ELSE 0 END AS FURNIZOR
      FROM OBLIGPIF O
        INNER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
        INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
        INNER JOIN TREZOR  T  ON T.CODTREZOR   = T1.CODTREZOR AND T.TIPDOC = G.TIPDOC
        INNER JOIN NPART   P  ON P.CODPART     = O.CODPART
      WHERE O.SEMNIFICATIE IN (300, 400)
        AND T.AN*12+T.LUNA BETWEEN v_ALIni AND v_ALFin
        AND Coalesce(O.Valoare , 0) &lt;&gt; 0
        AND NOT EXISTS (SELECT 1 FROM TMP_SAFT_NPART T WHERE T.CODPART = O.CODPART AND T.ICONT = O.ICONT)
        AND O.CODPART &lt;&gt; 0 AND O.ICONT &lt;&gt; 0
        AND T.SUBUNITATEA = pSubunit
    ) subs
    GROUP BY subs.CODPART, subs.ICONT;
  END IF;

  PERFORM pkg_saft_PUT_INFO('00.C34','BEGIN_SAFT--TMP_SAFT_NPART');
  UPDATE TMP_SAFT_NPART
  SET CLIENT   = CASE WHEN ICONT IN (0,1) THEN CLIENT   WHEN ICONT IN (3,5,7,10,11,18,20,23,24,30,31,32,33,34,61)                                                                                         THEN 1 ELSE 0 END,
      FURNIZOR = CASE WHEN ICONT IN (0,1) THEN FURNIZOR WHEN ICONT IN (2,4,6,8,9,12,13,14,15,16,17,19,21,22,25,26,27,28,29,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60) THEN 1 ELSE 0 END;

  PERFORM pkg_saft_PUT_INFO('00.C35','BEGIN_SAFT--TMP_SAFT_NPART');
  DELETE FROM TMP_SAFT_NPART WHERE CLIENT = 0 AND FURNIZOR = 0;

  PERFORM pkg_saft_PUT_INFO('00.C36','BEGIN_SAFT--TMP_SAFT_NPART');
  CALL UPDATE_CODCONT_FROM_IOPART1 ('TMP_SAFT_NPART', 'CODCONT', 'CODPART', 'ICONT', '', v_ALFin);
  --UPDATE TMP_SAFT_NPART SET CODCONT = PKG_LIST_BASE_UTILS_iCont_CodCont(ICONT, CODPART, v_ALFin, 0);

  PERFORM pkg_saft_PUT_INFO('00.C37','BEGIN_SAFT--TMP_SAFT_NPART - VERIFICA INFOCM');
  INSERT INTO TMP_SAFT_NPART (CODPART, ICONT, CODCONT, CLIENT, FURNIZOR, SOLDI, SOLDF)
  SELECT DISTINCT PARTENER, 0 AS ICONT, 0 AS CODCONT, 1 AS CLIENT, 0 AS FURNIZOR, 0 AS SOLDI, 0 AS SOLDF
  FROM IESIRI I
  WHERE I.INFOCM = 1
    AND I.AN*12+I.LUNA BETWEEN v_ALIni AND v_ALFin
    AND NOT EXISTS (SELECT 1 FROM TMP_SAFT_NPART T WHERE T.CODPART = I.PARTENER AND T.CLIENT = 1)
    AND I.PARTENER &lt;&gt; 0
    AND I.SUBUNITATEA = Coalesce(NULLIF(pSubunit,1),I.SUBUNITATEA);

  PERFORM pkg_saft_PUT_INFO('00.D','BEGIN_SAFT--ActulizareCodSaftInNCont');
  PERFORM pkg_saft_UMPLE_NPARTDET(v_ALIni, v_ALFin, TRUE);

  INSERT INTO TMP_SAFT_NPARTFUZ SELECT Min(CodPart) OVER (PARTITION BY PARTID) CODPARTFUZ, CODPART FROM TMP_SAFT_NPARTDET;
  DELETE FROM TMP_SAFT_NPARTDET WHERE CodPart IN (SELECT CODPART FROM TMP_SAFT_NPARTFUZ WHERE CODPARTFUZ &lt;&gt; CODPART);
  PERFORM pkg_saft_PUT_INFO('00.E01','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  EXECUTE 'TRUNCATE TABLE TMP_MANEVRA2';
  INSERT INTO TMP_MANEVRA2(CODUNIC)
  SELECT CODINTR
  FROM INTRARI I
  WHERE I.AN*12+I.LUNA BETWEEN v_ALIni AND v_ALFin
    AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE I.SUBUNITATEA END;
  INSERT INTO TMP_MANEVRA2(CODUNIC)
  SELECT J.INDEXLOCAL
  FROM JURNAL J
  WHERE J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
    AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
    AND J.TIPDOC = 81 AND J.CODDOC = 1
    AND EXISTS(SELECT 1 FROM INTRARI I WHERE I.CODINTR = J.INDEXLOCAL AND I.AN*12+I.LUNA &lt; v_ALIni );
  PERFORM pkg_saft_PUT_INFO('00.E02','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD,
    CHEIE_CODCONTDED, CHEIE_CODCONTCOL, CHEIE_TAXVAL,
    CODCONTDED
  )
  SELECT
    NEXTVAL('SEQ_SAFT_TI'),
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD,
    To_Number(CHEIE_CODCONTDED) CHEIE_CODCONTDED, To_Number(Coalesce(CHEIE_CODCONTCOL, CHEIE_CODCONTPRORATA)) CHEIE_CODCONTCOL, To_Number(CHEIE_TAXVAL) CHEIE_TAXVAL,
    CASE
      WHEN subs.tipdoc = 5 AND subs.TIPTRANZACTIE = 3
      THEN (SELECT Max(c.codcont) FROM jurnal j INNER JOIN TMP_SAFT_CC4426 c ON c.codcont = j.contd WHERE j.tipdoc = subs.tipdoc AND j.coddoc = subs.coddoc)
      ELSE NULL
    END AS CODCONTDED
  FROM (
    SELECT
      TD.TIPDOC, TD.CODDOC, TD.CODCONT,
      To_Char(TT.COD, 'fm999000') TAXTYPE, To_Char(Coalesce(TD.TaxCode, 0), 'fm999000000') TAXCODE, TC.ProcTaxa TAXPERCENTAGE, Sum(TD.TAXBASE) TAXBASE, Sum(TD.TAXVAL) TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL::NUMERIC CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD,
      NullIf(CASE WHEN Instr(TD.Cheia, '&lt;P') &gt; 0 THEN SubStr(TD.Cheia, Instr(TD.Cheia, '&lt;P')+2, Instr(TD.Cheia,'P&gt;')-Instr(TD.Cheia,'&lt;P')-2) END, '') CHEIE_CODCONTPRORATA,
      NullIf(CASE WHEN Instr(TD.Cheia, '&lt;D') &gt; 0 THEN SubStr(TD.Cheia, Instr(TD.Cheia, '&lt;D')+2, Instr(TD.Cheia,'D&gt;')-Instr(TD.Cheia,'&lt;D')-2) END, '') CHEIE_CODCONTDED,
      NullIf(CASE WHEN Instr(TD.Cheia, '&lt;C') &gt; 0 THEN SubStr(TD.Cheia, Instr(TD.Cheia, '&lt;C')+2, Instr(TD.Cheia,'C&gt;')-Instr(TD.Cheia,'&lt;C')-2) END, '') CHEIE_CODCONTCOL,
      NullIf(CASE WHEN Instr(TD.Cheia, '&lt;V') &gt; 0 THEN SubStr(TD.Cheia, Instr(TD.Cheia, '&lt;V')+2, Instr(TD.Cheia,'V&gt;')-Instr(TD.Cheia,'&lt;V')-2) END, '') CHEIE_TAXVAL,
      I.TIPTRANZACTIE
    FROM TMP_MANEVRA2 M
      INNER JOIN INTRARI               I  ON I.CODINTR  = M.CODUNIC
      INNER JOIN TAXDECL               TD ON TD.TIPDOC  = I.TIPDOC AND TD.CODDOC = I.CODINTR
      LEFT  JOIN WINMADMIN.TaxCodeSaft TC ON TC.Cod     = TD.TaxCode
      LEFT  JOIN NCONT                 C  ON C.CodCont  = TD.CodCont
      LEFT  JOIN WINMADMIN.TaxTypeSaft TT ON TT.COD     = CASE
                                                            WHEN COALESCE(C.TAXTYPE, 0) = 0 AND COALESCE(C.IMPOZIT, 0) = 1 THEN 0
                                                            WHEN COALESCE(C.TAXTYPE, 0) = 0                                THEN 300
                                                            ELSE C.TAXTYPE
                                                          END
    WHERE TD.TaxCode &gt; 0
      AND TD.MANUAL  &lt;&gt; 2
      AND Coalesce(TD.CODDOC1, 0) &gt;= 0
      AND NOT ( Coalesce(TD.TAXBASE, 0) = 0 AND Coalesce(TD.TAXVAL, 0) = 0 )
    GROUP BY TD.TIPDOC, TD.CODDOC, TD.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa, I.TIPTRANZACTIE, TD.Cheia, TT.Description
    ORDER BY TD.TIPDOC, TD.CODDOC, TD.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa
  ) subs;

  PERFORM pkg_saft_PUT_INFO('00.E03','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD,
    CODCONTDED
  )
  SELECT
    NEXTVAL('SEQ_SAFT_TI'),
    TIPDOC, CODDOC, CODCONT,
    TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD,
    (SELECT Max(c.codcont) FROM jurnal j INNER JOIN TMP_SAFT_CC4426 c ON c.codcont = j.contc WHERE j.tipdoc = subs.tipdoc AND j.coddoc = subs.coddoc) AS CODCONTDED
  FROM (
    SELECT
      TD.TIPDOC, TD.CODDOC, C.CODCONT,
      To_Char(TT.COD, 'fm999000') TAXTYPE, To_Char(Coalesce(TD.TaxCode, 0), 'fm999000000') TAXCODE, TC.ProcTaxa TAXPERCENTAGE, Sum(TD.TAXBASE) TAXBASE, Sum(TD.TAXVAL) TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL::NUMERIC CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD
    FROM TMP_MANEVRA2 M
      INNER JOIN INTRARI               I  ON I.CODINTR  = M.CODUNIC
      INNER JOIN TAXDECL               TD ON TD.TIPDOC  = I.TIPDOC AND TD.CODDOC = I.CODINTR
      LEFT  JOIN WINMADMIN.TaxCodeSaft TC ON TC.Cod     = TD.TaxCode
      LEFT  JOIN NCONT                 C  ON C.CodCont  = CASE WHEN vTipTVAMixt100 = 2 THEN vCCheltTVADed ELSE TD.CodCont END
      LEFT  JOIN WINMADMIN.TaxTypeSaft TT ON TT.COD     = CASE
                                                            WHEN COALESCE(C.TAXTYPE, 0) = 0 AND COALESCE(C.IMPOZIT, 0) = 1 THEN 0
                                                            WHEN COALESCE(C.TAXTYPE, 0) = 0                                THEN 300
                                                            ELSE C.TAXTYPE
                                                          END
    WHERE TD.TaxCode &gt; 0
      AND TD.MANUAL  &lt;&gt; 2
      AND Coalesce(TD.CODDOC1, 0) &lt; 0
    GROUP BY TD.TIPDOC, TD.CODDOC, C.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa, TT.DESCRIPTION
    ORDER BY TD.TIPDOC, TD.CODDOC, C.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa
  ) subs;
  PERFORM pkg_saft_PUT_INFO('00.E04','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  EXECUTE 'TRUNCATE TABLE TMP_MANEVRA2';
  INSERT INTO TMP_MANEVRA2(CODUNIC)
  SELECT CODIES
  FROM IESIRI I
  WHERE I.AN*12+I.LUNA BETWEEN v_ALIni AND v_ALFin
    AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE I.SUBUNITATEA END;
  INSERT INTO TMP_MANEVRA2(CODUNIC)
  SELECT J.INDEXLOCAL
  FROM JURNAL J
  WHERE J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
    AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
    AND J.TIPDOC = 81 AND J.CODDOC = 2
    AND EXISTS(SELECT 1 FROM IESIRI I WHERE I.CODIES = J.INDEXLOCAL AND I.AN*12+I.LUNA &lt; v_ALIni );

  PERFORM pkg_saft_PUT_INFO('00.E05','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD,
    CHEIE_BAZATVAMARJA
  )
  SELECT
    NEXTVAL('SEQ_SAFT_TI'),
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD,
    To_Number(CHEIE_BAZATVAMARJA)
  FROM (
    SELECT
      TD.TIPDOC, TD.CODDOC, TD.CODCONT,
      To_Char(TT.COD, 'fm999000') TAXTYPE, To_Char(Coalesce(TD.TaxCode, 0), 'fm999000000') TAXCODE, TC.ProcTaxa TAXPERCENTAGE, Sum(TD.TAXBASE) TAXBASE, Sum(TD.TAXVAL) TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL::NUMERIC CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD,
      CASE
        WHEN I.TIPTVA IN (7,8) THEN CASE WHEN Instr(TD.Cheia,'BAZATVAMARJA&gt;') &gt; 0 THEN SubStr(TD.Cheia, Instr(TD.Cheia, '&lt;BAZATVAMARJA')+13, Instr(TD.Cheia,'BAZATVAMARJA&gt;')-Instr(TD.Cheia,'&lt;BAZATVAMARJA')-13) ELSE NULL END
        ELSE NULL
      END AS CHEIE_BAZATVAMARJA
    FROM TMP_MANEVRA2 M
      INNER JOIN IESIRI                I  ON I.CODIES   = M.CODUNIC
      INNER JOIN TAXDECL               TD ON TD.TIPDOC  = I.TIPDOC AND TD.CODDOC = I.CodIes
      LEFT  JOIN WINMADMIN.TaxCodeSaft TC ON TC.Cod     = TD.TaxCode
      LEFT  JOIN NCONT                 C  ON C.CodCont  = TD.CodCont
      LEFT  JOIN WINMADMIN.TaxTypeSaft TT ON TT.COD     = CASE
                                                            WHEN COALESCE(C.TAXTYPE, 0) = 0 AND COALESCE(C.IMPOZIT, 0) = 1 THEN 0
                                                            WHEN COALESCE(C.TAXTYPE, 0) = 0                                THEN 300
                                                            ELSE C.TAXTYPE
                                                          END
    WHERE TD.TaxCode &lt;&gt; 0
      AND TD.MANUAL  &lt;&gt; 2
    GROUP BY TD.TIPDOC, TD.CODDOC, TD.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa, TT.DESCRIPTION, TD.Cheia, I.TIPTVA
    ORDER BY TD.TIPDOC, TD.CODDOC, TD.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa
  ) subs;
  PERFORM pkg_saft_PUT_INFO('00.E06','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  )
  SELECT
    NEXTVAL('SEQ_SAFT_TI'),
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  FROM (
    SELECT
      TD.TIPDOC, TD.CODDOC, TD.CODCONT,
      To_Char(TT.COD, 'fm999000') TAXTYPE, To_Char(Coalesce(TD.TaxCode, 0), 'fm999000000') TAXCODE, TC.ProcTaxa TAXPERCENTAGE, Sum(TD.TAXBASE) TAXBASE, Sum(TD.TAXVAL) TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL::NUMERIC CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD
    FROM TREZOR T
      INNER JOIN TREZOR1               T1 ON T1.CODTREZOR = T.CodTrezor
      INNER JOIN TAXDECL               TD ON TD.TIPDOC    = T.TIPDOC AND TD.CODDOC = T1.CodTrezor1
      LEFT  JOIN WINMADMIN.TaxCodeSaft TC ON TC.Cod       = TD.TaxCode
      LEFT  JOIN NCONT                 C  ON C.CodCont    = TD.CodCont
      LEFT  JOIN WINMADMIN.TaxTypeSaft TT ON TT.COD       = CASE
                                                              WHEN COALESCE(C.TAXTYPE, 0) = 0 AND COALESCE(C.IMPOZIT, 0) = 1 THEN 0
                                                              WHEN COALESCE(C.TAXTYPE, 0) = 0                                THEN 300
                                                              ELSE C.TAXTYPE
                                                            END
    WHERE T.AN*12+T.LUNA BETWEEN v_ALIni AND v_ALFin
      AND TD.MANUAL  &lt;&gt; 2
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE T.SUBUNITATEA END
    GROUP BY TD.TIPDOC, TD.CODDOC, TD.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa, TT.DESCRIPTION
    ORDER BY TD.TIPDOC, TD.CODDOC, TD.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa
  ) subs;

  PERFORM pkg_saft_PUT_INFO('00.E07','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  )
  SELECT
    NEXTVAL('SEQ_SAFT_TI'),
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  FROM (
    SELECT
      TD.TIPDOC, TD.CODDOC, TD.CODCONT,
      To_Char(TT.COD, 'fm999000') TAXTYPE, To_Char(Coalesce(TD.TaxCode, 0), 'fm999000000') TAXCODE, TC.ProcTaxa TAXPERCENTAGE, Sum(TD.TAXBASE) TAXBASE, Sum(TD.TAXVAL) TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL::NUMERIC CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD
    FROM COMPENS DOC
      INNER JOIN TAXDECL               TD ON TD.CODDOC    = DOC.CODCOMPENS AND TD.TIPDOC = 28
      LEFT  JOIN WINMADMIN.TaxCodeSaft TC ON TC.Cod       = TD.TaxCode
      LEFT  JOIN NCONT                 C  ON C.CodCont    = TD.CodCont
      LEFT  JOIN WINMADMIN.TaxTypeSaft TT ON TT.COD       = CASE
                                                              WHEN COALESCE(C.TAXTYPE, 0) = 0 AND COALESCE(C.IMPOZIT, 0) = 1 THEN 0
                                                              WHEN COALESCE(C.TAXTYPE, 0) = 0                                THEN 300
                                                              ELSE C.TAXTYPE
                                                            END
    WHERE DOC.AN*12+DOC.LUNA BETWEEN v_ALIni AND v_ALFin
      AND TD.MANUAL  &lt;&gt; 2
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE DOC.SUBUNITATEA END
    GROUP BY TD.TIPDOC, TD.CODDOC, TD.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa, TT.DESCRIPTION
    ORDER BY TD.TIPDOC, TD.CODDOC, TD.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa
  ) subs;

  PERFORM pkg_saft_PUT_INFO('00.E08','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  )
  SELECT
    NEXTVAL('SEQ_SAFT_TI'),
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  FROM (
    SELECT
      TD.TIPDOC, TD.CODDOC, TD.CODCONT,
      To_Char(TT.COD, 'fm999000') TAXTYPE, To_Char(Coalesce(TD.TaxCode, 0), 'fm999000000') TAXCODE, TC.ProcTaxa TAXPERCENTAGE, Sum(TD.TAXBASE) TAXBASE, Sum(TD.TAXVAL) TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL::NUMERIC CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD
    FROM NC DOC
      INNER JOIN TAXDECL               TD ON TD.CODDOC    = DOC.CODNC AND TD.TIPDOC = 35
      LEFT  JOIN WINMADMIN.TaxCodeSaft TC ON TC.Cod       = TD.TaxCode
      LEFT  JOIN NCONT                 C  ON C.CodCont    = TD.CodCont
      LEFT  JOIN WINMADMIN.TaxTypeSaft TT ON TT.COD       = CASE
                                                              WHEN COALESCE(C.TAXTYPE, 0) = 0 AND COALESCE(C.IMPOZIT, 0) = 1 THEN 0
                                                              WHEN COALESCE(C.TAXTYPE, 0) = 0                                THEN 300
                                                              ELSE C.TAXTYPE
                                                            END
    WHERE DOC.AN*12+DOC.LUNA BETWEEN v_ALIni AND v_ALFin
      AND TD.MANUAL  &lt;&gt; 2
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE DOC.SUBUNITATEA END
    GROUP BY TD.TIPDOC, TD.CODDOC, TD.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa, TT.DESCRIPTION
    ORDER BY TD.TIPDOC, TD.CODDOC, TD.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa
  ) subs;

  PERFORM pkg_saft_PUT_INFO('00.E09','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  )
  SELECT
    NEXTVAL('SEQ_SAFT_TI'),
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  FROM (
    SELECT
      DOC.TIPDOC, DOC.CODDOC, DOC.CODCONT,
      To_Char(TT.COD, 'fm999000') TAXTYPE, To_Char(Coalesce(DOC.TaxCode, 0), 'fm999000000') TAXCODE, TC.ProcTaxa TAXPERCENTAGE, 0 TAXBASE, 0 TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL::NUMERIC CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD
    FROM (
      SELECT J.TIPDOC, J.CODDOC, C.CODCONT, 380200 TAXCODE
      FROM TMP_SAFT_JURNAL J INNER JOIN NCONT C ON C.CODCONT = J.CONTD
      WHERE J.TIPDOC = 32
        AND J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
        AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
        AND c.codsaft IN ('4426', '4427')
      UNION
      SELECT J.TIPDOC, J.CODDOC, C.CODCONT, 380200 TAXCODE
      FROM TMP_SAFT_JURNAL J INNER JOIN NCONT C ON C.CODCONT = J.CONTC
      WHERE J.TIPDOC = 32
        AND J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
        AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
        AND c.codsaft IN ('4426', '4427')
    ) DOC
      LEFT JOIN WINMADMIN.TaxCodeSaft TC ON TC.Cod        = DOC.TaxCode
      LEFT JOIN NCONT                 C  ON C.CodCont     = DOC.CodCont
      LEFT JOIN WINMADMIN.TaxTypeSaft TT ON TT.COD        = CASE
                                                              WHEN COALESCE(C.TAXTYPE, 0) = 0 AND COALESCE(C.IMPOZIT, 0) = 1 THEN 0
                                                              WHEN COALESCE(C.TAXTYPE, 0) = 0                                THEN 300
                                                              ELSE C.TAXTYPE
                                                            END
  ) subs;

  PERFORM pkg_saft_PUT_INFO('00.E10','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  )
  SELECT
    NEXTVAL('SEQ_SAFT_TI'),
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  FROM (
    SELECT
      DOC.TIPDOC, DOC.CODJURNAL AS CODDOC, TD.CODCONT,
      To_Char(TT.COD, 'fm999000') TAXTYPE, To_Char(Coalesce(TC.Cod, 0), 'fm999000000') TAXCODE, TC.ProcTaxa TAXPERCENTAGE,
      (TD.TAXBASE-Coalesce(XD.TAXBASE, 0))*DOC.COEF TAXBASE, (TD.TAXVAL-Coalesce(XD.TAXVAL, 0))*DOC.COEF TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL::NUMERIC CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD
    FROM (
      SELECT
        J.CODJURNAL, J.TIPDOC,
        COALESCE( xINT.TIPDOC,  xIES.TIPDOC, 0) AS TIPX,
        COALESCE( xINT.CODINTR, xIES.CODIES, 0) AS CODX,
        CASE
          WHEN POSITION('%' IN 'J.DOCUMENT') = 0                                                                                                  THEN 1
          WHEN SubStr(J.DOCUMENT, 1, POSITION('%' IN 'J.DOCUMENT')-1) &lt;&gt; REGEXP_REPLACE(SubStr(J.DOCUMENT, 1, POSITION('%' IN 'J.DOCUMENT')-1),'\D+','') THEN 1
          ELSE To_Number(SubStr(J.DOCUMENT, 1, POSITION('%' IN 'J.DOCUMENT')-1)) / 100
        END COEF,
        Coalesce(xINT.TVAINCASARE, xIES.TVAINCASARE, 0) TVAINCASARE
      FROM TMP_SAFT_JURNAL J
        LEFT JOIN INTRARI xINT ON xINT.CODINTR = J.INDEXLOCAL AND J.TIPDOC = 81 AND J.CODDOC = 1
        LEFT JOIN IESIRI  xIES ON xIES.CODIES  = J.INDEXLOCAL AND J.TIPDOC = 81 AND J.CODDOC = 2
      WHERE J.TIPDOC = 81
        AND J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
        AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
    ) DOC
      INNER JOIN TAXDECL               TD ON TD.CODDOC    = DOC.CODX AND TD.TIPDOC = DOC.TIPX AND TD.CODDOC1 &gt;= 0
      LEFT  JOIN TAXDECL               XD ON XD.CODDOC    = DOC.CODX AND XD.TIPDOC = DOC.TIPX AND XD.CODDOC1 &lt;  0 AND XD.CODDOC1 = -TD.CODDOC1 -- tichet 58523 am inlocuit INNER cu LEFT
      LEFT  JOIN WINMADMIN.TaxCodeSaft TC ON TC.Cod       = CASE
                                                              WHEN TD.TaxCode IN (301101, 301102, 301103, 301104, 301105) THEN TD.TaxCode
                                                              WHEN TD.TaxCode IN (361301, 361302, 361303, 361304, 361305) THEN TD.TaxCode
                                                              WHEN TD.TaxCode IN (310309, 310310, 310311, 310344, 310351) THEN TD.TaxCode
                                                              WHEN TD.TaxCode = 301301 /* 19% - intrari */                THEN 301101
                                                              WHEN TD.TaxCode = 301302 /*  9% - intrari */                THEN 301102
                                                              WHEN TD.TaxCode = 301303 /*  5% - intrari */                THEN 301103
                                                              WHEN TD.TaxCode = 301305 /* 21% - intrari */                THEN 301104
                                                              WHEN TD.TaxCode = 301306 /* 11% - intrari */                THEN 301105
                                                              WHEN TD.TaxCode = 310335 /* 19% - iesiri  */                THEN 310309
                                                              WHEN TD.TaxCode = 310336 /*  9% - iesiri  */                THEN 310310
                                                              WHEN TD.TaxCode = 310337 /*  5% - iesiri  */                THEN 310311
                                                              WHEN TD.TaxCode = 310350 /* 21% - iesiri  */                THEN 310344
                                                              WHEN TD.TaxCode = 310354 /* 11% - iesiri  */                THEN 310351
                                                              ELSE 0
                                                            END
      LEFT  JOIN NCONT                 C  ON C.CodCont    = TD.CodCont
      LEFT JOIN WINMADMIN.TaxTypeSaft  TT ON TT.COD       = CASE
                                                              WHEN COALESCE(C.TAXTYPE, 0) = 0 AND COALESCE(C.IMPOZIT, 0) = 1 THEN 0
                                                              WHEN COALESCE(C.TAXTYPE, 0) = 0                                THEN 300
                                                              ELSE C.TAXTYPE
                                                            END
    WHERE NOT (DOC.TVAINCASARE = 1 AND TD.TAXVAL = 0) -- exlud linii cu TVA 0 la incasare
  ) subs;

  PERFORM pkg_saft_PUT_INFO('00.E21','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  -- Facturi la avize de iesire
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  )
  SELECT
    NEXTVAL('SEQ_SAFT_TI'),
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  FROM (
    SELECT DISTINCT
      DOC.TIPDOC, DOC.CODDOC, DOC.CODCONT,
      To_Char(TT.COD, 'fm999000') TAXTYPE, To_Char(Coalesce(TD.TaxCode, 0), 'fm999000000') TAXCODE, NULL::NUMERIC TAXPERCENTAGE, 0 TAXBASE, 0 TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL::NUMERIC CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD
    FROM (
      SELECT J.TIPDOC, J.CODDOC, C.CODCONT
      FROM TMP_SAFT_JURNAL J INNER JOIN NCONT C ON C.CODCONT = J.CONTD
      WHERE J.TIPDOC = 26
        AND J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
        AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
        AND c.codsaft IN ('4428')
    ) DOC
      INNER JOIN iesiri1               i1  ON i1.codies   = doc.coddoc
      INNER JOIN ieslink               il  ON il.codies1  = i1.codies1
      INNER JOIN iesiri1               ae1 ON ae1.codies1 = il.codlinieaviz AND Coalesce(ae1.tva, 0) &lt;&gt; 0
      INNER JOIN iesiri                ae  ON ae.codies   = ae1.codies
      LEFT  JOIN taxdecl               td  ON td.tipdoc   = ae.tipdoc AND td.coddoc = ae.codies AND td.coddoc1 = ae1.codies1
      LEFT  JOIN ncont                 c   ON c.codcont   = td.codcont
      LEFT  JOIN WINMADMIN.TaxTypeSaft tt  ON tt.cod      = COALESCE(NULLIF(C.TAXTYPE, 0), 300)
  ) subs;
  PERFORM pkg_saft_PUT_INFO('00.E22','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  -- Facturi la avize de intrare
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  )
  SELECT
    NEXTVAL('SEQ_SAFT_TI'),
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  FROM (
    SELECT DISTINCT
      DOC.TIPDOC, DOC.CODDOC, DOC.CODCONT,
      To_Char(TT.COD, 'fm999000') TAXTYPE, To_Char(Coalesce(TD.TaxCode, 0), 'fm999000000') TAXCODE, NULL::NUMERIC TAXPERCENTAGE, 0 TAXBASE, 0 TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL::NUMERIC CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD
    FROM (
      SELECT J.TIPDOC, J.CODDOC, C.CODCONT
      FROM TMP_SAFT_JURNAL J INNER JOIN NCONT C ON C.CODCONT = J.CONTC
      WHERE J.TIPDOC = 9
        AND J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
        AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
        AND c.codsaft IN ('4428')
    ) DOC
      INNER JOIN intrari1              i1  ON i1.codintr   = doc.coddoc
      INNER JOIN intrlink              il  ON il.codintr1  = i1.codintr1
      INNER JOIN intrari1              ae1 ON ae1.codintr1 = il.codlinieaviz AND Coalesce(ae1.tva, 0) &lt;&gt; 0
      INNER JOIN intrari               ae  ON ae.codintr   = ae1.codintr
      LEFT  JOIN taxdecl               td  ON td.tipdoc    = ae.tipdoc AND td.coddoc = ae.codintr AND td.coddoc1 = ae1.codintr1
      LEFT  JOIN ncont                 c   ON c.codcont    = td.codcont
      LEFT  JOIN WINMADMIN.TaxTypeSaft tt  ON tt.cod       = COALESCE(NULLIF(C.TAXTYPE, 0), 300)
  ) subs;

  PERFORM pkg_saft_PUT_INFO('00.E23','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  --Facturi la avize 4426, 4427
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  )
  SELECT
    NEXTVAL('SEQ_SAFT_TI'),
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  FROM (
    SELECT
      DOC.TIPDOC, DOC.CODDOC, DOC.CODCONT,
      To_Char(TT.COD, 'fm999000') TAXTYPE, To_Char(Coalesce(TD.TaxCode, 0), 'fm999000000') TAXCODE, NULL::NUMERIC TAXPERCENTAGE, 0 TAXBASE, 0 TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL::NUMERIC CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD
    FROM (
      SELECT J.TIPDOC, J.CODDOC, C.CODCONT, C.TAXTYPE
      FROM TMP_SAFT_JURNAL J INNER JOIN NCONT C ON C.CODCONT = J.CONTD
      WHERE J.TIPDOC IN (9, 26)
        AND J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
        AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
        AND c.codsaft IN ('4426', '4427')
      UNION
      SELECT J.TIPDOC, J.CODDOC, C.CODCONT, C.TAXTYPE
      FROM TMP_SAFT_JURNAL J INNER JOIN NCONT C ON C.CODCONT = J.CONTC
      WHERE J.TIPDOC IN (9, 26)
        AND J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
        AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
        AND c.codsaft IN ('4426', '4427')
    ) DOC
      LEFT  JOIN taxdecl               td ON td.tipdoc = doc.tipdoc AND td.coddoc = doc.coddoc
      LEFT  JOIN WINMADMIN.TaxTypeSaft tt ON tt.cod    = COALESCE(NULLIF(DOC.TAXTYPE, 0), 300)
  ) subs;
  PERFORM pkg_saft_PUT_INFO('00.E90','BEGIN_SAFT--TMP_SAFT_TAXINFO_MP');
  INSERT INTO TMP_SAFT_TAXINFO_MP (
    CODTI, IDXLOCAL, CODCONT,
    TAXBASE,
    TAXVAL)
  SELECT
    codti, Row_Number() OVER (PARTITION BY codti ORDER BY mp_valoare) IdxLocal, cont,
    Round(taxbase*mp_valoare/Sum(mp_valoare) OVER (PARTITION BY codti),2) mp_taxbase,
    Round(taxval *mp_valoare/Sum(mp_valoare) OVER (PARTITION BY codti),2) mp_taxval
  FROM (
    SELECT
      ti.codti, iob1.cont, ti.taxbase, ti.taxval,
      Sum(mp.valoare) mp_valoare
    FROM tmp_saft_taxinfo ti
      INNER JOIN moduriplati mp   ON mp.codies = ti.coddoc
      INNER JOIN iesiri      i    ON i.codies  = mp.codies
      INNER JOIN nbankcont1  bc1  ON bc1.codbankcont = mp.codbankcont AND i.an*12+i.luna BETWEEN bc1.ALStart  AND bc1.ALSTOP
      INNER JOIN iobank1     iob1 ON iob1.codiobank = bc1.codiobanca  AND i.an*12+i.luna BETWEEN iob1.ALStart AND iob1.ALSTOP
    WHERE ti.tipdoc = 16 AND Coalesce(mp.valoare, 0) &lt;&gt; 0
    GROUP BY ti.codti, iob1.cont, ti.taxbase, ti.taxval
  ) ss1;

  PERFORM pkg_saft_PUT_INFO('00.F06','BEGIN_SAFT--TMP_SAFT_CODSAF');
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 06, CODPART, NEXTVAL('SEQ_SAFT')
  FROM (
    SELECT DISTINCT CODPART
    FROM TMP_SAFT_NPARTDET /*TMP_SAFT_NPART*/
    ORDER BY 1
  ) subs;

  PERFORM pkg_saft_PUT_INFO('00.F07','BEGIN_SAFT--TMP_SAFT_CODSAF');
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 07, CODAGENDA, NEXTVAL('SEQ_SAFT')
  FROM (
    SELECT DISTINCT CODAGENDA
    FROM TMP_SAFT_NPARTDET /*TMP_SAFT_NPART*/ TP INNER JOIN NAGENDA A ON A.CODPART = TP.CODPART AND A.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(A.INACTIV, 0) = 0
    ORDER BY 1
  ) subs;

  IF bPartContact THEN
    PERFORM pkg_saft_PUT_INFO('00.F08','BEGIN_SAFT--TMP_SAFT_CODSAF');
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
    SELECT 08, CODSURSA, NEXTVAL('SEQ_SAFT')
    FROM (
      SELECT CODSURSA
      FROM TMP_SAFT_CODSAF C06
      WHERE C06.CodSAFTTab = 06 AND EXISTS (SELECT 1 FROM NPERSCONTACT PC WHERE PC.CodPart = C06.CODSURSA)
      ORDER BY 1
    ) subs;

    PERFORM pkg_saft_PUT_INFO('00.F09','BEGIN_SAFT--TMP_SAFT_CODSAF');
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
    SELECT 09, CODPERSC, NEXTVAL('SEQ_SAFT')
    FROM (
      SELECT DISTINCT PC.CODPERSC
      FROM TMP_SAFT_CODSAF C08 LEFT JOIN NPERSCONTACT PC ON PC.CodPart = C08.CODSURSA
      WHERE C08.CodSAFTTab = 08
      ORDER BY 1
    ) subs;
  END IF;
  PERFORM pkg_saft_PUT_INFO('00.F10','BEGIN_SAFT--TMP_SAFT_CODSAF');
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 10, COD_CODFISCAL, NEXTVAL('SEQ_SAFT')
  FROM (
    SELECT DISTINCT PCF.COD_CODFISCAL
    FROM TMP_SAFT_CODSAF C06 INNER JOIN TMP_SAFT_NPARTDET PCF ON PCF.CODPART = C06.CODSURSA
    WHERE C06.CodSAFTTab = 06 AND PCF.CODFISCAL IS NOT NULL
    ORDER BY 1
  ) subs;

  IF bPartBanca THEN
    PERFORM pkg_saft_PUT_INFO('00.F11','BEGIN_SAFT--TMP_SAFT_CODSAF');
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
    SELECT 11, CODPARTB, NEXTVAL('SEQ_SAFT')
    FROM (
      SELECT DISTINCT Coalesce(PB.CODPARTB, 0) CODPARTB
      FROM TMP_SAFT_CODSAF C06 LEFT JOIN NPARTB PB ON PB.CODPART = C06.CODSURSA AND PB.IMPLICIT = 1
      WHERE C06.CodSAFTTab = 06
      ORDER BY 1
    ) subs;
  END IF;

  PERFORM pkg_saft_PUT_INFO('00.F14','BEGIN_SAFT--TMP_SAFT_CODSAF');
  cSQL := 'INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 14, codumsaft, NEXTVAL(''SEQ_SAFT'')
  FROM (
    SELECT DISTINCT ums.codumsaft
    FROM iesiri i
      INNER JOIN iesiri1           i1  ON i1.codies    = i.codies
      INNER JOIN num1              u1  ON u1.codum1     = i1.umsec
      INNER JOIN num               u   ON u.codum       = u1.codum
      INNER JOIN winmadmin.numsaft ums ON ums.codumsaft = u.codumsaft
    WHERE I.AN*12+i.LUNA BETWEEN '||To_Char(v_ALIni, 'fm99990')||' AND '||To_Char(v_ALFin, 'fm99990')||'
      AND I.OPERAT = 1 AND I.ANULAT = 0 AND Coalesce(u.codumsaft,0) &lt;&gt; 0'||
      CASE WHEN pSubunit = 1 THEN '' ELSE ' AND I.SUBUNITATEA = '||To_Char(pSubunit) END ||
      CASE WHEN pTip    &lt;&gt; 4 THEN '' ELSE ' AND i1.tiplinie = ''='''                 END ||'
    UNION
    SELECT DISTINCT ums.codumsaft
    FROM intrari i
      INNER JOIN intrari1          i1  ON i1.codintr    = i.codintr
      INNER JOIN num1              u1  ON u1.codum1     = i1.umsec
      INNER JOIN num               u   ON u.codum       = u1.codum
      INNER JOIN winmadmin.numsaft ums ON ums.codumsaft = u.codumsaft
    WHERE I.AN*12+i.LUNA BETWEEN '||To_Char(v_ALIni, 'fm99990')||' AND '||To_Char(v_ALFin, 'fm99990')||'
      AND I.OPERAT = 1 AND I.ANULAT = 0 AND Coalesce(u.codumsaft,0) &lt;&gt; 0'||
      CASE WHEN pSubunit = 1 THEN '' ELSE ' AND I.SUBUNITATEA = '||To_Char(pSubunit) END ||
      CASE WHEN pTip    &lt;&gt; 4 THEN '' ELSE ' AND i1.tiplinie = ''='''                 END ||'
    ORDER BY 1
  ) subs';
  EXECUTE cSQL;
  PERFORM pkg_saft_PUT_INFO('00.F17','BEGIN_SAFT--TMP_SAFT_CODSAF');
  cSQL := 'INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 17, O.CODOBIECT, NEXTVAL(''SEQ_SAFT'')
  FROM (
    SELECT DISTINCT I1.CODOBIECT
    FROM iesiri i INNER JOIN iesiri1 i1 ON i1.codies = i.codies
    WHERE I.AN*12+i.LUNA BETWEEN '||To_Char(v_ALIni, 'fm99990')||' AND '||To_Char(v_ALFin, 'fm99990')||'
      AND I.OPERAT = 1 AND I.ANULAT = 0 AND Coalesce(I1.CODOBIECT,0) &lt;&gt; 0'||
      CASE WHEN pSubunit = 1 THEN '' ELSE ' AND I.SUBUNITATEA = '||To_Char(pSubunit) END ||
      CASE WHEN pTip    &lt;&gt; 4 THEN '' ELSE ' AND i1.tiplinie = ''='''                 END ||'
    UNION
    SELECT DISTINCT I1.CODOBIECT
    FROM intrari i INNER JOIN intrari1 i1 ON i1.codintr = i.codintr
    WHERE I.AN*12+i.LUNA BETWEEN '||To_Char(v_ALIni, 'fm99990')||' AND '||To_Char(v_ALFin, 'fm99990')||'
      AND I.OPERAT = 1 AND I.ANULAT = 0 AND Coalesce(I1.CODOBIECT,0) &lt;&gt; 0'||
      CASE WHEN pSubunit = 1 THEN '' ELSE ' AND I.SUBUNITATEA = '||To_Char(pSubunit) END ||
      CASE WHEN pTip    &lt;&gt; 4 THEN '' ELSE ' AND i1.tiplinie = ''='''                 END ||'
    ORDER BY 1
  ) subs
    INNER JOIN nartobj o ON o.codobiect = subs.codobiect
  WHERE Coalesce(o.saft_export, 1) = 1 ';
  EXECUTE cSQL; -- pus sql dinamic deaorece am gasit gasit cazuri in care o lua pe aratura si nu inteleg de ce
  IF pTip = 4 THEN -- La Cerere - include stocuri
    PERFORM pkg_saft_PUT_INFO('00.F20','BEGIN_SAFT--TMP_SAFT_TAXINFO');
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
    SELECT 20, t.codobiect, NEXTVAL('SEQ_SAFT')
    FROM (
      SELECT o.codobiect
      FROM (
        SELECT DISTINCT codobiect
        FROM nirstoc ns INNER JOIN nirluna nl ON nl.codnirstoc = ns.codnirstoc
        WHERE nl.an = vAnFin AND nl.luna = vLunaFin AND Coalesce(nl.rest, 0) &lt;&gt; 0
      ) t
        INNER JOIN nartobj o ON o.codobiect = t.codobiect
        INNER JOIN nart    a ON a.codarticol = o.codarticol
      WHERE a.tipstoc IN (1, 2)
      UNION
      SELECT codobiect
      FROM stocfake
      WHERE an = vAnFin AND luna = vLunaFin
    ) T;

    PERFORM pkg_saft_PUT_INFO('00.F53','BEGIN_SAFT--TMP_SAFT_STOCKMOVEMENT');
    INSERT INTO TMP_SAFT_STOCKMOVEMENT(CODSAF, TIPDOC, CODDOC, CODPARINTE, TAB, MOVEMENTTYPE, DATADOC, CODPART)
    SELECT NEXTVAL('SEQ_SAFT'), i.tipdoc, n.codnir, i.codintr, 'N', '10', n.datanir, p.codpartfuz
    FROM intrari i
      INNER JOIN nir               n ON n.codintr = i.codintr AND n.tipnir = i.tipdoc
      LEFT  JOIN tmp_saft_npartfuz p ON p.codpart = i.partener
    WHERE i.an = vAnFin AND i.luna = vLunaFin AND i.operat = 1 AND i.anulat = 0;

    INSERT INTO TMP_SAFT_STOCKMOVEMENT(CODSAF, TIPDOC, CODDOC, CODPARINTE, TAB, MOVEMENTTYPE, DATADOC, CODPART)
    SELECT NEXTVAL('SEQ_SAFT'), i.tipdoc, n.codnir, i.codies, 'N', '30', n.datanir, p.codpartfuz
    FROM iesiri i
      INNER JOIN nir               n ON n.codies = i.codies AND n.tipnir = i.tipdoc
      LEFT  JOIN tmp_saft_npartfuz p ON p.codpart = i.partener
    WHERE i.an = vAnFin AND i.luna = vLunaFin AND i.operat = 1 AND i.anulat = 0;
    INSERT INTO TMP_SAFT_STOCKMOVEMENT(CODSAF, TIPDOC, CODDOC, CODPARINTE, TAB, MOVEMENTTYPE, DATADOC, CODPART)
    SELECT NEXTVAL('SEQ_SAFT'), i.tipdoc, l.codlivr, i.codies, 'L', '40', l.datalivr, p.codpartfuz
    FROM iesiri i
      INNER JOIN livr              l ON l.codies = i.codies AND l.tiplivr = i.tipdoc
      LEFT  JOIN tmp_saft_npartfuz p ON p.codpart = i.partener
    WHERE i.an = vAnFin AND i.luna = vLunaFin AND i.operat = 1 AND i.anulat = 0;

    INSERT INTO TMP_SAFT_STOCKMOVEMENT(CODSAF, TIPDOC, CODDOC, CODPARINTE, TAB, MOVEMENTTYPE, DATADOC, CODPART)
    SELECT NEXTVAL('SEQ_SAFT'), i.tipdoc, l.codlivr, i.codintr, 'L', '50', l.datalivr, p.codpartfuz
    FROM intrari i
      INNER JOIN livr              l ON l.codintr = i.codintr AND l.tiplivr = i.tipdoc
      LEFT  JOIN tmp_saft_npartfuz p ON p.codpart = i.partener
    WHERE i.an = vAnFin AND i.luna = vLunaFin AND i.operat = 1 AND i.anulat = 0;

    INSERT INTO TMP_SAFT_STOCKMOVEMENT(CODSAF, TIPDOC, CODDOC, CODPARINTE, TAB, MOVEMENTTYPE, DATADOC, CODPART)
    SELECT NEXTVAL('SEQ_SAFT'), t.tipdoc, n.codnir, t.codtransf, 'N', '80', n.datanir, 0
    FROM transf t
      INNER JOIN nir               n ON n.codtransf = t.codtransf AND n.tipnir = t.tipdoc
    WHERE t.an = vAnFin AND t.luna = vLunaFin AND t.operat = 1 AND t.anulat = 0;

    INSERT INTO TMP_SAFT_STOCKMOVEMENT(CODSAF, TIPDOC, CODDOC, CODPARINTE, TAB, MOVEMENTTYPE, DATADOC, CODPART)
    SELECT NEXTVAL('SEQ_SAFT'), t.tipdoc, l.codlivr, t.codtransf, 'L', '80', l.datalivr, 0
    FROM transf t
      INNER JOIN livr              l ON l.codtransf = t.codtransf AND l.tiplivr = t.tipdoc
    WHERE t.an = vAnFin AND t.luna = vLunaFin AND t.operat = 1 AND t.anulat = 0;
    UPDATE TMP_SAFT_STOCKMOVEMENT T
    SET MOVEMENTTYPE =
        CASE
          WHEN TAB = 'N' AND TIPDOC IN (1,2,3,4,5,6)               THEN  '10' --Achizitie
          WHEN TAB = 'N' AND TIPDOC IN (7, 24)                     THEN  '20' --Productie
          WHEN TAB = 'L' AND TIPDOC IN (19,20,21,23)               THEN  '30' --Vânzare
          WHEN TAB = 'N' AND TIPDOC IN (19,20,21,23)               THEN  '40' --Retur produse vândute
          WHEN TAB = 'L' AND TIPDOC IN (1,2,3,4,5,6,7)             THEN  '50' --Retur produse achizitionate
          --WHEN                                                   THEN  '60' --Reduceri comerciale primite
          WHEN TAB = 'L' AND TIPDOC IN (7, 24)                     THEN  '70' --Consum
          WHEN TIPDOC = 12                                         THEN  '80' --Transfer intern
          --WHEN                                                   THEN  '90' --Cheltuieli ulterioare incluse în valoarea de intrare
          WHEN TIPDOC = 13                                         THEN '100' --Diferente de pret
          WHEN TIPDOC = 15                                         THEN '110' --Plus de inventar
          WHEN TIPDOC = 14                                         THEN '120' --Minus de inventar
          --WHEN                                                   THEN '130' --Ajustari pentru deprecierea stocurilor
          --WHEN                                                   THEN '140' --Reluari de ajustari pentru deprecierea stocurilor
          --WHEN                                                   THEN '150' --Bunuri acordate cu titlu gratuit
          --WHEN                                                   THEN '160' --Bunuri degradate
          --WHEN                                                   THEN '170' --Bunuri expirate
          ELSE                                                          '180' --Alte tranzactii
        END;

    UPDATE TMP_SAFT_STOCKMOVEMENT T
    SET (LINES_COUNT, LINES_SUM) = (SELECT Count(1), Sum(Cant) FROM LIVR1 L1 WHERE L1.CODLIVR = T.CODDOC)
    WHERE T.TAB = 'L';

    UPDATE TMP_SAFT_STOCKMOVEMENT T
    SET (LINES_COUNT, LINES_SUM) = (SELECT Count(1), Sum(CantNir) FROM NIRSTOC NS WHERE NS.CODNIR = T.CODDOC)
    WHERE T.TAB = 'N';
  END IF;

  IF pTip = 7 THEN -- Anuala - Active
    PERFORM pkg_saft_PUT_INFO('00.F22','BEGIN_SAFT--TMP_SAFT_CODSAF');
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF, CODAUX)
    SELECT 22, CODMIFIX, NEXTVAL('SEQ_SAFT'), CODMIFIX1
    FROM (
      SELECT CODMIFIX, CODMIFIX1
      FROM (
        SELECT CODMIFIX, CODMIFIX1, Row_Number() OVER (PARTITION BY CODMIFIX ORDER BY AN ASC, LUNA ASC) CODMIFIX_IDX_A
        FROM TMP_SAFT_MIFIX1 m1
      ) ssa
      WHERE ssa.CODMIFIX_IDX_A = 1
      ORDER BY CODMIFIX
    ) ssb;
--    PERFORM pkg_saft_PUT_INFO('00.F23','BEGIN_SAFT--TMP_SAFT_CODSAF');
--    campul AssetSupplier este optional si nu trebuie sa se exporte datele (macar pt moment pt a scapa de erori
--    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
--    SELECT 23, CODFURN, NEXTVAL('SEQ_SAFT')
--    FROM (
--      SELECT DISTINCT Coalesce(NS.FURN, 0) CODFURN
--      FROM TMP_SAFT_CODSAF C22
--        INNER JOIN mifix1 m1 ON m1.codmifix1 = C22.CODAUX
--        INNER JOIN nirstoc ns ON ns.codnirstoc = m1.codnirstoc
--      WHERE c22.codsafttab = 22
--      ORDER BY 1
--    ) ssa;

    PERFORM pkg_saft_PUT_INFO('00.F59','BEGIN_SAFT--TMP_SAFT_CODSAF');
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF, CODPARINTE, CODAUX)
    SELECT 59, CODSURSA, NEXTVAL('SEQ_SAFT') AS CODSAF, CODSAF AS CODPARINTE, CODAUX
    FROM TMP_SAFT_CODSAF
    WHERE codsafttab = 22;

    PERFORM pkg_saft_PUT_INFO('00.F24','BEGIN_SAFT--TMP_SAFT_CODSAF');
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF, CODPARINTE, CODAUX)
    SELECT 24, CODMIFIX1_FIN, NEXTVAL('SEQ_SAFT'), CODSAF, CODMIFIX1_INI
    FROM (
      SELECT
        CODSAF,
        Max(CASE WHEN CODMIFIX_IDX_A = 1 THEN CODMIFIX1 ELSE 0 END) CODMIFIX1_INI,
        Max(CASE WHEN CODMIFIX_IDX_D = 1 THEN CODMIFIX1 ELSE 0 END) CODMIFIX1_FIN
      FROM (
        SELECT
          C59.CODSAF, xJ1.ALSTART, M1.CODMIFIX1,
          Row_Number() OVER (PARTITION BY M1.CODMIFIX, xJ1.ALSTART ORDER BY M1.AL ASC ) CODMIFIX_IDX_A,
          Row_Number() OVER (PARTITION BY M1.CODMIFIX, xJ1.ALSTART ORDER BY M1.AL DESC) CODMIFIX_IDX_D
        FROM TMP_SAFT_CODSAF C59
          INNER JOIN (
            SELECT CODMIFIX1, CODMIFIX, AN*12+LUNA AL
            FROM TMP_SAFT_MIFIX1
          ) M1 ON M1.CODMIFIX = C59.CODSURSA
          LEFT JOIN (
            SELECT CODMIFIX, ALSTART, ALSTOP
            FROM (
              SELECT CODMIFIX, Min(AL) ALSTART, Max(AL) ALSTOP
              FROM (
                SELECT
                  TM1.CODMIFIX, M1.CODCLASIF, NS.CODIOART,
                  ROW_NUMBER () OVER (PARTITION BY TM1.CODMIFIX                            ORDER BY TM1.AN, TM1.LUNA) -
                  ROW_NUMBER () OVER (PARTITION BY TM1.CODMIFIX, M1.CODCLASIF, NS.CODIOART ORDER BY TM1.AN, TM1.LUNA) Grup,
                  TM1.AN*12+TM1.LUNA AL
                FROM TMP_SAFT_MIFIX1 TM1
                  INNER JOIN MIFIX1  M1 ON M1.CODMIFIX1  = TM1.CODMIFIX1
                  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = M1.CODNIRSTOC
                  INNER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR
              ) aJ1
              GROUP BY aJ1.CODMIFIX, aJ1.CODCLASIF, aJ1.CODIOART, aJ1.Grup
            ) bJ1
          ) xJ1 ON xJ1.CODMIFIX = M1.CODMIFIX AND M1.AL BETWEEN xJ1.ALSTART AND xJ1.ALSTOP
        WHERE c59.codsafttab = 59
      ) ssa
      GROUP BY CODSAF, ALSTART
      ORDER BY CODSAF, ALSTART
    ) ssb ;
    PERFORM pkg_saft_PUT_INFO('00.F60','BEGIN_SAFT--TMP_SAFT_CODSAF');
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSAF, CODPARINTE, CODAUX)
    SELECT 60, NEXTVAL('SEQ_SAFT') AS CODSAF, CODSAF AS CODPARINTE, CODSURSA
    FROM TMP_SAFT_CODSAF
    WHERE codsafttab = 24;
    PERFORM pkg_saft_PUT_INFO('00.F25','BEGIN_SAFT--TMP_SAFT_CODSAF');
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSAF, CODPARINTE, CODAUX)
    SELECT 25, NEXTVAL('SEQ_SAFT') AS CODSAF, CODSAF AS CODPARINTE, CODSURSA
    FROM TMP_SAFT_CODSAF
    WHERE codsafttab = 60;
--    PERFORM pkg_saft_PUT_INFO('00.F56','BEGIN_SAFT--TMP_SAFT_CODSAF');
--    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF, CODPARINTE, CODAUX)
--    SELECT 56, CODSURSA, NEXTVAL('SEQ_SAFT') AS CODSAF, CODSAF AS CODPARINTE, CODAUX
--    FROM TMP_SAFT_CODSAF
--    WHERE codsafttab = 22;

    PERFORM pkg_saft_PUT_INFO('00.F57','BEGIN_SAFT--TMP_SAFT_CODSAF');
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF, CODPARINTE, CODAUX)
    SELECT 57, T.CODJURNAL1, NEXTVAL('SEQ_SAFT') AS CODSAF, T.CODPARINTE, T.CODMIFIX1
    FROM (
      SELECT DISTINCT J1.CODJURNAL1, C22.CODSAF AS CODPARINTE, M1.CODMIFIX1
      FROM         TMP_SAFT_JURNAL1 J1
        INNER JOIN TMP_SAFT_MIFIX1  M1  ON M1.CODMIFIX1 = J1.CODMIFIX1
        INNER JOIN TMP_SAFT_CODSAF  C22 ON C22.CODSURSA = M1.CODMIFIX AND C22.CODSAFTTAB = 22
    ) T;
    PERFORM pkg_saft_PUT_INFO('00.F61','BEGIN_SAFT--TMP_SAFT_CODSAF');
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF, CODPARINTE, CODAUX)
    SELECT 61, CODSURSA, NEXTVAL('SEQ_SAFT') AS CODSAF, CODSAF AS CODPARINTE, CODAUX
    FROM TMP_SAFT_CODSAF
    WHERE codsafttab = 57;

    PERFORM pkg_saft_PUT_INFO('00.F58','BEGIN_SAFT--TMP_SAFT_CODSAF');
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF, CODPARINTE, CODAUX)
    SELECT 58, CODSURSA, NEXTVAL('SEQ_SAFT') AS CODSAF, CODSAF AS CODPARINTE, CODAUX
    FROM TMP_SAFT_CODSAF C61
    WHERE c61.codsafttab = 61;
  END IF;

  PERFORM pkg_saft_PUT_INFO('00.F26','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 26, 0, NEXTVAL('SEQ_SAFT');

  PERFORM pkg_saft_PUT_INFO('00.F27','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 27, CODJURNAL, NEXTVAL('SEQ_SAFT')
  FROM (
    SELECT J.CODJURNAL
    FROM TMP_SAFT_JURNAL J
      INNER JOIN NCONT CD ON CD.CODCONT = J.CONTD
      INNER JOIN NCONT CC ON CC.CODCONT = J.CONTC
    WHERE J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
      AND NOT(CD.CLASA IN (8,9) AND CC.CLASA IN (8,9))
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
    ORDER BY 1
  ) subs;

  PERFORM pkg_saft_PUT_INFO('00.F28','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 28, CODJURNAL, NEXTVAL('SEQ_SAFT')
  FROM (
    SELECT CODJURNAL
    FROM TMP_SAFT_JURNAL J
    WHERE J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
    ORDER BY 1
  ) subs;

  PERFORM pkg_saft_PUT_INFO('00.F3101','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 3101, CODSURSA, NEXTVAL('SEQ_SAFT') -- 31 ContD
  FROM (
    SELECT C28.CODSURSA
    FROM TMP_SAFT_CODSAF C28
    WHERE C28.CodSAFTTab = 28
    ORDER BY 1
  ) subs;

  PERFORM pkg_saft_PUT_INFO('00.F3102','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 3102, CODSURSA, NEXTVAL('SEQ_SAFT') -- 31 ContC
  FROM (
    SELECT C28.CODSURSA
    FROM TMP_SAFT_CODSAF C28
    WHERE C28.CodSAFTTab = 28
    ORDER BY 1
  ) subs;

  PERFORM pkg_saft_PUT_INFO('00.F3103','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF, CODPARINTE, CODAUX, IDXAUX)
  SELECT 3103, CODSURSA, NEXTVAL('SEQ_SAFT') AS CODSAF, CODPARINTE, CODAUX, IDXAUX -- 31 TVA
  FROM (
    SELECT C31.CODSURSA, C31.CODSAF AS CODPARINTE, TI.CODTI AS CODAUX, TIM.IDXLOCAL AS IDXAUX
    FROM TMP_SAFT_CODSAF C31
      INNER JOIN TMP_SAFT_JURNAL     J   ON J.CODJURNAL = C31.CODSURSA
      INNER JOIN TMP_SAFT_TAXINFO    TI  ON TI.TIPDOC   = J.TIPDOC AND TI.CODCONT = J.CONTD AND TI.CODDOC = CASE WHEN J.TIPDOC IN (29, 30, 31) THEN J.INDEXLOCAL ELSE J.CODDOC END
      LEFT  JOIN TMP_SAFT_TAXINFO_MP TIM ON TIM.CODTI   = TI.CODTI
      LEFT  JOIN TAXDECL             TD  ON TD.TIPDOC   = J.TIPDOC AND TD.CODCONT = J.CONTC AND TD.CODDOC = J.CODDOC
                                        AND TD.TIPDOC IN (28, 35)  AND TD.CHEIA = '&lt;D'||Trim(To_Char(J.CONTD))||'D&gt;&lt;C'||Trim(To_Char(J.CONTC))||'C&gt;&lt;V'||REPLACE(Trim(To_Char(J.VALOARE)),',','.')||'V&gt;'
    WHERE C31.CodSAFTTab = 3101
      AND CASE WHEN J.TIPDOC IN (28, 35) THEN TD.CODDOC ELSE TI.CODDOC END IS NOT NULL
    ORDER BY 1,2
  ) subs;

  PERFORM pkg_saft_PUT_INFO('00.F3104','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF, CODPARINTE, CODAUX, IDXAUX)
  SELECT 3104, CODSURSA, NEXTVAL('SEQ_SAFT') AS CODSAF, CODPARINTE, CODAUX, IDXAUX -- 31 TVA
  FROM (
    SELECT C31.CODSURSA, C31.CODSAF AS CODPARINTE, TI.CODTI AS CODAUX, TIM.IDXLOCAL AS IDXAUX
    FROM TMP_SAFT_CODSAF C31
      INNER JOIN TMP_SAFT_JURNAL     J   ON J.CODJURNAL = C31.CODSURSA
      INNER JOIN TMP_SAFT_TAXINFO    TI  ON TI.TIPDOC   = J.TIPDOC AND TI.CODCONT = J.CONTC AND TI.CODDOC = CASE WHEN J.TIPDOC IN (29, 30, 31) THEN J.INDEXLOCAL ELSE J.CODDOC END
      LEFT  JOIN TMP_SAFT_TAXINFO_MP TIM ON TIM.CODTI   = TI.CODTI
      LEFT  JOIN TAXDECL             TD  ON TD.TIPDOC   = J.TIPDOC AND TD.CODCONT = J.CONTD AND TD.CODDOC = J.CODDOC
                                        AND TD.TIPDOC IN (28, 35)  AND TD.CHEIA = '&lt;D'||Trim(To_Char(J.CONTD))||'D&gt;&lt;C'||Trim(To_Char(J.CONTC))||'C&gt;&lt;V'||REPLACE(Trim(To_Char(J.VALOARE)),',','.')||'V&gt;'
    WHERE C31.CodSAFTTab = 3102
      AND CASE WHEN J.TIPDOC IN (28, 35) THEN TD.CODDOC ELSE TI.CODDOC END IS NOT NULL
    ORDER BY 1,2
  ) subs;

  PERFORM pkg_saft_PUT_INFO('00.G12','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 12, To_Number(TaxType, '999999990'), NEXTVAL('SEQ_SAFT')
  FROM (
    SELECT DISTINCT TaxType
    FROM TMP_SAFT_TAXINFO
    ORDER BY 1
  ) subs;
  PERFORM pkg_saft_PUT_INFO('00.G13','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF, CODPARINTE)
  SELECT 13, To_Number(TaxCode, '999999990'), NEXTVAL('SEQ_SAFT'), C12.CODSAF
  FROM (
    SELECT DISTINCT TaxType, TaxCode
    FROM TMP_SAFT_TAXINFO
    ORDER BY 1, 2
  )  subs LEFT JOIN TMP_SAFT_CODSAF C12 ON C12.CodSAFTTab = 12 AND C12.CODSURSA = To_Number(subs.TaxType, '999999990');

  PERFORM pkg_saft_PUT_INFO('00.H1','BEGIN_SAFT--TMP_SAFT_TAXINFO');
  perform pkg_saft_UMPLE_MANEVRA_CONT_FROM_CONST('SAFTPartConturi', vLunaFin,vLunaFin);

  INSERT INTO TMP_SAFT_NCONT (
    CODCONT, SIMBOL, CODSAFT, CLASA, DEN_CONT, TIPCONT, NIVEL, NO_SOLDPART, VALID,
    FRUNZA
  )
  WITH recursive cRec (CODCONT, CLASA, SIMBOL, DEN_CONT, TIPCONT, CODPARINTE, CODSINTETIC, CODSAFT, LVL, NO_SOLDPART) AS (
    SELECT
      C.CODCONT, C.CLASA, C.SIMBOL, C.DEN_CONT, C.TIPCONT, C.CODPARINTE, C.CODCONT CODSINTETIC, C.CODSAFT, 0 AS LVL,
      CASE WHEN M.CODUNIC IS NOT NULL THEN 1 ELSE 0 END NO_SOLDPART
    FROM NCONT C
      INNER JOIN NCONT1       C1 ON C.CODCONT = C1.CODCONT AND v_ALFin BETWEEN C1.ALSTART AND C1.ALSTOP
      LEFT  JOIN (SELECT DISTINCT CODUNIC FROM TMP_SAFT_MANEVRA WHERE FILTRU = 'SAFTPartConturi') M ON M.CODUNIC = C.CODCONT
    WHERE Coalesce(c.codparinte, 0) = 0
      AND NOT (C.CODCONT = 0 OR C.SIMBOL  = '999' OR C.CLASA = 9)
      AND NOT EXISTS (SELECT 1 FROM NCONTECHIV CE WHERE CE.CONTVECHI = C.CODCONT AND (CE.AN * 12 + CE.LUNA) &lt;= v_ALFin )
      AND NOT Coalesce(NULLIF(C.AnInactiv*12+C.LunaInactiv, 0), v_ALIni) &lt; v_ALIni
    UNION ALL
    SELECT
      C.CODCONT, C.CLASA, C.SIMBOL, C.DEN_CONT, C.TIPCONT, C.CODPARINTE, CR.CODSINTETIC, Coalesce(C.CODSAFT, CR.CODSAFT), CR.LVL + 1 AS LVL,
      CASE WHEN M.CODUNIC IS NOT NULL THEN 1 ELSE cr.NO_SOLDPART END NO_SOLDPART
    FROM NCONT C
      INNER JOIN NCONT1       C1 ON C.CODCONT = C1.CODCONT AND v_ALFin BETWEEN C1.ALSTART AND C1.ALSTOP
      INNER JOIN cRec         cr ON cr.codcont = C.codparinte
      LEFT  JOIN (SELECT DISTINCT CODUNIC FROM TMP_SAFT_MANEVRA WHERE FILTRU = 'SAFTPartConturi') M ON M.CODUNIC = C.CODCONT
    WHERE NOT EXISTS (SELECT 1 FROM NCONTECHIV CE WHERE CE.CONTVECHI = C.CODCONT AND (CE.AN * 12 + CE.LUNA) &lt;= v_ALFin )
      AND NOT Coalesce(NULLIF(C.AnInactiv*12+C.LunaInactiv, 0), v_ALIni) &lt; v_ALIni
  )
  SELECT
    C.CODCONT, C.SIMBOL, C.CODSAFT, C.CLASA, C.DEN_CONT, Coalesce(C.TIPCONT,0), C.LVL, C.NO_SOLDPART, 0 AS VALID,
    CASE WHEN EXISTS(SELECT 1 FROM cRec xc WHERE xc.CODPARINTE = C.CODCONT) THEN 0 ELSE 1 END FRUNZA
  FROM cRec C;

  UPDATE TMP_SAFT_NCONT A SET VALID = 1 WHERE VALID = 0 AND EXISTS(SELECT 1 FROM TMP_SAFT_TAXINFO B WHERE B.CODCONT = A.CODCONT);
  UPDATE TMP_SAFT_NCONT A SET VALID = 1 WHERE VALID = 0 AND EXISTS(SELECT 1 FROM TMP_SAFT_MIFIX1  B WHERE B.CONT    = A.CODCONT);
  UPDATE TMP_SAFT_NCONT A SET VALID = 1 WHERE VALID = 0 AND EXISTS(SELECT 1 FROM TMP_SAFT_JURNAL  B WHERE B.CONTD   = A.CODCONT);
  UPDATE TMP_SAFT_NCONT A SET VALID = 1 WHERE VALID = 0 AND EXISTS(SELECT 1 FROM TMP_SAFT_JURNAL  B WHERE B.CONTC   = A.CODCONT);
  UPDATE TMP_SAFT_NCONT A SET VALID = 1 WHERE VALID = 0 AND EXISTS(SELECT 1 FROM NCONTSOLD        B WHERE B.CODCONT = A.CODCONT AND B.AN = vAnIni AND B.LUNA = 1        AND NOT (B.SOLDID  = 0 AND B.SOLDIC  = 0));
  UPDATE TMP_SAFT_NCONT A SET VALID = 1 WHERE VALID = 0 AND EXISTS(SELECT 1 FROM NCONTRUL         B WHERE B.CODCONT = A.CODCONT AND B.AN = vAnIni AND B.LUNA = vLunaIni AND NOT (B.RULAJPD = 0 AND B.RULAJPC = 0 AND B.RULAJCD = 0 AND B.RULAJCC = 0));
  UPDATE TMP_SAFT_NCONT A SET VALID = 1 WHERE VALID = 0 AND EXISTS(SELECT 1 FROM NCONTSOLD        B WHERE B.CODCONT = A.CODCONT AND B.AN = vAnFin AND B.LUNA = 1        AND NOT (B.SOLDID  = 0 AND B.SOLDIC  = 0));
  UPDATE TMP_SAFT_NCONT A SET VALID = 1 WHERE VALID = 0 AND EXISTS(SELECT 1 FROM NCONTRUL         B WHERE B.CODCONT = A.CODCONT AND B.AN = vAnFin AND B.LUNA = vLunaFin AND NOT (B.RULAJPD = 0 AND B.RULAJPC = 0 AND B.RULAJCD = 0 AND B.RULAJCC = 0));
  UPDATE TMP_SAFT_NCONT A SET VALID = 1 WHERE VALID = 0 AND EXISTS(SELECT 1 FROM TMP_SAFT_NPART   B WHERE B.CODCONT = A.CODCONT) AND NO_SOLDPART = 0;

  DELETE FROM TMP_SAFT_NCONT WHERE VALID = 0;

  IF pTip IN (   7) THEN
    PERFORM pkg_saft_PUT_INFO('00.H2','BEGIN_SAFT--TMP_SAFT_NCONT-active');
    DELETE FROM TMP_MANEVRA2;
    INSERT INTO TMP_MANEVRA2 SELECT DISTINCT CONT FROM TMP_SAFT_MIFIX1;
    DELETE FROM TMP_MANEVRA2 WHERE CODUNIC IN (SELECT CODCONT FROM TMP_SAFT_NCONT);
    SELECT Count(1) INTO vCount FROM TMP_MANEVRA2;

    IF vCount &gt; 0 THEN
      INSERT INTO TMP_SAFT_NCONT (
        CODCONT, SIMBOL, CODSAFT, CLASA, DEN_CONT, TIPCONT, NIVEL, NO_SOLDPART, VALID,
        FRUNZA
      )
      WITH recursive cRec (CODCONT, CLASA, SIMBOL, DEN_CONT, TIPCONT, CODPARINTE, CODSINTETIC, CODSAFT, LVL) AS (
        SELECT C.CODCONT, C.CLASA, C.SIMBOL, C.DEN_CONT, C.TIPCONT, C.CODPARINTE, C.CODCONT CODSINTETIC, C.CODSAFT, 0 AS LVL
        FROM NCONT C
          INNER JOIN NCONT1 C1 ON C.CODCONT = C1.CODCONT AND v_ALFin &gt;= C1.ALSTART AND v_ALIni &lt;=  C1.ALSTOP
        WHERE Coalesce(c.codparinte, 0) = 0
        UNION ALL
        SELECT C.CODCONT, C.CLASA, C.SIMBOL, C.DEN_CONT, C.TIPCONT, C.CODPARINTE, CR.CODSINTETIC, Coalesce(C.CODSAFT, CR.CODSAFT), CR.LVL + 1 AS LVL
        FROM NCONT C
          INNER JOIN NCONT1 C1 ON C.CODCONT = C1.CODCONT AND v_ALFin &gt;= C1.ALSTART AND v_ALIni &lt;=  C1.ALSTOP
          INNER JOIN cRec   cr ON cr.codcont = C.codparinte
      )
      SELECT
        C.CODCONT, C.SIMBOL, C.CODSAFT, C.CLASA, C.DEN_CONT, Coalesce(C.TIPCONT,0), C.LVL, 0 NO_SOLDPART, 1 AS VALID,
        CASE WHEN EXISTS(SELECT 1 FROM cRec xc WHERE xc.CODPARINTE = C.CODCONT) THEN 0 ELSE 1 END FRUNZA
      FROM TMP_MANEVRA2 T INNER JOIN cRec C ON C.CODCONT = T.CODUNIC;
    END IF;
  END IF;

  UPDATE TMP_SAFT_TAXINFO SET TAXBASE = Round(TAXBASE,2), TAXVAL = Round(TAXVAL,2);
  PERFORM pkg_saft_PUT_INFO('00.Z','BEGIN_SAFT--TMP_SAFT_TAXINFO');

                                   PERFORM PKG_SAFT_UMPLE_T01();         --SAF_HEADER
                                   PERFORM PKG_SAFT_UMPLE_T02();         --SAF_SELECTIONCRITERIA
  IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T03(); END IF; --SAF_ACCOUNT
  IF NOT pTip IN (4, 5, 6, 7) THEN PERFORM PKG_SAFT_UMPLE_T04(); END IF; --SAF_CUSTOMER
  IF NOT pTip IN (4, 5, 6, 7) THEN PERFORM PKG_SAFT_UMPLE_T05(); END IF; --SAF_SUPPLIER
                                   PERFORM PKG_SAFT_UMPLE_T06();         --SAF_COMPANYSTRUCTURE
                                   PERFORM PKG_SAFT_UMPLE_T07();         --SAF_ADDRESS
                                   PERFORM PKG_SAFT_UMPLE_T08();         --SAF_CONTACT
                                   PERFORM PKG_SAFT_UMPLE_T09();         --SAF_CONTACTPERSON
                                   PERFORM PKG_SAFT_UMPLE_T10();         --SAF_TAXREGISTRATION
                                   PERFORM PKG_SAFT_UMPLE_T11();         --SAF_BANKACCOUNT
  IF NOT pTip IN (         7) THEN PERFORM PKG_SAFT_UMPLE_T12(); END IF; --SAF_TAXTABLEENTRY
  IF NOT pTip IN (         7) THEN PERFORM PKG_SAFT_UMPLE_T13(); END IF; --SAF_TAXCODEDETAILS
  IF NOT pTip IN (         7) THEN PERFORM PKG_SAFT_UMPLE_T14(); END IF; --SAF_UOMTABLEENTRY
  IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T15(); END IF; --SAF_ANALYSISTYPETABLEENTRY
  IF     pTip IN (4         ) THEN PERFORM PKG_SAFT_UMPLE_T16(); END IF; --SAF_MOVEMENTTYPETABLEENTRY
  IF NOT pTip IN (         7) THEN PERFORM PKG_SAFT_UMPLE_T17(); END IF; --SAF_PRODUCT
  IF NOT pTip IN (   5, 6, 7) THEN PERFORM PKG_SAFT_UMPLE_T18(); END IF; --SAF_TAX
  IF     pTip IN (4         ) THEN PERFORM PKG_SAFT_UMPLE_T19(); END IF; --SAF_PHYSICALSTOCKENTRY
  IF     pTip IN (4         ) THEN PERFORM PKG_SAFT_UMPLE_T20(); END IF; --SAF_STOCKCHARACTERISTICS
--IF     pTip IN (4         ) THEN PERFORM PKG_SAFT_UMPLE_T21(); END IF; --SAF_OWNER
  IF     pTip IN (         7) THEN PERFORM PKG_SAFT_UMPLE_T22(); END IF; --SAF_ASSET
  IF     pTip IN (         7) THEN PERFORM PKG_SAFT_UMPLE_T23(); END IF; --SAF_ASSETSUPPLIER
  IF     pTip IN (         7) THEN PERFORM PKG_SAFT_UMPLE_T59(); END IF; --SAF_VALUATIONS
  IF     pTip IN (         7) THEN PERFORM PKG_SAFT_UMPLE_T24(); END IF; --SAF_VALUATION
  IF     pTip IN (         7) THEN PERFORM PKG_SAFT_UMPLE_T60(); END IF; --SAF_EXTRAORDINARYDEPRECIATIONSFORPERIOD
  IF     pTip IN (         7) THEN PERFORM PKG_SAFT_UMPLE_T25(); END IF; --SAF_EXTRAORDINARYDEPRECIATIONFORPERIOD
  IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T26(); END IF; --SAF_GENERALLEDGERENTRIES
  IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T27(); END IF; --SAF_JOURNAL
  IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T28(); END IF; --SAF_TRANSACTION
  IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T29(); END IF; --SAF_TRANSACTIONLINE
  IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T30(); END IF; --SAF_ANALYSIS
  IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T31(); END IF; --SAF_AMOUNT
  IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T32(); END IF; --SAF_TAXINFORMATION
  IF     pTip IN (4,       7) THEN PERFORM PKG_SAFT_UMPLE_T33(); END IF; --SAF_SALESINVOICES
--IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T34(); END IF; --SAF_INVOICE
--IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T35(); END IF; --SAF_CUSTOMERINFO
--IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T36(); END IF; --SAF_SUPPLIERINFO
--IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T37(); END IF; --SAF_SHIPPINGPOINT
--IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T38(); END IF; --SAF_INVOICELINE
--IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T39(); END IF; --SAF_ORDERREFERENCES
--IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T40(); END IF; --SAF_DELIVERY
--IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T41(); END IF; --SAF_DELIVERYPERIOD
--IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T42(); END IF; --SAF_REFERENCES
--IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T43(); END IF; --SAF_CREDITNOTE
--IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T44(); END IF; --SAF_INVOICESETTLEMENT
--IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T45(); END IF; --SAF_INVOICEDOCUMENTTOTALS
  IF     pTip IN (4,       7) THEN PERFORM PKG_SAFT_UMPLE_T46(); END IF; --SAF_PURCHASEINVOICES
  IF     pTip IN (4,       7) THEN PERFORM PKG_SAFT_UMPLE_T47(); END IF; --SAF_PAYMENTS
--IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T48(); END IF; --SAF_PAYMENT
--IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T49(); END IF; --SAF_PAYMENTLINE
--IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T50(); END IF; --SAF_PAYMENTSETTLEMENT
--IF NOT pTip IN (   5, 6   ) THEN PERFORM PKG_SAFT_UMPLE_T51(); END IF; --SAF_PAYMENTDOCUMENTTOTALS
  IF     pTip IN (4         ) THEN PERFORM PKG_SAFT_UMPLE_T52(); END IF; --SAF_MOVEMENTOFGOODS
  IF     pTip IN (4         ) THEN PERFORM PKG_SAFT_UMPLE_T53(); END IF; --SAF_STOCKMOVEMENT
  IF     pTip IN (4         ) THEN PERFORM PKG_SAFT_UMPLE_T54(); END IF; --SAF_DOCUMENTREFERENCE
  IF     pTip IN (4         ) THEN PERFORM PKG_SAFT_UMPLE_T55(); END IF; --SAF_STOCKMOVEMENTLINE
  IF     pTip IN (         7) THEN PERFORM PKG_SAFT_UMPLE_T56(); END IF; --SAF_ASSETTRANSACTIONS
  IF     pTip IN (         7) THEN PERFORM PKG_SAFT_UMPLE_T57(); END IF; --SAF_ASSETTRANSACTION
  IF     pTip IN (         7) THEN PERFORM PKG_SAFT_UMPLE_T61(); END IF; --SAF_ASSETTRANSACTIONVALUATIONS
  IF     pTip IN (         7) THEN PERFORM PKG_SAFT_UMPLE_T58(); END IF; --SAF_ASSETTRANSACTIONVALUATION
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_updatetaxdecl</obj_name>
  <obj_hashval>5e45526828602107a29d8918366bbece</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_updatetaxdecl(pcaz numeric, pcoddoc numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vRec             RECORD;
  XRec             RECORD;
  aCod             Numeric(20);
  aNeded           Numeric;
  cTaxCode         VARCHAR(30);
  aTax             Numeric(20);
  cTaxa            VARCHAR(30);
  cTd1             VARCHAR(20);
  cTd2             VARCHAR(20);
  cTx1             VARCHAR(40);
  cTx2             VARCHAR(20);
  cTxP             VARCHAR(20);
  crTd1            VARCHAR(40);
  crTx1            VARCHAR(20);
  Taxa2            VARCHAR(20);
  DoServCaStoc     BOOLEAN;
  bArt0            BOOLEAN;
  bArt1            BOOLEAN;
  bArt2            BOOLEAN;
  cCod1            VARCHAR(30);
  cCod2            VARCHAR(30);
  cCod3            VARCHAR(30);
  cCod4            VARCHAR(30);
  cCod5            VARCHAR(30);
  cCod6            VARCHAR(30);
  cCod7            VARCHAR(30);
  cCod8            VARCHAR(30);
  cKeia            VARCHAR(300);
  aCODINTR1        NUMERIC(20);
  SuplimTipDoc3    Numeric(20,7);
  aValLinie        Numeric(20,7);
  aTVALinie        Numeric(20,7);
  aTaxBase         NUMERIC(20,7);
  aTaxVal          NUMERIC(20,7);
  aVal             Numeric(20,7);
  aDisc            Numeric(20,7);
  aProcTVADoc      Numeric(20,7);
  aTotBase         Numeric(20,7);
  aTotVal          Numeric(20,7);
  KIncas           Numeric(20,7);
  BazaTVAMarja     Numeric(20,7);
  aContSaft        Numeric(20);
  aTipDoc          Numeric(20);
  aAnulat          Numeric(1);
  aOperat          Numeric(1);
  aManual          Numeric(1);
  aTipTranzactie   Numeric(2);
  aTipTVA          Numeric(2);
  aTipFactura      Numeric(5);
  ArtIncasUlterior Numeric(20);
  IOArtIncasImed   Numeric(20);
  TVA0FaraDed      Numeric(20);
  aAn              Numeric(10);
  aLuna            Numeric(3);
  aCoefIO          Numeric(2);
  Semn             NUMERIC;
  aSubunit         NUMERIC(20);
  aCursLinie       numeric(1);
  ContTrezor       numeric(20);
BEGIN
  --Florin 16.12.2025 - sinc. Oracle
  --Florin 31.10.2025 - fixat 67183
  --Florin 29.09.2025 - fixat 66777
  --Florin 23.09.2025 - sinc. Oracle
  --Florin 05.09.2025 - sinc. Oracle
  --Florin 04.09.2025 - sinc. Oracle
  --Florin 03.09.2025 - fixat 66554
  --Florin 13.08.2025 - fixat 66380
  --Stef   30.07.2025
  --Florin 04.02.2025 - fixat 64643
  --Florin 30.01.2025 - fixat 64594
  --Stef 29.01.2025 - sinc. Oracle
  PERFORM pkg_globals_SetSeparator(',');
  aCursLinie := Coalesce(fnc_GetValConstanta('ContabCursLinie' ,getANLUCRU(), getLUNALUCRU()),'2');
  SELECT TipDoc,  TipTranzactie,  TipTVA, Coalesce(TipFactura, 0), Coalesce(Anulat, 0), Coalesce(Operat, 1), Subunitatea
    INTO   aTipDoc, aTipTranzactie, aTipTVA, aTipFactura,            aAnulat,             aOperat,             aSubunit
    FROM Intrari
  WHERE CodIntr = pCodDoc;
  IF pCaz = 0 THEN
    SELECT TipDoc, TipTranzactie, TipTVA, Coalesce(TipFactura, 0), Coalesce(Anulat, 0), Coalesce(Operat, 1) INTO aTipDoc, aTipTranzactie, aTipTVA, aTipFactura, aAnulat, aOperat
    FROM Intrari
    WHERE CodIntr = pCodDoc;
    IF aAnulat = 1 OR aOperat = 0 or aTipFactura = 2 or (aTipTranzactie in (4,5) and aTipDoc &lt;&gt; 2 and aTipTVA = 1) THEN
      DELETE FROM TaxDecl WHERE TipDoc = aTipDoc AND CodDoc = pCodDoc;
    ELSE
      DELETE FROM TaxDecl WHERE TipDoc = aTipDoc AND CodDoc = pCodDoc AND MANUAL = 0;
    FOR vRec IN (
        WITH Intr (CodIntr, TipDoc, DataDoc, TVAIncasare, AnLuna, An, Luna, Curs, PlatitorTVA, Taxa1, TipTranzactie, TipTVA, Taxa2, TaxaI, Cheia1, Cheia2, RotEFact)
        AS (
          SELECT
            I.CodIntr, I.TipDoc, I.DataDoc, I.TVAIncasare, I.An*12+I.Luna AnLuna, I.An, I.Luna, Coalesce(NULLIF(I.Curs,0),1) Curs,
            CASE WHEN SubStr(PCF.CodFiscal,1,1) &gt;= Chr(65) THEN '1' ELSE '0' END PlatitorTVA,
            CASE
              WHEN T.SimbAuto = 'RO' THEN '2'
              WHEN Coalesce(T.STATCOMUNITAR,0) = 0 THEN '0'
              ELSE
                CASE WHEN SubStr(PCF.CodFiscal,1,1) &gt;= Chr(65)
                     THEN case
                            WHEN T.SimbAuto = SubStr(PCF.CodFiscal,1,2) then '1'
                            else '3'
                          end
                     ELSE '1'
                END
            END ||'.'||To_Char(TipTranzactie,'FM900') Taxa1,
            I.TipTranzactie, I.TipTVA,
            CASE WHEN (TipSaft = 2)or(Extract(Year from I.DataDoc)*12+Extract(Month from I.DataDoc) &lt;&gt; I.An*12+I.Luna) THEN '2'
            ELSE '9' END||'.'||Coalesce(TVAIncasare,0) Taxa2,
            CASE WHEN T.SimbAuto = 'RO' THEN 2 ELSE Coalesce(T.STATCOMUNITAR,0) END||'.'||To_Char(TipTranzactie,'FM900')||'.'||TipTVA||'.'||CASE WHEN TipSaft = 2 THEN '2' ELSE '9' END||'.'||Coalesce(TVAIncasare,0) TaxaI,
            CASE WHEN T.SimbAuto = 'RO' THEN 2 ELSE Coalesce(T.STATCOMUNITAR,0) END||'.'||To_Char(TipTranzactie,'FM900') Cheia1, TipSaft||'.'||Coalesce(TVAIncasare,0) Cheia2,
            I.RotEFact
          FROM  Intrari I
            LEFT JOIN NAGENDA      A   ON A.CODAGENDA = I.CodLocatie AND A.codpart = I.Partener
            LEFT JOIN NLOCALIT     L   ON L.CODLOCALIT = Coalesce(A.CODLOCALIT, 0)
            LEFT JOIN NTARI        T   ON T.CODTARA = Coalesce(L.CODTARA, 0)
            LEFT JOIN NPARTCODFISC PCF ON PCF.Cod_CODFISCAL = Coalesce(I.CodFiscal,0)
          WHERE CodIntr = pCodDoc
        )
        SELECT
          I1.CodIntr, I1.CodIntr1, I.TipDoc, I.An, I.Luna, I.AnLuna, I.TVAIncasare, I.PlatitorTVA, I.Cheia1, I.Cheia2, I.Taxa1, I.Taxa2, Coalesce(I1.Impozabil,0) Impozabil,
          Coalesce(D1.PretImport,
          Case when aCursLinie = 1 then Coalesce(NULLIF(I1.CursFacturaAvans, 0), I.Curs) else I.Curs end*Coalesce(I1.PretOrig, I1.PU)*Coalesce(I1.CoefDiscMaj,1)) * I1.Cant Valoare,
          Case when aCursLinie = 1 then Coalesce(NULLIF(I1.CursFacturaAvans, 0), I.Curs) else I.Curs end*D1.PretValuta * I1.Cant ValoareDVI, Coalesce(D.TaxeIncluse,0) TaxeIncluse,
          CASE
            WHEN I.TIPDOC = 3
            THEN Case when aCursLinie = 1 then Coalesce(NULLIF(I1.CursFacturaAvans, 0), I.Curs) else I.Curs end*Coalesce(I1.TVA, 0)*Coalesce(I1.CoefDiscMaj,1)* CASE WHEN I1.ADDim = -100 THEN 0 ELSE 1/(1+Coalesce(I1.ADDim/100,0)) END
            ELSE Coalesce(D1.TVA,Case when aCursLinie = 1 then Coalesce(NULLIF(I1.CursFacturaAvans, 0), I.Curs) else I.Curs end*Coalesce(I1.TVA, 0))
          END TVA,
          TL.CODCONTDED, TL.CODCONTCOLE, TL.procent ProcTVAArt, I.TipTVA, I.TipTranzactie,
          A.TipArticol,
          CASE WHEN TL.PROCENT IS NULL THEN '?' WHEN TL.PROCENT = 0 THEN '0' ELSE '1' END CotaArtZero, I1.TVANEDED, I1.Codobiect,
          Coalesce(
            NULLIF(AE1.ContServ, 0),
            CASE
              WHEN D1.CodDVI1 IS NOT NULL AND AE1.CodIntr1 = I1.CodIntr1
              THEN
                COALESCE (
                  (
                    SELECT Min(io1.cont)
                    FROM nirstoc ns INNER JOIN ioart1 io1 ON io1.codioart = ns.codioart
                    WHERE ns.coddvi1 = D1.CodDVI1 AND Coalesce(io1.cont, 0) &lt;&gt; 0
                      AND i.AnLuna BETWEEN io1.ALStart AND io1.ALStop
                  ),
                  (
                    SELECT Min(io1.cont)
                    FROM livr1 l1
                      LEFT JOIN NIRSTOC NS ON NS.CodNirStoc = L1.CodNirStoc
                      LEFT JOIN LIVRVAL LV ON LV.CodLivr1   = L1.CodLivr1
                      LEFT JOIN ioart1 io1 ON io1.codioart  = Coalesce(lv.CodIOArt, ns.codioart)
                    WHERE l1.coddvi1 = D1.CodDVI1 AND Coalesce(io1.cont, 0) &lt;&gt; 0
                      AND i.AnLuna BETWEEN io1.ALStart AND io1.ALStop
                  )
                )
              ELSE
                COALESCE (
                  (
                    SELECT Min(io1.cont)
                    FROM nirstoc ns INNER JOIN ioart1 io1 ON io1.codioart = ns.codioart
                    WHERE ns.codintr1 = ae1.codintr1 AND Coalesce(io1.cont, 0) &lt;&gt; 0
                      AND i.AnLuna BETWEEN io1.ALStart AND io1.ALStop
                  ),
                  (
                    SELECT Min(io1.cont)
                    FROM livr1 l1
                      LEFT JOIN NIRSTOC NS ON NS.CodNirStoc = L1.CodNirStoc
                      LEFT JOIN LIVRVAL LV ON LV.CodLivr1   = L1.CodLivr1
                      LEFT JOIN ioart1 io1 ON io1.codioart  = Coalesce(lv.CodIOArt, ns.codioart)
                    WHERE l1.codintr1 = ae1.codintr1 AND Coalesce(io1.cont, 0) &lt;&gt; 0
                      AND i.AnLuna BETWEEN io1.ALStart AND io1.ALStop
                  )
                )
            END
          ) ContSaft, I.DataDoc, Coalesce(I1.TVA, 0) TVALinie, Coalesce(AL.TaxCode, 0) TaxCodeArt,
          I.RotEFact, TD.Manual
        FROM Intr I
          INNER JOIN Intrari1 I1  ON I1.CodIntr    = I.CodIntr
          LEFT  JOIN DVI      D   ON D.CodIntr     = I.CodIntr
          LEFT  JOIN DVI1     D1  ON D1.CodIntr1   = I1.CodIntr1
          LEFT  JOIN IntrLink IK  ON IK.CodIntr1   = I1.CodIntr1
          LEFT  JOIN Intrari1 AE1 ON AE1.CodIntr1 = Coalesce(IK.CodLinieAviz, I1.CodIntr1)
          LEFT  JOIN NArtOBJ  O   ON O.CodObiect   = I1.CodObiect
          LEFT  JOIN NArt     A   ON A.CodArticol  = O.CodArticol
          LEFT  JOIN NArt1    AL  ON AL.CODARTICOL = O.CODARTICOL AND I.AnLuna BETWEEN AL.ALStart AND AL.ALStop
          LEFT  JOIN NTva1    TL  ON TL.CodTVA     = AL.CodTVA    AND I.AnLuna BETWEEN TL.ALStart AND TL.ALStop
          LEFT  JOIN TAXDECL  TD  ON TD.TipDoc     = I.Tipdoc     AND TD.Coddoc = I.CodIntr AND TD.Coddoc1 = I1.CODIntr1
        WHERE (Coalesce(I1.Impozabil, 0) &lt;&gt; 4)
--          AND (Coalesce(TD.Manual, 0) &lt;&gt; 1)
          AND (NOT I1.TipLinie IN ('G','T'))
          AND (Coalesce(I1.Cant,0) &lt;&gt; 0)
      ) LOOP
        cTd1  := ''; cTx1  := '';  cTd2 := '';  cTx2 := '';  cTxP := '';
        crTd1 := ''; crTx1 := '';

        DoServCaStoc := vRec.TipDoc = 2;
        if vRec.Tiparticol = '1' then --daca e serviciu
          Select Count(*) into aCod from Intrari1 where CodIntr = pCodDoc and TipLinie = '=';
          if (vRec.TipDoc = 5)and (vRec.TipTranzactie in (2,3))  then
             DoServCaStoc :=
                (aCod &gt; 0 and Coalesce(fnc_GetValConstanta('InclServInValBunuri' ,vRec.An, vRec.Luna), '2')='1')
                or
                (InStr(','||Coalesce(fnc_GetValConstanta('ServAICB' ,vRec.An, vRec.Luna), '0')||',', ','||vRec.CodObiect||',') &gt; 0)
                or
                (InStr(','||Coalesce(fnc_GetValConstanta('SERVIMPB' ,vRec.An, vRec.Luna), '0')||',', ','||vRec.CodObiect||',') &gt; 0);
          end if;
          if (vRec.TipDoc in (1,9)) and (vRec.TipTranzactie = 2)  then
             DoServCaStoc :=
                (aCod &gt; 0 and Coalesce(fnc_GetValConstanta('InclServInValBunuri' ,vRec.An, vRec.Luna), '2')='1')
                or
                (InStr(','||Coalesce(fnc_GetValConstanta('ServAICB' ,vRec.An, vRec.Luna), '0')||',', ','||vRec.CodObiect||',') &gt; 0);
          end if;
          if (vRec.TipDoc in (1,9)) and (vRec.TipTranzactie = 3)  then
             DoServCaStoc :=
                (aCod &gt; 0 and Coalesce(fnc_GetValConstanta('InclServInValBunuri' ,vRec.An, vRec.Luna), '2')='1');
          end if;
        end if;

        bArt0 := vRec.Tiparticol = '0';  bArt1 := vRec.Tiparticol = '1';  bArt2 := vRec.Tiparticol = '2';

        IF    vRec.TipDoc IN (1, 2, 3, 9) THEN cTd1 := '98';  cTd2 := '99';
        ELSIF vRec.TipDoc = 5             THEN cTd1 := '05';  cTd2 := '99';
        ELSIF vRec.TipDoc = 4             THEN cTd1 := '04';  cTd2 := '??';
        END IF;
        IF    bArt0 OR bArt2 OR DoServCaStoc THEN cTx1 := '8'; cTx2 := '9';
        ELSIF bArt1                     THEN cTx1 := '1'; cTx2 := '9';
        END IF;

        if (vRec.TipDoc = 2) and Coalesce(fnc_getvalconstanta('AvizFaraTVANeex' ,vRec.An, vRec.Luna), '2')='2'
          then cTx1 := '0'; cTx2 := '0'; end if;
        crTx1 := vRec.TipArticol;

        aNeded := Coalesce(vRec.TVANEDED,0);
        cTd1 := vRec.PlatitorTVA||'.'||cTd1||'.';
        cTd2 := vRec.PlatitorTVA||'.'||cTd2||'.';

        crTd1 := cTd1;
        Taxa2 := vRec.Taxa2;
        if (Extract(Year from vRec.DataDoc)*12+Extract(Month from vRec.DataDoc) &lt;&gt; vRec.AnLuna)
        AND (vRec.TVALinie = 0)
        then Taxa2 := '9.'||Coalesce(vRec.TVAIncasare,0); end if;

        IF vRec.Impozabil = 3  THEN
          cTaxa := vRec.Taxa1 ||'.2.'||Taxa2;
          cKeia := vRec.Cheia1||'.2.'||vRec.Cheia2;
        ELSE
          cTaxa := vRec.Taxa1 ||'.'||vRec.TipTVA||'.'||Taxa2;
          cKeia := vRec.Cheia1||'.'||vRec.TipTVA||'.'||vRec.Cheia2;
        END IF;

        cTx1  := cTaxa||'.'||cTx1 ||'.'||vRec.CotaArtZero||'.';
        cTx2  := cTaxa||'.'||cTx2 ||'.'||vRec.CotaArtZero||'.';
        crTx1 := cKeia||'.'||crTx1||'.'||vRec.CotaArtZero||'.';

        if vrec.TIPDOC = 5 and vrec.TIPTRANZACTIE = 2 and vrec.TIPTVA = 2 and vrec.TAXEINCLUSE = 1
          then aValLinie := vRec.ValoareDVI;
          else aValLinie := vRec.Valoare;
        END IF;
        aTVALinie := vRec.TVA;

        SuplimTipDoc3 := 0;
        IF vRec.TipDoc = 3
        THEN
          aValLinie := aValLinie - aTVALinie;
          SuplimTipDoc3 := aTVALinie;
        END IF;

        IF aValLinie &lt;&gt; 0
        THEN aProcTVADoc := Round(aTVALinie/aValLinie*100, 0);
        ELSE aProcTVADoc := 0;
        END IF;
        IF (vRec.TipTVA &lt;&gt; 9)
        OR (Coalesce(fnc_GetValConstanta('ProcTVAArt315' ,vRec.An, vRec.Luna), To_Char(trunc(aProcTVADoc)))&lt;&gt; To_Char(trunc(aProcTVADoc)))
        THEN
         IF aValLinie = 0
          THEN aProcTVADoc := vRec.ProcTVAArt ;
          ELSE aProcTVADoc := PKG_LIST_BASE_UTILS_CALC_MATCH_TVA(vRec.TIPDOC, vRec.An, vRec.Luna, 1, aValLinie + SuplimTipDoc3, vRec.TVA, vRec.CodObiect, vRec.ProcTVAArt, vRec.RotEFact, 1);
          END IF;
        END IF;
        cTxP  := To_Char(aProcTVADoc,'FM900');
        cKeia := crTd1||crTx1|| cTxP ||'.'||aNeded;

        cCod1 := cTd1 ||cTx1 || cTxP ||'.'||aNeded;
        cCod2 := cTd1 ||cTx2 || cTxP ||'.'||aNeded;
        cCod3 := cTd1 ||cTx1 ||  '99'||'.'||aNeded;
        cCod4 := cTd1 ||cTx2 ||  '99'||'.'||aNeded;
        cCod5 := cTd2 ||cTx1 || cTxP ||'.'||aNeded;
        cCod6 := cTd2 ||cTx2 || cTxP ||'.'||aNeded;
        cCod7 := cTd2 ||cTx1 ||  '99'||'.'||aNeded;
        cCod8 := cTd2 ||cTx2 ||  '99'||'.'||aNeded;
        if Coalesce(vRec.Impozabil,0) = 4 and Coalesce(vRec.TVANEDED,0) = 1 THEN
          aTax     := -1;
          cKeia := 'ok - decont intern';
          aTaxBase := aValLinie;
          aTaxVal  := aTVALinie;
          BEGIN
            SELECT codTaxdecl INTO aCod FROM TAXDECL WHERE TipDoc = vRec.TIPDOC AND CODDOC1 = vRec.CODINTR1;
          EXCEPTION WHEN OTHERS THEN
            aCod := 0;
          END;

          IF pkg_saft_FirmaPlatitorTVA(aSubunit, vRec.An, vRec.Luna) = 0 THEN
            aTax := 0;
            cKeia := 'neplatitor TVA';
          END IF;

          IF aCod = 0 OR aCod IS NULL THEN
            aManual := 0;
            INSERT INTO TAXDECL(codTaxdecl,        tipdoc,      coddoc,       coddoc1,       TaxCode, TaxBase,   TaxVal,    Cheia, Manual,  CodCont,       AnLuna)
            VALUES(Nextval('SEQ_TAXDECL_CODTAXDECL'), vRec.TIPDOC, vRec.CODINTR, vRec.CODINTR1, aTAX,    aTaxBase, aTaxVal, cKeia, aManual, vRec.ContSaft, vRec.AnLuna);
          ELSE
            IF vRec.Manual = 0 THEN
              UPDATE TAXDECL
              SET TaxBase = aTaxBase, TaxVal = aTaxVal, CHEIA = cKeia, AnLuna = vRec.AnLuna, TaxCode = aTax, CodCont = vRec.ContSaft
              WHERE codTaxdecl = aCod;
            ELSE
              UPDATE TAXDECL
              SET TaxBase = aTaxBase, TaxVal = aTaxVal, CHEIA = cKeia WHERE codTaxdecl = aCod;
            END IF;
          END IF;
        ELSE
          BEGIN
            aTaxBase := aValLinie;
            aTaxVal  := aTVALinie;
            aCODINTR1 := vRec.CodIntr1;
            if aNEDED = 3 then
              aTaxBase := Round(aValLinie/2, 3);
              aTaxVal  := Round(aTVALinie/2, 3);
              aCODINTR1 := -vRec.CodIntr1;
            elsif aNEDED = 1 then
              aCODINTR1 := -vRec.CodIntr1;
            end if;
            SELECT T.COD, T.TAXA INTO cTaxCode, aTax
            FROM WINMADMIN.Taxcode_i T
            WHERE T.Cod = cCod1 OR T.Cod = cCod2 OR T.Cod = cCod3 OR T.Cod = cCod4 OR T.Cod = cCod5 OR T.Cod = cCod6 OR T.Cod = cCod7 OR T.Cod = cCod8;
            cKeia := 'ok - '||cTaxCode;
            IF VRec.Tiptranzactie &lt; 4 AND VREC.TipTVA = 2 THEN cKeia := '&lt;D'||VREC.CODCONTDED||'D&gt;&lt;C'||VREC.CODCONTCOLE||'C&gt;&lt;V'||To_Char(aTaxVal)||'V&gt; '||cKeia; END IF;
            IF VRec.Tiptranzactie &lt; 4 AND VREC.TipTVA = 4 THEN cKeia := '&lt;P'||VREC.CODCONTDED||'P&gt; '                                                    ||cKeia; END IF;
          EXCEPTION WHEN OTHERS THEN
            aTax  := 0;
            cKeia := '?'||'=='||cCod1||'=='||cCod2||'=='||cCod3||'=='||cCod4||'=='||cCod5||'=='||cCod6||'=='||cCod7||'=='||cCod8;
          END;

          BEGIN
            SELECT codTaxdecl INTO aCod FROM TAXDECL WHERE TipDoc = vRec.TIPDOC AND CODDOC1 = aCODINTR1;
          EXCEPTION WHEN OTHERS THEN
            aCod := 0;
          END;

          IF VREC.TaxCodeArt &gt; 0 THEN
            aTax := VREC.TaxCodeArt;
            cKeia := 'TaxCodeArt';
          END IF;

          IF pkg_saft_FirmaPlatitorTVA(aSubunit, vRec.An, vRec.Luna) = 0 THEN
            aTax := 0;
            cKeia := 'neplatitor TVA';
          END IF;

          IF aCod = 0 OR aCod IS NULL THEN
            aManual := 0;
            INSERT INTO TAXDECL(codTaxdecl,        tipdoc,      coddoc,       coddoc1,       TaxCode, TaxBase,   TaxVal,    Cheia, Manual,  CodCont,       AnLuna)
            VALUES(Nextval('SEQ_TAXDECL_CODTAXDECL'), vRec.TIPDOC, vRec.CODINTR, aCODINTR1, aTAX,    aTaxBase, aTaxVal, cKeia, aManual, vRec.ContSaft, vRec.AnLuna);
          ELSE
            IF vRec.Manual = 0 THEN
              UPDATE TAXDECL
              SET TaxBase = aTaxBase, TaxVal = aTaxVal, CHEIA = cKeia, AnLuna = vRec.AnLuna, TaxCode = aTax, CodCont = vRec.ContSaft
              WHERE codTaxdecl = aCod;
            ELSE
              UPDATE TAXDECL
              SET TaxBase = aTaxBase, TaxVal = aTaxVal, CHEIA = cKeia
              WHERE codTaxdecl = aCod;
            END IF;
          END IF;
          if aNEDED &gt; 0 then
            cKeia := crTd1||crTx1|| cTxP ||'.0';
            cCod1 := cTd1 ||cTx1 || cTxP ||'.0';
            cCod2 := cTd1 ||cTx2 || cTxP ||'.0';
            cCod3 := cTd1 ||cTx1 ||  '99'||'.0';
            cCod4 := cTd1 ||cTx2 ||  '99'||'.0';
            cCod5 := cTd2 ||cTx1 || cTxP ||'.0';
            cCod6 := cTd2 ||cTx2 || cTxP ||'.0';
            cCod7 := cTd2 ||cTx1 ||  '99'||'.0';
            cCod8 := cTd2 ||cTx2 ||  '99'||'.0';
            BEGIN
              aTaxBase := aValLinie;
              aTaxVal  := aTVALinie;
              SELECT T.COD, T.TAXA INTO cTaxCode, aTax
              FROM WINMADMIN.Taxcode_i T
              WHERE T.Cod = cCod1 OR T.Cod = cCod2 OR T.Cod = cCod3 OR T.Cod = cCod4 OR T.Cod = cCod5 OR T.Cod = cCod6 OR T.Cod = cCod7 OR T.Cod = cCod8;
              cKeia := 'ok - '||cTaxCode;
            EXCEPTION WHEN OTHERS THEN
              aTax  := 0;
              cKeia := '?'||'=='||cCod1||'=='||cCod2||'=='||cCod3||'=='||cCod4||'=='||cCod5||'=='||cCod6||'=='||cCod7||'=='||cCod8;
            END;

            BEGIN
              SELECT codTaxdecl INTO aCod FROM TAXDECL WHERE TipDoc = vRec.TIPDOC AND CODDOC1 = vRec.CODINTR1;
            EXCEPTION WHEN OTHERS THEN
              aCod := 0;
            END;

            IF VREC.TaxCodeArt &gt; 0 THEN
              aTax := VREC.TaxCodeArt;
              cKeia := 'TaxCodeArt';
            END IF;

            IF pkg_saft_FirmaPlatitorTVA(aSubunit, vRec.An, vRec.Luna) = 0 THEN
              aTax := 0;
              cKeia := 'neplatitor TVA';
            END IF;

            IF aCod = 0 OR aCod IS NULL THEN
              aManual := 0;
              INSERT INTO TAXDECL(codTaxdecl,        tipdoc,      coddoc,       coddoc1,       TaxCode, TaxBase,   TaxVal,    Cheia, Manual,  CodCont,       AnLuna)
              VALUES(Nextval('SEQ_TAXDECL_CODTAXDECL'), vRec.TIPDOC, vRec.CODINTR, vRec.CODINTR1, aTAX,    aTaxBase, aTaxVal, cKeia, aManual, vRec.ContSaft, vRec.AnLuna);
            ELSE
              IF vRec.Manual = 0 THEN
                UPDATE TAXDECL
                SET TaxBase = aTaxBase, TaxVal = aTaxVal, CHEIA = cKeia, AnLuna = vRec.AnLuna, TaxCode = aTax, CodCont = vRec.ContSaft
                WHERE codTaxdecl = aCod;
              ELSE
                UPDATE TAXDECL
                SET TaxBase = aTaxBase, TaxVal = aTaxVal, CHEIA = cKeia
                WHERE codTaxdecl = aCod;
              END IF;
            END IF;
          END IF;
        END IF;
      END LOOP;
    END IF;
  ELSIF pCaz = 1 THEN
    SELECT An, Luna, TipDoc, TipTVA, TipTranzactie, Coalesce(Anulat, 0), Coalesce(Operat, 1), Subunitatea INTO aAn, aLuna, aTipDoc, aTipTVA, aTipTranzactie, aAnulat, aOperat, aSubunit
    FROM Iesiri
    WHERE CodIes = pCodDoc;
    IF aAnulat = 1 OR aOperat = 0 or (aTipTranzactie = 5 and aTipDoc &lt;&gt; 20) THEN
      DELETE FROM TaxDecl WHERE TipDoc = aTipDoc AND CodDoc = pCodDoc;
    ELSE
      DELETE FROM TaxDecl WHERE TipDoc = aTipDoc AND CodDoc = pCodDoc AND MANUAL = 0;
      TVA0FaraDed := Coalesce(fnc_GetValConstanta('TVA0FaraDed' ,aAn, aLuna), '0');
      FOR vRec IN (
        WITH IES (CodIES, TipDoc, An, Luna, AnLuna, TVAIncasare, Curs, TaxaI, CheiaI, INFOCM, TipFactura, TipTranzactie, RotEFact) AS  (
          SELECT
            I.CodIES, I.TipDoc, I.AN, I.Luna, I.An*12+I.Luna AnLuna, I.TVAIncasare, Coalesce(NULLIF(I.Curs,0),1) Curs,
            CASE WHEN SubStr(PCF.CodFiscal,1,1) &gt;= Chr(65) THEN '1' ELSE '0' END ||'.'||
            CASE WHEN T.SimbAuto = 'RO' THEN 2 ELSE Coalesce(T.STATCOMUNITAR,0) END||'.'||
            TipTranzactie||'.'||To_Char(TipTVA,'FM900')||'.'||
            CASE WHEN TipSaft = 2 THEN '2' WHEN TipSaft = 3 THEN '3' ELSE '9' END||'.'||
            Case when Coalesce(TipFactura,0) = 7 or Coalesce(INFOCM,0) = 1 THEN 1 ELSE 0
            END TaxaI,
            CASE WHEN SubStr(PCF.CodFiscal,1,1) &gt;= Chr(65) THEN 1 ELSE 0 END||'.'||
            CASE WHEN T.SimbAuto = 'RO' THEN 2 ELSE Coalesce(T.STATCOMUNITAR,0) END||'.'||TipTranzactie||'.'||To_Char(TipTVA,'FM900')||'.'||TipSaft||'.'||
            Case when Coalesce(TipFactura,0) = 7 or Coalesce(INFOCM,0) = 1 THEN 1 ELSE 0 END CheiaI,
            Coalesce(INFOCM,0) INFOCM, Coalesce(TipFactura,0) TipFactura, I.TipTranzactie, I.RotEFact
          FROM IESIRI I
            LEFT JOIN NAGENDA A ON A.CODAGENDA = I.CodLocatie AND A.codpart = I.Partener
            LEFT JOIN NLOCALIT L ON L.CODLOCALIT = Coalesce(A.CODLOCALIT, 0)
            LEFT JOIN NTARI T ON T.CODTARA = Coalesce(L.CODTARA, 0)
            LEFT JOIN NPARTCODFISC PCFP ON PCFP.CodPart = I.Partener AND PCFP.PRINCIPAL = 1
            LEFT JOIN NPARTCODFISC PCF  ON PCF.Cod_CODFISCAL = Coalesce(NullIf(I.CodFiscal,0),PCFP.COD_CODFISCAL)
          WHERE CodIes = pCodDoc
        )
        SELECT
          I1.CodIES, I1.CodIES1, I.TipDoc, I.An, I.Luna, I.AnLuna, I.INFOCM, I.TipFactura, I.TVAIncasare, I.TipTranzactie,
          Case when aCursLinie = 1 then Coalesce(NULLIF(I1.CursFacturaAvans, 0), I.Curs) else I.Curs end*Coalesce(I1.PretOrig, I1.PU)*Coalesce(I1.CoefDiscMaj,1)*I1.Cant Valoare,
          Case when aCursLinie = 1 then Coalesce(NULLIF(I1.CursFacturaAvans, 0), I.Curs) else I.Curs end*Coalesce(I1.TVA, 0)*Coalesce(I1.CoefDiscMaj,1)*CASE WHEN I1.ADDim = -100 THEN 0 ELSE 1/(1+Coalesce(I1.ADDim/100,0)) END TVA,
          TL.procent ProcTVAArt,
          I.CheiaI, I.TaxaI, A.TipArticol,I1.CodObiect,
          CASE WHEN TL.PROCENT IS NULL THEN '?' WHEN TL.CodTVA = TVA0FaraDed THEN '0' ELSE '1' END CotaArtZero,
          I1.TipLinie, AE1.CodIES1 CodAE1, AE1.ContServ, AE.ContIntermed, Coalesce(AL.TaxCode, 0) TaxCodeArt, I.RotEFact, I1.Impozabil,
          I1.Taxa, TD.Manual
        FROM IES I
          INNER JOIN Iesiri1  I1  ON I1.CodIES     = I.CodIES
          LEFT  JOIN IesLink  IK  ON IK.CodIes1    = I1.CodIes1
          LEFT  JOIN Iesiri1  AE1 ON AE1.CodIes1   = Coalesce(IK.CodLinieAviz, I1.CodIes1)
          LEFT  JOIN Iesiri   AE  ON AE.CodIes     = AE1.CodIes
          LEFT  JOIN NArtOBJ  O   ON O.CodObiect   = I1.CodObiect
          LEFT  JOIN NArt     A   ON A.CodArticol  = O.CodArticol
          LEFT  JOIN NArt1    AL  ON AL.CODARTICOL = O.CODARTICOL AND I.AnLuna BETWEEN AL.ALStart AND AL.ALStop
          LEFT  JOIN NTva1    TL  ON TL.CodTVA     = AL.CodTVA AND I.AnLuna BETWEEN TL.ALStart AND TL.ALStop
          LEFT  JOIN TAXDECL  TD  ON TD.TipDoc     = I.Tipdoc AND TD.Coddoc = I.CodIes and TD.Coddoc1 = I1.CODIES1
        WHERE NOT I1.TipLinie IN ('G','T') and Coalesce(I1.Cant,0) &lt;&gt; 0
                      --AND (Coalesce(TD.Manual, 0) &lt;&gt; 1)

      ) LOOP
        IF vRec.TipLinie = '=' AND vRec.INFOCM = 1 THEN
          BEGIN
            SELECT codcont INTO aContSaft FROM ncont WHERE Simbol = '707';
          EXCEPTION
            WHEN OTHERS THEN aContSaft := 0;
          END;
        ELSIF vRec.TipLinie = '=' THEN
          SELECT Min(venituri) INTO aContSaft
          FROM (
            SELECT ROW_NUMBER() OVER (ORDER BY CASE WHEN Coalesce(l1.contintermed, 0) = 0 THEN 1 ELSE 0 END, L1.CODLIVR1) RNOrd,
            Case when vrec.TipDoc = 14 THEN io1.CHELTTVACOLECTAT ELSE io1.venituri END venituri
            FROM livr1 l1
              LEFT JOIN LIVR    L   ON L.CodLivr     = L1.CodLivr
              LEFT JOIN IESIRI  I   ON I.CodIes      = L.CodIes AND I.TipDoc = L.TipLivr
              LEFT JOIN NIRSTOC NS  ON NS.CodNirStoc = L1.CodNirStoc
              LEFT JOIN LIVRVAL LV  ON LV.CodLivr1   = L1.CodLivr1
              LEFT JOIN IOART1  IO1 ON IO1.CodIOArt  = Coalesce(Nullif(l1.contintermed, 0), Nullif(i.contintermed, 0), lv.CodIOArt, ns.codioart)
            WHERE l1.codies1 = vRec.CodAE1 AND Coalesce(io1.venituri, 0) &lt;&gt; 0
              AND vRec.AnLuna BETWEEN io1.ALStart AND io1.ALStop
          ) ssub
          WHERE RNOrd = 1;
        ELSE
          aContSaft := vRec.ContServ;
        END IF;

        cTd1 := ''; cTx1 := '';
        DoServCaStoc := (Coalesce(fnc_GetValConstanta('InclServInValBunuri' ,vRec.An, vRec.Luna), '2')='1');
        IF DoServCaStoc THEN
          SELECT Count(*) into aCod FROM Iesiri1 WHERE CodIes = pCodDoc and TipLinie = '=';
          IF aCod = 0 THEN DoServCaStoc := False; END IF;
        END IF;
        IF (not DoServCaStoc) and (vRec.TipTranzactie = 2) THEN
          DoServCaStoc := InStr(','||Coalesce(fnc_GetValConstanta('ServLICB' ,vRec.An, vRec.Luna), '0')||',', ','||vRec.CodObiect||',') &gt; 0;
        END IF;
        bArt0 := vRec.Tiparticol = '0';  bArt1 := vRec.Tiparticol = '1';  bArt2 := vRec.Tiparticol = '2';
        IF    bArt0 OR bArt2 OR DoServCaStoc THEN cTx1 := '8'; cTx2 := '9';
        ELSIF bArt1                     THEN cTx1 := '1'; cTx2 := '9';
        END IF;
        IF (vRec.TipDoc = 20) and Coalesce(fnc_GetValConstanta('AvizFaraTVANeex' ,vRec.An, vRec.Luna), '2')='2' THEN cTx1 := '0'; cTx2 := '0'; END IF; crTx1 := vRec.Tiparticol;
        IF vRec.Impozabil = 5 THEN
          cTaxa := Substr(vRec.TaxaI, 1, 6)||'12'||Substr(vRec.TaxaI, 9, 5);
          cTx1  := cTaxa ||'.'||cTx1 ||'.'||vRec.CotaArtZero||'.';
          cTx2  := cTaxa ||'.'||cTx2 ||'.'||vRec.CotaArtZero||'.';

          cTaxa := Substr(vRec.CheiaI, 1, 6)||'12'||Substr(vRec.CheiaI, 9, 5);
          crTx1 := cTaxa||'.'||crTx1||'.'||vRec.CotaArtZero||'.';
        ELSE
          cTx1  := vRec.TaxaI ||'.'||cTx1 ||'.'||vRec.CotaArtZero||'.';
          cTx2  := vRec.TaxaI ||'.'||cTx2 ||'.'||vRec.CotaArtZero||'.';
          crTx1 := vRec.CheiaI||'.'||crTx1||'.'||vRec.CotaArtZero||'.';
        END IF;

        aValLinie := vRec.Valoare;
        aTVALinie := vRec.TVA;
        IF vRec.TipDoc = 21
        THEN aValLinie := aValLinie - aTVALinie;
        END IF;
        BazaTVAMarja := 0; --pentru tva la marja de adaos
        IF aValLinie = 0
        THEN aProcTVADoc := 0;
        ELSE
          IF vRec.TipDoc = 14 --mMinuslainventar
          THEN
            IF vRec.TVA = 0
            THEN aProcTVADoc := 0;
            ELSE
              aProcTVADoc := vRec.ProcTVAArt;
              IF aProcTVADoc &lt;&gt; 0
              THEN aValLinie := Round(aTVALinie /(aProcTVADoc/100),2);
              END IF;
            END IF;
          ELSE
            IF aTipTVA IN (7,8) THEN
              aProcTVADoc  := vRec.ProcTVAArt;
              IF aProcTVADoc &lt;&gt; 0 THEN
                BazaTVAMarja := Round(aTVALinie / (aProcTVADoc/100),2);
              END IF;
            ELSE
              aProcTVADoc := PKG_LIST_BASE_UTILS_CALC_MATCH_TVA(vRec.TIPDOC, vRec.An, vRec.Luna, 1, vRec.Valoare, vRec.TVA, vRec.CodObiect, vRec.ProcTVAArt, vRec.RotEFact, 1);
            END IF;
          END IF;
        END IF;
        cTxP := To_Char(aProcTVADoc,'FM900');
        cKeia := crTx1 || cTxP ;
        cCod1 := cTx1  || cTxP ;
        cCod2 := cTx2  || cTxP ;
        cCod3 := cTx1  || '99';
        cCod4 := cTx2  || '99';
        IF VRec.TipDoc = 14 THEN
          aTax  := 0;
          cKeia := 'OK - hardcoded';
          IF    aProcTVADoc = 21 THEN aTax := 380006;
          ELSIF aProcTVADoc = 11 THEN aTax := 380007;
          ELSIF aProcTVADoc = 19 THEN aTax := 380001;
          ELSIF aProcTVADoc =  9 THEN aTax := 380002;
          ELSIF aProcTVADoc =  5 THEN aTax := 380003;
          ELSIF aProcTVADoc = 20 THEN aTax := 380004;
          ELSIF aProcTVADoc = 24 THEN aTax := 380005;
          END IF;
        ELSE
          IF (VRec.TVAIncasare = 1) AND (aTVALinie &lt;&gt; 0) THEN
            BEGIN
              SELECT T.COD, T.TAXA INTO cTaxCode, aTax
              FROM WINMADMIN.Taxcode_E2 T
              WHERE T.Cod = cCod1 OR T.Cod = cCod2 ;
            EXCEPTION WHEN OTHERS THEN
              aTax  := 0;
            END;
            IF aTax = 0 or aTax is null then
              BEGIN
                  SELECT T.COD, T.TAXA INTO cTaxCode, aTax
                  FROM WINMADMIN.Taxcode_E2 T
                  WHERE T.Cod = cCod3 OR T.Cod = cCod4 ;
              EXCEPTION WHEN OTHERS THEN
                aTax  := 0;
              END;
            end if;
          ELSE
            BEGIN
              SELECT T.COD, T.TAXA INTO cTaxCode, aTax
              FROM WINMADMIN.Taxcode_E T
              WHERE T.Cod = cCod1 OR T.Cod = cCod2 ;
            EXCEPTION WHEN OTHERS THEN
              aTax  := 0;
            END;
            IF aTax = 0 or aTax is null then
              BEGIN
                  SELECT T.COD, T.TAXA INTO cTaxCode, aTax
                  FROM WINMADMIN.Taxcode_E T
                  WHERE T.Cod = cCod3 OR T.Cod = cCod4 ;
              EXCEPTION WHEN OTHERS THEN
                aTax  := 0;
              END;
            end if;
          END IF;
          if aTax = 0 or aTax is null then cKeia := '?'||'=='||cCod1||'=='||cCod2||'=='||cCod3||'=='||cCod4;
                      else cKeia := 'ok - '||cTaxCode; end if;
        END IF;

        IF BazaTVAMarja &lt;&gt; 0 THEN
           cKeia := '&lt;BAZATVAMARJA'||To_Char(round(BazaTVAMarja, 2))||'BAZATVAMARJA&gt; '||cKeia;
        END IF;

        BEGIN
          SELECT T.codTaxdecl INTO aCod FROM TAXDECL T WHERE T.TipDoc = vRec.TIPDOC AND T.CODDOC1 = vRec.CODIES1;
        EXCEPTION WHEN OTHERS THEN
          aCod := 0;
        END;

        IF (VRec.TipDoc &lt;&gt; 14)or(aTVALinie &lt;&gt; 0) THEN --la 14 pun IN taxdecl numai daca linia are TVA
          IF VREC.TaxCodeArt &gt; 0 THEN
            aTax := VREC.TaxCodeArt;
            cKeia := 'TaxCodeArt';
          END IF;
          IF VREC.Taxa IN (3,4,5) and aTVALinie = 0 THEN
            aTax := 310324;
            cKeia := 'Hardcoded SGR';
          END IF;

          IF pkg_saft_FirmaPlatitorTVA(aSubunit, vRec.An, vRec.Luna) = 0 THEN
            aTax := 0;
            cKeia := 'neplatitor TVA';
          END IF;

          IF aCod IS NULL OR aCod = 0 THEN
            aManual := 0;
            --IF VREC.TVAINCASARE = 1 THEN aManual := 2; ELSE aManual := 0; END IF;
            INSERT INTO TAXDECL(codTaxdecl,        tipdoc, coddoc,      coddoc1,      TaxCode, TaxBase,   TaxVal,    Cheia, Manual,  CodCont,   AnLuna)
            VALUES(Nextval('SEQ_TAXDECL_CODTAXDECL'), vRec.TIPDOC, vRec.CODIES, vRec.CODIES1, aTAX,    aValLinie, aTVALinie, cKeia, aManual, aContSaft, vRec.AnLuna);
          ELSE
            IF vRec.Manual = 0 THEN
              UPDATE TAXDECL
              SET TaxBase = aValLinie, TaxVal = aTVALinie, CHEIA = cKeia, AnLuna = vRec.AnLuna, TaxCode = aTax, CodCont = aContSaft
              WHERE codTaxdecl = aCod;
            ELSE
              UPDATE TAXDECL
              SET TaxBase = aValLinie, TaxVal = aTVALinie, CHEIA = cKeia
              WHERE codTaxdecl = aCod;
            END IF;
          END IF;
        END IF;
      END LOOP;
    END IF;
  ELSIF pCaz = 2 THEN
    SELECT An, Luna INTO aAn, aLuna    FROM Iesiri    WHERE CodIes = pCodDoc;
    ArtIncasUlterior := Coalesce(fnc_getvalconstanta('ArtIncasUlterior'    ,aAn, aLuna), '0');
    IOArtIncasImed   := Coalesce(fnc_getvalconstanta('ContIncasareFactura' ,aAn, aLuna), '0');
    DELETE FROM TaxDecl WHERE TipDoc = 16 AND CodDoc = pCodDoc;
    FOR vRec IN (
    WITH IES (CodIES, TipDoc, ContIntermed, TaxaI, AnLuna, DoServ) AS  (
      SELECT
        I.CodIes, I.TipDoc, I.ContIntermed, '0.2.6.01.9.0.' TaxaI, I.An*12+I.Luna AnLuna,
        Coalesce(fnc_getvalconstanta('InclServInValBunuri', I.An, I.Luna), '2') DoServ
      FROM  IESIRI I
      WHERE CodIes = pCodDoc AND TipDoc = 16 AND Operat = 1 AND Anulat = 0
    ),
    TVADOC AS (
      SELECT
        CodIes1,
        Round(PKG_LIST_BASE_UTILS_CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT, 1)/100, 2) KTVA,
        PU*Cant + Coalesce (ValDiscPret,0) ValFaraDisc
      FROM Iesiri I
        INNER JOIN Iesiri1 I1 ON i1.CodIes     = I.CodIes
        LEFT  JOIN nartobj o  ON o.codobiect   = i1.codobiect
        LEFT  JOIN nart1   a1 ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
        LEFT  JOIN ntva1   t1 ON t1.codtva     = a1.codtva    AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
      WHERE I.CodIes = pCodDoc
    ),
    DISCDOC AS (
      SELECT
        CodIes, Round(PROCTVA,0) PROCTVA, DISCOUNT, TVADISCOUNT
      FROM Discmonetar
      WHERE CodIes = pCodDoc
    ),
    CONTDOC AS (
      SELECT CodIes1, ContSaft, CodIOArt
      FROM (
        SELECT
          ROW_NUMBER() OVER (PARTITION BY I1.CodIes1 ORDER BY CASE WHEN Coalesce(l1.contintermed, 0) = 0 THEN 1 ELSE 0 END, L1.CODLIVR1) RNOrd,
          I1.CodIes1, CASE WHEN I1.tiplinie = '=' THEN io1.venituri ELSE i1.ContServ END ContSaft, Coalesce(lv.CodIOArt, Coalesce(ns.codioart, 0)) CodIOArt
        FROM IES I
          INNER JOIN Iesiri1 I1  ON I1.CodIes     = I.CodIes
          LEFT JOIN  livr1   l1  ON I1.CodIes1    = L1.CodIes1
          LEFT JOIN  NIRSTOC NS  ON NS.CodNirStoc = L1.CodNirStoc
          LEFT JOIN  LIVRVAL LV  ON LV.CodLivr1   = L1.CodLivr1
          LEFT JOIN  IOART1  IO1 ON IO1.CodIOArt  = Coalesce(Nullif(l1.contintermed, 0), Nullif(i.contintermed, 0), lv.CodIOArt, ns.codioart) AND I.AnLuna BETWEEN io1.ALStart AND io1.ALStop
        WHERE NOT I1.TipLinie in ('G','T')
      ) asub
      WHERE asub.rnord = 1
    ),
    IES1 AS (
      SELECT
        CodIes AS CodDoc, AnLuna, ProcTVA AS CodDoc1, ContSaft, Cod1, Cod2, CoefIO,
        Sum(Coalesce(Valoare, 0)-Coalesce(TVA, 0)) Valoare , Sum(Coalesce(TVA, 0)) TVA, TaxCodeArt, TaxaSpec
      FROM (
        SELECT
          I.CodIes, I.AnLuna, Coalesce(TD.KTVA*100,0) PROCTVA, CD.ContSaft, TD.ValFaraDisc Valoare, Coalesce(I1.TVA, 0) + Coalesce(ValDiscPret,0)* KTVA / (1+KTVA) TVA,
          I.TaxaI||'9.'||CASE WHEN TL.PROCENT = 0 THEN '0' ELSE '1' END||'.'||To_Char(Round(TD.kTVA*100, 2),'FM900') AS Cod1,
          I.TaxaI||'9.'||CASE WHEN TL.PROCENT = 0 THEN '0' ELSE '1' END||'.'||'99' AS Cod2,
          CASE WHEN CD.CodIOArt = IOArtIncasImed THEN 0 ELSE 1 END CoefIO, Coalesce(AL.TaxCode, 0) TaxCodeArt,
          CASE WHEN I1.Taxa in (3,4,5) and I1.TVA = 0 then 1 else 0 end TaxaSpec
        FROM IES I
          INNER JOIN IESIRI1 I1 ON I1.CodIes     = I.CodIes
          INNER JOIN TVADOC  TD ON TD.CodIes1    = I1.CodIes1
          LEFT  JOIN CONTDOC CD ON CD.CodIes1    = I1.CodIes1
          LEFT  JOIN NArtOBJ O  ON O .CodObiect  = I1.CodObiect
          LEFT  JOIN NArt    A  ON A .CodArticol = O.CodArticol
          LEFT  JOIN NArt1   AL ON AL.CODARTICOL = O.CODARTICOL AND I.AnLuna BETWEEN AL.ALStart AND AL.ALStop
          LEFT  JOIN NTva1   TL ON TL.CodTVA     = AL.CodTVA    AND I.AnLuna BETWEEN TL.ALStart AND TL.ALStop
        WHERE NOT I1.TipLinie in ('G','T') and Coalesce(I1.Cant,0) &lt;&gt; 0 and I1.CodObiect &lt;&gt; ArtIncasUlterior
      ) subs
      GROUP BY CodIes, AnLuna, PROCTVA, CoefIO, ContSaft, Cod1, Cod2, TaxCodeArt, TaxaSpec
    )
    SELECT
      I.CodDoc, I.CodDoc1, Case WHEN I.TaxaSpec = 1 then 310324 WHEN I.TaxCodeArt &gt; 0 then I.TaxCodeArt else T.TAXA end AS TaxCode,
      I.Valoare AS TaxBase, I.TVA AS TaxVal, CoefIO,
      CASE
        WHEN T.TAXA &lt;&gt; 0 THEN  'ok - '||T.COD
        ELSE '?ok - '||T.COD||'=='||I.Cod1||'=='||I.Cod2
      END AS Cheia,
      0 AS Manual, I.ContSaft AS CodCont, I.AnLuna
    FROM Ies1 I LEFT JOIN DISCDOC D on D.Codies = I.CodDoc and D.ProcTVA = I.CodDoc1
    LEFT JOIN WINMADMIN.Taxcode_E T ON T.Cod = I.Cod1 OR T.Cod = I.Cod2
    ) loop
      SELECT Count(*) into aCod from Iesiri1 I1 WHERE I1.CodIes = pCodDoc and Coalesce (ValDiscPret,0) &lt;&gt; 0;

      IF pkg_saft_FirmaPlatitorTVA(aSubunit, aAn, aLuna) = 0 THEN
        aTax := 0;
        cKeia := 'neplatitor TVA';
      ELSE
        aTax := VRec.Taxcode;
        cKeia := VRec.Cheia;
      END IF;

      IF aCod &lt;&gt; 0 -- am disc pe linie
      THEN
        INSERT INTO TaxDecl(CodTaxdecl, TipDoc, CodDoc, CodDoc1, TaxCode, TaxBase, TaxVal,Cheia, Manual, CodCont, AnLuna)
        VALUES(nextval('SEQ_TAXDECL_CODTAXDECL'), 16, vRec.CodDoc, vRec.CodDoc1, vRec.TaxCode, vRec.TaxBase, vRec.TaxVal, vRec.Cheia, vRec.Manual, vRec.CodCont, vRec.AnLuna);
      ELSE
        WITH
        TVADOC AS (
          SELECT
            CodIes1,
            Round(PKG_LIST_BASE_UTILS_CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT, 1)/100, 2) KTVA,
            PU*Cant Val
          FROM Iesiri I
            INNER JOIN Iesiri1 I1 on i1.CodIes     = I.CodIes
            LEFT  JOIN nartobj o  ON o.codobiect   = i1.codobiect
            LEFT  JOIN nart1   a1 ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
            LEFT  JOIN ntva1   t1 ON t1.codtva     = a1.codtva    AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
          WHERE I.CodIes = pCodDoc
        ),
        CONTDOC AS (
          SELECT CodIes1, Case when CodIOArt = IOArtIncasImed then 0 else 1 end CoefIO
          FROM (
            SELECT
              ROW_NUMBER() OVER (PARTITION BY I1.CodIes1 ORDER BY CASE WHEN Coalesce(l1.contintermed, 0) = 0 THEN 1 ELSE 0 END, L1.CODLIVR1) RNOrd,
              I1.CodIes1, Coalesce(lv.CodIOArt, Coalesce(ns.codioart, 0)) CodIOArt
            FROM IESIRI I
              INNER JOIN Iesiri1 I1  ON I1.CodIes     = I.CodIes
              LEFT JOIN  livr1   l1  ON I1.CodIes1    = L1.CodIes1
              LEFT JOIN  NIRSTOC NS  ON NS.CodNirStoc = L1.CodNirStoc
              LEFT JOIN  LIVRVAL LV  ON LV.CodLivr1   = L1.CodLivr1
              WHERE I.CodIes = pCodDoc AND TipDoc = 16 AND Operat = 1 AND Anulat = 0 AND (NOT I1.TipLinie in ('G','T'))
          ) asub
          WHERE asub.rnord = 1
        ),
        IES1 AS (
          SELECT CodIes, ProcTVA, CoefIO, Sum(Coalesce(Val, 0)) Valoare
          FROM (
            SELECT I.CodIes, CD.CoefIO, Coalesce(TD.KTVA*100,0) PROCTVA, TD.Val
            FROM (
              SELECT CodIes
              FROM  IESIRI
              WHERE CodIes = pCodDoc AND Operat = 1
            ) I
              INNER JOIN IESIRI1 I1 ON I1.CodIes     = I.CodIes
              LEFT  JOIN CONTDOC CD ON CD.CodIes1    = I1.CodIes1
              INNER JOIN TVADOC  TD ON TD.CodIes1    = I1.CodIes1
            WHERE NOT I1.TipLinie in ('G','T') and Coalesce(I1.Cant,0) &lt;&gt; 0
          ) subs
          GROUP BY CodIes, CoefIO, PROCTVA
        )
        SELECT I.Valoare, I.CoefIO, Coalesce(D.Discount,0) Discount INTO aVal, aCoefIO, aDisc
        FROM Ies1 I LEFT JOIN (SELECT CodIes, Round(PROCTVA,0) PROCTVA, DISCOUNT FROM Discmonetar WHERE CodIes = pCodDoc ) D on D.Codies = I.CodIes and D.ProcTVA = I.ProcTVA
        WHERE I.ProcTVA = vRec.Coddoc1 and I.CoefIO = VRec.CoefIO;
        IF aVal = 0 THEN KIncas := 1; ELSE KIncas := 1 + aCoefIO*aDisc/aVal; END IF;

        IF pkg_saft_FirmaPlatitorTVA(aSubunit, aAn, aLuna) = 0 THEN
          aTax := 0;
          cKeia := 'neplatitor TVA';
        ELSE
          aTax := VRec.Taxcode;
          cKeia := VRec.Cheia;
        END IF;

        INSERT INTO TaxDecl(CodTaxdecl, TipDoc, CodDoc, CodDoc1, TaxCode, TaxBase, TaxVal,Cheia, Manual, CodCont, AnLuna)
        VALUES(nextval('SEQ_TAXDECL_CODTAXDECL'), 16, vRec.CodDoc, vRec.CodDoc1, vRec.TaxCode, Round(KIncas*vRec.TaxBase, 2), Round(KIncas*vRec.TaxVal, 2),vRec.Cheia, vRec.Manual, vRec.CodCont, vRec.AnLuna);
      END IF;
    END LOOP;
  ELSIF pCaz = 3 THEN
    SELECT TipDoc, Coalesce(Operat, 1), An, Luna, Subunitatea INTO aTipDoc, aOperat, aAn, aLuna, aSubunit FROM Trezor WHERE CodTrezor = pCodDoc;
    IF aOperat = 0 THEN
      DELETE FROM TaxDecl WHERE TipDoc = aTipDoc AND CodDoc IN (SELECT CodTrezor1 FROM Trezor1 WHERE CodTrezor = pCodDoc);
    ELSE
      DELETE FROM TaxDecl WHERE TipDoc = aTipDoc AND MANUAL = 0 AND CodDoc IN (SELECT CodTrezor1 FROM Trezor1 WHERE CodTrezor = pCodDoc);
      FOR vRec IN (
        SELECT
          bSub.coddoc, bSub.coddoc1, bSub.tipdoc, bSub.AnLuna,
          Coalesce(TE.Taxa, TI.Taxa, bSub.Taxa) Taxa, bSub.ValBaza, bSub.ValTaxa,
          bSub.cont, bSub.impozit, bSub.Simbol, bSub.TaxCode, bSub.TaxaI, bSub.TaxaE, bSub.TipTranz,bSub.ObiectTranz,
          bSub.TVAIncasare, bSub.ProcStopaj, bSub.CodIO, bSub.TipDocIO, bSub.TipIO
        FROM (
          SELECT
            aSub.CodDoc, aSub.CodDoc1, aSub.tipdoc, aSub.TipTranz, aSub.ObiectTranz,aSub.AnLuna, C.TaxCode Taxa, Round(T.ProcTaxa,0) proc,
            CASE
              WHEN Coalesce(c.impozit,0) = 1 AND Coalesce(T.ProcTaxa,0) = 0 THEN 0
              WHEN Coalesce(c.impozit,0) = 1                                THEN Round(aSub.Val/(T.ProcTaxa/100),2)
              ELSE aSub.Val - aSub.TVA
            END ValBaza,
            CASE WHEN Coalesce(c.impozit,0) = 1 THEN aSub.Val ELSE aSub.TVA END ValTaxa, T.COD TaxCode,
            aSub.TaxaE||To_Char(Round(PKG_LIST_BASE_UTILS_MATCH_TVA_PROC(CASE WHEN aSub.VAL-aSub.TVA = 0 THEN 0 ELSE aSub.TVA/(aSub.VAL-aSub.TVA) END*100, aSub.AnLuna),0),'FM900')       TaxaE,
            aSub.TaxaI||To_Char(Round(PKG_LIST_BASE_UTILS_MATCH_TVA_PROC(CASE WHEN aSub.VAL-aSub.TVA = 0 THEN 0 ELSE aSub.TVA/(aSub.VAL-aSub.TVA) END*100, aSub.AnLuna),0),'FM900')||'.0' TaxaI,
            aSub.cont, Coalesce(c.impozit,0) impozit, c.Simbol, TVAIncasare, ProcStopaj, aSub.CodIO, aSub.TipDocIO, aSub.TipIO
          FROM (
            SELECT
              t1.codtrezor1 coddoc, o.codobligpif coddoc1, t.tipdoc, t1.TipTranz, t1.ObiectTranz, T.An*12+T.Luna AnLuna,
              Coalesce(ies.TVAIncasare, Coalesce(intr.TVAIncasare, 0)) TVAIncasare, Coalesce(Intr.ProcStopaj,0) ProcStopaj,
              Coalesce(ies.CodIes, Coalesce(intr.CodIntr, 0)) CodIO,
              Coalesce(ies.TipDoc, Coalesce(intr.TipDoc, 0)) TipDocIO,
              CASE WHEN ies.CodIes is not Null THEN 1 ELSE 0 END TipIO,
              CASE
                WHEN o.semnificatie IN (900,901, 950, 951) THEN o.icont
                ELSE (select wme_result from PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(null, o.semnificatie, o.icont, PKG_NOMPART_GET_PART_COD_CARACT_LUNA(t1.codpart,t.an,t.luna)))
              END cont,
              Coalesce(o.valoare,0) * Coalesce(NullIF(t1.curs,0),1) VAL,
              Coalesce(g.tva,0)     * Coalesce(NullIF(t1.curs,0),1) TVA,
              --Coalesce(o.valoare,0) * Coalesce(NullIF(g.curs,0),1)/Coalesce(NullIF(t1.curs,0),1) VAL,
              --Coalesce(g.tva,0)     * Coalesce(NullIF(g.curs,0),1)/Coalesce(NullIF(t1.curs,0),1) TVA,
              CASE
              WHEN Coalesce(g.tva,0) &lt;&gt; 0  AND t1.TipTranz = 1 AND t1.ObiectTranz &lt;&gt; 1 THEN '0.2.1.01.9.0.9.1.'
              WHEN Coalesce(g.tva,0) &lt;&gt; 0  AND t1.TipTranz = 0 AND t1.ObiectTranz  = 1 THEN '0.2.1.01.9.0.9.1.'
              ELSE '?'
              END TaxaE,
              CASE
              WHEN Coalesce(g.tva,0) &lt;&gt; 0  AND t1.TipTranz = 1 AND t1.ObiectTranz  =  1 THEN '1.98.2.01.1.3.0.9.1.'
              WHEN Coalesce(g.tva,0) &lt;&gt; 0  AND t1.TipTranz = 0 AND t1.ObiectTranz  &lt;&gt; 1 THEN '1.98.2.01.1.3.0.9.1.'
              ELSE '?'
              END TaxaI
            FROM trezor t
              LEFT JOIN trezor1  t1   ON t.codtrezor = t1.codtrezor
              LEFT JOIN general  g    ON g.tipdoc = t.tipdoc AND g.coddoc = t1.codtrezor1
              LEFT JOIN obligpif o    ON o.codgeneral = g.codgeneral
              LEFT JOIN stingere s    ON s.codstingatorpif = o.codobligpif
              LEFT JOIN obligpif os   ON os.codobligpif = s.codstinspif
              LEFT JOIN general  gs   ON gs.codgeneral = os.codgeneral
              LEFT JOIN intrari  intr ON intr.codintr = gs.coddoc and intr.tipdoc = gs.tipdoc
              LEFT JOIN iesiri   ies  ON ies.codies = gs.coddoc and ies.tipdoc = gs.tipdoc
              LEFT JOIN trezor1  ts1  ON ts1.codtrezor1 = gs.coddoc AND gs.tipdoc IN (29,31)
              LEFT JOIN trezor   ts   ON ts.codtrezor = ts1.codtrezor
            WHERE T.CodTrezor = pCodDoc AND t1.tiptranz IN (0,1)
              AND (Coalesce( OS.SEMNIFICATIE , 0) = 0 or NOT OS.SEMNIFICATIE IN (500, 600))
              AND (   (t.TipDoc = 33 and t1.obiecttranz IN (3, 4))
                    OR(t.TipDoc &lt;&gt; 33 and t1.obiecttranz IN (4,5,6))
                    OR(o.semnificatie IN (310,320,330,410,420,430))
                    OR Coalesce(ies.TVAIncasare, Coalesce(intr.TVAIncasare, 0)) =1
                    OR Coalesce(intr.PROCSTOPAJ, 0) &lt;&gt; 0
                  )
            UNION ALL
            SELECT
              t1.codtrezor1 coddoc, o.codobligpif coddoc1, t.tipdoc, t1.TipTranz, t1.ObiectTranz, T.An*12+T.Luna AnLuna,
              Coalesce(ies.TVAIncasare, Coalesce(intr.TVAIncasare, 0)) TVAIncasare, 0 ProcStopaj,
              Coalesce(ies.CodIes, Coalesce(intr.CodIntr, 0)) CodIO,
              Coalesce(ies.TipDoc, Coalesce(intr.TipDoc, 0)) TipDocIO,
              CASE WHEN ies.CodIes is not Null THEN 1 ELSE 0 END TipIO,
              (select wme_result from PKG_TREZOR_CODCONTCEC(null, TS.CodBanca, OS.Semnificatie, TS1.Tipdecont, TS1.ObiectTranz, T.an, T.luna)) Cont,
              Coalesce(O_STING_FACT.valoare,0) * Coalesce(NullIF(G_STING_FACT.curs,0),1)/Coalesce(NullIF(t1.curs,0),1) VAL,
              Coalesce(G_STING_FACT.tva,0)     * Coalesce(NullIF(G_STING_FACT.curs,0),1)/Coalesce(NullIF(t1.curs,0),1) TVA,
              CASE WHEN t1.TipTranz = 1 AND Coalesce(g.tva,0) &lt;&gt; 0 THEN '0.2.1.01.9.0.9.1.' ELSE '?' END TaxaE,
              CASE WHEN t1.TipTranz = 1 AND Coalesce(g.tva,0) &lt;&gt; 0 THEN '?' ELSE '1.98.2.01.1.3.0.9.1.' END TaxaI
            FROM trezor t
              INNER JOIN trezor1  t1   ON t.codtrezor = t1.codtrezor
              INNER JOIN general  g    ON g.tipdoc = t.tipdoc AND g.coddoc = t1.codtrezor1
              INNER JOIN obligpif o    ON o.codgeneral = g.codgeneral
              INNER JOIN stingere s    ON s.codstingatorpif = o.codobligpif
              INNER JOIN obligpif os   ON os.codobligpif = s.codstinspif AND OS.SEMNIFICATIE IN (500, 600)
              INNER JOIN general  gs   ON gs.codgeneral = os.codgeneral
              INNER JOIN GENERAL G_STING_FACT ON G_STING_FACT.TIPDOC = GS.TIPDOC AND G_STING_FACT.CODDOC = GS.CODDOC
              INNER JOIN OBLIGPIF O_STING_FACT ON O_STING_FACT.CODGENERAL = G_STING_FACT.CODGENERAL
              INNER JOIN STINGERE S_STING_FACT ON S_STING_FACT.CODSTINGATORPIF = O_STING_FACT.CODOBLIGPIF
              INNER JOIN OBLIGPIF OBLIG_FACT ON OBLIG_FACT.CODOBLIGPIF = S_STING_FACT.CODSTINSPIF
              INNER JOIN GENERAL GENERAL_FACT ON OBLIG_FACT.CODGENERAL = GENERAL_FACT.CODGENERAL
              LEFT JOIN intrari  intr ON intr.codintr = GENERAL_FACT.coddoc and intr.tipdoc = GENERAL_FACT.tipdoc
              LEFT JOIN iesiri   ies  ON ies.codies = GENERAL_FACT.coddoc and ies.tipdoc = GENERAL_FACT.tipdoc
              LEFT JOIN trezor1 ts1 ON ts1.codtrezor1 = gs.coddoc AND gs.tipdoc IN (29,31)
              LEFT JOIN trezor ts ON ts.codtrezor = ts1.codtrezor
            WHERE T.CodTrezor = pCodDoc  AND t1.tiptranz IN (0,1) AND OS.SEMNIFICATIE IN (500, 600)
              AND Coalesce(ies.TVAIncasare, Coalesce(intr.TVAIncasare, 0)) =1
          ) aSub
            LEFT JOIN NCONT                 C ON C.CodCont = aSub.Cont
            LEFT JOIN WINMADMIN.TAXCODESAFT T ON T.Cod     = C.TaxCode
        ) bSub
          LEFT JOIN WINMADMIN.TAXCODE_I TI ON TI.Cod    = TaxaI
          LEFT JOIN WINMADMIN.TAXCODE_E TE ON TE.Cod    = TaxaE
          LEFT JOIN TAXDECL             TD ON TD.TipDoc = bSub.TipDoc AND TD.CodDoc = bSub.CodDoc and TD.CodDoc1 = bSub.CodDoc1
        WHERE (Coalesce(TD.Manual, 0) &lt;&gt; 1)
      ) LOOP
        aValLinie := vRec.ValBaza;
        aTVALinie := vRec.ValTaxa;
        if aTVALinie = 0 and VRec.Procstopaj &lt;&gt; 0 then
          aTVALinie := Round(aValLinie*VRec.Procstopaj/100,2);
        end if;
        aTotBase  := 0;
        aTotVal   := 0;
        IF (vRec.Tvaincasare = 1) THEN
          --DELETE FROM TAXDECL T WHERE T.TipDoc = vRec.TIPDoc AND T.CODDOC = vRec.CODDoc AND T.CODDOC1 = vRec.CODDoc1;
          BEGIN
            SELECT Sum(TaxBase), Sum(TaxVal) INTO aTotBase, aTotVal FROM TaxDecl
            WHERE TipDoc = vRec.TipDocIO AND CodDoc = vRec.CodIO AND CodDoc1 &gt; 0;
          EXCEPTION WHEN OTHERS THEN
            aTotBase := 0; aTotVal := 0;
          END;
          aTotBase := Coalesce(aTotBase,0); aTotVal := Coalesce(aTotVal,0);
          IF (aTotBase + aTotVal) = 0 THEN
            BEGIN
              IF    vRec.TipDocIO &lt; 10 THEN perform pkg_saft_UpdateTaxDecl(0, vRec.CodIO);
              ELSIF vRec.TipDocIO &lt; 27 THEN perform pkg_saft_UpdateTaxDecl(1, vRec.CodIO);
              END IF;
              SELECT Sum(TaxBase), Sum(TaxVal) INTO aTotBase, aTotVal FROM TaxDecl WHERE TipDoc = vRec.TipDocIO and CodDoc = vRec.CodIO;
            EXCEPTION WHEN OTHERS THEN
              aTotBase := 0; aTotVal := 0;
            END;
          END IF;
        END IF;
        IF (vRec.Tvaincasare = 1)and(aTotVal) &lt;&gt; 0 THEN
          KIncas := (aValLinie + aTVALinie)/(aTotBase + aTotVal);
          FOR XRec IN (
            SELECT TaxCode, TVANeded, Sum(TotBase) TotBase, Sum(TotVal) TotVal
            FROM (
              SELECT TaxCode, Coalesce(I1.TVANeded, 0) TVANeded, (TaxBase) TotBase, (TaxVal) TotVal
              FROM TaxDecl T
                INNER JOIN Intrari1 I1 ON I1.Codintr = T.Coddoc and I1.Codintr1 = T.Coddoc1
              WHERE T.TipDoc = vRec.TipDocIO and T.CodDoc = vRec.CodIO
              UNION ALL
              SELECT Tx.Taxcode, Coalesce(I1.TVANeded, 0) TVANeded, Coalesce(-t.TaxBase, 0) TotBase, Coalesce(-t.TaxVal, 0) TotVal
              FROM TaxDecl T
                INNER JOIN Intrari1 I1 ON I1.Codintr = T.Coddoc and I1.Codintr1 = -T.Coddoc1
                LEFT  JOIN TaxDecl Tx ON Tx.Coddoc = I1.Codintr and Tx.Coddoc1 = I1.Codintr1
              WHERE T.TipDoc = vRec.TipDocIO and T.CodDoc = vRec.CodIO
              UNION ALL
              SELECT TaxCode, 0 TVANeded, (TaxBase) TotBase, (TaxVal) TotVal
              FROM TaxDecl T
                INNER JOIN Iesiri1 I1 ON I1.Codies = T.Coddoc and I1.Codies1 = T.Coddoc1
              WHERE T.TipDoc = vRec.TipDocIO and T.CodDoc = vRec.CodIO
              UNION ALL
              SELECT Tx.Taxcode, 0 TVANeded, Coalesce(-t.TaxBase, 0) TotBase, Coalesce(-t.TaxVal, 0) TotVal
              FROM TaxDecl T
                INNER JOIN Iesiri1 I1 ON I1.Codies = T.Coddoc and I1.Codies1 = -T.Coddoc1
                LEFT  JOIN TaxDecl Tx ON Tx.Coddoc = I1.Codies and Tx.Coddoc1 = I1.Codies1
              WHERE T.TipDoc = vRec.TipDocIO and T.CodDoc = vRec.CodIO
            ) subs
            GROUP BY TaxCode, TVANeded
          ) LOOP
            IF ((XRec.Tvaneded = 0)or(xRec.TotBase &lt;&gt; 0)) and ((aValLinie + aTVALinie) &lt;&gt; 0) THEN
              IF vRec.TipTranz = 1  THEN
                IF vRec.ObiectTranz &lt;&gt; 1
                THEN
                  cTaxa := '0.2.1.01.9.0.9.1.'||
                  To_Char(Round(CASE WHEN xRec.Totbase = 0 THEN 0 ELSE 100*xRec.Totval/xRec.Totbase END,0),'FM900');
                  BEGIN
                    SELECT Taxa into aTax FROM WINMADMIN.TAXCODE_E WHERE Cod  = cTaxa;
                  EXCEPTION WHEN OTHERS THEN
                    aTax := 0;
                  END;
                ELSE
                  cTaxa := '1.98.2.01.1.9.0.9.1.'||
                  To_Char(Round(CASE WHEN xRec.Totbase = 0 THEN 0 ELSE 100*xRec.Totval/xRec.Totbase END,0),'FM900')||'.0';
                  BEGIN
                    SELECT Taxa into aTax FROM WINMADMIN.TAXCODE_I WHERE Cod  = cTaxa;
                  EXCEPTION WHEN OTHERS THEN
                    aTax := 0;
                  END;
                END IF;
              ELSE
                IF vRec.ObiectTranz = 1
                THEN
                  cTaxa := '0.2.1.01.9.0.9.1.'||
                  To_Char(Round(CASE WHEN xRec.Totbase = 0 THEN 0 ELSE 100*xRec.Totval/xRec.Totbase END,0),'FM900');
                  BEGIN
                    SELECT Taxa into aTax FROM WINMADMIN.TAXCODE_E WHERE Cod  = cTaxa;
                  EXCEPTION WHEN OTHERS THEN
                    aTax := 0;
                  END;
                ELSE
                  cTaxa := '1.98.2.01.1.9.0.9.1.'||
                  To_Char(Round(CASE WHEN xRec.Totbase = 0 THEN 0 ELSE 100*xRec.Totval/xRec.Totbase END,0),'FM900')||'.0';
                  BEGIN
                    SELECT Taxa into aTax FROM WINMADMIN.TAXCODE_I WHERE Cod  = cTaxa;
                  EXCEPTION WHEN OTHERS THEN
                    aTax := 0;
                  END;
                END IF;
              END IF;
              cKeia     := 'ok - '||cTaxa;
              IF aTax = 0 THEN
                cKeia := '?'||cTaxa;
              END IF;
              BEGIN
                SELECT T.codTaxdecl INTO aCod FROM TAXDECL T
                WHERE T.TipDoc = vRec.TIPDoc AND T.CODDOC = vRec.CODDoc  AND T.CODDOC1 = vRec.CODDoc1 and T.Taxcode = aTax ;
              EXCEPTION WHEN OTHERS THEN
                aCod := 0;
              END;
              IF xRec.TotVal = 0 THEN
                IF aCod &gt; 0 THEN
                  DELETE FROM TAXDECL WHERE codTaxdecl = aCod;
                END IF;
              ELSE
                IF pkg_saft_FirmaPlatitorTVA(aSubunit, aAn, aLuna) = 0 THEN
                  aTax := 0;
                  cKeia := 'neplatitor TVA';
                END IF;
                IF aCod = 0 or aCod is null THEN
                  Semn := +1;
                  IF vRec.ObiectTranz = 1 THEN
                    Semn := -1;
                  END IF;
                  aManual := 0;
                  IF xRec.TotVal = 0 THEN aManual := 2; ELSE aManual := 0; END IF;
                  INSERT INTO TAXDECL(codTaxdecl,        tipdoc,      coddoc,      coddoc1,      TaxCode, TaxBase,                  TaxVal,                  Cheia, Manual,  CodCont,   AnLuna)
                  VALUES(Nextval('SEQ_TAXDECL_CODTAXDECL'), vRec.TIPDOC, vRec.CODDOC, vRec.CODDOC1, aTAX,    Semn*xRec.Totbase*KIncas, Semn*xRec.TotVal*KIncas, cKeia, aManual, vRec.Cont, vRec.AnLuna);
                ELSE
                  UPDATE TAXDECL
                  SET TaxBase = TaxBase + Round(xRec.Totbase*KIncas,2), TaxVal = TaxVal + Round(xRec.TotVal*KIncas,2), CHEIA = cKeia, AnLuna = vRec.AnLuna, TaxCode = aTax, CodCont = vRec.Cont
                  WHERE codTaxdecl = aCod;
                END IF;
              END IF;
            END IF;
          END LOOP;
        ELSIF aTVALinie &lt;&gt; 0 THEN --nu e tva incasare
          aTax      := vRec.Taxa;
          ContTrezor := vRec.Cont;
          if VRec.Procstopaj &lt;&gt; 0 then
            aTax := 0;
            cKeia := 'stopaj';
            ContTrezor := Coalesce(pkg_categconst.GetValConstanta('ContStopNerez' ,aAn,aLuna),'0');
          end if;
          IF vRec.TipTranz = 1  THEN
            IF vRec.ObiectTranz &lt;&gt; 1 THEN cKeia := 'ok - '||vRec.TaxaE;
                                     ELSE cKeia := 'ok - '||vRec.TaxaI;
            END IF;
          ELSE
            IF vRec.ObiectTranz &lt;&gt; 1 THEN cKeia := 'ok - '||vRec.TaxaI;
                                     ELSE cKeia := 'ok - '||vRec.TaxaE;
            END IF;
          END IF;
          IF aTax = 0 and VRec.Procstopaj = 0 THEN
            IF vRec.TipTranz = 1
            THEN cKeia := '?'||vRec.TaxaE;
            ELSE cKeia := '?'||vRec.TaxaI;
            END IF;
          END IF;
          BEGIN
            SELECT T.codTaxdecl INTO aCod FROM TAXDECL T
            WHERE T.TipDoc = vRec.TIPDOC AND T.CODDOC = vRec.CODDOC AND T.CODDOC1 = vRec.CODDOC1 ;
          EXCEPTION WHEN OTHERS THEN
            aCod := 0;
          END;

          IF pkg_saft_FirmaPlatitorTVA(aSubunit, aAn, aLuna) = 0 THEN
            aTax := 0;
            cKeia := 'neplatitor TVA';
          END IF;

          IF Coalesce(aCod, 0) = 0 THEN
            IF vRec.ObiectTranz = 1 THEN
              aValLinie := -aValLinie;
              aTVALinie := -aTVALinie;
            END IF;
            INSERT INTO TAXDECL(codTaxdecl,        tipdoc, coddoc,      coddoc1,      TaxCode, TaxBase,   TaxVal,    Cheia, Manual, CodCont, AnLuna)
            VALUES(Nextval('SEQ_TAXDECL_CODTAXDECL'), vRec.TIPDOC, vRec.CODDOC, vRec.CODDOC1, aTAX,    aValLinie, aTVALinie, cKeia, 0,      ContTrezor, vRec.AnLuna);
          ELSE
            UPDATE TAXDECL
            SET TaxBase = aValLinie, TaxVal = aTVALinie, CHEIA = cKeia, AnLuna = vRec.AnLuna, TaxCode = aTax, CodCont = ContTrezor
            WHERE codTaxdecl = aCod;
          END IF;
        END IF;--nu e tva incasare
      END LOOP;
    END IF;
    ELSIF pCaz = 4 THEN
    SELECT Subunitatea, An, Luna INTO aSubunit, aAn, aLuna
    FROM COMPENS
    WHERE CodCompens = pCodDoc;
    DELETE FROM TaxDecl WHERE TipDoc = 28 AND CodDoc = pCodDoc AND MANUAL = 0 ;
    FOR vRec IN (
    SELECT
      bSub.coddoc, bSub.coddoc1, bSub.tipdoc, bSub.AnLuna,
      Coalesce(TE.Taxa, TI.Taxa, bSub.Taxa) Taxa, bSub.ValBaza, bSub.ValTaxa,
      bSub.cont, bSub.impozit, bSub.Simbol, bSub.TaxCode, bSub.TaxaI, bSub.TaxaE, bSub.Retur, bSub.Debit,
      bSub.TVAIncasare, bSub.CodIO, bSub.TipDocIO, bSub.TipIO
    FROM (
      SELECT
        aSub.CodDoc, aSub.CodDoc1, aSub.tipdoc, aSub.Retur, aSub.Debit,aSub.AnLuna, C.TaxCode Taxa, Round(T.ProcTaxa,0) proc,
        CASE
          WHEN Coalesce(c.impozit,0) = 1 AND Coalesce(T.ProcTaxa,0) = 0 THEN 0
          WHEN Coalesce(c.impozit,0) = 1                                THEN Round(aSub.Val/(T.ProcTaxa/100),2)
          ELSE aSub.Val - aSub.TVA
        END ValBaza,
        CASE WHEN Coalesce(c.impozit,0) = 1 THEN aSub.Val ELSE aSub.TVA END ValTaxa, T.COD TaxCode,
        aSub.TaxaE||To_Char(Round(PKG_LIST_BASE_UTILS_MATCH_TVA_PROC(CASE WHEN aSub.VAL-aSub.TVA = 0 THEN 0 ELSE aSub.TVA/(aSub.VAL-aSub.TVA) END*100, aSub.AnLuna),0),'FM900')       TaxaE,
        aSub.TaxaI||To_Char(Round(PKG_LIST_BASE_UTILS_MATCH_TVA_PROC(CASE WHEN aSub.VAL-aSub.TVA = 0 THEN 0 ELSE aSub.TVA/(aSub.VAL-aSub.TVA) END*100, aSub.AnLuna),0),'FM900')||'.0' TaxaI,
        aSub.cont, Coalesce(c.impozit,0) impozit, c.Simbol, TVAIncasare, aSub.CodIO, aSub.TipDocIO, aSub.TipIO
      FROM (
        SELECT
          t.codcompens coddoc, o.codobligpif coddoc1, 28 tipdoc,
          Case when intr.CodIntr is not null and SIGN(intr.Valdoc) &lt; 0 THEN 1
               when Ies.CodIEs is not null and SIGN(Ies.ValDoc) &lt; 0 THEN 1
               when gs.SEMNIFICATIE IN (310,410) THEN 1
               else 0
          end Retur,
          Case when g.SEMNIFICATIE IN (1300, 1301, 1302, 1303) THEN 1 else 0 end DEBIT,
          T.An*12+T.Luna AnLuna,
          Coalesce(ies.TVAIncasare, Coalesce(intr.TVAIncasare, 0)) TVAIncasare,
          Coalesce(ies.CodIes, Coalesce(intr.CodIntr, 0)) CodIO,
          Coalesce(ies.TipDoc, Coalesce(intr.TipDoc, 0)) TipDocIO,
          CASE WHEN ies.CodIes is not Null THEN 1 ELSE 0 END TipIO,
          CASE
            WHEN o.semnificatie IN (900,901, 950, 951) THEN o.icont
            ELSE (select wme_result from PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(null, o.semnificatie, o.icont, PKG_NOMPART_GET_PART_COD_CARACT_LUNA(o.codpart,t.an,t.luna)))
          END cont,
            Case when G.Moneda = 0 then Coalesce(o.valoare,0) else Coalesce(o.valoare,0)*G.Curs end VAL,
          Case when G.Moneda = 0 then Coalesce(g.tva,0) else Coalesce(g.tva,0)*g.curs end   TVA,
          CASE
          WHEN g.SEMNIFICATIE IN (1300, 1301, 1302, 1303) THEN  '0.2.1.01.9.0.9.1.'    --plata
          ELSE '?'
          END TaxaE,
          CASE
          WHEN g.SEMNIFICATIE IN (1350, 1351, 1352, 1353) THEN '1.98.2.01.1.3.0.9.1.' --incasare
          ELSE '?'
          END TaxaI
        FROM compens t
          LEFT JOIN general  g    ON g.tipdoc = 28 AND g.coddoc = t.codcompens
          LEFT JOIN obligpif o    ON o.codgeneral = g.codgeneral
          LEFT JOIN stingere s    ON s.codstingatorpif = o.codobligpif
          LEFT JOIN obligpif os   ON os.codobligpif = s.codstinspif
          LEFT JOIN general  gs   ON gs.codgeneral = os.codgeneral
          LEFT JOIN intrari  intr ON intr.codintr = gs.coddoc and intr.tipdoc = gs.tipdoc
          LEFT JOIN iesiri   ies  ON ies.codies = gs.coddoc and ies.tipdoc = gs.tipdoc
          LEFT JOIN compens  Cmp   ON Cmp.codcompens = gs.coddoc AND gs.tipdoc = 28
          LEFT JOIN TREZOR1  Tre1 ON Tre1.CODTREZOR1   = gs.CODDOC AND gs.TIPDOC IN (29, 30, 31, 33)
        WHERE T.codcompens = pCodDoc and Coalesce(o.codpart,0) &gt; 0
              and (g.SEMNIFICATIE IN (1300, 1301, 1302, 1303) or g.SEMNIFICATIE IN (1350, 1351, 1352, 1353))
        ) aSub
            LEFT JOIN NCONT                 C ON C.CodCont = aSub.Cont
            LEFT JOIN WINMADMIN.TAXCODESAFT T ON T.Cod     = C.TaxCode
        ) bSub
          LEFT JOIN WINMADMIN.TAXCODE_I TI ON TI.Cod    = TaxaI
          LEFT JOIN WINMADMIN.TAXCODE_E TE ON TE.Cod    = TaxaE
        WHERE ((bsub.TVAIncasare = 1)or(bsub.ValTaxa &lt;&gt; 0))
      ) LOOP
        aValLinie := vRec.ValBaza;
        aTVALinie := vRec.ValTaxa;
        aTotBase  := 0;
        aTotVal   := 0;
        IF (vRec.Tvaincasare = 1) THEN
          --DELETE FROM TAXDECL T WHERE T.TipDoc = vRec.TIPDoc AND T.CODDOC = vRec.CODDoc AND T.CODDOC1 = vRec.CODDoc1;
          BEGIN
            SELECT Sum(TaxBase), Sum(TaxVal) INTO aTotBase, aTotVal FROM TaxDecl
            WHERE TipDoc = vRec.TipDocIO AND CodDoc = vRec.CodIO AND CodDoc1 &gt; 0;
          EXCEPTION WHEN OTHERS THEN
            aTotBase := 0; aTotVal := 0;
          END;
          aTotBase := Coalesce(aTotBase,0); aTotVal := Coalesce(aTotVal,0);
          IF (aTotBase + aTotVal) = 0 THEN
            BEGIN
              IF    vRec.TipDocIO &lt; 10 THEN perform pkg_saft_UpdateTaxDecl(0, vRec.CodIO);
              ELSIF vRec.TipDocIO &lt; 27 THEN perform pkg_saft_UpdateTaxDecl(1, vRec.CodIO);
              END IF;
              SELECT Sum(TaxBase), Sum(TaxVal) INTO aTotBase, aTotVal FROM TaxDecl WHERE TipDoc = vRec.TipDocIO and CodDoc = vRec.CodIO;
            EXCEPTION WHEN OTHERS THEN
              aTotBase := 0; aTotVal := 0;
            END;
          END IF;
        END IF;
        IF (vRec.Tvaincasare = 1)and(aTotVal) &lt;&gt; 0 THEN
          KIncas := (aValLinie + aTVALinie)/(aTotBase + aTotVal);
          FOR XRec IN (
            SELECT TaxCode, TVANeded, Sum(TotBase) TotBase, Sum(TotVal) TotVal
            FROM (
              SELECT TaxCode, Coalesce(I1.TVANeded, 0) TVANeded, (TaxBase) TotBase, (TaxVal) TotVal
              FROM TaxDecl T
                INNER JOIN Intrari  I  ON I .Codintr = T.Coddoc and I.TipDoc = T.TipDoc
                INNER JOIN Intrari1 I1 ON I1.Codintr = I.Codintr and I1.Codintr1 = T.Coddoc1
              WHERE T.TipDoc = vRec.TipDocIO and T.CodDoc = vRec.CodIO
              UNION ALL
              SELECT Tx.Taxcode, Coalesce(I1.TVANeded, 0) TVANeded, Coalesce(-t.TaxBase, 0) TotBase, Coalesce(-t.TaxVal, 0) TotVal
              FROM TaxDecl T
                INNER JOIN Intrari  I  ON I .Codintr = T.Coddoc and I.TipDoc = T.TipDoc
                INNER JOIN Intrari1 I1 ON I1.Codintr = I.Codintr and I1.Codintr1 = -T.Coddoc1
                LEFT  JOIN TaxDecl Tx ON Tx.Coddoc = I1.Codintr and Tx.Coddoc1 = I1.Codintr1
              WHERE T.TipDoc = vRec.TipDocIO and T.CodDoc = vRec.CodIO
              UNION ALL
              SELECT TaxCode, 0 TVANeded, (TaxBase) TotBase, (TaxVal) TotVal
              FROM TaxDecl T
                INNER JOIN Iesiri   I  ON I .Codies = T.Coddoc and I.TipDoc = T.TipDoc
                INNER JOIN Iesiri1 I1 ON I1.Codies = I.Codies and I1.Codies1 = T.Coddoc1
              WHERE T.TipDoc = vRec.TipDocIO and T.CodDoc = vRec.CodIO
              UNION ALL
              SELECT Tx.Taxcode, 0 TVANeded, Coalesce(-t.TaxBase, 0) TotBase, Coalesce(-t.TaxVal, 0) TotVal
              FROM TaxDecl T
                INNER JOIN Iesiri   I  ON I .Codies = T.Coddoc and I.TipDoc = T.TipDoc
                INNER JOIN Iesiri1 I1 ON I1.Codies = I.Codies and I1.Codies1 = -T.Coddoc1
                LEFT  JOIN TaxDecl Tx ON Tx.Coddoc = I1.Codies and Tx.Coddoc1 = I1.Codies1
              WHERE T.TipDoc = vRec.TipDocIO and T.CodDoc = vRec.CodIO
            ) subs
            GROUP BY TaxCode, TVANeded
          ) LOOP
            IF ((XRec.Tvaneded = 0)or(xRec.TotBase &lt;&gt; 0)) and ((aValLinie + aTVALinie) &lt;&gt; 0) THEN
              IF vRec.Debit = 1 then
               if vRec.Retur = 0  THEN
                  cTaxa := '1.98.2.01.1.9.0.9.1.'||
                  To_Char(Round(CASE WHEN xRec.Totbase = 0 THEN 0 ELSE 100*xRec.Totval/xRec.Totbase END,0),'FM900')||'.0';
                  BEGIN
                    SELECT Taxa into aTax FROM WINMADMIN.TAXCODE_I WHERE Cod  = cTaxa;
                  EXCEPTION WHEN OTHERS THEN
                    aTax := 0;
                  END;
              ELSE
                  cTaxa := '0.2.1.01.9.0.9.1.'||
                  To_Char(Round(CASE WHEN xRec.Totbase = 0 THEN 0 ELSE 100*xRec.Totval/xRec.Totbase END,0),'FM900');
                  BEGIN
                    SELECT Taxa into aTax FROM WINMADMIN.TAXCODE_E WHERE Cod  = cTaxa;
                  EXCEPTION WHEN OTHERS THEN
                    aTax := 0;
                  END;
                end if;
              ELSE
                  if vRec.Retur = 0 then
                    cTaxa := '0.2.1.01.9.0.9.1.'||
                    To_Char(Round(CASE WHEN xRec.Totbase = 0 THEN 0 ELSE 100*xRec.Totval/xRec.Totbase END,0),'FM900');
                    BEGIN
                      SELECT Taxa into aTax FROM WINMADMIN.TAXCODE_E WHERE Cod  = cTaxa;
                    EXCEPTION WHEN OTHERS THEN
                      aTax := 0;
                    END;
                  else
                    cTaxa := '1.98.2.01.1.9.0.9.1.'||
                    To_Char(Round(CASE WHEN xRec.Totbase = 0 THEN 0 ELSE 100*xRec.Totval/xRec.Totbase END,0),'FM900')||'.0';
                    BEGIN
                      SELECT Taxa into aTax FROM WINMADMIN.TAXCODE_I WHERE Cod  = cTaxa;
                    EXCEPTION WHEN OTHERS THEN
                      aTax := 0;
                    END;
                  end if;
              END IF;
              cKeia     := 'ok - '||cTaxa;
              IF aTax = 0 THEN
                cKeia := '?'||cTaxa;
              END IF;
              BEGIN
                SELECT T.codTaxdecl INTO aCod FROM TAXDECL T
                WHERE T.TipDoc = vRec.TIPDoc AND T.CODDOC = vRec.CODDoc  AND T.CODDOC1 = vRec.CODDoc1 and T.Taxcode = aTax ;
              EXCEPTION WHEN OTHERS THEN
                aCod := 0;
              END;
              IF xRec.TotVal = 0 THEN
                IF aCod &gt; 0 THEN
                  DELETE FROM TAXDECL WHERE codTaxdecl = aCod;
                END IF;
              ELSE
                IF pkg_saft_FirmaPlatitorTVA(aSubunit, aAn, aLuna) = 0 THEN
                  aTax := 0;
                  cKeia := 'neplatitor TVA';
                END IF;
                IF vRec.Retur = 1 THEN
                  Semn := -1;
                ELSE
                  Semn := +1;
                END IF;

                IF aCod = 0 or aCod is null THEN
                  aManual := 0;
                  IF xRec.TotVal = 0 THEN aManual := 2; ELSE aManual := 0; END IF;
                  INSERT INTO TAXDECL(codTaxdecl,        tipdoc,      coddoc,      coddoc1,      TaxCode, TaxBase,                  TaxVal,                  Cheia, Manual,  CodCont,   AnLuna)
                  VALUES(Nextval('SEQ_TAXDECL_CODTAXDECL'), vRec.TIPDOC, vRec.CODDOC, vRec.CODDOC1, aTAX,    Semn*xRec.Totbase*KIncas, Semn*xRec.TotVal*KIncas, cKeia, aManual, vRec.Cont, vRec.AnLuna);
                ELSE
                  UPDATE TAXDECL
                  SET TaxBase = TaxBase + Semn*Round(xRec.Totbase*KIncas,2), TaxVal = TaxVal + Semn*Round(xRec.TotVal*KIncas,2), CHEIA = cKeia, AnLuna = vRec.AnLuna, TaxCode = aTax, CodCont = vRec.Cont
                  WHERE codTaxdecl = aCod;
                END IF;
              END IF;
            END IF;
          END LOOP;
        ELSIF aTVALinie &lt;&gt; 0 THEN --nu e tva incasare
          aTax      := vRec.Taxa;
/*
          IF vRec.Debit = 0  THEN
              cTaxa := '1.98.2.01.1.9.0.9.1.'||
              To_Char(Round(CASE WHEN xRec.Totbase = 0 THEN 0 ELSE 100*xRec.Totval/xRec.Totbase END,0),'FM900')||'.0';
              BEGIN
                SELECT Taxa into aTax FROM WINMADMIN.TAXCODE_I WHERE Cod  = cTaxa;
              EXCEPTION WHEN OTHERS THEN
                aTax := 0;
              END;
          ELSE
              cTaxa := '0.2.1.01.9.0.9.1.'||
              To_Char(Round(CASE WHEN xRec.Totbase = 0 THEN 0 ELSE 100*xRec.Totval/xRec.Totbase END,0),'FM900');
              BEGIN
                SELECT Taxa into aTax FROM WINMADMIN.TAXCODE_E WHERE Cod  = cTaxa;
              EXCEPTION WHEN OTHERS THEN
                aTax := 0;
              END;
          END IF;
          cKeia     := 'ok - '||cTaxa;
*/
          IF aTax = 0 THEN
           cKeia := '?'||cTaxa;
          END IF;
          BEGIN
            SELECT T.codTaxdecl INTO aCod FROM TAXDECL T
            WHERE T.TipDoc = vRec.TIPDOC AND T.CODDOC = vRec.CODDOC AND T.CODDOC1 = vRec.CODDOC1 ;
          EXCEPTION WHEN OTHERS THEN
            aCod := 0;
          END;

          IF pkg_saft_FirmaPlatitorTVA(aSubunit, aAn, aLuna) = 0 THEN
            aTax := 0;
            cKeia := 'neplatitor TVA';
          END IF;

          IF vRec.Retur = 1 THEN
              aValLinie := -aValLinie;
              aTVALinie := -aTVALinie;
          END IF;
          IF Coalesce(aCod, 0) = 0 THEN
            INSERT INTO TAXDECL(codTaxdecl,        tipdoc, coddoc,      coddoc1,      TaxCode, TaxBase,   TaxVal,    Cheia, Manual, CodCont,   AnLuna)
            VALUES(Nextval('SEQ_TAXDECL_CODTAXDECL'), vRec.TIPDOC, vRec.CODDOC, vRec.CODDOC1, aTAX,    aValLinie, aTVALinie, cKeia, 0,      vRec.Cont, vRec.AnLuna);
          ELSE
            UPDATE TAXDECL
            SET TaxBase = aValLinie, TaxVal = aTVALinie, CHEIA = cKeia, AnLuna = vRec.AnLuna, TaxCode = aTax, CodCont = vRec.Cont
            WHERE codTaxdecl = aCod;
          END IF;
        END IF;--nu e tva incasare
     END LOOP;
  END IF;

END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_soldinitial_sp_deleterecord</obj_name>
  <obj_hashval>29f5dea91f3907f4988302b018e1368c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_soldinitial_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC       RECORD;
  V_REC_TREZ1 RECORD;
  V_REC_O     RECORD;
  aCODPART    numeric;
  ANI         numeric;
  LUNAI       numeric;
BEGIN
    --Laura 17.12.2021 - sinc. Oracle (16.12.2021)
  --Florin 03.03.2021 - fixat 44307
  PERFORM PKG_SOLDINITIAL_SP_LOCKRECORD(RecId);

  SELECT CODPART INTO aCODPART FROM SOLDINI WHERE CODSOLDINI = RecID;

  DELETE FROM TMP_GENERAL;
  DELETE FROM TMP_GENERAL_LITIGII;
  DELETE FROM TMP_OBLIGVAMA_INITIAL;
  DELETE FROM TMP_STINGERE_ASOCIAT;

  INSERT INTO TMP_GENERAL_LITIGII (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT G.CODGENERAL, G.TIPDOC, G.CODDOC, G.MONEDA, G.CURS, G.TVA, G.SEMNIFICATIE
  FROM GENERAL G, COMPENS C
  WHERE
    G.TIPDOC IN (28)        AND
    C.CODCOMPENS = G.CODDOC AND
    C.PARTD = aCODPART      AND
    C.PARTC = aCODPART      AND
    C.AN * 12 + C.LUNA &lt; current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric * 12 + current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric AND
    G.SEMNIFICATIE = 1350;

  INSERT INTO TMP_OBLIGVAMA_INITIAL (CODOBLIGPIF, CODGENERAL, VALOARE, CODPART, ICONT, SEMNIFICATIE)
  SELECT CODOBLIGPIF, CODGENERAL, VALOARE, CODPART, ICONT, SEMNIFICATIE
  FROM OBLIGPIF O
  WHERE EXISTS (SELECT CODGENERAL FROM TMP_GENERAL_LITIGII WHERE CODGENERAL = O.CODGENERAL);

  INSERT INTO TMP_STINGERE_ASOCIAT (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
  SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE
  FROM STINGERE S
  WHERE EXISTS (SELECT CODOBLIGPIF FROM TMP_OBLIGVAMA_INITIAL WHERE CODOBLIGPIF = S.CODSTINGATORPIF);

  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
  FROM GENERAL G, COMPENS C
  WHERE
     SEMNIFICATIE = 1303     AND
     TIPDOC IN (28)          AND
     C.CODCOMPENS = G.CODDOC AND
     C.PARTD = aCODPART      AND
     C.PARTC = aCODPART      AND
     C.AN * 12 + C.LUNA &lt; current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric * 12 + current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric;

  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
  FROM GENERAL G
  WHERE
    (  (TIPDOC IN (1, 2, 3, 4, 9))  OR (TIPDOC = 5 AND  SEMNIFICATIE &lt;&gt; 130) )  AND
    (SELECT PARTENER FROM INTRARI I WHERE CODINTR = G.CODDOC) = aCODPART        AND
    (SELECT I.AN * 12 + I.LUNA FROM INTRARI I WHERE CODINTR = G.CODDOC) &lt; current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric * 12 + current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric;

  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, FARAREG)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, FARAREG
  FROM GENERAL G
  WHERE
     TIPDOC = 5 AND
     SEMNIFICATIE = 130 AND
     (SELECT CODVAMA FROM DVI D WHERE CODDVI = G.CODDOC) = aCODPART AND
     (SELECT I.AN * 12 + I.LUNA FROM INTRARI I, DVI D WHERE CODDVI = G.CODDOC AND  D.CODINTR = I.CODINTR) &lt; current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric * 12 + current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric;

  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
  FROM GENERAL G
  WHERE
    TIPDOC IN (19, 20, 21, 22, 26) AND
    (SELECT PARTENER FROM IESIRI I WHERE CODIES = G.CODDOC) = aCODPART AND
    (SELECT I.AN * 12 + I.LUNA FROM IESIRI I WHERE CODIES = G.CODDOC) &lt; current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric * 12 + current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric;

  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
  FROM GENERAL G
  WHERE
    TIPDOC IN (29, 30, 31, 33) AND
    SEMNIFICATIE NOT IN (300, 400, 500, 600, 800, 801) AND
    (SELECT CODPART FROM TREZOR1 T WHERE CODTREZOR1 = G.CODDOC) = aCODPART AND
    (SELECT T.AN * 12 + T.LUNA FROM TREZOR1 T WHERE CODTREZOR1 = G.CODDOC) &lt; current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric * 12 + current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric;

  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS)
  SELECT G.CODGENERAL, G.TIPDOC, G.CODDOC, G.MONEDA, G.CURS, G.TVA, G.SEMNIFICATIE, G.ICONTAVANS, G.PROCTVAAVANS
  FROM GENERAL G, NC1 N1, NC N
  WHERE
     G.TIPDOC = 35 AND
     G.SEMNIFICATIE IN (1200, 1201) AND
     N1.CODNC1 = G.CODDOC AND
     N.CODNC = N1.CODNC AND
     N.PART = aCODPART AND
     N.AN * 12 + N.LUNA &lt; current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric * 12 + current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric;

  DELETE FROM TMP_OBLIGPIF;
  INSERT INTO TMP_OBLIGPIF (CODOBLIGPIF)
  SELECT CODOBLIGPIF FROM OBLIGPIF WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL);

  DELETE FROM TMP_GENERAL_CECURI;
  INSERT INTO TMP_GENERAL_CECURI (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
  FROM GENERAL G
  WHERE
     TIPDOC = 31 AND SEMNIFICATIE IN (500, 600) AND (SELECT CODPART FROM TREZOR1 T WHERE CODTREZOR1 = G.CODDOC) = aCODPART AND
     (SELECT T.AN * 12 + T.LUNA FROM TREZOR1 T WHERE CODTREZOR1 = G.CODDOC) &lt; current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric * 12 + current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric;

  DELETE FROM TMP_TREZOR1;
  INSERT INTO TMP_TREZOR1 (CODTREZOR1, CODTREZOR, INDEXLOCAL, TIPTRANZ, CARNETDOC, DOC, NRDOC, DATADOC, VALDOC, CURS, COMISION, OBIECTTRANZ, CODPART, CODBANCA, TIPDECONT, DATADECONT, AN, LUNA, OBS, AGENT, ANULAT, INFOCONTBANCAR, SUBUNITATEA)
  SELECT T1.CODTREZOR1, T1.CODTREZOR, INDEXLOCAL, T1.TIPTRANZ, T1.CARNETDOC, T1.DOC, T1.NRDOC, T1.DATADOC, VALDOC, CURS, COMISION, OBIECTTRANZ, CODPART, T.CODBANCA, TIPDECONT, DATADECONT, T1.AN, T1.LUNA, T1.OBS, T1.AGENT, ANULAT, coalesce(BK.SIMBOL,'') || '/' || coalesce(BC.NRCONT::varchar ,'') || coalesce(CHR(13),'') || coalesce(M.SIMBOL,''), T.SUBUNITATEA
  FROM TREZOR1 T1
      INNER JOIN TREZOR T ON  T.CODTREZOR = T1.CODTREZOR
      LEFT JOIN NBANKCONT BC ON  BC.CODBANKCONT = T.CODBANCA
      LEFT JOIN NBANK BK ON  BK.CODBANK = BC.CODBANK
      LEFT JOIN NMONEDE M ON  M.CODMONEDA = BC.CODMONEDA
  WHERE
    CODTREZOR1 IN (SELECT CODDOC FROM TMP_GENERAL_CECURI);

  INSERT INTO TMP_GENERAL_CECURI (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
  FROM GENERAL G
  WHERE
     TIPDOC = 31 AND SEMNIFICATIE IN (300, 400) AND CODDOC IN (SELECT CODTREZOR1 FROM TMP_TREZOR1);

  INSERT INTO TMP_OBLIGPIF_ASOCIAT (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODTREZOR1)
  SELECT CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA,
         (SELECT  DISTINCT CODTREZOR1 FROM TMP_TREZOR1 T1, TMP_GENERAL_CECURI G WHERE G.CODGENERAL = OB.CODGENERAL AND  T1.CODTREZOR1 = G.CODDOC)
  FROM (SELECT * FROM OBLIGPIF WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL_CECURI) ) OB
  ORDER BY CODOBLIGPIF ;

  DELETE FROM TMP_STINGERE;
  INSERT INTO TMP_STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
  (SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE
  FROM STINGERE
  WHERE
    CODSTINSPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF) AND CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF_ASOCIAT));

  DELETE FROM STINGERE WHERE CODSTINGERE IN (SELECT CODSTINGERE FROM TMP_STINGERE);
  DELETE FROM OBLIGPIF WHERE CODOBLIGPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF_ASOCIAT);
  DELETE FROM GENERAL  WHERE CODGENERAL  IN (SELECT CODGENERAL  FROM TMP_GENERAL_CECURI);
  DELETE FROM STINGERE S WHERE EXISTS (SELECT CODSTINGERE FROM TMP_STINGERE_ASOCIAT  WHERE CODSTINGERE = S.CODSTINGERE);
  DELETE FROM OBLIGPIF O WHERE EXISTS (SELECT CODOBLIGPIF FROM TMP_OBLIGVAMA_INITIAL WHERE CODOBLIGPIF = O.CODOBLIGPIF);
  DELETE FROM GENERAL  G WHERE EXISTS (SELECT CODGENERAL  FROM TMP_GENERAL_LITIGII   WHERE CODGENERAL = G.CODGENERAL);

  FOR V_REC IN (SELECT * FROM TMP_TREZOR1) LOOP
    DELETE FROM TREZOR  WHERE CODTREZOR = V_REC.CODTREZOR;
    DELETE FROM TREZOR1 WHERE CODTREZOR1 = V_REC.CODTREZOR1;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_GENERAL) LOOP
    IF V_REC.TIPDOC IN (1, 2, 3, 4, 5, 9) THEN
      DELETE FROM INTRARI1 WHERE CODINTR = V_REC.CODDOC;
    ELSE
      IF V_REC.TIPDOC IN (19, 20, 21, 22, 26) THEN
        DELETE FROM IESIRI1 WHERE CODIES = V_REC.CODDOC;
      ELSE
        IF V_REC.TIPDOC IN (29, 30, 31, 33) THEN
          FOR V_REC_TREZ1 IN (SELECT * FROM TREZOR1 WHERE CODTREZOR1 = V_REC.CODDOC) LOOP
            DELETE FROM TREZOR1 WHERE CODTREZOR1 = V_REC_TREZ1.CODTREZOR1;
          END LOOP;
        ELSE
          IF V_REC.TIPDOC IN (28) THEN
            DELETE FROM COMPENS WHERE CODCOMPENS = V_REC.CODDOC;
          ELSE
            IF V_REC.TIPDOC IN (35) THEN
              DELETE FROM NC1 WHERE CODNC1 = V_REC.CODDOC;
            END IF;
          END IF;
        END IF;
      END IF;
    END IF;

    FOR V_REC_O IN (SELECT * FROM OBLIGPIF WHERE CODGENERAL = V_REC.CODGENERAL) LOOP
      DELETE FROM OBLIGPIFLUNA WHERE CODOBLIGPIF = V_REC_O.CODOBLIGPIF;
      DELETE FROM OBLIGPIF     WHERE CODOBLIGPIF = V_REC_O.CODOBLIGPIF;
    END LOOP;

    DELETE FROM GENERAL WHERE CODGENERAL = V_REC.CODGENERAL;
  END LOOP;

  SELECT newAn, newluna INTO ANI, LUNAI
  FROM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA(current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric, current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric, ANI, LUNAI);

  DELETE FROM NPARTSOLDLUNA    WHERE CODPART = aCODPART AND  AN = ANI AND  LUNA = LUNAI;
  DELETE FROM NPARTSOLDLUNASUB WHERE CODPART = aCODPART AND  AN = ANI AND  LUNA = LUNAI;
  DELETE FROM SOLDINI          WHERE CODSOLDINI = RECID;

  PERFORM NotifyModif(2, RecId, 'SOLDINI');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_venitavans_ini_sp_postrecords</obj_name>
  <obj_hashval>f04fde3ebc56bcb2f847b17b8d5d06a3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_venitavans_ini_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC   RECORD;
  ACODIES numeric;
  ACOD    numeric;
  ANI     numeric := 0;
  LUNAI   numeric := 0;
  NR      numeric := 0;
BEGIN
  IF  OPERATION = 0 THEN
    SELECT CODIES1 INTO RECID FROM TMP_MASTERCHELTAVANS;

    FOR V_REC IN (SELECT * FROM TMP_CHELTAVANS) LOOP
      UPDATE CHELTAVANS
      SET
      ANINCEPUT   = V_REC.ANINCEPUT,
      LUNAINCEPUT = V_REC.LUNAINCEPUT,
      CODIOART    = V_REC.CODIOART,
      DATASTART   = V_REC.DATASTART,
      DATAEND     = V_REC.DATAEND,
      OBSERVATII  = V_REC.OBSERVATII,
      ISVENIT     = 1
      WHERE
       CODCHELTAVANS = V_REC.CODCHELTAVANS;

      UPDATE IESIRI
      SET
      PARTENER    = V_REC.CODPART,
      SUBUNITATEA = V_REC.CODSUBUNIT,
      NRDOC       = V_REC.NRDOC,
      DATADOC     = V_REC.DATADOC,
      SERIADOC    = V_REC.SERIADOC
      WHERE
       CODIES = V_REC.CODINTR;

      UPDATE IESIRI1
      SET
      CODOBIECT = V_REC.CODOBIECT,
      GESTACT   = V_REC.CODGEST,
      CONTSERV  = V_REC.CONTSERV,
      CANT      = 1,
      OBS       = V_REC.OBS,
      PU        = (SELECT VALOARE FROM TMP_CHELTAVANS1)
      WHERE
       CODIES1 = V_REC.CODIES1;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_CHELTAVANS1) LOOP
      UPDATE CHELTAVANS1
      SET
      VALOARE   = V_REC.VALOARE,
      DURATAN   = V_REC.DURATAN,
      DURATAF   = V_REC.DURATAF,
      DFBLOCAT  = V_REC.DFBLOCAT,
      AMO       = V_REC.AMO,
      ANSTART   = V_REC.ANSTART,
      LUNASTART = V_REC.LUNASTART
      WHERE
       CODCHELTAVANS1 = V_REC.CODCHELTAVANS1;

      UPDATE CHELTAVANS1
      SET
      VALOARE = V_REC.VALOARE
      WHERE
       CODCHELTAVANS = V_REC.CODCHELTAVANS AND  ANSTART * 12 + LUNASTART &gt; V_REC.ANSTART * 12 + V_REC.LUNASTART;
    END LOOP;
  ELSE
    PERFORM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA(current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric, current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric, ANI, LUNAI);

    SELECT NEXTVAL('SEQ_IESIRI1_CODIES1') INTO RecId;
    SELECT NEXTVAL('SEQ_IESIRI_CODIES')   INTO aCODIES;

    INSERT INTO MASTERCHELTAVANS(CODIES1) VALUES(RECID);

    INSERT INTO IESIRI(CODIES, TIPDOC, ANULAT, OPERAT, NRDOC, DATADOC, PARTENER, SUBUNITATEA, INITIALIZARI, AN, LUNA, SERIADOC, PREFIXDOC)
    (SELECT aCODIES, 19, 0, 1, NRDOC, DATADOC, CODPART, CODSUBUNIT, 1, ANI, LUNAI, SERIADOC, 'F' FROM TMP_CHELTAVANS);

    INSERT INTO IESIRI1(CODIES1, CODIES, TIPLINIE, CONTSERV, GESTACT, CODOBIECT, PU, CANT, OBS)
    (SELECT RECID, aCODIES, 'S', CONTSERV, CODGEST, CODOBIECT, (SELECT VALOARE FROM TMP_CHELTAVANS1), 1, OBS FROM TMP_CHELTAVANS);

    SELECT NEXTVAL('SEQ_CHELTAVANS_CODCHELTAVANS') INTO ACOD;

    UPDATE TMP_CHELTAVANS1 SET CODCHELTAVANS = ACOD;
    UPDATE TMP_JURNAL      SET CODDOC = aCOD, INDEXLOCAL = aCOD;
    UPDATE TMP_JURNAL1     SET CODDOC = aCOD, INDEXLOCAL = aCOD, IContBazaD = aCOD, IContBazaC = aCOD;

    INSERT INTO CHELTAVANS(CODCHELTAVANS, CODIES1, ANINCEPUT, LUNAINCEPUT, CODIOART, DATASTART, DATAEND, OBSERVATII, ISVENIT)
    (SELECT ACOD, RECID, ANINCEPUT, LUNAINCEPUT, CODIOART, DATASTART, DATAEND, OBSERVATII, 1 FROM TMP_CHELTAVANS);

    INSERT INTO CHELTAVANS1(CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, AMO, ANSTART, LUNASTART)
    (SELECT NEXTVAL('SEQ_CHELTAVANS1_CODCHELTAVANS1'), CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, AMO, ANSTART, LUNASTART FROM TMP_CHELTAVANS1);
  END IF;

  DELETE FROM JURNAl1 J1
  WHERE
   TIPDOC = 106 AND
   AN     = current_setting('PKG_GLOBALS.ANLUCRU'  , true)::numeric AND
   LUNA   = current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric AND
   EXISTS (SELECT CODMIFIX FROM TMP_MIFIX_INITIAL WHERE CODMIFIX = J1.CODDOC) AND
   NOT  EXISTS (SELECT CODJURNAL1 FROM TMP_JURNAl1 WHERE CODJURNAL1 = J1.CODJURNAL1);

  FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
    IF  V_REC.CODJURNAL1 &gt; 0 THEN
      UPDATE JURNAL1
      SET
      CODDOC        = V_REC.CODDOC,
      TIPDOC        = V_REC.TIPDOC,
      INDEXLOCAL    = V_REC.INDEXLOCAL,
      CODBAZAD      = V_REC.CODBAZAD,
      ICONTBAZAD    = V_REC.ICONTBAZAD,
      TIPBAZAD      = V_REC.TIPBAZAD,
      CODBAZAC      = V_REC.CODBAZAC,
      ICONTBAZAC    = V_REC.ICONTBAZAC,
      TIPBAZAC      = V_REC.TIPBAZAC,
      CODDESCRD     = V_REC.CODDESCRD,
      ICONTD        = V_REC.ICONTD,
      TIPCONTD      = V_REC.TIPCONTD,
      ANALITICCONTD = V_REC.ANALITICCONTD,
      CODDESCRC     = V_REC.CODDESCRC,
      ICONTC        = V_REC.ICONTC,
      TIPCONTC      = V_REC.TIPCONTC,
      ANALITICCONTC = V_REC.ANALITICCONTC,
      GEST          = V_REC.GEST,
      VALOARE       = V_REC.VALOARE,
      VALOAREV      = V_REC.VALOAREV,
      OBS           = V_REC.OBS,
      AN            = V_REC.AN,
      LUNA          = V_REC.LUNA,
      SUBUNITATEA   = V_REC.SUBUNITATEA,
      DATADOC       = V_REC.DATADOC,
      DOCUMENT      = V_REC.DOCUMENT
      WHERE
       CODJURNAL1 = V_REC.CODJURNAl1;
    ELSE
      INSERT INTO JURNAL1(CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD, CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, DOCUMENT)
      VALUES(NEXTVAL('SEQ_JURNAL1_CODJURNAL1'), V_REC.CODDOC, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CODBAZAD, V_REC.ICONTBAZAD, V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD, V_REC.CODBAZAC, V_REC.ICONTBAZAC, V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT);
    END IF;
  END LOOP;

  DELETE FROM JURNAL J
  WHERE
   TIPDOC = 106 AND
   AN     = current_setting('PKG_GLOBALS.ANLUCRU'  , true)::numeric AND
   LUNA   = current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric AND
   EXISTS (SELECT CODMIFIX FROM TMP_MIFIX_INITIAL WHERE CODMIFIX = J.CODDOC) AND
   NOT  EXISTS (SELECT CODJURNAL FROM TMP_JURNAL WHERE CODJURNAL = J.CODJURNAL);

  FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
    IF  V_REC.CODJURNAL &gt; 0 THEN
      UPDATE JURNAL
      SET
      CODDOC      = V_REC.CODDOC,
      TIPDOC      = V_REC.TIPDOC,
      INDEXLOCAL  = V_REC.INDEXLOCAL,
      CONTD       = V_REC.CONTD,
      CONTC       = V_REC.CONTC,
      GEST        = V_REC.GEST,
      VALOARE     = V_REC.VALOARE,
      VALOAREV    = V_REC.VALOAREV,
      OBS         = V_REC.OBS,
      AN          = V_REC.AN,
      LUNA        = V_REC.LUNA,
      SUBUNITATEA = V_REC.SUBUNITATEA,
      DATADOC     = V_REC.DATADOC,
      DOCUMENT    = V_REC.DOCUMENT
      WHERE
       CODJURNAL = V_REC.CODJURNAl;
    ELSE
      INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, DATADOC, DOCUMENT)
      VALUES(NEXTVAL('SEQ_JURNAL_CODJURNAL'), V_REC.CODDOC, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT);
    END IF;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP
    SELECT COUNT(*) INTO NR FROM NCONTRUL
    WHERE
     CODCONT = V_REC.CODCONT AND
     AN      = current_setting('PKG_GLOBALS.ANLUCRU'  , true)::numeric AND
     LUNA    = current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric;

    IF  NR = 0 THEN
      INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
      VALUES(NEXTVAL('SEQ_NCONTRUL_CODCONTRUL'), V_REC.CODCONT, 0, 0, 0, 0, 0, 0, 0, 0, current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric, current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric);
    END IF;

    UPDATE NCONTRUL
    SET
    RULAJCD  = RULAJCD  + (CASE WHEN  V_REC.TIP = 'D' THEN V_REC.VALOARE  ELSE 0 END ) ,
    RULAJCC  = RULAJCC  + (CASE WHEN  V_REC.TIP = 'C' THEN V_REC.VALOARE  ELSE 0 END ) ,
    RULAJVCD = RULAJVCD + (CASE WHEN  V_REC.TIP = 'D' THEN V_REC.VALOAREV ELSE 0 END ) ,
    RULAJVCC = RULAJVCC + (CASE WHEN  V_REC.TIP = 'C' THEN V_REC.VALOAREV ELSE 0 END )
    WHERE
     CODCONT = V_REC.CODCONT AND
     AN      = current_setting('PKG_GLOBALS.ANLUCRU'  , true)::numeric AND
     LUNA    = current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric;
  END LOOP;

  PERFORM PKG_GLOBALS_MarkDirtyJurnal();
  PERFORM NotifyModif(Operation, RecId, 'MASTERCHELTAVANS');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>remake_all_sequences</obj_name>
  <obj_hashval>017d22164d5b5ebccc2d9cc596136359</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION remake_all_sequences(nume_schema character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
 DECLARE
   V_REC RECORD;
   newVal numeric;
   s character varying;
BEGIN
  --Florin 08.09.2021 - sinc.Oracle (07.09.2021)
  -- STEF 13.08.2020 OBSOLETE se va sterge sa ramana doar pkg_remake_sequences_remake_all_sequences
  FOR V_REC IN
  (
  SELECT
    sequence,
    seq.table_name,
    COALESCE(SEQ.column_name, COL.Column_Name) AS COLUMN_NAME
  FROM
    INFORMATION_SCHEMA.COLUMNS COL,
  (
    SELECT
      upper(relname) as sequence,
      CASE
        WHEN upper(relname) = 'SEQ_ALERTA_INFO_CODALERTEINFO'  THEN 'ALERTE_INFO'
        WHEN upper(relname) = 'SEQ_ALERTA_INFO_RULARE'         THEN 'ALERTE_INFO'
        WHEN upper(relname) = 'SEQ_AUTORIZATII_CODAUTORIZATII' THEN 'NAUTORIZATIIAUTO'
        WHEN upper(relname) = 'SEQ_BALSTOCREST_COD'            THEN 'BAL_STOC_REST'
        WHEN upper(relname) = 'SEQ_COMANDA1_CODCOMANDA2'       THEN 'COMANDA2' -- CRED CA SAU DENUMIT ERONAT ASA
        WHEN upper(relname) = 'SEQ_COMANDA2_CODCOMANDA3'       THEN 'COMANDA3' -- CRED CA SAU DENUMIT ERONAT ASA
        WHEN upper(relname) = 'SEQ_DESCRIP_CODDESCRIPTOR'      THEN 'DESCRIPTORI'
        WHEN upper(relname) = 'SEQ_DESCRIPT1_CODDESCRIPTOR1'   THEN 'DESCRIPTORI1'
        WHEN upper(relname) = 'SEQ_DPP_CODDIFPRETPROD'         THEN 'DIFPRETPROD'
        WHEN upper(relname) = 'SEQ_DPP1_CODDIFPRETPROD1'       THEN 'DIFPRETPROD1'
        WHEN upper(relname) = 'SEQ_ETICHCOLET_COD'             THEN 'NARTOBJCOLET'
        WHEN upper(relname) = 'SEQ_ESTPROD1M_CODESTPROD1M'     THEN 'ESTIMARIPROD1M'
        WHEN upper(relname) = 'SEQ_ESTPROD1M_CODESTPROD1M'     THEN 'ESTIMARIPROD1M'
        WHEN upper(relname) = 'SEQ_ESTPROD1N_CODESTPROD1N'     THEN 'ESTIMARIPROD1N'
        WHEN upper(relname) = 'SEQ_IESIRIR_CODIESR'            THEN 'IESIRIRETAIL'
        WHEN upper(relname) = 'SEQ_IESIRI1R_CODIES1R'          THEN 'IESIRI1RETAIL'
        WHEN upper(relname) = 'SEQ_MEDEXT_CODMEDEXT'           THEN 'MEDEX_TARI'
        WHEN upper(relname) = 'SEQ_NELEMAERO_CODELEMAERO'      THEN 'NELEMAEROAUTO'
        WHEN upper(relname) = 'SEQ_NINTERV_CODINTERV'          THEN 'NINTERVENTIIAUTO'
        WHEN upper(relname) = 'SEQ_NPARTCODFISC_COD_CODFISCAL' THEN 'NPARTCODFISC'
        WHEN upper(relname) = 'SEQ_NPARTLC_CODNPARTLC'         THEN 'NPARTLSTCLASE'
        WHEN upper(relname) = 'SEQ_PARAMLISTE'                 THEN 'PARAMLISTE'
        WHEN upper(relname) = 'SEQ_PMP_ALL_LUNA'               THEN 'PMP_ALL_LUNA'
        WHEN upper(relname) = 'SEQ_PRELPRET_RETAIL'            THEN 'SYNCPRETRETAIL'
        WHEN upper(relname) = 'SEQ_PROCACTDATE_CODPROCACT'     THEN 'PROC_ACT_DATE'
        WHEN upper(relname) = 'SEQ_PROCACTDATE1_CODPROCACT1'   THEN 'PROC_ACT_DATE1'
        WHEN upper(relname) = 'SEQ_PROCACTDEF_CODPROCDEF'      THEN 'PROC_ACT_DEF'
        WHEN upper(relname) = 'SEQ_RAPSTOCMEDIST'              THEN 'RAPSTOCMEDIST'
        WHEN upper(relname) = 'SEQ_RESTOBIECTE_COD'            THEN 'RESTOBIECT'
        WHEN upper(relname) = 'SEQ_SYSNPRETRETAIL_CODSYNC'     THEN 'SYNCPRETRETAIL'
        WHEN upper(relname) = 'SEQ_TIPSEDII1_CODTIPSEDIU1'     THEN 'NTIPSEDII1'
        WHEN upper(relname) = 'SEQ_USER_LISTS_LISTID'          THEN 'MENULISTE'
        WHEN upper(relname) = 'SEQ_TRIGAR_MODIF'               THEN 'TRIGAR_MODIF'
        WHEN upper(relname) = 'SEQ_SINTEZAEMUL1_CODSINTEZA1'   THEN 'SINTEZAEMULARE1'
        WHEN upper(relname) = 'SEQ_SINTEZAEMUL2_CODSINTEZA2'   THEN 'SINTEZAEMULARE2'
        WHEN upper(relname) = 'SEQ_STOBJASOC_CODSTOBJASOC'   THEN 'SETTASKOBJASOC'
        ELSE
          upper(substr(relname, 5, INSTRb(text(relname), '_', -1, 1) - 5))
      END table_name,
        CASE -- in principiu secventa este asociata primei coloane din tabela, iar exceptiile sunt in acest case
        WHEN upper(relname) = 'SEQ_ALERTA_INFO_RULARE'         THEN 'CODRULARE'
        WHEN upper(relname) = 'SEQ_ETICHCOLET_COD'             THEN 'IDCOLET'
        WHEN upper(relname) = 'SEQ_EMULARE_BONID'              THEN 'IDBON'
        WHEN upper(relname) = 'SEQ_PRELPRET_RETAIL'            THEN 'IDPRELUARE'
        WHEN upper(relname) = 'SEQ_TRIGAR_MODIF'               THEN 'CODMODIF'
        WHEN upper(relname) = 'SEQ_PRIORITATEGANTT'            THEN 'PRIORITATE'
        WHEN upper(relname) = 'SEQ_STAREESTIMARI1_CODSTARE1'   THEN 'CODSTARE1'
        ELSE NULL
      END column_name
FROM
    pg_statio_all_sequences
  where
    lower(schemaname) = lower(nume_schema)
    and  INSTRb(text(relname), '_', -1, 1) - 5  &gt; 0
    AND upper(relname) &lt;&gt; 'SEQ_ETICHCOLET_COD' -- astea sunt i oracke varchar
    AND upper(relname) &lt;&gt; 'SEQ_EMULARE_BONID'
  ) SEQ
 where
   lower(table_schema) = lower(nume_schema)
   and lower(col.table_name) = lower(seq.table_name)
   and ordinal_position = 1
 )
 LOOP
   s := 'SELECT COALESCE(MAX(' || V_REC.Column_Name || '), 99) + 1 FROM ' || V_REC.Table_Name;
   EXECUTE s INTO newVal;
   if newVal &lt; 100 then newVal := 100; end if;
   perform remake_sequence(nume_schema, v_rec.sequence, newval);
 END LOOP;

end;
$function$
</obj_text>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_efact_custom</obj_name>
  <obj_hashval>4f5b5bcce7dbdc45066e4c277069f883</obj_hashval>
  <obj_text>SELECT codefactc,
    den_efcustom,
    sqlcampuri,
    sqlcampuri1
   FROM martor.efact_custom a;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_formatii</obj_name>
  <obj_hashval>bf22794d00013e213b1ad30dad32c0d2</obj_hashval>
  <obj_text>SELECT f.codformatie,
    f.den_formatie,
    f.simbol,
    ng.den_gest
   FROM martor.formatii f
     LEFT JOIN martor.ngest ng ON f.codgest = ng.codgest;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_obj_art</obj_name>
  <obj_hashval>1b4c89aa644367c6332c20f14d0c5cda</obj_hashval>
  <obj_text>SELECT codobiect,
    denumire AS denobiect,
    codextern,
    codintern,
    codvamal
   FROM martor.nartobj o;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>alerte_def</obj_name>
  <obj_hashval>5fdf8c5c4c6fa19ded5997a387800a4e</obj_hashval>
  <obj_text>CREATE TABLE alerte_def (
  "codalertadef" numeric(20,0),
  "denumire" character varying(200),
  "codintern" character varying(200),
  "sql" text
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>bugetrectif</obj_name>
  <obj_hashval>e25ba73edc2cbf9f7e1f956f4c756ef3</obj_hashval>
  <obj_text>CREATE TABLE bugetrectif (
  "codbugetrectif" numeric(20,0) NOT NULL,
  "nrdoc" numeric(20,0),
  "datadoc" date,
  "an" numeric(4,0),
  "lunasursa" numeric(2,0),
  "lunadest" numeric(20,0),
  "obs" character varying(250),
  "userid" numeric(20,0),
  "datacreare" timestamp(6) without time zone,
  "codanaliza" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>bugetrectif1</obj_name>
  <obj_hashval>fe9c4c3bec8d160b840947825d19fe0c</obj_hashval>
  <obj_text>CREATE TABLE bugetrectif1 (
  "codbugetrectif1" numeric(20,0) NOT NULL,
  "codbugetrectif" numeric(20,0),
  "codnodsursa" numeric(20,0),
  "codnoddest" numeric(20,0),
  "vcredit" numeric(20,7),
  "vangajaprob" numeric(20,7),
  "vangajreal" numeric(20,7),
  "vplataaprob" numeric(20,7),
  "vplatareal" numeric(20,7),
  "vchelt" numeric(20,7),
  "vplanif" numeric(20,7),
  "vfact" numeric(20,7),
  "vincasreal" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>bugetstoc</obj_name>
  <obj_hashval>9a545466adf791456ec28a2da0c38461</obj_hashval>
  <obj_text>CREATE TABLE bugetstoc (
  "codbugetstoc" numeric(20,0) NOT NULL,
  "codbugetprod" numeric(20,0),
  "codobiect" numeric(20,0),
  "codclasea" numeric(20,0),
  "stoc" numeric(20,7),
  "coefum" numeric(20,7),
  "valtotal" numeric(20,7),
  "valmat" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>custodieini</obj_name>
  <obj_hashval>f5cf00c2a032d793bd2e70c4f70dd92d</obj_hashval>
  <obj_text>CREATE TABLE custodieini (
  "codcustodie" numeric(20,0) NOT NULL,
  "codpart" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>dflansz1</obj_name>
  <obj_hashval>4465a7211495e7fc137b2f9ca67cb8c1</obj_hashval>
  <obj_text>CREATE TABLE dflansz1 (
  "codlansz" numeric(20,0),
  "codreteta" numeric(20,0),
  "codobiect" numeric(20,0),
  "an" numeric(4,0),
  "saptamana" numeric(2,0),
  "dirty" numeric(10,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>docfreex</obj_name>
  <obj_hashval>4fe1fdbf53e1e328089804c77b7ce4af</obj_hashval>
  <obj_text>CREATE TABLE docfreex (
  "startnr" numeric(20,0) NOT NULL,
  "endnr" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>efactura</obj_name>
  <obj_hashval>396a17eeb9c7470903897ea71682940d</obj_hashval>
  <obj_text>CREATE TABLE efactura (
  "codies" numeric(20,0) NOT NULL,
  "idincarcare" character varying(20),
  "iddescarcare" character varying(20),
  "dataincarcare" timestamp(6) without time zone,
  "stare" character varying(20),
  "tipmediu" numeric(1,0),
  "mesaje" text
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>etva_vama_export</obj_name>
  <obj_hashval>cec183f79877d1e9d884867952eeb8d5</obj_hashval>
  <obj_text>CREATE TABLE etva_vama_export (
  "codetva_vama_export" numeric(20,0) NOT NULL,
  "codetva" numeric(20,0),
  "nr_mrn" character varying(100),
  "data_mrn" date,
  "valoare" numeric(20,7),
  "moneda" character varying(20),
  "curs" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>iesiri_pdx</obj_name>
  <obj_hashval>d2a26f14c35b22367b7eb9f10c0128db</obj_hashval>
  <obj_text>CREATE TABLE iesiri_pdx (
  "codies" numeric(20,0),
  "nrdoc" numeric(20,0),
  "zi" numeric(20,0),
  "part" numeric(20,0),
  "indexlocal" numeric(20,0),
  "art" numeric(20,0),
  "tiplinie" character varying(1),
  "canties1" numeric(20,7),
  "pret" numeric(20,7),
  "cantlivr" numeric(20,7),
  "codstoc" numeric(20,0),
  "part_wme" numeric(20,0),
  "codobiect" numeric(20,0),
  "codnirstoc" numeric(20,0),
  "datadoc" date,
  "tipdoc" numeric(5,0),
  "prefixdoc" character varying(5),
  "valdoc" numeric(20,7),
  "tvadoc" numeric(20,7),
  "an" numeric(4,0),
  "luna" numeric(2,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>ieslink</obj_name>
  <obj_hashval>a244efd23e70a55f2e55e5d38222499a</obj_hashval>
  <obj_text>CREATE TABLE ieslink (
  "codies1" numeric(20,0) NOT NULL,
  "codliniecomanda" numeric(20,0),
  "codlinieaviz" numeric(20,0),
  "cant" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>jurnalshort</obj_name>
  <obj_hashval>b7c44fa957ede2a439d04c65bfb2de61</obj_hashval>
  <obj_text>CREATE TABLE jurnalshort (
  "machete" character varying(1000)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>medex</obj_name>
  <obj_hashval>b49d44acfe5a5a024199f6fc026ea89f</obj_hashval>
  <obj_text>CREATE TABLE medex (
  "codmedex" numeric(20,0) NOT NULL,
  "datalista" date,
  "obs" character varying(250)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nclaseop</obj_name>
  <obj_hashval>c94aa23e1929a771b41063c144819b2d</obj_hashval>
  <obj_text>CREATE TABLE nclaseop (
  "codclaseop" numeric(20,0) NOT NULL,
  "den_claseop" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nclaseopt</obj_name>
  <obj_hashval>24df403e9f99297a93dd2787f029478f</obj_hashval>
  <obj_text>CREATE TABLE nclaseopt (
  "codclaseopt" numeric(20,0) NOT NULL,
  "denumire" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>normemat</obj_name>
  <obj_hashval>42a7d2c970de1ce0e43b3bafba95e052</obj_hashval>
  <obj_text>CREATE TABLE normemat (
  "codnormemat" numeric(20,0) NOT NULL,
  "codnorma" numeric(20,0),
  "codprodcomp" numeric(20,0),
  "codobiect" numeric(20,0),
  "cant" numeric(20,7),
  "pret" numeric(20,7),
  "d1" numeric(20,7),
  "d2" numeric(20,7),
  "d3" numeric(20,7),
  "indexlocal" numeric(10,0),
  "cantum1" numeric(20,7),
  "codmat" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>noteconta</obj_name>
  <obj_hashval>3a502d466035ea77ac00044ed4e9284b</obj_hashval>
  <obj_text>CREATE TABLE noteconta (
  "codnota" numeric(2,0),
  "denumire" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nova</obj_name>
  <obj_hashval>14dbcf2a1272524eed03d55a1a7d0488</obj_hashval>
  <obj_text>CREATE TABLE nova (
  "codobiect" numeric(20,0),
  "pretachiz" numeric
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>npart1x</obj_name>
  <obj_hashval>0b344617de30efdda4252da709e7efd2</obj_hashval>
  <obj_text>CREATE TABLE npart1x (
  "codpart1" numeric(20,0),
  "codpart" numeric(20,0),
  "codiopart" numeric(20,0),
  "creditclient" numeric(18,2),
  "volumtranzc" numeric(18,2),
  "creditfurn" numeric(18,2),
  "volumtranzf" numeric(16,2),
  "anstart" numeric(4,0),
  "lunastart" numeric(2,0),
  "alstart" numeric(5,0),
  "alstop" numeric(5,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>nsertar1</obj_name>
  <obj_hashval>571faa276e4fb183d5f40a99c1abdaf0</obj_hashval>
  <obj_text>CREATE TABLE nsertar1 (
  "codsertar1" numeric(20,0) NOT NULL,
  "codsertar" numeric(20,0),
  "codobligpif" numeric(20,0),
  "valoare" numeric(20,7),
  "dendoclegatura" character varying(100),
  "codgeneral" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>oportunitati1</obj_name>
  <obj_hashval>7829964028d6653cd8a636a10a7fa933</obj_hashval>
  <obj_text>CREATE TABLE oportunitati1 (
  "codoportunitate1" numeric(20,0) NOT NULL,
  "codoportunitate" numeric(20,0),
  "indexlocal" numeric(3,0),
  "stadiu" numeric(1,0),
  "codagent" numeric(20,0),
  "info" character varying(2000),
  "datac" timestamp(0) without time zone,
  "codmotiv" numeric(20,0),
  "followup" timestamp(0) without time zone,
  "codtask" numeric(20,0),
  "codpers" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>packing1</obj_name>
  <obj_hashval>7f278d43269f314cd57657d4d6ba24ca</obj_hashval>
  <obj_text>CREATE TABLE packing1 (
  "codpacking1" numeric(20,0) NOT NULL,
  "codpacking" numeric(20,0),
  "coddoc1" numeric(20,0),
  "codobiect" numeric(20,0),
  "codamb_primar" numeric(20,0),
  "codamb_secundar" numeric(20,0),
  "codamb_tertiar" numeric(20,0),
  "cantamb" numeric(20,7),
  "cantambxprimar" numeric(20,7),
  "cantambxsecundar" numeric(20,7),
  "cantambxtertiar" numeric(20,7),
  "cantcomanda" numeric(20,7),
  "cantobj" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>planifnod</obj_name>
  <obj_hashval>ec359f97ba22b6641b0598c76094570f</obj_hashval>
  <obj_text>CREATE TABLE planifnod (
  "codplanifnod" numeric(20,0) NOT NULL,
  "codplanifprod1" numeric(20,0),
  "codplanifprod" numeric(20,0),
  "cant" numeric(20,7),
  "nodoriginal" numeric(20,0),
  "pozitie" numeric(10,0),
  "codreteta" numeric(20,0),
  "tip" numeric(1,0),
  "codobiect" numeric(20,0),
  "indexparinte" character varying(50),
  "codprodmat" numeric(20,0),
  "nivel" numeric(10,0),
  "ordine" numeric(5,0),
  "codproiectnod" numeric(20,0),
  "versiune" numeric(1,0),
  "cantprodreteta" numeric(20,7),
  "cantmatreteta" numeric(20,7),
  "necesar" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>prestatii</obj_name>
  <obj_hashval>7a4b643fa6bada3706f9f77542ad5815</obj_hashval>
  <obj_text>CREATE TABLE prestatii (
  "codprestatie" numeric(20,0) NOT NULL,
  "cod" character varying(50),
  "denumire" character varying(500)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>punctaje</obj_name>
  <obj_hashval>6d994b7dd7b2ae4b7109b9a5ff6741c6</obj_hashval>
  <obj_text>CREATE TABLE punctaje (
  "codpunctaj" numeric(20,0) NOT NULL,
  "denumire" character varying(100),
  "datastart" date,
  "dataend" date,
  "tip" numeric(5,0),
  "casademarcat" numeric(1,0),
  "facturare" numeric(1,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>punctajvaldoc</obj_name>
  <obj_hashval>6d35789d86bac99fa3bd708fc1822271</obj_hashval>
  <obj_text>CREATE TABLE punctajvaldoc (
  "cod" numeric(20,0),
  "codpunctaj" numeric(20,0),
  "limitaval" numeric(20,7),
  "puncte" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sablonnote</obj_name>
  <obj_hashval>fbd68f31d696c0dced1766ce430aec89</obj_hashval>
  <obj_text>CREATE TABLE sablonnote (
  "tipdoc" numeric(5,0),
  "simbold" character varying(50),
  "simbolc" character varying(50),
  "codnota" numeric(2,0),
  "obs" character varying(200)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>sal_ndrep</obj_name>
  <obj_hashval>6eef2939a2c7ddd5aa1d31b8c31fbf45</obj_hashval>
  <obj_text>CREATE TABLE sal_ndrep (
  "codndrep" numeric(20,0) NOT NULL,
  "denumire" character varying(50),
  "tip" numeric(2,0),
  "modcalc" numeric(2,0),
  "dataadaug" date
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>servfact</obj_name>
  <obj_hashval>6ec05282dcde2af79f7fa997a218ba19</obj_hashval>
  <obj_text>CREATE TABLE servfact (
  "codservfact" numeric(20,0),
  "denumire" character varying(200),
  "codobiect" numeric(20,0),
  "modcalcul" numeric(5,0),
  "sumapornirekm" numeric(20,7),
  "sumapornirecant" numeric(20,7),
  "procpornirekm" numeric(20,7),
  "procpornirecant" numeric(20,7),
  "cod" character varying(10)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_manevra_intr1</obj_name>
  <obj_hashval>2dd5dabcc39d6c634af73ab6cce978b4</obj_hashval>
  <obj_text>CREATE TABLE tmp_manevra_intr1 (
  "codintr1" numeric(20,0),
  "codobiect" numeric(20,0),
  "codcmdprodmat" numeric(20,0),
  "cantpredata" numeric(20,7),
  "codnirstoc" numeric(20,0),
  "pretpredare" numeric(20,7),
  "np" character varying(50),
  "seriinp" character varying(2500),
  "setimananp" character varying(50)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>tmp_particip</obj_name>
  <obj_hashval>d90496cfe8016d1cbc9f90b356a05cde</obj_hashval>
  <obj_text>CREATE TABLE tmp_particip (
  "cod" numeric(20,0),
  "denumire" character varying(200),
  "procent" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>transflink</obj_name>
  <obj_hashval>3ecbc9aefa470c08f767b010260ad2e9</obj_hashval>
  <obj_text>CREATE TABLE transflink (
  "codtransf1" numeric(20,0),
  "codliniecomanda" numeric(20,0),
  "cant" numeric(20,7)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>user_alerte</obj_name>
  <obj_hashval>f34adc930bd7f66b94997e20962833ba</obj_hashval>
  <obj_text>CREATE TABLE user_alerte (
  "userid" numeric(20,0)
);</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_intrari_codmoneda</obj_name>
  <obj_reftable>intrari</obj_reftable>
  <obj_hashval>30ac638a31d55786c63fa689ccec68d2</obj_hashval>
  <obj_text>CREATE INDEX idx_intrari_codmoneda ON intrari USING btree (moneda)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_livr_datalivr</obj_name>
  <obj_reftable>livr</obj_reftable>
  <obj_hashval>1ad30817349f9424b7fdc926b97d7ab9</obj_hashval>
  <obj_text>CREATE INDEX idx_livr_datalivr ON livr USING btree (datalivr)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_reg</obj_name>
  <obj_reftable>reg</obj_reftable>
  <obj_hashval>20b56ebe378a7fd47a543445f9505db6</obj_hashval>
  <obj_text>CREATE INDEX idx_reg ON reg USING btree (an, luna, tipreg)</obj_text>
</row>

<row>
  <obj_type>INDEX</obj_type>
  <obj_name>idx_soldini_codpart</obj_name>
  <obj_reftable>soldini</obj_reftable>
  <obj_hashval>b495ab880e75cfc269cdacf4e5c98d3a</obj_hashval>
  <obj_text>CREATE INDEX idx_soldini_codpart ON soldini USING btree (codpart)</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_trigar_modif</obj_name>
  <obj_hashval>fc79398427b75e1b0790ff1f493c42df</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_trigar_modif INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>SEQUENCE</obj_type>
  <obj_name>seq_utilajedev_codutilajdev</obj_name>
  <obj_hashval>a5aa3ad29871b6a04d3532c9833dbc20</obj_hashval>
  <obj_text>CREATE SEQUENCE seq_utilajedev_codutilajdev INCREMENT BY 1 MINVALUE 100 MAXVALUE 999999999999999999 START 101 CACHE 1 NO CYCLE;</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sms_send_sms_full</obj_name>
  <obj_hashval>fee6df35537d732b9dc210a16cd4cf34</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sms_send_sms_full(INOUT wme_result numeric, INOUT nrtelefon character varying, INOUT amesaj character varying, INOUT anume character varying, INOUT acoddoc numeric, INOUT acoddoc1 numeric, INOUT atipdoc numeric, INOUT forceresend numeric, INOUT msg_eroare character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  Res                numeric := 0;
  MESAJ              varchar;
  TimeStampu         numeric;
  NrCaractereMax     numeric;
  Nr                 numeric;

  SMS_url           varchar := '?';
  SMS_metoda        varchar := '?';
  SMS_content_type  varchar := '?';
  SMS_content_Value varchar := '?';
  SMS_fromValue     varchar := '?';
  SMS_chksum_param  varchar := '?';
  SMS_json_param    varchar := '?';
  SMS_json_data     varchar := '?';
  SMS_err_marker    varchar := '?';
  API_Key           varchar := '?';
  API_Secret        varchar := '?';

  SMS_PROVIDER      VARCHAR := '?';
BEGIN
  --Florin 01.11.2022 - sinc. Oracle (26.10.2022)
  --Adina 15.03.2021
  --Florin 16.02.2021

  IF ForceResend = 0 THEN
    SELECT Count(*) INTO Nr
    FROM SMSURI
    WHERE
       TELEFON      = NRTELEFON and
       SMSURI.MESAJ = aMesaj and
       Status       = 1 and
       CodDoc       = aCodDoc and
       CodDoc1      = aCodDoc1 and
       TipDoc       = aTipDoc;

    IF Nr &gt; 0 THEN
      Res        := -1;
      MSG_EROARE := 'Allready sended';
      WME_Result :=  RES;
      RETURN;
    END IF;
  END IF;

  IF (API_Key = '?') THEN
    SELECT asms_url, asms_metoda, asms_content_type, asms_content_value, asms_fromvalue, asms_chksum_param, asms_json_param, asms_json_data, asms_err_marker, akey, apass
    INTO SMS_url           ,
         SMS_metoda        ,
         SMS_content_type  ,
         SMS_content_Value ,
         SMS_fromValue     ,
         SMS_chksum_param  ,
         SMS_json_param    ,
         SMS_json_data     ,
         SMS_err_marker    ,
         API_Key,
         API_Secret
    FROM winmadmin.PKG_USERFIRME_Get_user_SMS_Full(public.get_schema(), null, null, null, null, null, null, null, null, null, null, null);
  END IF;

  IF (API_Key = '?') THEN
    MSG_Eroare := '"Not API_Key active"';
  ELSE
    TimeStampu := (SELECT date_to_unix_ts.WME_RESULT FROM date_to_unix_ts(NULL,CURRENT_TIMESTAMP));
    NrCaractereMax := 999;
    IF    InSTR(upper(SMS_url), 'NOTIFICA', 1, 1) &gt; 0 THEN NrCaractereMax := 160;
    ELSIF InSTR(upper(SMS_url), 'ORANGE',   1, 1) &gt; 0 THEN NrCaractereMax := 160;
    ELSIF InSTR(upper(SMS_url), 'ADVERT',   1, 1) &gt; 0 THEN NrCaractereMax := 480;
  END IF;

  Mesaj := aMesaj;
  IF  InSTR(Mesaj, coalesce(Chr(13),'') || coalesce(Chr(10),''), 1, 1) = 1 THEN
    Mesaj := Substr(Mesaj, 3);
  END IF;

  IF  InSTR(Mesaj, coalesce(Chr(13),'') || coalesce(Chr(10),''), length(Mesaj) - 2, 1) &gt; 0 THEN
    Mesaj := Substr(Mesaj, 1, length(Mesaj) - 2);
  END IF;

  IF  length(Mesaj) &gt; NrCaractereMax THEN
    Mesaj := coalesce(Substr(Mesaj, 1, NrCaractereMax - 10),'') || '...more...';
  END IF;

  MSG_EROARE := '';
  perform set_config('PKG_SMS.SMS_url',upper(SMS_url),false);
  SMS_url := upper(SMS_url);

    IF InSTR(upper(SMS_url), 'CENTRALATELEFONICA', 1,1) &gt; 0 then
      RES := pkg_sms_SEND_SMS_CENTRALATELEFONICA(NRTELEFON, MESAJ, MSG_EROARE);
    ELSIF InSTR(upper(SMS_url), 'NOTIFICA', 1, 1) &gt; 0 THEN
    SMS_url := replace(SMS_url, '%JSONPARAM%' , ''); --JS
    SMS_url := replace(SMS_url, '%TIMESTAMP%' , COALESCE(TIMESTAMPU::varchar,''));
    SMS_url := replace(SMS_url, '%CHECKSUM%'  , '');  --CHK
    SMS_url := replace(SMS_url, '%NRTELEFON%' , COALESCE(NRTELEFON,''));
    SMS_url := replace(SMS_url, '%FROMMSG%'   , COALESCE(SMS_fromValue,''));
    SMS_url := replace(SMS_url, '%MESAJ%'     , COALESCE(MESAJ,''));
    SMS_url := replace(SMS_url, '%API_SECRET%', COALESCE(API_SECRET,''));
    SMS_url := replace(SMS_url, '%API_KEY%'   , COALESCE(API_KEY,''));

    SMS_content_Value := upper(SMS_content_Value);
    SMS_content_Value := replace(SMS_content_Value, '%JSONPARAM%' , ''); --JS
    SMS_content_Value := replace(SMS_content_Value, '%TIMESTAMP%' , COALESCE(TIMESTAMPU::varchar,''));
    SMS_content_Value := replace(SMS_content_Value, '%CHECKSUM%'  , '');  --CHK
    SMS_content_Value := replace(SMS_content_Value, '%NRTELEFON%' , COALESCE(NRTELEFON,''));
    SMS_content_Value := replace(SMS_content_Value, '%FROMMSG%'   , COALESCE(SMS_fromValue,''));
    SMS_content_Value := replace(SMS_content_Value, '%MESAJ%'     , COALESCE(MESAJ,''));
    SMS_content_Value := replace(SMS_content_Value, '%API_SECRET%', COALESCE(API_SECRET,''));
    SMS_content_Value := replace(SMS_content_Value, '%API_KEY%'   , COALESCE(API_KEY,''));

    SMS_json_Data := upper(SMS_json_Data);
    SMS_json_Data := replace(SMS_json_Data, '%JSONPARAM%' , ''); --JS
    SMS_json_Data := replace(SMS_json_Data, '%TIMESTAMP%' , COALESCE(TIMESTAMPU::varchar,''));
    SMS_json_Data := replace(SMS_json_Data, '%CHECKSUM%'  , '');  --CHK
    SMS_json_Data := replace(SMS_json_Data, '%NRTELEFON%' , COALESCE(NRTELEFON,''));
    SMS_json_Data := replace(SMS_json_Data, '%FROMMSG%'   , COALESCE(SMS_fromValue,''));
    SMS_json_Data := replace(SMS_json_Data, '%MESAJ%'     , COALESCE(MESAJ,''));
    SMS_json_Data := replace(SMS_json_Data, '%API_SECRET%', COALESCE(API_SECRET,''));
    SMS_json_Data := replace(SMS_json_Data, '%API_KEY%'   , COALESCE(API_KEY,''));

    RES := (PKG_SMS_SENDSMS_NOTIFICA(SMS_url, NRTELEFON, MESAJ, API_KEY, API_SECRET));
  ELSIF InSTR(upper(SMS_url), 'ORANGE', 1, 1) &gt; 0 THEN
    RES := (PKG_SMS_SENDSMS_ORANGE(SMS_url,NRTELEFON, SMS_content_Value, MESAJ, SMS_fromValue, API_Key));
  ELSIF InSTR(SMS_url, 'ADVERT',   1,1) &gt; 0 THEN
    RES := (PKG_SMS_SENDSMS_ADVERT(SMS_url,NRTELEFON, MESAJ, API_Key));
  ELSE
    MSG_Eroare := '"Unknown provider!"';
    RES := 0;
    END IF;
  END IF;

  INSERT INTO SMSURI(CODSMS, DATA, USERID, TELEFON, MESAJ, EROARE, Nume, Status, CodDoc, CodDoc1, TipDoc)
  VALUES(NEXTVAL('SEQ_SMSURI_CODSMS'), CURRENT_TIMESTAMP, current_setting('PKG_GLOBALS.USERID', true)::numeric, NRTELEFON, MESAJ, MSG_Eroare, aNume, Res, aCodDoc, aCodDoc1, aTipDoc);

  WME_Result :=  RES;
  RETURN;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>updatenpart1crminteger</obj_name>
  <obj_hashval>854a84bb1dea8cf4d3123dd672355289</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION updatenpart1crminteger(camp character varying, valoare numeric, adatastart date)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 04.12.2025
  Perform UpdateNPART1CRMString(Camp, to_char(valoare), aDataStart);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rezervari_get_tmp_rez_rez</obj_name>
  <obj_hashval>147488918aadda58e9ee023d6fe3ee11</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rezervari_get_tmp_rez_rez()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 06.06.2024 - sinc. Oracle
  --Florin 16/19.12.2022 - fixat 56588/56589
  --Florin 29.11.2022 - sinc. Oracle
  --Bogdan 15.10.2020
  DELETE FROM TMP_REZ_REZ;

  INSERT INTO TMP_REZ_REZ (CODCOMANDA1,
      DENUMIRE,
      CODOBIECT,
      CODGEST,
      CODIOART,
      Gest_IOArt,
      CANT,
      RESTCOM,
      UM,
      UMSEC,
      REZ,
      REZINI,
      REZFURN,
      REZCMDFURN,
      CODNIRSTOC,
      CODNIRSER,
      NECESAR,
      NECESARINI,
      IDX,
      REZOLVAT,
      REZFURNINI,
      DEN_UMSEC,
      DEN_UM1,
      DEN_UM2,
      DATADOC,
      CODEXTERN,
      D1, D2, D3,
      PARITATE,
      RelatieUM1,
      CANTUM1)
  (SELECT CODCOMANDA1,
        DENUMIRE,
        CODOBIECT,
        CODGEST,
        CODIOART,
        coalesce (Substr (Den_gest, 1, 25) ,'') || coalesce (chr (13) ,'') || coalesce (Den_IOART,'') AS GEST_IOART,
        COALESCE (CANT, 0) ,
        COALESCE (RESTCOM, 0) ,
        UM,
        UMSEC,
        COALESCE (REZ, 0) ,
        COALESCE (REZINI, 0) ,
        COALESCE (REZFURN, 0) ,
        COALESCE (REZCMDFURN, 0) ,
        CODNIRSTOC,
        CODNIRSER,
        COALESCE (NECESAR, 0) ,
        COALESCE (NECESARINI, 0) ,
        IDX,
        COALESCE (REZOLVAT, 0) ,
        COALESCE (REZFURNINI, 0) ,
        DEN_UMSEC,
        DEN_UM1,
        DEN_UM2,
        DATADOC,
        CODEXTERN,
        D1,D2,D3,
        Paritate,
        RelatieUM1,
        cantUM1
   FROM (SELECT rr.codcomanda1,
            rr.Denumire,
            rr.codobiect,
            Imp.GESTIMPLICITA CODGEST,
            IMP.CONTIMPLICIT  CODIOART,
            ioa.den_ioart     DEN_IOART,
            G.den_gest        DEN_GEST,
            rr.cant,
            0 RESTCOM,
            rr.UM,
            rr.UMSec,
            rr.den_umsec,
            rr.den_um1,
            rr.den_um2,
            rez.rest         REZ,
            rez.ini          REZINI,
            rezf.restfurn    REZFURN,
            rezCmdf.restfurn REZCMDFURN,
            0                CODNIRSTOC,
            0                CODNIRSER,
            rr.necesar,
            rr.necesarini,
            rr.idx,
            COALESCE (Rzv.Cant, 0) REZOLVAT,
            rezf.restfurn          REZFURNINI,
            rr.datadoc,
            rr.codextern,
            RR.D1,RR.D2,RR.D3,
            RR.Paritate,
            RR.RelatieUM1,
            RR.cantUM1
          FROM (SELECT pp.codcomanda1,
                  pp.Denumire,
                  pp.codobiect,
                  pp.idx,
                  pp.UM,
                  pp.UMSec,
                  pp.den_um1,
                  pp.den_um2,
                  pp.den_umsec,
                  pp.datadoc,
                  sum (pp.cant)         CANT,
                  sum (pp.RestAcceptat) NECESAR,
                  sum (pp.RestAcceptat) NECESARINI,
                  pp.codextern,
                  pp.D1,pp.D2,pp.D3,
                  pp.Paritate,
                  pp.RelatieUM1,
                 sum(
                   round(CASE
                           WHEN pp.RELATIEUM1 IN (1, 7) AND COALESCE(pp.D1, 0) &lt;&gt; 0 THEN PP.RESTACCEPTAT/pp.D1
                           WHEN pp.RELATIEUM1 IN (2, 8) AND COALESCE(pp.D1, 0) * COALESCE(pp.D2, 0) &lt;&gt; 0 THEN PP.RESTACCEPTAT / (COALESCE(pp.D1,0) * COALESCE(pp.D2,0))
                           WHEN pp.RELATIEUM1 IN (3, 9) AND COALESCE(pp.D1, 0) * COALESCE(pp.D2, 0) * COALESCE(pp.D3, 0) &lt;&gt; 0 THEN PP.RESTACCEPTAT / (COALESCE(pp.D1,0) * COALESCE(pp.D2,0) * COALESCE(pp.D3,0))
                           WHEN pp.RELATIEUM1 IN (4, 10) THEN PP.RESTACCEPTAT * COALESCE(pp.D1,0)
                           WHEN pp.RELATIEUM1 IN (5, 11) THEN PP.RESTACCEPTAT * COALESCE(pp.D1, 0) * COALESCE(pp.D2, 0)
                           WHEN pp.RELATIEUM1 IN (6, 12) THEN PP.RESTACCEPTAT * COALESCE(pp.D1, 0) * COALESCE(pp.D2, 0) * COALESCE(pp.D3, 0)
                           ELSE NULL
                         END,7)
                 ) CantUM1
                FROM (SELECT c1.codcomanda1,
                             obj.denumire,
                             obj.codobiect,
                             um.den_um UM,
                             PN.CANT * (CASE WHEN coalesce(ne.codobiect, 0) = 0 THEN 1 else ne.paritate END) cant,
                             um1.codum1 UMSec,
                             CASE WHEN COALESCE (pn.nodoriginal, 0) = 0 THEN 0
                                  ELSE CASE WHEN pn.tip = 5 THEN 3 ELSE pn.tip END
                             END IDX,
                             CASE WHEN pn.tip = 5 THEN pn.cant ELSE
                             c1.RestAcceptat * um1.paritate / PN0.CANT *
                             PN.CANT END
                              * CASE WHEN COALESCE (ne.codobiect, 0) = 0 THEN 1 ELSE ne.paritate END  RESTACCEPTAT,
                             um1.den_um1 den_umsec,
                             um_1.den_um   DEN_UM1,
                             um_2.den_um   DEN_UM2,
                             c.datadoc,
                             obj.codextern,
                             coalesce(mat.d1,art.D1) d1,
                             coalesce(mat.d2,art.D2) d2,
                             coalesce(mat.d3,art.D3) d3,
                             um1.Paritate,
                             art.RelatieUM1
                      FROM comanda1                         c1
                        INNER JOIN comanda                  c     ON c1.codcomanda = c.codcomanda
                        INNER JOIN tmp_manevra_liniicomenzi tmp   ON c1.codcomanda1 = tmp.codcomanda1
                        LEFT JOIN proiectnod                pn    ON c1.codproiect = pn.codproiect
                        left join prodmat                   mat   on mat.codmat = pn.codprodmat
                        LEFT JOIN proiectnod                pn0   ON c1.codproiect = pn0.codproiect and COALESCE (pn0.nodoriginal, 0) = 0
                        left join nodechiv                  ne    on ne.codcomanda1 = c1.codcomanda1
                                         and ne.codproiectnod =  pn.codproiectnod
                        left join nartobj                   obj   on coalesce(ne.codobiect,pn.codobiect) = obj.codobiect
                        LEFT JOIN nart                      art   ON obj.codarticol = art.codarticol
                        LEFT JOIN num                       um    ON art.um = um.codum
                        LEFT JOIN num                       um_1  ON art.um1 = um_1.codum
                        LEFT JOIN num                       um_2  ON art.um2 = um_2.codum
                        LEFT JOIN num1                      um1   ON art.um = um1.codum and um1.secundara &lt;&gt; 1
                        LEFT JOIN nodechiv                  ne1   ON ne1.codcomanda1 = c1.codcomanda1 and ne1.codproiectnod = pn.codproiectnod
                        LEFT JOIN nartobj                   obje  ON ne1.codobiect = obje.codobiect
                        LEFT JOIN nart                      arte  ON obje.codarticol = arte.codarticol
                        LEFT JOIN num                       ume   ON arte.um = ume.codum
                        LEFT JOIN num1                      um1e  ON arte.um = um1e.codum and um1e.secundara &lt;&gt; 1
                      WHERE
                        c1.codproiect &gt; 0 and c1.culansare = 1
                      ) pp
                GROUP BY
                  pp.codcomanda1,
                  pp.Denumire,
                  pp.codobiect,
                  pp.umsec,
                  pp.den_umsec,
                  pp.den_um1,
                  pp.den_um2,
                  pp.datadoc,
                  pp.UM,
                  pp.idx,
                  pp.codextern,
                  pp.D1,pp.D2,pp.D3,
                  pp.Paritate,
                  pp.RelatieUM1) rr
          LEFT join (SELECT r.codcomanda1, sum (r.rest) REST, sum (r.RezervatIni) INI, ns.codobiect
                       FROM rezervats r INNER JOIN nirstoc ns ON ns.codnirstoc = r.codnirstoc
                       WHERE R.CODNIRSTOC &gt; 0
                       GROUP BY r.codcomanda1, ns.codobiect
                      ) rez ON rr.codcomanda1 = rez.codcomanda1 and rr.codobiect = rez.codobiect
            LEFT JOIN (SELECT r.codcomanda1, sum (r.rest) RESTFURN, r.codobiect
                       FROM rezervats r
                       WHERE COALESCE (R.CODNIRSTOC, 0) = 0 and COALESCE (R.CODCOMANDA1F, 0) = 0
                       GROUP BY r.codcomanda1, r.codobiect
                      ) rezf ON rr.codcomanda1 = rezf.codcomanda1 and rr.codobiect = rezf.codobiect
            LEFT JOIN (SELECT r.codcomanda1, sum (r.rest) RESTFURN, r.codobiect
                       FROM rezervats r
                       WHERE COALESCE (R.CODNIRSTOC, 0) = 0 and COALESCE (R.CODCOMANDA1F, 0) &gt; 0
                       GROUP BY r.codcomanda1, r.codobiect
                      ) rezCmdf ON rr.codcomanda1 = rezCmdf.codcomanda1 and rr.codobiect = rezCmdf.codobiect
            LEFT JOIN nartobj        obj     ON obj.codobiect = rr.codobiect
            LEFT JOIN nartimplicite  imp     ON obj.codarticol = imp.codarticol and imp.codsubunit = current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric
            LEFT JOIN IOART          IOA     ON COALESCE (IOA.CODIOART, 0) = COALESCE (imp.contimplicit, 0)
            LEFT JOIN NGEST          G       ON COALESCE (G.CODGEST, 0) = COALESCE (IMP.GestImplicita, 0)
            LEFT JOIN (SELECT cmdmat.codobiect, l.codcmd1 CODCOMANDA1, sum (lk.cant) CANT
                       FROM iesprodlink         lk
                          INNER JOIN cmdprodmat cmdmat ON lk.codcmdprodmat   = cmdmat.codcmdprodmat
                          INNER JOIN comanda1   c1     ON cmdmat.codcomanda1 = c1.codcomanda1
                          INNER JOIN lansare1   l1     ON l1.codcmd1         = c1.codcomanda1
                          INNER JOIN lansare    l      ON l1.codlansare      = l.codlansare
                       GROUP BY cmdmat.codobiect, l.codcmd1
                      ) Rzv ON Rzv.CodObiect = rr.codobiect and Rzv.CodComanda1 = rr.codcomanda1
          ) A_PG
      WHERE NecesarIni &lt;&gt; 0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_fixeaza_solduri_initiale</obj_name>
  <obj_hashval>97069bf4d02f3ec50e399050f1c4f6fb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_fixeaza_solduri_initiale()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC         RECORD;
  V_RECSTINGERI RECORD;
  aREST         double precision;
  NR            numeric := 0;
  aCODTREZOR1   numeric := 0;
  aSEMNIF       numeric := 0;
begin
  FOR V_REC IN
  (
  SELECT O.CODOBLIGPIF, O.CODPART, I.AN, I.LUNA, I.CODINTR, 0 AS CODIES, 0 AS CODTREZOR, 0 AS CODCOMPENS, 0 AS CODNC
  FROM OBLIGPIF O
      LEFT JOIN GENERAL G ON  G.CODGENERAL = O.CODGENERAL
      LEFT JOIN INTRARI I ON  I.CODINTR = G.CODDOC
  WHERE O.SEMNIFICATIE IN (100, 140) AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999') AND (   I.OPERAT = 1)  AND (   I.ANULAT = 0)
  union ALL
  SELECT O.CODOBLIGPIF, O.CODPART, I.AN, I.LUNA, I.CODINTR, 0 AS CODIES, 0 AS CODTREZOR, 0 AS CODCOMPENS, 0 AS CODNC
  FROM OBLIGPIF O
      LEFT JOIN GENERAL G ON  G.CODGENERAL = O.CODGENERAL
      LEFT JOIN INTRARI I ON  I.CODINTR = G.CODDOC
  WHERE O.SEMNIFICATIE IN (110) AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999') AND (   I.OPERAT = 1)  AND (   I.ANULAT = 0)
  union ALL
  SELECT O.CODOBLIGPIF, O.CODPART, I.AN, I.LUNA, I.CODINTR, 0 AS CODIES, 0 AS CODTREZOR, 0 AS CODCOMPENS, 0 AS CODNC
  FROM OBLIGPIF O
      LEFT JOIN GENERAL G ON  G.CODGENERAL = O.CODGENERAL
      LEFT JOIN DVI D ON  G.CODDOC = D.CODDVI
      LEFT JOIN INTRARI I ON  I.CODINTR = D.CODINTR
  WHERE O.SEMNIFICATIE IN (130) AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999') AND (   I.OPERAT = 1)  AND (   I.ANULAT = 0)
  union ALL
  SELECT O.CODOBLIGPIF, O.CODPART, I.AN, I.LUNA, 0 AS CODINTR, I.CODIES, 0 AS CODTREZOR, 0 AS CODCOMPENS, 0 AS CODNC
  FROM OBLIGPIF O
      LEFT JOIN GENERAL G ON  G.CODGENERAL = O.CODGENERAL
      LEFT JOIN IESIRI I ON  I.CODIES = G.CODDOC
  WHERE O.SEMNIFICATIE IN (200, 240) AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999') AND (   I.OPERAT = 1)  AND (   I.ANULAT = 0)
  union ALL
  SELECT O.CODOBLIGPIF, O.CODPART, I.AN, I.LUNA, 0 AS CODINTR, I.CODIES, 0 AS CODTREZOR, 0 AS CODCOMPENS, 0 AS CODNC
  FROM OBLIGPIF O
      LEFT JOIN GENERAL G ON  G.CODGENERAL = O.CODGENERAL
      LEFT JOIN IESIRI I ON  I.CODIES = G.CODDOC
  WHERE O.SEMNIFICATIE IN (210) AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999') AND (   I.OPERAT = 1)  AND (   I.ANULAT = 0)
  union ALL
  SELECT O.CODOBLIGPIF, O.CODPART, T.AN, T.LUNA, 0 AS CODINTR, 0 AS CODIES, T.CODTREZOR, 0 AS CODCOMPENS, 0 AS CODNC
  FROM OBLIGPIF O
      LEFT JOIN GENERAL G ON  G.CODGENERAL = O.CODGENERAL
      LEFT JOIN TREZOR1 T1 ON  T1.CODTREZOR1 = G.CODDOC
      LEFT JOIN TREZOR T ON  T.CODTREZOR = T1.CODTREZOR
  WHERE ((T1.INITIALIZARI = 1) OR (COALESCE( T1.INITIALIZARI, 0) &lt;&gt; 1 AND  T.OPERAT = 1) ) AND G.TIPDOC IN (29, 30, 31, 33) AND  T.AN * 12 + T.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999') AND G.SEMNIFICATIE IN (310, 330, 410, 430, 500, 600)
  union ALL
  SELECT O.CODOBLIGPIF, O.CODPART, N.AN, N.LUNA, 0 AS CODINTR, 0 AS CODIES, 0 AS CODTREZOR, 0 AS CODCOMPENS, N.CODNC
  FROM OBLIGPIF O
      LEFT JOIN GENERAL G ON  G.CODGENERAL = O.CODGENERAL
      LEFT JOIN NC1 N1 ON  N1.CODNC1 = G.CODDOC
      LEFT JOIN NC N ON  N.CODNC = N1.CODNC
  WHERE O.SEMNIFICATIE IN (1200, 1201, 1250, 1251) AND  N.AN * 12 + N.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
  union ALL
  SELECT O.CODOBLIGPIF, O.CODPART, C.AN, C.LUNA, 0 AS CODINTR, 0 AS CODIES, 0 AS CODTREZOR, C.CODCOMPENS, 0 AS CODNC
  FROM OBLIGPIF O
      LEFT JOIN GENERAL G ON  G.CODGENERAL = O.CODGENERAL
      LEFT JOIN COMPENS C ON  C.CODCOMPENS = G.CODDOC
  WHERE O.SEMNIFICATIE IN (1301, 1303, 1351) AND  C.AN * 12 + C.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
  )
  LOOP
    BEGIN
      SELECT COALESCE( REST, 0)
      INTO aREST
      FROM OBLIGPIFLUNA
      WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF AND  AN = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999') AND  LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999');
    EXCEPTION WHEN OTHERS THEN
      aREST := 0;
    END;

    UPDATE OBLIGPIF SET VALOARE = aREST WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;

    SELECT COUNT( *) INTO NR FROM SOLDINI WHERE CODPART = V_REC.CODPART;
    IF  NR = 0 THEN
      INSERT INTO SOLDINI(CODSOLDINI, CODPART) VALUES(NEXTVAL('SEQ_SOLDINI_CODSOLDINI'), V_REC.CODPART);
    END IF;

    IF  COALESCE( V_REC.CODINTR, 0) &lt;&gt; 0 THEN
      UPDATE INTRARI
      SET
      AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
      LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
      WHERE
       CODINTR = V_REC.CODINTR;
    END IF;

    IF  COALESCE( V_REC.CODIES, 0) &lt;&gt; 0 THEN
      UPDATE IESIRI
      SET
      AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
      LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
      WHERE
       CODIES = V_REC.CODIES;
    END IF;

    IF  COALESCE( V_REC.CODTREZOR, 0) &lt;&gt; 0 THEN
      UPDATE TREZOR
      SET
      AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999'),
      LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
      WHERE
       CODTREZOR = V_REC.CODTREZOR;

      BEGIN
        SELECT COALESCE( T1.CODTREZOR1, 0), COALESCE( O.SEMNIFICATIE, 0)
        INTO aCODTREZOR1, aSEMNIF
        FROM OBLIGPIF O, GENERAL G, TREZOR1 T1
        WHERE O.CODOBLIGPIF = V_REC.CODOBLIGPIF AND  G.CODGENERAL = O.CODGENERAL AND O.SEMNIFICATIE IN (500, 600) AND  T1.CODTREZOR1 = G.CODDOC;
      EXCEPTION WHEN OTHERS THEN
        aSEMNIF := 0;
      END;

      IF aSEMNIF IN (500, 600) THEN
        UPDATE TREZOR1 SET VALDOC = aREST WHERE CODTREZOR1 = aCODTREZOR1;
      END IF;
    END IF;

    IF  COALESCE( V_REC.CODCOMPENS, 0) &lt;&gt; 0 THEN
      UPDATE COMPENS
      SET
      AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
      LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
      WHERE
       CODCOMPENS = V_REC.CODCOMPENS;
    END IF;

    IF  COALESCE( V_REC.CODNC, 0) &lt;&gt; 0 THEN
      UPDATE NC
      SET
      AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
      LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
      WHERE
       CODNC = V_REC.CODNC;

      UPDATE NC1
      SET
      AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
      LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
      WHERE
       CODNC = V_REC.CODNC;
    END IF;

    FOR V_RECSTINGERI IN
    (
    SELECT S.CODSTINGERE, O_STINGATOR.CODOBLIGPIF, O_STINGATOR.CODGENERAL, T.AN, T.LUNA, T.CODTREZOR
    FROM STINGERE S
        LEFT JOIN OBLIGPIF O_STINGATOR ON  O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
        LEFT JOIN GENERAL G ON  G.CODGENERAL = O_STINGATOR.CODGENERAL
        LEFT JOIN TREZOR1 T1 ON  T1.CODTREZOR1 = G.CODDOC
        LEFT JOIN TREZOR T ON  T.CODTREZOR = T1.CODTREZOR
    WHERE S.CODSTINSPIF = V_REC.CODOBLIGPIF AND  T.OPERAT = 1 AND G.TIPDOC IN (29, 30, 31, 33) AND  T.AN * 12 + T.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
    )
    LOOP
      DELETE FROM STINGERE WHERE CODSTINGERE = V_RECSTINGERI.CODSTINGERE;
      DELETE FROM GENERAL  WHERE CODGENERAL  = V_RECSTINGERI.CODGENERAL;
      DELETE FROM OBLIGPIF WHERE CODOBLIGPIF = V_RECSTINGERI.CODOBLIGPIF;

      UPDATE TREZOR1
      SET
      AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
      LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
      WHERE
       CODTREZOR = V_RECSTINGERI.CODTREZOR;

      UPDATE TREZOR
      SET
      AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
      LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
      WHERE
       CODTREZOR = V_RECSTINGERI.CODTREZOR;
    END LOOP;

    FOR V_RECSTINGERI IN
    (
    SELECT S.CODSTINGERE, O_STINGATOR.CODOBLIGPIF, C.AN, C.LUNA, C.CODCOMPENS, O_STINGATOR.CODGENERAL
    FROM STINGERE S
        LEFT JOIN OBLIGPIF O_STINGATOR ON  O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
        LEFT JOIN GENERAL G ON  G.CODGENERAL = O_STINGATOR.CODGENERAL
        LEFT JOIN COMPENS C ON  C.CODCOMPENS = G.CODDOC
    WHERE S.CODSTINSPIF = V_REC.CODOBLIGPIF AND G.TIPDOC IN (28) AND  C.AN * 12 + C.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
    )
    LOOP
      UPDATE STINGERE SET VALOARE = 0           WHERE CODSTINGERE = V_RECSTINGERI.CODSTINGERE;
      UPDATE OBLIGPIF SET VALOARE = 0, REST = 0 WHERE CODOBLIGPIF = V_RECSTINGERI.CODOBLIGPIF;
      UPDATE GENERAL  SET TVA = 0               WHERE CODGENERAL  = V_RECSTINGERI.CODGENERAL;

      UPDATE COMPENS
      SET
      AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
      LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
      WHERE
       CODCOMPENS = V_RECSTINGERI.CODCOMPENS;
    END LOOP;

    FOR V_RECSTINGERI IN
    (
    SELECT S.CODSTINGERE, O_STINGATOR.CODOBLIGPIF, I.AN, I.LUNA, I.CODINTR, O_STINGATOR.CODGENERAL
    FROM STINGERE S
        LEFT JOIN OBLIGPIF O_STINGATOR ON  O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
        LEFT JOIN GENERAL G ON  G.CODGENERAL = O_STINGATOR.CODGENERAL
        LEFT JOIN INTRARI I ON  I.CODINTR = G.CODDOC
    WHERE S.CODSTINSPIF = V_REC.CODOBLIGPIF AND  I.OPERAT = 1 AND G.SEMNIFICATIE IN (111) AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
    )
    LOOP
      UPDATE STINGERE SET VALOARE = 0           WHERE CODSTINGERE = V_RECSTINGERI.CODSTINGERE;
      UPDATE OBLIGPIF SET VALOARE = 0, REST = 0 WHERE CODOBLIGPIF = V_RECSTINGERI.CODOBLIGPIF;
      UPDATE GENERAL  SET TVA = 0               WHERE CODGENERAL  = V_RECSTINGERI.CODGENERAL;

      UPDATE INTRARI
      SET
      AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
      LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
      WHERE
       CODINTR = V_RECSTINGERI.CODINTR;
    END LOOP;

    FOR V_RECSTINGERI IN
    (
    SELECT S.CODSTINGERE, O_STINGATOR.CODOBLIGPIF, I.AN, I.LUNA, I.CODIES, O_STINGATOR.CODGENERAL
    FROM STINGERE S
        LEFT JOIN OBLIGPIF O_STINGATOR ON  O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
        LEFT JOIN GENERAL G ON  G.CODGENERAL = O_STINGATOR.CODGENERAL
        LEFT JOIN IESIRI I ON  I.CODIES = G.CODDOC
    WHERE S.CODSTINSPIF = V_REC.CODOBLIGPIF AND  I.OPERAT = 1 AND G.SEMNIFICATIE IN (211) AND  I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
    )
    LOOP
      UPDATE STINGERE SET VALOARE = 0           WHERE CODSTINGERE = V_RECSTINGERI.CODSTINGERE;
      UPDATE OBLIGPIF SET VALOARE = 0, REST = 0 WHERE CODOBLIGPIF = V_RECSTINGERI.CODOBLIGPIF;
      UPDATE GENERAL  SET TVA = 0               WHERE CODGENERAL  = V_RECSTINGERI.CODGENERAL;

      UPDATE IESIRI
      SET
      AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
      LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
      WHERE
       CODIES = V_RECSTINGERI.CODIES;
    END LOOP;
  END LOOP;

  UPDATE TREZOR1
  SET
  AN   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI'  , true)),'999999999999999999'),
  LUNA = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999')
  WHERE
   INITIALIZARI = 1;

  FOR V_REC IN (SELECT CODTREZOR1, T.AN, T.LUNA FROM TREZOR1 T1, TREZOR T WHERE T.CODTREZOR = T1.CODTREZOR) LOOP
    UPDATE TREZOR1
    SET
    AN   = V_REC.AN,
    LUNA = V_REC.LUNA
    WHERE
     CODTREZOR1 = V_REC.CODTREZOR1;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_bcar_salveazamp</obj_name>
  <obj_hashval>fa7e531adf651e9da8860b815a415913</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_bcar_salveazamp(acodpart numeric, acodsediu numeric, vcodobiect numeric, atipbcar numeric, aobs character varying, OUT acodmpbcar numeric)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCodObiect numeric(20);
  aCant numeric(20,7);
  aOldPret numeric(20,7);
  aOldTVA  numeric(20,7);
  CursPUVAL numeric(20,7);
  UrmarirePUVAL varchar(5);
  aTipTVA varchar(5);
  aTVA numeric(20,7);
  aProcTVA numeric(20,7);
  aVALDOC     numeric(20, 7);
  aTVADOC     numeric(20, 7);
  aCODGENERAL numeric(20);
  aVALOBLIG   numeric(20, 7);
  aMONEDA     numeric(20);
  NR          numeric(5);
  aPRETORIG   numeric(20,7);
  aVALDISCDOC numeric(20, 7);
  aTVADISCDOC numeric(20, 7);
  v_rec       record;
  V_REC_OBLIG record;
begin
  --Florin 26.11.2025 - fixat 67430
  --Florin 01.10.2025
  select nextval('seq_mpbcar_codmpbcar') into aCodMPBCAR;
  insert into mpbcar(codmpbcar,
                     userid,
                     datacreare,
                     codpart,
                     codsediu,
                     tipbcar,
                     codobiect,
                     obs)
  values(aCodMPBCAR,
         GETUSERID(),
         current_date,
         aCodPart,
         aCodSediu,
         aTipBCAR,
         vCodObiect,
         aObs);
  insert into mpbcar1(codmpbcar1,
                      codmpbcar,
                      codbcar,
                      nrdoc,
                      datadoc,
                      denobiect,
                      codobiect,
                      netkg,
                      utilkg,
                      pretachiz,
                      pretuscare,
                      pretlastas,
                      tipbcar,
                      pretachiznou,
                      codcontract1,
                      moneda,
                      curs,
                      iaumiditate,
                      iastraine,
                      iaincoltit,
                      iahectolitrica,
                      iagluten,
                      iafuzaritate,
                      iacadere,
                      iadeformare,
                      iasticlozitate,
                      iasparturi,
                      iaproteina,
                      iaaflatoxina,
                      iaatac_plosnita,
                      iacontinut_ulei,
                      iaaciditate,
                      iasistave,
                      iarefractie,
                      iaindice_w,
                      iatoxina_don,
                      iaboabe_toxice)
  select nextval('seq_mpbcar1_codmpbcar1'),
         acodmpbcar,
         codbcar,
         nrdoc,
         datadoc,
         denobiect,
         codobiect,
         netkg,
         utilkg,
         pretachiz,
         pretuscare,
         pretlastas,
         tipbcar,
         pretachiznou,
         codcontract1,
         moneda,
         curs,
         iaumiditate,
         iastraine,
         iaincoltit,
         iahectolitrica,
         iagluten,
         iafuzaritate,
         iacadere,
         iadeformare,
         iasticlozitate,
         iasparturi,
         iaproteina,
         iaaflatoxina,
         iaatac_plosnita,
         iacontinut_ulei,
         iaaciditate,
         iasistave,
         iarefractie,
         iaindice_w,
         iatoxina_don,
         iaboabe_toxice
  from tmp_bcar_man1;
  insert into mpbcar2(codmpbcar2,
                      codmpbcar,
                      iaumiditate,
                      iastraine,
                      iaincoltit,
                      iahectolitrica,
                      iagluten,
                      iafuzaritate,
                      iacadere,
                      iadeformare,
                      iasticlozitate,
                      iasparturi,
                      iaproteina,
                      iaaflatoxina,
                      iaatac_plosnita,
                      iacontinut_ulei,
                      iaaciditate,
                      iasistave,
                      iarefractie,
                      iaindice_w,
                      iatoxina_don,
                      iaboabe_toxice)
  select nextval('seq_mpbcar2_codmpbcar2'),
         acodmpbcar,
         iaumiditate,
         iastraine,
         iaincoltit,
         iahectolitrica,
         iagluten,
         iafuzaritate,
         iacadere,
         iadeformare,
         iasticlozitate,
         iasparturi,
         iaproteina,
         iaaflatoxina,
         iaatac_plosnita,
         iacontinut_ulei,
         iaaciditate,
         iasistave,
         iarefractie,
         iaindice_w,
         iatoxina_don,
         iaboabe_toxice
  from tmp_bcar_man2;
  if aTipBCAR = 0 then
    for v_rec in (select m1.codbcar, i1.codintr1, i.codintr, m1.pretachiznou pret, i.an, i.luna, i.datadoc, cf.codfiscal cf, i1.cant, i.curs, i.tipdoc
                  from tmp_bcar_man1 m1
                       left join intrari1 i1 on i1.codintr1 = m1.coddoc1
                       left join intrari i on i.codintr = i1.codintr and i.tipdoc = m1.tipdoc
                       LEFT JOIN NPARTCODFISC CF ON CF.COD_CODFISCAL = I.CODFISCAL
                 ) loop
      update bcar set pretachiz = v_rec.pret where codbcar = v_rec.codbcar;
      perform NotifyModif(0, v_rec.codbcar, 'BCAR');
      if v_rec.codintr &gt; 0 then
        perform NotifyModif(0, v_rec.codbcar, 'INTRARI');
        update jurnal1 set dirty = 1 where coddoc = v_rec.codintr and tipdoc = v_rec.tipdoc;
        --actualizez si avizul
        select CodObiect, Cant, PU, TVA into aCodObiect, aCant, aOldPret, aOldTVA
        from intrari1 where CodIntr1 = v_rec.codintr1;

        CursPUVAL := 1;
        SELECT fnc_GetValConstanta('UrmarirePUVAL', v_rec.AN, v_rec.LUNA) INTO UrmarirePUVAL;
        IF UrmarirePUVAL = '1' THEN
          BEGIN
            CursPUVal := (select wme_result from PKG_MONEDE_GETCURSMONEDA(null,
                         fnc_GetValConstanta('MonedaSitV', v_rec.AN, v_rec.LUNA),
                         fnc_GetValConstanta('BancaSitV', v_rec.AN, v_rec.LUNA),
                         TO_CHAR(v_rec.DATADOC, 'dd.mm.yyyy')
                         ));
          EXCEPTION WHEN OTHERS THEN  CursPUVAl := 1;
          END;
        END IF;


        BEGIN
           SELECT fnc_GetValConstanta('AvizFaraTVANeex', getANLUCRU(), getLUNALUCRU()) INTO aTipTVA;
           EXCEPTION WHEN OTHERS THEN aTIPTVA := '0';
        END;
        if aTIPTVA = 1 OR INSTR(UPPER(v_Rec.CF), 'RO') = 0 then aTVA := 0;
        else
          select wme_result from PKG_SELECTARTICOLE_GETPROCENTTVA(null, (select wme_result from PKG_SELECTARTICOLE_GETARTOFOBJECT(null, aCodObiect), v_rec.AN, v_rec.LUNA)) into aProcTVA;
          aTVA := Round(v_rec.Pret * v_rec.Cant * aProcTVA / 100, 6);
        end if;


        update intrari1 I1
        set
          PU       = CASE
                        WHEN coalesce(I1.COEFDISCMAJ, 1) = 0 THEN v_rec.PRET
                        ELSE v_Rec.Pret * coalesce(I1.COEFDISCMAJ, 1)
                      END,
          PRETORIG = v_Rec.pret,
          TVA = aTVA
        where
          CodIntr1 = v_rec.codintr1;

        UPDATE INTRARI I
        SET
          VALDOC = coalesce((SELECT SUM( coalesce(PU, 0) * coalesce(CANT, 0) + coalesce(TVA, 0)) FROM INTRARI1 I1 WHERE I1.CODINTR = v_rec.codintr), 0),
          TVADOC = coalesce((SELECT SUM( coalesce(TVA, 0)) FROM INTRARI1 I1 WHERE I1.CODINTR = v_rec.codintr), 0)
        WHERE
          I.CODINTR = v_rec.codintr;

      -- RECALCULEZ OBLIGATIILE PE 408;
        BEGIN
         SELECT coalesce(VALDOC,0), coalesce(TVADOC,0), coalesce(MONEDA,0)
         INTO
           aVALDOC, aTVADoc, aMONEDA
          FROM
            INTRARI
          WHERE
            CODINTR = v_rec.codintr;
           EXCEPTION WHEN OTHERS THEN aVALDOC := 0; aTVADOC := 0; aTVADOC := 0; aMONEDA := 0;
        END;

        SELECT COUNT(*) INTO NR FROM GENERAL WHERE TIPDOC = 2 AND CODDOC = v_rec.codintr AND SEMNIFICATIE = 140;

        aVALOBLIG := ROUND(aVALDOC - aTVADOC, 2) + ROUND(aTVADOC, 2);

        IF NR = 0 THEN
          SELECT NEXTVAL('SEQ_GENERAL_CODGENERAL') INTO aCODGENERAL;

          INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
          VALUES (aCODGENERAL, 2, v_rec.codintr, aMONEDA, v_rec.Curs, 140);

          INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE, CODPART)
          VALUES (NEXTVAL('SEQ_OBLIGPIF_CODOBLIGPIF'), aCODGENERAL, aVALOBLIG, aVALOBLIG, 6, 140, aCODPART );

        ELSE
          SELECT COUNT(*) INTO NR
          FROM
            OBLIGPIF O,
            GENERAL G
          WHERE
            G.TIPDOC = 2 AND G.CODDOC = v_rec.codintr AND G.SEMNIFICATIE = 140
            AND O.CODGENERAL = G.CODGENERAL;

          IF NR = 0 THEN
            INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE, CODPART)
            VALUES (NEXTVAL('SEQ_OBLIGPIF_CODOBLIGPIF'), (SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = 2 AND CODDOC = v_rec.codintr AND SEMNIFICATIE = 140), aVALDOC, aVALDOC, 6, 140, aCODPART);
          END IF;

          FOR V_REC_OBLIG IN
          (
            SELECT
               O.CODOBLIGPIF,
               O.CODGENERAL
            FROM
              GENERAL G,
              OBLIGPIF O
            WHERE
                  G.TIPDOC = 2
              AND G.CODDOC = v_rec.codintr
              AND G.SEMNIFICATIE = 140
              AND O.CODGENERAL = G.CODGENERAL
           )
           LOOP
             UPDATE OBLIGPIF
             SET
               VALOARE = aVALOBLIG,
               REST    = aVALOBLIG
             WHERE
               CODOBLIGPIF = V_REC_OBLIG.CODOBLIGPIF;
           END LOOP;
        END IF;
      end if;
    end loop;
  else
    for v_rec in (select m1.codbcar, i1.codies1, i.codies, m1.pretachiznou pret, i.an, i.luna, i.datadoc, cf.codfiscal cf, i1.cant, i.curs, i.tipdoc,
                         coalesce(i.custodie,0) custodie, i.tiptva
                  from tmp_bcar_man1 m1
                       left join iesiri1 i1 on i1.codies1 = m1.coddoc1
                       left join iesiri i on i.codies = i1.codies and i.tipdoc = m1.tipdoc
                       LEFT JOIN NPARTCODFISC CF ON CF.COD_CODFISCAL = I.CODFISCAL
                 ) loop
      update jurnal1 set dirty = 1 where coddoc = v_rec.codies and tipdoc = v_rec.tipdoc;
      update bcar set pretachiz = v_rec.pret where codbcar = v_rec.codbcar;
      if v_rec.codies &gt; 0 then
        if (v_rec.custodie = 1)or(v_rec.TipTVA = 2) then
          aTIPTVA := 1;
        else
          BEGIN
             SELECT fnc_GetValConstanta('AvizFaraTVANeex', getANLUCRU(), getLUNALUCRU()) INTO aTipTVA;
             EXCEPTION WHEN OTHERS THEN aTIPTVA := 0;
          END;
        end if;

        if aTIPTVA = 1 then aTVA := 0;
        else
          select PKG_SELECTARTICOLE.GETPROCENTTVA(PKG_SELECTARTICOLE.GETARTOFOBJECT(aCodObiect), v_rec.AN, v_rec.LUNA) into aProcTVA;
          aTVA := v_rec.Pret * v_rec.Cant * aProcTVA / 100;
        end if;

        aPRETORIG := v_rec.PRET;

      /*
        update iesiri1
        set
          PU       = aPret,
          PRETORIG = aPRETORIG,
          TVA      = aTVA
        where
        CodIes1 = aCodLinieAE;
      */
        update iesiri1 i1
        set
          PU       = aPRETORIG * i1.coefdiscmaj,
          PRETORIG = aPRETORIG,
          TVA      = CASE WHEN coalesce(v_rec.TIPTVA, 0) IN (2, 3, 4, 5, 6) THEN 0
                          ELSE aTVA
                     END
        where
          CodIes1 = v_rec.codies1;


        SELECT SUM( coalesce(PU, 0) * coalesce(CANT, 0) + coalesce(TVA, 0)) INTO aVALDOC FROM IESIRI1 I1 WHERE I1.CODIES = v_rec.codies;
        SELECT SUM( coalesce(TVA, 0)) INTO aTVADOC FROM IESIRI1 I1 WHERE I1.CODIES = v_rec.codies;

        SELECT SUM( coalesce(PU, 0) * coalesce(CANT, 0)  * coalesce(PROCDISC, 0)/100) INTO aVALDISCDOC FROM IESIRI1 I1 WHERE I1.CODIES = v_rec.codies;
        SELECT SUM( coalesce(TVA, 0) *  coalesce(PROCDISC, 0)/100) INTO aTVADISCDOC FROM IESIRI1 I1 WHERE I1.CODIES = v_rec.codies;

        UPDATE IESIRI I
        SET
          VALDOC      = coalesce(aVALDOC, 0) + coalesce(aVALDISCDOC,0) + coalesce(aTVADISCDOC,0),
          TVADOC      = coalesce(aTVADOC, 0) + coalesce(aTVADISCDOC,0),
          VALDISCOUNT = coalesce(aVALDISCDOC,0),
          TVADISCOUNT = coalesce(aTVADISCDOC,0)
        WHERE
          I.CODIES = v_rec.codies;

      -- RECALCULEZ OBLIGATIILE PE 418;
        BEGIN
         SELECT coalesce(VALDOC,0),  coalesce(MONEDA,0)
         INTO
           aVALDOC, aMONEDA
          FROM
            IESIRI
          WHERE
            CODIES = v_rec.codies;
           EXCEPTION WHEN OTHERS THEN aVALDOC := 0;aMONEDA := 0;
          END;

        SELECT COUNT(*) INTO NR FROM GENERAL WHERE TIPDOC = 20 AND CODDOC = v_rec.codies AND SEMNIFICATIE = 240;

        IF NR = 0 THEN
          SELECT NEXTVAL('SEQ_GENERAL_CODGENERAL') INTO aCODGENERAL;

          INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
          VALUES (aCODGENERAL, 20, v_rec.codies, aMONEDA, v_rec.CURS, 240);

          INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE, CODPART)
          VALUES (NEXTVAL('SEQ_OBLIGPIF_CODOBLIGPIF'), aCODGENERAL, aVALDOC, aVALDOC, 7, 240, aCODPART);

        ELSE
          SELECT COUNT(*) INTO NR
          FROM
            OBLIGPIF O,
            GENERAL G
          WHERE
            G.TIPDOC = 20 AND G.CODDOC = v_rec.codies AND G.SEMNIFICATIE = 240
            AND O.CODGENERAL = G.CODGENERAL;

          IF NR = 0 THEN
            INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE, CODPART)
            VALUES (NEXTVAL('SEQ_OBLIGPIF_CODOBLIGPIF'), (SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = 20 AND CODDOC = v_rec.codies AND SEMNIFICATIE = 240), aVALDOC, aVALDOC, 7, 240, aCODPART);
          END IF;

          FOR V_REC_OBLIG IN
          (
            SELECT
               O.CODOBLIGPIF,
               O.CODGENERAL
            FROM
              GENERAL G,
              OBLIGPIF O
            WHERE
                  G.TIPDOC = 20
              AND G.CODDOC = v_rec.codies
              AND G.SEMNIFICATIE = 240
              AND O.CODGENERAL = G.CODGENERAL
           )
           LOOP
             UPDATE OBLIGPIF
             SET
               VALOARE = aVALDOC,
               REST    = aVALDOC
             WHERE
               CODOBLIGPIF = V_REC_OBLIG.CODOBLIGPIF;
           end loop;
         end if;
     end if;
   end loop;
  end if;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_iesiri_total_count_semnif</obj_name>
  <obj_hashval>fc567230f5d3ea46a59fc1fadc0c1c8e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_iesiri_total_count_semnif(asemnif numeric)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
DECLARE
 nr NUMERIC(20, 7) := 0;
BEGIN
  --Florin 31.07.2025
  BEGIN
    SELECT CODOBLIGPIF INTO NR FROM TMP_OBLIGPIF_INITIAL WHERE SEMNIFICATIE = aSEMNIF;
    --SELECT COUNT(*) INTO NR FROM TMP_OBLIGPIF_INITIAL WHERE ICONT = aICONT AND NVL(CURS, 0) = NVL(aCURS, 0);
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  RETURN nr;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_restsitlistgest_setparams</obj_name>
  <obj_hashval>c41ab3e9cd7b413352599168ba3d8a58</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_restsitlistgest_setparams(acodrestaurant numeric, adatastart character varying, adataend character varying, aid numeric, aver numeric, pcodjob1 numeric DEFAULT 0)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 21.05.2025
  PERFORM pkg_list_struct_SetTableSpec((current_setting('PKG_LIST_BASE_RESTSITLISTGEST.gSuplCols', true)));
  PERFORM pkg_list_struct_AdunaColoanele();
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>timp</obj_name>
  <obj_hashval>746e0d688fe28855ae9950cc6b14afc6</obj_hashval>
  <obj_text>CREATE TABLE timp (
  "timp" character varying(30)
);</obj_text>
</row>

<row>
  <obj_type>TABLE</obj_type>
  <obj_name>x</obj_name>
  <obj_hashval>8db425cf0817d8cd2ab13924a39d4263</obj_hashval>
  <obj_text>CREATE TABLE x (
  "view_name" character varying(30),
  "test" text
);</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_eudr_setjoinuri</obj_name>
  <obj_hashval>fc797b628e26094d6b636d93882ce7e6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_eudr_setjoinuri()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 12.12.2025
  perform Pkg_List_Struct_SetTableSpec(current_setting('PKG_LIST_BASE_EUDR.gSuplCols', true));
  perform pkg_list_struct_AdunaColoanele();
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_servfact_sp_lockrecord</obj_name>
  <obj_hashval>bb499701240796eb84281c25c1b0f976</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_servfact_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CODSERVFACT INTO Tmp FROM SERVFACT WHERE CODSERVFACT = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_intrari_for_jurnal</obj_name>
  <obj_hashval>a889459c73f2f5320d91f3758d786401</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_intrari_for_jurnal(startrec numeric, endrec numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC            RECORD;
  NR               double precision := 0;
  LUNAREF          REFCURSOR;
  IOPART1REC       RECORD;
  aCODSUBUNITSTINS numeric;
  TIPINTR          numeric;
  aCurs            double precision;
BEGIN
  --Florin 12.11.2025 - sinc. Oracle
  --Florin 06.11.2025 - sinc. Oracle
  --Florin 13.11.2023 - sinc. Oracle
  --Florin 24.10.2023 - sinc. Oracle
  --Stef 03.03.2023
  --Florin 29.06.2022 - fnc_getprocenttvaart
  --Laura 27.01.2022 - sinc. Oracle (29.12.2021)
  PERFORM PKG_SERVICE_EMPTY_DOCUMENTE_FOR_JURNAL();

  INSERT INTO TMP_INTRARI(CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, NRDOC, DATADOC, PARTENER, NRAVIZ, RotEFact, CARNETDOC, VALDOC, TVADOC, MAJORARI, AN, LUNA, OBS, SATELIT, COMPLEX, CODSUBUNIT, CODFISCAL, CONTSUPLIM, SERIADOC, BUGETARE, VALSUPLIM, TIPREPSUPLIM, CODLOCATIE, TIPFACTURA, CODGESTPROD, MONEDA, CURS, SUBUNITATEA, TVAIncasare, Prorata, TIPTVA)
  SELECT CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, NRDOC, DATADOC, PARTENER, NRAVIZ, RotEFact, CARNETDOC, VALDOC, TVADOC, MAJORARI, AN, LUNA, OBS, SATELIT, COMPLEX, CODSUBUNIT, CODFISCAL, CONTSUPLIM, SERIADOC, BUGETARE, VALSUPLIM, TIPREPSUPLIM, CODLOCATIE, TIPFACTURA, CODGESTPROD, MONEDA, CURS, SUBUNITATEA, TVAIncasare, Prorata, TIPTVA
  FROM (SELECT row_number() over() AS RN, S.*
        FROM (SELECT I.CODINTR, TIPDOC, I.ANULAT, I.BLOCAT, I.OPERAT, PREFIXDOC, NRDOC, DATADOC, PARTENER,
                     NRAVIZ, RotEFact, CARNETDOC, VALDOC, TVADOC, MAJORARI, AN, LUNA, I.OBS, SATELIT, COMPLEX,
                     CODSUBUNIT, CODFISCAL, CONTSUPLIM, SERIADOC, BUGETARE, VALSUPLIM, TIPREPSUPLIM,
                     CODLOCATIE, TIPFACTURA, CODGESTPROD, I.MONEDA, I.CURS, I.SUBUNITATEA, I.TVAIncasare,
                     I.Prorata, I.TIPTVA
              FROM INTRARI I
              WHERE AN * 12 + LUNA = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X)
                AND PKG_SERVICE_IS_DIRTY_DOC(I.TIPDOC, I.CODINTR) = 1
              ORDER BY CODINTR
             ) S
       ) A_PG
  WHERE RN &gt;= STARTREC AND  RN &lt;= ENDREC;

  DELETE FROM INTRARI1_MAN;
  INSERT INTO INTRARI1_MAN
  (SELECT * FROM INTRARI1 WHERE CODINTR IN (SELECT CODINTR FROM TMP_INTRARI));

  INSERT INTO TMP_DVI(CODDVI, CODINTR, CODVAMA, NRDOC, DATADOC, CONTCHELT, CONTTVA, TAXEINCLUSE, FISAVAMA, TAXEPECHELT, TIPREPSUPLIM, VALSUPLIM, CONTSUPLIM, OBS, TIPIMPORT, VALDOCVAMA, TVADOCVAMA)
  SELECT CODDVI, CODINTR, CODVAMA, NRDOC, DATADOC, CONTCHELT, CONTTVA, TAXEINCLUSE, FISAVAMA, TAXEPECHELT, TIPREPSUPLIM, VALSUPLIM, CONTSUPLIM, OBS, TIPIMPORT, VALDOCVAMA, TVADOCVAMA
  FROM DVI WHERE CODINTR IN (SELECT CODINTR FROM TMP_INTRARI);

  INSERT INTO TMP_INTRARI1(CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, UMSEC, AN, LUNA, CodCentru, CONTSERV, CONTDISCOUNT, GESTACT, CODOBIECT, PRETORIG, PU, CANT, TVA, ADDIM, RESTFACT, NRCERTIF, TG, PUMAXIMAL, PURIDICATA, PROCADAOS, FURNAVIZSUBUNIT, DATAACHIZAVIZSUBUNIT, CODOBLIGSTORNO, CURSFACTURAAVANS, DENUM, VALOARE, PARITATE, PROCTVA, GESTIMPLICITA, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2, CODCMDINT1, DENOBIECT, SIMBOLCONTSERV, TVANEDED, ICONTPART, CODANALIZANOD, IMPOZABIL)
  SELECT *
  FROM (SELECT I1.CODINTR1, I1.CODINTR, I1.INDEXLOCAL, I1.TIPLINIE, I1.UMSEC, I1.AN, I1.LUNA, i1.CodCentru,
               I1.CONTSERV, I1.CONTDISCOUNT, I1.GESTACT, I1.CODOBIECT, I1.PRETORIG, I1.PU * COALESCE( U1.PARITATE, 1),
               I1.CANT / COALESCE( U1.PARITATE, 1), I1.TVA, I1.ADDIM, I1.RESTFACT, I1.NRCERTIF, I1.TG,
               I1.PUMAXIMAL, I1.PURIDICATA, I1.PROCADAOS, I1.FURNAVIZSUBUNIT, I1.DATAACHIZAVIZSUBUNIT,
               I1.CODOBLIGSTORNO, I1.CURSFACTURAAVANS,
               CASE WHEN I1.TIPLINIE IN ('G', 'T') THEN '%' ELSE U1.DEN_UM1 END ,
               (CASE WHEN UPPER( I1.TIPLINIE) IN ('=', 'S', 'V') THEN I1.CANT * I1.PU ELSE I1.RESTFACT END ) ,
               U1.PARITATE,
               CASE WHEN UPPER( I1.TIPLINIE) IN ('=', 'S', 'V') THEN fnc_getprocenttvaart(A.CODARTICOL, X.ANLUCRU, X.LUNALUCRU)
                    ELSE 0
               END ,
               A.GESTIMPLICITA, NART1LUNA.CODTVA, NART1LUNA.CODACCIZE, NART1LUNA.CODTAXA1, NART1LUNA.CODTAXA2,
               I1.CODCMDINT1, O.DENUMIRE,
               (CASE WHEN  I1.CODOBIECT &lt;&gt; 0 AND UPPER( I1.TIPLINIE) IN ('G', 'T') THEN '(' || C.SIMBOL || ')'
                     WHEN UPPER( I1.TIPLINIE) IN ('S', 'V') THEN '(' || (SELECT PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT FROM PKG_PLANCONTURI_GETSIMBOLCONT(NULL, CONTSERV)) || ')'
                     ELSE ''
                END ) ,
               I1.TVANEDED, I1.ICONTPART, I1.CODANALIZANOD, I1.IMPOZABIL
        FROM TMP_PKG_GLOBALS X, INTRARI1_MAN I1
            LEFT JOIN NARTOBJ       O         ON  O.CODOBIECT  = I1.CODOBIECT
            LEFT JOIN NART          A         ON  A.CODARTICOL = O.CODARTICOL
            LEFT JOIN TMP_NART_LUNA NART1LUNA ON  NART1LUNA.CODARTICOL = O.CODARTICOL
            LEFT JOIN NUM1          U1        ON  U1.CODUM1 = I1.UMSEC
            LEFT JOIN NCONT         C         ON  C.CODCONT = I1.CODOBIECT
        WHERE EXISTS (SELECT * FROM TMP_INTRARI WHERE CODINTR = I1.CODINTR)
  ) B_PG
  ORDER BY CODINTR , INDEXLOCAL ;

  UPDATE TMP_INTRARI1 I1
  SET
  NRDOCLINK = (SELECT COALESCE(II.PREFIXDOC, '') || coalesce(II.NRDOC::varchar,'')
               FROM INTRLINK IL
                    LEFT JOIN INTRARI1 II1 ON  II1.CodINTR1 = IL.CODLINIEAVIZ
                    LEFT JOIN INTRARI  II  ON  II.CodINTR   = II1.CODINTR
               WHERE I1.TIPLINIE IN ('S', '=') AND  IL.CODINTR1 = I1.CODINTR1
              )
  WHERE I1.TIPLINIE IN ('S', '=') AND  COALESCE( (SELECT TIPDOC FROM TMP_INTRARI WHERE CODINTR = I1.CODINTR), 0) = 9;

  UPDATE TMP_INTRARI1 I1 SET VALOARE = Round(Valoare, 2)
    WHERE  COALESCE((SELECT ROTEFACT FROM TMP_INTRARI WHERE CODINTR = I1.CODINTR), 0) = 1;

  UPDATE TMP_INTRARI1
  SET
  SIMBOLCONTSERV = CASE WHEN  COALESCE( CONTDISCOUNT, 0) &lt;&gt; 0 THEN '(' || (SELECT PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT FROM PKG_PLANCONTURI_GETSIMBOLCONT(NULL, COALESCE( CONTDISCOUNT, 0))) || ')'
                        ELSE ''
                   END
  WHERE TIPLINIE IN ('G', 'T');

  UPDATE TMP_INTRARI1
  SET
  SIMBOLCONTSERV = '(' || (SELECT PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT FROM PKG_PLANCONTURI_GETSIMBOLCONT(NULL, CONTSERV)) || ')'
  WHERE UPPER( TIPLINIE) IN ('S', 'V');

  INSERT INTO TMP_DVI1(CODDVI1, CODDVI, CODINTR1, TIPLINIE, INDEXLOCAL, PRETIMPORT, PUMAXIMAL, CONTDISCOUNT, PRETVALUTA, PRETORIGINAL, TVA, UMSEC, ADDIM, CODOBIECT, CANT, PARITATE, PROCTVA, VALOARE, DENUM, GESTIMPLICITA, TVANEDED)
  SELECT CODDVI1, CODDVI, CODINTR1, TIPLINIE, INDEXLOCAL, PRETIMPORT * COALESCE( U1.PARITATE, 1),
         PUMAXIMAL * COALESCE( U1.PARITATE, 1), CONTDISCOUNT, PRETVALUTA * COALESCE( U1.PARITATE, 1),
         PRETORIGINAL, TVA, UMSEC, ADDIM, CODOBIECT, CANT / COALESCE( U1.PARITATE, 1), U1.PARITATE,
         CASE WHEN TIPLINIE IN ('=', 'S', 'V') THEN fnc_getprocenttvaart((SELECT PKG_SELECTARTICOLE_GETARTOFOBJECT.WME_RESULT FROM PKG_SELECTARTICOLE_GETARTOFOBJECT(NULL, CODOBIECT)), X.ANLUCRU, X.LUNALUCRU)
              ELSE 0
         END ,
         CASE WHEN TIPLINIE IN ('=', 'S', 'V') THEN PRETIMPORT * CANT ELSE VALOARETAXA END ,
         CASE WHEN TIPLINIE IN ('A', 'X', 'C') THEN '%' ELSE U1.DEN_UM1 END ,
         CASE WHEN TIPLINIE IN ('=', 'S', 'V') THEN (SELECT GESTIMPLICITA FROM NART
                                                     WHERE CODARTICOL = (SELECT PKG_SELECTARTICOLE_GETARTOFOBJECT.WME_RESULT FROM PKG_SELECTARTICOLE_GETARTOFOBJECT(NULL, CODOBIECT))
                                                    )
              ELSE 0
         END ,
         TVANEDED
  FROM TMP_PKG_GLOBALS X, DVI1 D1
       LEFT JOIN NUM1 U1 ON  U1.CODUM1 = D1.UMSEC
  WHERE CODDVI IN (SELECT CODDVI FROM TMP_DVI);

  UPDATE TMP_DVI1 D1
  SET
  DENOBIECT = CASE
                 WHEN  TIPLINIE = 'X' THEN 'Taxa vamala'
                 WHEN  TIPLINIE = 'A' THEN 'Accize in vama'
                 WHEN  TIPLINIE = 'C' THEN 'Comision vamal'
                 ELSE COALESCE( (SELECT DENOBIECT FROM TMP_INTRARI1 WHERE CODINTR1 = D1.CODINTR1), '')
              END ,
  INFOSUPLIM = CASE WHEN TIPLINIE IN ('X', 'A', 'C') AND  CONTDISCOUNT &lt;&gt; 0 THEN (SELECT PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT FROM PKG_PLANCONTURI_GETSIMBOLCONT(NULL, CONTDISCOUNT)) END ,
  PROCADAOS = COALESCE( (SELECT PROCADAOS FROM TMP_INTRARI1 WHERE CODINTR1 = D1.CODINTR1), 0),
  (MASA, VOLUM) = (SELECT COALESCE( MASA, 0), COALESCE( VOLUM, 0) FROM NARTOBJ O WHERE O.CODOBIECT = D1.CODOBIECT),
  (CONTSERV, SIMBOLCONTSERV, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2, GESTACT, CODCENTRU, CURSFACTURAAVANS, CODOBLIGSTORNO, CODANALIZANOD)
  =
  (SELECT CONTSERV, SIMBOLCONTSERV, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2, GESTACT, CODCENTRU, CURSFACTURAAVANS, CODOBLIGSTORNO, CODANALIZANOD
   FROM TMP_INTRARI1 I1 WHERE I1.CODINTR1 = D1.CODINTR1);


  INSERT INTO TMP_INTRLINK(CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT, MONEDAAVIZ, CURSAVIZ, PRETAVIZ, CANTAVIZ, TVAAVIZ, SUBUNITAVIZ)
  (SELECT L.CODINTR1, L.CODLINIECOMANDA, L.CODLINIEAVIZ, L.CANT,
          CASE WHEN  I.TIPDOC = 9 THEN AVIZ.MONEDA      ELSE 0 END ,
          CASE WHEN  I.TIPDOC = 9 THEN AVIZ.CURS        ELSE 0 END ,
          CASE WHEN  I.TIPDOC = 9 THEN AVIZ.PU          ELSE 0 END ,
          CASE WHEN  I.TIPDOC = 9 THEN AVIZ.CANT        ELSE 0 END ,
          CASE WHEN  I.TIPDOC = 9 THEN AVIZ.TVA         ELSE 0 END ,
          CASE WHEN  I.TIPDOC = 9 THEN AVIZ.SUBUNITATEA ELSE 0 END
   FROM INTRLINK L
        LEFT JOIN INTRARI1 I1 ON  L.CODINTR1 = I1.CODINTR1
        LEFT JOIN INTRARI  I  ON  I.CODINTR  = I1.CODINTR
        LEFT JOIN (SELECT G.MONEDA, COALESCE( GREG.CURS, G.CURS) AS CURS, S.PU, S.CANT, S.TVA, S.CODINTR1, SM.SUBUNITATEA
                   FROM INTRARI1 S, INTRARI SM, GENERAL G
                        LEFT JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON  GREG.CODGENERAL = G.CODGENERAL
                   WHERE G.TIPDOC = 2 AND  G.CODDOC = S.CODINTR AND  S.CODINTR = SM.CODINTR
                  ) AVIZ ON  AVIZ.CODINTR1 = L.CODLINIEAVIZ
   WHERE EXISTS (SELECT * FROM TMP_INTRARI1 WHERE CODINTR1 = L.CODINTR1)
  );

  INSERT INTO TMP_INTRASTEPTLINK(CODINTR1, CODLINIEFACTURA, CANT)
  (SELECT CODINTR1, CODLINIEFACTURA, CANT FROM INTRASTEPTLINK L WHERE L.CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1));

  UPDATE TMP_INTRASTEPTLINK L
  SET
  (MONEDAFACT, CURSFACT, PRETFACT, TVAFACT, DATAFACT, CONTFACT)
  =
  (SELECT G.MONEDA, COALESCE( GREG.CURS, G.CURS), S.PU, S.TVA, I.DATADOC, S.CONTSERV
   FROM INTRARI1 S, GENERAL G
        LEFT JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON  GREG.CODGENERAL = G.CODGENERAL, INTRARI I
   WHERE S.CODINTR1 = L.CODLINIEFACTURA AND  G.CODDOC = S.CODINTR AND  I.CODINTR = S.CODINTR AND  G.TIPDOC = 9 AND  G.SEMNIFICATIE = 140
  );

  INSERT INTO TMP_NIR(CODNIR, CODINTR, CARNETNIR, NRNIR, DATANIR, GEST, OBS, TIPNIR, ANULAT, BLOCAT, OPERAT, VALOARE)
  (
  SELECT N.CODNIR, N.CODINTR, N.CARNETNIR, N.NRNIR, N.DATANIR, N.GEST, N.OBS, N.TIPNIR, N.ANULAT, N.BLOCAT, N.OPERAT,
         (SELECT SUM( NS.CANTNIR * NS.PRET) FROM NIRSTOC NS WHERE NS.CODNIR = N.CODNIR)
  FROM NIR N
  WHERE EXISTS (SELECT * FROM TMP_INTRARI WHERE CODINTR = N.CODINTR)
  );

  DELETE FROM NIRSTOC_MAN;
  INSERT INTO NIRSTOC_MAN
  SELECT * FROM NIRSTOC NS WHERE EXISTS (SELECT CODNIR FROM TMP_NIR WHERE CODNIR = NS.CODNIR);

  INSERT INTO TMP_NIRSTOC(CODNIRSTOC, CODNIR, CODINTR1, CODDVI1, CANTNIR, UMSEC, CODOBIECT, CODIOART, PRET, ROTLEI, ROTVALUTA, ADAOS, TVA, TIPSERIE, CODLIVR1, REST, PROCENTADAOS, SUPLIMENT, SuplNeded, DENUM, PARITATE, VALOARE, CANTFURN, MG, DIFPRET, ARETVANEEX, PUStandard, ANALITICTVA, CONT, PRETACHIZ, PROVIZION, PROCTVA, CODTVA, DENOBIECT)
  SELECT *
  FROM (SELECT NS.CODNIRSTOC, NS.CODNIR, NS.CODINTR1, NS.CODDVI1, NS.CANTNIR / U1.PARITATE, NS.UMSEC, NS.CODOBIECT,
               NS.CODIOART, NS.PRET * U1.PARITATE, NS.ROTLEI, NS.ROTVALUTA, NS.ADAOS * U1.PARITATE, NS.TVA,
               NS.TIPSERIE, NS.CODLIVR1, NS.REST, NS.PROCENTADAOS, NS.SUPLIMENT, NS.SuplNeded, U1.DEN_UM1,
               U1.PARITATE, NS.CANTNIR * NS.PRET, NS.CANTFURN / U1.PARITATE, IOALUNA.MG, IOALUNA.DIFPRET,
               IOALUNA.ARETVANEEX, IOALUNA.PUStandard, IOALUNA.TVANEEX AS ANALITICTVA, IOALUNA.CONT,
               NS.pret - NS.Adaos, NS.PROVIZION,
               fnc_getprocenttvaart(A.CODARTICOL, X.ANLUCRU, X.LUNALUCRU),
               NART1LUNA.CODTVA, O.DENUMIRE
        FROM Tmp_Pkg_Globals X, NIRSTOC_MAN NS
            LEFT JOIN TMP_INTRARI1   I1        ON  I1.CODINTR1          = NS.CODINTR1
            LEFT JOIN TMP_IOART_LUNA IOALUNA   ON  IOALUNA.CODIOART     = NS.CODIOART
            LEFT JOIN NARTOBJ        O         ON  O.CODOBIECT          = NS.CODOBIECT
            LEFT JOIN NART           A         ON  A.CODARTICOL         = O.CODARTICOL
            LEFT JOIN TMP_NART_LUNA  NART1LUNA ON  NART1LUNA.CODARTICOL = O.CODARTICOL, NUM1 U1
        WHERE EXISTS (SELECT * FROM TMP_NIR WHERE CODNIR = NS.CODNIR) AND  U1.CODUM1 = NS.UMSEC
       ) C_PG
  ORDER BY CODNIR , CODINTR1 ;

  INSERT INTO TMP_LIVR(CODLIVR, CODIES, CODINTR, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT)
  (
  SELECT CODLIVR, CODIES, CODINTR, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT
  FROM LIVR L WHERE EXISTS (SELECT * FROM TMP_INTRARI WHERE CODINTR = L.CODINTR)
  );

  INSERT INTO TMP_LIVR1(CODLIVR1, CODLIVR, CODINTR1, CODDVI1, CODNIRSTOC, CANT, CODNIRSER, PMP, UMSEC, DENUM, PARITATE, GEST, CODIOART, CODOBIECT, DENOBIECT, CODLIVRTOT, TIPLINIE, PRETINREG, ADAOS, TVANEEX, PRETACHIZ, TIPSERIE, CODSERIE, SERIE, PROVIZION)
  (
  SELECT L1.CODLIVR1, L1.CODLIVR, L1.CODINTR1, L1.CODDVI1, L1.CODNIRSTOC, L1.CANT / U1.PARITATE, L1.CODNIRSER, L1.PMP, L1.UMSEC, U1.DEN_UM1, U1.PARITATE,
         CASE WHEN LV.CODLIVR1 IS NULL  THEN N.GEST ELSE LV.GEST END ,
         CASE WHEN LV.CODLIVR1 IS NULL  THEN NS.CODIOART ELSE LV.CODIOART END ,
         CASE WHEN LV.CODLIVR1 IS NULL  THEN NS.CODOBIECT ELSE LV.CODOBIECT END ,
         CASE WHEN LV.CODLIVR1 IS NULL  THEN (SELECT PKG_SELECTARTICOLE_GETDENOBIECTEXT.WME_RESULT FROM PKG_SELECTARTICOLE_GETDENOBIECTEXT(NULL, NS.CODOBIECT))
              ELSE (SELECT PKG_SELECTARTICOLE_GETDENOBIECTEXT.WME_RESULT FROM PKG_SELECTARTICOLE_GETDENOBIECTEXT(NULL, LV.CODOBIECT))
         END ,
         0, '=',
         CASE WHEN LV.CODLIVR1 IS NULL  THEN NS.PRET * U1.PARITATE ELSE LV.PRETINREG * U1.PARITATE END ,
         CASE WHEN LV.CODLIVR1 IS NULL  THEN NS.ADAOS * U1.PARITATE ELSE (LV.PRETINREG - LV.PRETACHIZ)  * U1.PARITATE END ,
         CASE WHEN LV.CODLIVR1 IS NULL  THEN NS.TVA ELSE LV.TVANEEX END ,
         CASE WHEN LV.CODLIVR1 IS NULL  THEN (  NS.PRET - NS.ADAOS)  * U1.PARITATE ELSE LV.PRETACHIZ * U1.PARITATE END ,
         CASE WHEN LV.CODLIVR1 IS NULL  THEN NS.TIPSERIE ELSE 0 END ,
         (SELECT CODSERIE FROM NIRSER WHERE CODNIRSER = L1.CODNIRSER),
         (SELECT SERIE FROM NSERII WHERE CODSERIE = (SELECT CODSERIE FROM NIRSER WHERE CODNIRSER = L1.CODNIRSER)),
         NS.PROVIZION
  FROM LIVR1 L1
      LEFT JOIN NIRSTOC NS ON  NS.CODNIRSTOC = L1.CODNIRSTOC
      LEFT JOIN LIVRVAL LV ON  LV.CODLIVR1   = L1.CODLIVR1
      LEFT JOIN NIR     N  ON  N.CODNIR      = NS.CODNIR
      LEFT JOIN LIVR    L  ON  L.CODLIVR     = L1.CODLIVR, NUM1 U1
  WHERE
     EXISTS (SELECT * FROM TMP_INTRARI WHERE CODINTR = L.CODINTR) AND  U1.CODUM1 = L1.UMSEC
  );

  INSERT INTO TMP_LIVRTOT(CODLIVRTOT, CODLIVR, CODIESINT1, UMSEC, GEST, CODIOART, CODOBIECT, DENUM, PARITATE, DIFPRET, ARETVANEEX, MG, CONT, SUFIXTVANEEX, PROCTVA, CANT, PRETINREG, PRETACHIZ)
    SELECT row_number() over(), CODLIVR, CODIESINT1, UMSEC, GEST, CODIOART, CODOBIECT, DENUM, PARITATE, DIFPRET, ARETVANEEX, MG, CONT, SUFIXTVANEEX, PROCTVA, CANT, PRETINREG, PRETACHIZ
    FROM
    (
      SELECT
          L1.CODLIVR as CODLIVR,
          L1.CODINTR1 as CODIESINT1,
          L1.UMSEC as UMSEC,
          L1.GEST as GEST,
          L1.CODIOART as CODIOART,
          L1.CODOBIECT as CODOBIECT,
          L1.DENUM as DENUM,
          L1.PARITATE as PARITATE,
          IOALUNA.DIFPRET as DIFPRET,
          IOALUNA.ARETVANEEX as ARETVANEEX,
          IOALUNA.MG as MG,
          IOALUNA.CONT as CONT,
          IOALUNA.TVANEEX as SUFIXTVANEEX,
          NTVALUNA.PROCENT as PROCTVA,
          SUM( L1.CANT) as CANT,
          SUM( L1.PRETINREG * L1.CANT) / CASE  WHEN  SUM( L1.CANT)=0 THEN 1 ELSE  SUM( L1.CANT) END as PRETINREG,
          SUM( L1.PRETACHIZ * L1.CANT) / case WHEN  SUM( L1.CANT)=0 THEN 1 ELSE  SUM( L1.CANT) END  as PRETACHIZ
      FROM TMP_LIVR1 L1
        CROSS JOIN TMP_PKG_GLOBALS TG
        LEFT  JOIN TMP_LIVR L         ON  L.CODLIVR    = L1.CODLIVR
        LEFT  JOIN NARTOBJ  O         ON  O.CODOBIECT  = L1.CODOBIECT
        LEFT  JOIN NART     A         ON  A.CODARTICOL = O.CODARTICOL
        LEFT  JOIN IOART1   IOALUNA   ON  IOALUNA.CODIOART = L1.CODIOART AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN IOALUNA.ALSTART AND IOALUNA.ALSTOP
        LEFT  JOIN NGEST    G         ON  G.CODGEST = L1.GEST
        LEFT  JOIN IOART    IO        ON  IO.CODIOART = L1.CODIOART
        LEFT  JOIN NART1    NART1LUNA ON  NART1LUNA.CODARTICOL = O.CODARTICOL AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP
        LEFT  JOIN NTVA1    NTVALUNA  ON  NTVALUNA.CODTVA = NART1LUNA.CODTVA AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN NTVALUNA.ALSTART AND NTVALUNA.ALSTOP
      WHERE L.TIPLIVR &lt;&gt; 5
      GROUP BY
          L1.CODLIVR, L1.CODINTR1, L1.CODOBIECT, L1.UMSEC, L1.GEST, L1.CODIOART, L1.DENUM, L1.PARITATE, IOALUNA.DIFPRET, IOALUNA.ARETVANEEX, IOALUNA.MG, IOALUNA.CONT, IOALUNA.TVANEEX, NTVALUNA.PROCENT

      union all
      --CODLIVRTOT, CODLIVR, CODIESINT1, UMSEC, GEST, CODIOART, CODOBIECT, DENUM, PARITATE, DIFPRET, ARETVANEEX, MG, CONT, SUFIXTVANEEX, PROCTVA, CANT, PRETINREG, PRETACHIZ
      select
        L1.CODLIVR as CODLIVR,
        L1.CODDVI1 as CODIESINT1,
        L1.UMSEC as UMSEC,
        L1.GEST as GEST,
        L1.CODIOART as CODIOART,
        L1.CODOBIECT as CODOBIECT,
        L1.DENUM as DENUM,
        L1.PARITATE as PARITATE,
        IOALUNA.DIFPRET as DIFPRET,
        IOALUNA.ARETVANEEX as ARETVANEEX,
        IOALUNA.MG as MG,
        IOALUNA.CONT as CONT,
        IOALUNA.TVANEEX as SUFIXTVANEEX,
        NTVALUNA.PROCENT as PROCTVA,
        SUM( L1.CANT) as CANT,
        SUM( L1.PRETINREG * L1.CANT) / case WHEN  SUM( L1.CANT)=0 THEN 1 ELSE  SUM( L1.CANT) END as PRETINREG,
        SUM( L1.PRETACHIZ * L1.CANT) / case WHEN  SUM( L1.CANT)=0 THEN 1 ELSE  SUM( L1.CANT) END as PRETACHIZ
      FROM TMP_LIVR1 L1
        CROSS JOIN TMP_PKG_GLOBALS TG
        LEFT JOIN TMP_LIVR L ON  L.CODLIVR    = L1.CODLIVR
        LEFT JOIN NARTOBJ  O ON  O.CODOBIECT  = L1.CODOBIECT
        LEFT JOIN NART     A ON  A.CODARTICOL = O.CODARTICOL
        LEFT JOIN IOART1 IOALUNA ON IOALUNA.CODIOART = L1.CODIOART AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN IOALUNA.ALSTART AND IOALUNA.ALSTOP
        LEFT JOIN NGEST  G ON  G.CODGEST = L1.GEST
        LEFT JOIN IOART IO ON  IO.CODIOART = L1.CODIOART
        LEFT JOIN NART1 NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP
        LEFT JOIN NTVA1 NTVALUNA  ON NTVALUNA.CODTVA = NART1LUNA.CODTVA AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN NTVALUNA.ALSTART AND NTVALUNA.ALSTOP
      WHERE
           L.TIPLIVR = 5
      GROUP BY
        L1.CODLIVR, L1.CODDVI1, L1.CODOBIECT, L1.UMSEC, L1.GEST, L1.CODIOART, L1.DENUM, L1.PARITATE, IOALUNA.DIFPRET, IOALUNA.ARETVANEEX, IOALUNA.MG, IOALUNA.CONT, IOALUNA.TVANEEX, NTVALUNA.PROCENT
      ) als;

  /*INSERT INTO TMP_LIVRTOT
  (
  CODLIVRTOT, CODLIVR, CODIESINT1, UMSEC, GEST, CODIOART, CODOBIECT, DENUM, PARITATE, DIFPRET, ARETVANEEX, MG, CONT, SUFIXTVANEEX, PROCTVA, CANT, PRETINREG, PRETACHIZ
  )
  SELECT *
  FROM (
  SELECT 0, L1.CODLIVR, L1.CODDVI1, L1.UMSEC, L1.GEST, L1.CODIOART, L1.CODOBIECT, L1.DENUM, L1.PARITATE, IOALUNA.DIFPRET, IOALUNA.ARETVANEEX, IOALUNA.MG, IOALUNA.CONT, IOALUNA.TVANEEX, NTVALUNA.PROCENT, SUM( L1.CANT), SUM( L1.PRETINREG * L1.CANT) / CASE

  WHEN  SUM( L1.CANT)=0 THEN 1
  ELSE  SUM( L1.CANT)
  END , SUM( L1.PRETACHIZ * L1.CANT) / CASE

  WHEN  SUM( L1.CANT)=0 THEN 1
  ELSE  SUM( L1.CANT)
  END
  FROM TMP_LIVR1 L1
  LEFT JOIN TMP_LIVR L ON  L.CODLIVR = L1.CODLIVR
  LEFT JOIN NARTOBJ O ON  O.CODOBIECT = L1.CODOBIECT
  LEFT JOIN NART A ON  A.CODARTICOL = O.CODARTICOL
  LEFT JOIN (
  SELECT CODIOART, MG, DIFPRET, ARETVANEEX, CONT, TVANEEX
  FROM IOART1 IO1
  WHERE
     IO1.ANSTART * 12 + IO1.LUNASTART = (
  SELECT MAX( IO2.ANSTART * 12 + IO2.LUNASTART)
  FROM IOART1 IO2
  WHERE
     IO2.CODIOART = IO1.CODIOART AND  IO2.ANSTART * 12 + IO2.LUNASTART &lt;= (
  SELECT ANLUCRU * 12 + LUNALUCRU
  FROM TMP_PKG_GLOBALS X
  )
  )
  ) IOALUNA ON  IOALUNA.CODIOART = L1.CODIOART
  LEFT JOIN NGEST G ON  G.CODGEST = L1.GEST
  LEFT JOIN IOART IO ON  IO.CODIOART = L1.CODIOART
  LEFT JOIN (
  SELECT CODARTICOL, CODTVA
  FROM NART1 A1
  WHERE
     A1.ANSTART * 12 + A1.LUNASTART = (
  SELECT MAX( A11.ANSTART * 12 + A11.LUNASTART)
  FROM NART1 A11
  WHERE
     A11.CODARTICOL = A1.CODARTICOL AND  A11.ANSTART * 12 + A11.LUNASTART &lt;= (
  SELECT ANLUCRU * 12 + LUNALUCRU
  FROM TMP_PKG_GLOBALS X
  )
  )
  ) NART1LUNA ON  NART1LUNA.CODARTICOL = O.CODARTICOL
  LEFT JOIN (
  SELECT CODTVA, PROCENT
  FROM NTVA1 T1
  WHERE
     T1.ANSTART * 12 + T1.LUNASTART = (
  SELECT MAX( T11.ANSTART * 12 + T11.LUNASTART)
  FROM NTVA1 T11
  WHERE
     T11.CODTVA = T1.CODTVA AND  T11.ANSTART * 12 + T11.LUNASTART &lt;= (
  SELECT ANLUCRU * 12 + LUNALUCRU
  FROM TMP_PKG_GLOBALS X
  )
  )
  ) NTVALUNA ON  NTVALUNA.CODTVA = NART1LUNA.CODTVA
  WHERE
     L.TIPLIVR = 5
  GROUP BY
    1, L1.CODLIVR, L1.CODDVI1, L1.CODOBIECT, L1.UMSEC, L1.GEST, L1.CODIOART, L1.DENUM, L1.PARITATE, IOALUNA.DIFPRET, IOALUNA.ARETVANEEX, IOALUNA.MG, IOALUNA.CONT, IOALUNA.TVANEEX, NTVALUNA.PROCENT
  ) E_PG
  ORDER BY
    CODLIVR , CODDVI1 ;
    */
  --todo change this
  --UPDATE TMP_LIVRTOT T
  --SET
  --CODLIVRTOT = ROWNUM
  --;

  UPDATE TMP_LIVR1 L1
  SET
  CODLIVRTOT = (SELECT CODLIVRTOT FROM TMP_LIVRTOT
                WHERE CODLIVR = L1.CODLIVR AND  CODIESINT1 = L1.CODINTR1 AND  UMSEC = L1.UMSEC AND  PARITATE = L1.PARITATE AND  GEST = L1.GEST AND  CODIOART = L1.CODIOART
               )
  WHERE (SELECT TIPLIVR FROM TMP_LIVR L WHERE L.CODLIVR = L1.CODLIVR) &lt;&gt; 5;

  UPDATE TMP_LIVR1 L1
  SET
  CODLIVRTOT = (SELECT CODLIVRTOT FROM TMP_LIVRTOT
                WHERE CODLIVR = L1.CODLIVR AND  CODIESINT1 = L1.CODDVI1 AND  UMSEC = L1.UMSEC AND  PARITATE = L1.PARITATE AND  GEST = L1.GEST AND  CODIOART = L1.CODIOART
               )
  WHERE (SELECT TIPLIVR FROM TMP_LIVR L WHERE L.CODLIVR = L1.CODLIVR) = 5;

  FOR V_REC IN
  (
  SELECT Y.*, X.AnLucru ANX, X.LunaLucru LUNAX
  FROM TMP_INTRARI Y, TMP_PKG_GLOBALS X
  WHERE
    Y.TIPDOC IN (1, 2, 3, 5, 4, 9)
  )
  LOOP
    SELECT COUNT( *) INTO NR FROM TMP_IOPARTDOC WHERE CODPART = V_REC.PARTENER;

    IF  NR = 0 THEN
      LUNAREF := (SELECT PKG_NOMPART_GET_RECORD_PART_CARACT_LUNA.WME_RESULT FROM PKG_NOMPART_GET_RECORD_PART_CARACT_LUNA(NULL, V_REC.PARTENER, V_REC.AnX, V_REC.LUNAX));
      LOOP
        FETCH LUNAREF INTO IOPART1REC;
        EXIT  WHEN not FOUND;
        IF  IOPART1REC.CODIOPART1 &gt; 0 THEN
          INSERT INTO TMP_IOPARTDOC(CODPART, CODIOPART1, CODIOPART, CONTFURNIZOR, CONTCLIENT, CONTFURNAVANS, CONTCLIENTAVANS, CONTFURNAVIZ, CONTCLIENTAVIZ, CONTFURNMF, CONTCREDITD, CONTDEBITD, CONTLITIGII, CONTFURNAVS, CONTFURNAVIC, CONTFURNAVIN, CONTTERTI, TvaNeexF, TvaNeexP, TvaNeexI, TVANEEXC, TIP)
          VALUES(V_REC.PARTENER, IOPART1REC.CODIOPART1, IOPART1REC.CODIOPART, IOPART1REC.CONTFURNIZOR, IOPART1REC.CONTCLIENT, IOPART1REC.CONTFURNAVANS, IOPART1REC.CONTCLIENTAVANS, IOPART1REC.CONTFURNAVIZ, IOPART1REC.CONTCLIENTAVIZ, IOPART1REC.CONTFURNMF, IOPART1REC.CONTCREDITD, IOPART1REC.CONTDEBITD, IOPART1REC.CONTLITIGII, IOPART1REC.CONTFURNAVS, IOPART1REC.CONTFURNAVIC, IOPART1REC.CONTFURNAVIN, IOPART1REC.CONTTERTI, IOPART1REC.TvaNeexF, IOPART1REC.TvaNeexP, IOPART1REC.TvaNeexI, IOPART1REC.TVANEEXC, IOPART1REC.TIP);
        END IF;
      END LOOP;
    END IF;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_DVI, TMP_PKG_GLOBALS X) LOOP
    SELECT COUNT( *) INTO NR FROM TMP_IOPARTVAMA WHERE CODPART = V_REC.CODVAMA;
    IF  NR = 0 THEN
      LUNAREF := (SELECT PKG_NOMPART_GET_RECORD_PART_CARACT_LUNA.WME_RESULT FROM PKG_NOMPART_GET_RECORD_PART_CARACT_LUNA(NULL, V_REC.CODVAMA, V_REC.ANLUCRU, V_REC.LUNALUCRU));
      LOOP
        FETCH LUNAREF INTO IOPART1REC;
        EXIT  WHEN  not FOUND;
        IF  IOPART1REC.CODIOPART1 &gt; 0 THEN
          INSERT INTO TMP_IOPARTVAMA(CODPART, CODIOPART1, CODIOPART, CONTFURNIZOR, CONTCLIENT, CONTFURNAVANS, CONTCLIENTAVANS, CONTFURNAVIZ, CONTCLIENTAVIZ, CONTFURNMF, CONTCREDITD, CONTDEBITD, CONTLITIGII, CONTFURNAVS, CONTFURNAVIC, CONTFURNAVIN, CONTTERTI, TvaNeexF, TvaNeexP, TvaNeexI, TVANEEXC, TIP)
          VALUES(V_REC.CODVAMA, IOPART1REC.CODIOPART1, IOPART1REC.CODIOPART, IOPART1REC.CONTFURNIZOR, IOPART1REC.CONTCLIENT, IOPART1REC.CONTFURNAVANS, IOPART1REC.CONTCLIENTAVANS, IOPART1REC.CONTFURNAVIZ, IOPART1REC.CONTCLIENTAVIZ, IOPART1REC.CONTFURNMF, IOPART1REC.CONTCREDITD, IOPART1REC.CONTDEBITD, IOPART1REC.CONTLITIGII, IOPART1REC.CONTFURNAVS, IOPART1REC.CONTFURNAVIC, IOPART1REC.CONTFURNAVIN, IOPART1REC.CONTTERTI, IOPART1REC.TvaNeexF, IOPART1REC.TvaNeexP, IOPART1REC.TvaNeexI, IOPART1REC.TVANEEXC, IOPART1REC.TIP);
        END IF;
      END LOOP;
    END IF;
  END LOOP;

  DELETE FROM TMP_GENERAL;
  INSERT INTO TMP_GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS)
  (
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS
  FROM GENERAL G
  WHERE EXISTS (SELECT CODINTR FROM TMP_INTRARI WHERE CODINTR = G.CODDOC AND  TIPDOC = G.TIPDOC)
  );

  DELETE FROM TMP_OBLIGPIF;
  INSERT INTO TMP_OBLIGPIF(CODOBLIGPIF, CODGENERAL)
  (SELECT CODOBLIGPIF, CODGENERAL FROM OBLIGPIF WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL));

  DELETE FROM TMP_STINGERE;
  INSERT INTO TMP_STINGERE(CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
  (SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE FROM STINGERE WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF));

  FOR V_REC IN
  (
  SELECT S.CODSTINGERE, G.TIPDOC, G.CODDOC, G.SEMNIFICATIE
  FROM TMP_STINGERE S, OBLIGPIF O, GENERAL G
  WHERE
     S.CODSTINSPIF = O.CODOBLIGPIF AND  G.CODGENERAL = O.CODGENERAL
  )
  LOOP
    aCODSUBUNITSTINS := 0;
    IF V_REC.SEMNIFICATIE IN (110) THEN
      BEGIN
        SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM INTRARI WHERE CODINTR = V_REC.CODDOC AND  TIPDOC = V_REC.TIPDOC;
      EXCEPTION WHEN OTHERS THEN
        aCODSUBUNITSTINS := 0;
      END;

      UPDATE TMP_STINGERE SET CODSUBUNITSTINS = aCODSUBUNITSTINS WHERE CODSTINGERE = V_REC.CODSTINGERE;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stocvalini_sp_insertrecord</obj_name>
  <obj_hashval>eb70cd938a06dcb905976ffbaef76b37</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stocvalini_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_STOCVALINI (CODSTOCVALINI) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_carnet_wmeonline</obj_name>
  <obj_hashval>e409780c7159b1dfe4f9e9a0fc611e02</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_carnet_wmeonline(INOUT wme_result numeric, INOUT acodsubunit numeric, INOUT tipmacheta numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCODCARNET numeric := 0;
begin
  BEGIN
    SELECT CODCARNET
    into STRICT aCODCARNET
    FROM DOCCARNETE C
    WHERE
      SUBUNITATEA = aCODSUBUNIT
      AND COALESCE (COMENZIONLINE, 0) = 1 /*limit 1 */
      AND EXISTS (SELECT DL.CODCARNET FROM DOCLINK DL WHERE DL.CODMACHETA = TIPMACHETA AND DL.CODCARNET = C.CODCARNET)
      limit 1;
  EXCEPTION
  WHEN OTHERS THEN
    aCODCARNET := 0;
  END;

  WME_Result := aCODCARNET;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_solduribancilunaprec</obj_name>
  <obj_hashval>bc045b85163b4329e3454bd33940877f</obj_hashval>
  <obj_text>SELECT codbankcont,
    COALESCE(soldlei, 0::numeric) AS soldlei,
    COALESCE(soldvaluta, 0::numeric) AS soldvaluta
   FROM martor.nbanksoldluna
  WHERE an = martor.getanprecedent() AND luna = martor.getlunaprecedenta();</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_intrari_getlastpretachizx</obj_name>
  <obj_hashval>df4674edf6fde0b0d986cd818c4be776</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_intrari_getlastpretachizx(acodobiect numeric, acodintr1 numeric DEFAULT 0, aexclsupl numeric DEFAULT 0)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
DECLARE
  FaraIntrSubunit VARCHAR(5) := '?';
  v_rec record;
BEGIN
  --Florin 18.07.2025
  FaraIntrSubunit := NVL(fnc_GetValConstanta('FaraIntrSubunit', getANLUCRU(), get_LUNALUCRU()), '?');
  FOR V_REC IN (
    SELECT NS.PRET - Nvl(NS.ADAOS,0) - CASE WHEN NVL(aExclSupl,0) = 1 AND NS.CANTNIR &lt;&gt; 0 THEN Nvl(NS.SUPLIMENT,0)/NS.CANTNIR ELSE 0 END PretAchiz
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    WHERE NS.CODOBIECT = aCODOBIECT
      AND ((TIPNIR IN (1, 2, 3, 4, 5, 7, 8, 9, 15)) OR (TIPNIR = 6 AND FaraIntrSubunit = '2' ))
      AND OPERAT = 1 AND ANULAT = 0
      AND (aCodIntr1 &gt; 0 and coalesce(ns.codintr1,0) &lt;&gt; aCodIntr1 or aCodIntr1 = 0)
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.PretAchiz;
  END LOOP;
  RETURN 0;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_nompart_partanaf_actnrregcom</obj_name>
  <obj_hashval>119ef493287dcfdb396f7b21e2e3d602</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_nompart_partanaf_actnrregcom()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  v_rec record;
BEGIN
  --Florin 17.09.2025
  FOR v_rec IN (
    SELECT CODPART, NRREGCOM
    FROM TMP_NPART_ANAF
    WHERE CODPART IS NOT NULL AND NRREGCOM IS NOT NULL
      AND COALESCE(OLD_NRREGCOM, '#') &lt;&gt; COALESCE(NRREGCOM, '#')
  ) LOOP
    UPDATE NPART
    SET REGCOM = v_rec.NRREGCOM
    WHERE CODPART = v_rec.CODPART;
  END LOOP;
  PERFORM pkg_nompart_PartANAF_Init();
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reclamatii_getcarnetdoc_i</obj_name>
  <obj_hashval>aef62b42e3bad2c34b284b94f23b96d2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reclamatii_getcarnetdoc_i(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_RECLAMATII.CARNETDOC_I', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_getmonedareg</obj_name>
  <obj_hashval>56b6a6450c15a0e4f3c02385c95f6c1d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_getmonedareg()
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
begin
  --Bogdan 17.08.2020
  return  current_setting('PKG_REG.moneda_reg', true) :: numeric;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regoss_generatedataxtrimestru</obj_name>
  <obj_hashval>e40699ac5c3ded12994e72c15d0e8bf5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regoss_generatedataxtrimestru(ptrimestrul numeric, pcursreg numeric, pmoneda numeric, pforce numeric DEFAULT 0)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
    dataStartTrim date;
    dataStopTrim date;
    aCursReg NUMERIC(20,7);
    recId NUMERIC;
    recIdx NUMERIC;
    nrRows integer;
    tvaDocRegExistent NUMERIC(20,7);
    tvadocvalExistent NUMERIC(20,7);
    flgModif NUMERIC(1);
    contExistent NUMERIC(20);
    v_rec record;
  BEGIN
    --Florin 06.12.2022 - sinc. Oracle
    --Florin 05.12.2022 - fixat 56437
    --Florin 30.11.2022 - sinc. Oracle (23-28.11.2022)
    --Florin 17.11.2022 - sinc. Oracle (8-16.11.2022)
    --Florin 08.11.2022 - sinc. Oracle
    --Florin 04.11.2022 - sinc. Oracle
    aCursReg := pCursReg;
    SELECT datastart, datastop INTO dataStartTrim, dataStopTrim FROM pkg_regoss_GetDateTrimestru(pTrimestrul, dataStartTrim, dataStopTrim, NULL::NUMERIC);
    begin
      select rs.codregoss into recId  from tmp_regoss rs;
    exception
           when NO_DATA_FOUND then recId := 0;
    end;
    PERFORM pkg_globals_baga_in_x(dataStartTrim::VARCHAR);
    PERFORM pkg_globals_baga_in_x(dataStopTrim::VARCHAR);
    PERFORM pkg_globals_baga_in_x(recId::VARCHAR);
    if dataStartTrim is null or dataStopTrim is null  then
      return;
    end if;
    if recId &lt; 1 OR pForce &gt; 0 then
      delete from tmp_regoss1;
    END IF;
    update tmp_regoss1 set deleted = 1;
    recIdx := 0;
    flgModif := 1;
    if pForce &gt; 0 THEN
      flgModif := 0;
    end if;
    for v_rec in
                      (  select ies.codies as coddoc,
                             ies.tipdoc as tipdoc,
                             ies.tvadoc as tvadoc,
                             ies.tvadoc * coalesce(ies.curs,1) as tvadocval,
                             ies.tvadoc * aCursReg as tvadocreg,
                             ies.moneda,
                             ies.curs,
                             ies.partener as codpart,
                             part.den_part as den_part,
                             COALESCE(ies.seriadoc, '')||' '||COALESCE(ies.nrdoc::varchar, '')||'/'||to_char(ies.datadoc, 'dd.mm.yyyy') as doc,
                             ies.subunitatea as subunitatea,
                             ies.codtvaserv as codtvaserv,
                             tsr1.codtvaserv1 as codtvaserv1,
                             tsr1.codcont as cont,
                             (SELECT wme_result FROM PKG_PLANCONTURI_GETSIMBOLCONT(NULL, tsr1.codcont)) as simbolcont
                      from iesiri ies
                      join npart part on part.codpart = ies.partener
                      join tvaserv1 tsr1 on tsr1.codtvaserv = ies.codtvaserv
                        and getAnLunaLucru() BETWEEN tsr1.ALSTART AND tsr1.ALSTOP
                      join tvaserv tsr on tsr.codtvaserv = ies.codtvaserv
                     where ies.datadoc::DATE between dataStartTrim and dataStopTrim
                       and ies.tiptranzactie = 2
                       and ies.tiptva = 10 and ies.tipdoc = 19
                       and coalesce(ies.anulat,0) = 0
                       and coalesce(ies.operat,0) = 1
                       and coalesce(tsr1.codcont,0) &lt;&gt; 0
                       and ies.moneda = pMoneda ) loop
       select count(*) into nrRows from tmp_regoss1 trs1 where trs1.coddoc = v_rec.CODDOC and trs1.tipdoc = v_rec.TIPDOC;
       if nrRows &gt; 0 THEN
                     select trs1.TVADOCREG, trs1.TVADOCVAL, trs1.cont into tvaDocRegExistent, tvadocvalExistent, contExistent
           from tmp_regoss1 trs1
           where trs1.coddoc = v_rec.CODDOC and trs1.tipdoc = v_rec.TIPDOC LIMIT 1;
           if (abs(tvaDocRegExistent - v_rec.TVADOCREG) &gt; 0.0000001)
           OR (abs(tvadocvalExistent - v_rec.TVADOCVAL) &gt; 0.0000001)
            OR (contExistent &lt;&gt; v_rec.CONT)  then --update existing row
             update tmp_regoss1 trs1
                    set  TVADOCVAL      = v_rec.TVADOCVAL ,
                           TVADOC       = v_rec.TVADOC ,
                           TVADOCREG    = v_rec.TVADOCREG ,
                           CURS         = v_rec.CURS,
                           DIFERENTA    = v_rec.TVADOCREG - v_rec.TVADOCVAL,
                           CODPART      = v_rec.CODPART,
                           DEN_PART     = v_rec.DEN_PART,
                           DOC          = v_rec.DOC,
                           SUBUNITATEA  = v_rec.SUBUNITATEA,
                           CONT         = v_rec.cont,
                           CODTVASERV  = v_rec.CODTVASERV,
                           CODTVASERV1= v_rec.CODTVASERV1,
                           MODIFICARI   = flgModif,
                           DELETED        = 0,
                           SIMBOLCONT = v_rec.SIMBOLCONT
           where trs1.coddoc = v_rec.CODDOC and trs1.tipdoc = v_rec.TIPDOC;
         ELSE
           update tmp_regoss1 trs1 SET DELETED = 0  where trs1.coddoc = v_rec.CODDOC and trs1.tipdoc = v_rec.TIPDOC;
         end if;
       else
       recIdx := recIdx + 1;
       insert into tmp_regoss1 (
                     CODREGOSS1,
                     CODREGOSS ,
                     CODDOC ,
                     TIPDOC ,
                     TVADOCVAL ,
                     TVADOC ,
                     TVADOCREG ,
                     CURS,
                     DIFERENTA,
                     CODPART,
                     DEN_PART,
                     DOC,
                     SUBUNITATEA,
                     CONT,
                     SIMBOLCONT,
                     CODTVASERV,
                     CODTVASERV1,
                     modificari,
                     DELETED)
       values (
                     -1 * recIdx,
                     recId ,
                     v_rec.CODDOC ,
                     v_rec.TIPDOC ,
                     v_rec.TVADOCVAL ,
                     v_rec.TVADOC ,
                     v_rec.TVADOCREG ,
                     v_rec.CURS,
                     v_rec.TVADOCREG - v_rec.TVADOCVAL,
                     v_rec.CODPART,
                     v_rec.DEN_PART,
                     v_rec.DOC,
                     v_rec.SUBUNITATEA,
                     v_rec.CONT,
                     v_rec.SIMBOLCONT,
                     v_rec.CODTVASERV,
                     v_rec.CODTVASERV1,
                     flgModif,
                     0);
            END IF;
     end loop;
    delete from tmp_regoss1 where deleted = 1;
  END;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_datanextreg</obj_name>
  <obj_hashval>d91c96e839fa9b466ae9e16946515aee</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_datanextreg(INOUT wme_result date, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_REGPART.DATANEXTREG'));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regtrezor_sp_gotorecord</obj_name>
  <obj_hashval>dbacb78076712cc0b06f0827b16d402b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regtrezor_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC             RECORD;
  V_REC_TREZOR      RECORD;
  PARAM_REG_DATA    date;
  PARAM_REG_MONEDA  numeric;
  PARAM_REG_CURS    double precision;
  LunaPrecedentaReg numeric;
  AnPrecedentReg    numeric;
  DIFERENTE         numeric := 0;
BEGIN
  --Florin 17.08.2022 - sinc. Oracle
  --Bogdan 18.08.2020
  --Florin 27.02.2021 - inlocuit nvl
  PERFORM PKG_STOC_GENERARE_FACTURI_MAKE_CONFIG_LUNA();
  DELETE FROM TMP_REG;
  INSERT INTO TMP_REG (CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, SimbolMoneda, SimbolBank, Provizion, Luna, An, CodAnaliza, CodCentru, CodAnalizaNod)
  (  SELECT R.CodReg, R.TipReg, R.NrDoc, R.DataDoc, R.CodBank, R.CodMoneda, R.Curs, R.Dirty, R.Obs, R.CodSubunit, M.Simbol, B.Simbol, R.Provizion, R.Luna, R.An, R.CodAnaliza, R.CodCentru, R.CodAnalizaNod
    FROM REG R
        LEFT JOIN NMONEDE M ON  M.CODMONEDA = R.CODMONEDA
        LEFT JOIN NBANK   B ON  B.CODBANK   = R.CODBANK
    WHERE R.CodReg = RecID
    );

  SELECT DataDoc, CodMoneda, Curs
    INTO PARAM_REG_DATA, PARAM_REG_MONEDA, PARAM_REG_CURS
  FROM TMP_REG;

  PERFORM PKG_REG_SetParamsReg( TO_CHAR( PARAM_REG_DATA, 'DD.MM.YYYY'), PARAM_REG_MONEDA, PARAM_REG_CURS::NUMERIC);
  perform set_config('PKG_REGTREZOR.CURS_IN',to_char(PARAM_REG_CURS,'99999999999.9999999'),false);

  PERFORM PKG_GLOBALS_SETLUNATEMP( getAnLucru(), getLunaLucru());
  select  PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA.newan, PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA.newluna
  from PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( getAnLucru(), getLunaLucru(), AnPrecedentReg, LunaPrecedentaReg)
    into AnPrecedentReg, LunaPrecedentaReg;
  PERFORM PKG_GLOBALS_SETLUNAPRECEDENTA( AnPrecedentReg, LunaPrecedentaReg);

  DELETE FROM TMP_REGTREZOR1_MARTOR;
  INSERT INTO TMP_REGTREZOR1_MARTOR( CODBANKCONT, SOLDDOCVAL)
    SELECT CODBANKCONT, SOLDDOCVAL FROM REGTREZOR1 WHERE CODREG = RECID;

  DELETE FROM TMP_REGTREZOR1;
  INSERT INTO TMP_REGTREZOR1 (
      CodRegTrezor1, SoldDoc, SoldDocVal, SoldDocReg, CodBank,
      CodBankCont, Diferenta, Den_Cont, NrCont, Filiala, Credit, SUBUNITATEA)
  (SELECT -1 * row_number() over (),
      T1.SoldValuta,
      T1.SoldLei,
      T1.SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(NULL,NULL)),
      NBC.CodBank,
      T1.CodBankCont,
      T1.SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(NULL,NULL)) - T1.SoldLei,
      NBC.Den_Cont,
      NBC.NrCont,
      NBC.Filiala,
      NBC.Credit,
      NBC.SUBUNITATEA
  FROM (SELECT SoldValuta, SoldLei, CodBankCont FROM V_SOLDURIBANCILUNA ) T1
       INNER JOIN NBANKCONT NBC ON  NBC.CodBankCont = T1.CodBankCont AND coalesce(NBC.FARAREG, 0) = 0
  WHERE
       NBC.CodMoneda = pkg_reg_getmonedareg() AND
       T1.SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(NULL,NULL)) - T1.SoldLei &lt;&gt; 0);

   INSERT INTO TMP_JURNAL (SELECT * FROM JURNAL  WHERE TIPDOC = 45 AND  CODDOC = RECID);
  INSERT INTO TMP_JURNAL1(SELECT * FROM JURNAL1 WHERE TIPDOC = 45 AND  CODDOC = RECID);

  DELETE FROM TMP_RULAJ;
  FOR V_REC in (
          SELECT INTBL.CODBANKCONT, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT
          FROM TMP_REGTREZOR1_MARTOR INTBL LEFT JOIN TMP_REGTREZOR1 OUTTBL ON  OUTTBL.CODBANKCONT = INTBL.CODBANKCONT
          union
          SELECT OUTTBL.CODBANKCONT, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT
          FROM TMP_REGTREZOR1 OUTTBL LEFT JOIN TMP_REGTREZOR1_MARTOR INTBL ON  INTBL.CODBANKCONT = OUTTBL.CODBANKCONT
  ) LOOP
    IF  COALESCE( V_REC.SOLDIN, 0) &lt;&gt; COALESCE( V_REC.SOLDOUT, 0) THEN
      DIFERENTE := 1;
      EXIT ;
    END IF;
  END LOOP;

      IF current_setting('PKG_GLOBALS.ANCURENT', TRUE)::numeric * 12 + current_setting('PKG_GLOBALS.LUNACURENTA', TRUE)::numeric
      &lt;= getANLUCRU() * 12 + getLUNALUCRU() AND  DIFERENTE = 1 THEN
    FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
      UPDATE TMP_JURNAL1 SET DIRTY = 1 WHERE CODJURNAL1 = V_REC.CODJURNAL1;
      UPDATE JURNAL1     set DIRTY = 1 WHERE CODJURNAL1 = V_REC.CODJURNAL1;
    END LOOP;

    FOR V_REC_TREZOR in (
              SELECT T.*
              FROM TREZOR T, NBANKCONT BC
              WHERE
                  TIPDOC IN (29, 30, 31)
                  AND  BC.CODBANKCONT = T.CODBANCA
                  AND  BC.CREDIT = 1
                  AND  EXISTS (SELECT CODBANKCONT FROM (SELECT CODBANKCONT FROM TMP_REGTREZOR1  UNION SELECT CODBANKCONT FROM TMP_REGTREZOR1_MARTOR) A_PG
                               WHERE CODBANKCONT = T.CODBANCA)
                   AND  AN * 12 + LUNA &gt; getAnLucru() * 12 + getLunaLucru()
      ) LOOP
          UPDATE JURNAL1 set DIRTY = 1 where  TIPDOC = V_REC_TREZOR.TIPDOC AND  CODDOC = V_REC_TREZOR.CODTREZOR;
    END LOOP;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regtrezor_sp_postrecords</obj_name>
  <obj_hashval>7e50a301bc2447b5451086a0cf2af018</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regtrezor_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC        RECORD;
  V_REC_SUB    RECORD;
  V_REC_TREZOR RECORD;
  NR           numeric;
  TMP_NR       numeric;
  DIFERENTE    numeric := 0;
  CURS_OUT     double precision;
  Cod1         NUMERIC(20);
BEGIN
  --Florin 22.05.2023 - fixat 58379
  --Florin 10.05.2023 - sinc. Oracle (09.05.2023)
  --Florin 18.08.2022 - fixat 55275
  SELECT CURS INTO CURS_OUT FROM TMP_REG;

  IF  Operation = 0 THEN
    SELECT CodReg INTO RecID FROM TMP_REG;

    UPDATE REG
    SET
    (TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, Provizion, Luna, An, CodAnaliza, CodCentru, CodAnalizaNod)
    =
    (SELECT TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, Provizion, Luna, An, CodAnaliza, CodCentru, CodAnalizaNod
     FROM TMP_REG
    )
    WHERE CodReg = RecID;

    DELETE FROM REGTREZOR1 WHERE CodReg = RecID;
    for v_rec in (select * from tmp_regtrezor1) LOOP
      select NEXTVAL('SEQ_REGTREZOR1_CODREGTREZOR1') into Cod1;
      INSERT INTO REGTREZOR1(CodRegTrezor1, CodReg, SoldDoc, SoldDocVal, SoldDocReg, CodBank, CodBankCont)
      values (Cod1, RecID, v_rec.SoldDoc, v_rec.SoldDocVal, v_rec.SoldDocReg, v_rec.CodBank, v_rec.CodBankCont);
      update tmp_jurnal1 set indexlocal = Cod1 where indexlocal = v_rec.codregtrezor1;
      update tmp_jurnal set indexlocal = Cod1 where indexlocal = v_rec.codregtrezor1;
    END LOOP;

    DELETE FROM JURNAL1 WHERE TIPDOC = 45 AND  CODDOC = RECID AND CODJURNAL1 NOT IN (SELECT CODJURNAL1 FROM TMP_JURNAl1);

    FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
      IF  V_REC.CODJURNAL1 &gt; 0 THEN
        UPDATE JURNAL1
        SET
        CODDOC        = V_REC.CODDOC,
        TIPDOC        = V_REC.TIPDOC,
        INDEXLOCAL    = V_REC.INDEXLOCAL,
        CODBAZAD      = V_REC.CODBAZAD,
        ICONTBAZAD    = V_REC.ICONTBAZAD,
        TIPBAZAD      = V_REC.TIPBAZAD,
        CODBAZAC      = V_REC.CODBAZAC,
        ICONTBAZAC    = V_REC.ICONTBAZAC,
        TIPBAZAC      = V_REC.TIPBAZAC,
        CODDESCRD     = V_REC.CODDESCRD,
        ICONTD        = V_REC.ICONTD,
        TIPCONTD      = V_REC.TIPCONTD,
        ANALITICCONTD = V_REC.ANALITICCONTD,
        CODDESCRC     = V_REC.CODDESCRC,
        ICONTC        = V_REC.ICONTC,
        TIPCONTC      = V_REC.TIPCONTC,
        ANALITICCONTC = V_REC.ANALITICCONTC,
        GEST          = V_REC.GEST,
        VALOARE       = V_REC.VALOARE,
        VALOAREV      = V_REC.VALOAREV,
        OBS           = V_REC.OBS,
        AN            = V_REC.AN,
        LUNA          = V_REC.LUNA,
        DIRTY         = V_REC.DIRTY,
        SUBUNITATEA   = V_REC.SUBUNITATEA,
        DATADOC       = V_REC.DATADOC,
        CODCENTRU     = V_REC.CODCENTRU,
        CODANALIZANOD = V_REC.CODANALIZANOD,
        DOCUMENT      = V_REC.DOCUMENT
        WHERE
         CODJURNAL1 = V_REC.CODJURNAL1;
      ELSE
        INSERT INTO JURNAL1(CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD, CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, DOCUMENT, CODCENTRU, CODANALIZANOD)
        VALUES(NEXTVAL('SEQ_JURNAL1_CODJURNAL1'), RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CODBAZAD, V_REC.ICONTBAZAD, V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD, V_REC.CODBAZAC, V_REC.ICONTBAZAC, V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT, V_REC.CODCENTRU, V_REC.CODANALIZANOD);
      END IF;
    END LOOP;

    DELETE FROM JURNAL WHERE TIPDOC = 45 AND  CODDOC = RECID AND CODJURNAL NOT IN (SELECT CODJURNAL FROM TMP_JURNAl);

    FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
      IF  V_REC.CODJURNAL &gt; 0 THEN
        UPDATE JURNAL
        SET
        CODDOC        = V_REC.CODDOC,
        TIPDOC        = V_REC.TIPDOC,
        INDEXLOCAL    = V_REC.INDEXLOCAL,
        CONTD         = V_REC.CONTD,
        CONTC         = V_REC.CONTC,
        GEST          = V_REC.GEST,
        VALOARE       = V_REC.VALOARE,
        VALOAREV      = V_REC.VALOAREV,
        OBS           = V_REC.OBS,
        AN            = V_REC.AN,
        LUNA          = V_REC.LUNA,
        SUBUNITATEA   = V_REC.SUBUNITATEA,
        DATADOC       = V_REC.DATADOC,
        CODCENTRU     = V_REC.CODCENTRU,
        CODANALIZANOD = V_REC.CODANALIZANOD,
        DOCUMENT      = V_REC.DOCUMENT
        WHERE
         CODJURNAL = V_REC.CODJURNAl;
      ELSE
        INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, DATADOC, DOCUMENT, CODCENTRU, CODANALIZANOD)
        VALUES(NEXTVAL('SEQ_JURNAL_CODJURNAL'), RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT, V_REC.CODCENTRU, V_REC.CODANALIZANOD);
      END IF;
    END LOOP;
  ELSE
    SELECT NEXTVAL('SEQ_REG_CODREG') INTO RecID;

    INSERT INTO REG(CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, Provizion, Luna, An, CodAnaliza, CodCentru, CodAnalizaNod)
    (SELECT RecID, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, Provizion, Luna, An, CodAnaliza, CodCentru, CodAnalizaNod
      FROM TMP_REG
    );

    for v_rec in (select * from tmp_regtrezor1) LOOP
      select NEXTVAL('SEQ_REGTREZOR1_CODREGTREZOR1') into Cod1;
      INSERT INTO REGTREZOR1(CodRegTrezor1, CodReg, SoldDoc, SoldDocVal, SoldDocReg, CodBank, CodBankCont)
      values (Cod1, RecID, v_rec.SoldDoc, v_rec.SoldDocVal, v_rec.SoldDocReg, v_rec.CodBank, v_rec.CodBankCont);
      update tmp_jurnal1 set indexlocal = Cod1 where indexlocal = v_rec.codregtrezor1;
      update tmp_jurnal set indexlocal = Cod1 where indexlocal = v_rec.codregtrezor1;
    END LOOP;

    INSERT INTO JURNAL1(CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD, CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, CODCENTRU, CODANALIZANOD)
    (SELECT NEXTVAL('SEQ_JURNAL1_CODJURNAL1'), RECID, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD, CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, CODCENTRU, CODANALIZANOD
     FROM TMP_JURNAL1
    );

    INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, DATADOC, CODCENTRU, CODANALIZANOD)
    (SELECT NEXTVAL('SEQ_JURNAL_CODJURNAL'), RECID, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, DATADOC, CODCENTRU, CODANALIZANOD
     FROM TMP_JURNAL
    );
  END IF;

  FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP
    SELECT COUNT( *) INTO TMP_NR FROM NCONTRUL
    WHERE CODCONT = V_REC.CODCONT AND  AN = TO_NUMBER((current_setting('PKG_GLOBALS.ANLUCRU', true)),'999999999999999999') AND  LUNA = TO_NUMBER((current_setting('PKG_GLOBALS.LUNALUCRU', true)),'999999999999999999');

    IF  TMP_NR = 0 THEN
      INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
      VALUES(NEXTVAL('SEQ_NCONTRUL_CODCONTRUL'), V_REC.CODCONT, 0, 0, 0, 0, 0, 0, 0, 0, TO_NUMBER((current_setting('PKG_GLOBALS.ANLUCRU', true)),'999999999999999999'), TO_NUMBER((current_setting('PKG_GLOBALS.LUNALUCRU', true)),'999999999999999999'));
    END IF;

    UPDATE NCONTRUL
    SET
    RULAJCD  = RULAJCD  + (CASE WHEN  V_REC.TIP = 'D' THEN V_REC.VALOARE  ELSE 0 END ) ,
    RULAJCC  = RULAJCC  + (CASE WHEN  V_REC.TIP = 'C' THEN V_REC.VALOARE  ELSE 0 END ) ,
    RULAJVCD = RULAJVCD + (CASE WHEN  V_REC.TIP = 'D' THEN V_REC.VALOAREV ELSE 0 END ) ,
    RULAJVCC = RULAJVCC + (CASE WHEN  V_REC.TIP = 'C' THEN V_REC.VALOAREV ELSE 0 END )
    WHERE
     CODCONT = V_REC.CODCONT AND  AN = TO_NUMBER((current_setting('PKG_GLOBALS.ANLUCRU', true)),'999999999999999999') AND  LUNA = TO_NUMBER((current_setting('PKG_GLOBALS.LUNALUCRU', true)),'999999999999999999');

    IF  COALESCE( V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
      FOR V_REC_SUB IN (SELECT * FROM NCONTRUL
                        WHERE CODCONT = V_REC.CODCONT AND  AN = TO_NUMBER((current_setting('PKG_GLOBALS.ANLUCRU', true)),'999999999999999999') AND  LUNA = TO_NUMBER((current_setting('PKG_GLOBALS.LUNALUCRU', true)),'999999999999999999')
                       )
      LOOP
        SELECT COUNT( *) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND  SUBUNITATEA = V_REC.SUBUNITATEA;

        IF  NR = 0 THEN
          INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA)
          VALUES(NEXTVAL('SEQ_NCONTRULSUB_CODRULSUB'), V_REC_SUB.CODCONTRUL, 0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
        END IF;

        UPDATE NCONTRULSUB
        SET
        RULAJCD  = RULAJCD  + (CASE WHEN  V_REC.TIP = 'D' THEN V_REC.VALOARE  ELSE 0 END ) ,
        RULAJCC  = RULAJCC  + (CASE WHEN  V_REC.TIP = 'C' THEN V_REC.VALOARE  ELSE 0 END ) ,
        RULAJVCD = RULAJVCD + (CASE WHEN  V_REC.TIP = 'D' THEN V_REC.VALOAREV ELSE 0 END ) ,
        RULAJVCC = RULAJVCC + (CASE WHEN  V_REC.TIP = 'C' THEN V_REC.VALOAREV ELSE 0 END )
        WHERE
         CODCONTRUL = V_REC_SUB.CODCONTRUL AND  SUBUNITATEA = V_REC.SUBUNITATEA;
      END LOOP;
    END IF;
  END LOOP;

  FOR V_REC IN (SELECT INTBL.CODBANKCONT, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT
                FROM TMP_REGTREZOR1_MARTOR INTBL LEFT JOIN TMP_REGTREZOR1 OUTTBL ON  OUTTBL.CODBANKCONT = INTBL.CODBANKCONT
                union
                SELECT OUTTBL.CODBANKCONT, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT
                FROM TMP_REGTREZOR1 OUTTBL LEFT JOIN TMP_REGTREZOR1_MARTOR INTBL ON  INTBL.CODBANKCONT = OUTTBL.CODBANKCONT
               )
  LOOP
    IF  COALESCE( V_REC.SOLDIN, 0) &lt;&gt; COALESCE( V_REC.SOLDOUT, 0) THEN
      DIFERENTE := 1;
      EXIT ;
    END IF;
  END LOOP;

  IF (DIFERENTE = 1)  OR (COALESCE(TO_NUMBER((current_setting('PKG_REGTREZOR.CURS_IN', true)),'99999999999.9999999'), 0) &lt;&gt; COALESCE( CURS_OUT, 0)) THEN
    FOR V_REC IN (SELECT * FROM REG
                  WHERE TIPREG = 45 AND  CODMONEDA = (SELECT CODMONEDA FROM TMP_REG)
                  AND  AN * 12 + LUNA &gt; TO_NUMBER((current_setting('PKG_GLOBALS.ANLUCRU', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_GLOBALS.LUNALUCRU', true)),'999999999999999999')
                 )
    LOOP
      UPDATE JURNAL1 SET DIRTY = 1 WHERE TIPDOC = 45 AND  CODDOC = V_REC.CODREG;
    END LOOP;

    FOR V_REC_TREZOR IN (SELECT T.*
                         FROM TREZOR T, NBANKCONT BC
                         WHERE TIPDOC IN (29, 30, 31) AND  BC.CODBANKCONT = T.CODBANCA AND  BC.CREDIT = 1
                          AND  EXISTS (SELECT CODBANKCONT FROM (SELECT CODBANKCONT FROM TMP_REGTREZOR1 UNION SELECT CODBANKCONT FROM TMP_REGTREZOR1_MARTOR) A_PG
                                       WHERE CODBANKCONT = T.CODBANCA)
                          AND  AN * 12 + LUNA &gt; TO_NUMBER((current_setting('PKG_GLOBALS.ANLUCRU', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_GLOBALS.LUNALUCRU', true)),'999999999999999999')
                        )
    LOOP
      UPDATE JURNAL1 SET DIRTY = 1 WHERE TIPDOC = V_REC_TREZOR.TIPDOC AND  CODDOC = V_REC_TREZOR.CODTREZOR;
    END LOOP;
  END IF;

  PERFORM PKG_GLOBALS_MarkDirtyJurnal();
  PERFORM NotifyModif( Operation, RecId, 'REG');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_make_miscari_in_intervalul</obj_name>
  <obj_hashval>49270e03b1eccb682996a29d4eeab865</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_make_miscari_in_intervalul(agest numeric, adata_start character varying, adata_end character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 28.11.2023 - sinc. Oracle
  --Florin 26.05.2022 - to_timestamp
  --Florin 17.05.2022 - sinc. Oracle
  DELETE FROM TMP_NIR_IN_INTERVALUL;
  INSERT INTO TMP_NIR_IN_INTERVALUL(CODOBIECT, CANTNIR)
  SELECT CODOBIECT, SUM( CANTNIR) AS CANTNIR
  FROM (SELECT NS.CODOBIECT, CANTNIR, N.DATANIR AS DATACREARE
        FROM NIRSTOC NS, NIR N, NARTOBJ O, NART A, IOART1 IO1
        WHERE NS.CODNIR = N.CODNIR AND  N.GEST = aGEST AND  O.CODOBIECT = NS.CODOBIECT AND  O.CODARTICOL = A.CODARTICOL AND  COALESCE( A.CASADEMARCAT, 1) = 1
              AND IO1.CODIOART = NS.CODIOART AND IO1.MG &lt;&gt; 5 AND N.TIPNIR &lt;&gt; 12 AND N.TIPNIR &lt;&gt; 13
              AND EXTRACT(YEAR FROM N.DATANIR) *12 + EXTRACT(MONTH FROM N.DATANIR) BETWEEN IO1.ALSTART AND IO1.ALSTOP
       union ALL
        SELECT NS.CODOBIECT, L1.CANT CANT, L.DATALIVR AS DATACREARE
        FROM LIVR1 L1, LIVR L, NIRSTOC NS, NIR N, NARTOBJ O, NART A, IOART1 IO1
        WHERE L1.CODNIRSTOC = NS.CODNIRSTOC AND  L1.CODLIVR = L.CODLIVR AND  L.TIPLIVR = 15 AND  NS.CODNIR = N.CODNIR AND  N.GEST = aGEST AND
              O.CODOBIECT = NS.CODOBIECT AND  A.CODARTICOL = O.CODARTICOL AND  COALESCE( A.CASADEMARCAT, 0) = 1
              AND IO1.CODIOART = NS.CODIOART AND IO1.MG &lt;&gt; 5
              AND EXTRACT(YEAR FROM N.DATANIR) * 12 + EXTRACT(MONTH FROM N.DATANIR) BETWEEN IO1.ALSTART AND IO1.ALSTOP
       ) A_PG
  WHERE COALESCE( DATACREARE, to_timestamp( '01.01.2000', 'DD.MM.YYYY')) &gt;=  to_timestamp( aDATA_START, 'DD.MM.YYYY hh24:mi') AND
        COALESCE( DATACREARE, to_timestamp( '01.01.2000', 'DD.MM.YYYY')) &lt;= to_timestamp( aDATA_END  , 'DD.MM.YYYY hh24:mi')
  GROUP BY CODOBIECT;

  DELETE FROM TMP_LIVR_IN_INTERVALUL;
  INSERT INTO TMP_LIVR_IN_INTERVALUL(CODOBIECT, CANTNIR)
  SELECT CODOBIECT, SUM( CANT) AS CANT
  FROM (SELECT NS.CODOBIECT, L1.CANT, L.DATALIVR AS DATACREARE
        FROM LIVR1 L1, LIVR L, NIRSTOC NS, NIR N, NARTOBJ O, NART A
        WHERE L1.CODNIRSTOC = NS.CODNIRSTOC AND  L1.CODLIVR = L.CODLIVR AND  L.TIPLIVR &lt;&gt; 15 AND  NS.CODNIR = N.CODNIR AND
              N.GEST = aGEST AND  O.CODOBIECT = NS.CODOBIECT AND  A.CODARTICOL = O.CODARTICOL AND  COALESCE( A.CASADEMARCAT, 0) = 1
       ) B_PG
  WHERE  COALESCE( DATACREARE, to_timestamp( '01.01.2000', 'DD.MM.YYYY')) &gt;=  to_timestamp( aData_START, 'DD.MM.YYYY hh24:mi') AND
         COALESCE( DATACREARE, to_timestamp( '01.01.2000', 'DD.MM.YYYY')) &lt;= to_timestamp( aData_END  , 'DD.MM.YYYY hh24:mi')
  GROUP BY CODOBIECT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_post_gestimplicite</obj_name>
  <obj_hashval>cc1a543e953ddbc09036844607ad9a41</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_post_gestimplicite()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  DELETE FROM RESTGESTIMPLICITE O
  WHERE EXISTS (SELECT COD FROM TMP_RESTGESTIMPLICITE_INI OI WHERE OI.COD = O.COD)
        AND  NOT  EXISTS (SELECT COD FROM TMP_RESTGESTIMPLICITE OT WHERE OT.COD = O.COD);

  FOR V_REC IN (SELECT * FROM TMP_RESTGESTIMPLICITE) LOOP
    IF  COALESCE( V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE RESTGESTIMPLICITE
      SET
        CODOBIECT     = V_REC.CODOBIECT,
        GESTIMPLICITA = V_REC.GESTIMPLICITA
      WHERE
       COD = V_REC.COD;
    ELSE
      INSERT INTO RESTGESTIMPLICITE(COD, CODRESTAURANT, CODOBIECT, GESTIMPLICITA)
      VALUES(V_REC.COD, V_REC.CODRESTAURANT, V_REC.CODOBIECT, V_REC.GESTIMPLICITA);
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_set_cmd_diminuate</obj_name>
  <obj_hashval>f249ebf55505f5f171163ee3b783df24</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_set_cmd_diminuate()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  FOR V_REC IN (SELECT CODUNIC FROM TMP_MANEVRA) LOOP
    UPDATE RESTCMD SET DIMINUAT = 1 WHERE CODRESTCMD = V_REC.CODUNIC;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rezervari_updategestioart</obj_name>
  <obj_hashval>83f495643774ae76bf8192401ae5043b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rezervari_updategestioart(acodcomanda1 numeric, acodobiect numeric, acodgest numeric, acodioart numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 04.03.2021 - fixat 44408
  UPDATE TMP_REZ_REZ
  SET
  CodIOArt   = aCodIOArt,
  CodGest    = aCodGest,
  Gest_IOArt = Substr((SELECT DEN_GEST  FROM NGest WHERE CodGest  = aCodGest), 1, 25) || Chr(13)
                   || (SELECT DEN_IOART FROM IOArt WHERE CodIOArt = aCodIOArt)
  WHERE CodComanda1 = aCodComanda1 AND  CodObiect = aCodObiect;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_ropharma_do_preluare_localitati</obj_name>
  <obj_hashval>0b083c62b0edf21e19acbd27fae2316d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_ropharma_do_preluare_localitati()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_ROPHARMA_PREIA_LOCALITATI( 'ROPH'  , 'ROPH2014');
  PERFORM PKG_ROPHARMA_PREIA_LOCALITATI( 'ROPHBC', 'ROPH2014');
  PERFORM PKG_ROPHARMA_PREIA_LOCALITATI( 'ROPHIS', 'ROPH2014');
  PERFORM PKG_ROPHARMA_PREIA_LOCALITATI( 'MURES' , 'ROPH2014');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_an_initializari</obj_name>
  <obj_hashval>1c1363d21f0ff4957c26a1e030f219f6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_an_initializari(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_curata_iesiri1</obj_name>
  <obj_hashval>17683b3456c4f1e4c1469da746954a01</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_curata_iesiri1()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  NR    numeric := 0;
begin
  FOR V_REC IN
  (
  SELECT I1.CODIES1, I1.CANT, I.TIPDOC
  FROM IESIRI1 I1, IESIRI I
  WHERE I.CODIES = I1.CODIES AND  COALESCE( I.TVAINCASARE, 0) = 0
    AND I.AN * 12 + I.LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
  )
  LOOP
    NR := 0;
    IF  V_REC.TIPDOC = 20 THEN
      IF  V_REC.CANT = 0 THEN
        SELECT COUNT( *) INTO NR FROM IESLINK WHERE CODLINIEAVIZ = V_REC.CODIES1;
        IF  NR = 0 THEN
          BEGIN
            DELETE FROM IESIRI1 WHERE CODIES1 = V_REC.CODIES1;
          EXCEPTION WHEN OTHERS THEN
            NR := NR + 1;
          END;
        END IF;
      END IF;
    ELSE
      BEGIN
        DELETE FROM IESIRI1 WHERE CODIES1 = V_REC.CODIES1;
      EXCEPTION WHEN OTHERS THEN
        NR := NR + 1;
      END;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_getan_rupere</obj_name>
  <obj_hashval>e9e8375b5dabdbed5c80c3f646589d7c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_getan_rupere(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_getluna_initializari</obj_name>
  <obj_hashval>1f1961c950b4e3774564520c6478386e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_getluna_initializari(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_sterge_fixari_lunare_anter</obj_name>
  <obj_hashval>7e89d8a470656fed7cf99bd77ccc25c1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_sterge_fixari_lunare_anter()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM NIRLUNA
  WHERE AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999');

  DELETE FROM STOCVALLUNA
  WHERE AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999');

  DELETE FROM OBLIGPIFLUNA
  WHERE AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999');

  DELETE FROM NPARTSOLDLUNA
  WHERE AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999');

  DELETE FROM NPARTSOLDLUNASUB
  WHERE AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999');

  DELETE FROM NPERSSOLDLUNA
  WHERE AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999');

  DELETE FROM NPERSSOLDLUNASUB
  WHERE AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999');

  DELETE FROM NBANKSOLDLUNA
  WHERE AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999');

  DELETE FROM AVIZINTLUNA
  WHERE AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999');

  DELETE FROM AVIZIESLUNA
  WHERE AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999');

  DELETE FROM COMANDA1LUNA
  WHERE AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_INITIALIZARI', true)),'999999999999999999');

  DELETE FROM NCONTRUL
  WHERE AN * 12 + LUNA &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');

  UPDATE NCONT1
  SET
  ANSTART   = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999'),
  LUNASTART = TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999')
  WHERE ANSTART * 12 + LUNASTART &lt; TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_RUPERE', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.LUNA_RUPERE', true)),'999999999999999999');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t48</obj_name>
  <obj_hashval>a20334c32d58e176ab3464fedf2e7ab9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t48()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 06.01.2022
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t59</obj_name>
  <obj_hashval>c6a8651f9df7a461c5ad84d3cbf90475</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t59()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef  25.05.2023
  INSERT INTO TMP_SAFT59
  SELECT
    C24.CODPARINTE COL01,--CODSAF_VALUATIONS NUMBER(20)
    Count(1)       COL02 --DETSAF_VALUATION  NUMBER(20)
  FROM TMP_SAFT_CODSAF C24
  WHERE C24.CodSAFTTab = 24
  GROUP BY C24.CODPARINTE;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_catspor_setct_monitor</obj_name>
  <obj_hashval>22072642ee5fe80747c9a3f7e476ad16</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_catspor_setct_monitor(act_monitor character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 05.04.2022
  perform set_config('PKG_SAL_catspor.CT_MONITOR',aCT_MONITOR,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_catspor_sp_lockrecord</obj_name>
  <obj_hashval>140018558388f97ab7e84c96eff269cb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_catspor_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp NUMERIC;
BEGIN
  --Florin 01.03.2022
  SELECT CODCATSPOR
  INTO Tmp
  FROM SAL_CATSPOR
  WHERE
   CODCATSPOR = RecId;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_dedgen_ct_monitor</obj_name>
  <obj_hashval>50f3b85dfea4133024ab65f05839add4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_dedgen_ct_monitor(wme_result character varying, fakeparam numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aDoc varchar;
BEGIN
  --Florin 01.03.2022
   WME_Result := current_setting('PKG_SAL_DEDGEN.CT_MONITOR', true);
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
  WME_Result := 'MON_5';
RETURN ;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_fondp_sp_gotorecord</obj_name>
  <obj_hashval>e8ce25494fa9aac09d23cd463d09dca4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_fondp_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 01.03.2022
  INSERT INTO TMP_SAL_FONDP
  (
  CODFONDP, Denumire
  )
  (
  SELECT CODFONDP, Denumire
  FROM SAL_FONDP
  WHERE
     CODFONDP = RecId
  );
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_nasig_setct_monitor</obj_name>
  <obj_hashval>67d7316e5fbc5c8ea5fad555fd8c49b5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_nasig_setct_monitor(act_monitor character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 02.03.2022
  perform set_config('PKG_SAL_NASIG.CT_MONITOR',aCT_MONITOR,false);
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_nasig_sp_lockrecord</obj_name>
  <obj_hashval>d3a0920df11c905789c6a480fef5d8be</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_nasig_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
 DECLARE
 Tmp numeric;
BEGIN
  --Florin 02.03.2022
  SELECT codnasig
  INTO Tmp
  FROM SAL_NASIG
  WHERE
     codnasig = RecId;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sali_sp_insertrecord</obj_name>
  <obj_hashval>b251742f68163ebccbc761e12175b97d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sali_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_SALI (CODSALA) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sali_sp_lockrecord</obj_name>
  <obj_hashval>de13043e9652a0dc13dcfc5bcb75471f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sali_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CODSALA INTO Tmp FROM SALI WHERE CODSALA = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_setreturnabil</obj_name>
  <obj_hashval>53df63abea5e0e9d4fb2902a1139f372</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_setreturnabil(areturnabil numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SELECTARTICOLE.RETURNABIL',to_char(COALESCE( aRETURNABIL, 0),'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_setumprincipala</obj_name>
  <obj_hashval>c05c45f68fe568f9ead0c6189f1e26e6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_setumprincipala(ump numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SELECTARTICOLE.UMPRINCIPALA',to_char(UMP,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sertar_sp_insertrecord</obj_name>
  <obj_hashval>c42ff1e53e23e566a1c49e34ae4a77d9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sertar_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 12.04.2023 - sinc. Oracle (11.04.2023)
  INSERT INTO TMP_NSERTAR (CodSertar) VALUES(0);
  PERFORM PKG_CFGTABLES_EXT_INSERTRECORD(69);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sertar_sp_lockrecord</obj_name>
  <obj_hashval>d52071066a102893d06b3687dfb4b85f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sertar_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CodSertar INTO Tmp FROM NSERTAR WHERE CodSertar = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_clear_rulaje_for_jurnal</obj_name>
  <obj_hashval>af2ea5a218cec0240501e9291d892f07</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_clear_rulaje_for_jurnal()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM JURNAL WHERE AN * 12 + LUNA = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X);

  UPDATE NCONTRUL
  SET
  RULAJCD      = 0,
  RULAJCC      = 0,
  RULAJVCD     = 0,
  RULAJVCC     = 0,
  RULAJC_IFRS  = 0,
  RULAJVC_IFRS = 0,
  RULAJC_GRUP  = 0,
  RULAJVC_GRUP = 0
  WHERE
   AN * 12 + LUNA = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_settnccantitate</obj_name>
  <obj_hashval>dd20b96ef4d8a585e719ac1517aef0ff</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_settnccantitate(atnccantitate numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  perform set_config('PKG_SERVICE.tncCantitate',to_char(atncCantitate,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_settncpenalizari</obj_name>
  <obj_hashval>e4673d5e590b486e4631da0bf7702caf</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_settncpenalizari(atncpenalizari numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  perform set_config('PKG_SERVICE.tncPenalizari',to_char(atncPenalizari,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_servpost_sp_insertrecord</obj_name>
  <obj_hashval>925507ba7d0a9e7c1000a19e6160b36f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_servpost_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO Tmp_ServPost (CodServiciu) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_settask_setcarnetdoc_i</obj_name>
  <obj_hashval>ef2df781c30634b0275981aa1a703fa9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_settask_setcarnetdoc_i(acarnetdoc_i numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SETTASK.CARNETDOC_I',to_char(aCARNETDOC_I,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_settask_sp_deleterecord</obj_name>
  <obj_hashval>2ea0e1aed114c182921af933eab8668d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_settask_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_SETTASK_SP_LOCKRECORD( RecId);

  UPDATE settask SET sters = 1 WHERE codtask = RecID;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settccurtotalcuaj</obj_name>
  <obj_hashval>9e60bbfe107537aaff09b2e983d1f5f0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settccurtotalcuaj(atccurtotalcuaj numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcCurTotalCuAj',to_char(atcCurTotalCuAj,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settcintrodusa</obj_name>
  <obj_hashval>3a720dade5b18945a14b72ae57afce71</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settcintrodusa(atcintrodusa numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcIntrodusa',to_char(atcIntrodusa,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tcintrodusa</obj_name>
  <obj_hashval>984c814f8afab238db1cb860140cc603</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tcintrodusa(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcIntrodusa')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 8;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_soldinitial_setoldcodpart</obj_name>
  <obj_hashval>d60c37120dd5534a300513c9c54da989</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_soldinitial_setoldcodpart(aoldcodpart numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SOLDINITIAL.OLDCODPART',to_char(aOLDCODPART,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_soldinitial_sp_insertrecord</obj_name>
  <obj_hashval>739b5dbf098009923ab2f118ea2244f0</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_soldinitial_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_SOLDINI (CODSOLDINI) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stoc_generare_facturi_postdisclikistoc</obj_name>
  <obj_hashval>b400cc10779f4bb3a44145286e0db76d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stoc_generare_facturi_postdisclikistoc()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
begin
  FOR V_REC IN (SELECT * FROM TMP_NIRSTOC) LOOP
    UPDATE NIRSTOC SET DISCLIKISTOC = V_REC.DISCLIKISTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stociniart_sp_insertrecord</obj_name>
  <obj_hashval>a19e874c889e245a87bfd6ff95884c29</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stociniart_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_STOCINI (CODSTOCINI) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stocinitial_sp_postrecords</obj_name>
  <obj_hashval>d362a8e9320d79e55a129c4a6c31282e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stocinitial_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
declare
  V_REC           RECORD;
  V_RECNIRSER     RECORD;
  V_MIFIX1        RECORD;
  ANI             numeric;
  LUNAI           numeric;
  vCODINTR        numeric;
  vCODINTR1       numeric;
  vCODNIR         numeric;
  vCODNIRSTOC     numeric;
  vCODDVI         numeric;
  aGEST           numeric;
  aPERS           numeric;
  aCODSERIE       numeric;
  NOMSERIE        varchar;
  vCODNIRSER      numeric;
  NR              numeric := 0;
  NRMIFIX         numeric := 0;
  aVALOARE        numeric := 0;
  aTIPDOCNirStoc1 numeric;
  V_REC_COPII     record;
BEGIN
  --Florin 12.12.2025 - sinc. Oracle
  --Florin 25.07.2025 - sinc. Oracle
  --Florin 13.01.2023 - fixat 56790
  --Florin 29.12.2022 - fixat 55514
  --Florin 17.11.2022 - fixat 56291
  --Florin 21.10.2022 - sinc. Oracle (18.10.2022)
  --Adina 17.08.2021 - sinc.Oracle din 17.08.2021
  --PERFORM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA(current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric, current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric, ANI, LUNAI);
  SELECT NEWAN, NEWLUNA
  FROM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA(current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric,
                                              current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric,
                                              ANI, LUNAI)
  INTO ANI, LUNAI;

  DELETE FROM tmp_manevra;

  INSERT INTO tmp_manevra (codunic)
  SELECT codnirstoc FROM tmp_nirstoc
  union
  SELECT codnirstoc FROM tmp_nirstocini;

  SELECT CODGEST, CODPERS INTO aGEST, aPERS FROM TMP_STOCINI;

  if OPERATION = 0 then
    SELECT CODSTOCINI INTO RecId FROM TMP_STOCINI;

    UPDATE STOCINI
    set
      CODGEST = aGEST,
      CODPERS = aPERS
    where
      CODSTOCINI = RecID ;

    -- verific linii serii si stoc sterse;
    for V_REC in (SELECT * FROM NIRSER WHERE CODNIRSTOC in (SELECT NS.CODNIRSTOC
                                                            FROM  NIRSTOC NS
                                                                  left join NIR     N ON N.CODNIR  = NS.CODNIR
                                                                  left join INTRARI I ON I.CODINTR = N.CODINTR
                                                                  where
                                                                    N.GEST = aGEST
                                                                    and I.AN * 12 + I.LUNA &lt; current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric * 12 + current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric
                                                           )
                                      and CODNIRSER not in (SELECT CODNIRSER FROM TMP_NIRSERINI )
                 )
    loop
      DELETE FROM NIRSERLUNA WHERE CODNIRSER = v_rec.CODNIRSER;
      DELETE FROM NIRSER     WHERE CODNIRSER = V_REC.CODNIRSER;
    end loop;

    for V_REC in (SELECT NS.CODNIRSTOC, NS.CODNIR, I1.CODINTR1, I.CODINTR
                  FROM  NIRSTOC NS
                        left join NIR      N  ON N.CODNIR    = NS.CODNIR
                        left join INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1
                        left join INTRARI  I  ON I.CODINTR   = N.CODINTR
                        where
                          N.GEST = aGEST
                          and I.AN * 12 + I.LUNA &lt; current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric * 12 + current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric
                          and NS.CODNIRSTOC not in (SELECT CODNIRSTOC FROM TMP_NIRSTOCINI )
                 )
    loop
      DELETE FROM NIRSER  WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
      DELETE FROM NIRLUNA WHERE CODNIRSTOC = v_rec.CODNIRSTOC;

      DELETE FROM NIRSTOC  WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
      DELETE FROM NIRSTOC1 WHERE CODNIRSTOC = V_REC.CODNIRSTOC;

      DELETE FROM INTRARI1 I1 WHERE CODINTR1 = v_rec.CODINTR1 and (SELECT count(*) FROM NIRSTOC WHERE CODINTR1 = I1.CODINTR1 ) = 0;
    end loop;

    for V_REC in (SELECT NS.CODNIRSTOC, NS.CODNIR, T1.CODTRANSF1, T.CODTRANSF
                  FROM  NIRSTOC NS
                        left join NIR     N  ON N.CODNIR      = NS.CODNIR
                        left join TRANSF1 T1 ON T1.CODTRANSF1 = NS.CODTRANSF1
                        left join TRANSF  T  ON T.CODTRANSF   = N.CODTRANSF
                        where
                          N.GEST = aGEST
                          and T.AN * 12 + T.LUNA &lt; current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric * 12 + current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric
                          and NS.CODNIRSTOC not in (SELECT CODNIRSTOC FROM TMP_NIRSTOCINI)
                 )
    loop
      DELETE FROM NIRSER  WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
      DELETE FROM NIRLUNA WHERE CODNIRSTOC = v_rec.CODNIRSTOC;

      DELETE FROM NIRSTOC  WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
      DELETE FROM NIRSTOC1 WHERE CODNIRSTOC = V_REC.CODNIRSTOC;

      DELETE FROM TRANSF1 T1 WHERE CODTRANSF1 = v_rec.CODTRANSF1 and (SELECT count(*) FROM NIRSTOC WHERE CODTRANSF1 = T1.CODTRANSF1 ) = 0;
    end loop;

    for V_REC in (SELECT * FROM TMP_NIRSTOCINI ) loop
      if V_REC.CODNIRSTOC &lt; 0 then
        SELECT nextval('SEQ_INTRARI_CODINTR')    INTO vCODINTR;
        SELECT nextval('SEQ_DVI_CODDVI')         INTO vCODDVI;
        SELECT nextval('SEQ_INTRARI1_CODINTR1')  INTO vCODINTR1;
        SELECT nextval('SEQ_NIR_CODNIR')         INTO vCODNIR;
        SELECT nextval('SEQ_NIRSTOC_CODNIRSTOC') INTO vCODNIRSTOC;

        INSERT INTO INTRARI ( CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, DATADOC, PARTENER, AN, LUNA, SUBUNITATEA )
        values ( vCODINTR, 1, 0, 0, 1, 'F', v_rec.DATADOC, v_rec.FURNIZOR, ANI, LUNAI, current_setting('PKG_GLOBALS.SUBUNITATE_DOC', true)::numeric );

        INSERT INTO DVI ( CODINTR, CODDVI, TIPIMPORT )
        values ( vCODINTR, vCODDVI, v_rec.tipimport );

        INSERT INTO INTRARI1 ( CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, UMSEC, AN, LUNA, CODOBIECT, PRETORIG, PU, CANT, TG, PUMAXIMAL, NRCERTIF, CODCENTRU )
        values ( vCODINTR1, vCODINTR, 1, '=', V_REC.UMSEC, ANI, LUNAI, v_rec.CODOBIECT, v_rec.PRETACHIZ / V_REC.PARITATE, v_rec.PRETACHIZ / V_REC.PARITATE,
                 v_rec.CANTNIR * V_REC.PARITATE, v_rec.TG, V_REC.PUMAXIMAL / V_REC.PARITATE, V_REC.NRCERTIF, V_REC.CODCENTRU );

        INSERT INTO NIR ( CODNIR, CODINTR, DATANIR, GEST, TIPNIR, ANULAT, BLOCAT, OPERAT, USERID, DATACREARE )
        values ( vCODNIR, vCODINTR, v_rec.DATADOC, aGEST, 1, 0, 0, 1, to_number (current_setting ('PKG_GLOBALS.USERID', true)), CURRENT_DATE );

        INSERT INTO NIRSTOC
        ( CODNIRSTOC,
          CODNIR,
          CODINTR1,
          CANTNIR,
          REST,
          UMSEC,
          CODOBIECT,
          CODIOART,
          PRET,
          PUVAL,
          ADAOS,
          TVA,
          TIPSERIE,
          FURN,
          DATAACHIZ,
          TIPDOCACHIZ,
          PUMAXIMAL,
          CODLOCATIE,
          TG,
          CANTUM1,
          RESTUM1,
          CANTUM2,
          RESTUM2,
          PROCENTADAOS,
          D1,
          D2,
          D3,
          ROTLEI,
          ROTVALUTA,
          SERIELOT,
          PROVIZION,
          EUDR_RN, EUDR_VN)
        values
        ( vCODNIRSTOC,
          vCODNIR,
          vCODINTR1,
          v_rec.CANTNIR * V_REC.PARITATE,
          v_rec.CANTNIR * V_REC.PARITATE,
          V_REC.UMSEC,
          V_REC.CODOBIECT,
          V_REC.CODIOART,
          V_REC.PRETINREG / V_REC.PARITATE,
          V_REC.PUVAL / V_REC.PARITATE,
          ( V_REC.PRETINREG - V_REC.PRETACHIZ) / V_REC.PARITATE,
          V_REC.TVA,
          V_REC.TIPSERIE,
          V_REC.FURNIZOR,
          V_REC.DATADOC,
          1,
          V_REC.PUMAXIMAL / V_REC.PARITATE,
          V_REC.CODLOCATIE,
          V_REC.TG,
          V_REC.CANTUM1,
          V_REC.CANTUM1,
          V_REC.CANTUM2,
          V_REC.CANTUM2,
          V_REC.PROCENTADAOS,
          V_REC.D1,
          V_REC.D2,
          V_REC.D3,
          V_REC.ROTLEI,
          V_REC.ROTVALUTA,
          V_REC.SERIELOT,
          V_REC.PROVIZION,
          V_REC.EUDR_RN, V_REC.EUDR_VN );

        aTIPDOCNirStoc1 := 1 - 2 * 1 * coalesce(v_rec.Tipimport, 0);

        INSERT INTO NIRSTOC1 ( CODNIRSTOC, CODNIRSTOCORIG, TIPDOC, PRETMAT, DIRTY, DINSTOC, CODCOMANDA1 )
        values (vCODNIRSTOC, vCODNIRSTOC, aTIPDOCNirStoc1,
                CASE when aTIPDOCNirStoc1 &lt; 0 then 0
                     else V_REC.PRETINREG / V_REC.PARITATE - ( V_REC.PRETINREG - V_REC.PRETACHIZ) / V_REC.PARITATE
                END ,
                0, 1, 0 );

        INSERT INTO NIRLUNA ( CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2 )
        values ( vCODNIRSTOC, ANI, LUNAI, v_rec.CANTNIR * V_REC.PARITATE, coalesce(V_REC.CANTUM1, 0), coalesce(V_REC.CANTUM2, 0) );

        for V_RECNIRSER in (SELECT * FROM TMP_NIRSERINI WHERE CODNIRSTOC = V_REC.CODNIRSTOC ) loop
          if V_RECNIRSER.CODSERIE &lt; 0 then
            begin
              SELECT coalesce(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_RECNIRSER.SERIE and CODOBIECT = V_REC.CODOBIECT;
            exception
              when others then aCODSERIE := 0;
            end;

            if coalesce(aCODSERIE, 0) = 0 then
              SELECT nextval('SEQ_NSERII_CODSERIE') INTO aCODSERIE;

              INSERT INTO NSERII ( CODSERIE, SERIE, CODOBIECT )
              values ( aCODSERIE, V_RECNIRSER.SERIE, V_REC.CODOBIECT );
            end if;
          else
            aCODSERIE := V_RECNIRSER.CODSERIE;

            SELECT coalesce(SERIE, '') INTO NOMSERIE FROM NSERII WHERE CODSERIE = aCODSERIE;

            if coalesce(NOMSERIE, '') &lt;&gt; V_RECNIRSER.SERIE then
              UPDATE NSERII SET SERIE = V_RECNIRSER.SERIE WHERE CODSERIE = aCODSERIE ;
            end if;
          end if;

          SELECT nextval('SEQ_NIRSER_CODNIRSER') INTO vCODNIRSER;

          INSERT INTO NIRSER (CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, REST,
                              CANTUM1, RESTUM1, CANTUM2, RESTUM2, OBS, CodCertif,
                              DataProd, Stare, Divizor, Bucati, TG, DataProd1, TG1)
          values (vCODNIRSER, vCODNIRSTOC, aCODSERIE, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE,
                  V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM2, V_RECNIRSER.CANTUM2, V_RECNIRSER.OBS, V_RECNIRSER.CodCertif,
                  V_RECNIRSER.DataProd, V_RECNIRSER.Stare, V_RECNIRSER.Divizor, V_RECNIRSER.Bucati, V_RECNIRSER.TG, V_RECNIRSER.DataProd1, V_RECNIRSER.TG1);

          INSERT INTO NIRSERLUNA ( CODNIRSER, CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2 )
          values ( vCODNIRSER, vCODNIRSTOC, ANI, LUNAI, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, coalesce(V_REC.CANTUM1, 0), coalesce(V_REC.CANTUM2, 0) );
        end loop;
      ELSE
        UPDATE INTRARI
        SET
          DATADOC = v_rec.DATADOC,
          PARTENER = v_rec.FURNIZOR
        WHERE
          CODINTR = (SELECT CODINTR FROM NIR WHERE CODNIR = v_rec.CODNIR ) ;

        SELECT CODINTR  INTO vCodIntr FROM NIR WHERE CODNIR  = v_rec.CODNIR;
        SELECT count(*) INTO NR       FROM DVI WHERE CodIntr = vCodIntr;

        if Nr = 0 then
          SELECT nextval('SEQ_DVI_CODDVI') INTO vCODDVI;

          INSERT INTO DVI ( CODDVI, CODINTR, TIPIMPORT )
          values ( vCODDVI, vCodIntr, V_REC.TIPIMPORT );
        else
          UPDATE DVI SET TipImport = v_REC.Tipimport WHERE CodIntr = vCodIntr ;
        end if;

        UPDATE INTRARI1
        set
          UMSEC     = V_REC.UMSEC,
          PRETORIG  = v_rec.PRETACHIZ / v_rec.PARITATE,
          PU        = v_rec.PRETACHIZ / v_rec.PARITATE,
          CANT      = v_rec.CANTNIR * v_rec.PARITATE,
          TG        = v_rec.TG,
          NRCERTIF  = V_REC.NRCERTIF,
          CODCENTRU = V_REC.CODCENTRU,
          CODOBIECT = V_REC.CODOBIECT,
          PUMAXIMAL = v_rec.PUMaximal / v_rec.PARITATE
        where
          CODINTR1 = v_rec.CODINTR1 ;

        UPDATE NIR
        set
          DATANIR = v_rec.DATADOC,
          GEST    = aGEST
        where
          CODNIR = v_rec.CODNIR ;

        UPDATE NIRSTOC
        set
          CANTNIR      = V_REC.CANTNIR * V_REC.PARITATE,
          CANTUM1      = V_REC.CANTUM1,
          CANTUM2      = V_REC.CANTUM2,
          CODIOART     = V_REC.CODIOART,
          CODOBIECT    = V_REC.CODOBIECT,
          UMSEC        = V_REC.UMSEC,
          PRET         = V_REC.PRETINREG / v_rec.PARITATE,
          PUVAL        = V_REC.PUVAL / v_rec.PARITATE,
          ADAOS        = ( V_REC.PRETINREG - V_REC.PRETACHIZ) / v_rec.PARITATE,
          TVA          = V_REC.TVA,
          REST         = (SELECT PKG_INTRARI_GET_REST_STOC.WME_RESULT     FROM PKG_INTRARI_GET_REST_STOC(null, V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTNIR * v_rec.PARITATE)),
          RESTUM1      = (SELECT PKG_INTRARI_GET_REST_STOC_UM1.WME_RESULT FROM PKG_INTRARI_GET_REST_STOC_UM1(null, V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTUM1)),
          RESTUM2      = (SELECT PKG_INTRARI_GET_REST_STOC_UM2.WME_RESULT FROM PKG_INTRARI_GET_REST_STOC_UM2(null, V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTUM2)),
          FURN         = V_REC.FURNIZOR,
          DATAACHIZ    = V_REC.DATADOC,
          TIPDOCACHIZ  = 1,
          PUMAXIMAL    = V_REC.PUMAXIMAL / v_rec.PARITATE,
          CODLOCATIE   = V_REC.CODLOCATIE,
          TG           = V_REC.TG,
          PROCENTADAOS = V_REC.PROCENTADAOS,
          D1           = V_REC.D1,
          D2           = V_REC.D2,
          D3           = V_REC.D3,
          SERIELOT     = V_REC.SERIELOT,
          PROVIZION    = V_REC.PROVIZION,
          EUDR_RN      = V_REC.EUDR_RN,
          EUDR_VN      = V_REC.EUDR_VN
        where
          CODNIRSTOC = v_rec.CODNIRSTOC ;

       --propag EUDR
       FOR V_REC_COPII IN (SELECT * FROM NIRSTOC1 NS1 WHERE CODNIRSTOCORIG &lt;&gt; CODNIRSTOC AND CODNIRSTOCORIG = v_rec.CODNIRSTOC)
       loop
         UPDATE NIRSTOC
         SET
           EUDR_RN = V_REC.EUDR_RN,
           EUDR_VN = V_REC.EUDR_VN
         WHERE
           CODNIRSTOC = V_REC_COPII.CODNIRSTOC;
       end loop;

        --propag din nou furnizorul pe pozitiile de stoc generate prin transfer
        PERFORM pkg_stociniart_PropagaFurn(v_rec.codnirstoc, v_rec.furnizor);

        aTIPDOCNirStoc1 := 1 - 2 * 1 * coalesce(v_rec.Tipimport, 0);

        UPDATE NIRSTOC1
        set
          TIPDOC      = aTIPDOCNirStoc1,
          PRETMAT     = CASE when aTIPDOCNirStoc1 &lt; 0 then 0 else V_REC.PRETINREG / v_rec.PARITATE - ( V_REC.PRETINREG - V_REC.PRETACHIZ) / V_REC.PARITATE end ,
          DIRTY       = 0,
          DINSTOC     = 1,
          CODCOMANDA1 = 0
        where
            CODNIRSTOC = V_REC.CODNIRSTOC ;

        begin
          SELECT count(*) INTO NRMIFIX FROM MIFIX1 WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
        exception
          when others then NRMIFIX := 0;
        end;

        if NRMIFIX &gt; 0 then
          aVALOARE := v_rec.PretINREG / v_rec.Paritate;

          for V_MIFIX1 in (SELECT * FROM MIFIX1 MF1 WHERE MF1.CODNIRSTOC = V_REC.CODNIRSTOC and PRET &lt;&gt; aVALOARE ) loop
            UPDATE MIFIX1  SET PRET = aVALOARE WHERE CODMIFIX1 = V_MIFIX1.CODMIFIX1 ;
            UPDATE JURNAL1 SET DIRTY = 1 WHERE CODDOC = V_MIFIX1.CODMIFIX and TIPDOC = 36 and AN * 12 + LUNA &gt;= V_MIFIX1.ANSTART * 12 + V_MIFIX1.LUNASTART ;
          end loop;
        end if;

        for V_RECNIRSER in (SELECT * FROM TMP_NIRSERINI WHERE CODNIRSTOC = V_REC.CODNIRSTOC ) loop
          if V_RECNIRSER.CODSERIE &lt; 0 then
            begin
              SELECT coalesce(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_RECNIRSER.SERIE and CODOBIECT = V_REC.CODOBIECT;
            exception
              when others then aCODSERIE := 0;
            end;

            if coalesce(aCODSERIE, 0) = 0 then
              SELECT nextval('SEQ_NSERII_CODSERIE') INTO aCODSERIE;

              INSERT INTO NSERII ( CODSERIE, SERIE, CODOBIECT )
              values ( aCODSERIE, V_RECNIRSER.SERIE, V_REC.CODOBIECT );
            end if;
          else
            aCODSERIE := V_RECNIRSER.CODSERIE;

            SELECT coalesce(SERIE, '') INTO NOMSERIE FROM NSERII WHERE CODSERIE = aCODSERIE;

            if coalesce(NOMSERIE, '') &lt;&gt; V_RECNIRSER.SERIE then
              UPDATE NSERII SET SERIE = V_RECNIRSER.SERIE WHERE CODSERIE = aCODSERIE ;
            end if;
          end if;

          if V_RECNIRSER.CODNIRSER &lt; 0 then
            SELECT nextval('SEQ_NIRSER_CODNIRSER') INTO vCODNIRSER;

            INSERT INTO NIRSER ( CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, REST, CANTUM1, RESTUM1, CANTUM2, RESTUM2, Obs,
                                 CodCertif, DataProd, Stare, Divizor, Bucati, TG, CodProducator)
            values (vCODNIRSER, V_REC.CODNIRSTOC, aCODSERIE, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE,
                    V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM2, V_RECNIRSER.CANTUM2, V_RECNIRSER.Obs, V_RECNIRSER.CodCertif,
                    V_RECNIRSER.DataProd, V_RECNIRSER.Stare, V_RECNIRSER.Divizor, V_RECNIRSER.Bucati, V_RECNIRSER.TG, V_RECNIRSER.CodProducator);

            INSERT INTO NIRSERLUNA ( CODNIRSER, CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2 )
            values ( vCODNIRSER, V_REC.CODNIRSTOC, ANI, LUNAI, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM2 );
          else
            UPDATE NIRSER
            set
              CODSERIE  = aCODSERIE,
              CANTNIR   = V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE,
              CANTUM1   = V_RECNIRSER.CANTUM1,
              CANTUM2   = V_RECNIRSER.CANTUM2,
              OBS       = V_RECNIRSER.Obs,
              CodCertif = V_RECNIRSER.CodCertif,
              DataProd  = V_RECNIRSER.DataProd,
              Stare     = V_RECNIRSER.Stare,
              Divizor   = V_RECNIRSER.Divizor,
              Bucati    = V_RECNIRSER.Bucati,
              TG        = V_RECNIRSER.TG,
              DataProd1 = V_RECNIRSER.DataProd1,
              TG1       = V_RECNIRSER.TG1,
              REST      = (SELECT PKG_INTRARI_GET_REST_STOC_SERIE.WME_RESULT
                           FROM PKG_INTRARI_GET_REST_STOC_SERIE( null,
                                                                  (SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC ),
                                                                 V_RECNIRSER.CodNirSer,
                                                                 V_RECNIRSER.CantNir * V_RECNIRSER.PARITATE)
                          ),
              RESTUM1   = (SELECT PKG_INTRARI_GET_REST_STOC_SERIE_UM1.WME_RESULT
                           FROM PKG_INTRARI_GET_REST_STOC_SERIE_UM1( null,
                                                                     (SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC ),
                                                                     V_RECNIRSER.CodNirSer,
                                                                     V_RECNIRSER.CantUM1)
                          ),
              RESTUM2   = (SELECT PKG_INTRARI_GET_REST_STOC_SERIE_UM2.WME_RESULT
                           FROM PKG_INTRARI_GET_REST_STOC_SERIE_UM2( null,
                                                                     (SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC ),
                                                                     V_RECNIRSER.CodNirSer,
                                                                     V_RECNIRSER.CantUM2)
                          ),
              codproducator = V_RECNIRSER.codproducator
            WHERE CODNIRSER = V_RECNIRSER.CODNIRSER ;

            SELECT count(*) INTO NR FROM NIRSERLUNA WHERE CODNIRSER = V_RECNIRSER.CODNIRSER and AN = ANI and LUNA = LUNAI;

            if NR = 0 then
              INSERT INTO NIRSERLUNA ( CODNIRSTOC, CODNIRSER, AN, LUNA, REST, RESTUM1, RESTUM2 )
              values ( V_REC.CODNIRSTOC, V_RECNIRSER.CODNIRSER, ANI, LUNAI, V_REC.CANTNIR * V_REC.PARITATE, V_REC.CANTUM1, V_REC.CANTUM2 );
            else
              UPDATE NIRSERLUNA
              set
                REST    = V_RECNIRSER.CANTNIR * V_REC.PARITATE,
                RESTUM1 = V_RECNIRSER.CANTUM1,
                RESTUM2 = V_RECNIRSER.CANTUM2
              where
                CODNIRSER = v_recNIRSER.CODNIRSER and AN = ANI and LUNA = LUNAI ;
            end if;
          end if;
        end loop;

        SELECT count(*) INTO NR FROM NIRLUNA WHERE CODNIRSTOC = v_rec.CODNIRSTOC and AN = ANI and LUNA = LUNAI;

        if NR = 0 then
          INSERT INTO NIRLUNA ( CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2 )
          values ( V_REC.CODNIRSTOC, ANI, LUNAI, V_REC.CANTNIR * V_REC.PARITATE, coalesce(V_REC.CANTUM1, 0), coalesce(V_REC.CANTUM2, 0) );
        else
          UPDATE NIRLUNA
          set
            REST    = V_REC.CANTNIR * V_REC.PARITATE,
            RESTUM1 = coalesce(V_REC.CANTUM1, 0),
            RESTUM2 = coalesce(V_REC.CANTUM2, 0)
          where
            CODNIRSTOC = v_rec.CODNIRSTOC and AN = ANI and LUNA = LUNAI ;
        end if;
      end if;
    end loop;
  ELSE -- INSERT
    SELECT nextval('SEQ_STOCINI_CODSTOCINI') INTO RECID;

    INSERT INTO STOCINI (SELECT RECID, CODGEST, CODPERS FROM TMP_STOCINI );

    for V_REC in (SELECT * FROM TMP_NIRSTOCINI ) loop
      SELECT nextval('SEQ_INTRARI_CODINTR')    INTO vCODINTR;
      SELECT nextval('SEQ_DVI_CODDVI')         INTO vCODDVI;
      SELECT nextval('SEQ_INTRARI1_CODINTR1')  INTO vCODINTR1;
      SELECT nextval('SEQ_NIR_CODNIR')         INTO vCODNIR;
      SELECT nextval('SEQ_NIRSTOC_CODNIRSTOC') INTO vCODNIRSTOC;

      INSERT INTO INTRARI ( CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, DATADOC, PARTENER, AN, LUNA, SUBUNITATEA )
      values ( vCODINTR, 1, 0, 0, 1, 'F', v_rec.DATADOC, v_rec.FURNIZOR, ANI, LUNAI, current_setting('PKG_GLOBALS.SUBUNITATE_DOC', true)::numeric );

      INSERT INTO DVI ( CODINTR, CODDVI, TIPIMPORT )
      values ( vCODINTR, vCODDVI, v_rec.tipimport );

      INSERT INTO INTRARI1 ( CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, UMSEC, AN, LUNA, CODOBIECT, PRETORIG, PU, CANT, TG, PUMaximal, NRCERTIF, CODCENTRU )
      values ( vCODINTR1, vCODINTR, 1, '=', V_REC.UMSEC, ANI, LUNAI, v_rec.CODOBIECT, v_rec.PRETACHIZ / V_REC.PARITATE, v_rec.PRETACHIZ / V_REC.PARITATE,
               v_rec.CANTNIR * V_REC.PARITATE, v_rec.TG, V_REC.PUMAXIMAL / V_REC.PARITATE, V_REC.NRCERTIF, V_REC.CODCENTRU );

      INSERT INTO NIR ( CODNIR, CODINTR, DATANIR, GEST, TIPNIR, ANULAT, BLOCAT, OPERAT )
      values ( vCODNIR, vCODINTR, v_rec.DATADOC, aGEST, 1, 0, 0, 1 );

      INSERT INTO NIRSTOC
      ( CODNIRSTOC,
        CODNIR,
        CODINTR1,
        CANTNIR,
        REST,
        UMSEC,
        CODOBIECT,
        CODIOART,
        PRET,
        PUVAL,
        ADAOS,
        TVA,
        TIPSERIE,
        FURN,
        DATAACHIZ,
        TIPDOCACHIZ,
        PUMAXIMAL,
        CODLOCATIE,
        TG,
        CANTUM1,
        RESTUM1,
        CANTUM2,
        RESTUM2,
        PROCENTADAOS,
        D1,
        D2,
        D3,
        ROTLEI,
        ROTVALUTA,
        SERIELOT,
        PROVIZION,
        EUDR_RN, EUDR_VN)
      values
      ( vCODNIRSTOC,
        vCODNIR,
        vCODINTR1,
        v_rec.CANTNIR * V_REC.PARITATE,
        v_rec.CANTNIR * V_REC.PARITATE,
        V_REC.UMSEC,
        V_REC.CODOBIECT,
        V_REC.CODIOART,
        V_REC.PRETINREG / V_REC.PARITATE,
        V_REC.PUVAL / V_REC.PARITATE,
        ( V_REC.PRETINREG - V_REC.PRETACHIZ) / V_REC.PARITATE,
        V_REC.TVA,
        V_REC.TIPSERIE,
        V_REC.FURNIZOR,
        V_REC.DATADOC,
        1,
        V_REC.PUMAXIMAL / V_REC.PARITATE,
        V_REC.CODLOCATIE,
        V_REC.TG,
        V_REC.CANTUM1,
        V_REC.CANTUM1,
        V_REC.CANTUM2,
        V_REC.CANTUM2,
        V_REC.PROCENTADAOS,
        V_REC.D1,
        V_REC.D2,
        V_REC.D3,
        V_REC.ROTLEI,
        V_REC.ROTVALUTA,
        V_REC.SERIELOT,
        V_REC.PROVIZION,
        V_REC.EUDR_RN, V_REC.EUDR_VN);

      aTIPDOCNirStoc1 := 1 - 2 * 1 * coalesce(v_rec.Tipimport, 0);

      INSERT INTO NIRSTOC1 ( CODNIRSTOC, CODNIRSTOCORIG, TIPDOC, PRETMAT, DIRTY, DINSTOC, CODCOMANDA1 )
      values ( vCODNIRSTOC, vCODNIRSTOC, aTIPDOCNirStoc1,
               CASE when aTIPDOCNirStoc1 &lt; 0 then 0
                    else coalesce(V_REC.PRETINREG, 0) / coalesce(V_REC.PARITATE, 0) - ( coalesce(V_REC.PRETINREG, 0) - coalesce(V_REC.PRETACHIZ, 0)) / coalesce(V_REC.PARITATE, 0)
               END ,
               0, 1, 0 );

      INSERT INTO NIRLUNA ( CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2 )
      values ( vCODNIRSTOC, ANI, LUNAI, V_REC.CANTNIR * V_REC.PARITATE, V_REC.CANTUM1, V_REC.CANTUM2 );

      for V_RECNIRSER in (SELECT * FROM TMP_NIRSERINI WHERE CODNIRSTOC = V_REC.CODNIRSTOC ) loop
        if V_RECNIRSER.CODSERIE &lt; 0 then
          begin
            SELECT coalesce(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_RECNIRSER.SERIE and CODOBIECT = V_REC.CODOBIECT;
          exception
            when others then aCODSERIE := 0;
          end;

          if coalesce(aCODSERIE, 0) = 0 then
            SELECT nextval('SEQ_NSERII_CODSERIE') INTO aCODSERIE;

            INSERT INTO NSERII ( CODSERIE, SERIE, CODOBIECT )
            values ( aCODSERIE, V_RECNIRSER.SERIE, V_REC.CODOBIECT );
          end if;
        else
          aCODSERIE := V_RECNIRSER.CODSERIE;

          begin
            SELECT coalesce(SERIE, '?') INTO NOMSERIE FROM NSERII WHERE CODSERIE = aCODSERIE;
          exception
            when others then NOMSERIE := '?';
          end;

          if coalesce(NOMSERIE, '?') &lt;&gt; V_RECNIRSER.SERIE then
            UPDATE NSERII SET SERIE = V_RECNIRSER.SERIE WHERE CODSERIE = aCODSERIE ;
          end if;
        end if;

        SELECT nextval('SEQ_NIRSER_CODNIRSER') INTO VCODNIRSER;

        INSERT INTO NIRSERLUNA ( CODNIRSER, CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2 )
        values ( vCODNIRSER, vCODNIRSTOC, ANI, LUNAI, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM2 );

        INSERT INTO NIRSER ( CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, REST,
                             CANTUM1, RESTUM1, CANTUM2, RESTUM2, Obs, CodCertif,
                             DataProd, Stare, Divizor, Bucati, TG, DataProd1, TG1)
        values ( vCODNIRSER, vCODNIRSTOC, aCODSERIE, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE,
                 V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM2, V_RECNIRSER.CANTUM2, V_RECNIRSER.Obs, V_RECNIRSER.CodCertif,
                 V_RECNIRSER.DataProd, V_RECNIRSER.Stare, V_RECNIRSER.Divizor, V_RECNIRSER.Bucati, V_RECNIRSER.TG, V_RECNIRSER.DataProd1, V_RECNIRSER.TG1);
      end loop;
    end loop;
  end if;

  perform pkg_pretprod_SetDirtyStructura();

  DELETE FROM PMPLUNA WHERE AN = ANI and LUNA = LUNAI;

  for V_REC in (SELECT
                      CODOBIECT,
                      CODSUBUNIT,
                      sum(CANTINTR) as CANTINTR,
                      sum(VALINTR) as VALINTR,
                      sum(RESTLUNA) as RESTLUNA,
                      sum(VALVALUTA) as VALVALUTA,
                      ANI,
                      LUNAI
                FROM
                    (
                    select
                      NS.CODOBIECT,
                      G.CODSUBUNIT,
                      NS.CANTNIR as CANTINTR,
                      ( NS.PRET - coalesce(NS.ADAOS, 0)) * NS.CANTNIR as VALINTR,
                      NS.CANTNIR - (SELECT PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA.WME_RESULT
                                    FROM PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA(null, NS.CodNirStoc, ANI, LUNAI)) as RESTLUNA,
                      NS.PUVAL * NS.CANTNIR as VALVALUTA
                    from
                      NIRSTOC NS,
                      NIR N,
                      TMP_IOART_LUNA IO,
                      INTRARI I,
                      NGEST G
                    where
                      NS.CODIOART = IO.CODIOART
                      and IO.MG = 3
                      and NS.CODNIR = N.CODNIR
                      and N.TIPNIR in (1, 2, 3, 4, 5, 6, 7)
                      and N.ANULAT = 0
                      and N.OPERAT = 1
                      and I.CODINTR = N.CODINTR
                      and I.AN = ANI
                      and I.LUNA = LUNAI
                      and G.CODGEST = N.GEST
                  union all
                    select
                      NS.CODOBIECT,
                      G.CODSUBUNIT,
                      NS.CANTNIR as CANTINTR,
                      ( NS.PRET - coalesce(NS.ADAOS, 0)) * NS.CANTNIR as VALINTR,
                      NS.CANTNIR - (SELECT PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA.WME_RESULT
                                    FROM PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA(null, NS.CodNirStoc, ANI, LUNAI)) as RESTLUNA,
                      NS.PUVAL * NS.CANTNIR as VALVALUTA
                    from
                      NIRSTOC NS,
                      NIR N,
                      TMP_IOART_LUNA IO,
                      TRANSF I,
                      NGEST G
                    where
                      NS.CODIOART = IO.CODIOART
                      and IO.MG = 3
                      and NS.CODNIR = N.CODNIR
                      and N.TIPNIR in (12, 13)
                      and N.ANULAT = 0
                      and N.OPERAT = 1
                      and I.CODTRANSF = N.CODTRANSF
                      and I.AN = ANI
                      and I.LUNA = LUNAI
                      and G.CODGEST = N.GEST
                  union all
                    select
                      NS.CODOBIECT,
                      G.CODSUBUNIT,
                      NS.CANTNIR as CANTINTR,
                      ( NS.PRET - coalesce(NS.ADAOS, 0)) * NS.CANTNIR as VALINTR,
                      NS.CANTNIR - (SELECT PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA.WME_RESULT
                                    FROM PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA(null, NS.CodNirStoc, ANI, LUNAI)) as RESTLUNA,
                      NS.PUVAL * NS.CANTNIR as VALVALUTA
                    from
                      NIRSTOC NS,
                      NIR N,
                      TMP_IOART_LUNA IO,
                      IESIRI I,
                      NGEST G
                    where
                      NS.CODIOART = IO.CODIOART
                      and IO.MG = 3
                      and NS.CODNIR = N.CODNIR
                      and N.TIPNIR in (14, 15, 19)
                      and N.ANULAT = 0
                      and N.OPERAT = 1
                      and I.CODIES = N.CODIES
                      and I.AN = ANI
                      and I.LUNA = LUNAI
                      and G.CODGEST = N.GEST ) A_PG
                group BY CODOBIECT, CODSUBUNIT
               )
  loop
    INSERT INTO PMPLUNA ( CODPMPLUNA, CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, REST, AN, LUNA, VALVALUTA )
    values (nextval('SEQ_PMPLUNA_CODPMPLUNA'),
            V_REC.CODOBIECT,
            V_REC.CODSUBUNIT,
            V_REC.CANTINTR,
            V_REC.VALINTR,
            V_REC.RESTLUNA,
            ANI,
            LUNAI,
            V_REC.VALVALUTA );
  end loop;

  DELETE FROM PMP_ALL_LUNA WHERE AN = ANI and LUNA = LUNAI;

  for V_REC in
  (
    select
      CODOBIECT,
      sum(CANTINTR) as CANTINTR,
      sum(VALINTR) as VALINTR,
      sum(RESTLUNA) as RESTLUNA,
      sum(VALVALUTA) as VALVALUTA,
      ANI,
      LUNAI
    from
      (
        select
          NS.CODOBIECT,
          NS.CANTNIR as CANTINTR,
          ( NS.PRET - coalesce(NS.ADAOS, 0)) * NS.CANTNIR as VALINTR,
          NS.CANTNIR - (SELECT PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA.WME_RESULT
                        FROM PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA(null, NS.CodNirStoc, ANI, LUNAI)) as RESTLUNA,
          NS.PUVAL * NS.CANTNIR as VALVALUTA
        from
          NIRSTOC NS,
          NIR N,
          TMP_IOART_LUNA IO,
          INTRARI I
        where
          NS.CODIOART = IO.CODIOART
          and IO.MG = 3
          and NS.CODNIR = N.CODNIR
          and N.TIPNIR in (1, 2, 3, 4, 5, 7)
          and N.ANULAT = 0
          and N.OPERAT = 1
          and I.CODINTR = N.CODINTR
          and I.AN = ANI
          and I.LUNA = LUNAI
      union all
        select
          NS.CODOBIECT,
          NS.CANTNIR as CANTINTR,
          ( NS.PRET - coalesce(NS.ADAOS, 0)) * NS.CANTNIR as VALINTR,
          NS.CANTNIR - (SELECT PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA.WME_RESULT
                        FROM PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA(null, NS.CodNirStoc, ANI, LUNAI)) as RESTLUNA,
          NS.PUVAL * NS.CANTNIR as VALVALUTA
        from
          NIRSTOC NS,
          NIR N,
          TMP_IOART_LUNA IO,
          TRANSF I
        where
          NS.CODIOART = IO.CODIOART
          and IO.MG = 3
          and NS.CODNIR = N.CODNIR
          and N.TIPNIR in (12, 13)
          and N.ANULAT = 0
          and N.OPERAT = 1
          and I.CODTRANSF = N.CODTRANSF
          and I.AN = ANI
          and I.LUNA = LUNAI
      union all
        select
          NS.CODOBIECT,
          NS.CANTNIR as CANTINTR,
          ( NS.PRET - coalesce(NS.ADAOS, 0)) * NS.CANTNIR as VALINTR,
          NS.CANTNIR - (SELECT PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA.WME_RESULT
                        FROM PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA(null, NS.CodNirStoc, ANI, LUNAI)) as RESTLUNA,
          NS.PUVAL * NS.CANTNIR as VALVALUTA
        from
          NIRSTOC NS,
          NIR N,
          TMP_IOART_LUNA IO,
          IESIRI I
        where
          NS.CODIOART = IO.CODIOART
          and IO.MG = 3
          and NS.CODNIR = N.CODNIR
          and N.TIPNIR in (14, 15, 19)
          and N.ANULAT = 0
          and N.OPERAT = 1
          and I.CODIES = N.CODIES
          and I.AN = ANI
          and I.LUNA = LUNAI
      ) B_PG
    group BY CODOBIECT
  )
  loop
    INSERT INTO PMP_ALL_LUNA ( CODPMP_ALL_LUNA, CODOBIECT, CANTINTR, VALINTR, REST, AN, LUNA, VALVALUTA )
    values (nextval('SEQ_PMP_ALL_LUNA'),
            V_REC.CODOBIECT,
            V_REC.CANTINTR,
            V_REC.VALINTR,
            V_REC.RESTLUNA,
            ANI,
            LUNAI,
            V_REC.VALVALUTA );
  end loop;

  for V_REC in (SELECT CodNirStoc, PRETINREG FROM Tmp_NIRSTOCINI WHERE ActualizPret = 1 ) loop
    perform PKG_Jurnal_setDirtyNirStoc(V_REC.CODNIRSTOC, V_Rec.PRETINREG, '0', 0);
  end loop;

  perform NotifyModif(Operation, RecId, 'STOCINI');
 end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stocvalini_sp_deleterecord</obj_name>
  <obj_hashval>6c37ef681869765f4c173692f310d104</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stocvalini_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCODGEST numeric;
  ANI      numeric;
  LUNAI    numeric;
BEGIN
  --Florin 16.02.2023 - fixat 60999
  PERFORM PKG_STOCVALINI_SP_LOCKRECORD(RecId);

  SELECT GEST INTO aCODGEST FROM STOCVALINI WHERE CODSTOCVALINI = RecID;

  SELECT ANI, LUNAI INTO ANI, LUNAI FROM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA(current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric, current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric, ANI, LUNAI);

  DELETE FROM STOCVALLUNA WHERE GEST = aCODGEST AND  AN = ANI AND  LUNA = LUNAI;
  DELETE FROM STOCVALINI  WHERE CODSTOCVALINI = RECID;

  PERFORM NotifyModif(2, RecId, 'STOCVALINI');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_targetag_sp_lockrecord</obj_name>
  <obj_hashval>fdfc2148c852cc43a487be21cba58094</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_targetag_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
begin
  SELECT CodTARGETAG INTO Tmp FROM TARGETAG WHERE CodTARGETAG = RecId FOR UPDATE NOWAIT;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transeini_i</obj_name>
  <obj_hashval>e5689683c3c55df051989cfd9c86ff3c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transeini_i(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_TRANSEINI.I', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_setfrommanevra</obj_name>
  <obj_hashval>03fe7eb1c815fcb4c7022d3d2078de84</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_setfrommanevra(afrommanevra numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_TRASEULIVR.FromManevra',to_char(aFromManevra,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_traseulivr_sp_gotorecord</obj_name>
  <obj_hashval>c3ba546c0a61ecef613718fb494c5b94</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_traseulivr_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aTipTraseu   numeric;
  aCODLOCALIT  numeric;
  aAdresa      varchar;
  aLat         double precision;
  aLng         double precision;
  aDEN_ZONA    varchar;
  aSIMBAUTO    varchar;
  aDEN_LOCALIT varchar;
begin
  --Florin 13.09.2022 - fixat 55542
  INSERT INTO TMP_TraseuLivr(CodTraseuLivr, DenTraseu, SimbolTraseu, CODLOCALIT, Adresa, Opriri, Ore, Minute, Tip, Lat, Lng)
  SELECT CodTraseuLivr, DenTraseu, SimbolTraseu, CODLOCALIT, Adresa, Opriri, Ore, Minute, COALESCE( Tip, 0), Lat, Lng
  FROM TraseuLivr WHERE CodTraseuLivr = RecId;

  SELECT COALESCE( T.Tip, 0), T.CODLOCALIT, Z.DEN_ZONA, J.SIMBAUTO, L.DEN_LOCALIT, T.Adresa, T.Lat, T.Lng
  INTO aTipTraseu, aCODLOCALIT, aDEN_ZONA, aSIMBAUTO, aDEN_LOCALIT, aAdresa, aLat, aLng
  FROM Tmp_TraseuLivr T
      LEFT JOIN NLOCALIT L ON  L.CODLOCALIT = T.CODLOCALIT
      LEFT JOIN NJUDET   J ON  J.CODJUDET   = L.CODJUDET
      LEFT JOIN NZONE    Z ON  Z.CODZONA    = L.CODZONA;

  INSERT INTO TMP_NAGENDA_TRASEU(CODAGENDA, FIRMA, SEDIU, ZONA, JUDET, LOCALITATE, POZTRASEU, SSOC, ADRESA, CODTRASEULIVR, Lat, Lng, CodPart)
  SELECT A.CODAGENDA, P.DEN_PART, A.OBS, Z.DEN_ZONA, J.SIMBAUTO, L.DEN_LOCALIT,
        (CASE WHEN  aTipTraseu = 0 THEN A.POZTRASEU ELSE A.POZTRASEU1 END )  POZTRASEU,
         CASE WHEN A.SEDIUSOCIAL BETWEEN 4 AND 7 THEN 1 ELSE 0 END ,
        (SELECT GETADRESA.WME_RESULT FROM GETADRESA(NULL, A.SECTOR, A.STRADA, A.NR1, A.NR2, A.BLOC, A.SCARA, A.ETAJ, A.APART, A.CODPOSTAL)),
        RecId, A.Latitudine::numeric, A.Longitudine::numeric, A.CodPart
  FROM NAGENDA A
  INNER JOIN NPART    P ON  P.CODPART    = A.CODPART
  LEFT  JOIN NLOCALIT L ON  L.CODLOCALIT = A.CODLOCALIT
  LEFT  JOIN NJUDET   J ON  J.CODJUDET   = L.CODJUDET
  LEFT  JOIN NZONE    Z ON  Z.CODZONA    = L.CODZONA
  WHERE (aTipTraseu = 0 and  COALESCE( CODTRASEU, 0) = RecID)  or (aTipTraseu = 1 and  COALESCE(CODTRASEU1, 0) = RecID)  AND  COALESCE(a.INACTIV, 0) = 0
  union ALL
  SELECT 0, 'Start', '', aDEN_ZONA, aSIMBAUTO, aDEN_LOCALIT, 0, null, aAdresa, 0, aLat, aLng, -1;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_getct_monitor</obj_name>
  <obj_hashval>00c0c3bf44e3825abd10e99459e8397a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_getct_monitor(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := current_setting('PKG_TREZOR.CT_MONITOR', true);
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 'MON_16';
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_notifystergereincasarefact</obj_name>
  <obj_hashval>7388f388d13a065b413ef3900ae4b0af</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_notifystergereincasarefact(acodstingere numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  v_rec record;
BEGIN
  --Florin 22.11.2023
  FOR V_REC IN
  ( select
      g.coddoc,
      g.tipdoc
    from
      stingere s
      inner join obligpif o on o.codobligpif = s.codstinspif and o.semnificatie = 200
      inner join general g on g.codgeneral = o.codgeneral
    where
      s.codstingere = aCodStingere
  )
  LOOP
    PERFORM NotifyModif(11, v_rec.coddoc, 'IESIRI');
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tvaserv_sp_insertrecord</obj_name>
  <obj_hashval>0904cbea19442ab199344c67dc250f5a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tvaserv_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  INSERT INTO  TMP_TVASERV( CodTVASERV ) VALUES (0) ;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tvaserv_sp_lockrecord</obj_name>
  <obj_hashval>5400752a46f8c43f23df1d7c53b4e60f</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tvaserv_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  Tmp numeric;
BEGIN
  SELECT CodTVASERV INTO Tmp FROM TVASERV WHERE CodTVASERV = RecId FOR UPDATE NOWAIT;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_umsec_g_codum1</obj_name>
  <obj_hashval>fd79ba77f6e95c17c66610b1746116b7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_umsec_g_codum1(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_UMSEC.g_codum1', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_test</obj_name>
  <obj_hashval>342c0f598a613d8aca31665f661bb811</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_test()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_CMD RECORD;
  V_REC RECORD;
  vCodUtilaj      numeric;
  vCodUtilaj20    numeric;
  vCodUtilaj2     numeric;
  vCodUtilaj2C    numeric;
  vCodInterventie numeric;
begin
  BEGIN
    SELECT CODINTERVENTIIAUTO INTO vCodInterventie FROM ninterventiiauto WHERE denumire = 'MONTAJ';
  EXCEPTION WHEN others THEN
    vCodInterventie := 0;
  END;

  IF  vCodInterventie &gt; 0 THEN
    BEGIN
      SELECT u.codutilaj
      INTO vCodUtilaj
      FROM utilaje u INNER JOIN nartobj o ON  o.codobiect = u.codobiect
      WHERE o.denumire = 'LINIE AMENAJARE VITRINE MYA' AND  U.SERIEF = '182014,182015,182016';
    EXCEPTION WHEN others THEN
      vCodUtilaj := 0;
    END;

    IF  vCodUtilaj &gt; 0 THEN
      FOR v_cmd IN (SELECT  DISTINCT c1.codcomanda1
                    FROM comanda1 c1
                        INNER JOIN comanda  c  ON  c.codcomanda   = c1.codcomanda
                        INNER JOIN raportp0 r0 ON  r0.codcomanda1 = c1.codcomanda1
                        INNER JOIN raportp1 r1 ON  r1.codraportp0 = r0.codraportp0 and  r1.codraportp = r0.codraportp
                        INNER JOIN raportp  r  ON  r0.codraportp  = r.codraportp
                    WHERE c.nrdoc = 1264 and  c.tipdoc = 53 and  r.nrdoc = 1307
                   )
      LOOP
        SELECT NEXTVAL('SEQ_UTILAJE20_CODUTILAJ20') INTO vCodUtilaj20;
        SELECT NEXTVAL('SEQ_UTILAJE2_CODUTILAJ2')   INTO vCodUtilaj2;
        SELECT NEXTVAL('SEQ_UTILAJE2C_CODUTILAJ2C') INTO vCodUtilaj2;

        INSERT INTO utilaje20(codutilaj20, codutilaj, datadoc, descriere, stare)
        VALUES(vCodUtilaj20, vCodUtilaj, to_date('02.07.2018', 'dd.mm.yyyy'), 'Deviz montaj', 7);

        INSERT INTO utilaje2(codutilaj2, codutilaj, interventie, codutilaj20)
        VALUES(vCodUtilaj2, vCodUtilaj, vCodInterventie, vCodUtilaj20);

        INSERT INTO utilaje2c(codutilaj2c, codutilaj2, codutilaj, codcomanda1, datastart, dataend)
        VALUES(NEXTVAL('SEQ_UTILAJE2C_CODUTILAJ2C'), vcodutilaj2, vcodutilaj, v_cmd.codcomanda1, to_date('02.07.2018', 'dd.mm.yyyy'), to_date('03.07.2018', 'dd.mm.yyyy'));

        FOR v_rec IN (SELECT r1.angajat
                      FROM raportp0 r0
                          INNER JOIN raportp1 r1 ON  r1.codraportp0 = r0.codraportp0 and  r1.codraportp = r0.codraportp
                          INNER JOIN raportp  r  ON  r0.codraportp  = r.codraportp
                      WHERE r0.codcomanda1 = v_cmd.codcomanda1
                     )
        LOOP
          INSERT INTO utilaje2p(codutilaj2p, codutilaj2, codutilaj, codpers)
          VALUES(NEXTVAL('SEQ_UTILAJE2P_CODUTILAJ2P'), vCodUtilaj2, vCodUtilaj, v_rec.angajat);
        END LOOP;
      END LOOP;
    END IF;

    BEGIN
      SELECT u.codutilaj
      INTO vCodUtilaj
      FROM utilaje u INNER JOIN nartobj o ON  o.codobiect = u.codobiect
      WHERE o.denumire = 'MODERNIZARE SILOZURI CIMENT' AND  U.SERIEF = '2017';
    EXCEPTION WHEN others THEN
      vCodUtilaj := 0;
    END;

    IF  vCodUtilaj &gt; 0 THEN
      FOR v_cmd IN   (SELECT  DISTINCT c1.codcomanda1,
                             CASE
                               WHEN  c.nrdoc = 1390 THEN to_date('31.07.2018', 'dd.mm.yyyy')
                               WHEN  c.nrdoc = 1403 THEN to_date('29.08.2018', 'dd.mm.yyyy')
                               WHEN  c.nrdoc = 1404 THEN to_date('07.08.2018', 'dd.mm.yyyy')
                               WHEN c.nrdoc IN (1406, 1407, 1408, 1409) THEN to_date('27.08.2018', 'dd.mm.yyyy')
                               WHEN c.nrdoc IN (1484, 1483) THEN to_date('17.09.2018', 'dd.mm.yyyy')
                               WHEN  c.nrdoc = 1447 THEN to_date('04.09.2018', 'dd.mm.yyyy')
                               WHEN  c.nrdoc = 1777 THEN to_date('08.01.2019', 'dd.mm.yyyy')
                             END  DATASTART,
                             CASE
                               WHEN  c.nrdoc = 1390 THEN to_date('29.08.2018', 'dd.mm.yyyy')
                               WHEN  c.nrdoc = 1403 THEN to_date('29.08.2018', 'dd.mm.yyyy')
                               WHEN  c.nrdoc = 1404 THEN to_date('07.08.2018', 'dd.mm.yyyy')
                               WHEN c.nrdoc IN (1406, 1407, 1408, 1409) THEN to_date('27.08.2018', 'dd.mm.yyyy')
                               WHEN c.nrdoc IN (1484, 1483) THEN to_date('17.09.2018', 'dd.mm.yyyy')
                               WHEN  c.nrdoc = 1447 THEN to_date('04.09.2018', 'dd.mm.yyyy')
                               WHEN  c.nrdoc = 1777 THEN to_date('08.01.2019', 'dd.mm.yyyy')
                             END  DATAEND,
                             CASE
                               WHEN  c.nrdoc = 1390 THEN to_date('29.08.2018', 'dd.mm.yyyy')
                               WHEN  c.nrdoc = 1403 THEN to_date('29.08.2018', 'dd.mm.yyyy')
                               WHEN  c.nrdoc = 1404 THEN to_date('07.08.2018', 'dd.mm.yyyy')
                               WHEN  c.nrdoc = 1406 THEN to_date('27.08.2018', 'dd.mm.yyyy')
                               WHEN c.nrdoc IN (1407, 1408, 1409) THEN to_date('20.08.2018', 'dd.mm.yyyy')
                               WHEN c.nrdoc IN (1484, 1483) THEN to_date('17.09.2018', 'dd.mm.yyyy')
                               WHEN  c.nrdoc = 1447 THEN to_date('04.09.2018', 'dd.mm.yyyy')
                               WHEN  c.nrdoc = 1777 THEN to_date('08.01.2019', 'dd.mm.yyyy')
                             END  DATAI
                     FROM comanda1 c1
                         INNER JOIN comanda  c  ON  c.codcomanda   = c1.codcomanda
                         INNER JOIN raportp0 r0 ON  r0.codcomanda1 = c1.codcomanda1
                         INNER JOIN raportp1 r1 ON  r1.codraportp0 = r0.codraportp0 and  r1.codraportp = r0.codraportp
                         INNER JOIN raportp  r  ON  r0.codraportp  = r.codraportp
                     WHERE c.nrdoc IN (1390, 1403, 1404, 1406, 1407, 1408, 1409, 1483, 1484, 1447, 1777) and r.nrdoc IN (1434, 1447, 1448, 1450, 1451, 1452, 1453, 1530, 1529, 1492, 1823) and  c.tipdoc = 53
                    )
      LOOP
        SELECT NEXTVAL('SEQ_UTILAJE20_CODUTILAJ20') INTO vCodUtilaj20;
        SELECT NEXTVAL('SEQ_UTILAJE2_CODUTILAJ2')   INTO vCodUtilaj2;
        SELECT NEXTVAL('SEQ_UTILAJE2C_CODUTILAJ2C') INTO vCodUtilaj2;

        INSERT INTO utilaje20(codutilaj20, codutilaj, datadoc, descriere, stare)
        VALUES(vCodUtilaj20, vCodUtilaj, v_cmd.datai, 'Deviz montaj', 7);

        INSERT INTO utilaje2(codutilaj2, codutilaj, interventie, codutilaj20)
        VALUES(vCodUtilaj2, vCodUtilaj, vCodInterventie, vCodUtilaj20);

        INSERT INTO utilaje2c(codutilaj2c, codutilaj2, codutilaj, codcomanda1, datastart, dataend)
        VALUES(NEXTVAL('SEQ_UTILAJE2C_CODUTILAJ2C'), vcodutilaj2, vcodutilaj, v_cmd.codcomanda1, v_cmd.datastart, v_cmd.dataend);

        FOR v_rec IN (SELECT r1.angajat
                      FROM raportp0 r0
                          INNER JOIN raportp1 r1 ON  r1.codraportp0 = r0.codraportp0 and  r1.codraportp = r0.codraportp
                          INNER JOIN raportp  r  ON  r0.codraportp  = r.codraportp
                      WHERE r0.codcomanda1 = v_cmd.codcomanda1
                     )
        LOOP
          INSERT INTO utilaje2p(codutilaj2p, codutilaj2, codutilaj, codpers)
          VALUES(NEXTVAL('SEQ_UTILAJE2P_CODUTILAJ2P'), vCodUtilaj2, vCodUtilaj, v_rec.angajat);
        END LOOP;
      END LOOP;
    END IF;

    BEGIN
      SELECT u.codutilaj
      INTO vCodUtilaj
      FROM utilaje u INNER JOIN nartobj o ON  o.codobiect = u.codobiect
      WHERE o.denumire = 'CUPTOR REVENT MODEL 725 O/G' AND  U.SERIEF = '19.2531.117';
    EXCEPTION WHEN others THEN
      vCodUtilaj := 0;
    END;

    IF  vCodUtilaj &gt; 0 THEN
      FOR v_cmd IN (SELECT  DISTINCT c1.codcomanda1
                    FROM comanda1 c1
                    INNER JOIN comanda c ON  c.codcomanda = c1.codcomanda
                    INNER JOIN raportp0 r0 ON  r0.codcomanda1 = c1.codcomanda1
                    INNER JOIN raportp1 r1 ON  r1.codraportp0 = r0.codraportp0 and  r1.codraportp = r0.codraportp
                    INNER JOIN raportp r ON  r0.codraportp = r.codraportp
                    WHERE c.nrdoc = 2090 and  c.tipdoc = 53 and  r.nrdoc = 2139
                   )
      LOOP
        SELECT NEXTVAL('SEQ_UTILAJE20_CODUTILAJ20') INTO vCodUtilaj20;
        SELECT NEXTVAL('SEQ_UTILAJE2_CODUTILAJ2')   INTO vCodUtilaj2;
        SELECT NEXTVAL('SEQ_UTILAJE2C_CODUTILAJ2C') INTO vCodUtilaj2;

        INSERT INTO utilaje20(codutilaj20, codutilaj, datadoc, descriere, stare)
        VALUES(vCodUtilaj20, vCodUtilaj, to_date('07.05.2019', 'dd.mm.yyyy'), 'Deviz montaj', 7);

        INSERT INTO utilaje2(codutilaj2, codutilaj, interventie, codutilaj20)
        VALUES(vCodUtilaj2, vCodUtilaj, vCodInterventie, vCodUtilaj20);

        INSERT INTO utilaje2c(codutilaj2c, codutilaj2, codutilaj, codcomanda1, datastart, dataend)
        VALUES(NEXTVAL('SEQ_UTILAJE2C_CODUTILAJ2C'), vcodutilaj2, vcodutilaj, v_cmd.codcomanda1, to_date('23.04.2019', 'dd.mm.yyyy'), to_date('07.05.2019', 'dd.mm.yyyy'));

        FOR v_rec IN (SELECT r1.angajat
                      FROM raportp0 r0
                      INNER JOIN raportp1 r1 ON  r1.codraportp0 = r0.codraportp0 and  r1.codraportp = r0.codraportp
                      INNER JOIN raportp  r  ON  r0.codraportp  = r.codraportp
                      WHERE r0.codcomanda1 = v_cmd.codcomanda1
                     )
        LOOP
          INSERT INTO utilaje2p(codutilaj2p, codutilaj2, codutilaj, codpers)
          VALUES(NEXTVAL('SEQ_UTILAJE2P_CODUTILAJ2P'), vCodUtilaj2, vCodUtilaj, v_rec.angajat);
        END LOOP;
      END LOOP;
    END IF;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_voucher_sp_insertrecord</obj_name>
  <obj_hashval>aabe0c2a2a5a88f31859250063b8e3fd</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_voucher_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_VOUCHER (CodVoucher) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_weekcashflow_setct_monitor</obj_name>
  <obj_hashval>36102f8536fd1fc4b15076922d1d681b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_weekcashflow_setct_monitor(act_monitor character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_WEEKCASHFLOW.CT_MONITOR',aCT_MONITOR,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_detalii_oferta</obj_name>
  <obj_hashval>4d7476fa574c0eaa919b44f3fd2d16b5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_detalii_oferta(INOUT wme_result refcursor, INOUT acodoferta numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
  DECLARE
    S varchar;
    OFERTA1CURSOR REFCURSOR;
  begin
    S := '
      SELECT O1.CODOFERTA1, N.DENUMIRE, O1.PRET, O1.CANTMIN,
        O1.ZILEL, O1.ZILEC, O1.PROCDISCOUNT, O1.OBS,
        O1.CODOBIECT, N.CODARTICOL, U1.DEN_UM1, O1.CODOFERTA,
        O1.UMSEC, O1.PROCADAOS, O1.D1, O1.D2,
        O1.D3, O1.INDEXLOCAL, O1.PRETREF
      FROM OFERTA1 O1, NARTOBJ N, NUM1 U1
      WHERE
        O1.CODOFERTA = '
          || coalesce ( (aCODOFERTA) ::varchar::varchar ,'')
          || '
        AND O1.UMSEC = U1.CODUM1
        AND O1.CODOBIECT = N.CODOBIECT
      ORDER BY
        O1.INDEXLOCAL ';
    OPEN OFERTA1CURSOR for execute S;
    WME_Result := OFERTA1CURSOR;
    RETURN;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_getstocuri_stoc0</obj_name>
  <obj_hashval>17dd4c4d42fc61106d8f95ba8a69f3a2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_getstocuri_stoc0(INOUT wme_result refcursor, INOUT acodpart numeric, INOUT adenobiect character varying, INOUT adenclasa character varying, INOUT acodgest numeric, INOUT acodextern character varying, INOUT acodintern character varying, INOUT atogglevat numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
  DECLARE
    STOCCURSOR REFCURSOR;
    FILTRU_ART   varchar := '';
      FILTRU_CLASA varchar := '';
    FILTRU_GEST  varchar := '';
     FILTRU_CODEXTERN   varchar := '';
      FILTRU_CODINTERN   varchar := '';
      S           varchar;
      AN           numeric(5);
      LUNA         numeric(2);
      aCODCATPRET  numeric := 0;
      COMPUTE_VAT  varchar := ' coalesce(PM.LEI, 0) ';
      REVERSE_VAT  varchar := ' coalesce(PM.LEI, 0) ';
       var_table_varchar varchar array;
  BEGIN
    --Florin 19.09.2024 - sinc. Oracle
    AN   := EXTRACT(YEAR FROM current_date);
    LUNA := EXTRACT(MONTH FROM current_date);
    perform pkg_globals_setlunalucru_simpla(AN, Luna);
    perform pkg_stoc_generare_facturi_make_config_luna_ext();
    BEGIN
      SELECT coalesce(CODCATEGPRET, 0) into strict aCODCATPRET FROM NPART WHERE CODPART = aCODPART;
      EXCEPTION WHEN OTHERS THEN aCODCATPRET := 0;
    END;
       IF coalesce(aToggleVAT, 0) = 1 THEN
      REVERSE_VAT := ' ROUND(coalesce(PM.LEI, 0) / (1 + coalesce(TVAL.PROCENT, 0) / 100), 2) ';
    END IF;

    S := ' SELECT distinct * FROM ' ||
         ' ( ' ||
         '    SELECT ' ||
         '      1 AS TIPARTICOL, ' ||
         '      O.DENUMIRE AS DENOBIECT, ' ||
         '      O.CODEXTERN, ' ||
         '      O.CODINTERN,' ||
       '      O.CODARTICOL,' ||
       '      O.INACTIV, ' ||
         '      A.DEN_ARTICOL AS DEN_ART,' ||
         '      A.UM1 AS DUM1,' ||
         '      A.COMENZIONLINE,' ||
         '      U0.DEN_UM1 AS DENUM1,' ||
         '      NULL as DEN_GEST, ' ||
         '      O.CODOBIECT, ' ||
         '      0 as CODGEST, ' ||
         '    CASE ' ||
         '      WHEN CAT.TIP = 1 THEN '|| REVERSE_VAT || ' ' ||
         '      ELSE coalesce(PM.LEI, 0) ' ||
         '    END  AS PRET, ' ||
         '      coalesce(TVAL.PROCENT, 0) AS TVA, ' ||
         '    CASE ' ||
         '      WHEN CAT.TIP = 1 THEN coalesce(PM.LEI, 0) ' ||
         '      ELSE '|| COMPUTE_VAT || ' ' ||
         '    END  AS PRET_TVA, ' ||
         '      0 AS STOC, ' ||
         '      P.DEN_PART AS PRODUCATOR, ' ||
         '      CLAS.DEN_CLASEA AS CLASA, ' ||
         '      CLAS.CODCLASEA, ' ||
         '      U.DEN_UM, ' ||
         '      U1.CODUM1 ' ||
         '    FROM  ' ||
         '      NART A   ' ||
       '      LEFT OUTER JOIN NUM1 U0 ON U0.CODUM1 = A.UM1 ' ||
         '      LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = A.CODARTICOL  ' ||
         '      LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA = NAL.CODTVA ' ||
         '      LEFT OUTER JOIN NUM U ON U.CODUM = A.UM ' ||
         '      LEFT OUTER JOIN NUM1 U1 ON U1.CODUM = U.CODUM AND U1.SECUNDARA = 0' ||
         '      LEFT OUTER JOIN NCLASEA CLAS ON CLAS.CODCLASEA = CLASA, ' ||
         '      NARTOBJ O ' ||
         '      LEFT OUTER JOIN PRETM PM ON PM.CODOBIECT = O.CODOBIECT AND PM.SUBUNITATEA = ' || coalesce(GETSUBUNITATE(), 0)::varchar ||
         '      AND CODCATPRET = ' || aCODCATPRET::varchar ||
         '      LEFT JOIN NCATPRET CAT ON CAT.CODCATPRET = PM.CODCATPRET ' ||
         '      LEFT OUTER JOIN NPART P ON P.CODPART = O.CODPRODUCATOR ' ||
         '    WHERE O.CODARTICOL = A.CODARTICOL AND coalesce(O.INACTIV, 0) &lt;&gt;1 AND coalesce(O.BLOCAT, 0) NOT IN (1, 3) AND ( (A.TIPARTICOL = 1 ) OR (A.TIPARTICOL = 0 AND ((SELECT COUNT(*) FROM NIRSTOC NS WHERE NS.CODOBIECT=O.CODOBIECT) = 0) and 2&gt; 1 ) ) ' ||
         ' UNION ALL ' ||
         ' SELECT ' ||
         '    0 AS TIPARTICOL, ' ||
         '    O.DENUMIRE AS DENOBIECT, ' ||
         '    O.CODEXTERN,' ||
         '    O.CODINTERN, ' ||
       '    O.CODARTICOL,' ||
       '      O.INACTIV, ' ||
         '    A.DEN_ARTICOL AS DEN_ART,' ||
         '    A.UM1 AS DUM1,' ||
         '      A.COMENZIONLINE,' ||
         '    U0.DEN_UM1 AS DENUM1,' ||
         '    G.DEN_GEST, ' ||
         '    STOCVIEW.CODOBIECT, ' ||
         '    STOCVIEW.CODGEST,' ||

         '    CASE ' ||
         '      WHEN CAT.TIP = 1 THEN '|| REVERSE_VAT || ' ' ||
         '      ELSE coalesce(PM.LEI, 0) ' ||
         '    END  AS PRET, ' ||
         '      coalesce(TVAL.PROCENT, 0) AS TVA, ' ||
         '    CASE ' ||
         '      WHEN CAT.TIP = 1 THEN coalesce(PM.LEI, 0) ' ||
         '      ELSE '|| COMPUTE_VAT || ' ' ||
         '    END  AS PRET_TVA, ' ||

         '    STOCVIEW.STOC, ' ||
         '    P.DEN_PART AS PRODUCATOR, ' ||
         '    CLAS.DEN_CLASEA AS CLASA, ' ||
         '    CLAS.CODCLASEA, ' ||
         '    U.DEN_UM, ' ||
         '    U1.CODUM1 ' ||
         ' FROM ' ||
         '    ( ' ||  -- stoc cumulat
         '     SELECT CODOBIECT, CODGEST, SUM(STOC) AS STOC ' ||
         '     FROM ' ||
         '         ( ' ||
         '           SELECT  CODOBIECT, CODGEST, STOC FROM ' ||
         '                (  ' ||
         '                   SELECT ' ||
         '                      NS.CODOBIECT, ' ||
         '                      N.GEST AS CODGEST,' ||
         '                      SUM(NS.REST - coalesce((SELECT SUM(REST) FROM REZERVATS R WHERE R.CODNIRSTOC = NS.CODNIRSTOC), 0)) AS STOC ' ||
         '                   FROM ' ||
         '                      NIRSTOC NS  ' ||
         '                      LEFT OUTER JOIN TMP_IOART_LUNA IOAL ON IOAL.CODIOART = NS.CODIOART, ' ||
         '                      NIR     N ' ||
         '                   WHERE ' ||
  --     '                      NS.REST &gt;= 0 ' ||
         '                      N.CODNIR = NS.CODNIR ' ||
         '                      AND (((SELECT COUNT(*) FROM TMP_GESTDEDICATE) = 0) OR (EXISTS (SELECT CODGEST FROM TMP_GESTDEDICATE WHERE CODGEST = N.GEST))) ' ||
         '                      AND IOAL.MG &lt;&gt; 3 AND IOAL.MG &lt;&gt; 5  ' ||
         '                      AND coalesce(IOAL.ESTEMIFIX, 0) = 0    ' ||
         '                      AND coalesce(IOAL.ESTEOBINV, 0) = 0    ' ||
         '                   GROUP BY ' ||
         '                      NS.CODOBIECT, ' ||
         '                      N.GEST ' ||
         '                ) ' ||
  --       '           WHERE STOC &gt;= 0 ' ||
         '         ) ' ||
         '     GROUP BY CODOBIECT, CODGEST ' ||
         '    ) STOCVIEW,  ' ||
         '    NARTOBJ O ' ||
         '    LEFT OUTER JOIN PRETM PM ON PM.CODOBIECT = O.CODOBIECT AND PM.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE AND CODCATPRET = ' || aCODCATPRET::varchar ||
         '    LEFT JOIN NCATPRET CAT ON CAT.CODCATPRET = PM.CODCATPRET ' ||
         '    LEFT OUTER JOIN NART A ON A.CODARTICOL = O.CODARTICOL  ' ||
      '      LEFT OUTER JOIN NUM1 U0 ON U0.CODUM1 = A.UM1 ' ||
         '    LEFT OUTER JOIN NUM U ON U.CODUM = A.UM ' ||
         '    LEFT OUTER JOIN NUM1 U1 ON U1.CODUM = U.CODUM AND U1.SECUNDARA = 0' ||
         '    LEFT OUTER JOIN NCLASEA CLAS ON CLAS.CODCLASEA = CLASA  ' ||
         '    LEFT OUTER JOIN NPART P ON P.CODPART = O.CODPRODUCATOR ' ||
         '    LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = A.CODARTICOL  ' ||
         '    LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA = NAL.CODTVA, ' ||
         '    NGEST G ' ||
         '  WHERE ' ||
         '    G.CODGEST = STOCVIEW.CODGEST ' ||
         '    AND G.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE ' ||
         '    AND O.CODOBIECT = STOCVIEW.CODOBIECT AND coalesce(O.INACTIV, 0) &lt;&gt;1 AND coalesce(O.BLOCAT, 0) NOT IN (1, 3) ' ||
         ' ) ' ||
         '  WHERE 1=1';

    IF coalesce(aDENOBIECT, '?') &lt;&gt; '?' THEN
      var_table_varchar := pkg_wmeonline_TOKENIZE_STRING(aDENOBIECT, ' ');
          for elem in 1 .. array_length(var_table_varchar)
          loop
           FILTRU_ART := FILTRU_ART || ' AND UPPER(DENOBIECT) LIKE ' || '''%' || UPPER(var_table_varchar[elem]) || '%''';
          end loop;
    END IF;

    IF coalesce(aCODEXTERN, '?') &lt;&gt; '?' THEN
      FILTRU_CODEXTERN := ' AND UPPER(CODEXTERN) LIKE ' || '''%' || UPPER(aCODEXTERN) || '%''';
    END IF;


    IF coalesce(aCODINTERN, '?') &lt;&gt; '?' THEN
      FILTRU_CODINTERN := ' AND UPPER(CODINTERN) LIKE ' || '''%' || UPPER(aCODINTERN) || '%''';
    END IF;


    IF coalesce(aDENCLASA, '?') &lt;&gt; '?' THEN
      FILTRU_CLASA := ' AND UPPER(CLASA) LIKE ' || '''%' || UPPER(aDENCLASA) || '%''';
    END IF;


  IF coalesce(aDENOBIECT, '?') &lt;&gt; '?' AND SUBSTR(aDENOBIECT, 1, 1) = '=' THEN
      FILTRU_ART := ' AND UPPER(DENOBIECT) = ''' ||  LTRIM(UPPER(aDENOBIECT), '=') || ''' ';
  END IF;

  IF coalesce(aCODEXTERN, '?') &lt;&gt; '?' AND SUBSTR(aCODEXTERN, 1, 1) = '=' THEN
      FILTRU_CODEXTERN := ' AND UPPER(CODEXTERN) = ''' ||  LTRIM(UPPER(aCODEXTERN), '=') || ''' ';
  END IF;

  IF coalesce(aCODINTERN, '?') &lt;&gt; '?' AND SUBSTR(aCODINTERN, 1, 1) = '=' THEN
      FILTRU_CODINTERN := ' AND UPPER(CODINTERN) = ''' ||  LTRIM(UPPER(aCODINTERN), '=') || ''' ';
  END IF;

  IF coalesce(aDENCLASA, '?') &lt;&gt; '?' AND SUBSTR(aDENCLASA, 1, 1) = '=' THEN
      FILTRU_CLASA := ' AND UPPER(CLASA) = ''' ||  LTRIM(UPPER(aDENCLASA), '=') || ''' ';
  END IF;


    IF coalesce(aCODGEST, 0) &lt;&gt; 0 THEN
        FILTRU_GEST := ' AND CODGEST = ' || aCODGEST::varchar;
    END IF;

    OPEN STOCCURSOR FOR execute S || FILTRU_ART || ' ' || FILTRU_CLASA || ' ' || FILTRU_GEST || FILTRU_CODEXTERN || ' ' || FILTRU_CODINTERN || ' ORDER BY DENOBIECT ';
  WME_Result := STOCCURSOR;
    RETURN;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_getstocuri_stoc0_4php</obj_name>
  <obj_hashval>d9ccbbaa6b8185675b4e82eeb53669b2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_getstocuri_stoc0_4php(refcursor, numeric, character varying, character varying, numeric, character varying, character varying, numeric, numeric)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
DECLARE
  STOCCURSOR        REFCURSOR;
  S                 varchar;
  S_PRET            varchar;
  COND_PM           varchar;
  sAL               varchar;
  AN                numeric(5);
  LUNA              numeric(2);
  sCODCATPRET       varchar;
  sCODSUBUNIT       varchar := coalesce(GETSUBUNITATE(), 0)::varchar;
  COMPUTE_VAT       varchar := ' coalesce(PM.LEI, 0) ';
  REVERSE_VAT       varchar := ' coalesce(PM.LEI, 0) ';
  var_table_varchar varchar array;
  vCntGestDedicate  NUMERIC;
BEGIN
-- Stef 05.08.2022
  AN   := EXTRACT(YEAR FROM current_date);
  LUNA := EXTRACT(MONTH FROM current_date);
  sAL  := (An*12+LUNA)::varchar;
  perform pkg_globals_setlunalucru_simpla(AN, Luna);
  --perform pkg_stoc_generare_facturi_make_config_luna();
  BEGIN
    SELECT coalesce(CODCATEGPRET, 0)::varchar INTO STRICT sCODCATPRET FROM NPART WHERE CODPART = $2;
  EXCEPTION
    WHEN OTHERS THEN sCODCATPRET := '0';
  END;

  S_PRET := 'PM.LEI';
  COND_PM := '';
  IF coalesce($9, 0) &lt;&gt; 0 THEN
    S_PRET  := 'PM.VALUTA';
    COND_PM := ' AND PM.MONEDA = ' || $9::varchar || ' ';
  END IF;

  COMPUTE_VAT := ' coalesce(' || S_PRET || ', 0) ';
  REVERSE_VAT := ' coalesce(' || S_PRET || ', 0) ';

  IF coalesce($8, 0) = 1 THEN
    COMPUTE_VAT := ' ROUND(coalesce(' || S_PRET || ', 0) * (1 + coalesce(TVAL.PROCENT, 0) / 100), 2) ';
  END IF;

  IF coalesce($8, 0) = 1 THEN
    REVERSE_VAT := ' ROUND(coalesce(' || S_PRET || ', 0) / (1 + coalesce(TVAL.PROCENT, 0) / 100), 2) ';
  END IF;

  SELECT COUNT(1) INTO vCntGestDedicate FROM TMP_GESTDEDICATE;

  S :=
  'SELECT distinct *
  FROM (
    SELECT
       1 AS TIPARTICOL, O.DENUMIRE AS DENOBIECT, O.CODEXTERN, O.CODINTERN, O.CODARTICOL, O.INACTIV, A.DEN_ARTICOL AS DEN_ART, A.UM1 AS DUM1, A.COMENZIONLINE,
       U0.DEN_UM1 AS DENUM1, NULL AS DEN_GEST, O.CODOBIECT, 0 AS CODGEST,
       CASE  WHEN CAT.TIP = 1 THEN '|| REVERSE_VAT || ' ELSE coalesce(' || S_PRET || ', 0) END AS PRET,
       coalesce(TVAL.PROCENT, 0) AS TVA,
       CASE WHEN CAT.TIP = 1 THEN coalesce(' || S_PRET || ', 0) ELSE '|| COMPUTE_VAT || ' END AS PRET_TVA,
       0 AS STOC, P.DEN_PART AS PRODUCATOR, CLAS.DEN_CLASEA AS CLASA, CLAS.CODCLASEA, U.DEN_UM, U1.CODUM1
     FROM NART A
       INNER JOIN NARTOBJ O ON O.CODARTICOL = A.CODARTICOL
       LEFT JOIN NUM1 U0 ON U0.CODUM1 = A.UM1
       LEFT JOIN NART1 NAL  ON NAL.CODARTICOL = A.CODARTICOL AND '||sAL||' BETWEEN NAL.ALSTART AND NAL.ALSTOP
       LEFT JOIN NTVA1 TVAL ON TVAL.CODTVA = NAL.CODTVA AND '||sAL||' BETWEEN TVAL.ALSTART AND TVAL.ALSTOP
       LEFT JOIN NUM U ON U.CODUM = A.UM
       LEFT JOIN NUM1 U1 ON U1.CODUM = U.CODUM AND U1.SECUNDARA = 0
       LEFT JOIN NCLASEA CLAS ON CLAS.CODCLASEA = CLASA
       LEFT JOIN PRETM PM ON PM.CODOBIECT = O.CODOBIECT AND PM.SUBUNITATEA = '||sCODSUBUNIT|| COND_PM ||' AND PM.CODCATPRET = '||sCODCATPRET||'
       LEFT JOIN NCATPRET CAT ON CAT.CODCATPRET = PM.CODCATPRET
       LEFT JOIN NPART P ON P.CODPART = O.CODPRODUCATOR
    WHERE coalesce(O.INACTIV, 0) &lt;&gt; 1
      AND coalesce(O.BLOCAT, 0) NOT IN (1, 3)
      AND (
           (A.TIPARTICOL = ''1'' ) OR
           (A.TIPARTICOL = ''0'' AND NOT EXISTS (
        SELECT 1
        FROM NIRSTOC NS
        JOIN NIR N ON N.CODNIR = NS.CODNIR
        JOIN NGEST G ON G.CODGEST = N.GEST
        WHERE NS.CODOBIECT = O.CODOBIECT
          AND G.CODSUBUNIT = '|| sCODSUBUNIT ||'
   ))
      )
    UNION ALL
    SELECT
       0 AS TIPARTICOL, O.DENUMIRE AS DENOBIECT, O.CODEXTERN, O.CODINTERN, O.CODARTICOL, O.INACTIV, A.DEN_ARTICOL AS DEN_ART, A.UM1 AS DUM1, A.COMENZIONLINE,
       U0.DEN_UM1 AS DENUM1, G.DEN_GEST, STOCVIEW.CODOBIECT, STOCVIEW.CODGEST,
       CASE WHEN CAT.TIP = 1 THEN '|| REVERSE_VAT || ' ELSE coalesce(' || S_PRET || ', 0) END  AS PRET,
       coalesce(TVAL.PROCENT, 0) AS TVA,
       CASE WHEN CAT.TIP = 1 THEN coalesce(' || S_PRET || ', 0) ELSE '|| COMPUTE_VAT || ' END  AS PRET_TVA,
       STOCVIEW.STOC, P.DEN_PART AS PRODUCATOR, CLAS.DEN_CLASEA AS CLASA, CLAS.CODCLASEA, U.DEN_UM, U1.CODUM1
    FROM ( -- stoc cumulat
      SELECT CODOBIECT, CODGEST, SUM(STOC) AS STOC
      FROM (
        SELECT  CODOBIECT, CODGEST, STOC
        FROM (
          SELECT NS.CODOBIECT, N.GEST AS CODGEST, SUM(NS.REST - coalesce((SELECT SUM(REST) FROM REZERVATS R WHERE R.CODNIRSTOC = NS.CODNIRSTOC), 0)) AS STOC
          FROM NIRSTOC NS
            INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
            LEFT JOIN IOART1 IOAL ON IOAL.CODIOART = NS.CODIOART AND '||sAL||' BETWEEN IOAL.ALSTART AND IOAL.ALSTOP
          WHERE IOAL.MG &lt;&gt; 5 '||
          CASE WHEN vCntGestDedicate &gt; 0 THEN '
            AND EXISTS (SELECT CODGEST FROM TMP_GESTDEDICATE WHERE CODGEST = N.GEST)'
            ELSE ''
          END||'
            AND (SELECT PKG_CATEGCONST_ESTEMIFIX.WME_RESULT FROM PKG_CATEGCONST_ESTEMIFIX(NULL, IOAL.CONT)) = 0
            AND (SELECT PKG_CATEGCONST_ESTEOBINV.WME_RESULT FROM PKG_CATEGCONST_ESTEOBINV(NULL, IOAL.CONT)) = 0
          GROUP BY NS.CODOBIECT, N.GEST
        ) sq
      ) sq1
      GROUP BY CODOBIECT, CODGEST
    ) STOCVIEW
      INNER JOIN NARTOBJ O ON O.CODOBIECT = STOCVIEW.CODOBIECT
      INNER JOIN NGEST G ON G.CODGEST = STOCVIEW.CODGEST AND G.CODSUBUNIT = '||sCODSUBUNIT||'
      LEFT JOIN PRETM PM ON PM.CODOBIECT = O.CODOBIECT AND PM.SUBUNITATEA = G.CODSUBUNIT AND PM.CODCATPRET = '||sCODCATPRET||COND_PM||'
      LEFT JOIN NCATPRET CAT ON CAT.CODCATPRET = PM.CODCATPRET
      LEFT JOIN NART A ON A.CODARTICOL = O.CODARTICOL
      LEFT JOIN NUM1 U0 ON U0.CODUM1 = A.UM1
      LEFT JOIN NUM U ON U.CODUM = A.UM
      LEFT JOIN NUM1 U1 ON U1.CODUM = U.CODUM AND U1.SECUNDARA = 0
      LEFT JOIN NCLASEA CLAS ON CLAS.CODCLASEA = A.CLASA
      LEFT JOIN NPART P ON P.CODPART = O.CODPRODUCATOR
      LEFT JOIN NART1 NAL  ON NAL.CODARTICOL = A.CODARTICOL AND '||sAL||' BETWEEN NAL.ALSTART AND NAL.ALSTOP
      LEFT JOIN NTVA1 TVAL ON TVAL.CODTVA = NAL.CODTVA AND '||sAL||' BETWEEN TVAL.ALSTART AND TVAL.ALSTOP
    WHERE coalesce(O.INACTIV, 0) &lt;&gt;1 AND coalesce(O.BLOCAT, 0) NOT IN (1, 3)
  ) subq
  WHERE 1=1';

  IF coalesce($3, '?') not in ('?', '') THEN
    var_table_varchar := string_to_array($3, ' ');
    FOR elem IN 1 .. array_length(var_table_varchar, 1)
    LOOP
      s := s ||'  AND UPPER(DENOBIECT) LIKE ' || '''%' || UPPER(var_table_varchar[elem]) || '%''';
    END LOOP;
  END IF;

  IF coalesce($6, '?') not in ('?', '') THEN
    s := s ||'
    AND UPPER(CODEXTERN) LIKE ' || '''%' || UPPER($6) || '%''';
  END IF;

  IF coalesce($7, '?') not in ('?', '') THEN
    s := s ||'
    AND UPPER(CODINTERN) LIKE ' || '''%' || UPPER($7) || '%''';
  END IF;

  IF coalesce($4, '?') not in ('?', '') THEN
    s := s ||'
    AND UPPER(CLASA) LIKE ' || '''%' || UPPER($4) || '%''';
  END IF;

  IF (coalesce($3, '?') not in ('?', '')) AND SUBSTR($3, 1, 1) = '=' THEN
    s := s ||'
    AND UPPER(DENOBIECT) = ''' ||  LTRIM(UPPER($3), '=') || ''' ';
  END IF;

  IF (coalesce($6, '?') not in ('?', '')) AND SUBSTR($6, 1, 1) = '=' THEN
    s := s ||'
    AND UPPER(CODEXTERN) = ''' ||  LTRIM(UPPER($6), '=') || ''' ';
  END IF;

  IF (coalesce($7, '?') not in ('?', '')) AND SUBSTR($7, 1, 1) = '=' THEN
    s := s ||'
    AND UPPER(CODINTERN) = ''' ||  LTRIM(UPPER($7), '=') || ''' ';
  END IF;

  IF (coalesce($4, '?') not in ('?', '')) AND SUBSTR($4, 1, 1) = '=' THEN
    s := s ||'
    AND UPPER(CLASA) = ''' ||  LTRIM(UPPER($4), '=') || ''' ';
  END IF;

  IF coalesce($5, 0) &lt;&gt; 0 THEN
    s := s ||'
    AND CODGEST = ' || $5::varchar;
  END IF;
  s := s ||'
  ORDER BY DENOBIECT';

  OPEN $1 FOR execute S;
  RETURN NEXT $1;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_zineluc_sp_insertrecord</obj_name>
  <obj_hashval>0d366d12562824171c6b74b8d479563d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_zineluc_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_ZINELUC (CodZiNeluc) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_niruri_ser_luna</obj_name>
  <obj_hashval>4e5a9ed9c6dceb99ec830babc01a2b6b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_niruri_ser_luna()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$ begin
  return
  'select
    NSE.CODNIRSER,
    NSE.CODNIRSTOC,
    NSE.CANTNIR as REST,
    NSE.CANTUM1 as RESTUM1,
    NSE.CANTUM2 as RESTUM2
  from
    NIRSER NSE,
    NIRSTOC NS
    left join NIR     N on N.CODNIR  = NS.CODNIR
    left join INTRARI I on I.CODINTR = N.CODINTR,
    TMP_IOART_LUNA IO
  where
    NSE.CODNIRSTOC = NS.CODNIRSTOC
    and N.TIPNIR in (1, 2, 3, 4, 5, 6, 7)
    and N.ANULAT = 0
    and N.OPERAT = 1
    and I.AN   = current_setting(''PKG_GLOBALS.ANTEMP''  , true)::numeric
    and I.LUNA = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric
    and IO.CODIOART = NS.CODIOART
    and IO.MG &lt;&gt; 5
  union all
  select
    NSE.CODNIRSER,
    NSE.CODNIRSTOC,
    NSE.CANTNIR as REST,
    NSE.CANTUM1 as RESTUM1,
    NSE.CANTUM2 as RESTUM2
  from
    NIRSER NSE,
    NIRSTOC NS
    left join NIR    N on N.CODNIR = NS.CODNIR
    left join IESIRI I on I.CODIES = N.CODIES,
    TMP_IOART_LUNA IO
  where
    NSE.CODNIRSTOC = NS.CODNIRSTOC
    and N.TIPNIR in (19, 20, 21, 22, 23, 24, 25)
    and N.ANULAT = 0
    and N.OPERAT = 1
    and I.AN   = current_setting(''PKG_GLOBALS.ANTEMP''  , true)::numeric
    and I.LUNA = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric
    and IO.CODIOART = NS.CODIOART
    and IO.MG &lt;&gt; 5
  union all
  select
    NSE.CODNIRSER,
    NSE.CODNIRSTOC,
    NSE.CANTNIR as REST,
    NSE.CANTUM1 as RESTUM1,
    NSE.CANTUM2 as RESTUM2
  from
    NIRSER NSE,
    NIRSTOC NS
    left join NIR    N on N.CODNIR    = NS.CODNIR
    left join TRANSF T on T.CODTRANSF = N.CODTRANSF,
    TMP_IOART_LUNA IO
  where
    NSE.CODNIRSTOC = NS.CODNIRSTOC
    and N.TIPNIR in (12,
    13)
    and N.ANULAT = 0
    and N.OPERAT = 1
    and T.AN   = current_setting(''PKG_GLOBALS.ANTEMP''  , true)::numeric
    and T.LUNA = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric
    and IO.CODIOART = NS.CODIOART
    and IO.MG &lt;&gt; 5';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_bi_iesiri</obj_name>
  <obj_hashval>a4ec8e135641d8be7ec849da6c49bfe8</obj_hashval>
  <obj_text>SELECT xm.numepresc AS numedoc,
    i.codies::character varying AS coddoc,
    i.tipdoc,
    i.prefixdoc,
    dc.serie AS seriedoc,
    i.nrdoc::character varying AS nrdoc,
        CASE
            WHEN i.datadoc &gt;= to_date('1970'::text, 'yyyy'::text) AND i.datadoc &lt;= martor.add_months(CURRENT_DATE, 120) THEN i.datadoc
            ELSE NULL::timestamp without time zone
        END AS datadoc,
    m.simbol AS moneda,
    round(i.curs, 4) AS curs,
    p.den_part AS partener,
    p.codpart,
    p.dataadaugarii,
    p.codclasa AS codclasep,
    p.codintern AS codinternpart,
    date_trunc('day'::text, vc.vechime) AS vechimeclient,
    i1.codobiect::character varying AS codobiect,
        CASE
            WHEN COALESCE(ae1.cant, i1.cant) = 0::numeric THEN 0::numeric
            ELSE round(i1.cant * COALESCE(l1.cant, ae1.cant, i1.cant) / COALESCE(ae1.cant, i1.cant), 4)
        END AS cant,
    round(i1.pretorig *
        CASE
            WHEN (i.tipdoc &lt;&gt; ALL (ARRAY[16::numeric, 21::numeric])) OR COALESCE(i1.cant * i1.pu, 0::numeric) = 0::numeric THEN 1::numeric
            ELSE 1::numeric - COALESCE(i1.tva, 0::numeric) / (i1.cant * i1.pu)
        END, 4) AS pretorig,
    round(i1.pu -
        CASE
            WHEN (i.tipdoc &lt;&gt; ALL (ARRAY[16::numeric, 21::numeric])) OR COALESCE(i1.cant, 0::numeric) = 0::numeric THEN 0::numeric
            ELSE COALESCE(i1.tva, 0::numeric) / i1.cant
        END, 4) AS pu,
    round(
        CASE
            WHEN i.tipdoc = 16::numeric THEN i1.pu -
            CASE
                WHEN i1.cant = 0::numeric THEN 0::numeric
                ELSE COALESCE(i1.tva, 0::numeric) / i1.cant
            END
            ELSE ( SELECT pkg_list_base_iesiri_calcpies.wme_result
               FROM martor.pkg_list_base_iesiri_calcpies(NULL::numeric, i.codies, i.tipdoc, i1.cant, i1.pu, i1.tva, i1.addim, i1.coefdiscmaj, i1.valdiscpret, 0::numeric) pkg_list_base_iesiri_calcpies(wme_result, pcodies, ptipdoc, pcant, ppu, ptva, paddim, pcoefdiscmaj, pvaldiscpret, pincltva))
        END *
        CASE
            WHEN i.tipdoc &lt;&gt; 16::numeric THEN 1::numeric
            WHEN COALESCE(i1.pu * i1.cant, 0::numeric) = 0::numeric THEN 0::numeric
            WHEN COALESCE(i1.valdiscpret, 0::numeric) &lt;&gt; 0::numeric THEN 1::numeric + i1.valdiscpret / (i1.pu * i1.cant)
            ELSE martor.pkg_list_base_utils_getcoefdiscmonetar(i.codies, i1.tiplinie, i1.codobiect, i1.contserv, '-1'::integer::numeric, 1::numeric)
        END, 4) AS pretfinal,
        CASE
            WHEN COALESCE(ae1.cant, i1.cant) = 0::numeric THEN 0::numeric
            ELSE round(i1.tva * COALESCE(l1.cant, ae1.cant, i1.cant) / COALESCE(ae1.cant, i1.cant), 4)
        END AS tvalin,
    i1.indexlocal AS indexdoc,
    COALESCE(l1.codlivr1, 0::numeric)::character varying AS codlivr1,
    ae1.codies::character varying AS codae,
    ae1.codies1::character varying AS codae1,
    l1.nrlivr::character varying AS nrlivr,
        CASE
            WHEN l1.datalivr &gt;= to_date('1970'::text, 'yyyy'::text) AND l1.datalivr &lt;= martor.add_months(CURRENT_DATE, 120) THEN l1.datalivr
            ELSE NULL::date
        END AS datalivr,
    llivr.den_localit AS localitate,
    jlivr.den_judet AS judet,
    (ag.nume::text || ' '::text) || ag.prenume::text AS agent,
    round(
        CASE
            WHEN l1.pretachizorig IS NOT NULL THEN l1.pretachizorig
            WHEN ae.initializari = 1::numeric AND ae.custodie = 1::numeric THEN ae1.pucorelat
            ELSE 0::numeric
        END, 4) AS pretachizorig,
    round(
        CASE
            WHEN l1.pretachiz IS NOT NULL THEN l1.pretachiz
            WHEN ae.initializari = 1::numeric AND ae.custodie = 1::numeric THEN ae1.pucorelat
            ELSE 0::numeric
        END, 4) AS pretachiz,
    round(
        CASE
            WHEN l1.pretinreg IS NOT NULL THEN l1.pretinreg
            WHEN ae.initializari = 1::numeric AND ae.custodie = 1::numeric THEN ae1.pucorelat
            ELSE 0::numeric
        END, 4) AS pretinreg,
    l1.dataachiz,
    f.den_part AS furnizor,
    date_trunc('day'::text, vf.vechime::timestamp with time zone) AS vechimefurnizor,
    g.den_gest AS gestiune,
    loc.denumire AS locatie,
    nc.simbol AS cont,
    nc.den_cont,
    ioa.den_ioart AS tipcontabil,
    c1.termen AS termenlivr,
    CURRENT_DATE AS datasystem,
    ioa1.mg,
    i.an * 100::numeric + i.luna AS anluna,
    cref.curs AS curssitv
   FROM martor.iesiri1 i1
     JOIN martor.iesiri i ON i.codies = i1.codies
     LEFT JOIN martor.machete xm ON xm.codmacheta = i.tipdoc
     LEFT JOIN martor.nmonede m ON m.codmoneda = COALESCE(i.moneda, 0::numeric)
     LEFT JOIN martor.ieslink ilae ON ilae.codies1 = i1.codies1 AND i.tipdoc = 26::numeric AND ilae.codlinieaviz IS NOT NULL
     LEFT JOIN martor.iesiri1 ae1 ON ae1.codies1 = ilae.codlinieaviz
     LEFT JOIN martor.iesiri ae ON ae.codies = ae1.codies
     LEFT JOIN ( SELECT l1_1.codlivr1,
            l1_1.codlivr,
            l1_1.codies1,
            l1_1.cant,
            l.nrlivr,
            l.datalivr,
                CASE
                    WHEN ns.dataachiz &gt;= to_date('1970'::text, 'yyyy'::text) AND ns.dataachiz &lt;= martor.add_months(CURRENT_DATE, 120) THEN ns.dataachiz
                    ELSE NULL::date
                END AS dataachiz,
                CASE
                    WHEN nso.codnirstoc IS NOT NULL THEN COALESCE(nso.pret - nso.adaos, 0::numeric)
                    WHEN lv.codlivrval IS NOT NULL THEN COALESCE(lv.pretachiz, 0::numeric)
                    ELSE NULL::numeric
                END AS pretachizorig,
                CASE
                    WHEN ns.codnirstoc IS NOT NULL THEN COALESCE(ns.pret - ns.adaos, 0::numeric)
                    WHEN lv.codlivrval IS NOT NULL THEN COALESCE(lv.pretachiz, 0::numeric)
                    ELSE NULL::numeric
                END AS pretachiz,
                CASE
                    WHEN ns.codnirstoc IS NOT NULL THEN COALESCE(ns.pret, 0::numeric)
                    WHEN lv.codlivrval IS NOT NULL THEN COALESCE(lv.pretinreg, 0::numeric)
                    ELSE NULL::numeric
                END AS pretinreg,
            ns.furn,
            COALESCE(lv.gest, n.gest, 0::numeric) AS gest,
            ns.codlocatie,
            COALESCE(lv.codioart, ns.codioart, 0::numeric) AS codioart
           FROM martor.iesiri i_1
             JOIN martor.livr l ON l.codies = i_1.codies AND l.tiplivr = i_1.tipdoc
             JOIN martor.livr1 l1_1 ON l.codlivr = l1_1.codlivr
             LEFT JOIN martor.livrval lv ON lv.codlivr1 = l1_1.codlivr1
             LEFT JOIN martor.nirstoc ns ON ns.codnirstoc = l1_1.codnirstoc
             LEFT JOIN martor.nirstoc1 ns1 ON ns1.codnirstoc = l1_1.codnirstoc
             LEFT JOIN martor.nirstoc nso ON nso.codnirstoc = ns1.codnirstocorig
             LEFT JOIN martor.nir n ON n.codnir = ns.codnir
          WHERE COALESCE(i_1.operat, 0::numeric) = 1::numeric AND COALESCE(i_1.anulat, 0::numeric) = 0::numeric AND (i_1.tipdoc &lt;&gt; ALL (ARRAY[14::numeric, 15::numeric]))) l1 ON l1.codies1 = COALESCE(ae1.codies1, i1.codies1)
     LEFT JOIN martor.doccarnete dc ON dc.codcarnet = i.carnetdoc
     LEFT JOIN martor.num1 u1 ON u1.codum1 = i1.umsec
     LEFT JOIN martor.npart p ON p.codpart = i.partener
     LEFT JOIN martor.npart f ON f.codpart = l1.furn
     LEFT JOIN martor.ngest g ON g.codgest = l1.gest
     LEFT JOIN martor.nlocatii loc ON loc.codlocatie = l1.codlocatie
     LEFT JOIN martor.npers ag ON ag.codpers = i.agent
     LEFT JOIN martor.nagenda slivr ON slivr.codagenda = i.codlocatie
     LEFT JOIN martor.nlocalit llivr ON llivr.codlocalit = slivr.codlocalit
     LEFT JOIN martor.njudet jlivr ON jlivr.codjudet = llivr.codjudet
     LEFT JOIN martor.ioart ioa ON ioa.codioart = COALESCE(ae1.codioartcust, l1.codioart)
     LEFT JOIN martor.ioart1 ioa1 ON ioa1.codioart = ioa.codioart AND (i.an * 100::numeric + i.luna) &gt;= ioa1.alstart AND (i.an * 100::numeric + i.luna) &lt;= ioa1.alstop
     LEFT JOIN martor.ncont nc ON nc.codcont = COALESCE(ioa1.cont, i1.cont)
     LEFT JOIN martor.ieslink ilc ON ilc.codies1 = COALESCE(ae1.codies1, i1.codies1) AND ilc.codliniecomanda IS NOT NULL
     LEFT JOIN martor.comanda1 c1 ON c1.codcomanda1 = ilc.codliniecomanda
     LEFT JOIN ( SELECT iesiri.partener,
            min(iesiri.datadoc) AS vechime
           FROM martor.iesiri
          WHERE iesiri.partener IS NOT NULL AND iesiri.datadoc &gt;= to_date('1970'::text, 'yyyy'::text) AND iesiri.datadoc &lt;= martor.add_months(CURRENT_DATE, 120)
          GROUP BY iesiri.partener) vc ON vc.partener = i.partener
     LEFT JOIN ( SELECT nirstoc.furn,
            min(nirstoc.dataachiz) AS vechime
           FROM martor.nirstoc
          WHERE nirstoc.furn IS NOT NULL AND nirstoc.dataachiz &gt;= to_date('1970'::text, 'yyyy'::text) AND nirstoc.dataachiz &lt;= martor.add_months(CURRENT_DATE, 120)
          GROUP BY nirstoc.furn) vf ON vf.furn = l1.furn
     LEFT JOIN ( SELECT
                CASE
                    WHEN n1.data = min(n1.data) OVER (ORDER BY n1.data) THEN to_date('00010101'::text, 'YYYYMMDD'::text)
                    ELSE n1.data
                END AS datastart,
            COALESCE(lead(n1.data) OVER (ORDER BY n1.data) - 1, to_date('25001231'::text, 'YYYYMMDD'::text)) AS datastop,
            n1.valoare AS curs
           FROM ( SELECT COALESCE(max(
                        CASE
                            WHEN cl.simb = 'BANCASITV'::text THEN to_number(cv.valoare::text, '99999999999999999999'::text)
                            ELSE 0::numeric
                        END), 0::numeric) AS codbanca,
                    COALESCE(max(
                        CASE
                            WHEN cl.simb = 'MONEDASITV'::text THEN to_number(cv.valoare::text, '99999999999999999999'::text)
                            ELSE 0::numeric
                        END), 0::numeric) AS codmoneda
                   FROM ( SELECT upper(c1_1.simbol::text) AS simb,
                            cl_1.codconstluna,
                            row_number() OVER (PARTITION BY (upper(c1_1.simbol::text)) ORDER BY cl_1.anstart DESC, cl_1.lunastart DESC) AS idxconst
                           FROM martor.const1 c1_1
                             JOIN martor.categconst ct ON ct.codcateg = c1_1.codcateg
                             JOIN martor.constluna cl_1 ON cl_1.codconst1 = c1_1.codconst1
                          WHERE (upper(c1_1.simbol::text) = ANY (ARRAY['BANCASITV'::text, 'MONEDASITV'::text])) AND cl_1.userid = 0::numeric) cl
                     LEFT JOIN martor.constval cv ON cv.codconstluna = cl.codconstluna
                  WHERE cl.idxconst = 1) tmp
             JOIN martor.nmonede1 n1 ON n1.codbanca = tmp.codbanca AND n1.codmoneda = tmp.codmoneda) cref ON cref.datastart &lt;= i.datadoc AND cref.datastop &gt;= i.datadoc
  WHERE COALESCE(i.operat, 0::numeric) = 1::numeric AND COALESCE(i.anulat, 0::numeric) = 0::numeric AND (i1.tiplinie::text = ANY (ARRAY['='::character varying::text, 'S'::character varying::text, 'V'::character varying::text])) AND (i.tipdoc &lt;&gt; ALL (ARRAY[14::numeric, 15::numeric]));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_bi_intrari</obj_name>
  <obj_hashval>2f6051d97d94808898dea37e2e326447</obj_hashval>
  <obj_text>SELECT xm.numepresc AS numedoc,
    i.codintr::character varying AS coddoc,
    i.tipdoc,
    i.prefixdoc,
    dc.serie AS seriedoc,
    i.nrdoc::character varying AS nrdoc,
        CASE
            WHEN i.datadoc &gt;= to_date('1970'::text, 'yyyy'::text) AND i.datadoc &lt;= martor.add_months(CURRENT_DATE, 120) THEN i.datadoc
            ELSE NULL::date
        END AS datadoc,
    m.simbol AS moneda,
    round(i.curs, 4) AS curs,
    p.den_part AS partener,
    date_trunc('day'::text, vc.vechime::timestamp with time zone) AS vechimefurn,
    i1.codobiect::character varying AS codobiect,
    round(COALESCE(- l1.cant, ns.cantnir, i1.cant), 4) AS cant,
    round(i1.pretorig, 4) AS pretorig,
    round(i1.pu, 4) AS pu,
    round(i1.pretorig * COALESCE(NULLIF(i1.coefdiscmaj, 0::numeric), 1::numeric), 4) AS pretfinal,
    round(
        CASE
            WHEN COALESCE(i1.cant, 0::numeric) = 0::numeric THEN 0::numeric
            ELSE i1.tva * COALESCE(- l1.cant, ns.cantnir, i1.cant) / i1.cant
        END, 4) AS tvalin,
    i1.indexlocal AS indexdoc,
    COALESCE(ns.codnirstoc, 0::numeric)::character varying AS codnirstoc,
    ae1.codintr::character varying AS codae,
    ae1.codintr1::character varying AS codae1,
    n.nrnir::character varying AS nrrecept,
        CASE
            WHEN n.datanir &gt;= to_date('1970'::text, 'yyyy'::text) AND n.datanir &lt;= martor.add_months(CURRENT_DATE, 120) THEN n.datanir
            ELSE NULL::date
        END AS datarecept,
    llivr.den_localit AS localitate,
    jlivr.den_judet AS judet,
    (ag.nume::text || ' '::text) || ag.prenume::text AS agent,
    round(
        CASE
            WHEN ns.codnirstoc IS NOT NULL THEN ns.pret - ns.adaos
            WHEN lv.codlivrval IS NOT NULL THEN lv.pretachiz
            ELSE i1.pretorig * COALESCE(NULLIF(i1.coefdiscmaj, 0::numeric), 1::numeric)
        END, 4) AS pretachiz,
    round(
        CASE
            WHEN ns.codnirstoc IS NOT NULL THEN ns.pret
            WHEN lv.codlivrval IS NOT NULL THEN lv.pretinreg
            ELSE i1.pretorig * COALESCE(NULLIF(i1.coefdiscmaj, 0::numeric), 1::numeric)
        END, 4) AS pretinreg,
        CASE
            WHEN ns.dataachiz &gt;= to_date('1970'::text, 'yyyy'::text) AND ns.dataachiz &lt;= martor.add_months(CURRENT_DATE, 120) THEN ns.dataachiz
            ELSE NULL::date
        END AS dataachiz,
    g.den_gest AS gestiune,
    loc.denumire AS locatie,
    nc.simbol AS cont,
    nc.den_cont,
    ioa.den_ioart AS tipcontabil,
    c1.termen AS termenlivr,
    CURRENT_DATE AS datasystem,
    ioa1.mg,
    i.an * 100::numeric + i.luna AS anluna
   FROM martor.intrari i
     JOIN martor.intrari1 i1 ON i1.codintr = i.codintr
     LEFT JOIN martor.machete xm ON xm.codmacheta = i.tipdoc
     LEFT JOIN martor.nmonede m ON m.codmoneda = COALESCE(i.moneda, 0::numeric)
     LEFT JOIN martor.intrlink ilae ON ilae.codintr1 = i1.codintr1 AND i.tipdoc = 9::numeric AND ilae.codlinieaviz IS NOT NULL
     LEFT JOIN martor.intrari1 ae1 ON ae1.codintr1 = ilae.codlinieaviz
     LEFT JOIN martor.intrari ae ON ae.codintr = ae1.codintr
     LEFT JOIN martor.dvi ON dvi.codintr = i.codintr
     LEFT JOIN martor.dvi1 ON dvi1.coddvi = dvi.coddvi AND dvi1.codintr1 = i1.codintr1
     LEFT JOIN martor.livr1 l1 ON l1.codintr1 = i1.codintr1
     LEFT JOIN martor.livrval lv ON lv.codlivr1 = l1.codlivr1
     LEFT JOIN martor.nirstoc ns ON ns.codobiect = i1.codobiect AND (l1.codlivr1 IS NOT NULL AND ns.codnirstoc = l1.codnirstoc OR l1.codlivr1 IS NULL AND (ns.codintr1 = COALESCE(ae1.codintr1, i1.codintr1) OR ns.coddvi1 = dvi1.coddvi1))
     LEFT JOIN martor.nir n ON n.codintr = COALESCE(ae.codintr, i.codintr) AND n.codnir = ns.codnir
     LEFT JOIN martor.doccarnete dc ON dc.codcarnet = i.carnetdoc
     LEFT JOIN martor.num1 u1 ON u1.codum1 = i1.umsec
     LEFT JOIN martor.npart p ON p.codpart = i.partener
     LEFT JOIN martor.ngest g ON g.codgest = COALESCE(n.gest, lv.gest)
     LEFT JOIN martor.nlocatii loc ON loc.codlocatie = ns.codlocatie
     LEFT JOIN martor.npers ag ON ag.codpers = i.agent
     LEFT JOIN martor.nagenda slivr ON slivr.codagenda = i.codlocatie
     LEFT JOIN martor.nlocalit llivr ON llivr.codlocalit = slivr.codlocalit
     LEFT JOIN martor.njudet jlivr ON jlivr.codjudet = llivr.codjudet
     LEFT JOIN martor.ioart ioa ON ioa.codioart = COALESCE(lv.codioart, ns.codioart)
     LEFT JOIN ( SELECT x.codioart,
            x.codioart1,
                CASE
                    WHEN (x.anstart * 12::numeric + x.lunastart) = (fl.aninitial * 12::numeric + fl.lunainitiala) THEN 0::numeric
                    ELSE x.anstart * 12::numeric + x.lunastart
                END AS alstart,
            COALESCE(lead(x.anstart * 12::numeric + x.lunastart) OVER (PARTITION BY x.codioart ORDER BY (x.anstart * 12::numeric + x.lunastart)) - 1::numeric, fl.anmaxim * 12::numeric + fl.lunamaxima) AS alstop
           FROM martor.ioart1 x
             CROSS JOIN martor.firmaluni fl) iox ON iox.codioart = ioa.codioart AND (i.an * 12::numeric + i.luna) &gt;= iox.alstart AND (i.an * 12::numeric + i.luna) &lt;= iox.alstop
     LEFT JOIN martor.ioart1 ioa1 ON ioa1.codioart1 = iox.codioart1
     LEFT JOIN martor.ncont nc ON nc.codcont = ioa1.cont
     LEFT JOIN martor.intrlink ilc ON ilc.codintr1 = COALESCE(ae1.codintr1, i1.codintr1) AND ilae.codliniecomanda IS NOT NULL
     LEFT JOIN martor.comanda1 c1 ON c1.codcomanda1 = ilc.codliniecomanda
     LEFT JOIN ( SELECT intrari.partener,
            min(intrari.datadoc) AS vechime
           FROM martor.intrari
          WHERE intrari.partener IS NOT NULL AND intrari.datadoc &gt;= to_date('1970'::text, 'YYYY'::text) AND intrari.datadoc &lt;= martor.add_months(CURRENT_DATE, 120)
          GROUP BY intrari.partener) vc ON vc.partener = i.partener
  WHERE COALESCE(i.operat, 0::numeric) = 1::numeric AND COALESCE(i.anulat, 0::numeric) = 0::numeric AND (i1.tiplinie::text = ANY (ARRAY['='::character varying::text, 'S'::character varying::text, 'V'::character varying::text]));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_bugetemf</obj_name>
  <obj_hashval>11d18a973886b8226f24cb361994d972</obj_hashval>
  <obj_text>SELECT codbugetmf,
    codmifix,
    userid,
    subunitatea,
    datacreare
   FROM martor.bugetmf
  WHERE codbugetmf = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_cantar</obj_name>
  <obj_hashval>489055e4c4e5c499011ccf4ce8c6d3b3</obj_hashval>
  <obj_text>SELECT codcantar,
    codobiect,
    an,
    luna,
    subunitate,
    nraviz
   FROM martor.cantar
  WHERE codcantar = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_voucher</obj_name>
  <obj_hashval>ea4cfc3402047a8be7b2a3fd928469e7</obj_hashval>
  <obj_text>SELECT codvoucher AS coddoc,
    obs,
    datastart,
    datastop,
    valoare
   FROM martor.voucher
  WHERE codvoucher = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_nartobj_test</obj_name>
  <obj_hashval>31fdd353baf65753061c2b14ddd8f395</obj_hashval>
  <obj_text>SELECT codarticol,
    codobiect,
    den_articol,
    um,
    clasa,
    tipserie,
    tiparticol,
    aretg,
    contimplicit,
    producator,
    gestimplicita,
    certificat,
    evolutiepret,
    contserviciu,
    um1,
    um2,
    codexternart,
    sufixcodextern,
    culoare,
    codvamal,
    codextern,
    codintern,
    umambalare,
    stocmin,
    stocmax,
    termenplata,
    procadaosnir,
    promotie,
    blocat,
    rotunjire,
    nefacturabil,
    cantaribil,
    codtva,
    codaccize,
    codaccizedvi,
    codtaxa1,
    codtaxa2,
    tippretmax,
    pumaxluna,
    proctva,
    COALESCE(string_agg(denobiect::text, ' '::text ORDER BY indexlocal), '... fara atribute ...'::text) AS denobiect,
    produspropriu,
    inactiv,
    faracmdfurn,
    relatieum1,
    d1,
    d2,
    d3,
    dci,
    denlocatie,
    denumiretrad,
    den_ioart,
    den_gest,
    min(codatrobj) AS codatrobj,
    farastoc
   FROM ( SELECT a.codarticol,
            o.codobiect,
            a.den_articol,
            a.um,
            a.clasa,
            a.tipserie,
            a.tiparticol,
            a.aretg,
            ai.contimplicit,
            p.den_part AS producator,
            ai.gestimplicita,
            a.certificat,
            a.evolutiepret,
            a.contserviciu,
            a.um1,
            a.um2,
            a.codexternart,
            a.sufixcodextern,
            a.culoare,
            o.codvamal,
            o.codextern,
            o.codintern,
            o.umambalare,
            o.stocmin,
            o.stocmax,
            o.termenplata,
            o.procadaosnir,
            o.promotie,
            o.blocat,
            o.rotvaluta AS rotunjire,
            o.nefacturabil,
            u.tipum AS cantaribil,
            nart1luna.codtva,
            nart1luna.codaccize,
            nart1luna.codaccizedvi,
            nart1luna.codtaxa1,
            nart1luna.codtaxa2,
            nartobj1luna.tippretmax,
            nartobj1luna.pretmaximal AS pumaxluna,
            COALESCE(tvaluna.procent, '-1'::integer::numeric) AS proctva,
            COALESCE(b.valoare, '... fara atribute ...'::character varying) AS denobiect,
            o.produspropriu,
            o.inactiv,
            o.faracmdfurn,
            a.relatieum1,
            a.d1,
            a.d2,
            a.d3,
            a.dci,
            loc.denumire AS denlocatie,
            trad.denumiretrad,
            ioa.den_ioart,
            gi.den_gest,
            COALESCE(t.codobiect, 0::numeric) AS codatrobj,
            COALESCE(t.indexlocal, 0::numeric) AS indexlocal,
            COALESCE(o.farastoc, 0::numeric) AS farastoc
           FROM martor.nartobj o
             JOIN martor.nart a ON o.codarticol = a.codarticol
             JOIN martor.num u ON u.codum = a.um
             LEFT JOIN martor.nartimplicite ai ON ai.codarticol = a.codarticol AND ai.codsubunit = (( SELECT pkg_globals_getsubunitate_doc.wme_result
                   FROM martor.pkg_globals_getsubunitate_doc(NULL::numeric, NULL::numeric) pkg_globals_getsubunitate_doc(wme_result, fakeparam)))
             LEFT JOIN martor.nlocatii loc ON ai.locatieimplicita = loc.codlocatie
             LEFT JOIN martor.npart p ON p.codpart = o.codproducator
             LEFT JOIN martor.natrobj t ON t.codobiect = o.codobiect
             LEFT JOIN martor.natrib1 b ON t.codvalatr = b.codvalatr
             LEFT JOIN martor.nartobjtrad trad ON trad.codobiect = o.codobiect AND trad.codlimba = (( SELECT pkg_globals_getlimbadenart.wme_result
                   FROM martor.pkg_globals_getlimbadenart(NULL::numeric, NULL::numeric) pkg_globals_getlimbadenart(wme_result, fakeparam)))
             LEFT JOIN martor.ioart ioa ON ai.contimplicit = ioa.codioart
             LEFT JOIN martor.ngest gi ON gi.codgest = ai.gestimplicita
             LEFT JOIN ( SELECT a1.codarticol,
                    a1.codtva,
                    a1.codaccize,
                    a1.codtaxa1,
                    a1.codtaxa2,
                    a1.codaccizedvi
                   FROM martor.nart1 a1
                  WHERE (a1.anstart * 12::numeric + a1.lunastart) = (( SELECT max(a11.anstart * 12::numeric + a11.lunastart) AS max
                           FROM martor.nart1 a11
                          WHERE a11.codarticol = a1.codarticol AND (a11.anstart * 12::numeric + a11.lunastart) &lt;= ((( SELECT pkg_globals_getanlucru.wme_result
                                   FROM martor.pkg_globals_getanlucru(NULL::numeric, NULL::numeric) pkg_globals_getanlucru(wme_result, fakeparam))) * 12::numeric + (( SELECT pkg_globals_getlunalucru.wme_result
                                   FROM martor.pkg_globals_getlunalucru(NULL::numeric, NULL::numeric) pkg_globals_getlunalucru(wme_result, fakeparam))))))) nart1luna ON nart1luna.codarticol = o.codarticol
             LEFT JOIN ( SELECT n.codtva,
                    n1.codtva1,
                    n.den_tva,
                    n1.procent,
                    n1.codcontded,
                    n1.codcontcole,
                    n1.codcontneex
                   FROM martor.ntva n
                     LEFT JOIN martor.ntva1 n1 ON n.codtva = n1.codtva
                  WHERE (n1.anstart * 12::numeric + n1.lunastart) = (( SELECT max(nt1.anstart * 12::numeric + nt1.lunastart) AS max
                           FROM martor.ntva1 nt1
                          WHERE nt1.codtva = n1.codtva AND (nt1.anstart * 12::numeric + nt1.lunastart) &lt;= (( SELECT pkg_globals_anlunalucru.wme_result
                                   FROM martor.pkg_globals_anlunalucru(NULL::numeric, NULL::numeric) pkg_globals_anlunalucru(wme_result, fakeparam)))))) tvaluna ON tvaluna.codtva = nart1luna.codtva
             LEFT JOIN ( SELECT o1.codobiect,
                    o1.tippretmax,
                    o1.pretmaximal
                   FROM martor.nartobj1 o1
                  WHERE (o1.anstart * 12::numeric + o1.lunastart) = (( SELECT max(o11.anstart * 12::numeric + o11.lunastart) AS max
                           FROM martor.nartobj1 o11
                          WHERE o11.codobiect = o1.codobiect AND (o11.anstart * 12::numeric + o11.lunastart) &lt;= ((( SELECT pkg_globals_getanlucru.wme_result
                                   FROM martor.pkg_globals_getanlucru(NULL::numeric, NULL::numeric) pkg_globals_getanlucru(wme_result, fakeparam))) * 12::numeric + (( SELECT pkg_globals_getlunalucru.wme_result
                                   FROM martor.pkg_globals_getlunalucru(NULL::numeric, NULL::numeric) pkg_globals_getlunalucru(wme_result, fakeparam))))))) nartobj1luna ON nartobj1luna.codobiect = o.codobiect
          WHERE o.codarticol = (( SELECT pkg_selectarticole_getcodartcurent.wme_result
                   FROM martor.pkg_selectarticole_getcodartcurent(NULL::numeric, NULL::numeric) pkg_selectarticole_getcodartcurent(wme_result, fakeparam)))
          ORDER BY (COALESCE(t.indexlocal, 0::numeric))) a_pg
  GROUP BY codarticol, codobiect, den_articol, um, clasa, tipserie, tiparticol, aretg, contimplicit, producator, gestimplicita, certificat, evolutiepret, contserviciu, um1, um2, codexternart, sufixcodextern, codvamal, codextern, codintern, umambalare, stocmin, stocmax, termenplata, procadaosnir, promotie, blocat, rotunjire, nefacturabil, cantaribil, codtva, codaccize, codaccizedvi, codtaxa1, codtaxa2, tippretmax, pumaxluna, proctva, produspropriu, inactiv, faracmdfurn, relatieum1, d1, d2, d3, dci, denlocatie, denumiretrad, den_ioart, den_gest, culoare, farastoc;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_nclasegest</obj_name>
  <obj_hashval>fd466d038f2cc20265f778c2b17a7377</obj_hashval>
  <obj_text>WITH RECURSIVE fg_tree AS (
         SELECT nclaseg_1.codclaseg,
            nclaseg_1.codclaseg AS codparinte
           FROM martor.nclaseg nclaseg_1
          WHERE nclaseg_1.codclaseg = 0::numeric
        UNION ALL
         SELECT c.codclaseg,
            p.codparinte
           FROM martor.nclaseg c
             JOIN fg_tree p ON p.codclaseg = c.codparinte
        )
 SELECT codclaseg,
    den_claseg,
    simbol,
    nivel,
    nranalitice,
    codparinte
   FROM martor.nclaseg;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_proc_act_def</obj_name>
  <obj_hashval>8c13ccc36984835e4b8f69b0331646df</obj_hashval>
  <obj_text>SELECT codprocactdef,
    denumire,
    codintern,
    sql
   FROM martor.proc_act_def;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_sitfin1</obj_name>
  <obj_hashval>b3b33416130f3873d4667064c4b3ca1e</obj_hashval>
  <obj_text>SELECT codsitfin,
    codf,
    denumire,
    sectiune,
    (codf::text || ' - '::text) || denumire::text AS codden
   FROM martor.sitfin
  WHERE COALESCE(tip, 0::numeric) = 1::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpers_nc_debit</obj_name>
  <obj_hashval>15a9acda9445eff24f7019c4ba9c8c3a</obj_hashval>
  <obj_text>SELECT nc1.agent AS codpers,
    nc1.icontd AS icont,
    nc.moneda AS codmoneda,
    sum(
        CASE
            WHEN nc.moneda = 0::numeric THEN nc1.valoare
            WHEN nc.moneda &lt;&gt; 0::numeric THEN nc1.valoare * nc.curs
            ELSE NULL::numeric
        END) AS soldlei,
    sum(nc1.valoare) AS soldvaluta
   FROM martor.nc1,
    martor.nc
  WHERE nc.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND nc.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric AND nc.codnc = nc1.codnc AND COALESCE(nc1.agent, 0::numeric) &lt;&gt; 0::numeric AND COALESCE(nc1.icontd, 0::numeric) &lt;&gt; 0::numeric AND COALESCE(nc1.persd, 0::numeric) &lt;&gt; 0::numeric
  GROUP BY nc1.agent, nc1.icontd, nc.moneda;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_voucher</obj_name>
  <obj_hashval>3748f2615153de814f6b936a04fc1c92</obj_hashval>
  <obj_text>SELECT v.codvoucher,
    p.codpart,
    p.den_part AS part,
    v.obs,
    v.datastart,
    v.datastop,
    m.codmoneda,
    m.simbol AS smoneda,
    v.valoare,
    v.valoare - COALESCE(x.folosit, 0::numeric) AS rest,
    v.codcmd,
    v.codies
   FROM martor.voucher v
     JOIN martor.npart p ON p.codpart = COALESCE(v.codpartener, 0::numeric)
     JOIN martor.nmonede m ON m.codmoneda = COALESCE(v.moneda, 0::numeric)
     LEFT JOIN ( SELECT voucherlink.codvoucher,
            sum(voucherlink.valoare) AS folosit
           FROM martor.voucherlink
          GROUP BY voucherlink.codvoucher) x ON x.codvoucher = v.codvoucher;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_setan_initializari</obj_name>
  <obj_hashval>d6d0c0e862ddbcf03f7dfb303891448c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_setan_initializari(aan_initializari numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_RUPERE_FIRMA.AN_INITIALIZARI',to_char(aAN_INITIALIZARI,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t19</obj_name>
  <obj_hashval>46083a17c0e490df0e9885f2b32e27a3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t19()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
    vTipAvizCustodie NUMERIC;
    sFirmaID         VARCHAR(35);
    vSubunit         NUMERIC(20);
    vALFin           NUMERIC(5);
BEGIN
  --Florin 11.12.2025 - fixat 67555
  --Florin 17.11.2025 - sinc. Oracle
  --Florin 23.11.2023 - fixat 60132
  PERFORM pkg_saft_PUT_INFO('19.A','UMPLE_T19--SAF_PHYSICALSTOCKENTRY');
  BEGIN
    SELECT fnc_GetValConstanta('TipAvizCustodie', ANFIN,LUNAFIN)::NUMERIC INTO vTipAvizCustodie FROM TMP_SAFT_PARAMS;
  EXCEPTION WHEN OTHERS THEN
    vTipAvizCustodie := -1;
  END;

  SELECT CODSUBUNIT INTO vSubunit
  FROM TMP_SAFT_PARAMS;

  IF vSubunit = 1 THEN
    SELECT '00'||REGEXP_REPLACE(F.CODFISCAL,'\D+','') INTO sFirmaID
    FROM TMP_SAFT_PARAMS SP INNER JOIN WINMADMIN.FIRMA F ON F.CODFIRMA = SP.CODFIRMA;
  ELSE
    SELECT '00'||REGEXP_REPLACE(S.CIF,'\D+','') INTO sFirmaID
    FROM TMP_SAFT_PARAMS SP INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = SP.CODSUBUNIT;
  END IF;

   INSERT INTO TMP_SAFT19
  SELECT
    nextval('SEQ_SAFT')      COL01,--CODSAF_PHYSICALSTOCKENTRY    NUMBER(20)
    T.COL02                  COL02,--WAREHOUSEID                  NVARCHAR2(35)
    NULL                     COL03,--LOCATIONID                   NVARCHAR2(18)
    To_Char(T.CODOBIECT)     COL04,--PRODUCTCODE                  NVARCHAR2(70)
    NULL                     COL05,--STOCKACCOUNTNO               NVARCHAR2(70)
    T.COL06                  COL06,--PRODUCTTYPE                  NVARCHAR2(18)
    NULL                     COL07,--PRODUCTSTATUS                NVARCHAR2(18)
    T.COL08                  COL08,--STOCKACCOUNTCOMMODITYCODE    NVARCHAR2(35)
    T.COL09                  COL09,--OWNERID                      NVARCHAR2(35)
    T.COL10                  COL10,--UOMPHYSICALSTOCK             NVARCHAR2(9)
    T.COL11                  COL11,--UOMTOUOMBASECONVERSIONFACTOR NUMBER(22,7)
    T.COL12                  COL12,--UNITPRICE                    NUMBER(18,2)
    T.COL13                  COL13,--OPENINGSTOCKQUANTITY         NUMBER(22,6)
    T.COL14                  COL14,--OPENINGSTOCKVALUE            NUMBER(18,2)
    T.COL15                  COL15,--CLOSINGSTOCKQUANTITY         NUMBER(22,6)
    T.COL16                  COL16,--CLOSINGSTOCKVALUE            NUMBER(18,2)
    Coalesce(C20.CODSAF, 20) COL17 --CODSAF_STOCKCHARACTERISTICS  NUMBER(20)
  FROM (
    SELECT
      COL02, CODOBIECT, COL06, COL08, COL09, COL10, COL11, COL12,
      Sum(Coalesce(COL13, 0)) AS COL13, Sum(Coalesce(COL14, 0)) AS COL14, Sum(COL15) AS COL15, Sum(COL16) AS COL16
    FROM (
      SELECT
        SubStr(Coalesce(G.SIMBOL, G.DEN_GEST), 1, 35) AS COL02,
        NS.CODOBIECT,
        Substr(C.SIMBOL,1,18) AS COL06, --To_Char(NS.CODIOART) AS COL06,
        Coalesce(NULLIF(SubStr(Trim(O.CODVAMAL),1,18), ''), '0') AS COL08,
        Coalesce(NULLIF(Trim(F.PartID), ''), sFirmaID) AS COL09,
        SubStr(UMS.CODSAFT, 1, 9) AS COL10, Coalesce(UM.PARITATEUMSAFT, 1) AS COL11,
        Coalesce(NS.PRET, 0) - Coalesce(NS.ADAOS, 0) AS COL12,
        NLP.REST AS COL13, NLP.REST * (Coalesce(NS.PRET, 0) - Coalesce(NS.ADAOS, 0)) AS COL14,
        NLF.REST AS COL15, NLF.REST * (Coalesce(NS.PRET, 0) - Coalesce(NS.ADAOS, 0)) AS COL16
      FROM TMP_SAFT_PARAMS SP
        INNER JOIN NIRLUNA           NLF  ON NLF.AN = SP.ANFIN AND NLF.LUNA = SP.LUNAFIN
        LEFT  JOIN NIRLUNA           NLP  ON NLP.AN = SP.ANP   AND NLP.LUNA = SP.LUNAP AND NLP.CODNIRSTOC = NLF.CODNIRSTOC
        LEFT  JOIN NIRSTOC           NS   ON NS.CODNIRSTOC = NLF.CODNIRSTOC
        LEFT  JOIN NIR               N    ON N.CODNIR      = NS.CODNIR
        LEFT  JOIN NGEST             G    ON G.CODGEST     = N.GEST
        LEFT  JOIN TMP_SAFT_NPARTFUZ FF   ON FF.CODPART    = CASE WHEN NS.CODIOART = vTipAvizCustodie THEN NS.FURN ELSE NULL END
        LEFT  JOIN TMP_SAFT_NPARTDET F    ON F.CODPART     = FF.CODPARTFUZ
        LEFT  JOIN NUM1              UM1  ON UM1.CODUM1    = NS.UMSEC
        LEFT  JOIN NUM               UM   ON UM.CODUM      = UM1.CODUM
        LEFT  JOIN NARTOBJ           O    ON O.CODOBIECT   = NS.CODOBIECT
        LEFT  JOIN IOART1            IOA1 ON IOA1.CODIOART = NS.CODIOART AND SP.ANFIN*12+SP.LUNAFIN BETWEEN IOA1.ALSTART AND IOA1.ALSTOP
        LEFT  JOIN NCONT             C    ON C.CODCONT     = IOA1.CONT
        LEFT  JOIN (
          SELECT DISTINCT CODUNIC FROM TMP_SAFT_MANEVRA WHERE FILTRU IN ('CObInventar', 'CMifix') AND AL = vALFin
        )                            MAN  ON MAN.CODUNIC   = IOA1.CONT
        LEFT  JOIN WINMADMIN.NUMSAFT UMS  ON UMS.CODUMSAFT = UM.CODUMSAFT
      WHERE MAN.CODUNIC IS NULL
        AND CASE
              WHEN Coalesce(NLF.REST, 0) &lt;&gt; 0 THEN 1
              WHEN Coalesce(NLP.REST, 0) &lt;&gt; 0 THEN 1
              WHEN NLP.CODNIRSTOC IS NULL     THEN 1 -- pozitie creata in perioada
              WHEN
                EXISTS (
                  SELECT 1
                  FROM LIVR1 L1
                    INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
                    LEFT  JOIN IESIRI  IES   ON IES.CODIES      = L.CODIES
                    LEFT  JOIN INTRARI INTR  ON INTR.CODINTR    = L.CODINTR
                    LEFT  JOIN TRANSF  TRANF ON TRANF.CODTRANSF = L.CODTRANSF
                  WHERE L1.CODNIRSTOC = NLF.CODNIRSTOC
                    AND Coalesce(IES.AN*12+IES.LUNA, INTR.AN*12+INTR.LUNA, TRANF.AN*12+TRANF.LUNA, 0) BETWEEN SP.ANINI*12+SP.LUNAINI AND SP.ANFIN*12+SP.LUNAFIN
                )                             THEN 1
              ELSE 0
            END = 1
      UNION ALL
      SELECT
        WAREHOUSEID AS COL02,
        CODOBIECT,
        PRODUCTTYPE AS COL06,
        Coalesce(NULLIF(Trim(STOCKACCOUNTCOMMODITYCODE), ''), '0') AS COL08,
        Coalesce(NULLIF(Trim(OWNERID), ''), sFirmaID) AS COL09,
        UOMPHYSICALSTOCK AS COL10, CAST(UOMTOUOMBASECONVERSIONFACTOR AS NUMERIC(20,7)) AS COL11,
        UNITPRICE AS COL12,
        OPENINGSTOCKQUANTITY AS COL13, OPENINGSTOCKVALUE AS COL14,
        CLOSINGSTOCKQUANTITY AS COL15, CLOSINGSTOCKVALUE AS COL16
      FROM TMP_SAFT_PARAMS SP INNER JOIN STOCFAKE SF ON SF.AN = SP.ANFIN AND SF.LUNA = SP.LUNAFIN
    ) A_PG
    GROUP BY COL02, CODOBIECT, COL06, COL08, COL09, COL10, COL11, COL12
  ) T LEFT JOIN TMP_SAFT_CODSAF C20 ON C20.CODSURSA = T.CODOBIECT AND CODSAFTTAB = 20;

  PERFORM pkg_saft_PUT_INFO('19.Z','UMPLE_T19--SAF_PHYSICALSTOCKENTRY');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_soldinitial_sp_gotorecord</obj_name>
  <obj_hashval>acee04098f9c7246336bea720755caf4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_soldinitial_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC              RECORD;
  V_REC_AVANSURI     RECORD;
  VREC_TREZOR1_CEC   RECORD;
  aCODPART           numeric := 0;
  aCODGENERAL_AVANS  numeric := 0;
  aCODOBLIGPIF_AVANS numeric := 0;
  aCODIOPART         numeric := 0;
BEGIN
  --Florin 29.06.2022 - fnc_getprocenttvaart
  --Bogdan 28.04.2022 - 52858 - Initializare solduri parteneri: observatii
  --Florin 07.02.2022 - fixat 52963
  --Florin 05.01.2022 - sinc. Oracle (29.12.2021)
  --Florin 10.12.2021 - fixat 52269
  --Bogdan 15.12.2020
  INSERT INTO TMP_SOLDINI (CODSOLDINI, CODPART)
  SELECT CODSOLDINI, CODPART FROM SOLDINI WHERE CODSOLDINI = RECID;

  perform set_config ('PKG_SOLDINITIAL.OLDCODPART',0::varchar,false);

  IF RECID &gt; 0 THEN
    SELECT COALESCE (CODPART, 0) INTO aCODPART FROM TMP_SOLDINI;

    perform set_config ('PKG_SOLDINITIAL.OLDCODPART',aCODPART::varchar,false);

    UPDATE TMP_SOLDINI
    SET
      (VOLUMTRANZC, VOLUMTRANZF)
      =
      (SELECT VOLUMTRANZC, VOLUMTRANZF FROM NPART1
       WHERE
          CODPART       = aCODPART
          AND ANSTART   = current_setting ('PKG_GLOBALS.ANINITIAL'  , true) ::numeric
          AND LUNASTART = current_setting ('PKG_GLOBALS.LUNAINITIALA', true) ::NUMERIC
      );
  END IF;

  DELETE FROM TMP_GENERAL;
  DELETE FROM TMP_GENERAL_LITIGII;

  INSERT INTO TMP_GENERAL_LITIGII (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT G.CODGENERAL, G.TIPDOC, G.CODDOC, G.MONEDA, G.CURS, G.TVA, G.SEMNIFICATIE
  FROM GENERAL G, COMPENS C
  WHERE
    G.TIPDOC IN (28)
    AND C.CODCOMPENS = G.CODDOC
    AND C.PARTD = aCODPART
    AND C.PARTC = aCODPART
    AND C.AN * 12 + C.LUNA &lt; current_setting ('PKG_GLOBALS.ANINITIAL', true) ::numeric * 12 + current_setting ('PKG_GLOBALS.LUNAINITIALA', true) ::numeric
    AND G.SEMNIFICATIE = 1350;

  INSERT INTO TMP_OBLIGVAMA_INITIAL (CODOBLIGPIF, CODGENERAL, VALOARE, CODPART, ICONT, SEMNIFICATIE)
  SELECT CODOBLIGPIF, CODGENERAL, VALOARE, CODPART, ICONT, SEMNIFICATIE
  FROM OBLIGPIF O
  WHERE EXISTS (SELECT CODGENERAL FROM TMP_GENERAL_LITIGII WHERE CODGENERAL = O.CODGENERAL);

  INSERT INTO TMP_STINGERE_ASOCIAT (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
  SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE
  FROM STINGERE S
  WHERE EXISTS (SELECT CODOBLIGPIF FROM TMP_OBLIGVAMA_INITIAL WHERE CODOBLIGPIF = S.CODSTINGATORPIF);

  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
  FROM GENERAL G, COMPENS C
  WHERE
    SEMNIFICATIE IN (1301, 1303)
    AND TIPDOC   IN (28)
    AND C.CODCOMPENS = G.CODDOC
    AND C.PARTD = aCODPART
    AND C.PARTC = aCODPART
    AND C.AN * 12 + C.LUNA &lt; current_setting ('PKG_GLOBALS.ANINITIAL', true) ::numeric * 12 + current_setting ('PKG_GLOBALS.LUNAINITIALA', true) ::numeric;

  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, FARAREG)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, FARAREG
  FROM GENERAL G
  WHERE
    ( (TIPDOC IN (1, 2, 3, 4, 9)) OR (TIPDOC = 5 AND SEMNIFICATIE &lt;&gt; 130) )
    AND (SELECT PARTENER FROM INTRARI I WHERE CODINTR = G.CODDOC) = aCODPART
    AND (SELECT I.AN * 12 + I.LUNA FROM INTRARI I WHERE CODINTR = G.CODDOC) &lt; current_setting ('PKG_GLOBALS.ANINITIAL', true) ::numeric * 12 + current_setting ('PKG_GLOBALS.LUNAINITIALA', true) ::numeric;

  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, FARAREG)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, FARAREG
  FROM GENERAL G
  WHERE
    TIPDOC = 5
    AND SEMNIFICATIE = 130
    AND (SELECT CODVAMA FROM DVI D WHERE CODDVI = G.CODDOC) = aCODPART
    AND (SELECT I.AN * 12 + I.LUNA FROM INTRARI I, DVI D WHERE CODDVI = G.CODDOC AND D.CODINTR = I.CODINTR)
         &lt; current_setting ('PKG_GLOBALS.ANINITIAL', true) ::numeric * 12 + current_setting ('PKG_GLOBALS.LUNAINITIALA', true) ::numeric;

  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, FARAREG)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, FARAREG
  FROM GENERAL G
  WHERE
    TIPDOC IN (19, 20, 21, 22, 26)
    AND (SELECT PARTENER FROM IESIRI I WHERE CODIES = G.CODDOC) = aCODPART
    AND (SELECT I.AN * 12 + I.LUNA FROM IESIRI I WHERE CODIES = G.CODDOC)
        &lt; current_setting ('PKG_GLOBALS.ANINITIAL', true) ::numeric * 12 + current_setting ('PKG_GLOBALS.LUNAINITIALA', true) ::numeric;

  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, FARAREG)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, FARAREG
  FROM GENERAL G
  WHERE
    TIPDOC               IN (29, 30, 31, 33)
    AND SEMNIFICATIE NOT IN (300, 400, 500, 600, 800, 801)
    AND (SELECT CODPART FROM TREZOR1 T WHERE CODTREZOR1 = G.CODDOC) = aCODPART
    AND (SELECT T.AN * 12 + T.LUNA FROM TREZOR1 T WHERE CODTREZOR1 = G.CODDOC)
        &lt; current_setting ('PKG_GLOBALS.ANINITIAL', true) ::numeric * 12 + current_setting ('PKG_GLOBALS.LUNAINITIALA', true) ::numeric;

  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, FARAREG)
  SELECT G.CODGENERAL, G.TIPDOC, G.CODDOC, G.MONEDA, G.CURS, G.TVA, G.SEMNIFICATIE, G.ICONTAVANS, G.PROCTVAAVANS, G.FARAREG
  FROM GENERAL G, NC1 N1, NC N
  WHERE
    G.TIPDOC = 35
    AND G.SEMNIFICATIE IN (1200, 1201)
    AND N1.CODNC1 = G.CODDOC
    AND N.CODNC = N1.CODNC
    AND N.PART = aCODPART
    AND N.AN * 12 + N.LUNA &lt; current_setting ('PKG_GLOBALS.ANINITIAL', true) ::numeric * 12 + current_setting ('PKG_GLOBALS.LUNAINITIALA', true) ::numeric;

  FOR V_REC IN (SELECT * FROM TMP_GENERAL) LOOP
    INSERT INTO TMP_OBLIGPIF (CODOBLIGPIF, CODGENERAL, VALOARE, TERMEN,
        MAJORARI, ADAOSDOC, GRATIE, CODPART,
        ICONT, SEMNIFICATIE, MONEDA, FARAREG,
        CURS, TVA, SUMALEI, SUMAVALUTA,
        NRDOC, DATADOC, AGENT, CODLOCATIE,
        OBS, SIMBOLCONT, DESCRSEMNIF, SUBUNITATEA,
        PROCTVAAVANS, CODOBLIGASOCIAT, VALPROVIZION, TIPTVA,
        TIPTRANZACTIE, PRORATA, SERIADOC, CURSDOCSTINS,
        CODCENTRU, CODTIPPARTINCERT)
    SELECT CODOBLIGPIF, CODGENERAL, VALOARE, TERMEN,
      MAJORARI, ADAOSDOC, GRATIE, CODPART,
      ICONT, SEMNIFICATIE, V_REC.MONEDA, V_REC.FARAREG,
      V_REC.CURS, V_REC.TVA,
      (
        CASE
          WHEN V_REC.MONEDA = 0  THEN O.VALOARE
          WHEN V_REC.MONEDA &lt;&gt; 0 THEN ROUND ( (O.VALOARE * V_REC.CURS) ::numeric, 2)
        END)
      , (
        CASE
          WHEN V_REC.MONEDA = 0  THEN 0
          WHEN V_REC.MONEDA &lt;&gt; 0 THEN O.VALOARE
        END)
      , (
        CASE
          WHEN V_REC.TIPDOC IN (1, 2, 3, 4, 9)                THEN (SELECT NRDOC FROM INTRARI WHERE CODINTR = V_REC.CODDOC)
          WHEN V_REC.TIPDOC = 5 AND V_REC.SEMNIFICATIE &lt;&gt; 130 THEN (SELECT NRDOC FROM INTRARI WHERE CODINTR = V_REC.CODDOC)
          WHEN V_REC.TIPDOC = 5 AND V_REC.SEMNIFICATIE = 130  THEN (SELECT NRDOC FROM DVI D   WHERE CODDVI  = V_REC.CODDOC)
          WHEN V_REC.TIPDOC IN (19, 20, 21, 22, 26)           THEN (SELECT NRDOC FROM IESIRI  WHERE CODIES  = V_REC.CODDOC)
          WHEN V_REC.TIPDOC IN (29, 30, 31, 33)               THEN (SELECT NRDOC FROM TREZOR1 WHERE CODTREZOR1 = V_REC.CODDOC)
          WHEN V_REC.TIPDOC IN (28)                           THEN (SELECT I.NRDOC FROM OBLIGPIF OBF, GENERAL GF, IESIRI I
                                                                    WHERE
                                                                      OBF.CODOBLIGPIF = O.CODOBLIGASOCIAT
                                                                      AND GF.CODGENERAL = OBF.CODGENERAL
                                                                      AND I.CODIES = GF.CODDOC
                                                                      AND I.TIPDOC = GF.TIPDOC)
          WHEN V_REC.TIPDOC IN (35)                           THEN (SELECT NRDOC FROM NC N, NC1 N1 WHERE N1.CODNC1 = V_REC.CODDOC AND N.CODNC = N1.CODNC)
        END)
      , (
        CASE
          WHEN V_REC.TIPDOC IN (1, 2, 3, 4, 9)          THEN (SELECT DATADOC FROM INTRARI WHERE CODINTR = V_REC.CODDOC)
          WHEN V_REC.TIPDOC = 5 AND SEMNIFICATIE &lt;&gt; 130 THEN (SELECT DATADOC FROM INTRARI WHERE CODINTR = V_REC.CODDOC)
          WHEN V_REC.TIPDOC = 5 AND SEMNIFICATIE = 130  THEN (SELECT DATADOC FROM DVI     WHERE CODDVI  = V_REC.CODDOC)
          WHEN V_REC.TIPDOC IN (19, 20, 21, 22, 26)     THEN (SELECT DATADOC FROM IESIRI  WHERE CODIES  = V_REC.CODDOC)
          WHEN V_REC.TIPDOC IN (29, 30, 31, 33)         THEN (SELECT DATADOC FROM TREZOR1 WHERE CODTREZOR1 = V_REC.CODDOC)
          WHEN V_REC.TIPDOC IN (28)                     THEN (SELECT I.DATADOC FROM OBLIGPIF OBF, GENERAL GF, IESIRI I
                                                              WHERE
                                                                OBF.CODOBLIGPIF = O.CODOBLIGASOCIAT
                                                                AND GF.CODGENERAL = OBF.CODGENERAL
                                                                AND I.CODIES = GF.CODDOC
                                                                AND I.TIPDOC = GF.TIPDOC)
          WHEN V_REC.TIPDOC IN (35)                     THEN (SELECT DATADOC FROM NC N, NC1 N1 WHERE N1.CODNC1 = V_REC.CODDOC AND N.CODNC = N1.CODNC)
        END)
      , (
        CASE
          WHEN V_REC.TIPDOC IN (19, 20, 21, 22, 26) THEN (SELECT AGENT FROM IESIRI WHERE CODIES = V_REC.CODDOC)
          WHEN V_REC.TIPDOC IN (28)                 THEN (SELECT I.AGENT FROM OBLIGPIF OBF, GENERAL GF, IESIRI I
                                                          WHERE
                                                            OBF.CODOBLIGPIF = O.CODOBLIGASOCIAT
                                                            AND GF.CODGENERAL = OBF.CODGENERAL
                                                            AND I.CODIES = GF.CODDOC
                                                            AND I.TIPDOC = GF.TIPDOC)
          WHEN V_REC.TIPDOC IN (29, 30, 31, 33)     THEN (SELECT AGENT FROM TREZOR1 WHERE CODTREZOR1 = V_REC.CODDOC)
          ELSE 0
        END)
      , (
        CASE
          WHEN V_REC.TIPDOC IN (1, 2, 3, 4, 9)                THEN (SELECT CODLOCATIE FROM INTRARI WHERE CODINTR = V_REC.CODDOC)
          WHEN V_REC.TIPDOC = 5 AND V_REC.SEMNIFICATIE &lt;&gt; 130 THEN (SELECT CODLOCATIE FROM INTRARI WHERE CODINTR = V_REC.CODDOC)
          WHEN V_REC.TIPDOC IN (19, 20, 21, 22, 26)           THEN (SELECT CODLOCATIE FROM IESIRI  WHERE CODIES  = V_REC.CODDOC)
          WHEN V_REC.TIPDOC IN (29, 30, 31, 33)               THEN (SELECT CODLOCATIE FROM TREZOR1 WHERE CODTREZOR1 = V_REC.CODDOC)
          WHEN V_REC.TIPDOC IN (28)                           THEN (SELECT I.CODLOCATIE FROM OBLIGPIF OBF, GENERAL GF, IESIRI I
                                                                    WHERE
                                                                      OBF.CODOBLIGPIF = O.CODOBLIGASOCIAT
                                                                      AND GF.CODGENERAL = OBF.CODGENERAL
                                                                      AND I.CODIES = GF.CODDOC
                                                                      AND I.TIPDOC = GF.TIPDOC)
          ELSE 0
        END)
      , (
        CASE
          WHEN V_REC.TIPDOC IN (1, 2, 3, 4, 9)                THEN (SELECT SUBSTR (OBS, 1, 250) FROM INTRARI WHERE CODINTR = V_REC.CODDOC)
          WHEN V_REC.TIPDOC = 5 AND V_REC.SEMNIFICATIE &lt;&gt; 130 THEN (SELECT SUBSTR (OBS, 1, 250) FROM INTRARI WHERE CODINTR = V_REC.CODDOC)
          WHEN V_REC.TIPDOC = 5 AND V_REC.SEMNIFICATIE = 130  THEN (SELECT SUBSTR (OBS, 1, 250) FROM DVI     WHERE CODDVI  = V_REC.CODDOC)
          WHEN V_REC.TIPDOC IN (19, 20, 21, 22, 26)           THEN (SELECT SUBSTR (OBS, 1, 250) FROM IESIRI  WHERE CODIES  = V_REC.CODDOC)
          WHEN V_REC.TIPDOC IN (29, 30, 31, 33)               THEN (SELECT SUBSTR (OBS, 1, 250) FROM TREZOR1  WHERE CODTREZOR1 = V_REC.CODDOC)
          WHEN V_REC.TIPDOC IN (28)                           THEN (SELECT SUBSTR (I.OBS, 1, 250) FROM OBLIGPIF OBF, GENERAL GF, IESIRI I
                                                                    WHERE
                                                                      OBF.CODOBLIGPIF = O.CODOBLIGASOCIAT
                                                                      AND GF.CODGENERAL = OBF.CODGENERAL
                                                                      AND I.CODIES = GF.CODDOC
                                                                      AND I.TIPDOC = GF.TIPDOC)
          WHEN V_REC.TIPDOC IN (35)                           THEN (SELECT SUBSTR (N.OBS, 1, 250) FROM NC N, NC1 N1 WHERE N1.CODNC1 = V_REC.CODDOC AND N.CODNC = N1.CODNC)
          ELSE NULL
        END)
      , (SELECT PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT
         FROM PKG_PLANCONTURI_GETSIMBOLCONT (NULL, (SELECT PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG.WME_RESULT
                                                    FROM PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG (NULL,O.SEMNIFICATIE, O.ICONT, (SELECT PKG_NOMPART_GET_PART_COD_CARACT_LUNA.WME_RESULT
                                                                                                                             FROM PKG_NOMPART_GET_PART_COD_CARACT_LUNA (NULL,O.CODPART, current_setting ('PKG_GLOBALS.ANINITIAL', true) ::numeric, current_setting ('PKG_GLOBALS.LUNAINITIALA', true) ::numeric))))))
      , (
        CASE
          WHEN V_REC.SEMNIFICATIE IN (100, 130) THEN
            CASE
              WHEN (SELECT COALESCE (VALOARE, 0) FROM OBLIGPIF O WHERE O.CODGENERAL = V_REC.CODGENERAL limit 1) &lt; 0 THEN 'De incasat'
              ELSE 'De platit'
            END
          WHEN V_REC.SEMNIFICATIE IN (200) THEN
            CASE
              WHEN (SELECT COALESCE (VALOARE, 0) FROM OBLIGPIF O WHERE O.CODGENERAL = V_REC.CODGENERAL limit 1) &lt; 0 THEN 'De platit'
              ELSE 'De incasat'
            END
          WHEN V_REC.SEMNIFICATIE IN (1303)     THEN 'Litigii'
          WHEN V_REC.SEMNIFICATIE IN (1301)     THEN 'De incasat'
          WHEN V_REC.SEMNIFICATIE IN (110, 210) THEN 'Avans facturat'
          WHEN V_REC.SEMNIFICATIE IN (120, 220) THEN 'Garantie'
          WHEN V_REC.SEMNIFICATIE IN (140, 240) THEN 'De facturat'
          WHEN V_REC.SEMNIFICATIE IN (310)      THEN 'Avans platit'
          WHEN V_REC.SEMNIFICATIE IN (330, 430) THEN 'Avans din retur'
          WHEN V_REC.SEMNIFICATIE IN (410)      THEN 'Avans incasat'
          WHEN V_REC.SEMNIFICATIE IN (1200) AND ICONT &lt;&gt; 3   THEN 'De platit'
          WHEN V_REC.SEMNIFICATIE IN (1200) AND ICONT IN (3) THEN 'De incasat'
          WHEN V_REC.SEMNIFICATIE IN (1201)     THEN 'De incasat'
        END)
      , (
        CASE
          WHEN V_REC.TIPDOC IN (1, 2, 3, 4, 9)                THEN (SELECT SUBUNITATEA   FROM INTRARI WHERE CODINTR = V_REC.CODDOC)
          WHEN V_REC.TIPDOC = 5 AND V_REC.SEMNIFICATIE &lt;&gt; 130 THEN (SELECT SUBUNITATEA   FROM INTRARI WHERE CODINTR = V_REC.CODDOC)
          WHEN V_REC.TIPDOC = 5 AND V_REC.SEMNIFICATIE = 130  THEN (SELECT I.SUBUNITATEA FROM DVI D, INTRARI I WHERE D.CODDVI = V_REC.CODDOC AND I.CODINTR = D.CODINTR)
          WHEN V_REC.TIPDOC IN (19, 20, 21, 22, 26)           THEN (SELECT SUBUNITATEA   FROM IESIRI WHERE CODIES = V_REC.CODDOC)
          WHEN V_REC.TIPDOC IN (29, 30, 31, 33)               THEN (SELECT T.SUBUNITATEA FROM TREZOR T, TREZOR1 T1 WHERE CODTREZOR1 = V_REC.CODDOC AND T1.CODTREZOR = T.CODTREZOR)
          WHEN V_REC.TIPDOC IN (28)                           THEN (SELECT SUBUNITATEA   FROM COMPENS WHERE CODCOMPENS = V_REC.CODDOC)
          WHEN V_REC.TIPDOC IN (35)                           THEN (SELECT N.SUBUNITATEA FROM NC N, NC1 N1 WHERE N1.CODNC1 = V_REC.CODDOC AND N.CODNC = N1.CODNC)
        END)
      , V_REC.PROCTVAAVANS, CODOBLIGASOCIAT,
      CASE
        WHEN V_REC.SEMNIFICATIE = 1303 THEN (
            CASE
              WHEN COALESCE (V_REC.MONEDA, 0) = 0 THEN ROUND ( (O.VALOARE * O.COEFPROVIZION) ::numeric, 3)
              ELSE ROUND ( (ROUND ( (O.VALOARE * V_REC.CURS) ::numeric, 2) * O.COEFPROVIZION) ::numeric, 3)
            END)
          ELSE 0
      END , (
        CASE
          WHEN V_REC.TIPDOC IN (1, 2, 3, 4, 9) THEN (SELECT TIPTVA FROM INTRARI WHERE CODINTR = V_REC.CODDOC)
          ELSE NULL
        END)
      , (
        CASE
          WHEN V_REC.TIPDOC IN (1, 2, 3, 4, 9) THEN (SELECT TIPTRANZACTIE FROM INTRARI WHERE CODINTR = V_REC.CODDOC)
          ELSE NULL
        END)
      , (
        CASE
          WHEN V_REC.TIPDOC IN (1, 2, 3, 4, 9) THEN (SELECT PRORATA FROM INTRARI WHERE CODINTR = V_REC.CODDOC)
          ELSE NULL
        END)
      , (
        CASE
          WHEN V_REC.TIPDOC IN (1, 2, 3, 4, 9)                THEN (SELECT SERIADOC FROM INTRARI WHERE CODINTR = V_REC.CODDOC)
          WHEN V_REC.TIPDOC = 5 AND V_REC.SEMNIFICATIE &lt;&gt; 130 THEN (SELECT SERIADOC FROM INTRARI WHERE CODINTR = V_REC.CODDOC)
          WHEN V_REC.TIPDOC IN (19, 20, 21, 22, 26)           THEN (SELECT SERIADOC FROM IESIRI WHERE CODIES = V_REC.CODDOC)
          WHEN V_REC.TIPDOC IN (29, 30, 31, 33)               THEN (SELECT SERIEDOC FROM TREZOR1 WHERE CODTREZOR1 = V_REC.CODDOC)
        END)
      , (
        CASE
          WHEN V_REC.TIPDOC IN (1, 2, 3, 4, 9)      THEN (SELECT CURS FROM INTRARI WHERE CODINTR = V_REC.CODDOC)
          WHEN V_REC.TIPDOC IN (19, 20, 21, 22, 26) THEN (SELECT CURS FROM IESIRI  WHERE CODIES  = V_REC.CODDOC)
        END)
      , CODCENTRU,
      CASE
        WHEN V_REC.TIPDOC IN (28) THEN (SELECT CODTIPPARTINCERT FROM COMPENS WHERE CODCOMPENS = V_REC.CODDOC)
        ELSE NULL
      END
    FROM OBLIGPIF O
    WHERE
      CODGENERAL = V_REC.CODGENERAL;
  END LOOP;

  FOR V_REC IN (SELECT CODOBLIGPIF, CODGENERAL FROM TMP_OBLIGPIF O
                WHERE O.SEMNIFICATIE = 200 AND EXISTS (SELECT CODOBLIGASOCIAT FROM TMP_OBLIGPIF WHERE CODOBLIGASOCIAT = O.CODOBLIGPIF))
  LOOP
    DELETE FROM TMP_GENERAL  WHERE CODGENERAL = V_REC.CODGENERAL;
    DELETE FROM TMP_OBLIGPIF WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
  END LOOP;

  UPDATE TMP_OBLIGPIF O
  SET PROCENT = (SELECT CODGENERAL FROM OBLIGPIF WHERE CODOBLIGPIF = O.CODOBLIGASOCIAT);

  INSERT INTO TMP_GENERAL_CECURI (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
  FROM GENERAL G
  WHERE
    TIPDOC = 31
    AND SEMNIFICATIE IN (500, 600)
    AND (SELECT CODPART FROM TREZOR1 T WHERE CODTREZOR1 = G.CODDOC) = aCODPART
    AND (SELECT T.AN * 12 + T.LUNA FROM TREZOR1 T WHERE CODTREZOR1 = G.CODDOC)
        &lt; current_setting ('PKG_GLOBALS.ANINITIAL', true) ::numeric * 12 + current_setting ('PKG_GLOBALS.LUNAINITIALA', true) ::numeric;

  INSERT INTO TMP_TREZOR1 (CODTREZOR1, CODTREZOR, INDEXLOCAL, TIPTRANZ, CARNETDOC, DOC, NRDOC, DATADOC, VALDOC, CURS, COMISION, CODMONEDA,
                           OBIECTTRANZ, CODPART, CODBANCA, TIPDECONT, DATADECONT, AN, LUNA, OBS, AGENT, ANULAT, INFOCONTBANCAR, SUBUNITATEA)
  SELECT T1.CODTREZOR1, T1.CODTREZOR, INDEXLOCAL, T1.TIPTRANZ, T1.CARNETDOC, T1.DOC, T1.NRDOC, T1.DATADOC, VALDOC, CURS, COMISION, M.CODMONEDA,
         OBIECTTRANZ, CODPART, T.CODBANCA, TIPDECONT, DATADECONT, T1.AN, T1.LUNA, T1.OBS, T1.AGENT, ANULAT,
         coalesce (BK.SIMBOL,'')
          || '/'
          || coalesce (BC.NRCONT::varchar ,'')
          || coalesce (CHR (13) ,'')
          || coalesce (M.SIMBOL,'') ,
         T.SUBUNITATEA
  FROM TREZOR1          T1, TREZOR T
    LEFT JOIN NBANKCONT BC ON BC.CODBANKCONT = T.CODBANCA
    LEFT JOIN NBANK     BK ON BK.CODBANK     = BC.CODBANK
    LEFT JOIN NMONEDE   M  ON M.CODMONEDA    = BC.CODMONEDA
  WHERE
    CODTREZOR1 IN (SELECT CODDOC FROM TMP_GENERAL_CECURI)
    AND T.CODTREZOR = T1.CODTREZOR;

  INSERT INTO TMP_GENERAL_CECURI (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
  FROM GENERAL G
  WHERE
    TIPDOC = 31
    AND SEMNIFICATIE IN (300, 400)
    AND CODDOC       IN (SELECT CODTREZOR1 FROM TMP_TREZOR1);

  INSERT INTO TMP_OBLIGPIF_ASOCIAT (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, ADAOSDOC, SEMNIFICATIE, TIP,
                                    CONTBANKTRANZACTIE, VALOAREAFISATA, CODTREZOR1)
  SELECT CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, ADAOSDOC, SEMNIFICATIE, TIP,
         CONTBANKTRANZACTIE, VALOAREAFISATA,
         (SELECT  DISTINCT CODTREZOR1 FROM TMP_TREZOR1 T1, TMP_GENERAL_CECURI G WHERE G.CODGENERAL = OB.CODGENERAL AND T1.CODTREZOR1 = G.CODDOC)
  FROM (SELECT * FROM OBLIGPIF WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL_CECURI)) OB
  ORDER BY CODOBLIGPIF;

  DELETE FROM TMP_STINGERE;

  INSERT INTO TMP_STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
  SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE
  FROM STINGERE
  WHERE
        CODSTINSPIF     IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF)
    AND CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF_ASOCIAT);

  DELETE FROM TMP_STINGERE_INITIAL;

  INSERT INTO TMP_STINGERE_INITIAL SELECT * FROM TMP_STINGERE;

  INSERT INTO TMP_STINGERE_INITIAL SELECT * FROM TMP_STINGERE_ASOCIAT;

  UPDATE TMP_OBLIGPIF_ASOCIAT OA
  SET
  CODTREZOR1      = COALESCE ( (SELECT CODDOC FROM TMP_GENERAL_CECURI WHERE CODGENERAL = OA.CODGENERAL) , 0) ,
  DENDOCLEGATURA  = COALESCE ( (SELECT coalesce ( (NRDOC) ::varchar,'') || '/' || coalesce (To_Char (DATADOC,'dd.mm.yyyy') ,'')
                                FROM TMP_OBLIGPIF
                                WHERE
                                  CODOBLIGPIF = (SELECT CODSTINSPIF FROM TMP_STINGERE WHERE CODSTINGATORPIF = OA.CODOBLIGPIF)) , '???') ,
  SIMBOLCONT      = COALESCE ( (SELECT SIMBOLCONT
                                FROM TMP_OBLIGPIF
                                WHERE
                                  CODOBLIGPIF = (SELECT CODSTINSPIF FROM TMP_STINGERE WHERE CODSTINGATORPIF = OA.CODOBLIGPIF)) , '???') ,
  CODOBLIGASOCIAT = COALESCE ( (SELECT CODSTINSPIF
                                FROM TMP_STINGERE
                                WHERE
                                  CODSTINGATORPIF = OA.CODOBLIGPIF) , 0) ,
  CURS            = COALESCE ( (SELECT CURS FROM TMP_OBLIGPIF WHERE CODOBLIGPIF = (SELECT CODSTINSPIF FROM TMP_STINGERE WHERE CODSTINGATORPIF = OA.CODOBLIGPIF)) , 1)
  WHERE
    SEMNIFICATIE IN (300, 400);

  FOR V_REC_AVANSURI IN (SELECT G.CODGENERAL, G.TIPDOC, G.CODDOC, G.SEMNIFICATIE, O.CODOBLIGPIF, O.NRDOC, O.DATADOC, O.SIMBOLCONT, O.SUMALEI, O.SUMAVALUTA, G.MONEDA
                         FROM TMP_GENERAL G, TMP_OBLIGPIF O
                         WHERE
                           O.CODGENERAL = G.CODGENERAL
                           AND G.SEMNIFICATIE IN (310, 410)
                           AND G.TIPDOC = 31
                        )
  LOOP
    aCODGENERAL_AVANS  := 0;
    aCODOBLIGPIF_AVANS := 0;
    FOR VREC_TREZOR1_CEC IN (SELECT * FROM TMP_TREZOR1 WHERE CODTREZOR1 = V_REC_AVANSURI.CODDOC) LOOP
      aCODGENERAL_AVANS  := aCODGENERAL_AVANS  + 1;
      aCODOBLIGPIF_AVANS := aCODOBLIGPIF_AVANS + 1;
      INSERT INTO TMP_GENERAL_CECURI (CODGENERAL, TIPDOC, CODDOC, SEMNIFICATIE)
      VALUES (aCODGENERAL_AVANS, 31, VREC_TREZOR1_CEC.CODTREZOR1, - V_REC_AVANSURI.SEMNIFICATIE);

      INSERT INTO TMP_OBLIGPIF_ASOCIAT (CODOBLIGPIF, CODGENERAL, VALOARE, SEMNIFICATIE, CODOBLIGASOCIAT, DENDOCLEGATURA, SIMBOLCONT, CODTREZOR1)
      VALUES (aCODOBLIGPIF_AVANS, aCODGENERAL_AVANS,
              CASE
                WHEN V_REC_AVANSURI.MONEDA = 0 THEN V_REC_AVANSURI.SUMALEI
                ELSE V_REC_AVANSURI.SUMAVALUTA
              END ,
              - V_REC_AVANSURI.SEMNIFICATIE, V_REC_AVANSURI.CODOBLIGPIF,
              coalesce ( (V_REC_AVANSURI.NRDOC) ::varchar,'') || '\' || coalesce (To_Char (V_REC_AVANSURI.DATADOC,'dd.mm.yyyy') ,'') ,
              V_REC_AVANSURI.SIMBOLCONT, VREC_TREZOR1_CEC.CODTREZOR1);
    END LOOP;
  END LOOP;

  UPDATE TMP_GENERAL G
  SET
  INITIALIZARI = (
      CASE
        WHEN TIPDOC IN (1, 2, 3, 4, 5, 9)   THEN (SELECT INITIALIZARI FROM INTRARI WHERE CODINTR = G.CODDOC)
        WHEN TIPDOC IN (19, 20, 21, 22, 26) THEN (SELECT INITIALIZARI FROM IESIRI  WHERE CODIES = G.CODDOC)
        WHEN TIPDOC IN (29, 30, 31, 33)     THEN (SELECT INITIALIZARI FROM TREZOR1 WHERE CODTREZOR1 = G.CODDOC)
        ELSE 0
      END);

  INSERT INTO TMP_INTRARI1 (CodIntr1, CodIntr, IndexLocal, CUSTODIE,
      TipLinie, Umsec, An, Luna,
      ContServ, CONTDISCOUNT, GESTACT, CodObiect,
      PretOrig, PU, Cant, TVA,
      AdDim, MIFIX, CODOBIECTORIG, PARITATEORIG,
      COEFDISCMAJ, OBS, RestFact, NrCertif,
      TG, PUMaximal, PURidicata, ProcAdaos,
      FURNAVIZSUBUNIT, DATAACHIZAVIZSUBUNIT, CODOBLIGSTORNO, CURSFACTURAAVANS,
      DenUM, Valoare, Paritate, ProcTVA,
      GestImplicita, ARETG, CERTIFICAT, CODTVA,
      CODACCIZE, CODTAXA1, CODTAXA2, DenObiect,
      CODGENERAL)
  SELECT *
  FROM (SELECT i1.CodIntr1, i1.CodIntr, i1.IndexLocal, I1.CUSTODIE,
        i1.TipLinie, i1.Umsec, i1.An, i1.Luna,
        i1.ContServ, i1.CONTDISCOUNT, i1.GestAct, i1.CodObiect,
        i1.PretOrig, i1.PU * COALESCE (u1.Paritate, 1) , i1.Cant / COALESCE (u1.Paritate, 1) , i1.TVA,
        i1.AdDim, I1.MIFIX, I1.CODOBIECTORIG, I1.PARITATEORIG,
        I1.COEFDISCMAJ, I1.OBS, i1.RestFact, i1.NrCertif,
        i1.TG, i1.PUMaximal, i1.PURidicata, i1.procadaos,
        i1.FURNAVIZSUBUNIT, I1.DATAACHIZAVIZSUBUNIT, I1.CODOBLIGSTORNO, I1.CURSFACTURAAVANS,
        CASE WHEN I1.TIPLINIE IN ('G', 'T') THEN '%' ELSE u1.Den_UM1 END ,
        (CASE WHEN UPPER (I1.TIPLINIE) IN ('=', 'S', 'V') THEN i1.Cant * i1.PU
              ELSE I1.RESTFACT
         END)
        , u1.Paritate,
        CASE
          WHEN UPPER (I1.TIPLINIE) IN ('=', 'S', 'V') THEN fnc_getprocenttvaart(a.CodArticol, current_setting ('PKG_GLOBALS.ANLUCRU', true) ::numeric, current_setting ('PKG_GLOBALS.LUNALUCRU', true) ::numeric)
          ELSE 0
        END ,
        A.GESTIMPLICITA, A.ARETG, A.CERTIFICAT,
        NART1LUNA.CODTVA, NART1LUNA.CODACCIZE, NART1LUNA.CODTAXA1, NART1LUNA.CODTAXA2,
        O.DENUMIRE, G.CODGENERAL
      FROM INTRARI1       i1
        LEFT JOIN NartObj o ON o.CodObiect = i1.CodObiect
        LEFT JOIN Nart    a ON a.CodArticol = o.CodArticol
        LEFT JOIN NART1 NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL AND GETANLUNALUCRU() BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP
        LEFT JOIN NUM1 u1 ON u1.CodUM1 = i1.UmSec, TMP_GENERAL G
      WHERE
        i1.CodIntr = G.CODDOC
        AND I1.TIPLINIE IN ('=', 'S')
        AND G.TIPDOC = 2
        AND G.SEMNIFICATIE = 140) A_PG
  ORDER BY
    IndexLocal;

  INSERT INTO TMP_IESIRI1 (CODIES1, CODIES, INDEXLOCAL, TIPLINIE,
      UMSEC, CONTSERV, CONTDISCOUNT, CODCRITERIU,
      MIFIX, GESTACT, CODOBIECT, PRETORIG,
      PU, CANT, TVA, CONT,
      PROCDISC, ADDIM, RESTFACT, PUMAXIMAL,
      GARANTIE, DENUM, VALOARE, PARITATE,
      PROCTVA, CODOBLIGSTORNO, CURSFACTURAAVANS, COEFDISCMAJ,
      OBS, CODOBIECTORIG, PARITATEORIG, CODTVA,
      CODACCIZE, CODTAXA1, CODTAXA2, CODCLASA,
      DENOBIECT, CODGENERAL)
  SELECT *
  FROM (SELECT I1.CODIES1, I1.CODIES, I1.INDEXLOCAL, I1.TIPLINIE,
        I1.UMSEC, I1.CONTSERV, I1.CONTDISCOUNT, I1.CODCRITERIU,
        I1.MIFIX, I1.GESTACT, I1.CODOBIECT, I1.PRETORIG,
        I1.PU * COALESCE (U1.PARITATE, 1) , I1.CANT / COALESCE (U1.PARITATE, 1) , I1.TVA, I1.CONT,
        I1.PROCDISC, I1.ADDIM, I1.RESTFACT, I1.PUMAXIMAL,
        I1.GARANTIE,
        CASE WHEN I1.TIPLINIE IN ('G', 'T') THEN '%' ELSE U1.DEN_UM1 END ,
        (CASE WHEN I1.TIPLINIE IN ('=', 'S', 'V') THEN I1.CANT * I1.PU ELSE I1.RESTFACT END)
        , U1.PARITATE,
        CASE
          WHEN I1.TIPLINIE IN ('=', 'S', 'V') THEN fnc_getprocenttvaart(A.CODARTICOL, current_setting ('PKG_GLOBALS.ANLUCRU', true) ::numeric, current_setting ('PKG_GLOBALS.LUNALUCRU', true) ::numeric)
          ELSE 0
        END ,
        I1.CODOBLIGSTORNO, I1.CURSFACTURAAVANS, I1.COEFDISCMAJ,
        I1.OBS, I1.CODOBIECTORIG, I1.PARITATEORIG, NART1LUNA.CODTVA,
        NART1LUNA.CODACCIZE, NART1LUNA.CODTAXA1, NART1LUNA.CODTAXA2, A.CLASA,
        O.DENUMIRE, G.CODGENERAL
      FROM IESIRI1          I1
        LEFT JOIN NARTOBJ O ON O.CODOBIECT = I1.CODOBIECT
        LEFT JOIN NART    A ON A.CODARTICOL = O.CODARTICOL
        LEFT OUTER JOIN NART1 NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL AND GETANLUNALUCRU() BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP
        LEFT JOIN NUM1 U1 ON U1.CODUM1 = I1.UMSEC, TMP_GENERAL G
      WHERE
        I1.CODIES = G.CODDOC
        AND I1.TIPLINIE IN ('=', 'S')
        AND G.TIPDOC = 20
        AND G.SEMNIFICATIE = 240) B_PG
  ORDER BY
    INDEXLOCAL;

  UPDATE TMP_OBLIGPIF
  SET
  PLATA =
          CASE
            WHEN SEMNIFICATIE IN (330, 430) THEN 2
            WHEN SEMNIFICATIE = 310 THEN 1
            WHEN SEMNIFICATIE = 410 THEN 1
            WHEN SEMNIFICATIE = 110 THEN 0
            WHEN SEMNIFICATIE = 210 THEN 0
            WHEN SEMNIFICATIE = 120 THEN 0
            WHEN SEMNIFICATIE = 220 THEN 0
            ELSE 1
          END
  WHERE
    ICONT IN (4, 5, 12, 13, 14);

  UPDATE TMP_GENERAL G SET SUBUNITATEA = (SELECT  DISTINCT SUBUNITATEA FROM TMP_OBLIGPIF O WHERE O.CODGENERAL = G.CODGENERAL);

  FOR V_REC IN (SELECT O.CODOBLIGPIF, G.CODDOC FROM TMP_OBLIGPIF O, TMP_GENERAL G WHERE O.SEMNIFICATIE = 200 AND O.CODGENERAL = G.CODGENERAL)
  LOOP
    UPDATE TMP_OBLIGPIF
    SET
      TVA = (SELECT TVADOC FROM IESIRI WHERE CODIES = V_REC.CODDOC)
    WHERE
      CODOBLIGPIF = V_REC.CODOBLIGPIF;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_GENERAL WHERE SEMNIFICATIE = 100) LOOP
    UPDATE TMP_OBLIGPIF
    SET
      TVAINCASARE = (SELECT TVAINCASARE FROM INTRARI WHERE CODINTR = V_REC.CODDOC)
    WHERE
      CODGENERAL = V_REC.CODGENERAL;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_GENERAL WHERE SEMNIFICATIE = 200) LOOP
    UPDATE TMP_OBLIGPIF
    SET
      TVAINCASARE = (SELECT TVAINCASARE FROM IESIRI WHERE CODIES = V_REC.CODDOC)
    WHERE
      CODGENERAL = V_REC.CODGENERAL;
  END LOOP;

  FOR V_REC IN (SELECT G.TIPDOC, G.CODDOC, O.SEMNIFICATIE, G.CODGENERAL
                FROM TMP_OBLIGPIF O, TMP_GENERAL G
                WHERE
                  O.TVAINCASARE = 1 AND O.CODGENERAL = G.CODGENERAL)
  LOOP
    IF V_REC.SEMNIFICATIE = 100 THEN
      INSERT INTO TMP_INTRARI1_TVAINCAS (CodIntr1, CodIntr, IndexLocal, CUSTODIE,
          TipLinie, Umsec, An, Luna,
          ContServ, CONTDISCOUNT, GestAct, CodObiect,
          PretOrig, PU, Cant, TVA,
          AdDim, MIFIX, CODOBIECTORIG, PARITATEORIG,
          COEFDISCMAJ, OBS, RestFact, NrCertif,
          TG, PUMaximal, PURidicata, ProcAdaos,
          FURNAVIZSUBUNIT, DATAACHIZAVIZSUBUNIT, CODOBLIGSTORNO, CURSFACTURAAVANS,
          DenUM, Valoare, Paritate, ProcTVA,
          GestImplicita, TVANEDED, ARETG, CERTIFICAT,
          CODTVA, CODACCIZE, CODTAXA1, CODTAXA2,
          DenObiect, CODGENERAL)
      SELECT *
      FROM (SELECT i1.CodIntr1, i1.CodIntr, i1.IndexLocal, I1.CUSTODIE,
            i1.TipLinie, i1.Umsec, i1.An, i1.Luna,
            i1.ContServ, i1.CONTDISCOUNT, i1.GestAct, i1.CodObiect,
            i1.PretOrig, i1.PU * COALESCE (u1.Paritate, 1) , i1.Cant / COALESCE (u1.Paritate, 1) , i1.TVA,
            i1.AdDim, I1.MIFIX, I1.CODOBIECTORIG, I1.PARITATEORIG,
            I1.COEFDISCMAJ, I1.OBS, i1.RestFact, i1.NrCertif,
            i1.TG, i1.PUMaximal, i1.PURidicata, i1.procadaos,
            i1.FURNAVIZSUBUNIT, I1.DATAACHIZAVIZSUBUNIT, I1.CODOBLIGSTORNO, I1.CURSFACTURAAVANS,
            CASE WHEN I1.TIPLINIE IN ('G', 'T') THEN '%' ELSE u1.Den_UM1 END ,
            (CASE WHEN UPPER (I1.TIPLINIE) IN ('=', 'S', 'V') THEN i1.Cant * i1.PU ELSE I1.RESTFACT END)
            , u1.Paritate,
            CASE
              WHEN UPPER (I1.TIPLINIE) IN ('=', 'S', 'V') THEN fnc_getprocenttvaart(a.CodArticol, current_setting ('PKG_GLOBALS.ANLUCRU', true) ::numeric, current_setting ('PKG_GLOBALS.LUNALUCRU', true) ::numeric)
              ELSE 0
            END ,
            A.GESTIMPLICITA, I1.TVANEDED, A.ARETG,
            A.CERTIFICAT, NART1LUNA.CODTVA, NART1LUNA.CODACCIZE, NART1LUNA.CODTAXA1,
            NART1LUNA.CODTAXA2, O.DENUMIRE, V_REC.CODGENERAL
          FROM INTRARI        I, INTRARI1 i1
            LEFT JOIN NartObj o ON o.CodObiect = i1.CodObiect
            LEFT JOIN Nart    a ON a.CodArticol = o.CodArticol
            LEFT JOIN NART1 NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL AND GETANLUNALUCRU() BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP
            LEFT JOIN NUM1 u1 ON u1.CodUM1 = i1.UmSec
          WHERE
            I.CODINTR = V_REC.CODDOC
            AND I.TIPDOC = V_REC.TIPDOC
            AND I1.CodIntr = I.CODINTR
            AND I1.TIPLINIE IN ('=', 'S')) C_PG
      ORDER BY
        IndexLocal;
    END IF;

    IF V_REC.SEMNIFICATIE = 200 THEN
      INSERT INTO TMP_IESIRI1_TVAINCAS (CODIES1, CODIES, INDEXLOCAL, TIPLINIE,
          UMSEC, CONTSERV, CONTDISCOUNT, CODCRITERIU,
          MIFIX, GESTACT, CODOBIECT, PRETORIG,
          PU, CANT, TVA, CONT,
          PROCDISC, ADDIM, RESTFACT, PUMAXIMAL,
          GARANTIE, DENUM, VALOARE, PARITATE,
          PROCTVA, CODOBLIGSTORNO, CURSFACTURAAVANS, COEFDISCMAJ,
          OBS, CODOBIECTORIG, PARITATEORIG, CODTVA,
          CODACCIZE, CODTAXA1, CODTAXA2, CODCLASA,
          DENOBIECT, CODGENERAL)
      SELECT *
      FROM (SELECT I1.CODIES1, I1.CODIES, I1.INDEXLOCAL, I1.TIPLINIE,
                I1.UMSEC, I1.CONTSERV, I1.CONTDISCOUNT, I1.CODCRITERIU,
                I1.MIFIX, I1.GESTACT, I1.CODOBIECT, I1.PRETORIG,
                I1.PU * COALESCE (U1.PARITATE, 1) , I1.CANT / COALESCE (U1.PARITATE, 1) , I1.TVA, I1.CONT,
                I1.PROCDISC, I1.ADDIM, I1.RESTFACT, I1.PUMAXIMAL,
                I1.GARANTIE,
                CASE WHEN I1.TIPLINIE IN ('G', 'T') THEN '%' ELSE U1.DEN_UM1 END ,
                (CASE WHEN I1.TIPLINIE IN ('=', 'S', 'V') THEN I1.CANT * I1.PU ELSE I1.RESTFACT END)
                , U1.PARITATE,
                CASE
                  WHEN I1.TIPLINIE IN ('=', 'S', 'V') THEN fnc_getprocenttvaart(A.CODARTICOL, current_setting ('PKG_GLOBALS.ANLUCRU', true) ::numeric, current_setting ('PKG_GLOBALS.LUNALUCRU', true) ::numeric)
                  ELSE 0
                END ,
                I1.CODOBLIGSTORNO, I1.CURSFACTURAAVANS, I1.COEFDISCMAJ,
                I1.OBS, I1.CODOBIECTORIG, I1.PARITATEORIG, NART1LUNA.CODTVA,
                NART1LUNA.CODACCIZE, NART1LUNA.CODTAXA1, NART1LUNA.CODTAXA2, A.CLASA,
                O.DENUMIRE, V_REC.CODGENERAL
            FROM IESIRI         I, IESIRI1 I1
              LEFT JOIN NARTOBJ O ON O.CODOBIECT = I1.CODOBIECT
              LEFT JOIN NART    A ON A.CODARTICOL = O.CODARTICOL
              LEFT JOIN NART1 NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL AND GETANLUNALUCRU() BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP        LEFT JOIN NUM1 U1 ON U1.CODUM1 = I1.UMSEC
            WHERE
              I.CODIES = V_REC.CODDOC
              AND I.TIPDOC = V_REC.TIPDOC
              AND I1.CODIES = I.CODIES
              AND I1.TIPLINIE IN ('=', 'S')
           ) D_PG
      ORDER BY INDEXLOCAL;
    END IF;
  END LOOP;

  DELETE FROM TMP_OBLIGPIF_INITIAL;

  INSERT INTO TMP_OBLIGPIF_INITIAL
  SELECT * FROM TMP_OBLIGPIF
  union ALL
  SELECT * FROM TMP_OBLIGPIF_ASOCIAT
  union ALL
  SELECT * FROM TMP_OBLIGVAMA_INITIAL;

  DELETE FROM TMP_TREZOR1_INITIAL;

  INSERT INTO TMP_TREZOR1_INITIAL (CODTREZOR1)
  SELECT CODTREZOR1 FROM TMP_TREZOR1;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_soldinitial_sp_postrecords</obj_name>
  <obj_hashval>49a11146f986ef500156a23b334eb97c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_soldinitial_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC                RECORD;
  V_RECGENERAL         RECORD;
  V_REC_TREZOR1        RECORD;
  V_REC_LINK_AVANS_CEC RECORD;
  V_RECOBLIG           RECORD;
  V_REC_STINGEREFACT   RECORD;
  V_RECINTRARI1        RECORD;
  V_RECIESIRI1         RECORD;
  V_REC_TREZ_D         RECORD;
  V_REC_GEN_D          RECORD;
  V_REC_GENERAL        RECORD;
  V_REC_OBLIG          RECORD;
  ANI               numeric;
  LUNAI             numeric;
  ANP               numeric;
  LUNAP             numeric;
  aPART             numeric;
  V_CODDOC          numeric;
  V_COD             numeric;
  V_CODGENERAL      numeric;
  NRDOC             numeric;
  aCODTREZOR        numeric;
  aCODTREZOR1       numeric;
  aCODOBLIGPIF      numeric;
  NRDOCS            numeric;
  NRNIRS            numeric;
  NR                numeric;
  CODFACTURA        numeric;
  CODOBLIGFACTURA   numeric;
  CODGENERALFACTURA numeric;
  CODOBLIGCOMPENS   numeric;
  CODGENERALCOMPENS numeric;
  aVALOARE     double precision;
  aVOLUMTRANZF double precision;
  aVOLUMTRANZC double precision;

  DATANEXTREG       date;
  aDATATVA          date;
  aTVAINCASARE      numeric := 0;
BEGIN
  --Bogdan 28.04.2022 - 52858 - Initializare solduri parteneri: observatii
  --Florin 09.03.2022 - sinc. Oracle (08.03.2022)
  --Adina 11.03.2021 - add prc_al_refresh
  --Bogdan 15.12.2020

  SELECT newAn, newluna INTO ANI, LUNAI
  FROM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA (current_setting ('PKG_GLOBALS.ANINITIAL', true) ::numeric, current_setting ('PKG_GLOBALS.LUNAINITIALA', true) ::numeric, ANI, LUNAI);


  SELECT CODPART INTO aPART FROM TMP_SOLDINI;

  IF OPERATION = 0 THEN
    SELECT CODSOLDINI INTO RecId FROM TMP_SOLDINI;

    UPDATE SOLDINI SET CODPART = aPART WHERE CODSOLDINI = RecID;

    DELETE FROM INTRARI1
    WHERE
      (CODINTR IN ( SELECT G.CODDOC
                    FROM TMP_OBLIGPIF_INITIAL O, GENERAL G
                    WHERE
                      G.CODGENERAL = O.CODGENERAL
                      AND G.TIPDOC = 2
                      AND G.SEMNIFICATIE = 140))
      AND (CODINTR1 NOT IN (SELECT CODINTR1 FROM TMP_INTRARI1));

    DELETE FROM IESIRI1
    WHERE
      (CODIES IN (SELECT G.CODDOC FROM TMP_OBLIGPIF_INITIAL O, GENERAL G
                  WHERE
                    G.CODGENERAL = O.CODGENERAL
                    AND G.TIPDOC = 20
                    AND G.SEMNIFICATIE = 240))
                    AND (CODIES1 NOT IN (SELECT CODIES1 FROM TMP_IESIRI1));

    DELETE FROM INTRARI1
    WHERE
      (CODINTR IN (SELECT G.CODDOC
          FROM TMP_OBLIGPIF_INITIAL O, GENERAL G
          WHERE
            O.TVAINCASARE = 1
            AND G.CODGENERAL = O.CODGENERAL
            AND G.SEMNIFICATIE = 100))
            AND (CODINTR1 NOT IN (SELECT CODINTR1 FROM TMP_INTRARI1_TVAINCAS));

    DELETE FROM IESIRI1
    WHERE
      (CODIES IN (SELECT G.CODDOC
          FROM TMP_OBLIGPIF_INITIAL O, GENERAL G
          WHERE
            O.TVAINCASARE = 1
            AND G.CODGENERAL = O.CODGENERAL
            AND G.SEMNIFICATIE = 200))
            AND (CODIES1 NOT IN (SELECT CODIES1 FROM TMP_IESIRI1_TVAINCAS));

    DELETE FROM STINGERE
    WHERE
      CODSTINGERE IN (SELECT CODSTINGERE FROM TMP_STINGERE_INITIAL)
      AND CODSTINGERE NOT IN (SELECT CODSTINGERE FROM TMP_STINGERE)
      AND CODSTINGERE NOT IN (SELECT CODSTINGERE FROM TMP_STINGERE_ASOCIAT);

    DELETE FROM TMP_DOCS;

    FOR V_REC IN (SELECT OI.*, G.TIPDOC, G.CODDOC, COALESCE (OO.CODOBLIGASOCIAT, 0) AS CODFACTURA
      FROM TMP_OBLIGPIF_INITIAL OI LEFT JOIN TMP_OBLIGPIF OO ON OO.CODOBLIGPIF = OI.CODOBLIGPIF, GENERAL G
      WHERE
        OI.SEMNIFICATIE = 1303
        AND COALESCE (OI.CODOBLIGASOCIAT, 0) &lt;&gt; 0
        AND COALESCE (OI.PROCENT, 0) &lt;&gt; 0
        AND G.CODGENERAL = OI.PROCENT)
    LOOP
      IF V_REC.CODOBLIGASOCIAT &lt;&gt; V_REC.CODFACTURA THEN
        SELECT COUNT(*)
        INTO NRDOCS
        FROM TMP_DOCS
        WHERE TIPDOC = V_REC.TIPDOC AND CODDOC = V_REC.CODDOC;

        IF NRDOCS = 0 THEN
          INSERT INTO TMP_DOCS (CODDOC, TIPDOC) VALUES (V_REC.CODDOC, V_REC.TIPDOC);
        END IF;

        DELETE FROM GENERAL      WHERE CODGENERAL  = V_REC.PROCENT;
        DELETE FROM OBLIGPIFLUNA WHERE CODOBLIGPIF = V_REC.CODOBLIGASOCIAT;
        DELETE FROM OBLIGPIF     WHERE CODOBLIGPIF = V_REC.CODOBLIGASOCIAT;
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT *
      FROM TMP_OBLIGPIF_INITIAL
      WHERE
        CODOBLIGPIF NOT IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF)
        AND CODOBLIGPIF NOT IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF_ASOCIAT)
        AND CODOBLIGPIF NOT IN (SELECT CODOBLIGPIF FROM TMP_OBLIGVAMA_INITIAL))
    LOOP
      FOR V_RECGENERAL IN (SELECT * FROM GENERAL WHERE CODGENERAL = V_REC.CODGENERAL) LOOP
        SELECT COUNT(*)
        INTO NRDOCS
        FROM TMP_DOCS
        WHERE TIPDOC = V_RECGENERAL.TIPDOC AND CODDOC = V_RECGENERAL.CODDOC;

        IF NRDOCS = 0 THEN
          INSERT INTO TMP_DOCS (CODDOC, TIPDOC) VALUES (V_RECGENERAL.CODDOC, V_RECGENERAL.TIPDOC);
        END IF;

        DELETE FROM GENERAL WHERE CODGENERAL = V_RECGENERAL.CODGENERAL;
      END LOOP;

      DELETE FROM OBLIGPIFLUNA WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
      DELETE FROM OBLIGPIF     WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_DOCS) LOOP
      SELECT COUNT(*)
      INTO NRDOCS
      FROM GENERAL
      WHERE TIPDOC = V_REC.TIPDOC AND CODDOC = V_REC.CODDOC;

      NRNIRS := 0;
      IF V_REC.TIPDOC IN (1, 2, 3, 4, 5, 9) THEN
        SELECT COUNT(*)
        INTO NRNIRS
        FROM NIR
        WHERE TIPNIR = V_REC.TIPDOC AND CODINTR = V_REC.CODDOC;
      END IF;

      IF NRDOCS + NRNIRS = 0 THEN
        IF V_REC.TIPDOC IN (1, 2, 3, 4, 5, 9) THEN
          DELETE FROM INTRARI1 WHERE CODINTR = V_REC.CODDOC;
        ELSE
          IF V_REC.TIPDOC IN (19, 20, 21, 22, 26) THEN
            DELETE FROM IESIRI1 WHERE CODIES = V_REC.CODDOC;
          ELSE
            IF V_REC.TIPDOC IN (29, 30, 31, 33) THEN
              FOR V_REC_TREZOR1 IN (SELECT * FROM TREZOR1 WHERE CODTREZOR1 = V_REC.CODDOC) LOOP
                DELETE FROM TREZOR1 WHERE CODTREZOR1 = V_REC_TREZOR1.CODTREZOR1;
              END LOOP;
            ELSE
              IF V_REC.TIPDOC IN (28) THEN
                DELETE FROM COMPENS WHERE CODCOMPENS = V_REC.CODDOC;
              ELSE
                IF V_REC.TIPDOC IN (35) THEN
                  DELETE FROM NC1 WHERE CODNC1 = V_REC.CODDOC;
                END IF;
              END IF;
            END IF;
          END IF;
        END IF;
      END IF;
    END LOOP;

    FOR V_RECGENERAL IN (SELECT * FROM TMP_GENERAL) LOOP
      IF (V_RECGENERAL.CODDOC IS NULL) OR (V_RECGENERAL.CODDOC = 0) THEN
        SELECT (
            CASE
              WHEN V_RECGENERAL.TIPDOC IN (1, 2, 3, 4, 9)                       THEN NEXTVAL ('SEQ_INTRARI_CODINTR')
              WHEN V_RECGENERAL.TIPDOC = 5 AND V_RECGENERAL.SEMNIFICATIE &lt;&gt; 130 THEN NEXTVAL ('SEQ_INTRARI_CODINTR')
              WHEN V_RECGENERAL.TIPDOC = 5 AND V_RECGENERAL.SEMNIFICATIE  = 130 THEN NEXTVAL ('SEQ_DVI_CODDVI')
              WHEN V_RECGENERAL.TIPDOC IN (19, 20, 21, 22, 26)                  THEN NEXTVAL ('SEQ_IESIRI_CODIES')
              WHEN V_RECGENERAL.TIPDOC IN (29, 30, 31, 33)                      THEN NEXTVAL ('SEQ_TREZOR1_CODTREZOR1')
              WHEN V_RECGENERAL.TIPDOC IN (28)                                  THEN NEXTVAL ('SEQ_COMPENS_CODCOMPENS')
              WHEN V_RECGENERAL.TIPDOC IN (35)                                  THEN NEXTVAL ('SEQ_NC1_CODNC1')
            END)
        INTO V_CODDOC;
      ELSE
        V_CODDOC := V_RECGENERAL.CODDOC;
      END IF;

      BEGIN
        SELECT TVAINCASARE, DATADOC
        INTO aTVAINCASARE, aDATATVA
        FROM TMP_OBLIGPIF
        WHERE CODGENERAL = V_RECGENERAL.CODGENERAL;
      EXCEPTION
      WHEN OTHERS THEN
        aTVAINCASARE := NULL;
        aDATATVA     := NULL;
      END;

      IF V_RECGENERAL.SEMNIFICATIE IN (310, 410) THEN
        BEGIN
          SELECT T1.CODTREZOR
          INTO ACODTREZOR
          FROM TREZOR1 T1
          WHERE T1.CODTREZOR1 = V_RECGENERAL.CODDOC;
        EXCEPTION
        WHEN OTHERS THEN
          ACODTREZOR := 0;
        END;

        FOR V_REC_LINK_AVANS_CEC IN (SELECT OA.CODTREZOR1
                                     FROM TMP_OBLIGPIF O, TMP_OBLIGPIF_ASOCIAT OA
                                     WHERE
                                       O.CODGENERAL = V_RECGENERAL.CODGENERAL
                                       AND OA.CODOBLIGASOCIAT = O.CODOBLIGPIF
                                       AND OA.SEMNIFICATIE = - V_RECGENERAL.SEMNIFICATIE)
        LOOP
          FOR V_REC_TREZOR1 IN (SELECT * FROM TMP_TREZOR1 WHERE CODTREZOR1 = V_REC_LINK_AVANS_CEC.CODTREZOR1) LOOP
            UPDATE TMP_TREZOR1
            SET
            CODTREZOR  = aCODTREZOR,
            CODTREZOR1 = V_CODDOC
            WHERE
              CODTREZOR1 = V_REC_LINK_AVANS_CEC.CODTREZOR1;

            UPDATE TREZOR
            SET
            TIPDOC   = 31,
            CODBANCA = V_REC_TREZOR1.CODBANCA
            WHERE
              CODTREZOR = aCODTREZOR;
          END LOOP;

          UPDATE TMP_GENERAL_CECURI   SET CODDOC = V_CODDOC     WHERE CODDOC = V_REC_LINK_AVANS_CEC.CODTREZOR1;
          UPDATE TMP_OBLIGPIF_ASOCIAT SET CODTREZOR1 = V_CODDOC WHERE CODTREZOR1 = V_REC_LINK_AVANS_CEC.CODTREZOR1;

          V_RECGENERAL.TIPDOC := 31;
        END LOOP;
      END IF;

      IF V_RECGENERAL.CODGENERAL &lt; 0 THEN
        SELECT NEXTVAL ('SEQ_GENERAL_CODGENERAL') INTO V_CODGENERAL;

        INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, FARAREG, DATATVA)
        VALUES (V_CODGENERAL, V_RECGENERAL.TIPDOC, V_CODDOC, V_RECGENERAL.MONEDA,
            ROUND ( (V_RECGENERAL.CURS) ::numeric, 7) ,
            CASE WHEN V_RECGENERAL.SEMNIFICATIE &lt;&gt; 200 THEN V_RECGENERAL.TVA ELSE NULL END ,
            V_RECGENERAL.SEMNIFICATIE, V_RECGENERAL.ICONTAVANS, V_RECGENERAL.PROCTVAAVANS, V_RECGENERAL.FARAREG,
            CASE WHEN aTVAINCASARE = 1 THEN aDATATVA ELSE NULL END);
      ELSE
        V_CODGENERAL := V_RECGENERAL.CODGENERAL;
        UPDATE GENERAL
        SET
          TIPDOC       = V_RECGENERAL.TIPDOC,
          CODDOC       = V_CODDOC,
          MONEDA       = V_RECGENERAL.MONEDA,
          CURS         = ROUND ( (V_RECGENERAL.CURS) ::numeric, 7) ,
          TVA          = CASE WHEN V_RECGENERAL.SEMNIFICATIE &lt;&gt; 200 THEN V_RECGENERAL.TVA ELSE NULL END ,
          SEMNIFICATIE = V_RECGENERAL.SEMNIFICATIE,
          ICONTAVANS   = V_RECGENERAL.ICONTAVANS,
          PROCTVAAVANS = V_RECGENERAL.PROCTVAAVANS,
          FARAREG      = V_RECGENERAL.FARAREG,
          DATATVA      = CASE WHEN aTVAINCASARE = 1 THEN aDATATVA ELSE NULL END
        WHERE
          CODGENERAL = V_CODGENERAL;
      END IF;

      FOR V_RECOBLIG IN (SELECT * FROM TMP_OBLIGPIF WHERE CODGENERAL = V_RECGENERAL.CODGENERAL) LOOP
        CODOBLIGFACTURA := NULL;
        IF V_RECOBLIG.MONEDA = 0 THEN
          aVALOARE := V_RECOBLIG.SUMALEI;
        ELSE
          aVALOARE := V_RECOBLIG.SUMAVALUTA;
        END IF;

        IF (V_RECOBLIG.SEMNIFICATIE = 1303) AND (COALESCE (V_RECOBLIG.CODOBLIGASOCIAT, 0) &lt;&gt; 0) THEN
          IF COALESCE (V_RECOBLIG.CODOBLIGASOCIAT, 0) &lt; 0 THEN
            SELECT NEXTVAL ('SEQ_OBLIGPIF_CODOBLIGPIF') INTO CODOBLIGFACTURA;
            SELECT NEXTVAL ('SEQ_GENERAL_CODGENERAL')   INTO CODGENERALFACTURA;
            SELECT NEXTVAL ('SEQ_IESIRI_CODIES')        INTO CODFACTURA;

            INSERT INTO IESIRI (CODIES, PREFIXDOC, TIPDOC, ANULAT, OPERAT, PARTENER, NRDOC, DATADOC, SUBUNITATEA, AN, LUNA, TVADOC, SERIADOC, MONEDA, CURS)
            VALUES (CODFACTURA, 'F', 19, 0,
                1, V_RECOBLIG.CODPART, V_RECOBLIG.NRDOC, V_RECOBLIG.DATADOC,
                V_RECOBLIG.SUBUNITATEA, ANI, LUNAI, V_RECOBLIG.TVA,
                V_RECOBLIG.SERIADOC, V_RECOBLIG.MONEDA, V_RECOBLIG.CURSDOCSTINS);

            INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
            VALUES (CODGENERALFACTURA, 19, CODFACTURA, V_RECOBLIG.MONEDA, ROUND ( (V_RECOBLIG.CURS) ::numeric, 7) , 200);

            INSERT INTO OBLIGPIF (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, SEMNIFICATIE, CODCENTRU)
            VALUES (CODOBLIGFACTURA, CODGENERALFACTURA, V_RECOBLIG.TERMEN, aVALOARE, 0, V_RECOBLIG.CODPART, 3, 200, V_RECOBLIG.CODCENTRU);

            UPDATE TMP_STINGERE_ASOCIAT
            SET CODSTINSPIF = CODOBLIGFACTURA
            WHERE
              CODSTINSPIF = V_RECOBLIG.CODOBLIGASOCIAT;
          ELSE
            CODOBLIGFACTURA   := V_RECOBLIG.CODOBLIGASOCIAT;
            CODGENERALFACTURA := V_RECOBLIG.PROCENT;
            BEGIN
              SELECT CODDOC INTO CODFACTURA FROM GENERAL WHERE CODGENERAL = CODGENERALFACTURA;
            EXCEPTION
            WHEN OTHERS THEN
              CODFACTURA := 0;
            END;

            UPDATE IESIRI
            SET
              PARTENER    = V_RECOBLIG.CODPART,
              NRDOC       = V_RECOBLIG.NRDOC,
              SERIADOC    = V_RECOBLIG.SERIADOC,
              DATADOC     = V_RECOBLIG.DATADOC,
              SUBUNITATEA = V_RECOBLIG.SUBUNITATEA,
              TVADOC      = V_RECOBLIG.TVA,
              MONEDA      = V_RECOBLIG.MONEDA,
              CURS        = V_RECOBLIG.CURSDOCSTINS
            WHERE
              CODIES = CODFACTURA;

            UPDATE GENERAL
            SET
            MONEDA = V_RECOBLIG.MONEDA,
            CURS   = ROUND ( (V_RECOBLIG.CURS) ::numeric, 7)
            WHERE
              CODGENERAL = CODGENERALFACTURA;

            UPDATE OBLIGPIF
            SET
            TERMEN    = V_RECOBLIG.TERMEN,
            CODPART   = V_RECOBLIG.CODPART,
            CODCENTRU = V_RECOBLIG.CODCENTRU,
            VALOARE   = aVALOARE
            WHERE
              CODOBLIGPIF = CODOBLIGFACTURA;
          END IF;

          FOR V_REC_STINGEREFACT IN (SELECT O.CODOBLIGPIF, G.CODGENERAL, S.CODSTINGERE
            FROM TMP_OBLIGVAMA_INITIAL O, TMP_GENERAL_LITIGII G, TMP_STINGERE_ASOCIAT S
            WHERE
              S.CODSTINSPIF = CODOBLIGFACTURA
              AND O.CODOBLIGPIF = S.CODSTINGATORPIF
              AND G.CODGENERAL = O.CODGENERAL)
          LOOP
            IF V_REC_STINGEREFACT.CODOBLIGPIF &lt; 0 THEN
              SELECT NEXTVAL ('SEQ_OBLIGPIF_CODOBLIGPIF') INTO CODOBLIGCOMPENS;
              SELECT NEXTVAL ('SEQ_GENERAL_CODGENERAL')   INTO CODGENERALCOMPENS;

              INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
              VALUES (CODGENERALCOMPENS, 28, V_CODDOC, V_RECOBLIG.MONEDA, V_RECOBLIG.CURS, 1350);

              IF V_RECOBLIG.MONEDA = 0 THEN
                aVALOARE := V_RECOBLIG.SUMALEI;
              ELSE
                aVALOARE := V_RECOBLIG.SUMAVALUTA;
              END IF;

              INSERT INTO OBLIGPIF (CODOBLIGPIF, CODGENERAL, VALOARE, CODPART, ICONT, SEMNIFICATIE, CODCENTRU)
              VALUES (CODOBLIGCOMPENS, CODGENERALCOMPENS, aVALOARE, V_RECOBLIG.CODPART, V_RECOBLIG.ICONT, 1350, V_RECOBLIG.CODCENTRU);

              INSERT INTO STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
              VALUES (NEXTVAL ('SEQ_STINGERE_CODSTINGERE') , CODOBLIGFACTURA, CODOBLIGCOMPENS, aVALOARE);
            ELSE
              UPDATE GENERAL
              SET
              MONEDA = V_RECOBLIG.MONEDA,
              CURS   = ROUND ( (V_RECOBLIG.CURS) ::numeric, 7)
              WHERE
                CODGENERAL = V_REC_STINGEREFACT.CODGENERAL;

              UPDATE OBLIGPIF
              SET
              VALOARE   = aVALOARE,
              CODCENTRU = V_RECOBLIG.CODCENTRU,
              CODPART   = V_RECOBLIG.CODPART
              WHERE
                CODOBLIGPIF = V_REC_STINGEREFACT.CODOBLIGPIF;

              UPDATE STINGERE SET VALOARE = aVALOARE WHERE CODSTINGERE = V_REC_STINGEREFACT.CODSTINGERE;
            END IF;
          END LOOP;
        END IF;

        IF V_RECOBLIG.CODOBLIGPIF &lt; 0 THEN
          SELECT NEXTVAL ('SEQ_OBLIGPIF_CODOBLIGPIF') INTO aCODOBLIGPIF;

          UPDATE TMP_STINGERE SET CODSTINSPIF = aCODOBLIGPIF WHERE CODSTINSPIF = V_RECOBLIG.CODOBLIGPIF;

          IF V_RECOBLIG.MONEDA = 0 THEN
            aVALOARE := V_RECOBLIG.SUMALEI;
          ELSE
            aVALOARE := V_RECOBLIG.SUMAVALUTA;
          END IF;

          INSERT INTO OBLIGPIF (CODOBLIGPIF, CODGENERAL, TERMEN, MAJORARI, ADAOSDOC, GRATIE, VALOARE, REST, CODPART, ICONT, SEMNIFICATIE, CODOBLIGASOCIAT, COEFPROVIZION, CODCENTRU)
          VALUES (aCODOBLIGPIF, V_CODGENERAL, V_RECOBLIG.TERMEN, V_RECOBLIG.MAJORARI, V_RECOBLIG.ADAOSDOC, V_RECOBLIG.GRATIE,
                  (CASE WHEN V_RECOBLIG.MONEDA = 0 THEN V_RECOBLIG.SUMALEI ELSE V_RECOBLIG.SUMAVALUTA END),
                  (CASE WHEN V_RECOBLIG.MONEDA = 0 THEN V_RECOBLIG.SUMALEI ELSE V_RECOBLIG.SUMAVALUTA END),
                  aPART, V_RECOBLIG.ICONT, V_RECOBLIG.SEMNIFICATIE, CODOBLIGFACTURA,
                  CASE WHEN V_RECOBLIG.SEMNIFICATIE = 1303 THEN (CASE WHEN V_RECOBLIG.SUMALEI = 0 THEN 0
                                                                      ELSE ROUND ( (V_RECOBLIG.VALPROVIZION / V_RECOBLIG.SUMALEI) ::numeric, 6)
                                                                 END)
                       ELSE NULL
                  END ,
                  V_RECOBLIG.CODCENTRU);

          INSERT INTO OBLIGPIFLUNA (CODOBLIGPIF, AN, LUNA, REST, RESTTVA)
          VALUES (aCODOBLIGPIF, ANI, LUNAI,
                  (CASE WHEN V_RECOBLIG.MONEDA = 0 THEN V_RECOBLIG.SUMALEI ELSE V_RECOBLIG.SUMAVALUTA END),
                   CASE WHEN V_RECOBLIG.SEMNIFICATIE &lt;&gt; 200 THEN COALESCE (V_RECOBLIG.TVA, 0) ELSE NULL END);
        ELSE
          UPDATE OBLIGPIF
          SET
            CODGENERAL = V_CODGENERAL,
            TERMEN     = V_RECOBLIG.TERMEN,
            MAJORARI   = V_RECOBLIG.MAJORARI,
            ADAOSDOC   = V_RECOBLIG.ADAOSDOC,
            GRATIE     = V_RECOBLIG.GRATIE,
            CODCENTRU  = V_RECOBLIG.CODCENTRU,
            VALOARE    = (CASE WHEN V_RECOBLIG.MONEDA = 0 THEN COALESCE (V_RECOBLIG.SUMALEI, 0) ELSE COALESCE (V_RECOBLIG.SUMAVALUTA, 0) END),
            REST       = (CASE WHEN (V_RECOBLIG.MONEDA = 0) AND (V_RECOBLIG.SUMALEI &gt;= 0)
                                 THEN V_RECOBLIG.SUMALEI - COALESCE ((SELECT SUM (VALOARE) FROM STINGERE WHERE CODSTINSPIF = V_RECOBLIG.CODOBLIGPIF) , 0)
                               WHEN (V_RECOBLIG.MONEDA = 0) AND (V_RECOBLIG.SUMALEI &lt; 0)
                                 THEN V_RECOBLIG.SUMALEI + COALESCE ((SELECT SUM (VALOARE) FROM STINGERE WHERE CODSTINSPIF = V_RECOBLIG.CODOBLIGPIF) , 0)
                               WHEN (V_RECOBLIG.MONEDA &lt;&gt; 0) AND (V_RECOBLIG.SUMAVALUTA &gt;= 0)
                                 THEN V_RECOBLIG.SUMAVALUTA - COALESCE ((SELECT SUM (VALOARE) FROM STINGERE WHERE CODSTINSPIF = V_RECOBLIG.CODOBLIGPIF) , 0)
                               WHEN (V_RECOBLIG.MONEDA &lt;&gt; 0) AND (V_RECOBLIG.SUMAVALUTA &lt; 0)
                                 THEN V_RECOBLIG.SUMAVALUTA + COALESCE ((SELECT SUM (VALOARE) FROM STINGERE WHERE CODSTINSPIF = V_RECOBLIG.CODOBLIGPIF) , 0)
                          END
                         ),
            CODPART         = aPART,
            ICONT           = V_RECOBLIG.ICONT,
            CODOBLIGASOCIAT = CODOBLIGFACTURA,
            SEMNIFICATIE    = V_RECOBLIG.SEMNIFICATIE,
            COEFPROVIZION   = CASE WHEN V_RECOBLIG.SEMNIFICATIE = 1303 THEN (CASE WHEN V_RECOBLIG.SUMALEI = 0 THEN 0
                                                                                  ELSE ROUND ( (V_RECOBLIG.VALPROVIZION / V_RECOBLIG.SUMALEI) ::numeric, 7)
                                                                             END)
                                   ELSE NULL
                              END
          WHERE
            CODOBLIGPIF = V_RECOBLIG.CODOBLIGPIF;

          SELECT COUNT(*)
          INTO NR
          FROM OBLIGPIFLUNA
          WHERE CODOBLIGPIF = V_RECOBLIG.CODOBLIGPIF AND AN = ANI AND LUNA = LUNAI;

          IF NR = 0 THEN
            INSERT INTO OBLIGPIFLUNA (CODOBLIGPIF, AN, LUNA, REST, RESTTVA)
            VALUES (V_RECOBLIG.CODOBLIGPIF, ANI, LUNAI,
                    (CASE WHEN V_RECOBLIG.MONEDA = 0 THEN V_RECOBLIG.SUMALEI ELSE V_RECOBLIG.SUMAVALUTA END),
                     CASE WHEN V_RECOBLIG.SEMNIFICATIE &lt;&gt; 200 THEN COALESCE (V_RECOBLIG.TVA, 0) ELSE NULL END
                   );
          ELSE
            UPDATE OBLIGPIFLUNA
            SET
            REST    = (CASE WHEN V_RECOBLIG.MONEDA = 0 THEN COALESCE (V_RECOBLIG.SUMALEI, 0)
                            ELSE COALESCE (V_RECOBLIG.SUMAVALUTA, 0)
                       END),
            RESTTVA =  CASE WHEN V_RECOBLIG.SEMNIFICATIE &lt;&gt; 200 THEN COALESCE (V_RECOBLIG.TVA, 0) ELSE NULL END
            WHERE
              CODOBLIGPIF = V_RECOBLIG.CODOBLIGPIF AND AN = ANI AND LUNA = LUNAI;
          END IF;
        END IF;

        NRDOC := 1;
        IF V_RECGENERAL.TIPDOC = 5 AND V_RECGENERAL.SEMNIFICATIE = 130 THEN
          SELECT COUNT(*) INTO NRDOC FROM DVI WHERE CODDVI = V_CODDOC;

          IF NRDOC &gt; 0 THEN
            UPDATE DVI
            SET
            NRDOC   = V_RECOBLIG.NRDOC,
            DATADOC = V_RECOBLIG.DATADOC,
            OBS     = V_RECOBLIG.OBS,
            CODVAMA = aPART
            WHERE
              CODDVI = V_CODDOC;
          END IF;
        END IF;

        IF ( (V_RECGENERAL.TIPDOC IN (1, 2, 3, 4, 9)) OR (V_RECGENERAL.TIPDOC = 5 AND V_RECGENERAL.SEMNIFICATIE &lt;&gt; 130)) THEN
          SELECT COUNT(*) INTO NRDOC FROM INTRARI WHERE CODINTR = V_CODDOC;

          IF NRDOC = 0 THEN
            INSERT INTO INTRARI (CODINTR, TIPDOC, ANULAT, BLOCAT,
                OPERAT, PREFIXDOC, NRDOC, DATADOC,
                CODLOCATIE, OBS, PARTENER, AN,
                LUNA, INITIALIZARI, SUBUNITATEA, TVAINCASARE,
                TIPTVA, TIPTRANZACTIE, PRORATA, VALDOC,
                SERIADOC, MONEDA, CURS)
              VALUES (V_CODDOC, V_RECGENERAL.TIPDOC, 0, 0, 1,
                      (SELECT PKG_GLOBALS_GETPREFIXDOC.WME_RESULT FROM PKG_GLOBALS_GETPREFIXDOC (NULL,V_RECGENERAL.TIPDOC)) ,
                      V_RECOBLIG.NRDOC, V_RECOBLIG.DATADOC, V_RECOBLIG.CODLOCATIE, V_RECOBLIG.OBS, aPART, ANI, LUNAI,
                      1, V_RECOBLIG.SUBUNITATEA, aTVAINCASARE, V_RECOBLIG.TIPTVA, V_RECOBLIG.TIPTRANZACTIE, V_RECOBLIG.PRORATA,
                      CASE WHEN V_RECOBLIG.MONEDA = 0 THEN COALESCE (V_RECOBLIG.SUMALEI, 0) ELSE COALESCE (V_RECOBLIG.SUMAVALUTA, 0) END,
                      V_RECOBLIG.SERIADOC, V_RECOBLIG.MONEDA, V_RECOBLIG.CURSDOCSTINS);
          ELSE
            UPDATE INTRARI
            SET
              TIPDOC        = V_RECGENERAL.TIPDOC,
              NRDOC         = V_RECOBLIG.NRDOC,
              SERIADOC      = V_RECOBLIG.SERIADOC,
              DATADOC       = V_RECOBLIG.DATADOC,
              CODLOCATIE    = V_RECOBLIG.CODLOCATIE,
              OBS           = V_RECOBLIG.OBS,
              PARTENER      = aPART,
              SUBUNITATEA   = V_RECOBLIG.SUBUNITATEA,
              INITIALIZARI  = V_RECGENERAL.INITIALIZARI,
              TVAINCASARE   = aTVAINCASARE,
              TIPTVA        = V_RECOBLIG.TIPTVA,
              TIPTRANZACTIE = V_RECOBLIG.TIPTRANZACTIE,
              PRORATA       = V_RECOBLIG.PRORATA,
              VALDOC        = CASE WHEN V_RECOBLIG.MONEDA = 0 THEN COALESCE (V_RECOBLIG.SUMALEI, 0) ELSE COALESCE (V_RECOBLIG.SUMAVALUTA, 0) END,
              MONEDA        = V_RECOBLIG.MONEDA,
              CURS          = V_RECOBLIG.CURSDOCSTINS
            WHERE
              CODINTR = V_CODDOC;
          END IF;
        ELSE
          IF V_RECGENERAL.TIPDOC IN (19, 20, 21, 22, 26) THEN
            SELECT COUNT(*) INTO NRDOC FROM IESIRI WHERE CODIES = V_CODDOC;

            IF NRDOC = 0 THEN
              INSERT INTO IESIRI (CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, NRDOC, DATADOC, AGENT, CODLOCATIE, OBS, PARTENER, AN, LUNA, INITIALIZARI, SUBUNITATEA,
                                  TVADOC, TVAINCASARE, DATATVA, VALDOC, SERIADOC, MONEDA, CURS)
              VALUES (V_CODDOC, V_RECGENERAL.TIPDOC, 0, 0, 1,
                      (SELECT PKG_GLOBALS_GETPREFIXDOC.WME_RESULT FROM PKG_GLOBALS_GETPREFIXDOC (NULL,V_RECGENERAL.TIPDOC)) ,
                      V_RECOBLIG.NRDOC, V_RECOBLIG.DATADOC, V_RECOBLIG.AGENT, V_RECOBLIG.CODLOCATIE, V_RECOBLIG.OBS, aPART, ANI, LUNAI, 1,
                      V_RECOBLIG.SUBUNITATEA, V_RECOBLIG.TVA, aTVAINCASARE, aDATATVA,
                      CASE WHEN V_RECOBLIG.MONEDA = 0 THEN COALESCE (V_RECOBLIG.SUMALEI, 0) ELSE COALESCE (V_RECOBLIG.SUMAVALUTA, 0) END,
                      V_RECOBLIG.SERIADOC, V_RECOBLIG.MONEDA, V_RECOBLIG.CURS);
            ELSE
              UPDATE IESIRI
              SET
                TIPDOC       = V_RECGENERAL.TIPDOC,
                NRDOC        = V_RECOBLIG.NRDOC,
                SERIADOC     = V_RECOBLIG.SERIADOC,
                DATADOC      = V_RECOBLIG.DATADOC,
                AGENT        = V_RECOBLIG.AGENT,
                CODLOCATIE   = V_RECOBLIG.CODLOCATIE,
                OBS          = V_RECOBLIG.OBS,
                SUBUNITATEA  = V_RECOBLIG.SUBUNITATEA,
                PARTENER     = aPART,
                INITIALIZARI = V_RECGENERAL.INITIALIZARI,
                TVADOC       = V_RECOBLIG.TVA,
                TVAINCASARE  = aTVAINCASARE,
                DATATVA      = aDATATVA,
                VALDOC       = CASE WHEN V_RECOBLIG.MONEDA = 0 THEN COALESCE (V_RECOBLIG.SUMALEI, 0) ELSE COALESCE (V_RECOBLIG.SUMAVALUTA, 0) END,
                MONEDA       = V_RECOBLIG.MONEDA,
                CURS         = V_RECOBLIG.CURSDOCSTINS
              WHERE
                CODIES = V_CODDOC;
            END IF;
          ELSE
            IF V_RECGENERAL.TIPDOC IN (29, 30, 31, 33) THEN
              SELECT COUNT(*) INTO NRDOC FROM TREZOR1 WHERE CODTREZOR1 = V_CODDOC;

              IF NRDOC = 0 THEN
                SELECT NEXTVAL ('SEQ_TREZOR_CODTREZOR') INTO aCODTREZOR;

                INSERT INTO TREZOR (CODTREZOR, TIPDOC, SUBUNITATEA, AN, LUNA, OPERAT)
                VALUES (aCODTREZOR, V_RECGENERAL.TIPDOC, V_RECGENERAL.SUBUNITATEA, ANI, LUNAI, 1);

                INSERT INTO TREZOR1 (CODTREZOR1, CODTREZOR, INDEXLOCAL, NRDOC, DATADOC, CODLOCATIE, CODPART, AN, LUNA, INITIALIZARI, AGENT, SERIEDOC, OBS)
                VALUES (V_CODDOC, aCODTREZOR, 1, V_RECOBLIG.NRDOC, V_RECOBLIG.DATADOC, V_RECOBLIG.CODLOCATIE, aPART, ANI, LUNAI, 1, V_RECOBLIG.AGENT, V_RECOBLIG.SERIADOC, V_RECOBLIG.OBS);

                UPDATE TMP_TREZOR1 SET CODTREZOR = aCODTREZOR WHERE CODTREZOR1 = V_CODDOC;
              ELSE
                UPDATE TREZOR1
                SET
                  NRDOC        = V_RECOBLIG.NRDOC,
                  SERIEDOC     = V_RECOBLIG.SERIADOC,
                  DATADOC      = V_RECOBLIG.DATADOC,
                  CODLOCATIE   = V_RECOBLIG.CODLOCATIE,
                  CODPART      = aPART,
                  AGENT        = V_RECOBLIG.AGENT,
                  INITIALIZARI = V_RECGENERAL.INITIALIZARI,
                  OBS          = V_RECOBLIG.OBS
                WHERE
                  CODTREZOR1 = V_CODDOC;

                UPDATE TREZOR
                SET SUBUNITATEA = V_RECOBLIG.SUBUNITATEA
                WHERE
                  CODTREZOR = (SELECT CODTREZOR FROM TREZOR1 WHERE CODTREZOR1 = V_CODDOC);
              END IF;
            ELSE
              IF V_RECGENERAL.TIPDOC IN (28) THEN
                SELECT COUNT(*) INTO NRDOC FROM COMPENS WHERE CODCOMPENS = V_CODDOC;

                IF NRDOC = 0 THEN
                  INSERT INTO COMPENS (CODCOMPENS, DATADOC, NRDOC, AN, LUNA, PARTD, PARTC, SUBUNITATEA, CODTIPPARTINCERT, TIPCOMPENS)
                  VALUES (V_CODDOC, V_RECOBLIG.DATADOC, 0, ANI, LUNAI, V_RECOBLIG.CODPART, V_RECOBLIG.CODPART, V_RECOBLIG.SUBUNITATEA, V_RECOBLIG.CODTIPPARTINCERT,
                          CASE WHEN V_RECOBLIG.SEMNIFICATIE = 1303 AND V_RECOBLIG.ICONT = 11 THEN 1
                               WHEN V_RECOBLIG.SEMNIFICATIE = 1303 AND V_RECOBLIG.ICONT = 10 THEN 4
                               ELSE 0
                          END);
                ELSE
                  UPDATE COMPENS
                  SET
                    PARTD            = V_RECOBLIG.CODPART,
                    PARTC            = V_RECOBLIG.CODPART,
                    CODTIPPARTINCERT = V_RECOBLIG.CODTIPPARTINCERT,
                    SUBUNITATEA      = V_RECOBLIG.SUBUNITATEA,
                    TIPCOMPENS       = CASE WHEN V_RECOBLIG.SEMNIFICATIE = 1303 AND V_RECOBLIG.ICONT = 11 THEN 1
                                            WHEN V_RECOBLIG.SEMNIFICATIE = 1303 AND V_RECOBLIG.ICONT = 10 THEN 4
                                            ELSE 0
                                       END
                  WHERE CODCOMPENS = V_CODDOC;
                END IF;
              ELSE
                IF V_RECGENERAL.TIPDOC = 35 THEN
                  UPDATE NC
                  SET SUBUNITATEA = V_RECOBLIG.SUBUNITATEA
                  WHERE CODNC = (SELECT CODNC FROM NC1 WHERE CODNC1 = V_CODDOC);
                END IF;
              END IF;
            END IF;
          END IF;
        END IF;

        FOR V_RECINTRARI1 IN (SELECT * FROM TMP_INTRARI1 WHERE CODGENERAL = V_RECGENERAL.CODGENERAL) LOOP
          IF COALESCE (V_RECINTRARI1.CodIntr1, 0) &gt; 0 THEN
            UPDATE INTRARI1
            SET
              IndexLocal           = V_RECINTRARI1.IndexLocal,
              TipLinie             = V_RECINTRARI1.TipLinie,
              UmSec                = V_RECINTRARI1.UmSec,
              An                   = V_RECINTRARI1.An,
              Luna                 = V_RECINTRARI1.Luna,
              ContServ             = V_RECINTRARI1.ContServ,
              CONTDISCOUNT         = V_RECINTRARI1.CONTDISCOUNT,
              GestAct              = V_RECINTRARI1.GestAct,
              CodObiect            = V_RECINTRARI1.CodObiect,
              PretOrig             = V_RECINTRARI1.PretOrig,
              PU                   = V_RECINTRARI1.PU / COALESCE (V_RECINTRARI1.Paritate, 1) ,
              Cant                 = V_RECINTRARI1.Cant * COALESCE (V_RECINTRARI1.Paritate, 1) ,
              TVA                  = V_RECINTRARI1.TVA,
              AdDim                = V_RECINTRARI1.AdDim,
              MIFIX                = V_RECINTRARI1.MIFIX,
              CODOBIECTORIG        = V_RECINTRARI1.CODOBIECTORIG,
              PARITATEORIG         = V_RECINTRARI1.PARITATEORIG,
              COEFDISCMAJ          = V_RECINTRARI1.COEFDISCMAJ,
              CUSTODIE             = V_RECINTRARI1.CUSTODIE,
              OBS                  = V_RECINTRARI1.OBS,
              CODOBLIGSTORNO       = V_RECINTRARI1.CODOBLIGSTORNO,
              CURSFACTURAAVANS     = V_RECINTRARI1.CURSFACTURAAVANS,
              RestFact             = CASE WHEN V_RECINTRARI1.TIPLINIE IN ('S', '=')
                                            THEN V_RECINTRARI1.Cant * V_RECINTRARI1.Paritate
                                                 - (SELECT COALESCE (SUM (IL.CANT) , 0)
                                                    FROM INTRLINK        IL
                                                      LEFT JOIN INTRARI1 I1 ON I1.CODINTR1 = IL.CODINTR1
                                                      LEFT JOIN INTRARI  I  ON I.CODINTR = I1.CODINTR
                                                    WHERE IL.CODLINIEAVIZ = V_RECINTRARI1.CodINTR1 AND I.TIPDOC = 9 AND I.OPERAT = 1 AND I.ANULAT = 0
                                                   )
                                                 + (SELECT COALESCE (SUM (AE1.CANT) , 0)
                                                    FROM INTRARI1 AE1, INTRARI AE
                                                    WHERE AE1.CODINTR1STORNO = V_RECINTRARI1.CODINTR1 AND AE.CODINTR = AE1.CODINTR AND AE.TIPDOC = 2
                                                      AND AE.OPERAT = 1 AND AE.ANULAT = 0
                                                   )
                                          ELSE 0
                                     END ,
              NrCertif             = V_RECINTRARI1.NrCertif,
              TG                   = V_RECINTRARI1.TG,
              PUMaximal            = V_RECINTRARI1.PUMaximal,
              PURidicata           = V_RECINTRARI1.PURidicata,
              ProcAdaos            = V_RECINTRARI1.ProcAdaos,
              FURNAVIZSUBUNIT      = V_RECINTRARI1.FURNAVIZSUBUNIT,
              DATAACHIZAVIZSUBUNIT = V_RECINTRARI1.DATAACHIZAVIZSUBUNIT
            WHERE
              CodIntr1 = V_RECINTRARI1.CodIntr1;
          ELSE
            SELECT NEXTVAL ('SEQ_INTRARI1_CODINTR1') INTO V_COD;

            INSERT INTO INTRARI1 (CodIntr1, CodIntr, IndexLocal, CUSTODIE, TipLinie, Umsec, An, Luna, ContServ, CONTDISCOUNT, GestAct, CodObiect,
                                  PretOrig, PU, Cant, TVA, AdDim, MIFIX, CODOBIECTORIG, PARITATEORIG, COEFDISCMAJ, OBS, RestFact, NrCertif,
                                  TG, PUMaximal, PURidicata, ProcAdaos, FURNAVIZSUBUNIT, DATAACHIZAVIZSUBUNIT, CODOBLIGSTORNO, CURSFACTURAAVANS)
            VALUES (V_COD, V_CODDOC, V_RECINTRARI1.IndexLocal, V_RECINTRARI1.CUSTODIE,
                    V_RECINTRARI1.TipLinie, V_RECINTRARI1.Umsec, V_RECINTRARI1.An, V_RECINTRARI1.Luna,
                    V_RECINTRARI1.ContServ, V_RECINTRARI1.CONTDISCOUNT, V_RECINTRARI1.GestAct, V_RECINTRARI1.CodObiect,
                    V_RECINTRARI1.PretOrig, V_RECINTRARI1.PU / COALESCE (V_RECINTRARI1.Paritate, 1) ,
                    V_RECINTRARI1.Cant * COALESCE (V_RECINTRARI1.Paritate, 1) , V_RECINTRARI1.TVA,
                    V_RECINTRARI1.AdDim, V_RECINTRARI1.MIFIX, V_RECINTRARI1.CODOBIECTORIG, V_RECINTRARI1.PARITATEORIG,
                    V_RECINTRARI1.COEFDISCMAJ, V_RECINTRARI1.OBS,
                    (CASE WHEN V_RECINTRARI1.TIPLINIE IN ('G', 'T') THEN V_RECINTRARI1.VALOARE ELSE V_RECINTRARI1.Cant  * V_RECINTRARI1.Paritate END),
                    V_RECINTRARI1.NrCertif, V_RECINTRARI1.TG, V_RECINTRARI1.PUMaximal, V_RECINTRARI1.PURidicata,
                    V_RECINTRARI1.ProcAdaos, V_RECINTRARI1.FURNAVIZSUBUNIT, V_RECINTRARI1.DATAACHIZAVIZSUBUNIT, V_RECINTRARI1.CODOBLIGSTORNO,
                    V_RECINTRARI1.CURSFACTURAAVANS);
          END IF;
        END LOOP;

        FOR V_RECINTRARI1 IN (SELECT * FROM TMP_INTRARI1_TVAINCAS WHERE CODGENERAL = V_RECGENERAL.CODGENERAL) LOOP
          IF COALESCE (V_RECINTRARI1.CodIntr1, 0) &gt; 0 THEN
            UPDATE INTRARI1
            SET
              IndexLocal    = V_RECINTRARI1.IndexLocal,
              TipLinie      = V_RECINTRARI1.TipLinie,
              UmSec         = V_RECINTRARI1.UmSec,
              An            = V_RECINTRARI1.An,
              Luna          = V_RECINTRARI1.Luna,
              ContServ      = V_RECINTRARI1.ContServ,
              CONTDISCOUNT  = V_RECINTRARI1.CONTDISCOUNT,
              GestAct       = V_RECINTRARI1.GestAct,
              CodObiect     = V_RECINTRARI1.CodObiect,
              PretOrig      = V_RECINTRARI1.PretOrig,
              PU            = V_RECINTRARI1.PU / COALESCE (V_RECINTRARI1.Paritate, 1) ,
              Cant          = V_RECINTRARI1.Cant * COALESCE (V_RECINTRARI1.Paritate, 1) ,
              TVA           = V_RECINTRARI1.TVA,
              AdDim         = V_RECINTRARI1.AdDim,
              MIFIX         = V_RECINTRARI1.MIFIX,
              CODOBIECTORIG = V_RECINTRARI1.CODOBIECTORIG,
              PARITATEORIG  = V_RECINTRARI1.PARITATEORIG,
              COEFDISCMAJ   = V_RECINTRARI1.COEFDISCMAJ,
              OBS           = V_RECINTRARI1.OBS,
              TVANEDED      = V_RECINTRARI1.TVANEDED
            WHERE
              CodIntr1 = V_RECINTRARI1.CodIntr1;
          ELSE
            SELECT NEXTVAL ('SEQ_INTRARI1_CODINTR1') INTO V_COD;

            INSERT INTO INTRARI1 (CodIntr1, CodIntr, IndexLocal, CUSTODIE, TipLinie, Umsec, An, Luna, ContServ, CONTDISCOUNT, GestAct, CodObiect,
                                  PretOrig, PU, Cant, TVA, AdDim, MIFIX, CODOBIECTORIG, PARITATEORIG, COEFDISCMAJ, OBS, TVANEDED)
            VALUES (V_COD, V_CODDOC, V_RECINTRARI1.IndexLocal, V_RECINTRARI1.CUSTODIE, V_RECINTRARI1.TipLinie, V_RECINTRARI1.Umsec, V_RECINTRARI1.An, V_RECINTRARI1.Luna,
                    V_RECINTRARI1.ContServ, V_RECINTRARI1.CONTDISCOUNT, V_RECINTRARI1.GestAct, V_RECINTRARI1.CodObiect,
                    V_RECINTRARI1.PretOrig, V_RECINTRARI1.PU / COALESCE (V_RECINTRARI1.Paritate, 1) , V_RECINTRARI1.Cant * COALESCE (V_RECINTRARI1.Paritate, 1) ,
                    V_RECINTRARI1.TVA, V_RECINTRARI1.AdDim, V_RECINTRARI1.MIFIX, V_RECINTRARI1.CODOBIECTORIG, V_RECINTRARI1.PARITATEORIG,
                    V_RECINTRARI1.COEFDISCMAJ, V_RECINTRARI1.OBS, V_RECINTRARI1.TVANEDED);
          END IF;
        END LOOP;

        IF V_RECGENERAL.TIPDOC IN (1, 2, 3, 4, 9) THEN
          UPDATE INTRARI
          SET TVADOC = (SELECT SUM (TVA) FROM INTRARI1 WHERE CODINTR = V_CODDOC)
          WHERE CODINTR = V_CODDOC;
        END IF;

        FOR V_RECIESIRI1 IN (SELECT * FROM TMP_IESIRI1 WHERE CODGENERAL = V_RECGENERAL.CODGENERAL) LOOP
          IF COALESCE (V_RECIESIRI1.CODIES1, 0) &gt; 0 THEN
            UPDATE IESIRI1
            SET
              INDEXLOCAL       = V_RECIESIRI1.INDEXLOCAL,
              TIPLINIE         = V_RECIESIRI1.TIPLINIE,
              UMSEC            = V_RECIESIRI1.UMSEC,
              CONTSERV         = V_RECIESIRI1.CONTSERV,
              CONTDISCOUNT     = V_RECIESIRI1.CONTDISCOUNT,
              CODCRITERIU      = V_RECIESIRI1.CODCRITERIU,
              MIFIX            = V_RECIESIRI1.MIFIX,
              GESTACT          = V_RECIESIRI1.GESTACT,
              CODOBIECT        = V_RECIESIRI1.CODOBIECT,
              PRETORIG         = V_RECIESIRI1.PU / COALESCE (V_RECIESIRI1.PARITATE, 1) ,
              PU               = V_RECIESIRI1.PU / COALESCE (V_RECIESIRI1.PARITATE, 1) ,
              CANT             = V_RECIESIRI1.CANT * COALESCE (V_RECIESIRI1.PARITATE, 1) ,
              TVA              = V_RECIESIRI1.TVA,
              CONT             = V_RECIESIRI1.CONT,
              PROCDISC         = V_RECIESIRI1.PROCDISC,
              CODOBLIGSTORNO   = V_RECIESIRI1.CODOBLIGSTORNO,
              CURSFACTURAAVANS = V_RECIESIRI1.CURSFACTURAAVANS,
              COEFDISCMAJ      = V_RECIESIRI1.COEFDISCMAJ,
              OBS              = V_RECIESIRI1.OBS,
              CODOBIECTORIG    = V_RECIESIRI1.CODOBIECTORIG,
              PARITATEORIG     = V_RECIESIRI1.PARITATEORIG,
              ADDIM            = V_RECIESIRI1.ADDIM,
              RESTFACT         = CASE WHEN V_RECIESIRI1.TIPLINIE IN ('S', '=')
                                        THEN V_RECIESIRI1.CANT * V_RECIESIRI1.PARITATE
                                             - (SELECT COALESCE (SUM (IL.CANT) , 0)
                                                FROM IESLINK        IL
                                                  LEFT JOIN IESIRI1 I1 ON I1.CODIES1 = IL.CODIES1
                                                  LEFT JOIN IESIRI  I  ON I.CODIES = I1.CODIES
                                                WHERE
                                                  IL.CODLINIEAVIZ = V_RECIESIRI1.CODIES1
                                                  AND I.TIPDOC = 26
                                                  AND I.OPERAT = 1
                                                  AND I.ANULAT = 0
                                               )
                                             + (SELECT COALESCE (SUM (AE1.CANT) , 0)
                                                FROM IESIRI1 AE1, IESIRI AE
                                                WHERE
                                                  AE1.CODIES1STORNO = V_RECIESIRI1.CODIES1
                                                  AND AE.CODIES = AE1.CODIES
                                                  AND AE.TIPDOC = 20
                                                  AND AE.OPERAT = 1
                                                  AND AE.ANULAT = 0
                                               )
                                      WHEN V_RECIESIRI1.TIPLINIE IN ('G', 'T') THEN V_RECIESIRI1.VALOARE
                                      ELSE 0
                                 END ,
              PUMAXIMAL        = V_RECIESIRI1.PUMAXIMAL,
              GARANTIE         = V_RECIESIRI1.GARANTIE
            WHERE
              CODIES1 = V_RECIESIRI1.CODIES1;
          ELSE
            SELECT NEXTVAL ('SEQ_IESIRI1_CODIES1') INTO V_COD;

            INSERT INTO IESIRI1 (CODIES1, CODIES, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, CONTDISCOUNT, CODCRITERIU, MIFIX, GESTACT, CODOBIECT, PRETORIG,
                                 PU, CANT, TVA, CONT, PROCDISC, ADDIM, RESTFACT, PUMAXIMAL, TIPLIVRARE, GARANTIE, CODOBLIGSTORNO, CURSFACTURAAVANS,
                                 COEFDISCMAJ, OBS, CODOBIECTORIG, PARITATEORIG)
            VALUES (V_COD, V_CODDOC, V_RECIESIRI1.INDEXLOCAL, V_RECIESIRI1.TIPLINIE,
                    V_RECIESIRI1.UMSEC, V_RECIESIRI1.CONTSERV, V_RECIESIRI1.CONTDISCOUNT, V_RECIESIRI1.CODCRITERIU,
                    V_RECIESIRI1.MIFIX, V_RECIESIRI1.GESTACT, V_RECIESIRI1.CODOBIECT, V_RECIESIRI1.PU / COALESCE (V_RECIESIRI1.PARITATE, 1) ,
                    V_RECIESIRI1.PU / COALESCE (V_RECIESIRI1.PARITATE, 1) , V_RECIESIRI1.CANT * COALESCE (V_RECIESIRI1.PARITATE, 1) , V_RECIESIRI1.TVA, V_RECIESIRI1.CONT,
                    V_RECIESIRI1.PROCDISC, V_RECIESIRI1.ADDIM,
                    (CASE WHEN V_RECIESIRI1.TIPLINIE IN ('G', 'T') THEN V_RECIESIRI1.VALOARE ELSE V_RECIESIRI1.CANT  * COALESCE (V_RECIESIRI1.PARITATE, 1) END),
                    V_RECIESIRI1.PUMAXIMAL, V_RECIESIRI1.TIPLIVRARE, V_RECIESIRI1.GARANTIE, V_RECIESIRI1.CODOBLIGSTORNO,
                    V_RECIESIRI1.CURSFACTURAAVANS, V_RECIESIRI1.COEFDISCMAJ, V_RECIESIRI1.OBS, V_RECIESIRI1.CODOBIECTORIG, V_RECIESIRI1.PARITATEORIG);
          END IF;
        END LOOP;

        FOR V_RECIESIRI1 IN (SELECT * FROM TMP_IESIRI1_TVAINCAS WHERE CODGENERAL = V_RECGENERAL.CODGENERAL) LOOP
          IF COALESCE (V_RECIESIRI1.CODIES1, 0) &gt; 0 THEN
            UPDATE IESIRI1
            SET
              INDEXLOCAL       = V_RECIESIRI1.INDEXLOCAL,
              TIPLINIE         = V_RECIESIRI1.TIPLINIE,
              UMSEC            = V_RECIESIRI1.UMSEC,
              CONTSERV         = V_RECIESIRI1.CONTSERV,
              CONTDISCOUNT     = V_RECIESIRI1.CONTDISCOUNT,
              CODCRITERIU      = V_RECIESIRI1.CODCRITERIU,
              MIFIX            = V_RECIESIRI1.MIFIX,
              GESTACT          = V_RECIESIRI1.GESTACT,
              CODOBIECT        = V_RECIESIRI1.CODOBIECT,
              PRETORIG         = V_RECIESIRI1.PU / COALESCE (V_RECIESIRI1.PARITATE, 1) ,
              PU               = V_RECIESIRI1.PU / COALESCE (V_RECIESIRI1.PARITATE, 1) ,
              CANT             = V_RECIESIRI1.CANT * COALESCE (V_RECIESIRI1.PARITATE, 1) ,
              TVA              = V_RECIESIRI1.TVA,
              CONT             = V_RECIESIRI1.CONT,
              PROCDISC         = V_RECIESIRI1.PROCDISC,
              CODOBLIGSTORNO   = V_RECIESIRI1.CODOBLIGSTORNO,
              CURSFACTURAAVANS = V_RECIESIRI1.CURSFACTURAAVANS,
              COEFDISCMAJ      = V_RECIESIRI1.COEFDISCMAJ,
              OBS              = V_RECIESIRI1.OBS,
              CODOBIECTORIG    = V_RECIESIRI1.CODOBIECTORIG,
              PARITATEORIG     = V_RECIESIRI1.PARITATEORIG,
              ADDIM            = V_RECIESIRI1.ADDIM,
              PUMAXIMAL        = V_RECIESIRI1.PUMAXIMAL,
              GARANTIE         = V_RECIESIRI1.GARANTIE
            WHERE
              CODIES1 = V_RECIESIRI1.CODIES1;
          ELSE
            SELECT NEXTVAL ('SEQ_IESIRI1_CODIES1') INTO V_COD;

            INSERT INTO IESIRI1 (CODIES1, CODIES, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, CONTDISCOUNT, CODCRITERIU, MIFIX, GESTACT, CODOBIECT, PRETORIG,
                                 PU, CANT, TVA, CONT, PROCDISC, ADDIM, PUMAXIMAL, TIPLIVRARE, GARANTIE, CODOBLIGSTORNO, CURSFACTURAAVANS, COEFDISCMAJ,
                                 OBS, CODOBIECTORIG, PARITATEORIG)
            VALUES (V_COD, V_CODDOC, V_RECIESIRI1.INDEXLOCAL, V_RECIESIRI1.TIPLINIE,
                    V_RECIESIRI1.UMSEC, V_RECIESIRI1.CONTSERV, V_RECIESIRI1.CONTDISCOUNT, V_RECIESIRI1.CODCRITERIU,
                    V_RECIESIRI1.MIFIX, V_RECIESIRI1.GESTACT, V_RECIESIRI1.CODOBIECT, V_RECIESIRI1.PU / COALESCE (V_RECIESIRI1.PARITATE, 1) ,
                    V_RECIESIRI1.PU / COALESCE (V_RECIESIRI1.PARITATE, 1) , V_RECIESIRI1.CANT * COALESCE (V_RECIESIRI1.PARITATE, 1) , V_RECIESIRI1.TVA, V_RECIESIRI1.CONT,
                    V_RECIESIRI1.PROCDISC, V_RECIESIRI1.ADDIM, V_RECIESIRI1.PUMAXIMAL, V_RECIESIRI1.TIPLIVRARE,
                    V_RECIESIRI1.GARANTIE, V_RECIESIRI1.CODOBLIGSTORNO, V_RECIESIRI1.CURSFACTURAAVANS, V_RECIESIRI1.COEFDISCMAJ,
                    V_RECIESIRI1.OBS, V_RECIESIRI1.CODOBIECTORIG, V_RECIESIRI1.PARITATEORIG);
          END IF;
        END LOOP;
      END LOOP;
    END LOOP;

    FOR V_REC_TREZ_D IN (SELECT TI.CODTREZOR1 CODI, COALESCE (T1.CODTREZOR1, 0) AS CODF
                         FROM TMP_TREZOR1_INITIAL TI LEFT JOIN TMP_TREZOR1 T1 ON T1.CODTREZOR1 = TI.CODTREZOR1)
    LOOP
      IF V_REC_TREZ_D.CODF = 0 THEN
        FOR V_REC_GEN_D IN (SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = 31 AND CODDOC = V_REC_TREZ_D.CODI) LOOP
          DELETE FROM OBLIGPIF WHERE CODGENERAL = V_REC_GEN_D .CODGENERAL;
          DELETE FROM GENERAL  WHERE CODGENERAL = V_REC_GEN_D .CODGENERAL;
        END LOOP;

        DELETE FROM TREZOR1 WHERE CODTREZOR1 = V_REC_TREZ_D.CODI;
      END IF;
    END LOOP;

    FOR V_REC_TREZOR1 IN (SELECT * FROM TMP_TREZOR1) LOOP
      IF V_REC_TREZOR1.CODTREZOR1 &lt; 0 THEN
        SELECT NEXTVAL ('SEQ_TREZOR_CODTREZOR')   INTO aCODTREZOR;
        SELECT NEXTVAL ('SEQ_TREZOR1_CODTREZOR1') INTO aCODTREZOR1;

        INSERT INTO TREZOR (CODTREZOR, TIPDOC, CODBANCA, AN, LUNA, OPERAT, BLOCAT, SUBUNITATEA)
        VALUES (aCODTREZOR, 31, V_REC_TREZOR1.CODBANCA, ANI, LUNAI, 1, 0, V_REC_TREZOR1.SUBUNITATEA);

        INSERT INTO TREZOR1 (CODTREZOR1, CODTREZOR, INDEXLOCAL, DOC, NRDOC, DATADOC, CODPART, TIPTRANZ, VALDOC, CURS, TIPDECONT, OBS,
                             DATADECONT, AN, LUNA, INITIALIZARI, ANULAT, AGENT)
        VALUES (aCODTREZOR1, aCODTREZOR, 1, V_REC_TREZOR1.DOC, V_REC_TREZOR1.NRDOC, V_REC_TREZOR1.DATADOC, aPART, V_REC_TREZOR1.TIPTRANZ,
                V_REC_TREZOR1.VALDOC, V_REC_TREZOR1.CURS, V_REC_TREZOR1.TIPDECONT, V_REC_TREZOR1.OBS, V_REC_TREZOR1.DATADECONT, ANI, LUNAI, 1, 0, V_REC_TREZOR1.AGENT);

        UPDATE TMP_GENERAL_CECURI   SET CODDOC = aCODTREZOR1     WHERE CODDOC = V_REC_TREZOR1.CODTREZOR1;
        UPDATE TMP_OBLIGPIF_ASOCIAT SET CODTREZOR1 = aCODTREZOR1 WHERE CODTREZOR1 = V_REC_TREZOR1.CODTREZOR1;

        FOR V_REC_GENERAL IN (SELECT * FROM TMP_GENERAL_CECURI WHERE CODDOC = aCODTREZOR1 AND SEMNIFICATIE &gt; 0) LOOP
          SELECT NEXTVAL ('SEQ_GENERAL_CODGENERAL') INTO V_CODGENERAL;

          UPDATE TMP_OBLIGPIF_ASOCIAT SET CODGENERAL = V_CODGENERAL WHERE CODGENERAL = V_REC_GENERAL.CODGENERAL;

          INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
          VALUES (V_CODGENERAL, V_REC_GENERAL.TIPDOC, V_REC_GENERAL.CODDOC, V_REC_GENERAL.MONEDA,
                  ROUND((V_REC_GENERAL.CURS) ::numeric, 7) , V_REC_GENERAL.TVA, V_REC_GENERAL.SEMNIFICATIE);
        END LOOP;

        FOR V_REC_OBLIG IN (SELECT * FROM TMP_OBLIGPIF_ASOCIAT WHERE CODTREZOR1 = aCODTREZOR1 AND SEMNIFICATIE &gt; 0) LOOP
          SELECT NEXTVAL ('SEQ_OBLIGPIF_CODOBLIGPIF') INTO ACODOBLIGPIF;

          UPDATE TMP_STINGERE SET CODSTINGATORPIF = aCODOBLIGPIF WHERE CODSTINGATORPIF = V_REC_OBLIG.CODOBLIGPIF;

          INSERT INTO OBLIGPIF (CODOBLIGPIF, CODGENERAL, VALOARE, REST, CODPART, ICONT, SEMNIFICATIE, CONTBANKTRANZACTIE)
          VALUES (aCODOBLIGPIF, V_REC_OBLIG.CODGENERAL, V_REC_OBLIG.VALOARE,
                  V_REC_OBLIG.VALOARE - COALESCE ((SELECT SUM (VALOARE) FROM STINGERE WHERE CODSTINSPIF = V_REC_OBLIG.CODOBLIGPIF) , 0) ,
                  V_REC_OBLIG.CODPART, V_REC_OBLIG.ICONT, V_REC_OBLIG.SEMNIFICATIE, V_REC_OBLIG.CONTBANKTRANZACTIE);

          INSERT INTO OBLIGPIFLUNA (CODOBLIGPIF, AN, LUNA, REST, RESTTVA)
          VALUES (aCODOBLIGPIF, ANI, LUNAI, V_REC_OBLIG.VALOARE, CASE WHEN V_REC_OBLIG.SEMNIFICATIE &lt;&gt; 200 THEN COALESCE (V_REC_OBLIG.TVA, 0) ELSE NULL END);
        END LOOP;
      ELSE
        UPDATE TREZOR
        SET
        CODBANCA    = V_REC_TREZOR1.CODBANCA,
        SUBUNITATEA = V_REC_TREZOR1.SUBUNITATEA
        WHERE
          CODTREZOR = V_REC_TREZOR1.CODTREZOR;

        UPDATE TREZOR1
        SET
          CODTREZOR  = V_REC_TREZOR1.CODTREZOR,
          DOC        = V_REC_TREZOR1.DOC,
          NRDOC      = V_REC_TREZOR1.NRDOC,
          DATADOC    = V_REC_TREZOR1.DATADOC,
          CODPART    = V_REC_TREZOR1.CODPART,
          TIPTRANZ   = V_REC_TREZOR1.TIPTRANZ,
          VALDOC     = V_REC_TREZOR1.VALDOC,
          CURS       = V_REC_TREZOR1.CURS,
          TIPDECONT  = V_REC_TREZOR1.TIPDECONT,
          OBS        = V_REC_TREZOR1.OBS,
          DATADECONT = V_REC_TREZOR1.DATADECONT,
          AN         = ANI,
          LUNA       = LUNAI,
          AGENT      = V_REC_TREZOR1.AGENT
        WHERE
          CODTREZOR1 = V_REC_TREZOR1.CODTREZOR1;

        FOR V_REC_GENERAL IN (SELECT * FROM TMP_GENERAL_CECURI WHERE CODDOC = V_REC_TREZOR1.CODTREZOR1 AND SEMNIFICATIE &gt; 0) LOOP
          IF V_REC_GENERAL.CODGENERAL &lt; 0 THEN
            SELECT NEXTVAL ('SEQ_GENERAL_CODGENERAL') INTO V_CODGENERAL;

            UPDATE TMP_OBLIGPIF_ASOCIAT SET CODGENERAL = V_CODGENERAL WHERE CODGENERAL = V_REC_GENERAL.CODGENERAL;

            INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
            VALUES (V_CODGENERAL, V_REC_GENERAL.TIPDOC, V_REC_GENERAL.CODDOC, V_REC_GENERAL.MONEDA,
                    ROUND ( (V_REC_GENERAL.CURS) ::numeric, 7) , V_REC_GENERAL.TVA, V_REC_GENERAL.SEMNIFICATIE);
          ELSE
            UPDATE GENERAL
            SET
              TIPDOC       = V_REC_GENERAL.TIPDOC,
              CODDOC       = V_REC_GENERAL.CODDOC,
              MONEDA       = V_REC_GENERAL.MONEDA,
              CURS         = ROUND ( (V_REC_GENERAL.CURS) ::numeric, 7) ,
              TVA          = V_REC_GENERAL.TVA,
              SEMNIFICATIE = V_REC_GENERAL.SEMNIFICATIE
            WHERE
              CODGENERAL = V_REC_GENERAL.CODGENERAL;
          END IF;
        END LOOP;

        FOR V_RECOBLIG IN (SELECT * FROM TMP_OBLIGPIF_ASOCIAT WHERE CODTREZOR1 = V_REC_TREZOR1.CODTREZOR1 AND SEMNIFICATIE &gt; 0) LOOP
          IF V_RECOBLIG.CODOBLIGPIF &lt; 0 THEN
            SELECT NEXTVAL ('SEQ_OBLIGPIF_CODOBLIGPIF') INTO ACODOBLIGPIF;

            UPDATE TMP_STINGERE SET CODSTINGATORPIF = aCODOBLIGPIF WHERE CODSTINGATORPIF = V_RECOBLIG.CODOBLIGPIF;

            INSERT INTO OBLIGPIF (CODOBLIGPIF, CODGENERAL, VALOARE, REST, CODPART, ICONT, SEMNIFICATIE, CONTBANKTRANZACTIE)
            VALUES (aCODOBLIGPIF, V_RECOBLIG.CODGENERAL, V_RECOBLIG.VALOARE,
                    CASE WHEN V_RECOBLIG.SEMNIFICATIE IN (500, 600) THEN V_RECOBLIG.VALOARE ELSE 0 END,
                    V_RECOBLIG.CODPART, V_RECOBLIG.ICONT, V_RECOBLIG.SEMNIFICATIE, V_RECOBLIG.CONTBANKTRANZACTIE);

            INSERT INTO OBLIGPIFLUNA (CODOBLIGPIF, AN, LUNA, REST, RESTTVA)
            VALUES (aCODOBLIGPIF, ANI, LUNAI,
                    CASE WHEN V_RECOBLIG.SEMNIFICATIE IN (500, 600) THEN V_RECOBLIG.VALOARE    ELSE 0    END ,
                    CASE WHEN V_RECOBLIG.SEMNIFICATIE &lt;&gt; 200 THEN COALESCE (V_RECOBLIG.TVA, 0) ELSE NULL END);
          ELSE
            UPDATE OBLIGPIF
            SET
            CODGENERAL         = V_RECOBLIG.CODGENERAL,
            VALOARE            = V_RECOBLIG.VALOARE,
            REST               = CASE WHEN V_RECOBLIG.SEMNIFICATIE IN (500, 600) THEN V_RECOBLIG.VALOARE - COALESCE ( (SELECT SUM (VALOARE) FROM STINGERE WHERE CODSTINSPIF = V_RECOBLIG.CODOBLIGPIF) , 0)
                                      ELSE 0
                                 END ,
            CODPART            = V_RECOBLIG.CODPART,
            ICONT              = V_RECOBLIG.ICONT,
            SEMNIFICATIE       = V_RECOBLIG.SEMNIFICATIE,
            CODCENTRU          = V_RECOBLIG.CODCENTRU,
            CONTBANKTRANZACTIE = V_RECOBLIG.CONTBANKTRANZACTIE
            WHERE
              CODOBLIGPIF = V_RECOBLIG.CODOBLIGPIF;

            UPDATE OBLIGPIFLUNA
            SET
            REST = CASE WHEN V_RECOBLIG.SEMNIFICATIE IN (500, 600) THEN V_RECOBLIG.VALOARE ELSE 0 END
            WHERE
              CODOBLIGPIF = V_RECOBLIG.CODOBLIGPIF AND AN = ANI AND LUNA = LUNA;
          END IF;
        END LOOP;
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_STINGERE) LOOP
      IF V_REC.CODSTINGERE &lt; 0 THEN
        INSERT INTO STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
        VALUES (NEXTVAL ('SEQ_STINGERE_CODSTINGERE') , V_REC.CODSTINSPIF, V_REC.CODSTINGATORPIF, V_REC.VALOARE);
      ELSE
        UPDATE STINGERE SET VALOARE = V_REC.VALOARE WHERE CODSTINGERE = V_REC.CODSTINGERE;
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT G.MONEDA, OSTINS.DATADOC, G.CURS AS OLDCURSREG, GSTINGATOR.CODGENERAL,
                         GSTINGATOR.CURS AS CURSSTINGATOR, T1.CODTREZOR, T1.DATADOC AS DATASTINGERE, G.CODGENERAL AS CODGENERALSTINS
                  FROM TMP_GENERAL G, TMP_OBLIGPIF OSTINS, STINGERE S, OBLIGPIF OSTINGATOR, GENERAL GSTINGATOR, TREZOR1 T1
                  WHERE
                    COALESCE (G.MONEDA, 0) &lt;&gt; 0
                    AND G.CODGENERAL = OSTINS.CODGENERAL
                    AND S.CODSTINSPIF = OSTINS.CODOBLIGPIF
                    AND OSTINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
                    AND GSTINGATOR.CODGENERAL = OSTINGATOR.CODGENERAL
                    AND GSTINGATOR.TIPDOC IN (29, 30, 31, 33)
                    AND T1.CODTREZOR1 = GSTINGATOR.CODDOC
                    AND G.CURS &lt;&gt; GSTINGATOR.CURS)
    LOOP
      SELECT MIN (DATADOC)
      INTO DATANEXTREG
      FROM REG R, REG1 R1
      WHERE
        TIPREG = 46
        AND R.DATADOC &gt; V_REC.DATADOC
        AND R.CODMONEDA = V_REC.MONEDA
        AND R1.CODREG = R.CODREG
        AND R1.CODGENERAL = V_REC.CODGENERALSTINS;

      IF (SELECT PKG_REGPART_DATA_DOC_CORECTA.WME_RESULT FROM PKG_REGPART_DATA_DOC_CORECTA (NULL,V_REC.DATASTINGERE, V_REC.DATADOC, DATANEXTREG)) = 1 THEN
        UPDATE GENERAL SET CURS = V_REC.OLDCURSREG WHERE CODGENERAL = V_REC.CODGENERAL;
        UPDATE JURNAL1 SET DIRTY = 1               WHERE TIPDOC IN (29, 30, 31, 33) AND CODDOC = v_rec.codtrezor;
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT G.MONEDA, OSTINS.DATADOC, G.CURS AS OLDCURSREG, GSTINGATOR.CODGENERAL,
                         GSTINGATOR.CURS AS CURSSTINGATOR, C.CODCOMPENS, C.DATADOC AS DATASTINGERE, G.CODGENERAL AS CODGENERALSTINS
                  FROM TMP_GENERAL G, TMP_OBLIGPIF OSTINS, STINGERE S, OBLIGPIF OSTINGATOR, GENERAL GSTINGATOR, COMPENS C
                  WHERE
                    COALESCE (G.MONEDA, 0) &lt;&gt; 0
                    AND G.CODGENERAL = OSTINS.CODGENERAL
                    AND S.CODSTINSPIF = OSTINS.CODOBLIGPIF
                    AND OSTINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
                    AND GSTINGATOR.CODGENERAL = OSTINGATOR.CODGENERAL
                    AND GSTINGATOR.TIPDOC IN (28)
                    AND C.CODCOMPENS = GSTINGATOR.CODDOC)
    LOOP
      SELECT MIN (DATADOC)
      INTO DATANEXTREG
      FROM REG R, REG1 R1
      WHERE
        TIPREG = 46
        AND R.DATADOC &gt; V_REC.DATADOC
        AND R.CODMONEDA = V_REC.MONEDA
        AND R1.CODREG = R.CODREG
        AND R1.CODGENERAL = V_REC.CODGENERALSTINS;

      IF (SELECT PKG_REGPART_DATA_DOC_CORECTA.WME_RESULT FROM PKG_REGPART_DATA_DOC_CORECTA (NULL,V_REC.DATASTINGERE, V_REC.DATADOC, DATANEXTREG)) = 1 THEN
        UPDATE JURNAL1 SET DIRTY = 1 WHERE TIPDOC = 28 AND CODDOC = V_REC.CODCOMPENS;
      END IF;
    END LOOP;
  ELSE
    SELECT NEXTVAL ('SEQ_SOLDINI_CODSOLDINI') INTO RECID;

    INSERT INTO SOLDINI SELECT RECID, aPART;

    FOR V_RECGENERAL IN (SELECT * FROM TMP_GENERAL) LOOP
      SELECT (
          CASE
            WHEN V_RECGENERAL.TIPDOC IN (1, 2, 3, 4, 5, 9)   THEN NEXTVAL ('SEQ_INTRARI_CODINTR')
            WHEN V_RECGENERAL.TIPDOC IN (19, 20, 21, 22, 26) THEN NEXTVAL ('SEQ_IESIRI_CODIES')
            WHEN V_RECGENERAL.TIPDOC IN (29, 30, 31, 33)     THEN NEXTVAL ('SEQ_TREZOR1_CODTREZOR1')
            WHEN V_RECGENERAL.TIPDOC IN (28)                 THEN NEXTVAL ('SEQ_COMPENS_CODCOMPENS')
          END)
      INTO V_CODDOC;

      BEGIN
        SELECT TVAINCASARE, DATADOC
        INTO aTVAINCASARE, aDATATVA
        FROM TMP_OBLIGPIF
        WHERE CODGENERAL = V_RECGENERAL.CODGENERAL;
      EXCEPTION
      WHEN OTHERS THEN
        aTVAINCASARE := NULL;
        aDATATVA     := NULL;
      END;

      IF V_RECGENERAL.SEMNIFICATIE IN (310, 410) THEN
        FOR V_REC_LINK_AVANS_CEC IN ( SELECT OA.CODTREZOR1
                                      FROM TMP_OBLIGPIF O, TMP_OBLIGPIF_ASOCIAT OA
                                      WHERE
                                        O.CODGENERAL = V_RECGENERAL.CODGENERAL
                                        AND OA.CODOBLIGASOCIAT = O.CODOBLIGPIF
                                        AND OA.SEMNIFICATIE = - V_RECGENERAL.SEMNIFICATIE)
        LOOP
          UPDATE TMP_TREZOR1          SET CODTREZOR1 = V_CODDOC WHERE CODTREZOR1 = V_REC_LINK_AVANS_CEC.CODTREZOR1;
          UPDATE TMP_GENERAL_CECURI   SET CODDOC = V_CODDOC     WHERE CODDOC     = V_REC_LINK_AVANS_CEC.CODTREZOR1;
          UPDATE TMP_OBLIGPIF_ASOCIAT SET CODTREZOR1 = V_CODDOC WHERE CODTREZOR1 = V_REC_LINK_AVANS_CEC.CODTREZOR1;

          V_RECGENERAL.TIPDOC := 31;
        END LOOP;
      END IF;

      SELECT NEXTVAL ('SEQ_GENERAL_CODGENERAL') INTO V_CODGENERAL;

      INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, FARAREG, DATATVA)
      VALUES (V_CODGENERAL, V_RECGENERAL.TIPDOC, V_CODDOC, V_RECGENERAL.MONEDA, ROUND ( (V_RECGENERAL.CURS) ::numeric, 7) ,
              CASE WHEN V_RECGENERAL.SEMNIFICATIE &lt;&gt; 200 THEN V_RECGENERAL.TVA ELSE NULL END,
              V_RECGENERAL.SEMNIFICATIE, V_RECGENERAL.ICONTAVANS, V_RECGENERAL.PROCTVAAVANS, V_RECGENERAL.FARAREG,
              CASE WHEN aTVAINCASARE = 1 THEN aDATATVA ELSE NULL END);

      FOR V_RECOBLIG IN (SELECT * FROM TMP_OBLIGPIF WHERE CODGENERAL = V_RECGENERAL.CODGENERAL) LOOP
        CODOBLIGFACTURA := NULL;
        IF V_RECOBLIG.MONEDA = 0 THEN
          aVALOARE := V_RECOBLIG.SUMALEI;
        ELSE
          aVALOARE := V_RECOBLIG.SUMAVALUTA;
        END IF;

        IF (V_RECOBLIG.SEMNIFICATIE = 1303) AND (COALESCE (V_RECOBLIG.CODOBLIGASOCIAT, 0) &lt;&gt; 0) THEN
          SELECT NEXTVAL ('SEQ_OBLIGPIF_CODOBLIGPIF') INTO CODOBLIGFACTURA;
          SELECT NEXTVAL ('SEQ_GENERAL_CODGENERAL')   INTO CODGENERALFACTURA;
          SELECT NEXTVAL ('SEQ_IESIRI_CODIES')        INTO CODFACTURA;

          INSERT INTO IESIRI (CODIES, PREFIXDOC, TIPDOC, ANULAT, OPERAT, PARTENER, NRDOC, DATADOC, SUBUNITATEA, AN, LUNA, TVADOC, TVAINCASARE, SERIADOC, MONEDA, CURS)
          VALUES (CODFACTURA, 'F', 19, 0, 1, V_RECOBLIG.CODPART, V_RECOBLIG.NRDOC, V_RECOBLIG.DATADOC,
                  V_RECOBLIG.SUBUNITATEA, ANI, LUNAI, V_RECOBLIG.TVA, aTVAINCASARE, V_RECOBLIG.SERIADOC, V_RECOBLIG.MONEDA, V_RECOBLIG.CURSDOCSTINS);

          INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
          VALUES (CODGENERALFACTURA, 19, CODFACTURA, V_RECOBLIG.MONEDA, ROUND ( (V_RECOBLIG.CURS) ::numeric, 7) , 200);

          INSERT INTO OBLIGPIF (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, SEMNIFICATIE, CODCENTRU)
          VALUES (CODOBLIGFACTURA, CODGENERALFACTURA, V_RECOBLIG.TERMEN, aVALOARE, 0, V_RECOBLIG.CODPART, 3, 200, V_RECOBLIG.CODCENTRU);

          UPDATE TMP_STINGERE_ASOCIAT SET CODSTINSPIF = CODOBLIGFACTURA WHERE CODSTINSPIF = V_RECOBLIG.CODOBLIGASOCIAT;

          FOR V_REC_STINGEREFACT IN ( SELECT O.CODOBLIGPIF, G.CODGENERAL, S.CODSTINGERE
                                      FROM TMP_OBLIGVAMA_INITIAL O, TMP_GENERAL_LITIGII G, TMP_STINGERE_ASOCIAT S
                                      WHERE
                                        S.CODSTINSPIF = CODOBLIGFACTURA
                                        AND O.CODOBLIGPIF = S.CODSTINGATORPIF
                                        AND G.CODGENERAL = O.CODGENERAL)
          LOOP
            SELECT NEXTVAL ('SEQ_OBLIGPIF_CODOBLIGPIF') INTO CODOBLIGCOMPENS;
            SELECT NEXTVAL ('SEQ_GENERAL_CODGENERAL')   INTO CODGENERALCOMPENS;

            INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
            VALUES (CODGENERALCOMPENS, 28, V_CODDOC, V_RECOBLIG.MONEDA, V_RECOBLIG.CURS, 1350);

            IF V_RECOBLIG.MONEDA = 0 THEN
              aVALOARE := V_RECOBLIG.SUMALEI;
            ELSE
              aVALOARE := V_RECOBLIG.SUMAVALUTA;
            END IF;

            INSERT INTO OBLIGPIF (CODOBLIGPIF, CODGENERAL, VALOARE, CODPART, ICONT, SEMNIFICATIE, CODCENTRU)
            VALUES (CODOBLIGCOMPENS, CODGENERALCOMPENS, aVALOARE, V_RECOBLIG.CODPART, V_RECOBLIG.ICONT, 1350, V_RECOBLIG.CODCENTRU);

            INSERT INTO STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
            VALUES (NEXTVAL ('SEQ_STINGERE_CODSTINGERE') , CODOBLIGFACTURA, CODOBLIGCOMPENS, aVALOARE);
          END LOOP;
        END IF;

        SELECT NEXTVAL ('SEQ_OBLIGPIF_CODOBLIGPIF') INTO aCODOBLIGPIF;

        UPDATE TMP_STINGERE SET CODSTINSPIF = aCODOBLIGPIF WHERE CODSTINSPIF = V_RECOBLIG.CODOBLIGPIF;

        INSERT INTO OBLIGPIF (CODOBLIGPIF, CODGENERAL, TERMEN, MAJORARI, ADAOSDOC, GRATIE, VALOARE, REST, CODPART, ICONT, SEMNIFICATIE, CODOBLIGASOCIAT, COEFPROVIZION, CODCENTRU)
        VALUES (aCODOBLIGPIF, V_CODGENERAL, V_RECOBLIG.TERMEN, V_RECOBLIG.MAJORARI, V_RECOBLIG.ADAOSDOC, V_RECOBLIG.GRATIE,
                (CASE WHEN V_RECOBLIG.MONEDA = 0 THEN COALESCE (V_RECOBLIG.SUMALEI, 0) ELSE COALESCE (V_RECOBLIG.SUMAVALUTA, 0) END),
                (CASE WHEN V_RECOBLIG.MONEDA = 0 THEN COALESCE (V_RECOBLIG.SUMALEI, 0) ELSE COALESCE (V_RECOBLIG.SUMAVALUTA, 0) END),
                aPART, V_RECOBLIG.ICONT, V_RECOBLIG.SEMNIFICATIE, CODOBLIGFACTURA,
                CASE WHEN V_RECOBLIG.SEMNIFICATIE = 1303 THEN (CASE WHEN V_RECOBLIG.SUMALEI = 0 THEN 0
                                                                    ELSE ROUND ( (V_RECOBLIG.VALPROVIZION / V_RECOBLIG.SUMALEI) ::numeric, 7)
                                                               END)
                     ELSE NULL
                END ,
               V_RECOBLIG.CODCENTRU);

        INSERT INTO OBLIGPIFLUNA (CODOBLIGPIF, AN, LUNA, REST, RESTTVA)
        VALUES (aCODOBLIGPIF, ANI, LUNAI,
                (CASE WHEN V_RECOBLIG.MONEDA = 0 THEN COALESCE (V_RECOBLIG.SUMALEI, 0) ELSE COALESCE (V_RECOBLIG.SUMAVALUTA, 0) END),
                 CASE WHEN V_RECOBLIG.SEMNIFICATIE &lt;&gt; 200 THEN COALESCE (V_RECOBLIG.TVA, 0) ELSE NULL END);

        IF V_RECGENERAL.TIPDOC IN (1, 2, 3, 4, 5, 9) THEN
          INSERT INTO INTRARI (CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, NRDOC, DATADOC, CODLOCATIE, OBS, PARTENER, AN, LUNA, INITIALIZARI, SUBUNITATEA, TVAINCASARE,
                               TIPTVA, TIPTRANZACTIE, PRORATA, VALDOC, SERIADOC, MONEDA, CURS)
          VALUES (V_CODDOC, V_RECGENERAL.TIPDOC, 0, 0, 1,
                  (SELECT PKG_GLOBALS_GETPREFIXDOC.WME_RESULT FROM PKG_GLOBALS_GETPREFIXDOC (NULL,V_RECGENERAL.TIPDOC)) ,
                  V_RECOBLIG.NRDOC, V_RECOBLIG.DATADOC, V_RECOBLIG.CODLOCATIE, V_RECOBLIG.OBS, aPART, ANI, LUNAI,
                  1, V_RECGENERAL.SUBUNITATEA, aTVAINCASARE, V_RECOBLIG.TIPTVA, V_RECOBLIG.TIPTRANZACTIE, V_RECOBLIG.PRORATA,
                  CASE WHEN V_RECOBLIG.MONEDA = 0 THEN COALESCE (V_RECOBLIG.SUMALEI, 0) ELSE COALESCE (V_RECOBLIG.SUMAVALUTA, 0) END,
                 V_RECOBLIG.SERIADOC, V_RECOBLIG.MONEDA, V_RECOBLIG.CURSDOCSTINS);
        ELSE
          IF V_RECGENERAL.TIPDOC IN (19, 20, 21, 22, 26) THEN
            INSERT INTO IESIRI (CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, NRDOC, DATADOC, AGENT, CODLOCATIE, OBS, PARTENER, AN, LUNA, INITIALIZARI, SUBUNITATEA,
                                TVADOC, TVAINCASARE, VALDOC, SERIADOC, MONEDA, CURS)
            VALUES (V_CODDOC, V_RECGENERAL.TIPDOC, 0, 0, 1,
                    (SELECT PKG_GLOBALS_GETPREFIXDOC.WME_RESULT FROM PKG_GLOBALS_GETPREFIXDOC (NULL,V_RECGENERAL.TIPDOC)) ,
                    V_RECOBLIG.NRDOC, V_RECOBLIG.DATADOC, V_RECOBLIG.AGENT, V_RECOBLIG.CODLOCATIE, V_RECOBLIG.OBS, aPART, ANI, LUNAI, 1,
                    V_RECGENERAL.SUBUNITATEA, V_RECOBLIG.TVA, aTVAINcasare,
                    CASE WHEN V_RECOBLIG.MONEDA = 0 THEN COALESCE (V_RECOBLIG.SUMALEI, 0) ELSE COALESCE (V_RECOBLIG.SUMAVALUTA, 0) END,
                   V_RECOBLIG.SERIADOC, V_RECOBLIG.MONEDA, V_RECOBLIG.CURSDOCSTINS);
          ELSE
            IF V_RECGENERAL.TIPDOC IN (29, 30, 31, 33) THEN
              SELECT NEXTVAL ('SEQ_TREZOR_CODTREZOR') INTO aCODTREZOR;

              INSERT INTO TREZOR (CODTREZOR, TIPDOC, SUBUNITATEA, AN, LUNA, OPERAT)
              VALUES (aCODTREZOR, V_RECGENERAL.TIPDOC, V_RECGENERAL.SUBUNITATEA, ANI, LUNAI, 1);

              INSERT INTO TREZOR1 (CODTREZOR1, CODTREZOR, INDEXLOCAL, NRDOC, DATADOC, CODPART, CODLOCATIE, AN, LUNA, INITIALIZARI, AGENT, SERIEDOC, OBS)
              VALUES (V_CODDOC, aCODTREZOR, 1, V_RECOBLIG.NRDOC, V_RECOBLIG.DATADOC, aPART, V_RECOBLIG.CODLOCATIE, ANI, LUNAI, 1, V_RECOBLIG.AGENT, V_RECOBLIG.SERIADOC, V_RECOBLIG.OBS);

              UPDATE TMP_TREZOR1 SET CODTREZOR = aCODTREZOR WHERE CODTREZOR1 = V_CODDOC;
            ELSE
              IF V_RECGENERAL.TIPDOC IN (28) THEN
                INSERT INTO COMPENS (CODCOMPENS, DATADOC, NRDOC, AN, LUNA, PARTD, PARTC, SUBUNITATEA, CODTIPPARTINCERT, TIPCOMPENS)
                VALUES (V_CODDOC, V_RECOBLIG.DATADOC, 0, ANI, LUNAI, V_RECOBLIG.CODPART, V_RECOBLIG.CODPART, V_RECOBLIG.SUBUNITATEA, V_RECOBLIG.CODTIPPARTINCERT,
                        CASE WHEN V_RECOBLIG.SEMNIFICATIE = 1303 AND V_RECOBLIG.ICONT = 11 THEN 1
                             WHEN V_RECOBLIG.SEMNIFICATIE = 1303 AND V_RECOBLIG.ICONT = 10 THEN 4
                             ELSE 0
                        END);
              END IF;
            END IF;
          END IF;
        END IF;

        FOR V_RECINTRARI1 IN (SELECT * FROM TMP_INTRARI1 WHERE CODGENERAL = V_RECGENERAL.CODGENERAL) LOOP
          SELECT NEXTVAL ('SEQ_INTRARI1_CODINTR1') INTO V_COD;

          INSERT INTO INTRARI1 (CodIntr1, CodIntr, IndexLocal, CUSTODIE, TipLinie, Umsec, An, Luna, ContServ, CONTDISCOUNT, GestAct, CodObiect, PretOrig, PU, Cant, TVA,
                                AdDim, MIFIX, CODOBIECTORIG, PARITATEORIG, COEFDISCMAJ, OBS, RestFact, NrCertif, TG, PUMaximal, PURidicata, ProcAdaos,
                                FURNAVIZSUBUNIT, DATAACHIZAVIZSUBUNIT, CODOBLIGSTORNO, CURSFACTURAAVANS, TVANEDED)
          VALUES (V_COD, V_CODDOC, V_RECINTRARI1.IndexLocal, V_RECINTRARI1.CUSTODIE, V_RECINTRARI1.TipLinie, V_RECINTRARI1.Umsec, V_RECINTRARI1.An, V_RECINTRARI1.Luna,
                  V_RECINTRARI1.ContServ, V_RECINTRARI1.CONTDISCOUNT, V_RECINTRARI1.GestAct, V_RECINTRARI1.CodObiect,
                  V_RECINTRARI1.PU / COALESCE (V_RECINTRARI1.Paritate, 1) , V_RECINTRARI1.PU / COALESCE (V_RECINTRARI1.Paritate, 1) ,
                  V_RECINTRARI1.Cant * COALESCE (V_RECINTRARI1.Paritate, 1) , V_RECINTRARI1.TVA,
                  V_RECINTRARI1.AdDim, V_RECINTRARI1.MIFIX, V_RECINTRARI1.CODOBIECTORIG, V_RECINTRARI1.PARITATEORIG, V_RECINTRARI1.COEFDISCMAJ, V_RECINTRARI1.OBS,
                  (CASE WHEN V_RECINTRARI1.TIPLINIE IN ('G', 'T') THEN V_RECINTRARI1.VALOARE ELSE V_RECINTRARI1.Cant  * V_RECINTRARI1.Paritate END),
                  V_RECINTRARI1.NrCertif, V_RECINTRARI1.TG, V_RECINTRARI1.PUMaximal, V_RECINTRARI1.PURidicata,
                  V_RECINTRARI1.ProcAdaos, V_RECINTRARI1.FURNAVIZSUBUNIT, V_RECINTRARI1.DATAACHIZAVIZSUBUNIT, V_RECINTRARI1.CODOBLIGSTORNO,
                  V_RECINTRARI1.CURSFACTURAAVANS, V_RECINTRARI1.TVANEDED);
        END LOOP;

        FOR V_RECINTRARI1 IN (SELECT * FROM TMP_INTRARI1_TVAINCAS WHERE CODGENERAL = V_RECGENERAL.CODGENERAL) LOOP
          SELECT NEXTVAL ('SEQ_INTRARI1_CODINTR1') INTO V_COD;

          INSERT INTO INTRARI1 (CodIntr1, CodIntr, IndexLocal, CUSTODIE, TipLinie, Umsec, An, Luna, ContServ, CONTDISCOUNT, GestAct, CodObiect,
                                PretOrig, PU, Cant, TVA, AdDim, MIFIX, CODOBIECTORIG, PARITATEORIG, COEFDISCMAJ, OBS, TVANEDED)
          VALUES (V_COD, V_CODDOC, V_RECINTRARI1.IndexLocal, V_RECINTRARI1.CUSTODIE, V_RECINTRARI1.TipLinie, V_RECINTRARI1.Umsec, V_RECINTRARI1.An, V_RECINTRARI1.Luna,
                  V_RECINTRARI1.ContServ, V_RECINTRARI1.CONTDISCOUNT, V_RECINTRARI1.GestAct, V_RECINTRARI1.CodObiect,
                  V_RECINTRARI1.PU / COALESCE (V_RECINTRARI1.Paritate, 1) , V_RECINTRARI1.PU / COALESCE (V_RECINTRARI1.Paritate, 1) ,
                  V_RECINTRARI1.Cant * COALESCE (V_RECINTRARI1.Paritate, 1) , V_RECINTRARI1.TVA,
                  V_RECINTRARI1.AdDim, V_RECINTRARI1.MIFIX, V_RECINTRARI1.CODOBIECTORIG, V_RECINTRARI1.PARITATEORIG,
                  V_RECINTRARI1.COEFDISCMAJ, V_RECINTRARI1.OBS, V_RECINTRARI1.TVANeded);
        END LOOP;

        IF V_RECGENERAL.TIPDOC IN (1, 2, 3, 4, 9) THEN
          UPDATE INTRARI
          SET TVADOC = (SELECT SUM (TVA) FROM INTRARI1 WHERE CODINTR = V_CODDOC)
          WHERE CODINTR = V_CODDOC;
        END IF;

        FOR V_RECIESIRI1 IN (SELECT * FROM TMP_IESIRI1 WHERE CODGENERAL = V_RECGENERAL.CODGENERAL) LOOP
          SELECT NEXTVAL ('SEQ_IESIRI1_CODIES1') INTO V_COD;

          INSERT INTO IESIRI1 (CODIES1, CODIES, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, CONTDISCOUNT, CODCRITERIU, MIFIX, GESTACT, CODOBIECT, PRETORIG,
                               PU, CANT, TVA, CONT, PROCDISC, ADDIM, RESTFACT, PUMAXIMAL, TIPLIVRARE, GARANTIE, CODOBLIGSTORNO, CURSFACTURAAVANS,
                               COEFDISCMAJ, OBS, CODOBIECTORIG, PARITATEORIG)
          VALUES (V_COD, V_CODDOC, V_RECIESIRI1.INDEXLOCAL, V_RECIESIRI1.TIPLINIE, V_RECIESIRI1.UMSEC, V_RECIESIRI1.CONTSERV, V_RECIESIRI1.CONTDISCOUNT,
                  V_RECIESIRI1.CODCRITERIU, V_RECIESIRI1.MIFIX, V_RECIESIRI1.GESTACT, V_RECIESIRI1.CODOBIECT, V_RECIESIRI1.PRETORIG,
                  V_RECIESIRI1.PU / COALESCE (V_RECIESIRI1.PARITATE, 1) , V_RECIESIRI1.CANT * COALESCE (V_RECIESIRI1.PARITATE, 1) , V_RECIESIRI1.TVA, V_RECIESIRI1.CONT,
                  V_RECIESIRI1.PROCDISC, V_RECIESIRI1.ADDIM,
                  CASE
                    WHEN V_RECIESIRI1.TIPLINIE IN ('S', '=') THEN V_RECIESIRI1.CANT * V_RECIESIRI1.PARITATE
                    WHEN V_RECIESIRI1.TIPLINIE IN ('G', 'T') THEN V_RECIESIRI1.VALOARE
                    ELSE 0
                  END ,
                  V_RECIESIRI1.PUMAXIMAL, V_RECIESIRI1.TIPLIVRARE, V_RECIESIRI1.GARANTIE,
                  V_RECIESIRI1.CODOBLIGSTORNO, V_RECIESIRI1.CURSFACTURAAVANS, V_RECIESIRI1.COEFDISCMAJ, V_RECIESIRI1.OBS,
                  V_RECIESIRI1.CODOBIECTORIG, V_RECIESIRI1.PARITATEORIG);
        END LOOP;

        FOR V_RECIESIRI1 IN (SELECT * FROM TMP_IESIRI1_TVAINCAS WHERE CODGENERAL = V_RECGENERAL.CODGENERAL) LOOP
          SELECT NEXTVAL ('SEQ_IESIRI1_CODIES1') INTO V_COD;

          INSERT INTO IESIRI1 (CODIES1, CODIES, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, CONTDISCOUNT, CODCRITERIU, MIFIX, GESTACT, CODOBIECT, PRETORIG,
                               PU, CANT, TVA, CONT, PROCDISC, ADDIM, PUMAXIMAL, TIPLIVRARE, GARANTIE, CODOBLIGSTORNO, CURSFACTURAAVANS, COEFDISCMAJ,
                               OBS, CODOBIECTORIG, PARITATEORIG)
          VALUES (V_COD, V_CODDOC, V_RECIESIRI1.INDEXLOCAL, V_RECIESIRI1.TIPLINIE, V_RECIESIRI1.UMSEC, V_RECIESIRI1.CONTSERV, V_RECIESIRI1.CONTDISCOUNT,
                  V_RECIESIRI1.CODCRITERIU, V_RECIESIRI1.MIFIX, V_RECIESIRI1.GESTACT, V_RECIESIRI1.CODOBIECT, V_RECIESIRI1.PRETORIG,
                  V_RECIESIRI1.PU / COALESCE (V_RECIESIRI1.PARITATE, 1) , V_RECIESIRI1.CANT * COALESCE (V_RECIESIRI1.PARITATE, 1) , V_RECIESIRI1.TVA, V_RECIESIRI1.CONT,
                  V_RECIESIRI1.PROCDISC, V_RECIESIRI1.ADDIM, V_RECIESIRI1.PUMAXIMAL, V_RECIESIRI1.TIPLIVRARE,
                  V_RECIESIRI1.GARANTIE, V_RECIESIRI1.CODOBLIGSTORNO, V_RECIESIRI1.CURSFACTURAAVANS, V_RECIESIRI1.COEFDISCMAJ,
                  V_RECIESIRI1.OBS, V_RECIESIRI1.CODOBIECTORIG, V_RECIESIRI1.PARITATEORIG);
        END LOOP;
      END LOOP;
    END LOOP;

    FOR V_REC_TREZOR1 IN (SELECT * FROM TMP_TREZOR1) LOOP
      SELECT NEXTVAL ('SEQ_TREZOR_CODTREZOR') INTO aCODTREZOR;

      IF V_REC_TREZOR1.CODTREZOR1 &lt; 0 THEN
        SELECT NEXTVAL ('SEQ_TREZOR1_CODTREZOR1') INTO aCODTREZOR1;
      ELSE
        aCODTREZOR1 := V_REC_TREZOR1.CODTREZOR1;
      END IF;

      IF V_REC_TREZOR1.CODTREZOR1 &lt; 0 THEN
        INSERT INTO TREZOR (CODTREZOR, TIPDOC, CODBANCA, AN, LUNA, OPERAT, BLOCAT, SUBUNITATEA)
        VALUES (aCODTREZOR, 31, V_REC_TREZOR1.CODBANCA, ANI, LUNAI, 1, 0, V_REC_TREZOR1.SUBUNITATEA);

        INSERT INTO TREZOR1 (CODTREZOR1, CODTREZOR, INDEXLOCAL, DOC, NRDOC, DATADOC, CODPART, TIPTRANZ, VALDOC, CURS, TIPDECONT, OBS, DATADECONT, AN, LUNA, INITIALIZARI, ANULAT)
        VALUES (aCODTREZOR1, aCODTREZOR, 1, V_REC_TREZOR1.DOC, V_REC_TREZOR1.NRDOC, V_REC_TREZOR1.DATADOC, aPART, V_REC_TREZOR1.TIPTRANZ,
                V_REC_TREZOR1.VALDOC, V_REC_TREZOR1.CURS, V_REC_TREZOR1.TIPDECONT, V_REC_TREZOR1.OBS, V_REC_TREZOR1.DATADECONT, ANI, LUNAI, 1, 0);
      ELSE
        UPDATE TREZOR
        SET
          TIPDOC      = 31,
          CODBANCA    = V_REC_TREZOR1.CODBANCA,
          AN          = ANI,
          LUNA        = LUNAI,
          OPERAT      = 1,
          BLOCAT      = 0,
          SUBUNITATEA = V_REC_TREZOR1.SUBUNITATEA
        WHERE
          CODTREZOR = V_REC_TREZOR1.CODTREZOR;

        UPDATE TREZOR1
        SET
          DOC        = V_REC_TREZOR1.DOC,
          NRDOC      = V_REC_TREZOR1.NRDOC,
          DATADOC    = V_REC_TREZOR1.DATADOC,
          CODPART    = V_REC_TREZOR1.CODPART,
          TIPTRANZ   = V_REC_TREZOR1.TIPTRANZ,
          VALDOC     = V_REC_TREZOR1.VALDOC,
          CURS       = V_REC_TREZOR1.CURS,
          TIPDECONT  = V_REC_TREZOR1.TIPDECONT,
          OBS        = V_REC_TREZOR1.OBS,
          DATADECONT = V_REC_TREZOR1.DATADECONT,
          AN         = ANI,
          LUNA       = LUNAI
        WHERE
          CODTREZOR1 = V_REC_TREZOR1.CODTREZOR1;
      END IF;

      UPDATE TMP_GENERAL_CECURI SET CODDOC = aCODTREZOR1 WHERE CODDOC = V_REC_TREZOR1.CODTREZOR1;
    END LOOP;

    FOR V_REC_GENERAL IN (SELECT * FROM TMP_GENERAL_CECURI WHERE SEMNIFICATIE &gt; 0) LOOP
      SELECT NEXTVAL ('SEQ_GENERAL_CODGENERAL') INTO V_CODGENERAL;

      UPDATE TMP_OBLIGPIF_ASOCIAT SET CODGENERAL = V_CODGENERAL WHERE CODGENERAL = V_REC_GENERAL.CODGENERAL;

      INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
      VALUES (V_CODGENERAL, V_REC_GENERAL.TIPDOC, V_REC_GENERAL.CODDOC, V_REC_GENERAL.MONEDA, ROUND((V_REC_GENERAL.CURS) ::numeric, 7) , V_REC_GENERAL.TVA, V_REC_GENERAL.SEMNIFICATIE);
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF_ASOCIAT WHERE SEMNIFICATIE &gt; 0) LOOP
      SELECT NEXTVAL ('SEQ_OBLIGPIF_CODOBLIGPIF') INTO aCODOBLIGPIF;

      UPDATE TMP_STINGERE SET CODSTINGATORPIF = aCODOBLIGPIF WHERE CODSTINGATORPIF = V_REC.CODOBLIGPIF;

      INSERT INTO OBLIGPIF (CODOBLIGPIF, CODGENERAL, VALOARE, REST, CODPART, ICONT, SEMNIFICATIE, CONTBANKTRANZACTIE)
      VALUES (aCODOBLIGPIF, V_REC.CODGENERAL, V_REC.VALOARE, CASE WHEN V_REC.SEMNIFICATIE IN (500, 600) THEN V_REC.VALOARE ELSE 0 END,
              V_REC.CODPART, V_REC.ICONT, V_REC.SEMNIFICATIE, V_REC.CONTBANKTRANZACTIE);

      INSERT INTO OBLIGPIFLUNA (CODOBLIGPIF, AN, LUNA, REST, RESTTVA)
      VALUES (aCODOBLIGPIF, ANI, LUNAI,
              CASE WHEN V_REC.SEMNIFICATIE IN (500, 600) THEN V_REC.VALOARE    ELSE 0    END ,
              CASE WHEN V_REC.SEMNIFICATIE &lt;&gt; 200 THEN COALESCE (V_REC.TVA, 0) ELSE NULL END);
    END LOOP;

    INSERT INTO STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
    (SELECT NEXTVAL ('SEQ_STINGERE_CODSTINGERE') , CODSTINSPIF, CODSTINGATORPIF, VALOARE FROM TMP_STINGERE);
  END IF;

  perform set_config ('PKG_GLOBALS.ANTEMP',ANI::varchar,false);
  perform set_config ('PKG_GLOBALS.LUNATEMP',LUNAI::varchar,false);

  select newAn, newluna INTO ANP, LUNAP FROM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA (ANI, LUNAI, ANP, LUNAP);
  perform set_config ('PKG_GLOBALS.ANPRECEDENT',ANP::varchar,false);
  perform set_config ('PKG_GLOBALS.LUNAPRECEDENTA',LUNAP::varchar,false);

  PERFORM PKG_NOMPART_SET_CODPART_SOLD_ANALIZAT (aPART);

  DELETE FROM NPARTSOLDLUNA WHERE AN = ANI AND LUNA = LUNAI AND CODPART = aPART;

  IF aPART &lt;&gt; current_setting ('PKG_SOLDINITIAL.OLDCODPART', true) ::numeric THEN
    DELETE FROM NPARTSOLDLUNA    WHERE AN = ANI AND LUNA = LUNAI AND CODPART = current_setting ('PKG_SOLDINITIAL.OLDCODPART', true) ::numeric;
    DELETE FROM NPARTSOLDLUNASUB WHERE AN = ANI AND LUNA = LUNAI AND CODPART = current_setting ('PKG_SOLDINITIAL.OLDCODPART', true) ::numeric;
  END IF;

  INSERT INTO NPARTSOLDLUNA (CODPARTSOLDLUNA, CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA)
  (SELECT NEXTVAL ('SEQ_NPARTSOLDLUNA_CODSOLDLUNA'), CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, current_setting ('PKG_GLOBALS.ANTEMP', true) ::numeric, current_setting ('PKG_GLOBALS.LUNATEMP', true) ::numeric
   FROM V_SOLDPART_EXT WHERE CODPART = aPART);

  DELETE FROM NPARTSOLDLUNASUB WHERE AN = ANI AND LUNA = LUNAI AND CODPART = aPART;

  INSERT INTO NPARTSOLDLUNASUB (CODPARTSOLDLUNASUB, CODPART, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA, AN, LUNA)
  (SELECT NEXTVAL ('SEQ_NPARTSOLDLUNASUB_COD') , CODPART, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA, current_setting ('PKG_GLOBALS.ANTEMP', true) ::numeric, current_setting ('PKG_GLOBALS.LUNATEMP', true) ::numeric
   FROM V_SOLDPARTSUB_EXT WHERE CODPART = aPART);

  FOR V_REC IN (SELECT O.CODOBLIGPIF, O.ICONT AS ICONTSTINS, S.CODSTINGATORPIF, OS.ICONT AS ICONTSTINGATOR
                FROM TMP_OBLIGPIF O, STINGERE S, OBLIGPIF OS
                WHERE S.CODSTINSPIF = O.CODOBLIGPIF AND S.CODSTINGATORPIF = OS.CODOBLIGPIF)
  LOOP
    IF V_REC.ICONTSTINS &lt;&gt; V_REC.ICONTSTINGATOR THEN
      UPDATE OBLIGPIF SET ICONT = V_REC.ICONTSTINS WHERE CODOBLIGPIF = V_REC.CODSTINGATORPIF;
    END IF;
  END LOOP;

  SELECT COALESCE (VOLUMTRANZC, 0) , COALESCE (VOLUMTRANZF, 0) INTO aVOLUMTRANZC, aVOLUMTRANZF FROM TMP_SOLDINI;

  IF aVOLUMTRANZF + aVOLUMTRANZC &gt; 0 THEN
    SELECT COUNT(*) INTO NR
    FROM NPART1
    WHERE
      CODPART       = aPART
      AND ANSTART   = current_setting ('PKG_GLOBALS.ANINITIAL', true) ::numeric
      AND LUNASTART = current_setting ('PKG_GLOBALS.LUNAINITIALA', true) ::numeric;

    IF NR = 0 THEN
      INSERT INTO NPART1 (CODPART1, CODPART, CODIOPART, VOLUMTRANZC, VOLUMTRANZF, ANSTART, LUNASTART)
      VALUES (NEXTVAL ('SEQ_NPART1_CODPART1') , aPART, 101, aVOLUMTRANZC, aVOLUMTRANZF, current_setting ('PKG_GLOBALS.ANINITIAL', true) ::numeric, current_setting ('PKG_GLOBALS.LUNAINITIALA', true) ::numeric);

      CALL PRC_AL_REFRESH('npart1', aPART);
    ELSE
      UPDATE NPART1
      SET VOLUMTRANZF = aVOLUMTRANZF, VOLUMTRANZC = aVOLUMTRANZC
      WHERE
        CODPART       = aPART
        AND ANSTART   = current_setting ('PKG_GLOBALS.ANINITIAL'   , true) ::numeric
        AND LUNASTART = current_setting ('PKG_GLOBALS.LUNAINITIALA', true) ::numeric;
    END IF;
  END IF;

  PERFORM NotifyModif (Operation, RecId, 'SOLDINI');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_statcon_sp_deleterecord</obj_name>
  <obj_hashval>cfe6fae1830491ca7144469d02331890</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_statcon_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_STATCON_SP_LOCKRECORD( RecId);
  DELETE FROM StatCon WHERE CodStatCon = RecId;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_categconst</obj_name>
  <obj_hashval>4255dac8993ac1bbb2ea16153300b7a2</obj_hashval>
  <obj_text>SELECT codcateg,
    indexlocal,
    denumire,
    tipcateg
   FROM martor.categconst c
  WHERE tipcateg::text = current_setting('PKG_CATEGCONST.TIPCATEGORIE'::text, true)
  ORDER BY indexlocal;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_claseop</obj_name>
  <obj_hashval>3435f3ebd9614b91921b71afdc062d5d</obj_hashval>
  <obj_text>SELECT codclaseop,
    den_claseop
   FROM martor.nclaseop;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_grupdrept_codgrupdrept</obj_name>
  <obj_hashval>c62a236be6317ecd096a2eee54d8dfeb</obj_hashval>
  <obj_text>SELECT codgrupdrept
   FROM winmadmin.grupdrept
  ORDER BY codgrupdrept;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_grupuser_codgrupuser</obj_name>
  <obj_hashval>03830fdc1a00d470d7c7ab410c131c97</obj_hashval>
  <obj_text>SELECT codgrupuser
   FROM winmadmin.grupuser
  ORDER BY codgrupuser;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>PROCEDURE</obj_type>
  <obj_name>umple_tmp_al_curslinie</obj_name>
  <obj_hashval>497a0174039cbdf16492506abdcc1c27</obj_hashval>
  <obj_text>CREATE OR REPLACE PROCEDURE umple_tmp_al_curslinie(IN aalstart numeric, IN aalstop numeric)
 LANGUAGE plpgsql
AS $procedure$
BEGIN
  --Stef 23.12.2025
  CALL create_wm_temps_flag('TMP_AL_CURSLINIE');
  EXECUTE 'TRUNCATE TABLE TMP_AL_CURSLINIE';

  INSERT INTO TMP_AL_CURSLINIE
  WITH recursive cRec (AL) AS (
    SELECT aALStart AS AL UNION ALL
    SELECT AL+1     AS AL FROM cRec WHERE al &lt; aALStop
  )
  SELECT AL, To_Number(Coalesce(VALOARE,'2'))
  FROM cRec
  LEFT JOIN (
    SELECT CL.ALSTART, CL.ALSTOP, CV.VALOARE
    FROM (
      SELECT codconst1
      FROM const1
      WHERE UPPER(SIMBOL) = 'CONTABCURSLINIE'
    ) c1
      LEFT JOIN constluna cl ON cl.codconst1    = c1.codconst1
      LEFT JOIN constval  cv ON cv.codconstluna = cl.codconstluna
  ) cv ON crec.AL BETWEEN cv.ALSTART AND cv.ALSTOP ;
END;
$procedure$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_obj_art</obj_name>
  <obj_hashval>44c5e12aed564c15d3badc669038311b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_obj_art()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Adina 22.03.2021 - sinc.Oracle
  --Adina 15 sept.2020
  RETURN
  'SELECT
  A.CODARTICOL,
  O.CODOBIECT,
  A.DEN_ARTICOL,
  A.UM,
  A.CLASA,
  A.TIPSERIE,
  A.TIPARTICOL,
  A.ARETG,
  IOA.CODIOART CONTIMPLICIT,
  P.DEN_PART AS PRODUCATOR,
  GI.CODGEST GESTIMPLICITA,
  A.CERTIFICAT,
  A.EVOLUTIEPRET,
  A.CONTSERVICIU,
  A.UM1,
  A.UM2,
  O.CODEXTERN,
  O.CODCNAS,
  O.CODINTERN,
  O.UMAMBALARE,
  O.STOCMIN,
  O.STOCMAX,
  O.RETURNABIL,
  O.TERMENPLATA,
  O.PROCADAOSNIR,
  O.PROMOTIE,
  O.BLOCAT,
  O.NEFACTURABIL,
  O.FARACMDFURN,
  NART1LUNA.CODTVA,
  NART1LUNA.CODACCIZE,
  NART1LUNA.CODACCIZEDVI,
  NART1LUNA.CODTAXA1,
  NART1LUNA.CODTAXA2,
  coalesce(TVALUNA.PROCENT, -1) AS PROCTVA,
  NARTOBJ1LUNA.TIPPRETMAX,
  NARTOBJ1LUNA.PRETMAXIMAL AS PUMAXLUNA,
  O.DENUMIRE AS DENOBIECT,
  A.RELATIEUM1,
  A.RELATIEUM2,
  PMM.LEI AS PRETVANZARE,
  PMM.VALUTA AS PRETVALUTA,
  A.D1,
  A.D2,
  A.D3,
  A.DCI,
  A.Culoare,
  O.ROTVALUTA AS ROTUNJIRE,
  coalesce(E.CODGRUPA, 0) CodGrupa,
  coalesce(E.Ind, 0) IndGrupa,
  U.TipUM CANTARIBIL,
  O.CODVAMAL,
  A.CASADEMARCAT,
  O.Produspropriu,
  A.CODEXTERNART || A.SUFIXCODEXTERN AS CODEXTERNART,
  coalesce(V_NARTATR.CODARTATR, 0)   AS CUATRIBUTE,
  coalesce(V_NATROBJ.CODATROBJ, 0)   AS ATRIBUTE_OBIECT,
  coalesce(O.TRADUCARTGENERIC, 0)    AS TRADUCARTGENERIC,
  coalesce(O.INACTIV, 0) AS INACTIV,
  CLA.SIMBOL             AS SIMBOLCLASA,
  CLA.DEN_CLASEA         AS DENUMIRECLASA,
  CLA_S.DEN_CLASEAS      AS SIMBOLCLASASTAT,
  LOC.DENUMIRE           AS DENLOCATIE,
  TRAD.DENUMIRETRAD,
  PART_IMPL.DEN_PART AS PART_IMPLICIT,
  U.DEN_UM,
  USEC.DEN_UM AS DEN_UM1,
  UALT.DEN_UM AS DEN_UM2,
  IOA.DEN_IOART,
  GI.DEN_GEST,
  O.GREUTSPECIFICA,
  AI.NEVANDABIL,
  coalesce(O.FARASTOC,0) FARASTOC,
  CLA.CODIDENT,
  A.PARITATED1,
  A.PARITATED2,
  A.PARITATED3,
  CS.SIMBOL DEN_CONTSERVICIU,
  O.MASA,
  LOC.CODLOCATIE LOCATIEIMPLICITA
  FROM NARTOBJ O
  LEFT  JOIN (SELECT CODOBIECT, MIN(CODATROBJ) AS CODATROBJ FROM NATROBJ GROUP BY CODOBIECT )   V_NATROBJ ON V_NATROBJ.CODOBIECT = O.CODOBIECT
  INNER JOIN NART             A            ON O.CODARTICOL           = A.CODARTICOL
  LEFT  JOIN (SELECT CODARTICOL, MIN(CODARTATR) AS CODARTATR FROM NARTATR GROUP BY CODARTICOL ) V_NARTATR ON V_NARTATR.CODARTICOL =A.CODARTICOL
  LEFT  JOIN NCLASEA          CLA          ON CLA.CODCLASEA          = A.CLASA
  LEFT  JOIN NCLASEAS         CLA_S        ON CLA_S.CODCLASEAS       = A.CLASASTATIST
  LEFT  JOIN num              u            ON u.codum                = a.um
  LEFT  JOIN num              uSEC         ON uSEC.codum             = a.um1
  LEFT  JOIN num              uALT         ON uALT.codum             = a.um2
  LEFT  JOIN NARTIMPLICITE    AI           ON AI.CODARTICOL          = A.CODARTICOL AND AI.CODSUBUNIT = GETSUBUNITATE()
  LEFT  JOIN NARTOBJIMP       OI           ON OI.CODOBIECT           = O.CODOBIECT  AND OI.CODSUBUNIT = GETSUBUNITATE()
  LEFT  JOIN IOART            IOA          ON CASE WHEN COALESCE(OI.CONTIMPLICIT,0) = 0     THEN AI.CONTIMPLICIT     ELSE OI.CONTIMPLICIT     END = IOA.CODIOART
  LEFT  JOIN NLOCATII         LOC          ON CASE WHEN COALESCE(OI.LOCATIEIMPLICITA,0) = 0 THEN AI.LOCATIEIMPLICITA ELSE OI.LOCATIEIMPLICITA END = LOC.CODLOCATIE
  LEFT  JOIN TMP_MANPRETM     PMM          ON PMM.CODOBIECT          = O.CODOBIECT
  LEFT  JOIN NPART            P            ON P.CODPART              = O.CODPRODUCATOR
  LEFT  JOIN TMP_NART_LUNA    NART1LUNA    ON NART1LUNA.CODARTICOL   = O.CODARTICOL
  LEFT  JOIN TMP_NTVA_LUNA    TVALUNA      ON TVALUNA.CODTVA         = NART1LUNA.CODTVA
  LEFT  JOIN TMP_NARTOBJ_LUNA NARTOBJ1LUNA ON NARTOBJ1LUNA.CODOBIECT = O.CODOBIECT
  LEFT  JOIN NECHIV           E            ON E.CODOBIECT            = O.CODOBIECT
  LEFT  JOIN NARTOBJTRAD      TRAD         ON TRAD.CODOBIECT         = O.CODOBIECT AND TRAD.CODLIMBA = current_setting(''PKG_GLOBALS.CODLIMBADENART'',true)::numeric
  LEFT  JOIN NARTCLI          CL           ON CL.CODOBIECT           = O.CODOBIECT AND coalesce(CL.IMPLICIT, 0) = 1
  LEFT  JOIN NPART            PART_IMPL    ON PART_IMPL.CODPART      = CL.CODPART
  LEFT  JOIN NGEST            GI           ON GI.CODGEST             = CASE WHEN COALESCE(OI.GESTIMPLICITA,0) = 0 THEN AI.GESTIMPLICITA ELSE OI.GESTIMPLICITA END
  LEFT  JOIN NCONT            CS           ON CS.CODCONT             = A.CONTSERVICIU ';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_alerte</obj_name>
  <obj_hashval>b6584858539ad0bba8769b185db49195</obj_hashval>
  <obj_text>SELECT a.codalerta,
    a.denumire,
    a.obs,
    o.codorar,
    o.denumire AS denumire_orar,
    o.obs AS denumire_def,
    COALESCE(a.tipalerta, 0::numeric) AS tipalerta
   FROM martor.alerte a
     LEFT JOIN martor.orar o ON o.codorar = a.codorar;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_bi_comenzi</obj_name>
  <obj_hashval>a3f064536c9db99b1be93e501d89c616</obj_hashval>
  <obj_text>SELECT xm.numepresc AS numedoc,
    c.codcomanda AS coddoc,
    c.tipdoc,
    c.prefixdoc,
    c.nrdoc,
    c.datadoc,
    mon.simbol AS moneda,
    round(c.curs, 4) AS curs,
        CASE c.tipdoc
            WHEN 44 THEN ns.den_subunit
            WHEN 43 THEN ng.den_gest
            ELSE np.den_part
        END AS partener,
    np.codpart,
    ng.codgest,
    ns.codsubunit AS cudsubunit,
    c1.codobiect,
    nobj.denumire AS denobiect,
    num1.den_um1 AS denum,
    c1.cantcomandat / num1.paritate AS cantcomandat,
    c1.cantacceptat / num1.paritate AS cantacceptat,
    c1.restacceptat / num1.paritate AS restacceptat,
    c1.pu * num1.paritate AS pu,
    c1.indexlocal AS indexdoc,
    CURRENT_DATE AS datasystem,
    c.an * 100::numeric + c.luna AS anluna
   FROM martor.comanda c
     LEFT JOIN martor.comanda1 c1 ON c.codcomanda = c1.codcomanda
     LEFT JOIN martor.machete xm ON xm.codmacheta = c.tipdoc
     LEFT JOIN martor.nmonede mon ON mon.codmoneda = c.moneda
     LEFT JOIN martor.nartobj nobj ON nobj.codobiect = c1.codobiect
     LEFT JOIN martor.nart art ON nobj.codarticol = art.codarticol
     LEFT JOIN martor.nartobjsubunit nobjs ON nobjs.codobiect = nobj.codobiect AND nobjs.subunitate =
        CASE
            WHEN c.tipdoc = 44::numeric THEN c.subunitsursa
            ELSE c.subunitatea
        END
     LEFT JOIN martor.num1 ON num1.codum1 = c1.umsec
     LEFT JOIN martor.num us ON us.codum = art.um1
     LEFT JOIN martor.npers ag ON c.agent = ag.codpers
     LEFT JOIN martor.nclasea cla ON art.clasa = cla.codclasea
     LEFT JOIN martor.nclaseas cs ON art.clasastatist = cs.codclaseas
     LEFT JOIN martor.npart np ON np.codpart = c.partener
     LEFT JOIN martor.ngest ng ON ng.codgest = c.codgest
     LEFT JOIN martor.nsubunit ns ON ns.codsubunit = c.subunitatea
     LEFT JOIN martor.nsubunit s ON s.codsubunit = c.subunitatea
  WHERE c.anulat = 0::numeric AND c.operat = 1::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_codurifiscaleretail</obj_name>
  <obj_hashval>0e85cf238b8a6422d93b260def541c7e</obj_hashval>
  <obj_text>SELECT cod,
    codpartretail,
    codfiscal,
    principal
   FROM martor.ncodfiscretail
  WHERE codpartretail = (( SELECT pkg_nompart_get_part_curent_cf.wme_result
           FROM martor.pkg_nompart_get_part_curent_cf(NULL::numeric, NULL::numeric) pkg_nompart_get_part_curent_cf(wme_result, fakeparam)))
  ORDER BY principal DESC;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_descriptori1</obj_name>
  <obj_hashval>1cdfb15b793b4c6f78cc4866612502a5</obj_hashval>
  <obj_text>SELECT d1.coddescriptor1,
    d1.coddescriptor,
    d1.valoare,
    d1.codasociat,
    d.tip,
    ( SELECT pkg_descriptori_getdenasociat.wme_result
           FROM martor.pkg_descriptori_getdenasociat(NULL::character varying, d.tip, d1.codasociat) pkg_descriptori_getdenasociat(wme_result, ptip, pcodasociat)) AS denasociat,
    d.den_descriptor,
    d.simbol
   FROM martor.descriptori d
     LEFT JOIN martor.descriptori1 d1 ON d1.coddescriptor = d.coddescriptor;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_infooferta</obj_name>
  <obj_hashval>bac469d54252e84959bdac759959d42b</obj_hashval>
  <obj_text>SELECT o1.codoferta1,
    (o.nrdoc::character varying::text || '/'::text) || to_char(o.dataoferta::timestamp with time zone, 'DD.MM.YYYY'::text) AS info
   FROM martor.oferta1 o1,
    martor.oferta o
  WHERE o.codoferta = o1.codoferta;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_iofilial</obj_name>
  <obj_hashval>1b756f4c65939c8a968ada954c6c09b1</obj_hashval>
  <obj_text>SELECT codiofilial,
    den_iofilial,
    COALESCE(( SELECT max(i1.anstart * 12::numeric + i1.lunastart) AS max
           FROM martor.iofilial1 i1
          WHERE i1.codiofilial = i.codiofilial AND (i1.anstart * 12::numeric + i1.lunastart) &lt;= (( SELECT pkg_globals_anlunalucru.wme_result
                   FROM martor.pkg_globals_anlunalucru(NULL::numeric, NULL::numeric) pkg_globals_anlunalucru(wme_result, fakeparam)))), 0::numeric) AS activ
   FROM martor.iofilial i;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_analiza</obj_name>
  <obj_hashval>c6c2e7630a9b78c154298eb9b3b7aa03</obj_hashval>
  <obj_text>SELECT codanaliza,
    den_analiza,
    idelement,
    idcentru,
    inactiv
   FROM martor.analiza
  WHERE codanaliza = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_precomenzi</obj_name>
  <obj_hashval>608495771a819ddc95cc1c6648a29fa6</obj_hashval>
  <obj_text>SELECT codprecomanda,
    tipdoc,
    anulat,
    blocat,
    operat,
    prefixdoc,
    nrdoc,
    carnetdoc,
    datadoc,
    valoare,
    an,
    luna,
    obs,
    moneda,
    subunitatea,
    userid,
    datacreare,
    inchisa,
    seriadoc,
    verificat
   FROM martor.precomanda
  WHERE codprecomanda = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_raportp</obj_name>
  <obj_hashval>ba8fbda5f213518807dda756a73578fd</obj_hashval>
  <obj_text>SELECT codraportp,
    nrdoc,
    datai,
    datas,
    pe_formatie,
    sectie,
    formatie,
    programf,
    subunitatea,
    an,
    luna,
    userid,
    datacreare,
    intreruperi,
    codcentru,
    prefixdoc,
    carnetdoc,
    seriadoc,
    schimb
   FROM martor.raportp
  WHERE codraportp = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lst_locatiipart</obj_name>
  <obj_hashval>e220c93ae79a6ed31dcc0d32f9c5df47</obj_hashval>
  <obj_text>SELECT a.codagenda,
    p.den_part,
    a.obs
   FROM martor.nagenda a
     JOIN martor.npart p ON p.codpart = a.codpart
  WHERE a.tip = 0::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_menudate</obj_name>
  <obj_hashval>8cbef82c7976e79eb56bfacd85bf9c39</obj_hashval>
  <obj_text>SELECT codmenudate,
    den_menu,
    userid,
    nrbuton
   FROM martor.menudate m
  WHERE userid::text = current_setting('PKG_GLOBALS.USERID'::text, true);</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_mfclasif</obj_name>
  <obj_hashval>1c0b927d07efd5615b1caa7b8392b679</obj_hashval>
  <obj_text>SELECT codclasif,
    denumire,
    simbol,
    durata,
    durataf,
    duratag
   FROM martor.mfclasif;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_oferte</obj_name>
  <obj_hashval>5e7adf06f621b03e5e6883572586726e</obj_hashval>
  <obj_text>SELECT o.codoferta,
    o.tipdoc,
    o.anulat,
    o.blocat,
    o.operat,
    c.serie,
    o.nrdoc,
    o.datastart,
    o.dataend,
    o.partener,
    o.an,
    o.luna,
    o.obs,
    o.moneda,
    o.codlocatie,
    o.subunitatea,
    o.codfiscal,
    o.userid,
    o.datacreare,
        CASE
            WHEN o.tipbeneficiar = 1::numeric THEN 'DA'::text
            ELSE 'NU'::text
        END AS pe_clasa,
    COALESCE(p.den_part, cp.den_clasep, '...'::character varying) AS den_part,
    m.den_moneda,
    l.den_localit,
    s.den_subunit AS subunitatedoc,
    ag.obs AS sediu,
    o.toatesubunit,
    ( SELECT numeprenume.wme_result
           FROM martor.numeprenume(NULL::character varying, u.nume, u.prenume) numeprenume(wme_result, pnume, pprenume)) AS utilizator,
    ( SELECT sum(COALESCE(o1.cantmin * o1.pret, 0::numeric)) AS sum
           FROM martor.oferta1 o1
          WHERE o1.codoferta = o.codoferta) AS valoare
   FROM martor.oferta o
     LEFT JOIN martor.npart p ON COALESCE(o.partener, 0::numeric) = p.codpart AND COALESCE(o.tipbeneficiar, 0::numeric) = 0::numeric
     LEFT JOIN martor.nclasep cp ON COALESCE(o.codclasep, 0::numeric) = cp.codclasep AND COALESCE(o.tipbeneficiar, 0::numeric) = 1::numeric
     LEFT JOIN martor.nagenda ag ON COALESCE(o.codlocatie, 0::numeric) = ag.codagenda
     LEFT JOIN martor.nlocalit l ON COALESCE(ag.codlocalit, 0::numeric) = l.codlocalit
     LEFT JOIN martor.nmonede m ON COALESCE(o.moneda, 0::numeric) = m.codmoneda
     LEFT JOIN martor.nsubunit s ON s.codsubunit = o.subunitatea
     LEFT JOIN martor.doccarnete c ON c.codcarnet = o.carnetdoc
     LEFT JOIN martor.npers u ON u.logonname = o.userid
  WHERE o.tipdoc = (( SELECT pkg_globals_gettipoferta.wme_result
           FROM martor.pkg_globals_gettipoferta(NULL::numeric, NULL::numeric) pkg_globals_gettipoferta(wme_result, fakeparam))) AND (COALESCE(o.toatesubunit, 0::numeric) = 1::numeric OR COALESCE(o.subunitatea, 1::numeric) =
        CASE
            WHEN (( SELECT pkg_globals_getsubunitate.wme_result
               FROM martor.pkg_globals_getsubunitate(NULL::numeric, NULL::numeric) pkg_globals_getsubunitate(wme_result, fakeparam))) = 1::numeric THEN COALESCE(o.subunitatea, 1::numeric)
            ELSE ( SELECT pkg_globals_getsubunitate.wme_result
               FROM martor.pkg_globals_getsubunitate(NULL::numeric, NULL::numeric) pkg_globals_getsubunitate(wme_result, fakeparam))
        END) AND o.datastart &lt;= last_day(to_date((('01.'::text || (( SELECT pkg_globals_getlunalucru.wme_result
           FROM martor.pkg_globals_getlunalucru(NULL::numeric, NULL::numeric) pkg_globals_getlunalucru(wme_result, fakeparam)))) || '.'::text) || (( SELECT pkg_globals_getanlucru.wme_result
           FROM martor.pkg_globals_getanlucru(NULL::numeric, NULL::numeric) pkg_globals_getanlucru(wme_result, fakeparam))), 'DD.MM.YYYY'::text)) AND o.dataend &gt;= to_date((('01.'::text || (( SELECT pkg_globals_getlunalucru.wme_result
           FROM martor.pkg_globals_getlunalucru(NULL::numeric, NULL::numeric) pkg_globals_getlunalucru(wme_result, fakeparam)))) || '.'::text) || (( SELECT pkg_globals_getanlucru.wme_result
           FROM martor.pkg_globals_getanlucru(NULL::numeric, NULL::numeric) pkg_globals_getanlucru(wme_result, fakeparam))), 'DD.MM.YYYY'::text);</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_sold_ini</obj_name>
  <obj_hashval>4fc8c168b53325cd58be24b3165fde0c</obj_hashval>
  <obj_text>SELECT i.codsoldini,
    i.codpart,
    p.den_part,
    ( SELECT sum(ns.soldlei) AS sum
           FROM martor.npartsoldluna ns
          WHERE ns.codpart = i.codpart AND ns.an = (( SELECT pkg_globals_getantemp.wme_result
                   FROM martor.pkg_globals_getantemp(NULL::numeric, NULL::numeric) pkg_globals_getantemp(wme_result, fakeparam))) AND ns.luna = (( SELECT pkg_globals_getlunatemp.wme_result
                   FROM martor.pkg_globals_getlunatemp(NULL::numeric, NULL::numeric) pkg_globals_getlunatemp(wme_result, fakeparam)))) AS soldreal
   FROM martor.soldini i
     LEFT JOIN martor.npart p ON i.codpart = p.codpart;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpartsub_ifrs</obj_name>
  <obj_hashval>3b02016740d6458a6537d7d39b96ebd4</obj_hashval>
  <obj_text>SELECT codpart,
    icont,
    subunitatea,
    sum(sold_ifrs) AS sold_ifrs
   FROM ( SELECT npartsoldlunasub.codpart,
            npartsoldlunasub.icont,
            npartsoldlunasub.subunitatea,
            sum(npartsoldlunasub.sold_ifrs) AS sold_ifrs
           FROM martor.npartsoldlunasub
          WHERE npartsoldlunasub.an = current_setting('PKG_GLOBALS.ANPRECEDENT'::text, true)::numeric AND npartsoldlunasub.luna = current_setting('PKG_GLOBALS.LUNAPRECEDENTA'::text, true)::numeric AND npartsoldlunasub.codmoneda = 0::numeric AND COALESCE(npartsoldlunasub.sold_ifrs, 0::numeric) &lt;&gt; 0::numeric
          GROUP BY npartsoldlunasub.codpart, npartsoldlunasub.icont, npartsoldlunasub.subunitatea
        UNION ALL
         SELECT a_pg.codpart,
            a_pg.icont,
            a_pg.subunitatea,
            sum(a_pg.soldlei) AS sold_ifrs
           FROM ( SELECT o.codpart,
                    o.icont,
                    n.subunitatea,
                        CASE
                            WHEN (o.semnificatie = ANY (ARRAY[1250::numeric, 1251::numeric])) AND (o.icont = ANY (ARRAY[2::numeric, 5::numeric, 6::numeric, 8::numeric, 9::numeric, 15::numeric, 17::numeric])) THEN - o.valoare
                            WHEN (o.semnificatie = ANY (ARRAY[1250::numeric, 1251::numeric])) AND (o.icont = ANY (ARRAY[3::numeric, 4::numeric, 7::numeric, 10::numeric, 11::numeric, 12::numeric, 13::numeric, 14::numeric])) THEN o.valoare
                            ELSE NULL::numeric
                        END AS soldlei
                   FROM martor.obligpif o,
                    martor.general g,
                    martor.nc1 n1,
                    martor.nc n
                  WHERE (o.semnificatie = ANY (ARRAY[1250::numeric, 1251::numeric])) AND g.codgeneral = o.codgeneral AND n1.codnc1 = g.coddoc AND n.codnc = n1.codnc AND g.moneda = 0::numeric AND n.an = current_setting('PKG_GLOBALS.ANTEMP'::text, true)::numeric AND n.luna = current_setting('PKG_GLOBALS.LUNATEMP'::text, true)::numeric) a_pg
          GROUP BY a_pg.codpart, a_pg.icont, a_pg.subunitatea) b_pg
  GROUP BY codpart, icont, subunitatea;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_tipsedii</obj_name>
  <obj_hashval>c81cb3c768ea18bfa51faabcb5e9845a</obj_hashval>
  <obj_text>SELECT codtipsediu,
    denumire,
    iclasa
   FROM martor.ntipsedii;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_bi_obligatii</obj_name>
  <obj_hashval>82420d7ff8b94c3c64c4a4bc3256a267</obj_hashval>
  <obj_text>SELECT subs.coddoc,
    subs.tipdoc,
    subs.numedoc,
    subs.valdoc,
    subs.nrdoc,
    subs.datadoc,
    subs.codoblig,
    subs.tipoblig,
    subs.simboblig,
    subs.obsoblig,
    subs.valoblig,
    subs.tvaoblig,
    subs.termenoblig,
    subs.moneda,
    subs.curs,
    subs.codpart,
    subs.partener,
    subs.coddocstingere,
    subs.tipdocstingere,
    subs.numedocstingere,
    subs.valstingere,
    subs.tvastingere,
    subs.codstingere,
    subs.tipstingere,
    subs.simbstingere,
    subs.obsstingere,
    subs.datastingere,
    subs.datadecont,
    subs.datasystem,
    subs.anluna,
    subs.agentdoc,
    subs.agentsting,
    subs.anlunasting,
    subs.cursorig,
    conts.simbol AS simbcontsting,
    conts.den_cont AS dencontsting,
    contd.simbol AS simbcontdoc,
    contd.den_cont AS dencontdoc,
    subs.subunitate_doc
   FROM ( SELECT g.coddoc,
            g.tipdoc,
            xm.numepresc AS numedoc,
            COALESCE(intr.valdoc, ies.valdoc, t1.valdoc, nc1.valoare, o.valoare) AS valdoc,
            COALESCE(intr.nrdoc, ies.nrdoc, c.nrdoc, t1.nrdoc, nc.nrdoc)::character varying AS nrdoc,
            COALESCE(intr.datadoc::timestamp without time zone, ies.datadoc, c.datadoc::timestamp without time zone, t1.datadoc::timestamp without time zone, nc.datadoc::timestamp without time zone) AS datadoc,
            o.codobligpif AS codoblig,
            o.semnificatie AS tipoblig,
            xs.simb AS simboblig,
            xs.obs AS obsoblig,
            xs.semn::numeric * (o.valoare - xs.tva::numeric * COALESCE(g.tva, 0::numeric)) AS valoblig,
            (xs.semn * xs.tva)::numeric * COALESCE(g.tva, 0::numeric) AS tvaoblig,
                CASE
                    WHEN o.termen IS NULL THEN COALESCE(intr.datadoc::timestamp without time zone, ies.datadoc, c.datadoc::timestamp without time zone, t1.datadoc::timestamp without time zone, nc.datadoc::timestamp without time zone)::date + COALESCE(p.scadentav, 0::numeric)::integer
                    WHEN o.termen &gt;= COALESCE(intr.datadoc::timestamp without time zone, ies.datadoc, c.datadoc::timestamp without time zone, t1.datadoc::timestamp without time zone, nc.datadoc::timestamp without time zone) THEN o.termen
                    ELSE COALESCE(intr.datadoc::timestamp without time zone, ies.datadoc, c.datadoc::timestamp without time zone, t1.datadoc::timestamp without time zone, nc.datadoc::timestamp without time zone)::date + COALESCE(p.scadentav, 0::numeric)::integer
                END AS termenoblig,
            m.simbol AS moneda,
            COALESCE(reg.curs, g.curs, 1::numeric) AS curs,
            o.codpart,
            p.den_part AS partener,
            gs.coddoc AS coddocstingere,
            gs.tipdoc AS tipdocstingere,
            xms.numepresc AS numedocstingere,
            xss.semn::numeric * (os.valoare - xss.tva::numeric * COALESCE(gs.tva, 0::numeric)) AS valstingere,
            (xss.semn * xss.tva)::numeric * COALESCE(gs.tva, 0::numeric) AS tvastingere,
            os.codobligpif AS codstingere,
            os.semnificatie AS tipstingere,
            xss.simb AS simbstingere,
            xss.obs AS obsstingere,
            COALESCE(intrs.datadoc::timestamp without time zone, iess.datadoc, cs.datadoc::timestamp without time zone, t1s.datadoc::timestamp without time zone) AS datastingere,
                CASE
                    WHEN gs.tipdoc = 31::numeric THEN ( SELECT
                            CASE
                                WHEN t1x.datadoc IS NULL THEN COALESCE(intrs.datadoc::timestamp without time zone, iess.datadoc, cs.datadoc::timestamp without time zone, t1s.datadoc::timestamp without time zone)
                                WHEN COALESCE(intrs.datadoc::timestamp without time zone, iess.datadoc, cs.datadoc::timestamp without time zone, t1s.datadoc::timestamp without time zone) IS NULL THEN t1x.datadoc::timestamp without time zone
                                ELSE GREATEST(t1x.datadoc::timestamp without time zone, COALESCE(intrs.datadoc::timestamp without time zone, iess.datadoc, cs.datadoc::timestamp without time zone, t1s.datadoc::timestamp without time zone))
                            END AS "greatest"
                       FROM martor.general gc
                         JOIN martor.obligpif oc ON oc.codgeneral = gc.codgeneral
                         JOIN martor.stingere sc ON sc.codstinspif = oc.codobligpif
                         JOIN martor.obligpif osc ON osc.codobligpif = sc.codstingatorpif
                         JOIN martor.general gsc ON gsc.codgeneral = osc.codgeneral
                         JOIN martor.trezor1 t1x ON t1x.codtrezor1 = gsc.coddoc
                      WHERE (gc.semnificatie = ANY (ARRAY[500::numeric, 600::numeric])) AND gc.tipdoc = 31::numeric AND gc.coddoc = gs.coddoc)
                    ELSE COALESCE(intrs.datadoc::timestamp without time zone, iess.datadoc, cs.datadoc::timestamp without time zone, t1s.datadoc::timestamp without time zone)
                END AS datadecont,
            CURRENT_DATE AS datasystem,
            COALESCE(intr.an * 100::numeric + intr.luna, ies.an * 100::numeric + ies.luna, c.an * 100::numeric + c.luna, t.an * 100::numeric + t.luna, nc.an * 100::numeric + nc.luna) AS anluna,
            martor.numeprenume(agd.nume, agd.prenume) AS agentdoc,
            martor.numeprenume(ags.nume, ags.prenume) AS agentsting,
            COALESCE(intrs.an * 100::numeric + intrs.luna, iess.an * 100::numeric + iess.luna, cs.an * 100::numeric + cs.luna, ts.an * 100::numeric + ts.luna) AS anlunasting,
            COALESCE(g.curs, 1::numeric) AS cursorig,
            sub.den_subunit AS subunitate_doc,
            martor.pkg_list_base_utils_icont_codcont(o.icont, o.codpart, COALESCE(intr.an * 12::numeric + intr.luna, ies.an * 12::numeric + ies.luna, c.an * 12::numeric + c.luna, t.an * 12::numeric + t.luna, nc.an * 12::numeric + nc.luna), o.semnificatie) AS codcontd,
            martor.pkg_list_base_utils_icont_codcont(os.icont, os.codpart, COALESCE(intrs.an * 12::numeric + intrs.luna, iess.an * 12::numeric + iess.luna, cs.an * 12::numeric + cs.luna, ts.an * 12::numeric + ts.luna), os.semnificatie) AS codconts
           FROM martor.obligpif o
             JOIN martor.v_semnificatii xs ON xs.semnificatie::numeric = o.semnificatie AND
                CASE xs.icont
                    WHEN 0 THEN 1
                    WHEN o.icont THEN 1
                    ELSE 0
                END = 1
             JOIN martor.general g ON g.codgeneral = o.codgeneral
             LEFT JOIN martor.nmonede m ON m.codmoneda = COALESCE(g.moneda, 0::numeric)
             LEFT JOIN martor.machete xm ON xm.codmacheta = g.tipdoc
             LEFT JOIN martor.dvi ON g.coddoc = dvi.coddvi AND o.semnificatie = 130::numeric
             LEFT JOIN martor.intrari intr ON intr.codintr = COALESCE(dvi.codintr, g.coddoc) AND intr.tipdoc = g.tipdoc
             LEFT JOIN martor.iesiri ies ON ies.codies = g.coddoc AND ies.tipdoc = g.tipdoc
             LEFT JOIN martor.compens c ON c.codcompens = g.coddoc AND g.tipdoc = 28::numeric AND (o.semnificatie = ANY (ARRAY[1301::numeric, 1351::numeric, 1303::numeric]))
             LEFT JOIN martor.trezor1 t1 ON t1.codtrezor1 = g.coddoc AND (g.tipdoc = ANY (ARRAY[29::numeric, 30::numeric, 31::numeric, 33::numeric])) AND (g.semnificatie = ANY (ARRAY[310::numeric, 410::numeric, 330::numeric, 430::numeric]))
             LEFT JOIN martor.trezor t ON t.codtrezor = t1.codtrezor
             LEFT JOIN martor.nc1 ON nc1.codnc1 = g.coddoc AND g.tipdoc = 35::numeric AND (o.semnificatie = ANY (ARRAY[1200::numeric, 1201::numeric]))
             LEFT JOIN martor.nc ON nc.codnc = nc1.codnc
             LEFT JOIN martor.nsubunit sub ON sub.codsubunit = COALESCE(intr.subunitatea, ies.subunitatea, t.subunitatea, nc.subunitatea)
             LEFT JOIN martor.npart p ON p.codpart = o.codpart
             LEFT JOIN ( SELECT x.codgeneral,
                    x.curs
                   FROM ( SELECT r1.codgeneral,
                            r.curs,
                            row_number() OVER (PARTITION BY r1.codgeneral ORDER BY r.datadoc DESC) AS rnord
                           FROM martor.reg r
                             JOIN martor.reg1 r1 ON r1.codreg = r.codreg
                          WHERE r.tipreg = 46::numeric) x
                  WHERE x.rnord = 1) reg ON reg.codgeneral = g.codgeneral
             LEFT JOIN martor.stingere s ON s.codstinspif = o.codobligpif
             LEFT JOIN martor.obligpif os ON os.codobligpif = s.codstingatorpif
             LEFT JOIN martor.general gs ON gs.codgeneral = os.codgeneral
             LEFT JOIN martor.v_semnificatii xss ON xss.semnificatie::numeric = os.semnificatie AND
                CASE xss.icont
                    WHEN 0 THEN 1
                    WHEN os.icont THEN 1
                    ELSE 0
                END = 1
             LEFT JOIN martor.machete xms ON xms.codmacheta = gs.tipdoc
             LEFT JOIN martor.intrari intrs ON intrs.codintr = gs.coddoc AND intrs.tipdoc = gs.tipdoc
             LEFT JOIN martor.iesiri iess ON iess.codies = gs.coddoc AND iess.tipdoc = gs.tipdoc
             LEFT JOIN martor.compens cs ON cs.codcompens = gs.coddoc AND gs.tipdoc = 28::numeric
             LEFT JOIN martor.trezor1 t1s ON t1s.codtrezor1 = gs.coddoc AND (gs.tipdoc = ANY (ARRAY[29::numeric, 30::numeric, 31::numeric, 33::numeric]))
             LEFT JOIN martor.trezor ts ON ts.codtrezor = t1s.codtrezor
             LEFT JOIN martor.npers agd ON agd.codpers = COALESCE(intr.agent, ies.agent, c.agent, t1.agent, t.agent)
             LEFT JOIN martor.npers ags ON ags.codpers = COALESCE(intrs.agent, iess.agent, cs.agent, t1s.agent, ts.agent)
             LEFT JOIN martor.ncont contd_1 ON contd_1.codcont = martor.pkg_list_base_utils_icont_codcont(o.icont, o.codpart, COALESCE(intr.an * 12::numeric + intr.luna, ies.an * 12::numeric + ies.luna, c.an * 12::numeric + c.luna, t.an * 12::numeric + t.luna, nc.an * 12::numeric + nc.luna), o.semnificatie)
             LEFT JOIN martor.ncont conts_1 ON conts_1.codcont = martor.pkg_list_base_utils_icont_codcont(os.icont, os.codpart, COALESCE(intrs.an * 12::numeric + intrs.luna, iess.an * 12::numeric + iess.luna, cs.an * 12::numeric + cs.luna, ts.an * 12::numeric + ts.luna), os.semnificatie)
          WHERE (o.semnificatie = ANY (ARRAY[100::numeric, 110::numeric, 120::numeric, 130::numeric, 200::numeric, 210::numeric, 220::numeric, 310::numeric, 330::numeric, 410::numeric, 430::numeric, 1200::numeric, 1201::numeric, 1301::numeric, 1303::numeric, 1351::numeric])) AND (g.tipdoc &lt;&gt; ALL (ARRAY[2::numeric, 20::numeric])) AND COALESCE(intrs.an, iess.an, cs.an, ts.an) = 2019::numeric) subs
     LEFT JOIN martor.ncont contd ON contd.codcont = subs.codcontd
     LEFT JOIN martor.ncont conts ON conts.codcont = subs.codconts;</obj_text>
  <obj_nivel>1</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_umambalare</obj_name>
  <obj_hashval>3420e5b49003e3296e06426c987cc47b</obj_hashval>
  <obj_text>SELECT 0 AS codum1,
    0 AS codum,
    0 AS secundara,
    '... nedefinita ...'::character varying AS den_um1,
    1 AS paritate,
    0 AS zecimale
UNION ALL
 SELECT v_umsec.codum1,
    v_umsec.codum,
    v_umsec.secundara,
    v_umsec.den_um1,
    v_umsec.paritate,
    v_umsec.zecimale
   FROM martor.v_umsec;</obj_text>
  <obj_nivel>1</obj_nivel>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_nasig_sp_postrecords</obj_name>
  <obj_hashval>0566b6887c18a3a1c7a4379f81df59f1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_nasig_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
 DECLARE
 V_REC RECORD;
  aDoc varchar;
  vCod numeric;
BEGIN
  --Florin 27.10.2022 - returns record
  --Florin 30.03.2022 - PostLog
  --Florin 02.03.2022
  PERFORM pkg_sal_nasig_setct_monitor('MON_5');
  SELECT tip
  INTO aDoc
  FROM TMP_SAL_NASIG;
  IF  Operation = 0
  THEN
  SELECT codnasig
  INTO RECID
  FROM TMP_SAL_NASIG;
  IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true)::numeric, current_setting('PKG_SAL_NASIG.CT_MONITOR', true)))
  THEN
    PERFORM WINMADMIN.pkg_userfirme_postlogcucommit('SAL_NASIG', current_setting ('PKG_GLOBALS.USERNAME', true) , 'M', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
  END IF;
  UPDATE SAL_NASIG
  SET
  (codnasig, tip, codasig, caracter, intrerupere) = (
  SELECT codnasig, tip, codasig, caracter, intrerupere
  FROM TMP_SAL_NASIG
  )
  WHERE
   codnasig = RecId
  ;
  DELETE FROM SAL_NASIG3
  WHERE
  (  codnasig0 IN (
  SELECT nasig0.codnasig0
  FROM SAL_NASIG0 nasig0
  WHERE
     nasig0.codnasig = RecId
  ) and codnasig3 NOT IN (
  SELECT codnasig3
  FROM TMP_SAL_NASIG3
  ))  OR (  codnasig0 IN (
  SELECT nasig0.codnasig0
  FROM SAL_NASIG0 nasig0
  LEFT JOIN TMP_SAL_NASIG0 tns0 ON  tns0.codnasig0 = nasig0.codnasig0
  WHERE
     nasig0.codnasig = RecId and tns0.codnasig0 IS NULL
  )) ;
  DELETE FROM SAL_NASIG2
  WHERE
  (  codnasig0 IN (
  SELECT nasig0.codnasig0
  FROM SAL_NASIG0 nasig0
  WHERE
     nasig0.codnasig = RecId
  ) and codnasig2 NOT IN (
  SELECT codnasig2
  FROM TMP_SAL_NASIG2
  ))  OR (  codnasig0 IN (
  SELECT nasig0.codnasig0
  FROM SAL_NASIG0 nasig0
  LEFT JOIN TMP_SAL_NASIG0 tns0 ON  tns0.codnasig0 = nasig0.codnasig0
  WHERE
     nasig0.codnasig = RecId and tns0.codnasig0 IS NULL
  )) ;
  DELETE FROM SAL_NASIG1
  WHERE
  (  codnasig0 IN (
  SELECT nasig0.codnasig0
  FROM SAL_NASIG0 nasig0
  WHERE
     nasig0.codnasig = RecId
  ) and codnasig1 NOT IN (
  SELECT codnasig1
  FROM TMP_SAL_NASIG1
  ))  OR (  codnasig0 IN (
  SELECT nasig0.codnasig0
  FROM SAL_NASIG0 nasig0
  LEFT JOIN TMP_SAL_NASIG0 tns0 ON  tns0.codnasig0 = nasig0.codnasig0
  WHERE
     nasig0.codnasig = RecId and tns0.codnasig0 IS NULL
  )) ;
  DELETE FROM SAL_NASIG0
  WHERE
   codnasig = RecId and codnasig0 NOT IN (
  SELECT codnasig0
  FROM TMP_SAL_NASIG0
  );
  UPDATE SAL_NASIG0 asg0
  SET
  (codnasig0, codnasig, Bazacalcul, Angajator, Cont1, Asigurare, Cont2, ContribSalMinEcFirma, ContribSalMinEcCAS, Penalizare, Impozit, CrestereCopil, SuspendareCM, Buget, NoAngajat, NoAngajator, ZilePlataFirma, NeavizatCAS, Plafonare, NoDeducere, Constructii, ANSTART, LUNASTART, ALSTART, ALSTOP) = (
  SELECT codnasig0, codnasig, Bazacalcul, Angajator, Cont1, Asigurare, Cont2, ContribSalMinEcFirma, ContribSalMinEcCAS, Penalizare, Impozit, CrestereCopil, SuspendareCM, Buget, NoAngajat, NoAngajator, ZilePlataFirma, NeavizatCAS, Plafonare, NoDeducere, Constructii, ANSTART, LUNASTART, ALSTART, ALSTOP
  FROM TMP_SAL_NASIG0 tnc
  WHERE
     tnc.codnasig0 &gt; 0 and  tnc.codnasig0 = asg0.codnasig0
  )
  WHERE
   asg0.codnasig = RecId
  ;
  FOR v_rec IN
  (
  SELECT *
  FROM TMP_SAL_NASIG0
  WHERE
     codnasig0 &lt; 0
  )
  LOOP
  SELECT NEXTVAL('SEQ_SAL_NASIG0_CODNASIG0')
  INTO vcod;
  UPDATE TMP_SAL_NASIG1
  SET
  codnasig0 = vcod
  WHERE
   codnasig0 = v_rec.codnasig0
  ;
  UPDATE TMP_SAL_NASIG2
  SET
  codnasig0 = vcod
  WHERE
   codnasig0 = v_rec.codnasig0
  ;
  UPDATE TMP_SAL_NASIG3
  SET
  codnasig0 = vcod
  WHERE
   codnasig0 = v_rec.codnasig0
  ;
  INSERT INTO SAL_NASIG0
  (
  codnasig0, codnasig, Bazacalcul, Angajator, Cont1, Asigurare, Cont2, ContribSalMinEcFirma, ContribSalMinEcCAS, Penalizare, Impozit, CrestereCopil, SuspendareCM, Buget, NoAngajat, NoAngajator, ZilePlataFirma, NeavizatCAS, Plafonare, NoDeducere, Constructii, ANSTART, LUNASTART, ALSTART, ALSTOP
  )
  VALUES
  (
  vcod, RecId, v_rec.Bazacalcul, v_rec.Angajator, v_rec.Cont1, v_rec.Asigurare, v_rec.Cont2, v_rec.ContribSalMinEcFirma, v_rec.ContribSalMinEcCAS, v_rec.Penalizare, v_rec.Impozit, v_rec.CrestereCopil, v_rec.SuspendareCM, v_rec.Buget, v_rec.NoAngajat, v_rec.NoAngajator, v_rec.ZilePlataFirma, v_rec.NeavizatCAS, v_rec.Plafonare, v_rec.NoDeducere, v_rec.Constructii, v_rec.ANSTART, v_rec.LUNASTART, v_rec.ALSTART, v_rec.ALSTOP
  );
  END LOOP;
  UPDATE SAL_NASIG1 asg1
  SET
  (codnasig1, codnasig0, modcalcul, conditionare, umv) = (
  SELECT codnasig1, codnasig0, modcalcul, conditionare, umv
  FROM TMP_SAL_NASIG1 tasg
  WHERE
     tasg.codnasig1 &gt; 0 and  tasg.codnasig1 = asg1.codnasig1
  )
  WHERE
  asg1.codnasig1 IN (
  SELECT ti.codnasig1
  FROM TMP_SAL_NASIG1 ti
  WHERE
     ti.codnasig1 &gt; 0
  )
  ;
  FOR v_rec IN
  (
  SELECT *
  FROM TMP_SAL_NASIG1
  WHERE
     codnasig1 &lt; 0
  )
  LOOP
  SELECT NEXTVAL('SEQ_SAL_NASIG1_CODNASIG1')
  INTO vcod;
  UPDATE TMP_SAL_NASIG2
  SET
  codnasig1 = vcod
  WHERE
   codnasig1 = v_rec.codnasig1
  ;
  INSERT INTO SAL_NASIG1
  (
  codnasig1, codnasig0, modcalcul, conditionare, umv
  )
  VALUES
  (
  vcod, v_rec.codnasig0, v_rec.modcalcul, v_rec.conditionare, v_rec.umv
  );
  END LOOP;
  UPDATE SAL_NASIG2 asg2
  SET
  (codnasig2, codnasig0, codnasig1, cuantum, liminf, limsup) = (
  SELECT codnasig2, codnasig0, codnasig1, cuantum, liminf, limsup
  FROM TMP_SAL_NASIG2 tasg
  WHERE
     tasg.codnasig2 &gt; 0 and  tasg.codnasig2 = asg2.codnasig2
  )
  WHERE
  asg2.codnasig2 IN (
  SELECT ti.codnasig2
  FROM TMP_SAL_NASIG2 ti
  WHERE
     ti.codnasig2 &gt; 0
  )
  ;
  INSERT INTO SAL_NASIG2
  (
  codnasig2, codnasig0, codnasig1, cuantum, liminf, limsup
  )
  (
  SELECT NEXTVAL('SEQ_SAL_NASIG2_CODNASIG2'), codnasig0, codnasig1, cuantum, liminf, limsup
  FROM TMP_SAL_NASIG2 tnc
  WHERE
     tnc.codnasig2 &lt; 0
  );
  UPDATE SAL_NASIG3 asg3
  SET
  (codnasig3, codnasig0, tip, elemcalcul, multiplicare, codcont, contributie) = (
  SELECT codnasig3, codnasig0, tip, elemcalcul, multiplicare, codcont, contributie
  FROM TMP_SAL_NASIG3 tasg
  WHERE
     tasg.codnasig3 &gt; 0 and  tasg.codnasig3 = asg3.codnasig3
  )
  WHERE
  asg3.codnasig3 IN (
  SELECT ti.codnasig3
  FROM TMP_SAL_NASIG3 ti
  WHERE
     ti.codnasig3 &gt; 0
  )
  ;
  INSERT INTO SAL_NASIG3
  (
  codnasig3, codnasig0, tip, elemcalcul, multiplicare, codcont, contributie
  )
  (
  SELECT NEXTVAL('SEQ_SAL_NASIG3_CODNASIG3'), codnasig0, tip, elemcalcul, multiplicare, codcont, contributie
  FROM TMP_SAL_NASIG3 tnc
  WHERE
     tnc.codnasig3 &lt; 0
  );
  ELSE
    IF (SELECT wme_result FROM WINMADMIN.PKG_USERFIRME_ValidPostLog(NULL, current_setting ('PKG_GLOBALS.USERID', true)::numeric, current_setting('PKG_SAL_NASIG.CT_MONITOR', true)))
    THEN
      PERFORM WINMADMIN.pkg_userfirme_postlogcucommit('SAL_NASIG', current_setting ('PKG_GLOBALS.USERNAME', true) , 'M', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
    END IF;
  SELECT NEXTVAL('SEQ_SAL_NASIG_CODNASIG')
  INTO RecId;
  INSERT INTO SAL_NASIG
  (
  codnasig, tip, codasig, caracter, intrerupere
  )
  (
  SELECT RecId, tip, codasig, caracter, intrerupere
  FROM TMP_SAL_NASIG
  );
  FOR v_rec IN
  (
  SELECT *
  FROM TMP_SAL_NASIG0
  )
  LOOP
  SELECT NEXTVAL('SEQ_SAL_NASIG0_CODNASIG0')
  INTO vcod;
  UPDATE TMP_SAL_NASIG1
  SET
  codnasig0 = vcod
  WHERE
   codnasig0 = v_rec.codnasig0
  ;
  UPDATE TMP_SAL_NASIG2
  SET
  codnasig0 = vcod
  WHERE
   codnasig0 = v_rec.codnasig0
  ;
  UPDATE TMP_SAL_NASIG3
  SET
  codnasig0 = vcod
  WHERE
   codnasig0 = v_rec.codnasig0
  ;
  INSERT INTO SAL_NASIG0
  (
  codnasig0, codnasig, Bazacalcul, Angajator, Cont1, Asigurare, Cont2, ContribSalMinEcFirma, ContribSalMinEcCAS, Penalizare, Impozit, CrestereCopil, SuspendareCM, Buget, NoAngajat, NoAngajator, ZilePlataFirma, NeavizatCAS, Plafonare, NoDeducere, Constructii, ANSTART, LUNASTART, ALSTART, ALSTOP
  )
  VALUES
  (
  vcod, RecId, v_rec.Bazacalcul, v_rec.Angajator, v_rec.Cont1, v_rec.Asigurare, v_rec.Cont2, v_rec.ContribSalMinEcFirma, v_rec.ContribSalMinEcCAS, v_rec.Penalizare, v_rec.Impozit, v_rec.CrestereCopil, v_rec.SuspendareCM, v_rec.Buget, v_rec.NoAngajat, v_rec.NoAngajator, v_rec.ZilePlataFirma, v_rec.NeavizatCAS, v_rec.Plafonare, v_rec.NoDeducere, v_rec.Constructii, v_rec.ANSTART, v_rec.LUNASTART, v_rec.ALSTART, v_rec.ALSTOP
  );
  END LOOP;
  FOR v_rec IN
  (
  SELECT *
  FROM TMP_SAL_NASIG1
  )
  LOOP
  SELECT NEXTVAL('SEQ_SAL_NASIG1_CODNASIG1')
  INTO vcod;
  UPDATE TMP_SAL_NASIG2
  SET
  codnasig1 = vcod
  WHERE
   codnasig1 = v_rec.codnasig1
  ;
  INSERT INTO SAL_NASIG1
  (
  codnasig1, codnasig0, modcalcul, conditionare, umv
  )
  VALUES
  (
  vcod, v_rec.codnasig0, v_rec.modcalcul, v_rec.conditionare, v_rec.umv
  );
  END LOOP;
  INSERT INTO SAL_NASIG2
  (
  codnasig2, codnasig0, codnasig1, cuantum, liminf, limsup
  )
  (
  SELECT NEXTVAL('SEQ_SAL_NASIG2_CODNASIG2'), codnasig0, codnasig1, cuantum, liminf, limsup
  FROM TMP_SAL_NASIG2 tnc
  );
  INSERT INTO SAL_NASIG3
  (
  codnasig3, codnasig0, tip, elemcalcul, multiplicare, codcont, contributie
  )
  (
  SELECT NEXTVAL('SEQ_SAL_NASIG3_CODNASIG3'), codnasig0, tip, elemcalcul, multiplicare, codcont, contributie
  FROM TMP_SAL_NASIG3 tnc
  WHERE
     tnc.codnasig3 &lt; 0
  );
  END IF;
  call PRC_AL_REFRESH( 'SAL_NASIG0', RECID);
  PERFORM NotifyModif( Operation, RecId, 'SAL_NASIG');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_check_regulpers_luna</obj_name>
  <obj_hashval>119b44c42a9c106aceb84c9fd2e6fcbb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_check_regulpers_luna()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC_MARE RECORD;
  V_REC      RECORD;
  PARAM_REG_DATA    date;
  PARAM_REG_MONEDA  NUMERIC(20);
  PARAM_REG_CURS    NUMERIC(20,7);
  LunaPrecedentaReg NUMERIC(2);
  AnPrecedentReg    numeric;
  DIFERENTE         numeric := 0;
  aTIPCONT          numeric := 0;
  aSEMN             numeric := 0;
BEGIN
  --Florin 17.08.2022 - sinc. Oracle
  --Bogdan 18.08.2020
  FOR V_REC_MARE in (SELECT * FROM REG, TMP_PKG_GLOBALS X WHERE TIPREG = 47 AND  AN = ANLUCRU AND  LUNA = LUNALUCRU) LOOP
    SELECT V_REC_MARE.DataDoc, V_REC_MARE.CodMoneda, V_REC_MARE.Curs
      INTO PARAM_REG_DATA, PARAM_REG_MONEDA, PARAM_REG_CURS;

    PERFORM PKG_REG_SetParamsReg( TO_CHAR( PARAM_REG_DATA, 'DD.MM.YYYY'), PARAM_REG_MONEDA, PARAM_REG_CURS::NUMERIC);
    PERFORM PKG_GLOBALS_SETLUNATEMP( getAnLucru(), getLunaLucru());

    select  PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA.newan, PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA.newluna
    from PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( getAnLucru(), getLunaLucru(), AnPrecedentReg, LunaPrecedentaReg)
      into AnPrecedentReg, LunaPrecedentaReg;

    PERFORM PKG_GLOBALS_SETLUNAPRECEDENTA( AnPrecedentReg, LunaPrecedentaReg);

    DELETE FROM TMP_REGPERS1_MARTOR;
    INSERT INTO TMP_REGPERS1_MARTOR(CODPERS, ICONT, SOLDDOCVAL)
    SELECT CODPERS, ICONT, SUM( SOLDDOCVAL) FROM REGPERS1 WHERE CODREG = V_REC_MARE.CODREG GROUP BY CODPERS, ICONT;

    DELETE FROM TMP_REGPERS1;
    DELETE FROM TMP_SOLDPERS_SUB;
    INSERT INTO TMP_SOLDPERS_SUB(CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA)
    SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
    FROM V_SOLDPERS_TRANZACTII_SUB WHERE  CODMONEDA = pkg_reg_getmonedareg();

    FOR V_REC in (SELECT * FROM TMP_SOLDPERS_SUB S) LOOP
      BEGIN
        SELECT COALESCE( TIPCONT, 0)
          INTO ATIPCONT
        FROM NCONT, TMP_PKG_GLOBALS X
        WHERE
             CODCONT = (SELECT PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG.WME_RESULT
                        FROM PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(NULL,
                                       1100,
                                       V_REC.ICONT,
                                       (SELECT PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA.WME_RESULT
                                         FROM PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA(NULL, V_REC.CODPERS, getAnLucru(), getLunaLucru()))));
        EXCEPTION WHEN OTHERS THEN
            aTIPCONT := 0;
      END;

      IF  COALESCE( aTIPCONT, 0) = 1 THEN
        aSEMN := -1;
      ELSE
        aSEMN := 1;
      END IF;

      UPDATE TMP_SOLDPERS_SUB
      set SEMN = aSEMN
      WHERE
         CODPERS = V_REC.CODPERS AND  CODMONEDA = V_REC.CODMONEDA AND  ICONT = V_REC.ICONT;
    END LOOP;

    INSERT INTO TMP_REGPERS1 (CodRegPers1, SoldDoc, SoldDocVal, SoldDocReg, CodPers, CodCont, ICONT, SUBUNITATEA, Diferenta, Den_Pers, Den_Cont)
    SELECT -1 * row_number() over(),
          SOLDVALUTA,
          SOLDLEI,
          SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(NULL,NULL)),
          CodPers,
          CodCont,
          ICONT,
          SUBUNITATEA,
          SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(NULL,NULL)) - SoldLei, Prenume || ' ' || Nume,
          Den_Cont
    FROM (
        SELECT T1.CODPERS, SOLDVALUTA, SOLDLEI, NUME, PRENUME, ICONT, SUBUNITATEA,
               (SELECT PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT
                FROM PKG_PLANCONTURI_GETSIMBOLCONT(NULL, (SELECT PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG.WME_RESULT
                                                          FROM PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(NULL, 1100, ICONT,
                                                                                                   (SELECT PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA.WME_RESULT
                                                                                                    FROM PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA(NULL, T1.CODPERS, getAnLucru(), getLunaLucru())))))
               ) AS DEN_CONT,
               (SELECT PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG.WME_RESULT
                 FROM PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(NULL, 1100, ICONT,
                                                          (SELECT PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA.WME_RESULT
                                                           FROM PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA(NULL, T1.CODPERS, getAnLucru(), getLunaLucru())))
                ) AS CODCONT
        FROM TMP_PKG_GLOBALS X,
          (SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SUM( SOLDLEI) SOLDLEI, SUM( SOLDVALUTA) SOLDVALUTA
            FROM (
                SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA,
                    COALESCE( SOLDLEI, 0) * COALESCE( SEMN, 1) SOLDLEI,
                    COALESCE( SOLDVALUTA, 0) * COALESCE( SEMN, 1) SOLDVALUTA
                FROM TMP_SOLDPERS_SUB
                union ALL
                SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
                FROM V_SOLDPERS_PREC_SUB
                WHERE CODMONEDA = pkg_reg_getmonedareg()
                ) A_PG
            GROUP BY CODPERS, ICONT, CODMONEDA, SUBUNITATEA
          ) T1, NPERS NP
        WHERE
               NP.CodPers = T1.CodPers
               AND  CODMONEDA = pkg_reg_getmonedareg()
               AND  T1.SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(NULL,NULL)) - T1.SoldLei &lt;&gt; 0) B_PG;

    FOR V_REC in (
      SELECT INTBL.CODPERS, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT
      FROM TMP_REGPERS1_MARTOR INTBL
        LEFT JOIN ( SELECT CODPERS, ICONT, SUM( SOLDDOCVAL) AS SOLDDOCVAL FROM TMP_REGPERS1 GROUP BY  CODPERS, ICONT
                  ) OUTTBL ON  OUTTBL.CODPERS = INTBL.CODPERS AND  OUTTBL.ICONT = INTBL.ICONT
      union
      SELECT OUTTBL.CODPERS, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT
      FROM (SELECT CODPERS, ICONT, SUM( SOLDDOCVAL) AS SOLDDOCVAL FROM TMP_REGPERS1 GROUP BY CODPERS, ICONT
           ) OUTTBL
      LEFT JOIN TMP_REGPERS1_MARTOR INTBL ON  INTBL.CODPERS = OUTTBL.CODPERS AND  INTBL.ICONT = OUTTBL.ICONT
    ) LOOP
      IF  COALESCE( V_REC.SOLDIN, 0) &lt;&gt; COALESCE( V_REC.SOLDOUT, 0) THEN
          DIFERENTE := 1;
          EXIT ;
      END IF;
    END LOOP;

    IF  DIFERENTE = 1 THEN
      UPDATE JURNAL1
      set DIRTY = 1
      where  TIPDOC = 47 AND  CODDOC = V_REC_MARE.CODREG;
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tarifeman_set_variabile</obj_name>
  <obj_hashval>8d145c6d3d2c5ec593c6b3804bd17ba6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tarifeman_set_variabile(aowner character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_TARIFEMAN.gOwner',aOwner,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_soldpers_prec</obj_name>
  <obj_hashval>0fbd6b541253c1ee4e39bca5d9bc0ea8</obj_hashval>
  <obj_text>SELECT codpers,
    icont,
    codmoneda,
    soldlei,
    soldvaluta
   FROM martor.nperssoldluna
  WHERE an = current_setting('PKG_GLOBALS.ANPRECEDENT'::text, true)::numeric AND luna = current_setting('PKG_GLOBALS.LUNAPRECEDENTA'::text, true)::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_list_base_pkg_list_base_restlistgest_setjoinuri</obj_name>
  <obj_hashval>d8d9122621b13cc2170393c13630313e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_list_base_pkg_list_base_restlistgest_setjoinuri()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 20.05.2025
  PERFORM Pkg_List_Struct_SetTableSpec((current_setting('pkg_list_base_pkg_list_base_restlistgest.gSuplCols', true)));
  PERFORM pkg_list_struct_AdunaColoanele();
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_monede_update_pretm_curs</obj_name>
  <obj_hashval>fca713248cdbd1d793c7823bd50e617b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_monede_update_pretm_curs(p_simbol_banca character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  v_curs_curent  nmonede1.valoare%TYPE;
  v_today     DATE := current_date;
  v_err       VARCHAR(4000);
  v_cod_moneda NMONEDE1.CODMONEDA%TYPE;
  v_codbanca   NBANK.CODBANK%TYPE;
  r         record;
  v_state  text;
  v_msg    text;
  v_claimed int;

  v_started_by text;
  v_dummy      numeric;
BEGIN
  --Florin 21.08.2025
  BEGIN
      SELECT codbank
        INTO v_codbanca
        FROM nbank
       WHERE simbol = p_simbol_banca;
  EXCEPTION
   WHEN NO_DATA_FOUND THEN
      RAISE EXCEPTION USING
        ERRCODE = 'P0001',
        MESSAGE = 'Simbol de banca inexistent: ' || p_simbol_banca;

    WHEN TOO_MANY_ROWS THEN
      RAISE EXCEPTION USING
        ERRCODE = 'P0001',
        MESSAGE = 'Simbol de banca duplicat in NBANK: ' || p_simbol_banca;
  END;

  SELECT wme_result, fakeparam
    INTO v_started_by, v_dummy
  FROM pkg_globals_username(NULL::varchar, NULL::numeric);

  FOR r IN (
  SELECT DISTINCT codmoneda
    FROM nmonede1
   WHERE codbanca = v_codbanca
     AND COALESCE(codmoneda,0) &lt;&gt; 0 ) LOOP
   BEGIN
      v_claimed := NULL;
      -- log start pentru moneda curenta
      INSERT INTO pretm_autoupd_log
             (cod_moneda, cod_banca, run_date, started_by, start_ts, status)
      VALUES (r.codmoneda, v_codbanca, v_today, v_started_by, current_timestamp, 'RUNNING')
      ON CONFLICT DO NOTHING
      RETURNING 1 INTO v_claimed;
      IF v_claimed IS NULL THEN
        -- alta sesiune a pornit deja
        CONTINUE;
      END IF;
      v_curs_curent := (SELECT PKG_MONEDE_GETCURSMONEDA.WME_RESULT FROM PKG_MONEDE_GETCURSMONEDA(null,
                   r.codmoneda,
                   v_codbanca,
                   TO_CHAR(v_today, 'dd.mm.yyyy')
                 ));
      IF v_curs_curent = 1 THEN
          UPDATE pretm_autoupd_log
             SET end_ts = CURRENT_TIMESTAMP,
                 status = 'ERROR: nu exista curs'
           WHERE cod_moneda = r.codmoneda
             AND cod_banca  = v_codbanca
             AND run_date   = v_today;
           COMMIT;
           CONTINUE;
      END IF;
   -- 1) Actualizeaza PRETM
        UPDATE pretm p
           SET lei = (SELECT PKG_PRETURI_WMROTOPRET.WME_RESULT FROM PKG_PRETURI_WMROTOPRET(NULL,
                         (SELECT o.rotvaluta
                            FROM nartobj o
                           WHERE o.codobiect = p.codobiect),
                         COALESCE(p.valuta, 0) * v_curs_curent
                       ))
         WHERE p.moneda = r.codmoneda
           AND EXISTS (
                 SELECT 1
                   FROM ncatpret c
                  WHERE c.codcatpret = p.codcatpret
                    AND c.tip         &lt; 3
               );
    -- 2) Actualizeaza PRETMAMB
      UPDATE pretmamb pa
         SET lei = (SELECT PKG_PRETURI_WMROTOPRET.WME_RESULT FROM PKG_PRETURI_WMROTOPRET(NULL,src.rot_val, src.val_fc * v_curs_curent))
        FROM (
          SELECT
            pa2.codpretm            AS codpretm,
            o.rotvaluta             AS rot_val,
            COALESCE(pa2.valuta,0)  AS val_fc
          FROM pretmamb pa2
          JOIN pretm      p  ON pa2.codpretm   = p.codpretm
          JOIN ncatpret   c  ON c.codcatpret   = p.codcatpret
                             AND c.tip          &lt; 3
          JOIN nartobj    o  ON o.codobiect    = p.codobiect
          WHERE p.moneda = r.codmoneda
        ) AS src
       WHERE pa.codpretm = src.codpretm;

        UPDATE pretm_autoupd_log
           SET end_ts = CURRENT_TIMESTAMP,
               status = 'SUCCESS'
         WHERE cod_moneda = r.codmoneda
           AND cod_banca  = v_codbanca
           AND run_date   = v_today;
        EXCEPTION
           WHEN unique_violation THEN
               CONTINUE;
      WHEN OTHERS THEN
          GET STACKED DIAGNOSTICS
            v_state = RETURNED_SQLSTATE,
            v_msg   = MESSAGE_TEXT;

          v_err := COALESCE(v_state || ': ', '') || left(v_msg, 3900);
          INSERT INTO X VALUES('AA', v_err);
      RETURN;
          UPDATE pretm_autoupd_log
             SET end_ts = CURRENT_TIMESTAMP,
                 status = 'ERROR',
                   error_msg = v_err
           WHERE cod_moneda = r.codmoneda
             AND cod_banca  = v_codbanca
             AND run_date   = v_today;

          CONTINUE;
       END;
    END LOOP;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_postretail_checkinactivari_art</obj_name>
  <obj_hashval>1f263a21ca40021bc6f2c206a116fa13</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_postretail_checkinactivari_art(acodpostretail numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  v_rec record;
begin
  --Florin 27.11.2025
  FOR V_REC IN (SELECT * FROM INACTIVRETAIL WHERE CODPOSTRETAIL = aCODPOSTRETAIL)
  LOOP
    UPDATE NARTOBJ
    SET
      INACTIV = 1
    WHERE
      CODOBIECT = V_REC.CODOBIECT;
  END LOOP;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_moneda_reg</obj_name>
  <obj_hashval>5f9b852d7106afea06caed86e4ebce38</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_moneda_reg(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_REG.moneda_reg', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_setan_reg</obj_name>
  <obj_hashval>f62eb14a10a8bc4e89e7d81e6b03918c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_setan_reg(aan_reg numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REG.an_reg',to_char(aan_reg,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_setbank_reg</obj_name>
  <obj_hashval>d14d1f5613fb321c5656a847b85c4a11</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_setbank_reg(abank_reg numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REG.bank_reg',to_char(abank_reg,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_setbankreg</obj_name>
  <obj_hashval>956b4dddba5c591a9364e2e85ca794c5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_setbankreg(bank_p numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REG.bank_reg',to_char(bank_p,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_reg_setdata_reg</obj_name>
  <obj_hashval>6588d9d11ba71f47629f9a96ba657bd2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_reg_setdata_reg(adata_reg date)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REG.data_reg',adata_reg::varchar,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_conditie_litigii</obj_name>
  <obj_hashval>b9fd4050e32c384ce835f4fee44c18b4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_conditie_litigii(INOUT wme_result numeric, INOUT asemnificatie numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  --Bogdan 18.08.2020
  IF aSEMNIFICATIE IN (1303) THEN
    select pkg_regpart_getinclusiv_litigii.WME_Result from pkg_regpart_getinclusiv_litigii(null,null) into WME_Result;
    RETURN;
  ELSE
    WME_Result :=  1;
    RETURN;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpart_setinclusiv_cecuri</obj_name>
  <obj_hashval>a99b23ec1fabde7aedcd395d9f85ea71</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpart_setinclusiv_cecuri(ainclusiv_cecuri numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_REGPART.INCLUSIV_CECURI',to_char(aINCLUSIV_CECURI,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_regpers_sp_postrecords</obj_name>
  <obj_hashval>ab3f9ffcfdb1bdc9eebd26b227c339d3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_regpers_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
declare
  V_REC     RECORD;
  V_REC_SUB RECORD;
  NR        numeric;
  TMP_NR    numeric;
  DIFERENTE numeric := 0;
  CURS_OUT  numeric;
  cod1      NUMERIC(20);
begin
  SELECT CURS INTO CURS_OUT FROM TMP_REG;

  if Operation = 0 then
    SELECT CodReg INTO RecID FROM TMP_REG;

    UPDATE REG
    SET
      (TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, Provizion, Luna, An, CodAnaliza, CodCentru, CodAnalizaNod)
      =
      (SELECT TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, Provizion, Luna, An, CodAnaliza, CodCentru, CodAnalizaNod
       FROM TMP_REG )
    WHERE CodReg = RecID ;

    DELETE FROM REGPERS1 WHERE CodReg = RecID;
    for v_rec in (select * from TMP_REGPERS1) LOOP
      select NEXTVAL('SEQ_REGPERS1_CODREGPERS1') into cod1;
      INSERT INTO REGPERS1 ( CodRegPers1, CodReg, SoldDoc, SoldDocVal, SoldDocReg, CodPers, CodCont, ICONT, SUBUNITATEA )
      values (cod1, RecID, v_rec.SoldDoc, v_rec.SoldDocVal, v_rec.SoldDocReg, v_rec.CodPers, v_rec.CodCont, v_rec.ICONT, v_rec.SUBUNITATEA);
      update tmp_jurnal1 set indexlocal = Cod1 where indexlocal = v_rec.codregpers1;
      update tmp_jurnal set indexlocal = Cod1 where indexlocal = v_rec.codregpers1;
    END LOOP;

    DELETE FROM JURNAL1
    WHERE TIPDOC = 47 and CODDOC = RECID and CODJURNAL1 not in (SELECT CODJURNAL1 FROM TMP_JURNAl1 );

    for V_REC in (SELECT * FROM TMP_JURNAL1 ) loop
      if V_REC.CODJURNAL1 &gt; 0 then
        UPDATE JURNAL1
        set
          CODDOC        = V_REC.CODDOC,
          TIPDOC        = V_REC.TIPDOC,
          INDEXLOCAL    = V_REC.INDEXLOCAL,
          CODBAZAD      = V_REC.CODBAZAD,
          ICONTBAZAD    = V_REC.ICONTBAZAD,
          TIPBAZAD      = V_REC.TIPBAZAD,
          CODBAZAC      = V_REC.CODBAZAC,
          ICONTBAZAC    = V_REC.ICONTBAZAC,
          TIPBAZAC      = V_REC.TIPBAZAC,
          CODDESCRD     = V_REC.CODDESCRD,
          ICONTD        = V_REC.ICONTD,
          TIPCONTD      = V_REC.TIPCONTD,
          ANALITICCONTD = V_REC.ANALITICCONTD,
          CODDESCRC     = V_REC.CODDESCRC,
          ICONTC        = V_REC.ICONTC,
          TIPCONTC      = V_REC.TIPCONTC,
          ANALITICCONTC = V_REC.ANALITICCONTC,
          GEST          = V_REC.GEST,
          VALOARE       = V_REC.VALOARE,
          VALOAREV      = V_REC.VALOAREV,
          OBS           = V_REC.OBS,
          AN            = V_REC.AN,
          LUNA          = V_REC.LUNA,
          DIRTY         = V_REC.DIRTY,
          SUBUNITATEA   = V_REC.SUBUNITATEA,
          CODCENTRU     = V_REC.CODCENTRU,
          CODANALIZANOD = V_REC.CODANALIZANOD,
          DATADOC       = V_REC.DATADOC,
          document      = V_REC.DOCUMENT
        where
          CODJURNAL1 = V_REC.CODJURNAL1 ;
      else
        INSERT INTO JURNAL1 ( CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD, CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, document, CODCENTRU, CODANALIZANOD )
        values ( NEXTVAL('SEQ_JURNAL1_CODJURNAL1'), RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CODBAZAD, V_REC.ICONTBAZAD, V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD, V_REC.CODBAZAC, V_REC.ICONTBAZAC, V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT, V_REC.CODCENTRU, V_REC.CODANALIZANOD );
      end if;
    end loop;

    DELETE FROM JURNAL WHERE TIPDOC = 47 and CODDOC = RECID and CODJURNAL not in (SELECT CODJURNAL FROM TMP_JURNAl );

    for V_REC in (SELECT * FROM TMP_JURNAL ) loop
      if V_REC.CODJURNAL &gt; 0 then
        UPDATE JURNAL
        set
          CODDOC        = V_REC.CODDOC,
          TIPDOC        = V_REC.TIPDOC,
          INDEXLOCAL    = V_REC.INDEXLOCAL,
          CONTD         = V_REC.CONTD,
          CONTC         = V_REC.CONTC,
          GEST          = V_REC.GEST,
          VALOARE       = V_REC.VALOARE,
          VALOAREV      = V_REC.VALOAREV,
          OBS           = V_REC.OBS,
          AN            = V_REC.AN,
          LUNA          = V_REC.LUNA,
          SUBUNITATEA   = V_REC.SUBUNITATEA,
          DATADOC       = V_REC.DATADOC,
          CODCENTRU     = V_REC.CODCENTRU,
          CODANALIZANOD = V_REC.CODANALIZANOD,
          document = V_REC.DOCUMENT
        where
          CODJURNAL = V_REC.CODJURNAl ;
      else
        INSERT INTO JURNAL ( CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, DATADOC, document, CODCENTRU, CODANALIZANOD )
        values ( NEXTVAL('SEQ_JURNAL_CODJURNAL'), RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT, V_REC.CODCENTRU, V_REC.CODANALIZANOD );
      end if;
    end loop;
  ELSE
    SELECT NEXTVAL('SEQ_REG_CODREG') INTO RecID;

    INSERT INTO REG ( CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, Provizion, Luna, An, CodAnaliza, CodCentru, CodAnalizaNod )
    (SELECT RecID, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, Provizion, Luna, An, CodAnaliza, CodCentru, CodAnalizaNod
     FROM TMP_REG );

    for v_rec in (select * from TMP_REGPERS1) LOOP
      select NEXTVAL('SEQ_REGPERS1_CODREGPERS1') into cod1;
      INSERT INTO REGPERS1         (CodRegPers1, CodReg, SoldDoc, SoldDocVal, SoldDocReg, CodPers, CodCont, ICONT, SUBUNITATEA)
      values (cod1, RecID, v_rec.SoldDoc, v_rec.SoldDocVal, v_rec.SoldDocReg, v_rec.CodPers, v_rec.CodCont, v_rec.ICONT, v_rec.SUBUNITATEA);
      update tmp_jurnal1 set indexlocal = Cod1 where indexlocal = v_rec.codregpers1;
      update tmp_jurnal set indexlocal = Cod1 where indexlocal = v_rec.codregpers1;
    END LOOP;

    INSERT INTO JURNAL1 ( CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD, CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, CODCENTRU, CODANALIZANOD )
    (SELECT NEXTVAL('SEQ_JURNAL1_CODJURNAL1'), RECID, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD, CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, CODCENTRU, CODANALIZANOD
     FROM TMP_JURNAL1 );

    INSERT INTO JURNAL ( CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, DATADOC, CODCENTRU, CODANALIZANOD )
    (SELECT NEXTVAL('SEQ_JURNAL_CODJURNAL'), RECID, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, DATADOC, CODCENTRU, CODANALIZANOD
     FROM TMP_JURNAL );
  end if;

  for V_REC in (SELECT * FROM TMP_RULAJ ) loop
    SELECT COUNT(*) INTO TMP_NR
    FROM NCONTRUL
    WHERE CODCONT = V_REC.CODCONT and AN = current_setting('PKG_GLOBALS.ANLUCRU', true)::NUMERIC and LUNA = current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric;

    if TMP_NR = 0 then
      INSERT INTO NCONTRUL ( CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA )
      values ( NEXTVAL('SEQ_NCONTRUL_CODCONTRUL'), V_REC.CODCONT, 0, 0, 0, 0, 0, 0, 0, 0, current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric, current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric );
    end if;

    UPDATE NCONTRUL
    set
      RULAJCD  = RULAJCD  + (CASE when V_REC.TIP = 'D' then V_REC.VALOARE  else 0 end ) ,
      RULAJCC  = RULAJCC  + (CASE when V_REC.TIP = 'C' then V_REC.VALOARE  else 0 end ) ,
      RULAJVCD = RULAJVCD + (CASE when V_REC.TIP = 'D' then V_REC.VALOAREV else 0 end ) ,
      RULAJVCC = RULAJVCC + (CASE when V_REC.TIP = 'C' then V_REC.VALOAREV else 0 end )
    where
      CODCONT = V_REC.CODCONT
      and AN = current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric
      and LUNA = current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric ;

    if coalesce(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 then
      for V_REC_SUB in (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT and AN = current_setting('PKG_GLOBALS.ANLUCRU', true)::NUMERIC and LUNA = current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric )
      loop
        SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL and SUBUNITATEA = V_REC.SUBUNITATEA;

        if NR = 0 then
          INSERT INTO NCONTRULSUB ( CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA )
          values ( NEXTVAL('SEQ_NCONTRULSUB_CODRULSUB'), V_REC_SUB.CODCONTRUL, 0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA );
        end if;

        UPDATE NCONTRULSUB
        set
          RULAJCD  = RULAJCD  + (CASE when V_REC.TIP = 'D' then V_REC.VALOARE  else 0 end ) ,
          RULAJCC  = RULAJCC  + (CASE when V_REC.TIP = 'C' then V_REC.VALOARE  else 0 end ) ,
          RULAJVCD = RULAJVCD + (CASE when V_REC.TIP = 'D' then V_REC.VALOAREV else 0 end ) ,
          RULAJVCC = RULAJVCC + (CASE when V_REC.TIP = 'C' then V_REC.VALOAREV else 0 end )
        where
          CODCONTRUL = V_REC_SUB.CODCONTRUL and SUBUNITATEA = V_REC.SUBUNITATEA ;
      end loop;
    end if;
  end loop;

  for V_REC in (SELECT INTBL.CODPERS, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT
                FROM TMP_REGPERS1_MARTOR INTBL
                    left join (SELECT CODPERS, ICONT, SUM(SOLDDOCVAL) as SOLDDOCVAL FROM TMP_REGPERS1 group BY CODPERS, ICONT
                              ) OUTTBL ON OUTTBL.CODPERS = INTBL.CODPERS and OUTTBL.ICONT = INTBL.ICONT
                 union
                SELECT OUTTBL.CODPERS, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT
                FROM (SELECT CODPERS, ICONT, SUM(SOLDDOCVAL) as SOLDDOCVAL FROM TMP_REGPERS1 group BY CODPERS, ICONT
                     ) OUTTBL
                    left join TMP_REGPERS1_MARTOR INTBL ON INTBL.CODPERS = OUTTBL.CODPERS and INTBL.ICONT = OUTTBL.ICONT
               )
  loop
    if coalesce(V_REC.SOLDIN, 0) &lt;&gt; coalesce(V_REC.SOLDOUT, 0) then
      DIFERENTE := 1;
      exit ;
    end if;
  end loop;

  if (DIFERENTE = 1) or (coalesce(current_setting('PKG_REGPERS.CURS_IN', true)::numeric, 0) &lt;&gt; coalesce(CURS_OUT, 0))
  then
    for V_REC in (SELECT * FROM REG
                  WHERE TIPREG = 47
                    and CODMONEDA = (SELECT CODMONEDA FROM TMP_REG )
                    and AN * 12 + LUNA &gt; current_setting('PKG_GLOBALS.ANLUCRU', true)::numeric * 12 + current_setting('PKG_GLOBALS.LUNALUCRU', true)::numeric
                 )
    loop
      UPDATE JURNAL1 SET DIRTY = 1 WHERE TIPDOC = 47 and CODDOC = V_REC.CODREG ;
    end loop;
  end if;

  perform PKG_GLOBALS_MarkDirtyJurnal();
  perform NotifyModif(Operation, RecId, 'REG');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_remake_sequences_reval_sequence</obj_name>
  <obj_hashval>5b38fc118ab1b14a2a00f609af34b66d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_remake_sequences_reval_sequence(nume_tbl character varying, nume_colcod character varying, nume_seq character varying, shrink_seq boolean)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vNewVal numeric;
  vValSeq numeric;
  vValCol numeric;
  sSchema VARCHAR;
BEGIN
  --Florin 12.05.2025 - sinc. Oracle
  --Stef 02.03.2023
  sSchema := lower(getfirmaname());
  IF NULLIF(sSchema, '') IS NULL THEN
    sSchema := public.get_schema();
  END IF;

  vValSeq := NextVal(sSchema||'.'||nume_seq);
  vValCol := fnc_seqvalmin(nume_tbl, nume_colcod)+1;

  IF SHRINK_SEQ THEN
    vNewVal := GREATEST( COALESCE( vValCol, 0), 101);
  ELSE
    vNewVal := GREATEST( COALESCE( vValCol, 0), 101, vValSeq);
  END IF;
  IF vNewVal &lt;&gt; vValSeq+1 THEN
    vValSeq = setval(sSchema||'.'||nume_seq, vNewVal::bigint);
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_restaurant_release_all_stoclock</obj_name>
  <obj_hashval>9d323e5bfd16c2b491c464c532437f41</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_restaurant_release_all_stoclock()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
begin
  DELETE FROM STOCLOCKREST
  WHERE
   USERID = TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999') OR USERID IS NULL ;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_ropharma_do_preluare_judete</obj_name>
  <obj_hashval>b96f9756f1d8fd6a15962c3c07c16ca9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_ropharma_do_preluare_judete()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_ROPHARMA_PREIA_JUDETE( 'ROPH'  , 'ROPH2014');
  PERFORM PKG_ROPHARMA_PREIA_JUDETE( 'ROPHBC', 'ROPH2014');
  PERFORM PKG_ROPHARMA_PREIA_JUDETE( 'ROPHIS', 'ROPH2014');
  PERFORM PKG_ROPHARMA_PREIA_JUDETE( 'MURES' , 'ROPH2014');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_ropharma_getcodtara_dest</obj_name>
  <obj_hashval>e8730b7542df4b18feacbd4569916688</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_ropharma_getcodtara_dest(INOUT wme_result numeric, INOUT skemadest character varying, INOUT adentara character varying, INOUT asimbtara character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  S        varchar := '';
  aCODTARA numeric := 0;
begin
  BEGIN
    S := 'SELECT CODTARA ' || '   FROM ' || '     ' || SKEMADEST || '.NTARI ' || '   WHERE ' || '    UPPER(DEN_TARA) = ''' || UPPER( aDENTARA) || '''' || '    AND upper(coalesce(SIMBAUTO, ''?'')) = ''' || upper( COALESCE( aSIMBTARA, '?')) || '''';
    EXECUTE S;
  EXCEPTION WHEN OTHERS THEN
    aCODTARA := 0;
  END;
  WME_Result :=  aCODTARA;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_rupere_firma_getan_initializari</obj_name>
  <obj_hashval>7c87144d20e3322ea323ee0a1384932c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_rupere_firma_getan_initializari(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_RUPERE_FIRMA.AN_INITIALIZARI', true)),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sablondescript_sp_insertrecord</obj_name>
  <obj_hashval>6edf51a26224a9588a00be4582cbb2ac</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sablondescript_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO tmp_SABLONDESCRIPT(CODSABLON) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t03</obj_name>
  <obj_hashval>0cef02af5b893596cfd5c070ba3b28f5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t03()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vSubunit NUMERIC(20);
BEGIN
  --Stef 11.04.2025
  PERFORM pkg_saft_PUT_INFO('03.A','UMPLE_T03');
  SELECT CODSUBUNIT INTO vSubunit
  FROM TMP_SAFT_PARAMS;

  INSERT INTO TMP_SAFT03
  SELECT
    NEXTVAL('SEQ_SAFT')                               COL01,--CODSAF_ACCOUNT       -&gt; NUMERIC(20,0)
    CODSAFT                                           COL02,--ACCOUNTID            -&gt; STRING(70,0)
    DEN_CONT                                          COL03,--ACCOUNTDESCRIPTION   -&gt; STRING(255,0)
    SubStr(SIMBOL, 1, 35)                             COL04,--STANDARDACCOUNTID    -&gt; STRING(35,0)
    CAST(NULL AS VARCHAR(35))                         COL05,--GROUPINGCATEGORY     -&gt; STRING(35,0)
    CAST(NULL AS VARCHAR(35))                         COL06,--GROUPINGCODE         -&gt; STRING(35,0)
    CASE
      WHEN TIPCONT = 1                                 THEN 'Pasiv'
      WHEN TIPCONT = 2                                 THEN 'Bifunctional'
                                                       ELSE 'Activ'
    END                                               COL07,--ACCOUNTTYPE          -&gt; STRING(18,0)
    CAST(NULL AS DATE)                                COL08,--ACCOUNTCREATIONDATE  -&gt; DATE(10,0)
    CASE
      WHEN TIPCONT = 1                                 THEN NULL
      WHEN TIPCONT = 2 AND SOLDINI &lt; 0                 THEN NULL
      WHEN TIPCONT = 2 AND SOLDINI = 0 AND SOLDFIN &lt; 0 THEN NULL
      ELSE                                                  SOLDINI
    END                                               COL09,--OPENINGDEBITBALANCE  -&gt; NUMERIC(18,2)
    CASE
      WHEN TIPCONT = 1                                 THEN -SOLDINI
      WHEN TIPCONT = 2 AND SOLDINI &lt; 0                 THEN -SOLDINI
      WHEN TIPCONT = 2 AND SOLDINI = 0 AND SOLDFIN &lt; 0 THEN -SOLDINI
      ELSE                                                  NULL
    END                                               COL10,--OPENINGCREDITBALANCE -&gt; NUMERIC(18,2)
    CASE
      WHEN TIPCONT = 1                                 THEN NULL
      WHEN TIPCONT = 2 AND SOLDFIN &lt; 0                 THEN NULL
      WHEN TIPCONT = 2 AND SOLDFIN = 0 AND SOLDINI &lt; 0 THEN NULL
      ELSE                                                  SOLDFIN
    END                                               COL11,--CLOSINGDEBITBALANCE  -&gt; NUMERIC(18,2)
    CASE
      WHEN TIPCONT = 1                                 THEN -SOLDFIN
      WHEN TIPCONT = 2 AND SOLDFIN &lt; 0                 THEN -SOLDFIN
      WHEN TIPCONT = 2 AND SOLDFIN = 0 AND SOLDINI &lt; 0 THEN -SOLDFIN
      ELSE                                                  NULL
    END                                               COL12 --CLOSINGCREDITBALANCE -&gt; NUMERIC(18,2)
  FROM (
    SELECT
      C.CODCONT, C.TIPCONT, C.CODSAFT, C.DEN_CONT, C.SIMBOL,
      CASE
        WHEN vSubunit = 1
        THEN Coalesce(CSI.SOLDID,0) - Coalesce(CSI.SOLDIC,0) +  Coalesce(CRI.RULAJPD,0) - Coalesce(CRI.RULAJPC,0)
        ELSE Coalesce(SSI.SOLDID,0) - Coalesce(SSI.SOLDIC,0) +  Coalesce(SRI.RULAJPD,0) - Coalesce(SRI.RULAJPC,0)
      END SOLDINI,
      CASE
        WHEN vSubunit = 1
        THEN Coalesce(CSF.SOLDID,0) - Coalesce(CSF.SOLDIC,0) +  Coalesce(CRF.RULAJPD,0) - Coalesce(CRF.RULAJPC,0) + Coalesce(CRF.RULAJCD,0) - Coalesce(CRF.RULAJCC,0)
        ELSE Coalesce(SSF.SOLDID,0) - Coalesce(SSF.SOLDIC,0) +  Coalesce(SRF.RULAJPD,0) - Coalesce(SRF.RULAJPC,0) + Coalesce(SRF.RULAJCD,0) - Coalesce(SRF.RULAJCC,0)
      END SOLDFIN
    FROM TMP_SAFT_NCONT C
      CROSS JOIN TMP_SAFT_PARAMS SP
      LEFT JOIN NCONTSOLD    CSI ON CSI.CODCONT = C.CODCONT AND CSI.AN = SP.ANINI AND CSI.LUNA = 1
      LEFT JOIN NCONTRUL     CRI ON CRI.CODCONT = C.CODCONT AND CRI.AN = SP.ANINI AND CRI.LUNA = SP.LUNAINI
      LEFT JOIN NCONTSOLD    CSF ON CSF.CODCONT = C.CODCONT AND CSF.AN = SP.ANFIN AND CSF.LUNA = 1
      LEFT JOIN NCONTRUL     CRF ON CRF.CODCONT = C.CODCONT AND CRF.AN = SP.ANFIN AND CRF.LUNA = SP.LUNAFIN
      LEFT JOIN NCONTSOLDSUB SSI ON SSI.CODCONTSOLD = CSI.CODCONTSOLD AND SSI.SUBUNITATEA = vSubunit AND SSI.SUBUNITATEA &lt;&gt; 1
      LEFT JOIN NCONTRULSUB  SRI ON SRI.CODCONTRUL  = CRI.CODCONTRUL  AND SRI.SUBUNITATEA = vSubunit AND SRI.SUBUNITATEA &lt;&gt; 1
      LEFT JOIN NCONTSOLDSUB SSF ON SSF.CODCONTSOLD = CSF.CODCONTSOLD AND SSF.SUBUNITATEA = vSubunit AND SSF.SUBUNITATEA &lt;&gt; 1
      LEFT JOIN NCONTRULSUB  SRF ON SRF.CODCONTRUL  = CRF.CODCONTRUL  AND SRF.SUBUNITATEA = vSubunit AND SRF.SUBUNITATEA &lt;&gt; 1
    WHERE C.FRUNZA = 1 AND C.CODSAFT IS NOT NULL
    ORDER BY C.CODSAFT
  ) ssub;
  PERFORM pkg_saft_PUT_INFO('03.Z','UMPLE_T03--SAF_SELECTIONCRITERIA');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t34</obj_name>
  <obj_hashval>310b7d279075e4b29cb8052524d32a90</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t34()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 06.01.2022
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t35</obj_name>
  <obj_hashval>d9fd634899ef46e53a14b7c7a7647d48</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t35()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 06.01.2022
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t36</obj_name>
  <obj_hashval>2e5ff88d1abb1a7811b5e52059d81f48</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t36()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 06.01.2022
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_saft_umple_t37</obj_name>
  <obj_hashval>50a4b315820c8f04328d27f037797bfa</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_saft_umple_t37()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 06.01.2022
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_catret_sp_insertrecord</obj_name>
  <obj_hashval>2a052e9e3c48184051af943fa4e23154</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_catret_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 01.03.2022
  INSERT INTO TMP_SAL_CATRET
  (
  CODCATRET
  )
  VALUES
  (
  0
  );

end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_contrpp_ct_monitor</obj_name>
  <obj_hashval>00ffa55a8e736ba49f4bcaa9d260f0c3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_contrpp_ct_monitor(wme_result character varying, fakeparam numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 01.03.2022
  WME_Result := current_setting('PKG_SAL_CONTRPP.CT_MONITOR', true);
  RETURN;
  EXCEPTION WHEN undefined_object THEN
  WME_Result := 'MON_5';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_dedgen_sp_insertrecord</obj_name>
  <obj_hashval>119b462a68763ab4692947577cd28c48</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_dedgen_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 01.03.2022
  INSERT INTO TMP_SAL_DEDGEN
  (
  CODDEDGEN
  )
  VALUES
  (
  0
  );
  END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_impoz_ct_monitor</obj_name>
  <obj_hashval>7edc9da600e14aa2d86f9d02eae58e7d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_impoz_ct_monitor(wme_result character varying, fakeparam numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
 DECLARE
BEGIN
  --Florin 02.03.2022
  WME_Result := current_setting('PKG_SAL_IMPOZ.CT_MONITOR', true);
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
  WME_Result := 'MON_5';
  RETURN;
  END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_impoz_setct_monitor</obj_name>
  <obj_hashval>08617cfe6dac24d358928d98afa914d2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_impoz_setct_monitor(act_monitor character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
 DECLARE
BEGIN
  --Florin 02.03.2022
  perform set_config('PKG_SAL_IMPOZ.CT_MONITOR',aCT_MONITOR,false);
  END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_nasig_ct_monitor</obj_name>
  <obj_hashval>c5550b27453ad21bdb76b48d37b9ed24</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_nasig_ct_monitor(wme_result character varying, fakeparam numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 02.03.2022
  WME_Result := current_setting('PKG_SAL_NASIG.CT_MONITOR', true);
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
  WME_Result := 'MON_5';
  RETURN;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_nasig_getct_monitor</obj_name>
  <obj_hashval>fcd2a7bc137ffea73b8d288ad6ed9752</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_nasig_getct_monitor(wme_result character varying, fakeparam numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 02.03.2022
  WME_Result := current_setting('PKG_SAL_NASIG.CT_MONITOR', true);
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
  WME_Result := 'MON_5';
  RETURN;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_ncontrib_sp_insertrecord</obj_name>
  <obj_hashval>973c02e95c1d7475de36ea9a9339e84a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_ncontrib_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 02.03.2022
  INSERT INTO TMP_SAL_NCONTRIB
  (
  codncontrib
  )
  VALUES
  (
  0
  );
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_ncontrib_sp_lockrecord</obj_name>
  <obj_hashval>090bc710a9afb37108d93e290f5d24f5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_ncontrib_sp_lockrecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
Tmp numeric;
BEGIN
  --Florin 02.03.2022
  SELECT codncontrib
  INTO Tmp
  FROM SAL_NCONTRIB
  WHERE
     codncontrib = RecId;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sal_retineri_setct_monitor</obj_name>
  <obj_hashval>537f427b1ef4d9317a65fe15444b2f02</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sal_retineri_setct_monitor(act_monitor character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 02.03.2022
  perform set_config('PKG_SAL_RETINERI.CT_MONITOR',aCT_MONITOR,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_scenariilivr_populeaza_tmpuri</obj_name>
  <obj_hashval>8bc033dd58a7f7051d22a28ccc6e2ac6</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_scenariilivr_populeaza_tmpuri(g_subunit numeric, datalivrs character varying, datalivrf character varying, datacmds character varying, datacmdf character varying, scenariu numeric DEFAULT 0)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  NOD_Rezervat     numeric;
  NOD_RezFurn      numeric;
  TOT_RestCmd      numeric;
  TOT_RestFurn     numeric;
  Init             numeric;
  Zec              numeric;
  LastProiectNod   numeric;
  RezolvareLansari numeric;
BEGIN
  --Laura 28.10.2021 - sinc Oracle (27.10.2021)
  --Adina 07.07.2021 - sinc.Oracle din 06.07.2021
  --Adina 25.06.2021 - sinc.Oracle din 24.06.2021
  --Adina 24.06.2021 - sinc.Oracle din 23.06.2021
  DELETE FROM TMP_SIM_CCOM1;
  DELETE FROM TMP_SIM_LANS;
  DELETE FROM TMP_SIM_LANS1;
  DELETE FROM TMP_SIM_NODECHIV1;

  INSERT INTO TMP_SIM_CCOM1(NRDOC, DATADOC, DENOBIECT, DEN_CLIENT, CODCOMANDA1, CODOBIECT, CODPROIECT, VERSIUNE, CODCOMANDA, TIPDOC, CODCLIENT, TERMEN,
                            MASAO, VOLUMO, CODGRUPA, PARITATEGRUPA, GrupaE, ObjGeneric, CODTARA, DEN_TARA, CODZONA, DEN_ZONA, CODLOCALIT, DEN_LOCALIT,
                            UMSEC, OK, ACTIV, TIPCOMANDA, CODEXTERN, DENMAT, TRASEU, POZTRASEU, HTAG, CANTACCEPTAT, STOCREZERVAT, SCENDEFINITIVE,
                            ALTESCENARII, REST, DEREZOLVAT, LANSSCENARIU, LANSAT, Masa, Volum, TipClient)
  (
  SELECT C.NRDOC, C.DATADOC, NOBJ.DENUMIRE DENOBIECT, NP.DEN_PART DEN_CLIENT, C1.CODCOMANDA1, C1.CODOBIECT, C1.CODPROIECT, PR.VERSIUNE, C.CODCOMANDA, C.TIPDOC,
         NP.CODPART CODCLIENT, C1.TERMEN, NOBJ.MASA MASAO, NOBJ.VOLUM / 1000000 VOLUMO, NE.CODGRUPA, NE.PARITATE PARITATEGRUPA, GE.DENUMIRE GRUPAE,
         NOBJE.DENUMIRE OBJGENERIC, TARA.CODTARA, TARA.DEN_TARA, NZ.CODZONA, NZ.DEN_ZONA, NLOC.CODLOCALIT, NLOC.DEN_LOCALIT, C1.UMSEC, 0 OK,
         CASE WHEN  COALESCE(SCEN1.CANT, 0) = 0 THEN 0 ELSE 1 END  ACTIV,
         C.DISPLIVRARE, NOBJ.CODEXTERN, NOBJMAT.DENUMIRE DENMAT, TR.DENTRASEU TRASEU, NAG.POZTRASEU,
         COALESCE(PR.OBS1, '') || coalesce(COALESCE(PC.OBS1, ''),'') HTAG,
         C1.CANTACCEPTAT CANTACCEPTAT, REZ.REZERVAT STOCREZERVAT, COALESCE(SCDEF.CANT, 0) SCENDEFINITIVE, COALESCE(SC.CANT, 0) ALTESCENARII,
         C1.CANTACCEPTAT - COALESCE(SC.CANT, 0) - COALESCE(SCDEF.CANT, 0) REST,
         C1.CANTACCEPTAT - COALESCE(SC.CANT, 0) - COALESCE(SCDEF.CANT, 0) - COALESCE(SCEN1.LANS, 0) DEREZOLVAT,
         COALESCE(SCEN1.LANS, 0) LANSSCENARIU, COALESCE(CMDINT.CANTCMDINT, 0) LANSAT,
         COALESCE(NOBJ.MASA, 0) * COALESCE(SCEN1.LANS, 0),
         CASE WHEN COALESCE(SCEN1.LANS, 0) = 0 THEN 0 ELSE Round(COALESCE(NOBJ.VOLUM,0)/1000000 * COALESCE(SCEN1.LANS, 0), 2) END,
           case when bitand(NP.Strategic,1)=1 then 'strategic ' else '' end ||
           case when bitand(NP.tippartener,1)=1 then 'intern ' else '' end ||
           case when bitand(NP.tippartener,2)=2 then 'extern ' else '' end ||
           case when bitand(NP.tippartener,4)=4 then 'produc. ' else '' end ||
           case when bitand(NP.tippartener,8)=8 then 'asig.' else '' end ||
           case when BITand(NP.tippartener,16)=16 then 'comis.' else '' end as TipClient
  FROM TMP_SCENARIILIVR1 SCEN1
  INNER JOIN COMANDA1   C1      ON  SCEN1.CODCOMANDA1 = C1.CODCOMANDA1
  INNER JOIN COMANDA    C       ON  C.CODCOMANDA      = C1.CODCOMANDA
  INNER JOIN NARTOBJ    NOBJ    ON  NOBJ.CODOBIECT    = C1.CODOBIECT
  LEFT  JOIN NPART      NP      ON  NP.CODPART        = C.PARTENER
  LEFT  JOIN PROIECT    PR      ON  PR.CODPROIECT     = C1.CODPROIECT
  LEFT  JOIN PROIECTNOD PRN     ON  PRN.CODPROIECT    = PR.CODPROIECT AND  PRN.NODORIGINAL = 0
  LEFT  JOIN LATERAL (SELECT CODPRODCOMP, CODOBIECT FROM PRODMAT x WHERE PRINCIPAL = 1 AND x.CODPRODCOMP = PRN.CODRETETA LIMIT 1) MAT ON  MAT.CODPRODCOMP = PRN.CODRETETA
  LEFT  JOIN NARTOBJ    NOBJMAT ON  NOBJMAT.CODOBIECT = MAT.CODOBIECT
  LEFT  JOIN PRODCOMP   PC      ON  PC.CODPRODCOMP    = PRN.CODRETETA
  LEFT  JOIN NECHIV     NE      ON  NE.CODOBIECT      = C1.CODOBIECT
  LEFT  JOIN GRECHIV    GE      ON  GE.CODGRECHIV     = NE.CODGRUPA
  LEFT  JOIN NECHIV     NG      ON  NG.CODGRUPA       = NE.CODGRUPA AND  NG.GENERIC = 1
  LEFT  JOIN NARTOBJ    NOBJE   ON  NOBJE.CODOBIECT   = NG.CODOBIECT
  LEFT  JOIN NAGENDA    NAG     ON  NAG.CODAGENDA     = C.CODLOCATIE
  LEFT  JOIN TRASEULIVR TR      ON  TR.CODTRASEULIVR  = NAG.CODTRASEU
  LEFT  JOIN NLOCALIT   NLOC    ON  NLOC.CODLOCALIT   = NAG.CODLOCALIT
  LEFT  JOIN NZONE      NZ      ON  NZ.CODZONA        = NLOC.CODZONA
  LEFT  JOIN NTARI      TARA    ON  TARA.CODTARA      = NLOC.CODTARA
  LEFT  JOIN (SELECT S1.CODCOMANDA1, SUM(S1.LANS) CANT
              FROM SCENARIILIVR1 S1 INNER JOIN SCENARIILIVR S ON  S1.CODSCENARIU = S.CODSCENARIU
              WHERE COALESCE(S.DEFINITIV, 0) = 1 AND  S.CODSCENARIU &lt;&gt; SCENARIU
              GROUP BY S1.CODCOMANDA1
             ) SCDEF ON  SCDEF.CODCOMANDA1 = C1.CODCOMANDA1
  LEFT  JOIN (SELECT S1.CODCOMANDA1, SUM(S1.LANS) CANT
              FROM SCENARIILIVR1 S1 INNER JOIN SCENARIILIVR S ON  S1.CODSCENARIU = S.CODSCENARIU
              WHERE COALESCE(S.DEFINITIV, 0) = 0 AND  S.CODSCENARIU &lt;&gt; SCENARIU
              GROUP BY S1.CODCOMANDA1
             ) SC ON  SC.CODCOMANDA1 = C1.CODCOMANDA1
  LEFT  JOIN (SELECT R.CODCOMANDA1, SUM(R.REST) REZERVAT, NS.CODOBIECT
              FROM REZERVATS R INNER JOIN NIRSTOC NS ON  R.CODNIRSTOC = NS.CODNIRSTOC
              WHERE COALESCE(CODCMDPRODMAT, 0) = 0
              GROUP BY R.CODCOMANDA1, NS.CODOBIECT
             ) REZ ON  REZ.CODCOMANDA1 = C1.CODCOMANDA1 AND  NOBJ.CODOBIECT = REZ.CODOBIECT
  LEFT  JOIN (SELECT L0.Codcmd1 CMDCLI, C1.CodObiect, L0.CODSCENARIU, SUM(C1.CANTAcceptat) CANTCMDINT
              FROM LANSARE1 L1
                  INNER JOIN LANSARE0 L0 ON  L0.CodLansare0 = L1.CodLansare0
                  INNER JOIN Comanda1 C1 ON  C1.CODCOMANDA1 = L1.CodCmd1
              GROUP BY L0.Codcmd1, C1.CodObiect, L0.CODSCENARIU
             ) CMDINT ON  CMDINT.CMDCLI = C1.CODCOMANDA1 and  NOBJ.CODOBIECT = CMDINT.CODOBIECT
  );

  INSERT INTO TMP_SIM_LANS1(DENUMIRE, CODOBIECT, CODCOMANDA1, PREF, NIVEL, POZITIE, CODPROIECTNOD, NODORIGINAL, TIP, NECESARP, NECESAR, REZERVAT, NESOSIT, DataStart,
                            CERERE, STOC, CMDINT, DIFERENTE, ZECIMALE, UMSEC, DEN_UM, MatEchiv, CodExtern, DataStartCmdInt, CodComanda1I, IndexParinte, REZOLVAT)
  (
  SELECT DENUMIRE, CODOBIECT, CODCMD1, PREF, NIVEL, POZITIE, CODPROIECTNOD, NODORIGINAL, TIP, COALESCE(NECESARP, 0), 0 NECESAR, COALESCE(TotRezervat, 0),
         COALESCE(RestDeSosit, 0), DataStart, COALESCE(RestCerere, 0), COALESCE(STOC, 0), COALESCE(CantCMDINT, 0), 0 DIFERENTE, Zecimale, UMSEC, DEN_UM,
         MatEchiv, CodExtern, DataStartCmdInt, CodComanda1I, IndexParinte, 0
  FROM (SELECT Y.DENUMIRE, Y.CODOBIECT, Y.CODCMD1, Y.PREF, Y.NIVEL, Y.POZITIE, Y.CODPROIECTNOD, Y.NODORIGINAL, Y.Tip, Y.CANT, Y.TotRezervat, RestFurn.RestDeSosit,
               RestFurn.DataStart, CEREFURN.RestCerere, Y.STOC, Y.NECESARP, CMDI.CANTCMDINT,
               (SELECT COALESCE(u.Zecimale, 0)
                FROM NUM u, NART a, NARTOBJ o
                WHERE o.CodObiect = Y.CodObiect and  a.CodArticol = o.CodArticol and  u.CODUM = a.UM
               ) ZECIMALE,
               0 UMSEC,
               (SELECT DEN_UM
                FROM NUM u, NART a, NARTOBJ o
                WHERE o.CodObiect = Y.CodObiect and  a.CodArticol = o.CodArticol and  u.CODUM = a.UM
               ) DEN_UM,
               MatEchiv, CodExtern, cmdi.datastartcmdint::date, cmdi.codcomanda1 CODCOMANDA1I, Y.INDEXPARINTE
        FROM (SELECT NOBJ.DENUMIRE, NOBJ.CODOBIECT, COALESCE(NE.CODCOMANDA1, C1.CODCOMANDA1) CODCMD1, X.PREF, X.NIVEL, X.POZITIE, X.CODPROIECTNOD, X.NODORIGINAL,
                     X.Tip, X.CANT, REZ.TotRezervat, NS.REST * COALESCE(NE.PARITATE, 1) STOC, X.CANT / ORIG.CANT * COALESCE(NE.PARITATE, 1) NECESARP, x.MatEchiv, NOBJ.CodExtern, X.IndexParinte
              FROM COMANDA1 C1
                  INNER JOIN (SELECT PN0.CODPROIECTNOD NODORIG, PN.CODPROIECTNOD, PN.CODPROIECT, PN.CANT, PN.NODORIGINAL, PN.TIP, PN.CODOBIECT, PN.NIVEL, PN.POZITIE,
                                     SUBSTR(PN.INDEXPARINTE, 3, 47) PREF, CASE WHEN  MECHIV.Nr &gt; 0 THEN PN.Codprodmat ELSE 0 END  MATECHIV, PN.INDEXPARINTE
                              FROM PROIECTNOD PN
                                  INNER JOIN PROIECTNOD PN0 ON  PN0.CODPROIECT = PN.CODPROIECT AND  PN0.NODORIGINAL = 0
                                  LEFT  JOIN (SELECT count(*) NR, codmat FROM prodmat GROUP BY codmat) MECHIV ON  MECHIV.CODMAT = PN.CODPRODMAT
                             ) X ON  X.CODPROIECT = C1.CODPROIECT
                  LEFT JOIN PROIECTNOD ORIG ON  ORIG.CODPROIECTNOD = X.NODORIG
                  LEFT JOIN NODECHIV   NE   ON  NE.CODCOMANDA1     = C1.CODCOMANDA1 AND  NE.CODPROIECTNOD = X.CODPROIECTNOD
                  LEFT JOIN NARTOBJ    NOBJ ON  NOBJ.CODOBIECT     = COALESCE(NE.CODOBIECT, X.CODOBIECT)
                  LEFT JOIN ( SELECT sum(NSS.REST - coalesce((select sum(r.rest) from rezervats r where codnirstoc = nss.codnirstoc),0)) REST, NSS.CODOBIECT
                              FROM NIRSTOC NSS
                                  INNER JOIN NIR      ON  NSS.CODNIR = NIR.CodNIR
                                  INNER JOIN NGEST NG ON  NG.CODGEST = NIR.GEST
                              WHERE (G_SUBUNIT = 1 OR  NG.CodSubunit = G_SUBUNIT)
                              GROUP BY NSS.CODOBIECT
                            ) NS ON  NS.CODOBIECT = NOBJ.CODOBIECT
                  LEFT JOIN ( SELECT R.CodComanda1, NSR.CodObiect, SUM(R.REZERVATINI) TOTREZERVAT
                              FROM REZERVATS R INNER JOIN NIRSTOC NSR ON  R.CODNIRSTOC = NSR.CodNIRSTOC
                              GROUP BY R.CodCOmanda1, NSR.CodObiect
                            ) REZ ON  REZ.CodComanda1 = C1.CodComanda1 AND  NOBJ.CODOBIECT = REZ.CodObiect
              WHERE EXISTS (SELECT TMP.CODPROIECT  FROM TMP_SIM_CCOM1 TMP WHERE TMP.CODPROIECT  = X.CODPROIECT)
               AND  EXISTS (SELECT TMP.CODCOMANDA1 FROM TMP_SIM_CCOM1 TMP WHERE TMP.CODCOMANDA1 = COALESCE(NE.CODCOMANDA1, C1.CODCOMANDA1))
             ) Y
            LEFT JOIN ( SELECT L0.Codcmd1 CMDCLI1, L0.CODSCENARIU, L1.CODPROIECTNOD, SUM(C1.CANTAcceptat) CANTCMDINT, c1.datastart DATASTARTCMDINT, c1.codcomanda1
                        FROM LANSARE1 L1
                            INNER JOIN LANSARE0      L0  ON  L0.CodLansare0  = L1.CodLansare0
                            INNER JOIN TMP_SIM_CCOM1 CC1 ON  CC1.CODCOMANDA1 = L0.CodCmd1
                            INNER JOIN Comanda1      C1  ON  C1.CODCOMANDA1  = L1.CodCmd1
                        WHERE L0.CODSCENARIU = SCENARIU
                        GROUP BY L0.Codcmd1, L1.CODPROIECTNOD, L0.CODSCENARIU, c1.datastart, c1.codcomanda1
                      ) CMDI ON  CMDI.CmdCli1 = Y.CodCmd1 and  CMDI.Codproiectnod = Y.CODPROIECTNOD
            LEFT OUTER JOIN ( SELECT R.CodComanda1, NS.CodObiect, sum(r.rest) RESTDECONSUMAT
                              FROM rezervats r INNER JOIN nirstoc ns ON  ns.codnirstoc = r.codnirstoc
                              WHERE COALESCE(r.codnirstoc, 0) &gt; 0
                              GROUP BY NS.CodObiect, R.CodComanda1
                            ) RESTREZ ON  RESTREZ.CodObiect = Y.CodObiect AND  RESTREZ.CodComanda1 = Y.CodCmd1
            LEFT OUTER JOIN ( SELECT R.CodComanda1, R.CodObiect, Max(C1.Termen) DATASTART, sum(r.rest) RESTDESOSIT
                              FROM rezervats r INNER JOIN Comanda1 C1 ON  C1.CodComanda1 = r.CODCOMANDA1F
                              WHERE COALESCE(r.codnirstoc, 0) = 0 and  COALESCE(r.CODCOMANDA1F, 0) &lt;&gt; 0
                              GROUP BY r.CodObiect, r.codcomanda1
                            ) RESTFURN ON  RESTFURN.CodObiect = Y.CodObiect and  RESTFURN.CodComanda1 = Y.CodCmd1
            LEFT OUTER JOIN ( SELECT R.CodComanda1, R.CodObiect, sum(r.rest) RESTCERERE
                              FROM rezervats r
                              WHERE COALESCE(r.codnirstoc, 0) = 0 and  COALESCE(r.CODCOMANDA1F, 0) = 0
                              GROUP BY r.CodObiect, r.codcomanda1
                            ) CEREFURN ON  CEREFURN.CodObiect = Y.CodObiect and  CEREFURN.CodComanda1 = Y.CodCmd1
        ORDER BY Y.DENUMIRE
       ) A_PG
  WHERE NecesarP &gt; 0
  );

  INSERT INTO TMP_SIM_NODECHIV1(CODCOMANDA1, CODPROIECTNOD, CODOBIECT, CANT, PARITATE, TIP, CODOBIECTORIG, NODORIGINAL, STOC, CANTECHIVALATA, DENOBIECTECHIV, CODEXTERN)
  SELECT NE1.CODCOMANDA1, NE1.CODPROIECTNOD, NE1.CODOBIECT, NE1.CANT, NE1.PARITATE, NE1.TIP, L1.CODOBIECT, L1.NODORIGINAL, COALESCE(NS.REST, 0),
         NE1.CANT / NE1.PARITATE, OBJ.DENUMIRE, OBJ.CODEXTERN
  FROM TMP_SIM_LANS1 L1
      INNER JOIN NODECHIV1 NE1 ON  L1.CODCOMANDA1 = NE1.CODCOMANDA1 AND  L1.CODPROIECTNOD = NE1.CODPROIECTNOD
      INNER JOIN NARTOBJ OBJ ON  OBJ.CODOBIECT = NE1.CODOBIECT
      LEFT  JOIN (SELECT sum(NSS.REST) REST, NSS.CODOBIECT
                  FROM NIRSTOC NSS
                      INNER JOIN NIR      ON  NSS.CODNIR = NIR.CodNIR
                      INNER JOIN NGEST NG ON  NG.CODGEST = NIR.GEST
                  WHERE (G_SUBUNIT = 1 OR  NG.CodSubunit = G_SUBUNIT)
                  GROUP BY NSS.CODOBIECT
                 ) NS ON  NS.CODOBIECT = OBJ.CODOBIECT;

  IF  Scenariu = 0 THEN
    RezolvareLansari := 0;
  ELSE
    RezolvareLansari := 1;
  END IF;

  PERFORM PKG_SimLans_LoadScenariiLivr(Scenariu);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_conditieumprincipala</obj_name>
  <obj_hashval>1eaa190e68e5b372359f5362219b551e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_conditieumprincipala(INOUT wme_result numeric, INOUT ump numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
  IF  current_setting('PKG_SELECTARTICOLE.UMPRINCIPALA',TRUE)::NUMERIC = UMP THEN
    WME_Result :=  1;
    RETURN;
  ELSE
    WME_Result :=  0;
    RETURN;
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_selectarticole_getcod_obiect_analizat</obj_name>
  <obj_hashval>bb13bb07da9dcd39f1d6e88ea5c813b2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_selectarticole_getcod_obiect_analizat(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SELECTARTICOLE.COD_OBIECT_ANALIZAT')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 0;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_clear_dirty_flags</obj_name>
  <obj_hashval>0687f50ecfd010f86cceaab7fce1a480</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_clear_dirty_flags()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  UPDATE JURNAL1
  SET DIRTY = 0
  WHERE DIRTY &gt; 0 AND  AN * 12 + LUNA = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_interne_recordcount</obj_name>
  <obj_hashval>a0b0890d97921ee727fc9faa7d5b31a5</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_interne_recordcount(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 03.03.2023
  SELECT COUNT(1) INTO wme_result
  FROM TRANSF
  WHERE AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE_IS_DIRTY_DOC(TIPDOC, CODTRANSF) = 1;

  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_notecredit_for_jurnal</obj_name>
  <obj_hashval>429e58bdd2179492b0b12162a5e881cb</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_notecredit_for_jurnal(startrec numeric, endrec numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
BEGIN
  --Stef 30.01.2024
  PERFORM pkg_service_EMPTY_DOCUMENTE_FOR_NOTECREDIT();

  INSERT INTO TMP_NOTECREDIT (
      CodNCredit, CodContract2, CodPart, TipDoc, Subunitatea, DataStart,
      DataStop, CODCONTV, CODCONTT, CODCONTC, CODCONTP, DataStartD, DataStopD,
      DataFact, Contract, An, Luna, TipARticol, Obs, CodContract, CodMoneda,
      VolumPeArticole, CODCONTZ, PretBrutC, PretBrutV, CodCarnet, TipDiscV,
      Trimestriala, Corectie, COdNCCorectie, PrefixDoc, CarnetDoc, NrDoc,
      SeriaDoc, AreCarnetDoc, Previzionare, IesiriPeVolum, Curs, Inchisa)
  SELECT CodNCredit, CodContract2, CodPart, TipDoc, Subunitatea, DataStart,
      DataStop, CODCONTV, CODCONTT, CODCONTC, CODCONTP, DataStartD, DataStopD,
      DataFact, Contract, An, Luna, TipARticol, Obs, CodContract, CodMoneda,
      VolumPeArticole, CODCONTZ, PretBrutC, PretBrutV, CodCarnet, TipDiscV,
      Trimestriala, Corectie, COdNCCorectie, PrefixDoc, CarnetDoc, NrDoc,
      SeriaDoc, AreCarnetDoc, Previzionare, IesiriPeVolum, Curs, Inchisa
  FROM (
      SELECT row_number() over() RN, S.*
      FROM (
          SELECT NC.CodNCredit, NC.CodContract2, NC.CodPart, NC.TipDoc,
                NC.Subunitatea, NC.Datastart, NC.DataStop, nc.CODCONTV, nc.CODCONTT,
                nc.CODCONTC, nc.CODCONTP, NC.DataStart DATASTARTD,
                NC.DataStop DATASTOPD, CURRENT_TIMESTAMP DATAFACT,
                CASE  WHEN  COALESCE( NC.CodContract2, COALESCE( NC.CodContract, 0)) = 0 THEN '...fara...'
                      ELSE CASE WHEN  COALESCE( NC.CodContract, 0) = 0 THEN COALESCE(C.Nrdoc::varchar, '') || '/' || to_char( C.DataStart, 'DD.MM.YYYY') || '-' || to_char( C.DataStop, 'DD.MM.YYYY')
                                ELSE COALESCE(CNC.Nrdoc::varchar, '') || '/' || to_char( CNC.DataStart, 'DD.MM.YYYY') || '-' || to_char( CNC.DataStop, 'DD.MM.YYYY')
                           END
                END  CONTRACT,
                NC.An, NC.Luna, NC.TipArticol, NC.Obs,
                CASE WHEN  COALESCE( nc.codcontract2, 0) = 0 THEN NC.CodContract
                     ELSE C.Codcontract
                END  CODCONTRACT,
                COALESCE( NC.CodMoneda, C.Moneda) CODMONEDA,
                COALESCE( NC.VOLUMPEARTICOLE, 0) VOLUMPEARTICOLE,
                nc.CODCONTZ,
                COALESCE( nc.pretbrutc, 0) PRETBRUTC,
                COALESCE( nc.pretbrutv, 0) PRETBRUTV,
                nc.codcarnet,
                CASE WHEN  CASE WHEN  COALESCE( NC.CodContract2, 0)=0 THEN COALESCE( NC.CodContract, 0)
                                ELSE  NC.CodContract2
                           END  = 0 THEN CASE WHEN  COALESCE( NC.Volumpearticole, 0) = 0 THEN 3
                                              ELSE 4
                                         END
                     ELSE CASE WHEN  COALESCE( NC.CodContract, 0) = 0 THEN COALESCE( C.TIPTARGETV, 0)
                               ELSE COALESCE( CNC.TIPTARGETV, 0)
                          END
                END  TIPDISCV,
                COALESCE( NC.Trimestriala, 0) TRIMESTRIALA,
                NC.Corectie, NC.CodNCCorectie, NC.PrefixDoc, NC.CarnetDoc, NC.NrDoc, NC.SeriaDoc,
                case WHEN  COALESCE( NC.CARNETDOC, 0)=0 THEN 0
                     ELSE  1
                END  ARECARNETDOC,
                NC.Previzionare, NC.IesiriPeVolum, NC.Curs, NC.Inchisa
        FROM NOTECREDIT NC
          LEFT JOIN CONTRACT2 C2  ON  NC.CODCONTRACT2 = C2.CODCONTRACT2
          LEFT JOIN CONTRACT  C   ON  C2.CODCONTRACT  = C.CODCONTRACT
          LEFT JOIN CONTRACT  CNC ON  CNC.Codcontract = nc.codcontract
        WHERE NC.AN * 12 + NC.LUNA = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X)
          AND PKG_SERVICE_IS_DIRTY_DOC(NC.TIPDOC, NC.CODNCREDIT) = 1
        ORDER BY  NC.CodNCredit
        ) S
    ) A_PG
    WHERE
        RN &gt;= STARTREC AND  RN &lt;= ENDREC;

    INSERT INTO TMP_NOTECREDITT(CODNCREDIT1, CODNCREDIT, VALOARE,VALOAREOLD, CODANALIZANOD, CODCENTRU)
    SELECT CODNCREDIT1, CODNCREDIT, VALOARE, VALOAREOLD, CODANALIZANOD, CODCENTRU
    FROM NOTECREDIT1
    WHERE  CODNCREDIT IN (SELECT CODNCREDIT FROM TMP_NOTECREDIT)
      AND  TIP = current_setting('PKG_SERVICE.tncTermen', true)::numeric;

    INSERT INTO TMP_NOTECREDITV (CODNCREDIT1, CODNCREDIT, VALOARE, VALOAREOLD, CODANALIZANOD, CODCENTRU)
    SELECT CODNCREDIT1, CODNCREDIT, VALOARE, VALOAREOLD, CODANALIZANOD, CODCENTRU
    FROM NOTECREDIT1
    WHERE
        CODNCREDIT IN (SELECT CODNCREDIT FROM TMP_NOTECREDIT )
    AND  TIP = current_setting('PKG_SERVICE.tncVolum', true)::numeric;

    INSERT INTO TMP_NOTECREDITC (CODNCREDIT1, CODNCREDIT, VALOARE, VALOAREOLD, CODANALIZANOD, CODCENTRU)
    SELECT CODNCREDIT1, CODNCREDIT, VALOARE, VALOAREOLD, CODANALIZANOD, CODCENTRU
    FROM NOTECREDIT1
    WHERE
        CODNCREDIT IN (SELECT CODNCREDIT FROM TMP_NOTECREDIT)
      AND  TIP = current_setting('PKG_SERVICE.tncCantitate', true)::numeric;

    INSERT INTO TMP_NOTECREDITP(CODNCREDIT1, CODNCREDIT, VALOARE, VALOAREOLD, CODANALIZANOD, CODCENTRU)
    SELECT CODNCREDIT1, CODNCREDIT, VALOARE, VALOAREOLD, CODANALIZANOD, CODCENTRU
    FROM NOTECREDIT1
    WHERE
        CODNCREDIT IN (SELECT CODNCREDIT FROM TMP_NOTECREDIT)
      AND  TIP = current_setting('PKG_SERVICE.tncPenalizari', true)::numeric;

    INSERT INTO TMP_NOTECREDITZ (
        CodNCredit1, CodNCredit, Valoare, CodObligStins, CodDoc, TipDoc,
        CodObligStingator, Obs, ValDif, Valoareold, DOC, NRDOC, DATADOC,
        MONEDA, SEDIU, CURS, VALDOC, VALLEI, DISCOUNT, DENCRITERIU, DEN_CLASEDISC,
        CODCLASEDISC, CODNCREDIT1ORIG, CODDISCOUNT, PROCTVA, CODANALIZANOD, CODCENTRU)
    SELECT NC1.CodNCredit1, NC1.CodNCredit, NC1.Valoare, I.CodIes, NC1.CodDoc,
        NC1.TipDoc, NC1.CodObligStingator, NC1.Obs, NC1.ValDif, NC1.Valoareold,
        I.PREFIXDOC DOC, I.NRDOC NRDOC, I.DATADOC DATADOC,
        (SELECT PKG_MONEDE_GET_SIMBOL_MONEDA.WME_RESULT FROM PKG_MONEDE_GET_SIMBOL_MONEDA(NULL, G.MONEDA)) MONEDA,
        A.OBS SEDIU, case WHEN  COALESCE( GREG.CURS, G.CURS)=0 THEN 1
                          ELSE  COALESCE( GREG.CURS, G.CURS)
                     END  CURS, I.ValDoc - I.TVADOC,
        ROUND( (  I.ValDoc - I.TVADOC)  * case WHEN  COALESCE( GREG.CURS, G.CURS)=0 THEN 1
                            ELSE  COALESCE( GREG.CURS, G.CURS)
                          END , 4) VALLEI,
        0, CD.DENCRITERIU, CLSDISC.DEN_CLASEDISC, CLSDISC.CODCLASEDISC,
        NC1.CODNCREDIT1ORIG, NC1.CODDISCOUNT, COALESCE( nc1.proctva, 24), CODANALIZANOD, CODCENTRU
    FROM NOTECREDIT1 NC1
      INNER JOIN NOTECREDIT   NC ON  NC.CODNCREDIT = NC1.CODNCREDIT
      LEFT  JOIN IESDISC      ID ON  NC1.CODDOC = ID.CODIESDISC
      LEFT  JOIN DISCOUNT     D  ON  COALESCE( ID.CODDISCOUNT, NC1.CODDISCOUNT) = D.CODDISCOUNT
      LEFT  JOIN CRITERIIDISC CD ON  CD.CODCRITERIU = D.CODCRITERIU
      LEFT  JOIN IESIRI       I  ON  I.CODIES = ID.CodIes AND  NC1.TipDoc = I.TipDoc
      LEFT  JOIN NCLASEDISC   CLSDISC ON  CLSDISC.CODCLASEDISC = CD.CLASA
      LEFT  JOIN GENERAL      G  ON  I.CODIES = G.CODDOC AND  I.TipDoc = G.TipDoc
      LEFT  JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON  GREG.CODGENERAL = G.CODGENERAL
      LEFT  JOIN NAGENDA      A  ON  A.CODAGENDA = I.CODLOCATIE
    WHERE
        NC1.CodNCredit IN (
            SELECT CODNCREDIT
          FROM TMP_NOTECREDIT)
      AND  NC1.Tip = current_setting('PKG_SERVICE.tncProvizioane', true)::numeric
      AND  COALESCE( g.semnificatie, 0) &lt;&gt; 240
      and  COALESCE( g.semnificatie, 0) &lt;&gt; 500
      and  COALESCE( g.semnificatie, 0) &lt;&gt; 211
      and  COALESCE( g.semnificatie, 0) &lt;&gt; 210;

  FOR v_rec in (
          with IProc as (
                    select distinct I1.CodIes1, PKG_LIST_BASE_UTILS_CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1) ProcTVA
                      FROM tmp_notecreditz ncz
                           INNER JOIN TMP_NOTECREDIT N    ON N.CODNCREDIT = NCZ.CODNCREDIT AND N.TIPDOC = 58
                           inner join iesdisc        id   on id.codiesdisc = NCZ.CODDOC
                           inner join iesiri         i    on id.codies = i.codies
                           inner join iesiri1        I1   on i.codies = i1.codies
                           INNER JOIN nartobj        obj  ON i1.codobiect = obj.codobiect
                           INNER JOIN nart1          art1 ON art1.codarticol = obj.codarticol
                           INNER JOIN ntva1          tva1 ON tva1.codtva = art1.codtva
                      where I.AN*12+I.LUNA BETWEEN ART1.ALSTART AND ART1.ALSTOP
                        AND I.AN*12+I.LUNA BETWEEN TVA1.ALSTART AND TVA1.ALSTOP
                      ),
                      IProcVal as (
                                    select IProc.ProcTVA, I.CodIes,
                                           sum(i1.PretOrig*i1.cant*coalesce(i1.coefdiscmaj,1) -
                                               case
                                                 when not i.tipdoc in (16,21) then 0
                                                 else i1.PretOrig*i1.cant*coalesce(i1.coefdiscmaj,1)*
                                                        (select wme_result
                                                         from pkg_list_base_utils_get_cota_tva_art(null,i1.codobiect, i.an, i.luna))/100
                                               end) BazaTVA
                                    FROM (select distinct id.codies
                                          from tmp_notecreditz ncz
                                               inner join iesdisc id on id.codiesdisc = NCZ.CODDOC) ii
                                          inner join iesiri i on ii.codies = i.codies
                                          inner join iesiri1 I1 on i.codies = i1.codies
                                          INNER JOIN IProc ON i1.codies1 = IProc.codies1
                                    group by IProc.ProcTVA, I.CodIes
                                   )
      SELECT ncz.codncredit1, id.procent * IProcVal.BazaTVA / 100 VALDISC
      FROM tmp_notecreditz ncz
        INNER JOIN iesdisc id ON  id.codiesdisc = NCZ.CODDOC
        INNER JOIN IProcVal ON  IProcVal.CodIes = id.COdIes and  ncz.proctva = IProcVal.ProcTVA
      WHERE
          id.offinvoice = 2 and  ncz.coddoc &gt; 0
  ) LOOP
      UPDATE tmp_notecreditz
      set discount = v_Rec.valdisc
      where
        codncredit1 = v_rec.codncredit1 and  coddoc &gt; 0;
  END LOOP;

  FOR v_rec in (
    SELECT ncz.codncredit1, n1.valoare VALDISC, n1.proctva
    FROM tmp_notecreditz ncz
    INNER JOIN notecredit1 n1 ON  n1.codncredit1 = ncz.codncredit1orig
    WHERE
        COALESCE( ncz.coddoc, 0) = 0
    ) LOOP
      UPDATE tmp_notecreditz
      set discount = v_Rec.valdisc
      WHERE
        codncredit1 = v_rec.codncredit1 and  COALESCE( coddoc, 0) = 0 and  proctva = v_rec.proctva;
  END LOOP;

  FOR v_rec IN(
        with IProc as (
                    select distinct I1.CodIes1,
                           case
                             when (I1.CANT * I1.PU - (case when I.TIPDOC = 16 then coalesce(I1.TVA,0)
                                              when I.TIPDOC = 21 then coalesce(I1.TVA,0)
                                              else 0 end)) = 0 then tva1.procent
                             else pkg_list_base_utils_match_tva_proc(coalesce(I1.TVA,0)/(I1.CANT * I1.PU -
                                           (case when I.TIPDOC = 16 then coalesce(I1.TVA,0)
                                              when I.TIPDOC = 21 then coalesce(I1.TVA,0)
                                              else 0 end))*100, I.An*12+I.LUNA)
                           end ProcTVA
                    FROM tmp_notecreditz ncz
                         INNER JOIN TMP_NOTECREDIT N ON N.CODNCREDIT = NCZ.CODNCREDIT AND N.TIPDOC &lt;&gt; 58
                         inner join iesdisc id on id.codiesdisc = NCZ.CODDOC
                         inner join iesiri i on id.codies = i.codies
                         inner join iesiri1 I1 on i.codies = i1.codies
                         INNER JOIN nartobj obj ON i1.codobiect = obj.codobiect
                         INNER JOIN nart1 art1 ON art1.codarticol = obj.codarticol
                         INNER JOIN ntva1 tva1 ON tva1.codtva = art1.codtva
                    where I.AN*12+I.LUNA BETWEEN ART1.ALSTART AND ART1.ALSTOP
                      AND I.AN*12+I.LUNA BETWEEN TVA1.ALSTART AND TVA1.ALSTOP
                    ),
                    IProcVal as (
                                  select IProc.ProcTVA, I.CodIes,
                                         sum(i1.PretOrig*i1.cant*coalesce(i1.coefdiscmaj,1) -
                                             case
                                               when not i.tipdoc in (16,21) then 0
                                               else i1.PretOrig*i1.cant*coalesce(i1.coefdiscmaj,1)*
                                                  (select wme_result
                                                         from pkg_list_base_utils_get_cota_tva_art(null,i1.codobiect, i.an, i.luna))/100
                                             end) BazaTVA
                                  FROM tmp_notecreditz ncz
                                       inner join iesdisc id on id.codiesdisc = NCZ.CODDOC
                                       inner join iesiri i on id.codies = i.codies
                                       inner join iesiri1 I1 on i.codies = i1.codies
                                       INNER JOIN IProc ON i1.codies1 = IProc.codies1
                                  group by IProc.ProcTVA, I.CodIes
                                 )

        SELECT ncz.codncredit1, id.procent * IProcVal.BazaTVA / 100 VALDISC
        FROM tmp_notecreditz ncz
        INNER JOIN iesdisc id ON  id.codiesdisc = NCZ.CODDOC
        INNER JOIN IProcVal ON  IProcVal.CodIes = id.COdIes and  ncz.proctva = IProcVal.ProcTVA
        WHERE
           id.offinvoice = 3
  ) LOOP
      UPDATE tmp_notecreditz
      SET discount = v_Rec.valdisc
      WHERE
        codncredit1 = v_rec.codncredit1 and  coddoc &gt; 0;
  END LOOP;

  FOR v_rec in (
          SELECT ncz.codncredit1, n1.valoare VALDISC, n1.proctva
          FROM tmp_notecreditz ncz
          INNER JOIN notecredit1 n1 ON  n1.codncredit1 = ncz.codncredit1orig
          WHERE
             COALESCE( ncz.coddoc, 0) = 0
  ) LOOP
      UPDATE tmp_notecreditz
      SET discount = v_Rec.valdisc
      WHERE
        codncredit1 = v_rec.codncredit1 and  COALESCE( coddoc, 0) = 0 and  proctva = v_rec.proctva  ;
  END LOOP;

  UPDATE tmp_notecreditz
  set discount = valoare
  WHERE
    COALESCE( coddoc, 0) = 0 and  COALESCE( codncredit1orig, 0) = 0;

  UPDATE tmp_notecredit n
  set
    TOTALT     = (SELECT Round( sum( valdoc), 2) FROM tmp_notecreditt WHERE CODNCREDIT = N.CODNCREDIT),
    TOTALLEIT  = (SELECT Round( sum( vallei), 2) FROM tmp_notecreditt WHERE CODNCREDIT = N.CODNCREDIT),
    TOTALV     = (SELECT Round( sum( valdoc), 2) FROM tmp_notecreditv WHERE CODNCREDIT = N.CODNCREDIT),
    TOTALLEIV  = (SELECT Round( sum( vallei), 2) FROM tmp_notecreditv WHERE CODNCREDIT = N.CODNCREDIT),
    TOTALC     = (SELECT Round( sum( val), 2)    FROM tmp_notecreditc WHERE CODNCREDIT = N.CODNCREDIT),
    TOTALLEIC  = (SELECT Round( sum( vallei), 2) FROM tmp_notecreditc WHERE CODNCREDIT = N.CODNCREDIT),
    TOTALP     = (SELECT Round( sum( valdoc), 2) FROM tmp_notecreditp WHERE CODNCREDIT = N.CODNCREDIT),
    TOTALLEIP  = (SELECT Round( sum( vallei), 2) FROM tmp_notecreditp WHERE CODNCREDIT = N.CODNCREDIT),
    TOTALZ     = (SELECT Round( SUM( valdoc), 2) FROM tmp_notecreditz WHERE codobligstins &gt; 0 AND  CODNCREDIT = N.CODNCREDIT ),
    TOTALLEIZ  = (SELECT Round( sum( vallei), 2) FROM tmp_notecreditz WHERE codobligstins &gt; 0 AND  CODNCREDIT = N.CODNCREDIT ),
    TOTALDISCZ = (SELECT Round( sum( valoare - COALESCE( valoareold, 0)), 2) FROM tmp_notecreditz WHERE CODNCREDIT = N.CODNCREDIT);

    UPDATE tmp_notecredit
    set
      TOTALZ    = TOTALZ    + (SELECT COALESCE( Round( sum( valdoc), 2), 0) FROM tmp_notecreditz WHERE COALESCE( codobligstins, 0) = 0),
      TOTALLEIZ = TOTALLEIZ + (SELECT COALESCE( Round( sum( vallei), 2), 0) FROM tmp_notecreditz WHERE COALESCE( codobligstins, 0) = 0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_postcalcul_for_jurnal</obj_name>
  <obj_hashval>d1d7dda929ff753f52d90a6faecea42d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_postcalcul_for_jurnal(startrec numeric, endrec numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  TipValMatPC numeric;
begin
  --Stef 03.03.2023
  --Laura 27.01.2022 - sinc. Oracle (29.12.2021)
  --Bogdan 20.08.2020
  DELETE FROM TMP_PCALCUL;
  DELETE FROM TMP_PCGEST;
  DELETE FROM TMP_PCART;
  DELETE FROM TMP_PCSECTII;
  DELETE FROM TMP_PCSECTII2;
  DELETE FROM TMP_PCSECTII3;
  DELETE FROM TMP_PCSECTII5;

  INSERT INTO TMP_PCALCUL(
      CODPC, AN, LUNA, SUBUNITATEA, CUMULAT, operat, VARIANTA, DATADOC, TIPPUNCT, OBSERVATII, TipAloc, ValF)
  SELECT CODPC, AN, LUNA, SUBUNITATEA, CUMULAT, operat, VARIANTA, DATADOC, TIPPUNCT, OBSERVATII, TipAloc, ValF
  FROM (
    SELECT row_number() over() AS RN, S.*
    FROM (
        SELECT CODPC, AN, LUNA, SUBUNITATEA, CUMULAT, operat, VARIANTA, DATADOC, TIPPUNCT, OBSERVATII, COALESCE( TipAloc, 0) AS TIPALOC, ValF
        FROM PCALCUL
        WHERE AN * 12 + LUNA = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X)
          AND PKG_SERVICE_IS_DIRTY_DOC(72, CODPC) = 1
        ORDER BY  CODPC
        ) S
    ) A_PG
  WHERE
       RN &gt;= STARTREC AND  RN &lt;= ENDREC;

  INSERT INTO TMP_PCGEST (CODPCGEST, CODPC, CODGEST, MANS, PUNCTE, VALi, VALA, ValG, ValC, VALMAT, VALMAN, ValPUNCT, COEFMAN, DENGEST, ValD, ValS, TOTAL)
  SELECT PCG.CODPCGEST, PCG.CODPC, PCG.CODGEST, PCG.ManS, PCG.Puncte,
      PCG.VALi, PCG.VALa, PCG.ValG, PCG.ValC, PCG.VALMAT, PCG.VALMAN,
      CASE COALESCE( PCG.Puncte, 0) WHEN 0 THEN 0
          ELSE COALESCE( (  COALESCE( PCG.VALi, 0) + COALESCE( PCG.VALA, 0) + COALESCE( PCG.ValG, 0) + COALESCE( PCG.ValC, 0)) , 0) / PCG.Puncte
       END ,
       CASE COALESCE( PCG.MANS, 0) WHEN 0 THEN 0
           ELSE COALESCE( PCG.VALMAN, 0) / COALESCE( PCG.MANS, 0)
       END ,
      CASE PCG.CODGEST WHEN 0 THEN '.TOTAL'
           ELSE Substr( G.DEN_GEST, 1, 30)
      END ,
      PCG.VALMAT + PCG.VALMAN,
      PCG.VALi + PCG.VALA + PCG.ValG + PCG.ValC,
      PCG.VALMAT + PCG.VALMAN + PCG.VALi + PCG.VALA + PCG.ValG + PCG.ValC
  FROM PCGEST PCG
    LEFT JOIN NGEST G ON  G.CODGEST = PCG.CODGEST
  WHERE
      PCG.CODPC IN (SELECT CODPC FROM TMP_PCALCUL);

  TipValMatPC := fnc_getvalconstanta('TipValMatPC', getAnLucru(), getLunaLucru());

  INSERT INTO TMP_PCART (
      CODPCART, CODPC, CODCMD1, CODIOART, CANT, VAL, VALS, VALi, VALa, ValG, ValC, MAT, CODGEST,
      CODFORMATIE, COEF, MAN, VALMAN, CODCC, REST, ANLUNA, PUCALC, PretMat, CODOBIECT, PUNCTE,
      CENTRU, DENOBIECT, DENIOART, DENUM, PRETREFERINTA, PRETRETETA)
  SELECT PCA.CODPCART, PCA.CODPC, PCA.CODCMD1, PCA.CODIOART, COALESCE( PCA.CANT, 0),
      PCA.VAL, PCA.VALS, PCA.VALi, PCA.VALa, PCA.ValG, ValC, PCA.MAT, PCA.CODGEST,
      PCA.CODFORMATIE, PCA.COEF, PCA.MAN, PCA.VALMAN, PCA.CODCC, MAT.REST,
      (  PCC.AN * 12 + PCC.LUNA)  - (  C.AN * 12 + C.LUNA) ,
      Round( CASE WHEN  COALESCE( PCA.CANT, 0) = 0 THEN 0
                   ELSE CASE WHEN  TipValMatPC = 2 THEN (  COALESCE( PCA.MAT, 0) + COALESCE( PCA.MAN, 0) + COALESCE( PCA.VALS, 0))  / COALESCE( PCA.CANT, 0)
                             ELSE (  COALESCE( PCA.VAL, 0) + COALESCE( PCA.MAN, 0) + COALESCE( PCA.VALS, 0))  / COALESCE( PCA.CANT, 0)
                        END
              END , 5),
       Round( CASE WHEN  COALESCE( PCA.CANT, 0) = 0 THEN 0
                   ELSE COALESCE( PCA.MAT, 0) / COALESCE( PCA.CANT, 0)
              END , 5),
       C1.CODOBIECT, PCA.PUNCTE, CC.Simbol, OBJ.DENUMIRE, Substr( IOA.DEN_IOART, 1, 50), Substr( UM.DEN_UM, 1, 15), OBJ1.PRETREFERINTA, PC.PRET
  FROM PCART PCA
    INNER JOIN PCALCUL    PCC  ON  PCC.CODPC       = PCA.CODPC
    LEFT  JOIN NGEST      G    ON  G.CODGEST       = PCA.CODGEST
    LEFT  JOIN CENTRECOST CC   ON  CC.CODCENTRU    = PCA.CODCC
    LEFT  JOIN COMANDA1   C1   ON  PCA.CODCMD1     = C1.CODCOMANDA1
    INNER JOIN COMANDA    C    ON  C.CODCOMANDA    = C1.CODCOMANDA
    LEFT  JOIN CMDPRODMAT MAT  ON  MAT.CODCOMANDA1 = C1.CODCOMANDA1 AND  MAT.TIP = 0
    LEFT  JOIN PRODCOMP   PC   ON  PC.CODPRODCOMP  = C1.CODRETETA
    LEFT  JOIN NARTOBJ    OBJ  ON  OBJ.CODOBIECT   = C1.CODOBIECT
    LEFT  JOIN NARTOBJ1   OBJ1 ON  OBJ1.CODOBIECT  = OBJ.CODOBIECT
    LEFT  JOIN NART       ART  ON  OBJ.CODARTICOL  = ART.CODARTICOL
    LEFT  JOIN NUM        UM   ON  UM.CODUM        = ART.UM
    LEFT  JOIN IOART      IOA  ON  PCA.CODIOART    = IOA.CODIOART
  WHERE
      PCA.CODPC IN (SELECT CODPC FROM TMP_PCALCUL )
    AND PCC.AN*12+PCC.LUNA BETWEEN obj1.ALSTART AND obj1.ALSTOP;

  INSERT INTO TMP_PCSECTII (CODPCSECTII, CODPC, CODNEST, VAL, FAZA, CODD, CODC, CODCC, CODGEST, DENGEST, CENTRU, DEBIT, CREDIT)
  SELECT PCS.CODPCSECTII, PCS.CODPC, PCS.CODNEST, PCS.VAL, PCS.FAZA, debit.codcont, CREDIT.CODCONT,
        NS.CODCENTRU, NS.CODGEST, Substr( G.DEN_GEST, 1, 30), CC.Simbol, Substr( DEBIT.SIMBOL, 1, 20), Substr( CREDIT.SIMBOL, 1, 20)
  FROM PCSECTII PCS
    LEFT JOIN NESTJURNAL NS     ON  PCS.CODNEST  = NS.CODNESTJURNAL
    LEFT JOIN NGEST      G      ON  G.CODGEST    = NS.CODGEST
    LEFT JOIN CENTRECOST CC     ON  CC.CODCENTRU = NS.CODCENTRU
    LEFT JOIN NCONT      DEBIT  ON  NS.CODCONTD  = DEBIT.CODCONT
    LEFT JOIN NCONT      CREDIT ON  NS.CODCONTC  = CREDIT.CODCONT
  WHERE
      PCS.CODPC IN (SELECT CODPC FROM TMP_PCALCUL)
    and  PCS.FAZA = 0;

  INSERT INTO TMP_PCSECTII2(CODPCSECTII2, CODPC, CODNEST, VAL, FAZA, CODD, CODC, CODCC, CODGEST, DENGEST, CENTRU, DEBIT, CREDIT)
  SELECT PCS.CODPCSECTII, PCS.CODPC, PCS.CODNEST, PCS.VAL, PCS.FAZA, debit.codcont,
      CREDIT.CODCONT, NS.CODCENTRU, NS.CODGEST, Substr( G.DEN_GEST, 1, 30),
      CC.Simbol, Substr( DEBIT.SIMBOL, 1, 20), Substr( CREDIT.SIMBOL, 1, 20)
  FROM PCSECTII PCS
    LEFT JOIN NESTJURNAL NS     ON  PCS.CODNEST  = NS.CODNESTJURNAL
    LEFT JOIN NGEST      G      ON  G.CODGEST    = NS.CODGEST
    LEFT JOIN CENTRECOST CC     ON  CC.CODCENTRU = NS.CODCENTRU
    LEFT JOIN NCONT      DEBIT  ON  NS.CODCONTD  = DEBIT.CODCONT
    LEFT JOIN NCONT      CREDIT ON  NS.CODCONTC  = CREDIT.CODCONT
  WHERE
      PCS.CODPC IN (SELECT CODPC FROM TMP_PCALCUL)
    and  PCS.FAZA = 2;

  INSERT INTO TMP_PCSECTII3 (CODPCSECTII3, CODPC, CODNEST, VAL, FAZA, CODD, CODC, CODCC, CODGEST, DENGEST, CENTRU, DEBIT, CREDIT)
  SELECT PCS.CODPCSECTII, PCS.CODPC, PCS.CODNEST, PCS.VAL, PCS.FAZA, debit.codcont,
        CREDIT.CODCONT, NS.CODCENTRU, NS.CODGEST,
        Substr( G.DEN_GEST, 1, 30), CC.Simbol, Substr( DEBIT.SIMBOL, 1, 20), Substr( CREDIT.SIMBOL, 1, 20)
  FROM PCSECTII PCS
    LEFT JOIN NESTJURNAL NS     ON  PCS.CODNEST  = NS.CODNESTJURNAL
    LEFT JOIN NGEST      G      ON  G.CODGEST    = NS.CODGEST
    LEFT JOIN CENTRECOST CC     ON  CC.CODCENTRU = NS.CODCENTRU
    LEFT JOIN NCONT      DEBIT  ON  NS.CODCONTD  = DEBIT.CODCONT
    LEFT JOIN NCONT      CREDIT ON  NS.CODCONTC  = CREDIT.CODCONT
  WHERE
      PCS.CODPC IN (SELECT CODPC FROM TMP_PCALCUL)
      and  PCS.FAZA = 3;

  INSERT INTO TMP_PCSECTII5 (CODPCSECTII5, CODPC, CODNEST, VAL, FAZA, CODD, CODC, CODCC, CODGEST, DENGEST, CENTRU, DEBIT, CREDIT)
  SELECT PCS.CODPCSECTII, PCS.CODPC, PCS.CODNEST, PCS.VAL, PCS.FAZA, debit.codcont,
      CREDIT.CODCONT, NS.CODCENTRU, NS.CODGEST, Substr( G.DEN_GEST, 1, 30),
      CC.Simbol, Substr( DEBIT.SIMBOL, 1, 20), Substr( CREDIT.SIMBOL, 1, 20)
  FROM PCSECTII PCS
    LEFT JOIN NESTJURNAL NS     ON  PCS.CODNEST  = NS.CODNESTJURNAL
    LEFT JOIN NGEST      G      ON  G.CODGEST    = NS.CODGEST
    LEFT JOIN CENTRECOST CC     ON  CC.CODCENTRU = NS.CODCENTRU
    LEFT JOIN NCONT      DEBIT  ON  NS.CODCONTD  = DEBIT.CODCONT
    LEFT JOIN NCONT      CREDIT ON  NS.CODCONTC  = CREDIT.CODCONT
  WHERE
      PCS.CODPC IN (SELECT CODPC FROM TMP_PCALCUL)
    and  PCS.FAZA = 5;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_regtrezor_for_jurnal</obj_name>
  <obj_hashval>6ae30a9fc76e2c6efc330ba0fc102a9c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_regtrezor_for_jurnal(startrec numeric, endrec numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC_MARE RECORD;
  V_REC      RECORD;
  REG1CONT_IDX_LOCAL numeric(10) := 0;
  REG1_IDX_LOCAL     NUMERIC(20);
  PARAM_REG_DATA     date;
  PARAM_REG_MONEDA   NUMERIC(20);
  PARAM_REG_CURS     NUMERIC(20,7);
  DIFERENTE          numeric(1) := 0;
  DATANEXTREG        date;
  CODNEXTREG         NUMERIC(20);
  AnPrecedentReg     NUMERIC(20);
  LunaPrecedentaReg  NUMERIC(20);
BEGIN
  --Stef 03.03.2023
  --Florin 17.08.2022 - sinc. Oracle
  --Bogdan 18.08.2020
  PERFORM PKG_SERVICE_EMPTY_DOCUMENTE_FOR_REGTREZOR();
  DELETE FROM TMP_REG;

  INSERT INTO TMP_REG(
      CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs,
      Dirty, Obs, CodSubunit, SimbolMoneda, SimbolBank, Provizion,
      An, Luna, CODGEST, CodCentru, CodAnalizaNod)
  SELECT CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs,
      Dirty, Obs, CodSubunit, SimbolMoneda, SimbolBank, Provizion,
      An, Luna, CODGEST, CodCentru, CodAnalizaNod
  FROM (
      SELECT row_number() over() RN, R.CodReg, R.TipReg, R.NrDoc, R.DataDoc, R.CodBank,
        R.CodMoneda, R.Curs, R.Dirty, R.Obs, R.CodSubunit, M.Simbol AS SIMBOLMONEDA,
        B.Simbol AS SIMBOLBANK, R.Provizion, R.An, R.Luna, R.CODGEST, R.CodCentru, R.CodAnalizaNod
      FROM TMP_PKG_GLOBALS X, REG R
        LEFT JOIN NMONEDE M ON  M.CODMONEDA = R.CODMONEDA
        LEFT JOIN NBANK   B ON  B.CODBANK   = R.CODBANK
      WHERE
         TIPREG = 45 AND  AN = X.ANLUCRU AND  LUNA = X.LUNALUCRU
         AND PKG_SERVICE_IS_DIRTY_DOC(45, R.CODREG) = 1
    ) A_PG
  WHERE
       RN &gt;= STARTREC AND  RN &lt;= ENDREC;

  DELETE FROM TMP_REGTREZOR1;

  FOR V_REC_MARE IN (SELECT * FROM TMP_REG) LOOP
    DELETE FROM TMP_REGTREZOR1_MARTOR;
    INSERT INTO TMP_REGTREZOR1_MARTOR (CODBANKCONT, SOLDDOCVAL)
    SELECT CODBANKCONT, SOLDDOCVAL FROM REGTREZOR1 WHERE CODREG = V_REC_MARE.CODREG;

    SELECT V_REC_MARE.DataDoc, V_REC_MARE.CodMoneda, V_REC_MARE.Curs
    INTO PARAM_REG_DATA, PARAM_REG_MONEDA, PARAM_REG_CURS;

    PERFORM PKG_REG_SetParamsReg( TO_CHAR( PARAM_REG_DATA, 'DD.MM.YYYY'), PARAM_REG_MONEDA, PARAM_REG_CURS::NUMERIC);

    PERFORM PKG_GLOBALS_SETLUNATEMP( getAnLucru(), getLunaLucru());
    select  PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA.newan, PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA.newluna
        from PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( getAnLucru(), getLunaLucru(), AnPrecedentReg, LunaPrecedentaReg)
              into AnPrecedentReg, LunaPrecedentaReg;
    PERFORM PKG_GLOBALS_SETLUNAPRECEDENTA( AnPrecedentReg, LunaPrecedentaReg);

    INSERT INTO TMP_REGTREZOR1 (
        CODREG, CodRegTrezor1, SoldDoc, SoldDocVal, SoldDocReg, CodBank, CodBankCont,
        Diferenta, Den_Cont, NrCont, Filiala, Credit, SUBUNITATEA)
    (SELECT V_REC_MARE.CODREG,
        -1 * row_number() over(),
          T1.SoldValuta, T1.SoldLei,
          T1.SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(NULL,NULL)),
          NBC.CodBank, T1.CodBankCont,
          T1.SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(NULL,NULL)) - T1.SoldLei,
          NBC.Den_Cont, NBC.NrCont, NBC.Filiala, NBC.Credit, NBC.SUBUNITATEA
    FROM (SELECT SoldValuta, SoldLei, CodBankCont FROM V_SOLDURIBANCILUNA) T1
      INNER JOIN NBANKCONT NBC ON  NBC.CodBankCont = T1.CodBankCont and coalesce(NBC.FARAREG, 0) = 0
    WHERE
         NBC.CodMoneda = pkg_reg_getmonedareg()
         AND  T1.SoldValuta * (SELECT PKG_REG_GetCursReg.WME_RESULT FROM PKG_REG_GetCursReg(NULL,NULL)) - T1.SoldLei &lt;&gt; 0);

    DIFERENTE := 0;
    FOR V_REC IN (
      SELECT INTBL.CODBANKCONT, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT
      FROM TMP_REGTREZOR1_MARTOR INTBL
        LEFT JOIN TMP_REGTREZOR1 OUTTBL ON  OUTTBL.CODBANKCONT = INTBL.CODBANKCONT
      WHERE OUTTBL.CODREG = V_REC_MARE.CODREG
      union
      SELECT OUTTBL.CODBANKCONT, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT
      FROM TMP_REGTREZOR1 OUTTBL
        LEFT JOIN TMP_REGTREZOR1_MARTOR INTBL ON  INTBL.CODBANKCONT = OUTTBL.CODBANKCONT
      WHERE OUTTBL.CODREG = V_REC_MARE.CODREG
    ) LOOP
        IF  COALESCE( V_REC.SOLDIN, 0) &lt;&gt; COALESCE( V_REC.SOLDOUT, 0) THEN
          DIFERENTE := 1;
          EXIT ;
        END IF;
    END LOOP;

    IF  DIFERENTE = 1 THEN
      DELETE FROM REGTREZOR1 WHERE CODREG = V_REC_MARE.CODREG;

      INSERT INTO REGTREZOR1(CodRegTrezor1, CodReg, SoldDoc, SoldDocVal, SoldDocReg, CodBank, CodBankCont)
      (SELECT NEXTVAL('SEQ_REGTREZOR1_CODREGTREZOR1'), V_REC_MARE.CODREG, SoldDoc, SoldDocVal, SoldDocReg, CodBank, CodBankCont
       FROM TMP_REGTREZOR1 WHERE CODREG = V_REC_MARE.CODREG
      );
    END IF;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_get_trezor_for_jurnal</obj_name>
  <obj_hashval>4fe51ed129d510f92dadd736f5cefb33</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_get_trezor_for_jurnal(startrec numeric, endrec numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
  aCODSUBUNITSTINS numeric := 0;
  NEWCONSTVALUE    varchar := '';
  NEWCONSTSIMBOL   varchar := '';
  aCODNBANKCONT1   numeric := 0;
  aCODIOBANK       numeric := 0;
begin
  --Stef 03.03.2023
  PERFORM PKG_SERVICE_EMPTY_DOCUMENTE_FOR_TREZOR();
  PERFORM PKG_CONTURIBANCI_MAKE_CURS_BANKCONT_LUNA( '01.' || TO_CHAR( TO_NUMBER((current_setting('PKG_GLOBALS.LUNALUCRU', true)),'999999999999999999'),'9999999999') || '.' || TO_CHAR( TO_NUMBER((current_setting('PKG_GLOBALS.ANLUCRU', true)),'999999999999999999'),'9999999999'));

  INSERT INTO TMP_TREZOR(CODTREZOR, TIPDOC, CODBANCA, ICONTPERS, MONEDAPERS, CODMONEDA, OPERAT, SUBUNITATEA, CREDIT, CURSREG, AN, LUNA)
  SELECT CODTREZOR, TIPDOC, CODBANCA, ICONTPERS, MONEDAPERS, CODMONEDA, OPERAT, SUBUNITATEA, CREDIT, CURS, AN, LUNA
  FROM (SELECT row_number() over() AS RN, S.*
        FROM (SELECT T.CODTREZOR, T.TIPDOC, T.CODBANCA, T.ICONTPERS, T.MONEDAPERS, T.An, T.Luna, B.CODMONEDA, OPERAT, T.SUBUNITATEA, B.CREDIT, REG.CURS
              FROM TREZOR T
                   LEFT JOIN NBANKCONT B ON  B.CODBANKCONT = T.CODBANCA
                   LEFT JOIN TMP_CURS_BANKCONT_LUNA REG ON  REG.CODBANKCONT = T.CODBANCA
              WHERE AN * 12 + LUNA = (SELECT ANLUCRU * 12 + LUNALUCRU FROM TMP_PKG_GLOBALS X)
                AND PKG_SERVICE_IS_DIRTY_DOC(T.TIPDOC, T.CODTREZOR) = 1
              ORDER BY T.CODTREZOR
             ) S
       ) A_PG
  WHERE RN &gt;= STARTREC AND  RN &lt;= ENDREC;

  INSERT INTO TMP_TREZOR1(CODTREZOR1, CODTREZOR, INDEXLOCAL, TIPTRANZ, DOC, NRDOC, DATADOC, VALDOC, CURS, COMISION, OBIECTTRANZ, CODPART, TIPDECONT, DATADECONT, OBS, CodCentru, ANULAT)
  SELECT *
  FROM (SELECT CODTREZOR1, CODTREZOR, INDEXLOCAL, TIPTRANZ, DOC, NRDOC, DATADOC, VALDOC, CURS, COMISION, OBIECTTRANZ, CODPART, TIPDECONT, DATADECONT, OBS, CodCentru, ANULAT
        FROM TREZOR1 T1
        WHERE EXISTS (SELECT CODTREZOR FROM TMP_TREZOR T WHERE T.CODTREZOR = T1.CODTREZOR)
       ) B_PG
  ORDER BY INDEXLOCAL ;

  INSERT INTO TMP_GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  (SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
   FROM GENERAL G
   WHERE TIPDOC IN (29, 30, 31, 33) AND  EXISTS (SELECT CODTREZOR1 FROM TMP_TREZOR1 WHERE CODTREZOR1 = G.CODDOC)
  );

  INSERT INTO TMP_OBLIGPIF(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CodCentru, CODTRANSA, COEFPROVIZION, CODANALIZANOD, TVANEDED)
  SELECT CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CodCentru, CODTRANSA, COEFPROVIZION, CODANALIZANOD, TVANEDED
  FROM (SELECT * FROM OBLIGPIF WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL)) C_PG
  ORDER BY CODOBLIGPIF ;

  INSERT INTO TMP_STINGERE(CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
  (SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE
   FROM STINGERE
   WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF)
  );

       FOR V_REC IN
       (SELECT
          S.CODSTINGERE,
          G.TIPDOC,
          G.CODDOC,
          G.SEMNIFICATIE,
          I.SUBUNITATEA,
          I.PROCSTOPAJ
        FROM
          TMP_STINGERE S,
          OBLIGPIF O,
          GENERAL G,
          INTRARI I
        WHERE
          S.CODSTINSPIF = O.CODOBLIGPIF
          AND G.CODGENERAL = O.CODGENERAL
          AND G.SEMNIFICATIE IN (100, 110, 130)
          AND G.CODDOC = I.CODINTR
        )
        LOOP
          UPDATE TMP_STINGERE
          SET
            CODSUBUNITSTINS = V_REC.SUBUNITATEA,
            PROCSTOPAJ      = V_REC.PROCSTOPAJ
          WHERE
           CODSTINGERE = V_REC.CODSTINGERE;
        END LOOP;

        TRUNCATE TABLE MAN_IESIRI;
        INSERT INTO MAN_IESIRI(CODIES, SUBUNITATEA)
               SELECT
                  G.CODDOC,
                  I.SUBUNITATEA
                FROM
                  TMP_STINGERE S,
                  OBLIGPIF O,
                  GENERAL G
                  INNER JOIN IESIRI I ON  G.CODDOC = I.CODIES
                WHERE
                  S.CODSTINSPIF = O.CODOBLIGPIF
                  AND G.CODGENERAL = O.CODGENERAL
                  AND G.SEMNIFICATIE IN (200, 210);


       FOR V_REC IN
       (SELECT
          S.CODSTINGERE,
          I.SUBUNITATEA
        FROM
          TMP_STINGERE S,
          OBLIGPIF O,
          GENERAL G,
          MAN_IESIRI I
        WHERE
          S.CODSTINSPIF = O.CODOBLIGPIF
          AND G.CODGENERAL = O.CODGENERAL
          AND G.SEMNIFICATIE IN (200, 210)
          AND G.CODDOC = I.CODIES
        )
        LOOP
          UPDATE TMP_STINGERE
          SET
            CODSUBUNITSTINS = V_REC.SUBUNITATEA
          WHERE
           CODSTINGERE = V_REC.CODSTINGERE;
        END LOOP;




       FOR V_REC IN
       (SELECT
          S.CODSTINGERE,
          G.TIPDOC,
          G.CODDOC,
          G.SEMNIFICATIE,
          NC.SUBUNITATEA
        FROM
          TMP_STINGERE S,
          OBLIGPIF O,
          GENERAL G,
          NC1,
          NC
        WHERE
          S.CODSTINSPIF = O.CODOBLIGPIF
          AND G.CODGENERAL = O.CODGENERAL
          AND G.SEMNIFICATIE IN (1200, 1201)
          AND G.CODDOC = NC1.CODNC1
          AND NC.CODNC = NC1.CODNC
        )
        LOOP
          UPDATE TMP_STINGERE
          SET
            CODSUBUNITSTINS = V_REC.SUBUNITATEA
          WHERE
           CODSTINGERE = V_REC.CODSTINGERE;
        END LOOP;

       FOR V_REC IN
       (SELECT
          S.CODSTINGERE,
          G.TIPDOC,
          G.CODDOC,
          G.SEMNIFICATIE,
          T.SUBUNITATEA
        FROM
          TMP_STINGERE S,
          OBLIGPIF O,
          GENERAL G,
          TREZOR1 T1,
          TREZOR T
        WHERE
          S.CODSTINSPIF = O.CODOBLIGPIF
          AND G.CODGENERAL = O.CODGENERAL
          AND G.SEMNIFICATIE IN (310, 330, 410, 430)
          AND G.CODDOC = T1.CODTREZOR1
          AND T.CODTREZOR = T1.CODTREZOR
        )
        LOOP
          UPDATE TMP_STINGERE
          SET
            CODSUBUNITSTINS = V_REC.SUBUNITATEA
          WHERE
           CODSTINGERE = V_REC.CODSTINGERE;
        END LOOP;

       FOR V_REC IN
       (SELECT
          S.CODSTINGERE,
          G.TIPDOC,
          G.CODDOC,
          G.SEMNIFICATIE,
          C.SUBUNITATEA
        FROM
          TMP_STINGERE S,
          OBLIGPIF O,
          GENERAL G,
          COMPENS C
        WHERE
          S.CODSTINSPIF = O.CODOBLIGPIF
          AND G.CODGENERAL = O.CODGENERAL
          AND G.SEMNIFICATIE IN (1300, 1301, 1302, 1303, 1350, 1351, 1352)
          AND G.CODDOC = C.CODCOMPENS
        )
        LOOP
          UPDATE TMP_STINGERE
          SET
            CODSUBUNITSTINS = V_REC.SUBUNITATEA
          WHERE
           CODSTINGERE = V_REC.CODSTINGERE;
        END LOOP;


 /*

 FOR V_REC IN (SELECT S.CODSTINGERE, G.TIPDOC, G.CODDOC, G.SEMNIFICATIE
                FROM TMP_STINGERE S, OBLIGPIF O, GENERAL G
                WHERE S.CODSTINSPIF = O.CODOBLIGPIF AND  G.CODGENERAL = O.CODGENERAL
               )
  LOOP
    aCODSUBUNITSTINS := 0;
    IF V_REC.SEMNIFICATIE IN (100, 110, 130) THEN
      BEGIN
        SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM INTRARI WHERE CODINTR = V_REC.CODDOC AND  TIPDOC = V_REC.TIPDOC;
      EXCEPTION WHEN OTHERS THEN
        aCODSUBUNITSTINS := 0;
      END;
    ELSE
      IF V_REC.SEMNIFICATIE IN (200, 210) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM IESIRI WHERE CODIES = V_REC.CODDOC AND  TIPDOC = V_REC.TIPDOC;
        EXCEPTION WHEN OTHERS THEN
          aCODSUBUNITSTINS := 0;
        END;
      ELSE
        IF V_REC.SEMNIFICATIE IN (1200, 1201) THEN
          BEGIN
            SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM NC N, NC1 N1 WHERE N1.CODNC1 = V_REC.CODDOC AND  N.CODNC = N1.CODNC;
          EXCEPTION WHEN OTHERS THEN
            aCODSUBUNITSTINS := 0;
          END;
        ELSE
          IF V_REC.SEMNIFICATIE IN (310, 330, 410, 430) THEN
            BEGIN
              SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM TREZOR T, TREZOR1 T1 WHERE T1.CODTREZOR1 = V_REC.CODDOC AND  T.CODTREZOR = T1.CODTREZOR;
            EXCEPTION WHEN OTHERS THEN
              aCODSUBUNITSTINS := 0;
            END;
          ELSE
            IF V_REC.SEMNIFICATIE IN (1300, 1301, 1302, 1303, 1350, 1351, 1352) THEN
              BEGIN
                SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM COMPENS C WHERE C.CODCOMPENS = V_REC.CODDOC;
              EXCEPTION WHEN OTHERS THEN
                aCODSUBUNITSTINS := 0;
              END;
            END IF;
          END IF;
        END IF;
      END IF;
    END IF;

    UPDATE TMP_STINGERE SET CODSUBUNITSTINS = aCODSUBUNITSTINS WHERE CODSTINGERE = V_REC.CODSTINGERE;
  END LOOP;
*/
  UPDATE TMP_OBLIGPIF OB
  SET
  (CODTREZOR1, CURS, MONEDA, TVA) = (SELECT CODDOC, COALESCE( CURS, 1), COALESCE( MONEDA, 0), COALESCE( TVA, 0)
                                     FROM GENERAL G WHERE G.CODGENERAL = OB.CODGENERAL),
  (CURSISTORIC, SEMNIFCODSTINS)   = (SELECT COALESCE( CURS, 1), COALESCE( O.SEMNIFICATIE, 0)
                                     FROM STINGERE S
                                          LEFT JOIN OBLIGPIF O ON  O.CODOBLIGPIF = S.CODSTINSPIF
                                          LEFT JOIN GENERAL  G ON  G.CODGENERAL  = O.CODGENERAL
                                     WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF
                                    );

  FOR V_REC IN (SELECT O.CODOBLIGPIF, T1.TIPDECONT
                FROM TMP_OBLIGPIF O, TMP_GENERAL G, TMP_TREZOR1 T1
                WHERE O.SEMNIFICATIE IN (500, 600) AND  O.CODGENERAL = G.CODGENERAL AND  T1.CODTREZOR1 = G.CODDOC
               )
  LOOP
    UPDATE TMP_OBLIGPIF SET ICONT = V_REC.TIPDECONT WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
  END LOOP;

  FOR V_REC IN (SELECT O.CODOBLIGPIF, OS.SEMNIFICATIE, T1.TIPDECONT, T1.OBIECTTRANZ, T.CODBANCA
                FROM TMP_OBLIGPIF O, TMP_STINGERE S, OBLIGPIF OS, GENERAL GS, TREZOR1 T1, TREZOR T
                WHERE  S.CODSTINGATORPIF = O.CODOBLIGPIF
                  AND  OS.CODOBLIGPIF = S.CODSTINSPIF
                  AND OS.SEMNIFICATIE IN (500, 600)
                  AND O.SEMNIFICATIE  IN (300, 320, 400, 420)
                  AND  GS.CODGENERAL = OS.CODGENERAL
                  AND  T1.CODTREZOR1 = GS.CODDOC
                  AND  T1.CODTREZOR  = T.CODTREZOR
               )
  LOOP
    UPDATE TMP_OBLIGPIF
    SET
    ICONT              = V_REC.TIPDECONT,
    CONTBANKTRANZACTIE = V_REC.CODBANCA,
    OBIECTTRANZSTINS   = V_REC.OBIECTTRANZ
    WHERE
     CODOBLIGPIF = V_REC.CODOBLIGPIF;
  END LOOP;

  FOR V_REC IN (SELECT CODTREZOR1, CODOBLIGPIF FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (310, 410)) LOOP
    UPDATE TMP_TREZOR1 SET CODAVANS = V_REC.CODOBLIGPIF WHERE CODTREZOR1 = V_REC.CODTREZOR1;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF WHERE COALESCE( CODTRANSA, 0) &lt;&gt; 0) LOOP
    UPDATE TMP_OBLIGPIF
    SET
    CURSTRANSA = (SELECT G.CURS FROM OBLIGPIF O, GENERAL G WHERE O.CODOBLIGPIF = V_REC.CODTRANSA AND  G.CODGENERAL = O.CODGENERAL)
    WHERE
     CODOBLIGPIF = V_REC.CODOBLIGPIF;
  END LOOP;



  UPDATE TMP_TREZOR1 T
  SET
  DENTRANZ = SUBSTR((CASE when TIPTRANZ = 0 and OBIECTTRANZ = 0
                            then 'Furnizor :' || chr(13) || (SELECT DEN_PART FROM NPART P WHERE CODPART = T.CODPART)
                          when TIPTRANZ = 0 and OBIECTTRANZ = 1
                            then 'Retur Client :' || chr(13) || (SELECT DEN_PART FROM NPART P WHERE CODPART = T.CODPART)
                          when TIPTRANZ in (0, 1) and OBIECTTRANZ = 3
                            then 'Viramente interne :' || chr(13) || (SELECT B.SIMBOL || ' - ' || NRCONT FROM NBANKCONT BC left join NBANK B ON B.CODBANK = BC.CODBANK WHERE CODBANKCONT = T.CODPART)
                          when TIPTRANZ = 1 and OBIECTTRANZ = 0
                            then 'Client: ' || (CASE when T.AGENT &lt;&gt; 0 then '(Agent:' || T.NUMEAGENT || ')' else '' end) || chr(13)
                                            || coalesce((select DEN_PART from NPART P where CODPART = T.CODPART ), '')
                          when TIPTRANZ = 1 and OBIECTTRANZ = 1
                            then 'Retur Furnizor :' || chr(13) || coalesce((select DEN_PART from NPART P where CODPART = T.CODPART ), '')
                          when OBIECTTRANZ = 2
                            then 'Personal angajat :' || chr(13) || coalesce((select NUME || ' ' || PRENUME from NPERS P where CODPERS = T.CODPART ), '')
                          when TIPTRANZ = 0 and OBIECTTRANZ = 4
                            then 'Servicii, articole fara NIR...' || chr(13)
                                 || (SELECT PKG_PLANCONTURI_GETDENCONT.WME_RESULT
                                     FROM   PKG_PLANCONTURI_GETDENCONT(null, (SELECT coalesce( ICONT, -1) FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 and O.SEMNIFICATIE = 900 limit 1))
                                    )
                          when TIPTRANZ = 1 and OBIECTTRANZ = 4
                            then 'Direct pe venituri...' || chr(13)
                                 || (SELECT PKG_PLANCONTURI_GETDENCONT.WME_RESULT
                                     FROM   PKG_PLANCONTURI_GETDENCONT(null, (SELECT coalesce( ICONT, -1) FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 and O.SEMNIFICATIE = 901 limit 1))
                                    )
                          when TIPTRANZ = 0 and OBIECTTRANZ = 5
                            then 'Datorii, taxe, impozite ' || chr(13)
                                 || (SELECT PKG_PLANCONTURI_GETDENCONT.WME_RESULT
                                     FROM   PKG_PLANCONTURI_GETDENCONT(null, (SELECT coalesce( ICONT, -1) FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 and O.SEMNIFICATIE = 950 limit 1))
                                    )
                          when TIPTRANZ = 1 and OBIECTTRANZ = 5
                            then 'Imprumuturi, subventii ' || chr(13)
                                 || (SELECT PKG_PLANCONTURI_GETDENCONT.WME_RESULT
                                     FROM   PKG_PLANCONTURI_GETDENCONT(null, (SELECT coalesce( ICONT, -1) FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 and O.SEMNIFICATIE = 951 limit 1))
                                    )
                     END
                    ) , 1, 100);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_service_keep_alive</obj_name>
  <obj_hashval>a47cc62e5f760496eab97c6ab4308361</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_service_keep_alive()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  NULL;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_simlans_get_tmp_sim_lans</obj_name>
  <obj_hashval>5392a657ab5c8e7277a00ffa93fe7d77</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_simlans_get_tmp_sim_lans(scenariu numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_SIM_LANS;
  INSERT INTO TMP_SIM_LANS(NRDOC, DATADOC, CANT, CODPROIECT, CODCOMANDA1, CODLANSARE, OK)
  (SELECT L.NRDOC, L.DATADOC, L.CANT, L.CODPROIECT, L.CodCmd1 CODCOMANDA1, L.CODLANSARE, 0 OK
   FROM LANSARE L
   WHERE L.CodScenariu = SCENARIU AND  EXISTS (SELECT TMP.CodComanda1 FROM TMP_SIM_CCOM1 TMP WHERE COALESCE(TMP.Activ, 0) = 1 and  TMP.CodComanda1 = L.CodCmd1)
  );
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settcb</obj_name>
  <obj_hashval>ef7fc0a1b7210ea613928960bf7b1ab1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settcb(atcb numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcB',to_char(atcB,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_settcsoldi</obj_name>
  <obj_hashval>18754dd9ecf62d1626ffac29bdcd9517</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_settcsoldi(atcsoldi numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SITFIN.tcSoldI',to_char(atcSoldI,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_sitfin_tcprectotalaj</obj_name>
  <obj_hashval>20fe650e57bdf7fb426bde56884a16ea</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_sitfin_tcprectotalaj(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER((current_setting('PKG_SITFIN.tcPrecTotalAj')),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 22;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_splitchelt_sp_insertrecord</obj_name>
  <obj_hashval>db9ed48ef2b99c3b11127b733589fb27</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_splitchelt_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_SPLITCHELT (CodSPLITCHELT, Activ) VALUES(0, 1);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_splittva_tvastins_oblig_before_split</obj_name>
  <obj_hashval>7592244b07700f35e41125a65098d5af</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_splittva_tvastins_oblig_before_split(INOUT wme_result numeric, INOUT acodobligpif numeric, INOUT valoblig numeric, INOUT tvaoblig numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  TVASTINS double precision := 0;
begin
  IF  VALOBLIG = 0 THEN
    WME_Result :=  0;
    RETURN;
  END IF;

  SELECT ROUND( SUM( COALESCE( TVASTINS, 0)), 2)
  INTO TVASTINS
  FROM (SELECT TVAOBLIG * S.VALOARE / VALOBLIG AS TVASTINS
        FROM STINGERE S, OBLIGPIF O_STINGATOR
        WHERE S.CODSTINGATORPIF = O_STINGATOR.CODOBLIGPIF AND  COALESCE( O_STINGATOR.SPLITTVAACTIV, 0) = 0 AND  S.CODSTINSPIF = aCODOBLIGPIF AND  VALOBLIG &lt;&gt; 0
       ) A_PG;

  WME_Result :=  COALESCE( TVASTINS, 0);
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_statcon_sp_gotorecord</obj_name>
  <obj_hashval>7b568470a93f68a78323122e8eb50b7b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_statcon_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  INSERT INTO TMP_StatCon(CodStatCon, CodEvalS, Atribut, Den_evaluare)
  SELECT S.CodStatCon, S.CodEvalS, S.Atribut, E.Den_evaluare
  FROM StatCon S LEFT JOIN evals E ON  E.CODEVALS = S.Codevals
  WHERE CodStatCon = RECID;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stocinitial_propagafurn</obj_name>
  <obj_hashval>ff8531368f1504594f32334ac1a51e02</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stocinitial_propagafurn(acodnirstoc numeric, afurn numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC RECORD;
BEGIN
  --Adina 17.08.2021 - sinc.Oracle din 17.08.2021
  FOR v_Rec IN (SELECT codnirstoc FROM nirstoc WHERE codnirstocparinte = acodnirstoc) LOOP
    UPDATE nirstoc
    SET
    furn = afurn
    WHERE
     codnirstoc = v_rec.codnirstoc;

    PERFORM pkg_stociniart_PropagaFurn(v_rec.codnirstoc, afurn);
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stocinitial_sp_deleterecord</obj_name>
  <obj_hashval>668b9b851b90532cf451e9d7c35634fc</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stocinitial_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  V_REC RECORD;
  aGEST numeric;
  ANI   numeric;
  LUNAI numeric;
BEGIN
  --Florin 14.09.2022 - fixat 55569
  --Florin 16.08.2022 - sinc. Oracle
  SELECT CODGEST INTO aGEST FROM STOCINI WHERE CODSTOCINI = RecID;

  DELETE FROM STOCINI WHERE CODSTOCINI = RecID;
  DELETE FROM TMP_INTRARI1;
  DELETE FROM TMP_TRANSF1;

  DELETE FROM TMP_NIRSTOCINI;

  INSERT INTO TMP_NIRSTOCINI
    (CODNIRSTOC, CODNIR, CODINTR1, CODINTR, DATADOC, CODOBIECT, CODIOART, UMSEC, PRETACHIZ, PRETINREG,
    PUVAL, TVA, TG, TIPSERIE, CANTNIR, CODLOCATIE, FURNIZOR, INITIALIZARI, TIPNIR)
    (SELECT NS.CODNIRSTOC, NS.CODNIR, I1.CODINTR1, I.CODINTR, I.DATADOC, NS.CODOBIECT, NS.CODIOART,
    NS.UMSEC, NS.PRET - NS.ADAOS, NS.PRET, NS.PUVAL, NS.TVA, I1.TG, NS.TIPSERIE, NS.CANTNIR, NS.CODLOCATIE, I.PARTENER, I.INITIALIZARI, N.TIPNIR
   FROM NIRSTOC NS
        left join NIR      N  ON N.CODNIR    = NS.CODNIR
        left join INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1
        left join INTRARI  I  ON I.CODINTR   = N.CODINTR
   WHERE
      N.GEST = aGEST
      AND COALESCE(N.TIPNIR, 0) NOT IN (12, 13)
      and
      (I.AN * 12 + I.LUNA &lt; current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric * 12 + current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric
      OR         EXTRACT(YEAR FROM I.DATADOC) * 12 + EXTRACT(MONTH FROM I.DATADOC) &lt; current_setting('PKG_GLOBALS.ANINITIAL', TRUE)::numeric * 12 + current_setting('PKG_GLOBALS.LUNAINITIALA', TRUE)::numeric)
    );

    INSERT INTO TMP_NIRSTOCINI
    (CODNIRSTOC, CODNIR, CODINTR1, CODINTR, DATADOC, CODOBIECT, CODIOART, UMSEC, PRETACHIZ, PRETINREG, PUVAL, TVA, TG, TIPSERIE, CANTNIR, CODLOCATIE, FURNIZOR, INITIALIZARI, TIPNIR)
    (SELECT NS.CODNIRSTOC, NS.CODNIR, I1.CODTRANSF1, I.CODTRANSF, I.DATADOC, NS.CODOBIECT, NS.CODIOART, NS.UMSEC, NS.PRET - NS.ADAOS, NS.PRET, NS.PUVAL, NS.TVA, NS.TG, NS.TIPSERIE, NS.CANTNIR, NS.CODLOCATIE, 0, 1, N.TIPNIR
    FROM
    NIRSTOC NS
    LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR
    LEFT OUTER JOIN TRANSF1 I1 ON I1.CODTRANSF1 = NS.CODTRANSF1
    LEFT OUTER JOIN TRANSF  I  ON I.CODTRANSF   = N.CODTRANSF
    WHERE
      N.GEST = aGEST
      AND COALESCE(N.TIPNIR, 0) IN (12, 13)
      AND I.AN * 12 + I.LUNA &lt; current_setting('PKG_GLOBALS.ANINITIAL', TRUE)::NUMERIC * 12 + current_setting('PKG_GLOBALS.LUNAINITIALA', TRUE)::NUMERIC
   );



  DELETE FROM TMP_MANEVRA;

  INSERT INTO TMP_MANEVRA (CodUnic)
  SELECT codnirstoc FROM TMP_NIRSTOCINI;

  perform pkg_pretprod_SetDirtyStructura();

  for v_rec in (SELECT * FROM TMP_NIRSTOCINI ) loop
    DELETE FROM NIRSER     WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
    DELETE FROM NIRSERLUNA WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
    DELETE FROM NIRLUNA    WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
    DELETE FROM NIRSTOC    WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
    DELETE FROM NIRSTOC1   WHERE CODNIRSTOC = V_REC.CODNIRSTOC;

    IF V_REC.TIPNIR NOT IN (12, 13) THEN
      INSERT INTO TMP_INTRARI1 (CODINTR1) values (v_rec.CODINTR1);
    ELSE
      INSERT INTO TMP_TRANSF1(CODTRANSF1) VALUES (v_rec.CODINTR1);
    END IF;
  end loop;

  for v_rec in (SELECT * FROM TMP_NIRSTOCINI ) loop
    DELETE FROM NIR N WHERE CODNIR = v_rec.CODNIR and (SELECT count(*) FROM NIRSTOC WHERE CODNIR = V_REC.CODNIR ) = 0;
  end loop;

  DELETE FROM INTRARI1 I1
  WHERE
    exists (SELECT CODINTR1 FROM TMP_INTRARI1 TI1 WHERE TI1.CODINTR1 = I1.CODINTR1 )
    and (SELECT count(*) FROM NIRSTOC WHERE CODINTR1 = I1.CODINTR1 ) = 0;

  DELETE FROM TRANSF1 I1
  WHERE
  EXISTS (SELECT CODTRANSF1 FROM TMP_TRANSF1 TI1 WHERE TI1.CODTRANSF1 = I1.CODTRANSF1)
  AND (SELECT COUNT(*) FROM NIRSTOC WHERE CODTRANSF1 = I1.CODTRANSF1) = 0;

  -- RECALCULEZ FIXARILE DE PMP;
  perform PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA(current_setting('PKG_GLOBALS.ANINITIAL'   , true)::numeric,
                                                 current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric,
                                                 ANI, LUNAI);

  DELETE FROM PMPLUNA WHERE AN = ANI and LUNA = LUNAI;

  for V_REC in (SELECT
                        CODOBIECT,
                        CODSUBUNIT,
                        sum(CANTINTR) as CANTINTR,
                        sum(VALINTR) as VALINTR,
                        sum(RESTLUNA) as RESTLUNA,
                        ANI,
                        LUNAI
                FROM (
                      SELECT
                            NS.CODOBIECT,
                            G.CODSUBUNIT,
                            NS.CANTNIR as CANTINTR,
                            ( NS.PRET - coalesce(NS.ADAOS, 0)) * NS.CANTNIR as VALINTR,
                            NS.CANTNIR - (SELECT PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA.WME_RESULT
                                          FROM PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA(null, NS.CodNirStoc, ANI, LUNAI)) as RESTLUNA
                      FROM
                          NIRSTOC NS,
                          NIR N,
                          TMP_IOART_LUNA IO,
                          INTRARI I,
                          NGEST G
                      WHERE
                          NS.CODIOART = IO.CODIOART
                          and IO.MG = 3
                          and NS.CODNIR = N.CODNIR
                          and N.TIPNIR in (1, 2, 3, 4, 5, 6, 7)
                          and N.ANULAT = 0
                          and N.OPERAT = 1
                          and I.CODINTR = N.CODINTR
                          and I.AN = ANI
                          and I.LUNA = LUNAI
                          and G.CODGEST = N.GEST
                      union all
                      SELECT
                        NS.CODOBIECT,
                        G.CODSUBUNIT,
                        NS.CANTNIR as CANTINTR,
                        ( NS.PRET - coalesce(NS.ADAOS, 0)) * NS.CANTNIR as VALINTR,
                        NS.CANTNIR - (SELECT PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA.WME_RESULT
                                      FROM PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA(null, NS.CodNirStoc, ANI, LUNAI)) as RESTLUNA
                      FROM
                        NIRSTOC NS,
                        NIR N,
                        TMP_IOART_LUNA IO,
                        TRANSF I,
                        NGEST G
                      WHERE
                        NS.CODIOART = IO.CODIOART
                        and IO.MG = 3
                        and NS.CODNIR = N.CODNIR
                        and N.TIPNIR in (12, 13)
                        and N.ANULAT = 0
                        and N.OPERAT = 1
                        and I.CODTRANSF = N.CODTRANSF
                        and I.AN = ANI
                        and I.LUNA = LUNAI
                        and G.CODGEST = N.GEST
                      union all
                        SELECT
                          NS.CODOBIECT,
                          G.CODSUBUNIT,
                          NS.CANTNIR as CANTINTR,
                          ( NS.PRET - coalesce(NS.ADAOS, 0)) * NS.CANTNIR as VALINTR,
                          NS.CANTNIR - (SELECT PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA.WME_RESULT
                                        FROM PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA(null, NS.CodNirStoc, ANI, LUNAI)) as RESTLUNA
                        FROM
                          NIRSTOC NS,
                          NIR N,
                          TMP_IOART_LUNA IO,
                          IESIRI I,
                          NGEST G
                        WHERE
                          NS.CODIOART = IO.CODIOART
                          and IO.MG = 3
                          and NS.CODNIR = N.CODNIR
                          and N.TIPNIR in (14, 15, 19)
                          and N.ANULAT = 0
                          and N.OPERAT = 1
                          and I.CODIES = N.CODIES
                          and I.AN = ANI
                          and I.LUNA = LUNAI
                          and G.CODGEST = N.GEST
                        ) A_PG
                group BY CODOBIECT, CODSUBUNIT
               )
  loop
    INSERT INTO PMPLUNA ( CODPMPLUNA, CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, REST, AN, LUNA )
    values (nextval('SEQ_PMPLUNA_CODPMPLUNA'),
            V_REC.CODOBIECT,
            V_REC.CODSUBUNIT,
            V_REC.CANTINTR,
            V_REC.VALINTR,
            V_REC.RESTLUNA,
            ANI,
            LUNAI );
  end loop;

  DELETE FROM PMP_ALL_LUNA WHERE AN = ANI and LUNA = LUNAI;

  for V_REC in (SELECT
                      CODOBIECT,
                      sum(CANTINTR) as CANTINTR,
                      sum(VALINTR) as VALINTR,
                      sum(RESTLUNA) as RESTLUNA,
                      ANI,
                      LUNAI
                FROM
                    ( SELECT
                            NS.CODOBIECT,
                            NS.CANTNIR as CANTINTR,
                            ( NS.PRET - coalesce(NS.ADAOS, 0)) * NS.CANTNIR as VALINTR,
                            NS.CANTNIR - (SELECT PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA.WME_RESULT
                                          FROM PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA(null, NS.CodNirStoc, ANI, LUNAI)) as RESTLUNA
                      FROM
                        NIRSTOC NS,
                        NIR N,
                        TMP_IOART_LUNA IO,
                        INTRARI I
                      WHERE
                        NS.CODIOART = IO.CODIOART
                        and IO.MG = 3
                        and NS.CODNIR = N.CODNIR
                        and N.TIPNIR in (1, 2, 3, 4, 5, 7)
                        and N.ANULAT = 0
                        and N.OPERAT = 1
                        and I.CODINTR = N.CODINTR
                        and I.AN = ANI
                        and I.LUNA = LUNAI
                      union all
                      SELECT
                        NS.CODOBIECT,
                        NS.CANTNIR as CANTINTR,
                        ( NS.PRET - coalesce(NS.ADAOS, 0)) * NS.CANTNIR as VALINTR,
                        NS.CANTNIR - (SELECT PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA.WME_RESULT
                                      FROM PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA(null, NS.CodNirStoc, ANI, LUNAI)) as RESTLUNA
                      FROM
                        NIRSTOC NS,
                        NIR N,
                        TMP_IOART_LUNA IO,
                        TRANSF I
                      WHERE
                        NS.CODIOART = IO.CODIOART
                        and IO.MG = 3
                        and NS.CODNIR = N.CODNIR
                        and N.TIPNIR in (12, 13)
                        and N.ANULAT = 0
                        and N.OPERAT = 1
                        and I.CODTRANSF = N.CODTRANSF
                        and I.AN = ANI
                        and I.LUNA = LUNAI
                      union all
                      SELECT
                        NS.CODOBIECT,
                        NS.CANTNIR as CANTINTR,
                        ( NS.PRET - coalesce(NS.ADAOS, 0)) * NS.CANTNIR as VALINTR,
                        NS.CANTNIR - (SELECT PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA.WME_RESULT
                                      FROM PKG_INTRARI_SUMA_LIVRARI_DIN_NIR_IN_LUNA(null, NS.CodNirStoc, ANI, LUNAI)) as RESTLUNA
                      FROM
                        NIRSTOC NS,
                        NIR N,
                        TMP_IOART_LUNA IO,
                        IESIRI I
                      WHERE
                        NS.CODIOART = IO.CODIOART
                        and IO.MG = 3
                        and NS.CODNIR = N.CODNIR
                        and N.TIPNIR in (14, 15, 19)
                        and N.ANULAT = 0
                        and N.OPERAT = 1
                        and I.CODIES = N.CODIES
                        and I.AN = ANI
                        and I.LUNA = LUNAI
                     ) B_PG
                group BY CODOBIECT
               )
  loop
    INSERT INTO PMP_ALL_LUNA ( CODPMP_ALL_LUNA, CODOBIECT, CANTINTR, VALINTR, REST, AN, LUNA )
    values (nextval('SEQ_PMP_ALL_LUNA'),
            V_REC.CODOBIECT,
            V_REC.CANTINTR,
            V_REC.VALINTR,
            V_REC.RESTLUNA,
            ANI,
            LUNAI );
  end loop;

  perform NotifyModif(2, RecId, 'STOCINI');
 end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_stocinitial_sp_gotorecord</obj_name>
  <obj_hashval>24a19edfef0f92e56ed3f4b2f6dfacbc</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_stocinitial_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  aCODGEST numeric;
begin
  --Florin 12.12.2025 - sinc. Oracle
  --Florin 25.07.2025 - sinc. Oracle
  --Florin 21.10.2022 - sinc. Oracle (18.10.2022)
  perform PKG_STOC_GENERARE_FACTURI_MAKE_CONFIG_LUNA();

  INSERT INTO TMP_STOCINI
  SELECT * FROM STOCINI WHERE CODSTOCINI = RECID;

  if RECID &gt; 0 then
    SELECT coalesce(CODGEST, 0) INTO aCODGEST FROM TMP_STOCINI;
  end if;

  INSERT INTO TMP_OBJSTOCINI (CODOBJSTOCINI,
                              CODOBIECT,
                              DENOBIECT,
                              CODEXTERN,
                              CODINTERN,
                              TIPSERIE,
                              ARETG,
                              CERTIFICAT,
                              CONTIMPLICIT,
                              PUMAXIMAL,
                              D1,
                              D2,
                              D3,
                              STOCTOTAL,
                              UMSEC,
                              DENUM,
                              UM1,
                              UM2,
                              RELATIEUM1,
                              RELATIEUM2,
                              TVA )
  SELECT
    row_number() over() ,
    OI.CODOBIECT,
    O.DENUMIRE,
    O.CODEXTERN,
    O.CODINTERN,
    A.TIPSERIE,
    A.ARETG,
    A.CERTIFICAT,
    A.CONTIMPLICIT,
    OBJLUNA.PRETMAXIMAL,
    A.D1,
    A.D2,
    A.D3,
    OI.CANTNIR,
    USEC.CODUM1,
    U.DEN_UM,
    A.UM1,
    A.UM2,
    A.RELATIEUM1,
    A.RELATIEUM2,
    TL.PROCENT/100
  FROM
    (
    SELECT CODOBIECT, sum(CANTNIR) as CANTNIR
    FROM NIRSTOC NS
    WHERE
      ( exists ( SELECT CODNIR FROM NIR N WHERE N.CODNIR = NS.CODNIR and GEST = aCODGEST
                and exists
                (SELECT CODINTR FROM INTRARI WHERE CODINTR = N.CODINTR and AN * 12 + LUNA &lt; current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric * 12 + current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric )
               )
        or
        exists ( SELECT CODNIR FROM NIR N WHERE N.CODNIR = NS.CODNIR and GEST = aCODGEST
                and exists
                (SELECT CODTRANSF FROM TRANSF WHERE CODTRANSF = N.CODTRANSF and AN * 12 + LUNA &lt; current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric * 12 + current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric )
               )
        or
        exists ( SELECT CODNIR FROM NIR N WHERE N.CODNIR = NS.CODNIR and GEST = aCODGEST
                 and exists
                (SELECT CODIES FROM IESIRI WHERE CODIES = N.CODIES and AN * 12 + LUNA &lt; current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric * 12 + current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric )
               )
      )
    group BY CODOBIECT
    ) OI,
      NARTOBJ O
      left join TMP_NARTOBJ_LUNA OBJLUNA ON OBJLUNA.CODOBIECT = O.CODOBIECT,
      NART A,
      NUM U,
      NUM1 USEC,
      TMP_NART_LUNA AL,
      TMP_NTVA_LUNA TL
  WHERE
    OI.CODOBIECT = O.CODOBIECT
    and A.CODARTICOL = O.CODARTICOL
    and U.CODUM = A.UM
    and USEC.CODUM = U.CODUM
    and USEC.SECUNDARA = 0
    and AL.CODARTICOL = A.CODARTICOL
    and TL.CODTVA = AL.CODTVA;

  INSERT INTO TMP_NIRSTOCINI
  ( CODOBJSTOCINI,
    CODNIRSTOC,
    CODNIR,
    CODINTR1,
    CODINTR,
    DATADOC,
    CODOBIECT,
    CODIOART,
    UMSEC,
    PRETACHIZ,
    PRETINREG,
    PUVAL,
    TVA,
    TG,
    TIPSERIE,
    CANTNIR,
    CODLOCATIE,
    FURNIZOR,
    INITIALIZARI,
    PUMAXIMAL,
    CANTUM1,
    CANTUM2,
    PROCENTADAOS,
    DENUM,
    PARITATE,
    D1,
    D2,
    D3,
    NRCERTIF,
    ROTLEI,
    ROTVALUTA,
    TIPNIR,
    CODGESTPROD,
    REST,
    SERIELOT,
    CODCENTRU,
    TIPIMPORT,
    PROVIZION,
    UM1,
    UM2,
    MG,
    DIFPRET,
    ARETVANEEX,
    PUSTANDARD,
    DENOBIECT,
    PRETINITIAL,
    ACHIZINITIAL,
    CODIOARTINITIAL,
    EUDR_RN, EUDR_VN)
  (
    SELECT
      OI.CODOBJSTOCINI,
      NS.CODNIRSTOC,
      NS.CODNIR,
      I1.CODINTR1,
      I.CODINTR,
      I.DATADOC,
      NS.CODOBIECT,
      NS.CODIOART,
      NS.UMSEC,
      ( NS.PRET - NS.ADAOS) * U1.PARITATE,
      NS.PRET * U1.PARITATE,
      NS.PUVAL * U1.PARITATE,
      NS.TVA,
      NS.TG,
      NS.TIPSERIE,
      NS.CANTNIR / U1.PARITATE,
      NS.CODLOCATIE,
      I.PARTENER,
      I.INITIALIZARI,
      NS.PUMAXIMAL * U1.PARITATE,
      NS.CANTUM1,
      NS.CANTUM2,
      NS.PROCENTADAOS,
      U1.DEN_UM1,
      U1.PARITATE,
      NS.D1,
      NS.D2,
      NS.D3,
      I1.NRCERTIF,
      coalesce(NS.ROTLEI, NOBJ.ROTUNJIRE),
      coalesce(NS.ROTVALUTA, NOBJ.ROTVALUTA),
      N.TIPNIR,
      NS.CODGESTPROD,
      NS.REST,
      NS.SERIELOT,
      I1.CODCENTRU,
      coalesce(D.TIPIMPORT, 0),
      NS.PROVIZION,
      A.UM1,
      A.UM2,
      IOA.MG,
      IOA.DIFPRET,
      IOA.ARETVANEEX,
      IOA.PUSTANDARD,
      NOBJ.DENUMIRE,
      NS.PRET * U1.PARITATE,
      ( NS.PRET - NS.ADAOS) * U1.PARITATE,
      NS.CODIOART,
      NS.EUDR_RN, NS.EUDR_VN
    FROM
      NIRSTOC NS
      left join TMP_IOART_LUNA IOA  ON IOA.CODIOART = NS.CODIOART
      left join TMP_OBJSTOCINI OI   ON OI.CODOBIECT = NS.CODOBIECT
      left join NIR            N    ON N.CODNIR     = NS.CODNIR
      left join INTRARI1       I1   ON I1.CODINTR1  = NS.CODINTR1
      left join NARTOBJ        NOBJ ON NS.CODOBIECT = NOBJ.CODOBIECT
      left join NART           A    ON A.CODARTICOL = NOBJ.CODARTICOL
      left join INTRARI        I    ON I.CODINTR    = N.CODINTR
      left join DVI            D    ON D.CODINTR    = N.CODINTR,
      NUM1 U1
    WHERE
      N.GEST = aCODGEST
      and I.AN * 12 + I.LUNA &lt; current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric * 12 + current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric
      and NS.UMSEC = U1.CODUM1
      and N.TIPNIR &lt; 10 );

  INSERT INTO TMP_NIRSTOCINI
  ( CODOBJSTOCINI,
    CODNIRSTOC,
    CODNIR,
    CODINTR1,
    CODINTR,
    DATADOC,
    CODOBIECT,
    CODIOART,
    UMSEC,
    PRETACHIZ,
    PRETINREG,
    PUVAL,
    TVA,
    TG,
    TIPSERIE,
    CANTNIR,
    CODLOCATIE,
    FURNIZOR,
    INITIALIZARI,
    PUMAXIMAL,
    CANTUM1,
    CANTUM2,
    PROCENTADAOS,
    DENUM,
    PARITATE,
    D1,
    D2,
    D3,
    NRCERTIF,
    ROTLEI,
    ROTVALUTA,
    TIPNIR,
    CODGESTPROD,
    REST,
    SERIELOT,
    PROVIZION,
    UM1,
    UM2,
    MG,
    DIFPRET,
    ARETVANEEX,
    PUSTANDARD,
    DENOBIECT,
    PRETINITIAL,
    ACHIZINITIAL,
    CODIOARTINITIAL,
    EUDR_RN, EUDR_VN )
  (
    SELECT
      OI.CODOBJSTOCINI,
      NS.CODNIRSTOC,
      NS.CODNIR,
      I1.CODINTR1,
      I.CODINTR,
      I.DATADOC,
      NS.CODOBIECT,
      NS.CODIOART,
      NS.UMSEC,
      ( NS.PRET - NS.ADAOS) * U1.PARITATE,
      NS.PRET * U1.PARITATE,
      NS.PUVAL * U1.PARITATE,
      NS.TVA,
      NS.TG,
      NS.TIPSERIE,
      NS.CANTNIR / U1.PARITATE,
      NS.CODLOCATIE,
      I.PARTENER,
      I.INITIALIZARI,
      NS.PUMAXIMAL * U1.PARITATE,
      NS.CANTUM1,
      NS.CANTUM2,
      NS.PROCENTADAOS,
      U1.DEN_UM1,
      U1.PARITATE,
      NS.D1,
      NS.D2,
      NS.D3,
      I1.NRCERTIF,
      coalesce(NS.ROTLEI, NOBJ.ROTUNJIRE),
      coalesce(NS.ROTVALUTA, NOBJ.ROTVALUTA),
      N.TIPNIR,
      NS.CODGESTPROD,
      NS.REST,
      NS.SERIELOT,
      NS.PROVIZION,
      A.UM1,
      A.UM2,
      IOA.MG,
      IOA.DIFPRET,
      IOA.ARETVANEEX,
      IOA.PUSTANDARD,
      NOBJ.DENUMIRE,
      NS.PRET * U1.PARITATE,
      ( NS.PRET - NS.ADAOS) * U1.PARITATE,
      NS.CODIOART,
      NS.EUDR_RN, NS.EUDR_VN
    FROM
      NIRSTOC NS
      left join TMP_OBJSTOCINI OI   ON OI.CODOBIECT = NS.CODOBIECT
      left join TMP_IOART_LUNA IOA  ON IOA.CODIOART = NS.CODIOART
      left join NIR            N    ON N.CODNIR     = NS.CODNIR
      left join INTRARI1       I1   ON I1.CODINTR1  = NS.CODINTR1
      left join INTRARI        I    ON I.CODINTR    = N.CODINTR
      left join NARTOBJ        NOBJ ON NS.CODOBIECT = NOBJ.CODOBIECT
      left join NART           A    ON A.CODARTICOL = NOBJ.CODARTICOL
      left join IESIRI         E    ON E.CODIES     = N.CODIES,
      NUM1 U1
    where
      N.GEST = aCODGEST
      and E.AN * 12 + E.LUNA &lt; current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric * 12 + current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric
      and NS.UMSEC = U1.CODUM1
      and N.TIPNIR &gt;= 14 );

  INSERT INTO TMP_NIRSTOCINI
  ( CODOBJSTOCINI,
    CODNIRSTOC,
    CODNIR,
    CODTRANSF1,
    CODTRANSF,
    DATADOC,
    CODOBIECT,
    CODIOART,
    UMSEC,
    PRETACHIZ,
    PRETINREG,
    PUVAL,
    TVA,
    TG,
    TIPSERIE,
    CANTNIR,
    CODLOCATIE,
    FURNIZOR,
    PUMAXIMAL,
    CANTUM1,
    CANTUM2,
    PROCENTADAOS,
    DENUM,
    PARITATE,
    ROTLEI,
    ROTVALUTA,
    TIPNIR,
    CODGESTPROD,
    REST,
    SERIELOT,
    CODCENTRU,
    PROVIZION,
    UM1,
    UM2,
    MG,
    DIFPRET,
    ARETVANEEX,
    PUSTANDARD,
    DENOBIECT,
    PRETINITIAL,
    ACHIZINITIAL,
    CODIOARTINITIAL,
    EUDR_RN, EUDR_VN )
  (
    SELECT
      OI.CODOBJSTOCINI,
      NS.CODNIRSTOC,
      NS.CODNIR,
      T1.CODTRANSF1,
      T.CODTRANSF,
      T.DATADOC,
      NS.CODOBIECT,
      NS.CODIOART,
      NS.UMSEC,
      ( NS.PRET - NS.ADAOS) * U1.PARITATE,
      NS.PRET * U1.PARITATE,
      NS.PUVAL * U1.PARITATE,
      NS.TVA,
      NS.TG,
      NS.TIPSERIE,
      NS.CANTNIR / U1.PARITATE,
      NS.CODLOCATIE,
      NS.FURN,
      NS.PUMAXIMAL * U1.PARITATE,
      NS.CANTUM1,
      NS.CANTUM2,
      NS.PROCENTADAOS,
      U1.DEN_UM1,
      U1.PARITATE,
      coalesce(NS.ROTLEI, NOBJ.ROTUNJIRE),
      coalesce(NS.ROTVALUTA, NOBJ.ROTVALUTA),
      N.TIPNIR,
      NS.CODGESTPROD,
      NS.REST,
      NS.SERIELOT,
      T1.CODCENTRU,
      NS.PROVIZION,
      A.UM1,
      A.UM2,
      IOA.MG,
      IOA.DIFPRET,
      IOA.ARETVANEEX,
      IOA.PUSTANDARD,
      NOBJ.DENUMIRE,
      NS.PRET * U1.PARITATE,
      ( NS.PRET - NS.ADAOS) * U1.PARITATE,
      NS.CODIOART,
      NS.EUDR_RN, NS.EUDR_VN
    FROM
      NIRSTOC NS
      left join TMP_OBJSTOCINI OI   ON OI.CODOBIECT    = NS.CODOBIECT
      left join TMP_IOART_LUNA IOA  ON IOA.CODIOART    = NS.CODIOART
      left join NIR            N    ON N.CODNIR        = NS.CODNIR
      left join TRANSF1        T1   ON T1.CODTRANSF1   = NS.CODTRANSF1
      left join NARTOBJ        NOBJ ON NS.CODOBIECT    = NOBJ.CODOBIECT
      left join NART           A    ON NOBJ.CODARTICOL = A.CODARTICOL
      left join TRANSF         T    ON T.CODTRANSF     = N.CODTRANSF,
      NUM1 U1
    WHERE
      N.GEST = aCODGEST
      and T.AN * 12 + T.LUNA &lt; current_setting('PKG_GLOBALS.ANINITIAL', true)::numeric * 12 + current_setting('PKG_GLOBALS.LUNAINITIALA', true)::numeric
      and NS.UMSEC = U1.CODUM1
      and N.TIPNIR in (12, 13) );

  INSERT INTO TMP_NIRSERINI
  ( CODNIRSER,
    CODNIRSTOC,
    CODSERIE,
    CANTNIR,
    CANTUM1,
    CANTUM2, OBS, CodCertif, DataProd, Stare, Divizor, Bucati, SERIE, NRCERTIF, TG, DataProd1, TG1, Codproducator)
 (
    SELECT
      CODNIRSER,
      CODNIRSTOC,
      NS.CODSERIE,
      CANTNIR,
      CANTUM1,
      CANTUM2,
      NS.OBS,
      NS.CodCertif,
      NS.DataProd,
      NS.Stare,
      NS.Divizor,
      NS.Bucati,
      coalesce(( select SERIE from NSERII where CODSERIE = NS.CODSERIE ), ''),
      C.NRCERTIF,
      NS.TG,
      NS.DataProd1,
      NS.TG1,
      NS.CodProducator
    from
      NIRSER NS
      left join CERTIF C ON C.CODCERTIF = NS.CODCERTIF
    WHERE
      CODNIRSTOC in (SELECT CODNIRSTOC FROM TMP_NIRSTOCINI ) );

  UPDATE TMP_NIRSERINI NSE
  set
    PARITATE = coalesce(( select PARITATE from TMP_NIRSTOCINI where CODNIRSTOC = NSE.CODNIRSTOC limit 1 ), 1),
    CANTNIR  = CANTNIR / coalesce(( select PARITATE from TMP_NIRSTOCINI where CODNIRSTOC = NSE.CODNIRSTOC limit 1 ), 1),
    CANTUM1  = CANTUM1 / coalesce(( select PARITATE from TMP_NIRSTOCINI where CODNIRSTOC = NSE.CODNIRSTOC limit 1 ), 1),
    CANTUM2  = CANTUM2 / coalesce(( select PARITATE from TMP_NIRSTOCINI where CODNIRSTOC = NSE.CODNIRSTOC limit 1 ), 1) ;

  INSERT INTO TMP_NIRSTOC (CODNIRSTOC)
  SELECT CODNIRSTOC FROM TMP_NIRSTOCINI;

  INSERT INTO TMP_NIRSTOC1
  SELECT NS1.* FROM NIRSTOC1 NS1 WHERE exists (SELECT NS.CODNIRSTOC FROM TMP_NIRSTOCINI NS WHERE NS1.CODNIRSTOC = NS.CODNIRSTOC );

 end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_subsidiary_setcdataini</obj_name>
  <obj_hashval>6cfdb66c7855a7a97ee0e7dbf6847d3c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_subsidiary_setcdataini(acdataini date)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_SUBSIDIARY.cDataIni',acDataIni,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tari_sp_deleterecord</obj_name>
  <obj_hashval>e744040facd484fe8636ded0331e89a2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tari_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_TARI_SP_LOCKRECORD( RecId);
  DELETE FROM NTARI WHERE codtara = RecId;
  PERFORM NotifyModif( 2, RecId, 'NTARI');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_teme_teme_postrecord</obj_name>
  <obj_hashval>aa6f742ebf9e10eefb6894ce083d30f2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_teme_teme_postrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_X RECORD;
  V_REC RECORD;
begin
  FOR V_X IN (SELECT CodPers FROM TMP_NPERSCURS0 WHERE Selectat = 1) LOOP
    DELETE FROM NPERSCURS
    WHERE CodPers = V_X.CodPers
      and CodNPERSCURS IN (SELECT CodNPERSCURS FROM NPERSCURS WHERE CodPers = V_X.CodPers AND CodNPERSCURS IN (SELECT CodNPERSCURS FROM TMP_NPERSCURS));

    FOR v_rec IN (SELECT * FROM TMP_NPERSCURS WHERE Sel = 1 and CodNPERSCURS &gt; 0 and CODPERS = V_X.CodPers) LOOP
      UPDATE NPERSCURS
      SET
        CODCURS      = V_REC.CODCURS,
        CODTEMA      = V_REC.CODTEMA,
        STARE        = V_REC.STARE,
        NOTA         = V_REC.NOTA,
        DATA         = V_REC.DATA,
        DATAPLAN     = V_REC.DATAPLAN,
        TipFormare   = V_REC.TipFormare,
        NivelFormare = V_REC.NivelFormare,
        CodObiectiv  = V_REC.CodObiectiv,
        CodFunctie   = (SELECT Min (P1.CodFunctie) FROM NPERS1 P1 INNER JOIN FUNCTII1 F1 ON F1.CodFunctie = P1.Codfunctie
                        WHERE P1.CodPers = V_X.CodPers and F1.CodTema = V_REC.CodTema and F1.CodCurs = V_REC.CodCurs) ,
        ORE_REALIZ   = V_REC.ORE_REALIZ
      WHERE
        CodNPERSCURS = v_rec.CODNPERSCURS;
    END LOOP;

    INSERT INTO NPERSCURS (CodNPERSCURS,
        CODPERS,
        CODFUNCTIE,
        CODCURS,
        CODTEMA,
        STARE,
        NOTA,
        DATA,
        DATAPLAN,
        TipFormare,
        NivelFormare,
        CodObiectiv,
        ORE_REALIZ)
    SELECT NEXTVAL ('SEQ_NPERSCURS_CODNPERSCURS') , V_X.CodPers,
          (SELECT Min (P1.CodFunctie) FROM NPERS1 P1 INNER JOIN FUNCTII1 F1 ON F1.CodFunctie = P1.Codfunctie
           WHERE P1.CodPers = V_X.CodPers and F1.CodTema = CodTema and F1.CodCurs = CodCurs) ,
          CODCURS,
          CODTEMA,
          STARE,
          NOTA,
          DATA,
          DATAPLAN,
          TipFormare,
          NivelFormare,
          CodObiectiv,
          ORE_REALIZ
    FROM TMP_NPERSCURS WHERE CodNPERSCURS &lt; 0 and CODPERS = V_X.CodPers;
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tippartincert_sp_deleterecord</obj_name>
  <obj_hashval>ad91064ec3b3e64c2bedbef41198091e</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tippartincert_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  PERFORM PKG_TIPPARTINCERT_SP_LOCKRECORD( RecId);
  DELETE FROM TIPPARTINCERT WHERE CODTIPPARTINCERT = RecId;
  PERFORM NotifyModif( 2, RecId, 'TIPPARTINCERT');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transeini_sp_postrecords</obj_name>
  <obj_hashval>42d6cad6d401f6f28c1d33617b4bd846</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transeini_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
V_REC        RECORD;
aCODOBLIGPIF numeric;
aCODGENERAL  numeric;
aCODTREZOR1  numeric;
aCODTREZOR   numeric;
aCODMONEDA   numeric;
ANI          numeric;
LUNAI        numeric;
BEGIN
  --Adina 16.01.2021 - aranjat pt.verificare cu Oracle
  --Florin 14.01.2021 - schimbat apelul PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA, delete al doilea insert in OBLIGPIF
  SELECT NEWAN, NEWLUNA
  INTO ANI, LUNAI
  FROM PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( TO_NUMBER((current_setting('PKG_GLOBALS.ANINITIAL', true)),'999999999999999999'), TO_NUMBER((current_setting('PKG_GLOBALS.LUNAINITIALA', true)),'999999999999999999'), ANI, LUNAI);

  SELECT CODBANKCONT, CODMONEDA INTO RECID, aCODMONEDA FROM TMP_TRANSEINI;

  IF  Operation = 0 THEN
    UPDATE TRANSEINI SET CODBANKCONT = RECID WHERE CODBANKCONT = RECID;

    FOR V_REC IN (SELECT O.CODOBLIGPIF, O.CODGENERAL, T1.CODTREZOR1
                  FROM OBLIGPIF O, GENERAL G, TREZOR1 T1
                  WHERE O.SEMNIFICATIE = 800
                        AND  G.CODGENERAL = O.CODGENERAL
                        AND  G.TIPDOC = 30
                        AND  G.CODDOC = T1.CODTREZOR1
                        AND  T1.AN * 12 + T1.LUNA &lt; TO_NUMBER((current_setting('PKG_GLOBALS.ANINITIAL', true)),'999999999999999999') * 12 + TO_NUMBER((current_setting('PKG_GLOBALS.LUNAINITIALA', true)),'999999999999999999')
                        AND  EXISTS (SELECT CODOBLIGPIF
                                     FROM TMP_OBLIGPIF_INITIAL
                                     WHERE CODOBLIGPIF = O.CODOBLIGPIF
                                    )
                        AND NOT EXISTS (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF WHERE CODOBLIGPIF = O.CODOBLIGPIF)
                 )
    LOOP
      DELETE FROM GENERAL  WHERE CODGENERAL  = V_REC.CODGENERAL;
      DELETE FROM OBLIGPIF WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
    END LOOP;

    FOR V_REC IN (SELECT O.*, G.CODDOC FROM TMP_OBLIGPIF O, TMP_GENERAL G WHERE O.CODGENERAL = G.CODGENERAL)
    LOOP
      IF  V_REC.CODOBLIGPIF &lt; 0 THEN
        SELECT NEXTVAL('SEQ_GENERAL_CODGENERAL')   INTO aCODGENERAL;
        SELECT NEXTVAL('SEQ_TREZOR1_CODTREZOR1')   INTO aCODTREZOR1;
        SELECT NEXTVAL('SEQ_TREZOR_CODTREZOR')     INTO aCODTREZOR;
        SELECT NEXTVAL('SEQ_OBLIGPIF_CODOBLIGPIF') INTO aCODOBLIGPIF;

        UPDATE TMP_OBLIGPIF SET CODOBLIGPIF = aCODOBLIGPIF WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;

        INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, CODPART, ICONT, SEMNIFICATIE, CONTBANKTRANZACTIE, VALOAREAFISATA)
        VALUES(aCODOBLIGPIF, aCODGENERAL, V_REC.SUMAVALUTA, V_REC.CODPART, V_REC.ICONT, 800, RECID, V_REC.SUMAVALUTA);

        INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
        VALUES(aCODGENERAL, 30, aCODTREZOR1, aCODMONEDA, V_REC.CURS, 800);

        INSERT INTO TREZOR1(CODTREZOR1, CODTREZOR, INDEXLOCAL, TIPTRANZ, DOC, NRDOC, DATADOC, VALDOC, CURS, CODPART, OBIECTTRANZ, OBS, AN, LUNA, ANULAT, USERID, DATACREARE)
        VALUES(aCODTREZOR1, aCODTREZOR, 1, 0, V_REC.INFOTRANSA, V_REC.NRDOC, V_REC.DATADOC, V_REC.SUMAVALUTA, V_REC.CURS, V_REC.CODPART, 3, V_REC.OBS, ANI, LUNAI, 0, TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999'), CURRENT_TIMESTAMP);

        INSERT INTO TREZOR(CODTREZOR, TIPDOC, CODBANCA, DATADOC, AN, LUNA, OPERAT, USERID, DATACREARE, SUBUNITATEA)
        VALUES(aCODTREZOR, 30, RECID, V_REC.DATADOC, ANI, LUNAI, 1, TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999'), CURRENT_TIMESTAMP, V_REC.SUBUNITATEA);
      ELSE
        UPDATE OBLIGPIF
        SET
          VALOARE            = V_REC.SUMAVALUTA,
          CODPART            = V_REC.CODPART,
          VALOAREAFISATA     = V_REC.SUMAVALUTA,
          CONTBANKTRANZACTIE = RECID
        WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;

        UPDATE GENERAL
        SET
          MONEDA = aCODMONEDA,
          CURS   = V_REC.CURS
        WHERE CODGENERAL = V_REC.CODGENERAL;

        UPDATE TREZOR1
        SET
          DOC     = V_REC.INFOTRANSA,
          NRDOC   = V_REC.NRDOC,
          DATADOC = V_REC.DATADOC,
          VALDOC  = V_REC.SUMAVALUTA,
          CURS    = V_REC.CURS,
          CODPART = V_REC.CODPART,
          OBS     = V_REC.OBS
        WHERE CODTREZOR1 = V_REC.CODDOC;

        SELECT CODTREZOR INTO aCODTREZOR FROM TREZOR1 WHERE CODTREZOR1 = V_REC.CODDOC;

        UPDATE TREZOR
        SET
          CODBANCA = RECID,
          DATADOC  = V_REC.DATADOC
        WHERE CODTREZOR = aCODTREZOR;
      END IF;
    END LOOP;
  ELSE
    FOR V_REC IN (SELECT O.*, G.CODDOC FROM TMP_OBLIGPIF O, TMP_GENERAL G WHERE O.CODGENERAL = G.CODGENERAL)
    LOOP
      INSERT INTO TRANSEINI(CODBANKCONT) VALUES(RECID);

      SELECT NEXTVAL('SEQ_GENERAL_CODGENERAL')   INTO aCODGENERAL;
      SELECT NEXTVAL('SEQ_TREZOR1_CODTREZOR1')   INTO aCODTREZOR1;
      SELECT NEXTVAL('SEQ_TREZOR_CODTREZOR')     INTO aCODTREZOR;
      SELECT NEXTVAL('SEQ_OBLIGPIF_CODOBLIGPIF') INTO aCODOBLIGPIF;

      UPDATE TMP_OBLIGPIF SET CODOBLIGPIF = aCODOBLIGPIF WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;

      INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, CODPART, ICONT, SEMNIFICATIE, CONTBANKTRANZACTIE, VALOAREAFISATA)
      VALUES(aCODOBLIGPIF, aCODGENERAL, V_REC.SUMAVALUTA, V_REC.CODPART, V_REC.ICONT, 800, RECID, V_REC.SUMAVALUTA);

      INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
      VALUES(aCODGENERAL, 30, aCODTREZOR1, aCODMONEDA, V_REC.CURS, 800);

      INSERT INTO TREZOR1(CODTREZOR1, CODTREZOR, INDEXLOCAL, TIPTRANZ, DOC, NRDOC, DATADOC, VALDOC, CURS, CODPART, OBIECTTRANZ, OBS, AN, LUNA, ANULAT, USERID, DATACREARE)
      VALUES(aCODTREZOR1, aCODTREZOR, 1, 0, V_REC.INFOTRANSA, V_REC.NRDOC, V_REC.DATADOC, V_REC.SUMAVALUTA, V_REC.CURS, V_REC.CODPART, 3, V_REC.OBS, ANI, LUNAI, 0, TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999'), CURRENT_TIMESTAMP);

      INSERT INTO TREZOR(CODTREZOR, TIPDOC, CODBANCA, DATADOC, AN, LUNA, OPERAT, USERID, DATACREARE, SUBUNITATEA)
      VALUES(aCODTREZOR, 30, RECID, V_REC.DATADOC, ANI, LUNAI, 1, TO_NUMBER((current_setting('PKG_GLOBALS.USERID', true)),'999999999999999999'), CURRENT_TIMESTAMP, V_REC.SUBUNITATEA);
    END LOOP;
  END IF;

  FOR V_REC IN (SELECT OI.CODOBLIGPIF FROM TMP_OBLIGPIF_INITIAL OI
                union
                SELECT OI.CODOBLIGPIF FROM TMP_OBLIGPIF OI
               )
  LOOP
    UPDATE OBLIGPIF
    SET
      RESTTRANSA = VALOARE - COALESCE( (SELECT SUM( VALOARE) FROM OBLIGPIF WHERE CODTRANSA = V_REC.CODOBLIGPIF), 0)
    WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
  END LOOP;

  UPDATE OBLIGPIF O
  SET
    REST = 0
  WHERE EXISTS (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF_INITIAL WHERE CODOBLIGPIF = O.CODOBLIGPIF)
        OR
        EXISTS (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF         WHERE CODOBLIGPIF = O.CODOBLIGPIF);

  PERFORM NotifyModif( Operation, RecId, 'TRANSEINI');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_setaindicativ</obj_name>
  <obj_hashval>73b8c8c45ffbdaa8aef294d091c048ab</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_setaindicativ(aaindicativ character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_TRANSPORT.aINDICATIV',aaINDICATIV,false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_transport_setvtiprepartizare</obj_name>
  <obj_hashval>85b9be732e03e3bab945237453baeda8</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_transport_setvtiprepartizare(avtiprepartizare numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
perform set_config('PKG_TRANSPORT.vTipRepartizare',to_char(avTipRepartizare,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_carnetdoc_i</obj_name>
  <obj_hashval>3829158bee3aeef31a6a5ba4a1e8d799</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_carnetdoc_i(INOUT wme_result numeric, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := TO_NUMBER(current_setting('PKG_TREZOR.CARNETDOC_I', true),'999999999999999999');
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := NULL;
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_setnrdoc_i</obj_name>
  <obj_hashval>dc6d2bb06b258ea44d040ac8023599e9</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_setnrdoc_i(anrdoc numeric, acarnet numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  perform set_config('PKG_TREZOR.CARNETDOC_I',to_char(ACARNET,'999999999999999999'),false);
  perform set_config('PKG_TREZOR.NRDOC_I'    ,to_char(ANRDOC ,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_sp_deleterecord</obj_name>
  <obj_hashval>38198e8c45b158f0828b82b3473f9ded</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC           RECORD;
  V_RECAV         RECORD;
  V_RECJURN       RECORD;
  V_REC_JURN_SUB  RECORD;
  TIPDOCCASABANCA numeric;
  aCodSubunit     numeric;
  aDataDoc        date;
  aDoc            varchar;
  aCARNETDOC      numeric;
  aNRDOC          numeric;
BEGIN
  --Florin 22.11.2023 - sinc. Oracle
  --Florin 01.06.2023 - monitor
  --Florin 11.04.2023 - sinc. Oracle (10.04.2023)
  --Florin 18.10.2022 - sinc. Oracle
  --Florin 16.02.2022 - sinc. Oracle
    --Florin 23.03.2021 - pkg_userfirme_postlogcucommit
  perform pkg_trezor_setct_monitor('MON_16');
  PERFORM PKG_GLOBALS_MarkDirtyJurnal();
  PERFORM PKG_TREZOR_SP_LOCKRECORD( RecId);

  SELECT TIPDOC, SUBUNITATEA, DATADOC, NUMEDOC || '/' || DATADOC, COALESCE( CARNETDOC, 0), COALESCE( NRDOC, 0)
  INTO TIPDOCCASABANCA, aCodSubunit, aDataDoc, aDoc, aCARNETDOC, aNRDOC
  FROM TREZOR
  WHERE CODTREZOR = RecID;

  IF (SELECT PKG_USERFIRME_ValidPostLog.WME_RESULT FROM PKG_USERFIRME_ValidPostLog(NULL, TO_NUMBER(current_setting('PKG_GLOBALS.USERID', true),'999999999999999999'), current_setting('PKG_TREZOR.CT_MONITOR', true)))
  THEN
    PERFORM pkg_userfirme_postlogcucommit( 'TREZOR', current_setting('PKG_GLOBALS.USERNAME', true), 'S', RECID, current_setting('PKG_GLOBALS.FIRMANAME', true), aCodSubunit, aDataDoc, aDoc, '', (SELECT PKG_GLOBALS_GET_EXE_VERSION.WME_RESULT FROM PKG_GLOBALS_GET_EXE_VERSION(NULL,NULL)));
  END IF;
  PERFORM PKG_CFGTABLES_EXT_DELETERECORD (recId, TIPDOCCASABANCA);
  DELETE FROM TMP_TREZOR1;
  INSERT INTO TMP_TREZOR1(CODTREZOR1, CODSERTAR, CodPLATA1)
  (SELECT CODTREZOR1, CODSERTAR, CodPLATA1 FROM TREZOR1 WHERE CODTREZOR = RECID);

  DELETE FROM TMP_OBLIGPIF;
  INSERT INTO TMP_OBLIGPIF(CODOBLIGPIF, CODTRANSA)
  (SELECT CODOBLIGPIF, CODTRANSA
   FROM OBLIGPIF
   WHERE CODGENERAL IN (SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = TIPDOCCASABANCA AND CODDOC IN (SELECT CODTREZOR1 FROM TMP_TREZOR1))
  );

  DELETE FROM TMP_STINGERE;
  INSERT INTO TMP_STINGERE(CODSTINGERE, CODSTINSPIF, CODPLATA1)
  SELECT CODSTINGERE, CODSTINSPIF, CODPLATA1 FROM STINGERE WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF);

  FOR V_REC IN (SELECT * FROM TMP_STINGERE) LOOP
    PERFORM pkg_trezor_NotifyStergereIncasareFact(V_REC.CODSTINGERE);
    DELETE FROM STINGERE WHERE CODSTINGERE = V_REC.CODSTINGERE;

    IF  COALESCE( V_REC.CODPLATA1, 0) &lt;&gt; 0 THEN
      UPDATE PLATI1
      SET
      STINSA = 0,
      REST   = VALOARE
      WHERE
       CODPLATA1 = V_REC.CODPLATA1;
    END IF;
  END LOOP;

  FOR V_REC IN (SELECT * FROM OBLIGPIF O WHERE EXISTS (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF WHERE CODOBLIGPIF = O.CODOBLIGPIF)) LOOP
    FOR V_RECAV IN (SELECT * FROM CHELTAVANS WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF) LOOP
      FOR V_RECJURN IN (SELECT * FROM JURNAL WHERE CODDOC = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106)) LOOP
        UPDATE NCONTRUL
        SET
        RULAJCD      = RULAJCD      - V_RECJURN.VALOARE,
        RULAJVCD     = RULAJVCD     - V_RECJURN.VALOAREV,
        RULAJC_IFRS  = RULAJC_IFRS  - V_RECJURN.VALOARE_IFRS,
        RULAJVC_IFRS = RULAJVC_IFRS - V_RECJURN.VALOAREV_IFRS
        WHERE
         CODCONT = V_RECJURN.CONTD AND  AN = V_RECJURN.AN AND  LUNA = V_RECJURN.LUNA;

        FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_RECJURN.CONTD AND  AN = V_RECJURN.AN AND  LUNA = V_RECJURN.LUNA) LOOP
          UPDATE NCONTRULSUB
          SET
          RULAJCD      = RULAJCD      - V_RECJURN.VALOARE,
          RULAJVCD     = RULAJVCD     - V_RECJURN.VALOAREV,
          RULAJC_IFRS  = RULAJC_IFRS  - V_RECJURN.VALOARE_IFRS,
          RULAJVC_IFRS = RULAJVC_IFRS - V_RECJURN.VALOAREV_IFRS
          WHERE
           CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND  SUBUNITATEA = V_RECJURN.SUBUNITATEA;
        END LOOP;

        UPDATE NCONTRUL
        SET
        RULAJCC      = RULAJCC      - V_RECJURN.VALOARE,
        RULAJVCC     = RULAJVCC     - V_RECJURN.VALOAREV,
        RULAJC_IFRS  = RULAJC_IFRS  - V_RECJURN.VALOARE_IFRS,
        RULAJVC_IFRS = RULAJVC_IFRS - V_RECJURN.VALOAREV_IFRS
        WHERE
         CODCONT = V_RECJURN.CONTC AND  AN = V_RECJURN.AN AND  LUNA = V_RECJURN.LUNA;

        FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_RECJURN.CONTC AND  AN = V_RECJURN.AN AND  LUNA = V_RECJURN.LUNA) LOOP
          UPDATE NCONTRULSUB
          SET
          RULAJCC      = RULAJCC - V_RECJURN.VALOARE,
          RULAJVCC     = RULAJVCC - V_RECJURN.VALOAREV,
          RULAJC_IFRS  = RULAJC_IFRS - V_RECJURN.VALOARE_IFRS,
          RULAJVC_IFRS = RULAJVC_IFRS - V_RECJURN.VALOAREV_IFRS
          WHERE
           CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND  SUBUNITATEA = V_RECJURN.SUBUNITATEA;
        END LOOP;
      END LOOP;

      DELETE FROM JURNAL1     WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106);
      DELETE FROM JURNAL       WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106);
      DELETE FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
      DELETE FROM CHELTAVANS   WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
    END LOOP;

    DELETE FROM MASTERCHELTAVANS WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
    DELETE FROM OBLIGPIF         WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
  END LOOP;

  DELETE FROM GENERAL WHERE TIPDOC = TIPDOCCASABANCA AND CODDOC IN (SELECT CODTREZOR1 FROM TMP_TREZOR1);

  FOR V_REC IN (SELECT * FROM TREZOR1 WHERE CodTREZOR = RecId) LOOP
    DELETE FROM TAXDECL WHERE TipDoc = TIPDOCCASABANCA and CODDOC = V_REC.CodTrezor1;
    IF  V_REC.CARNETDOC &lt;&gt; 0 AND  V_REC.NRDOC &lt;&gt; 0 THEN
      PERFORM PKG_CARNETEDOC_RELEASENUMARDOC( V_REC.CARNETDOC, V_REC.NRDOC);
      PERFORM PKG_CARNETEDOC_COMPACTEAZAINTERVALE( V_REC.CARNETDOC);
    END IF;
  END LOOP;

  DELETE FROM TREZOR1 WHERE CODTREZOR = RecID;
  DELETE FROM TREZOR  WHERE CODTREZOR = RecID;

  UPDATE OBLIGPIF O
  SET
  REST    = (CASE WHEN  VALOARE &gt;= 0 THEN VALOARE - COALESCE( (SELECT SUM( VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
                  WHEN  VALOARE &lt;  0 THEN VALOARE + COALESCE( (SELECT SUM( VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)

             END ) ,
  RESTTVA = (CASE WHEN VALOARE &gt;= 0 THEN COALESCE( DINCARETVA, 0) - COALESCE( (SELECT SUM( COALESCE( DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
                  WHEN VALOARE &lt;  0 THEN COALESCE( DINCARETVA, 0) + COALESCE( (SELECT SUM( COALESCE( DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
             END )
  WHERE
  O.CODOBLIGPIF IN (SELECT CODSTINSPIF FROM TMP_STINGERE);

  FOR V_REC IN (SELECT * FROM JURNAL WHERE CODDOC = RecID AND  TIPDOC = TIPDOCCASABANCA) LOOP
    UPDATE NCONTRUL
    SET
    RULAJCD      = RULAJCD      - V_REC.VALOARE,
    RULAJVCD     = RULAJVCD     - V_REC.VALOAREV,
    RULAJC_IFRS  = RULAJC_IFRS  - V_REC.VALOARE_IFRS,
    RULAJVC_IFRS = RULAJVC_IFRS - V_REC.VALOAREV_IFRS
    WHERE
     CODCONT = V_REC.CONTD AND  AN = TO_NUMBER(current_setting('PKG_GLOBALS.ANLUCRU', true),'999999999999999999') AND  LUNA = TO_NUMBER(current_setting('PKG_GLOBALS.LUNALUCRU', true),'999999999999999999');

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND  AN = V_REC.AN AND  LUNA = V_REC.LUNA) LOOP
      UPDATE NCONTRULSUB
      SET
      RULAJCD      = RULAJCD      - V_REC.VALOARE,
      RULAJVCD     = RULAJVCD     - V_REC.VALOAREV,
      RULAJC_IFRS  = RULAJC_IFRS  - V_REC.VALOARE_IFRS,
      RULAJVC_IFRS = RULAJVC_IFRS - V_REC.VALOAREV_IFRS
      WHERE
       CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND  SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;

    UPDATE NCONTRUL
    SET
    RULAJCC      = RULAJCC      - V_REC.VALOARE,
    RULAJVCC     = RULAJVCC     - V_REC.VALOAREV,
    RULAJC_IFRS  = RULAJC_IFRS  - V_REC.VALOARE_IFRS,
    RULAJVC_IFRS = RULAJVC_IFRS - V_REC.VALOAREV_IFRS
    WHERE
     CODCONT = V_REC.CONTC AND  AN = TO_NUMBER(current_setting('PKG_GLOBALS.ANLUCRU', true),'999999999999999999') AND  LUNA = TO_NUMBER(current_setting('PKG_GLOBALS.LUNALUCRU', true),'999999999999999999');

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND  AN = V_REC.AN AND  LUNA = V_REC.LUNA) LOOP
      UPDATE NCONTRULSUB
      SET
      RULAJCC      = RULAJCC      - V_REC.VALOARE,
      RULAJVCC     = RULAJVCC     - V_REC.VALOAREV,
      RULAJC_IFRS  = RULAJC_IFRS  - V_REC.VALOARE_IFRS,
      RULAJVC_IFRS = RULAJVC_IFRS - V_REC.VALOAREV_IFRS
      WHERE
       CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND  SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;
  END LOOP;

  DELETE FROM JURNAL  WHERE CODDOC = RecID AND  TIPDOC = TIPDOCCASABANCA;
  DELETE FROM JURNAL1 WHERE CODDOC = RecID AND  TIPDOC = TIPDOCCASABANCA;
  DELETE FROM EXPERT1 WHERE CODEXPERT in (SELECT CODEXPERT FROM EXPERT WHERE CODDOC = RecID and TIPDOC = TIPDOCCASABANCA);
  DELETE FROM EXPERT  WHERE CODDOC = RecID and  TIPDOC = TIPDOCCASABANCA;

  FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF WHERE COALESCE( CODTRANSA, 0) &lt;&gt; 0) LOOP
    UPDATE OBLIGPIF
    SET
    RESTTRANSA = VALOARE - COALESCE( (SELECT SUM( O.VALOARE * COALESCE( G.CURS, 1) / COALESCE( T1.CURS, 1))
                                      FROM OBLIGPIF O, GENERAL G, TREZOR1 T1
                                      WHERE CODTRANSA = V_REC.CODTRANSA AND  G.CODGENERAL = O.CODGENERAL AND  T1.CODTREZOR1 = G.CODDOC
                                     ), 0)
    WHERE
     CODOBLIGPIF = V_REC.CODTRANSA;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_TREZOR1 WHERE COALESCE( CODSERTAR, 0) &lt;&gt; 0) LOOP
    UPDATE NSERTAR SET DEPUS = 0 WHERE CODSERTAR = V_REC.CODSERTAR;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_TREZOR1 WHERE COALESCE( CODPLATA1, 0) &lt;&gt; 0) LOOP
    UPDATE PLATI1
    SET
    STINSA = 0,
    REST   = VALOARE
    WHERE
     CODPLATA1 = V_REC.CODPLATA1;
  END LOOP;

  DELETE FROM DocAsoc WHERE (CODDOC = RECID AND  TIPDOC = TIPDOCCASABANCA) or (CODDOCASOC = RECID AND  TIPDOCASOC = TIPDOCCASABANCA) ;

  IF  aCARNETDOC &lt;&gt; 0 THEN
    PERFORM PKG_CARNETEDOC_RELEASENUMARDOC( aCARNETDOC, aNRDOC);
    PERFORM PKG_CARNETEDOC_COMPACTEAZAINTERVALE( aCARNETDOC);
  END IF;

  PERFORM NotifyModif( 2, RecId, 'TREZOR');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_sp_gotorecord</obj_name>
  <obj_hashval>48f174d8ebd25d7221e78ba3bd3af046</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_sp_gotorecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  V_REC            RECORD;
  TIPDOCCASABANCA  numeric;
  CODNBANKCONT     numeric;
  MONEDADOC        numeric;
  aICONTPERS       numeric;
  aMONEDAPERS      numeric;
  DOCOPERAT        numeric := 0;
  aCODSUBUNITSTINS numeric := 0;
  NEWCONSTVALUE    varchar := '';
  NEWCONSTSIMBOL   varchar := '';
  aCODNBANKCONT1   numeric := 0;
  aCODIOBANK       numeric := 0;
  SOLDLEIBANKA     double precision := 0;
  SOLDVALUTABANKA  double precision := 0;
  SOLDLEIPERS      double precision := 0;
  SOLDVALUTAPERS   double precision := 0;
  aANP             numeric := 0;
  aLUNAP           numeric := 0;
begin
  --Florin 23.11.2023 - sinc. Oracle
  --Florin 22.11.2023 - sinc. Oracle
  --Florin 14.07.2023  - fixat 58830
  --Florin 10.07.2023 (05.07.2023)
  --Florin 11.04.2023 - sinc. Oracle
  --Bogdan 15.03.2022 - fixat zecimale
  --Florin 17.02.2022 - fixat 53110
  --Florin 14.02.2022 - fixat 53077
  --Bogdan 11.02.2022 - 52981 : Monetare - TaxCode si Baza taxa coloane string si concatenate
    --Florin 09.02.2022 - sinc. Oracle
  --Bogdan 08.02.2022 52981 : Monetare - TaxCode si Baza taxa
  --Florin 16.11.2021 - fixat 52001
  --perform PKG_STOC_GENERARE_FACTURI_MAKE_CONFIG_LUNA();
  --Florin 22.04.2021 - fixat 40708
  --Florin 12.05.2021 - fixat 49370

  perform pkg_trezor_setct_monitor('MON_16');
  perform PKG_GLOBALS_SETLUNATEMP( to_number(current_setting('PKG_GLOBALS.ANLUCRU'  , true), '999999999999999999'),
                                   to_number(current_setting('PKG_GLOBALS.LUNALUCRU', true), '999999999999999999'));

  --perform PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( to_number(current_setting('PKG_GLOBALS.ANLUCRU', true), '999999999999999999'),
  --to_number(current_setting('PKG_GLOBALS.LUNALUCRU', true), '999999999999999999'),
  --to_number(current_setting('PKG_GLOBALS.ANPRECEDENT', true), '999999999999999999'),
  --to_number(current_setting('PKG_GLOBALS.LUNAPRECEDENTA', true), '999999999999999999'));

  aANP := (select PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA.NEWAN
           from PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( to_number(current_setting('PKG_GLOBALS.ANLUCRU'  , true), '999999999999999999'),
                                                        to_number(current_setting('PKG_GLOBALS.LUNALUCRU', true), '999999999999999999'),
                                                        null, null)
          );

  ALunaP := (select PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA.NEWLUNA
             from PKG_GLOBALS_CALCULEAZA_LUNA_PRECEDENTA( to_number(current_setting('PKG_GLOBALS.ANLUCRU'  , true), '999999999999999999'),
                                                          to_number(current_setting('PKG_GLOBALS.LUNALUCRU', true), '999999999999999999'),
                                                          null, null)
            );

  perform set_config('PKG_GLOBALS.ANPRECEDENT'   ,to_char(aAnP  ,'999999999999999999'),false);
  perform set_config('PKG_GLOBALS.LunaPRECEDENTA',to_char(aLunaP,'999999999999999999'),false);

  perform PKG_CONTURIBANCI_MAKE_CURS_BANKCONT_LUNA( '01.' || to_char( to_number(current_setting('PKG_GLOBALS.LUNALUCRU', true), '999999999999999999'), '999999999999999999') || '.' || to_char( to_number(current_setting('PKG_GLOBALS.ANLUCRU', true), '999999999999999999'), '999999999999999999'));


  if RECID &gt; 0 then
    select
      TIPDOC,
      CODBANCA,
      ICONTPERS,
      MONEDAPERS,
      OPERAT
    into
      TIPDOCCASABANCA,
      CODNBANKCONT,
      aICONTPERS,
      aMONEDAPERS,
      DOCOPERAT
    from
      TREZOR
    where
      CODTREZOR = RecID;
    IF coalesce(current_setting('pkg_trezor_SkipAnalizaSold', TRUE),'0')::numeric = 0 then
    if TIPDOCCASABANCA &lt;&gt; 33 then
      perform PKG_CONTURIBANCI_SETCONTBANCACURENT(CODNBANKCONT);

      begin
        SELECT SOLDLEI, SOLDVALUTA INTO SOLDLEIBANKA, SOLDVALUTABANKA FROM V_SOLDBANKLUNA;
      exception
        when others then
          begin
            SOLDLEIBANKA    := 0;
            SOLDVALUTABANKA := 0;
          end;
      end;
    else
      perform PKG_NOMPERS_SET_PERSOANA_CURENTA(CODNBANKCONT);
      perform PKG_NOMPERS_SET_ICONTPERS_CURENT(aICONTPERS);
      perform PKG_NOMPERS_SET_MONEDAPERS_CURENT(aMONEDAPERS);

      begin
        SELECT SOLDLEI, SOLDVALUTA INTO SOLDLEIPERS, SOLDVALUTAPERS FROM V_SOLDPERSOANA_LUNA;
      exception
        when others then
          begin
            SOLDLEIPERS    := 0;
            SOLDVALUTAPERS := 0;
          end;
      end;
    end if;
  END IF;

    INSERT INTO TMP_TREZOR1 ( CODTREZOR1,
      CODTREZOR,
      INDEXLOCAL,
      TIPTRANZ,
      CARNETDOC,
      DOC,
      NRDOC,
      DATADOC,
      VALDOC,
      CURS,
      COMISION,
      OBIECTTRANZ,
      SERIEDOC,
      CODPART,
      TIPDECONT,
      PLATATVA,
      CODSERTAR,
      NRI,
      CODCOMANDA,
      CODPLATA1,
      DATADECONT,
      AN,
      LUNA,
      OBS,
      AGENT,
      ANULAT,
      NUMEAGENT,
      CODCENTRU,
      IDENTIFLINIE,
      CODGEST,
      CODCMDINT1,
      CMDINT,
      TAXCODE,
      TAXBASE )
    SELECT *
    FROM
    (select
      T1.CODTREZOR1,
      T1.CODTREZOR,
      T1.INDEXLOCAL,
      T1.TIPTRANZ,
      T1.CARNETDOC,
      T1.DOC,
      T1.NRDOC,
      T1.DATADOC,
      T1.VALDOC,
      T1.CURS,
      T1.COMISION,
      T1.OBIECTTRANZ,
      T1.SERIEDOC,
      T1.CODPART,
      T1.TIPDECONT,
      T1.PLATATVA,
      T1.CODSERTAR,
      T1.NRI,
      T1.CODCOMANDA,
      CODPLATA1,
      T1.DATADECONT,
      T1.AN,
      T1.LUNA,
      T1.OBS,
      T1.AGENT,
      T1.ANULAT,
      (SELECT NUME || ' ' || PRENUME FROM NPERS WHERE CODPERS = T1.AGENT ),
      T1.CODCENTRU,
      T1.DOC || ' ' || T1.NRDOC || '/' || to_char( T1.DATADOC, 'DD.MM.YYYY') || ' - Valoare : ' || trunc(T1.VALDOC) IDENTIFLINIE,
      T1.CODGEST,
      T1.CODCMDINT1,
      C.NRDOC CMDINT,
      CASE WHEN LENGTH(TXDL.TAXCODE_STR) &gt; 250 THEN SUBSTR(TXDL.TAXCODE_STR,0,246)||'...' ELSE TXDL.TAXCODE_STR END,
      CASE WHEN LENGTH(TXDL.TAXBASE_STR) &gt; 250 THEN SUBSTR(TXDL.TAXBASE_STR,0,246)||'...' ELSE TXDL.TAXBASE_STR END
     FROM TREZOR1 T1
        left join COMANDA1 C1 ON C1.CODCOMANDA = T1.CODCMDINT1
        left join COMANDA  C  ON C1.CODCOMANDA = C.CODCOMANDA
        LEFT JOIN (SELECT TXD.TIPDOC,
                              TXD.CODDOC,
                              string_agg(TXD.TAXCODE::varchar,';' order by TXD.CODDOC1) AS TAXCODE_STR,
                              string_agg((TXD.TAXBASE::real)::varchar,';' order by TXD.CODDOC1) AS TAXBASE_STR
                         FROM TAXDECL TXD
                        GROUP BY TXD.TIPDOC, TXD.CODDOC) TXDL
                                                               ON TXDL.TIPDOC = TIPDOCCASABANCA
                                                              and TXDL.CODDOC = T1.CODTREZOR1
      WHERE t1.CODTREZOR = RecID
    ) A_PG
    order BY INDEXLOCAL ;

    insert into TMP_RETUROSTINS (CODRETUROSTINS,
                                 CODRETURO,
                                 CODDOC,
                                 TIPDOC,
                                 VALOARE,
                                 STARTEDAT,
                                 VOUCHERBARCODE)
    select  rs.CODRETUROSTINS,
            rs.CODRETURO,
            rs.CODDOC,
            rs.TIPDOC,
            rs.VALOARE,
            rs.STARTEDAT,
            rs.VOUCHERBARCODE
    from RETUROSTINS rs where rs.tipdoc = TIPDOCCASABANCA and rs.coddoc in (select ttrz1.CODTREZOR1 from TMP_TREZOR1 ttrz1);

    INSERT into
    TMP_TREZOR ( CODTREZOR,
      TIPDOC,
      CODBANCA,
      ICONTPERS,
      MONEDAPERS,
      DATADOC,
      NUMEDOC,
      AN,
      LUNA,
      CODBANK,
      NRCONT,
      CODMONEDA,
      SIMBOLMONEDA,
      SOLDCURENT,
      INCASARI,
      PLATI,
      AGENT,
      OPERAT,
      BLOCAT,
      SUBUNITATEA,
      CREDIT,
      CURSREG,
      UserID,
      CODANALIZA, CARNETDOC, NRDOC, SERIADOC, LISTAT)
    (select
      T.CODTREZOR,
      T.TIPDOC,
      T.CODBANCA,
      T.ICONTPERS,
      T.MONEDAPERS,
      T.DATADOC,
      T.NUMEDOC,
      T.AN,
      T.LUNA,
      coalesce( B.CODBANK, 0),
      CASE
        when TIPDOC = 33 then (SELECT PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT
                               FROM   PKG_PLANCONTURI_GETSIMBOLCONT(null,
                                                                    (SELECT PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG.WME_RESULT
                                                                     FROM   PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(null, 1100, T.ICONTPERS,
                                                                                                                (SELECT PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA.WME_RESULT
                                                                                                                 FROM   PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA(null, T.CODBANCA,
                                                                                                                                                             to_number(current_setting('PKG_GLOBALS.ANLUCRU', true), '999999999999999999'),
                                                                                                                                                             to_number(current_setting('PKG_GLOBALS.LUNALUCRU', true), '999999999999999999')))))))
        else B.NRCONT
      end ,
      CASE when TIPDOC &lt;&gt; 33 then B.CODMONEDA else null end ,
      CASE when TIPDOC = 33 then (SELECT PKG_MONEDE_GET_SIMBOL_MONEDA.WME_RESULT FROM PKG_MONEDE_GET_SIMBOL_MONEDA(null, T.MONEDAPERS))
           else M.SIMBOL
      end ,
      coalesce(CASE when TIPDOC &lt;&gt; 33 and B.CODMONEDA  =  0 then SOLDLEIBANKA
                    when TIPDOC &lt;&gt; 33 and B.CODMONEDA  &lt;&gt; 0 then SOLDVALUTABANKA
                    when TIPDOC =  33 and T.MONEDAPERS =  0 then SOLDLEIPERS
                    when TIPDOC =  33 and T.MONEDAPERS &lt;&gt; 0 then SOLDVALUTAPERS end , 0),
      (SELECT coalesce( sum(VALDOC), 0) FROM TMP_TREZOR1 WHERE DOCOPERAT = 1 and ANULAT = 0 and TIPTRANZ = 1 ),
      (SELECT coalesce( sum(VALDOC), 0) FROM TMP_TREZOR1 WHERE DOCOPERAT = 1 and ANULAT = 0 and TIPTRANZ = 0 )
        + (SELECT coalesce( sum(COMISION), 0) FROM TMP_TREZOR1 WHERE DOCOPERAT = 1 and ANULAT = 0 ),
      AGENT,
      OPERAT,
      BLOCAT,
      T.SUBUNITATEA,
      CASE when TIPDOC = 33 then 0 else B.CREDIT end as CREDIT,
      CASE when TIPDOC = 33 then 0 else REG.CURS end as CURSREG,
      UserID,
      T.CODANALIZA,
      T.CARNETDOC,
      T.NRDOC,
      T.SERIADOC, T.LISTAT
    FROM TREZOR T
          left join NBANKCONT              B   ON B.CODBANKCONT   = T.CODBANCA
          left join TMP_CURS_BANKCONT_LUNA REG ON REG.CODBANKCONT = T.CODBANCA
          left join NMONEDE                M   ON M.CODMONEDA     = B.CODMONEDA
    WHERE CODTREZOR = RecID );

    INSERT INTO TMP_GENERAL ( CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, FARAREG )
    (SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, FARAREG
     FROM general
     WHERE TIPDOC = TIPDOCCASABANCA and CODDOC in (SELECT CODTREZOR1 FROM TMP_TREZOR1 ) );

    INSERT INTO TMP_OBLIGPIF ( CODOBLIGPIF,
      CODGENERAL,
      TERMEN,
      VALOARE,
      REST,
      CODPART,
      ICONT,
      TIPPLATA,
      MAJORARI,
      SEMNIFICATIE,
      TIP,
      CONTBANKTRANZACTIE,
      CODOBLIGASOCIAT,
      VALOAREAFISATA,
      CODGEST,
      CODNPARCAUT,
      CODTRANSA,
      COEFPROVIZION,
      CODCENTRU,
      CODANALIZANOD,
      TVANEDED,
      PROCTVA,
      DINCARETVA,
      RESTTVA,
      TVAAFISAT )
    SELECT
      CODOBLIGPIF,
      CODGENERAL,
      TERMEN,
      VALOARE,
      REST,
      CODPART,
      ICONT,
      TIPPLATA,
      MAJORARI,
      SEMNIFICATIE,
      TIP,
      CONTBANKTRANZACTIE,
      CODOBLIGASOCIAT,
      VALOAREAFISATA,
      CODGEST,
      CODNPARCAUT,
      CODTRANSA,
      COEFPROVIZION,
      CODCENTRU,
      CODANALIZANOD,
      TVANEDED,
      PROCTVA,
      DINCARETVA,
      RESTTVA,
      TVAAFISAT
    FROM (SELECT * FROM OBLIGPIF WHERE CODGENERAL in (SELECT CODGENERAL FROM TMP_GENERAL ) ) B_PG
    order BY CODOBLIGPIF ;

    INSERT INTO TMP_STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE, CODPLATA1, Tipdocplati, DINCARETVA)
    ( SELECT CODSTINGERE, CODSTINSPIF, S.CODSTINGATORPIF, S.VALOARE, S.CODPLATA1, P.TipDoc, S.DINCARETVA
      FROM STINGERE S
          left join PLATI1 P1 on P1.CodPlata1 = S.CodPlata1
          left join PLATI  P  on P .CodPlata  = P1.CodPlata
      WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF));

    SELECT CODMONEDA INTO MONEDADOC FROM TMP_TREZOR;

    for V_REC in (SELECT O.CODOBLIGPIF, T1.TIPDECONT
                  FROM TMP_OBLIGPIF O, TMP_GENERAL G, TMP_TREZOR1 T1
                  WHERE O.SEMNIFICATIE in (500, 600) and O.CODGENERAL = G.CODGENERAL and T1.CODTREZOR1 = G.CODDOC
                 )
    loop
      UPDATE TMP_OBLIGPIF SET ICONT = V_REC.TIPDECONT WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF ;
    end loop;

    for V_REC in (SELECT O.CODOBLIGPIF, OS.SEMNIFICATIE, TS1.TIPDECONT, TS1.OBIECTTRANZ, TS.CODBANCA
                  FROM
                    TMP_OBLIGPIF O,
                    TMP_STINGERE S,
                    OBLIGPIF OS,
                    general GS,
                    TREZOR1 TS1,
                    TREZOR TS
                  WHERE
                    S.CODSTINGATORPIF = O.CODOBLIGPIF
                    and OS.CODOBLIGPIF = S.CODSTINSPIF
                    and OS.SEMNIFICATIE in (500, 600)
                    and O.SEMNIFICATIE in (300, 320, 400, 420)
                    and GS.CODGENERAL = OS.CODGENERAL
                    and TS1.CODTREZOR1 = GS.CODDOC
                    and TS.CODTREZOR = TS1.CODTREZOR
                 )
    loop
      UPDATE TMP_OBLIGPIF
      set
      ICONT              = V_REC.TIPDECONT,
      SIMBOLCONT         = (SELECT PKG_TREZOR_SIMBOLCONTCEC.WME_RESULT FROM PKG_TREZOR_SIMBOLCONTCEC(null, V_REC.CODBANCA, V_REC.SEMNIFICATIE, V_REC.TIPDECONT, V_REC.OBIECTTRANZ, null, null)),
      CONTBANKTRANZACTIE = V_REC.CODBANCA,
      OBIECTTRANZSTINS   = V_REC.OBIECTTRANZ
      where
        CODOBLIGPIF = V_REC.CODOBLIGPIF ;
    end loop;

    UPDATE TMP_OBLIGPIF OB
    set
    SIMBOLCONT =
    CASE when SEMNIFICATIE in (300, 320) and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF LIMIT 1 ), 0) = 500 then OB.SIMBOLCONT
         when SEMNIFICATIE in (400, 420) and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF LIMIT  1 ), 0) = 600 then OB.SIMBOLCONT
         when SEMNIFICATIE in (800, 801) then (SELECT PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT
                                               FROM PKG_PLANCONTURI_GETSIMBOLCONT(null, (SELECT PKG_CATEGCONST_GETVALCONSTBYCODE.WME_RESULT::numeric
                                                                                         FROM PKG_CATEGCONST_GETVALCONSTBYCODE(null, OB.ICONT,
                                                                                                                               to_number(current_setting('PKG_GLOBALS.ANLUCRU', true), '999999999999999999'),
                                                                                                                               to_number(current_setting('PKG_GLOBALS.LUNALUCRU', true), '999999999999999999')))))
         when SEMNIFICATIE in (900, 901, 950, 951) then (SELECT PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT FROM PKG_PLANCONTURI_GETSIMBOLCONT(null, OB.ICONT))
         when SEMNIFICATIE = 1000 then (SELECT PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT
                                        FROM PKG_PLANCONTURI_GETSIMBOLCONT(null,
                                                                           (SELECT PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG.WME_RESULT
                                                                            FROM PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(null, OB.SEMNIFICATIE, OB.ICONT,
                                                                                                                     (SELECT PKG_CONTURIBANCI_GET_BANKCONT_COD_CARACT_LUNA.WME_RESULT
                                                                                                                      FROM PKG_CONTURIBANCI_GET_BANKCONT_COD_CARACT_LUNA(null,
                                                                                                                                                                         CODNBANKCONT,
                                                                                                                                                                         to_number(current_setting('PKG_GLOBALS.ANLUCRU', true), '999999999999999999'),
                                                                                                                                                                         to_number(current_setting('PKG_GLOBALS.LUNALUCRU', true), '999999999999999999')))))))
         when SEMNIFICATIE in (1100, 1101) then (SELECT PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT
                                                 FROM PKG_PLANCONTURI_GETSIMBOLCONT(null,
                                                                                    (SELECT PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG.WME_RESULT
                                                                                     FROM PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(null, OB.SEMNIFICATIE, OB.ICONT,
                                                                                                                              (SELECT PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA.WME_RESULT
                                                                                                                               FROM PKG_NOMPERS_GET_PERS_COD_CARACT_LUNA(null,
                                                                                                                                                                         OB.CODPART,
                                                                                                                                                                         to_number(current_setting('PKG_GLOBALS.ANLUCRU', true), '999999999999999999'),
                                                                                                                                                                         to_number(current_setting('PKG_GLOBALS.LUNALUCRU', true), '999999999999999999')))))))
         else (SELECT PKG_PLANCONTURI_GETSIMBOLCONT.WME_RESULT
               FROM PKG_PLANCONTURI_GETSIMBOLCONT(null,
                                                  (SELECT PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG.WME_RESULT
                                                   FROM PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(null, OB.SEMNIFICATIE, OB.ICONT,
                                                                                            (SELECT PKG_NOMPART_GET_PART_COD_CARACT_LUNA.WME_RESULT
                                                                                             FROM PKG_NOMPART_GET_PART_COD_CARACT_LUNA(null, OB.CODPART,
                                                                                                                                       to_number(current_setting('PKG_GLOBALS.ANLUCRU', true), '999999999999999999'),
                                                                                                                                       to_number(current_setting('PKG_GLOBALS.LUNALUCRU', true), '999999999999999999'))))))) end ,
      FARAREG    = (SELECT FARAREG FROM TMP_GENERAL G WHERE G.CODGENERAL = OB.CODGENERAL ),
      CODTREZOR1 = (SELECT CODDOC  FROM TMP_GENERAL G WHERE G.CODGENERAL = OB.CODGENERAL ),
      CURS       = coalesce( ( select CURS   from TMP_GENERAL where CODGENERAL = OB.CODGENERAL ), 1),
      TVA        = coalesce( ( select TVA    from TMP_GENERAL where CODGENERAL = OB.CODGENERAL ), 0),
      MONEDA     = coalesce( ( select MONEDA from TMP_GENERAL where CODGENERAL = OB.CODGENERAL ), 0),
      SEMNIFCODSTINS = coalesce( ( select O.SEMNIFICATIE from TMP_STINGERE S left join OBLIGPIF O on O.CODOBLIGPIF = S.CODSTINSPIF where S.CODSTINGATORPIF = OB.CODOBLIGPIF LIMIT 1 ), 0),
      CURSISTORIC    = coalesce( ( select G.CURS from TMP_STINGERE S left join OBLIGPIF O on O.CODOBLIGPIF = S.CODSTINSPIF left join general G on G.CODGENERAL = O.CODGENERAL where S.CODSTINGATORPIF = OB.CODOBLIGPIF LIMIT 1 ), 0),
      DENDOCLEGATURA = (
      case
        when SEMNIFICATIE = 300 and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF limit 1 ), 0) = 100
          then (SELECT I.PREFIXDOC || (SELECT PKG_TREZOR_PRELSERIADOC.WME_RESULT FROM PKG_TREZOR_PRELSERIADOC(null, I.SERIADOC)) || I.NRDOC || '(' || to_char( I.DATADOC, 'dd.mm.yyyy') || ')'
                FROM STINGERE S
                    left join OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                    left join general  G ON G.CODGENERAL  = O.CODGENERAL
                    left join INTRARI  I ON I.CODINTR     = G.CODDOC
                WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF limit 1
               )
        when SEMNIFICATIE = 300 and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF LIMIT 1 ), 0) = 130
          then (SELECT 'DVOT' || D.NRDOC::varchar || '(' || to_char( D.DATADOC, 'dd.mm.yyyy') || ')'
                FROM STINGERE S
                    left join OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                    left join general  G ON G.CODGENERAL  = O.CODGENERAL
                    left join DVI      D ON D.CODDVI      = G.CODDOC
                WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF limit  1
               )
        when SEMNIFICATIE = 400 and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF LIMIT 1 ), 0) = 200
          then (SELECT I.PREFIXDOC || (SELECT PKG_TREZOR_PRELSERIADOC.WME_RESULT FROM PKG_TREZOR_PRELSERIADOC(null, I.SERIADOC)) || I.NRDOC || '(' || to_char( I.DATADOC, 'dd.mm.yyyy') || ')'
                FROM STINGERE S
                    left join OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                    left join general  G ON G.CODGENERAL  = O.CODGENERAL
                    left join IESIRI   I ON I.CODIES      = G.CODDOC
                WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF LIMIT 1
               )
        when SEMNIFICATIE = 300 and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF limit 1 ), 0) = 1201
          then (SELECT 'NC' || N.NRDOC::varchar || '(' || to_char( N.DATADOC, 'dd.mm.yyyy') || ')'
                FROM STINGERE S
                    left join OBLIGPIF O  ON O.CODOBLIGPIF = S.CODSTINSPIF
                    left join general  G  ON G.CODGENERAL  = O.CODGENERAL
                    left join NC1      N1 ON N1.CODNC1     = G.CODDOC
                    left join NC       N  ON N.CODNC       = N1.CODNC
                WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF limit 1
               )
        when SEMNIFICATIE = 300 and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF limit 1 ), 0) = 1351
          then (SELECT 'PV' || C.NRDOC || '(' || to_char( C.DATADOC, 'dd.mm.yyyy') || ')'
                FROM STINGERE S
                    left join OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                    left join general  G ON G.CODGENERAL  = O.CODGENERAL
                    left join COMPENS  C ON C.CODCOMPENS  = G.CODDOC
                WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF limit 1
               )
        when SEMNIFICATIE = 400 and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF limit 1 ), 0) = 1200
          then (SELECT 'NC' || N.NRDOC::varchar || '(' || to_char( N.DATADOC, 'dd.mm.yyyy') || ')'
                FROM STINGERE S
                    left join OBLIGPIF O  ON O.CODOBLIGPIF = S.CODSTINSPIF
                    left join general  G  ON G.CODGENERAL  = O.CODGENERAL
                    left join NC1      N1 ON N1.CODNC1     = G.CODDOC
                    left join NC       N  ON N.CODNC       = N1.CODNC
                WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF limit 1
               )
        when SEMNIFICATIE = 400 and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF  LIMIT 1 ), 0) in (1301)
          then (SELECT 'PV' || C.NRDOC::varchar || '(' || to_char( C.DATADOC, 'dd.mm.yyyy') || ')'
                FROM STINGERE S
                    left join OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                    left join general  G ON G.CODGENERAL  = O.CODGENERAL
                    left join COMPENS  C ON C.CODCOMPENS  = G.CODDOC
                WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF limit 1
               )
        when SEMNIFICATIE = 400 and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF  LIMIT 1 ), 0) in (1303)
          then (SELECT I.PREFIXDOC || I.NRDOC::varchar || '(' || to_char( I.DATADOC, 'dd.mm.yyyy') || ')'
                FROM STINGERE S
                    left join OBLIGPIF O  ON O.CODOBLIGPIF = S.CODSTINSPIF
                    left join general  G  ON G.CODGENERAL  = O.CODGENERAL
                    left join COMPENS  C  ON C.CODCOMPENS  = G.CODDOC
                    left join OBLIGPIF F  ON F.CODOBLIGPIF = O.CODOBLIGASOCIAT
                    left join general  GF ON GF.CODGENERAL = F.CODGENERAL
                    left join IESIRI   I  ON I.CODIES      = GF.CODDOC and I.TIPDOC = GF.TIPDOC
                WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF limit 1
               )
        when SEMNIFICATIE = 300 and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF LIMIT 1 ), 0) = 500
          then (SELECT T.DOC || (SELECT PKG_TREZOR_PRELSERIADOC.WME_RESULT FROM PKG_TREZOR_PRELSERIADOC(null, T.SERIEDOC)) || T.NRDOC::varchar || '(' || to_char( T.DATADOC, 'dd.mm.yyyy') || ')'
                FROM STINGERE S
                    left join OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                    left join general  G ON G.CODGENERAL  = O.CODGENERAL
                    left join TREZOR1  T ON T.CODTREZOR1  = G.CODDOC
                WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF limit 1
               )
        when SEMNIFICATIE = 400 and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF LIMIT 1 ), 0) = 600
          then (SELECT T.DOC || (SELECT PKG_TREZOR_PRELSERIADOC.WME_RESULT FROM PKG_TREZOR_PRELSERIADOC(null, T.SERIEDOC)) || T.NRDOC::varchar || '(' || to_char( T.DATADOC, 'dd.mm.yyyy') || ')'
                FROM STINGERE S
                    left join OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                    left join general  G ON G.CODGENERAL  = O.CODGENERAL
                    left join TREZOR1  T ON T.CODTREZOR1  = G.CODDOC
                WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF limit  1
               )
        when SEMNIFICATIE = 320 and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF LIMIT 1 ), 0) in (310, 330, 500)
          then (SELECT T.DOC || (SELECT PKG_TREZOR_PRELSERIADOC.WME_RESULT FROM PKG_TREZOR_PRELSERIADOC(null, T.SERIEDOC)) || T.NRDOC::varchar || '(' || to_char( T.DATADOC, 'dd.mm.yyyy') || ')'
                FROM STINGERE S
                    left join OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                    left join general  G ON G.CODGENERAL  = O.CODGENERAL
                    left join TREZOR1  T ON T.CODTREZOR1  = G.CODDOC
                WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF limit 1
               )
        when SEMNIFICATIE = 420 and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF LIMIT 1 ), 0) in (410, 430, 600)
          then (SELECT T.DOC || (SELECT PKG_TREZOR_PRELSERIADOC.WME_RESULT FROM PKG_TREZOR_PRELSERIADOC(null, T.SERIEDOC)) || T.NRDOC::varchar || '(' || to_char( T.DATADOC, 'dd.mm.yyyy') || ')'
                FROM STINGERE S
                    left join OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                    left join general  G ON G.CODGENERAL  = O.CODGENERAL
                    left join TREZOR1  T ON T.CODTREZOR1  = G.CODDOC
                WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF limit 1
               )
        when SEMNIFICATIE = 320 and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF LIMIT 1 ), 0) = 100
          then (SELECT I.PREFIXDOC || (SELECT PKG_TREZOR_PRELSERIADOC.WME_RESULT FROM PKG_TREZOR_PRELSERIADOC(null, I.SERIADOC)) || I.NRDOC::varchar || '(' || to_char( I.DATADOC, 'dd.mm.yyyy') || ')'
                FROM STINGERE S
                    left join OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                    left join general  G ON G.CODGENERAL  = O.CODGENERAL
                    left join INTRARI  I ON I.CODINTR     = G.CODDOC
                WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF LIMIT 1
               )
        when SEMNIFICATIE = 320 and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF limit 1 ), 0) = 130
          then (SELECT I.PREFIXDOC || (SELECT PKG_TREZOR_PRELSERIADOC.WME_RESULT FROM PKG_TREZOR_PRELSERIADOC(null, I.SERIADOC)) || I.NRDOC::varchar || '(' || to_char( I.DATADOC, 'dd.mm.yyyy') || ')'
                FROM STINGERE S
                    left join OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                    left join general  G ON G.CODGENERAL  = O.CODGENERAL
                    left join DVI      D ON D.CODDVI      = G.CODDOC and G.TIPDOC = 5
                    left join INTRARI  I ON I.CODINTR     = D.CODINTR
                WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF limit 1
               )
        when SEMNIFICATIE in (320, 420) and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF LIMIT 1 ), 0) = 1200
          then (SELECT 'NC' || N.NRDOC::varchar || '(' || to_char( N.DATADOC, 'dd.mm.yyyy') || ')'
                FROM STINGERE S
                    left join OBLIGPIF O  ON O.CODOBLIGPIF = S.CODSTINSPIF
                    left join general  G  ON G.CODGENERAL  = O.CODGENERAL
                    left join NC1      N1 ON N1.CODNC1     = G.CODDOC
                    left join NC       N  ON N.CODNC       = N1.CODNC
                WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF LIMIT 1
               )
        when SEMNIFICATIE = 320 and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF LIMIT 1 ), 0) in (1301)
           then (SELECT 'PV' || C.NRDOC::varchar || '(' || to_char( C.DATADOC, 'dd.mm.yyyy') || ')'
                 FROM STINGERE S
                    left join OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                    left join general  G ON G.CODGENERAL  = O.CODGENERAL
                    left join COMPENS  C ON C.CODCOMPENS  = G.CODDOC
                WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF limit 1
               )
        when SEMNIFICATIE = 420 and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF limit 1 ), 0) = 200
          then (SELECT I.PREFIXDOC || (SELECT PKG_TREZOR_PRELSERIADOC.WME_RESULT FROM PKG_TREZOR_PRELSERIADOC(null, I.SERIADOC)) || I.NRDOC::varchar || '(' || to_char( I.DATADOC, 'dd.mm.yyyy') || ')'
                FROM STINGERE S
                    left join OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                    left join general  G ON G.CODGENERAL  = O.CODGENERAL
                    left join IESIRI   I ON I.CODIES      = G.CODDOC
                WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF LIMIT 1
                )
        when SEMNIFICATIE in (320, 420) and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF limit 1 ), 0) = 1201
          then (SELECT 'NC' || N.NRDOC::varchar || '(' || to_char( N.DATADOC, 'dd.mm.yyyy') || ')'
                FROM STINGERE S
                    left join OBLIGPIF O  ON O.CODOBLIGPIF = S.CODSTINSPIF
                    left join general  G  ON G.CODGENERAL  = O.CODGENERAL
                    left join NC1      N1 ON N1.CODNC1     = G.CODDOC
                    left join NC       N  ON N.CODNC       = N1.CODNC
                WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF LIMIT 1
               )
        when SEMNIFICATIE = 420 and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF LIMIT 1 ), 0) = 1351
          then (SELECT 'PV' || C.NRDOC::varchar || '(' || to_char( C.DATADOC, 'dd.mm.yyyy') || ')'
                FROM STINGERE S
                    left join OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                    left join general  G ON G.CODGENERAL  = O.CODGENERAL
                    left join COMPENS  C ON C.CODCOMPENS  = G.CODDOC
                WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF LIMIT 1
               )
        when SEMNIFICATIE in (310, 330) then 'Plata in avans'
        when SEMNIFICATIE in (410, 430) then 'Incasare in avans'
        when SEMNIFICATIE in (800, 801) and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF limit 1 ), 0) in (800, 801)
          then (SELECT T.DOC || (SELECT PKG_TREZOR_PRELSERIADOC.WME_RESULT FROM PKG_TREZOR_PRELSERIADOC(null, T.SERIEDOC)) || T.NRDOC::varchar || '(' || to_char( T.DATADOC, 'dd.mm.yyyy') || ')'
                FROM STINGERE S
                    left join OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                    left join general  G ON G.CODGENERAL  = O.CODGENERAL
                    left join TREZOR1  T ON T.CODTREZOR1  = G.CODDOC
                WHERE S.CODSTINGATORPIF = OB.CODOBLIGPIF limit 1
               )
        when SEMNIFICATIE in (800, 801) and coalesce( ( select OO.SEMNIFICATIE from STINGERE SS left join OBLIGPIF OO on SS.CODSTINSPIF = OO.CODOBLIGPIF where SS.CODSTINGATORPIF = OB.CODOBLIGPIF LIMIT 1 ), 0) = 0
          then 'Viramente interne'
        when SEMNIFICATIE = 900           then 'Pe cheltuieli'
        when SEMNIFICATIE = 901           then 'Pe venituri'
        when SEMNIFICATIE in (950, 951)   then 'Direct pe cont'
        when SEMNIFICATIE = 1000          then 'Dobanda'
        when SEMNIFICATIE in (1100, 1101) then 'Angajat'
        else '???' end ) ;


    FOR V_REC IN (SELECT O.CODOBLIGPIF, O_STINS.TERMEN
                  FROM TMP_OBLIGPIF O, STINGERE S, OBLIGPIF O_STINS
                  WHERE O.CODOBLIGPIF = S.CODSTINGATORPIF AND O_STINS.CODOBLIGPIF = S.CODSTINSPIF
                 )
    LOOP
      UPDATE TMP_OBLIGPIF SET TERMEN = V_REC.TERMEN WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
    END LOOP;

    UPDATE TMP_TREZOR1 T
    set
    DENTRANZ = SUBSTR( (
    case
      when TIPTRANZ = 0 and OBIECTTRANZ = 0 then 'Furnizor :' || chr(13) || (SELECT DEN_PART FROM NPART P WHERE CODPART = T.CODPART )
      when TIPTRANZ = 0 and OBIECTTRANZ = 1 then 'Retur :'    || chr(13) || (SELECT DEN_PART FROM NPART P WHERE CODPART = T.CODPART )
      when TIPTRANZ in (0, 1) and OBIECTTRANZ = 3
        then 'Viramente interne :' || chr(13) || (SELECT B.SIMBOL || ' - ' || NRCONT FROM NBANKCONT BC left join NBANK B ON B.CODBANK = BC.CODBANK WHERE CODBANKCONT = T.CODPART)
      when TIPTRANZ = 1 and OBIECTTRANZ = 0 then 'Client: ' || (CASE when T.AGENT &lt;&gt; 0
        then '(Agent:' || T.NUMEAGENT || ')' else '' end ) || chr(13) || coalesce( ( select DEN_PART from NPART P where CODPART = T.CODPART ), '')
      when TIPTRANZ = 1 and OBIECTTRANZ = 1 then 'Retur :' || chr(13) || coalesce( ( select DEN_PART from NPART P where CODPART = T.CODPART ), '')
      when OBIECTTRANZ = 2                  then 'Personal angajat :' || chr(13) || coalesce( ( select NUME || ' ' || PRENUME from NPERS P where CODPERS = T.CODPART ), '')
      when TIPTRANZ = 0 and OBIECTTRANZ = 4
        then 'Servicii, articole fara NIR...' || (SELECT PKG_TREZOR_GETDENPARTDIECTPECONT.WME_RESULT FROM PKG_TREZOR_GETDENPARTDIECTPECONT(null, coalesce( CODPART, 0))) || chr(13)
                                              || (SELECT PKG_PLANCONTURI_GETDENCONT.WME_RESULT FROM PKG_PLANCONTURI_GETDENCONT(null,
                                                                                                                               (SELECT coalesce( ICONT, -1)
                                                                                                                                FROM TMP_OBLIGPIF O
                                                                                                                                WHERE O.CODTREZOR1 = T.CODTREZOR1 and O.SEMNIFICATIE = 900 LIMIT 1 )))
      when TIPTRANZ = 1 and OBIECTTRANZ = 4
        then 'Direct pe venituri...' || (SELECT PKG_TREZOR_GETDENPARTDIECTPECONT.WME_RESULT FROM PKG_TREZOR_GETDENPARTDIECTPECONT(null, coalesce( CODPART, 0))) || chr(13)
                                     || (SELECT PKG_PLANCONTURI_GETDENCONT.WME_RESULT FROM PKG_PLANCONTURI_GETDENCONT(null,
                                                                                                                      (SELECT coalesce( ICONT, -1)
                                                                                                                       FROM TMP_OBLIGPIF O
                                                                                                                       WHERE O.CODTREZOR1 = T.CODTREZOR1 and O.SEMNIFICATIE = 901 LIMIT 1 )))
      when TIPTRANZ = 0 and OBIECTTRANZ = 5
        then 'Datorii, taxe, impozite ' || chr(13) || (SELECT PKG_PLANCONTURI_GETDENCONT.WME_RESULT
                                                       FROM PKG_PLANCONTURI_GETDENCONT(null, (SELECT coalesce( ICONT, -1) FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 and O.SEMNIFICATIE = 950 limit 1)))
      when TIPTRANZ = 1 and OBIECTTRANZ = 5
        then 'Imprumuturi, subventii ' || chr(13) || (SELECT PKG_PLANCONTURI_GETDENCONT.WME_RESULT
                                                      FROM PKG_PLANCONTURI_GETDENCONT(null, ( SELECT coalesce( ICONT, -1) FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 and O.SEMNIFICATIE = 951 limit 1 )))
      when TIPTRANZ = 1 and OBIECTTRANZ = 6
        then 'Dobanda la depozit:' || chr(13) || (SELECT PKG_PLANCONTURI_GETDENCONT.WME_RESULT
                                                  FROM PKG_PLANCONTURI_GETDENCONT(null, (SELECT PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG.WME_RESULT
                                                                                         FROM PKG_GLOBALS_GET_CONT_CONTABIL_OBLIG(null, 1000,
                                                                                                                                  (SELECT coalesce( ICONT, -1) FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 and O.SEMNIFICATIE = 1000 limit 1 ),
                                                                                                                                  (SELECT PKG_CONTURIBANCI_GET_BANKCONT_COD_CARACT_LUNA.WME_RESULT
                                                                                                                                   FROM PKG_CONTURIBANCI_GET_BANKCONT_COD_CARACT_LUNA(null, CODNBANKCONT,
                                                                                                                                                                                      to_number(current_setting('PKG_GLOBALS.ANLUCRU', true), '999999999999999999'),
                                                                                                                                                                                      to_number(current_setting('PKG_GLOBALS.LUNALUCRU', true), '999999999999999999')))))))
      else '' end ) ,
    1,
    100),
    CODAVANS = coalesce( ( select CODOBLIGPIF from TMP_OBLIGPIF O where O.CODTREZOR1 = T.CODTREZOR1 and SEMNIFICATIE in (310, 410) limit 1 ), 0) ;

    for V_REC in (SELECT * FROM TMP_OBLIGPIF WHERE coalesce( CODTRANSA, 0) &lt;&gt; 0 ) loop
      UPDATE TMP_OBLIGPIF
      set
      CURSTRANSA = (SELECT G.CURS FROM OBLIGPIF O, general G WHERE O.CODOBLIGPIF = V_REC.CODTRANSA and G.CODGENERAL = O.CODGENERAL ),
      INFOTRANSA = (SELECT T1.DOC ||  T1.NRDOC::varchar || '/' || to_char( T1.DATADOC, 'DD.MM.YYYY')
                    FROM OBLIGPIF O, general G, TREZOR1 T1
                    WHERE O.CODOBLIGPIF = V_REC.CODTRANSA and G.CODGENERAL = O.CODGENERAL and G.TIPDOC in (30, 31) and T1.CODTREZOR1 = G.CODDOC )
      where
        CODOBLIGPIF = V_REC.CODOBLIGPIF ;
    end loop;

    for V_REC in (SELECT S.CODSTINGERE, G.TIPDOC, G.CODDOC, G.SEMNIFICATIE, S.CODSTINGATORPIF
                  FROM TMP_STINGERE S, OBLIGPIF O, general G WHERE S.CODSTINSPIF = O.CODOBLIGPIF and G.CODGENERAL = O.CODGENERAL )
    loop
      aCODSUBUNITSTINS := 0;

      if V_REC.SEMNIFICATIE in (100, 110, 130) then
        begin
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM INTRARI WHERE CODINTR = V_REC.CODDOC and TIPDOC = V_REC.TIPDOC;
        exception
          when others then aCODSUBUNITSTINS := 0;
        end;
      else
        if V_REC.SEMNIFICATIE in (200, 210) then
          begin
            SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM IESIRI WHERE CODIES = V_REC.CODDOC and TIPDOC = V_REC.TIPDOC;
          exception
            when others then aCODSUBUNITSTINS := 0;
          end;
        else
          if V_REC.SEMNIFICATIE in (1200, 1201) then
            begin
              SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM NC N, NC1 N1 WHERE N1.CODNC1 = V_REC.CODDOC and N.CODNC = N1.CODNC;
            exception
              when others then aCODSUBUNITSTINS := 0;
            end;
          else
            if V_REC.SEMNIFICATIE in (310, 330, 410, 430) then
              begin
                SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM TREZOR T, TREZOR1 T1 WHERE T1.CODTREZOR1 = V_REC.CODDOC and T.CODTREZOR = T1.CODTREZOR;
              exception
                when others then aCODSUBUNITSTINS := 0;
              end;
            else
              if V_REC.SEMNIFICATIE in (1300, 1301, 1302, 1303, 1350, 1351, 1352) then
                begin
                  SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM COMPENS C WHERE C.CODCOMPENS = V_REC.CODDOC;
                exception
                  when others then aCODSUBUNITSTINS := 0;
                end;
              end if;
            end if;
          end if;
        end if;
      end if;

      UPDATE TMP_STINGERE  SET CODSUBUNITSTINS = aCODSUBUNITSTINS WHERE CODSTINGERE = V_REC.CODSTINGERE ;
       UPDATE TMP_OBLIGPIF SET SUBUNITATEA = aCODSUBUNITSTINS     WHERE CODOBLIGPIF = V_REC.CODSTINGATORPIF;
    end loop;

    UPDATE TMP_OBLIGPIF SET SUBUNITATEA = current_setting('PKG_GLOBALS.SUBUNITATE', True)::NUMERIC WHERE SUBUNITATEA IS NULL;

    DELETE FROM TMP_OBLIGPIF_INITIAL;
    INSERT INTO TMP_OBLIGPIF_INITIAL SELECT * FROM TMP_OBLIGPIF;

    DELETE FROM TMP_STINGERE_INITIAL;
    INSERT INTO TMP_STINGERE_INITIAL (SELECT * FROM TMP_STINGERE );

    INSERT INTO TMP_JURNAL  (SELECT * FROM JURNAL  WHERE TIPDOC = TIPDOCCASABANCA and CODDOC = RECID );
    INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = TIPDOCCASABANCA and CODDOC = RECID );

    DELETE FROM TMP_RULAJ;
  end if;

  DELETE FROM TMP_TREZOR1_INITIAL;

  INSERT INTO TMP_TREZOR1_INITIAL ( CODTREZOR1, CODTREZOR, CURS, TIPTRANZ, OBIECTTRANZ, CODPART, VALDOC )
  SELECT CODTREZOR1, CODTREZOR, CURS, TIPTRANZ, OBIECTTRANZ, CODPART, VALDOC FROM TMP_TREZOR1;

  UPDATE TMP_TREZOR1 T1
  set
    INFOCMD = (SELECT PrefixDoc || NrDoc || '/' || DataDoc FROM COMANDA C WHERE C.CODCOMANDA = T1.CODCOMANDA )
  where
    coalesce( CODCOMANDA, 0) &lt;&gt; 0 ;

  UPDATE TMP_TREZOR1 T1 SET TIPTRANZ = 2 WHERE PLATATVA = 1 ;

  FOR V_REC IN (SELECT T1.CODTREZOR1 FROM TMP_RETUROSTINS R INNER JOIN TMP_TREZOR1 T1 ON T1.CODTREZOR1 = R.CODDOC)
  LOOP
    UPDATE TMP_TREZOR1
    SET
      LINKRETURO = 1
    WHERE
      CODTREZOR1 = V_REC.CODTREZOR1;
  END LOOP;

  PERFORM PKG_CFGTABLES_EXT_GOTORECORD(TIPDOCCASABANCA);
 end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trezor_sp_insertrecord</obj_name>
  <obj_hashval>261c0bda629cfa0028c9f39926877ed4</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trezor_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Florin 11.04.2023 - sinc. Oracle (10.04.2023)
  PERFORM PKG_CFGTABLES_EXT_INSERTRECORD(104);
  INSERT INTO TMP_TREZOR (CODTREZOR) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_trigar_tasktopers</obj_name>
  <obj_hashval>671e6b0932ecddc36fa95269d11d3621</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_trigar_tasktopers(acodpers numeric, acodpart numeric, aproblema character varying, sursamesaj character varying)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  aCodUser numeric;
BEGIN
  --Adina 23.03.2021
  aCodUser := null;
  SELECT LOGONNAME INTO aCodUser FROM NPers WHERE CodPers = aCodPers;
  IF  Coalesce(acodUser, 0) &lt;&gt; 0 THEN
    PERFORM pkg_trigar_TaskToUser(aCodUser, aCodPArt, aPROBLEMA, SursaMesaj);
  END IF;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_tvaserv_sp_deleterecord</obj_name>
  <obj_hashval>5c41124738a935f4944d78f5f30bb6f3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_tvaserv_sp_deleterecord(recid numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  perform pkg_tvaserv_sp_lockrecord(recid);
  DELETE FROM TVASERV WHERE CodTVASERV = RecId;

  perform NotifyModif(2, RecId, 'TVASERV');
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_um_getcoefum</obj_name>
  <obj_hashval>9f705cd1b1de7919f4aa60e1ee1418d7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_um_getcoefum(INOUT wme_result numeric, INOUT acodum1 numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  Rez double precision;
begin
  --Bogdan 07.06.2023 - 58490 : PG - Actualizare stoc - trecere la UM specifice: eroare
  Rez := 1.0;
  BEGIN
    SELECT COALESCE( num.COEF, 0) INTO strict Rez
    FROM NUM
         INNER JOIN num1 ON  num.codum = num1.codum
    WHERE num1.CODUM1 = aCodUM1;
  EXCEPTION WHEN others THEN
    Rez := 1.0;
  END;

  IF  Rez = 0.0 THEN
    Rez := 1.0;
  END IF;

  WME_Result :=  Rez;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_um_test_unicitate_um</obj_name>
  <obj_hashval>8d4d1caab0d63e1da6b3ff184f0251f1</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_um_test_unicitate_um(INOUT wme_result numeric, INOUT denum character varying, INOUT cod numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  Nr numeric;
begin
  SELECT COUNT( *) INTO Nr FROM NUM WHERE Upper( Den_UM) = Upper( DenUM) AND  CodUM &lt;&gt; Cod;
  WME_Result :=  Nr;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_setcodutilaj2c</obj_name>
  <obj_hashval>58a75b992a1f42bf1d4d6e9ac1b34a8b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_setcodutilaj2c(acodutilaj2c numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  perform set_config('PKG_UTILAJE.vCodUtilaj2C',to_char(aCodUtilaj2C,'999999999999999999'),false);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_utilaje_sp_postrecords</obj_name>
  <obj_hashval>0db7c68eb845857885386da5e6fb05c3</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_utilaje_sp_postrecords(INOUT operation numeric, INOUT recid numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  V_REC       RECORD;
  aDoc        varchar;
  aCod        numeric;
  aOldCodIes1 numeric;
  aNewCodIes1 numeric;
  aTip        numeric;
  aCodPart     numeric;
  aOldCodPart numeric;
  aCount    numeric;
  curVal    NUMERIC;
BEGIN
  --Florin 01.06.2023 - monitor
  --Florin 12.04.2023 - sinc. Oracle
  --Florin 16.02.2023 - fixat 57220
  --Florin 13.02.2023 - sinc. Oracle
  --Florin 20.07.2022 - sinc. Oracle
  --FLorin 15.06.2022 - sinc. Oracle
  --Florin 29.12.2021 - sinc. Oracle (27.12.2021)
  --Laura 24.09.2021 - sinc Oracle (24.09.2021)
  --Adina 02.08.2021 - sinc.Oracle - add callcenter
  --Adina 14.07.2021 - sinc.Oracle din 14.07.2021
  --Bogdan 08.10.2020
  --Florin 30.10.2020 fixat #40738
  perform pkg_utilaje_setct_monitor('MON_53');
  aOldCodIes1 := 0;
  aNewCodIes1 := 0;

  SELECT Tip, coalesce(codpart, 0) INTO aTip, aCodPart FROM tmp_utilaje;
  IF NOT aTip IN (1,4) THEN DELETE FROM tmp_utilaje1; END IF;
  PERFORM PKG_CFGTABLES_EXT_POSTRECORDS_INIT (508);

  IF OPERATION = 0 THEN
    SELECT codutilaj INTO RECID FROM TMP_UTILAJE;
     begin
      select coalesce(codpart,0) into aOldCodPart from utilaje where codutilaj = recid;
  exception when others then aOldCodPart := 0;
  end;

    UPDATE tmp_utilaje20 SET codutilaj = recid;

    SELECT COALESCE (codies1, 0) INTO aNewCodIes1 FROM tmp_utilaje;

    SELECT COALESCE (codies1, 0) INTO aOldCodIes1 FROM utilaje WHERE codutilaj = recid;

    IF (SELECT WME_RESULT FROM pkg_userfirme_validpostlog (NULL,current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting ('PKG_UTILAJE.CT_MONITOR', true))) THEN
      SELECT 'Utilaj "'|| coalesce (nrinventar::varchar ,'')|| '"' INTO aDoc FROM UTILAJE WHERE codutilaj = recid;
      PERFORM pkg_userfirme_postlogcucommit ('UTILAJE', current_setting ('PKG_GLOBALS.USERNAME', true) , 'M', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
    END IF;

    UPDATE UTILAJE U
    SET
      (
        CODOBIECT,
        NRINVENTAR,
        ETICHETA,
        TIPUTILAJ,
        FLOTA,
        MODEL,
        ANF,
        SERIEF,
        INCARCARE,
        DATAGARANTIE,
        DATAGARANTIEI,
        INGARANTIE,
        LUNGIME,
        LATIME,
        INALTIME,
        OBS,
        INACTIV,
        CORECTIEINDEX,
        UM,
        CodGest,
        PLAFONCANTF,
        CODPART,
        CODIES1,
        APROBAT,
        DATASTART,
        NRCONTR,
        DATACONTR,
        CODFURNIZOR,
        DOC,
        TIP,
        CODLOCALIT,
        ADRESA,
        HFACTOR,
        AGENT,
        CODPRODUCATOR,
        CODLOCATIE
      )
      =
      (SELECT CODOBIECT,
          NRINVENTAR,
          ETICHETA,
          TIPUTILAJ,
          FLOTA,
          MODEL,
          ANF,
          SERIEF,
          INCARCARE,
          DATAGARANTIE,
          DATAGARANTIEI,
          INGARANTIE,
          LUNGIME,
          LATIME,
          INALTIME,
          OBS,
          INACTIV,
          CORECTIEINDEX,
          UM,
          CodGest,
          PLAFONCANTF,
          CODPART,
          CODIES1,
          APROBAT,
          DATASTART,
          NRCONTR,
          DATACONTR,
          CODFURNIZOR,
          DOC,
          TIP,
          CODLOCALIT,
          ADRESA,
          HFACTOR,
          AGENT,
          CODPRODUCATOR, CODLOCATIE
        FROM TMP_UTILAJE)
    WHERE
      U.CODUTILAJ = RECID;

    DELETE FROM UTILAJE1 U1 WHERE U1.CODUTILAJ = RecID AND NOT EXISTS (SELECT TMP.CODUTILAJ1 FROM TMP_UTILAJE1 TMP WHERE TMP.CODUTILAJ1 = U1.CODUTILAJ1);

    FOR V_REC IN (SELECT * FROM TMP_UTILAJE1 WHERE codutilaj1 &gt; 0) LOOP
      UPDATE UTILAJE1 U1
      SET
        NRCONTR        = V_REC.NRCONTR,
        CARNETCONTR    = V_REC.CARNETCONTR,
        STATUS_PART    = V_REC.STATUS_PART,
        STATUS_DEPO    = V_REC.STATUS_DEPO,
        CODPART        = V_REC.CODPART,
        CODLOCATIE     = V_REC.CODLOCATIE,
        DATA           = V_REC.DATA,
        OBS            = V_REC.OBS,
        STATUS_SERVICE = V_REC.STATUS_SERVICE,
        INDEXLOCAL     = V_REC.INDEXLOCAL,
        CODPERS        = V_REC.CODPERS,
        ESTETIC        = V_REC.ESTETIC
      WHERE
        U1.CODUTILAJ1 = V_REC.CODUTILAJ1;
    END LOOP;

    INSERT INTO UTILAJE1 (CODUTILAJ1,
        CODUTILAJ,
        NRCONTR,
        CARNETCONTR,
        STATUS_PART,
        STATUS_DEPO,
        CODPART,
        CODLOCATIE,
        DATA,
        OBS,
        STATUS_SERVICE,
        USERID,
        DATACREARE,
        INDEXLOCAL,
        CODPERS,
        ESTETIC)
    SELECT NEXTVAL ('SEQ_UTILAJE1_CODUTILAJ1') ,
      RECID,
      NRCONTR,
      CARNETCONTR,
      STATUS_PART,
      STATUS_DEPO,
      CODPART,
      CODLOCATIE,
      DATA,
      OBS,
      STATUS_SERVICE,
      current_setting ('PKG_GLOBALS.USERID', true) ::numeric,
      CURRENT_TIMESTAMP,
      INDEXLOCAL,
      CODPERS,
      ESTETIC
    FROM TMP_UTILAJE1
    WHERE
      CODUTILAJ1 &lt; 0;

    FOR V_REC IN (SELECT CODUTILAJ20, STARE
                  FROM UTILAJE20 U20
                  WHERE U20.CODUTILAJ = RecID AND NOT EXISTS (SELECT TMP.CODUTILAJ20 FROM TMP_UTILAJE20 TMP WHERE TMP.CODUTILAJ20 = U20.CODUTILAJ20)
                 )
    LOOP
      DELETE FROM UTILAJE20 WHERE CODUTILAJ20 = V_REC.CODUTILAJ20;

      INSERT INTO UTILAJEMON (CODMONITORIZARE, CODUTILAJ20, USERID, DATAMODIF, STAREV, TIPMODIF)
      VALUES (NEXTVAL ('SEQ_UTILAJEMON_CODMONITORIZARE') , V_REC.CODUTILAJ20, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, CURRENT_TIMESTAMP, V_REC.STARE, 'STERGERE');
    END LOOP;

    DELETE FROM UTILAJEDEV DEV
    WHERE DEV.CODUTILAJ = RecID AND NOT EXISTS (SELECT TMP.CODUTILAJDEV FROM TMP_UTILAJEDEV TMP WHERE TMP.CODUTILAJDEV = DEV.CODUTILAJDEV);

    DELETE FROM UTILAJE2C U2C
    WHERE U2C.CODUTILAJ = RecID AND NOT EXISTS (SELECT TMP.CODUTILAJ2C FROM TMP_UTILAJE2C TMP WHERE TMP.CODUTILAJ2C = U2C.CODUTILAJ2C);

    DELETE FROM UTILAJE2P U2P
    WHERE U2P.CODUTILAJ = RecID AND NOT EXISTS (SELECT TMP.CODUTILAJ2P FROM TMP_UTILAJE2P TMP WHERE TMP.CODUTILAJ2P = U2P.CODUTILAJ2P);

    DELETE FROM UTILAJE2 U2
    WHERE U2.CODUTILAJ = RecID AND NOT EXISTS (SELECT TMP.CODUTILAJ2 FROM TMP_UTILAJE2 TMP WHERE TMP.CODUTILAJ2 = U2.CODUTILAJ2);

    FOR V_REC IN (SELECT TMP.*, U20.STARE STAREVECHE FROM TMP_UTILAJE20 TMP LEFT JOIN UTILAJE20 U20 ON U20.CODUTILAJ20 = TMP.CODUTILAJ20) LOOP
      IF v_rec.codutilaj20 &gt; 0 THEN
        UPDATE UTILAJE20
        SET
          NRDOC      = V_REC.NRDOC,
          DATADOC    = V_REC.DATADOC,
          DESCRIERE  = V_REC.DESCRIERE,
          STARE      = V_REC.STARE,
          OPERATOR   = V_REC.OPERATOR,
          OBS        = V_REC.OBS,
          CODIES     = V_REC.CODIES,
          CODLOCALIT = V_REC.CODLOCALIT,
          ADRESA     = V_REC.ADRESA,
          CODPERSC   = V_REC.CODPERSC,
          CALLCENTER = V_REC.CALLCENTER,
          CODBC      = V_REC.CODBC,
          PRIORITATE = V_REC.PRIORITATE
        WHERE
          codutilaj20 = v_rec.codutilaj20;

        IF V_REC.STAREVECHE &lt;&gt; V_REC.STARE THEN
          INSERT INTO UTILAJEMON (CODMONITORIZARE, CODUTILAJ20, USERID, DATAMODIF, STAREV, STAREN, TIPMODIF)
          VALUES (NEXTVAL ('SEQ_UTILAJEMON_CODMONITORIZARE'), V_REC.CODUTILAJ20, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, CURRENT_TIMESTAMP,
                  V_REC.STAREVECHE, V_REC.STARE, 'MODIFICARE');
        END IF;
      ELSE
        SELECT NEXTVAL ('SEQ_UTILAJE20_CODUTILAJ20') INTO aCod;

        UPDATE tmp_utilaje2   SET codutilaj20 = aCod WHERE codutilaj20 = v_rec.codutilaj20;
        UPDATE tmp_utilajedev SET codutilaj20 = aCod WHERE codutilaj20 = v_rec.codutilaj20;
        UPDATE tmp_utilaje20  SET codutilaj20 = aCod WHERE codutilaj20 = v_rec.codutilaj20;

        INSERT INTO UTILAJE20 (CODUTILAJ20,
            CODUTILAJ,
            NRDOC,
            DATADOC,
            DESCRIERE,
            STARE,
            OPERATOR,
            OBS,
            CODIES,
            CODLOCALIT,
            ADRESA,
            CODPERSC,
            CALLCENTER,
            CODBC,
            PRIORITATE)
          VALUES (aCod,
            RecId,
            V_REC.NRDOC,
            V_REC.DATADOC,
            V_REC.DESCRIERE,
            V_REC.STARE,
            V_REC.OPERATOR,
            V_REC.OBS,
            V_REC.CODIES,
            V_REC.CODLOCALIT,
            V_REC.ADRESA,
            V_REC.CODPERSC,
            V_REC.CALLCENTER,
            V_REC.CODBC,
            V_REC.PRIORITATE);

        INSERT INTO UTILAJEMON (CODMONITORIZARE, CODUTILAJ20, USERID, DATAMODIF, STAREN, TIPMODIF)
        VALUES (NEXTVAL ('SEQ_UTILAJEMON_CODMONITORIZARE'), aCod, current_setting ('PKG_GLOBALS.USERID', true) ::numeric, CURRENT_TIMESTAMP, V_REC.STARE, 'ADAUGARE');
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_UTILAJEDEV) LOOP
      IF V_REC.CODUTILAJDEV &gt; 0 THEN
        UPDATE UTILAJEDEV
        SET
          CODUTILAJ20 = V_REC.CODUTILAJ20,
          CODOBIECT   = V_REC.CODOBIECT,
          CANT        = V_REC.CANT,
          PRET        = V_REC.PRET,
          CANTFACT    = V_REC.CANTFACT,
          FACTURABIL  = V_REC.FACTURABIL,
          CODIES1     = V_REC.CODIES1,
          CODUTILAJ2  = V_REC.CODUTILAJ2,
          TIPLIVRARE  = V_REC.TIPLIVRARE,
          TVA         = V_REC.TVA,
          CONSUMABIL  = V_REC.CONSUMABIL,
          CANTCONS    = V_REC.CANTCONS
        WHERE
          CODUTILAJDEV = V_REC.CODUTILAJDEV;
      ELSE
        INSERT INTO UTILAJEDEV (CODUTILAJDEV,
            CODUTILAJ,
            CODUTILAJ20,
            CODOBIECT,
            CANT,
            PRET,
            CANTFACT,
            FACTURABIL,
            CODIES1,
            CODUTILAJ2,
            TIPLIVRARE,
            TVA,
            CONSUMABIL,
            CANTCONS)
          VALUES (NEXTVAL ('SEQ_UTILAJEDEV_CODUTILAJDEV') ,
            RECID,
            V_REC.CODUTILAJ20,
            V_REC.CODOBIECT,
            V_REC.CANT,
            V_REC.PRET,
            V_REC.CANTFACT,
            V_REC.FACTURABIL,
            V_REC.CODIES1,
            V_REC.CODUTILAJ2,
            V_REC.TIPLIVRARE,
            V_REC.TVA,
            V_REC.CONSUMABIL,
            V_REC.CANTCONS);
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_UTILAJE2) LOOP
      IF v_rec.codutilaj2 &gt; 0 THEN
        UPDATE UTILAJE2
        SET
          INTERVENTIE = v_rec.INTERVENTIE,
          CODCOMANDA1 = V_REC.CODCOMANDA1,
          CODUTILAJ20 = V_REC.CODUTILAJ20,
          CODAUTO     = V_REC.CODAUTO,
          KMPARCURSI = V_REC.KMPARCURSI
        WHERE
          codutilaj2 = v_rec.codutilaj2;
      ELSE
        SELECT NEXTVAL ('SEQ_UTILAJE2_CODUTILAJ2') INTO aCod;

        UPDATE tmp_utilaje2c SET codutilaj2 = aCod WHERE codutilaj2 = v_rec.codutilaj2;
        UPDATE tmp_utilaje2p SET codutilaj2 = aCod WHERE codutilaj2 = v_rec.codutilaj2;

        INSERT INTO UTILAJE2 (CODUTILAJ2, CODUTILAJ, INTERVENTIE, CODCOMANDA1, CODUTILAJ20, CODAUTO, KMPARCURSI)
        VALUES (aCod, RecId, v_rec.INTERVENTIE, V_REC.CODCOMANDA1, V_REC.CODUTILAJ20, V_REC.CODAUTO, v_rec.KMPARCURSI);
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_UTILAJE2C) LOOP
      IF v_rec.codutilaj2C &gt; 0 THEN
        UPDATE UTILAJE2C
        SET
          INDEXC      = V_rEC.Indexc,
          DATAINDEXC  = V_REC.DATAINDEXC,
          CODCOMANDA1 = V_REC.CODCOMANDA1,
          Explicatii  = V_REC.Explicatii,
          DATASTART   = V_REC.DATASTART,
          DATAEND     = V_REC.DATAEND,
          INDEXV      = V_rEC.IndexV,
          DATAV       = V_REC.DATAV,
          RESETAT     = V_REC.RESETAT,
          INDEXLOCAL  = V_REC.INDEXLOCAL,
          ORESTART    = V_REC.ORESTART,
          ORESTOP     = V_REC.ORESTOP
        WHERE
          codutilaj2C = v_rec.codutilaj2C;
      ELSE
        INSERT INTO UTILAJE2C (CODUTILAJ2C,
            CODUTILAJ2,
            CODUTILAJ,
            INDEXC,
            DATAINDEXC,
            CODCOMANDA1,
            Explicatii,
            DataStart,
            DataEnd,
            indexv,
            datav,
            resetat,
            indexlocal, ORESTART, ORESTOP)
          VALUES (NEXTVAL ('SEQ_UTILAJE2C_CODUTILAJ2C') ,
            V_REC.CODUTILAJ2,
            RECID,
            V_rEC.INDEXC,
            V_REC.DATAINDEXC,
            V_REC.CODCOMANDA1,
            V_REC.Explicatii,
            v_rec.datastart,
            v_rec.dataend,
            v_rec.indexv,
            v_rec.datav,
            v_rec.resetat,
            v_rec.indexlocal,
            V_REC.ORESTART,
            V_REC.ORESTOP);
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_UTILAJE2P) LOOP
      IF v_rec.codutilaj2P &gt; 0 THEN
        UPDATE UTILAJE2P SET CODPERS = V_REC.CODPERS WHERE codutilaj2P = v_rec.codutilaj2P;
      ELSE
        INSERT INTO UTILAJE2P (CODUTILAJ2P, CODUTILAJ2, CODUTILAJ, CODPERS)
        VALUES (NEXTVAL ('SEQ_UTILAJE2P_CODUTILAJ2P'), V_REC.CODUTILAJ2, RECID, V_REC.CODPERS);
      END IF;
    END LOOP;

    DELETE FROM UTILAJE3 U3 WHERE U3.CODUTILAJ = RecID AND NOT EXISTS (SELECT TMP.CODUTILAJ3 FROM TMP_UTILAJE3 TMP WHERE TMP.CODUTILAJ3 = U3.CODUTILAJ3);

    FOR V_REC IN (SELECT * FROM TMP_UTILAJE3) LOOP
      IF v_rec.codutilaj3 &gt; 0 THEN
        UPDATE UTILAJE3
        SET
          DATABORD      = v_rec.databord,
          INDEXBORD     = v_rec.indexbord,
          AN            = v_Rec.An,
          LUNA          = v_rec.luna,
          CORECTIEINDEX = v_rec.CORECTIEINDEX,
          TIP_INDEX          =  v_rec.TIP_INDEX
        WHERE
          codutilaj3 = v_rec.codutilaj3;
      ELSE
        INSERT INTO UTILAJE3 (CODUTILAJ3, CODUTILAJ, DATABORD, INDEXBORD, AN, LUNA, CORECTIEINDEX, TIP_INDEX)
        VALUES (NEXTVAL ('SEQ_UTILAJE3_CODUTILAJ3'), RecId, v_rec.DATABORD, v_rec.INDEXBORD, v_rec.AN, v_rec.LUNA, V_REC.CORECTIEINDEX, V_REC.TIP_INDEX);
      END IF;
    END LOOP;

    DELETE FROM UTILAJETIPINDEX UTI WHERE UTI.CODUTILAJ = RecID
    AND NOT EXISTS (SELECT TMP.CODTINDEX FROM TMP_UTILAJETIPINDEX TMP WHERE TMP.CODTINDEX = UTI.CODTINDEX);

    FOR V_REC IN (SELECT * FROM TMP_UTILAJETIPINDEX) LOOP
      if v_rec.CODTINDEX &gt; 0 THEN
        UPDATE UTILAJETIPINDEX SET
          DENUMIRE          =  v_rec.DENUMIRE,
          UM                =  v_rec.UM,
          PLAFONCANTF       =  v_rec.PLAFONCANTF
        where CODTINDEX = v_rec.CODTINDEX;
      ELSE
        INSERT INTO UTILAJETIPINDEX(CODTINDEX, codutilaj, tip_index, denumire, um, plafoncantf)
        values (NEXTVAL('SEQ_UTILAJETIPINDEX_CODTINDEX'),RecId,v_rec.TIP_INDEX,v_rec.DENUMIRE, v_rec.UM, v_rec.PLAFONCANTF);
      END IF;
   END LOOP;

  ELSE    -- insert
    aOldCodPart := 0;
    SELECT COALESCE (codies1, 0) INTO aOldCodIes1 FROM tmp_utilaje;

    SELECT NEXTVAL ('SEQ_UTILAJE_CODUTILAJ') INTO RECID;
    PERFORM PKG_CFGTABLES_EXT_UPDATE_COD_CORESP('UTILAJE', RecId);

    UPDATE tmp_utilaje20 SET codutilaj = recid;

    INSERT INTO UTILAJE (CODUTILAJ,
        CODOBIECT,
        NRINVENTAR,
        ETICHETA,
        TIPUTILAJ,
        FLOTA,
        MODEL,
        ANF,
        SERIEF,
        INCARCARE,
        DATAGARANTIE,
        DATAGARANTIEI,
        INGARANTIE,
        LUNGIME,
        LATIME,
        INALTIME,
        OBS,
        INACTIV,
        CORECTIEINDEX,
        UM,
        CodGest,
        PLAFONCANTF,
        CODPART,
        CODIES1,
        APROBAT,
        DATASTART,
        NRCONTR,
        DATACONTR,
        CODFURNIZOR,
        DOC,
        TIP,
        CODLOCALIT,
        ADRESA,
        HFACTOR,
        AGENT,
        CODPRODUCATOR, CODLOCATIE)
    SELECT RecId,
      CODOBIECT,
      NRINVENTAR,
      ETICHETA,
      TIPUTILAJ,
      FLOTA,
      MODEL,
      ANF,
      SERIEF,
      INCARCARE,
      DATAGARANTIE,
      DATAGARANTIEI,
      INGARANTIE,
      LUNGIME,
      LATIME,
      INALTIME,
      OBS,
      INACTIV,
      CORECTIEINDEX,
      UM,
      CodGest,
      PLAFONCANTF,
      CODPART,
      CODIES1,
      APROBAT,
      DATASTART,
      NRCONTR,
      DATACONTR,
      CODFURNIZOR,
      DOC,
      TIP,
      CODLOCALIT,
      ADRESA,
      HFACTOR,
      AGENT,
      CODPRODUCATOR, CODLOCATIE
    FROM TMP_UTILAJE;

    IF (SELECT WME_RESULT FROM winmadmin.pkg_userfirme_validpostlog (NULL,current_setting ('PKG_GLOBALS.USERID', true) ::numeric, current_setting ('PKG_UTILAJE.CT_MONITOR', true))) THEN
      SELECT 'Utilaj "'|| coalesce (nrinventar::varchar ,'')|| '"' INTO aDoc FROM UTILAJE WHERE codutilaj = recid;
      PERFORM winmadmin.pkg_userfirme_postlogcucommit ('UTILAJE', current_setting ('PKG_GLOBALS.USERNAME', true) , 'A', RECID, current_setting ('PKG_GLOBALS.FIRMANAME', true) , current_setting ('PKG_GLOBALS.SUBUNITATE', true) ::numeric, null, aDoc, current_setting ('PKG_GLOBALS.EXE_VERSION', true));
    END IF;

    INSERT INTO UTILAJE1 (CODUTILAJ1,
        CODUTILAJ,
        NRCONTR,
        CARNETCONTR,
        STATUS_PART,
        STATUS_DEPO,
        CODPART,
        CODLOCATIE,
        DATA,
        OBS,
        STATUS_SERVICE,
        USERID,
        DATACREARE,
        INDEXLOCAL,
        CODPERS,
        ESTETIC)
    SELECT NEXTVAL ('SEQ_UTILAJE1_CODUTILAJ1') ,
      CURRVAL('SEQ_UTILAJE_CODUTILAJ'),
      NRCONTR,
      CARNETCONTR,
      STATUS_PART,
      STATUS_DEPO,
      CODPART,
      CODLOCATIE,
      DATA,
      OBS,
      STATUS_SERVICE,
      current_setting ('PKG_GLOBALS.USERID', true) ::numeric,
      CURRENT_TIMESTAMP,
      INDEXLOCAL,
      CODPERS,
      ESTETIC
    FROM TMP_UTILAJE1;

    FOR V_REC IN (SELECT * FROM TMP_UTILAJE20) LOOP
      SELECT NEXTVAL ('SEQ_UTILAJE20_CODUTILAJ20') INTO aCod;

      UPDATE tmp_utilaje2   SET codutilaj20 = aCod WHERE codutilaj20 = v_rec.codutilaj20;
      UPDATE tmp_utilajedev SET codutilaj20 = aCod WHERE codutilaj20 = v_rec.codutilaj20;
      UPDATE tmp_utilaje20  SET codutilaj20 = aCod WHERE codutilaj20 = v_rec.codutilaj20;

      INSERT INTO UTILAJE20 (CODUTILAJ20,
          CODUTILAJ,
          NRDOC,
          DATADOC,
          DESCRIERE,
          STARE,
          OPERATOR,
          OBS,
          CODIES,
          CODLOCALIT,
          ADRESA,
          CODPERSC,
          CODBC,
          PRIORITATE)
        VALUES (aCod,
          RecId,
          V_REC.NRDOC,
          V_REC.DATADOC,
          V_REC.DESCRIERE,
          V_REC.STARE,
          V_REC.OPERATOR,
          V_REC.OBS,
          V_REC.CODIES,
          V_REC.CODLOCALIT,
          V_REC.ADRESA,
          V_REC.CODPERSC,
          V_REC.CODBC,
          v_REC.PRIORITATE);

      INSERT INTO UTILAJEMON (CODMONITORIZARE,
          CODUTILAJ20,
          USERID,
          DATAMODIF,
          STAREN,
          TIPMODIF)
        VALUES (NEXTVAL ('SEQ_UTILAJEMON_CODMONITORIZARE') ,
          aCod,
          current_setting ('PKG_GLOBALS.USERID', true) ::numeric,
          CURRENT_TIMESTAMP,
          V_REC.STARE,
          'ADAUGARE');
    END LOOP;

    INSERT INTO UTILAJEDEV (CODUTILAJDEV,
        CODUTILAJ,
        CODUTILAJ20,
        CODOBIECT,
        CANT,
        PRET,
        CANTFACT,
        FACTURABIL,
        CODIES1,
        CODUTILAJ2,
        TIPLIVRARE,
        TVA,
        CONSUMABIL,
        CANTCONS)
    SELECT NEXTVAL ('SEQ_UTILAJEDEV_CODUTILAJDEV') ,
      RECID,
      D.CODUTILAJ20,
      D.CODOBIECT,
      D.CANT,
      D.PRET,
      D.CANTFACT,
      D.FACTURABIL,
      D.CODIES1,
      D.CODUTILAJ2,
      D.TIPLIVRARE,
      D.TVA,
      D.CONSUMABIL,
      D.CANTCONS
    FROM TMP_UTILAJEDEV D;

    FOR v_rec IN (SELECT * FROM tmp_utilaje2) LOOP
      SELECT NEXTVAL ('SEQ_UTILAJE2_CODUTILAJ2') INTO aCod;

      UPDATE tmp_utilaje2c SET codutilaj2 = aCod WHERE codutilaj2 = v_rec.codutilaj2;
      UPDATE tmp_utilaje2P SET codutilaj2 = aCod WHERE codutilaj2 = v_rec.codutilaj2;

      INSERT INTO UTILAJE2 (CODUTILAJ2,
          CODUTILAJ,
          INTERVENTIE,
          CODCOMANDA1,
          CODUTILAJ20,
          CODAUTO,
          KMPARCURSI)
        VALUES (aCod,
          CURRVAL('SEQ_UTILAJE_CODUTILAJ'),
          v_rec.INTERVENTIE,
          v_rec.CODCOMANDA1,
          V_REC.CODUTILAJ20,
          V_REC.CODAUTO,
          V_REC.KMPARCURSI);
    END LOOP;

    INSERT INTO UTILAJE2C (CODUTILAJ2C,
        CODUTILAJ2,
        CODUTILAJ,
        INDEXC,
        DATAINDEXC,
        CODCOMANDA1,
        EXPLICATII,
        DATASTART,
        DATAEND,
        INDEXV,
        DATAV,
        RESETAT,
        INDEXLOCAL)
    SELECT NEXTVAL ('SEQ_UTILAJE2C_CODUTILAJ2C') ,
      CODUTILAJ2,
      RECID,
      INDEXC,
      DATAINDEXC,
      CODCOMANDA1,
      EXPLICATII,
      DATASTART,
      DATAEND,
      INDEXV,
      DATAV,
      RESETAT,
      INDEXLOCAL
    FROM TMP_UTILAJE2C;

    INSERT INTO UTILAJE2P (CODUTILAJ2P, CODUTILAJ2, CODUTILAJ, CODPERS)
    SELECT NEXTVAL ('SEQ_UTILAJE2P_CODUTILAJ2P') , CODUTILAJ2, RECID, CODPERS FROM TMP_UTILAJE2P;
    curVal :=  CURRVAL('SEQ_UTILAJE_CODUTILAJ');
    INSERT INTO UTILAJE3 (CODUTILAJ3,
        CODUTILAJ,
        DATABORD,
        INDEXBORD,
        AN,
        LUNA,
        CORECTIEINDEX,
        TIP_INDEX)
    SELECT NEXTVAL ('SEQ_UTILAJE3_CODUTILAJ3') ,
      curVal,
      DATABORD,
      INDEXBORD,
      AN,
      LUNA,
      CORECTIEINDEX,
      TIP_INDEX
    FROM TMP_UTILAJE3;
  END IF;

    INSERT INTO UTILAJETIPINDEX(CODTINDEX, codutilaj, tip_index, denumire, um, plafoncantf)
    SELECT NEXTVAL('SEQ_UTILAJETIPINDEX_CODTINDEX'), curVal,TIP_INDEX,DENUMIRE, UM, PLAFONCANTF
    FROM TMP_UTILAJETIPINDEX;

  IF aOldCodIes1 &lt;&gt; aNewCodIes1 THEN
    IF aOldCodIes1 &gt; 0 THEN
      UPDATE iesiri1 SET codutilaj = NULL WHERE codies1 = aOldCodIes1;
    END IF;

    IF aNewCodIes1 &gt; 0 THEN
      UPDATE iesiri1 SET codutilaj = recid WHERE codies1 = aNewCodIes1;
    END IF;
  END IF;

  INSERT INTO UTILAJE20_MON (CODUTILAJ20,
      CODUTILAJ,
      NRDOC,
      DATADOC,
      DESCRIERE,
      STARE,
      OPERATOR,
      OBS,
      CODIES,
      CODLOCALIT,
      ADRESA,
      DENOPERATOR,
      FACTURARE,
      DEVIZ,
      DATAMODIF)
  SELECT CODUTILAJ20,
    RECID,
    NRDOC,
    DATADOC,
    DESCRIERE,
    STARE,
    current_setting ('PKG_GLOBALS.USERID', true) ::numeric,
    OBS,
    CODIES,
    CODLOCALIT,
    ADRESA,
    current_setting ('PKG_GLOBALS.USERNAME', true) ,
    FACTURARE,
    DEVIZ,
    CURRENT_TIMESTAMP
  FROM TMP_UTILAJE20;

  if aOldCodPart &lt;&gt; aCodPart then
    update utilaje1 set status_part = 3 where codutilaj = recid and codpart = aOldCodPart;
    if aCodPart &gt; 0 then
      aCount := 0;
      select count(*) into aCount from utilaje1 where codutilaj = recid;
      aCount := aCount + 1;
      insert into UTILAJE1(CODUTILAJ1,
                           CODUTILAJ,
                           STATUS_PART,
                           STATUS_DEPO,
                           CODPART,
                           DATA,
                           USERID,
                           DATACREARE,
                           STATUS_SERVICE,
                           INDEXLOCAL,
                           ESTETIC,
                           CODLOCATIE)
      select NEXTVAL ('SEQ_UTILAJE1_CODUTILAJ1'),
             codutilaj,
             2,
             1,
             aCodPart,
             trunc(current_timestamp::date),
             current_setting ('PKG_GLOBALS.USERID', true) ::numeric,
             CURRENT_TIMESTAMP,
             1,
             aCount,
             1,
             (SELECT AG.CODAGENDA FROM NAGENDA AG WHERE CODPART = ACODPART AND SEDIUSOCIAL BETWEEN 4 AND 7)
      from utilaje where codutilaj = recid;
    end if;
  end if;

  PERFORM PKG_CFGTABLES_EXT_POSTRECORDS(508);
  PERFORM NotifyModif (Operation, RecId, 'UTILAJE');
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_venitavans_ini_sp_insertrecord</obj_name>
  <obj_hashval>8830eac0b1df9eb07ed5428e49bbf726</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_venitavans_ini_sp_insertrecord()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  DELETE FROM TMP_MIFIX_INITIAL;
  DELETE FROM TMP_MASTERCHELTAVANS;
  INSERT INTO TMP_MASTERCHELTAVANS (CODIES1) VALUES(0);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_weekcashflow_ct_monitor</obj_name>
  <obj_hashval>995986b7754e98778a7c41daf336988c</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_weekcashflow_ct_monitor(INOUT wme_result character varying, INOUT fakeparam numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
begin
BEGIN
  WME_Result := (current_setting('PKG_WEEKCASHFLOW.CT_MONITOR', true));
  RETURN ;
  EXCEPTION WHEN undefined_object THEN
WME_Result := 'MON_65';
RETURN ;
END;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_infopers_by_logonname</obj_name>
  <obj_hashval>be28de9565c02b45b5dfcfd0a285e946</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_infopers_by_logonname(INOUT wme_result refcursor, INOUT ausername character varying)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
  DECLARE
    TMPCURSOR REFCURSOR;
  BEGIN
    --Florin 19.09.2024 - sinc. Oracle
    BEGIN
      OPEN TMPCURSOR FOR
      SELECT P.CODPERS, NUME, PRENUME, COALESCE (P.CODSUBUNIT, 0) AS CODSUBUNIT,
        S.DEN_SUBUNIT
      FROM NPERS             P
        LEFT JOIN NSUBUNIT S ON COALESCE (P.CODSUBUNIT, 0) = S.CODSUBUNIT
      WHERE
        upper (LOGONNAME) = upper (aUserName);

    EXCEPTION
    WHEN OTHERS THEN
      OPEN TMPCURSOR FOR
      SELECT -1 AS CODPERS;

    END;
    WME_Result := TMPCURSOR;
    RETURN;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_get_infopers_by_logonname_4php</obj_name>
  <obj_hashval>47985c3fcd480e3df19d1143e0f25f4a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_get_infopers_by_logonname_4php(refcursor, character varying)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
  DECLARE
    TMPCURSOR REFCURSOR;
  begin
    BEGIN
      OPEN $1 FOR
      SELECT CODPERS, NUME, PRENUME, COALESCE (P.CODSUBUNIT, 0) AS CODSUBUNIT,
        S.DEN_SUBUNIT
      FROM NPERS             P
        LEFT JOIN NSUBUNIT S ON COALESCE (P.CODSUBUNIT, 0) = S.CODSUBUNIT
      WHERE
        LOGONNAME = $2::numeric;

    EXCEPTION
    WHEN OTHERS THEN
      OPEN $1 FOR
      SELECT -1 AS CODPERS;

    END;
    return next $1;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_getstocuri_4php</obj_name>
  <obj_hashval>9baf19b2c6835bd2f31741ef5c2d35a2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_getstocuri_4php(refcursor, numeric, character varying, character varying, numeric, character varying, character varying)
 RETURNS SETOF refcursor
 LANGUAGE plpgsql
AS $function$
  DECLARE
    STOCCURSOR REFCURSOR;
    FILTRU_ART   varchar := '';
      FILTRU_CLASA varchar := '';
    FILTRU_GEST  varchar := '';
     FILTRU_CODEXTERN   varchar := '';
      FILTRU_CODINTERN   varchar := '';
      S           varchar;
      AN           numeric(5);
      LUNA         numeric(2);
      aCODCATPRET  numeric := 0;
  begin
    AN   := EXTRACT(YEAR FROM current_date);
    LUNA := EXTRACT(MONTH FROM current_date);
    perform pkg_globals_setlunalucru_simpla(AN, Luna);
/*    perform pkg_stoc_generare_facturi_make_config_luna_ext(); */
     perform pkg_stoc_generare_facturi_make_config_luna();
    BEGIN
      SELECT coalesce(CODCATEGPRET, 0) into strict aCODCATPRET FROM NPART WHERE CODPART = $2;
      EXCEPTION WHEN OTHERS THEN aCODCATPRET := 0;
    END;

    S := ' SELECT * FROM ' ||
         ' ( ' ||
         '    SELECT ' ||
         '      1 AS TIPARTICOL, ' ||
         '      O.DENUMIRE AS DENOBIECT, ' ||
         '      O.CODEXTERN, ' ||
         '      O.CODINTERN,' ||
       '      O.CODARTICOL,' ||
       '      O.INACTIV, ' ||
         '      A.DEN_ARTICOL AS DEN_ART,' ||
         '      A.UM1 AS DUM1,' ||
         '      A.COMENZIONLINE,' ||
         '      U0.DEN_UM1 AS DENUM1,' ||
         '      NULL as DEN_GEST, ' ||
         '      O.CODOBIECT, ' ||
         '      0 as CODGEST, ' ||
         '      CASE ' ||
         '        WHEN CAT.TIP = 1 THEN ROUND(coalesce(PM.LEI, 0) / (1 + coalesce(TVAL.PROCENT, 0) / 100), 2) ' ||
         '        ELSE coalesce(PM.LEI, 0) ' ||
         '      END  AS PRET, ' ||
         '      0 AS STOC, ' ||
         '      P.DEN_PART AS PRODUCATOR, ' ||
         '      CLAS.DEN_CLASEA AS CLASA, ' ||
         '      U.DEN_UM, ' ||
         '      U1.CODUM1 ' ||
         '    FROM  ' ||
         '      NART A   ' ||
       '      LEFT OUTER JOIN NUM1 U0 ON U0.CODUM1 = A.UM1 ' ||
         '      LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = A.CODARTICOL  ' ||
         '      LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA = NAL.CODTVA ' ||
         '      LEFT OUTER JOIN NUM U ON U.CODUM = A.UM ' ||
         '      LEFT OUTER JOIN NUM1 U1 ON U1.CODUM = U.CODUM AND U1.SECUNDARA = 0' ||
         '      LEFT OUTER JOIN NCLASEA CLAS ON CLAS.CODCLASEA = CLASA, ' ||
         '      NARTOBJ O ' ||
         '      LEFT OUTER JOIN PRETM PM ON PM.CODOBIECT = O.CODOBIECT AND PM.SUBUNITATEA = ' || coalesce(getsubunitate(), 0)::varchar ||
         '      AND CODCATPRET = ' ||aCODCATPRET::varchar ||
         '      LEFT JOIN NCATPRET CAT ON CAT.CODCATPRET = PM.CODCATPRET ' ||
         '      LEFT OUTER JOIN NPART P ON P.CODPART = O.CODPRODUCATOR ' ||
         '    WHERE O.CODARTICOL = A.CODARTICOL AND A.TIPARTICOL::integer = 1 AND coalesce(A.COMENZIONLINE, 0) = 1 ' ||
         ' UNION ALL ' ||
         ' SELECT ' ||
         '    0 AS TIPARTICOL, ' ||
         '    O.DENUMIRE AS DENOBIECT, ' ||
         '    O.CODEXTERN,' ||
         '    O.CODINTERN, ' ||
       '    O.CODARTICOL,' ||
       '      O.INACTIV, ' ||
         '    A.DEN_ARTICOL AS DEN_ART,' ||
         '    A.UM1 AS DUM1,' ||
         '      A.COMENZIONLINE,' ||
         '    U0.DEN_UM1 AS DENUM1,' ||
         '    G.DEN_GEST, ' ||
         '    STOCVIEW.CODOBIECT, ' ||
         '    STOCVIEW.CODGEST,' ||
         '    CASE ' ||
         '      WHEN CAT.TIP = 1 THEN ROUND(coalesce(PM.LEI, 0) / (1 + coalesce(TVAL.PROCENT, 0) / 100), 2) ' ||
         '      ELSE coalesce(PM.LEI, 0) ' ||
         '    END  AS PRET, ' ||
         '    STOCVIEW.STOC, ' ||
         '    P.DEN_PART AS PRODUCATOR, ' ||
         '    CLAS.DEN_CLASEA AS CLASA, ' ||
         '    U.DEN_UM, ' ||
         '    U1.CODUM1 ' ||
         ' FROM ' ||
         '    ( ' ||  -- stoc cumulat
         '     SELECT CODOBIECT, CODGEST, SUM(STOC) AS STOC ' ||
         '     FROM ' ||
         '         ( ' ||
         '           SELECT  CODOBIECT, CODGEST, STOC FROM ' ||
         '                (  ' ||
         '                   SELECT ' ||
         '                      NS.CODOBIECT, ' ||
         '                      N.GEST AS CODGEST,' ||
         '                      SUM(NS.REST - coalesce((SELECT SUM(REST) FROM REZERVATS R WHERE R.CODNIRSTOC = NS.CODNIRSTOC), 0)) AS STOC ' ||
         '                   FROM ' ||
         '                      NIRSTOC NS  ' ||
         '                      LEFT OUTER JOIN TMP_IOART_LUNA IOAL ON IOAL.CODIOART = NS.CODIOART, ' ||
         '                      NIR     N ' ||
         '                   WHERE ' ||
         '                      NS.REST &gt; 0 ' ||
         '                      AND N.CODNIR = NS.CODNIR ' ||
         '                      AND (((SELECT COUNT(*) FROM TMP_GESTDEDICATE) = 0) OR (EXISTS (SELECT CODGEST FROM TMP_GESTDEDICATE WHERE CODGEST = N.GEST))) ' ||
  --       '                      AND IOAL.MG &lt;&gt; 3 AND IOAL.MG &lt;&gt; 5  ' ||
         '                      AND IOAL.MG &lt;&gt; 5  ' ||
         '                      AND coalesce(IOAL.ESTEMIFIX, 0) = 0    ' ||
         '                      AND coalesce(IOAL.ESTEOBINV, 0) = 0    ' ||
         '                   GROUP BY ' ||
         '                      NS.CODOBIECT, ' ||
         '                      N.GEST ' ||
         '                ) sq ' ||
         '           WHERE STOC &gt;= 0 ' ||
         '         ) sq1 ' ||
         '     GROUP BY CODOBIECT, CODGEST ' ||
         '    ) STOCVIEW,  ' ||
         '    NARTOBJ O ' ||
         '    LEFT OUTER JOIN PRETM PM ON PM.CODOBIECT = O.CODOBIECT AND PM.SUBUNITATEA = ' || (current_setting('PKG_GLOBALS.SUBUNITATE', True))::numeric || ' AND CODCATPRET = ' || aCODCATPRET::varchar ||
         '    LEFT JOIN NCATPRET CAT ON CAT.CODCATPRET = PM.CODCATPRET ' ||
         '    LEFT OUTER JOIN NART A ON A.CODARTICOL = O.CODARTICOL  ' ||
      '      LEFT OUTER JOIN NUM1 U0 ON U0.CODUM1 = A.UM1 ' ||
         '    LEFT OUTER JOIN NUM U ON U.CODUM = A.UM ' ||
         '    LEFT OUTER JOIN NUM1 U1 ON U1.CODUM = U.CODUM AND U1.SECUNDARA = 0' ||
         '    LEFT OUTER JOIN NCLASEA CLAS ON CLAS.CODCLASEA = CLASA  ' ||
         '    LEFT OUTER JOIN NPART P ON P.CODPART = O.CODPRODUCATOR ' ||
         '    LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = A.CODARTICOL  ' ||
         '    LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA = NAL.CODTVA, ' ||
         '    NGEST G ' ||
         '  WHERE ' ||
         '    G.CODGEST = STOCVIEW.CODGEST ' ||
         '    AND G.CODSUBUNIT = ' || (current_setting('PKG_GLOBALS.SUBUNITATE', True))::numeric ||
         '    AND O.CODOBIECT = STOCVIEW.CODOBIECT ' ||
         ' ) subq ' ||
         '  WHERE 1=1';

    IF coalesce($3, '?') not in ('?', '') THEN
      FILTRU_ART := ' AND UPPER(DENOBIECT) LIKE ' || '''%' || UPPER($3) || '%''';
    END IF;

    IF coalesce($6, '?') not in ('?', '') THEN
      FILTRU_CODEXTERN := ' AND UPPER(CODEXTERN) LIKE ' || '''%' || UPPER($6) || '%''';
    END IF;


    IF coalesce($7, '?') not in ('?', '') THEN
      FILTRU_CODINTERN := ' AND UPPER(CODINTERN) LIKE ' || '''%' || UPPER($7) || '%''';
    END IF;


    IF coalesce($4, '?') not in ('?', '') THEN
      FILTRU_CLASA := ' AND UPPER(CLASA) LIKE ' || '''%' || UPPER($4) || '%''';
    END IF;

    IF coalesce($5, 0) &lt;&gt; 0 THEN
      FILTRU_GEST := ' AND CODGEST = ' || $5::varchar;
    END IF;

    OPEN $1 FOR execute S || FILTRU_ART || ' ' || FILTRU_CLASA || ' ' || FILTRU_GEST || FILTRU_CODEXTERN || ' ' || FILTRU_CODINTERN || ' ORDER BY DENOBIECT ';
    return next $1;
  end;
  $function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_wmeonline_getsubunitati</obj_name>
  <obj_hashval>4f5ab16c954478ec61ff0453511e81ac</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_wmeonline_getsubunitati(INOUT wme_result refcursor, INOUT puser numeric, INOUT pfirma numeric)
 RETURNS record
 LANGUAGE plpgsql
AS $function$
DECLARE
  RESULT_CURSOR REFCURSOR;
begin
  DELETE
  FROM TMP_MANEVRA;

  perform winmadmin.pkg_userfirme_getsubunitati(pUSER, pFIRMA);

  insert into tmp_manevra (select CODSUBUNIT from TMP_SUBUNITDEDICATE);

  OPEN RESULT_CURSOR FOR
  SELECT S.CODSUBUNIT, S.DEN_SUBUNIT
  FROM TMP_MANEVRA        T
    INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = T.CODUNIC;

  WME_Result := RESULT_CURSOR;
  RETURN;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>process_tmp_lst_externe</obj_name>
  <obj_hashval>63a9800c4d68f85258d5bc70f56f6d33</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION process_tmp_lst_externe()
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  VREC RECORD;
BEGIN
  --Adina 19.06.2021
  FOR vRec IN (SELECT SqlText, ListId, ListVER FROM TMP_LST_EXTERNE ORDER BY ORDINE) LOOP
    PERFORM LIST_EXECUTE_IMMEDIATE(vRec.SqlText, vRec.ListId, vRec.ListVER);
  END LOOP;
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>remake_sequence</obj_name>
  <obj_hashval>d1b8dc1c1383dbe985beff27dbba78ca</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION remake_sequence(nume_schema character varying, nume_secv character varying, newvalue numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
BEGIN
  EXECUTE 'SELECT SETVAL(''' || nume_schema || '.' || nume_secv || ''',' || TO_CHAR(newvalue, '999999999999999999') || ');';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_livrari_ser_luna</obj_name>
  <obj_hashval>d259067d99b873196757bb77dcd3a999</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_livrari_ser_luna()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$ begin
  return
  'select
    L1.CODNIRSER,
    L1.CODNIRSTOC,
    -1 * L1.CANT as REST,
    -1 * L1.CANTUM1 as RESTUM1,
    -1 * L1.CANTUM2 as RESTUM2
  from
    LIVR1 L1
    left join NIRSTOC NS on NS.CODNIRSTOC = L1.CODNIRSTOC
    left join LIVR    L  on L.CODLIVR     = L1.CODLIVR
    left join INTRARI I  on I.CODINTR     = L.CODINTR,
    TMP_IOART_LUNA IO
  where
    NS.TIPSERIE &gt; 0
    and L.TIPLIVR in (1, 2, 3, 4, 5, 6, 7)
    and L.OPERAT = 1
    and L.ANULAT = 0
    and I.AN   = current_setting(''PKG_GLOBALS.ANTEMP''  , true)::numeric
    and I.LUNA = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric
    and IO.CODIOART = NS.CODIOART
    and IO.MG &lt;&gt; 5
  union all
  select
    L1.CODNIRSER,
    L1.CODNIRSTOC,
    -1 * L1.CANT as REST,
    -1 * L1.CANTUM1 as RESTUM1,
    -1 * L1.CANTUM2 as RESTUM2
  from
    LIVR1 L1
    left join NIRSTOC NS on NS.CODNIRSTOC = L1.CODNIRSTOC
    left join LIVR    L  on L.CODLIVR     = L1.CODLIVR
    left join IESIRI  I  on I.CODIES      = L.CODIES,
    TMP_IOART_LUNA IO
  where
    NS.TIPSERIE &gt; 0
    and L.TIPLIVR in (14, 16, 19, 20, 23, 24)
    and L.OPERAT = 1
    and L.ANULAT = 0
    and I.AN   = current_setting(''PKG_GLOBALS.ANTEMP''  , true)::numeric
    and I.LUNA = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric
    and IO.CODIOART = NS.CODIOART
    and IO.MG &lt;&gt; 5
  union all
  select
    L1.CODNIRSER,
    L1.CODNIRSTOC,
    -1 * L1.CANT as REST,
    -1 * L1.CANTUM1 as RESTUM1,
    -1 * L1.CANTUM2 as RESTUM2
  from
    LIVR1 L1
    left join NIRSTOC NS on NS.CODNIRSTOC = L1.CODNIRSTOC
    left join LIVR    L  on L.CODLIVR     = L1.CODLIVR
    left join TRANSF  T  on T.CODTRANSF   = L.CODTRANSF,
    TMP_IOART_LUNA IO
  where
    NS.TIPSERIE &gt; 0
    and L.TIPLIVR in (12,
    13)
    and L.OPERAT = 1
    and L.ANULAT = 0
    and T.AN   = current_setting(''PKG_GLOBALS.ANTEMP''  , true)::numeric
    and T.LUNA = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric
    and IO.CODIOART = NS.CODIOART
    and IO.MG &lt;&gt; 5
  union all
  select
    L1.CODNIRSER,
    L1.CODNIRSTOC,
    L1.CANT as REST,
    L1.CANTUM1 as RESTUM1,
    L1.CANTUM2 as RESTUM2
  from
    LIVR1 L1
    left join NIRSTOC NS on NS.CODNIRSTOC = L1.CODNIRSTOC
    left join LIVR    L  on L.CODLIVR     = L1.CODLIVR
    left join IESIRI  I  on I.CODIES      = L.CODIES,
    TMP_IOART_LUNA IO
  where
    NS.TIPSERIE &gt; 0
    and L.TIPLIVR = 15
    and L.OPERAT = 1
    and L.ANULAT = 0
    and I.AN   = current_setting(''PKG_GLOBALS.ANTEMP''  , true)::numeric
    and I.LUNA = current_setting(''PKG_GLOBALS.LUNATEMP'', true)::numeric
    and IO.CODIOART = NS.CODIOART
    and IO.MG &lt;&gt; 5';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_oblig_client</obj_name>
  <obj_hashval>918bdcb86fc8cae21d58debd1eaf701a</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_oblig_client()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Adina 23 septembrie 2020
  RETURN
  '  SELECT
      CODOBLIGPIF, DOC, NRDOC, DATADOC, VALOARE, REST, TERMEN, PRELUAT, RAMAS, CODSTINGATOR, SEMNIFCODSTINS, SIMBOLCONT, ICONT,
      CODMONEDA, SIMBOLMONEDA, CURS, TVA, CODLOCATIE, SEDIU, SUBUNITATEA, DEN_SUBUNIT, PROCTVAAVANS
    FROM ( ' || V_OBLIG_CLIENT_IESIRI() || ' ) v1
  UNION ALL
    SELECT
      CODOBLIGPIF, DOC, NRDOC, DATADOC, VALOARE, REST, TERMEN, PRELUAT, RAMAS, CODSTINGATOR, SEMNIFCODSTINS, SIMBOLCONT, ICONT,
      CODMONEDA, SIMBOLMONEDA, CURS, TVA, CODLOCATIE, SEDIU, SUBUNITATEA, DEN_SUBUNIT, PROCTVAAVANS
    FROM ( ' || V_OBLIG_CLIENT_NC() || ' ) v2
  UNION ALL
    SELECT
      CODOBLIGPIF, DOC, NRDOC, DATADOC, VALOARE, REST, TERMEN, PRELUAT, RAMAS, CODSTINGATOR, SEMNIFCODSTINS, SIMBOLCONT, ICONT,
      CODMONEDA, SIMBOLMONEDA, CURS, TVA, CODLOCATIE, SEDIU, SUBUNITATEA, DEN_SUBUNIT, PROCTVAAVANS
    FROM ( ' || V_OBLIG_CLIENT_COMPENS() || ' ) v3 ';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_pmp_luna</obj_name>
  <obj_hashval>dbb63621175740ab24de8a5b22bdd56b</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_pmp_luna(vcodobiect numeric DEFAULT 0, vcodsubunit numeric DEFAULT 0)
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
BEGIN
  --Stef 03.03.2023
  RETURN '
  SELECT CODOBIECT, CODSUBUNIT, SUM(CANTINTR) AS CANTINTR, SUM(VALINTR) AS VALINTR, SUM(RESTLUNA) AS RESTLUNA, SUM(VALVALUTA) AS VALVALUTA
  FROM (
    SELECT CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, RESTLUNA, VALVALUTA
    FROM ('||V_PMP_INTRARI(vcodobiect, vcodsubunit)||') A
    UNION ALL
    SELECT CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, RESTLUNA, VALVALUTA
    FROM ('||V_PMP_IESIRI (vcodobiect, vcodsubunit)||') B
  ) A_PG
  GROUP BY CODOBIECT, CODSUBUNIT';
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>v_stoc_tranzactii_luna</obj_name>
  <obj_hashval>ecccf1b82ef9da829390b9155dde859d</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION v_stoc_tranzactii_luna()
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
begin
  --Adina aug.2020
  return
  'SELECT CODNIRSTOC, SUM(REST) AS REST, SUM(RESTUM1) AS RESTUM1, SUM(RESTUM2) AS RESTUM2
  FROM
      (
        SELECT CODNIRSTOC, REST, RESTUM1, RESTUM2 FROM ('||V_NIRURI_LUNA() ||') a_pg
        UNION ALL
        SELECT CODNIRSTOC, REST, RESTUM1, RESTUM2 FROM ('||V_LIVRARI_LUNA()||') b_pg
      ) c_pg
  GROUP BY CODNIRSTOC
  ';
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_alerte_def</obj_name>
  <obj_hashval>4cf48006837730ac6fe8c8fc9723ac1c</obj_hashval>
  <obj_text>SELECT codalertadef,
    denumire,
    sql
   FROM martor.alerte_def a;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_art_simplu</obj_name>
  <obj_hashval>55d022dfc1acd33f755b3b06001a3ca4</obj_hashval>
  <obj_text>SELECT codarticol,
    den_articol
   FROM martor.nart a;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_criteriidisc</obj_name>
  <obj_hashval>5507b9bb91cd2c0351f559e9b8ed8e72</obj_hashval>
  <obj_text>SELECT codcriteriu,
    dencriteriu,
    offinvoice,
    COALESCE(puncte, 0::numeric) AS puncte,
        CASE
            WHEN COALESCE(puncte, 0::numeric) = 1::numeric THEN 'Puncte'::character varying
            ELSE 'Discount'::character varying
        END AS tipdisc
   FROM martor.criteriidisc
  WHERE codcriteriu &gt; 20::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_databord</obj_name>
  <obj_hashval>5d930928f7136c4517274289f8f46fc9</obj_hashval>
  <obj_text>SELECT p0.codnparcaut,
    max(p0.codnparc0) AS codnparc0
   FROM martor.nparc0 p0,
    ( SELECT nparc0.codnparcaut,
            max(nparc0.databord) AS databord
           FROM martor.nparc0
          GROUP BY nparc0.codnparcaut) x
  WHERE x.codnparcaut = p0.codnparcaut AND x.databord = p0.databord
  GROUP BY p0.codnparcaut;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_jobliste</obj_name>
  <obj_hashval>d3c10015ea2bd6a1f9c6f0582d575b18</obj_hashval>
  <obj_text>SELECT j.codjob,
    j.userid,
    j.denumire,
    j.tipjob,
    u.username,
    u.nume
   FROM martor.jobliste j
     LEFT JOIN winmadmin.utilizator u ON u.codutilizator = j.userid
  WHERE COALESCE(j.tipjob, 0::numeric) &lt; 2::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_jurnal_t</obj_name>
  <obj_hashval>6f9bfb799123886df0a1b765825509ae</obj_hashval>
  <obj_text>SELECT 5 AS tipinreg,
    j.codcentru AS centrucost,
    cd.simbol AS simbcontdebit,
    cc.simbol AS simbconcredit,
    j.valoare AS v,
    j.codjurnal,
    j.coddoc,
    j.tipdoc,
    j.indexlocal,
    j.contd,
    j.contc,
    j.gest,
    j.valoare,
    j.valoarev,
    j.obs,
    j.an,
    j.luna,
    j.subunitatea,
    j.datadoc,
    j.document,
    j.codcentru,
    j.valoaregrup,
    j.valoare_ifrs,
    j.valoarev_ifrs
   FROM martor.jurnal j
     JOIN martor.ncont1 c1d ON c1d.codcont1 = (( SELECT pkg_planconturi_get_cont_cod_caract_luna.wme_result
           FROM martor.pkg_planconturi_get_cont_cod_caract_luna(NULL::numeric, j.contd, j.an, j.luna) pkg_planconturi_get_cont_cod_caract_luna(wme_result, acodcont, aan, aluna)))
     JOIN martor.ncont1 c1c ON c1c.codcont1 = (( SELECT pkg_planconturi_get_cont_cod_caract_luna.wme_result
           FROM martor.pkg_planconturi_get_cont_cod_caract_luna(NULL::numeric, j.contc, j.an, j.luna) pkg_planconturi_get_cont_cod_caract_luna(wme_result, acodcont, aan, aluna)))
     JOIN martor.ncontt cd ON cd.codcontt = c1d.conttertiar
     JOIN martor.ncontt cc ON cc.codcontt = c1c.conttertiar
  WHERE (j.an * 12::numeric + j.luna) &gt;= (( SELECT pkg_list_base_regjurnal_lunaini.wme_result
           FROM martor.pkg_list_base_regjurnal_lunaini(NULL::numeric, NULL::numeric) pkg_list_base_regjurnal_lunaini(wme_result, fakeparam))) AND (j.an * 12::numeric + j.luna) &lt;= (( SELECT pkg_list_base_regjurnal_lunafin.wme_result
           FROM martor.pkg_list_base_regjurnal_lunafin(NULL::numeric, NULL::numeric) pkg_list_base_regjurnal_lunafin(wme_result, fakeparam))) AND COALESCE(c1d.conttertiar, 0::numeric) &gt; 0::numeric AND COALESCE(c1c.conttertiar, 0::numeric) &gt; 0::numeric AND (EXISTS ( SELECT 1
           FROM martor.ncontt1 ct1d
          WHERE ct1d.codcontt = cd.codcontt AND (ct1d.anstart * 12::numeric + ct1d.lunastart) &lt;= (( SELECT pkg_list_base_regjurnal_lunafin.wme_result
                   FROM martor.pkg_list_base_regjurnal_lunafin(NULL::numeric, NULL::numeric) pkg_list_base_regjurnal_lunafin(wme_result, fakeparam))))) AND (EXISTS ( SELECT 1
           FROM martor.ncontt1 ct1c
          WHERE ct1c.codcontt = cc.codcontt AND (ct1c.anstart * 12::numeric + ct1c.lunastart) &lt;= (( SELECT pkg_list_base_regjurnal_lunafin.wme_result
                   FROM martor.pkg_list_base_regjurnal_lunafin(NULL::numeric, NULL::numeric) pkg_list_base_regjurnal_lunafin(wme_result, fakeparam)))));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_locmunca</obj_name>
  <obj_hashval>a9375fd69fe4fd274b35dcb40ee4a229</obj_hashval>
  <obj_text>SELECT codloc,
    simbol,
    denumire,
    tip,
    dsv,
        CASE
            WHEN tip = 0::numeric THEN 'Manual'::text
            WHEN tip = 1::numeric THEN 'Mijloc fix'::text
            WHEN tip = 2::numeric THEN 'Utilaj'::text
            ELSE ' '::text
        END AS tipstring
   FROM martor.locmunca
  WHERE codloc = current_setting('PKG_GLOBALS.RECID_DOC_LISTARE'::text, true)::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_oferta</obj_name>
  <obj_hashval>960cca9bca6926ff0903de9aa3b41711</obj_hashval>
  <obj_text>SELECT codoferta,
    tipdoc,
    nrdoc,
    anulat,
    operat,
    blocat,
    an,
    luna
   FROM martor.oferta o
  WHERE codoferta = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_lista_proiect</obj_name>
  <obj_hashval>40e283ac082fd2fc677ed9e8ab6ab3a4</obj_hashval>
  <obj_text>SELECT codproiect,
    codversiune,
    codobiectprod,
    versiune,
    intocmita,
    dataproiect,
    clasa,
    procesare,
    complex,
    activ,
    finalizat,
    blocat,
    invizibila,
    generic,
    implicit,
    durata,
    marjaordine,
    userid,
    datacreare,
    obs1,
    obs2,
    obs3,
    obs4,
    obs5,
    obs6,
    codextern
   FROM martor.proiect
  WHERE codproiect = (( SELECT pkg_globals_get_recid_doc_listare.wme_result
           FROM martor.pkg_globals_get_recid_doc_listare(NULL::numeric, NULL::numeric) pkg_globals_get_recid_doc_listare(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_locatii_gestiune</obj_name>
  <obj_hashval>61d0a8e497a3c2001c40b3fac49e9a17</obj_hashval>
  <obj_text>SELECT codlocatie,
    codgest,
    denumire,
    indexlocal,
    nrcelule,
    descriere,
    codextern,
    tiplocatie,
    codlocfixa,
    codvecinleft,
    codvecinright,
    coordx,
    inactiv
   FROM martor.nlocatii
  WHERE COALESCE(codgest, 0::numeric) = 0::numeric OR codgest = (( SELECT pkg_nomgest_get_gest_curenta_locatii.wme_result
           FROM martor.pkg_nomgest_get_gest_curenta_locatii(NULL::numeric, NULL::numeric) pkg_nomgest_get_gest_curenta_locatii(wme_result, fakeparam))) OR (( SELECT pkg_nomgest_get_locatia_curenta.wme_result
           FROM martor.pkg_nomgest_get_locatia_curenta(NULL::numeric, NULL::numeric) pkg_nomgest_get_locatia_curenta(wme_result, fakeparam))) &gt; 0::numeric AND codlocatie = (( SELECT pkg_nomgest_get_locatia_curenta.wme_result
           FROM martor.pkg_nomgest_get_locatia_curenta(NULL::numeric, NULL::numeric) pkg_nomgest_get_locatia_curenta(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_locmunca</obj_name>
  <obj_hashval>7b4d9b1dddcc1c30ebe5f7fbb0763558</obj_hashval>
  <obj_text>SELECT codloc,
    simbol,
    denumire,
    tip,
    dsv,
    special,
        CASE
            WHEN tip = 0::numeric THEN 'Manual'::character varying
            WHEN tip = 1::numeric THEN 'Mijloc fix'::character varying
            WHEN tip = 2::numeric THEN 'Utilaj'::character varying
            ELSE ' '::character varying
        END AS tipstring,
    fara_gant
   FROM martor.locmunca;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_serii_obiect</obj_name>
  <obj_hashval>88cab879770f0d4f3326294a129a5cea</obj_hashval>
  <obj_text>SELECT DISTINCT codserie,
    serie,
    codobiect,
    obs
   FROM martor.nserii
  WHERE codobiect = (( SELECT pkg_serii_getobiectcurent.wme_result
           FROM martor.pkg_serii_getobiectcurent(NULL::numeric, NULL::numeric) pkg_serii_getobiectcurent(wme_result, fakeparam)));</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_sitfin</obj_name>
  <obj_hashval>cca2520883259db98567adbf0538b1f9</obj_hashval>
  <obj_text>SELECT codsitfin,
    codf,
    denumire,
    sectiune,
    (codf::text || ' - '::text) || denumire::text AS codden
   FROM martor.sitfin
  WHERE COALESCE(tip, 0::numeric) = 0::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>VIEW</obj_type>
  <obj_name>v_stoc_serii</obj_name>
  <obj_hashval>bcbf7cfdd5d2008273d7808f687316ad</obj_hashval>
  <obj_text>SELECT nse.codnirser,
    ns.codnirstoc,
    num.den_um,
    ser.serie,
    g.den_gest,
        CASE
            WHEN ns.tipserie &gt; 0::numeric THEN round(nse.rest, 10)
            ELSE round(ns.rest, 10)
        END - COALESCE(rez.cant, 0::numeric) - COALESCE(blocat.cant, 0::numeric) AS stoc
   FROM martor.nirstoc ns
     JOIN martor.nartobj obj ON ns.codobiect = obj.codobiect
     JOIN martor.nart art ON obj.codarticol = art.codarticol
     JOIN martor.num ON art.um = num.codum
     JOIN martor.nirser nse ON nse.codnirstoc = ns.codnirstoc
     JOIN martor.nserii ser ON ser.codserie = nse.codserie
     JOIN martor.nir nircurent ON nircurent.codnir = ns.codnir
     JOIN martor.ngest g ON g.codgest = nircurent.gest
     LEFT JOIN ( SELECT rezervats.codnirstoc,
            rezervats.codnirser,
            sum(rezervats.rest) AS cant
           FROM martor.rezervats
          GROUP BY rezervats.codnirstoc, rezervats.codnirser) rez ON rez.codnirstoc = ns.codnirstoc AND rez.codnirser = nse.codnirser
     LEFT JOIN ( SELECT stoclock.codnirstoc,
            stoclock.codnirser,
            sum(stoclock.cant) AS cant
           FROM martor.stoclock
          GROUP BY stoclock.codnirstoc, stoclock.codnirser) blocat ON blocat.codnirstoc = ns.codnirstoc AND blocat.codnirser = nse.codnirser
  WHERE ns.codobiect = (( SELECT pkg_selectarticole_getobiectanalizat.wme_result
           FROM martor.pkg_selectarticole_getobiectanalizat(NULL::numeric, NULL::numeric) pkg_selectarticole_getobiectanalizat(wme_result, fakeparam))) AND (g.codsubunit = (( SELECT pkg_globals_getsubunitate.wme_result
           FROM martor.pkg_globals_getsubunitate(NULL::numeric, NULL::numeric) pkg_globals_getsubunitate(wme_result, fakeparam))) OR (( SELECT pkg_globals_getsubunitate.wme_result
           FROM martor.pkg_globals_getsubunitate(NULL::numeric, NULL::numeric) pkg_globals_getsubunitate(wme_result, fakeparam))) = 1::numeric) AND (
        CASE
            WHEN ns.tipserie &gt; 0::numeric THEN round(nse.rest, 10)
            ELSE round(ns.rest, 10)
        END - COALESCE(rez.cant, 0::numeric)) &gt; 0::numeric;</obj_text>
  <obj_nivel>0</obj_nivel>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>monetare_calc_disclin</obj_name>
  <obj_hashval>1c38964dc657639ba2db7dc97d5539d7</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION monetare_calc_disclin(pcodies numeric)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
DECLARE
  vTipDoc      NUMERIC;
  vAN          NUMERIC;
  vLuna        NUMERIC;
  vCoteDisc    NUMERIC;
  vCIntermedCM NUMERIC;
  vConIncFact  NUMERIC;
  sArtExcl     VARCHAR(4000);
BEGIN
  --Stef   23.12.2025
  --Florin 02.12.2025
  CALL create_wm_temps_flag('TMP_MON_DISCLIN');
  call TRUNCATE_TABLE('TMP_MON_DISCLIN');
  call TRUNCATE_TABLE('TMP_MON_DISCPROC');
  BEGIN
    SELECT TipDoc, An, Luna INTO vTipDoc, vAN, vLuna FROM iesiri WHERE codies = pCodIes;
  EXCEPTION WHEN OTHERS THEN
    vTipDoc := 0;
  END;

  IF vTipDoc IN (16) THEN
    SELECT Count(1) INTO vCoteDisc
    FROM discmonetar
    WHERE codies = pCodIes;

    INSERT INTO TMP_MON_DISCLIN (CodIes1, CodObiect, ProcTVA, Calc, LinVal, LinTVA, DiscVal, DiscTVA)
    SELECT
      i1.CodIes1, i1.CodObiect,
      CASE
        WHEN (i1.cant*i1.pu-i1.tva) = 0 THEN 0
        ELSE PKG_LIST_BASE_UTILS_MATCH_TVA_PROC(i1.tva*100/(i1.cant*i1.pu-i1.tva), i.An*12+i.Luna)
      END ProcTVA,
      CASE
        WHEN (i1.cant*i1.pu-i1.tva) = 0       THEN 0
        WHEN i1.tiplinie = 'V'                THEN 0
        WHEN Coalesce(i1.valdiscpret, 0) &lt;&gt; 0 THEN 0
        ELSE                                       1
      END Calc,
      i1.pu*i1.cant LinVal, i1.tva LinTVA,
      Coalesce(i1.valdiscpret,0) DiscVal, Coalesce(i1.tva*i1.valdiscpret/NullIF(i1.pu*i1.cant,0), 0) DiscTVA
    FROM iesiri i inner join iesiri1 i1 ON i1.codies = i.codies
    WHERE i.codies = pCodIes;

    IF vCoteDisc = 0 THEN
      UPDATE TMP_MON_DISCLIN SET Calc = 0 WHERE Calc = -1;
    ELSE
      PERFORM pkg_globals_SetSeparator(',');
      SELECT STRING_AGG(x, '') INTO sArtExcl
      FROM (
        SELECT Coalesce(fnc_GetValConstanta('ArtFaraDiscMonetar',vAn,vLuna),'0') x UNION
        SELECT Coalesce(fnc_GetValConstanta('ArtIncasImediat'   ,vAn,vLuna),'0') x UNION
        SELECT Coalesce(fnc_GetValConstanta('ArtIncasUlterior'  ,vAn,vLuna),'0') x
      ) subs;
      IF NULLIF(sArtExcl, '') IS NOT NULL THEN
        sArtExcl := ','||sArtExcl||',';
        UPDATE TMP_MON_DISCLIN SET Calc = 0 WHERE Calc = -1 AND InStr(sArtExcl, ','||CodObiect||',') &gt; 0;
      END IF;

      vCIntermedCM := To_Number(Coalesce(fnc_GetValConstanta('CIntermedCM'        ,vAn,vLuna),'-1'));
      IF vCIntermedCM &gt; 0 THEN
        UPDATE TMP_MON_DISCLIN SET Calc = 0
        WHERE Calc = -1
          AND Codies1 IN (
            SELECT CodIes1
            FROM Iesiri1
            WHERE CodIes = pCodIes AND Coalesce(ContServ,-1) = vCIntermedCM
          );
      END IF;

      vConIncFact  := To_Number(Coalesce(fnc_GetValConstanta('ContIncasareFactura',vAn,vLuna),'-1'));
      IF vConIncFact &gt; 0 THEN
        UPDATE TMP_MON_DISCLIN SET Calc = 0
        WHERE Calc = -1
          AND Codies1 IN (
            SELECT CodIes1
            FROM LIVR L
              INNER JOIN LIVR1   L1 ON L1.Codlivr    = L.CodLivr
              LEFT  JOIN LIVRVAL LV ON LV.CodLivr1   = L1.CodLivr1
              LEFT  JOIN NIRSTOC NS ON NS.CodNirStoc = L1.CodNirStoc
            WHERE L.TipLivr = 16 AND L.CodIes = pCodIes AND Coalesce(NS.CodIoart,LV.CodIoart, 0) = vConIncFact
          );
      END IF;

      INSERT INTO TMP_MON_DISCPROC (ProcTVA, REST_VAL, REST_TVA, DTOT_VAL, DTOT_TVA, DREP_VAL, DREP_TVA)
      SELECT dm.ProcTVA, di1.REST_VAL, di1.REST_TVA, dm.DISCOUNT, dm.TVADISCOUNT, di1.DREP_VAL, di1.DREP_TVA
      FROM discmonetar dm
        LEFT JOIN (
          SELECT
            ProcTVA,
            Sum(CASE WHEN CALC = 1 THEN LINVAL ELSE 0  END) REST_VAL,
            Sum(CASE WHEN CALC = 1 THEN LINTVA ELSE 0  END) REST_TVA,
            Sum(CASE WHEN CALC = 1 THEN 0 ELSE DISCVAL END) DREP_VAL,
            Sum(CASE WHEN CALC = 1 THEN 0 ELSE DISCTVA END) DREP_TVA
          FROM TMP_MON_DISCLIN
          GROUP BY ProcTVA
        ) di1 ON di1.ProcTVA = dm.ProcTVA
      WHERE dm.Codies = pCodIes;
    END IF;

    UPDATE TMP_MON_DISCLIN SET Calc = 0 WHERE NOT ProcTVA IN (SELECT DISTINCT ProcTVA FROM TMP_MON_DISCPROC);

    UPDATE TMP_MON_DISCLIN DL
    SET (DiscVal, DiscTVA) =
        (SELECT LINVAL*(DTOT_VAL-DREP_VAL)/REST_VAL, LINTVA*(DTOT_TVA-DREP_TVA)/REST_TVA
         FROM TMP_MON_DISCPROC DP
         WHERE DP.ProcTVA = DL.ProcTVA  )
    WHERE Calc = 1;

  END IF;
END;
$function$
</obj_text>
</row>

<row>
  <obj_type>PROCEDURE</obj_type>
  <obj_name>create_wm_temp</obj_name>
  <obj_hashval>b28c5f6474e442769ee24e936af8b932</obj_hashval>
  <obj_text>CREATE OR REPLACE PROCEDURE create_wm_temp(IN ptempname character varying)
 LANGUAGE plpgsql
AS $procedure$
DECLARE
  sTableSpace VARCHAR := get_temp_tablespace();
  vRec        RECORD;
  sDDL        TEXT;
BEGIN
  --Stef 03.03.2023
  SELECT 'CREATE TEMPORARY TABLE '||tmp_name||E' (\n'||array_to_string(array_agg(col_def ORDER BY col_ord), E',\n')||E'\n) ON COMMIT PRESERVE ROWS'||sTableSpace||';' AS ddl_text
  INTO   sDDL
  FROM (
    SELECT tmp_name, col_def, col_ord
    FROM WM_COL_TMP MCol
    WHERE Upper(MCol.tmp_name) = Upper(pTempName)
    UNION ALL
    SELECT tmp_name, col_def, col_ord
    FROM WINMADMIN.WM_COL_TMP WCol
    WHERE Upper(WCol.tmp_name) = Upper(pTempName)
      AND NOT EXISTS (SELECT 1 FROM WM_COL_TMP MCol WHERE MCol.tmp_name = WCol.tmp_name)
  ) WCT
  GROUP BY tmp_name;

  EXECUTE sDDL;

  --indecsi la temporare
  FOR vRec IN (
    SELECT idx_def AS ddl_text
    FROM (
      SELECT midx.tmp_name, midx.idx_def
      FROM wm_idx_tmp midx
      WHERE Upper(midx.tmp_name) = Upper(pTempName)
      UNION ALL
      SELECT widx.tmp_name, widx.idx_def
      FROM WINMADMIN.wm_idx_tmp widx
      WHERE Upper(widx.tmp_name) = Upper(pTempName)
        AND NOT EXISTS (SELECT 1 FROM wm_idx_tmp midx WHERE midx.tmp_name = widx.tmp_name)
    ) WCT
    ORDER BY tmp_name, idx_def
  ) LOOP
    BEGIN
      EXECUTE vRec.ddl_text;
    EXCEPTION
      WHEN OTHERS THEN NULL;
    END;
  END LOOP;

EXCEPTION
  WHEN OTHERS THEN NULL;
END;
$procedure$
</obj_text>
</row>

<row>
  <obj_type>PROCEDURE</obj_type>
  <obj_name>create_wm_temps</obj_name>
  <obj_hashval>20a121b9599f56eb71f113dffe110a0d</obj_hashval>
  <obj_text>CREATE OR REPLACE PROCEDURE create_wm_temps()
 LANGUAGE plpgsql
AS $procedure$
DECLARE
  sTableSpace VARCHAR := get_temp_tablespace();
  vRec        RECORD;
  vSkema      VARCHAR;
BEGIN
  --Stef 04.04.2025
  FOR vRec IN (
    SELECT 'DROP TABLE ' || c.relname || ';' AS ddl_text
    FROM (SELECT DISTINCT Lower(TMP_NAME) tmp_name FROM WM_COL_TMP) t
      INNER JOIN pg_catalog.pg_class     c ON c.relname = t.tmp_name
      LEFT  JOIN pg_catalog.pg_namespace n ON n.oid     = c.relnamespace
    WHERE n.nspname like 'pg_temp_%'
      AND pg_catalog.pg_table_is_visible(c.oid)
  ) LOOP
    BEGIN
      EXECUTE vRec.ddl_text;
    EXCEPTION
      WHEN OTHERS THEN NULL;
    END;
  END LOOP;

  FOR vRec IN (
    SELECT
      'CREATE TEMPORARY TABLE '||tmp_name||'('||STRING_AGG(E'\n '||col_def, ', ' ORDER BY col_ord)||E'\n) ON COMMIT PRESERVE ROWS'||sTableSpace||';' AS ddl_text
    FROM (
      SELECT tmp_name, col_def, col_ord
      FROM WM_COL_TMP
      WHERE NOT tmp_name IN (SELECT DISTINCT tmp_name FROM WM_FLAG_TMP)
      UNION ALL
      SELECT tmp_name, col_def, col_ord
      FROM WINMADMIN.WM_COL_TMP
      WHERE NOT tmp_name IN (SELECT DISTINCT tmp_name FROM WM_COL_TMP UNION ALL SELECT DISTINCT tmp_name FROM WINMADMIN.WM_FLAG_TMP)
    ) WCT
    GROUP BY tmp_name
  ) LOOP
    BEGIN
      EXECUTE vRec.ddl_text;
    EXCEPTION
      WHEN OTHERS THEN NULL;
    END;
  END LOOP;

  --indecsi la temporare
  FOR vRec IN (
    SELECT idx_def AS ddl_text
    FROM (
      SELECT midx.tmp_name, midx.idx_def
      FROM wm_idx_tmp midx LEFT JOIN WM_FLAG_TMP MFlag ON UPPER(MFlag.tmp_name) = UPPER(midx.tmp_name)
      WHERE MFlag.FLAG IS NULL
      UNION ALL
      SELECT widx.tmp_name, widx.idx_def
      FROM WINMADMIN.wm_idx_tmp widx
      WHERE NOT EXISTS (SELECT 1 FROM wm_idx_tmp midx WHERE midx.tmp_name = widx.tmp_name)
    ) WCT
    ORDER BY tmp_name, idx_def
  ) LOOP
    BEGIN
      EXECUTE vRec.ddl_text;
    EXCEPTION
      WHEN OTHERS THEN NULL;
    END;
  END LOOP;

  --viewuri cu temporare
  FOR vRec IN (SELECT v_name, v_def FROM WM_VIEW_TMP WHERE V_DEF IS NOT NULL ORDER BY v_nivel, v_name) LOOP
    BEGIN
      EXECUTE vRec.v_def;
      UPDATE WM_VIEW_TMP SET v_valid = 1 WHERE v_name = vRec.v_name;
    EXCEPTION
      WHEN OTHERS THEN UPDATE WM_VIEW_TMP SET v_valid = 0 WHERE v_name = vRec.v_name;
    END;
  END LOOP;

  --temporare la extensii
  -- Skema curenta o extrag din search_path
  SELECT elem
  INTO vSkema
  FROM (
    SELECT string_to_array(setting,', ') arr
    FROM pg_settings
    WHERE name = 'search_path'
  ) s, unnest(s.arr) WITH ORDINALITY a(elem, nr)
  WHERE a.elem NOT IN ('public', 'winmadmin')
  ORDER BY nr
  LIMIT 1;

  IF vSkema IS NULL THEN
    vSkema := NULLIF(Lower(getfirmaname()), '');
  END IF;

  IF vSkema IS NOT NULL THEN
    FOR vRec IN (
      SELECT
        tsql.tabname,
        ( SELECT COUNT(1)
          FROM pg_catalog.pg_class c INNER JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
          WHERE c.relname = 'tmp_'||tsql.tabname AND n.nspname like 'pg_temp_%' AND pg_catalog.pg_table_is_visible(c.oid)
        ) tmpcnt
      FROM (
              SELECT Lower(numetabela) AS tabname FROM cfgtables
        UNION SELECT 'settaskext'
      ) tsql
        INNER JOIN pg_catalog.pg_class c ON c.relname = tsql.tabname
        INNER JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
      WHERE n.nspname = vSkema
        AND pg_catalog.pg_table_is_visible(c.oid)
    ) LOOP
      IF vRec.tmpcnt &gt; 0 THEN
        BEGIN
          EXECUTE 'DROP TABLE tmp_' || vrec.tabname ;
        EXCEPTION
          WHEN OTHERS THEN NULL;
        END;
      END IF;
      BEGIN
        EXECUTE 'CREATE TEMPORARY TABLE tmp_' || vrec.tabname || ' ON COMMIT PRESERVE ROWS AS SELECT * FROM ' || vrec.tabname || ' WHERE 1=0';
      EXCEPTION
        WHEN OTHERS THEN NULL;
      END;
    END LOOP;

    FOR vRec IN (
      SELECT 'ALTER TABLE tmp_'||numetabela||STRING_AGG(E'\n ADD COLUMN '||coldef, ', ' ORDER BY indexlocal) ddl_text
      FROM (
        SELECT
          c.numetabela, c1.indexlocal, '"'||lower(numecamp)||'"'||PKG_CFGTABLES_GET_FIELD_TYPE(c1.Tip,c1.Zecimale,c1.Marime) coldef
        FROM cfgtables1 c1 INNER JOIN cfgtables c ON c.codcfgtable = c1.codcfgtable
        WHERE c1.tmp = 1
      ) subs
      GROUP BY numetabela
    ) LOOP
      BEGIN
        EXECUTE vrec.ddl_text;
      EXCEPTION
        WHEN OTHERS THEN NULL;
      END;
    END LOOP;
  END IF;
END;
$procedure$
</obj_text>
</row>

<row>
  <obj_type>PROCEDURE</obj_type>
  <obj_name>create_wm_temps_flag</obj_name>
  <obj_hashval>5154322f5f55d5856987a8017c29dc97</obj_hashval>
  <obj_text>CREATE OR REPLACE PROCEDURE create_wm_temps_flag(IN pflag character varying)
 LANGUAGE plpgsql
AS $procedure$
DECLARE
  sTableSpace VARCHAR := get_temp_tablespace();
  vRec        RECORD;
BEGIN
  --Stef 04.04.2025
  FOR vRec IN (
    SELECT 'CREATE TEMPORARY TABLE if not EXISTS '||tmp_name||E' (\n'||array_to_string(array_agg(col_def ORDER BY col_ord), E',\n')||E'\n) ON COMMIT PRESERVE ROWS'||sTableSpace||';' AS ddl_text
    FROM (
      SELECT tmp_name, col_def, col_ord
      FROM WM_COL_TMP
      WHERE tmp_name IN (SELECT DISTINCT tmp_name FROM WM_FLAG_TMP WHERE Upper(FLAG) = Upper(pflag))
    ) WCT
    GROUP BY tmp_name
  ) LOOP
    BEGIN
      EXECUTE vRec.ddl_text;
    EXCEPTION
      WHEN OTHERS THEN NULL;
    END;
  END LOOP;

  --indecsi la temporare
  FOR vRec IN (
    SELECT idx_def AS ddl_text
    FROM wm_idx_tmp
    WHERE tmp_name IN (SELECT DISTINCT LOWER(tmp_name) FROM WM_FLAG_TMP WHERE Upper(FLAG) = Upper(pflag))
    ORDER BY tmp_name, idx_def
  ) LOOP
    BEGIN
      EXECUTE vRec.ddl_text;
    EXCEPTION
      WHEN OTHERS THEN NULL;
    END;
  END LOOP;
END;
$procedure$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_alerte_updatealertedef</obj_name>
  <obj_hashval>34cfe959a1be880c4368656e2a861f90</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_alerte_updatealertedef(acodalerta numeric, OUT acodalertadef numeric)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 25.09.2025 - fixat 66708
  --Florin 18.09.2025
  aCodAlertaDef := winmadmin.pkg_userfirme_UpdateAlerteDef(aCodAlerta, getFIRMANAME(), aCodAlertaDef);
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_alerte_updateprocdef</obj_name>
  <obj_hashval>a6030b86cae095196abc1c38f23a6157</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_alerte_updateprocdef(acodalerta numeric)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
begin
  --Florin 18.09.2025
  PERFORM winmadmin.pkg_userfirme_UpdateProcDef(aCodAlerta, getFIRMANAME());
end;
$function$
</obj_text>
</row>

<row>
  <obj_type>FUNCTION</obj_type>
  <obj_name>pkg_categconst_estemfsaft</obj_name>
  <obj_hashval>618644b3821019b3cb0333e191bc28c2</obj_hashval>
  <obj_text>CREATE OR REPLACE FUNCTION pkg_categconst_estemfsaft(acodcont numeric)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$
DECLARE
  aSIMBOL     varchar := NULL;
  ESTE        numeric := 0;
  anLunaLucru numeric;
BEGIN
  --Florin 11.11.2025 - sinc. Oracle
  RETURN pkg_categconst_ESTECONTPENTRU(aCODCONT, 'CAMOMIFIXNC');
end;
$function$
</obj_text>
</row>

</table>
