-- SQL SERVER
-- DROP VIEW dbo.FACC_V_LIST_REGISTRU_JURNAL_X;
CREATE VIEW dbo.FACC_V_LIST_REGISTRU_JURNAL_X AS
SELECT     
	TBL_REGISTRU.ID_DOCUMENT,
    TBL_REGISTRU.DAT_DOCUMENT, 
	TBL_REGISTRU.DAT_SCADENT,     
    TBL_REGISTRU.COD_NUMBER, 
	TBL_REGISTRU.TIP_DOCUMENT,     
    TBL_REGISTRU.ID_PARTNER, 
    TBL_REGISTRU.PARTNER_NAME, 
	TBL_REGISTRU.COD_FISCAL,
	TBL_REGISTRU.COD_CNP,		    
    TBL_REGISTRU.EXPLICATII, 
    TBL_REGISTRU.CONT_DEBIT, 
    TBL_REGISTRU.CONT_CREDIT, 
    SUM(TBL_REGISTRU.DEC_VALUE) AS DEC_VALUE
FROM   
    (SELECT     
  TOP (100) PERCENT 
  dbo.FACC_T_CONTARI.ID_DOCUMENT,
  dbo.FACC_T_CONTARI.DAT_DOCUMENT, 
		dbo.FACC_T_DOCUMENTS.DAT_SCADENT,
		dbo.FACC_V_ALL_DOCUMENTS.COD_NUMBER,
		dbo._FACC_GET_DOCUMENT_TYPE_NAME(dbo.FACC_T_CONTARI.ID_DOCUMENT) AS TIP_DOCUMENT, 
  dbo.NCL_V_PARTNERS_NAMES.ID_PARTNER, 
  dbo.NCL_V_PARTNERS_NAMES.PARTNER_NAME, 
		dbo.NCL_T_PARTNERS.COD_FISCAL,
		dbo.NCL_T_PARTNERS.COD_CNP,	
  dbo.FACC_T_CONTARI.EXPLICATII, 
  dbo.FACC_T_CONTARI.CONT_DEBIT, 
  dbo.FACC_T_CONTARI.CONT_CREDIT, 
  dbo.FACC_T_CONTARI.DEC_VAL AS DEC_VALUE
    FROM    
  dbo.FACC_T_CONTARI 
  INNER JOIN dbo.FACC_V_ALL_DOCUMENTS ON dbo.FACC_T_CONTARI.ID_DOCUMENT = dbo.FACC_V_ALL_DOCUMENTS.ID_DOCUMENT 
  LEFT OUTER JOIN dbo.NCL_V_PARTNERS_NAMES ON dbo.FACC_V_ALL_DOCUMENTS.ID_PARTNER = dbo.NCL_V_PARTNERS_NAMES.ID_PARTNER
		LEFT OUTER JOIN dbo.NCL_T_PARTNERS ON dbo.FACC_V_ALL_DOCUMENTS.ID_PARTNER = dbo.NCL_T_PARTNERS.ID_PARTNER  
  LEFT OUTER JOIN dbo.FACC_T_DOCUMENTS on dbo.FACC_T_CONTARI.ID_DOCUMENT = dbo.FACC_T_DOCUMENTS.ID_DOCUMENT
    WHERE
  (dbo.FACC_T_CONTARI.DEC_VAL <> 0)
    ) AS TBL_REGISTRU 
    INNER JOIN dbo.NCL_T_ACCOUNTS ON TBL_REGISTRU.CONT_DEBIT = dbo.NCL_T_ACCOUNTS.COD_ACCOUNT 
    INNER JOIN dbo.NCL_T_ACCOUNTS AS NCL_T_ACCOUNTS_1 ON TBL_REGISTRU.CONT_CREDIT = NCL_T_ACCOUNTS_1.COD_ACCOUNT
