Skip to content

Commit

Permalink
Update information on linked thirdparty
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Aug 29, 2011
1 parent c0c6d1b commit 5120a21
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 22 deletions.
84 changes: 64 additions & 20 deletions htdocs/adherents/class/adherent.class.php
Expand Up @@ -49,9 +49,9 @@ class Adherent extends CommonObject
var $ref;
var $civilite_id;
var $firstname;
var $prenom; // deprecated
var $prenom; // TODO deprecated
var $lastname;
var $nom; // deprecated
var $nom; // TODO deprecated
var $login;
var $pass;
var $societe;
Expand All @@ -62,16 +62,19 @@ class Adherent extends CommonObject
var $ville;
var $town;

var $state_id;
var $state_code;
var $state;
var $fk_departement; // Id of department
var $departement_code; // Code of department
var $departement; // Label of department
var $state_id; // Id of department
var $state_code; // Code of department
var $state; // Label of department
var $fk_departement; // TODO deprecated
var $departement_code; // TODO deprecated
var $departement; // TODO deprecated

var $pays_id;
var $pays_code;
var $pays;
var $country_id;
var $country_code;
var $country;
var $pays_id; // TODO deprecated
var $pays_code; // TODO deprecated
var $pays; // TODO deprecated

var $email;
var $phone;
Expand Down Expand Up @@ -243,6 +246,7 @@ function getmorphylib($morphy='')

/**
* Create a member into database
*
* @param user Objet user qui demande la creation
* @param notrigger 1 ne declenche pas les triggers, 0 sinon
* @return int <0 if KO, >0 if OK
Expand Down Expand Up @@ -363,13 +367,15 @@ function create($user,$notrigger=0)

/**
* Update a member in database (standard information and password)
* @param user User making update
* @param notrigger 1=disable trigger UPDATE (when called by create)
* @param nosyncuser 0=Synchronize linked user (standard info), 1=Do not synchronize linked user
* @param nosyncuserpass 0=Synchronize linked user (password), 1=Do not synchronize linked user
* @return int <0 si KO, >0 si OK
*
* @param user User making update
* @param notrigger 1=disable trigger UPDATE (when called by create)
* @param nosyncuser 0=Synchronize linked user (standard info), 1=Do not synchronize linked user
* @param nosyncuserpass 0=Synchronize linked user (password), 1=Do not synchronize linked user
* @param nosyncthirdparty 0=Synchronize linked thirdparty (standard info), 1=Do not synchronize linked thirdparty
* @return int <0 if KO, >0 if OK
*/
function update($user,$notrigger=0,$nosyncuser=0,$nosyncuserpass=0)
function update($user,$notrigger=0,$nosyncuser=0,$nosyncuserpass=0,$nosyncthirdparty=0)
{
global $conf, $langs;

Expand Down Expand Up @@ -454,7 +460,7 @@ function update($user,$notrigger=0,$nosyncuser=0,$nosyncuserpass=0)
}
}

// Remove link to user
// Remove links to user and replace with new one
if (! $error)
{
dol_syslog(get_class($this)."::update update link to user");
Expand All @@ -474,14 +480,13 @@ function update($user,$notrigger=0,$nosyncuser=0,$nosyncuserpass=0)

if (! $error && $nbrowsaffected) // If something has change in main data
{
// Update information on linked user if it is an update
if ($this->user_id > 0 && ! $nosyncuser)
{
require_once(DOL_DOCUMENT_ROOT."/user/class/user.class.php");

dol_syslog(get_class($this)."::update update linked user");

// This member is linked with a user, so we also update users informations
// if this is an update.
$luser=new User($this->db);
$result=$luser->fetch($this->user_id);

Expand Down Expand Up @@ -517,6 +522,45 @@ function update($user,$notrigger=0,$nosyncuser=0,$nosyncuserpass=0)
}
}

// Update information on linked thirdparty if it is an update
if ($this->fk_soc > 0 && ! $nosyncthirdparty)
{
require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");

dol_syslog(get_class($this)."::update update linked thirdparty");

// This member is linked with a thirdparty, so we also update thirdparty informations
// if this is an update.
$lthirdparty=new Societe($this->db);
$result=$lthirdparty->fetch($this->fk_soc);

if ($result >= 0)
{
$lthirdparty->address=$this->address;
$lthirdparty->zip=$this->zip;
$lthirdparty->town=$this->town;
$lthirdparty->email=$this->email;
$lthirdparty->tel=$this->phone;
$lthirdparty->state_id=$this->state_id;
$lthirdparty->country_id=$this->country_id;
$lthirdparty->pays_id=$this->pays_id;
//$lthirdparty->phone_mobile=$this->phone_mobile;

$result=$lthirdparty->update($this->fk_soc,$user,0,1,1,'update'); // Use sync to 0 to avoid cyclic updates
if ($result < 0)
{
$this->error=$lthirdparty->error;
dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
$error++;
}
}
else
{
$this->error=$lthirdparty->error;
$error++;
}
}

if (! $error && ! $notrigger)
{
$this->use_webcal=($conf->global->PHPWEBCALENDAR_MEMBERSTATUS=='always'?1:0);
Expand Down
3 changes: 2 additions & 1 deletion htdocs/lib/functions.lib.php
Expand Up @@ -3194,6 +3194,7 @@ function get_default_npr($societe_vendeuse, $societe_acheteuse, $idprod)

/**
* Function that return localtax of a product line (according to seller, buyer and product vat rate)
*
* @param societe_vendeuse Objet societe vendeuse
* @param societe_acheteuse Objet societe acheteuse
* @param local Localtax to process (1 or 2)
Expand All @@ -3205,7 +3206,7 @@ function get_default_localtax($societe_vendeuse, $societe_acheteuse, $local, $id
if (!is_object($societe_vendeuse)) return -1;
if (!is_object($societe_acheteuse)) return -1;

if($societe_vendeuse->pays_id=='ES')
if ($societe_vendeuse->pays_id=='ES' || $societe_vendeuse->pays_code=='ES')
{
if ($local==1) //RE
{
Expand Down
2 changes: 1 addition & 1 deletion htdocs/societe/class/societe.class.php
Expand Up @@ -477,7 +477,7 @@ function update($id, $user='', $call_trigger=1, $allowmodcodeclient=0, $allowmod
$sql.= ",ville = ".($this->town?"'".$this->db->escape($this->town)."'":"null");

$sql .= ",fk_departement = '" . ($this->state_id?$this->state_id:'0') ."'";
$sql .= ",fk_pays = '" . ($this->pays_id?$this->pays_id:'0') ."'";
$sql .= ",fk_pays = '" . ($this->country_id?$this->country_id:'0') ."'";

$sql .= ",tel = ".($this->tel?"'".$this->db->escape($this->tel)."'":"null");
$sql .= ",fax = ".($this->fax?"'".$this->db->escape($this->fax)."'":"null");
Expand Down

0 comments on commit 5120a21

Please sign in to comment.