mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
autoaffect individual status for thirdparty
This commit is contained in:
parent
e0551f1e32
commit
6fdff2c3ab
|
|
@ -207,7 +207,7 @@ if (empty($reshook)) {
|
|||
}
|
||||
|
||||
// Create third party from a member
|
||||
if (($action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->rights->societe->creer) || (!empty($conf->global->ADHERENT_DEFAULT_CREATE_THIRDPARTY))) {
|
||||
if (($action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->rights->societe->creer)) {
|
||||
if ($result > 0) {
|
||||
// User creation
|
||||
$company = new Societe($db);
|
||||
|
|
@ -550,7 +550,7 @@ if (empty($reshook)) {
|
|||
$db->commit();
|
||||
$rowid = $object->id;
|
||||
$id = $object->id;
|
||||
$action = '';
|
||||
|
||||
} else {
|
||||
$db->rollback();
|
||||
|
||||
|
|
@ -559,12 +559,41 @@ if (empty($reshook)) {
|
|||
} else {
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
|
||||
$action = 'create';
|
||||
}
|
||||
} else {
|
||||
$action = 'create';
|
||||
}
|
||||
// Auto-create thirdparty on member creation
|
||||
if (!empty($conf->global->ADHERENT_DEFAULT_CREATE_THIRDPARTY)) {
|
||||
if ($result > 0) {
|
||||
// User creation
|
||||
$company = new Societe($db);
|
||||
|
||||
$companyalias = '';
|
||||
$fullname = $object->getFullName($langs);
|
||||
|
||||
if ($object->morphy == 'mor') {
|
||||
$companyname = $object->company;
|
||||
if (!empty($fullname)) {
|
||||
$companyalias = $fullname;
|
||||
}
|
||||
} else {
|
||||
$companyname = $fullname;
|
||||
if (!empty($object->company)) {
|
||||
$companyalias = $object->company;
|
||||
}
|
||||
}
|
||||
|
||||
$result = $company->create_from_member($object, $companyname, $companyalias);
|
||||
|
||||
if ($result < 0) {
|
||||
$langs->load("errors");
|
||||
setEventMessages($langs->trans($company->error), null, 'errors');
|
||||
setEventMessages($company->error, $company->errors, 'errors');
|
||||
}
|
||||
} else {
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
}
|
||||
}
|
||||
$action = ($result < 0 || !$error) ? '' : 'create';
|
||||
}
|
||||
|
||||
if ($user->rights->adherent->supprimer && $action == 'confirm_delete' && $confirm == 'yes') {
|
||||
|
|
|
|||
|
|
@ -868,6 +868,7 @@ class Societe extends CommonObject
|
|||
$sql .= ", name_alias";
|
||||
$sql .= ", entity";
|
||||
$sql .= ", datec";
|
||||
$sql .= ", fk_typent";
|
||||
$sql .= ", fk_user_creat";
|
||||
$sql .= ", canvas";
|
||||
$sql .= ", status";
|
||||
|
|
@ -882,6 +883,7 @@ class Societe extends CommonObject
|
|||
$sql .= ", accountancy_code_sell";
|
||||
$sql .= ") VALUES ('".$this->db->escape($this->name)."', '".$this->db->escape($this->name_alias)."', ".$this->db->escape($this->entity).", '".$this->db->idate($now)."'";
|
||||
$sql .= ", ".(!empty($user->id) ? ((int) $user->id) : "null");
|
||||
$sql .= ", ".(!empty($this->typent_id) ? ((int) $this->typent_id) : "null");
|
||||
$sql .= ", ".(!empty($this->canvas) ? "'".$this->db->escape($this->canvas)."'" : "null");
|
||||
$sql .= ", ".$this->status;
|
||||
$sql .= ", ".(!empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null");
|
||||
|
|
@ -958,7 +960,7 @@ class Societe extends CommonObject
|
|||
* @param array $tags Array of tag to affect to contact
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
public function create_individual(User $user, $no_email, $tags = array())
|
||||
public function create_individual(User $user, $no_email = 0, $tags = array())
|
||||
{
|
||||
global $conf;
|
||||
|
||||
|
|
@ -3793,21 +3795,24 @@ class Societe extends CommonObject
|
|||
$this->client = 1; // A member is a customer by default
|
||||
$this->code_client = ($customercode ? $customercode : -1);
|
||||
$this->code_fournisseur = -1;
|
||||
|
||||
$this->typent_id = ($member->morphy == 'phy' ? 8 : 0); // The type of thirdparty is private (individual) if the member is human (phy)
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
|
||||
// Cree et positionne $this->id
|
||||
$result = $this->create($user);
|
||||
|
||||
if ($result >= 0) {
|
||||
// Auto-create contact on thirdparty creation
|
||||
if (!empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT)) {
|
||||
if (!empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT)) {
|
||||
// Fill fields needed by contact
|
||||
$this->name_bis = $member->lastname;
|
||||
$this->name_bis = $member->lastname;
|
||||
$this->firstname = $member->firstname;
|
||||
$this->civility_id = $member->civility_id;
|
||||
|
||||
dol_syslog("We ask to create a contact/address too", LOG_DEBUG);
|
||||
$result = $this->create_individual($user);
|
||||
|
||||
if ($result < 0) {
|
||||
setEventMessages($this->error, $this->errors, 'errors');
|
||||
$this->db->rollback();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user