1. 程式人生 > >個人所得稅計算及多人避稅問題

個人所得稅計算及多人避稅問題

住房公積金 turn ID for hid spl font use cti

根據工資計算應繳納稅額是一個分段函數求和問題。今日遇到的問題是:夫妻二人如何劃分工資才能使得二人繳納稅額之和最少?
如果改成N個人劃分固定金額使得繳納稅額最少呢?

<html>

<head>
    <style>
        table {
            border-collapse: collapse;
        }

        td {
            width: 50%;
            border-style: solid;
            border-width: 2px;
            border-collapse:
separate; } </style> </head> <body> <input id="csv" onchange="inflate()" onkeydown="hideInfo()" style="font-size:20px;width:100%;height:30px;"> <p id="info" style="color:red"></p> <table>
<thead> <tr> <td>屬性</td> <td>取值</td> </tr> </thead> <tbody> <tr> <td>月份</td> <td id="month"></td>
</tr> <tr> <td>基本公資</td> <td id="primary-pay"></td> </tr> <tr> <td>崗位津貼 </td> <td id="job-pay"></td> </tr> <tr> <td>績效津貼 </td> <td id="work-pay"></td> </tr> <tr> <td>季度獎金 </td> <td id="semester-pay"></td> </tr> <tr> <td>其他津貼 </td> <td id="other-pay"></td> </tr> <tr> <td>應發工資</td> <td id="should-give"></td> </tr> <tr> <td>保險 </td> <td id="safe-cost"></td> </tr> <tr> <td>住房公積金 </td> <td id="house-cost"></td> </tr> <tr> <td>其它 </td> <td id="other-cost"></td> </tr> <tr> <td>扣除五險一金後的工資</td> <td id="minus-pay"></td> </tr> <tr> <td>個稅 </td> <td id="tax"></td> </tr> <tr> <td>實發工資</td> <td id="final-pay"></td> </tr> <tr> <td>姓名</td> <td id="worker"></td> </tr> </tbody> </table> <div style="margin-top: 30px"> <h2>兩個人最少稅如何分錢</h2> <input id="avoidTax" onchange="canculateStrategy()"> <p id="strategy"></p> </div> </body> <script> function $(sel) { return document.querySelector(sel) } function parse(s) { var s = s.replace(/, /g, "").replace(/,/g, "") console.log(s) var a = s.split(/\s+/) console.log(a) for (var i = 0; i < a.length - 1; i++) { a[i] = parseFloat(a[i]) if (isNaN(a[i])) { a[i] = 0 } } return a } function hideInfo(s) { $("#info").innerHTML = "" } function calculateTax(money) { var rate = [0.03, 0.1, 0.2, 0.25, 0.3, 0.35, 0.45] var diff = [0, 1500, 4500, 9000, 35000, 55000, 80000, 2e9] for (var i = 0; i < diff.length; i++)diff[i] += 3500 var tax = 0 for (var i = 0; i < rate.length; i++) { if (money >= diff[i]) { var tempMoney = Math.min(diff[i + 1], money) - diff[i] tax += tempMoney * rate[i] } } return tax } function inflate() { var s = $("#csv").value var a = parse(s) if (a.length != 14) { $("#info").innerHTML = "輸入不規範" return } $("#month").innerHTML = a[0] $("#primary-pay").innerHTML = a[1] $("#job-pay").innerHTML = a[2] $("#work-pay").innerHTML = a[3] $("#semester-pay").innerHTML = a[4] $("#other-pay").innerHTML = a[5] var shouldGive = 0 for (var i = 1; i < 6; i++) { shouldGive += a[i] } $("#should-give").innerHTML = shouldGive + "" $("#safe-cost").innerHTML = a[7] $("#house-cost").innerHTML = a[8] $("#other-cost").innerHTML = a[9] var costSum = a[7] + a[8] + a[9] var beforePay = shouldGive - costSum $("#minus-pay").innerHTML = beforePay var tax = calculateTax(shouldGive - costSum) $("#tax").innerHTML = tax $("#final-pay").innerHTML = beforePay - tax $("#worker").innerHTML = a[13] } function canculateStrategy() { var money = parseFloat($("#avoidTax").value) var min = 0 var minTax = 2e9 for (var i = 0; i < money; i++) { var now = calculateTax(i) + calculateTax(money - i) if (now < minTax) { minTax = now min = i } } $("#strategy").innerHTML = min + "+" + (money - min) + ",最少稅額" + minTax } </script> </html>

個人所得稅計算及多人避稅問題