bank.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990
  1. <?php
  2. /* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
  4. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2013 Peter Fontaine <contact@peterfontaine.fr>
  7. * Copyright (C) 2015-2016 Marcos García <marcosgdf@gmail.com>
  8. * Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
  9. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  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. * \file htdocs/user/bank.php
  26. * \ingroup HRM
  27. * \brief Tab for HR and bank
  28. */
  29. // Load Dolibarr environment
  30. require '../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/user/class/userbankaccount.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  37. if (isModEnabled('holiday')) {
  38. require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
  39. }
  40. if (isModEnabled('expensereport')) {
  41. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  42. }
  43. if (isModEnabled('salaries')) {
  44. require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
  45. require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php';
  46. }
  47. // Load translation files required by page
  48. $langs->loadLangs(array('companies', 'commercial', 'banks', 'bills', 'trips', 'holiday', 'salaries'));
  49. $id = GETPOST('id', 'int');
  50. $ref = GETPOST('ref', 'alphanohtml');
  51. $bankid = GETPOST('bankid', 'int');
  52. $action = GETPOST("action", 'alpha');
  53. $cancel = GETPOST('cancel', 'alpha');
  54. // Security check
  55. $socid = 0;
  56. if ($user->socid > 0) {
  57. $socid = $user->socid;
  58. }
  59. $feature2 = (($socid && $user->rights->user->self->creer) ? '' : 'user');
  60. $object = new User($db);
  61. if ($id > 0 || !empty($ref)) {
  62. $result = $object->fetch($id, $ref, '', 1);
  63. $object->getrights();
  64. }
  65. $account = new UserBankAccount($db);
  66. if (!$bankid) {
  67. $account->fetch(0, '', $id);
  68. } else {
  69. $account->fetch($bankid);
  70. }
  71. if (empty($account->userid)) {
  72. $account->userid = $object->id;
  73. }
  74. // Define value to know what current user can do on users
  75. $canadduser = (!empty($user->admin) || $user->rights->user->user->creer || $user->rights->hrm->write_personal_information->write);
  76. $canreaduser = (!empty($user->admin) || $user->rights->user->user->lire || $user->rights->hrm->read_personal_information->read);
  77. $permissiontoaddbankaccount = (!empty($user->rights->salaries->write) || !empty($user->rights->hrm->employee->write) || !empty($user->rights->user->creer));
  78. // Ok if user->rights->salaries->read or user->rights->hrm->read
  79. //$result = restrictedArea($user, 'salaries|hrm', $object->id, 'user&user', $feature2);
  80. $ok = false;
  81. if ($user->id == $id) {
  82. $ok = true; // A user can always read its own card
  83. }
  84. if (!empty($user->rights->salaries->read)) {
  85. $ok = true;
  86. }
  87. if (!empty($user->rights->hrm->read)) {
  88. $ok = true;
  89. }
  90. if (!empty($user->rights->expensereport->lire) && ($user->id == $object->id || $user->rights->expensereport->readall)) {
  91. $ok = true;
  92. }
  93. if (!$ok) {
  94. accessforbidden();
  95. }
  96. /*
  97. * Actions
  98. */
  99. if ($action == 'add' && !$cancel && $permissiontoaddbankaccount) {
  100. $account->userid = $object->id;
  101. $account->bank = GETPOST('bank', 'alpha');
  102. $account->label = GETPOST('label', 'alpha');
  103. $account->courant = GETPOST('courant', 'alpha');
  104. $account->code_banque = GETPOST('code_banque', 'alpha');
  105. $account->code_guichet = GETPOST('code_guichet', 'alpha');
  106. $account->number = GETPOST('number', 'alpha');
  107. $account->cle_rib = GETPOST('cle_rib', 'alpha');
  108. $account->bic = GETPOST('bic', 'alpha');
  109. $account->iban = GETPOST('iban', 'alpha');
  110. $account->domiciliation = GETPOST('domiciliation', 'alpha');
  111. $account->proprio = GETPOST('proprio', 'alpha');
  112. $account->owner_address = GETPOST('owner_address', 'alpha');
  113. $account->currency_code = trim(GETPOST("account_currency_code"));
  114. $account->state_id = GETPOST("account_state_id", 'int');
  115. $account->country_id = GETPOST("account_country_id", 'int');
  116. $result = $account->create($user);
  117. if (!$result) {
  118. setEventMessages($account->error, $account->errors, 'errors');
  119. $action = 'edit'; // Force chargement page edition
  120. } else {
  121. setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
  122. $action = '';
  123. }
  124. }
  125. if ($action == 'update' && !$cancel && $permissiontoaddbankaccount) {
  126. $account->userid = $object->id;
  127. $account->bank = GETPOST('bank', 'alpha');
  128. $account->label = GETPOST('label', 'alpha');
  129. $account->courant = GETPOST('courant', 'alpha');
  130. $account->code_banque = GETPOST('code_banque', 'alpha');
  131. $account->code_guichet = GETPOST('code_guichet', 'alpha');
  132. $account->number = GETPOST('number', 'alpha');
  133. $account->cle_rib = GETPOST('cle_rib', 'alpha');
  134. $account->bic = GETPOST('bic', 'alpha');
  135. $account->iban = GETPOST('iban', 'alpha');
  136. $account->domiciliation = GETPOST('domiciliation', 'alpha');
  137. $account->proprio = GETPOST('proprio', 'alpha');
  138. $account->owner_address = GETPOST('owner_address', 'alpha');
  139. $account->currency_code = trim(GETPOST("account_currency_code"));
  140. $account->state_id = GETPOST("account_state_id", 'int');
  141. $account->country_id = GETPOST("account_country_id", 'int');
  142. $result = $account->update($user);
  143. if (!$result) {
  144. setEventMessages($account->error, $account->errors, 'errors');
  145. $action = 'edit'; // Force chargement page edition
  146. } else {
  147. setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
  148. $action = '';
  149. }
  150. }
  151. if ($action == 'delete_confirmed' && !$cancel && $permissiontoaddbankaccount) {
  152. $result = $account->delete($user);
  153. if ($result < 0) {
  154. setEventMessages($account->error, $account->errors, 'errors');
  155. } else {
  156. setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
  157. header("Location: ".DOL_URL_ROOT.'/user/bank.php?id='.$object->id);
  158. exit;
  159. }
  160. $action = '';
  161. }
  162. // update birth
  163. if ($action == 'setbirth' && $canadduser && !$cancel) {
  164. $object->birth = dol_mktime(0, 0, 0, GETPOST('birthmonth', 'int'), GETPOST('birthday', 'int'), GETPOST('birthyear', 'int'));
  165. $result = $object->update($user);
  166. if ($result < 0) {
  167. setEventMessages($object->error, $object->errors, 'errors');
  168. }
  169. }
  170. // update personal email
  171. if ($action == 'setpersonal_email' && $canadduser && !$cancel) {
  172. $object->personal_email = (string) GETPOST('personal_email', 'alphanohtml');
  173. $result = $object->update($user);
  174. if ($result < 0) {
  175. setEventMessages($object->error, $object->errors, 'errors');
  176. }
  177. }
  178. // update personal mobile
  179. if ($action == 'setpersonal_mobile' && $canadduser && !$cancel) {
  180. $object->personal_mobile = (string) GETPOST('personal_mobile', 'alphanohtml');
  181. $result = $object->update($user);
  182. if ($result < 0) {
  183. setEventMessages($object->error, $object->errors, 'errors');
  184. }
  185. }
  186. // update ref_employee
  187. if ($action == 'setref_employee' && $canadduser && !$cancel) {
  188. $object->ref_employee = (string) GETPOST('ref_employee', 'alphanohtml');
  189. $result = $object->update($user);
  190. if ($result < 0) {
  191. setEventMessages($object->error, $object->errors, 'errors');
  192. }
  193. }
  194. // update national_registration_number
  195. if ($action == 'setnational_registration_number' && $canadduser && !$cancel) {
  196. $object->national_registration_number = (string) GETPOST('national_registration_number', 'alphanohtml');
  197. $result = $object->update($user);
  198. if ($result < 0) {
  199. setEventMessages($object->error, $object->errors, 'errors');
  200. }
  201. }
  202. if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) {
  203. // update default_c_exp_tax_cat
  204. if ($action == 'setdefault_c_exp_tax_cat' && $canadduser) {
  205. $object->default_c_exp_tax_cat = GETPOST('default_c_exp_tax_cat', 'int');
  206. $result = $object->update($user);
  207. if ($result < 0) {
  208. setEventMessages($object->error, $object->errors, 'errors');
  209. }
  210. }
  211. // update default range
  212. if ($action == 'setdefault_range' && $canadduser) {
  213. $object->default_range = GETPOST('default_range', 'int');
  214. $result = $object->update($user);
  215. if ($result < 0) {
  216. setEventMessages($object->error, $object->errors, 'errors');
  217. }
  218. }
  219. }
  220. /*
  221. * View
  222. */
  223. $form = new Form($db);
  224. $formcompany = new FormCompany($db);
  225. $childids = $user->getAllChildIds(1);
  226. $person_name = !empty($object->firstname) ? $object->lastname.", ".$object->firstname : $object->lastname;
  227. $title = $person_name." - ".$langs->trans('BankAccounts');
  228. $help_url = '';
  229. llxHeader('', $title, $help_url);
  230. $head = user_prepare_head($object);
  231. if ($id && $bankid && $action == 'edit' && ($user->rights->user->user->creer || $user->rights->hrm->write_personal_information->write)) {
  232. if ($conf->use_javascript_ajax) {
  233. print "\n<script>";
  234. print 'jQuery(document).ready(function () {
  235. jQuery("#type").change(function() {
  236. document.formbank.action.value="edit";
  237. document.formbank.submit();
  238. });
  239. jQuery("#selectaccount_country_id").change(function() {
  240. document.formbank.action.value="edit";
  241. document.formbank.submit();
  242. });
  243. })';
  244. print "</script>\n";
  245. }
  246. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" name="formbank" method="post">';
  247. print '<input type="hidden" name="token" value="'.newToken().'">';
  248. print '<input type="hidden" name="action" value="update">';
  249. print '<input type="hidden" name="id" value="'.GETPOST("id", 'int').'">';
  250. print '<input type="hidden" name="bankid" value="'.$bankid.'">';
  251. }
  252. if ($id && $action == 'create' && $user->rights->user->user->creer) {
  253. if ($conf->use_javascript_ajax) {
  254. print "\n<script>";
  255. print 'jQuery(document).ready(function () {
  256. jQuery("#type").change(function() {
  257. document.formbank.action.value="create";
  258. document.formbank.submit();
  259. });
  260. jQuery("#selectaccount_country_id").change(function() {
  261. document.formbank.action.value="create";
  262. document.formbank.submit();
  263. });
  264. })';
  265. print "</script>\n";
  266. }
  267. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" name="formbank" method="post">';
  268. print '<input type="hidden" name="token" value="'.newToken().'">';
  269. print '<input type="hidden" name="action" value="add">';
  270. print '<input type="hidden" name="bankid" value="'.$bankid.'">';
  271. }
  272. // View
  273. if ($action != 'edit' && $action != 'create') { // If not bank account yet, $account may be empty
  274. $title = $langs->trans("User");
  275. print dol_get_fiche_head($head, 'bank', $title, -1, 'user');
  276. $linkback = '';
  277. if ($user->rights->user->user->lire || $user->admin) {
  278. $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  279. }
  280. $morehtmlref = '<a href="'.DOL_URL_ROOT.'/user/vcard.php?id='.$object->id.'" class="refid">';
  281. $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
  282. $morehtmlref .= '</a>';
  283. dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin, 'rowid', 'ref', $morehtmlref);
  284. print '<div class="fichecenter"><div class="fichehalfleft">';
  285. print '<div class="underbanner clearboth"></div>';
  286. print '<table class="border centpercent tableforfield">';
  287. print '<tr><td class="titlefieldmiddle">'.$langs->trans("Login").'</td>';
  288. if (!empty($object->ldap_sid) && $object->statut == 0) {
  289. print '<td class="error">';
  290. print $langs->trans("LoginAccountDisableInDolibarr");
  291. print '</td>';
  292. } else {
  293. print '<td>';
  294. $addadmin = '';
  295. if (property_exists($object, 'admin')) {
  296. if (isModEnabled('multicompany') && !empty($object->admin) && empty($object->entity)) {
  297. $addadmin .= img_picto($langs->trans("SuperAdministratorDesc"), "redstar", 'class="paddingleft"');
  298. } elseif (!empty($object->admin)) {
  299. $addadmin .= img_picto($langs->trans("AdministratorDesc"), "star", 'class="paddingleft"');
  300. }
  301. }
  302. print showValueWithClipboardCPButton($object->login).$addadmin;
  303. print '</td>';
  304. }
  305. print '</tr>';
  306. // Hierarchy
  307. print '<tr><td>'.$langs->trans("HierarchicalResponsible").'</td>';
  308. print '<td>';
  309. if (empty($object->fk_user)) {
  310. print '<span class="opacitymedium">'.$langs->trans("None").'</span>';
  311. } else {
  312. $huser = new User($db);
  313. if ($object->fk_user > 0) {
  314. $huser->fetch($object->fk_user);
  315. print $huser->getNomUrl(1);
  316. } else {
  317. print '<span class="opacitymedium">'.$langs->trans("None").'</span>';
  318. }
  319. }
  320. print '</td>';
  321. print "</tr>\n";
  322. // Expense report validator
  323. if (isModEnabled('expensereport')) {
  324. print '<tr><td>';
  325. $text = $langs->trans("ForceUserExpenseValidator");
  326. print $form->textwithpicto($text, $langs->trans("ValidatorIsSupervisorByDefault"), 1, 'help');
  327. print '</td>';
  328. print '<td>';
  329. if (!empty($object->fk_user_expense_validator)) {
  330. $evuser = new User($db);
  331. $evuser->fetch($object->fk_user_expense_validator);
  332. print $evuser->getNomUrl(1);
  333. }
  334. print '</td>';
  335. print "</tr>\n";
  336. }
  337. // Holiday request validator
  338. if (isModEnabled('holiday')) {
  339. print '<tr><td>';
  340. $text = $langs->trans("ForceUserHolidayValidator");
  341. print $form->textwithpicto($text, $langs->trans("ValidatorIsSupervisorByDefault"), 1, 'help');
  342. print '</td>';
  343. print '<td>';
  344. if (!empty($object->fk_user_holiday_validator)) {
  345. $hvuser = new User($db);
  346. $hvuser->fetch($object->fk_user_holiday_validator);
  347. print $hvuser->getNomUrl(1);
  348. }
  349. print '</td>';
  350. print "</tr>\n";
  351. }
  352. // Position/Job
  353. print '<tr><td>'.$langs->trans("PostOrFunction").'</td>';
  354. print '<td>'.dol_escape_htmltag($object->job).'</td>';
  355. print '</tr>'."\n";
  356. // Weeklyhours
  357. print '<tr><td>'.$langs->trans("WeeklyHours").'</td>';
  358. print '<td>';
  359. print price2num($object->weeklyhours);
  360. print '</td>';
  361. print "</tr>\n";
  362. // Sensitive salary/value information
  363. if ((empty($user->socid) && in_array($id, $childids)) // A user can always see salary/value information for its subordinates
  364. || (!empty($conf->salaries->enabled) && !empty($user->rights->salaries->readall))
  365. || (isModEnabled('hrm') && !empty($user->rights->hrm->employee->read))) {
  366. $langs->load("salaries");
  367. // Salary
  368. print '<tr><td>'.$langs->trans("Salary").'</td>';
  369. print '<td>';
  370. print ($object->salary != '' ? img_picto('', 'salary', 'class="pictofixedwidth paddingright"').'<span class="amount">'.price($object->salary, '', $langs, 1, -1, -1, $conf->currency) : '').'</span>';
  371. print '</td>';
  372. print "</tr>\n";
  373. // THM
  374. print '<tr><td>';
  375. $text = $langs->trans("THM");
  376. print $form->textwithpicto($text, $langs->trans("THMDescription"), 1, 'help', 'classthm');
  377. print '</td>';
  378. print '<td>';
  379. print ($object->thm != '' ?price($object->thm, '', $langs, 1, -1, -1, $conf->currency) : '');
  380. print '</td>';
  381. print "</tr>\n";
  382. // TJM
  383. print '<tr><td>';
  384. $text = $langs->trans("TJM");
  385. print $form->textwithpicto($text, $langs->trans("TJMDescription"), 1, 'help', 'classtjm');
  386. print '</td>';
  387. print '<td>';
  388. print ($object->tjm != '' ?price($object->tjm, '', $langs, 1, -1, -1, $conf->currency) : '');
  389. print '</td>';
  390. print "</tr>\n";
  391. }
  392. // Date employment
  393. print '<tr><td>'.$langs->trans("DateOfEmployment").'</td>';
  394. print '<td>';
  395. if ($object->dateemployment) {
  396. print '<span class="opacitymedium">'.$langs->trans("FromDate").'</span> ';
  397. print dol_print_date($object->dateemployment, 'day');
  398. }
  399. if ($object->dateemploymentend) {
  400. print '<span class="opacitymedium"> - '.$langs->trans("To").'</span> ';
  401. print dol_print_date($object->dateemploymentend, 'day');
  402. }
  403. print '</td>';
  404. print "</tr>\n";
  405. // Date of birth
  406. if ($user->hasRight('hrm', 'read_personal_information', 'read') || $user->hasRight('hrm', 'write_personal_information', 'write')) {
  407. print '<tr>';
  408. print '<td>';
  409. print $form->editfieldkey("DateOfBirth", 'birth', $object->birth, $object, $user->rights->user->user->creer);
  410. print '</td><td>';
  411. print $form->editfieldval("DateOfBirth", 'birth', $object->birth, $object, $user->rights->user->user->creer, 'day', $object->birth);
  412. print '</td>';
  413. print "</tr>\n";
  414. }
  415. // Personal email
  416. if ($user->hasRight('hrm', 'read_personal_information', 'read') || $user->hasRight('hrm', 'write_personal_information', 'write')) {
  417. print '<tr class="nowrap">';
  418. print '<td>';
  419. print $form->editfieldkey("UserPersonalEmail", 'personal_email', $object->personal_email, $object, $user->rights->user->user->creer || $user->rights->hrm->write_personal_information->write);
  420. print '</td><td>';
  421. print $form->editfieldval("UserPersonalEmail", 'personal_email', $object->personal_email, $object, $user->rights->user->user->creer || $user->rights->hrm->write_personal_information->write, 'email', '', null, null, '', 0, 'dol_print_email');
  422. print '</td>';
  423. print '</tr>';
  424. }
  425. // Personal phone
  426. if ($user->hasRight('hrm', 'read_personal_information', 'read') || $user->hasRight('hrm', 'write_personal_information', 'write')) {
  427. print '<tr class="nowrap">';
  428. print '<td>';
  429. print $form->editfieldkey("UserPersonalMobile", 'personal_mobile', $object->personal_mobile, $object, $user->rights->user->user->creer || $user->rights->hrm->write_personal_information->write);
  430. print '</td><td>';
  431. print $form->editfieldval("UserPersonalMobile", 'personal_mobile', $object->personal_mobile, $object, $user->rights->user->user->creer || $user->rights->hrm->write_personal_information->write, 'string', '', null, null, '', 0, 'dol_print_phone');
  432. print '</td>';
  433. print '</tr>';
  434. }
  435. if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) {
  436. print '<tr class="nowrap">';
  437. print '<td>';
  438. print $form->editfieldkey("DefaultCategoryCar", 'default_c_exp_tax_cat', $object->default_c_exp_tax_cat, $object, $user->rights->user->user->creer);
  439. print '</td><td>';
  440. if ($action == 'editdefault_c_exp_tax_cat') {
  441. $ret = '<form method="post" action="'.$_SERVER["PHP_SELF"].($moreparam ? '?'.$moreparam : '').'">';
  442. $ret .= '<input type="hidden" name="action" value="setdefault_c_exp_tax_cat">';
  443. $ret .= '<input type="hidden" name="token" value="'.newToken().'">';
  444. $ret .= '<input type="hidden" name="id" value="'.$object->id.'">';
  445. $ret .= $form->selectExpenseCategories($object->default_c_exp_tax_cat, 'default_c_exp_tax_cat', 1);
  446. $ret .= '<input type="submit" class="button" name="modify" value="'.$langs->trans("Modify").'"> ';
  447. $ret .= '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  448. $ret .= '</form>';
  449. print $ret;
  450. } else {
  451. $label_exp_tax_cat = dol_getIdFromCode($db, $object->default_c_exp_tax_cat, 'c_exp_tax_cat', 'rowid', 'label');
  452. print $langs->trans($label_exp_tax_cat);
  453. //print $form->editfieldval("DefaultCategoryCar", 'default_c_exp_tax_cat', $object->default_c_exp_tax_cat, $object, $user->rights->user->user->creer, 'string', ($object->default_c_exp_tax_cat != '' ? $object->default_c_exp_tax_cat : ''));
  454. }
  455. print '</td>';
  456. print '</tr>';
  457. print '<tr class="nowrap">';
  458. print '<td>';
  459. print $form->editfieldkey("DefaultRangeNumber", 'default_range', $object->default_range, $object, $user->rights->user->user->creer);
  460. print '</td><td>';
  461. if ($action == 'editdefault_range') {
  462. $ret = '<form method="post" action="'.$_SERVER["PHP_SELF"].($moreparam ? '?'.$moreparam : '').'">';
  463. $ret .= '<input type="hidden" name="action" value="setdefault_range">';
  464. $ret .= '<input type="hidden" name="token" value="'.newToken().'">';
  465. $ret .= '<input type="hidden" name="id" value="'.$object->id.'">';
  466. $expensereportik = new ExpenseReportIk($db);
  467. $maxRangeNum = $expensereportik->getMaxRangeNumber($object->default_c_exp_tax_cat);
  468. $ret .= $form->selectarray('default_range', range(0, $maxRangeNum), $object->default_range);
  469. $ret .= '<input type="submit" class="button" name="modify" value="'.$langs->trans("Modify").'"> ';
  470. $ret .= '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  471. $ret .= '</form>';
  472. print $ret;
  473. } else {
  474. print $object->default_range;
  475. }
  476. print '</td>';
  477. print '</tr>';
  478. }
  479. // Accountancy code
  480. if (isModEnabled('accounting')) {
  481. print '<tr><td>'.$langs->trans("AccountancyCode").'</td>';
  482. print '<td>'.$object->accountancy_code.'</td></tr>';
  483. }
  484. // Employee Number
  485. if ($user->hasRight('hrm', 'read_personal_information', 'read') || $user->hasRight('hrm', 'write_personal_information', 'write')) {
  486. print '<tr class="nowrap">';
  487. print '<td>';
  488. print $form->editfieldkey("RefEmployee", 'ref_employee', $object->ref_employee, $object, $user->rights->user->user->creer || $user->rights->hrm->write_personal_information->write);
  489. print '</td><td>';
  490. print $form->editfieldval("RefEmployee", 'ref_employee', $object->ref_employee, $object, $user->rights->user->user->creer || $user->rights->hrm->write_personal_information->write, 'string', $object->ref_employee);
  491. print '</td>';
  492. print '</tr>';
  493. }
  494. // National registration number
  495. if ($user->hasRight('hrm', 'read_personal_information', 'read') || $user->hasRight('hrm', 'write_personal_information', 'write')) {
  496. print '<tr class="nowrap">';
  497. print '<td>';
  498. print $form->editfieldkey("NationalRegistrationNumber", 'national_registration_number', $object->national_registration_number, $object, $user->rights->user->user->creer || $user->rights->hrm->write_personal_information->write);
  499. print '</td><td>';
  500. print $form->editfieldval("NationalRegistrationNumber", 'national_registration_number', $object->national_registration_number, $object, $user->rights->user->user->creer || $user->rights->hrm->write_personal_information->write, 'string', $object->national_registration_number);
  501. print '</td>';
  502. print '</tr>';
  503. }
  504. print '</table>';
  505. print '</div><div class="fichehalfright">';
  506. // Max number of elements in small lists
  507. $MAXLIST = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
  508. // Latest payments of salaries
  509. if (!empty($conf->salaries->enabled) &&
  510. (($user->rights->salaries->read && (in_array($object->id, $childids) || $object->id == $user->id)) || (!empty($user->rights->salaries->readall)))
  511. ) {
  512. $payment_salary = new PaymentSalary($db);
  513. $salary = new Salary($db);
  514. $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";
  515. $sql .= " FROM ".MAIN_DB_PREFIX."salary as s";
  516. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."payment_salary as ps ON (s.rowid = ps.fk_salary)";
  517. $sql .= " WHERE s.fk_user = ".((int) $object->id);
  518. $sql .= " AND s.entity IN (".getEntity('salary').")";
  519. $sql .= " GROUP BY s.rowid, s.ref, s.label, s.datesp, s.dateep, s.paye, s.amount";
  520. $sql .= " ORDER BY s.dateep DESC";
  521. $resql = $db->query($sql);
  522. if ($resql) {
  523. $num = $db->num_rows($resql);
  524. print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  525. print '<table class="noborder centpercent">';
  526. print '<tr class="liste_titre">';
  527. print '<td colspan="5"><table class="nobordernopadding centpercent"><tr><td>'.$langs->trans("LastSalaries", ($num <= $MAXLIST ? "" : $MAXLIST)).'</td><td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/salaries/list.php?search_user='.$object->login.'">'.$langs->trans("AllSalaries").'<span class="badge marginleftonlyshort">'.$num.'</span></a></td>';
  528. print '</tr></table></td>';
  529. print '</tr>';
  530. $i = 0;
  531. while ($i < $num && $i < $MAXLIST) {
  532. $objp = $db->fetch_object($resql);
  533. $salary->id = $objp->sid;
  534. $salary->ref = $objp->sref ? $objp->sref : $objp->sid;
  535. $salary->label = $objp->label;
  536. $salary->datesp = $db->jdate($objp->datesp);
  537. $salary->dateep = $db->jdate($objp->dateep);
  538. $salary->paye = $objp->paye;
  539. $salary->amount = $objp->amount;
  540. $payment_salary->id = !empty($objp->rowid) ? $objp->rowid : 0;
  541. $payment_salary->ref = !empty($objp->ref) ? $objp->ref : "";
  542. $payment_salary->datep = $db->jdate(!empty($objp->datep) ? $objp->datep : "");
  543. print '<tr class="oddeven">';
  544. print '<td class="nowraponall">';
  545. print $salary->getNomUrl(1);
  546. print '</td>';
  547. print '<td class="right nowraponall">'.dol_print_date($db->jdate($objp->datesp), 'day')."</td>\n";
  548. print '<td class="right nowraponall">'.dol_print_date($db->jdate($objp->dateep), 'day')."</td>\n";
  549. print '<td class="right nowraponall"><span class="amount">'.price($objp->amount).'</span></td>';
  550. print '<td class="right nowraponall">'.$salary->getLibStatut(5, $objp->alreadypaid).'</td>';
  551. print '</tr>';
  552. $i++;
  553. }
  554. $db->free($resql);
  555. if ($num <= 0) {
  556. print '<td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></a>';
  557. }
  558. print "</table>";
  559. print "</div>";
  560. } else {
  561. dol_print_error($db);
  562. }
  563. }
  564. // Latest leave requests
  565. if (isModEnabled('holiday') && ($user->rights->holiday->readall || ($user->rights->holiday->read && $object->id == $user->id))) {
  566. $holiday = new Holiday($db);
  567. $sql = "SELECT h.rowid, h.statut as status, h.fk_type, h.date_debut, h.date_fin, h.halfday";
  568. $sql .= " FROM ".MAIN_DB_PREFIX."holiday as h";
  569. $sql .= " WHERE h.fk_user = ".((int) $object->id);
  570. $sql .= " AND h.entity IN (".getEntity('holiday').")";
  571. $sql .= " ORDER BY h.date_debut DESC";
  572. $resql = $db->query($sql);
  573. if ($resql) {
  574. $num = $db->num_rows($resql);
  575. print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  576. print '<table class="noborder centpercent">';
  577. print '<tr class="liste_titre">';
  578. print '<td colspan="4"><table class="nobordernopadding centpercent"><tr><td>'.$langs->trans("LastHolidays", ($num <= $MAXLIST ? "" : $MAXLIST)).'</td><td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/holiday/list.php?id='.$object->id.'">'.$langs->trans("AllHolidays").'<span class="badge marginleftonlyshort">'.$num.'</span></a></td>';
  579. print '</tr></table></td>';
  580. print '</tr>';
  581. $i = 0;
  582. while ($i < $num && $i < $MAXLIST) {
  583. $objp = $db->fetch_object($resql);
  584. $holiday->id = $objp->rowid;
  585. $holiday->ref = $objp->rowid;
  586. $holiday->fk_type = $objp->fk_type;
  587. $holiday->statut = $objp->status;
  588. $holiday->status = $objp->status;
  589. $nbopenedday = num_open_day($db->jdate($objp->date_debut, 'gmt'), $db->jdate($objp->date_fin, 'gmt'), 0, 1, $objp->halfday);
  590. print '<tr class="oddeven">';
  591. print '<td class="nowraponall">';
  592. print $holiday->getNomUrl(1);
  593. print '</td><td class="right nowraponall">'.dol_print_date($db->jdate($objp->date_debut), 'day')."</td>\n";
  594. print '<td class="right nowraponall">'.$nbopenedday.' '.$langs->trans('DurationDays').'</td>';
  595. print '<td class="right nowraponall">'.$holiday->LibStatut($objp->status, 5).'</td>';
  596. print '</tr>';
  597. $i++;
  598. }
  599. $db->free($resql);
  600. if ($num <= 0) {
  601. print '<td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></a>';
  602. }
  603. print "</table>";
  604. print "</div>";
  605. } else {
  606. dol_print_error($db);
  607. }
  608. }
  609. // Latest expense report
  610. if (isModEnabled('expensereport') &&
  611. ($user->rights->expensereport->readall || ($user->rights->expensereport->lire && $object->id == $user->id))
  612. ) {
  613. $exp = new ExpenseReport($db);
  614. $sql = "SELECT e.rowid, e.ref, e.fk_statut as status, e.date_debut, e.total_ttc";
  615. $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as e";
  616. $sql .= " WHERE e.fk_user_author = ".((int) $object->id);
  617. $sql .= " AND e.entity = ".((int) $conf->entity);
  618. $sql .= " ORDER BY e.date_debut DESC";
  619. $resql = $db->query($sql);
  620. if ($resql) {
  621. $num = $db->num_rows($resql);
  622. print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  623. print '<table class="noborder centpercent">';
  624. print '<tr class="liste_titre">';
  625. print '<td colspan="4"><table class="nobordernopadding centpercent"><tr><td>'.$langs->trans("LastExpenseReports", ($num <= $MAXLIST ? "" : $MAXLIST)).'</td><td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/expensereport/list.php?id='.$object->id.'">'.$langs->trans("AllExpenseReports").'<span class="badge marginleftonlyshort">'.$num.'</span></a></td>';
  626. print '</tr></table></td>';
  627. print '</tr>';
  628. $i = 0;
  629. while ($i < $num && $i < $MAXLIST) {
  630. $objp = $db->fetch_object($resql);
  631. $exp->id = $objp->rowid;
  632. $exp->ref = $objp->ref;
  633. $exp->status = $objp->status;
  634. print '<tr class="oddeven">';
  635. print '<td class="nowraponall">';
  636. print $exp->getNomUrl(1);
  637. print '</td><td class="right nowraponall">'.dol_print_date($db->jdate($objp->date_debut), 'day')."</td>\n";
  638. print '<td class="right nowraponall"><span class="amount">'.price($objp->total_ttc).'</span></td>';
  639. print '<td class="right nowraponall">'.$exp->LibStatut($objp->status, 5).'</td>';
  640. print '</tr>';
  641. $i++;
  642. }
  643. $db->free($resql);
  644. if ($num <= 0) {
  645. print '<td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></a>';
  646. }
  647. print "</table>";
  648. print "</div>";
  649. } else {
  650. dol_print_error($db);
  651. }
  652. }
  653. print '</div></div>';
  654. print '<div style="clear:both"></div>';
  655. print dol_get_fiche_end();
  656. // List of bank accounts (Currently only one bank account possible for each employee)
  657. $morehtmlright = '';
  658. if ($account->id == 0) {
  659. if ($permissiontoaddbankaccount) {
  660. $morehtmlright = dolGetButtonTitle($langs->trans('Add'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=create');
  661. } else {
  662. $morehtmlright = dolGetButtonTitle($langs->trans('Add'), $langs->trans('NotEnoughPermissions'), 'fa fa-plus-circle', '', '', -2);
  663. }
  664. } else {
  665. $morehtmlright = dolGetButtonTitle($langs->trans('Add'), $langs->trans('AlreadyOneBankAccount'), 'fa fa-plus-circle', '', '', -2);
  666. }
  667. print load_fiche_titre($langs->trans("BankAccounts"), $morehtmlright, 'bank_account');
  668. print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  669. print '<table class="liste centpercent">';
  670. print '<tr class="liste_titre">';
  671. print_liste_field_titre("LabelRIB");
  672. print_liste_field_titre("Bank");
  673. print_liste_field_titre("RIB");
  674. print_liste_field_titre("IBAN");
  675. print_liste_field_titre("BIC");
  676. print_liste_field_titre("Currency");
  677. print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', '', '', 'maxwidthsearch ');
  678. print "</tr>\n";
  679. if ($account->id > 0) {
  680. print '<tr class="oddeven">';
  681. // Label
  682. print '<td>'.dol_escape_htmltag($account->label).'</td>';
  683. // Bank name
  684. print '<td>'.dol_escape_htmltag($account->bank).'</td>';
  685. // Account number
  686. print '<td>';
  687. $stringescaped = '';
  688. foreach ($account->getFieldsToShow() as $val) {
  689. if ($val == 'BankCode') {
  690. $stringescaped .= dol_escape_htmltag($account->code_banque).' ';
  691. } elseif ($val == 'BankAccountNumber') {
  692. $stringescaped .= dol_escape_htmltag($account->number).' ';
  693. } elseif ($val == 'DeskCode') {
  694. $stringescaped .= dol_escape_htmltag($account->code_guichet).' ';
  695. } elseif ($val == 'BankAccountNumberKey') {
  696. $stringescaped .= dol_escape_htmltag($account->cle_rib).' ';
  697. }
  698. }
  699. if (!empty($account->label) && $account->number) {
  700. if (!checkBanForAccount($account)) {
  701. $stringescaped .= ' '.img_picto($langs->trans("ValueIsNotValid"), 'warning');
  702. } else {
  703. $stringescaped .= ' '.img_picto($langs->trans("ValueIsValid"), 'info');
  704. }
  705. }
  706. print $stringescaped;
  707. print '</td>';
  708. // IBAN
  709. print '<td>'.getIbanHumanReadable($account);
  710. if (!empty($account->iban)) {
  711. if (!checkIbanForAccount($account)) {
  712. print ' '.img_picto($langs->trans("IbanNotValid"), 'warning');
  713. }
  714. }
  715. print '</td>';
  716. // BIC
  717. print '<td>';
  718. print dol_escape_htmltag($account->bic);
  719. if (!empty($account->bic)) {
  720. if (!checkSwiftForAccount($account)) {
  721. print ' '.img_picto($langs->trans("SwiftNotValid"), 'warning');
  722. }
  723. }
  724. print '</td>';
  725. // Currency
  726. print '<td>'.$account->currency_code.'</td>';
  727. // Edit/Delete
  728. print '<td class="right nowraponall">';
  729. if ($permissiontoaddbankaccount) {
  730. print '<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&bankid='.$account->id.'&action=edit&token='.newToken().'">';
  731. print img_picto($langs->trans("Modify"), 'edit');
  732. print '</a>';
  733. print '<a class="editfielda marginleftonly marginrightonly reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&bankid='.$account->id.'&action=delete_confirmed&token='.newToken().'">';
  734. print img_picto($langs->trans("Delete"), 'delete');
  735. print '</a>';
  736. }
  737. print '</td>';
  738. print '</tr>';
  739. }
  740. if ($account->id == 0) {
  741. $colspan = 7;
  742. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoBANRecord").'</span></td></tr>';
  743. }
  744. print '</table>';
  745. print '</div>';
  746. }
  747. // Edit
  748. if ($id && ($action == 'edit' || $action == 'create') && $user->rights->user->user->creer) {
  749. $title = $langs->trans("User");
  750. print dol_get_fiche_head($head, 'bank', $title, 0, 'user');
  751. $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  752. dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin);
  753. //print '<div class="fichecenter">';
  754. print '<div class="underbanner clearboth"></div>';
  755. print '<table class="border centpercent">';
  756. print '<tr><td class="titlefield fieldrequired">'.$langs->trans("LabelRIB").'</td>';
  757. print '<td colspan="4"><input size="30" type="text" name="label" value="'.$account->label.'"></td></tr>';
  758. print '<tr><td class="fieldrequired">'.$langs->trans("BankName").'</td>';
  759. print '<td><input size="30" type="text" name="bank" value="'.$account->bank.'"></td></tr>';
  760. // Currency
  761. print '<tr><td class="fieldrequired">'.$langs->trans("Currency");
  762. print '<input type="hidden" value="'.$account->currency_code.'">';
  763. print '</td>';
  764. print '<td class="maxwidth200onsmartphone">';
  765. $selectedcode = $account->currency_code;
  766. if (!$selectedcode) {
  767. $selectedcode = $conf->currency;
  768. }
  769. print img_picto('', 'multicurrency', 'class="pictofixedwidth"');
  770. print $form->selectCurrency((GETPOSTISSET("account_currency_code") ? GETPOST("account_currency_code") : $selectedcode), 'account_currency_code');
  771. print '</td></tr>';
  772. // Country
  773. $account->country_id = $account->country_id ? $account->country_id : $mysoc->country_id;
  774. $selectedcode = $account->country_code;
  775. if (GETPOSTISSET("account_country_id")) {
  776. $selectedcode = GETPOST("account_country_id");
  777. } elseif (empty($selectedcode)) {
  778. $selectedcode = $mysoc->country_code;
  779. }
  780. $account->country_code = getCountry($selectedcode, 2); // Force country code on account to have following field on bank fields matching country rules
  781. print '<tr><td class="fieldrequired">'.$langs->trans("Country").'</td>';
  782. print '<td class="maxwidth200onsmartphone">';
  783. print img_picto('', 'country', 'class="pictofixedwidth"').$form->select_country($selectedcode, 'account_country_id');
  784. if ($user->admin) {
  785. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  786. }
  787. print '</td></tr>';
  788. // State
  789. print '<tr><td>'.$langs->trans('State').'</td><td class="maxwidth200onsmartphone">';
  790. if ($selectedcode) {
  791. print img_picto('', 'state', 'class="pictofixedwidth"');
  792. print $formcompany->select_state(GETPOSTISSET("account_state_id") ? GETPOST("account_state_id") : $account->state_id, $selectedcode, 'account_state_id');
  793. } else {
  794. print $countrynotdefined;
  795. }
  796. print '</td></tr>';
  797. // Show fields of bank account
  798. foreach ($account->getFieldsToShow() as $val) {
  799. if ($val == 'BankCode') {
  800. $name = 'code_banque';
  801. $size = 8;
  802. $content = $account->code_banque;
  803. } elseif ($val == 'DeskCode') {
  804. $name = 'code_guichet';
  805. $size = 8;
  806. $content = $account->code_guichet;
  807. } elseif ($val == 'BankAccountNumber') {
  808. $name = 'number';
  809. $size = 18;
  810. $content = $account->number;
  811. } elseif ($val == 'BankAccountNumberKey') {
  812. $name = 'cle_rib';
  813. $size = 3;
  814. $content = $account->cle_rib;
  815. }
  816. print '<td>'.$langs->trans($val).'</td>';
  817. print '<td><input size="'.$size.'" type="text" class="flat" name="'.$name.'" value="'.$content.'"></td>';
  818. print '</tr>';
  819. }
  820. // IBAN
  821. print '<tr><td class="fieldrequired">'.$langs->trans("IBAN").'</td>';
  822. print '<td colspan="4"><input size="30" type="text" name="iban" value="'.$account->iban.'"></td></tr>';
  823. print '<tr><td class="fieldrequired">'.$langs->trans("BIC").'</td>';
  824. print '<td colspan="4"><input size="12" type="text" name="bic" value="'.$account->bic.'"></td></tr>';
  825. print '<tr><td class="tdtop">'.$langs->trans("BankAccountDomiciliation").'</td><td colspan="4">';
  826. print '<textarea name="domiciliation" rows="4" class="quatrevingtpercent">';
  827. print dol_escape_htmltag($account->domiciliation);
  828. print "</textarea></td></tr>";
  829. print '<tr><td>'.$langs->trans("BankAccountOwner").'</td>';
  830. print '<td colspan="4"><input size="30" type="text" name="proprio" value="'.$account->proprio.'"></td></tr>';
  831. print "</td></tr>\n";
  832. print '<tr><td class="tdtop">'.$langs->trans("BankAccountOwnerAddress").'</td><td colspan="4">';
  833. print '<textarea name="owner_address" rows="4" class="quatrevingtpercent">';
  834. print dol_escape_htmltag($account->owner_address);
  835. print "</textarea></td></tr>";
  836. print '</table>';
  837. //print '</div>';
  838. print dol_get_fiche_end();
  839. print $form->buttonsSaveCancel("Modify");
  840. }
  841. if ($id && $action == 'edit' && $user->rights->user->user->creer) {
  842. print '</form>';
  843. }
  844. if ($id && $action == 'create' && $user->rights->user->user->creer) {
  845. print '</form>';
  846. }
  847. // End of page
  848. llxFooter();
  849. $db->close();