* test_repro_podate_unknown_member.prg
* Reproduce eroarea raportata de utilizator (03.08.2026): "Unknown member PODATE" in
* FRM_FACTURA.DO_CAUTA_PARTENER, la clic pe but_cautare_client, in fluxul FACTURA_ACN.
*
* Cauza: fix-ul anterior a scris "Thisform.poDate.dataact", dar poDate NU e proprietate a
* formularului - e variabila PRIVATE declarata in factura_acn() (proceduri_acnpro.prg:3072),
* vizibila fara calificator in toate metodele frm_factura (folosita bar asa in ~30 de locuri:
* oacnpro.vc2 liniile 7542,7719,7747,8059 etc). Thisform.poDate nu exista => "Unknown member".
*
* Testeaza DOAR mecanismul de scoping (fara sa instantieze tot frm_factura/crsCapFactura):
* replica exact contextul - o procedura apelanta declara PRIVATE poDate, apoi o subprocedura
* (analoaga cu metoda do_cauta_partener) foloseste expresia. Verifica intai ca varianta veche
* (Thisform.poDate) DA eroarea raportata, apoi ca varianta noua (poDate bare) NU da eroare.
*
* Rulare: vfp9.exe -A -T "test_repro_podate_unknown_member.prg"

SET SAFETY OFF
SET TALK OFF

PUBLIC gcUILog
gcUILog = "D:\ROA\ROAACNPRO\COMUN\utile\Teste\test_repro_podate_unknown_member_log.txt"
STRTOFILE("START" + CHR(13)+CHR(10), gcUILog)

DO test_apelant_factura_acn

QUIT

PROCEDURE test_apelant_factura_acn
	*-- replica factura_acn(): PRIVATE poDate, ramane in scop pentru tot ce se apeleaza mai jos
	PRIVATE poDate
	poDate = CREATEOBJECT('Empty')
	ADDPROPERTY(poDate, 'dataact', DATE())

	*-- instantiez un obiect minimal, cu o metoda care replica STRICT do_cauta_partener
	PUBLIC goFormTest
	goFormTest = CREATEOBJECT('formtest_do_cauta_partener')

	*-- varianta VECHE (bug reportat): Thisform.poDate - poDate nu e proprietate a obiectului
	LOCAL lcRezVechi
	lcRezVechi = goFormTest.do_cauta_partener_vechi()
	DO PrLogLocal WITH 'VARIANTA VECHE (Thisform.poDate): ' + lcRezVechi

	*-- varianta NOUA (fix aplicat): poDate bare, gasit ca PRIVATE in call stack
	LOCAL lcRezNou
	lcRezNou = goFormTest.do_cauta_partener_nou()
	DO PrLogLocal WITH 'VARIANTA NOUA (poDate bare): ' + lcRezNou

	DO PrLogLocal WITH 'GATA'
ENDPROC

DEFINE CLASS formtest_do_cauta_partener AS Form
	PROCEDURE do_cauta_partener_vechi
		LOCAL lcRes
		lcRes = 'NEASTEPTAT: nu a aruncat eroare'
		TRY
			LOCAL ldDataTest
			ldDataTest = Thisform.poDate.dataact
			lcRes = 'NEASTEPTAT: Thisform.poDate.dataact a functionat, data=' + TRANSFORM(m.ldDataTest)
		CATCH TO loExc
			lcRes = 'EROARE REPRODUSA: ErrorNo=' + TRANSFORM(loExc.ErrorNo) + ' Message=' + loExc.Message
		ENDTRY
		RETURN m.lcRes
	ENDPROC

	PROCEDURE do_cauta_partener_nou
		LOCAL lcRes
		lcRes = 'NEASTEPTAT: nu s-a putut evalua'
		TRY
			LOCAL ldDataTest
			ldDataTest = poDate.dataact
			lcRes = 'OK: poDate.dataact rezolvat, data=' + TRANSFORM(m.ldDataTest)
		CATCH TO loExc
			lcRes = 'FAIL: ErrorNo=' + TRANSFORM(loExc.ErrorNo) + ' Message=' + loExc.Message
		ENDTRY
		RETURN m.lcRes
	ENDPROC
ENDDEFINE

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