From b478031d19c13092dc5f86e6d4f7fc114ea9a85d Mon Sep 17 00:00:00 2001
From: Administrator <Administrator@DESKTOP-5BIMHQ3>
Date: 星期一, 11 三月 2024 13:28:29 +0800
Subject: [PATCH] Merge branch 'wxw'

---
 Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs |  252 ++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 193 insertions(+), 59 deletions(-)

diff --git a/Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs b/Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs
index 116e879..1d8d751 100644
--- a/Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs
+++ b/Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs
@@ -42,6 +42,23 @@
             }
         }
 
+        //鏍规嵁鍏ュ簱鍗曞彿鑾峰彇鍏ュ簱鎬诲崟淇℃伅
+        public List<BllArrivalNotice> GetArrivalNotice(ArrivalNoticeVm model)
+        {
+            string sqlString = string.Empty;
+            try
+            {
+                sqlString = $"select * from BllArrivalNotice where ASNNo = '{model.ASNNo}' and isdel='0'  ";
+                var modelList = Db.Ado.SqlQuery<BllArrivalNotice>(sqlString);
+
+                return modelList;
+            }
+            catch (Exception ex)
+            {
+                throw ex;
+            }
+        }
+
         // 鏍规嵁鍗曟嵁鍙疯幏鍙栧崟鎹槑缁嗗垪琛�
         public List<ArrivalNoticeDetailDto> GetArrivalNoticeDetails(ArrivalNoticeVm model)
         {
@@ -1281,6 +1298,30 @@
             }
         }
 
+        /// <summary>
+        /// 楠岃瘉鍌ㄤ綅鍦板潃(鍦扮爜)鏄惁鍙敤
+        /// </summary>
+        /// <param name="locatNo">鍌ㄤ綅缂栫爜</param>
+        /// <returns></returns>
+        public string CheckLocatNo(string locatNo)
+        {
+            try
+            {
+                string strMsg = "";
+                var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == locatNo && w.Status == "0" && w.WareHouseNo == "W02");
+                if (storageLocat == null)
+                {
+                    throw new Exception("-1:鍦扮爜(鍌ㄤ綅淇℃伅)涓嶅瓨鍦ㄦ垨闈炵┖闂茬姸鎬侊紝璇锋牳鏌�!");
+                }
+
+                return strMsg;
+            }
+            catch (Exception ex)
+            {
+                throw new Exception(ex.Message);
+            }
+        }
+
         //鏍规嵁绠辩爜鑾峰彇鐗╂枡銆佹壒娆°�佹暟閲忕瓑淇℃伅
         public PdaPalletNoCheckDto GetBoxInfoByBoxNo(string boxNo)
         {
@@ -1737,8 +1778,6 @@
                 {
                     throw new Exception("-1:鍗曟嵁鍙蜂笉鍙负绌�!");
                 }
-                //鏍规嵁鍗曟嵁鍙疯幏鍙栧叆搴撳崟鎬诲崟
-                var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.AsnNo);
                 if (model.AsnDetailId == null || model.AsnDetailId == 0)
                 {
                     throw new Exception("-1:鐗╂枡涓嶅彲涓虹┖!");
@@ -1746,6 +1785,12 @@
                 if (string.IsNullOrEmpty(model.PalletNo))
                 {
                     throw new Exception("-1:鎵樼洏鍙蜂笉鍙负绌�!");
+                }
+                //鏍规嵁鍗曟嵁鍙疯幏鍙栧叆搴撳崟鎬诲崟
+                var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.AsnNo);
+                if (notice.Status != "0" && notice.Status != "1")
+                {
+                    throw new Exception("-1:鍏ュ簱鍗曠姸鎬佷笉鏄瓑寰呮墽琛屾垨鎵ц瀹屾垚!");
                 }
                 if (string.IsNullOrEmpty(model.LotNo))
                 {
@@ -1763,6 +1808,10 @@
                     if (indexOfDash != -1)
                     {
                         model.LotNo = model.LotNo.Substring(indexOfDash + 1);
+                    }
+                    else
+                    {
+                        model.LotNo = "";
                     }
                 }
                 //鍒ゆ柇鐗╂枡鏁伴噺鏄惁涓�0 涓�0鍒ゆ柇绠辩爜淇℃伅 涓嶄负0缁х画
