create or replace package pack_sesiune is

  -- Author  : LIANA.MACINIC
  -- Created : 1/6/2005 3:32:39 PM
  -- Purpose :

  -- 30.09.2009
  -- marius.mutu
  -- calculeaza_total_cu_tva, calculeaza_total_fara_tva, calculeaza_total_tva - nvl(V_AJUSTARE,0)

  -- Public type declarations
  V_Schema         varchar2(64);
  dev_idLucrare    number(20);
  dev_idOrdl       number(20);
  dev_idOper       number(20);
  anbal            number(4);
  lunabal          number(2);
  dev_an           number(4);
  dev_luna         number(2);
  an               number(4);
  luna             number(2);
  gest_data_init   date;
  gest_data_final  date;
  sal_idStat       number(10);
  id_prg_owner     syn_nom_programe.id_program%Type;
  id_prg           syn_def_programe.id_prog%Type;
  comenzi_idSectie number(5);

  -- cont            plcont.cont%type;
  cont VARCHAR2(4);

  nIdeROASTART         number(2) := 0;
  nIdeROADEF           number(2) := 1;
  nIdeROACONT          number(2) := 2;
  nIdeROASAL           number(2) := 3;
  nIdeROARES           number(2) := 4;
  nIdeROAGEST          number(2) := 5;
  nIdeROAIMOB          number(2) := 6;
  nIdeROAMANAGER       number(2) := 7;
  nIdeROAAUTO          number(2) := 8;
  nIdeROANOR           number(2) := 9;
  nIdeROADECL          number(2) := 10;
  nIdeROARETAIL        number(2) := 58;
  nID_UTIL             syn_utilizatori.id_util%Type;
  nid_moneda_nationala nom_valute.id_valuta%TYPE;
  nzecimale_pretv      number(2);
  nzecimale_preta      number(2);
  nzecimale_pretaval   number(2);
  nzecimale_pretvval   number(2);
  nzecimale_sumav      number(2);
  nzecimale_sumaa      number(2);
  nzecimale_sumaval    number(2);

  function id_sesiune RETURN NUMBER;
  function get_data_init return date;
  function get_data_final return date;
  procedure set_data_init(tcdata date);
  procedure set_data_final(tcdata date);
  procedure setlunabal(V_LUNA in number);
  procedure setanbal(V_AN in number);
  procedure setLuna(V_LUNA in number);
  procedure setAn(V_AN in number);
  procedure setcont(V_CONT IN varchar2);
  procedure setSchema(v_gcs in varchar2);
  function getlunabal return number;
  function getanbal return number;
  function getluna return number;
  function getan return number;
  function getcont return varchar2;
  function getultimazi return date;
  function getSchema return varchar2;
  PROCEDURE set_data_ron(V_GCS VARCHAR2);
  FUNCTION get_anron RETURN ACT_TEMP.AN%TYPE;
  FUNCTION get_lunaron RETURN ACT_TEMP.LUNA%TYPE;
  FUNCTION suma_ron(TNSUMA NUMBER, TNAN NUMBER, TNLUNA NUMBER) RETURN NUMBER;
  FUNCTION suma_ron(TNSUMA     NUMBER,
                    TNAN       NUMBER,
                    TNLUNA     NUMBER,
                    TNPRECIZIE NUMBER) RETURN NUMBER;
  FUNCTION suma_ron(TNSUMA NUMBER, TDDATA DATE) RETURN NUMBER;
  procedure set_id_stat(tn_id_stat in number);
  function get_id_stat return number;
  FUNCTION getoptiunefirma(tcS IN VARCHAR2, tcOptiune IN VARCHAR2)
    RETURN VARCHAR2;
  FUNCTION getOptiuneFirma(tcOptiune IN VARCHAR2) RETURN VARCHAR2;
  PROCEDURE set_id_prg_owner(tnId_Prg_Owner IN syn_nom_programe.id_program%Type);
  PROCEDURE set_id_prg(tnId_Prg IN syn_def_programe.id_prog%Type);
  FUNCTION get_id_prg_owner return syn_nom_programe.id_program%Type;
  FUNCTION get_id_prg return syn_def_programe.id_prog%Type;
  PROCEDURE set_id_util(tnId_Util IN syn_utilizatori.id_util%Type);
  FUNCTION get_id_util RETURN syn_utilizatori.id_util%Type;
  procedure set_id_sectie_comenzi(tn_id_sectie IN NUMBER);
  function get_id_sectie_comenzi return number;
  function e_mama(tnIdFirma IN NUMBER) return number;
  PROCEDURE SetOptiuneUtilizator(tcVarname  IN OPTIUNI_UTIL.VARNAME%TYPE,
                                 tnIdUtil   OPTIUNI_UTIL.ID_UTIL%TYPE,
                                 tcVarvalue OPTIUNI_UTIL.VARVALUE%TYPE,
                                 tcVardesc  OPTIUNI_UTIL.VARDESC%TYPE := NULL);
  PROCEDURE SetOptiune(tcVarname  IN OPTIUNI.VARNAME%TYPE,
                                 tcVarvalue OPTIUNI.VARVALUE%TYPE,
                                 tcVarType  OPTIUNI.VARTYPE%TYPE DEFAULT 'CHARACTER',
                                 tcVardesc  OPTIUNI.VARDESC%TYPE DEFAULT NULL);

  PROCEDURE SetOptiune2(tcVarname  IN OPTIUNI.VARNAME%TYPE,
                                 tcVarvalue OPTIUNI.VARVALUE2%TYPE,
                                 tcVarType  OPTIUNI.VARTYPE%TYPE DEFAULT 'CHARACTER',
                                 tcVardesc  OPTIUNI.VARDESC%TYPE DEFAULT NULL);

  function calculeaza_pret_fara_tva(V_PRET_UNITAR  IN NUMBER,
                                    V_CURS         IN NUMBER,
                                    V_ID_VALUTA    IN NUMBER,
                                    V_PROC_TVA     IN NUMBER,
                                    V_PRET_ARE_TVA IN NUMBER,
                                    V_TIP          IN NUMBER) return number;

  function calculeaza_pret_TVA(V_PRET_UNITAR  IN NUMBER,
                               V_CURS         IN NUMBER,
                               V_ID_VALUTA    IN NUMBER,
                               V_PROC_TVA     IN NUMBER,
                               V_PRET_ARE_TVA IN NUMBER,
                               V_TIP          IN NUMBER) return number;

  function calculeaza_pret_cu_tva(V_PRET_UNITAR  IN NUMBER,
                                  V_CURS         IN NUMBER,
                                  V_ID_VALUTA    IN NUMBER,
                                  V_PROC_TVA     IN NUMBER,
                                  V_PRET_ARE_TVA IN NUMBER,
                                  V_TIP          IN NUMBER) return number;

  function converteste_pret_fara_tva(V_PRET_UNITAR  IN NUMBER,
                                     V_CURS         IN NUMBER,
                                     V_ID_VALUTA    IN NUMBER,
                                     V_PROC_TVA     IN NUMBER,
                                     V_PRET_ARE_TVA IN NUMBER,
                                     V_TIP          IN NUMBER) return number;

  function converteste_pret_TVA(V_PRET_UNITAR  IN NUMBER,
                                V_CURS         IN NUMBER,
                                V_ID_VALUTA    IN NUMBER,
                                V_PROC_TVA     IN NUMBER,
                                V_PRET_ARE_TVA IN NUMBER,
                                V_TIP          IN NUMBER) return number;

  function converteste_pret_cu_tva(V_PRET_UNITAR  IN NUMBER,
                                   V_CURS         IN NUMBER,
                                   V_ID_VALUTA    IN NUMBER,
                                   V_PROC_TVA     IN NUMBER,
                                   V_PRET_ARE_TVA IN NUMBER,
                                   V_TIP          IN NUMBER) return number;

  FUNCTION calculeaza_total_cu_tva(V_PRET                IN NUMBER,
                                   V_AJUSTARE            IN NUMBER,
                                   V_CURS                IN NUMBER,
                                   V_DISCOUNT_UNITAR     IN NUMBER,
                                   V_DISCOUNT_EVIDENTIAT IN NUMBER,
                                   V_CANTITATE           IN NUMBER,
                                   V_PRET_CU_TVA         IN NUMBER,
                                   V_PROC_TVAV           IN NUMBER,
                                   V_ZECIMALE_PRET       IN NUMBER,
                                   V_ZECIMALE_SUMA       IN NUMBER)
    return number;

  FUNCTION calculeaza_total_fara_tva(V_PRET                IN NUMBER,
                                     V_AJUSTARE            IN NUMBER,
                                     V_CURS                IN NUMBER,
                                     V_DISCOUNT_UNITAR     IN NUMBER,
                                     V_DISCOUNT_EVIDENTIAT IN NUMBER,
                                     V_CANTITATE           IN NUMBER,
                                     V_PRET_CU_TVA         IN NUMBER,
                                     V_PROC_TVAV           IN NUMBER,
                                     V_ZECIMALE_PRET       IN NUMBER,
                                     V_ZECIMALE_SUMA       IN NUMBER)
    return number;

  FUNCTION calculeaza_total_tva(V_PRET                IN NUMBER,
                                V_AJUSTARE            IN NUMBER,
                                V_CURS                IN NUMBER,
                                V_DISCOUNT_UNITAR     IN NUMBER,
                                V_DISCOUNT_EVIDENTIAT IN NUMBER,
                                V_CANTITATE           IN NUMBER,
                                V_PRET_CU_TVA         IN NUMBER,
                                V_PROC_TVAV           IN NUMBER,
                                V_ZECIMALE_PRET       IN NUMBER,
                                V_ZECIMALE_SUMA       IN NUMBER)
    return number;

  function tva2proctva(V_TVA  IN ACT.SUMA%TYPE,
                       V_PRET IN ACT.SUMA%TYPE,
                       V_AN   IN ACT.AN%TYPE,
                       V_LUNA IN ACT.LUNA%TYPE) RETURN ACT.PROC_TVA%TYPE;

  function tva2proctva(V_TVA IN ACT.SUMA%TYPE, V_PRET IN ACT.SUMA%TYPE)
    RETURN ACT.PROC_TVA%TYPE;

  FUNCTION verifica_acces(V_TABELA     IN VARCHAR2,
                          V_ID         IN NUMBER,
                          V_MINUTE_MAX IN NUMBER) RETURN VARCHAR2;

  FUNCTION verifica_acces(V_TABELA     IN VARCHAR2,
                          V_ID         IN NUMBER,
                          V_MINUTE_MAX IN NUMBER,
                          V_TIP        IN NUMBER) RETURN VARCHAR2;

  PROCEDURE blocheaza_acces(V_TABELA     IN VARCHAR2,
                            V_ID         IN NUMBER,
                            V_MINUTE_MAX IN NUMBER);

  PROCEDURE deblocheaza_acces(V_SID IN NUMBER);

  PROCEDURE deblocheaza_acces(V_TABELA IN VARCHAR2, V_ID IN NUMBER);

  PROCEDURE deblocheaza_acces_expirat(V_TABELA IN VARCHAR2, V_ID IN NUMBER);
