diff --git a/htdocs/includes/modules/societe/mod_codeclient_elephant.php b/htdocs/includes/modules/societe/mod_codeclient_elephant.php index 63a2c6f9845..e08c5d05e37 100644 --- a/htdocs/includes/modules/societe/mod_codeclient_elephant.php +++ b/htdocs/includes/modules/societe/mod_codeclient_elephant.php @@ -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 diff --git a/htdocs/includes/modules/societe/mod_codeclient_leopard.php b/htdocs/includes/modules/societe/mod_codeclient_leopard.php index b0eef718a0a..3ea9452e94f 100644 --- a/htdocs/includes/modules/societe/mod_codeclient_leopard.php +++ b/htdocs/includes/modules/societe/mod_codeclient_leopard.php @@ -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)); diff --git a/htdocs/includes/modules/societe/mod_codeclient_monkey.php b/htdocs/includes/modules/societe/mod_codeclient_monkey.php index 6e08a4219e4..68440aa5f72 100644 --- a/htdocs/includes/modules/societe/mod_codeclient_monkey.php +++ b/htdocs/includes/modules/societe/mod_codeclient_monkey.php @@ -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
'.$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ère la valeur max (réponse immédiate car champ indéxé) + $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; - } - } ?> diff --git a/htdocs/includes/modules/societe/modules_societe.class.php b/htdocs/includes/modules/societe/modules_societe.class.php index 3ee966e6bc0..ed86614ff1f 100644 --- a/htdocs/includes/modules/societe/modules_societe.class.php +++ b/htdocs/includes/modules/societe/modules_societe.class.php @@ -76,8 +76,9 @@ class ModeleThirdPartyCode /** \brief Renvoi prochaine valeur attribué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).'
'; $s.=$langs->trans("AutomaticCode").': '.yn($this->code_auto,1,1).'
'; $s.='
'; - if ($type == 0 || $type == -1) $s.=$langs->trans("NextValue").': '.$this->getExample($langs,$soc,0).'
'; - if ($type == 1 || $type == -1) $s.=$langs->trans("NextValue").': '.$this->getExample($langs,$soc,1).''; + if ($type == 0 || $type == -1) $s.=$langs->trans("NextValue").': '.$this->getNextValue($soc,0).'
'; + if ($type == 1 || $type == -1) $s.=$langs->trans("NextValue").': '.$this->getNextValue($soc,1).''; return $s; } + + function verif_prefixIsUsed() + { + return false; + } + } diff --git a/htdocs/langs/en_US/companies.lang b/htdocs/langs/en_US/companies.lang index 1d9acb0d5e8..69f5c9878b1 100644 --- a/htdocs/langs/en_US/companies.lang +++ b/htdocs/langs/en_US/companies.lang @@ -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. diff --git a/htdocs/langs/fr_FR/companies.lang b/htdocs/langs/fr_FR/companies.lang index 9dc45c86b64..83a82dafb96 100644 --- a/htdocs/langs/fr_FR/companies.lang +++ b/htdocs/langs/fr_FR/companies.lang @@ -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.