From 53ec31f86cf00a9f8b90edc0a601f99e5e7dfd81 Mon Sep 17 00:00:00 2001
From: duhe <226547893@qq.com>
Date: 星期六, 15 三月 2025 23:02:50 +0800
Subject: [PATCH] 采购订单:列表页面 同一个单据,只有第一条记录显示第一行记录的主表数据

---
 WebTM/views/销售管理/应收单/Xs_ReceivableBill.html | 2016 +++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 1,617 insertions(+), 399 deletions(-)

diff --git "a/WebTM/views/\351\224\200\345\224\256\347\256\241\347\220\206/\345\272\224\346\224\266\345\215\225/Xs_ReceivableBill.html" "b/WebTM/views/\351\224\200\345\224\256\347\256\241\347\220\206/\345\272\224\346\224\266\345\215\225/Xs_ReceivableBill.html"
index 4c36e12..f7b4108 100644
--- "a/WebTM/views/\351\224\200\345\224\256\347\256\241\347\220\206/\345\272\224\346\224\266\345\215\225/Xs_ReceivableBill.html"
+++ "b/WebTM/views/\351\224\200\345\224\256\347\256\241\347\220\206/\345\272\224\346\224\266\345\215\225/Xs_ReceivableBill.html"
@@ -47,6 +47,7 @@
                         <div class="layui-btn-group">
                             <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 +55,8 @@
                         <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">
                             <!--鍩烘湰淇℃伅-->
@@ -64,7 +66,7 @@
                                         <div class="layui-inline">
                                             <label class="layui-form-label">鍗曟嵁缂栧彿</label>
                                             <div class="layui-input-inline">
-                                                <input type="text" class="layui-input" name="HBillNo" id="HBillNo" style="background-color:#efefef4d;" readonly>
+                                                <input type="text" class="layui-input" name="HBillNo" id="HBillNo" style="background-color:#efefef4d;">
                                                 <input type="hidden" name="HInterID" id="HInterID" value="0">
                                             </div>
                                         </div>
@@ -81,9 +83,9 @@
                                                     <!--鍔ㄦ�佹覆鏌撴簮鍗曠被鍨�-->
                                                 </select>
                                                 <!--<select name="BillType" id="BillType" lay-filter="BillType" style="width: 180px; ">
-                                                    <option style="color:blue;" selected="selected" value="1401">閿�鍞鍗�</option>
-                                                    <option style="color:blue;" value="1205">閿�鍞嚭搴撳崟</option>
-                                                </select>-->
+                    <option style="color:blue;" selected="selected" value="1401">閿�鍞鍗�</option>
+                    <option style="color:blue;" value="1205">閿�鍞嚭搴撳崟</option>
+                </select>-->
                                             </div>
                                         </div>
                                         <div class="layui-inline">
@@ -92,7 +94,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;">
                                                 <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>
@@ -101,33 +103,23 @@
                                     </div>
                                     <div class="layui-row">
                                         <div class="layui-inline">
-                                            <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;" readonly>
-                                                <input type="hidden" name="HEmpID" id="HEmpID" class="layui-input" value="0" style="float:left;width:150px;">
-                                                <!--<button type="button" lay-submit="" class="layui-btn" lay-filter="HEmpList" 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>
                                             <div class="layui-input-inline">
-                                                <input type="text" name="HDeptName" id="HDeptName" class="layui-input" value="" style="background-color:#efefef4d;" readonly>
-                                                <input type="hidden" name="HDeptID" id="HDeptID" class="layui-input" value="0" style="float:left;width:150px;">
-                                                <!--<button type="button" lay-submit="" class="layui-btn" lay-filter="hdeptlist" style="width:40px;">
+                                                <input type="text" name="HDeptName" id="HDeptName" class="layui-input" value="" style="background-color: #efefef4d; float: left; width: 150px;" readonly>
+                                                <input type="hidden" name="HDeptID" id="HDeptID" class="layui-input" value="0" style="float: left; width: 110px;">
+                                                <button type="button" lay-submit="" class="layui-btn" lay-filter="HDeptList" style="width:40px;">
                                                     <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="margin-left:-9px;"></i>
-                                                </button>-->
+                                                </button>
                                             </div>
                                         </div>
                                         <div class="layui-inline">
                                             <label class="layui-form-label">涓荤</label>
                                             <div class="layui-input-inline">
-                                                <input type="text" name="HMangerName" id="HMangerName" class="layui-input" value="" style="background-color:#efefef4d;" readonly>
+                                                <input type="text" name="HMangerName" id="HMangerName" class="layui-input" value="" style="background-color: #efefef4d; float: left; width: 150px;" readonly>
                                                 <input type="hidden" name="HMangerID" id="HMangerID" class="layui-input" value="0" style="float:left;width:150px;">
-                                                <!--<button type="button" lay-submit="" class="layui-btn" lay-filter="HManagerList" style="width:40px;">
+                                                <button type="button" lay-submit="" class="layui-btn" lay-filter="HManagerList" style="width:40px;">
                                                     <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="margin-left:-9px;"></i>
-                                                </button>-->
+                                                </button>
                                             </div>
                                         </div>
                                         <div class="layui-inline">
@@ -136,54 +128,27 @@
                                                 <input type="text" name="HCusName" id="HCusName" class="layui-input" value="" style="background-color:#efefef4d;" readonly>
                                                 <input type="hidden" name="HCusID" id="HCusID" class="layui-input" value="0" style="float:left;width:150px;">
                                                 <!--<button type="button" lay-submit="" class="layui-btn" lay-filter="HCusList" 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">
+                                            <label class="layui-form-label">鍗曚环绫诲瀷</label>
+                                            <div class="layui-input-inline">
+                                                <select name="HPriceType" id="HPriceType" lay-filter="HPriceType" style="width: 190px; ">
+                                                    <option value="鍘荤◣浠�">鍘荤◣浠�</option>
+                                                    <option value="缁撶畻浠�" selected="selected">缁撶畻浠�</option>
+                                                    <option value="鍚◣浠�">鍚◣浠�</option>
+                                                </select>
                                             </div>
                                         </div>
                                     </div>
                                     <div class="layui-row">
                                         <div class="layui-inline">
-                                            <label class="layui-form-label">甯佸埆</label>
+                                            <label class="layui-form-label">椤圭洰鍚嶇О</label>
                                             <div class="layui-input-inline">
-                                                <input type="text" name="HCurName" id="HCurName" class="layui-input" value="" style="background-color:#efefef4d;" 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>
-                                            <div class="layui-input-inline">
-                                                <input type="text" name="HSellSName" id="HSellSName" class="layui-input" value="" style="background-color:#efefef4d;" readonly>
-                                                <input type="hidden" name="HSellSID" id="HSellSID" class="layui-input" value="0" style="float:left;width:150px;">
-                                                <!--<button type="button" lay-submit="" class="layui-btn" lay-filter="hsellslist" 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 type="text" name="HSSName" id="HSSName" class="layui-input" value="" style="background-color:#efefef4d;" 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 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;">
+                                                <input type="text" name="HProjectName" id="HProjectName" class="layui-input" lay-filter="HProjectName" value="" style="background-color:#efefef4d;" readonly>
+                                                <input type="hidden" name="HProjectID" id="HProjectID" class="layui-input" value="0" style="float:left;width:150px;">
                                             </div>
                                         </div>
                                     </div>
@@ -195,16 +160,7 @@
                                             </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 class="layui-row" style="display:none;">
@@ -224,6 +180,81 @@
                                             <label class="layui-form-label">鍐呴儴鍗曟嵁鍙�</label>
                                             <div class="layui-input-inline">
                                                 <input class="layui-input" name="HInnerBillNo" id="HInnerBillNo" value="" autocomplete="off">
+                                            </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="HEmpName" id="HEmpName" class="layui-input" value="" style="background-color:#efefef4d;" readonly>
+                                                <input type="hidden" name="HEmpID" id="HEmpID" class="layui-input" value="0" style="float:left;width:150px;">
+                                                <!--<button type="button" lay-submit="" class="layui-btn" lay-filter="HEmpList" 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>
+                                            <div class="layui-input-inline">
+                                                <input type="text" name="HCurName" id="HCurName" class="layui-input" value="" style="background-color:#efefef4d;" 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>
+                                            <div class="layui-input-block">
+                                                <input type="date" class="layui-input" lay-verify="HReceiveDate" name="HReceiveDate" id="HReceiveDate" style="width:190px;">
+                                            </div>
+                                        </div>
+                                    </div>
+                                    <div class="layui-row">
+
+                                        <div class="layui-inline">
+                                            <label class="layui-form-label">閿�鍞柟寮�</label>
+                                            <div class="layui-input-inline">
+                                                <input type="text" name="HSellSName" id="HSellSName" class="layui-input" value="" style="background-color:#efefef4d;" readonly>
+                                                <input type="hidden" name="HSellSID" id="HSellSID" class="layui-input" value="0" style="float:left;width:150px;">
+                                                <!--<button type="button" lay-submit="" class="layui-btn" lay-filter="hsellslist" 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>
+                                            <div class="layui-input-inline">
+                                                <input type="text" name="HSSName" id="HSSName" class="layui-input" value="" style="background-color:#efefef4d;" 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" 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>
@@ -305,20 +336,37 @@
                         </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 +378,8 @@
     <script>
         //#region 鎶樺彔娉ㄩ噴
         //#endregion
+        //鏄惁鏈夋簮鍗�
+        var haveSource = false;
         layui.config({
             base: '../../../layuiadmin/' //闈欐�佽祫婧愭墍鍦ㄨ矾寰�
         }).extend({
@@ -346,10 +396,10 @@
 
             var allVal;
             var HModName = "Xs_ReceivableBill";
-
+            window.OptionData = [];
             //璁板綍缁勭粐鐨勫��
             var HOrgIDBar = 0;
-
+            var topScroll = 0;//璁板綍婊氬姩鏉$殑浣嶇疆
 
         //#region 銆愬姩鎬佽幏鍙栨ā鍧楀悕绉般��
             var HModuleType = "1426";
@@ -383,6 +433,11 @@
             //鍒濆鍖栧瓙琛�
             set_InitGrid();
 
+            //鍒濆鍖栫粍缁�
+            Organ();
+
+            //鑾峰彇婧愬崟绫诲瀷
+            HBillType();
             //#region 鍒ゆ柇鎿嶄綔绫诲瀷骞跺垵濮嬪寲鐣岄潰
             if (OperationType == 1) {                                                   //鏃犳簮鍗曟柊澧�
                /* $("#HItemID").val(0);*/
@@ -415,11 +470,7 @@
 
             DisPlay_HideColumn();
 
-            //鍒濆鍖栫粍缁�
-            Organ();
-
-            //鑾峰彇婧愬崟绫诲瀷
-            HBillType();
+            
 
             //#endregion
 
@@ -439,6 +490,12 @@
             //#region 瀹℃牳鎸夐挳
             form.on('submit(set_CheckBill)', function (data) {
                 set_CheckBill(0);
+            });
+            //#endregion
+
+            //#region 閫夋暣鍗�
+            form.on('submit(set_SelectMainBill)', function (data) {
+                set_SelectMainBill();
             });
             //#endregion
 
@@ -495,9 +552,9 @@
                 }
                 //#endregion
 
-                //if (AllowLoadData(data)) {
+                if (AllowLoadData(data)) {
                     set_SaveBill(data);
-                //}
+                }
             });
             //#endregion
             //#endregion
@@ -551,6 +608,243 @@
             });
             //#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() == "1401") {
+                        //婧愬崟绫诲瀷鏄攢鍞鍗�
+                        url = "/Xs_SeOrderBill/PushList";
+                    } else if ($("#BillType").val() == "1205") {
+                        //婧愬崟绫诲瀷鏄攢鍞嚭搴撳崟
+                        url = "/Kf_SellOutBill/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() == "1401") {
+                                    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].涓氬姟鍛�
+                                        , "HCusID": dataArray[0].HCusID
+                                        , "HCusName": dataArray[0].瀹㈡埛
+                                        , "HCurID": dataArray[0].HCurID
+                                        , "HCurName": dataArray[0].甯佸埆
+                                        , "HExRate": dataArray[0].姹囩巼
+                                        , "HSSID": dataArray[0].HSSID
+                                        , "HSSName": dataArray[0].缁撶畻鏂瑰紡
+                                        , "HSellSID": dataArray[0].HSellSID
+                                        , "HSellSName": dataArray[0].閿�鍞柟寮�
+                                        , "HProjectID": (dataArray[0].HProjectID == null ? 0 : dataArray[0].HProjectID)
+                                        , "HProjectName": (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
+                                                , "鐗╂枡浠g爜": dataArray[i].鐗╂枡浠g爜
+                                                , "鐗╂枡鍚嶇О": dataArray[i].鐗╂枡鍚嶇О
+                                                , "瑙勬牸鍨嬪彿": dataArray[i].瑙勬牸鍨嬪彿
+                                                , "HUnitID": dataArray[i].HUnitID
+                                                , "璁¢噺鍗曚綅": dataArray[i].璁¢噺鍗曚綅
+                                                , "HQty": dealDoubleToFixed(HQty, 1)
+                                                , "HPrice": dealDoubleToFixed(dataArray[i].鍗曚环, 3)
+                                                , "HTaxPrice": dealDoubleToFixed(dataArray[i].HTaxPrice, 3)
+                                                , 'HDiscountRate': "1"                                                     //
+                                                , 'HRelTaxPrice': dealDoubleToFixed(dataArray[i].HTaxPrice, 3)
+                                                , "HTaxRate": dataArray[i].绋庣巼
+                                                , 'HTaxMoney': dealDoubleToFixed(HTaxMoney, 2)                                                         //
+                                                , "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].HBillType
+                                                , "HRelationQty": "0"
+                                                , "HRelationMoney": "0"
+
+                                                , 'HPOOrderInterID': "0"
+                                                , 'HPOOrderEntryID': "0"
+                                                , 'HPOOrderBillNo': ""
+
+                                                , 'HSeOrderTaxPrice': dealDoubleToFixed(dataArray[i].HTaxPrice, 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[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;
+                                    haveSource = true;
+
+                                } else if ($("#BillType").val() == "1205") {
+                                    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].涓氬姟鍛�
+                                        , "HCusID": dataArray[0].HSupID
+                                        , "HCusName": dataArray[0].瀹㈡埛
+                                        , "HCurID": dataArray[0].HCurID
+                                        , "HCurName": dataArray[0].甯佸埆
+                                        , "HExRate": dataArray[0].姹囩巼
+                                        , "HSSID": "0"
+                                        , "HSSName": ""
+                                        , "HSellSID": dataArray[0].HSellSID
+                                        , "HSellSName": dataArray[0].閿�鍞柟寮�
+                                        , "HProjectName": dataArray[0].椤圭洰鍚嶇О
+                                        , "HProjectID": (dataArray[0].HProjectID == null ? 0 : dataArray[0].HProjectID)
+                                    });
+                                    //瀛愯〃  璧嬪��
+                                    var rowdataEntry = [];
+                                    for (var i = 0; i < dataArray.length; i++) {
+                                        var HQty = dataArray[i].鏁伴噺 - dataArray[i].鍏宠仈鏁伴噺;                           //鏁伴噺
+                                        rowdataEntry.push(
+                                            {
+                                                "HMaterID": dataArray[i].HMaterID
+                                                , "鐗╂枡浠g爜": dataArray[i].鐗╂枡浠g爜
+                                                , "鐗╂枡鍚嶇О": 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': dealDoubleToFixed(HQty * dataArray[i].鍗曚环 * dataArray[0].绋庣巼, 2)                                                         //
+                                                , "HMoney": dealDoubleToFixed(HQty * dataArray[i].鍗曚环, 2)
+                                                , 'HMoneyBB': dealDoubleToFixed(HQty * dataArray[i].鍗曚环 * dataArray[0].姹囩巼, 2)
+                                                , 'HlineTotal': dealDoubleToFixed(HQty * dataArray[i].鍚◣鍗曚环, 2)
+                                                , 'HlineTotalBB': dealDoubleToFixed(HQty * dataArray[i].鍚◣鍗曚环 * dataArray[0].姹囩巼, 2)
+                                                , "HRemark": ""
+
+                                                , "HSourceInterID": dataArray[i].hmainid
+                                                , "HSourceEntryID": dataArray[i].hsubid
+                                                , "HSourceBillNo": dataArray[i].鍗曟嵁鍙�
+                                                , "HSourceBillType": dataArray[i].HBillType
+                                                , "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[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;
+                                    haveSource = true;
+
+                                }
+                                table.render(option);
+                                changeHPrice();
+                                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 澶嶉�夋鐘舵�佸彉鏇�
@@ -572,7 +866,7 @@
                     , "HQty": "0"
                     , "HPrice": "0"
                     , "HTaxPrice": "0"
-                    , 'HDiscountRate': "0"
+                    , 'HDiscountRate': "1"
                     , 'HRelTaxPrice': "0"
                     , "HTaxRate": "0"
                     , 'HTaxMoney': "0"
@@ -619,6 +913,12 @@
                     case 'set_HideColumn':
                         get_HideColumn();
                         break;
+                    //搴撳瓨鏌ヨ
+                    case 'get_Inventory': get_Inventory();
+                        break;
+                    //鍑哄叆搴撹褰曟煡璇�
+                    case 'get_InOutSum': get_InOutSum();
+                        break;
                 }
             });
             //#endregion
@@ -634,8 +934,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 //寰楀埌淇敼鍚庣殑鍊�
@@ -643,191 +948,396 @@
                     , field = obj.field; //寰楀埌瀛楁
                 //layer.msg('[ID: ' + data.id + '] ' + field + ' 瀛楁鏇存敼涓猴細' + value);
 
-                //switch (field) {
-                //    case "HQty":                                                       //鏁伴噺
-                //        //鏁版嵁鏍煎紡鏍¢獙
-                //        temp = value + "";
-                //        if (!ref.test(temp) || temp == 0) {
-                //            //鎭㈠鏁版嵁鍒扮紪杈戝墠
-                //            obj.update({
-                //                HQty: oldText
-                //            });
-                //            table.render(option);
+                switch (field) {
+                    case "HQty":                                                       //鏁伴噺
+                        //鏁版嵁鏍煎紡鏍¢獙
+                        temp = value + "";
+                        if (!ref1.test(temp)) {
+                            //鎭㈠鏁版嵁鍒扮紪杈戝墠
+                            obj.update({
+                                HQty: oldText
+                            });
+                            table.render(option);
 
-                //            layer.msg("鏁伴噺璇疯緭鍏ュぇ浜�0鐨勬暟瀛�!");
-                //            return;
-                //        }
+                            layer.msg("鏁伴噺璇疯緭鍏ヤ笉涓�0鐨勬暟瀛�!");
+                            return;
+                        } else if (temp * 1 == 0) {
+                            //鎭㈠鏁版嵁鍒扮紪杈戝墠
+                            obj.update({
+                                HQty: oldText
+                            });
+                            table.render(option);
+
+                            layer.msg("鏁伴噺璇疯緭鍏ヤ笉涓�0鐨勬暟瀛�!");
+                            return;
+                        }
+
+                        //鏁版嵁鏍¢獙鍚堟牸锛岄噸绠楄褰�
+                        var HQty = value * 1;                   //鏁伴噺
+                        var HPrice = obj.data.HPrice * 1;
+                        var HMoney = HQty * HPrice;                     //閲戦=鏁伴噺*鍗曚环
+                        var HTaxRate = obj.data.HTaxRate * 0.01;           //绋庣巼 
+                        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 HExRate = $("#HExRate").val();                      //姹囩巼
+                        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));
+                        HMoneyBB = Number(HMoneyBB.toFixed(HMoneyDec));
+                        HlineTotal = Number(HlineTotal.toFixed(HMoneyDec));
+                        HTaxPrice = Number(HTaxPrice.toFixed(HPriceDec));
+                        HRelTaxPrice = Number(HRelTaxPrice.toFixed(HPriceDec));
+                        HlineTotalBB = Number(HlineTotalBB.toFixed(HMoneyDec));
+
+                        //鍚屾鏇存柊琛ㄦ牸鍜岀紦瀛樺搴旂殑鍊�
+                        obj.update({
+                            HQty: HQty                          //鏇存柊HQty瀛楁锛孒Qty
+                            , HPrice: HPrice                     //鏇存柊HPrice瀛楁锛孒Price
+                            , HMoney: HMoney                      //鏇存柊HMoney瀛楁锛孒Money
+                            , HTaxMoney: HTaxMoney                  //鏇存柊HTaxMoney瀛楁锛孒TaxMoney
+                            , HlineTotal: HlineTotal             //鏇存柊HlineTotal瀛楁锛孒lineTotal
+                            , HTaxPrice, HTaxPrice                   //鏇存柊HTaxPrice瀛楁锛孒TaxPrice
+                            , HRelTaxPrice: HRelTaxPrice            //鏇存柊HRelTaxPrice瀛楁锛屽叾鍊兼潵鑷彉閲廐RelTaxPrice
+                            , HlineTotalBB: HlineTotalBB              //鏇存柊HlineTotalBB瀛楁锛屽叾鍊兼潵鑷彉閲廐lineTotalBB
+                            , HMoneyBB: HMoneyBB
+                        });
+                        table.render(option);
+                        break;
+                    case "HPrice":                                                       //鍗曚环
+                        //鏁版嵁鏍煎紡鏍¢獙
+                        temp = value + "";
+                        if (!ref.test(temp) || temp == 0) {
+                            //鎭㈠鏁版嵁鍒扮紪杈戝墠
+                            obj.update({
+                                HPrice: oldText
+                            });
+                            table.render(option);
+
+                            layer.msg("鍗曚环璇疯緭鍏ュぇ浜�0鐨勬暟瀛�!");
+                            return;
+                        }
 
 
-                //        //鏁版嵁鏍¢獙鍚堟牸锛岄噸绠楄褰�
-                //        var HQty = value * 1;                           //鏁伴噺
-                //        var HPrice = obj.data.HPrice * 1;               //鍗曚环
-                //        var HTaxRate = obj.data.HTaxRate * 0.01;           //绋庣巼
-                //        /*var HDiscountRate = obj.data.HDiscountRate * 1; //鎶樻墸鐜�*/
-                //        var HTaxPrice = HPrice * (1 + HTaxRate);        //鍚◣鍗曚环=鍗曚环*(1+绋庣巼)
-                //        /*var HRelTaxPrice = HTaxPrice * HDiscountRate;   //瀹為檯鍚◣鍗曚环=鍚◣鍗曚环*鎶樻墸鐜�*/
-                //        //鎶樻墸棰� = 鍚◣鍗曚环 * (1 - 鎶樻墸鐜�) * 鏁伴噺
-                //        var HMoney = HQty * HPrice;                     //閲戦=鏁伴噺*鍗曚环
-                //        var HTaxMoney = HMoney * (1 + HTaxRate);            //浠风◣鍚堣=閲戦 * (1 + 绋庣巼)
+                        //鏁版嵁鏍¢獙鍚堟牸锛岄噸绠楄褰�
+                        var HQty = obj.data.HQty * 1;                   //鏁伴噺
+                        var HPrice = value * 1;                         //鍗曚环
+                        var HMoney = HQty * HPrice;                     //閲戦=鏁伴噺*鍗曚环
+                        var HTaxRate = obj.data.HTaxRate * 0.01;           //绋庣巼
+                        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 HExRate = $("#HExRate").val();                      //姹囩巼
+                        var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate));     //鏈綅甯佷环绋庡悎璁�=(绋庨+閲戦)*姹囩巼
+                        var HMoneyBB = HMoney * HExRate;
 
-                //        //璁剧疆鏁版嵁灏忔暟浣嶆暟
-                //        HQty = dealDoubleToFixed(HQty, 1);
-                //        HPrice = dealDoubleToFixed(HPrice, 3);
-                //        HTaxRate = HTaxRate;
-                //        HTaxPrice = dealDoubleToFixed(HTaxPrice, 3);
-                //        HMoney = dealDoubleToFixed(HMoney, 2);
-                //        HTaxMoney = dealDoubleToFixed(HTaxMoney, 2);
+                        //鏁板瓧绮惧害
+                        HQty = Number(HQty.toFixed(HQtyDec));
+                        HPrice = Number(HPrice.toFixed(HPriceDec));
+                        HMoney = Number(HMoney.toFixed(HMoneyDec));
+                        HTaxMoney = Number(HTaxMoney.toFixed(HMoneyDec));
+                        HMoneyBB = Number(HMoneyBB.toFixed(HMoneyDec));
+                        HlineTotal = Number(HlineTotal.toFixed(HMoneyDec));
+                        HTaxPrice = Number(HTaxPrice.toFixed(HPriceDec));
+                        HRelTaxPrice = Number(HRelTaxPrice.toFixed(HPriceDec));
+                        HlineTotalBB = Number(HlineTotalBB.toFixed(HMoneyDec));
 