@@ -1782,6 +1831,52 @@
 
                     }
                 }
+                int isDeposit = 0;
+                //鍒ゆ柇鎬诲崟鍗曟嵁鏄惁涓哄瘎瀛樺崟鎹�
+                if (notice.Type == "7")
+                {
+                    isDeposit = 1;
+                }
+                if (isDeposit == 1)
+                {
+                    //鍒ゆ柇鎬诲崟澶囨敞鏄惁涓虹┖
+                    if (!string.IsNullOrWhiteSpace(notice.Demo))
+                    {
+                        //鍒嗗壊鎬诲崟澶囨敞鍙婃墭鐩樺娉�
+                        var noticeDemo = notice.Demo.Split('銆�'); //鎬诲崟澶囨敞
+                        var palletDemo = model.Demo.Split('銆�'); //鎵樼洏澶囨敞
+
+                        //寰幆鎵樼洏澶囨敞
+                        foreach (var itemPallet in palletDemo)
+                        {
+                            int isDemo = 0;
+                            //寰幆鎬诲崟澶囨敞
+                            foreach (var itemNotice in noticeDemo)
+                            {
+                                //鍒ゆ柇鏄惁鏈夌浉鍚屽娉�
+                                if (itemPallet == itemNotice)
+                                {
+                                    isDemo = 1;
+                                    break;
+                                }
+                            }
+                            if (isDemo == 0)
+                            {
+                                throw new Exception("-1:鎬诲崟澶囨敞涓庢墭鐩樺娉ㄤ笉绗︼紝璇锋牳瀹炲悗閲嶆柊缁戝畾!");
+                            }
+                        }
+                    }
+                    else if (string.IsNullOrWhiteSpace(notice.Demo))
+                    {
+                        //鍒ゆ柇鎵樼洏澶囨敞鏄惁涓虹┖
+                        if (!string.IsNullOrWhiteSpace(model.Demo))
+                        {
+                            throw new Exception("-1:璇锋坊鍔犳�诲崟澶囨敞鍚庤緭鍏ユ墭鐩樺娉�!");
+                        }
+                    }
+                }
+
+
                 #endregion
 
                 Db.BeginTran();
@@ -1791,6 +1886,12 @@
                 if (pallet == null)
                 {
                     throw new Exception("鏈煡璇㈠埌鎵樼洏淇℃伅锛岃鏍稿疄锛�");
+                }
+                //鍒ゆ柇鎵樼洏鏄惁鍦ㄥ簱澶�
+                var stockDetail = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
+                if (stockDetail != null && !string.IsNullOrEmpty(stockDetail.WareHouseNo))
+                {
+                    throw new Exception("璇ユ墭鐩樻湭鍦ㄥ簱澶栵紝璇锋牳瀹烇紒");
                 }
                 // 楠岃瘉鍏ュ簱鍗曟槑缁嗘槸鍚﹀瓨鍦�
                 var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == model.AsnDetailId && m.ASNNo == model.AsnNo && m.LotNo.Contains(model.LotNo));
@@ -1802,40 +1903,46 @@
                 var package = Db.Queryable<SysPackag>().Where(m => m.IsDel == "0");
                 var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == detail.SkuNo);
                 var pack = package.First(m => m.IsDel == "0" && m.PackagNo == sku.PackagNo);
-                if (pack == null)
-                {
-                    throw new Exception("-1:鑾峰彇鐗╂枡鍖呰澶辫触锛岃鏍稿疄!");
-                }
+
                 var pNum = 0;//鎵樼洏鐗╁搧鏁伴噺 
                 var bNum = 0;//绠辩爜鐗╁搧鏁伴噺 
