duhe
2025-09-15 adebb0660a3414da01ca04e44bd6be4e23e1c664
WebTM/views/²É¹º¹ÜÀí/Ó¦¸¶µ¥/Cg_PayableBill.html
@@ -45,8 +45,10 @@
                <form class="layui-form" lay-filter="component-form-group" action="">
                    <div class="layui-card-header">
                        <div class="layui-btn-group">
                            <button type="button" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="set_AddNew" id="set_AddNew">新增</button>
                            <button type="button" id="set_SaveBill" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="Saver">保存</button>
                            <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="set_CheckBill">审核</button>
                            <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="set_SelectMainBill">选整单</button>
                            <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="Exit">退出</button>
                        </div>
                    </div>
@@ -54,7 +56,9 @@
                        <h1 style="text-align: center; padding: 10px 0;"><b>应付单</b></h1>
                        <ul class="layui-tab-title" lay-filter="tab-all">
                            <li lay-id="1" style="padding:1px;" class="layui-this">基本信息</li>
                            <li lay-id="2" style="padding:1px;">制单信息</li>
                            <li lay-id="2" style="padding:1px;">其他信息</li>
                            <li lay-id="3" style="padding:1px;">制单信息</li>
                        </ul>
                        <div class="layui-tab-content">
                            <!--基本信息-->
@@ -81,9 +85,9 @@
                                                    <!--动态渲染源单类型-->
                                                </select>
                                                <!--<select name="BillType" id="BillType" lay-filter="BillType" style="width: 180px; ">
                                                    <option style="color:blue;" selected="selected" value="1102">采购订单</option>
                                                    <option style="color:blue;" value="1201">采购入库单</option>
                                                </select>-->
                            <option style="color:blue;" selected="selected" value="1102">采购订单</option>
                            <option style="color:blue;" value="1201">采购入库单</option>
                        </select>-->
                                            </div>
                                        </div>
                                        <div class="layui-inline">
@@ -92,7 +96,7 @@
                                                <input type="hidden" name="HMainSourceInterID" id="HMainSourceInterID" class="layui-input" value="0" style="float:left;width:150px;">
                                                <input type="hidden" name="HMainSourceEntryID" id="HMainSourceEntryID" class="layui-input" value="0" style="float:left;width:150px;">
                                                <input type="hidden" name="HMainSourceBillType" id="HMainSourceBillType" class="layui-input" value="" style="float:left;width:150px;">
                                                <input type="text" name="HMainSourceBillNo" id="HMainSourceBillNo" class="layui-input" value="" style="float: left; width: 150px; background-color: #efefef4d;" readonly>
                                                <input type="text" name="HMainSourceBillNo" id="HMainSourceBillNo" class="layui-input" value="" style="float: left; width: 150px; " readonly>
                                                <button type="button" lay-submit="" class="layui-btn" lay-filter="HMainSource" style="width:40px;">
                                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="margin-left:-9px;"></i>
                                                </button>
@@ -100,14 +104,14 @@
                                        </div>
                                    </div>
                                    <div class="layui-row">
                                        <div class="layui-inline"style="width:625px">
                                        <div class="layui-inline" >
                                            <label class="layui-form-label">供应商<label style="color:red"> * </label></label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="HSupName" id="HSupName" class="layui-input" value="" style="background-color: #efefef4d; width: 505px" readonly>
                                                <input type="hidden" name="HSupID" id="HSupID" class="layui-input" value="0" style="float: left; width: 505px;">
                                                <input type="text" name="HSupName" id="HSupName" class="layui-input" value="" style="background-color: #efefef4d; width: 150px" readonly>
                                                <input type="hidden" name="HSupID" id="HSupID" class="layui-input" value="0" style="float: left; width: 150px;">
                                                <!--<button type="button" lay-submit="" class="layui-btn" lay-filter="HSupList" style="width:40px;">
                                                        <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="margin-left:-9px;"></i>
                                                    </button>-->
                <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="margin-left:-9px;"></i>
            </button>-->
                                            </div>
                                        </div>
                                        <div class="layui-inline">
@@ -121,7 +125,7 @@
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">业务员<label style="color:red"> * </label></label>
                                            <label class="layui-form-label">业务员</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="HEmpName" id="HEmpName" class="layui-input" value="" style="background-color: #efefef4d; float: left; width: 150px;" readonly>
                                                <input type="hidden" name="HEmpID" id="HEmpID" class="layui-input" value="0" style="float:left;width:150px;">
@@ -130,26 +134,8 @@
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-row">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">币别<label style="color:red"> * </label></label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="HCurName" id="HCurName" class="layui-input" value="" style="background-color: #efefef4d; float: left; width: 150px;" readonly>
                                                <input type="hidden" name="HCurID" id="HCurID" class="layui-input" value="0" style="float:left;width:150px;">
                                                <button type="button" lay-submit="" class="layui-btn" lay-filter="HCurList" style="width:40px;">
                                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="margin-left:-9px;"></i>
                                                </button>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">汇率<label style="color:red"> * </label></label>
                                            <div class="layui-input-inline">
                                                <input class="layui-input" name="HExRate" id="HExRate" autocomplete="off" value="0" style="background-color: #efefef4d;" readonly>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">采购方式<label style="color:red"> * </label></label>
                                            <label class="layui-form-label">采购方式</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="HPSStyleName" id="HPSStyleName" class="layui-input" value="" style="background-color: #efefef4d; float: left; width: 150px;" readonly>
                                                <input type="hidden" name="HPSStyleID" id="HPSStyleID" class="layui-input" value="0" style="float:left;width:150px;">
@@ -158,17 +144,8 @@
                                                </button>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">结算方式<label style="color:red"> * </label></label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="HSSName" id="HSSName" class="layui-input" value="" style="background-color: #efefef4d; float: left; width: 150px;" readonly>
                                                <input type="hidden" name="HSSID" id="HSSID" class="layui-input" value="0" style="float:left;width:150px;">
                                                <button type="button" lay-submit="" class="layui-btn" lay-filter="HSSList" style="width:40px;">
                                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="margin-left:-9px;"></i>
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-row">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">主管</label>
@@ -180,10 +157,24 @@
                                                </button>
                                            </div>
                                        </div>
                                        <div class="layui-inline" style="">
                                            <label class="layui-form-label">发票编号</label>
                                            <div class="layui-input-inline" style="background-color: #efefef4d; float: left; width: 150px;">
                                                <input class="layui-input" name="HInvoiceBillNo" id="HInvoiceBillNo" autocomplete="off">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">付款日期<label style="color:red"> * </label></label>
                                            <div class="layui-input-block">
                                                <input type="date" class="layui-input" lay-verify="HReceiveDate" name="HReceiveDate" id="HReceiveDate" style="width:190px;">
                                            <label class="layui-form-label">项目名称</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="HProjectName" id="HProjectName" class="layui-input" value="" style="float: left; width: 150px; background-color: #efefef4d;" readonly>
                                                <input type="hidden" name="HProjectID" id="HProjectID" class="layui-input" value="0" style="float: left; width: 150px; background-color: #efefef4d;">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">项目编码</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="HProjectNumber" id="HProjectNumber" class="layui-input" value="" style="float: left; width: 150px; background-color: #efefef4d;" readonly>
                                            </div>
                                        </div>
                                    </div>
@@ -192,16 +183,6 @@
                                            <label class="layui-form-label">备注</label>
                                            <div class="layui-input-block">
                                                <input class="layui-input" name="HRemark" id="HRemark" autocomplete="off" style="width: 1135px;">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-row" style="margin-top:10px;">
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 85px;">组织<label style="color:red"> * </label></label>
                                            <div class="layui-input-block" style="margin-left: 120px; width: 501px;">
                                                <select name="HOrgID" id="HOrgID" lay-verify="HOrgID">
                                                    <!--动态渲染组织-->
                                                </select>
                                            </div>
                                        </div>
                                    </div>
@@ -227,6 +208,59 @@
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!--其他信息-->
                            <div class="layui-tab-item">
                                <div class="layui-form-item" style="padding-top: 10px;">
                                    <div class="layui-row">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">结算方式</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="HSSName" id="HSSName" class="layui-input" value="" style="background-color: #efefef4d; float: left; width: 150px;" readonly>
                                                <input type="hidden" name="HSSID" id="HSSID" class="layui-input" value="0" style="float:left;width:150px;">
                                                <button type="button" lay-submit="" class="layui-btn" lay-filter="HSSList" style="width:40px;">
                                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="margin-left:-9px;"></i>
                                                </button>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">付款日期<label style="color:red"> * </label></label>
                                            <div class="layui-input-block">
                                                <input type="date" class="layui-input" lay-verify="HReceiveDate" name="HReceiveDate" id="HReceiveDate" style="width:190px;">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">币别<label style="color:red"> * </label></label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="HCurName" id="HCurName" class="layui-input" value="" style="background-color: #efefef4d; float: left; width: 150px;" readonly>
                                                <input type="hidden" name="HCurID" id="HCurID" class="layui-input" value="0" style="float:left;width:150px;">
                                                <button type="button" lay-submit="" class="layui-btn" lay-filter="HCurList" style="width:40px;">
                                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="margin-left:-9px;"></i>
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-row">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">汇率<label style="color:red"> * </label></label>
                                            <div class="layui-input-inline">
                                                <input class="layui-input" name="HExRate" id="HExRate" autocomplete="off" value="0" style="background-color: #efefef4d;" readonly>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-row" style="margin-top:10px;">
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 85px;">组织<label style="color:red"> * </label></label>
                                            <div class="layui-input-block" style="margin-left: 120px; width: 501px;">
                                                <select name="HOrgID" id="HOrgID" lay-verify="HOrgID">
                                                    <!--动态渲染组织-->
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!--制单信息-->
@@ -305,20 +339,38 @@
                        </div>
                    </div>
                    <table class="layui-hide" id="mainTable" lay-filter="mainTable"></table>
                    <script type="text/html" id="toolbarDemo">
                        <div class="layui-btn-container">
                            <button type="button" class="layui-btn layui-btn-sm" lay-event="btn-AddLine"><i class="layui-icon layui-icon-form"></i>增加一行</button>
                            <button type="button" class="layui-btn layui-btn-sm" lay-event="btn-InsertLine"><i class="layui-icon layui-icon-form"></i>插入一行</button>
                            <button type="button" class="layui-btn layui-btn-sm" lay-event="btn-CopyLine"><i class="layui-icon layui-icon-form"></i>复制一行</button>
                            <button type="button" class="layui-btn layui-btn-sm" lay-event="btn-Up"><i class="layui-icon layui-icon-form"></i>上移</button>
                            <button type="button" class="layui-btn layui-btn-sm" lay-event="btn-Under"><i class="layui-icon layui-icon-form"></i>下移</button>
                            <button type="button" class="layui-btn layui-btn-sm" lay-event="set_HideColumn"><i class="layui-icon layui-icon-form"></i>列设置</button>
                    <div class="layui-tab" lay-filter="tab-POStockInBill">
                        <ul class="layui-tab-title" lay-filter="tab-all">
                            <li style="padding:1px;" class="layui-this">汇总表格</li>
                            <li style="padding:1px;">明细表格</li>
                        </ul>
                        <div class="layui-tab-content">
                            <div class="layui-tab-item layui-show">
                                <table class="layui-hide" id="mainTable" lay-filter="mainTable"></table>
                                <script type="text/html" id="toolbarDemo">
                                    <div class="layui-btn-container">
                                        {{# if(haveSource == false){ }}
                                        <button type="button" class="layui-btn layui-btn-sm" lay-event="btn-AddLine"><i class="layui-icon layui-icon-form"></i>增加一行</button>
                                        <button type="button" class="layui-btn layui-btn-sm" lay-event="btn-InsertLine"><i class="layui-icon layui-icon-form"></i>插入一行</button>
                                        <button type="button" class="layui-btn layui-btn-sm" lay-event="btn-CopyLine"><i class="layui-icon layui-icon-form"></i>复制一行</button>
                                        <button type="button" class="layui-btn layui-btn-sm" lay-event="btn-Up"><i class="layui-icon layui-icon-form"></i>上移</button>
                                        <button type="button" class="layui-btn layui-btn-sm" lay-event="btn-Under"><i class="layui-icon layui-icon-form"></i>下移</button>
                                        {{# } }}
                                        <button type="button" class="layui-btn layui-btn-sm" lay-event="get_Inventory" id="get_Inventory"><i class="layui-icon layui-icon-form"></i>库存查询</button>
                                        <button type="button" class="layui-btn layui-btn-sm" lay-event="get_InOutSum" id="get_InOutSum"><i class="layui-icon layui-icon-form"></i>出入库记录查询</button>
                                        <button type="button" class="layui-btn layui-btn-sm" lay-event="set_HideColumn"><i class="layui-icon layui-icon-form"></i>列设置</button>
                                    </div>
                                </script>
                                <script type="text/html" id="xuhao">
                                    {{d.LAY_TABLE_INDEX+1}}
                                </script>
                            </div>
                            <div class="layui-tab-item">
                                <table class="layui-hide" id="mainTableEntry" lay-filter="mainTableEntry"></table>
                            </div>
                        </div>
                    </script>
                    <script type="text/html" id="xuhao">
                        {{d.LAY_TABLE_INDEX+1}}
                    </script>
                    </div>
                </form>
            </div>
        </div>
@@ -330,6 +382,8 @@
    <script>
        //#region æŠ˜å æ³¨é‡Š
        //#endregion
        //是否有源单
        var haveSource = false;
        layui.config({
            base: '../../../layuiadmin/' //静态资源所在路径
        }).extend({
@@ -346,14 +400,15 @@
            var allVal;
            var HModName = "Cg_PayableBill";
            var topScroll = 0;//记录滚动条的位置
            //记录组织的值
            var HOrgIDBar = 0;
            //子表渲染参数
            var option = {};
            var optionEntry = {};
            //#endregion
            //#region è¿›å…¥é¡µé¢å³åŠ è½½
@@ -439,9 +494,22 @@
            })
            //#endregion
            //#region æ–°å¢ž
            form.on('submit(set_AddNew)', function (data) {
                const url = new URL(location.href);
                location.href = url.origin + url.pathname;
            });
            //#endregion
            //#region å®¡æ ¸æŒ‰é’®
            form.on('submit(set_CheckBill)', function (data) {
                set_CheckBill(0);
            });
            //#endregion
            //#region é€‰æ•´å•
            form.on('submit(set_SelectMainBill)', function (data) {
                set_SelectMainBill();
            });
            //#endregion
@@ -554,6 +622,254 @@
            });
            //#endregion
            //#region å›žè½¦é€‰æ‹©æºå•
            $('#HMainSourceBillNo').on('keydown', function (event) {
                var HSourceBillNo = $('#HMainSourceBillNo').val();//(源单单据号)
                if (event.keyCode == 13) {
                    var ajaxLoad = layer.load();
                    var url;
                    //判断文本框是否有数据    new
                    if (HSourceBillNo == "") {
                        layer.close(ajaxLoad);
                        return;
                    }
                    if ($("#BillType").val() == "1102") {
                        //源单类型是采购订单
                        url = "/Cg_POOrderBill/PushList";
                    } else if ($("#BillType").val() == "1201") {
                        //源单类型是收料通知单
                        url = "/Kf_POStockInBill/PushList";
                    }
                    $.ajax({
                        url: GetWEBURL() + url,
                        type: "GET",
                        data: { "HBillNo": HSourceBillNo, "user": sessionStorage["HUserName"] },
                        success: function (result) {
                            if (result.code == 1) { // è¯´æ˜ŽéªŒè¯æˆåŠŸäº†ï¼Œ
                                var dataArray = result.data;
                                if ($("#BillType").val() == "1102") {
                                    form.val("component-form-group", { //formTest å³ class="layui-form" æ‰€åœ¨å…ƒç´ å±žæ€§ lay-filter="" å¯¹åº”的值
                                        "HMainSourceInterID": "0"
                                        , "HMainSourceEntryID": "0"
                                        /*, "HMainSourceBillNo": ""*/
                                        , "HMainSourceBillType": $("#BillType").val()
                                        , "HDeptID": dataArray[0].HDeptID
                                        , "HDeptName": dataArray[0].部门
                                        , "HMangerID": dataArray[0].HManagerID
                                        , "HMangerName": dataArray[0].主管
                                        , "HEmpID": dataArray[0].HEmpID
                                        , "HEmpName": dataArray[0].业务员
                                        , "HSupID": dataArray[0].HSupID
                                        , "HSupName": dataArray[0].供应商
                                        , "HCurID": dataArray[0].HCurID
                                        , "HCurName": dataArray[0].币别
                                        , "HExRate": dataArray[0].汇率
                                        , "HSSID": dataArray[0].HSSID
                                        , "HSSName": dataArray[0].结算方式
                                        , "HPSStyleID": dataArray[0].HPSStyleID
                                        , "HPSStyleName": dataArray[0].采购方式
                                        , "HProjectID": dataArray[0].HProjectID
                                        , "HProjectName": dataArray[0].项目名称
                                        , "HProjectNumber": dataArray[0].项目代码
                                    });
                                    //子表Entry  èµ‹å€¼
                                    var rowdataEntry = [];
                                    for (var i = 0; i < dataArray.length; i++) {
                                        var HQty = dataArray[i].数量 - dataArray[i].关联数量;                           //数量
                                        var HPrice = dataArray[i].单价;               //单价
                                        var HMoney = HQty * HPrice;                     //金额=数量*单价
                                        var HTaxRate = dataArray[i].税率 * 0.01;           //税率
                                        var HTaxMoney = Number((HMoney * HTaxRate));         //税额=金额*税率
                                        var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                                        var HExRate = $("#HExRate").val();                      //汇率
                                        var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate));      //本位币价税合计=(税额+金额)*汇率
                                        var HMoneyBB = HMoney * HExRate;
                                        rowdataEntry.push(
                                            {
                                                "HMaterID": dataArray[i].HMaterID
                                                , "物料代码": dataArray[i].物料代码
                                                , "物料名称": dataArray[i].物料名称
                                                , "规格型号": dataArray[i].规格型号
                                                , "HUnitID": dataArray[i].HUnitID
                                                , "计量单位": dataArray[i].计量单位
                                                , "HQty": dealDoubleToFixed(HQty, 1)
                                                , "HPrice": dealDoubleToFixed(dataArray[i].单价, 3)
                                                , "HTaxPrice": dealDoubleToFixed(dataArray[i].含税单价, 3)
                                                , 'HDiscountRate': "1"                                                     //
                                                , 'HRelTaxPrice': dealDoubleToFixed(dataArray[i].含税单价, 3)
                                                , "HTaxRate": dataArray[i].税率
                                                , 'HTaxMoney': HTaxMoney                                                         //
                                                , "HMoney": dealDoubleToFixed(HMoney, 2)
                                                , 'HMoneyBB': dealDoubleToFixed(HMoneyBB, 2)
                                                , 'HlineTotal': dealDoubleToFixed(HlineTotal, 2)
                                                , 'HlineTotalBB': dealDoubleToFixed(HlineTotalBB, 2)
                                                , "HRemark": ""
                                                , "HSourceInterID": dataArray[i].hmainid
                                                , "HSourceEntryID": dataArray[i].hsubid
                                                , "HSourceBillNo": dataArray[i].单据号
                                                , "HSourceBillType": dataArray[i].单据类型
                                                , "HRelationQty": "0"
                                                , "HRelationMoney": "0"
                                                , 'HPOOrderInterID': "0"
                                                , 'HPOOrderEntryID': "0"
                                                , 'HPOOrderBillNo': ""
                                                , 'HSeOrderTaxPrice': dealDoubleToFixed(dataArray[i].含税单价, 3)
                                                , "HSeOrderInterID": dataArray[i].hmainid
                                                , "HSeOrderEntryID": dataArray[i].hsubid
                                                , "HSeOrderBillNo": dataArray[i].单据号
                                            }
                                        );
                                    }
                                    optionEntry.data = JSON.parse(JSON.stringify(rowdataEntry));
                                    table.render(optionEntry);
                                    //子表汇总
                                    for (var i = 0; i < rowdataEntry.length; i++) {
                                        var item = rowdataEntry[i];
                                        for (var j = i + 1; j < rowdataEntry.length; j++) {
                                            if (rowdataEntry[j].HMaterID == item.HMaterID) {
                                                rowdataEntry[i].HQty += rowdataEntry[j].HQty;//数量
                                                rowdataEntry[i].HMoney += rowdataEntry[j].HMoney;//金额
                                                rowdataEntry[i].HPrice = rowdataEntry[i].HMoney / rowdataEntry[i].HQty;//单价
                                                //rowdataEntry[i].HMoney = rowdataEntry[i].HQty * rowdataEntry[i].HPrice//金额=数量*单价
                                                rowdataEntry[i].HTaxMoney = Number((rowdataEntry[i].HMoney * rowdataEntry[i].HTaxRate).toFixed(4))//税额
                                                rowdataEntry[i].HlineTotal = rowdataEntry[i].HMoney + rowdataEntry[i].HTaxMoney //价税合计
                                                var HExRate = $("#HExRate").val();
                                                rowdataEntry[i].HlineTotalBB = Number(((rowdataEntry[i].HMoney + rowdataEntry[i].HTaxMoney) * HExRate).toFixed(4)) //本位币价税合计
                                                rowdataEntry[i].HMoneyBB = Number((rowdataEntry[i].HMoney * HExRate).toFixed(4)) //本位币金额
                                                rowdataEntry.splice(j, 1);
                                                j = j - 1;
                                            }
                                        }
                                    }
                                    set_InitGridHaveSource();
                                    option.data = rowdataEntry;
                                } else if ($("#BillType").val() == "1201") {
                                    form.val("component-form-group", { //formTest å³ class="layui-form" æ‰€åœ¨å…ƒç´ å±žæ€§ lay-filter="" å¯¹åº”的值
                                        "HMainSourceInterID": "0"
                                        , "HMainSourceEntryID": "0"
                                        /*, "HMainSourceBillNo": ""*/
                                        , "HMainSourceBillType": $("#BillType").val()
                                        , "HDeptID": dataArray[0].HDeptID
                                        , "HDeptName": dataArray[0].部门
                                        , "HMangerID": dataArray[0].hmanagerid == null ? "0" : dataArray[0].hmanagerid
                                        , "HMangerName": dataArray[0].主管
                                        , "HEmpID": dataArray[0].HEmpID
                                        , "HEmpName": dataArray[0].业务员
                                        , "HSupID": dataArray[0].HSupID
                                        , "HSupName": dataArray[0].供应商
                                        , "HCurID": dataArray[0].HCurID
                                        , "HCurName": dataArray[0].币别
                                        , "HExRate": dataArray[0].汇率
                                        , "HSSID": "0"
                                        , "HSSName": ""
                                        , "HPSStyleID": dataArray[0].HPSStyleID
                                        , "HPSStyleName": dataArray[0].采购方式
                                        , "HProjectID": dataArray[0].HProjectID
                                        , "HProjectName": dataArray[0].项目名称
                                        , "HProjectNumber": dataArray[0].项目代码
                                        , "HInvoiceBillNo": dataArray[0].发票编号
                                    });
                                    //子表Entry  èµ‹å€¼
                                    var rowdataEntry = [];
                                    for (var i = 0; i < dataArray.length; i++) {
                                        var HQty = dataArray[i].实收数量 - dataArray[i].关联数量;                           //数量
                                        var HPrice = dataArray[i].单价;               //单价
                                        var HMoney = HQty * HPrice;                     //金额=数量*单价
                                        var HTaxRate = dataArray[i].税率 * 0.01;           //税率
                                        var HTaxMoney = Number((HMoney * HTaxRate));         //税额=金额*税率
                                        var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                                        var HExRate = $("#HExRate").val();                      //汇率
                                        var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate));      //本位币价税合计=(税额+金额)*汇率
                                        var HMoneyBB = HMoney * HExRate;
                                        rowdataEntry.push(
                                            {
                                                "HMaterID": dataArray[i].HMaterID
                                                , "物料代码": dataArray[i].物料代码
                                                , "物料名称": dataArray[i].物料名称
                                                , "规格型号": dataArray[i].规格型号
                                                , "HUnitID": dataArray[i].HUnitID
                                                , "计量单位": dataArray[i].计量单位
                                                , "HQty": dealDoubleToFixed(HQty, 1)
                                                , "HPrice": dealDoubleToFixed(dataArray[i].单价, 3)
                                                , "HTaxPrice": dealDoubleToFixed(dataArray[i].含税单价, 3)
                                                , 'HDiscountRate': "1"                                                     //
                                                , 'HRelTaxPrice': dealDoubleToFixed(dataArray[i].含税单价, 3)
                                                , "HTaxRate": dataArray[i].税率
                                                , 'HTaxMoney': HTaxMoney                                                         //
                                                , "HMoney": dealDoubleToFixed(HMoney, 2)
                                                , 'HMoneyBB': dealDoubleToFixed(HMoneyBB, 2)
                                                , 'HlineTotal': dealDoubleToFixed(HlineTotal, 2)
                                                , 'HlineTotalBB': dealDoubleToFixed(HlineTotalBB, 2)
                                                , "HRemark": ""
                                                , "HSourceInterID": dataArray[i].hmainid
                                                , "HSourceEntryID": dataArray[i].hsubid
                                                , "HSourceBillNo": dataArray[i].单据号
                                                , "HSourceBillType": dataArray[i].单据类型
                                                , "HRelationQty": "0"
                                                , "HRelationMoney": "0"
                                                , 'HPOOrderInterID': "0"
                                                , 'HPOOrderEntryID': "0"
                                                , 'HPOOrderBillNo': ""
                                                // , 'HSeOrderTaxPrice': dealDoubleToFixed(dataArray[i].含税单价, 3)
                                                , "HSeOrderInterID": dataArray[i].HSourceBillType == "1401" ? dataArray[i].HSourceInterID : "0"
                                                , "HSeOrderEntryID": dataArray[i].HSourceBillType == "1401" ? dataArray[i].HSourceEntryID : "0"
                                                , "HSeOrderBillNo": dataArray[i].HSourceBillType == "1401" ? dataArray[i].源单单号 : ""
                                            }
                                        );
                                    }
                                    optionEntry.data = JSON.parse(JSON.stringify(rowdataEntry));
                                    table.render(optionEntry);
                                    //子表汇总
                                    for (var i = 0; i < rowdataEntry.length; i++) {
                                        var item = rowdataEntry[i];
                                        for (var j = i + 1; j < rowdataEntry.length; j++) {
                                            if (rowdataEntry[j].HMaterID == item.HMaterID) {
                                                rowdataEntry[i].HQty += rowdataEntry[j].HQty;
                                                rowdataEntry[i].HMoney += rowdataEntry[j].HMoney;//金额
                                                rowdataEntry[i].HPrice = rowdataEntry[i].HMoney / rowdataEntry[i].HQty;//单价
                                                rowdataEntry[i].HTaxMoney = Number((rowdataEntry[i].HMoney * rowdataEntry[i].HTaxRate).toFixed(4))//税额
                                                rowdataEntry[i].HlineTotal = rowdataEntry[i].HMoney + rowdataEntry[i].HTaxMoney //价税合计
                                                var HExRate = $("#HExRate").val();
                                                rowdataEntry[i].HlineTotalBB = Number(((rowdataEntry[i].HMoney + rowdataEntry[i].HTaxMoney) * HExRate).toFixed(4)) //本位币价税合计
                                                rowdataEntry[i].HMoneyBB = Number((rowdataEntry[i].HMoney * HExRate).toFixed(4)) //本位币金额
                                                rowdataEntry.splice(j, 1);
                                                j = j - 1;
                                            }
                                        }
                                    }
                                    set_InitGridHaveSource();
                                    option.data = rowdataEntry;
                                }
                                haveSource = true;
                                table.render(option);
                                layer.close(ajaxLoad);
                                layer.msg("查询成功", { time: 1 * 1000, icon: 1 });
                            } else {
                                layer.alert(result.Message, { icon: 5, btn: ['退出'], time: 100000, offset: 't' });
                                layer.close(ajaxLoad);
                            }
                        }, error: function () {
                            layer.alert(result.Message + "发生错误!", { icon: 5 });
                            layer.close(ajaxLoad);
                        }
                    });
                }
            });
            //#endregion
            //#endregion
            //#region å¤é€‰æ¡†çŠ¶æ€å˜æ›´
@@ -575,7 +891,7 @@
                    , "HQty": "0"
                    , "HPrice": "0"
                    , "HTaxPrice": "0"
                    , 'HDiscountRate': "0"
                    , 'HDiscountRate': "1"
                    , 'HRelTaxPrice': "0"
                    , "HTaxRate": "0"
                    , 'HTaxMoney': "0"
@@ -618,6 +934,12 @@
                    //下移
                    case 'btn-Under': btn_under();
                        break;
                    //库存查询
                    case 'get_Inventory': get_Inventory();
                        break;
                    //出入库记录查询
                    case 'get_InOutSum': get_InOutSum();
                        break;
                    //列设置
                    case 'set_HideColumn':
                        get_HideColumn();
