* test_timp_verificare_masa.prg - masoara UNDE se duce timpul la verificarea in masa a
* codurilor fiscale cand raspunsul vine din cache (ISTORIC_CODURI_FISCALE), nu de la ANAF.
*
* Traseul masurat: VerificareANAF.VerificaListaCIF(..., 'MASA') din COMUN\programe\validare.prg,
* apelat de frm_verificare_parteneri.do_verifica (COMUN\clase\overificari.vc2:2736) si de
* orapoarte.prg:1997.
*
* ANAF-ul REAL nu e apelat niciodata: subclasa VerificareANAFTimp (finalul fisierului) blocheaza
* ANAF_SincronWebService_PlatitorTva si numara apelurile, deci tot ce se masoara e cost local
* (Oracle + VFP), nu latenta serviciului ANAF.
*
* Ce masoara, in ordine:
*   A. rulare completa VerificaListaCIF pe N coduri proaspete in cache (implicit N=200)
*   B. descompunerea pe faze a aceleiasi rulari (OrdineCache, ZileCache, NormalizeazaCoduriCursor,
*      CitesteIstoricPentruCoduri, bucla de Locate, SalveazaIstoricDinCursor, bucla de goLog)
*   C. costul brut al unui apel Oracle prin goExecutor (cu si fara scriere in goLog)
*   D. limita IN (...) din CitesteIstoricPentruCoduri: lista de coduri se pune inline in SQL,
*      deci peste 1000 de coduri Oracle da ORA-01795
*   E. bucla de completare din apelant (overificari.vc2:2741-2756): LOCATE cu UDF per rand,
*      comparata cu aceeasi completare pe cursor indexat
*
* Rulare: vfp9.exe -A -T "...\test_timp_verificare_masa.prg" [N]
* Log: test_timp_verificare_masa_log.txt (langa script)
* Curatenie: randurile scrise in ISTORIC_CODURI_FISCALE peste watermark-ul de ID se sterg la final.

LPARAMETERS tcN

SET SAFETY OFF
SET TALK OFF
SET DELETED ON
SET EXACT ON
SET CENTURY ON
SET DATE DMY
SET NULLDISPLAY TO ''
CLOSE DATABASES

PUBLIC gcTestLog, gnApeluriANAF, gcMockUltimMesaj, gnMockUltimTip, gnMockRaspuns
gcTestLog = "D:\ROA\ROACONT\COMUN\utile\Teste\cache_anaf\test_timp_verificare_masa_log.txt"
STRTOFILE("START " + TTOC(DATETIME()) + CHR(13) + CHR(10), gcTestLog)
gnApeluriANAF = 0
gcMockUltimMesaj = ''
gnMockUltimTip = 0
gnMockRaspuns = 6

ON ERROR DO ErrTimp WITH ERROR(), MESSAGE(), PROGRAM(), LINENO()
ON SHUTDOWN QUIT

DO D:\ROA\ROACONT\COMUN\utile\Teste\test_init_env_auto.prg WITH 'CENTRAL', 'MARIUSM_AUTO', 'ROMFASTSOFT'
IF gnHandle <= 0
	DO WrLog WITH 'EROARE: conectare Oracle esuata - GATA'
	QUIT
ENDIF
DO WrLog WITH 'mediu OK, schema=' + gcS

* mock-ul de amessagebox se incarca ULTIMUL (dialogurile modale ar bloca rularea headless)
SET PROCEDURE TO "D:\ROA\ROACONT\COMUN\utile\Teste\mock_amessagebox.prg" ADDITIVE

* mock_amessagebox NU acopera apelul de amessagebox din oexecutor.oExecuta: VFP rezolva intai
* in fisierul de proceduri curent (oproceduri_comune.prg), iar acolo amessagebox deschide un
* FORMULAR modal (MessageBox.vcx), invizibil in enumerarea ferestrelor - headless blocheaza
* procesul la nesfarsit. Sectiunea D provoaca intentionat ORA-01795, deci executorul trebuie
* sa fie unul care nu deschide dialogul.
PUBLIC gnErorriSQL, gcUltimaEroareSQL
gnErorriSQL = 0
gcUltimaEroareSQL = ''
LOCAL loExecFaraDialog
loExecFaraDialog = CREATEOBJECT('oexec_fara_dialog_t')
loExecFaraDialog.nHandle = gnHandle
goExecutor = loExecFaraDialog

