Created
July 28, 2014 13:19
-
-
Save standa/0e2c706c65651d393aea to your computer and use it in GitHub Desktop.
Swiss BESR Invoice Check Digit
This file contains 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
// ----------------------------------------------------------------------------- | |
// @author standa | 2014-04-30 | Swiss Rechnung (BESR) | |
// not guaranteed 100% but seems to work for us | |
public function calculateCheckDigit($number) | |
{ | |
$matrix = array( | |
0 => array(0,9,4,6,8,2,7,1,3,5), | |
1 => array(9,4,6,8,2,7,1,3,5,0), | |
2 => array(4,6,8,2,7,1,3,5,0,9), | |
3 => array(6,8,2,7,1,3,5,0,9,4), | |
4 => array(8,2,7,1,3,5,0,9,4,6), | |
5 => array(2,7,1,3,5,0,9,4,6,8), | |
6 => array(7,1,3,5,0,9,4,6,8,2), | |
7 => array(1,3,5,0,9,4,6,8,2,7), | |
8 => array(3,5,0,9,4,6,8,2,7,1), | |
9 => array(5,0,9,4,6,8,2,7,1,3) | |
); | |
$checkDigits = array(0,9,8,7,6,5,4,3,2,1); | |
$transfer = 0; | |
foreach (str_split($number) as $digit) { | |
$transfer = $matrix[$digit][$transfer]; | |
} | |
return $checkDigits[$transfer]; | |
} | |
// ----------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment