info.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/salaries.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  29. if (!empty($conf->projet->enabled)) {
  30. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  32. }
  33. // Load translation files required by the page
  34. $langs->loadLangs(array("compta", "bills", "users", "salaries", "hrm"));
  35. $id = GETPOST('id', 'int');
  36. $ref = GETPOST('ref', 'alpha');
  37. $action = GETPOST('action', 'aZ09');
  38. $label = GETPOST('label', 'alphanohtml');
  39. $projectid = (GETPOST('projectid', 'int') ? GETPOST('projectid', 'int') : GETPOST('fk_project', 'int'));
  40. // Security check
  41. $socid = GETPOST('socid', 'int');
  42. if ($user->socid) {
  43. $socid = $user->socid;
  44. }
  45. $object = new Salary($db);
  46. $extrafields = new ExtraFields($db);
  47. $childids = $user->getAllChildIds(1);
  48. // fetch optionals attributes and labels
  49. $extrafields->fetch_name_optionals_label($object->table_element);
  50. $object = new Salary($db);
  51. if ($id > 0 || !empty($ref)) {
  52. $object->fetch($id, $ref);
  53. // Check current user can read this salary
  54. $canread = 0;
  55. if (!empty($user->rights->salaries->readall)) {
  56. $canread = 1;
  57. }
  58. if (!empty($user->rights->salaries->read) && $object->fk_user > 0 && in_array($object->fk_user, $childids)) {
  59. $canread = 1;
  60. }
  61. if (!$canread) {
  62. accessforbidden();
  63. }
  64. }
  65. restrictedArea($user, 'salaries', $object->id, 'salary', '');
  66. /*
  67. * Actions
  68. */
  69. // Link to a project
  70. if ($action == 'classin' && $user->rights->banque->modifier) {
  71. $object->fetch($id);
  72. $object->setProject($projectid);
  73. }
  74. // set label
  75. if ($action == 'setlabel' && $user->rights->salaries->write) {
  76. $object->fetch($id);
  77. $object->label = $label;
  78. $object->update($user);
  79. }
  80. /*
  81. * View
  82. */
  83. if (!empty($conf->projet->enabled)) $formproject = new FormProjets($db);
  84. $title = $langs->trans('Salary')." - ".$langs->trans('Info');
  85. $help_url = "";
  86. llxHeader("", $title, $help_url);
  87. $object = new Salary($db);
  88. $object->fetch($id);
  89. $object->info($id);
  90. $head = salaries_prepare_head($object);
  91. print dol_get_fiche_head($head, 'info', $langs->trans("SalaryPayment"), -1, 'salary');
  92. $linkback = '<a href="'.DOL_URL_ROOT.'/salaries/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  93. $morehtmlref = '<div class="refidno">';
  94. $userstatic = new User($db);
  95. $userstatic->fetch($object->fk_user);
  96. // Label
  97. if ($action != 'editlabel') {
  98. $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->salaries->write, 'string', '', 0, 1);
  99. $morehtmlref .= $object->label;
  100. } else {
  101. $morehtmlref .= $langs->trans('Label').' :&nbsp;';
  102. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  103. $morehtmlref .= '<input type="hidden" name="action" value="setlabel">';
  104. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  105. $morehtmlref .= '<input type="text" name="label" value="'.$object->label.'"/>';
  106. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  107. $morehtmlref .= '</form>';
  108. }
  109. $morehtmlref .= '<br>'.$langs->trans('Employee').' : '.$userstatic->getNomUrl(-1);
  110. // Project
  111. if (!empty($conf->projet->enabled)) {
  112. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  113. if ($user->rights->salaries->write) {
  114. if ($action != 'classify') {
  115. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
  116. }
  117. if ($action == 'classify') {
  118. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  119. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  120. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  121. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  122. $morehtmlref .= $formproject->select_projects(-1, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1, 0, 'maxwidth500');
  123. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  124. $morehtmlref .= '</form>';
  125. } else {
  126. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  127. }
  128. } else {
  129. if (!empty($object->fk_project)) {
  130. $proj = new Project($db);
  131. $proj->fetch($object->fk_project);
  132. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  133. if ($proj->title) {
  134. $morehtmlref .= ' - '.$proj->title;
  135. }
  136. } else {
  137. $morehtmlref .= '';
  138. }
  139. }
  140. }
  141. $morehtmlref .= '</div>';
  142. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
  143. print '<div class="fichecenter">';
  144. print '<div class="underbanner clearboth"></div>';
  145. print '<br>';
  146. print '<table width="100%"><tr><td>';
  147. dol_print_object_info($object);
  148. print '</td></tr></table>';
  149. print '</div>';
  150. print dol_get_fiche_end();
  151. // End of page
  152. llxFooter();
  153. $db->close();