* test_valuta_dvi_usd.prg
* Scenariu raportat de Marius (runda7, COMUN\clase\ointroduceri.vcx, clasa import_nota):
* document secundar intr-o ALTA valuta decat principala trebuie convertit prin lei
* (suma/This.oact.Curs), nu adunat direct la baza in valuta principalei.
*   Doc1 (principal) FACTURA 15000 RAJA, 1000 EUR curs 5.2300 (5230 lei), in_valuta,
*        participa la pret, TVA pe DVI ('D'): DVI 101 BIROUL VAMAL, tva 1098.30 lei / 210 EUR,
*        explicatie ACH. IMP. 21%.
*   Doc2 (secundar) DVI 101 BIROUL VAMAL, 100 USD curs 4.0000 (400 lei), in_valuta (USD -
*        id_valuta DIFERIT de EUR), participa la pretul in valuta, TVA normal ('F') proprie
*        84 lei / 21 USD (autocalculata din sablon cu_tva).
*   Articol: A8/371 (mock_cauta_nom_articole, cont 371 - substituie A-TEST din cerinta,
*        acelasi cont), cantitate 1, pret_val 1000 (1000 EUR).
* Asteptat dupa fix (procent_val/nbaza_val NU mai aduna suma_val a doc2 direct la baza EUR,
* ci Round(suma/curs,2)=76.48 EUR-echivalent):
*   procent_val ~= 107.648, nbaza_val ~= 1076.48, rul_temp.pretd ~= 1076.48 / pret ~= 5629.99,
*   S-ul (371) al doc2 explicatia5 ~= '7.65', randul D (diferenta) ~= 0, ntva_val ~= 226.06.
*
* Rulare:
*   powershell -ExecutionPolicy Bypass -File test_valuta_dvi_usd.ps1

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

PUBLIC gcUILog, gcSyncDir
gcUILog  = "D:\ROA\ROAGEST\COMUN\utile\Teste\achizitie_import\test_valuta_dvi_usd_log.txt"
gcSyncDir = "D:\ROA\ROAGEST\COMUN\utile\Teste\achizitie_import\uisync_valuta_usd\"
STRTOFILE("START " + TTOC(DATETIME()) + CHR(13)+CHR(10), gcUILog)

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

