Browse Source

add feature to select own country (currently SE and DE) with different VKP amounts and rates

svn path=/trunk/; revision=33506
tags/stw2018
Max Mehl 3 years ago
parent
commit
8a1970dfdc
3 changed files with 64 additions and 25 deletions
  1. 38
    13
      cgi-bin/perdiem.php
  2. 1
    1
      internal/pd-result.en.xhtml
  3. 25
    11
      internal/pd.en.xhtml

+ 38
- 13
cgi-bin/perdiem.php View File

@@ -26,18 +26,43 @@
*
***********************************************************************/

$output = '';
$output = ''; // create empty variable

$epd = $_POST['country']; // Euro per day
// detect home country and set accodingly: currency, rates
$home = $_POST['home'];
if ($home === 'de') {
$cur = " €";
$c_b = 0.2;
$c_l = 0.4;
$c_d = 0.4;
} elseif ($home === 'se' ) {
$cur = " SEK";
$c_b = 0.15;
$c_l = 0.35;
$c_d = 0.35;
}


// amount per day
$epd = $_POST['dest'];
if ($epd === 'other') {
$epd = $_POST['country_other'];
$epd = $_POST['dest_other']; // if other destination, just take this value
} else {
$pattern = "/" . $home . "=([0-9.]+)?\/([0-9.]+)?/"; // define pattern something like "/de=12/24/"
$epd = preg_match($pattern, $epd, $match, PREG_OFFSET_CAPTURE); // actually search for it
$epd = $match[0][0]; // matches are on 2nd level inn an array
$epd = explode('=', $epd); // now separate at the "="
$epd = $epd[1]; // take the second half of it "12/24"
}
$epd = explode('/', $epd);
$epd_trav = $epd[0];
$epd_full = $epd[1];

$output .= "<p>Travel day(s): " . $epd_trav . " EUR per day <br />";
$output .= "Full day(s): " . $epd_full . " EUR per day</p>";
$epd = explode('/', $epd); // separate at "/"
$epd_trav = $epd[0]; // first half
$epd_full = $epd[1]; // second hald

$output .= "<p>Travel day(s): " . $epd_trav . $cur . " per day <br />";
$output .= "Full day(s): " . $epd_full . $cur . " per day <br />";
$output .= "Own country: " . $home . " <br />";
$output .= "Percentage rate for breakfast/lunch/dinner: " . $c_b . "/" . $c_l . "/" . $c_d . " <br /></p>";

