Issues (2811)

public/htdocs/user/bank.php (16 issues)

1
<?php
2
3
/* Copyright (C) 2002-2004  Rodolphe Quiedeville        <[email protected]>
4
 * Copyright (C) 2003       Jean-Louis Bergamo          <[email protected]>
5
 * Copyright (C) 2004-2015  Laurent Destailleur         <[email protected]>
6
 * Copyright (C) 2005-2009  Regis Houssin               <[email protected]>
7
 * Copyright (C) 2013       Peter Fontaine              <[email protected]>
8
 * Copyright (C) 2015-2016  Marcos García               <[email protected]>
9
 * Copyright (C) 2015       Alexandre Spangaro          <[email protected]>
10
 * Copyright (C) 2021       Gauthier VERDOL             <[email protected]>
11
 * Copyright (C) 2024		MDW							<[email protected]>
12
 * Copyright (C) 2024       Frédéric France             <[email protected]>
13
 * Copyright (C) 2024       Rafael San José             <[email protected]>
14
 *
15
 * This program is free software; you can redistribute it and/or modify
16
 * it under the terms of the GNU General Public License as published by
17
 * the Free Software Foundation; either version 3 of the License, or
18
 * (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU General Public License
26
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
27
 */
28
29
use Dolibarr\Code\Core\Classes\Form;
30
use Dolibarr\Code\Core\Classes\FormCompany;
31
use Dolibarr\Code\ExpenseReport\Classes\ExpenseReport;
32
use Dolibarr\Code\ExpenseReport\Classes\ExpenseReportIk;
33
use Dolibarr\Code\Holiday\Classes\Holiday;
34
use Dolibarr\Code\Salaries\Classes\PaymentSalary;
35
use Dolibarr\Code\Salaries\Classes\Salary;
36
use Dolibarr\Code\User\Classes\User;
37
use Dolibarr\Code\User\Classes\UserBankAccount;
38
use Dolibarr\Lib\ViewMain;
39
40
/**
41
 *      \file       htdocs/user/bank.php
42
 *      \ingroup    HRM
43
 *      \brief      Tab for HR and bank
44
 */
45
46
// Load Dolibarr environment
47
require constant('DOL_DOCUMENT_ROOT') . '/main.inc.php';
48
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/usergroups.lib.php';
49
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/bank.lib.php';
50
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/date.lib.php';
51
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/company.lib.php';
52
53
// Load translation files required by page
54
$langs->loadLangs(array('companies', 'commercial', 'banks', 'bills', 'trips', 'holiday', 'salaries'));
55
56
$id = GETPOSTINT('id');
57
$ref = GETPOST('ref', 'alphanohtml');
58
$bankid = GETPOSTINT('bankid');
59
$action = GETPOST("action", 'alpha');
60
$cancel = GETPOST('cancel', 'alpha');
61
62
// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
63
$hookmanager->initHooks(array('usercardBank', 'globalcard'));
64
65
// Security check
66
$socid = 0;
67
if ($user->socid > 0) {
68
    $socid = $user->socid;
69
}
70
$feature2 = (($socid && $user->hasRight('user', 'self', 'creer')) ? '' : 'user');
71
72
$object = new User($db);
73
if ($id > 0 || !empty($ref)) {
74
    $result = $object->fetch($id, $ref, '', 1);
75
    $object->getrights();
76
}
77
78
$account = new UserBankAccount($db);
79
if (!$bankid) {
80
    // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
81
    $account->fetch(0, '', $id);
82
} else {
83
    $account->fetch($bankid);
84
}
85
if (empty($account->userid)) {
86
    $account->userid = $object->id;
87
}
88
89
// Define value to know what current user can do on users
90
$selfpermission = ($user->id == $id && $user->hasRight('user', 'self', 'creer'));
91
$canadduser = (!empty($user->admin) || $user->hasRight('user', 'user', 'creer') || $user->hasRight('hrm', 'write_personal_information', 'write'));
92
$canreaduser = (!empty($user->admin) || $user->hasRight('user', 'user', 'lire') || $user->hasRight('hrm', 'read_personal_information', 'read'));
93
$permissiontoaddbankaccount = ($user->hasRight('salaries', 'write') || $user->hasRight('hrm', 'employee', 'write') || $user->hasRight('user', 'user', 'creer') || $selfpermission);
94
$permissiontoreadhr = $user->hasRight('hrm', 'read_personal_information', 'read') || $user->hasRight('hrm', 'write_personal_information', 'write');
95
$permissiontowritehr = $user->hasRight('hrm', 'write_personal_information', 'write');
96
$permissiontosimpleedit = ($selfpermission || $canadduser);
97
98
// Ok if user->hasRight('salaries', 'readall') or user->hasRight('hrm', 'read')
99
//$result = restrictedArea($user, 'salaries|hrm', $object->id, 'user&user', $feature2);
100
$ok = false;
101
if ($user->id == $id) {
102
    $ok = true; // A user can always read its own card
103
}
104
if ($user->hasRight('salaries', 'readall')) {
105
    $ok = true;
106
}
107
if ($user->hasRight('hrm', 'read')) {
108
    $ok = true;
109
}
110
if ($user->hasRight('expensereport', 'lire') && ($user->id == $object->id || $user->hasRight('expensereport', 'readall'))) {
111
    $ok = true;
112
}
113
if (!$ok) {
114
    accessforbidden();
115
}
116
117
118
/*
119
 *	Actions
120
 */
