expensereport_ik.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /* Copyright (C) 2012 Mikael Carlavan <contact@mika-carl.fr>
  3. * Copyright (C) 2017 ATM Consulting <contact@atm-consulting.fr>
  4. * Copyright (C) 2017 Pierre-Henry Favre <phf@atm-consulting.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/admin/expensereport_ik.php
  21. * \ingroup expensereport
  22. * \brief Page to display expense tax ik
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/expensereport.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport_ik.class.php';
  29. // Load translation files required by the page
  30. $langs->loadLangs(array("admin", "trips", "errors", "other", "dict"));
  31. if (!$user->admin) {
  32. accessforbidden();
  33. }
  34. $error = 0;
  35. $action = GETPOST('action', 'aZ09');
  36. $id = GETPOST('id', 'int');
  37. $ikoffset = GETPOST('ikoffset', 'int');
  38. $coef = GETPOST('coef', 'int');
  39. $fk_c_exp_tax_cat = GETPOST('fk_c_exp_tax_cat');
  40. $fk_range = GETPOST('fk_range');
  41. if ($action == 'updateik') {
  42. $expIk = new ExpenseReportIk($db);
  43. if ($id > 0) {
  44. $result = $expIk->fetch($id);
  45. if ($result < 0) {
  46. dol_print_error('', $expIk->error, $expIk->errors);
  47. }
  48. }
  49. $expIk->setValues($_POST);
  50. $result = $expIk->create($user);
  51. if ($result > 0) {
  52. setEventMessages('SetupSaved', null, 'mesgs');
  53. header('Location: '.$_SERVER['PHP_SELF']);
  54. exit;
  55. } else {
  56. setEventMessages($expIk->error, $expIk->errors, 'errors');
  57. }
  58. } elseif ($action == 'delete') { // TODO add confirm
  59. $expIk = new ExpenseReportIk($db);
  60. if ($id > 0) {
  61. $result = $expIk->fetch($id);
  62. if ($result < 0) {
  63. dol_print_error('', $expIk->error, $expIk->errors);
  64. }
  65. $expIk->delete($user);
  66. }
  67. header('Location: '.$_SERVER['PHP_SELF']);
  68. exit;
  69. }
  70. $rangesbycateg = ExpenseReportIk::getAllRanges();
  71. /*
  72. * View
  73. */
  74. llxHeader('', $langs->trans("ExpenseReportsSetup"));
  75. $form = new Form($db);
  76. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  77. print load_fiche_titre($langs->trans("ExpenseReportsSetup"), $linkback, 'title_setup');
  78. $head = expensereport_admin_prepare_head();
  79. print dol_get_fiche_head($head, 'expenseik', $langs->trans("ExpenseReportsIk"), -1, 'trip');
  80. echo '<span class="opacitymedium">'.$langs->trans('ExpenseReportIkDesc').'</span>';
  81. print '<br><br>';
  82. echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';
  83. if ($action == 'edit') {
  84. echo '<input type="hidden" name="id" value="'.$id.'" />';
  85. echo '<input type="hidden" name="fk_c_exp_tax_cat" value="'.$fk_c_exp_tax_cat.'" />';
  86. echo '<input type="hidden" name="fk_range" value="'.$fk_range.'" />';
  87. echo '<input type="hidden" name="action" value="updateik" />';
  88. }
  89. echo '<input type="hidden" name="token" value="'.newToken().'" />';
  90. echo '<table class="noborder centpercent">';
  91. foreach ($rangesbycateg as $fk_c_exp_tax_cat => $Tab) {
  92. $title = ($Tab['active'] == 1) ? $langs->trans($Tab['label']) : $form->textwithpicto($langs->trans($Tab['label']), $langs->trans('expenseReportCatDisabled'), 1, 'help', '', 0, 3);
  93. echo '<tr class="liste_titre">';
  94. echo '<td>'.$title.'</td>';
  95. echo '<td>'.$langs->trans('expenseReportOffset').'</td>';
  96. echo '<td>'.$langs->trans('expenseReportCoef').'</td>';
  97. echo '<td>'.$langs->trans('expenseReportTotalForFive').'</td>';
  98. echo '<td>&nbsp;</td>';
  99. echo '</tr>';
  100. if ($Tab['active'] == 0) {
  101. continue;
  102. }
  103. $tranche = 1;
  104. foreach ($Tab['ranges'] as $k => $range) {
  105. if (isset($Tab['ranges'][$k + 1])) {
  106. $label = $langs->trans('expenseReportRangeFromTo', $range->range_ik, ($Tab['ranges'][$k + 1]->range_ik - 1));
  107. } else {
  108. $label = $langs->trans('expenseReportRangeMoreThan', $range->range_ik);
  109. }
  110. if ($range->range_active == 0) {
  111. $label = $form->textwithpicto($label, $langs->trans('expenseReportRangeDisabled'), 1, 'help', '', 0, 3);
  112. }
  113. echo '<tr class="oddeven">';
  114. // Label
  115. echo '<td class="nowraponall"><b>['.$langs->trans('RangeNum', $tranche++).']</b> - '.$label.'</td>';
  116. // Offset
  117. echo '<td class="nowraponall">';
  118. if ($action == 'edit' && $range->ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat) {
  119. echo '<input type="text" class="maxwidth100" name="ikoffset" value="'.$range->ik->ikoffset.'" />';
  120. } else {
  121. echo $range->ik->ikoffset;
  122. }
  123. echo '</td>';
  124. // Coef
  125. echo '<td class="nowraponall">';
  126. if ($action == 'edit' && $range->ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat) {
  127. echo '<input type="text" class="maxwidth100" name="coef" value="'.$range->ik->coef.'" />';
  128. } else {
  129. echo ($range->ik->id > 0 ? $range->ik->coef : $langs->trans('expenseReportCoefUndefined'));
  130. }
  131. echo '</td>';
  132. // Total for one
  133. echo '<td class="nowraponall">'.$langs->trans('expenseReportPrintExample', price($range->ik->ikoffset + 5 * $range->ik->coef)).'</td>';
  134. // Action
  135. echo '<td class="right">';
  136. if ($range->range_active == 1) {
  137. if ($action == 'edit' && $range->ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat) {
  138. echo '<input id="" class="button button-save" name="save" value="'.$langs->trans("Save").'" type="submit" />';
  139. echo '<input class="button button-cancel" value="'.$langs->trans("Cancel").'" onclick="javascript:history.go(-1)" type="button" />';
  140. } else {
  141. echo '<a class="editfielda marginrightonly paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?action=edit&token='.newToken().'&id='.$range->ik->id.'&fk_c_exp_tax_cat='.$range->fk_c_exp_tax_cat.'&fk_range='.$range->rowid.'">'.img_edit().'</a>';
  142. if (!empty($range->ik->id)) {
  143. echo '<a class="paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&id='.$range->ik->id.'">'.img_delete().'</a>';
  144. }
  145. // TODO add delete link
  146. }
  147. }
  148. echo '</td>';
  149. echo '</tr>';
  150. }
  151. }
  152. echo '</table>';
  153. echo '</form>';
  154. print dol_get_fiche_end();
  155. // End of page
  156. llxFooter();
  157. $db->close();