-                //        //鍚屾鏇存柊琛ㄦ牸鍜岀紦瀛樺搴旂殑鍊�
-                //        obj.update({
-                //            HQty: HQty
-                //            , HPrice: HPrice
-                //            , HTaxRate: HTaxRate * 100
-                //            , HTaxPrice: HTaxPrice
-                //            , HMoney: HMoney
-                //            , HTaxMoney: HTaxMoney
-                //        });
-                //        table.render(option);
-                //        break;
-                //    case "HPrice":                                                       //鍗曚环
-                //        //鏁版嵁鏍煎紡鏍¢獙
-                //        temp = value + "";
-                //        if (!ref.test(temp) || temp == 0) {
-                //            //鎭㈠鏁版嵁鍒扮紪杈戝墠
-                //            obj.update({
-                //                HPrice: oldText
-                //            });
-                //            table.render(option);
+                        //鍚屾鏇存柊琛ㄦ牸鍜岀紦瀛樺搴旂殑鍊�
+                        obj.update({
+                            HQty: HQty                          //鏇存柊HQty瀛楁锛孒Qty
+                            , HPrice: HPrice                     //鏇存柊HPrice瀛楁锛孒Price
+                            , HMoney: HMoney                      //鏇存柊HMoney瀛楁锛孒Money
+                            , HTaxMoney: HTaxMoney                  //鏇存柊HTaxMoney瀛楁锛孒TaxMoney
+                            , HlineTotal: HlineTotal             //鏇存柊HlineTotal瀛楁锛孒lineTotal
+                            , HTaxPrice, HTaxPrice                   //鏇存柊HTaxPrice瀛楁锛孒TaxPrice
+                            , HRelTaxPrice: HRelTaxPrice            //鏇存柊HRelTaxPrice瀛楁锛屽叾鍊兼潵鑷彉閲廐RelTaxPrice
+                            , HlineTotalBB: HlineTotalBB              //鏇存柊HlineTotalBB瀛楁锛屽叾鍊兼潵鑷彉閲廐lineTotalBB
+                            , HMoneyBB: HMoneyBB
+                        });
+                        table.render(option);
+                        break;
+                    case "HTaxRate":                                                       //鏁伴噺
+                        //鏁版嵁鏍煎紡鏍¢獙
+                        temp = value + "";
+                        if (!ref.test(temp)) {
+                            //鎭㈠鏁版嵁鍒扮紪杈戝墠
+                            obj.update({
+                                HTaxRate: oldText
+                            });
+                            table.render(option);
 
-                //            layer.msg("鍗曚环璇疯緭鍏ュぇ浜�0鐨勬暟瀛�!");
-                //            return;
-                //        }
+                            layer.msg("绋庣巼璇疯緭鍏ヤ笉灏忎簬0鐨勬暟瀛�!");
+                            return;
+                        }
 
 
-                //        //鏁版嵁鏍¢獙鍚堟牸锛岄噸绠楄褰�
-                //        var HQty = obj.data.HQty * 1;                   //鏁伴噺
-                //        var HPrice = value * 1;                         //鍗曚环
-                //        var HTaxRate = obj.data.HTaxRate * 0.01;           //绋庣巼
-                //        /*var HDiscountRate = obj.data.HDiscountRate * 1; //鎶樻墸鐜�*/
-                //        var HTaxPrice = HPrice * (1 + HTaxRate);        //鍚◣鍗曚环=鍗曚环*(1+绋庣巼)
-                //        /*var HRelTaxPrice = HTaxPrice * HDiscountRate;   //瀹為檯鍚◣鍗曚环=鍚◣鍗曚环*鎶樻墸鐜�*/
-                //        //鎶樻墸棰� = 鍚◣鍗曚环 * (1 - 鎶樻墸鐜�) * 鏁伴噺
-                //        var HMoney = HQty * HPrice;                     //閲戦=鏁伴噺*鍗曚环
-                //        var HTaxMoney = HMoney * (1 + HTaxRate);            //浠风◣鍚堣=閲戦 * (1 + 绋庣巼)
+                        //鏁版嵁鏍¢獙鍚堟牸锛岄噸绠楄褰�
+                        var HQty = obj.data.HQty * 1;                   //鏁伴噺
+                        var HPrice = obj.data.HPrice * 1;               //鍗曚环
+                        var HTaxRate = value * 0.01;                       //绋庣巼
+                        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 HExRate = $("#HExRate").val();                      //姹囩巼
+                        var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate));     //鏈綅甯佷环绋庡悎璁�=(绋庨+閲戦)*姹囩巼
+                        var HMoneyBB = HMoney * HExRate;
 
-                //        //璁剧疆鏁版嵁灏忔暟浣嶆暟
-                //        HQty = dealDoubleToFixed(HQty, 1);
-                //        HPrice = dealDoubleToFixed(HPrice, 3);
-                //        HTaxRate = HTaxRate;
-                //        HTaxPrice = dealDoubleToFixed(HTaxPrice, 3);
-                //        HMoney = dealDoubleToFixed(HMoney, 2);
-                //        HTaxMoney = dealDoubleToFixed(HTaxMoney, 2);
+                        //鏁板瓧绮惧害
+                        HQty = Number(HQty.toFixed(HQtyDec));
+                        HPrice = Number(HPrice.toFixed(HPriceDec));
+                        HMoney = Number(HMoney.toFixed(HMoneyDec));
+                        HTaxMoney = Number(HTaxMoney.toFixed(HMoneyDec));
+                        HMoneyBB = Number(HMoneyBB.toFixed(HMoneyDec));
+                        HlineTotal = Number(HlineTotal.toFixed(HMoneyDec));
+                        HTaxPrice = Number(HTaxPrice.toFixed(HPriceDec));
+                        HRelTaxPrice = Number(HRelTaxPrice.toFixed(HPriceDec));
+                        HlineTotalBB = Number(HlineTotalBB.toFixed(HMoneyDec));
 
-                //        //鍚屾鏇存柊琛ㄦ牸鍜岀紦瀛樺搴旂殑鍊�
-                //        obj.update({
-                //            HQty: HQty
-                //            , HPrice: HPrice
-                //            , HTaxRate: HTaxRate * 100
-                //            , HTaxPrice: HTaxPrice
-                //            , HMoney: HMoney
-                //            , HTaxMoney: HTaxMoney
-                //        });
-                //        table.render(option);
-                //        break;
-                //    case "HTaxRate":                                                       //鏁伴噺
-                //        //鏁版嵁鏍煎紡鏍¢獙
-                //        temp = value + "";
-                //        if (!ref.test(temp)) {
-                //            //鎭㈠鏁版嵁鍒扮紪杈戝墠
-                //            obj.update({
-                //                HTaxRate: oldText
-                //            });
-                //            table.render(option);
-
-                //            layer.msg("绋庣巼璇疯緭鍏ヤ笉灏忎簬0鐨勬暟瀛�!");
-                //            return;
-                //        }
+                        //鍚屾鏇存柊琛ㄦ牸鍜岀紦瀛樺搴旂殑鍊�
+                        obj.update({
+                            HQty: HQty                          //鏇存柊HQty瀛楁锛孒Qty
+                            , HPrice: HPrice                     //鏇存柊HPrice瀛楁锛孒Price
+                            , HMoney: HMoney                      //鏇存柊HMoney瀛楁锛孒Money
+                            , HTaxMoney: HTaxMoney                  //鏇存柊HTaxMoney瀛楁锛孒TaxMoney
+                            , HlineTotal: HlineTotal             //鏇存柊HlineTotal瀛楁锛孒lineTotal
+                            , HTaxPrice, HTaxPrice                   //鏇存柊HTaxPrice瀛楁锛孒TaxPrice
+                            , HRelTaxPrice: HRelTaxPrice            //鏇存柊HRelTaxPrice瀛楁锛屽叾鍊兼潵鑷彉閲廐RelTaxPrice
+                            , HlineTotalBB: HlineTotalBB              //鏇存柊HlineTotalBB瀛楁锛屽叾鍊兼潵鑷彉閲廐lineTotalBB
+                            , HMoneyBB: HMoneyBB
+                        });
+                        table.render(option);
+                        break;
+                    case "HDiscountRate":                                                       //鏁伴噺
+                        //鏁版嵁鏍煎紡鏍¢獙
+                        temp = value + "";
+                        if (!ref.test(temp)) {
+                            //鎭㈠鏁版嵁鍒扮紪杈戝墠
+                            obj.update({
+                                HDiscountRate: oldText
+                            });
+                            table.render(option);
+                            layer.msg("鎶樻墸鐜囪杈撳叆涓嶅皬浜�0鐨勬暟瀛�!");
+                            return;
+                        }
 
 
-                //        //鏁版嵁鏍¢獙鍚堟牸锛岄噸绠楄褰�
-                //        var HQty = obj.data.HQty * 1;                   //鏁伴噺
-                //        var HPrice = obj.data.HPrice * 1;               //鍗曚环
-                //        var HTaxRate = value * 0.01;                       //绋庣巼
-                //        /*var HDiscountRate = obj.data.HDiscountRate * 1; //鎶樻墸鐜�*/
-                //        var HTaxPrice = HPrice * (1 + HTaxRate);        //鍚◣鍗曚环=鍗曚环*(1+绋庣巼)
-                //        /*var HRelTaxPrice = HTaxPrice * HDiscountRate;   //瀹為檯鍚◣鍗曚环=鍚◣鍗曚环*鎶樻墸鐜�*/
-                //        //鎶樻墸棰� = 鍚◣鍗曚环 * (1 - 鎶樻墸鐜�) * 鏁伴噺
-                //        var HMoney = HQty * HPrice;                     //閲戦=鏁伴噺*鍗曚环
-                //        var HTaxMoney = HMoney * (1 + HTaxRate);            //浠风◣鍚堣=閲戦 * (1 + 绋庣巼)
+                        //鏁版嵁鏍¢獙鍚堟牸锛岄噸绠楄褰�
+                        var HTaxRate = obj.data.HTaxRate * 0.01;           //绋庣巼 
+                        var HQty = obj.data.HQty * 1;                   //鏁伴噺
+                        var HPrice = obj.data.HPrice * 1;
+                        var HMoney = HQty * HPrice;                     //閲戦=鏁伴噺*鍗曚环
+                        var HTaxMoney = Number((HMoney * HTaxRate));         //绋庨=閲戦*绋庣巼
+                        var HTaxPrice = Number((HPrice * (1 + HTaxRate)));        //鍚◣鍗曚环=鍗曚环*(1+绋庣巼)
+                        var HDiscountRate = obj.data.HDiscountRate * 1;     //鎶樻墸鐜�
+                        var HRelTaxPrice = Number((HTaxPrice * HDiscountRate));   //瀹為檯鍚◣鍗曚环=鍚◣鍗曚环*鎶樻墸鐜�
+                        //鏁板瓧绮惧害
+                        HQty = Number(HQty.toFixed(HQtyDec));
+                        HPrice = Number(HPrice.toFixed(HPriceDec));
+                        HMoney = Number(HMoney.toFixed(HMoneyDec));
+                        HTaxMoney = Number(HTaxMoney.toFixed(HMoneyDec));
+                        HTaxPrice = Number(HTaxPrice.toFixed(HPriceDec));
+                        HRelTaxPrice = Number(HRelTaxPrice.toFixed(HPriceDec));
 