LOCAL lnN, lnI, lnT, lcSql, lcLista, lnRandInit, lnRandFinal
lnN = IIF(TYPE('tcN') = 'C' AND !EMPTY(tcN), INT(VAL(tcN)), 200)
DO WrLog WITH 'N cerut = ' + TRANSFORM(lnN)

* goLog scrie doar daca fisierul de log EXISTA (log_mesaje.prg:54) - in productie exista,
* deci il cream, ca masuratoarea sa includa costul real de logare
PUBLIC gcLogApp
gcLogApp = "D:\ROA\ROACONT\COMUN\utile\Teste\cache_anaf\test_timp_log_app.txt"
STRTOFILE('', gcLogApp)
goLog.cLogFile = gcLogApp

* --- watermark ID, inainte de orice scriere ---
PUBLIC gnIdMaxIstoric
gnIdMaxIstoric = 0
IF goExecutor.oExecuta('SELECT NVL(MAX(ID),0) AS IDMAX FROM ISTORIC_CODURI_FISCALE', 'crsWmT')
	SELECT crsWmT
	GO TOP
	gnIdMaxIstoric = IDMAX
	USE IN (SELECT('crsWmT'))
ENDIF
DO WrLog WITH 'watermark ISTORIC_CODURI_FISCALE id_max=' + TRANSFORM(gnIdMaxIstoric)
IF gnIdMaxIstoric <= 0
	DO WrLog WITH 'ATENTIE: watermark invalid - curatenia finala se va sari'
ENDIF

LOCAL loVer, lnZile
loVer = CREATEOBJECT('VerificareANAFTimp')
lnZile = loVer.ZileCache()
DO WrLog WITH 'ZileCache = ' + TRANSFORM(lnZile)

* --- context: cat de mare e istoricul, cate coduri sunt proaspete ---
IF goExecutor.oExecuta('SELECT COUNT(*) AS N FROM ISTORIC_CODURI_FISCALE', 'crsCtx1')
	DO WrLog WITH 'randuri in ISTORIC_CODURI_FISCALE: ' + TRANSFORM(crsCtx1.N)
	USE IN (SELECT('crsCtx1'))
ENDIF
lcSql = 'SELECT COUNT(DISTINCT COD_FISCAL_N) AS N FROM ISTORIC_CODURI_FISCALE'
lcSql = lcSql + ' WHERE DATAORAV_ANAF IS NOT NULL AND SYSDATE - DATAORAV_ANAF <= ' + TRANSFORM(lnZile)
IF goExecutor.oExecuta(lcSql, 'crsCtx2')
	DO WrLog WITH 'coduri proaspete in cache (<= ' + TRANSFORM(lnZile) + ' zile): ' + TRANSFORM(crsCtx2.N)
	USE IN (SELECT('crsCtx2'))
ENDIF

* --- lotul de test: coduri PROASPETE din cache, ca sa nu se ajunga la ANAF ---
lcSql = 'SELECT COD_FISCAL_N FROM (SELECT DISTINCT COD_FISCAL_N FROM ISTORIC_CODURI_FISCALE'
lcSql = lcSql + ' WHERE COD_FISCAL_N IS NOT NULL AND DATAORAV_ANAF IS NOT NULL'
lcSql = lcSql + ' AND SYSDATE - DATAORAV_ANAF <= ' + TRANSFORM(lnZile)
lcSql = lcSql + ' ORDER BY COD_FISCAL_N) WHERE ROWNUM <= ' + TRANSFORM(lnN)
IF !goExecutor.oExecuta(lcSql, 'crsCoduriSursa')
	DO WrLog WITH 'EROARE: nu pot citi codurile din istoric - GATA'
	QUIT
ENDIF