TRY
	LOCAL gcAppPath, lcPath
	gcAppPath = "D:\ROA\ROAGEST\"
	SET DEFAULT TO (gcAppPath)

	lcPath = gcAppPath + 'Date;' + gcAppPath + 'Include;' + gcAppPath + 'FERESTRE;' + ;
		gcAppPath + 'GRAFICE;' + gcAppPath + 'CLASE;' + gcAppPath + 'MENIURI;' + ;
		gcAppPath + 'PROGRAME;' + gcAppPath + 'RAPOARTE;' + gcAppPath + 'COMUN;' + ;
		gcAppPath + 'COMUN\CLASE;' + gcAppPath + 'COMUN\FERESTRE;' + gcAppPath + 'COMUN\PROGRAME;' + ;
		gcAppPath + 'COMUN\GRAFICE;' + gcAppPath + 'COMUN\RAPOARTE;' + gcAppPath + 'COMUN\MENIURI;' + ;
		gcAppPath + 'COMUN\UTILE\GRIDEXTRAS;' + gcAppPath + 'COMUN\UTILE\CTL32;' + ;
		gcAppPath + 'COMUN\UTILE\HPDF;' + gcAppPath + 'COMUN\UTILE\HPDF\REPORTOUTPUT;' + ;
		gcAppPath + 'COMUN\UTILE\WEB;' + gcAppPath + 'COMUN\UTILE\EXCEL;' + ;
		ADDBS(SUBSTR(gcAppPath,1,RAT([\],gcAppPath,2)))+[COMUNROA\]
	SET PATH TO &lcPath ADDITIVE
	DO DcLog WITH 'SET PATH OK'

	*----- CLASE -----
	SET CLASSLIB TO (gcAppPath + "comun\clase\appwiz") ADDITIVE
	SET CLASSLIB TO GESTIUNI ADDITIVE
	SET CLASSLIB TO CAUT ADDITIVE
	SET CLASSLIB TO BAZA ADDITIVE
	SET CLASSLIB TO comun ADDITIVE
	SET CLASSLIB TO accessibility.vcx ADDITIVE
	SET CLASSLIB TO messagebox ADDITIVE
	SET CLASSLIB TO registry ADDITIVE
	SET CLASSLIB TO cauta_alfa_forms.vcx ADDITIVE
	SET CLASSLIB TO DECABAZA ADDITIVE
	SET CLASSLIB TO onomenclatoare ADDITIVE
	SET CLASSLIB TO stocuri.vcx ADDITIVE
	SET CLASSLIB TO rulaje.vcx ADDITIVE
	SET CLASSLIB TO ointroduceri ADDITIVE
	SET CLASSLIB TO ointroduceri_web ADDITIVE
	SET CLASSLIB TO ointroduceri_depozit ADDITIVE
	SET CLASSLIB TO overificari ADDITIVE
	SET CLASSLIB TO ferestre_oracle ADDITIVE
	SET CLASSLIB TO ferestre_cere_date.vcx ADDITIVE
	SET CLASSLIB TO configurare.vcx ADDITIVE
	SET CLASSLIB TO serii_numere.vcx ADDITIVE
	SET CLASSLIB TO omodificari.vcx ADDITIVE
	SET CLASSLIB TO ocompensari.vcx ADDITIVE
	SET CLASSLIB TO caut_ora ADDITIVE
	SET CLASSLIB TO onote_contabile ADDITIVE
	SET CLASSLIB TO otoolbar ADDITIVE
	SET CLASSLIB TO bon_fisc ADDITIVE
	SET CLASSLIB TO onom_articole ADDITIVE
	SET CLASSLIB TO onom_retete ADDITIVE
	SET CLASSLIB TO orapoarte ADDITIVE
	SET CLASSLIB TO orapoarte_gestiuni ADDITIVE
	SET CLASSLIB TO orapoarte_parametri ADDITIVE
	SET CLASSLIB TO ONOM_CURS ADDITIVE
	SET CLASSLIB TO ctl32_statusbar_fals.vcx ADDITIVE
	SET CLASSLIB TO ctl32_common.vcx ADDITIVE
	SET CLASSLIB TO ctl32_structs.vcx ADDITIVE
	SET CLASSLIB TO ctl32_progressbar.vcx ADDITIVE
	SET CLASSLIB TO ctl32_balloontip.vcx ADDITIVE
	SET CLASSLIB TO ocriterii.vcx ADDITIVE
	SET CLASSLIB TO oavize.vcx ADDITIVE
	SET CLASSLIB TO onomenclatoare2 ADDITIVE
	SET CLASSLIB TO wwdialogs.vcx ADDITIVE
	SET CLASSLIB TO oimportxml.vcx ADDITIVE
	SET CLASSLIB TO excelxml.vcx ADDITIVE
	SET CLASSLIB TO orapoarte_obinv.vcx ADDITIVE
	DO DcLog WITH 'SET CLASSLIB OK'

	*----- PROCEDURI (mock-uri PRIMELE, ui_harness la final) -----
	SET PROCEDURE TO PROCEDURI
	SET PROCEDURE TO "D:\ROA\ROAGEST\COMUN\utile\Teste\mock_amessagebox.prg" ADDITIVE
	SET PROCEDURE TO "D:\ROA\ROAGEST\COMUN\utile\Teste\mock_cauta_nom_articole.prg" ADDITIVE
	SET PROCEDURE TO "D:\ROA\ROAGEST\COMUN\utile\Teste\achizitie_import\mock_caut_valuta.prg" ADDITIVE
	SET PROCEDURE TO acces_meniu ADDITIVE
	SET PROCEDURE TO cauta_alfa ADDITIVE
	SET PROCEDURE TO pmenu ADDITIVE
	SET PROCEDURE TO proceduri_comune ADDITIVE
	SET PROCEDURE TO quitapp ADDITIVE
	SET PROCEDURE TO init_program ADDITIVE
	SET PROCEDURE TO oproceduri_listari.prg ADDITIVE
	SET PROCEDURE TO oproceduri_configurare.prg ADDITIVE
	SET PROCEDURE TO oproceduri_articole.prg ADDITIVE
	SET PROCEDURE TO oproceduri_retete.prg ADDITIVE
	SET PROCEDURE TO orapoarte.prg ADDITIVE
	SET PROCEDURE TO mesaje ADDITIVE
	SET PROCEDURE TO oserii_numere.prg ADDITIVE
	SET PROCEDURE TO oexport.prg ADDITIVE
	SET PROCEDURE TO wwConfig.prg ADDITIVE
	SET PROCEDURE TO proceduri_rapoarte.prg ADDITIVE
	SET PROCEDURE TO OPROCEDURI_CURS.PRG ADDITIVE
	SET PROCEDURE TO validare.prg ADDITIVE
	SET PROCEDURE TO GENCURSOR.PRG ADDITIVE
	SET PROCEDURE TO OPROCEDURI_COMUNE.PRG ADDITIVE
	SET PROCEDURE TO OINIT_OPTIUNI.PRG ADDITIVE
	SET PROCEDURE TO updateserver.prg ADDITIVE
	SET PROCEDURE TO oinainte_de.prg ADDITIVE
	SET PROCEDURE TO ooperatii_comune.prg ADDITIVE
	SET PROCEDURE TO Ocompensari.PRG ADDITIVE
	SET PROCEDURE TO OPROCEDURI_aMS.PRG ADDITIVE
	SET PROCEDURE TO oproceduri_rulaje ADDITIVE
	SET PROCEDURE TO oproceduri_stocuri ADDITIVE
	SET PROCEDURE TO OINTRODUCERI ADDITIVE
	SET PROCEDURE TO oHeader.prg ADDITIVE
	SET PROCEDURE TO proceduri_excel.PRG ADDITIVE
	SET PROCEDURE TO onomenclatoare.PRG ADDITIVE
	SET PROCEDURE TO osecurity ADDITIVE
	SET PROCEDURE TO ocautare ADDITIVE
	SET PROCEDURE TO orefaceri ADDITIVE
	SET PROCEDURE TO ofacturare_comun.PRG ADDITIVE
	SET PROCEDURE TO ofacturare_stoc.PRG ADDITIVE
	SET PROCEDURE TO oproceduri_casademarcat ADDITIVE
	SET PROCEDURE TO oproceduri_casa_marcat_e500 ADDITIVE
	SET PROCEDURE TO oproceduri_casa_marcat_mp500 ADDITIVE
	SET PROCEDURE TO oproceduri_util.prg ADDITIVE
	SET PROCEDURE TO wwxmlhttp.prg ADDITIVE
	SET PROCEDURE TO ini.prg ADDITIVE
	SET PROCEDURE TO odocumente.prg ADDITIVE
	SET PROCEDURE TO regex.prg ADDITIVE
	SET PROCEDURE TO wwutils.prg ADDITIVE
	SET PROCEDURE TO inchidere_k ADDITIVE
	SET PROCEDURE TO iniacces.prg ADDITIVE
	SET PROCEDURE TO oupdate.prg ADDITIVE
	SET PROCEDURE TO procese.prg ADDITIVE
	SET PROCEDURE TO version.prg ADDITIVE
	SET PROCEDURE TO xmlaccess.prg ADDITIVE
	SET PROCEDURE TO xmlparser.prg ADDITIVE
	SET PROCEDURE TO filebringer.prg ADDITIVE
	SET PROCEDURE TO wwcodeupdate.prg ADDITIVE
	SET PROCEDURE TO wwhttp.prg ADDITIVE
	SET PROCEDURE TO xdate.prg ADDITIVE
	SET PROCEDURE TO ofacturare.prg ADDITIVE
	SET PROCEDURE TO oproceduri_obinv.prg ADDITIVE
	SET PROCEDURE TO oproceduri_facturare.prg ADDITIVE
	SET PROCEDURE TO email.prg ADDITIVE
	SET PROCEDURE TO "D:\ROA\ROAGEST\COMUN\utile\Teste\ui_harness.prg" ADDITIVE
	DO DcLog WITH 'SET PROCEDURE OK'

	*----- goMockValuta: rezultatul FIX al caut_valuta mock (capcana l - construit INLINE);
	*      implicit EUR (moneda documentului principal) - caut_valuta nu e invocat direct in
	*      fluxul acestui test (id_valuta/curs se seteaza direct pe dialog, ca in AdaugaDoc*),
	*      dar mock-ul e incarcat pentru orice apel intern neasteptat. -----
	PUBLIC goMockValuta
	goMockValuta = CREATEOBJECT('Custom')
	goMockValuta.AddProperty('id_valuta', 978)
	goMockValuta.AddProperty('nume_val', 'EUR')

	*----- Globale -----
	PUBLIC gnPc, gnPval, gnPcant, gnPpret, gnPPretval, gnPCurs, gnPVal, gnPPretV, gnPPretVal
	STORE 2 TO gnPc, gnPval, gnPVal
	gnPcant = 3
	STORE 4 TO gnPpret, gnPPretval, gnPPretVal, gnPPretV, gnPCurs
	PUBLIC gl406, gcS, gnAn, gnLuna, gnIdFirma, gnIdSucursala, gcAcces, gcFirma
	gl406 = .T.
	gcS = 'CONTAFIN'
	gnAn = YEAR(DATE())
	gnLuna = MONTH(DATE())
	gnIdFirma = 110
	gnIdSucursala = 110
	gcAcces = "1;2;3;4;5;6;7;8;"
	gcFirma = gcS
	PUBLIC nror(65000)

	PUBLIC gnButon
	STORE 2 TO gnButon
	PUBLIC gcMockArtCodmat, gcMockAcontCrt
	gcMockArtCodmat = ''
	gcMockAcontCrt = ''
	PUBLIC gnMockRaspuns
	gnMockRaspuns = 6

	PUBLIC goExecutor, goApp
	goExecutor = CREATEOBJECT('dummyexecutor')
	goApp = CREATEOBJECT('dummyapp')

	*----- poAct: antetul notei (moneda principala EUR, curs 5.23); dialogul mosteneste din el la Init -----
	PUBLIC poAct
	poAct = CREATEOBJECT('Custom')
	poAct.AddProperty('nume_val', 'EUR')
	poAct.AddProperty('curs', 5.23)
	poAct.AddProperty('proc_tva', 1.21)
	poAct.AddProperty('nnir', 0)
	poAct.AddProperty('id_valuta', 978)
	poAct.AddProperty('id_fdoc', 1)
	poAct.AddProperty('fdoc', 'Factura')
	poAct.AddProperty('id_partc', 601)
	poAct.AddProperty('partc', 'RAJA')
	poAct.AddProperty('serie_act', '')
	poAct.AddProperty('dataact', DATE())
	poAct.AddProperty('tva_incasare', 0)
	poAct.AddProperty('id_set', 1)
	poAct.AddProperty('id_gestin', 1)

	*----- jtva_coloane2 / saft_taxtable: perechi reale 21% (Oracle dev, vjtva_coloane) -----
	IF USED('jtva_coloane2')
		USE IN ('jtva_coloane2')
	ENDIF
	CREATE CURSOR jtva_coloane2 (ordine N(8), id_jtva_coloana N(14), denumire C(100), ;
		jc N(1), jv N(1), afisat N(1), coloana_jc C(20), coloana_jv C(20), cota_tva N(6,2), id_tva N(14))
	INSERT INTO jtva_coloane2 VALUES (0, 0, '', 0, 0, 1, '', '', 0, 0)
	INSERT INTO jtva_coloane2 VALUES (1, 208, 'ACH. INT. 21%', 1, 0, 1, 'RO21B', 'RO21T', 21, 209)
	INSERT INTO jtva_coloane2 VALUES (2, 209, 'TVA ACH. INT. 21%', 1, 0, 1, 'RO21T', '', 21, 0)
	INSERT INTO jtva_coloane2 VALUES (3, 220, 'ACH. IMP. 21%', 1, 0, 1, 'FO21B', 'FO21T', 21, 221)
	INSERT INTO jtva_coloane2 VALUES (4, 221, 'TVA ACH. IMP. 21%', 1, 0, 1, 'FO21T', '', 21, 0)

	IF USED('saft_taxtable')
		USE IN ('saft_taxtable')
	ENDIF
	CREATE CURSOR saft_taxtable (taxname C(250) NULL, typename C(250) NULL, taxcode N(6) NULL, ;
		taxtype N(3) NULL, descriere C(250) NULL, tip C(100) NULL, descriere_tip C(250) NULL, ;
		procent_taxa N(7,2) NULL, procent_prorata N(7,2) NULL, inactiv N(1) NULL, tva N(1) NULL, ;
		wht N(1) NULL, tva_achizitii N(1) NULL, tva_livrari N(1) NULL)
	INDEX ON taxcode TAG taxcode
	INSERT INTO saft_taxtable (taxname, taxcode, descriere, procent_taxa, tva, wht, tva_achizitii, tva_livrari) ;
		VALUES ('', 0, '', 0, 1, 1, 1, 1)
	INSERT INTO saft_taxtable (taxname, taxcode, descriere, procent_taxa, tva, wht, tva_achizitii, tva_livrari) ;
		VALUES ('301104-Achizitii de bunuri si servicii taxabile cu cota de 21%, altele decat importurile si cele supuse masurilor de simplificare', 301104, '', 21, 1, 0, 1, 0)
	INSERT INTO saft_taxtable (taxname, taxcode, descriere, procent_taxa, tva, wht, tva_achizitii, tva_livrari) ;
		VALUES ('301204-Import de bunuri cota 21%', 301204, '', 21, 1, 0, 1, 0)

	DO CreeazaIntrodc WITH 'introdc'
	DO CreeazaIntrodc WITH 'introdc_sablon'
	INSERT INTO introdc_sablon (scd, scc, cu_tva, ordine, id_set, participa_valuta, tip_rand, ;
			id_jtva_coloana, ptva, explicatie_tva) ;
		VALUES ('371', '401', 1, 1, 1, .T., 'B', 208, 21, 'ACH. INT. 21%')
	INSERT INTO introdc_sablon (scd, scc, cu_tva, ordine, id_set, participa_valuta, tip_rand, ;
			id_jtva_coloana, ptva, explicatie_tva) ;
		VALUES ('4426', '401', 1, 2, 1, .T., 'T', 209, 21, 'TVA ACH. INT. 21%')
	GO TOP IN introdc_sablon

	DO CreeazaRulTemp
	INSERT INTO rul_temp (denumire, codmat, cant, pret, pret_lei, cont, cota_tva) ;
		VALUES ('PLACEHOLDER', 'PH', 1, 1, 1, '371', 21)

	*-- F1 (ointroduceri.prg): index ord_doc INAINTE de CREATEOBJECT - vezi docs/testare-ui-vfp.md capcana p.
	SELECT introdc
	INDEX ON Str(Nvl(nr_doc,0),8) + Icase(tip_rand='B','1', tip_rand='S','2', tip_rand='G','3', tip_rand='T','4', tip_rand='D','5', '6') + Padr(Nvl(scd,''),10) TAG ord_doc
	SET ORDER TO ord_doc

	DO DcLog WITH 'cursoare pregatite, CREATEOBJECT(import_nota, .F.) - lIntern=.F. (import)'
	PUBLIC goObj
	goObj = CREATEOBJECT('IMPORT_nota', .F.)
	IF VARTYPE(goObj) <> 'O'
		DO DcLog WITH 'FAIL: instantiere import_nota'
		DO HarnessDone WITH 'done-error'
		QUIT
	ENDIF
	goObj.lDialogAratat = .T.
	goObj.oact = poAct
	*-- lSpargeSecundare=.T.: doc2 (DVI, USD) participa la pret in alta valuta si trebuie
	*-- SPART pe cont (371), altfel nu apare randul S verificat (explicatia5).
	goObj.lSpargeSecundare = .T.
	goObj.WindowType = 0
	goObj.Visible = .T.
	goObj.Show()
	goObj.WindowState = 2
	DOEVENTS FORCE

	SELECT rul_temp
	ZAP
	goObj.gridart.Refresh()
	DOEVENTS FORCE

	*========================= DOC 1 (principal, FACTURA EUR + DVI referinta), DOC 2 (secundar, DVI USD) =========================
	PUBLIC goDlg, goT
	DO AdaugaDoc1
	DO VerificaPereche WITH 15000, 5230, 1000, 'EUR'
	DO AdaugaDoc2
	DO VerificaPereche WITH 101, 400, 100, 'USD'

	DO DcLog WITH 'dump introdc dupa cele 2 documente (inainte de articol):'
	DO DumpIntrodc

	DO HarnessStep WITH 0, 'dupa 2 documente: introdc=' + TRANSFORM(RECCOUNT_ACTIVE('introdc')) + ' randuri'

	*========================= ARTICOL (flux real do_adauga_articol) - A8/371 substituie A-TEST/371 =========================
	gcMockArtCodmat = 'ART-A8-371'
	gcMockAcontCrt = '4'
	TRY
		goObj.do_adauga_articol()
	CATCH TO loExcA1
		DO DcLog WITH 'EROARE do_adauga_articol (A8/371) ' + TRANSFORM(loExcA1.ErrorNo) + ' [' + loExcA1.Message + '] in ' + loExcA1.Procedure + ':' + TRANSFORM(loExcA1.LineNo)
	ENDTRY
	DOEVENTS FORCE
	SELECT rul_temp
	LOCATE FOR ALLTRIM(codmat) == 'ART-A8-371'
	IF FOUND()
		REPLACE cant WITH 1, pret_val WITH 1000, pretd WITH 1000, pret WITH ROUND(1000*5.23,4), pret_lei WITH ROUND(1000*5.23,4)
		DO DcLog WITH 'articol (371) adaugat, cant/pret completate (1000 EUR / ' + TRANSFORM(ROUND(1000*5.23,4)) + ' lei)'
	ELSE
		DO DcLog WITH 'FAIL: articolul nu a fost adaugat de do_adauga_articol()'
	ENDIF
	goObj.gridart.Refresh()
	DOEVENTS FORCE

	DO HarnessStep WITH 1, 'dupa adaugare articol, rul_temp=' + TRANSFORM(RECCOUNT_ACTIVE('rul_temp'))

	*========================= SINCRONIZARE =========================
	LOCAL llEroareSync
	llEroareSync = .F.
	TRY
		goObj.sincronizeaza()
	CATCH TO loExcS1
		llEroareSync = .T.
		DO DcLog WITH 'EROARE la sincronizeaza() ' + TRANSFORM(loExcS1.ErrorNo) + ' [' + loExcS1.Message + '] in ' + loExcS1.Procedure + ':' + TRANSFORM(loExcS1.LineNo) + ' (' + loExcS1.LineContents + ')'
	ENDTRY
	DOEVENTS FORCE
	goObj.grid1.Refresh()
	IF !llEroareSync
		DO DcLog WITH 'PASS sincronizare: sincronizeaza() fara eroare'
	ELSE
		DO DcLog WITH 'FAIL sincronizare: sincronizeaza() a aruncat eroare'
	ENDIF
	DO DcLog WITH 'dump introdc dupa sincronizare:'
	DO DumpIntrodc

	DO HarnessStep WITH 2, 'dupa sincronizare, introdc=' + TRANSFORM(RECCOUNT_ACTIVE('introdc')) + ' randuri'

	*========================= ASSERT-URI =========================
	PRIVATE pnAsserts, pnPass
	STORE 0 TO pnAsserts, pnPass

	DO DcLog WITH 'goObj.procent_val=' + TRANSFORM(goObj.procent_val) + ' goObj.nbaza_val=' + TRANSFORM(goObj.nbaza_val) + ' goObj.ntva_val=' + TRANSFORM(goObj.ntva_val)
	DO Assert3 WITH '1-procent_val (astept 107.648, NU 110)', goObj.procent_val, 107.648
	DO Assert3 WITH '2-nbaza_val (astept 1076.48, NU 1100)', goObj.nbaza_val, 1076.48
	DO Assert3 WITH '6-ntva_val (astept 226.06, NU 231)', goObj.ntva_val, 226.06

	SELECT rul_temp
	LOCATE FOR ALLTRIM(codmat) == 'ART-A8-371'
	IF FOUND()
		DO DcLog WITH 'rul_temp: pretd=' + TRANSFORM(pretd) + ' pret=' + TRANSFORM(pret)
		DO Assert3 WITH '3a-rul_temp.pretd (astept 1076.48, NU 1100)', pretd, 1076.48
		DO Assert3 WITH '3b-rul_temp.pret (astept 5629.99, NU 5753)', pret, 5629.99
	ELSE
		pnAsserts = pnAsserts + 2
		DO DcLog WITH '  FAIL 3a/3b: nu am gasit articolul ART-A8-371 in rul_temp'
	ENDIF

	SELECT introdc
	LOCATE FOR nract = 101 AND ALLTRIM(fdoc) == 'DVI' AND tip_rand == 'S' AND ALLTRIM(scd) == '371'
	IF FOUND()
		DO DcLog WITH 'S doc2 (nract=101,scd=371): explicatia5=[' + ALLTRIM(NVL(explicatia5,'')) + ']'
		DO AssertStr WITH '4-explicatia5 S doc2 (astept 7.65, NU 10.00)', ALLTRIM(NVL(explicatia5,'')), '7.65'
	ELSE
		pnAsserts = pnAsserts + 1
		DO DcLog WITH '  FAIL 4: nu am gasit randul S (nract=101, fdoc=DVI, scd=371)'
	ENDIF

	SELECT introdc
	LOCATE FOR tip_rand == 'D'
	IF FOUND()
		DO DcLog WITH 'randul D (diferenta): suma=' + TRANSFORM(suma)
		DO Assert3 WITH '5-diferenta D (|suma|<=0.02, inainte de fix era -123)', ABS(suma), 0
	ELSE
		DO DcLog WITH '  INFO 5: nu exista rand D (diferenta 0, D a fost sters de recalc_diferente) - OK'
		pnAsserts = pnAsserts + 1
		pnPass = pnPass + 1
	ENDIF

	LOCAL llValidSume
	llValidSume = goObj.valideaza_sume()
	DO DcLog WITH '7-valideaza_sume()=' + TRANSFORM(llValidSume) + ' cmesajsync=[' + ALLTRIM(NVL(goObj.cmesajsync,'')) + ']'
	pnAsserts = pnAsserts + 1
	IF llValidSume AND EMPTY(ALLTRIM(NVL(goObj.cmesajsync,'')))
		pnPass = pnPass + 1
		DO DcLog WITH '  PASS 7-valideaza_sume (.T., cmesajsync gol)'
	ELSE
		DO DcLog WITH '  FAIL 7-valideaza_sume (' + TRANSFORM(llValidSume) + ', cmesajsync=[' + ALLTRIM(NVL(goObj.cmesajsync,'')) + '])'
	ENDIF

	*========================= PAS NOU: schimbare curs pe randul S(371) al DVI USD (nract=101) - resincronizare (runda8) =========================
	LOCAL lcDocKeyDvi2
	lcDocKeyDvi2 = ''
	SELECT introdc
	LOCATE FOR nract = 101 AND ALLTRIM(fdoc) == 'DVI' AND tip_rand == 'S' AND ALLTRIM(scd) == '371'
	DO Assert3 WITH '8-rand S DVI USD (371) gasit inainte de schimbare curs', IIF(FOUND(),1,0), 1
	IF FOUND()
		lcDocKeyDvi2 = ALLTRIM(NVL(introdc.doc_key,''))
		DO DcLog WITH 'PAS-curs: pozitionat pe randul S (nract=101,scd=371), curs INAINTE=' + TRANSFORM(introdc.curs) + ' doc_key=[' + lcDocKeyDvi2 + ']'

		goObj.grid1.cCurs.text1.Value = 4.50
		goObj.grid1.cCurs.text1.Valid()

		DO Assert3 WITH '9-armare lSyncPending=.T. dupa Valid curs (pre-DOEVENTS)', IIF(goObj.lSyncPending,1,0), 1
		DO Assert3 WITH '10-armare tmrSync.Interval>0 dupa Valid curs (pre-DOEVENTS)', IIF(goObj.tmrSync.Interval>0,1,0), 1

		DOEVENTS FORCE

		DO Assert3 WITH '11-sync consumat lSyncPending=.F. dupa DOEVENTS', IIF(goObj.lSyncPending,1,0), 0
		DO Assert3 WITH '12-sync consumat tmrSync.Interval=0 dupa DOEVENTS', goObj.tmrSync.Interval, 0
	ELSE
		pnAsserts = pnAsserts + 4
		DO DcLog WITH '  FAIL 9-12: nu exista randul S(371) pe DVI 101, sar peste schimbarea de curs'
	ENDIF

	DO DcLog WITH 'dump introdc dupa schimbare curs DVI USD (4.50):'
	DO DumpIntrodc

	SELECT introdc
	LOCATE FOR nract = 101 AND ALLTRIM(fdoc) == 'DVI' AND tip_rand == 'S' AND ALLTRIM(scd) == '371'
	IF FOUND()
		DO Assert3 WITH '13-S(371) suma recalculata (450 lei)', suma, 450
	ELSE
		pnAsserts = pnAsserts + 1
		DO DcLog WITH '  FAIL 13: nu am gasit randul S(371) dupa sync'
	ENDIF

	SELECT introdc
	LOCATE FOR ALLTRIM(NVL(doc_key,'')) == lcDocKeyDvi2 AND tip_rand == 'T'
	IF FOUND()
		DO Assert3 WITH '14-T DVI suma recalculata (94.50 lei)', suma, 94.50
	ELSE
		pnAsserts = pnAsserts + 1
		DO DcLog WITH '  FAIL 14: nu am gasit randul T al doc2 (doc_key=' + lcDocKeyDvi2 + ') dupa sync'
	ENDIF

	DO DcLog WITH 'goObj.procent_val=' + TRANSFORM(goObj.procent_val) + ' goObj.nbaza_val=' + TRANSFORM(goObj.nbaza_val)
	DO Assert3 WITH '15-procent_val dupa curs (astept 108.604)', goObj.procent_val, 108.604
	DO Assert3 WITH '16-nbaza_val dupa curs (astept 1086.04)', goObj.nbaza_val, 1086.04

	SELECT rul_temp
	LOCATE FOR ALLTRIM(codmat) == 'ART-A8-371'
	IF FOUND()
		DO DcLog WITH 'rul_temp dupa curs: pretd=' + TRANSFORM(pretd) + ' pret=' + TRANSFORM(pret)
		DO Assert3 WITH '17-rul_temp.pretd dupa curs (astept 1086.04)', pretd, 1086.04
		*!* 5679.99, nu pretd*curs=5680.03 - do_reface rotunjeste intermediar (acelasi tipar ca 3b)
		DO Assert3 WITH '18-rul_temp.pret dupa curs (astept 5679.99)', pret, 5679.99
	ELSE
		pnAsserts = pnAsserts + 2
		DO DcLog WITH '  FAIL 17/18: nu am gasit articolul ART-A8-371 in rul_temp dupa curs'
	ENDIF

	SELECT introdc
	LOCATE FOR tip_rand == 'D'
	IF FOUND()
		DO DcLog WITH 'randul D dupa curs: suma=' + TRANSFORM(suma)
		DO Assert3 WITH '19-diferenta D dupa curs (|suma|<=0.02)', ABS(suma), 0
	ELSE
		DO DcLog WITH '  INFO 19: nu exista rand D dupa curs - OK'
		pnAsserts = pnAsserts + 1
		pnPass = pnPass + 1
	ENDIF

	SELECT introdc
	LOCATE FOR nract = 101 AND ALLTRIM(fdoc) == 'DVI' AND tip_rand == 'S' AND ALLTRIM(scd) == '371'
	IF FOUND()
		DO DcLog WITH 'S doc2 dupa curs: explicatia5=[' + ALLTRIM(NVL(explicatia5,'')) + ']'
		DO AssertStr WITH '20-explicatia5 S DVI dupa curs (astept 8.60)', ALLTRIM(NVL(explicatia5,'')), '8.60'
	ELSE
		pnAsserts = pnAsserts + 1
		DO DcLog WITH '  FAIL 20: nu am gasit randul S(371) pt explicatia5 dupa curs'
	ENDIF

	LOCAL llValidSume2
	llValidSume2 = goObj.valideaza_sume()
	DO DcLog WITH '21-valideaza_sume() dupa curs=' + TRANSFORM(llValidSume2) + ' cmesajsync=[' + ALLTRIM(NVL(goObj.cmesajsync,'')) + ']'
	pnAsserts = pnAsserts + 1
	IF llValidSume2 AND EMPTY(ALLTRIM(NVL(goObj.cmesajsync,'')))
		pnPass = pnPass + 1
		DO DcLog WITH '  PASS 21-valideaza_sume dupa curs (.T., cmesajsync gol)'
	ELSE
		DO DcLog WITH '  FAIL 21-valideaza_sume dupa curs (' + TRANSFORM(llValidSume2) + ', cmesajsync=[' + ALLTRIM(NVL(goObj.cmesajsync,'')) + '])'
	ENDIF

	DO HarnessStep WITH 3, 'curs resincronizare DVI USD: ' + TRANSFORM(pnPass) + '/' + TRANSFORM(pnAsserts) + ' PASS'

	DO DcLog WITH 'REZULTAT: ' + TRANSFORM(pnPass) + '/' + TRANSFORM(pnAsserts) + ' assert-uri PASS'
	IF pnPass = pnAsserts
		DO DcLog WITH 'VERDICT FINAL: PASS (' + TRANSFORM(pnPass) + '/' + TRANSFORM(pnAsserts) + ')'
	ELSE
		DO DcLog WITH 'VERDICT FINAL: FAIL (' + TRANSFORM(pnPass) + '/' + TRANSFORM(pnAsserts) + ' assert-uri PASS)'
	ENDIF

	DO HarnessStep WITH 4, 'final: ' + TRANSFORM(pnPass) + '/' + TRANSFORM(pnAsserts) + ' PASS'
	DO HarnessDone WITH 'done'

CATCH TO loExc
	DO DcLog WITH 'CATCH ErrorNo=' + TRANSFORM(loExc.ErrorNo) + ' Message=' + loExc.Message + ' Proc=' + loExc.Procedure + ' Line=' + TRANSFORM(loExc.LineNo) + ' [' + loExc.LineContents + ']'
	DO HarnessDone WITH 'done-error'
ENDTRY

QUIT

*==================================================================================
PROCEDURE AdaugaDoc1
	*-- FACTURA 15000, RAJA, DVI in EUR (curs 5.23): DVI 101, BIROUL VAMAL, tva 1098.30/210.
	goDlg = CREATEOBJECT('import_adauga_factura', goObj)
	goDlg.cFelDoc = 'Factura'
	goDlg.nIdFdoc = 1
	goDlg.nNract = 15000
	goDlg.dDataAct = DATE()
	goDlg.nIdPartener = 601
	goDlg.cPartener = 'RAJA'
	goDlg.cExplicatia = 'Import marfa RAJA'
	goDlg.nSuma = 1000
	goDlg.nSumaLei = 0
	goDlg.nCurs = 5.23
	goDlg.nIdValuta = 978
	goDlg.cValuta = 'EUR'
	goDlg.nIdExplicatieTva = 220
	goDlg.cExplicatieTva = 'ACH. IMP. 21%'
	goDlg.optTipTva.Value = 2 && D = DVI
	goDlg.chkInValutaCont.Value = 1
	goDlg.chkParticipaValuta.Value = 1
	goDlg.cSerieDvi = ''
	goDlg.nNractDvi = 101
	goDlg.dDviData = DATE()
	goDlg.nIdFdocDVI = 2
	goDlg.cFelDocDvi = 'DVI'
	goDlg.nDviIdPartener = 900
	goDlg.cDviPartener = 'BIROUL VAMAL'
	goDlg.nDviTvaLei = 1098.30
	goDlg.nDviTvaVal = 210.00
	goDlg.actualizeaza_stare_dvi()
	goDlg.WindowType = 0
	goDlg.Visible = .T.
	goDlg.Show()
	DOEVENTS FORCE
	DO DcLog WITH 'DOC1: valideaza = ' + TRANSFORM(goDlg.valideaza())
	DO ConstruiesteToDlg
	DO DcLog WITH 'DOC1: do_adauga_factura = ' + TRANSFORM(goObj.do_adauga_factura(goT))
	goDlg.Hide()
	DOEVENTS FORCE