-                //        //璁剧疆鏁版嵁灏忔暟浣嶆暟
-                //        HQty = dealDoubleToFixed(HQty, 1);
-                //        HPrice = dealDoubleToFixed(HPrice, 3);
-                //        HTaxRate = HTaxRate;
-                //        HTaxPrice = dealDoubleToFixed(HTaxPrice, 3);
-                //        HMoney = dealDoubleToFixed(HMoney, 2);
-                //        HTaxMoney = dealDoubleToFixed(HTaxMoney, 2);
+                        //鍚屾鏇存柊琛ㄦ牸鍜岀紦瀛樺搴旂殑鍊�
+                        obj.update({
+                            HTaxRate: HTaxRate * 100                //灏咹TaxRate灞炴�х殑鍊间箻浠�100锛屽苟鏇存柊涓烘柊鐨勫��    绋庣巼涔�100  浠庡皬鏁扮被鍨嬪彉涓烘暣鏁版垨娴偣鍨�      
+                            , HQty: HQty                //鏇存柊HQty瀛楁锛岋紝鍏跺�兼潵鑷彉閲廐Qty
+                            , HPrice: HPrice                 //鏇存柊HPrice瀛楁锛屽叾鍊兼潵鑷彉閲廐Price
+                            , HMoney: HMoney                       //鏇存柊HMoney瀛楁锛屽叾鍊兼潵鑷彉閲廐Money
+                            , HTaxMoney: HTaxMoney                  //鏇存柊HTaxMoney瀛楁锛屽叾鍊兼潵鑷彉閲廐TaxMoney
+                            , HTaxPrice: HTaxPrice                  //鏇存柊HTaxPrice瀛楁锛屽叾鍊兼潵鑷彉閲廐TaxPrice
+                            , HDiscountRate: HDiscountRate                  //鏇存柊HDiscountRate瀛楁锛屽叾鍊兼潵鑷彉閲廐DiscountRate
+                            , HRelTaxPrice: HRelTaxPrice                  //鏇存柊HRelTaxPrice瀛楁锛屽叾鍊兼潵鑷彉閲廐RelTaxPrice
+                        });
+                        table.render(option);
+                        break;
+                    case "HTaxPrice":                                                       //鍚◣鍗曚环
+                        //鏁版嵁鏍煎紡鏍¢獙
+                        temp = value + "";
+                        if (!ref.test(temp)) {
+                            //鎭㈠鏁版嵁鍒扮紪杈戝墠
+                            obj.update({
+                                HTaxPrice: oldText
+                            });
+                            table.render(option);
 
-                //        //鍚屾鏇存柊琛ㄦ牸鍜岀紦瀛樺搴旂殑鍊�
-                //        obj.update({
-                //            HQty: HQty
-                //            , HPrice: HPrice
-                //            , HTaxRate: HTaxRate * 100
-                //            , HTaxPrice: HTaxPrice
-                //            , HMoney: HMoney
-                //            , HTaxMoney: HTaxMoney
-                //        });
-                //        table.render(option);
-                //        break;
-                //    case "HTaxPrice":                                                       //鏁伴噺
-                //        //鏁版嵁鏍煎紡鏍¢獙
-                //        temp = value + "";
-                //        if (!ref.test(temp)) {
-                //            //鎭㈠鏁版嵁鍒扮紪杈戝墠
-                //            obj.update({
-                //                HTaxPrice: oldText
-                //            });
-                //            table.render(option);
+                            layer.msg("鍚◣鍗曟嵁璇疯緭鍏ヤ笉灏忎簬0鐨勬暟瀛�!");
+                            return;
+                        }
+                        //鏁版嵁鏍¢獙鍚堟牸锛岄噸绠楄褰�
+                        var HTaxRate = obj.data.HTaxRate * 0.01;                       //绋庣巼
+                        var HTaxPrice = value * 1;                          //鍚◣鍗曚环=鍗曚环*(1+绋庣巼)
+                        var HPrice = HTaxPrice / (1 + HTaxRate);        //鍗曚环=鍚◣鍗曟嵁/(1+绋庣巼)
+                        var HQty = obj.data.HQty * 1;                   //鏁伴噺
+                        var HMoney = HQty * HPrice;                     //閲戦=鏁伴噺*鍗曚环
+                        var HTaxMoney = Number((HMoney * HTaxRate));         //绋庨=閲戦*绋庣巼
+                        var HlineTotal = HMoney + HTaxMoney;            //浠风◣鍚堣=閲戦+绋庨
+                        var HDiscountRate = obj.data.HDiscountRate * 1;   //鎶樻墸鐜�
+                        var HRelTaxPrice = Number((HTaxPrice * HDiscountRate));   //瀹為檯鍚◣鍗曚环=鍚◣鍗曚环*鎶樻墸鐜�
+                        var HExRate = $("#HExRate").val();                      //姹囩巼
+                        var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate));     //鏈綅甯佷环绋庡悎璁�=(绋庨+閲戦)*姹囩巼
+                        var HMoneyBB = HMoney * HExRate;
 
-                //            layer.msg("鍚◣鍗曟嵁璇疯緭鍏ヤ笉灏忎簬0鐨勬暟瀛�!");
-                //            return;
-                //        }
-                //        //鏁版嵁鏍¢獙鍚堟牸锛岄噸绠楄褰�
-                //        var HQty = obj.data.HQty * 1;                   //鏁伴噺
-                //        var HTaxRate = obj.data.HTaxRate * 0.01;        //绋庣巼
-                //        var HTaxPrice = value * 1;                          //鍚◣鍗曚环=鍗曚环*(1+绋庣巼)
-                //        var HPrice = HTaxPrice / (1 + HTaxRate);        //鍗曚环=鍚◣鍗曟嵁/(1+绋庣巼)
+                        ///鏁板瓧绮惧害
+                        HQty = Number(HQty.toFixed(HQtyDec));
+                        HPrice = Number(HPrice.toFixed(HPriceDec));
+                        HMoney = Number(HMoney.toFixed(HMoneyDec));
+                        HTaxMoney = Number(HTaxMoney.toFixed(HMoneyDec));
+                        HMoneyBB = Number(HMoneyBB.toFixed(HMoneyDec));
+                        HlineTotal = Number(HlineTotal.toFixed(HMoneyDec));
+                        HTaxPrice = Number(HTaxPrice.toFixed(HPriceDec));
+                        HRelTaxPrice = Number(HRelTaxPrice.toFixed(HPriceDec));
+                        HlineTotalBB = Number(HlineTotalBB.toFixed(HMoneyDec));
 
-                //        /*var HDiscountRate = obj.data.HDiscountRate * 1; //鎶樻墸鐜�*/
+                        //鍚屾鏇存柊琛ㄦ牸鍜岀紦瀛樺搴旂殑鍊�
+                        obj.update({
+                            HQty: HQty                          //鏇存柊HQty瀛楁锛孒Qty
+                            , HPrice: HPrice                     //鏇存柊HPrice瀛楁锛孒Price
+                            , HMoney: HMoney                      //鏇存柊HMoney瀛楁锛孒Money
+                            , HTaxMoney: HTaxMoney                  //鏇存柊HTaxMoney瀛楁锛孒TaxMoney
+                            , HlineTotal: HlineTotal             //鏇存柊HlineTotal瀛楁锛孒lineTotal
+                            , HTaxPrice, HTaxPrice                   //鏇存柊HTaxPrice瀛楁锛孒TaxPrice
+                            , HRelTaxPrice: HRelTaxPrice            //鏇存柊HRelTaxPrice瀛楁锛屽叾鍊兼潵鑷彉閲廐RelTaxPrice
+                            , HlineTotalBB: HlineTotalBB              //鏇存柊HlineTotalBB瀛楁锛屽叾鍊兼潵鑷彉閲廐lineTotalBB
+                            , HMoneyBB: HMoneyBB
+                        });
+                        table.render(option)
+                        break;
+                    case "HMoney":                                                       //閲戦
+                        //鏁版嵁鏍煎紡鏍¢獙
+                        temp = value + "";
+                        if (!ref.test(temp) || temp == 0 || obj.data.HQty == 0) {
+                            //鎭㈠鏁版嵁鍒扮紪杈戝墠
+                            obj.update({
+                                HMoney: oldText
+                            });
+                            table.render(option);
 
-                //        /*var HRelTaxPrice = HTaxPrice * HDiscountRate;   //瀹為檯鍚◣鍗曚环=鍚◣鍗曚环*鎶樻墸鐜�*/
-                //        //鎶樻墸棰� = 鍚◣鍗曚环 * (1 - 鎶樻墸鐜�) * 鏁伴噺
-                //        var HMoney = HQty * HPrice;                     //閲戦=鏁伴噺*鍗曚环
-                //        var HTaxMoney = HMoney * (1 + HTaxRate);            //浠风◣鍚堣=閲戦 * (1 + 绋庣巼)
+                            layer.msg("鏁伴噺鎴栭噾棰濊杈撳叆澶т簬0鐨勬暟瀛�!");
+                            return;
+                        }
 
-                //        //璁剧疆鏁版嵁灏忔暟浣嶆暟
-                //        HQty = dealDoubleToFixed(HQty, 1);
-                //        HPrice = dealDoubleToFixed(HPrice, 3);
-                //        HTaxRate = HTaxRate;
-                //        HTaxPrice = dealDoubleToFixed(HTaxPrice, 3);
-                //        HMoney = dealDoubleToFixed(HMoney, 2);
-                //        HTaxMoney = dealDoubleToFixed(HTaxMoney, 2);
 
-                //        //鍚屾鏇存柊琛ㄦ牸鍜岀紦瀛樺搴旂殑鍊�
-                //        obj.update({
-                //            HQty: HQty
-                //            , HPrice: HPrice
-                //            , HTaxRate: HTaxRate * 100
-                //            , HTaxPrice: HTaxPrice
-                //            , HMoney: HMoney
-                //            , HTaxMoney: HTaxMoney
-                //        });
-                //        table.render(option);
-                //        break;
-                //    default:
-                //}
+                        //鏁版嵁鏍¢獙鍚堟牸锛岄噸绠楄褰�
+                        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));         //绋庨=閲戦*绋庣巼
+                        var HlineTotal = HMoney + HTaxMoney;            //浠风◣鍚堣=閲戦+绋庨
+                        var HTaxPrice = Number((HPrice * (1 + HTaxRate)));        //鍚◣鍗曚环=鍗曚环*(1+绋庣巼)
+                        var HDiscountRate = obj.data.HDiscountRate * 1;   //鎶樻墸鐜�
+                        var HRelTaxPrice = Number((HTaxPrice * HDiscountRate));   //瀹為檯鍚◣鍗曚环=鍚◣鍗曚环*鎶樻墸鐜�
+                        var HExRate = $("#HExRate").val();                      //姹囩巼
+                        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));
+                        HMoneyBB = Number(HMoneyBB.toFixed(HMoneyDec));
+                        HlineTotal = Number(HlineTotal.toFixed(HMoneyDec));
+                        HTaxPrice = Number(HTaxPrice.toFixed(HPriceDec));
+                        HRelTaxPrice = Number(HRelTaxPrice.toFixed(HPriceDec));
+                        HlineTotalBB = Number(HlineTotalBB.toFixed(HMoneyDec));
+
+                        //鍚屾鏇存柊琛ㄦ牸鍜岀紦瀛樺搴旂殑鍊�
+                        obj.update({
+                            HQty: HQty                          //鏇存柊HQty瀛楁锛孒Qty
+                            , HPrice: HPrice                     //鏇存柊HPrice瀛楁锛孒Price
+                            , HMoney: HMoney                      //鏇存柊HMoney瀛楁锛孒Money
+                            , HTaxMoney: HTaxMoney                  //鏇存柊HTaxMoney瀛楁锛孒TaxMoney
+                            , HlineTotal: HlineTotal             //鏇存柊HlineTotal瀛楁锛孒lineTotal
+                            , HTaxPrice, HTaxPrice                   //鏇存柊HTaxPrice瀛楁锛孒TaxPrice
+                            , HRelTaxPrice: HRelTaxPrice            //鏇存柊HRelTaxPrice瀛楁锛屽叾鍊兼潵鑷彉閲廐RelTaxPrice
+                            , HlineTotalBB: HlineTotalBB              //鏇存柊HlineTotalBB瀛楁锛屽叾鍊兼潵鑷彉閲廐lineTotalBB
+                            , HMoneyBB: HMoneyBB
+                        });
+                        table.render(option);
+                        break;
+                    default:
+                }
             });
             //#endregion
