* test_runda7_diferente.prg
* Verifica RUNDA 7 (COMUN\clase\ointroduceri.vcx, clasa import_nota) - vezi
* docs\diff_runda7_dif_lei_6588_focus.patch:
*   1. recalc_diferente: diferenta se scrie DOAR in lei pe randul D (suma_val=0, in_valuta=0,
*      participa_valuta=.F., nume_val='', id_valuta=0, curs=0, Thisform.ndif_val=0, explicatia=='DIFERENTA').
*   2. Cont diferenta: dominant clasa 3 -> regulile vechi (34x->711, 371->607, 381/388->608,
*      altfel 60+cifrele 3-4 din cont); FARA clasa 3 (doar articole clasa 2/imobilizari) -> scd FIX '6588'.
*   3. sparge_document nu mai scrie sufixul ' (rot.)' in explicatia.
*   4. Guard "doar la modificare" pe Grid1.cSuma/cSumaVal/GridArt.cCotaTva (GotFocus salveaza
*      valoarea veche in nsumavechi/nsumavalvechi/ncotatvavechi; Valid iese fara efect daca
*      Value == valoarea veche).
*   5. sincronizeaza() restaureaza pozitia si de pe randul D (Locate For tip_rand=='D').
*
* Scenariul A (exemplul lui Marius): FACTURA 100 RAJA EUR curs 5.23 (DVI 101 BIROUL VAMAL) +
*   FACTURA 102 TRANS OIL 1000 lei (DVI 101) + FACTURA 103 BIROUL VAMAL 500 lei (TVA la furnizor),
*   articole prin fluxul real "Adauga repere": BULDOEXCAVATOR cont 212 (1 buc, 5000 EUR) si
*   AC GREE BORA cont 303 (1 buc, 100 EUR) -> dominant clasa 3 (303) -> scd='603'.
* Scenariul B: FACTURA 100 + DVI 101 (subset), UNIC articol BULDOEXCAVATOR cont 212 (imobilizari,
*   fara clasa 3) -> scd FIX '6588'.
*
* Rulare:
*   powershell -ExecutionPolicy Bypass -File test_runda7_diferente.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_runda7_diferente_log.txt"
gcSyncDir = "D:\ROA\ROAGEST\COMUN\utile\Teste\achizitie_import\uisync_runda7\"
STRTOFILE("START " + TTOC(DATETIME()) + CHR(13)+CHR(10), gcUILog)

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

	*----- PROCEDURI (mock amessagebox + mock cauta_nom_articole 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 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 R7Log 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)

	PUBLIC gnButon
	STORE 2 TO gnButon
	PUBLIC gcMockArtCodmat
	gcMockArtCodmat = ''

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

	*----- poAct: antetul notei; dialogul mosteneste din el la Init -----
	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 21% (ca in test_scenariu_import_212). -----
	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)

	*===================================================================================
	*==================== SCENARIUL A: dominant clasa 3 (303) -> scd '603' ===========
	*===================================================================================
	DO R7Log WITH '========== SCENARIUL A: FACTURA 100/102/103 + articole 212+303 =========='
	*-- F1 (ointroduceri.prg:1616-1618): indexul ord_doc, o singura data, INAINTE de CREATEOBJECT -
	*-- fara el, Go Top+Locate din sincronizeaza() gaseste documentul "principal" dupa ordinea
	*-- fizica (recno), care se schimba dupa fiecare spargere -> cascada gresita pe documente
	*-- nefactura-principala. Cu indexul, ordinea e mereu dupa nr_doc (S-urile mostenesc nr_doc-ul
	*-- principalei), deci documentul principal ramane stabil la sincronizari repetate.
	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
	PUBLIC goObjA
	goObjA = CREATEOBJECT('IMPORT_nota', .F.)
	IF VARTYPE(goObjA) <> 'O'
		DO R7Log WITH 'FAIL: instantiere import_nota (Scenariul A)'
		DO HarnessDone WITH 'done-error'
		QUIT
	ENDIF
	goObjA.lDialogAratat = .T.
	goObjA.oact = poAct
	goObjA.WindowType = 0
	goObjA.Visible = .T.
	goObjA.Show()
	goObjA.WindowState = 2
	DOEVENTS FORCE

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

	*----- DOC 1: FACTURA 100, RAJA, DVI valuta (EUR curs 5.23) -----
	PUBLIC goDlg, goT
	goDlg = CREATEOBJECT('import_adauga_factura', goObjA)
	goDlg.cFelDoc = 'Factura'
	goDlg.nIdFdoc = 1
	goDlg.nNract = 100
	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 R7Log WITH 'A-DOC1: valideaza = ' + TRANSFORM(goDlg.valideaza())
	DO ConstruiesteToDlg
	DO R7Log WITH 'A-DOC1: do_adauga_factura = ' + TRANSFORM(goObjA.do_adauga_factura(goT))
	goDlg.Hide()
	DOEVENTS FORCE

	*----- DOC 2: FACTURA 102, TRANS OIL MOTO, DVI lei (acelasi doc vamal 101) -----
	goDlg = CREATEOBJECT('import_adauga_factura', goObjA)
	goDlg.cFelDoc = 'Factura'
	goDlg.nIdFdoc = 1
	goDlg.nNract = 102
	goDlg.dDataAct = DATE()
	goDlg.nIdPartener = 602
	goDlg.cPartener = 'TRANS OIL MOTO'
	goDlg.cExplicatia = 'Achizitie TRANS OIL MOTO'
	goDlg.nSuma = 1000
	goDlg.nSumaLei = 0
	goDlg.nCurs = 0
	goDlg.nIdExplicatieTva = 220
	goDlg.cExplicatieTva = 'ACH. IMP. 21%'
	goDlg.optTipTva.Value = 2 && D = DVI
	goDlg.chkInValutaCont.Value = 0
	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 = 210.00
	goDlg.nDviTvaVal = 0
	goDlg.actualizeaza_stare_dvi()
	goDlg.WindowType = 0
	goDlg.Visible = .T.
	goDlg.Show()
	DOEVENTS FORCE
	DO R7Log WITH 'A-DOC2: valideaza = ' + TRANSFORM(goDlg.valideaza())
	DO ConstruiesteToDlg
	DO R7Log WITH 'A-DOC2: do_adauga_factura = ' + TRANSFORM(goObjA.do_adauga_factura(goT))
	goDlg.Hide()
	DOEVENTS FORCE

	*----- DOC 3: FACTURA 103, BIROUL VAMAL, TVA la furnizor (nu DVI) -----
	goDlg = CREATEOBJECT('import_adauga_factura', goObjA)
	goDlg.cFelDoc = 'Factura'
	goDlg.nIdFdoc = 1
	goDlg.nNract = 103
	goDlg.dDataAct = DATE()
	goDlg.nIdPartener = 900
	goDlg.cPartener = 'BIROUL VAMAL'
	goDlg.cExplicatia = 'Factura BIROUL VAMAL'
	goDlg.nSuma = 500
	goDlg.nSumaLei = 0
	goDlg.nCurs = 0
	goDlg.nIdExplicatieTva = 208
	goDlg.cExplicatieTva = 'ACH. INT. 21%'
	goDlg.optTipTva.Value = 1 && F = furnizor
	goDlg.chkInValutaCont.Value = 0
	goDlg.chkParticipaValuta.Value = 1
	goDlg.WindowType = 0
	goDlg.Visible = .T.
	goDlg.Show()
	DOEVENTS FORCE
	DO R7Log WITH 'A-DOC3: valideaza = ' + TRANSFORM(goDlg.valideaza())
	DO ConstruiesteToDlg
	DO R7Log WITH 'A-DOC3: do_adauga_factura = ' + TRANSFORM(goObjA.do_adauga_factura(goT))
	goDlg.Hide()
	DOEVENTS FORCE

	DO R7Log WITH 'A: dump introdc dupa cele 3 documente:'
	DO DumpIntrodc

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

	*----- Adaugare articole prin fluxul REAL do_adauga_articol -----
	gcMockArtCodmat = 'ART-BULD-212'
	TRY
		goObjA.do_adauga_articol()
	CATCH TO loExcAddA1
		DO R7Log WITH 'EROARE do_adauga_articol (BULDOEXCAVATOR) ' + TRANSFORM(loExcAddA1.ErrorNo) + ' [' + loExcAddA1.Message + ']'
	ENDTRY
	DOEVENTS FORCE
	SELECT rul_temp
	LOCATE FOR ALLTRIM(codmat) == 'ART-BULD-212'
	IF FOUND()
		REPLACE cant WITH 1, pret_val WITH 5000, pretd WITH 5000, pret WITH ROUND(5000*5.23,4), pret_lei WITH ROUND(5000*5.23,4)
		DO R7Log WITH 'A: BULDOEXCAVATOR (212) adaugat prin do_adauga_articol REAL, cant/pret completate'
	ELSE
		DO R7Log WITH 'FAIL A: BULDOEXCAVATOR nu a fost adaugat de do_adauga_articol()'
	ENDIF

	gcMockArtCodmat = 'ART-GREE-303'
	TRY
		goObjA.do_adauga_articol()
	CATCH TO loExcAddA2
		DO R7Log WITH 'EROARE do_adauga_articol (AC GREE BORA) ' + TRANSFORM(loExcAddA2.ErrorNo) + ' [' + loExcAddA2.Message + ']'
	ENDTRY
	DOEVENTS FORCE
	SELECT rul_temp
	LOCATE FOR ALLTRIM(codmat) == 'ART-GREE-303'
	IF FOUND()
		REPLACE cant WITH 1, pret_val WITH 100, pretd WITH 100, pret WITH ROUND(100*5.23,4), pret_lei WITH ROUND(100*5.23,4)
		DO R7Log WITH 'A: AC GREE BORA (303) adaugat prin do_adauga_articol REAL, cant/pret completate'
	ELSE
		DO R7Log WITH 'FAIL A: AC GREE BORA nu a fost adaugat de do_adauga_articol()'
	ENDIF
	goObjA.gridart.Refresh()
	DOEVENTS FORCE

	*----- sincronizeaza() -----
	LOCAL llEroareSyncA
	llEroareSyncA = .F.
	TRY
		goObjA.sincronizeaza()
	CATCH TO loExcSyncA
		llEroareSyncA = .T.
		DO R7Log WITH 'EROARE la sincronizeaza() (A) ' + TRANSFORM(loExcSyncA.ErrorNo) + ' [' + loExcSyncA.Message + ;
			'] in ' + loExcSyncA.Procedure + ':' + TRANSFORM(loExcSyncA.LineNo) + ' (' + loExcSyncA.LineContents + ')'
	ENDTRY
	DOEVENTS FORCE
	goObjA.grid1.Refresh()
	DOEVENTS FORCE
	IF !llEroareSyncA
		DO R7Log WITH 'PASS A-sync: sincronizeaza() a rulat fara eroare'
	ELSE
		DO R7Log WITH 'FAIL A-sync: sincronizeaza() a aruncat eroare'
	ENDIF

	DO R7Log WITH 'A: dump introdc dupa sincronizeaza:'
	DO DumpIntrodc

	*----- VERIFICARI randul D (numai lei, explicatia, scd/scc, formula) -----
	DO VerificaRandD WITH goObjA, '603', '303', 'A'

	*----- VERIFICARE: nicio explicatie nu contine '(rot.)' -----
	DO VerificaFaraRotund WITH 'A'

	*----- VERIFICARE pozitie: pe rand T (DVI), sincronizeaza() pastreaza pozitia -----
	DO VerificaPozitieT WITH goObjA, 101, 'A'

	*----- VERIFICARE pozitie: pe randul D, sincronizeaza() ramane pe D -----
	DO VerificaPozitieD WITH goObjA, 'A'

	*----- VERIFICARE guard Valid (Grid1.cSuma.Text1): Value == nsumavechi -> fara efect -----
	DO VerificaGuardValid WITH goObjA, 'A'

	DO HarnessStep WITH 1, 'A: dupa verificari (rand D, pozitie, guard); introdc=' + TRANSFORM(RECCOUNT_ACTIVE('introdc')) + ' randuri'

	goObjA.Hide()
	goObjA.Release()
	DOEVENTS FORCE

	*===================================================================================
	*==================== SCENARIUL B: doar imobilizari (212) -> scd '6588' ==========
	*===================================================================================
	DO R7Log WITH '========== SCENARIUL B: FACTURA 100 + DVI 101, UNIC articol 212 =========='
	IF USED('introdc')
		USE IN ('introdc')
	ENDIF
	DO CreeazaIntrodc WITH 'introdc'
	IF USED('rul_temp')
		USE IN ('rul_temp')
	ENDIF
	DO CreeazaRulTemp
	INSERT INTO rul_temp (denumire, codmat, cant, pret, pret_lei, cont, cota_tva) ;
		VALUES ('PLACEHOLDER', 'PH', 1, 1, 1, '371', 21)

	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
	PUBLIC goObjB
	goObjB = CREATEOBJECT('IMPORT_nota', .F.)
	IF VARTYPE(goObjB) <> 'O'
		DO R7Log WITH 'FAIL: instantiere import_nota (Scenariul B)'
		DO HarnessDone WITH 'done-error'
		QUIT
	ENDIF
	goObjB.lDialogAratat = .T.
	goObjB.oact = poAct
	goObjB.WindowType = 0
	goObjB.Visible = .T.
	goObjB.Show()
	goObjB.WindowState = 2
	DOEVENTS FORCE

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

	*----- DOC 1: FACTURA 100, RAJA, DVI valuta (EUR curs 5.23) -----
	goDlg = CREATEOBJECT('import_adauga_factura', goObjB)
	goDlg.cFelDoc = 'Factura'
	goDlg.nIdFdoc = 1
	goDlg.nNract = 100
	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 R7Log WITH 'B-DOC1: valideaza = ' + TRANSFORM(goDlg.valideaza())
	DO ConstruiesteToDlg
	DO R7Log WITH 'B-DOC1: do_adauga_factura = ' + TRANSFORM(goObjB.do_adauga_factura(goT))
	goDlg.Hide()
	DOEVENTS FORCE

	DO R7Log WITH 'B: dump introdc dupa documentul 1:'
	DO DumpIntrodc

	DO HarnessStep WITH 2, 'B: dupa FACTURA 100 + DVI 101, introdc=' + TRANSFORM(RECCOUNT_ACTIVE('introdc')) + ' randuri'

	*----- Adaugare articol UNIC (BULDOEXCAVATOR cont 212) prin fluxul REAL -----
	gcMockArtCodmat = 'ART-BULD-212'
	TRY
		goObjB.do_adauga_articol()
	CATCH TO loExcAddB
		DO R7Log WITH 'EROARE do_adauga_articol (B) ' + TRANSFORM(loExcAddB.ErrorNo) + ' [' + loExcAddB.Message + ']'
	ENDTRY
	DOEVENTS FORCE
	SELECT rul_temp
	LOCATE FOR ALLTRIM(codmat) == 'ART-BULD-212'
	IF FOUND()
		REPLACE cant WITH 1, pret_val WITH 5000, pretd WITH 5000, pret WITH ROUND(5000*5.23,4), pret_lei WITH ROUND(5000*5.23,4)
		DO R7Log WITH 'B: BULDOEXCAVATOR (212) adaugat prin do_adauga_articol REAL, cant/pret completate'
	ELSE
		DO R7Log WITH 'FAIL B: BULDOEXCAVATOR nu a fost adaugat de do_adauga_articol()'
	ENDIF
	goObjB.gridart.Refresh()
	DOEVENTS FORCE

	LOCAL llEroareSyncB
	llEroareSyncB = .F.
	TRY
		goObjB.sincronizeaza()
	CATCH TO loExcSyncB
		llEroareSyncB = .T.
		DO R7Log WITH 'EROARE la sincronizeaza() (B) ' + TRANSFORM(loExcSyncB.ErrorNo) + ' [' + loExcSyncB.Message + ']'
	ENDTRY
	DOEVENTS FORCE
	goObjB.grid1.Refresh()
	DOEVENTS FORCE
	IF !llEroareSyncB
		DO R7Log WITH 'PASS B-sync: sincronizeaza() a rulat fara eroare'
	ELSE
		DO R7Log WITH 'FAIL B-sync: sincronizeaza() a aruncat eroare'
	ENDIF

	DO R7Log WITH 'B: dump introdc dupa sincronizeaza:'
	DO DumpIntrodc

	*----- VERIFICARI randul D (fara clasa 3 -> 6588, doar lei) -----
	DO VerificaRandD WITH goObjB, '6588', '212', 'B'
	DO VerificaFaraRotund WITH 'B'

	DO HarnessStep WITH 3, 'B: final, introdc=' + TRANSFORM(RECCOUNT_ACTIVE('introdc')) + ' randuri, eroare_sync=' + TRANSFORM(llEroareSyncB)
	DO HarnessDone WITH 'done'

