@model Com._9pm2.ClientWeb.Models.EmployeeSalaryList
@{
    ViewBag.Title = "工资管理";
}
<script src="../../Scripts/payroll.js?vn=20180813"></script>
<script>

</script>
<style>
    .ui-datepicker-calendar {
        display: none;
    }
    .ui-datepicker-prev, .ui-datepicker-next {
        height: 38px !important;        
    }
    .ui-datepicker .ui-datepicker-prev .ui-icon, .ui-datepicker .ui-datepicker-next .ui-icon {
        width: 16px;
        height: 16px;
    }
</style>

<form method="post" action="/HR/Payroll">
    <div class="divSearch">
        <div>            
           @Html.TextBox("sMonthSn", null, new { maxlength = "50", @class = "text-date-month", placeholder = "交易日期" })
            <button class="btn btn-default" id="btnSearch">搜索</button>
            <button id="btnCalculate" type="button" class="btn btn-primary">计算工资</button>
            <button id="btnDownload" type="button" class="btn btn-primary">下载（Excel）</button>          
        </div>
    </div>
</form>

<div class="error-msg"></div>
@if (!string.IsNullOrEmpty(ViewBag.Message))
{
    <div class="info-msg" style="display:block;margin-bottom:10px;">@ViewBag.Message</div>
}

<div class="list" style="overflow:auto">
    <table id="tSalary" style="min-width:1200px" >
        <thead>
            <tr>
                <th>员工姓名</th>
                <th>实发工资</th>
                <th>基本工资</th>
                <th>津贴</th>
                <th>扣款</th>                
                <th>代扣个税</th>
                <th>养老保险</th>
                <th>医疗保险</th>
                <th>生育保险</th>
                <th>工伤保险</th>
                <th>失业保险</th>
                <th>公积金</th>
                <th>绩效</th>
                <th>调整</th>                
                <th style="width:110px;">操作</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model.Salaries)
            {
                <tr id="@item.Id">
                    <td>@item.EmployeeName</td>
                    <td>@item.NetPay</td>
                    <td>@item.BaseSalary</td>
                    <td>
                        @foreach (var s in item.Allowance)
                        {
                            <div>@(s.AllowanceName + ":" + s.AllowanceAmount)</div>
                        }
                    </td>
                    <td>
                        @foreach (var s in item.Deducts)
                        {
                            <div>@(s.DeductName + ":" + s.DeductAmount)</div>

                        }
                    </td>
                    <td>
                    @(item.IncomeTax==0?"":item.IncomeTax.ToString())</td>
                    <td>
                        @{
                            var s1 = item.Insurances.FirstOrDefault(m => m.InsuranceType == (int)Com._9pm2.ClientWeb.Common.SalaryInsuranceType.养老保险);
                            if (s1 != null)
                            {
                                if (s1.InsuranceAmountP > 0)
                                {
                                    <div>@("个人：" + s1.InsuranceAmountP)</div>
                                }
                                if (s1.InsuranceAmountC > 0)
                                {
                                    <div>@("公司：" + s1.InsuranceAmountC)</div>

                                }
                            }
                        }
                    </td>

                    <td>
                        @{
                            s1 = item.Insurances.FirstOrDefault(m => m.InsuranceType == (int)Com._9pm2.ClientWeb.Common.SalaryInsuranceType.医疗保险);
                            if (s1 != null)
                            {
                                if (s1.InsuranceAmountP > 0)
                                {
                                    <div>@("个人：" + s1.InsuranceAmountP)</div>

                                }
                                if (s1.InsuranceAmountC > 0)
                                {
                                    <div>@("公司：" + s1.InsuranceAmountC)</div>

                                }
                            }
                        }
                    </td>

                    <td>
                        @{
                            s1 = item.Insurances.FirstOrDefault(m => m.InsuranceType == (int)Com._9pm2.ClientWeb.Common.SalaryInsuranceType.生育保险);
                            if (s1 != null)
                            {
                                if (s1.InsuranceAmountP > 0)
                                {
                                    <div>@("个人：" + s1.InsuranceAmountP)</div>

                                }
                                if (s1.InsuranceAmountC > 0)
                                {
                                    <div>@("公司：" + s1.InsuranceAmountC)</div>

                                }
                            }
                        }
                    </td>

                    <td>
                        @{
                            s1 = item.Insurances.FirstOrDefault(m => m.InsuranceType == (int)Com._9pm2.ClientWeb.Common.SalaryInsuranceType.工伤保险);
                            if (s1 != null)
                            {
                                if (s1.InsuranceAmountP > 0)
                                {
                                    <div>@("个人：" + s1.InsuranceAmountP)</div>

                                }
                                if (s1.InsuranceAmountC > 0)
                                {
                                    <div>@("公司：" + s1.InsuranceAmountC)</div>

                                }
                            }
                        }
                    </td>

                    <td>
                        @{
                            s1 = item.Insurances.FirstOrDefault(m => m.InsuranceType == (int)Com._9pm2.ClientWeb.Common.SalaryInsuranceType.失业保险);
                            if (s1 != null)
                            {
                                if (s1.InsuranceAmountP > 0)
                                {
                                    <div>@("个人：" + s1.InsuranceAmountP)</div>

                                }
                                if (s1.InsuranceAmountC > 0)
                                {
                                    <div>@("公司：" + s1.InsuranceAmountC)</div>

                                }
                            }
                        }
                    </td>

                    <td>
                        @{
                            s1 = item.Insurances.FirstOrDefault(m => m.InsuranceType == (int)Com._9pm2.ClientWeb.Common.SalaryInsuranceType.公积金);
                            if (s1 != null)
                            {
                                if (s1.InsuranceAmountP > 0)
                                {
                                    <div>@("个人：" + s1.InsuranceAmountP)</div>

                                }
                                if (s1.InsuranceAmountC > 0)
                                {
                                    <div>@("公司：" + s1.InsuranceAmountC)</div>

                                }
                            }
                        }
                    </td>

                    
                    <td>                        
                            @(item.PerformanceAmount==0?"":item.PerformanceAmount.ToString())                     
                        
                    </td>
                    <td>
                        @if (item.AdustAmount != 0)
                        {
                            @(item.AdjustName + "：" + item.AdustAmount)
                        }
                       
                    </td>
                    <td style="text-align:center;">
                        <a href="javascript:void(0)" onclick="ChangePerformance(@item.Id,'@item.EmployeeName',@item.PerformanceAmount)">绩效</a>
                        <a href="javascript:void(0)" onclick="ChangeAdjust(@item.Id,'@item.EmployeeName','@item.AdjustName',@item.AdustAmount)">调整</a> 
                        <a href="javascript:void(0)" onclick="Delete(@item.Id,'@item.EmployeeName')">删除</a> 
                        

                    </td>
                </tr>
                            }
        </tbody>



    </table>
   
    <div style="min-width:1200px">
        @Html.Pager("Payroll", "HR", Model.RouterDirectory, Model.PagerConfig, "pagerDiv", "pagerDiv", 8, true, false, true, true, false)
    </div>