-                if (pack.L5Num.HasValue)
+
+                //鍒ゆ柇鏄惁涓哄瘎瀛樼墿鏂�
+                if (isDeposit == 0)
                 {
-                    pNum = (int)pack.L5Num;
-                    bNum = (int)pack.L4Num;
-                }
-                else if (pack.L4Num.HasValue)
-                {
-                    pNum = (int)pack.L4Num;
-                    bNum = (int)pack.L3Num;
-                }
-                else if (pack.L3Num.HasValue)
-                {
-                    pNum = (int)pack.L3Num;
-                    bNum = (int)pack.L2Num;
-                }
-                else if (pack.L2Num.HasValue)
-                {
-                    pNum = (int)pack.L2Num;
-                    bNum = (int)pack.L1Num;
-                }
-                else if (pack.L1Num.HasValue)
-                {
-                    pNum = (int)pack.L1Num;
-                    bNum = (int)pack.L1Num;
-                }
-                if (pNum == 0 || bNum == 0)
-                {
-                    throw new Exception($"缁戝畾澶辫触锛寋detail.SkuNo}鐗╁搧鍖呰鏈壘鍒帮紒");
+                    if (pack == null)
+                    {
+                        throw new Exception("-1:鑾峰彇鐗╂枡鍖呰澶辫触锛岃鏍稿疄!");
+                    }
+                    if (pack.L5Num.HasValue)
+                    {
+                        pNum = (int)pack.L5Num;
+                        bNum = (int)pack.L4Num;
+                    }
+                    else if (pack.L4Num.HasValue)
+                    {
+                        pNum = (int)pack.L4Num;
+                        bNum = (int)pack.L3Num;
+                    }
+                    else if (pack.L3Num.HasValue)
+                    {
+                        pNum = (int)pack.L3Num;
+                        bNum = (int)pack.L2Num;
+                    }
+                    else if (pack.L2Num.HasValue)
+                    {
+                        pNum = (int)pack.L2Num;
+                        bNum = (int)pack.L1Num;
+                    }
+                    else if (pack.L1Num.HasValue)
+                    {
+                        pNum = (int)pack.L1Num;
+                        bNum = (int)pack.L1Num;
+                    }
+                    if (pNum == 0 || bNum == 0)
+                    {
+                        throw new Exception($"缁戝畾澶辫触锛寋detail.SkuNo}鐗╁搧鍖呰鏈壘鍒帮紒");
+                    }
                 }
                 #endregion
 
@@ -1854,7 +1961,7 @@
                     }
                 }
                 #endregion
-                var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo);
+                var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo && m.Status != "2");
                 var bindId = 0;
                 if (bind == null)
                 {
@@ -1871,14 +1978,16 @@
                         Type = "0",
                         LotNo = model.LotNo,
                         LotText = detail.LotText,
-                        SupplierLot = "",
+                        SupplierLot = detail.SupplierLot,
                         InspectMark = "0",
                         BitPalletMark = "1",
                         IsBale = "0",
                         IsBelt = "0",
-                        CreateUser = userId
+                        CreateUser = userId,
+                        Demo = model.Demo,
+
                     };
-                    if (model.SkuQty > pNum)
+                    if (model.SkuQty > pNum && isDeposit == 0)
                     {
                         throw new Exception($"缁戝畾澶辫触锛寋model.PalletNo}鎵樼洏缁戝畾鏁伴噺澶т簬璇ョ墿鍝佹墭鐩樺寘瑁呮暟閲忥紒");
                     }
@@ -1892,6 +2001,7 @@
                         throw new Exception("-1:褰撳墠鎵樼洏姝e湪鎵ц涓紝缁戝畾澶辫触锛岃鏍稿疄!");
                     }
                     bindId = bind.Id;
+                    bind.Qty += model.SkuQty;
                 }
 
                 #region 绠辩爜淇℃伅