GROUP BY 
	TBL_REGISTRU.ID_DOCUMENT,
    TBL_REGISTRU.DAT_DOCUMENT, 
    TBL_REGISTRU.DAT_SCADENT,     
    TBL_REGISTRU.COD_NUMBER, 
    TBL_REGISTRU.TIP_DOCUMENT,    
    TBL_REGISTRU.ID_PARTNER, 
    TBL_REGISTRU.PARTNER_NAME, 
	TBL_REGISTRU.COD_FISCAL,
	TBL_REGISTRU.COD_CNP,		
    TBL_REGISTRU.EXPLICATII, 
    TBL_REGISTRU.CONT_DEBIT, 
    TBL_REGISTRU.CONT_CREDIT
HAVING
    (SUM(TBL_REGISTRU.DEC_VALUE) <> 0)
	

  
CREATE VIEW dbo.FACC_V_LIST_REGISTRU_JURNAL_Y AS
SELECT 
r.ID_DOCUMENT,r.DAT_DOCUMENT,r.DAT_SCADENT,r.COD_NUMBER,r.TIP_DOCUMENT,r.ID_PARTNER,r.PARTNER_NAME,r.COD_FISCAL,r.COD_CNP,r.EXPLICATII,r.CONT_DEBIT,r.CONT_CREDIT,r.DEC_VALUE,
l.ID_IN as ID_DOCP, l.VAL_LEI, COALESCE(l.val_lei, r.dec_value) as suma
  FROM [mybiz].[dbo].[FACC_V_LIST_REGISTRU_JURNAL_X] r
  left outer join [mybiz].[dbo].[PRT_T_LEGATURI] l on r.id_document = l.ID_OUT

  

CREATE VIEW dbo.FACC_V_LIST_REGISTRU_JURNAL_Y_2024 AS
SELECT [ID_DOCUMENT]
      ,[DAT_DOCUMENT]
      ,[DAT_SCADENT]
      ,[COD_NUMBER]
      ,[TIP_DOCUMENT]
      ,[ID_PARTNER]
      ,[PARTNER_NAME]
      ,[COD_FISCAL]
      ,[COD_CNP]
      ,[EXPLICATII]
      ,[CONT_DEBIT]
      ,[CONT_CREDIT]
      ,[DEC_VALUE]
      ,[ID_DOCP]
      ,[VAL_LEI]
      ,[suma]
  FROM [mybiz].[dbo].[FACC_V_LIST_REGISTRU_JURNAL_Y] 
  where dat_document >= '2024-01-01'

  
/****** Script for SelectTopNRows command from SSMS  ******/
SELECT [ID_DOCUMENT]
      ,[DAT_DOCUMENT]
      ,[DAT_SCADENT]
      ,[COD_NUMBER]
      ,[TIP_DOCUMENT]
      ,[ID_PARTNER]
      ,[PARTNER_NAME]
      ,[COD_FISCAL]
      ,[COD_CNP]
      ,[EXPLICATII]
      ,[CONT_DEBIT]
      ,[CONT_CREDIT]
      ,[DEC_VALUE]
      ,[ID_DOCP]
      ,[VAL_LEI]
      ,[suma]
  FROM [mybiz].[dbo].FACC_V_LIST_REGISTRU_JURNAL_Y_2024 
  order by dat_document desc
  
-------------------------------------
CREATE TABLE EXT_IMPORT_DOCUMENTE (
    ID_DOCUMENT VARCHAR2(100),
    DAT_DOCUMENT VARCHAR2(100),
    DAT_SCADENT VARCHAR2(100),
    COD_NUMBER VARCHAR2(100),
    TIP_DOCUMENT VARCHAR2(100),
    ID_PARTNER VARCHAR2(100),
    PARTNER_NAME VARCHAR2(200),
    COD_FISCAL VARCHAR2(100),
    COD_CNP VARCHAR2(100),
    EXPLICATII VARCHAR2(500),
    CONT_DEBIT VARCHAR2(100),
    CONT_CREDIT VARCHAR2(100),
    DEC_VALUE VARCHAR2(100),
    ID_DOCP VARCHAR2(100),
    VAL_LEI VARCHAR2(100),
    SUMA VARCHAR2(100)
)
ORGANIZATION EXTERNAL (
    TYPE ORACLE_LOADER
    DEFAULT DIRECTORY DMPDIR
    ACCESS PARAMETERS (
        RECORDS DELIMITED BY NEWLINE
        SKIP 1
        FIELDS TERMINATED BY ','
        OPTIONALLY ENCLOSED BY '"'
        MISSING FIELD VALUES ARE NULL
    )
    LOCATION ('registru_jurnal_2024.csv')
)
REJECT LIMIT 0;

