diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 2b368d7bd75..f4f94d927ee 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -4012,7 +4012,7 @@ class Facture extends CommonInvoice
}
if (!empty($addon)) {
- dol_syslog("Call getNextNumRef with ".$addonConstName." = ".$conf->global->FACTURE_ADDON.", thirdparty=".$soc->name.", type=".$soc->typent_code, LOG_DEBUG);
+ dol_syslog("Call getNextNumRef with ".$addonConstName." = ".$conf->global->FACTURE_ADDON.", thirdparty=".$soc->name.", type=".$soc->typent_code.", mode=".$mode, LOG_DEBUG);
$mybool = false;
diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php
index eae29bf4036..8c419eec3c9 100644
--- a/htdocs/core/lib/functions2.lib.php
+++ b/htdocs/core/lib/functions2.lib.php
@@ -1451,14 +1451,17 @@ function get_next_value($db, $mask, $table, $field, $where = '', $objsoc = '', $
// Now we replace the counter
$maskbefore = '{'.$masktri.'}';
$maskafter = str_pad($counter, dol_strlen($maskcounter), "0", STR_PAD_LEFT);
- //print 'x'.$maskbefore.'-'.$maskafter.'y';
+ //print 'x'.$numFinal.' - '.$maskbefore.' - '.$maskafter.'y';exit;
$numFinal = str_replace($maskbefore, $maskafter, $numFinal);
// Now we replace the refclient
if ($maskrefclient) {
- //print "maskrefclient=".$maskrefclient." maskwithonlyymcode=".$maskwithonlyymcode." maskwithnocode=".$maskwithnocode." maskrefclient_clientcode=".$maskrefclient_clientcode."\n
";exit;
+ //print "maskrefclient=".$maskrefclient." maskrefclient_counter=".$maskrefclient_counter." maskwithonlyymcode=".$maskwithonlyymcode." maskwithnocode=".$maskwithnocode." maskrefclient_clientcode=".$maskrefclient_clientcode." maskrefclient_maskcounter=".$maskrefclient_maskcounter."\n
";exit;
$maskrefclient_maskbefore = '{'.$maskrefclient.'}';
- $maskrefclient_maskafter = $maskrefclient_clientcode.str_pad($maskrefclient_counter, dol_strlen($maskrefclient_maskcounter), "0", STR_PAD_LEFT);
+ $maskrefclient_maskafter = $maskrefclient_clientcode;
+ if (dol_strlen($maskrefclient_maskcounter) > 0) {
+ $maskrefclient_maskafter .= str_pad($maskrefclient_counter, dol_strlen($maskrefclient_maskcounter), "0", STR_PAD_LEFT);
+ }
$numFinal = str_replace($maskrefclient_maskbefore, $maskrefclient_maskafter, $numFinal);
}