ENDPROC

PROCEDURE AdaugaDoc2
	*-- DVI 101, BIROUL VAMAL, 100 USD curs 4.00 (400 lei) - ALTA valuta decat principala (EUR),
	*-- participa la pretul in valuta, TVA normal ('F', NU referinta la alt DVI) - proprie, se
	*-- autocalculeaza din sablonul cu_tva (21% din baza: 84 lei / 21 USD).
	goDlg = CREATEOBJECT('import_adauga_factura', goObj)
	goDlg.cFelDoc = 'DVI'
	goDlg.nIdFdoc = 2
	goDlg.nNract = 101
	goDlg.dDataAct = DATE()
	goDlg.nIdPartener = 900
	goDlg.cPartener = 'BIROUL VAMAL'
	goDlg.cExplicatia = 'DVI 101 taxe vamale USD'
	goDlg.nSuma = 100
	goDlg.nSumaLei = 0
	goDlg.nCurs = 4.00
	goDlg.nIdValuta = 840
	goDlg.cValuta = 'USD'
	goDlg.nIdExplicatieTva = 220
	goDlg.cExplicatieTva = 'ACH. IMP. 21%'
	goDlg.optTipTva.Value = 1 && F = furnizor (normal, NU referinta DVI)
	goDlg.chkInValutaCont.Value = 1
	goDlg.chkParticipaValuta.Value = 1
	goDlg.WindowType = 0
	goDlg.Visible = .T.
	goDlg.Show()
	DOEVENTS FORCE
	DO DcLog WITH 'DOC2: valideaza = ' + TRANSFORM(goDlg.valideaza())
	DO ConstruiesteToDlg
	DO DcLog WITH 'DOC2: do_adauga_factura = ' + TRANSFORM(goObj.do_adauga_factura(goT))
	goDlg.Hide()
	DOEVENTS FORCE
