SET DELETED ON
SET ANSI ON
SET EXACT ON 
SET SAFETY OFF 
CLOSE DATABASES 
SET CENTURY ON 
SET DATE DMY 
SET NULLDISPLAY TO ''

CT_SUCCES = 1
CT_INSUCCES = -1
crlf = CHR(13) + CHR(10)
gnAn = 2022
gnLuna = 6
gnIdUtil = -3
glEMama = .T.
gnIdFirma = 110
gcCondSucursala = []
gnIdSucursala = m.gnIdFirma
gcS = 'ROMFAST'
gcFirma = 'ROMFAST'
gcUserName = m.gcS
gcNumeProgram=[ROACONT]
gcAppName = [ROACONT]
glLunaInchisa = .F.
glEMama = .F.

Declare nror[65000]
buton = 1
gnButon = 1
pnButon = 1

LOCAL lcPath
PRIVATE gcAppPath 

gcAppPath = [D:\ROA\ROACONT\]
Set Default To (gcAppPath)
lcPath = gcAppPath + 'Date;' + ;
	gcAppPath + 'Include;' + ;
	gcAppPath + 'FERESTRE;' + ;
	gcAppPath + 'GRAFICE;' + ;
	gcAppPath + 'CLASE;' + ;
	gcAppPath + 'MENIURI;' + ;
	gcAppPath + 'PROGRAME;' + ;
	gcAppPath + 'RAPOARTE;' + ;
	gcAppPath + 'COMUN\CLASE;' + ;
	gcAppPath + 'COMUN\FERESTRE;' + ;	
	gcAppPath + 'COMUN\PROGRAME;' + ;
	gcAppPath + 'COMUN\GRAFICE;' + ;
	gcAppPath + 'COMUN\RAPOARTE;' + ;
    gcAppPath + 'COMUN\UTILE\CALENDAR;' + ;	
    gcAppPath + 'COMUN\UTILE\CTL32;' + ;	
	gcAppPath + 'COMUN\UTILE\HPDF;' + ;		
	gcAppPath + 'COMUN\UTILE\HPDF\REPORTOUTPUT;' + ;			
	gcAppPath + 'COMUN\UTILE\WEB;' + ;
	gcAppPath + 'COMUN\UTILE\NFJSON;' + ;	
	gcAppPath + 'COMUN\UTILE\NFXML;' + ;		
	gcAppPath + 'COMUN\UTILE\EXCEL;' + ;	
	Addbs(Substr(gcAppPath,1,Rat([\],gcAppPath,2)))+[COMUNROA\]
	
SET PATH TO &lcPath ADDITIVE 

lcLastSetClassLib=Set("CLASSLIB")
lcMainClassLib="clase\cont2000"



*CLASE__________________________________________________________
Set Classlib To (lcMainClassLib) Additive
Set Classlib To appwiz Additive
Set Classlib To CAUT Additive
* SET CLASSLIB TO FERESTREBAZA ADDITIVE
Set Classlib To BAZA Additive
Set Classlib To contab Additive
Set Classlib To comun Additive
Set Classlib To registry Additive
Set Classlib To cauta_alfa_forms.vcx Additive
Set Classlib To obalanta Additive
Set Classlib To ocriterii.vcx Additive
Set Classlib To ctl32_statusbar.vcx Additive
Set Classlib To ctl32_common.vcx Additive
Set Classlib To ctl32_structs.vcx Additive
Set Classlib To ctl32_progressbar.vcx Additive
*!*	SET CLASSLIB TO ctl32_scontainer.vcx additive


