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,59 +225,63 @@ 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
lcOrderNumber = CleanWebText(Transform(loOrder.Number)) If llContinue
lcOrderDate = ConvertWebDate(loOrder.Date) lcOrderNumber = CleanWebText(Transform(loOrder.Number))
ldOrderDate = String2Date(m.lcOrderDate, 'yyyymmdd') lcOrderDate = ConvertWebDate(loOrder.Date)
lcPrefix = lcPrefix + " " + lcOrderNumber ldOrderDate = String2Date(m.lcOrderDate, 'yyyymmdd')
lcPrefix = lcPrefix + " " + lcOrderNumber
*-- Procesare partener *-- Procesare partener
gcStepError = "" gcStepError = ""
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
lnIdAdresaFacturare = ProcessAddress(m.lnPartnerID, loOrder.billing) If llContinue
If Type('loOrder.shipping') = 'O' lnIdAdresaFacturare = ProcessAddress(m.lnPartnerID, loOrder.billing)
lnIdAdresaLivrare = ProcessAddress(m.lnPartnerID, loOrder.shipping) If Type('loOrder.shipping') = 'O'
Endif lnIdAdresaLivrare = ProcessAddress(m.lnPartnerID, loOrder.shipping)
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) llContinue = .F.
Return .F. Endif
Endif Endif
*-- Import comanda in Oracle *-- Import comanda in Oracle
lcSQL = "BEGIN PACK_IMPORT_COMENZI.importa_comanda(?lcOrderNumber, ?ldOrderDate, ?lnPartnerID, ?lcArticlesJSON, ?lnIdAdresaLivrare, ?lnIdAdresaFacturare, ?goSettings.IdPol, ?goSettings.IdSectie, ?@lnIdComanda); END;" If llContinue
lnResult = SQLExec(goConnectie, lcSQL) lcSQL = "BEGIN PACK_IMPORT_COMENZI.importa_comanda(?lcOrderNumber, ?ldOrderDate, ?lnPartnerID, ?lcArticlesJSON, ?lnIdAdresaLivrare, ?lnIdAdresaFacturare, ?goSettings.IdPol, ?goSettings.IdSectie, ?@lnIdComanda); END;"
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