From 99b5d3d7c950a8332f81d3ca07be9f2d5957f58c Mon Sep 17 00:00:00 2001
From: 南骏 池 <chiffly@163.com>
Date: 星期六, 29 三月 2025 16:26:44 +0800
Subject: [PATCH] 1.期初入库优化

---
 service/Warehouse/MesItemBlManager.cs |  209 +++++++++++++++++++++++++++++++++++----------------
 1 files changed, 142 insertions(+), 67 deletions(-)

diff --git a/service/Warehouse/MesItemBlManager.cs b/service/Warehouse/MesItemBlManager.cs
index ff46948..9b4729b 100644
--- a/service/Warehouse/MesItemBlManager.cs
+++ b/service/Warehouse/MesItemBlManager.cs
@@ -1,4 +1,5 @@
-锘縰sing NewPdaSqlServer.DB;
+锘縰sing Masuit.Tools;
+using NewPdaSqlServer.DB;
 using NewPdaSqlServer.Dto.service;
 using NewPdaSqlServer.entity;
 using NewPdaSqlServer.util;
@@ -19,7 +20,7 @@
         var list = Db.Queryable<MesItemBl>()
             .Where(s => (s.Bl018 ?? false) == true
                         && (s.Bl019 ?? false) == false
-                        && s.Bl008 == query.type)
+                        && s.Bl008 == query.Type)
             .Select(s => s.BlNo)
             .ToList();
         return list;
@@ -39,11 +40,11 @@
 
         // 妫�鏌ヨˉ鏂欏崟鏄惁瀛樺湪涓斾负鐢熶骇琛ユ枡绫诲瀷
         var mesItemBl = Db.Queryable<MesItemBl>()
-            .Where(a => a.BlNo == query.billNo && a.Bl008 == "鐢熶骇琛ユ枡")
+            .Where(a => a.BlNo == query.billNo && a.Bl008 == query.Type && a.Bl018 == true)
             .First();
 
         if (mesItemBl == null)
-            throw new Exception("鍗曟嵁鍙蜂笉姝g‘锛�");
+            throw new Exception("鍗曟嵁鍙蜂笉瀛樺湪鎴栨湭瀹℃牳锛�");
 
         if (mesItemBl.Bl019 == true)
             throw new Exception("鍗曟嵁鍙峰凡瀹屾垚锛�");
@@ -68,6 +69,7 @@
     }
 
     /// <summary>
+    /// 鐢熶骇宸ュ崟琛ユ枡鎵爜
     ///     鎵弿鏉$爜  prc_rf_pda_scan_zout_barcode3
     /// </summary>
     /// <param name="query">鏌ヨ鍙傛暟</param>
@@ -80,11 +82,11 @@
     ///     - blNo: 琛ユ枡鍗曞彿(蹇呭~)
     /// </remarks>
     public (WarehouseQuery item, List<MesItemBlDetail> pendingList)
