* test_taxcode_scc_aliniere.prg
* aliniaza_tva_la_baza (COMUN\clase\ointroduceri.vcx, import_nota) reface taxcode (SAFT) si
* comutarea scc/ascc 4427/creditor S pe randurile T realiniate la familia S-ului. Scenariul se
* produce integral prin fluxul REAL de utilizator (model: test_repro_tva11_explicatie.prg):
*   factura de import DVI (21%), 2 articole (21% si 11%), sincronizare, apoi pe randul S de 11%:
*   1. dublu-click Explicatie TVA -> alege familia CE (taxare inversa, eligibila 4427) ->
*      dupa resincronizare T(11%) trebuie sa aiba scc='4427', ascc=''.
*   2. editare manuala S(11%).scc/ascc prin Grid1.cScc/cAscc.Text1 (ca in test_tva_creditori.prg)
*      la un creditor DIFERIT de '401' -> T(11%) ramane pe scc='4427' (regula 4427 domina
*      creditorul, cat timp familia e eligibila).
*   3. dublu-click Explicatie TVA din nou -> revine la familia documentului (FO, neeligibila
*      4427) -> T(11%) trebuie sa revina la creditorul CURENT al S(11%) (cel editat la pasul 2,
*      NU '401' fix - vezi TVA pe creditori).
* taxcode (SAFT, gl406 activ) verificat la fiecare pas cu valoarea EXACTA din nomenclator.
*
* Rulare: powershell -ExecutionPolicy Bypass -File test_taxcode_scc_aliniere.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_taxcode_scc_aliniere_log.txt"
gcSyncDir = "D:\ROA\ROAGEST\COMUN\utile\Teste\achizitie_import\uisync_taxcode_scc_aliniere\"
STRTOFILE("START " + TTOC(DATETIME()) + CHR(13)+CHR(10), gcUILog)

ON ERROR DO TvErr 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 TvLog 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 TvLog 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\mock_cauta_nom_articole.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\achizitie_import\mock_cauta_alfa_tva11.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 TvLog WITH 'SET PROCEDURE OK'

	PUBLIC goMockValuta
	goMockValuta = CREATEOBJECT('Custom')
	goMockValuta.AddProperty('id_valuta', 978)
	goMockValuta.AddProperty('nume_val', 'EUR')

	*----- 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 gnTipGest
	gnTipGest = 0
	PUBLIC gnHandle
	gnHandle = -1
	PUBLIC gcTempPath
	gcTempPath = ADDBS(SYS(2023))
	PUBLIC gcCondSucursala
	gcCondSucursala = ''

	PUBLIC gnButon
	STORE 2 TO gnButon
	PUBLIC gcMockArtCodmat, gcMockAcontCrt
	gcMockArtCodmat = ''
	gcMockAcontCrt = ''
	PUBLIC gnMockRaspuns
	gnMockRaspuns = 6
	PUBLIC gcMockUltimMesaj, gnMockUltimTip
	gcMockUltimMesaj = ''
	gnMockUltimTip = 0
	*-- denumirea aleasa in dialogul de cautare explicatie TVA (mock_cauta_alfa_tva11.prg)
	PUBLIC gcTestTvaAlege
	gcTestTvaAlege = ''

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

	*----- poAct: antetul notei (moneda principala 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', 'MULTI SUPPLY 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: FO21B/T (220/221, familia documentului) + CE21CTB/T (226/227) +
	*      CE11CTB/T (232/233, familia CE 11% - eligibila 4427). FO11B/T (236/237, familia
	*      documentului la 11% - NEeligibila 4427) LIPSESC deliberat aici (gol de nomenclator,
	*      ca in test_repro_tva11_explicatie.prg mod PRE) - se adauga mai jos, chiar inainte de
	*      PAS 5, cand utilizatorul "completeaza nomenclatorul" (vezi flux-achizitie-import.md).
	*      Fara acest gol, gaseste_jtva_cota ar rezolva cota 11% pe familia documentului la orice
	*      resincronizare si alegerea manuala (CE, branch A) nu ar mai ramane (nu exista protectie
	*      de tip expl_manual pe randul S, doar pe T). -----
	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, 220, 'ACH. IMP. 21%', 1, 0, 1, 'FO21B', 'FO21T', 21, 221)
	INSERT INTO jtva_coloane2 VALUES (2, 221, 'TVA ACH. IMP. 21%', 1, 0, 1, 'FO21T', '', 21, 0)
	INSERT INTO jtva_coloane2 VALUES (3, 226, 'ACH. BUNURI CE. 21% FURNIZOR INREGISTRAT TVA', 1, 0, 1, 'CE21CTB', 'CE21CTT', 21, 227)
	INSERT INTO jtva_coloane2 VALUES (4, 227, 'TVA ACH. BUNURI CE. 21% FURNIZOR INREGISTRAT TVA', 1, 0, 1, 'CE21CTT', '', 21, 0)
	INSERT INTO jtva_coloane2 VALUES (5, 232, 'ACH. BUNURI CE. 11% FURNIZOR INREGISTRAT TVA', 1, 0, 1, 'CE11CTB', 'CE11CTT', 11, 233)
	INSERT INTO jtva_coloane2 VALUES (6, 233, 'TVA ACH. BUNURI CE. 11% FURNIZOR INREGISTRAT TVA', 1, 0, 1, 'CE11CTT', '', 11, 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)
	INSERT INTO saft_taxtable (taxname, taxcode, descriere, procent_taxa, tva, wht, tva_achizitii, tva_livrari) ;
		VALUES ('301205-Import de bunuri cota 11%', 301205, '', 11, 1, 0, 1, 0)
	INSERT INTO saft_taxtable (taxname, taxcode, descriere, procent_taxa, tva, wht, tva_achizitii, tva_livrari) ;
		VALUES ('300704-Achizitii de bunuri CE 21%', 300704, '', 21, 1, 0, 1, 0)
	INSERT INTO saft_taxtable (taxname, taxcode, descriere, procent_taxa, tva, wht, tva_achizitii, tva_livrari) ;
		VALUES ('300705-Achizitii de bunuri CE 11%', 300705, '', 11, 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', 220, 21, 'ACH. IMP. 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', 221, 21, 'TVA ACH. IMP. 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)

	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

	*----- goDlgTva11: formularul REAL cauta_alfa_form pentru dialogul de explicatie TVA -----
	IF USED('crsTva11cauta')
		USE IN ('crsTva11cauta')
	ENDIF
	CREATE CURSOR crsTva11cauta (id_jtva_coloana N(14), denumire C(100), cota_tva N(6,2))
	INSERT INTO crsTva11cauta VALUES (232, 'ACH. BUNURI CE. 11% FURNIZOR INREGISTRAT TVA', 11)
	INSERT INTO crsTva11cauta VALUES (233, 'TVA ACH. BUNURI CE. 11% FURNIZOR INREGISTRAT TVA', 11)
	GO TOP

	PUBLIC goDlgTva11
	goDlgTva11 = CREATEOBJECT('cauta_alfa_form', 'crsTva11cauta', '', 'Explicatie TVA,Cota TVA', ;
		'denumire,cota_tva', .F., '', 1)
	goDlgTva11.crs_cursor = 'crsTva11cauta'
	goDlgTva11.cIdColumn = 'id_jtva_coloana'
	goDlgTva11.WindowType = 0
	goDlgTva11.Show()
	DOEVENTS FORCE
	DO TvLog WITH 'goDlgTva11 construit (cauta_alfa_form REAL, mod single-select)'

	DO TvLog WITH 'cursoare pregatite, CREATEOBJECT(import_nota, .F.)'
	PUBLIC goObj
	goObj = CREATEOBJECT('IMPORT_nota', .F.)
	IF VARTYPE(goObj) <> 'O'
		DO TvLog 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

	*-- cJtvaCol4427: Init l-a creat gol (mock pe goExecutor.oExecuta) - il repopulez cu acelasi
	*-- filtru REAL folosit in productie, aplicat pe jtva_coloane2 (infrastructura de nomenclator,
	*-- nu pasul de flux testat): CE11CTT (233) si CE21CTT (227) se califica, FO11T/FO21T nu.
	IF USED('cJtvaCol4427')
		USE IN ('cJtvaCol4427')
	ENDIF
	SELECT id_jtva_coloana FROM jtva_coloane2 ;
		WHERE (coloana_jc LIKE 'TI%T' OR coloana_jc LIKE 'XX%TIT') ;
		OR (coloana_jc LIKE 'CE%T' AND coloana_jc NOT LIKE 'CE%FTT') ;
		INTO CURSOR cJtvaCol4427
	INDEX ON id_jtva_coloana TAG id_jtva
	DO TvLog WITH 'cJtvaCol4427 repopulat: ' + TRANSFORM(RECCOUNT('cJtvaCol4427')) + ' randuri (astept 2: 227,233)'

	PRIVATE pnAsserts, pnPass
	STORE 0 TO pnAsserts, pnPass

	*========================= PAS 1: FACTURA DE IMPORT, DVI, NOTE INITIAL PE 21% =========================
	PUBLIC goDlg, goT, gcDocKey1
	goDlg = CREATEOBJECT('import_adauga_factura', goObj)
	goDlg.cFelDoc = 'Factura'
	goDlg.nIdFdoc = 1
	goDlg.nNract = 19500
	goDlg.dDataAct = DATE()
	goDlg.nIdPartener = 601
	goDlg.cPartener = 'MULTI SUPPLY SRL'
	goDlg.cExplicatia = 'Import marfa multicota TVA scc/taxcode'
	goDlg.nSuma = 1500
	goDlg.nSumaLei = 0
	goDlg.nCurs = 5
	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 = 9519
	goDlg.dDviData = DATE()
	goDlg.nIdFdocDVI = 2
	goDlg.cFelDocDvi = 'DVI'
	goDlg.nDviIdPartener = 901
	goDlg.cDviPartener = 'DIRECTIA VAMALA'
	goDlg.nDviTvaLei = 1325.00
	goDlg.nDviTvaVal = 0
	goDlg.actualizeaza_stare_dvi()
	goDlg.WindowType = 0
	goDlg.Visible = .T.
	goDlg.Show()
	DOEVENTS FORCE
	DO TvLog WITH 'valideaza = ' + TRANSFORM(goDlg.valideaza())

	goT = CREATEOBJECT('Empty')
	=ADDPROPERTY(goT,'serie_act','')
	=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',ROUND(goDlg.nSuma*goDlg.nCurs,gnPC))
	=ADDPROPERTY(goT,'suma_val',goDlg.nSuma)
	=ADDPROPERTY(goT,'in_valuta',goDlg.chkInValutaCont.Value)
	=ADDPROPERTY(goT,'participa_valuta',.T.)
	=ADDPROPERTY(goT,'id_valuta',goDlg.nIdValuta)
	=ADDPROPERTY(goT,'curs',goDlg.nCurs)
	=ADDPROPERTY(goT,'nume_val',ALLTRIM(NVL(goDlg.cValuta,'')))
	=ADDPROPERTY(goT,'cTipTva','D')
	=ADDPROPERTY(goT,'id_jtva_coloana',goDlg.nIdExplicatieTva)
	=ADDPROPERTY(goT,'dvi_serie','')
	=ADDPROPERTY(goT,'dvi_nract',goDlg.nNractDvi)
	=ADDPROPERTY(goT,'dvi_dataact',DATE())
	=ADDPROPERTY(goT,'dvi_id_fdoc',2)
	=ADDPROPERTY(goT,'dvi_fdoc','DVI')
	=ADDPROPERTY(goT,'dvi_id_partc',901)
	=ADDPROPERTY(goT,'dvi_partc','DIRECTIA VAMALA')
	=ADDPROPERTY(goT,'dvi_scc','401')
	=ADDPROPERTY(goT,'dvi_tva_lei',1325.00)
	=ADDPROPERTY(goT,'dvi_tva_val',0)
	=ADDPROPERTY(goT,'dvi_in_valuta',.F.)
	=ADDPROPERTY(goT,'dvi_id_valuta',0)
	=ADDPROPERTY(goT,'dvi_curs',0)
	=ADDPROPERTY(goT,'dvi_nume_val','')
	=ADDPROPERTY(goT,'dvi_valuta_proprie',1)
	=ADDPROPERTY(goT,'disc_baza_lei',0)
	=ADDPROPERTY(goT,'disc_baza_val',0)

	LOCAL llOkAdauga
	llOkAdauga = goObj.do_adauga_factura(goT)
	=Assert3('1-do_adauga_factura(goT) reuseste', IIF(llOkAdauga,1,0), 1)
	goDlg.Hide()
	DOEVENTS FORCE

	SELECT introdc
	SET ORDER TO
	LOCATE FOR nract = 19500 AND tip_rand == 'B'
	IF FOUND()
		gcDocKey1 = ALLTRIM(NVL(doc_key,''))
	ENDIF
	SELECT introdc
	SET ORDER TO ord_doc

	DO HarnessStep WITH 0, 'factura DVI creata (note initial 21%), doc_key=' + gcDocKey1

	*========================= PAS 2: 2 ARTICOLE (21% si 11%) - defalcare pe cote la sincronizare =========================
	gcMockArtCodmat = 'ART-BULD-212'
	gcMockAcontCrt = ''
	TRY
		goObj.do_adauga_articol()
	CATCH TO loExcA1
		DO TvLog WITH 'EROARE do_adauga_articol (1, 21%) ' + TRANSFORM(loExcA1.ErrorNo) + ' [' + loExcA1.Message + ']'
	ENDTRY
	DOEVENTS FORCE
	SELECT rul_temp
	LOCATE FOR ALLTRIM(codmat) == 'ART-BULD-212'
	IF FOUND()
		REPLACE cant WITH 1, pret_val WITH 1000, pretd WITH 1000, pret WITH ROUND(1000*5,4), ;
			pret_lei WITH ROUND(1000*5,4), cota_tva WITH 21
	ENDIF

	gcMockArtCodmat = 'ART-A8-371'
	gcMockAcontCrt = '4'
	TRY
		goObj.do_adauga_articol()
	CATCH TO loExcA2
		DO TvLog WITH 'EROARE do_adauga_articol (2, 11%) ' + TRANSFORM(loExcA2.ErrorNo) + ' [' + loExcA2.Message + ']'
	ENDTRY
	DOEVENTS FORCE
	SELECT rul_temp
	LOCATE FOR ALLTRIM(codmat) == 'ART-A8-371'
	IF FOUND()
		REPLACE cant WITH 1, pret_val WITH 500, pretd WITH 500, pret WITH ROUND(500*5,4), ;
			pret_lei WITH ROUND(500*5,4), cota_tva WITH 11
	ENDIF
	goObj.gridart.Refresh()
	DOEVENTS FORCE

	=Assert3('2-doua articole in rul_temp (21% + 11%)', RECCOUNT_ACTIVE('rul_temp'), 2)

	DO HarnessStep WITH 1, 'articole (21% si 11%) adaugate'

	LOCAL llEroareSync1
	llEroareSync1 = .F.
	TRY
		goObj.sincronizeaza()
	CATCH TO loExcS1
		llEroareSync1 = .T.
		DO TvLog WITH 'EROARE sincronizeaza() #1 ' + TRANSFORM(loExcS1.ErrorNo) + ' [' + loExcS1.Message + ']'
	ENDTRY
	DOEVENTS FORCE
	=Assert3('3-sincronizeaza() #1 fara eroare VFP', IIF(llEroareSync1,0,1), 1)

	*-- baseline: FO11B/FO11T LIPSESC (gol de nomenclator, deliberat) - gaseste_jtva_cota nu
	*-- gaseste perechea de 11% in familia documentului (FO), deci S(11%) ramane cu explicatia
	*-- mostenita de la baza (21%) si T(11%) e posibil sa nu existe inca - doar diagnostic aici,
	*-- fara assert-uri (starea exacta conteaza mai putin decat rezultatul dupa alegerea manuala).
	DO TvLog WITH 'familii dupa sincronizare #1 (baseline, gol de nomenclator la 11%): S(11)=' + TRANSFORM(CampRand('S',11,'id_jtva_coloana')) + ' T(11)=' + TRANSFORM(CampRand('T',11,'id_jtva_coloana')) + ' T(11).scc=[' + CampRandC('T',11,'scc') + ']'

	DO HarnessStep WITH 2, 'sincronizare#1 (baseline, gol nomenclator): S(11)=' + TRANSFORM(CampRand('S',11,'id_jtva_coloana')) + ' T(11)=' + TRANSFORM(CampRand('T',11,'id_jtva_coloana'))

	*========================= PAS 3 (BRANCH A): dublu-click Explicatie TVA pe S(11%) -> familia CE (4427) =========================
	SELECT introdc
	LOCATE FOR ALLTRIM(NVL(doc_key,'')) == gcDocKey1 AND tip_rand == 'S' AND ptva == 11
	LOCAL llGasitS11
	llGasitS11 = FOUND()
	=Assert3('5-exista rand S cu ptva=11', IIF(llGasitS11,1,0), 1)

	IF llGasitS11
		gcTestTvaAlege = 'ACH. BUNURI CE. 11% FURNIZOR INREGISTRAT TVA'
		STORE 0 TO gnButon
		TRY
			goObj.grid1.cExplicatieTva.Text1.DblClick()
		CATCH TO loExcDbl1
			DO TvLog WITH 'EROARE DblClick (CE) ' + TRANSFORM(loExcDbl1.ErrorNo) + ' [' + loExcDbl1.Message + '] in ' + loExcDbl1.Procedure + ':' + TRANSFORM(loExcDbl1.LineNo)
		ENDTRY
		DOEVENTS FORCE
		goObj.sincronizeaza()
		DOEVENTS FORCE

		DO TvLog WITH 'dupa alegere CE + sincronizare#2: S(11)=' + TRANSFORM(CampRand('S',11,'id_jtva_coloana')) + ' T(11)=' + TRANSFORM(CampRand('T',11,'id_jtva_coloana')) + ' T(11).scc=[' + CampRandC('T',11,'scc') + '] T(11).ascc=[' + CampRandC('T',11,'ascc') + '] T(11).taxcode=' + TRANSFORM(CampRand('T',11,'taxcode'))
		*-- S(11%) revine la familia mostenita de la baza (220) la fiecare resincronizare (creeaza_rand_s
		*-- nu pastreaza o alegere manuala pe randul S - doar randul T are protectia expl_manual) -
		*-- comportament PREEXISTENT, nu obiectul acestui test; conteaza DOAR rezultatul pe randul T.
		=Assert3('7-T(11%) aliniat la familia CE (233/CE11CTT)', CampRand('T',11,'id_jtva_coloana'), 233)
		=Assert3('8-T(11%) familie 4427-eligibila -> scc=4427', IIF(CampRandC('T',11,'scc')=='4427',1,0), 1)
		=Assert3('9-T(11%) ascc golit cand scc=4427', IIF(EMPTY(CampRandC('T',11,'ascc')),1,0), 1)
		=Assert3('10-T(11%) taxcode recalculat (301205->300705, familia CE11)', CampRand('T',11,'taxcode'), 300705)
	ENDIF

	DO HarnessStep WITH 3, 'dupa alegere CE (4427): T(11)=' + TRANSFORM(CampRand('T',11,'id_jtva_coloana')) + ' scc=' + CampRandC('T',11,'scc')

	*========================= PAS 4: editare manuala S(11%).scc/ascc (creditor diferit de 401) =========================
	*-- ca in test_tva_creditori.prg: GotFocus (retine valoarea veche in Thisform.cOldVal),
	*-- schimba Value, apoi Valid() REAL (fara replicare manuala a logicii din spate).
	IF llGasitS11
		SELECT introdc
		LOCATE FOR ALLTRIM(NVL(doc_key,'')) == gcDocKey1 AND tip_rand == 'S' AND ptva == 11
		IF FOUND()
			goObj.Grid1.cScc.Text1.Value = scc
			goObj.Grid1.cScc.Text1.GotFocus()
			goObj.Grid1.cScc.Text1.Value = '407'
			TRY
				goObj.Grid1.cScc.Text1.Valid()
			CATCH TO loExcScc
				DO TvLog WITH 'EROARE Valid scc ' + TRANSFORM(loExcScc.ErrorNo) + ' [' + loExcScc.Message + ']'
			ENDTRY
			DOEVENTS FORCE

			SELECT introdc
			LOCATE FOR ALLTRIM(NVL(doc_key,'')) == gcDocKey1 AND tip_rand == 'S' AND ptva == 11
			goObj.Grid1.cAscc.Text1.Value = ascc
			goObj.Grid1.cAscc.Text1.GotFocus()
			goObj.Grid1.cAscc.Text1.Value = '9'
			TRY
				goObj.Grid1.cAscc.Text1.Valid()
			CATCH TO loExcAscc
				DO TvLog WITH 'EROARE Valid ascc ' + TRANSFORM(loExcAscc.ErrorNo) + ' [' + loExcAscc.Message + ']'
			ENDTRY
			DOEVENTS FORCE
		ENDIF
		goObj.sincronizeaza()
		DOEVENTS FORCE

		DO TvLog WITH 'dupa editare creditor S(11%) (407/9) + sincronizare#3: S(11).scc=[' + CampRandC('S',11,'scc') + '] T(11)=' + TRANSFORM(CampRand('T',11,'id_jtva_coloana')) + ' T(11).scc=[' + CampRandC('T',11,'scc') + '] T(11).ascc=[' + CampRandC('T',11,'ascc') + ']'
		=Assert3('11-S(11%).scc editat (407)', IIF(CampRandC('S',11,'scc')=='407',1,0), 1)
		=Assert3('12-T(11%) ramane pe familia CE (233) - editarea creditorului nu schimba explicatia', CampRand('T',11,'id_jtva_coloana'), 233)
		=Assert3('13-T(11%) ramane scc=4427 (regula 4427 domina creditorul S, cat timp familia e eligibila)', IIF(CampRandC('T',11,'scc')=='4427',1,0), 1)
	ENDIF

	DO HarnessStep WITH 4, 'dupa editare creditor S(11%): scc S=' + CampRandC('S',11,'scc') + ' T ramane 4427=' + TRANSFORM(IIF(CampRandC('T',11,'scc')=='4427',1,0))

	*-- "completarea nomenclatorului": FO11B/FO11T (236/237) devin disponibile - abia acum
	*-- utilizatorul poate alege familia documentului la 11% (nu exista mai devreme, vezi
	*-- comentariul de la crearea lui jtva_coloane2).
	INSERT INTO jtva_coloane2 VALUES (7, 236, 'ACH. IMP. 11%', 1, 0, 1, 'FO11B', 'FO11T', 11, 237)
	INSERT INTO jtva_coloane2 VALUES (8, 237, 'TVA ACH. IMP. 11%', 1, 0, 1, 'FO11T', '', 11, 0)
	SELECT crsTva11cauta
	INSERT INTO crsTva11cauta VALUES (236, 'ACH. IMP. 11%', 11)
	INSERT INTO crsTva11cauta VALUES (237, 'TVA ACH. IMP. 11%', 11)

	*========================= PAS 5 (BRANCH B): resincronizare (F5) dupa completarea nomenclatorului =========================
	*-- utilizatorul observa (cmesajsync/mesajul de nomenclator incomplet a disparut) ca lipsa a
	*-- fost rezolvata si reincearca sincronizarea (F5 - KeyPress -4 apeleaza direct sincronizeaza(),
	*-- vezi ointroduceri.vcx PROCEDURE KeyPress) - NU mai e nevoie de dublu-click, familia
	*-- documentului (FO) se rezolva acum natural pentru cota 11%, la fel ca la cota 21%.
	IF llGasitS11
		goObj.sincronizeaza()
		DOEVENTS FORCE

		DO TvLog WITH 'dupa completare nomenclator + sincronizare#4 (F5): S(11)=' + TRANSFORM(CampRand('S',11,'id_jtva_coloana')) + ' T(11)=' + TRANSFORM(CampRand('T',11,'id_jtva_coloana')) + ' T(11).scc=[' + CampRandC('T',11,'scc') + '] T(11).ascc=[' + CampRandC('T',11,'ascc') + '] T(11).taxcode=' + TRANSFORM(CampRand('T',11,'taxcode'))
		=Assert3('14-S(11%) revine la familia documentului (236/FO11B)', CampRand('S',11,'id_jtva_coloana'), 236)
		=Assert3('15-T(11%) aliniat la familia FO (237/FO11T)', CampRand('T',11,'id_jtva_coloana'), 237)
		=Assert3('16-T(11%) familie NEeligibila 4427 -> scc revine la creditorul S(11%) (407, NU 401 fix)', IIF(CampRandC('T',11,'scc')=='407',1,0), 1)
		=Assert3('17-T(11%) ascc revine la ascc-ul S(11%) (9)', IIF(CampRandC('T',11,'ascc')=='9',1,0), 1)
		=Assert3('18-T(11%) taxcode recalculat (300705->301205, familia FO11)', CampRand('T',11,'taxcode'), 301205)
	ENDIF

	DO HarnessStep WITH 5, 'dupa revenire la FO: T(11)=' + TRANSFORM(CampRand('T',11,'id_jtva_coloana')) + ' scc=' + CampRandC('T',11,'scc') + ' taxcode=' + TRANSFORM(CampRand('T',11,'taxcode'))

	*========================= PAS 6: al DOILEA dublu-click pe S(11%), familia FO (NEeligibila 4427) =========================
	*-- alegerea de pe randul S se aplica pe randurile T de ACEEASI cota si nu forteaza '401':
	*-- T(11%) isi pastreaza creditorul editat (407/9), T(21%) ramane neatins. Un creditor
	*-- suprascris aici PERSISTA - resincronizarea nu il repara, fiindca explicatia randului T
	*-- e deja cea corecta (aliniaza_tva_la_baza atinge scc doar cand schimba explicatia).
	LOCAL lnT21Expl, lcT21Scc, lnT21Taxcode
	lnT21Expl = CampRand('T',21,'id_jtva_coloana')
	lcT21Scc = CampRandC('T',21,'scc')
	lnT21Taxcode = CampRand('T',21,'taxcode')
	DO TvLog WITH 'baseline inainte de PAS 6: T(11).scc=[' + CampRandC('T',11,'scc') + '] T(21)=' + TRANSFORM(lnT21Expl) + ' T(21).scc=[' + lcT21Scc + '] T(21).taxcode=' + TRANSFORM(lnT21Taxcode)

	IF llGasitS11
		SELECT introdc
		LOCATE FOR ALLTRIM(NVL(doc_key,'')) == gcDocKey1 AND tip_rand == 'S' AND ptva == 11
		gcTestTvaAlege = 'ACH. IMP. 11%'
		STORE 0 TO gnButon
		*-- do_termin consuma formularul dialogului: se reconstruieste inaintea fiecarei alegeri
		goDlgTva11 = CREATEOBJECT('cauta_alfa_form', 'crsTva11cauta', '', 'Explicatie TVA,Cota TVA', ;
			'denumire,cota_tva', .F., '', 1)
		goDlgTva11.crs_cursor = 'crsTva11cauta'
		goDlgTva11.cIdColumn = 'id_jtva_coloana'
		goDlgTva11.WindowType = 0
		goDlgTva11.Show()
		DOEVENTS FORCE
		TRY
			goObj.grid1.cExplicatieTva.Text1.DblClick()
		CATCH TO loExcDbl2
			DO TvLog WITH 'EROARE DblClick #2 (FO) ' + TRANSFORM(loExcDbl2.ErrorNo) + ' [' + loExcDbl2.Message + '] in ' + loExcDbl2.Procedure + ':' + TRANSFORM(loExcDbl2.LineNo)
		ENDTRY
		DOEVENTS FORCE
		goObj.sincronizeaza()
		DOEVENTS FORCE

		DO TvLog WITH 'dupa dublu-click #2 (FO): T(11)=' + TRANSFORM(CampRand('T',11,'id_jtva_coloana')) + ' T(11).scc=[' + CampRandC('T',11,'scc') + '] T(11).ascc=[' + CampRandC('T',11,'ascc') + '] T(11).taxcode=' + TRANSFORM(CampRand('T',11,'taxcode')) + ' T(21)=' + TRANSFORM(CampRand('T',21,'id_jtva_coloana')) + ' T(21).scc=[' + CampRandC('T',21,'scc') + ']'
		=Assert3('19-T(11%) ramane pe perechea FO (237)', CampRand('T',11,'id_jtva_coloana'), 237)
		=Assert3('20-T(11%) pastreaza creditorul REAL al S(11%) (407, NU 401 fix)', IIF(CampRandC('T',11,'scc')=='407',1,0), 1)
		=Assert3('21-T(11%) pastreaza ascc-ul S(11%) (9)', IIF(CampRandC('T',11,'ascc')=='9',1,0), 1)
		=Assert3('22-T(11%) taxcode ramane al familiei FO11 (301205)', CampRand('T',11,'taxcode'), 301205)
		=Assert3('23-T(21%) neatins: explicatia ramane a familiei de 21%', CampRand('T',21,'id_jtva_coloana'), lnT21Expl)
		=Assert3('24-T(21%) neatins: taxcode ramane al cotei 21%', CampRand('T',21,'taxcode'), lnT21Taxcode)
		=Assert3('24a-T(21%) neatins: creditorul ramane al cotei lui, nu al randului T de 11%', IIF(CampRandC('T',21,'scc')==lcT21Scc,1,0), 1)
	ENDIF

	DO HarnessStep WITH 6, 'dublu-click #2 (FO): T(11).scc=' + CampRandC('T',11,'scc') + ' T(21)=' + TRANSFORM(CampRand('T',21,'id_jtva_coloana'))

	*========================= PAS 7: al TREILEA dublu-click pe S(11%) -> familia CE (eligibila 4427) =========================
	*-- cu nomenclatorul complet, cota 11% se rezolva la resincronizare pe familia documentului,
	*-- deci alegerea CE de pe randul S nu supravietuieste (randul S nu are protectie de tip
	*-- expl_manual); conteaza ca randul T ramane coerent cu S, cu creditorul lui, si ca randul
	*-- T de 21% nu e atins de trecerea prin 4427.
	IF llGasitS11
		SELECT introdc
		LOCATE FOR ALLTRIM(NVL(doc_key,'')) == gcDocKey1 AND tip_rand == 'S' AND ptva == 11
		gcTestTvaAlege = 'ACH. BUNURI CE. 11% FURNIZOR INREGISTRAT TVA'
		STORE 0 TO gnButon
		*-- do_termin consuma formularul dialogului: se reconstruieste inaintea fiecarei alegeri
		goDlgTva11 = CREATEOBJECT('cauta_alfa_form', 'crsTva11cauta', '', 'Explicatie TVA,Cota TVA', ;
			'denumire,cota_tva', .F., '', 1)
		goDlgTva11.crs_cursor = 'crsTva11cauta'
		goDlgTva11.cIdColumn = 'id_jtva_coloana'
		goDlgTva11.WindowType = 0
		goDlgTva11.Show()
		DOEVENTS FORCE
		TRY
			goObj.grid1.cExplicatieTva.Text1.DblClick()
		CATCH TO loExcDbl3
			DO TvLog WITH 'EROARE DblClick #3 (CE) ' + TRANSFORM(loExcDbl3.ErrorNo) + ' [' + loExcDbl3.Message + '] in ' + loExcDbl3.Procedure + ':' + TRANSFORM(loExcDbl3.LineNo)
		ENDTRY
		DOEVENTS FORCE
		goObj.sincronizeaza()
		DOEVENTS FORCE

		DO TvLog WITH 'dupa dublu-click #3 (CE): S(11)=' + TRANSFORM(CampRand('S',11,'id_jtva_coloana')) + ' T(11)=' + TRANSFORM(CampRand('T',11,'id_jtva_coloana')) + ' T(11).scc=[' + CampRandC('T',11,'scc') + '] T(21)=' + TRANSFORM(CampRand('T',21,'id_jtva_coloana')) + ' T(21).scc=[' + CampRandC('T',21,'scc') + ']'
		=Assert3('25-T(11%) coerent cu familia S(11%) dupa resincronizare (237)', CampRand('T',11,'id_jtva_coloana'), 237)
		=Assert3('26-T(11%) pastreaza creditorul S(11%) (407) dupa trecerea prin CE', IIF(CampRandC('T',11,'scc')=='407',1,0), 1)
		=Assert3('27-T(21%) neatins de trecerea prin 4427: explicatia ramane 221', CampRand('T',21,'id_jtva_coloana'), lnT21Expl)
		=Assert3('28-T(21%) neatins de trecerea prin 4427: taxcode ramane 301204', CampRand('T',21,'taxcode'), lnT21Taxcode)
		=Assert3('28a-T(21%) neatins de trecerea prin 4427: creditorul ramane al cotei lui', IIF(CampRandC('T',21,'scc')==lcT21Scc,1,0), 1)
	ENDIF

	DO HarnessStep WITH 7, 'dublu-click #3 (CE): T(11).scc=' + CampRandC('T',11,'scc') + ' T(21).taxcode=' + TRANSFORM(CampRand('T',21,'taxcode'))

	DO TvLog WITH 'dump introdc FINAL:'
	DO DumpIntrodc

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

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

