dolibarr 25.0.0-alpha
functions_gr.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2026 Nick Fragoulis
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 */
17
64function dolGRCalculateCreditorReference($payment_id, $statut, $dias_code = '', $usage = '')
65{
66 if ($statut < 1) {
67 return '';
68 }
69
70 if (!function_exists('dolCreditorRefCheckDigits')) {
71 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions_creditorref.lib.php';
72 }
73
74 if ($dias_code === '') {
75 $dias_code = getDolGlobalString('MAIN_INFO_SOCIETE_DIAS_CODE');
76 }
77 $dias_code = preg_replace('/[^0-9]/', '', (string) $dias_code);
78
79 if (!dolGRIsValidDiasCode($dias_code)) {
80 dol_syslog('dolGRCalculateCreditorReference: MAIN_INFO_SOCIETE_DIAS_CODE must be 5 digits starting with 9, got "'.$dias_code.'"', LOG_WARNING);
81 return '';
82 }
83
84 if ($usage === '') {
85 $usage = getDolGlobalString('MAIN_INFO_SOCIETE_DIAS_CODE_USAGE', '8');
86 }
87 if (!in_array((string) $usage, array('8', '9'), true)) {
88 dol_syslog('dolGRCalculateCreditorReference: code usage must be 8 or 9, got "'.$usage.'", 8 is used', LOG_WARNING);
89 $usage = '8';
90 }
91
92 $id = ltrim(preg_replace('/[^0-9]/', '', (string) $payment_id), '0');
93
94 if (dol_strlen($id) > 15) {
95 dol_syslog('dolGRCalculateCreditorReference: debt code "'.$id.'" exceeds 15 digits, only the last 15 are kept', LOG_WARNING);
96 $id = dol_substr($id, -15);
97 }
98
99 $payload = $dias_code.$usage.str_pad($id, 15, '0', STR_PAD_LEFT);
100
101 return 'RF'.dolCreditorRefCheckDigits($payload).$payload;
102}
103
112function dolGRIsValidDiasCode($dias_code)
113{
114 return (bool) preg_match('/^9[0-9]{4}$/', (string) $dias_code);
115}
116
129{
130 if (!function_exists('dolCreditorRefIsValid')) {
131 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions_creditorref.lib.php';
132 }
133
134 $ref = dolPayRefStrip((string) $ref);
135
136 if (dol_strlen($ref) !== 25 || !dolCreditorRefIsValid($ref) || !dolGRIsValidDiasCode(dol_substr($ref, 4, 5))) {
137 return false;
138 }
139
140 return (bool) preg_match('/^[0-7]$/', dol_substr($ref, 9, 1));
141}
142
150{
151 $ref = str_replace(' ', '', (string) $ref);
152
153 if (dol_substr($ref, 0, 2) !== 'RF' || dol_strlen($ref) !== 25) {
154 return '';
155 }
156
157 return dol_substr($ref, 4, 5);
158}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dolCreditorRefIsValid($ref)
Check that a string is a valid ISO 11649 Structured Creditor Reference.
dolPayRefStrip($ref)
Remove formatting spaces from a payment reference (machine form).
dolGRGetDiasCodeFromReference($ref)
Extract the DIAS code from a greek RF reference.
dolGRCalculateCreditorReference($payment_id, $statut, $dias_code='', $usage='')
Calculate a greek DIAS RF Structured Creditor Reference.
dolGRIsValidDiasCode($dias_code)
Check a DIAS creditor code.
dolGRIsAmountCheckedReference($ref)
Tell if a greek DIAS reference asks the paying bank for an amount check.