wxw
2024-08-13 adb69643f9f8fef29f2f20f51ee8faff97583ad2
Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs
@@ -1083,5 +1083,86 @@
        }
        #endregion
        #region 零箱解绑
        public void LingxingUnbind(string palletNo,string boxNo, int userId)
        {
            try
            {
                if (string.IsNullOrEmpty(palletNo))
                {
                    throw new Exception("托盘号不能为空");
                }
                if (string.IsNullOrEmpty(boxNo))
                {
                    throw new Exception("箱码不能为空");
                }
                //开启事务
                Db.BeginTran();
                var comTime = DateTime.Now;
                //托盘库存明细信息
                var detail = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == palletNo);
                if (detail == null)
                {
                    throw new Exception("该托盘库存明细信息不存在");
                }
                //库存箱支明细信息
                var boxList = Db.Queryable<DataBoxInfo>().Where(w => w.IsDel == "0" && w.StockDetailId == detail.Id && w.BoxNo == boxNo).ToList();
                if (boxList.Count <= 0)
                {
                    throw new Exception("该箱码库存箱支信息不存在");
                }
                decimal boxQty = 0;//箱内数量
                foreach (var item in boxList)
                {
                    boxQty += item.Qty;
                    item.StockDetailId = 0;//清空托盘外键
                }
                //更新库存箱支明细表
                Db.Updateable(boxList).ExecuteCommand();
                detail.Qty -= boxQty;//托盘库存数量
                detail.BitPalletMark = "1";//零托标记
                //更新托盘库存表
                Db.Updateable(detail).ExecuteCommand();
                //添加托盘解绑绑定记录
                var unBind = new BllPalletUnbind()
                {
                    UpbindPalletNo = palletNo,
                    BindPalletNo = "",
                    LotNo = detail.LotNo,
                    LotText = detail.LotText,
                    SupplierLot = detail.SupplierLot,
                    SkuNo = detail.SkuNo,
                    SkuName = detail.SkuName,
                    Standard = detail.Standard,
                    Qty = boxQty,
                    PalletNo2 = detail.PalletNo2,
                    PalletNo3 = detail.PalletNo3,
                    BoxNo = boxNo,
                    InspectNo = "",
                    InspectStatus = detail.InspectStatus,
                    IsDel = "0",
                    CreateTime = comTime,
                    CreateUser = userId
                };
                Db.Insertable(unBind).ExecuteCommand();
                //添加操作日志
                new OperationCrServer().AddLogOperationCr("库内作业", "操作日志", boxNo, "编辑", $"零箱解绑:原托盘码:{palletNo}上的箱码{boxNo}解绑", userId);
                //提交事务
                Db.CommitTran();
            }
            catch (Exception e)
            {
                //回滚事务
                Db.RollbackTran();
                throw new Exception(e.Message);
            }
        }
        #endregion
    }
}