diff --git a/VERAG_PROG_ALLGEMEIN/Schnittstellen/MSE/cMSEAPI.vb b/VERAG_PROG_ALLGEMEIN/Schnittstellen/MSE/cMSEAPI.vb index ac234dae..f6401477 100644 --- a/VERAG_PROG_ALLGEMEIN/Schnittstellen/MSE/cMSEAPI.vb +++ b/VERAG_PROG_ALLGEMEIN/Schnittstellen/MSE/cMSEAPI.vb @@ -1153,6 +1153,7 @@ Public Class cMSEAPI Dim invoiceID As Integer = 0 Dim invoiceDate As String Dim customerID As Integer = 0 + Dim Country As String = "" Dim total_amount_euro As Double = 0 Dim total_vat_amount_euro As Double = 0 @@ -1166,22 +1167,30 @@ Public Class cMSEAPI invoiceDate = currentRow(3).ToString() End If + ' Country + If Not IsDBNull(currentRow(13)) Then + Country = currentRow(13).ToString() + End If + ' CustomerID If Not IsDBNull(currentRow(4)) Then Integer.TryParse(currentRow(4).ToString(), customerID) End If ' Amounts - If Not IsDBNull(currentRow(37)) Then - Double.TryParse(currentRow(37).ToString(), total_amount_euro) + If Not IsDBNull(currentRow(35)) Then + Double.TryParse(currentRow(35).ToString(), total_amount_euro) End If If Not IsDBNull(currentRow(36)) Then - Double.TryParse(currentRow(36).ToString(), total_vat_amount_euro) + Double.TryParse(currentRow(36).ToString().Replace(".", ","), total_vat_amount_euro) End If - Dim inv As New cMSEInvoices(invoiceID, invoiceDate, customerID) + + + Dim inv As New cMSEInvoices(invoiceDate, Country, customerID) + inv.invoice_id = invoiceID If lngRecordCount = 2 Then MDMEinarb.invoicedate = invoiceDate @@ -1235,28 +1244,36 @@ Public Class cMSEAPI Public Function importInvoicesPDF_alternative(dateiname As String, uploadToDs As Boolean) As String 'if the API do not return any invoices, we get the invoices via Filetransfer! Try - 'Aufbau Dateiname -> Rechnungsdatum_Kundennummer_ + 'Aufbau Dateiname -> Rechnungsdatum_RechnungsNr_Kundennummer_ Dim isVat As Boolean = False Dim nameString = checkNullStr(dateiname) Dim nameWithoutExt As String = System.IO.Path.GetFileNameWithoutExtension(nameString) Dim parts() As String = nameWithoutExt.Split("_"c) - Dim invoiceDate As Date = Date.MinValue + Dim invoiceDate As String Dim customerNo As Integer = 0 Dim invoiceNo As Integer = 0 Dim country As String = "" If parts.Length >= 2 Then + Dim rawDate As String = parts(0) - Date.TryParse(parts(0).ToString(), invoiceDate) - Integer.TryParse(parts(1).ToString(), customerNo) + Dim parsedDate As Date + If Date.TryParseExact(rawDate, "yyyyMMdd", + Globalization.CultureInfo.InvariantCulture, + Globalization.DateTimeStyles.None, + parsedDate) Then + + invoiceDate = parsedDate.ToString("yyyy-MM-dd") + End If + Integer.TryParse(parts(1).ToString(), invoiceNo) End If ' Optional invoice number If parts.Length >= 3 Then - Integer.TryParse(parts(2).ToString(), invoiceNo) + Integer.TryParse(parts(2).ToString(), customerNo) End If 'country If parts.Length >= 4 Then @@ -1271,16 +1288,23 @@ Public Class cMSEAPI If isVat Then - Dim inv As New cMSEInvoices(invoiceDate, customerNo, invoiceNo, country) - inv.name = nameString - If Not inv.archiv AndAlso isVat Then inv.SAVEBYCountry() 'bereits archiverte REchnungen nicht überschreiben!!!! + Dim inv As New cMSEInvoices(invoiceDate, country, customerNo) - If inv.daId Is Nothing AndAlso uploadToDs AndAlso isVat Then + If inv.hasEntry Then - Dim DS As New VERAG_PROG_ALLGEMEIN.cDATENSERVER("MDM", "MDM_DATEN", "MSE", Now.Year, Now.ToString("yyyyMMdd"), dateiname) - DS.uploadDataToDATENSERVER(PDFRECHNUNGENPFAD_VERARBEITUNG & "\" & dateiname,,,,,, True) - SQL.doSQL("Update [tblMSEInvoices] SET [daId]='" & DS.da_id & "' where [name] = '" & dateiname & "'", "FMZOLL") + inv.name = nameWithoutExt & ".pdf" + inv.invoice_nr = invoiceNo + + If Not inv.archiv AndAlso isVat Then inv.SAVEBYCountry() 'bereits archiverte REchnungen nicht überschreiben!!!! + + If inv.daId Is Nothing AndAlso uploadToDs AndAlso isVat Then + + Dim DS As New VERAG_PROG_ALLGEMEIN.cDATENSERVER("MDM", "MDM_DATEN", "MSE", Now.Year, Now.ToString("yyyyMMdd"), nameWithoutExt & ".pdf") + DS.uploadDataToDATENSERVER(PDFRECHNUNGENPFAD_VERARBEITUNG & "\" & nameWithoutExt & ".pdf",,,,,, True) + SQL.doSQL("Update [tblMSEInvoices] SET [daId]='" & DS.da_id & "' where [name] = '" & nameWithoutExt & ".pdf" & "'", "FMZOLL") + End If End If + End If @@ -1709,11 +1733,10 @@ Public Class cMSEInvoices ' Dim inv As New cMSEInvoices(invoiceDate, customerNo, invoiceNo, country) - Sub New(invoice_date As String, customer_number As Integer, invoice_nr As Integer, country As String) + Sub New(invoice_date As String, country As String, customer_number As Integer) Me.country = country Me.invoice_date = invoice_date Me.customer_number = customer_number - Me.invoice_nr = invoice_nr LOADBYCOUNTRY() End Sub @@ -1845,11 +1868,10 @@ Public Class cMSEInvoices Try hasEntry = False Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL() - Using cmd As New SqlCommand("SELECT * FROM tblMSEInvoices WHERE customer_number=@customer_number AND country = @country AND invoice_date = @invoice_date AND invoice_nr = @invoice_nr", conn) + Using cmd As New SqlCommand("SELECT * FROM tblMSEInvoices WHERE customer_number=@customer_number AND country = @country AND invoice_date = @invoice_date", conn) cmd.Parameters.AddWithValue("@customer_number", customer_number) cmd.Parameters.AddWithValue("@country", country) cmd.Parameters.AddWithValue("@invoice_date", invoice_date) - cmd.Parameters.AddWithValue("@invoice_nr", invoice_nr) Dim dr = cmd.ExecuteReader() If dr.Read Then For Each li In getParameterList() @@ -1908,7 +1930,7 @@ Public Class cMSEInvoices End If Next str = str.Substring(0, str.Length - 1) 'wg. ',' - Return (" UPDATE tblMSEInvoices SET " & str & " WHERE customer_number=@customer_number AND country = @country AND invoice_date = @invoice_date AND invoice_nr = @invoice_nr ") + Return (" UPDATE tblMSEInvoices SET " & str & " WHERE customer_number=@customer_number AND country = @country AND invoice_date = @invoice_date") Catch ex As Exception VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)