diff --git a/htdocs/admin/societe.php b/htdocs/admin/societe.php index 7be38bfe744..ec321f43259 100644 --- a/htdocs/admin/societe.php +++ b/htdocs/admin/societe.php @@ -78,6 +78,13 @@ if ($_POST["action"] == 'usesearchtoselectcompany') } } +// défini les constantes du modèle tigre +if ($_POST["action"] == 'updateMask') +{ + dolibarr_set_const($db, "CODE_TIGRE_MASK_CUSTOMER",$_POST["maskcustomer"]); + dolibarr_set_const($db, "CODE_TIGRE_MASK_SUPPLIER",$_POST["masksupplier"]); +} + /* * Affichage page configuration module societe diff --git a/htdocs/includes/modules/societe/mod_codeclient_tigre.php b/htdocs/includes/modules/societe/mod_codeclient_tigre.php index 76554266be1..6f5b8ad3bed 100644 --- a/htdocs/includes/modules/societe/mod_codeclient_tigre.php +++ b/htdocs/includes/modules/societe/mod_codeclient_tigre.php @@ -96,12 +96,157 @@ class mod_codeclient_tigre extends ModeleThirdPartyCode /** \brief Renvoi la description du module - * \return string Texte descripif + * \param $type Client ou fournisseur (1:client, 2:fournisseur) + * \return string Texte descripif */ - function getExample($langs) + function getExample($langs,$objsoc=0,$type=0) { - return "CC0001
CF0001"; + if ($type == 1) + { + $example = $this->buildMask($objsoc,1); + } + else if ($type == 2) + { + $example = $this->buildMask($objsoc,2); + } + else + { + $example = $this->buildMask($objsoc,1)."
".$this->buildMask($objsoc,2); + } + return $example; } + + /** \brief Renvoi prochaine valeur attribuée + * \param $type Client ou fournisseur (1:client, 2:fournisseur) + * \return string Valeur + */ + function getNextValue($type=0) + { + global $db,$conf; + + + // On récupère la valeur max (réponse immédiate car champ indéxé) + $posindice = $this->numbitcounter; + $searchyy=''; + $sql = "SELECT MAX(facnumber)"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture"; + if ($conf->global->FACTURE_NUM_RESTART_BEGIN_YEAR) + { + $sql.= " WHERE facnumber REGEXP '^".$this->searchLast."'"; + } + else if ($facture->type == 2) + { + $sql.= " WHERE type = 2 AND facnumber REGEXP '^".$this->prefixcreditnote."'"; + } + $resql=$db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + if ($row) $searchyy = substr($row[0],0,-$posindice); + } + + // Si au moins un champ respectant le modèle a été trouvée + if (eregi('^'.$this->searchLastWithNoYear.'',$searchyy)) + { + // Recherche rapide car restreint par un like sur champ indexé + $sql = "SELECT MAX(0+SUBSTRING(facnumber,-".$posindice."))"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture"; + $sql.= " WHERE facnumber REGEXP '^".$searchyy."'"; + $resql=$db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + $max = $row[0]; + } + } + else + { + $max=0; + } + + // On replace le prefix de l'avoir + if ($conf->global->AVOIR_NUM_WITH_INVOICE && $facture->type == 2) + { + $this->prefix = $this->prefixcreditnote; + } + + // On applique le nombre de chiffres du compteur + $arg = '%0'.$this->numbitcounter.'s'; + $num = sprintf($arg,$max+1); + $numFinal = ''; + + dolibarr_syslog("mod_codeclient_tigre::getNextValue return ".$numFinal); + return $numFinal; + } + + /** \brief Construction du masque de numérotation + * \param objsoc Objet société + * \param $type Client ou fournisseur (1:client, 2:fournisseur) + * \return string Valeur + */ + function buildMask($objsoc=0,$type='') + { + global $conf; + + if ($type==1) + { + $mask = $conf->global->CODE_TIGRE_MASK_CUSTOMER; + } + else if ($type==2) + { + $mask = $conf->global->CODE_TIGRE_MASK_SUPPLIER; + } + + // Ajout du jour en cours + if (ereg('(\{d{2}\})',$mask)) + { + $mask = ereg_replace('(\{d{2}\})',strftime("%d",time()),$mask); + } + else if (ereg('\{d+\}',$mask) && (ereg('\{d+\}',$mask) != '{dd}')) + { + return -1; + } + + // Ajout du mois en cours + if (ereg('(\{m{2}\})',$mask)) + { + $mask = ereg_replace('(\{m{2}\})',strftime("%m",time()),$mask); + } + else if (ereg('\{m+\}',$mask) && (ereg('\{m+\}',$mask) != '{mm}')) + { + return -2; + } + + // Ajout de l'année en cours + if (ereg('\{a{2}\}',$mask)) + { + $mask = ereg_replace('\{a{2}\}',substr(strftime("%Y",time()),2),$mask); + } + else if (ereg('\{a{4}\}',$mask)) + { + $mask = ereg_replace('\{a{4}\}',strftime("%Y",time()),$mask); + } + else if (ereg('\{a+\}',$mask) && ((ereg('\{a+\}',$mask) != '{aa}') || (ereg('\{a+\}',$mask) != '{aaa}'))) + { + return -3; + } + + //Ajout du préfix de la société + if (is_object($objsoc) && $objsoc->prefix_comm && ereg('\{pre\}',$mask)) + { + $mask = ereg_replace('\{pre\}',strtoupper($objsoc->prefix_comm),$mask); + } + else if (is_object($objsoc) && !$objsoc->prefix_comm && ereg('\{pre\}',$mask)) + { + return -4; + } + else if (!is_object($objsoc) && ereg('\{pre\}',$mask)) + { + $mask = ereg_replace('\{pre\}','ABC',$mask); + } + + return $mask; + } /** diff --git a/htdocs/soc.php b/htdocs/soc.php index f5c24ecc199..3a0350e5ce5 100644 --- a/htdocs/soc.php +++ b/htdocs/soc.php @@ -341,12 +341,19 @@ if ($_POST["getcustomercode"] || $_POST["getsuppliercode"] || print ''.$langs->trans('CustomerCode').''; print '
'; - print ''; + if ($modCodeClient->code_auto == 1) + { + print $langs->trans('AutomaticallyGenerated').' '; + } + else + { + print ''; + } print ''; $s=$langs->trans("CustomerCodeDesc").'
'; $s.=$langs->trans("ValidityControledByModule").': '.$modCodeClient->getNom($langs).'
'; $s.=$langs->trans("RequiredIfCustomer").': '.yn(!$modCodeClient->code_null).'
'; - $s.=$langs->trans("Example").': '.$modCodeClient->getExample($langs).''; + $s.=$langs->trans("Example").': '.$modCodeClient->getExample($langs,$soc,1).''; print $form->textwithhelp('',$s,1); print '
'; @@ -358,14 +365,20 @@ if ($_POST["getcustomercode"] || $_POST["getsuppliercode"] || print $form->selectyesno("fournisseur",$soc->fournisseur,1); print ''; print ''.$langs->trans('SupplierCode').''; - print '
'; - print ''; + if ($modCodeFournisseur->code_auto == 1) + { + print $langs->trans('AutomaticallyGenerated').' '; + } + else + { + print ''; + } print ''; $s=$langs->trans("SupplierCodeDesc").'
'; $s.=$langs->trans("ValidityControledByModule").': '.$modCodeFournisseur->getNom($langs).'
'; $s.=$langs->trans("RequiredIfSupplier").': '.yn(!$modCodeFournisseur->code_null).'
'; - $s.=$langs->trans("Example").': '.$modCodeFournisseur->getExample($langs).''; + $s.=$langs->trans("Example").': '.$modCodeFournisseur->getExample($langs,$soc,2).''; print $form->textwithhelp('',$s,1); print '
'; @@ -673,7 +686,7 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit') $s=$langs->trans("CustomerCodeDesc").'
'; $s.=$langs->trans("ValidityControledByModule").': '.$modCodeClient->getNom($langs).'
'; $s.=$langs->trans("RequiredIfCustomer").': '.yn(!$modCodeClient->code_null).'
'; - $s.=$langs->trans("Example").': '.$modCodeClient->getExample($langs).''; + $s.=$langs->trans("Example").': '.$modCodeClient->getExample($langs,$soc,1).''; print $form->textwithhelp('',$s,1); print ''; @@ -700,7 +713,7 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit') $s=$langs->trans("SupplierCodeDesc").'
'; $s.=$langs->trans("ValidityControledByModule").': '.$modCodeFournisseur->getNom($langs).'
'; $s.=$langs->trans("RequiredIfSupplier").': '.yn(!$modCodeFournisseur->code_null).'
'; - $s.=$langs->trans("Example").': '.$modCodeFournisseur->getExample($langs).''; + $s.=$langs->trans("Example").': '.$modCodeFournisseur->getExample($langs,$soc,2).''; print $form->textwithhelp('',$s,1); print '';