+
+            //#region 涓嬫媺妗嗕簨浠�
+            // 鐩戝惉涓嬫媺妗嗛�夋嫨  
+            form.on('select(HPriceType)', function (data) {
+                console.log(data.value); // 寰楀埌琚�変腑鐨勫��  
+                changeHPrice();
+            });
+            //鏍规嵁涓嬫媺妗嗙殑鍊艰缃墿鏂欏崟浠风瓑淇℃伅
+            function changeHPrice() {
+                //#region 瀛愯〃 鏁版嵁妫�楠�
+                for (var i = 0; i < option.data.length; i++) {
+                    if (option.data[i]["HMaterID"] == "0" || option.data[i]["HMaterID"] == "" || option.data[i]["HMaterID"] == undefined) {
+                        layer.msg("绗�" + (i + 1) + "琛岋細鐗╂枡鏈�夋嫨锛�");
+                        return false;
+                    } else {
+                        var HPrice = option.data[i]["HPrice"];
+                        var HMaterID = option.data[i]["HMaterID"];
+                        var HType = $("#HPriceType").val();
+                        //鑾峰彇鐗╂枡瀵瑰簲鍗曚环绫诲瀷鐨勫崟浠�
+                        $.ajax({
+                            url: GetWEBURL() + "/Xs_ReceivableBill/getPriceByType",
+                            type: "GET",
+                            async: false,
+                            data: { "HMaterID": HMaterID, HType: HType },
+                            success: function (d) {
+                                HPrice = Number(d.data);
+                            }, error: function () {
+                                layer.alert("鍙戠敓閿欒!" + d.Message, { icon: 5 });
+                            }
+                        });
+                        var Dec = getDecByMaterID(option.data[i]["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"];  //閲戦绮惧害
+                        //鏁版嵁鏍¢獙鍚堟牸锛岄噸绠楄褰�
+                        var HTaxRate = option.data[i]["HTaxRate"] * 0.01;
+                        var HExRate = $("#HExRate").val();                      //姹囩巼
+                        var HQty = option.data[i]["HQty"] * 1;                           //鏁伴噺
+                        var HMoney = HQty * HPrice;                     //閲戦=鏁伴噺*鍗曚环
+                        var HTaxMoney = Number((HMoney * HTaxRate));         //绋庨=閲戦*绋庣巼
+                        var HlineTotal = HMoney + HTaxMoney;            //浠风◣鍚堣=閲戦+绋庨
+                        var HTaxPrice = Number((HPrice * (1 + HTaxRate)));        //鍚◣鍗曚环=鍗曚环*(1+绋庣巼)
+                        var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate));     //鏈綅甯佷环绋庡悎璁�=(绋庨+閲戦)*姹囩巼
+                        var HDiscountRate = option.data[i]["HDiscountRate"] * 1;   //鎶樻墸鐜�
+                        var HRelTaxPrice = Number((HTaxPrice * HDiscountRate));   //瀹為檯鍚◣鍗曚环=鍚◣鍗曚环*鎶樻墸鐜�
+                        var HExRate = $("#HExRate").val();                      //姹囩巼
+                        var HMoneyBB = HMoney * HExRate;
+                        ///鏁板瓧绮惧害
+                        option.data[i]["HQty"] = Number(HQty.toFixed(HQtyDec));
+                        option.data[i]["HPrice"] = Number(HPrice.toFixed(HPriceDec));
+                        option.data[i]["HMoney"] = Number(HMoney.toFixed(HMoneyDec));
+                        option.data[i]["HTaxMoney"] = Number(HTaxMoney.toFixed(HMoneyDec));
+                        option.data[i]["HMoneyBB"] = Number(HMoneyBB.toFixed(HMoneyDec));
+                        option.data[i]["HlineTotal"] = Number(HlineTotal.toFixed(HMoneyDec));
+                        option.data[i]["HTaxPrice"] = Number(HTaxPrice.toFixed(HPriceDec));
+                        option.data[i]["HRelTaxPrice"] = Number(HRelTaxPrice.toFixed(HPriceDec));
+                        option.data[i]["HlineTotalBB"] = Number(HlineTotalBB.toFixed(HMoneyDec));
+                    }
+
+                }
+                table.render(option);
+                //#endregion
+            }
+
+            //#endregion
+            
             //#endregion
 
             //#endregion
@@ -954,19 +1464,19 @@
                     , area: ['90%', '90%']//澶у皬
                     , title: '閿�鍞儴闂ㄥ垪琛�'//鏍囬
                     , shift: 2//寮瑰嚭鍔ㄧ敾
-                    , content: ['../../Baseset/鍩虹璧勬枡/Gy_DepartmentList.html', 'yes']
-                    //, btn: ['纭畾', '鍙栨秷']
-                    //, btn1: function (index, layero) {//鎸夐挳銆愭寜閽竴銆戠殑鍥炶皟
-                    //    var iframeWindow = window['layui-layer-iframe' + index]  //鑾峰彇寮规椤甸潰
-                    //    var checkStatus = iframeWindow.layui.table.checkStatus('mainTable');//鑾峰彇table鐨別lem:"#test"
-                    //    if (checkStatus.data.length === 0) {
-                    //        return layer.msg('璇烽�夋嫨鏁版嵁');
-                    //    }
-                    //    $("#HDeptName").val(checkStatus.data[0].HName);
-                    //    $("#HDeptID").val(checkStatus.data[0].HItemID);
-                    //    layer.close(index); //瀹冭幏鍙栫殑濮嬬粓鏄渶鏂板脊鍑虹殑鏌愪釜灞傦紝鍊兼槸鐢眑ayer鍐呴儴鍔ㄦ�侀�掑璁$畻鐨�
-                    //}
-                    //, btn2: function (index, layero) { }
+                    , content: ['../../鍩虹璧勬枡/鍏敤鍩虹璧勬枡/Gy_DepartmentList.html', 'yes']
+                    , btn: ['纭畾', '鍙栨秷']
+                    , btn1: function (index, layero) {//鎸夐挳銆愭寜閽竴銆戠殑鍥炶皟
+                        var iframeWindow = window['layui-layer-iframe' + index]  //鑾峰彇寮规椤甸潰
+                        var checkStatus = iframeWindow.layui.table.checkStatus('mainTable');//鑾峰彇table鐨別lem:"#test"
+                        if (checkStatus.data.length === 0) {
+                            return layer.msg('璇烽�夋嫨鏁版嵁');
+                        }
+                        $("#HDeptName").val(checkStatus.data[0].閮ㄩ棬鍚嶇О);
+                        $("#HDeptID").val(checkStatus.data[0].HItemID);
+                        layer.close(index); //瀹冭幏鍙栫殑濮嬬粓鏄渶鏂板脊鍑虹殑鏌愪釜灞傦紝鍊兼槸鐢眑ayer鍐呴儴鍔ㄦ�侀�掑璁$畻鐨�
+                    }
+                    , btn2: function (index, layero) { }
                 })
             }
             //#endregion
@@ -979,19 +1489,19 @@
                     , area: ['90%', '90%']//澶у皬
                     , title: '閿�鍞富绠″垪琛�'//鏍囬
                     , shift: 2//寮瑰嚭鍔ㄧ敾
-                    , content: ['../../Baseset/鍩虹璧勬枡/Gy_EmployeeList.html?Type=HManager', 'yes']
-                    //, btn: ['纭畾', '鍙栨秷']
-                    //, btn1: function (index, layero) {//鎸夐挳銆愭寜閽竴銆戠殑鍥炶皟
-                    //    var iframeWindow = window['layui-layer-iframe' + index]  //鑾峰彇寮规椤甸潰
-                    //    var checkStatus = iframeWindow.layui.table.checkStatus('mainTable');//鑾峰彇table鐨別lem:"#test"
-                    //    if (checkStatus.data.length === 0) {
-                    //        return layer.msg('璇烽�夋嫨鏁版嵁');
-                    //    }
-                    //    $("#HManagerName").val(checkStatus.data[0].HName);
-                    //    $("#HManagerID").val(checkStatus.data[0].HItemID);
-                    //    layer.close(index); //瀹冭幏鍙栫殑濮嬬粓鏄渶鏂板脊鍑虹殑鏌愪釜灞傦紝鍊兼槸鐢眑ayer鍐呴儴鍔ㄦ�侀�掑璁$畻鐨�
-                    //}
-                    //, btn2: function (index, layero) { }
+                    , content: ['../../鍩虹璧勬枡/鍏敤鍩虹璧勬枡/Gy_EmployeeList.html?Type=HManager', 'yes']
+                    , btn: ['纭畾', '鍙栨秷']
+                    , btn1: function (index, layero) {//鎸夐挳銆愭寜閽竴銆戠殑鍥炶皟
+                        var iframeWindow = window['layui-layer-iframe' + index]  //鑾峰彇寮规椤甸潰
+                        var checkStatus = iframeWindow.layui.table.checkStatus('mainTable');//鑾峰彇table鐨別lem:"#test"
+                        if (checkStatus.data.length === 0) {
+                            return layer.msg('璇烽�夋嫨鏁版嵁');
+                        }
+                        $("#HMangerName").val(checkStatus.data[0].鑱屽憳鍚嶇О);
+                        $("#HMangerID").val(checkStatus.data[0].HItemID);
+                        layer.close(index); //瀹冭幏鍙栫殑濮嬬粓鏄渶鏂板脊鍑虹殑鏌愪釜灞傦紝鍊兼槸鐢眑ayer鍐呴儴鍔ㄦ�侀�掑璁$畻鐨�
+                    }
+                    , btn2: function (index, layero) { }
                 })
             }
             //#endregion
@@ -1144,7 +1654,17 @@
                         if (checkStatus.data.length === 0) {
                             return layer.msg('璇烽�夋嫨鏁版嵁');
                         }
-
+                        var HCusID = $("#HCusID").val();//鍒ゆ柇瀹㈡埛
+                        if (HCusID == 0 || HCusID == '') {
+                            HCusID = checkStatus.data[0]["HCusID"];
+                        }
+                        for (var i = 0; i < checkStatus.data.length; i++) {
+                            if (checkStatus.data[i]["HCusID"] != HCusID) {
+                                layer.msg("涓嬫帹澶辫触!宸茬粡閫変腑鐨勮褰曚腑瀛樺湪涓嶅悓瀹㈡埛!");
+                                layer.close(index);
+                                return;
+                            }
+                        }
                         if ($("#BillType").val() == "1401") {
                             setInitBySeOrderBill(checkStatus);
                         }
@@ -1152,13 +1672,318 @@
                         {
                             setInitBySellOutBill(checkStatus);
                         }
-
+                        changeHPrice();
                         layer.close(index); //瀹冭幏鍙栫殑濮嬬粓鏄渶鏂板脊鍑虹殑鏌愪釜灞傦紝鍊兼槸鐢眑ayer鍐呴儴鍔ㄦ�侀�掑璁$畻鐨�
                     }
                     , btn2: function (index, layero) { }
                 })
             }
             //#endregion
