mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-02-13 03:12:35 +01:00
New: Customer and supplier codes can be automatically generated
This commit is contained in:
@@ -54,10 +54,10 @@ class mod_codeclient_elephant extends ModeleThirdPartyCode
|
||||
{
|
||||
$this->nom = "Elephant";
|
||||
$this->version = "dolibarr";
|
||||
$this->code_null = 0;
|
||||
$this->code_modifiable = 0;
|
||||
$this->code_modifiable_invalide = 1;
|
||||
$this->code_modifiable_null = 1;
|
||||
$this->code_null = 0;
|
||||
$this->code_auto = 1;
|
||||
$this->prefixIsRequired = 0;
|
||||
}
|
||||
@@ -236,18 +236,6 @@ class mod_codeclient_elephant extends ModeleThirdPartyCode
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Renvoi une valeur correcte
|
||||
* \param $db Handler acces base
|
||||
* \param $code Code reference eventuel
|
||||
* \return string Code correct, <0 si KO
|
||||
*/
|
||||
function get_correct($db, $code)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Renvoi si un code est pris ou non (par autre tiers)
|
||||
* \param $db Handler acces base
|
||||
|
||||
@@ -57,10 +57,10 @@ class mod_codeclient_leopard extends ModeleThirdPartyCode
|
||||
{
|
||||
$this->nom = "Leopard";
|
||||
$this->version = "dolibarr";
|
||||
$this->code_null = 1;
|
||||
$this->code_modifiable = 1;
|
||||
$this->code_modifiable_invalide = 1;
|
||||
$this->code_modifiable_null = 1;
|
||||
$this->code_null = 1;
|
||||
$this->code_auto = 0;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ class mod_codeclient_leopard extends ModeleThirdPartyCode
|
||||
* \param $code Code a v<>rifier
|
||||
* \param $soc Objet societe
|
||||
*/
|
||||
function verif($db, $code, $soc)
|
||||
function verif($db, &$code, $soc)
|
||||
{
|
||||
$code = strtoupper(trim($code));
|
||||
|
||||
|
||||
@@ -42,18 +42,20 @@ class mod_codeclient_monkey extends ModeleThirdPartyCode
|
||||
var $version; // 'development', 'experimental', 'dolibarr'
|
||||
var $code_auto; // Numerotation automatique
|
||||
|
||||
var $prefixcustomer='CU';
|
||||
var $prefixsupplier='SU';
|
||||
|
||||
/** \brief Constructeur classe
|
||||
*/
|
||||
function mod_codeclient_monkey()
|
||||
{
|
||||
$this->nom = "Monkey";
|
||||
$this->version = "experimental";
|
||||
$this->code_modifiable = 0;
|
||||
$this->version = "dolibarr";
|
||||
$this->code_null = 1;
|
||||
$this->code_modifiable = 1;
|
||||
$this->code_modifiable_invalide = 1;
|
||||
$this->code_modifiable_null = 1;
|
||||
$this->code_null = 0;
|
||||
$this->code_auto = 0;
|
||||
$this->code_auto = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,16 +64,73 @@ class mod_codeclient_monkey extends ModeleThirdPartyCode
|
||||
*/
|
||||
function info($langs)
|
||||
{
|
||||
return $langs->trans("MonkeyNumRefModelDesc");
|
||||
return $langs->trans("MonkeyNumRefModelDesc",$this->prefixcustomer,$this->prefixsupplier);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Renvoi la description du module
|
||||
* \return string Texte descripif
|
||||
*/
|
||||
function getExample($langs)
|
||||
function getExample($langs,$objsoc=0,$type=-1)
|
||||
{
|
||||
return "000001";
|
||||
return $this->prefixcustomer.'0901-0001<br>'.$this->prefixsupplier.'0901-0001';
|
||||
}
|
||||
|
||||
|
||||
/** \brief Return next value
|
||||
* \param objsoc Object third party
|
||||
* \param $type Client ou fournisseur (1:client, 2:fournisseur)
|
||||
* \return string Value if OK, '' if module not configured, <0 if KO
|
||||
*/
|
||||
function getNextValue($objsoc=0,$type=-1)
|
||||
{
|
||||
global $db, $conf;
|
||||
|
||||
$return='000001';
|
||||
|
||||
$field='';$where='';
|
||||
if ($type == 0)
|
||||
{
|
||||
$field = 'code_client';
|
||||
//$where = ' AND client in (1,2)';
|
||||
}
|
||||
else if ($type == 1)
|
||||
{
|
||||
$field = 'code_fournisseur';
|
||||
//$where = ' AND fournisseur = 1';
|
||||
}
|
||||
else return -1;
|
||||
|
||||
|
||||
if ($type == 0) $prefix=$this->prefixcustomer;
|
||||
if ($type == 1) $prefix=$this->prefixsupplier;
|
||||
|
||||
// D'abord on r<>cup<75>re la valeur max (r<>ponse imm<6D>diate car champ ind<6E>x<EFBFBD>)
|
||||
$posindice=8;
|
||||
$sql = "SELECT MAX(0+SUBSTRING(".$field.",".$posindice.")) as max";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe";
|
||||
$sql.= " WHERE ".$field." LIKE '".$prefix."%'";
|
||||
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
if ($obj) $max = $obj->max;
|
||||
else $max=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_syslog("mod_codeclient_monkey::getNextValue sql=".$sql);
|
||||
return -1;
|
||||
}
|
||||
|
||||
//$date=time();
|
||||
$date=gmmktime();
|
||||
$yymm = strftime("%y%m",$date);
|
||||
$num = sprintf("%04s",$max+1);
|
||||
|
||||
dolibarr_syslog("mod_codeclient_monkey::getNextValue return ".$prefix.$yymm."-".$num);
|
||||
return $prefix.$yymm."-".$num;
|
||||
}
|
||||
|
||||
|
||||
@@ -122,35 +181,6 @@ class mod_codeclient_monkey extends ModeleThirdPartyCode
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Renvoi une valeur correcte
|
||||
* \param $db Handler acces base
|
||||
* \param $code Code reference eventuel
|
||||
* \return string Code correct, <0 si KO
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Renvoi si un code est pris ou non (par autre tiers)
|
||||
* \param $db Handler acces base
|
||||
@@ -193,46 +223,17 @@ class mod_codeclient_monkey extends ModeleThirdPartyCode
|
||||
{
|
||||
$res = 0;
|
||||
|
||||
if (strlen($code) < 3)
|
||||
if (strlen($code) < 11)
|
||||
{
|
||||
$res = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (eregi('[0-9][0-9][0-9]+',$code))
|
||||
{
|
||||
$res = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$res = -2;
|
||||
}
|
||||
|
||||
$res = 0;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Renvoi 0 si numerique, sinon renvoi nb de car non numerique
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -76,8 +76,9 @@ class ModeleThirdPartyCode
|
||||
/** \brief Renvoi prochaine valeur attribu<62>e
|
||||
* \return string Valeur
|
||||
*/
|
||||
function getNextValue($langs)
|
||||
function getNextValue($objsoc=0,$type=-1)
|
||||
{
|
||||
global $langs;
|
||||
return $langs->trans("NotAvailable");
|
||||
}
|
||||
|
||||
@@ -148,10 +149,16 @@ class ModeleThirdPartyCode
|
||||
$s.=$langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide,1,1).'<br>';
|
||||
$s.=$langs->trans("AutomaticCode").': '.yn($this->code_auto,1,1).'<br>';
|
||||
$s.='<br>';
|
||||
if ($type == 0 || $type == -1) $s.=$langs->trans("NextValue").': <b>'.$this->getExample($langs,$soc,0).'</b><br>';
|
||||
if ($type == 1 || $type == -1) $s.=$langs->trans("NextValue").': <b>'.$this->getExample($langs,$soc,1).'</b>';
|
||||
if ($type == 0 || $type == -1) $s.=$langs->trans("NextValue").': <b>'.$this->getNextValue($soc,0).'</b><br>';
|
||||
if ($type == 1 || $type == -1) $s.=$langs->trans("NextValue").': <b>'.$this->getNextValue($soc,1).'</b>';
|
||||
return $s;
|
||||
}
|
||||
|
||||
function verif_prefixIsUsed()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -259,6 +259,6 @@ FiscalYearInformation=Information on the fiscal year
|
||||
FiscalMonthStart=Starting month of the fiscal year
|
||||
|
||||
# Monkey
|
||||
MonkeyNumRefModelDesc=Check that customer/supplier code contains 6 numbers.
|
||||
MonkeyNumRefModelDesc=Return numero with format %syymm-nnnn for customer code and %syymm-nnnn for supplier code where yy is year, mm is month and nnnn is a sequence with no break and no return to 0.
|
||||
# Leopard
|
||||
LeopardNumRefModelDesc=Customer/supplier code is free. This code can be modified at any time.
|
||||
|
||||
@@ -262,6 +262,6 @@ FiscalYearInformation=Information sur l'année fiscale
|
||||
FiscalMonthStart=Mois de début d'exercice
|
||||
|
||||
# Monkey
|
||||
MonkeyNumRefModelDesc=Vérifie que le code client/fournisseur est un nombre sur 6 chiffres, sans ruptures.
|
||||
MonkeyNumRefModelDesc=Renvoie le numéro sous la forme %syymm-nnnn pour les codes clients et %syymm-nnnn pour les codes fournisseurs où yy est l'année, mm le mois et nnnn un compteur séquentiel sans rupture et sans remise à 0.
|
||||
# Leopard
|
||||
LeopardNumRefModelDesc=Code client/fournisseur libre sans vérification. Peut-etre modifié à tout moment.
|
||||
|
||||
Reference in New Issue
Block a user