@@ -1,7 +1,9 @@
Imports System . Data . SqlClient
Imports System . IO
Imports System . Net
Imports System . Reflection
Imports System . Web . Configuration
Imports io . konik . zugferd
Imports javax
Public Class cMSEAPI
@@ -14,10 +16,17 @@ Public Class cMSEAPI
Dim apiSettingsloaded As Boolean = False
Dim test As Boolean = False
Dim PDFRECHNUNGENPFAD As String = " "
Public PDFRECHNUNGENPFAD_VERARBEITUNG As String = " "
Public PDFRECHNUNGENPFAD_VERARBEITUNG_ZIEL As String = " "
Public ANLAGEN
Public ARCHIV
Sub New ( )
End Sub
Sub New ( program As String )
VERAG_PROG_ALLGEMEIN . cChilkat_Helper . UnlockCilkat ( )
API = SQL . loadDgvBySql ( " SELECT top(1) * FROM tblAPIEinstellungen WHERE api_program=' " & program & " ' and api_productive =' " & IIf ( VERAG_PROG_ALLGEMEIN . cAllgemein . TESTSYSTEM , " 0 " , " 1 " ) & " ' " , " ADMIN " )
@@ -33,6 +42,8 @@ Public Class cMSEAPI
rest . VerboseLogging = False
End If
PDFRECHNUNGENPFAD_VERARBEITUNG_ZIEL = Me . GET_PARAM_ByName ( " PDFRECHNUNGEN_VERARBEITUNG_ZIEL-PFAD " , VERAG_PROG_ALLGEMEIN . cAllgemein . TESTSYSTEM )
PDFRECHNUNGENPFAD_VERARBEITUNG = Me . GET_PARAM_ByName ( " PDFRECHNUNGEN_VERARBEITUNG-PFAD " , VERAG_PROG_ALLGEMEIN . cAllgemein . TESTSYSTEM )
PDFRECHNUNGENPFAD = Me . GET_PARAM_ByName ( " PDFRECHNUNGEN-PFAD " , VERAG_PROG_ALLGEMEIN . cAllgemein . TESTSYSTEM )
ANLAGEN = Me . GET_PARAM_ByName ( " ANLAGEN " , VERAG_PROG_ALLGEMEIN . cAllgemein . TESTSYSTEM )
ARCHIV = Me . GET_PARAM_ByName ( " ARCHIV " , VERAG_PROG_ALLGEMEIN . cAllgemein . TESTSYSTEM )
@@ -41,6 +52,8 @@ Public Class cMSEAPI
End Sub
Shared Function GET_PARAM_ByName ( tcParam_name , TESTSYSTEM ) As String
Dim SQL As New VERAG_PROG_ALLGEMEIN . SQL
Return SQL . getValueTxtBySql ( " SELECT TOP 1 [Param_value] FROM [tblPartnersystem_Paramter] WHERE Param_system='MSE' AND [Param_name]=' " & tcParam_name & " ' AND Param_testsystem = " & IIf ( TESTSYSTEM , 1 , 0 ) , , , SQL . GetNewOpenConnectionFMZOLL_SYSTEM ( TESTSYSTEM ) )
@@ -1078,7 +1091,7 @@ Public Class cMSEAPI
For Each r As DataRow In dt . Rows
If r ( " url " ) <> " " AndAlso r ( " name " ) <> " " AndAlso r ( " name " ) . contains ( " VAT " ) Then 'only VAT-Invoices
Dim inv As New cMSEInvoices ( r ( " name " ) , r ( " invoice_id " ) )
Dim inv As New cMSEInvoices ( r ( " name " ) , CInt ( r ( " invoice_id " ) ) )
If inv . daId Is Nothing Then 'verhindert unnötige Downloads
Dim filepath = VERAG_PROG_ALLGEMEIN . cFormularManager . getPDFViaSpirePDF_FromURLStream ( r ( " url " ) , r ( " name " ) , PDFRECHNUNGENPFAD , False )
If filepath <> " " AndAlso uploadToDs Then
@@ -1102,6 +1115,182 @@ Public Class cMSEAPI
End Function
Function isleernothing ( s ) As Object
If s Is DBNull . Value Then Return Nothing
If s . ToString . Trim = " " Then Return Nothing
Return s . trim
End Function
Public Function readAndSaveMSE ( objFileRead As StreamReader , fi As FileInfo , cnt As Integer ) As Boolean
Dim lngRecordCount As Long = 0
objFileRead . DiscardBufferedData ( )
objFileRead . BaseStream . Seek ( 0 , System . IO . SeekOrigin . Begin )
Dim counTrans As Integer = 0
Dim savedTrans As Integer = 0
Dim MDMEinarb As New cMDMEinarbeitung ( " MSE " , Now ( ) )
Do While ( objFileRead . Peek ( ) > - 1 )
Dim currentRow As String ( )
currentRow = objFileRead . ReadLine ( ) . Split ( " ; " )
lngRecordCount = lngRecordCount + 1
If lngRecordCount = 1 Then
If Not ( isleernothing ( ( currentRow ( 0 ) ) ) = " Controller ID " ) Then
Return False
End If
Else
Try
Dim invoiceID As Integer = 0
Dim invoiceDate As String
Dim customerID As Integer = 0
Dim total_amount_euro As Double = 0
Dim total_vat_amount_euro As Double = 0
' InvoiceID
If Not IsDBNull ( currentRow ( 2 ) ) Then
Integer . TryParse ( currentRow ( 2 ) . ToString ( ) , invoiceID )
End If
' InvoiceDate
If Not IsDBNull ( currentRow ( 3 ) ) Then
invoiceDate = currentRow ( 3 ) . 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 )
End If
If Not IsDBNull ( currentRow ( 36 ) ) Then
Double . TryParse ( currentRow ( 36 ) . ToString ( ) , total_vat_amount_euro )
End If
Dim inv As New cMSEInvoices ( invoiceID , invoiceDate , customerID )
If lngRecordCount = 2 Then
MDMEinarb . invoicedate = invoiceDate
End If
If inv . hasEntry Then
inv . total_amount_euro += total_amount_euro
inv . total_vat_amount_euro += total_vat_amount_euro
Else
inv . total_amount_euro = total_amount_euro
inv . total_vat_amount_euro = total_vat_amount_euro
End If
inv . name = " TEMP "
inv . msts_vat_number = - 1
inv . alternativeImport = True
inv . SAVEBYCUSTOMERIDDATE ( )
Console . WriteLine ( " MSE: " & isleernothing ( ( currentRow ( 1 ) ) ) & " - " & lngRecordCount & " - " & isleernothing ( ( currentRow ( 10 ) ) ) )
Catch ex As Exception
VERAG_PROG_ALLGEMEIN . cErrorHandler . ERR ( ex . Message , ex . StackTrace , System . Reflection . MethodInfo . GetCurrentMethod . Name )
End Try
End If
Loop
cnt = CInt ( lngRecordCount )
MDMEinarb . ds_total += cnt - 1
MDMEinarb . ds_count += counTrans
MDMEinarb . import_date = Now ( )
MDMEinarb . importfilename = fi . Name
If MDMEinarb . ds_total = MDMEinarb . ds_count Then
MDMEinarb . completed = True
MDMEinarb . completed_date = Now ( )
End If
MDMEinarb . SAVE ( )
objFileRead . Close ( )
Return True
End Function
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_
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 customerNo As Integer = 0
Dim invoiceNo As Integer = 0
Dim country As String = " "
If parts . Length >= 2 Then
Date . TryParse ( parts ( 0 ) . ToString ( ) , invoiceDate )
Integer . TryParse ( parts ( 1 ) . ToString ( ) , customerNo )
End If
' Optional invoice number
If parts . Length >= 3 Then
Integer . TryParse ( parts ( 2 ) . ToString ( ) , invoiceNo )
End If
'country
If parts . Length >= 4 Then
If parts ( 3 ) . Length = 2 Then
country = parts ( 3 )
End If
End If
If parts . Contains ( " VAT " ) Then
isVat = True
End If
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!!!!
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 " ) , dateiname )
DS . uploadDataToDATENSERVER ( PDFRECHNUNGENPFAD_VERARBEITUNG & " \ " & dateiname , , , , , , True )
SQL . doSQL ( " Update [tblMSEInvoices] SET [daId]=' " & DS . da_id & " ' where [name] = ' " & dateiname & " ' " , " FMZOLL " )
End If
End If
Catch ex As WebException
VERAG_PROG_ALLGEMEIN . cErrorHandler . ERR ( ex . Message , ex . StackTrace , System . Reflection . MethodInfo . GetCurrentMethod . Name )
End Try
End Function
Public Sub saveTransactions ( num As Integer , dt As DataTable , transactions As Chilkat . JsonArray , receiver As Integer , ByRef savedTrans As Integer , Optional ignorePurchaseDate As Boolean = False , Optional onlyBilledTransactions As Boolean = True )
Dim j As Integer = 0
@@ -1494,6 +1683,7 @@ Public Class cMSEInvoices
Property archiv As Boolean = False
Property archiviertDatum As Object = Nothing
Property UStVAn_ID As Object = Nothing
Property alternativeImport As Boolean = False
Public hasEntry = False
@@ -1503,11 +1693,31 @@ Public Class cMSEInvoices
End Sub
Sub New ( name , invoice_id )
Sub New ( name As String , invoice_id As Integer )
Me . name = name
Me . invoice_id = invoice_id
LOAD ( )
End Sub
Sub New ( invoice_id As Integer , invoice_date As String , customer_number As Integer )
Me . invoice_id = invoice_id
Me . invoice_date = invoice_date
Me . customer_number = customer_number
LOADBYCUSTOMERIDETC ( )
End Sub
' 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 )
Me . country = country
Me . invoice_date = invoice_date
Me . customer_number = customer_number
Me . invoice_nr = invoice_nr
LOADBYCOUNTRY ( )
End Sub
Function getParameterList ( ) As List ( Of VERAG_PROG_ALLGEMEIN . SQLVariable )
Dim list As New List ( Of VERAG_PROG_ALLGEMEIN . SQLVariable )
list . Add ( New VERAG_PROG_ALLGEMEIN . SQLVariable ( " name " , name ) )
@@ -1524,6 +1734,7 @@ Public Class cMSEInvoices
list . Add ( New VERAG_PROG_ALLGEMEIN . SQLVariable ( " archiviertDatum " , archiviertDatum ) )
list . Add ( New VERAG_PROG_ALLGEMEIN . SQLVariable ( " invoice_nr " , invoice_nr ) )
list . Add ( New VERAG_PROG_ALLGEMEIN . SQLVariable ( " UStVAn_ID " , UStVAn_ID ) )
list . Add ( New VERAG_PROG_ALLGEMEIN . SQLVariable ( " alternativeImport " , alternativeImport ) )
Return list
End Function
@@ -1542,11 +1753,38 @@ Public Class cMSEInvoices
Return SQL . doSQLVarList ( sqlstr , " FMZOLL " , , list )
End Function
'Dim inv As New cMSEInvoices(invoiceID, invoiceDate, customerID)
Public Function SAVEBYCUSTOMERIDDATE ( ) As Boolean
Dim list As List ( Of VERAG_PROG_ALLGEMEIN . SQLVariable ) = getParameterList ( )
Dim sqlstr = " BEGIN TRAN IF EXISTS(SELECT * FROM tblMSEInvoices WHERE invoice_date=@invoice_date AND invoice_id = @invoice_id AND customer_number = @customer_number) " &
" BEGIN " & getUpdateCmdBYCustomeridDate ( ) & " END " &
" Else " &
" BEGIN " & getInsertCmd ( ) & " END " &
" commit tran "
Return SQL . doSQLVarList ( sqlstr , " FMZOLL " , , list )
End Function
Public Function SAVEBYCountry ( ) As Boolean
Dim list As List ( Of VERAG_PROG_ALLGEMEIN . SQLVariable ) = getParameterList ( )
Dim sqlstr = " BEGIN TRAN IF EXISTS(SELECT * FROM tblMSEInvoices WHERE invoice_date=@invoice_date AND invoice_id = @invoice_id AND customer_number = @customer_number) " &
" BEGIN " & getUpdateCmdBYCustomeridDateCountry ( ) & " END " &
" Else " &
" BEGIN " & getInsertCmd ( ) & " END " &
" commit tran "
Return SQL . doSQLVarList ( sqlstr , " FMZOLL " , , list )
End Function
Public Sub LOAD ( )
Try
hasEntry = False
Using conn As SqlConnection = SQL . GetNewOpenConnectionFMZOLL ( )
Using cmd As New SqlCommand ( " SELECT * FROM tblMSEInvoices WHERE name=@nam e AND invoice_id = @invoice_id " , conn )
Using cmd As New SqlCommand ( " SELECT * FROM tblMSEInvoices WHERE invoice_date=@invoice_dat e AND invoice_id = @invoice_id " , conn )
cmd . Parameters . AddWithValue ( " @name " , name )
cmd . Parameters . AddWithValue ( " @invoice_id " , invoice_id )
Dim dr = cmd . ExecuteReader ( )
@@ -1572,6 +1810,71 @@ Public Class cMSEInvoices
End Sub
Public Sub LOADBYCUSTOMERIDETC ( )
Try
hasEntry = False
Using conn As SqlConnection = SQL . GetNewOpenConnectionFMZOLL ( )
Using cmd As New SqlCommand ( " SELECT * FROM tblMSEInvoices WHERE customer_number=@customer_number AND invoice_id = @invoice_id AND invoice_date = @invoice_date " , conn )
cmd . Parameters . AddWithValue ( " @customer_number " , customer_number )
cmd . Parameters . AddWithValue ( " @invoice_id " , invoice_id )
cmd . Parameters . AddWithValue ( " @invoice_date " , invoice_date )
Dim dr = cmd . ExecuteReader ( )
If dr . Read Then
For Each li In getParameterList ( )
Dim propInfo As PropertyInfo = Me . GetType . GetProperty ( li . Scalarvariable )
If dr . Item ( li . Text ) Is DBNull . Value Then
propInfo . SetValue ( Me , Nothing )
Else
propInfo . SetValue ( Me , dr . Item ( li . Text ) )
End If
Next
hasEntry = True
End If
dr . Close ( )
End Using
End Using
Catch ex As Exception
VERAG_PROG_ALLGEMEIN . cErrorHandler . ERR ( ex . Message , ex . StackTrace , System . Reflection . MethodInfo . GetCurrentMethod . Name )
End Try
End Sub
Public Sub LOADBYCOUNTRY ( )
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 )
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 ( )
Dim propInfo As PropertyInfo = Me . GetType . GetProperty ( li . Scalarvariable )
If dr . Item ( li . Text ) Is DBNull . Value Then
propInfo . SetValue ( Me , Nothing )
Else
propInfo . SetValue ( Me , dr . Item ( li . Text ) )
End If
Next
hasEntry = True
End If
dr . Close ( )
End Using
End Using
Catch ex As Exception
VERAG_PROG_ALLGEMEIN . cErrorHandler . ERR ( ex . Message , ex . StackTrace , System . Reflection . MethodInfo . GetCurrentMethod . Name )
End Try
End Sub
Public Function getUpdateCmd ( ) As String
Try
@@ -1592,6 +1895,47 @@ Public Class cMSEInvoices
Return " "
End Function
'Dim inv As New cMSEInvoices(invoiceID, invoiceDate, customerID)
Public Function getUpdateCmdBYCustomeridDateCountry ( ) As String
Try
Dim list As List ( Of VERAG_PROG_ALLGEMEIN . SQLVariable ) = getParameterList ( )
Dim str As String = " "
For Each i In list
If Not i . isPrimaryParam Then
str &= " [ " & i . Text & " ] = @ " & i . Scalarvariable & " , " '.Replace("-", "").Replace(" ", "") & ","
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 " )
Catch ex As Exception
VERAG_PROG_ALLGEMEIN . cErrorHandler . ERR ( ex . Message , ex . StackTrace , System . Reflection . MethodInfo . GetCurrentMethod . Name )
End Try
Return " "
End Function
Public Function getUpdateCmdBYCustomeridDate ( ) As String
Try
Dim list As List ( Of VERAG_PROG_ALLGEMEIN . SQLVariable ) = getParameterList ( )
Dim str As String = " "
For Each i In list
If Not i . isPrimaryParam Then
str &= " [ " & i . Text & " ] = @ " & i . Scalarvariable & " , " '.Replace("-", "").Replace(" ", "") & ","
End If
Next
str = str . Substring ( 0 , str . Length - 1 ) 'wg. ','
Return ( " UPDATE tblMSEInvoices SET " & str & " WHERE invoice_date=@invoice_date AND invoice_id = @invoice_id AND customer_number = @customer_number " )
Catch ex As Exception
VERAG_PROG_ALLGEMEIN . cErrorHandler . ERR ( ex . Message , ex . StackTrace , System . Reflection . MethodInfo . GetCurrentMethod . Name )
End Try
Return " "
End Function
Public Function getInsertCmd ( ) As String
Try