Show state in address for us and india

This commit is contained in:
Laurent Destailleur 2010-06-18 22:54:16 +00:00
parent 6296c2ab22
commit ad8440d276
5 changed files with 77 additions and 37 deletions

View File

@ -1226,7 +1226,7 @@ if ($rowid && $action != 'edit')
print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td class="valeur">'.$adh->cp.' '.$adh->ville.'</td></tr>'; print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td class="valeur">'.$adh->cp.' '.$adh->ville.'</td></tr>';
// Country // Country
print '<tr><td>'.$langs->trans("Country").'</td><td class="valeur">'.getCountryLabel($adh->pays_id).'</td></tr>'; print '<tr><td>'.$langs->trans("Country").'</td><td class="valeur">'.getCountry($adh->pays_id).'</td></tr>';
// Department // Department
print '<tr><td>'.$langs->trans('State').'</td><td class="valeur">'.$adh->departement.'</td>'; print '<tr><td>'.$langs->trans('State').'</td><td class="valeur">'.$adh->departement.'</td>';

View File

@ -270,7 +270,7 @@ if ((isset($_GET["action"]) && $_GET["action"] == 'edit')
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("State").'</td><td>'; print '<tr '.$bc[$var].'><td>'.$langs->trans("State").'</td><td>';
$pays_code=getCountryLabel($conf->global->MAIN_INFO_SOCIETE_PAYS,2); $pays_code=getCountry($conf->global->MAIN_INFO_SOCIETE_PAYS,2);
$formcompany->select_departement($conf->global->MAIN_INFO_SOCIETE_DEPARTEMENT,$pays_code,'departement_id'); $formcompany->select_departement($conf->global->MAIN_INFO_SOCIETE_DEPARTEMENT,$pays_code,'departement_id');
print '</td></tr>'."\n"; print '</td></tr>'."\n";
@ -601,7 +601,7 @@ else
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("CompanyCountry").'</td><td>'; print '<tr '.$bc[$var].'><td>'.$langs->trans("CompanyCountry").'</td><td>';
print getCountryLabel($conf->global->MAIN_INFO_SOCIETE_PAYS,1); print getCountry($conf->global->MAIN_INFO_SOCIETE_PAYS,1);
print '</td></tr>'; print '</td></tr>';
$var=!$var; $var=!$var;

View File

@ -180,19 +180,19 @@ function societe_prepare_head2($objsoc)
/** /**
* \brief Retourne le nom traduit ou code+nom d'un pays depuis id * \brief Return country translated from an id
* \param id id of country * \param id id of country
* \param withcode 0=Return label, 1=Return code + label, 2=Return code * \param withcode 0=Return label, 1=Return code + label, 2=Return code
* \return string String with country code or translated country name * \return string String with country code or translated country name
*/ */
function getCountryLabel($id,$withcode=0) function getCountry($id,$withcode=0)
{ {
global $db,$langs; global $db,$langs;
$sql = "SELECT rowid, code, libelle FROM ".MAIN_DB_PREFIX."c_pays"; $sql = "SELECT rowid, code, libelle FROM ".MAIN_DB_PREFIX."c_pays";
$sql.= " WHERE rowid=".$id; $sql.= " WHERE rowid=".$id;
dol_syslog("Company.lib::getCountryLabel sql=".$sql); dol_syslog("Company.lib::getCountry sql=".$sql);
$resql=$db->query($sql); $resql=$db->query($sql);
if ($resql) if ($resql)
{ {
@ -208,8 +208,41 @@ function getCountryLabel($id,$withcode=0)
{ {
return $langs->trans("NotDefined"); return $langs->trans("NotDefined");
} }
$db->free($resql);
} }
else dol_print_error($db,'');
}
/**
* \brief Return state translated from an id
* \param id id of state (province/departement)
* \param withcode 0=Return label, 1=Return code + label, 2=Return code
* \return string String with state code or translated state name
*/
function getState($id,$withcode=0)
{
global $db,$langs;
$sql = "SELECT rowid, code_departement as code, nom as label FROM ".MAIN_DB_PREFIX."c_departements";
$sql.= " WHERE rowid=".$id;
dol_syslog("Company.lib::getState sql=".$sql);
$resql=$db->query($sql);
if ($resql)
{
$obj = $db->fetch_object($resql);
if ($obj)
{
$label=$obj->label;
if ($withcode == 1) return $label=$obj->code?"$obj->code":"$obj->code - $label";
else if ($withcode == 2) return $label=$obj->code;
else return $label;
}
else
{
return $langs->trans("NotDefined");
}
}
else dol_print_error($db,'');
} }
/** /**

View File

@ -49,6 +49,11 @@ function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$target
{ {
$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($sourcecompany->address); $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($sourcecompany->address);
$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($sourcecompany->cp).' '.$outputlangs->convToOutputCharset($sourcecompany->ville); $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($sourcecompany->cp).' '.$outputlangs->convToOutputCharset($sourcecompany->ville);
if (($sourcecompany->departement_id || $sourcecompany->departement) && in_array($sourcecompany->pays_code,array('US','IN')))
{
if ($sourcecompany->departement_id && empty($sourcecompany->departement)) $sourcecompany->departement=getState($sourcecompany->departement_id);
$stringaddress.=" - ".$outputlangs->convToOutputCharset($sourcecompany->departement);
}
$stringaddress .= "\n"; $stringaddress .= "\n";
// Tel // Tel
if ($sourcecompany->tel) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ".$outputlangs->convToOutputCharset($sourcecompany->tel); if ($sourcecompany->tel) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ".$outputlangs->convToOutputCharset($sourcecompany->tel);
@ -68,8 +73,9 @@ function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$target
// Recipient properties // Recipient properties
$stringaddress.="\n".$outputlangs->convToOutputCharset($targetcontact->address); $stringaddress.="\n".$outputlangs->convToOutputCharset($targetcontact->address);
$stringaddress.="\n".$outputlangs->convToOutputCharset($targetcontact->cp) . " " . $outputlangs->convToOutputCharset($targetcontact->ville); $stringaddress.="\n".$outputlangs->convToOutputCharset($targetcontact->cp) . " " . $outputlangs->convToOutputCharset($targetcontact->ville);
if ($targetcompany->departement && in_array($targetcompany->pays_code,array('US','IN'))) if (($targetcompany->departement_id || $targetcompany->departement) && in_array($targetcompany->pays_code,array('US','IN')))
{ {
if ($targetcompany->departement_id && empty($targetcompany->departement)) $targetcompany->departement=getState($targetcompany->departement_id);
$stringaddress.=" - ".$outputlangs->convToOutputCharset($targetcompany->departement); $stringaddress.=" - ".$outputlangs->convToOutputCharset($targetcompany->departement);
} }
$stringaddress.="\n"; $stringaddress.="\n";
@ -80,8 +86,9 @@ function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$target
// Recipient properties // Recipient properties
$stringaddress.="\n".$outputlangs->convToOutputCharset($targetcompany->address); $stringaddress.="\n".$outputlangs->convToOutputCharset($targetcompany->address);
$stringaddress.="\n".$outputlangs->convToOutputCharset($targetcompany->cp) . " " . $outputlangs->convToOutputCharset($targetcompany->ville); $stringaddress.="\n".$outputlangs->convToOutputCharset($targetcompany->cp) . " " . $outputlangs->convToOutputCharset($targetcompany->ville);
if ($targetcompany->departement && in_array($targetcompany->pays_code,array('US','IN'))) if (($targetcompany->departement_id || $targetcompany->departement) && in_array($targetcompany->pays_code,array('US','IN')))
{ {
if ($targetcompany->departement_id && empty($targetcompany->departement)) $targetcompany->departement=getState($targetcompany->departement_id);
$stringaddress.=" - ".$outputlangs->convToOutputCharset($targetcompany->departement); $stringaddress.=" - ".$outputlangs->convToOutputCharset($targetcompany->departement);
} }
$stringaddress.="\n"; $stringaddress.="\n";

View File

@ -34,7 +34,7 @@ class Multicompany
var $error; var $error;
//! Numero de l'erreur //! Numero de l'erreur
var $errno = 0; var $errno = 0;
var $entities = array(); var $entities = array();
/** /**
@ -45,7 +45,7 @@ class Multicompany
function Multicompany($DB) function Multicompany($DB)
{ {
$this->db = $DB; $this->db = $DB;
$this->canvas = "default"; $this->canvas = "default";
$this->name = "admin"; $this->name = "admin";
$this->description = ""; $this->description = "";
@ -56,9 +56,9 @@ class Multicompany
*/ */
function Create($user,$datas) function Create($user,$datas)
{ {
} }
/** /**
* \brief Supression * \brief Supression
*/ */
@ -66,35 +66,35 @@ class Multicompany
{ {
} }
/** /**
* \brief Fetch entity * \brief Fetch entity
*/ */
function fetch($id) function fetch($id)
{ {
global $conf; global $conf;
$sql = "SELECT "; $sql = "SELECT ";
$sql.= $this->db->decrypt('name')." as name"; $sql.= $this->db->decrypt('name')." as name";
$sql.= ", ".$this->db->decrypt('value')." as value"; $sql.= ", ".$this->db->decrypt('value')." as value";
$sql.= " FROM ".MAIN_DB_PREFIX."const"; $sql.= " FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$this->db->decrypt('name')." LIKE 'MAIN_%'"; $sql.= " WHERE ".$this->db->decrypt('name')." LIKE 'MAIN_%'";
$sql.= " AND entity = ".$id; $sql.= " AND entity = ".$id;
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
$num = $this->db->num_rows($result); $num = $this->db->num_rows($result);
$entityDetails = array(); $entityDetails = array();
$i = 0; $i = 0;
while ($i < $num) while ($i < $num)
{ {
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
if (preg_match('/^MAIN_INFO_SOCIETE_PAYS$/i',$obj->name)) if (preg_match('/^MAIN_INFO_SOCIETE_PAYS$/i',$obj->name))
{ {
$entityDetails[$obj->name] = getCountryLabel($obj->value); $entityDetails[$obj->name] = getCountry($obj->value);
} }
else if (preg_match('/^MAIN_MONNAIE$/i',$obj->name)) else if (preg_match('/^MAIN_MONNAIE$/i',$obj->name))
{ {
@ -104,14 +104,14 @@ class Multicompany
{ {
$entityDetails[$obj->name] = $obj->value; $entityDetails[$obj->name] = $obj->value;
} }
$i++; $i++;
} }
return $entityDetails; return $entityDetails;
} }
} }
/** /**
* \brief Enable/disable entity * \brief Enable/disable entity
*/ */
@ -122,46 +122,46 @@ class Multicompany
$sql = "UPDATE ".MAIN_DB_PREFIX."entity"; $sql = "UPDATE ".MAIN_DB_PREFIX."entity";
$sql.= " SET ".$type." = ".$value; $sql.= " SET ".$type." = ".$value;
$sql.= " WHERE rowid = ".$id; $sql.= " WHERE rowid = ".$id;
dol_syslog("Multicompany::setEntity sql=".$sql, LOG_DEBUG); dol_syslog("Multicompany::setEntity sql=".$sql, LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
} }
/** /**
* \brief List of entities * \brief List of entities
*/ */
function getEntities($details=0,$visible=0) function getEntities($details=0,$visible=0)
{ {
global $conf; global $conf;
$sql = "SELECT rowid, label, description, visible, active"; $sql = "SELECT rowid, label, description, visible, active";
$sql.= " FROM ".MAIN_DB_PREFIX."entity"; $sql.= " FROM ".MAIN_DB_PREFIX."entity";
if ($visible) $sql.= " WHERE visible = 1"; if ($visible) $sql.= " WHERE visible = 1";
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
$num = $this->db->num_rows($result); $num = $this->db->num_rows($result);
$i = 0; $i = 0;
while ($i < $num) while ($i < $num)
{ {
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
$this->entities[$i]['id'] = $obj->rowid; $this->entities[$i]['id'] = $obj->rowid;
$this->entities[$i]['label'] = $obj->label; $this->entities[$i]['label'] = $obj->label;
$this->entities[$i]['description'] = $obj->description; $this->entities[$i]['description'] = $obj->description;
$this->entities[$i]['visible'] = $obj->visible; $this->entities[$i]['visible'] = $obj->visible;
$this->entities[$i]['active'] = $obj->active; $this->entities[$i]['active'] = $obj->active;
if ($details) $this->entities[$i]['details'] = $this->fetch($obj->rowid); if ($details) $this->entities[$i]['details'] = $this->fetch($obj->rowid);
$i++; $i++;
} }
} }
} }
/** /**
* \brief Return combo list of entities. * \brief Return combo list of entities.
* \param entities Entities array * \param entities Entities array
@ -170,9 +170,9 @@ class Multicompany
function select_entities($entities,$selected='',$option='') function select_entities($entities,$selected='',$option='')
{ {
$return = '<select class="flat" name="entity" '.$option.'>'; $return = '<select class="flat" name="entity" '.$option.'>';
if (is_array($entities)) if (is_array($entities))
{ {
foreach ($entities as $entity) foreach ($entities as $entity)
{ {
if ($entity['active'] == 1) if ($entity['active'] == 1)
@ -186,7 +186,7 @@ class Multicompany
} }
} }
$return.= '</select>'; $return.= '</select>';
return $return; return $return;
} }
@ -197,13 +197,13 @@ class Multicompany
function assign_smarty_values(&$smarty, $action='') function assign_smarty_values(&$smarty, $action='')
{ {
global $conf,$langs; global $conf,$langs;
$smarty->assign('langs', $langs); $smarty->assign('langs', $langs);
$picto='title.png'; $picto='title.png';
if (empty($conf->browser->firefox)) $picto='title.gif'; if (empty($conf->browser->firefox)) $picto='title.gif';
$smarty->assign('title_picto', img_picto('',$picto)); $smarty->assign('title_picto', img_picto('',$picto));
$smarty->assign('entities',$this->entities); $smarty->assign('entities',$this->entities);
$smarty->assign('img_on',img_picto($langs->trans("Activated"),'on')); $smarty->assign('img_on',img_picto($langs->trans("Activated"),'on'));
$smarty->assign('img_off',img_picto($langs->trans("Disabled"),'off')); $smarty->assign('img_off',img_picto($langs->trans("Disabled"),'off'));