salaries.lib.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * Copyright (C) 2015 Charlie BENKE <charlie@patas-monkey.com>
  4. * Copyright (C) 2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
  5. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  6. * Copyright (C) 2023 Frédéric France <frederic.france@netlogic.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. * or see https://www.gnu.org/
  21. */
  22. /**
  23. * Returns an array with the tabs for the "salaries" section
  24. * It loads tabs from modules looking for the entity salaries
  25. *
  26. * @param Paiement $object Current salaries object
  27. * @return array Tabs for the salaries section
  28. */
  29. function salaries_prepare_head($object)
  30. {
  31. global $db, $langs, $conf;
  32. $h = 0;
  33. $head = array();
  34. $head[$h][0] = DOL_URL_ROOT.'/salaries/card.php?id='.$object->id;
  35. $head[$h][1] = $langs->trans("Salary");
  36. $head[$h][2] = 'card';
  37. $h++;
  38. if (isModEnabled('paymentbybanktransfer')) {
  39. $nbStandingOrders = 0;
  40. $sql = "SELECT COUNT(pfd.rowid) as nb";
  41. $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
  42. $sql .= " WHERE pfd.fk_salary = ".((int) $object->id);
  43. $sql .= " AND type = 'ban'";
  44. $resql = $db->query($sql);
  45. if ($resql) {
  46. $obj = $db->fetch_object($resql);
  47. if ($obj) {
  48. $nbStandingOrders = $obj->nb;
  49. }
  50. } else {
  51. dol_print_error($db);
  52. }
  53. $langs->load("banks");
  54. $head[$h][0] = DOL_URL_ROOT.'/salaries/virement_request.php?id='.$object->id.'&type=bank-transfer';
  55. $head[$h][1] = $langs->trans('BankTransfer');
  56. if ($nbStandingOrders > 0) {
  57. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbStandingOrders.'</span>';
  58. }
  59. $head[$h][2] = 'request_virement';
  60. $h++;
  61. }
  62. // Show more tabs from modules
  63. // Entries must be declared in modules descriptor with line
  64. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  65. // $this->tabs = array('entity:-tabname); to remove a tab
  66. complete_head_from_modules($conf, $langs, $object, $head, $h, 'salaries', 'add', 'core');
  67. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  68. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  69. $upload_dir = $conf->salaries->dir_output."/".dol_sanitizeFileName($object->ref);
  70. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  71. $nbLinks = Link::count($db, $object->element, $object->id);
  72. $head[$h][0] = DOL_URL_ROOT.'/salaries/document.php?id='.$object->id;
  73. $head[$h][1] = $langs->trans('Documents');
  74. if (($nbFiles + $nbLinks) > 0) {
  75. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  76. }
  77. $head[$h][2] = 'documents';
  78. $h++;
  79. $head[$h][0] = DOL_URL_ROOT.'/salaries/info.php?id='.$object->id;
  80. $head[$h][1] = $langs->trans("Info");
  81. $head[$h][2] = 'info';
  82. $h++;
  83. complete_head_from_modules($conf, $langs, $object, $head, $h, 'salaries', 'add', 'external');
  84. complete_head_from_modules($conf, $langs, $object, $head, $h, 'salaries', 'remove');
  85. return $head;
  86. }
  87. /**
  88. * Return array head with list of tabs to view object informations
  89. *
  90. * @return array head
  91. */
  92. function salaries_admin_prepare_head()
  93. {
  94. global $conf, $db, $langs, $user;
  95. $extrafields = new ExtraFields($db);
  96. $extrafields->fetch_name_optionals_label('salary');
  97. $h = 0;
  98. $head = array();
  99. $head[$h][0] = DOL_URL_ROOT.'/salaries/admin/salaries.php';
  100. $head[$h][1] = $langs->trans("Miscellaneous");
  101. $head[$h][2] = 'general';
  102. $h++;
  103. // Show more tabs from modules
  104. // Entries must be declared in modules descriptor with line
  105. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  106. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  107. complete_head_from_modules($conf, $langs, null, $head, $h, 'salaries_admin');
  108. $head[$h][0] = DOL_URL_ROOT.'/salaries/admin/salaries_extrafields.php';
  109. $head[$h][1] = $langs->trans("ExtraFieldsSalaries");
  110. $nbExtrafields = $extrafields->attributes['salary']['count'];
  111. if ($nbExtrafields > 0) {
  112. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  113. }
  114. $head[$h][2] = 'attributes';
  115. $h++;
  116. complete_head_from_modules($conf, $langs, null, $head, $h, 'salaries_admin', 'remove');
  117. return $head;
  118. }