dolibarr 21.0.0-beta
functions_be.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
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
33function dolBECalculateStructuredCommunication($invoice_number, $invoice_type)
34{
35 $invoice_number = preg_replace('/[^0-9]/', '', $invoice_number); // Keep only numbers
36
37 // We complete with 0 and take the last 8 digits of the number are used to generate the reference base.
38 $invoice_number = substr('00000000'.$invoice_number, -8);
39
40 // Prefix with invoice type
41 switch ($invoice_type) {
42 case '0':
43 $invoice_type = '20'; // invoice type standard
44 break;
45 case '1':
46 $invoice_type = '30'; // invoice type replacement
47 break;
48 case '2':
49 $invoice_type = '40'; // invoice type credit note
50 break;
51 case '3':
52 $invoice_type = '21'; // invoice type deposit
53 break;
54 case '5':
55 $invoice_type = '20'; // invoice type situation, force to standard
56 break;
57 default:
58 $invoice_type = '00';
59 }
60
61 // Calculate module97
62 $invoice_number = $invoice_type.$invoice_number;
63 $mod97 = intval($invoice_number) % 97;
64 $controlKey = ($mod97 === 0) ? 97 : $mod97;
65
66 // Add the check digit at the end of the reference
67 $invoice_number .= $controlKey;
68
69 // Format reference as XXX/XXXX/XXXXX
70 $part1 = '+++'.substr($invoice_number, 0, 3);
71 $part2 = substr($invoice_number, 3, 4);
72 $part3 = substr($invoice_number, 7, 5).'+++'; // Includes last 3 digits + 2 check digits
73
74 $invoice_number = $part1 . '/' . $part2 . '/' . $part3;
75
76 return $invoice_number;
77}
dolBECalculateStructuredCommunication($invoice_number, $invoice_type)
Calculate Structured Communication / BE Bank payment reference number.