<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增收入')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-income-add">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">客户：</label>
                    <div class="col-sm-8">
                        <select class="form-control" name="customerId" th:with="commons=${@common.getCustomerList()}">
                            <option value="">请选择</option>
                            <option th:each="common : ${commons}" th:text="${common.customerName}" th:value="${common.customerId}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">用户：</label>
                    <div class="col-sm-8">
                        <select class="form-control" name="userId" th:with="users=${@user.getUserList()}">
                            <option value="">请选择</option>
                            <option th:each="user : ${users}" th:text="${user.userName}" th:value="${user.userId}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">收入日期：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input name="incomeDate" class="form-control" placeholder="yyyy-MM-dd" type="text">
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">收入类目：</label>
                    <div class="col-sm-8">
                        <select name="incomeType" class="form-control" th:with="type=${@dict.getType('income_type')}">
                            <option value="">请选择</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">收入总金额：</label>
                    <div class="col-sm-8">
                        <input name="grossAmount" id="grossAmount" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">税率：</label>
                    <div class="col-sm-8 form-inline">
                        <input name="rate" id="rate" class="form-control" type="text">%
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">净收入：</label>
                    <div class="col-sm-8">
                        <input name="netAmount" id="netAmount" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">税额：</label>
                    <div class="col-sm-8">
                        <input name="taxAmount" id="taxAmount" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">备注：</label>
                    <div class="col-sm-8">
                        <textarea name="remark" class="form-control"></textarea>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "business/income"
        $("#form-income-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-income-add').serialize());
            }
        }

        $("input[name='incomeDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("#grossAmount, #rate").blur(function(){
            let grossAmount = Number($("#grossAmount").val()) || 0;
            let rate = Number($("#rate").val()) || 0;

            let netAmount = grossAmount / (1 + rate / 100);
            let taxAmount = grossAmount - netAmount;

            $("#taxAmount").val(taxAmount.toFixed(2));
            $("#netAmount").val(netAmount.toFixed(2));

        });

    </script>
</body>
</html>