*!* 16.11.2021
*!* am tratat cazurile suma = "0.00", in loc de "0"

*!* 13.12.2021
*!* ExtrasBanca_UNICREDIT_CSV. Am corectat importul sumelor peste 1 milion
*!* CreeazaNote. Am corectat importul sumelor in valuta

*!*	11.07.2023
*!*	CreeazaNote. Am adaugat note depunere/retragere numerar corespondent 5311 = 581

*!*	08.01.2024
*!*	csvBT - tratare CSV exportat din BT24. Are sume negative pe Debit si posibil "<LF>~~"  pe linia cu tranzactia

*!*	12.06.2024
*!*	csvBT - corectie preluare nume si iban tert

*!*	26.08.2024
*!*	csvRaiffeisen - corectie conversie suma cu zecimale

*!*	loImport = CREATEOBJECT("ImportNote", "ExtrasBanca", "RZBR", "MT940", "TXT", "cContBanca=>5121??cContIban=>RO33RONCRT123143213243232")
*!*	loImport.Import()

*!* CreeazaNote - caut partenerul dupa toate variantele de denumire (nume prenume)
*!*	CreeazaNote - caut un document pereche chiar daca nu am numar de document

*!*	06.01.2025
*!* actualizat csvIngbusiness

*!*	20.01.2025
*!*	actualizat csvStripe 

*!* 21.01.2025
*!* corectie data tranzactii

*!*	06.05.2025
*!*	IMPORT xlsx RAIFFEISEN

*!*	12.05.2025
*!*	IMPORT csv FANCOURIER

*!* 22.09.2025
*!* IMPORT GARANTI - corectie eroare cod fiscal, tratare constituire/lichidare/dobanda depozit, 

*!*	05.01.2026
*!*	IMPORT csvbt din extrase de cont csv, nu numai din lista tranzactii csv

*!* 09.06.2026
*!* Import csvBT - elimin CRLF din interiorul descrierii care rupe linia de tranzactie pe 2 linii

*!* 25.07.2026
*!* marius.mutu
*!* CreeazaNote/CompleteazaParteneriROA - la CUI-uri duplicate aleg partenerul cu facturi in perioada curenta, nu ultimul creat

*************************************
* Clasa ImportNote este fabrica de clase tip Export
*************************************
Define Class ImportNote As Custom
	oImport = Null

	cFile = '' && fisierul de import

	* Perioada de import
	dData1 = {}
	dData2 = {}
	
	dData = {} && data de import, indiferent de datele din fisier

	cFileExt = "TXT"
	cClass = '' && clasa de import: ex: "ExtrasBanca"
	cClassType = '' && tipul de clasa de import: ex: "RZBR"
	cFileType = '' && tipul de fisier (optional) ex: MT940
	cFileExt = '' && extensia fisierului ex: TXT/XML/CSV/XLS
	cHashParam = ''

	cErrorMessage = ''
	lError = .F.

	Procedure Init
		Lparameters tcFile, tdData1, tdData2, tcClass, tcClassType, tcFileType, tcFileExt, tcHashParam, tdData
		* tcFile = fisierul de importat (optional)
		* tdData1, tdData2 = perioada de import
		* tcClass = Clasa de import (ExtrasBanca)
		* tcClassType = tipul de clasa de import (ex: Identificatorul bancii = RZBR)
		* tcFileType (optional) = tipul de fisier (MT940, in cazul in care pentru aceeasi extensie ex: "txt" sunt mai multe tipuri de fisier)
		* tcFileExt = extensia fisierului extras (txt, xml, csv, xls)
		* tlCreeazaParteneri = se creeaza parteneri in baza de date daca nu exista
		* tlFactura = se cauta facturi pereche in baza de date
		* tlComanda = se cauta comenzi in baza de date
		* tcHashParam = parametri optionali care se transmit la clasa de import sub forma [cselect=>select id, name from test??cwhere=>id=pnId??corder=>name]
		* Se parseaza cu loHash = GetHash(tcHashParam) oproceduri_comune.prg
		* tdData = nu mai tin cont de perioada de import, import tot fisierul si pun tdDataExtras. 
		* Se foloseste pentru fisierele de la curieri (un fisier cu transferurile dintr-o zi, chiar daca datele persoanelor individuale sunt diferite)
		* Tin cont de tdData doar pentru importurile de la curieri
		
		This.cFile = Iif(!Empty(m.tcFile), Alltrim(m.tcFile), "")
		This.dData1 = Iif(!Empty(m.tdData1), m.tdData1, Date(m.gnAn, m.gnLuna, 1))
		This.dData2 = Iif(!Empty(m.tdData2), m.tdData2, Gomonth(Date(m.gnAn, m.gnLuna, 1), 1) - 1)
		This.cClass = Iif(!Empty(m.tcClass), Upper(Alltrim(m.tcClass)), "ExtrasBanca")
		This.cClassType = Iif(!Empty(m.tcClassType), Upper(Alltrim(m.tcClassType)), "")
		This.cFileExt = Iif(!Empty(m.tcFileExt), Upper(Alltrim(m.tcFileExt)), "TXT")
		This.cFileType = Iif(!Empty(m.tcFileType), Upper(Alltrim(m.tcFileType)), "")
		This.cHashParam = Iif(!Empty(m.tcHashParam), m.tcHashParam, "")
		This.dData = tdData
		
	Endproc && Init

	Procedure Destroy
		Use In (Select('C_IMPORT_TEMP'))
		Use In (Select('cActTemp'))
	Endproc && Destroy

	Procedure Import
		Lparameters tlCreeazaNote

		Local lcFile, lcFileExt, llSucces, llCreeazaNote
		Local lcClasa, lcClass, lcClassType, lcFileType, lcHashParam, lnLinii
		Local ldData1, ldData2, ldData
		Local llCreeazaParteneri

		lcClass = This.cClass && ExtrasBanca
		lcClassType = This.cClassType && RZBR (RAIFFEISEN)
		lcFileExt = This.cFileExt && TXT/XML/CSV/XLS
		lcFileType = This.cFileType && MT940 (optional)
		lcFile = This.cFile && fisierul de import (optional)
		lcHashParam = This.cHashParam
		llCreeazaNote = Iif(Pcount() > 0, m.tlCreeazaNote, .T.)

		ldData1 = This.dData1
		ldData2 = This.dData2
		ldData = this.dData

		llSucces = .T.
		lnLinii = 0

		* Aleg fisierul de import
		If Empty(m.lcFile)
			lcFileExt = Iif(!Empty(This.cFileExt), Upper(Alltrim(This.cFileExt)), 'TXT')
			lcFile = Getfile(m.lcFileExt, "Fisier", "Selecteaza", 0, "Alege fisierul din care se realizeaza importul")
			If !Empty(m.lcFile)
				This.cFile = m.lcFile
			Else
				This.cErrorMessage = This.cErrorMessage + Iif(!Empty(This.cErrorMessage), Chr(13), '') + 'Fisierul este gol!'
				This.lError = .T.
				llSucces = .F.
			Endif
		Endif

		* Creez cursoarele pentru import
		Create Cursor C_IMPORT_TEMP (nr N(14), Data D, suma N(15, 2), suma_val N(15, 2), Curs N (15, 4), nume_val C(20), id_valuta I, explicatie C (100), iban C (24), denumire C (60), cod_fiscal C (13), tip C (2), tip_2 C (3), documente C(250), comenzi C(250))

		Select nr, Data, suma, suma_val, Curs, nume_val, id_valuta, explicatie, iban, denumire, cod_fiscal, tip, tip_2, documente, comenzi, ;
			Space(4) As scd, Space(4) As scc, Space(4) As ascd, Space(4) As ascc, ;
			Cast(Null As N(10)) As id_partd, Cast(Null As N(10)) As id_partc, Space(100) As partd, Space(100) As partc, ;
			Cast(Null As N(10)) As id_part, SPACE(100) as partener, ;
			Cast(0 As I) As id_factd, Cast(0 As I) As id_factc, Cast(0 As I) As pereched, Cast(0 As I) As perechec, ;
			Cast(Null As I) As id_fdoc, Space(50) As fdoc ;
			From C_IMPORT_TEMP ;
			Into Cursor cActTemp Readwrite


		* Instantiaza clasa de import corespunzatoare bazat pe Class, classType, FileExt, FileType
		If m.llSucces
			lcClasa = ''
			Try
				lcClasa = m.lcClass + ;
					Iif(!Empty(m.lcClassType), '_' + m.lcClassType, '') + ;
					Iif(!Empty(m.lcFileExt), '_' + m.lcFileExt, '') + ;
					Iif(!Empty(m.lcFileType), '_' + m.lcFileType, '') && ExtrasBanca_RZBR_TXT_MT940, ExtrasBanca_RZBR_TXT, ExtrasBanca_RZBR_XML

				This.oImport = Createobject(m.lcClasa, m.lcHashParam)
			Catch
				Try
					lcClasa = "ExtrasBanca_General"
					This.oImport = Createobject(m.lcClasa, m.lcHashParam)
				Catch To loEx
					This.lError = .T.
					llSucces = .F.
					This.cErrorMessage = This.cErrorMessage + Iif(!Empty(This.cErrorMessage), Chr(13), '') + loEx.Message
				Endtry
			Endtry
			If Type('This.oImport') <> 'O'
				This.lError = .T.
				llSucces = .F.
				This.cErrorMessage = This.cErrorMessage + Iif(!Empty(This.cErrorMessage), Chr(13), '') + 'Nu este definit importul pentru ' + m.lcClasa
			Else
				This.oImport.cFile = m.lcFile
				This.oImport.dData1 = m.ldData1
				This.oImport.dData2 = m.ldData2
				This.oImport.dData = m.ldData
				*!*					This.oImport.lCreeazaParteneri = m.llCreeazaParteneri
			Endif
		Endif && llSucces

		If m.llSucces And Type('This.oImport') = 'O'
			* Parsez fisierul de import si completez C_IMPORT_TEMP
			llSucces = This.oImport.Parse()
			If !m.llSucces
				This.lError = .T.
				llSucces = .F.
				This.cErrorMessage = This.cErrorMessage + Iif(!Empty(This.cErrorMessage), Chr(13), '') + This.oImport.cErrorMessage
			Else
				IF EMPTY(NVL(m.ldData, {}))
					Delete From C_IMPORT_TEMP Where !Between(Data, m.ldData1, m.ldData2)
				ELSE
					* import tot fisierul daca este completata ldData pentru deconturile de la curieri
					UPDATE C_IMPORT_TEMP SET data = m.ldData
				ENDIF 	
			Endif

			If !Inlist(This.oImport.cValuta, 'RON', 'LEI', 'ROL')
				This.oImport.cContBanca = '5124' && banca valuta
			Endif

			If m.llSucces And m.llCreeazaNote
				* Creez note contabile in act_temp, completez parteneri, conturi
				llSucces = This.oImport.CreeazaNote()
			Endif
		Endif && llSucces

		Return m.llSucces

	Endproc
Enddefine && ImportNote


*************************************
* Clasa factory pentru import extras banca
* Instantiaza clasa import banca specifica bancii si tipului de fisier ales
* Apeleaza ParseStatement din clasa import specifica
*************************************
Define Class ExtrasBanca As Custom
	oExtrasBanca = Null

	cErrorMessage = ''
	lError = .F.

	lCreeazaParteneri = .F. && creeaza parteneri daca nu exista (dupa cod fiscal)
	lFactura = .F.
	lComanda = .F.

	cFile = '' && fisierul de import
	
	dData1 = {} && perioada de import
	dData2 = {}
	
	dData = {} && data de import, se importa toate inregistrarile, si se pune dData. Pentru deconturile de la curieri
	
	cIBAN = '' && cont bancar IBAN la care se refere extrasul
	cValuta = 'RON'

	cBIC = '' && cod BIC banca / nu se mai foloseste ???
	nNr = 0 && statement number/ numar extras
	cContBanca = '5121' && 5121/5124/5125
	cAcontBanca = '' && analitic 5121
	nIdPartenerBanca = 0 && id_part ROA banca
	cBanca = '' && denumire banca

	cTipComisioane = 'COM' && 627
	cTipTaxe = 'CHG' && 627
	cTipCec = 'CHK' && 403/413
	cTipDobanzi = 'INT' && 666/766
	cTipTerti = 'TRF' && 401/4111
	cTipBuget = 'BUG' && 448
	cTipTransfer = 'TRS' && 5121
	cTipAlte = 'ALT' && 6588/7588
	cTipDepunere = 'DEP' && 5311
	cTipEfecteComerciale = 'EFT' && 403/413
	cTipComisionDecont = 'CDT' && 473 comisioane retinute de procesatori plati, curieri

	Dimension aLinii[1]
	nLinii = 0

	Procedure Init
		Lparameters tcHashParam

		Local lcContBanca, lcContIBAN, lcHashParam, loHash
		Local lcAcontBanca, llComanda, llCreeazaParteneri, llFactura
		Local lcBanca, lnIdPartenerBanca

		lcHashParam = Iif(!Empty(m.tcHashParam), m.tcHashParam, '')
		loHash = GetHash(m.lcHashParam)
		lcContBanca = m.loHash.GetValue('cContBanca')
		lcAcontBanca = m.loHash.GetValue('cAContBanca')
		lcContIBAN = loHash.GetValue('cContIban')
		lnIdPartenerBanca = loHash.GetValue('nIdPartBanca')
		lcBanca = m.loHash.GetValue('cBanca')				
		
		llCreeazaParteneri = loHash.GetValue('lCreeazaParteneri') && creeaza parteneri daca nu exista codul fiscal in baza de date
		llFactura = loHash.GetValue('lFactura')  && se cauta facturi pereche in baza de date
		llComanda = loHash.GetValue('lComanda')  && se cauta comenzi in baza de date


		This.cContBanca = Iif(!Empty(m.lcContBanca), m.lcContBanca, '5121')
		This.cIBAN = Iif(!Empty(m.lcContIBAN), m.lcContIBAN, '')
		This.lCreeazaParteneri = m.llCreeazaParteneri
		This.lFactura = m.llFactura
		This.lComanda = m.llComanda
		This.nIdPartenerBanca = m.lnIdPartenerBanca
		This.cBanca = m.lcBanca
		Return .T.
	Endproc && Init

	**********************
	* Se implementeaza in clasa copil
	**********************
	Procedure Parse
	Endproc && Parse

	**********************
	*** Retrateaza inregistrarile din C_IMPORT_TEMP, le importa in cActTemp si completeaza conturile, partenerii
	**********************
	Procedure CreeazaNote
		Local lcCodFiscal, lcContBanca, lcContC, lcContD, lcContPartener, lcDenumire, lcDocumente
		Local lcFdocExtrasCont, lcFdocOp, lcIBAN, lcPartC, lcPartD, lcPartener, lcPartenerBanca, lcTip
		Local lnDocumente, lnI, lnIdFdocExtrasCont, lnIdFdocOp, lnIdPartC, lnIdPartD, lnIdPartener
		Local lnIdPartenerBanca, lnNr, lnNrAct, lnSuma, loAct, loCauta, llSucces, lcSelect
		Local loDate As "Empty"
		Local lcCont, lcNumeValuta, lcValuta, ldDataIreg, llMonedaNationala, lnCurs, lnIdPartCoresp
		Local lnIdTipPart, lnIdValuta, lnSpecial, lnTipPersoana, loDate2, loValuta, llDocumentPereche
		Local lcRecc, lcRecno, lnRecno
		Local lcComanda, lcDenumire2, lcPartenerCasa, lcTip2, lnVariante, llExcludeOriginal
		Local lnDenumire, lnDocument, lnIdPartenerCasa, lnVariante, loPartener
		Local lcGrupIdLista, lcSqlGrup, lnIdPartAlternativ, lcPartAlternativ

		PRIVATE pcContBanca, pnIdPartBanca
		
		lcSelect = Select()

		llSucces = .T.
		lcFdocOp = ''
		lcFdocExtrasCont = ''
		lnIdFdocOp = 0
		lnIdFdocExtrasCont = 0
		lcNumeValuta = ''
		lnIdValuta = 0
		lnCurs = 0
		llMonedaNationala = .T.

		If Type('gnID_FDOC_OP') = 'N' And !Empty(m.gnID_FDOC_OP)
			lnIdFdocOp = m.gnID_FDOC_OP
			lcFdocOp = GetFdocById(m.gnID_FDOC_OP)
		Endif
		If Type('gnID_FDOC_EXTRASCONT') = 'N' And !Empty(m.gnID_FDOC_EXTRASCONT)
			lnIdFdocExtrasCont = m.gnID_FDOC_EXTRASCONT
			lcFdocExtrasCont = GetFdocById(m.gnID_FDOC_EXTRASCONT)
		Endif

		* llFactura = (GetOptiuneFirma("RC_MT940_DOCUMENTE_PERECHE") = "1")

		lnNr = This.nNr

		lcValuta = This.cValuta && RON/EUR/USD/GBP
		lcContBanca = This.cContBanca && 5121/5124
		lcIBAN = This.cIBAN && contul bancar din extras
		lnIdPartenerBanca = This.nIdPartenerBanca
		lcPartenerBanca = This.cBanca
		lnIdPartenerCasa = 0

		* Partener Banca lei/valuta
		Wait Window 'Cautare partener banca...' Nowait
		If EMPTY(m.lnIdPartenerBanca) AND !Empty(m.lcIBAN)
			lnIdPartenerBanca = GetIdPartenerByContBanca(m.lcIBAN)
		Endif
		If Empty(m.lnIdPartenerBanca)
			If !Empty(m.lcIBAN)
				AMESSAGEBOX('Nu exista nici un partener tip Banca ' + m.lcContBanca + ' cu contul bancar ' + m.lcIBAN + Chr(13) + Chr(10) + ;
					  'Alegeti Banca ' + m.lcContBanca + ' pentru inregistrarea extrasului!', 0 + 64, _Screen.Caption)
			Endif
			loCauta = CautPartenerContabilitate(GetHash([cTitlu=>Banca??cCont=>] + m.lcContBanca))
			lnIdPartenerBanca = NVL(loCauta.id_part, 0)
			lcPartenerBanca = Alltrim(m.loCauta.denumire)

			IF !EMPTY(m.lnIdPartenerBanca) AND AMESSAGEBOX('Doriti sa salvati contul bancar: ' + m.lcIBAN + ' pe acest partener?',4+32,_screen.Caption) = 6
				pcContBanca = m.lcIBAN
				pnIdPartBanca = m.lnIdPartenerBanca
				llSucces = goExecutor.oExecuta('UPDATE NOM_PARTENERI SET CONT_BANCA = ?pcContBanca WHERE ID_PART = ?pnIdPartBanca')
			ENDIF 
		Endif
		If Empty(m.lcPartenerBanca) And !Empty(m.lnIdPartenerBanca)
			lcPartenerBanca = GetDenumirePartenerById(m.lnIdPartenerBanca)
		Endif


		* Valuta
		If !Empty(m.lcValuta)
			loValuta = GetValutaByISO(m.lcValuta)
			lcNumeValuta = Alltrim(loValuta.nume_val)
			lnIdValuta = loValuta.id_valuta
			llMonedaNationala = (loValuta.moneda_nationala = 1)
		Endif

		* Comasez comisioanele TIP_2 = COM
		Select Data, Sum(suma) As comision, Count(suma) As nr_comision From C_IMPORT_TEMP Where tip_2 = this.cTipComisioane Group By Data Into Cursor C_COMISION
		Scan
			For lnI = 1 To C_COMISION.nr_comision - 1
				Select C_IMPORT_TEMP
				Locate For tip_2 = this.cTipComisioane .And. Data = C_COMISION.Data
				If Found()
					Delete
				Endif
			Endfor
			Select C_IMPORT_TEMP
			Locate For tip_2 = this.cTipComisioane .And. Data = C_COMISION.Data
			If Found()
				Replace suma With C_COMISION.comision
			Endif
		Endscan

		USE IN (SELECT('C_COMISION'))

		* Comasez comisioanele procesatori plati TIP_2 = CDT
		Select Data, Sum(suma) As comision, Count(suma) As nr_comision From C_IMPORT_TEMP Where tip_2 = this.cTipComisionDecont Group By Data Into Cursor C_COMISION
		Scan
			For lnI = 1 To C_COMISION.nr_comision - 1
				Select C_IMPORT_TEMP
				Locate For tip_2 = this.cTipComisionDecont .And. Data = C_COMISION.Data
				If Found()
					Delete
				Endif
			Endfor
			Select C_IMPORT_TEMP
			Locate For tip_2 = this.cTipComisionDecont .And. Data = C_COMISION.Data
			If Found()
				Replace suma With C_COMISION.comision
			Endif
		Endscan

		USE IN (SELECT('C_COMISION'))

		Select cActTemp
		Append From Dbf('C_IMPORT_TEMP')
		
		* Caut/creez parteneri
		Create Cursor cGrupParteneriCui (id_part_ales N(9), id_part N(9), denumire C(100))
		SELECT distinct cod_fiscal, denumire, iban FROM cActTemp INTO CURSOR cParteneriTemp READWRITE 
		SELECT cParteneriTemp
		lcRecc = Transform(Reccount())		
		SCAN
			lcCodFiscal = Upper(Alltrim(cod_fiscal))
			lcDenumire = Upper(Alltrim(denumire))
			lcIBan = UPPER(ALLTRIM(NVL(iban,'')))
			lcRecno = Transform(Recno())
			lnIdPartener = 0

			Wait Window 'Cautare parteneri ' + Transform(Recno()) + '/' + m.lcRecc Nowait
			IF INKEY(0.5) = 27
				IF AMESSAGEBOX('Doriti sa renuntati?',4+32,_screen.Caption) = 6
					llSucces = .F.
					EXIT 
				ENDIF 
			ENDIF 
			* Caut partener dupa cod fiscal
			If !Empty(m.lcCodFiscal)
				Wait Window 'Import inregistrare ' + m.lcRecno + '/' + m.lcRecc + ' - cautare partener cod fiscal' Nowait
				loPartener = GetPartenerByCodFiscal(m.lcCodFiscal)
				If !Isnull(loPartener)
					lnIdPartener = Nvl(loPartener.id_part, 0)
					lcPartener = Alltrim(Nvl(loPartener.denumire, ""))
					If GetParteneriByCuiNormalizat(m.lcCodFiscal, "cGrupCuiTemp") And Reccount("cGrupCuiTemp") > 1
						lcGrupIdLista = ""
						Select cGrupCuiTemp
						Scan
							lcGrupIdLista = m.lcGrupIdLista + Iif(Empty(m.lcGrupIdLista), "", ",") + Transform(id_part)
						Endscan
						lcSqlGrup = [select id_part, count(*) as nr, sum(precdeb + debit - preccred - credit) as sold from ireg_parteneri ] + ;
							[where an = ?gnAn and luna = ?gnLuna and id_part in (] + m.lcGrupIdLista + [) group by id_part ] + ;
							[order by count(*) desc, abs(sum(precdeb + debit - preccred - credit)) desc]
						If goExecutor.oExecuta(m.lcSqlGrup, "cGrupCuiDoc") And Reccount("cGrupCuiDoc") > 0
							Select cGrupCuiTemp
							Locate For id_part = cGrupCuiDoc.id_part
							If Found()
								lnIdPartener = cGrupCuiTemp.id_part
								lcPartener = Alltrim(Nvl(cGrupCuiTemp.denumire, ""))
							Endif
						Endif
						If Used("cGrupCuiDoc")
							Use In (Select("cGrupCuiDoc"))
						Endif
						Select cGrupCuiTemp
						Scan
							Insert Into cGrupParteneriCui (id_part_ales, id_part, denumire) Values (m.lnIdPartener, cGrupCuiTemp.id_part, Alltrim(Nvl(cGrupCuiTemp.denumire, "")))
						Endscan
					Endif
					If Used("cGrupCuiTemp")
						Use In (Select("cGrupCuiTemp"))
					Endif
				Endif
			Endif
			* Caut partener dupa denumire
			If Empty(m.lnIdPartener) And !Empty(m.lcDenumire)
				Wait Window 'Import inregistrare ' + m.lcRecno + '/' + m.lcRecc + ' - cautare partener denumire' Nowait
				loPartener = GetPartenerByDenumire(m.lcDenumire)
				If !Isnull(loPartener)
					lnIdPartener = Nvl(loPartener.id_part, 0)
					lcPartener = Alltrim(Nvl(loPartener.denumire, ""))
				ENDIF 
				IF EMPTY(m.lnIdPartener) 
 					* Caut si alte variante de denumiri (nume prenume1 prenume2, prenume1 prenume2 nume)
					llExcludeOriginal = .T.
					lcVariante = GetNamePermutations(m.lcDenumire, m.llExcludeOriginal)
					lnVariante = GETWORDCOUNT(m.lcVariante, ';')
					FOR lnDenumire = 1 TO m.lnVariante
						lcDenumire2 = GETWORDNUM(m.lcVariante, m.lnDenumire, ';')
					
						loPartener = GetPartenerByDenumire(m.lcDenumire2)
						If !Isnull(loPartener) AND !EMPTY(Nvl(loPartener.id_part, 0))
							lnIdPartener = Nvl(loPartener.id_part, 0)
							lcPartener = Alltrim(Nvl(loPartener.denumire, ""))
							EXIT 
						ENDIF
					ENDFOR 	
				ENDIF && EMPTY(m.lnIdPartener)	
			ENDIF

			* Caut partener dupa IBAN
			If Empty(m.lnIdPartener) And !Empty(m.lcIBan)
				Wait Window 'Import inregistrare ' + m.lcRecno + '/' + m.lcRecc + ' - cautare partener IBAN' Nowait
				loPartener = GetPartenerByContBanca(m.lcIBAN)
				If !Isnull(loPartener)
					lnIdPartener = Nvl(loPartener.id_part, 0)
					lcPartener = Alltrim(Nvl(loPartener.denumire, ""))
				Endif
			ENDIF
						
			* Creez partenerul daca nu l-am gasit dupa cod fiscal sau dupa denumire si doar daca are cod fiscal
			* Altfel poate sa existe, dar cu denumire diferita
			If This.lCreeazaParteneri And Empty(m.lnIdPartener) And !Empty(m.lcCodFiscal)
				Wait Window 'Import inregistrare ' + m.lcRecno + '/' + m.lcRecc + ' - adaugare partener' Nowait
				loDate = Createobject("Empty")
				AddProperty(loDate, "cod_fiscal", m.lcCodFiscal)
				AddProperty(loDate, "denumire", m.lcDenumire)
				AddProperty(loDate, "id_part", m.lnIdPartener)
				lnIdTipPart = Iif(m.lcTip = "D", 17, 16) && furnizor/client
				AddProperty(loDate, "tip_partener", m.lnIdTipPart)
				lnTipPersoana = Iif(Len(m.lcCodFiscal) < 13, 1, 2) && persoana juridica/fizica
				AddProperty(loDate, "tip_persoana", m.lnTipPersoana)
				loDate2 = nom_parteneri_nou(, , , , , m.loDate)
				lnIdPartener = Nvl(loDate2.id_part, 0)
				lcPartener = Alltrim(Nvl(loDate2.denumire, ''))
			ENDIF

			IF !EMPTY(m.lnIdPartener)
				UPDATE cActTemp SET id_part = m.lnIdPartener, partener = m.lcPartener WHERE UPPER(ALLTRIM(cod_fiscal)) = m.lcCodFiscal AND Upper(Alltrim(denumire)) = m.lcDenumire
			ENDIF 
									
		ENDSCAN && cParteneriTemp
		USE IN (SELECT('cParteneriTemp'))

		* Completez conturi, parteneri
		Select cActTemp
		lcRecc = Transform(Reccount())
		Scan
			lcContD = ""
			lcContC = ""
			lnIdPartener = NVL(id_part,0)
			lnIdPartD = 0
			lnIdPartC = 0
			lcPartD = ""
			lcPartC = ""
			lcPartener = ALLTRIM(partener)
			lcContPartener = ""
			lcTip = Alltrim(tip)
			lcTip2 = Alltrim(tip_2)

			lcCodFiscal = Upper(Alltrim(cod_fiscal))
			lcDenumire = Upper(Alltrim(denumire))
			lnRecno = RECNO()
			lcRecno = Transform(m.lnRecno)

			Wait Window 'Import inregistrare ' + Transform(Recno()) + '/' + m.lcRecc Nowait
			IF MOD(m.lnRecno, 100) = 0 
				IF INKEY(0.5) = 27
					IF AMESSAGEBOX('Doriti sa renuntati?',4+32,_screen.Caption) = 6
						llSucces = .F.
						EXIT 
					ENDIF 
				ENDIF 
			ENDIF 
			IF .F. && am facut cautarea partenerilor separat
				* Caut partener dupa cod fiscal
				If !Empty(m.lcCodFiscal)
					Wait Window 'Import inregistrare ' + m.lcRecno + '/' + m.lcRecc + ' - cautare partener cod fiscal' Nowait
					loPartener = GetPartenerByCodFiscal(m.lcCodFiscal)
					If !Isnull(loPartener)
						lnIdPartener = Nvl(loPartener.id_part, 0)
						lcPartener = Alltrim(Nvl(loPartener.denumire, ""))
					Endif
				Endif
				* Caut partener dupa denumire
				If Empty(m.lnIdPartener) And !Empty(m.lcDenumire)
					Wait Window 'Import inregistrare ' + m.lcRecno + '/' + m.lcRecc + ' - cautare partener denumire' Nowait
					loPartener = GetPartenerByDenumire(m.lcDenumire)
					If !Isnull(loPartener)
						lnIdPartener = Nvl(loPartener.id_part, 0)
						lcPartener = Alltrim(Nvl(loPartener.denumire, ""))
					Endif
				Endif

				* Creez partenerul daca nu l-am gasit dupa cod fiscal sau dupa denumire
				If This.lCreeazaParteneri And Empty(m.lnIdPartener) And !(Empty(m.lcCodFiscal) And Empty(m.lcDenumire))
					Wait Window 'Import inregistrare ' + m.lcRecno + '/' + m.lcRecc + ' - adaugare partener' Nowait
					loDate = Createobject("Empty")
					AddProperty(loDate, "cod_fiscal", m.lcCodFiscal)
					AddProperty(loDate, "denumire", m.lcDenumire)
					AddProperty(loDate, "id_part", m.lnIdPartener)
					lnIdTipPart = Iif(m.lcTip = "D", 17, 16) && furnizor/client
					AddProperty(loDate, "tip_partener", m.lnIdTipPart)
					lnTipPersoana = Iif(Len(m.lcCodFiscal) < 13, 1, 2) && persoana juridica/fizica
					AddProperty(loDate, "tip_persoana", m.lnTipPersoana)
					loDate2 = nom_parteneri_nou(, , , , , m.loDate)
					lnIdPartener = Nvl(loDate2.id_part, 0)
					lcPartener = Alltrim(Nvl(loDate2.denumire, ''))
				ENDIF
			ENDIF && .F.


			*!*				If !Empty(m.lnIdPartener)
			*!*					WAIT WINDOW 'Import inregistrare ' + TRANSFORM(RECNO()) + '/' + m.lcRecc + ' - cautare denumire partener' NOWAIT
			*!*					lcPartener = GetDenumirePartenerById(m.lnIdPartener)
			*!*				Endif

			Wait Window 'Import inregistrare ' + m.lcRecno + '/' + m.lcRecc + ' - completare conturi' Nowait
			If m.lcTip = "D"
				lcContC = m.lcContBanca
				lnIdPartC = m.lnIdPartenerBanca
				lcPartC = m.lcPartenerBanca

				lnIdPartD = m.lnIdPartener
				lcPartD = m.lcPartener

				Do Case
					Case m.lcTip2 = This.cTipComisioane && "COM" && comision
						lcContD = "627"
					Case m.lcTip2 = This.cTipTaxe && "CHG" && comisioane, taxe
						lcContD = "627"
					Case m.lcTip2 = This.cTipCec && "CHK" && cec-uri, efecte de primit/platit
						lcContD = "403"
					Case m.lcTip2 = This.cTipDobanzi && "INT" && venituri/cheltuieli cu dobanzi
						lcContD = "666"
					Case m.lcTip2 = This.cTipAlte && "ALT" && alte cheltuieli/venituri exploatare
						lcContD = "6588"
					Case m.lcTip2 = This.cTipTerti && "TRF" && terti (clienti/furnizori)
						lcContD = "401"
					Case m.lcTip2 = This.cTipBuget && "BUG" && datorii la buget
						lcContD = "4481"
					Case m.lcTip2 = This.cTipTransfer && "TRS" transfer intre conturi
						lcContD = "581"
					Case m.lcTip2 = This.cTipDepunere && "DEP" depunere/retragere numerar
						lcContD = "581"
					Case m.lcTip2 = This.cTipEfecteComerciale && "EFT" efecte comerciale
						lcContD = "403"
					Case m.lcTip2 = This.cTipComisionDecont && "CDT" comision procesatori plati
						lcContD = "473"						
					Otherwise
						lcContD = "581"
				Endcase
				lcContPartener = m.lcContD
			Else
				lcContD = m.lcContBanca
				lnIdPartD = m.lnIdPartenerBanca
				lcPartD = m.lcPartenerBanca

				lnIdPartC = m.lnIdPartener
				lcPartC = m.lcPartener

				Do Case
					Case m.lcTip2 = This.cTipDobanzi && "INT" && venituri/cheltuieli cu dobanzi
						lcContC = "766"
					Case m.lcTip2 = This.cTipAlte && "ALT" && alte cheltuieli/venituri exploatare
						lcContC = "7588"
					Case m.lcTip2 = This.cTipCec && "CHK" && cec-uri, efecte de primit/platit
						lcContC = "413"
					Case m.lcTip2 = This.cTipTerti && "TRF" && terti (clienti/furnizori)
						lcContC = "4111"
					Case m.lcTip2 = This.cTipBuget && "BUG" && creante de la buget
						lcContC = "4482"
					Case m.lcTip2 = This.cTipTransfer && transfer intre conturi
						lcContC = "581"
					Case m.lcTip2 = This.cTipDepunere && depunere/retragere numerar
						lcContC = "581"
					Case m.lcTip2 = This.cTipEfecteComerciale && "EFE" efecte comerciale
						lcContC = "413"
					Otherwise
						lcContC = "581"
				Endcase
				lcContPartener = m.lcContC
			Endif

			Select cActTemp
			Replace scd With m.lcContD, scc With m.lcContC, id_partd With m.lnIdPartD, id_partc With m.lnIdPartC, partd With m.lcPartD, partc With m.lcPartC
			Replace id_valuta With m.lnIdValuta, nume_val With m.lcNumeValuta
			If !m.llMonedaNationala
				IF curs = 0
					REPLACE curs WITH 1
				ENDIF 
				Replace suma_val With suma
				Replace suma With ROUND(suma_val * curs, m.gnPC)

			Endif

			* TODO?
			* Intorc cursorul cu facturi al clientului si contului respectiv
			* Repet pana la epuizarea sumei de plata/incasare sau pana cand nu mai este sold de imperecheat
			* Caut documentele gasite in cursorul cu facturi si imprechez suma pe facturile din cursor
			* Daca nu mai am documente, dar suma de plata nu este epuizata, imperechez facturile in ordine cronologica
			* Adaug facturile imperecheate

			* Acum asociez doar UN SINGUR DOCUMENT, daca este completat in detaliile operatiei
			* Incerc sa aflu documentul pereche dupa cont, partener, suma, numar document doar daca am un singur document!!! daca sunt mai multe se complica cazurile
			If This.lFactura && daca este configurata optiunea sa se caute documentele pereche
				lcDocumente = Alltrim(NVL(cActTemp.documente,''))
				
				* Fortez cautarea chiar daca nu are documente
				* Vreau sa gasesc 
				IF EMPTY(m.lcDocumente)
					lcDocumente = '0'
				ENDIF 
				lnSuma = cActTemp.suma
				lnDocumente = Getwordcount(m.lcDocumente, ",")
				If !Empty(m.lnIdPartener) And m.lnDocumente > 0
					FOR lnDocument = 1 TO m.lnDocumente
						lnNrAct = Int(Val(Getwordnum(m.lcDocumente, m.lnDocument, ",")))
						Wait Window 'Import inregistrare ' + m.lcRecno + '/' + m.lcRecc + ' - cautare factura: ' + Transform(m.lnNrAct) Nowait
						loAct = GetDocumentByContPartenerAct(m.lcContPartener, m.lnIdPartener, m.lnNrAct, .F.)
						* daca am gasit un document si suma este mai mica decat soldul facturii (daca erau mai multe documente puteau fi si sume diferite)
						If !Empty(m.loAct.id_fact)
							Select cActTemp
							If m.lcTip = "D" And m.lnSuma <= - m.loAct.solddeb
								Replace id_factd With m.loAct.id_fact, pereched With m.loAct.nract, scd With m.loAct.Cont, ascd With m.loAct.acont
							Else
								If m.lcTip = "C" And m.lnSuma <= m.loAct.solddeb
									Replace id_factc With m.loAct.id_fact, perechec With m.loAct.nract, scc With m.loAct.Cont, ascc With m.loAct.acont
								Endif
							ENDIF
							* Daca am gasit un document, ies din bucla
							EXIT
						Else
							lnIdPartAlternativ = 0
							If Used("cGrupParteneriCui")
								Select cGrupParteneriCui
								Scan For id_part_ales = m.lnIdPartener And id_part <> m.lnIdPartener
									lcPartAlternativ = Alltrim(denumire)
									loAct = GetDocumentByContPartenerAct(m.lcContPartener, id_part, m.lnNrAct, .F.)
									If !Empty(m.loAct.id_fact) And ((m.lcTip = "D" And m.lnSuma <= - m.loAct.solddeb) Or (m.lcTip = "C" And m.lnSuma <= m.loAct.solddeb))
										lnIdPartAlternativ = id_part
										Exit
									Endif
									Select cGrupParteneriCui
								Endscan
							Endif
							Select cActTemp
							If !Empty(m.lnIdPartAlternativ)
								Select cActTemp
								If m.lcTip = "D"
									Replace id_factd With m.loAct.id_fact, pereched With m.loAct.nract, scd With m.loAct.Cont, ascd With m.loAct.acont, id_partd With m.lnIdPartAlternativ, partd With m.lcPartAlternativ
								Else
									Replace id_factc With m.loAct.id_fact, perechec With m.loAct.nract, scc With m.loAct.Cont, ascc With m.loAct.acont, id_partc With m.lnIdPartAlternativ, partc With m.lcPartAlternativ
								Endif
								EXIT
							Endif
						ENDIF && !Empty(m.loAct.id_fact)
					ENDFOR && lnDocument 	
				ENDIF && !Empty(m.lnIdPartener) And m.lnDocumente > 0
			ENDIF && This.lFactura


			* Acum asociez doar UN SINGUR DOCUMENT, daca este completat in detaliile operatiei
			* Incerc sa aflu documentul pereche dupa cont, partener, suma, numar document doar daca am un singur document!!! daca sunt mai multe se complica cazurile
			If This.lComanda && daca este configurata optiunea sa se caute documentele pereche dupa comanda
				lcDocumente = Alltrim(cActTemp.comenzi)
				lnSuma = cActTemp.suma
				lnDocumente = Getwordcount(m.lcDocumente, ",")
				If !Empty(m.lnIdPartener) And m.lnDocumente > 0
					FOR lnDocument = 1 TO m.lnDocumente
						lcComanda = Getwordnum(m.lcDocumente, m.lnDocument, ",")
						Wait Window 'Import inregistrare ' + m.lcRecno + '/' + m.lcRecc + ' - cautare factura pentru comanda: ' + Transform(m.lcComanda) Nowait
						loAct = GetDocumentByContPartenerAct(m.lcContPartener, m.lnIdPartener, m.lcComanda, .T.)
						* daca am gasit un document si suma este mai mica decat soldul facturii (daca erau mai multe documente puteau fi si sume diferite)
						If !Empty(m.loAct.id_fact)
							Select cActTemp
							If m.lcTip = "D" And m.lnSuma <= - m.loAct.solddeb
								Replace id_factd With m.loAct.id_fact, pereched With m.loAct.nract, scd With m.loAct.Cont, ascd With m.loAct.acont
							Else
								If m.lcTip = "C" And m.lnSuma <= m.loAct.solddeb
									Replace id_factc With m.loAct.id_fact, perechec With m.loAct.nract, scc With m.loAct.Cont, ascc With m.loAct.acont
								Endif
							ENDIF
							* Daca am gasit un document, ies din bucla
							EXIT
						Else
							lnIdPartAlternativ = 0
							If Used("cGrupParteneriCui")
								Select cGrupParteneriCui
								Scan For id_part_ales = m.lnIdPartener And id_part <> m.lnIdPartener
									lcPartAlternativ = Alltrim(denumire)
									loAct = GetDocumentByContPartenerAct(m.lcContPartener, id_part, m.lcComanda, .T.)
									If !Empty(m.loAct.id_fact) And ((m.lcTip = "D" And m.lnSuma <= - m.loAct.solddeb) Or (m.lcTip = "C" And m.lnSuma <= m.loAct.solddeb))
										lnIdPartAlternativ = id_part
										Exit
									Endif
									Select cGrupParteneriCui
								Endscan
							Endif
							Select cActTemp
							If !Empty(m.lnIdPartAlternativ)
								Select cActTemp
								If m.lcTip = "D"
									Replace id_factd With m.loAct.id_fact, pereched With m.loAct.nract, scd With m.loAct.Cont, ascd With m.loAct.acont, id_partd With m.lnIdPartAlternativ, partd With m.lcPartAlternativ
								Else
									Replace id_factc With m.loAct.id_fact, perechec With m.loAct.nract, scc With m.loAct.Cont, ascc With m.loAct.acont, id_partc With m.lnIdPartAlternativ, partc With m.lcPartAlternativ
								Endif
								EXIT
							Endif
						ENDIF && !Empty(m.loAct.id_fact)
					ENDFOR && lnDocument 	
				ENDIF && !Empty(m.lnIdPartener) And m.lnDocumente > 0
			ENDIF && This.lComanda 
			
		ENDSCAN && cActTemp
		
		* Completez acum numar document ca sa pot adauga note de retragere/depunere numerar cu acelasi numar document ca si transferul din banca
		UPDATE cActTemp SET nr = INT(VAL(DTOS(data) + ALLTRIM(STR(RECNO())))) WHERE EMPTY(NVL(nr,0))
		
		* Adaug linii retragere/depunere numerar 5311 = 581 / 581 = 5311 corespunzatoare 581 = 5121 / 5121 = 581
		IF m.llSucces
			SELECT *, -1*RECNO() as nr2 FROM cActTemp WHERE Alltrim(tip_2) = This.cTipDepunere AND (ALLTRIM(scd) = '581' OR ALLTRIM(scc) = '581') INTO CURSOR cNumerarTemp READWRITE 
			IF _tally > 0
				loCauta = CautPartenerContabilitate(GetHash([cTitlu=>Alegeti Casa pentru retragere/depunere numerar??cCont=>5311]))
				lnIdPartenerCasa = NVL(loCauta.id_part, 0)
				lcPartenerCasa = Alltrim(loCauta.denumire)

				If Empty(m.lcPartenerCasa) And !Empty(m.lnIdPartenerCasa)
					lcPartenerCasa = GetDenumirePartenerById(m.lnIdPartenerCasa)
				ENDIF
			
				SELECT cNumerarTemp
				SCAN
					IF ALLTRIM(scd) = '581'
						REPLACE scd WITH '5311', scc WITH '581', id_partc WITH 0, partc WITH '', id_partd WITH m.lnIdPartenerCasa, partd WITH m.lcPartenerCasa
					ELSE
						REPLACE scd WITH '581', scc WITH '5311', id_partd WITH 0, partd WITH '', id_partc WITH m.lnIdPartenerCasa, partc WITH m.lcPartenerCasa				
					ENDIF
					IF EMPTY(NVL(nr, 0))
						REPLACE nr WITH nr2  && folosesc nr = recno negativ, sa completez acelasi numar document ca la linia retragere numerar
					ENDIF 	
				ENDSCAN 
				
				SELECT cActTemp
				APPEND FROM DBF('cNumerarTemp')
			ENDIF 
			USE IN (SELECT('cNumerarTemp'))
		ENDIF && llSucces
 
		IF m.llSucces
			* Completez fel document cu EXTRAS CONT pentru inregistrarile cu nr = nr extras si cu ORDIN PLATA pentru inregistrarile cu nr diferit de nr extras
