Skip to content

Instantly share code, notes, and snippets.

@changwu-tw
Created June 17, 2015 02:49
Show Gist options
  • Save changwu-tw/b987286e03199af41553 to your computer and use it in GitHub Desktop.
Save changwu-tw/b987286e03199af41553 to your computer and use it in GitHub Desktop.
替代役年終計算
<!doctype html>
<html lang="zh-tw">
<head>
<meta charset="utf-8">
<title>替代役役男年終獎金計算</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function() {
$( "#datepicker1" ).datepicker( {dateFormat: "yy-mm-dd"} );
$( "#datepicker2" ).datepicker( {dateFormat: "yy-mm-dd"} );
});
</script>
</head>
<body>
<form action="view.php" method="post" name="form1">
<p>除夕日期: <input type="text" id="datepicker1" name="LunarNewYear"></p>
<p>入伍日期: <input type="text" id="datepicker2" name="ServeDate"></p>
<input type="submit" id="button" value="計算">
</form>
</body>
</html>
<?php
$LunarNewYear = $_POST['LunarNewYear'];
$ServeDate = $_POST['ServeDate'];
// 年終月數為入伍至春節前十日
function monthOfDuring($ServeDate, $LunarNewYear) {
$datetime1 = new DateTime($ServeDate);
$datetime2 = new DateTime($LunarNewYear);
$datetime2->modify('-10 days');
$interval = $datetime1->diff($datetime2);
return $interval->format('%m');
}
// 一等兵 6630 二等兵 6070
// 服役滿半年後的下個月份起月薪俸以一等兵計算
function baseSalary($ServeDate) {
$monthOfServeDate = date('n', strtotime($ServeDate));
return ($monthOfServeDate < 7) ? 6630 : 6070;
}
// 年終計算方式為: 月薪俸 × 1.5個月 × 在役月數 / 12
function calculateYearEndBonus($baseSalary, $monthOfDuring) {
$salary = $baseSalary * 1.5 * $monthOfDuring / 12;
return round($salary);
}
$baseSalary = baseSalary($ServeDate);
$monthOfDuring = monthOfDuring($ServeDate, $LunarNewYear);
$YearEndBonus = calculateYearEndBonus($baseSalary, $monthOfDuring);
// echo $baseSalary."\n";
// echo $monthOfDuring."\n";
echo $YearEndBonus."\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment