<%@ page language="C#" masterpagefile="~/Member/MyShopMasterPage.master" autoeventwireup="true" inherits="Member_JXC_AccountAoucherInfo, WebApp_deploy" title="记账凭证信息" %>

<asp:Content ID="cphContent" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <script type="text/javascript">
        function pickedFunc() {
            $dp.$('<%=txtCreateTime.ClientID %>').value = $dp.cal.getNewDateStr('yyyy-MM-dd HH:mm:ss');
        }
    </script>
    <div class="pageTitle" style="line-height: 30px; vertical-align: middle;">
        &nbsp;&nbsp;&nbsp;&nbsp;凭证信息</div>
    <div class="TabText">
        <table class="ShopOrderStyle">
            <caption>
                &nbsp;<asp:Literal ID="ltrTitle" runat="server" Text="记账凭证"></asp:Literal>
            </caption>
        </table>
        <table class="ShopOrderStyle" runat="server">
            <tr>
                <td class="OrderTitle">
                    凭证号码 ：
                </td>
                <td>
                    <asp:TextBox ID="txtAccountANumber" runat="server" Width="200px"></asp:TextBox>
                </td>
                <td class="OrderTitle">
                    凭证张数 ：
                </td>
                <td>
                    <asp:TextBox ID="txtAccountACountAdd" runat="server" Width="60px"></asp:TextBox>
                    <asp:RegularExpressionValidator ForeColor="Red" ID="revCountAdd" runat="server" ControlToValidate="txtAccountACountAdd"
                        ErrorMessage="只能填写数字" ValidationExpression="\d" Display="Dynamic" />
                </td>
            </tr>
            <tr>
                <td class="OrderTitle">
                    制单人 ：
                </td>
                <td>
                    <asp:TextBox ID="txtInputer" runat="server" Width="200px"></asp:TextBox>
                </td>
                <td class="OrderTitle">
                    制单时间 ：
                </td>
                <td>
                    <asp:TextBox ID="txtCreateTime" runat="server" onfocus="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss',onpicked:pickedFunc})"
                        CssClass="Wdate" Width="165px"></asp:TextBox>
                </td>
            </tr>
            <tr id="tr_IsCaudit" runat="server" visible="false">
                <td class="OrderTitle">
                    审核人 ：
                </td>
                <td>
                    <asp:Label ID="lblCauditName" runat="server"></asp:Label>
                </td>
                <td class="OrderTitle">
                    审核时间 ：
                </td>
                <td>
                    <asp:Label ID="lblCauditDate" runat="server"></asp:Label>
                </td>
            </tr>
            <tr id="tr_IsAccount" runat="server" visible="false">
                <td class="OrderTitle">
                    记账人 ：
                </td>
                <td>
                    <asp:Label ID="lblAccountName" runat="server"></asp:Label>
                </td>
                <td class="OrderTitle">
                    记账时间 ：
                </td>
                <td>
                    <asp:Label ID="lblAccountDate" runat="server"></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="OrderTitle">
                    凭证说明 ：
                </td>
                <td colspan="3">
                    <asp:TextBox ID="txtAccountAExplainAdd" runat="server" TextMode="MultiLine" Width="320px" Height="60px"></asp:TextBox>
                </td>
            </tr>
        </table>
        <table class="ShopOrderStyle">
            <tr>
                <td colspan="4">
                    <asp:HiddenField ID="hfInfoID" runat="server" />
                    <%--凭证ID--%>
                    <div id="divItem" runat="server">
                    </div>
                    <asp:HiddenField ID="hfStockOrderID" runat="server" />
                    <%--库单ID--%>
                    <div id="divInfo" runat="server">
                    </div>
                </td>
            </tr>
        </table>
        <table class="ShopOrderStyle">
            <tr>
                <td align="center" valign="bottom" colspan="4" style="line-height: 30px">
                    <span style="margin-left: 160px">&nbsp;</span>
                    <input type="button" id="btnSelectOrder" onclick="SelectOrder()" value="选择库单" />&nbsp;&nbsp;
                    <asp:Button ID="btnCashierOK" runat="server" Text="审核凭证" OnClientClick="return confirm('确定要审核凭证信息吗？');"
                        OnClick="btnCashierOK_Click"></asp:Button>&nbsp;&nbsp;
                    <asp:Button ID="btnCashierCancle" runat="server" Text="取消审核" OnClientClick="return confirm('确定要取消已审核的凭证信息吗？');"
                        OnClick="btnCashierCancle_Click"></asp:Button>&nbsp;&nbsp;
                    <asp:Button ID="btnDelInfo" runat="server" Text="删除凭证" OnClientClick="return confirm('确定要删除凭证信息吗？');"
                        OnClick="btnDelInfo_Click"></asp:Button>&nbsp;&nbsp;
                    <asp:Button ID="btnSave" runat="server" Text="保存" OnClick="btnSave_Click"></asp:Button>&nbsp;&nbsp;
                    <asp:Button ID="btnCancle" runat="server" Text="取消" OnClick="btnCancle_Click"></asp:Button>
                </td>
            </tr>
        </table>
        <br />
    </div>
    <script type="text/javascript">
        $(function () {
            //添加：addinfo、修改：editinfo
            var actionInfo = "<%=Action %>";
            if (actionInfo == "addinfo") {
                document.getElementById("<%=btnSave.ClientID %>").disabled = true; //保存按钮不可用


                $("#<%=divInfo.ClientID %>").css("diplay", "block"); //库单信息
                $("#<%=divItem.ClientID %>").css("diplay", "none"); //凭证记录信息

            } else if (actionInfo == "checkinfo" || actionInfo == "editinfo") {
                document.getElementById("btnSelectOrder").disabled = true; //选择库单按钮不可用


                $("#<%=divInfo.ClientID %>").css("diplay", "none"); //库单信息
                $("#<%=divItem.ClientID %>").css("diplay", "block"); //凭证记录信息

                var ctlName = document.getElementById("<%=hfInfoID.ClientID %>");
                GetItemByInfoID(ctlName.value); //记录信息
            }
        });
    </script>
    <script type="text/javascript">
        //选择库单
        function SelectOrder() {
            var ctlName = document.getElementById("<%=hfStockOrderID.ClientID %>");
            var arr = showModalDialog('/Member/JXC/StockInfoOrderSelect.aspx?ProductType=0&DefaultValue=' + ctlName.value, '', 'dialogWidth:750px; dialogHeight:600px; help: no; scroll: yes; status: no');
            if (arr != null) {
                ctlName.value = arr;
                document.getElementById("<%=btnSave.ClientID %>").disabled = false; //保存按钮可用
                getStockOrderInfo(arr); //库单信息
            }
        }
        //库单信息
        function getStockOrderInfo(stockorderid) {
            var itemStr = "";
            $("#<%=divInfo.ClientID %>").html("");
            itemStr += "<table class='tableHead' width='100%' id='tb_rptProduct'>" +
                           "<tr><th style='text-align: center;'>库单号码</th>" +
                           "<th style='text-align: center;'>商品金额</th>" +
                           "<th style='text-align: center;'>运费金额</th>" +
                          "<th style='text-align: center;'>发票税额</th>" +
                          "<th style='text-align: center;'>订单税额</th>" +
                          "<th style='text-align: center;'>手续费</th>" +
                          "<th style='text-align: center;'>应收金额</th>" +
                          "<th style='text-align: center;'>已收金额</th></tr>";
            $.post("../../WebService/Member_JXCService.ashx", { 'Action': 'GetStockOrderStockOrderID', 'StockOrderID': stockorderid }, function (data, state) {
                if (state == "success") {
                    if (data.toString() != "") {
                        var d = eval(data);
                        $.each(d.table1, function (i) {
                            var infoNumber = d.table1[i].InfoNumber; //库单号码
                            var moneyGoods = d.table1[i].MoneyGoods; //商品金额
                            var deliver_TotalPrice = d.table1[i].Deliver_TotalPrice; //运费金额
                            var invoice_TotalPrice = d.table1[i].Invoice_TotalPrice; //发票税额
                            var moneyTotal = d.table1[i].MoneyTotal; //订单税额
                            var fee = d.table1[i].Fee; //手续费
                            var receiptMoney = d.table1[i].ReceiptMoney; //应收金额
                            var alreadyReceiptMoney = d.table1[i].AlreadyReceiptMoney; //已收金额

                            itemStr += "<tr><td style='text-align: center;'>" + infoNumber + "</td>" +
                                        "<td style='text-align: center;'>" + moneyGoods + "</td>" +
                                        "<td style='text-align: center;'>" + deliver_TotalPrice + "</td>" +
                                        "<td style='text-align: center;'>" + invoice_TotalPrice + "</td>" +
                                        "<td style='text-align: center;'>" + moneyTotal + "</td>" +
                                        "<td style='text-align: center;'>" + fee + "</td>" +
                                        "<td style='text-align: center;'>" + receiptMoney + "</td>" +
                                        "<td style='text-align: center;'>" + alreadyReceiptMoney + "</td>";

                        });
                    } else {
                        itemStr += "<tr><td style='text-align: center;' colspan='8'>没有数据！</td>";
                    }
                    itemStr += "</tr></table>";
                    $("#<%=divInfo.ClientID %>").append(itemStr);
                }
            });
        }

        //记录信息
        function GetItemByInfoID(infoids) {
            var itemStr = "";
            $("#<%=divItem.ClientID %>").html("");
            itemStr += "<table class='tableHead' width='100%' id='tb_rptProduct'>" +
                           "<tr><th style='text-align: center;'>行号</th>" +
                           "<th style='text-align: center;'>会计科目</th>" +
                           "<th style='text-align: center;'>摘要</th>" +
                          "<th style='text-align: center;'>借方金额</th>" +
                          "<th style='text-align: center;'>贷方金额</th></tr>";
            $.post("../../WebService/Member_JXCService.ashx", { 'Action': 'GetAAItemByInfoID', 'InfoID': infoids }, function (data, state) {
                if (state == "success") {
                    if (data.toString() != "") {
                        var d = eval(data);
                        $.each(d.table1, function (i) {
                            var itemid = d.table1[i].AccountAItemID; //科目Id
                            var subjectid = d.table1[i].AAItemAccountSID; //科目Id
                            var itemsummary = d.table1[i].AAItemSummary; //摘要
                            var borrowprice = d.table1[i].BorrowPrice; //借方金额
                            var loanprice = d.table1[i].LoanPrice; //贷方金额
                            var subjcetname = "&nbsp;" + d.table1[i].SubjectName;
                            itemStr += "<tr><td style='text-align: center;'><input type='hidden' id='itemid" + i + "' value='" + itemid + "' />" + (i + 1) + "</td>" +
                                        "<td style='text-align: left;'>" + subjcetname + "</td>" +
                                        "<td style='text-align: center;'>" + itemsummary + "</td>";

                            if (parseFloat(borrowprice) > 0 && parseFloat(loanprice) == 0) {
                                itemStr += "<td style='text-align: center;'>" + borrowprice + "</td>" +
                                        "<td style='text-align: center;'>&nbsp;</td>";
                            } else if (parseFloat(borrowprice) == 0 && parseFloat(loanprice) > 0) {
                                itemStr += "<td style='text-align: center;'>&nbsp;</td>" +
                                        "<td style='text-align: center;'>" + loanprice + "</td>";
                            }

                        });
                    } else {
                        itemStr += "<tr><td style='text-align: center;' colspan='5'>没有数据！</td>";
                    }
                    itemStr += "</tr></table>";
                    $("#<%=divItem.ClientID %>").append(itemStr);
                }
            });
        }
    </script>
</asp:Content>
