diff --git a/htdocs/soc.php b/htdocs/soc.php index 7859f3050d4f62e90365b7722decbd0eab2ccac0..96df1c66a96ee4cc00f3cea69cba2c44738b5704 100644 --- a/htdocs/soc.php +++ b/htdocs/soc.php @@ -76,7 +76,14 @@ if ($_POST["action"] == 'add' or $_POST["action"] == 'update') if ($_POST["action"] == 'add') { $socid = $soc->create(); - Header("Location: soc.php?socid=$socid"); + + if ($socid > 0) { + Header("Location: soc.php?socid=$socid"); + } + else { + $mesg="Erreur, cette soci�t� existe d�j�"; + $_GET["actions"]='create'; + } } } @@ -99,7 +106,10 @@ if ($_GET["action"] == 'create') if ($_GET["type"]=='c') { $soc->client=1; } if ($_GET["type"]=='p') { $soc->client=2; } - print '<div class="titre">'.$langs->trans("NewCompany").'</div><br>'; + print_titre($langs->trans("NewCompany")); + print "<br>\n"; + + print $mesg; print '<form action="soc.php" method="post">'; print '<input type="hidden" name="action" value="add">'; print '<input type="hidden" name="fournisseur" value="0">'; diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index 3a0f814eaac4ccdd547c484d1b930d0f93afbc1a..14a6dfe6242e6154e0d6a8cb157d2043d4919fb9 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -70,10 +70,14 @@ class Societe { if ($this->db->query($sql) ) { $id = $this->db->last_insert_id(); - $this->update($id); + $result=$this->update($id); + if ($result < 0) { return $result; } return $id; - } + } else { + dolibarr_print_error($this->db); + } + } /* * @@ -102,7 +106,6 @@ class Societe { * TODO simpliste pour l'instant mais remplit 95% des cas * � am�liorer */ - if ($this->departement_id == -1 && $this->pays_id == 1) { if (strlen(trim($this->cp)) == 5) @@ -139,18 +142,20 @@ class Societe { $sql .= ",client = '" . $this->client ."'"; $sql .= ",fournisseur = '" . $this->fournisseur ."'"; $sql .= " WHERE idp = '" . $id ."';"; + if ($this->db->query($sql)) { - return 0; + return 0; } else { - if ($this->db->errno() == 1062) - { - // Doublons sur le prefix commercial - return -1; - } - print $this->db->error(); + if ($this->db->errno() == $this->db->ERROR_DUPLICATE) + { + // Doublon + return -1; + } + + dolibarr_print_error($this->db); } }