expensereport_ik.php 6.2 KB

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