-        SctlScanBarcode(
+        ScblScanBarcode(
             WarehouseQuery query)
     {
-        if (string.IsNullOrEmpty(query.billNo))
-            throw new Exception("璇烽�夊彇鍗曟嵁鍙凤紒");
+        //if (string.IsNullOrEmpty(query.billNo))
+        //    throw new Exception("璇烽�夊彇鍗曟嵁鍙凤紒");
 
         if (string.IsNullOrEmpty(query.barcode))
             throw new Exception("璇锋壂鎻忔潯鐮侊紒");
@@ -93,7 +95,7 @@
             throw new Exception("鐢ㄦ埛鍚嶄笉鑳戒负绌猴紒");
 
         if (string.IsNullOrEmpty(query.blNo))
-            throw new Exception("琛ユ枡鍗曞彿涓嶈兘涓虹┖锛�");
+            throw new Exception("鐢宠鍗曞彿涓嶈兘涓虹┖锛�");
 
 
         // 妫�楠屾槸鍚﹂噸澶嶆壂鎻�
@@ -112,9 +114,13 @@
         if (stockBarcode == null)
             throw new Exception($"搴撳瓨涓棤姝ゆ潯鐮�,璇锋牳瀵癸紒{query.barcode}");
 
+        var depots = Db.Queryable<MesDepots>()
+            .Where(t => t.DepotId == stockBarcode.DepotId)
+            .First();
+
         // 妫�鏌ヨˉ鏂欏崟鐘舵��
         var mesItemBl = Db.Queryable<MesItemBl>()
-            .Where(a => a.BlNo == query.blNo && (a.Bl018 ?? false) == false)
+            .Where(a => a.BlNo == query.blNo)
             .First();
 
         if (mesItemBl == null)
@@ -139,6 +145,16 @@
         var quantity = (blDetail.Bld007 ?? 0) - (blDetail.Bld008 ?? 0);
         if (quantity == 0)
             throw new Exception("鐗╂枡宸叉壂鐮佸畬鎴愶紝璇锋牳瀵癸紒");
+
+
+        if(stockBarcode.Quantity >  quantity)
+        {
+            query.status = 2;
+            query.message = "鏉$爜搴撳瓨澶т簬闇�棰嗭紝璇锋媶鍒嗭紒";
+            query.CfNum = quantity;
+            query.Num = stockBarcode.Quantity;
+            return (query, []);
+        }
 
         // 妫�鏌ュ伐鍗曚俊鎭�
         var womdaa = Db.Queryable<Womdaa>()
@@ -184,13 +200,21 @@
         // 寮�鍚簨鍔″鐞�
         var success = UseTransaction(db =>
         {
+            var outNoType = "";
+            if(query.Type == "鐢熶骇琛ユ枡")
+            {
+                outNoType = "SCBL(鐢熶骇琛ユ枡)";
+            }else 
+            {
+                outNoType = "SCCL(鐢熶骇瓒呴)";
+            }
             // 鑾峰彇鎴栧垱寤哄嚭搴撳崟
             var outId = Guid.NewGuid();
-            var outNo = BillNo.GetBillNo("BL(宸ュ崟琛ユ枡)");
+            var outNo = BillNo.GetBillNo(outNoType);
 
             var existingOut = db.Queryable<MesInvItemOuts>()
-                .Where(a => a.BbillNo == query.blNo
-                            && a.DepotCode == womdab.Dab017
+                .Where(a => a.TaskNo == query.blNo
+                            && a.DepotId == stockBarcode.DepotId
                             && a.OutDate.Value.Date.ToString("yyyy-MM-dd") ==
                             DateTime.Now.Date.ToString("yyyy-MM-dd")
                             && a.BillTypeId == 200
@@ -218,8 +242,9 @@
                     BillTypeId = 200,
                     TransactionNo = 209,
                     Remark = mesItemBl.Bl007,
-                    DepotCode = womdab.Dab017,
+                    DepotCode = depots.DepotCode,
                     OutPart = womdaa.Daa013,
+                    OutType = query.Type,
                     FType = 0,
                     Factory = stockBarcode.Factory,
                     Company = stockBarcode.Company,
@@ -228,23 +253,25 @@
                     PbillNo = womdaa.Daa001,
                     OutDate = DateTime.Now,
                     Status = 0,
-                    BbillNo = query.blNo
+                    DepotId = stockBarcode.DepotId,
+                    THORGID = stockBarcode.StockOrgId,
+                    //BbillNo = query.billNo
                 }).IgnoreColumns(true).ExecuteCommand();
             }
 
             // 妫�鏌ュ苟鏇存柊鍑哄簱鍗曠墿鏂欐槑缁�
             var itemCount = db.Queryable<MesInvItemOutItems>()
                 .Where(i =>
-                    i.ItemOutId == outId && i.ItemId == stockBarcode.ItemId)
+                    i.ItemOutId == outId && i.ItemId == stockBarcode.ItemId && i.ItemOutId == outId && i.DepotId == stockBarcode.DepotsId.ToString())
                 .Count();
 
             if (itemCount > 0)
                 // 鏇存柊宸插瓨鍦ㄧ殑鐗╂枡鏄庣粏鏁伴噺
                 db.Updateable<MesInvItemOutItems>()
                     .SetColumns(i =>
-                        i.Quantity == i.Quantity + stockBarcode.Quantity)
+                        i.TlQty == i.TlQty + stockBarcode.Quantity)
                     .Where(i =>
-                        i.ItemOutId == outId && i.ItemId == stockBarcode.ItemId)
+                        i.ItemOutId == outId && i.ItemId == stockBarcode.ItemId && i.ItemOutId == outId && i.DepotId == stockBarcode.DepotsId.ToString())
                     .ExecuteCommand();
             else
                 // 鎻掑叆鏂扮殑鐗╂枡鏄庣粏璁板綍
