Administrator
2024-03-06 65ecd34acf0a3d33e6c1e10c93e351716d749e2f
Wms/WMS.BLL/BllAsnServer/BllBoxInfoServer.cs
@@ -576,7 +576,7 @@
                    packStr += "-" + pack.L5Num + "/" + pack.L5Name;
                }
                //标签表
                var label = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.ASNDetailNo == imId).ToList();
                var label = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.Origin == "WMS生成").ToList();
                #endregion
@@ -614,30 +614,35 @@
                var modelList = new List<BllBoxInfo>();
                var addLotNo = "";
                if (arriveQty < 0)
                {
                    throw new Exception("到货数量不能小于0!");
                }
                Db.BeginTran();
                if (packLevel == 1)
                {
                    #region 一级包装
                    // 根据用户输入的箱数量计算需要的条码数
                    var labQty = label.Sum(m => m.Qty);
                    var qty = asnList.Qty - labQty;//当前单据剩余需要打印的物料数量(不是标签数量)
                    if (qty <= 0)
                    {
                        throw new Exception("当前单据物料标签已打印完毕,如有需要请补打");
                    }
                    //var labQty = label.Sum(m => m.Qty);
                    //var qty = asnList.Qty - labQty;//当前单据剩余需要打印的物料数量(不是标签数量)
                    //if (qty <= 0)
                    //{
                    //    throw new Exception("当前单据物料标签已打印完毕,如有需要请补打");
                    //}
                    #region 到货数量
                    if (arriveQty - qty > 0)
                    {
                        throw new Exception("到货数量大于未打标签数量,请重新输入到货数量并核实!");
                    }
                    else
                    {
                        qty = arriveQty;
                    }
                    //if (arriveQty - qty > 0)
                    //{
                    //    throw new Exception("到货数量大于未打标签数量,请重新输入到货数量并核实!");
                    //}
                    //else
                    //{
                    //    qty = arriveQty;
                    //}
                    var qty = arriveQty;
                    #endregion
                    int labelNum = 1; //生产条码数量
@@ -656,23 +661,38 @@
                    string maxBoxCode = ""; //箱码号
                    // 生成自编批号
                    string toDayTime = DateTime.Now.ToString("yyyyMMdd");
                    var maxLotNo = label.Max(a => a.LotNo);
                    var maxBoxNo = label.Max(a => a.BoxNo);
                    if (isReset == "0")
                    {
                        maxLotNoStr = maxLotNo;
                        maxBoxCode = maxBoxNo;
                        if (string.IsNullOrWhiteSpace(maxLotNoStr))
                        //判断单据是否是余料退回单
                        if (asn.Type == "4")
                        {
                            maxLotNoStr = toDayTime.Substring(2, 6) + "0001";
                            maxLotNoStr = asnList.LotNo;
                            maxBoxCode = label.Where(m=>m.LotNo == maxLotNoStr).Max(a => a.BoxNo);
                            if (string.IsNullOrWhiteSpace(maxLotNoStr))
                            {
                                throw new Exception("车间余料退回单据批次不能为空");
                            }
                        }
                        else
                        {
                            var labelCount = label.Where(m => m.ASNDetailNo == imId).ToList();
                            if (labelCount.Count <= 0)
                            {
                                throw new Exception("当前单据明细还未生成标签,请选择重置批次选项为‘是’;");
                            }
                            maxLotNoStr = label.Max(a => a.LotNo);
                            maxBoxCode = label.Max(a => a.BoxNo);
                            if (string.IsNullOrWhiteSpace(maxLotNoStr))
                            {
                                maxLotNoStr = toDayTime.Substring(2, 6) + "0001";
                            }
                        }
                    }
                    else
                    {
                        var maxCode = Db.Queryable<BllLabelBoxNo>().Max(a => a.LotNo);                        // 获取今天最大批次号
                        var maxCode = Db.Queryable<BllBoxInfo>().Where(m=>m.Origin == "WMS生成").Max(a => a.LotNo);                        // 获取今天最大批次号
                        if (string.IsNullOrWhiteSpace(maxCode))
                        {
                            maxLotNoStr = toDayTime.Substring(2, 6) + "0001";
@@ -720,7 +740,7 @@
                        }
                        //获取箱码
                        if (maxBoxCode == "")
                        if (string.IsNullOrWhiteSpace(maxBoxCode))
                        {
                            var str = "B"+maxLotNoStr + "000001"; //批号+ 流水  2302010001000001
                            maxBoxCode = str;
@@ -769,25 +789,27 @@
                    #region 二级包装
                    // 根据用户输入的箱数量计算需要的条码数
                    var labQty = label.Sum(m => m.Qty);
                    var qty2 = asnList.Qty - labQty;
                    if (qty2 <= 0)
                    {
                        throw new Exception("当前单据物料标签已打印完毕,如有需要请补打");
                    }
                    //var labQty = label.Sum(m => m.Qty);
                    //var qty2 = asnList.Qty - labQty;
                    //if (qty2 <= 0)
                    //{
                    //    throw new Exception("当前单据物料标签已打印完毕,如有需要请补打");
                    //}
                    #region 增加到货数量
                    if (arriveQty - qty2 > 0)
                    {
                        throw new Exception("到货数量大于未打标签数量,请重新输入到货数量!");
                    }
                    else
                    {
                        qty2 = arriveQty;
                    }
                    //if (arriveQty - qty2 > 0)
                    //{
                    //    throw new Exception("到货数量大于未打标签数量,请重新输入到货数量!");
                    //}
                    //else
                    //{
                    //    qty2 = arriveQty;
                    //}
                    #endregion
                    var qty2 = arriveQty;
                    int labelNum2 = 1; //生产箱条码数量
                    labelNum2 = int.Parse(Math.Ceiling(qty2 / bNum).ToString());
@@ -806,20 +828,37 @@
                    string toDayTime2 = DateTime.Now.ToString("yyyyMMdd");
                    if (isReset == "0")
                    {
                        var maxCode = label.Max(a => a.LotNo);
                        var boxCode1 = label.Max(a => a.BoxNo);//箱号
                        var boxCode2 = label.Max(a => a.BoxNo3);//支号
                        maxCodestr2 = maxCode;
                        maxboxcode2 = boxCode1;
                        maxboxcode3 = boxCode2;
                        if (string.IsNullOrWhiteSpace(maxCodestr2))
                        //判断单据是否是余料退回单
                        if (asn.Type == "4")
                        {
                            maxCodestr2 = toDayTime2.Substring(2, 6) + "0001";
                            maxCodestr2 = asnList.LotNo;
                            maxboxcode2 = label.Where(m => m.LotNo == maxCodestr2).Max(a => a.BoxNo);
                            maxboxcode3 = label.Where(m => m.LotNo == maxCodestr2).Max(a => a.BoxNo3);//支号
                            if (string.IsNullOrWhiteSpace(maxCodestr2))
                            {
                                throw new Exception("车间余料退回单据批次不能为空");
                            }
                        }
                        else
                        {
                            var labelCount = label.Where(m => m.ASNDetailNo == imId).ToList();
                            if (labelCount.Count <= 0)
                            {
                                throw new Exception("当前单据明细还未生成标签,请选择重置批次选项为‘是’;");
                            }
                            maxCodestr2 = label.Max(a => a.LotNo); ;
                            maxboxcode2 = label.Max(a => a.BoxNo);//箱号;
                            maxboxcode3 = label.Max(a => a.BoxNo3);//支号;
                            if (string.IsNullOrWhiteSpace(maxCodestr2))
                            {
                                maxCodestr2 = toDayTime2.Substring(2, 6) + "0001";
                            }
                        }
                    }
                    else
                    {
                        var maxCode = Db.Queryable<BllLabelBoxNo>().Max(a => a.LotNo);                        // 获取今天最大批次号
                        var maxCode = Db.Queryable<BllBoxInfo>().Where(m => m.Origin == "WMS生成").Max(a => a.LotNo);                        // 获取今天最大批次号
                        if (string.IsNullOrWhiteSpace(maxCode))
                        {
                            maxCodestr2 = toDayTime2.Substring(2, 6) + "0001";
@@ -868,7 +907,7 @@
                        }
                        //获取箱码
                        if (maxboxcode2 == "")
                        if (string.IsNullOrWhiteSpace(maxboxcode2))
                        {
                            maxboxcode2 = "B"+maxCodestr2 + "000001"; // 箱号     批号+第几箱
                        }
@@ -912,7 +951,7 @@
                                }
                            }
                            
                            if (maxboxcode3 == "")
                            if (string.IsNullOrWhiteSpace(maxboxcode3))
                            {
                                maxboxcode3 = "Z"+maxCodestr2 + "0001"; // 支号     批号+第几箱 
                            }
@@ -975,7 +1014,7 @@
                        Db.Updateable(asnList).ExecuteCommand();
                    } 
                }
                Db.CommitTran();
                return modelList;
@@ -983,6 +1022,7 @@
            }
            catch (Exception e)
            {
                Db.RollbackTran();
                throw new Exception(e.Message);
            }
        }
@@ -1512,7 +1552,7 @@
                                        model1.Qty = item.Qty;// 数量
                                        model1.BoxNo = item.BoxNo3;                 // 支号     
                                        model.ImgStr = BarcodeHelper.GetCodeBarBase64(model1.BoxNo, 160, 40, false);
                                        model1.ImgStr = BarcodeHelper.GetCodeBarBase64(model1.BoxNo, 160, 40, false);
                                        // 添加到list集合
                                        printModelList.Add(model1);
@@ -1543,9 +1583,6 @@
                #endregion
                //dataContext.WmsLabelPrintLog.InsertAllOnSubmit(printlog);
                //    dataContext.SubmitChanges();
                //    return printModel;
                return printModelList;
            }
            catch (Exception e)