Amélioration des messages d'erreur

This commit is contained in:
Rodolphe Quiedeville 2004-12-08 13:22:56 +00:00
parent ddb2a32c42
commit e49b5fbef1

View File

@ -101,6 +101,48 @@ 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
*/
function verify()
{
$result = 0;
if (strlen(trim($this->nom)) == 0)
{
$this->error_message = "Le nom de la société ne peut être vide";
$result = -2;
}
$rescode = $this->verif_codeclient();
if ($rescode <> 0)
{
if ($rescode == -1)
{
$this->error_message = "La syntaxe du code client est incorrecte.";
}
if ($rescode == -2)
{
$this->error_message = "Vous devez saisir un code client.";
}
if ($rescode == -3)
{
$this->error_message = "Ce code client est déjà utilisé.";
}
$result = -3;
}
return $result;
}
/** /**
* \brief Mise a jour des paramètres de la société * \brief Mise a jour des paramètres de la société
* \param id id societe * \param id id societe
@ -109,10 +151,12 @@ class Societe {
function update($id, $user='') function update($id, $user='')
{ {
if (strlen(trim($this->nom)) == 0) dolibarr_syslog("Societe::Update");
$result = $this->verify();
if ($result == 0)
{ {
$this->nom = "VALEUR MANQUANTE"; dolibarr_syslog("Societe::Update verify ok");
}
if (strlen(trim($this->capital)) == 0) if (strlen(trim($this->capital)) == 0)
{ {
@ -161,16 +205,26 @@ class Societe {
if (trim($this->pays_id)) if (trim($this->pays_id))
{ $sql .= ",fk_pays = '" . $this->pays_id ."'"; } { $sql .= ",fk_pays = '" . $this->pays_id ."'"; }
if (trim($this->tel)) { $sql .= ",tel = '" . trim($this->tel) ."'"; } if (trim($this->tel))
if (trim($this->fax)) { $sql .= ",fax = '" . trim($this->fax) ."'"; } { $sql .= ",tel = '" . trim($this->tel) ."'"; }
if (trim($this->url)) { $sql .= ",url = '" . trim($this->url) ."'"; } if (trim($this->fax))
if (trim($this->siren)) { $sql .= ",siren = '" . trim($this->siren) ."'"; } { $sql .= ",fax = '" . trim($this->fax) ."'"; }
if (trim($this->siret)) { $sql .= ",siret = '" . trim($this->siret) ."'"; } if (trim($this->url))
if (trim($this->ape)) { $sql .= ",ape = '" . trim($this->ape) ."'"; } { $sql .= ",url = '" . trim($this->url) ."'"; }
if (trim($this->prefix_comm)) { $sql .= ",prefix_comm = '" . trim($this->prefix_comm) ."'"; } if (trim($this->siren))
if (trim($this->tva_intra)) { $sql .= ",tva_intra = '" . trim($this->tva_intra) ."'"; } { $sql .= ",siren = '" . trim($this->siren) ."'"; }
if (trim($this->capital)) { $sql .= ",capital = '" . trim($this->capital) ."'"; } if (trim($this->siret))
if (trim($this->effectif_id)) { $sql .= ",fk_effectif = '" . trim($this->effectif_id) ."'"; } { $sql .= ",siret = '" . trim($this->siret) ."'"; }
if (trim($this->ape))
{ $sql .= ",ape = '" . trim($this->ape) ."'"; }
if (trim($this->prefix_comm))
{ $sql .= ",prefix_comm = '" . trim($this->prefix_comm) ."'"; }
if (trim($this->tva_intra))
{ $sql .= ",tva_intra = '" . trim($this->tva_intra) ."'"; }
if (trim($this->capital))
{ $sql .= ",capital = '" . trim($this->capital) ."'"; }
if (trim($this->effectif_id))
{ $sql .= ",fk_effectif = '" . trim($this->effectif_id) ."'"; }
if (trim($this->forme_juridique_code)) if (trim($this->forme_juridique_code))
{ {
@ -202,25 +256,35 @@ class Societe {
$sql .= ", code_compta = '". $this->code_compta ."'"; $sql .= ", code_compta = '". $this->code_compta ."'";
} }
$sql .= " WHERE idp = '" . $id ."'"; $sql .= " WHERE idp = '" . $id ."'";
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
return 0; $result = 0;
} }
else else
{ {
if ($this->db->errno() == $this->db->ERROR_DUPLICATE) if ($this->db->errno() == $this->db->ERROR_DUPLICATE)
{ {
// Doublon // Doublon
return -1; $this->error_message = "Erreur, le prefix '".$this->prefix_comm."' existe déjà vous devez en choisir un autre";
$result = -1;
}
}
} }
dolibarr_print_error($this->db);
} return $result;
} }
/** /**
* \brief Recupére l'objet societe * \brief Recupére l'objet societe
* \param socid id de la société à charger en mémoire * \param socid id de la société à charger en mémoire
@ -804,6 +868,25 @@ class Societe {
* Renvoie 0 si ok, peut modifier le code client suivant le module utilisé * Renvoie 0 si ok, peut modifier le code client suivant le module utilisé
* *
*/ */
function verif_codeclient()
{
if (defined('CODECLIENT_ADDON') && strlen(CODECLIENT_ADDON) > 0)
{
require_once DOL_DOCUMENT_ROOT.'/includes/modules/societe/'.CODECLIENT_ADDON.'.php';
$var = CODECLIENT_ADDON;
$mod = new $var;
return $mod->verif($this->db, $this->code_client);
}
else
{
return 0;
}
}
function check_codeclient() function check_codeclient()
{ {
if (defined('CODECLIENT_ADDON') && strlen(CODECLIENT_ADDON) > 0) if (defined('CODECLIENT_ADDON') && strlen(CODECLIENT_ADDON) > 0)