<%@ page language="C#" masterpagefile="~/Member/MyShopMasterPage.master" autoeventwireup="true" inherits="Member_JXC_StockOrderSale, WebApp_deploy" title="销售出库单" %>

<asp:Content ID="cphContent" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <script src="../../Js/My97DatePicker/config.js" type="text/javascript"></script>
    <script src="../../Js/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script type="text/javascript">
        function pickedFunc() {
            $dp.$('<%=txtInputTime.ClientID %>').value = $dp.cal.getNewDateStr('yyyy-MM-dd HH:mm:ss');
        }
        //收款期限
        function pickedFunE() {
            $dp.$('<%=txtReceiptEndDate.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" id="tab_AddOrEdit">
            <tr>
                <td class="OrderTitle">
                    单据编号 ：
                </td>
                <td style="width: 220px">
                    <asp:TextBox ID="txtStockNumber" runat="server" Enabled="false" Width="200px"></asp:TextBox>
                </td>
                <td class="OrderTitle">
                    记录时间 ：
                </td>
                <td style="width: 220px">
                    <asp:TextBox ID="txtInputTime" runat="server" onfocus="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss',onpicked:pickedFunc})"
                        CssClass="Wdate" Width="165px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="OrderTitle">
                    记录人 ：
                </td>
                <td>
                    <asp:TextBox ID="txtInputer" runat="server"></asp:TextBox>
                </td>
                <td class="OrderTitle">
                    收款期限 ：
                </td>
                <td>
                    <asp:TextBox ID="txtReceiptEndDate" runat="server" onfocus="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss',onpicked:pickedFunE})"
                        CssClass="Wdate" Width="165px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="OrderTitle">
                    客户名称 ：
                </td>
                <td>
                    <asp:Label ID="lblBuyerName" runat="server"></asp:Label>
                </td>
                <td class="OrderTitle">
                    收款日期 ：
                </td>
                <td>
                    <asp:Label ID="lblPayTime" runat="server"></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="OrderTitle">
                    运费金额 ：
                </td>
                <td>
                    <asp:Label ID="lblDeliver_TotalPrice" runat="server"></asp:Label>
                </td>
                <td class="OrderTitle">
                    发票金额 ：
                </td>
                <td>
                    <asp:Label ID="lblInvoice_TotalPrice" runat="server"></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="OrderTitle">
                    商品金额 ：
                </td>
                <td>
                    <asp:Label ID="lblMoneyGoods" runat="server"></asp:Label>
                </td>
                <td class="OrderTitle">
                    应收金额 ：
                </td>
                <td>
                    <asp:Label ID="lblReceiptMoney" runat="server" Width="165px"></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="OrderTitle">
                    已收金额 ：
                </td>
                <td>
                    <asp:Label ID="lblAreadyReceiptMoney" runat="server"></asp:Label>
                </td>
                <td class="OrderTitle">
                    费用 ：
                </td>
                <td>
                    <asp:Label ID="lblFee" runat="server"></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="OrderTitle">
                    备注 ：
                </td>
                <td colspan="3">
                    <asp:TextBox ID="txtRemarks" runat="server" TextMode="MultiLine" Width="260px" Height="60px"></asp:TextBox>
                </td>
            </tr>
        </table>
        <table class="ShopOrderStyle">
            <tr>
                <td colspan="4">
                    <asp:HiddenField ID="hfProductStr" runat="server" />
                    <asp:HiddenField ID="hfOrderID" runat="server" />
                    <%--订单ID--%>
                    <asp:HiddenField ID="hfMoneyGoods" runat="server" />
                    <%--商品--%>
                    <asp:HiddenField ID="hfDeliver_TotalPrice" runat="server" />
                    <%--运费--%>
                    <asp:HiddenField ID="hfInvoice_TotalPrice" runat="server" />
                    <%--发票金额--%>
                    <asp:HiddenField ID="hfFee" runat="server" />
                    <%--费用--%>
                    <asp:HiddenField ID="hfMoney" runat="server" />
                    <%--收款金额--%>
                    <asp:HiddenField ID="hfAlreadyMoney" runat="server" />
                    <%--已收金额--%>
                    <asp:HiddenField ID="hfTime" runat="server" />
                    <%--收款日期--%>
                    <asp:HiddenField ID="hfDeliverStatus" runat="server" />
                    <%--物流状态--%>
                    <div id="divProduct" runat="server">
                    </div>
                </td>
            </tr>
            <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;
                    <input type="button" id="btnCheckAoucher" onclick="javascript:window.location.href = 'CheckAccountAoucher.aspx?Action=checkinfo&InfoID=<%=InfoID %>'"
                        value="查看凭证" />&nbsp;&nbsp;
                    <asp:Button ID="btnSave" runat="server" Text="保存" OnClientClick="return checkPass()"
                        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 checkInputTime() {
            var inputTime = $("#<%=txtInputTime.ClientID %>"); //记录时间
            if (inputTime.val().length == 0) {
                alert("记录时间不能为空!");
                inputTime.focus();
                return false;
            }
            return true;
        }
        function checkPass() {
            if (checkInputTime() && GetAddProducts()) {
                return true;
            } else {
                return false;
            }
        }


        //商品
        function GetAddProducts() {
            //添加：addinfo、修改：editinfo
            var actionInfo = "<%=ActionInfo %>"; 
            if (actionInfo == "editinfo") {

            }
            var lblMoneyGoods = $("#<%=lblMoneyGoods.ClientID %>"); //商品金额
            var hfMoneyGoods = $("#<%=hfMoneyGoods.ClientID %>");
            hfMoneyGoods.val(lblMoneyGoods.text());

            var lblDeliver_TotalPrice = $("#<%=lblDeliver_TotalPrice.ClientID %>"); //运费
            var hfDeliver_TotalPrice = $("#<%=hfDeliver_TotalPrice.ClientID %>");
            hfDeliver_TotalPrice.val(lblDeliver_TotalPrice.text());

            var lblInvoice_TotalPrice = $("#<%=lblInvoice_TotalPrice.ClientID %>"); //发票金额
            var hfInvoice_TotalPrice = $("#<%=hfInvoice_TotalPrice.ClientID %>");
            hfInvoice_TotalPrice.val(lblInvoice_TotalPrice.text());

            var lblFee = $("#<%=lblFee.ClientID %>"); //费用
            var hfFee = $("#<%=hfFee.ClientID %>");
            hfFee.val(lblFee.text());

            var lblReceiptMoney = $("#<%=lblReceiptMoney.ClientID %>"); //收款金额
            var hfMoney = $("#<%=hfMoney.ClientID %>");
            hfMoney.val(lblReceiptMoney.text());

            var lblAreadyReceiptMoney = $("#<%=lblAreadyReceiptMoney.ClientID %>"); //已收金额
            var hfAlreadyMoney = $("#<%=hfAlreadyMoney.ClientID %>");
            hfAlreadyMoney.val(lblAreadyReceiptMoney.text());

            var lblPayTime = $("#<%=lblPayTime.ClientID %>"); //收款日期
            var hfTime = $("#<%=hfTime.ClientID %>");
            hfTime.val(lblPayTime.text());


            var hfDeliverStatus = $("#<%=hfDeliverStatus.ClientID %>"); //物流状态
            hfDeliverStatus.val();

            var productstr = $("#<%=hfProductStr.ClientID %>"); //商品（ID,数量,价格,单位,入库后）
            var productlist = $("#tb_rptProduct tr"); //商品信息
            if (productlist.length <= 1) {
                alert("没有需入/出库的商品！");
                return false;
            }
            var str = "";
            var newstr = "";
            if (productlist.length - 1 > 0) {
                for (var i = 0; i < productlist.length - 1; i++) {
                    var vproductid = $("#productID" + i); //商品ID
                    var vcount = $("#count" + i); //数量
                    var vprice = $("#price" + i); //价格
                    var vunit = $("#unit" + i); //单位
                    newstr = vproductid.val() + "," + vcount.text() + "," + vprice.text() + "," + vunit.text() + "|";
                    str += newstr;
                }
                var position = str.lastIndexOf('|');
                if (position > 0) {
                    str = str.substring(0, str.length - 1);
                }
                productstr.val(str);
            }
            return true;
        }      
    </script>
    <script type="text/javascript">
        $(function () {
            //添加：addinfo、修改：editinfo
            var actionInfo = "<%=ActionInfo %>";
            var Ownerpower = "<%=Ownerpower %>";
            if (Ownerpower.toString().toLowerCase() == "false") {
                document.getElementById("btnCheckAoucher").style.display = "none";
            }
            if (actionInfo == "addinfo") {
                document.getElementById("<%=btnSave.ClientID %>").disabled = true; //保存按钮不可用
                document.getElementById("btnCheckAoucher").disabled = true; //查看凭证按钮不可用
            } else if (actionInfo == "editinfo") {
                var ctlName = document.getElementById("<%=hfOrderID.ClientID %>");
                GetProductByOrderProdcutIDs(ctlName.value);
                document.getElementById("btnSelectOrder").disabled = true; //选择订单按钮不可用
                document.getElementById("btnCheckAoucher").disabled = false; //查看凭证可用
            }
        });
    </script>
    <script type="text/javascript">
        //选择订单
        function SelectOrder() {
            var ctlName = document.getElementById("<%=hfOrderID.ClientID %>");
            var arr = showModalDialog('/Member/JXC/StockOrderSaleSelect.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; //保存
                GetProductByOrderProdcutIDs(arr);
            }
        }
        //商品信息
        function GetProductByOrderProdcutIDs(orderids) {
            var lblBuyerName = $("#<%=lblBuyerName.ClientID %>"); //客户名称
            var lblDeliver_TotalPrice = $("#<%=lblDeliver_TotalPrice.ClientID %>"); //运费金额
            var lblInvoice_TotalPrice = $("#<%=lblInvoice_TotalPrice.ClientID %>"); //发票金额
            var lblMoneyGoods = $("#<%=lblMoneyGoods.ClientID %>"); //商品金额
            var lblReceiptMoney = $("#<%=lblReceiptMoney.ClientID %>"); //应收金额
            var lblAreadyReceiptMoney = $("#<%=lblAreadyReceiptMoney.ClientID %>"); //已收金额
            var lblPayTime = $("#<%=lblPayTime.ClientID %>"); //收款时间
            var lblFee = $("#<%=lblFee.ClientID %>"); //费用
            var hfDeliverStatus = $("#<%=hfDeliverStatus.ClientID %>"); //物流状态

            //添加：addinfo、修改：editinfo
            var actionInfo = "<%=ActionInfo %>";
            var prodcutStr = "";
            $("#<%=divProduct.ClientID %>").html("");
            prodcutStr += "<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></tr>";
            $.post("../../WebService/Member_JXCService.ashx", { 'Action': 'GetProductByOrderProdcutIDs', 'OrderIDs': orderids }, function (data, state) {
                if (state == "success") {
                    if (data.toString() != "") {
                        var d = eval(data);
                        $.each(d.table1, function (i) {
                            lblBuyerName.text(d.table1[i].BuyerName);
                            lblDeliver_TotalPrice.text(d.table1[i].Deliver_TotalPrice);
                            lblInvoice_TotalPrice.text(d.table1[i].Invoice_TotalPrice);
                            lblMoneyGoods.text(d.table1[i].MoneyGoods);

                            var orderTotal = d.table1[i].MoneyTotal; //订单金额
                            var moneyreceipy = d.table1[i].MoneyReceipt; //包含手续费
                            var alreadymoney = d.table1[i].alMoneyReceipt; //不包括手续费(已收金额)
                            if (alreadymoney == "" || alreadymoney == null) {
                                alreadymoney = 0;
                            }
                            lblAreadyReceiptMoney.text(moneyreceipy); //已收金额

                            var fee = 0;
                            var chazhi = parseFloat(moneyreceipy) - parseFloat(alreadymoney);
                            if (parseFloat(chazhi) >= 0) {
                                fee = parseFloat(moneyreceipy) - parseFloat(alreadymoney);
                            }
                            lblFee.text(fee);
                            var rm = parseFloat(orderTotal) + parseFloat(fee);

                            lblReceiptMoney.text(rm); //应收金额
                            lblPayTime.text(d.table1[i].PayTime);
                            hfDeliverStatus.val(d.table1[i].DeliverStatus);

                            var productid = d.table1[i].ProductID;
                            var productname = d.table1[i].ProductName;
                            var pt = d.table1[i].ProductType;
                            var producttype = "普通商品";
                            //商品类型（一口价：1、拍卖：2、团购：3、促销(秒杀)：4、积分商品：5）
                            if (pt == "5") {
                                producttype = "积分商品";
                            } else if (pt == "4") {
                                producttype = "促销(秒杀)";
                            } else if (pt == "3") {
                                producttype = "团购";
                            } else if (pt == "2") {
                                producttype = "拍卖";
                            } else if (pt == "1") {
                                producttype = "一口价";
                            }
                            var productcount = d.table1[i].Quantity;
                            var productprice = d.table1[i].Price;
                            var productunit = d.table1[i].PUnit;
                            var producttotal = parseFloat(productprice) * parseInt(productcount);
                            if (productname.length > 20) {
                                productname = productname.substring(0, 18) + "...";
                            }
                            prodcutStr += "<tr><td style='text-align: center;'>" + (i + 1) + "</td>" +
                                        "<td style='text-align: center;'><input type='hidden' id='productID" + i + "' value='" + productid + "' />" + productname + "</td>" +
                                        "<td style='text-align: center;'>" + producttype + "</td>" +
                                        "<td style='text-align: center;'><span style='color:black' id='count" + i + "'>" + productcount + "</span></td>" +
                                        "<td style='text-align: center;'><span style='color:black' id='price" + i + "'>" + productprice + "</span></td>" +
                                        "<td style='text-align: center;'><span style='color:black' id='unit" + i + "'>" + productunit + "</span></td>" +
                                        "<td style='text-align: center;'>" + producttotal + "</td>";

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