IF USED('cCoduriMasa')
	USE IN cCoduriMasa
ENDIF
CREATE CURSOR cCoduriMasa (cod_fiscal C(30) NULL, data D NULL)
SELECT crsCoduriSursa
SCAN
	INSERT INTO cCoduriMasa (cod_fiscal, data) VALUES (ALLTRIM(TRANSFORM(crsCoduriSursa.COD_FISCAL_N)), DATE())
	SELECT crsCoduriSursa
ENDSCAN
USE IN (SELECT('crsCoduriSursa'))
lnN = RECCOUNT('cCoduriMasa')
DO WrLog WITH '--- lot efectiv: ' + TRANSFORM(lnN) + ' coduri proaspete'
IF lnN = 0
	DO WrLog WITH 'EROARE: niciun cod proaspat in cache - GATA'
	QUIT
ENDIF

*==========================================================
* A. rulare completa VerificaListaCIF (traseu MASA = CACHE,ANAF)
*==========================================================
DO WrLog WITH ''
DO WrLog WITH '=== A. VerificaListaCIF complet, ' + TRANSFORM(lnN) + ' coduri ==='
gnApeluriANAF = 0
lnRandInit = NrRanduriIstoric()
lnT = SECONDS()
LOCAL lcRez
lcRez = loVer.VerificaListaCIF('cCoduriMasa', DATE(), 'crsANAFTest', 'MASA')
lnT = SECONDS() - lnT
lnRandFinal = NrRanduriIstoric()
DO WrLog WITH 'TOTAL VerificaListaCIF = ' + TRANSFORM(ROUND(lnT, 3)) + ' s pentru ' + TRANSFORM(lnN) + ' coduri'
DO WrLog WITH '  = ' + TRANSFORM(ROUND(lnT / MAX(lnN, 1) * 1000, 2)) + ' ms/cod'
DO WrLog WITH 'randuri intoarse: ' + TRANSFORM(IIF(USED('crsANAFTest'), RECCOUNT('crsANAFTest'), 0))
DO WrLog WITH 'apeluri ANAF (blocate de subclasa): ' + TRANSFORM(gnApeluriANAF)
DO WrLog WITH 'randuri NOI in ISTORIC_CODURI_FISCALE dupa rulare: ' + TRANSFORM(lnRandFinal - lnRandInit)
IF USED('crsANAFTest')
	SELECT sursa, COUNT(*) AS nr FROM crsANAFTest GROUP BY sursa INTO CURSOR crsSurse
	SELECT crsSurse
	SCAN
		DO WrLog WITH '  sursa [' + ALLTRIM(NVL(crsSurse.sursa, '')) + '] = ' + TRANSFORM(crsSurse.nr)
		SELECT crsSurse
	ENDSCAN
	USE IN (SELECT('crsSurse'))
ENDIF

*==========================================================
* B. descompunere pe faze
*==========================================================
DO WrLog WITH ''
DO WrLog WITH '=== B. descompunere pe faze ==='
LOCAL loVerB, lcAliasNorm, lnCui, lcCod, ldData, llGasit, lnFaraRasp
loVerB = CREATEOBJECT('VerificareANAFTimp')

lnT = SECONDS()
LOCAL lcOrdine
lcOrdine = loVerB.OrdineCacheReal('MASA')
DO WrLog WITH 'B1 OrdineCache(MASA) = ' + TRANSFORM(ROUND(SECONDS() - lnT, 3)) + ' s -> ' + lcOrdine

lnT = SECONDS()
=loVerB.ZileCache()
DO WrLog WITH 'B2 ZileCache = ' + TRANSFORM(ROUND(SECONDS() - lnT, 3)) + ' s'

lnT = SECONDS()
lcAliasNorm = loVerB.NormalizeazaCoduriCursor('cCoduriMasa', DATE())
DO WrLog WITH 'B3 NormalizeazaCoduriCursor = ' + TRANSFORM(ROUND(SECONDS() - lnT, 3)) + ' s'

