* test_repro_import_nota.prg
* Repro pentru "Data type mismatch" raportat la CREATEOBJECT('IMPORT_nota', tlIntern)
* (COMUN\programe\ointroduceri.prg linia 1621, procedura achizitie_import).
* Clasa import_nota e in COMUN\clase\ointroduceri.vcx (parent frm_termin_renunt OF
* "_frm_child.vcx"). Scop: reproducem instantierea in afara aplicatiei, fara UI/Oracle
* reale (goExecutor e un dummy), ca sa vedem daca eroarea apare la atribuirea
* proprietatilor din definitia clasei (inainte de Init) sau in interiorul Init.
*
* Rulare headless:
*   & "C:\Program Files (x86)\Microsoft Visual FoxPro 9\vfp9.exe" -A ;
*     "D:\ROA\ROAGEST\COMUN\utile\Teste\achizitie_import\test_repro_import_nota.prg"
* Rezultat: D:\ROA\ROAGEST\COMUN\utile\Teste\achizitie_import\test_repro_import_nota_log.txt

LPARAMETERS tcBisect

PUBLIC gcLogFile, gcBisect
gcBisect = IIF(EMPTY(tcBisect), '', UPPER(ALLTRIM(tcBisect)))
gcLogFile = "D:\ROA\ROAGEST\COMUN\utile\Teste\achizitie_import\test_repro_import_nota_log.txt"
STRTOFILE("START " + TTOC(DATETIME()) + " bisect=" + gcBisect + CHR(13)+CHR(10), gcLogFile)

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

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

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 ReproLog 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
	IF EMPTY(gcBisect)
		SET CLASSLIB TO ointroduceri ADDITIVE
	ENDIF
	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

	*----- Bisectie: cand gcBisect e setat, clasa ointroduceri REALA (linia de mai sus) nu
	*      s-a incarcat deloc (vezi IF EMPTY(gcBisect) mai sus) - incarcam DOAR copia
	*      modificata, ca sa nu depindem de ordinea de rezolvare intre doua classlib-uri
	*      cu acelasi nume de clasa incarcate simultan (risc de fals negativ). Vezi
	*      COMUN\docs\depanare_testare_vfp.md sectiunea 4. -----
	DO CASE
	CASE gcBisect == 'H1_CTIP'
		SET CLASSLIB TO "C:\Users\mmari\AppData\Local\Temp\claude\D--ROA-ROAGEST\e6e780ff-4117-4276-9c13-3235134137f5\scratchpad\bisect_ointroduceri\ointroduceri.vcx" ADDITIVE
		DO ReproLog WITH 'BISECT H1_CTIP: doar clasa modificata incarcata (Column24.ControlSource -> "tip_rand")'
	CASE gcBisect == 'H2_CTAXCODE'
		SET CLASSLIB TO "C:\Users\mmari\AppData\Local\Temp\claude\D--ROA-ROAGEST\e6e780ff-4117-4276-9c13-3235134137f5\scratchpad\bisect_ointroduceri\ointroduceri.vcx" ADDITIVE
		DO ReproLog WITH 'BISECT H2_CTAXCODE: doar clasa modificata incarcata (Column21.ControlSource -> "taxcode")'
	CASE gcBisect == 'RULTEMP'
		SET CLASSLIB TO ointroduceri ADDITIVE
		DO ReproLog WITH 'BISECT RULTEMP: clasa reala + rul_temp pre-creat'
	CASE !EMPTY(gcBisect)
		SET CLASSLIB TO ("C:\Users\mmari\AppData\Local\Temp\claude\D--ROA-ROAGEST\e6e780ff-4117-4276-9c13-3235134137f5\scratchpad\" + gcBisect + "\ointroduceri.vcx") ADDITIVE
		DO ReproLog WITH 'BISECT generic: doar clasa din scratchpad\' + gcBisect + ' incarcata'
	ENDCASE

	DO ReproLog WITH 'SET CLASSLIB OK'
	LOCAL lnCL, lcCLPath, lcCLList
	lcCLList = ''
	FOR lnCL = 1 TO 1
		lcCLPath = SET('CLASSLIB', lnCL)
		IF EMPTY(lcCLPath)
			EXIT
		ENDIF
		IF 'OINTRODUCERI' $ UPPER(lcCLPath)
			lcCLList = lcCLList + TRANSFORM(lnCL) + '=' + lcCLPath + ' | '
		ENDIF
	ENDFOR
	DO ReproLog WITH 'classlib-uri "ointroduceri" active: ' + lcCLList

	*----- PROCEDURI -----
	SET PROCEDURE TO PROCEDURI
	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

	DO ReproLog WITH 'SET PROCEDURE OK'

	*----- 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 = .F.
	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 cursorul cerut fara Oracle real -----
	PUBLIC goExecutor
	goExecutor = CREATEOBJECT('dummyexecutor')
	DO ReproLog WITH 'goExecutor dummy creat'

	*----- poAct dummy (ramura lIntern=.F.; nu ar trebui atinsa cu tlIntern=.T.) -----
	PUBLIC poAct
	poAct = CREATEOBJECT('Custom')
	poAct.AddProperty('nume_val', 'EUR')
	poAct.AddProperty('curs', 5)
	poAct.AddProperty('proc_tva', 1.19)
	poAct.AddProperty('nnir', 0)

	*----- jtva_coloane2: structura din ointroduceri.prg:1601-1609 (SELECT ... INTO CURSOR) -----
	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 (ordine, id_jtva_coloana, denumire, jc, jv, afisat, coloana_jc, coloana_jv, cota_tva, id_tva) ;
		VALUES (0, 0, '', 0, 0, 1, '', '', 0, 0)
	INSERT INTO jtva_coloane2 (ordine, id_jtva_coloana, denumire, jc, jv, afisat, coloana_jc, coloana_jv, cota_tva, id_tva) ;
		VALUES (1, 101, 'ACH. INT. 19%', 1, 0, 1, 'coloana_jc', 'coloana_jv', 19, 1)
	DO ReproLog WITH 'jtva_coloane2 creat'

	*----- saft_taxtable: structura din COMUN\programe\updateserver.prg:625 (update_saft_taxtable) -----
	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 ReproLog WITH 'saft_taxtable creat'

	*----- introdc: N.* din cnote_contabile (ointroduceri.prg:1467, select din vnote_contabile) ;
	*      + coloanele AS din ointroduceri.prg:1553-1563. Ramane GOL (in fluxul real e Zap-uit
	*      dupa clonarea in introdc_sablon - ointroduceri.prg:1577). Tipuri taxcode/paymentcode
	*      potrivite dupa saft_taxtable.taxcode (N(6)) si saft_mecanisme_plati.methodcode (C(9)),
	*      vezi updateserver.prg:625,652.
	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), ;
		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))
	DO ReproLog WITH 'introdc creat (gol, ' + TRANSFORM(FCOUNT('introdc')) + ' campuri)'

	*----- rul_temp: in fluxul real e creat abia in Init (T2); il cream aici INAINTE de
	*      CREATEOBJECT ca sa testam ipoteza ca GridArt (runda 3a) se leaga la constructie
	*      de rul_temp inexistent. Structura minimala: campurile referite de GridArt. -----
	IF gcBisect == 'RULTEMP' OR gcBisect == 'RULTEMP_CUR'
		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))
		DO ReproLog WITH 'rul_temp creat INAINTE de CREATEOBJECT'
	ENDIF

	DO ReproLog WITH 'mediu pregatit, incerc CREATEOBJECT(import_nota)'

	SELECT introdc
	LOCAL loObj
	loObj = CREATEOBJECT('IMPORT_nota', .T.)

	IF VARTYPE(loObj) == 'O'
		DO ReproLog WITH 'INSTANTIERE OK'
		RELEASE loObj
	ELSE
		DO ReproLog WITH 'INSTANTIERE A RETURNAT ' + TRANSFORM(loObj) + ' (nu obiect)'
	ENDIF

