Community

Разбиение строки ИНН/КПП на отдельные поля ИНН и КПП с проверкой формата


Dim vStringToDelete, vFieldName, vFieldVal, i
Dim CharToDelete, L, IssKPP, IssINN

IssKPP = ""
IssINN = ""
me.CHECKSUCCEEDED = true

' удаление мусора
vStringToDelete = ";:АБВГДЕЖЗИЙЛМНОСТУФХЦШЩЧЪЫЬЭЮЯ()INКПКKKP/\"
vFieldName = "IssINNKPP"

vFieldVal = me.FIELD(vFieldName).TEXT
vFieldVal = UCase(CStr(vFieldVal))

vFieldVal = Replace (vFieldVal, vbCR, "")
vFieldVal = Replace (vFieldVal, vbLF, "")
vFieldVal = Replace (vFieldVal, " ", "")

for i = 1 to Len(vStringToDelete)
CharToDelete = Mid (vStringToDelete, i, 1)
if instr(1, vFieldVal, CharToDelete) <> 0 then
vFieldVal = Replace (vFieldVal, CharToDelete, "")
end if
next
'============== разбиение на ИНН и КПП ===================
L = Len(vFieldVal)
if L = 19 then
IssKPP = Mid (vFieldVal, 11,9)
IssINN = Mid(vFieldVal,1,10)
if IsNumeric (IssINN) = false then
me.ERRORMESSAGE = "Нечисловое значение ИНН"
me.CHECKSUCCEEDED = false
me.FOCUSEDFIELD = me.FIELD (vFieldName)
Exit Sub
end if
if IsNumeric (IssKPP) = false then
me.ERRORMESSAGE = "Нечисловое значение КПП"
me.CHECKSUCCEEDED = false
me.FOCUSEDFIELD = me.FIELD (vFieldName)
Exit Sub
end if
elseif L = 12 or L = 10 then
IssINN = vFieldVal
if IsNumeric (IssINN) = false then
me.ERRORMESSAGE = "Нечисловое значение ИНН"
me.CHECKSUCCEEDED = false
me.FOCUSEDFIELD = me.FIELD (vFieldName)
Exit Sub
end if
if me.FIELD("IssKPP").Text <> "" and me.FIELD("NoneIssKPP").VALUE = true then
me.FIELD("IssKPP").Text = ""
end if
if me.FIELD("NoneIssKPP").VALUE = false Then
me.ERRORMESSAGE = "Проверьте нахождение КПП или укажите, что он не нужен"
me.CHECKSUCCEEDED = false
me.FOCUSEDFIELD = me.FIELD (vFieldName)
Exit Sub
end if
else
' IssINN = ""
' IssKPP] = ""
me.ERRORMESSAGE = "Некорректный формат поля ИНН/КПП. Разбиение по полям невозможно."
me.FOCUSEDFIELD = me.FIELD (vFieldName)
me.CHECKSUCCEEDED = false
Exit Sub
end if

'======== проверка корпоративного ИНН =======================================
L = Len (IssINN)
Dim InnIsCorrect
Dim a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12
if L = 10 then
a1 = CInt(Mid(IssINN, 1, 1))
a2 = CInt(Mid(IssINN, 2, 1))
a3 = CInt(Mid(IssINN, 3, 1))
a4 = CInt(Mid(IssINN, 4, 1))
a5 = CInt(Mid(IssINN, 5, 1))
a6 = CInt(Mid(IssINN, 6, 1))
a7 = CInt(Mid(IssINN, 7, 1))
a8 = CInt(Mid(IssINN, 8, 1))
a9 = CInt(Mid(IssINN, 9, 1))
a10 = CInt(Mid(IssINN, 10, 1))

InnIsCorrect = (a10 = ((a1 * 2 + a2 * 4 + a3 * 10 + a4 * 3 + a5 * 5 + a6 * 9 + a7 * 4 + a8 * 6 + a9 * 8) Mod 11) Mod 10)
' 2, 4, 10, 3, 5, 9, 4, 6, 8

if InnIsCorrect = 0 then
me.ERRORMESSAGE = "Некорректный формат ИНН"
me.CHECKSUCCEEDED = false
me.FOCUSEDFIELD = me.FIELD (vFieldName)
Exit Sub
end if
'------------------------ проверка персонального ИНН ------------------------
elseif L = 12 then
a1 = CInt(Mid(IssINN, 1, 1))
a2 = CInt(Mid(IssINN, 2, 1))
a3 = CInt(Mid(IssINN, 3, 1))
a4 = CInt(Mid(IssINN, 4, 1))
a5 = CInt(Mid(IssINN, 5, 1))
a6 = CInt(Mid(IssINN, 6, 1))
a7 = CInt(Mid(IssINN, 7, 1))
a8 = CInt(Mid(IssINN, 8, 1))
a9 = CInt(Mid(IssINN, 9, 1))
a10 = CInt(Mid(IssINN, 10, 1))
a11 = CInt(Mid(IssINN, 11, 1))
a12 = CInt(Mid(IssINN, 12, 1))

if a11 <> ((a1 * 7 + a2 * 2 + a3 * 4 + a4 * 10 + a5 * 3 + a6 * 5 + a7 * 9 + a8 * 4 + a9 * 6 + a10 * 8) Mod 11) Mod 10 Then
' 7, 2, 4, 10, 3, 5, 9, 4, 6, 8
me.ERRORMESSAGE = "Некорректный формат ИНН"
me.CHECKSUCCEEDED = false
me.FOCUSEDFIELD = me.FIELD (vFieldName)
Exit Sub
End If
if (a12 <> ((a1 * 3 + a2 * 7 + a3 * 2 + a4 * 4 + a5 * 10 + a6 * 3 + a7 * 5 + a8 * 9 + a9 * 4 + a10 * 6 + a11 * 8) Mod 11) Mod 10) Then
' 3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8
me.ERRORMESSAGE = "Некорректный формат ИНН"
me.CHECKSUCCEEDED = false
me.FOCUSEDFIELD = me.FIELD (vFieldName)
Exit Sub
End If

end if
'=============== запись значений в поля ===========================================
me.FIELD("IssINN").TEXT = IssINN
if not IssKPP = "" then
me.FIELD("IssKPP").TEXT = IssKPP
me.FIELD(vFieldName).TEXT = IssINN & " / " & IssKPP
me.FocusedField = me.Field(vFieldName)
me.CHECKSUCCEEDED = true
end if
me.CHECKSUCCEEDED = true


0

Comments

0 comments

Please sign in to leave a comment.