*PROCEDURI______________________________________________________
Set Procedure To PROCEDURI Additive
Set Procedure To pmenu Additive
Set Procedure To proceduri_comune Additive
Set Procedure To mesaje Additive
Set Procedure To acces_meniu Additive
Set Procedure To quitapp Additive
Set Procedure To init_program Additive
Set Procedure To oproceduri_maintenance.PRG Additive
Set Procedure To gridproc Additive
Set Procedure To proceduri_excel Additive
Set Procedure To oserii_numere.PRG Additive
Set Procedure To cauta_alfa Additive
Set Procedure To oproceduri_parteneri Additive
Set Procedure To oproceduri_incasari Additive
Set Procedure To oserii_numere Additive
Set Procedure To wwconfig Additive
Set Procedure To oexport Additive
SET PROCEDURE TO ocasabanca ADDITIVE 
SET PROCEDURE TO importfromxlsx ADDITIVE 
SET PROCEDURE TO appendfromxlsx.prg ADDITIVE 
SET PROCEDURE TO overificari.prg ADDITIVE 
SET PROCEDURE TO onomenclatoare.prg ADDITIVE 
SET PROCEDURE TO excelxml.prg ADDITIVE 


SET PROCEDURE TO saft_d406.prg ADDITIVE 

&& CLASE ORACLE
Set Classlib To DECABAZA Additive
Set Classlib To onomenclatoare Additive
Set Classlib To oparteneri Additive
Set Classlib To OCASABANCA Additive
Set Classlib To OVANZCUMP Additive
Set Classlib To oCompensari Additive
Set Classlib To oRapoarte_cont Additive
Set Classlib To oSit_Op Additive
Set Classlib To overificari Additive
Set Classlib To oteste Additive
Set Classlib To omodificari Additive
Set Classlib To ooptiuni Additive
Set Classlib To ointroduceri_cont Additive
Set Classlib To onote_contabile Additive
Set Classlib To odebcred Additive
Set Classlib To ferestre_oracle Additive
Set Classlib To caut_ora Additive
Set Classlib To otoolbar Additive
Set Classlib To inchideri_sal Additive
Set Classlib To serii_numere Additive
Set Classlib To contabilitate_rapoarte Additive
Set Classlib To oconversii Additive
Set Classlib To oactualizari Additive
Set Classlib To anaf_efactura Additive

&& CLASE UTILITARE
Set Classlib To Messagebox Additive
SET CLASSLIB TO wwdialogs ADDITIVE 
SET CLASSLIB TO orapoarte.vcx additive
SET CLASSLIB TO orapoarte_contabilitate.vcx additive
SET CLASSLIB TO accessibility.vcx ADDITIVE 
SET CLASSLIB TO _calendar.vcx ADDITIVE 
SET CLASSLIB TO orapoarte_comun.vcx ADDITIVE 
SET CLASSLIB TO saft_d406.vcx ADDITIVE 

&& PROCEDURI ORACLE
Set Procedure To GENCURSOR.PRG Additive
Set Procedure To OPROCEDURI_COMUNE.PRG Additive
Set Procedure To OINIT_OPTIUNI.PRG Additive
Set Procedure To updateserver.PRG Additive
Set Procedure To oCompensari.PRG Additive
Set Procedure To oSituatii_Operative.PRG Additive
Set Procedure To oOperatii_comune.PRG Additive

Set Procedure To OCONT2003.PRG Additive
Set Procedure To OPROCEDURI_aMS.PRG Additive
Set Procedure To oparteneri.PRG Additive
Set Procedure To orapoarte.PRG Additive
Set Procedure To orap_trezorerie Additive
Set Procedure To ocautare Additive
Set Procedure To omeniu_initializari Additive
Set Procedure To osecurity Additive
Set Procedure To oheader Additive
Set Procedure To orefaceri Additive
Set Procedure To oproceduri_casademarcat Additive
Set Procedure To controllerecr Additive
Set Procedure To oproceduri_comune_imob.PRG Additive
Set Procedure To oproceduri_conversie.PRG Additive
Set Procedure To odocumente.PRG Additive
Set Procedure To oproceduri_actualizari.PRG Additive
SET PROCEDURE TO orapoarte_dinamice.prg additive
SET PROCEDURE TO update_imob.prg ADDITIVE 
SET PROCEDURE TO oproceduri_import.prg ADDITIVE 
Set Procedure To wwutils.PRG Additive
Set Procedure To wwxmlhttp.PRG Additive
Set Procedure To ini.PRG Additive
Set Procedure To regex.PRG Additive
Set Procedure To validare.PRG Additive && validare cif
Set Procedure To oproceduri_evolutie Additive
Set Procedure To oproceduri_decont Additive

