234 lines
7.5 KiB
Plaintext
234 lines
7.5 KiB
Plaintext
' ArticleExists(Identifier: String)
|
|
' ---------------------------------------------------------
|
|
' Findet Artikelnummer anhand von versch. Kriterien
|
|
' - Artikel-Nummer, Alternative Artikel-Nummer, EAN-Code, Seriennummer
|
|
' - Gibt die Zeile im Grid zurück in der Artikel das erste Mal gefunden wurde
|
|
'
|
|
' Rückgabewert: ArticleRow: Int
|
|
' ---------------------------------------------------------
|
|
' Version Date: 04.01.2021
|
|
|
|
Const ARTICLE_EXISTS_NO_STOCK = -99
|
|
Const ARTICLE_EXISTS_NO_SERIALNUMBER = -98
|
|
Const ARTICLE_EXISTS_NO_ARTICLE_EAN = -97
|
|
Const ARTICLE_EXISTS_NO_REGEX_MATCH = -96
|
|
|
|
Function ArticleExists(Identifier)
|
|
ArticleExists = 0
|
|
HasError = False
|
|
CURRENT_SERIALNUMBER = ""
|
|
|
|
Set mywin = CWLStart.CurrentModule.Windows.Item(WINDOW_ID)
|
|
Set Grid = mywin.Controls.Item(GRID_ID).Grid
|
|
|
|
' ===================== ARTIKEL NUMMER / EAN-CODE =====================
|
|
SQL = ""
|
|
' Artikelnummer / EAN-Code / Alternative Artikelnummer
|
|
SQL = SQL & "((C002 = '" & Identifier & "') Or (C075 = '" & Identifier & "') Or (C114 = '" & Identifier & "')) AND "
|
|
' Artikel darf nicht inaktiv sein
|
|
SQL = SQL & "(c038 IS NULL) "
|
|
' Nach Mandant und Wirtschaftsjahr filtern
|
|
SQL = SQL & SQLQuery_BasicWhere
|
|
|
|
Set ResultArtikel = CWLStart.CurrentCompany.SearchRecord(TABLE_21, SQL)
|
|
|
|
If DEBUG_ON = True Then
|
|
AddDebugLine "Searching for Article by ArticleNo/EAN-Code.. " & vbNewline & vbNewline
|
|
AddDebugLine "Result Columns: " & ResultArtikel & vbNewline
|
|
AddDebugLine "Result Rows: " & ResultArtikel.RowCount & vbNewline
|
|
AddDebugLine "SQL: " & SQL
|
|
|
|
ShowDebugBox "ArticleExists"
|
|
End If
|
|
|
|
' ===================== SERIENNUMMER =====================
|
|
SQL = ""
|
|
' Artikelnummer
|
|
SQL = SQL & "(C068 = '" & Identifier & "') AND "
|
|
' Artikel darf nicht inaktiv sein
|
|
SQL = SQL & "(c038 IS NULL) "
|
|
' Nach Mandant und Wirtschaftsjahr filtern
|
|
SQL = SQL & SQLQuery_BasicWhere
|
|
|
|
Set ResultSeriennummer = CWLStart.CurrentCompany.SearchRecord(TABLE_21, SQL)
|
|
|
|
If DEBUG_ON = True Then
|
|
AddDebugLine "Searching for Article by Article serial number " & vbNewline
|
|
AddDebugLine "Result Columns: " & ResultSeriennummer
|
|
AddDebugLine "Result Rows: " & ResultSeriennummer.RowCount
|
|
AddDebugLine "SQL: " & SQL
|
|
|
|
ShowDebugBox "ArticleExists"
|
|
End If
|
|
|
|
If ResultSeriennummer.RowCount > 0 Then
|
|
SerialNumberString = ResultSeriennummer.Value("C068")
|
|
MainArticleNumber = ResultSeriennummer.Value("C011")
|
|
|
|
SQL = ""
|
|
SQL = SQL & "(C002 = '" & MainArticleNumber & "') "
|
|
' Nach Mandant und Wirtschaftsjahr filtern
|
|
SQL = SQL & SQLQuery_BasicWhere
|
|
|
|
Set ResultMainArticle = CWLStart.CurrentCompany.SearchRecord(TABLE_21, SQL)
|
|
|
|
If ResultMainArticle.RowCount > 0 Then
|
|
SerialNumberPattern = ResultMainArticle.Value("C222")
|
|
End If
|
|
|
|
If DEBUG_ON = True Then
|
|
AddDebugLine "Preparing Regex Check. " & vbNewline
|
|
AddDebugLine "SerialNumberString: " & SerialNumberString
|
|
AddDebugLine "SerialNumberPattern: " & SerialNumberPattern
|
|
AddDebugLine "MainArticleNumber: " & MainArticleNumber
|
|
|
|
ShowDebugBox "ArticleExists"
|
|
End If
|
|
|
|
If Len(SerialNumberPattern) > 0 And Len(SerialNumberString) > 0 Then
|
|
Set SerialNumberRegex = New Regexp
|
|
With SerialNumberRegex
|
|
.Pattern = SerialNumberPattern
|
|
.IgnoreCase = False
|
|
.Global = False
|
|
End With
|
|
|
|
Set RegexMatch = SerialNumberRegex.Execute(SerialNumberString)
|
|
Set FirstMatch = RegexMatch.Item(0)
|
|
|
|
If DEBUG_ON = True Then
|
|
AddDebugLine "Checked Serialnumber against Regex. (1/2)" & vbNewline
|
|
AddDebugLine "FirstMatch.Length: " & FirstMatch.Length
|
|
AddDebugLine "Len(SerialNumberString): " & Len(SerialNumberString)
|
|
AddDebugLine "FirstMatch.FirstIndex: " & FirstMatch.FirstIndex
|
|
|
|
ShowDebugBox "ArticleExists"
|
|
End If
|
|
|
|
If Not (FirstMatch.Length = Len(SerialNumberString) And FirstMatch.FirstIndex = 0) Then
|
|
ArticleExists = ARTICLE_EXISTS_NO_REGEX_MATCH
|
|
HasError = True
|
|
End If
|
|
|
|
If DEBUG_ON = True Then
|
|
AddDebugLine "Checked Serialnumber against Regex. (2/2)" & vbNewline
|
|
AddDebugLine "Result: " & SerialNumberRegex.Test(SerialNumberString)
|
|
AddDebugLine "Serialnumber: " & SerialNumberString
|
|
AddDebugLine "Regex: " & SerialNumberPattern
|
|
|
|
ShowDebugBox "ArticleExists"
|
|
End If
|
|
End If
|
|
|
|
CURRENT_SERIALNUMBER = Identifier
|
|
Set Result = ResultSeriennummer
|
|
Else
|
|
Set Result = ResultArtikel
|
|
End If
|
|
|
|
'==========================================================
|
|
If HasError = True Then
|
|
' Just skip the rest of the function and return the current error
|
|
Elseif Result.RowCount > 0 Then
|
|
' Wir brauchen die Hauptartikelnummer, weil die Prüfung sonst bei SN-Artikeln fehlschlägt
|
|
MainArticleNumber = Result.Value("C011")
|
|
RealArticleNumber = Result.Value("C002")
|
|
ProductShape = 0
|
|
|
|
' Ausprägung des Artikels prüfen
|
|
SQL = ""
|
|
SQL = "SELECT c001 FROM t301 (NOLOCK) WHERE c003 = (SELECT c066 FROM v021 (NOLOCK) WHERE c002 = '" & RealArticleNumber & "' " & SQLQuery_BasicWhere & ")" & SQLQuery_BasicWhere
|
|
|
|
If DEBUG_ON = True Then
|
|
AddDebugLine "SQL: " & SQL
|
|
|
|
ShowDebugBox "ArticleExists"
|
|
End If
|
|
|
|
Set Result = CWLStart.CurrentCompany.Connection.Select(SQL)
|
|
|
|
If Result > -1 Then
|
|
ProductShape = Result.Value("c001")
|
|
Else
|
|
ProductShape = 0
|
|
End If
|
|
|
|
CURRENT_SHAPE = ProductShape
|
|
|
|
' Lagerstand des Artikels prüfen
|
|
SQL = ""
|
|
SQL = SQL & "SELECT "
|
|
SQL = SQL & "(SELECT C008 AS [MengeZugang] from [v021] (NOLOCK) where (c002 = '__ARTICLENUMBER__') "& SQLQuery_BasicWhere &")"
|
|
SQL = SQL & " - "
|
|
SQL = SQL & "(SELECT C009 AS [MengeAbgang] from [v021] (NOLOCK) where (c002 = '__ARTICLENUMBER__') "& SQLQuery_BasicWhere &") "
|
|
'SQL = SQL & " - "
|
|
'SQL = SQL & "ISNULL((SELECT SUM(C035) AS [MengeVerkauf] FROM [t014] (NOLOCK) where c000 = '__ARTICLENUMBER__' "& SQLQuery_BasicWhere &"), 0)"
|
|
SQL = SQL & " AS c000"
|
|
|
|
SQL = Replace(SQL, "__ARTICLENUMBER__", RealArticleNumber)
|
|
|
|
If DEBUG_ON = True Then
|
|
AddDebugLine "SQL: " & SQL
|
|
|
|
ShowDebugBox "ArticleExists"
|
|
End If
|
|
|
|
Set Result = CWLStart.CurrentCompany.Connection.Select(SQL)
|
|
AmountStocked = Result.Value("c000")
|
|
|
|
If DEBUG_ON = True Then
|
|
AddDebugLine "Checking stock of product: " & RealArticleNumber & " (" & MainArticleNumber & ")" & vbNewline
|
|
AddDebugLine "Result Columns: " & Result
|
|
AddDebugLine "Result Rows: " & Result.RowCount
|
|
AddDebugLine "Stock: " & AmountStocked
|
|
AddDebugLine "SQL: " & SQL
|
|
|
|
ShowDebugBox "ArticleExists"
|
|
End If
|
|
|
|
If AmountStocked > 0 Then
|
|
If DEBUG_ON = True Then
|
|
AddDebugLine "Amount stocked: " & AmountStocked
|
|
End If
|
|
|
|
' Vorkommen in Tabelle prüfen
|
|
For Row = 1 To Grid.LineCount
|
|
CurrentArticleNumber = Grid.GetCellValue(Row, COLUMN_ARTICLENUMBER)
|
|
Total = Cint(Grid.GetCellValue(Row, COLUMN_TOTAL))
|
|
Scanned = Cint(Grid.GetCellValue(Row, COLUMN_SCANNED))
|
|
|
|
If CurrentArticleNumber = MainArticleNumber Then
|
|
If DEBUG_ON = True Then
|
|
AddDebugLine "CurrentArticleNumber matches MainArticleNumber! (" & CurrentArticleNumber & ")"
|
|
End If
|
|
|
|
If Total > Scanned Then
|
|
If DEBUG_ON = True Then
|
|
AddDebugLine "Product is not yet scanned completetly and exists in Row " & Row & "!"
|
|
End If
|
|
|
|
ArticleExists = Row
|
|
Exit For
|
|
End If
|
|
End If
|
|
Next
|
|
Else
|
|
If DEBUG_ON = True Then
|
|
AddDebugLine "Amount stocked: 0"
|
|
End If
|
|
|
|
ArticleExists = ARTICLE_EXISTS_NO_STOCK
|
|
End If
|
|
|
|
If DEBUG_ON = True Then
|
|
ShowDebugBox "ArticleExists"
|
|
End If
|
|
Else
|
|
If CURRENT_SERIALNUMBER = "" Then
|
|
ArticleExists = ARTICLE_EXISTS_NO_ARTICLE_EAN
|
|
Else
|
|
ArticleExists = ARTICLE_EXISTS_NO_SERIALNUMBER
|
|
End If
|
|
End If
|
|
|
|
End Function |