@@ -633,19 +955,6 @@
            });
            //#endregion
            //#region ç›‘听单元格编辑  å•元格编辑后 å˜æ›´
            table.on('edit(mainTable)', function (obj) {
                //数值格式校验工具
                var ref = /^\d+(\.\d+)?$/;          //非负数正则表达式
                var temp = "";
                // å•元格编辑之前的值
                var oldText = $(this).prev().text();
                var value = obj.value //得到修改后的值
                    , data = obj.data //得到所在行所有键值
                    , field = obj.field; //得到字段
            });
            //#endregion
            //#endregion
            //#endregion
@@ -764,13 +1073,14 @@
            //#region å¼¹çª—选择方法
            //#region é€‰æ‹©é‡‡è´­éƒ¨é—¨
            function get_checkDept() {
                var HOrgName = $('select[name="HOrgID"] option:selected').text();
                layer.open({
                    type: 2//弹窗类型
                    , skin: 'layui-layer-rim' //加上边框
                    , area: ['90%', '90%']//大小
                    , title: '采购部门列表'//标题
                    , shift: 2//弹出动画
                    , content: ['../../基础资料/公用基础资料/Gy_DepartmentList.html', 'yes']
                    , content: ['../../基础资料/公用基础资料/Gy_DepartmentList.html?Type=2&HOrgName=' + HOrgName, 'yes']
                    , btn: ['确定', '取消']
                    , btn1: function (index, layero) {//按钮【按钮一】的回调
                        var iframeWindow = window['layui-layer-iframe' + index]  //获取弹框页面
@@ -789,13 +1099,14 @@
            //#region é€‰æ‹©é‡‡è´­ä¸»ç®¡
            function get_checkManager() {
                var HOrgID = $("#HOrgID").val();
                layer.open({
                    type: 2//弹窗类型
                    , skin: 'layui-layer-rim' //加上边框
                    , area: ['90%', '90%']//大小
                    , title: '采购主管列表'//标题
                    , shift: 2//弹出动画
                    , content: ['../../基础资料/公用基础资料/Gy_EmployeeList.html?Type=HManager', 'yes']
                    , content: ['../../基础资料/公用基础资料/Gy_EmployeeList.html?Type=HManager&HOrgID=' + HOrgID, 'yes']
                    , btn: ['确定', '取消']
                    , btn1: function (index, layero) {//按钮【按钮一】的回调
                        var iframeWindow = window['layui-layer-iframe' + index]  //获取弹框页面
@@ -814,13 +1125,14 @@
            //#region é€‰æ‹©ä¸šåŠ¡å‘˜
            function get_checkEmp() {
                var HOrgID = $("#HOrgID").val();
                layer.open({
                    type: 2//弹窗类型
                    , skin: 'layui-layer-rim' //加上边框
                    , area: ['90%', '90%']//大小
                    , title: '业务员列表'//标题
                    , shift: 2//弹出动画
                    , content: ['../../基础资料/公用基础资料/Gy_EmployeeList.html?Type=HEmp', 'yes']
                    , content: ['../../基础资料/公用基础资料/Gy_EmployeeList.html?Type=HEmp&HOrgID=' + HOrgID, 'yes']
                    , btn: ['确定', '取消']
                    , btn1: function (index, layero) {//按钮【按钮一】的回调
                        var iframeWindow = window['layui-layer-iframe' + index]  //获取弹框页面
@@ -852,13 +1164,14 @@
            //#region é€‰æ‹©é‡‡è´­æ–¹å¼
            function get_checkSellS() {
                var HOrgName = $('select[name="HOrgID"] option:selected').text();
                layer.open({
                    type: 2//弹窗类型
                    , skin: 'layui-layer-rim' //加上边框
                    , area: ['90%', '90%']//大小
                    , title: '采购方式列表'//标题
                    , shift: 2//弹出动画
                    , content: ['../../基础资料/公用基础资料/Gy_PoStockStyle.html', 'yes']
                    , content: ['../../基础资料/公用基础资料/Gy_PoStockStyle.html?Type=2&HOrgName=' + HOrgName, 'yes']
                    , btn: ['确定', '取消']
                    , btn1: function (index, layero) {//按钮【按钮一】的回调
                        var iframeWindow = window['layui-layer-iframe' + index]  //获取弹框页面
@@ -878,13 +1191,14 @@
            //#region ç»“算方式选择页面
            function get_checkSS() {
                var HOrgName = $('select[name="HOrgID"] option:selected').text();
                layer.open({
                    type: 2//弹窗类型
                    , skin: 'layui-layer-rim' //加上边框
                    , area: ['90%', '90%']//大小
                    , title: '结算方式列表'//标题
                    , shift: 2//弹出动画
                    , content: ['../../基础资料/基础资料/Gy_SettleStyle.html', 'yes']
                    , content: ['../../基础资料/基础资料/Gy_SettleStyle.html?Type=2&HOrgName=' + HOrgName, 'yes']
                    , btn: ['确定', '取消']
                    , btn1: function (index, layero) {//按钮【按钮一】的回调
                        var iframeWindow = window['layui-layer-iframe' + index]  //获取弹框页面
@@ -909,7 +1223,7 @@
                    , area: ['90%', '90%']//大小
                    , title: '采购币别列表'//标题
                    , shift: 2//弹出动画
                    , content: ['../../基础资料/公用基础资料/Gy_Currency.html', 'yes']
                    , content: ['../../基础资料/公用基础资料/Gy_Currency.html?Type=2', 'yes']
                    , btn: ['确定', '取消']
                    , btn1: function (index, layero) {//按钮【按钮一】的回调
                        var iframeWindow = window['layui-layer-iframe' + index]  //获取弹框页面
@@ -983,7 +1297,17 @@
                        if (checkStatus.data.length === 0) {
                            return layer.msg('请选择数据');
                        }
                        var HSupID = $("#HSupID").val();//判断供应商
                        if (HSupID == 0 || HSupID == '') {
                            HSupID = checkStatus.data[0]["HSupID"];
                        }
                        for (var i = 0; i < checkStatus.data.length; i++) {
                            if (checkStatus.data[i]["HSupID"] != HSupID) {
                                layer.msg("下推失败!已经选中的记录中存在不同供应商!");
                                layer.close(index);//关闭弹窗
                                return;
                            }
                        }
                        if ($("#BillType").val() == "1102") {
                            setInitByPOOrderBill(checkStatus);
                        }
@@ -998,6 +1322,318 @@
                })
            }
            //#endregion
            //#region é€‰æ•´å•
            function set_SelectMainBill() {
                var url;
                if ($("#BillType").val() == "1102") {
                    url = "../../采购管理/采购订单/Cg_POOrderBillQuery.html?openType=2&HOrgID=" + HOrgID;
                } else if ($("#BillType").val() == "1201") {
                    url = "../../验收入库/外购入库/Kf_POStockInBillListQuery.html?openType=2&HOrgID=" + HOrgID;
                } else {
                    return layer.msg('当前不支持该源单选择!!');
                }
                //页面层-自定义
                layer.open({
                    type: 2
                    , skin: "layui-layer-rim" //加上边框
                    , title: '' + '源单' + '列表'  //标题
                    , closeBtn: 1  //窗体右上角关闭 çš„ æ ·å¼
                    , shift: 2 //弹出动画
                    , area: ["90%", "90%"] //窗体大小
                    , maxmin: true //设置最大最小按钮是否显示
                    , content: [url, "yes"]
                    , btn: ["确定", "取消"]
                    , btn1: function (index, laero) {
                        //按钮一  çš„回调
                        var iframeWindow = window["layui-layer-iframe" + index];//获取弹框页面
                        var checkStatus = iframeWindow.layui.table.checkStatus("mainTable");//获取选中的数据
                        if (checkStatus.data.length == 0) {
                            return layer.msg("请至少选择一条数据!");
                        }
                        var HSupID = $("#HSupID").val();//判断供应商
                        if (HSupID == 0 || HSupID == '') {
                            HSupID = checkStatus.data[0]["HSupID"];
                        }
                        //获取供应商代码,设置条件
                        var sMainWhere = " and hmainid in(";
                        for (var i = 0; i < checkStatus.data.length; i++) {
                            if (checkStatus.data[i]["HSupID"] != HSupID) {
                                layer.msg("下推失败!已经选中的记录中存在不同供应商!");
                                layer.close(index);//关闭弹窗
                                return;
                            }
                            sMainWhere += checkStatus.data[i]["hmainid"]
                            if (i != checkStatus.data.length - 1) {
                                sMainWhere += ",";
                            } else {
                                sMainWhere += ") ";
                            }
                        }
                        getSeletMainInfo(sMainWhere);
                        layer.close(index);//关闭弹窗
                    }
                });
            }
            //#endregion
            //#region æ•´å•信息获取方法
            function getSeletMainInfo(sMainWhere) {
                var ajaxLoad = layer.load();
                if ($("#BillType").val() == "1102") {
                    $.ajax({
                        url: GetWEBURL() + '/Cg_POOrderBill/list',
                        async: false,
                        type: "GET",
                        data: { "sWhere": sMainWhere, "user": sessionStorage["HUserName"] },
                        success: function (data1) {
                            if (data1.count == 1) {
                                var dataArray = data1.data;
                                option.data = [];//清空子表
                                form.val("component-form-group", { //formTest å³ class="layui-form" æ‰€åœ¨å…ƒç´ å±žæ€§ lay-filter="" å¯¹åº”的值
                                    "HMainSourceInterID": "0"
                                    , "HMainSourceEntryID": "0"
                                    /*, "HMainSourceBillNo": ""*/
                                    , "HMainSourceBillType": $("#BillType").val()
                                    , "HDeptID": dataArray[0].HDeptID
                                    , "HDeptName": dataArray[0].部门
                                    , "HMangerID": dataArray[0].HManagerID
                                    , "HMangerName": dataArray[0].主管
                                    , "HEmpID": dataArray[0].HEmpID
                                    , "HEmpName": dataArray[0].业务员
                                    , "HSupID": dataArray[0].HSupID
                                    , "HSupName": dataArray[0].供应商
                                    , "HCurID": dataArray[0].HCurID
                                    , "HCurName": dataArray[0].币别
                                    , "HExRate": dataArray[0].汇率
                                    , "HSSID": dataArray[0].HSSID
                                    , "HSSName": dataArray[0].结算方式
                                    , "HPSStyleID": dataArray[0].HPSStyleID
                                    , "HPSStyleName": dataArray[0].采购方式
                                    , "HProjectID": dataArray[0].HProjectID
                                    , "HProjectName": dataArray[0].项目名称
                                    , "HProjectNumber": dataArray[0].项目代码
                                });
                                //子表Entry  èµ‹å€¼
                                var rowdataEntry = [];
                                for (var i = 0; i < dataArray.length; i++) {
                                    var HQty = dataArray[i].数量 - dataArray[i].关联数量;                           //数量
                                    var HPrice = dataArray[i].单价;               //单价
                                    var HMoney = HQty * HPrice;                     //金额=数量*单价
                                    var HTaxRate = dataArray[i].税率 * 0.01;           //税率
                                    var HTaxMoney = Number((HMoney * HTaxRate));         //税额=金额*税率
                                    var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                                    var HExRate = $("#HExRate").val();                      //汇率
                                    var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate));      //本位币价税合计=(税额+金额)*汇率
                                    var HMoneyBB = HMoney * HExRate;
                                    rowdataEntry.push(
                                        {
                                            "HMaterID": dataArray[i].HMaterID
                                            , "物料代码": dataArray[i].物料代码
                                            , "物料名称": dataArray[i].物料名称
                                            , "规格型号": dataArray[i].规格型号
                                            , "HUnitID": dataArray[i].HUnitID
                                            , "计量单位": dataArray[i].计量单位
                                            , "HQty": dealDoubleToFixed(HQty, 1)
                                            , "HPrice": dealDoubleToFixed(dataArray[i].单价, 3)
                                            , "HTaxPrice": dealDoubleToFixed(dataArray[i].含税单价, 3)
                                            , 'HDiscountRate': "1"                                                     //
                                            , 'HRelTaxPrice': dealDoubleToFixed(dataArray[i].含税单价, 3)
                                            , "HTaxRate": dataArray[i].税率
                                            , 'HTaxMoney': HTaxMoney                                                         //
                                            , "HMoney": dealDoubleToFixed(HMoney, 2)
                                            , 'HMoneyBB': dealDoubleToFixed(HMoneyBB, 2)
                                            , 'HlineTotal': dealDoubleToFixed(HlineTotal, 2)
                                            , 'HlineTotalBB': dealDoubleToFixed(HlineTotalBB, 2)
                                            , "HRemark": ""
                                            , "HSourceInterID": dataArray[i].hmainid
                                            , "HSourceEntryID": dataArray[i].hsubid
                                            , "HSourceBillNo": dataArray[i].单据号
                                            , "HSourceBillType": dataArray[i].单据类型
                                            , "HRelationQty": "0"
                                            , "HRelationMoney": "0"
                                            , 'HPOOrderInterID': "0"
                                            , 'HPOOrderEntryID': "0"
                                            , 'HPOOrderBillNo': ""
                                            , 'HSeOrderTaxPrice': dealDoubleToFixed(dataArray[i].含税单价, 3)
                                            , "HSeOrderInterID": dataArray[i].hmainid
                                            , "HSeOrderEntryID": dataArray[i].hsubid
                                            , "HSeOrderBillNo": dataArray[i].单据号
                                        }
                                    );
                                }
                                optionEntry.data = JSON.parse(JSON.stringify(rowdataEntry));
                                table.render(optionEntry);
                                //子表汇总
                                for (var i = 0; i < rowdataEntry.length; i++) {
                                    var item = rowdataEntry[i];
                                    for (var j = i + 1; j < rowdataEntry.length; j++) {
                                        if (rowdataEntry[j].HMaterID == item.HMaterID) {
                                            rowdataEntry[i].HQty += rowdataEntry[j].HQty;//数量
                                            rowdataEntry[i].HMoney += rowdataEntry[j].HMoney;//金额
                                            rowdataEntry[i].HPrice = rowdataEntry[i].HMoney / rowdataEntry[i].HQty;//单价
                                            rowdataEntry[i].HTaxMoney = Number((rowdataEntry[i].HMoney * rowdataEntry[i].HTaxRate).toFixed(4))//税额
                                            rowdataEntry[i].HlineTotal = rowdataEntry[i].HMoney + rowdataEntry[i].HTaxMoney //价税合计
                                            var HExRate = $("#HExRate").val();
                                            rowdataEntry[i].HlineTotalBB = Number(((rowdataEntry[i].HMoney + rowdataEntry[i].HTaxMoney) * HExRate).toFixed(4)) //本位币价税合计
                                            rowdataEntry[i].HMoneyBB = Number((rowdataEntry[i].HMoney * HExRate).toFixed(4)) //本位币金额
                                            rowdataEntry.splice(j, 1);
                                            j = j - 1;
                                        }
                                    }
                                }
                                set_InitGridHaveSource();
                                option.data = rowdataEntry;
                                haveSource = true;
                                table.render(option);
                                layer.close(ajaxLoad);
                                //layer.alert("查询成功", { icon: 1 });
                            } else {
                                layer.close(ajaxLoad);
                                layer.alert(data1.code + data1.Message, { icon: 5 });
                                return;
                            }
                        }, error: function () {
                            layer.close(ajaxLoad);
                            layer.alert("接口请求失败!", { icon: 5 });
                            return;
                        }
                    });
                } else if ($("#BillType").val() == "1201") {
                    $.ajax({
                        url: GetWEBURL() + '/Kf_POStockInBill/list',
                        type: "GET",
                        data: { "sWhere": sMainWhere, "user": sessionStorage["HUserName"] },
                        success: function (data1) {
                            if (data1.count == 1) {
                                dataArray = data1.data;
                                form.val("component-form-group", { //formTest å³ class="layui-form" æ‰€åœ¨å…ƒç´ å±žæ€§ lay-filter="" å¯¹åº”的值
                                    "HMainSourceInterID": "0"
                                    , "HMainSourceEntryID": "0"
                                    /*, "HMainSourceBillNo": ""*/
                                    , "HMainSourceBillType": $("#BillType").val()
                                    , "HDeptID": dataArray[0].HDeptID
                                    , "HDeptName": dataArray[0].部门
                                    , "HMangerID": dataArray[0].hmanagerid == null ? "0" : dataArray[0].hmanagerid
                                    , "HMangerName": dataArray[0].主管
                                    , "HEmpID": dataArray[0].HEmpID
                                    , "HEmpName": dataArray[0].业务员
                                    , "HSupID": dataArray[0].HSupID
                                    , "HSupName": dataArray[0].供应商
                                    , "HCurID": dataArray[0].HCurID
                                    , "HCurName": dataArray[0].币别
                                    , "HExRate": dataArray[0].汇率
                                    , "HSSID": "0"
                                    , "HSSName": ""
                                    , "HPSStyleID": dataArray[0].HPSStyleID
                                    , "HPSStyleName": dataArray[0].采购方式
                                    , "HProjectID": dataArray[0].HProjectID
                                    , "HProjectName": dataArray[0].项目名称
                                    , "HProjectNumber": dataArray[0].项目代码
                                    , "HInvoiceBillNo": dataArray[0].发票编号
                                });
                                //子表Entry  èµ‹å€¼
                                var rowdataEntry = [];
                                for (var i = 0; i < dataArray.length; i++) {
                                    var HQty = dataArray[i].实收数量 - dataArray[i].关联数量;                           //数量
                                    var HPrice = dataArray[i].单价;               //单价
                                    var HMoney = HQty * HPrice;                     //金额=数量*单价
                                    var HTaxRate = dataArray[i].税率 * 0.01;           //税率
                                    var HTaxMoney = Number((HMoney * HTaxRate));         //税额=金额*税率
                                    var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                                    var HExRate = $("#HExRate").val();                      //汇率
                                    var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate));      //本位币价税合计=(税额+金额)*汇率
                                    var HMoneyBB = HMoney * HExRate;
                                    rowdataEntry.push(
                                        {
                                            "HMaterID": dataArray[i].HMaterID
                                            , "物料代码": dataArray[i].物料代码
                                            , "物料名称": dataArray[i].物料名称
                                            , "规格型号": dataArray[i].规格型号
                                            , "HUnitID": dataArray[i].HUnitID
                                            , "计量单位": dataArray[i].计量单位
                                            , "HQty": dealDoubleToFixed(HQty, 1)
                                            , "HPrice": dealDoubleToFixed(dataArray[i].单价, 3)
                                            , "HTaxPrice": dealDoubleToFixed(dataArray[i].含税单价, 3)
                                            , 'HDiscountRate': "1"                                                     //
                                            , 'HRelTaxPrice': dealDoubleToFixed(dataArray[i].含税单价, 3)
                                            , "HTaxRate": dataArray[i].税率
                                            , 'HTaxMoney': HTaxMoney                                                         //
                                            , "HMoney": dealDoubleToFixed(HMoney, 2)
                                            , 'HMoneyBB': dealDoubleToFixed(HMoneyBB, 2)
                                            , 'HlineTotal': dealDoubleToFixed(HlineTotal, 2)
                                            , 'HlineTotalBB': dealDoubleToFixed(HlineTotalBB, 2)
                                            , "HRemark": ""
                                            , "HSourceInterID": dataArray[i].hmainid
                                            , "HSourceEntryID": dataArray[i].hsubid
                                            , "HSourceBillNo": dataArray[i].单据号
                                            , "HSourceBillType": dataArray[i].单据类型
                                            , "HRelationQty": "0"
                                            , "HRelationMoney": "0"
                                            , 'HPOOrderInterID': "0"
                                            , 'HPOOrderEntryID': "0"
                                            , 'HPOOrderBillNo': ""
                                            // , 'HSeOrderTaxPrice': dealDoubleToFixed(dataArray[i].含税单价, 3)
                                            , "HSeOrderInterID": dataArray[i].HSourceBillType == "1401" ? dataArray[i].HSourceInterID : "0"
                                            , "HSeOrderEntryID": dataArray[i].HSourceBillType == "1401" ? dataArray[i].HSourceEntryID : "0"
                                            , "HSeOrderBillNo": dataArray[i].HSourceBillType == "1401" ? dataArray[i].源单单号 : ""
                                        }
                                    );
                                }
                                optionEntry.data = JSON.parse(JSON.stringify(rowdataEntry));
                                table.render(optionEntry);
                                //子表汇总
                                for (var i = 0; i < rowdataEntry.length; i++) {
                                    var item = rowdataEntry[i];
                                    for (var j = i + 1; j < rowdataEntry.length; j++) {
                                        if (rowdataEntry[j].HMaterID == item.HMaterID) {
                                            rowdataEntry[i].HQty += rowdataEntry[j].HQty;
                                            rowdataEntry[i].HMoney += rowdataEntry[j].HMoney;//金额
                                            rowdataEntry[i].HPrice = rowdataEntry[i].HMoney / rowdataEntry[i].HQty;//单价
                                            rowdataEntry[i].HTaxMoney = Number((rowdataEntry[i].HMoney * rowdataEntry[i].HTaxRate).toFixed(4))//税额
                                            rowdataEntry[i].HlineTotal = rowdataEntry[i].HMoney + rowdataEntry[i].HTaxMoney //价税合计
                                            var HExRate = $("#HExRate").val();
                                            rowdataEntry[i].HlineTotalBB = Number(((rowdataEntry[i].HMoney + rowdataEntry[i].HTaxMoney) * HExRate).toFixed(4)) //本位币价税合计
                                            rowdataEntry[i].HMoneyBB = Number((rowdataEntry[i].HMoney * HExRate).toFixed(4)) //本位币金额
                                            rowdataEntry.splice(j, 1);
                                            j = j - 1;
                                        }
                                    }
                                }
                                set_InitGridHaveSource();
                                option.data = rowdataEntry;
                                haveSource = true;
                                table.render(option);
                                layer.close(ajaxLoad);
                            } else {
                                layer.close(ajaxLoad);
                                layer.alert(data1.code + data1.Message, { icon: 5 });
                                return;
                            }
                        }, error: function () {
                            layer.close(ajaxLoad);
                            layer.alert("接口请求失败!", { icon: 5 });
                            return;
                        }
                    });
                } else {
                    return layer.msg('当前不支持该源单选择!!');
                }
            }
            //#endregion
            //#endregion
            //#region å­è¡¨åˆå§‹åŒ–
@@ -1011,7 +1647,7 @@
                    , loading: false
                    , cols: [[ //子表
                        { type: 'checkbox', totalRowText: '合计行' }
                        , { type: 'numbers', title: '序号', width: 100 }
                        , { type: 'numbers', field: '序号', title: '序号', width: 100 }
                        , { field: 'HMaterID', title: 'HMaterID', width: 100, hide: true, style: 'background-color:#efefef4d;' }
                        , { field: '物料代码', title: '物料代码', width: 150, edit: 'text', event: "HMaterID" }//f7
                        , { field: '物料名称', title: '物料名称', width: 150, style: 'background-color:#efefef4d;' }
@@ -1019,11 +1655,11 @@
                        , { field: 'HUnitID', title: 'HUnitID', width: 100, hide: true, style: 'background-color:#efefef4d;' }
                        , { field: '计量单位', title: '计量单位', width: 100, edit: 'text', event: "HUnitID"}//f7
                        , { field: 'HQty', title: '数量', width: 100, totalRow: true, edit: 'text'}
                        , { field: 'HPrice', title: '单价', width: 100, edit: 'text', event: "HPrice" }
                        , { field: 'HMoney', title: '金额', width: 100, totalRow: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HPrice', title: '单价', width: 100, event: "HPrice", style: 'background-color:#efefef4d;' }
                        , { field: 'HMoney', title: '金额', width: 100, totalRow: true, edit: 'text' }
                        , { field: 'HTaxPrice', title: '含税单价', width: 100, edit: 'text', event: "HTaxPrice" }
                        , { field: 'HDiscountRate', title: '折扣率', width: 100, edit: 'text' }
                        , { field: 'HRelTaxPrice', title: '实际含税单价', width: 100, edit: 'text' }
                        , { field: 'HRelTaxPrice', title: '实际含税单价', width: 100, style: 'background-color:#efefef4d;' }
                        , { field: 'HTaxRate', title: '税率', width: 100, edit: 'text' }
                        , { field: 'HTaxMoney', title: '税额', width: 100, totalRow: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HMoneyBB', title: '本位币金额', width: 100, totalRow: true, style: 'background-color:#efefef4d;' }
@@ -1048,8 +1684,56 @@
                        , { field: 'HSeOrderBillNo', title: '销售订单号', width: 100, hide: true, style: 'background-color:#efefef4d;' }
                        , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 70 }
                    ]]
                }
                    , done: function (res, curr, count) {
                        $(".layui-table-main").scrollTop(topScroll);
                    }
                }
                optionEntry = {
                    elem: '#mainTableEntry'
                    , totalRow: true
                    , limit: 500
                    , height: 500
                    , loading: false
                    , cols: [[ //子表
                        { type: 'checkbox', totalRowText: '合计行' }
                        , { type: 'numbers', title: '序号', width: 100 }
                        , { field: 'HMaterID', title: 'HMaterID', width: 100, hide: true, style: 'background-color:#efefef4d;' }
                        , { field: '物料代码', title: '物料代码', width: 150, style: 'background-color:#efefef4d;'}
                        , { field: '物料名称', title: '物料名称', width: 150, style: 'background-color:#efefef4d;' }
                        , { field: '规格型号', title: '规格型号', width: 100, style: 'background-color:#efefef4d;' }
                        , { field: 'HUnitID', title: 'HUnitID', width: 100, hide: true, style: 'background-color:#efefef4d;' }
                        , { field: '计量单位', title: '计量单位', width: 100, style: 'background-color:#efefef4d;'}
                        , { field: 'HQty', title: '数量', width: 100, totalRow: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HPrice', title: '单价', width: 100, style: 'background-color:#efefef4d;' }
                        , { field: 'HMoney', title: '金额', width: 100, totalRow: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HTaxPrice', title: '含税单价', width: 100, style: 'background-color:#efefef4d;' }
                        , { field: 'HDiscountRate', title: '折扣率', width: 100, style: 'background-color:#efefef4d;' }
                        , { field: 'HRelTaxPrice', title: '实际含税单价', width: 100, style: 'background-color:#efefef4d;' }
                        , { field: 'HTaxRate', title: '税率', width: 100, style: 'background-color:#efefef4d;' }
                        , { field: 'HTaxMoney', title: '税额', width: 100, totalRow: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HMoneyBB', title: '本位币金额', width: 100, totalRow: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HlineTotal', title: '价税合计', width: 100, totalRow: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HlineTotalBB', title: '本位币价税合计', width: 100, totalRow: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HRemark', title: '备注', width: 100, style: 'background-color:#efefef4d;' }
                        , { field: 'HSourceInterID', title: '源单内码', width: 100, hide: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HSourceEntryID', title: '源单子内码', width: 100, hide: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HSourceBillNo', title: '源单号', width: 100, hide: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HSourceBillType', title: '源单类型', width: 100, hide: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HRelationQty', title: '关联数量', width: 100, totalRow: true, hide: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HRelationMoney', title: '关联金额', width: 100, totalRow: true, hide: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HPOOrderInterID', title: '采购订单内码', width: 100, hide: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HPOOrderEntryID', title: '采购订单子内码', width: 100, hide: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HPOOrderBillNo', title: '采购订单号', width: 100, hide: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HSeOrderTaxPrice', title: '订单含税单价', width: 100, hide: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HSeOrderInterID', title: '销售订单内码', width: 100, hide: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HSeOrderEntryID', title: '销售订单子内码', width: 100, hide: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HSeOrderBillNo', title: '销售订单号', width: 100, hide: true, style: 'background-color:#efefef4d;' }
                    ]]
                }
                var rowdata = [{
                    "HMaterID": "0"
                    , "物料代码": ""
@@ -1060,7 +1744,7 @@
                    , "HQty": "0"
                    , "HPrice": "0"
                    , "HTaxPrice": "0"
                    , 'HDiscountRate': "0"
                    , 'HDiscountRate': "1"
                    , 'HRelTaxPrice': "0"
                    , "HTaxRate": "0"
                    , 'HTaxMoney': "0"
@@ -1088,7 +1772,21 @@
                }];
                option.data = rowdata;
                table.render(option);
                table.render(optionEntry);
            }
            function set_InitGridHaveSource() {
                //选中源单后数量不可编辑
                for (var i = 0; i < option.cols[0].length; i++) {
                    if (option.cols[0][i]["field"] == "HQty") {
                       option.cols[0][i]["edit"] = false;
                    }
                    //if (option.cols[0][i]["field"] == "HMoney") {
                    //    option.cols[0][i]["edit"] = false;
                    //}
                }
            }
            //#endregion
@@ -1097,8 +1795,13 @@
            table.on('edit(mainTable)', function (obj) {
                //数值格式校验工具
                var ref = /^\d+(\.\d+)?$/;          //非负数正则表达式
                var ref1 = /^-?\d+(\.\d+)?$/;          //判断字符串是否为数字(包含整数、浮点数),正则表达式
                var temp = "";
                var Dec = getDecByMaterID(obj.data.HMaterID) //获取精度
                var HQtyDec = (Dec["HQtyDec"] == null || Dec["HQtyDec"] == 0) ? 4 : Dec["HQtyDec"];  //数量精度
                var HPriceDec = (Dec["HPriceDec"] == null || Dec["HPriceDec"] == 0) ? 4 : Dec["HPriceDec"];  //单价精度
                var HMoneyDec = (Dec["HMoneyDec"] == null || Dec["HMoneyDec"] == 0) ? 2 : Dec["HMoneyDec"];  //金额精度
                topScroll = $('#mainTable').next('.layui-table-view').find('.layui-table-body').scrollTop();//获取滚动条位置
                // å•元格编辑之前的值
                var oldText = $(this).prev().text();
                var value = obj.value //得到修改后的值
@@ -1110,14 +1813,23 @@
                    case "HQty":                                         //数量
                        //数据格式校验
                        temp = value + "";
                        if (!ref.test(temp) || temp == 0) {
                        if (!ref1.test(temp)) {
                            //恢复数据到编辑前
                            obj.update({
                                HQty: oldText
                            });
                            table.render(option);
                            layer.msg("数量请输入大于0的数字!");
                            layer.msg("数量请输入不为0的数字!");
                            return;
                        } else if (temp * 1 == 0) {
                            //恢复数据到编辑前
                            obj.update({
                                HQty: oldText
                            });
                            table.render(option);
                            layer.msg("数量请输入不为0的数字!");
                            return;
                        }
@@ -1127,11 +1839,19 @@
                        var HPrice = obj.data.HPrice * 1;               //单价
                        var HMoney = HQty * HPrice;                     //金额=数量*单价
                        var HTaxRate = obj.data.HTaxRate * 0.01;           //税率 
                        var HTaxMoney = Number((HMoney * HTaxRate).toFixed(4));         //税额=金额*税率
                        var HTaxMoney = Number((HMoney * HTaxRate));         //税额=金额*税率
                        var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                        var HExRate = $("#HExRate").val();                      //汇率
                        var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate).toFixed(4));      //本位币价税合计=(税额+金额)*汇率
                        var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate));      //本位币价税合计=(税额+金额)*汇率
                        var HMoneyBB = HMoney * HExRate;
                        HQty = Number(HQty.toFixed(HQtyDec));
                        HPrice = Number(HPrice.toFixed(HPriceDec));
                        HMoney = Number(HMoney.toFixed(HMoneyDec));
                        HTaxMoney = Number(HTaxMoney.toFixed(HMoneyDec));
                        HlineTotal = Number(HlineTotal.toFixed(HMoneyDec));
                        HlineTotalBB = Number(HlineTotalBB.toFixed(HMoneyDec));
                        HMoneyBB = Number(HMoneyBB.toFixed(HMoneyDec));
                        //同步更新表格和缓存对应的值
                        obj.update({
                            HQty: HQty
@@ -1140,7 +1860,9 @@
                            , HTaxMoney: HTaxMoney
                            , HlineTotal: HlineTotal
                            , HlineTotalBB: HlineTotalBB
                            , HMoneyBB: HMoneyBB
                        });
                        table.render(option);
                        break;
                    case "HPrice":                                         //单价
                        //数据格式校验
@@ -1150,7 +1872,7 @@
                            obj.update({
                                HPrice: oldText
                            });
                            table.render(option);
                            layer.msg("单价请输入大于0的数字!");
                            return;
                        }
@@ -1167,7 +1889,17 @@
                        var HRelTaxPrice = Number((HTaxPrice * HDiscountRate).toFixed(4));   //实际含税单价=含税单价*折扣率
                        var HExRate = $("#HExRate").val();                      //汇率
                        var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate).toFixed(4));     //本位币价税合计=(税额+金额)*汇率
                        var HMoneyBB = HMoney * HExRate;
                        //数字精度
                        HQty = Number(HQty.toFixed(HQtyDec));
                        HPrice = Number(HPrice.toFixed(HPriceDec));
                        HMoney = Number(HMoney.toFixed(HMoneyDec));
                        HlineTotal = Number(HlineTotal.toFixed(HMoneyDec));
                        HTaxPrice = Number(HTaxPrice.toFixed(HPriceDec));
                        HRelTaxPrice = Number(HRelTaxPrice.toFixed(HPriceDec));
                        HlineTotalBB = Number(HlineTotalBB.toFixed(HMoneyDec));
                        HTaxMoney = Number(HTaxMoney.toFixed(HMoneyDec));
                        HMoneyBB = Number(HMoneyBB.toFixed(HMoneyDec));
                        //同步更新表格和缓存对应的值
                        obj.update({
                            HQty: HQty
@@ -1178,7 +1910,9 @@
                            , HTaxPrice, HTaxPrice
                            , HRelTaxPrice: HRelTaxPrice
                            , HlineTotalBB: HlineTotalBB
                            , HMoneyBB: HMoneyBB
                        });
                        table.render(option);
                        break;
                    case "HTaxRate":                                                       //数量
                        //数据格式校验
@@ -1188,7 +1922,7 @@
                            obj.update({
                                HTaxRate: oldText
                            });
                            table.render(option);
                            layer.msg("税率请输入不小于0的数字!");
                            return;
                        }
@@ -1207,7 +1941,17 @@
                        var HRelTaxPrice = Number((HTaxPrice * HDiscountRate).toFixed(4));   //实际含税单价=含税单价*折扣率
                        var HExRate = $("#HExRate").val();                       //汇率
                        var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate).toFixed(4));       //本位币价税合计=(税额+金额)*汇率
                        var HMoneyBB = HMoney * HExRate;
                        //数字精度
                        HQty = Number(HQty.toFixed(HQtyDec));
                        HPrice = Number(HPrice.toFixed(HPriceDec));
                        HMoney = Number(HMoney.toFixed(HMoneyDec));
                        HlineTotal = Number(HlineTotal.toFixed(HMoneyDec));
                        HTaxPrice = Number(HTaxPrice.toFixed(HPriceDec));
                        HRelTaxPrice = Number(HRelTaxPrice.toFixed(HPriceDec));
                        HlineTotalBB = Number(HlineTotalBB.toFixed(HMoneyDec));
                        HTaxMoney = Number(HTaxMoney.toFixed(HMoneyDec));
                        HMoneyBB = Number(HMoneyBB.toFixed(HMoneyDec));
                        //同步更新表格和缓存对应的值
                        obj.update({
                            HTaxRate: HTaxRate * 100
@@ -1220,7 +1964,9 @@
                            , HTaxPrice, HTaxPrice
                            , HRelTaxPrice: HRelTaxPrice
                            , HlineTotalBB: HlineTotalBB
                            , HMoneyBB: HMoneyBB
                        });
                        table.render(option);
                        break;
                    case "HDiscountRate":                                                       //数量
                        //数据格式校验
@@ -1230,7 +1976,7 @@
                            obj.update({
                                HDiscountRate: oldText
                            });
                            table.render(option);
                            layer.msg("折扣率请输入不小于0的数字!");
                            return;
                        }
@@ -1241,12 +1987,18 @@
                        var HQty = obj.data.HQty * 1;                   //数量
                        var HPrice = obj.data.HPrice * 1;
                        var HMoney = HQty * HPrice;                     //金额=数量*单价
                        var HTaxMoney = Number((HMoney * HTaxRate).toFixed(4));         //税额=金额*税率
                        var HTaxPrice = Number((HPrice * (1 + HTaxRate)).toFixed(4));        //含税单价=单价*(1+税率)
                        var HTaxMoney = Number((HMoney * HTaxRate));         //税额=金额*税率
                        var HTaxPrice = Number((HPrice * (1 + HTaxRate)));        //含税单价=单价*(1+税率)
                        var HDiscountRate = obj.data.HDiscountRate * 1;     //折扣率
                        var HRelTaxPrice = Number((HTaxPrice * HDiscountRate).toFixed(4));   //实际含税单价=含税单价*折扣率
                        var HRelTaxPrice = Number((HTaxPrice * HDiscountRate));   //实际含税单价=含税单价*折扣率
                        //数字精度
                        HQty = Number(HQty.toFixed(HQtyDec));
                        HPrice = Number(HPrice.toFixed(HPriceDec));
                        HMoney = Number(HMoney.toFixed(HMoneyDec));
                        HTaxPrice = Number(HTaxPrice.toFixed(HPriceDec));
                        HRelTaxPrice = Number(HRelTaxPrice.toFixed(HPriceDec));
                        HTaxMoney = Number(HTaxMoney.toFixed(HMoneyDec));
                        //同步更新表格和缓存对应的值
                        obj.update({
                            HTaxRate: HTaxRate * 100
@@ -1258,8 +2010,117 @@
                            , HDiscountRate: HDiscountRate
                            , HRelTaxPrice: HRelTaxPrice
                        });
                        break;
                        table.render(option);
                        break;
                    case "HTaxPrice":                                         //单价
                        //数据格式校验
                        temp = value + "";     //修改后的值 è½¬ä¸ºå­—符串 èµ‹å€¼ç»™  å˜é‡temp
                        // ref很可能是一个正则表达式对象,用于匹配特定的字符串模式。ref.test(temp)会检查变量temp(即转换后的单价字符串)是否符合ref定义的模式。如果test方法返回false
                        if (!ref.test(temp)) { //检查单价字符串是否符合预期的格式
                            //恢复数据到编辑前
                            obj.update({            //更新表格某一行数据
                                HTaxPrice: oldText     //将hprice字段恢复到保存前的值
                            });
                            table.render(option);
                            layer.msg("含税单价请输入数字!");   //请输入单价的数值
                            return;
                        }
                        //数据校验合格,重算记录
                        var HQty = obj.data.HQty * 1;                   //数量
                        var HTaxPrice = value * 1;                    //含税单价
                        var HTaxRate = obj.data.HTaxRate * 0.01;           //税率
                        var HPrice = Number((HTaxPrice / (1 + HTaxRate)).toFixed(4));                         //单价 = å«ç¨Žå•ä»·/(1+税率)
                        var HMoney = HQty * HPrice;                     //金额=数量*单价
                        var HTaxMoney = Number((HMoney * HTaxRate).toFixed(4));         //税额=金额*税率
                        var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                        var HDiscountRate = obj.data.HDiscountRate * 1;   //折扣率
                        var HRelTaxPrice = Number((HTaxPrice * HDiscountRate).toFixed(4));   //实际含税单价=含税单价*折扣率
                        var HExRate = $("#HExRate").val();                      //汇率
                        var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate).toFixed(4));     //本位币价税合计=(税额+金额)*汇率
                        var HMoneyBB = HMoney * HExRate;
                        //数字精度
                        HQty = Number(HQty.toFixed(HQtyDec));
                        HPrice = Number(HPrice.toFixed(HPriceDec));
                        HMoney = Number(HMoney.toFixed(HMoneyDec));
                        HTaxMoney = Number(HTaxMoney.toFixed(HMoneyDec));
                        HlineTotal = Number(HlineTotal.toFixed(HMoneyDec));
                        HTaxPrice = Number(HTaxPrice.toFixed(HPriceDec));
                        HRelTaxPrice = Number(HRelTaxPrice.toFixed(HPriceDec));
                        HlineTotalBB = Number(HlineTotalBB.toFixed(HMoneyDec));
                        HMoneyBB = Number(HMoneyBB.toFixed(HMoneyDec));
                        //同步更新表格和缓存对应的值
                        obj.update({                    //更新表格数据                æ–¹æ³•是该对象提供的一个方法,用于更新其内部状态或与之关联的数据源
                            HQty: HQty                               //更新HQty字段,HQty
                            , HPrice: HPrice                         //更新HPrice字段,HPrice
                            , HMoney: HMoney                      //更新HMoney字段,HMoney
                            , HTaxMoney: HTaxMoney                  //更新HTaxMoney字段,HTaxMoney
                            , HlineTotal: HlineTotal             //更新HlineTotal字段,HlineTotal
                            , HTaxPrice, HTaxPrice                   //更新HTaxPrice字段,HTaxPrice
                            , HRelTaxPrice: HRelTaxPrice            //更新HRelTaxPrice字段,其值来自变量HRelTaxPrice
                            , HlineTotalBB: HlineTotalBB              //更新HlineTotalBB字段,其值来自变量HlineTotalBB
                            , HMoneyBB: HMoneyBB
                        });
                        table.render(option);
                        break;
                    case "HMoney":                                         //金额
                        //数据格式校验
                        temp = value + "";
                        if (!ref1.test(temp)) {
                            //恢复数据到编辑前
                            obj.update({
                                HMoney: oldText
                            });
                            table.render(option);
                            layer.msg("金额或数量请输入大于0的数字!");
                            return;
                        } else if (temp * 1 == 0) {
                            //恢复数据到编辑前
                            obj.update({
                                HMoney: oldText
                            });
                            table.render(option);
                            layer.msg("金额或数量请输入大于0的数字!");
                            return;
                        }
                        //数据校验合格,重算记录
                        var HQty = obj.data.HQty * 1;                   //数量
                        var HMoney = value * 1;                     //金额=数量*单价
                        var HPrice = HMoney / HQty;
                        var HTaxRate = obj.data.HTaxRate * 0.01;           //税率
                        var HTaxMoney = Number((HMoney * HTaxRate).toFixed(4));         //税额=金额*税率
                        var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                        var HTaxPrice = Number((HPrice * (1 + HTaxRate)).toFixed(4));        //含税单价=单价*(1+税率)
                        var HDiscountRate = obj.data.HDiscountRate * 1;   //折扣率
                        var HRelTaxPrice = Number((HTaxPrice * HDiscountRate).toFixed(4));   //实际含税单价=含税单价*折扣率
                        var HExRate = $("#HExRate").val();                      //汇率
                        var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate).toFixed(4));     //本位币价税合计=(税额+金额)*汇率
                        var HMoneyBB = HMoney * HExRate;
                        //数字精度
                        HQty = Number(HQty.toFixed(HQtyDec));
                        HPrice = Number(HPrice.toFixed(HPriceDec));
                        HMoney = Number(HMoney.toFixed(HMoneyDec));
                        HlineTotal = Number(HlineTotal.toFixed(HMoneyDec));
                        HTaxPrice = Number(HTaxPrice.toFixed(HPriceDec));
                        HRelTaxPrice = Number(HRelTaxPrice.toFixed(HPriceDec));
                        HlineTotalBB = Number(HlineTotalBB.toFixed(HMoneyDec));
                        HTaxMoney = Number(HTaxMoney.toFixed(HMoneyDec));
                        HMoneyBB = Number(HMoneyBB.toFixed(HMoneyDec));
                        //同步更新表格和缓存对应的值
                        obj.update({
                            HQty: HQty
                            , HPrice: HPrice
                            , HMoney: HMoney
                            , HTaxMoney: HTaxMoney
                            , HlineTotal: HlineTotal
                            , HTaxPrice, HTaxPrice
                            , HRelTaxPrice: HRelTaxPrice
                            , HlineTotalBB: HlineTotalBB
                            , HMoneyBB: HMoneyBB
                        });
                        table.render(option);
                        break;
                    default:
                }
            });