121
122
if ($action == 'add' && !$cancel && $permissiontoaddbankaccount) {
123
    $account->userid = $object->id;
124
125
    $account->bank = GETPOST('bank', 'alpha');
0 ignored issues
show
Documentation Bug introduced by
It seems like GETPOST('bank', 'alpha') can also be of type array or array or array. However, the property $bank is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
126
    $account->label = GETPOST('label', 'alpha');
0 ignored issues
show
Documentation Bug introduced by
It seems like GETPOST('label', 'alpha') can also be of type array or array or array. However, the property $label is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
127
    $account->type = GETPOSTINT('courant'); // not used
128
    $account->code_banque = GETPOST('code_banque', 'alpha');
0 ignored issues
show
Documentation Bug introduced by
It seems like GETPOST('code_banque', 'alpha') can also be of type array or array or array. However, the property $code_banque is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
129
    $account->code_guichet = GETPOST('code_guichet', 'alpha');
0 ignored issues
show
Documentation Bug introduced by
It seems like GETPOST('code_guichet', 'alpha') can also be of type array or array or array. However, the property $code_guichet is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
130
    $account->number = GETPOST('number', 'alpha');
0 ignored issues
show
Documentation Bug introduced by
It seems like GETPOST('number', 'alpha') can also be of type array or array or array. However, the property $number is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
131
    $account->cle_rib = GETPOST('cle_rib', 'alpha');
0 ignored issues
show
Documentation Bug introduced by
It seems like GETPOST('cle_rib', 'alpha') can also be of type array or array or array. However, the property $cle_rib is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
132
    $account->bic = GETPOST('bic', 'alpha');
0 ignored issues
show
Documentation Bug introduced by
It seems like GETPOST('bic', 'alpha') can also be of type array or array or array. However, the property $bic is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
133
    $account->iban = GETPOST('iban', 'alpha');
0 ignored issues
show
Documentation Bug introduced by
It seems like GETPOST('iban', 'alpha') can also be of type array or array or array. However, the property $iban is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
134
    $account->domiciliation = GETPOST('address', 'alpha');
0 ignored issues
show
Documentation Bug introduced by
It seems like GETPOST('address', 'alpha') can also be of type array or array or array. However, the property $domiciliation is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
Bug Best Practice introduced by
The property $domiciliation is declared private in Dolibarr\Code\Compta\Classes\Account. Since you implement __set, consider adding a @property or @property-write.
Loading history...
135
    $account->address = GETPOST('address', 'alpha');
0 ignored issues
show
Documentation Bug introduced by
It seems like GETPOST('address', 'alpha') can also be of type array or array or array. However, the property $address is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
136
    $account->owner_name = GETPOST('proprio', 'alpha');
0 ignored issues
show
Documentation Bug introduced by
It seems like GETPOST('proprio', 'alpha') can also be of type array or array or array. However, the property $owner_name is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
137
    $account->proprio = $account->owner_name;
0 ignored issues
show
Bug Best Practice introduced by
The property $proprio is declared private in Dolibarr\Code\Compta\Classes\Account. Since you implement __set, consider adding a @property or @property-write.
Loading history...
Documentation Bug introduced by
It seems like $account->owner_name can also be of type array or array or array. However, the property $proprio is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
138
    $account->owner_address = GETPOST('owner_address', 'alpha');
0 ignored issues
show
Documentation Bug introduced by
It seems like GETPOST('owner_address', 'alpha') can also be of type array or array or array. However, the property $owner_address is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
139
140
    $account->currency_code = trim(GETPOST("account_currency_code"));
141
    $account->state_id = GETPOSTINT("account_state_id");
142
    $account->country_id = GETPOSTINT("account_country_id");
143
144
    $result = $account->create($user);
145
146
    if (!$result) {
147
        setEventMessages($account->error, $account->errors, 'errors');
148
        $action = 'edit'; // Force chargement page edition
149
    } else {
150
        setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
151
        $action = '';
152
    }
153
}
154
155
if ($action == 'update' && !$cancel && $permissiontoaddbankaccount) {
156
    $account->userid = $object->id;
157
158
    $account->bank = GETPOST('bank', 'alpha');
159
    $account->label = GETPOST('label', 'alpha');
160
    $account->type = GETPOSTINT('courant'); // not used
161
    $account->code_banque = GETPOST('code_banque', 'alpha');
162
    $account->code_guichet = GETPOST('code_guichet', 'alpha');
163
    $account->number = GETPOST('number', 'alpha');
164
    $account->cle_rib = GETPOST('cle_rib', 'alpha');
165
    $account->bic = GETPOST('bic', 'alpha');
166
    $account->iban = GETPOST('iban', 'alpha');
167
    $account->domiciliation = GETPOST('address', 'alpha');
168
    $account->address = GETPOST('address', 'alpha');
169
    $account->proprio = GETPOST('proprio', 'alpha');
170
    $account->owner_address = GETPOST('owner_address', 'alpha');
171
172
    $account->currency_code = trim(GETPOST("account_currency_code"));
173
    $account->state_id = GETPOSTINT("account_state_id");
174
    $account->country_id = GETPOSTINT("account_country_id");
175
176
    $result = $account->update($user);
177
178
    if (!$result) {
179
        setEventMessages($account->error, $account->errors, 'errors');
180
        $action = 'edit'; // Force chargement page edition
181
    } else {
182
        setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
183
        $action = '';
184
    }
185
}
186
187
if ($action == 'delete_confirmed' && !$cancel && $permissiontoaddbankaccount) {
188
    $result = $account->delete($user);
189
    if ($result < 0) {
190
        setEventMessages($account->error, $account->errors, 'errors');
191
    } else {
192
        setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
193
        header("Location: " . constant('BASE_URL') . '/user/bank.php?id=' . $object->id);
194
        exit;
195
    }
196
    $action = '';
197
}
198
199
// update birth
200
if ($action == 'setbirth' && $canadduser && !$cancel) {
201
    $object->birth = dol_mktime(0, 0, 0, GETPOSTINT('birthmonth'), GETPOSTINT('birthday'), GETPOSTINT('birthyear'));
202
    $result = $object->update($user);
203
    if ($result < 0) {
204
        setEventMessages($object->error, $object->errors, 'errors');
205
    }
206
}
207
208
// update personal email
209
if ($action == 'setpersonal_email' && $permissiontosimpleedit && !$cancel) {
210
    $object->personal_email = (string)GETPOST('personal_email', 'alphanohtml');
211
    $result = $object->update($user);
212
    if ($result < 0) {
213
        setEventMessages($object->error, $object->errors, 'errors');
214
    }
215
}
216
217
// update personal mobile
218
if ($action == 'setpersonal_mobile' && $permissiontosimpleedit && !$cancel) {
219
    $object->personal_mobile = (string)GETPOST('personal_mobile', 'alphanohtml');
220
    $result = $object->update($user);
221
    if ($result < 0) {
222
        setEventMessages($object->error, $object->errors, 'errors');
223
    }
224
}
225
226
// update accountancy_code
227
if ($action == 'setaccountancy_code' && $canadduser && !$cancel) {
228
    $object->accountancy_code = (string)GETPOST('accountancy_code', 'alphanohtml');
229
    $result = $object->update($user);
230
    if ($result < 0) {
231
        setEventMessages($object->error, $object->errors, 'errors');
232
    }
233
}
234
235
// update ref_employee
236
if ($action == 'setref_employee' && $canadduser && !$cancel) {
237
    $object->ref_employee = (string)GETPOST('ref_employee', 'alphanohtml');
238
    $result = $object->update($user);
239
    if ($result < 0) {
240
        setEventMessages($object->error, $object->errors, 'errors');
241
    }
242
}
243
244
// update national_registration_number
245
if ($action == 'setnational_registration_number' && $canadduser && !$cancel) {
246
    $object->national_registration_number = (string)GETPOST('national_registration_number', 'alphanohtml');
247
    $result = $object->update($user);
248
    if ($result < 0) {
249
        setEventMessages($object->error, $object->errors, 'errors');
250
    }
251
}
252
253
if (getDolGlobalString('MAIN_USE_EXPENSE_IK')) {
254
    // update default_c_exp_tax_cat
255
    if ($action == 'setdefault_c_exp_tax_cat' && $canadduser) {
256
        $object->default_c_exp_tax_cat = GETPOSTINT('default_c_exp_tax_cat');
257
        $result = $object->update($user);
258
        if ($result < 0) {
259
            setEventMessages($object->error, $object->errors, 'errors');
260
        }
261
    }
262
263
    // update default range
264
    if ($action == 'setdefault_range' && $canadduser) {
265
        $object->default_range = GETPOSTINT('default_range');
266
        $result = $object->update($user);
267
        if ($result < 0) {
268
            setEventMessages($object->error, $object->errors, 'errors');
269
        }
270
    }
271
}
272
273
/*
274
 *	View
275
 */
