Qual: Mutualize code. Only one function to build address format.
This commit is contained in:
parent
8e2171b64c
commit
5c3e6de073
@ -1530,40 +1530,6 @@ class Adherent extends CommonObject
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return full address of member
|
||||
*
|
||||
* @param int $withcountry 1=Add country into address string
|
||||
* @param string $sep Separator to use to build string
|
||||
* @return string Full address string
|
||||
*/
|
||||
function getFullAddress($withcountry=0,$sep="\n")
|
||||
{
|
||||
$ret='';
|
||||
if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country)))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php';
|
||||
$tmparray=getCountry($this->country_id,'all');
|
||||
$this->country_code=$tmparray['code'];
|
||||
$this->country =$tmparray['label'];
|
||||
}
|
||||
|
||||
if (in_array($this->country_code,array('US')))
|
||||
{
|
||||
$ret.=($this->address?$this->address.$sep:'');
|
||||
$ret.=trim($this->zip.' '.$this->town);
|
||||
if ($withcountry) $ret.=($this->country?$sep.$this->country:'');
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret.=($this->address?$this->address.$sep:'');
|
||||
$ret.=trim($this->zip.' '.$this->town);
|
||||
if ($withcountry) $ret.=($this->country?$sep.$this->country:'');
|
||||
}
|
||||
return trim($ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne le libelle du statut d'un adherent (brouillon, valide, resilie)
|
||||
*
|
||||
|
||||
@ -866,41 +866,6 @@ class Contact extends CommonObject
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return full address of contact
|
||||
*
|
||||
* @param int $withcountry 1=Add country into address string
|
||||
* @param string $sep Separator to use to build string
|
||||
* @return string Full address string
|
||||
*/
|
||||
function getFullAddress($withcountry=0,$sep="\n")
|
||||
{
|
||||
$ret='';
|
||||
if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country)))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php';
|
||||
$tmparray=getCountry($this->country_id,'all');
|
||||
$this->country_code=$tmparray['code'];
|
||||
$this->country =$tmparray['label'];
|
||||
}
|
||||
|
||||
if (in_array($this->country_code,array('US')))
|
||||
{
|
||||
$ret.=($this->address?$this->address.$sep:'');
|
||||
$ret.=trim($this->zip.' '.$this->town);
|
||||
if ($withcountry) $ret.=($this->country?$sep.$this->country:'');
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret.=($this->address?$this->address.$sep:'');
|
||||
$ret.=trim($this->zip.' '.$this->town);
|
||||
if ($withcountry) $ret.=($this->country?$sep.$this->country:'');
|
||||
}
|
||||
return trim($ret);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return label of a civility contact
|
||||
*
|
||||
|
||||
@ -78,6 +78,26 @@ abstract class CommonObject
|
||||
return dol_trunc($ret,$maxlen);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return full address of contact
|
||||
*
|
||||
* @param int $withcountry 1=Add country into address string
|
||||
* @param string $sep Separator to use to build string
|
||||
* @return string Full address string
|
||||
*/
|
||||
function getFullAddress($withcountry=0,$sep="\n")
|
||||
{
|
||||
if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country)))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php';
|
||||
$tmparray=getCountry($this->country_id,'all');
|
||||
$this->country_code=$tmparray['code'];
|
||||
$this->country =$tmparray['label'];
|
||||
}
|
||||
|
||||
return dol_format_address($this, $withcountry, $sep);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if ref is used.
|
||||
*
|
||||
@ -1558,7 +1578,7 @@ abstract class CommonObject
|
||||
|
||||
// Add revenue stamp to total
|
||||
$this->total_ttc += isset($this->revenuestamp)?$this->revenuestamp:0;
|
||||
|
||||
|
||||
$this->db->free($resql);
|
||||
|
||||
// Now update global field total_ht, total_ttc and tva
|
||||
@ -2139,7 +2159,7 @@ abstract class CommonObject
|
||||
$this->array_options[$key]=$this->db->idate($this->array_options[$key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->db->begin();
|
||||
|
||||
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields WHERE fk_object = ".$this->id;
|
||||
@ -2189,27 +2209,27 @@ abstract class CommonObject
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function to show lines of extrafields with output datas
|
||||
*
|
||||
*
|
||||
* @param object $extrafields extrafield Object
|
||||
* @param string $mode Show output (view) or input (edit) for extrafield
|
||||
*
|
||||
* @return string
|
||||
* @param string $mode Show output (view) or input (edit) for extrafield
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function showOptionals($extrafields,$mode='view')
|
||||
{
|
||||
global $_POST;
|
||||
|
||||
|
||||
$out = '';
|
||||
|
||||
|
||||
if(count($extrafields->attribute_label) > 0)
|
||||
{
|
||||
$out .= "\n";
|
||||
$out .= '<!-- showOptionalsInput --> ';
|
||||
$out .= "\n";
|
||||
|
||||
|
||||
$e = 0;
|
||||
foreach($extrafields->attribute_label as $key=>$label)
|
||||
{
|
||||
@ -2226,7 +2246,7 @@ abstract class CommonObject
|
||||
$out .= '<tr>';
|
||||
$colspan='0';
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
$out .= '<tr>';
|
||||
}
|
||||
@ -2237,7 +2257,7 @@ abstract class CommonObject
|
||||
}
|
||||
$out .= '<td>'.$label.'</td>';
|
||||
$out .='<td colspan="'.$colspan.'">';
|
||||
|
||||
|
||||
switch($mode) {
|
||||
case "view":
|
||||
$out .= $extrafields->showOutputField($key,$value);
|
||||
@ -2246,9 +2266,9 @@ abstract class CommonObject
|
||||
$out .= $extrafields->showInputField($key,$value);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$out .= '</td>'."\n";
|
||||
|
||||
|
||||
if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= '</tr>';
|
||||
else $out .= '</tr>';
|
||||
$e++;
|
||||
|
||||
@ -675,19 +675,21 @@ function dol_get_fiche_end($notab=0)
|
||||
* Return a formated address (part address/zip/town/state) according to country rules
|
||||
*
|
||||
* @param Object $object A company or contact object
|
||||
* @param int $withcountry 1=Add country into address string
|
||||
* @param string $sep Separator to use to build string
|
||||
* @return string Formated string
|
||||
*/
|
||||
function dol_format_address($object)
|
||||
function dol_format_address($object,$withcountry=0,$sep="\n")
|
||||
{
|
||||
$ret='';
|
||||
$countriesusingstate=array('US','IN','GB','ES');
|
||||
$countriesusingstate=array('AU','US','IN','GB','ES');
|
||||
|
||||
// Address
|
||||
$ret .= $object->address;
|
||||
// Zip/Town/State
|
||||
if (in_array($object->country_code,array('US'))) // US: title firstname name \n address lines \n town, state, zip \n country
|
||||
if (in_array($object->country_code,array('US','AU'))) // US: title firstname name \n address lines \n town, state, zip \n country
|
||||
{
|
||||
$ret .= ($ret ? "\n" : '' ).$object->town;
|
||||
$ret .= ($ret ? $sep : '' ).$object->town;
|
||||
if ($object->state && in_array($object->country_code,$countriesusingstate))
|
||||
{
|
||||
$ret.=", ".$object->state;
|
||||
@ -696,16 +698,16 @@ function dol_format_address($object)
|
||||
}
|
||||
else if (in_array($object->country_code,array('GB'))) // UK: title firstname name \n address lines \n town state \n zip \n country
|
||||
{
|
||||
$ret .= ($ret ? "\n" : '' ).$object->town;
|
||||
$ret .= ($ret ? $sep : '' ).$object->town;
|
||||
if ($object->state && in_array($object->country_code,$countriesusingstate))
|
||||
{
|
||||
$ret.=", ".$object->state;
|
||||
}
|
||||
if ($object->zip) $ret .= ($ret ? "\n" : '' ).$object->zip;
|
||||
if ($object->zip) $ret .= ($ret ? $sep : '' ).$object->zip;
|
||||
}
|
||||
else if (in_array($object->country_code,array('ES'))) // title firstname name \n address lines \n zip town \n state \n country
|
||||
else if (in_array($object->country_code,array('ES'))) // ES: title firstname name \n address lines \n zip town \n state \n country
|
||||
{
|
||||
$ret .= ($ret ? "\n" : '' ).$object->zip;
|
||||
$ret .= ($ret ? $sep : '' ).$object->zip;
|
||||
$ret .= ' '.$object->town;
|
||||
if ($object->state && in_array($object->country_code,$countriesusingstate))
|
||||
{
|
||||
@ -715,7 +717,7 @@ function dol_format_address($object)
|
||||
|
||||
else // Other: title firstname name \n address lines \n zip town \n country
|
||||
{
|
||||
$ret .= ($ret ? "\n" : '' ).$object->zip;
|
||||
$ret .= ($ret ? $sep : '' ).$object->zip;
|
||||
$ret .= ' '.$object->town;
|
||||
if ($object->state && in_array($object->country_code,$countriesusingstate))
|
||||
{
|
||||
@ -723,6 +725,8 @@ function dol_format_address($object)
|
||||
}
|
||||
}
|
||||
|
||||
if ($withcountry) $ret.=($object->country?$sep.$object->country:'');
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
@ -2752,18 +2756,18 @@ function get_localtax($tva, $local, $thirdparty_buyer="", $thirdparty_seller="")
|
||||
// Some test to guess with no need to make database access
|
||||
if ($mysoc->country_code == 'ES') // For spain localtaxes 1 and 2, tax is qualified if buyer use local taxe
|
||||
{
|
||||
if ($local == 1)
|
||||
if ($local == 1)
|
||||
{
|
||||
if ($thirdparty_seller->id==$mysoc->id)
|
||||
{
|
||||
if (! $thirdparty_buyer->localtax1_assuj) return 0;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
if (! $thirdparty_seller->localtax1_assuj) return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($local == 2 && ! $thirdparty_buyer->localtax2_assuj) return 0;
|
||||
}
|
||||
else
|
||||
|
||||
@ -1521,40 +1521,6 @@ class Societe extends CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return full address of third party
|
||||
*
|
||||
* @param int $withcountry 1=Add country into address string
|
||||
* @param string $sep Separator to use to build string
|
||||
* @return string Full address string
|
||||
*/
|
||||
function getFullAddress($withcountry=0,$sep="\n")
|
||||
{
|
||||
$ret='';
|
||||
if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country)))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php';
|
||||
$tmparray=getCountry($this->country_id,'all');
|
||||
$this->country_code=$tmparray['code'];
|
||||
$this->country =$tmparray['label'];
|
||||
}
|
||||
|
||||
if (in_array($this->country_code,array('US')))
|
||||
{
|
||||
$ret.=($this->address?$this->address.$sep:'');
|
||||
$ret.=trim($this->zip.' '.$this->town);
|
||||
if ($withcountry) $ret.=($this->country?$sep.$this->country:'');
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret.=($this->address?$this->address.$sep:'');
|
||||
$ret.=trim($this->zip.' '.$this->town);
|
||||
if ($withcountry) $ret.=($this->country?$sep.$this->country:'');
|
||||
}
|
||||
return trim($ret);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return list of contacts emails existing for third party
|
||||
*
|
||||
|
||||
@ -413,6 +413,10 @@ class FunctionsTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$object->country_code='US';
|
||||
$address=dol_format_address($object);
|
||||
$this->assertEquals("21 jump street\nMyTown, MyState, 99999",$address);
|
||||
|
||||
$object->country_code='AU';
|
||||
$address=dol_format_address($object);
|
||||
$this->assertEquals("21 jump street\nMyTown, MyState, 99999",$address);
|
||||
}
|
||||
|
||||
|
||||
@ -444,9 +444,10 @@ class SocieteTest extends PHPUnit_Framework_TestCase
|
||||
$localobjectadd->address='New address';
|
||||
$localobjectadd->zip='New zip';
|
||||
$localobjectadd->town='New town';
|
||||
$localobjectadd->state='New state';
|
||||
$result=$localobjectadd->getFullAddress(1);
|
||||
print __METHOD__." id=".$localobjectadd->id." result=".$result."\n";
|
||||
$this->assertContains("New address\nNew zip New town\nUnited States", $result);
|
||||
$this->assertContains("New address\nNew town, New state, New zip\nUnited States", $result);
|
||||
|
||||
return $localobjectadd->id;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user