+
+
+            //#region 閫夋暣鍗�
+            function set_SelectMainBill() {
+                var url;
+                if ($("#BillType").val() == "1401") {
+                    url = "../../閿�鍞鐞�/閿�鍞鍗�/Xs_SeOrderBillQuery.html?openType=2&HOrgID=" + HOrgID;
+                    HSourceBillName = "閿�鍞鍗�";
+                }
+                else if ($("#BillType").val() == "1205") {
+                    url = "../../棰嗘枡鍙戣揣/閿�鍞嚭搴�/Kf_SellOutBillQuery.html?openType=2&HOrgID=" + HOrgID;
+                    HSourceBillName = "閿�鍞嚭搴撳崟";
+                }
+                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 HCusID = $("#HCusID").val();//鍒ゆ柇瀹㈡埛
+                        if (HCusID == 0 || HCusID == '') {
+                            HCusID = checkStatus.data[0]["HCusID"];
+                        }
+                        //鑾峰彇璁剧疆鏉′欢
+                        var sMainWhere = " and hmainid in(";
+                        for (var i = 0; i < checkStatus.data.length; i++) {
+                            if (checkStatus.data[i]["HCusID"] != HCusID) {
+                                layer.msg("涓嬫帹澶辫触!宸茬粡閫変腑鐨勮褰曚腑瀛樺湪涓嶅悓瀹㈡埛!");
+                                layer.close(index);//鍏抽棴寮圭獥
+                                return;
+                            }
+                            sMainWhere += checkStatus.data[i]["hmainid"]
+                            if (i != checkStatus.data.length - 1) {
+                                sMainWhere += ",";
+                            } else {
+                                sMainWhere += ") ";
+                            }
+                        }
+                        getSeletMainInfo(sMainWhere);
+                        changeHPrice();
+                        layer.close(index);//鍏抽棴寮圭獥
+                    }
+                });
+            }
+            //#endregion
+
+            //#region 鏁村崟淇℃伅鑾峰彇鏂规硶
+            function getSeletMainInfo(sMainWhere) {
+                var ajaxLoad = layer.load();
+                if ($("#BillType").val() == "1401") {
+                    $.ajax({
+                        url: GetWEBURL() + '/Xs_SeOrderBill/list',
+                        async: false,
+                        type: "GET",
+                        data: { "sWhere": sMainWhere, "user": sessionStorage["HUserName"] },
+                        success: function (data1) {
+                            if (data1.count == 1) {
+                                var 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
+                                    , "HMangerName": dataArray[0].涓荤
+                                    , "HEmpID": dataArray[0].HEmpID
+                                    , "HEmpName": dataArray[0].涓氬姟鍛�
+                                    , "HCusID": dataArray[0].HCusID
+                                    , "HCusName": dataArray[0].瀹㈡埛
+                                    , "HCurID": dataArray[0].HCurID
+                                    , "HCurName": dataArray[0].甯佸埆
+                                    , "HExRate": dataArray[0].姹囩巼
+                                    , "HSSID": dataArray[0].HSSID
+                                    , "HSSName": dataArray[0].缁撶畻鏂瑰紡
+                                    , "HSellSID": dataArray[0].HSellSID
+                                    , "HSellSName": dataArray[0].閿�鍞柟寮�
+                                    
+                                    , "HProjectName": dataArray[0].椤圭洰鍚嶇О
+                                    , "HProjectID": (dataArray[0].HProjectID == null ? 0 : dataArray[0].HProjectID)
+                                });
+                                //瀛愯〃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
+                                            , "鐗╂枡浠g爜": dataArray[i].鐗╂枡浠g爜
+                                            , "鐗╂枡鍚嶇О": dataArray[i].鐗╂枡鍚嶇О
+                                            , "瑙勬牸鍨嬪彿": dataArray[i].瑙勬牸鍨嬪彿
+                                            , "HUnitID": dataArray[i].HUnitID
+                                            , "璁¢噺鍗曚綅": dataArray[i].璁¢噺鍗曚綅
+                                            , "HQty": dealDoubleToFixed(HQty, 1)
+                                            , "HPrice": dealDoubleToFixed(dataArray[i].鍗曚环, 3)
+                                            , "HTaxPrice": dealDoubleToFixed(dataArray[i].HTaxPrice, 3)
+                                            , 'HDiscountRate': "1"                                                     //
+                                            , 'HRelTaxPrice': dealDoubleToFixed(dataArray[i].HTaxPrice, 3)
+                                            , "HTaxRate": dataArray[i].绋庣巼
+                                            , 'HTaxMoney': dealDoubleToFixed(HTaxMoney, 2)                                                         //
+                                            , "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].HBillType
+                                            , "HRelationQty": "0"
+                                            , "HRelationMoney": "0"
+
+                                            , 'HPOOrderInterID': "0"
+                                            , 'HPOOrderEntryID': "0"
+                                            , 'HPOOrderBillNo': ""
+
+                                            , 'HSeOrderTaxPrice': dealDoubleToFixed(dataArray[i].HTaxPrice, 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[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;
+                                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() == "1205") {
+                    $.ajax({
+                        url: GetWEBURL() + '/Kf_SellOutBill/GetSellOutBillList',
+                        type: "GET",
+                        async: false,
+                        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
+                                    , "HMangerName": dataArray[0].涓荤
+                                    , "HEmpID": dataArray[0].HEmpID
+                                    , "HEmpName": dataArray[0].涓氬姟鍛�
+                                    , "HCusID": dataArray[0].HSupID
+                                    , "HCusName": dataArray[0].瀹㈡埛
+                                    , "HCurID": dataArray[0].涓昏〃甯佸埆id
+                                    , "HCurName": dataArray[0].涓昏〃甯佸埆
+                                    , "HExRate": dataArray[0].涓昏〃姹囩巼
+                                    , "HSSID": "0"
+                                    , "HSSName": ""
+                                    , "HSellSID": dataArray[0].HSellSID
+                                    , "HSellSName": dataArray[0].閿�鍞柟寮�
+                                    , "HProjectID": (dataArray[0].HProjectID == null ? 0 : dataArray[0].HProjectID)
+                                    , "HProjectName": dataArray[0].椤圭洰鍚嶇О
+                                });
+                                    //瀛愯〃  璧嬪��
+                                var rowdataEntry = [];
+                                for (var i = 0; i < dataArray.length; i++) {
+                                    var HQty = dataArray[i].鏁伴噺*1 - dataArray[i].宸插叧鑱旀暟閲�;                           //鏁伴噺
+                                    rowdataEntry.push(
+                                        {
+                                            "HMaterID": dataArray[i].HMaterID
+                                            , "鐗╂枡浠g爜": dataArray[i].鐗╂枡浠g爜
+                                            , "鐗╂枡鍚嶇О": 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': dealDoubleToFixed(HQty * dataArray[i].鍗曚环 * dataArray[0].绋庣巼, 2)                                                         //
+                                            , "HMoney": dealDoubleToFixed(HQty * dataArray[i].鍗曚环, 2)
+                                            , 'HMoneyBB': dealDoubleToFixed(HQty * dataArray[i].鍗曚环 * dataArray[0].姹囩巼, 2)
+                                            , 'HlineTotal': dealDoubleToFixed(HQty * dataArray[i].鍚◣鍗曚环, 2)
+                                            , 'HlineTotalBB': dealDoubleToFixed(HQty * dataArray[i].鍚◣鍗曚环 * dataArray[0].姹囩巼, 2)
+                                            , "HRemark": ""
+
+                                            , "HSourceInterID": dataArray[i].hmainid
+                                            , "HSourceEntryID": dataArray[i].hsubid
+                                            , "HSourceBillNo": dataArray[i].鍗曟嵁鍙�
+                                            , "HSourceBillType": dataArray[i].HBillType
+                                            , "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[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;
+                                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 瀛愯〃鍒濆鍖�
@@ -1180,13 +2005,13 @@
                         , { 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', event: "HQty" }
-                        , { field: 'HPrice', title: '鍗曚环', width: 100, edit: 'text', event: "HPrice" }
+                        , { field: 'HPrice', title: '鍗曚环', width: 100, event: "HPrice", style: 'background-color:#efefef4d;' }
                         , { field: 'HTaxPrice', title: '鍚◣鍗曚环', width: 100, edit: 'text', event: "HTaxPrice" }
                         , { field: 'HDiscountRate', title: '鎶樻墸鐜�', width: 100, edit: 'text' }
                         , { field: 'HRelTaxPrice', title: '瀹為檯鍚◣鍗曚环', width: 100, edit: 'text' }
                         , { field: 'HTaxRate', title: '绋庣巼', width: 100, edit: 'text' }
                         , { field: 'HTaxMoney', title: '绋庨', width: 100, totalRow: true, style: 'background-color:#efefef4d;' }
-                        , { field: 'HMoney', title: '閲戦', width: 100, totalRow: true, style: 'background-color:#efefef4d;' }
+                        , { field: 'HMoney', title: '閲戦', width: 100, totalRow: true, edit: 'text' }
                         , { 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;' }
@@ -1209,6 +2034,9 @@
                         , { 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);
+                    }
                 }
 
                 var rowdata = [{
@@ -1221,7 +2049,7 @@
                     , "HQty": "0"
                     , "HPrice": "0"
                     , "HTaxPrice": "0"
-                    , 'HDiscountRate': "0"
+                    , 'HDiscountRate': "1"
                     , 'HRelTaxPrice': "0"
                     , "HTaxRate": "0"
                     , 'HTaxMoney': "0"
@@ -1247,9 +2075,62 @@
                     , "HSeOrderEntryID": "0"
                     , "HSeOrderBillNo": ""
                 }];
+                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: '鐗╂枡浠g爜', title: '鐗╂枡浠g爜', 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;' }
+                    ]]
+                }
                 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;
+                    }
+                }
             }
             //#endregion
 
@@ -1276,7 +2157,7 @@
                                 , "HMainSourceEntryID": data.HMainSourceEntryID
                                 , "HMainSourceBillNo": data.HMainSourceBillNo
                                 , "HMainSourceBillType": data.HMainSourceBillType
-
+                                , "HPriceType": data.鍗曚环绫诲瀷
                                 , "HDeptID": data.HDeptID
                                 , "HDeptName": data.閮ㄩ棬
                                 , "HMangerID": data.HMangerID
@@ -1296,6 +2177,8 @@
                                 , "HRemark": data.琛ㄥご澶囨敞
                                 , "HExplanation": data.鎽樿
                                 , "HInnerBillNo": data.鍐呴儴鍗曟嵁鍙�
+                                , "HProjectID": (data.HProjectID == null ? 0 : data.HProjectID)
+                                , "HProjectName": data.椤圭洰鍚嶇О
 
                                 , "HMaker": data.鍒跺崟浜�
                                 , "HMakeDate": data.鍒跺崟鏃ユ湡 == null ? "" : Format(new Date(data.鍒跺崟鏃ユ湡), "yyyy-MM-dd")
@@ -1309,7 +2192,12 @@
                                 , "HDeleteDate": data.浣滃簾鏃ユ湡 == null ? "" : Format(new Date(data.浣滃簾鏃ユ湡), "yyyy-MM-dd")
                             });
 
-                            HOrgIDBar = 0;
+                            if (data.HMainSourceBillType != "") {
+                                haveSource = true;
+                                $("#BillType").val(data.HMainSourceBillType);
+                            }
+
+                            HOrgIDBar = sessionStorage["OrganizationID"];
 
                             //瀛愯〃  璧嬪��
                             var rowdata = [];
@@ -1355,6 +2243,12 @@
                             }
                             option.data = rowdata;
                             table.render(option);