@@ -254,13 +281,14 @@
                     ItemOutId = outId,
                     ItemNo = blDetail.Bld002,
                     Quantity = stockBarcode.Quantity,
+                    TlQty = stockBarcode.Quantity,
                     CreateBy = query.userName,
                     CreateDate = DateTime.Now,
                     LastupdateBy = query.userName,
                     LastupdateDate = DateTime.Now,
                     Factory = stockBarcode.Factory,
                     Company = stockBarcode.Company,
-                    DepotCode = womdab.Dab017,
+                    DepotCode = depots.DepotCode,
                     TaskNo = query.blNo,
                     WorkNo = womdaa.Daa021,
                     WorkLine = blDetail.Bld013,
@@ -268,7 +296,9 @@
                     ErpId = womdab.Eid,
                     ErpAutoid = womdab.Erpid,
                     PbillNo = query.billNo,
-                    ItemId = blDetail.Bld012
+                    ItemId = blDetail.Bld012,
+                    DepotId = stockBarcode.DepotsId.ToString(),
+                    ItemDabid = blDetail.Id,
                     // Unit = blDetail.Bld009,
                     // DepotId = (int)stockBarcode.DepotsId
                 }).IgnoreColumns(true).ExecuteCommand();
@@ -287,7 +317,7 @@
                 CreateDate = DateTime.Now,
                 LastupdateBy = query.userName,
                 LastupdateDate = DateTime.Now,
-                DepotCode = stockBarcode.DepotsCode,
+                DepotCode = depots.DepotCode,
                 DepotSectionCode = stockBarcode.DepotSectionsCode,
                 Remark = blDetail.Bld010,
                 Factory = stockBarcode.Factory,
@@ -312,7 +342,7 @@
                 Guid = Guid.NewGuid(),
                 Status = 1,
                 BillTypeId = 200, // p_bill_type_id
-                TransactionCode = "210", // p_transaction_no
+                TransactionCode = "209", // p_transaction_no
                 BusinessType = -1,
                 ItemBarcode = stockBarcode.ItemBarcode,
                 ItemNo = stockBarcode.ItemNo,
@@ -345,7 +375,7 @@
                     Dab020 = (it.Dab020 ?? 0) + stockBarcode.Quantity,
                     Dab021 = (it.Dab021 ?? 0) + stockBarcode.Quantity
                 })
-                .Where(it => it.Id == womdab.Id && it.Dab003 == womdab.Dab003)
+                .Where(it => it.Guid == womdab.DaaGuid && it.Dab003 == womdab.Dab003)
                 .ExecuteCommand();
 
             // 鏇存柊琛ユ枡鍗曟槑缁嗗凡琛ユ暟閲�
@@ -443,7 +473,7 @@
         if (string.IsNullOrEmpty(query.barcode))
             throw new Exception("璇锋壂鎻忔潯鐮侊紒");
 
-        if (query.Num <= 0)
+        if ((query.Num ?? 0) <= 0)
             throw new Exception("璇疯緭鍏ユ纭殑鍙戞枡鏁伴噺锛�");
 
         if (string.IsNullOrEmpty(query.blNo))
@@ -469,6 +499,16 @@
         var totalQty = stockBarcode.Quantity;
         string newBarcode = null;
 