CATCH TO loExc
	DO ReproLog WITH 'CATCH ErrorNo=' + TRANSFORM(loExc.ErrorNo)
	DO ReproLog WITH 'CATCH Message=' + loExc.Message
	DO ReproLog WITH 'CATCH Procedure=' + loExc.Procedure
	DO ReproLog WITH 'CATCH LineNo=' + TRANSFORM(loExc.LineNo)
	DO ReproLog WITH 'CATCH LineContents=' + loExc.LineContents
	DO ReproLog WITH 'CATCH Details=' + loExc.Details
	DO ReproLog WITH 'CATCH StackLevel=' + TRANSFORM(loExc.StackLevel)
ENDTRY

DO ReproLog WITH 'GATA'
QUIT

PROCEDURE ReproErr
	LPARAMETERS tnErr, tcMsg, tcProg, tnLine
	DO ReproLog WITH 'ON ERROR (in afara TRY) ' + TRANSFORM(tnErr) + ' [' + tcProg + ':' + TRANSFORM(tnLine) + '] ' + tcMsg
ENDPROC

PROCEDURE ReproLog
	LPARAMETERS tcMsg
	LOCAL lcL
	lcL = FILETOSTR(gcLogFile)
	STRTOFILE(lcL + tcMsg + CHR(13)+CHR(10), gcLogFile)
ENDPROC

DEFINE CLASS dummyexecutor AS Custom
	cEroare = ''

	PROCEDURE oExecute
		LPARAMETERS tcSql, tcCursor
		IF USED(m.tcCursor)
			USE IN (m.tcCursor)
		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
			CREATE CURSOR (m.tcCursor) (id_temp N(1))
		ENDIF
		RETURN .T.
	ENDPROC
ENDDEFINE