+
+                            //瀛愯〃  璧嬪��
+                            var rowdata = result.list[0];
+                            optionEntry.data = rowdata;
+                            table.render(optionEntry);
+
                             layer.close(ajaxLoad);
                         } else {
                             layer.close(ajaxLoad);
@@ -1435,8 +2329,8 @@
                                 , "HQty": dealDoubleToFixed(dataArray[i].鏁伴噺, 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)
@@ -1487,7 +2381,7 @@
 
                         , "HDeptID": dataArray[0].HDeptID
                         , "HDeptName": dataArray[0].閮ㄩ棬
-                        , "HMangerID": dataArray[0].hmanagerid
+                        , "HMangerID": dataArray[0].HManagerID
                         , "HMangerName": dataArray[0].涓荤
                         , "HEmpID": dataArray[0].HEmpID
                         , "HEmpName": dataArray[0].涓氬姟鍛�
@@ -1507,17 +2401,17 @@
                     for (var i = 0; i < dataArray.length; i++) {
                         rowdata.push(
                             {
-                                "HMaterID": dataArray[i].hmaterid
+                                "HMaterID": dataArray[i].HMaterID
                                 , "鐗╂枡浠g爜": dataArray[i].鐗╂枡浠g爜
                                 , "鐗╂枡鍚嶇О": dataArray[i].鐗╂枡鍚嶇О
                                 , "瑙勬牸鍨嬪彿": dataArray[i].瑙勬牸鍨嬪彿
-                                , "HUnitID": dataArray[i].hunitid
+                                , "HUnitID": dataArray[i].HUnitID
                                 , "璁¢噺鍗曚綅": dataArray[i].璁¢噺鍗曚綅
                                 , "HQty": dealDoubleToFixed(dataArray[i].鏁伴噺, 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].鏁伴噺 * dataArray[i].鍗曚环, 2)
@@ -1574,6 +2468,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 = "";
@@ -1584,7 +2492,7 @@
                     refSav = "Update";
                 }
 
-                var sMainSub = sMainStr + ';' + sSubStr + ';' + refSav + ';' + sessionStorage["HUserName"];
+                var sMainSub = sMainStr + ';' + sSubStr + ';' + sSubStr2 + ';' + refSav + ';' + sessionStorage["HUserName"];
 
                 $.ajax({
                     type: "POST",
@@ -1596,6 +2504,11 @@
                         if (data.count == 1) { // 璇存槑楠岃瘉鎴愬姛浜嗭紝
                             layer.msg(data.Message, { icon: 1 });
                             $('#set_SaveBill').addClass("layui-btn-disabled").attr("disabled", true);
+                            if (data.Verify == "Y") //鑷姩瀹℃牳
+                            {
+                                $("#HInterID").val(data.HInterID);//鑾峰彇鎻愪氦鎴愬姛杩斿洖鐨勫崟鎹富ID
+                                set_CheckBill(0); //瀹℃牳
+                            }
                             //淇濆瓨鍚庢祻瑙�
                             //ReRoadBillMain();
                         }
@@ -1616,6 +2529,7 @@
             function AllowLoadData(data) {
                 //鏁板�兼牸寮忔牎楠屽伐鍏�
                 var ref = /^\d+(\.\d+)?$/;          //闈炶礋鏁版鍒欒〃杈惧紡
+                var ref1 = /^-?\d+(\.\d+)?$/;          //鍒ゆ柇瀛楃涓叉槸鍚︿负鏁板瓧(鍖呭惈鏁存暟銆佹诞鐐规暟)锛屾鍒欒〃杈惧紡
                 var temp = "";
 
                 //#region 琛ㄥご鏁版嵁妫�楠�
@@ -1678,11 +2592,11 @@
 
                     //瀹炲彂鏁伴噺鏍煎紡鏍¢獙
                     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;
                     }
 
@@ -1713,25 +2627,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;
+                    //}
 
                     //鍙戣揣浠撳簱闈炵┖楠岃瘉
                     if (option.data[i]["HWHID"] == "0") {
@@ -1758,7 +2673,7 @@
                                 , shift: 2 //寮瑰嚭鍔ㄧ敾
                                 , area: ["90%", "90%"] //绐椾綋澶у皬
                                 , maxmin: true //璁剧疆鏈�澶ф渶灏忔寜閽槸鍚︽樉绀�
-                                , content: ['../../Baseset/鍩虹璧勬枡/Gy_MaterialList.html', 'yes']
+                                , content: ['../../鍩虹璧勬枡/鍏敤鍩虹璧勬枡/Gy_Material.html', 'yes']
                                 , btn: ["纭畾", "鍙栨秷"]
                                 , btn1: function (index, laero) {
                                     //鎸夐挳涓�  鐨勫洖璋�
@@ -1768,17 +2683,74 @@
                                     if (checkStatus.data.length != 1) {
                                         return layer.msg("璇烽�夋嫨涓�鏉℃暟鎹�");
                                     }
-
-                                    //鏇存柊琛ㄦ牸缂撳瓨鐨勬暟鎹�
-                                    obj.update({
-                                        "HMaterID": checkStatus.data[0].HItemID
-                                        , "鐗╂枡浠g爜": checkStatus.data[0].HNumber
-                                        , "鐗╂枡鍚嶇О": checkStatus.data[0].HName
-                                        , "瑙勬牸鍨嬪彿": checkStatus.data[0].HModel
-                                        , "HUnitID": checkStatus.data[0].HUnitID
-                                        , "璁¢噺鍗曚綅": checkStatus.data[0].HUnitName
-                                    })
+                                    OptionData = checkStatus.data[0];
                                     layer.close(index);//鍏抽棴寮圭獥
+                                }
+                                , end: function () {
+                                    if (typeof (OptionData.HItemID) != "undefined") {
+                                        //閫氳繃渚涘簲鍟唅d鑾峰彇绋庣巼
+                                        var HSupID = $("#HCusID").val();
+                                        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"];  //閲戦绮惧害
+                                        var HPrice = obj.data.HPrice * 1;
+                                        var HTaxRate = obj.data.HTaxRate*0.01;
+                                        if (HSupID != 0) {
+                                            $.ajax({
+                                                url: GetWEBURL() + "/Gy_Customer/xg",
+                                                //url: "http://localhost:12761/Gy_Supplier/xg",
+                                                type: "GET",
+                                                data: {
+                                                    "HInterID": HSupID
+                                                },
+                                                success: function (d) {
+                                                   HTaxRate = parseInt(d.data[0].澧炲�肩◣鐜�) * 0.01;
+                                                }
+                                            });
+                                        }
+                                        var HExRate = $("#HExRate").val();                      //姹囩巼
+                                        //鏁版嵁鏍¢獙鍚堟牸锛岄噸绠楄褰�
+                                        var HQty = obj.data.HQty * 1;                           //鏁伴噺
+                                        var HMoney = HQty * HPrice;                     //閲戦=鏁伴噺*鍗曚环
+                                        var HTaxMoney = Number((HMoney * HTaxRate));         //绋庨=閲戦*绋庣巼
+                                        var HlineTotal = HMoney + HTaxMoney;            //浠风◣鍚堣=閲戦+绋庨
+                                        var HTaxPrice = Number((HPrice * (1 + HTaxRate)));        //鍚◣鍗曚环=鍗曚环*(1+绋庣巼)
+                                        var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate));     //鏈綅甯佷环绋庡悎璁�=(绋庨+閲戦)*姹囩巼
+                                        var HDiscountRate = obj.data.HDiscountRate * 1;   //鎶樻墸鐜�
+                                        var HRelTaxPrice = Number((HTaxPrice * HDiscountRate));   //瀹為檯鍚◣鍗曚环=鍚◣鍗曚环*鎶樻墸鐜�
+                                        var HMoneyBB = HMoney * HExRate;
+                                        ///鏁板瓧绮惧害
+                                        HQty = Number(HQty.toFixed(HQtyDec));
+                                        HPrice = Number(HPrice.toFixed(HPriceDec));
+                                        HMoney = Number(HMoney.toFixed(HMoneyDec));
+                                        HTaxMoney = Number(HTaxMoney.toFixed(HMoneyDec));
+                                        HMoneyBB = Number(HMoneyBB.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鐨勫�间负鈥淗BillNo鈥濆瓧娈电殑鍊糎ItemID`鐨勫��
+                                            , "鐗╂枡浠g爜": OptionData.鐗╂枡浠g爜
+                                            , "鐗╂枡鍚嶇О": OptionData.鐗╂枡鍚嶇О
+                                            , "瑙勬牸鍨嬪彿": OptionData.瑙勬牸鍨嬪彿
+                                            , "HUnitID": OptionData.HUnitID
+                                            , "璁¢噺鍗曚綅": OptionData.璁¢噺鍗曚綅鍚嶇О
+                                            , "HTaxRate": HTaxRate * 100
+                                            , HQty: HQty                          //鏇存柊HQty瀛楁锛孒Qty
+                                            , HPrice: HPrice                     //鏇存柊HPrice瀛楁锛孒Price
+                                            , HMoney: HMoney                      //鏇存柊HMoney瀛楁锛孒Money
+                                            , HTaxMoney: HTaxMoney                  //鏇存柊HTaxMoney瀛楁锛孒TaxMoney
+                                            , HlineTotal: HlineTotal             //鏇存柊HlineTotal瀛楁锛孒lineTotal
+                                            , HTaxPrice, HTaxPrice                   //鏇存柊HTaxPrice瀛楁锛孒TaxPrice
+                                            , HRelTaxPrice: HRelTaxPrice            //鏇存柊HRelTaxPrice瀛楁锛屽叾鍊兼潵鑷彉閲廐RelTaxPrice
+                                            , HlineTotalBB: HlineTotalBB              //鏇存柊HlineTotalBB瀛楁锛屽叾鍊兼潵鑷彉閲廐lineTotalBB
+                                            , HMoneyBB: HMoneyBB
+                                        })
+                                        OptionData = [];
+                                    }
                                 }
                             })
                         }
@@ -1792,7 +2764,7 @@
                                 , shift: 2 //寮瑰嚭鍔ㄧ敾
                                 , area: ["90%", "90%"] //绐椾綋澶у皬
                                 , maxmin: true //璁剧疆鏈�澶ф渶灏忔寜閽槸鍚︽樉绀�
-                                , content: ['../../Baseset/鍩虹璧勬枡/Gy_UnitList.html', 'yes']
+                                , content: ['../../鍩虹璧勬枡/鍏敤鍩虹璧勬枡/Gy_Unit.html?type=AuxiliaryUnit', 'yes']
                                 , btn: ["纭畾", "鍙栨秷"]
                                 , btn1: function (index, laero) {
                                     //鎸夐挳涓�  鐨勫洖璋�
@@ -1804,10 +2776,20 @@
                                     }
                                     //鏇存柊琛ㄦ牸缂撳瓨鐨勬暟鎹�
                                     obj.update({
-                                        "璁¢噺鍗曚綅": checkStatus.data[0].HName
+                                        "璁¢噺鍗曚綅": checkStatus.data[0].璁¢噺鍗曚綅鍚嶇О
                                         , "HUnitID": checkStatus.data[0].HItemID
                                     })
                                     layer.close(index);//鍏抽棴寮圭獥
+                                }
+                                , end: function () {
+                                    if (typeof (OptionData.HItemID) != "undefined") {
+                                        //鏇存柊琛ㄦ牸缂撳瓨鐨勬暟鎹�
+                                        obj.update({
+                                            "HUnitID": OptionData.HItemID
+                                            , "璁¢噺鍗曚綅": OptionData.璁¢噺鍗曚綅鍚嶇О
+                                        })
+                                        OptionData = [];
+                                    }
                                 }
                             })
                         }
@@ -1815,6 +2797,98 @@
                         return false;
                     }
                 })
+                //鍙屽嚮
+                $('.layui-table-box tbody td[data-field="鐗╂枡浠g爜"]').off('dblclick').on('dblclick', function () {
+                    layer.open({
+                        type: 2
+                        , skin: "layui-layer-rim" //鍔犱笂杈规
+                        , title: "鐗╂枡鍒楄〃"  //鏍囬
+                        , closeBtn: 1  //绐椾綋鍙充笂瑙掑叧闂� 鐨� 鏍峰紡
+                        , shift: 2 //寮瑰嚭鍔ㄧ敾
+                        , area: ["90%", "90%"] //绐椾綋澶у皬
+                        , maxmin: true //璁剧疆鏈�澶ф渶灏忔寜閽槸鍚︽樉绀�
+                        , content: ['../../鍩虹璧勬枡/鍏敤鍩虹璧勬枡/Gy_Material.html', '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 () {
+                            if (typeof (OptionData.HItemID) != "undefined") {
+                                //閫氳繃渚涘簲鍟唅d鑾峰彇绋庣巼
+                                var HSupID = $("#HCusID").val();
+                                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"];  //閲戦绮惧害
+                                var HPrice = obj.data.HPrice * 1;
+                                var HTaxRate = obj.data.HTaxRate*0.01;
+                                if (HSupID != 0) {
+                                    $.ajax({
+                                        url: GetWEBURL() + "/Gy_Customer/xg",
+                                        //url: "http://localhost:12761/Gy_Supplier/xg",
+                                        type: "GET",
+                                        data: {
+                                            "HInterID": HSupID
+                                        },
+                                        success: function (d) {
+                                            HTaxRate = parseInt(d.data[0].澧炲�肩◣鐜�) * 0.01;
+                                        }
+                                    });
+                                }
+                                var HExRate = $("#HExRate").val();                      //姹囩巼
+                                //鏁版嵁鏍¢獙鍚堟牸锛岄噸绠楄褰�
+                                var HQty = obj.data.HQty * 1;                           //鏁伴噺
+                                var HMoney = HQty * HPrice;                     //閲戦=鏁伴噺*鍗曚环
+                                var HTaxMoney = Number((HMoney * HTaxRate));         //绋庨=閲戦*绋庣巼
+                                var HlineTotal = HMoney + HTaxMoney;            //浠风◣鍚堣=閲戦+绋庨
+                                var HTaxPrice = Number((HPrice * (1 + HTaxRate)));        //鍚◣鍗曚环=鍗曚环*(1+绋庣巼)
+                                var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate));     //鏈綅甯佷环绋庡悎璁�=(绋庨+閲戦)*姹囩巼
+                                var HDiscountRate = obj.data.HDiscountRate * 1;   //鎶樻墸鐜�
+                                var HRelTaxPrice = Number((HTaxPrice * HDiscountRate));   //瀹為檯鍚◣鍗曚环=鍚◣鍗曚环*鎶樻墸鐜�
+                                var HExRate = $("#HExRate").val();                      //姹囩巼
+                                var HMoneyBB = HMoney * HExRate;
+                                ///鏁板瓧绮惧害
+                                HQty = Number(HQty.toFixed(HQtyDec));
+                                HPrice = Number(HPrice.toFixed(HPriceDec));
+                                HMoney = Number(HMoney.toFixed(HMoneyDec));
+                                HTaxMoney = Number(HTaxMoney.toFixed(HMoneyDec));
+                                HMoneyBB = Number(HMoneyBB.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鐨勫�间负鈥淗BillNo鈥濆瓧娈电殑鍊糎ItemID`鐨勫��
+                                    , "鐗╂枡浠g爜": OptionData.鐗╂枡浠g爜
+                                    , "鐗╂枡鍚嶇О": OptionData.鐗╂枡鍚嶇О
+                                    , "瑙勬牸鍨嬪彿": OptionData.瑙勬牸鍨嬪彿
+                                    , "HUnitID": OptionData.HUnitID
+                                    , "璁¢噺鍗曚綅": OptionData.璁¢噺鍗曚綅鍚嶇О
+                                    , "HTaxRate": HTaxRate * 100
+                                    , HQty: HQty                          //鏇存柊HQty瀛楁锛孒Qty
+                                    , HPrice: HPrice                     //鏇存柊HPrice瀛楁锛孒Price
+                                    , HMoney: HMoney                      //鏇存柊HMoney瀛楁锛孒Money
+                                    , HTaxMoney: HTaxMoney                  //鏇存柊HTaxMoney瀛楁锛孒TaxMoney
+                                    , HlineTotal: HlineTotal             //鏇存柊HlineTotal瀛楁锛孒lineTotal
+                                    , HTaxPrice, HTaxPrice                   //鏇存柊HTaxPrice瀛楁锛孒TaxPrice
+                                    , HRelTaxPrice: HRelTaxPrice            //鏇存柊HRelTaxPrice瀛楁锛屽叾鍊兼潵鑷彉閲廐RelTaxPrice
+                                    , HlineTotalBB: HlineTotalBB              //鏇存柊HlineTotalBB瀛楁锛屽叾鍊兼潵鑷彉閲廐lineTotalBB
+                                    , HMoneyBB: HMoneyBB
+                                })
+                                OptionData = [];
+                            }
+                        }
+                    })
+                });
             }
             //#endregion
 
@@ -1825,12 +2899,15 @@
                 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);
                         }
                     });