+        var outNoType = "";
+        if (query.Type == "鐢熶骇琛ユ枡")
+        {
+            outNoType = "SCBL(鐢熶骇琛ユ枡)";
+        }
+        else
+        {
+            outNoType = "SCCL(鐢熶骇瓒呴)";
+        }
+
         // 寮�鍚簨鍔″鐞�
         var success = UseTransaction(db =>
         {
@@ -481,7 +521,7 @@
                     .Where(s => s.Id == stockBarcode.ItemId).First();
 
                 // 鐢熸垚鏂版潯鐮佸彿
-                newBarcode = BillNo.GetBillNo("TMBH(鏉$爜缂栧彿)", mesItems.ItemNo);
+                newBarcode = BillNo.GetBillNo("TM(鏉$爜)", mesItems.ItemNo);
 
                 // 鍐欏叆鏂版潯鐮�
                 executeCommand += db.Insertable(new MesInvItemBarcodes
@@ -528,24 +568,30 @@
 
                 // 鏇存柊鍘熸潯鐮佹暟閲�
                 executeCommand += db.Updateable<MesInvItemBarcodes>()
-                    .SetColumns(it => it.Quantity == totalQty - query.Num)
+                    .SetColumns(it => it.Quantity == it.Quantity - query.Num)
                     .Where(it => it.ItemBarcode == query.barcode)
                     .ExecuteCommand();
 
-                // 鍒犻櫎鍘熸潯鐮佸簱瀛樿褰�
-                executeCommand += db.Deleteable<MesInvItemStocks>()
+                // 鏇存柊鍘熸潯鐮佹暟閲�
+                executeCommand += db.Updateable<MesInvItemStocks>()
+                    .SetColumns(it => it.Quantity == it.Quantity - query.Num)
                     .Where(it => it.ItemBarcode == query.barcode)
                     .ExecuteCommand();
+
+                //// 鍒犻櫎鍘熸潯鐮佸簱瀛樿褰�
+                //executeCommand += db.Deleteable<MesInvItemStocks>()
+                //    .Where(it => it.ItemBarcode == query.barcode)
+                //    .ExecuteCommand();
 
                 // 鎻掑叆鍓╀綑鏉$爜鏁伴噺鐨勬柊搴撳瓨璁板綍
                 executeCommand += db.Insertable(new MesInvItemStocks
                 {
                     Guid = Guid.NewGuid(),
                     TaskNo = stockBarcode.TaskNo,
-                    ItemBarcode = stockBarcode.ItemBarcode,
+                    ItemBarcode = newBarcode,
                     ItemNo = stockBarcode.ItemNo,
                     LotNo = stockBarcode.LotNo,
-                    Quantity = totalQty - query.Num,
+                    Quantity = query.Num,
                     EpFlag = stockBarcode.EpFlag,
                     CustomerNo = stockBarcode.CustomerNo,
                     ItemWt = stockBarcode.ItemWt,
@@ -573,7 +619,7 @@
                     Status = 1,
                     BillTypeId = 200, // p_bill_type_id
                     TransactionCode = "209", // p_transaction_no
-                    BusinessType = -1,
+                    BusinessType = 0,
                     ItemBarcode = newBarcode,
                     ItemNo = stockBarcode.ItemNo,
                     LotNo = stockBarcode.LotNo,
@@ -583,7 +629,7 @@
                     FromInvDepotSectionsCode = null,
                     ToInvDepotsCode = stockBarcode.DepotsCode,
                     ToInvDepotSectionsCode = stockBarcode.DepotSectionsCode,
-                    Description = null,
+                    Description = query.Type + "鎷嗗垎鐢熸垚",
                     CreateBy = query.userName,
                     CreateDate = DateTime.Now,
                     LastupdateBy = query.userName,
@@ -605,11 +651,11 @@
                 throw new Exception("鍙戞枡鏁伴噺澶т簬鏉$爜鏁�,璇锋牳瀵癸紒");
             }
 
-            if (string.IsNullOrEmpty(newBarcode)) newBarcode = query.barcode;
+            //if (string.IsNullOrEmpty(newBarcode)) newBarcode = query.barcode;
 
             // 妫�鏌ヨˉ鏂欏崟鐘舵��
             var mesItemBl = Db.Queryable<MesItemBl>()
-                .Where(a => a.BlNo == query.blNo && (a.Bl018 ?? false) == false)
+                .Where(a => a.BlNo == query.blNo && (a.Bl018 ?? false) == true)
                 .First();
 
             if (mesItemBl == null)
@@ -660,14 +706,19 @@
                     it.TaskNo == query.blNo && it.ItemId == stockBarcode.ItemId)
                 .Sum(it => it.Quantity);
 
-            if (sumQty > remainingQty)
-                throw new Exception(
-                    $"鎷嗗垎鏁伴噺锛歿sumQty} 澶т簬寰呭彂鏂欐暟閲忥細{remainingQty}锛岃鏍稿锛�");
+            //if (sumQty > remainingQty)
+            //    throw new Exception(
+            //        $"鎷嗗垎鏁伴噺锛歿sumQty} 澶т簬寰呭彂鏂欐暟閲忥細{remainingQty}锛岃鏍稿锛�");
+
+
+            var depots = Db.Queryable<MesDepots>()
+                .Where(t => t.DepotId == stockBarcode.DepotId)
+                .First();
 
             // 鑾峰彇鎴栧垱寤哄嚭搴撳崟
             var itemOut = db.Queryable<MesInvItemOuts>()
-                .Where(a => a.BbillNo == query.blNo
-                            && a.DepotCode == womdab.Dab017
+                .Where(a => a.TaskNo == query.blNo
+                            && a.DepotId == stockBarcode.DepotId
                             && a.OutDate.Value.Date.ToString("yyyy-MM-dd") ==
                             DateTime.Now.Date.ToString("yyyy-MM-dd")
                             && a.BillTypeId == 200
@@ -675,11 +726,13 @@
                             && a.Status == 0)
                 .First();
 
+            var outId = new Guid();
+            var outNo = "";
             if (itemOut == null)
             {
                 // 鍒涘缓鏂扮殑鍑哄簱鍗�
-                var outId = Guid.NewGuid();
-                var outNo = BillNo.GetBillNo("BL(宸ュ崟琛ユ枡)");
+                outId = Guid.NewGuid();
+                outNo = BillNo.GetBillNo(outNoType);
 
                 // 鎻掑叆鍑哄簱鍗曚富琛�
                 executeCommand += db.Insertable(new MesInvItemOuts
@@ -694,7 +747,7 @@
                     BillTypeId = 200,
                     TransactionNo = 209,
                     Remark = mesItemBl.Bl007,
-                    DepotCode = womdab.Dab017,
+                    DepotCode = depots.DepotCode,
                     OutPart = womdaa.Daa013,
                     FType = 0,
                     Factory = stockBarcode.Factory,
@@ -704,15 +757,24 @@
                     PbillNo = womdaa.Daa001,
                     OutDate = DateTime.Now,
                     Status = 0,
-                    BbillNo = query.blNo
+                    DepotId = stockBarcode.DepotId,
+                    THORGID = stockBarcode.StockOrgId,
+                    OutType = query.Type,
+                    //BbillNo = query.blNo
                 }).IgnoreColumns(true).ExecuteCommand();
+            }
+            else
+            {
+                 outId = itemOut.Guid;
+                 outNo = itemOut.ItemOutNo;
             }
 
             // 妫�鏌ユ槸鍚﹀凡瀛樺湪鍑哄簱鍗曟槑缁�
             var itemOutItemCount = db.Queryable<MesInvItemOutItems>()
                 .Where(it =>
-                    it.ItemOutId == itemOut.Guid &&
-                    it.ItemId == stockBarcode.ItemId)
+                    it.ItemOutId == outId &&
+                    it.ItemId == stockBarcode.ItemId && 
+                    it.DepotId == stockBarcode.DepotId.ToString())
                 .Count();
 
             if (itemOutItemCount == 0)
@@ -720,16 +782,17 @@
                 executeCommand += db.Insertable(new MesInvItemOutItems
                 {
                     Guid = Guid.NewGuid(),
-                    ItemOutId = itemOut.Guid,
+                    ItemOutId = outId,
                     ItemNo = blDetail.Bld002,
                     Quantity = query.Num,
+                    TlQty = query.Num,
                     CreateBy = query.userName,
                     CreateDate = DateTime.Now,
                     LastupdateBy = query.userName,
                     LastupdateDate = DateTime.Now,
                     Factory = stockBarcode.Factory,
                     Company = stockBarcode.Company,
-                    DepotCode = womdab.Dab017,
+                    DepotCode = depots.DepotCode,
                     TaskNo = query.blNo,
                     WorkNo = womdaa.Daa021,
                     WorkLine = blDetail.Bld013,
@@ -737,24 +800,27 @@
                     ErpId = womdab.Eid,
                     ErpAutoid = womdab.Erpid,
                     PbillNo = query.billNo,
-                    ItemId = blDetail.Bld012
+                    ItemId = blDetail.Bld012,
+                    DepotId = stockBarcode.DepotId.ToString(),
+                    ItemDabid = womdab.Guid,
                     // Unit = blDetail.Bld009,
                     // DepotId = (int)stockBarcode.DepotsId
                 }).IgnoreColumns(true).ExecuteCommand();
             else
                 // 鏇存柊宸叉湁鍑哄簱鍗曟槑缁嗘暟閲�
                 executeCommand += db.Updateable<MesInvItemOutItems>()
-                    .SetColumns(it => it.Quantity == it.Quantity + query.Num)
+                    .SetColumns(it => it.TlQty == (it.TlQty ?? 0) + query.Num)
                     .Where(it =>
-                        it.ItemOutId == itemOut.Guid &&
-                        it.ItemId == stockBarcode.ItemId)
+                    it.ItemOutId == outId &&
+                    it.ItemId == stockBarcode.ItemId &&
+                    it.DepotId == stockBarcode.DepotId.ToString())
                     .ExecuteCommand();
 
             // 鎻掑叆鍑哄簱鏉$爜鏄庣粏
             executeCommand += db.Insertable(new MesInvItemOutCDetails
             {
                 Guid = Guid.NewGuid(),
-                ItemOutId = itemOut.Guid,
+                ItemOutId = outId,
                 ItemBarcode = newBarcode ?? query.barcode,
                 ItemNo = stockBarcode.ItemNo,
                 LotNo = stockBarcode.LotNo,
@@ -764,7 +830,7 @@
                 CreateDate = DateTime.Now,
                 LastupdateBy = query.userName,
                 LastupdateDate = DateTime.Now,
-                DepotCode = stockBarcode.DepotsCode,
+                DepotCode = depots.DepotCode,
                 DepotSectionCode = stockBarcode.DepotSectionsCode,
                 Remark = blDetail.Bld010,
                 Factory = stockBarcode.Factory,
@@ -778,7 +844,8 @@
                 PbillNo = query.billNo,
                 ItemId = blDetail.Bld012,
                 Unit = blDetail.Bld009,
-                DepotId = (int)stockBarcode.DepotsId
+                DepotId = (int)stockBarcode.DepotsId,
+                Dabid = womdab.Guid,
             }).IgnoreColumns(true).ExecuteCommand();
 
             // 鎻掑叆涓氬姟娴佹按
@@ -787,7 +854,7 @@
                 Guid = Guid.NewGuid(),
                 Status = 1,
                 BillTypeId = 200, // p_bill_type_id
-                TransactionCode = "210", // p_transaction_no 
+                TransactionCode = "209", // p_transaction_no 
                 BusinessType = 1,
                 ItemBarcode = newBarcode ?? query.barcode,
                 ItemNo = stockBarcode.ItemNo,
@@ -796,7 +863,7 @@
                 Quantity = query.Num,
                 FromInvDepotsCode = stockBarcode.DepotsCode,
                 FromInvDepotSectionsCode = stockBarcode.DepotSectionsCode,
-                Description = null,
+                Description = query.Type,
                 CreateBy = query.userName,
                 CreateDate = DateTime.Now,
                 LastupdateBy = query.userName,
@@ -820,8 +887,7 @@
                     Dab020 = (it.Dab020 ?? 0) + query.Num, // 宸插彂鏂欐暟閲�
                     Dab021 = (it.Dab021 ?? 0) + query.Num // 宸插彂鏂欐暟閲�
                 })
