Ajout module numrotation automatique tigre
This commit is contained in:
parent
0f9e8b22ab
commit
090bf60f15
@ -49,6 +49,7 @@ class mod_codeclient_tigre extends ModeleThirdPartyCode
|
||||
var $numbitcounter; // Nombre de chiffres du compteur
|
||||
var $substrBegin;
|
||||
var $substrEnd;
|
||||
var $prefixIsRequired;
|
||||
|
||||
|
||||
/** \brief Constructeur classe
|
||||
@ -62,6 +63,7 @@ class mod_codeclient_tigre extends ModeleThirdPartyCode
|
||||
$this->code_modifiable_null = 1;
|
||||
$this->code_null = 0;
|
||||
$this->code_auto = 1;
|
||||
$this->prefixIsRequired = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -284,17 +286,33 @@ class mod_codeclient_tigre extends ModeleThirdPartyCode
|
||||
else if (is_object($objsoc) && !$objsoc->prefix_comm && $maskElement[$i] == '{pre}')
|
||||
{
|
||||
$error++;
|
||||
$this->prefixIsRequired = 1;
|
||||
}
|
||||
else if (!is_object($objsoc) && $maskElement[$i] == '{pre}')
|
||||
{
|
||||
$maskRebuild .= 'ABC';
|
||||
if (is_string($objsoc) && $objsoc)
|
||||
{
|
||||
$prefixLength = strlen($objsoc);
|
||||
$maskRebuild .= $objsoc;
|
||||
}
|
||||
else if (is_bool($objsoc) && $objsoc == 0)
|
||||
{
|
||||
$prefixLength = 3;
|
||||
$maskRebuild .= 'ABC';
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
$this->prefixIsRequired = 1;
|
||||
}
|
||||
|
||||
if ($foundCounter==0)
|
||||
{
|
||||
$substrBegin += 3;
|
||||
$substrBegin += $prefixLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
$substrEnd += 3;
|
||||
$substrEnd += $prefixLength;
|
||||
}
|
||||
}
|
||||
|
||||
@ -355,6 +373,7 @@ class mod_codeclient_tigre extends ModeleThirdPartyCode
|
||||
//print 'begin='.$this->substrBegin.'<br>';
|
||||
//print 'end='.$this->substrEnd.'<br>';
|
||||
//print 'searchcode='.$this->searchcode.'<br>';
|
||||
//print $error;
|
||||
return $maskRebuild;
|
||||
}
|
||||
|
||||
@ -384,6 +403,10 @@ class mod_codeclient_tigre extends ModeleThirdPartyCode
|
||||
{
|
||||
$result=-3;
|
||||
}
|
||||
else if ($soc->prefixIsRequired && !$soc->prefix_comm)
|
||||
{
|
||||
$result=-4;
|
||||
}
|
||||
else
|
||||
{
|
||||
$result=0;
|
||||
@ -414,24 +437,7 @@ class mod_codeclient_tigre extends ModeleThirdPartyCode
|
||||
*/
|
||||
function get_correct($db, $code)
|
||||
{
|
||||
$return='001';
|
||||
|
||||
$sql = "SELECT MAX(code_client) as maxval FROM ".MAIN_DB_PREFIX."societe";
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$obj=$db->fetch_object($resql);
|
||||
if ($obj)
|
||||
{
|
||||
$newval=$obj->maxval+1;
|
||||
$return=sprintf('%03d',$newval);
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -476,23 +482,6 @@ class mod_codeclient_tigre extends ModeleThirdPartyCode
|
||||
function verif_syntax($code)
|
||||
{
|
||||
$res = 0;
|
||||
|
||||
if (strlen($code) < 3)
|
||||
{
|
||||
$res = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (eregi('[0-9][0-9][0-9]+',$code))
|
||||
{
|
||||
$res = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$res = -2;
|
||||
}
|
||||
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
@ -503,17 +492,6 @@ class mod_codeclient_tigre extends ModeleThirdPartyCode
|
||||
function is_num($str)
|
||||
{
|
||||
$ok = 0;
|
||||
|
||||
$alpha = '0123456789';
|
||||
|
||||
for ($i = 0 ; $i < length($str) ; $i++)
|
||||
{
|
||||
if (strpos($alpha, substr($str,$i, 1)) === false)
|
||||
{
|
||||
$ok++;
|
||||
}
|
||||
}
|
||||
|
||||
return $ok;
|
||||
}
|
||||
|
||||
|
||||
@ -158,6 +158,10 @@ if ((! $_POST["getcustomercode"] && ! $_POST["getsuppliercode"])
|
||||
$oldsoc=new Societe($db);
|
||||
$result=$oldsoc->fetch($socid);
|
||||
|
||||
// On vérifie si un tiers devient client ou fournisseur pour l'obtention d'un code automatiqe
|
||||
if (!$soc->client && $soc->code_client == "automaticCode") $soc->code_client = '';
|
||||
if (!$soc->fournisseur && $soc->code_fournisseur == "automaticCode") $soc->code_fournisseur = '';
|
||||
|
||||
$result = $soc->update($socid,$user,1,$oldsoc->codeclient_modifiable(),$oldsoc->codefournisseur_modifiable());
|
||||
if ($result >= 0)
|
||||
{
|
||||
@ -342,6 +346,7 @@ if ($_POST["getcustomercode"] || $_POST["getsuppliercode"] ||
|
||||
print '<table class="nobordernopadding"><tr><td>';
|
||||
if ($modCodeClient->code_auto == 1)
|
||||
{
|
||||
if ($soc->client == 1 || $soc->client == 2) print '<input type="hidden" name="code_client" value="automaticCode">';
|
||||
print $langs->trans('AutomaticallyGenerated').' ';
|
||||
}
|
||||
else
|
||||
@ -364,6 +369,7 @@ if ($_POST["getcustomercode"] || $_POST["getsuppliercode"] ||
|
||||
print '<table class="nobordernopadding"><tr><td>';
|
||||
if ($modCodeFournisseur->code_auto == 1)
|
||||
{
|
||||
if ($soc->fournisseur == 1) print '<input type="hidden" name="code_fournisseur" value="automaticCode">';
|
||||
print $langs->trans('AutomaticallyGenerated').' ';
|
||||
}
|
||||
else
|
||||
@ -616,7 +622,7 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit')
|
||||
$soc->typent_id=$_POST["typent_id"];
|
||||
$soc->effectif_id=$_POST["effectif_id"];
|
||||
|
||||
$soc->tva_assuj = $_POST["assujtva_value"];
|
||||
$soc->tva_assuj = $_POST["assujtva_value"];
|
||||
$soc->tva_intra_code=$_POST["tva_intra_code"];
|
||||
$soc->tva_intra_num=$_POST["tva_intra_num"];
|
||||
|
||||
@ -666,7 +672,12 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit')
|
||||
print '<td width="25%">'.$langs->trans('CustomerCode').'</td><td width="25%">';
|
||||
|
||||
print '<table class="nobordernopadding"><tr><td>';
|
||||
if ($soc->codeclient_modifiable())
|
||||
if (!$soc->code_client && $modCodeClient->code_auto == 1)
|
||||
{
|
||||
if (!$soc->client) print '<input type="hidden" name="code_client" value="automaticCode">';
|
||||
print $langs->trans('AutomaticallyGenerated').' ';
|
||||
}
|
||||
else if ($soc->codeclient_modifiable())
|
||||
{
|
||||
print '<input type="text" name="code_client" size="16" value="'.$soc->code_client.'" maxlength="15">';
|
||||
}
|
||||
@ -676,7 +687,7 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit')
|
||||
print '<input type="hidden" name="code_client" value="'.$soc->code_client.'">';
|
||||
}
|
||||
print '</td><td>';
|
||||
$s=$modCodeClient->getToolTip($langs,$soc,0);
|
||||
$s=$modCodeClient->getToolTip($langs,$soc,0);
|
||||
print $form->textwithhelp('',$s,1);
|
||||
print '</td></tr></table>';
|
||||
|
||||
@ -690,7 +701,12 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit')
|
||||
print '<td>'.$langs->trans('SupplierCode').'</td><td>';
|
||||
|
||||
print '<table class="nobordernopadding"><tr><td>';
|
||||
if ($soc->codefournisseur_modifiable())
|
||||
if (!$soc->code_fournisseur && $modCodeFournisseur->code_auto == 1)
|
||||
{
|
||||
if (!$soc->fournisseur) print '<input type="hidden" name="code_fournisseur" value="automaticCode">';
|
||||
print $langs->trans('AutomaticallyGenerated').' ';
|
||||
}
|
||||
else if ($soc->codefournisseur_modifiable())
|
||||
{
|
||||
print '<input type="text" name="code_fournisseur" size="16" value="'.$soc->code_fournisseur.'" maxlength="15">';
|
||||
}
|
||||
@ -700,7 +716,7 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit')
|
||||
print '<input type="hidden" name="code_fournisseur" value="'.$soc->code_fournisseur.'">';
|
||||
}
|
||||
print '</td><td>';
|
||||
$s=$modCodeFournisseur->getToolTip($langs,$soc,1);
|
||||
$s=$modCodeFournisseur->getToolTip($langs,$soc,1);
|
||||
print $form->textwithhelp('',$s,1);
|
||||
print '</td></tr></table>';
|
||||
|
||||
|
||||
@ -81,6 +81,7 @@ class Societe
|
||||
var $prospect;
|
||||
var $fournisseur;
|
||||
|
||||
var $prefixIsRequired;
|
||||
var $code_client;
|
||||
var $code_fournisseur;
|
||||
var $code_compta;
|
||||
@ -134,6 +135,10 @@ class Societe
|
||||
dolibarr_syslog("Societe::create ".$this->nom);
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
// Pour code automatique
|
||||
if ($this->code_client == "automaticCode") $this->get_codeclient($this->prefix_comm,0);
|
||||
if ($this->code_fournisseur == "automaticCode") $this->get_codefournisseur($this->prefix_comm,1);
|
||||
|
||||
$result = $this->verify();
|
||||
|
||||
@ -241,6 +246,10 @@ class Societe
|
||||
{
|
||||
$this->error .= "Ce code client est déjà utilisé.\n";
|
||||
}
|
||||
if ($rescode == -4)
|
||||
{
|
||||
$this->error .= "Vous devez renseigner le préfix.\n";
|
||||
}
|
||||
$result = -3;
|
||||
}
|
||||
}
|
||||
@ -263,6 +272,10 @@ class Societe
|
||||
{
|
||||
$this->error .= "Ce code fournisseur est déjà utilisé.\n";
|
||||
}
|
||||
if ($rescode == -4)
|
||||
{
|
||||
$this->error .= "Vous devez renseigner le préfix.\n";
|
||||
}
|
||||
$result = -3;
|
||||
}
|
||||
}
|
||||
@ -316,6 +329,10 @@ class Societe
|
||||
|
||||
$this->effectif_id=trim($this->effectif_id);
|
||||
$this->forme_juridique_code=trim($this->forme_juridique_code);
|
||||
|
||||
// Pour code client/fournisseur automatique
|
||||
if ($this->code_client == "automaticCode") $this->get_codeclient($this->prefix_comm,0);
|
||||
if ($this->code_fournisseur == "automaticCode") $this->get_codefournisseur($this->prefix_comm,1);
|
||||
|
||||
$result = $this->verify(); // Verifie que nom obligatoire et code client ok et unique
|
||||
|
||||
@ -1416,6 +1433,45 @@ class Societe
|
||||
return $this->bank_account->verif();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Attribut un code client à partir du module de controle des codes.
|
||||
* \return code_client Code client automatique
|
||||
*/
|
||||
function get_codeclient($objsoc=0,$type=0)
|
||||
{
|
||||
global $conf;
|
||||
if ($conf->global->SOCIETE_CODECLIENT_ADDON)
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/modules/societe/'.$conf->global->SOCIETE_CODECLIENT_ADDON.'.php';
|
||||
$var = $conf->global->SOCIETE_CODECLIENT_ADDON;
|
||||
$mod = new $var;
|
||||
|
||||
$this->code_client = $mod->getNextValue($objsoc,$type);
|
||||
$this->prefixIsRequired = $mod->prefixIsRequired;
|
||||
|
||||
dolibarr_syslog("Societe::get_codeclient code_client=".$this->code_client." module=".$var);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Attribut un code fournisseur à partir du module de controle des codes.
|
||||
* \return code_fournisseur Code fournisseur automatique
|
||||
*/
|
||||
function get_codefournisseur($objsoc=0,$type=1)
|
||||
{
|
||||
global $conf;
|
||||
if ($conf->global->SOCIETE_CODEFOURNISSEUR_ADDON)
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/modules/societe/'.$conf->global->SOCIETE_CODEFOURNISSEUR_ADDON.'.php';
|
||||
$var = $conf->global->SOCIETE_CODEFOURNISSEUR_ADDON;
|
||||
$mod = new $var;
|
||||
|
||||
$this->code_fournisseur = $mod->getNextValue($objsoc,$type);
|
||||
$this->prefixIsRequired = $mod->prefixIsRequired;
|
||||
|
||||
dolibarr_syslog("Societe::get_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$var);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Verifie si un code client est modifiable en fonction des parametres
|
||||
|
||||
Loading…
Reference in New Issue
Block a user