CATCH TO loExc
	DO R7Log 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 ConstruiesteToDlg
	*-- toDlg construit INLINE in programul PRINCIPAL (vezi docs/testare-ui-vfp.md capcana l).
	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 (vezi test_adauga_repere_212.prg / ointroduceri.vc2:11030).
	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 VerificaRandD
	*-- randul D (runda7): doar lei (suma_val=0, in_valuta=0, participa_valuta=.F., nume_val='',
	*-- id_valuta=0, curs=0, ndif_val formular=0), explicatia=='DIFERENTA', scd/scc asteptate,
	*-- suma == nbaza_lei - Sum(Round(pret*cant,gnPc)) din rul_temp (formula recalc_diferente).
	LPARAMETERS toObj, tcScdAsteptat, tcSccAsteptat, tcLabel
	LOCAL lnSel, lcMsg, llD, lnSumaArticole, lnSumaAsteptata, llOkCampuriLei
	lnSel = SELECT()

	SELECT SUM(ROUND(pret*cant,gnPc)) AS s FROM rul_temp WHERE !DELETED() INTO CURSOR crsSumaArtR7 NOFILTER
	lnSumaArticole = NVL(crsSumaArtR7.s, 0)
	USE IN crsSumaArtR7
	lnSumaAsteptata = ROUND(toObj.nbaza_lei - lnSumaArticole, gnPc)

	SELECT introdc
	LOCATE FOR tip_rand == 'D'
	llD = FOUND()
	IF llD
		llOkCampuriLei = (suma_val = 0) AND (in_valuta = 0) AND (!participa_valuta) AND ;
			EMPTY(ALLTRIM(NVL(nume_val,''))) AND (id_valuta = 0) AND (curs = 0) AND ;
			ALLTRIM(explicatia) == 'DIFERENTA' AND (toObj.ndif_val = 0) AND ;
			ALLTRIM(scd) == tcScdAsteptat AND ALLTRIM(scc) == tcSccAsteptat AND ;
			ABS(suma - lnSumaAsteptata) < 0.01
		IF llOkCampuriLei
			lcMsg = 'PASS ' + tcLabel + '-randD: explicatia=DIFERENTA suma=' + TRANSFORM(suma) + ;
				' (asteptat ' + TRANSFORM(lnSumaAsteptata) + ') scd=' + ALLTRIM(scd) + ' scc=' + ALLTRIM(scc) + ;
				' suma_val=0 in_valuta=0 participa_valuta=.F. nume_val=[] id_valuta=0 curs=0 ndif_val=0 - TOATE OK'
		ELSE
			lcMsg = 'FAIL ' + tcLabel + '-randD: suma=' + TRANSFORM(suma) + '(astept ' + TRANSFORM(lnSumaAsteptata) + ') ' + ;
				'scd=[' + ALLTRIM(scd) + '](astept [' + tcScdAsteptat + ']) scc=[' + ALLTRIM(scc) + '](astept [' + tcSccAsteptat + ']) ' + ;
				'explicatia=[' + ALLTRIM(explicatia) + '] suma_val=' + TRANSFORM(suma_val) + ' in_valuta=' + TRANSFORM(in_valuta) + ;
				' participa_valuta=' + TRANSFORM(participa_valuta) + ' nume_val=[' + ALLTRIM(NVL(nume_val,'')) + '] id_valuta=' + TRANSFORM(id_valuta) + ;
				' curs=' + TRANSFORM(curs) + ' ndif_val(formular)=' + TRANSFORM(toObj.ndif_val)
		ENDIF
	ELSE
		lcMsg = 'FAIL ' + tcLabel + '-randD: nu exista rand tip_rand=D in introdc dupa sincronizeaza() (diferenta asteptata=' + TRANSFORM(lnSumaAsteptata) + ')'
	ENDIF
	DO R7Log WITH lcMsg
	SELECT (lnSel)