ENDPROC

PROCEDURE ConstruiesteToDlg
	*-- toDlg construit INLINE (nu intr-o functie apelata din procedura de business) - vezi
	*-- docs/testare-ui-vfp.md capcana l; aici functioneaza fiindca goT e PUBLIC (nu return local).
	goT = CREATEOBJECT('Empty')
	=ADDPROPERTY(goT,'serie_act',ALLTRIM(NVL(goDlg.cSerieAct,'')))
	=ADDPROPERTY(goT,'nract',goDlg.nNract)
	=ADDPROPERTY(goT,'dataact',goDlg.dDataAct)
	=ADDPROPERTY(goT,'fdoc',goDlg.cFelDoc)
	=ADDPROPERTY(goT,'id_fdoc',goDlg.nIdFdoc)
	=ADDPROPERTY(goT,'id_partc',goDlg.nIdPartener)
	=ADDPROPERTY(goT,'partc',goDlg.cPartener)
	=ADDPROPERTY(goT,'explicatia',ALLTRIM(NVL(goDlg.cExplicatia,'')))
	=ADDPROPERTY(goT,'suma',IIF(goDlg.chkInValutaCont.Value=1 AND goDlg.nCurs<>0,IIF(goDlg.nSumaLei<>0,goDlg.nSumaLei,ROUND(goDlg.nSuma*goDlg.nCurs,gnPC)),goDlg.nSuma))
	=ADDPROPERTY(goT,'suma_val',IIF(goDlg.chkInValutaCont.Value=1 AND goDlg.nCurs<>0,goDlg.nSuma,0))
	=ADDPROPERTY(goT,'in_valuta',goDlg.chkInValutaCont.Value)
	=ADDPROPERTY(goT,'participa_valuta',(goDlg.chkParticipaValuta.Value=1))
	=ADDPROPERTY(goT,'id_valuta',IIF(goDlg.chkInValutaCont.Value=1,goDlg.nIdValuta,0))
	=ADDPROPERTY(goT,'curs',IIF(goDlg.chkInValutaCont.Value=1,goDlg.nCurs,0))
	=ADDPROPERTY(goT,'nume_val',IIF(goDlg.chkInValutaCont.Value=1,ALLTRIM(NVL(goDlg.cValuta,'')),''))
	=ADDPROPERTY(goT,'cTipTva',IIF(goDlg.optTipTva.Value=1,'F',IIF(goDlg.optTipTva.Value=2,'D','N')))
	=ADDPROPERTY(goT,'id_jtva_coloana',goDlg.nIdExplicatieTva)
	=ADDPROPERTY(goT,'dvi_serie',CHRTRAN(ALLTRIM(NVL(goDlg.cSerieDvi,'')),CHR(34),''))
	=ADDPROPERTY(goT,'dvi_nract',goDlg.nNractDvi)
	=ADDPROPERTY(goT,'dvi_dataact',goDlg.dDviData)
	=ADDPROPERTY(goT,'dvi_id_fdoc',goDlg.nIdFdocDVI)
	=ADDPROPERTY(goT,'dvi_fdoc',goDlg.cFelDocDvi)
	=ADDPROPERTY(goT,'dvi_id_partc',goDlg.nDviIdPartener)
	=ADDPROPERTY(goT,'dvi_partc',goDlg.cDviPartener)
	=ADDPROPERTY(goT,'dvi_scc','401')
	=ADDPROPERTY(goT,'dvi_tva_lei',goDlg.nDviTvaLei)
	=ADDPROPERTY(goT,'dvi_tva_val',goDlg.nDviTvaVal)
