* test_scenariu_dvi_complet.prg
* Scenariu complet Marius (rundele 8-11, COMUN\clase\ointroduceri.vcx, clasa import_nota),
* curs 1 EUR = 5.2300:
*   Doc1 FACTURA 15000 RAJA, 4707+523=5230 lei / 900+100=1000 EUR, in_valuta, participa,
*        TVA pe DVI ('D'): DVI 100 BIROUL VAMAL, tva 1098.30 lei/210 EUR, explicatie ACH. IMP. 21%.
*   Doc2 FACTURA 12000 TRANS OIL, 1000 lei, participa, TVA pe DVI ('D'): acelasi DVI 100
*        BIROUL VAMAL, tva 210 lei.
*   Doc3 DVI 100 BIROUL VAMAL, 500 lei (taxe vamale), TVA normal ('F') cu explicatia ACH. IMP. 21%.
*   Articole (flux real do_adauga_articol + mock_cauta_nom_articole): BULDOEXCAVATOR cont 212
*        acont '1' (cant 1, pret_val 900); A8 cod 8003510000203 cont 371 acont '4' (cant 1, pret_val 100).
* Verifica: (r8) spargere pe cont+analitic (S 212/ascd=1, S 371/ascd=4); (r9) doc_key unic per
* document + T-ul doc3 (DVI taxe vamale, ramura 'F') NU e re-cheiat pe 4427 (scc=401, coloana_jc
* FO21T nu se potriveste patternurilor TI/CE); (r10) do_sterge cu meniu 6/7/2 (Cancel) +
* do_copiaza_nota cu meniu 6/7; (r11) procente per rand explicatia4/5 + totaluri banda.
*
* Rulare:
*   powershell -ExecutionPolicy Bypass -File test_scenariu_dvi_complet.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_scenariu_dvi_complet_log.txt"
gcSyncDir = "D:\ROA\ROAGEST\COMUN\utile\Teste\achizitie_import\uisync_dvi_complet\"
STRTOFILE("START " + TTOC(DATETIME()) + CHR(13)+CHR(10), gcUILog)

