FIX Check of customer/vendor code fails in some cases

This commit is contained in:
Laurent Destailleur 2020-12-20 13:54:02 +01:00
parent ba86448bce
commit 8c87050703
17 changed files with 120 additions and 54 deletions

View File

@ -269,7 +269,10 @@ if ($object->id > 0)
print '<tr><td>';
print $langs->trans('CustomerCode').'</td><td>';
print $object->code_client;
if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
$tmpcheck = $object->check_codeclient();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
}
print '</td></tr>';
print '<tr>';

View File

@ -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."<br>\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."<br>\n";
//print "masktri=".$masktri." maskcounter=".$maskcounter." maskwithonlyymcode=".$maskwithonlyymcode." maskwithnocode=".$maskwithnocode." maskraz=".$maskraz." maskoffset=".$maskoffset."<br>\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;
}

View File

@ -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;
}
}

View File

@ -180,7 +180,11 @@ if ($object->id > 0)
print '<tr>';
print '<td class="titlefield">'.$langs->trans("SupplierCode").'</td><td>';
print $object->code_fournisseur;
if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
$tmpcheck = $object->check_codefournisseur();
var_dump($tmpcheck);
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
}
print '</td>';
print '</tr>';

View File

@ -101,7 +101,10 @@ if ($socid > 0)
print '<tr><td class="titlefield">';
print $langs->trans('CustomerCode').'</td><td colspan="3">';
print $object->code_client;
if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
$tmpcheck = $object->check_codeclient();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
}
print '</td></tr>';
}
@ -110,7 +113,10 @@ if ($socid > 0)
print '<tr><td class="titlefield">';
print $langs->trans('SupplierCode').'</td><td colspan="3">';
print $object->code_fournisseur;
if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
$tmpcheck = $object->check_codefournisseur();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
}
print '</td></tr>';
}

View File

@ -2330,7 +2330,10 @@ else
print '<tr><td>';
print $langs->trans('CustomerCode').'</td><td>';
print $object->code_client;
if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
$tmpcheck = $object->check_codeclient();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
}
print '</td>';
print '</tr>';
}
@ -2341,7 +2344,10 @@ else
print '<tr><td>';
print $langs->trans('SupplierCode').'</td><td>';
print $object->code_fournisseur;
if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
$tmpcheck = $object->check_codefournisseur();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
}
print '</td>';
print '</tr>';
}

View File

@ -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()
{

View File

@ -130,7 +130,10 @@ if ($object->client)
print '<tr><td class="titlefield">';
print $langs->trans('CustomerCode').'</td><td colspan="3">';
print $object->code_client;
if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
$tmpcheck = $object->check_codeclient();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
}
print '</td></tr>';
$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 '<tr><td class="titlefield">';
print $langs->trans('SupplierCode').'</td><td colspan="3">';
print $object->code_fournisseur;
if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
$tmpcheck = $object->check_codefournisseur();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
}
print '</td></tr>';
$sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."commande_fournisseur where fk_soc = ".$socid;
$resql = $db->query($sql);

View File

@ -136,7 +136,10 @@ if ($object->id)
print '<tr><td class="titlefield">';
print $langs->trans('CustomerCode').'</td><td colspan="3">';
print $object->code_client;
if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
$tmpcheck = $object->check_codeclient();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
}
print '</td></tr>';
}
@ -145,7 +148,10 @@ if ($object->id)
print '<tr><td class="titlefield">';
print $langs->trans('SupplierCode').'</td><td colspan="3">';
print $object->code_fournisseur;
if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
$tmpcheck = $object->check_codefournisseur();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
}
print '</td></tr>';
}

View File

@ -99,7 +99,10 @@ if ($object->id > 0)
print '<tr><td class="'.$cssclass.'">';
print $langs->trans('CustomerCode').'</td><td colspan="3">';
print $object->code_client;
if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
$tmpcheck = $object->check_codeclient();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
}
print '</td></tr>';
}
@ -108,7 +111,10 @@ if ($object->id > 0)
print '<tr><td class="'.$cssclass.'">';
print $langs->trans('SupplierCode').'</td><td colspan="3">';
print $object->code_fournisseur;
if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
$tmpcheck = $object->check_codefournisseur();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
}
print '</td></tr>';
}

View File