@@ -1312,17 +2173,26 @@
                                , "HExplanation": data.摘要
                                , "HInnerBillNo": data.内部单据号
                                , "HProjectID": data.HProjectID == null ? 0 : data.HProjectID
                                , "HProjectName": data.项目名称
                                , "HProjectNumber": data.项目代码
                                , "HInvoiceBillNo": data.发票编号
                                , "HMaker": data.制单人
                                , "HMakeDate": data.制单日期 == null ? "" : Format(new Date(data.制单日期), "yyyy-MM-dd HH:mm:ss")
                                , "HMakeDate": data.制单日期 == null ? "" : Format(new Date(data.制单日期), "yyyy-MM-dd hh:mm:ss")
                                , "HUpDater": data.修改人
                                , "HUpDateDate": data.修改日期 == null ? "" : Format(new Date(data.修改日期), "yyyy-MM-dd HH:mm:ss")
                                , "HUpDateDate": data.修改日期 == null ? "" : Format(new Date(data.修改日期), "yyyy-MM-dd hh:mm:ss")
                                , "HChecker": data.审核人
                                , "HCheckDate": data.审核日期 == null ? "" : Format(new Date(data.审核日期), "yyyy-MM-dd HH:mm:ss")
                                , "HCheckDate": data.审核日期 == null ? "" : Format(new Date(data.审核日期), "yyyy-MM-dd hh:mm:ss")
                                , "HCloseMan": data.关闭人
                                , "HCloseDate": data.关闭日期 == null ? "" : Format(new Date(data.关闭日期), "yyyy-MM-dd HH:mm:ss")
                                , "HCloseDate": data.关闭日期 == null ? "" : Format(new Date(data.关闭日期), "yyyy-MM-dd hh:mm:ss")
                                , "HDeleteMan": data.作废人
                                , "HDeleteDate": data.作废日期 == null ? "" : Format(new Date(data.作废日期), "yyyy-MM-dd HH:mm:ss")
                                , "HDeleteDate": data.作废日期 == null ? "" : Format(new Date(data.作废日期), "yyyy-MM-dd hh:mm:ss")
                            });
                            if (data.HMainSourceBillType != "") {
                                haveSource = true;
                            }
                            HOrgIDBar = 0;
