@model Com._9pm2.ClientWeb.Models.StockInList
@{
    ViewBag.Title = "进货单管理";
}
<script src="~/Scripts/stockcommon.js?vn=20180813"></script>
<script src="../../Scripts/stockin.js?vn=20180813"></script>
@{
    Com._9pm2.ClientWeb.Models.LoginUser user = Session["LoginUser"] as Com._9pm2.ClientWeb.Models.LoginUser;
}
<form method="post" action="/Warehouse/StockIn">
    <div class="divSearch">
        <div>           
            <div class="div-search-select2">
                @Html.DropDownList("sSupplierId", new SelectList(Model.DdlSupplier, "ItemValue", "ItemText"))
            </div>
            @Html.DropDownList("sType", new SelectList(Model.DdlType, "ItemValue", "ItemText"))
            <div class="div-search-select2">
                @Html.DropDownList("sMaterial", new SelectList(Model.DdlMaterial, "ItemValue", "ItemText"))
                @Html.Hidden("hiddenMaterial")
            </div>   
            @Html.DropDownList("sStatus", new SelectList(Model.DdlStatus, "ItemValue", "ItemText"))
            @Html.DropDownList("sPaymentStatus", new SelectList(Model.DdlPaymentStatus, "ItemValue", "ItemText"))
            @Html.TextBox("sBeginDate", null, new { maxlength = "50", @class = "text-date", placeholder = "进货日期" }) ~ @Html.TextBox("sEndDate", null, new { maxlength = "50", @class = "text-date", placeholder = "进货日期" })
            @Html.TextBox("sKeywords", null, new { maxlength = "50", placeholder = "关键字" })
            <button class="btn btn-default" id="btnSearch">搜索</button>
            <button id="btnNew" type="button" class="btn btn-default">新增</button>
            @if (user.PermissionList.Contains(Com._9pm2.ClientWeb.Common.PT_PermissionType.P4_供应商对账))
            {
                <button class="btn btn-default" type="button" onclick="btnBatchPayment();">批量支付</button>
            }
        </div>
    </div>
</form>

<div class="error-msg"></div>

<div class="list">
    <table id="tStockIn" class="">
        <thead>
            <tr>
                <th>
                    <input type="checkbox" id="chkAll" onclick="SelectAll();" />
                </th>
                <th>进货单编号</th>
                <th>进货类型</th>
                <th>供应商</th>
                <th>总金额</th>
                <th>进货日期</th>    
                <th>审核状态</th>
                <th>付款状态</th>   
                <th>经办人</th>   
                <th style="width:120px;">操作</th>
            </tr>
        </thead>
        <tbody id="stockInList">
            @foreach (var item in Model.List)
            {
                <tr id="@item.Id">
                    <td class="td-checkbox">
                        <input type="checkbox" onclick="SelectOne();" />
                    </td>
                    <td>@item.SN</td>
                    <td>@((Com._9pm2.ClientWeb.Common.StockInType)item.Type)</td>
                   
                    <td>@item.Supplier.Name</td>
                    <td>
                        <span id="s1">@item.Amount</span>
                        <span style="display:none" id="s2">@item.Paid</span>
                    </td>
                    <td>@item.StockInTime.ToString("yyyy-MM-dd")</td>
                    <td><span>@((Com._9pm2.ClientWeb.Common.StockInStatus)item.Status)</span></td>
                    <td>
                        <span>@((Com._9pm2.ClientWeb.Common.SupplierPaymentStatus)item.PaymentStatus)</span>                        
                    </td>                   
                    <td>@item.Operator</td>
                    <td style="text-align:center" class="td-last">
                        <div class="operation-btns">
                            <div>
                                <button id="select">&nbsp;</button>
                            </div>
                            <ul>                                
                                @if (item.Status != (int)Com._9pm2.ClientWeb.Common.StockInStatus.已审核)
                                {
                                    <li><a href="javascript:void(0);" onclick="EditStockIn('@item.Id');">编辑</a></li>                                    
                                    <li><a href="javascript:void(0);" onclick="DeleteStockIn('@item.Id');">删除</a></li>
                                    if (user.PermissionList.Contains(Com._9pm2.ClientWeb.Common.PT_PermissionType.P8_进货单审核))
                                    {
                                        <li><a href="javascript:void(0);" onclick="ApproveStockIn('@item.Id');">审核入库</a></li>
                                    }
                                }
                                else
                                {
                                    if (user.PermissionList.Contains(Com._9pm2.ClientWeb.Common.PT_PermissionType.P8_进货单审核))
                                    {
                                         <li><a href="javascript:void(0);" onclick="UnApproveStockIn('@item.Id');">反审核</a></li>
                                    }
                                }

                                @if (user.PermissionList.Contains(Com._9pm2.ClientWeb.Common.PT_PermissionType.P4_供应商对账))
                                {
                                    <li><a href="javascript:void(0);" onclick="AddPayment('@item.Id')">支付</a></li>
                                }
                            </ul>
                        </div>
                    </td>
                </tr>            
            }

            @if (Model.List.Count() > 0)
            {
                <tr class="totalTd">
                    <td colspan="2">
                        <span>总计(所有页):</span>
                    </td>
                   
                    <td></td>
                    <td></td>
                    <td class="oderAmountTotal">@Com._9pm2.ClientWeb.Utilities.NFormat.Format(Model.TotalAmount) </td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
            }
        </tbody>
    </table>
    @Html.Pager("StockIn", "Warehouse", Model.RouterDirectory, Model.PagerConfig, "pagerDiv", "pagerDiv", 8, true, false, true, true, false)