ON ERROR DO DcErr 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 DcLog 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 DcLog 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 DcLog 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, gcMockAcontCrt
	gcMockArtCodmat = ''
	gcMockAcontCrt = ''
	*-- controleaza mock_amessagebox.prg (implicit 6=Da, testele de stergere/copiere il schimba per pas)
	PUBLIC gnMockRaspuns
	gnMockRaspuns = 6

	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', 5.23)
	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', 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% (Oracle dev, vjtva_coloane, 17.07.2026) -----
	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)

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

	DO DcLog WITH 'cursoare pregatite, CREATEOBJECT(import_nota, .F.) - lIntern=.F. (import)'
	PUBLIC goObj
	goObj = CREATEOBJECT('IMPORT_nota', .F.)
	IF VARTYPE(goObj) <> 'O'
		DO DcLog WITH 'FAIL: instantiere import_nota'
		DO HarnessDone WITH 'done-error'
		QUIT
	ENDIF
	goObj.lDialogAratat = .T.
	goObj.oact = poAct
	*-- acest test acopera modul NESPART (secundarele raman intregi) - spargerea secundarelor e acoperita de test_sparge_secundare.prg
	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

	*========================= DOC 1, DOC 2, DOC 3 =========================
	PUBLIC goDlg, goT
	DO AdaugaDoc1
	DO VerificaPereche WITH 15000, 5230, 1000, 'EUR'
	DO VerificaDvi WITH 15000, 100, 5230, 1098.30, 210.00

	DO AdaugaDoc2
	DO VerificaPereche WITH 12000, 1000, 0, ''

	DO AdaugaDoc3
	DO VerificaPereche WITH 100, 500, 0, ''

	DO DcLog WITH 'dump introdc dupa cele 3 documente (inainte de articole):'
	DO DumpIntrodc

	DO HarnessStep WITH 0, 'dupa 3 documente: introdc=' + TRANSFORM(RECCOUNT_ACTIVE('introdc')) + ' randuri (astept 6, 3 perechi B/T)'

	*========================= ARTICOLE (flux real do_adauga_articol) =========================
	gcMockArtCodmat = 'ART-BULD-212'
	gcMockAcontCrt = '1'
	TRY
		goObj.do_adauga_articol()
	CATCH TO loExcA1
		DO DcLog WITH 'EROARE do_adauga_articol (BULDOEXCAVATOR) ' + TRANSFORM(loExcA1.ErrorNo) + ' [' + loExcA1.Message + '] in ' + loExcA1.Procedure + ':' + TRANSFORM(loExcA1.LineNo)
	ENDTRY
	DOEVENTS FORCE
	SELECT rul_temp
	LOCATE FOR ALLTRIM(codmat) == 'ART-BULD-212'
	IF FOUND()
		REPLACE cant WITH 1, pret_val WITH 900, pretd WITH 900, pret WITH ROUND(900*5.23,4), pret_lei WITH ROUND(900*5.23,4)
		DO DcLog WITH 'BULDOEXCAVATOR (212) adaugat, cant/pret completate (900 EUR / ' + TRANSFORM(ROUND(900*5.23,4)) + ' lei)'
	ELSE
		DO DcLog WITH 'FAIL: BULDOEXCAVATOR nu a fost adaugat de do_adauga_articol()'
	ENDIF

	gcMockArtCodmat = 'ART-A8-371'
	gcMockAcontCrt = '4'
	TRY
		goObj.do_adauga_articol()
	CATCH TO loExcA2
		DO DcLog WITH 'EROARE do_adauga_articol (A8) ' + TRANSFORM(loExcA2.ErrorNo) + ' [' + loExcA2.Message + '] in ' + loExcA2.Procedure + ':' + TRANSFORM(loExcA2.LineNo)
	ENDTRY
	DOEVENTS FORCE
	SELECT rul_temp
	LOCATE FOR ALLTRIM(codmat) == 'ART-A8-371'
	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 DcLog WITH 'A8 (371) adaugat, cant/pret completate (100 EUR / ' + TRANSFORM(ROUND(100*5.23,4)) + ' lei)'
	ELSE
		DO DcLog WITH 'FAIL: A8 nu a fost adaugat de do_adauga_articol()'
	ENDIF
	goObj.gridart.Refresh()
	DOEVENTS FORCE

	DO HarnessStep WITH 1, 'dupa adaugare articole BULDOEXCAVATOR+A8, rul_temp=' + TRANSFORM(RECCOUNT_ACTIVE('rul_temp'))

	*========================= SINCRONIZARE #1 =========================
	LOCAL llEroareSync1
	llEroareSync1 = .F.
	TRY
		goObj.sincronizeaza()
	CATCH TO loExcS1
		llEroareSync1 = .T.
		DO DcLog WITH 'EROARE la sincronizeaza() #1 ' + TRANSFORM(loExcS1.ErrorNo) + ' [' + loExcS1.Message + '] in ' + loExcS1.Procedure + ':' + TRANSFORM(loExcS1.LineNo) + ' (' + loExcS1.LineContents + ')'
	ENDTRY
	DOEVENTS FORCE
	goObj.grid1.Refresh()
	IF !llEroareSync1
		DO DcLog WITH 'PASS sincronizare1: sincronizeaza() #1 fara eroare'
	ELSE
		DO DcLog WITH 'FAIL sincronizare1: sincronizeaza() #1 a aruncat eroare'
	ENDIF
	DO DcLog WITH 'dump introdc dupa sincronizare #1:'
	DO DumpIntrodc

	DO HarnessStep WITH 2, 'dupa sincronizare #1, introdc=' + TRANSFORM(RECCOUNT_ACTIVE('introdc')) + ' randuri'

	*========================= SINCRONIZARE #2 (stabilitate la resincronizare) =========================
	LOCAL lnRandInainte2, lnRandDupa2
	SELECT introdc
	COUNT TO lnRandInainte2 FOR !DELETED()
	LOCAL llEroareSync2
	llEroareSync2 = .F.
	TRY
		goObj.sincronizeaza()
	CATCH TO loExcS2
		llEroareSync2 = .T.
		DO DcLog WITH 'EROARE la sincronizeaza() #2 ' + TRANSFORM(loExcS2.ErrorNo) + ' [' + loExcS2.Message + ']'
	ENDTRY
	DOEVENTS FORCE
	goObj.grid1.Refresh()
	SELECT introdc
	COUNT TO lnRandDupa2 FOR !DELETED()
	IF !llEroareSync2 AND lnRandInainte2 = lnRandDupa2
		DO DcLog WITH 'PASS sincronizare2 (stabilitate): #2 fara eroare, randuri neschimbate (' + TRANSFORM(lnRandDupa2) + ')'
	ELSE
		DO DcLog WITH 'FAIL sincronizare2 (stabilitate): eroare=' + TRANSFORM(llEroareSync2) + ' randuriInainte=' + TRANSFORM(lnRandInainte2) + ' randuriDupa=' + TRANSFORM(lnRandDupa2)
	ENDIF
	DO DcLog WITH 'dump introdc dupa sincronizare #2:'
	DO DumpIntrodc

	*========================= VERIFICARE 1: ANALITICE (r8) =========================
	DO VerificaAnalitic WITH '212', '1', 900, 'r8-S212'
	DO VerificaAnalitic WITH '371', '4', 100, 'r8-S371'
	*-- ascd NEgolit dupa al 2-lea F5 (verificat implicit prin DO VerificaAnalitic de mai sus, apelat DUPA sincronizare #2)

	*========================= VERIFICARE 2: DVI / doc_key (r9) =========================
	*-- doc1 e principalul: dupa spargere B-ul lui a disparut (dec.9) - T-ul DVI se cauta prin
	*-- nr_doc-ul luat de pe un rand S (nract-ul original se pastreaza si pe S-uri).
	DO VerificaDviPrincipalSpart
	DO VerificaDvi WITH 12000, 100, 1000, 210.00, 0
	DO VerificaRandTNormalF WITH 100, '4426', '401', 21, 105.00, 'TVA ACH. IMP. 21%'
	DO VerificaDocKeyUnice WITH 3

	*========================= VERIFICARE 3: PROCENTE (r11) =========================
	DO VerificaProcente WITH 15000, '100.00', '100.00', 'doc1(principal)'
	DO VerificaProcente WITH 12000, '19.12', '19.12', 'doc2'
	DO VerificaProcente WITH 100, '9.56', '9.56', 'doc3'

	*========================= VERIFICARE 4: TOTALURI (r11) =========================
	DO DcLog WITH 'TOTALURI: TxtFtvaLei=' + TRANSFORM(goObj.txtftvalei.Value) + ' TxtFtvaVal=' + TRANSFORM(goObj.txtftvaval.Value) + ;
		' Text2=' + TRANSFORM(goObj.text2.Value) + ' Text3=' + TRANSFORM(goObj.text3.Value) + ;
		' nbaza_lei=' + TRANSFORM(goObj.nbaza_lei) + ' ntva_lei=' + TRANSFORM(goObj.ntva_lei) + ;
		' nbaza_val=' + TRANSFORM(goObj.nbaza_val) + ' ntva_val=' + TRANSFORM(goObj.ntva_val)
	IF ABS(goObj.txtftvalei.Value - 6730.00) < 0.01
		DO DcLog WITH 'PASS r11-TxtFtvaLei: ' + TRANSFORM(goObj.txtftvalei.Value) + ' (asteptat 6730.00)'
	ELSE
		DO DcLog WITH 'FAIL r11-TxtFtvaLei: ' + TRANSFORM(goObj.txtftvalei.Value) + ' (asteptat 6730.00)'
	ENDIF
	IF ABS(goObj.ntva_lei - 1413.30) < 0.01
		DO DcLog WITH 'PASS r11-ntva_lei: ' + TRANSFORM(goObj.ntva_lei) + ' (asteptat 1413.30 = 1098.30+210+105)'
	ELSE
		DO DcLog WITH 'INFO r11-ntva_lei: ' + TRANSFORM(goObj.ntva_lei) + ' (asteptare estimata 1413.30 = 1098.30+210+105 - raporteaza valoarea efectiva)'
	ENDIF
	IF ABS(goObj.text2.Value - (goObj.nbaza_lei + goObj.ntva_lei)) < 0.01
		DO DcLog WITH 'PASS r11-Text2: ' + TRANSFORM(goObj.text2.Value) + ' == nbaza_lei+ntva_lei (' + TRANSFORM(goObj.nbaza_lei + goObj.ntva_lei) + ')'
	ELSE
		DO DcLog WITH 'FAIL r11-Text2: ' + TRANSFORM(goObj.text2.Value) + ' != nbaza_lei+ntva_lei (' + TRANSFORM(goObj.nbaza_lei + goObj.ntva_lei) + ')'
	ENDIF
	IF ABS(goObj.text3.Value - (goObj.nbaza_val + goObj.ntva_val)) < 0.01
		DO DcLog WITH 'PASS r11-Text3: ' + TRANSFORM(goObj.text3.Value) + ' == nbaza_val+ntva_val (' + TRANSFORM(goObj.nbaza_val + goObj.ntva_val) + ')'
	ELSE
		DO DcLog WITH 'FAIL r11-Text3: ' + TRANSFORM(goObj.text3.Value) + ' != nbaza_val+ntva_val (' + TRANSFORM(goObj.nbaza_val + goObj.ntva_val) + ')'
	ENDIF
	DO DcLog WITH 'INFO r11-TxtFtvaVal: ' + TRANSFORM(goObj.txtftvaval.Value) + ' (asteptare aproximativa 1286.80 - raporteaza valoarea efectiva)'
	DO DcLog WITH 'INFO r11-ntva_val: ' + TRANSFORM(goObj.ntva_val) + ' (asteptare aproximativa 270.23 - raporteaza valoarea efectiva)'

	DO HarnessStep WITH 3, 'dupa verificari analitice/DVI/procente/totaluri - vezi log pentru PASS/FAIL'

	*========================= VERIFICARE 5a: STERGERE document (raspuns 6) =========================
	SELECT introdc
	LOCATE FOR nract = 100 AND ALLTRIM(fdoc) == 'DVI' AND tip_rand == 'B'
	LOCAL llPozitionatDoc3, lcDocKeyDoc3Sters
	llPozitionatDoc3 = FOUND()
	IF llPozitionatDoc3
		lcDocKeyDoc3Sters = doc_key
		gnMockRaspuns = 6
		DO DcLog WITH 'DIAG pre-do_sterge(6): recno=' + TRANSFORM(RECNO('introdc')) + ' reccount=' + TRANSFORM(RECCOUNT('introdc')) + ' eof=' + TRANSFORM(EOF('introdc')) + ' bof=' + TRANSFORM(BOF('introdc')) + ' tip_rand=' + tip_rand + ' doc_key=[' + ALLTRIM(doc_key) + '] gnMockRaspuns=' + TRANSFORM(gnMockRaspuns)
		TRY
			goObj.do_sterge()
		CATCH TO loExcDel1
			DO DcLog WITH 'EROARE do_sterge (raspuns6) ' + TRANSFORM(loExcDel1.ErrorNo) + ' [' + loExcDel1.Message + ']'
		ENDTRY
		DOEVENTS FORCE
	ELSE
		DO DcLog WITH 'FAIL setup-stergere6: nu am gasit randul B al doc3 (nract=100, DVI)'
	ENDIF
	DO VerificaStergereDoc3Doar WITH 'r10-stergere-doc(raspuns6)'
	*-- doc1 (principal) nu mai are rand B dupa spargere (D9: B dispare dupa spargere) - verific
	*-- prin S-uri (nract-ul original se pastreaza pe ele); doc2 (nespart) inca are B.
	DO VerificaDoc1SIntact
	DO VerificaPereche WITH 12000, 1000, 0, ''
	DO DcLog WITH 'dump introdc dupa stergere document (raspuns6):'
	DO DumpIntrodc

	DO HarnessStep WITH 4, 'dupa stergere document doc3 (raspuns6): introdc=' + TRANSFORM(RECCOUNT_ACTIVE('introdc'))

	*========================= VERIFICARE 5b: STERGERE doar linia (raspuns 7) =========================
	DO AdaugaDoc3
	DOEVENTS FORCE
	SELECT introdc
	LOCATE FOR nract = 100 AND ALLTRIM(fdoc) == 'DVI' AND tip_rand == 'B'
	LOCAL llPozB7, lnRandInainte7
	llPozB7 = FOUND()
	SELECT introdc
	COUNT TO lnRandInainte7 FOR !DELETED()
	*-- COUNT muta pointerul pe EOF (nu-l restaureaza) - repozitionez explicit inainte de apel,
	*-- altfel do_sterge() vede Eof()=.T. si iese fara sa faca nimic (bug de test, nu de aplicatie).
	IF llPozB7
		SELECT introdc
		LOCATE FOR nract = 100 AND ALLTRIM(fdoc) == 'DVI' AND tip_rand == 'B'
		gnMockRaspuns = 7
		DO DcLog WITH 'DIAG pre-do_sterge(7): recno=' + TRANSFORM(RECNO('introdc')) + ' reccount=' + TRANSFORM(RECCOUNT('introdc')) + ' eof=' + TRANSFORM(EOF('introdc')) + ' bof=' + TRANSFORM(BOF('introdc')) + ' tip_rand=' + tip_rand + ' doc_key=[' + ALLTRIM(doc_key) + '] gnMockRaspuns=' + TRANSFORM(gnMockRaspuns)
		TRY
			goObj.do_sterge()
		CATCH TO loExcDel2
			DO DcLog WITH 'EROARE do_sterge (raspuns7) ' + TRANSFORM(loExcDel2.ErrorNo) + ' [' + loExcDel2.Message + ']'
		ENDTRY
		DOEVENTS FORCE
	ELSE
		DO DcLog WITH 'FAIL setup-stergere7: nu am gasit randul B al doc3 re-adaugat'
	ENDIF
	LOCAL lnRandDupa7
	SELECT introdc
	COUNT TO lnRandDupa7 FOR !DELETED()
	IF llPozB7 AND lnRandDupa7 = lnRandInainte7 - 1
		DO DcLog WITH 'PASS r10-stergere-linie(raspuns7): a disparut EXACT 1 rand (' + TRANSFORM(lnRandInainte7) + ' -> ' + TRANSFORM(lnRandDupa7) + ')'
	ELSE
		DO DcLog WITH 'FAIL r10-stergere-linie(raspuns7): randuriInainte=' + TRANSFORM(lnRandInainte7) + ' randuriDupa=' + TRANSFORM(lnRandDupa7) + ' (astept diferenta de exact 1)'
	ENDIF

	DO HarnessStep WITH 5, 'dupa stergere linie doc3-B (raspuns7): introdc=' + TRANSFORM(RECCOUNT_ACTIVE('introdc'))

	*========================= VERIFICARE 5c: STERGERE Cancel (raspuns 2) - nimic sters =========================
	SELECT introdc
	GO TOP
	LOCAL lnRandInainte2c
	COUNT TO lnRandInainte2c FOR !DELETED()
	*-- COUNT muta pointerul pe EOF - repozitionez inainte de apel (vezi comentariul de la stergere7).
	SELECT introdc
	GO TOP
	gnMockRaspuns = 2
	DO DcLog WITH 'DIAG pre-do_sterge(2/cancel): recno=' + TRANSFORM(RECNO('introdc')) + ' reccount=' + TRANSFORM(RECCOUNT('introdc')) + ' eof=' + TRANSFORM(EOF('introdc')) + ' bof=' + TRANSFORM(BOF('introdc')) + ' tip_rand=' + IIF(EOF('introdc') OR BOF('introdc'),'?',introdc.tip_rand) + ' gnMockRaspuns=' + TRANSFORM(gnMockRaspuns)
	TRY
		goObj.do_sterge()
	CATCH TO loExcDel3
		DO DcLog WITH 'EROARE do_sterge (raspuns2/cancel) ' + TRANSFORM(loExcDel3.ErrorNo) + ' [' + loExcDel3.Message + ']'
	ENDTRY
	DOEVENTS FORCE
	LOCAL lnRandDupa2c
	SELECT introdc
	COUNT TO lnRandDupa2c FOR !DELETED()
	IF lnRandInainte2c = lnRandDupa2c
		DO DcLog WITH 'PASS r10-stergere-cancel(raspuns2): niciun rand sters (' + TRANSFORM(lnRandDupa2c) + ')'
	ELSE
		DO DcLog WITH 'FAIL r10-stergere-cancel(raspuns2): randuriInainte=' + TRANSFORM(lnRandInainte2c) + ' randuriDupa=' + TRANSFORM(lnRandDupa2c) + ' (astept egale)'
	ENDIF
	gnMockRaspuns = 6

	DO HarnessStep WITH 6, 'dupa stergere Cancel: introdc=' + TRANSFORM(RECCOUNT_ACTIVE('introdc')) + ' (neschimbat)'

	*========================= VERIFICARE 6a: COPIERE document (raspuns 6) =========================
	*-- doc2 (TRANS OIL, nract=12000): nu e documentul principal, deci pastreaza randul B intact
	*-- toata rularea (doar principalul - doc1 - isi pierde B-ul la spargere, D9); folosesc doc2
	*-- ca sa am mereu un B valid de pozitionat pentru copiere, indiferent de starea testelor de
	*-- stergere anterioare (care au vizat doc3).
	SELECT introdc
	LOCATE FOR nract = 12000 AND tip_rand == 'B'
	LOCAL llPozDoc2B, lnMaxNrDocInainte, lnRandInainteCopy
	llPozDoc2B = FOUND()
	lnMaxNrDocInainte = 0
	CALCULATE MAX(IIF(NVL(nr_doc,0) = 99999999, 0, NVL(nr_doc,0))) TO lnMaxNrDocInainte
	SELECT introdc
	COUNT TO lnRandInainteCopy FOR !DELETED()
	*-- COUNT/CALCULATE muta pointerul pe EOF - repozitionez inainte de apel (vezi stergere7).
	IF llPozDoc2B
		SELECT introdc
		LOCATE FOR nract = 12000 AND tip_rand == 'B'
		gnMockRaspuns = 6
		DO DcLog WITH 'DIAG pre-do_copiaza_nota(6): recno=' + TRANSFORM(RECNO('introdc')) + ' reccount=' + TRANSFORM(RECCOUNT('introdc')) + ' eof=' + TRANSFORM(EOF('introdc')) + ' bof=' + TRANSFORM(BOF('introdc')) + ' tip_rand=' + tip_rand + ' doc_key=[' + ALLTRIM(doc_key) + '] gnMockRaspuns=' + TRANSFORM(gnMockRaspuns)
		TRY
			goObj.do_copiaza_nota()
		CATCH TO loExcCopy1
			DO DcLog WITH 'EROARE do_copiaza_nota (raspuns6) ' + TRANSFORM(loExcCopy1.ErrorNo) + ' [' + loExcCopy1.Message + ']'
		ENDTRY
		DOEVENTS FORCE
	ELSE
		DO DcLog WITH 'FAIL setup-copiere6: nu am gasit randul B al doc2 (nract=12000)'
	ENDIF
	DO VerificaCopiereDocument WITH lnMaxNrDocInainte, lnRandInainteCopy
	DO DcLog WITH 'dump introdc dupa copiere document (raspuns6):'
	DO DumpIntrodc

	DO HarnessStep WITH 7, 'dupa copiere document doc2 (raspuns6): introdc=' + TRANSFORM(RECCOUNT_ACTIVE('introdc'))

	*========================= VERIFICARE 6b: COPIERE doar linia (raspuns 7) =========================
	SELECT introdc
	LOCATE FOR nract = 12000 AND tip_rand == 'B'
	LOCAL llPozDoc2B2, lnRandInainteCopy2
	llPozDoc2B2 = FOUND()
	SELECT introdc
	COUNT TO lnRandInainteCopy2 FOR !DELETED()
	*-- COUNT muta pointerul pe EOF - repozitionez inainte de apel (vezi stergere7).
	IF llPozDoc2B2
		SELECT introdc
		LOCATE FOR nract = 12000 AND tip_rand == 'B'
		gnMockRaspuns = 7
		DO DcLog WITH 'DIAG pre-do_copiaza_nota(7): recno=' + TRANSFORM(RECNO('introdc')) + ' reccount=' + TRANSFORM(RECCOUNT('introdc')) + ' eof=' + TRANSFORM(EOF('introdc')) + ' bof=' + TRANSFORM(BOF('introdc')) + ' tip_rand=' + tip_rand + ' doc_key=[' + ALLTRIM(doc_key) + '] gnMockRaspuns=' + TRANSFORM(gnMockRaspuns)
		TRY
			goObj.do_copiaza_nota()
		CATCH TO loExcCopy2
			DO DcLog WITH 'EROARE do_copiaza_nota (raspuns7) ' + TRANSFORM(loExcCopy2.ErrorNo) + ' [' + loExcCopy2.Message + ']'
		ENDTRY
		DOEVENTS FORCE
	ELSE
		DO DcLog WITH 'FAIL setup-copiere7: nu am gasit randul B al doc2'
	ENDIF
	LOCAL lnRandDupaCopy2
	SELECT introdc
	COUNT TO lnRandDupaCopy2 FOR !DELETED()
	IF llPozDoc2B2 AND lnRandDupaCopy2 = lnRandInainteCopy2 + 1
		DO DcLog WITH 'PASS(partial) r10-copiere-linie(raspuns7): a aparut EXACT 1 rand nou (' + TRANSFORM(lnRandInainteCopy2) + ' -> ' + TRANSFORM(lnRandDupaCopy2) + ')'
	ELSE
		DO DcLog WITH 'FAIL r10-copiere-linie(raspuns7): randuriInainte=' + TRANSFORM(lnRandInainteCopy2) + ' randuriDupa=' + TRANSFORM(lnRandDupaCopy2) + ' (astept diferenta de exact 1)'
	ENDIF
	DO VerificaCopiereLinieContinut WITH 'r10-copiere-linie-continut(raspuns7)'

	DO DcLog WITH 'dump introdc FINAL:'
	DO DumpIntrodc

	DO DcLog WITH 'GATA - scenariu executat integral'
	DO HarnessStep WITH 8, 'final: introdc=' + TRANSFORM(RECCOUNT_ACTIVE('introdc')) + ' randuri'
	DO HarnessDone WITH 'done'

CATCH TO loExc
	DO DcLog 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 AdaugaDoc1
	*-- FACTURA 15000, RAJA, DVI valuta (EUR curs 5.23): DVI 100, BIROUL VAMAL, tva 1098.30/210.
	goDlg = CREATEOBJECT('import_adauga_factura', goObj)
	goDlg.cFelDoc = 'Factura'
	goDlg.nIdFdoc = 1
	goDlg.nNract = 15000
	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 = 100
	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 DcLog WITH 'DOC1: valideaza = ' + TRANSFORM(goDlg.valideaza())
	DO ConstruiesteToDlg
	DO DcLog WITH 'DOC1: do_adauga_factura = ' + TRANSFORM(goObj.do_adauga_factura(goT))
	goDlg.Hide()
	DOEVENTS FORCE
ENDPROC

PROCEDURE AdaugaDoc2
	*-- FACTURA 12000, TRANS OIL, DVI lei (acelasi doc vamal 100).
	goDlg = CREATEOBJECT('import_adauga_factura', goObj)
	goDlg.cFelDoc = 'Factura'
	goDlg.nIdFdoc = 1
	goDlg.nNract = 12000
	goDlg.dDataAct = DATE()
	goDlg.nIdPartener = 602
	goDlg.cPartener = 'TRANS OIL'
	goDlg.cExplicatia = 'Achizitie TRANS OIL'
	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 = 100
	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 DcLog WITH 'DOC2: valideaza = ' + TRANSFORM(goDlg.valideaza())
	DO ConstruiesteToDlg
	DO DcLog WITH 'DOC2: do_adauga_factura = ' + TRANSFORM(goObj.do_adauga_factura(goT))
	goDlg.Hide()
	DOEVENTS FORCE
ENDPROC

PROCEDURE AdaugaDoc3
	*-- DVI 100, BIROUL VAMAL, 500 lei (taxe vamale), TVA normal 'F' cu explicatia ACH. IMP. 21%.
	goDlg = CREATEOBJECT('import_adauga_factura', goObj)
	goDlg.cFelDoc = 'DVI'
	goDlg.nIdFdoc = 2
	goDlg.nNract = 100
	goDlg.dDataAct = DATE()
	goDlg.nIdPartener = 900
	goDlg.cPartener = 'BIROUL VAMAL'
	goDlg.cExplicatia = 'Taxe vamale DVI 100'
	goDlg.nSuma = 500
	goDlg.nSumaLei = 0
	goDlg.nCurs = 0
	goDlg.nIdExplicatieTva = 220
	goDlg.cExplicatieTva = 'ACH. IMP. 21%'
	goDlg.optTipTva.Value = 1 && F = furnizor (normal, NU referinta DVI)
	goDlg.chkInValutaCont.Value = 0
	goDlg.chkParticipaValuta.Value = 1
	goDlg.WindowType = 0
	goDlg.Visible = .T.
	goDlg.Show()
	DOEVENTS FORCE
	DO DcLog WITH 'DOC3: valideaza = ' + TRANSFORM(goDlg.valideaza())
	DO ConstruiesteToDlg
	DO DcLog WITH 'DOC3: do_adauga_factura = ' + TRANSFORM(goObj.do_adauga_factura(goT))
	goDlg.Hide()
	DOEVENTS FORCE
ENDPROC

PROCEDURE ConstruiesteToDlg
	*-- toDlg construit INLINE (nu intr-o functie apelata din procedura de business) - vezi
	*-- docs/testare-ui-vfp.md capcana l; aici functioneaza fiindca goT e PUBLIC (nu return local).
	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 (VRUL, Oracle dev, MARIUSM_AUTO - vezi test_adauga_repere_212.prg).
	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 VerificaPereche
	LPARAMETERS tnNract, tnBazaLei, tnBazaVal, tcVal
	LOCAL lnSel, lcMsg, llB, lnBS, lnBSV, lcNV
	lnSel = SELECT()
	SELECT introdc
	LOCATE FOR nract = tnNract AND tip_rand == 'B'
	llB = FOUND()
	IF llB
		lnBS = suma
		lnBSV = suma_val
		lcNV = ALLTRIM(NVL(nume_val,''))
	ENDIF
	IF llB AND ABS(lnBS - tnBazaLei) < 0.01 AND ABS(lnBSV - tnBazaVal) < 0.01 AND ALLTRIM(NVL(lcNV,'')) == tcVal
		lcMsg = 'PASS pereche nract=' + TRANSFORM(tnNract) + ': B(suma=' + TRANSFORM(lnBS) + ' val=' + TRANSFORM(lnBSV) + ' ' + lcNV + ')'
	ELSE
		lcMsg = 'FAIL pereche nract=' + TRANSFORM(tnNract) + ': B?=' + TRANSFORM(llB) + ' bazaLei=' + TRANSFORM(IIF(llB,lnBS,-1)) + '(astept ' + TRANSFORM(tnBazaLei) + ') bazaVal=' + TRANSFORM(IIF(llB,lnBSV,-1)) + '(astept ' + TRANSFORM(tnBazaVal) + ') val=[' + IIF(llB,lcNV,'?') + '](astept [' + tcVal + '])'
	ENDIF
	DO DcLog WITH lcMsg
	SELECT (lnSel)
ENDPROC

PROCEDURE VerificaDoc1SIntact
	*-- doc1 (principal, nract=15000) nu mai are rand B dupa spargere (dec.9: "B dispare dupa
	*-- spargere", ointroduceri.vc2:11910-11912) - verific ca ramane intact prin S-uri (pastreaza
	*-- nract-ul original din Gather Name loRandB Memo in creeaza_rand_s).
	LOCAL lnSel, lcMsg, lnSumaS, lnSumaSVal
	lnSel = SELECT()
	SELECT SUM(suma) AS s, SUM(suma_val) AS sv FROM introdc WHERE nract = 15000 AND tip_rand == 'S' INTO CURSOR crsDoc1S NOFILTER
	lnSumaS = NVL(crsDoc1S.s, 0)
	lnSumaSVal = NVL(crsDoc1S.sv, 0)
	USE IN crsDoc1S
	IF ABS(lnSumaS - 5230) < 0.01 AND ABS(lnSumaSVal - 1000) < 0.01
		lcMsg = 'PASS doc1-intact(dupa stergere doc3, prin S-uri): suma=' + TRANSFORM(lnSumaS) + ' suma_val=' + TRANSFORM(lnSumaSVal)
	ELSE
		lcMsg = 'FAIL doc1-intact(dupa stergere doc3, prin S-uri): suma=' + TRANSFORM(lnSumaS) + '(astept 5230) suma_val=' + TRANSFORM(lnSumaSVal) + '(astept 1000)'
	ENDIF
	DO DcLog WITH lcMsg
	SELECT (lnSel)
ENDPROC

PROCEDURE VerificaDviPrincipalSpart
	*-- doc1 (principal, nract=15000) dupa spargere: B a disparut, nr_doc se ia de pe un rand S
	*-- (pastreaza nract-ul original); T-ul DVI se cauta prin acel nr_doc (nract-ul T-ului a fost
	*-- rescris pe identitatea vamii - 100/DVI - si colizioneaza cu T-urile doc2/doc3).
	*-- Runda 27: T-ul e grupat pe cota+scc/ascc preluate de la S-uri (creditorul S-urilor); aici
	*-- ambele S-uri (212 si 371) au scc=401 mostenit din sablon, deci T-ul ramane unul singur.
	*-- Partenerul TVA (partc) NU se preia de la S-uri: ramane cel ales la introducerea facturii
	*-- (aici TVA pe DVI -> BIROUL VAMAL).
	LOCAL lnSel, lcMsg, llS, llT, lnNrDocCrt, lnTS, lnTSV, lcTPartc, lcTScc
	lnSel = SELECT()
	SELECT introdc
	LOCATE FOR nract = 15000 AND tip_rand == 'S'
	llS = FOUND()
	llT = .F.
	IF llS
		lnNrDocCrt = nr_doc
		LOCATE FOR nr_doc = lnNrDocCrt AND tip_rand == 'T'
		llT = FOUND()
		IF llT
			lnTS = suma
			lnTSV = suma_val
			lcTPartc = ALLTRIM(NVL(partc,''))
			lcTScc = ALLTRIM(NVL(scc,''))
		ENDIF
	ENDIF
	IF llS AND llT AND ABS(lnTS - 1098.30) < 0.01 AND ABS(lnTSV - 210.00) < 0.01 AND lcTScc == '401' AND lcTPartc == 'BIROUL VAMAL'
		lcMsg = 'PASS DVI-principal(dupa spargere) nract=15000: T_DVI(nr_doc=' + TRANSFORM(lnNrDocCrt) + ' scc=' + lcTScc + ' partc=' + lcTPartc + ' suma=' + TRANSFORM(lnTS) + ' suma_val=' + TRANSFORM(lnTSV) + ')'
	ELSE
		lcMsg = 'FAIL DVI-principal(dupa spargere) nract=15000: S?=' + TRANSFORM(llS) + ' T?=' + TRANSFORM(llT) + ' scc=' + lcTScc + '(astept 401) partc=' + lcTPartc + '(astept BIROUL VAMAL) suma=' + TRANSFORM(IIF(llT,lnTS,-1)) + '(astept 1098.30) suma_val=' + TRANSFORM(IIF(llT,lnTSV,-1)) + '(astept 210.00)'
	ENDIF
	DO DcLog WITH lcMsg
	SELECT (lnSel)
ENDPROC

PROCEDURE VerificaDvi
	*-- randul T e re-cheiat pe documentul vamal (nract/fdoc/id_fdoc/partc devin cele ale DVI-ului
	*-- 100/BIROUL VAMAL pt. TOATE documentele cu ramura 'D') - nract/fdoc NU mai disting T-urile
	*-- intre ele (colizie); disting prin nr_doc (nemodificat de ramura DVI), obtinut de pe randul B
	*-- propriu al documentului (tnNract = nract-ul FACTURII, neatins).
	LPARAMETERS tnNract, tnNractDvi, tnBazaLei, tnTvaLei, tnTvaVal
	LOCAL lnSel, lcMsg, llB, llT, lnBS, lnTS, lnTSV, lcTPartc, llVama, lnNrDocCrt
	lnSel = SELECT()
	SELECT introdc
	LOCATE FOR nract = tnNract AND tip_rand == 'B'
	llB = FOUND()
	IF llB
		lnBS = suma
		lnNrDocCrt = nr_doc
	ENDIF
	llT = .F.
	IF llB
		LOCATE FOR nr_doc = lnNrDocCrt AND tip_rand == 'T'
		llT = FOUND()
		IF llT
			lnTS = suma
			lnTSV = suma_val
			lcTPartc = ALLTRIM(NVL(partc,''))
			llVama = ('VAMAL' $ UPPER(lcTPartc)) AND nract = tnNractDvi
		ENDIF
	ENDIF
	IF llB AND llT AND ABS(lnBS - tnBazaLei) < 0.01 AND ABS(lnTS - tnTvaLei) < 0.01 AND ABS(lnTSV - tnTvaVal) < 0.01 AND llVama
		lcMsg = 'PASS DVI nract=' + TRANSFORM(tnNract) + ': B(suma=' + TRANSFORM(lnBS) + ') + T_DVI(nr_doc=' + TRANSFORM(lnNrDocCrt) + ' partc=' + lcTPartc + ' suma=' + TRANSFORM(lnTS) + ' suma_val=' + TRANSFORM(lnTSV) + ')'
	ELSE
		lcMsg = 'FAIL DVI nract=' + TRANSFORM(tnNract) + ': B(suma=' + TRANSFORM(IIF(llB,lnBS,-1)) + ', astept ' + TRANSFORM(tnBazaLei) + ') T_DVI(suma=' + TRANSFORM(IIF(llT,lnTS,-1)) + ', astept ' + TRANSFORM(tnTvaLei) + ' suma_val=' + TRANSFORM(IIF(llT,lnTSV,-1)) + ', astept ' + TRANSFORM(tnTvaVal) + ' partc=' + IIF(llT,lcTPartc,'?') + ')'
	ENDIF
	DO DcLog WITH lcMsg
	SELECT (lnSel)
ENDPROC

PROCEDURE VerificaRandTNormalF
	*-- doc3 (ramura 'F', TVA normal): T-ul propriu (nu referinta DVI), scd/scc/ptva/suma/explicatie.
	*-- doc3.B e unic identificabil (nract=100+tip_rand=B+fdoc=DVI - singurul document care e chiar
	*-- 'DVI 100'); T-ul lui se cauta prin nr_doc (nract-ul T-ului ar coincide cu al T-urilor
	*-- doc1/doc2 dupa ramura 'D' a acelora - colizie, vezi VerificaDvi).
	LPARAMETERS tnNract, tcScdAsteptat, tcSccAsteptat, tnPtvaAsteptat, tnSumaAsteptata, tcExplicatieAsteptata
	LOCAL lnSel, lcMsg, llB, llT, lnNrDocCrt
	lnSel = SELECT()
	SELECT introdc
	LOCATE FOR nract = tnNract AND ALLTRIM(fdoc) == 'DVI' AND tip_rand == 'B'
	llB = FOUND()
	llT = .F.
	IF llB
		lnNrDocCrt = nr_doc
		LOCATE FOR nr_doc = lnNrDocCrt AND tip_rand == 'T'
		llT = FOUND()
	ENDIF
	IF llT AND ALLTRIM(scd) == tcScdAsteptat AND ALLTRIM(scc) == tcSccAsteptat AND ABS(ptva - tnPtvaAsteptat) < 0.01 ;
			AND ABS(suma - tnSumaAsteptata) < 0.01 AND ALLTRIM(explicatie_tva) == tcExplicatieAsteptata
		lcMsg = 'PASS r9-randT-doc3(F): scd=' + ALLTRIM(scd) + ' scc=' + ALLTRIM(scc) + ' ptva=' + TRANSFORM(ptva) + ;
			' suma=' + TRANSFORM(suma) + ' explicatie=[' + ALLTRIM(explicatie_tva) + '] - TOATE OK (scc NU e 4427)'
	ELSE
		IF llT
			lcMsg = 'FAIL r9-randT-doc3(F): scd=[' + ALLTRIM(scd) + '](astept [' + tcScdAsteptat + ']) scc=[' + ALLTRIM(scc) + '](astept [' + tcSccAsteptat + ']) ' + ;
				'ptva=' + TRANSFORM(ptva) + '(astept ' + TRANSFORM(tnPtvaAsteptat) + ') suma=' + TRANSFORM(suma) + '(astept ' + TRANSFORM(tnSumaAsteptata) + ') ' + ;
				'explicatie=[' + ALLTRIM(explicatie_tva) + '](astept [' + tcExplicatieAsteptata + '])'
		ELSE
			lcMsg = 'FAIL r9-randT-doc3(F): nu am gasit randul T pentru nract=' + TRANSFORM(tnNract) + ' fdoc=DVI'
		ENDIF
	ENDIF
	DO DcLog WITH lcMsg
	SELECT (lnSel)
ENDPROC

PROCEDURE VerificaDocKeyUnice
	*-- toate documentele (B/S/T grupate pe doc_key) au prefix nr_doc distinct.
	LPARAMETERS tnDocumenteAsteptate
	LOCAL lnSel, lcMsg, lnDistinct
	lnSel = SELECT()
	SELECT DISTINCT nr_doc FROM introdc WHERE !DELETED() INTO CURSOR crsDocKeyDistinct NOFILTER
	lnDistinct = RECCOUNT('crsDocKeyDistinct')
	USE IN crsDocKeyDistinct
	IF lnDistinct >= tnDocumenteAsteptate
		lcMsg = 'PASS r9-doc_key-unic: ' + TRANSFORM(lnDistinct) + ' valori nr_doc distincte (>= ' + TRANSFORM(tnDocumenteAsteptate) + ' asteptate)'
	ELSE
		lcMsg = 'FAIL r9-doc_key-unic: ' + TRANSFORM(lnDistinct) + ' valori nr_doc distincte (astept >= ' + TRANSFORM(tnDocumenteAsteptate) + ')'
	ENDIF
	DO DcLog WITH lcMsg
	SELECT (lnSel)
ENDPROC

PROCEDURE VerificaAnalitic
	*-- r8: randul S pe cont+ascd (analiticul articolului), suma_val = baza articolului in valuta.
	LPARAMETERS tcCont, tcAscdAsteptat, tnBazaValAsteptata, tcLabel
	LOCAL lnSel, lcMsg, llS
	lnSel = SELECT()
	SELECT introdc
	LOCATE FOR tip_rand == 'S' AND ALLTRIM(scd) == tcCont
	llS = FOUND()
	IF llS AND ALLTRIM(NVL(ascd,'')) == tcAscdAsteptat AND ABS(suma_val - tnBazaValAsteptata) < 0.01
		lcMsg = 'PASS ' + tcLabel + ': rand S cont=' + tcCont + ' ascd=[' + ALLTRIM(ascd) + '] suma_val=' + TRANSFORM(suma_val) + ' - OK'
	ELSE
		IF llS
			lcMsg = 'FAIL ' + tcLabel + ': rand S cont=' + tcCont + ' ascd=[' + ALLTRIM(NVL(ascd,'')) + '](astept [' + tcAscdAsteptat + ']) suma_val=' + TRANSFORM(suma_val) + '(astept ' + TRANSFORM(tnBazaValAsteptata) + ')'
		ELSE
			lcMsg = 'FAIL ' + tcLabel + ': nu exista rand S cu cont=' + tcCont
		ENDIF
	ENDIF
	DO DcLog WITH lcMsg
	SELECT (lnSel)
ENDPROC

PROCEDURE VerificaProcente
	*-- cauta pe B SAU S (documentul principal - doc1 - nu mai are B dupa spargere, dec.9;
	*-- explicatia4/5 se scriu si pe S-urile lui in sincronizeaza(), Scan For Inlist('B','S')).
	LPARAMETERS tnNract, tcExplicatia4Asteptata, tcExplicatia5Asteptata, tcLabel
	LOCAL lnSel, lcMsg, llB
	lnSel = SELECT()
	SELECT introdc
	LOCATE FOR nract = tnNract AND INLIST(tip_rand,'B','S')
	llB = FOUND()
	IF llB AND ALLTRIM(NVL(explicatia4,'')) == tcExplicatia4Asteptata AND ALLTRIM(NVL(explicatia5,'')) == tcExplicatia5Asteptata
		lcMsg = 'PASS r11-procente ' + tcLabel + ' (nract=' + TRANSFORM(tnNract) + '): explicatia4=[' + ALLTRIM(explicatia4) + '] explicatia5=[' + ALLTRIM(explicatia5) + '] - OK'
	ELSE
		IF llB
			lcMsg = 'FAIL r11-procente ' + tcLabel + ' (nract=' + TRANSFORM(tnNract) + '): explicatia4=[' + ALLTRIM(NVL(explicatia4,'')) + '](astept [' + tcExplicatia4Asteptata + ']) explicatia5=[' + ALLTRIM(NVL(explicatia5,'')) + '](astept [' + tcExplicatia5Asteptata + '])'
		ELSE
			lcMsg = 'FAIL r11-procente ' + tcLabel + ': nu am gasit randul B pentru nract=' + TRANSFORM(tnNract)
		ENDIF
	ENDIF
	DO DcLog WITH lcMsg
	SELECT (lnSel)
ENDPROC

PROCEDURE VerificaStergereDoc3Doar
	*-- anti-regresie: dupa stergerea doc3 (raspuns6), doar B+T ale doc3 (nract=100/fdoc=DVI/tip B -
	*-- identitate unica, randurile B nu sunt rescrise de ramura DVI a celorlalte documente) trebuie
	*-- sa fi disparut; randurile T ale doc1/doc2 (gasite prin nr_doc-ul PROPRIU al fiecaruia, luat de
	*-- pe randul B - nract-ul T-ului e rescris pe identitatea vamii si colizioneaza intre documente,
	*-- vezi VerificaDvi) raman INTACTE.
	LPARAMETERS tcLabel
	LOCAL lnSel, lcMsg, llDoc3BExista, llDoc1TExista, llDoc2TExista, lnNrDoc1, lnNrDoc2
	lnSel = SELECT()
	SELECT introdc
	LOCATE FOR nract = 100 AND ALLTRIM(fdoc) == 'DVI' AND id_fdoc = 2 AND tip_rand == 'B'
	llDoc3BExista = FOUND()
	*-- doc1 e principalul: la acest punct din scenariu B-ul lui deja a disparut (dec.9, dupa
	*-- spargere) - nr_doc se ia de pe un rand S (pastreaza nract-ul original).
	LOCATE FOR nract = 15000 AND tip_rand == 'S'
	llDoc1TExista = FOUND()
	IF llDoc1TExista
		lnNrDoc1 = nr_doc
		LOCATE FOR nr_doc = lnNrDoc1 AND tip_rand == 'T'
		llDoc1TExista = FOUND()
	ENDIF
	LOCATE FOR nract = 12000 AND tip_rand == 'B'
	llDoc2TExista = FOUND()
	IF llDoc2TExista
		lnNrDoc2 = nr_doc
		LOCATE FOR nr_doc = lnNrDoc2 AND tip_rand == 'T'
		llDoc2TExista = FOUND()
	ENDIF
	IF !llDoc3BExista AND llDoc1TExista AND llDoc2TExista
		lcMsg = 'PASS ' + tcLabel + ': doc3 (B propriu) a disparut, doc1/doc2 (inclusiv T-ul cu DVI 100) raman intacte'
	ELSE
		lcMsg = 'FAIL ' + tcLabel + ': doc3B_existaInca=' + TRANSFORM(llDoc3BExista) + '(astept .F.) doc1T_exista=' + TRANSFORM(llDoc1TExista) + '(astept .T.) doc2T_exista=' + TRANSFORM(llDoc2TExista) + '(astept .T.)'
	ENDIF
	DO DcLog WITH lcMsg
	SELECT (lnSel)
ENDPROC

PROCEDURE VerificaCopiereDocument
	*-- dupa do_copiaza_nota (raspuns6, sursa=doc2 TRANS OIL): document nou (nr_doc > maxim anterior),
	*-- doar randuri B+T (fara S), CONTINUT identic cu sursa (B: suma=1000/fdoc=Factura/partc=TRANS OIL;
	*-- T: suma=210/partc=BIROUL VAMAL), doc_key nou DISTINCT de al sursei, sursa (nr_doc=2) neatinsa.
	LPARAMETERS tnMaxNrDocInainte, tnRandInainte
	LOCAL lnSel, lcMsg, lnMaxNrDocDupa, lnRandDupa, llAreBNou, llAreTNou, llAreSNou, lnDocKeyDupl
	LOCAL llContinutOk, lcDocKeyNou, lcDocKeySursa, llDocKeyDistinct, llSursaIntacta
	lnSel = SELECT()
	SELECT introdc
	lnMaxNrDocDupa = 0
	CALCULATE MAX(IIF(NVL(nr_doc,0) = 99999999, 0, NVL(nr_doc,0))) TO lnMaxNrDocDupa
	COUNT TO lnRandDupa FOR !DELETED()
	SELECT introdc
	LOCATE FOR nr_doc = lnMaxNrDocDupa AND tip_rand == 'B'
	llAreBNou = FOUND()
	llContinutOk = .F.
	IF llAreBNou
		lcDocKeyNou = doc_key
		llContinutOk = ALLTRIM(fdoc) == 'Factura' AND ABS(suma - 1000) < 0.01 AND ALLTRIM(NVL(partc,'')) == 'TRANS OIL' AND nract = 12000
	ENDIF
	SELECT introdc
	LOCATE FOR nr_doc = lnMaxNrDocDupa AND tip_rand == 'T'
	llAreTNou = FOUND()
	IF llAreTNou
		llContinutOk = llContinutOk AND ABS(suma - 210) < 0.01 AND ('VAMAL' $ UPPER(ALLTRIM(NVL(partc,''))))
	ENDIF
	SELECT introdc
	LOCATE FOR nr_doc = lnMaxNrDocDupa AND tip_rand == 'S'
	llAreSNou = FOUND()
	SELECT COUNT(*) AS n FROM introdc WHERE !DELETED() AND nr_doc = lnMaxNrDocDupa INTO CURSOR crsDocNouCnt NOFILTER
	lnDocKeyDupl = crsDocNouCnt.n
	USE IN crsDocNouCnt
	*-- doc_key distinct fata de sursa (doc2, nr_doc=2) + sursa neatinsa (suma tot 1000/TRANS OIL)
	SELECT introdc
	LOCATE FOR nr_doc = 2 AND tip_rand == 'B'
	llSursaIntacta = FOUND() AND ABS(suma - 1000) < 0.01 AND ALLTRIM(NVL(partc,'')) == 'TRANS OIL'
	lcDocKeySursa = IIF(FOUND(), doc_key, '?')
	llDocKeyDistinct = !EMPTY(lcDocKeyNou) AND ALLTRIM(lcDocKeyNou) != ALLTRIM(lcDocKeySursa)
	IF lnMaxNrDocDupa > tnMaxNrDocInainte AND lnRandDupa = tnRandInainte + 2 AND llAreBNou AND llAreTNou AND !llAreSNou ;
			AND lnDocKeyDupl = 2 AND llContinutOk AND llDocKeyDistinct AND llSursaIntacta
		lcMsg = 'PASS r10-copiere-document(raspuns6): document nou nr_doc=' + TRANSFORM(lnMaxNrDocDupa) + ' (>' + TRANSFORM(tnMaxNrDocInainte) + '), +2 randuri (B 1000/Factura/TRANS OIL + T 210/BIROUL VAMAL, fara S), doc_key nou distinct de sursa, sursa (nr_doc=2) neatinsa'
	ELSE
		lcMsg = 'FAIL r10-copiere-document(raspuns6): maxNrDoc ' + TRANSFORM(tnMaxNrDocInainte) + '->' + TRANSFORM(lnMaxNrDocDupa) + ' randuri ' + TRANSFORM(tnRandInainte) + '->' + TRANSFORM(lnRandDupa) + ' (astept +2) areB=' + TRANSFORM(llAreBNou) + ' areT=' + TRANSFORM(llAreTNou) + ' areS=' + TRANSFORM(llAreSNou) + '(astept .F.) randuriPeDocNou=' + TRANSFORM(lnDocKeyDupl) + '(astept 2) continutOk=' + TRANSFORM(llContinutOk) + '(astept .T.) doc_keyDistinct=' + TRANSFORM(llDocKeyDistinct) + '(astept .T.) sursaIntacta=' + TRANSFORM(llSursaIntacta) + '(astept .T.)'
	ENDIF
	DO DcLog WITH lcMsg
	SELECT (lnSel)
ENDPROC

PROCEDURE VerificaCopiereLinieContinut
	*-- dupa do_copiaza_nota (raspuns7, sursa=doc2.B TRANS OIL): randul nou trebuie sa fie o COPIE
	*-- reala a sursei (tip_rand='B', nract=12000, fdoc='Factura', suma=1000, partc='TRANS OIL'),
	*-- cu nr_doc nou si doc_key nou distinct de sursa - NU un rand gol (bug runda12: Calculate Max
	*-- muta pointerul pe EOF inainte de Scatter pe ramura "copie linie" a do_copiaza_nota).
	LPARAMETERS tcLabel
	LOCAL lnSel, lcMsg, lnMaxNrDoc, llGasit, llContinutOk, lcDocKeyNou, lcDocKeySursa, llDocKeyDistinct
	lnSel = SELECT()
	SELECT introdc
	lnMaxNrDoc = 0
	CALCULATE MAX(IIF(NVL(nr_doc,0) = 99999999, 0, NVL(nr_doc,0))) TO lnMaxNrDoc
	SELECT introdc
	LOCATE FOR nr_doc = lnMaxNrDoc AND tip_rand == 'B'
	llGasit = FOUND()
	llContinutOk = .F.
	IF llGasit
		lcDocKeyNou = doc_key
		llContinutOk = ALLTRIM(fdoc) == 'Factura' AND nract = 12000 AND ABS(suma - 1000) < 0.01 AND ALLTRIM(NVL(partc,'')) == 'TRANS OIL'
	ENDIF
	SELECT introdc
	LOCATE FOR nr_doc = 2 AND tip_rand == 'B'
	lcDocKeySursa = IIF(FOUND(), doc_key, '?')
	llDocKeyDistinct = llGasit AND !EMPTY(lcDocKeyNou) AND ALLTRIM(lcDocKeyNou) != ALLTRIM(lcDocKeySursa)
	IF llGasit AND llContinutOk AND llDocKeyDistinct
		lcMsg = 'PASS ' + tcLabel + ': randul nou (nr_doc=' + TRANSFORM(lnMaxNrDoc) + ') e copie reala a sursei (fdoc=Factura nract=12000 suma=1000 partc=TRANS OIL), doc_key nou distinct'
	ELSE
		lcMsg = 'FAIL ' + tcLabel + ': randul nou NU e o copie reala a sursei - gasit=' + TRANSFORM(llGasit) + ' continutOk=' + TRANSFORM(llContinutOk) + '(astept .T., verifica fdoc/nract/suma/partc) doc_keyDistinct=' + TRANSFORM(llDocKeyDistinct)
	ENDIF
	DO DcLog WITH lcMsg
	SELECT (lnSel)
ENDPROC

PROCEDURE DumpIntrodc
	LOCAL lnSel
	lnSel = SELECT()
	SELECT introdc
	SCAN
		DO DcLog WITH '  recno=' + TRANSFORM(RECNO()) + ' nr_doc=' + TRANSFORM(NVL(nr_doc,0)) + ' nract=' + TRANSFORM(nract) + ' fdoc=[' + ALLTRIM(NVL(fdoc,'')) + '] tip_rand=' + tip_rand + ;
			' scd=' + ALLTRIM(scd) + ' ascd=[' + ALLTRIM(NVL(ascd,'')) + '] scc=' + ALLTRIM(scc) + ' ptva=' + TRANSFORM(ptva) + ' suma=' + TRANSFORM(suma) + ' suma_val=' + TRANSFORM(suma_val) + ;
			' partc=[' + ALLTRIM(NVL(partc,'')) + '] expl4=[' + ALLTRIM(NVL(explicatia4,'')) + '] expl5=[' + ALLTRIM(NVL(explicatia5,'')) + '] 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 DcErr
	LPARAMETERS tnErr, tcMsg, tcProg, tnLine
	DO DcLog WITH 'ON ERROR ' + TRANSFORM(tnErr) + ' [' + tcProg + ':' + TRANSFORM(tnLine) + '] ' + tcMsg
ENDPROC

PROCEDURE DcLog
	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
		*-- update_jtva_coloane (SELECT * FROM vjtva_coloane ...): mock cu date reale.
		IF 'VJTVA_COLOANE' $ UPPER(m.tcSql)
			DO CreeazaJtvaColoaneView WITH m.tcCursor
			RETURN 1
		ENDIF
		*-- rul_temp (recreat de import_nota.Init din vrul cand e gol): structura completa.
		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
		*-- assign_analitic (creeaza_rand_s / do_adauga_articol): config_analitice - prefix/sufix goale,
		*-- deci acont-ul vine direct din fconturi_analitice (mai jos), controlat de gcMockAcontCrt.
		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
		*-- fconturi_analitice: acont-ul curent, setat explicit de test (gcMockAcontCrt) inainte de
		*-- fiecare do_adauga_articol() - simplu si deterministic, fara sa depinda de binding real.
		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
		*-- vplcont_analitic: validare analitic vs plan de conturi - un rand => acontul e "valid".
		IF 'VPLCONT_ANALITIC' $ UPPER(m.tcSql)
			CREATE CURSOR (m.tcCursor) (cont C(10), acont C(20))
			INSERT INTO (m.tcCursor) VALUES ('212', '1')
			INSERT INTO (m.tcCursor) VALUES ('371', '4')
			RETURN 1
		ENDIF
		*-- ramura generica: cursor gol (nu afecteaza fluxurile testate mai sus).
		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'
				*-- coloana_jc 'FO21T' (import) NU se potriveste patternurilor TI%T/XX%TIT/CE%T -
				*-- cursor gol => scc ramane '401' (nu 4427) - vezi Init:11251-11258.
				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