end pack_sesiune;
/
create or replace package body pack_sesiune is

 -- 17.03.2016
 -- marius.mutu
 -- tva2proctva - s-a calculat si procent tva 5% din raportul tva/pret,
 -- la 5% aparea cota standard ex: 20% 2016

 -- 18.10.2016
 -- marius.mutu
 -- + SetOptiune

 -- 13.11.2020
 -- marius.mutu
 -- + SetOptiune2 (salveaza in optiuni.varvalue2 clob in loc de optiuni.varvalue varchar2)

  FUNCTION id_sesiune RETURN NUMBER IS
    V_RETURN NUMBER(20) := 0;
  BEGIN
    V_RETURN := DEV_IDLUCRARE;
    RETURN V_RETURN;
  END;

  FUNCTION get_data_init RETURN date IS
  BEGIN

    return gest_data_init;
  END;

  FUNCTION get_data_final RETURN date IS
  BEGIN

    return gest_data_final;
  END;

  procedure set_data_init(tcdata in date) is

    lcdata date := tcdata;
  begin
    gest_data_init := lcdata;
  end;

  procedure set_data_final(tcdata in date) is

    lcdata date := tcdata;
  begin
    gest_data_final := lcdata;
  end;
  ------------------------------------------------------------------
  procedure setlunabal(V_LUNA IN NUMBER) is
  begin
    lunabal := V_LUNA;
  end;
  ------------------------------------------------------------------
  procedure setanbal(V_AN IN NUMBER) is
  begin
    anbal := V_AN;
  end;
  ------------------------------------------------------------------
  procedure setluna(V_LUNA IN NUMBER) is
  begin
    dev_luna := V_LUNA;
    luna     := V_LUNA;
  end;
  ------------------------------------------------------------------
  procedure setan(V_AN IN NUMBER) is
  begin
    dev_an := V_AN;
    an     := V_AN;
  end;
  ------------------------------------------------------------------
  procedure setcont(V_CONT IN varchar2) is
  begin
    cont := V_CONT;
  end;
  ------------------------------------------------------------------
  procedure setschema(V_gcs IN varchar2) is
  begin
    V_schema := v_gcs;
  end;
  ------------------------------------------------------------------
  function getlunabal return number is
  begin
    return lunabal;
  end;
  ------------------------------------------------------------------
  function getanbal return number is
  begin
    return anbal;
  end;
  ------------------------------------------------------------------
  function getluna return number is
  begin
    return dev_luna;
  end;
  ------------------------------------------------------------------
  function getan return number is
  begin
    return dev_an;
  end;
  ------------------------------------------------------------------
  function getcont return varchar2 is
  begin
    return cont;
  end;
  ------------------------------------------------------------------
  function getultimazi return date is
  begin
    return last_day(to_date(dev_an || '/' || dev_luna || '/01',
                            'YYYY/MM/DD'));
  end;

  ---------------------------------------------------------------
  function getschema return varchar2 is
  begin
    return v_schema;
  end;

  ---------------------------------------------------------------
  FUNCTION getoptiunefirma(tcS IN VARCHAR2, tcOptiune IN VARCHAR2)
    RETURN VARCHAR2 IS
    lcValue Optiuni.Varvalue%Type := '';
  BEGIN
    BEGIN
      select varvalue
        INTO lcValue
        from optiuni
       where UPPER(TRIM(VARNAME)) = UPPER(TRIM(tcOptiune));
    EXCEPTION
      WHEN OTHERS THEN
        lcValue := '';
    END;
    RETURN lcValue;
  END;

  ---------------------------------------------------------------
  FUNCTION getOptiuneFirma(tcOptiune IN VARCHAR2) RETURN VARCHAR2 IS
    lcValue Optiuni.Varvalue%Type := '';
  BEGIN
    lcValue := getOptiuneFirma(user, tcOptiune);
    return lcValue;
  END;

  ---------------------------------------------------------------
  PROCEDURE set_data_ron(V_GCS VARCHAR2) IS
    lcDataRon varchar2(50);

  BEGIN
    execute immediate 'SELECT varvalue from ' || V_GCS ||
                      '.optiuni where upper(varname) = ''DATARON'''
      into lcDataRon;
    if lcDataRon is not null then
      pack_contafin.nAnRON   := to_number(substr(lcDataRon, 4, 4));
      pack_contafin.nLunaRON := to_number(substr(lcDataRon, 1, 2));
    else
      pack_contafin.nAnRON   := 2005;
      pack_contafin.nLunaRON := 7;
    end if;
  END;

  ---------------------------------------------------------------
  FUNCTION get_anron RETURN ACT_TEMP.AN%TYPE IS
  BEGIN
    return pack_contafin.nAnRON;
  END GET_ANRON;

  ---------------------------------------------------------------

  FUNCTION get_lunaron RETURN ACT_TEMP.LUNA%TYPE IS
  BEGIN
    return pack_contafin.nLunaRon;
  END GET_LUNARON;

  ---------------------------------------------------------------

  FUNCTION suma_ron(TNSUMA NUMBER, TNAN NUMBER, TNLUNA NUMBER) RETURN NUMBER IS

  BEGIN

    IF (tnluna + tnan * 12 <
       pack_sesiune.GET_ANRON() * 12 + pack_sesiune.GET_LUNARON()) AND
       (pack_sesiune.getAn() * 12 + pack_sesiune.getLuna() >=
       pack_sesiune.GET_ANRON() * 12 + pack_sesiune.GET_LUNARON()) THEN
      RETURN NVL(TNSUMA, 0) / 10000;
    ELSE
      RETURN NVL(TNSUMA, 0);
    END IF;

  END SUMA_RON;

  ---------------------------------------------------------------

  FUNCTION suma_ron(TNSUMA     NUMBER,
                    TNAN       NUMBER,
                    TNLUNA     NUMBER,
                    TNPRECIZIE NUMBER) RETURN NUMBER IS

  BEGIN

    IF (tnluna + tnan * 12 <
       pack_sesiune.GET_ANRON() * 12 + pack_sesiune.GET_LUNARON()) AND
       (pack_sesiune.getAn() * 12 + pack_sesiune.getLuna() >=
       pack_sesiune.GET_ANRON() * 12 + pack_sesiune.GET_LUNARON()) THEN
      RETURN round(NVL(TNSUMA, 0) / 10000, TNPRECIZIE);
    ELSE
      RETURN ROUND(NVL(TNSUMA, 0), TNPRECIZIE);
    END IF;

  END SUMA_RON;
  ----------------------------
  FUNCTION suma_ron(TNSUMA NUMBER, TDDATA DATE) RETURN NUMBER IS
    lnAn   number(4);
    lnLuna number(2);
  BEGIN
    lnAn   := extract(year from TDDATA);
    lnLuna := extract(month from TDDATA);
    RETURN pack_sesiune.suma_ron(TNSUMA, LNAN, LNLUNA);

  END SUMA_RON;
  ----------------------------
  procedure set_id_stat(tn_id_stat IN NUMBER) is
  begin
    sal_idStat := tn_id_stat;
  end;
  -----------------------------------
  function get_id_stat return number is
  begin
    return sal_idStat;
  end;
  -----------------------------------
  PROCEDURE set_id_prg_owner(tnId_Prg_Owner IN syn_nom_programe.id_program%Type) IS
  BEGIN
    id_prg_owner := tnId_Prg_Owner;
  END set_id_prg_owner;
  -----------------------------------
  PROCEDURE set_id_prg(tnId_Prg IN syn_def_programe.id_prog%Type) IS
  BEGIN
    id_prg := tnId_Prg;
  END set_id_prg;
  -----------------------------------
  FUNCTION get_id_prg_owner return syn_nom_programe.id_program%Type IS
  BEGIN
    RETURN id_prg_owner;
  END get_id_prg_owner;
  -----------------------------------
  FUNCTION get_id_prg return syn_def_programe.id_prog%Type IS
  BEGIN
    RETURN id_prg;
  END get_id_prg;
  -----------------------------------
  -----------------------------------
  PROCEDURE set_id_util(tnId_Util IN syn_utilizatori.id_util%Type) IS
    v_utilizator syn_vutilizatori.UTILIZATOR%type;
  BEGIN
    nId_Util := tnId_Util;
    begin
      SELECT UTILIZATOR
        INTO v_utilizator
        FROM syn_vutilizatori
       WHERE ID_UTIL = tnId_Util
         AND INACTIV = 0;
    exception
      when NO_DATA_FOUND then
        v_utilizator := '';
    end;
    dbms_session.set_identifier(v_utilizator);
  END set_id_util;
  -----------------------------------
  FUNCTION get_id_util RETURN syn_utilizatori.id_util%Type IS
  BEGIN
    RETURN nId_Util;
  END get_id_util;
  -----------------------------------
  procedure set_id_sectie_comenzi(tn_id_sectie IN NUMBER) is
  begin
    comenzi_idSectie := tn_id_sectie;
  end;
  -----------------------------------
  function get_id_sectie_comenzi return number is
  begin
    return comenzi_idSectie;
  end;
  -----------------------------------
  function e_mama(tnIdFirma IN NUMBER) return number is
    V_E_MAMA NUMBER(1) := 0;
  begin
    if tnIdFirma IS NOT NULL then
      V_E_MAMA := 0;
    else
      select max(NVL(e_mama, 0))
        into V_E_MAMA
        from syn_nom_firme
       where schema = USER;
    end if;

    return v_e_mama;
  end;
  -----------------------------------
  PROCEDURE SetOptiuneUtilizator(tcVarname  IN OPTIUNI_UTIL.VARNAME%TYPE,
                                 tnIdUtil   OPTIUNI_UTIL.ID_UTIL%TYPE,
                                 tcVarvalue OPTIUNI_UTIL.VARVALUE%TYPE,
                                 tcVardesc  OPTIUNI_UTIL.VARDESC%TYPE := NULL) IS

  BEGIN

    MERGE INTO optiuni_util
    USING dual
    on (upper(varname) = upper(tcVarname) and id_util = tnIdUtil)
    WHEN MATCHED THEN
      UPDATE SET varvalue = tcVarvalue
    WHEN NOT MATCHED THEN
      INSERT
        (varname, id_util, vardesc, varvalue)
      VALUES
        (upper(tcVarname), tnIdUtil, tcVardesc, tcVarvalue);

  END SetOptiuneUtilizator;
  -----------------------------------
  PROCEDURE SetOptiune(tcVarname  IN OPTIUNI.VARNAME%TYPE,
                                 tcVarvalue OPTIUNI.VARVALUE%TYPE,
                                 tcVarType  OPTIUNI.VARTYPE%TYPE DEFAULT 'CHARACTER',
                                 tcVardesc  OPTIUNI.VARDESC%TYPE DEFAULT NULL) IS

  BEGIN

    MERGE INTO optiuni
    USING dual
    on (upper(varname) = upper(tcVarname))
    WHEN MATCHED THEN
      UPDATE SET varvalue = tcVarvalue
    WHEN NOT MATCHED THEN
      INSERT
        (varname, varvalue, vartype, vardesc)
      VALUES
        (upper(tcVarname), tcVarvalue, tcVarType, tcVardesc);

  END SetOptiune;

  ----------------------------------------------------------------------------
  PROCEDURE SetOptiune2(tcVarname  IN OPTIUNI.VARNAME%TYPE,
                                 tcVarvalue OPTIUNI.VARVALUE2%TYPE,
                                 tcVarType  OPTIUNI.VARTYPE%TYPE DEFAULT 'CHARACTER',
                                 tcVardesc  OPTIUNI.VARDESC%TYPE DEFAULT NULL) IS
  BEGIN
    MERGE INTO optiuni
    USING dual
    on (upper(varname) = upper(tcVarname))
    WHEN MATCHED THEN
      UPDATE SET varvalue2 = tcVarvalue
    WHEN NOT MATCHED THEN
      INSERT
        (varname, varvalue2, vartype, vardesc)
      VALUES
        (upper(tcVarname), tcVarvalue, tcVarType, tcVardesc);

  END SetOptiune2;

  ----------------------------------------------------------------------------
  function calculeaza_pret_fara_tva(V_PRET_UNITAR  IN NUMBER,
                                    V_CURS         IN NUMBER,
                                    V_ID_VALUTA    IN NUMBER,
                                    V_PROC_TVA     IN NUMBER,
                                    V_PRET_ARE_TVA IN NUMBER,
                                    V_TIP          IN NUMBER) return number IS
    V_PRET_FARA_TVA number := 0;
    V_ZECIMALE      number(2);
    V_ZECIMALEVAL   number(2);
  BEGIN
    IF V_TIP = 1 THEN
      -- achizitie
      V_ZECIMALE    := pack_sesiune.nzecimale_preta;
      V_ZECIMALEVAL := pack_sesiune.nzecimale_pretaval;
    ELSE
      -- vanzare
      V_ZECIMALE    := pack_sesiune.nzecimale_pretv;
      V_ZECIMALEVAL := pack_sesiune.nzecimale_pretvval;
    END IF;
    IF V_PRET_ARE_TVA = 0 THEN
      -- pretul de referinta este fara tva
      IF NVL(V_ID_VALUTA, pack_sesiune.nid_moneda_nationala) <>
         pack_sesiune.nid_moneda_nationala THEN
        -- pretul este in valuta
        V_PRET_FARA_TVA := ROUND(V_CURS *
                                 ROUND(V_PRET_UNITAR, V_ZECIMALEVAL),
                                 V_ZECIMALE);
      ELSE
        V_PRET_FARA_TVA := ROUND(V_PRET_UNITAR, V_ZECIMALE);
      END IF;
    ELSE
      -- pretul de referinta este cu tva
      V_PRET_FARA_TVA := ROUND(calculeaza_pret_cu_tva(v_pret_unitar,
                                                      v_curs,
                                                      v_id_valuta,
                                                      v_proc_tva,
                                                      v_pret_are_tva,
                                                      v_tip)

                               / V_PROC_TVA,
                               V_ZECIMALE);
    END IF;
    return V_PRET_FARA_TVA;
  END calculeaza_pret_fara_tva;
  ----------------------------------------------------------------------------
  function calculeaza_pret_TVA(V_PRET_UNITAR  IN NUMBER,
                               V_CURS         IN NUMBER,
                               V_ID_VALUTA    IN NUMBER,
                               V_PROC_TVA     IN NUMBER,
                               V_PRET_ARE_TVA IN NUMBER,
                               V_TIP          IN NUMBER) return NUMBER IS
    V_PRET_TVA    number := 0;
    V_ZECIMALE    number(2);
    V_ZECIMALEVAL number(2);
  BEGIN
    IF V_TIP = 1 THEN
      -- achizitie
      V_ZECIMALE    := pack_sesiune.nzecimale_preta;
      V_ZECIMALEVAL := pack_sesiune.nzecimale_pretaval;
    ELSE
      -- vanzare
      V_ZECIMALE    := pack_sesiune.nzecimale_pretv;
      V_ZECIMALEVAL := pack_sesiune.nzecimale_pretvval;
    END IF;
    IF V_PRET_ARE_TVA = 0 THEN
      -- pretul de referinta este fara tva
      V_PRET_TVA := ROUND(pack_sesiune.calculeaza_pret_fara_tva(v_pret_unitar,
                                                                v_curs,
                                                                v_id_valuta,
                                                                v_proc_tva,
                                                                v_pret_are_tva,
                                                                v_tip) *
                          (V_PROC_TVA - 1),
                          V_ZECIMALE);
    ELSE
      -- pretul de referinta este cu tva
      V_PRET_TVA := pack_sesiune.calculeaza_pret_cu_tva(v_pret_unitar,
                                                        v_curs,
                                                        v_id_valuta,
                                                        v_proc_tva,
                                                        v_pret_are_tva,
                                                        v_tip) -
                    pack_sesiune.calculeaza_pret_fara_tva(v_pret_unitar,
                                                          v_curs,
                                                          v_id_valuta,
                                                          v_proc_tva,
                                                          v_pret_are_tva,
                                                          v_tip);
    END IF;
    return V_PRET_TVA;
  END calculeaza_pret_TVA;
  ----------------------------------------------------------------------------
  function calculeaza_pret_cu_tva(V_PRET_UNITAR  IN NUMBER,
                                  V_CURS         IN NUMBER,
                                  V_ID_VALUTA    IN NUMBER,
                                  V_PROC_TVA     IN NUMBER,
                                  V_PRET_ARE_TVA IN NUMBER,
                                  V_TIP          IN NUMBER) RETURN NUMBER IS
    V_PRET_CU_TVA number := 0;
    V_ZECIMALE    number(2);
    V_ZECIMALEVAL number(2);
  BEGIN
    IF V_TIP = 1 THEN
      -- achizitie
      V_ZECIMALE    := pack_sesiune.nzecimale_preta;
      V_ZECIMALEVAL := pack_sesiune.nzecimale_pretaval;
    ELSE
      -- vanzare
      V_ZECIMALE    := pack_sesiune.nzecimale_pretv;
      V_ZECIMALEVAL := pack_sesiune.nzecimale_pretvval;
    END IF;
    IF V_PRET_ARE_TVA = 0 THEN
      V_PRET_CU_TVA := pack_sesiune.calculeaza_pret_fara_tva(v_pret_unitar,
                                                             v_curs,
                                                             v_id_valuta,
                                                             v_proc_tva,
                                                             v_pret_are_tva,
                                                             v_tip) +
                       pack_sesiune.calculeaza_pret_tva(v_pret_unitar,
                                                        v_curs,
                                                        v_id_valuta,
                                                        v_proc_tva,
                                                        v_pret_are_tva,
                                                        v_tip);
    ELSE
      -- pretul de referinta este cu tva
      IF NVL(V_ID_VALUTA, pack_sesiune.nid_moneda_nationala) <>
         pack_sesiune.nid_moneda_nationala THEN
        -- pretul este in valuta
        V_PRET_CU_TVA := ROUND(V_CURS * ROUND(V_PRET_UNITAR, V_ZECIMALEVAL),
                               V_ZECIMALE);
      ELSE
        V_PRET_CU_TVA := ROUND(V_PRET_UNITAR, V_ZECIMALE);
      END IF;
    END IF;
    return V_PRET_CU_TVA;
  end calculeaza_pret_cu_tva;
  ----------------------------------------------------------------------------
  function converteste_pret_fara_tva(V_PRET_UNITAR  IN NUMBER,
                                     V_CURS         IN NUMBER,
                                     V_ID_VALUTA    IN NUMBER,
                                     V_PROC_TVA     IN NUMBER,
                                     V_PRET_ARE_TVA IN NUMBER,
                                     V_TIP          IN NUMBER) return number IS
    V_PRET_FARA_TVA number := 0;
    V_ZECIMALE      number(2);
    V_ZECIMALEVAL   number(2);
  BEGIN
    IF V_TIP = 1 THEN
      -- achizitie
      V_ZECIMALE    := pack_sesiune.nzecimale_preta;
      V_ZECIMALEVAL := pack_sesiune.nzecimale_pretaval;
    ELSE
      -- vanzare
      V_ZECIMALE    := pack_sesiune.nzecimale_pretv;
      V_ZECIMALEVAL := pack_sesiune.nzecimale_pretvval;
    END IF;
    IF V_PRET_ARE_TVA = 0 THEN
      -- pretul de referinta este fara tva
      IF NVL(V_ID_VALUTA, pack_sesiune.nid_moneda_nationala) <>
         pack_sesiune.nid_moneda_nationala THEN
        -- pretul este in valuta
        V_PRET_FARA_TVA := ROUND(ROUND(V_PRET_UNITAR, V_ZECIMALE) / V_CURS,
                                 V_ZECIMALEVAL);
      ELSE
        V_PRET_FARA_TVA := ROUND(V_PRET_UNITAR, V_ZECIMALE);
      END IF;
    ELSE
      -- pretul de referinta este cu tva
      V_PRET_FARA_TVA := ROUND(pack_sesiune.converteste_pret_cu_tva(v_pret_unitar,
                                                                    v_curs,
                                                                    v_id_valuta,
                                                                    v_proc_tva,
                                                                    v_pret_are_tva,
                                                                    v_tip)

                               / V_PROC_TVA,
                               (CASE
                                 WHEN NVL(V_ID_VALUTA,
                                          pack_sesiune.nid_moneda_nationala) <>
                                      pack_sesiune.nid_moneda_nationala THEN
                                  V_ZECIMALEVAL
                                 ELSE
                                  V_ZECIMALE
                               END));
    END IF;
    return V_PRET_FARA_TVA;
  END converteste_pret_fara_tva;
  ----------------------------------------------------------------------------
  function converteste_pret_TVA(V_PRET_UNITAR  IN NUMBER,
                                V_CURS         IN NUMBER,
                                V_ID_VALUTA    IN NUMBER,
                                V_PROC_TVA     IN NUMBER,
                                V_PRET_ARE_TVA IN NUMBER,
                                V_TIP          IN NUMBER) return NUMBER IS
    V_PRET_TVA    number := 0;
    V_ZECIMALE    number(2);
    V_ZECIMALEVAL number(2);
  BEGIN
    IF V_TIP = 1 THEN
      -- achizitie
      V_ZECIMALE    := pack_sesiune.nzecimale_preta;
      V_ZECIMALEVAL := pack_sesiune.nzecimale_pretaval;
    ELSE
      -- vanzare
      V_ZECIMALE    := pack_sesiune.nzecimale_pretv;
      V_ZECIMALEVAL := pack_sesiune.nzecimale_pretvval;
    END IF;
    IF V_PRET_ARE_TVA = 0 THEN
      -- pretul de referinta este fara tva
      V_PRET_TVA := ROUND(pack_sesiune.converteste_pret_fara_tva(v_pret_unitar,
                                                                 v_curs,
                                                                 v_id_valuta,
                                                                 v_proc_tva,
                                                                 v_pret_are_tva,
                                                                 v_tip) *
                          (V_PROC_TVA - 1),
                          (CASE
                            WHEN NVL(V_ID_VALUTA, pack_sesiune.nid_moneda_nationala) <>
                                 pack_sesiune.nid_moneda_nationala THEN
                             V_ZECIMALEVAL
                            ELSE
                             V_ZECIMALE
                          END));
    ELSE
      -- pretul de referinta este cu tva
      V_PRET_TVA := pack_sesiune.converteste_pret_cu_tva(v_pret_unitar,
                                                         v_curs,
                                                         v_id_valuta,
                                                         v_proc_tva,
                                                         v_pret_are_tva,
                                                         v_tip) -
                    pack_sesiune.converteste_pret_fara_tva(v_pret_unitar,
                                                           v_curs,
                                                           v_id_valuta,
                                                           v_proc_tva,
                                                           v_pret_are_tva,
                                                           v_tip);
    END IF;
    return V_PRET_TVA;
  END converteste_pret_TVA;
  ----------------------------------------------------------------------------
  function converteste_pret_cu_tva(V_PRET_UNITAR  IN NUMBER,
                                   V_CURS         IN NUMBER,
                                   V_ID_VALUTA    IN NUMBER,
                                   V_PROC_TVA     IN NUMBER,
                                   V_PRET_ARE_TVA IN NUMBER,
                                   V_TIP          IN NUMBER) RETURN NUMBER IS
    V_PRET_CU_TVA number := 0;
    V_ZECIMALE    number(2);
    V_ZECIMALEVAL number(2);
  BEGIN
    IF V_TIP = 1 THEN
      -- achizitie
      V_ZECIMALE    := pack_sesiune.nzecimale_preta;
      V_ZECIMALEVAL := pack_sesiune.nzecimale_pretaval;
    ELSE
      -- vanzare
      V_ZECIMALE    := pack_sesiune.nzecimale_pretv;
      V_ZECIMALEVAL := pack_sesiune.nzecimale_pretvval;
    END IF;
    IF V_PRET_ARE_TVA = 0 THEN
      V_PRET_CU_TVA := pack_sesiune.converteste_pret_fara_tva(v_pret_unitar,
                                                              v_curs,
                                                              v_id_valuta,
                                                              v_proc_tva,
                                                              v_pret_are_tva,
                                                              v_tip) +
                       pack_sesiune.converteste_pret_tva(v_pret_unitar,
                                                         v_curs,
                                                         v_id_valuta,
                                                         v_proc_tva,
                                                         v_pret_are_tva,
                                                         v_tip);
    ELSE
      -- pretul de referinta este cu tva
      IF NVL(V_ID_VALUTA, pack_sesiune.nid_moneda_nationala) <>
         pack_sesiune.nid_moneda_nationala THEN
        -- pretul este in valuta
        V_PRET_CU_TVA := ROUND(ROUND(V_PRET_UNITAR, V_ZECIMALE) / V_CURS,
                               V_ZECIMALEVAL);
      ELSE
        V_PRET_CU_TVA := ROUND(V_PRET_UNITAR, V_ZECIMALE);
      END IF;
    END IF;
    return V_PRET_CU_TVA;
  end converteste_pret_cu_tva;
  ----------------------------------------------------------------------------
  FUNCTION calculeaza_total_cu_tva(V_PRET                IN NUMBER,
                                   V_AJUSTARE            IN NUMBER,
                                   V_CURS                IN NUMBER,
                                   V_DISCOUNT_UNITAR     IN NUMBER,
                                   V_DISCOUNT_EVIDENTIAT IN NUMBER,
                                   V_CANTITATE           IN NUMBER,
                                   V_PRET_CU_TVA         IN NUMBER,
                                   V_PROC_TVAV           IN NUMBER,
                                   V_ZECIMALE_PRET       IN NUMBER,
                                   V_ZECIMALE_SUMA       IN NUMBER)
    RETURN NUMBER IS
    V_SUMA_CU_TVA  ACT.SUMA%TYPE;
    V_ZECIMALEPRET NUMBER(1) := NVL(V_ZECIMALE_PRET,
                                    pack_sesiune.nzecimale_pretv);
    V_ZECIMALESUMA NUMBER(1) := NVL(V_ZECIMALE_SUMA,
                                    pack_sesiune.nzecimale_sumav);
  BEGIN
    IF V_PRET_CU_TVA = 1 THEN
      IF V_DISCOUNT_EVIDENTIAT = 1 THEN
        V_SUMA_CU_TVA := ROUND((ROUND(NVL(V_CURS, 1) * V_PRET,
                                      V_ZECIMALEPRET) +
                               ROUND(NVL(V_AJUSTARE, 0) * V_PROC_TVAV,
                                      V_ZECIMALEPRET)) * V_CANTITATE,
                               V_ZECIMALESUMA) -
                         ROUND(ROUND(NVL(V_CURS, 1) *
                                     NVL(V_DISCOUNT_UNITAR, 0),
                                     V_ZECIMALEPRET) * V_CANTITATE,
                               V_ZECIMALESUMA);
      ELSE
        V_SUMA_CU_TVA := ROUND((ROUND(NVL(V_CURS, 1) *
                                      ROUND(V_PRET, V_ZECIMALEPRET),
                                      V_ZECIMALEPRET) -
                               ROUND(NVL(V_CURS, 1) *
                                      ROUND(NVL(V_DISCOUNT_UNITAR, 0),
                                            V_ZECIMALEPRET),
                                      V_ZECIMALEPRET) +
                               ROUND(NVL(V_AJUSTARE, 0) * V_PROC_TVAV,
                                      V_ZECIMALEPRET)) * V_CANTITATE,
                               V_ZECIMALESUMA);
      END IF;
    ELSE
      V_SUMA_CU_TVA := pack_sesiune.calculeaza_total_fara_tva(V_PRET,
                                                              V_AJUSTARE,
                                                              V_CURS,
                                                              V_DISCOUNT_UNITAR,
                                                              V_DISCOUNT_EVIDENTIAT,
                                                              V_CANTITATE,
                                                              V_PRET_CU_TVA,
                                                              V_PROC_TVAV,
                                                              V_ZECIMALEPRET,
                                                              V_ZECIMALESUMA) +
                       pack_sesiune.calculeaza_total_tva(V_PRET,
                                                         V_AJUSTARE,
                                                         V_CURS,
                                                         V_DISCOUNT_UNITAR,
                                                         V_DISCOUNT_EVIDENTIAT,
                                                         V_CANTITATE,
                                                         V_PRET_CU_TVA,
                                                         V_PROC_TVAV,
                                                         V_ZECIMALEPRET,
                                                         V_ZECIMALESUMA);
    END IF;
    RETURN V_SUMA_CU_TVA;
  END calculeaza_total_cu_tva;
  ----------------------------------------------------------------------------
  FUNCTION calculeaza_total_fara_tva(V_PRET                IN NUMBER,
                                     V_AJUSTARE            IN NUMBER,
                                     V_CURS                IN NUMBER,
                                     V_DISCOUNT_UNITAR     IN NUMBER,
                                     V_DISCOUNT_EVIDENTIAT IN NUMBER,
                                     V_CANTITATE           IN NUMBER,
                                     V_PRET_CU_TVA         IN NUMBER,
                                     V_PROC_TVAV           IN NUMBER,
                                     V_ZECIMALE_PRET       IN NUMBER,
                                     V_ZECIMALE_SUMA       IN NUMBER)
    RETURN NUMBER IS
    V_SUMA_FARA_TVA ACT.SUMA%TYPE;
    V_ZECIMALEPRET  NUMBER(1) := NVL(V_ZECIMALE_PRET,
                                     pack_sesiune.nzecimale_pretv);
    V_ZECIMALESUMA  NUMBER(1) := NVL(V_ZECIMALE_SUMA,
                                     pack_sesiune.nzecimale_sumav);
  BEGIN
    IF V_PRET_CU_TVA = 1 THEN
      V_SUMA_FARA_TVA := pack_sesiune.calculeaza_total_cu_tva(V_PRET,
                                                              V_AJUSTARE,
                                                              V_CURS,
                                                              V_DISCOUNT_UNITAR,
                                                              V_DISCOUNT_EVIDENTIAT,
                                                              V_CANTITATE,
                                                              V_PRET_CU_TVA,
                                                              V_PROC_TVAV,
                                                              V_ZECIMALEPRET,
                                                              V_ZECIMALESUMA) -
                         pack_sesiune.calculeaza_total_tva(V_PRET,
                                                           V_AJUSTARE,
                                                           V_CURS,
                                                           V_DISCOUNT_UNITAR,
                                                           V_DISCOUNT_EVIDENTIAT,
                                                           V_CANTITATE,
                                                           V_PRET_CU_TVA,
                                                           V_PROC_TVAV,
                                                           V_ZECIMALEPRET,
                                                           V_ZECIMALESUMA);
    ELSE
      IF V_DISCOUNT_EVIDENTIAT = 1 THEN
        V_SUMA_FARA_TVA := ROUND((ROUND(NVL(V_CURS, 1) * V_PRET,
                                        V_ZECIMALEPRET) +
                                 NVL(V_AJUSTARE, 0)) * V_CANTITATE,
                                 V_ZECIMALESUMA) -
                           ROUND(ROUND(NVL(V_CURS, 1) *
                                       NVL(V_DISCOUNT_UNITAR, 0),
                                       V_ZECIMALEPRET) * V_CANTITATE,
                                 V_ZECIMALESUMA);
      ELSE
        V_SUMA_FARA_TVA := ROUND((ROUND(NVL(V_CURS, 1) *
                                        ROUND(V_PRET, V_ZECIMALEPRET),
                                        V_ZECIMALEPRET) -
                                 ROUND(NVL(V_CURS, 1) *
                                        ROUND(NVL(V_DISCOUNT_UNITAR, 0),
                                              V_ZECIMALEPRET),
                                        V_ZECIMALEPRET) +
                                 NVL(V_AJUSTARE, 0)) * V_CANTITATE,
                                 V_ZECIMALESUMA);
      END IF;
    END IF;
    RETURN V_SUMA_FARA_TVA;
  END calculeaza_total_fara_tva;
  ----------------------------------------------------------------------------
  FUNCTION calculeaza_total_tva(V_PRET                IN NUMBER,
                                V_AJUSTARE            IN NUMBER,
                                V_CURS                IN NUMBER,
                                V_DISCOUNT_UNITAR     IN NUMBER,
                                V_DISCOUNT_EVIDENTIAT IN NUMBER,
                                V_CANTITATE           IN NUMBER,
                                V_PRET_CU_TVA         IN NUMBER,
                                V_PROC_TVAV           IN NUMBER,
                                V_ZECIMALE_PRET       IN NUMBER,
                                V_ZECIMALE_SUMA       IN NUMBER)
    RETURN NUMBER IS
    V_SUMA_TVA     ACT.SUMA%TYPE;
    V_ZECIMALEPRET NUMBER(1) := NVL(V_ZECIMALE_PRET,
                                    pack_sesiune.nzecimale_pretv);
    V_ZECIMALESUMA NUMBER(1) := NVL(V_ZECIMALE_SUMA,
                                    pack_sesiune.nzecimale_sumav);
  BEGIN
    IF V_PRET_CU_TVA = 1 THEN
      V_SUMA_TVA := ROUND(pack_sesiune.calculeaza_total_cu_tva(V_PRET,
                                                               V_AJUSTARE,
                                                               V_CURS,
                                                               V_DISCOUNT_UNITAR,
                                                               V_DISCOUNT_EVIDENTIAT,
                                                               V_CANTITATE,
                                                               V_PRET_CU_TVA,
                                                               V_PROC_TVAV,
                                                               V_ZECIMALEPRET,
                                                               V_ZECIMALESUMA) *
                          (V_PROC_TVAV - 1) / V_PROC_TVAV,
                          V_ZECIMALESUMA);

    ELSE
      IF V_DISCOUNT_EVIDENTIAT = 1 THEN
        V_SUMA_TVA := ROUND(ROUND((ROUND(NVL(V_CURS, 1) * V_PRET,
                                         V_ZECIMALEPRET) +
                                  NVL(V_AJUSTARE, 0)) * V_CANTITATE,
                                  V_ZECIMALESUMA) * (V_PROC_TVAV - 1),
                            V_ZECIMALESUMA) -
                      ROUND(ROUND(ROUND(NVL(V_CURS, 1) *
                                        NVL(V_DISCOUNT_UNITAR, 0),
                                        V_ZECIMALEPRET) * V_CANTITATE,
                                  V_ZECIMALESUMA) * (V_PROC_TVAV - 1),
                            V_ZECIMALESUMA);
      ELSE
        V_SUMA_TVA := ROUND(ROUND((ROUND(NVL(V_CURS, 1) *
                                         ROUND(V_PRET, V_ZECIMALEPRET),
                                         V_ZECIMALEPRET) -
                                  ROUND(NVL(V_CURS, 1) *
                                         ROUND(NVL(V_DISCOUNT_UNITAR, 0),
                                               V_ZECIMALEPRET),
                                         V_ZECIMALEPRET) +
                                  NVL(V_AJUSTARE, 0)) * V_CANTITATE,
                                  V_ZECIMALESUMA) * (V_PROC_TVAV - 1),
                            V_ZECIMALESUMA);
      END IF;
    END IF;
    RETURN V_SUMA_TVA;
  END calculeaza_total_tva;
  ----------------------------------------------------------------------------
  function tva2proctva(V_TVA  IN ACT.SUMA%TYPE,
                       V_PRET IN ACT.SUMA%TYPE,
                       V_AN   IN ACT.AN%TYPE,
                       V_LUNA IN ACT.LUNA%TYPE) RETURN ACT.PROC_TVA%TYPE is
    V_PROC_TVA ACT.PROC_TVA%TYPE;
  BEGIN

    if V_PRET = 0 or V_TVA = 0 then
      V_PROC_TVA := 1;
    else
      V_PROC_TVA := ROUND(V_TVA / V_PRET, 2);
      if V_PROC_TVA between 0.03 and 0.07 then
        V_PROC_TVA := 1.05;
      elsif V_PROC_TVA between 0.08 and 0.11 then
        V_PROC_TVA := 1.09;
      else
        V_PROC_TVA := pack_contafin.getCotaTVAStandard(V_LUNA, V_AN);
      end if;
    end if;
    return V_PROC_TVA;
  END tva2proctva;
  ----------------------------------------------------------------------------
  function tva2proctva(V_TVA IN ACT.SUMA%TYPE, V_PRET IN ACT.SUMA%TYPE)
    RETURN ACT.PROC_TVA%TYPE is
  BEGIN
    return pack_sesiune.tva2proctva(V_TVA,
                                    V_PRET,
                                    pack_sesiune.an,
                                    pack_sesiune.luna);
  END tva2proctva;
  ----------------------------------------------------------------------------
  FUNCTION verifica_acces(V_TABELA     IN VARCHAR2,
                          V_ID         IN NUMBER,
                          V_MINUTE_MAX IN NUMBER) RETURN VARCHAR2 IS
  BEGIN
    RETURN pack_sesiune.verifica_acces(V_TABELA, V_ID, V_MINUTE_MAX, 1);
  END verifica_acces;
  ----------------------------------------------------------------------------
  FUNCTION verifica_acces(V_TABELA     IN VARCHAR2,
                          V_ID         IN NUMBER,
                          V_MINUTE_MAX IN NUMBER,
                          V_TIP        IN NUMBER) RETURN VARCHAR2 IS
    -- V_TIP              = 1 - verifica si blocheaza
    --                    = 2 - doar verifica
    V_MESAJ        VARCHAR2(1000);
    V_DATAORAE     DATE;
    V_DATA_ACTUALA DATE;
  BEGIN
    BEGIN
      SELECT MAX(DATAORAE) AS DATAORAE, SYSDATE
        INTO V_DATAORAE, V_DATA_ACTUALA
        FROM TABELE_BLOCATE
       WHERE TABELA = V_TABELA
         AND ID = V_ID;
    EXCEPTION
      WHEN NO_DATA_FOUND THEN
        V_DATAORAE     := NULL;
        V_DATA_ACTUALA := NULL;
    END;

    IF V_DATAORAE IS NULL THEN
      V_MESAJ := NULL;
      IF V_TIP = 1 THEN
        pack_sesiune.blocheaza_acces(V_TABELA, V_ID, NVL(V_MINUTE_MAX, 60));
      END IF;
    ELSE
      IF V_DATA_ACTUALA > V_DATAORAE THEN
        V_MESAJ := NULL;
        pack_sesiune.deblocheaza_acces_expirat(V_TABELA, V_ID);
        IF V_TIP = 1 THEN
          pack_sesiune.blocheaza_acces(V_TABELA,
                                       V_ID,
                                       NVL(V_MINUTE_MAX, 60));
        END IF;
      ELSE
        V_MESAJ := 'Nu puteti face operatii asupra acestei inregistrari! Sesiunea expira la ' ||
                   to_char(V_DATAORAE, 'DD/MM/YYYY HH24:mi:ss') || ' !';
      END IF;
    END IF;
    RETURN V_MESAJ;
  END verifica_acces;
  ----------------------------------------------------------------------------
  PROCEDURE blocheaza_acces(V_TABELA     IN VARCHAR2,
                            V_ID         IN NUMBER,
                            V_MINUTE_MAX IN NUMBER) is
  BEGIN
    INSERT INTO TABELE_BLOCATE
      (SID, TABELA, ID, DATAORAE)
    VALUES
      (sys_context('userenv', 'SID'),
       V_TABELA,
       V_ID,
       SYSDATE + NVL(V_MINUTE_MAX, 60) / (24 * 60));
  END blocheaza_acces;
  ----------------------------------------------------------------------------
  PROCEDURE deblocheaza_acces(V_SID IN NUMBER) is
  BEGIN
    DELETE FROM TABELE_BLOCATE WHERE SID = V_SID;
  END deblocheaza_acces;
  ----------------------------------------------------------------------------
  PROCEDURE deblocheaza_acces(V_TABELA IN VARCHAR2, V_ID IN NUMBER) is
  BEGIN
    DELETE FROM TABELE_BLOCATE
     WHERE SID = sys_context('userenv', 'SID')
       AND TABELA = V_TABELA
       AND ID = V_ID;
  END deblocheaza_acces;
  ----------------------------------------------------------------------------
  PROCEDURE deblocheaza_acces_expirat(V_TABELA IN VARCHAR2, V_ID IN NUMBER) is
  BEGIN
    DELETE FROM TABELE_BLOCATE
     WHERE TABELA = V_TABELA
       AND ID = V_ID;
  END deblocheaza_acces_expirat;
  ----------------------------------------------------------------------------
begin
  pack_sesiune.nid_moneda_nationala := pack_def.GetIdMonedaNationala();
  pack_sesiune.nzecimale_preta      := PACK_SESIUNE.getoptiunefirma(USER,
                                                                    'PPRET');
  pack_sesiune.nzecimale_pretv      := PACK_SESIUNE.getoptiunefirma(USER,
                                                                    'PPRETV');
  pack_sesiune.nzecimale_pretaval   := PACK_SESIUNE.getoptiunefirma(USER,
                                                                    'PPRETVAL');
  pack_sesiune.nzecimale_pretvval   := PACK_SESIUNE.getoptiunefirma(USER,
                                                                    'PVAL');
  pack_sesiune.nzecimale_sumaa      := PACK_SESIUNE.getoptiunefirma(USER,
                                                                    'PC');
  pack_sesiune.nzecimale_sumav      := PACK_SESIUNE.getoptiunefirma(USER,
                                                                    'PC');
  pack_sesiune.nzecimale_sumaval    := PACK_SESIUNE.getoptiunefirma(USER,
                                                                    'PVAL');
end pack_sesiune;
/