ENDPROC

PROCEDURE VerificaFaraRotund
	LPARAMETERS tcLabel
	LOCAL lnSel, lcMsg, lnGasite
	lnSel = SELECT()
	SELECT introdc
	lnGasite = 0
	SCAN FOR '(rot.)' $ NVL(explicatia,'')
		lnGasite = lnGasite + 1
	ENDSCAN
	IF lnGasite = 0
		lcMsg = 'PASS ' + tcLabel + '-fara_rotund: nicio explicatie din introdc nu contine "(rot.)"'
	ELSE
		lcMsg = 'FAIL ' + tcLabel + '-fara_rotund: ' + TRANSFORM(lnGasite) + ' randuri cu "(rot.)" in explicatia (asteptat 0)'
	ENDIF
	DO R7Log WITH lcMsg
	SELECT (lnSel)
ENDPROC

PROCEDURE VerificaPozitieT
	*-- pozitioneaza pe randul T al doc-ului vamal (nract=tnNractVama), apeleaza sincronizeaza(),
	*-- verifica ca ramane pe ACELASI rand (doc_key+tip_rand+scd identice) - D-C1.
	LPARAMETERS toObj, tnNractVama, tcLabel
	LOCAL lnSel, lcMsg, lcDocKeyDinainte, lcScdDinainte, llGasitInainte, llEroare
	lnSel = SELECT()
	SELECT introdc
	LOCATE FOR nract = tnNractVama AND tip_rand == 'T'
	llGasitInainte = FOUND()
	IF !llGasitInainte
		DO R7Log WITH 'FAIL ' + tcLabel + '-pozitieT: nu am gasit randul T pentru nract=' + TRANSFORM(tnNractVama) + ' (setup)'
		SELECT (lnSel)
		RETURN
	ENDIF
	lcDocKeyDinainte = doc_key
	lcScdDinainte = scd

	llEroare = .F.
	TRY
		toObj.sincronizeaza()
	CATCH TO loExcPozT
		llEroare = .T.
		DO R7Log WITH 'EROARE la sincronizeaza() in VerificaPozitieT ' + TRANSFORM(loExcPozT.ErrorNo) + ' [' + loExcPozT.Message + ']'
	ENDTRY
	DOEVENTS FORCE

	SELECT introdc
	IF !llEroare AND doc_key == lcDocKeyDinainte AND tip_rand == 'T' AND scd == lcScdDinainte
		lcMsg = 'PASS ' + tcLabel + '-pozitieT: dupa sincronizeaza(), recordul curent a ramas pe randul T (nract=' + TRANSFORM(tnNractVama) + ', scd=' + ALLTRIM(scd) + ')'
	ELSE
		lcMsg = 'FAIL ' + tcLabel + '-pozitieT: dupa sincronizeaza(), tip_rand=[' + tip_rand + '] doc_key=[' + ALLTRIM(doc_key) + '] scd=[' + ALLTRIM(scd) + ;
			'] (astept tip_rand=T, doc_key=[' + ALLTRIM(lcDocKeyDinainte) + '], scd=[' + ALLTRIM(lcScdDinainte) + '])'
	ENDIF
	DO R7Log WITH lcMsg
	SELECT (lnSel)