*!*				Replace All id_fdoc With Iif(nr = m.lnNr, m.lnIdFdocExtrasCont, Iif(!Empty(nr), m.lnIdFdocOp, id_fdoc))
*!*				Replace All fdoc With Iif(nr = m.lnNr, m.lcFdocExtrasCont, Iif(!Empty(nr), m.lcFdocOp, fdoc))
			Replace All id_fdoc With m.lnIdFdocExtrasCont, fdoc With m.lcFdocExtrasCont IN cActTemp

			Wait Window 'Verificare conturi fara parteneri/documente' Nowait

			* sterg partenerii si documentele pereche de pe conturile care nu au parteneri, documente
			llSucces = goExecutor.oExecuta('SELECT distinct cont, cu_inregistrari FROM vconfig_cont_ireg order by cont', 'cConturiPartTemp')
			If m.llSucces
				Select a.Cont, Iif(!Isnull(b.Cont), 1, 0) As epart, Nvl(b.cu_inregistrari, 0) As cu_inregistrari ;
					From (Select scd As Cont From cActTemp ;
					  Union ;
					  Select scc As Cont From cActTemp) a Left Join cConturiPartTemp b On a.Cont = b.Cont ;
					Into Cursor cConturiTemp

				Select cConturiTemp
				Scan For epart = 0
					lcCont = Alltrim(Cont)
					If epart = 0
						Update cActTemp Set id_partd = 0, partd = '', id_factd = 0, pereched = 0 Where Alltrim(scd) = m.lcCont
						Update cActTemp Set id_partc = 0, partc = '', id_factc = 0, perechec = 0 Where Alltrim(scc) = m.lcCont
					Else
						If cu_inregistrari = 0
							Update cActTemp Set id_factd = 0, pereched = 0 Where Alltrim(scd) = m.lcCont
							Update cActTemp Set id_factc = 0, perechec = 0 Where Alltrim(scc) = m.lcCont
						Endif
					Endif
				Endscan
				Use In (Select('cConturiTemp'))
				Use In (Select('cConturiPartTemp'))
			Endif && llSucces

			ldDataIreg = Gomonth(Date(m.gnAn, m.gnLuna, 1), 1) - 1
			If Type('gnIdSucursala') = 'U'
				Local gnIdSucursala
				gnIdSucursala = 0
			Endif
			If Type('gcSucursala') = 'U'
				Local gcSucursala
				gcSucursala = Iif(!Empty(Nvl(m.gnIdSucursala, 0)), m.gcFirma, '')
			Endif

			Select nr As nract, Data As dataact, Iif(Year(Data) * 12 + Month(Data) = m.gnAn * 12 + m.gnLuna, Data, m.ldDataIreg) As dataireg, suma, ;
				suma_val, nume_val, id_valuta, Curs, ;
				Cast(Upper(Alltrim(explicatie) + Iif(!Empty(Nvl(denumire, '')), ' ' + Alltrim(denumire), '') + ;
					Iif(!Empty(Nvl(cod_fiscal, '')), ' ' + Alltrim(cod_fiscal), '')) As C(100)) As explicatia, ;
				M.lcIBAN As explicatia4, ;
				scd, scc, ascd, ascc, id_partd, id_partc, partd, partc, ;
				id_factd, id_factc, pereched, perechec, ;
				id_fdoc, fdoc, ;
				Cast(gnIdSucursala As N(5) Null) As id_sucursala, Space(200) As sucursala ;
				From cActTemp ;
				Order By Data ;
				Into Cursor cActTemp2 Readwrite

			* Dadea eroare cand puneam cast(m.gnIdSucursala as I)
			Update cActTemp2 Set id_sucursala = m.gnIdSucursala, sucursala = m.gcSucursala
			Delete From cActTemp2 Where suma = 0

			Use In (Select('cActTemp'))
			Select * From cActTemp2 Into Cursor cActTemp Readwrite
			Use In (Select('cActTemp2'))
			Select (m.lcSelect)
		ENDIF && llSucces	

		If Used("cGrupParteneriCui")
			Use In (Select("cGrupParteneriCui"))
		Endif

		Return m.llSucces
	Endproc && CreeazaNote

Enddefine && ExtrasBanca


Define Class ExtrasBanca_MT940 As ExtrasBanca
	cDescription = 'clasa generica import extras MT940'

	*****************************
	*** Parseaza liniile din extras si le introduce in cursorul C_IMPORT_TEMP
	*****************************
	Procedure Parse

		Local lcBanca, lcCodFiscal, lcCursor, lcDenumire, lcDescriere, lcExtraRand, lcFacturi, lcFile
		Local lcIBAN, lcRand, lcRand1, lcRefDoc, lcTip, lcTip2, ldData, lnLinie, lnLinii, lnNr, lnPos
		Local lnPozitieN, lnRand, lnResults, lnSuma, llSucces

		lcFile = This.cFile
		lnLinii = 0
		If File(m.lcFile)
			lnLinii = Alines(This.aLinii, Filetostr(m.lcFile), 1)
			lnLinii = Iif(Empty(m.lnLinii), 0, m.lnLinii)
			This.nLinii = m.lnLinii
		Endif
		llSucces = .T.

		If m.lnLinii = 0
			This.lError = .T.
			llSucces = .F.
			This.cErrorMessage = This.cErrorMessage + Iif(!Empty(This.cErrorMessage), Chr(13), '') + 'Fisierul este gol!'
		Endif

		* Verific antetul fisierului
		If m.llSucces
			llSucces = .F.
			* verifica daca exista :25 in primele 20 linii
			For lnLinie = 1 To 20
				lcRand = Alltrim(This.aLinii[m.lnLinie])
				If Left(m.lcRand, 4) = ':25:'
					llSucces = .T.
					Exit
				Endif
			Endfor
			If !m.llSucces
				This.lError = .T.
				This.cErrorMessage = This.cErrorMessage + Iif(!Empty(This.cErrorMessage), Chr(13), '') + 'Nu corespunde structura fisierului!'
			Endif
		Endif

		If m.llSucces
			Select C_IMPORT_TEMP
			lnLinii = This.nLinii
			For lnLinie = 1 To m.lnLinii
				lcRand = Alltrim(This.aLinii[m.lnLinie])
				ldData = ''
				lcTip = ''
				lcTip2 = ''
				lnSuma = 0

				Do Case
					Case Left(m.lcRand, 4) = ':25:' && cont bancar
						* :25:RO57RZBR0000060011634808
						This.cIBAN = Upper(Alltrim(Substr(m.lcRand, 5))) && RO57RZBR0000060011634808
						This.cBIC = Substr(m.lcRand, 9, 4) && RZBR

					Case Left(m.lcRand, 5) = ':28C:' && numar extras/statement number
						* :28C:213/1
						This.nNr = Int(Val(Substr(m.lcRand, 6))) && 213

					Case Left(m.lcRand, 4) = ':61:' && tranzactie master, pe un singur rand
						* :61:1712201220D82665,12NTRF32871258//3A9H3KUEDK5T72I
						* :61:1712201220D3141,04NTRFNONREF//3A9H3KUEDK5T73M
						* :61:1712201220D8,00NCOMNONREF//3A9H3KUEDK5T73W
						ldData = Ctod(Substr(m.lcRand, 9, 2) + "." + Substr(m.lcRand, 7, 2) + ".20" + Substr(m.lcRand, 5, 2))
						lcTip = Substr(m.lcRand, 15, 1) && D/C
						lcRand = Substr(m.lcRand, 16) && 82665,12NTRF32871258//3A9H3KUEDK5T72I
						lnPozitieN = At("N", m.lcRand)
						lnSuma = Val(Strtran(Substr(m.lcRand, 1, m.lnPozitieN - 1), ",", ".")) && 82665.12
						lcTip2 = Substr(m.lcRand, m.lnPozitieN + 1, 3) && TRF

						Select C_IMPORT_TEMP
						Append Blank
						Replace Data With m.ldData, suma With m.lnSuma, tip With m.lcTip, tip_2 With m.lcTip2

						If !'NONREF' $ m.lcRand
							lnPos = At('/', m.lcRand) && && 82665,12NTRF32871258//3A9H3KUEDK5T72I
							lcCodFiscal = Substr(m.lcRand, m.lnPozitieN + 4, m.lnPos - m.lnPozitieN - 4) && 32871258
							Replace cod_fiscal With m.lcCodFiscal
						Endif
						*** Se poate sa mai existe o linie suplimentara cu detalii pentru :61:


					Case Left(m.lcRand, 4) = ":86:" && tranzactie detalii, maxim 6 randuri
						* Completez randul :86: cu liniile urmatoare, pana la intalnirea liniei :61:,:62:, ':6x:'

						* :86:000^20C/V F. 54^24Ref.Doc 1501/OPIB^30GE GARAN
						* TI BANK S.A.^31RO68UGBI0000442012404RON^32ADINA SI
						*  CAMI UNIVERS SRL
						* :61:1712201220D13,74NCOMNONREF//3A9H3KUEDK5T72S

						lcExtraRand = ""
						lcRand1 = m.lcRand
						For lnRand = 1 To 5
							lnLinie = m.lnLinie + 1 && avansez 1 linie
							IF m.lnLinie > m.lnLinii
								EXIT 
							ENDIF 
							lcExtraRand = This.aLinii[m.lnLinie]
							If Left(m.lcExtraRand, 2) = ':6'
								lnLinie = m.lnLinie - 1 && revin 1 linie
								Exit
							Else
								lcRand1 = m.lcRand1 + m.lcExtraRand
							Endif
						Endfor
						lcRand = m.lcRand1

						lcDescriere = Strextract(m.lcRand, '^20', '^', 1, 1 + 2) && 20: descriere: C/V F. 54
						* Array sau lista cu numere de facturi separate prin "," daca exista in descriere
						lcFacturi = ''
						*!*							lnResults = GetRegExpAll(m.lcDescriere, '\d+', @m.lcFacturi)
						lnResults = GetRegExpAllNumbers(m.lcDescriere, @m.lcFacturi)

						lcRefDoc = Strextract(m.lcRand, '^24', '^', 1, 1 + 2) && 24: document plata: Ref.Doc 1501/OPIB
						lnNr = 0
						If 'ref.doc' $ Lower(m.lcRefDoc)
							lnNr = Int(Val(Strextract(m.lcRefDoc, 'ref.doc', '/', 1, 1 + 2)))
						Endif
						lcBanca = Strextract(m.lcRand, '^30', '^', 1, 1 + 2) && 30: banca tert: GE GARANTI BANK S.A.
						lcIBAN = Strextract(m.lcRand, '^31', '^', 1, 1 + 2) && 31: cont bancar tert: RO68UGBI0000442012404RON
						lcDenumire = Strextract(m.lcRand, '^32', '^', 1, 1 + 2) && 32: nume tert: ADINA SI CAMI UNIVERS SRL
						Replace iban With m.lcIBAN, denumire With m.lcDenumire, explicatie With m.lcDescriere + '; ' + m.lcRefDoc, nr With m.lnNr, documente With m.lcFacturi
				Endcase
			Endfor && lnLinie = 1 TO lnLinii

			Select C_IMPORT_TEMP
			Replace All nr With This.nNr For Empty(nr)
		Endif && llSucces

		Return m.llSucces

	Endproc && Parse
Enddefine

Define Class ExtrasBanca_RAIFFEISEN_TXT_MT940 As ExtrasBanca_MT940
	* Se poate suprascrie daca RAIFFEISEN are particularitati fata de clasa generica
Enddefine && ExtrasBanca_RAIFFEISEN_TXT_MT940

Define Class ExtrasBanca_CREDITEUROPE_XML As ExtrasBanca

	*****************************
	*** Parseaza liniile din extras si le introduce in cursorul C_IMPORT_TEMP
	*****************************
	Procedure Parse
		Local lcBanca, lcCodFiscal, lcCursor, lcData, lcDenumire, lcDescriere, lcDescriereFacturi
		Local lcExplicatie, lcExtraRand, lcFacturi, lcFile, lcIBAN, lcInfo1, lcInfo1Exemplu, lcInfo2
		Local lcInfo2Exemplu, lcMovements, lcMovementsExemplu, lcNr, lcRand, lcRand1, lcRef, lcRefDoc
		Local lcText, lcTip, lcTip2, ldData, lnCredit, lnDay, lnDebit, lnLinie, lnLinii, lnMonth, lnNr
		Local lnPos, lnPozitieN, lnRand, lnResults, lnSuma, lnYear, llSucces, ldData1, ldData2
		Local loEx As Exception

		lcFile = This.cFile
		lnLinii = 0
		llSucces = .T.

		If File(m.lcFile)
			Text To m.lcInfo1Exemplu Noshow
			<document>
				<sysdate>20210428105248</sysdate>
				<IBAN>RO88FNNB000503152940RO02</IBAN>
				<valuta>RON</valuta>
				<opening_balance>
					<balance>19245.98</balance>
					<date>20210401</date>
				</opening_balance>
			<movements>
			Endtext

			Text To m.lcInfo2Exemplu Noshow
		<closing_balance>
			<balance>22354.81</balance>
			<date>20210428</date>
		</closing_balance>
			Endtext

			Text To m.lcMovementsExemplu Noshow
			<movements>
				<movement>
					<ref>OPIOPRIC/12747148</ref>
					<value_date>20210401</value_date>
					<booking_date>20210401</booking_date>
					<details>Incasare OP/NOTPROVIDED/DOMINUS CONSULT SRL /ROC/srvicii contabilitate conf. contr.//RFB/35</details>
					<tip_plata>OPC</tip_plata>
					<numar_doc>NOTPROVIDED</numar_doc>
					<cui_platitor>15111236</cui_platitor>
					<IBAN_platitor>RO78BTRL01401202699905XX</IBAN_platitor>
					<Denumire_platitor>DOMINUS CONSULT SRL</Denumire_platitor>
					<debit>0.00</debit>
					<credit>600.00</credit>
				</movement>
			</movements>
			Endtext

			lcText = Filetostr(m.lcFile)

			lcInfo1 = Strextract(m.lcText, '<document>', '<movements>', 1, 1)
			lcInfo2 = Strextract(m.lcText, '<closing_balance>', '</closing_balance>', 1, 1)

			lcMovements = Strextract(m.lcText, '<MOVEMENTS>', '</MOVEMENTS>', 1, 1 + 4)

			Try
				lnLinii = Xmltocursor(m.lcMovements, "cMovementsTemp")
			Catch To loEx
				This.lError = .T.
				llSucces = .F.
				This.cErrorMessage = This.cErrorMessage + Iif(!Empty(This.cErrorMessage), Chr(13), '') + 'Nu corespunde structura fisierului!' + ;
					Chr(13) + loEx.Message
				lnLinii = 0
			Endtry
			lnLinii = Iif(Empty(m.lnLinii), 0, m.lnLinii)
			This.nLinii = m.lnLinii
		Endif

		If m.lnLinii = 0
			This.lError = .T.
			llSucces = .F.
			This.cErrorMessage = This.cErrorMessage + Iif(!Empty(This.cErrorMessage), Chr(13), '') + 'Fisierul este gol!'
		Endif

		* Verific antetul fisierului
		If m.llSucces
			If ![<opening_balance>] $ m.lcInfo1
				This.lError = .T.
				llSucces = .F.
				This.cErrorMessage = This.cErrorMessage + Iif(!Empty(This.cErrorMessage), Chr(13), '') + 'Nu corespunde structura fisierului!'
			Endif
		Endif

		If m.llSucces

			This.cIBAN = Upper(Alltrim(Strextract(m.lcInfo1, '<IBAN>', '</IBAN>', 1, 1)))
			This.cValuta = Upper(Alltrim(Strextract(m.lcInfo1, '<valuta>', '</valuta>', 1, 1)))
			If !Inlist(This.cValuta, 'RON', 'LEI', 'ROL')
				This.cContBanca = '5124' && banca valuta
			Endif
			
			ldData1 = This.dData1
			ldData2 = this.dData2
			
			This.nNr = Int(Val(Strextract(m.lcInfo2, '<date>', '</date>', 1, 1))) && numarul extrasului il consider data de sfarsit a extrasului
			Select cMovementsTemp
			Scan
				lcData = Alltrim(Transform(value_date))
				lnYear = Int(Val(Substr(m.lcData, 1, 4)))
				lnMonth = Int(Val(Substr(m.lcData, 5, 2)))
				lnDay = Int(Val(Substr(m.lcData, 7, 2)))
				ldData = Date(m.lnYear, m.lnMonth, m.lnDay)
				IF !BETWEEN(m.ldData, m.ldData1, m.ldData2)
					LOOP
				ENDIF 

				lnDebit = Val(Transform(debit))
				lnCredit = Val(Transform(credit))
				lnSuma = Iif(m.lnDebit <> 0, m.lnDebit, m.lnCredit)
				lcTip = Iif(m.lnDebit <> 0, 'D', 'C')
				lcRef = Getwordnum(Upper(Alltrim(ref)), 1, '/')
				* OPIOPRIC/12747148 Incasare OP/2021105/WERT SRL /ROC/FACT. 2372 DIN 01.03.2021
				* COM/12747474
				* ODSIBS.ODORANGE/9061093 Plata factura Orange, cod abonat 0554957175
				* OPPIBS.OPRCT/13717432  Plata OP /  342 - BUGETUL DE STAT
				* FXCIBS.FCTRAN/1962148 Transfer 1000 RON cu data valutei 23-APR-21
				* GENCCCPJS/862026678 Plata comision lunar de administrare cont
				lcTip2 = ''
				Do Case
					Case m.lcRef = 'COM' Or 'GENCCCPJS' $ m.lcRef
						lcTip2 = This.cTipComisioane
					Case 'OPPIBS.OPRCT' $ m.lcRef
						lcTip2 = This.cTipBuget
					Case 'FXCIBS' $ m.lcRef
						lcTip2 = This.cTipTransfer
					Case m.lcRef = 'OPIOPRIC' Or 'OPPIBS.OPRCC' $ m.lcRef
						lcTip2 = This.cTipTerti
					Otherwise
						lcTip2 =  This.cTipTerti 
				Endcase
				lcCodFiscal = Upper(Alltrim(TRANSFORM(cui_platitor)))
				lcDescriere = Alltrim(TRANSFORM(Details))
				* Daca sunt mai multe informatii, nu pastrez explicatiile 2,3,4 (numar op, nume partener si alta explicatie necunoscuta)
				* Pastrez doar tipul de document incasare op / plata op / transfer etc. si detaliile completate de client/furnizor
				* in procedura import_extras completez explicatia cu nume client/furnizori si cod fiscal
				lcExplicatie = m.lcDescriere
				Do Case
					Case Getwordcount(m.lcDescriere, '/') = 2
						lcExplicatie = Alltrim(Getwordnum(m.lcDescriere, 1, '/'))

					Case Getwordcount(m.lcDescriere, '/') > 4
						lcExplicatie = Alltrim(Alltrim(Getwordnum(m.lcDescriere, 1, '/')) + ' ' + Alltrim(Getwordnum(m.lcDescriere, 5, '/')))
				Endcase

				lcBanca = '' && nume banca platitor
				lcIBAN = Alltrim(TRANSFORM(iban_platitor)) && cont bancar tert: RO68UGBI0000442012404RON
				lcDenumire = Alltrim(TRANSFORM(denumire_platitor)) && nume tert: ADINA SI CAMI UNIVERS SRL

				lnNr = 0 && numar document de plata OP
				If Lower(Left(m.lcDescriere, 8)) = 'plata op' && Plata OP /  343 - BUGETUL DE STAT
					lcNr = Alltrim(Strextract(m.lcDescriere, 'Plata OP /', '-', 1, 1))
					lnNr = Int(Val(m.lcNr))
				Endif

				* Array sau lista cu numere de facturi separate prin "," daca exista in descriere
				* (?:( \d+)(?![\.\d])(?!2021).) spatiu apoi cifre, fara . si cifra si fara anul curent (sa excluda datele)
				lcFacturi = ''
				lcDescriereFacturi = m.lcDescriere

				If 'incasare op' $ Lower(m.lcDescriereFacturi)
					* Incasare OP/2021105/WERT SRL /ROC/FACT. 2372 DIN 01.03.2021
					* Incasare OP/197 DIVIZIA DE PAZA SRL /ROC/FACT NR  2021102 29 04 2021 SUPORT TEHNIC APR 2021
					* Incasare OP/864/CN ACN SA 2021100/29,04,2021
					lcDescriereFacturi = Getwordnum(m.lcDescriereFacturi, 3, '/')+ ' ' + Getwordnum(m.lcDescriereFacturi, 4, '/')+ ' '+ Getwordnum(m.lcDescriereFacturi, 5, '/')
				Endif
				*!*					lcRegExp = "(?:( \d+)(?![\.\d])(?!" + Alltrim(Str(Int(m.gnAn))) + ").)"
				*!*					lcRegExp = "(\d)+"
				*!*					lnResults = GetRegExpAll(m.lcDescriereFacturi, m.lcRegExp, @m.lcFacturi)
				lnResults = GetRegExpAllNumbers(m.lcDescriereFacturi, @m.lcFacturi)

				Select C_IMPORT_TEMP
				Append Blank
				Replace Data With m.ldData, suma With m.lnSuma, tip With m.lcTip, tip_2 With m.lcTip2, cod_fiscal With m.lcCodFiscal
				Replace iban With m.lcIBAN, denumire With m.lcDenumire, explicatie With m.lcExplicatie, documente With m.lcFacturi, nr With m.lnNr
			Endscan && cMovementsTemp

			Select C_IMPORT_TEMP
			Replace All nr With This.nNr For Empty(nr)

		Endif && llSucces
		Use In (Select('cMovementsTemp'))

		Return m.llSucces
	Endproc && Parse
Enddefine && ExtrasBanca_CREDITEUROPE_XML