Set Procedure To proceduri_rapoarte.PRG Additive
SET PROCEDURE TO anaf_efactura.prg ADDITIVE


*!* modificare v 2.0.95
SET PROCEDURE TO iniacces.prg ADDITIVE 
SET PROCEDURE TO oupdate.prg additive
SET PROCEDURE TO procese.prg additive
SET PROCEDURE TO version.prg additive
SET PROCEDURE TO xmlaccess.prg additive
SET PROCEDURE TO xmlparser.prg additive
SET PROCEDURE TO filebringer.prg additive
SET PROCEDURE TO wwcodeupdate.prg additive
SET PROCEDURE TO wwhttp.prg ADDITIVE 
SET PROCEDURE TO wwapi.prg ADDITIVE 
*!* modificare v 2.0.95^

*!*	modificare	v 2.5.28
Declare Integer GetPrivateProfileString In WIN32API ;
	string, String, String, String @, Integer, String
Declare Integer WritePrivateProfileString In Win32Api ;
	string, String, String, String
Declare Integer CopyFile In WIN32API ;
	STRING  lpExistingFileName,;
	STRING  lpNewFileName,;
	INTEGER bFailIfExists
Declare Integer URLDownloadToFile In urlmon.Dll;
	INTEGER pCaller, String szURL, String szFileName,;
	INTEGER dwReserved, Integer lpfnCB
Declare Integer PathFileExists In shlwapi;
	STRING pszPath
*!*	modificare	v 2.5.28	^	

If Type('goApi') = 'U'
	Public goApi
	goApi = Newobject("wwAPI", "wwAPI.prg")
ENDIF

set procedure to oinit_optiuni.prg additive
set procedure to oproceduri_comune.prg additive

PRIVATE gnHandle, goExecutor, goConn, goFirma, goCalendar, gcAcces, goApp, DIRGEN, gcBasePath, gcTempPath
Private gcGeneralIniFile
DIRGEN = [D:\ROA\]
gcBasePath = dirgen
gcGeneralIniFile = DIRGEN + "settings.ini"
gcSettingsFile = m.gcGeneralIniFile
gcTempPath = Addbs(shortpath(goApi.GetTempPath())) + gcS + [\] && WWAPI.PRG
If !Directory(gcTempPath)
	Md (gcTempPath)
Endif

Private poLog,goLog && obiect pt logarea mesajelor sistemului
poLog = Newobject("Log_Mesaje","Log_Mesaje.prg")
goLog = poLog

goApp=Createobject("wzApplication")

gnHandle = 0

goExecutor = createobject("oExecutor")
goConn = createobject("oConn")
lcHost = INPUTBOX('Host','Host','ROA_ROMFAST')
lcSchema = INPUTBOX('Schema','Schema', m.gcS)
lcPassword = INPUTBOX('Password','Password','ROMFASTSOFT')
gcS = ALLTRIM(m.lcSchema)
gcUserName = m.gcS
goConn.Connect(m.lcHost, m.lcSchema, m.lcPassword)

gcAcces=[1;2;3;4;5;6;7;8;]

goFirma = null 
llSucces = goExecutor.oExecuta("select * from syn_v_nom_firme where schema = ?gcS", "cFirma")

SELECT cFirma
gnIdFirma = id_firma
gnIdSucursala = null
gcFirma = ALLTRIM(firma)

IF m.llSucces 
	SELECT cFirma
	SCATTER NAME goFirma
ELSE
	goFirma = CREATEOBJECT('custom')
	goFirma.addproperty('cod_fiscal', 'RO1879855')	
	goFirma.addproperty('schema', m.gcS)	
	goFirma.addproperty('firma', m.gcS)			
