dolibarr 20.0.2
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Put here all includes required by your class file
30require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
31//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
32//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
33
38{
42 public $element = 'societeaccount';
43
47 public $table_element = 'societe_account';
48
52 public $picto = 'lock';
53
54
94 // BEGIN MODULEBUILDER PROPERTIES
99 public $fields = array(
100 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'visible' => -2, 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'index' => 1, 'comment' => 'Id',),
101 'entity' => array('type' => 'integer', 'label' => 'Entity', 'visible' => 0, 'enabled' => 1, 'position' => 5, 'default' => 1),
102 'login' => array('type' => 'varchar(64)', 'label' => 'Login', 'visible' => 1, 'enabled' => 1, 'notnull' => 1, 'position' => 10, 'showoncombobox' => 1, 'autofocusoncreate' => 1),
103 'pass_encoding' => array('type' => 'varchar(24)', 'label' => 'PassEncoding', 'visible' => 0, 'enabled' => 1, 'position' => 30),
104 'pass_crypted' => array('type' => 'password', 'label' => 'Password', 'visible' => -1, 'enabled' => 1, 'position' => 31, 'notnull' => 1),
105 'pass_temp' => array('type' => 'varchar(128)', 'label' => 'Temp', 'visible' => 0, 'enabled' => 0, 'position' => 32, 'notnull' => -1,),
106 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'ThirdParty', 'visible' => 1, 'enabled' => 1, 'position' => 40, 'notnull' => -1, 'index' => 1, 'picto' => 'company', 'css' => 'maxwidth300 widthcentpercentminusxx'),
107 'site' => array('type' => 'varchar(128)', 'label' => 'WebsiteTypeLabel', 'visible' => 0, 'enabled' => 0, 'position' => 41, 'notnull' => 1, 'default' => '', 'help' => 'Name of the website or service if this is account on an external website or service', 'csslist' => 'tdoverflowmax150', 'arrayofkeyval' => array(/* For static analysis, filled in constructor */)),
108 'fk_website' => array('type' => 'integer:Website:website/class/website.class.php', 'label' => 'WebSite', 'visible' => 0, 'enabled' => 0, 'position' => 42, 'notnull' => -1, 'index' => 1, 'picto' => 'website', 'css' => 'maxwidth300 widthcentpercentminusxx'),
109 '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'),
110 '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)',),
111 'date_last_login' => array('type' => 'datetime', 'label' => 'LastConnexion', 'visible' => 2, 'enabled' => 1, 'position' => 50, 'notnull' => 0,),
112 'date_previous_login' => array('type' => 'datetime', 'label' => 'PreviousConnexion', 'visible' => 2, 'enabled' => 1, 'position' => 51, 'notnull' => 0,),
113 //'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'visible'=>-1, 'enabled'=>1, 'position'=>45, 'notnull'=>-1,),
114 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'visible' => -1, 'enabled' => 1, 'position' => 46, 'notnull' => -1,),
115 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'visible' => -2, 'enabled' => 1, 'position' => 500, 'notnull' => 1,),
116 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'visible' => -2, 'enabled' => 1, 'position' => 500, 'notnull' => 1,),
117 'fk_user_creat' => array('type' => 'integer', 'label' => 'UserAuthor', 'visible' => -2, 'enabled' => 1, 'position' => 500, 'notnull' => 1,),
118 'fk_user_modif' => array('type' => 'integer', 'label' => 'UserModif', 'visible' => -2, 'enabled' => 1, 'position' => 500, 'notnull' => -1,),
119 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'visible' => -2, 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'index' => 1,),
120 'status' => array('type' => 'integer', 'label' => 'Status', 'visible' => 1, 'enabled' => 1, 'position' => 1000, 'notnull' => 1, 'index' => 1, 'default' => 1, 'arrayofkeyval' => array('1' => 'Active', '0' => 'Disabled')),
121 );
122
126 public $rowid;
127
131 public $entity;
132
133 public $key_account;
134 public $login;
135 public $pass_encoding;
136 public $pass_crypted;
137 public $pass_temp;
138
142 public $fk_soc;
143
144 public $site;
145 public $site_account;
146
150 public $date_last_login;
151
152
153 public $date_previous_login;
154 public $note_private;
155
159 public $date_creation;
160
164 public $fk_user_creat;
165
169 public $fk_user_modif;
170
171 public $import_key;
172
176 public $status;
177
178 // END MODULEBUILDER PROPERTIES
179
180
181 const STATUS_ENABLED = 1;
182 const STATUS_DISABLED = 0;
183
184
190 public function __construct(DoliDB $db)
191 {
192 global $langs;
193
194 $this->db = $db;
195
196 $this->ismultientitymanaged = 0;
197
198 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
199 $this->fields['rowid']['visible'] = 0;
200 }
201
202 // add site type list and set visible
203 $site_type_list = array();
204
205 if (isModEnabled('webportal')) {
206 $this->fields['site']['visible'] = 1;
207 $this->fields['site']['enabled'] = 1;
208 $site_type_list['dolibarr_portal'] = $langs->trans('WebsiteTypeDolibarrPortal');
209 }
210
211 if (isModEnabled('website')) {
212 $this->fields['fk_website']['visible'] = 1;
213 $this->fields['fk_website']['enabled'] = 1;
214 $this->fields['site']['visible'] = 1;
215 $this->fields['site']['enabled'] = 1;
216 $site_type_list['dolibarr_website'] = $langs->trans('WebsiteTypeDolibarrWebsite');
217 }
218
219 $this->fields['site']['arrayofkeyval'] = $site_type_list;
220 }
221
229 public function create(User $user, $notrigger = 0)
230 {
231 return $this->createCommon($user, $notrigger);
232 }
233
241 public function createFromClone(User $user, $fromid)
242 {
243 global $hookmanager, $langs;
244 $error = 0;
245
246 dol_syslog(__METHOD__, LOG_DEBUG);
247
248 $object = new self($this->db);
249
250 $this->db->begin();
251
252 // Load source object
253 $object->fetchCommon($fromid);
254 // Reset some properties
255 unset($object->id);
256 unset($object->fk_user_creat);
257 unset($object->import_key);
258
259 // Clear fields
260 $object->ref = "copy_of_".$object->ref;
261 // $object->title = $langs->trans("CopyOf")." ".$object->title;
262
263 // Create clone
264 $object->context['createfromclone'] = 'createfromclone';
265 $result = $object->createCommon($user);
266 if ($result < 0) {
267 $error++;
268 $this->error = $object->error;
269 $this->errors = $object->errors;
270 }
271
272 unset($object->context['createfromclone']);
273
274 // End
275 if (!$error) {
276 $this->db->commit();
277 return $object;
278 } else {
279 $this->db->rollback();
280 return -1;
281 }
282 }
283
291 public function fetch($id, $ref = null)
292 {
293 $result = $this->fetchCommon($id, $ref);
294 if ($result > 0 && !empty($this->table_element_line)) {
295 $this->fetchLines();
296 }
297 return $result;
298 }
299
305 public function fetchLines()
306 {
307 $this->lines = array();
308
309 // Load lines with object societeAccountLine
310
311 return count($this->lines) ? 1 : 0;
312 }
313
324 public function getCustomerAccount($id, $site, $status = 0, $site_account = '')
325 {
326 $sql = "SELECT sa.key_account as key_account, sa.entity";
327 $sql .= " FROM ".MAIN_DB_PREFIX."societe_account as sa";
328 $sql .= " WHERE sa.fk_soc = ".((int) $id);
329 $sql .= " AND sa.entity IN (".getEntity('societe').")";
330 $sql .= " AND sa.site = '".$this->db->escape($site)."' AND sa.status = ".((int) $status);
331 $sql .= " AND sa.key_account IS NOT NULL AND sa.key_account <> ''";
332 $sql .= " AND (sa.site_account = '' OR sa.site_account IS NULL OR sa.site_account = '".$this->db->escape($site_account)."')";
333 $sql .= " ORDER BY sa.site_account DESC"; // To get the entry with a site_account defined in priority
334
335 dol_syslog(get_class($this)."::getCustomerAccount Try to find the first system customer id for ".$site." of thirdparty id=".$id." (example: cus_.... for stripe)", LOG_DEBUG);
336 $result = $this->db->query($sql);
337 if ($result) {
338 if ($this->db->num_rows($result)) {
339 $obj = $this->db->fetch_object($result);
340 $key = $obj->key_account;
341 } else {
342 $key = '';
343 }
344 } else {
345 $key = '';
346 }
347
348 return $key;
349 }
350
360 public function getThirdPartyID($id, $site, $status = 0)
361 {
362 $socid = 0;
363
364 $sql = "SELECT sa.fk_soc as fk_soc, sa.key_account, sa.entity";
365 $sql .= " FROM ".MAIN_DB_PREFIX."societe_account as sa";
366 $sql .= " WHERE sa.key_account = '".$this->db->escape($id)."'";
367 $sql .= " AND sa.entity IN (".getEntity('societe').")";
368 $sql .= " AND sa.site = '".$this->db->escape($site)."' AND sa.status = ".((int) $status);
369 $sql .= " AND sa.fk_soc > 0";
370
371 dol_syslog(get_class($this)."::getCustomerAccount Try to find the first thirdparty id for ".$site." for external id=".$id, LOG_DEBUG);
372 $result = $this->db->query($sql);
373 if ($result) {
374 if ($this->db->num_rows($result)) {
375 $obj = $this->db->fetch_object($result);
376 $socid = $obj->fk_soc;
377 }
378 }
379
380 return $socid;
381 }
382
390 public function update(User $user, $notrigger = 0)
391 {
392 return $this->updateCommon($user, $notrigger);
393 }
394
402 public function delete(User $user, $notrigger = 0)
403 {
404 return $this->deleteCommon($user, $notrigger);
405 }
406
413 public function getTooltipContentArray($params)
414 {
415 global $langs, $user;
416
417 $langs->loadLangs(['companies, commercial', 'website']);
418
419 $datas = [];
420 $option = $params['option'] ?? '';
421
422 $datas['picto'] = '<u>'.$langs->trans("WebsiteAccount").'</u>';
423 $datas['login'] = '<br><b>'.$langs->trans('Login').':</b> '.$this->login;
424
425 return $datas;
426 }
427
438 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
439 {
440 global $db, $conf, $langs;
441 global $dolibarr_main_authentication, $dolibarr_main_demo;
442 global $menumanager;
443
444 if (!empty($conf->dol_no_mouse_hover)) {
445 $notooltip = 1; // Force disable tooltips
446 }
447
448 $result = '';
449
450 $this->ref = $this->login;
451
452 $label = '<u>'.$langs->trans("WebsiteAccount").'</u>';
453 $label .= '<br>';
454 $label .= '<b>'.$langs->trans('Login').':</b> '.$this->ref;
455 //$label.= '<b>' . $langs->trans('WebSite') . ':</b> ' . $this->ref;
456
457 $url = DOL_URL_ROOT.'/website/websiteaccount_card.php?id='.$this->id;
458
459 if ($option != 'nolink') {
460 // Add param to save lastsearch_values or not
461 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
462 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
463 $add_save_lastsearch_values = 1;
464 }
465 if ($add_save_lastsearch_values) {
466 $url .= '&save_lastsearch_values=1';
467 }
468 }
469
470 $linkclose = '';
471 $classfortooltip = 'classfortooltip';
472 $dataparams = '';
473 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
474 $params = [
475 'id' => $this->id,
476 'objecttype' => $this->element,
477 'option' => $option,
478 ];
479 $classfortooltip = 'classforajaxtooltip';
480 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
481 $label = '';
482 }
483
484 if (empty($notooltip)) {
485 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
486 $label = $langs->trans("WebsiteAccount");
487 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
488 }
489 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
490 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
491 } else {
492 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
493 }
494
495 $linkstart = '<a href="'.$url.'"';
496 $linkstart .= $linkclose.'>';
497 $linkend = '</a>';
498
499 $result .= $linkstart;
500 if ($withpicto) {
501 $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);
502 }
503 if ($withpicto != 2) {
504 $result .= $this->ref;
505 }
506 $result .= $linkend;
507
508 return $result;
509 }
510
517 public function getLibStatut($mode = 0)
518 {
519 return $this->LibStatut($this->status, $mode);
520 }
521
522 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
530 public function LibStatut($status, $mode = 0)
531 {
532 // phpcs:enable
533 if (is_null($status)) {
534 return '';
535 }
536
537 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
538 global $langs;
539 //$langs->load("mymodule@mymodule");
540 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
541 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
542 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
543 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
544 }
545
546 $statusType = 'status4';
547 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
548 if ($status == self::STATUS_DISABLED) {
549 $statusType = 'status6';
550 }
551
552 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
553 }
554
561 public function info($id)
562 {
563 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
564 $sql .= ' fk_user_creat, fk_user_modif';
565 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
566 $sql .= ' WHERE t.rowid = '.((int) $id);
567 $result = $this->db->query($sql);
568 if ($result) {
569 if ($this->db->num_rows($result)) {
570 $obj = $this->db->fetch_object($result);
571 $this->id = $obj->rowid;
572
573 $this->user_creation_id = $obj->fk_user_creat;
574 $this->user_modification_id = $obj->fk_user_modif;
575 $this->date_creation = $this->db->jdate($obj->datec);
576 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
577 }
578
579 $this->db->free($result);
580 } else {
581 dol_print_error($this->db);
582 }
583 }
584
591 public function initAsSpecimen()
592 {
593 return $this->initAsSpecimenCommon();
594 }
595}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:637
$object ref
Definition info.php:79
Parent class of all other business classes (invoices, contracts, proposals, orders,...
createCommon(User $user, $notrigger=0)
Create object in the database.
updateCommon(User $user, $notrigger=0)
Update object into database.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in 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.
fetch($id, $ref=null)
Load object in memory from the database.
info($id)
Charge les information 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 optionally 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.
update(User $user, $notrigger=0)
Update object into database.
getCustomerAccount($id, $site, $status=0, $site_account='')
Try to find the external customer id of a thirdparty for another site/system.
LibStatut($status, $mode=0)
Return the status.
getThirdPartyID($id, $site, $status=0)
Try to find the thirdparty id from an another site/system external id.
create(User $user, $notrigger=0)
Create object into database.
Class to manage Dolibarr users.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.