-                .Where(it => it.Id == womdab.Id && it.Dab003 == womdab.Dab003)
-                .IgnoreColumns(true)
+                .Where(it => it.Guid == womdab.DaaGuid && it.Dab003 == womdab.Dab003)
                 .ExecuteCommand();
 
             // 鏇存柊琛ユ枡鍗曟槑缁嗗凡琛ユ暟閲�
@@ -866,6 +932,13 @@
 
             if (executeCommand <= 1) throw new Exception("鏇存柊澶辫触");
 
+
+            // 鍒涘缓 鎻掑叆鏃ュ織
+            var logService = new LogService();
+            var LogMsg = "[PDA]" + query.Type + "銆傛潯鐮併��" + query.barcode + "銆� 鍑哄簱鍗曞彿銆�" + outNo + "銆�";
+            logService.CreateLog(db, query.userName, womdaa.Guid.ToString(), "WOMDAA", LogMsg, womdaa.Daa001);
+
+
             return executeCommand;
         }) > 0;
 
@@ -897,7 +970,7 @@
         var list = Db.Queryable<MesItemBl>()
             .Where(s => (s.Bl018 ?? false) == true
                         && (s.Bl019 ?? false) == false
-                        && s.Bl008 == query.type)
+                        && s.Bl008 == query.Type)
             .Select(s => s.BlNo)
             .ToList();
         return list;
