diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index 10f2912f86d..1d16003e9a5 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -344,6 +344,21 @@ class Propal $client->fetch($this->socidp); $this->client = $client; } + + + /** + * + * + */ + + function fetch_adresse_livraison($id) + { + $adresse = new Societe($this->db); + $adresse->fetch_adresse_livraison($id); + $this->adresse = $adresse; + } + + /** * \brief Supprime une ligne de detail @@ -606,41 +621,6 @@ class Propal } } - if ($this->adresse_livraison_id) - { - $sql = "SELECT name, address, cp, ville, fk_pays"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe_adresse_livraison"; - $sql.= " WHERE rowid = ".$this->adresse_livraison_id; - - $resqladdress = $this->db->query($sql); - - if ($resqladdress) - { - $obja = $this->db->fetch_object($resqladdress); - $this->adresse_livraison_nom = $obja->name; - $this->adresse_livraison_adresse = $obja->address; - $this->adresse_livraison_cp = $obja->cp; - $this->adresse_livraison_ville = $obja->ville; - $this->adresse_livraison_pays_id = $obja->fk_pays; - } - } - - if ($this->adresse_livraison_pays_id) - { - $sql = "SELECT libelle"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_pays"; - $sql.= " WHERE rowid = ".$this->adresse_livraison_pays_id; - - $resqlpays = $this->db->query($sql); - - if ($resqlpays) - { - $objz = $this->db->fetch_object($resqlpays); - $this->adresse_livraison_pays = $objz->libelle; - } - } - - if ($obj->fk_statut == 0) { $this->brouillon = 1; diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index 2bc9a8489d7..8d9e8c1f14e 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -578,6 +578,57 @@ class Societe return $result; } + + /** + * + * Lit une adresse de livraison + * + */ + function fetch_adresse_livraison($id) + { + global $conf; + + $sql = "SELECT l.rowid, l.label, l.fk_societe, l.nom, l.address, l.cp"; + $sql .= ", ".$this->db->pdate("l.tms")."as dm, ".$this->db->pdate("l.datec")."as dc"; + $sql .= ", l.ville, l.fk_departement, l.fk_pays, l.note"; + $sql .= ", d.nom as departement, p.libelle as pays, p.code, s.nom as socname"; + $sql .= " FROM ".MAIN_DB_PREFIX."livraison as l"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d ON l.fk_departement = d.rowid"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_pays as p ON l.fk_pays = p.rowid"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON l.fk_societe = s.idp"; + $sql .= " WHERE l.rowid = $id"; + + $result = $this->db->query($sql) ; + + if ( $result ) + { + $obj = $this->db->fetch_object($result); + + $this->id = $obj->rowid; + $this->datec = $obj->dc; + $this->datem = $obj->dm; + $this->label = $obj->label; + $this->socid = $obj->fk_societe; + $this->societe = $obj->socname; + $this->nom = $obj->nom; + $this->address = $obj->address; + $this->cp = $obj->cp; + $this->ville = $obj->ville; + $this->departement = $obj->departement; + $this->pays = $obj->pays; + $this->code_pays = $obj->code; + + $this->db->free(); + + + return 1; + } + else + { + $this->error=$this->db->error(); + return -1; + } + } /** * \brief Suppression d'une societe de la base avec ses dépendances (contacts, rib...)