Update for fk_country

This commit is contained in:
aspangaro 2015-11-11 08:52:28 +01:00
parent ca0c68a8e2
commit e157d8b8d2
2 changed files with 37 additions and 8 deletions

View File

@ -182,9 +182,11 @@ class Establishment extends CommonObject
*/
function fetch($id)
{
$sql = "SELECT rowid, name, address, zip, town, status";
$sql.= " FROM ".MAIN_DB_PREFIX."establishment";
$sql.= " WHERE rowid = ".$id;
$sql = "SELECT e.rowid, e.name, e.address, e.zip, e.town, e.status, e.fk_country as country_id,";
$sql.= ' c.code as country_code, c.label as country';
$sql.= " FROM ".MAIN_DB_PREFIX."establishment as e";
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON e.fk_country = c.rowid';
$sql.= " WHERE e.rowid = ".$id;
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$result = $this->db->query($sql);
@ -199,6 +201,10 @@ class Establishment extends CommonObject
$this->town = $obj->town;
$this->status = $obj->status;
$this->country_id = $obj->country_id;
$this->country_code = $obj->country_code;
$this->country = $obj->country;
return 1;
}
else
@ -357,4 +363,22 @@ class Establishment extends CommonObject
if ($withpicto != 2) $result.=$link.$this->name.$linkend;
return $result;
}
/**
* Return account country code
*
* @return string country code
*/
function getCountryCode()
{
global $mysoc;
// We return country code of bank account
if (! empty($this->country_code)) return $this->country_code;
// We return country code of managed company
if (! empty($mysoc->country_code)) return $mysoc->country_code;
return '';
}
}

View File

@ -84,9 +84,7 @@ else if ($action == 'add')
$object->address = GETPOST('address', 'alpha');
$object->zip = GETPOST('zipcode', 'alpha');
$object->town = GETPOST('town', 'alpha');
$object->country_id = GETPOST('country_id','int')?GETPOST('country_id','int'):$mysoc->country_id;
$object->country_id = $object->country_id?$object->country_id:$mysoc->country_id;
$object->country_id = $_POST["country_id"];
$object->country_id = $_POST["country_id"];
$object->status = GETPOST('status','int');
$object->fk_user_author = $user->id;
$object->datec = dol_now();
@ -135,7 +133,7 @@ else if ($action == 'update')
$object->address = GETPOST('address', 'alpha');
$object->zip = GETPOST('zipcode', 'alpha');
$object->town = GETPOST('town', 'alpha');
$object->country_id = GETPOST('country_id', 'int');
$object->country_id = $_POST["country_id"];
$object->fk_user_mod = $user->id;
$result = $object->update();
@ -364,7 +362,14 @@ else if ($id)
// Country
print '<tr>';
print '<td>'.$langs->trans("Country").'</td>';
print '<td colspan="2">'.getCountry($object->fk_country,1).'</td>';
print '<td colspan="2">';
if ($object->country_id > 0)
{
$img=picto_from_langcode($object->country_code);
print $img?$img.' ':'';
print getCountry($object->getCountryCode(),0,$db);
}
print '</td>';
print '</tr>';
// Status