* test_repro_flux_curat_doc_dublu.prg
* Test de REPRODUCERE - FLUX CURAT, FARA nicio interactiune de grila (nu se cheama
* Grid1.cNract.Text1.Valid() si nu se cheama copiaza_valoare() manual din test). Raspunde la
* intrebarea: se strica SINGUR nract-ul facturii principale (DOC1) in timpul fluxului real -
* dialog import_adauga_factura (x2 documente) + do_adauga_articol() + sincronizeaza() +
* inainte_de_do_termin() - sau ramane corect pana la Terminat, asa cum a raportat Marius?
*
* Scenariu (date reale, act.cod=1140856):
*   DOC1 - factura principala: nract=15000, id_fdoc=42 (Factura), id_partc=463 (RAJA), in
*     valuta EUR (curs 5.23), suma=1000 EUR=5230 lei, discount financiar 100 EUR=523 lei;
*     TVA pe DVI (nract=101, id_fdoc=39 'DVI', id_partc=1398 'BIROUL VAMAL'), DVI FARA valuta
*     proprie (bifa scoasa - alegere RON prin picker-ul real, normalizata "fara valuta").
*   DOC2 - taxe vamale: nract=101, id_fdoc=39 (DVI), id_partc=1398 (BIROUL VAMAL), FARA
*     valuta, suma=500 lei, TVA la FURNIZOR (nu pe DVI) cota 11%, participa la pret.
*   ARTICOLE (2, ale DOC1): cont 371 analitic 816, un articol cota 11% (baza 100 EUR/523 lei)
*     si unul cota 21% (baza 900 EUR/4707 lei) - proportie 100:900, ca sa se exercite
*     sparge_tva_protejat() (randul T-DVI e "protejat" - valuta_proprie=1 - pentru ca factura
*     e in valuta straina, chiar daca DVI-ul insusi nu are valuta proprie).
*
* ATENTIE: DOC2 are ACELASI nract/id_fdoc/id_partc (101/39/1398) ca randul T-DVI al DOC1 (dupa
* ce acesta preia identitatea vamala) - testul verifica explicit ca doc_key nu se suprapune
* intre cele doua (calc_doc_key :8799 include nr_doc, care difera - vezi assert-urile finale).
*
* Dump complet introdc dupa fiecare pas (tip_rand, nr_doc, doc_key, nract, id_fdoc, id_partc,
* scd, scc, suma, suma_val, rand_dvi, valuta_proprie, mod_manual) + actactan dupa Terminat.
* Asserturile de identitate se fac dupa nr_doc (nu dupa nract, care e tocmai ce se verifica).
*
* Rulare:
*   powershell -ExecutionPolicy Bypass -File test_repro_flux_curat_doc_dublu.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_repro_flux_curat_doc_dublu_log.txt"
gcSyncDir = "D:\ROA\ROAGEST\COMUN\utile\Teste\achizitie_import\uisync_repro_flux_curat\"
STRTOFILE("START " + TTOC(DATETIME()) + CHR(13)+CHR(10), gcUILog)

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

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

	lcPath = gcAppPath + 'COMUN\Utile\Teste\achizitie_import\stub_verificare;' + ;
		gcAppPath + 'Date;' + gcAppPath + 'Include;' + gcAppPath + 'FERESTRE;' + ;
		gcAppPath + 'GRAFICE;' + gcAppPath + 'CLASE;' + gcAppPath + 'MENIURI;' + ;
		gcAppPath + 'PROGRAME;' + gcAppPath + 'RAPOARTE;' + gcAppPath + 'COMUN;' + ;
		gcAppPath + 'COMUN\CLASE;' + gcAppPath + 'COMUN\FERESTRE;' + gcAppPath + 'COMUN\PROGRAME;' + ;
		gcAppPath + 'COMUN\GRAFICE;' + gcAppPath + 'COMUN\RAPOARTE;' + gcAppPath + 'COMUN\MENIURI;' + ;
		gcAppPath + 'COMUN\UTILE\GRIDEXTRAS;' + gcAppPath + 'COMUN\UTILE\CTL32;' + ;
		gcAppPath + 'COMUN\UTILE\HPDF;' + gcAppPath + 'COMUN\UTILE\HPDF\REPORTOUTPUT;' + ;
		gcAppPath + 'COMUN\UTILE\WEB;' + gcAppPath + 'COMUN\UTILE\EXCEL;' + ;
		ADDBS(SUBSTR(gcAppPath,1,RAT([\],gcAppPath,2)))+[COMUNROA\]
	SET PATH TO &lcPath ADDITIVE
	DO EeLog WITH 'SET PATH OK'

	*----- CLASE -----
	SET CLASSLIB TO (gcAppPath + "comun\clase\appwiz") ADDITIVE
	SET CLASSLIB TO GESTIUNI ADDITIVE
	SET CLASSLIB TO CAUT ADDITIVE
	SET CLASSLIB TO BAZA ADDITIVE
	SET CLASSLIB TO comun ADDITIVE
	SET CLASSLIB TO accessibility.vcx ADDITIVE
	SET CLASSLIB TO messagebox ADDITIVE
	SET CLASSLIB TO registry ADDITIVE
	SET CLASSLIB TO cauta_alfa_forms.vcx ADDITIVE
	SET CLASSLIB TO DECABAZA ADDITIVE
	SET CLASSLIB TO onomenclatoare ADDITIVE
	SET CLASSLIB TO stocuri.vcx ADDITIVE
	SET CLASSLIB TO rulaje.vcx ADDITIVE
	SET CLASSLIB TO ointroduceri ADDITIVE
	SET CLASSLIB TO ointroduceri_web ADDITIVE
	SET CLASSLIB TO ointroduceri_depozit ADDITIVE
	SET CLASSLIB TO overificari ADDITIVE
	SET CLASSLIB TO ferestre_oracle ADDITIVE
	SET CLASSLIB TO ferestre_cere_date.vcx ADDITIVE
	SET CLASSLIB TO configurare.vcx ADDITIVE
	SET CLASSLIB TO serii_numere.vcx ADDITIVE
	SET CLASSLIB TO omodificari.vcx ADDITIVE
	SET CLASSLIB TO ocompensari.vcx ADDITIVE
	SET CLASSLIB TO caut_ora ADDITIVE
	SET CLASSLIB TO onote_contabile ADDITIVE
	SET CLASSLIB TO otoolbar ADDITIVE
	SET CLASSLIB TO bon_fisc ADDITIVE
	SET CLASSLIB TO onom_articole ADDITIVE
	SET CLASSLIB TO onom_retete ADDITIVE
	SET CLASSLIB TO orapoarte ADDITIVE
	SET CLASSLIB TO orapoarte_gestiuni ADDITIVE
	SET CLASSLIB TO orapoarte_parametri ADDITIVE
	SET CLASSLIB TO ONOM_CURS ADDITIVE
	SET CLASSLIB TO ctl32_statusbar_fals.vcx ADDITIVE
	SET CLASSLIB TO ctl32_common.vcx ADDITIVE
	SET CLASSLIB TO ctl32_structs.vcx ADDITIVE
	SET CLASSLIB TO ctl32_progressbar.vcx ADDITIVE
	SET CLASSLIB TO ctl32_balloontip.vcx ADDITIVE
	SET CLASSLIB TO ocriterii.vcx ADDITIVE
	SET CLASSLIB TO oavize.vcx ADDITIVE
	SET CLASSLIB TO onomenclatoare2 ADDITIVE
	SET CLASSLIB TO wwdialogs.vcx ADDITIVE
	SET CLASSLIB TO oimportxml.vcx ADDITIVE
	SET CLASSLIB TO excelxml.vcx ADDITIVE
	SET CLASSLIB TO orapoarte_obinv.vcx ADDITIVE
	DO EeLog WITH 'SET CLASSLIB OK'

	*----- PROCEDURI (mock-uri PRIMELE, ui_harness la final) -----
	SET PROCEDURE TO PROCEDURI
	SET PROCEDURE TO "D:\ROA\ROAGEST\COMUN\utile\Teste\mock_amessagebox.prg" ADDITIVE
	SET PROCEDURE TO "D:\ROA\ROAGEST\COMUN\utile\Teste\achizitie_import\mock_caut_valuta.prg" ADDITIVE
	SET PROCEDURE TO "D:\ROA\ROAGEST\COMUN\utile\Teste\mock_cauta_nom_articole.prg" ADDITIVE
	SET PROCEDURE TO "D:\ROA\ROAGEST\COMUN\utile\Teste\achizitie_import\mock_oscrie_in_fisiere.prg" ADDITIVE
	SET PROCEDURE TO acces_meniu ADDITIVE
	SET PROCEDURE TO cauta_alfa ADDITIVE
	SET PROCEDURE TO pmenu ADDITIVE
	SET PROCEDURE TO proceduri_comune ADDITIVE
	SET PROCEDURE TO quitapp ADDITIVE
	SET PROCEDURE TO init_program ADDITIVE
	SET PROCEDURE TO oproceduri_listari.prg ADDITIVE
	SET PROCEDURE TO oproceduri_configurare.prg ADDITIVE
	SET PROCEDURE TO oproceduri_articole.prg ADDITIVE
	SET PROCEDURE TO oproceduri_retete.prg ADDITIVE
	SET PROCEDURE TO orapoarte.prg ADDITIVE
	SET PROCEDURE TO mesaje ADDITIVE
	SET PROCEDURE TO oserii_numere.prg ADDITIVE
	SET PROCEDURE TO oexport.prg ADDITIVE
	SET PROCEDURE TO wwConfig.prg ADDITIVE
	SET PROCEDURE TO proceduri_rapoarte.prg ADDITIVE
	SET PROCEDURE TO OPROCEDURI_CURS.PRG ADDITIVE
	SET PROCEDURE TO validare.prg ADDITIVE
	SET PROCEDURE TO GENCURSOR.PRG ADDITIVE
	SET PROCEDURE TO OPROCEDURI_COMUNE.PRG ADDITIVE
	SET PROCEDURE TO OINIT_OPTIUNI.PRG ADDITIVE
	SET PROCEDURE TO updateserver.prg ADDITIVE
	SET PROCEDURE TO oinainte_de.prg ADDITIVE
	SET PROCEDURE TO ooperatii_comune.prg ADDITIVE
	SET PROCEDURE TO Ocompensari.PRG ADDITIVE
	SET PROCEDURE TO OPROCEDURI_aMS.PRG ADDITIVE
	SET PROCEDURE TO oproceduri_rulaje ADDITIVE
	SET PROCEDURE TO oproceduri_stocuri ADDITIVE
	SET PROCEDURE TO OINTRODUCERI ADDITIVE
	SET PROCEDURE TO oHeader.prg ADDITIVE
	SET PROCEDURE TO proceduri_excel.PRG ADDITIVE
	SET PROCEDURE TO onomenclatoare.PRG ADDITIVE
	SET PROCEDURE TO osecurity ADDITIVE
	SET PROCEDURE TO ocautare ADDITIVE
	SET PROCEDURE TO orefaceri ADDITIVE
	SET PROCEDURE TO ofacturare_comun.PRG ADDITIVE
	SET PROCEDURE TO ofacturare_stoc.PRG ADDITIVE
	SET PROCEDURE TO oproceduri_casademarcat ADDITIVE
	SET PROCEDURE TO oproceduri_casa_marcat_e500 ADDITIVE
	SET PROCEDURE TO oproceduri_casa_marcat_mp500 ADDITIVE
	SET PROCEDURE TO oproceduri_util.prg ADDITIVE
	SET PROCEDURE TO wwxmlhttp.prg ADDITIVE
	SET PROCEDURE TO ini.prg ADDITIVE
	SET PROCEDURE TO odocumente.prg ADDITIVE
	SET PROCEDURE TO regex.prg ADDITIVE
	SET PROCEDURE TO wwutils.prg ADDITIVE
	SET PROCEDURE TO inchidere_k ADDITIVE
	SET PROCEDURE TO iniacces.prg ADDITIVE
	SET PROCEDURE TO oupdate.prg ADDITIVE
	SET PROCEDURE TO procese.prg ADDITIVE
	SET PROCEDURE TO version.prg ADDITIVE
	SET PROCEDURE TO xmlaccess.prg ADDITIVE
	SET PROCEDURE TO xmlparser.prg ADDITIVE
	SET PROCEDURE TO filebringer.prg ADDITIVE
	SET PROCEDURE TO wwcodeupdate.prg ADDITIVE
	SET PROCEDURE TO wwhttp.prg ADDITIVE
	SET PROCEDURE TO xdate.prg ADDITIVE
	SET PROCEDURE TO ofacturare.prg ADDITIVE
	SET PROCEDURE TO oproceduri_obinv.prg ADDITIVE
	SET PROCEDURE TO oproceduri_facturare.prg ADDITIVE
	SET PROCEDURE TO email.prg ADDITIVE
	SET PROCEDURE TO "D:\ROA\ROAGEST\COMUN\utile\Teste\ui_harness.prg" ADDITIVE
	DO EeLog WITH 'SET PROCEDURE OK'

	*----- Globale -----
	PUBLIC gnPc, gnPval, gnPcant, gnPpret, gnPPretval, gnPCurs, gnPVal, gnPPretV, gnPPretVal
	STORE 2 TO gnPc, gnPval, gnPVal
	gnPcant = 3
	STORE 4 TO gnPpret, gnPPretval, gnPPretVal, gnPPretV, gnPCurs
	PUBLIC gl406, gcS, gnAn, gnLuna, gnIdFirma, gnIdSucursala, gcAcces, gcFirma
	gl406 = .T.
	gcS = 'CONTAFIN'
	gnAn = YEAR(DATE())
	gnLuna = MONTH(DATE())
	gnIdFirma = 110
	gnIdSucursala = 110
	gcAcces = "1;2;3;4;5;6;7;8;"
	gcFirma = gcS
	PUBLIC nror(65000)

	PUBLIC gnMockRaspuns, gcMockUltimMesaj, gnMockUltimTip, gcMockArtCodmat
	gnMockRaspuns = 6
	gcMockUltimMesaj = ''
	gnMockUltimTip = 0
	PUBLIC gnButon
	gnButon = 1
	gcMockArtCodmat = ''

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

	*----- poAct: antetul notei (factura import EUR, curs 5.23) -----
	PUBLIC poAct
	poAct = CREATEOBJECT('Custom')
	poAct.AddProperty('nume_val', 'EUR')
	poAct.AddProperty('curs', 5.23)
	poAct.AddProperty('proc_tva', 1.21)
	poAct.AddProperty('nnir', 0)
	poAct.AddProperty('id_valuta', 978)
	poAct.AddProperty('id_fdoc', 42)
	poAct.AddProperty('fdoc', 'Factura')
	poAct.AddProperty('id_partc', 463)
	poAct.AddProperty('partc', 'RAJA')
	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 11% + 21%, achizitii interne + import -----
	IF USED('jtva_coloane2')
		USE IN ('jtva_coloane2')
	ENDIF
	CREATE CURSOR jtva_coloane2 (ordine N(8), id_jtva_coloana N(14), denumire C(100), ;
		jc N(1), jv N(1), afisat N(1), coloana_jc C(20), coloana_jv C(20), cota_tva N(6,2), id_tva N(14))
	INSERT INTO jtva_coloane2 VALUES (0, 0, '', 0, 0, 1, '', '', 0, 0)
	INSERT INTO jtva_coloane2 VALUES (1, 208, 'ACH. INT. 21%', 1, 0, 1, 'RO21B', 'RO21T', 21, 209)
	INSERT INTO jtva_coloane2 VALUES (2, 209, 'TVA ACH. INT. 21%', 1, 0, 1, 'RO21T', '', 21, 0)
	INSERT INTO jtva_coloane2 VALUES (3, 210, 'ACH. INT. 11%', 1, 0, 1, 'RO11B', 'RO11T', 11, 211)
	INSERT INTO jtva_coloane2 VALUES (4, 211, 'TVA ACH. INT. 11%', 1, 0, 1, 'RO11T', '', 11, 0)
	INSERT INTO jtva_coloane2 VALUES (5, 220, 'ACH. IMP. 21%', 1, 0, 1, 'FO21B', 'FO21T', 21, 221)
	INSERT INTO jtva_coloane2 VALUES (6, 221, 'TVA ACH. IMP. 21%', 1, 0, 1, 'FO21T', '', 21, 0)
	INSERT INTO jtva_coloane2 VALUES (7, 222, 'ACH. IMP. 11%', 1, 0, 1, 'FO11B', 'FO11T', 11, 223)
	INSERT INTO jtva_coloane2 VALUES (8, 223, 'TVA ACH. IMP. 11%', 1, 0, 1, 'FO11T', '', 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 ('301104-Achizitii interne cota 11%', 301104, '', 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', 208, 21, 'ACH. INT. 21%')
	INSERT INTO introdc_sablon (scd, scc, cu_tva, ordine, id_set, participa_valuta, tip_rand, ;
			id_jtva_coloana, ptva, explicatie_tva) ;
		VALUES ('4426', '401', 1, 2, 1, .T., 'T', 209, 21, 'TVA ACH. INT. 21%')
	GO TOP IN introdc_sablon

	DO CreeazaRulTemp
	INSERT INTO rul_temp (denumire, codmat, cant, pret, pret_lei, cont, cota_tva) ;
		VALUES ('PLACEHOLDER', 'PH', 1, 1, 1, '371', 21)

	*-- index ord_doc INAINTE de CREATEOBJECT (capcana p, docs/testare-ui-vfp.md)
	SELECT introdc
	INDEX ON Str(Nvl(nr_doc,0),8) + Icase(tip_rand='B','1', tip_rand='S','2', tip_rand='G','3', tip_rand='T','4', tip_rand='D','5', '6') + Padr(Nvl(scd,''),10) TAG ord_doc
	SET ORDER TO ord_doc

	*-- vezi antetul test_e2e_dvi_ron_discount.prg: tlIntern BARA, aceeasi valoare ca la CREATEOBJECT
	PRIVATE tlIntern
	tlIntern = .F.

	PUBLIC gcTempPath
	gcTempPath = ADDBS(SYS(2023))
	PUBLIC gnHandle
	gnHandle = -1
	PUBLIC gnTipGest
	gnTipGest = 0
	PUBLIC gcCondSucursala
	gcCondSucursala = ''

	DO EeLog WITH 'cursoare pregatite, CREATEOBJECT(import_nota, .F. - mod import)'
	PUBLIC goObj
	goObj = CREATEOBJECT('IMPORT_nota', .F.)
	IF VARTYPE(goObj) <> 'O'
		DO EeLog WITH 'FAIL: instantiere import_nota'
		DO HarnessDone WITH 'done-error'
		QUIT
	ENDIF
	goObj.lDialogAratat = .T.
	goObj.oact = poAct
	*-- lSpargeSecundare ramane la valoarea implicita a clasei (.T., "spargere secundare activa")
	*-- - NU se suprascrie, ca sa reflecte comportamentul implicit real, nu setarea din alte teste.
	goObj.WindowType = 0
	goObj.Visible = .T.
	goObj.Show()
	goObj.WindowState = 2
	DOEVENTS FORCE

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

	PRIVATE pnAsserts, pnPass
	STORE 0 TO pnAsserts, pnPass

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

	*========================= DOC1: factura EUR (RAJA) + TVA DVI fara valuta proprie + discount =========================
	PUBLIC goDlg
	goDlg = CREATEOBJECT('import_adauga_factura', goObj)
	goDlg.cFelDoc = 'Factura'
	goDlg.nIdFdoc = 42
	goDlg.nNract = 15000
	goDlg.dDataAct = DATE()
	goDlg.nIdPartener = 463
	goDlg.cPartener = 'RAJA'
	goDlg.cExplicatia = 'Factura import RAJA'
	goDlg.nSuma = 1000
	goDlg.nSumaLei = 0
	goDlg.nCurs = 5.23
	goDlg.nIdValuta = 978
	goDlg.cValuta = 'EUR'
	goDlg.chkInValutaCont.Value = 1
	goDlg.chkParticipaValuta.Value = 1
	goDlg.nIdExplicatieTva = 220
	goDlg.cExplicatieTva = 'ACH. IMP. 21%'
	goDlg.nProcentTva = 21

	*-- DVI: identitate proprie (document vamal, partener vamal, nract 101), FARA valuta proprie
	goDlg.cSerieDvi = ''
	goDlg.nNractDvi = 101
	goDlg.dDviData = DATE()
	goDlg.nIdFdocDVI = 39
	goDlg.cFelDocDvi = 'DVI'
	goDlg.nDviIdPartener = 1398
	goDlg.cDviPartener = 'BIROUL VAMAL'

	goDlg.optTipTva.Value = 2
	goDlg.optTipTva.InteractiveChange()

	*-- alegere RON pe blocul DVI (picker real, mock_caut_valuta) - normalizare "fara valuta proprie"
	PUBLIC goMockValuta, goMockValutaCoada
	goMockValuta = CREATEOBJECT('Custom')
	goMockValuta.AddProperty('id_valuta', 1)
	goMockValuta.AddProperty('nume_val', 'RON')
	goMockValutaCoada = CREATEOBJECT('Collection')
	LOCAL loValRon
	loValRon = CREATEOBJECT('Custom')
	loValRon.AddProperty('id_valuta', 1)
	loValRon.AddProperty('nume_val', 'RON')
	goMockValutaCoada.Add(loValRon)
	goDlg.cmdDviValuta.Click()
	=AssertStr('1-DVI valuta aleasa RON (fara valuta proprie)', ALLTRIM(goDlg.cDviValuta), 'RON')

	*-- discount financiar (doar baza)
	goDlg.txtDiscBaza.Value = 100
	goDlg.txtDiscBaza.Valid()

	goDlg.WindowType = 0
	goDlg.Visible = .T.
	goDlg.Show()
	DOEVENTS FORCE
	DO HarnessStep WITH 1, 'DOC1 completat: RAJA nract=15000, DVI nract=101 fara valuta, discount 100 EUR'

	LOCAL llOkValid1
	llOkValid1 = goDlg.valideaza()
	=Assert3('2-DOC1 dialog valideaza() reuseste', IIF(llOkValid1,1,0), 1)

	*-- toDlg DOC1 construit INLINE in programul PRINCIPAL (capcana l, mock_caut_valuta.prg)
	PUBLIC goT
	goT = CREATEOBJECT('Empty')
	=ADDPROPERTY(goT,'serie_act',ALLTRIM(NVL(goDlg.cSerieAct,'')))
	=ADDPROPERTY(goT,'nract',goDlg.nNract)
	=ADDPROPERTY(goT,'dataact',goDlg.dDataAct)
	=ADDPROPERTY(goT,'fdoc',goDlg.cFelDoc)
	=ADDPROPERTY(goT,'id_fdoc',goDlg.nIdFdoc)
	=ADDPROPERTY(goT,'id_partc',goDlg.nIdPartener)
	=ADDPROPERTY(goT,'partc',goDlg.cPartener)
	=ADDPROPERTY(goT,'explicatia',ALLTRIM(NVL(goDlg.cExplicatia,'')))
	=ADDPROPERTY(goT,'suma',IIF(goDlg.chkInValutaCont.Value=1 AND goDlg.nCurs<>0,IIF(goDlg.nSumaLei<>0,goDlg.nSumaLei,ROUND(goDlg.nSuma*goDlg.nCurs,gnPC)),goDlg.nSuma))
	=ADDPROPERTY(goT,'suma_val',IIF(goDlg.chkInValutaCont.Value=1 AND goDlg.nCurs<>0,goDlg.nSuma,0))
	=ADDPROPERTY(goT,'in_valuta',goDlg.chkInValutaCont.Value)
	=ADDPROPERTY(goT,'participa_valuta',(goDlg.chkParticipaValuta.Value=1))
	=ADDPROPERTY(goT,'id_valuta',IIF(goDlg.chkInValutaCont.Value=1,goDlg.nIdValuta,0))
	=ADDPROPERTY(goT,'curs',IIF(goDlg.chkInValutaCont.Value=1,goDlg.nCurs,0))
	=ADDPROPERTY(goT,'nume_val',IIF(goDlg.chkInValutaCont.Value=1,ALLTRIM(NVL(goDlg.cValuta,'')),''))
	=ADDPROPERTY(goT,'cTipTva',IIF(goDlg.optTipTva.Value=1,'F',IIF(goDlg.optTipTva.Value=2,'D','N')))
	=ADDPROPERTY(goT,'id_jtva_coloana',goDlg.nIdExplicatieTva)
	IF goDlg.optTipTva.Value = 2
		=ADDPROPERTY(goT,'dvi_serie',CHRTRAN(ALLTRIM(NVL(goDlg.cSerieDvi,'')),CHR(34),''))
		=ADDPROPERTY(goT,'dvi_nract',goDlg.nNractDvi)
		=ADDPROPERTY(goT,'dvi_dataact',goDlg.dDviData)
		=ADDPROPERTY(goT,'dvi_id_fdoc',goDlg.nIdFdocDVI)
		=ADDPROPERTY(goT,'dvi_fdoc',goDlg.cFelDocDvi)
		=ADDPROPERTY(goT,'dvi_id_partc',goDlg.nDviIdPartener)
		=ADDPROPERTY(goT,'dvi_partc',goDlg.cDviPartener)
		=ADDPROPERTY(goT,'dvi_scc','401')
		=ADDPROPERTY(goT,'dvi_tva_lei',goDlg.nDviTvaLei)
		=ADDPROPERTY(goT,'dvi_tva_val',goDlg.nDviTvaVal)
		=ADDPROPERTY(goT,'dvi_in_valuta',!(EMPTY(goDlg.cDviValuta) OR UPPER(ALLTRIM(goDlg.cDviValuta))=='RON'))
		=ADDPROPERTY(goT,'dvi_id_valuta',goDlg.nDviIdValuta)
		=ADDPROPERTY(goT,'dvi_curs',goDlg.nDviCurs)
		=ADDPROPERTY(goT,'dvi_nume_val',ALLTRIM(NVL(goDlg.cDviValuta,'')))
		=ADDPROPERTY(goT,'dvi_valuta_proprie',IIF(!(EMPTY(goDlg.cDviValuta) OR UPPER(ALLTRIM(goDlg.cDviValuta))=='RON') OR !(EMPTY(goDlg.cValuta) OR UPPER(ALLTRIM(goDlg.cValuta))=='RON'),IIF(goDlg.nDviIdValuta<>goDlg.nIdValuta OR goDlg.nDviCurs<>goDlg.nCurs,1,0),0))
	ENDIF
	=ADDPROPERTY(goT,'disc_baza_lei',IIF(goDlg.chkInValutaCont.Value=1 AND goDlg.nCurs<>0,ROUND(goDlg.nDiscBaza*goDlg.nCurs,gnPC),goDlg.nDiscBaza))
	=ADDPROPERTY(goT,'disc_baza_val',IIF(goDlg.chkInValutaCont.Value=1 AND goDlg.nCurs<>0,goDlg.nDiscBaza,0))

	LOCAL llOkAdauga1
	llOkAdauga1 = goObj.do_adauga_factura(goT)
	=Assert3('3-DOC1 do_adauga_factura(goT) reuseste (Termin)', IIF(llOkAdauga1,1,0), 1)
	goDlg.Hide()
	DOEVENTS FORCE
	DO HarnessStep WITH 2, 'DOC1 adaugat: introdc=' + TRANSFORM(RECCOUNT_ACTIVE('introdc')) + ' randuri'
	DO DumpIntrodc WITH 'DUMP dupa DOC1 (RAJA, nract=15000)'

	*========================= DOC2: taxe vamale (BIROUL VAMAL) - TVA la furnizor, cota 11%, FARA valuta =========================
	PUBLIC goDlg2
	goDlg2 = CREATEOBJECT('import_adauga_factura', goObj)
	goDlg2.cFelDoc = 'DVI'
	goDlg2.nIdFdoc = 39
	goDlg2.nNract = 101
	goDlg2.dDataAct = DATE()
	goDlg2.nIdPartener = 1398
	goDlg2.cPartener = 'BIROUL VAMAL'
	goDlg2.cExplicatia = 'Taxe vamale'
	goDlg2.nSuma = 500
	goDlg2.nSumaLei = 0
	goDlg2.nCurs = 0
	goDlg2.nIdValuta = 0
	goDlg2.cValuta = ''
	goDlg2.chkInValutaCont.Value = 0
	goDlg2.chkParticipaValuta.Value = 1
	goDlg2.nIdExplicatieTva = 210
	goDlg2.cExplicatieTva = 'ACH. INT. 11%'
	goDlg2.nProcentTva = 11

	goDlg2.optTipTva.Value = 1
	goDlg2.optTipTva.InteractiveChange()

	goDlg2.WindowType = 0
	goDlg2.Visible = .T.
	goDlg2.Show()
	DOEVENTS FORCE
	DO HarnessStep WITH 3, 'DOC2 completat: BIROUL VAMAL nract=101, TVA furnizor 11%, fara valuta'

	LOCAL llOkValid2
	llOkValid2 = goDlg2.valideaza()
	=Assert3('4-DOC2 dialog valideaza() reuseste', IIF(llOkValid2,1,0), 1)

	*-- toDlg DOC2 construit INLINE in programul PRINCIPAL (aceeasi capcana l)
	PUBLIC goT2
	goT2 = CREATEOBJECT('Empty')
	=ADDPROPERTY(goT2,'serie_act',ALLTRIM(NVL(goDlg2.cSerieAct,'')))
	=ADDPROPERTY(goT2,'nract',goDlg2.nNract)
	=ADDPROPERTY(goT2,'dataact',goDlg2.dDataAct)
	=ADDPROPERTY(goT2,'fdoc',goDlg2.cFelDoc)
	=ADDPROPERTY(goT2,'id_fdoc',goDlg2.nIdFdoc)
	=ADDPROPERTY(goT2,'id_partc',goDlg2.nIdPartener)
	=ADDPROPERTY(goT2,'partc',goDlg2.cPartener)
	=ADDPROPERTY(goT2,'explicatia',ALLTRIM(NVL(goDlg2.cExplicatia,'')))
	=ADDPROPERTY(goT2,'suma',IIF(goDlg2.chkInValutaCont.Value=1 AND goDlg2.nCurs<>0,IIF(goDlg2.nSumaLei<>0,goDlg2.nSumaLei,ROUND(goDlg2.nSuma*goDlg2.nCurs,gnPC)),goDlg2.nSuma))
	=ADDPROPERTY(goT2,'suma_val',IIF(goDlg2.chkInValutaCont.Value=1 AND goDlg2.nCurs<>0,goDlg2.nSuma,0))
	=ADDPROPERTY(goT2,'in_valuta',goDlg2.chkInValutaCont.Value)
	=ADDPROPERTY(goT2,'participa_valuta',(goDlg2.chkParticipaValuta.Value=1))
	=ADDPROPERTY(goT2,'id_valuta',IIF(goDlg2.chkInValutaCont.Value=1,goDlg2.nIdValuta,0))
	=ADDPROPERTY(goT2,'curs',IIF(goDlg2.chkInValutaCont.Value=1,goDlg2.nCurs,0))
	=ADDPROPERTY(goT2,'nume_val',IIF(goDlg2.chkInValutaCont.Value=1,ALLTRIM(NVL(goDlg2.cValuta,'')),''))
	=ADDPROPERTY(goT2,'cTipTva',IIF(goDlg2.optTipTva.Value=1,'F',IIF(goDlg2.optTipTva.Value=2,'D','N')))
	=ADDPROPERTY(goT2,'id_jtva_coloana',goDlg2.nIdExplicatieTva)
	=ADDPROPERTY(goT2,'disc_baza_lei',IIF(goDlg2.chkInValutaCont.Value=1 AND goDlg2.nCurs<>0,ROUND(goDlg2.nDiscBaza*goDlg2.nCurs,gnPC),goDlg2.nDiscBaza))
	=ADDPROPERTY(goT2,'disc_baza_val',IIF(goDlg2.chkInValutaCont.Value=1 AND goDlg2.nCurs<>0,goDlg2.nDiscBaza,0))

	LOCAL llOkAdauga2
	llOkAdauga2 = goObj.do_adauga_factura(goT2)
	=Assert3('5-DOC2 do_adauga_factura(goT2) reuseste (Termin)', IIF(llOkAdauga2,1,0), 1)
	goDlg2.Hide()
	DOEVENTS FORCE
	DO HarnessStep WITH 4, 'DOC2 adaugat: introdc=' + TRANSFORM(RECCOUNT_ACTIVE('introdc')) + ' randuri'
	DO DumpIntrodc WITH 'DUMP dupa DOC2 (BIROUL VAMAL, nract=101)'

	*========================= verificare doc_key: T-DVI (DOC1) vs B (DOC2) nu se suprapun =========================
	LOCAL lcDocKeyTDvi, lcDocKeyDoc2B
	lcDocKeyTDvi = ''
	lcDocKeyDoc2B = ''
	SELECT introdc
	LOCATE FOR Nvl(rand_dvi,0) = 1
	IF FOUND()
		lcDocKeyTDvi = ALLTRIM(NVL(doc_key,''))
	ENDIF
	LOCATE FOR nract = 101 AND id_fdoc = 39 AND tip_rand == 'B'
	IF FOUND()
		lcDocKeyDoc2B = ALLTRIM(NVL(doc_key,''))
	ENDIF
	=Assert3('6-ambele doc_key gasite (T-DVI si B-DOC2)', IIF(!EMPTY(lcDocKeyTDvi) AND !EMPTY(lcDocKeyDoc2B),1,0), 1)
	pnAsserts = pnAsserts + 1
	IF !EMPTY(lcDocKeyTDvi) AND !EMPTY(lcDocKeyDoc2B) AND lcDocKeyTDvi <> lcDocKeyDoc2B
		pnPass = pnPass + 1
		DO EeLog WITH '  PASS 7-doc_key T-DVI(DOC1)=[' + lcDocKeyTDvi + '] <> doc_key B(DOC2)=[' + lcDocKeyDoc2B + '] (fara suprapunere)'
	ELSE
		DO EeLog WITH '  FAIL 7-doc_key T-DVI(DOC1)=[' + lcDocKeyTDvi + '] SE SUPRAPUNE cu B(DOC2)=[' + lcDocKeyDoc2B + '] -> pista doc_key CONFIRMATA'
	ENDIF

	*========================= ARTICOLE (2, ale DOC1): cont 371 analitic 816, cote 11%/21% =========================
	gcMockArtCodmat = 'ART-A8-371'
	LOCAL llEroareArt1
	llEroareArt1 = .F.
	TRY
		goObj.do_adauga_articol()
	CATCH TO loExcArt1
		llEroareArt1 = .T.
		DO EeLog WITH 'EROARE do_adauga_articol (art1) ' + TRANSFORM(loExcArt1.ErrorNo) + ' [' + loExcArt1.Message + ']'
	ENDTRY
	=Assert3('8-do_adauga_articol() art1 (cota 11%) fara eroare', IIF(llEroareArt1,0,1), 1)
	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), cont WITH '371', cota_tva WITH 11
	ELSE
		pnAsserts = pnAsserts + 1
		DO EeLog WITH '  FAIL 8b: articolul cota 11% nu a fost adaugat'
	ENDIF

	gcMockArtCodmat = 'ART-BULD-212'
	LOCAL llEroareArt2
	llEroareArt2 = .F.
	TRY
		goObj.do_adauga_articol()
	CATCH TO loExcArt2
		llEroareArt2 = .T.
		DO EeLog WITH 'EROARE do_adauga_articol (art2) ' + TRANSFORM(loExcArt2.ErrorNo) + ' [' + loExcArt2.Message + ']'
	ENDTRY
	=Assert3('9-do_adauga_articol() art2 (cota 21%) fara eroare', IIF(llEroareArt2,0,1), 1)
	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), cont WITH '371', cota_tva WITH 21
	ELSE
		pnAsserts = pnAsserts + 1
		DO EeLog WITH '  FAIL 9b: articolul cota 21% nu a fost adaugat'
	ENDIF
	goObj.gridart.Refresh()
	DOEVENTS FORCE
	DO HarnessStep WITH 5, 'articole adaugate (cont 371/816, cote 11% si 21%)'
	DO DumpIntrodc WITH 'DUMP dupa ARTICOLE (inainte de sincronizare)'

	*========================= sincronizeaza() REAL =========================
	LOCAL llEroareSync
	llEroareSync = .F.
	TRY
		goObj.sincronizeaza()
	CATCH TO loExcSync
		llEroareSync = .T.
		DO EeLog WITH 'EROARE sincronizeaza() ' + TRANSFORM(loExcSync.ErrorNo) + ' [' + loExcSync.Message + '] in ' + loExcSync.Procedure + ':' + TRANSFORM(loExcSync.LineNo)
	ENDTRY
	DOEVENTS FORCE
	=Assert3('10-sincronizeaza() fara eroare', IIF(llEroareSync,0,1), 1)
	DO HarnessStep WITH 6, 'sincronizat'
	DO DumpIntrodc WITH 'DUMP dupa sincronizeaza() (flux curat, fara nicio interactiune de grila)'

	*========================= ASSERT-URI DE INTEGRITATE nract - identitate dupa nr_doc, NU dupa nract =========================
	LOCAL lnNrDocRaja, llBugFluxCurat
	lnNrDocRaja = 0
	llBugFluxCurat = .F.
	SELECT introdc
	LOCATE FOR id_partc = 463 AND tip_rand <> 'T'
	IF FOUND()
		lnNrDocRaja = nr_doc
	ENDIF
	IF lnNrDocRaja = 0
		*-- RAJA nu mai apare dupa id_partc (posibil deja corupt) - incerc dupa nr_doc minim
		SELECT introdc
		CALCULATE MIN(nr_doc) TO lnNrDocRaja
	ENDIF
	DO EeLog WITH 'nr_doc identificat pentru DOC1 (RAJA): ' + TRANSFORM(lnNrDocRaja)

	LOCAL lnCntVerifCurat
	lnCntVerifCurat = 0
	SELECT introdc
	SCAN FOR nr_doc = lnNrDocRaja AND Nvl(rand_dvi,0) <> 1
		lnCntVerifCurat = lnCntVerifCurat + 1
		pnAsserts = pnAsserts + 1
		IF nract == 15000
			pnPass = pnPass + 1
			DO EeLog WITH '  PASS 11.' + TRANSFORM(lnCntVerifCurat) + '-tip_rand=' + tip_rand + ' nract=15000 (flux curat, =' + TRANSFORM(nract) + ')'
		ELSE
			llBugFluxCurat = .T.
			DO EeLog WITH '  FAIL 11.' + TRANSFORM(lnCntVerifCurat) + '-tip_rand=' + tip_rand + ' nract=' + TRANSFORM(nract) + ' (asteptat 15000) -> SE STRICA SINGUR, FARA TRIGGER'
		ENDIF
	ENDSCAN

	DO HarnessStep WITH 7, 'verificat flux curat: ' + TRANSFORM(pnPass) + '/' + TRANSFORM(pnAsserts) + ' PASS'

	*========================= imediat inainte de Terminat: ultim DUMP introdc =========================
	DO DumpIntrodc WITH 'DUMP imediat inainte de Terminat (introdc, dupa sincronizare, fara trigger)'

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

	IF USED('actactan')
		DO EeLog WITH 'DUMP actactan dupa Terminat:'
		SELECT actactan
		SCAN
			DO EeLog WITH '  recno=' + TRANSFORM(RECNO()) + ' nract=' + TRANSFORM(NVL(nract,0)) + ' id_fdoc=' + TRANSFORM(NVL(id_fdoc,0)) + ;
				' id_partc=' + TRANSFORM(NVL(id_partc,0)) + ' partc=[' + ALLTRIM(NVL(partc,'')) + ']' + ;
				' scd=' + ALLTRIM(NVL(scd,'')) + ' scc=' + ALLTRIM(NVL(scc,'')) + ' suma=' + TRANSFORM(NVL(suma,0))
		ENDSCAN

		LOCAL lnCntVerifActactan
		lnCntVerifActactan = 0
		SELECT actactan
		SCAN FOR id_partc = 463
			lnCntVerifActactan = lnCntVerifActactan + 1
			pnAsserts = pnAsserts + 1
			IF nract == 15000
				pnPass = pnPass + 1
				DO EeLog WITH '  PASS 13.' + TRANSFORM(lnCntVerifActactan) + '-actactan randul partener 463 (RAJA): nract=15000 (=' + TRANSFORM(nract) + ')'
			ELSE
				llBugFluxCurat = .T.
				DO EeLog WITH '  FAIL 13.' + TRANSFORM(lnCntVerifActactan) + '-actactan randul partener 463 (RAJA): nract=' + TRANSFORM(nract) + ' (asteptat 15000) -> BUG in actactan, flux curat'
			ENDIF
		ENDSCAN
		IF lnCntVerifActactan = 0
			DO EeLog WITH '  INFO: niciun rand cu id_partc=463 in actactan (poate fi corupt catre 1398 - vezi dump)'
		ENDIF
	ELSE
		DO EeLog WITH 'INFO: actactan neinstantiat dupa inainte_de_do_termin() (posibil eroare de validare mai devreme in flux)'
	ENDIF

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

	DO EeLog WITH '========================================================='
	IF llBugFluxCurat
		DO EeLog WITH 'BUG CONFIRMAT: nract-ul DOC1 (RAJA, 15000) SE STRICA SINGUR in fluxul curat ' + ;
			'(fara nicio interactiune de grila / Valid() / copiaza_valoare() apelate din test).'
	ELSE
		DO EeLog WITH 'BUG NECONFIRMAT in flux curat: nract-ul DOC1 (RAJA, 15000) a ramas corect pe toate ' + ;
			'randurile lui (B/G/S) pe tot parcursul fluxului real - dialog x2 + articole + sincronizare + Terminat - ' + ;
			'FARA nicio interactiune de grila. Corupt bug-ul necesita un declansator suplimentar (vezi test separat).'
	ENDIF
	DO EeLog WITH '========================================================='

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

	DO HarnessDone WITH 'done'

CATCH TO loExc
	DO EeLog WITH 'CATCH ErrorNo=' + TRANSFORM(loExc.ErrorNo) + ' Message=' + loExc.Message + ' Proc=' + loExc.Procedure + ' Line=' + TRANSFORM(loExc.LineNo) + ' [' + loExc.LineContents + ']'
	DO HarnessDone WITH 'done-error'
ENDTRY

QUIT

*==================================================================================
PROCEDURE DumpIntrodc
	LPARAMETERS tcTitlu
	LOCAL lcSelAnt, lnRecAnt
	lcSelAnt = SELECT()
	lnRecAnt = IIF(USED('introdc'), IIF(EOF('introdc') OR BOF('introdc'), 0, RECNO('introdc')), 0)
	DO EeLog WITH tcTitlu
	IF !USED('introdc')
		DO EeLog WITH '  (introdc neinstantiat)'
		RETURN
	ENDIF
	SELECT introdc
	SCAN
		DO EeLog WITH '  tip_rand=' + ALLTRIM(NVL(tip_rand,'?')) + ' nr_doc=' + TRANSFORM(NVL(nr_doc,0)) + ;
			' nract=' + TRANSFORM(NVL(nract,0)) + ' id_fdoc=' + TRANSFORM(NVL(id_fdoc,0)) + ;
			' id_partc=' + TRANSFORM(NVL(id_partc,0)) + ' doc_key=[' + ALLTRIM(NVL(doc_key,'')) + ']' + ;
			' rand_dvi=' + TRANSFORM(NVL(rand_dvi,0)) + ' valuta_proprie=' + TRANSFORM(NVL(valuta_proprie,0)) + ;
			' mod_manual=' + TRANSFORM(NVL(mod_manual,0)) + ' scd=' + ALLTRIM(NVL(scd,'')) + ' scc=' + ALLTRIM(NVL(scc,'')) + ;
			' suma=' + TRANSFORM(NVL(suma,0)) + ' suma_val=' + TRANSFORM(NVL(suma_val,0))
	ENDSCAN
	IF lnRecAnt > 0
		TRY
			GO lnRecAnt
		CATCH
			GO TOP
		ENDTRY
	ENDIF
	SELECT (lcSelAnt)
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 CreeazaRulTemp
	IF USED('rul_temp')
		USE IN ('rul_temp')
	ENDIF
	CREATE CURSOR rul_temp ( ;
		id_rul N(20,0), an N(4,0), luna N(2,0), cod N(20,0);
		, serie C(100), nnir N(20,0), id_articol N(10,0), denumire C(100);
		, codmat C(50), codmatf C(50), codbare C(50), um C(20);
		, id_gestiune N(5,0), nume_gestiune C(50), cgest C(20), nr_pag N(2,0);
		, gestionar C(50), comisie_receptie1 C(50), comisie_receptie2 C(50), comisie_receptie3 C(50);
		, cant N(14,3), cante N(14,3), cont C(10), acont C(20);
		, pret N(18,4), tva N(18,4), valoare N(18,4), valtva N(18,4);
		, proc_tva N(5,2), pretv N(18,4), pretvtva N(18,4), tvav N(18,4);
		, valoarev N(18,4), valtvav N(18,4), proc_tvav N(5,2), adaos N(18,4);
		, adaos_tva N(18,4), valoare_adaos N(18,4), valtva_adaos N(18,4), procent N(10,3);
		, discunitar N(18,4), discount_tva N(18,4), valoare_discount N(18,4), valtva_discount N(18,4);
		, proc_disc N(7,3), pretd N(14,4), curs N(18,4), id_valuta N(10,0);
		, nume_val C(20), id_lucrare N(20,0), nrord C(100), id_responsabil N(10,0);
		, nresp C(100), resp_marca N(18,4), dataact T, id_util N(5,0);
		, util C(30), dataora T, id_sectie N(5,0), sectie C(50);
		, csectie C(10), alcooltutun N(1,0), datain T, dataout T;
		, id_fact N(20,0), id_gestiunec N(10,0), nume_gestiunec C(50), cgestc C(20);
		, id_responsabilc N(5,0), id_reteta N(10,0), reteta C(50), nrespc C(100);
		, respc_marca N(18,4), id_set N(20,0), id_tip_rulaj N(10,0), tip_rulaj C(50);
		, id_obiect_depozit N(10,0), id_rul_aux N(10,0), nract N(20,0), serie_act C(10);
		, dataoras T, id_utils N(10,0), lot C(30), adata_expirare T;
		, id_sucursala N(5,0), sucursala C(250), id_part_rez N(10,0), part_rez C(100);
		, id_lucrare_rez N(10,0), nrord_rez C(100), subgrupa C(100), grupa C(100);
		, id_subgrupa N(5,0), id_grupa N(5,0), in_stoc N(1,0), in_crm N(1,0);
		, id_furnizor N(10,0), furnizor C(100), id_jtva_coloana N(4,0), explicatie_tva C(100);
		, taxcode N(6,0), taxname C(254), saft_procent N(18,4), codnc8 C(20);
		, id_tara_origine N(4,0), cod_tara_origine C(5), tara_origine C(50), greutate N(12,4);
		, fdoc C(30), id_fdoc N(18,4);
		, pret_lei N(18,4), pret_val N(14,4), cota_tva N(6,2))
