expensereport.lib.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /* Copyright (C) 2011 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2022 Frédéric France <frederic.france@netlogic.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. * or see https://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/lib/expensereport.lib.php
  21. * \brief Functions for module expensereport
  22. */
  23. /**
  24. * Prepare array with list of tabs
  25. *
  26. * @param Object $object Object related to tabs
  27. * @return array Array of tabs to show
  28. */
  29. function expensereport_prepare_head($object)
  30. {
  31. global $db, $langs, $conf;
  32. $h = 0;
  33. $head = array();
  34. $head[$h][0] = DOL_URL_ROOT.'/expensereport/card.php?id='.$object->id;
  35. $head[$h][1] = $langs->trans("ExpenseReport");
  36. $head[$h][2] = 'card';
  37. $h++;
  38. // Show more tabs from modules
  39. // Entries must be declared in modules descriptor with line
  40. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  41. // $this->tabs = array('entity:-tabname); to remove a tab
  42. complete_head_from_modules($conf, $langs, $object, $head, $h, 'expensereport', 'add', 'core');
  43. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  44. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  45. $upload_dir = $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref);
  46. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  47. $nbLinks = Link::count($db, $object->element, $object->id);
  48. $head[$h][0] = DOL_URL_ROOT.'/expensereport/document.php?id='.$object->id;
  49. $head[$h][1] = $langs->trans('Documents');
  50. if (($nbFiles + $nbLinks) > 0) {
  51. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  52. }
  53. $head[$h][2] = 'documents';
  54. $h++;
  55. if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
  56. $nbNote = 0;
  57. if (!empty($object->note_private)) {
  58. $nbNote++;
  59. }
  60. if (!empty($object->note_public)) {
  61. $nbNote++;
  62. }
  63. $head[$h][0] = DOL_URL_ROOT.'/expensereport/note.php?id='.$object->id;
  64. $head[$h][1] = $langs->trans('Notes');
  65. if ($nbNote > 0) {
  66. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  67. }
  68. $head[$h][2] = 'note';
  69. $h++;
  70. }
  71. $head[$h][0] = DOL_URL_ROOT.'/expensereport/info.php?id='.$object->id;
  72. $head[$h][1] = $langs->trans("Info");
  73. $head[$h][2] = 'info';
  74. $h++;
  75. complete_head_from_modules($conf, $langs, $object, $head, $h, 'donation', 'add', 'external');
  76. complete_head_from_modules($conf, $langs, $object, $head, $h, 'expensereport', 'remove');
  77. return $head;
  78. }
  79. /**
  80. * Returns an array with the tabs for the "Expense report payment" section
  81. * It loads tabs from modules looking for the entity payment
  82. *
  83. * @param Paiement $object Current payment object
  84. * @return array Tabs for the payment section
  85. */
  86. function payment_expensereport_prepare_head(PaymentExpenseReport $object)
  87. {
  88. global $langs, $conf;
  89. $h = 0;
  90. $head = array();
  91. $head[$h][0] = DOL_URL_ROOT.'/expensereport/payment/card.php?id='.$object->id;
  92. $head[$h][1] = $langs->trans("ExpenseReportPayment");
  93. $head[$h][2] = 'payment';
  94. $h++;
  95. // Show more tabs from modules
  96. // Entries must be declared in modules descriptor with line
  97. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  98. // $this->tabs = array('entity:-tabname); to remove a tab
  99. complete_head_from_modules($conf, $langs, $object, $head, $h, 'payment_expensereport');
  100. $head[$h][0] = DOL_URL_ROOT.'/expensereport/payment/info.php?id='.$object->id;
  101. $head[$h][1] = $langs->trans("Info");
  102. $head[$h][2] = 'info';
  103. $h++;
  104. complete_head_from_modules($conf, $langs, $object, $head, $h, 'payment_expensereport', 'remove');
  105. return $head;
  106. }
  107. /**
  108. * Return array head with list of tabs to view object informations.
  109. *
  110. * @return array head array with tabs
  111. */
  112. function expensereport_admin_prepare_head()
  113. {
  114. global $langs, $conf, $user, $db;
  115. $h = 0;
  116. $head = array();
  117. $extrafields = new ExtraFields($db);
  118. $extrafields->fetch_name_optionals_label('expensereport');
  119. $h = 0;
  120. $head[$h][0] = DOL_URL_ROOT."/admin/expensereport.php";
  121. $head[$h][1] = $langs->trans("ExpenseReports");
  122. $head[$h][2] = 'expensereport';
  123. $h++;
  124. $head[$h][0] = DOL_URL_ROOT."/admin/expensereport_rules.php";
  125. $head[$h][1] = $langs->trans("ExpenseReportsRules");
  126. $head[$h][2] = 'expenserules';
  127. $h++;
  128. if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) {
  129. $head[$h][0] = DOL_URL_ROOT."/admin/expensereport_ik.php";
  130. $head[$h][1] = $langs->trans("ExpenseReportsIk");
  131. $head[$h][2] = 'expenseik';
  132. $h++;
  133. }
  134. // Show more tabs from modules
  135. // Entries must be declared in modules descriptor with line
  136. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  137. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  138. complete_head_from_modules($conf, $langs, null, $head, $h, 'expensereport_admin');
  139. $head[$h][0] = DOL_URL_ROOT.'/admin/expensereport_extrafields.php';
  140. $head[$h][1] = $langs->trans("ExtraFields");
  141. $nbExtrafields = $extrafields->attributes['expensereport']['count'];
  142. if ($nbExtrafields > 0) {
  143. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  144. }
  145. $head[$h][2] = 'attributes';
  146. $h++;
  147. /*
  148. $head[$h][0] = DOL_URL_ROOT.'/fichinter/admin/fichinterdet_extrafields.php';
  149. $head[$h][1] = $langs->trans("ExtraFieldsLines");
  150. $head[$h][2] = 'attributesdet';
  151. $h++;
  152. */
  153. complete_head_from_modules($conf, $langs, null, $head, $h, 'expensereport_admin', 'remove');
  154. return $head;
  155. }