-- Verificarea datelor brute
SELECT * FROM EXT_IMPORT_DOCUMENTE WHERE ROWNUM <= 10;

-- Crearea tabelului final cu conversie flexibilă și gestionarea erorilor
create table IMP_IMPORT_DOCUMENTE AS
SELECT
    TO_NUMBER(REGEXP_SUBSTR(ID_DOCUMENT, '\d+')) AS ID_DOCUMENT,
    TO_DATE(SUBSTR(REPLACE(DAT_DOCUMENT, 'NULL', ''),1,10), 'YYYY-MM-DD') AS DAT_DOCUMENT,
    TO_DATE(SUBSTR(REPLACE(DAT_SCADENT, 'NULL', ''),1,10), 'YYYY-MM-DD') AS DAT_SCADENT,
    REGEXP_SUBSTR(COD_NUMBER, '\d+') as COD_NUMBER,
    REPLACE(TIP_DOCUMENT, 'NULL', '') AS TIP_DOCUMENT,
    TO_NUMBER(REGEXP_SUBSTR(ID_PARTNER, '\d+')) AS ID_PARTNER,
    REPLACE(PARTNER_NAME, 'NULL', '') AS PARTNER_NAME,
    REPLACE(COD_FISCAL, 'NULL', '') AS COD_FISCAL,
    REPLACE(COD_CNP, 'NULL', '') AS COD_CNP,
    REPLACE(EXPLICATII, 'NULL', '') AS EXPLICATII,
    REPLACE(CONT_DEBIT, 'NULL', '') AS CONT_DEBIT,
    REPLACE(CONT_CREDIT, 'NULL', '') AS CONT_CREDIT,
    TO_NUMBER(REPLACE(DEC_VALUE, 'NULL', '0'), '999999999.99') AS DEC_VALUE,
    TO_NUMBER(REGEXP_SUBSTR(ID_DOCP, '\d+')) AS ID_DOCP,
    TO_NUMBER(REPLACE(VAL_LEI,'NULL', '0'), '999999999.99') AS VAL_LEI,
    TO_NUMBER(REPLACE(SUMA, 'NULL', '0'), '999999999.99') AS SUMA
	FROM EXT_IMPORT_DOCUMENTE;

-- Verificarea datelor convertite
SELECT * FROM IMPORT_DOCUMENTE WHERE ROWNUM <= 10;

-- Verificarea rândurilor cu probleme la conversia datei
SELECT ID_DOCUMENT, DAT_DOCUMENT, DAT_SCADENT
FROM IMP_IMPORT_DOCUMENTE
WHERE DAT_DOCUMENT IS NULL OR DAT_SCADENT IS NULL;

ALTER TABLE IMP_IMPORT_DOCUMENTE ADD ID_PART NUMBER(20) NULL;
alter table IMP_IMPORT_DOCUMENTE add scd varchar2(4);
alter table IMP_IMPORT_DOCUMENTE add ascd varchar2(4);
alter table IMP_IMPORT_DOCUMENTE add scc varchar2(4);
alter table IMP_IMPORT_DOCUMENTE add ascc varchar2(4);
alter table IMP_IMPORT_DOCUMENTE add cod number(20);
alter table IMP_IMPORT_DOCUMENTE add id_fdoc number(5);



-- Created on 10/29/2024 by MMARI 
declare 
      lnIdPart NOM_PARTENERI.ID_PART%TYPE := 0;
begin
  -- Test statements here
  for item in (select distinct id_partner, partner_name, cod_fiscal, cod_cnp from imp_import_documente where cod_fiscal is not null) loop
      select max(id_part) into lnIdPart from nom_parteneri where sters = 0 and trim(regexp_replace(cod_fiscal, '[^0-9]', '')) = item.cod_fiscal;
      if lnIdPart is null then
           PACK_DEF.adauga_partener(tcDenumire => item.partner_name,
                             tcNume => item.partner_name,
                             tcPrenume => '',
                             tcCod_fiscal => item.cod_fiscal,
                             tcReg_comert => '',
                             tnId_loc => NULL,
                             tnId_categorie_entitate => NULL,
                             tcPrefix => NULL,
                             tcSufix => NULL,
                             tnTip_persoana => 1,
                             tcBanca => NULL,
                             tcCont_banca => NULL,
                             tnInactiv => 0,
                             tcMotiv_inactiv => NULL,
                             tnId_util => -3,
                             tcSir_id_tipPart => '16;',
                             tnId_Part => lnIdPart);   
        
          update nom_parteneri set zona = 'IMPORT' where id_part = lnIdPart;
      end if;
      
      update imp_import_documente set id_part = lnIdPart where id_partner = item.id_partner;
  end loop;
    
end;
/

UPDATE IMP_IMPORT_DOCUMENTE
   SET SCD = CASE
               WHEN INSTR(cont_debit, '.') > 0 THEN
                SUBSTR(cont_debit, 1, INSTR(cont_debit, '.') - 1)
               ELSE
                cont_debit
             END,
       ascd = CASE
                WHEN INSTR(cont_debit, '.') > 0 THEN
                 REPLACE(SUBSTR(cont_debit, INSTR(cont_debit, '.') + 1),
                         '.',
                         '')
                ELSE
                 null
              END,
       scc = CASE
               WHEN INSTR(cont_credit, '.') > 0 THEN
                SUBSTR(cont_credit, 1, INSTR(cont_credit, '.') - 1)
               ELSE
                cont_credit
             END,
       ascc = CASE
                WHEN INSTR(cont_credit, '.') > 0 THEN
                 REPLACE(SUBSTR(cont_credit, INSTR(cont_credit, '.') + 1),
                         '.',
                         '')
                ELSE
                 null
              END;

BEGIN
  FOR ITEM IN (SELECT 50 as id_fdoc, 'Amortizare' as fel_document
                 FROM DUAL
               UNION ALL
               SELECT 25, 'Chitanta Beneficiar Lei'
                 FROM DUAL
               UNION ALL
               SELECT 25, 'Chitanta Furnizor Lei'
                 FROM DUAL
               UNION ALL
               SELECT 15, 'Consum'
                 FROM DUAL
               UNION ALL
               SELECT 35, 'Dispozitie de incasare / plata Lei'
                 FROM DUAL
               UNION ALL
               SELECT 40, 'Extras de cont Lei'
                 FROM DUAL
               UNION ALL
               SELECT 42, 'Factura Client'
                 FROM DUAL
               UNION ALL
               SELECT 42, 'Factura Furnizor'
                 FROM DUAL
               UNION ALL
               SELECT 50, 'Import Aplicatii Fidelio'
                 FROM DUAL
               UNION ALL
               SELECT 50, 'Import Aplicatii Micros'
                 FROM DUAL
               UNION ALL
               SELECT 50, 'Inchidere Venituri si Cheltuieli'
                 FROM DUAL
               UNION ALL
               SELECT 48, 'Monetar lei'
                 FROM DUAL
               UNION ALL
               SELECT 50, 'Nota Salarizare'
                 FROM DUAL
               UNION ALL
               SELECT 50, 'Note contabile diverse'
                 FROM DUAL
               UNION ALL
               SELECT 56, 'Ordin de plata beneficiar Lei'
                 FROM DUAL
               UNION ALL
               SELECT 56, 'Ordin de plata furnizor Lei'
                 FROM DUAL
               UNION ALL
               SELECT 55, 'Transfer'
                 FROM DUAL) LOOP
    UPDATE IMP_IMPORT_DOCUMENTE
       SET ID_FDOC = ITEM.ID_FDOC
     WHERE UPPER(TRIM(replace(tip_document,'-->','')))  = UPPER(ITEM.FEL_DOCUMENT);
  END LOOP;