@@ -1370,6 +2240,13 @@
                            }
                            option.data = rowdata;
                            table.render(option);
                            //子表  èµ‹å€¼
                            var rowdata = result.list[0];
                            optionEntry.data = rowdata;
                            table.render(optionEntry);
                            layer.close(ajaxLoad);
                        } else {
                            layer.close(ajaxLoad);
@@ -1436,6 +2313,9 @@
                        , "HSSName": dataArray[0].结算方式
                        , "HPSStyleID": dataArray[0].HPSStyleID
                        , "HPSStyleName": dataArray[0].采购方式
                        , "HProjectID": dataArray[0].HProjectID
                        , "HProjectName": dataArray[0].项目名称
                        , "HProjectNumber": dataArray[0].项目代码
                    });
                    //子表  èµ‹å€¼
@@ -1515,6 +2395,10 @@
                        , "HExRate": dataArray[0].汇率
                        , "HPSStyleID": dataArray[0].HPSStyleID
                        , "HPSStyleSName": dataArray[0].采购方式
                        , "HProjectID": dataArray[0].HProjectID
                        , "HProjectName": dataArray[0].项目名称
                        , "HProjectNumber": dataArray[0].项目代码
                        , "HInvoiceBillNo": dataArray[0].发票编号
                    });
                    //子表  èµ‹å€¼
