* test_repro_valuta_dblclick.prg - reproduce headless bugul "valuta ramane USD" din
* Grid1.cValuta.Text1.DblClick (COMUN\clase\ointroduceri.vcx, clasa IMPORT_nota).
* Ipoteza: apelat PROGRAMATIC (fara focus real pe celula) Replace-ul ramane (PASS fals in
* teste vechi); cu focus REAL pe celula (ca la dublu-click de mouse), textbox-ul activ
* rescrie valoarea VECHE peste camp la parasirea celulei => valuta "ramane" USD.
*
* Mock caut_valuta (mock_caut_valuta.prg, incarcat PRIMUL, capcana g) returneaza
* goMockValuta (id_valuta=1, nume_val='RON'), construit INLINE in main (capcana l).
*
* Pasi: A (programatic, fara focus) - astept 'RON'; B (cu focus real pe celula) -
* verifica daca revine la 'USD' (bug reprodus) sau ramane 'RON'.
*
* Rulare (prin harness):
*   powershell -ExecutionPolicy Bypass -File vfp_ui_harness.ps1 -TestPrg <acest.prg> -Steps @(...)
* Log: test_repro_valuta_dblclick_log.txt

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_repro_valuta_dblclick_log.txt"
gcSyncDir = "D:\ROA\ROAGEST\COMUN\utile\Teste\achizitie_import\uisync_valuta\"
STRTOFILE("START " + TTOC(DATETIME()) + CHR(13)+CHR(10), gcUILog)