lnT = SECONDS()
lcLista = ''
SELECT (lcAliasNorm)
SCAN FOR cui_n <> 0
	lcLista = lcLista + IIF(EMPTY(lcLista), '', ',') + ALLTRIM(STR(cui_n))
	SELECT (lcAliasNorm)
ENDSCAN
DO WrLog WITH 'B4 construire lista coduri = ' + TRANSFORM(ROUND(SECONDS() - lnT, 3)) + ' s'

IF USED('crsFazaB')
	USE IN crsFazaB
ENDIF
lnT = SECONDS()
=loVerB.CitesteIstoricPentruCoduri(lcLista, DATE(), 'crsFazaB', 'CACHE')
DO WrLog WITH 'B5 CitesteIstoricPentruCoduri (1 interogare) = ' + TRANSFORM(ROUND(SECONDS() - lnT, 3)) + ' s'
DO WrLog WITH '   randuri din cache: ' + TRANSFORM(IIF(USED('crsFazaB'), RECCOUNT('crsFazaB'), 0))

* bucla de Locate care alege codurile ramase (validare.prg:1939-1954)
lnT = SECONDS()
lnFaraRasp = 0
SELECT (lcAliasNorm)
SCAN
	lnCui = cui_n
	llGasit = .F.
	IF lnCui <> 0 AND USED('crsFazaB') AND RECCOUNT('crsFazaB') > 0
		SELECT crsFazaB
		LOCATE FOR cui = lnCui
		llGasit = FOUND()
	ENDIF
	IF !llGasit
		lnFaraRasp = lnFaraRasp + 1
	ENDIF
	SELECT (lcAliasNorm)
ENDSCAN
DO WrLog WITH 'B6 bucla Locate (2 treceri in cod real) = ' + TRANSFORM(ROUND(SECONDS() - lnT, 3)) + ' s'
DO WrLog WITH '   coduri neacoperite de cache: ' + TRANSFORM(lnFaraRasp)

lnT = SECONDS()
LOCAL lnSalvate
lnSalvate = loVerB.SalveazaIstoricDinCursor('crsFazaB', gnIdUtil)
lnT = SECONDS() - lnT
DO WrLog WITH 'B7 SalveazaIstoricDinCursor = ' + TRANSFORM(ROUND(lnT, 3)) + ' s pentru ' + TRANSFORM(lnSalvate) + ' randuri'
DO WrLog WITH '   = ' + TRANSFORM(ROUND(lnT / MAX(lnSalvate, 1) * 1000, 2)) + ' ms/rand (1 apel PL/SQL per rand)'

lnT = SECONDS()
IF USED('crsFazaB')
	SELECT crsFazaB
	SCAN FOR LEFT(NVL(sursa, ''), 5) == 'CACHE'
		goLog.Log('cache cui=' + TRANSFORM(cui) + ' sursa=' + ALLTRIM(sursa), 'testtimp')
		SELECT crsFazaB
	ENDSCAN
ENDIF
DO WrLog WITH 'B8 bucla de goLog pe randurile din cache = ' + TRANSFORM(ROUND(SECONDS() - lnT, 3)) + ' s'

*==========================================================
* C. costul brut al unui apel Oracle prin goExecutor
*==========================================================
DO WrLog WITH ''
DO WrLog WITH '=== C. cost apel Oracle prin goExecutor ==='
LOCAL lnRep
lnRep = MIN(lnN, 200)

lnT = SECONDS()
FOR lnI = 1 TO lnRep
	=goExecutor.oExecuta('begin null; end;')
ENDFOR
lnT = SECONDS() - lnT
DO WrLog WITH 'C1 ' + TRANSFORM(lnRep) + ' x [begin null; end;] cu goLog activ = ' + TRANSFORM(ROUND(lnT, 3)) + ' s'
DO WrLog WITH '   = ' + TRANSFORM(ROUND(lnT / lnRep * 1000, 2)) + ' ms/apel'

LOCAL lcLogVechi
lcLogVechi = goLog.cLogFile
goLog.cLogFile = 'D:\ROA\ROACONT\COMUN\utile\Teste\cache_anaf\_log_inexistent.txt'
lnT = SECONDS()
FOR lnI = 1 TO lnRep
	=goExecutor.oExecuta('begin null; end;')