276
277
$form = new Form($db);
278
$formcompany = new FormCompany($db);
279
280
$childids = $user->getAllChildIds(1);
281
282
$person_name = !empty($object->firstname) ? $object->lastname . ", " . $object->firstname : $object->lastname;
283
$title = $person_name . " - " . $langs->trans('BankAccounts');
284
$help_url = '';
285
ViewMain::llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-user page-bank');
286
287
$head = user_prepare_head($object);
288
289
if ($id && $bankid && $action == 'edit' && !$cancel && $permissiontoaddbankaccount) {
290
    if ($conf->use_javascript_ajax) {
291
        print "\n<script>";
292
        print 'jQuery(document).ready(function () {
293
					jQuery("#type").change(function() {
294
						document.formbank.action.value="edit";
295
						document.formbank.submit();
296
					});
297
					jQuery("#selectaccount_country_id").change(function() {
298
						document.formbank.action.value="edit";
299
						document.formbank.submit();
300
					});
301
				})';
302
        print "</script>\n";
303
    }
304
    print '<form action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '" name="formbank" method="post">';
305
    print '<input type="hidden" name="token" value="' . newToken() . '">';
306
    print '<input type="hidden" name="action" value="update">';
307
    print '<input type="hidden" name="id" value="' . GETPOSTINT("id") . '">';
308
    print '<input type="hidden" name="bankid" value="' . $bankid . '">';
309
}
310
if ($id && $action == 'create' && !$cancel && $permissiontoaddbankaccount) {
311
    if ($conf->use_javascript_ajax) {
312
        print "\n<script>";
313
        print 'jQuery(document).ready(function () {
314
					jQuery("#type").change(function() {
315
						document.formbank.action.value="create";
316
						document.formbank.submit();
317
					});
318
					jQuery("#selectaccount_country_id").change(function() {
319
						document.formbank.action.value="create";
320
						document.formbank.submit();
321
					});
322
				})';
323
        print "</script>\n";
324
    }
325
    print '<form action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '" name="formbank" method="post">';
326
    print '<input type="hidden" name="token" value="' . newToken() . '">';
327
    print '<input type="hidden" name="action" value="add">';
328
    print '<input type="hidden" name="bankid" value="' . $bankid . '">';
