document.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
  7. * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  9. * Copyright (C) 2015-2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
  10. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. * or see https://www.gnu.org/
  25. */
  26. /**
  27. * \file htdocs/salaries/document.php
  28. * \ingroup salaries
  29. * \brief Page of linked files onto salaries
  30. */
  31. // Load Dolibarr environment
  32. require '../main.inc.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/salaries.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
  37. if (isModEnabled('project')) {
  38. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  40. }
  41. // Load translation files required by the page
  42. $langs->loadLangs(array("compta", "bills", "users", "salaries", "hrm"));
  43. $id = GETPOST('id', 'int');
  44. $ref = GETPOST('ref', 'alpha');
  45. $action = GETPOST('action', 'aZ09');
  46. $confirm = GETPOST('confirm', 'alpha');
  47. $label = GETPOST('label', 'alphanohtml');
  48. $projectid = (GETPOST('projectid', 'int') ? GETPOST('projectid', 'int') : GETPOST('fk_project', 'int'));
  49. // Get parameters
  50. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  51. $sortfield = GETPOST('sortfield', 'aZ09comma');
  52. $sortorder = GETPOST('sortorder', 'aZ09comma');
  53. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  54. if (empty($page) || $page == -1) {
  55. $page = 0;
  56. } // If $page is not defined, or '' or -1
  57. $offset = $limit * $page;
  58. $pageprev = $page - 1;
  59. $pagenext = $page + 1;
  60. if (!$sortorder) {
  61. $sortorder = "ASC";
  62. }
  63. if (!$sortfield) {
  64. $sortfield = "name";
  65. }
  66. $object = new Salary($db);
  67. $extrafields = new ExtraFields($db);
  68. $childids = $user->getAllChildIds(1);
  69. // fetch optionals attributes and labels
  70. $extrafields->fetch_name_optionals_label($object->table_element);
  71. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  72. $hookmanager->initHooks(array('salarydoc', 'globalcard'));
  73. if ($id > 0 || !empty($ref)) {
  74. $object->fetch($id, $ref);
  75. // Check current user can read this salary
  76. $canread = 0;
  77. if (!empty($user->rights->salaries->readall)) {
  78. $canread = 1;
  79. }
  80. if (!empty($user->rights->salaries->read) && $object->fk_user > 0 && in_array($object->fk_user, $childids)) {
  81. $canread = 1;
  82. }
  83. if (!$canread) {
  84. accessforbidden();
  85. }
  86. }
  87. $upload_dir = $conf->salaries->dir_output.'/'.dol_sanitizeFileName($object->id);
  88. $modulepart = 'salaries';
  89. // Security check
  90. $socid = GETPOSTINT('socid');
  91. if ($user->socid) {
  92. $socid = $user->socid;
  93. }
  94. restrictedArea($user, 'salaries', $object->id, 'salary', '');
  95. $permissiontoread = $user->rights->salaries->read;
  96. $permissiontoadd = $user->rights->salaries->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles
  97. $permissiontodelete = $user->rights->salaries->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  98. /*
  99. * Actions
  100. */
  101. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  102. // Link to a project
  103. if ($action == 'classin' && $user->rights->banque->modifier) {
  104. $object->fetch($id);
  105. $object->setProject($projectid);
  106. }
  107. // set label
  108. if ($action == 'setlabel' && $user->rights->salaries->write) {
  109. $object->fetch($id);
  110. $object->label = $label;
  111. $object->update($user);
  112. }
  113. /*
  114. * View
  115. */
  116. $form = new Form($db);
  117. if (isModEnabled('project')) $formproject = new FormProjets($db);
  118. $title = $langs->trans('Salary')." - ".$langs->trans('Documents');
  119. $help_url = "";
  120. llxHeader("", $title, $help_url);
  121. if ($object->id) {
  122. $object->fetch_thirdparty();
  123. $head = salaries_prepare_head($object);
  124. print dol_get_fiche_head($head, 'documents', $langs->trans("SalaryPayment"), -1, 'salary');
  125. // Build file list
  126. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  127. $totalsize = 0;
  128. foreach ($filearray as $key => $file) {
  129. $totalsize += $file['size'];
  130. }
  131. $linkback = '<a href="'.DOL_URL_ROOT.'/salaries/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  132. $morehtmlref = '<div class="refidno">';
  133. $userstatic = new User($db);
  134. $userstatic->fetch($object->fk_user);
  135. // Label
  136. if ($action != 'editlabel') {
  137. $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->salaries->write, 'string', '', 0, 1);
  138. $morehtmlref .= $object->label;
  139. } else {
  140. $morehtmlref .= $langs->trans('Label').' :&nbsp;';
  141. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  142. $morehtmlref .= '<input type="hidden" name="action" value="setlabel">';
  143. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  144. $morehtmlref .= '<input type="text" name="label" value="'.$object->label.'"/>';
  145. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  146. $morehtmlref .= '</form>';
  147. }
  148. $morehtmlref .= '<br>'.$langs->trans('Employee').' : '.$userstatic->getNomUrl(-1);
  149. $usercancreate = $permissiontoadd;
  150. // Project
  151. if (isModEnabled('project')) {
  152. $langs->load("projects");
  153. $morehtmlref .= '<br>';
  154. if ($usercancreate) {
  155. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  156. if ($action != 'classify') {
  157. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  158. }
  159. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  160. } else {
  161. if (!empty($object->fk_project)) {
  162. $proj = new Project($db);
  163. $proj->fetch($object->fk_project);
  164. $morehtmlref .= $proj->getNomUrl(1);
  165. if ($proj->title) {
  166. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  167. }
  168. }
  169. }
  170. }
  171. $morehtmlref .= '</div>';
  172. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
  173. print '<div class="fichecenter">';
  174. print '<div class="underbanner clearboth"></div>';
  175. print '<table class="border tableforfield centpercent">';
  176. print "<tr>";
  177. print '<td class="titlefield">' . $langs->trans("DateStartPeriod") . '</td><td>';
  178. print dol_print_date($object->datesp, 'day');
  179. print '</td></tr>';
  180. print "<tr>";
  181. print '<td>' . $langs->trans("DateEndPeriod") . '</td><td>';
  182. print dol_print_date($object->dateep, 'day');
  183. print '</td></tr>';
  184. print '<tr><td>' . $langs->trans("Amount") . '</td><td><span class="amount">' . price($object->amount, 0, $langs, 1, -1, -1, $conf->currency) . '</span></td></tr>';
  185. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td>'.count($filearray).'</td></tr>';
  186. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td>'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  187. print '</table>';
  188. print '</div>';
  189. print dol_get_fiche_end();
  190. $modulepart = 'salaries';
  191. $permissiontoadd = $user->rights->salaries->write;
  192. $param = '&id='.$object->id;
  193. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  194. } else {
  195. print $langs->trans("ErrorUnknown");
  196. }
  197. // End of page
  198. llxFooter();
  199. $db->close();