@@ -1579,7 +2463,6 @@
                    $("#HUpDateDate").val(Format(new Date(), "yyyy-MM-dd hh:mm:ss"));
                }
                var sMainStr = JSON.stringify(data.field);
                //获取子表数据
                var num = [];
                for (var i = 0; i < table.cache["mainTable"].length; i++) {
@@ -1589,7 +2472,20 @@
                    }
                }
                var sSubStr = JSON.stringify(num);
                var sSubStr2;
                if (haveSource == true) {
                    //获取子表2数据
                    var num = [];
                    for (var i = 0; i < table.cache["mainTableEntry"].length; i++) {
                        if (table.cache["mainTableEntry"][i] != "") {
                            table.cache["mainTableEntry"][i].LAY_TABLE_INDEX = i;
                            num.push(table.cache["mainTableEntry"][i])
                        }
                    }
                    sSubStr2 = JSON.stringify(num);
                } else {
                    sSubStr2 = JSON.stringify([]);
                }
                //获取操作方式
                var refSav = "";
                if (OperationType == 1 || OperationType == 2 || OperationType == 4) {
@@ -1599,7 +2495,7 @@
                    refSav = "Update";
                }
                var sMainSub = sMainStr + ';' + sSubStr + ';' + refSav + ';' + sessionStorage["HUserName"];
                var sMainSub = sMainStr + ';' + sSubStr + ';' + sSubStr2 + ';'+ refSav + ';' + sessionStorage["HUserName"];
                $.ajax({
                    type: "POST",
@@ -1610,6 +2506,11 @@
                    success: function (data) {
                        if (data.count == 1) { // è¯´æ˜ŽéªŒè¯æˆåŠŸäº†ï¼Œ
                            layer.msg(data.Message, { icon: 1 });
                            if (data.Verify == "Y") //自动审核
                            {
                                $("#HInterID").val(data.HInterID);//获取提交成功返回的单据主ID
                                set_CheckBill(0); //审核
                            }
                            $('#set_SaveBill').addClass("layui-btn-disabled").attr("disabled", true);
                            //保存后浏览
                            //ReRoadBillMain();
@@ -1631,6 +2532,7 @@
            function AllowLoadData(data) {
                //数值格式校验工具
                var ref = /^\d+(\.\d+)?$/;          //非负数正则表达式
                var ref1 = /^-?\d+(\.\d+)?$/;          //判断字符串是否为数字(包含整数、浮点数),正则表达式
                var temp = "";
                //#region è¡¨å¤´æ•°æ®æ£€éªŒ
@@ -1643,43 +2545,43 @@
                    layer.msg("日期不能为空!");
                    return false;
                }
                if ($("#HCurID").val() == 0) {
                    layer.msg("请选择币别!");
                    return;
                }
                if ($("#HExRate").val() == 0) {
                    layer.msg("请输入汇率!");
                    return;
                }
                if ($("#HEmpID").val() == 0) {
                    layer.msg("请选择业务员员!");
                    return;
                }
                if ($("#HDeptID").val() == 0) {
                    layer.msg("请选择采购部门!");
                    return;
                }
                //if ($("#HCurID").val() == 0) {
                //    layer.msg("请选择币别!");
                //    return;
                //}
                //if ($("#HExRate").val() == 0) {
                //    layer.msg("请输入汇率!");
                //    return;
                //}
                //if ($("#HEmpID").val() == 0) {
                //    layer.msg("请选择业务员员!");
                //    return;
                //}
                //if ($("#HDeptID").val() == 0) {
                //    layer.msg("请选择采购部门!");
                //    return;
                //}
                if ($("#HSupID").val() == 0) {
                    layer.msg("请选择供应商!");
                    return;
                }
                if ($("#HPSStyleID").val() == 0) {
                    layer.msg("请选择采购方式!");
                    return;
                }
                if ($("#HSSID").val() == 0) {
                    layer.msg("请选择结算方式!");
                    return;
                }
                //if ($("#HPSStyleID").val() == 0) {
                //    layer.msg("请选择采购方式!");
                //    return;
                //}
                //if ($("#HSSID").val() == 0) {
                //    layer.msg("请选择结算方式!");
                //    return;
                //}
                temp = $("#HExRate").val() + "";
                if (temp == 0) {
                    layer.msg("汇率不能为0!");
                    return false;
                } else if (!ref.test(temp)) {
                    layer.msg("汇率请输入大于0的数字!");
                    return false;
                }
                //temp = $("#HExRate").val() + "";
                //if (temp == 0) {
                //    layer.msg("汇率不能为0!");
                //    return false;
                //} else if (!ref.test(temp)) {
                //    layer.msg("汇率请输入大于0的数字!");
                //    return false;
                //}
                //#endregion
                //#region å­è¡¨ æ•°æ®æ£€éªŒ
@@ -1697,13 +2599,13 @@
                        return false;
                    }
                    //实发数量格式校验
                    //数量格式校验
                    temp = option.data[i]["HQty"] + "";
                    if (temp == "0") {
                        layer.msg("第" + (i + 1) + "行:实收数量不能为0!");
                    if (!ref1.test(temp)) {
                        layer.msg("第" + (i + 1) + "行:数量请输入不为0的数字!");
                        return false;
                    } else if (!ref.test(temp)) {
                        layer.msg("第" + (i + 1) + "行:实收数量请输入大于0的数字!");
                    } else if (temp * 1 == 0) {
                        layer.msg("第" + (i + 1) + "行:数量请输入不为0的数字!");
                        return false;
                    }
@@ -1734,25 +2636,26 @@
                        return false;
                    }
                    //金额格式校验
                    temp = option.data[i]["HMoney"] + "";
                    if (temp == "0") {
                        layer.msg("第" + (i + 1) + "行:金额不能为0!");
                        return false;
                    } else if (!ref.test(temp)) {
                        layer.msg("第" + (i + 1) + "行:金额请输入大于0的数字!");
                        return false;
                    }
                    ////金额格式校验
                    //temp = option.data[i]["HMoney"] + "";
                    //if (temp == "0") {
                    //    layer.msg("第" + (i + 1) + "行:金额不能为0!");
                    //    return false;
                    //} else if (!ref.test(temp)) {
                    //    layer.msg("第" + (i + 1) + "行:金额请输入大于0的数字!");
                    //    return false;
                    //}
                    //价税合计格式校验
                    temp = option.data[i]["HTaxMoney"] + "";
                    if (temp == "0") {
                        layer.msg("第" + (i + 1) + "行:价税合计不能为0!");
                        return false;
                    } else if (!ref.test(temp)) {
                        layer.msg("第" + (i + 1) + "行:价税合计请输入大于0的数字!");
                        return false;
                    }
                    ////价税合计格式校验
                    //temp = option.data[i]["HTaxMoney"] + "";
                    ////if (temp == "0") {
                    ////    layer.msg("第" + (i + 1) + "行:价税合计不能为0!");
                    ////    return false;
                    ////} else
                    //if (!ref.test(temp)) {
                    //    layer.msg("第" + (i + 1) + "行:税额请输入大于0的数字!");
                    //    return false;
                    //}
                }
                //#endregion
                return true;
@@ -1765,7 +2668,7 @@
                    if (event.key == "F7") {
                        //物料
                        if (obj.event == "HMaterID") {
                                var HOrgID = $("#HOrgID").val();
                            var HOrgID = $("#HOrgID").val();  //获取id="HOrgID"的元素中获取其值,并将该值存储在变量HOrgID中
                            layer.open({
                                type: 2
                                , skin: "layui-layer-rim" //加上边框
@@ -1785,31 +2688,81 @@
                                        return layer.msg("请选择一条数据");
                                    }
                                    OptionData = checkStatus.data[0];
                                    //更新表格缓存的数据
                                    obj.update({
                                        "HMaterID": checkStatus.data[0].HItemID
                                        , "物料代码": checkStatus.data[0].HNumber
                                        , "物料名称": checkStatus.data[0].HName
                                        , "规格型号": checkStatus.data[0].HModel
                                        , "HUnitID": checkStatus.data[0].HUnitID
                                        , "计量单位": checkStatus.data[0].HUnitName
                                    })
                                    layer.close(index);//关闭弹窗
                                }
                               , end: function () {
                                obj.update({
                                    "HMaterID": OptionData.HItemID
                                        ,"物料代码" : OptionData.物料代码
                                       , "物料名称" :OptionData.物料名称
                                        ,"规格型号" : OptionData.规格型号
                                        ,"HUnitID" :OptionData.HUnitID
                                        ,"计量单位" : OptionData.计量单位名称
                                })
                            }
                                , end: function () {
                                    //通过供应商id获取税率
                                    var HSupID = $("#HSupID").val();
                                    if (HSupID != 0 && typeof (OptionData.HItemID) != "undefined") {
                                        var Dec = getDecByMaterID(obj.data.HMaterID) //获取精度
                                        var HQtyDec = (Dec["HQtyDec"] == null || Dec["HQtyDec"] == 0) ? 4 : Dec["HQtyDec"];  //数量精度
                                        var HPriceDec = (Dec["HPriceDec"] == null || Dec["HPriceDec"] == 0) ? 4 : Dec["HPriceDec"];  //单价精度
                                        var HMoneyDec = (Dec["HMoneyDec"] == null || Dec["HMoneyDec"] == 0) ? 2 : Dec["HMoneyDec"];  //金额精度
                                        $.ajax({
                                            url: GetWEBURL() + "/Gy_Supplier/xg",
                                            //url: "http://localhost:12761/Gy_Supplier/xg",
                                            type: "GET",
                                            data: {
                                                "HInterID": HSupID
                                            },
                                            success: function (d) {
                                                var HTaxRate = parseInt(d.data[0].增值税率) * 0.01;
                                                var HExRate = $("#HExRate").val();                      //汇率
                                                //数据校验合格,重算记录
                                                var HQty = obj.data.HQty * 1;                           //数量
                                                var HPrice = obj.data.HPrice * 1;               //单价
                                                var HMoney = HQty * HPrice;                     //金额=数量*单价
                                                var HTaxMoney = Number((HMoney * HTaxRate));         //税额=金额*税率
                                                var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                                                var HTaxPrice = Number((HPrice * (1 + HTaxRate)));        //含税单价=单价*(1+税率)
                                                var HDiscountRate = obj.data.HDiscountRate * 1;   //折扣率
                                                var HRelTaxPrice = Number((HTaxPrice * HDiscountRate));   //实际含税单价=含税单价*折扣率
                                                var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate));     //本位币价税合计=(税额+金额)*汇率
                                                //数字精度
                                                HQty = Number(HQty.toFixed(HQtyDec));
                                                HPrice = Number(HPrice.toFixed(HPriceDec));
                                                HMoney = Number(HMoney.toFixed(HMoneyDec));
                                                HTaxMoney = Number(HTaxMoney.toFixed(HMoneyDec));
                                                HlineTotal = Number(HlineTotal.toFixed(HMoneyDec));
                                                HTaxPrice = Number(HTaxPrice.toFixed(HPriceDec));
                                                HRelTaxPrice = Number(HRelTaxPrice.toFixed(HPriceDec));
                                                HlineTotalBB = Number(HlineTotalBB.toFixed(HMoneyDec));
                                                obj.update({ //更新表格数据
                                                    "HMaterID": OptionData.HItemID             //设置HItemID的值为“HBillNo”字段的值HItemID`的值
                                                    , "物料代码": OptionData.物料代码
                                                    , "物料名称": OptionData.物料名称
                                                    , "规格型号": OptionData.规格型号
                                                    , "HUnitID": OptionData.HUnitID
                                                    , "计量单位": OptionData.计量单位名称
                                                    , "HTaxRate": HTaxRate * 100
                                                    , HQty: HQty                               //更新HQty字段,HQty
                                                    , HPrice: HPrice                         //更新HPrice字段,HPrice
                                                    , HMoney: HMoney                      //更新HMoney字段,HMoney
                                                    , HTaxMoney: HTaxMoney                  //更新HTaxMoney字段,HTaxMoney
                                                    , HlineTotal: HlineTotal             //更新HlineTotal字段,HlineTotal
                                                    , HTaxPrice, HTaxPrice                   //更新HTaxPrice字段,HTaxPrice
                                                    , HRelTaxPrice: HRelTaxPrice            //更新HRelTaxPrice字段,其值来自变量HRelTaxPrice
                                                    , HlineTotalBB: HlineTotalBB              //更新HlineTotalBB字段,其值来自变量HlineTotalBB
                                                })
                                            }
                                        });
                                    } else if (typeof (OptionData.HItemID) != "undefined") {
                                        obj.update({ //更新表格数据
                                            "HMaterID": OptionData.HItemID             //设置HItemID的值为“HBillNo”字段的值HItemID`的值
                                            , "物料代码": OptionData.物料代码
                                            , "物料名称": OptionData.物料名称
                                            , "规格型号": OptionData.规格型号
                                            , "HUnitID": OptionData.HUnitID
                                            , "计量单位": OptionData.计量单位名称
                                        })
                                    }
                                }
                            })
                        }
                        //计量单位
                        if (obj.event == "HUnitID") {
                            var HOrgName = $('select[name="HOrgID"] option:selected').text();
                            layer.open({
                                type: 2
                                , skin: "layui-layer-rim" //加上边框
@@ -1818,37 +2771,132 @@
                                , shift: 2 //弹出动画
                                , area: ["90%", "90%"] //窗体大小
                                , maxmin: true //设置最大最小按钮是否显示
                                , content: ['../../基础资料/公用基础资料/Gy_Unit.html', 'yes']
                                , content: ['../../基础资料/公用基础资料/Gy_Unit.html?Type=2&HOrgName=' + HOrgName, 'yes']
                                , btn: ["确定", "取消"]
                                , btn1: function (index, laero) {
                                //按钮一  çš„回调
                                var iframeWindow = window["layui-layer-iframe" + index];//获取弹框页面
                                var checkStatus = iframeWindow.layui.table.checkStatus("mainTable");//获取选中的数据
                                    //按钮一  çš„回调
                                    var iframeWindow = window["layui-layer-iframe" + index];//获取弹框页面
                                    var checkStatus = iframeWindow.layui.table.checkStatus("mainTable");//获取选中的数据
                                if (checkStatus.data.length != 1) {
                                    return layer.msg("请选择一条数据");
                                    if (checkStatus.data.length != 1) {
                                        return layer.msg("请选择一条数据");
                                    }
                                    OptionData = checkStatus.data[0];
                                    //更新表格缓存的数据
                                    obj.update({
                                        "HUnitID": checkStatus.data[0].HItemID
                                        , "计量单位": checkStatus.data[0].计量单位名称
                                    })
                                    layer.close(index);//关闭弹窗
                                }
                                OptionData = checkStatus.data[0];
                                //更新表格缓存的数据
                                obj.update({
                                    "HUnitID": checkStatus.data[0].HItemID
                                    , "计量单位": checkStatus.data[0].计量单位名称
                                })
                                layer.close(index);//关闭弹窗
                            }
                            , end: function () {
                                obj.update({
                                    "HUnitID": OptionData.HItemID
                                    , "计量单位": OptionData.计量单位名称
                                })
                            }
                                , end: function () {
                                    obj.update({
                                        "HUnitID": OptionData.HItemID
                                        , "计量单位": OptionData.计量单位名称
                                    })
                                }
                        })
                    }
                    obj.event = "";
                    return false;
                }
            })
                })
                //双击
                $('.layui-table-box tbody td[data-field="物料代码"]').off('dblclick').on('dblclick', function () {
                    var HOrgID = $("#HOrgID").val();  //获取id="HOrgID"的元素中获取其值,并将该值存储在变量HOrgID中
                    layer.open({
                        type: 2
                        , skin: "layui-layer-rim" //加上边框
                        , title: "物料列表"  //标题
                        , closeBtn: 1  //窗体右上角关闭 çš„ æ ·å¼
                        , shift: 2 //弹出动画
                        , area: ["90%", "90%"] //窗体大小
                        , maxmin: true //设置最大最小按钮是否显示
                        , content: ['../../基础资料/公用基础资料/Gy_Material.html?openType=2&HOrgID=' + HOrgID, 'yes']
                        , btn: ["确定", "取消"]
                        , btn1: function (index, laero) {
                            //按钮一  çš„回调
                            var iframeWindow = window["layui-layer-iframe" + index];//获取弹框页面
                            var checkStatus = iframeWindow.layui.table.checkStatus("mainTable");//获取选中的数据
                            if (checkStatus.data.length != 1) {
                                return layer.msg("请选择一条数据");
                            }
                            OptionData = checkStatus.data[0];
                            layer.close(index);//关闭弹窗
                        }
                        , end: function () {
                            //通过供应商id获取税率
                            var HSupID = $("#HSupID").val();
                            if (HSupID != 0 && typeof (OptionData.HItemID) != "undefined") {
                                var Dec = getDecByMaterID(obj.data.HMaterID) //获取精度
                                var HQtyDec = (Dec["HQtyDec"] == null || Dec["HQtyDec"] == 0) ? 4 : Dec["HQtyDec"];  //数量精度
                                var HPriceDec = (Dec["HPriceDec"] == null || Dec["HPriceDec"] == 0) ? 4 : Dec["HPriceDec"];  //单价精度
                                var HMoneyDec = (Dec["HMoneyDec"] == null || Dec["HMoneyDec"] == 0) ? 2 : Dec["HMoneyDec"];  //金额精度
                                $.ajax({
                                    url: GetWEBURL() + "/Gy_Supplier/xg",
                                    //url: "http://localhost:12761/Gy_Supplier/xg",
                                    type: "GET",
                                    data: {
                                        "HInterID": HSupID
                                    },
                                    success: function (d) {
                                        var HTaxRate = parseInt(d.data[0].增值税率) * 0.01;
                                        var HExRate = $("#HExRate").val();                      //汇率
                                        //数据校验合格,重算记录
                                        var HQty = obj.data.HQty * 1;                           //数量
                                        var HPrice = obj.data.HPrice * 1;               //单价
                                        var HMoney = HQty * HPrice;                     //金额=数量*单价
                                        var HTaxMoney = Number((HMoney * HTaxRate));         //税额=金额*税率
                                        var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                                        var HTaxPrice = Number((HPrice * (1 + HTaxRate)));        //含税单价=单价*(1+税率)
                                        var HDiscountRate = obj.data.HDiscountRate * 1;   //折扣率
                                        var HRelTaxPrice = Number((HTaxPrice * HDiscountRate));   //实际含税单价=含税单价*折扣率
                                        var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate));     //本位币价税合计=(税额+金额)*汇率
                                        //数字精度
                                        HQty = Number(HQty.toFixed(HQtyDec));
                                        HPrice = Number(HPrice.toFixed(HPriceDec));
                                        HMoney = Number(HMoney.toFixed(HMoneyDec));
                                        HTaxMoney = Number(HTaxMoney.toFixed(HMoneyDec));
                                        HlineTotal = Number(HlineTotal.toFixed(HMoneyDec));
                                        HTaxPrice = Number(HTaxPrice.toFixed(HPriceDec));
                                        HRelTaxPrice = Number(HRelTaxPrice.toFixed(HPriceDec));
                                        HlineTotalBB = Number(HlineTotalBB.toFixed(HMoneyDec));
                                        obj.update({ //更新表格数据
                                            "HMaterID": OptionData.HItemID             //设置HItemID的值为“HBillNo”字段的值HItemID`的值
                                            , "物料代码": OptionData.物料代码
                                            , "物料名称": OptionData.物料名称
                                            , "规格型号": OptionData.规格型号
                                            , "HUnitID": OptionData.HUnitID
                                            , "计量单位": OptionData.计量单位名称
                                            , "HTaxRate": HTaxRate * 100
                                            , HQty: HQty                               //更新HQty字段,HQty
                                            , HPrice: HPrice                         //更新HPrice字段,HPrice
                                            , HMoney: HMoney                      //更新HMoney字段,HMoney
                                            , HTaxMoney: HTaxMoney                  //更新HTaxMoney字段,HTaxMoney
                                            , HlineTotal: HlineTotal             //更新HlineTotal字段,HlineTotal
                                            , HTaxPrice, HTaxPrice                   //更新HTaxPrice字段,HTaxPrice
                                            , HRelTaxPrice: HRelTaxPrice            //更新HRelTaxPrice字段,其值来自变量HRelTaxPrice
                                            , HlineTotalBB: HlineTotalBB              //更新HlineTotalBB字段,其值来自变量HlineTotalBB
                                        })
                                    }
                                });
                            } else if (typeof (OptionData.HItemID) != "undefined"){
                                obj.update({ //更新表格数据
                                    "HMaterID": OptionData.HItemID             //设置HItemID的值为“HBillNo”字段的值HItemID`的值
                                    , "物料代码": OptionData.物料代码
                                    , "物料名称": OptionData.物料名称
                                    , "规格型号": OptionData.规格型号
                                    , "HUnitID": OptionData.HUnitID
                                    , "计量单位": OptionData.计量单位名称
                                })
                            }
                        }
                    })
                });
        }
            //#endregion