@@ -1926,6 +2036,7 @@
 
                 // 鏇存敼绠辨敮鍏崇郴琛�
                 decimal factQty = 0.00m;//鎵樼洏鎬绘暟閲�
+                //鎴愬搧缁勬墭
                 if (model.SkuQty == 0)
                 {
                     var boxGroup = boxInfoList.GroupBy(m => m.BoxNo).ToList();
@@ -1966,7 +2077,7 @@
                     // 鏇存柊鎵樼洏缁戝畾琛�
                     bind.Qty += factQty;
                 }
-                if (bind.FullQty < bind.Qty)
+                if (bind.FullQty < bind.Qty && isDeposit == 0)
                 {
                     throw new Exception("鎵樼洏缁戝畾鏁伴噺宸茶秴鍑鸿鐗╂枡鍖呰鏁伴噺");
                 }
@@ -1975,7 +2086,7 @@
                 {
                     bind.BitPalletMark = "0";
                 }
-                if (bind.Qty > pNum)
+                if (bind.Qty > pNum && isDeposit == 0)
                 {
                     throw new Exception($"缁戝畾澶辫触锛寋bind.PalletNo}鎵樼洏缁戝畾鏁伴噺澶т簬璇ョ墿鍝佹墭鐩樺寘瑁呮暟閲忥紒");
                 }