@@ -915,9 +988,9 @@
         if (string.IsNullOrEmpty(query.billNo))
             throw new Exception("璇烽�夊崟鎹彿锛�");
 
-        // 妫�鏌ヨ秴棰嗗崟鏄惁瀛樺湪涓斾负鐢熶骇瓒呴绫诲瀷
+        // 妫�鏌ヨ秴棰嗗崟鏄惁瀛樺湪涓斾负鐢熶骇瓒呴/濮斿瓒呴绫诲瀷
         var mesItemBl = Db.Queryable<MesItemBl>()
-            .Where(a => a.BlNo == query.billNo && a.Bl008 == "鐢熶骇瓒呴")
+            .Where(a => a.BlNo == query.billNo && a.Bl008 == query.Type)
             .First();
 
         if (mesItemBl == null)
@@ -1100,8 +1173,8 @@
             var outId = Guid.Empty;
             var outNo = "";
             var outRecord = db.Queryable<MesInvItemOuts>()
-                .Where(a => a.BbillNo == query.blNo
-                            && a.DepotCode == womdab.Dab017
+                .Where(a => a.TaskNo == query.blNo
+                            && a.DepotId == stockBarcode.DepotId
                             && a.OutDate.Value.Date == DateTime.Now.Date
                             && a.BillTypeId == 200
                             && a.TransactionNo == 210
@@ -1130,7 +1203,7 @@
                     OutPart = womdaa.Daa013,
                     FType = 0,
                     WorkNo = womdaa.Daa021,
-                    OutType = "鐢熶骇瓒呴鍗�",
+                    OutType = query.Type,
                     BoardItem = womdaa.Daa002,
                     PbillNo = womdaa.Daa001,
                     OutDate = DateTime.Now,
@@ -1170,7 +1243,8 @@
                     ErpId = womdab.Eid,
                     ErpAutoid = womdab.Erpid,
                     PbillNo = query.billNo,
-                    ItemId = blDetail.Bld012
+                    ItemId = blDetail.Bld012,
+                    DepotId = stockBarcode.DepotId.ToString(),
                     // Unit = blDetail.Bld009,
                     // DepotId = stockBarcode.DepotsId
                 }).IgnoreColumns(true).ExecuteCommand();
