* test_e2e_dvi_ron_discount.prg
* Runda30 (F1+F2) + Runda32 (model B/G/T, un singur rand G): test e2e pe SCENARIUL EXACT cerut
* de Marius - factura de import in valuta (EUR), TVA DVI platit in RON (valuta proprie DVI,
* diferita de a facturii), discount financiar (doar baza, fara bifa), articole adaugate, apoi
* finalizare. Flux REAL: dialogul `import_adauga_factura` (nu insert direct in cursoare) +
* `do_adauga_articol()` real + `sincronizeaza()` real.
*
* IMPORTANT: toDlg (contractul pentru do_adauga_factura) se construieste INLINE, in programul
* PRINCIPAL, NU prin apelul `goDlg.construieste_todlg()` - capcana documentata deja in antetul
* `mock_caut_valuta.prg` ("CREATEOBJECT/ADDPROPERTY nu merg corect apelate dintr-o procedura in
* acest runtime"): confirmat prin diagnostic (28.07.2026) ca aceasta metoda arunca eroare 11
* ("argument invalid") pe PRIMUL Addproperty, universal, pe orice instanta (inclusiv virgina),
* dar EXACT ACELASI cod, apelat din programul principal cu goDlg.* in loc de This.*, functioneaza
* corect. NU incerca sa "repari" apeland metoda direct - vezi handoff_dvi_discount.md pentru
* dovezile complete (izolare fata de tip de date, mediu, mostenire de clasa, lungime de linie).
*
* Assert-uri rand cu rand pe `introdc` (sursa de adevar inainte de scrierea finala):
*   - randul B (baza factura): scd=371, suma=5000.00 (1000 EUR x curs 5), suma_val=1000.00,
*     in_valuta=1, id_valuta=978 (EUR), partener facturii;
*   - randul T-DVI (rand_dvi=1): scd=4426/scc=401, suma=840.00 (baza NETA lei x 21% =
*     (5000-1000)*21%, discountul scade baza DVI-ului), suma_val=0, in_valuta=0, id_valuta=0/
*     curs=0/nume_val='' (normalizare RON->fara valuta pe randul scris, desi pe dialog RON are
*     id real 1 - vezi conventia din handoff), participa_valuta=.F., partenerul vamal (DIRECTIA
*     VAMALA), mod_manual=1 (valoarea NETA difera de auto-calculul brut baza*cota=1050.00 facut
*     de do_adauga_factura la creare, deci randul e protejat de do_executa - vezi Runda32);
*   - randul G (discount, un singur rand, model B/G/T): scd = scc-ul randului B (analitic
*     mostenit), scc=767, suma=+1000.00, suma_val=+200.00 (POZITIV), id_partd = partenerul
*     facturii (de pe creditul B), participa_valuta=.F., cu_tva=0, ptva=0;
*   - pretul articolului (rul_temp) neafectat de discount: pret_lei=4000.00 (800 EUR x 5);
*   - randul D (diferenta), daca apare, e informativ (best-effort - nu il forteaza scenariul);
*   - totalurile din subsol (D4): txtftvalei/txtftvaval raman pe baza integrala (5000.00/
*     1000.00); Text2/Text3 (cu TVA) scad discountul (4840.00 = 5000+840-1000, respectiv
*     800.00 = 1000+0-200) - verificate imediat dupa Termin, inainte de a adauga articole
*     (documentul nu e inca spart pe randuri S, B ramane intreg pentru un calcul curat).
*
* Acoperea si cerinta FINALA (Runda32): factura de import in valuta + discount + TVA pe DVI,
* cu assert-uri pe cele trei randuri (B/G/T) si pe totalurile din subsolul notei.
*
* PASUL FINAL "Terminat" (scrierea in `actactan` prin `import_nota.inainte_de_do_termin()`)
* SE RULEAZA (nu mai e sarit). Acel cod deschide `Do Form verificare` (formular MODAL real,
* `COMUN\ferestre\verificare.scx`, WindowType=1) - fara mock ar ramane blocat la nesfarsit.
* Testul foloseste un STUB `verificare.scx` dedicat, in `stub_verificare\` (langa acest test,
* NU peste formularul real) - form gol, `WindowType=0`, `Init` seteaza `gnButon=1` si
* `Return .F.` (impiedica instantierea => `Do Form` revine imediat, fara afisare). Stub-ul
* castiga rezolutia `Do Form` pentru ca `stub_verificare` e primul folder din `SET PATH`
* (inaintea lui `COMUN\FERESTRE`, unde e formularul real) - confirmat empiric: `SET PATH`
* rezolva pe ORDINEA din lista, primul folder cu fisierul cerut castiga.
* Assert-uri suplimentare rand cu rand pe `actactan` (structura reala, fara `tip_rand`/
* `rand_dvi` - randurile se identifica dupa scd/scc/semnul sumei): B (scd=371), T-DVI
* (scd=4426, suma POZITIVA), G (scc=767, un singur rand) + niciun rand fals de finalizare NIR.
*
* Rulare:
*   powershell -ExecutionPolicy Bypass -File test_e2e_dvi_ron_discount.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_e2e_dvi_ron_discount_log.txt"
gcSyncDir = "D:\ROA\ROAGEST\COMUN\utile\Teste\achizitie_import\uisync_e2e_dvi_ron_discount\"
STRTOFILE("START " + TTOC(DATETIME()) + CHR(13)+CHR(10), gcUILog)

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

TRY
	LOCAL gcAppPath, lcPath
	gcAppPath = "D:\ROA\ROAGEST\"
	SET DEFAULT TO (gcAppPath)

	lcPath = gcAppPath + 'COMUN\Utile\Teste\achizitie_import\stub_verificare;' + ;
		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 EeLog 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 EeLog WITH 'SET CLASSLIB OK'

	*----- PROCEDURI (mock-uri 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\achizitie_import\mock_caut_valuta.prg" ADDITIVE
	SET PROCEDURE TO "D:\ROA\ROAGEST\COMUN\utile\Teste\mock_cauta_nom_articole.prg" ADDITIVE
	SET PROCEDURE TO "D:\ROA\ROAGEST\COMUN\utile\Teste\achizitie_import\mock_oscrie_in_fisiere.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 EeLog 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 gnMockRaspuns, gcMockUltimMesaj, gnMockUltimTip, gcMockArtCodmat
	gnMockRaspuns = 6
	gcMockUltimMesaj = ''
	gnMockUltimTip = 0
	PUBLIC gnButon
	gnButon = 1
	gcMockArtCodmat = ''

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

	*----- poAct: antetul notei (factura import EUR, curs 5) -----
	PUBLIC poAct
	poAct = CREATEOBJECT('Custom')
	poAct.AddProperty('nume_val', 'EUR')
	poAct.AddProperty('curs', 5)
	poAct.AddProperty('proc_tva', 1.21)
	poAct.AddProperty('nnir', 0)
	poAct.AddProperty('id_valuta', 978)
	poAct.AddProperty('id_fdoc', 1)
	poAct.AddProperty('fdoc', 'Factura')
	poAct.AddProperty('id_partc', 601)
	poAct.AddProperty('partc', 'FURNIZOR EXTERN GMBH')
	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% (achizitii interne + import) -----
	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 ('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)

	*-- index ord_doc INAINTE de CREATEOBJECT (capcana p, docs/testare-ui-vfp.md)
	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

	*-- import_nota.inainte_de_do_termin() citeste variabila BARA tlIntern (linia
	*-- "Iif(tlIntern, 0, 100)"), nu This.lIntern - se bazeaza pe mostenirea PRIVATE de-a
	*-- lungul stivei de apel de la achizitie_import(tnIdSet, tlIntern), procedura reala care
	*-- ar instantia formularul (Show() modal, deci tlIntern ramane "vizibil" din metodele
	*-- formularului). Testul ocoleste achizitie_import (CREATEOBJECT direct, ca toate
	*-- celelalte teste din suita), deci tlIntern trebuie declarata explicit aici, cu ACEEASI
	*-- valoare data la CREATEOBJECT (.F. = mod import) - nu e defect de cod, e o conventie de
	*-- scop de variabila care presupune fluxul real prin achizitie_import.
	PRIVATE tlIntern
	tlIntern = .F.

	*-- alt global de mediu real (roagest.prg la pornire) folosit de clase pentru export
	*-- fisiere temporare (XML/PDF/index) - nedeclarat pana acum pentru ca pasul Terminat
	*-- nu fusese exercitat headless inainte de stub-ul verificare.scx
	PUBLIC gcTempPath
	gcTempPath = ADDBS(SYS(2023))

	*-- gnHandle: handle SQLCONNECT real (SQLSetprop/SQLExec native) folosit de
	*-- oscrie_in_fisiere - -1 e conventia din dbaccesscontroller.prg pt. "fara conexiune";
	*-- fara o conexiune Oracle reala, scrierea propriu-zisa in ACT nu poate fi validata aici
	PUBLIC gnHandle
	gnHandle = -1

	*-- gnTipGest: citit bare la Do listare_nir With poAct.nnir, gnTipGest In oproceduri_listari,
	*-- dupa oscrie_in_fisiere() cu succes - 0 = gestiune normala (nu declanseaza ramurile
	*-- speciale gnTipGest=6/7 vazute in cod pentru marfa la pret de vanzare)
	PUBLIC gnTipGest
	gnTipGest = 0

	*-- gcCondSucursala: fragment WHERE folosit la rapoarte multi-sucursala (listare_nir) -
	*-- gol = fara filtrare (o singura sucursala, ca in test_init_env.prg)
	PUBLIC gcCondSucursala
	gcCondSucursala = ''

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

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

	PRIVATE pnAsserts, pnPass
	STORE 0 TO pnAsserts, pnPass

	DO HarnessStep WITH 0, 'nota goala afisata, mod import (.F.)'

	*========================= DIALOG: factura EUR + TVA DVI in RON + discount financiar =========================
	PUBLIC goDlg
	goDlg = CREATEOBJECT('import_adauga_factura', goObj)
	goDlg.cFelDoc = 'Factura'
	goDlg.nIdFdoc = 1
	goDlg.nNract = 8001
	goDlg.dDataAct = DATE()
	goDlg.nIdPartener = 601
	goDlg.cPartener = 'FURNIZOR EXTERN GMBH'
	goDlg.cExplicatia = 'Marfa import cu DVI in RON si discount'
	goDlg.nSuma = 1000
	goDlg.nSumaLei = 0
	goDlg.nCurs = 5
	goDlg.nIdValuta = 978
	goDlg.cValuta = 'EUR'
	goDlg.chkInValutaCont.Value = 1
	goDlg.chkParticipaValuta.Value = 1
	goDlg.nIdExplicatieTva = 220
	goDlg.cExplicatieTva = 'ACH. IMP. 21%'
	goDlg.nProcentTva = 21

	*-- DVI: identitate (document vamal, partener vamal)
	goDlg.cSerieDvi = ''
	goDlg.nNractDvi = 9001
	goDlg.dDviData = DATE()
	goDlg.nIdFdocDVI = 2
	goDlg.cFelDocDvi = 'DVI'
	goDlg.nDviIdPartener = 900
	goDlg.cDviPartener = 'DIRECTIA VAMALA'

	*-- comuta pe mod TVA DVI (radio "TVA in vama") - flux real, InteractiveChange
	goDlg.optTipTva.Value = 2
	goDlg.optTipTva.InteractiveChange()

	*-- alegere RON pe blocul DVI, prin picker-ul REAL (mock_caut_valuta, coada FIFO cu 1 pick)
	PUBLIC goMockValuta, goMockValutaCoada
	goMockValuta = CREATEOBJECT('Custom')
	goMockValuta.AddProperty('id_valuta', 1)
	goMockValuta.AddProperty('nume_val', 'RON')
	goMockValutaCoada = CREATEOBJECT('Collection')
	LOCAL loValRon
	loValRon = CREATEOBJECT('Custom')
	loValRon.AddProperty('id_valuta', 1)
	loValRon.AddProperty('nume_val', 'RON')
	goMockValutaCoada.Add(loValRon)
	goDlg.cmdDviValuta.Click()
	=AssertStr('1-DVI valuta aleasa RON', ALLTRIM(goDlg.cDviValuta), 'RON')
	=Assert3('2-DVI curs fixat la 1 (RON)', goDlg.nDviCurs, 1)
	=Assert3('3-DVI TVA lei auto = baza_lei*21% = 1050.00', goDlg.nDviTvaLei, 1050.00)

	*-- discount financiar (Runda32: doar baza, fara bifa) - Valid() reface imediat TVA DVI pe
	*-- baza NETA (suma-discount), fara auto-calcul separat de "TVA discount"
	goDlg.txtDiscBaza.Value = 200
	goDlg.txtDiscBaza.Valid()
	=Assert3('4-dupa discount: DVI TVA lei pe baza NETA = (5000-1000)*21% = 840.00', goDlg.nDviTvaLei, 840.00)

	goDlg.WindowType = 0
	goDlg.Visible = .T.
	goDlg.Show()
	DOEVENTS FORCE
	DO HarnessStep WITH 1, 'dialog completat: factura EUR 1000, DVI TVA RON 840.00 (baza neta), discount baza 200'

	*-- valideaza() REAL de pe dialog (buton Termin apeleaza mereu asta primul)
	LOCAL llOkValid
	llOkValid = goDlg.valideaza()
	=Assert3('6a-dialog valideaza() reuseste', IIF(llOkValid,1,0), 1)

	*-- toDlg construit INLINE in programul PRINCIPAL, NU prin goDlg.construieste_todlg() -
	*-- capcana l (vezi antetul mock_caut_valuta.prg): CREATEOBJECT/ADDPROPERTY nu merg corect
	*-- apelate dintr-o PROCEDURA/METODA in acest runtime headless (confirmat: crapa universal,
	*-- inclusiv pe o instanta virgina, cu eroarea 11 pe primul Addproperty din construieste_todlg;
	*-- acelasi cod, apelat din programul principal cu goDlg.* in loc de This.*, functioneaza OK).
	*-- Lista de campuri COPIATA din construieste_todlg (ointroduceri.vc2 ~6180) ca sa ramana
	*-- fidela contractului - vezi si celelalte teste motor (test_dvi_valuta_ron.prg etc.), care
	*-- folosesc acelasi tipar.
	PUBLIC goT
	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)
	IF goDlg.optTipTva.Value = 2
		=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)
		*-- dvi_in_valuta: LOGIC (nu numeric), derivat dupa NUME - fidel cu construieste_todlg
		=ADDPROPERTY(goT,'dvi_in_valuta',!(EMPTY(goDlg.cDviValuta) OR UPPER(ALLTRIM(goDlg.cDviValuta))=='RON'))
		=ADDPROPERTY(goT,'dvi_id_valuta',goDlg.nDviIdValuta)
		=ADDPROPERTY(goT,'dvi_curs',goDlg.nDviCurs)
		=ADDPROPERTY(goT,'dvi_nume_val',ALLTRIM(NVL(goDlg.cDviValuta,'')))
		*-- dvi_valuta_proprie: regula pe valuta EFECTIVA (fix task #9) - daca ambele parti sunt
		*-- efectiv "fara valuta" (gol sau RON), rezultat 0; altfel compara id/curs ca inainte
		=ADDPROPERTY(goT,'dvi_valuta_proprie',IIF(!(EMPTY(goDlg.cDviValuta) OR UPPER(ALLTRIM(goDlg.cDviValuta))=='RON') OR !(EMPTY(goDlg.cValuta) OR UPPER(ALLTRIM(goDlg.cValuta))=='RON'),IIF(goDlg.nDviIdValuta<>goDlg.nIdValuta OR goDlg.nDviCurs<>goDlg.nCurs,1,0),0))
	ENDIF
	=ADDPROPERTY(goT,'disc_baza_lei',IIF(goDlg.chkInValutaCont.Value=1 AND goDlg.nCurs<>0,ROUND(goDlg.nDiscBaza*goDlg.nCurs,gnPC),goDlg.nDiscBaza))
	=ADDPROPERTY(goT,'disc_baza_val',IIF(goDlg.chkInValutaCont.Value=1 AND goDlg.nCurs<>0,goDlg.nDiscBaza,0))

	*-- "Termin" REAL: oParinte.do_adauga_factura() cu toDlg-ul construit mai sus
	LOCAL llOkAdauga
	llOkAdauga = goObj.do_adauga_factura(goT)
	=Assert3('6-do_adauga_factura(goT) reuseste (Termin)', IIF(llOkAdauga,1,0), 1)
	goDlg.Hide()
	DOEVENTS FORCE
	DO HarnessStep WITH 2, 'dupa Termin pe dialog: introdc=' + TRANSFORM(RECCOUNT_ACTIVE('introdc')) + ' randuri'

	*========================= ASSERT-URI RAND CU RAND PE introdc =========================
	LOCAL lcSccB
	SELECT introdc
	LOCATE FOR nract = 8001 AND tip_rand == 'B'
	=Assert3('7-randul B (baza factura) gasit', IIF(FOUND(),1,0), 1)
	IF FOUND()
		lcSccB = ALLTRIM(NVL(scc,''))
		=AssertStr('8-B.scd=371', ALLTRIM(scd), '371')
		=Assert3('9-B.suma=5000.00 (1000 EUR x curs 5)', suma, 5000.00)
		=Assert3('10-B.suma_val=1000.00', suma_val, 1000.00)
		=Assert3('11-B.in_valuta=1', NVL(in_valuta,0), 1)
		=Assert3('12-B.id_valuta=978 (EUR)', NVL(id_valuta,0), 978)
		=AssertStr('13-B.nume_val=EUR', ALLTRIM(NVL(nume_val,'')), 'EUR')
		=Assert3('14-B.id_partc=601 (furnizorul facturii)', NVL(id_partc,0), 601)
		=AssertStr('15-B.partc=FURNIZOR EXTERN GMBH', ALLTRIM(NVL(partc,'')), 'FURNIZOR EXTERN GMBH')
	ELSE
		pnAsserts = pnAsserts + 8
		DO EeLog WITH '  FAIL 8-15: randul B negasit'
	ENDIF

	SELECT introdc
	LOCATE FOR Nvl(rand_dvi,0) = 1
	=Assert3('16-randul T-DVI (rand_dvi=1) gasit', IIF(FOUND(),1,0), 1)
	IF FOUND()
		=AssertStr('17-T-DVI.scd=4426', ALLTRIM(scd), '4426')
		=AssertStr('18-T-DVI.scc=401', ALLTRIM(scc), '401')
		=Assert3('19-T-DVI.suma=840.00 (baza NETA lei x 21%, discount scazut din baza DVI)', suma, 840.00)
		=Assert3('20-T-DVI.suma_val=0 (RON)', NVL(suma_val,0), 0)
		=Assert3('21-T-DVI.in_valuta=0', NVL(in_valuta,0), 0)
		=Assert3('22-T-DVI.id_valuta=0 (normalizare fara-valuta pe randul scris)', NVL(id_valuta,0), 0)
		=Assert3('23-T-DVI.curs=0', NVL(curs,0), 0)
		=AssertStr('24-T-DVI.nume_val="" ', ALLTRIM(NVL(nume_val,'?')), '')
		=Assert3('25-T-DVI.participa_valuta=.F. (nu intra in footer valuta)', IIF(participa_valuta,1,0), 0)
		=Assert3('26-T-DVI.valuta_proprie=1 (RON <> EUR factura)', NVL(valuta_proprie,0), 1)
		=Assert3('27-T-DVI.id_partc=900 (Directia Vamala)', NVL(id_partc,0), 900)
		=AssertStr('28-T-DVI.partc=DIRECTIA VAMALA', ALLTRIM(NVL(partc,'')), 'DIRECTIA VAMALA')
		=Assert3('29-T-DVI.mod_manual=0 (TVA-ul tastat coincide cu auto-calculul pe baza neta 840.00)', NVL(mod_manual,0), 0)
	ELSE
		pnAsserts = pnAsserts + 12
		DO EeLog WITH '  FAIL 17-29: randul T-DVI negasit'
	ENDIF

	LOCAL lnCntGDoc1
	lnCntGDoc1 = 0
	SELECT introdc
	SCAN FOR nract = 8001 AND tip_rand == 'G'
		lnCntGDoc1 = lnCntGDoc1 + 1
	ENDSCAN
	=Assert3('30b-exact un singur rand G (model B/G/T, Runda32)', lnCntGDoc1, 1)

	SELECT introdc
	LOCATE FOR nract = 8001 AND tip_rand == 'G' AND ALLTRIM(NVL(scc,'')) == '767'
	=Assert3('30-randul G (discount, 401->767) gasit', IIF(FOUND(),1,0), 1)
	IF FOUND()
		IF !EMPTY(lcSccB)
			=AssertStr('31-G.scd = analitic mostenit de pe creditul B', ALLTRIM(scd), lcSccB)
		ENDIF
		=Assert3('32-G.suma=+1000.00 (baza discount in lei, POZITIV)', suma, 1000.00)
		=Assert3('33-G.suma_val=+200.00 (POZITIV)', suma_val, 200.00)
		=Assert3('34-G.id_partd=601 (furnizorul facturii, de pe creditul B)', NVL(id_partd,0), 601)
		=Assert3('35-G.participa_valuta=.F.', IIF(participa_valuta,1,0), 0)
		=Assert3('36-G.cu_tva=1 (mostenit din linia de baza, runda33)', NVL(cu_tva,0), 1)
		=Assert3('37-G.ptva=21 (aceeasi cota ca linia de baza, runda33)', NVL(ptva,0), 21)
	ELSE
		pnAsserts = pnAsserts + 6
		DO EeLog WITH '  FAIL 31-37: randul G negasit'
	ENDIF

	*========================= TOTALURI SUBSOL (Runda32: total cu TVA scade discountul, =========================
	*========================= total fara TVA ramane baza integrala - D4) - inainte de a adauga =========================
	*========================= articole (document inca nespart, B ramane intreg) =========================
	=Assert3('37b-subsol: txtftvalei (fara TVA) = baza integrala 5000.00', goObj.txtftvalei.Value, 5000.00)
	=Assert3('37c-subsol: Text2 (cu TVA) = baza+TVA-discount = 5000+840-1000 = 4840.00', goObj.Text2.Value, 4840.00)
	=Assert3('37d-subsol: txtftvaval (fara TVA, valuta) = baza integrala 1000.00', goObj.txtftvaval.Value, 1000.00)
	=Assert3('37e-subsol: Text3 (cu TVA, valuta) = baza+TVA-discount = 1000+0-200 = 800.00', goObj.Text3.Value, 800.00)

	*========================= ARTICOL prin do_adauga_articol() REAL =========================
	gcMockArtCodmat = 'ART-BULD-212'
	LOCAL llEroareArt
	llEroareArt = .F.
	TRY
		goObj.do_adauga_articol()
	CATCH TO loExcArt
		llEroareArt = .T.
		DO EeLog WITH 'EROARE do_adauga_articol ' + TRANSFORM(loExcArt.ErrorNo) + ' [' + loExcArt.Message + ']'
	ENDTRY
	DOEVENTS FORCE
	=Assert3('43-do_adauga_articol() fara eroare', IIF(llEroareArt,0,1), 1)
	SELECT rul_temp
	LOCATE FOR ALLTRIM(codmat) == 'ART-BULD-212'
	=Assert3('44-articolul BULDOEXCAVATOR adaugat in rul_temp', IIF(FOUND(),1,0), 1)
	IF FOUND()
		REPLACE cant WITH 1, pret_val WITH 800, pretd WITH 800, pret WITH ROUND(800*5,4), ;
			pret_lei WITH ROUND(800*5,4), cota_tva WITH 21
	ELSE
		pnAsserts = pnAsserts + 1
		DO EeLog WITH '  FAIL 44: articolul nu a fost adaugat'
	ENDIF
	goObj.gridart.Refresh()
	DOEVENTS FORCE
	DO HarnessStep WITH 3, 'articol adaugat (BULDOEXCAVATOR, 800 EUR)'

	*========================= sincronizeaza() REAL =========================
	LOCAL llEroareSync
	llEroareSync = .F.
	TRY
		goObj.sincronizeaza()
	CATCH TO loExcSync
		llEroareSync = .T.
		DO EeLog WITH 'EROARE sincronizeaza() ' + TRANSFORM(loExcSync.ErrorNo) + ' [' + loExcSync.Message + '] in ' + loExcSync.Procedure + ':' + TRANSFORM(loExcSync.LineNo)
	ENDTRY
	DOEVENTS FORCE
	=Assert3('45-sincronizeaza() fara eroare', IIF(llEroareSync,0,1), 1)

	*-- pretul articolului neafectat de discount (discount participa_valuta=.F., exclus din baze)
	SELECT rul_temp
	LOCATE FOR ALLTRIM(codmat) == 'ART-BULD-212'
	=Assert3('46-dupa sincronizeaza(): pret_lei articol neschimbat (4000.00)', IIF(FOUND(),pret_lei,-1), 4000.00)

	*-- randurile T-DVI si G supravietuiesc sincronizarii (nu doar la creare)
	SELECT introdc
	LOCATE FOR Nvl(rand_dvi,0) = 1
	=Assert3('47-dupa sincronizeaza(): T-DVI inca gasit', IIF(FOUND(),1,0), 1)
	IF FOUND()
		=Assert3('48-dupa sincronizeaza(): T-DVI.suma neschimbata (840.00, baza neta, protejata de mod_manual=1)', suma, 840.00)
	ELSE
		pnAsserts = pnAsserts + 1
		DO EeLog WITH '  FAIL 48: T-DVI a disparut dupa sincronizare'
	ENDIF
	SELECT introdc
	LOCATE FOR nract = 8001 AND tip_rand == 'G' AND ALLTRIM(NVL(scc,'')) == '767'
	=Assert3('49-dupa sincronizeaza(): G inca gasit', IIF(FOUND(),1,0), 1)
	IF FOUND()
		=Assert3('50-dupa sincronizeaza(): G.suma neschimbata (+1000.00)', suma, 1000.00)
	ELSE
		pnAsserts = pnAsserts + 1
		DO EeLog WITH '  FAIL 50: G a disparut dupa sincronizare'
	ENDIF

	*-- randul D (diferenta) - informativ, best-effort (nu e fortat de acest scenariu)
	SELECT introdc
	LOCATE FOR nract = 8001 AND tip_rand == 'D'
	IF FOUND()
		DO EeLog WITH 'INFO randul D (diferenta) exista: suma=' + TRANSFORM(suma) + ' - neafectat de discount (G exclus din bazele de calcul)'
	ELSE
		DO EeLog WITH 'INFO randul D (diferenta) nu apare in acest scenariu (numere curate, fara rotunjire reziduala) - nu e o cerinta a acestui test'
	ENDIF

	DO HarnessStep WITH 4, 'sincronizeaza() verificat - vezi log'

	*========================= Terminat -> scriere in actactan (stub verificare.scx, vezi handoff) =========================
	DO CreeazaActactan
	LOCAL llEroareTermin
	llEroareTermin = .F.
	TRY
		goObj.inainte_de_do_termin()
	CATCH TO loExcTermin
		llEroareTermin = .T.
		DO EeLog WITH 'EROARE inainte_de_do_termin() ' + TRANSFORM(loExcTermin.ErrorNo) + ' [' + loExcTermin.Message + '] in ' + loExcTermin.Procedure + ':' + TRANSFORM(loExcTermin.LineNo)
	ENDTRY
	=Assert3('51-inainte_de_do_termin() fara eroare (Terminat)', IIF(llEroareTermin,0,1), 1)

	*-- Randurile in actactan sunt scrise INAINTE de Do Form verificare/oscrie_in_fisiere/
	*-- listare_nir (Scan For suma<>0 Or se_scrie=1 / Append/Gather, mult mai devreme in
	*-- metoda) - o eroare TARZIE (ex. in raportarea NIR, dupa scriere) nu invalideaza datele
	*-- deja scrise. De-aia verific actactan INDIFERENT de llEroareTermin.
	IF USED('actactan')
		DO EeLog WITH 'DIAG dump actactan dupa Terminat:'
		SELECT actactan
		SCAN
			DO EeLog WITH '  recno=' + TRANSFORM(RECNO()) + ' nract=' + TRANSFORM(nract) + ' scd=' + ALLTRIM(NVL(scd,'')) + ' scc=' + ALLTRIM(NVL(scc,'')) + ;
				' suma=' + TRANSFORM(suma) + ' suma_val=' + TRANSFORM(NVL(suma_val,0)) + ' in_valuta=?' + ' id_valuta=' + TRANSFORM(NVL(id_valuta,0)) + ;
				' id_partd=' + TRANSFORM(NVL(id_partd,0)) + ' id_partc=' + TRANSFORM(NVL(id_partc,0)) + ' partc=[' + ALLTRIM(NVL(partc,'')) + ']'
		ENDSCAN

		=Assert3('52-actactan folosit dupa Terminat', IIF(USED('actactan'),1,0), 1)

		*-- randul "B" (baza facturii) - sincronizeaza() redistribuie valoarea originala pe
		*-- conturile REALE ale articolelor participante (212 = contul articolului BULDOEXCAVATOR,
		*-- nu 371, placeholder-ul din sablon) - comportament PRE-EXISTENT de participare la pret,
		*-- neschimbat de F1/F2. Nu (mai) pin-uiesc contul/suma exacta (ar cere sa refac math-ul
		*-- complet de spargere pe cote) - verific doar ca valoarea facturii e reprezentata,
		*-- atribuita corect furnizorului, in EUR.
		SELECT actactan
		LOCATE FOR nract = 8001 AND ALLTRIM(NVL(scc,'')) == '401' AND suma > 0 AND NVL(id_partc,0) = 601
		=Assert3('53-actactan: cel putin un rand de baza (scc=401, furnizor) gasit', IIF(FOUND(),1,0), 1)
		IF FOUND()
			=Assert3('56-actactan randul de baza: id_valuta=978 (EUR)', NVL(id_valuta,0), 978)
			=AssertStr('57-actactan randul de baza: nume_val=EUR', ALLTRIM(NVL(nume_val,'')), 'EUR')
			=Assert3('58-actactan randul de baza: id_partc=601 (furnizorul facturii)', NVL(id_partc,0), 601)
		ELSE
			pnAsserts = pnAsserts + 3
			DO EeLog WITH '  FAIL 56-58: niciun rand de baza gasit in actactan'
		ENDIF
		*-- NU verific suma totala exacta pe randurile de baza: cu un singur articol (800 EUR)
		*-- fata de baza integrala a facturii (1000 EUR), sincronizeaza() mai scrie si un rand de
		*-- diferenta/reconciliere (scd=6588) - matematica exacta de spargere pe conturi tine de
		*-- participarea la pret (pre-existenta, neschimbata de F1/F2), nu de scopul acestui test.

		SELECT actactan
		LOCATE FOR ALLTRIM(NVL(scd,'')) == '4426' AND suma > 0
		=Assert3('59-actactan randul T-DVI (scd=4426, suma pozitiva) gasit', IIF(FOUND(),1,0), 1)
		IF FOUND()
			=Assert3('60-actactan T-DVI.suma=840.00 (baza neta)', suma, 840.00)
			=Assert3('61-actactan T-DVI.suma_val=0 (RON, in_valuta=0, necopiat)', NVL(suma_val,0), 0)
			=Assert3('62-actactan T-DVI.id_valuta=0 (RON normalizat)', NVL(id_valuta,0), 0)
			=Assert3('63-actactan T-DVI.id_partc=900 (Directia Vamala)', NVL(id_partc,0), 900)
			=AssertStr('64-actactan T-DVI.partc=DIRECTIA VAMALA', ALLTRIM(NVL(partc,'')), 'DIRECTIA VAMALA')
		ELSE
			pnAsserts = pnAsserts + 4
			DO EeLog WITH '  FAIL 60-64: randul T-DVI negasit in actactan'
		ENDIF

		SELECT actactan
		LOCATE FOR nract = 8001 AND ALLTRIM(NVL(scc,'')) == '767'
		=Assert3('65-actactan randul G (scc=767, discount baza) gasit', IIF(FOUND(),1,0), 1)
		IF FOUND()
			=Assert3('66-actactan G.suma=+1000.00 (POZITIV)', suma, 1000.00)
			=Assert3('67-actactan G.suma_val=+200.00 (POZITIV, valuta mostenita de la B)', NVL(suma_val,0), 200.00)
			=Assert3('68-actactan G.id_partd=601 (furnizorul facturii)', NVL(id_partd,0), 601)
		ELSE
			pnAsserts = pnAsserts + 3
			DO EeLog WITH '  FAIL 66-68: randul G negasit in actactan'
		ENDIF

		*-- niciun rand fals de finalizare NIR: scd gol + scc=401 + suma=0, generat cand un rand cu_tva=0 (G) nu e exclus corect
		SELECT actactan
		LOCATE FOR EMPTY(NVL(scd,'')) AND ALLTRIM(NVL(scc,'')) == '401' AND NVL(suma,0) = 0
		=Assert3('73-niciun rand fals de finalizare NIR in actactan', IIF(FOUND(),1,0), 0)
	ELSE
		pnAsserts = pnAsserts + 16
		DO EeLog WITH '  FAIL 52-73: inainte_de_do_termin() a esuat sau actactan nu exista - assert-urile pe actactan sarite'
	ENDIF

	DO EeLog WITH 'REZULTAT: ' + TRANSFORM(pnPass) + '/' + TRANSFORM(pnAsserts) + ' assert-uri PASS'
	IF pnPass = pnAsserts
		DO EeLog WITH 'REZULTAT: PASS (' + TRANSFORM(pnPass) + '/' + TRANSFORM(pnAsserts) + ')'
	ELSE
		DO EeLog WITH 'REZULTAT: FAIL (' + TRANSFORM(pnPass) + '/' + TRANSFORM(pnAsserts) + ' assert-uri PASS)'
	ENDIF

	DO HarnessStep WITH 5, 'final: ' + TRANSFORM(pnPass) + '/' + TRANSFORM(pnAsserts) + ' PASS'
	DO HarnessDone WITH 'done'

CATCH TO loExc
	DO EeLog 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 CreeazaIntrodc
	*-- Runda30 (F1/pas2): coloane NOI rand_dvi N(1), valuta_proprie N(1) fata de structura veche.
	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 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 CreeazaActactan
	*-- structura minima ceruta de GATHER-urile
	*-- din import_nota.inainte_de_do_termin() (Scan For suma<>0 Or se_scrie=1 / Append Blank /
	*-- Gather Name poAct + Gather Name loFact Fields ...). Fara ea, GATHER FIELDS ar da eroare
	*-- de camp inexistent inainte sa ajunga la Do Form verificare.
	IF USED('actactan')
		USE IN ('actactan')
	ENDIF
	CREATE CURSOR actactan ( ;
		id_fdoc N(14), fdoc C(50), dataact D, serie_act C(10), nract N(14), ;
		partc C(100), id_partc N(14), partd C(100), id_partd N(14), ;
		suma N(18,4), suma_val N(18,4), explicatia C(100), explicatia4 C(50), explicatia5 C(50), ;
		scd C(10), ascd C(20), scc C(10), ascc C(20), id_jtva_coloana N(14) NULL, taxcode N(6), ;
		id_valuta N(14), curs N(14,4), nume_val C(10), proc_tva N(8,4), nnir N(14), ;
		tva_incasare N(1), id_set N(14), id_gestin N(14))
ENDPROC

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

PROCEDURE Assert3
	LPARAMETERS tcLabel, tuActual, tuExpected
	pnAsserts = pnAsserts + 1
	IF ABS(NVL(tuActual,0) - tuExpected) < 0.02
		pnPass = pnPass + 1
		DO EeLog WITH '  PASS ' + tcLabel + ' (=' + TRANSFORM(tuActual) + ')'
	ELSE
		DO EeLog WITH '  FAIL ' + tcLabel + ' (actual=' + TRANSFORM(tuActual) + ' asteptat=' + TRANSFORM(tuExpected) + ')'
	ENDIF
ENDPROC

PROCEDURE AssertStr
	LPARAMETERS tcLabel, tcActual, tcExpected
	pnAsserts = pnAsserts + 1
	IF tcActual == tcExpected
		pnPass = pnPass + 1
		DO EeLog WITH '  PASS ' + tcLabel + ' (=[' + tcActual + '])'
	ELSE
		DO EeLog WITH '  FAIL ' + tcLabel + ' (actual=[' + tcActual + '] asteptat=[' + tcExpected + '])'
	ENDIF
ENDPROC

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

PROCEDURE EeLog
	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'
			CREATE CURSOR (m.tcCursor) (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))
			RETURN 1
		ENDIF
		IF 'CONFIG_ANALITICE' $ UPPER(m.tcSql)
			CREATE CURSOR (m.tcCursor) (camp_leg_prefix C(30), camp_leg_sufix C(30))
			INSERT INTO (m.tcCursor) VALUES ('', '')
			RETURN 1
		ENDIF
		IF 'FCONTURI_ANALITICE' $ UPPER(m.tcSql)
			CREATE CURSOR (m.tcCursor) (acont C(20))
			INSERT INTO (m.tcCursor) VALUES (IIF(TYPE('gcMockAcontCrt') = 'C', gcMockAcontCrt, ''))
			RETURN 1
		ENDIF
		IF 'VPLCONT_ANALITIC' $ UPPER(m.tcSql)
			*-- gol: niciun cont nu cere analitic in scenariul acestui test (371/401 folosite
			*-- fara analitic, ca in restul suitei - vezi verificare_note_contabile)
			CREATE CURSOR (m.tcCursor) (cont C(10), acont C(20))
			RETURN 1
		ENDIF
		IF 'VCONFIG_CONT_IREG' $ UPPER(m.tcSql)
			*-- 401 recunoscut ca si cont cu parteneri (verificare_note_contabile) - altfel
			*-- verif_part goleste id_partc/id_partd pe randurile T-DVI/G inainte de actactan
			CREATE CURSOR (m.tcCursor) (contpart C(10), fel_cont N(1), cu_inregistrari N(1), ;
				explic_cont C(100), exceptie C(10), pozitie N(1), invers N(1), gasit N(1))
			INSERT INTO (m.tcCursor) VALUES ('401', 0, 0, 'Furnizori', '', 0, 0, 0)
			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)
	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
