From fd2625521b82f91dcb8b1c9a227dc8738f580d40 Mon Sep 17 00:00:00 2001
From: Administrator <Administrator@DESKTOP-5BIMHQ3>
Date: 星期一, 05 二月 2024 11:36:31 +0800
Subject: [PATCH] PDA平库入库模块确认入库功能开发

---
 Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs |  375 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 375 insertions(+), 0 deletions(-)

diff --git a/Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs b/Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs
index 676cfdc..dcec486 100644
--- a/Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs
+++ b/Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs
@@ -2004,5 +2004,380 @@
             }
         }
         #endregion
+
+        #region 骞冲簱鍏ュ簱
+        /// <summary>
+        /// 骞冲簱纭鍏ュ簱
+        /// </summary>
+        /// <param name="model"></param>
+        public void ConfirmInStock(PalletBindVm model)
+        {
+            try
+            {
+                #region 楠岃瘉淇℃伅
+                if (string.IsNullOrEmpty(model.ASNNo))
+                {
+                    throw new Exception("鍏ュ簱鍗曚笉鑳戒负绌�!");
+                }
+                if (string.IsNullOrEmpty(model.PalletNo))
+                {
+                    throw new Exception("鎵樼洏鏉$爜涓嶈兘涓虹┖!");
+                }
+                if (string.IsNullOrEmpty(model.LocatNo))
+                {
+                    throw new Exception("鍌ㄤ綅鍦板潃涓嶈兘涓虹┖!");
+                }
+                #endregion
+                //鑾峰彇褰撳墠鏃堕棿
+                DateTime serverTime = Db.Ado.GetDateTime("select GETDATE();");
+
+                #region 鏄惁鍥炴祦鍏ュ簱
+                int iscount = 0;
+                //搴撳瓨鏄庣粏淇℃伅
+                var stockDetail = Db.Queryable<DataStockDetail>().Where(a => a.IsDel == "0" && a.PalletNo == model.PalletNo).ToList();
+                //楠岃瘉搴撳瓨鏄惁鎷ユ湁璇ユ墭淇℃伅
+                if (stockDetail != null && stockDetail.Count > 0)
+                {
+                    iscount = 1; //鍥炴祦鍏ュ簱
+                }
+                #endregion
+
+                #region 鎵樼洏缁戝畾淇℃伅
+                var bindInfo = Db.Queryable<BllPalletBind>().First(w => w.IsDel == "0" && w.ASNNo == model.ASNNo && w.PalletNo == model.PalletNo && w.Status != "2");
+                if (iscount == 0)
+                {
+                    if (bindInfo == null)
+                    {
+                        throw new Exception("鎵樼洏缁戝畾淇℃伅涓嶅瓨鍦紝璇锋牳鏌�!");
+                    }
+                    if (!string.IsNullOrEmpty(bindInfo.WareHouseNo))
+                    {
+                        throw new Exception("璇ユ墭鐩樻湭鍦ㄥ簱澶栵紝璇锋牳鏌�!");
+                    }
+                }
+                
+                #endregion
+
+                #region 鍦扮爜淇℃伅(鍌ㄤ綅淇℃伅)
+                var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == model.LocatNo && w.Status == "0" && w.WareHouseNo == "W02");
+                if (storageLocat == null)
+                {
+                    throw new Exception("鍌ㄤ綅淇℃伅涓嶅瓨鍦ㄦ垨闈炵┖闂茬姸鎬侊紝璇锋牳鏌�!");
+                }
+                #endregion
+
+                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);
+                    //楠岃瘉鍏ュ簱鍗曟�诲崟鏄惁鍏抽棴
+                    if (notice == null)
+                    {
+                        throw new Exception("鍏ュ簱鍗曟�诲崟淇℃伅涓嶅瓨鍦紝璇锋牳鏌�!");
+                    }
+                    //鍒ゆ柇鍏ュ簱鍗曟�诲崟鏄惁涓哄凡鍏抽棴
+                    if (notice.Status == "3")
+                    {
+                        throw new Exception("鍏ュ簱鍗曟�诲崟宸插叧闂紝璇锋牳鏌�!");
+                    }
+                    #endregion
+
+                    bool isFinsh = true;//鏄惁鍏ㄩ儴鍏ュ簱瀹屾垚
+                    #region 鍏ュ簱鍗曟槑缁�
+                    var noticeDetail = Db.Queryable<BllArrivalNoticeDetail>().First(w => w.IsDel == "0" && w.ASNNo == model.ASNNo && w.Id == bindInfo.ASNDetailNo);
+                    if (noticeDetail == null)
+                    {
+                        throw new Exception("鍏ュ簱鍗曟槑缁嗕俊鎭笉瀛樺湪锛岃鏍告煡!");
+                    }
+                    noticeDetail.CompleteQty += bindInfo.Qty;//澧炲姞鍏ュ簱鏁伴噺
+                    //鍒ゆ柇鍏ュ簱鏁伴噺澧炲姞鍚庢槸鍚﹀ぇ浜庣瓑浜庡崟鎹暟閲�
+                    if (noticeDetail.CompleteQty >= noticeDetail.Qty)
+                    {
+                        noticeDetail.Status = "2";//鎵ц瀹屾垚
+                        noticeDetail.CompleteTime = serverTime;
+                    }
+                    else
+                    {
+                        noticeDetail.Status = "1";//姝e湪鎵ц
+
+                        isFinsh = false;
+                    }
+                    noticeDetail.UpdateUser = model.CreateUser;
+                    noticeDetail.UpdateTime = serverTime;
+                    Db.Updateable(noticeDetail).ExecuteCommand();
+                    #endregion
+
+                    #region 鐗╂枡淇℃伅
+                    var sku = Db.Queryable<SysMaterials>().First(s => s.SkuNo == noticeDetail.SkuNo && s.IsDel == "0" && s.SkuName == noticeDetail.SkuName);
+                    //鍒ゆ柇鐗╂枡淇℃伅鏄惁涓虹┖
+                    if (sku == null)
+                    {
+                        throw new Exception("鐗╂枡淇℃伅涓嶅瓨鍦紝璇锋牳鏌�!");
+                    }
+                    #endregion
+
+                    #region 搴撳瓨鎬昏〃
+                    // 鍒ゆ柇褰撳墠鐗╂枡搴撳瓨琛ㄦ槸鍚﹀凡瀛樺湪
+                    var stockModel = Db.Queryable<DataStock>().First(w => w.IsDel == "0" && w.SkuNo == noticeDetail.SkuNo && w.LotNo == bindInfo.LotNo && w.Standard == noticeDetail.Standard);
+                    if (stockModel == null || stockModel.Id == 0)
+                    {
+                        stockModel = new DataStock
+                        {
+                            LotNo = bindInfo.LotNo,
+                            LotText = bindInfo.LotText,
+                            SupplierLot = bindInfo.SupplierLot,
+                            SkuNo = noticeDetail.SkuNo,
+                            SkuName = noticeDetail.SkuName,
+                            Qty = bindInfo.Qty,
+                            Standard = noticeDetail.Standard,
+                            CreateUser = (int)model.CreateUser,
+                            CreateTime = serverTime
+                        };
+                        //鏂板搴撳瓨鎬讳俊鎭�
+                        Db.Insertable<DataStock>(stockModel).ExecuteCommand();
+                    }
+                    else
+                    {
+                        stockModel.Qty += bindInfo.Qty;
+                        stockModel.UpdateUser = (int)model.CreateUser;
+                        stockModel.UpdateTime = serverTime;
+                        //淇敼搴撳瓨鎬讳俊鎭�
+                        Db.Updateable(stockModel).ExecuteCommand();
+                    }
+                    #endregion
+
+                    #region 搴撳瓨鏄庣粏琛�
+                    // 鍒ゆ柇褰撳墠鎵樼洏鏄惁宸插瓨鍦紙鎷h揣鍥炲簱鎵樼洏锛�
+                    var detailModel = Db.Queryable<DataStockDetail>().First(it => it.PalletNo == bindInfo.PalletNo && it.LotNo == bindInfo.LotNo && it.SkuNo == noticeDetail.SkuNo
+                        && it.Standard == noticeDetail.Standard && it.IsDel == "0");
+                    var stId = 0;
+                    if (detailModel == null || detailModel.Id == 0)
+                    {
+                        // 娣诲姞搴撳瓨鏄庣粏琛�
+                        detailModel = new DataStockDetail()
+                        {
+                            LotNo = bindInfo.LotNo,
+                            LotText = bindInfo.LotText,
+                            SupplierLot = noticeDetail.SupplierLot,
+                            SkuNo = noticeDetail.SkuNo,
+                            SkuName = noticeDetail.SkuName,
+                            Standard = noticeDetail.Standard,
+                            Qty = bindInfo.Qty,
+                            LockQty = 0,
+                            FrozenQty = 0,
+                            InspectQty = bindInfo.Qty,
+                            ASNNo = noticeDetail.ASNNo,
+                            ASNDetailNo = (int)bindInfo.ASNDetailNo,
+                            WareHouseNo = "W02",
+                            RoadwayNo = "",
+                            AreaNo = "",
+                            LocatNo = model.LocatNo,
+                            PalletNo = model.PalletNo,
+                            PalletNo2 = bindInfo.PalletNo2,
+                            PalletNo3 = bindInfo.PalletNo3,
+                            CompleteTime = serverTime,
+                            ProductionTime = bindInfo.ProductionTime,
+                            ExpirationTime = bindInfo.ExpirationTime,
+                            Status = "0",
+                            InspectMark = bindInfo.InspectMark,
+                            BitPalletMark = bindInfo.BitPalletMark,
+                            InspectStatus = sku.IsInspect,// 缁勭洏鐨勬椂鍊欏氨瑕侀粯璁よ瀹氬ソ鏄惁鍚堟牸
+                            PackagNo = sku.PackagNo,
+                            IsBale = bindInfo.IsBale,
+                            IsBelt = bindInfo.IsBelt,
+                            CreateUser = (int)model.CreateUser,
+                            CreateTime = serverTime
+                        };
+                        stId = Db.Insertable<DataStockDetail>(detailModel).ExecuteReturnIdentity();
+
+                    }
+                    else
+                    {
+                        stId = detailModel.Id;
+                        detailModel.LocatNo = model.LocatNo;
+                        detailModel.UpdateTime = serverTime;
+                        detailModel.UpdateUser = (int)model.CreateUser;
+                        // 鍙樻洿鍌ㄤ綅鍦板潃
+                        Db.Updateable<DataStockDetail>(detailModel).UpdateColumns(it => new { it.LocatNo, it.UpdateTime, it.UpdateUser }).ExecuteCommand();
+                    }
+                    #endregion
+
+                    #region 浠诲姟鍙婄粍鎵樹俊鎭�
+                    //鍒涘缓浠诲姟淇℃伅
+                    var taskNo = new Common().GetMaxNo("TK");
+                    var exTask = new LogTask    //鍏ュ簱浠诲姟
+                    {
+                        TaskNo = taskNo,
+                        Sender = "WMS",
+                        Receiver = "PDA",
+                        IsSuccess = 1, //鏄惁涓嬪彂鎴愬姛 0澶辫触 1鎴愬姛
+                        SendDate = serverTime,  //鍙戦�佹椂闂�
+                        BackDate = serverTime,  //杩斿洖鏃堕棿
+                        StartLocat = "",//璧峰浣嶇疆
+                        EndLocat = "鍔涜骞冲簱",//鐩爣浣嶇疆
+                        PalletNo = bindInfo.PalletNo,//鎵樼洏鐮�
+                        IsSend = 0,//鏄惁鍙啀娆′笅鍙�
+                        IsCancel = 0,//鏄惁鍙彇娑�
+                        IsFinish = 0,//鏄惁鍙畬鎴�
+                        Type = "0",//浠诲姟绫诲瀷 0 鍏ュ簱浠诲姟 1 鍑哄簱浠诲姟  2 绉诲簱浠诲姟
+                        Status = "2",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚
+                        OrderType = "0",//0 鍏ュ簱鍗� 1 鍑哄簱鍗�  2 鐩樼偣鍗�  3 绉诲簱鍗�
+                        Msg = "鍔涜骞冲簱鐨勫叆搴撲换鍔�",
+                    };
+                    Db.Insertable(exTask).ExecuteCommand();
+
+                    //淇敼缁勬墭鐘舵��
+                    bindInfo.Status = "2"; //2 鍏ュ簱瀹屾垚
+                    bindInfo.WareHouseNo = "W02";//鎵�灞炰粨搴�
+                    bindInfo.LocatNo = model.LocatNo;//鍌ㄤ綅鍦板潃
+                    bindInfo.UpdateTime = serverTime;
+                    bindInfo.UpdateUser = model.CreateUser;
+                    bindInfo.CompleteTime = serverTime; //瀹屾垚鏃堕棿
+                    bindInfo.TaskNo = taskNo; //浠诲姟鍙�
+                    Db.Updateable(bindInfo).ExecuteCommand();
+                    #endregion
+
+                    #region 搴撳瓨绠辨敮鏄庣粏琛�
+                    // 鎻掑叆鏂扮粍鐨勭鏀俊鎭�
+                    var comTime = DateTime.Now;
+                    foreach (var item in boxInfoList)
+                    {
+                        var info = new DataBoxInfo()
+                        {
+                            StockDetailId = stId,
+                            BindNo = bindInfo.Id,
+                            BoxNo = item.BoxNo,
+                            BoxNo2 = item.BoxNo2,
+                            BoxNo3 = item.BoxNo3,
+                            PalletNo = item.PalletNo,
+                            PalletNo2 = item.PalletNo2,
+                            PalletNo3 = item.PalletNo3,
+                            Qty = item.Qty,
+                            FullQty = item.FullQty,
+                            Status = "2",
+                            LotNo = item.LotNo,
+                            LotText = item.LotText,
+                            SkuNo = item.SkuNo,
+                            SkuName = item.SkuName,
+                            Standard = sku.Standard,
+                            ProductionTime = item.ProductionTime,
+                            SupplierLot = item.SupplierLot,
+                            InspectMark = item.InspectMark,
+                            BitBoxMark = item.BitBoxMark,
+                            InspectStatus = item.InspectStatus,
+                            //InspectTime = item.,
+
+                            IsDel = "0",
+                            CreateUser = 0,
+                            CreateTime = comTime
+                        };
+                        Db.Insertable(info).ExecuteCommand();
+                    }
+                    #endregion
+
+                    var entryList = Db.Queryable<BllArrivalNoticeDetail>().Where(w => w.IsDel == "0" && w.ASNNo == notice.ASNNo && w.Id != noticeDetail.Id && w.Status != "2").ToList();
+                    if (isFinsh && entryList.Count <= 0)//鍏ュ簱鍗曟槑缁嗗叏閮ㄥ畬鎴�
+                    {
+                        //淇敼鍏ュ簱鍗曟�诲崟淇℃伅
+                        notice.Status = "2";
+                        notice.UpdateUser = model.CreateUser;
+                        notice.UpdateTime = serverTime;
+                        Db.Updateable(notice).ExecuteCommand();
+                    }
+                    else
+                    {
+                        //鍒ゆ柇鎬诲崟鐘舵�佹槸鍚︿负姝e湪鎵ц
+                        if (notice.Status == "0")
+                        {
+                            //淇敼鍏ュ簱鍗曟�诲崟淇℃伅
+                            notice.Status = "1";
+                            notice.UpdateUser = model.CreateUser;
+                            notice.UpdateTime = serverTime;
+                            Db.Updateable(notice).ExecuteCommand();
+                        }
+                    }
+                }
+                else
+                {
+                    //淇敼搴撳瓨鏄庣粏淇℃伅
+                    foreach (var item in stockDetail)
+                    {
+                        item.Status = "0"; //鐘舵�佹洿鏀逛负寰呭垎閰�
+                        item.WareHouseNo = "W02"; //鎵�灞炰粨搴�
+                        item.LocatNo = model.LocatNo;//鍌ㄤ綅鍦板潃
+                        item.UpdateTime = serverTime; //淇敼鏃堕棿
+                        item.UpdateUser = model.CreateUser; //淇敼浜�
+                        //淇敼搴撳瓨鏄庣粏淇℃伅                                           
+                        Db.Updateable(item).ExecuteCommand();
+                    }
+                    //鑾峰彇鎷h揣淇℃伅
+                    var alotr = Db.Queryable<BllExportAllot>().First(a => a.IsDel == "0" && a.PalletNo == model.PalletNo && a.Status == "4");
+                    if (alotr != null)
+                    {
+                        alotr.Status = "5"; //5 宸插畬鎴�
+                        alotr.UpdateUser = model.CreateUser; //淇敼浜�
+                        alotr.UpdateTime = serverTime; //淇敼鏃堕棿
+                        //淇敼鎷h揣淇℃伅
+                        Db.Updateable(alotr).ExecuteCommand();
+                    }
+                    #region 浠诲姟鍙婄粍鎵樹俊鎭�
+                    //鍒涘缓浠诲姟淇℃伅
+                    var taskNo = new Common().GetMaxNo("TK");
+                    var exTask = new LogTask    //鍏ュ簱浠诲姟
+                    {
+                        TaskNo = taskNo,
+                        Sender = "WMS",
+                        Receiver = "PDA",
+                        IsSuccess = 1, //鏄惁涓嬪彂鎴愬姛 0澶辫触 1鎴愬姛
+                        SendDate = DateTime.Now,  //鍙戦�佹椂闂�
+                        BackDate = DateTime.Now,  //杩斿洖鏃堕棿
+                        StartLocat = "",//璧峰浣嶇疆
+                        EndLocat = "鍔涜骞冲簱",//鐩爣浣嶇疆
+                        PalletNo = model.PalletNo,//鎵樼洏鐮�
+                        IsSend = 0,//鏄惁鍙啀娆′笅鍙�
+                        IsCancel = 0,//鏄惁鍙彇娑�
+                        IsFinish = 0,//鏄惁鍙畬鎴�
+                        Type = "0",//浠诲姟绫诲瀷 0 鍏ュ簱浠诲姟 1 鍑哄簱浠诲姟  2 绉诲簱浠诲姟
+                        Status = "2",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚
+                        OrderType = "0",//0 鍏ュ簱鍗� 1 鍑哄簱鍗�  2 鐩樼偣鍗�  3 绉诲簱鍗�
+                        Msg = "鍔涜骞冲簱鐨勫洖搴撲换鍔�",
+                    };
+                    Db.Insertable(exTask).ExecuteCommand();
+                    #endregion
+                }
+                storageLocat.Status = "1";//鐘舵�佸凡浣跨敤
+                storageLocat.UpdateTime = serverTime; //淇敼鏃堕棿
+                storageLocat.UpdateUser = model.CreateUser; //淇敼浜�
+                //淇敼鍌ㄤ綅淇℃伅                                        
+                Db.Updateable(storageLocat).ExecuteCommand();
+
+                new OperationASNServer().AddLogOperationAsn("PDA妯″潡", "骞冲簱鍏ュ簱", model.PalletNo, "瀹屾垚", $"鍦≒DA涓婂畬鎴愬崟鎹彿涓猴細{model.ASNNo}鐨勬墭鐩樼爜涓猴細{model.PalletNo}鐨勫钩搴撳叆搴撴搷浣�", (int)model.CreateUser);
+
+                Db.CommitTran();
+            }
+            catch (Exception ex)
+            {
+                Db.RollbackTran();
+                throw ex;
+            }
+        }
+        #endregion
     }
 }

--
Gitblit v1.8.0