<%@ Page Title="" Language="C#" MasterPageFile="~/Styles/MasterPage/MasterPage_Edit.master" AutoEventWireup="true" CodeFile="DeliveryOrders_Edit.aspx.cs" Inherits="Sale_DeliveryOrder_DeliveryOrders_Edit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <script type="text/javascript">
        var do_id = '<%=id%>';
        var action = '<%=xview["action"]%>';
        function Save() {
            <%=xview["Script_GetInput"] %>
            var action = '<%=xview["action"]%>';
            parent.ShowLoadingMask(); //显示遮罩
            $.ajax({
                type: "POST",
                contentType: "application/json",
                url: 'DeliveryOrders_Service.asmx/Save',
                data: "{action:'" + action + "',<%=xview["Script_SaveJSON"]%>}",
                dataType: 'json',
                success: function (result) {
                    parent.HideLoadingMask(); //关闭遮罩
                    var r = result.d;
                    if (r == "success") {
                        if(action == "Add"){
                            asyncbox.confirm('保存成功!\n是否要继续新增？','提示',function(buttonResult){
　　　                            if(buttonResult == 'ok'){
　　　　　                            window.location.reload();
　　　                            }else{
                                    parent.search_grid();
                                    CloseDivWin(); //关闭窗口
　　　                            }
                            });
                        }else{
                            parent.search_grid();
                            asyncbox.success('保存成功!','提示',function(buttonResult){
                                CloseDivWin(); //关闭窗口
                            });
                        }
                    } else {
                        parent.AlertNO(r);
                    }
                }
            });
        }
    </script>
    <!--工具栏-->
    <div class="list_menu_bar">
        <a plain="true" class="easyui-linkbutton" iconcls="icon-save" onclick="Save()" id="btn_save" style='<%=auth.AuthView("Sale_DeliveryOrder_Edit")%>'>保存</a>
    </div>
    <div id="edit_div" style="width:800px;height:500px;overflow:auto;">
        <div class="edit_area" style='margin-left:40px;border:solid 0px red;float:left'>
        <%=xview["input_ui"]%>
        </div>
        <div style='float:left'>
            <a id="inventory_photo_view_href" href='<%=xview["inventory_photo_view_href"]%>' target="_blank">
                <img id="inventory_photo_view" style='border:0px' id='small_pic_url' src="<%=xview["inventory_photo_view"]%>"/></a>
        </div><br />
    </div>

    <script type="text/javascript">
        var dgt_quan = <%=xview["digit_quantity"]%>;
        var dgt_num = <%=xview["digit_number"]%>;
        var dgt_exch = <%=xview["digit_exch"]%>;
        var dgt_pri = <%=xview["digit_unit_price"]%>;
        var exchange_rate = <%=tm.exchange_rate%>;
        var cus_id = '<%=tm.customer==null?0:tm.customer.cus_id%>';
        flag_is_sale = 1;//只显示开启销售属性的存货
        //初始化页面
        function init_page() {
            $F("do_id").value = "<%=id%>";
            var verify_uid = '<%=tm.verify_uid%>';
            if(verify_uid != ''){
                $('#btn_save').linkbutton('disable');
                disable_all_input();//禁止输入
            }
            if(verify_uid == ''){
                FastSearch_Inventory(); //查询存货
                FastSearch_D_Warehouse(); //查询仓库

                //选择自定义项档案
                <%for(int i=1;i<=5;i++){ %>
                $F("trigger_d_sdefine<%=i%>").onclick = function () {
                    AdvancedSearch_DefineItem($("#d_sdefine<%=i%>").val(),'DeliveryOrders_d_sdefine<%=i%>','d_sdefine<%=i%>');
                };
                <%}
              for(int i=1;i<=5;i++){ %>
                $F("trigger_d_ndefine<%=i%>").onclick = function () {
                    AdvancedSearch_DefineItem($("#d_ndefine<%=i%>").val(),'DeliveryOrders_d_ndefine<%=i%>','d_ndefine<%=i%>');
                };
                <%} %>

                //弹窗选择自由项
                $F("trigger_free1").onclick = function () {
                    AdvancedSearch_DefineItem($("#free1").val(),'free1','free1');
                };
                $F("trigger_free2").onclick = function () {
                    AdvancedSearch_DefineItem($("#free2").val(),'free2','free2');
                };
                //弹窗选择批次
                $F("trigger_batch").onclick = function () {
                    AdvancedSearch_Batch($("#batch").val(),'batch','batch');
                };
                //弹窗选择销售订单
                $F("trigger_so_order_number").onclick = function () {
                    AdvancedSearch_SalesOrders($("#so_order_number").val());
                };
            }
            $F('tax').readOnly = true;//禁输税额
            //禁输外币部分
            $F('nat_unit_price').readOnly = true;
            $F('nat_total_price').readOnly = true;
            $F('nat_tax').readOnly = true;
            $F('nat_tax_total_price').readOnly = true;
            $F('nat_tax_unit_price').readOnly = true;
            <%if(action.Equals("Update")){ %>
                $F("i_code").value = '<%=m.inventory.i_code%>';
                $F("i_name").value = '<%=m.inventory.i_name%>';
                $F("standard").value = '<%=m.inventory.standard%>';
                $F("munit").value = '<%=m.inventory.munit%>';
                $F("aunit").value = '<%=m.inventory.aunit%>';
                $F("d_wh_name").value = '<%=m.warehouse==null?"":m.warehouse.wh_name%>';
                $F("order_quantity").value = '<%=m.sales_orders==null ?0:m.sales_orders.quantity%>';

                $F("d_inv_sdefine1").value = '<%=m.inventory.sdefine1%>';//存货字符自定义项1
                $F("d_inv_sdefine2").value = '<%=m.inventory.sdefine2%>';//存货字符自定义项2
                $F("d_inv_sdefine3").value = '<%=m.inventory.sdefine3%>';//存货字符自定义项3
                $F("d_inv_sdefine4").value = '<%=m.inventory.sdefine4%>';//存货字符自定义项4
                $F("d_inv_sdefine5").value = '<%=m.inventory.sdefine5%>';//存货字符自定义项5

                $F("d_inv_ndefine1").value = '<%=m.inventory.ndefine1%>';//存货数值自定义项1
                $F("d_inv_ndefine2").value = '<%=m.inventory.ndefine2%>';//存货数值自定义项2
                $F("d_inv_ndefine3").value = '<%=m.inventory.ndefine3%>';//存货数值自定义项3
                $F("d_inv_ndefine4").value = '<%=m.inventory.ndefine4%>';//存货数值自定义项4
                $F("d_inv_ndefine5").value = '<%=m.inventory.ndefine5%>';//存货数值自定义项5


            <%}else{ %>
                $F("d_tax_rate").value = parent.$F("tax_rate").value;//税率
                $F("kl").value = parent.$F("zdkl").value;//整单扣率
                $F("d_wh_id").value = '<%=tm.warehouse==null?0:tm.warehouse.wh_id%>';
                $F("d_wh_name").value = '<%=tm.warehouse==null?"":tm.warehouse.wh_name%>';
                $F("d_dep_id").value = '<%=tm.department==null?0:tm.department.dep_id%>';
                $F("d_dep_name").value = '<%=tm.department==null?"":tm.department.dep_name%>';
            <%} %>
            //如果辅计量单位为空
            if($F("aunit").value == ""){
                $F('num').disabled = true;//禁止输件数
                $F('convert_rate').disabled = true;//禁止输换算率
            }
        }
        //改数量
        $F("quantity").onchange = function(){
            if(IsSpaceOrNaNOrZero($F('quantity').value)){
                $F('quantity').value = '';
                return;
            }
            //金额=单价*数量
            $F('total_price').value = ($F('quantity').value*$F('unit_price').value).toFixed(2);
            //含税金额=含税单价*数量
            $F('tax_total_price').value = ($F('tax_unit_price').value*$F('quantity').value).toFixed(2);
            //税额=含税金额-金额
            $F('tax').value = ($F('tax_total_price').value-$F('total_price').value).toFixed(2);
            //辅计单位不为空
            if($F('aunit').value != ""){
                //如果件数不为空
                if($F('num').value != ""){
                    //换算率=数量/件数
                    $F('convert_rate').value = ($F('quantity').value/$F('num').value).toFixed(dgt_exch);
                }
                //如果换算率不为空但件数为空
                if($F('convert_rate').value != "" && $F('num').value == ""){
                    //件数=数量/换算率
                    $F('num').value = ($F('quantity').value/$F('convert_rate').value).toFixed(dgt_num);
                }
            }
            compute_zhe_kou();//算折扣金额
            compute_nat();//算外币
        }
        //改件数
        $F("num").onchange = function(){
            if(IsSpaceOrNaNOrZero($F('num').value)){
                $F('num').value = '';
                return;
            }
            if($F('num').value != "" && $F('convert_rate').value != "" && $F('aunit').value != ""){
                //数量=换算率*件数
                $F('quantity').value = ($F('convert_rate').value*$F('num').value).toFixed(dgt_quan);
                //金额=单价*数量
                $F('total_price').value = ($F('unit_price').value*$F('quantity').value).toFixed(2);
                //含税金额=含税单价*数量
                $F('tax_total_price').value = ($F('tax_unit_price').value*$F('quantity').value).toFixed(2);
                //税金=含税金额-金额
                $F('tax').value = ($F('tax_total_price').value-$F('total_price').value).toFixed(2);
                compute_zhe_kou();//算折扣金额
                compute_nat();//算外币
            }
        }
        //改换算率
        $F("convert_rate").onchange = function(){
            if(IsSpaceOrNaNOrZero($F('convert_rate').value)){
                $F('convert_rate').value = '';
                return;
            }
            if($F('num').value != "" && $F('convert_rate').value != "" && $F('aunit').value != ""){
                //数量=换算率*件数
                $F('quantity').value = ($F('convert_rate').value*$F('num').value).toFixed(dgt_quan);
                //金额=单价*数量
                $F('total_price').value = ($F('unit_price').value*$F('quantity').value).toFixed(2);
                //含税金额=含税单价*数量
                $F('tax_total_price').value = ($F('tax_unit_price').value*$F('quantity').value).toFixed(2);
                //税金=含税金额-金额
                $F('tax').value = ($F('tax_total_price').value-$F('total_price').value).toFixed(2);
                compute_zhe_kou();//算折扣金额
                compute_nat();//算外币
            }
        }
        //改无税单价
        $F("unit_price").onchange = function(){
            if(IsSpaceOrNaN($F('unit_price').value)){
                $F('unit_price').value = '';
                return;
            }
            if(IsSpaceOrNaN($F('d_tax_rate').value)){
                $F('d_tax_rate').value = '0';    
            }
            //含税单价=单价*(1+税率)
            $F('tax_unit_price').value = ($F('unit_price').value*(1+$F('d_tax_rate').value/100)).toFixed(dgt_pri);
            if(IsSpaceOrNaNOrZero($F('quantity').value)){
                return;
            }
            //金额=单价*数量
            $F('total_price').value = ($F('unit_price').value*$F('quantity').value).toFixed(2);
            //含税金额=含税单价*数量
            $F('tax_total_price').value = ($F('tax_unit_price').value*$F('quantity').value).toFixed(2);
            //税金=含税金额-金额
            $F('tax').value = ($F('tax_total_price').value-$F('total_price').value).toFixed(2);
            compute_zhe_kou();//算折扣金额
            compute_nat();//算外币
        }
        //改无税金额
        $F("total_price").onchange = function(){
            if(IsSpaceOrNaN($F('total_price').value)){
                $F('total_price').value = '';
                return;
            }
            if(IsSpaceOrNaNOrZero($F('quantity').value)){
                return;
            }
            if(IsSpaceOrNaN($F('d_tax_rate').value)){
                $F('d_tax_rate').value = '0';    
            }
            $F("total_price").value = JSRound($F("total_price").value,2);
            //无税单价=无税金额/数量
            $F('unit_price').value = ($F('total_price').value/$F('quantity').value).toFixed(dgt_pri);
            //含税金额=无税金额*(1+税率)
            $F('tax_total_price').value = ($F('total_price').value*(1+$F('d_tax_rate').value/100)).toFixed(2);
            //含税单价=含税金额/数量
            $F('tax_unit_price').value = ($F('tax_total_price').value/$F('quantity').value).toFixed(dgt_pri);
            //税额=含税金额-无税金额
            $F('tax').value = ($F('tax_total_price').value-$F('total_price').value).toFixed(2);
            compute_zhe_kou();//算折扣金额
            compute_nat();//算外币
        }
        //通过含税单价计算
        function count_tax_unit_price(){
            if(IsSpaceOrNaN($F('tax_unit_price').value)){
                $F('tax_unit_price').value = '';
                return;
            }
            if(IsSpaceOrNaN($F('d_tax_rate').value)){
                $F('d_tax_rate').value = '0';    
            }
            $F("tax_unit_price").value = JSRound($F("tax_unit_price").value,dgt_pri);
            //单价=含税单价/(1+税率)
            $F('unit_price').value = ($F('tax_unit_price').value/(1+$F('d_tax_rate').value/100)).toFixed(dgt_pri);
            if(IsSpaceOrNaNOrZero($F('quantity').value)){
                return;
            }
            //金额=单价x数量
            $F('total_price').value = ($F('unit_price').value*$F('quantity').value).toFixed(2);
            //含税金额=含税单价*数量
            $F('tax_total_price').value = ($F('tax_unit_price').value*$F('quantity').value).toFixed(2);
            //税金=含税金额-金额
            $F('tax').value = ($F('tax_total_price').value-$F('total_price').value).toFixed(2);
            compute_zhe_kou();//算折扣金额
            compute_nat();//算外币
        }
        //改变含税单价
        $F("tax_unit_price").onchange = function(){
            count_tax_unit_price();
        }
        //改含税金额
        $F("tax_total_price").onchange = function(){
            if(IsSpaceOrNaNOrZero($F('quantity').value)){
                return;
            }
            if(IsSpaceOrNaNOrZero($F('tax_total_price').value)){
                $F('tax_total_price').value = '';
                return;
            }
            if(IsSpaceOrNaN($F('d_tax_rate').value)){
                $F('d_tax_rate').value = '0';    
            }
            $F("tax_total_price").value = JSRound($F("tax_total_price").value,2);
            //含税单价=含税金额/数量
            $F('tax_unit_price').value = ($F('tax_total_price').value/$F('quantity').value).toFixed(dgt_pri);
            //无税金额=含税金额/(1+税率)
            $F('total_price').value = ($F('tax_total_price').value/(1+$F('d_tax_rate').value/100)).toFixed(2);
            //税额=含税金额-无税金额
            $F('tax').value = ($F('tax_total_price').value-$F('total_price').value).toFixed(2);
            //无税单价=无税金额/数量
            $F('unit_price').value = ($F('total_price').value/$F('quantity').value).toFixed(dgt_pri);
            compute_zhe_kou();//算折扣金额
            compute_nat();//算外币
        }
        //改税率
        $F("d_tax_rate").onchange = function(){
            if(IsSpaceOrNaN($F('d_tax_rate').value)){
                $F('d_tax_rate').value = '0';
                return;
            }
            if(IsSpaceOrNaNOrZero($F('quantity').value)){
                $F('quantity').value = '';
                return;
            }
            //单价=含税单价/(1+税率)
            $F('unit_price').value = ($F('tax_unit_price').value/(1+$F('d_tax_rate').value/100)).toFixed(dgt_pri);
            //金额=单价x数量
            $F('total_price').value = ($F('unit_price').value*$F('quantity').value).toFixed(2);
            //含税金额=含税单价*数量
            //$F('tax_total_price').value = ($F('tax_unit_price').value*$F('quantity').value).toFixed(2);
            //税金=含税金额-金额
            $F('tax').value = ($F('tax_total_price').value-$F('total_price').value).toFixed(2);
            compute_nat();//算外币
        }
        //改报价
        $F("quoted_price").onchange = function(){
            if($F('quoted_price').value == "" || $F('quoted_price').value==0 || isNaN($F('quoted_price').value)){
                return;
            }
            if($F('kl').value == "" || isNaN($F('kl').value)){
                $F('kl').value = "100";
            }
            //含税单价=报价*扣率
            $F('tax_unit_price').value = ($F('quoted_price').value*$F('kl').value/100).toFixed(dgt_pri);
            //单价=含税单价/(1+税率)
            $F('unit_price').value = ($F('tax_unit_price').value/(1+$F('d_tax_rate').value/100)).toFixed(dgt_pri);
            if(IsSpaceOrNaNOrZero($F('quantity').value)){
                $F('quantity').value = '';
                return;
            }
            //金额=单价x数量
            $F('total_price').value = ($F('unit_price').value*$F('quantity').value).toFixed(2);
            //含税金额=含税单价*数量
            $F('tax_total_price').value = ($F('tax_unit_price').value*$F('quantity').value).toFixed(2);
            //税金=含税金额-金额
            $F('tax').value = ($F('tax_total_price').value-$F('total_price').value).toFixed(2);
            compute_zhe_kou();//算折扣金额
            compute_nat();//算外币
        }
        //改折扣率
        $F("kl").onchange = function(){

            if($F('quoted_price').value == "" || $F('quoted_price').value==0 || isNaN($F('quoted_price').value)){
                return;
            }
            if($F('kl').value == "" || isNaN($F('kl').value)){
                $F('kl').value = "100";
            }
            //含税单价=报价*扣率
            $F('tax_unit_price').value = ($F('quoted_price').value*$F('kl').value/100).toFixed(dgt_pri);
            //单价=含税单价/(1+税率)
            $F('unit_price').value = ($F('tax_unit_price').value/(1+$F('d_tax_rate').value/100)).toFixed(dgt_pri);
            if(IsSpaceOrNaNOrZero($F('quantity').value)){
                $F('quantity').value = '';
                return;
            }
            //金额=单价x数量
            $F('total_price').value = ($F('unit_price').value*$F('quantity').value).toFixed(2);
            //含税金额=含税单价*数量
            $F('tax_total_price').value = ($F('tax_unit_price').value*$F('quantity').value).toFixed(2);
            //税金=含税金额-金额
            $F('tax').value = ($F('tax_total_price').value-$F('total_price').value).toFixed(2);
            compute_zhe_kou();//算折扣金额
            compute_nat();//算外币
        }
        //改折扣金额
        $F("zk").onchange = function(){
            if(IsSpaceOrNaNOrZero($F('quantity').value)){
                $F('quantity').value = '';
                return;
            }
            if($F('quoted_price').value == "" || $F('quoted_price').value==0 || isNaN($F('quoted_price').value)){
                return;
            }
            if($F('zk').value == "" || isNaN($F('zk').value)){
                $F('zk').value = "0";
            }
            //含税金额=报价*数量-折扣金额
            $F('tax_total_price').value = ($F('quoted_price').value*$F('quantity').value-$F('zk').value).toFixed(2);

            //含税单价=含税金额/数量
            $F('tax_unit_price').value = ($F('tax_total_price').value/$F('quantity').value).toFixed(dgt_pri);
            //无税金额=含税金额/(1+税率)
            $F('total_price').value = ($F('tax_total_price').value/(1+$F('d_tax_rate').value/100)).toFixed(2);
            //税额=含税金额-无税金额
            $F('tax').value = ($F('tax_total_price').value-$F('total_price').value).toFixed(2);
            //无税单价=无税金额/数量
            $F('unit_price').value = ($F('total_price').value/$F('quantity').value).toFixed(dgt_pri);

            //折扣率=含税金额/报价*数量
            $F('kl').value = ($F('tax_total_price').value/($F('quoted_price').value*$F('quantity').value)*100).toFixed(2);
            compute_nat();//算外币
        }
        //运算外币部分
        function compute_nat(){
            if(IsSpaceOrNaNOrZero($F('quantity').value)){
                $F('quantity').value = '';
                return;
            }
            //本币无税单价=单价*汇率
            $F('nat_unit_price').value = ($F('unit_price').value*exchange_rate).toFixed(dgt_pri);
	        //本币无税金额=金额*汇率
            $F('nat_total_price').value = ($F('total_price').value*exchange_rate).toFixed(2);
            //本币税额=税额*汇率
            $F('nat_tax').value = ($F('tax').value*exchange_rate).toFixed(2);
            //本币价税合计=含税金额*汇率
            $F('nat_tax_total_price').value = ($F('tax_total_price').value*exchange_rate).toFixed(2);
            //本币含税单价=本币含税金额/数量
            $F('nat_tax_unit_price').value = ($F('nat_tax_total_price').value/$F("quantity").value).toFixed(dgt_pri);
        }
        //运算折扣额
        function compute_zhe_kou(){
            if(IsSpaceOrNaNOrZero($F('quantity').value)){
                $F('quantity').value = '';
                return;
            }
            var quoted_price = $F('quoted_price');
            if(!isNaN(quoted_price.value) && quoted_price.value !="" && quoted_price.value !=0){
                //折扣金额=报价*数量-含税金额
                $F('zk').value = ($F('quoted_price').value*($F('quantity').value)-$F('tax_total_price').value).toFixed(2);
                //折扣率=含税金额/报价*数量
                $F('kl').value = ($F('tax_total_price').value/($F('quoted_price').value*$F('quantity').value)*100).toFixed(2);
            }else{
                $F('zk').value = "";
            }
            //报价金额=报价*数量
            $("#quoted_total_price").val(($("#quoted_price").val()*$("#quantity").val()).toFixed(2));
            //如果折扣是负数，与明销售金额大于报价
            if($F('zk').value<0){
                $F('zk').value = "";//让折扣金额为零
                $F('kl').value = "";//让扣率为空
            }
        }
        //弹出窗口_选择销售订单
        function AdvancedSearch_SalesOrders(keyword) {
            var order_rows_count = '<%=xview["order_rows_count"]%>';//表体总记录数
            var url = "../../Component/AdvancedSearch/SalesOrders_Select.aspx?keyword=" + escape(keyword)
                +"&do_id="+do_id+"&order_rows_count="+order_rows_count;
            parent.asyncbox.open({
                id: 'win_select',
                url: url,
                modal: true,
                width:800,
                height:500,
                title: '选择销售订单'
            });
        }
        //通过主键_获取销售订单明细
        function SearchService_SalesOrders(sos_id) {
            $.ajax({
                type: "POST",
                contentType: "application/json",
                url: '../../Sale/SalesOrder/SalesOrders_Service.asmx/Get',
                data: "{sos_id:'" + sos_id + "'}",
                dataType: 'json',
                success: function (result) {
                    $("#sos_id").val(result.d.sos_id);
                    $("#i_id").val(result.d.inventory.i_id);
                    $("#i_code").val(result.d.inventory.i_code);
                    $("#i_name").val(result.d.inventory.i_name);
                    $("#standard").val(result.d.inventory.standard);
                    $("#munit").val(result.d.inventory.munit);
                    $("#aunit").val(result.d.inventory.aunit);
                    $('#so_order_number').val(result.d.parent_object.order_number);//订单号
                    $('#order_quantity').val(result.d.quantity); //订单数
                    $('#quantity').val(result.d.quantity-result.d.acc_fh_quantity); //待发货数量
                    if($("#aunit").val() != ""){
                        $('#num').val(result.d.num-result.d.acc_fh_num); //待发货件数=订单件数-累发货件数
                        $('#convert_rate').val(result.d.convert_rate); //换算率
                        $F('num').disabled = false;//允许输件数
                        $F('convert_rate').disabled = false;//允许输换算率
                    }else{
                        $('#num').val(""); //清空件数
                        $('#convert_rate').val(""); //清空换算率
                        $F('num').disabled = true;//禁止输件数
                        $F('convert_rate').disabled = true;//禁止输换算率
                    }
                    if(result.d.inventory.on_batch == 1){
                        $("#batch").attr("disabled", false); //允许输批次
                        $("#trigger_batch").css("display","");
                    }else{
                        $("#batch").attr("disabled", true); //禁止输批次
                        $("#batch").val("");
                        $("#trigger_batch").css("display","none");
                    }
                    //子表自定义项
                    $("#d_sdefine1").val(result.d.d_sdefine1);
                    $("#d_sdefine2").val(result.d.d_sdefine2);
                    $("#d_sdefine3").val(result.d.d_sdefine3);
                    $("#d_sdefine4").val(result.d.d_sdefine4);
                    $("#d_sdefine5").val(result.d.d_sdefine5);
                    $("#d_ndefine1").val(result.d.d_ndefine1);
                    $("#d_ndefine2").val(result.d.d_ndefine2);
                    $("#d_ndefine3").val(result.d.d_ndefine3);
                    $("#d_ndefine4").val(result.d.d_ndefine4);
                    $("#d_ndefine5").val(result.d.d_ndefine5);

                    $("#inventory_photo_view").attr("src", result.d.inventory.inventory_photo.small_pic_url);
                    $("#inventory_photo_view_href").attr("href", result.d.inventory.inventory_photo.pic_url);
                    //无税单价=订单无税单价
                    $("#unit_price").val(result.d.unit_price);
                    //含税单价=订单含税单价
                    $("#tax_unit_price").val(result.d.tax_unit_price);
                    //税率
                    $('#d_tax_rate').val(result.d.d_tax_rate)
                    //含税金额=含税单价*数量
                    $("#tax_total_price").val(JSRound($("#tax_unit_price").val()*$('#quantity').val(),2));
                    //通过无税金额=含税金额/(1+税率)
                    $("#total_price").val(JSRound($("#tax_total_price").val()/(1+$('#d_tax_rate').val()/100),2));
                    //税额=含税金额-无税金额
                    $("#tax").val($("#tax_total_price").val()-$("#total_price").val());
                    compute_zhe_kou();//算折扣金额
                    compute_nat();//算外币
                }
            });
        }
        //通过主键_获取存货
        //inventory_auto_search = false;//禁止输入自动搜索
        function SearchService_Inventory(i_id) {
            $.ajax({
                type: "POST",
                contentType: "application/json",
                url: '../../Base/Inventory/Inventory_Service.asmx/Get',
                data: "{i_id:'" + i_id + "'}",
                dataType: 'json',
                success: function (result) {
                    $("#i_id").val(result.d.i_id); //存货id
                    $("#i_code").val(result.d.i_code); //存货编码
                    $("#i_name").val(result.d.i_name); //存货名称
                    $("#standard").val(result.d.standard); //规格型号
                    $("#munit").val(result.d.munit); //主单位
                    $("#aunit").val(result.d.aunit); //辅计量单位
                    if ($("#aunit").val() == "") {//如果辅计量单位不为空
                        $("#num").attr("disabled", true); //禁止输件数
                        $("#num").val(""); //清空件数
                        $("#convert_rate").attr("disabled", true); //禁止输换算率
                        $("#convert_rate").val(""); //清空换算率
                    } else {
                        $("#convert_rate").val(result.d.convert_rate); //辅计量单位
                        $("#num").attr("disabled", false); //允许输件数
                        $("#convert_rate").attr("disabled", false); //允许输换算率
                    }
                    if(result.d.on_batch == 1){
                        $("#batch").attr("disabled", false); //允许输批次
                        $("#trigger_batch").css("display","");
                    }else{
                        $("#batch").attr("disabled", true); //禁止输批次
                        $("#batch").val("");
                        $("#trigger_batch").css("display","none");
                    }
                    var small_pic_url = result.d.inventory_photo.small_pic_url; //缩略图
                    if (small_pic_url != null) {
                        $("#inventory_photo_view").attr("src", result.d.inventory_photo.small_pic_url);
                    }
                    var pic_url = result.d.inventory_photo.pic_url; //原图
                    if (pic_url != null) {
                        $("#inventory_photo_view_href").attr("href", result.d.inventory_photo.pic_url);
                    }
                    $("#d_inv_sdefine1").val(result.d.sdefine1); //存货字符自定义项1
                    $("#d_inv_sdefine2").val(result.d.sdefine2); //存货字符自定义项2
                    $("#d_inv_sdefine3").val(result.d.sdefine3); //存货字符自定义项3
                    $("#d_inv_sdefine4").val(result.d.sdefine4); //存货字符自定义项4
                    $("#d_inv_sdefine5").val(result.d.sdefine5); //存货字符自定义项5
                    $("#d_inv_ndefine1").val(result.d.ndefine1); //存货数值自定义项1
                    $("#d_inv_ndefine2").val(result.d.ndefine2); //存货数值自定义项2
                    $("#d_inv_ndefine3").val(result.d.ndefine3); //存货数值自定义项3
                    $("#d_inv_ndefine4").val(result.d.ndefine4); //存货数值自定义项4
                    $("#d_inv_ndefine5").val(result.d.ndefine5); //存货数值自定义项5
                    //最新报价
                    $("#quoted_price").val(result.d.new_tax_unit_price);
                    $("#tax_unit_price").val(result.d.new_tax_unit_price);
                    if($("#kl").val()!=""){
                        //如果有扣率，选存货后自动计算扣后单价
                        var zh_tax_unit_price = ($("#tax_unit_price").val()*$("#kl").val()/100).toFixed(dgt_pri);;
                        $("#tax_unit_price").val(zh_tax_unit_price);
                    }
                    $("#quantity").val("1");//为适应零售功能，数量默认为1
                    count_tax_unit_price();
                    compute_zhe_kou();//算折扣金额
                    compute_nat();//算外币
                    //默认选中数量，方便修改
                    $("#quantity").focus();
                    $("#quantity").select();
                }
            });
        }
        //页面JS脚本
        <%=xview["DeliveryOrders_Edit_JavaScript"]%>
        
        //页面加载完毕事件
        $(document).ready(function(){
            init_page();
            $F("i_code").focus();//存货编码设置焦点
            //在存货编码回车自动带出信息
            $F("i_code").onkeydown = function (evt) {
                evt = evt ? evt : (window.event ? window.event : null);
                if (evt.keyCode == "13") {
                    var i_id = SearchService_InventoryByCode($F("i_code").value);
                }
            }
        });
    </script>
</asp:Content>