ENDPROC

PROCEDURE CreeazaRulTemp
	*-- structura reala rul_temp (VRUL, Oracle dev).
	IF USED('rul_temp')
		USE IN ('rul_temp')
	ENDIF
	CREATE CURSOR rul_temp ( ;
		id_rul N(20,0), an N(4,0), luna N(2,0), cod N(20,0);
		, serie C(100), nnir N(20,0), id_articol N(10,0), denumire C(100);
		, codmat C(50), codmatf C(50), codbare C(50), um C(20);
		, id_gestiune N(5,0), nume_gestiune C(50), cgest C(20), nr_pag N(2,0);
		, gestionar C(50), comisie_receptie1 C(50), comisie_receptie2 C(50), comisie_receptie3 C(50);
		, cant N(14,3), cante N(14,3), cont C(10), acont C(20);
		, pret N(18,4), tva N(18,4), valoare N(18,4), valtva N(18,4);
		, proc_tva N(5,2), pretv N(18,4), pretvtva N(18,4), tvav N(18,4);
		, valoarev N(18,4), valtvav N(18,4), proc_tvav N(5,2), adaos N(18,4);
		, adaos_tva N(18,4), valoare_adaos N(18,4), valtva_adaos N(18,4), procent N(10,3);
		, discunitar N(18,4), discount_tva N(18,4), valoare_discount N(18,4), valtva_discount N(18,4);
		, proc_disc N(7,3), pretd N(14,4), curs N(18,4), id_valuta N(10,0);
		, nume_val C(20), id_lucrare N(20,0), nrord C(100), id_responsabil N(10,0);
		, nresp C(100), resp_marca N(18,4), dataact T, id_util N(5,0);
		, util C(30), dataora T, id_sectie N(5,0), sectie C(50);
		, csectie C(10), alcooltutun N(1,0), datain T, dataout T;
		, id_fact N(20,0), id_gestiunec N(10,0), nume_gestiunec C(50), cgestc C(20);
		, id_responsabilc N(5,0), id_reteta N(10,0), reteta C(50), nrespc C(100);
		, respc_marca N(18,4), id_set N(20,0), id_tip_rulaj N(10,0), tip_rulaj C(50);
		, id_obiect_depozit N(10,0), id_rul_aux N(10,0), nract N(20,0), serie_act C(10);
		, dataoras T, id_utils N(10,0), lot C(30), adata_expirare T;
		, id_sucursala N(5,0), sucursala C(250), id_part_rez N(10,0), part_rez C(100);
		, id_lucrare_rez N(10,0), nrord_rez C(100), subgrupa C(100), grupa C(100);
		, id_subgrupa N(5,0), id_grupa N(5,0), in_stoc N(1,0), in_crm N(1,0);
		, id_furnizor N(10,0), furnizor C(100), id_jtva_coloana N(4,0), explicatie_tva C(100);
		, taxcode N(6,0), taxname C(254), saft_procent N(18,4), codnc8 C(20);
		, id_tara_origine N(4,0), cod_tara_origine C(5), tara_origine C(50), greutate N(12,4);
		, fdoc C(30), id_fdoc N(18,4);
		, pret_lei N(18,4), pret_val N(14,4), cota_tva N(6,2))
