info.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. /* Copyright (C) 2005-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2015 Charlie BENKE <charlie@patas-monkey.com>
  4. * Copyright (C) 2017-2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
  5. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/salaries/info.php
  22. * \ingroup salaries
  23. * \brief Page with info about salaries contribution
  24. */
  25. // Load Dolibarr environment
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/salaries.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  30. if (isModEnabled('project')) {
  31. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  33. }
  34. // Load translation files required by the page
  35. $langs->loadLangs(array("compta", "bills", "users", "salaries", "hrm"));
  36. $id = GETPOST('id', 'int');
  37. $ref = GETPOST('ref', 'alpha');
  38. $action = GETPOST('action', 'aZ09');
  39. $label = GETPOST('label', 'alphanohtml');
  40. $projectid = (GETPOST('projectid', 'int') ? GETPOST('projectid', 'int') : GETPOST('fk_project', 'int'));
  41. // Security check
  42. $socid = GETPOST('socid', 'int');
  43. if ($user->socid) {
  44. $socid = $user->socid;
  45. }
  46. $object = new Salary($db);
  47. $extrafields = new ExtraFields($db);
  48. $childids = $user->getAllChildIds(1);
  49. // fetch optionals attributes and labels
  50. $extrafields->fetch_name_optionals_label($object->table_element);
  51. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  52. $hookmanager->initHooks(array('salaryinfo', 'globalcard'));
  53. $object = new Salary($db);
  54. if ($id > 0 || !empty($ref)) {
  55. $object->fetch($id, $ref);
  56. // Check current user can read this salary
  57. $canread = 0;
  58. if (!empty($user->rights->salaries->readall)) {
  59. $canread = 1;
  60. }
  61. if (!empty($user->rights->salaries->read) && $object->fk_user > 0 && in_array($object->fk_user, $childids)) {
  62. $canread = 1;
  63. }
  64. if (!$canread) {
  65. accessforbidden();
  66. }
  67. }
  68. restrictedArea($user, 'salaries', $object->id, 'salary', '');
  69. $permissiontoread = $user->rights->salaries->read;
  70. $permissiontoadd = $user->rights->salaries->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles
  71. $permissiontodelete = $user->rights->salaries->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  72. /*
  73. * Actions
  74. */
  75. // Link to a project
  76. if ($action == 'classin' && $user->rights->banque->modifier) {
  77. $object->fetch($id);
  78. $object->setProject($projectid);
  79. }
  80. // set label
  81. if ($action == 'setlabel' && $user->rights->salaries->write) {
  82. $object->fetch($id);
  83. $object->label = $label;
  84. $object->update($user);
  85. }
  86. /*
  87. * View
  88. */
  89. if (isModEnabled('project')) $formproject = new FormProjets($db);
  90. $title = $langs->trans('Salary')." - ".$langs->trans('Info');
  91. $help_url = "";
  92. llxHeader("", $title, $help_url);
  93. $object->fetch($id);
  94. $object->info($id);
  95. $head = salaries_prepare_head($object);
  96. print dol_get_fiche_head($head, 'info', $langs->trans("SalaryPayment"), -1, 'salary');
  97. $linkback = '<a href="'.DOL_URL_ROOT.'/salaries/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  98. $morehtmlref = '<div class="refidno">';
  99. $userstatic = new User($db);
  100. $userstatic->fetch($object->fk_user);
  101. // Label
  102. if ($action != 'editlabel') {
  103. $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->salaries->write, 'string', '', 0, 1);
  104. $morehtmlref .= $object->label;
  105. } else {
  106. $morehtmlref .= $langs->trans('Label').' :&nbsp;';
  107. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  108. $morehtmlref .= '<input type="hidden" name="action" value="setlabel">';
  109. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  110. $morehtmlref .= '<input type="text" name="label" value="'.$object->label.'"/>';
  111. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  112. $morehtmlref .= '</form>';
  113. }
  114. $morehtmlref .= '<br>'.$langs->trans('Employee').' : '.$userstatic->getNomUrl(-1);
  115. $usercancreate = $permissiontoadd;
  116. // Project
  117. if (isModEnabled('project')) {
  118. $langs->load("projects");
  119. $morehtmlref .= '<br>';
  120. if ($usercancreate) {
  121. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  122. if ($action != 'classify') {
  123. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  124. }
  125. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  126. } else {
  127. if (!empty($object->fk_project)) {
  128. $proj = new Project($db);
  129. $proj->fetch($object->fk_project);
  130. $morehtmlref .= $proj->getNomUrl(1);
  131. if ($proj->title) {
  132. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  133. }
  134. }
  135. }
  136. }
  137. $morehtmlref .= '</div>';
  138. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
  139. print '<div class="fichecenter">';
  140. print '<div class="underbanner clearboth"></div>';
  141. print '<br>';
  142. print '<table class="centpercent"><tr><td>';
  143. dol_print_object_info($object);
  144. print '</td></tr></table>';
  145. print '</div>';
  146. print dol_get_fiche_end();
  147. // End of page
  148. llxFooter();
  149. $db->close();