seadoggie01 Posted January 26, 2021 Posted January 26, 2021 (edited) Here's a quick script I wrote to help ensure the IRS will accept our file for bulk TIN matching. If you don't know what that is, you probably don't need this script. It helps us verify that everyone we need to record paying taxes to has supplied us with their correct information (Tax ID, Tax ID type, and Name) expandcollapse popup#include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <Array.au3> #comments-start This is built from IRS Records, not by the IRS. See here for more information: "On-Line Taxpayer Identification Number (TIN) Matching Program PUBLICATION 2108A" (https://www.irs.gov/pub/irs-pdf/p2108a.pdf) It is NOT guarenteed to work, but it's my best guess. The text file to upload is required to be in the following format: Columns: (semicolon delimited) 1: 1,2, or 3 stating 1-EIN, 2-SSN, 3-Unknown 2: TIN Number - 9 digits without other characters 3: Name - 1 to 40 characters of alphanumeric, hypens, ampersands, and spaces 4: Account - [Optional] Isn't used by IRS. May contain 0 to 20 alphanumeric characters and spaces Other (unwritten?) Requirements: * Name cannot start/end with a space! Our file was rejected in 2021 for this reason. I updated the RegEx to check this. * The final semicolon before a newline appears to not be required * (Unverified) CRLF newlines This script also keeps track of multiple variations on a TIN because you will get locked out if you attempt to TIN match too many variations (N.B.: this is 4+ variations in a 48 hour period, so be cautious! Also, check their website, don't take my word for it. I don't have an account) No GUI because I don't like making them. It displays data using the Console and _ArrayDisplay :D #comments-end Global Const $sRegExValidation = "(?i)^([1-3]);(\d{9});((?! )[a-z\d\-\& ]{1,40}(?<! ));([\da-z ]{0,20});?$" Main() Func Main() ; Get the file to read Local $sFile = FileOpenDialog("Select your TIN matching data...", Default, "All (*.*)", $FD_FILEMUSTEXIST) If @error Then Exit MsgBox($MB_OK, "Canceled", "Unable to get a file for validation. Exiting.") ; Get the text of the file Local $sText = FileRead($sFile) ; Split it into lines Local $aLines = StringSplit($sText, @CRLF, 3) ; Keep a list of TINs (Helps track duplicates) Local $aTINs[UBound($aLines)][2], $iTinCount = 0 ; Create the valid array Local $aValidTIN[UBound($aLines)][4], $iValidTin = 0 ; Array for invalid items Local $aMisMatch[0][2] Local $aTemp[0], $iRow ; For each line For $i=0 to UBound($aLines) - 1 ; Run the RegEx $aTemp = StringRegExp($aLines[$i], $sRegExValidation, 3) If @error Then ; If this isn't a blank line, add it to the mismatched array If $aLines[$i] <> "" Then _ArrayAdd($aMisMatch, $aLines[$i] & "|" & _GetFailureReason($aLines[$i])) EndIf Else ; Add the captured data to the array $aValidTIN[$iValidTin][0] = $aTemp[0] $aValidTIN[$iValidTin][1] = $aTemp[1] $aValidTIN[$iValidTin][2] = $aTemp[2] $aValidTIN[$iValidTin][3] = $aTemp[3] $iValidTin += 1 ; Add the TIN number to the list $iRow = ArrayContains2D($aTINs, $aTemp[1]) If @error Then Exit ElseIf $iRow = False Then $aTINs[$iTinCount][0] = $aTemp[1] $aTINs[$iTinCount][1] = 1 $iTinCount += 1 Else $aTINs[$iRow][1] += 1 EndIf EndIf Next Local $aMultiAttempts[UBound($aTINs) / 3], $iMulti = 0 For $i=0 to UBound($aTINs) - 1 If $aTINs[$i][1] > 3 Then $aMultiAttempts[$iMulti] = $aTINs[$i][0] $iMulti += 1 EndIf Next ReDim $aMultiAttempts[$iMulti] If UBound($aMultiAttempts) > 0 Then ConsoleWrite("+ Too many attempts" & @CRLF & "+ " & _ArrayToString($aMultiAttempts, @CRLF & "+ ") & @CRLF) ; Resize the array to remove any blank lines ReDim $aValidTIN[$iValidTin][4] ; If there were any mistmatched items, display them If UBound($aMisMatch) <> 0 Then _ArrayDisplay($aMisMatch, "Failed Validation") ; Show everything that matches _ArrayDisplay($aValidTIN, "Valid TIN Matching", "", 0, Default, "Option|TIN|Name|Account") EndFunc Func ArrayContains2D($aArray, $vItem, $iColumn = 0) If Not UBound($aArray, 0) = 2 Then Return SetError(1, 0, False) ; For each row For $i=0 to UBound($aArray) - 1 If $aArray[$i][$iColumn] = $vItem Then Return $i Next EndFunc Func _GetFailureReason($sText) If Not StringRegExp($sText, "^[1-3];.*$") Then Return "Invalid Option" ElseIf Not StringRegExp($sText, "^[1-3];\d{9};.*$") Then Return "Invalid TIN" ElseIf Not StringRegExp($sText, "^[1-3];\d{9};([A-Za-z\d\-\& ]+);.*$") Then Return "Invalid Name - Bad characters" ElseIf Not StringRegExp($sText, "^[1-3];\d{9};([A-Za-z\d\-\& ]{1,40});$") Then Return "Invalid Name - Too long" Else Return "Invalid Account" EndIf EndFunc I'm only human, so don't expect that they'll accept even if it passes. Our file was denied earlier due to extra spaces, despite the seeming lack of that requirement. Edited January 26, 2021 by seadoggie01 #CS and #CE All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now