ENDFOR
lnT = SECONDS() - lnT
DO WrLog WITH 'C2 ' + TRANSFORM(lnRep) + ' x [begin null; end;] fara goLog = ' + TRANSFORM(ROUND(lnT, 3)) + ' s'
DO WrLog WITH '   = ' + TRANSFORM(ROUND(lnT / lnRep * 1000, 2)) + ' ms/apel'
goLog.cLogFile = lcLogVechi

*==========================================================
* D. limita IN (...) din CitesteIstoricPentruCoduri
*==========================================================
DO WrLog WITH ''
DO WrLog WITH '=== D. limita listei IN (...) ==='
LOCAL lcLista1000, lcLista1001, llOk
lcLista1000 = ListaSintetica(1000)
lcLista1001 = ListaSintetica(1001)

lcSql = 'SELECT COUNT(*) AS N FROM ISTORIC_CODURI_FISCALE WHERE COD_FISCAL_N IN (' + lcLista1000 + ')'
llOk = (goExecutor.oExecute(lcSql, 'crsLim1') >= 1)
DO WrLog WITH 'D1 IN cu 1000 elemente: ' + IIF(llOk, 'OK', 'ESEC -> ' + goExecutor.cEroare)
IF USED('crsLim1')
	USE IN crsLim1
ENDIF

lcSql = 'SELECT COUNT(*) AS N FROM ISTORIC_CODURI_FISCALE WHERE COD_FISCAL_N IN (' + lcLista1001 + ')'
llOk = (goExecutor.oExecute(lcSql, 'crsLim2') >= 1)
DO WrLog WITH 'D2 IN cu 1001 elemente: ' + IIF(llOk, 'OK', 'ESEC -> ' + goExecutor.cEroare)
IF USED('crsLim2')
	USE IN crsLim2
ENDIF

* efectul in flux: lot de 1001 coduri, cache-ul pica, ANAF blocat -> plasa de siguranta
* face cate o interogare per cod
IF USED('cCoduri1001')
	USE IN cCoduri1001
ENDIF
CREATE CURSOR cCoduri1001 (cod_fiscal C(30) NULL, data D NULL)
SELECT cCoduriMasa
SCAN
	INSERT INTO cCoduri1001 (cod_fiscal, data) VALUES (cCoduriMasa.cod_fiscal, DATE())
	SELECT cCoduriMasa
ENDSCAN
FOR lnI = RECCOUNT('cCoduri1001') + 1 TO 1001
	INSERT INTO cCoduri1001 (cod_fiscal, data) VALUES (ALLTRIM(STR(9000000 + lnI)), DATE())
ENDFOR
DO WrLog WITH 'D3 lot de ' + TRANSFORM(RECCOUNT('cCoduri1001')) + ' coduri (peste limita IN)'
gnApeluriANAF = 0
gcMockUltimMesaj = ''
lnT = SECONDS()
=loVer.VerificaListaCIF('cCoduri1001', DATE(), 'crsANAF1001', 'MASA')
lnT = SECONDS() - lnT
DO WrLog WITH 'D4 TOTAL VerificaListaCIF pe 1001 coduri = ' + TRANSFORM(ROUND(lnT, 3)) + ' s'
DO WrLog WITH '   randuri intoarse: ' + TRANSFORM(IIF(USED('crsANAF1001'), RECCOUNT('crsANAF1001'), 0))
DO WrLog WITH '   apeluri ANAF (blocate): ' + TRANSFORM(gnApeluriANAF)
DO WrLog WITH '   ultim dialog modal interceptat: [' + LEFT(gcMockUltimMesaj, 120) + ']'

*==========================================================
* E. bucla de completare din apelant (overificari.vc2)
*==========================================================
DO WrLog WITH ''
DO WrLog WITH '=== E. completarea tabelului in apelant (do_verifica) ==='
IF !USED('crsANAFTest') OR RECCOUNT('crsANAFTest') = 0
	DO WrLog WITH 'E: sarit - nu am rezultate de completat'