$output .= '<table class="table table-striped">
<tr>
@@ -85,7 +110,7 @@ foreach ($days as &$day) { // calculate for each day
if ($break === "yes") {
$r_b = $eur * 0.2;
$r_day = $r_day + $r_b;
$output .= "<td>yes (" . $r_b . " €)</td>";
$output .= "<td>yes (" . $r_b . $cur . ")</td>";
} else {
$output .= "<td>no</td>";
}
@@ -94,7 +119,7 @@ foreach ($days as &$day) { // calculate for each day
if ($lunch === "yes") {
$r_l = $eur * 0.4;
$r_day = $r_day + $r_l;
$output .= "<td>yes (" . $r_l . " €)</td>";
$output .= "<td>yes (" . $r_l . $cur . ")</td>";
} else {
$output .= "<td>no</td>";
}
@@ -103,13 +128,13 @@ foreach ($days as &$day) { // calculate for each day
if ($dinner === "yes") {
$r_d = $eur * 0.4;
$r_day = $r_day + $r_d;
$output .= "<td>yes (" . $r_d . " €)</td>";
$output .= "<td>yes (" . $r_d . $cur . ")</td>";
} else {
$output .= "<td>no</td>";
}
// reimbursement for the single day
$output .= "<td>" . $r_day . " €</td>";
$output .= "<td>" . $r_day . $cur . "</td>";
$r_total = $r_total + $r_day;
// close row (day)
@@ -119,7 +144,7 @@ foreach ($days as &$day) { // calculate for each day
}

$output .= "<tr><td></td><td></td><td></td><td></td>";
$output .= "<td><strong>Total per diem: " . $r_total . " €</strong></td></tr></table>";
$output .= "<td><strong>Total per diem: " . $r_total . $cur . "</strong></td></tr></table>";

//------------------------------------


+ 1
- 1
internal/pd-result.en.xhtml View File

@@ -4,7 +4,7 @@
<head>
<title>FSFE - Internal Tools - per diem calculator</title>
<style type="text/css">
tr#descr {
tr.descr {
font-style: italic;
font-size: small;
}

+ 25
- 11
internal/pd.en.xhtml View File

@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Originally coded by Max Mehl <max.mehl [at] fsfe [dot] org> for FSFE e.V. -->
<html>
<head>
<title>FSFE - Internal Tools - per diem calculator</title>
<style type="text/css">
tr#descr {
tr.descr {
font-style: italic;
font-size: small;
}
@@ -21,14 +21,19 @@
<h1>Calculate per diem charges (VKP)</h1>
<form action="/cgi-bin/perdiem.php" method="post">
<h2>1. Select country</h2>
<!-- you can add new countries. For the individual amounts, set value=$travel/$full -->
<input type="radio" id="de" name="country" value="12/24" checked="checked" /><label for="de"> Germany</label>
<input type="radio" id="be" name="country" value="28/41" /><label for="be"> Belgium</label><br />
<input type="radio" id="other" name="country" value="other" />Other (per diems travel/full (e.g. "12/24" for Germany)): <input type="text" name="country_other" placeholder="12/24" />
<h2>1. Select your own country</h2>
<!-- if you add new countries, the respective settings have to be set in PHP file -->
<input type="radio" id="home-de" name="home" value="de" checked="checked" /><label for="home-de"> Germany</label>
<input type="radio" id="home-se" name="home" value="se" /><label for="home-se"> Sweden</label><br />
<h2>2. Select the destination country</h2>
<!-- you can add new countries. For the individual amounts, set value="CC=$travel/$full,[...]" -->
<input type="radio" id="dest-de" name="dest" value="de=12/24,se=292.5/585" checked="checked" /><label for="dest-de"> Germany</label>
<input type="radio" id="dest-be" name="dest" value="de=28/41,se=315.5/631" /><label for="dest-be"> Belgium</label><br />
<input type="radio" id="dest-other" name="dest" value="other" />Other <input type="text" name="dest_other" placeholder="12/24" /><label>(per diems travel/full (e.g. "12/24" for Germany -> Germany))</label>
<h2>2. Which meal did you pay yourself?</h2>
<h2>3. Which meal did you pay yourself?</h2>
<table class="table table-striped">
<tr>
<th>Use</th>
@@ -37,7 +42,7 @@
<th>Lunch</th>
<th>Dinner</th>
</tr>
<tr id="descr">
<tr class="descr">
<td>Calculate this day</td>
<td>Name the day (e.g. by date) <br />Leave blank to autoname them</td>
<td>Did you pay this meal yourself?</td>
@@ -48,6 +53,9 @@
<tr>
<td colspan="5"><strong>Outward travel day (or if you travelled only one day)</strong></td>
</tr>
<tr class="descr">
<td colspan="5">Please be aware of when a day counts as travel or full day!</td>
</tr>
<tr>
<td>
@@ -70,6 +78,9 @@
<tr>
<td colspan="5"><strong>Full days (only check those you travelled)</strong></td>
</tr>
<tr class="descr">
<td colspan="5">Please be aware of when a day counts as travel/half or full day!</td>
</tr>

<tr>
<td>
@@ -194,6 +205,9 @@
<tr>
<td colspan="5"><strong>Return travel day</strong></td>
</tr>
<tr class="descr">
<td colspan="5">Please be aware of when a day counts as travel or full day!</td>
</tr>

<tr>
<td>
@@ -214,7 +228,7 @@
</tr>
</table>

<button type="submit" name="action" value="calc">Calculate per diems</button>
<button type="submit" name="action" value="calc">Calculate per diem</button>

</form>

Loading…
Cancel
Save