@ -174,7 +174,10 @@ if ($result > 0)
print '<tr><td class="titlefield">';
print $langs->trans('CustomerCode').'</td><td colspan="3">';
print $object->code_client;
if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
$tmpcheck = $object->check_codeclient();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
}
print '</td></tr>';
}
@ -183,7 +186,10 @@ if ($result > 0)
print '<tr><td class="titlefield">';
print $langs->trans('SupplierCode').'</td><td colspan="3">';
print $object->code_fournisseur;
if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
$tmpcheck = $object->check_codefournisseur();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
}
print '</td></tr>';
}

View File

@ -847,7 +847,10 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard'
print '<tr><td class="titlefield">';
print $langs->trans('CustomerCode').'</td><td colspan="2">';
print $object->code_client;
if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
$tmpcheck = $object->check_codeclient();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
}
print '</td></tr>';
$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 '<tr><td class="titlefield">';
print $langs->trans('SupplierCode').'</td><td colspan="2">';
print $object->code_fournisseur;
if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
$tmpcheck = $object->check_codefournisseur();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
}
print '</td></tr>';
$sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."facture where fk_soc = ".$socid;
$resql = $db->query($sql);

View File

@ -212,8 +212,10 @@ if ($object->client) {
print '<tr><td class="titlefield">';
print $langs->trans('CustomerCode').'</td><td colspan="3">';
print $object->code_client;
if ($object->check_codeclient() != 0)
$tmpcheck = $object->check_codeclient();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
}
print '</td></tr>';
}
@ -221,8 +223,10 @@ if ($object->fournisseur) {
print '<tr><td class="titlefield">';
print $langs->trans('SupplierCode').'</td><td colspan="3">';
print $object->code_fournisseur;
if ($object->check_codefournisseur() != 0)
$tmpcheck = $object->check_codefournisseur();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
}
print '</td></tr>';
}

View File

@ -99,7 +99,10 @@ if ($socid)
print '<tr><td class="titlefield">';
print $langs->trans('CustomerCode').'</td><td colspan="3">';
print $object->code_client;
if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
$tmpcheck = $object->check_codeclient();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
}
print '</td></tr>';
}
@ -108,7 +111,10 @@ if ($socid)
print '<tr><td class="titlefield">';
print $langs->trans('SupplierCode').'</td><td colspan="3">';
print $object->code_fournisseur;
if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
$tmpcheck = $object->check_codefournisseur();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
}
print '</td></tr>';
}

View File

@ -193,7 +193,10 @@ if ($id > 0 || !empty($ref))
print '<tr><td class="titlefield">';
print $langs->trans('CustomerCode').'</td><td colspan="3">';
print $object->code_client;
if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
$tmpcheck = $object->check_codeclient();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
}
print '</td></tr>';
}
@ -202,7 +205,10 @@ if ($id > 0 || !empty($ref))
print '<tr><td class="titlefield">';
print $langs->trans('SupplierCode').'</td><td colspan="3">';
print $object->code_fournisseur;
if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
$tmpcheck = $object->check_codefournisseur();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
}
print '</td></tr>';
}
print '</table>';

View File

@ -213,8 +213,10 @@ if ($object->client) {
print '<tr><td class="titlefield">';
print $langs->trans('CustomerCode').'</td><td colspan="3">';
print $object->code_client;
if ($object->check_codeclient() != 0)
$tmpcheck = $object->check_codeclient();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
}
print '</td></tr>';
}
@ -222,8 +224,10 @@ if ($object->fournisseur) {
print '<tr><td class="titlefield">';
print $langs->trans('SupplierCode').'</td><td colspan="3">';
print $object->code_fournisseur;
if ($object->check_codefournisseur() != 0)
$tmpcheck = $object->check_codefournisseur();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
}
print '</td></tr>';
}

View File

@ -441,10 +441,10 @@ if ($socid && !$projectid && !$project_ref && $user->rights->societe->lire) {
print '<tr><td class="titlefield">';
print $langs->trans('CustomerCode').'</td><td>';
print $socstat->code_client;
if ($socstat->check_codeclient() != 0) {
print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
$tmpcheck = $socstat->check_codeclient();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
}
print '</td>';
print '</tr>';
}
@ -453,10 +453,10 @@ if ($socid && !$projectid && !$project_ref && $user->rights->societe->lire) {
print '<tr><td class="titlefield">';
print $langs->trans('SupplierCode').'</td><td>';
print $socstat->code_fournisseur;
if ($socstat->check_codefournisseur() != 0) {
$tmpcheck = $socstat->check_codefournisseur();
if ($tmpcheck != 0 && $tmpcheck != -5) {
print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
}
print '</td>';
print '</tr>';
}