41 $invoice_number = preg_replace(
'/[^0-9]/',
'', $invoice_number);
42 $invoice_number = ltrim($invoice_number,
'0');
48 $invoice_number = str_pad($invoice_number, 3,
'0', STR_PAD_LEFT);
50 dol_syslog(
'dolFICalculatePaymentReference: base "'.$invoice_number.
'" is longer than 19 digits, cut to keep the reference valid', LOG_WARNING);
51 $invoice_number =
dol_substr($invoice_number, 0, 19);
53 $coefficients = array(7, 3, 1);
55 $stlen_invoice_number = (int) strlen($invoice_number);
57 for ($i = 0; $i < $stlen_invoice_number; $i++) {
58 $sum += (int) $invoice_number[$stlen_invoice_number - $i - 1] * $coefficients[$i % 3];
60 $check_digit = (10 - ($sum % 10)) % 10;
61 $bank_reference_fi = $invoice_number . $check_digit;
63 $reference_with_suffix = $bank_reference_fi .
"271500";
66 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_creditorref.lib.php';
68 $check_digit = 98 - $remainder;
69 if ($check_digit < 10) {
70 $check_digit =
'0' . $check_digit;
72 $bank_reference =
"RF" . $check_digit . $bank_reference_fi;
74 $bank_reference = $bank_reference_fi;
79 return wordwrap($bank_reference, 4,
' ',
true);
94 if ($amount >= 0 && !empty($bank_reference)) {
95 if (substr($bank_reference, 0, 2) ===
"RF") {
96 $recipient_account = preg_replace(
'/[^0-9]/',
'', $recipient_account);
97 $recipient_account = str_pad($recipient_account, 16,
'0', STR_PAD_LEFT);
98 $referencetobarcode = preg_replace(
'/[^0-9]/',
'', $bank_reference);
99 $referencetobarcode = substr($referencetobarcode, 0, 2) . str_pad(substr($referencetobarcode, 2), 21,
'0', STR_PAD_LEFT);
100 $euros = floor((
float) $amount);
101 $cents = round(((
float) $amount - $euros) * 100);
102 $due_date =
date(
'ymd', (
int) $due_date);
104 $barcodeData .= $recipient_account;
105 $barcodeData .= sprintf(
'%06d', (
int) $euros);
106 $barcodeData .= sprintf(
'%02d', (
int) $cents);
107 $barcodeData .= $referencetobarcode;
108 $barcodeData .= $due_date;
109 } elseif (substr($bank_reference, 0, 2) !==
"RF") {
110 $recipient_account = preg_replace(
'/[^0-9]/',
'', $recipient_account);
111 $recipient_account = str_pad($recipient_account, 16,
'0', STR_PAD_LEFT);
112 $referencetobarcode = preg_replace(
'/[^0-9]/',
'', $bank_reference);
113 $euros = floor((
float) $amount);
114 $cents = round(((
float) $amount - $euros) * 100);
115 $due_date =
date(
'ymd', (
int) $due_date);
117 $barcodeData .= $recipient_account;
118 $barcodeData .= sprintf(
'%06d', (
int) $euros);
119 $barcodeData .= sprintf(
'%02d', (
int) $cents);
120 $barcodeData .=
'000';
121 $barcodeData .= str_pad($referencetobarcode, 20,
'0', STR_PAD_LEFT);
122 $barcodeData .= $due_date;
144 if (!is_object(
$object) || empty(
$object->payment_reference) || empty(
$object->date_lim_reglement)) {
148 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
150 $idofbankaccount =
$object->fk_account;
151 if (empty($idofbankaccount)) {
152 $idofbankaccount =
$object->fk_bank;
154 if (empty($idofbankaccount)) {
157 if (empty($idofbankaccount)) {
162 if ($bankaccount->fetch($idofbankaccount) <= 0 || empty($bankaccount->iban)) {
170 if (strpos($iban,
'FI') !== 0) {
171 dol_syslog(
'dolFIGetInvoiceBarcodeData: barcode needs a finnish IBAN, got '.$iban, LOG_WARNING);
176 $reference = str_replace(
' ',
'', (
string)
$object->payment_reference);
177 if (!ctype_digit(
dol_substr($reference, 0, 2) ===
'RF' ?
dol_substr($reference, 2) : $reference)) {
178 dol_syslog(
'dolFIGetInvoiceBarcodeData: barcode needs a numeric reference, got '.$reference, LOG_WARNING);
182 $amount =
$object->getRemainToPay();
191 dol_syslog(
'dolFIGetInvoiceBarcodeData: barcode length is '.
dol_strlen($barcodedata).
', expected 54, discarded', LOG_WARNING);
209 if (empty($barcodedata)) {
213 return trim(chunk_split($barcodedata, 5,
' '));
227 $reference = str_replace(
' ',
'', (
string) $reference);
233 $base = substr($reference, 0, -1);
234 $given = (int) substr($reference, -1);
236 $coefficients = array(7, 3, 1);
239 for ($pos =
dol_strlen($base) - 1; $pos >= 0; $pos--) {
240 $sum += ((int) $base[$pos]) * $coefficients[$i % 3];
244 return $given === ((10 - ($sum % 10)) % 10);
if(! $sortfield) if(! $sortorder) $object
Class to manage bank accounts.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_strtoupper($string, $encoding="UTF-8")
Convert a string to upper.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dolCreditorRefMod97($digits)
Remainder of a long decimal string divided by 97.
dolFIGenerateInvoiceBarcodeData($recipient_account, $amount, $bank_reference, $due_date)
Calculate payment Barcode data with FI/RF bank payment reference number.
dolFIIsValidReference($reference)
Check that a string is a valid finnish national reference.
dolFIGetInvoiceBarcodeData($object)
Build the finnish payment barcode data of an invoice.
dolFIFormatVirtualBarcode($barcodedata)
Format the finnish payment barcode for reading, as banks print it.
dolFICalculatePaymentReference($invoice_number, $statut, $use_rf)
Calculate Creditor Reference RF / FI Bank payment reference number.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date