END;


 
insert into act (an, luna, dataireg, cod, id_fact, dataact, datascad, nract, id_fdoc, explicatia, scd, ascd, scc, ascc, suma, id_Factd, id_factc, id_partd, id_partc, id_util, dataora, explicatia4)
select extract(year from dat_document) as an, extract(month from dat_document) as luna, dat_document as dataireg, id_document as cod, id_document as id_fact, dat_document as dataact, dat_scadent as datascad, to_number(nvl(cod_number,to_char(dat_document, 'yyyymmdd')))  as nract,
id_fdoc, explicatii as explicatia, scd, ascd, scc, ascc, suma, 
case when scd in ('401','404','419','462', '408') then nvl(id_docp,0) else 0 end as id_factd,
case when scc in ('4111','409','4091', '4092', '4093', '4094','461', '418') then nvl(id_docp,0) else 0 end as id_factc,
case when scd in ('401','404','419','462', '408','4111','409','4091', '4092', '4093', '4094','461', '418') then nvl(id_part,0) else 0 end as id_partd,
case when scc in ('401','404','419','462', '408','4111','409','4091', '4092', '4093', '4094','461', '418') then nvl(id_part,0) else 0 end as id_partc,
  -3 as id_util, to_date('29102024','ddmmyyyy') as dataora, 'IMPORT BIZ' as explicatia4
  from imp_import_documente where extract(year from dat_document) = 2024 and extract(month from dat_document) between 1 and 5 order by dat_document, cod_number;
  
update act set id_jtva_coloana = 113 where  an=2024 and scc = '401' and id_jtva_coloana is null and explicatia4 = 'IMPORT BIZ';  

----------------------------------
-- DOCUMENTE DUBLE DIN IMPORTBIZ SI ROA
--select t.*,rowid from act t where an=2024 and luna = 6 order by dataact, nract, cod;

select an, luna, nract, dataact, scd, ascd, scc, ascc, suma, explicatia4, sters, id_utils, dataoras, cod from
(select an, luna, nract, dataact, scd, ascd, scc, ascc, suma, explicatia4, sters, id_utils, dataoras, cod from act
union 
select an, luna, nract, dataact, scd, ascd, scc, ascc, suma, explicatia4, 0 as sters, 0 as id_utils, null as dataoras, cod from act_imp_2024)
where an=2024 and luna = 10 and cod in (
select cod from
(with select_data as
(select distinct a.cod, a.dataact, a.nract, b.cod as codb from
(select distinct dataact, nract, suma, cod, explicatia4 from act_imp_2024 where an=2024 and luna = 10 ) a join 
(select distinct dataact, nract, suma, cod, explicatia4 from act where an=2024 and luna = 10 and sters = 0 and explicatia4 is null) b on (a.dataact = b.dataact and a.nract = b.nract and a.suma = b.suma)
)
select cod from select_data
union 
select codb from select_data))
order by dataact, nract, cod, suma;

------------------------
update act set explicatia5 = 'DUPLICATE' WHERE an=2024 and luna = 9 and cod in (
select cod from
(with select_data as
(select distinct a.cod, a.dataact, a.nract, b.cod as codb from
(select distinct dataact, nract, suma, cod, explicatia4 from act where an=2024 and luna = 9 and sters = 0 and explicatia4 = 'IMPORT BIZ') a join 
(select distinct dataact, nract, suma, cod, explicatia4 from act where an=2024 and luna = 9 and sters = 0 and explicatia4 is null) b on (a.dataact = b.dataact and a.nract = b.nract and a.suma = b.suma)
)
select cod from select_data
union 
select codb from select_data));


select t.*,rowid from act t where an=2024 and luna = 6 and cod in (
select cod from
(with select_data as
(select distinct a.cod, a.dataact, a.nract, b.cod as codb from
(select distinct dataact, nract, suma, cod, explicatia4 from act where an=2024 and luna = 6 and sters = 0 and explicatia4 = 'IMPORT BIZ') a join 
(select distinct dataact, nract, suma, cod, explicatia4 from act where an=2024 and luna = 6 and sters = 0 and explicatia4 is null) b on (a.dataact = b.dataact and a.nract = b.nract and a.suma = b.suma)
)
select cod from select_data
union 
select codb from select_data))
order by dataact, nract, cod;

select T.EXPLICATIA4, T.EXPLICATIA5, T.STERS, T.DATAORAS, T.ID_UTILS, t.nract, t.dataact, t.explicatia, t.scd, t.ascd, t.scc, t.ascc, t.suma, t.*,rowid from act t where an=2024 and luna = 6 AND EXPLICATIA5 like '%DUPLICATE' order by t.dataact, t.nract, t.cod;

-- DUPLICATE
select T.EXPLICATIA4, T.EXPLICATIA5, T.STERS, t.nract, t.dataact, t.scd, t.ascd, t.scc, t.ascc, t.suma, t.id_jtva_coloana, t.taxcode, t.paymentcode, t.explicatia, t.id_fact, t.id_factd, t.id_factc, t.cod, t.id_act, t.id_fdoc, t.datascad, t.dataireg, t.an, t.luna, t.nnir, t.id_util, t.dataora, t.id_responsabil, t.id_venchelt, t.id_sectie, t.id_set, t.id_lucrare, t.id_Gestin, t.id_Gestout, t.id_Valuta, t.proc_tva, t.id_ctr, t.serie_act,rowid from act t where an=2024 and luna = 6 AND STERS = 0 AND EXPLICATIA5 = 'DUPLICATE' order by t.dataact, t.nract, t.cod, t.suma;

-- ZDUPLICATE
select T.EXPLICATIA4, T.EXPLICATIA5, T.STERS, t.nract, t.dataact, t.scd, t.ascd, t.scc, t.ascc, t.suma, t.explicatia, t.id_fact, t.id_factd, t.id_factc, t.cod, t.id_act, t.id_jtva_coloana, t.id_fdoc, t.datascad, t.dataireg, t.an, t.luna, t.nnir, t.id_util, t.dataora, t.id_responsabil, t.id_venchelt, t.id_sectie, t.id_set, t.id_lucrare, t.id_Gestin, t.id_Gestout, t.id_Valuta, t.proc_tva, t.id_ctr, t.serie_act, t.taxcode, t.paymentcode,rowid from act t where an=2024 and luna = 6 AND EXPLICATIA5 = 'ZDUPLICATE' order by t.dataact, t.nract, t.cod, t.suma;
------------------------


/*SELECT SUM(SUMA) AS SUMA from imp_import_documente where extract(year from dat_document) = 2024 and extract(month from dat_document) = 6 
AND SUBSTR(SCD, 1,3) = '401';
SELECT SUM(SUMA) AS SUMA from imp_import_documente where extract(year from dat_document) = 2024 and extract(month from dat_document) = 6 
AND SUBSTR(SCC, 1,3) = '401';*/

SELECT CONT, SUM(DEBIT) AS DEBIT, SUM(CREDIT) AS CREDIT FROM 
(SELECT SUBSTR(SCD,1,3) AS CONT, SUMA AS DEBIT, 0 AS CREDIT FROM ACT WHERE AN=2024 AND LUNA = 6 AND STERS = 0 AND SCD IS NOT NULL
UNION ALL
SELECT SUBSTR(SCC,1,3) AS CONT, 0 AS DEBIT, SUMA AS CREDIT FROM ACT WHERE AN=2024 AND LUNA = 6 AND STERS = 0 AND SCC IS NOT NULL)
GROUP BY CONT
ORDER BY CONT;

