码迷,mamicode.com
首页 > 其他好文 > 详细

个人所得税计算及多人避税问题

时间:2018-05-01 15:26:17      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:select   ide   html   one   mes   height   工资   NPU   The   

根据工资计算应缴纳税额是一个分段函数求和问题。今日遇到的问题是:夫妻二人如何划分工资才能使得二人缴纳税额之和最少?
如果改成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>

个人所得税计算及多人避税问题

标签:select   ide   html   one   mes   height   工资   NPU   The   

原文地址:https://www.cnblogs.com/weiyinfu/p/8976056.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!