diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 21650cd62f6..90fd1c534ba 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -558,6 +558,77 @@ class Form return $out; } + /** + * Return select list of incoterms + * + * @param string $selected Id or Code of preselected incoterm + * @param string $htmlname Name of html select object + * @param string $htmloption Options html on select object + * @param string $maxlength Max length for labels (0=no limit) + * @return string HTML string with select + */ + function select_incoterms($selected='',$htmlname='incoterm_id',$htmloption='',$maxlength=0) + { + global $conf,$langs; + + $langs->load("dict"); + + $out=''; + $incotermArray=array(); + + $sql = "SELECT rowid, code"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_incoterms"; + $sql.= " WHERE active = 1"; + $sql.= " ORDER BY code ASC"; + + dol_syslog(get_class($this)."::select_incoterm", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $out.= ''; + } + else + { + dol_print_error($this->db); + } + + return $out; + } + /** * Return list of types of lines (product or service) * Example: 0=product, 1=service, 9=other (for external module) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 77673b82ed3..d0cfa7e7f4d 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -352,6 +352,11 @@ class Societe extends CommonObject var $array_options; + // Incoterms + var $fk_incoterms; + var $location_incoterms; + var $libelle_incoterms; //Used into tooltip + /** * To contains a clone of this when we need to save old properties of object */ @@ -424,7 +429,7 @@ class Societe extends CommonObject if ($result >= 0) { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, entity, datec, fk_user_creat, canvas, status, ref_int, ref_ext, fk_stcomm, import_key)"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, entity, datec, fk_user_creat, canvas, status, ref_int, ref_ext, fk_stcomm, fk_incoterms, location_incoterms ,import_key)"; $sql.= " VALUES ('".$this->db->escape($this->name)."', ".$conf->entity.", '".$this->db->idate($now)."'"; $sql.= ", ".(! empty($user->id) ? "'".$user->id."'":"null"); $sql.= ", ".(! empty($this->canvas) ? "'".$this->canvas."'":"null"); @@ -432,6 +437,8 @@ class Societe extends CommonObject $sql.= ", ".(! empty($this->ref_int) ? "'".$this->ref_int."'":"null"); $sql.= ", ".(! empty($this->ref_ext) ? "'".$this->ref_ext."'":"null"); $sql.= ", 0"; + $sql.= ", ".(int) $this->fk_incoterms; + $sql.= ", '".$this->db->escape($this->location_incoterms)."'"; $sql.= ", ".(! empty($this->import_key) ? "'".$this->import_key."'":"null").")"; dol_syslog(get_class($this)."::create", LOG_DEBUG); @@ -731,6 +738,10 @@ class Societe extends CommonObject $this->webservices_url = $this->webservices_url?clean_url($this->webservices_url,0):''; $this->webservices_key = trim($this->webservices_key); + //Incoterms + $this->fk_incoterms = (int) $this->fk_incoterms; + $this->location_incoterms = trim($this->location_incoterms); + $this->db->begin(); // Check name is required and codes are ok or unique. @@ -814,6 +825,10 @@ class Societe extends CommonObject $sql .= ",webservices_url = ".(! empty($this->webservices_url)?"'".$this->db->escape($this->webservices_url)."'":"null"); $sql .= ",webservices_key = ".(! empty($this->webservices_key)?"'".$this->db->escape($this->webservices_key)."'":"null"); + //Incoterms + $sql.= ", fk_incoterms = ".$this->fk_incoterms; + $sql.= ", location_incoterms = ".(! empty($this->location_incoterms)?"'".$this->db->escape($this->location_incoterms)."'":"null"); + if ($customer) { $sql .= ", code_client = ".(! empty($this->code_client)?"'".$this->db->escape($this->code_client)."'":"null"); @@ -976,13 +991,14 @@ class Societe extends CommonObject $sql .= ', s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur, s.parent, s.barcode'; $sql .= ', s.fk_departement, s.fk_pays as country_id, s.fk_stcomm, s.remise_client, s.mode_reglement, s.cond_reglement, s.tva_assuj'; $sql .= ', s.mode_reglement_supplier, s.cond_reglement_supplier, s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo'; - $sql .= ', s.outstanding_limit, s.import_key, s.canvas'; + $sql .= ', s.outstanding_limit, s.import_key, s.canvas, s.fk_incoterms, s.location_incoterms'; $sql .= ', fj.libelle as forme_juridique'; $sql .= ', e.libelle as effectif'; $sql .= ', c.code as country_code, c.label as country'; $sql .= ', d.code_departement as state_code, d.nom as state'; $sql .= ', st.libelle as stcomm'; $sql .= ', te.code as typent_code'; + $sql .= ', i.libelle as libelle_incoterms'; $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as e ON s.fk_effectif = e.id'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid'; @@ -990,6 +1006,7 @@ class Societe extends CommonObject $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as te ON s.fk_typent = te.id'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON s.fk_incoterms = i.rowid'; if ($rowid) $sql .= ' WHERE s.rowid = '.$rowid; if ($ref) $sql .= " WHERE s.nom = '".$this->db->escape($ref)."' AND s.entity IN (".getEntity($this->element, 1).")"; if ($ref_ext) $sql .= " WHERE s.ref_ext = '".$this->db->escape($ref_ext)."' AND s.entity IN (".getEntity($this->element, 1).")"; @@ -1118,6 +1135,11 @@ class Societe extends CommonObject $this->import_key = $obj->import_key; + //Incoterms + $this->fk_incoterms = $obj->fk_incoterms; + $this->location_incoterms = $obj->location_incoterms; + $this->libelle_incoterms = $obj->libelle_incoterms; + $result = 1; // Retreive all extrafield for thirdparty @@ -2067,6 +2089,31 @@ class Societe extends CommonObject $bac->fetch(0,$this->id); return $bac->getRibLabel(true); } + + /** + * Return incoterms informations + * + * @return string Bank number + */ + function display_incoterms() + { + $out = ''; + $this->incoterms_libelle = ''; + if (!empty($this->fk_incoterms)) + { + $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; + $result = $this->db->query($sql); + if ($result) + { + $res = $this->db->fetch_object($result); + $out .= $res->code; + } + } + + $out .= ' - '.$this->location_incoterms; + + return $out; + } /** * Return Array of RIB diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index d0d9c9cbb47..279197b27e1 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -45,6 +45,7 @@ $langs->load("commercial"); $langs->load("bills"); $langs->load("banks"); $langs->load("users"); +if ($conf->incoterm->enabled && !empty($conf->global->INCOTERM_ACTIVATE)) $langs->load("incoterm"); if (! empty($conf->notification->enabled)) $langs->load("mails"); $mesg=''; $error=0; $errors=array(); @@ -191,6 +192,12 @@ if (empty($reshook)) $object->webservices_url = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL); $object->webservices_key = GETPOST('webservices_key', 'san_alpha'); + // Incoterms + if ($conf->incoterm->enabled && !empty($conf->global->INCOTERM_ACTIVATE)) + { + $object->fk_incoterms = GETPOST('incoterm_id', 'int'); + $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); + } // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); @@ -1074,7 +1081,18 @@ else $form->select_users((! empty($object->commercial_id)?$object->commercial_id:$user->id),'commercial_id',1); // Add current user by default print ''; } - + + // Incoterms + if ($conf->incoterm->enabled && !empty($conf->global->INCOTERM_ACTIVATE)) + { + print '
| '; + print $langs->trans('IncotermLabel'); + print ' | '; + if ($user->rights->societe->creer) print ''.img_edit().''; + else print ' '; + print ' |