select a.dataact, a.suma as biz, b.suma as roa, a.suma - b.suma as dif from
(SELECT sum(t.suma) as suma, dat_document as dataact from imp_import_documente t where extract(year from dat_document) = 2024 and extract(month from dat_document) = 6 AND SUBSTR(SCD, 1,3) = '401' group by dat_document) a left join 
(SELECT sum(t.suma) as suma, dataact from ACT t where AN=2024 AND LUNA = 6 AND SUBSTR(SCD, 1,3) = '401' AND STERS= 0  group by dataact) b on (a.dataact = b.dataact) order by dataact;


select a.scd, a.scc, b.scd, b.scc, a.dataact, a.suma as biz, b.suma as roa, nvl(a.suma,0) - nvl(b.suma,0) as dif from
(SELECT SCD, SCC, sum(t.suma) as suma, dat_document as dataact from imp_import_documente t where extract(year from dat_document) = 2024 and extract(month from dat_document) = 6 group by SCD, SCC, dat_document) a left join 
(SELECT SCD, SCC, sum(t.suma) as suma, dataact from ACT t where AN=2024 AND LUNA = 6 AND STERS= 0  group by SCD, SCC, dataact) b on (a.dataact = b.dataact and a.scd = b.scd and a.scc = b.scc) 
where nvl(a.suma,0) - nvl(b.suma,0) <> 0 order by a.scd, a.dataact;

select t.*,rowid from imp_import_documente t where extract(year from dat_document) = 2024 and extract(month from dat_document) = 6 AND SUBSTR(SCC, 1,3) = '401' AND dat_document = to_date('20062024', 'ddmmyyyy')order by dat_document, to_number(cod_number), suma;
--select t.explicatia4, t.*,rowid from act t where AN=2024 AND LUNA = 6 AND SUBSTR(SCD, 1,3) = '401' AND STERS= 0  AND dataact = to_date('21062024', 'ddmmyyyy')order by dataact, suma;
select T.EXPLICATIA4, T.EXPLICATIA5, T.STERS, t.nract, t.dataact, t.scd, t.ascd, t.scc, t.ascc, t.suma, t.id_jtva_coloana, t.taxcode, t.paymentcode, t.explicatia, t.id_fact, t.id_factd, t.id_factc, t.cod, t.id_act, t.id_fdoc, t.datascad, t.dataireg, t.an, t.luna, t.nnir, t.id_util, t.dataora, t.id_responsabil, t.id_venchelt, t.id_sectie, t.id_set, t.id_lucrare, t.id_Gestin, t.id_Gestout, t.id_Valuta, t.proc_tva, t.id_ctr, t.serie_act,rowid from act t where an=2024 and luna = 6 AND STERS = 0 AND SUBSTR(SCC, 1,3) = '401' AND dataact = to_date('20062024', 'ddmmyyyy')  order by t.dataact, T.NRACT, t.suma;

select t.*,rowid from imp_import_documente t where extract(year from dat_document) = 2024 and extract(month from dat_document) = 6 AND cod_number like '%7000696928%' AND dat_document = to_date('20062024', 'ddmmyyyy')order by dat_document, to_number(cod_number), suma;
select T.EXPLICATIA4, T.EXPLICATIA5, T.STERS, t.nract, t.dataact, t.scd, t.ascd, t.scc, t.ascc, t.suma, t.id_jtva_coloana, t.taxcode, t.paymentcode, t.explicatia, t.id_fact, t.id_factd, t.id_factc, t.cod, t.id_act, t.id_fdoc, t.datascad, t.dataireg, t.an, t.luna, t.nnir, t.id_util, t.dataora, t.id_responsabil, t.id_venchelt, t.id_sectie, t.id_set, t.id_lucrare, t.id_Gestin, t.id_Gestout, t.id_Valuta, t.proc_tva, t.id_ctr, t.serie_act,rowid from act t where an=2024 and luna = 6 AND STERS = 0 AND nract=  7000696928 AND dataact = to_date('20062024', 'ddmmyyyy')  order by t.dataact, T.NRACT, t.suma;
