From b035b5b208f9805f4355d1524d7c5f7e5509850f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 8 Aug 2004 21:46:14 +0000 Subject: [PATCH] =?UTF-8?q?Fix:=20Probl=E8me=20=E0=20la=20cr=E9ation=20d'u?= =?UTF-8?q?ne=20soci=E9t=E9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/soc.php | 21 +++++++++-------- htdocs/societe.class.php | 49 ++++++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/htdocs/soc.php b/htdocs/soc.php index 96df1c66a96..09a6badb8af 100644 --- a/htdocs/soc.php +++ b/htdocs/soc.php @@ -37,9 +37,10 @@ if ($user->societe_id > 0) $_GET["socid"] = $user->societe_id; } +$soc = new Societe($db); + if ($_POST["action"] == 'add' or $_POST["action"] == 'update') { - $soc = new Societe($db); $soc->nom = $_POST["nom"]; $soc->adresse = $_POST["adresse"]; $soc->cp = $_POST["cp"]; @@ -75,23 +76,25 @@ if ($_POST["action"] == 'add' or $_POST["action"] == 'update') } if ($_POST["action"] == 'add') { - $socid = $soc->create(); + $socid = $soc->create($user); if ($socid > 0) { Header("Location: soc.php?socid=$socid"); } + elseif ($socid == -1) { + $mesg="Erreur, cette société existe déjà sous ce nom ou pour ce prefix commercial"; + $_GET["action"]='create'; + } else { - $mesg="Erreur, cette société existe déjà"; - $_GET["actions"]='create'; + dolibarr_print_error($db); } } } -/* - * - * - */ + llxHeader(); + + $form = new Form($db); if ($_GET["action"] == 'create') @@ -101,7 +104,7 @@ if ($_GET["action"] == 'create') /* * Fiche societe en mode création */ - $soc = new Societe($db); + if ($_GET["type"]=='f') { $soc->fournisseur=1; } if ($_GET["type"]=='c') { $soc->client=1; } if ($_GET["type"]=='p') { $soc->client=2; } diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index f58c5294670..ccbd8afc021 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -62,7 +62,7 @@ class Societe { * * */ - function create() + function create($user='') { $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, datec, datea, client) "; $sql .= " VALUES ('".trim($this->nom)."', now(), now(), '$this->client');"; @@ -70,7 +70,7 @@ class Societe { if ($this->db->query($sql) ) { $id = $this->db->last_insert_id(); - $result=$this->update($id); + $result=$this->update($id,$user); if ($result < 0) { return $result; } return $id; @@ -84,7 +84,7 @@ class Societe { * * */ - function update($id) + function update($id,$user='') { if (strlen(trim($this->nom)) == 0) { @@ -103,8 +103,7 @@ class Societe { /* - * TODO simpliste pour l'instant mais remplit 95% des cas - * à améliorer + * \todo simpliste pour l'instant mais remplit 95% des cas à améliorer */ if ($this->departement_id == -1 && $this->pays_id == 1) { @@ -122,26 +121,26 @@ class Societe { $sql = "UPDATE ".MAIN_DB_PREFIX."societe "; - $sql .= " SET nom = '" . trim($this->nom) ."'"; - $sql .= ",address = '" . trim($this->adresse) ."'"; - $sql .= ",cp = '" . trim($this->cp) ."'"; - $sql .= ",ville = '" . trim($this->ville) ."'"; - $sql .= ",fk_departement = '" . $this->departement_id ."'"; - $sql .= ",fk_pays = '" . $this->pays_id ."'"; - $sql .= ",tel = '" . $this->tel ."'"; - $sql .= ",fax = '" . $this->fax ."'"; - $sql .= ",url = '" . trim($this->url) ."'"; - $sql .= ",siren = '" . trim($this->siren) ."'"; - $sql .= ",siret = '" . trim($this->siret) ."'"; - $sql .= ",ape = '" . trim($this->ape) ."'"; - $sql .= ",prefix_comm = '" . trim($this->prefix_comm) ."'"; - $sql .= ",tva_intra = '" . trim($this->tva_intra) ."'"; - $sql .= ",capital = '" . $this->capital ."'"; - $sql .= ",fk_effectif = '" . $this->effectif_id ."'"; - $sql .= ",fk_forme_juridique = '" . $this->forme_juridique_code ."'"; - $sql .= ",client = '" . $this->client ."'"; - $sql .= ",fournisseur = '" . $this->fournisseur ."'"; - $sql .= " WHERE idp = '" . $id ."';"; + $sql .= " SET nom = '" . trim($this->nom) ."'"; // Champ obligatoire + if (trim($this->adresse)) { $sql .= ",address = '" . trim($this->adresse) ."'"; } + if (trim($this->cp)) { $sql .= ",cp = '" . trim($this->cp) ."'"; } + if (trim($this->ville)) { $sql .= ",ville = '" . trim($this->ville) ."'"; } + if (trim($this->departement_id)) { $sql .= ",fk_departement = '" . $this->departement_id ."'"; } + if (trim($this->pays_id)) { $sql .= ",fk_pays = '" . $this->pays_id ."'"; } + if (trim($this->tel)) { $sql .= ",tel = '" . $this->tel ."'"; } + if (trim($this->fax)) { $sql .= ",fax = '" . $this->fax ."'"; } + if (trim($this->url)) { $sql .= ",url = '" . trim($this->url) ."'"; } + if (trim($this->siren)) { $sql .= ",siren = '" . trim($this->siren) ."'"; } + if (trim($this->siret)) { $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 = '" . $this->capital ."'"; } + if (trim($this->effectif_id)) { $sql .= ",fk_effectif = '" . $this->effectif_id ."'"; } + if (trim($this->forme_juridique)) { $sql .= ",fk_forme_juridique = '" . $this->forme_juridique_code ."'"; } + if (trim($this->client)) { $sql .= ",client = '" . $this->client ."'"; } + if (trim($this->fournisseur)) { $sql .= ",fournisseur = '" . $this->fournisseur ."'"; } + $sql .= " WHERE idp = '" . $id ."'"; if ($this->db->query($sql)) {