using Model.InterFaceModel;
|
using Model.ModelDto;
|
using Model.ModelVm;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Linq.Expressions;
|
using Model.ModelDto.BllAsnDto;
|
using Utility.Tools;
|
using WMS.BLL.LogServer;
|
using WMS.DAL;
|
using WMS.Entity.BllAsnEntity;
|
using WMS.Entity.Context;
|
using WMS.Entity.SysEntity;
|
using WMS.IBLL.IBllAsnServer;
|
|
namespace WMS.BLL.BllAsnServer
|
{
|
public class BllBoxInfoServer : DbHelper<BllBoxInfo>, IBllBoxInfoServer
|
{
|
private static readonly SqlSugarScope Db = DataContext.Db;
|
|
public BllBoxInfoServer() : base(Db)
|
{
|
}
|
|
//添加箱码信息
|
public string AddBoxInfo(BoxInfoVm model)
|
{
|
string strMessage = "";
|
string sqlString = string.Empty;
|
try
|
{
|
if (string.IsNullOrEmpty(model.BoxNo))
|
{
|
strMessage = "-1:箱码不可为空!";
|
return strMessage;
|
}
|
//if (string.IsNullOrEmpty(model.BoxNo2))
|
//{
|
// strMessage = "-1:盒码不可为空!";
|
// return strMessage;
|
//}
|
if (string.IsNullOrEmpty(model.BoxNo3))
|
{
|
strMessage = "-1:支码不可为空!";
|
return strMessage;
|
}
|
if (string.IsNullOrEmpty(model.SkuNo))
|
{
|
strMessage = "-1:物料编码不可为空!";
|
return strMessage;
|
}
|
if (string.IsNullOrEmpty(model.LotNo))
|
{
|
strMessage = "-1:批次号不可为空!";
|
return strMessage;
|
}
|
if (model.Qty == null || model.Qty <= 0)
|
{
|
strMessage = "-1:实际数量必须大于0!";
|
return strMessage;
|
}
|
if (string.IsNullOrEmpty(model.ProductionTime))
|
{
|
strMessage = "-1:生产日期不可为空!";
|
return strMessage;
|
}
|
|
// 验证是否重复 支/袋码
|
sqlString += $@"select count(id) from BllBoxInfo where BoxNo3 = '{model.BoxNo3}' and IsDel = 0 ";
|
int rowCount = Db.Ado.GetInt(sqlString);
|
if (rowCount > 0)
|
{
|
strMessage = "-1:重复数据!";
|
return strMessage;
|
}
|
// 获取物料信息
|
sqlString = "select tb1.SkuNo,tb1.SkuName,tb1.Warranty, ";
|
sqlString += "case tb2.level when 5 then tb2.L4Num when 4 then tb2.L3Num when 3 then tb2.L2Num else 0 end as FullQty ";
|
sqlString += "from SysMaterials as tb1 left join SysPackag as tb2 on tb1.PackagNo = tb2.PackagNo ";
|
sqlString += $"where SkuNo = '{model.SkuNo}' and tb1.IsDel = '0';";
|
var materialModel = Db.Ado.SqlQuery<BoxInfoVm>(sqlString);
|
if (materialModel.Count <= 0)
|
{
|
strMessage = "-1:该物料信息不存在!";
|
return strMessage;
|
}
|
DateTime Ptime = DateTime.Parse(model.ProductionTime);
|
double dayNum = (int)materialModel[0].Warranty;
|
model.ExpirationTime = Ptime.AddDays(dayNum);
|
if (string.IsNullOrEmpty(model.InspectMark))
|
{
|
model.InspectMark = "0";
|
}
|
if (string.IsNullOrEmpty(model.BitBoxMark))
|
{
|
model.BitBoxMark = "0";
|
}
|
|
var sku = Db.Queryable<SysMaterials>().First(m => m.SkuNo == model.SkuNo);
|
if (sku == null)
|
{
|
throw new Exception("未查询到物料信息");
|
}
|
|
#region 包装信息
|
string str = $"select SUM(Qty) Qty from BllBoxInfo where IsDel = '0' and BoxNo = '{model.BoxNo}'";
|
//获取箱码信息
|
var box = Db.Ado.SqlQuerySingle<BoxInfoVm>(str);
|
if (box.Qty == null)
|
{
|
box.Qty = 0;
|
}
|
box.Qty = box.Qty + model.Qty;
|
var package = Db.Queryable<SysPackag>().Where(m => m.IsDel == "0");
|
var pack = package.First(m => m.IsDel == "0" && m.PackagNo == sku.PackagNo);
|
var pNum = 0;//物品包装数量
|
if (pack.L5Num.HasValue)
|
{
|
pNum = (int)pack.L5Num;
|
}
|
if (pack.L4Num.HasValue)
|
{
|
pNum = (int)pack.L4Num;
|
}
|
if (pack.L3Num.HasValue)
|
{
|
pNum = (int)pack.L3Num;
|
}
|
if (pack.L2Num.HasValue)
|
{
|
pNum = (int)pack.L2Num;
|
if (pack.L2Name == "箱")
|
{
|
if (box.Qty > (int)pack.L2Num)
|
{
|
throw new Exception($"绑定失败,箱支{model.BoxNo}实际数量大于物品包装数量!");
|
}
|
}
|
}
|
if (pack.L1Num.HasValue)
|
{
|
pNum = (int)pack.L1Num;
|
if (pack.L1Name == "支" || pack.L1Name == "盒" || pack.L1Name == "袋" || pack.L1Name == "根" || pack.L1Name == "块")
|
{
|
if (model.Qty > (int)pack.L1Num)
|
{
|
throw new Exception($"绑定失败,箱支{model.BoxNo3}实际数量大于物品包装数量!");
|
}
|
}
|
}
|
|
if (pNum == 0)
|
{
|
throw new Exception($"绑定失败,{sku.SkuNo}物品包装未找到!");
|
}
|
|
#endregion
|
|
// 插入信息
|
sqlString = "Insert into BllBoxInfo (BoxNo,BoxNo2,BoxNo3,SkuNo,SkuName,LotNo,LotText,";
|
sqlString += "Qty,FullQty,ProductionTime,ExpirationTime,InspectMark,InspectStatus,BitBoxMark,Origin,Status,CreateUser) values ( ";
|
sqlString += $"'{model.BoxNo}','{model.BoxNo2}','{model.BoxNo3}','{model.SkuNo}', ";
|
sqlString += $"'{materialModel[0].SkuName}','{model.LotNo}','{model.LotText}','{model.Qty}','{materialModel[0].FullQty}',";
|
sqlString += $"'{model.ProductionTime}','{model.ExpirationTime}','{model.InspectMark}','{sku.IsInspect}','{model.BitBoxMark}','{model.Origin}','0','{model.CreateUser}');";
|
|
rowCount = Db.Ado.ExecuteCommand(sqlString);
|
if (rowCount <= 0)
|
{
|
strMessage = "-1:添加失败!";
|
}
|
else
|
{
|
if (model.Origin == "录入")
|
{
|
new OperationASNServer().AddLogOperationAsn("入库作业", "箱支录入", model.BoxNo3, "添加", $"添加了箱码:{model.BoxNo}、追溯码:{model.BoxNo3}的箱支物料信息", Convert.ToInt32(model.CreateUser));
|
}
|
}
|
|
return strMessage;
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
}
|
|
//删除箱码信息
|
public string DelBoxInfo(BoxInfoVm model)
|
{
|
string sqlString = string.Empty;
|
try
|
{
|
var boxInfo = Db.Queryable<BllBoxInfo>().First(m => m.IsDel == "0" && m.Id == model.Id);
|
if (boxInfo == null)
|
{
|
throw new Exception("未查询到信息");
|
}
|
//开启事务
|
Db.Ado.BeginTran();
|
// 删除明细单
|
sqlString += $"UPDATE BllBoxInfo SET IsDel = '1',";
|
sqlString += $"UpdateTime = GETDATE(),UpdateUser = '{model.CreateUser}' ";
|
sqlString += $"WHERE Id = '{model.Id}' and Status = '0';";
|
|
int rowCount = Db.Ado.ExecuteCommand(sqlString);
|
if (rowCount <= 0)
|
{
|
return "-1:状态已变更无法删除!";
|
}
|
var boxInfoList = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == boxInfo.BoxNo && m.Id != model.Id).ToList();
|
if (boxInfoList.Count != 0)
|
{
|
foreach (var item in boxInfoList)
|
{
|
if (item.BitBoxMark == "1" || item.Status != "0")
|
{
|
continue;
|
}
|
|
var sql = $"update BllBoxInfo SET BitBoxMark = '1' Where id = {item.Id}";
|
int rowCount2 = Db.Ado.ExecuteCommand(sql);
|
if (rowCount2 <= 0)
|
{
|
throw new Exception("-1:状态已变更无法删除!");
|
}
|
}
|
}
|
|
Db.Ado.CommitTran();
|
new OperationASNServer().AddLogOperationAsn("入库作业", "箱支录入", boxInfo.BoxNo3, "删除", $"删除了箱码:{boxInfo.BoxNo}、追溯码:{boxInfo.BoxNo3}的箱支物料信息", Convert.ToInt32(model.CreateUser));
|
|
return "";
|
}
|
catch (Exception ex)
|
{
|
Db.Ado.RollbackTran();
|
throw new Exception(ex.Message);
|
}
|
}
|
|
//获取箱码信息(未绑定托盘的箱码)
|
public List<BoxInfoDto> GetBoxInfoList(BoxInfoVm model, out int count)
|
{
|
string sqlString = string.Empty;
|
string sqlCount = string.Empty;
|
string sqlPub = string.Empty;
|
try
|
{
|
if (model.Page == 0)
|
{
|
model.Page = 1;
|
}
|
Expression<Func<BllBoxInfo, bool>> item = Expressionable.Create<BllBoxInfo>()
|
.AndIF(!string.IsNullOrWhiteSpace(model.BoxNo), it => it.BoxNo.Contains(model.BoxNo.Trim()))
|
.AndIF(!string.IsNullOrWhiteSpace(model.BoxNo2), it => it.BoxNo2.Contains(model.BoxNo2.Trim()))
|
.AndIF(!string.IsNullOrWhiteSpace(model.BoxNo3), it => it.BoxNo3.Contains(model.BoxNo3.Trim()))
|
.AndIF(!string.IsNullOrWhiteSpace(model.SkuNo), it => it.SkuNo.Contains(model.SkuNo.Trim()))
|
.AndIF(!string.IsNullOrWhiteSpace(model.LotNo), it => it.LotNo.Contains(model.LotNo.Trim()))
|
.AndIF(!string.IsNullOrWhiteSpace(model.LotText), it => it.LotText.Contains(model.LotText.Trim()))
|
.AndIF(!string.IsNullOrWhiteSpace(model.ProductionTime), it => it.ProductionTime >= Convert.ToDateTime(model.ProductionTime))
|
.AndIF(!string.IsNullOrWhiteSpace(model.InspectMark), it => it.InspectMark == model.InspectMark.Trim())
|
.AndIF(!string.IsNullOrWhiteSpace(model.BitBoxMark), it => it.BitBoxMark == model.BitBoxMark.Trim())
|
.AndIF(!string.IsNullOrWhiteSpace(model.Origin), it => it.Origin == model.Origin.Trim())
|
.And(m => m.SkuNo != "100099" && m.IsDel == "0" && m.Status == "0")
|
.ToExpression();//注意 这一句 不能少
|
var total = 0;
|
var data = GetAllWhereAsync(item)
|
.LeftJoin<SysUserInfor>((a, b) => a.CreateUser == b.Id)
|
.LeftJoin<SysUserInfor>((a, b, c) => a.CreateUser == c.Id)
|
.Select((a, b, c) => new BoxInfoDto()
|
{
|
Id = a.Id,
|
BoxNo = a.BoxNo,
|
BoxNo2 = a.BoxNo2,
|
BoxNo3 = a.BoxNo3,
|
Status = a.Status,
|
Origin = a.Origin,
|
SkuNo = a.SkuNo,
|
SkuName = a.SkuName,
|
Qty = a.Qty,
|
FullQty = a.FullQty,
|
LotNo = a.LotNo,
|
LotText = a.LotText,
|
SupplierLot = a.SupplierLot,
|
BitBoxMark = a.BitBoxMark,
|
InspectStatus = a.InspectStatus,
|
InspectMark = a.InspectMark,
|
ProductionTime = a.ProductionTime,
|
ExpirationTime = a.ExpirationTime,
|
CreateUserName = b.RealName,
|
UpdateUserName = c.RealName,
|
CreateTime = a.CreateTime,
|
UpdateTime = a.UpdateTime
|
})
|
.OrderByDescending(a => a.CreateTime)
|
.ToOffsetPage(model.Page, model.Limit, ref total);
|
count = total;
|
return data;
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
//导入箱码信息
|
public string ImportBoxInfo(BoxInfoVms models)
|
{
|
string strMessage = "";
|
try
|
{
|
if (models.ListBoxInfo.Count <= 0)
|
{
|
strMessage = "-1:文件内无数据请核实!";
|
}
|
var num = 0;
|
int CreateUser = Convert.ToInt32(models.CreateUser);
|
List<string> boxList = new List<string>();
|
foreach (BoxInfoVm model in models.ListBoxInfo)
|
{
|
try
|
{
|
model.CreateUser = models.CreateUser;
|
model.Origin = "导入";
|
var msg = AddBoxInfo(model);
|
strMessage += msg;
|
if (msg == "")
|
{
|
num += 1;
|
var hasBoxItem = boxList.Exists(x => x == model.BoxNo);
|
if (!hasBoxItem)
|
{
|
boxList.Add(model.BoxNo);
|
}
|
}
|
}
|
catch
|
{
|
// ignored
|
}
|
}
|
if (num > 0)
|
{
|
new OperationASNServer().AddLogOperationAsn("入库作业", "箱支录入", $"共导入了{boxList.Count}箱", "导入", $"共导入了{boxList.Count}箱,共导入了{num}支", CreateUser);
|
}
|
if (strMessage.Contains("-1") && num > 0)
|
{
|
return "部分导入成功" + strMessage;
|
}
|
if (num>0)
|
{
|
return "导入成功" + strMessage;
|
}
|
|
return strMessage;
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
}
|
|
//根据箱码获取未组盘的箱码信息
|
public List<BoxInfoDto> GetBoxInfoList(string boxCode, string isContinue, string boxCode2)
|
{
|
try
|
{
|
if (string.IsNullOrWhiteSpace(boxCode))
|
{
|
return null;
|
}
|
|
var sql = $@" select BoxNo,SkuNo,SkuName,LotNo,sum(Qty) as Qty,Status from BllBoxInfo group by BoxNo,SkuNo,SkuName,LotNo,Status,IsDel ";
|
|
if (isContinue == "1")
|
{
|
if (string.IsNullOrWhiteSpace(boxCode2))
|
{
|
throw new Exception("开启连续组托时,尾箱码信息不可为空!");
|
}
|
sql += $"having BoxNo >= '{boxCode}' and BoxNo <= '{boxCode2}' and Status = '0' and IsDel = '0' ";
|
}
|
else
|
{
|
sql += $"having BoxNo = '{boxCode}' and Status = '0' and IsDel = '0' ";
|
|
}
|
|
var data = Db.Ado.SqlQuery<BoxInfoDto>(sql);
|
return data;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
|
//获取标签信息(生成标签)
|
public List<LabelBoxDto> AddLabelBoxReturn(int imId, string isReset, decimal arriveQty, string skuName, string standard, string packStandard, string skuNo,
|
string supplierLot, string productionTime, string expirationTime, string storeTime, int userId)
|
{
|
try
|
{
|
|
#region 单据、物料、包装、标签信息获取
|
|
var asnList = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.Id == imId && m.IsDel == "0");
|
if (asnList == null)
|
{
|
throw new Exception("未查询到单据明细信息");
|
}
|
var asn = Db.Queryable<BllArrivalNotice>().First(m => m.ASNNo == asnList.ASNNo && m.IsDel == "0");
|
if (asn == null)
|
{
|
throw new Exception("未查询到单据信息");
|
}
|
//物料
|
var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == asnList.SkuNo);
|
var pack = Db.Queryable<SysPackag>().First(m => m.IsDel == "0" && m.PackagNo == asnList.PackagNo);
|
if (pack == null)
|
{
|
throw new Exception("未查询到当前单据中物料的包装信息");
|
}
|
//标签表
|
var label = Db.Queryable<BllLabelBoxNo>().Where(m => m.IsDel == "0" && m.ASNDetailNo == imId).ToList();
|
|
|
#endregion
|
|
#region 包装查询
|
|
var bNum = 0;//箱物品数量
|
var zNum = 0;//支物品数量
|
var packLevel = 0;
|
var isGo = true;
|
|
if (pack.L5Num.HasValue)
|
{
|
if (pack.L5Name != "托")
|
{
|
isGo = false;
|
packLevel = 5;
|
bNum = Convert.ToInt32(pack.L5Num);
|
}
|
}
|
if (pack.L4Num.HasValue && isGo)
|
{
|
if (pack.L4Name != "托")
|
{
|
isGo = false;
|
packLevel = 4;
|
bNum = Convert.ToInt32(pack.L4Num);
|
}
|
}
|
if (pack.L3Num.HasValue && isGo)
|
{
|
if (pack.L4Name != "托")
|
{
|
isGo = false;
|
packLevel = 3;
|
bNum = Convert.ToInt32(pack.L3Num);
|
}
|
}
|
if (pack.L2Num.HasValue)
|
{
|
packLevel = 2;
|
bNum = Convert.ToInt32(pack.L2Num);
|
|
}
|
if (pack.L1Num.HasValue)
|
{
|
if (packLevel == 0)
|
{
|
packLevel = 1;
|
bNum = Convert.ToInt32(pack.L1Num);
|
}
|
zNum = Convert.ToInt32(pack.L1Num);
|
}
|
|
if (packLevel <= 1)//包装等级小于1,按照1级标签打印
|
{
|
packLevel = 1;
|
}
|
|
#endregion
|
|
if (packLevel == 1)
|
{
|
#region 一级包装
|
|
// 根据用户输入的箱数量计算需要的条码数
|
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;
|
}
|
|
#endregion
|
|
int labelNum = 1; //生产条码数量
|
if (zNum > 0)
|
{
|
labelNum = int.Parse(Math.Ceiling(qty / zNum).ToString());//标签数量
|
}
|
else
|
{
|
throw new Exception("当前单据物料是一级包装,未查询到一级包装信息");
|
}
|
|
#region 获取/生成批次号
|
|
string maxLotNoStr = ""; //批次号
|
string maxBoxCode = ""; //箱码号
|
// 生成自编批号
|
string toDayTime = DateTime.Now.ToString("yyyyMMdd");
|
var diJiJian = 0;
|
|
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))
|
{
|
maxLotNoStr = toDayTime.Substring(2, 6) + "0001";
|
}
|
}
|
else
|
{
|
var maxCode = Db.Queryable<BllLabelBoxNo>().Max(a => a.LotNo); // 获取今天最大批次号
|
if (string.IsNullOrWhiteSpace(maxCode))
|
{
|
maxLotNoStr = toDayTime.Substring(2, 6) + "0001";
|
}
|
else
|
{
|
var lotStr = maxCode.Substring(0, 6);
|
var timeStr = toDayTime.Substring(2, 6);
|
if (lotStr == timeStr)
|
{
|
maxLotNoStr = toDayTime.Substring(2, 6) + (int.Parse(maxCode.Substring(6, 4)) + 1).ToString().PadLeft(4, '0');
|
}
|
else
|
{
|
maxLotNoStr = timeStr + "0001";
|
}
|
|
}
|
}
|
|
#endregion
|
|
var modelList = new List<LabelBoxDto>();
|
|
for (int i = 1; i <= labelNum; i++)
|
{
|
// 物料条码信息赋值
|
LabelBoxDto model = new LabelBoxDto();
|
model.AsnDetailNo = imId;
|
model.SkuNo = asnList.SkuNo;
|
model.SkuName = asnList.SkuName;
|
|
model.SupplierName = asn.CustomerName; // 供应商
|
|
model.Standard = asnList.Standard; // 规格
|
model.PackageStandard = packStandard;
|
model.SupplierLot = supplierLot; // 厂家批号
|
model.LotNo = maxLotNoStr; //批次
|
|
model.ProductionTime = DateTime.Parse(productionTime); // 生产日期
|
model.StoreTime = DateTime.Parse(storeTime); // 储存期至
|
model.ExpirationTime = DateTime.Parse(expirationTime); // 有效期至/贮存期
|
if (i == labelNum)
|
{
|
// 最后一个条码
|
var s = zNum * (i - 1);
|
if (zNum > qty - s)
|
{
|
model.Qty = qty - s;// 数量
|
}
|
else
|
{
|
model.Qty = zNum;// 数量
|
}
|
}
|
else
|
{
|
model.Qty = zNum; // 数量
|
}
|
|
|
if (maxBoxCode == "")
|
{
|
var str = model.LotNo + "000001";
|
model.BoxNo = str; // 支号 批号+ 流水 2302010001000001
|
maxBoxCode = model.BoxNo;
|
}
|
else
|
{
|
model.BoxNo = maxBoxCode.Substring(0, 10) + (int.Parse(maxBoxCode.Substring(10, 6)) + 1).ToString().PadLeft(6, '0');
|
maxBoxCode = model.BoxNo;
|
}
|
model.ImgStr = BarcodeHelper.GetCodeBarBase64(model.BoxNo, 80, 50);
|
|
// 添加到list集合
|
modelList.Add(model);
|
|
// 将条码保存到原料条码表
|
var labelModel = new BllLabelBoxNo()
|
{
|
ASNNo = asnList.ASNNo,
|
ASNDetailNo = asnList.Id,
|
BoxNo = model.BoxNo,
|
ParentBoxNo = "",
|
Qty = model.Qty,
|
SkuNo = model.SkuNo,
|
SkuName = model.SkuName,
|
Standard = model.Standard,
|
PackageStandard = model.PackageStandard,
|
|
LotNo = model.LotNo,
|
SupplierName = asn.CustomerName,
|
ProductionTime = model.ProductionTime,
|
SupplierLot = model.SupplierLot,
|
StoreTime = model.StoreTime,
|
ExpirationTime = model.ExpirationTime,
|
IsUse = "0",
|
Level = "1",
|
|
CreateUser = userId,
|
CreateTime = DateTime.Now,
|
};
|
|
Db.Insertable(labelModel).ExecuteCommand();
|
|
}
|
|
#endregion
|
}
|
else //(packLevel == 2)
|
{
|
#region 二级包装
|
|
// 根据用户输入的箱数量计算需要的条码数
|
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;
|
}
|
#endregion
|
|
int labelNum2 = 1; //生产箱条码数量
|
|
labelNum2 = int.Parse(Math.Ceiling(qty2 / bNum).ToString());
|
|
|
|
var ss = bNum / zNum; //每箱支标签数量
|
var labelNumZ2 = Math.Ceiling((decimal)ss);
|
|
#region 获取/生成批次号
|
|
string maxCodestr2 = ""; //批次
|
string maxboxcode2 = ""; //箱码
|
string maxboxcode3 = ""; //支码
|
// 生成自编批号
|
string toDayTime2 = DateTime.Now.ToString("yyyyMMdd");
|
if (isReset == "0")
|
{
|
var maxCode = label.Max(a => a.LotNo);
|
var boxCode1 = label.Where(m => m.Level == "1").Max(a => a.BoxNo);//箱号
|
var boxCode2 = label.Where(m => m.Level == "2").Max(a => a.BoxNo);//支号
|
maxCodestr2 = maxCode;
|
maxboxcode2 = boxCode1;
|
maxboxcode3 = boxCode2;
|
if (string.IsNullOrWhiteSpace(maxCodestr2))
|
{
|
maxCodestr2 = toDayTime2.Substring(2, 6) + "0001";
|
}
|
}
|
else
|
{
|
var maxCode = Db.Queryable<BllLabelBoxNo>().Max(a => a.LotNo); // 获取今天最大批次号
|
if (string.IsNullOrWhiteSpace(maxCode))
|
{
|
maxCodestr2 = toDayTime2.Substring(2, 6) + "0001";
|
}
|
else
|
{
|
var lotStr = maxCode.Substring(0, 6);
|
var timeStr = toDayTime2.Substring(2, 6);
|
if (lotStr == timeStr)
|
{
|
maxCodestr2 = timeStr + (int.Parse(maxCode.Substring(6, 4)) + 1).ToString().PadLeft(4, '0');
|
}
|
else
|
{
|
maxCodestr2 = timeStr + "0001";
|
}
|
|
}
|
}
|
|
#endregion
|
|
var modelList = new List<LabelBoxDto>();
|
|
for (int i = 1; i <= labelNum2; i++)//箱码标签
|
{
|
// 物料条码信息赋值
|
LabelBoxDto model = new LabelBoxDto();
|
model.AsnDetailNo = imId;
|
model.SkuNo = asnList.SkuNo;
|
model.SkuName = asnList.SkuName;
|
|
model.Standard = asnList.Standard; // 规格
|
model.PackageStandard = packStandard;
|
|
model.SupplierLot = supplierLot; // 厂家批号
|
model.LotNo = maxCodestr2; //批次
|
|
model.ProductionTime = DateTime.Parse(productionTime); // 生产日期
|
model.StoreTime = DateTime.Parse(storeTime); // 储存期至
|
model.ExpirationTime = DateTime.Parse(expirationTime); // 有效期至/贮存期
|
if (i == labelNum2)
|
{
|
// 最后一个条码
|
var s = bNum * (i - 1);
|
if (bNum > qty2 - s)
|
{
|
model.Qty = qty2 - s;// 数量
|
}
|
else
|
{
|
model.Qty = bNum;// 数量
|
}
|
}
|
else
|
{
|
model.Qty = bNum; // 数量
|
}
|
|
if (maxboxcode2 == "")
|
{
|
maxboxcode2 = model.LotNo + "000001";
|
model.BoxNo = maxboxcode2; // 箱号 批号+第几箱
|
maxboxcode2 = model.BoxNo;
|
}
|
else
|
{
|
model.BoxNo = maxboxcode2.Substring(0, 10) + (int.Parse(maxboxcode2.Substring(10, 6)) + 1).ToString().PadLeft(6, '0');
|
maxboxcode2 = model.BoxNo;
|
}
|
model.ImgStr = BarcodeHelper.GetCodeBarBase64(model.BoxNo, 80, 50);
|
|
// 添加到list集合
|
modelList.Add(model);
|
|
if (i == labelNum2)
|
{
|
var isGo2 = false;
|
var sl = 0;
|
for (int j = 1; j <= labelNumZ2; j++)
|
{
|
if (isGo2)
|
{
|
break;
|
}
|
var d = zNum;
|
if (i == labelNum2)
|
{
|
var s = bNum * (i - 1);
|
var s2 = zNum * (j - 1);
|
if (zNum >= qty2 - s - s2)
|
{
|
d = (int)(qty2 - s - s2); // 数量
|
isGo2 = true;
|
}
|
}
|
sl++;
|
}
|
labelNumZ2 = sl;
|
}
|
|
for (int j = 1; j <= labelNumZ2; j++)//最小单位标签
|
{
|
if (isGo)
|
{
|
break;
|
}
|
var d = zNum;
|
if (i == labelNum2)
|
{
|
var s = bNum * (i - 1);
|
var s2 = zNum * (j - 1);
|
if (zNum >= qty2 - s - s2)
|
{
|
d = (int)(qty2 - s - s2); // 数量
|
isGo = true;
|
}
|
}
|
//// 物料条码信息赋值
|
//LabelPrint5Model model2 = new LabelPrint5Model();
|
//model2.ImportId = imId;
|
//model2.OuterBillCode = list.OuterBillCode;
|
//model2.ImportBillCode = list.ImportBillCode;
|
//model2.SkuNo = list.GoodsCode;
|
//model2.SkuName = list.GoodsName;
|
//model2.QtyCount = (int)labelNumZ2; // 总件数(int)labelNumZ2
|
|
//model2.SupplierName = supplierName; // 生产厂家
|
//model2.ProductionDate = productionDate; // 生产日期
|
//model2.SapSkuNo = sapNo; // SAP代码
|
//model2.Standard = good.GoodsStandard; // 规格
|
//model2.SupplierLot = supplierLot; // 厂家批号
|
|
//model2.LotNo = maxCodestr2; //批次
|
|
|
//model2.InspectTime = inspectTime; // 复验期至
|
//model2.ExpirationTime = expirationTime; // 有效期至/贮存期
|
//model2.ExpirationType = good.GoodsTemp; // 贮存条件
|
//model2.Qty = d; // 数量
|
|
//model2.QtyOrd = j; // 第几件
|
//if (maxboxcode3 == "")
|
//{
|
// var str = mesGood.PadRight(16, ' ') + model.LotNo.PadRight(12, ' ') + "0001";
|
// model2.BoxCode = str; // 支号 批号+第几箱
|
// maxboxcode3 = model2.BoxCode;
|
//}
|
//else
|
//{
|
// model2.BoxCode = maxboxcode3.Substring(0, 28) + (int.Parse(maxboxcode3.Substring(28, 4)) + 1).ToString().PadLeft(4, '0');
|
// maxboxcode3 = model2.BoxCode;
|
//}
|
|
//model2.imageStr = Utility.Extra.BarcodeHelper.GetQrCodeBase64(model2.BoxCode, 85, 85);
|
//// 添加到list集合
|
|
//if (printModel.Count(m => m.BoxCode.Length > 17) <= 100)//排除待箱码判断支码是否小于100
|
//{
|
// printModel.Add(model2);
|
//}
|
//var guid = Guid.NewGuid().ToString("N");
|
//// 将条码保存到原料条码表
|
//var LabelModel2 = new LabelPrint
|
//{
|
// LabelID = guid,
|
// LabelStream = model.BoxCode,
|
// BoxCode1 = model2.BoxCode,
|
// GoodsCode = model2.SkuNo,
|
// GoodsName = model2.SkuName,
|
// GoodsStandard = model2.Standard,
|
// ImportLotNo = model2.LotNo,
|
// SupplierName = model2.SupplierName,
|
// ImportId = model2.ImportId,
|
// OuterBillCode = model2.OuterBillCode,
|
// ImportBillCode = model2.ImportBillCode,
|
// ProductionDate = model2.ProductionDate,
|
// SapSkuNo = model2.SapSkuNo,
|
// Qty = model2.Qty,
|
// SupplierLot = model2.SupplierLot,
|
// InspectTime = model2.InspectTime,
|
// ExpirationTime = model2.ExpirationTime,
|
// QtyCount = model2.QtyCount,
|
// QtyOrd = model2.QtyOrd,
|
// ExpirationType = model2.ExpirationType,
|
// BoxNum = bNum,//model.Qty,
|
|
// BulkTank = model.Qty == bNum ? 0 : 1,//零头箱
|
// BulkCase = 0,//零头盒
|
|
// CreateUser = createUser,
|
// CreateTime = DateTime.Now,
|
// IsUse = 0
|
//};
|
|
//DataContext.LabelPrint.InsertOnSubmit(LabelModel2);
|
}
|
|
|
}
|
|
#endregion
|
}
|
|
//return printModel;
|
|
|
throw new NotImplementedException();
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
|
}
|
}
|