Define Class ExtrasBanca_UNICREDIT_CSV As ExtrasBanca

	*****************************
	*** Parseaza liniile din extras si le introduce in cursorul C_IMPORT_TEMP
	*****************************
	Procedure Parse
		Local lcBanca, lcCodFiscal, lcCursor, lcData, lcDenumire, lcDescriere, lcDescriereFacturi
		Local lcExplicatie, lcExtraRand, lcFacturi, lcFile, lcIBAN, lcInfo1, lcInfo1Exemplu, lcInfo2
		Local lcInfo2Exemplu, lcMovements, lcMovementsExemplu, lcNr, lcRand, lcRand1, lcRef, lcRefDoc
		Local lcText, lcTip, lcTip2, ldData, lnCredit, lnDay, lnDebit, lnLinie, lnLinii, lnMonth, lnNr
		Local lnPos, lnPozitieN, lnRand, lnResults, lnSuma, lnYear, llSucces, lcRegExp

		lcFile = This.cFile
		lnLinii = 0
		llSucces = .T.

		If File(m.lcFile)
			Text To m.lcAntetExemplu Noshow
Titlu cont;Cont;Valuta;Sold deschidere;Sold inchidere
GENIUS IMM MOD OP;819976000;RON;-80.762,64;-158.108,98
			Endtext

			Text To m.lcBodyExemplu Noshow
Cont;Suma;Valuta;Data tranzactiei;Data valutei;Banca;Numele bancii;Adresa bancii;Cont;IBAN;Nume;Adresa 1;Adresa 2;Adresa 3;Detalii tranzactie 1;Detalii tranzactie 2;Detalii tranzactie 3;Detalii tranzactie 4;Detalii tranzactie 5;Detalii tranzactie 6;Detalii tranzactie 7;Detalii tranzactie 8;Detalii plata 1;Detalii plata 2;Detalii plata 3;Detalii plata 4;Detalii plata 5;Detalii plata 6;Cod fiscal;Numar ordin;Camp neutilizat;Camp neutilizat;Camp neutilizat;Numar de referinta;Requested Processing date;Numar inregistrare PSP;Nume PSP tert;Referinta plata PSP tert;Tara emiterii autorizatiei;Codul autoritatii nationale
819976000;-21,28;RON;10.05.2021;10.05.2021;;;;;;;;;;COMMISSION FOR CASH TRANS;CAK-LCD/1900/A/0015;;;;;;;;;;;;;;;;;;;;;;;;
819976000;2.127,84;RON;10.05.2021;10.05.2021;;;;;;;;;;CASH DEPOSIT/LEI ACCOUNT;CAK-LCD/1900/A/0015;FACT PROF SOWB21009895;MATEI ANDREI MARIUS;;;;;;;;;;;;;;;;;;;;;;
819976000;-51,33;RON;07.05.2021;07.05.2021;INGB;ING BANK ROMANIA;;;RO54INGB0000999907783025;PRO INTERACTIVE PLUS SRL;;;;;;;;;;;;F 6607/05.04.21;;;;;;32933032;304;;;;279591539;07.05.2021;;;;;
			Endtext

			lnLinii = Alines(This.aLinii, Filetostr(m.lcFile), 1)
			lnLinii = Iif(m.lnLinii < 2, 0, m.lnLinii)
			This.nLinii = m.lnLinii
		Endif

		If m.lnLinii = 0
			This.lError = .T.
			llSucces = .F.
			This.cErrorMessage = This.cErrorMessage + Iif(!Empty(This.cErrorMessage), Chr(13), '') + 'Fisierul este gol!'
		Endif

		* Verific antetul fisierului
		If m.llSucces
			If ![Titlu cont;Cont;Valuta;Sold deschidere;Sold inchidere] $ This.aLinii[1]
				This.lError = .T.
				llSucces = .F.
				This.cErrorMessage = This.cErrorMessage + Iif(!Empty(This.cErrorMessage), Chr(13), '') + 'Nu corespunde structura fisierului!'
			Endif
		Endif
		If m.llSucces
			lcLinie = This.aLinii[2]
			This.cIBAN = syGETWORDNUM(m.lcLinie, 2, ';')
			This.cValuta = syGETWORDNUM(m.lcLinie, 3, ';')

			This.nNr = Int(Val(Dtos(Gomonth(Date(m.gnAn, m.gnLuna, 1), 1) - 1)))

			For lnLinie = 4 To m.lnLinii
				lcLinie = This.aLinii[m.lnLinie]
				lcData = syGETWORDNUM(m.lcLinie, 4, ';')
				lnYear = Int(Val(Substr(m.lcData, 7, 4)))
				lnMonth = Int(Val(Substr(m.lcData, 4, 2)))
				lnDay = Int(Val(Substr(m.lcData, 1, 2)))
				ldData = Date(m.lnYear, m.lnMonth, m.lnDay)

				lcSuma = syGETWORDNUM(m.lcLinie, 2, ';')
				lcSuma = Strtran(m.lcSuma, '.', '', 1, 10, 1) && sterg separatorul grupe .
				lcSuma = Strtran(m.lcSuma, ',', '.', 1, 1, 1) && modific separator zecimale in .
				lnSuma = Val(m.lcSuma)
				lcTip = Iif(m.lnSuma < 0, 'D', 'C')
				lnSuma = Abs(m.lnSuma)

				lcD1 = syGETWORDNUM(m.lcLinie, 15, ';')
				lcD2 = syGETWORDNUM(m.lcLinie, 16, ';')
				lcD3 = syGETWORDNUM(m.lcLinie, 17, ';')
				lcD4 = syGETWORDNUM(m.lcLinie, 18, ';')
				lcD5 = syGETWORDNUM(m.lcLinie, 19, ';')
				lcD6 = syGETWORDNUM(m.lcLinie, 20, ';')
				lcD7 = syGETWORDNUM(m.lcLinie, 21, ';')
				lcD8 = syGETWORDNUM(m.lcLinie, 22, ';')
				lcDP1 = syGETWORDNUM(m.lcLinie, 23, ';')
				lcDP2 = syGETWORDNUM(m.lcLinie, 24, ';')
				lcDP3 = syGETWORDNUM(m.lcLinie, 25, ';')
				lcDP4 = syGETWORDNUM(m.lcLinie, 26, ';')
				lcDP5 = syGETWORDNUM(m.lcLinie, 27, ';')
				lcDP6 = syGETWORDNUM(m.lcLinie, 28, ';')
				lcExplicatie = m.lcD1 + ;
					Iif(!Empty(m.lcD2), ' ' + m.lcD2, '') + ;
					Iif(!Empty(m.lcD3), ' ' + m.lcD3, '') + ;
					Iif(!Empty(m.lcD4), ' ' + m.lcD4, '') + ;
					Iif(!Empty(m.lcD5), ' ' + m.lcD5, '') + ;
					Iif(!Empty(m.lcD6), ' ' + m.lcD6, '') + ;
					Iif(!Empty(m.lcD7), ' ' + m.lcD7, '') + ;
					Iif(!Empty(m.lcD8), ' ' + m.lcD8, '') + ;
					Iif(!Empty(m.lcDP1), ' ' + m.lcDP1, '') + ;
					Iif(!Empty(m.lcDP2), ' ' + m.lcDP2, '') + ;
					Iif(!Empty(m.lcDP3), ' ' + m.lcDP3, '') + ;
					Iif(!Empty(m.lcDP4), ' ' + m.lcDP4, '') + ;
					Iif(!Empty(m.lcDP5), ' ' + m.lcDP5, '') + ;
					Iif(!Empty(m.lcDP6), ' ' + m.lcDP6, '')

				* COMMISSION FOR CASH TRANS;CAK-LCD/1900/A/0015
				* CASH DEPOSIT/LEI ACCOUNT;CAK-LCD/1900/A/0015;FACT PROF SOWB21009895;MATEI ANDREI MARIUS

				lcBanca = Upper(Alltrim(syGETWORDNUM(m.lcLinie, 6, ';'))) && nume banca platitor
				lcIBAN = Upper(Alltrim(syGETWORDNUM(m.lcLinie, 10, ';'))) && cont bancar tert: RO68UGBI0000442012404RON
				lcDenumire = Upper(Alltrim(syGETWORDNUM(m.lcLinie, 11, ';'))) && denumire tert
				lcCodFiscal = syGETWORDNUM(m.lcLinie, 29, ';')
				lnNr = Int(Val(syGETWORDNUM(m.lcLinie, 30, ';')))

				lcTip2 = ''
				Do Case
					Case 'COMMISSION' $ Upper(m.lcExplicatie) Or ' FEE' $ Upper(m.lcExplicatie) Or ;
							'FEE/' $ Upper(m.lcExplicatie) Or Upper(m.lcExplicatie) = 'FEE'
						lcTip2 = This.cTipComisioane
					Case 'CASH DEPOSIT' $ Upper(m.lcExplicatie)
						lcTip2 = This.cTipDepunere
					Case 'BUGETUL DE STAT' $ m.lcDenumire
						lcTip2 = This.cTipBuget
					Case 'PROMISSORY NOTE' $ Upper(m.lcDP1) Or 'PROMISSORY NOTE' $ Upper(m.lcD1)
						lcTip2 = This.cTipEfecteComerciale
					Otherwise
						lcTip2 = This.cTipTerti
				Endcase


				* Array sau lista cu numere de facturi separate prin "," daca exista in descriere
				* (?:( \d+)(?![\.\d])(?!2021).) spatiu apoi cifre, fara . si cifra si fara anul curent (sa excluda datele)
				lcFacturi = ''
				lcDescriereFacturi = m.lcExplicatie
				lnResults = GetRegExpAllNumbers(m.lcDescriereFacturi, @m.lcFacturi)

				Select C_IMPORT_TEMP
				Append Blank
				Replace Data With m.ldData, suma With m.lnSuma, tip With m.lcTip, tip_2 With m.lcTip2, cod_fiscal With m.lcCodFiscal
				Replace iban With m.lcIBAN, denumire With m.lcDenumire, explicatie With m.lcExplicatie, documente With m.lcFacturi, nr With m.lnNr
			Endfor && laLinii

			Select C_IMPORT_TEMP
			Replace All nr With This.nNr For Empty(nr)

		Endif && llSucces
		Use In (Select('cMovementsTemp'))

		Return m.llSucces
	Endproc && Parse
Enddefine && ExtrasBanca_UNICREDIT_CSV

* Clasa preluata din SAGA
* Determina automat tipul de fisier (extras, decont curier, procesator plati) din continutul fisierului
Define Class ExtrasBanca_General As ExtrasBanca

	Function Parse
		Local mdatareferinta, lnfilehandle, mrand, mcomision, mnrcomision, isunicredit, isfaracitire, mnrimport
		mSelectedFile = This.cFile
		isunicredit = .F.
		isbcr = .F.
		isfaracitire = .F.
		mdatareferinta = Date()
		mnrimport = 1
		mrand = ""

		Create Cursor match (Id N (10), id_pi N (7), ip C (1), nr C (16), cod C (8), denumire C (64), Data D, scadent D Null, Total N (15, 2), tva N (15, 2), neachitat N (15, 2), neachitat_real N (15, 2), achitat N (15, 2), cod_valuta C (3), Curs N (15, 4), dif_curs N (15, 2), total_val N (16, 4), is_total N (1, 0), tip_o C (3), grupa C (16), plan C (6), sector C (16), sursa C (16), capitol C (16), articol C (16), tip C (1), tvai N (1, 0), inf_suplm C (100))
		Index On Data Tag Data

		Create Cursor c_iex (Id N (10, 0), ip C (1), nr C (16), Data D, suma N (15, 2), explicatie C (200), original M, iban C (24), cod C (8), tert C (64), cf C (13), tip C (2), tip_2 C (3), Cont C (20), cont_casa C (20), ok N (1, 0), tert_v N (1, 0), suma_v N (1, 0), cod_valuta C (3), tip_o C (3), importat N (1), tel C (20), email C (100), asociat N (1, 0), documente C(250), comenzi C(250))


		If !Inlist(Upper(Justext(mSelectedFile)), "XLS", "XML")
			lnfilehandle = Fopen(mSelectedFile)
			If lnfilehandle = -1
				Messagebox( "Fisierul nu poate fi accesat." + Chr(13) + "Probabil ca este deschis �n alta fereastra.", 16, "Eroare acces" )
				Return .F.
			Endif
			Do While !Feof(lnfilehandle) .And. Empty(mrand)
				mrand = Fgets(lnfilehandle)
			Enddo
			Fclose(lnfilehandle)
		Endif

		Do Case
			Case Left(Upper(Justext(mSelectedFile)), 3) = "XLS"
				This.xlsGeneral(mSelectedFile)
			Case Upper(Justext(mSelectedFile)) = "XML"
				This.xmlAsc(mSelectedFile)
			Case Upper(Justext(mSelectedFile)) = "TXT" .And. "mandat postal" $ Lower(mrand)
				This.txtPosta(mSelectedFile)
			Case Upper(Justext(mSelectedFile)) = "CSV"
				Do Case
					Case 'transaction date,type,order'$Lower(mrand)
						* Data Comenzii,Tipul,Nr Comanda,,Data Transferului,Suma,Comision,Suma Neta,Referinta
						This.csvStripe(mSelectedFile)			
					Case Lower(Left(mrand, 4)) = "tip," .Or. Lower(Left(mrand, 5)) = "type,"
						This.csvBooking(mSelectedFile)
					Case "id produs,cod produs," $ Lower(mrand)
						This.csvPayu(mSelectedFile)
					Case Occurs('textbox', Lower(mrand)) > 6
						This.csvIntesa(mSelectedFile, 1)
					Case Occurs('textbox', Lower(mrand)) = 6
						This.csvIntesa(mSelectedFile, 2)
					Case 'localitate' $ Lower(mrand) AND 'persoanae' $ Lower(mrand) 
						This.csvFanCourier(mSelectedFile)
					Case 'oras destinatar' $ Lower(mrand)
						This.csvFunCourier(mSelectedFile)
					Case 'awb,data_awb,destinatar' $ Lower(mrand)
						This.csvFunCourier2(mSelectedFile)
					Case 'idawb' $ Lower(mrand)
						This.csvCargus(mSelectedFile)
					Case 'waybill' $ Lower(mrand)
						This.csvDPD(mSelectedFile, 1)
					Case 'data,id,numar' $ Lower(mrand) .Or. '"data","id","numar"' $ Lower(mrand) .Or. 'data;id;numar' $ Lower(mrand) .Or. '"data";"id";"numar"' $ Lower(mrand)
						This.csvDPD(mSelectedFile, 2)
					Case 'tranzactiile contului:' $ Lower(mrand) .Or. 'account activities:' $ Lower(mrand)
						This.csvGaranti(mSelectedFile)
					Case Lower(Left(mrand, 11)) = "cod client:"
						This.csvGaranti_2(mSelectedFile)
					Case 'suma db' $ Lower(mrand) .Or. ('suma debit' $ Lower(mrand) .And. 'referinta' $ Lower(mrand) .And. 'data val.' $ Lower(mrand))
						This.csvOTP(mSelectedFile)
					Case "perioada:" $ Lower(mrand) .Or. "data generare extras:" $ Lower(mrand)
						This.csvRaiffeisen(mSelectedFile, Iif(";;" $ mrand, ";", ","))
					Case "titlu cont" $ Lower(mrand) .Or. "account title" $ Lower(mrand)
						If "titlu cont" $ Lower(mrand)
							This.csvUnicredit(mSelectedFile, Substr(mrand, Atc( "Titlu cont", mrand) + 10, 1))
						Else
							This.csvUnicredit(mSelectedFile, Substr(mrand, Atc( "Account Title", mrand) + 13, 1))
						Endif
					Case ",,detalii tranzactie," $ Lower(mrand) .Or. ",,transaction details," $ Lower(mrand)
						If "debit,credit" $ Lower(mrand)
							This.csvIng(mSelectedFile, 2)
						Else
							This.csvIng(mSelectedFile, 1)
						Endif
					Case "numar cont;" $ Lower(mrand)
						lnTipFisier = IIF('sold initial;sold final;numar cont;'$ Lower(mrand), 2, 1)
						This.csvIngbusiness(mSelectedFile, ";", m.lnTipFisier)
					Case "ingb" $ Lower(mrand) .Or. 'numar cont,' $ Lower(mrand) .Or. 'numar cont",' $ Lower(mrand)
						This.csvIngbusiness(mSelectedFile, ",")
					Case Lower(Left(mrand, 10)) = "tranzactii" .Or. Lower(Left(mrand, 12)) = "transactions"
						* BTGO lista de tranzactii in cursul lunii
						This.csvBT(mSelectedFile, 1)
					Case Lower(Left(mrand, 19)) = [lista de tranzactii] OR Lower(Left(mrand, 21)) = ["lista de tranzactii"]
						* BTGO extrase de cont final de luna
						This.csvBT(mSelectedFile, 2)						
					Case '"date",' $ Lower(mrand)
						This.csvPaypal(mSelectedFile)
					Case Lower(Left(mrand, 6)) = '"brde"' .Or. Lower(Left(mrand, 4)) = 'brde'
						This.csvBRD(mSelectedFile)
					Case Lower(Left(mrand, 6)) = '"rncb"' .Or. Lower(Left(mrand, 4)) = 'rncb'
						This.csvBCR2(mSelectedFile)
					Case "first bank" $ Lower(mrand)
						This.csvFirstBank(mSelectedFile)
					Case "cece" $ Lower(mrand)
						This.csvCEC(mSelectedFile)
					Case Lower(Left(mrand, 3)) = '"#"'
						This.csvMobilPay(mSelectedFile)
					Case "data emitere extras" $ Lower(mrand)
						This.csvBCR(mSelectedFile)
					Case Occurs(";", mrand) = 7
						This.csvUnDoi(mSelectedFile)
					Case Occurs(",", mrand) = 6
						This.csvPaypoint(mSelectedFile)
					Case "platitor_nume_denumire" $ Lower(mrand)
						This.csvIdea(mSelectedFile)
					Case "numeclient,perioada,codclient" $ Lower(mrand)
						This.csvCreditEurope(mSelectedFile)
					Case Lower(Left(mrand, 3)) = "sep"
						This.csvAlpha(mSelectedFile)
					Otherwise
						Messagebox( "Formatul fisierului CSV nu este implementat pentru import.", 16, "Format necunoscut" )
						Return .F.
				Endcase
			Case Upper(Justext(mSelectedFile)) = "TXT" 	&& MT940
				This.MT940(mSelectedFile)
			Otherwise
				*
		Endcase

		Update c_iex Set tip_2 = This.cTipTerti Where Empty(tip_2)

		Select Int(Val(nr)) As nr, Data, suma, explicatie, original, iban, cod, tert As denumire, cf As cod_fiscal, tip, tip_2, ;
			Cont, tert_v, suma_v As suma_val, cod_valuta As nume_val, tip_o, documente, comenzi ;
			From c_iex Into Cursor c_iex_temp

		Select C_IMPORT_TEMP
		Append From Dbf('c_iex_temp')
		Use In (Select('c_iex_temp'))
		Use In (Select('c_iex'))
		Use In (Select('match '))

		*!*			This.cIBAN = syGETWORDNUM(m.lcLinie, 2, ';')
		*!*			This.cValuta = syGETWORDNUM(m.lcLinie, 3, ';')
		*!*			If !Inlist(This.cValuta, 'RON', 'LEI', 'ROL')
		*!*				This.cContBanca = '5124' && banca valuta
		*!*			ENDIF

	Endfunc && Parse


	Function MT940
		Fopen(mSelectedFile)
		mtextoriginal = ""
		Select c_iex
		Do While !Feof(lnfilehandle)
			If !isfaracitire
				mrand = Fgets(lnfilehandle)
			Endif
			isfaracitire = .F.
			Do Case
				Case Left(m.mrand, 4) = ':25:' && cont bancar
					* :25:RO57RZBR0000060011634808
					This.cIBAN = Upper(Alltrim(Substr(m.mrand, 5))) && RO57RZBR0000060011634808
				Case ":61:" $ mrand
					Append Blank
					mldatae = {}
					nnrapnc = Occurs("NC", mrand)
					If nnrapnc > 0
						mstartdata = At("NC", mrand, nnrapnc) + 2
						mldatae = Ctod(Substr(mrand, mstartdata + 4, 2) + "." + Substr(mrand, mstartdata + 2, 2) + ".20" + Substr(mrand, mstartdata, 2))
					Endif
					If mldatae = {}
						mldatae = Ctod(Substr(mrand, 9, 2) + "." + Substr(mrand, 7, 2) + ".20" + Substr(mrand, 5, 2))
					Endif
					Replace Data With mldatae, tip With Substr(mrand, 15, 1) + Iif(Inlist(Substr(mrand, 16, 1), "D", "C"), Substr(mrand, 16, 1), "")
					mrand = Iif(Inlist(Substr(mrand, 16, 1), "D", "C"), Substr(mrand, 17, 50), Substr(mrand, 16, 50))
					mtextoriginal = mrand
					Do Case
						Case "NTRF" $ mrand
							isbcr = .T.
							mpozitien = At("N", mrand)
							Replace suma With Val(Strtran(Substr(mrand, 1, mpozitien - 1), ",", ".")), tip_2 With Substr(mrand, mpozitien + 1, 3)
							If "//" $ mrand
								mpozitienr = At("//", mrand) + 10
								Replace nr With Alltrim(Substr(mrand, mpozitienr, 16))
							Else
								Replace nr With Alltrim(Substr(mrand, mpozitien + 4, 16))
							Endif
						Case "FMSC" $ mrand
							mpozitien = At("F", mrand)
							Replace suma With Val(Strtran(Substr(mrand, 1, mpozitien - 1), ",", ".")), tip_2 With "", nr With Alltrim(Substr(mrand, mpozitien + 12, 16))
							isunicredit = .T.
						Otherwise
							mpozitien = At("N", mrand)
							Replace suma With Val(Strtran(Substr(mrand, 1, mpozitien - 1), ",", ".")), tip_2 With Substr(mrand, mpozitien + 1, 3), nr With Strtran(Alltrim(Substr(mrand, mpozitien + 4, 16)), "NONREF //", "")
							If !("NONREF //" $ mrand)
								mrand = Fgets(lnfilehandle)
								Replace explicatie With mrand
								mtextoriginal = mtextoriginal + Chr(13) + mrand
							Endif
					Endcase
				Case ":86:" $ mrand .And. "+31" $ mrand
					Replace iban With Alltrim(Substr(mrand, At( "+31", mrand) + 3, 24))
					mrand = Fgets(lnfilehandle)
					mtextoriginal = mtextoriginal + Chr(13) + mrand
					Replace tert With Substr(mrand, At( "+32", mrand) + 3, At( "+33", mrand) - 4), cf With Alltrim(Substr(mrand, At( "+33", mrand) + 3, 13))
				Case ":86:" $ mrand .And. !isunicredit .And. !isbcr
					mnextrand = Fgets(lnfilehandle)
					mtextoriginal = mtextoriginal + Chr(13) + mnextrand
					If mnextrand = ":61:"
						mrand = mnextrand
						isfaracitire = .T.
						Loop
					Else
						mrand1 = mrand + mnextrand
					Endif
					mnextrand = Fgets(lnfilehandle)
					mtextoriginal = mtextoriginal + Chr(13) + mnextrand
					If mnextrand = ":61:"
						mrand = mnextrand
						isfaracitire = .T.
						Loop
					Else
						mrand1 = mrand + mnextrand
					Endif
					mnextrand = Fgets(lnfilehandle)
					mtextoriginal = mtextoriginal + Chr(13) + mnextrand
					If mnextrand = ":61:"
						mrand = mnextrand
						isfaracitire = .T.
						Loop
					Else
						mrand1 = mrand + mnextrand
					Endif
					mnextrand = Fgets(lnfilehandle)
					mtextoriginal = mtextoriginal + Chr(13) + mnextrand
					If mnextrand = ":61:"
						mrand = mnextrand
						isfaracitire = .T.
						Loop
					Else
						mrand1 = mrand + mnextrand
					Endif
					mrand1 = Substr(Strtran(mrand1, "intrabancara Platitor", ""), 5, 250)
					mcf = getnrfromstring(mrand1)
					miban = Substr(mcf, At("RO", mcf), 24)
					mcf = Substr(mcf, 1, At( " ", mcf))
					mtert = Substr(mrand1, At( " ", mrand1) + 3, At(mcf, mrand1) - 5)
					If "Detalii " $ mrand1
						mexplicatie = Substr(mrand1, At( "Detalii ", mrand1) + 8, 60)
					Else
						mexplicatie = Substr(mrand, 5, 60)
					Endif
					If !verifcf(mcf)
						mcf = getdigitsfromstring(mrand1, 4, 1, ".")
					Endif
					Replace tert With mtert, cf With mcf, iban With miban, explicatie With mexplicatie
				Case ":86:" $ mrand .And. isbcr
					mnextrand = ""
					mrand1 = mrand
					ij = 1
					Do While !(":61:" $ mnextrand) .And. ij <= 7
						mnextrand = Fgets(lnfilehandle)
						If mnextrand = ":61:"
							Fseek(lnfilehandle, - Len(mnextrand) - 2, 1)
						Else
							mrand1 = mrand1 + mnextrand
						Endif
						ij = ij + 1
					Enddo
					mtextoriginal = mtextoriginal + Chr(13) + mrand1
					Store "" To mtert, miban, mcf
					If tip = "C"
						If "-Platitor" $ mrand1
							mstart = At("-Platitor", mrand1) + 11
							mtert = Substr(mrand1, mstart, 200)
							mstartiban = At(" RO", mtert) + 2
							miban = Substr(mtert, mstartiban, 24)
							mstartcf = At(" CODFISC ", mtert) + 9
							mcf = Substr(mtert, mstartcf, 12)
							If " " $ mcf
								mcf = Left(mcf, At(" ", mcf))
							Else
								If "-" $ mcf
									mcf = Left(mcf, At("-", mcf) - 1)
								Endif
							Endif
							mtert = Left(mtert, mstartiban - 2)
						Endif
					Else
						If "-Beneficiar" $ mrand1
							mstart = At("-Beneficiar", mrand1) + 13
							mtert = Substr(mrand1, mstart, 200)
							mstartiban = At(" RO", mtert) + 2
							miban = Substr(mtert, mstartiban, 24)
							mstartcf = At(" CODFISC ", mtert) + 9
							mcf = Substr(mtert, mstartcf, 12)
							If " " $ mcf
								mcf = Left(mcf, At(" ", mcf))
							Else
								If "-" $ mcf
									mcf = Left(mcf, At("-", mcf) - 1)
								Endif
							Endif
							mtert = Left(mtert, mstartiban - 2)
						Endif
					Endif
					If !verifcf(mcf)
						mcf = getdigitsfromstring(mrand1, 4, 1, ".")
					Endif
					If "Detalii " $ mrand1
						mexplicatie = Substr(mrand1, At( "Detalii ", mrand1) + 9, 60)
					Else
						mexplicatie = Substr(mrand, 5, 60)
					Endif
					Replace tert With mtert, cf With mcf, iban With miban, explicatie With mexplicatie
				Case ":86:" $ mrand .And. isunicredit
					mtextoriginal = mtextoriginal + Chr(13) + mrand
					mrand1 = Fgets(lnfilehandle)
					If mrand1 = ":61:"
						mrand = mrand1
						isfaracitire = .T.
					Else
						mtextoriginal = mtextoriginal + Chr(13) + mrand1
						If "CUI" $ mrand + mrand1
							mrand2 = Fgets(lnfilehandle)
							mtextoriginal = mtextoriginal + Chr(13) + mrand2
							If mrand2 = ":61:"
								mrand1 = mrand + mrand1
								mrand = mrand2
								isfaracitire = .T.
							Else
								mrand1 = mrand + mrand1 + mrand2
								mrand2 = Fgets(lnfilehandle)
								If mrand2 = ":61:"
									mrand = mrand2
									isfaracitire = .T.
								Else
									mrand1 = mrand1 + mrand2
									mtextoriginal = mtextoriginal + Chr(13) + mrand2
								Endif
							Endif
							mtert = Alltrim(Left(mrand1, At("CUI", mrand1) - 3))
							mrand1 = Alltrim(Substr(mrand1, At("CUI", mrand1) + 3, 400))
							mcf = Alltrim(Substr(mrand1, 1, At(",", mrand1) - 1))
							mrand1 = Alltrim(Substr(mrand1, At("Acc.", mrand1) + 4, 400))
							miban = Alltrim(Substr(mrand1, 1, At(",", mrand1) - 1))
							mrand1 = Alltrim(Substr(mrand1, At(",", mrand1, 4) + 2, 400))
							mexplicatie = Alltrim(Substr(mrand1, 1, At(",", mrand1) - 1))
							Replace tert With Substr(mtert, 5, 60), cf With mcf, iban With miban, explicatie With mexplicatie, tip_2 With "TRF"
						Else
							Do Case
								Case ":61:" $ mrand1
									isfaracitire = .T.
									mrand = mrand1
									mexplicatie = Alltrim(Substr(mrand, 5, 60))
								Case mrand1 = ":"
									mexplicatie = Alltrim(Substr(mrand, 5, 60))
								Otherwise
									mrand2 = Fgets(lnfilehandle) + " "
									mexplicatie = ""
									If mrand2 = ":61:"
										mrand = mrand2
										isfaracitire = .T.
									Else
										mexplicatie = mrand2
										mtextoriginal = mtextoriginal + Chr(13) + mrand2
										mrand3 = Fgets(lnfilehandle)
										If mrand3 = ":61:"
											mrand = mrand3
											isfaracitire = .T.
										Else
											mtextoriginal = mtextoriginal + Chr(13) + mrand3
											mrand4 = Fgets(lnfilehandle)
											If mrand4 = ":61:"
												mrand = mrand4
												isfaracitire = .T.
											Else
												mtextoriginal = mtextoriginal + Chr(13) + mrand4
												If mrand2 = "Fee/" .Or. "Transfond fee" $ mrand2
													mexplicatie = mrand2 + mrand3 + " " + mrand4
												Else
													mexplicatie = mrand3 + " " + mrand4
												Endif
											Endif
										Endif
									Endif
							Endcase
							If mexplicatie = "Fee/" .Or. "Transfond fee" $ mexplicatie .Or. "COMMISSION" $ Upper(mtextoriginal)
								Replace tip_2 With "COM", explicatie With "Comision"
							Else
								Replace explicatie With mexplicatie
							Endif
						Endif
					Endif
			Endcase
			Replace original With mtextoriginal
		Enddo
		Fclose(lnfilehandle)

	Endfunc
	Function xlsGeneral
		Lparameters pselectedfile
		Local I, mnrstart, mcf, mtert, mexplicatie, mtipimport, mdataextras
		Local oexcel As "Excel.Application"
		Local lcData, lcValue, loEx as Exception, llXLS, llXLSX
		*:Global jj, mcolcredit, mcoldata, mcoldebit, mcolexplicatie, mcontorinregistrari, mcredit, mdata
		*:Global mdataimp, mdatatest, mdebit, mexplicatie1, minceput, mlfinal, mlungime, mnrdoc, mnrdoctest
		*:Global mpozsrl, mpozstart1, mpozstart2, msrl, msuma, msumac, msumad, mtext1, mtextoriginal
		*:Global mtexttert, oexcelapp, oworkbook
		mtipimport = ""
		lcMesajEroare = ""
		Create Cursor C_TMP_I (data_t C (10), detalii C (250), data_v C (10), debit C (15), credit C (15), cf C (13), tert C (120), nr C (16), iban C (24), comision N (15, 2), documente C(250), comenzi C(250))

		* Pentru llXLSX nu folosesc automatizare Microsoft Excel

		lcDBF = ''
		IF LOWER(JUSTEXT(m.pselectedfile)) = 'xlsx'
			llXLS = .F.	
			llXLSX = .T.	
			
			Create Cursor cXLSXTmp(mfield1 M null,mfield2 M null,mfield3 M null,mfield4 M null,mfield5 M null,mfield6 M null,;
				mfield7 M null,mfield8 M null,mfield9 M null,mfield10 M null,mfield11 M null,mfield12 M null,mfield13 M null,;
				mfield14 M null,mfield15 M null,mfield16 M null,mfield17 M null,mfield18 M null,mfield19 M null,mfield20 M null,;
				mfield21 M null,mfield22 M null,mfield23 M null,mfield24 M null,mfield25 M null,mfield26 M null,mfield27 M null,;
				mfield28 M null,mfield29 M null,mfield30 M null)
								
			TRY 
				* lcFileName,cCur,lcFFields,lnStartRows,lcSheet,llEmptyCells
				appendfromxlsx(m.pselectedfile,'cXLSXTmp','',1,'',.T.)
				GO TOP IN cXLSXTmp	
			Catch To loEx
				lcMesajEroare = loEx.message
			ENDTRY
							
			IF RECCOUNT('cXLSXTmp') = 0
				USE IN (SELECT('cXLSXTmp'))
				AMESSAGEBOX('Eroare la importul din fisier!' + IIF(!EMPTY(m.lcMesajEroare), CHR(13) + m.lcMesajEroare, ""), 0 + 48, 'Atentie!')
				Return .F.			
			ENDIF 
		ELSE 
			Try
				oexcel = Createobject("Excel.Application")
			Catch To loEx
				*
			ENDTRY

			If Vartype(oexcel) <> "O"
				AMESSAGEBOX( 'Nu aveti instalat Microsoft Excel!', 0 + 48, 'Atentie!')
				Return .F.
			Endif
			oexcel.Visible = .T.
			oexcel.sheetsinnewworkbook = 1
			oworkbook = oexcel.workbooks.Open(pselectedfile)
			oexcelapp = oexcel.Application
			llXLS = .T.
			llXLSX = .F.
		ENDIF && !m.llXLSX		

		mnrstart = 0

		Do Case
			CASE m.llXLSX AND (LOWER(ALLTRIM(cXLSXTmp.mfield1)) = "payout date")
				* Import EMAG din XLSX
				mtipimport = "eMag"

				INSERT INTO C_TMP_I(data_t, data_v, debit, credit, nr, tert, comenzi) ;
					SELECT CAST(mfield1 as C(10)) as data_t, CAST(mfield1 as C(10)) as data_v, CAST("" as C(15)) as debit, ;
						CAST(mfield17 as C(15)) as credit, CAST(mfield9 as C(16)) as nr, CAST(mfield12 as C(120)) as tert, CAST(mfield9 as C(250)) as comenzi ;
						FROM cXLSXTmp ;
						WHERE RECNO() > 1
					
			Case m.llXLSX AND (LEFT(LOWER(ALLTRIM(cXLSXTmp.mfield1)),3) = "gls" OR ("referin"$lower(cXLSXTmp.mfield1) AND "colet"$lower(cXLSXTmp.mfield2)))
				* Import GLS din XLSX

				mtipimport = "GLS"

				mdataextras = ""
				SELECT cXLSXTmp 
				SCAN 
					lcValue = ALLTRIM(LOWER(mfield1))
					Do Case
						Case  "data tranferarii banilor:" $ m.lcValue Or "data transferarii banilor:" $ m.lcValue
							lcData = GetRegExp(m.lcValue, '\d{2}\.\d{2}\.\d{4}', 1)
							If !Empty(Ctod(m.lcData))
								mdataextras = m.lcData
							Endif

						Case Inlist(Lower(Left(m.lcValue, 5)), "numar", "num�r")
							mnrstart = RECNO()
							Exit
					Endcase
				ENDSCAN 
				If mnrstart = 0
					Return
				Endif

				Insert Into C_TMP_I (data_t, data_v, debit, credit, detalii, nr, comenzi) ;
					SELECT CAST(mfield4 as C(10)) as data_t, CAST(Iif(!Empty(mdataextras), mdataextras, mfield4) as C(10)) as data_v, ;
						CAST('' as C(15)) as debit, CAST(Iif(!EMPTY(NVL(mfield5, '')), mfield5, "") as C(15)) as credit, ;
						  CAST(mfield7 as C(250)) as detalii, CAST(mfield2 as C(16)) as nr, CAST(ALLTRIM(mfield2) as C(250)) as comenzi ;
  						FROM cXLSXTmp ;
						WHERE RECNO() > mnrstart AND !EMPTY(NVL(mfield2,'')) AND !EMPTY(NVL(mfield7,''))


				UPDATE C_TMP_I SET tert = Upper(Left(detalii,  At("    ",  detalii))) WHERE "    " $ Alltrim(detalii) AND EMPTY(NVL(tert,''))
				UPDATE C_TMP_I SET tert = Upper(Left(detalii,  At(" RO-",  detalii))) WHERE " RO-" $ Alltrim(detalii) AND EMPTY(NVL(tert,''))				

			Case m.llXLSX AND (LEFT(LOWER(ALLTRIM(cXLSXTmp.mfield1)),14) = "orasdestinatar") AND (LEFT(LOWER(ALLTRIM(cXLSXTmp.mfield2)),8) = "data awb") 
				* Import FAN Courier din XLSX
				mtipimport = "FAN"

				mdataextras = ""
				mnrstart = 1

				Insert Into C_TMP_I (data_t, data_v, debit, credit, detalii, nr, comenzi) ;
					SELECT CAST(mfield2 as C(10)) as data_t, CAST(mfield2 as C(10)) as data_v, ;
						CAST('' as C(15)) as debit, CAST(Iif(!EMPTY(NVL(mfield3, '')), mfield3, "") as C(15)) as credit, ;
						  CAST(mfield6 as C(250)) as detalii, CAST(mfield4 as C(16)) as nr, CAST(ALLTRIM(mfield4) as C(250)) as comenzi ;
  						FROM cXLSXTmp ;
						WHERE RECNO() > mnrstart AND !EMPTY(NVL(mfield3,'')) AND !EMPTY(NVL(mfield6,''))

				SELECT C_TMP_I
				SCAN FOR " CUI " $ UPPER(detalii) OR " CUI:" $ UPPER(detalii)
					mcf = getdigitsfromstring(C_TMP_I.detalii, 4, 1, ".")
					SELECT C_TMP_I
					IF !EMPTY(mcf)
						REPLACE cf WITH m.mcf
					ENDIF 	
				ENDSCAN 	

				UPDATE C_TMP_I SET tert = Upper(detalii) WHERE !" CUI " $ UPPER(detalii) AND !" CUI:" $ UPPER(detalii)
				UPDATE C_TMP_I SET tert = Upper(Left(detalii,  At(" CUI",  detalii))) WHERE EMPTY(NVL(TERT, '')) AND " CUI" $ UPPER(detalii) && CIOBANU ANAMARIA-CRISTINA CUI 33930204 L

				
			Case m.llXLS AND (Type( "oExcelApp.Cells(1,1).Value" ) = "C" .And. Lower(Left(oexcelapp.cells(1, 1).Value, 11)) = "payout date")
				* automatizare Excel pentru fisier EMAG XLSX
				* Nu se intra pe ramura aceasta pentru ca intra pe importul fara automatizare
				mtipimport = "eMag"

				I = 2
				Do While !Isnull(oexcelapp.cells(I, 1).Value) .And. !Empty(oexcelapp.cells(I, 1).Value)
					Insert Into C_TMP_I (data_t, data_v, debit, credit, nr, tert) Values (oexcelapp.cells(I, 1).Value, oexcelapp.cells(I, 1).Value, "", Str(oexcelapp.cells(I, 17).Value, 15, 2), Alltrim(Str(oexcelapp.cells(I, 9).Value, 16, 0)), Alltrim(oexcelapp.cells(I, 12).Value))
					I = I + 1
				ENDDO
				
			Case m.llXLS AND Type( "oExcelApp.Cells(1,1).Value" ) = "C" .And. Lower(Left(oexcelapp.cells(1, 1).Value, 3)) = "gls"
				* automatizare Excel pentru fisier GSL XLS
				mtipimport = "GLS"
				I = 1
				mdataextras = ""
				For I = 1 To 100
					lcValue = Alltrim(Lower(Transform(oexcelapp.cells(I, 1).Value)))
					Do Case
						Case  "data tranferarii banilor:" $ m.lcValue Or "data transferarii banilor:" $ m.lcValue
							lcData = GetRegExp(m.lcValue, '\d{2}\.\d{2}\.\d{4}', 1)
							If !Empty(Ctod(m.lcData))
								mdataextras = m.lcData
							Endif
							*!* If !Empty(Ctod(Substr(oexcelapp.cells(i, 1).Value, 27, 10)))
							*!* mdataextras = Substr(oexcelapp.cells(i, 1).Value, 27, 10)
							*!* Endif
							*!*							CASE  "cont bancar nr.:" $ m.lcValue
							*!*								This.cIBAN = UPPER(ALLTRIM(SUBSTR(m.lcValue, 17)))

						Case Inlist(Lower(Left(m.lcValue, 5)), "numar", "num�r")
							mnrstart = I
							Exit

					Endcase
				Endfor
				If mnrstart = 0
					Return
				Endif
				I = mnrstart + 1
				Do While !Isnull(oexcelapp.cells(I, 2).Value) .And. !Empty(oexcelapp.cells(I, 2).Value)
					If !Isnull(oexcelapp.cells(I, 7).Value)
						Insert Into C_TMP_I (data_t, data_v, debit, credit, detalii, nr, documente) ;
							Values (oexcelapp.cells(I, 4).Value, ;
							  Iif( !Empty(mdataextras), mdataextras, oexcelapp.cells(I, 4).Value), "", ;
							  Iif( !Isnull(oexcelapp.cells(I, 5).Value), Str(oexcelapp.cells(I, 5).Value, 15, 2), ""), ;
							  oexcelapp.cells(I, 7).Value, ;
							  Alltrim(Str(oexcelapp.cells(I, 2).Value)), ;
							  Alltrim(Transform(oexcelapp.cells(I, 1).Value)))

						If "    " $ Alltrim(C_TMP_I.detalii)
							Replace tert With Upper(Left(C_TMP_I.detalii,  At("    ",  C_TMP_I.detalii)))
						Endif
					Endif
					I = I + 1
				ENDDO
															
			Case m.llXLS AND (Type( "oExcelApp.Cells(6,14).Value" ) = "C" .And. Upper(Left(oexcelapp.cells(6, 14).Value, 11)) = "EXTRAS CONT")
				mtipimport = "ProCredit"
				I = 44
				Do While !Isnull(oexcelapp.cells(I, 10).Value) .And. !Empty(oexcelapp.cells(I, 10).Value)
					msumad = oexcelapp.cells(I, 19).Value
					msumac = oexcelapp.cells(I, 21).Value
					mdata = oexcelapp.cells(I, 10).Value
					mexplicatie = oexcelapp.cells(I, 13).Value
					If !Isnull(mexplicatie)
						mtert = ""
						If " SRL " $ mexplicatie .Or. " SA " $ mexplicatie
							If " SRL " $ mexplicatie
								msrl = " SRL"
							Else
								msrl = " SA "
							Endif
							mpozsrl = At(msrl, mexplicatie) + 4
							mpozstart1 = At(" ", mexplicatie, 2) + 1
							mpozstart2 = At(" ", mexplicatie, 3) + 1
							If getnumberincrement(Substr(mexplicatie, mpozstart1, mpozstart2 - mpozstart1)) > 0
								mpozstart1 = mpozstart2
							Endif
							If mpozsrl - mpozstart1 > 0
								mtert = Substr(mexplicatie, mpozstart1, mpozsrl - mpozstart1)
								mexplicatie = Substr(mexplicatie, mpozsrl + 1, 150)
							Endif
						Endif
						Insert Into C_TMP_I (data_t, data_v, debit, credit, nr, tert, detalii, iban) Values (mdata, mdata, Iif( !Isnull(msumad), msumad, ""), Iif( !Isnull(msumac), msumac, ""), "", mtert, mexplicatie, getibanfromstring(mexplicatie, 1))
					Endif
					I = I + 1
				Enddo
			Case m.llXLS AND (Type( "oExcelApp.Cells(2,2).Value" ) = "C" .And. Upper(Left(oexcelapp.cells(2, 2).Value, 15)) = "PATRIA BANK S.A")
				mtipimport = "Patria"
				I = 35
				mcontorinregistrari = 1
				Do While mcontorinregistrari <= 10
					msumad = oexcelapp.cells(I, 16).Value
					msumac = oexcelapp.cells(I, 21).Value
					mdata = oexcelapp.cells(I, 4).Value
					mexplicatie = oexcelapp.cells(I, 9).Value
					If !Isnull(mdata)
						Insert Into C_TMP_I (data_t, data_v, debit, credit, nr, tert, detalii) Values (mdata, mdata, Iif( !Isnull(msumad), msumad, ""), Iif( !Isnull(msumac), msumac, ""), "", "", mexplicatie)
						mcontorinregistrari = 1
					Else
						mcontorinregistrari = mcontorinregistrari + 1
					Endif
					I = I + 1
				Enddo
			Case m.llXLS AND (Type( "oExcelApp.Cells(5,1).Value" ) = "C" .And. Lower(Left(oexcelapp.cells(5, 1).Value, 20)) = "soldul depus �nainte")
				mtipimport = "Viva"
				I = 6
				Do While !Isnull(oexcelapp.cells(I, 1).Value) .And. !Empty(oexcelapp.cells(I, 1).Value)
					msuma = oexcelapp.cells(I, 5).Value
					mdata = Dtoc(oexcelapp.cells(I, 1).Value)
					Insert Into C_TMP_I (data_t, data_v, debit, credit, nr, tert) Values (mdata, mdata, Iif(msuma > 0, Str(msuma, 15, 2), ""), Iif(msuma < 0, Str(msuma, 15, 2), ""), "", Substr(oexcelapp.cells(I, 3).Value, At(" - ", oexcelapp.cells(I, 3).Value) + 3, 100))
					I = I + 1
				Enddo
			Case m.llXLS AND (Type( "oExcelApp.Cells(1,1).Value" ) = "C" .And. (Lower(Left(oexcelapp.cells(1, 1).Value, 15)) = "daily statement" .Or. Lower(Left(oexcelapp.cells(1, 1).Value, 17)) = "account statement"))
				mtipimport = "PNB"
				I = 12
				Do While !Isnull(oexcelapp.cells(I, 1).Value) .And. !Empty(oexcelapp.cells(I, 1).Value) .And. Type( "oExcelApp.Cells(i,5).Value" ) = "N"
					Insert Into C_TMP_I (data_t, data_v, detalii) Values (oexcelapp.cells(I, 1).Value, oexcelapp.cells(I, 2).Value, Alltrim(oexcelapp.cells(I, 3).Value))
					If oexcelapp.cells(I, 5).Value < 0
						Replace debit With Alltrim(Str(oexcelapp.cells(I, 5).Value, 15, 2))
					Else
						Replace credit With Alltrim(Str(oexcelapp.cells(I, 5).Value, 15, 2))
					Endif
					If oexcelapp.cells(I, 4).Value = "TRF"
						mlfinal = At( " Bank reference", oexcelapp.cells(I, 3).Value)
						minceput = At( " ", oexcelapp.cells(I, 3).Value, 3)
						If mlfinal > 0 .And. minceput > 0
							Replace tert With Substr(oexcelapp.cells(I, 3).Value, minceput + 1, mlfinal - minceput)
						Endif
					Endif
					Replace iban With getibanfromstring(oexcelapp.cells(I, 3).Value, 1)
					Replace cf With getdigitsfromstring(oexcelapp.cells(I, 3).Value, 4, 1, ".")
					I = I + 1
				Enddo

			Case m.llXLS AND Type( "oExcelApp.Cells(1,1).Value" ) = "C" .And. Lower(Left(oexcelapp.cells(1, 1).Value, 22)) = "nume client / companie"
				mtipimport = "SameDay"
				oexcelapp = oexcel.activeworkbook.sheets(2)
				I = 2
				If Lower(Left(oexcelapp.cells(1, 9).Value, 18)) = "ramburs transferat"
					Do While !Isnull(oexcelapp.cells(I, 11).Value) .And. !Empty(oexcelapp.cells(I, 11).Value)
						Insert Into C_TMP_I (data_t, data_v, debit, credit, detalii, nr, tert) Values (oexcelapp.cells(I, 10).Value, oexcelapp.cells(I, 11).Value, "", Iif( !Isnull(oexcelapp.cells(I, 8).Value), Str(oexcelapp.cells(I, 8).Value, 15, 2), ""), Alltrim(oexcelapp.cells(I, 3).Value) + " " + Alltrim(oexcelapp.cells(I, 4).Value) + " " + Alltrim(oexcelapp.cells(I, 5).Value), Alltrim(oexcelapp.cells(I, 1).Value), Alltrim(oexcelapp.cells(I, 2).Value))
						I = I + 1
					Enddo
				Else
					Do While !Isnull(oexcelapp.cells(I, 10).Value) .And. !Empty(oexcelapp.cells(I, 10).Value)
						Insert Into C_TMP_I (data_t, data_v, debit, credit, detalii, nr, tert) Values (oexcelapp.cells(I, 9).Value, oexcelapp.cells(I, 10).Value, "", Iif( !Isnull(oexcelapp.cells(I, 8).Value), Str(oexcelapp.cells(I, 8).Value, 15, 2), ""), Alltrim(oexcelapp.cells(I, 3).Value) + " " + Alltrim(oexcelapp.cells(I, 4).Value) + " " + Alltrim(oexcelapp.cells(I, 5).Value), Alltrim(oexcelapp.cells(I, 1).Value), Alltrim(oexcelapp.cells(I, 2).Value))
						I = I + 1
					Enddo
				Endif

			Case m.llXLSX AND (LEFT(LOWER(ALLTRIM(cXLSXTmp.mfield1)),3) = "awb") AND (LEFT(LOWER(ALLTRIM(cXLSXTmp.mfield2)),15) = "nume destinatar") 
				
				* Import SameDay din XLSX
				mtipimport = "SameDay"

				mdataextras = ""
				mnrstart = 1

				Insert Into C_TMP_I (data_t, data_v, debit, credit, detalii, nr, comenzi, tert) ;
					SELECT CAST(mfield9 as C(10)) as data_t, CAST(mfield10 as C(10)) as data_v, ;
						CAST('' as C(15)) as debit, CAST(Iif(!EMPTY(NVL(mfield8, '')), mfield8, "") as C(15)) as credit, ;
						  CAST(ALLTRIM(NVL(mfield2, '')) + ' ' + ALLTRIM(NVL(mfield3, '')) + ' ' + ALLTRIM(NVL(mfield4, '')) as C(250)) as detalii, CAST(mfield1 as C(16)) as nr, CAST(ALLTRIM(mfield1) as C(250)) as comenzi, ;
						  CAST(mfield2 as C(100)) as tert ;
  						FROM cXLSXTmp ;
						WHERE RECNO() > mnrstart AND !EMPTY(NVL(mfield8,'')) AND !EMPTY(NVL(mfield2,''))

			Case m.llXLS AND Type( "oExcelApp.Cells(1,1).Value" ) = "C" .And. Lower(Left(oexcelapp.cells(1, 1).Value, 10)) = "merchantid"
				mtipimport = "EuPlatesc"
				I = 2
				Do While !Isnull(oexcelapp.cells(I, 10).Value) .And. !Empty(oexcelapp.cells(I, 10).Value)
					mdataimp = ""
					mdatatest = oexcelapp.cells(I, 10).Value
					Do Case
						Case Type("mDataTest") = "T"
							mdataimp = Dtoc(mdatatest)
						Case Type("mDataTest") = "D"
							mdataimp = Left(Ttoc(mdatatest), 10)
						Otherwise
							mdataimp = mdatatest
					Endcase
					mnrdoc = ""
					mnrdoctest = oexcelapp.cells(I, 2).Value
					If Type("mNrDocTest") = "N"
						mnrdoc = Alltrim(Str(mnrdoctest, 15, 0))
					Else
						mnrdoc = mnrdoctest
					Endif
					Insert Into C_TMP_I (data_t, data_v, debit, credit, detalii, nr, tert, comision) Values (mdataimp, mdataimp, Iif( !Isnull(oexcelapp.cells(I, 11).Value), Alltrim(Str(oexcelapp.cells(I, 11).Value, 15, 2)), ""), Iif( !Isnull(oexcelapp.cells(I, 6).Value), Alltrim(Str(oexcelapp.cells(I, 6).Value, 15, 2)), ""), Alltrim(oexcelapp.cells(I, 3).Value), mnrdoc, Iif( !Isnull(oexcelapp.cells(I, 4).Value), Alltrim(oexcelapp.cells(I, 4).Value), ""), Iif( !Isnull(oexcelapp.cells(I, 13).Value), oexcelapp.cells(I, 13).Value, 0))
					I = I + 1
				Enddo
			Case m.llXLS AND Type( "oExcelApp.Cells(1,1).Value" ) = "C" .And. Lower(Left(oexcelapp.cells(1, 1).Value, 13)) = "expeditie tur"
				mtipimport = "Cargus"
				I = 3
				Do While !Isnull(oexcelapp.cells(I, 12).Value) .And. !Empty(oexcelapp.cells(I, 12).Value)
					Insert Into C_TMP_I (data_t, data_v, debit, credit, detalii, nr, tert) Values (Dtoc(oexcelapp.cells(I, 9).Value), Dtoc(oexcelapp.cells(I, 12).Value), "", Iif( !Isnull(oexcelapp.cells(I, 11).Value), Str(oexcelapp.cells(I, 11).Value, 15, 2), ""), "Data " + Dtoc(oexcelapp.cells(I, 9).Value) + " Nr chit. " + Alltrim(oexcelapp.cells(I, 10).Value), Alltrim(oexcelapp.cells(I, 13).Value), Alltrim(oexcelapp.cells(I, 5).Value))
					I = I + 1
				Enddo
			Case m.llXLS AND Type( "oExcelApp.Cells(1,1).Value" ) = "C" .And. Lower(Left(oexcelapp.cells(1, 1).Value, 22)) = "chitanta cont colector"
				mtipimport = "Cargus"
				I = 1
				For I = 1 To 100
					If oexcelapp.cells(I, 1).Value = "Data"
						mnrstart = I
						Exit
					Endif
				Endfor
				If mnrstart = 0
					Return
				Endif
				I = mnrstart + 1
				If Type( "oExcelApp.Cells(i,8).Value" ) = "T"
					Do While !Isnull(oexcelapp.cells(I, 8).Value) .And. !Empty(oexcelapp.cells(I, 8).Value)
						Insert Into C_TMP_I (data_t, data_v, debit, credit, detalii, nr, tert) Values (Dtoc(oexcelapp.cells(I, 1).Value), Dtoc(oexcelapp.cells(I, 8).Value), "", Iif( !Isnull(oexcelapp.cells(I, 3).Value), Str(oexcelapp.cells(I, 3).Value, 15, 2), ""), "Data " + Dtoc(oexcelapp.cells(I, 1).Value) + " Serie chit. " + Alltrim(oexcelapp.cells(I, 2).Value) + " Serie deco. " + Alltrim(oexcelapp.cells(I, 5).Value), Alltrim(oexcelapp.cells(I, 9).Value), Alltrim(oexcelapp.cells(I, 7).Value))
						I = I + 1
					Enddo
				Else
					Do While !Isnull(oexcelapp.cells(I, 9).Value) .And. !Empty(oexcelapp.cells(I, 9).Value)
						Insert Into C_TMP_I (data_t, data_v, debit, credit, detalii, nr, tert) Values (Dtoc(oexcelapp.cells(I, 1).Value), Dtoc(oexcelapp.cells(I, 9).Value), "", Iif( !Isnull(oexcelapp.cells(I, 3).Value), Str(oexcelapp.cells(I, 3).Value, 15, 2), ""), "Data " + Dtoc(oexcelapp.cells(I, 1).Value) + " Serie chit. " + Alltrim(oexcelapp.cells(I, 2).Value) + " Serie deco. " + Alltrim(oexcelapp.cells(I, 6).Value), Alltrim(oexcelapp.cells(I, 10).Value), Alltrim(oexcelapp.cells(I, 8).Value))
						I = I + 1
					Enddo
				Endif

			Case m.llXLSX AND ((LEFT(LOWER(ALLTRIM(cXLSXTmp.mfield1)),8) = "perioada") OR (LEFT(LOWER(ALLTRIM(cXLSXTmp.mfield1)),20) = "data generare extras"))
				* Import RAIFFEISEN din XLSX
				SELECT cXLSXTmp
				LOCATE FOR 'RAIFFEISEN'$mfield2
				IF !FOUND()
					AMessagebox( "Format fisier incorect.", 16, "Import extrase" )
					Return .F.
				ENDIF 

				LOCATE FOR ATC('Cod IBAN:', mfield1) > 0
				IF FOUND()
					This.cIBAN = UPPER(ALLTRIM(mfield2))
				ENDIF 					

				mtipimport = "RAIFFEISEN"


				
				mdataextras = ""
				mnrstart = 18

				Insert Into C_TMP_I (data_t, data_v, debit, credit, detalii, nr, comenzi) ;
					SELECT CAST(mfield1 as C(10)) as data_t, CAST(mfield2 as C(10)) as data_v, ;
						CAST(Iif(!EMPTY(NVL(mfield3, '')), mfield3, "") as C(15)) as debit, CAST(Iif(!EMPTY(NVL(mfield4, '')), mfield4, "") as C(15)) as credit, ;
						  CAST(mfield12 as C(250)) as detalii, CAST(mfield9 as C(120)) as tert, CAST(ALLTRIM(mfield11) as C(24)) as iban ;
  						FROM cXLSXTmp ;
						WHERE RECNO() > mnrstart AND !EMPTY(NVL(mfield1,'')) AND !EMPTY(NVL(mfield2,''))

				SELECT C_TMP_I
				SCAN FOR " CUI " $ UPPER(detalii) OR " CUI:" $ UPPER(detalii)
					mcf = getdigitsfromstring(C_TMP_I.detalii, 4, 1, ".")
					SELECT C_TMP_I
					IF !EMPTY(mcf)
						REPLACE cf WITH m.mcf
					ENDIF 	
				ENDSCAN 	
				
			Case m.llXLS AND (Type( "oExcelApp.Cells(1,1).Value" ) = "C" .And. Lower(Left(oexcelapp.cells(1, 1).Value, 21)) = "data generare extras:" .Or. (Type( "oExcelApp.Cells(2,1).Value" ) = "C" .And. Lower(Left(oexcelapp.cells(2, 1).Value, 21)) = "data generare extras:" ))

				mtipimport = "RAIFFEISEN"
				I = 1
				For I = 1 To 100
					If Lower(Left(oexcelapp.cells(I, 1).Value, 17)) = "data inregistrare"
						mnrstart = I
						Exit
					Endif
				Endfor
				If mnrstart = 0
					Return
				Endif
				I = mnrstart + 2
				Do While !Isnull(oexcelapp.cells(I, 2).Value) .And. !Empty(oexcelapp.cells(I, 2).Value)
					If !Isnull(oexcelapp.cells(I, 12).Value)
						Insert Into C_TMP_I (data_t, data_v, debit, credit, detalii, cf, tert, iban, nr) Values (oexcelapp.cells(I, 1).Value, oexcelapp.cells(I, 2).Value, Iif( !Isnull(oexcelapp.cells(I, 3).Value), Str(oexcelapp.cells(I, 3).Value, 15, 2), ""), Iif( !Isnull(oexcelapp.cells(I, 4).Value), Str(oexcelapp.cells(I, 4).Value, 15, 2), ""), oexcelapp.cells(I, 12).Value, Iif( !Isnull(oexcelapp.cells(I, 6).Value), oexcelapp.cells(I, 6).Value, ""), Iif( !Isnull(oexcelapp.cells(I, 9).Value), oexcelapp.cells(I, 9).Value, ""), Iif( !Isnull(oexcelapp.cells(I, 11).Value), oexcelapp.cells(I, 11).Value, ""), Iif( !Isnull(oexcelapp.cells(I, 5).Value), oexcelapp.cells(I, 5).Value, ""))
					Endif
					I = I + 1
				Enddo
			CASE m.llXLS
				mtipimport = "LIBRA"
				I = 1
				For I = 1 To 100
					If Type( "oExcelApp.Cells(i,2).Value" ) = "C" .And. Lower(Left(oexcelapp.cells(I, 2).Value, 4)) = "data"
						mnrstart = I
						Exit
					Endif
				Endfor
				If mnrstart = 0
					Messagebox( "Format XLS incorect.", 16, "Import extrase" )
					Return .F.
				Endif
				I = mnrstart + 1
				mcoldata = 0
				mcolexplicatie = 0
				mcoldebit = 0
				mcolcredit = 0
				For jj = 1 To 18
					If mcoldata = 0 .And. Type( "oExcelApp.Cells(mNrStart,jj).Value" ) = "C" .And. Lower(Left(oexcelapp.cells(mnrstart, jj).Value, 4)) = "data"
						mcoldata = jj
						Loop
					Endif
					If jj > mcoldata .And. mcoldata <> 0 .And. mcolexplicatie = 0 .And. Type( "oExcelApp.Cells(mNrStart,jj).Value" ) = "C" .And. Lower(Left(oexcelapp.cells(mnrstart, jj).Value, 9)) = "descriere"
						mcolexplicatie = jj
						Loop
					Endif
					If jj > mcolexplicatie .And. mcoldata <> 0 .And. mcolexplicatie <> 0 .And. mcoldebit = 0 .And. Type( "oExcelApp.Cells(mNrStart,jj).Value" ) = "C" .And. Lower(Left(oexcelapp.cells(mnrstart, jj).Value, 5)) = "debit"
						mcoldebit = jj
						Loop
					Endif
					If jj > mcoldebit .And. mcoldata <> 0 .And. mcolexplicatie <> 0 .And. mcoldebit <> 0 .And. mcolcredit = 0 .And. Type( "oExcelApp.Cells(mNrStart,jj).Value" ) = "C" .And. Lower(Left(oexcelapp.cells(mnrstart, jj).Value, 6)) = "credit"
						mcolcredit = jj
					Endif
				Endfor
				If mcoldata = 0 .Or. mcolexplicatie = 0 .Or. mcoldebit = 0 .Or. mcolcredit = 0
					Messagebox( "Format XLS incorect.", 16, "Import extrase" )
					Return .F.
				Endif
				Do While !Isnull(oexcelapp.cells(I, mcoldata).Value) .And. !Empty(oexcelapp.cells(I, mcoldata).Value)
					If Type( "oExcelApp.Cells(i,mColDebit).Value" ) = "N"
						mdebit = Alltrim(Str(oexcelapp.cells(I, mcoldebit).Value, 15, 2))
					Else
						mdebit = Alltrim(oexcelapp.cells(I, mcoldebit).Value)
					Endif
					If Type( "oExcelApp.Cells(i,mColCredit).Value" ) = "N"
						mcredit = Alltrim(Str(oexcelapp.cells(I, mcolcredit).Value, 15, 2))
					Else
						mcredit = Alltrim(oexcelapp.cells(I, mcolcredit).Value)
					Endif
					If !Isnull(mdebit) .And. !Isnull(mcredit)
						Insert Into C_TMP_I (data_t, detalii, data_v, debit, credit) Values (oexcelapp.cells(I, mcoldata).Value, oexcelapp.cells(I, mcolexplicatie).Value, oexcelapp.cells(I, mcoldata).Value, mdebit, mcredit)
					Endif
					I = I + 1
				ENDDO
			OTHERWISE 
				AMessagebox( "Format fisier incorect.", 16, "Import extrase" )
				Return .F.	
		ENDCASE 

		USE IN (SELECT('cXLSXTmp'))
		

		UPDATE C_TMP_I SET data_v = TRANSFORM(ExcelSerialNumber2Date(INT(VAL(data_v)))) WHERE !('.'$data_v OR '/'$data_v)
		UPDATE C_TMP_I SET data_t = TRANSFORM(ExcelSerialNumber2Date(INT(VAL(data_t)))) WHERE !('.'$data_v OR '/'$data_t)
		Select C_TMP_I
		Scan For !Empty(data_v)
			Select c_iex
			Insert Into c_iex (Data, documente, comenzi) Values (setdategerman(C_TMP_I.data_v), C_TMP_I.documente, C_TMP_I.comenzi)
			If !Empty(C_TMP_I.debit) .And. Val(C_TMP_I.debit) <> 0
				Replace tip With "D"
				msuma = This.setsuma(C_TMP_I.debit)
			Else
				Replace tip With "C"
				If mtipimport = "eMag"
					msuma = Val(C_TMP_I.credit)
				Else
					msuma = This.setsuma(C_TMP_I.credit)
				Endif
			Endif
			Replace suma With msuma
						
			mexplicatie = Alltrim(C_TMP_I.detalii)
			mexplicatie = Strtran(mexplicatie, " ", " ")
			mtert = ""
			mcf = ""

			Do Case
				Case LEFT(ALLTRIM(LOWER(NVL(mexplicatie,''))), 8) = "comision" OR ;
					'comision-atm'$LOWER(NVL(mexplicatie,'')) OR ;
					'comision procesare ridicare numerar'$LOWER(NVL(mexplicatie,'')) OR ;
					'pachet izi'$LOWER(NVL(mexplicatie,'')) OR ;
					'abonament'$LOWER(NVL(mexplicatie,'')) 			
					Replace tip_2 With This.cTipComisioane
					
				Case 'retragere de numerar'$ALLTRIM(LOWER(NVL(mexplicatie,''))) OR ;
					'depunere de numerar'$ALLTRIM(LOWER(NVL(mexplicatie,''))) OR ;
					'depunere numerar'$ALLTRIM(LOWER(NVL(mexplicatie,''))) OR ;
					'retragere numerar'$ALLTRIM(LOWER(NVL(mexplicatie,'')))
					Replace tip_2 With This.cTipDepunere										

				Case 'transfer intern'$ALLTRIM(LOWER(NVL(mexplicatie,''))) OR ;
					'dob.dep'$ALLTRIM(LOWER(NVL(mexplicatie,'')))
					Replace tip_2 With This.cTipTransfer
				
				Otherwise
					Replace tip_2 With ""
			ENDCASE
			
			If "Detalii: " $ mexplicatie
				mexplicatie1 = Substr(mexplicatie, Atc( "Detalii: ", mexplicatie) + 9, 100)
				mtexttert = Left(mexplicatie, Atc( "Detalii: ", mexplicatie) - 1)
			Else
				mexplicatie1 = mexplicatie
				mtexttert = mexplicatie
			Endif
			If Empty(C_TMP_I.tert)
				If c_iex.tip = "D" .And. "beneficiar: " $ Lower(mtexttert)
					mtext1 = Substr(mtexttert, Atc( "Beneficiar: ", mtexttert) + 12, 60)
					mlungime = Min(Iif(Occurs( " RO", Upper(mtext1)) > 0, Atc( " RO", mtext1, Occurs( " RO", Upper(mtext1))), 60), Iif( "cont benef" $ Lower(mtext1), Atc( "Cont benef", mtext1), 60), Iif("platitor" $ Lower(mtext1), Atc("Platitor", mtext1), 60))
					mlungime = Max(mlungime, 7) - 1
					mtert = Left(mtext1, mlungime)
				Else
					If "platitor: " $ Lower(mtexttert)
						mtext1 = Substr(mtexttert, Atc( "Platitor: ", mtexttert) + 10, 60)
						mlungime = Iif(Occurs( " RO", Upper(mtext1)) > 0, Atc( " RO", mtext1, Occurs( " RO", Upper(mtext1))), 60)
						mlungime = Max(mlungime, 7) - 1
						mtert = Left(mtext1, mlungime)
					Endif
				Endif
			Else
				mtert = Alltrim(Upper(C_TMP_I.tert))
			Endif

			mcf = getdigitsfromstring(C_TMP_I.detalii, 13, 2, ".")
			If Empty(mcf)
				If Empty(C_TMP_I.cf) .And. !Inlist(mtipimport, "GLS", "FAN", "Cargus", "PNB", "eMAG", "SameDay", "Patria", "ProCredit")
					mcf = getdigitsfromstring(C_TMP_I.detalii, 4, 1, ".")
				Else
					mcf = Alltrim(C_TMP_I.cf)
				Endif
			Endif
			mtextoriginal = C_TMP_I.data_v + " " + Chr(13) + Alltrim(C_TMP_I.debit) + Alltrim(C_TMP_I.credit) + " " + Chr(13) + Alltrim(C_TMP_I.nr) + " " + Alltrim(C_TMP_I.cf) + Chr(13) + Alltrim(C_TMP_I.tert) + " " + Alltrim(C_TMP_I.iban) + " " + Chr(13) + Alltrim(C_TMP_I.detalii) + " "
			Replace tert With Upper(mtert), cf With mcf, explicatie With mexplicatie1, original With mtextoriginal, nr With C_TMP_I.nr, iban With C_TMP_I.iban
			If mtipimport = "eMag" .And. !Empty(c_iex.nr)
				Select match
				Locate For inf_suplm = Alltrim(c_iex.nr)
				If Found()
					Replace id_pi With c_iex.Id
					If Empty(c_iex.cod) .Or. c_iex.cod <> match.cod
						Replace cod With match.cod, tert With match.denumire In c_iex
					Endif
					Select match
					Replace achitat With c_iex.suma
					This.actsume()
					Replace asociat With 1 In c_iex
				Endif
			Endif
		Endscan
		Select data_v, Sum(comision) As comision From C_TMP_I Group By data_v Into Cursor C_COMISON
		Scan For comision > 0
			Insert Into c_iex (Data, suma, tip, tip_2) Values (setdategerman(C_COMISON.data_v), C_COMISON.comision, "D", "COM")
		Endscan

		Use In (Select('C_TMP_I'))
		IF EMPTY(this.cIBAN)
			This.cIBAN = m.mtipimport
		ENDIF 			
	Endfunc
	*
	Procedure csvFirstBank
		Lparameters pselectedfile
		Local mtextoriginal
		This.cIBAN = 'FirstBank'
		mtextoriginal = ""
		mfilestr = Filetostr(pselectedfile)
		mfilestr = Strtran(mfilestr, '=', '')
		If "Transaction History" $ mfilestr .Or. "Istoric Tranzac" $ mfilestr
			Create Cursor C_TMP_I (data_t C (10), data_v C (10), tip_op C (100), referinta C (200), explicatie C (200), suma C (15))
		Else
			Create Cursor C_TMP_I (data_t C (10), data_v C (10), suma C (15), referinta C (200), tip_op C (100), explicatie C (200))
		Endif
		Strtofile(mfilestr, m.gcTempPath + "FirstBankTMP.csv")
		Append From (m.gcTempPath + "FirstBankTMP.csv") Delimited With Character ";"

		Delete For Empty(Ctod(C_TMP_I.data_t))
		Scan For !Empty(data_t) .And. !Empty(setdategerman(C_TMP_I.data_t))
			Select c_iex
			Insert Into c_iex (Data) Values (setdategerman(C_TMP_I.data_t))
			If "-" $ C_TMP_I.suma
				Replace tip With "D"
			Else
				Replace tip With "C"
			Endif
			Replace suma With This.setsuma(C_TMP_I.suma)
			Do Case
				Case "comis" $ Lower(C_TMP_I.tip_op)
					Replace tip_2 With "COM"
				Otherwise
					Replace tip_2 With ""
			Endcase
			mexplicatie = C_TMP_I.explicatie
			mtert = ""
			miban = ""
			If Occurs(",", mexplicatie) > 0
				mtert = Upper(Left(mexplicatie, At(",", mexplicatie) - 1))
			Endif
			miban = getibanfromstring(mexplicatie, 1)
			If !Empty(miban)
				mtert = Left(mexplicatie, At(miban, mexplicatie) - 1)
				mexplicatie = Substr(mexplicatie, At(miban, mexplicatie) + 25, 100)
			Endif
			Replace tert With mtert, iban With miban
			mtextoriginal = C_TMP_I.data_t + " " + Chr(13) + C_TMP_I.suma + " " + Chr(13) + Alltrim(C_TMP_I.tip_op) + " " + Chr(13) + Alltrim(C_TMP_I.explicatie)
			Replace explicatie With mexplicatie, original With mtextoriginal
		Endscan
	Endproc
	*
	Procedure csvOTP
		Lparameters pselectedfile
		Local mtextoriginal, mexplicatie, mtert, miban, mstarttert, mstartcont, mdataop
		This.cIBAN = 'OTP'
		mtextoriginal = ""
		Create Cursor C_TMP_I (detalii1 C (200), data_v C (10), data_op C (10), detalii2 C (200), debit C (15), credit C (15))
		mfilestr = Filetostr(pselectedfile)
		mlen = Len(mfilestr)
		If Occurs('""', mfilestr) > 20
			mfilestr = EliminVirguleDintreGhilimele(mfilestr, '""')
			mfilestr = Strtran(mfilestr, '"', '')
			Strtofile(mfilestr, m.gcTempPath + "OTPTMP.csv")
			Append From (m.gcTempPath + "OTPTMP.csv") Csv
		Else
			Append From (mSelectedFile) Csv
		Endif
		Scan For !Empty(data_op)
			Select c_iex
			mdataop = Substr(C_TMP_I.data_op, 7, 2) + "." + Substr(C_TMP_I.data_op, 5, 2) + "." + Substr(C_TMP_I.data_op, 1, 4)
			Insert Into c_iex (Data) Values (Ctod(mdataop))
			mtert = ""
			miban = ""
			mstarttert = 0
			mexplicatie = Alltrim(C_TMP_I.detalii2)
			If EMPTY(VAL(Alltrim(C_TMP_I.credit)))
				Replace tip With "D"
				msuma = Abs(Val(C_TMP_I.debit))
				If "Ben:" $ C_TMP_I.detalii2
					mstarttert = At("Ben:", mexplicatie) + 5
					mstartcont = At("Cont:", mexplicatie) + 6
					mtert = Substr(mexplicatie, mstarttert, mstartcont - mstarttert - 8)
					miban = Substr(mexplicatie, mstartcont, 24)
				Endif
			Else
				Replace tip With "C"
				msuma = Abs(Val(C_TMP_I.credit))
				If "Platitor:" $ C_TMP_I.detalii2
					mstarttert = At("Platitor:", mexplicatie) + 10
					mstartcont = At("Cont:", mexplicatie) + 6
					mtert = Substr(mexplicatie, mstarttert, mstartcont - mstarttert - 8)
					miban = Substr(mexplicatie, mstartcont, 24)
				Endif
			Endif
			Replace suma With msuma
			Do Case
				Case "comision" $ Lower(C_TMP_I.detalii2)
					Replace tip_2 With "COM"
				Otherwise
					Replace tip_2 With ""
			Endcase
			mtextoriginal = Alltrim(C_TMP_I.detalii1) + Chr(13) + Alltrim(C_TMP_I.data_op) + " " + Chr(13) + Iif(C_TMP_I.debit <> "0.00", Alltrim(C_TMP_I.debit), Alltrim(C_TMP_I.credit)) + " " + Chr(13) + Alltrim(C_TMP_I.detalii2)
			Replace nr With Alltrim(Str(Recno())), tert With Upper(mtert), explicatie With mexplicatie, original With mtextoriginal, iban With miban
		Endscan
	Endproc
	*

	Procedure xmlAsc

		Lparameters pselectedfile
		Local oxml, orootnode, orootnodecontext, orootnodecontmisc, ij, npass, onode, nnumlinii, nchildlen, mtextoriginal
		This.cIBAN = 'XML'
		mtextoriginal = ""
		oxml = Createobject('MSXML2.DomDocument')
		oxml.Async = .F.
		oxml.Load(pselectedfile)
		orootnode = oxml.documentelement
		If Isnull(orootnode)
			AMessagebox( "Fisier de XML invalid.", 16, "Eroare import extrase" )
			Return
		Endif
		Do Case
			Case orootnode.nodename = "document"
				orootnodecontext = orootnode.childnodes.Item(2)
				If orootnodecontext.nodename <> "movements"
					Messagebox( "Format XML invalid.", 64, "Atentie...")
					Return
				Endif
				nnumliniicontext = orootnodecontext.childnodes.Length
				For ij = 0 To (nnumliniicontext - 1)
					orootnodecontmisc = orootnodecontext.childnodes.Item(ij)
					If orootnodecontmisc.nodename <> "movement"
						Loop
					Endif
					nnumlinii = orootnodecontmisc.childnodes.Length
					m.cf = ""
					m.tert = ""
					m.iban = ""
					m.suma = 0
					m.explicatie = ""
					m.data = {}
					m.debit = ""
					m.credit = ""
					m.suma = ""
					m.original = ""
					For npass = 0 To (nnumlinii - 1)
						olinienode = orootnodecontmisc.childnodes.Item(npass)
						cvalue = olinienode.Text
						cparentname = olinienode.nodename
						Do Case
							Case cparentname == "ref"
								m.nr = cvalue
							Case cparentname == "value_date"
								m.data = setdategerman(cvalue)
							Case cparentname = "debit"
								m.debit = Val(cvalue)
							Case cparentname = "credit"
								m.credit = Val(cvalue)
							Case cparentname == "details"
								m.explicatie = cvalue
						Endcase
						If !Empty(cvalue)
							m.original = M.original + cvalue + Chr(13)
						Endif
					Endfor
					Select c_iex
					If m.data >= Ctod("01.01.2015")
						Insert Into c_iex (Data) Values (m.data)
						If m.credit = 0
							m.suma = M.debit
							Replace tip With "D", ip With "I" In c_iex
						Else
							m.suma = M.credit
							Replace tip With "C", ip With "P" In c_iex
						Endif
						If "comision" $ Lower(m.explicatie)
							Replace tip_2 With "COM" In c_iex
						Endif
						If "in fav." $ M.explicatie
							mtext1 = Substr(m.explicatie, At( "in fav.", M.explicatie) + 8)
							mdouapuncte = At(":", mtext1) - 1
							If mdouapuncte > 0
								m.tert = Substr(mtext1, 1, mdouapuncte)
							Endif
						Endif
						If "Denumire Client:" $ M.explicatie
							mtext1 = Substr(m.explicatie, At( "Denumire Client:", M.explicatie) + 17)
							mvirgula = At(",", mtext1) - 1
							If mvirgula > 0
								m.tert = Substr(mtext1, 1, mvirgula)
							Endif
						Endif
						Gather Memvar
					Endif
				Endfor
			Case orootnode.nodename = "extras"
				orootnodecontext = orootnode.childnodes.Item(0)
				If orootnodecontext.nodename <> "cont_ext"
					AMessagebox( "Format XML invalid.", 64, "Atentie...")
					Return
				Endif
				nnumliniicontext = orootnodecontext.childnodes.Length
				For ij = 0 To (nnumliniicontext - 1)
					orootnodecontmisc = orootnodecontext.childnodes.Item(ij)
					If orootnodecontmisc.nodename <> "cont_misc"
						Loop
					Endif
					nnumlinii = orootnodecontmisc.childnodes.Length
					m.cf = ""
					m.tert = ""
					m.iban = ""
					m.suma = 0
					m.explicatie = ""
					m.data = {}
					m.debit = ""
					m.credit = ""
					m.suma = ""
					m.original = ""
					For npass = 0 To (nnumlinii - 1)
						olinienode = orootnodecontmisc.childnodes.Item(npass)
						cvalue = olinienode.Text
						cparentname = olinienode.nodename
						Do Case
							Case cparentname == "nrdoc"
								m.nr = cvalue
							Case cparentname == "datadoc"
								m.data = setdategerman(cvalue)
							Case cparentname == "platitor"
								m.cf = Upper(cvalue)
							Case cparentname == "numepb"
								m.tert = Upper(cvalue)
							Case cparentname == "ibanbfpl"
								m.iban = Upper(cvalue)
							Case cparentname = "sumad"
								m.debit = Val(cvalue)
							Case cparentname = "sumac"
								m.credit = Val(cvalue)
							Case cparentname == "explicatii"
								m.explicatie = cvalue
						Endcase
						If !Empty(cvalue)
							m.original = M.original + cvalue + Chr(13)
						Endif
					Endfor
					Select c_iex
					If m.data >= Ctod("01.01.2015")
						Insert Into c_iex (Data) Values (m.data)
						If m.credit = 0
							m.suma = M.debit
							Replace tip With "D", ip With "I" In c_iex
						Else
							m.suma = M.credit
							Replace tip With "C", ip With "P" In c_iex
						Endif
						If "comision" $ Lower(m.explicatie)
							Replace tip_2 With "COM" In c_iex
						Endif
						Gather Memvar
					Endif
				Endfor
			Otherwise
				AMessagebox( "Format XML invalid.", 64, "Atentie...")
		Endcase
	Endproc
	*

	Procedure csvAlpha
		Lparameters pselectedfile
		Local mtextoriginal
		This.cIBAN = 'Alpha'
		mtextoriginal = ""
		Create Cursor C_TMP_I (data_v C (16), data_t C (16), explicatie C (250), referinta C (60), valuta C (3), suma C (15), tip C (2), valuta1 C (3), sold C (15))

		Append From (pselectedfile) Delimited With Char ";"

		Scan For !Empty(data_t) .And. !Empty(setdategerman(C_TMP_I.data_t))
			Select c_iex
			Insert Into c_iex (Data) Values (setdategerman(Alltrim(C_TMP_I.data_t)))
			If Alltrim(C_TMP_I.tip) = "C"
				Replace tip With "C"
			Else
				Replace tip With "D"
			Endif
			Replace suma With This.setsuma(C_TMP_I.suma)
			mexplicatie = Alltrim(C_TMP_I.explicatie)
			Do Case
				Case "comision" $ Lower(mexplicatie)
					Replace tip_2 With "COM"
				Otherwise
					Replace tip_2 With ""
			Endcase


			miban = ""

			miban = getibanfromstring(mexplicatie, 1)
			mpoziban = 0
			If miban = "RO"
				mpoziban = At(miban, mexplicatie)
			Endif
			mtert = ""
			mcf = ""
			If c_iex.tip = "C"
				If "PLATITOR: " $ mexplicatie
					mpoztertstart = At( "PLATITOR: ", mexplicatie) + 10
					If mpoziban > mpoztertstart
						mtert1 = Alltrim(Substr(mexplicatie, mpoztertstart, mpoziban - mpoztertstart))
					Else
						mtert1 = Alltrim(Substr(mexplicatie, mpoztertstart, 100))
					Endif
					If "," $ mtert1
						mtert = Left(mtert1, At( ",", mtert1) - 1)
					Else
						mtert = mtert1
					Endif
				Endif
			Else
				If "BENEFICIAR: " $ mexplicatie
					mpoztertstart = At( "BENEFICIAR: ", mexplicatie) + 12
					If (mpoziban - 9) > mpoztertstart
						mtert1 = Alltrim(Substr(mexplicatie, mpoztertstart, (mpoziban - 9) - mpoztertstart))
					Else
						mtert1 = Alltrim(Substr(mexplicatie, mpoztertstart, 100))
					Endif
					If "," $ mtert1
						mtert = Left(mtert1, At( ",", mtert1) - 1)
					Else
						mtert = mtert1
					Endif
				Endif
			Endif
			mexplicatiereal = ""
			If "END TO END " $ mexplicatie .Or. "URGENT " $ mexplicatie
				If "END TO END " $ mexplicatie
					mpoztertexplfin = At( "END TO END ", mexplicatie) - 1
				Else
					mpoztertexplfin = At( "URGENT ", mexplicatie) - 1
				Endif
				If "DETALII INCASARE: " $ mexplicatie
					mpoztertexplstart = At( "DETALII INCASARE: ", mexplicatie) + 18
					mexplicatiereal = Alltrim(Substr(mexplicatie, mpoztertexplstart, mpoztertexplfin - mpoztertexplstart))
				Else
					If "DETALII PLATA: " $ mexplicatie
						mpoztertexplstart = At( "DETALII PLATA: ", mexplicatie) + 15
						mexplicatiereal = Alltrim(Substr(mexplicatie, mpoztertexplstart, mpoztertexplfin - mpoztertexplstart))
					Else
						mexplicatiereal = mexplicatie
					Endif
				Endif
			Endif
			Replace tert With mtert, iban With miban, cf With mcf
			mtextoriginal = C_TMP_I.data_t + " " + Chr(13) + C_TMP_I.suma + " " + Chr(13) + Alltrim(mexplicatie)
			Replace explicatie With mexplicatiereal, original With mtextoriginal
		Endscan
	Endproc
	*

	Procedure csvBCR
		Lparameters pselectedfile
		Local mtextoriginal, mfilestr, mlen, ij, mpas
		This.cIBAN = 'BCR'
		mtextoriginal = ""
		Create Cursor C_TMP_I (data_e C (10), ora_e C (6), data_i C (10), data_s C (10), valuta C (16), Curs C (16), Cont C (24), tip C (24), titular C (60), sold_i C (15), data_final C (10), ora_fin C (6), detalii C (250), referinta C (60), debit C (15), credit C (15), t_debit C (15), t_credit C (15), sold_f C (15), sume_b C (15), sold_d C (15), plafon C (15))
		mfilestr = Filetostr(pselectedfile)
		If Occurs('""', mfilestr) >= 4
			mfilestr = EliminVirguleDintreGhilimele(mfilestr, '""')
		Else
			mfilestr = EliminVirguleDintreGhilimele(mfilestr, '"')
		Endif
		mfilestr = Strtran(mfilestr, '"', '')
		Strtofile(mfilestr, m.gcTempPath + "BCRTMP.csv")
		Select C_TMP_I
		Append From (m.gcTempPath + "BCRTMP.csv") Csv
		Delete For Empty(Ctod(C_TMP_I.data_final))
		Scan For !Empty(data_final) .And. !Empty(detalii)
			Select c_iex
			Insert Into c_iex (Data) Values (Ctod(C_TMP_I.data_final))
			If EMPTY(VAL(Alltrim(C_TMP_I.credit)))
				Replace tip With "D", suma With This.setsuma(C_TMP_I.debit)
			Else
				Replace tip With "C", suma With This.setsuma(C_TMP_I.credit)
			Endif
			Do Case
				Case "comision " $ C_TMP_I.detalii .Or. "Operatiuni fara numerar" $ C_TMP_I.detalii
					Replace tip_2 With "COM"
				Case "rambursare automata" $ Lower(C_TMP_I.detalii) .Or. "tragere automata" $ Lower(C_TMP_I.detalii)
					Replace tip_2 With "XXX"
				Otherwise
					Replace tip_2 With "TRF"
			Endcase
			mnr = Alltrim(Substr(C_TMP_I.referinta, At("Ordin de plata ", C_TMP_I.referinta) + 15, 100))
			Replace nr With Left(mnr, At(".", mnr) - 4)
			mtert = ""
			mcf = ""
			If tip = "C"
				If "Ordonator: " $ C_TMP_I.detalii
					mtert = Alltrim(Substr(C_TMP_I.detalii, At( "Ordonator: ", C_TMP_I.detalii) + 11, 100))
				Endif
				If "Platitor: " $ C_TMP_I.detalii
					mtert = Alltrim(Substr(C_TMP_I.detalii, At( "Platitor: ", C_TMP_I.detalii) + 10, 100))
				Endif
				mcf = Alltrim(Str(Val(Alltrim(Substr(C_TMP_I.detalii, At("CODFISC ", C_TMP_I.detalii) + 8, 13))), 13, 0))
			Else
				If "Ordonator: " $ C_TMP_I.detalii
					mtert = Alltrim(Substr(C_TMP_I.detalii, At( "Ordonator: ", C_TMP_I.detalii) + 11, 100))
				Endif
				If "Beneficiar: " $ C_TMP_I.detalii
					mtert = Alltrim(Substr(C_TMP_I.detalii, At( "Beneficiar: ", C_TMP_I.detalii) + 12, 100))
				Endif
				If "CODFISC" $ C_TMP_I.detalii
					mcf = Alltrim(Str(Val(Alltrim(Substr(C_TMP_I.detalii, At( "CODFISC ", C_TMP_I.detalii, Occurs("CODFISC", C_TMP_I.detalii)) + 8, 13))), 13, 0))
				Endif
			Endif
			If ";" $ mtert
				mtert = Left(mtert, At(";", mtert) - 1)
			Else
				mlen = Len(mtert)
				mspace = mlen
				For ij = 1 To mlen
					If Substr(mtert, ij, 1) == " "
						mspace = ij
					Endif
					If Isdigit(Substr(mtert, ij, 1))
						Exit
					Endif
				Endfor
				mtert = Left(mtert, mspace - 1)
			Endif
			Replace tert With mtert, cf With Iif(mcf <> "0 ", mcf, "")
			mexplicatie = Alltrim(Substr(C_TMP_I.detalii, At("Detalii: ", C_TMP_I.detalii) + 9, 100))
			mtextoriginal = C_TMP_I.data_final + Chr(13) + Alltrim(C_TMP_I.titular) + Chr(13) + Alltrim(C_TMP_I.Cont) + Chr(13) + Alltrim(C_TMP_I.detalii) + Chr(13) + Alltrim(C_TMP_I.referinta) + Chr(13) + Alltrim(C_TMP_I.debit) + " " + Alltrim(C_TMP_I.credit)
			Replace explicatie With mexplicatie, original With mtextoriginal, iban	With getibanfromstring(C_TMP_I.detalii, 1)
		Endscan
	Endproc
	*

	Procedure csvBCR2
		Lparameters pselectedfile
		Local mtextoriginal
		This.cIBAN = 'BCR'
		mtextoriginal = ""
		Create Cursor C_TMP_I (c1 C (4), c2 C (24), c3 C (24), data_v C (10), cod_valuta C (24), c6 C (10), c7 C (10), c8 C (24), c9 C (24), suma C (24), tip C (3), c12 C (24), c13 C (24), tert C (100), c15 C (24), c16 C (2), c17 C (4), c18 C (24), cf C (100), c20 C (100), detalii C (100), detalii2 C (60), detalii3 C (60), detalii4 C (100), detalii5 C (100), c26 C (2), c27 C (2), c28 C (24))
		Append From (mSelectedFile) Delimited With Char ";"
		Locate For !Empty(data_v)
		If Eof()
			Use In C_TMP_I
			Create Cursor C_TMP_I (c1 C (4), c2 C (24), c3 C (24), data_v C (10), cod_valuta C (24), c6 C (10), c7 C (10), c8 C (24), suma C (24), tip C (3), c12 C (24), c13 C (24), tert C (100), c15 C (24), c16 C (2), c17 C (4), c18 C (24), c18_1 C (24), c18_2 C (24), cf C (100), detalii C (100), detalii2 C (24), detalii3 C (60), detalii4 C (100), detalii5 C (100), c26 C (2), c27 C (2), c28 C (24))
			Append From (mSelectedFile) Delimited With Character,
		Endif
		Scan For !Empty(data_v)
			Select c_iex
			Insert Into c_iex (Data) Values (setdategerman(C_TMP_I.data_v))
			msuma = Thisform.setsuma(C_TMP_I.suma)
			If "-" $ C_TMP_I.suma
				Replace tip With "D"
			Else
				Replace tip With "C"
			Endif
			Replace suma With msuma
			Do Case
				Case "com" $ Lower(C_TMP_I.tip)
					Replace tip_2 With "COM"
				Otherwise
					Replace tip_2 With ""
			Endcase
			mexplicatie = Alltrim(C_TMP_I.detalii)
			mexplicatie = Strtran(mexplicatie, " ", " ")
			If "Detalii: " $ C_TMP_I.detalii
				mexplicatie = Substr(mexplicatie, At( "Detalii: ", mexplicatie) + 9, 100)
			Endif

			miban = getibanfromstring(Alltrim(C_TMP_I.detalii4) + C_TMP_I.detalii5, 1)
			If "CODFISC" $ C_TMP_I.detalii5
				mcf = getdigitsfromstring(Substr(C_TMP_I.detalii5, At("CODFISC", C_TMP_I.detalii5) + 8, 13), 4, 1, ".")
			Else
				mcf = ""
			Endif
			Replace tert With Upper(C_TMP_I.tert), cf With mcf, iban With miban
			mtextoriginal = C_TMP_I.data_v + " " + C_TMP_I.tip + " " + Chr(13) + Alltrim(C_TMP_I.suma) + " " + Chr(13) + Alltrim(C_TMP_I.tert) + " " + " " + Chr(13) + Alltrim(C_TMP_I.detalii) + Alltrim(C_TMP_I.detalii2) + Alltrim(C_TMP_I.detalii3) + Alltrim(C_TMP_I.detalii4) + Alltrim(C_TMP_I.detalii5)
			Replace explicatie With mexplicatie, original With mtextoriginal
		Endscan
	Endproc
	*

	Procedure csvBRD
		Lparameters pselectedfile
		Local mtextoriginal
		This.cIBAN = 'BRD'
		mtextoriginal = ""
		Create Cursor C_TMP_I (c1 C (4), c2 C (24), c3 C (24), data_v C (10), cod_valuta C (24), c6 C (10), c7 C (10), c8 C (24), c9 C (24), suma C (24), tip C (3), c12 C (24), c13 C (24), c14 C (100), c15 C (24), c16 C (2), c17 C (4), c18 C (24), tert C (100), cf C (100), detalii C (100), detalii2 C (100), detalii3 C (100), detalii4 C (100), c25 C (24), c26 C (2), c27	C (2), iban C (24))

		Append From (mSelectedFile) Delimited With Char ";"
		Locate For !Empty(data_v)
		If Eof()
			Use In C_TMP_I
			Create Cursor C_TMP_I (c1 C (4), c2 C (24), c3 C (24), data_v C (10), cod_valuta C (24), c6 C (10), c7 C (10), c8 C (24), suma C (24), tip C (3), c12 C (24), c13 C (24), c14 C (100), c15 C (24), c16 C (2), c17 C (4), c18 C (24), c18_1 C (24), c18_2 C (24), tert C (100), cf C (100), detalii C (100), detalii2 C (100), detalii3 C (100), detalii4 C (100), c25 C (24), c26 C (2), c27 C (2), iban C (24))
			Append From (mSelectedFile) Delimited With Character,
		Endif
		Scan For !Empty(data_v)
			Select c_iex
			Insert Into c_iex (Data) Values (setdategerman(C_TMP_I.data_v))
			msuma = This.setsuma(C_TMP_I.suma)
			If "-" $ C_TMP_I.suma
				Replace tip With "D"
			Else
				Replace tip With "C"
			Endif
			Replace suma With ABS(msuma)
			Do Case
				Case "com" $ Lower(C_TMP_I.tip)
					Replace tip_2 With "COM"
				Case ATC('TransCr-IncIntra',C_TMP_I.detalii) > 0
					Replace tip_2 With This.cTipTransfer
				Otherwise
					Replace tip_2 With ""
			Endcase
			mexplicatie = Alltrim(C_TMP_I.detalii)
			mexplicatie = Strtran(mexplicatie, " ", " ")
			If "Detalii: " $ C_TMP_I.detalii
				mexplicatie = Substr(mexplicatie, At( "Detalii: ", mexplicatie) + 9, 100)
			Endif
			Replace tert With ALLTRIM(STRTRAN(Upper(C_TMP_I.tert), 'Dl ','',1,1,1)), cf With getdigitsfromstring(C_TMP_I.cf, 4, 1, ".")
			mtextoriginal = C_TMP_I.data_v + " " + C_TMP_I.tip + " " + Chr(13) + Alltrim(C_TMP_I.suma) + " " + Chr(13) + Alltrim(C_TMP_I.tert) + " " + Chr(13) + Alltrim(C_TMP_I.c14) + " " + Chr(13) + Alltrim(C_TMP_I.cf) + " " + Chr(13) + Alltrim(C_TMP_I.detalii) + Alltrim(C_TMP_I.detalii2) + Alltrim(C_TMP_I.detalii3) + Alltrim(C_TMP_I.detalii4) + Chr(13) + Alltrim(C_TMP_I.iban)
			Replace explicatie With mexplicatie, original With mtextoriginal, iban With C_TMP_I.iban
		Endscan
	Endproc
	*
	Procedure csvBT
		Lparameters pselectedfile, tnTip
		* pcSelectedFile: fisierul csv
		* tnTip: 1 (default) = lista tranzactii, 2 = extras de cont
		
		Local mtextoriginal
		Local lcDescriereFacturi, lcFacturi, lcLinie, lnLinie, lnLinii, lnResults
		LOCAL mcf, mexplicatie, mfilestr, miban, mtert

		lnLinii = Alines(This.aLinii, Filetostr(m.pselectedfile), 1)
		FOR lnLinie = 1 TO lnLinii
			lcLinie = This.aLinii[m.lnLinie]
			lcItem = STRTRAN(LOWER(ALLTRIM(GETWORDNUM(m.lcLinie,1,','))), ["], [],1,2)
			IF m.lcItem = [numar cont:]
				This.cIBAN = STRTRAN(LEFT(ALLTRIM(syGETWORDNUM(m.lcLinie, 2, ',')), 24), ["], [], 1, 2)
				EXIT 
			ENDIF 
		ENDFOR 

		IF EMPTY(this.cIBAN)
			This.cIBAN = 'BT'
		ENDIF 	
		mtextoriginal = ""
		
		IF m.tnTip = 1 && lista de tranzactii
			* Data tranzactie,Data valuta,Descriere,Referinta tranzactiei,Debit,Credit,Sold contabil
			Create Cursor C_TMP_I (data_p C (16), data_t C (16), explicatie C (200), referinta C (200), suma_d C (15), suma_c C (15), sold C (15))
		ELSE
			* Data tranzactie,Data valuta,Referinta,Tip tranzactie,Descriere,Debit,Credit
			Create Cursor C_TMP_I (data_p C (16), data_t C (16), referinta C (200), tipt C (100), explicatie C (200), suma_d C (15), suma_c C (15))
		ENDIF 	
		mfilestr = Filetostr(pselectedfile)
		mfilestr = EliminVirguleDintreGhilimele(mfilestr, '"')
		mfilestr = Strtran(mfilestr, '"', '')
		
		* elimin LF din descriere in CSV BT24 se poate sa fie un LF pe linia cu tranzactia + ~~ pe urmatoarea linie
		mfilestr = Strtran(mfilestr, CHR(10) + '~~', '')

		* Reunesc liniile rupte: pastrez un \n doar daca e urmat de o data cu an complet (4 cifre) + virgula
		* Formate suportate: YYYY-MM-DD, / DD/MM/YYYY, / DD.MM.YYYY, / DD-MM-YYYY, / YYYY/MM/DD, / MM/DD/YYYY,
		mfilestr = Strtranx(mfilestr, "\r?\n(?!(?:\d{4}-\d{2}-\d{2}|\d{2}/\d{2}/\d{4}|\d{2}\.\d{2}\.\d{4}|\d{2}-\d{2}-\d{4}|\d{4}/\d{2}/\d{2}),)", " ", 1, , 1)

		* Este csv exportat din BT24 sau NeoBT. BT24 are sume negative???? pe debit pentru plati
		llBT24 = 'sold contabil'$LOWER(mfilestr)
				
		Strtofile(mfilestr, m.gcTempPath + "BTTMP.csv")
		Append From (m.gcTempPath + "BTTMP.csv") Csv

		Scan For !Empty(data_t) .And. !Empty(setdategerman(C_TMP_I.data_t))
			Select c_iex
			Insert Into c_iex (Data) Values (setdategerman(Alltrim(C_TMP_I.data_t)))
			If !EMPTY(VAL(Alltrim(C_TMP_I.suma_d)))
				Replace tip With "D"
				Replace suma With This.setsuma(C_TMP_I.suma_d)

				* Doar pentru export CSV BT24, platile (Debit) au suma negativa
				* Le inlocuiesc cu suma inversa
				IF m.llBT24
					REPLACE suma WITH -suma
				ENDIF 
			Else
				Replace tip With "C"
				Replace suma With This.setsuma(C_TMP_I.suma_c)
			ENDIF
			* Incasare OP;/ROC/FC. 2022047/ 04.02.2022//RFB/4337692;;;;DRAFT DINAMIC CONSTRUCT SRL;RO43OTPV120001427418RO01;OTPVROBU
			* NEOBT
			* "30-05-2024","30-05-2024","Incasare OP - canal electronic;f 2024103;ARGENTA SRL;RO86BTRL01401202H76370XX;BTRLRO22;REF: 014ZEXA24151017X","014ZEXA24151017X","","1,184.24 ","2,184.24 "
			
			* BT24
			* 2024-06-05,2024-06-05,"Incasare OP - canal electronic;F 2024131;MIDIA GREEN ENERGY SA;RO87BTRL01401202716668XX;BTRLRO22;REF: 414ZEXA2415702DU",414ZEXA2415702DU,,"797.30","12,013.14"
			IF m.tnTip = 1 && lista de tranzactii
				mexplicatie = Alltrim(C_TMP_I.explicatie)
			ELSE
				mexplicatie = Alltrim(C_TMP_I.tipt) + ';' + Alltrim(C_TMP_I.explicatie)
			ENDIF 	
			Do Case
				Case LEFT(ALLTRIM(LOWER(NVL(mexplicatie,''))), 8) = "comision" OR ;
					'comision-atm'$LOWER(NVL(mexplicatie,'')) OR ;
					'comision procesare ridicare numerar'$LOWER(NVL(mexplicatie,'')) OR ;
					'pachet izi'$LOWER(NVL(mexplicatie,''))
					Replace tip_2 With This.cTipComisioane
					
				Case 'retragere de numerar'$ALLTRIM(LOWER(NVL(mexplicatie,'')))
					Replace tip_2 With This.cTipDepunere					
				Case 'transfer intern'$ALLTRIM(LOWER(NVL(mexplicatie,'')))
					Replace tip_2 With This.cTipTransfer
					
				Otherwise
					Replace tip_2 With ""
			Endcase
			mtert = ALLTRIM(syGETWORDNUM(m.mexplicatie, 3, ';'))
			miban = ALLTRIM(syGETWORDNUM(m.mexplicatie, 4, ';'))
			mcf = ""
			
			lcDescriereFacturi = ALLTRIM(syGETWORDNUM(m.mexplicatie, 2, ';'))
			lcFacturi = ''
			lnResults = GetRegExpAllNumbers(m.lcDescriereFacturi, @m.lcFacturi)
			
			Replace tert With mtert, iban With miban, cf With mcf, documente WITH m.lcFacturi
			mtextoriginal = C_TMP_I.data_t + " " + Chr(13) + Alltrim(C_TMP_I.suma_d) + "," + Alltrim(C_TMP_I.suma_c) + " " + Chr(13) + Alltrim(mexplicatie)
			Replace explicatie With mexplicatie, original With mtextoriginal
		Endscan
	ENDPROC && csvBT
	*
	Procedure csvBT_original
		Lparameters pselectedfile
		Local mtextoriginal, misgilimele
		This.cIBAN = 'BT'
		mtextoriginal = ""
		misgilimele = .F.
		mfilestr = Filetostr(pselectedfile)
		Strtofile(mfilestr, m.gcTempPath + "BTTMP.csv")
		lnfilehandle = Fopen(pselectedfile)
		Do While !Feof(lnfilehandle)
			mrand = Fgets(lnfilehandle, 1024)
			If '""' $ mrand
				misgilimele = .T.
				If ';",' $ mrand
					mpozatm1 = At( ';",', mrand) + 1
					mrandfinal = Substr(mrand, mpozatm1, 200)
					mpozvirgulaatm = At( ',', mrandfinal, 2)
					mrand = Left(mrand, mpozatm1) + '",,""' + Substr(mrand, mpozatm1 + mpozvirgulaatm, 50)
				Endif
				mrand = Strtran(mrand, '""";;;;', '""')
				mrand = Strtran(mrand, '""";;;', '""')
				mrand = Strtran(mrand, '""";;', '""')
				mrand = Strtran(mrand, '""";', '""')
				mrand = Strtran(mrand, '""', '^')
				mrand = Strtran(mrand, '"', '')
				mrand = Strtran(mrand, '^', '"')
			Endif
			If Substr(mrand, 3, 1) == '-' .Or. Substr(mrand, 3, 1) == '/' .Or. Substr(mrand, 3, 1) == '.' .Or. Left(mrand, 2) == '20' .Or. Left(mrand, 2) == '21'
				mldata = setdategerman(Left(mrand, At(',', mrand)))
				mrand1 = Alltrim(Substr(mrand, At(',', mrand, 2) + 1, 1000))
				mrand1 = EliminVirguleDintreGhilimele(mrand1, '"')
				mnrpctvirg = Occurs(';', mrand1)
				mpozfinexpl1 = At(';', mrand1)
				Do Case
					Case mnrpctvirg = 0
						mpozfinexpl1 = At(',', mrand1, 1)
						mpozfinexpl2 = mpozfinexpl1
						mpozfinexpl3 = mpozfinexpl1
						mpozfinexpl4 = mpozfinexpl1
						mpozfinexpl5 = mpozfinexpl1
						mpozfinexpl6 = mpozfinexpl5
					Case mnrpctvirg = 1
						mpozfinexpl2 = At(';', mrand1, 1)
						mpozfinexpl3 = At(';', mrand1, 1)
						mpozfinexpl4 = At(';', mrand1, 1)
						mpozfinexpl5 = At(';', mrand1, 1)
						mpozfinexpl6 = mpozfinexpl5
					Case mnrpctvirg = 2
						mpozfinexpl2 = At(';', mrand1, 2)
						mpozfinexpl3 = At(';', mrand1, 2)
						mpozfinexpl4 = At(';', mrand1, 2)
						mpozfinexpl5 = At(';', mrand1, 2)
						mpozfinexpl6 = mpozfinexpl5
					Case mnrpctvirg = 3
						mpozfinexpl2 = At(';', mrand1, 2)
						mpozfinexpl3 = At(';', mrand1, 2)
						mpozfinexpl4 = At(';', mrand1, 2)
						mpozfinexpl5 = At(';', mrand1, 3)
						mpozfinexpl6 = mpozfinexpl5
					Case mnrpctvirg = 4
						mpozfinexpl2 = At(';', mrand1, 2)
						mpozfinexpl3 = At(';', mrand1, 2)
						mpozfinexpl4 = At(';', mrand1, 3)
						mpozfinexpl5 = At(';', mrand1, 4)
						mpozfinexpl6 = mpozfinexpl5
					Otherwise
						mpozfinexpl2 = At(';', mrand1, 2)
						mpozfinexpl3 = At(';', mrand1, 3)
						mpozfinexpl4 = At(';', mrand1, 4)
						mpozfinexpl5 = At(';', mrand1, 5)
						mpozfinexpl6 = At(';', mrand1, 6)
				Endcase
				mlexplicatie1 = Substr(mrand1, 1, mpozfinexpl1 - 1)
				mlexplicatie2 = Substr(mrand1, mpozfinexpl1 + 1, mpozfinexpl2 - mpozfinexpl1 - 1)
				mpoz3 = Substr(mrand1, mpozfinexpl3 + 1, mpozfinexpl4 - mpozfinexpl3 - 1)
				mpoz4 = Substr(mrand1, mpozfinexpl4 + 1, mpozfinexpl5 - mpozfinexpl4 - 1)
				mpoz5 = Substr(mrand1, mpozfinexpl5 + 1, mpozfinexpl6 - mpozfinexpl5 - 1)
				If (mpoz5 = "RO" .Or. misgilimele) .And. mpoz4 <> "RO" .And. mnrpctvirg <> 5
					mltert = mpoz4
					mlcont = mpoz5
				Else
					mltert = mpoz3
					mlcont = mpoz4
				Endif
				mrand2 = Substr(mrand1, At(',', mrand1, 2) + 1, 1000)
				mpozvirgulaexpl4 = At( ',', mrand2, 2)
				If mrand2 = ","
					mlsumad = ""
					mlsumac = Strtran(Strtran(Substr(mrand2, 2, mpozvirgulaexpl4 - 2), '"', ''), ',', '')
				Else
					mlsumad = Strtran(Strtran(Substr(mrand2, 1, mpozvirgulaexpl4 - 1), '"', ''), ',', '')
					mlsumac = ""
				Endif
				If mldata >= Ctod("01.01.2015")
					Insert Into c_iex (Data) Values (mldata)
					If Val(mlsumad) <> 0
						mltip = "D"
						mlsuma = Abs(Val(mlsumad))
					Else
						mltip = "C"
						mlsuma = Abs(Val(mlsumac))
					Endif
					If "Comision " $ mrand2 .Or. "Comision " $ mlexplicatie1
						Replace tip_2 With "COM" In c_iex
					Endif
					If mltip = "D"
						Replace tip With mltip, ip With "I", suma With mlsuma In c_iex
					Else
						Replace tip With mltip, ip With "P", suma With mlsuma In c_iex
					Endif
					Replace tert With Upper(mltert), explicatie With Iif(Empty(mlexplicatie2), mlexplicatie1, mlexplicatie2), ;
						iban With mlcont, original With mrand1 In c_iex
				Endif
			Endif
		Enddo
		Fclose(lnfilehandle)
	Endproc
	*

	Procedure csvCEC
		Lparameters pselectedfile
		Local mtextoriginal
		This.cIBAN = 'CEC'
		mtextoriginal = ""
		Create Cursor C_TMP_I (c1 C (10), c2 C (10), c3 C (10), d1 C (10), moneda C (3), s1 C (10), s2 C (10), data_t C (10), data_v C (10), suma C (15), tip_op C (100), nr C (16), c4 C (10), c5 C (10), c6 C (10), c7 C (10), c8 C (10), c9 C (10), c10 C (10), c11 C (10), explicatie1 C (200), explicatie2 C (200), explicatie3 C (200), explicatie4 C (200), explicatie5 C (200))
		mfilestr = Filetostr(pselectedfile)
		mfilestr = Strtran(mfilestr, '"', '')
		Strtofile(mfilestr, m.gcTempPath + "CECTMP.csv")
		Select C_TMP_I
		Append From (m.gcTempPath + "CECTMP.csv") Delimited With Char ";"

		Delete For Empty(Ctod(C_TMP_I.data_t))
		Scan For !Empty(data_t) .And. !Empty(setdategerman(C_TMP_I.data_t))
			Select c_iex
			Insert Into c_iex (Data) Values (setdategerman(C_TMP_I.data_t))
			If "-" $ C_TMP_I.suma
				Replace tip With "D"
			Else
				Replace tip With "C"
			Endif
			Replace suma With This.setsuma(C_TMP_I.suma)
			mexplicatie = Alltrim(C_TMP_I.explicatie1) + Alltrim(C_TMP_I.explicatie2) + Alltrim(C_TMP_I.explicatie3) + Alltrim(C_TMP_I.explicatie4) + Alltrim(C_TMP_I.explicatie5)
			Do Case
				Case "comision" $ Lower(mexplicatie) .Or. "Abonament Internet Banking" $ mexplicatie
					Replace tip_2 With "COM"
				Otherwise
					Replace tip_2 With ""
			Endcase
			mtert = ""


			miban = ""

			mcf = ""
			mpoziban = 0
			mlenexpl = 0
			If "Iban Platitor" $ mexplicatie
				mpoziban = At( "Iban Platitor", mexplicatie)
				mlenexpl = Len( "Iban Platitor" ) + 1
				miban = Substr(mexplicatie, mpoziban + mlenexpl, 24)
			Endif
			If "Iban Beneficiar" $ mexplicatie
				mpoziban = At( "Iban Beneficiar", mexplicatie)
				mlenexpl = Len( "Iban Beneficiar" ) + 1
				miban = Substr(mexplicatie, mpoziban + mlenexpl, 24)
			Endif
			If mpoziban <> 0
				mexplicatie2 = Substr(mexplicatie, 1, mpoziban - 1) + Substr(mexplicatie, mpoziban + mlenexpl + 1, 300)
			Else
				mexplicatie2 = mexplicatie
			Endif
			If tip = "C"
				If "Platitor " $ mexplicatie2
					mtert1 = Alltrim(Substr(mexplicatie2, At( "Platitor ", mexplicatie2) + 9, 100))
					If "," $ mtert1
						mtert = Left(mtert1, At( ",", mtert1) - 1)
					Else
						mtert = mtert1
					Endif
				Endif
				If "CUI/CNP Platitor" $ mexplicatie2
					mcf = Alltrim(Str(Val(Alltrim(Substr(mexplicatie2, At( "CUI/CNP Platitor", mexplicatie2) + 17, 13))), 13, 0))
				Endif
			Else
				If "Beneficiar " $ mexplicatie2
					mtert1 = Alltrim(Substr(mexplicatie2, At( "Beneficiar ", mexplicatie2) + 11, 100))
					If "," $ mtert1
						mtert = Left(mtert1, At( ",", mtert1) - 1)
					Else
						mtert = mtert1
					Endif
				Endif
				If "CUI/CNP Beneficiar" $ mexplicatie2
					mcf = Alltrim(Str(Val(Alltrim(Substr(mexplicatie2, At( "CUI/CNP Beneficiar", mexplicatie2) + 19, 13))), 13, 0))
				Endif
			Endif
			mcf1 = getdigitsfromstring(mcf, 4, 1, ".")
			If Empty(mcf1)
				mcf1 = getdigitsfromstring(mcf, 13, 2, ".")
			Endif
			Replace tert With mtert, iban With miban, cf With mcf1, nr With C_TMP_I.nr
			mtextoriginal = C_TMP_I.data_t + " " + Chr(13) + C_TMP_I.suma + " " + Chr(13) + Alltrim(C_TMP_I.nr) + " " + Chr(13) + Alltrim(mexplicatie)
			If Occurs(",", mexplicatie) > 0
				mexplicatie = Left(mexplicatie, At(",", mexplicatie) - 1)
			Endif
			Replace explicatie With mexplicatie, original With mtextoriginal
		Endscan
	Endproc
	*

	Procedure csvCreditEurope
		Lparameters pselectedfile
		Local mtextoriginal

		lnLinii = Alines(This.aLinii, Filetostr(m.pselectedfile), 1)
		lcLinie = This.aLinii[2]
		This.cIBAN = syGETWORDNUM(m.lcLinie, 5, ',')
		IF EMPTY(this.cIBAN)
			This.cIBAN = 'CreditEurope'
		ENDIF 	
		mtextoriginal = ""
		Create Cursor C_TMP_I (data_t C (16), data_v C (16), referinta C (20), explicatie C (200), suma_d C (15), suma_c C (15), sold C (15))
		mfilestr = Filetostr(pselectedfile)
		mfilestr = EliminVirguleDintreGhilimele(mfilestr, '"')
		mfilestr = Strtran(mfilestr, '"', '')
		Strtofile(mfilestr, m.gcTempPath + "CreditEuropeTMP.csv")
		Append From (m.gcTempPath + "CreditEuropeTMP.csv") Csv
		Scan For !Empty(data_t) .And. !Empty(setdategerman(C_TMP_I.data_t))
			Select c_iex
			Insert Into c_iex (Data) Values (setdategerman(Alltrim(C_TMP_I.data_t)))
			If !EMPTY(VAL(Alltrim(C_TMP_I.suma_d)))
				Replace tip With "D"
				Replace suma With This.setsuma(C_TMP_I.suma_d)
			Else
				Replace tip With "C"
				Replace suma With This.setsuma(C_TMP_I.suma_c)
			Endif
			mexplicatie = Alltrim(C_TMP_I.explicatie)
			Do Case
				Case "comision" $ Lower(mexplicatie)
					Replace tip_2 With "COM"
				Otherwise
					Replace tip_2 With ""
			Endcase
			mtert = ""


			miban = ""

			mcf = ""
			mpoztertstart = At(" - ", mexplicatie) + 3
			mpoztertfin = At(" : ", mexplicatie)
			If mpoztertstart > 0 .And. mpoztertfin > 0
				mtert = Alltrim(Substr(mexplicatie, mpoztertstart, mpoztertfin - mpoztertstart))
			Endif
			Replace tert With mtert, iban With miban, cf With mcf
			mtextoriginal = C_TMP_I.data_t + " " + Chr(13) + Alltrim(C_TMP_I.suma_d) + "," + Alltrim(C_TMP_I.suma_c) + " " + Chr(13) + Alltrim(mexplicatie)
			Replace explicatie With mexplicatie, original With mtextoriginal
		Endscan
	Endproc
	*
	Procedure csvFanCourier
		Lparameters pselectedfile
		Local mtextoriginal
		This.cIBAN = 'FanCourier'
		*:Global mfilestr
		mtextoriginal = ""
		Create Cursor C_TMP_I (oras C (60), data_awb C (10), suma C (15), nr_awb C (60), expeditor C (60), tert C (100), continut C (60), pc C (60), data_t C (10), card C (20), pe C (60), ramburs C (20), Retur C (20), data_v C (10))
		mfilestr = Filetostr(pselectedfile)
		mfilestr = Strtran(mfilestr, '""""', '')
		mfilestr = Strtran(mfilestr, '"""', '""')
		If Occurs('""', Left(mfilestr, At(Chr(13), mfilestr))) >= 4
			mfilestr = EliminVirguleDintreGhilimele(mfilestr, '""')
		Else
			mfilestr = EliminVirguleDintreGhilimele(mfilestr, '"')
		Endif
		mfilestr = Strtran(mfilestr, '"', '')
		Strtofile(mfilestr, m.gcTempPath + "FANTMP.csv")
		Select C_TMP_I
		Append From (m.gcTempPath + "FANTMP.csv") Csv
		Delete For Empty(Ctod(C_TMP_I.data_t))
		Scan For .Not. Empty(data_t) .And. .Not. Empty(setdategerman(C_TMP_I.data_t))
			Select c_iex
			Insert Into c_iex (Data) Values (setdategerman(C_TMP_I.data_t))
			Replace tip With "C", suma With This.setsuma(C_TMP_I.suma), tert With Upper(C_TMP_I.tert)
			
			mcf = getdigitsfromstring(Alltrim(C_TMP_I.tert), 4, 1, ".")
			If !EMPTY(Alltrim(mcf))
				REPLACE cf WITH mcf
			Endif
						
			mtextoriginal = Alltrim(C_TMP_I.data_t) + " " + Chr(13) + Alltrim(C_TMP_I.suma) + Chr(13) + Alltrim(C_TMP_I.oras) + " " + "AWB " + Alltrim(C_TMP_I.nr_awb) + " " + Alltrim(C_TMP_I.continut) + Chr(13) + Alltrim(C_TMP_I.tert) + Chr(13) + Alltrim(C_TMP_I.pe) + " " + "AWB " + Alltrim(C_TMP_I.ramburs) + " " + Alltrim(C_TMP_I.Retur) + " " + Alltrim(C_TMP_I.card)
			Replace explicatie With C_TMP_I.tert, original With mtextoriginal
		Endscan
	Endproc
	*

	*
	Procedure csvFunCourier
		Lparameters pselectedfile
		Local mtextoriginal
		This.cIBAN = 'FanCourier'
		*:Global mfilestr
		mtextoriginal = ""
		Create Cursor C_TMP_I (oras C (60), data_awb C (10), suma C (15), nr_awb C (60), expeditor C (60), tert C (100), continut C (60), pc C (60), data_t C (10), pe C (60), ramburs C (20), Retur C (20), card C (20))
		mfilestr = Filetostr(pselectedfile)
		mfilestr = Strtran(mfilestr, '""""', '')
		mfilestr = Strtran(mfilestr, '"""', '""')
		If Occurs('""', Left(mfilestr, At(Chr(13), mfilestr))) >= 4
			mfilestr = EliminVirguleDintreGhilimele(mfilestr, '""')
		Else
			mfilestr = EliminVirguleDintreGhilimele(mfilestr, '"')
		Endif
		mfilestr = Strtran(mfilestr, '"', '')
		Strtofile(mfilestr, m.gcTempPath + "FUNTMP.csv")
		Select C_TMP_I
		Append From (m.gcTempPath + "FUNTMP.csv") Csv
		Delete For Empty(Ctod(C_TMP_I.data_t))
		Scan For .Not. Empty(data_t) .And. .Not. Empty(setdategerman(C_TMP_I.data_t))
			Select c_iex
			Insert Into c_iex (Data) Values (setdategerman(C_TMP_I.data_t))
			Replace tip With "C", suma With This.setsuma(C_TMP_I.suma), tert With Upper(C_TMP_I.tert)
			mtextoriginal = Alltrim(C_TMP_I.data_t) + " " + Chr(13) + Alltrim(C_TMP_I.suma) + Chr(13) + Alltrim(C_TMP_I.oras) + " " + "AWB " + Alltrim(C_TMP_I.nr_awb) + " " + Alltrim(C_TMP_I.continut) + Chr(13) + Alltrim(C_TMP_I.tert) + Chr(13) + Alltrim(C_TMP_I.pe) + " " + "AWB " + Alltrim(C_TMP_I.ramburs) + " " + Alltrim(C_TMP_I.Retur) + " " + Alltrim(C_TMP_I.card)
			Replace explicatie With C_TMP_I.tert, original With mtextoriginal
		Endscan
	Endproc
	*
	Procedure csvFunCourier2
		Lparameters pselectedfile
		Local mtextoriginal
		This.cIBAN = 'FanCourier'
		mtextoriginal = ""
		Create Cursor C_TMP_I (nr_awb C (60), data_awb C (10), tert C (100), oras C (60), expeditor C (60), oras_exp C (60), suma C (15), iban C (24), data_t C (10), continut C (60))
		mfilestr = Filetostr(pselectedfile)
		mfilestr = Strtran(mfilestr, '""""', '')
		mfilestr = Strtran(mfilestr, '"""', '""')
		If Occurs('""', Left(mfilestr, At(Chr(13), mfilestr))) >= 4
			mfilestr = EliminVirguleDintreGhilimele(mfilestr, '""')
		Else
			mfilestr = EliminVirguleDintreGhilimele(mfilestr, '"')
		Endif
		mfilestr = Strtran(mfilestr, '"', '')
		Strtofile(mfilestr, m.gcTempPath + "FUNTMP.csv")
		Select C_TMP_I
		Append From (m.gcTempPath + "FUNTMP.csv") Csv
		Delete For Empty(Ctod(C_TMP_I.data_t))
		Scan For !Empty(data_t) .And. !Empty(setdategerman(C_TMP_I.data_t))
			Select c_iex
			Insert Into c_iex (Data) Values (setdategerman(C_TMP_I.data_t))
			Replace tip With "C", suma With This.setsuma(C_TMP_I.suma), tert With Upper(C_TMP_I.tert)
			mtextoriginal = Alltrim(C_TMP_I.data_t) + " " + Chr(13) + Alltrim(C_TMP_I.suma) + Chr(13) + Alltrim(C_TMP_I.oras) + " " + "AWB " + Alltrim(C_TMP_I.nr_awb) + " " + Alltrim(C_TMP_I.continut) + Chr(13) + Alltrim(C_TMP_I.tert)
			Replace explicatie With C_TMP_I.tert, original With mtextoriginal
		Endscan
	Endproc
	*

	Procedure csvGaranti
		Lparameters pselectedfile
		Local mtextoriginal
		This.cIBAN = 'Garanti'
		mtextoriginal = ""
		Create Cursor C_TMP_I (data_t C (16), explicatie C (200), suma C (15), sold C (15))
		Append From (pselectedfile) Delimited With Char ";"
		Scan For !Empty(data_t) .And. !Empty(setdategerman(C_TMP_I.data_t))
			Select c_iex
			Insert Into c_iex (Data) Values (setdategerman(Alltrim(C_TMP_I.data_t)))
			If "-" $ C_TMP_I.suma
				Replace tip With "D"
			Else
				Replace tip With "C"
			Endif
			Replace suma With ABS(This.setsuma(C_TMP_I.suma))
			mexplicatie = STRTRAN(Alltrim(C_TMP_I.explicatie), '  ', ' ',1,100,1) && elimin spatiile duble
			mexplicatie = STRTRAN(Alltrim(mexplicatie ), '  ', ' ',1,100,1) && elimin spatiile duble
			mexplicatie = STRTRAN(Alltrim(mexplicatie ), '  ', ' ',1,100,1) && elimin spatiile duble
			mexplicatie = STRTRAN(Alltrim(mexplicatie ), '  ', ' ',1,100,1) && elimin spatiile duble
			mexplicatie = STRTRAN(Alltrim(mexplicatie ), '  ', ' ',1,100,1) && elimin spatiile duble						
						
			Do Case
				Case "comision" $ Lower(mexplicatie)
					lcTip2 = This.cTipComisioane
				Case "dobanda" $ Lower(mexplicatie)
					lcTip2 = This.cTipDobanzi	
				Case "lichidare depozit" $ Lower(mexplicatie)
					lcTip2 = This.cTipTransfer
				Case "constituire depozit" $ Lower(mexplicatie)
					lcTip2 = This.cTipTransfer
				Otherwise
					lcTip2 = ""
			Endcase
			mtert = ""


			miban = ""

			mcf = ""
			mpoziban = 0
			mlenexpl = 0
			If "IBAN platitor:" $ mexplicatie
				mpoziban = At( "IBAN platitor:", mexplicatie)
				mlenexpl = Len( "IBAN platitor:" ) + 1
				miban = Substr(mexplicatie, mpoziban + mlenexpl, 24)
			Endif
			If "IBAN beneficiar:" $ mexplicatie
				mpoziban = At( "IBAN beneficiar:", mexplicatie)
				mlenexpl = Len( "IBAN beneficiar:" ) + 1
				miban = Substr(mexplicatie, mpoziban + mlenexpl, 24)
			Endif
			If mpoziban <> 0
				mexplicatie2 = Substr(mexplicatie, 1, mpoziban - 1)
			Else
				mexplicatie2 = mexplicatie
			Endif
			If tip = "C"
				mpoztertstart = At( "Platitor: ", mexplicatie2) + 10
				If "Platitor: " $ mexplicatie2
					If mpoziban > mpoztertstart
						mtert1 = Alltrim(Substr(mexplicatie2, mpoztertstart, mpoziban - mpoztertstart))
					Else
						mtert1 = Alltrim(Substr(mexplicatie2, mpoztertstart, 100))
					Endif
					If "," $ mtert1
						mtert = Left(mtert1, At( ",", mtert1) - 1)
					Else
						mtert = mtert1
					Endif
				Endif
			Else
				mpoztertstart = At( "Beneficiar: ", mexplicatie2) + 12
				If "Beneficiar: " $ mexplicatie2
					If mpoziban > mpoztertstart
						mtert1 = Alltrim(Substr(mexplicatie2, mpoztertstart, mpoziban - mpoztertstart))
					Else
						mtert1 = Alltrim(Substr(mexplicatie2, mpoztertstart, 100))
					Endif
					If "," $ mtert1
						mtert = Left(mtert1, At( ",", mtert1) - 1)
					Else
						mtert = mtert1
					Endif
				Endif
			Endif
			If "Cod fiscal:" $ mexplicatie
				mcf = getdigitsfromstring(Alltrim(Substr(mexplicatie, At("Cod fiscal:", mexplicatie) + 12, 13)), 4, 1, ".")
				If Alltrim(mcf) == Alltrim(gofirma.codfiscalfro)
					mcf = ""
				Endif
			Endif
			Replace tert With mtert, iban With miban, cf With mcf, tip_2 With m.lcTip2
			
			mtextoriginal = C_TMP_I.data_t + " " + Chr(13) + C_TMP_I.suma + " " + Chr(13) + Alltrim(mexplicatie)
			If Occurs("Detalii:", mexplicatie) > 0
				mexplicatie = Substr(mexplicatie, At("Detalii:", mexplicatie) + 8, 200)
			Endif
			Replace explicatie With mexplicatie, original With mtextoriginal
		Endscan
	Endproc
	*

	Procedure csvGaranti_2
		Lparameters pselectedfile
		Local mtextoriginal
		This.cIBAN = 'Garanti'
		mtextoriginal = ""
		Create Cursor C_TMP_I (data_t C (16), data_v C (16), tert C (60), iban C (36),	explicatie C (200), suma C (15), sold C (15))

		Append From (pselectedfile) Csv
		Scan For !Empty(data_t) .And. !Empty(setdategerman(C_TMP_I.data_t))
			Select c_iex
			Insert Into c_iex (Data) Values (setdategerman(Alltrim(C_TMP_I.data_t)))
			If "-" $ C_TMP_I.suma
				Replace tip With "D"
			Else
				Replace tip With "C"
			Endif
			Replace suma With ABS(This.setsuma(C_TMP_I.suma))
			mexplicatie = Alltrim(C_TMP_I.explicatie)
			Do Case
				Case "comision" $ Lower(mexplicatie)
					lcTip2 = This.cTipComisioane
				Case "dobanda" $ Lower(mexplicatie)
					lcTip2 = This.cTipDobanzi	
				Case "lichidare depozit" $ Lower(mexplicatie)
					lcTip2 = This.cTipTransfer
				Case "constituire depozit" $ Lower(mexplicatie)
					lcTip2 = This.cTipTransfer
				Otherwise
					lcTip2 = ""
			Endcase
			mtert = Alltrim(C_TMP_I.tert)
			miban = Alltrim(C_TMP_I.iban)
			Replace tert With mtert, iban With miban, tip_2 WITH m.lcTip2
			
			mtextoriginal = C_TMP_I.data_t + " " + Chr(13) + mtert + " " + Chr(13) + miban + " " + Chr(13) + C_TMP_I.suma + " " + Chr(13) + Alltrim(mexplicatie)
			If Occurs("Detalii:", mexplicatie) > 0
				mexplicatie = Substr(mexplicatie, At("Detalii:", mexplicatie) + 8, 200)
			Endif
			Replace explicatie With mexplicatie, original With mtextoriginal
		Endscan
	Endproc
	*

	Procedure csvIdea
		Lparameters pselectedfile
		Local mtextoriginal
		This.cIBAN = 'Idea'
		mtextoriginal = ""
		Create Cursor C_TMP_I (data_t C (10), data_v C (10), referinta C (10), explicatie C (150), tert C (100), suma C (15))
		Append From (pselectedfile) Csv
		Scan For !Empty(data_t) .And. !Empty(setdategerman(C_TMP_I.data_t))
			Select c_iex
			Insert Into c_iex (Data) Values (setdategerman(C_TMP_I.data_t))
			If "-" $ C_TMP_I.suma
				Replace tip With "D"
			Else
				Replace tip With "C"
			Endif
			Replace suma With This.setsuma(Strtran(Strtran(C_TMP_I.suma, "+", ""), "-", ""))
			Do Case
				Case "comis" $ Lower(C_TMP_I.explicatie) .Or. "administrare cont" $ Lower(C_TMP_I.explicatie)
					Replace tip_2 With "COM"
				Otherwise
					Replace tip_2 With ""
			Endcase
			mexplicatie = C_TMP_I.explicatie
			mtert = ""


			miban = ""

			If Occurs(":", C_TMP_I.tert) > 0
				mtert = Upper(Substr(C_TMP_I.tert, At(":", C_TMP_I.tert) + 2, 100))
			Else
				mtert = Upper(C_TMP_I.tert)
			Endif
			Replace tert With mtert
			mtextoriginal = C_TMP_I.data_t + " " + Chr(13) + C_TMP_I.suma + " " + Chr(13) + C_TMP_I.referinta + " " + Chr(13) + Alltrim(C_TMP_I.explicatie) + " " + Chr(13) + Alltrim(C_TMP_I.tert)
			Replace explicatie With mexplicatie, original With mtextoriginal
		Endscan
	Endproc
	*

	Procedure csvIng
		Lparameters pselectedfile, pltipfisier
		Local mtextoriginal
		This.cIBAN = 'ING'
		mtextoriginal = ""
		If pltipfisier = 1
			Create Cursor C_TMP_I (text1 C (200), field1 C (10), detalii2 C (200), detalii C (200), debit C (15), field3 C (100), credit C (15), credit2 C (15))
		Else
			Create Cursor C_TMP_I (text1 C (200), field1 C (10), detalii2 C (200), detalii C (200), field4 C (10), debit C (15), field3 C (100), credit C (15), credit2 C (15))
		Endif
		Append From (pselectedfile) Csv
		Replace detalii With detalii2 For Empty(detalii)
		Replace credit With credit2 For Empty(credit)
		Locate
		Select C_TMP_I
		Do While !Eof()
			Select C_TMP_I
			If !Empty(text1)
				mtextoriginal = Alltrim(text1)
				If '""' $ text1
					mldatatext = Left(text1, At( ",", text1) - 1)
				Else
					mldatatext = Alltrim(text1)
				Endif
				mldata = setdategerman(mldatatext)
				If mldata >= Ctod("01.01.2015")
					Insert Into c_iex (Data) Values (mldata)
					Select C_TMP_I
					If '""' $ text1
						mloccurence3 = At(",", text1, 3)
						mloccurence4 = At(",", text1, 4)
						mlexplicatie1 = Substr(text1, mloccurence3 + 1, mloccurence4 - mloccurence3)
						mloccurence5 = At(',', text1, 5)
						mlsumadc = Substr(text1, mloccurence5 + 1, 100)
						mloccurence1 = At('""', text1, 1)
						mloccurence2 = At('""', text1, 2)
						mlsuma = Val(Strtran(Strtran(Substr(text1, mloccurence1 + 2, mloccurence2 - mloccurence1 - 2), ".", ""), ",", "."))
						If mlsumadc = '""'
							mltip = "D"
						Else
							mltip = "C"
						Endif
						If "comisio" $ Lower(text1)
							Replace tip_2 With "COM" In c_iex
						Endif
					Else
						mtextoriginal = mtextoriginal + Chr(13) + Alltrim(debit) + " " + Alltrim(field3) + " " + Alltrim(credit)
						mdebit = Thisform.setsuma(debit) + Thisform.setsuma(field3)
						If mdebit > 0
							mltip = "D"
							mlsuma = mdebit
						Else
							mltip = "C"
							mlsuma = Thisform.setsuma(credit)
						Endif
						If "comisio" $ Lower(detalii)
							Replace tip_2 With "COM" In c_iex
						Endif
					Endif
					mltert = ""
					mlcont = ""
					mlexplicatie2 = ""
					Skip
					If mltip = "D"
						Replace tip With mltip, ip With "I", suma With mlsuma In c_iex
						Do While Empty(text1) .And. !Eof()
							mtextoriginal = mtextoriginal + Chr(13) + Alltrim(detalii)
							If "Detalii:" $ detalii
								mlexplicatie2 = Alltrim(Strtran(detalii, "Detalii:", ""))
							Endif
							If "Terminal:" $ detalii
								mltert = Alltrim(Strtran(detalii, "Terminal:", ""))
							Endif
							If "Beneficiar:" $ detalii
								mltert = Alltrim(Strtran(detalii, "Beneficiar:", ""))
							Endif
							If "In contul:" $ detalii
								mlcont = Alltrim(Strtran(detalii, "In contul:", ""))
							Endif
							Skip
						Enddo
					Else
						Replace tip With mltip, ip With "P", suma With mlsuma In c_iex
						Do While Empty(text1) .And. !Eof()
							mtextoriginal = mtextoriginal + Chr(13) + Alltrim(detalii)
							If "Detalii:" $ detalii
								mlexplicatie2 = Alltrim(Strtran(detalii, "Detalii:", ""))
							Endif
							If "Ordonator:" $ detalii
								mltert = Alltrim(Strtran(detalii, "Ordonator:", ""))
							Endif
							If "Din contul:" $ detalii
								mlcont = Alltrim(Strtran(detalii, "Din contul:", ""))
							Endif
							Skip
						Enddo
					Endif
					Replace tert With Upper(mltert), explicatie With mlexplicatie2,	iban With mlcont, original With mtextoriginal In c_iex
					Loop
				Else
					Skip
				Endif
			Else
				Skip
			Endif
		Enddo
	Endproc
	*

	Procedure csvIngbusiness
		Lparameters pselectedfile, pldelimitator, tnTipFisier
		Local mtextoriginal, mdataop, lcTipTransfer
		This.cIBAN = 'INGBussiness'
		mtextoriginal = ""
	
		IF m.tnTipFisier = 1
			Create Cursor C_TMP_I (nr_cont C (24), data_t C (10), suma C (15), cod_valuta C (3), tip_tran C (150), tert C (100), ;
				  adresa C (100), iban C (24), banca C (200),	explicatie C (200), sold C (15), cf c(20))
		ELSE 
			* are in plus la inceput sold_i si sold_f
			Create Cursor C_TMP_I (sold_i C(20), sold_f C(20), nr_cont C (24), data_t C (10), suma C (15), cod_valuta C (3), tip_tran C (150), tert C (100), ;
				  adresa C (100), iban C (24), banca C (200),	explicatie C (200), sold C (15), cf c(20))				  
		ENDIF 				  
		If pldelimitator = ';'
			Append From (mSelectedFile) Delimited With Char ";"
		Else
			mfilestr = Filetostr(pselectedfile)
			If '""' $ mfilestr
				mfilestr = Strtran(mfilestr, '"""', '""')
				mfilestr = EliminVirguleDintreGhilimele(mfilestr, '""', ".")
				mfilestr = Strtran(mfilestr, '"', '')
			Endif
			Strtofile(mfilestr, m.gcTempPath + "INGTmp.csv")
			Append From (m.gcTempPath + "INGTmp.csv") Delimited With Character,
		Endif
		Scan For !Empty(data_t)
			Select c_iex
			If Alltrim(C_TMP_I.data_t) = "202"
				mdataop = Substr(C_TMP_I.data_t, 7, 2) + "." + Substr(C_TMP_I.data_t, 5, 2) + "." + Substr(C_TMP_I.data_t, 1, 4)
			Else
				mdataop = Alltrim(C_TMP_I.data_t)
			Endif
			If !Empty(Ctod(mdataop))
				Insert Into c_iex (Data) Values (setdategerman(mdataop))
				msuma = This.setsuma(C_TMP_I.suma)
				If "-" $ C_TMP_I.suma
					Replace tip With "D"
				Else
					Replace tip With "C"
				Endif
				Replace suma With Abs(msuma)
				lcTipTransfer = Lower(C_TMP_I.tip_tran)
				Do Case
					Case "comision" $ m.lcTipTransfer
						Replace tip_2 With This.cTipComisioane
					Case 'retragere numerar'$m.lcTipTransfer OR 'depunere numerar'$m.lcTipTransfer
						Replace tip_2 With This.cTipDepunere					
					Case 'transfer intern'$m.lcTipTransfer
						Replace tip_2 With This.cTipTransfer					
					Otherwise
						Replace tip_2 With ""
				ENDCASE
								
				Replace tert With Upper(C_TMP_I.tert), cf WITH ALLTRIM(NVL(C_TMP_I.cf,''))
				mexplicatie = Alltrim(C_TMP_I.explicatie)
				mtextoriginal = C_TMP_I.data_t + " " + Chr(13) + Alltrim(C_TMP_I.suma) + " " + Chr(13) + Alltrim(C_TMP_I.tip_tran) + " " + Chr(13) + Alltrim(C_TMP_I.tert) + Chr(13) + Alltrim(C_TMP_I.iban) + " " + Chr(13) + mexplicatie
				Replace explicatie With mexplicatie, original With mtextoriginal, iban With C_TMP_I.iban
			Endif
		Endscan
	Endproc
	*

	Procedure csvIntesa
		Lparameters pselectedfile, pisextras
		Local mtextoriginal
		This.cIBAN = 'Intesa'
		mtextoriginal = ""
		If pisextras = 1
			Create Cursor C_TMP_I (data_v C (10), data_t C (10), detalii C (200), Curs C (10), nr C (16), tip C (1), suma C (24))
		Else
			Create Cursor C_TMP_I (data_v C (11), nr C (10), detalii C (200), tert C (10), suma C (24))
		Endif
		mfilestr = Filetostr(pselectedfile)
		mlen = Len(mfilestr)
		mfilestr = EliminVirguleDintreGhilimele(mfilestr, '"')
		mfilestr = Strtran(mfilestr, '"', '')
		Strtofile(mfilestr, m.gcTempPath + "IntesaTMP.csv")
		Append From (m.gcTempPath + "IntesaTMP.csv") Csv
		Scan For !Empty(data_v)
			mdatatranz = setdategerman(Lower(C_TMP_I.data_v))
			If !Empty(mdatatranz)
				msuma = Thisform.setsuma(C_TMP_I.suma)
				If msuma <> 0
					Select c_iex
					Insert Into c_iex (Data) Values (mdatatranz)
					If pisextras = 1
						Replace tip With C_TMP_I.tip
					Else
						If msuma > 0
							Replace tip With "D"
						Else
							Replace tip With "C"
						Endif
					Endif
					Replace suma With Abs(msuma)
					Do Case
						Case "comision" $ Lower(C_TMP_I.detalii) .Or. "com." $ Lower(C_TMP_I.detalii)
							Replace tip_2 With "COM"
						Otherwise
							Replace tip_2 With ""
					Endcase


					miban = getibanfromstring(C_TMP_I.detalii, 1)
					mtert = ""
					If "-" $ C_TMP_I.detalii .And. Occurs( "/", C_TMP_I.detalii) >= 2
						mpoz1 = At( "-", C_TMP_I.detalii) + 2
						mpoz2 = At( "/", C_TMP_I.detalii, 2)
						mtert = Alltrim(Substr(C_TMP_I.detalii, mpoz1, mpoz2 - mpoz1))
					Else
						If C_TMP_I.detalii = "Incasare" .And. Occurs( "/ ", C_TMP_I.detalii) >= 2
							mpoz1 = At( "/ ", C_TMP_I.detalii) + 2
							mpoz2 = At( "/ ", C_TMP_I.detalii, 2) - 1
							mtert = Substr(C_TMP_I.detalii, mpoz1, mpoz2 - mpoz1)
							If "," $ mtert
								mtert = Left(mtert, At( ",", mtert) - 1)
							Endif
						Endif
					Endif
					If "CUI" $ mtert
						mtert = Left(mtert, At("CUI", mtert) - 1)
					Endif
					mexplicatie = C_TMP_I.detalii
					If ":" $ C_TMP_I.detalii
						mpoz1 = At(":", C_TMP_I.detalii) + 2
						mexplicatie = Alltrim(Substr(C_TMP_I.detalii, mpoz1, 150))
					Endif
					Replace tert With mtert
					If "CUI" $ C_TMP_I.detalii
						mpoz1 = At("CUI", C_TMP_I.detalii) + 4
						Replace cf With getdigitsfromstring(Substr(C_TMP_I.detalii, mpoz1, 16), 4, 1, ".")
					Endif
					mtextoriginal = C_TMP_I.data_v + Chr(13) + Alltrim(C_TMP_I.suma) + " " + Chr(13) + Alltrim(C_TMP_I.nr) + " " + Chr(13) + Alltrim(C_TMP_I.detalii)
					Replace explicatie With mexplicatie, original With mtextoriginal, iban With miban
				Endif
			Endif
		Endscan
	Endproc
	*

	Procedure csvPaypal
		Lparameters pselectedfile
		Local mtextoriginal
		This.cIBAN = 'PayPal'
		mtextoriginal = ""
		Create Cursor C_TMP_I (data_t C (10), c1 C (10), c2 C (10), detalii1 C (100), cod_valuta C (16), suma C (16), fee C (10), net C (100), ;
			  balance C (10), c3 C (10), email C (60), nume C (100), banca C (10), iban C (24), c5 C (10), c6	C (10), c7 C (10), c8 C (100))
		Append From (mSelectedFile) Csv
		Delete For Empty(C_TMP_I.data_t)
		Scan For !Empty(data_t)
			Select c_iex
			If C_TMP_I.data_t = "202" .Or. !"/" $ C_TMP_I.data_t
				mdata = setdategerman(C_TMP_I.data_t)
			Else
				Set Date To AMERICAN
				mdata = Ctod(C_TMP_I.data_t)
				Set Date To German
			Endif
			Insert Into c_iex (Data) Values (mdata)
			If "-" $ C_TMP_I.suma
				Replace tip With "D"
			Else
				Replace tip With "C"
			Endif
			Replace suma With This.setsuma(C_TMP_I.suma)
			Do Case
				Case "comision" $ Lower(C_TMP_I.detalii1) .Or. "COMMISSION" $ Upper(C_TMP_I.detalii1)
					Replace tip_2 With "COM"
				Otherwise
					Replace tip_2 With ""
			Endcase
			Replace tert With Upper(C_TMP_I.nume), cod_valuta With C_TMP_I.cod_valuta
			mexplicatie = Alltrim(C_TMP_I.detalii1)
			mtextoriginal = C_TMP_I.data_t + " " + Chr(13) + C_TMP_I.suma + " " + Chr(13) + Alltrim(C_TMP_I.iban) + " " + Chr(13) + Alltrim(C_TMP_I.nume) + " " + Alltrim(C_TMP_I.cod_valuta) + " " + Chr(13) + Alltrim(C_TMP_I.email) + " " + Chr(13) + mexplicatie
			Replace explicatie With mexplicatie, original With mtextoriginal, iban With C_TMP_I.iban, email With C_TMP_I.email
			mfee = This.setsuma(C_TMP_I.fee)
			If mfee > 0
				Insert Into c_iex (Data, tip, suma, tip_2, explicatie) Values (mdata, "D", mfee, "COM", "Comision")
			Endif
		Endscan
	Endproc
	*

	Procedure csvPayu
		Lparameters pselectedfile
		Local mtextoriginal, mfilestr, mlen, ij, mpas
		This.cIBAN = 'PayU'
		mtextoriginal = ""
		Create Cursor C_TMP_I (c01 C (1), c02 C (1), c03 C (1), c04 C (1), c05 C (1), c06 C (1), c07 C (1), ;
			  c08 C (1), c09 C (1), c10 C (1), Data C (10), c12 C (1), c13 C (1), c14 C (1), suma C (15), c16 C (1), ;
			  c17 C (1), c18 C (1), c19 C (1), c20 C (1), c21 C (1), c22 C (1), c23 C (1), c24 C (1), ;
			  firma C (150), client C (150), adresa C (160), telefon C (16), email C (64), oras C (24), ;
			  c60 C (1), c61 C (1), c62 C (1), cnp C (13), cf C (13), nr_i C (15), banca C(60), iban C(250), referinta C(60))

		Select C_TMP_I
		Append From (pselectedfile) Csv
		Scan For !Empty(Data)
			Select c_iex
			Insert Into c_iex (Data) Values (setdategerman(C_TMP_I.Data))
			Replace tip With "C", suma With This.setsuma(C_TMP_I.suma)
			mtert = ""
			mcf = ""
			If !Empty(C_TMP_I.firma)
				mtert = Upper(Alltrim(C_TMP_I.firma))
			Else
				mtert = Upper(Alltrim(C_TMP_I.client))
			Endif
			If !Empty(C_TMP_I.cf)
				mcf = Alltrim(C_TMP_I.cf)
			Else
				mcf = Alltrim(C_TMP_I.cnp)
			Endif
			Replace tert With mtert, cf With mcf, iban With C_TMP_I.iban, tel With C_TMP_I.telefon, email With C_TMP_I.email
			mexplicatie = Alltrim(C_TMP_I.referinta)
			mtextoriginal = C_TMP_I.Data + Chr(13) + Alltrim(C_TMP_I.firma) + Alltrim(C_TMP_I.client) + Chr(13) + Alltrim(C_TMP_I.cnp) + Alltrim(C_TMP_I.cf) + Chr(13) + Alltrim(C_TMP_I.telefon) + Chr(13) + Alltrim(C_TMP_I.email) + Chr(13) + Alltrim(C_TMP_I.suma) + Chr(13) + Alltrim(C_TMP_I.oras) + " " + Alltrim(C_TMP_I.adresa)
			Replace explicatie With mexplicatie, original With mtextoriginal
		Endscan
	Endproc
	*
	
	Procedure csvStripe
		Lparameters pselectedfile
		Local mtextoriginal, mfilestr, mlen, ij, mpas
		This.cIBAN = 'Stripe'
		mtextoriginal = ""
		Create Cursor C_TMP_I (DataC C (25), tip C (30), comanda C (30), client C (150), status C(50), Data C (10), suma C (15), ;
			  comision C (15), sumaneta C (15), referinta c(50))

		Select C_TMP_I
		Append From (pselectedfile) Csv
		Scan For !Empty(Data)
			lcData = ALLTRIM(data)
			ldData = {}
			lnLuna = VAL(GETWORDNUM(m.lcData,1,'/'))
			lnZi = VAL(GETWORDNUM(m.lcData,2,'/'))
			lnAn = VAL(GETWORDNUM(m.lcData,3,'/'))			
			IF BETWEEN(m.lnZi, 1, 31) AND BETWEEN(m.lnLuna, 1, 12) AND BETWEEN(m.lnAn, 2000,2999)
				TRY 
					ldData = DATE(m.lnAn, m.lnLuna, m.lnZi)
				CATCH 
					*
				ENDTRY 	
			ENDIF 	
						
			SELECT c_iex
			Insert Into c_iex (Data) Values (m.ldData)
			Replace tip With "C", suma With This.setsuma(C_TMP_I.suma)
			mtert = Upper(Alltrim(C_TMP_I.client))
			Replace tert With mtert
			mexplicatie = Alltrim(C_TMP_I.tip) + ' ' + Alltrim(C_TMP_I.comanda)
			mtextoriginal = C_TMP_I.Data + Chr(13) + Alltrim(C_TMP_I.client) + Chr(13) + Alltrim(C_TMP_I.suma) + Chr(13) + Alltrim(C_TMP_I.comanda)
			Replace explicatie With mexplicatie, original With mtextoriginal
		Endscan
	Endproc
	*

	Procedure csvRaiffeisen
		Lparameters pselectedfile, pdelimiter
		Local mtextoriginal
		This.cIBAN = 'Raiffeisen'
		mtextoriginal = ""

		Create Cursor C_TMP_I (data_t C (10), data_v C (10), debit C (15), credit C (15), nr C (15), cf C (15), ordonator C (100), beneficiar C (100), ;
			  nume C(100), banca C (100), iban C (24), detalii C (200))

		If pdelimiter = ";"
			Append From (mSelectedFile) Delimited With Char ";"
		Else
			Append From (mSelectedFile) Csv
		Endif
		Delete For Empty(Ctod(C_TMP_I.data_t))
		Scan For !Empty(data_t)
			Select c_iex
			Insert Into c_iex (Data) Values (setdategerman(C_TMP_I.data_t))
			If !Empty(C_TMP_I.debit)
				Replace tip With "D"
				msuma = This.setsuma(C_TMP_I.debit)
			Else
				Replace tip With "C"
				msuma = This.setsuma(C_TMP_I.credit)
			Endif
			Replace suma With msuma
			Do Case
				Case "comision" $ Lower(C_TMP_I.detalii)
					Replace tip_2 With "COM"
				Otherwise
					Replace tip_2 With ""
			Endcase
			Replace nr With C_TMP_I.nr, tert With Upper(C_TMP_I.nume), cf With Upper(C_TMP_I.cf)
			mexplicatie = Alltrim(C_TMP_I.detalii)
			mtextoriginal = C_TMP_I.data_t + " " + Chr(13) + Alltrim(C_TMP_I.debit) + Alltrim(C_TMP_I.credit) + " " + Chr(13) + Alltrim(C_TMP_I.nr) + Chr(13) + Alltrim(C_TMP_I.iban) + " " + Chr(13) + Alltrim(C_TMP_I.nume) + " " + Alltrim(C_TMP_I.cf) + " " + Chr(13) + mexplicatie
			Replace explicatie With mexplicatie, original With mtextoriginal, iban With C_TMP_I.iban
		Endscan
	Endproc
	*

	Procedure csvUnicredit
		Lparameters pselectedfile, pdelimiter
		Local mtextoriginal
		This.cIBAN = 'Unicredit'
		mtextoriginal = ""
		Create Cursor C_TMP_I (Cont C (24), suma C (15), valuta C (16), data_t C (10), data_v C (10), banca C (10), banca_nume C (100), ;
			  adresa C (10), cont1 C(10), iban C (24), nume C(100), adr1 C (10), adr2 C (10), adr3 C (10), detalii1 C (100), detalii2 C (100), ;
			  detalii3 C (100), detalii4 C (100), detalii5 C (100), detalii6 C (100), detalii7 C (100), detalii8 C (100), detaliip1 C (100), detaliip2 C (100), detaliip3 C (100), ;
			  detaliip4 C (100), detaliip5 C (100), detaliip6 C (100), ;
			  cf C (15), nr C (15), camp2 C (10), camp3 C (10), camp4 C (10), plafon C (15))


		If File(m.pselectedfile)
			lnLinii = Alines(This.aLinii, Filetostr(m.lcFile), 1)
			lnLinii = Iif(Empty(m.lnLinii), 0, m.lnLinii)
			This.nLinii = m.lnLinii

			lcLinie = This.aLinii[2]
			This.cIBAN = syGETWORDNUM(m.lcLinie, 2, ';')
			This.cValuta = syGETWORDNUM(m.lcLinie, 3, ';')
		Endif
			
		Do Case
			Case pdelimiter = ";"
				Append From (mSelectedFile) Delimited With Char ";"
			Case pdelimiter = Chr(10) .Or. Empty(pdelimiter)
				Append From (mSelectedFile) Delimited With Char Tab
			Otherwise
				Append From (mSelectedFile) Csv
		Endcase
		Delete For Empty(Ctod(C_TMP_I.data_t))
		Scan For !Empty(data_t) .And. !Empty(setdategerman(C_TMP_I.data_t))
			Select c_iex
			Insert Into c_iex (Data) Values (setdategerman(C_TMP_I.data_t))
			If "-" $ C_TMP_I.suma
				Replace tip With "D"
			Else
				Replace tip With "C"
			Endif
			Replace suma With This.setsuma(C_TMP_I.suma)
			Do Case
				Case "comision" $ Lower(C_TMP_I.detalii1) .Or. "transfond fee" $ Lower(C_TMP_I.detalii1) .Or. ;
						"COMMISSION" $ Upper(C_TMP_I.detalii1) Or ;
						' FEE' $ Upper(C_TMP_I.detalii1) Or 'FEE/' $ Upper(C_TMP_I.detalii1) Or Upper(C_TMP_I.detalii1) = 'FEE'
					lcTip2 = "COM"
				Case 'CASH DEPOSIT' $ Upper(C_TMP_I.detalii1)
					lcTip2 = This.cTipDepunere
				Case 'BUGETUL DE STAT' $ Upper(C_TMP_I.nume)
					lcTip2 = This.cTipBuget
				Case 'PROMISSORY NOTE' $ Upper(C_TMP_I.detaliip1) Or 'PROMISSORY NOTE' $ Upper(C_TMP_I.detalii1)
					lcTip2 = This.cTipEfecteComerciale
				Otherwise
					lcTip2 = This.cTipTerti
			Endcase

			Replace nr With C_TMP_I.nr, tert With C_TMP_I.nume, cf With C_TMP_I.cf, tip_2 With m.lcTip2

			mexplicatie = Alltrim(Alltrim(C_TMP_I.detalii1) + " " + Alltrim(C_TMP_I.detalii2) + " " + Alltrim(C_TMP_I.detalii3) + " " + ;
				  Alltrim(C_TMP_I.detalii4) + " " + Alltrim(C_TMP_I.detalii5) + " " + ;
				  Alltrim(C_TMP_I.detalii6) + " " + Alltrim(C_TMP_I.detalii7) + " " + Alltrim(C_TMP_I.detalii8) + " " + ;
				  Alltrim(C_TMP_I.detaliip1) + " " + Alltrim(C_TMP_I.detaliip2) + " " + Alltrim(C_TMP_I.detaliip3) + " " + ;
				  Alltrim(C_TMP_I.detaliip4) + " " + Alltrim(C_TMP_I.detaliip5) + " " + Alltrim(C_TMP_I.detaliip6))

			mtextoriginal = C_TMP_I.data_t + " " + Chr(13) + C_TMP_I.suma + " " + Chr(13) + Alltrim(C_TMP_I.iban) + " " + Chr(13) + Alltrim(C_TMP_I.nume) + " " + Alltrim(C_TMP_I.cf) + " " + Chr(13) + mexplicatie + " " + Chr(13) + Alltrim(C_TMP_I.nr)

			* Array sau lista cu numere de facturi separate prin "," daca exista in descriere
			* (?:( \d+)(?![\.\d])(?!2021).) spatiu apoi cifre, fara . si cifra si fara anul curent (sa excluda datele)
			lcFacturi = ''
			lcDescriereFacturi = m.mexplicatie
			lnResults = GetRegExpAllNumbers(m.lcDescriereFacturi, @m.lcFacturi)

			Replace explicatie With mexplicatie, original With mtextoriginal, iban With C_TMP_I.iban, documente With m.lcFacturi
		Endscan
	Endproc
	*
	Procedure csvMobilPay
		Lparameters pselectedfile

		Local mtextoriginal, mdata, mexplicatie, msuma, mcomanda, lcTip, lcTip2, lcNr
		This.cIBAN = 'MobilPay'

		mtextoriginal = ""
		Create Cursor C_TMP_I (c1 C (4), c2 C (24), Id C (24), ;
			  data_v C (24), data_o C(10), suma C (24), creditat C (24), comision ;
			  C (10), tva_comis C (10), moneda C (3), c9 C (24), ;
			  c10 C (24), prenume C (36), nume C (36), email C (60), ;
			  tel C (20), descriere C (100))

		Append From (mSelectedFile) Delimited With Char,
		*Locate For .Not. Empty(data_v)
		Scan For .Not. Empty(data_v)
			mdata = setdategerman(C_TMP_I.data_v)
			msuma = This.setsuma(C_TMP_I.suma)
			mcomision = This.setsuma(C_TMP_I.comision) + This.setsuma(C_TMP_I.tva_comis)
			lcNr = DTOS(mdata)
			lcTip2 = ''
			IF msuma = 0 AND mcomision <> 0
				msuma = -ABS(mcomision)
				lcTip2 = This.cTipComisionDecont
			ENDIF 
			If !Empty(mdata) And msuma <> 0
				Select c_iex
				Insert Into c_iex (Data) Values (mdata)
				If msuma < 0
					lcTip = "D"
				Else
					lcTip = "C"
				ENDIF
				* comisioanele au suma negativa
				msuma = ABS(msuma) 

				mexplicatie = Alltrim(C_TMP_I.descriere) && "Plata comanda SOWB21009885 de la Safetyone"
				mcomanda = ALLTRIM(STREXTRACT(mexplicatie, 'plata comanda ', ' ', 1, 1+2))

				mtextoriginal = Alltrim(C_TMP_I.Id) + " " + C_TMP_I.data_v + " " + Chr(13) + ;
					Alltrim(C_TMP_I.suma) + " " + Chr(13) + Alltrim(C_TMP_I.nume) + " " + ;
					Alltrim(C_TMP_I.prenume) + Chr(13) + Alltrim(C_TMP_I.email) + " " + Chr(13) + Alltrim(C_TMP_I.tel)

				Replace explicatie With mexplicatie, original With mtextoriginal, tel With C_TMP_I.tel, email With C_TMP_I.email, tip_2 WITH m.lcTip2, comenzi WITH mcomanda, ;
					tert With Upper(Alltrim(C_TMP_I.nume)) + " " + Upper(Alltrim(C_TMP_I.prenume)), tip WITH m.lcTip, suma With msuma, nr WITH m.lcNr
			Endif
		Endscan
	Endproc
	*
	Procedure txtPosta

		Lparameters pselectedfile
		Local mtextoriginal
		This.cIBAN = 'POSTA'
		*:Global mexplicatie, msuma
		mtextoriginal = ""
		Create Cursor C_TMP_I (c1 C (24), c2 C (24), nr C (24), data1 C (10), oficiu C (36), tert C (64), adresa C (150), suma C (24), linie C (1), explicatie C (200), data_v C (10))
		Append From (mSelectedFile) Delimited With Char ";"
		Scan For !Empty(data_v)
			Select c_iex
			Insert Into c_iex (Data) Values (setdategerman(C_TMP_I.data_v))
			msuma = This.setsuma(C_TMP_I.suma)
			Replace tip With "C", suma With msuma, nr With C_TMP_I.nr
			mexplicatie = Alltrim(C_TMP_I.explicatie)
			Replace tert With Upper(C_TMP_I.tert)
			mtextoriginal = C_TMP_I.data_v + " " + C_TMP_I.c2 + " " + C_TMP_I.nr + " " + Chr(13) + Alltrim(C_TMP_I.suma) + " " + Chr(13) + Alltrim(C_TMP_I.tert) + " " + Chr(13) + Alltrim(C_TMP_I.adresa) + Chr(13) + Alltrim(C_TMP_I.explicatie)
			Replace explicatie With mexplicatie, original With mtextoriginal
		Endscan
	Endproc
*
	Function setsuma

		Lparameters plsumatext
		Local ii
		plsumatext = Alltrim(plsumatext)
		mlen = Len(plsumatext)
		For ii = 1 To mlen
			If !Inlist(Substr(plsumatext, ii, 1), " ", ",", ".", "-", "+", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9")
				plsumatext = Left(plsumatext, ii - 1)
				Exit
			Endif
		Endfor
		Do Case
			Case "." $ Right(Alltrim(plsumatext), 3)
				Return Val(Strtran(plsumatext, ",", ""))
			Case "," $ Right(Alltrim(plsumatext), 3)
				Return Val(Strtran(Strtran(plsumatext, ".", ""), ",", "."))
			Otherwise
				Return Val(Strtran(plsumatext, ",", ""))
		Endcase
	Endfunc && SetSuma

	*
	* Nu am verificat ce face
	Function actsume
		Local mnrrec, lcSelect
		lcSelec = Select()
		Select match
		Do Case
			Case achitat < neachitat_real
				Replace is_total With 0
			Case achitat = neachitat_real
				Replace is_total With 1
			Case achitat > Total .And. Total > 0
				Select (m.lcSelect)
				Return .F.
		Endcase
		If .Not. Eof()
			mnrrec = Recno()
		Endif

		Scan
			Replace neachitat With neachitat_real - achitat
		Endscan
		Sum achitat, neachitat To lnAchitat, lnNeachitat
		If Type("mNrRec") = "N"
			Goto mnrrec
		Endif
		lnRamas = c_iex.suma - m.lnAchitat
		If m.lnRamas = 0
			Replace asociat With 1 In c_iex
		Else
			Replace asociat With 0 In c_iex
		Endif
		Select (m.lcSelect)
		Return .T.
	Endfunc && ActSume
	*
Enddefine && ExtrasBanca_General

*
Function ValidCNP
	Lparameters lpcnp
	If Len(Alltrim(lpcnp)) <> 13
		Return .F.
	Endif
	n1 = Val(Substr(lpcnp, 1, 1))
	n2 = Val(Substr(lpcnp, 2, 1))
	n3 = Val(Substr(lpcnp, 3, 1))
	n4 = Val(Substr(lpcnp, 4, 1))
	n5 = Val(Substr(lpcnp, 5, 1))
	n6 = Val(Substr(lpcnp, 6, 1))
	n7 = Val(Substr(lpcnp, 7, 1))
	n8 = Val(Substr(lpcnp, 8, 1))
	n9 = Val(Substr(lpcnp, 9, 1))
	n10 = Val(Substr(lpcnp, 10, 1))
	n11 = Val(Substr(lpcnp, 11, 1))
	n12 = Val(Substr(lpcnp, 12, 1))
	n13 = Val(Substr(lpcnp, 13, 1))
	C = Mod((n1 * 2 + n2 * 7 + n3 * 9 + n4 * 1 + n5 * 4 + n6 * 6 + n7 * 3 + n8 * 5 + n9 * 8 + n10 * 2 + n11 * 7 + n12 * 9), 11)
	If C = 10
		C = 1
	Endif
	If C = n13
		Return .T.
	Else
		Return .F.
	Endif
Endfunc
*
Function GetDataCNP
	Lparameters plcnp
	Local mlan
	mlan = Substr(plcnp, 2, 2)
	If Val(mlan) > 20 .And. !Inlist(Left(plcnp, 1), "5", "6")
		mlan = "19" + mlan
	Else
		mlan = "20" + mlan
	Endif
	Return Ctod(Substr(plcnp, 6, 2) + "." + Substr(plcnp, 4, 2) + "." + mlan)
Endfunc
*
Function verifcf
	Lparameters plcfisc
	Local mlsuma, mlrest
	plcfisc = getnrfromstring(plcfisc)
	If Len(Alltrim(plcfisc)) = 13
		If !ValidCNP(plcfisc)
			Return .F.
		Else
			Return .T.
		Endif
	Else
		If Len(Alltrim(plcfisc)) < 2 .Or. Len(Alltrim(plcfisc)) > 9 .Or. plcfisc = "0"
			Return .F.
		Endif
	Endif
	plcfisc = Padl(Alltrim(plcfisc), 10, "0")
	mlsuma = 0
	For I = 1 To 10
		mlsuma = mlsuma + Val(Substr(plcfisc, I, 1)) * Val(Substr("753217532", I, 1))
	Endfor
	mlrest = Mod((mlsuma * 10), 11)
	If mlrest = 10
		mlrest = 0
	Endif
	If Val(Substr(plcfisc, 10, 1)) <> mlrest
		Return .F.
	Else
		Return .T.
	Endif
Endfunc
*
Function getnrfromstring
	Lparameters plstr
	Local mlenstr
	mlenstr = Len(Alltrim(plstr))
	Do While Isalpha(plstr) .Or. Left(plstr, 1) == " " .Or. Left(plstr, 1) == "&" .Or. Left(plstr, 1) == "/" .Or. Left(plstr, 1) == "-" .Or. Left(plstr, 1) == "_" .Or. Left(plstr, 1) == "." .Or. Left(plstr, 1) == ":"
		plstr = Rtrim(Substr(plstr, 2, mlenstr))
	Enddo
	Return plstr
Endfunc
*
Function getdigitsfromstring
	Lparameters plstr, plnrdigits, pltip, plseparator
	Local mlenstr, ii, mreturnnrintermed, mreturnnrfinal
	mlenstr = Len(Alltrim(plstr))
	mreturnnrintermed = ""
	mreturnnrfinal = ""
	For ii = 1 To mlenstr
		mcurentchar = Substr(plstr, ii, 1)
		If Isdigit(mcurentchar) .Or. (pltip = 3 .And. Inlist(mcurentchar, ".", ","))
			mreturnnrintermed = mreturnnrintermed + mcurentchar
		Else
			If pltip = 1 .Or. pltip = 2
				mreturnnrintermed = ""
			Endif
		Endif
		If Len(mreturnnrintermed) >= plnrdigits
			Do Case
				Case pltip = 1
					If Len(mreturnnrintermed) <= 12 .And. verifcf(mreturnnrintermed) .And. !Isdigit(Substr(plstr, ii + 1, 1))
						mreturnnrfinal = mreturnnrintermed
						Exit
					Endif
				Case pltip = 2
					If ValidCNP(mreturnnrintermed)
						mreturnnrfinal = mreturnnrintermed
						Exit
					Endif
				Case pltip = 3
					mreturnnrintermed = Strtran(mreturnnrintermed, plseparator, "")
					If Val(mreturnnrintermed) > 0
						mreturnnrfinal = mreturnnrintermed
						Exit
					Endif
			Endcase
		Endif
	Endfor
	Return mreturnnrfinal
Endfunc
*
Function getibanfromstring
	Lparameters plstr, plpoz
	Local mlenstr, ii, mreturnnrintermed, mreturnnrfinal
	mlenstr = Len(Alltrim(plstr))
	mreturnnrintermed = ""
	mreturnnrfinal = ""
	misok = .F.
	For ii = 1 To mlenstr
		mcurentchar = Substr(plstr, ii, 1)
		If misok
			If Len(mreturnnrintermed) < 24
				mreturnnrintermed = mreturnnrintermed + mcurentchar
			Else
				Exit
			Endif
		Else
			If mcurentchar == "R" .And. mreturnnrintermed = "" .And. Substr(plstr, ii + 1, 1) == "O"
				mreturnnrintermed = mreturnnrintermed + mcurentchar
			Else
				If mcurentchar == "O" .And. mreturnnrintermed = "R"
					mreturnnrintermed = mreturnnrintermed + mcurentchar
				Else
					If !misok .And. Inlist(mcurentchar, "1", "2", "3", "4", "5", "6", "7", "8", "9", "0") .And. mreturnnrintermed = "RO" .And. Len(mreturnnrintermed) <= 3
						mreturnnrintermed = mreturnnrintermed + mcurentchar
						If plpoz = 1
							misok = .T.
						Else
							mreturnnrintermed = ""
							plpoz = plpoz - 1
						Endif
					Else
						mreturnnrintermed = ""
					Endif
				Endif
			Endif
		Endif
	Endfor
	If verifiban(mreturnnrintermed)
		Return mreturnnrintermed
	Else
		Return ""
	Endif
Endfunc

*

Function getnumberincrement
	Lparameters pactualnumber
	Local mstartchr, mintermed
	mstartchr = ""
	mintermed = Alltrim(pactualnumber)
	mlennr = Len(mintermed)
	Do While Isalpha(mintermed) .Or. Left(mintermed, 1) == " " .Or. Left(mintermed, 1) == "-" .Or. Left(mintermed, 1) == "." .Or. Left(mintermed, 1) == "/"
		mstartchr = mstartchr + Left(mintermed, 1)
		mintermed = Rtrim(Substr(mintermed, 2, 16))
	Enddo
	Return Round(Val(Strtran(Strtran(mintermed, "e", ""), "E", "")), 0)
Endfunc
*
Function GetSerieIncrement
	Lparameters pactualnumber
	Local mstartchr, mintermed
	mstartchr = ""
	mintermed = Alltrim(pactualnumber)
	mlennr = Len(mintermed)
	Do While Isalpha(mintermed) .Or. Inlist(Left(mintermed, 1), " ", ".", "/", "-")
		mstartchr = mstartchr + Left(mintermed, 1)
		mintermed = Rtrim(Substr(mintermed, 2, 16))
	Enddo
	Return mstartchr
Endfunc
*
*
Function setdategerman
	Lparameters pldatatext
	Local mdatar, mlzi, mlluna, mlan, mlunatext, lcSetDate
	*:Global mlocc, mlocc1
	lcSetDate = Set("Date")
	If "ian" $ pldatatext .Or. "feb" $ pldatatext .Or. "mar" $ pldatatext .Or. "apr" $ pldatatext .Or. "mai" $ pldatatext .Or. "iun" $ pldatatext .Or. "iul" $ pldatatext .Or. "aug" $ pldatatext .Or. "sep" $ pldatatext .Or. "oct" $ pldatatext .Or. "noi" $ pldatatext .Or. "dec" $ pldatatext .Or. "jan" $ pldatatext .Or. "may" $ pldatatext .Or. "jun" $ pldatatext .Or. "jul" $ pldatatext .Or. "nov" $ pldatatext
		mlocc = At(" ", pldatatext, 2)
		mlocc1 = At(" ", pldatatext, 1)
		If mlocc = 0
			mlocc = At("-", pldatatext, 2)
			mlocc1 = At("-", pldatatext, 1)
			If mlocc = 0
				mlocc = At(".", pldatatext, 2)
				mlocc1 = At(".", pldatatext, 1)
			Endif
		Endif
		mlzi = Substr(pldatatext, 1, mlocc1 - 1)
		mlunatext = Lower(Substr(pldatatext, mlocc1 + 1, mlocc - 3))
		mlluna = ""
		Do Case
			Case mlunatext = "ian" .Or. mlunatext = "jan"
				mlluna = "01"
			Case mlunatext = "feb"
				mlluna = "02"
			Case mlunatext = "mar"
				mlluna = "03"
			Case mlunatext = "apr"
				mlluna = "04"
			Case mlunatext = "mai" .Or. mlunatext = "may"
				mlluna = "05"
			Case mlunatext = "iun" .Or. mlunatext = "jun"
				mlluna = "06"
			Case mlunatext = "iul" .Or. mlunatext = "jul"
				mlluna = "07"
			Case mlunatext = "aug"
				mlluna = "08"
			Case mlunatext = "sep"
				mlluna = "09"
			Case mlunatext = "oct"
				mlluna = "10"
			Case mlunatext = "noi" .Or. mlunatext = "nov"
				mlluna = "11"
			Case mlunatext = "dec"
				mlluna = "12"
		Endcase
		mlan = Substr(pldatatext, mlocc + 1, 4)
		mdatar = Ctod(mlzi + "." + mlluna + "." + mlan)
	Else
		pldatatext = Substr(pldatatext, 1, 10)
		If "," $ pldatatext
			pldatatext = Left(pldatatext, At(",", pldatatext) - 1)
		Endif
		mdatar = {}
		If Substr(pldatatext, 3, 1) == '/' .Or. Substr(pldatatext, 2, 1) == '/'
			mdatar = Ctod(Strtran(pldatatext, "/", "."))
		Else
			If Left(pldatatext, 3) == '201' .Or. Left(pldatatext, 3) == '202'
				Set Date To Japan
				If "-" $ pldatatext .Or. "/" $ pldatatext
					mdatar = Ctod(Strtran(pldatatext, "-", "/" ))
				Else
					mdatar = Ctod(Substr(pldatatext, 1, 4) + "/" + Substr(pldatatext, 5, 2) + "/" + Substr(pldatatext, 7, 2))
				Endif
				Set Date To German
			Else
				mdatar = Ctod(pldatatext)
			Endif
		Endif
	Endif
	Set Date &lcSetDate
	Return mdatar
Endfunc
*
Function EliminVirguleDintreGhilimele
	Lparameters plstring, pltipghilimele, plinlocuitor
	Local mnrghilimele, mlen, mstartghilimele, ij
	mlen = Len(plstring)
	mnrghilimele = Len(pltipghilimele)
	mstartghilimele = 0
	For ij = 1 To mlen
		If Substr(plstring, ij, mnrghilimele) = pltipghilimele
			If mstartghilimele = 0
				mstartghilimele = 1
			Else
				mstartghilimele = 0
			Endif
		Endif
		If Substr(plstring, ij, 1) = ',' .And. mstartghilimele = 1
			If Type("plInlocuitor") = "C"
				plstring = Substr(plstring, 1, ij - 1) + plinlocuitor + Alltrim(Substr(plstring, ij + 1, 2000000))
			Else
				plstring = Substr(plstring, 1, ij - 1) + Alltrim(Substr(plstring, ij + 1, 2000000))
			Endif
			mlen = mlen - 1
			ij = ij - 1
		Endif
	Endfor
	Return plstring
Endfunc


* --------------------------------------------------------------------
* Intoarce numarul de rezultate
* Parametrul tcItems (OUT) o lista cu numere separate prin virgula din textul original
* --------------------------------------------------------------------
Function GetRegExpAllNumbers
	Lparameters tcSourceString, tcItems
	* tcSourceString: Bld. Stefan cel Mare   14   Tirgu Neamt
	* tcPattern: [A-Za-z\s]+$ = (caracter sau spatiu) de cel putin o data la sfarsitul liniei = Tirgu Neamt
	* tcPattern: \d+[A-Za-z\s]+$ = oricate cifre (caracter sau spatiu) de cel putin o data la sfarsitul liniei = 14   Tirgu Neamt
	* taItems "A">taItems : array cu rezultatele (OUT) taItems[1..Result] sau taItems "C" lista facturi separate prin virgula
	Local lnResults, lcPattern, lcAn, lcAn2, lcSourceString
	*!*		lcRegExp = "(\d)+"
	*!*		lcRegExp = "(?<![.\d])\d+(?![.\d])"

	* Nu doresc sa rezulte an, luna, zi din data facturii
	* Adaug . dupa anul curent, ca sa il gaseasca pattern-ul
	* Patternul de negative look behind dadea eroare, daca cautam .2021
	* Caut [.AAAA ] sau [.AA ] si adaug un [.] in dreapta
	lcAn = Alltrim(Str(m.gnAn))
	*!*		lcAn2 = RIGHT(m.lcAn,2)
	*!*		lcSourceString = STRTRAN(m.tcSourceString, '.' + m.lcAn + ' ', '.' + m.lcAn + '. ',1,10,1)
	*!*		lcSourceString = STRTRAN(m.lcSourceString, '.' + m.lcAn2 + ' ', '.' + m.lcAn2 + '. ',1,10,1)
	*!*		IF RIGHT(m.lcSourceString,5) = '.' + m.lcAn OR RIGHT(m.lcSourceString,3) = '.' + m.lcAn2
	*!*			lcSourceString = m.lcSourceString + '.'
	*!*		ENDIF
	* Elimin zz.ll.aa(aa)
	lcSourceString = strtranx(m.tcSourceString, "\d{2}\.\d{2}\.\d{2,}", [], 1, , 1)

	* Elimin aaaa (anul curent) ex: martie 2021
	lcSourceString = strtranx(m.lcSourceString, " " + m.lcAn + "\b", [], 1, , 1)

	lcPattern = "\d+(?![.\d])" && numere fara . (sa nu apara zile)
	lnResults = GetRegExpAll(m.lcSourceString, m.lcPattern, @m.tcItems)
	Return lnResults
Endfunc

* --------------------------------------------------------------------
* Deschide tcCursor cu id_part, denumire, cod_fiscal pentru toti parteneri cu acelasi CUI normalizat
* --------------------------------------------------------------------
Function GetParteneriByCuiNormalizat
	Lparameters tcCodFiscal, tcCursor
	Private pcCui
	Local lcSql, llSucces

	pcCui = Alltrim(Strtran(Strtran(Upper(Alltrim(m.tcCodFiscal)), ' ', ''), 'RO', ''))

	lcSql = [select id_part, denumire, cod_fiscal from nom_parteneri where sters = 0 and inactiv = 0 ] + ;
		[and replace(replace(upper(cod_fiscal),' ',''),'RO','') = ?pcCui order by id_part]
	llSucces = goExecutor.oExecuta(m.lcSql, m.tcCursor)
	Return m.llSucces
Endfunc

* --------------------------------------------------------------------
* Creeaza/Actualizeaza Parteneri in ROA pentru fiecare cod_fiscal din tcCursorParteneri
* Verific dupa cod_fiscal, apoi dupa denumire
* Creeaza adrese parteneri daca este cazul
* Verifica daca exista cod_fiscal
* --------------------------------------------------------------------
Procedure CompleteazaParteneriROA
	Lparameters tcCursorParteneri, toCallBackForm
	* tcCursorParteneri: numele cursorului cParteneri (cod_fiscal, denumire[, adresa] [,reg_com])
	* toCallBackForm: referinta la un formular cu metoda Trace(tcMesaj) optional

	* Completez id_part
	*loHash = GetHash([cselect=>select id_part from nom_parteneri where replace(UPPER(cod_fiscal),' ', '') = replace(UPPER(?pcCodFiscal), ' ', '') and sters = 0 and inactiv = 0??cCursor=>cClientiROA])
	Local lcAdresa, lcAdreseParteneri, lcApart, lcBanca, lcBloc, lcCod_fiscal, lcCodpostal, lcCont_Banca
	Local lcCorespDel, lcDA_apare, lcDenumire, lcDenumire_adresa, lcEmail, lcEtaj, lcFax, lcIdPart
	Local lcIdString, lcId_Judet, lcId_categ_ent, lcId_loc, lcId_loc_inreg, lcId_tara, lcId_util, lcItem
	Local lcJudet, lcJudetBucuresti, lcLocalitate, lcMesaj, lcMotiv_inactiv, lcNumar, lcNume, lcPrefix
	Local lcPrenume, lcPrincipala, lcReg_comert, lcScara, lcSelect, lcSql, lcSqlCod, lcSqlDenumire
	Local lcSqlInsert, lcSqlPart, lcStrada, lcSufix, lcTara, lcTelefon1, lcTelefon2, lcTip_persoana
	Local lcWeb, lcinactiv, llCallBack, llSucces, lnIdJudet, lnIdJudetBucuresti, lnIdLocalitateBucuresti
	Local lnIdTaraRO, lnItem, lnItems, lnSucces
	Local lcCuiNorm
	Private pnIdAdresa, pcCodFiscal, pcDenumire, pnIdPart, pnNrAdrese, pnIdJudet

	llCallBack = Type('toCallBackForm') = 'O' And Pemstatus(m.toCallBackForm, 'trace', 5)

	pnIdJudet = 0
	pcCodFiscal = ''
	pcDenumire = ''
	pnIdPart = 0
	pnNrAdrese = 0

	lcSelect = Select()

	lcSqlPart = [select id_part, cod_fiscal, denumire from nom_parteneri where sters = 0 and inactiv = 0]
	llSucces = goExecutor.oExecuta(m.lcSqlPart, 'cParteneriROA')

	If !m.llSucces
		Return m.llSucces
	Endif

	Select id_part, cod_fiscal, denumire, NormalizeazaCUI(cod_fiscal) As cui_norm From cParteneriROA Into Cursor cParteneriROA Readwrite
	Index On cui_norm Tag cuinorm

	lcAdreseParteneri = [select id_adresa, id_part, localitate, id_loc, judet, id_judet, tara, id_tara from vadrese_parteneri]
	llSucces = goExecutor.oExecuta(m.lcAdreseParteneri, 'cAdreseROA')

	If !m.llSucces
		Use In (Select('cParteneriROA'))
		Return m.llSucces
	Endif

	*!*	lcSqlCod = [select MAX(id_part) as id_part from nom_parteneri where replace(UPPER(cod_fiscal),' ', '') = ?pcCodFiscal and sters = 0 and inactiv = 0]
	*!*	lcSqlDenumire = [select MAX(id_part) as id_part from nom_parteneri where denumire = ?pcDenumire and sters = 0 and inactiv = 0]

	Select (m.tcCursorParteneri)
	Scan
		pcCodFiscal = Alltrim(Upper(Strtran(cod_fiscal, ' ', '')))
		pcDenumire = Alltrim(Upper(denumire))
		IF LEN(m.pcCodFiscal) <= 3
			pcCodFiscal = ''
		ENDIF 
		pnIdPart = 0

		lcAdresa = Iif(Type(m.tcCursorParteneri + '.adresa') = 'C', Strtran(Alltrim(Upper(Nvl(adresa, ''))), Chr(13), ' '), '')
		* Preciziei (Strada), Nr. 6M, Complex rezidential TEN BLOCKS Bl. 8B, Sc. 1, Et. 6, Ap. 32, Cod Postal 062203, Bucuresti, Romania
		* Doinei (Strada), Nr. 94, Et. 2, Ap. 12 int 412, Cod Postal 077086, Fundeni, Romania
		* Lieberman Partners Srl Braniste Valeriu (Strada), Nr. 37-39, Et. 2, Ap. 8, Cod Postal 030715, Bucuresti, Romania

		Wait Window 'Import parteneri... Caut partenerul ' + Transform(Recno()) + '/' + Transform(Reccount()) Nowait

		Select cParteneriROA
		If !Empty(m.pcCodFiscal)
			Locate For Alltrim(Strtran(cod_fiscal, ' ', '')) = m.pcCodFiscal
			*!*			lnSucces = goExecutor.oSelect2Value(m.lcSqlCod, @pnIdPart)
			If !Found()
				lcCuiNorm = NormalizeazaCUI(m.pcCodFiscal)
				If !Empty(m.lcCuiNorm)
					Seek m.lcCuiNorm Order cuinorm
				Endif
			Endif
		Else
			Locate For Alltrim(Upper(denumire)) = m.pcDenumire
			*!*			lnSucces = goExecutor.oSelect2Value(m.lcSqlDenumire, @pnIdPart)
		Endif
		*!*		If m.lnSucces = -1
		*!*			Thisform.trace('Eroare la selectia din clienti ROA ' + goExecutor.oPrelucrareEroare())
		*!*			Exit
		*!*		Endif
		If Found()
			pnIdPart = cParteneriROA.id_part
		Endif

		If !Empty(Nvl(m.pnIdPart, 0))
			Select (m.tcCursorParteneri)
			Replace id_part With m.pnIdPart
			lcMesaj = 'Partener existent ' + Alltrim(denumire) + ' CUI: ' + Alltrim(cod_fiscal) + ' ID: ' + Alltrim(Transform(id_part))
			If m.llCallBack
				m.toCallBackForm.trace(m.lcMesaj)
			Endif
		Else
			* Adaugare clienti
			Select (m.tcCursorParteneri)
			lcDenumire = Left(Nvl(Strtran(Alltrim(Upper(denumire)), ['], ['']), ""), 100)
			lcNume = Left(Nvl(Strtran(Alltrim(Upper(nume)), ['], ['']), ""), 100)
			lcPrenume = Left(Nvl(Strtran(Alltrim(Upper(prenume)), ['], ['']), ""), 100)
			If Empty(m.lcNume)
				lcNume = m.lcDenumire
				lcPrenume = ''
			Endif
			lcCod_fiscal = Upper(Alltrim(cod_fiscal))
			IF LEN(m.lcCod_fiscal) <= 3
				lcCod_fiscal = ''
			ENDIF 
			lcReg_comert = Nvl(Alltrim(Upper(reg_com)), "")
			lcId_loc_inreg = 'NULL'
			lcId_categ_ent = 'NULL'
			lcPrefix = ""
			lcSufix = ""
			lcTip_persoana = Iif(!Empty(m.lcCod_fiscal) And Len(m.lcCod_fiscal) < 13, "1", "2")
			lcBanca = ""
			lcCont_Banca = ""
			lcinactiv = "0"
			lcMotiv_inactiv = ""
			lcIdString = "16"
			lcCorespDel = ""
			lcId_util = "-3"
			lcSqlInsert = [begin pack_def.adauga_partener('] + m.lcDenumire + [','] + m.lcNume + [','] + m.lcPrenume + [','] + m.lcCod_fiscal + [','] + ;
				M.lcReg_comert + [',] + m.lcId_loc_inreg + [,] + m.lcId_categ_ent + [,'] + m.lcPrefix + [','] + m.lcSufix + [',] + ;
				M.lcTip_persoana + [,'] + m.lcBanca + [','] + m.lcCont_Banca + [',] + m.lcinactiv + [,'] + m.lcMotiv_inactiv + [',] + ;
				M.lcId_util + [,'] + m.lcIdString + [','] + m.lcCorespDel + [',?@pnIdPart); end;]

			llSucces = goExecutor.oExecuta(m.lcSqlInsert)
			If !Empty(Nvl(m.pnIdPart, 0))
				Select (m.tcCursorParteneri)
				Replace id_part With m.pnIdPart
				
				INSERT INTO cParteneriROA (id_part, cod_fiscal, denumire) VALUES (m.pnIdPart, m.lcCod_fiscal, m.lcDenumire)
				
				If m.llCallBack
					m.toCallBackForm.trace('Client nou ' + Alltrim(denumire) + ' CUI: ' + Alltrim(cod_fiscal) + ' ID: ' + Alltrim(Transform(id_part)))
				Endif
			Else
				Select (m.tcCursorParteneri)
				lcMesaj = 'Eroare la adaugarea in clienti ROA ' + Alltrim(denumire) + ' CUI: ' + Alltrim(cod_fiscal) + Chr(13) + Chr(10) + goExecutor.oPrelucrareEroare()
				If m.llCallBack
					m.toCallBackForm.trace(m.lcMesaj)
				Endif
				*AMessagebox(m.lcMesaj, 0 + 48, _Screen.Caption )
				Exit
			Endif && !Empty(Nvl(m.pnIdPart,0))

		Endif && !Empty(Nvl(m.pnIdPart, 0))

		***********************************
		* Adresa partener
		***********************************
		If !Empty(m.lcAdresa)
			Calculate Cnt(id_adresa) For id_part = m.pnIdPart To m.pnNrAdrese In cAdreseROA
			*!*		pnNrAdrese = 0
			*!*		lnSucces = goExecutor.oSelect2Value([SELECT COUNT(*) as nr FROM adrese_parteneri WHERE id_part = ?pnIdPart], @pnNrAdrese)
			*!*		If m.lnSucces < 0
			*!*			lcMesaj = goExecutor.cEroare
			*!*			Thisform.trace(m.lcMesaj)
			*!*			AMessagebox(m.lcMesaj, 0 + 48, _Screen.Caption )
			*!*			Exit
			*!*		Endif

			lcIdPart = Alltrim(Str(m.pnIdPart))
			lcDenumire_adresa = ""
			lcDA_apare = "0"
			lcStrada = ""
			lcNumar = ""

			lcBloc = ""
			lcScara = ""
			lcApart = ""
			lcEtaj = ""
			lcId_loc = "NULL"
			lcLocalitate = ""
			lcId_Judet = "NULL"
			lcCodpostal = "NULL"
			lcId_tara =  "NULL"
			lcTelefon1 = ""
			lcTelefon2 = ""
			lcFax = ""
			lcEmail = ""
			lcWeb = ""
			lcPrincipala = Iif(m.pnNrAdrese = 0, "1", "0")
			lcinactiv = "0"
			lcId_util = "-3"

			lnItems = Getwordcount(m.lcAdresa, ',')
			For lnItem = 1 To m.lnItems
				lcItem = Alltrim(Getwordnum(m.lcAdresa, m.lnItem, ','))
				Do Case
					Case m.lnItem = 1 && strada
						lcStrada = Left(Alltrim(m.lcItem), 150)
					Case 'NR.' $ m.lcItem && nr strada
						lcNumar = Left(Alltrim(Strtran(m.lcItem, 'NR.', '')), 10)
					Case 'BL.' $ m.lcItem
						lcBloc = Left(Alltrim(Strtran(m.lcItem, 'BL.', '')), 30)
					Case 'SC.' $ m.lcItem
						lcScara = Left(Alltrim(Strtran(m.lcItem, 'SC.', '')), 10)
					Case 'ET.' $ m.lcItem
						lcEtaj = Left(Alltrim(Strtran(m.lcItem, 'ET.', '')), 20)
					Case 'AP.' $ m.lcItem
						lcApart = Left(Alltrim(Strtran(m.lcItem, 'AP.', '')), 10)
					Case 'COD POSTAL' $ m.lcItem
						lcCodpostal = Alltrim(Str(Int(Val(Left(Alltrim(Strtran(m.lcItem, 'COD POSTAL', '')), 20)))))
					Case 'LOC.' $ m.lcItem
						lcLocalitate = Alltrim(Strtran(m.lcItem, 'LOC.', ''))
					Case 'JUD.' $ m.lcItem
						lcJudet = Alltrim(Strtran(m.lcItem, 'JUD.', ''))
					Case m.lnItem = m.lnItems - 1 And Empty(m.lcLocalitate)
						lcLocalitate = m.lcItem
					Case m.lnItem = m.lnItems
						lcTara = m.lcItem
				Endcase
			Endfor

			lnIdJudetBucuresti = 10
			lcJudetBucuresti = "BUCURESTI"
			lnIdLocalitateBucuresti = 1759
			lnIdTaraRO = 1

			If m.lcLocalitate = 'BUCURESTI'
				lcLocalitate = 'BUCURESTI SECTORUL 1'
			Endif
			If Empty(m.lcLocalitate)
				lcLocalitate = 'BUCURESTI SECTORUL 1'
			Endif
			If Empty(m.lcJudet)
				lcJudet = m.lcJudetBucuresti
			Endif

			* caut adresa dupa localitate. daca nu o gasesc, o adaug
			Select cAdreseROA
			Locate For id_part = m.pnIdPart And localitate = m.lcLocalitate
			If !Found()
				pnIdJudet = 0
				llSucces = goExecutor.oSelecteaza2Value([select j.id_judet, j.id_tara from syn_nom_judete j where j.judet = '] + m.lcJudet + [' and j.inactiv = 0 and j.sters = 0], @m.pnIdJudet)

				If m.llSucces
					If Empty(Nvl(m.pnIdJudet, 0))
						llSucces = goExecutor.oSelecteaza2Value([select j.id_judet, j.id_tara from syn_nom_judete j where j.judet like '%] + m.lcJudetBucuresti + [%' and j.inactiv = 0 and j.sters = 0], @m.pnIdJudet)
						If m.llSucces
							lnIdJudet = m.pnIdJudet
						Else
							lnIdJudet = m.lnIdJudetBucuresti
						Endif
					Else
						lnIdJudet = m.pnIdJudet
					Endif
				Else
					If m.llCallBack
						m.toCallBackForm.trace(goExecutor.cEroare)
					Endif
					lnIdJudet = m.lnIdJudetBucuresti
				Endif

				lcSql = [select l.id_loc, l.id_judet, j.id_tara from syn_nom_localitati l left join syn_nom_judete j on l.id_judet = j.id_judet where l.id_judet = ] + Alltrim(Str(m.lnIdJudet)) + [ and l.localitate = '] + m.lcLocalitate + [' and l.inactiv = 0 and l.sters = 0 order by l.localitate]
				lnSucces = goExecutor.oExecuta(m.lcSql, 'cLocalitateTemp')
				If m.llSucces
					If Reccount('cLocalitateTemp') > 0
						Select cLocalitateTemp
						Go Top
						lcId_loc = Alltrim(Str(id_loc))
						lcId_Judet = Alltrim(Str(id_judet))
						lcId_tara = Alltrim(Str(id_tara))
						Use In (Select('cLocalitateTemp'))
					Else
						Use In (Select('cLocalitateTemp'))
						lcSql = [select l.id_loc, l.id_judet, j.id_tara from syn_nom_localitati l left join syn_nom_judete j on l.id_judet = j.id_judet where l.id_judet = ] + Alltrim(Str(m.lnIdJudet)) + [ and l.inactiv = 0 and l.sters = 0 order by l.localitate]
						llSucces = goExecutor.oExecuta(m.lcSql, 'cLocalitateTemp')
						If m.llSucces
							Select cLocalitateTemp
							Go Top
							lcId_loc = Alltrim(Str(id_loc))
							lcId_Judet = Alltrim(Str(id_judet))
							lcId_tara = Alltrim(Str(id_tara))
						Else
							If m.llCallBack
								m.toCallBackForm.trace(goExecutor.cEroare)
							Endif
						Endif
						Use In (Select('cLocalitateTemp'))
					Endif
				Else
					If m.llCallBack
						m.toCallBackForm.trace(goExecutor.cEroare)
					Endif
				Endif

				If Empty(Nvl(m.lcId_loc, ''))
					lcId_loc = Alltrim(Str(m.lnIdLocalitateBucuresti))
					lcId_Judet = Alltrim(Str(m.lnIdJudetBucuresti))
					lcId_tara = Alltrim(Str(m.lnIdTaraRO))
				Endif && llSucces

				If m.lcId_loc <> 'NULL'
					pnIdAdresa = 0
					*!*					* caut adresa dupa localitate. daca nu o gasesc, o adaug
					*!*					lcSql = [SELECT id_adresa FROM adrese_parteneri where sters = 0 and inactiv = 0 and id_loc = ] + m.lcId_loc + [ AND id_part = ] + m.lcIdPart
					*!*					lnSucces = goExecutor.oSelect2Value(m.lcSql, @pnIdAdresa)
					*!*					If m.lnSucces < 0
					*!*						lcMesaj = goExecutor.cEroare
					*!*						Thisform.trace(m.lcMesaj)
					*!*						AMessagebox(m.lcMesaj, 0 + 48, _Screen.Caption )
					*!*						Exit
					*!*					Endif

					If Empty(Nvl(m.pnIdAdresa, 0))
						lcSql = [begin pack_def.adauga_adresa_partener2(] + m.lcIdPart + [,'] + m.lcDenumire_adresa + [',] + m.lcDA_apare + [,] + ;
							['] + m.lcStrada + [','] + m.lcNumar + [','] + ;
							M.lcBloc + [','] + m.lcScara + [','] + m.lcApart + [','] + m.lcEtaj + [',] + m.lcId_loc + [,'] + m.lcLocalitate + [',] + m.lcId_Judet + [,] + m.lcCodpostal + [,] + m.lcId_tara + [,'] + ;
							M.lcTelefon1 + [','] + m.lcTelefon2 + [','] + m.lcFax + [','] + m.lcEmail + [','] + m.lcWeb + [',] + ;
							M.lcPrincipala + [,] + m.lcinactiv + [,] + m.lcId_util + [,?@pnIdAdresa); end;]

						llSucces = goExecutor.oExecuta(m.lcSql)
						If !m.llSucces
							lcMesaj = goExecutor.cEroare
							If m.llCallBack
								m.toCallBackForm.trace(m.lcMesaj)
							Endif
							* AMessagebox(m.lcMesaj, 0 + 48, _Screen.Caption )
							Exit
						Endif
					Endif && empty(m.pnIdAdresa)

				Endif && m.lcId_loc <> 'NULL'
			Endif && !found()

		Endif && !empty(m.lcAdresa)


	Endscan && tcCursorParteneri

	Use In (Select('cParteneriROA'))
	Use In (Select('cAdreseROA'))
	Select (m.lcSelect)

	Return m.llSucces
Endproc && CompleteazaParteneriROA

Procedure CompleteazaValutaROA
	Lparameters tcCursorValuta, toCallBackForm
	* tcCursorValuta: numele cursorului cValuta (valuta)
	* toCallBackForm: referinta la un formular cu metoda Trace(tcMesaj) optional

	Local lcMesaj, lcSelect, lcSql, lcValuta, llCallBack, llSucces, lnIdValuta
	lcSelect = Select()

	llCallBack = Type('toCallBackForm') = 'O' And Pemstatus(m.toCallBackForm, 'trace', 5)

	lcSql = [select id_valuta, nume_val as valuta from vnom_valute]
	llSucces = goExecutor.oExecuta(m.lcSql, 'cValuteROA')

	If !m.llSucces
		If m.llCallBack
			lcMesaj = goExecutor.cEroare
			m.toCallBackForm.trace(m.lcMesaj)
		Endif
		Return m.llSucces
	Endif

	Select (m.tcCursorValuta)
	Scan
		lcValuta = Alltrim(Upper(Strtran(valuta, ' ', '')))
		lnIdValuta = 0

		Wait Window 'Import valute ... Caut valuta' + Transform(Recno()) + '/' + Transform(Reccount()) Nowait

		Select cValuteROA
		If !Empty(m.lcValuta)
			Locate For Alltrim(Strtran(valuta, ' ', '')) = m.lcValuta
			If Found()
				lnIdValuta = cValuteROA.id_valuta
				Select (m.tcCursorValuta)
				Replace id_valuta With m.lnIdValuta
			Endif && found
		Endif && empty
	Endscan && tcCursorValuta

	Use In (Select('cValuteROA'))
	Select (m.lcSelect)

	Return m.llSucces
Endproc
   