* test_picker_real_212.prg
* Test cerut de Marius (utilizator real, 17.07.2026): a selectat BULDOEXCAVATOR (cont 212) in
* dialogul real de cautare (butonul "Adauga repere") si NU s-a adaugat nimic in grila, FARA niciun
* mesaj. Testul anterior (test_adauga_repere_212.prg) mock-uia cauta_nom_articole INTREG - nu
* acoperea dialogul real de cautare (formularul cauta_alfa_form, COMUN\clase\cauta_alfa_forms.vcx).
*
* Aici do_adauga_articol() e REAL, cauta_nom_articole() e REAL, XML2ListaIDDescriere() e REAL;
* SINGURUL punct inlocuit e cauta_alfa() (COMUN\programe\cauta_alfa.prg) - shadow in
* mock_cauta_alfa_dialog.prg, care instantiaza formularul REAL cauta_alfa_form si ii apeleaza
* metodele REALE (do_alege/do_termin/do_renunt), doar cu sursa de date Oracle inlocuita de un
* cursor mock (This.CursorFill() din decabaza.vc2 cere o conexiune reala - nu poate fi mock-uit
* prin goExecutor ca restul infrastructurii) si bucla modala inlocuita de actiuni programatice
* (WindowType=0, vezi docs/testare-ui-vfp.md capcana g). Vezi mock_cauta_alfa_dialog.prg pentru
* detalii si motivatie completa.
*
* Scenarii (fiecare printr-un apel REAL la goObj.do_adauga_articol()):
*   A: BULDOEXCAVATOR marcat (do_alege() real) + OK (do_termin() real) -> articolul TREBUIE sa
*      apara in rul_temp/grila.
*   B: nimic marcat + OK direct -> ipoteza cailor tacute: gnButon=1 (OK seteaza mereu gnButon=1,
*      indiferent de marcaj - _frm_base.do_termin), XML dintr-un cursor GOL (CURSORTOXML pe 0
*      randuri) NU e EMPTY() ca string -> trece de "IF gnButon=1 AND !EMPTY(lcXMLArticole)" ->
*      XMLTOCURSOR da 0 randuri -> SCAN nu itereaza -> nimic adaugat, FARA mesaj (tlLoud implicit
*      .F. la cauta_nom_articole(lcFiltru) cu un singur parametru - suprima mesajul din
*      XML2ListaIDDescriere indiferent de nr. de randuri).
*   C: dublu-click pe denumire (fara marcaj) - in modul multi-select (lAles=.T.) NU exista binding
*      dblClick->do_termin (cauta_alfa_forms.vc2:652 "If !Thisform.lales") - dublu-click echivaleaza
*      cu 2x Click (do_alege de 2 ori: marcheaza apoi demarcheaza) - fara submit automat.
*
* Rulare:
*   powershell -ExecutionPolicy Bypass -File vfp_ui_harness.ps1 `
*       -TestPrg test_picker_real_212.prg `
*       -Steps @('nota-goala','dialog-A-marcat','grila-A-rezultat','rezultat-B','rezultat-C','final')

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

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

	*----- PROCEDURI (mock amessagebox + shadow cauta_alfa 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_alfa_dialog.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 PrLog WITH 'SET PROCEDURE OK'

	*----- 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)

	*-- gnButon: variabila "gola" folosita in tot lantul cauta_alfa->do_termin/do_renunt->
	*-- do_adauga_articol. In aplicatia reala e declarata PRIVATE o singura data la pornire
	*-- (Programe/roagest.prg:496) si ramane vizibila tot restul rularii; aici o declar PUBLIC.
	PUBLIC gnButon
	STORE 0 TO gnButon

	*-- Control test citit de mock_cauta_alfa_dialog.prg
	PUBLIC gcTestScenariu
	PUBLIC gcTestGnButon, gcTestXML, gcTestLenXML, gcTestCAles, gcTestRandiuriMarcate
	*-- diagnostic cerut de team lead: pcAles (variabila PRIVATE folosita in filtrul XML) vs
	*-- Thisform.cAles (marcajul vizual/albastrit) - verifica daca raman SINCRONE
	PUBLIC gcTestPcAles, gcTestPcAlesInainte, gcTestCAlesInainte

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

	*----- poAct: antetul notei -----
	PUBLIC poAct
	poAct = CREATEOBJECT('Custom')
	poAct.AddProperty('nume_val', '')
	poAct.AddProperty('curs', 1)
	poAct.AddProperty('proc_tva', 1.21)
	poAct.AddProperty('nnir', 0)
	poAct.AddProperty('id_valuta', 0)
	poAct.AddProperty('id_fdoc', 1)
	poAct.AddProperty('fdoc', 'Factura')
	poAct.AddProperty('id_partc', 500)
	poAct.AddProperty('partc', 'FURNIZOR ANTET SRL')
	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 (ca in test_adauga_repere_212.prg) -----
	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)

	*----- introdc: 1 document principal, deja adaugat, ca sa existe o cota_tva de mostenit -----
	DO CreeazaIntrodc WITH 'introdc'
	INSERT INTO introdc (nract, dataact, fdoc, id_fdoc, id_partc, partc, explicatia, suma, ;
			tip_rand, scd, scc, cu_tva, id_set, ordine, participa_valuta, id_jtva_coloana, ptva, ;
			explicatie_tva, doc_key) ;
		VALUES (100, DATE(), 'Factura', 1, 601, 'FURNIZOR PRINCIPAL SRL', 'Marfa', 5000, ;
			'B', '371', '401', 1, 1, 1, .T., 208, 21, 'ACH. INT. 21%', 'B|100|1|601')
	INSERT INTO introdc (nract, dataact, fdoc, id_fdoc, id_partc, partc, suma, ;
			tip_rand, scd, scc, cu_tva, id_set, ordine, participa_valuta, id_jtva_coloana, ptva, ;
			explicatie_tva, doc_key) ;
		VALUES (100, DATE(), 'Factura', 1, 601, 'FURNIZOR PRINCIPAL SRL', 1050, ;
			'T', '4426', '401', 1, 1, 2, .T., 209, 21, 'TVA ACH. INT. 21%', 'T|100|1|601')
	GO TOP IN introdc

	*----- rul_temp cu 1 rand INAINTE de instantiere (capcana k) -----
	DO CreeazaRulTemp
	INSERT INTO rul_temp (denumire, codmat, cant, pret, pret_lei, cont, cota_tva) ;
		VALUES ('PLACEHOLDER', 'PH', 1, 1, 1, '371', 21)

	*----- gcMockNomCursor: "nomenclatorul fals" cerut de team lead - BULDOEXCAVATOR cont 212 +
	*      2 articole in plus, cu structura EXACTA a select-ului din cauta_nom_articole
	*      (ocautare.prg:563-567, vnom_articole_toate). -----
	IF USED('nom_fals')
		USE IN ('nom_fals')
	ENDIF
	CREATE CURSOR nom_fals ( ;
		denumire C(100), codmat C(30), codbare C(30), um C(10), grupa C(50), subgrupa C(50), ;
		id_grupa N(10), id_subgrupa N(10), dnf C(20), cont C(10), acont C(20), inactiv N(1), ;
		id_articol N(10), um2 C(10), um_iso C(10), cod_um_iso C(10), cant_bax N(10,3), ;
		in_crm N(1), in_stoc N(1), codmatf C(30), conditii_pastrare C(100), id_part N(10), ;
		partener C(100), indicativ C(30), taxa_reconditionare N(10,4), id_articol_general N(10), ;
		articol_general C(100), listare_codbare N(1), tip C(20), timpn N(10,4), codnc8 C(20), ;
		greutate N(10,4), id_tara_origine N(5), tara_origine C(50), codcpv C(20))
	INSERT INTO nom_fals (denumire, codmat, um, cont, acont, inactiv, id_articol, in_stoc) ;
		VALUES ('BULDOEXCAVATOR', 'ART-BULD-212', 'BUC', '212', '', 0, 1001, 1)
	INSERT INTO nom_fals (denumire, codmat, um, cont, acont, inactiv, id_articol, in_stoc) ;
		VALUES ('EXCAVATOR MIC', 'ART-EXC-212', 'BUC', '212', '', 0, 1002, 1)
	INSERT INTO nom_fals (denumire, codmat, um, cont, acont, inactiv, id_articol, in_stoc) ;
		VALUES ('MOTOSAPA', 'ART-MOTO-213', 'BUC', '213', '', 0, 1003, 1)
	GO TOP IN nom_fals

	*----- goDlgA/B/C: cele 3 dialoage REALE (cauta_alfa_form), PRE-CONSTRUITE aici in programul
	*      PRINCIPAL - CREATEOBJECT apelat dintr-o procedura intoarce obiect stricat in acest runtime
	*      headless (capcana l, docs/testare-ui-vfp.md); shadow-ul (mock_cauta_alfa_dialog.prg) doar
	*      selecteaza unul din aceste 3 obiecte dupa gcTestScenariu, nu le mai construieste. Fiecare
	*      are propriul cursor (copie din nom_fals), ca marcajele dintr-un scenariu sa nu se scurga in
	*      altul. Parametrii Init sunt EXACT cei trimisi de cauta_nom_articole (ocautare.prg:556-575)
	*      catre cauta_alfa: coloane/titluri identice, ll_AllInList=.F., tnTipReturn=1 (lAles=.T.). -----
	LOCAL lcTitluColoaneNom, lcColoaneNom
	lcTitluColoaneNom = 'Denumire,Cod Material,Cod bare,UM,Grupa,Subgrupa,Cont,Analitic,DNF,Id'
	lcColoaneNom = 'denumire,codmat,codbare,um,grupa,subgrupa,cont,acont,dnf,id_articol'

	PUBLIC goDlgA, goDlgB, goDlgC
	LOCAL lcCurA, lcCurB, lcCurC
	lcCurA = SYS(2015)
	SELECT * FROM nom_fals INTO CURSOR (lcCurA) READWRITE
	lcCurB = SYS(2015)
	SELECT * FROM nom_fals INTO CURSOR (lcCurB) READWRITE
	lcCurC = SYS(2015)
	SELECT * FROM nom_fals INTO CURSOR (lcCurC) READWRITE

	goDlgA = CREATEOBJECT('cauta_alfa_form', lcCurA, '', lcTitluColoaneNom, lcColoaneNom, .F., 'denumire', 1)
	goDlgA.crs_cursor = lcCurA
	goDlgA.Lb_titlu_alb_b121.Caption = 'Alegeti articolele (mouse-click pe denumire sau apasati SPACE)'
	goDlgA.lAles = .T.
	goDlgA.cAles = REPLICATE(' ', RECCOUNT(lcCurA))
	goDlgA.cIdColumn = 'id_articol'
	goDlgA.WindowType = 0
	goDlgA.Show()

	goDlgB = CREATEOBJECT('cauta_alfa_form', lcCurB, '', lcTitluColoaneNom, lcColoaneNom, .F., 'denumire', 1)
	goDlgB.crs_cursor = lcCurB
	goDlgB.Lb_titlu_alb_b121.Caption = 'Alegeti articolele (mouse-click pe denumire sau apasati SPACE)'
	goDlgB.lAles = .T.
	goDlgB.cAles = REPLICATE(' ', RECCOUNT(lcCurB))
	goDlgB.cIdColumn = 'id_articol'
	goDlgB.WindowType = 0
	goDlgB.Show()

	goDlgC = CREATEOBJECT('cauta_alfa_form', lcCurC, '', lcTitluColoaneNom, lcColoaneNom, .F., 'denumire', 1)
	goDlgC.crs_cursor = lcCurC
	goDlgC.Lb_titlu_alb_b121.Caption = 'Alegeti articolele (mouse-click pe denumire sau apasati SPACE)'
	goDlgC.lAles = .T.
	goDlgC.cAles = REPLICATE(' ', RECCOUNT(lcCurC))
	goDlgC.cIdColumn = 'id_articol'
	goDlgC.WindowType = 0
	goDlgC.Show()
	DOEVENTS FORCE
	DO PrLog WITH 'goDlgA/B/C construite (3 formulare REALE cauta_alfa_form, fiecare cu propriul cursor)'

	DO PrLog WITH 'cursoare pregatite, CREATEOBJECT(import_nota, .T.)'
	SELECT introdc
	PUBLIC goObj
	goObj = CREATEOBJECT('IMPORT_nota', .T.)
	IF VARTYPE(goObj) <> 'O'
		DO PrLog WITH 'FAIL: instantiere import_nota'
		DO HarnessDone WITH 'done-error'
		QUIT
	ENDIF
	goObj.lDialogAratat = .T.
	goObj.oact = poAct
	goObj.WindowType = 0
	goObj.Visible = .T.
	goObj.Show()
	goObj.WindowState = 2
	DOEVENTS FORCE

	*-- golesc placeholder-ul cu ZAP (capcana k)
	SELECT rul_temp
	ZAP
	goObj.gridart.Refresh()
	DOEVENTS FORCE

	*========================= PAS 0: nota afisata =========================
	DO HarnessStep WITH 0, 'import_nota afisat, rul_temp=' + TRANSFORM(RECCOUNT_ACTIVE('rul_temp')) + ' articole, nom_fals=' + TRANSFORM(RECCOUNT_ACTIVE('nom_fals')) + ' randuri (BULDOEXCAVATOR cont 212 + 2)'

	*========================= SCENARIUL A: marcheaza BULDOEXCAVATOR + OK real =========================
	LOCAL lnRandInainteA, lnRandDupaA, llEroareA
	gcTestScenariu = 'A'
	STORE 0 TO gnButon
	lnRandInainteA = RECCOUNT_ACTIVE('rul_temp')
	llEroareA = .F.
	TRY
		goObj.do_adauga_articol()
	CATCH TO loExcA
		llEroareA = .T.
		DO PrLog WITH 'SCENARIU A: EROARE la do_adauga_articol() ' + TRANSFORM(loExcA.ErrorNo) + ' [' + loExcA.Message + ;
			'] in ' + loExcA.Procedure + ':' + TRANSFORM(loExcA.LineNo) + ' (' + loExcA.LineContents + ')'
	ENDTRY
	DOEVENTS FORCE
	goObj.gridart.Refresh()
	DOEVENTS FORCE
	lnRandDupaA = RECCOUNT_ACTIVE('rul_temp')
	DO PrLog WITH 'SCENARIU A: gnButon(din shadow)=' + TRANSFORM(gcTestGnButon) + ' LEN(XML)=' + TRANSFORM(gcTestLenXML) + ' EMPTY(XML)=' + TRANSFORM(EMPTY(gcTestXML)) + ' randuriMarcate(dupa filtrul X)=' + TRANSFORM(gcTestRandiuriMarcate) + ' cAles=[' + gcTestCAles + ']'
	DO PrLog WITH 'SCENARIU A: DIAGNOSTIC pcAles vs Thisform.cAles (cerut de team lead) - pcAlesInainteDeXML=[' + gcTestPcAlesInainte + '] cAlesInainteDeXML=[' + gcTestCAlesInainte + '] SINCRON=' + TRANSFORM(gcTestPcAlesInainte == gcTestCAlesInainte) + ' | dupa=[' + gcTestPcAles + ']'
	DO PrLog WITH 'SCENARIU A: XML complet = [' + gcTestXML + ']'
	DO PrLog WITH 'SCENARIU A: rul_temp INAINTE=' + TRANSFORM(lnRandInainteA) + ' DUPA=' + TRANSFORM(lnRandDupaA) + ' eroare=' + TRANSFORM(llEroareA)

	LOCAL llArtA
	llArtA = .F.
	SELECT rul_temp
	LOCATE FOR ALLTRIM(codmat) == 'ART-BULD-212'
	IF FOUND()
		llArtA = .T.
		DO PrLog WITH 'PASS scenariul A: BULDOEXCAVATOR marcat+OK -> articolul APARE in rul_temp (denumire=' + ALLTRIM(denumire) + ' cont=[' + ALLTRIM(NVL(cont,'')) + '])'
	ELSE
		DO PrLog WITH 'FAIL scenariul A: BULDOEXCAVATOR marcat+OK -> articolul NU apare in rul_temp (asteptat: sa apara)'
	ENDIF

	*-- captura grila cu articolul deja adaugat de scenariul A (pasul 1 din harness e scris DIN
	*-- INTERIORUL shadow-ului cauta_alfa, la momentul "dialog cu BULDOEXCAVATOR marcat, inainte de
	*-- OK" - vezi mock_cauta_alfa_dialog.prg, CASE gcTestScenariu=='A' - deci acesta e pasul 2)
	DO HarnessStep WITH 2, 'grila dupa scenariul A (BULDOEXCAVATOR marcat+OK): rul_temp=' + TRANSFORM(RECCOUNT_ACTIVE('rul_temp')) + ' randuri'

	*========================= SCENARIUL B: nimic marcat + OK =========================
	*-- reset rul_temp la starea goala pentru un test curat al scenariului B
	SELECT rul_temp
	ZAP
	goObj.gridart.Refresh()
	DOEVENTS FORCE

	LOCAL lnRandInainteB, lnRandDupaB, llEroareB
	gcTestScenariu = 'B'
	STORE 0 TO gnButon
	lnRandInainteB = RECCOUNT_ACTIVE('rul_temp')
	llEroareB = .F.
	TRY
		goObj.do_adauga_articol()
	CATCH TO loExcB
		llEroareB = .T.
		DO PrLog WITH 'SCENARIU B: EROARE la do_adauga_articol() ' + TRANSFORM(loExcB.ErrorNo) + ' [' + loExcB.Message + ']'
	ENDTRY
	DOEVENTS FORCE
	goObj.gridart.Refresh()
	DOEVENTS FORCE
	lnRandDupaB = RECCOUNT_ACTIVE('rul_temp')
	DO PrLog WITH 'SCENARIU B: gnButon(din shadow)=' + TRANSFORM(gcTestGnButon) + ' LEN(XML)=' + TRANSFORM(gcTestLenXML) + ' EMPTY(XML)=' + TRANSFORM(EMPTY(gcTestXML)) + ' randuriMarcate(dupa filtrul X)=' + TRANSFORM(gcTestRandiuriMarcate) + ' cAles=[' + gcTestCAles + ']'
	DO PrLog WITH 'SCENARIU B: XML complet = [' + gcTestXML + ']'
	DO PrLog WITH 'SCENARIU B: rul_temp INAINTE=' + TRANSFORM(lnRandInainteB) + ' DUPA=' + TRANSFORM(lnRandDupaB) + ' eroare=' + TRANSFORM(llEroareB)

	LOCAL llMesajB
	llMesajB = ('MOCK amessagebox apelat' $ FILETOSTR(gcUILog))
	IF gcTestGnButon = 1 AND gcTestLenXML > 0 AND gcTestRandiuriMarcate = 0 AND lnRandDupaB = lnRandInainteB
		DO PrLog WITH 'PASS scenariul B: IPOTEZA CONFIRMATA - OK cu nimic marcat -> gnButon=1, XML NEGOL (' + TRANSFORM(gcTestLenXML) + ' caractere) dintr-un cursor cu 0 randuri marcate, do_adauga_articol NU adauga nimic (rul_temp neschimbat), FARA mesaj de eroare (mesaj amessagebox in log=' + TRANSFORM(llMesajB) + ')'
	ELSE
		DO PrLog WITH 'FAIL/DIFERIT scenariul A vs ipoteza: gnButon=' + TRANSFORM(gcTestGnButon) + ' (astept 1) LEN(XML)=' + TRANSFORM(gcTestLenXML) + ' (astept >0) randuriMarcate=' + TRANSFORM(gcTestRandiuriMarcate) + ' (astept 0) randDupa=' + TRANSFORM(lnRandDupaB) + ' randInainte=' + TRANSFORM(lnRandInainteB)
	ENDIF

	*========================= SCENARIUL C: dublu-click pe denumire (fara marcaj) =========================
	SELECT rul_temp
	ZAP
	goObj.gridart.Refresh()
	DOEVENTS FORCE

	LOCAL lnRandInainteC, lnRandDupaC, llEroareC
	gcTestScenariu = 'C'
	STORE 0 TO gnButon
	lnRandInainteC = RECCOUNT_ACTIVE('rul_temp')
	llEroareC = .F.
	TRY
		goObj.do_adauga_articol()
	CATCH TO loExcC
		llEroareC = .T.
		DO PrLog WITH 'SCENARIU C: EROARE la do_adauga_articol() ' + TRANSFORM(loExcC.ErrorNo) + ' [' + loExcC.Message + ']'
	ENDTRY
	DOEVENTS FORCE
	goObj.gridart.Refresh()
	DOEVENTS FORCE
	lnRandDupaC = RECCOUNT_ACTIVE('rul_temp')
	DO PrLog WITH 'SCENARIU C: gnButon(din shadow)=' + TRANSFORM(gcTestGnButon) + ' LEN(XML)=' + TRANSFORM(gcTestLenXML) + ' EMPTY(XML)=' + TRANSFORM(EMPTY(gcTestXML)) + ' randuriMarcate(dupa filtrul X)=' + TRANSFORM(gcTestRandiuriMarcate) + ' cAles=[' + gcTestCAles + ']'
	DO PrLog WITH 'SCENARIU C: rul_temp INAINTE=' + TRANSFORM(lnRandInainteC) + ' DUPA=' + TRANSFORM(lnRandDupaC) + ' eroare=' + TRANSFORM(llEroareC)
	IF lnRandDupaC = lnRandInainteC
		DO PrLog WITH 'INFO scenariul C: dublu-click pe denumire (fara submit automat pe dblclick in mod multi-select) -> dupa 2x Click(do_alege), OK -> acelasi comportament ca scenariul B (nimic net marcat, nimic adaugat)'
	ELSE
		DO PrLog WITH 'INFO scenariul C: rul_temp s-a modificat (randDupa=' + TRANSFORM(lnRandDupaC) + ' vs randInainte=' + TRANSFORM(lnRandInainteC) + ')'
	ENDIF

	DO HarnessStep WITH 3, 'rezultat scenariul B (nimic marcat+OK): rul_temp neschimbat=' + TRANSFORM(lnRandDupaB = lnRandInainteB) + ', fara mesaj=' + TRANSFORM(!llMesajB)

	DO HarnessStep WITH 4, 'rezultat scenariul C (dublu-click): rul_temp neschimbat=' + TRANSFORM(lnRandDupaC = lnRandInainteC)

	DO PrLog WITH 'GATA - toate scenariile executate (A/B/C)'
	DO HarnessStep WITH 5, 'final'
	DO HarnessDone WITH 'done'

CATCH TO loExc
	DO PrLog 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 CreeazaRulTemp
	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

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

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

PROCEDURE PrLog
	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
		IF 'VJTVA_COLOANE' $ UPPER(m.tcSql)
			DO CreeazaJtvaColoaneView WITH m.tcCursor
			RETURN 1
		ENDIF
		IF UPPER(ALLTRIM(m.tcCursor)) == 'RUL_TEMP'
			DO CreeazaRulTemp
		ELSE
			CREATE CURSOR (m.tcCursor) (id_temp N(1))
		ENDIF
		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)
	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
