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