@@ -1859,12 +2907,16 @@
                if (obj.event === 'del') {
                    layer.confirm('真的删除行吗?', function (index) {
                        console.log("索引为:" + rowIndex);
                        if (rowIndex === '0') {
                        if (rowIndex === '0' && table.cache["mainTable"].length == 1) {
                            layer.msg('首行无法删除!!!');
                        } else {
                            obj.del();
                        } else if (haveSource == true) {
                            layer.msg('有源单无法删除!!!');
                        }
                        else {
                            obj.del();//假删除
                            table.cache["mainTable"].splice(rowIndex, 1);  //②彻底移除元素,从缓存里移除这一行
                            option.data = table.cache["mainTable"];//将数据绑定到data上
                            table.reload(option);
                            table.render(option);
                            layer.close(index);
                        }
                    });
@@ -1879,6 +2931,56 @@
                table.render(option);
                //rows++;
                layer.msg('增加一行按钮!')
            }
            //#endregion
            //#region åº“存查询
            function get_Inventory() {
                var checkStatus = table.checkStatus('mainTable')
                    , data = checkStatus.data;
                if (checkStatus.data.length === 1 && data[0].HMaterID != 0) {
                    var HMaterID = data[0].HMaterID.toString();
                    //弹窗方法
                    layer.open({
                        type: 2//弹窗类型
                        , skin: 'layui-layer-rim' //加上边框
                        , area: ['90%', '90%']//大小
                        , title: '库存查询列表'//标题
                        , shift: 2//弹出动画
                        , content: ['../../仓存管理/条码报表/Kf_ICinventoryQueryReport.html?Type=1&HMaterID=' + HMaterID, 'yes']
                        , btn: ['取消']
                        , btn1: function (index, layero) {
                            layer.close(index);
                        }
                    })
                }
                else {
                    layer.msg('请选择一行有物料数据查询!');
                }
            }
            //#endregion
            //#region å‡ºå…¥åº“记录查询
            function get_InOutSum() {
                var checkStatus = table.checkStatus('mainTable')
                    , data = checkStatus.data;
                if (checkStatus.data.length === 1 && data[0].HMaterID != 0) {
                    var HMaterID = data[0].HMaterID.toString();
                    layer.open({
                        type: 2//弹窗类型
                        , skin: 'layui-layer-rim' //加上边框
                        , area: ['90%', '90%']//大小
                        , title: '出入库记录列表'//标题
                        , shift: 2//弹出动画
                        , content: ['../../仓存管理/条码报表/Kf_StockInOutSumQueryReport.html?Type=1&HMaterID=' + HMaterID, 'yes']
                        , btn: ['取消']
                        , btn1: function (index, layero) {
                            layer.close(index);
                        }
                    })
                }
                else {
                    layer.msg('请选择一行有物料数据查询!');
                }
            }
            //#endregion
@@ -1991,7 +3093,11 @@
                var colName = "";
                var contentUrl = "";
                for (var i = 1; i < option.cols[0].length - 1; i++) {
                    colName += option.cols[0][i]["title"] + ",";
                    colName += option.cols[0][i]["field"] + ",";
                }
                var colTitleName = "";
                for (var i = 1; i < option.cols[0].length - 1; i++) {
                    colTitleName += option.cols[0][i]["title"] + ",";
                }
                var urlStr = window.document.location.pathname;//获取文件路径
                var urlLen = urlStr.split('/');
@@ -2000,7 +3106,7 @@
                }
                colName = encodeURI(colName.substring(0, colName.length - 1));//对 URI è¿›è¡Œç¼–码
                contentUrl += '基础资料/隐藏列设置/Gy_GridView_Hide.html?HModName=' + HModName + '&colName=' + colName;
                contentUrl += '基础资料/隐藏列设置/Gy_GridView_Hide.html?HModName=' + HModName + '&colName=' + colName + '&colTitleName = ' + colTitleName;
                layer.open({
                    type: 2
@@ -2073,6 +3179,10 @@
                                    case "R":
                                        option.cols[0][i + 1]["align"] = "right";
                                        break;
                                }
                                //设置表格title属性显示别名
                                if (dataCols[4] != null && dataCols[4] != "") {
                                    option.cols[0][i + 1]["title"] = dataCols[4];
                                }
                            }
