This commit is contained in:
2026-03-11 13:45:21 +02:00
parent 69841872d1
commit 902f99c507

View File

@@ -201,18 +201,20 @@ Endfunc
*-- Procesare comanda web - logeaza O SINGURA LINIE per comanda *-- Procesare comanda web - logeaza O SINGURA LINIE per comanda
*-- Format: [N/Total] OrderNumber P:PartnerID A:AddrFact/AddrLivr -> OK/ERR details *-- Format: [N/Total] OrderNumber P:PartnerID A:AddrFact/AddrLivr -> OK/ERR details
*-- NOTA: VFP nu permite RETURN in TRY/CATCH, se foloseste flag llContinue
Function ProcessWebOrder Function ProcessWebOrder
Lparameters loOrder, tnIndex, tnTotal Lparameters loOrder, tnIndex, tnTotal
Local llSuccess, lcOrderNumber, lcOrderDate, lnPartnerID, lcArticlesJSON Local llSuccess, lcOrderNumber, lcOrderDate, lnPartnerID, lcArticlesJSON
Local lcSQL, lnResult, lcErrorDetails, lnIdComanda, llSucces Local lcSQL, lnResult, lcErrorDetails, lnIdComanda
Local ldOrderDate, loError Local ldOrderDate, loError
Local lnIdAdresaFacturare, lnIdAdresaLivrare Local lnIdAdresaFacturare, lnIdAdresaLivrare
Local lcPrefix, lcSummary, lcErrDetail Local lcPrefix, lcSummary, lcErrDetail, llContinue
lnIdAdresaLivrare = NULL lnIdAdresaLivrare = NULL
lnIdAdresaFacturare = NULL lnIdAdresaFacturare = NULL
lnIdComanda = 0 lnIdComanda = 0
llSucces = .T. llSuccess = .F.
llContinue = .T.
lnPartnerID = 0 lnPartnerID = 0
lcOrderNumber = "?" lcOrderNumber = "?"
@@ -223,10 +225,11 @@ Function ProcessWebOrder
*-- Validare comanda *-- Validare comanda
If !ValidateWebOrder(loOrder) If !ValidateWebOrder(loOrder)
LogMessage(lcPrefix + " ? -> ERR VALIDARE: date obligatorii lipsa", "ERROR", gcLogFile) LogMessage(lcPrefix + " ? -> ERR VALIDARE: date obligatorii lipsa", "ERROR", gcLogFile)
Return .F. llContinue = .F.
Endif Endif
*-- Extragere date comanda *-- Extragere date comanda
If llContinue
lcOrderNumber = CleanWebText(Transform(loOrder.Number)) lcOrderNumber = CleanWebText(Transform(loOrder.Number))
lcOrderDate = ConvertWebDate(loOrder.Date) lcOrderDate = ConvertWebDate(loOrder.Date)
ldOrderDate = String2Date(m.lcOrderDate, 'yyyymmdd') ldOrderDate = String2Date(m.lcOrderDate, 'yyyymmdd')
@@ -237,45 +240,48 @@ Function ProcessWebOrder
lnPartnerID = ProcessPartner(loOrder.billing) lnPartnerID = ProcessPartner(loOrder.billing)
If lnPartnerID <= 0 If lnPartnerID <= 0
LogMessage(lcPrefix + " -> ERR PARTENER: " + Iif(Empty(gcStepError), "nu s-a putut procesa", gcStepError), "ERROR", gcLogFile) LogMessage(lcPrefix + " -> ERR PARTENER: " + Iif(Empty(gcStepError), "nu s-a putut procesa", gcStepError), "ERROR", gcLogFile)
Return .F. llContinue = .F.
Endif
Endif Endif
*-- Adrese *-- Adrese + JSON articole
If llContinue
lnIdAdresaFacturare = ProcessAddress(m.lnPartnerID, loOrder.billing) lnIdAdresaFacturare = ProcessAddress(m.lnPartnerID, loOrder.billing)
If Type('loOrder.shipping') = 'O' If Type('loOrder.shipping') = 'O'
lnIdAdresaLivrare = ProcessAddress(m.lnPartnerID, loOrder.shipping) lnIdAdresaLivrare = ProcessAddress(m.lnPartnerID, loOrder.shipping)
Endif Endif
*-- Construire JSON articole
lcArticlesJSON = BuildArticlesJSON(loOrder.items) lcArticlesJSON = BuildArticlesJSON(loOrder.items)
If Empty(m.lcArticlesJSON) If Empty(m.lcArticlesJSON)
LogMessage(lcPrefix + " P:" + Transform(lnPartnerID) + " -> ERR JSON_ARTICOLE", "ERROR", gcLogFile) LogMessage(lcPrefix + " P:" + Transform(lnPartnerID) + " -> ERR JSON_ARTICOLE", "ERROR", gcLogFile)
Return .F. llContinue = .F.
Endif
Endif Endif
*-- Import comanda in Oracle *-- Import comanda in Oracle
If llContinue
lcSQL = "BEGIN PACK_IMPORT_COMENZI.importa_comanda(?lcOrderNumber, ?ldOrderDate, ?lnPartnerID, ?lcArticlesJSON, ?lnIdAdresaLivrare, ?lnIdAdresaFacturare, ?goSettings.IdPol, ?goSettings.IdSectie, ?@lnIdComanda); END;" lcSQL = "BEGIN PACK_IMPORT_COMENZI.importa_comanda(?lcOrderNumber, ?ldOrderDate, ?lnPartnerID, ?lcArticlesJSON, ?lnIdAdresaLivrare, ?lnIdAdresaFacturare, ?goSettings.IdPol, ?goSettings.IdSectie, ?@lnIdComanda); END;"
lnResult = SQLExec(goConnectie, lcSQL) lnResult = SQLExec(goConnectie, lcSQL)
*-- Construire linie sumar cu ID-uri adrese
lcSummary = lcPrefix + " P:" + Transform(lnPartnerID) + ; lcSummary = lcPrefix + " P:" + Transform(lnPartnerID) + ;
" A:" + Transform(Nvl(lnIdAdresaFacturare, 0)) + "/" + Transform(Nvl(lnIdAdresaLivrare, 0)) " A:" + Transform(Nvl(lnIdAdresaFacturare, 0)) + "/" + Transform(Nvl(lnIdAdresaLivrare, 0))
If lnResult > 0 And Nvl(m.lnIdComanda, 0) > 0 If lnResult > 0 And Nvl(m.lnIdComanda, 0) > 0
LogMessage(lcSummary + " -> OK ID:" + Transform(m.lnIdComanda), "INFO", gcLogFile) LogMessage(lcSummary + " -> OK ID:" + Transform(m.lnIdComanda), "INFO", gcLogFile)
Return .T. llSuccess = .T.
Else Else
lcErrorDetails = GetOracleErrorDetails() lcErrorDetails = GetOracleErrorDetails()
lcErrDetail = ClassifyImportError(lcErrorDetails) lcErrDetail = ClassifyImportError(lcErrorDetails)
CollectFailedSKUs(lcErrorDetails) CollectFailedSKUs(lcErrorDetails)
LogMessage(lcSummary + " -> ERR " + lcErrDetail, "ERROR", gcLogFile) LogMessage(lcSummary + " -> ERR " + lcErrDetail, "ERROR", gcLogFile)
Return .F. Endif
Endif Endif
Catch To loError Catch To loError
LogMessage(lcPrefix + " -> ERR EXCEPTIE: " + loError.Message, "ERROR", gcLogFile) LogMessage(lcPrefix + " -> ERR EXCEPTIE: " + loError.Message, "ERROR", gcLogFile)
Return .F.
Endtry Endtry
Return llSuccess
Endfunc Endfunc
*-- Validare comanda web *-- Validare comanda web