</div>  

<div id="divPayment" title="订单支付信息" style="display:none">
    <div id="divPaymentContent" class="list">
        <div id="paymentStatusDiv" class="FL" style="margin-bottom:5px;">
            <span class="OrderStatus">支付状态：</span>
            <span id="pdPaymentStatus" class="OrderStatus"></span>
        </div>
        <div id="unpaidDiv" class="FR" style="float:right;margin-bottom:5px;">
            <span class="OrderStatus">未付金额：</span>
            <span class="OrderStatusUnPaid" style="color:Red" id="unpaidAmount"></span>
        </div>
        <div class="gray clear">提示：支付记录不可删除。如果录入错误，可以随后补录一笔负数冲抵。</div>
        <table class="tableEdit">
            <tr>
                <td class="label">
                    支付记录
                </td>
                <td colspan="3" id="PaymentHistory"></td>
            </tr>
            <tr>
                <td class="label">
                    订单金额
                </td>
                <td class='money' id="Amount"></td>
                <td class="label">
                    已付金额
                </td>
                <td class='money' id="Paid"></td>
            </tr>
            <tr id="trAddPayment2">
                <td class="label">
                    支付金额
                </td>
                <td>
                    <input type="text" id="PaymentAmount" class="text-money" /> &nbsp;<span class="redStar">*</span>
                </td>
                <td class="label">
                    支付方式
                </td>
                <td>
                    @Html.DropDownList("PaymentType", new SelectList(Model.DdlPaymentType, "ItemValue", "ItemText"), new { @style = "width:160px;" }) &nbsp;<span class="redStar">*</span>
                </td>
            </tr>
            <tr id="trAddPayment3">
                <td class="label">
                    备注
                </td>
                <td colspan="3">
                    <input type="text" style="width: 400px" id="PaymentMemo" />
                </td>
            </tr>
        </table>
    </div>
    <div style="text-align: right;">
        <div class="error-msg"></div>
        <button type="button" class="btn btn-primary" id="btnAddPayment" onclick="PaymentSubmit()">支付</button>
        <button type="button" class="btn btn-default" onclick="$('#divPayment').dialog('close');">关闭</button>
    </div>
</div>

<div id="divBatchPayment" title="批量支付" style="display: none">
    <div id="divBatchPaymentContent" class="list" style="overflow-y: auto; ">

        <table class="tableEdit">
            <tr>
                <td class="label">
                    未付金额
                </td>
                <td style="font-weight:bold; font-size:1.3em;color:#a94442" id="batchUnpaidAmount"></td>
            </tr>
            <tr>
                <td class="label">
                    支付金额
                </td>
                <td>
                    <input type="text" id="PaymentAmount" class="text-money" /> &nbsp;<span class="redStar">*</span>
                </td>
            </tr>
            <tr>
                <td class="label">
                    支付方式
                </td>
                <td>
                    @Html.DropDownList("batchPaymentType", new SelectList(Model.DdlPaymentType, "ItemValue", "ItemText"), new { @style = "width:160px;" }) &nbsp;<span class="redStar">*</span>
                </td>
            </tr>
            <tr>
                <td class="label">
                    备注
                </td>
                <td>
                    <input style="width: 400px" type="text" id="batchPaymentMemo" />
                </td>
            </tr>
        </table>
    </div>
    <div style="text-align: right;">

        <div class="error-msg"></div>
        <button type="button" class="btn btn-primary" id="btnAddBatchPayment" onclick="BatchPaymentSubmit()">保存</button>
        <button type="button" class="btn btn-default" onclick="$('#divBatchPayment').dialog('close');">关闭</button>
    </div>
</div>


@Html.Partial("StockInDetail")