329
}
330
331
332
// View
333
if ($action != 'edit' && $action != 'create') {     // If not bank account yet, $account may be empty
334
    $title = $langs->trans("User");
335
    print dol_get_fiche_head($head, 'bank', $title, -1, 'user');
336
337
    $linkback = '';
338
339
    if ($user->hasRight('user', 'user', 'lire') || $user->admin) {
340
        $linkback = '<a href="' . constant('BASE_URL') . '/user/list.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>';
341
    }
342
343
    $morehtmlref = '<a href="' . constant('BASE_URL') . '/user/vcard.php?id=' . $object->id . '&output=file&file=' . urlencode(dol_sanitizeFileName($object->getFullName($langs) . '.vcf')) . '" class="refid" rel="noopener">';
344
    $morehtmlref .= img_picto($langs->trans("Download") . ' ' . $langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
345
    $morehtmlref .= '</a>';
346
347
    $urltovirtualcard = '/user/virtualcard.php?id=' . ((int)$object->id);
348
    $morehtmlref .= dolButtonToOpenUrlInDialogPopup('publicvirtualcard', $langs->transnoentitiesnoconv("PublicVirtualCardUrl") . ' - ' . $object->getFullName($langs), img_picto($langs->trans("PublicVirtualCardUrl"), 'card', 'class="valignmiddle marginleftonly paddingrightonly"'), $urltovirtualcard, '', 'nohover');
349
350
    dol_banner_tab($object, 'id', $linkback, $user->hasRight('user', 'user', 'lire') || $user->admin, 'rowid', 'ref', $morehtmlref);
351
352
    print '<div class="fichecenter"><div class="fichehalfleft">';
353
354
    print '<div class="underbanner clearboth"></div>';
355
356
    print '<table class="border centpercent tableforfield">';
357
358
    print '<tr><td class="titlefieldmiddle">' . $langs->trans("Login") . '</td>';
359
    if (!empty($object->ldap_sid) && $object->statut == 0) {
360
        print '<td class="error">';
361
        print $langs->trans("LoginAccountDisableInDolibarr");
362
        print '</td>';
363
    } else {
364
        print '<td>';
365
        $addadmin = '';
366
        if (property_exists($object, 'admin')) {
367
            if (isModEnabled('multicompany') && !empty($object->admin) && empty($object->entity)) {
368
                $addadmin .= img_picto($langs->trans("SuperAdministratorDesc"), "redstar", 'class="paddingleft"');
369
            } elseif (!empty($object->admin)) {
370
                $addadmin .= img_picto($langs->trans("AdministratorDesc"), "star", 'class="paddingleft"');
371
            }
372
        }
373
        print showValueWithClipboardCPButton($object->login) . $addadmin;
374
        print '</td>';
375
    }
376
    print '</tr>';
377
378
379
    // Hierarchy
380
    print '<tr><td>' . $langs->trans("HierarchicalResponsible") . '</td>';
381
    print '<td>';
382
    if (empty($object->fk_user)) {
383
        print '<span class="opacitymedium">' . $langs->trans("None") . '</span>';
384
    } else {
385
        $huser = new User($db);
386
        if ($object->fk_user > 0) {
387
            $huser->fetch($object->fk_user);
388
            print $huser->getNomUrl(1);
389
        } else {
390
            print '<span class="opacitymedium">' . $langs->trans("None") . '</span>';
391
        }
392
    }
393
    print '</td>';
394
    print "</tr>\n";
395
396
    // Expense report validator
397
    if (isModEnabled('expensereport')) {
398
        print '<tr><td>';
399
        $text = $langs->trans("ForceUserExpenseValidator");
400
        print $form->textwithpicto($text, $langs->trans("ValidatorIsSupervisorByDefault"), 1, 'help');
401
        print '</td>';
402
        print '<td>';
403
        if (!empty($object->fk_user_expense_validator)) {
404
            $evuser = new User($db);
405
            $evuser->fetch($object->fk_user_expense_validator);
406
            print $evuser->getNomUrl(1);
407
        }
408
        print '</td>';
409
        print "</tr>\n";
410
    }
411
412
    // Holiday request validator
413
    if (isModEnabled('holiday')) {
414
        print '<tr><td>';
415
        $text = $langs->trans("ForceUserHolidayValidator");
416
        print $form->textwithpicto($text, $langs->trans("ValidatorIsSupervisorByDefault"), 1, 'help');
417
        print '</td>';
418
        print '<td>';
419
        if (!empty($object->fk_user_holiday_validator)) {
420
            $hvuser = new User($db);
421
            $hvuser->fetch($object->fk_user_holiday_validator);
422
            print $hvuser->getNomUrl(1);
423
        }
424
        print '</td>';
425
        print "</tr>\n";
426
    }
427
428
    // Position/Job
429
    print '<tr><td>' . $langs->trans("PostOrFunction") . '</td>';
430
    print '<td>' . dol_escape_htmltag($object->job) . '</td>';
431
    print '</tr>' . "\n";
432
433
    // Weeklyhours
434
    print '<tr><td>' . $langs->trans("WeeklyHours") . '</td>';
435
    print '<td>';
436
    print price2num($object->weeklyhours);
437
    print '</td>';
438
    print "</tr>\n";
439
440
    // Sensitive salary/value information
441
    if (
442
        (empty($user->socid) && in_array($id, $childids))   // A user can always see salary/value information for its subordinates
443
        || (isModEnabled('salaries') && $user->hasRight('salaries', 'readall'))
444
        || (isModEnabled('hrm') && $user->hasRight('hrm', 'employee', 'read'))
445
    ) {
446
        $langs->load("salaries");
447
448
        // Salary
449
        print '<tr><td>' . $langs->trans("Salary") . '</td>';
450
        print '<td>';
451
        print($object->salary != '' ? img_picto('', 'salary', 'class="pictofixedwidth paddingright"') . '<span class="amount">' . price($object->salary, 0, $langs, 1, -1, -1, $conf->currency) : '') . '</span>';
452
        print '</td>';
453
        print "</tr>\n";
454
455
        // THM
456
        print '<tr><td>';
457
        $text = $langs->trans("THM");
458
        print $form->textwithpicto($text, $langs->trans("THMDescription"), 1, 'help', 'classthm');
459
        print '</td>';
460
        print '<td>';
461
        print($object->thm != '' ? price($object->thm, 0, $langs, 1, -1, -1, $conf->currency) : '');
462
        print '</td>';
463
        print "</tr>\n";
464
465
        // TJM
466
        print '<tr><td>';
467
        $text = $langs->trans("TJM");
468
        print $form->textwithpicto($text, $langs->trans("TJMDescription"), 1, 'help', 'classtjm');
469
        print '</td>';
470
        print '<td>';
471
        print($object->tjm != '' ? price($object->tjm, 0, $langs, 1, -1, -1, $conf->currency) : '');
472
        print '</td>';
473
        print "</tr>\n";
474
    }
475
476
    // Date employment
477
    print '<tr><td>' . $langs->trans("DateOfEmployment") . '</td>';
478
    print '<td>';
479
    if ($object->dateemployment) {
480
        print '<span class="opacitymedium">' . $langs->trans("FromDate") . '</span> ';
481
        print dol_print_date($object->dateemployment, 'day');
482
    }
483
    if ($object->dateemploymentend) {
484
        print '<span class="opacitymedium"> - ' . $langs->trans("To") . '</span> ';
485
        print dol_print_date($object->dateemploymentend, 'day');
486
    }
487
    print '</td>';
488
    print "</tr>\n";
489
490
    // Date of birth
491
    if ($user->hasRight('hrm', 'read_personal_information', 'read') || $user->hasRight('hrm', 'write_personal_information', 'write')) {
492
        print '<tr>';
493
        print '<td>';
494
        print $form->editfieldkey("DateOfBirth", 'birth', $object->birth, $object, $user->hasRight('user', 'user', 'creer'));
495
        print '</td><td>';
496
        print $form->editfieldval("DateOfBirth", 'birth', $object->birth, $object, $user->hasRight('user', 'user', 'creer'), 'day', $object->birth);
497
        print '</td>';
498
        print "</tr>\n";
499
    }
500
501
    // Personal email
502
    if ($user->hasRight('hrm', 'read_personal_information', 'read') || $user->hasRight('hrm', 'write_personal_information', 'write') || $permissiontosimpleedit) {
503
        print '<tr class="nowrap">';
504
        print '<td>';
505
        print $form->editfieldkey("UserPersonalEmail", 'personal_email', $object->personal_email, $object, $user->hasRight('user', 'user', 'creer') || $user->hasRight('hrm', 'write_personal_information', 'write'));
506
        print '</td><td>';
507
        print $form->editfieldval("UserPersonalEmail", 'personal_email', $object->personal_email, $object, $user->hasRight('user', 'user', 'creer') || $user->hasRight('hrm', 'write_personal_information', 'write'), 'email', '', null, null, '', 0, '');
508
        print '</td>';
509
        print '</tr>';
510
    }
511
512
    // Personal phone
513
    if ($user->hasRight('hrm', 'read_personal_information', 'read') || $user->hasRight('hrm', 'write_personal_information', 'write') || $permissiontosimpleedit) {
514
        print '<tr class="nowrap">';
515
        print '<td>';
516
        print $form->editfieldkey("UserPersonalMobile", 'personal_mobile', $object->personal_mobile, $object, $user->hasRight('user', 'user', 'creer') || $user->hasRight('hrm', 'write_personal_information', 'write'));
517
        print '</td><td>';
518
        print $form->editfieldval("UserPersonalMobile", 'personal_mobile', $object->personal_mobile, $object, $user->hasRight('user', 'user', 'creer') || $user->hasRight('hrm', 'write_personal_information', 'write'), 'phone', '', null, null, '', 0, '');
519
        print '</td>';
520
        print '</tr>';
521
    }
522
523
    if (getDolGlobalString('MAIN_USE_EXPENSE_IK')) {
524
        print '<tr class="nowrap">';
525
        print '<td>';
526
        print $form->editfieldkey("DefaultCategoryCar", 'default_c_exp_tax_cat', $object->default_c_exp_tax_cat, $object, $user->hasRight('user', 'user', 'creer'));
527
        print '</td><td>';
528
        if ($action == 'editdefault_c_exp_tax_cat') {
529
            $ret = '<form method="post" action="' . $_SERVER["PHP_SELF"] . ($moreparam ? '?' . $moreparam : '') . '">';
530
            $ret .= '<input type="hidden" name="action" value="setdefault_c_exp_tax_cat">';
531
            $ret .= '<input type="hidden" name="token" value="' . newToken() . '">';
532
            $ret .= '<input type="hidden" name="id" value="' . $object->id . '">';
533
            $ret .= $form->selectExpenseCategories($object->default_c_exp_tax_cat, 'default_c_exp_tax_cat', 1);
534
            $ret .= '<input type="submit" class="button" name="modify" value="' . $langs->trans("Modify") . '"> ';
535
            $ret .= '<input type="submit" class="button button-cancel" name="cancel" value="' . $langs->trans("Cancel") . '">';
536
            $ret .= '</form>';
537
            print $ret;
538
        } else {
539
            $label_exp_tax_cat = dol_getIdFromCode($db, $object->default_c_exp_tax_cat, 'c_exp_tax_cat', 'rowid', 'label');
540
            print $langs->trans($label_exp_tax_cat);
541
            //print $form->editfieldval("DefaultCategoryCar", 'default_c_exp_tax_cat', $object->default_c_exp_tax_cat, $object, $user->hasRight('user', 'user', 'creer'), 'string', ($object->default_c_exp_tax_cat != '' ? $object->default_c_exp_tax_cat : ''));
542
        }
543
        print '</td>';
544
        print '</tr>';
545
546
        print '<tr class="nowrap">';
547
        print '<td>';
548
        print $form->editfieldkey("DefaultRangeNumber", 'default_range', $object->default_range, $object, $user->hasRight('user', 'user', 'creer'));
549
        print '</td><td>';
550
        if ($action == 'editdefault_range') {
551
            $ret = '<form method="post" action="' . $_SERVER["PHP_SELF"] . ($moreparam ? '?' . $moreparam : '') . '">';
552
            $ret .= '<input type="hidden" name="action" value="setdefault_range">';
553
            $ret .= '<input type="hidden" name="token" value="' . newToken() . '">';
554
            $ret .= '<input type="hidden" name="id" value="' . $object->id . '">';
555
556
            $expensereportik = new ExpenseReportIk($db);
557
            $maxRangeNum = $expensereportik->getMaxRangeNumber($object->default_c_exp_tax_cat);
558
559
            $ret .= $form->selectarray('default_range', range(0, $maxRangeNum), $object->default_range);
560
            $ret .= '<input type="submit" class="button" name="modify" value="' . $langs->trans("Modify") . '"> ';
561
            $ret .= '<input type="submit" class="button button-cancel" name="cancel" value="' . $langs->trans("Cancel") . '">';
562
            $ret .= '</form>';
563
            print $ret;
564
        } else {
565
            print $object->default_range;
566
        }
567
        print '</td>';
568
        print '</tr>';
569
    }
570
571
    // Accountancy code
572
    if (isModEnabled('accounting')) {
573
        print '<tr class="nowrap">';
574
        print '<td>';
575
        print $form->editfieldkey("AccountancyCode", 'accountancy_code', $object->accountancy_code, $object, $user->hasRight('user', 'user', 'creer'));
576
        print '</td><td>';
577
        print $form->editfieldval("AccountancyCode", 'accountancy_code', $object->accountancy_code, $object, $user->hasRight('user', 'user', 'creer'), 'string', '', null, null, '', 0, '');
578
        print '</td>';
579
        print '</tr>';
580
    }
581
582
    // Employee Number
583
    if ($permissiontoreadhr) {
584
        print '<tr class="nowrap">';
585
        print '<td>';
586
        print $form->editfieldkey("RefEmployee", 'ref_employee', $object->ref_employee, $object, $permissiontowritehr);
587
        print '</td><td>';
588
        print $form->editfieldval("RefEmployee", 'ref_employee', $object->ref_employee, $object, $permissiontowritehr, 'string', $object->ref_employee);
589
        print '</td>';
590
        print '</tr>';
591
    }
592
593
    // National registration number
594
    if ($permissiontoreadhr) {
595
        print '<tr class="nowrap">';
596
        print '<td>';
597
        print $form->editfieldkey("NationalRegistrationNumber", 'national_registration_number', $object->national_registration_number, $object, $permissiontowritehr);
598
        print '</td><td>';
599
        print $form->editfieldval("NationalRegistrationNumber", 'national_registration_number', $object->national_registration_number, $object, $permissiontowritehr, 'string', $object->national_registration_number);
600
        print '</td>';
601
        print '</tr>';
602
    }
603
604
    print '</table>';
605
606
    print '</div><div class="fichehalfright">';
607
608
    // Max number of elements in small lists
609
    $MAXLIST = getDolGlobalString('MAIN_SIZE_SHORTLIST_LIMIT');
610
611
    // Latest payments of salaries
612
    if (
613
        isModEnabled('salaries') &&
614
        (($user->hasRight('salaries', 'read') && (in_array($object->id, $childids) || $object->id == $user->id)) || ($user->hasRight('salaries', 'readall')))
615
    ) {
616
        $payment_salary = new PaymentSalary($db);
617
        $salary = new Salary($db);
618
619
        $sql = "SELECT s.rowid as sid, s.ref as sref, s.label, s.datesp, s.dateep, s.paye, s.amount, SUM(ps.amount) as alreadypaid";
620
        $sql .= " FROM " . MAIN_DB_PREFIX . "salary as s";
621
        $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "payment_salary as ps ON (s.rowid = ps.fk_salary)";
622
        $sql .= " WHERE s.fk_user = " . ((int)$object->id);
623
        $sql .= " AND s.entity IN (" . getEntity('salary') . ")";
624
        $sql .= " GROUP BY s.rowid, s.ref, s.label, s.datesp, s.dateep, s.paye, s.amount";
625
        $sql .= " ORDER BY s.dateep DESC";
626
627
        $resql = $db->query($sql);
628
        if ($resql) {
629
            $num = $db->num_rows($resql);
630
631
            print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
632
            print '<table class="noborder centpercent">';
633
634
            print '<tr class="liste_titre">';
635
            print '<td colspan="5"><table class="nobordernopadding centpercent"><tr><td>' . $langs->trans("LastSalaries", ($num <= $MAXLIST ? "" : $MAXLIST)) . '</td><td class="right"><a class="notasortlink" href="' . constant('BASE_URL') . '/salaries/list.php?search_user=' . $object->login . '">' . $langs->trans("AllSalaries") . '<span class="badge marginleftonlyshort">' . $num . '</span></a></td>';
636
            print '</tr></table></td>';
637
            print '</tr>';
638
639
            $i = 0;
640
            while ($i < $num && $i < $MAXLIST) {
641
                $objp = $db->fetch_object($resql);
642
643
                $salary->id = $objp->sid;
644
                $salary->ref = $objp->sref ? $objp->sref : $objp->sid;
645
                $salary->label = $objp->label;
646
                $salary->datesp = $db->jdate($objp->datesp);
647
                $salary->dateep = $db->jdate($objp->dateep);
648
                $salary->paye = $objp->paye;
649
                $salary->amount = $objp->amount;
650
651
                $payment_salary->id = !empty($objp->rowid) ? $objp->rowid : 0;
652
                $payment_salary->ref = !empty($objp->ref) ? $objp->ref : "";
653
                $payment_salary->datep = $db->jdate(!empty($objp->datep) ? $objp->datep : "");
654
655
                print '<tr class="oddeven">';
656
                print '<td class="nowraponall">';
657
                print $salary->getNomUrl(1);
658
                print '</td>';
659
                print '<td class="right nowraponall">' . dol_print_date($db->jdate($objp->datesp), 'day') . "</td>\n";
660
                print '<td class="right nowraponall">' . dol_print_date($db->jdate($objp->dateep), 'day') . "</td>\n";
661
                print '<td class="right nowraponall"><span class="amount">' . price($objp->amount) . '</span></td>';
662
                print '<td class="right nowraponall">' . $salary->getLibStatut(5, $objp->alreadypaid) . '</td>';
663
                print '</tr>';
664
                $i++;
665
            }
666
            $db->free($resql);
667
668
            if ($num <= 0) {
669
                print '<td colspan="5"><span class="opacitymedium">' . $langs->trans("None") . '</span></a>';
670
            }
671
            print "</table>";
672
            print "</div>";
673
        } else {
674
            dol_print_error($db);
675
        }
676
    }
677
678
    // Latest leave requests
679
    if (isModEnabled('holiday') && ($user->hasRight('holiday', 'readall') || ($user->hasRight('holiday', 'read') && $object->id == $user->id))) {
680
        $holiday = new Holiday($db);
681
682
        $sql = "SELECT h.rowid, h.statut as status, h.fk_type, h.date_debut, h.date_fin, h.halfday";
683
        $sql .= " FROM " . MAIN_DB_PREFIX . "holiday as h";
684
        $sql .= " WHERE h.fk_user = " . ((int)$object->id);
685
        $sql .= " AND h.entity IN (" . getEntity('holiday') . ")";
686
        $sql .= " ORDER BY h.date_debut DESC";
687
688
        $resql = $db->query($sql);
689
        if ($resql) {
690
            $num = $db->num_rows($resql);
691
692
            print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
693
            print '<table class="noborder centpercent">';
694
695
            print '<tr class="liste_titre">';
696
            print '<td colspan="4"><table class="nobordernopadding centpercent"><tr><td>' . $langs->trans("LastHolidays", ($num <= $MAXLIST ? "" : $MAXLIST)) . '</td><td class="right"><a class="notasortlink" href="' . constant('BASE_URL') . '/holiday/list.php?id=' . $object->id . '">' . $langs->trans("AllHolidays") . '<span class="badge marginleftonlyshort">' . $num . '</span></a></td>';
697
            print '</tr></table></td>';
698
            print '</tr>';
699
700
            $i = 0;
701
            while ($i < $num && $i < $MAXLIST) {
702
                $objp = $db->fetch_object($resql);
703
704
                $holiday->id = $objp->rowid;
705
                $holiday->ref = $objp->rowid;
706
707
                $holiday->fk_type = $objp->fk_type;
708
                $holiday->statut = $objp->status;
709
                $holiday->status = $objp->status;
710
711
                $nbopenedday = num_open_day($db->jdate($objp->date_debut, 'gmt'), $db->jdate($objp->date_fin, 'gmt'), 0, 1, $objp->halfday);
712
713
                print '<tr class="oddeven">';
714
                print '<td class="nowraponall">';
715
                print $holiday->getNomUrl(1);
716
                print '</td><td class="right nowraponall">' . dol_print_date($db->jdate($objp->date_debut), 'day') . "</td>\n";
717
                print '<td class="right nowraponall">' . $nbopenedday . ' ' . $langs->trans('DurationDays') . '</td>';
718
                print '<td class="right nowraponall">' . $holiday->LibStatut($objp->status, 5) . '</td>';
719
                print '</tr>';
720
                $i++;
721
            }
722
            $db->free($resql);
723
724
            if ($num <= 0) {
725
                print '<td colspan="4"><span class="opacitymedium">' . $langs->trans("None") . '</span></a>';
726
            }
727
            print "</table>";
728
            print "</div>";
729
        } else {
730
            dol_print_error($db);
731
        }
732
    }
733
734
    // Latest expense report
735
    if (
736
        isModEnabled('expensereport') &&
737
        ($user->hasRight('expensereport', 'readall') || ($user->hasRight('expensereport', 'lire') && $object->id == $user->id))
738
    ) {
739
        $exp = new ExpenseReport($db);
740
741
        $sql = "SELECT e.rowid, e.ref, e.fk_statut as status, e.date_debut, e.total_ttc";
742
        $sql .= " FROM " . MAIN_DB_PREFIX . "expensereport as e";
743
        $sql .= " WHERE e.fk_user_author = " . ((int)$object->id);
744
        $sql .= " AND e.entity = " . ((int)$conf->entity);
745
        $sql .= " ORDER BY e.date_debut DESC";
746
747
        $resql = $db->query($sql);
748
        if ($resql) {
749
            $num = $db->num_rows($resql);
750
751
            print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
752
            print '<table class="noborder centpercent">';
753
754
            print '<tr class="liste_titre">';
755
            print '<td colspan="4"><table class="nobordernopadding centpercent"><tr><td>' . $langs->trans("LastExpenseReports", ($num <= $MAXLIST ? "" : $MAXLIST)) . '</td><td class="right"><a class="notasortlink" href="' . constant('BASE_URL') . '/expensereport/list.php?id=' . $object->id . '">' . $langs->trans("AllExpenseReports") . '<span class="badge marginleftonlyshort">' . $num . '</span></a></td>';
756
            print '</tr></table></td>';
757
            print '</tr>';
758
759
            $i = 0;
760
            while ($i < $num && $i < $MAXLIST) {
761
                $objp = $db->fetch_object($resql);
762
763
                $exp->id = $objp->rowid;
764
                $exp->ref = $objp->ref;
765
                $exp->status = $objp->status;
766
767
                print '<tr class="oddeven">';
768
                print '<td class="nowraponall">';
769
                print $exp->getNomUrl(1);
770
                print '</td><td class="right nowraponall">' . dol_print_date($db->jdate($objp->date_debut), 'day') . "</td>\n";
771
                print '<td class="right nowraponall"><span class="amount">' . price($objp->total_ttc) . '</span></td>';
772
                print '<td class="right nowraponall">' . $exp->LibStatut($objp->status, 5) . '</td>';
773
                print '</tr>';
774
                $i++;
775
            }
776
            $db->free($resql);
777
778
            if ($num <= 0) {
779
                print '<td colspan="4"><span class="opacitymedium">' . $langs->trans("None") . '</span></a>';
780
            }
781
            print "</table>";
782
            print "</div>";
783
        } else {
784
            dol_print_error($db);
785
        }
786
    }
787
788
    print '</div></div>';
789
    print '<div class="clearboth"></div>';
790
791
    print dol_get_fiche_end();
792
793
    // List of bank accounts (Currently only one bank account possible for each employee)
794
795
    $morehtmlright = '';
796
    if ($account->id == 0) {
797
        if ($permissiontoaddbankaccount) {
798
            $morehtmlright = dolGetButtonTitle($langs->trans('Add'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=create');
799
        } else {
800
            $morehtmlright = dolGetButtonTitle($langs->trans('Add'), $langs->trans('NotEnoughPermissions'), 'fa fa-plus-circle', '', '', -2);
801
        }
802
    } else {
803
        $morehtmlright = dolGetButtonTitle($langs->trans('Add'), $langs->trans('AlreadyOneBankAccount'), 'fa fa-plus-circle', '', '', -2);
804
    }
805
806
    print load_fiche_titre($langs->trans("BankAccounts"), $morehtmlright, 'bank_account');
807
808
    print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
809
    print '<table class="liste centpercent">';
810
811
    print '<tr class="liste_titre">';
812
    print_liste_field_titre("LabelRIB");
813
    print_liste_field_titre("Bank");
814
    print_liste_field_titre("RIB");
815
    print_liste_field_titre("IBAN");
816
    print_liste_field_titre("BIC");
817
    print_liste_field_titre("Currency");
818
    print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', '', '', 'maxwidthsearch ');
819
    print "</tr>\n";
820
821
    if ($account->id > 0) {
822
        print '<tr class="oddeven">';
823
        // Label
824
        print '<td>' . dol_escape_htmltag($account->label) . '</td>';
825
        // Bank name
826
        print '<td>' . dol_escape_htmltag($account->bank) . '</td>';
827
        // Account number
828
        print '<td>';
829
        $stringescaped = '';
830
        foreach ($account->getFieldsToShow() as $val) {
831
            if ($val == 'BankCode') {
832
                $stringescaped .= dol_escape_htmltag($account->code_banque) . ' ';
833
            } elseif ($val == 'BankAccountNumber') {
834
                $stringescaped .= dol_escape_htmltag($account->number) . ' ';
835
            } elseif ($val == 'DeskCode') {
836
                $stringescaped .= dol_escape_htmltag($account->code_guichet) . ' ';
837
            } elseif ($val == 'BankAccountNumberKey') {
838
                $stringescaped .= dol_escape_htmltag($account->cle_rib) . ' ';
839
            }
840
        }
841
        if (!empty($account->label) && $account->number) {
842
            if (!checkBanForAccount($account)) {
843
                $stringescaped .= ' ' . img_picto($langs->trans("ValueIsNotValid"), 'warning');
844
            } else {
845
                $stringescaped .= ' ' . img_picto($langs->trans("ValueIsValid"), 'info');
846
            }
847
        }
848
849
        print $stringescaped;
850
        print '</td>';
851
        // IBAN
852
        print '<td class="tdoverflowmax200" title="' . dol_escape_htmltag(getIbanHumanReadable($account)) . '">';
853
        if (!empty($account->iban)) {
854
            if (!checkIbanForAccount($account)) {
855
                print ' ' . img_picto($langs->trans("IbanNotValid"), 'warning');
856
            }
857
        }
858
        print getIbanHumanReadable($account);
859
        print '</td>';
860
        // BIC
861
        print '<td class="tdoverflowmax150" title="' . dol_escape_htmltag($account->bic) . '">';
862
        if (!empty($account->bic)) {
863
            if (!checkSwiftForAccount($account)) {
864
                print ' ' . img_picto($langs->trans("SwiftNotValid"), 'warning');
865
            }
866
        }
867
        print dol_escape_htmltag($account->bic);
868
        print '</td>';
869
870
        // Currency
871
        print '<td>' . $account->currency_code . '</td>';
872
873
        // Edit/Delete
874
        print '<td class="right nowraponall">';
875
        if ($permissiontoaddbankaccount) {
876
            print '<a class="editfielda marginleftonly marginrightonly" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&bankid=' . $account->id . '&action=edit&token=' . newToken() . '">';
877
            print img_picto($langs->trans("Modify"), 'edit');
878
            print '</a>';
879
880
            print '<a class="editfielda marginleftonly marginrightonly reposition" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&bankid=' . $account->id . '&action=delete_confirmed&token=' . newToken() . '">';
881
            print img_picto($langs->trans("Delete"), 'delete');
882
            print '</a>';
883
        }
884
        print '</td>';
885
886
        print '</tr>';
887
    }
888
889
890
    if ($account->id == 0) {
891
        $colspan = 7;
892
        print '<tr><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs->trans("NoBANRecord") . '</span></td></tr>';
893
    }
894
895
896
    print '</table>';
897
    print '</div>';
898
899
    // Add hook in fields
900
    $parameters = array('colspan' => ' colspan="2"');
901
    $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
902
}
903
904
// Edit
905
if ($id && ($action == 'edit' || $action == 'create') && $permissiontoaddbankaccount) {
906
    $title = $langs->trans("User");
907
    print dol_get_fiche_head($head, 'bank', $title, 0, 'user');
908
909
    $linkback = '<a href="' . constant('BASE_URL') . '/user/list.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>';
910
911
    dol_banner_tab($object, 'id', $linkback, $user->hasRight('user', 'user', 'lire') || $user->admin);
912
913
    print '<div class="underbanner clearboth"></div>';
914
    print '<br>';
915
916
    print '<table class="border centpercent">';
917
918
    print '<tr><td class="titlefield fieldrequired">' . $langs->trans("Label") . '</td>';
919
    print '<td><input size="30" type="text" name="label" value="' . $account->label . '" autofocus></td></tr>';
920
921
    print '<tr><td class="">' . $langs->trans("BankName") . '</td>';
922
    print '<td><input size="30" type="text" name="bank" value="' . $account->bank . '"></td></tr>';
923
924
    // Currency
925
    print '<tr><td class="fieldrequired">' . $langs->trans("Currency");
926
    print '<input type="hidden" value="' . $account->currency_code . '">';
927
    print '</td>';
928
    print '<td class="maxwidth200onsmartphone">';
929
    $selectedcode = $account->currency_code;
930
    if (!$selectedcode) {
931
        $selectedcode = $conf->currency;
932
    }
933
    print img_picto('', 'multicurrency', 'class="pictofixedwidth"');
934
    print $form->selectCurrency((GETPOSTISSET("account_currency_code") ? GETPOST("account_currency_code") : $selectedcode), 'account_currency_code');
935
    print '</td></tr>';
936
937
    // Country
938
    $account->country_id = $account->country_id ? $account->country_id : $mysoc->country_id;
939
    $selectedcode = $account->country_code;
940
    if (GETPOSTISSET("account_country_id")) {
941
        $selectedcode = GETPOST("account_country_id");
942
    } elseif (empty($selectedcode)) {
943
        $selectedcode = $mysoc->country_code;
944
    }
945
    $account->country_code = getCountry($selectedcode, 2); // Force country code on account to have following field on bank fields matching country rules
0 ignored issues
show
Documentation Bug introduced by
It seems like getCountry($selectedcode, 2) can also be of type array. However, the property $country_code is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
946
947
    print '<tr><td class="fieldrequired">' . $langs->trans("Country") . '</td>';
948
    print '<td class="maxwidth200onsmartphone">';
949
    print img_picto('', 'country', 'class="pictofixedwidth"') . $form->select_country($selectedcode, 'account_country_id');
950
    if ($user->admin) {
951
        print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
952
    }
953
    print '</td></tr>';
954
955
    // State
956
    print '<tr><td>' . $langs->trans('State') . '</td><td class="maxwidth200onsmartphone">';
957
    if ($selectedcode) {
958
        print img_picto('', 'state', 'class="pictofixedwidth"');
959
        print $formcompany->select_state(GETPOSTISSET("account_state_id") ? GETPOST("account_state_id") : $account->state_id, $selectedcode, 'account_state_id');
960
    } else {
961
        print $countrynotdefined;
962
    }
963
    print '</td></tr>';
964
965
966
    // Show fields of bank account
967
    $bankaccount = $account;
968
969
    // Code here is similar as in paymentmodes.php for third-parties
970
    foreach ($bankaccount->getFieldsToShow(1) as $val) {
971
        $require = false;
972
        $tooltip = '';
973
        if ($val == 'BankCode') {
974
            $name = 'code_banque';
975
            $size = 8;
976
            $content = $bankaccount->code_banque;
977
        } elseif ($val == 'DeskCode') {
978
            $name = 'code_guichet';
979
            $size = 8;
980
            $content = $bankaccount->code_guichet;
981
        } elseif ($val == 'BankAccountNumber') {
982
            $name = 'number';
983
            $size = 18;
984
            $content = $bankaccount->number;
985
        } elseif ($val == 'BankAccountNumberKey') {
986
            $name = 'cle_rib';
987
            $size = 3;
988
            $content = $bankaccount->cle_rib;
989
        } elseif ($val == 'IBAN') {
990
            $name = 'iban';
991
            $size = 30;
992
            $content = $bankaccount->iban;
993
            if ($bankaccount->needIBAN()) {
994
                $require = true;
995
            }
996
            $tooltip = $langs->trans("Example") . ':<br>CH93 0076 2011 6238 5295 7<br>LT12 1000 0111 0100 1000<br>FR14 2004 1010 0505 0001 3M02 606<br>LU28 0019 4006 4475 0000<br>DE89 3704 0044 0532 0130 00';
997
        } elseif ($val == 'BIC') {
998
            $name = 'bic';
999
            $size = 12;
1000
            $content = $bankaccount->bic;
1001
            if ($bankaccount->needIBAN()) {
1002
                $require = true;
1003
            }
1004
            $tooltip = $langs->trans("Example") . ': LIABLT2XXXX';
1005
        }
1006
        print '<tr>';
1007
        print '<td' . ($require ? ' class="fieldrequired" ' : '') . '>';
1008
        if ($tooltip) {
1009
            print $form->textwithpicto($langs->trans($val), $tooltip, 4, 'help', '', 0, 3, $name);
1010
        } else {
1011
            print $langs->trans($val);
1012
        }
1013
        print '</td>';
1014
        print '<td><input size="' . $size . '" type="text" class="flat" name="' . $name . '" value="' . $content . '"></td>';
1015
        print '</tr>';
1016
    }
1017
1018
    print '<tr><td class="tdtop">' . $langs->trans("BankAccountDomiciliation") . '</td><td colspan="4">';
1019
    print '<textarea name="address" rows="4" class="quatrevingtpercent">';
1020
    print dol_escape_htmltag($account->address);
1021
    print "</textarea></td></tr>";
1022
1023
    print '<tr><td>' . $langs->trans("BankAccountOwner") . '</td>';
1024
    print '<td colspan="4"><input size="30" type="text" name="proprio" value="' . $account->proprio . '"></td></tr>';
1025
    print "</td></tr>\n";
1026
1027
    print '<tr><td class="tdtop">' . $langs->trans("BankAccountOwnerAddress") . '</td><td colspan="4">';
1028
    print '<textarea name="owner_address" rows="4" class="quatrevingtpercent">';
1029
    print dol_escape_htmltag($account->owner_address);
1030
    print "</textarea></td></tr>";
1031
1032
    print '</table>';
1033
1034
    //print '</div>';
1035
1036
    print dol_get_fiche_end();
1037
1038
    print $form->buttonsSaveCancel($action == 'create' ? "Create" : "Modify");
1039
}
1040
1041
if ($id && $action == 'edit' && $permissiontoaddbankaccount) {
1042
    print '</form>';
1043
}
1044
1045
if ($id && $action == 'create' && $permissiontoaddbankaccount) {
1046
    print '</form>';
1047
}
1048
1049
// End of page
1050
ViewMain::llxFooter();
1051
$db->close();
1052