dolibarr 18.0.6
societeaccount.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2014-2016 Juanjo Menent <jmenent@2byte.es>
4 * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
5 * Copyright (C) 2015 Raphaƫl Doursenaud <rdoursenaud@gpcsolutions.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Put here all includes required by your class file
28require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
29//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
30//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
31
36{
40 public $element = 'societeaccount';
41
45 public $table_element = 'societe_account';
46
50 public $ismultientitymanaged = 0;
51
55 public $picto = 'lock';
56
57
75 // BEGIN MODULEBUILDER PROPERTIES
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,),
93 //'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'visible'=>-1, 'enabled'=>1, 'position'=>45, 'notnull'=>-1,),
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')),
101 );
102
106 public $rowid;
107
111 public $entity;
112
113 public $key_account;
114 public $login;
115 public $pass_encoding;
116 public $pass_crypted;
117 public $pass_temp;
118
122 public $fk_soc;
123
124 public $site;
125 public $site_account;
126
130 public $date_last_login;
131
132
133 public $date_previous_login;
134 public $note_private;
135
139 public $date_creation;
140
141
142 public $tms;
143
147 public $fk_user_creat;
148
152 public $fk_user_modif;
153
154 public $import_key;
155
159 public $status;
160
161 // END MODULEBUILDER PROPERTIES
162
163
169 public function __construct(DoliDB $db)
170 {
171 global $conf;
172
173 $this->db = $db;
174
175 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
176 $this->fields['rowid']['visible'] = 0;
177 }
178 }
179
187 public function create(User $user, $notrigger = false)
188 {
189 return $this->createCommon($user, $notrigger);
190 }
191
199 public function createFromClone(User $user, $fromid)
200 {
201 global $hookmanager, $langs;
202 $error = 0;
203
204 dol_syslog(__METHOD__, LOG_DEBUG);
205
206 $object = new self($this->db);
207
208 $this->db->begin();
209
210 // Load source object
211 $object->fetchCommon($fromid);
212 // Reset some properties
213 unset($object->id);
214 unset($object->fk_user_creat);
215 unset($object->import_key);
216
217 // Clear fields
218 $object->ref = "copy_of_".$object->ref;
219 // $object->title = $langs->trans("CopyOf")." ".$object->title;
220
221 // Create clone
222 $object->context['createfromclone'] = 'createfromclone';
223 $result = $object->createCommon($user);
224 if ($result < 0) {
225 $error++;
226 $this->error = $object->error;
227 $this->errors = $object->errors;
228 }
229
230 unset($object->context['createfromclone']);
231
232 // End
233 if (!$error) {
234 $this->db->commit();
235 return $object;
236 } else {
237 $this->db->rollback();
238 return -1;
239 }
240 }
241
249 public function fetch($id, $ref = null)
250 {
251 $result = $this->fetchCommon($id, $ref);
252 if ($result > 0 && !empty($this->table_element_line)) {
253 $this->fetchLines();
254 }
255 return $result;
256 }
257
263 public function fetchLines()
264 {
265 $this->lines = array();
266
267 // Load lines with object societeAccountLine
268
269 return count($this->lines) ? 1 : 0;
270 }
271
282 public function getCustomerAccount($id, $site, $status = 0, $site_account = '')
283 {
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"; // To get the entry with a site_account defined in priority
292
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);
295 if ($result) {
296 if ($this->db->num_rows($result)) {
297 $obj = $this->db->fetch_object($result);
298 $key = $obj->key_account;
299 } else {
300 $key = '';
301 }
302 } else {
303 $key = '';
304 }
305
306 return $key;
307 }
308
318 public function getThirdPartyID($id, $site, $status = 0)
319 {
320 $socid = 0;
321
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";
328
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);
331 if ($result) {
332 if ($this->db->num_rows($result)) {
333 $obj = $this->db->fetch_object($result);
334 $socid = $obj->fk_soc;
335 }
336 }
337
338 return $socid;
339 }
340
348 public function update(User $user, $notrigger = false)
349 {
350 return $this->updateCommon($user, $notrigger);
351 }
352
360 public function delete(User $user, $notrigger = false)
361 {
362 return $this->deleteCommon($user, $notrigger);
363 }
364
371 public function getTooltipContentArray($params)
372 {
373 global $conf, $langs, $user;
374
375 $langs->loadLangs(['companies, commercial']);
376
377 $datas = [];
378 $option = $params['option'] ?? '';
379
380 $datas['picto'] = '<u>'.$langs->trans("WebsiteAccount").'</u>';
381 $datas['login'] = '<br><b>'.$langs->trans('Login').':</b> '.$this->login;
382
383 return $datas;
384 }
385
396 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
397 {
398 global $db, $conf, $langs;
399 global $dolibarr_main_authentication, $dolibarr_main_demo;
400 global $menumanager;
401
402 if (!empty($conf->dol_no_mouse_hover)) {
403 $notooltip = 1; // Force disable tooltips
404 }
405
406 $result = '';
407
408 $this->ref = $this->login;
409
410 $label = '<u>'.$langs->trans("WebsiteAccount").'</u>';
411 $label .= '<br>';
412 $label .= '<b>'.$langs->trans('Login').':</b> '.$this->ref;
413 //$label.= '<b>' . $langs->trans('WebSite') . ':</b> ' . $this->ref;
414
415 $url = DOL_URL_ROOT.'/website/websiteaccount_card.php?id='.$this->id;
416
417 if ($option != 'nolink') {
418 // Add param to save lastsearch_values or not
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;
422 }
423 if ($add_save_lastsearch_values) {
424 $url .= '&save_lastsearch_values=1';
425 }
426 }
427
428 $linkclose = '';
429 $classfortooltip = 'classfortooltip';
430 $dataparams = '';
431 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
432 $params = [
433 'id' => $this->id,
434 'objecttype' => $this->element,
435 'option' => $option,
436 ];
437 $classfortooltip = 'classforajaxtooltip';
438 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
439 $label = '';
440 }
441
442 if (empty($notooltip)) {
443 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
444 $label = $langs->trans("WebsiteAccount");
445 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
446 }
447 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
448 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
449 } else {
450 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
451 }
452
453 $linkstart = '<a href="'.$url.'"';
454 $linkstart .= $linkclose.'>';
455 $linkend = '</a>';
456
457 $result .= $linkstart;
458 if ($withpicto) {
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);
460 }
461 if ($withpicto != 2) {
462 $result .= $this->ref;
463 }
464 $result .= $linkend;
465
466 return $result;
467 }
468
475 public function getLibStatut($mode = 0)
476 {
477 return $this->LibStatut($this->status, $mode);
478 }
479
480 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
488 public static function LibStatut($status, $mode = 0)
489 {
490 // phpcs:enable
491 global $langs;
492
493 if ($mode == 0) {
494 $prefix = '';
495 if ($status == 1) {
496 return $langs->trans('Enabled');
497 } elseif ($status == 0) {
498 return $langs->trans('Disabled');
499 }
500 } elseif ($mode == 1) {
501 if ($status == 1) {
502 return $langs->trans('Enabled');
503 } elseif ($status == 0) {
504 return $langs->trans('Disabled');
505 }
506 } elseif ($mode == 2) {
507 if ($status == 1) {
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');
511 }
512 } elseif ($mode == 3) {
513 if ($status == 1) {
514 return img_picto($langs->trans('Enabled'), 'statut4');
515 } elseif ($status == 0) {
516 return img_picto($langs->trans('Disabled'), 'statut5');
517 }
518 } elseif ($mode == 4) {
519 if ($status == 1) {
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');
523 }
524 } elseif ($mode == 5) {
525 if ($status == 1) {
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');
529 }
530 } elseif ($mode == 6) {
531 if ($status == 1) {
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');
535 }
536 }
537
538 return '';
539 }
540
547 public function info($id)
548 {
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);
554 if ($result) {
555 if ($this->db->num_rows($result)) {
556 $obj = $this->db->fetch_object($result);
557 $this->id = $obj->rowid;
558
559
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);
564 }
565
566 $this->db->free($result);
567 } else {
568 dol_print_error($this->db);
569 }
570 }
571
578 public function initAsSpecimen()
579 {
580 $this->initAsSpecimenCommon();
581 }
582}
$object ref
Definition info.php:78
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.