ENDPROC

PROCEDURE VerificaPozitieD
	*-- pozitioneaza pe randul D, apeleaza sincronizeaza(), verifica ca ramane pe tip_rand='D' (D-C1).
	LPARAMETERS toObj, tcLabel
	LOCAL lnSel, lcMsg, llGasitInainte, llEroare
	lnSel = SELECT()
	SELECT introdc
	LOCATE FOR tip_rand == 'D'
	llGasitInainte = FOUND()
	IF !llGasitInainte
		DO R7Log WITH 'FAIL ' + tcLabel + '-pozitieD: nu exista rand D (setup)'
		SELECT (lnSel)
		RETURN
	ENDIF

	llEroare = .F.
	TRY
		toObj.sincronizeaza()
	CATCH TO loExcPozD
		llEroare = .T.
		DO R7Log WITH 'EROARE la sincronizeaza() in VerificaPozitieD ' + TRANSFORM(loExcPozD.ErrorNo) + ' [' + loExcPozD.Message + ']'
	ENDTRY
	DOEVENTS FORCE

	SELECT introdc
	IF !llEroare AND tip_rand == 'D'
		lcMsg = 'PASS ' + tcLabel + '-pozitieD: dupa sincronizeaza(), recordul curent a ramas pe randul D'
	ELSE
		lcMsg = 'FAIL ' + tcLabel + '-pozitieD: dupa sincronizeaza(), tip_rand=[' + tip_rand + '] (astept D)'
	ENDIF
	DO R7Log WITH lcMsg
	SELECT (lnSel)
