diff --git a/htdocs/includes/modules/commande/mod_commande_diamant.php b/htdocs/includes/modules/commande/mod_commande_diamant.php index c3ffacecc5d..5f1b93df7b7 100644 --- a/htdocs/includes/modules/commande/mod_commande_diamant.php +++ b/htdocs/includes/modules/commande/mod_commande_diamant.php @@ -86,11 +86,70 @@ class mod_commande_diamant extends ModeleNumRefCommandes } } - + /** \brief Renvoi prochaine valeur attribuée + * \return string Valeur + */ + function getNextValue() + { + global $db; + + // D'abord on récupère la valeur max (réponse immédiate car champ indéxé) + $cyy=''; + $sql = "SELECT MAX(ref)"; + $sql.= " FROM ".MAIN_DB_PREFIX."commande"; + $resql=$db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + if ($row) $cyy = substr($row[0],0,4); + } + + // Si au moins un champ respectant le modèle a été trouvée + if (eregi('C[0-9][0-9]',$cyy)) + { + // Recherche rapide car restreint par un like sur champ indexé + $posindice=4; + $sql = "SELECT MAX(0+SUBSTRING(ref,$posindice))"; + $sql.= " FROM ".MAIN_DB_PREFIX."commande"; + $sql.= " WHERE ref like '${cyy}%'"; + $resql=$db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + $max = $row[0]; + } + } + else + { + $max=0; + } + + if (!defined("COMMANDE_DIAMANT_DELTA")) + { + define("COMMANDE_DIAMANT_DELTA", 0); + } + $max = $max + COMMANDE_DIAMANT_DELTA; + $yy = strftime("%y",time()); + $num = sprintf("%05s",$max+1); + + return "C$yy$num"; + } + + + /** \brief Renvoie la référence de commande suivante non utilisée + * \param objsoc Objet société + * \return string Texte descripif + */ + function commande_get_num($objsoc=0) + { + return $this->getNextValue(); + } + + /** \brief Renvoie le prochaine numéro de référence de commande non utilisé \param obj_soc objet société \return string numéro de référence de commande non utilisé - */ + function commande_get_num($obj_soc=0) { global $db; @@ -117,5 +176,6 @@ class mod_commande_diamant extends ModeleNumRefCommandes return 'C'.$y.substr("0000".$num, strlen("0000".$num)-5,5); } +*/ } ?> diff --git a/htdocs/includes/modules/commande/mod_commande_jade.php b/htdocs/includes/modules/commande/mod_commande_jade.php index 748827b3d06..1423abc0727 100644 --- a/htdocs/includes/modules/commande/mod_commande_jade.php +++ b/htdocs/includes/modules/commande/mod_commande_jade.php @@ -55,6 +55,14 @@ class mod_commande_jade extends ModeleNumRefCommandes return "Renvoie le numéro sous la forme numérique CYY00001, CYY00002, CYY00003, ... où YY représente l'année. Le numéro d'incrément qui suit l'année n'est PAS remis à zéro en début d'année."; } + /** \brief Renvoi un exemple de numérotation + * \return string Example + */ + function getExample() + { + return "C0600001"; + } + /** \brief Renvoi prochaine valeur attribuée * \return string Valeur */