39 $invoice_number = preg_replace(
'/[^0-9]/',
'', $invoice_number);
40 $invoice_number = ltrim($invoice_number,
'0');
41 $invoice_number = strrev($invoice_number);
42 $coefficients = array(7, 3, 1, 7, 3);
44 $stlen_invoice_number = (int) strlen($invoice_number);
45 for ($i = 0; $i < $stlen_invoice_number; $i++) {
46 $sum += (int) $invoice_number[$i] * $coefficients[$i % 5];
48 $check_digit = (10 - ($sum % 10)) % 10;
49 $bank_reference_fi = strrev($invoice_number) . $check_digit;
51 $reference_with_suffix = $bank_reference_fi .
"271500";
52 $remainder = (int) bcmod($reference_with_suffix,
'97');
53 $check_digit = 98 - $remainder;
54 if ($check_digit < 10) {
55 $check_digit =
'0' . $check_digit;
57 $bank_reference =
"RF" . $check_digit . $bank_reference_fi;
59 $bank_reference = $bank_reference_fi;
64 return wordwrap($bank_reference, 4,
' ',
true);
79 if ($amount >= 0 && !empty($bank_reference)) {
80 if (substr($bank_reference, 0, 2) ===
"RF") {
81 $recipient_account = preg_replace(
'/[^0-9]/',
'', $recipient_account);
82 $recipient_account = str_pad($recipient_account, 16,
'0', STR_PAD_LEFT);
83 $referencetobarcode = preg_replace(
'/[^0-9]/',
'', $bank_reference);
84 $referencetobarcode = substr($referencetobarcode, 0, 2) . str_pad(substr($referencetobarcode, 2), 21,
'0', STR_PAD_LEFT);
85 $euros = floor(floatval($amount));
86 $cents = round((floatval($amount) - $euros) * 100);
87 $due_date = date(
'ymd', (
int) $due_date);
89 $barcodeData .= $recipient_account;
90 $barcodeData .= sprintf(
'%06d', (
int) $euros);
91 $barcodeData .= sprintf(
'%02d', (
int) $cents);
92 $barcodeData .= $referencetobarcode;
93 $barcodeData .= (int) $due_date;
94 } elseif (substr($bank_reference, 0, 2) !==
"RF") {
95 $recipient_account = preg_replace(
'/[^0-9]/',
'', $recipient_account);
96 $recipient_account = str_pad($recipient_account, 16,
'0', STR_PAD_LEFT);
97 $referencetobarcode = preg_replace(
'/[^0-9]/',
'', $bank_reference);
98 $euros = floor(floatval($amount));
99 $cents = round((floatval($amount) - $euros) * 100);
100 $due_date = date(
'ymd', (
int) $due_date);
102 $barcodeData .= $recipient_account;
103 $barcodeData .= sprintf(
'%06d', (
int) $euros);
104 $barcodeData .= sprintf(
'%02d', (
int) $cents);
105 $barcodeData .=
'000';
106 $barcodeData .= str_pad($referencetobarcode, 20,
'0', STR_PAD_LEFT);
107 $barcodeData .= (int) $due_date;
dolFIGenerateInvoiceBarcodeData($recipient_account, $amount, $bank_reference, $due_date)
Calculate payment Barcode data with FI/RF bank payment reference number.