ON ERROR DO UIErr 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 UILog 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 UILog WITH 'SET CLASSLIB OK'

	*----- PROCEDURI -----
	SET PROCEDURE TO PROCEDURI
	*-- mock amessagebox INCARCAT PRIMUL (inaintea oproceduri_comune.prg, care are amessagebox
	*-- real): in VFP, la nume duplicat de procedura, castiga fisierul cautat PRIMUL in lista.
	SET PROCEDURE TO "D:\ROA\ROAGEST\COMUN\utile\Teste\mock_amessagebox.prg" ADDITIVE
	*-- mock caut_valuta INCARCAT PRIMUL, inaintea lui ocautare (care are caut_valuta real).
	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

	*----- Harness UI reutilizabil (mock-urile sunt incarcate mai sus, primele). -----
	SET PROCEDURE TO "D:\ROA\ROAGEST\COMUN\utile\Teste\ui_harness.prg" ADDITIVE

	DO UILog WITH 'SET PROCEDURE OK'

	*----- goMockValuta: rezultatul FIX al caut_valuta mock (capcana l - construit INLINE). -----
	PUBLIC goMockValuta
	goMockValuta = CREATEOBJECT('Custom')
	goMockValuta.AddProperty('id_valuta', 1)
	goMockValuta.AddProperty('nume_val', 'RON')
	DO UILog WITH 'goMockValuta creat: id_valuta=1 nume_val=RON'

	*----- Globale minimale cerute de definitia clasei / Init -----
	PUBLIC gnPc, gnPval, gnPcant, gnPpret, gnPPretval, gnPCurs, gnPVal, gnPPretV, gnPPretVal
	gnPc = 2
	gnPval = 2
	gnPVal = 2
	gnPcant = 3
	gnPpret = 4
	gnPPretval = 4
	gnPPretVal = 4
	gnPPretV = 4
	gnPCurs = 4

	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)

	*----- goExecutor dummy: creeaza cursoarele cerute fara Oracle real -----
	PUBLIC goExecutor
	goExecutor = CREATEOBJECT('dummyexecutor')
	DO UILog WITH 'goExecutor dummy creat'

	*----- goApp dummy: _frm_base.Init cere goApp.ReadIni (FONTSIZEPLUS/FONTNAME) -----
	PUBLIC goApp
	goApp = CREATEOBJECT('dummyapp')
	DO UILog WITH 'goApp dummy creat'

	*----- poAct dummy: obiectul act (curs valutar in_valuta) -----
	PUBLIC poAct
	poAct = CREATEOBJECT('Custom')
	poAct.AddProperty('nume_val', 'USD')
	poAct.AddProperty('curs', 4.56)
	poAct.AddProperty('proc_tva', 1.21)
	poAct.AddProperty('nnir', 0)
	poAct.AddProperty('dataact', DATE())

	*----- jtva_coloane2: minimal (nu e relevant pentru bugul de valuta, dar cerut de Init). -----
	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)
	DO UILog WITH 'jtva_coloane2 creat (minimal)'

	*----- saft_taxtable: minimal. -----
	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)
	DO UILog WITH 'saft_taxtable creat (minimal)'

	*----- introdc: RecordSource Grid1. Document unic (nract=1001) cu 1 rand B + 1 rand T,
	*      in valuta USD (in_valuta=1, id_valuta=2, nume_val='USD', curs=4.56, participa_valuta=.T.) -----
	IF USED('introdc')
		USE IN ('introdc')
	ENDIF
	CREATE CURSOR introdc ( ;
		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))

	*-- randul B (baza): suma 1000 lei, suma_val 219.30 USD (curs 4.56)
	INSERT INTO introdc (tip_rand, scd, scc, ascc, suma, suma_val, id_jtva_coloana, ptva, explicatie_tva, ;
			in_valuta, participa_valuta, id_valuta, curs, nume_val, nr_doc, nract, serie_act, fdoc, partc, explicatia, ;
			cu_tva, dataact, suma_doc, suma_doc_val, doc_key) ;
		VALUES ('B','371','401','FURN01', 1000, 219.30, 208, 21, 'ACH. INT. 21%', ;
			1, .T., 2, 4.56, 'USD', 1, 1001, 'A', 'Factura', 'FURNIZOR ABC SRL', 'Marfa achizitionata valuta', ;
			1, DATE(), 1210, 265.35, 'A|1001|0|0')
	*-- randul T (TVA pereche): suma 210 lei, suma_val 46.05 USD
	INSERT INTO introdc (tip_rand, scd, scc, ascc, suma, suma_val, id_jtva_coloana, ptva, explicatie_tva, ;
			in_valuta, participa_valuta, id_valuta, curs, nume_val, nr_doc, nract, serie_act, fdoc, partc, explicatia, ;
			cu_tva, dataact, suma_doc, suma_doc_val, doc_key) ;
		VALUES ('T','4426','401','FURN01', 210, 46.05, 209, 21, 'TVA ACH. INT. 21%', ;
			1, .T., 2, 4.56, 'USD', 1, 1001, 'A', 'Factura', 'FURNIZOR ABC SRL', 'TVA deductibil valuta', ;
			1, DATE(), 1210, 265.35, 'A|1001|0|0')
	GO TOP IN introdc
	DO UILog WITH 'introdc populat (' + TRANSFORM(RECCOUNT('introdc')) + ' randuri, USD/curs 4.56)'

	*----- rul_temp: RecordSource GridArt. Pre-populat, ca sa nu-l recreeze Init din Oracle. -----
	IF USED('rul_temp')
		USE IN ('rul_temp')
	ENDIF
	CREATE CURSOR rul_temp (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))
	INSERT INTO rul_temp (denumire, codmat, cant, pret_val, pretd, pret, pret_lei, ;
			cont, acont, serie, lot, adata_expirare, proc_disc, cota_tva) ;
		VALUES ('Laptop Dell Latitude', 'ART001', 1, 219.30, 219.30, 1000, 1000, ;
			'371', '01', 'SN-LAP-001', 'L001', '', 0, 21)
	GO TOP IN rul_temp
	DO UILog WITH 'rul_temp populat (' + TRANSFORM(RECCOUNT('rul_temp')) + ' articole)'

	*----- Desktop VFP vizibil, maximizat -----
	_SCREEN.Visible = .T.
	_SCREEN.WindowState = 2
	_SCREEN.Caption = 'TEST REPRO valuta dblclick'

	DO UILog WITH 'mediu pregatit, CREATEOBJECT(import_nota, .T.)'

	SELECT introdc
	PUBLIC goObj
	goObj = CREATEOBJECT('IMPORT_nota', .T.)

	IF VARTYPE(goObj) <> 'O'
		DO UILog WITH 'FAIL: CREATEOBJECT a returnat ' + TRANSFORM(goObj)
		DO HarnessDone WITH 'done-error'
		QUIT
	ENDIF
	goObj.oact = poAct
	DO UILog WITH 'PASS: instantiere OK, afisez formularul'

	goObj.WindowType = 0
	goObj.Visible = .T.
	goObj.Show()
	goObj.WindowState = 2
	DOEVENTS FORCE

	*========================= PAS 0: formular afisat =========================
	DO HarnessStep WITH 0, 'Formular afisat: introdc=' + TRANSFORM(RECCOUNT('introdc')) + ' randuri, nume_val B=' + ALLTRIM(introdc.nume_val)

	*========================= PAS A: apel PROGRAMATIC, FARA focus real pe celula =========================
	*-- Pozitionez pe randul B, apelez direct handler-ul DblClick FARA sa fi dat SetFocus
	*-- celulei/Text1-ului (simuleaza apelul din testele vechi, care treceau).
	SELECT introdc
	GO TOP
	LOCATE FOR tip_rand == 'B'
	DO UILog WITH 'PAS A: pozitionat pe randul B, nume_val INAINTE=' + ALLTRIM(NVL(introdc.nume_val,'?')) + ' (astept USD)'

	LOCAL lcActivPreA
	lcActivPreA = IIF(TYPE('_SCREEN.ActiveForm.ActiveControl') = 'O', _SCREEN.ActiveForm.ActiveControl.Name, '?')
	DO UILog WITH 'PAS A: control activ INAINTE de DblClick = ' + lcActivPreA

	goObj.grid1.cValuta.text1.DblClick()
	DOEVENTS FORCE

	*-- mut focusul pe alt control, ca la parasirea normala a celulei
	goObj.grid1.cCurs.text1.SetFocus()
	DOEVENTS FORCE

	SELECT introdc
	LOCATE FOR tip_rand == 'B'
	LOCAL lcNumeValA
	lcNumeValA = ALLTRIM(NVL(introdc.nume_val,'?'))
	IF lcNumeValA == 'RON'
		DO UILog WITH 'PAS A PASS (asteptat): programatic fara focus real => nume_val=' + lcNumeValA + ' (Replace ramane, nu e suprascris)'
	ELSE
		DO UILog WITH 'PAS A NEASTEPTAT: nume_val=' + lcNumeValA + ' (asteptam RON)'
	ENDIF
	DO HarnessStep WITH 1, 'PAS A (programatic): nume_val=' + lcNumeValA

	*========================= PAS B: cu FOCUS REAL pe celula (reproducerea bugului) =========================
	*-- Resetez randul B la USD/id_valuta=2 (setup, nu parte din pasul testat)
	SELECT introdc
	LOCATE FOR tip_rand == 'B'
	REPLACE id_valuta WITH 2, nume_val WITH 'USD', curs WITH 4.56
	goObj.grid1.Refresh()
	DOEVENTS FORCE
	DO UILog WITH 'PAS B: reset randul B la USD, nume_val=' + ALLTRIM(introdc.nume_val)

	*-- activez celula coloanei cValuta pe randul B: SetFocus pe grid, apoi pe Text1-ul coloanei
	goObj.grid1.SetFocus()
	DOEVENTS FORCE
	goObj.grid1.cValuta.text1.SetFocus()
	DOEVENTS FORCE

	LOCAL lcActivB, lcValueActivB
	lcActivB = IIF(TYPE('_SCREEN.ActiveForm.ActiveControl') = 'O', _SCREEN.ActiveForm.ActiveControl.Name, '?')
	*-- This.Value al textbox-ului activ (cValuta.Text1) - starea INAINTE de DblClick
	lcValueActivB = ALLTRIM(NVL(goObj.grid1.cValuta.text1.Value, '?'))
	DO UILog WITH 'PAS B: control activ dupa SetFocus = ' + lcActivB + '; Text1.Value INAINTE de DblClick = [' + lcValueActivB + ']'

	*-- echivalentul handler-ului de dublu-click, ACUM cu celula avand focus real
	goObj.grid1.cValuta.text1.DblClick()
	DOEVENTS FORCE

	LOCAL lcValueActivB2
	lcValueActivB2 = ALLTRIM(NVL(goObj.grid1.cValuta.text1.Value, '?'))
	DO UILog WITH 'PAS B: Text1.Value DUPA DblClick (inainte de mutarea focusului) = [' + lcValueActivB2 + ']'

	*-- mut focusul pe ALT control/coloana - aici s-ar declansa write-back-ul controlului activ
	goObj.grid1.cCurs.text1.SetFocus()
	DOEVENTS FORCE

	SELECT introdc
	LOCATE FOR tip_rand == 'B'
	LOCAL lcNumeValB, lcNumeValT
	lcNumeValB = ALLTRIM(NVL(introdc.nume_val,'?'))
	LOCATE FOR tip_rand == 'T'
	lcNumeValT = ALLTRIM(NVL(introdc.nume_val,'?'))

	IF lcNumeValB == 'USD'
		DO UILog WITH 'PAS B: BUG REPRODUS - dupa DblClick cu focus real + mutare focus, randul B a revenit la nume_val=' + lcNumeValB + ' (randul T=' + lcNumeValT + '). Mecanism: write-back-ul controlului activ (Text1) suprascrie Replace-ul cu valoarea veche.'
	ELSE
		DO UILog WITH 'PAS B: bugul NU s-a reprodus asa - nume_val randul B=' + lcNumeValB + ' (randul T=' + lcNumeValT + '). Stare: Text1.Value inainte=[' + lcValueActivB + '] dupa DblClick=[' + lcValueActivB2 + '] control activ=[' + lcActivB + ']'

		*-- varianta 2: dupa DblClick, mut pointerul pe ALT RAND din grid (scroll) inainte de verificare
		DO UILog WITH 'PAS B varianta 2: reset randul B la USD, reincerc cu mutare pe alt RAND dupa DblClick'
		SELECT introdc
		LOCATE FOR tip_rand == 'B'
		REPLACE id_valuta WITH 2, nume_val WITH 'USD', curs WITH 4.56
		goObj.grid1.Refresh()
		DOEVENTS FORCE

		goObj.grid1.SetFocus()
		DOEVENTS FORCE
		goObj.grid1.cValuta.text1.SetFocus()
		DOEVENTS FORCE
		LOCAL lcValueActivB3
		lcValueActivB3 = ALLTRIM(NVL(goObj.grid1.cValuta.text1.Value, '?'))
		goObj.grid1.cValuta.text1.DblClick()
		DOEVENTS FORCE
		LOCAL lcValueActivB4
		lcValueActivB4 = ALLTRIM(NVL(goObj.grid1.cValuta.text1.Value, '?'))

		*-- muta pointerul grid-ului pe randul urmator (T), simuland navigare cu sageata/click alt rand
		SELECT introdc
		LOCATE FOR tip_rand == 'T'
		goObj.grid1.Refresh()
		DOEVENTS FORCE

		SELECT introdc
		LOCATE FOR tip_rand == 'B'
		LOCAL lcNumeValB2
		lcNumeValB2 = ALLTRIM(NVL(introdc.nume_val,'?'))
		IF lcNumeValB2 == 'USD'
			DO UILog WITH 'PAS B varianta 2: BUG REPRODUS - dupa DblClick + mutare pe alt rand din grid, randul B=' + lcNumeValB2
		ELSE
			DO UILog WITH 'PAS B varianta 2: NU s-a reprodus - randul B=' + lcNumeValB2 + '. Text1.Value inainte=[' + lcValueActivB3 + '] dupa DblClick=[' + lcValueActivB4 + ']'
		ENDIF
	ENDIF

	DO HarnessStep WITH 2, 'PAS B (focus real): randB=' + lcNumeValB + ' randT=' + lcNumeValT

	DO UILog WITH 'GATA - toate pasii executati'
	DO HarnessDone WITH 'done'

CATCH TO loExc
	DO UILog 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 UIErr
	LPARAMETERS tnErr, tcMsg, tcProg, tnLine
	DO UILog WITH 'ON ERROR ' + TRANSFORM(tnErr) + ' [' + tcProg + ':' + TRANSFORM(tnLine) + '] ' + tcMsg
ENDPROC

PROCEDURE UILog
	LPARAMETERS tcMsg
	LOCAL lcL
	lcL = 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
		IF 'VJTVA_COLOANE' $ UPPER(m.tcSql)
			DO CreeazaJtvaColoaneView WITH m.tcCursor
			RETURN 1
		ENDIF
		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'
				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)
ENDPROC
