dolibarr 21.0.0-beta
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 'date_last_reset_password' => array('type' => 'datetime', 'label' => 'PreviousResetPassword', 'visible' => 0, 'enabled' => 1, 'position' => 53, 'notnull' => 0,),
114 //'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'visible'=>-1, 'enabled'=>1, 'position'=>45, 'notnull'=>-1,),
115 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'visible' => -1, 'enabled' => 1, 'position' => 46, 'notnull' => -1,),
116 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'visible' => -2, 'enabled' => 1, 'position' => 500, 'notnull' => 1,),
117 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'visible' => -2, 'enabled' => 1, 'position' => 500, 'notnull' => 1,),
118 'fk_user_creat' => array('type' => 'integer', 'label' => 'UserAuthor', 'visible' => -2, 'enabled' => 1, 'position' => 500, 'notnull' => 1,),
119 'fk_user_modif' => array('type' => 'integer', 'label' => 'UserModif', 'visible' => -2, 'enabled' => 1, 'position' => 500, 'notnull' => -1,),
120 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'visible' => -2, 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'index' => 1,),
121 'status' => array('type' => 'integer', 'label' => 'Status', 'visible' => 1, 'enabled' => 1, 'position' => 1000, 'notnull' => 1, 'index' => 1, 'default' => 1, 'arrayofkeyval' => array('1' => 'Active', '0' => 'Disabled')),
122 );
123
127 public $rowid;
128
132 public $entity;
133
137 public $key_account;
141 public $login;
145 public $pass_encoding;
149 public $pass_crypted;
153 public $pass_temp;
154
158 public $fk_soc;
159
163 public $site;
167 public $site_account;
168
172 public $date_last_login;
173
177 public $date_last_reset_password;
181 public $date_previous_login;
185 public $note_private;
186
190 public $fk_user_creat;
191
195 public $fk_user_modif;
196
200 public $import_key;
201
205 public $status;
206
207 // END MODULEBUILDER PROPERTIES
208
209
210 const STATUS_ENABLED = 1;
211 const STATUS_DISABLED = 0;
212
213
219 public function __construct(DoliDB $db)
220 {
221 global $langs;
222
223 $this->db = $db;
224
225 $this->ismultientitymanaged = 0;
226
227 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
228 $this->fields['rowid']['visible'] = 0;
229 }
230
231 // add site type list and set visible
232 $site_type_list = array();
233
234 if (isModEnabled('webportal')) {
235 $this->fields['site']['visible'] = 1;
236 $this->fields['site']['enabled'] = 1;
237 $site_type_list['dolibarr_portal'] = $langs->trans('WebsiteTypeDolibarrPortal');
238 }
239
240 if (isModEnabled('website')) {
241 $this->fields['fk_website']['visible'] = 1;
242 $this->fields['fk_website']['enabled'] = 1;
243 $this->fields['site']['visible'] = 1;
244 $this->fields['site']['enabled'] = 1;
245 $site_type_list['dolibarr_website'] = $langs->trans('WebsiteTypeDolibarrWebsite');
246 }
247
248 $this->fields['site']['arrayofkeyval'] = $site_type_list;
249 }
250
258 public function create(User $user, $notrigger = 0)
259 {
260 return $this->createCommon($user, $notrigger);
261 }
262
270 public function createFromClone(User $user, $fromid)
271 {
272 global $hookmanager, $langs;
273 $error = 0;
274
275 dol_syslog(__METHOD__, LOG_DEBUG);
276
277 $object = new self($this->db);
278
279 $this->db->begin();
280
281 // Load source object
282 $object->fetchCommon($fromid);
283 // Reset some properties
284 unset($object->id);
285 unset($object->fk_user_creat);
286 unset($object->import_key);
287
288 // Clear fields
289 $object->ref = "copy_of_".$object->ref;
290 // $object->title = $langs->trans("CopyOf")." ".$object->title;
291
292 // Create clone
293 $object->context['createfromclone'] = 'createfromclone';
294 $result = $object->createCommon($user);
295 if ($result < 0) {
296 $error++;
297 $this->error = $object->error;
298 $this->errors = $object->errors;
299 }
300
301 unset($object->context['createfromclone']);
302
303 // End
304 if (!$error) {
305 $this->db->commit();
306 return $object;
307 } else {
308 $this->db->rollback();
309 return -1;
310 }
311 }
312
320 public function fetch($id, $ref = null)
321 {
322 $result = $this->fetchCommon($id, $ref);
323 if ($result > 0 && !empty($this->table_element_line)) {
324 $this->fetchLines();
325 }
326 return $result;
327 }
328
334 public function fetchLines()
335 {
336 $this->lines = array();
337
338 // Load lines with object societeAccountLine
339
340 return count($this->lines) ? 1 : 0;
341 }
342
353 public function getCustomerAccount($id, $site, $status = 0, $site_account = '')
354 {
355 $sql = "SELECT sa.key_account as key_account, sa.entity";
356 $sql .= " FROM ".MAIN_DB_PREFIX."societe_account as sa";
357 $sql .= " WHERE sa.fk_soc = ".((int) $id);
358 $sql .= " AND sa.entity IN (".getEntity('societe').")";
359 $sql .= " AND sa.site = '".$this->db->escape($site)."' AND sa.status = ".((int) $status);
360 $sql .= " AND sa.key_account IS NOT NULL AND sa.key_account <> ''";
361 $sql .= " AND (sa.site_account = '' OR sa.site_account IS NULL OR sa.site_account = '".$this->db->escape($site_account)."')";
362 $sql .= " ORDER BY sa.site_account DESC, sa.rowid DESC"; // To get the entry with a site_account defined in priority
363
364 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);
365 $result = $this->db->query($sql);
366 if ($result) {
367 if ($this->db->num_rows($result)) {
368 $obj = $this->db->fetch_object($result);
369 $key = $obj->key_account;
370 } else {
371 $key = '';
372 }
373 } else {
374 $key = '';
375 }
376
377 return $key;
378 }
379
389 public function getThirdPartyID($id, $site, $status = 0)
390 {
391 $socid = 0;
392
393 $sql = "SELECT sa.fk_soc as fk_soc, sa.key_account, sa.entity";
394 $sql .= " FROM ".MAIN_DB_PREFIX."societe_account as sa";
395 $sql .= " WHERE sa.key_account = '".$this->db->escape($id)."'";
396 $sql .= " AND sa.entity IN (".getEntity('societe').")";
397 $sql .= " AND sa.site = '".$this->db->escape($site)."' AND sa.status = ".((int) $status);
398 $sql .= " AND sa.fk_soc > 0";
399 $sql .= " ORDER BY sa.site_account DESC, sa.rowid DESC"; // To get the entry with a site_account defined in priority
400
401 dol_syslog(get_class($this)."::getCustomerAccount Try to find the first thirdparty id for ".$site." for external id=".$id, LOG_DEBUG);
402 $result = $this->db->query($sql);
403 if ($result) {
404 if ($this->db->num_rows($result)) {
405 $obj = $this->db->fetch_object($result);
406 $socid = $obj->fk_soc;
407 }
408 }
409
410 return $socid;
411 }
412
420 public function update(User $user, $notrigger = 0)
421 {
422 return $this->updateCommon($user, $notrigger);
423 }
424
432 public function delete(User $user, $notrigger = 0)
433 {
434 return $this->deleteCommon($user, $notrigger);
435 }
436
443 public function getTooltipContentArray($params)
444 {
445 global $langs, $user;
446
447 $langs->loadLangs(['companies, commercial', 'website']);
448
449 $datas = [];
450 $option = $params['option'] ?? '';
451
452 $datas['picto'] = '<u>'.$langs->trans("WebsiteAccount").'</u>';
453 $datas['login'] = '<br><b>'.$langs->trans('Login').':</b> '.$this->login;
454
455 return $datas;
456 }
457
468 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
469 {
470 global $db, $conf, $langs;
471 global $dolibarr_main_authentication, $dolibarr_main_demo;
472 global $menumanager;
473
474 if (!empty($conf->dol_no_mouse_hover)) {
475 $notooltip = 1; // Force disable tooltips
476 }
477
478 $result = '';
479
480 $this->ref = $this->login;
481
482 $label = '<u>'.$langs->trans("WebsiteAccount").'</u>';
483 $label .= '<br>';
484 $label .= '<b>'.$langs->trans('Login').':</b> '.$this->ref;
485 //$label.= '<b>' . $langs->trans('WebSite') . ':</b> ' . $this->ref;
486
487 $url = DOL_URL_ROOT.'/website/websiteaccount_card.php?id='.$this->id;
488
489 if ($option != 'nolink') {
490 // Add param to save lastsearch_values or not
491 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
492 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
493 $add_save_lastsearch_values = 1;
494 }
495 if ($add_save_lastsearch_values) {
496 $url .= '&save_lastsearch_values=1';
497 }
498 }
499
500 $linkclose = '';
501 $classfortooltip = 'classfortooltip';
502 $dataparams = '';
503 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
504 $params = [
505 'id' => $this->id,
506 'objecttype' => $this->element,
507 'option' => $option,
508 ];
509 $classfortooltip = 'classforajaxtooltip';
510 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
511 $label = '';
512 }
513
514 if (empty($notooltip)) {
515 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
516 $label = $langs->trans("WebsiteAccount");
517 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
518 }
519 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
520 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
521 } else {
522 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
523 }
524
525 $linkstart = '<a href="'.$url.'"';
526 $linkstart .= $linkclose.'>';
527 $linkend = '</a>';
528
529 $result .= $linkstart;
530 if ($withpicto) {
531 $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);
532 }
533 if ($withpicto != 2) {
534 $result .= $this->ref;
535 }
536 $result .= $linkend;
537
538 return $result;
539 }
540
547 public function getLibStatut($mode = 0)
548 {
549 return $this->LibStatut($this->status, $mode);
550 }
551
552 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
560 public function LibStatut($status, $mode = 0)
561 {
562 // phpcs:enable
563 if (is_null($status)) {
564 return '';
565 }
566
567 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
568 global $langs;
569 //$langs->load("mymodule@mymodule");
570 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
571 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
572 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
573 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
574 }
575
576 $statusType = 'status4';
577 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
578 if ($status == self::STATUS_DISABLED) {
579 $statusType = 'status6';
580 }
581
582 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
583 }
584
591 public function info($id)
592 {
593 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
594 $sql .= ' fk_user_creat, fk_user_modif';
595 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
596 $sql .= ' WHERE t.rowid = '.((int) $id);
597 $result = $this->db->query($sql);
598 if ($result) {
599 if ($this->db->num_rows($result)) {
600 $obj = $this->db->fetch_object($result);
601 $this->id = $obj->rowid;
602
603 $this->user_creation_id = $obj->fk_user_creat;
604 $this->user_modification_id = $obj->fk_user_modif;
605 $this->date_creation = $this->db->jdate($obj->datec);
606 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
607 }
608
609 $this->db->free($result);
610 } else {
611 dol_print_error($this->db);
612 }
613 }
614
621 public function initAsSpecimen()
622 {
623 return $this->initAsSpecimenCommon();
624 }
625}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
$object ref
Definition info.php:89
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.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
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.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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 a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79