Files
tasks/programe/proceduri.prg
2026-04-21 15:46:20 +03:00

390 lines
14 KiB
Plaintext

*!* 04.03.2013
*!* marius.mutu
*!* genereaza_xml_roa
*!* se retin numele xml-urilor pentru clientii roa in settings.ini in sectiunea [folder]
#Define crlf Chr(13) + Chr(10)
Procedure EditTask
Parameters tnId
Private poRec
lcSql = [select * from tasks where ] + Iif(!Empty(tnId), [ id = ?tnId], [1=2])
lcCursor = Sys(2015)
lnSucces = goExecutor.oexecute(lcSql, lcCursor)
If lnSucces > 0
Select (lcCursor)
Scatter Name poRec Memo
Do Form frm_adaugare_task
Endif
Return lnSucces
Endproc
*****==============================================================
Procedure EditLucrare
Parameters tnIdLucrare
Local lnSucces, lcCursor, lcSql
Private poRec
*!* IF EMPTY(tnid)
*!* endif
lcSql = [select * from luc_vlucrari_tot where ] + ;
Iif(!Empty(tnIdLucrare), [ id = ?tnIdLucrare ], [1=2])
lcCursor = Sys(2015)
lnSucces = goExecutor.oexecute(lcSql, lcCursor)
If lnSucces > 0
Select (lcCursor)
Scatter Name poRec Memo
poRec.datal = Ttod(poRec.datal)
Do Form frm_lucrare_noua
Endif
Return lnSucces
Endproc
**************************
**************************
* se apeleaza tasks.exe cu parametru din Windows Task Scheduller
* se genereaza xml pentru toti clientii ROA
**************************
Procedure genereaza_xml_roa_tot
Local lcSql, llAuto, llSilent
Text To lcSql
SELECT DISTINCT CUSTOMER_ID, CUSTOMER
FROM (select CUSTOMER_ID, CUSTOMER, DATA_PLEC
from VSC_PROGRAME_CLIENTI t
WHERE PROGRAM = 'ROACONT'
AND DATA_PLEC BETWEEN TRUNC(SYSDATE) - 60 AND SYSDATE)
order by CUSTOMER
Endtext
executaSql(lcSql, [cCustomersTemp], .T.)
llSilent = .T.
llAuto = .T.
Select cCustomersTemp
Scan
Wait Window Transform(Recno()) + Transform(Reccount()) + ' ' + cCustomersTemp.customer Nowait
Select cCustomersTemp
Do genereaza_xml_roa With customer_id, customer, m.llSilent, m.llAuto In proceduri.prg
Endscan
Use In (Select('cCustomersTemp'))
Endproc && genereaza_xml_roa_tot
***
Procedure genereaza_xml_roa
Lparameters tnCustomerId, tcName, tlSilent, tlAuto
* tlSilent: .T. = nu arata dialogul SaveAs pentru xml, decat daca nu are configurat numele fisierului
* tlAuto: .T. = genereaza automat numele fisierului xml, daca nu este configurat in settings.ini
*!* 09.08.2010
*!* marius.mutu
*!* nu se mai creeaza vechiul fisier xml cu aplicatiile, ci doar noul fisier
*!* 28.06.2012
*!* arhivele nu mai au extensia .exe, ci .zip ( am adaugat lcExtensieArhive )
*!* 20.07.2012
*!* am adaugat tcName
Local lcSql, lcfile, cVersiune, lcClipText, lcSir, lcFisier, lcDir, lcFisVersDif
Local lcfileVersiuniMax, lnSucces, lnCustomerId, liat, lcFileAfis, lcExtensieArhive
Local laEroare[1], lcVersiune, x, lcXMLFolder
Local llSilent, llAuto
llSilent = m.tlSilent
llAuto = m.tlAuto
lcExtensieArhive = [.ZIP]
liat = 0
lnCustomerId = m.tnCustomerId
*!* 20.07.2012 : am adaugat m.lcCustomerName
lcCustomerName = m.tcName
lcClipText = []
lcSir = []
lcFisier = []
lcDir = []
lcFisVersDif = []
*!* 25.01.2011
*!* x = SQLConnect("JCSSERVER","SOFT_SERII","123")
x = SQLConnect(goApp.cHostSerii, goApp.cUsernameSerii, goApp.cPasswordSerii)
If x < 0
Aerror(laEroare)
Messagebox(laEroare(3))
Return
Endif
*!* 25.01.2011 ^
*!* 17.06.2011 : am adaugat id_grup_clienti = 1 ( clienti ROA )
lcSql = [select DISTINCT customer_id, NUME, ID_PROGRAM, (CASE WHEN Upper(PROGRAM) ] + ;
[LIKE 'INDEX%' THEN 'MANUAL' ELSE PROGRAM END) AS PROGRAM from vgen_programe ] + ;
[where customer_id = ] + Alltrim(Str(m.lnCustomerId)) + [ and id_grup_clienti = 1]
lnSucces = SQLExec(x, lcSql, "crsProgsTemp1")
If lnSucces < 0
Return
Endif
SQLDisconnect(x)
*!* selectie combobox - un client, programele cu licenta pentru client
*!* 17.06.2011 : am adaugat comun ca sa pot face ROASTART.xml si <server>.XML
*!* 20.07.2012 : am inlocuit crs2xml.id cu m.lnCustomerId
executaSql([select 0 as ales, v.customer, v.program, v.versiune, v.versiune_maxima, ] + ;
[v.id, v.customer_id, v.comun from vsc_versiune_max_inst_dv v ] + ;
[where v.customer_id = ] + Alltrim(Str(m.lnCustomerId)), "crsprogstemp2", .T.)
*!* selectie combobox - un client, programele cu licenta pentru client ^
executaSql([select * from programs], "crsPrograms", .T.)
executaSql([select * from sc_versiune_programe], "crsVersProg", .T.)
*** directorul xml_aplicatii
lcXMLFolder = Nvl(readINI(goApp.cinifile, "folder", "xml_aplicatii"), "")
If Empty(m.lcXMLFolder)
llSilent = .F.
ENDIF
*** 04.03.2013
*** citesc numele fisierului xml pentru client din clientului din settings.ini
lcCustomerNameSaved = Nvl(readINI(goApp.cinifile, "folder", "xml_aplicatii_" + Alltrim(Str(m.lnCustomerId))), "")
If !Empty(Nvl(m.lcCustomerNameSaved, ''))
lcCustomerName = Juststem(m.lcCustomerNameSaved)
ELSE
IF m.llAuto
lcCustomerName = 'customer_' + ALLTRIM(STR(m.lnCustomerId))
WriteINI(goApp.cinifile, "folder", "xml_aplicatii_" + Alltrim(Str(m.lnCustomerId)), m.lcCustomerName)
ELSE
llSilent = .F.
ENDIF
Endif
If !m.llSilent
*!* 20.07.2012 : am inlocuit crs2xml.Name cu m.lcCustomerName
lcfile = Putfile("Alegeti calea", Iif(Empty(m.lcXMLFolder), "", Addbs(m.lcXMLFolder)) + Upper(Alltrim(Strtran(m.lcCustomerName, ' ', ''))) + '.xml', 'xml')
If !Empty(m.lcfile)
writeINI(goApp.cinifile, 'folder', "xml_aplicatii_" + Alltrim(Str(m.lnCustomerId)), Juststem(m.lcfile))
Endif
Else
lcfile = Addbs(m.lcXMLFolder) + Upper(Alltrim(Strtran(m.lcCustomerName, ' ', ''))) + '.xml'
Endif
*!* 17.06.2011 : am adaugat comun ca sa pot face ROASTART.xml si <server>.XML
Select a.nume As customer, a.Program, b.versiune, b.versiune_maxima, a.customer_id, a.id_program, b.comun ;
From crsprogstemp2 b ;
INNER Join crsProgsTemp1 a On a.customer_id = b.customer_id And b.Id = a.id_program ;
Order By 7 Desc, 2 ;
Into Cursor crsXmlOut
Select Program As Item, versiune As Version, ;
'\_ARHIVE\' + Alltrim(Program) + '\' + Alltrim(Program) + '-' + Alltrim(versiune) + lcExtensieArhive As fileURL, ;
'' As usermsg ;
From crsXmlOut Where comun = 0 ;
Into Cursor crsXmlOutNew
*!* 17.06.2011 : am adaugat comun pentru ROASTART<server>.xml ( trebuie redenumit manual in ROASTART.xml )
*!* 20.07.2012 : am modificat coloanele item ( program as item ) si fileURL ( '\_ARHIVE\' + Alltrim(Program) + '\' + Alltrim(Program) + '-' + Alltrim(versiune) + lcExtensieArhive )
Select Iif(At([USERREPORTS], Alltrim(Program)) <> 0 And At([-], Program, 1) <> 0, Substr(Alltrim(Program), 1, At([-], Alltrim(Program), 1) - 1), Alltrim(Program)) As Item, versiune As Version, ;
'\_ARHIVE\' + Iif(At([USERREPORTS], Alltrim(Program)) <> 0, [USERREPORTS], Alltrim(Program)) + '\' + Alltrim(Program) + '-' + Alltrim(versiune) + lcExtensieArhive As fileURL, ;
'' As usermsg ;
From crsXmlOut Where comun = 1 ;
Into Cursor crsXmlOutNewS
*SELECT c.customer, c.program, c.versiune, c.customer_id FROM crsprogstemp2 c ;
JOIN crsprograms p ON p.id = c.id ORDER BY 2 ;
WHERE !EMPTY(NVL(c.versiune,[])) ;
INTO CURSOR crsProgLic
Select crsXmlOut
lcClipText = lcClipText + Alltrim(customer) + crlf + "VERSIUNI EXISTENTE: "
lcVersiune = ""
Set Textmerge On To Memvar lcVersiune Noshow
Set Textmerge Delimiters To '{{', '}}'
\<?XML Version='1.0'?>
Select crsXmlOut
*SELECT crsProgLic
Scan For customer_id = lnCustomerId
\<{{Alltrim(Program)}}>
\<codeupdate>
\<Version>{{Alltrim(versiune)}}</Version>
\<fileURL>{{'\_ARHIVE\' + Alltrim(Program) + '\' + Alltrim(Program) + '-' + Alltrim(versiune) + lcExtensieArhive}}</fileURL>
\<usermsg>S-a gasit {{Alltrim(Program)}} versiunea {{Alltrim(versiune)}}. Programul va incepe procedurile de actualizare !</usermsg>
\</codeupdate>
\</{{Alltrim(Program)}}>
lcClipText = lcClipText + Alltrim(Program) + '-' + Alltrim(versiune) + ', '
Endscan
Set Textmerge To
*!* 09.02.2010
*!* Cursortoxml("crsXmlOutNew", Addbs(Justpath(m.lcfile)) + Juststem(m.lcfile) + '.new.xml', 1, 0+512, 0, "1")
Cursortoxml("crsXmlOutNew", Addbs(Justpath(m.lcfile)) + Juststem(m.lcfile) + '.xml', 1, 0 + 512, 0, "1")
*!* 17.06.2011
Cursortoxml("crsXmlOutNewS", Addbs(Justpath(m.lcfile)) + 'ROASTART_' + Juststem(m.lcfile) + '.xml', 1, 0 + 512, 0, "1")
* Creez si un ROASTART.xml pentru firmele de pe ROA_ROMFAST, pentru ca ele descarca ROASTART.xml direct de pe ROA_CENTRAL, nu de pe ROA_ROMFAST
If Upper(Juststem(m.lcfile)) = 'ROMFAST'
Cursortoxml("crsXmlOutNewS", Addbs(Justpath(m.lcfile)) + 'ROASTART' + '.xml', 1, 0 + 512, 0, "1")
Endif
*!* 17.06.2011 ^
*!* Strtofile(lcVersiune, m.lcfile)
*!* 09.02.2010 ^
*** salvez director xml aplicatii
writeINI(goApp.cinifile, 'folder', 'xml_aplicatii', Justpath(m.lcfile))
*Use In (Select("crsProgLic"))
Use In (Select("crsprograms"))
Use In (Select("crsProgsTemp1"))
Use In (Select("crsProgsTemp2"))
Use In (Select("crsxmlout"))
Use In (Select("crsxmloutnew"))
Use In (Select("crsxmloutnewS")) && 17.06.2011
Use In (Select("crsVersProg"))
_Cliptext = Nvl(lcClipText, [])
Endproc && genereaza_xml_roa
*******************************************
Procedure genereaza_xml_contafin
Local lcAppPath, lcCheckSum, lcCustomerId, lcFileExe, lcFileZip, lcFisiere, lcSql, lcText, lcWhere
Local lcXML, lcXML2, lcfile, lnHandle, lnSucces, lcAppPath
lcXMLPath = readINI(goApp.cinifile, "folder", "contafin_arhive")
lcXMLPath = Addbs(m.lcXMLPath)
*!* lnHandle = SQLConnect('roa_romfast','soft','soft')
*!* If lnHandle < 0
*!* ProcessError()
*!* Return
*!* Endif
Text To lcSql Noshow Textmerge
SELECT vp.name as program, vc.versiune_curenta as versiune, vc.customer_id
From vprograme vp Left Join sc_versiune_programe vc On vc.id_program = vp.Id
Left Join programs_groups pg On pg.id_program = vp.Id
Where vc.appupdate = 1
Endtext
*!* lnSucces = SQLExec(lnHandle, lcSql, "cProgrameTemp")
*!* If lnSucces < 0
*!* ProcessError()
*!* Return
*!* Endif
executaSql(lcSql, "cProgrameTemp", .T.)
*!* 28.10.2010
Create Cursor crsCheckSum (fisier c(250), checksum c(100))
*!* 28.10.2010 ^
*!* <program>APPUPDATE</program>
*!* <fisier>http://83.103.197.79:3002/contafinupdate/default.aspx/update/download/|licenta|/appupdate-1.0.3.exe</fisier>
*!* <log>http://83.103.197.79:3002/contafinupdate/default.aspx/update/download/|licenta|/changelog_appupdate.txt</log>
*!* <versiune>1.0.3</versiune>
lcFisiere = ''
Select Distinct customer_id From cProgrameTemp Into Cursor cCustomers Order By customer_id
Select cCustomers
Scan
If !Empty(Nvl(customer_id, 0))
lcWhere = "inlist(nvl(customer_id,0), 0, " + Alltrim(Str(customer_id)) + ")"
lcCustomerId = Alltrim(Str(customer_id))
Else
lcWhere = "NVL(customer_id,0) = 0"
lcCustomerId = ""
Endif
Select Program, versiune, ;
[http://83.103.197.79:3002/contafinupdate/default.aspx/update/download/|licenta|/] + Alltrim(Program) + [-] + Alltrim(versiune) + [.exe] As fisier, ;
[http://83.103.197.79:3002/contafinupdate/default.aspx/update/download/|licenta|/changelog_] + Alltrim(Program) + [.txt] As Log, ;
Space(100) As checksum ;
From cProgrameTemp ;
Where &lcWhere ;
Order By Program ;
Into Cursor crsXML Readwrite
Select crsXML
Scan
lcFileExe = lcXMLPath + Alltrim(Program) + [-] + Alltrim(versiune) + [.exe]
lcFileZip = lcXMLPath + Alltrim(Program) + [-] + Alltrim(versiune) + [.zip]
lcfile = lcFileExe
If !File(lcFileExe)
If File(lcFileZip)
lcfile = lcFileZip
Endif
Endif
Wait Window 'CUSTOMER_ID ' + lcCustomerId + ' ' + Transform(Recno()) + '/' + Transform(Reccount()) + ' ' + lcfile Nowait
If File(lcfile)
Select crsCheckSum
Locate For Upper(Alltrim(fisier)) = Upper(Alltrim(lcfile))
If Found()
lcCheckSum = checksum
Else
lcText = Filetostr(lcfile)
lcCheckSum = Sys(2007, lcText, 0, 1)
lcText = ""
Insert Into crsCheckSum (fisier, checksum) Values (lcfile, lcCheckSum)
Endif
*** completez checksum-ul si schimb extensia fisierului din exe in zip, daca este cazul
Replace checksum With lcCheckSum, fisier With Forceext(Alltrim(fisier), Justext(m.lcfile)) In crsXML
Else
Messagebox('Nu exista fisierul ' + lcfile, 0 + 48, _Screen.Caption)
Endif
Endscan
lcXML = lcXMLPath + 'contafin' + Iif(!Empty(lcCustomerId), '_' + lcCustomerId, '') + '.xml' && CONTAFIN.XML, CONTAFIN_26.XML
lcXML2 = lcXMLPath + 'contafin_local' + Iif(!Empty(lcCustomerId), '_' + lcCustomerId, '') + '.xml' && CONTAFIN.XML, CONTAFIN_26.XML
Cursortoxml('crsXML', lcXML, 1, 512, 0, "1")
Select crsXML
Replace All fisier With Strtran(fisier, '83.103.197.79:3002', '10.0.20.122:81'), Log With Strtran(Log, '83.103.197.79:3002', '10.0.20.122:81')
Cursortoxml('crsXML', lcXML2, 1, 512, 0, "1")
Use In crsXML
lcFisiere = lcFisiere + lcXML + crlf
Endscan
Use In (Select('cCustomers'))
Use In (Select('cProgrameTemp'))
Use In (Select('crsCheckSum'))
Messagebox('S-au creat fisierele ' + lcFisiere)
Endproc && genereaza_xml_contafin
*************************************************************
*** converteste un nume de script in elementele componente
*************************************************************
Procedure ParseScriptName
Lparameters tcScript, tcScriptPrefix, tdScriptDate, tnScriptSeq, tcScriptType
Local lcScript, lnAn, lnLuna, lnPos, lnZi
lcScript = Juststem(m.tcScript)
tcScriptPrefix = ""
tdScriptDate = {}
tnScriptSeq = 0
tcScriptType = ""
If !Empty(m.lcScript)
tcScriptPrefix = Getwordnum(m.lcScript, 1, '_')
lnAn = Val(Getwordnum(m.lcScript, 2, '_'))
lnLuna = Val(Getwordnum(m.lcScript, 3, '_'))
lnZi = Val(Getwordnum(m.lcScript, 4, '_'))
tdScriptDate = Date(m.lnAn, m.lnLuna, m.lnZi)
tnScriptSeq = Int(Val(Juststem(Getwordnum(m.lcScript, 5, '_'))))
lnPos = At('_', m.lcScript, 5)
If m.lnPos > 0
tcScriptType = Juststem(Substr(m.lcScript, m.lnPos + 1))
Endif
Endif
Endproc && ParseScriptName