diff --git a/htdocs/includes/modules/societe/mod_codeclient_leopard.php b/htdocs/includes/modules/societe/mod_codeclient_leopard.php index 1393d43874c..bef0704422c 100644 --- a/htdocs/includes/modules/societe/mod_codeclient_leopard.php +++ b/htdocs/includes/modules/societe/mod_codeclient_leopard.php @@ -24,9 +24,26 @@ class mod_codeclient_leopard { + /* + * Attention ce module est utilisé par défaut si aucun module n'a + * été définit dans la configuration + * + * Le fonctionnement de celui-ci doit dont rester le plus ouvert + * possible + */ + function mod_codeclient_leopard() { $this->nom = "Léopard"; + $this->code_modifiable = 1; + + $this->code_modifiable_invalide = 1; // code modifiable si il est invalide + + $this->code_modifiable_null = 1; // code modifiable si il est null + + $this->code_null = 1; + + } function info() diff --git a/htdocs/includes/modules/societe/mod_codeclient_zebre.php b/htdocs/includes/modules/societe/mod_codeclient_zebre.php index 672ab4db4ee..c1ffcbce5d6 100644 --- a/htdocs/includes/modules/societe/mod_codeclient_zebre.php +++ b/htdocs/includes/modules/societe/mod_codeclient_zebre.php @@ -27,6 +27,15 @@ class mod_codeclient_zebre function mod_codeclient_zebre() { $this->nom = "Zèbre"; + + $this->code_modifiable = 0; // code modifiable + + $this->code_modifiable_invalide = 0; // code modifiable si il est invalide + + $this->code_modifiable_null = 1; // code modifiable si il est null + + $this->code_null = 0; // Saisi vide interdite + } /*! \brief Renvoi la description du module * \return string Texte descripif @@ -42,13 +51,13 @@ class mod_codeclient_zebre * */ - function verif($db, $code) + function verif($db, $code, $socid=0) { if ($this->verif_syntax($code) == 0) { $i = 1; - $is_dispo = $this->verif_dispo($db, $code); + $is_dispo = $this->verif_dispo($db, $code, $socid); while ( $is_dispo <> 0 && $i < 99) { diff --git a/htdocs/soc.php b/htdocs/soc.php index 679f518f442..92bd170c11a 100644 --- a/htdocs/soc.php +++ b/htdocs/soc.php @@ -47,30 +47,27 @@ $soc = new Societe($db); if ($_POST["action"] == 'add' or $_POST["action"] == 'update') { - $soc->nom = $_POST["nom"]; - $soc->adresse = $_POST["adresse"]; - $soc->cp = $_POST["cp"]; - $soc->ville = $_POST["ville"]; - $soc->pays_id = $_POST["pays_id"]; - $soc->departement_id = $_POST["departement_id"]; - $soc->tel = $_POST["tel"]; - $soc->fax = $_POST["fax"]; - $soc->url = ereg_replace( "http://", "", $_POST["url"] ); - $soc->siren = $_POST["siren"]; - $soc->siret = $_POST["siret"]; - $soc->ape = $_POST["ape"]; - $soc->prefix_comm = $_POST["prefix_comm"]; - - if (strlen(trim($_POST["code_client"]))) - { - $soc->code_client = $_POST["code_client"]; - } - $soc->capital = $_POST["capital"]; - $soc->tva_intra = $_POST["tva_intra_code"] . $_POST["tva_intra_num"]; - $soc->forme_juridique_code = $_POST["forme_juridique_code"]; - $soc->effectif_id = $_POST["effectif_id"]; - $soc->client = $_POST["client"]; - $soc->fournisseur = $_POST["fournisseur"]; + $soc->nom = $_POST["nom"]; + $soc->adresse = $_POST["adresse"]; + $soc->cp = $_POST["cp"]; + $soc->ville = $_POST["ville"]; + $soc->pays_id = $_POST["pays_id"]; + $soc->departement_id = $_POST["departement_id"]; + $soc->tel = $_POST["tel"]; + $soc->fax = $_POST["fax"]; + $soc->url = ereg_replace( "http://", "", $_POST["url"] ); + $soc->siren = $_POST["siren"]; + $soc->siret = $_POST["siret"]; + $soc->ape = $_POST["ape"]; + $soc->prefix_comm = $_POST["prefix_comm"]; + $soc->code_client = $_POST["code_client"]; + $soc->codeclient_modifiable = $_POST["codeclient_modifiable"]; + $soc->capital = $_POST["capital"]; + $soc->tva_intra = $_POST["tva_intra_code"] . $_POST["tva_intra_num"]; + $soc->forme_juridique_code = $_POST["forme_juridique_code"]; + $soc->effectif_id = $_POST["effectif_id"]; + $soc->client = $_POST["client"]; + $soc->fournisseur = $_POST["fournisseur"]; if ($_POST["action"] == 'update') { @@ -208,6 +205,7 @@ elseif ($_GET["action"] == 'edit') $soc->id = $_GET["socid"]; $soc->fetch($_GET["socid"]); } + if ($soc->error_message) { print '
'; @@ -217,6 +215,7 @@ elseif ($_GET["action"] == 'edit') print '
'; print ''; + print ''; print ''; print ''; @@ -241,15 +240,15 @@ elseif ($_GET["action"] == 'edit') print ''; print ''; print ''; @@ -276,9 +275,9 @@ elseif ($_GET["action"] == 'edit') print ''; print ''; print '
'.$langs->trans('Name').''.$langs->trans('Fax').'
'.$langs->trans('Code client').''; - if ($soc->code_client && $soc->check_codeclient() == 0) - { - print $soc->code_client; - } - else + + if ($soc->codeclient_modifiable == 1) { print ''; } - + else + { + print $soc->code_client; + } print '
'.$langs->trans('Web').'
'.$langs->trans('ProspectCustomer').''.$langs->trans('Supplier').''; diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index 88c7b0cf521..699507e6486 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -67,7 +67,7 @@ class Societe { function Societe($DB, $id=0) { global $config; - + $this->creation_bit = 0; $this->db = $DB; $this->id = $id; $this->client = 0; @@ -75,6 +75,24 @@ class Societe { $this->effectif_id = 0; $this->forme_juridique_code = 0; + if (defined('CODECLIENT_ADDON') && strlen(CODECLIENT_ADDON) > 0) + { + require_once DOL_DOCUMENT_ROOT.'/includes/modules/societe/'.CODECLIENT_ADDON.'.php'; + + $var = CODECLIENT_ADDON; + } + else + { + require_once DOL_DOCUMENT_ROOT.'/includes/modules/societe/mod_code_client_leopard.php'; + + $var = "mod_code_client_leopard"; + } + + $this->mod_codeclient = new $var; + + + $this->codeclient_modifiable = $this->mod_codeclient->modifiable; + return 1; } @@ -99,6 +117,8 @@ class Societe { $this->id = $this->db->last_insert_id(); } + $this->creation_bit = 1; + $result = $this->update($this->id); return $result; @@ -110,10 +130,9 @@ class Societe { } + /** - * \brief Mise a jour des paramètres de la société - * \param id id societe - * \param user Utilisateur qui demande la mise à jour + * \brief Verification lors de la modification */ function verify() { @@ -125,31 +144,37 @@ class Societe { $result = -2; } - $rescode = $this->verif_codeclient(); - - if ($rescode <> 0) + if ($this->codeclient_modifiable) { - if ($rescode == -1) - { - $this->error_message .= "La syntaxe du code client est incorrecte.\n"; - } + // On ne vérifie le code client que si celui-ci est modifiable + // Si il n'est pas modifiable il n'est pas mis à jour lors de l'update - if ($rescode == -2) - { - $this->error_message .= "Vous devez saisir un code client.\n"; - } + $rescode = $this->verif_codeclient(); - if ($rescode == -3) + if ($rescode <> 0) + { + if ($rescode == -1) + { + $this->error_message .= "La syntaxe du code client est incorrecte.\n"; + } + + if ($rescode == -2) + { + $this->error_message .= "Vous devez saisir un code client.\n"; + } + + if ($rescode == -3) { $this->error_message .= "Ce code client est déjà utilisé.\n"; } - - $result = -3; + + $result = -3; + } } + return $result; - } /** @@ -248,7 +273,7 @@ class Societe { $sql .= ",fk_user_modif = '".$user->id."'"; } - if (trim($this->code_client)) + if ($this->creation_bit || $this->codeclient_modifiable) { // Attention check_codeclient peut modifier le code // suivant le module utilisé @@ -349,6 +374,13 @@ $this->error_message = "Erreur, le prefix '".$this->prefix_comm."' existe d $this->capital = $obj->capital; $this->code_client = $obj->code_client; + + if (strlen($this->code_client) == 0 && $this->mod_codeclient->code_modifiable_null == 1) + { + $this->codeclient_modifiable = 1; + } + + $this->code_compta = $obj->code_compta; $this->tva_intra = $obj->tva_intra; @@ -880,7 +912,7 @@ $this->error_message = "Erreur, le prefix '".$this->prefix_comm."' existe d $mod = new $var; - return $mod->verif($this->db, $this->code_client); + return $mod->verif($this->db, $this->code_client, $this->id); } else {