diff --git a/htdocs/soc.php b/htdocs/soc.php index 7859f3050d4..96df1c66a96 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 '
'.$langs->trans("NewCompany").'

'; + print_titre($langs->trans("NewCompany")); + print "
\n"; + + print $mesg; print '
'; print ''; print ''; diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index 3a0f814eaac..14a6dfe6242 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); } }