dolibarr 19.0.3
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[0][0] = 0;
36 $tableau[0][1] = 9;
37 $tableau[0][2] = 4;
38 $tableau[0][3] = 6;
39 $tableau[0][4] = 8;
40 $tableau[0][5] = 2;
41 $tableau[0][6] = 7;
42 $tableau[0][7] = 1;
43 $tableau[0][8] = 3;
44 $tableau[0][9] = 5;
45 $tableau[0][10] = 0;
46
47 $tableau[1][0] = 9;
48 $tableau[1][1] = 4;
49 $tableau[1][2] = 6;
50 $tableau[1][3] = 8;
51 $tableau[1][4] = 2;
52 $tableau[1][5] = 7;
53 $tableau[1][6] = 1;
54 $tableau[1][7] = 3;
55 $tableau[1][8] = 5;
56 $tableau[1][9] = 0;
57 $tableau[1][10] = 9;
58
59 $tableau[2][0] = 4;
60 $tableau[2][1] = 6;
61 $tableau[2][2] = 8;
62 $tableau[2][3] = 2;
63 $tableau[2][4] = 7;
64 $tableau[2][5] = 1;
65 $tableau[2][6] = 3;
66 $tableau[2][7] = 5;
67 $tableau[2][8] = 0;
68 $tableau[2][9] = 9;
69 $tableau[2][10] = 8;
70
71 $tableau[3][0] = 6;
72 $tableau[3][1] = 8;
73 $tableau[3][2] = 2;
74 $tableau[3][3] = 7;
75 $tableau[3][4] = 1;
76 $tableau[3][5] = 3;
77 $tableau[3][6] = 5;
78 $tableau[3][7] = 0;
79 $tableau[3][8] = 9;
80 $tableau[3][9] = 4;
81 $tableau[3][10] = 7;
82
83 $tableau[4][0] = 8;
84 $tableau[4][1] = 2;
85 $tableau[4][2] = 7;
86 $tableau[4][3] = 1;
87 $tableau[4][4] = 3;
88 $tableau[4][5] = 5;
89 $tableau[4][6] = 0;
90 $tableau[4][7] = 9;
91 $tableau[4][8] = 4;
92 $tableau[4][9] = 6;
93 $tableau[4][10] = 6;
94
95 $tableau[5][0] = 2;
96 $tableau[5][1] = 7;
97 $tableau[5][2] = 1;
98 $tableau[5][3] = 3;
99 $tableau[5][4] = 5;
100 $tableau[5][5] = 0;
101 $tableau[5][6] = 9;
102 $tableau[5][7] = 4;
103 $tableau[5][8] = 6;
104 $tableau[5][9] = 8;
105 $tableau[5][10] = 5;
106
107 $tableau[6][0] = 7;
108 $tableau[6][1] = 1;
109 $tableau[6][2] = 3;
110 $tableau[6][3] = 5;
111 $tableau[6][4] = 0;
112 $tableau[6][5] = 9;
113 $tableau[6][6] = 4;
114 $tableau[6][7] = 6;
115 $tableau[6][8] = 8;
116 $tableau[6][9] = 2;
117 $tableau[6][10] = 4;
118
119 $tableau[7][0] = 1;
120 $tableau[7][1] = 3;
121 $tableau[7][2] = 5;
122 $tableau[7][3] = 0;
123 $tableau[7][4] = 9;
124 $tableau[7][5] = 4;
125 $tableau[7][6] = 6;
126 $tableau[7][7] = 8;
127 $tableau[7][8] = 2;
128 $tableau[7][9] = 7;
129 $tableau[7][10] = 3;
130
131 $tableau[8][0] = 3;
132 $tableau[8][1] = 5;
133 $tableau[8][2] = 0;
134 $tableau[8][3] = 9;
135 $tableau[8][4] = 4;
136 $tableau[8][5] = 6;
137 $tableau[8][6] = 8;
138 $tableau[8][7] = 2;
139 $tableau[8][8] = 7;
140 $tableau[8][9] = 1;
141 $tableau[8][10] = 2;
142
143 $tableau[9][0] = 5;
144 $tableau[9][1] = 0;
145 $tableau[9][2] = 9;
146 $tableau[9][3] = 4;
147 $tableau[9][4] = 6;
148 $tableau[9][5] = 8;
149 $tableau[9][6] = 2;
150 $tableau[9][7] = 7;
151 $tableau[9][8] = 1;
152 $tableau[9][9] = 3;
153 $tableau[9][10] = 1;
154
155
156 // Clean data
157 $bv = str_replace(' ', '', $bvrb);
158
159 // Make control
160 $report = 0;
161 while (dol_strlen($bv) > 1) {
162 $match = substr($bv, 0, 1);
163 $report = $tableau[$report][$match];
164 $bv = substr($bv, 1);
165 }
166 $controle = $tableau[$report][10];
167
168 return ($controle == $bv);
169}
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)