@@ -2150,30 +3260,42 @@
                    , "HSSName": dataArray[0].结算方式
                    , "HPSStyleID": dataArray[0].HPSStyleID
                    , "HPSStyleName": dataArray[0].采购方式
                    , "HProjectID": dataArray[0].HProjectID
                    , "HProjectName": dataArray[0].项目名称
                    , "HProjectNumber": dataArray[0].项目代码
                });
                //子表  èµ‹å€¼
                var rowdata = [];
                //子表Entry  èµ‹å€¼
                var rowdataEntry = [];
                for (var i = 0; i < dataArray.length; i++) {
                    rowdata.push(
                    var HQty = dataArray[i].数量 - dataArray[i].关联数量;                           //数量
                    var HPrice = dataArray[i].单价;               //单价
                    var HMoney = HQty * HPrice;                     //金额=数量*单价
                    var HTaxRate = dataArray[i].税率 * 0.01;           //税率
                    var HTaxMoney = Number((HMoney * HTaxRate));         //税额=金额*税率
                    var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                    var HExRate = $("#HExRate").val();                      //汇率
                    var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate));      //本位币价税合计=(税额+金额)*汇率
                    var HMoneyBB = HMoney * HExRate;
                    rowdataEntry.push(
                        {
                             "HMaterID": dataArray[i].HMaterID
                            "HMaterID": dataArray[i].HMaterID
                            , "物料代码": dataArray[i].物料代码
                            , "物料名称": dataArray[i].物料名称
                            , "规格型号": dataArray[i].规格型号
                            , "HUnitID": dataArray[i].HUnitID
                            , "计量单位": dataArray[i].计量单位
                            , "HQty": dealDoubleToFixed(dataArray[i].数量-dataArray[i].关联数量, 1)
                            , "HQty": dealDoubleToFixed(HQty, 1)
                            , "HPrice": dealDoubleToFixed(dataArray[i].单价, 3)
                            , "HTaxPrice": dealDoubleToFixed(dataArray[i].含税单价, 3)
                            , 'HDiscountRate':"0"                                                     //
                            , 'HRelTaxPrice': "0"
                            , 'HDiscountRate': "1"                                                     //
                            , 'HRelTaxPrice': dealDoubleToFixed(dataArray[i].含税单价, 3)
                            , "HTaxRate": dataArray[i].税率
                            , 'HTaxMoney':"0"                                                         //
                            , "HMoney": dealDoubleToFixed(dataArray[i].金额, 2)
                            , 'HMoneyBB': dealDoubleToFixed(dataArray[i].金额 * dataArray[0].汇率, 2)
                            , 'HlineTotal': dealDoubleToFixed(dataArray[i].价税合计, 2)
                            , 'HlineTotalBB': dealDoubleToFixed(dataArray[i].价税合计 * dataArray[0].汇率, 2)
                            , 'HTaxMoney': HTaxMoney                                                         //
                            , "HMoney": dealDoubleToFixed(HMoney, 2)
                            , 'HMoneyBB': dealDoubleToFixed(HMoneyBB, 2)
                            , 'HlineTotal': dealDoubleToFixed(HlineTotal, 2)
                            , 'HlineTotalBB': dealDoubleToFixed(HlineTotalBB, 2)
                            , "HRemark": ""
                            , "HSourceInterID": dataArray[i].hmainid
@@ -2194,7 +3316,30 @@
                        }
                    );
                }
                option.data = rowdata;
                optionEntry.data = JSON.parse(JSON.stringify(rowdataEntry));
                table.render(optionEntry);
                //子表汇总
                for (var i = 0; i < rowdataEntry.length; i++) {
                    var item = rowdataEntry[i];
                    for (var j = i + 1; j < rowdataEntry.length; j++) {
                        if (rowdataEntry[j].HMaterID == item.HMaterID) {
                            rowdataEntry[i].HQty += rowdataEntry[j].HQty;//数量
                            rowdataEntry[i].HMoney += rowdataEntry[j].HMoney;//金额
                            rowdataEntry[i].HPrice = rowdataEntry[i].HMoney / rowdataEntry[i].HQty;//单价
                            rowdataEntry[i].HTaxMoney = Number((rowdataEntry[i].HMoney * rowdataEntry[i].HTaxRate).toFixed(4))//税额
                            rowdataEntry[i].HlineTotal = rowdataEntry[i].HMoney + rowdataEntry[i].HTaxMoney //价税合计
                            var HExRate = $("#HExRate").val();
                            rowdataEntry[i].HlineTotalBB = Number(((rowdataEntry[i].HMoney + rowdataEntry[i].HTaxMoney) * HExRate).toFixed(4)) //本位币价税合计
                            rowdataEntry[i].HMoneyBB = Number((rowdataEntry[i].HMoney * HExRate).toFixed(4)) //本位币金额
                            rowdataEntry.splice(j, 1);
                            j = j - 1;
                        }
                    }
                }
                set_InitGridHaveSource();
                option.data = rowdataEntry;
                haveSource = true;
                table.render(option);
            }
            //#endregion
@@ -2221,6 +3366,12 @@
                        return;
                    }
                }
                if (dataArray[0].源单类型 == "1102") {
                    getPushSource_POOrderBillCur(dataArray[0].源单主内码, dataArray[0].源单子内码);
                } else {
                    getPushSource_POInStockBillCur(dataArray[0].源单主内码, dataArray[0].源单子内码);
                }
                form.val("component-form-group", { //formTest å³ class="layui-form" æ‰€åœ¨å…ƒç´ å±žæ€§ lay-filter="" å¯¹åº”的值
                    "HMainSourceInterID": "0"
@@ -2243,12 +3394,25 @@
                    , "HSSName": ""
                    , "HPSStyleID": dataArray[0].HPSStyleID
                    , "HPSStyleName": dataArray[0].采购方式
                    , "HProjectID": dataArray[0].HProjectID
                    , "HProjectName": dataArray[0].项目名称
                    , "HProjectNumber": dataArray[0].项目代码
                    , "HInvoiceBillNo": dataArray[0].发票编号
                });
                //子表  èµ‹å€¼
                var rowdata = [];
                //子表Entry  èµ‹å€¼
                var rowdataEntry = [];
                for (var i = 0; i < dataArray.length; i++) {
                    rowdata.push(
                    var HQty = dataArray[i].实收数量 - dataArray[i].关联数量;                           //数量
                    var HPrice = dataArray[i].单价;               //单价
                    var HMoney = HQty * HPrice;                     //金额=数量*单价
                    var HTaxRate = dataArray[i].税率 * 0.01;           //税率
                    var HTaxMoney = Number((HMoney * HTaxRate));         //税额=金额*税率
                    var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                    var HExRate = $("#HExRate").val();                      //汇率
                    var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate));      //本位币价税合计=(税额+金额)*汇率
                    var HMoneyBB = HMoney * HExRate;
                    rowdataEntry.push(
                        {
                            "HMaterID": dataArray[i].HMaterID
                            , "物料代码": dataArray[i].物料代码
@@ -2256,14 +3420,17 @@
                            , "规格型号": dataArray[i].规格型号
                            , "HUnitID": dataArray[i].HUnitID
                            , "计量单位": dataArray[i].计量单位
                            , "HQty": dealDoubleToFixed(dataArray[i].实收数量-dataArray[i].关联数量, 1)
                            , "HQty": dealDoubleToFixed(HQty, 1)
                            , "HPrice": dealDoubleToFixed(dataArray[i].单价, 3)
                            , "HTaxPrice": dealDoubleToFixed(dataArray[i].含税单价, 3)
                            , 'HDiscountRate': "0"                                                     //
                            , 'HRelTaxPrice': "0"
                            , 'HDiscountRate': "1"                                                     //
                            , 'HRelTaxPrice': dealDoubleToFixed(dataArray[i].含税单价, 3)
                            , "HTaxRate": dataArray[i].税率
                            , 'HTaxMoney': "0"                                                         //
                            , "HMoney":dataArray[i].金额
                            , 'HTaxMoney': HTaxMoney                                                         //
                            , "HMoney": dealDoubleToFixed(HMoney, 2)
                            , 'HMoneyBB': dealDoubleToFixed(HMoneyBB, 2)
                            , 'HlineTotal': dealDoubleToFixed(HlineTotal, 2)
                            , 'HlineTotalBB': dealDoubleToFixed(HlineTotalBB, 2)
                            , "HRemark": ""
                            , "HSourceInterID": dataArray[i].hmainid
@@ -2277,15 +3444,38 @@
                            , 'HPOOrderEntryID': "0"
                            , 'HPOOrderBillNo': ""
                           // , 'HSeOrderTaxPrice': dealDoubleToFixed(dataArray[i].含税单价, 3)
                            , "HSeOrderInterID": dataArray[i].HSourceBillType == "1401" ? dataArray[i].HSourceInterID: "0"
                            // , 'HSeOrderTaxPrice': dealDoubleToFixed(dataArray[i].含税单价, 3)
                            , "HSeOrderInterID": dataArray[i].HSourceBillType == "1401" ? dataArray[i].HSourceInterID : "0"
                            , "HSeOrderEntryID": dataArray[i].HSourceBillType == "1401" ? dataArray[i].HSourceEntryID : "0"
                            , "HSeOrderBillNo": dataArray[i].HSourceBillType == "1401" ? dataArray[i].源单单号 : ""
                        }
                    );
                }
                option.data = rowdata;
                optionEntry.data = JSON.parse(JSON.stringify(rowdataEntry));
                table.render(optionEntry);
                //子表汇总
                for (var i = 0; i < rowdataEntry.length; i++) {
                    var item = rowdataEntry[i];
                    for (var j = i + 1; j < rowdataEntry.length; j++) {
                        if (rowdataEntry[j].HMaterID == item.HMaterID) {
                            rowdataEntry[i].HQty += rowdataEntry[j].HQty;
                            rowdataEntry[i].HMoney += rowdataEntry[j].HMoney;//金额
                            rowdataEntry[i].HPrice = rowdataEntry[i].HMoney / rowdataEntry[i].HQty;//单价
                            rowdataEntry[i].HTaxMoney = Number((rowdataEntry[i].HMoney * rowdataEntry[i].HTaxRate).toFixed(4))//税额
                            rowdataEntry[i].HlineTotal = rowdataEntry[i].HMoney + rowdataEntry[i].HTaxMoney //价税合计
                            var HExRate = $("#HExRate").val();
                            rowdataEntry[i].HlineTotalBB = Number(((rowdataEntry[i].HMoney + rowdataEntry[i].HTaxMoney) * HExRate).toFixed(4)) //本位币价税合计
                            rowdataEntry[i].HMoneyBB = Number((rowdataEntry[i].HMoney * HExRate).toFixed(4)) //本位币金额
                            rowdataEntry.splice(j, 1);
                            j = j - 1;
                        }
                    }
                }
                set_InitGridHaveSource();
                option.data = rowdataEntry;
                haveSource = true;
                table.render(option);
            }
            //#endregion
@@ -2343,6 +3533,32 @@
            }
            //#endregion
            //#region æ ¹æ®ç‰©æ–™ID获取精度
            function getDecByMaterID(HMaterID) {
                var resultData = {};
                $.ajax({  // å¼‚步请求
                    url: GetWEBURL() + "Gy_Material/getDecByID",  //请求地址
                    async: false,   //是否开启异步
                    type: "GET",   //请求类型
                    data: {   //定义发送到服务器的数据
                        "HMaterID": HMaterID     //  å°†hmaterid作为请求参数发送
                    },
                    success: function (result) {   // å½“请求成功时,执行这个函数
                        if (result.code == 1) { // å¦‚果服务器返回的数据中的`code字段等于1,这可能表示审核操作成功执行
                            var data = result.data; //声明data变量,并将其赋值为result对象中的data属性
                            resultData = data[0];   //将data数组(或类数组对象)的第一个元素赋值给变量resultData
                        }
                        //else {
                        //    layer.alert(result.Message, { icon: 5, btn: ['退出'], time: 100000, offset: 't' }); //result.msg对象,提示弹窗 ç±»åž‹ä¸º5, æŒ‰é’®ï¼Œå’ŒæŒ‰é’®çš„名称为退出  æ—¶é—´ ä¸º100秒,以及偏移量(`offset: 't'
                        //}
                    }, error: function () {
                        layer.alert("发生错误!", { icon: 5 });  //提示弹窗 å‘生错误 ï¼Œè­¦ç¤ºæ ‡å¿—为5的
                    }
                });
                return resultData;
            }
            //#endregion
            //#region æ ¹æ®ä¸»å†…码与子内码获取源单采购入库单数据
            function getPushSource_POStockInBillInit(HSourceInterID, HSourceEntryID) {
                var res = "none";
@@ -2370,13 +3586,79 @@
            }
            //#endregion
            //#region æ ¹æ®ä¸»å†…码与子内码获取源单采购订单币别汇率
            function getPushSource_POOrderBillCur(HSourceInterID, HSourceEntryID) {
                var res = "none";
                $.ajax({
                    url: GetWEBURL() + "/Cg_POOrderBill/loadCg_POOrderBill_Push",
                    async: false,
                    type: "GET",
                    data: {
                        "HInterID": HSourceInterID
                        , "HSubID": HSourceEntryID
                    },
                    success: function (result) {
                        if (result.code == 1) { // è¯´æ˜ŽéªŒè¯æˆåŠŸäº†ï¼Œ
                            res = result.data[0];
                            form.val("component-form-group", { //formTest å³ class="layui-form" æ‰€åœ¨å…ƒç´ å±žæ€§ lay-filter="" å¯¹åº”的值
                                "HCurID": res.HCurID
                                , "HCurName": res.币别
                                , "HExRate": res.汇率
                            });
                        } else {
                            res = result.data;
                            //layer.alert(result.msg, { icon: 5, btn: ['退出'], time: 100000, offset: 't' });
                        }
                    }, error: function () {
                        res = "none";
                        layer.alert("发生错误!", { icon: 5 });
                    }
                });
                return res;
            }
            //#endregion
            //#region æ ¹æ®ä¸»å†…码与子内码获取源单收料通知单币别汇率
            function getPushSource_POInStockBillCur(HSourceInterID, HSourceEntryID) {
                var res = "none";
                $.ajax({
                    url: GetWEBURL() + "/Cg_POInStockBill/loadCg_POInStockBill_Push",
                    async: false,
                    type: "GET",
                    data: {
                        "HInterID": HSourceInterID
                        , "HSubID": HSourceEntryID
                    },
                    success: function (result) {
                        if (result.code == 1) { // è¯´æ˜ŽéªŒè¯æˆåŠŸäº†ï¼Œ
                            res = result.data[0];
                            form.val("component-form-group", { //formTest å³ class="layui-form" æ‰€åœ¨å…ƒç´ å±žæ€§ lay-filter="" å¯¹åº”的值
                                "HCurID": res.HCurID
                                , "HCurName": res.币别
                                , "HExRate": res.汇率
                            });
                        } else {
                            res = result.data;
                            //layer.alert(result.msg, { icon: 5, btn: ['退出'], time: 100000, offset: 't' });
                        }
                    }, error: function () {
                        res = "none";
                        layer.alert("发生错误!", { icon: 5 });
                    }
                });
                return res;
            }
            //#endregion
            //#endregion
            //以上是layui模块
        });
        //双击返回货币
        function GetGyCur(data) {
            OptionData = data
        }
        // åŸºç¡€èµ„料返回数据
        function GetHEmpValue(obj)  //返回业务员
        {
@@ -2452,8 +3734,8 @@
        //双击返回计量单位
         function GetGyUnit(data) {
             OptionData = data
        function GetUnitValue(data) {
             OptionData = data[0]
         }
            //双击返回物料