diff --git a/htdocs/core/modules/commande/mod_commande_saphir.php b/htdocs/core/modules/commande/mod_commande_saphir.php
index 1996717e5069783136cb6ddaf48d585023eabb10..2c8ae2ef3e9ef33ad554c7579f9761ece190b915 100644
--- a/htdocs/core/modules/commande/mod_commande_saphir.php
+++ b/htdocs/core/modules/commande/mod_commande_saphir.php
@@ -88,9 +88,12 @@ class mod_commande_saphir extends ModeleNumRefCommandes
      	global $conf,$langs,$mysoc;
 
     	$old_code_client=$mysoc->code_client;
+    	$old_code_type=$mysoc->typent_code;
     	$mysoc->code_client='CCCCCCCCCC';
+    	$mysoc->typent_code='TTTTTTTTTT';
      	$numExample = $this->getNextValue($mysoc,'');
 		$mysoc->code_client=$old_code_client;
+		$mysoc->typent_code=$old_code_type;
 
 		if (! $numExample)
 		{
@@ -121,7 +124,9 @@ class mod_commande_saphir extends ModeleNumRefCommandes
 			return 0;
 		}
 
-		$numFinal=get_next_value($db,$mask,'commande','ref','',$objsoc,$object->date);
+		$date = ($object->date_commande ? $object->date_commande : $object->date);
+
+		$numFinal=get_next_value($db,$mask,'commande','ref','',$objsoc,$date);
 
 		return  $numFinal;
 	}
diff --git a/htdocs/core/modules/expedition/mod_expedition_ribera.php b/htdocs/core/modules/expedition/mod_expedition_ribera.php
index c92ea93e6a2fd925b4bdcdbc59e38c782d4b4e78..c002da1eee2f4e458c9d68b5c550a19838ceb9bd 100644
--- a/htdocs/core/modules/expedition/mod_expedition_ribera.php
+++ b/htdocs/core/modules/expedition/mod_expedition_ribera.php
@@ -79,9 +79,12 @@ class mod_expedition_ribera extends ModelNumRefExpedition
      	global $conf,$langs,$mysoc;
 
     	$old_code_client=$mysoc->code_client;
+    	$old_code_type=$mysoc->typent_code;
     	$mysoc->code_client='CCCCCCCCCC';
+    	$mysoc->typent_code='TTTTTTTTTT';
      	$numExample = $this->getNextValue($mysoc,'');
 		$mysoc->code_client=$old_code_client;
+		$mysoc->typent_code=$old_code_type;
 
 		if (! $numExample)
 		{
@@ -111,7 +114,9 @@ class mod_expedition_ribera extends ModelNumRefExpedition
 			return 0;
 		}
 
-		$numFinal=get_next_value($db,$mask,'expedition','ref','',$objsoc->code_client,$shipment->date_expedition);
+		$date = $shipment->date_expedition;
+
+		$numFinal=get_next_value($db,$mask,'expedition','ref','',$objsoc,$date);
 
 		return  $numFinal;
 	}
diff --git a/htdocs/core/modules/propale/mod_propale_saphir.php b/htdocs/core/modules/propale/mod_propale_saphir.php
index 25ccecb253cc40138879846cf98f0ae1fa23e510..ec0b0b241e20e17129348eeadae6857a5d10550f 100644
--- a/htdocs/core/modules/propale/mod_propale_saphir.php
+++ b/htdocs/core/modules/propale/mod_propale_saphir.php
@@ -88,9 +88,12 @@ class mod_propale_saphir extends ModeleNumRefPropales
      	global $conf,$langs,$mysoc;
 
     	$old_code_client=$mysoc->code_client;
+    	$old_code_type=$mysoc->typent_code;
     	$mysoc->code_client='CCCCCCCCCC';
+    	$mysoc->typent_code='TTTTTTTTTT';
      	$numExample = $this->getNextValue($mysoc,'');
 		$mysoc->code_client=$old_code_client;
+		$mysoc->typent_code=$old_code_type;
 
 		if (! $numExample)
 		{
@@ -121,8 +124,8 @@ class mod_propale_saphir extends ModeleNumRefPropales
 			return 0;
 		}
 
-		$date=$propal->datep;
-		$customercode=$objsoc->code_client;
+		$date = $propal->date;
+
 		$numFinal=get_next_value($db,$mask,'propal','ref','',$objsoc,$date);
 
 		return  $numFinal;