Bugfix Creditsafe-Report

This commit is contained in:
2023-06-19 11:25:48 +02:00
parent bb3ff3f077
commit 949362ad98
2 changed files with 85 additions and 39 deletions

View File

@@ -3,6 +3,7 @@ Imports System.Globalization
Imports System.IO Imports System.IO
Imports com.oracle.xmlns.internal.webservices.jaxws_databinding Imports com.oracle.xmlns.internal.webservices.jaxws_databinding
Imports com.sun.org.apache.bcel.internal.generic Imports com.sun.org.apache.bcel.internal.generic
Imports itextsharp.text.pdf
Imports java.rmi.server Imports java.rmi.server
Imports javax.swing.plaf Imports javax.swing.plaf
Imports SDL.EORI Imports SDL.EORI
@@ -2758,7 +2759,7 @@ Public Class usrCntlKundenuebersicht
Dim company As New cCreditSafeAPI.Company("", "", land, KUNDE_ERW.kde_CreditSaveNo, KUNDE_ERW.kde_CreditSaveId, Nothing, "", "", "", "", "", "", "", "") Dim company As New cCreditSafeAPI.Company("", "", land, KUNDE_ERW.kde_CreditSaveNo, KUNDE_ERW.kde_CreditSaveId, Nothing, "", "", "", "", "", "", "", "")
Dim pdfObject As Byte() = Nothing
If lblBonitaetsdatum._value <> Nothing Then If lblBonitaetsdatum._value <> Nothing Then
Dim lastChecked As Date = Date.ParseExact(lblBonitaetsdatum._value, "dd.MM.yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo) Dim lastChecked As Date = Date.ParseExact(lblBonitaetsdatum._value, "dd.MM.yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo)
@@ -2767,22 +2768,18 @@ Public Class usrCntlKundenuebersicht
If cs.checkDateOfLastRequest(company) < lastChecked Then If cs.checkDateOfLastRequest(company) < lastChecked Then
Dim a As MsgBoxResult = MsgBox("Seit der letzen Abfrage (" & lastChecked.ToShortDateString & ") wurde bei Creditsafe keine Änderung gemacht!" & vbNewLine & "Trotzdem Creditreport-Daten aktualisieren?", vbYesNo) Dim a As MsgBoxResult = MsgBox("Seit der letzen Abfrage (" & lastChecked.ToShortDateString & ") wurde bei Creditsafe keine Änderung gemacht!" & vbNewLine & "Trotzdem Creditreport-Daten aktualisieren?", vbYesNo)
If a = vbYes Then If a = vbYes Then
cs.getReport(company, True)
pdfObject = cs.getPDF(company) setCreditsafereportEntry(cs, company)
setCreditSafeEntry(company, pdfObject, kdNr)
End If End If
Else Else
cs.getReport(company, True) setCreditsafereportEntry(cs, company)
pdfObject = cs.getPDF(company)
setCreditSafeEntry(company, pdfObject, kdNr)
End If End If
Else Else
cs.getReport(company, True) setCreditsafereportEntry(cs, company)
pdfObject = cs.getPDF(company)
setCreditSafeEntry(company, pdfObject, kdNr)
End If End If
@@ -2971,4 +2968,20 @@ Public Class usrCntlKundenuebersicht
Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
genUIDEORIList(kdNr, "EORI") genUIDEORIList(kdNr, "EORI")
End Sub End Sub
Private Sub setCreditsafereportEntry(cs As cCreditSafeAPI, company As cCreditSafeAPI.Company)
Dim pdfObject As Byte() = Nothing
Dim failureDesc As String = ""
cs.getReport(company, True)
pdfObject = cs.getPDF(company, failureDesc)
If pdfObject Is Nothing Then
setCreditSafeEntry(company, Nothing, kdNr)
MsgBox("Fehler beim Erstellen des PDF-Dokuments" & vbNewLine & failureDesc)
Else
setCreditSafeEntry(company, pdfObject, kdNr)
End If
End Sub
End Class End Class

View File

