dolibarr 20.0.0
functions_ch.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 * or see https://www.gnu.org/
17 */
18
32function dol_ch_controle_bvrb($bvrb)
33{
34 // Init array for control
35 $tableau = array();
36 $tableau[0][0] = 0;
37 $tableau[0][1] = 9;
38 $tableau[0][2] = 4;
39 $tableau[0][3] = 6;
40 $tableau[0][4] = 8;
41 $tableau[0][5] = 2;
42 $tableau[0][6] = 7;
43 $tableau[0][7] = 1;
44 $tableau[0][8] = 3;
45 $tableau[0][9] = 5;
46 $tableau[0][10] = 0;
47
48 $tableau[1][0] = 9;
49 $tableau[1][1] = 4;
50 $tableau[1][2] = 6;
51 $tableau[1][3] = 8;
52 $tableau[1][4] = 2;
53 $tableau[1][5] = 7;
54 $tableau[1][6] = 1;
55 $tableau[1][7] = 3;
56 $tableau[1][8] = 5;
57 $tableau[1][9] = 0;
58 $tableau[1][10] = 9;
59
60 $tableau[2][0] = 4;
61 $tableau[2][1] = 6;
62 $tableau[2][2] = 8;
63 $tableau[2][3] = 2;
64 $tableau[2][4] = 7;
65 $tableau[2][5] = 1;
66 $tableau[2][6] = 3;
67 $tableau[2][7] = 5;
68 $tableau[2][8] = 0;
69 $tableau[2][9] = 9;
70 $tableau[2][10] = 8;
71
72 $tableau[3][0] = 6;
73 $tableau[3][1] = 8;
74 $tableau[3][2] = 2;
75 $tableau[3][3] = 7;
76 $tableau[3][4] = 1;
77 $tableau[3][5] = 3;
78 $tableau[3][6] = 5;
79 $tableau[3][7] = 0;
80 $tableau[3][8] = 9;
81 $tableau[3][9] = 4;
82 $tableau[3][10] = 7;
83
84 $tableau[4][0] = 8;
85 $tableau[4][1] = 2;
86 $tableau[4][2] = 7;
87 $tableau[4][3] = 1;
88 $tableau[4][4] = 3;
89 $tableau[4][5] = 5;
90 $tableau[4][6] = 0;
91 $tableau[4][7] = 9;
92 $tableau[4][8] = 4;
93 $tableau[4][9] = 6;
94 $tableau[4][10] = 6;
95
96 $tableau[5][0] = 2;
97 $tableau[5][1] = 7;
98 $tableau[5][2] = 1;
99 $tableau[5][3] = 3;
100 $tableau[5][4] = 5;
101 $tableau[5][5] = 0;
102 $tableau[5][6] = 9;
103 $tableau[5][7] = 4;
104 $tableau[5][8] = 6;
105 $tableau[5][9] = 8;
106 $tableau[5][10] = 5;
107
108 $tableau[6][0] = 7;
109 $tableau[6][1] = 1;
110 $tableau[6][2] = 3;
111 $tableau[6][3] = 5;
112 $tableau[6][4] = 0;
113 $tableau[6][5] = 9;
114 $tableau[6][6] = 4;
115 $tableau[6][7] = 6;
116 $tableau[6][8] = 8;
117 $tableau[6][9] = 2;
118 $tableau[6][10] = 4;
119
120 $tableau[7][0] = 1;
121 $tableau[7][1] = 3;
122 $tableau[7][2] = 5;
123 $tableau[7][3] = 0;
124 $tableau[7][4] = 9;
125 $tableau[7][5] = 4;
126 $tableau[7][6] = 6;
127 $tableau[7][7] = 8;
128 $tableau[7][8] = 2;
129 $tableau[7][9] = 7;
130 $tableau[7][10] = 3;
131
132 $tableau[8][0] = 3;
133 $tableau[8][1] = 5;
134 $tableau[8][2] = 0;
135 $tableau[8][3] = 9;
136 $tableau[8][4] = 4;
137 $tableau[8][5] = 6;
138 $tableau[8][6] = 8;
139 $tableau[8][7] = 2;
140 $tableau[8][8] = 7;
141 $tableau[8][9] = 1;
142 $tableau[8][10] = 2;
143
144 $tableau[9][0] = 5;
145 $tableau[9][1] = 0;
146 $tableau[9][2] = 9;
147 $tableau[9][3] = 4;
148 $tableau[9][4] = 6;
149 $tableau[9][5] = 8;
150 $tableau[9][6] = 2;
151 $tableau[9][7] = 7;
152 $tableau[9][8] = 1;
153 $tableau[9][9] = 3;
154 $tableau[9][10] = 1;
155
156
157 // Clean data
158 $bv = str_replace(' ', '', $bvrb);
159
160 // Check (verify/validate)
161 $report = 0;
162 while (dol_strlen($bv) > 1) {
163 $match = substr($bv, 0, 1);
164 $report = $tableau[$report][$match];
165 $bv = substr($bv, 1);
166 }
167 $check = $tableau[$report][10];
168
169 return ($check == $bv);
170}
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_ch_controle_bvrb($bvrb)
Return if a BVRB number is valid or not (For Switzerland)