CATCH TO loExc
	DO TvLog 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 DumpIntrodc
	LOCAL lnSel
	lnSel = SELECT()
	SELECT introdc
	SCAN
		DO TvLog WITH '  nract=' + TRANSFORM(NVL(nract,0)) + ' tip=' + tip_rand + ' scd=' + ALLTRIM(NVL(scd,'')) + ' scc=' + ALLTRIM(NVL(scc,'')) + ' ascc=' + ALLTRIM(NVL(ascc,'')) + ' ptva=' + TRANSFORM(NVL(ptva,0)) + ' id_jtva=' + TRANSFORM(NVL(id_jtva_coloana,0)) + ' taxcode=' + TRANSFORM(NVL(taxcode,0)) + ' expl=[' + ALLTRIM(NVL(explicatie_tva,'')) + ']'
	ENDSCAN
	SELECT (lnSel)
ENDPROC

PROCEDURE CreeazaRulTemp
	*-- structura reala a rul_temp (vezi ointroduceri.vc2:11030 si test_adauga_repere_212.prg) -
	*-- GridArt e legat de rul_temp prin RecordSource inca din Init, deci trebuie sa existe cu
	*-- schema completa INAINTE de CREATEOBJECT('IMPORT_nota',...), altfel bind-ul grilei ramane
	*-- pe schema minimala creata de mock (goExecutor.oExecute) si formularul nu mai ajunge la Show().
	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

FUNCTION CampRand
	LPARAMETERS tcTipRand, tnCota, tcCamp
	LOCAL lnSel, lnRec, lnVal
	lnSel = SELECT()
	SELECT introdc
	lnRec = IIF(EOF() OR BOF(), 0, RECNO())
	LOCATE FOR ALLTRIM(NVL(doc_key,'')) == gcDocKey1 AND tip_rand == tcTipRand AND ptva == tnCota
	lnVal = IIF(FOUND(), NVL(EVALUATE('introdc.' + tcCamp), 0), -1)
	IF BETWEEN(lnRec, 1, RECCOUNT('introdc'))
		GO lnRec
	ENDIF
	SELECT (lnSel)
	RETURN lnVal
ENDFUNC

FUNCTION CampRandC
	*-- varianta CampRand pentru campuri caracter (scc/ascc) - NVL numeric ar da eroare de tip.
	LPARAMETERS tcTipRand, tnCota, tcCamp
	LOCAL lnSel, lnRec, lcVal
	lnSel = SELECT()
	SELECT introdc
	lnRec = IIF(EOF() OR BOF(), 0, RECNO())
	LOCATE FOR ALLTRIM(NVL(doc_key,'')) == gcDocKey1 AND tip_rand == tcTipRand AND ptva == tnCota
	lcVal = IIF(FOUND(), ALLTRIM(NVL(EVALUATE('introdc.' + tcCamp), '')), '?')
	IF BETWEEN(lnRec, 1, RECCOUNT('introdc'))
		GO lnRec
	ENDIF
	SELECT (lnSel)
	RETURN lcVal
