|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* Copyright (C) 2007-2017 Laurent Destailleur <[email protected]> |
|
4
|
|
|
* Copyright (C) 2014-2016 Juanjo Menent <[email protected]> |
|
5
|
|
|
* Copyright (C) 2015 Florian Henry <[email protected]> |
|
6
|
|
|
* Copyright (C) 2015 Raphaël Doursenaud <[email protected]> |
|
7
|
|
|
* Copyright (C) 2024 Frédéric France <[email protected]> |
|
8
|
|
|
* Copyright (C) 2024 MDW <[email protected]> |
|
9
|
|
|
* Copyright (C) 2024 Rafael San José <[email protected]> |
|
10
|
|
|
* |
|
11
|
|
|
* This program is free software; you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU General Public License as published by |
|
13
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
14
|
|
|
* (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* This program is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU General Public License |
|
22
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace Dolibarr\Code\Societe\Classes; |
|
26
|
|
|
|
|
27
|
|
|
use Dolibarr\Code\User\Classes\User; |
|
28
|
|
|
use Dolibarr\Core\Base\CommonObject; |
|
29
|
|
|
use DoliDB; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* \file societe/class/societeaccount.class.php |
|
33
|
|
|
* \ingroup societe |
|
34
|
|
|
* \brief This file is a CRUD class file for web sites account - SocieteAccount (Create/Read/Update/Delete) |
|
35
|
|
|
*/ |
|
36
|
|
|
|
|
37
|
|
|
// Put here all includes required by your class file |
|
38
|
|
|
//use Dolibarr\Code\Societe\Classes\Societe; |
|
39
|
|
|
// |
|
40
|
|
|
/** |
|
41
|
|
|
* Class for SocieteAccount |
|
42
|
|
|
*/ |
|
43
|
|
|
class SocieteAccount extends CommonObject |
|
44
|
|
|
{ |
|
45
|
|
|
/** |
|
46
|
|
|
* @var string ID to identify managed object |
|
47
|
|
|
*/ |
|
48
|
|
|
public $element = 'societeaccount'; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var string Name of table without prefix where object is stored |
|
52
|
|
|
*/ |
|
53
|
|
|
public $table_element = 'societe_account'; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var string String with name of icon for societeaccount. Must be the part after the 'object_' into object_myobject.png |
|
57
|
|
|
*/ |
|
58
|
|
|
public $picto = 'lock'; |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* 'type' field format: |
|
63
|
|
|
* 'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]', |
|
64
|
|
|
* 'select' (list of values are in 'options'. for integer list of values are in 'arrayofkeyval'), |
|
65
|
|
|
* 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter[:CategoryIdType[:CategoryIdList[:SortField]]]]]]', |
|
66
|
|
|
* 'chkbxlst:...', |
|
67
|
|
|
* 'varchar(x)', |
|
68
|
|
|
* 'text', 'text:none', 'html', |
|
69
|
|
|
* 'double(24,8)', 'real', 'price', 'stock', |
|
70
|
|
|
* 'date', 'datetime', 'timestamp', 'duration', |
|
71
|
|
|
* 'boolean', 'checkbox', 'radio', 'array', |
|
72
|
|
|
* 'mail', 'phone', 'url', 'password', 'ip' |
|
73
|
|
|
* Note: Filter must be a Dolibarr Universal Filter syntax string. Example: "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.status:!=:0) or (t.nature:is:NULL)" |
|
74
|
|
|
* 'label' the translation key. |
|
75
|
|
|
* 'picto' is code of a picto to show before value in forms |
|
76
|
|
|
* 'enabled' is a condition when the field must be managed (Example: 1 or 'getDolGlobalInt("MY_SETUP_PARAM")' or 'isModEnabled("multicurrency")' ...) |
|
77
|
|
|
* 'position' is the sort order of field. |
|
78
|
|
|
* 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0). |
|
79
|
|
|
* 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing) |
|
80
|
|
|
* 'noteditable' says if field is not editable (1 or 0) |
|
81
|
|
|
* 'alwayseditable' says if field can be modified also when status is not draft ('1' or '0') |
|
82
|
|
|
* 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created. |
|
83
|
|
|
* 'index' if we want an index in database. |
|
84
|
|
|
* 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommended to name the field fk_...). |
|
85
|
|
|
* 'searchall' is 1 if we want to search in this field when making a search from the quick search button. |
|
86
|
|
|
* 'isameasure' must be set to 1 or 2 if field can be used for measure. Field type must be summable like integer or double(24,8). Use 1 in most cases, or 2 if you don't want to see the column total into list (for example for percentage) |
|
87
|
|
|
* 'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'cssview'=>'wordbreak', 'csslist'=>'tdoverflowmax200' |
|
88
|
|
|
* 'help' and 'helplist' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click. |
|
89
|
|
|
* 'showoncombobox' if value of the field must be visible into the label of the combobox that list record |
|
90
|
|
|
* 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code. |
|
91
|
|
|
* 'arrayofkeyval' to set a list of values if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel"). Note that type can be 'integer' or 'varchar' |
|
92
|
|
|
* 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1. |
|
93
|
|
|
* 'comment' is not used. You can store here any text of your choice. It is not used by application. |
|
94
|
|
|
* 'validate' is 1 if you need to validate the field with $this->validateField(). Need MAIN_ACTIVATE_VALIDATION_RESULT. |
|
95
|
|
|
* 'copytoclipboard' is 1 or 2 to allow to add a picto to copy value into clipboard (1=picto after label, 2=picto after value) |
|
96
|
|
|
* |
|
97
|
|
|
* Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor. |
|
98
|
|
|
*/ |
|
99
|
|
|
|
|
100
|
|
|
// BEGIN MODULEBUILDER PROPERTIES |
|
101
|
|
|
/** |
|
102
|
|
|
* @var array<string,array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array<int,string>,comment?:string}> Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. |
|
|
|
|
|
|
103
|
|
|
*/ |
|
104
|
|
|
|
|
105
|
|
|
public $fields = array( |
|
106
|
|
|
'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'visible' => -2, 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'index' => 1, 'comment' => 'Id',), |
|
107
|
|
|
'entity' => array('type' => 'integer', 'label' => 'Entity', 'visible' => 0, 'enabled' => 1, 'position' => 5, 'default' => 1), |
|
108
|
|
|
'login' => array('type' => 'varchar(64)', 'label' => 'Login', 'visible' => 1, 'enabled' => 1, 'notnull' => 1, 'position' => 10, 'showoncombobox' => 1, 'autofocusoncreate' => 1), |
|
109
|
|
|
'pass_encoding' => array('type' => 'varchar(24)', 'label' => 'PassEncoding', 'visible' => 0, 'enabled' => 1, 'position' => 30), |
|
110
|
|
|
'pass_crypted' => array('type' => 'password', 'label' => 'Password', 'visible' => -1, 'enabled' => 1, 'position' => 31, 'notnull' => 1), |
|
111
|
|
|
'pass_temp' => array('type' => 'varchar(128)', 'label' => 'Temp', 'visible' => 0, 'enabled' => 0, 'position' => 32, 'notnull' => -1,), |
|
112
|
|
|
'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'), |
|
113
|
|
|
'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 */)), |
|
114
|
|
|
'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'), |
|
115
|
|
|
'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'), |
|
116
|
|
|
'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)',), |
|
117
|
|
|
'date_last_login' => array('type' => 'datetime', 'label' => 'LastConnexion', 'visible' => 2, 'enabled' => 1, 'position' => 50, 'notnull' => 0,), |
|
118
|
|
|
'date_previous_login' => array('type' => 'datetime', 'label' => 'PreviousConnexion', 'visible' => 2, 'enabled' => 1, 'position' => 51, 'notnull' => 0,), |
|
119
|
|
|
//'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'visible'=>-1, 'enabled'=>1, 'position'=>45, 'notnull'=>-1,), |
|
120
|
|
|
'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'visible' => -1, 'enabled' => 1, 'position' => 46, 'notnull' => -1,), |
|
121
|
|
|
'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'visible' => -2, 'enabled' => 1, 'position' => 500, 'notnull' => 1,), |
|
122
|
|
|
'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'visible' => -2, 'enabled' => 1, 'position' => 500, 'notnull' => 1,), |
|
123
|
|
|
'fk_user_creat' => array('type' => 'integer', 'label' => 'UserAuthor', 'visible' => -2, 'enabled' => 1, 'position' => 500, 'notnull' => 1,), |
|
124
|
|
|
'fk_user_modif' => array('type' => 'integer', 'label' => 'UserModif', 'visible' => -2, 'enabled' => 1, 'position' => 500, 'notnull' => -1,), |
|
125
|
|
|
'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'visible' => -2, 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'index' => 1,), |
|
126
|
|
|
'status' => array('type' => 'integer', 'label' => 'Status', 'visible' => 1, 'enabled' => 1, 'position' => 1000, 'notnull' => 1, 'index' => 1, 'default' => 1, 'arrayofkeyval' => array('1' => 'Active', '0' => 'Disabled')), |
|
127
|
|
|
); |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @var int ID |
|
131
|
|
|
*/ |
|
132
|
|
|
public $rowid; |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @var int Entity |
|
136
|
|
|
*/ |
|
137
|
|
|
public $entity; |
|
138
|
|
|
|
|
139
|
|
|
public $key_account; |
|
140
|
|
|
public $login; |
|
141
|
|
|
public $pass_encoding; |
|
142
|
|
|
public $pass_crypted; |
|
143
|
|
|
public $pass_temp; |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @var int Thirdparty ID |
|
147
|
|
|
*/ |
|
148
|
|
|
public $fk_soc; |
|
149
|
|
|
|
|
150
|
|
|
public $site; |
|
151
|
|
|
public $site_account; |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @var integer|string date_last_login |
|
155
|
|
|
*/ |
|
156
|
|
|
public $date_last_login; |
|
157
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
public $date_previous_login; |
|
160
|
|
|
public $note_private; |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @var integer|string date_creation |
|
164
|
|
|
*/ |
|
165
|
|
|
public $date_creation; |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @var int ID |
|
169
|
|
|
*/ |
|
170
|
|
|
public $fk_user_creat; |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @var int ID |
|
174
|
|
|
*/ |
|
175
|
|
|
public $fk_user_modif; |
|
176
|
|
|
|
|
177
|
|
|
public $import_key; |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @var int Status |
|
181
|
|
|
*/ |
|
182
|
|
|
public $status; |
|
183
|
|
|
|
|
184
|
|
|
// END MODULEBUILDER PROPERTIES |
|
185
|
|
|
|
|
186
|
|
|
|
|
187
|
|
|
const STATUS_ENABLED = 1; |
|
188
|
|
|
const STATUS_DISABLED = 0; |
|
189
|
|
|
|
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* Constructor |
|
193
|
|
|
* |
|
194
|
|
|
* @param DoliDB $db Database handler |
|
195
|
|
|
*/ |
|
196
|
|
|
public function __construct(DoliDB $db) |
|
197
|
|
|
{ |
|
198
|
|
|
global $langs; |
|
199
|
|
|
|
|
200
|
|
|
$this->db = $db; |
|
201
|
|
|
|
|
202
|
|
|
$this->ismultientitymanaged = 0; |
|
203
|
|
|
|
|
204
|
|
|
if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) { |
|
205
|
|
|
$this->fields['rowid']['visible'] = 0; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
// add site type list and set visible |
|
209
|
|
|
$site_type_list = array(); |
|
210
|
|
|
|
|
211
|
|
|
if (isModEnabled('webportal')) { |
|
212
|
|
|
$this->fields['site']['visible'] = 1; |
|
213
|
|
|
$this->fields['site']['enabled'] = 1; |
|
214
|
|
|
$site_type_list['dolibarr_portal'] = $langs->trans('WebsiteTypeDolibarrPortal'); |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
if (isModEnabled('website')) { |
|
218
|
|
|
$this->fields['fk_website']['visible'] = 1; |
|
219
|
|
|
$this->fields['fk_website']['enabled'] = 1; |
|
220
|
|
|
$this->fields['site']['visible'] = 1; |
|
221
|
|
|
$this->fields['site']['enabled'] = 1; |
|
222
|
|
|
$site_type_list['dolibarr_website'] = $langs->trans('WebsiteTypeDolibarrWebsite'); |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
$this->fields['site']['arrayofkeyval'] = $site_type_list; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* Create object into database |
|
230
|
|
|
* |
|
231
|
|
|
* @param User $user User that creates |
|
232
|
|
|
* @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
233
|
|
|
* @return int Return integer <0 if KO, Id of created object if OK |
|
234
|
|
|
*/ |
|
235
|
|
|
public function create(User $user, $notrigger = 0) |
|
236
|
|
|
{ |
|
237
|
|
|
return $this->createCommon($user, $notrigger); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* Clone and object into another one |
|
242
|
|
|
* |
|
243
|
|
|
* @param User $user User that creates |
|
244
|
|
|
* @param int $fromid Id of object to clone |
|
245
|
|
|
* @return mixed New object created, <0 if KO |
|
246
|
|
|
*/ |
|
247
|
|
|
public function createFromClone(User $user, $fromid) |
|
248
|
|
|
{ |
|
249
|
|
|
global $hookmanager, $langs; |
|
250
|
|
|
$error = 0; |
|
251
|
|
|
|
|
252
|
|
|
dol_syslog(__METHOD__, LOG_DEBUG); |
|
253
|
|
|
|
|
254
|
|
|
$object = new self($this->db); |
|
255
|
|
|
|
|
256
|
|
|
$this->db->begin(); |
|
257
|
|
|
|
|
258
|
|
|
// Load source object |
|
259
|
|
|
$object->fetchCommon($fromid); |
|
260
|
|
|
// Reset some properties |
|
261
|
|
|
unset($object->id); |
|
262
|
|
|
unset($object->fk_user_creat); |
|
263
|
|
|
unset($object->import_key); |
|
264
|
|
|
|
|
265
|
|
|
// Clear fields |
|
266
|
|
|
$object->ref = "copy_of_" . $object->ref; |
|
267
|
|
|
// $object->title = $langs->trans("CopyOf")." ".$object->title; |
|
268
|
|
|
|
|
269
|
|
|
// Create clone |
|
270
|
|
|
$object->context['createfromclone'] = 'createfromclone'; |
|
271
|
|
|
$result = $object->createCommon($user); |
|
272
|
|
|
if ($result < 0) { |
|
273
|
|
|
$error++; |
|
274
|
|
|
$this->error = $object->error; |
|
275
|
|
|
$this->errors = $object->errors; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
unset($object->context['createfromclone']); |
|
279
|
|
|
|
|
280
|
|
|
// End |
|
281
|
|
|
if (!$error) { |
|
282
|
|
|
$this->db->commit(); |
|
283
|
|
|
return $object; |
|
284
|
|
|
} else { |
|
285
|
|
|
$this->db->rollback(); |
|
286
|
|
|
return -1; |
|
287
|
|
|
} |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
/** |
|
291
|
|
|
* Load object in memory from the database |
|
292
|
|
|
* |
|
293
|
|
|
* @param int $id Id object |
|
294
|
|
|
* @param string $ref Ref |
|
295
|
|
|
* @return int Return integer <0 if KO, 0 if not found, >0 if OK |
|
296
|
|
|
*/ |
|
297
|
|
|
public function fetch($id, $ref = null) |
|
298
|
|
|
{ |
|
299
|
|
|
$result = $this->fetchCommon($id, $ref); |
|
300
|
|
|
if ($result > 0 && !empty($this->table_element_line)) { |
|
301
|
|
|
$this->fetchLines(); |
|
302
|
|
|
} |
|
303
|
|
|
return $result; |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
/** |
|
307
|
|
|
* Load object lines in memory from the database |
|
308
|
|
|
* |
|
309
|
|
|
* @return int Return integer <0 if KO, 0 if not found, >0 if OK |
|
310
|
|
|
*/ |
|
311
|
|
|
public function fetchLines() |
|
312
|
|
|
{ |
|
313
|
|
|
$this->lines = array(); |
|
314
|
|
|
|
|
315
|
|
|
// Load lines with object societeAccountLine |
|
316
|
|
|
|
|
317
|
|
|
return count($this->lines) ? 1 : 0; |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
/** |
|
321
|
|
|
* Try to find the external customer id of a thirdparty for another site/system. |
|
322
|
|
|
* |
|
323
|
|
|
* @param int $id Id of third party |
|
324
|
|
|
* @param string $site Site (example: 'stripe', '...') |
|
325
|
|
|
* @param int $status Status (0=test, 1=live) |
|
326
|
|
|
* @param string $site_account Value to use to identify with account to use on site when site can offer several accounts. For example: 'pk_live_123456' when using Stripe service. |
|
327
|
|
|
* @return string Stripe customer ref 'cu_xxxxxxxxxxxxx' or '' |
|
328
|
|
|
* @see getThirdPartyID() |
|
329
|
|
|
*/ |
|
330
|
|
|
public function getCustomerAccount($id, $site, $status = 0, $site_account = '') |
|
331
|
|
|
{ |
|
332
|
|
|
$sql = "SELECT sa.key_account as key_account, sa.entity"; |
|
333
|
|
|
$sql .= " FROM " . MAIN_DB_PREFIX . "societe_account as sa"; |
|
334
|
|
|
$sql .= " WHERE sa.fk_soc = " . ((int) $id); |
|
335
|
|
|
$sql .= " AND sa.entity IN (" . getEntity('societe') . ")"; |
|
336
|
|
|
$sql .= " AND sa.site = '" . $this->db->escape($site) . "' AND sa.status = " . ((int) $status); |
|
337
|
|
|
$sql .= " AND sa.key_account IS NOT NULL AND sa.key_account <> ''"; |
|
338
|
|
|
$sql .= " AND (sa.site_account = '' OR sa.site_account IS NULL OR sa.site_account = '" . $this->db->escape($site_account) . "')"; |
|
339
|
|
|
$sql .= " ORDER BY sa.site_account DESC"; // To get the entry with a site_account defined in priority |
|
340
|
|
|
|
|
341
|
|
|
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); |
|
342
|
|
|
$result = $this->db->query($sql); |
|
343
|
|
|
if ($result) { |
|
344
|
|
|
if ($this->db->num_rows($result)) { |
|
345
|
|
|
$obj = $this->db->fetch_object($result); |
|
346
|
|
|
$key = $obj->key_account; |
|
347
|
|
|
} else { |
|
348
|
|
|
$key = ''; |
|
349
|
|
|
} |
|
350
|
|
|
} else { |
|
351
|
|
|
$key = ''; |
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
|
|
return $key; |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
/** |
|
358
|
|
|
* Try to find the thirdparty id from an another site/system external id. |
|
359
|
|
|
* |
|
360
|
|
|
* @param string $id Id of customer in external system (example: 'cu_xxxxxxxxxxxxx', ...) |
|
361
|
|
|
* @param string $site Site (example: 'stripe', '...') |
|
362
|
|
|
* @param int $status Status (0=test, 1=live) |
|
363
|
|
|
* @return int Id of third party |
|
364
|
|
|
* @see getCustomerAccount() |
|
365
|
|
|
*/ |
|
366
|
|
|
public function getThirdPartyID($id, $site, $status = 0) |
|
367
|
|
|
{ |
|
368
|
|
|
$socid = 0; |
|
369
|
|
|
|
|
370
|
|
|
$sql = "SELECT sa.fk_soc as fk_soc, sa.key_account, sa.entity"; |
|
371
|
|
|
$sql .= " FROM " . MAIN_DB_PREFIX . "societe_account as sa"; |
|
372
|
|
|
$sql .= " WHERE sa.key_account = '" . $this->db->escape($id) . "'"; |
|
373
|
|
|
$sql .= " AND sa.entity IN (" . getEntity('societe') . ")"; |
|
374
|
|
|
$sql .= " AND sa.site = '" . $this->db->escape($site) . "' AND sa.status = " . ((int) $status); |
|
375
|
|
|
$sql .= " AND sa.fk_soc > 0"; |
|
376
|
|
|
|
|
377
|
|
|
dol_syslog(get_class($this) . "::getCustomerAccount Try to find the first thirdparty id for " . $site . " for external id=" . $id, LOG_DEBUG); |
|
378
|
|
|
$result = $this->db->query($sql); |
|
379
|
|
|
if ($result) { |
|
380
|
|
|
if ($this->db->num_rows($result)) { |
|
381
|
|
|
$obj = $this->db->fetch_object($result); |
|
382
|
|
|
$socid = $obj->fk_soc; |
|
383
|
|
|
} |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
|
return $socid; |
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
|
|
/** |
|
390
|
|
|
* Update object into database |
|
391
|
|
|
* |
|
392
|
|
|
* @param User $user User that modifies |
|
393
|
|
|
* @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
394
|
|
|
* @return int Return integer <0 if KO, >0 if OK |
|
395
|
|
|
*/ |
|
396
|
|
|
public function update(User $user, $notrigger = 0) |
|
397
|
|
|
{ |
|
398
|
|
|
return $this->updateCommon($user, $notrigger); |
|
399
|
|
|
} |
|
400
|
|
|
|
|
401
|
|
|
/** |
|
402
|
|
|
* Delete object in database |
|
403
|
|
|
* |
|
404
|
|
|
* @param User $user User that deletes |
|
405
|
|
|
* @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
406
|
|
|
* @return int Return integer <0 if KO, >0 if OK |
|
407
|
|
|
*/ |
|
408
|
|
|
public function delete(User $user, $notrigger = 0) |
|
409
|
|
|
{ |
|
410
|
|
|
return $this->deleteCommon($user, $notrigger); |
|
411
|
|
|
} |
|
412
|
|
|
|
|
413
|
|
|
/** |
|
414
|
|
|
* getTooltipContentArray |
|
415
|
|
|
* @param array $params params to construct tooltip data |
|
416
|
|
|
* @since v18 |
|
417
|
|
|
* @return array |
|
418
|
|
|
*/ |
|
419
|
|
|
public function getTooltipContentArray($params) |
|
420
|
|
|
{ |
|
421
|
|
|
global $langs, $user; |
|
422
|
|
|
|
|
423
|
|
|
$langs->loadLangs(['companies, commercial', 'website']); |
|
424
|
|
|
|
|
425
|
|
|
$datas = []; |
|
426
|
|
|
$option = $params['option'] ?? ''; |
|
427
|
|
|
|
|
428
|
|
|
$datas['picto'] = '<u>' . $langs->trans("WebsiteAccount") . '</u>'; |
|
429
|
|
|
$datas['login'] = '<br><b>' . $langs->trans('Login') . ':</b> ' . $this->login; |
|
430
|
|
|
|
|
431
|
|
|
return $datas; |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
/** |
|
435
|
|
|
* Return a link to the object card (with optionally the picto) |
|
436
|
|
|
* |
|
437
|
|
|
* @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto) |
|
438
|
|
|
* @param string $option On what the link point to ('nolink', ...) |
|
439
|
|
|
* @param int $notooltip 1=Disable tooltip |
|
440
|
|
|
* @param string $morecss Add more css on link |
|
441
|
|
|
* @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking |
|
442
|
|
|
* @return string String with URL |
|
443
|
|
|
*/ |
|
444
|
|
|
public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) |
|
445
|
|
|
{ |
|
446
|
|
|
global $db, $conf, $langs; |
|
447
|
|
|
global $dolibarr_main_authentication, $dolibarr_main_demo; |
|
448
|
|
|
global $menumanager; |
|
449
|
|
|
|
|
450
|
|
|
if (!empty($conf->dol_no_mouse_hover)) { |
|
451
|
|
|
$notooltip = 1; // Force disable tooltips |
|
452
|
|
|
} |
|
453
|
|
|
|
|
454
|
|
|
$result = ''; |
|
455
|
|
|
|
|
456
|
|
|
$this->ref = $this->login; |
|
457
|
|
|
|
|
458
|
|
|
$label = '<u>' . $langs->trans("WebsiteAccount") . '</u>'; |
|
459
|
|
|
$label .= '<br>'; |
|
460
|
|
|
$label .= '<b>' . $langs->trans('Login') . ':</b> ' . $this->ref; |
|
461
|
|
|
//$label.= '<b>' . $langs->trans('WebSite') . ':</b> ' . $this->ref; |
|
462
|
|
|
|
|
463
|
|
|
$url = constant('BASE_URL') . '/website/websiteaccount_card.php?id=' . $this->id; |
|
464
|
|
|
|
|
465
|
|
|
if ($option != 'nolink') { |
|
466
|
|
|
// Add param to save lastsearch_values or not |
|
467
|
|
|
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); |
|
468
|
|
|
if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { |
|
469
|
|
|
$add_save_lastsearch_values = 1; |
|
470
|
|
|
} |
|
471
|
|
|
if ($add_save_lastsearch_values) { |
|
472
|
|
|
$url .= '&save_lastsearch_values=1'; |
|
473
|
|
|
} |
|
474
|
|
|
} |
|
475
|
|
|
|
|
476
|
|
|
$linkclose = ''; |
|
477
|
|
|
$classfortooltip = 'classfortooltip'; |
|
478
|
|
|
$dataparams = ''; |
|
479
|
|
|
if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) { |
|
480
|
|
|
$params = [ |
|
481
|
|
|
'id' => $this->id, |
|
482
|
|
|
'objecttype' => $this->element, |
|
483
|
|
|
'option' => $option, |
|
484
|
|
|
]; |
|
485
|
|
|
$classfortooltip = 'classforajaxtooltip'; |
|
486
|
|
|
$dataparams = ' data-params="' . dol_escape_htmltag(json_encode($params)) . '"'; |
|
487
|
|
|
$label = ''; |
|
488
|
|
|
} |
|
489
|
|
|
|
|
490
|
|
|
if (empty($notooltip)) { |
|
491
|
|
|
if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) { |
|
492
|
|
|
$label = $langs->trans("WebsiteAccount"); |
|
493
|
|
|
$linkclose .= ' alt="' . dol_escape_htmltag($label, 1) . '"'; |
|
494
|
|
|
} |
|
495
|
|
|
$linkclose .= ($label ? ' title="' . dol_escape_htmltag($label, 1) . '"' : ' title="tocomplete"'); |
|
496
|
|
|
$linkclose .= $dataparams . ' class="' . $classfortooltip . ($morecss ? ' ' . $morecss : '') . '"'; |
|
497
|
|
|
} else { |
|
498
|
|
|
$linkclose = ($morecss ? ' class="' . $morecss . '"' : ''); |
|
499
|
|
|
} |
|
500
|
|
|
|
|
501
|
|
|
$linkstart = '<a href="' . $url . '"'; |
|
502
|
|
|
$linkstart .= $linkclose . '>'; |
|
503
|
|
|
$linkend = '</a>'; |
|
504
|
|
|
|
|
505
|
|
|
$result .= $linkstart; |
|
506
|
|
|
if ($withpicto) { |
|
507
|
|
|
$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); |
|
508
|
|
|
} |
|
509
|
|
|
if ($withpicto != 2) { |
|
510
|
|
|
$result .= $this->ref; |
|
511
|
|
|
} |
|
512
|
|
|
$result .= $linkend; |
|
513
|
|
|
|
|
514
|
|
|
return $result; |
|
515
|
|
|
} |
|
516
|
|
|
|
|
517
|
|
|
/** |
|
518
|
|
|
* Return the label of a given status |
|
519
|
|
|
* |
|
520
|
|
|
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto |
|
521
|
|
|
* @return string Label of status |
|
522
|
|
|
*/ |
|
523
|
|
|
public function getLibStatut($mode = 0) |
|
524
|
|
|
{ |
|
525
|
|
|
return $this->LibStatut($this->status, $mode); |
|
526
|
|
|
} |
|
527
|
|
|
|
|
528
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
|
529
|
|
|
/** |
|
530
|
|
|
* Return the status |
|
531
|
|
|
* |
|
532
|
|
|
* @param int $status Id status |
|
533
|
|
|
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto |
|
534
|
|
|
* @return string Label of status |
|
535
|
|
|
*/ |
|
536
|
|
|
public function LibStatut($status, $mode = 0) |
|
537
|
|
|
{ |
|
538
|
|
|
// phpcs:enable |
|
539
|
|
|
if (is_null($status)) { |
|
540
|
|
|
return ''; |
|
541
|
|
|
} |
|
542
|
|
|
|
|
543
|
|
|
if (empty($this->labelStatus) || empty($this->labelStatusShort)) { |
|
544
|
|
|
global $langs; |
|
545
|
|
|
//$langs->load("mymodule@mymodule"); |
|
546
|
|
|
$this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled'); |
|
547
|
|
|
$this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled'); |
|
548
|
|
|
$this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled'); |
|
549
|
|
|
$this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled'); |
|
550
|
|
|
} |
|
551
|
|
|
|
|
552
|
|
|
$statusType = 'status4'; |
|
553
|
|
|
//if ($status == self::STATUS_VALIDATED) $statusType = 'status1'; |
|
554
|
|
|
if ($status == self::STATUS_DISABLED) { |
|
555
|
|
|
$statusType = 'status6'; |
|
556
|
|
|
} |
|
557
|
|
|
|
|
558
|
|
|
return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); |
|
559
|
|
|
} |
|
560
|
|
|
|
|
561
|
|
|
/** |
|
562
|
|
|
* Charge les information d'ordre info dans l'objet commande |
|
563
|
|
|
* |
|
564
|
|
|
* @param int $id Id of order |
|
565
|
|
|
* @return void |
|
566
|
|
|
*/ |
|
567
|
|
|
public function info($id) |
|
568
|
|
|
{ |
|
569
|
|
|
$sql = 'SELECT rowid, date_creation as datec, tms as datem,'; |
|
570
|
|
|
$sql .= ' fk_user_creat, fk_user_modif'; |
|
571
|
|
|
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; |
|
572
|
|
|
$sql .= ' WHERE t.rowid = ' . ((int) $id); |
|
573
|
|
|
$result = $this->db->query($sql); |
|
574
|
|
|
if ($result) { |
|
575
|
|
|
if ($this->db->num_rows($result)) { |
|
576
|
|
|
$obj = $this->db->fetch_object($result); |
|
577
|
|
|
$this->id = $obj->rowid; |
|
578
|
|
|
|
|
579
|
|
|
$this->user_creation_id = $obj->fk_user_creat; |
|
580
|
|
|
$this->user_modification_id = $obj->fk_user_modif; |
|
581
|
|
|
$this->date_creation = $this->db->jdate($obj->datec); |
|
582
|
|
|
$this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem); |
|
583
|
|
|
} |
|
584
|
|
|
|
|
585
|
|
|
$this->db->free($result); |
|
586
|
|
|
} else { |
|
587
|
|
|
dol_print_error($this->db); |
|
588
|
|
|
} |
|
589
|
|
|
} |
|
590
|
|
|
|
|
591
|
|
|
/** |
|
592
|
|
|
* Initialise object with example values |
|
593
|
|
|
* Id must be 0 if object instance is a specimen |
|
594
|
|
|
* |
|
595
|
|
|
* @return int |
|
596
|
|
|
*/ |
|
597
|
|
|
public function initAsSpecimen() |
|
598
|
|
|
{ |
|
599
|
|
|
return $this->initAsSpecimenCommon(); |
|
600
|
|
|
} |
|
601
|
|
|
} |
|
602
|
|
|
|