ENDPROC

PROCEDURE CreeazaIntrodc
	LPARAMETERS tcAlias
	IF USED(tcAlias)
		USE IN (tcAlias)
	ENDIF
	CREATE CURSOR (tcAlias) ( ;
		id_note N(14), explicatia C(100), scd C(10), ascd C(20), scc C(10), ascc C(20), ;
		cu_tva N(1), id_set N(14), ordine N(8), in_valuta N(1), id_jtva_coloana N(14) NULL, ;
		ptva N(6,2), explicatie_tva C(50), tipjurnal C(2), taxcode N(6), paymentcode C(9), ;
		suma N(18,4), suma_val N(18,4), id_partd N(14), id_partc N(14), partd C(100), partc C(100), ;
		id_fact N(14), id_factd N(14), id_factc N(14), pereched N(14), perechec N(14), ;
		nract N(14), serie_act C(10), explicatia4 C(50), explicatia5 C(50), participa_valuta L, ;
		id_valuta N(14), curs N(14,4), nume_val C(10), dataact D, fdoc C(50), id_fdoc N(14), ;
		se_scrie N(1), tva_incasare N(1), doc_color N(10), doc_label C(10), tip_rand C(1), ;
		doc_key C(80), nr_doc N(8), suma_doc N(18,4), suma_doc_val N(18,4), mod_manual N(1), expl_manual N(1), ;
		scd_orig C(20), ascd_orig C(20), rand_dvi N(1), valuta_proprie N(1))
ENDPROC

PROCEDURE VerificaPereche
	LPARAMETERS tnNract, tnBazaLei, tnBazaVal, tcVal
	LOCAL lnSel, lcMsg, llB, lnBS, lnBSV, lcNV
	lnSel = SELECT()
	SELECT introdc
	LOCATE FOR nract = tnNract AND tip_rand == 'B'
	llB = FOUND()
	IF llB
		lnBS = suma
		lnBSV = suma_val
		lcNV = ALLTRIM(NVL(nume_val,''))
	ENDIF
	IF llB AND ABS(lnBS - tnBazaLei) < 0.01 AND ABS(lnBSV - tnBazaVal) < 0.01 AND ALLTRIM(NVL(lcNV,'')) == tcVal
		lcMsg = 'PASS pereche nract=' + TRANSFORM(tnNract) + ': B(suma=' + TRANSFORM(lnBS) + ' val=' + TRANSFORM(lnBSV) + ' ' + lcNV + ')'
	ELSE
		lcMsg = 'FAIL pereche nract=' + TRANSFORM(tnNract) + ': B?=' + TRANSFORM(llB) + ' bazaLei=' + TRANSFORM(IIF(llB,lnBS,-1)) + '(astept ' + TRANSFORM(tnBazaLei) + ') bazaVal=' + TRANSFORM(IIF(llB,lnBSV,-1)) + '(astept ' + TRANSFORM(tnBazaVal) + ') val=[' + IIF(llB,lcNV,'?') + '](astept [' + tcVal + '])'
	ENDIF
	DO DcLog WITH lcMsg
	SELECT (lnSel)
ENDPROC

PROCEDURE DumpIntrodc
	LOCAL lnSel
	lnSel = SELECT()
	SELECT introdc
	SCAN
		DO DcLog WITH '  recno=' + TRANSFORM(RECNO()) + ' nr_doc=' + TRANSFORM(NVL(nr_doc,0)) + ' nract=' + TRANSFORM(nract) + ' fdoc=[' + ALLTRIM(NVL(fdoc,'')) + '] tip_rand=' + tip_rand + ;
			' scd=' + ALLTRIM(scd) + ' ascd=[' + ALLTRIM(NVL(ascd,'')) + '] scc=' + ALLTRIM(scc) + ' ptva=' + TRANSFORM(ptva) + ' suma=' + TRANSFORM(suma) + ' suma_val=' + TRANSFORM(suma_val) + ;
			' in_valuta=' + TRANSFORM(NVL(in_valuta,0)) + ' id_valuta=' + TRANSFORM(NVL(id_valuta,0)) + ' partc=[' + ALLTRIM(NVL(partc,'')) + '] expl4=[' + ALLTRIM(NVL(explicatia4,'')) + '] expl5=[' + ALLTRIM(NVL(explicatia5,'')) + '] doc_key=[' + ALLTRIM(doc_key) + ']'
	ENDSCAN
	SELECT (lnSel)
ENDPROC

FUNCTION RECCOUNT_ACTIVE
	LPARAMETERS tcAlias
	LOCAL lnSel, lnCnt
	lnSel = SELECT()
	SELECT (tcAlias)
	COUNT TO lnCnt FOR !DELETED()
	SELECT (lnSel)
	RETURN lnCnt
ENDFUNC

PROCEDURE Assert3
	*-- compara numeric cu toleranta 0.02, logheaza PASS/FAIL, incrementeaza contoare (byref).
	LPARAMETERS tcLabel, tuActual, tuExpected
	pnAsserts = pnAsserts + 1
	IF ABS(NVL(tuActual,0) - tuExpected) < 0.02
		pnPass = pnPass + 1
		DO DcLog WITH '  PASS ' + tcLabel + ' (=' + TRANSFORM(tuActual) + ')'
	ELSE
		DO DcLog WITH '  FAIL ' + tcLabel + ' (actual=' + TRANSFORM(tuActual) + ' asteptat=' + TRANSFORM(tuExpected) + ')'
	ENDIF
ENDPROC