@@ -5,9 +5,11 @@ Imports System.Text
Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls
Imports System.Windows.Forms Imports System.Windows.Forms
Imports Chilkat Imports Chilkat
Imports iTextSharp.text.pdf
Imports Microsoft.Office.Interop.Outlook Imports Microsoft.Office.Interop.Outlook
Imports Newtonsoft.Json Imports Newtonsoft.Json
Imports Spire.Pdf.Lists Imports Spire.Pdf.Lists
Imports Spire.Pdf.OPC
Imports VERAG_PROG_ALLGEMEIN.IDEV_Intrastat Imports VERAG_PROG_ALLGEMEIN.IDEV_Intrastat
Imports VERAG_PROG_ALLGEMEIN.TESTJSON Imports VERAG_PROG_ALLGEMEIN.TESTJSON
@@ -75,7 +77,7 @@ Public Class cCreditSafeAPI
Shared Function SendGetRequestWithAuthHeader(url As String, company As Company, acceptContentType As String, method As String, authenticationToken As String) As String Shared Function SendGetRequestWithAuthHeader(url As String, company As Company, acceptContentType As String, method As String, authenticationToken As String, ByRef failureDesc As String) As String
Try Try
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat() VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
@@ -91,6 +93,8 @@ Public Class cCreditSafeAPI
If (success <> True) Then If (success <> True) Then
Debug.WriteLine("ConnectFailReason: " & rest.ConnectFailReason) Debug.WriteLine("ConnectFailReason: " & rest.ConnectFailReason)
Debug.WriteLine(rest.LastErrorText) Debug.WriteLine(rest.LastErrorText)
failureDesc = rest.LastErrorText
Return failureDesc
End If End If
rest.ClearAllQueryParams() rest.ClearAllQueryParams()
@@ -115,8 +119,21 @@ Public Class cCreditSafeAPI
If (rest.LastMethodSuccess <> True) Then If (rest.LastMethodSuccess <> True) Then
Debug.WriteLine(rest.LastErrorText) Debug.WriteLine(rest.LastErrorText)
MsgBox(rest.LastErrorText) MsgBox(rest.LastErrorText)
failureDesc = rest.LastErrorText
Return failureDesc
Else Else
Return pdfData.ToString If (rest.ResponseStatusCode <> 200) Then
Dim sbErrorText As New Chilkat.StringBuilder
sbErrorText.AppendBd(pdfData, "utf-8", 0, 0)
failureDesc = sbErrorText.GetAsString()
Return failureDesc & vbNewLine & url
Else
Return pdfData.GetEncoded("base64")
End If
End If End If
Else Else
@@ -124,7 +141,8 @@ Public Class cCreditSafeAPI
responseJson = rest.FullRequestNoBody(method, url) responseJson = rest.FullRequestNoBody(method, url)
If (rest.LastMethodSuccess <> True) Then If (rest.LastMethodSuccess <> True) Then
Debug.WriteLine(rest.LastErrorText) Debug.WriteLine(rest.LastErrorText)
MsgBox(rest.LastErrorText) failureDesc = rest.LastErrorText
Return failureDesc
Else Else
Return responseJson Return responseJson
@@ -156,9 +174,9 @@ Public Class cCreditSafeAPI
Shared Function searchCompanies(company As Company, ByRef dataTable As DataTable) As String Shared Function searchCompanies(company As Company, ByRef dataTable As DataTable) As String
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat() VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
Dim failureDesc As String
Dim myUrl As String = API_STRING & "/v1/companies" Dim myUrl As String = API_STRING & "/v1/companies"
Dim jsonRespString = SendGetRequestWithAuthHeader(myUrl, company, "application/json", "GET", token) Dim jsonRespString = SendGetRequestWithAuthHeader(myUrl, company, "application/json", "GET", token, failureDesc)
Dim json As New Chilkat.JsonObject Dim json As New Chilkat.JsonObject
@@ -250,6 +268,7 @@ Public Class cCreditSafeAPI
End Function End Function
Shared Function getReport(ByRef company As Company, withPDF As Boolean) As String 'Shared Function getReport(ByRef company As Company, withPDF As Boolean, ByRef bytes As Byte()) As String Shared Function getReport(ByRef company As Company, withPDF As Boolean) As String 'Shared Function getReport(ByRef company As Company, withPDF As Boolean, ByRef bytes As Byte()) As String
Dim failureDesc As String
Dim myUrl As String = API_STRING & "/v1/companies/" & company.creditSafeId & "/" Dim myUrl As String = API_STRING & "/v1/companies/" & company.creditSafeId & "/"
If company.country = "DE" Then If company.country = "DE" Then
'Abfragen für DE benötigen einen Reason-Code 'Abfragen für DE benötigen einen Reason-Code
@@ -257,7 +276,8 @@ Public Class cCreditSafeAPI
myUrl &= "&?language=DE&?template=full" myUrl &= "&?language=DE&?template=full"
Else Else
myUrl &= "?language=DE&?template=full" 'myUrl &= "?language=DE&?template=full"
myUrl &= "?template=full"
End If End If
Dim acceptContentType = "application/json" Dim acceptContentType = "application/json"
@@ -267,7 +287,7 @@ Public Class cCreditSafeAPI
Dim jsonRespString = SendGetRequestWithAuthHeader(myUrl, Nothing, acceptContentType, "GET", token) Dim jsonRespString = SendGetRequestWithAuthHeader(myUrl, Nothing, acceptContentType, "GET", token, failureDesc)
Dim json As New Chilkat.JsonObject Dim json As New Chilkat.JsonObject
Dim success As Boolean = json.Load(jsonRespString) Dim success As Boolean = json.Load(jsonRespString)
@@ -410,11 +430,13 @@ Public Class cCreditSafeAPI
company.csFailure = json.StringOf("details") company.csFailure = json.StringOf("details")
End If End If
Return "ohnePDF" Return failureDesc
End Function End Function
Shared Function getPDF(ByRef company As Company) As Byte() Shared Function getPDF(ByRef company As Company, ByRef failure As String) As Byte()
If company IsNot Nothing AndAlso company.creditSafeId <> "" Then
Dim myUrl As String = API_STRING & "/v1/companies/" & company.creditSafeId & "/" Dim myUrl As String = API_STRING & "/v1/companies/" & company.creditSafeId & "/"
If company.country = "DE" Then If company.country = "DE" Then
@@ -423,17 +445,29 @@ Public Class cCreditSafeAPI
myUrl &= "&?language=DE&?template=full" myUrl &= "&?language=DE&?template=full"
Else Else
myUrl &= "?language=DE&?template=full" myUrl &= "?template=full"
End If End If
Dim acceptContentType = "application/pdf" Dim acceptContentType = "application/pdf"
Dim pdfData2 As New Chilkat.BinData
Dim jsonRespString = SendGetRequestWithAuthHeader(myUrl, Nothing, acceptContentType, "GET", token) Dim failureDesc As String
Dim jsonRespString = SendGetRequestWithAuthHeader(myUrl, Nothing, acceptContentType, "GET", token, failureDesc)
If jsonRespString IsNot Nothing Then failure = failureDesc
Return Convert.FromBase64String(jsonRespString) If jsonRespString IsNot Nothing And failure = "" Then
Dim success = pdfData2.AppendEncoded(jsonRespString, "base64")
If success Then
Return pdfData2.GetBinary
End If End If
'Return Convert.FromBase64String(test)
End If
Else
Return Nothing
End If
End Function End Function
@@ -456,7 +490,6 @@ Public Class cCreditSafeAPI
If company.Street <> "" Then rest.AddQueryParam("street", company.Street) If company.Street <> "" Then rest.AddQueryParam("street", company.Street)
If company.Postalcode <> "" Then rest.AddQueryParam("postCode", company.Postalcode) If company.Postalcode <> "" Then rest.AddQueryParam("postCode", company.Postalcode)
If company.City <> "" Then rest.AddQueryParam("city", company.City) If company.City <> "" Then rest.AddQueryParam("city", company.City)
End If End If
@@ -467,9 +500,9 @@ Public Class cCreditSafeAPI
Shared Function checkDateOfLastRequest(company As Company) As Date Shared Function checkDateOfLastRequest(company As Company) As Date
Dim failureDesc As String
Dim myUrl As String = API_STRING & "/v1/companies" Dim myUrl As String = API_STRING & "/v1/companies"
Dim jsonRespString = SendGetRequestWithAuthHeader(myUrl, company, "application/json", "GET", token) Dim jsonRespString = SendGetRequestWithAuthHeader(myUrl, company, "application/json", "GET", token, failureDesc)
Dim json As New Chilkat.JsonObject Dim json As New Chilkat.JsonObject
Dim success As Boolean = json.Load(jsonRespString) Dim success As Boolean = json.Load(jsonRespString)