ENDFUNC

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 TvLog WITH '  PASS ' + tcLabel + ' (=' + TRANSFORM(tuActual) + ')'
	ELSE
		DO TvLog WITH '  FAIL ' + tcLabel + ' (actual=' + TRANSFORM(tuActual) + ' asteptat=' + TRANSFORM(tuExpected) + ')'
	ENDIF
ENDPROC

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

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

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 (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)
	INSERT INTO (m.tcCursor) (id_jtva_coloana, denumire, jc, jv, coloana_jc, cota_tva, id_tva, afisat, ordine, taxcode) ;
		VALUES (226, 'ACH. BUNURI CE. 21% FURNIZOR INREGISTRAT TVA', 1, 0, 'CE21CTB', 21, 227, 1, 5, 300704)
	INSERT INTO (m.tcCursor) (id_jtva_coloana, denumire, jc, jv, coloana_jc, cota_tva, afisat, ordine, taxcode) ;
		VALUES (227, 'TVA ACH. BUNURI CE. 21% FURNIZOR INREGISTRAT TVA', 1, 0, 'CE21CTT', 21, 1, 6, 300704)
	INSERT INTO (m.tcCursor) (id_jtva_coloana, denumire, jc, jv, coloana_jc, cota_tva, id_tva, afisat, ordine, taxcode) ;
		VALUES (232, 'ACH. BUNURI CE. 11% FURNIZOR INREGISTRAT TVA', 1, 0, 'CE11CTB', 11, 233, 1, 7, 300705)
	INSERT INTO (m.tcCursor) (id_jtva_coloana, denumire, jc, jv, coloana_jc, cota_tva, afisat, ordine, taxcode) ;
		VALUES (233, 'TVA ACH. BUNURI CE. 11% FURNIZOR INREGISTRAT TVA', 1, 0, 'CE11CTT', 11, 1, 8, 300705)
	INSERT INTO (m.tcCursor) (id_jtva_coloana, denumire, jc, jv, coloana_jc, cota_tva, id_tva, afisat, ordine, taxcode) ;
		VALUES (236, 'ACH. IMP. 11%', 1, 0, 'FO11B', 11, 237, 1, 39, 301205)
	INSERT INTO (m.tcCursor) (id_jtva_coloana, denumire, jc, jv, coloana_jc, cota_tva, afisat, ordine, taxcode) ;
		VALUES (237, 'TVA ACH. IMP. 11%', 1, 0, 'FO11T', 11, 1, 40, 301205)
ENDPROC

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)
			CREATE CURSOR (m.tcCursor) (cont C(10), acont C(20))
			INSERT INTO (m.tcCursor) VALUES ('371', '4')
			RETURN 1
		ENDIF
		IF 'VCONFIG_CONT_IREG' $ UPPER(m.tcSql)
			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))
				INDEX ON id_jtva_coloana TAG id_jtva
			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

DEFINE CLASS dummyapp AS Custom
	cStartupMenu = ''
	PROCEDURE ReadIni
		LPARAMETERS tcSection, tcKey
		RETURN ''
	ENDPROC
	PROCEDURE WriteIni
		LPARAMETERS tcSection, tcKey, tcValue
		RETURN .T.
	ENDPROC
ENDDEFINE