PROCEDURE AssertStr
	LPARAMETERS tcLabel, tcActual, tcExpected
	pnAsserts = pnAsserts + 1
	IF tcActual == tcExpected
		pnPass = pnPass + 1
		DO DcLog WITH '  PASS ' + tcLabel + ' (=[' + tcActual + '])'
	ELSE
		DO DcLog WITH '  FAIL ' + tcLabel + ' (actual=[' + tcActual + '] asteptat=[' + tcExpected + '])'
	ENDIF
ENDPROC

PROCEDURE DcErr
	LPARAMETERS tnErr, tcMsg, tcProg, tnLine
	DO DcLog WITH 'ON ERROR ' + TRANSFORM(tnErr) + ' [' + tcProg + ':' + TRANSFORM(tnLine) + '] ' + tcMsg
ENDPROC

PROCEDURE DcLog
	LPARAMETERS tcMsg
	SET SAFETY OFF
	LOCAL lcL
	lcL = IIF(FILE(gcUILog), FILETOSTR(gcUILog), '')
	STRTOFILE(lcL + tcMsg + CHR(13)+CHR(10), gcUILog)
ENDPROC

DEFINE CLASS dummyapp AS Custom
	PROCEDURE ReadIni
		LPARAMETERS tcSection, tcKey
		RETURN ''
	ENDPROC
	PROCEDURE WriteIni
		LPARAMETERS tcSection, tcKey, tcValue
		RETURN .T.
	ENDPROC
ENDDEFINE

DEFINE CLASS dummyexecutor AS Custom
	cEroare = ''
	PROCEDURE oExecute
		LPARAMETERS tcSql, tcCursor
		IF USED(m.tcCursor)
			USE IN (m.tcCursor)
		ENDIF
		*-- update_jtva_coloane (SELECT * FROM vjtva_coloane ...): mock cu date reale.
		IF 'VJTVA_COLOANE' $ UPPER(m.tcSql)
			DO CreeazaJtvaColoaneView WITH m.tcCursor
			RETURN 1
		ENDIF
		*-- rul_temp (recreat de import_nota.Init din vrul cand e gol): structura completa.
		IF UPPER(ALLTRIM(m.tcCursor)) == 'RUL_TEMP'
			CREATE CURSOR (m.tcCursor) (denumire C(100), codmat C(30), cant N(14,3), ;
				pret_val N(18,4), pretd N(18,4), pret N(18,4), pret_lei N(18,4), cont C(10), ;
				acont C(20), serie C(30), lot C(30), adata_expirare C(10), proc_disc N(6,2), cota_tva N(6,2))
			RETURN 1
		ENDIF
		*-- assign_analitic (creeaza_rand_s / do_adauga_articol): config_analitice - prefix/sufix goale,
		*-- deci acont-ul vine direct din fconturi_analitice (mai jos), controlat de gcMockAcontCrt.
		IF 'CONFIG_ANALITICE' $ UPPER(m.tcSql)
			CREATE CURSOR (m.tcCursor) (camp_leg_prefix C(30), camp_leg_sufix C(30))
			INSERT INTO (m.tcCursor) VALUES ('', '')
			RETURN 1
		ENDIF
		*-- fconturi_analitice: acont-ul curent, setat explicit de test (gcMockAcontCrt) inainte de
		*-- fiecare do_adauga_articol() - simplu si deterministic, fara sa depinda de binding real.
		IF 'FCONTURI_ANALITICE' $ UPPER(m.tcSql)
			CREATE CURSOR (m.tcCursor) (acont C(20))
			INSERT INTO (m.tcCursor) VALUES (IIF(TYPE('gcMockAcontCrt') = 'C', gcMockAcontCrt, ''))
			RETURN 1
		ENDIF
		*-- vplcont_analitic: validare analitic vs plan de conturi.
		IF 'VPLCONT_ANALITIC' $ UPPER(m.tcSql)
			CREATE CURSOR (m.tcCursor) (cont C(10), acont C(20))
			INSERT INTO (m.tcCursor) VALUES ('371', '4')
			RETURN 1
		ENDIF
		*-- ramura generica: cursor gol (nu afecteaza fluxurile testate mai sus).
		CREATE CURSOR (m.tcCursor) (id_temp N(1))
		RETURN 1
	ENDPROC
	PROCEDURE oExecuta
		LPARAMETERS tcSql, tcCursor
		IF !EMPTY(m.tcCursor)
			IF USED(m.tcCursor)
				USE IN (m.tcCursor)
			ENDIF
			IF UPPER(m.tcCursor) == 'CJTVACOL4427'
				*-- coloana_jc 'FO21T' (import) NU se potriveste patternurilor TI%T/XX%TIT/CE%T -
				*-- cursor gol => scc ramane '401' (nu 4427).
				CREATE CURSOR (m.tcCursor) (id_jtva_coloana N(14))
			ELSE
				CREATE CURSOR (m.tcCursor) (id_temp N(1))
			ENDIF
		ENDIF
		RETURN .T.
	ENDPROC
	PROCEDURE oSelect2Value
		LPARAMETERS tcSql, toValue
		toValue = ''
		RETURN 1
	ENDPROC
	PROCEDURE oReset
	ENDPROC
ENDDEFINE

PROCEDURE CreeazaJtvaColoaneView
	LPARAMETERS tcCursor
	IF USED(m.tcCursor)
		USE IN (m.tcCursor)
	ENDIF
	CREATE CURSOR (m.tcCursor) (id_jtva_coloana N(14), denumire C(100), jc N(1), jv N(1), ;
		coloana_jc C(20), coloana_jv C(20), cota_tva N(6,2), id_tva N(14) NULL, afisat N(1), ;
		id_jtva_ex N(14) NULL, id_jtva_neex N(14) NULL, ordine N(8), ;
		taxcode N(6) NULL, taxcode_neexigibil N(6) NULL, taxcode_n50 N(6) NULL, ;
		taxcode_n50_tvai N(6) NULL, taxcode_n100 N(6) NULL, taxcode_regularizare N(6) NULL, taxcode_tvai N(6) NULL)
	INSERT INTO (m.tcCursor) (id_jtva_coloana, denumire, jc, jv, afisat, ordine, cota_tva) VALUES (0, '', 0, 0, 1, 0, 0)
	INSERT INTO (m.tcCursor) (id_jtva_coloana, denumire, jc, jv, coloana_jc, cota_tva, id_tva, afisat, ordine, taxcode) ;
		VALUES (208, 'ACH. INT. 21%', 1, 0, 'RO21B', 21, 209, 1, 1, 301104)
	INSERT INTO (m.tcCursor) (id_jtva_coloana, denumire, jc, jv, coloana_jc, cota_tva, afisat, ordine, taxcode) ;
		VALUES (209, 'TVA ACH. INT. 21%', 1, 0, 'RO21T', 21, 1, 2, 301104)
	INSERT INTO (m.tcCursor) (id_jtva_coloana, denumire, jc, jv, coloana_jc, cota_tva, id_tva, afisat, ordine, taxcode) ;
		VALUES (220, 'ACH. IMP. 21%', 1, 0, 'FO21B', 21, 221, 1, 3, 301204)
	INSERT INTO (m.tcCursor) (id_jtva_coloana, denumire, jc, jv, coloana_jc, cota_tva, afisat, ordine, taxcode) ;
		VALUES (221, 'TVA ACH. IMP. 21%', 1, 0, 'FO21T', 21, 1, 4, 301204)
ENDPROC