ELSE
	DO ConstruiestePart WITH lnN
	LOCAL loVerificare, ldDataE
	loVerificare = CREATEOBJECT('verificarecod', .F., .F.)
	ldDataE = DATE()

	lnT = SECONDS()
	SELECT crsANAFTest
	SCAN
		SCATTER NAME loRec
		WITH loRec
			SELECT crsPartTest
			LOCATE FOR ALLTRIM(STRTRAN(cod_fiscal, loVerificare.GetCodTara(cod_fiscal), '')) = ALLTRIM(STR(.cui)) AND (EMPTY(NVL(data, {})) OR data = ldDataE)
			IF FOUND()
				REPLACE firma WITH .denumire, adresa WITH .adresa, stare WITH .mesaj, ;
					cod WITH ALLTRIM(STR(.cui)), tvaincasare WITH .tvaincasare, ;
					splittva WITH .splittva, inactiv WITH .inactiv
			ENDIF
		ENDWITH
		SELECT crsANAFTest
	ENDSCAN
	lnT = SECONDS() - lnT
	DO WrLog WITH 'E1 completare cu LOCATE + UDF (cod real) = ' + TRANSFORM(ROUND(lnT, 3)) + ' s'
	DO WrLog WITH '   ' + TRANSFORM(RECCOUNT('crsANAFTest')) + ' rezultate x ' + TRANSFORM(RECCOUNT('crsPartTest')) + ' randuri in tabel'

	* aceeasi completare, pe cursor indexat pe codul normalizat (reper pentru cat s-ar putea castiga)
	DO ConstruiestePart WITH lnN
	lnT = SECONDS()
	SELECT crsPartTest
	REPLACE ALL cod_fiscalfro WITH ALLTRIM(STRTRAN(STRTRAN(UPPER(NVL(cod_fiscal, '')), 'RO', ''), ' ', ''))
	INDEX ON cod_fiscalfro TAG cfro
	SELECT crsANAFTest
	SCAN
		SCATTER NAME loRec
		WITH loRec
			IF SEEK(PADR(ALLTRIM(STR(.cui)), 30), 'crsPartTest', 'cfro')
				SELECT crsPartTest
				REPLACE firma WITH .denumire, adresa WITH .adresa, stare WITH .mesaj, ;
					cod WITH ALLTRIM(STR(.cui)), tvaincasare WITH .tvaincasare, ;
					splittva WITH .splittva, inactiv WITH .inactiv
			ENDIF
		ENDWITH
		SELECT crsANAFTest
	ENDSCAN
	lnT = SECONDS() - lnT
	DO WrLog WITH 'E2 aceeasi completare pe cursor indexat (SEEK) = ' + TRANSFORM(ROUND(lnT, 3)) + ' s'
ENDIF

*==========================================================
* curatenie
*==========================================================
DO WrLog WITH ''
DO CurataIstoricTimp
DO WrLog WITH 'GATA ' + TTOC(DATETIME())
QUIT


PROCEDURE WrLog
	LPARAMETERS tcText
	STRTOFILE(TRANSFORM(tcText) + CHR(13) + CHR(10), gcTestLog, .T.)
ENDPROC

PROCEDURE ErrTimp
	LPARAMETERS tnError, tcMessage, tcProgram, tnLine
	DO WrLog WITH 'EROARE ' + TRANSFORM(tnError) + ' [' + TRANSFORM(tcMessage) + '] in ' + ;
		TRANSFORM(tcProgram) + ' linia ' + TRANSFORM(tnLine)
	RETURN
ENDPROC

FUNCTION NrRanduriIstoric
	LOCAL lnRez
	lnRez = 0
	IF goExecutor.oExecuta('SELECT COUNT(*) AS N FROM ISTORIC_CODURI_FISCALE', 'crsNrIst')
		lnRez = crsNrIst.N
		USE IN (SELECT('crsNrIst'))
	ENDIF
	RETURN lnRez
ENDFUNC