ENDPROC

PROCEDURE CreeazaActactan
	IF USED('actactan')
		USE IN ('actactan')
	ENDIF
	CREATE CURSOR actactan ( ;
		id_fdoc N(14), fdoc C(50), dataact D, serie_act C(10), nract N(14), ;
		partc C(100), id_partc N(14), partd C(100), id_partd N(14), ;
		suma N(18,4), suma_val N(18,4), explicatia C(100), explicatia4 C(50), explicatia5 C(50), ;
		scd C(10), ascd C(20), scc C(10), ascc C(20), id_jtva_coloana N(14) NULL, taxcode N(6), ;
		id_valuta N(14), curs N(14,4), nume_val C(10), proc_tva N(8,4), nnir N(14), ;
		tva_incasare N(1), id_set N(14), id_gestin N(14))
ENDPROC

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

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

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

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

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

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

DEFINE CLASS dummyexecutor AS Custom
	cEroare = ''
	PROCEDURE oExecute
		LPARAMETERS tcSql, tcCursor
		IF USED(m.tcCursor)
			USE IN (m.tcCursor)
		ENDIF
		IF 'VJTVA_COLOANE' $ UPPER(m.tcSql)
			DO CreeazaJtvaColoaneView WITH m.tcCursor
			RETURN 1
		ENDIF
		IF UPPER(ALLTRIM(m.tcCursor)) == 'RUL_TEMP'
			CREATE CURSOR (m.tcCursor) (denumire C(100), codmat C(30), cant N(14,3), ;
				pret_val N(18,4), pretd N(18,4), pret N(18,4), pret_lei N(18,4), cont C(10), ;
				acont C(20), serie C(30), lot C(30), adata_expirare C(10), proc_disc N(6,2), cota_tva N(6,2))
			RETURN 1
		ENDIF
		IF 'CONFIG_ANALITICE' $ UPPER(m.tcSql)
			CREATE CURSOR (m.tcCursor) (camp_leg_prefix C(30), camp_leg_sufix C(30))
			INSERT INTO (m.tcCursor) VALUES ('', '')
			RETURN 1
		ENDIF
		IF 'FCONTURI_ANALITICE' $ UPPER(m.tcSql)
			CREATE CURSOR (m.tcCursor) (acont C(20))
			INSERT INTO (m.tcCursor) VALUES (IIF(TYPE('gcMockAcontCrt') = 'C', gcMockAcontCrt, ''))
			RETURN 1
		ENDIF
		IF 'VPLCONT_ANALITIC' $ UPPER(m.tcSql)
			CREATE CURSOR (m.tcCursor) (cont C(10), acont C(20))
			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))
			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 (210, 'ACH. INT. 11%', 1, 0, 'RO11B', 11, 211, 1, 3, 301104)
	INSERT INTO (m.tcCursor) (id_jtva_coloana, denumire, jc, jv, coloana_jc, cota_tva, afisat, ordine, taxcode) ;
		VALUES (211, 'TVA ACH. INT. 11%', 1, 0, 'RO11T', 11, 1, 4, 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, 5, 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, 6, 301204)
	INSERT INTO (m.tcCursor) (id_jtva_coloana, denumire, jc, jv, coloana_jc, cota_tva, id_tva, afisat, ordine, taxcode) ;
		VALUES (222, 'ACH. IMP. 11%', 1, 0, 'FO11B', 11, 223, 1, 7, 301204)
	INSERT INTO (m.tcCursor) (id_jtva_coloana, denumire, jc, jv, coloana_jc, cota_tva, afisat, ordine, taxcode) ;
		VALUES (223, 'TVA ACH. IMP. 11%', 1, 0, 'FO11T', 11, 1, 8, 301204)
ENDPROC
