diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php
index d48c897d6bb..8b1ab0f4ac8 100644
--- a/htdocs/comm/card.php
+++ b/htdocs/comm/card.php
@@ -269,7 +269,10 @@ if ($object->id > 0)
print '
| ';
print $langs->trans('CustomerCode').' | ';
print $object->code_client;
- if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')';
+ $tmpcheck = $object->check_codeclient();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
+ print ' ('.$langs->trans("WrongCustomerCode").')';
+ }
print ' |
';
print '';
diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php
index 1ccc4a2d1fb..c00e0f7f825 100644
--- a/htdocs/core/lib/functions2.lib.php
+++ b/htdocs/core/lib/functions2.lib.php
@@ -773,6 +773,7 @@ function get_next_value($db, $mask, $table, $field, $where = '', $objsoc = '', $
if (dol_strlen($maskcounter) < 3 && empty($conf->global->MAIN_COUNTER_WITH_LESS_3_DIGITS)) return 'ErrorCounterMustHaveMoreThan3Digits';
// Extract value for third party mask counter
+ $regClientRef = array();
if (preg_match('/\{(c+)(0*)\}/i', $mask, $regClientRef))
{
$maskrefclient = $regClientRef[1].$regClientRef[2];
@@ -806,6 +807,7 @@ function get_next_value($db, $mask, $table, $field, $where = '', $objsoc = '', $
}
// Extract value for user
+ $regType = array();
if (preg_match('/\{(u+)\}/i', $mask, $regType))
{
$lastname = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
@@ -970,12 +972,10 @@ function get_next_value($db, $mask, $table, $field, $where = '', $objsoc = '', $
//print "masktri=".$masktri." maskcounter=".$maskcounter." maskraz=".$maskraz." maskoffset=".$maskoffset."
\n";
// Define $sqlstring
- if (function_exists('mb_strrpos'))
- {
+ if (function_exists('mb_strrpos')) {
$posnumstart = mb_strrpos($maskwithnocode, $maskcounter, 'UTF-8');
}
- else
- {
+ else {
$posnumstart = strrpos($maskwithnocode, $maskcounter);
} // Pos of counter in final string (from 0 to ...)
if ($posnumstart < 0) return 'ErrorBadMaskFailedToLocatePosOfSequence';
@@ -1218,6 +1218,7 @@ function check_value($mask, $value)
$hasglobalcounter = false;
// Extract value for mask counter, mask raz and mask offset
+ $reg = array();
if (preg_match('/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i', $mask, $reg))
{
$masktri = $reg[1].(isset($reg[2]) ? $reg[2] : '').(isset($reg[3]) ? $reg[3] : '');
@@ -1236,6 +1237,7 @@ function check_value($mask, $value)
if (dol_strlen($maskcounter) < 3) return 'ErrorCounterMustHaveMoreThan3Digits';
// Extract value for third party mask counter
+ $regClientRef = array();
if (preg_match('/\{(c+)(0*)\}/i', $mask, $regClientRef))
{
$maskrefclient = $regClientRef[1].$regClientRef[2];
@@ -1288,31 +1290,24 @@ function check_value($mask, $value)
// Define reg
if ($maskraz > 1 && !preg_match('/^(.*)\{(y+)\}\{(m+)\}/i', $maskwithonlyymcode, $reg)) return 'ErrorCantUseRazInStartedYearIfNoYearMonthInMask';
if ($maskraz <= 1 && !preg_match('/^(.*)\{(y+)\}/i', $maskwithonlyymcode, $reg)) return 'ErrorCantUseRazIfNoYearInMask';
- //print "x".$maskwithonlyymcode." ".$maskraz;
}
- //print "masktri=".$masktri." maskcounter=".$maskcounter." maskraz=".$maskraz." maskoffset=".$maskoffset."
\n";
+ //print "masktri=".$masktri." maskcounter=".$maskcounter." maskwithonlyymcode=".$maskwithonlyymcode." maskwithnocode=".$maskwithnocode." maskraz=".$maskraz." maskoffset=".$maskoffset."
\n";
- // Check we have a number in ($posnumstart+1).', '.dol_strlen($maskcounter)
- //
+ if (function_exists('mb_strrpos')) {
+ $posnumstart = mb_strrpos($maskwithnocode, $maskcounter, 'UTF-8');
+ }
+ else {
+ $posnumstart = strrpos($maskwithnocode, $maskcounter);
+ } // Pos of counter in final string (from 0 to ...)
+ if ($posnumstart < 0) return 'ErrorBadMaskFailedToLocatePosOfSequence';
+
+ // Check we have a number in $value at position ($posnumstart+1).', '.dol_strlen($maskcounter)
+ // TODO
// Check length
$len = dol_strlen($maskwithnocode);
if (dol_strlen($value) != $len) $result = -1;
- // Define $maskLike
- /* seems not used
- $maskLike = dol_string_nospecial($mask);
- $maskLike = str_replace("%","_",$maskLike);
- // Replace protected special codes with matching number of _ as wild card caracter
- $maskLike = str_replace(dol_string_nospecial('{yyyy}'),'____',$maskLike);
- $maskLike = str_replace(dol_string_nospecial('{yy}'),'__',$maskLike);
- $maskLike = str_replace(dol_string_nospecial('{y}'),'_',$maskLike);
- $maskLike = str_replace(dol_string_nospecial('{mm}'),'__',$maskLike);
- $maskLike = str_replace(dol_string_nospecial('{dd}'),'__',$maskLike);
- $maskLike = str_replace(dol_string_nospecial('{'.$masktri.'}'),str_pad("",dol_strlen($maskcounter),"_"),$maskLike);
- if ($maskrefclient) $maskLike = str_replace(dol_string_nospecial('{'.$maskrefclient.'}'),str_pad("",strlen($maskrefclient),"_"),$maskLike);
- */
-
dol_syslog("functions2::check_value result=".$result, LOG_DEBUG);
return $result;
}
diff --git a/htdocs/core/modules/societe/mod_codeclient_elephant.php b/htdocs/core/modules/societe/mod_codeclient_elephant.php
index 22ec06c8aa6..c7a2d600ede 100644
--- a/htdocs/core/modules/societe/mod_codeclient_elephant.php
+++ b/htdocs/core/modules/societe/mod_codeclient_elephant.php
@@ -267,7 +267,8 @@ class mod_codeclient_elephant extends ModeleThirdPartyCode
* -2 ErrorCustomerCodeRequired
* -3 ErrorCustomerCodeAlreadyUsed
* -4 ErrorPrefixRequired
- * -5 Other (see this->error)
+ * -5 NotConfigured - Setup empty so any value may be ok or not
+ * -6 Other (see this->error)
*/
public function verif($db, &$code, $soc, $type)
{
@@ -297,12 +298,11 @@ class mod_codeclient_elephant extends ModeleThirdPartyCode
$this->error = 'NotConfigured';
return -5;
}
-
$result = check_value($mask, $code);
if (is_string($result))
{
$this->error = $result;
- return -5;
+ return -6;
}
}
diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php
index b467fdbd366..9d94c6847b7 100644
--- a/htdocs/fourn/card.php
+++ b/htdocs/fourn/card.php
@@ -180,7 +180,11 @@ if ($object->id > 0)
print '
';
print '| '.$langs->trans("SupplierCode").' | ';
print $object->code_fournisseur;
- if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')';
+ $tmpcheck = $object->check_codefournisseur();
+ var_dump($tmpcheck);
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
+ print ' ('.$langs->trans("WrongSupplierCode").')';
+ }
print ' | ';
print '
';
diff --git a/htdocs/margin/tabs/thirdpartyMargins.php b/htdocs/margin/tabs/thirdpartyMargins.php
index ecb8a3ce764..047edc8cfe2 100644
--- a/htdocs/margin/tabs/thirdpartyMargins.php
+++ b/htdocs/margin/tabs/thirdpartyMargins.php
@@ -101,7 +101,10 @@ if ($socid > 0)
print '| ';
print $langs->trans('CustomerCode').' | ';
print $object->code_client;
- if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')';
+ $tmpcheck = $object->check_codeclient();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
+ print ' ('.$langs->trans("WrongCustomerCode").')';
+ }
print ' |
';
}
@@ -110,7 +113,10 @@ if ($socid > 0)
print '| ';
print $langs->trans('SupplierCode').' | ';
print $object->code_fournisseur;
- if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')';
+ $tmpcheck = $object->check_codefournisseur();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
+ print ' ('.$langs->trans("WrongSupplierCode").')';
+ }
print ' |
';
}
diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php
index d79a5c1a9e0..ea121acc4c7 100644
--- a/htdocs/societe/card.php
+++ b/htdocs/societe/card.php
@@ -2330,7 +2330,10 @@ else
print '| ';
print $langs->trans('CustomerCode').' | ';
print $object->code_client;
- if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')';
+ $tmpcheck = $object->check_codeclient();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
+ print ' ('.$langs->trans("WrongCustomerCode").')';
+ }
print ' | ';
print '
';
}
@@ -2341,7 +2344,10 @@ else
print '| ';
print $langs->trans('SupplierCode').' | ';
print $object->code_fournisseur;
- if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')';
+ $tmpcheck = $object->check_codefournisseur();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
+ print ' ('.$langs->trans("WrongSupplierCode").')';
+ }
print ' | ';
print '
';
}
diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php
index ee91363dba1..35b52243804 100644
--- a/htdocs/societe/class/societe.class.php
+++ b/htdocs/societe/class/societe.class.php
@@ -3018,6 +3018,8 @@ class Societe extends CommonObject
* -2 ErrorCustomerCodeRequired
* -3 ErrorCustomerCodeAlreadyUsed
* -4 ErrorPrefixRequired
+ * -5 NotConfigured - Setup empty so any value may be ok or not
+ * -6 Other (see this->error)
*/
public function check_codeclient()
{
diff --git a/htdocs/societe/consumption.php b/htdocs/societe/consumption.php
index 0ce28356d90..e9514365c0f 100644
--- a/htdocs/societe/consumption.php
+++ b/htdocs/societe/consumption.php
@@ -130,7 +130,10 @@ if ($object->client)
print '| ';
print $langs->trans('CustomerCode').' | ';
print $object->code_client;
- if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')';
+ $tmpcheck = $object->check_codeclient();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
+ print ' ('.$langs->trans("WrongCustomerCode").')';
+ }
print ' |
';
$sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."facture where fk_soc = ".$socid;
$resql = $db->query($sql);
@@ -153,7 +156,10 @@ if ($object->fournisseur)
print '| ';
print $langs->trans('SupplierCode').' | ';
print $object->code_fournisseur;
- if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')';
+ $tmpcheck = $object->check_codefournisseur();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
+ print ' ('.$langs->trans("WrongSupplierCode").')';
+ }
print ' |
';
$sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."commande_fournisseur where fk_soc = ".$socid;
$resql = $db->query($sql);
diff --git a/htdocs/societe/document.php b/htdocs/societe/document.php
index d082ae6baa5..05c6cbd2378 100644
--- a/htdocs/societe/document.php
+++ b/htdocs/societe/document.php
@@ -136,7 +136,10 @@ if ($object->id)
print '| ';
print $langs->trans('CustomerCode').' | ';
print $object->code_client;
- if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')';
+ $tmpcheck = $object->check_codeclient();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
+ print ' ('.$langs->trans("WrongCustomerCode").')';
+ }
print ' |
';
}
@@ -145,7 +148,10 @@ if ($object->id)
print '| ';
print $langs->trans('SupplierCode').' | ';
print $object->code_fournisseur;
- if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')';
+ $tmpcheck = $object->check_codefournisseur();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
+ print ' ('.$langs->trans("WrongSupplierCode").')';
+ }
print ' |
';
}
diff --git a/htdocs/societe/note.php b/htdocs/societe/note.php
index 2e3e3ec4532..63f9ab3b1c6 100644
--- a/htdocs/societe/note.php
+++ b/htdocs/societe/note.php
@@ -99,7 +99,10 @@ if ($object->id > 0)
print '| ';
print $langs->trans('CustomerCode').' | ';
print $object->code_client;
- if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')';
+ $tmpcheck = $object->check_codeclient();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
+ print ' ('.$langs->trans("WrongCustomerCode").')';
+ }
print ' |
';
}
@@ -108,7 +111,10 @@ if ($object->id > 0)
print '| ';
print $langs->trans('SupplierCode').' | ';
print $object->code_fournisseur;
- if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')';
+ $tmpcheck = $object->check_codefournisseur();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
+ print ' ('.$langs->trans("WrongSupplierCode").')';
+ }
print ' |
';
}
diff --git a/htdocs/societe/notify/card.php b/htdocs/societe/notify/card.php
index 191f9c4bb2c..52969ef4008 100644
--- a/htdocs/societe/notify/card.php
+++ b/htdocs/societe/notify/card.php
@@ -174,7 +174,10 @@ if ($result > 0)
print '| ';
print $langs->trans('CustomerCode').' | ';
print $object->code_client;
- if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')';
+ $tmpcheck = $object->check_codeclient();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
+ print ' ('.$langs->trans("WrongCustomerCode").')';
+ }
print ' |
';
}
@@ -183,7 +186,10 @@ if ($result > 0)
print '| ';
print $langs->trans('SupplierCode').' | ';
print $object->code_fournisseur;
- if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')';
+ $tmpcheck = $object->check_codefournisseur();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
+ print ' ('.$langs->trans("WrongSupplierCode").')';
+ }
print ' |
';
}
diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php
index 5894c3245a9..a215b254a55 100644
--- a/htdocs/societe/paymentmodes.php
+++ b/htdocs/societe/paymentmodes.php
@@ -847,7 +847,10 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard'
print '| ';
print $langs->trans('CustomerCode').' | ';
print $object->code_client;
- if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')';
+ $tmpcheck = $object->check_codeclient();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
+ print ' ('.$langs->trans("WrongCustomerCode").')';
+ }
print ' |
';
$sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."facture where fk_soc = ".$socid;
$resql = $db->query($sql);
@@ -899,7 +902,10 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard'
print '| ';
print $langs->trans('SupplierCode').' | ';
print $object->code_fournisseur;
- if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')';
+ $tmpcheck = $object->check_codefournisseur();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
+ print ' ('.$langs->trans("WrongSupplierCode").')';
+ }
print ' |
';
$sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."facture where fk_soc = ".$socid;
$resql = $db->query($sql);
diff --git a/htdocs/societe/price.php b/htdocs/societe/price.php
index df8e966d0ce..7571ae314ef 100644
--- a/htdocs/societe/price.php
+++ b/htdocs/societe/price.php
@@ -212,8 +212,10 @@ if ($object->client) {
print '| ';
print $langs->trans('CustomerCode').' | ';
print $object->code_client;
- if ($object->check_codeclient() != 0)
+ $tmpcheck = $object->check_codeclient();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' ('.$langs->trans("WrongCustomerCode").')';
+ }
print ' |
';
}
@@ -221,8 +223,10 @@ if ($object->fournisseur) {
print '| ';
print $langs->trans('SupplierCode').' | ';
print $object->code_fournisseur;
- if ($object->check_codefournisseur() != 0)
+ $tmpcheck = $object->check_codefournisseur();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' ('.$langs->trans("WrongSupplierCode").')';
+ }
print ' |
';
}
diff --git a/htdocs/societe/project.php b/htdocs/societe/project.php
index 1c2604e0e44..94b453e87d9 100644
--- a/htdocs/societe/project.php
+++ b/htdocs/societe/project.php
@@ -99,7 +99,10 @@ if ($socid)
print '| ';
print $langs->trans('CustomerCode').' | ';
print $object->code_client;
- if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')';
+ $tmpcheck = $object->check_codeclient();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
+ print ' ('.$langs->trans("WrongCustomerCode").')';
+ }
print ' |
';
}
@@ -108,7 +111,10 @@ if ($socid)
print '| ';
print $langs->trans('SupplierCode').' | ';
print $object->code_fournisseur;
- if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')';
+ $tmpcheck = $object->check_codefournisseur();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
+ print ' ('.$langs->trans("WrongSupplierCode").')';
+ }
print ' |
';
}
diff --git a/htdocs/societe/societecontact.php b/htdocs/societe/societecontact.php
index 5ff86ff0064..fdba8d6a461 100644
--- a/htdocs/societe/societecontact.php
+++ b/htdocs/societe/societecontact.php
@@ -193,7 +193,10 @@ if ($id > 0 || !empty($ref))
print '| ';
print $langs->trans('CustomerCode').' | ';
print $object->code_client;
- if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')';
+ $tmpcheck = $object->check_codeclient();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
+ print ' ('.$langs->trans("WrongCustomerCode").')';
+ }
print ' |
';
}
@@ -202,7 +205,10 @@ if ($id > 0 || !empty($ref))
print '| ';
print $langs->trans('SupplierCode').' | ';
print $object->code_fournisseur;
- if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')';
+ $tmpcheck = $object->check_codefournisseur();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
+ print ' ('.$langs->trans("WrongSupplierCode").')';
+ }
print ' |
';
}
print '';
diff --git a/htdocs/societe/website.php b/htdocs/societe/website.php
index e7ebae374e2..109e65c5b04 100644
--- a/htdocs/societe/website.php
+++ b/htdocs/societe/website.php
@@ -213,8 +213,10 @@ if ($object->client) {
print '| ';
print $langs->trans('CustomerCode').' | ';
print $object->code_client;
- if ($object->check_codeclient() != 0)
+ $tmpcheck = $object->check_codeclient();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' ('.$langs->trans("WrongCustomerCode").')';
+ }
print ' |
';
}
@@ -222,8 +224,10 @@ if ($object->fournisseur) {
print '| ';
print $langs->trans('SupplierCode').' | ';
print $object->code_fournisseur;
- if ($object->check_codefournisseur() != 0)
+ $tmpcheck = $object->check_codefournisseur();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' ('.$langs->trans("WrongSupplierCode").')';
+ }
print ' |
';
}
diff --git a/htdocs/ticket/list.php b/htdocs/ticket/list.php
index 40beb75b5e9..8e3b73346b7 100644
--- a/htdocs/ticket/list.php
+++ b/htdocs/ticket/list.php
@@ -441,10 +441,10 @@ if ($socid && !$projectid && !$project_ref && $user->rights->societe->lire) {
print '| ';
print $langs->trans('CustomerCode').' | ';
print $socstat->code_client;
- if ($socstat->check_codeclient() != 0) {
- print ' ('.$langs->trans("WrongCustomerCode").')';
+ $tmpcheck = $socstat->check_codeclient();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
+ print ' ('.$langs->trans("WrongCustomerCode").')';
}
-
print ' | ';
print '
';
}
@@ -453,10 +453,10 @@ if ($socid && !$projectid && !$project_ref && $user->rights->societe->lire) {
print '| ';
print $langs->trans('SupplierCode').' | ';
print $socstat->code_fournisseur;
- if ($socstat->check_codefournisseur() != 0) {
+ $tmpcheck = $socstat->check_codefournisseur();
+ if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' ('.$langs->trans("WrongSupplierCode").')';
}
-
print ' | ';
print '
';
}