@@ -1920,7 +2997,55 @@
                 }
             }
             //#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
             //#region 涓嬬Щ
             function btn_under() {
                 var checkStatus = table.checkStatus('mainTable')
@@ -1991,6 +3116,7 @@
             function DisPlay_HideColumn() {
                 $.ajax({
                     url: GetWEBURL() + '/Xt_grdAlignment_WMES/grdAlignmentWMESList',
+                    async:false,
                     type: "GET",
                     data: { "HModName": HModName, "user": sessionStorage["HUserName"] },
                     async: false,
@@ -2039,6 +3165,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];
                                 }
                             }
 
@@ -2151,26 +3281,29 @@
                     , "HSSName": dataArray[0].缁撶畻鏂瑰紡
                     , "HSellSID": dataArray[0].HSellSID
                     , "HSellSName": dataArray[0].閿�鍞柟寮�
+                    , "HProjectID": (dataArray[0].HProjectID == null ? 0 : dataArray[0].HProjectID)
+                    , "HProjectName": dataArray[0].椤圭洰鍚嶇О
                 });
 
-                //瀛愯〃  璧嬪��
-                var rowdata = [];
+                //瀛愯〃Entry  璧嬪��
+                var rowdataEntry = [];
                 for (var i = 0; i < dataArray.length; i++) {
-                    rowdata.push(
+                    var HQty = dataArray[i].鏁伴噺 - dataArray[i].鍏宠仈鏁伴噺;
+                    rowdataEntry.push(
                         {
-                             "HMaterID": dataArray[i].HMaterID
+                            "HMaterID": dataArray[i].HMaterID
                             , "鐗╂枡浠g爜": dataArray[i].鐗╂枡浠g爜
                             , "鐗╂枡鍚嶇О": dataArray[i].鐗╂枡鍚嶇О
                             , "瑙勬牸鍨嬪彿": dataArray[i].瑙勬牸鍨嬪彿
                             , "HUnitID": dataArray[i].HUnitID
                             , "璁¢噺鍗曚綅": dataArray[i].璁¢噺鍗曚綅
-                            , "HQty": dealDoubleToFixed(dataArray[i].鏁伴噺, 1)
+                            , "HQty": dealDoubleToFixed(HQty, 1)
                             , "HPrice": dealDoubleToFixed(dataArray[i].鍗曚环, 3)
-                            , "HTaxPrice": dealDoubleToFixed(dataArray[i].鍚◣鍗曚环, 3)
-                            , 'HDiscountRate':"0"                                                     //
-                            , 'HRelTaxPrice': "0"
+                            , "HTaxPrice": dealDoubleToFixed(dataArray[i].HTaxPrice, 3)
+                            , 'HDiscountRate': "1"                                                     //
+                            , 'HRelTaxPrice': dealDoubleToFixed(dataArray[i].HTaxPrice, 3)
                             , "HTaxRate": dataArray[i].绋庣巼
-                            , 'HTaxMoney':"0"                                                         //
+                            , 'HTaxMoney': "0"                                                         //
                             , "HMoney": dealDoubleToFixed(dataArray[i].閲戦, 2)
                             , 'HMoneyBB': dealDoubleToFixed(dataArray[i].閲戦 * dataArray[0].姹囩巼, 2)
                             , 'HlineTotal': dealDoubleToFixed(dataArray[i].浠风◣鍚堣, 2)
@@ -2188,14 +3321,35 @@
                             , 'HPOOrderEntryID': "0"
                             , 'HPOOrderBillNo': ""
 
-                            , 'HSeOrderTaxPrice': dealDoubleToFixed(dataArray[i].鍚◣鍗曚环, 3)
+                            , 'HSeOrderTaxPrice': dealDoubleToFixed(dataArray[i].HTaxPrice, 3)
                             , "HSeOrderInterID": dataArray[i].hmainid
                             , "HSeOrderEntryID": dataArray[i].hsubid
                             , "HSeOrderBillNo": 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[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.splice(j, 1);
+                            j = j - 1;
+                        }
+                    }
+                }
+                set_InitGridHaveSource();
+                option.data = rowdataEntry;
+                haveSource = true;
                 table.render(option);
             }
             //#endregion
@@ -2233,7 +3387,6 @@
                         return;
                     }
                 }
-
                 form.val("component-form-group", { //formTest 鍗� class="layui-form" 鎵�鍦ㄥ厓绱犲睘鎬� lay-filter="" 瀵瑰簲鐨勫��
                     "HMainSourceInterID": "0"
                     , "HMainSourceEntryID": "0"
@@ -2242,7 +3395,7 @@
 
                     , "HDeptID": dataArray[0].HDeptID
                     , "HDeptName": dataArray[0].閮ㄩ棬
-                    , "HMangerID": dataArray[0].hmanagerid
+                    , "HMangerID": dataArray[0].HManagerID
                     , "HMangerName": dataArray[0].涓荤
                     , "HEmpID": dataArray[0].HEmpID
                     , "HEmpName": dataArray[0].涓氬姟鍛�
@@ -2255,51 +3408,81 @@
                     , "HSSName": ""
                     , "HSellSID": dataArray[0].HSellSID
                     , "HSellSName": dataArray[0].閿�鍞柟寮�
+
+                    , "HProjectName": dataArray[0].椤圭洰鍚嶇О
+                    , "HProjectID": dataArray[0].HProjectID == null ? "0" : dataArray[0].HProjectID
                 });
-
+                
                 //瀛愯〃  璧嬪��
-                var rowdata = [];
-                for (var i = 0; i < dataArray.length; i++) {
-                    rowdata.push(
-                        {
-                            "HMaterID": dataArray[i].hmaterid
-                            , "鐗╂枡浠g爜": dataArray[i].鐗╂枡浠g爜
-                            , "鐗╂枡鍚嶇О": dataArray[i].鐗╂枡鍚嶇О
-                            , "瑙勬牸鍨嬪彿": dataArray[i].瑙勬牸鍨嬪彿
-                            , "HUnitID": dataArray[i].hunitid
-                            , "璁¢噺鍗曚綅": dataArray[i].璁¢噺鍗曚綅
-                            , "HQty": dealDoubleToFixed(dataArray[i].鏁伴噺, 1)
-                            , "HPrice": dealDoubleToFixed(dataArray[i].鍗曚环, 3)
-                            , "HTaxPrice": dealDoubleToFixed(dataArray[i].鍚◣鍗曚环, 3)
-                            , 'HDiscountRate': "0"                                                     //
-                            , 'HRelTaxPrice': "0"
-                            , "HTaxRate": dataArray[i].绋庣巼
-                            , 'HTaxMoney': "0"                                                         //
-                            , "HMoney": dealDoubleToFixed(dataArray[i].鏁伴噺 * dataArray[i].鍗曚环, 2)
-                            , 'HMoneyBB': dealDoubleToFixed(dataArray[i].鏁伴噺 * dataArray[i].鍗曚环 * dataArray[0].姹囩巼, 2)
-                            , 'HlineTotal': dealDoubleToFixed(dataArray[i].鏁伴噺 * dataArray[i].鍚◣鍗曚环, 2)
-                            , 'HlineTotalBB': dealDoubleToFixed(dataArray[i].鏁伴噺 * dataArray[i].鍚◣鍗曚环 * dataArray[0].姹囩巼, 2)
-                            , "HRemark": ""
+                var rowdataEntry = [];
+                try {
+                    for (var i = 0; i < dataArray.length; i++) {
+                        var HQty = dataArray[i].鏁伴噺 * 1 - dataArray[i].鍏宠仈鏁伴噺;
+                        rowdataEntry.push(
+                            {
+                                "HMaterID": dataArray[i].HMaterID
+                                , "鐗╂枡浠g爜": dataArray[i].鐗╂枡浠g爜
+                                , "鐗╂枡鍚嶇О": 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': "0"                                                         //
+                                , "HMoney": dealDoubleToFixed(HQty * dataArray[i].鍗曚环, 2)
+                                , 'HMoneyBB': dealDoubleToFixed(HQty * dataArray[i].鍗曚环 * dataArray[0].姹囩巼, 2)
+                                , 'HlineTotal': dealDoubleToFixed(HQty * dataArray[i].鍚◣鍗曚环, 2)
+                                , 'HlineTotalBB': dealDoubleToFixed(HQty * dataArray[i].鍚◣鍗曚环 * dataArray[0].姹囩巼, 2)
+                                , "HRemark": ""
 
-                            , "HSourceInterID": dataArray[i].hmainid
-                            , "HSourceEntryID": dataArray[i].hsubid
-                            , "HSourceBillNo": dataArray[i].鍗曟嵁鍙�
-                            , "HSourceBillType": dataArray[i].HBillType
-                            , "HRelationQty": "0"
-                            , "HRelationMoney": "0"
+                                , "HSourceInterID": dataArray[i].hmainid
+                                , "HSourceEntryID": dataArray[i].hsubid
+                                , "HSourceBillNo": dataArray[i].鍗曟嵁鍙�
+                                , "HSourceBillType": dataArray[i].HBillType
+                                , "HRelationQty": "0"
+                                , "HRelationMoney": "0"
 
-                            , 'HPOOrderInterID': "0"
-                            , 'HPOOrderEntryID': "0"
-                            , 'HPOOrderBillNo': ""
+                                , '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].婧愬崟鍗曞彿 : ""
-                        }
-                    );
+                                , '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;
+                catch (error) {
+                    layer.alert(error.Message, { icon: 5 });
+                }
+
+                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[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.splice(j, 1);
+                            j = j - 1;
+                        }
+                    }
+                }
+                set_InitGridHaveSource();
+                option.data = rowdataEntry;
+                haveSource = true;
                 table.render(option);
             }
             //#endregion
@@ -2358,6 +3541,32 @@
             }
             //#endregion
 
+            //#region 鏍规嵁鐗╂枡ID鑾峰彇绮惧害
+            function getDecByMaterID(HMaterID) {
+                var resultData = {};
+                $.ajax({  // 寮傛璇锋眰
+                    url: GetWEBURL() + "/Gy_Material/getDecByID",  //璇锋眰鍦板潃
+                    async: false,   //鏄惁寮�鍚紓姝�
+                    type: "GET",   //璇锋眰绫诲瀷
+                    data: {   //瀹氫箟鍙戦�佸埌鏈嶅姟鍣ㄧ殑鏁版嵁
+                        "HMaterID": HMaterID     //  灏咹MaterID浣滀负璇锋眰鍙傛暟鍙戦��
+                    },
+                    success: function (result) {   // 褰撹姹傛垚鍔熸椂锛屾墽琛岃繖涓嚱鏁�
+                        if (result.code == 1) { // 濡傛灉鏈嶅姟鍣ㄨ繑鍥炵殑鏁版嵁涓殑`code瀛楁绛変簬1锛岃繖鍙兘琛ㄧず瀹℃牳鎿嶄綔鎴愬姛鎵ц
+                            var data = result.data; //澹版槑data鍙橀噺锛屽苟灏嗗叾璧嬪�间负result瀵硅薄涓殑data灞炴��
+                            resultData = data[0];   //灏哾ata鏁扮粍锛堟垨绫绘暟缁勫璞★級鐨勭涓�涓厓绱犺祴鍊肩粰鍙橀噺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_SellOutBillInit(HSourceInterID, HSourceEntryID) {
                 var res = "none";
@@ -2402,18 +3611,18 @@
             $("#HCusID").val(obj[0].HItemID);
         }
 
+        
         function GetHManagerValue(obj)  //杩斿洖涓荤
         {
-            $("#HMangerName").val(obj[0].HName);
+            $("#HMangerName").val(obj[0].鑱屽憳鍚嶇О);
             $("#HMangerID").val(obj[0].HItemID);
         }
 
         function GetHDeptNameValue(obj)  //杩斿洖閮ㄩ棬
         {
-            $("#HDeptName").val(obj[0].HName);
+            $("#HDeptName").val(obj[0].閮ㄩ棬鍚嶇О);
             $("#HDeptID").val(obj[0].HItemID);
         }
-
         function GetSellStyleValue(obj)  //杩斿洖閿�鍞柟寮�
         {
             $("#HSellSName").val(obj[0].HName);
@@ -2425,6 +3634,15 @@
             $("#HSSName").val(obj[0].HName);
             $("#HSSID").val(obj[0].HItemID);
         }
+        function GetGyMaterial(obj)           //鐗╂枡鍚嶇О
+        {
+            OptionData = obj;
+        }
+
+        function GetAuxiliaryUnitValue(obj)           //璁¢噺鍗曚綅
+        {
+            OptionData = obj[0];
+        }
 
         //#region 澶勭悊灏忔暟鏄剧ず浣嶆暟锛坉ata锛氶渶瑕佸鐞嗙殑鏁版嵁锛沶um锛氭暟鎹殑绫诲瀷(濡�1:鏁伴噺锛�2:閲戦锛�3:鍗曚环)锛�
         function dealDoubleToFixed(data, num) {

--
Gitblit v1.9.1