</div>
 

 
<div id="divCalculate" title="工资计算" style="display:none">
    <div id="divCalculateContent">
        
            <table id="tableEdit" class="font85 tableEdit">
                <tr>
                    <td class="label">月份</td>
                    <td>
                        <span id="calculateMonth"></span>
                    </td>
                </tr>
                <tr>
                    <td class="label">计算类型</td>
                    <td>
                        <div style="margin:5px 0">
                            <input type="radio" name="calculateType" value="1" /> <span style="color:red">重新计算所有员工工资</span>
                        </div>
                        <div style="margin:0 0 5px 0">
                            <input type="radio" name="calculateType" value="2" checked /><span style="color:forestgreen">跳过已计算过的员工</span>
                        </div>
                    </td>
                </tr>
                 

            </table>
        
    </div>
    <div style="text-align:right;">
        <div class="error-msg"></div>
        @Html.Hidden("DeductId")
        <button class="btn btn-default" type="button" onclick="$('#divCalculate').dialog('close');">关闭</button>
        <button class="btn btn-primary" type="button" onclick="CalculateSalary()">开始计算</button>

    </div>
</div>

 
<div id="divPerformance" title="绩效工资" style="display:none">
    <div id="divPerformanceContent">
        
            <table id="tableEdit" class="font85 tableEdit">
                <tr>
                    <td class="label">员工</td>
                    <td>
                        <span id="pEmployeeName"></span>
                    </td>
                </tr>
                <tr>
                    <td class="label">月份</td>
                    <td>
                        <span id="pCalculateMonth"></span>
                    </td>
                </tr>
                <tr>
                    <td class="label">绩效工资</td>
                    <td>
                         <input type="text" id="pAmount" class="amount" />                        
                    </td>
                </tr>
                 

            </table>
        
    </div>
    <div style="text-align:right;">
        <div class="error-msg"></div>
        @Html.Hidden("DeductId")
        <button class="btn btn-default" type="button" onclick="$('#divPerformance').dialog('close');">关闭</button>
        <button class="btn btn-primary" type="button" onclick="SetPerformance()">确定</button>

    </div>
</div>

<div id="divAdjust" title="工资调整" style="display:none">
    <div id="divAdjustContent">

        <table id="tableEdit" class="font85 tableEdit">
            <tr>
                <td class="label">员工</td>
                <td>
                    <span id="aEmployeeName"></span>
                </td>
            </tr>
            <tr>
                <td class="label">月份</td>
                <td>
                    <span id="aCalculateMonth"></span>
                </td>
            </tr>
          

            <tr>
                <td class="label">调整金额</td>
                <td>
                    <input type="text" id="aAmount" class="amount" />
                    
                </td>
            </tr>

            <tr>
                <td class="label">调整原因</td>
                <td>
                    <input type="text" id="aReason" />                    
                </td>
            </tr>


        </table>

    </div>
    <div style="text-align:right;">
        <div class="error-msg"></div>
        @Html.Hidden("DeductId")
        <button class="btn btn-default" type="button" onclick="$('#divAdjust').dialog('close');">关闭</button>
        <button class="btn btn-primary" type="button" onclick="SetAdjust()">确定</button>

    </div>
</div>

<input type="hidden" id="Id" />