ENDIF 
lcDeclarant = Alltrim(goFirma.declarant)
AddProperty(goFirma, 'nume_declarant', m.lcDeclarant)
AddProperty(goFirma, 'prenume_declarant', '')
lnNraparitie = At(" ", m.lcDeclarant)
If lnNraparitie > 0
	goFirma.nume_declarant = Substr(m.lcDeclarant, 1, m.lnNraparitie)
	goFirma.prenume_declarant = Substr(m.lcDeclarant, m.lnNraparitie + 1)
Endif

USE IN (SELECT('cFirma'))

goCalendar = null
llSucces = goExecutor.oExecuta('SELECT anul, luna, tva_incasare FROM calendar WHERE an*12+luna = (select MAX(an*12+luna) FROM calendar)', 'cCalendar')
IF m.llSucces
	SELECT cCalendar
	GO TOP 
	gnAn = anul
	gnLuna = luna
	SCATTER NAME goCalendar
ENDIF 
USE IN (SELECT('cCalendar'))

_SCREEN.Caption = ALLTRIM(goFirma.firma) + " " + PADL(m.gnLuna,2, "0") + "/" + PADL(gnAn,4,"0") 

CREATE CURSOR dual (dummy c(10))
INSERT INTO dual (dummy) VALUES ("")
	
actualizeaza_optiuni()
Do optiuni_firma IN oinit_optiuni.prg

&& setez variabilele de sesiune pe server

lcSql = [begin pack_sesiune.set_Id_Util(?gnIdUtil); end;]
llSucces = goExecutor.oExecuta(lcSql)

lcSql = [begin pack_sesiune.setluna(?gnLuna); pack_sesiune.setan(?gnAn); end;]
llSucces = goExecutor.oExecuta(lcSql)

lcSql = [begin pack_sesiune.setlunabal(?gnLuna); pack_sesiune.setanbal(?gnAn); end;]
llSucces = goExecutor.oExecuta(lcSql)

lcSql = [begin pack_contafin.SET_DATA_RON(?gcS); end;]
llSucces = goExecutor.oExecuta(lcSql)

lcSql = [begin pack_sesiune.set_data_ron(?gcS); end;]
llSucces = goExecutor.oExecuta(lcSql)

lcSql = [begin pack_contafin.set_id_sucursala(?gnIdSucursala); end;]
llSucces = goExecutor.oExecuta(lcSql)

lcSql = [begin pack_contafin.set_id_firma(?gnIdFirma); end;]
llSucces = goExecutor.oExecuta(lcSql)

	
* lcCommand = INPUTBOX('Command', 'Command', 'DO FORM d:\roa\roacont\ferestre\frm_import_note_a4200.scx')
lnOptiune = xmenu('SAFT;Import extrase;XML eFactura;Import eFactura;SPV;Chatbot')
lcCommand = ''
DO CASE 
	CASE m.lnOptiune = 1
		CD [D:\ROA\COMUNROA\dist406]
		lcCommand = INPUTBOX('Command', 'Command', 'do viz_saft_d406 in saft_d406.prg')
	CASE m.lnOptiune = 2
		lcCommand = INPUTBOX('Command', 'Command', 'do form frm_import_extrase_banca.scx')
	CASE m.lnOptiune = 3
		lcCommand = INPUTBOX('Command', 'Command', 'do xmlefactura.prg')
	CASE m.lnOptiune = 4
		lcCommand = INPUTBOX('Command', 'Command', 'do vizImportEFactura in import_efactura.prg')
	CASE m.lnOptiune = 5
		lcCommand = INPUTBOX('Command', 'Command', 'do viz_spv in anaf_efactura.prg')		
	CASE m.lnOptiune = 6
		lcCommand = INPUTBOX('Command', 'Command', 'do form frm_chatbot.scx')
*!*			lcCommand = INPUTBOX('Command', 'Command', 'do chatbot.prg')				
		
ENDCASE 
IF !EMPTY(m.lcCommand)
	&lcCommand
ENDIF 
