Update VFP integration with improved error handling and settings management

- Add output/ directory to .gitignore to exclude generated JSON files
- Fix ApplicationSetup.prg parameter handling with LPARAMETERS and proper validation
- Update gomag-adapter.prg to use global settings object and clean old JSON files
- Enhance sync-comenzi-web.prg with Oracle integration improvements
- Add Visual FoxPro project files (roawebcomenzi.PJT/.pjx)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-11 17:01:00 +03:00
parent d1858f86b6
commit 5d43509987
8 changed files with 135 additions and 1368 deletions

View File

@@ -18,21 +18,13 @@ Local lcStatusText, lnStatusCode, loError
Local lnLimit, lnCurrentPage, llHasMorePages, loAllJsonData, lnTotalPages, lnTotalProducts
Local lcOrderApiUrl, loAllOrderData, lcOrderCsvFileName, lcOrderJsonFileName
Local ldStartDate, lcStartDateStr
Local lcIniFile, loSettings
Local lcIniFile
LOCAL llGetProducts, llGetOrders
PRIVATE gcAppPath, loJsonData, gcLogFile, gnStartTime, gnProductsProcessed, gnOrdersProcessed
PRIVATE loJsonData, gcLogFile, gnStartTime, gnProductsProcessed, gnOrdersProcessed
gcAppPath = ADDBS(JUSTPATH(SYS(16,0)))
SET DEFAULT TO (m.gcAppPath)
lcPath = gcAppPath + 'nfjson;'
SET PATH TO (m.lcPath) ADDITIVE
SET PROCEDURE TO utils.prg ADDITIVE
SET PROCEDURE TO ApplicationSetup.prg ADDITIVE
SET PROCEDURE TO nfjsonread.prg ADDITIVE
SET PROCEDURE TO nfjsoncreate.prg ADDITIVE
*-- Include utilitare necesare
SET PROCEDURE TO regex.prg ADDITIVE
*-- Initializare logging si statistici
gnStartTime = SECONDS()
@@ -47,39 +39,49 @@ IF !DIRECTORY(lcOutputDir)
MKDIR (lcOutputDir)
ENDIF
*-- Creare și inițializare clasa setup aplicație
*-- Creare si initializare clasa setup aplicatie
LOCAL loAppSetup
loAppSetup = CREATEOBJECT("ApplicationSetup", gcAppPath)
*-- Setup complet cu validare
IF !loAppSetup.Initialize()
LogMessage("EROARE: Setup-ul aplicației a eșuat sau necesită configurare!", "ERROR", gcLogFile)
LogMessage("EROARE: Setup-ul aplicatiei a esuat sau necesita configurare!", "ERROR", gcLogFile)
RETURN .F.
ENDIF
*-- Obținere setări din clasă
loSettings = loAppSetup.GetSettings()
*-- Configurare API din settings.ini
lcApiBaseUrl = loSettings.ApiBaseUrl
lcOrderApiUrl = loSettings.OrderApiUrl
lcApiKey = loSettings.ApiKey
lcApiShop = loSettings.ApiShop
lcUserAgent = loSettings.UserAgent
lcContentType = loSettings.ContentType
lnLimit = loSettings.Limit
llGetProducts = loSettings.GetProducts
llGetOrders = loSettings.GetOrders
lcApiBaseUrl = goSettings.ApiBaseUrl
lcOrderApiUrl = goSettings.OrderApiUrl
lcApiKey = goSettings.ApiKey
lcApiShop = goSettings.ApiShop
lcUserAgent = goSettings.UserAgent
lcContentType = goSettings.ContentType
lnLimit = goSettings.Limit
llGetProducts = goSettings.GetProducts
llGetOrders = goSettings.GetOrders
lnCurrentPage = 1 && Pagina de start
llHasMorePages = .T. && Flag pentru paginare
loAllJsonData = NULL && Obiect pentru toate datele
*-- Calculare data pentru ultimele X zile (din settings.ini)
ldStartDate = DATE() - loSettings.OrderDaysBack
ldStartDate = DATE() - goSettings.OrderDaysBack
lcStartDateStr = TRANSFORM(YEAR(ldStartDate)) + "-" + ;
RIGHT("0" + TRANSFORM(MONTH(ldStartDate)), 2) + "-" + ;
RIGHT("0" + TRANSFORM(DAY(ldStartDate)), 2)
*******************************************
*-- Sterg fisiere JSON comenzi anterioare
lcDirJson = gcAppPath + "output\"
lcJsonPattern = m.lcDirJson + goSettings.JsonFilePattern
lnJsonFiles = ADIR(laJsonFiles, lcJsonPattern)
FOR lnFile = 1 TO m.lnJsonFiles
lcFile = m.lcDirJson + laJsonFiles[m.lnFile,1]
IF FILE(m.lcFile)
DELETE FILE (m.lcFile)
ENDIF
ENDFOR
*******************************************
*-- Verificare daca avem WinHttp disponibil
TRY
loHttp = CREATEOBJECT("WinHttp.WinHttpRequest.5.1")
@@ -254,7 +256,7 @@ ENDIF
*-- SECTIUNEA COMENZI - se executa doar daca llGetOrders = .T.
IF llGetOrders
LogMessage("[ORDERS] =======================================", "INFO", gcLogFile)
LogMessage("[ORDERS] RETRIEVING ORDERS FROM LAST " + TRANSFORM(loSettings.OrderDaysBack) + " DAYS", "INFO", gcLogFile)
LogMessage("[ORDERS] RETRIEVING ORDERS FROM LAST " + TRANSFORM(goSettings.OrderDaysBack) + " DAYS", "INFO", gcLogFile)
LogMessage("[ORDERS] Start date: " + lcStartDateStr, "INFO", gcLogFile)
LogMessage("[ORDERS] =======================================", "INFO", gcLogFile)
@@ -432,7 +434,7 @@ CloseLog(gnStartTime, gnProductsProcessed, gnOrdersProcessed, gcLogFile)
PROCEDURE SaveProductsArray
PARAMETERS tloAllData, tcFileName
LOCAL lcJsonContent, lnPropCount, lnIndex, lcPropName, loProduct
LOCAL lcJsonContent, lnPropCount, lnIndex, lcPropName, loProduct, lcProductJson
*-- Incepe array-ul JSON
lcJsonContent = "[" + CHR(13) + CHR(10)
@@ -451,7 +453,7 @@ IF TYPE('tloAllData.products') = 'O'
lcJsonContent = lcJsonContent + "," + CHR(13) + CHR(10)
ENDIF
*-- Serializeaza produsul cu nfjsoncreate
*-- Serializeaza produsul cu nfjsoncreate standard
lcProductJson = nfJsonCreate(loProduct, .F.)
lcJsonContent = lcJsonContent + " " + lcProductJson
ENDIF
@@ -470,7 +472,7 @@ ENDPROC
PROCEDURE SaveOrdersArray
PARAMETERS tloAllData, tcFileName
LOCAL lcJsonContent, lnPropCount, lnIndex, lcPropName, loOrder
LOCAL lcJsonContent, lnPropCount, lnIndex, lcPropName, loOrder, lcOrderJson
*-- Incepe array-ul JSON
lcJsonContent = "[" + CHR(13) + CHR(10)
@@ -489,7 +491,7 @@ IF TYPE('tloAllData.orders') = 'O'
lcJsonContent = lcJsonContent + "," + CHR(13) + CHR(10)
ENDIF
*-- Serializeaza comanda cu nfjsoncreate
*-- Serializeaza comanda cu nfjsoncreate standard
lcOrderJson = nfJsonCreate(loOrder, .F.)
lcJsonContent = lcJsonContent + " " + lcOrderJson
ENDIF
@@ -504,6 +506,7 @@ STRTOFILE(lcJsonContent, tcFileName)
ENDPROC
*-- Functie pentru unirea produselor din toate paginile (versiune simpla)
PROCEDURE MergeProducts
PARAMETERS tloAllData, tloPageData