Fix: Problème à la création d'une société.

This commit is contained in:
Laurent Destailleur 2004-08-08 21:46:14 +00:00
parent f5a682c50e
commit b035b5b208
2 changed files with 36 additions and 34 deletions

View File

@ -37,9 +37,10 @@ if ($user->societe_id > 0)
$_GET["socid"] = $user->societe_id; $_GET["socid"] = $user->societe_id;
} }
$soc = new Societe($db);
if ($_POST["action"] == 'add' or $_POST["action"] == 'update') if ($_POST["action"] == 'add' or $_POST["action"] == 'update')
{ {
$soc = new Societe($db);
$soc->nom = $_POST["nom"]; $soc->nom = $_POST["nom"];
$soc->adresse = $_POST["adresse"]; $soc->adresse = $_POST["adresse"];
$soc->cp = $_POST["cp"]; $soc->cp = $_POST["cp"];
@ -75,23 +76,25 @@ if ($_POST["action"] == 'add' or $_POST["action"] == 'update')
} }
if ($_POST["action"] == 'add') if ($_POST["action"] == 'add')
{ {
$socid = $soc->create(); $socid = $soc->create($user);
if ($socid > 0) { if ($socid > 0) {
Header("Location: soc.php?socid=$socid"); 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 { else {
$mesg="Erreur, cette société existe déjà"; dolibarr_print_error($db);
$_GET["actions"]='create';
} }
} }
} }
/*
*
*
*/
llxHeader(); llxHeader();
$form = new Form($db); $form = new Form($db);
if ($_GET["action"] == 'create') if ($_GET["action"] == 'create')
@ -101,7 +104,7 @@ if ($_GET["action"] == 'create')
/* /*
* Fiche societe en mode création * Fiche societe en mode création
*/ */
$soc = new Societe($db);
if ($_GET["type"]=='f') { $soc->fournisseur=1; } if ($_GET["type"]=='f') { $soc->fournisseur=1; }
if ($_GET["type"]=='c') { $soc->client=1; } if ($_GET["type"]=='c') { $soc->client=1; }
if ($_GET["type"]=='p') { $soc->client=2; } if ($_GET["type"]=='p') { $soc->client=2; }

View File

@ -62,7 +62,7 @@ class Societe {
* *
* *
*/ */
function create() function create($user='')
{ {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, datec, datea, client) "; $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, datec, datea, client) ";
$sql .= " VALUES ('".trim($this->nom)."', now(), now(), '$this->client');"; $sql .= " VALUES ('".trim($this->nom)."', now(), now(), '$this->client');";
@ -70,7 +70,7 @@ class Societe {
if ($this->db->query($sql) ) { if ($this->db->query($sql) ) {
$id = $this->db->last_insert_id(); $id = $this->db->last_insert_id();
$result=$this->update($id); $result=$this->update($id,$user);
if ($result < 0) { return $result; } if ($result < 0) { return $result; }
return $id; return $id;
@ -84,7 +84,7 @@ class Societe {
* *
* *
*/ */
function update($id) function update($id,$user='')
{ {
if (strlen(trim($this->nom)) == 0) if (strlen(trim($this->nom)) == 0)
{ {
@ -103,8 +103,7 @@ class Societe {
/* /*
* TODO simpliste pour l'instant mais remplit 95% des cas * \todo simpliste pour l'instant mais remplit 95% des cas à améliorer
* à améliorer
*/ */
if ($this->departement_id == -1 && $this->pays_id == 1) if ($this->departement_id == -1 && $this->pays_id == 1)
{ {
@ -122,26 +121,26 @@ class Societe {
$sql = "UPDATE ".MAIN_DB_PREFIX."societe "; $sql = "UPDATE ".MAIN_DB_PREFIX."societe ";
$sql .= " SET nom = '" . trim($this->nom) ."'"; $sql .= " SET nom = '" . trim($this->nom) ."'"; // Champ obligatoire
$sql .= ",address = '" . trim($this->adresse) ."'"; if (trim($this->adresse)) { $sql .= ",address = '" . trim($this->adresse) ."'"; }
$sql .= ",cp = '" . trim($this->cp) ."'"; if (trim($this->cp)) { $sql .= ",cp = '" . trim($this->cp) ."'"; }
$sql .= ",ville = '" . trim($this->ville) ."'"; if (trim($this->ville)) { $sql .= ",ville = '" . trim($this->ville) ."'"; }
$sql .= ",fk_departement = '" . $this->departement_id ."'"; if (trim($this->departement_id)) { $sql .= ",fk_departement = '" . $this->departement_id ."'"; }
$sql .= ",fk_pays = '" . $this->pays_id ."'"; if (trim($this->pays_id)) { $sql .= ",fk_pays = '" . $this->pays_id ."'"; }
$sql .= ",tel = '" . $this->tel ."'"; if (trim($this->tel)) { $sql .= ",tel = '" . $this->tel ."'"; }
$sql .= ",fax = '" . $this->fax ."'"; if (trim($this->fax)) { $sql .= ",fax = '" . $this->fax ."'"; }
$sql .= ",url = '" . trim($this->url) ."'"; if (trim($this->url)) { $sql .= ",url = '" . trim($this->url) ."'"; }
$sql .= ",siren = '" . trim($this->siren) ."'"; if (trim($this->siren)) { $sql .= ",siren = '" . trim($this->siren) ."'"; }
$sql .= ",siret = '" . trim($this->siret) ."'"; if (trim($this->siret)) { $sql .= ",siret = '" . trim($this->siret) ."'"; }
$sql .= ",ape = '" . trim($this->ape) ."'"; if (trim($this->ape)) { $sql .= ",ape = '" . trim($this->ape) ."'"; }
$sql .= ",prefix_comm = '" . trim($this->prefix_comm) ."'"; if (trim($this->prefix_comm)) { $sql .= ",prefix_comm = '" . trim($this->prefix_comm) ."'"; }
$sql .= ",tva_intra = '" . trim($this->tva_intra) ."'"; if (trim($this->tva_intra)) { $sql .= ",tva_intra = '" . trim($this->tva_intra) ."'"; }
$sql .= ",capital = '" . $this->capital ."'"; if (trim($this->capital)) { $sql .= ",capital = '" . $this->capital ."'"; }
$sql .= ",fk_effectif = '" . $this->effectif_id ."'"; if (trim($this->effectif_id)) { $sql .= ",fk_effectif = '" . $this->effectif_id ."'"; }
$sql .= ",fk_forme_juridique = '" . $this->forme_juridique_code ."'"; if (trim($this->forme_juridique)) { $sql .= ",fk_forme_juridique = '" . $this->forme_juridique_code ."'"; }
$sql .= ",client = '" . $this->client ."'"; if (trim($this->client)) { $sql .= ",client = '" . $this->client ."'"; }
$sql .= ",fournisseur = '" . $this->fournisseur ."'"; if (trim($this->fournisseur)) { $sql .= ",fournisseur = '" . $this->fournisseur ."'"; }
$sql .= " WHERE idp = '" . $id ."';"; $sql .= " WHERE idp = '" . $id ."'";
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {