28require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40 public $element =
'societeaccount';
45 public $table_element =
'societe_account';
50 public $ismultientitymanaged = 0;
55 public $picto =
'lock';
79 public $fields = array(
80 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'visible'=>-2,
'enabled'=>1,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
'Id',),
81 'entity' => array(
'type'=>
'integer',
'label'=>
'Entity',
'visible'=>0,
'enabled'=>1,
'position'=>5,
'default'=>1),
82 'login' => array(
'type'=>
'varchar(64)',
'label'=>
'Login',
'visible'=>1,
'enabled'=>1,
'notnull'=>1,
'position'=>10,
'showoncombobox'=>1),
83 'pass_encoding' => array(
'type'=>
'varchar(24)',
'label'=>
'PassEncoding',
'visible'=>0,
'enabled'=>1,
'position'=>30),
84 'pass_crypted' => array(
'type'=>
'varchar(128)',
'label'=>
'Password',
'visible'=>1,
'enabled'=>1,
'position'=>31,
'notnull'=>1),
85 'pass_temp' => array(
'type'=>
'varchar(128)',
'label'=>
'Temp',
'visible'=>0,
'enabled'=>0,
'position'=>32,
'notnull'=>-1,),
86 'fk_soc' => array(
'type'=>
'integer:Societe:societe/class/societe.class.php',
'label'=>
'ThirdParty',
'visible'=>1,
'enabled'=>1,
'position'=>40,
'notnull'=>-1,
'index'=>1),
87 'fk_website' => array(
'type'=>
'integer:Website:website/class/website.class.php',
'label'=>
'WebSite',
'visible'=>1,
'enabled'=>1,
'position'=>42,
'notnull'=>-1,
'index'=>1),
88 'site' => array(
'type'=>
'varchar(128)',
'label'=>
'ExternalSite',
'visible'=>0,
'enabled'=>1,
'position'=>43,
'help'=>
'Name of the website or service if this is account on an external website or service'),
89 'site_account' => array(
'type'=>
'varchar(128)',
'label'=>
'ExternalSiteAccount',
'visible'=>0,
'enabled'=>1,
'position'=>44,
'help'=>
'A key to identify the account on external web site if this is an account on an external website'),
90 'key_account' => array(
'type'=>
'varchar(128)',
'label'=>
'KeyAccount',
'visible'=>0,
'enabled'=>1,
'position'=>48,
'notnull'=>0,
'index'=>1,
'searchall'=>1,
'comment'=>
'The id of third party in the external web site (for site_account if site_account defined)',),
91 'date_last_login' => array(
'type'=>
'datetime',
'label'=>
'LastConnexion',
'visible'=>2,
'enabled'=>1,
'position'=>50,
'notnull'=>0,),
92 'date_previous_login' => array(
'type'=>
'datetime',
'label'=>
'PreviousConnexion',
'visible'=>2,
'enabled'=>1,
'position'=>51,
'notnull'=>0,),
94 'note_private' => array(
'type'=>
'html',
'label'=>
'NotePrivate',
'visible'=>-1,
'enabled'=>1,
'position'=>46,
'notnull'=>-1,),
95 'date_creation' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'visible'=>-2,
'enabled'=>1,
'position'=>500,
'notnull'=>1,),
96 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'visible'=>-2,
'enabled'=>1,
'position'=>500,
'notnull'=>1,),
97 'fk_user_creat' => array(
'type'=>
'integer',
'label'=>
'UserAuthor',
'visible'=>-2,
'enabled'=>1,
'position'=>500,
'notnull'=>1,),
98 'fk_user_modif' => array(
'type'=>
'integer',
'label'=>
'UserModif',
'visible'=>-2,
'enabled'=>1,
'position'=>500,
'notnull'=>-1,),
99 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'visible'=>-2,
'enabled'=>1,
'position'=>1000,
'notnull'=>-1,
'index'=>1,),
100 'status' => array(
'type'=>
'integer',
'label'=>
'Status',
'visible'=>1,
'enabled'=>1,
'position'=>1000,
'notnull'=>1,
'index'=>1,
'default'=>1,
'arrayofkeyval'=>array(
'1'=>
'Active',
'0'=>
'Disabled')),
115 public $pass_encoding;
116 public $pass_crypted;
125 public $site_account;
130 public $date_last_login;
133 public $date_previous_login;
134 public $note_private;
139 public $date_creation;
147 public $fk_user_creat;
152 public $fk_user_modif;
175 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
176 $this->fields[
'rowid'][
'visible'] = 0;
201 global $hookmanager, $langs;
206 $object =
new self($this->db);
211 $object->fetchCommon($fromid);
214 unset($object->fk_user_creat);
215 unset($object->import_key);
218 $object->ref =
"copy_of_".$object->ref;
222 $object->context[
'createfromclone'] =
'createfromclone';
223 $result = $object->createCommon($user);
226 $this->error = $object->error;
227 $this->errors = $object->errors;
230 unset($object->context[
'createfromclone']);
237 $this->db->rollback();
249 public function fetch($id, $ref =
null)
252 if ($result > 0 && !empty($this->table_element_line)) {
265 $this->lines = array();
269 return count($this->lines) ? 1 : 0;
284 $sql =
"SELECT sa.key_account as key_account, sa.entity";
285 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_account as sa";
286 $sql .=
" WHERE sa.fk_soc = ".((int) $id);
287 $sql .=
" AND sa.entity IN (".getEntity(
'societe').
")";
288 $sql .=
" AND sa.site = '".$this->db->escape($site).
"' AND sa.status = ".((int) $status);
289 $sql .=
" AND sa.key_account IS NOT NULL AND sa.key_account <> ''";
290 $sql .=
" AND (sa.site_account = '' OR sa.site_account IS NULL OR sa.site_account = '".$this->db->escape($site_account).
"')";
291 $sql .=
" ORDER BY sa.site_account DESC";
293 dol_syslog(get_class($this).
"::getCustomerAccount Try to find the first system customer id for ".$site.
" of thirdparty id=".$id.
" (exemple: cus_.... for stripe)", LOG_DEBUG);
294 $result = $this->db->query($sql);
296 if ($this->db->num_rows($result)) {
297 $obj = $this->db->fetch_object($result);
298 $key = $obj->key_account;
322 $sql =
"SELECT sa.fk_soc as fk_soc, sa.key_account, sa.entity";
323 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_account as sa";
324 $sql .=
" WHERE sa.key_account = '".$this->db->escape($id).
"'";
325 $sql .=
" AND sa.entity IN (".getEntity(
'societe').
")";
326 $sql .=
" AND sa.site = '".$this->db->escape($site).
"' AND sa.status = ".((int) $status);
327 $sql .=
" AND sa.fk_soc > 0";
329 dol_syslog(get_class($this).
"::getCustomerAccount Try to find the first thirdparty id for ".$site.
" for external id=".$id, LOG_DEBUG);
330 $result = $this->db->query($sql);
332 if ($this->db->num_rows($result)) {
333 $obj = $this->db->fetch_object($result);
334 $socid = $obj->fk_soc;
360 public function delete(
User $user, $notrigger =
false)
373 global $conf, $langs, $user;
375 $langs->loadLangs([
'companies, commercial']);
378 $option = $params[
'option'] ??
'';
380 $datas[
'picto'] =
'<u>'.$langs->trans(
"WebsiteAccount").
'</u>';
381 $datas[
'login'] =
'<br><b>'.$langs->trans(
'Login').
':</b> '.$this->login;
396 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
398 global $db, $conf, $langs;
399 global $dolibarr_main_authentication, $dolibarr_main_demo;
402 if (!empty($conf->dol_no_mouse_hover)) {
408 $this->
ref = $this->login;
410 $label =
'<u>'.$langs->trans(
"WebsiteAccount").
'</u>';
412 $label .=
'<b>'.$langs->trans(
'Login').
':</b> '.$this->ref;
415 $url = DOL_URL_ROOT.
'/website/websiteaccount_card.php?id='.$this->id;
417 if ($option !=
'nolink') {
419 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
420 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
421 $add_save_lastsearch_values = 1;
423 if ($add_save_lastsearch_values) {
424 $url .=
'&save_lastsearch_values=1';
429 $classfortooltip =
'classfortooltip';
434 'objecttype' => $this->element,
437 $classfortooltip =
'classforajaxtooltip';
438 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
442 if (empty($notooltip)) {
443 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
444 $label = $langs->trans(
"WebsiteAccount");
445 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
447 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
448 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
450 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
453 $linkstart =
'<a href="'.$url.
'"';
454 $linkstart .= $linkclose.
'>';
457 $result .= $linkstart;
459 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') : $dataparams.
' class="'.(($withpicto != 2) ?
'paddingright ' :
'').$classfortooltip.
'"'), 0, 0, $notooltip ? 0 : 1);
461 if ($withpicto != 2) {
462 $result .= $this->ref;
477 return $this->
LibStatut($this->status, $mode);
496 return $langs->trans(
'Enabled');
497 } elseif ($status == 0) {
498 return $langs->trans(
'Disabled');
500 } elseif ($mode == 1) {
502 return $langs->trans(
'Enabled');
503 } elseif ($status == 0) {
504 return $langs->trans(
'Disabled');
506 } elseif ($mode == 2) {
508 return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
509 } elseif ($status == 0) {
510 return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
512 } elseif ($mode == 3) {
514 return img_picto($langs->trans(
'Enabled'),
'statut4');
515 } elseif ($status == 0) {
516 return img_picto($langs->trans(
'Disabled'),
'statut5');
518 } elseif ($mode == 4) {
520 return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
521 } elseif ($status == 0) {
522 return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
524 } elseif ($mode == 5) {
526 return $langs->trans(
'Enabled').
' '.
img_picto($langs->trans(
'Enabled'),
'statut4');
527 } elseif ($status == 0) {
528 return $langs->trans(
'Disabled').
' '.
img_picto($langs->trans(
'Disabled'),
'statut5');
530 } elseif ($mode == 6) {
532 return $langs->trans(
'Enabled').
' '.
img_picto($langs->trans(
'Enabled'),
'statut4');
533 } elseif ($status == 0) {
534 return $langs->trans(
'Disabled').
' '.
img_picto($langs->trans(
'Disabled'),
'statut5');
549 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
550 $sql .=
' fk_user_creat, fk_user_modif';
551 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
552 $sql .=
' WHERE t.rowid = '.((int) $id);
553 $result = $this->db->query($sql);
555 if ($this->db->num_rows($result)) {
556 $obj = $this->db->fetch_object($result);
557 $this->
id = $obj->rowid;
560 $this->user_creation_id = $obj->fk_user_creat;
561 $this->user_modification_id = $obj->fk_user_modif;
562 $this->date_creation = $this->db->jdate($obj->datec);
563 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
566 $this->db->free($result);
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
updateCommon(User $user, $notrigger=false)
Update object into database.
Class to manage Dolibarr database access.
Class for SocieteAccount.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
create(User $user, $notrigger=false)
Create object into database.
fetch($id, $ref=null)
Load object in memory from the database.
info($id)
Charge les informations d'ordre info dans l'objet commande.
getLibStatut($mode=0)
Return the label of a given status.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
getTooltipContentArray($params)
getTooltipContentArray
fetchLines()
Load object lines in memory from the database.
createFromClone(User $user, $fromid)
Clone and object into another one.
__construct(DoliDB $db)
Constructor.
static LibStatut($status, $mode=0)
Return the status.
getCustomerAccount($id, $site, $status=0, $site_account='')
Try to find the external customer id of a thirdparty for another site/system.
getThirdPartyID($id, $site, $status=0)
Try to find the thirdparty id from an another site/system external id.
update(User $user, $notrigger=false)
Update object into database.
Class to manage Dolibarr users.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.