@@ -1985,7 +2096,7 @@
                 var sqlString = string.Empty;
                 if (factQty == 0)
                 {
-                    sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{bind.Qty}' where id = '{model.AsnDetailId}';";
+                    sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{model.SkuQty}' where id = '{model.AsnDetailId}';";
                 }
                 else
                 {
@@ -1998,8 +2109,15 @@
                 if (detail.Status == "0")
                 {
                     var sqlString2 = string.Empty;
-                    sqlString2 += $"update BllArrivalNotice set Status = '1',CompleteTime= getDate() where ASNNo = '{model.AsnNo}' and Status ='0';";
-                    sqlString2 += $"update BllArrivalNoticeDetail set Status = '1',CompleteTime= getDate() where id = '{model.AsnDetailId}' and Status ='0';";
+                    sqlString2 += $"update BllArrivalNotice set Status = '1',UpdateTime= getDate(),UpdateUser = {userId} where ASNNo = '{model.AsnNo}' and Status ='0';";
+                    sqlString2 += $"update BllArrivalNoticeDetail set Status = '1',UpdateTime= getDate(),UpdateUser = {userId} where id = '{model.AsnDetailId}' and Status ='0';";
+                    Db.Ado.ExecuteCommand(sqlString2);
+                }
+                else if (detail.Status == "1")
+                {
+                    var sqlString2 = string.Empty;
+                    sqlString2 += $"update BllArrivalNotice set UpdateTime= getDate(),UpdateUser = {userId} where ASNNo = '{model.AsnNo}' and Status ='1';";
+                    sqlString2 += $"update BllArrivalNoticeDetail set UpdateTime= getDate(),UpdateUser = {userId} where id = '{model.AsnDetailId}' and Status ='1';";
                     Db.Ado.ExecuteCommand(sqlString2);
                 }
 
@@ -2053,6 +2171,13 @@
                 //楠岃瘉搴撳瓨鏄惁鎷ユ湁璇ユ墭淇℃伅
                 if (stockDetail != null && stockDetail.Count > 0)
                 {
+                    foreach (var item in stockDetail)
+                    {
+                        if (!string.IsNullOrEmpty(item.WareHouseNo))
+                        {
+                            throw new Exception("璇ユ墭鐩樻湭鍦ㄥ簱澶栵紝璇锋牳鏌�!");
+                        }
+                    }
                     iscount = 1; //鍥炴祦鍏ュ簱
                 }
                 #endregion
@@ -2084,22 +2209,6 @@
                 Db.BeginTran();//寮�鍚簨鍔�
                 if (iscount == 0)//姝e父鍏ュ簱
                 {
-                    #region 绠辩爜淇℃伅
-                    var boxInfoList = Db.Queryable<BllBoxInfo>().Where(w => w.IsDel == "0" && w.ASNNo == model.ASNNo).ToList();
-                    //楠岃瘉绠辩爜淇℃伅鏄惁瀛樺湪
-                    if (boxInfoList.Count <= 0)
-                    {
-                        throw new Exception("绠辩爜淇℃伅涓嶅瓨鍦紝璇锋牳鏌�!");
-                    }
-                    foreach (var item in boxInfoList)
-                    {
-                        item.Status = "2"; // 鏀瑰彉绠辨敮鍏崇郴琛ㄧ姸鎬侊細宸插叆搴�
-                        item.UpdateTime = serverTime;
-                        item.UpdateUser = model.CreateUser;
-                    }
-                    Db.Updateable(boxInfoList).ExecuteCommand();
-                    #endregion
-
                     #region 鍏ュ簱鎬诲崟淇℃伅
                     var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.Status != "3" && a.ASNNo == model.ASNNo);
                     //楠岃瘉鍏ュ簱鍗曟�诲崟鏄惁鍏抽棴
@@ -2111,6 +2220,30 @@
                     if (notice.Status == "3")
                     {
                         throw new Exception("鍏ュ簱鍗曟�诲崟宸插叧闂紝璇锋牳鏌�!");
+                    }
+                    #endregion
+
+                    #region 绠辩爜淇℃伅
+                    var boxInfoList = Db.Queryable<BllBoxInfo>().Where(w => w.IsDel == "0" && w.ASNNo == model.ASNNo).ToList();
+                    // type 0:鎴愬搧鍏ュ簱 1:閲囪喘鍏ュ簱 2:涓棿鍝佸叆搴� 3:閫�璐у叆搴� 4:杞﹂棿浣欐枡閫�鍥炲叆搴� 5:鍏跺畠鍏ュ簱 6:浠e偍鍏ュ簱 7:瀵勫瓨鍏ュ簱
+                    if (notice.Type == "2" || notice.Type == "6" || notice.Type == "7")
+                    {
+                        // 涓嶈创鐮佺墿鏂� 鏃犻渶楠岃瘉绠辩爜淇℃伅
+                    }
+                    else
+                    {
+                        //楠岃瘉绠辩爜淇℃伅鏄惁瀛樺湪
+                        if (boxInfoList.Count <= 0)
+                        {
+                            throw new Exception("绠辩爜淇℃伅涓嶅瓨鍦紝璇锋牳鏌�!");
+                        }
+                        foreach (var item in boxInfoList)
+                        {
+                            item.Status = "2"; // 鏀瑰彉绠辨敮鍏崇郴琛ㄧ姸鎬侊細宸插叆搴�
+                            item.UpdateTime = serverTime;
+                            item.UpdateUser = model.CreateUser;
+                        }
+                        Db.Updateable(boxInfoList).ExecuteCommand();
                     }
                     #endregion
 
@@ -2202,7 +2335,7 @@
                             ASNDetailNo = (int)bindInfo.ASNDetailNo,
                             WareHouseNo = "W02",
                             RoadwayNo = "",
-                            AreaNo = "",
+                            AreaNo = storageLocat.AreaNo,
                             LocatNo = model.LocatNo,
                             PalletNo = model.PalletNo,
                             PalletNo2 = bindInfo.PalletNo2,
@@ -2227,6 +2360,7 @@
                     {
                         stId = detailModel.Id;
                         detailModel.LocatNo = model.LocatNo;
+                        detailModel.AreaNo = storageLocat.AreaNo;
                         detailModel.UpdateTime = serverTime;
                         detailModel.UpdateUser = (int)model.CreateUser;
                         // 鍙樻洿鍌ㄤ綅鍦板潃

--
Gitblit v1.8.0