FUNCTION ListaSintetica
	LPARAMETERS tnCate
	LOCAL lcRez, lnJ
	lcRez = ''
	FOR lnJ = 1 TO tnCate
		lcRez = lcRez + IIF(EMPTY(lcRez), '', ',') + ALLTRIM(STR(8000000 + lnJ))
	ENDFOR
	RETURN lcRez
ENDFUNC

PROCEDURE ConstruiestePart
	LPARAMETERS tnCate
	LOCAL lnK
	IF USED('crsPartTest')
		USE IN crsPartTest
	ENDIF
	CREATE CURSOR crsPartTest (ales L, denumire C(100) NULL, cod_fiscal C(30) NULL, Valid L NULL, ;
		firma C(100) NULL, cod C(100) NULL, adresa C(250) NULL, judet C(100) NULL, regcom C(30) NULL, ;
		datatvamfin C(30) NULL, platitortvamfin L NULL, IsCIF L NULL, duplicat L, atribut_fiscal C(2), ;
		stare C(100), atentie C(100), cod_fiscalfro C(30) NULL, tvaincasare L, splittva L, inactiv L, Data D)
	SELECT cCoduriMasa
	SCAN
		INSERT INTO crsPartTest (cod_fiscal, denumire, Valid, IsCIF, Data) ;
			VALUES (cCoduriMasa.cod_fiscal, 'PARTENER ' + ALLTRIM(NVL(cCoduriMasa.cod_fiscal, '')), .T., .T., DATE())
		SELECT cCoduriMasa
	ENDSCAN
ENDPROC

PROCEDURE CurataIstoricTimp
	LOCAL lnSterse
	IF TYPE('gnIdMaxIstoric') <> 'N' OR gnIdMaxIstoric <= 0
		DO WrLog WITH 'curatenie SARITA - watermark invalid'
		RETURN
	ENDIF
	lnSterse = goExecutor.oExecuta('DELETE FROM ISTORIC_CODURI_FISCALE WHERE ID > ' + TRANSFORM(gnIdMaxIstoric))
	=goExecutor.oExecuta('COMMIT')
	DO WrLog WITH 'curatenie: sterse randurile cu ID > ' + TRANSFORM(gnIdMaxIstoric)
ENDPROC


*** executor care nu deschide formularul modal de eroare (altfel headless se blocheaza)
DEFINE CLASS oexec_fara_dialog_t AS oexecutor

	FUNCTION oExecuta
		LPARAMETERS tcSql, tcCursor, tlProgress, tcTitluProgress, tnHandle, tlShowError, tlQuitOnError, tlReconnect
		LOCAL lcSql, lcCursor, lnHandle, lnRez
		lcSql = IIF(EMPTY(tcSql), This.cSql, tcSql)
		lcCursor = IIF(EMPTY(tcCursor), This.cCursor, tcCursor)
		lnHandle = IIF(EMPTY(tnHandle), This.nHandle, tnHandle)
		lnRez = This.oExecute(lcSql, lcCursor, tlProgress, tcTitluProgress, lnHandle)
		IF lnRez < 1
			gnErorriSQL = gnErorriSQL + 1
			gcUltimaEroareSQL = TRANSFORM(This.cEroare)
		ENDIF
		RETURN (lnRez >= 1)
	ENDFUNC

ENDDEFINE


*** subclasa de test: blocheaza ANAF-ul real si expune OrdineCache-ul real sub alt nume
DEFINE CLASS VerificareANAFTimp AS VerificareANAF

	PROCEDURE OrdineCache
		LPARAMETERS tcTraseu
		RETURN 'CACHE,ANAF'
	ENDPROC

	PROCEDURE OrdineCacheReal
		LPARAMETERS tcTraseu
		RETURN VerificareANAF::OrdineCache(tcTraseu)
	ENDPROC

	PROCEDURE ANAF_SincronWebService_PlatitorTva
		LPARAMETERS tcCursorListaCIF, tdData, tcAlias
		gnApeluriANAF = gnApeluriANAF + 1
		RETURN IIF(EMPTY(tcAlias), 'crsANAF', tcAlias)
	ENDPROC

ENDDEFINE