ENDPROC

PROCEDURE VerificaGuardValid
	*-- guard "doar la modificare" (runda7, dec.4): setez Thisform.nsumavechi = suma curenta
	*-- (simuleaza GotFocus), apoi apelez direct Valid-ul lui Grid1.cSuma.Text1 cu aceeasi valoare -
	*-- Valid trebuie sa iasa imediat (fara Replace mod_manual, fara armare lSyncPending/tmrSync).
	LPARAMETERS toObj, tcLabel
	LOCAL lnSel, lcMsg, lnSumaCrt, llModManualInainte, llSyncPendingInainte, llApelDirectOk, llEroareApel
	lnSel = SELECT()
	SELECT introdc
	LOCATE FOR tip_rand == 'B'
	IF !FOUND()
		DO R7Log WITH 'INFO ' + tcLabel + '-guardValid: nu exista rand B pentru test (sarit)'
		SELECT (lnSel)
		RETURN
	ENDIF
	lnSumaCrt = suma
	llModManualInainte = (mod_manual = 1)

	toObj.nsumavechi = lnSumaCrt
	toObj.lSyncPending = .F.
	llSyncPendingInainte = toObj.lSyncPending

	llApelDirectOk = .F.
	llEroareApel = .F.
	TRY
		IF PEMSTATUS(toObj.Grid1.cSuma.Text1, 'Valid', 5)
			toObj.Grid1.cSuma.Text1.Value = lnSumaCrt
			toObj.Grid1.cSuma.Text1.Valid()
			llApelDirectOk = .T.
		ENDIF
	CATCH TO loExcGuard
		llEroareApel = .T.
		DO R7Log WITH 'INFO ' + tcLabel + '-guardValid: apel direct Grid1.cSuma.Text1.Valid() a esuat (' + ;
			TRANSFORM(loExcGuard.ErrorNo) + ' ' + loExcGuard.Message + ') - test indirect mai jos'
	ENDTRY

	SELECT introdc
	LOCATE FOR tip_rand == 'B'
	IF llApelDirectOk AND !llEroareApel
		IF (mod_manual = 1) == llModManualInainte AND toObj.lSyncPending == llSyncPendingInainte
			lcMsg = 'PASS ' + tcLabel + '-guardValid: Value==nsumavechi -> Valid a iesit fara efect (mod_manual neschimbat, lSyncPending=' + TRANSFORM(toObj.lSyncPending) + ')'
		ELSE
			lcMsg = 'FAIL ' + tcLabel + '-guardValid: Valid a avut efect desi Value==nsumavechi (mod_manual dupa=' + TRANSFORM(mod_manual) + ' lSyncPending dupa=' + TRANSFORM(toObj.lSyncPending) + ')'
		ENDIF
	ELSE
		*-- fallback indirect: dupa sincronizarea completa deja facuta, lSyncPending trebuie sa fie
		*-- .F. in stare de repaus; setam nsumavechi=suma curenta si verificam ca nu s-a schimbat nimic.
		IF toObj.lSyncPending == .F.
			lcMsg = 'PASS ' + tcLabel + '-guardValid (indirect): apel direct pe Grid1.cSuma.Text1.Valid() nedisponibil in headless - lSyncPending ramane .F. in repaus (guard documentat in cod, vezi diff_runda7)'
		ELSE
			lcMsg = 'FAIL ' + tcLabel + '-guardValid (indirect): lSyncPending=' + TRANSFORM(toObj.lSyncPending) + ' (astept .F. in repaus)'
		ENDIF
	ENDIF
	DO R7Log WITH lcMsg
	SELECT (lnSel)
ENDPROC

PROCEDURE DumpIntrodc
	LOCAL lnSel
	lnSel = SELECT()
	SELECT introdc
	SCAN
		DO R7Log WITH '  recno=' + TRANSFORM(RECNO()) + ' nract=' + TRANSFORM(nract) + ' tip_rand=' + tip_rand + ;
			' scd=' + ALLTRIM(scd) + ' scc=' + ALLTRIM(scc) + ' suma=' + TRANSFORM(suma) + ' suma_val=' + TRANSFORM(suma_val) + ;
			' explicatia=[' + ALLTRIM(NVL(explicatia,'')) + '] partc=[' + ALLTRIM(NVL(partc,'')) + '] 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 R7Err
	LPARAMETERS tnErr, tcMsg, tcProg, tnLine
	DO R7Log WITH 'ON ERROR ' + TRANSFORM(tnErr) + ' [' + tcProg + ':' + TRANSFORM(tnLine) + '] ' + tcMsg
ENDPROC

PROCEDURE R7Log
	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
