Last active
March 20, 2019 18:22
-
-
Save hasokeric/934fe60b7e1627c870895f428d5787c2 to your computer and use it in GitHub Desktop.
Epicor VIN Validation BPM Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Erp.SelectedSerialNumbers.CreateSerialNum.PRE.ValidateVIN | |
// | |
// | |
// | |
// Part IsVehicleRefCat? | |
bool isVehiclePart = | |
(from p in Db.Part.With(LockHint.NoLock) | |
where p.Company == Session.CompanyID | |
&& p.PartNum == PartNum | |
&& (new List<string>() { "ALTVEH", "COMVEH", "INCVEH", "INTVEH" }).Contains(p.RefCategory) | |
select p.RefCategory).Any(); | |
return isVehiclePart; | |
// Check VIN | |
Func<string, bool> IsValidVIN = _vin => | |
{ | |
if (_vin.Length != 17) { return false; } | |
string map = "0123456789X"; | |
string weights = "8765432X098765432"; | |
string transliterate = "0123456789.ABCDEFGH..JKLMN.P.R..STUVWXYZ"; | |
int sum = 0; | |
for (int i = 0; i < 17; ++i) | |
sum += (transliterate.IndexOf(_vin[i]) % 10) * map.IndexOf(weights[i]); | |
char checkDigit = map[sum % 11]; | |
return (checkDigit == _vin[8] && _vin.Length == 17 && !System.Text.RegularExpressions.Regex.IsMatch(_vin, "(.)\\1{16}")); | |
}; | |
return IsValidVIN(baseSerialNum); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT (CHARINDEX('J', 'ABCDEFGHJKLMNPRSTVWXY123456789', 0) - 1) + IIF((YEAR(GETDATE()) % 2040) > 100, 2010, 2039) -- Returns 2018, once we reach 2040 new offset is 2039 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment