expensereport_ik.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 3 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. $error = 0;
  32. $action = GETPOST('action', 'aZ09');
  33. $id = GETPOST('id', 'int');
  34. $ikoffset = GETPOST('ikoffset', 'int');
  35. $coef = GETPOST('coef', 'int');
  36. $fk_c_exp_tax_cat = GETPOST('fk_c_exp_tax_cat');
  37. $fk_range = GETPOST('fk_range', 'int');
  38. $expIk = new ExpenseReportIk($db);
  39. if (!$user->admin) {
  40. accessforbidden();
  41. }
  42. /*
  43. * Actions
  44. */
  45. if ($action == 'updateik') {
  46. if ($id > 0) {
  47. $result = $expIk->fetch($id);
  48. if ($result < 0) {
  49. dol_print_error('', $expIk->error, $expIk->errors);
  50. }
  51. }
  52. $expIk->setValues($_POST);
  53. $result = $expIk->create($user);
  54. if ($result > 0) {
  55. setEventMessages('SetupSaved', null, 'mesgs');
  56. header('Location: '.$_SERVER['PHP_SELF']);
  57. exit;
  58. } else {
  59. setEventMessages($expIk->error, $expIk->errors, 'errors');
  60. }
  61. } elseif ($action == 'delete') { // TODO add confirm
  62. if ($id > 0) {
  63. $result = $expIk->fetch($id);
  64. if ($result < 0) {
  65. dol_print_error('', $expIk->error, $expIk->errors);
  66. }
  67. $expIk->delete($user);
  68. }
  69. header('Location: '.$_SERVER['PHP_SELF']);
  70. exit;
  71. }
  72. $rangesbycateg = $expIk->getAllRanges();
  73. /*
  74. * View
  75. */
  76. llxHeader('', $langs->trans("ExpenseReportsSetup"));
  77. $form = new Form($db);
  78. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  79. print load_fiche_titre($langs->trans("ExpenseReportsSetup"), $linkback, 'title_setup');
  80. $head = expensereport_admin_prepare_head();
  81. print dol_get_fiche_head($head, 'expenseik', $langs->trans("ExpenseReportsIk"), -1, 'trip');
  82. echo '<span class="opacitymedium">'.$langs->trans('ExpenseReportIkDesc').'</span>';
  83. print '<br><br>';
  84. echo '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
  85. echo '<input type="hidden" name="token" value="'.newToken().'" />';
  86. if ($action == 'edit') {
  87. echo '<input type="hidden" name="id" value="'.$id.'" />';
  88. echo '<input type="hidden" name="fk_c_exp_tax_cat" value="'.$fk_c_exp_tax_cat.'" />';
  89. echo '<input type="hidden" name="fk_range" value="'.$fk_range.'" />';
  90. echo '<input type="hidden" name="action" value="updateik" />';
  91. }
  92. echo '<table class="noborder centpercent">';
  93. foreach ($rangesbycateg as $fk_c_exp_tax_cat => $Tab) {
  94. $title = ($Tab['active'] == 1) ? $langs->trans($Tab['label']) : $form->textwithpicto($langs->trans($Tab['label']), $langs->trans('expenseReportCatDisabled'), 1, 'help', '', 0, 3);
  95. echo '<tr class="liste_titre">';
  96. echo '<td>'.$title.'</td>';
  97. echo '<td>'.$langs->trans('expenseReportOffset').'</td>';
  98. echo '<td>'.$langs->trans('expenseReportCoef').'</td>';
  99. echo '<td>'.$langs->trans('expenseReportTotalForFive').'</td>';
  100. echo '<td>&nbsp;</td>';
  101. echo '</tr>';
  102. if ($Tab['active'] == 0) {
  103. continue;
  104. }
  105. $tranche = 1;
  106. foreach ($Tab['ranges'] as $k => $range) {
  107. if (isset($Tab['ranges'][$k + 1])) {
  108. $label = $langs->trans('expenseReportRangeFromTo', $range->range_ik, ($Tab['ranges'][$k + 1]->range_ik - 1));
  109. } else {
  110. $label = $langs->trans('expenseReportRangeMoreThan', $range->range_ik);
  111. }
  112. if ($range->range_active == 0) {
  113. $label = $form->textwithpicto($label, $langs->trans('expenseReportRangeDisabled'), 1, 'help', '', 0, 3);
  114. }
  115. echo '<tr class="oddeven">';
  116. // Label
  117. echo '<td class="nowraponall"><b>['.$langs->trans('RangeNum', $tranche++).']</b> - '.$label.'</td>';
  118. // Offset
  119. echo '<td class="nowraponall">';
  120. if ($action == 'edit' && $range->ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat) {
  121. echo '<input type="text" class="maxwidth100" name="ikoffset" value="'.$range->ik->ikoffset.'" />';
  122. } else {
  123. echo $range->ik->ikoffset;
  124. }
  125. echo '</td>';
  126. // Coef
  127. echo '<td class="nowraponall">';
  128. if ($action == 'edit' && $range->ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat) {
  129. echo '<input type="text" class="maxwidth100" name="coef" value="'.$range->ik->coef.'" />';
  130. } else {
  131. echo ($range->ik->id > 0 ? $range->ik->coef : $langs->trans('expenseReportCoefUndefined'));
  132. }
  133. echo '</td>';
  134. // Total for one
  135. echo '<td class="nowraponall">'.$langs->trans('expenseReportPrintExample', price($range->ik->ikoffset + 5 * $range->ik->coef)).'</td>';
  136. // Action
  137. echo '<td class="right">';
  138. if ($range->range_active == 1) {
  139. if ($action == 'edit' && $range->ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat) {
  140. echo '<input id="" class="button button-save" name="save" value="'.$langs->trans("Save").'" type="submit" />';
  141. echo '<input class="button button-cancel" value="'.$langs->trans("Cancel").'" onclick="javascript:history.go(-1)" type="button" />';
  142. } else {
  143. 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>';
  144. if (!empty($range->ik->id)) {
  145. echo '<a class="paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&id='.$range->ik->id.'">'.img_delete().'</a>';
  146. }
  147. // TODO add delete link
  148. }
  149. }
  150. echo '</td>';
  151. echo '</tr>';
  152. }
  153. }
  154. echo '</table>';
  155. echo '</form>';
  156. print dol_get_fiche_end();
  157. // End of page
  158. llxFooter();
  159. $db->close();