@@ -1209,7 +1283,8 @@
                 PbillNo = query.billNo,
                 ItemId = blDetail.Bld012,
                 Unit = blDetail.Bld009,
-                DepotId = (int)stockBarcode.DepotsId
+                DepotId = (int)stockBarcode.DepotsId,
+                Dabid = womdab.Guid,
             }).IgnoreColumns(true).ExecuteCommand();
 
             // 鎻掑叆涓氬姟娴佹按
@@ -1248,7 +1323,7 @@
                     Dab020 = (it.Dab020 ?? 0) + stockBarcode.Quantity,
                     Dab023 = (it.Dab023 ?? 0) + stockBarcode.Quantity
                 })
-                .Where(it => it.Id == womdab.Id)
+                .Where(it => it.Guid == womdab.Guid)
                 .ExecuteCommand();
 
             // 鏇存柊瓒呴鍗曟槑缁�
@@ -1652,7 +1727,7 @@
                     Dab020 = (it.Dab020 ?? 0) + stockBarcode.Quantity,
                     Dab023 = (it.Dab023 ?? 0) + stockBarcode.Quantity
                 })
-                .Where(it => it.Id == workOrderDetail.Id)
+                .Where(it => it.Guid == workOrderDetail.Guid)
                 .ExecuteCommand();
 
             // 鏇存柊琛ユ枡鍗曟槑缁嗗凡琛ユ暟閲�

--
Gitblit v1.9.3