Source files of fsfe.org, pdfreaders.org, freeyourandroid.org, ilovefs.org, drm.info, and test.fsfe.org. Contribute: https://fsfe.org/contribute/web/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

perdiem.php 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <?php
  2. /***********************************************************************
  3. * Copyright (C) 2016 Max Mehl <max.mehl [at] fsfe [dot] org> for FSFE e.V.
  4. ************************************************************************
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or (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 Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public
  17. * License along with this program. If not, see
  18. * <http://www.gnu.org/licenses/>.
  19. *
  20. ************************************************************************
  21. *
  22. * This file receives input from /internal/pd.en.(x)html and calculates per
  23. * diem charges for reimbursement claims. The amounts can be defined in
  24. * the XHTML file. For the output of the data, it uses
  25. * /internal/pd-result.en.(x)html as a template.
  26. *
  27. ***********************************************************************/
  28. $output = ''; // create empty variable
  29. // detect home country and set accodingly: currency, rates
  30. $home = $_POST['home'];
  31. if ($home === 'de') {
  32. $cur = " €"; // currency
  33. $c_b = 0.2; // breakfast rate
  34. $c_l = 0.4; // lunch rate
  35. $c_d = 0.4; // dinner rate
  36. $c_flat = 0; // flat rate (money which employee gets even if all meals are paid)
  37. } elseif ($home === 'se' ) {
  38. $cur = " SEK";
  39. $c_b = 0.15;
  40. $c_l = 0.35;
  41. $c_d = 0.35;
  42. $c_flat = 0.15;
  43. } elseif ($home === 'other') {
  44. $home_other = explode("/", $_POST['home_other']);
  45. $cur = " " . $home_other[0];
  46. $c_b = $home_other[1];
  47. $c_l = $home_other[2];
  48. $c_d = $home_other[3];
  49. $c_flat = $home_other[4];
  50. }
  51. // amount per day
  52. $epd = $_POST['dest'];
  53. if ($epd === 'other') {
  54. $epd = $_POST['dest_other']; // if other destination, just take this value
  55. } else {
  56. $pattern = "/" . $home . "=([0-9.]+)?\/([0-9.]+)?/"; // define pattern something like "/de=12/24/"
  57. $epd = preg_match($pattern, $epd, $match, PREG_OFFSET_CAPTURE); // actually search for it
  58. $epd = $match[0][0]; // matches are on 2nd level inn an array
  59. $epd = explode('=', $epd); // now separate at the "="
  60. $epd = $epd[1]; // take the second half of it "12/24"
  61. }
  62. $epd = explode('/', $epd); // separate at "/"
  63. $epd_trav = $epd[0]; // first half
  64. $epd_full = $epd[1]; // second hald
  65. $output .= "<h2>Detailled overview of per diems</h2>";
  66. $output .= "<p>Travel day(s): " . $epd_trav . $cur . " per day <br />";
  67. $output .= "Full day(s): " . $epd_full . $cur . " per day <br />";
  68. $output .= "Own country: " . $home . " <br />";
  69. $output .= "Percentage rate for breakfast/lunch/dinner: " . $c_b . "/" . $c_l . "/" . $c_d . " <br />";
  70. $output .= "Flat rate (percentage which employee gets even if all meals are paid): " . $c_flat . " <br /></p>";
  71. $output .= '<table class="table table-striped">
  72. <tr>
  73. <th>Date</th>
  74. <th>Breakfast</th>
  75. <th>Lunch</th>
  76. <th>Dinner</th>
  77. <th>Flat reimbursement</th>
  78. <th>Your total reimbursement</th>
  79. </tr>';
  80. $days = array('out', 1, 2, 3, 4, 5, 6, 7, 'return'); // define day range
  81. // set variables
  82. $r_total = 0; // total reimbursement
  83. foreach ($days as &$d) { // calculate for each day
  84. $use[$d] = $_POST['use'][$d];
  85. $date[$d] = $_POST['date'][$d];
  86. $break[$d] = $_POST['break'][$d];
  87. $lunch[$d] = $_POST['lunch'][$d];
  88. $dinner[$d] = $_POST['dinner'][$d];
  89. // set variables
  90. $r_day[$d] = 0; // reimbursement for this day
  91. if ($use[$d] === 'yes') { // only calculate if checkbox has been activated (day in use)
  92. if ($d === 'out' || $d === 'return') { // set amount of € for travel or full day
  93. $eur = $epd_trav; // total reimburseable amount for this day
  94. $desc = " (travel)";
  95. } else {
  96. $eur = $epd_full; // total reimburseable amount for this day
  97. $desc = " (full)";
  98. }
  99. // open row
  100. $output .= "<tr>";
  101. // date
  102. if ($date[$d] === '' ) {
  103. $date[$d] = "Day " . $d;
  104. }
  105. $output .= "<td>" . $date[$d] . $desc . "</td>";
  106. // breakfast ($r_b)
  107. if ($break[$d] === "yes") {
  108. $r_b = $eur * $c_b;
  109. $r_day[$d] = $r_day[$d] + $r_b;
  110. $output .= "<td>yes (" . $r_b . $cur . ")</td>";
  111. } else {
  112. $output .= "<td>no</td>";
  113. }
  114. // lunch ($r_l)
  115. if ($lunch[$d] === "yes") {
  116. $r_l = $eur * $c_l;
  117. $r_day[$d] = $r_day[$d] + $r_l;
  118. $output .= "<td>yes (" . $r_l . $cur . ")</td>";
  119. } else {
  120. $output .= "<td>no</td>";
  121. }
  122. // breakfast ($r_d)
  123. if ($dinner[$d] === "yes") {
  124. $r_d = $eur * $c_d;
  125. $r_day[$d] = $r_day[$d] + $r_d;
  126. $output .= "<td>yes (" . $r_d . $cur . ")</td>";
  127. } else {
  128. $output .= "<td>no</td>";
  129. }
  130. // flat rate
  131. $r_flat = $eur * $c_flat;
  132. $r_day[$d] = $r_day[$d] + $r_flat;
  133. $output .= "<td>" . $r_flat . $cur . "</td>";
  134. // reimbursement for the single day
  135. $output .= "<td>" . $r_day[$d] . $cur . "</td>";
  136. $r_total = $r_total + $r_day[$d];
  137. // close row (day)
  138. $output .= "</tr>";
  139. } // if day is used
  140. } // foreach
  141. $output .= "<tr><td></td><td></td><td></td><td></td><td></td>";
  142. $output .= "<td><strong>Total per diem: " . $r_total . $cur . "</strong></td></tr></table>";
  143. /* ------------------------------------
  144. * --- PRINT FOR COPY IN SPREADSHEET ---
  145. * -----------------------------------*/
  146. $output .= "<hr />";
  147. $output .= "<h2>Spreadsheet copy&amp;paste</h2>";
  148. $output .= "<p>The following section can be copied to your Reimbursement Claim spreadsheet. Please mark and copy the content of the table (except the headings), and paste it in your spreadsheet application.<br /><em>Hint: In LibreOffice, press Ctrl+Shift+V in order to paste it as unformatted text instead of HTML code. This avoids conflicting formatting.</em></p>";
  149. $output .= '<table class="table">';
  150. $output .= '<tr><th>Employee name</th><th>Date</th><th>Amount (EUR)</th><th>Recipient Name</th><th>ER number</th><th>Catchphrase</th><th>Receipt / per diem</th><th>Remarks</th></tr>';
  151. foreach ($days as &$d) { // calculate for each day
  152. if ($use[$d] === 'yes') {
  153. $rc_name = $_POST['rc_name'];
  154. $rc_er = $_POST['rc_er'];
  155. $rc_catch = $_POST['rc_catch'];
  156. if ($rc_name === '') { $rc_name = "YOUR-NAME"; }
  157. if ($rc_er === '') { $rc_er = "ER-NUMBER"; }
  158. if ($rc_catch === '') { $rc_catch = "CATCHPHRASE"; }
  159. $output .= "<tr>";
  160. // 1. Name
  161. $output .= "<td>" . $rc_name . "</td>";
  162. // 2. Date
  163. $output .= "<td>" . $date[$d] . "</td>";
  164. // 3. Amount
  165. $r_day[$d] = preg_replace("/\./", ",", $r_day[$d]); // replace . by , in amount to make it compatible with the used spreadsheet template
  166. $output .= "<td>" . $r_day[$d] . "</td>";
  167. // 4. Recipient Name (empty)
  168. $output .= "<td></td>";
  169. // 5. ER number
  170. $output .= "<td>" . $rc_er . "</td>";
  171. // 6. Catchphrase
  172. $output .= "<td>" . $rc_catch . "</td>";
  173. // 7. Receipt/per diem
  174. $output .= "<td>per diem</td>";
  175. // 8. Remarks
  176. if ($break[$d] === "yes") {
  177. $remark[$d] = "breakfast+";
  178. }
  179. if ($lunch[$d] === "yes") {
  180. $remark[$d] .= "lunch+";
  181. }
  182. if ($dinner[$d] === "yes") {
  183. $remark[$d] .= "dinner";
  184. }
  185. if ($break[$d] != "yes" && $lunch[$d] != "yes" && $dinner[$d] != "yes") {
  186. $remark[$d] = "nothing";
  187. }
  188. if ($break[$d] === "yes" && $lunch[$d] === "yes" && $dinner[$d] === "yes") {
  189. $remark[$d] = "everything";
  190. }
  191. $remark[$d] = preg_replace("/\+$/", "", $remark[$d]);
  192. $remark[$d] .= " self-paid";
  193. $output .= "<td>" . $remark[$d] . "</td>";
  194. $output .= "</tr>";
  195. }
  196. }
  197. $output .= '</table>';
  198. // --- PRINT OUTPUT IN TEMPLATE FILE ---
  199. function replace_page($temp, $content){
  200. $vars = array(':RESULT:'=>$content);
  201. return str_replace(array_keys($vars), $vars, $temp);
  202. }
  203. $template = file_get_contents('http://fsfe.org/internal/pd-result.en.html', true);
  204. echo replace_page($template, $output);
  205. ?>