using Model.ModelDto;
|
using Model.ModelVm;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using WMS.BLL.LogServer;
|
using WMS.Entity.Context;
|
using WMS.IBLL.IPdaServer;
|
using WMS.DAL;
|
using WMS.Entity.BllAsnEntity;
|
using WMS.Entity.DataEntity;
|
using WMS.Entity.SysEntity;
|
using WMS.Entity.LogEntity;
|
using WMS.Entity.BllSoEntity;
|
using Model.ModelVm.PdaVm;
|
using Model.ModelDto.PdaDto;
|
using Dm;
|
using Model.InterFaceModel;
|
using WMS.Entity.BllQualityEntity;
|
using Model.ModelDto.DataDto;
|
using System.Xml.Schema;
|
using ZXing.OneD;
|
using System.Threading.Tasks;
|
using System.Security.Policy;
|
using Newtonsoft.Json;
|
using Utility.Tools;
|
using Model.ModelDto.SysDto;
|
using Model.ModelVm.SysVm;
|
using System.Security.Cryptography.X509Certificates;
|
using AutoMapper.Configuration.Annotations;
|
|
namespace WMS.BLL.BllPdaServer
|
{
|
public class PdaAsnServer : IPdaAsnServer
|
{
|
private static readonly SqlSugarScope Db = DataContext.Db;
|
|
#region JC34
|
|
/// <summary>
|
/// 绑定托盘 贴标物料
|
/// </summary>
|
/// <param name="model"></param>
|
/// <param name="userId"></param>
|
/// <exception cref="Exception"></exception>
|
public void BindPalletPasteCode(PdaPalletBindVm model, int userId)
|
{
|
try
|
{
|
#region 判断
|
//0:成品入库 1:采购入库 3:退货入库 4:车间余料入库 8:生产退料入库
|
|
|
if (string.IsNullOrEmpty(model.AsnNo))
|
{
|
throw new Exception("单据号不可为空!");
|
}
|
if (model.AsnDetailId == null || model.AsnDetailId == 0)
|
{
|
throw new Exception("物料-批次不可为空!");
|
}
|
if (string.IsNullOrEmpty(model.PalletNo))
|
{
|
throw new Exception("托盘号不可为空!");
|
}
|
//根据单据号获取入库单总单
|
var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.AsnNo);
|
if (notice.Status != "0" && notice.Status != "1" && notice.Status != "2")
|
{
|
throw new Exception("该单据已关单!");
|
}
|
if (string.IsNullOrEmpty(model.LotNo))
|
{
|
throw new Exception("物料-批次不可为空!");
|
}
|
else
|
{
|
//从物料名称-批次中取出批次
|
int indexOfDash = model.LotNo.IndexOf("-");
|
if (indexOfDash != -1)
|
{
|
model.LotNo = model.LotNo.Substring(indexOfDash + 1);
|
}
|
else
|
{
|
throw new Exception("物料-批次不可为空!");
|
}
|
}
|
|
//判断箱码信息
|
if (string.IsNullOrEmpty(model.BoxNo))
|
{
|
throw new Exception("箱码信息不可为空!");
|
}
|
//是否连续组托 0:否 1:是
|
if (model.IsContinue == "1")
|
{
|
if (string.IsNullOrWhiteSpace(model.TailBoxNo))
|
{
|
throw new Exception("开启连续组托时,尾箱码信息不可为空!");
|
}
|
}
|
|
//托盘信息是否存在
|
var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
|
if (pallet == null)
|
{
|
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));
|
if (detail == 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("该托盘已有储位信息,不可组托,请核实!");
|
}
|
|
#endregion
|
|
//开启事务
|
Db.BeginTran();
|
//当前时间
|
var comTime = DateTime.Now;
|
|
#region 包装
|
|
var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == detail.SkuNo);
|
var pack = Db.Queryable<SysPackag>().First(m => m.IsDel == "0" && m.PackagNo == detail.PackagNo);
|
|
var pNum = 0;//托盘物品数量
|
var bNum = 0;//箱码物品数量
|
|
//公共方法获取包装数量
|
new Common().GetPackQtyInfo(detail.PackagNo, ref pNum, ref bNum);
|
|
#endregion
|
|
#region 验证是否允许立库同托盘不同物料入库或同托盘同物料不同批次入库
|
var palletBind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNNo == model.AsnNo && m.PalletNo == model.PalletNo && m.ASNDetailNo != model.AsnDetailId);
|
if (palletBind != null)
|
{
|
var box = Db.Queryable<BllBoxInfo>().First(m => m.IsDel == "0" && m.BindNo == palletBind.Id && m.BitBoxMark == "0");
|
if (box != null && (box.SkuNo != detail.SkuNo || !detail.LotNo.Contains(box.LotNo)))
|
{
|
var funSetting = Db.Queryable<SysFunSetting>().First(a => a.IsDel == "0" && a.FunSetNo == "Fun045");
|
if (funSetting == null || funSetting.IsEnable == "OFF")
|
{
|
throw new Exception($"不允许立库同托盘不同物料入库或同托盘不同批次入库!");
|
}
|
}
|
}
|
#endregion
|
|
#region 箱码信息
|
var msgStr = $"箱号为{model.BoxNo}";
|
var boxInfoList = new List<BllBoxInfo>();
|
|
//首箱
|
var boxInfo = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo).ToList();
|
if (boxInfo.Count == 0)
|
{
|
throw new Exception("箱码信息不存在!");
|
}
|
boxInfoList.AddRange(boxInfo);
|
//是否连续组托
|
if (model.IsContinue == "1")
|
{
|
//尾箱
|
var boxInfo2 = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.TailBoxNo).ToList();
|
if (boxInfo2.Count == 0)
|
{
|
throw new Exception("尾箱码信息不存在!");
|
}
|
boxInfoList.AddRange(boxInfo2);
|
var sql = $"select * from BllBoxInfo where IsDel = '0' and boxNo>'{model.BoxNo}' and boxNo<'{model.TailBoxNo}'; ";
|
var list = Db.Ado.SqlQuery<BllBoxInfo>(sql);
|
boxInfoList.AddRange(list);
|
msgStr += $"尾箱号为{model.TailBoxNo}";
|
}
|
//绑定箱总数量
|
//model.SkuQty = boxInfoList.Sum(s => s.Qty);
|
//和选择的批次同批次的箱码信息
|
var sameBoxInfoList = boxInfoList.Where(w => w.LotNo == model.LotNo && w.Status == "0").ToList();
|
//和选择的批次不同批次的箱码信息(拼箱批次)
|
var notBoxInfoList = boxInfoList.Where(w => w.LotNo != model.LotNo).ToList();
|
#endregion
|
|
if (sameBoxInfoList.Count <= 0)
|
{
|
throw new Exception("箱码信息不存在!");
|
}
|
else
|
{
|
#region 托盘绑定信息
|
var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo && m.LotNo == model.LotNo);
|
var bindId = 0;
|
if (bind == null)
|
{
|
bind = new BllPalletBind
|
{
|
ASNNo = model.AsnNo,
|
ASNDetailNo = (int)model.AsnDetailId,
|
PalletNo = model.PalletNo,
|
PalletNo2 = "",
|
PalletNo3 = "",
|
Qty = model.SkuQty,//不包含拼箱中非同批次数量
|
FullQty = pNum,
|
Status = "2",//入库完成
|
Type = "0",
|
LotNo = model.LotNo,
|
LotText = detail.LotText,
|
SupplierLot = detail.SupplierLot,
|
//InspectMark = model.IsSample, //是否取样托盘 后期业务开发时 接口传值需添加对应字段判断
|
//SamplingQty = 0, //取样数量 后期业务开发时 接口传值需添加对应字段判断
|
BitPalletMark = "1",
|
IsBale = "0",
|
IsBelt = "0",
|
CreateUser = userId,
|
Demo = model.Demo,
|
};
|
// 插入托盘绑定表
|
bindId = Db.Insertable(bind).ExecuteReturnIdentity();
|
}
|
else
|
{
|
bindId = bind.Id;
|
bind.Qty += model.SkuQty;
|
}
|
|
#endregion
|
|
#region 库存明细和质检信息
|
//获取该批次最终质检结果
|
BllQualityInspect quality = new BllQualityInspect();
|
//判断是否为退货入库单
|
if (notice.Type == "3")
|
{
|
quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.ASNNo == detail.ASNNo && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First();
|
}
|
else
|
{
|
quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First();
|
}
|
var tags = "0";
|
if (notice.Type == "3" || notice.Type == "4")
|
{
|
tags = "1";
|
}
|
|
// 判断库存明细是否已有此托盘信息
|
var sd1 = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.ASNDetailNo == bind.ASNDetailNo && m.PalletNo == model.PalletNo);
|
var sdId1 = 0;
|
if (sd1 != null)
|
{
|
sdId1 = sd1.Id;
|
// 库存已存在 更新数据
|
sd1.Qty = bind.Qty;
|
sd1.CompleteTime = comTime;
|
sd1.UpdateUser = userId;
|
sd1.UpdateTime = comTime;
|
|
Db.Updateable(sd1).ExecuteCommand();
|
}
|
else
|
{
|
// 库存不存在 插入数据
|
sd1 = new DataStockDetail()
|
{
|
LotNo = bind.LotNo,
|
LotText = bind.LotText,
|
SupplierLot = bind.SupplierLot,
|
SkuNo = sku.SkuNo,
|
SkuName = sku.SkuName,
|
Standard = sku.Standard,
|
Qty = bind.Qty,
|
LockQty = 0,
|
FrozenQty = 0,
|
InspectQty = 0,
|
ASNNo = bind.ASNNo,
|
ASNDetailNo = bind.ASNDetailNo,
|
WareHouseNo = "",//所属仓库
|
RoadwayNo = "",//所属巷道
|
AreaNo = "",//所属区域
|
LocatNo = "",//储位地址
|
PalletNo = bind.PalletNo,
|
PalletNo2 = bind.PalletNo2,
|
PalletNo3 = bind.PalletNo3,
|
PalletTags = tags,
|
CompleteTime = comTime,
|
ProductionTime = bind.ProductionTime,
|
ExpirationTime = bind.ExpirationTime,
|
Status = "0",
|
InspectMark = bind.InspectMark,
|
InspectStatus = sku.IsInspect,
|
BitPalletMark = bind.BitPalletMark,
|
PackagNo = detail.PackagNo, //liudl 由sku的包装编号变为入库单明细的包装编码
|
IsBale = bind.IsBale,
|
IsBelt = bind.IsBelt,
|
|
IsDel = "0",
|
CreateUser = 0,
|
CreateTime = comTime
|
};
|
|
//维护库存明细货主/供应商信息 //0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
|
if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")
|
{
|
sd1.OwnerNo = notice.CustomerNo;//货主编码
|
sd1.OwnerName = notice.CustomerName;//货主名称
|
}
|
else if (notice.Type == "1" || notice.Type == "5")//1:采购入库,2:其它入库
|
{
|
sd1.SupplierNo = notice.CustomerNo;//供应商编码
|
sd1.SupplierName = notice.CustomerName;//供应商名称
|
}
|
if (quality != null)
|
{
|
//修改合格不合格数量
|
if (quality.IsQualified == "1") //合格
|
{
|
//增加合格数量
|
quality.PassQty += bind.Qty;
|
sd1.InspectStatus = "1";
|
}
|
else if (quality.IsQualified == "0") //不合格
|
{
|
//增加不合格数量
|
quality.FailQty += bind.Qty;
|
sd1.InspectStatus = "2";
|
}
|
Db.Updateable(quality).ExecuteCommand(); //修改质检信息
|
}
|
//添加库存明细
|
sdId1 = Db.Insertable(sd1).ExecuteReturnIdentity();
|
}
|
#endregion
|
|
// 更改箱支关系表
|
decimal factQty = 0.00m;//托盘总数量
|
var isSample = "0";//是否取样
|
var sampleQty = 0m;//取样数量
|
|
//标签组托
|
var boxGroup = sameBoxInfoList.GroupBy(m => m.BoxNo).ToList();
|
foreach (var g in boxGroup)
|
{
|
decimal boxFullQty = 0;//箱内总数量
|
foreach (var box in g)
|
{
|
if (box.BindNo != null && box.BindNo != 0)
|
{
|
continue;
|
}
|
//箱内物料批次与单据明细不符合
|
if (box.SkuNo != detail.SkuNo || box.LotNo != model.LotNo)
|
{
|
throw new Exception($"-1:{box.BoxNo}箱内物料及批次与单据不一致,请核实!");
|
}
|
|
box.ASNNo = model.AsnNo;
|
box.ASNDetailNo = model.AsnDetailId;
|
box.BindNo = bindId;
|
box.PalletNo = model.PalletNo;
|
box.Status = "2";
|
//box.InspectMark = model.IsSample; //是否取样托盘 后期业务开发时 接口传值需添加对应字段判断
|
//box.SamplingQty = 0; //取样数量 后期业务开发时 接口传值需添加对应字段判断
|
box.CompleteTime = comTime;
|
box.UpdateTime = comTime;
|
box.UpdateUser = userId;
|
|
//box.Qty = box.Qty;
|
//box.BitBoxMark = box.Qty == box.FullQty ? "0" : "1";
|
|
factQty += box.Qty;
|
boxFullQty += box.Qty;
|
if (box.InspectMark == "1") //判断是否取样
|
{
|
isSample = "1";
|
sampleQty += (decimal)box.SamplingQty;
|
}
|
|
#region 库存箱码明细
|
var box2 = new DataBoxInfo()
|
{
|
StockDetailId = sdId1,
|
BindNo = bind.Id,
|
BoxNo = box.BoxNo,
|
BoxNo2 = box.BoxNo2,
|
BoxNo3 = box.BoxNo3,
|
PalletNo = box.PalletNo,
|
PalletNo2 = box.PalletNo2,
|
PalletNo3 = box.PalletNo3,
|
Qty = box.Qty,
|
FullQty = box.FullQty,
|
Status = "2",//0:未组托 1:已组托 2:已入库 3:已出库 4:已分配 5:已拣货
|
LotNo = box.LotNo,
|
LotText = box.LotText,
|
SkuNo = box.SkuNo,
|
SkuName = box.SkuName,
|
Standard = sku.Standard,
|
ProductionTime = box.ProductionTime,
|
SupplierLot = box.SupplierLot,
|
InspectStatus = sku.IsInspect,
|
InspectMark = box.InspectMark,
|
BitBoxMark = box.BitBoxMark,
|
ExpirationTime = box.ExpirationTime,
|
|
CreateUser = 0,
|
CreateTime = comTime
|
};
|
//添加库存箱码明细
|
Db.Insertable(box2).ExecuteCommand();
|
#endregion
|
}
|
if (boxFullQty > bNum)
|
{
|
throw new Exception($"绑定失败,{g.Key}箱码绑定数量大于该物品包装数量!");
|
}
|
}
|
//更改箱支关系表信息
|
Db.Updateable(boxInfoList).ExecuteCommand();
|
|
// 更新托盘绑定表
|
bind.Qty += factQty;
|
|
if (bind.FullQty < bind.Qty)
|
{
|
throw new Exception("托盘绑定数量已超出该物料包装数量");
|
}
|
|
if (bind.FullQty == bind.Qty)
|
{
|
bind.BitPalletMark = "0";
|
sd1.BitPalletMark = "0";
|
}
|
if (bind.Qty > pNum)
|
{
|
throw new Exception($"绑定失败,{bind.PalletNo}托盘绑定数量大于该物品托盘包装数量!");
|
}
|
|
if (isSample == "1")
|
{
|
bind.InspectMark = "1";
|
bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty;
|
}
|
Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand();
|
|
#region 入库单及明细
|
detail.FactQty += factQty;//已组数量
|
detail.CompleteQty += factQty;//完成数量
|
if (isSample == "1") //后期业务开发时 接口传值改为判断是否取样
|
{
|
detail.IsSampling = "1";
|
}
|
detail.Status = "1";//0:等待执行 1:正在执行 2:执行完成
|
if (detail.CompleteQty >= detail.Qty)
|
{
|
detail.Status = "2";
|
detail.CompleteTime = comTime;
|
}
|
detail.UpdateUser = userId;
|
detail.UpdateTime = comTime;
|
//更新入库单明细
|
Db.Updateable(detail).ExecuteCommand();
|
|
notice.UpdateUser = userId;
|
notice.UpdateTime = comTime;
|
if (notice.Status == "0")
|
{
|
notice.Status = "1";
|
}
|
var asnDetailNum = Db.Queryable<BllArrivalNoticeDetail>().Count(m => m.IsDel == "0" && m.ASNNo == detail.ASNNo && m.Status != "2");
|
if (asnDetailNum == 0)
|
{
|
notice.Status = "2";//执行完成
|
notice.CompleteTime = comTime;//完成时间
|
}
|
//更新入库单
|
Db.Updateable(notice).ExecuteCommand();
|
#endregion
|
|
#region 库存明细
|
sd1.Qty = bind.Qty;
|
//更改库存明细数量
|
Db.Updateable(sd1).Where(m => m.Id == sdId1).ExecuteCommand();
|
#endregion
|
|
#region 库存
|
var dataStock = Db.Queryable<DataStock>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo);
|
if (dataStock != null)
|
{
|
dataStock.Qty += factQty;
|
|
if (bind.InspectMark == "1")
|
{
|
dataStock.IsSampling = bind.InspectMark;
|
}
|
Db.Updateable(dataStock).ExecuteCommand();
|
}
|
else
|
{
|
var stock = new DataStock()
|
{
|
SkuNo = sku.SkuNo,
|
SkuName = sku.SkuName,
|
Standard = sku.Standard,
|
LotNo = bind.LotNo,
|
LotText = bind.LotText,
|
Qty = bind.Qty,
|
LockQty = 0,
|
FrozenQty = 0,
|
IsSampling = bind.InspectMark,
|
IsDel = "0",
|
CreateUser = userId,
|
CreateTime = comTime
|
};
|
//维护库存货主信息
|
if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
|
{
|
stock.OwnerNo = notice.CustomerNo;//货主编码
|
stock.OwnerName = notice.CustomerName;//货主名称
|
}
|
Db.Insertable(stock).ExecuteCommand();
|
}
|
#endregion
|
|
#region 质检请验
|
if ((notice.Type == "1" || notice.Type == "4" || notice.Type == "5") && sku.IsInspect != "1")
|
{
|
var qualityRequest = Db.Queryable<BllQualityInspectionRequest>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo && m.SupplierLot == bind.SupplierLot);
|
if (qualityRequest == null)
|
{
|
string qcNo = new Common().GetMaxNo("QC");
|
qualityRequest = new BllQualityInspectionRequest();
|
qualityRequest.QcNo = qcNo;
|
qualityRequest.Status = "0";
|
qualityRequest.SkuNo = sku.SkuNo;
|
qualityRequest.SkuName = sku.SkuName;
|
qualityRequest.LotNo = bind.LotNo;
|
qualityRequest.SupplierLot = bind.SupplierLot;
|
qualityRequest.Qty = detail.Qty;
|
qualityRequest.SamplingQty = 0;
|
qualityRequest.ASNNo = detail.ASNNo;
|
qualityRequest.CreateUser = userId;
|
qualityRequest.CreateTime = comTime;
|
//添加质检请验单
|
Db.Insertable(qualityRequest).ExecuteCommand();
|
}
|
}
|
#endregion
|
}
|
|
//拼箱
|
if (notBoxInfoList.Count > 0)
|
{
|
var gbox = notBoxInfoList.GroupBy(g => g.BoxNo).ToList();
|
if (gbox.Count > 1)
|
{
|
throw new Exception("一个托盘上只能有1个拼箱!");
|
}
|
gbox = notBoxInfoList.GroupBy(g => g.LotNo).ToList();
|
if (gbox.Count > 1)
|
{
|
throw new Exception("一个箱内最多能有2个不同批次物料!");
|
}
|
var pinBoxNo = notBoxInfoList[0].BoxNo;//拼箱箱码
|
var pinBoxLotNo = notBoxInfoList[0].LotNo;//拼箱批次号
|
//拼箱数量(和选择的批次不同批次的箱码数量)
|
decimal pinBoxQty = notBoxInfoList.Sum(s => s.Qty);
|
|
var dataBoxList = Db.Queryable<DataBoxInfo>().Where(w => w.IsDel == "0" && w.BoxNo == pinBoxNo && w.LotNo == pinBoxLotNo).ToList();
|
if (dataBoxList.Count > 0)//已有库存
|
{
|
//原托盘绑定信息
|
var oldPalletBind = Db.Queryable<BllPalletBind>().First(w => w.Id == notBoxInfoList[0].BindNo);
|
//原入库单明细
|
var oldAsnDetail = Db.Queryable<BllArrivalNoticeDetail>().First(w => w.Id == oldPalletBind.ASNDetailNo);
|
//原入库单
|
var oldAsnNotice = Db.Queryable<BllArrivalNotice>().First(w => w.ASNNo == oldAsnDetail.ASNNo);
|
#region 托盘绑定信息
|
var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == oldAsnDetail.Id && m.PalletNo == model.PalletNo);
|
var bindId = 0;
|
if (bind == null)
|
{
|
bind = new BllPalletBind
|
{
|
ASNNo = oldAsnDetail.ASNNo,
|
ASNDetailNo = oldAsnDetail.Id,
|
PalletNo = model.PalletNo,
|
PalletNo2 = "",
|
PalletNo3 = "",
|
Qty = 0,
|
FullQty = pNum,
|
Status = "2",//入库完成
|
Type = "0",
|
LotNo = pinBoxLotNo,
|
LotText = oldAsnDetail.LotText,
|
SupplierLot = oldAsnDetail.SupplierLot,
|
//InspectMark = model.IsSample, //是否取样托盘 后期业务开发时 接口传值需添加对应字段判断
|
//SamplingQty = 0, //取样数量 后期业务开发时 接口传值需添加对应字段判断
|
BitPalletMark = "1",
|
IsBale = "0",
|
IsBelt = "0",
|
CreateUser = userId,
|
Demo = model.Demo,
|
};
|
// 插入托盘绑定表
|
bindId = Db.Insertable(bind).ExecuteReturnIdentity();
|
}
|
else
|
{
|
bindId = bind.Id;
|
bind.Qty += pinBoxQty;
|
|
Db.Updateable(bind).ExecuteCommand();
|
}
|
#endregion
|
|
// 插入库存明细数据
|
var sd1 = new DataStockDetail()
|
{
|
LotNo = pinBoxLotNo,
|
LotText = notBoxInfoList[0].LotText,
|
SupplierLot = notBoxInfoList[0].SupplierLot,
|
SkuNo = sku.SkuNo,
|
SkuName = sku.SkuName,
|
Standard = sku.Standard,
|
Qty = pinBoxQty,
|
LockQty = 0,
|
FrozenQty = 0,
|
InspectQty = 0,
|
ASNNo = oldPalletBind.ASNNo,
|
ASNDetailNo = oldPalletBind.ASNDetailNo,
|
WareHouseNo = "",//所属仓库
|
RoadwayNo = "",//所属巷道
|
AreaNo = "",//所属区域
|
LocatNo = "",//储位地址
|
PalletNo = bind.PalletNo,
|
PalletNo2 = bind.PalletNo2,
|
PalletNo3 = bind.PalletNo3,
|
PalletTags = "0",
|
CompleteTime = comTime,
|
ProductionTime = oldPalletBind.ProductionTime,
|
ExpirationTime = oldPalletBind.ExpirationTime,
|
Status = "0",
|
InspectMark = oldPalletBind.InspectMark,
|
InspectStatus = sku.IsInspect,
|
BitPalletMark = oldPalletBind.BitPalletMark,
|
PackagNo = oldAsnDetail.PackagNo,
|
IsBale = oldPalletBind.IsBale,
|
IsBelt = oldPalletBind.IsBelt,
|
|
IsDel = "0",
|
CreateUser = 0,
|
CreateTime = comTime
|
};
|
//维护库存明细货主/供应商信息
|
if (oldAsnNotice.Type == "0" || oldAsnNotice.Type == "2" || oldAsnNotice.Type == "4" || oldAsnNotice.Type == "6" || oldAsnNotice.Type == "7")//0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
|
{
|
sd1.OwnerNo = oldAsnNotice.CustomerNo;//货主编码
|
sd1.OwnerName = oldAsnNotice.CustomerName;//货主名称
|
}
|
else if (oldAsnNotice.Type == "1" || oldAsnNotice.Type == "5")//1:采购入库,2:其它入库
|
{
|
sd1.SupplierNo = oldAsnNotice.CustomerNo;//供应商编码
|
sd1.SupplierName = oldAsnNotice.CustomerName;//供应商名称
|
}
|
//添加库存明细
|
var sdId1 = Db.Insertable(sd1).ExecuteReturnIdentity();
|
foreach (var item in dataBoxList)
|
{
|
item.StockDetailId = sdId1;//库存明细id
|
item.BindNo = bind.Id;//托盘绑定id
|
}
|
//更新库存箱支明细表
|
Db.Updateable(dataBoxList).ExecuteCommand();
|
|
//托盘解绑信息
|
var palletUnbind = Db.Queryable<BllPalletUnbind>().First(w => w.IsDel == "0" && w.UpbindPalletNo == oldPalletBind.PalletNo && w.BoxNo == pinBoxNo);
|
if (palletUnbind == null)
|
{
|
throw new Exception("拼箱的托盘解绑信息不存在!");
|
}
|
palletUnbind.BindPalletNo = model.PalletNo;//绑定托盘号
|
palletUnbind.UpdateTime = comTime;
|
palletUnbind.UpdateUser = userId;
|
//更新托盘解绑绑定表信息
|
Db.Updateable(palletUnbind).ExecuteCommand();
|
}
|
else
|
{
|
string sql = $@"SELECT detail.* FROM BllArrivalNoticeDetail as detail
|
JOIN BllArrivalNotice as notice ON detail.ASNNo=notice.ASNNo
|
WHERE notice.IsDel='0'
|
AND ( notice.Status=0 or notice.Status=1 )
|
AND detail.IsDel='0'
|
AND detail.LotNo='{pinBoxLotNo}'
|
AND detail.SkuNo='{sku.SkuNo}'
|
ORDER BY detail.CreateTime ";
|
//找到拼箱内其他批次所属入库单明细
|
var arrDetail = Db.Ado.SqlQuery<BllArrivalNoticeDetail>(sql).FirstOrDefault();
|
if (arrDetail == null)
|
{
|
throw new Exception("拼箱内物料所属入库单明细不存在!");
|
}
|
//找到拼箱内其他批次所属入库单
|
var arrNotice = Db.Queryable<BllArrivalNotice>().First(w => w.IsDel == "0" && w.ASNNo == arrDetail.ASNNo);
|
if (arrNotice == null)
|
{
|
throw new Exception("拼箱内物料所属入库单不存在!");
|
}
|
#region 托盘绑定信息
|
var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == arrDetail.Id && m.PalletNo == model.PalletNo);
|
var bindId = 0;
|
if (bind == null)
|
{
|
bind = new BllPalletBind
|
{
|
ASNNo = arrDetail.ASNNo,
|
ASNDetailNo = arrDetail.Id,
|
PalletNo = model.PalletNo,
|
PalletNo2 = "",
|
PalletNo3 = "",
|
Qty = 0,
|
FullQty = pNum,
|
Status = "2",//入库完成
|
Type = "0",
|
LotNo = pinBoxLotNo,
|
LotText = arrDetail.LotText,
|
SupplierLot = arrDetail.SupplierLot,
|
//InspectMark = model.IsSample, //是否取样托盘 后期业务开发时 接口传值需添加对应字段判断
|
//SamplingQty = 0, //取样数量 后期业务开发时 接口传值需添加对应字段判断
|
BitPalletMark = "1",
|
IsBale = "0",
|
IsBelt = "0",
|
CreateUser = userId,
|
Demo = model.Demo,
|
};
|
// 插入托盘绑定表
|
bindId = Db.Insertable(bind).ExecuteReturnIdentity();
|
}
|
else
|
{
|
bindId = bind.Id;
|
}
|
#endregion
|
|
#region 库存明细和质检信息
|
//获取该批次最终质检结果
|
BllQualityInspect quality = new BllQualityInspect();
|
//判断是否为退货入库单
|
if (arrNotice.Type == "3")
|
{
|
quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.ASNNo == arrDetail.ASNNo && a.SkuNo == arrDetail.SkuNo && a.LotNo == arrDetail.LotNo).OrderByDescending(a => a.CreateTime).First();
|
}
|
else
|
{
|
quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.SkuNo == arrDetail.SkuNo && a.LotNo == arrDetail.LotNo).OrderByDescending(a => a.CreateTime).First();
|
}
|
var tags = "0";
|
if (arrNotice.Type == "3" || arrNotice.Type == "4")
|
{
|
tags = "1";
|
}
|
|
// 判断库存明细是否已有此托盘信息
|
var sd1 = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.ASNDetailNo == arrDetail.Id && m.PalletNo == model.PalletNo);
|
var sdId1 = 0;
|
if (sd1 != null)
|
{
|
sdId1 = sd1.Id;
|
// 库存已存在 更新数据
|
sd1.Qty = bind.Qty;
|
sd1.CompleteTime = comTime;
|
sd1.UpdateUser = userId;
|
sd1.UpdateTime = comTime;
|
|
Db.Updateable(sd1).ExecuteCommand();
|
}
|
else
|
{
|
// 库存不存在 插入数据
|
sd1 = new DataStockDetail()
|
{
|
LotNo = pinBoxLotNo,
|
LotText = notBoxInfoList[0].LotText,
|
SupplierLot = bind.SupplierLot,
|
SkuNo = sku.SkuNo,
|
SkuName = sku.SkuName,
|
Standard = sku.Standard,
|
Qty = bind.Qty,
|
LockQty = 0,
|
FrozenQty = 0,
|
InspectQty = 0,
|
ASNNo = arrDetail.ASNNo,
|
ASNDetailNo = arrDetail.Id,
|
WareHouseNo = "",//所属仓库
|
RoadwayNo = "",//所属巷道
|
AreaNo = "",//所属区域
|
LocatNo = "",//储位地址
|
PalletNo = bind.PalletNo,
|
PalletNo2 = bind.PalletNo2,
|
PalletNo3 = bind.PalletNo3,
|
PalletTags = tags,
|
CompleteTime = comTime,
|
ProductionTime = bind.ProductionTime,
|
ExpirationTime = bind.ExpirationTime,
|
Status = "0",
|
InspectMark = bind.InspectMark,
|
InspectStatus = sku.IsInspect,
|
BitPalletMark = bind.BitPalletMark,
|
PackagNo = arrDetail.PackagNo, //liudl 由sku的包装编号变为入库单明细的包装编码
|
IsBale = bind.IsBale,
|
IsBelt = bind.IsBelt,
|
|
IsDel = "0",
|
CreateUser = 0,
|
CreateTime = comTime
|
};
|
|
//维护库存明细货主/供应商信息
|
if (arrNotice.Type == "0" || arrNotice.Type == "2" || arrNotice.Type == "4" || arrNotice.Type == "6" || arrNotice.Type == "7")//0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
|
{
|
sd1.OwnerNo = arrNotice.CustomerNo;//货主编码
|
sd1.OwnerName = arrNotice.CustomerName;//货主名称
|
}
|
else if (arrNotice.Type == "1" || arrNotice.Type == "5")//1:采购入库,2:其它入库
|
{
|
sd1.SupplierNo = arrNotice.CustomerNo;//供应商编码
|
sd1.SupplierName = arrNotice.CustomerName;//供应商名称
|
}
|
if (quality != null)
|
{
|
//修改合格不合格数量
|
if (quality.IsQualified == "1") //合格
|
{
|
//增加合格数量
|
quality.PassQty += bind.Qty;
|
sd1.InspectStatus = "1";
|
}
|
else if (quality.IsQualified == "0") //不合格
|
{
|
//增加不合格数量
|
quality.FailQty += bind.Qty;
|
sd1.InspectStatus = "2";
|
}
|
Db.Updateable(quality).ExecuteCommand(); //修改质检信息
|
}
|
//添加库存明细
|
sdId1 = Db.Insertable(sd1).ExecuteReturnIdentity();
|
}
|
#endregion
|
|
// 更改箱支关系表
|
decimal factQty = 0.00m;//托盘总数量
|
var isSample = "0";//是否取样
|
var sampleQty = 0m;//取样数量
|
|
//标签组托
|
var boxGroup = notBoxInfoList.GroupBy(m => m.BoxNo).ToList();
|
foreach (var g in boxGroup)
|
{
|
decimal boxFullQty = 0;//箱内总数量
|
foreach (var box in g)
|
{
|
if (box.BindNo != null && box.BindNo != 0)
|
{
|
continue;
|
}
|
//箱内物料批次与单据明细不符合
|
if (box.SkuNo != arrDetail.SkuNo || box.LotNo != arrDetail.LotNo)
|
{
|
throw new Exception($"-1:{box.BoxNo}箱内物料及批次与单据不一致,请核实!");
|
}
|
|
box.ASNNo = arrDetail.ASNNo;
|
box.ASNDetailNo = arrDetail.Id;
|
box.BindNo = bindId;
|
box.PalletNo = model.PalletNo;
|
box.Status = "2";
|
//box.InspectMark = model.IsSample; //是否取样托盘 后期业务开发时 接口传值需添加对应字段判断
|
//box.SamplingQty = 0; //取样数量 后期业务开发时 接口传值需添加对应字段判断
|
box.CompleteTime = comTime;
|
box.UpdateTime = comTime;
|
box.UpdateUser = userId;
|
|
//box.Qty = box.Qty;
|
//box.BitBoxMark = box.Qty == box.FullQty ? "0" : "1";
|
|
factQty += box.Qty;
|
boxFullQty += box.Qty;
|
if (box.InspectMark == "1") //判断是否取样
|
{
|
isSample = "1";
|
sampleQty += (decimal)box.SamplingQty;
|
}
|
|
#region 库存箱码明细
|
var box2 = new DataBoxInfo()
|
{
|
StockDetailId = sdId1,
|
BindNo = bind.Id,
|
BoxNo = box.BoxNo,
|
BoxNo2 = box.BoxNo2,
|
BoxNo3 = box.BoxNo3,
|
PalletNo = box.PalletNo,
|
PalletNo2 = box.PalletNo2,
|
PalletNo3 = box.PalletNo3,
|
Qty = box.Qty,
|
FullQty = box.FullQty,
|
Status = "2",//0:未组托 1:已组托 2:已入库 3:已出库 4:已分配 5:已拣货
|
LotNo = box.LotNo,
|
LotText = box.LotText,
|
SkuNo = box.SkuNo,
|
SkuName = box.SkuName,
|
Standard = sku.Standard,
|
ProductionTime = box.ProductionTime,
|
SupplierLot = box.SupplierLot,
|
InspectStatus = sku.IsInspect,
|
InspectMark = box.InspectMark,
|
BitBoxMark = box.BitBoxMark,
|
ExpirationTime = box.ExpirationTime,
|
|
CreateUser = 0,
|
CreateTime = comTime
|
};
|
//添加库存箱码明细
|
Db.Insertable(box2).ExecuteCommand();
|
#endregion
|
}
|
if (boxFullQty > bNum)
|
{
|
throw new Exception($"绑定失败,{g.Key}箱码绑定数量大于该物品包装数量!");
|
}
|
}
|
//更改箱支关系表信息
|
Db.Updateable(boxInfoList).ExecuteCommand();
|
|
// 更新托盘绑定表
|
bind.Qty += factQty;
|
|
if (bind.FullQty < bind.Qty)
|
{
|
throw new Exception("托盘绑定数量已超出该物料包装数量");
|
}
|
|
if (bind.FullQty == bind.Qty)
|
{
|
bind.BitPalletMark = "0";
|
sd1.BitPalletMark = "0";
|
}
|
if (bind.Qty > pNum)
|
{
|
throw new Exception($"绑定失败,{bind.PalletNo}托盘绑定数量大于该物品托盘包装数量!");
|
}
|
|
if (isSample == "1")
|
{
|
bind.InspectMark = "1";
|
bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty;
|
}
|
Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand();
|
|
#region 入库单及明细
|
arrDetail.FactQty += factQty;//已组数量
|
arrDetail.CompleteQty += factQty;//完成数量
|
if (isSample == "1") //后期业务开发时 接口传值改为判断是否取样
|
{
|
arrDetail.IsSampling = "1";
|
}
|
arrDetail.Status = "1";//0:等待执行 1:正在执行 2:执行完成
|
if (arrDetail.CompleteQty >= arrDetail.Qty)
|
{
|
arrDetail.Status = "2";
|
arrDetail.CompleteTime = comTime;
|
}
|
arrDetail.UpdateUser = userId;
|
arrDetail.UpdateTime = comTime;
|
//更新入库单明细
|
Db.Updateable(arrDetail).ExecuteCommand();
|
|
arrNotice.UpdateUser = userId;
|
arrNotice.UpdateTime = comTime;
|
if (arrNotice.Status == "0")
|
{
|
arrNotice.Status = "1";
|
}
|
var asnDetailNum = Db.Queryable<BllArrivalNoticeDetail>().Count(m => m.IsDel == "0" && m.ASNNo == arrDetail.ASNNo && m.Status != "2");
|
if (asnDetailNum == 0)
|
{
|
arrNotice.Status = "2";//执行完成
|
arrNotice.CompleteTime = comTime;//完成时间
|
}
|
//更新入库单
|
Db.Updateable(arrNotice).ExecuteCommand();
|
#endregion
|
|
#region 库存明细
|
sd1.Qty = bind.Qty;
|
//更改库存明细数量
|
Db.Updateable(sd1).Where(m => m.Id == sdId1).ExecuteCommand();
|
#endregion
|
|
#region 库存
|
var dataStock = Db.Queryable<DataStock>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo);
|
if (dataStock != null)
|
{
|
dataStock.Qty += factQty;
|
|
if (bind.InspectMark == "1")
|
{
|
dataStock.IsSampling = bind.InspectMark;
|
}
|
Db.Updateable(dataStock).ExecuteCommand();
|
}
|
else
|
{
|
var stock = new DataStock()
|
{
|
SkuNo = sku.SkuNo,
|
SkuName = sku.SkuName,
|
Standard = sku.Standard,
|
LotNo = bind.LotNo,
|
LotText = bind.LotText,
|
Qty = bind.Qty,
|
LockQty = 0,
|
FrozenQty = 0,
|
IsSampling = bind.InspectMark,
|
IsDel = "0",
|
CreateUser = userId,
|
CreateTime = comTime
|
};
|
//维护库存货主信息
|
if (arrNotice.Type == "0" || arrNotice.Type == "2" || arrNotice.Type == "4" || arrNotice.Type == "6" || arrNotice.Type == "7")//0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
|
{
|
stock.OwnerNo = notice.CustomerNo;//货主编码
|
stock.OwnerName = notice.CustomerName;//货主名称
|
}
|
Db.Insertable(stock).ExecuteCommand();
|
}
|
#endregion
|
|
#region 质检请验
|
if ((arrNotice.Type == "1" || arrNotice.Type == "4" || arrNotice.Type == "5") && sku.IsInspect != "1")
|
{
|
var qualityRequest = Db.Queryable<BllQualityInspectionRequest>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo && m.SupplierLot == bind.SupplierLot);
|
if (qualityRequest == null)
|
{
|
string qcNo = new Common().GetMaxNo("QC");
|
qualityRequest = new BllQualityInspectionRequest();
|
qualityRequest.QcNo = qcNo;
|
qualityRequest.Status = "0";
|
qualityRequest.SkuNo = sku.SkuNo;
|
qualityRequest.SkuName = sku.SkuName;
|
qualityRequest.LotNo = bind.LotNo;
|
qualityRequest.SupplierLot = bind.SupplierLot;
|
qualityRequest.Qty = arrDetail.Qty;
|
qualityRequest.SamplingQty = 0;
|
qualityRequest.ASNNo = arrDetail.ASNNo;
|
qualityRequest.CreateUser = userId;
|
qualityRequest.CreateTime = comTime;
|
//添加质检请验单
|
Db.Insertable(qualityRequest).ExecuteCommand();
|
}
|
}
|
#endregion
|
}
|
}
|
// 更改托盘使用状态
|
var sqlStr = $"update SysPallets set Status = '1' where PalletNo = '{model.PalletNo}';";
|
//添加托盘记录表数据
|
sqlStr += $"insert into LogPalletTrack values('{model.PalletNo}','{model.AsnNo}','组盘','0',getDate(),{userId},NULL,NULL);";
|
Db.Ado.ExecuteCommand(sqlStr);
|
new OperationASNServer().AddLogOperationAsn("PDA模块", "托盘绑定", model.AsnNo, "添加", $"添加了托盘码为:{model.PalletNo}、{msgStr}的组盘信息", userId);
|
|
//提交事务
|
Db.CommitTran();
|
}
|
catch (Exception e)
|
{
|
//回滚事务
|
Db.RollbackTran();
|
throw new Exception(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// 绑定托盘 不贴标物料
|
/// </summary>
|
/// <param name="model"></param>
|
/// <param name="userId"></param>
|
/// <exception cref="Exception"></exception>
|
public void BindPalletNoPasteCode(PdaPalletBindVm model, int userId)
|
{
|
try
|
{
|
Db.BeginTran();
|
#region 判断
|
|
//0:成品入库 1:采购入库 3:退货入库 4:车间余料入库 8:生产退料入库
|
|
|
if (string.IsNullOrEmpty(model.AsnNo))
|
{
|
throw new Exception("单据号不可为空!");
|
}
|
if (model.AsnDetailId == null || model.AsnDetailId == 0)
|
{
|
throw new Exception("物料不可为空!");
|
}
|
if (string.IsNullOrEmpty(model.PalletNo))
|
{
|
throw new Exception("托盘号不可为空!");
|
}
|
if (model.SkuQty < 0)
|
{
|
throw new Exception("物料数量不能小于0!");
|
}
|
//根据单据号获取入库单总单
|
var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.AsnNo);
|
if (notice.Status != "0" && notice.Status != "1" && notice.Status != "2")
|
{
|
throw new Exception("该单据已关单!");
|
}
|
|
if (string.IsNullOrEmpty(model.LotNo))
|
{
|
throw new Exception("物料批次不为空!");
|
}
|
else
|
{
|
//从物料名称-批次中取出批次
|
int indexOfDash = model.LotNo.IndexOf("-");
|
if (indexOfDash != -1)
|
{
|
model.LotNo = model.LotNo.Substring(indexOfDash + 1);
|
}
|
else
|
{
|
throw new Exception("物料批次不可为空!");
|
}
|
}
|
|
//托盘是否存在
|
var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
|
if (pallet == null)
|
{
|
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));
|
if (detail == 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("该托盘已有储位信息,请核实!");
|
}
|
//if (stockDetail != null && (stockDetail.SkuNo != detail.SkuNo || stockDetail.LotNo != model.LotNo))
|
//{
|
// throw new Exception("该托盘在库存已有其它物料批次信息,请核实!");
|
//}
|
|
#endregion
|
|
#region 包装
|
|
var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == detail.SkuNo);
|
//var pack = Db.Queryable<SysPackag>().First(m => m.IsDel == "0" && m.PackagNo == detail.PackagNo); // liudl 由Sku包装编号变更为入库单明细包装编号
|
|
var pNum = 0;//托盘物品数量
|
var bNum = 0;//箱码物品数量
|
//公共方法获取包装数量
|
new Common().GetPackQtyInfo(detail.PackagNo, ref pNum, ref bNum);
|
|
|
#endregion
|
|
#region 验证是否允许立库同托盘不同物料入库或同托盘同物料不同批次入库
|
//var palletBind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNNo == model.AsnNo && m.PalletNo == model.PalletNo && m.ASNDetailNo != model.AsnDetailId);
|
//if (palletBind != null)
|
//{
|
// var box = Db.Queryable<BllBoxInfo>().First(m => m.IsDel == "0" && m.BindNo == palletBind.Id && m.BitBoxMark == "0");
|
// if (box != null && (box.SkuNo != detail.SkuNo || !detail.LotNo.Contains(box.LotNo)))
|
// {
|
// var funSetting = Db.Queryable<SysFunSetting>().First(a => a.IsDel == "0" && a.FunSetNo == "Fun045");
|
// if (funSetting == null || funSetting.IsEnable == "OFF")
|
// {
|
// throw new Exception($"不允许立库同托盘不同物料入库或同托盘不同批次入库!");
|
// }
|
// }
|
//}
|
#endregion
|
|
var comTime = DateTime.Now;
|
|
#region 组托信息
|
|
var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo);
|
var bindId = 0;
|
if (bind == null)
|
{
|
DateTime? pTime = null;//生产日期
|
DateTime? eTime = null;//失效日期
|
if (!string.IsNullOrWhiteSpace(detail.Lot1))
|
{
|
pTime = DateTime.Parse(detail.Lot1);
|
}
|
if (!string.IsNullOrWhiteSpace(detail.Lot2))
|
{
|
eTime = DateTime.Parse(detail.Lot2);
|
}
|
|
|
bind = new BllPalletBind
|
{
|
ASNNo = model.AsnNo,
|
ASNDetailNo = (int)model.AsnDetailId,
|
PalletNo = model.PalletNo,
|
|
Qty = model.SkuQty,
|
FullQty = pNum,
|
Status = "2",//入库完成
|
Type = "0",
|
LotNo = model.LotNo,
|
LotText = detail.LotText,
|
SupplierLot = detail.SupplierLot,
|
//InspectMark = model.IsSample, //是否取样托盘 后期业务开发时 接口传值需添加对应字段判断
|
//SamplingQty = 0, //取样数量 后期业务开发时 接口传值需添加对应字段判断
|
ProductionTime = pTime,
|
ExpirationTime = eTime,
|
BitPalletMark = "1",
|
IsBale = "0",
|
IsBelt = "0",
|
CreateUser = userId,
|
Demo = model.Demo,
|
|
};
|
// 插入托盘绑定表
|
bindId = Db.Insertable(bind).ExecuteReturnIdentity();
|
}
|
else
|
{
|
bindId = bind.Id;
|
bind.Qty += model.SkuQty;
|
}
|
if (bind.Qty < 0)
|
{
|
throw new Exception("组托数量不能小于0");
|
}
|
|
#endregion
|
|
#region 库存明细
|
//获取该批次最终质检结果
|
BllQualityInspect quality = new BllQualityInspect();
|
//判断是否为退货入库单
|
if (notice.Type == "3")
|
{
|
quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.ASNNo == detail.ASNNo && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First();
|
}
|
else
|
{
|
quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First();
|
}
|
var tags = "0";
|
if (notice.Type == "3" || notice.Type == "4")
|
{
|
tags = "1";
|
}
|
//验证库存托盘是否有贴标物料
|
var skuStr = Db.Queryable<SysMaterials>().Where(m => m.IsDel == "0" && m.IsPasteCode == "1").Select(m => m.SkuNo).ToList();
|
var sdHave = Db.Queryable<DataStockDetail>().Count(m => m.IsDel == "0" && m.PalletNo == model.PalletNo && skuStr.Contains(m.SkuNo));
|
if (sdHave>0)
|
{
|
throw new Exception("当前托盘含有贴标物料信息,不能组托");
|
}
|
// 判断库存明细是否已有此托盘信息
|
var sd1 = Db.Queryable<DataStockDetail>()
|
.First(m => m.IsDel == "0" && m.ASNDetailNo == bind.ASNDetailNo && m.PalletNo == model.PalletNo && m.SkuNo == detail.SkuNo && m.LotNo == bind.LotNo);
|
var sdId1 = 0;
|
if (sd1 != null)
|
{
|
sdId1 = sd1.Id;
|
// 库存已存在 更新数据
|
sd1.Qty = bind.Qty;
|
sd1.CompleteTime = comTime;
|
sd1.UpdateUser = userId;
|
sd1.UpdateTime = comTime;
|
|
Db.Updateable(sd1).ExecuteCommand(); //修改质检信息
|
}
|
else
|
{
|
string inspectStatusStr = "0";
|
if (sku.IsInspect == "1")
|
{
|
inspectStatusStr = "1";
|
}
|
|
// 库存不存在 插入数据
|
sd1 = new DataStockDetail()
|
{
|
LotNo = bind.LotNo,
|
LotText = bind.LotText,
|
SupplierLot = bind.SupplierLot,
|
SkuNo = sku.SkuNo,
|
SkuName = sku.SkuName,
|
Standard = sku.Standard,
|
Qty = bind.Qty,
|
LockQty = 0,
|
FrozenQty = 0,
|
InspectQty = 0,
|
ASNNo = bind.ASNNo,
|
ASNDetailNo = bind.ASNDetailNo,
|
WareHouseNo = "",//所属仓库
|
RoadwayNo = "",//所属巷道
|
AreaNo = "",//所属区域
|
LocatNo = "",//储位地址
|
PalletNo = bind.PalletNo,
|
PalletNo2 = bind.PalletNo2,
|
PalletNo3 = bind.PalletNo3,
|
PalletTags = tags,
|
CompleteTime = comTime,
|
ProductionTime = bind.ProductionTime,
|
ExpirationTime = bind.ExpirationTime,
|
Status = "0",
|
InspectMark = bind.InspectMark,
|
InspectStatus = inspectStatusStr,
|
BitPalletMark = bind.BitPalletMark,
|
PackagNo = detail.PackagNo, //liudl 由sku的包装编号变为入库单明细的包装编码
|
IsBale = bind.IsBale,
|
IsBelt = bind.IsBelt,
|
|
IsDel = "0",
|
CreateUser = 0,
|
CreateTime = comTime
|
};
|
|
//维护库存明细货主/供应商信息 //0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
|
if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")
|
{
|
sd1.OwnerNo = notice.CustomerNo;//货主编码
|
sd1.OwnerName = notice.CustomerName;//货主名称
|
}
|
else if (notice.Type == "1" || notice.Type == "5")//1:采购入库,2:其它入库
|
{
|
sd1.SupplierNo = notice.CustomerNo;//供应商编码
|
sd1.SupplierName = notice.CustomerName;//供应商名称
|
}
|
if (quality != null)
|
{
|
//修改合格不合格数量
|
if (quality.IsQualified == "1") //合格
|
{
|
//增加合格数量
|
quality.PassQty += bind.Qty;
|
sd1.InspectStatus = "1";
|
}
|
else if (quality.IsQualified == "0") //不合格
|
{
|
//增加不合格数量
|
quality.FailQty += bind.Qty;
|
sd1.InspectStatus = "2";
|
}
|
Db.Updateable(quality).ExecuteCommand(); //修改质检信息
|
}
|
//添加库存明细
|
sdId1 = Db.Insertable(sd1).ExecuteReturnIdentity();
|
}
|
#endregion
|
|
#region 更改组托信息
|
|
var isSample = "0";//是否取样
|
var sampleQty = 0m;//取样数量
|
|
|
//if (bind.FullQty < bind.Qty && isTextTable == 0)
|
if (bind.FullQty < bind.Qty)
|
{
|
throw new Exception("托盘绑定数量已超出该物料包装数量");
|
}
|
|
if (bind.FullQty == bind.Qty)
|
{
|
bind.BitPalletMark = "0";
|
sd1.BitPalletMark = "0";
|
}
|
//if (bind.Qty > pNum && isTextTable == 0)
|
if (bind.Qty > pNum)
|
{
|
throw new Exception($"绑定失败,{bind.PalletNo}托盘绑定数量大于该物品托盘包装数量!");
|
}
|
|
if (isSample == "1")
|
{
|
bind.InspectMark = "1";
|
bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty;
|
}
|
Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand();
|
|
#endregion
|
|
#region 入库单及明细
|
decimal addQty = model.SkuQty;
|
|
detail.FactQty += addQty;//已组数量
|
detail.CompleteQty += addQty;//完成数量
|
if (isSample == "1") //后期业务开发时 接口传值改为判断是否取样
|
{
|
detail.IsSampling = "1";
|
}
|
detail.Status = "1";//0:等待执行 1:正在执行 2:执行完成
|
if (detail.CompleteQty >= detail.Qty)
|
{
|
detail.Status = "2";
|
detail.CompleteTime = comTime;
|
}
|
detail.UpdateUser = userId;
|
detail.UpdateTime = comTime;
|
//更新入库单明细
|
Db.Updateable(detail).ExecuteCommand();
|
|
notice.UpdateUser = userId;
|
notice.UpdateTime = comTime;
|
if (notice.Status == "0")
|
{
|
notice.Status = "1";
|
}
|
var asnDetailNum = Db.Queryable<BllArrivalNoticeDetail>()
|
.Count(m => m.IsDel == "0" && m.ASNNo == detail.ASNNo && m.Status != "2");
|
if (asnDetailNum == 0)
|
{
|
notice.Status = "2";
|
notice.CompleteTime = comTime;//完成时间
|
}
|
//更新入库单
|
Db.Updateable(notice).ExecuteCommand();
|
#endregion
|
|
#region 更改库存明细数量
|
|
sd1.Qty = bind.Qty;
|
//更改库存明细数量
|
Db.Updateable(sd1).Where(m => m.Id == sdId1).ExecuteCommand();
|
|
#endregion
|
|
#region 库存
|
var dataStock = Db.Queryable<DataStock>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo);
|
if (dataStock != null)
|
{
|
dataStock.Qty += model.SkuQty;
|
|
|
if (bind.InspectMark == "1")
|
{
|
dataStock.IsSampling = bind.InspectMark;
|
}
|
Db.Updateable(dataStock).ExecuteCommand();
|
}
|
else
|
{
|
var stock = new DataStock()
|
{
|
SkuNo = sku.SkuNo,
|
SkuName = sku.SkuName,
|
Standard = sku.Standard,
|
LotNo = bind.LotNo,
|
LotText = bind.LotText,
|
Qty = bind.Qty,
|
LockQty = 0,
|
FrozenQty = 0,
|
IsSampling = bind.InspectMark,
|
IsDel = "0",
|
CreateUser = userId,
|
CreateTime = comTime
|
};
|
//维护库存货主信息
|
if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
|
{
|
stock.OwnerNo = notice.CustomerNo;//货主编码
|
stock.OwnerName = notice.CustomerName;//货主名称
|
}
|
Db.Insertable(stock).ExecuteCommand();
|
}
|
#endregion
|
|
#region 质检请验
|
if ((notice.Type == "1" || notice.Type == "4" || notice.Type == "5") && sku.IsInspect != "1")
|
{
|
var qualityRequest = Db.Queryable<BllQualityInspectionRequest>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo && m.SupplierLot == bind.SupplierLot);
|
if (qualityRequest == null)
|
{
|
string qcNo = new Common().GetMaxNo("QC");
|
qualityRequest = new BllQualityInspectionRequest();
|
qualityRequest.QcNo = qcNo;
|
qualityRequest.Status = "0";
|
qualityRequest.SkuNo = sku.SkuNo;
|
qualityRequest.SkuName = sku.SkuName;
|
qualityRequest.LotNo = bind.LotNo;
|
qualityRequest.SupplierLot = bind.SupplierLot;
|
qualityRequest.Qty = detail.Qty;
|
qualityRequest.SamplingQty = 0;
|
qualityRequest.ASNNo = detail.ASNNo;
|
qualityRequest.CreateUser = userId;
|
qualityRequest.CreateTime = comTime;
|
//添加质检请验单
|
Db.Insertable(qualityRequest).ExecuteCommand();
|
}
|
}
|
#endregion
|
|
// 更改托盘使用状态
|
var sqlStr = $"update SysPallets set Status = '1' where PalletNo = '{model.PalletNo}';";
|
//添加托盘记录表数据
|
sqlStr += $"insert into LogPalletTrack values('{model.PalletNo}','{model.AsnNo}','组盘','0',getDate(),{userId},NULL,NULL);";
|
Db.Ado.ExecuteCommand(sqlStr);
|
new OperationASNServer().AddLogOperationAsn("PDA模块", "托盘绑定", model.AsnNo, "添加", $"添加了托盘码为:{model.PalletNo}的组盘信息", userId);
|
|
Db.CommitTran();
|
}
|
catch (Exception e)
|
{
|
Db.RollbackTran();
|
throw new Exception(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// 获取需要贴标签的入库单 单据号集合
|
/// </summary>
|
/// <returns></returns>
|
public List<string> GetPasteAsnNoStrList()
|
{
|
try
|
{
|
|
var modelList = Db.Queryable<BllArrivalNoticeDetail>()
|
.LeftJoin<BllArrivalNotice>((tb1, tb2) => tb1.ASNNo == tb2.ASNNo )
|
.LeftJoin<SysMaterials>((tb1, tb2, tb3) => tb1.SkuNo == tb3.SkuNo )
|
.Where((tb1, tb2, tb3) => tb1.IsDel == "0" && tb2.IsDel == "0" && (tb2.Status == "0" || tb2.Status == "1") && tb3.IsDel == "0" && tb3.IsPasteCode == "1")
|
.Select((tb1, tb2, tb3) => tb1.ASNNo).Distinct().ToList();
|
|
return modelList;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
/// <summary>
|
/// 获取不需要贴标签的入库单 单据号集合
|
/// </summary>
|
/// <returns></returns>
|
public List<string> GetNoPasteAsnNoStrList()
|
{
|
try
|
{
|
|
var modelList = Db.Queryable<BllArrivalNoticeDetail>()
|
.LeftJoin<BllArrivalNotice>((tb1, tb2) => tb1.ASNNo == tb2.ASNNo )
|
.LeftJoin<SysMaterials>((tb1, tb2, tb3) => tb1.SkuNo == tb3.SkuNo )
|
.Where((tb1, tb2, tb3) => tb1.IsDel == "0" && tb2.IsDel == "0" && (tb2.Status == "0" || tb2.Status == "1") && tb3.IsDel == "0" && tb3.IsPasteCode == "0")
|
.Select((tb1, tb2, tb3) => tb1.ASNNo).Distinct().ToList();
|
|
return modelList;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// 根据单据号获取单据明细列表
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public List<ArrivalNoticeDetailDto> GetBindArrivalNoticeDetails(ArrivalNoticeVm model)
|
{
|
string sqlString = string.Empty;
|
try
|
{
|
sqlString = $"select * from BllArrivalNoticeDetail where ASNNo = '{model.ASNNo}' and isdel='0' order by CreateTime;";
|
var modelList = Db.Ado.SqlQuery<ArrivalNoticeDetailDto>(sqlString);
|
List<ArrivalNoticeDetailDto> noticeList = new List<ArrivalNoticeDetailDto>();
|
foreach (var item in modelList)
|
{
|
if (string.IsNullOrEmpty(item.LotNo))
|
{
|
noticeList.Add(item);
|
}
|
else
|
{
|
string[] LotNoList = item.LotNo.Split(';');
|
foreach (var item2 in LotNoList)
|
{
|
ArrivalNoticeDetailDto entry = new ArrivalNoticeDetailDto()
|
{
|
Id = item.Id,
|
ASNNo = item.ASNNo,
|
CompleteQty = item.CompleteQty,
|
CompleteTime = item.CompleteTime,
|
CreateTime = item.CreateTime,
|
Qty = item.Qty,
|
FactQty = item.FactQty,
|
LotNo = item2,
|
Money = item.Money,
|
PackagNo = item.PackagNo,
|
PackagName = item.PackagName,
|
Status = item.Status,
|
SkuNo = item.SkuNo,
|
SkuName = item.SkuName,
|
};
|
|
|
noticeList.Add(entry);
|
}
|
}
|
}
|
List<ArrivalNoticeDetailDto> list = new List<ArrivalNoticeDetailDto>();
|
foreach (var item in noticeList)
|
{
|
string str = BySkuNoGetPackInfo(item.SkuNo);
|
if (str == "贴标")
|
{
|
list.Add(item);
|
}
|
}
|
|
return list;
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 根据单据号获取单据明细列表
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public List<ArrivalNoticeDetailDto> GetArrivalNoticeDetails(ArrivalNoticeVm model)
|
{
|
string sqlString = string.Empty;
|
try
|
{
|
sqlString = $"select * from BllArrivalNoticeDetail where ASNNo = '{model.ASNNo}' and isdel='0' order by CreateTime;";
|
var modelList = Db.Ado.SqlQuery<ArrivalNoticeDetailDto>(sqlString);
|
|
List<ArrivalNoticeDetailDto> list = new List<ArrivalNoticeDetailDto>();
|
foreach (var item in modelList)
|
{
|
string str = BySkuNoGetPackInfo(item.SkuNo);
|
if (str == "不贴标")
|
{
|
list.Add(item);
|
}
|
}
|
|
return list;
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 根据单据明细ID获取明细详情
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public ArrivalNoticeDetailDto GetArrivalNoticeDetail(ArrivalNoticeDetailVm model)
|
{
|
string sqlString = string.Empty;
|
try
|
{
|
if (model.Id == null || model.Id == 0)
|
{
|
throw new Exception("明细ID不可为空!");
|
}
|
|
sqlString = $"select * from BllArrivalNoticeDetail where Id = '{model.Id}' and isdel='0' order by CreateTime;";
|
var modelList = Db.Ado.SqlQuery<ArrivalNoticeDetailDto>(sqlString);
|
|
if (modelList.Count > 0)
|
{
|
if (!string.IsNullOrWhiteSpace(modelList[0].PackagNo))
|
{
|
// 查询整托数量 此处UDF1用来存储整托数量。
|
var packagModel = Db.Queryable<SysPackag>().Where(m => m.PackagNo == modelList[0].PackagNo && m.IsDel == "0").First();
|
switch (packagModel.Level.ToString())
|
{
|
case "1": modelList[0].UDF1 = packagModel.L1Num.ToString(); break;
|
case "2": modelList[0].UDF1 = packagModel.L2Num.ToString(); break;
|
case "3": modelList[0].UDF1 = packagModel.L3Num.ToString(); break;
|
case "4": modelList[0].UDF1 = packagModel.L4Num.ToString(); break;
|
default: modelList[0].UDF1 = packagModel.L5Num.ToString(); break;
|
}
|
}
|
return modelList[0];
|
}
|
|
return new ArrivalNoticeDetailDto();
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 根据箱码获取标签箱码信息
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public List<BoxInfoDto> GetBindBoxInfos(BoxInfoVm model,string url)
|
{
|
try
|
{
|
if (string.IsNullOrEmpty(model.BoxNo))
|
{
|
throw new Exception("请扫描外箱条码!");
|
}
|
if (string.IsNullOrWhiteSpace(model.ASNNo))
|
{
|
throw new Exception("请选择入库单号!");
|
}
|
var noticeList = Db.Queryable<BllArrivalNotice>().Where(m => m.IsDel == "0" && m.ASNNo == model.ASNNo).ToList();
|
if (noticeList.Count != 1)
|
{
|
throw new Exception("入库单号重复!");
|
}
|
var notice = noticeList.First();
|
if (notice.Type == "0") //成品入库
|
{
|
string sqlString = $@"SELECT
|
ASNNo,
|
BoxNo,
|
SkuNo,
|
SkuName,
|
LotNo,
|
BitBoxMark,
|
SUM(Qty) as Qty
|
FROM BllBoxInfo
|
WHERE IsDel = '0'
|
AND Status='0'
|
AND BoxNo = '{model.BoxNo}'
|
GROUP BY ASNNo,BoxNo,SkuNo,SkuName,LotNo,BitBoxMark; ";
|
var models = Db.Ado.SqlQuery<BoxInfoDto>(sqlString);
|
|
if (models.Count != 0)
|
{
|
return models;
|
}
|
else
|
{
|
var boxInfo = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo).ToList();
|
|
if (boxInfo.Count == 0)
|
{
|
models = GetFMBindBoxInfos(model.BoxNo, url);
|
return models;
|
}
|
else
|
{
|
if (boxInfo.Count(m => m.Status != "0") > 0)
|
{
|
throw new Exception("箱码信息状态不是等待执行");
|
}
|
return models;
|
}
|
|
|
|
}
|
}
|
else if (notice.Type == "1" || notice.Type == "4") //采购入库
|
{
|
string sqlString = $@"SELECT
|
ASNNo,
|
BoxNo,
|
SkuNo,
|
SkuName,
|
LotNo,
|
BitBoxMark,
|
SUM(Qty) as Qty
|
FROM BllBoxInfo
|
WHERE IsDel = '0'
|
AND Status='0'
|
AND BoxNo = '{model.BoxNo}'
|
GROUP BY ASNNo,BoxNo,SkuNo,SkuName,LotNo,BitBoxMark; ";
|
var models = Db.Ado.SqlQuery<BoxInfoDto>(sqlString);
|
|
if (models.Count != 0)
|
{
|
return models;
|
}
|
else
|
{
|
throw new Exception("没有查询到箱码信息");
|
}
|
}
|
else if (notice.Type == "3") //退货入库
|
{
|
string sqlString = $@"SELECT
|
ASNNo,
|
BoxNo,
|
SkuNo,
|
SkuName,
|
LotNo,
|
BitBoxMark,
|
SUM(Qty) as Qty
|
FROM BllBoxInfo
|
WHERE IsDel = '0'
|
AND Status='0'
|
AND BoxNo = '{model.BoxNo}'
|
GROUP BY ASNNo,BoxNo,SkuNo,SkuName,LotNo,BitBoxMark; ";
|
var models = Db.Ado.SqlQuery<BoxInfoDto>(sqlString);
|
|
if (models.Count != 0)
|
{
|
return models;
|
}
|
else
|
{
|
sqlString = $@"SELECT
|
ASNNo,
|
BoxNo,
|
SkuNo,
|
SkuName,
|
LotNo,
|
BitBoxMark,
|
SUM(Qty) as Qty
|
FROM BllBoxInfo
|
WHERE IsDel = '0'
|
AND Status='0'
|
AND BoxNo2 = '{model.BoxNo}'
|
GROUP BY ASNNo,BoxNo,SkuNo,SkuName,LotNo,BitBoxMark; ";
|
models = Db.Ado.SqlQuery<BoxInfoDto>(sqlString);
|
if (models.Count != 0)
|
{
|
return models;
|
}
|
else
|
{
|
sqlString = $@"SELECT
|
ASNNo,
|
BoxNo,
|
SkuNo,
|
SkuName,
|
LotNo,
|
BitBoxMark,
|
SUM(Qty) as Qty
|
FROM BllBoxInfo
|
WHERE IsDel = '0'
|
AND Status='0'
|
AND BoxNo3 = '{model.BoxNo}'
|
GROUP BY ASNNo,BoxNo,SkuNo,SkuName,LotNo,BitBoxMark; ";
|
models = Db.Ado.SqlQuery<BoxInfoDto>(sqlString);
|
if (models.Count != 0)
|
{
|
return models;
|
}
|
}
|
}
|
|
#region 获取最后一次出库拣货中的箱码信息
|
|
var comBox = Db.Queryable<BllCompleteDetail>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo).GroupBy(m => m.ExportAllotId).Select(m => m.ExportAllotId).ToList();
|
if (comBox.Count == 0)
|
{
|
comBox = Db.Queryable<BllCompleteDetail>().Where(m => m.IsDel == "0" && m.BoxNo2 == model.BoxNo).GroupBy(m => m.ExportAllotId).Select(m => m.ExportAllotId).ToList();
|
if (comBox.Count == 0)
|
{
|
comBox = Db.Queryable<BllCompleteDetail>().Where(m => m.IsDel == "0" && m.BoxNo3 == model.BoxNo).GroupBy(m => m.ExportAllotId).Select(m => m.ExportAllotId).ToList();
|
}
|
}
|
var i = 0;//循环次数
|
DateTime time = DateTime.Now;
|
var allotId = 0;
|
foreach (var item in comBox)
|
{
|
var comBoxList = Db.Queryable<BllCompleteDetail>().Where(m => m.IsDel == "0" && m.ExportAllotId == item).OrderByDescending(m => m.CreateTime).First();
|
if (i == 0)
|
{
|
time = comBoxList.CreateTime;
|
allotId = comBoxList.ExportAllotId;
|
}
|
else if (comBoxList.CreateTime > time)
|
{
|
time = comBoxList.CreateTime;
|
allotId = comBoxList.ExportAllotId;
|
}
|
i++;
|
}
|
if (allotId != 0)
|
{
|
var addComBox = Db.Queryable<BllCompleteDetail>().Where(m => m.IsDel == "0" && m.ExportAllotId == allotId).ToList();
|
var addComList = addComBox.GroupBy(m => m.BoxNo).ToList();
|
var sku = Db.Queryable<SysMaterials>().First(m => m.SkuNo == addComBox.First().SkuNo);
|
var pNum = 0;
|
var bNum = 0;
|
new Common().GetPackQtyInfo(sku.PackagNo, ref pNum, ref bNum);
|
var boxList = new List<BllBoxInfo>();
|
foreach (var com in addComList)
|
{
|
//箱内总数和
|
var qtySum = addComBox.Where(m => m.BoxNo == com.Key).Sum(m => m.CompleteQty);
|
var bitBox = "1";
|
if (qtySum == bNum)
|
{
|
bitBox = "0";
|
}
|
foreach (var item in com)
|
{
|
if (item.BoxNo != model.BoxNo)
|
{
|
if (item.BoxNo2 != model.BoxNo)
|
{
|
if (item.BoxNo3 != model.BoxNo)
|
{
|
continue;
|
}
|
}
|
}
|
var boxInfo = new BllBoxInfo()
|
{
|
BoxNo = item.BoxNo,
|
BoxNo2 = item.BoxNo2,
|
BoxNo3 = item.BoxNo3,
|
SkuNo = item.SkuNo,
|
SkuName = item.SkuName,
|
LotNo = item.LotNo,
|
LotText = item.LotText,
|
Qty = (decimal)item.CompleteQty,
|
FullQty = bNum,
|
//ProductionTime = ,
|
//ExpirationTime = ,
|
InspectMark = "0",
|
InspectStatus = "0",
|
BitBoxMark = bitBox,
|
Origin = "WMS",
|
Status = "0",
|
CreateUser = 0
|
};
|
boxList.Add(boxInfo);
|
}
|
|
}
|
Db.Insertable(boxList).ExecuteCommand();
|
|
string sqlString2 = $@"SELECT
|
ASNNo,
|
BoxNo,
|
SkuNo,
|
SkuName,
|
LotNo,
|
BitBoxMark,
|
SUM(Qty) as Qty
|
FROM BllBoxInfo
|
WHERE IsDel = '0'
|
AND Status='0'
|
AND BoxNo = '{model.BoxNo}'
|
GROUP BY ASNNo,BoxNo,SkuNo,SkuName,LotNo,BitBoxMark; ";
|
var models2 = Db.Ado.SqlQuery<BoxInfoDto>(sqlString2);
|
|
if (models2.Count != 0)
|
{
|
return models2;
|
}
|
else
|
{
|
sqlString2 = $@"SELECT
|
ASNNo,
|
BoxNo,
|
SkuNo,
|
SkuName,
|
LotNo,
|
BitBoxMark,
|
SUM(Qty) as Qty
|
FROM BllBoxInfo
|
WHERE IsDel = '0'
|
AND Status='0'
|
AND BoxNo2 = '{model.BoxNo}'
|
GROUP BY ASNNo,BoxNo,SkuNo,SkuName,LotNo,BitBoxMark; ";
|
models2 = Db.Ado.SqlQuery<BoxInfoDto>(sqlString2);
|
if (models2.Count != 0)
|
{
|
return models2;
|
}
|
else
|
{
|
sqlString2 = $@"SELECT
|
ASNNo,
|
BoxNo,
|
SkuNo,
|
SkuName,
|
LotNo,
|
BitBoxMark,
|
SUM(Qty) as Qty
|
FROM BllBoxInfo
|
WHERE IsDel = '0'
|
AND Status='0'
|
AND BoxNo3 = '{model.BoxNo}'
|
GROUP BY ASNNo,BoxNo,SkuNo,SkuName,LotNo,BitBoxMark; ";
|
models2 = Db.Ado.SqlQuery<BoxInfoDto>(sqlString2);
|
if (models2.Count != 0)
|
{
|
return models2;
|
}
|
}
|
}
|
|
|
}
|
|
throw new Exception("箱码信息不存在!");
|
#endregion
|
|
}
|
else
|
{
|
throw new Exception("单据类型错误");
|
}
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 根据箱码向追溯系统请求标签箱码信息
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public List<BoxInfoDto> GetFMBindBoxInfos(string boxno,string url)
|
{
|
try
|
{
|
#region 箱码请求接口,正式系统放开
|
var data = new
|
{
|
BoxCode = boxno
|
};
|
var jsonData = JsonConvert.SerializeObject(data);
|
|
var response = HttpHelper.DoPost(url, jsonData, "箱码信息请求", "FM");
|
|
var obj = JsonConvert.DeserializeObject<FumaGetBoxModel>(response);//解析返回数据
|
if (obj.Success != "0")
|
{
|
throw new Exception("请求失败" + obj.Message);
|
}
|
#endregion
|
var sku = Db.Queryable<SysMaterials>().First(m => m.SkuNo == obj.Product.SkuNo);
|
var pNum = 0;//托盘物品数量
|
var bNum = 0;//箱码物品数量
|
if (sku == null)
|
{
|
throw new Exception($"未查询到物料{obj.Product.SkuNo}信息");
|
}
|
new Common().GetPackQtyInfo(sku.PackagNo, ref pNum, ref bNum);
|
if (pNum == 0 || bNum == 0)
|
{
|
throw new Exception($"{sku.SkuNo}物品包装未找到!");
|
}
|
|
var boxList = new List<BllBoxInfo>();
|
var comTime = DateTime.Now;
|
//添加箱码信息
|
foreach (var box in obj.Product.BoxInfoList)
|
{
|
foreach (var box2 in box.BoxInfo2List)
|
{
|
foreach (var box3 in box2.BoxInfo3List)
|
{
|
var boxInfo = new BllBoxInfo()
|
{
|
BoxNo = box.BoxNo,
|
BoxNo2 = box2.BoxNo2,
|
BoxNo3 = box3.BoxNo3,
|
Qty = box3.Qty,
|
BitBoxMark = box.BitBoxMark,
|
|
ASNNo = "",
|
//ASNDetailNo = noticeDetail.Id,
|
OrderCode = "",//notice.OrderCode
|
//BindNo = bindId,
|
//PalletNo = model.PallNo,
|
FullQty = bNum,
|
Status = "2",
|
SkuNo = sku.SkuNo,
|
SkuName = sku.SkuName,
|
LotNo = obj.Product.LotNo,
|
LotText = obj.Product.LotText,
|
ProductionTime = DateTime.Parse(obj.Product.ProductionTime),
|
ExpirationTime = DateTime.Parse(obj.Product.ExpirationTime),
|
//CompleteTime = "",
|
InspectMark = "0",
|
InspectStatus = "0",
|
Origin = "赋码",
|
CreateTime = comTime,
|
CreateUser = 0
|
};
|
boxList.Add(boxInfo);
|
}
|
|
}
|
}
|
Db.Fastest<BllBoxInfo>().BulkCopy(boxList);
|
|
|
string sqlString = $@"SELECT
|
ASNNo,
|
BoxNo,
|
SkuNo,
|
SkuName,
|
LotNo,
|
BitBoxMark,
|
SUM(Qty) as Qty
|
FROM BllBoxInfo
|
WHERE IsDel = '0'
|
AND Status='0'
|
AND BoxNo = '{boxno}'
|
GROUP BY ASNNo,BoxNo,SkuNo,SkuName,LotNo,BitBoxMark; ";
|
var models = Db.Ado.SqlQuery<BoxInfoDto>(sqlString); // response
|
|
if (models.Count == 0)
|
{
|
throw new Exception("箱码信息不存在!");
|
}
|
|
return models;
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 验证托盘是否存在
|
/// </summary>
|
/// <param name="palletNo">托盘号</param>
|
/// <returns>"":可使用 -1:不可使用(原因)</returns>
|
public string IsEnablePalletNo(string palletNo)
|
{
|
string sqlMsg = "";
|
string sqlString = string.Empty;
|
try
|
{
|
sqlString = $"select * from SysPallets where PalletNo = '{palletNo}' and isdel = '0';";
|
var models = Db.Ado.SqlQuery<PalletBindVm>(sqlString);
|
|
if (models.Count > 1)
|
{
|
sqlMsg = "-1:存在重复托盘号,请检查!";
|
return sqlMsg;
|
}
|
if (models.Count > 0)
|
{
|
if (models[0].Status == "1")
|
{
|
var detail = Db.Queryable<DataStockDetail>().First(m=>m.PalletNo == palletNo );
|
|
if (detail!= null && !string.IsNullOrWhiteSpace(detail.LocatNo))
|
{
|
var pingAreaStr = Db.Queryable<SysStorageArea>().Where(m => m.IsDel == "0" && m.WareHouseNo == "W04" && m.AreaNo != "B06" && m.AreaNo != "B07").Select(m => m.AreaNo).ToList();
|
var pingLocateInfo = Db.Queryable<SysStorageLocat>().First(m => m.LocatNo == detail.LocatNo && pingAreaStr.Contains(m.AreaNo) && m.IsDel == "0");
|
if (pingLocateInfo == null)
|
{
|
sqlMsg = "-1:托盘使用中,此托盘应在库内请核实!";
|
}
|
}
|
}
|
}
|
else
|
{
|
sqlMsg = "-1:托盘号不存在!";
|
}
|
|
return sqlMsg;
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 根据单据获取标签数量
|
/// </summary>
|
/// <param name="asnNo">入库单</param>
|
/// <param name="asnDetailId">入库单明细号</param>
|
/// <returns></returns>
|
public BoxListInfoDto GetBoxCountByAsn(string asnNo,int? asnDetailId)
|
{
|
try
|
{
|
|
var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == asnDetailId);
|
if (detail == null)
|
{
|
throw new Exception("没有查询到单据明细信息");
|
}
|
var data = new BoxListInfoDto()
|
{
|
SkuNo = detail.SkuNo,
|
SkuName = detail.SkuName,
|
LotNo = detail.LotNo,
|
|
};
|
//获取状态是未组托的标签信息
|
var models = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.ASNNo == asnNo && m.ASNDetailNo == asnDetailId && m.Status == "0")
|
.GroupBy(m=> new { m.ProductionTime,m.ExpirationTime })
|
.Select(m=>new { m.ProductionTime ,m.ExpirationTime}).OrderBy(m=>m.ProductionTime).ToList();//&& m.Status == "0"
|
foreach (var item in models)
|
{
|
var boxNoList = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.ASNNo == asnNo && m.ASNDetailNo == asnDetailId && m.ProductionTime == item.ProductionTime).Select(m => m.BoxNo).ToList();
|
if (boxNoList.Count > 0)
|
{
|
data.BoxNoList = boxNoList;
|
data.Date1 = item.ProductionTime.ToString();
|
data.Date2 = item.ExpirationTime.ToString();
|
|
break;
|
}
|
}
|
return data;
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 保存指定的储位
|
/// </summary>
|
/// <param name="palletNo"></param>
|
/// <param name="locateNo"></param>
|
/// <param name="userId"></param>
|
/// <exception cref="Exception"></exception>
|
public void SaveAppointLocate(string palletNo, string locateNo, int userId)
|
{
|
try
|
{
|
//托盘库存信息
|
var stockDetailList = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && m.PalletNo == palletNo).ToList();
|
if (stockDetailList.Count(m=> string.IsNullOrWhiteSpace(m.LocatNo)) > 0)
|
{
|
throw new Exception("托盘没有在平库储位上");
|
}
|
//判断托盘的储位是否是平库
|
var stockDetail = stockDetailList.First();
|
var oldLocate = stockDetail.LocatNo;
|
var pingAreaStr = Db.Queryable<SysStorageArea>().Where(m => m.IsDel == "0" && m.WareHouseNo == "W04" && m.AreaNo != "B06" && m.AreaNo != "B07").Select(m => m.AreaNo).ToList();
|
var pingLocateInfo = Db.Queryable<SysStorageLocat>().First(m => m.LocatNo == oldLocate && pingAreaStr.Contains(m.AreaNo) && m.IsDel == "0");
|
if (pingLocateInfo == null)
|
{
|
throw new Exception("当前托盘所在的储位没有在系统中找到信息");
|
}
|
|
var skuList = Db.Queryable<SysMaterials>().Where(m => m.IsDel == "0").ToList();
|
//验证物料是否有成品
|
foreach (var item in stockDetailList)
|
{
|
var skuItem = skuList.First(m => m.SkuNo == item.SkuNo);
|
if (skuItem.Type == "2")
|
{
|
throw new Exception("成品物料请入成品库");
|
}
|
}
|
//储位
|
var locate = Db.Queryable<SysStorageLocat>().First(m => m.IsDel == "0" && m.LocatNo == locateNo);
|
if (locate == null)
|
{
|
throw new Exception("未查询到储位的信息");
|
}
|
if (locate.WareHouseNo != "W02")
|
{
|
throw new Exception("只能指定立库的储位");
|
}
|
if (locate.Status != "0" || locate.Flag != "0")
|
{
|
throw new Exception("该储位状态不是空储位或标志不是正常的");
|
}
|
|
|
Db.BeginTran();
|
try
|
{
|
var time = DateTime.Now;
|
//判断当前托盘是否存在绑定信息
|
var task = Db.Queryable<LogTask>().First(m=> m.IsDel == "0" && m.PalletNo == palletNo && (m.Status == "0" || m.Status == "1") && m.OrderType == "0" && m.Type == "0");
|
|
var upShelf = Db.Queryable<BllPalletUpShelf>().First(m => m.IsDel == "0" && m.PalletNo == palletNo && (m.Status == "0" || m.Status == "1"));
|
if (task != null)
|
{
|
if (task.Status == "1")
|
{
|
throw new Exception("托盘正在执行任务,不可指定储位");
|
}
|
if (task.Status == "0")
|
{
|
if (upShelf != null)
|
{
|
if (upShelf.Status == "1")
|
{
|
throw new Exception("托盘正在执行上架任务,不可指定储位");
|
}
|
if (upShelf.Status == "0")
|
{
|
if (locate.LocatNo == task.EndLocat)
|
{
|
throw new Exception("已指定储位,无需重复指定");
|
}
|
//重新指定储位
|
task.EndLocat = locate.LocatNo;
|
task.EndRoadway = locate.RoadwayNo;
|
upShelf.LocatNo = locate.LocatNo;
|
upShelf.RoadwayNo = locate.RoadwayNo;
|
Db.Updateable(task).ExecuteCommand();
|
Db.Updateable(upShelf).ExecuteCommand();
|
new OperationASNServer().AddLogOperationAsn("PDA模块", "指定储位", palletNo, "编辑", $"指定了储位:{locate.LocatNo}、托盘码:{palletNo}的信息", userId);
|
Db.CommitTran();
|
return;
|
}
|
}
|
else
|
{
|
throw new Exception("查询出任务但没有上架记录,信息错误");
|
}
|
}
|
}
|
|
// 添加入库日志记录
|
var taskNo = new Common().GetMaxNo("TK");
|
var addTask = new LogTask //入库任务
|
{
|
TaskNo = taskNo,
|
Sender = "WMS",
|
Receiver = "WCS",
|
IsSuccess = 1, //是否下发成功 0失败 1成功
|
SendDate = DateTime.Now, //发送时间
|
//BackDate = DateTime.Now, //返回时间
|
StartRoadway = "", // 起始巷道
|
StartLocat = oldLocate,//起始位置
|
EndLocat = locate.LocatNo,//目标位置
|
EndRoadway = locate.RoadwayNo, // 目标巷道
|
PalletNo = palletNo,//托盘码
|
IsSend = 1,//是否可再次下发
|
IsCancel = 1,//是否可取消
|
IsFinish = 1,//是否可完成
|
Type = "0",//任务类型 0 入库任务 1 出库任务 2 移库任务
|
Status = "0",//任务状态0:等待执行1正在执行2执行完成
|
OrderType = "0",//0 入库单 1 出库单 2 盘点单 3 移库单
|
Msg = $"{oldLocate}到=>>{locate.LocatNo}的入库任务", //关键信息
|
|
};
|
Db.Insertable(addTask).ExecuteCommand();
|
|
//添加托盘上架记录
|
var upShelfAdd = new BllPalletUpShelf()
|
{
|
TaskNo = addTask.TaskNo,
|
TraceNo = "",
|
PalletNo = palletNo,
|
SkuNo = stockDetail.SkuNo,
|
SkuName = stockDetail.SkuName,
|
LotNo = stockDetail.LotNo,
|
Status = "0",
|
|
WareHouseNo = locate.WareHouseNo,
|
RoadwayNo = locate.RoadwayNo,
|
AreaNo = locate.AreaNo,
|
LocatNo = locate.LocatNo,
|
|
CreateUser = 0,
|
};
|
Db.Insertable(upShelfAdd).ExecuteCommand();
|
|
locate.Status = "2";
|
|
Db.Updateable(locate).ExecuteCommand();
|
|
new OperationASNServer().AddLogOperationAsn("PDA模块", "指定储位", palletNo, "编辑", $"指定了储位:{locate.LocatNo}、托盘码:{palletNo}的信息", userId);
|
Db.CommitTran();
|
}
|
catch (Exception e)
|
{
|
Db.RollbackTran();
|
throw new Exception(e.Message);
|
}
|
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
#endregion
|
// 获取单据列表
|
public List<ArrivalNoticeDto> GetArrivalNotices(ArrivalNoticeVm model)
|
{
|
string sqlString = string.Empty;
|
try
|
{
|
// 未关单的单据
|
sqlString = $"select * from BllArrivalNotice where Type in ({model.Type}) and Status != '3' and Status != '4' and IsDel='0' order by CreateTime;";
|
var modelList = Db.Ado.SqlQuery<ArrivalNoticeDto>(sqlString);
|
|
return modelList;
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
//根据入库单号获取入库总单信息
|
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;
|
}
|
}
|
|
// 根据箱码或托盘号获取箱支信息 liudl
|
public List<BoxInfoDto> GetBoxInfos(BoxInfoVm model)
|
{
|
try
|
{
|
string sqlString = string.Empty;
|
if (model.IsHuiKu == 0)
|
{
|
sqlString = "select BoxNo, SkuNo,SkuName, LotNo, SUM(Qty) as Qty from BllBoxInfo where IsDel = '0' ";
|
if (!string.IsNullOrEmpty(model.PalletNo))
|
{
|
sqlString += $"and PalletNo = '{model.PalletNo}' and Status in ('0','1') ";
|
}
|
if (!string.IsNullOrEmpty(model.BoxNo))
|
{
|
sqlString += $"and BoxNo = '{model.BoxNo}' and Status in ('0','1') ";
|
}
|
sqlString += $"group by BoxNo,SkuNo,SkuName,LotNo; ";
|
}
|
else
|
{
|
sqlString = "select BoxNo, SkuNo,SkuName, LotNo, SUM(Qty) as Qty from DataBoxInfo where IsDel = '0' ";
|
if (!string.IsNullOrEmpty(model.PalletNo))
|
{
|
sqlString += $"and PalletNo = '{model.PalletNo}' ";
|
}
|
sqlString += $"group by BoxNo,SkuNo,SkuName,LotNo; ";
|
}
|
var models = Db.Ado.SqlQuery<BoxInfoDto>(sqlString);
|
|
return models;
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
//获取出入库所有订单关闭的单据信息
|
public List<NoticeDto> GetNotices()
|
{
|
try
|
{
|
string sqlString = string.Empty;
|
//获取入库单据
|
sqlString = "select ASNNo as Id,ASNNo as Title from BllArrivalNotice where IsDel = '0' and Status = '3'";
|
var Asnmodels = Db.Ado.SqlQuery<NoticeDto>(sqlString);
|
//获取出库单据
|
sqlString = "select SONo as Id,SONo as Title from BllExportNotice where IsDel = '0' and Status = '5'";
|
var Somodels = Db.Ado.SqlQuery<NoticeDto>(sqlString);
|
//合并出入库数据
|
foreach (var item in Somodels)
|
{
|
Asnmodels.Add(item);
|
}
|
return Asnmodels;
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
//获取出入库所有订单关闭的单据信息
|
public NoticeInfo ByNoGetNotices(string No)
|
{
|
try
|
{
|
NoticeInfo notice = new NoticeInfo();
|
if (string.IsNullOrEmpty(No))
|
{
|
throw new Exception("单号不可为空!");
|
}
|
string IsAss = No.Substring(0, 2);
|
if (IsAss == "AS")
|
{
|
//入库
|
//获取入库单总单与入库单明细
|
string str = $"select ASNNo as Code,OrderCode from BllArrivalNotice where IsDel = '0' and ASNNo = '{No}'";
|
notice = Db.Ado.SqlQuerySingle<NoticeInfo>(str);
|
//获取明细
|
str = $"select ASNNo as Code,OrderDetailCode as OrderCode,Qty,CompleteQty,SkuNo,SkuName,LotNo,Standard from BllArrivalNoticeDetail where IsDel = '0' and ASNNo = '{No}'";
|
notice.models = Db.Ado.SqlQuery<NoticeDetailInfo>(str);
|
|
}
|
else if (IsAss == "SO")
|
{
|
//出库
|
//获取出库单总单与出库单明细
|
string str = $"select SONo as Code,OrderCode from BllExportNotice where IsDel = '0' and SONo = '{No}'";
|
notice = Db.Ado.SqlQuerySingle<NoticeInfo>(str);
|
//获取明细
|
str = $"select SONo as Code,OrderDetailCode as OrderCode,Qty,CompleteQty,SkuNo,SkuName,LotNo,Standard from BllExportNoticeDetail where IsDel = '0' and SONo = '{No}'";
|
notice.models = Db.Ado.SqlQuery<NoticeDetailInfo>(str);
|
|
}
|
else
|
{
|
throw new Exception("当前单号存在异常!");
|
}
|
|
|
return notice;
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
// 根据托盘号或箱码获取托盘信息 liudl
|
public List<PalletBindDto> GetPalletBindInfo(BllPalletBind model)
|
{
|
try
|
{
|
string sqlString = string.Empty;
|
sqlString = "select b.SkuNo,b.SkuName,a.LotNo,a.Qty,a.PalletNo,a.Id from BllPalletBind a " +
|
"left join BllArrivalNoticeDetail b on a.ASNDetailNo = b.Id where a.IsDel = '0' and b.IsDel = '0' ";
|
if (!string.IsNullOrEmpty(model.PalletNo))
|
{
|
sqlString += $"and PalletNo = '{model.PalletNo}' and a.Status = '0' ";
|
}
|
else
|
{
|
throw new Exception("托盘号异常!");
|
}
|
var models = Db.Ado.SqlQuery<PalletBindDto>(sqlString);
|
|
return models;
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
// 绑定空托盘
|
public string BindNullPallet(PalletBindVm model)
|
{
|
string strMsg = "";
|
try
|
{
|
if (string.IsNullOrEmpty(model.PalletNo))
|
{
|
throw new Exception("托盘号不可为空");
|
}
|
if (model.Qty == null || model.Qty == 0)
|
{
|
throw new Exception("空托盘数量不可为空");
|
}
|
var stockDetail = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && m.PalletNo == model.PalletNo).ToList();
|
if (stockDetail.Count > 0)
|
{
|
throw new Exception("当前托盘在库内已有库存信息,请核实");
|
}
|
|
//获取托盘信息
|
var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
|
if (pallet == null)
|
{
|
throw new Exception("未查询到托盘信息");
|
}
|
if (pallet.Status != "0")
|
{
|
throw new Exception("托盘状态不能未使用状态");
|
}
|
//获取托盘信息
|
var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == "100099");
|
var pNum = 0;
|
var bNum = 0;
|
|
new Common().GetPackQtyInfo(sku.PackagNo, ref pNum, ref bNum);
|
|
var datetime = Db.GetDate();
|
Db.BeginTran();
|
|
// 插入托盘绑定表
|
var modelpb = new BllPalletBind
|
{
|
ASNNo = "",
|
ASNDetailNo = 0,
|
TaskNo = "", //任务号
|
PalletNo = model.PalletNo,
|
PalletNo2 = model.PalletNo2,
|
PalletNo3 = model.PalletNo3,
|
Qty = (int)model.Qty,
|
FullQty = pNum,
|
Status = "2", //等待执行
|
Type = "1", //0 物料托 1 空托
|
LotNo = "",
|
LotText = "",
|
SupplierLot = "",
|
InspectMark = "0", //0 否 1 是
|
BitPalletMark = pNum == (int)model.Qty ? "0" : "1",
|
IsBale = "0",
|
IsBelt = "0",
|
CreateUser = (int)model.CreateUser,
|
CreateTime = Db.GetDate()
|
};
|
var id = Db.Insertable(modelpb).ExecuteReturnIdentity();
|
|
//var modelbb = new BllBoxInfo
|
//{
|
// ASNNo = "",
|
// ASNDetailNo = null,
|
// BindNo = id,
|
// PalletNo = model.PalletNo,
|
// PalletNo2 = model.PalletNo2,
|
// PalletNo3 = model.PalletNo3,
|
// Status = "2",
|
// CompleteTime = DateTime.Now,
|
// Qty = (int)model.Qty,
|
// FullQty = pNum,
|
// SkuNo = sku.SkuNo,
|
// SkuName = sku.SkuName,
|
// LotNo = "",
|
// LotText = "",
|
// SupplierLot = "",
|
// InspectStatus = sku.IsInspect,
|
// Origin = "PDA",
|
// BoxNo = "",
|
// BoxNo2 = "",
|
// BoxNo3 = "",
|
// InspectMark = "",
|
// BitBoxMark = "0",
|
|
// CreateUser = (int)model.CreateUser,
|
// CreateTime = datetime
|
//};
|
//Db.Insertable(modelbb).ExecuteCommand();
|
|
//添加库存
|
|
#region 库存明细
|
var sd1 = new DataStockDetail()
|
{
|
LotNo = modelpb.LotNo,
|
LotText = modelpb.LotText,
|
SupplierLot = modelpb.SupplierLot,
|
SkuNo = sku.SkuNo,
|
SkuName = sku.SkuName,
|
Standard = sku.Standard,
|
Qty = modelpb.Qty,
|
LockQty = 0,
|
FrozenQty = 0,
|
InspectQty = 0,
|
ASNNo = modelpb.ASNNo,
|
ASNDetailNo = modelpb.ASNDetailNo,
|
WareHouseNo = "",
|
RoadwayNo = "",
|
AreaNo = "",
|
LocatNo = "",
|
PalletNo = modelpb.PalletNo,
|
PalletNo2 = modelpb.PalletNo2,
|
PalletNo3 = modelpb.PalletNo3,
|
PalletTags = "0",
|
CompleteTime = datetime,
|
ProductionTime = modelpb.ProductionTime,
|
ExpirationTime = modelpb.ExpirationTime,
|
Status = "0",
|
InspectMark = modelpb.InspectMark,
|
InspectStatus = sku.IsInspect,
|
BitPalletMark = modelpb.BitPalletMark,
|
PackagNo = sku.PackagNo,
|
IsBale = modelpb.IsBale,
|
IsBelt = modelpb.IsBelt,
|
|
|
IsDel = "0",
|
CreateUser = 0,
|
CreateTime = datetime
|
};
|
var sdId1 = Db.Insertable(sd1).ExecuteReturnIdentity();
|
#endregion
|
|
#region 库存箱码明细
|
|
//var box2 = new DataBoxInfo()
|
//{
|
// StockDetailId = sdId1,
|
// BindNo = modelpb.Id,
|
// BoxNo = modelbb.BoxNo,
|
// BoxNo2 = modelbb.BoxNo2,
|
// BoxNo3 = modelbb.BoxNo3,
|
// PalletNo = modelbb.PalletNo,
|
// PalletNo2 = modelbb.PalletNo2,
|
// PalletNo3 = modelbb.PalletNo3,
|
// Qty = modelbb.Qty,
|
// FullQty = modelbb.FullQty,
|
// Status = "2",
|
// LotNo = modelbb.LotNo,
|
// LotText = modelbb.LotText,
|
// SkuNo = modelbb.SkuNo,
|
// SkuName = modelbb.SkuName,
|
// Standard = sku.Standard,
|
// ProductionTime = modelbb.ProductionTime,
|
// SupplierLot = modelbb.SupplierLot,
|
// InspectStatus = sku.IsInspect,
|
// InspectMark = modelbb.InspectMark,
|
// BitBoxMark = modelbb.BitBoxMark,
|
// ExpirationTime = modelbb.ExpirationTime,
|
|
// CreateUser = 0,
|
// CreateTime = datetime
|
//};
|
//Db.Insertable(box2).ExecuteCommand();
|
#endregion
|
|
#region 库存
|
var dataStock1 = Db.Queryable<DataStock>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo);
|
if (dataStock1 != null)
|
{
|
dataStock1.Qty += modelpb.Qty;
|
if (modelpb.InspectMark == "1")
|
{
|
dataStock1.IsSampling = "0";
|
}
|
Db.Updateable(dataStock1).ExecuteCommand();
|
}
|
else
|
{
|
var stock = new DataStock()
|
{
|
SkuNo = sku.SkuNo,
|
SkuName = sku.SkuName,
|
Standard = sku.Standard,
|
LotNo = "",
|
LotText = "",
|
Qty = modelpb.Qty,
|
LockQty = 0,
|
FrozenQty = 0,
|
IsSampling = "0",
|
IsDel = "0",
|
CreateUser = 0,
|
CreateTime = datetime
|
};
|
Db.Insertable(stock).ExecuteCommand();
|
}
|
#endregion
|
|
|
// 更改托盘使用状态
|
string sqlStr = string.Empty;
|
sqlStr = $"update SysPallets set Status = '1' where PalletNo = '{model.PalletNo}';";
|
Db.Ado.ExecuteCommand(sqlStr);
|
Db.CommitTran();
|
|
// 插入操作日志
|
new OperationASNServer().AddLogOperationAsn("PDA模块", "空托入库", model.PalletNo, "添加", $"在PDA上添加了空托盘跺", (int)model.CreateUser);
|
|
return strMsg;
|
}
|
catch (Exception ex)
|
{
|
Db.Ado.RollbackTran();
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 解绑空托盘
|
/// </summary>
|
/// <param name="upBindPalletNo">解绑托盘号</param>
|
/// <param name="createUser">创建人</param>
|
/// <returns></returns>
|
public string UnBindNullPallet(string upBindPalletNo, int createUser)
|
{
|
string strMsg = "";
|
//捕获异常
|
try
|
{
|
var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.PalletNo == upBindPalletNo && m.Type == "1" && m.Status == "2");
|
if (bind == null)
|
{
|
throw new Exception("未查询到空托盘绑定信息");
|
}
|
if (!string.IsNullOrWhiteSpace(bind.TaskNo))
|
{
|
throw new Exception("当前托盘已有任务,请先取消任务再解绑托盘");
|
}
|
//获取任务信息
|
var logtask = Db.Queryable<LogTask>().First(a => a.PalletNo == upBindPalletNo && a.IsDel == "0" && (a.Status == "1" || a.Status == "0"));
|
if (logtask != null)
|
{
|
throw new Exception("该托盘有任务任务正在执行 请核实!");
|
}
|
|
//获取箱码信息
|
var box = Db.Queryable<BllBoxInfo>().First(a => a.PalletNo == upBindPalletNo && a.IsDel == "0" && a.BindNo == bind.Id);
|
//判断空托入库的托盘是否有该托盘
|
if (box == null)
|
{
|
strMsg = "该托盘不是空托托盘 或未绑定 请核实托盘";
|
return strMsg;
|
}
|
|
|
Db.BeginTran();
|
|
var time = DateTime.Now;
|
//删除托盘绑定信息
|
bind.IsDel = "1";
|
bind.UpdateUser = createUser;
|
bind.UpdateTime = time;
|
Db.Updateable(bind).ExecuteCommand();
|
|
//删除箱码信息
|
box.UpdateTime = time;
|
box.UpdateUser = createUser;
|
box.IsDel = "1";
|
Db.Updateable(box).ExecuteCommand();
|
|
// 插入解绑托盘表
|
BllPalletUnbind modelpb = new BllPalletUnbind
|
{
|
|
UpbindPalletNo = upBindPalletNo,
|
PalletNo2 = bind.PalletNo2,
|
PalletNo3 = bind.PalletNo3,
|
Qty = bind.Qty,
|
LotNo = bind.LotNo,
|
LotText = bind.LotText,
|
SupplierLot = bind.SupplierLot,
|
CreateUser = createUser,
|
CreateTime = time
|
};
|
Db.Insertable(modelpb).ExecuteCommand();
|
|
//删除库存信息
|
var stockDetail = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.PalletNo == upBindPalletNo);
|
Db.Deleteable(stockDetail).ExecuteCommand();
|
var boxInfo = Db.Queryable<DataBoxInfo>().Where(m => m.IsDel == "0" && m.StockDetailId == stockDetail.Id).ToList();
|
Db.Deleteable(boxInfo).ExecuteCommand();
|
var stock = Db.Queryable<DataStock>().First(m => m.IsDel == "0" && m.SkuNo == box.SkuNo);
|
stock.Qty -= bind.Qty;
|
if (stock.Qty == 0)
|
{
|
Db.Deleteable(stock).ExecuteCommand();
|
}
|
else if (stock.Qty < 0)
|
{
|
throw new Exception("库存信息错误,解绑后数量小于0");
|
}
|
else
|
{
|
Db.Updateable(stock).ExecuteCommand();
|
}
|
|
|
// 更改托盘使用状态
|
string sqlStr = string.Empty;
|
sqlStr = $"update SysPallets set Status = '0' where PalletNo = '{upBindPalletNo}';";
|
Db.Ado.ExecuteCommand(sqlStr);
|
Db.CommitTran();
|
|
// 插入操作日志
|
new OperationASNServer().AddLogOperationAsn("PDA模块", "空托入库", upBindPalletNo, "添加", $"在PDA上解绑了空托盘跺", createUser);
|
|
return strMsg;
|
}
|
catch (Exception ex)
|
{
|
//抛出异常
|
Db.Ado.RollbackTran();
|
throw ex;
|
}
|
}
|
|
// 删除已组信息
|
public string DelBoxInfo(BoxInfoVm model)
|
{
|
string strMsg = "";
|
string sqlString = string.Empty;
|
try
|
{
|
if (model.Id == null || model.Id == 0)
|
{
|
strMsg = "-1:箱支ID不可为空!";
|
return strMsg;
|
}
|
|
// 获取箱支信息和托盘状态(已组未入库的可删除;入库成功又出库的不可删除)
|
sqlString = $"select * from BllBoxInfo where id = '{model.Id}' and Status='1' and isdel = '0';";
|
var boxModel = Db.Ado.SqlQuery<BoxInfoDto>(sqlString);
|
if (boxModel.Count <= 0)
|
{
|
strMsg = "-1:箱支信息状态已变更或已存在库存信息,请检查!";
|
}
|
|
// 查询托盘上其他物料数量
|
sqlString = string.Empty;
|
sqlString += $"select count(id) from BllBoxInfo where PalletNo = '{boxModel[0].PalletNo}' and isdel = '0' and id != '{model.Id}';";
|
int rowNum = Db.Ado.GetInt(sqlString);
|
|
// 查询入库单明细是否有其他托盘绑定信息
|
sqlString = string.Empty;
|
sqlString += $"select count(id) from BllBoxInfo where ASNDetailNo = '{boxModel[0].ASNDetailNo}' and isdel = '0' and id != '{model.Id}';";
|
int asnDetailNum = Db.Ado.GetInt(sqlString);
|
|
// 查询入库单明细是否有其他托盘绑定信息
|
sqlString = string.Empty;
|
sqlString += $"select count(id) from BllBoxInfo where ASNNo = '{boxModel[0].ASNNo}' and isdel = '0' and id != '{model.Id}';";
|
int asnNum = Db.Ado.GetInt(sqlString);
|
|
Db.BeginTran();
|
// 解除箱支和托盘的关联
|
sqlString = string.Empty;
|
sqlString = $"Update BllBoxInfo set ASNNo = '',ASNDetailNo='',BindNo = '',PalletNo='', ";
|
sqlString += $"UpdateTime=GETDATE(),UpdateUser='{model.CreateUser} where id = '{model.Id}';";
|
|
// 判断托盘上是否还有物料 无:删除绑定的托盘信息并更改托盘状态
|
if (rowNum <= 0)
|
{
|
// 删除托盘绑定信息
|
sqlString = string.Empty;
|
sqlString = $"Update BllPalletBind set IsDel = '1' where id = '{model.Id}';";
|
|
|
// 判断入库单明细是否存在其他已组托盘的
|
if (asnDetailNum <= 0)
|
{
|
// 更改入库单明细状态
|
sqlString = string.Empty;
|
sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty - '{boxModel[0].Qty}',Status = '0', ";
|
sqlString += $"CompleteTime=GETDATE() where id = '{boxModel[0].ASNDetailNo}';";
|
Db.Ado.ExecuteCommand(sqlString);
|
|
// 判断入库单是否有其他组托信息
|
if (asnNum <= 0)
|
{
|
// 更改入库单状态
|
sqlString = string.Empty;
|
sqlString += $"update BllArrivalNotice set Status = '0',CompleteTime=GETDATE() where ASNNo = '{boxModel[0].ASNNo}';";
|
Db.Ado.ExecuteCommand(sqlString);
|
}
|
}
|
|
// 更改托盘状态
|
sqlString = string.Empty;
|
sqlString = $"update SysPallets set Status = '0' where PalletNo = '{boxModel[0].PalletNo}';";
|
Db.Ado.ExecuteCommand(sqlString);
|
}
|
|
Db.CommitTran();
|
return strMsg;
|
}
|
catch (Exception ex)
|
{
|
Db.RollbackTran();
|
throw ex;
|
}
|
}
|
|
// 删除已组信息
|
public string DelPalletBind(BllPalletBind model)
|
{
|
string strMsg = "";
|
string sqlString = string.Empty;
|
try
|
{
|
if (model.Id == 0)
|
{
|
throw new Exception("-1:托盘ID不可为0!");
|
}
|
|
//获取托盘绑定信息
|
var bind = Db.Queryable<BllPalletBind>().First(a => a.IsDel == "0" && a.Status == "0" && a.Id == model.Id);
|
//验证托盘绑定信息是否为空
|
if (bind == null)
|
{
|
throw new Exception("-1:未获取到对应托盘信息,请核实!");
|
}
|
//判断托盘绑定信息是否不是等待执行
|
if (bind.Status != "0")
|
{
|
throw new Exception("-1:该托盘已正在入库,请核实!");
|
}
|
//获取是否有指定库位
|
SysStorageLocat locat = new SysStorageLocat();
|
int isNullLocat = 0;
|
//判断储位是否为空
|
if (!string.IsNullOrWhiteSpace(bind.LocatNo))
|
{
|
isNullLocat = 1;
|
locat = Db.Queryable<SysStorageLocat>().First(a => a.IsDel == "0" && a.WareHouseNo == bind.WareHouseNo && a.RoadwayNo == bind.RoadwayNo && a.LocatNo == bind.LocatNo);
|
//判断储位地址是否为正在入库
|
if (locat.Status != "2")
|
{
|
throw new Exception("-1:当前托盘绑定的储位地址不是正在入库,请核实!");
|
}
|
}
|
//获取托盘信息
|
var pallet = Db.Queryable<SysPallets>().First(a => a.IsDel == "0" && a.PalletNo == model.PalletNo);
|
//判断托盘信息是否为空
|
if (pallet == null)
|
{
|
throw new Exception("-1:未获取到对应托盘信息,请核实!");
|
}
|
//获取对应入库单据总单
|
var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == bind.ASNNo);
|
//验证入库单总单信息
|
if (notice == null)
|
{
|
throw new Exception("-1:未获取到对应入库单总单信息,请核实!");
|
}
|
//获取对应入库单据明细
|
var noticeDetail = Db.Queryable<BllArrivalNoticeDetail>().First(a => a.IsDel == "0" && a.Id == bind.ASNDetailNo);
|
//验证入库单单据明细
|
if (noticeDetail == null)
|
{
|
throw new Exception("-1:未获取到对应入库单单据明细信息,请核实!");
|
}
|
var bind2 = Db.Queryable<BllPalletBind>().Where(a => a.IsDel == "0" && a.Id != model.Id && model.ASNDetailNo == noticeDetail.Id).ToList();
|
|
|
Db.BeginTran();
|
if (bind2.Count(m => m.InspectMark == "1") > 0)
|
{
|
noticeDetail.IsSampling = "1";
|
}
|
else
|
{
|
noticeDetail.IsSampling = "0";
|
}
|
//减少入库单明细数量 判断已组数量是否为0 再判断完成数量是否为0
|
noticeDetail.FactQty -= bind.Qty;
|
//判断已组数量是否为0
|
if (noticeDetail.FactQty == 0)
|
{
|
|
noticeDetail.Status = "0"; //入库单明细状态
|
|
//获取状态不是等待执行的明细信息
|
var count = Db.Queryable<BllArrivalNoticeDetail>().Count(m => m.IsDel == "0" && m.Id != noticeDetail.Id && m.ASNNo == bind.ASNNo && m.Status != "0");
|
if (count == 0)
|
{
|
//修改入库单信息
|
notice.Status = "0";
|
notice.UpdateTime = Db.GetDate();
|
notice.UpdateUser = model.CreateUser;
|
Db.Updateable(notice).ExecuteCommand();
|
}
|
}
|
Db.Updateable(noticeDetail).ExecuteCommand();
|
|
|
// 清除托盘绑定上信息
|
//ASNNo,ASNDetailNo,Qty,FullQty,LotNo,LotText,SupplierLot,IsDel,UpdateTime,UpdateUser
|
bind.ASNNo = ""; //入库单号
|
bind.ASNDetailNo = 0; //入库单明细id
|
bind.Qty = 0; //数量
|
bind.FullQty = 0; //整托数量
|
bind.LotNo = ""; //批次
|
bind.LotText = ""; //批次描述
|
bind.SupplierLot = ""; //供货批次
|
bind.IsDel = "1"; //是否删除
|
bind.UpdateTime = Db.GetDate(); //修改时间
|
bind.UpdateUser = model.CreateUser; //修改人
|
if (isNullLocat == 1)
|
{
|
bind.LocatNo = ""; //储位地址
|
bind.RoadwayNo = ""; //所属巷道
|
bind.WareHouseNo = ""; //所属仓库
|
//修改储位信息状态
|
locat.Status = "0"; //储位状态 0:空储位
|
Db.Updateable(locat).ExecuteCommand();
|
}
|
Db.Updateable(bind).ExecuteCommand();
|
|
//修改托盘信息状态
|
pallet.Status = "0"; //0:未使用
|
Db.Updateable(pallet).ExecuteCommand();
|
|
Db.CommitTran();
|
return strMsg;
|
}
|
catch (Exception ex)
|
{
|
Db.RollbackTran();
|
throw ex;
|
}
|
}
|
|
// 平库完成入库操作
|
public string CompleteInStock(PalletBindVm model)
|
{
|
string strMsg = "";
|
string sqlString = string.Empty;
|
try
|
{
|
///平库入库业务
|
///1:判断一系列条件
|
///1.1:判断托盘状态 是否为使用中
|
///1.2:判断组托、箱码信息 是否已入库
|
///1.3:判断单据是否关单 已关单无法入库 请重新创建其它单据
|
///1.4:判断任务信息是否为已完成(先判断 等确定组托后是否创建任务再决定是否注释)
|
///2:更改库存
|
///2.1:更改前判断库存是否存在该物料 如存在 直接增加数量 不存在 新增库存信息 增加库存明细信息
|
///3:更改单据
|
///3.1:更改单据时判断单据状态是否为已完成 如已完成 则只增加完成数量
|
///3.1.1:如正在执行 则判断完成数量加入库数量是否等于或大于入库单数量
|
///3.2:如正在执行或等待执行 则判断完成数量加入库数量是否等于或大于入库单数量
|
///3.2.1:不大于或等于 则变更状态为正在执行
|
///3.2.2:如大于或等于 则变更状态为已完成
|
///4:更改组托信息和箱码信息
|
///4.1:组托信息更改为已入库
|
///4.2:更改任务信息
|
|
//获取当前时间
|
DateTime serverTime = Db.Ado.GetDateTime("select GETDATE();");
|
#region 判断
|
|
#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)
|
{
|
foreach (var item in stockDetail)
|
{
|
if (!string.IsNullOrEmpty(item.WareHouseNo))
|
{
|
strMsg = "-1:该托盘未在库外,请核查!";
|
return strMsg;
|
}
|
}
|
iscount = 1; //回流入库
|
}
|
#endregion
|
|
#region 地码信息(储位信息)
|
var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == model.LocatNo && w.Status == "0");
|
if (storageLocat == null)
|
{
|
strMsg = "-1:储位信息不存在或非空闲状态,请核查!";
|
return strMsg;
|
}
|
#endregion
|
|
#region 组托信息
|
// 验证组托信息
|
var palletbind = Db.Queryable<BllPalletBind>().Where(p => p.IsDel == "0" && p.ASNNo == model.ASNNo && p.PalletNo == model.PalletNo && p.Status != "2").ToList();
|
|
if (iscount == 0)
|
{
|
//验证组托信息是否为空
|
if (palletbind == null || palletbind.Count <= 0)
|
{
|
strMsg = "-1:组托信息为空,请核查!";
|
return strMsg;
|
}
|
}
|
#endregion
|
|
#region 箱码信息
|
//获取箱码信息
|
var boxinfo = new List<BllBoxInfo>();
|
if (iscount == 0)
|
{
|
string boxstr = $"select * from BLLBoxInfo where IsDel = '0' and ASNNo = '{model.ASNNo}'";
|
boxinfo = Db.Ado.SqlQuery<BllBoxInfo>(boxstr).ToList();
|
|
//验证箱码信息是否存在
|
if (boxinfo.Count <= 0)
|
{
|
strMsg = "-1:箱码信息不存在,请核查!";
|
return strMsg;
|
}
|
}
|
#endregion
|
|
#region 单据信息
|
//获取入库单据总单
|
var arrival = new BllArrivalNotice();
|
if (iscount == 0)
|
{
|
arrival = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.Status != "3" && a.ASNNo == model.ASNNo);
|
|
//验证入库单总单是否关闭
|
if (arrival == null)
|
{
|
strMsg = "-1:入库单总单为空,请核查!";
|
return strMsg;
|
}
|
//判断入库单总单是否为已关闭
|
if (arrival.Status == "3")
|
{
|
strMsg = "-1:入库单总单已关闭,请核查!";
|
return strMsg;
|
}
|
}
|
//获取入库单明细信息
|
var arrivalnotice = new List<BllArrivalNoticeDetail>();
|
if (iscount == 0)
|
{
|
arrivalnotice = Db.Queryable<BllArrivalNoticeDetail>().Where(d => d.IsDel == "0" && d.ASNNo == arrival.ASNNo && d.Status == "1").ToList();
|
//验证入库单明细是否存在
|
if (arrivalnotice == null || arrivalnotice.Count <= 0)
|
{
|
strMsg = "-1:入库单明细为空,请核查!";
|
return strMsg;
|
}
|
}
|
#endregion
|
|
#endregion
|
|
Db.BeginTran();//开启事务
|
//判断是否回流入库
|
if (iscount == 0)
|
{
|
#region 正常入库
|
bool isFinsh = true;//入库单明细是否全部完成
|
//遍历入库单详情
|
foreach (var noticeItem in arrivalnotice)
|
{
|
#region 物料信息
|
var sku = Db.Queryable<SysMaterials>().First(s => s.SkuNo == noticeItem.SkuNo && s.IsDel == "0" && s.SkuName == noticeItem.SkuName);
|
//判断物料信息是否为空
|
if (sku == null)
|
{
|
strMsg = "-1:物料信息为空,请核查!";
|
return strMsg;
|
}
|
#endregion
|
decimal pallQty = 0;//托盘上数量
|
var boxinfo2 = boxinfo.Where(w => w.SkuNo == noticeItem.SkuNo && w.LotNo == noticeItem.LotNo && w.PalletNo == model.PalletNo).ToList();
|
if (boxinfo2.Count <= 0)
|
{
|
strMsg = "-1:箱码信息不存在,请核查!";
|
return strMsg;
|
}
|
else
|
{
|
// 改变箱支关系表状态:已入库
|
sqlString = $"Update BllBoxInfo set Status = '2' where PalletNo = '{model.PalletNo}' and ASNNo = '{model.ASNNo}' and Status = '1'";
|
Db.Ado.ExecuteCommand(sqlString);
|
|
pallQty = boxinfo2.Sum(w => w.Qty);
|
//入库单明细完成数量增加
|
noticeItem.CompleteQty += pallQty;
|
}
|
//判断入库数量增加后是否大于等于单据数量
|
if (noticeItem.CompleteQty >= noticeItem.Qty)
|
{
|
noticeItem.Status = "2";
|
noticeItem.CompleteTime = serverTime;
|
}
|
else
|
{
|
noticeItem.Status = "1";
|
|
isFinsh = false;
|
}
|
noticeItem.UpdateUser = model.CreateUser;
|
noticeItem.UpdateTime = serverTime;
|
Db.Updateable(arrivalnotice).ExecuteCommand();
|
|
#region 库存总表
|
// 判断当前物料库存表是否已存在
|
string str = $"select * from DataStock where SkuNo = '{noticeItem.SkuNo}' and LotNo = '{noticeItem.LotNo}' and Standard = '{noticeItem.Standard}' and SkuName = '{noticeItem.SkuName}' and IsDel = '0'";
|
var stockModel = Db.Ado.SqlQuerySingle<DataStock>(str);
|
|
if (stockModel == null || stockModel.Id == 0)
|
{
|
stockModel = new DataStock
|
{
|
LotNo = noticeItem.LotNo,
|
LotText = noticeItem.LotText,
|
SupplierLot = noticeItem.SupplierLot,
|
SkuNo = noticeItem.SkuNo,
|
SkuName = noticeItem.SkuName,
|
Qty = pallQty,
|
Standard = noticeItem.Standard,
|
CreateUser = (int)model.CreateUser,
|
CreateTime = serverTime
|
};
|
Db.Insertable<DataStock>(stockModel).ExecuteCommand();
|
}
|
else
|
{
|
sqlString = $"update DataStock set Qty = Qty + {pallQty}," +
|
$"UpdateTime = GETDATE(),UpdateUser='{model.CreateUser}' where id = '{stockModel.Id}';";
|
Db.Ado.ExecuteCommand(sqlString);
|
}
|
#endregion
|
|
#region 库存明细表
|
var palletbindInfo = palletbind.First(w => w.ASNDetailNo == noticeItem.Id);
|
// 判断当前托盘是否已存在(拣货回库托盘)
|
var detailModel = Db.Queryable<DataStockDetail>()
|
.First(it => it.PalletNo == palletbindInfo.PalletNo && it.LotNo == noticeItem.LotNo && it.SkuNo == noticeItem.SkuNo
|
&& it.Standard == noticeItem.Standard && it.IsDel == "0");
|
var stId = 0;
|
if (detailModel == null || detailModel.Id == 0)
|
{
|
// 获取可抽检数量
|
sqlString = "select sum(qty) from BllBoxInfo where isdel = 0 and ";
|
sqlString += $"BindNo = '{palletbindInfo.Id}'";
|
int inspectQty = Db.Ado.GetInt(sqlString);
|
|
// 添加库存明细表
|
detailModel = new DataStockDetail()
|
{
|
LotNo = noticeItem.LotNo,
|
LotText = noticeItem.LotText,
|
SupplierLot = noticeItem.SupplierLot,
|
SkuNo = noticeItem.SkuNo,
|
SkuName = noticeItem.SkuName,
|
Standard = noticeItem.Standard,
|
Qty = pallQty,
|
LockQty = 0,
|
FrozenQty = 0,
|
InspectQty = inspectQty,
|
ASNNo = noticeItem.ASNNo,
|
ASNDetailNo = (int)palletbindInfo.ASNDetailNo,
|
WareHouseNo = "W02",
|
RoadwayNo = "",
|
AreaNo = "",
|
LocatNo = model.LocatNo,
|
PalletNo = model.PalletNo,
|
PalletNo2 = palletbindInfo.PalletNo2,
|
PalletNo3 = palletbindInfo.PalletNo3,
|
CompleteTime = serverTime,
|
ProductionTime = palletbindInfo.ProductionTime,
|
ExpirationTime = palletbindInfo.ExpirationTime,
|
Status = "0",
|
InspectMark = palletbindInfo.InspectMark,
|
BitPalletMark = palletbindInfo.BitPalletMark,
|
InspectStatus = sku.IsInspect, // 组盘的时候就要默认设定好是否合格
|
PackagNo = sku.PackagNo,
|
IsBale = palletbindInfo.IsBale,
|
IsBelt = palletbindInfo.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 = DateTime.Now, //发送时间
|
BackDate = DateTime.Now, //返回时间
|
StartLocat = "",//起始位置
|
EndLocat = "零箱库",//目标位置
|
PalletNo = palletbindInfo.PalletNo,//托盘码
|
IsSend = 0,//是否可再次下发
|
IsCancel = 0,//是否可取消
|
IsFinish = 0,//是否可完成
|
Type = "0",//任务类型 0 入库任务 1 出库任务 2 移库任务
|
Status = "2",//任务状态0:等待执行1正在执行2执行完成
|
OrderType = "0",//0 入库单 1 出库单 2 盘点单 3 移库单
|
Msg = "零箱库的入库任务",
|
};
|
Db.Insertable(exTask).ExecuteCommand();
|
|
//修改组托状态
|
palletbindInfo.Status = "2"; //2 入库完成
|
palletbindInfo.WareHouseNo = "W02";//所属仓库
|
palletbindInfo.LocatNo = model.LocatNo;//储位地址
|
palletbindInfo.UpdateTime = serverTime;
|
palletbindInfo.UpdateUser = model.CreateUser;
|
palletbindInfo.CompleteTime = serverTime; //完成时间
|
palletbindInfo.TaskNo = taskNo; //任务号
|
Db.Updateable(palletbind).ExecuteCommand();
|
#endregion
|
|
#region 库存箱支明细表
|
// 插入新组的箱支信息
|
var comTime = DateTime.Now;
|
foreach (var item in boxinfo2)
|
{
|
var info = new DataBoxInfo()
|
{
|
StockDetailId = stId,
|
BindNo = palletbindInfo.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();
|
}
|
|
|
//sqlString = $"insert into DataBoxInfo select a.Id StockDetailId,b.BindNo,b.BoxNo,b.BoxNo2,b.BoxNo3,b.PalletNo,b.PalletNo2,b.PalletNo3,b.Qty,b.FullQty,b.Status,b.LotNo,b.LotText,b.SkuNo,b.SkuName,a.Standard,a.ProductionTime,a.SupplierLot,a.InspectMark,b.BitBoxMark,a.InspectStatus,a.InspectTime,'0' IsDel,GETDATE() CreateTime,{model.CreateUser} CreateUser,null UpdateTime,null UpdateUser from DataStockDetail a left join BllBoxInfo b on a.SkuNo=b.skuno where b.isdel = '0' and b.Status='2' and b.BindNo = '{palletbind.Id}' and b.PalletNo = '{model.PalletNo}'";
|
|
//Db.Ado.ExecuteCommand(sqlString);
|
|
//sqlString = $"insert into DataBoxInfo select stock.Id StockDetailId,box.BindNo,box.BoxNo,box.BoxNo2,box.BoxNo3,box.PalletNo,box.PalletNo2,box.PalletNo3,box.Qty,box.FullQty,box.Status,box.LotNo,box.LotText,box.SkuNo,box.SkuName,stock.Standard,stock.ProductionTime,stock.SupplierLot,stock.InspectMark,box.BitBoxMark,stock.InspectStatus,stock.InspectTime,'0' IsDel,GETDATE() CreateTime,{model.CreateUser} CreateUser,null UpdateTime,null UpdateUser from DataStockDetail stock left join BllBoxInfo box on stock.PalletNo = box.PalletNo where box.isdel = '0' and box.Status='2' and box.BindNo = '{palletbind.Id}' and stock.WareHouseNo = 'W02' and box.PalletNo = '{model.PalletNo}'";
|
//sqlString = $"select stock.Id StockDetailId,box.BindNo,box.BoxNo,box.BoxNo2,box.BoxNo3,box.PalletNo,box.PalletNo2,box.PalletNo3,box.Qty,box.FullQty,box.Status,box.LotNo,box.LotText,box.SkuNo,box.SkuName,stock.Standard,stock.ProductionTime,stock.SupplierLot,stock.InspectMark,box.BitBoxMark,stock.InspectStatus,stock.InspectTime,'0' IsDel,GETDATE() CreateTime,{model.CreateUser} CreateUser from DataStockDetail stock left join BllBoxInfo box on stock.PalletNo = box.PalletNo where box.isdel = '0' and box.Status='2' and box.BindNo = '{palletbind.Id}' and stock.WareHouseNo = 'W02' and box.PalletNo = '{model.PalletNo}'";
|
////and a.LocatNo = '{model.LocatNo},null UpdateTime,null UpdateUser'
|
|
//var databox = Db.Ado.SqlQuery<DataBoxInfo>(sqlString);
|
|
//foreach (var item in databox)
|
//{
|
// var boxdata = Db.Queryable<DataBoxInfo>().First(b => b.BoxNo == item.BoxNo);
|
|
// if (boxdata == null)
|
// {
|
// Db.Insertable(item).ExecuteCommand();
|
// }
|
// else
|
// {
|
// boxdata.Qty += item.Qty;
|
// Db.Updateable(boxdata).ExecuteCommand();
|
// }
|
//}
|
|
//sqlString = $"insert into DataBoxInfo ";
|
//sqlString += "select BindNo,BoxNo,BoxNo2,BoxNo3,PalletNo,PalletNo2,PalletNo3, ";
|
//sqlString += "Qty,FullQty,'0' as Status,LotNo,LotText,ProductionTime,SupplierLot,";
|
//sqlString += "InspectMark,BitBoxMark,InspectStatus ";
|
//sqlString += $"from BllBoxInfo where isdel = 0 and Status='1' and BindNo = '{bindModel.Id}';";
|
|
#endregion
|
}
|
if (isFinsh)//入库单明细全部完成
|
{
|
//修改入库单总单信息
|
arrival.Status = "2";
|
arrival.UpdateUser = model.CreateUser;
|
arrival.UpdateTime = serverTime;
|
Db.Updateable(arrival).ExecuteCommand();
|
}
|
else
|
{
|
//判断总单状态是否为正在执行
|
if (arrival.Status == "0")
|
{
|
//修改入库单总单信息
|
arrival.Status = "1";
|
arrival.UpdateUser = model.CreateUser;
|
arrival.UpdateTime = serverTime;
|
Db.Updateable(arrival).ExecuteCommand();
|
|
}
|
}
|
#endregion
|
}
|
if (iscount == 1)
|
{
|
//回流入库
|
#region 回流入库
|
|
//不修改库存 入库单据不做更改
|
//修改库存明细信息
|
//修改拣货信息为已完成
|
|
//修改库存明细信息
|
foreach (var item in stockDetail)
|
{
|
item.Status = "0"; //状态更改为待分配
|
item.WareHouseNo = "W02"; //所属仓库
|
item.UpdateTime = serverTime; //修改时间
|
item.UpdateUser = model.CreateUser; //修改人
|
//修改库存明细信息
|
Db.Updateable(item).ExecuteCommand();
|
}
|
//获取拣货信息
|
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; //修改时间
|
//修改拣货信息
|
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正在执行2执行完成
|
OrderType = "0",//0 入库单 1 出库单 2 盘点单 3 移库单
|
Msg = "零箱库的回库任务",
|
};
|
Db.Insertable(exTask).ExecuteCommand();
|
|
//修改组托状态
|
//palletbind.Status = "2"; //2 入库完成
|
//palletbind.UpdateTime = serverTime;
|
//palletbind.UpdateUser = model.CreateUser;
|
//palletbind.CompleteTime = serverTime; //完成时间
|
//palletbind.TaskNo = taskNo; //任务号
|
//Db.Updateable(palletbind).ExecuteCommand();
|
|
#endregion
|
|
#endregion
|
}
|
storageLocat.Status = "1";
|
storageLocat.UpdateTime = serverTime; //修改时间
|
storageLocat.UpdateUser = model.CreateUser; //修改人
|
//修改储位状态
|
Db.Updateable(storageLocat).ExecuteCommand();
|
|
new OperationASNServer().AddLogOperationAsn("PDA模块", "平库入库", model.PalletNo, "完成", $"在PDA上完成单据号为:{model.ASNNo}的托盘码为:{model.PalletNo}的平库入库操作", (int)model.CreateUser);
|
|
Db.CommitTran();
|
|
#region 平库入库注释代码
|
// 改变储位状态; 有货物
|
//sqlString = $"Update SysStorageLocat set Status = '1' where LocatNo = '{model.LocatNo}' and WareHouseNo = 'W01';";
|
//Db.Ado.ExecuteCommand(sqlString);
|
|
//// 改变箱支关系表状态:已入库
|
//sqlString = $"Update BllBoxInfo set Status = '2' where PalletNo = '{model.PalletNo}' and ASNNo = '{model.ASNNo}' and Status = '1';";
|
//Db.Ado.ExecuteCommand(sqlString);
|
|
//// 改变托盘绑定表状态:已入库 完成时间:当前时间
|
//sqlString = $"Update BllPalletBind set LocatNo = '{model.LocatNo}',Status = '2',CompleteTime=GETDATE() where PalletNo = '{model.PalletNo}' and ASNNo = '{model.ASNNo}';";
|
//Db.Ado.ExecuteCommand(sqlString);
|
|
// 改变入库明细表状态:若完成数量和数量相等:执行完成 不相等:正在执行;
|
//foreach (PalletBindVm bindModel in bindModels)
|
//{
|
// // 判断入库明细是否完成
|
// sqlString = $"select count(id) from BllArrivalNoticeDetail where isdel = '0' ";
|
// sqlString += $"and id = '{bindModel.ASNDetailNo}';";/*Qty = CompleteQty + {bindModel.Qty} and*/
|
// int detailNum = Db.Ado.GetInt(sqlString);
|
// if (detailNum > 0)
|
// {
|
// // 改变入库单明细状态和完成时间
|
// sqlString = $"Update BllArrivalNoticeDetail set Status = '2',CompleteTime=GETDATE() ";
|
// sqlString += $"where id = '{bindModel.ASNDetailNo}';";
|
// Db.Ado.ExecuteCommand(sqlString);
|
|
// // 判断入库单总表是否完成
|
// sqlString = $"select count(id) from BllArrivalNoticeDetail where isdel = '0' and Status != '2' ";
|
// sqlString += $"and ASNNo = '{bindModel.ASNNo}' and id !='{bindModel.ASNDetailNo}';";
|
// int asnNum = Db.Ado.GetInt(sqlString);
|
// if (detailNum <= 0)
|
// {
|
// // 改变入库单状态和完成时间 若入库明细表所有状态为执行完毕:执行完毕 否:正在执行;
|
// sqlString = $"Update BllArrivalNotice set CompleteQty = CompleteQty+{bindModel.Qty},Status = '2',CompleteTime=GETDATE() ";
|
// sqlString += $"where ASNNo = '{bindModel.ASNNo}';";
|
// Db.Ado.ExecuteCommand(sqlString);
|
// }
|
// }
|
|
// #region 库存总表
|
|
// // var stockModel = Db.Queryable<DataStock>()
|
// //.First(it => it.SkuNo == bindModel.SkuNo && it.LotNo == bindModel.LotNo
|
// // && it.Standard == bindModel.Standard && it.SupplierLot == bindModel.SupplierLot && it.IsDel == "0");
|
|
// //获取当前入库物料信息
|
// string str = string.Empty;
|
// str += $"select * from BllArrivalNoticeDetail where id in (select ASNDetailNo from BllBoxInfo where ASNNo = '{bindModel.ASNNo}' and PalletNo = '{bindModel.PalletNo}' and Status = '1');";
|
// //string sttr = "select * from BllArrivalNoticeDetail where id in (select ASNDetailNo from BllBoxInfo where ASNNo = 'ASN2023042400002' and PalletNo = 'T2300004' and Status = '1');";
|
// var noticeDetail = Db.Ado.SqlQuery<BllArrivalNoticeDetail>(str);
|
// // 判断当前物料库存表是否已存在
|
// str = $"select * from DataStock where SkuNo = '{noticeDetail[0].SkuNo}' and LotNo = '{noticeDetail[0].LotNo}' and Standard = '{noticeDetail[0].Standard}' and SkuName = '{noticeDetail[0].SkuName}' and IsDel = '0'";
|
// var stockModel = Db.Ado.SqlQuerySingle<DataStock>(str);
|
|
// if (stockModel == null || stockModel.Id == 0)
|
// {
|
// stockModel = new DataStock
|
// {
|
// LotNo = bindModel.LotNo,
|
// LotText = bindModel.LotText,
|
// SupplierLot = bindModel.SupplierLot,
|
// SkuNo = bindModel.SkuNo,
|
// SkuName = bindModel.SkuName,
|
// Qty = (int)bindModel.Qty,
|
// Standard = bindModel.Standard,
|
// CreateUser = (int)model.CreateUser
|
// };
|
// Db.Insertable<DataStock>(stockModel).ExecuteCommand();
|
// }
|
// else
|
// {
|
// sqlString = $"update DataStock set Qty = Qty + {bindModel.Qty}," +
|
// $"UpdateTime = GETDATE(),UpdateUser='{model.CreateUser}' where id = '{stockModel.Id}';";
|
// Db.Ado.ExecuteCommand(sqlString);
|
// }
|
// #endregion
|
|
// #region 库存明细表
|
// // 判断当前托盘是否已存在(拣货回库托盘)
|
// var detailModel = Db.Queryable<DataStockDetail>()
|
// .First(it => it.PalletNo == bindModel.PalletNo && it.LotNo == noticeDetail[0].LotNo && it.SkuNo == noticeDetail[0].SkuNo
|
// && it.Standard == noticeDetail[0].Standard && it.IsDel == "0");
|
// if (detailModel == null || detailModel.Id == 0)
|
// {
|
// // 获取可抽检数量
|
// sqlString = "select sum(qty) from BllBoxInfo where isdel = 0 and ";
|
// sqlString += $"BindNo = '{bindModel.Id}'";
|
// int inspectQty = Db.Ado.GetInt(sqlString);
|
|
// // 添加库存明细表
|
// detailModel = new DataStockDetail()
|
// {
|
// LotNo = noticeDetail[0].LotNo,
|
// LotText = noticeDetail[0].LotText,
|
// SupplierLot = noticeDetail[0].SupplierLot,
|
// SkuNo = noticeDetail[0].SkuNo,
|
// SkuName = noticeDetail[0].SkuName,
|
// Standard = noticeDetail[0].Standard,
|
// Qty = noticeDetail[0].Qty,
|
// LockQty = 0,
|
// FrozenQty = 0,
|
// InspectQty = inspectQty,
|
// ASNNo = bindModel.ASNNo,
|
// ASNDetailNo = (int)bindModel.ASNDetailNo,
|
// WareHouseNo = locatModel.WareHouseNo,
|
// RoadwayNo = locatModel.RoadwayNo,
|
// AreaNo = locatModel.AreaNo,
|
// LocatNo = model.LocatNo,
|
// PalletNo = model.PalletNo,
|
// PalletNo2 = bindModel.PalletNo2,
|
// PalletNo3 = bindModel.PalletNo3,
|
// CompleteTime = serverTime,
|
// ProductionTime = bindModel.ProductionTime,
|
// ExpirationTime = bindModel.ExpirationTime,
|
// Status = "0",
|
// InspectMark = bindModel.InspectMark,
|
// BitPalletMark = bindModel.BitPalletMark,
|
// InspectStatus = bindModel.InspectMark, // 组盘的时候就要默认设定好是否合格
|
// PackagNo = bindModel.PackagNo,
|
// IsBale = bindModel.IsBale,
|
// IsBelt = bindModel.IsBelt,
|
// CreateUser = (int)model.CreateUser
|
// };
|
|
// Db.Insertable<DataStockDetail>(detailModel).ExecuteCommand();
|
// }
|
// else
|
// {
|
// 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
|
|
|
//}
|
#endregion
|
|
|
|
return strMsg;
|
}
|
catch (Exception ex)
|
{
|
Db.RollbackTran();
|
throw ex;
|
}
|
}
|
|
//根据托盘号获取入库单号
|
public string GetASNNoByPalletNo(string palletNo)
|
{
|
try
|
{
|
//入库中
|
var aSNNoList = Db.Ado.SqlQuery<string>($"SELECT DISTINCT ASNNo from BllPalletBind where IsDel=0 and Status=0 and PalletNo='{palletNo}' ").ToList();
|
if (aSNNoList.Count <= 0)
|
{
|
//库外托盘或平库托盘
|
var dataStockList = Db.Ado.SqlQuery<string>($"select DISTINCT PalletNo from DataStockDetail where IsDel=0 and isnull(LocatNo,'') = '' and PalletNo='{palletNo}' ").ToList();
|
if (dataStockList.Count <= 0)
|
{
|
throw new Exception("托盘信息不存在或托盘在立库中!");
|
}
|
return "";
|
}
|
if (aSNNoList.Count > 1)
|
{
|
throw new Exception("同一个托盘号存在多个入库单,请检查!");
|
}
|
return aSNNoList[0];
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
}
|
|
/// <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 == "W04");
|
if (storageLocat == null)
|
{
|
throw new Exception("-1:地码(储位信息)不存在或非空闲状态,请核查!");
|
}
|
|
return strMsg;
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
}
|
|
//根据箱码获取物料、批次、数量等信息
|
public PdaPalletNoCheckDto GetBoxInfoByBoxNo(string boxNo)
|
{
|
try
|
{
|
if (string.IsNullOrWhiteSpace(boxNo))
|
{
|
throw new Exception("箱码不能为空");
|
}
|
|
var info = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == boxNo)
|
.GroupBy(m => new { m.BoxNo, m.SkuNo, m.SkuName, m.LotNo }).Select(a => new PdaPalletNoCheckDto
|
{
|
BoxNo = a.BoxNo,
|
SkuNo = a.SkuNo,
|
SkuName = a.SkuName,
|
LotNo = a.LotNo,
|
Qty = SqlFunc.AggregateSum(a.Qty)
|
}).ToList();
|
if (info.Count > 1)
|
{
|
throw new Exception("当前箱码查询出多条物料或批次信息,请核实");
|
}
|
|
return info.FirstOrDefault();
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
//拼托入库
|
public void CompleteInStockLing(PdaLingAsnVm model, int userId)
|
{
|
try
|
{
|
if (string.IsNullOrWhiteSpace(model.AsnNo))
|
{
|
throw new Exception("-1:盘点单据不能为空!");
|
}
|
if (model.AsnDetailId == null || model.AsnDetailId == 0)
|
{
|
throw new Exception("-1:物料批次不能为空!");
|
}
|
if (string.IsNullOrWhiteSpace(model.PalletNo))
|
{
|
throw new Exception("-1:托盘条码不能为空!");
|
}
|
if (string.IsNullOrWhiteSpace(model.BoxNo))
|
{
|
throw new Exception("-1:箱码不能为空!");
|
}
|
//获取当前时间
|
DateTime serverTime = Db.Ado.GetDateTime("select GETDATE();");
|
|
Db.BeginTran();//开启事务
|
|
#region 箱码信息
|
//获取箱码信息
|
string boxstr = $"select * from BLLBoxInfo where IsDel = '0' and BoxNo = '{model.BoxNo}'";
|
List<BllBoxInfo> boxinfo = Db.Ado.SqlQuery<BllBoxInfo>(boxstr).ToList();
|
//验证箱码信息是否存在
|
if (boxinfo.Count <= 0)
|
{
|
throw new Exception("-1:箱码信息不存在,请核查!");
|
}
|
decimal bNum = 0;//数量
|
//验证箱码是否已绑定托盘
|
foreach (var item in boxinfo)
|
{
|
if (!string.IsNullOrEmpty(item.PalletNo))
|
{
|
throw new Exception("-1:该箱码已绑定其他托盘,请先解绑托盘!");
|
}
|
bNum += item.Qty;
|
}
|
if (bNum == boxinfo[0].FullQty)
|
{
|
throw new Exception("-1:该箱子不是零箱,不能入零箱库!");
|
}
|
#endregion
|
|
#region 单据信息
|
//获取入库单据总单
|
var isFinsh = true;
|
var arrival = new BllArrivalNotice();
|
arrival = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.AsnNo);
|
//验证入库单总单是否关闭
|
if (arrival == null)
|
{
|
throw new Exception("-1:入库单总单为空,请核查!");
|
}
|
//判断入库单总单是否为已关闭
|
if (arrival.Status == "3")
|
{
|
throw new Exception("-1:入库单总单已关闭,请核查!");
|
}
|
// 验证入库单明细是否存在
|
var arrivalnotice = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == model.AsnDetailId && m.ASNNo == model.AsnNo);
|
if (arrivalnotice == null)
|
{
|
throw new Exception("-1:当前物料及批次与单据无关联,请核实!");
|
}
|
arrivalnotice.FactQty += bNum;
|
arrivalnotice.CompleteQty += bNum;
|
//判断入库数量增加后是否大于等于单据数量
|
if (arrivalnotice.CompleteQty >= arrivalnotice.Qty)
|
{
|
arrivalnotice.Status = "2";
|
arrivalnotice.CompleteTime = serverTime;
|
}
|
else
|
{
|
arrivalnotice.Status = "1";
|
|
isFinsh = false;
|
}
|
arrivalnotice.UpdateUser = userId;
|
arrivalnotice.UpdateTime = serverTime;
|
Db.Updateable(arrivalnotice).ExecuteCommand();
|
|
var arrivalnoticeList = Db.Queryable<BllArrivalNoticeDetail>().Where(m => m.IsDel == "0" && m.ASNNo == model.AsnNo).ToList();
|
foreach (var item in arrivalnoticeList)
|
{
|
if (item.CompleteQty < item.Qty)
|
{
|
isFinsh = false;
|
break;
|
}
|
}
|
if (isFinsh)
|
{
|
//修改入库单总单信息
|
arrival.Status = "2";
|
arrival.CompleteTime = serverTime;
|
arrival.UpdateUser = userId;
|
arrival.UpdateTime = serverTime;
|
Db.Updateable(arrival).ExecuteCommand();
|
}
|
else
|
{
|
//判断总单状态是否为正在执行
|
if (arrival.Status == "0")
|
{
|
//修改入库单总单信息
|
arrival.Status = "1";
|
arrival.UpdateUser = userId;
|
arrival.UpdateTime = serverTime;
|
Db.Updateable(arrival).ExecuteCommand();
|
}
|
}
|
#endregion
|
|
#region 托盘信息
|
//托盘是否存在
|
var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
|
if (pallet == null)
|
{
|
throw new Exception("-1:未查询到托盘信息,请核实!");
|
}
|
if (pallet.Status == "0")
|
{
|
// 更改托盘使用状态
|
var sqlStr = $"update SysPallets set Status = '1' where PalletNo = '{model.PalletNo}';";
|
Db.Ado.ExecuteCommand(sqlStr);
|
}
|
|
var palletStockDetail = Db.Ado.SqlQuery<DataStock>($"select * from DataStockDetail where PalletNo='{model.PalletNo}' and ISNULL(LocatNo,'')<>''").ToList();
|
if (palletStockDetail != null && palletStockDetail.Count > 0)
|
{
|
throw new Exception("-1:托盘在立库中不允许拼托,请核查!");
|
}
|
#endregion
|
|
#region 物料信息
|
var sku = Db.Queryable<SysMaterials>().First(s => s.SkuNo == arrivalnotice.SkuNo && s.IsDel == "0" && s.SkuName == arrivalnotice.SkuName);
|
//判断物料信息是否为空
|
if (sku == null)
|
{
|
throw new Exception("-1:物料信息为空,请核查!");
|
}
|
#endregion
|
|
#region 绑定托盘
|
var bindId = 0;
|
var bind = new BllPalletBind
|
{
|
ASNNo = model.AsnNo,
|
ASNDetailNo = (int)model.AsnDetailId,
|
PalletNo = model.PalletNo,
|
PalletNo2 = "",
|
PalletNo3 = "",
|
Qty = bNum,
|
FullQty = 0,//整托数量,托盘上可能放的是不同包装的箱子
|
Status = "2",
|
CompleteTime = serverTime,
|
Type = "0",
|
LotNo = arrivalnotice.LotNo,
|
LotText = arrivalnotice.LotText,
|
SupplierLot = "",
|
InspectMark = "0",
|
BitPalletMark = "1",
|
IsBale = "0",
|
IsBelt = "0",
|
CreateUser = userId
|
};
|
// 插入托盘绑定表
|
bindId = Db.Insertable(bind).ExecuteReturnIdentity();
|
#endregion
|
|
#region 库存总表
|
// 判断当前物料库存表是否已存在
|
string str = $"select * from DataStock where SkuNo = '{arrivalnotice.SkuNo}' and LotNo = '{arrivalnotice.LotNo}' and Standard = '{arrivalnotice.Standard}' and SkuName = '{arrivalnotice.SkuName}' and IsDel = '0'";
|
var stockModel = Db.Ado.SqlQuerySingle<DataStock>(str);
|
|
if (stockModel == null || stockModel.Id == 0)
|
{
|
stockModel = new DataStock
|
{
|
LotNo = arrivalnotice.LotNo,
|
LotText = arrivalnotice.LotText,
|
SupplierLot = arrivalnotice.SupplierLot,
|
SkuNo = arrivalnotice.SkuNo,
|
SkuName = arrivalnotice.SkuName,
|
Qty = bNum,
|
Standard = arrivalnotice.Standard,
|
CreateUser = userId,
|
CreateTime = serverTime
|
};
|
Db.Insertable<DataStock>(stockModel).ExecuteCommand();
|
}
|
else
|
{
|
string sqlString = $"update DataStock set Qty = Qty + {bNum}," +
|
$"UpdateTime = GETDATE(),UpdateUser='{userId}' where id = '{stockModel.Id}';";
|
Db.Ado.ExecuteCommand(sqlString);
|
}
|
#endregion
|
|
#region 库存明细表
|
var boxinfoItem = boxinfo.First();
|
var detailModel = Db.Queryable<DataStockDetail>().First(it => it.PalletNo == model.PalletNo && it.LotNo == arrivalnotice.LotNo
|
&& it.SkuNo == arrivalnotice.SkuNo && it.Standard == arrivalnotice.Standard && it.IsDel == "0");
|
var stId = 0;
|
if (detailModel == null || detailModel.Id == 0)
|
{
|
// 添加库存明细表
|
detailModel = new DataStockDetail()
|
{
|
LotNo = arrivalnotice.LotNo,
|
LotText = arrivalnotice.LotText,
|
SupplierLot = arrivalnotice.SupplierLot,
|
SkuNo = arrivalnotice.SkuNo,
|
SkuName = arrivalnotice.SkuName,
|
Standard = arrivalnotice.Standard,
|
Qty = bNum,
|
LockQty = 0,
|
FrozenQty = 0,
|
InspectQty = bNum,
|
ASNNo = arrivalnotice.ASNNo,
|
ASNDetailNo = (int)bind.ASNDetailNo,
|
WareHouseNo = "W02",
|
RoadwayNo = "",
|
AreaNo = "",
|
LocatNo = "",
|
PalletNo = model.PalletNo,
|
PalletNo2 = "",
|
PalletNo3 = "",
|
CompleteTime = serverTime,
|
ProductionTime = boxinfoItem.ProductionTime,
|
ExpirationTime = boxinfoItem.ProductionTime.Value.AddDays((int)sku.Warranty),//过期时间
|
Status = "0",
|
InspectMark = boxinfoItem.InspectMark,
|
BitPalletMark = "1",
|
InspectStatus = sku.IsInspect,// 组盘的时候就要默认设定好是否合格
|
PackagNo = sku.PackagNo,
|
IsBale = null,
|
IsBelt = null,
|
CreateUser = userId,
|
CreateTime = serverTime
|
};
|
stId = Db.Insertable<DataStockDetail>(detailModel).ExecuteReturnIdentity();
|
}
|
else
|
{
|
stId = detailModel.Id;
|
detailModel.Qty += bNum;
|
detailModel.InspectQty += bNum;
|
detailModel.LocatNo = "";
|
detailModel.UpdateTime = serverTime;
|
detailModel.UpdateUser = userId;
|
// 变更储位地址
|
Db.Updateable<DataStockDetail>(detailModel).UpdateColumns(it => new { it.Qty, it.InspectQty, it.LocatNo, it.UpdateTime, it.UpdateUser }).ExecuteCommand();
|
}
|
#endregion
|
|
#region 库存箱支明细表
|
var comTime = DateTime.Now;
|
foreach (var item in boxinfo)
|
{
|
// 维护箱支关系表
|
string sqlString = $"Update BLLBoxInfo set ASNNo='{model.AsnNo}',ASNDetailNo='{model.AsnDetailId}',BindNo='{bindId}',PalletNo='{model.PalletNo}',Status='2' where IsDel = '0' and BoxNo = '{model.BoxNo}'";
|
Db.Ado.ExecuteCommand(sqlString);
|
// 插入新组的箱支信息
|
var info = new DataBoxInfo()
|
{
|
StockDetailId = stId,
|
BindNo = bindId,
|
BoxNo = item.BoxNo,
|
BoxNo2 = item.BoxNo2,
|
BoxNo3 = item.BoxNo3,
|
PalletNo = model.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,
|
|
IsDel = "0",
|
CreateUser = 0,
|
CreateTime = comTime
|
};
|
Db.Insertable(info).ExecuteCommand();
|
}
|
#endregion
|
|
new OperationASNServer().AddLogOperationAsn("PDA模块", "零箱入库", model.PalletNo, "完成", $"在PDA上完成单据号为:{model.AsnNo}的托盘码为:{model.PalletNo}的零箱入库操作", userId);
|
|
Db.CommitTran();
|
|
}
|
catch (Exception ex)
|
{
|
Db.Ado.RollbackTran();//事务回滚
|
throw ex;
|
}
|
}
|
|
#region 产品组托
|
|
|
|
//根据物料获取是否存在包装信息
|
public string BySkuNoGetPackInfo(string skuNo)
|
{
|
try
|
{
|
//获取物料信息
|
var sku = Db.Queryable<SysMaterials>().First(a => a.IsDel == "0" && a.SkuNo == skuNo);
|
//判断物料信息是否为空
|
if (sku.IsPasteCode == "1")
|
{
|
return "贴标";
|
}
|
else
|
{
|
return "不贴标";
|
}
|
}
|
catch (Exception ex)
|
{
|
return ex.Message;
|
}
|
}
|
|
/// <summary>
|
/// 绑定托盘
|
/// </summary>
|
/// <param name="model"></param>
|
/// <param name="userId"></param>
|
/// <param name="origin"></param>
|
public void BindPallet(PdaPalletBindVm model, int userId, string origin)
|
{
|
try
|
{
|
#region 判断
|
|
//0:成品入库 1:采购入库 2:中间品入库 3:退货入库 4:车间余料入库 5:其它入库 6:代储入库 7:寄存入库
|
var TypeLot = "1, 2, 5, 6, 7";
|
|
if (string.IsNullOrEmpty(model.AsnNo))
|
{
|
throw new Exception("-1:单据号不可为空!");
|
}
|
if (model.AsnDetailId == null || model.AsnDetailId == 0)
|
{
|
throw new Exception("-1:物料不可为空!");
|
}
|
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" && notice.Status != "2")
|
{
|
throw new Exception("-1:该单据已关单!");
|
}
|
if (string.IsNullOrEmpty(model.LotNo))
|
{
|
//判断是否为不限制批次单据
|
if (!TypeLot.Contains(notice.Type))
|
{
|
throw new Exception("-1:物料批次不可为空!");
|
}
|
|
}
|
else
|
{
|
//从物料名称-批次中取出批次
|
int indexOfDash = model.LotNo.IndexOf("-");
|
if (indexOfDash != -1)
|
{
|
model.LotNo = model.LotNo.Substring(indexOfDash + 1);
|
}
|
else
|
{
|
model.LotNo = "";
|
}
|
}
|
//判断物料数量是否为0 为0判断箱码信息 不为0继续
|
if (model.TableType == 0)
|
{
|
if (string.IsNullOrEmpty(model.BoxNo))
|
{
|
throw new Exception("-1:箱码信息不可为空!");
|
}
|
|
if (model.IsContinue == "1")
|
{
|
if (string.IsNullOrWhiteSpace(model.TailBoxNo))
|
{
|
throw new Exception("-1:开启连续组托时,尾箱码信息不可为空!");
|
}
|
|
}
|
}
|
int isTextTable = model.TableType;
|
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();
|
|
//托盘是否存在
|
var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
|
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));
|
if (detail == null)
|
{
|
throw new Exception("-1:当前物料及批次与单据无关联,请核实!");
|
}
|
#region 包装
|
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);
|
|
var pNum = 0;//托盘物品数量
|
var bNum = 0;//箱码物品数量
|
|
//判断是否为寄存物料
|
if (isDeposit == 0 && isTextTable == 0)
|
{
|
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
|
|
#region 验证是否允许立库同托盘不同物料入库或同托盘同物料不同批次入库
|
var palletBind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNNo == model.AsnNo && m.PalletNo == model.PalletNo && m.ASNDetailNo != model.AsnDetailId);
|
if (palletBind != null)
|
{
|
var box = Db.Queryable<BllBoxInfo>().First(m => m.IsDel == "0" && m.BindNo == palletBind.Id && m.BitBoxMark == "0");
|
if (box != null && (box.SkuNo != detail.SkuNo || box.LotNo != detail.LotNo))
|
{
|
var funSetting = Db.Queryable<SysFunSetting>().First(a => a.IsDel == "0" && a.FunSetNo == "Fun045");
|
if (funSetting == null || funSetting.IsEnable == "OFF")
|
{
|
throw new Exception($"不允许立库同托盘不同物料入库或同托盘不同批次入库!");
|
}
|
}
|
}
|
#endregion
|
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)
|
{
|
bind = new BllPalletBind
|
{
|
ASNNo = model.AsnNo,
|
ASNDetailNo = (int)model.AsnDetailId,
|
PalletNo = model.PalletNo,
|
PalletNo2 = "",
|
PalletNo3 = "",
|
Qty = model.SkuQty,
|
FullQty = pNum,
|
Status = "0",
|
Type = "0",
|
LotNo = model.LotNo,
|
LotText = detail.LotText,
|
SupplierLot = detail.SupplierLot,
|
InspectMark = "0", //是否取样托盘 后期业务开发时 接口传值需添加对应字段判断
|
SamplingQty = 0, //取样数量 后期业务开发时 接口传值需添加对应字段判断
|
BitPalletMark = "1",
|
IsBale = "0",
|
IsBelt = "0",
|
CreateUser = userId,
|
Demo = model.Demo,
|
|
};
|
//if (model.TableType == 0 && isDeposit == 0 && isTextTable == 0) 不太理解这段代码的含义
|
//{
|
// throw new Exception($"绑定失败,{model.PalletNo}托盘绑定数量大于该物品托盘包装数量!");
|
//}
|
// 插入托盘绑定表
|
bindId = Db.Insertable(bind).ExecuteReturnIdentity();
|
}
|
else
|
{
|
if (bind.Status != "0")
|
{
|
throw new Exception("-1:当前托盘正在执行中,绑定失败,请核实!");
|
}
|
bindId = bind.Id;
|
bind.Qty += model.SkuQty;
|
}
|
|
#region 箱码信息
|
var msgStr = $"箱号为{model.BoxNo}";
|
var boxInfoList = new List<BllBoxInfo>();
|
if (model.SkuQty == 0)
|
{
|
//首箱
|
var boxInfo = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo && m.Status == "0").ToList();
|
if (boxInfo.Count == 0)
|
{
|
throw new Exception("-1:箱码信息不存在!");
|
}
|
boxInfoList.AddRange(boxInfo);
|
//是否连续组托
|
if (model.IsContinue == "1")
|
{
|
//尾箱
|
var boxInfo2 = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.TailBoxNo && m.Status == "0").ToList();
|
if (boxInfo2.Count == 0)
|
{
|
throw new Exception("-1:尾箱码信息不存在!");
|
}
|
boxInfoList.AddRange(boxInfo2);
|
var sql = $"select * from BllBoxInfo where IsDel = '0' and Status = '0' and boxNo>'{model.BoxNo}' and boxNo<'{model.TailBoxNo}'; ";
|
var list = Db.Ado.SqlQuery<BllBoxInfo>(sql);
|
boxInfoList.AddRange(list);
|
msgStr += $"尾箱号为{model.TailBoxNo}";
|
}
|
}
|
#endregion
|
|
// 更改箱支关系表
|
decimal factQty = 0.00m;//托盘总数量
|
//成品组托
|
if (isTextTable == 0)
|
{
|
var boxGroup = boxInfoList.GroupBy(m => m.BoxNo).ToList();
|
foreach (var g in boxGroup)
|
{
|
decimal boxFullQty = 0;//箱内总数量
|
foreach (var box in g)
|
{
|
if (box.BindNo != null && box.BindNo != 0)
|
{
|
continue;
|
}
|
//箱内物料批次与单据明细不符合
|
if (box.SkuNo != detail.SkuNo || box.LotNo != model.LotNo)
|
{
|
throw new Exception($"-1:{box.BoxNo}箱内物料及批次与单据不一致,请核实!");
|
}
|
|
box.ASNNo = model.AsnNo;
|
box.ASNDetailNo = model.AsnDetailId;
|
box.BindNo = bindId;
|
box.PalletNo = model.PalletNo;
|
box.Status = "1";
|
box.InspectMark = "0"; //是否取样托盘 后期业务开发时 接口传值需添加对应字段判断
|
box.SamplingQty = 0; //取样数量 后期业务开发时 接口传值需添加对应字段判断
|
box.CompleteTime = DateTime.Now;
|
box.UpdateTime = DateTime.Now;
|
box.UpdateUser = userId;
|
|
factQty += box.Qty;
|
boxFullQty += box.Qty;
|
}
|
if (boxFullQty > bNum)
|
{
|
throw new Exception($"绑定失败,{g.Key}箱码绑定数量大于该物品包装数量!");
|
}
|
}
|
Db.Updateable(boxInfoList).ExecuteCommand();
|
|
// 更新托盘绑定表
|
bind.Qty += factQty;
|
}
|
if (bind.FullQty < bind.Qty && isDeposit == 0 && isTextTable == 0)
|
{
|
throw new Exception("托盘绑定数量已超出该物料包装数量");
|
}
|
|
if (bind.FullQty == bind.Qty)
|
{
|
bind.BitPalletMark = "0";
|
}
|
if (bind.Qty > pNum && isDeposit == 0 && isTextTable == 0)
|
{
|
throw new Exception($"绑定失败,{bind.PalletNo}托盘绑定数量大于该物品托盘包装数量!");
|
}
|
Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand();
|
|
// 更改入库单明细已组数量和是否取样标识
|
var sqlString = string.Empty;
|
if (factQty == 0)
|
{
|
sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{model.SkuQty}' ";
|
//if (true) //后期业务开发时 接口传值改为判断是否取样
|
//{
|
// sqlString += $",IsSampling = '1' ";
|
//}
|
sqlString += $"where id = '{model.AsnDetailId}';";
|
}
|
else
|
{
|
sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{factQty}' ";
|
//if (true) //后期业务开发时 接口传值改为判断是否取样
|
//{
|
// sqlString += $",IsSampling = '1' ";
|
//}
|
sqlString += $"where id = '{model.AsnDetailId}';";
|
}
|
|
Db.Ado.ExecuteCommand(sqlString);
|
|
// 更改入库单及入库明细状态
|
if (detail.Status == "0")
|
{
|
var sqlString2 = string.Empty;
|
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);
|
}
|
|
// 更改托盘使用状态
|
var sqlStr = $"update SysPallets set Status = '1' where PalletNo = '{model.PalletNo}';";
|
//添加托盘记录表数据
|
sqlStr += $"insert into LogPalletTrack values('{model.PalletNo}','{model.AsnNo}','组盘','0',getDate(),{userId},NULL,NULL);";
|
Db.Ado.ExecuteCommand(sqlStr);
|
new OperationASNServer().AddLogOperationAsn("PDA模块", "托盘绑定", model.AsnNo, "添加", $"添加了托盘码为:{model.PalletNo}、{msgStr}的组盘信息", userId);
|
|
Db.CommitTran();
|
}
|
catch (Exception ex)
|
{
|
Db.RollbackTran();
|
throw ex;
|
}
|
}
|
|
//JC23绑定物料托盘 liudl del 此方法已作废
|
public void BindPalletByJc23(PdaPalletBindVm model, int userId, string origin)
|
{
|
try
|
{
|
#region 判断
|
|
//0:成品入库 1:采购入库 3:退货入库 4:车间余料入库 5:其它入库 6:代储入库
|
var TypeLot = "1, 5, 6";
|
|
if (string.IsNullOrEmpty(model.AsnNo))
|
{
|
throw new Exception("单据号不可为空!");
|
}
|
if (model.AsnDetailId == null || model.AsnDetailId == 0)
|
{
|
throw new Exception("物料不可为空!");
|
}
|
if (string.IsNullOrEmpty(model.PalletNo))
|
{
|
throw new Exception("托盘号不可为空!");
|
}
|
|
//根据单据号获取入库单总单
|
var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.AsnNo);
|
if (notice.Status != "0" && notice.Status != "1" && notice.Status != "2")
|
{
|
throw new Exception("该单据已关单!");
|
}
|
if (string.IsNullOrEmpty(model.LotNo))
|
{
|
//判断是否为不限制批次单据
|
if (!TypeLot.Contains(notice.Type))
|
{
|
throw new Exception("物料批次不可为空!");
|
}
|
|
}
|
else
|
{
|
//从物料名称-批次中取出批次
|
int indexOfDash = model.LotNo.IndexOf("-");
|
if (indexOfDash != -1)
|
{
|
model.LotNo = model.LotNo.Substring(indexOfDash + 1);
|
}
|
else
|
{
|
model.LotNo = "";
|
}
|
}
|
//判断绑定类型是否为0 为0判断箱码信息 不为0继续
|
if (model.TableType == 0)
|
{
|
if (string.IsNullOrEmpty(model.BoxNo))
|
{
|
throw new Exception("箱码信息不可为空!");
|
}
|
|
if (model.IsContinue == "1")
|
{
|
if (string.IsNullOrWhiteSpace(model.TailBoxNo))
|
{
|
throw new Exception("开启连续组托时,尾箱码信息不可为空!");
|
}
|
|
}
|
}
|
|
|
int isTextTable = model.TableType;
|
|
#endregion
|
|
Db.BeginTran();
|
|
//托盘是否存在
|
var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
|
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));
|
if (detail == null)
|
{
|
throw new Exception("当前物料及批次与单据无关联,请核实!");
|
}
|
#region 包装
|
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);
|
|
var pNum = 0;//托盘物品数量
|
var bNum = 0;//箱码物品数量
|
|
//判断是否标签页判断包装
|
if (isTextTable == 0)
|
{
|
if (pack == null)
|
{
|
throw new Exception("获取物料包装失败,请核实!");
|
}
|
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
|
|
#region 验证是否允许立库同托盘不同物料入库或同托盘同物料不同批次入库
|
var palletBind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNNo == model.AsnNo && m.PalletNo == model.PalletNo && m.ASNDetailNo != model.AsnDetailId);
|
if (palletBind != null)
|
{
|
var box = Db.Queryable<BllBoxInfo>().First(m => m.IsDel == "0" && m.BindNo == palletBind.Id && m.BitBoxMark == "0");
|
if (box != null && (box.SkuNo != detail.SkuNo || !detail.LotNo.Contains(box.LotNo)))
|
{
|
var funSetting = Db.Queryable<SysFunSetting>().First(a => a.IsDel == "0" && a.FunSetNo == "Fun045");
|
if (funSetting == null || funSetting.IsEnable == "OFF")
|
{
|
throw new Exception($"不允许立库同托盘不同物料入库或同托盘不同批次入库!");
|
}
|
}
|
}
|
#endregion
|
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)
|
{
|
bind = new BllPalletBind
|
{
|
ASNNo = model.AsnNo,
|
ASNDetailNo = (int)model.AsnDetailId,
|
PalletNo = model.PalletNo,
|
PalletNo2 = "",
|
PalletNo3 = "",
|
Qty = model.SkuQty,
|
FullQty = pNum,
|
Status = "0",
|
Type = "0",
|
LotNo = model.LotNo,
|
LotText = detail.LotText,
|
SupplierLot = detail.SupplierLot,
|
//InspectMark = model.IsSample, //是否取样托盘 后期业务开发时 接口传值需添加对应字段判断
|
//SamplingQty = 0, //取样数量 后期业务开发时 接口传值需添加对应字段判断
|
BitPalletMark = "1",
|
IsBale = "0",
|
IsBelt = "0",
|
CreateUser = userId,
|
Demo = model.Demo,
|
|
};
|
// 插入托盘绑定表
|
bindId = Db.Insertable(bind).ExecuteReturnIdentity();
|
}
|
else
|
{
|
if (bind.Status != "0")
|
{
|
throw new Exception("-1:当前托盘正在执行中,绑定失败,请核实!");
|
}
|
bindId = bind.Id;
|
bind.Qty += model.SkuQty;
|
}
|
|
#region 箱码信息
|
var msgStr = $"箱号为{model.BoxNo}";
|
var boxInfoList = new List<BllBoxInfo>();
|
if (isTextTable == 0) //判断是否是标签页组盘
|
{
|
//首箱
|
var boxInfo = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo && m.Status == "0").ToList();
|
if (boxInfo.Count == 0)
|
{
|
throw new Exception("箱码信息不存在!");
|
}
|
boxInfoList.AddRange(boxInfo);
|
//是否连续组托
|
if (model.IsContinue == "1")
|
{
|
//尾箱
|
var boxInfo2 = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.TailBoxNo && m.Status == "0").ToList();
|
if (boxInfo2.Count == 0)
|
{
|
throw new Exception("尾箱码信息不存在!");
|
}
|
boxInfoList.AddRange(boxInfo2);
|
var sql = $"select * from BllBoxInfo where IsDel = '0' and Status = '0' and boxNo>'{model.BoxNo}' and boxNo<'{model.TailBoxNo}'; ";
|
var list = Db.Ado.SqlQuery<BllBoxInfo>(sql);
|
boxInfoList.AddRange(list);
|
msgStr += $"尾箱号为{model.TailBoxNo}";
|
}
|
}
|
#endregion
|
|
// 更改箱支关系表
|
decimal factQty = 0.00m;//托盘总数量
|
var isSample = "0";//是否取样
|
var sampleQty = 0m;//取样数量
|
|
//标签组托
|
if (isTextTable == 0)
|
{
|
var boxGroup = boxInfoList.GroupBy(m => m.BoxNo).ToList();
|
foreach (var g in boxGroup)
|
{
|
decimal boxFullQty = 0;//箱内总数量
|
foreach (var box in g)
|
{
|
if (box.BindNo != null && box.BindNo != 0)
|
{
|
continue;
|
}
|
//箱内物料批次与单据明细不符合
|
if (box.SkuNo != detail.SkuNo || box.LotNo != model.LotNo)
|
{
|
throw new Exception($"-1:{box.BoxNo}箱内物料及批次与单据不一致,请核实!");
|
}
|
|
box.ASNNo = model.AsnNo;
|
box.ASNDetailNo = model.AsnDetailId;
|
box.BindNo = bindId;
|
box.PalletNo = model.PalletNo;
|
box.Status = "1";
|
//box.InspectMark = model.IsSample; //是否取样托盘 后期业务开发时 接口传值需添加对应字段判断
|
//box.SamplingQty = 0; //取样数量 后期业务开发时 接口传值需添加对应字段判断
|
box.CompleteTime = DateTime.Now;
|
box.UpdateTime = DateTime.Now;
|
box.UpdateUser = userId;
|
|
//box.Qty = box.Qty;
|
//box.BitBoxMark = box.Qty == box.FullQty ? "0" : "1";
|
|
factQty += box.Qty;
|
boxFullQty += box.Qty;
|
if (box.InspectMark == "1") //判断是否取样
|
{
|
isSample = "1";
|
sampleQty += (decimal)box.SamplingQty;
|
}
|
}
|
if (boxFullQty > bNum)
|
{
|
throw new Exception($"绑定失败,{g.Key}箱码绑定数量大于该物品包装数量!");
|
}
|
}
|
Db.Updateable(boxInfoList).ExecuteCommand();
|
|
// 更新托盘绑定表
|
bind.Qty += factQty;
|
}
|
if (bind.FullQty < bind.Qty && isTextTable == 0)
|
{
|
throw new Exception("托盘绑定数量已超出该物料包装数量");
|
}
|
|
if (bind.FullQty == bind.Qty)
|
{
|
bind.BitPalletMark = "0";
|
}
|
if (bind.Qty > pNum && isTextTable == 0)
|
{
|
throw new Exception($"绑定失败,{bind.PalletNo}托盘绑定数量大于该物品托盘包装数量!");
|
}
|
|
if (isSample == "1")
|
{
|
bind.InspectMark = "1";
|
bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty;
|
}
|
Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand();
|
|
// 更改入库单明细已组数量和是否取样标识
|
var sqlString = string.Empty;
|
if (isTextTable == 1)
|
{
|
sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{model.SkuQty}' ";
|
if (isSample == "1") //后期业务开发时 接口传值改为判断是否取样
|
{
|
sqlString += $",IsSampling = '1' ";
|
}
|
sqlString += $"where id = '{model.AsnDetailId}';";
|
}
|
else
|
{
|
sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{factQty}' ";
|
if (isSample == "1") //后期业务开发时 接口传值改为判断是否取样
|
{
|
sqlString += $",IsSampling = '1' ";
|
}
|
sqlString += $"where id = '{model.AsnDetailId}';";
|
}
|
|
Db.Ado.ExecuteCommand(sqlString);
|
|
// 更改入库单及入库明细状态
|
if (detail.Status == "0")
|
{
|
var sqlString2 = string.Empty;
|
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);
|
}
|
|
// 更改托盘使用状态
|
var sqlStr = $"update SysPallets set Status = '1' where PalletNo = '{model.PalletNo}';";
|
//添加托盘记录表数据
|
sqlStr += $"insert into LogPalletTrack values('{model.PalletNo}','{model.AsnNo}','组盘','0',getDate(),{userId},NULL,NULL);";
|
Db.Ado.ExecuteCommand(sqlStr);
|
new OperationASNServer().AddLogOperationAsn("PDA模块", "托盘绑定", model.AsnNo, "添加", $"添加了托盘码为:{model.PalletNo}、{msgStr}的组盘信息", userId);
|
|
Db.CommitTran();
|
}
|
catch (Exception e)
|
{
|
Db.RollbackTran();
|
throw new Exception(e.Message);
|
}
|
}
|
|
//JC23绑定物料托盘即增加库存
|
public void BindPalletStock(PdaPalletBindVm model, int userId, string origin)
|
{
|
try
|
{
|
#region 判断
|
|
//0:成品入库 1:采购入库 3:退货入库 4:车间余料入库 5:其它入库 6:代储入库
|
var TypeLot = "5, 6";
|
|
if (string.IsNullOrEmpty(model.AsnNo))
|
{
|
throw new Exception("单据号不可为空!");
|
}
|
if (model.AsnDetailId == null || model.AsnDetailId == 0)
|
{
|
throw new Exception("物料不可为空!");
|
}
|
if (string.IsNullOrEmpty(model.PalletNo))
|
{
|
throw new Exception("托盘号不可为空!");
|
}
|
if (model.SkuQty < 0)
|
{
|
throw new Exception("物料数量不能小于0!");
|
}
|
//根据单据号获取入库单总单
|
var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.AsnNo);
|
if (notice.Status != "0" && notice.Status != "1" && notice.Status != "2")
|
{
|
throw new Exception("该单据已关单!");
|
}
|
|
if (string.IsNullOrEmpty(model.LotNo))
|
{
|
throw new Exception("物料不为空!");
|
}
|
else
|
{
|
//从物料名称-批次中取出批次
|
int indexOfDash = model.LotNo.IndexOf("-");
|
if (indexOfDash != -1)
|
{
|
model.LotNo = model.LotNo.Substring(indexOfDash + 1);
|
}
|
else
|
{
|
if (!TypeLot.Contains(notice.Type))
|
{
|
throw new Exception("物料批次不可为空!");
|
}
|
|
model.LotNo = "";
|
}
|
}
|
|
//判断绑定类型是否为0 为0判断箱码信息 不为0继续
|
if (model.TableType == 0)
|
{
|
if (string.IsNullOrEmpty(model.BoxNo))
|
{
|
throw new Exception("箱码信息不可为空!");
|
}
|
|
if (model.IsContinue == "1")
|
{
|
if (string.IsNullOrWhiteSpace(model.TailBoxNo))
|
{
|
throw new Exception("开启连续组托时,尾箱码信息不可为空!");
|
}
|
}
|
}
|
|
int isTextTable = model.TableType;
|
#endregion
|
|
Db.BeginTran();
|
|
var comTime = DateTime.Now;
|
|
//托盘是否存在
|
var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
|
if (pallet == null)
|
{
|
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));
|
if (detail == 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("该托盘已有储位信息,请核实!");
|
}
|
if (stockDetail != null && (stockDetail.SkuNo != detail.SkuNo || stockDetail.LotNo != model.LotNo))
|
{
|
throw new Exception("该托盘在库存已有其它物料批次信息,请核实!");
|
}
|
|
#region 包装
|
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 == detail.PackagNo); // liudl 由Sku包装编号变更为入库单明细包装编号
|
|
var pNum = 0;//托盘物品数量
|
var bNum = 0;//箱码物品数量
|
|
//判断是否标签页判断包装
|
//if (isTextTable == 0)
|
//{
|
if (pack == null)
|
{
|
throw new Exception("获取物料包装失败,请核实!");
|
}
|
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
|
|
#region 验证是否允许立库同托盘不同物料入库或同托盘同物料不同批次入库
|
var palletBind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNNo == model.AsnNo && m.PalletNo == model.PalletNo && m.ASNDetailNo != model.AsnDetailId);
|
if (palletBind != null)
|
{
|
var box = Db.Queryable<BllBoxInfo>().First(m => m.IsDel == "0" && m.BindNo == palletBind.Id && m.BitBoxMark == "0");
|
if (box != null && (box.SkuNo != detail.SkuNo || !detail.LotNo.Contains(box.LotNo)))
|
{
|
var funSetting = Db.Queryable<SysFunSetting>().First(a => a.IsDel == "0" && a.FunSetNo == "Fun045");
|
if (funSetting == null || funSetting.IsEnable == "OFF")
|
{
|
throw new Exception($"不允许立库同托盘不同物料入库或同托盘不同批次入库!");
|
}
|
}
|
}
|
#endregion
|
//liudl && m.Status != "2" 组盘既入库完成无需根据托盘状态判断
|
var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo);
|
var bindId = 0;
|
if (bind == null)
|
{
|
bind = new BllPalletBind
|
{
|
ASNNo = model.AsnNo,
|
ASNDetailNo = (int)model.AsnDetailId,
|
PalletNo = model.PalletNo,
|
PalletNo2 = "",
|
PalletNo3 = "",
|
Qty = model.SkuQty,
|
FullQty = pNum,
|
Status = "2",//入库完成
|
Type = "0",
|
LotNo = model.LotNo,
|
LotText = detail.LotText,
|
SupplierLot = detail.SupplierLot,
|
//InspectMark = model.IsSample, //是否取样托盘 后期业务开发时 接口传值需添加对应字段判断
|
//SamplingQty = 0, //取样数量 后期业务开发时 接口传值需添加对应字段判断
|
BitPalletMark = "1",
|
IsBale = "0",
|
IsBelt = "0",
|
CreateUser = userId,
|
Demo = model.Demo,
|
|
};
|
// 插入托盘绑定表
|
bindId = Db.Insertable(bind).ExecuteReturnIdentity();
|
}
|
else
|
{
|
// liudl 组盘既入库完成无需判断托盘状态
|
//if (bind.Status != "0")
|
//{
|
// throw new Exception("-1:当前托盘正在执行中,绑定失败,请核实!");
|
//}
|
bindId = bind.Id;
|
bind.Qty += model.SkuQty;
|
}
|
if (bind.Qty < 0)
|
{
|
throw new Exception("组盘数量不能小于0");
|
}
|
#region 库存明细
|
//获取该批次最终质检结果
|
BllQualityInspect quality = new BllQualityInspect();
|
//判断是否为退货入库单
|
if (notice.Type == "3")
|
{
|
quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.ASNNo == detail.ASNNo && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First();
|
}
|
else
|
{
|
quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First();
|
}
|
var tags = "0";
|
if (notice.Type == "3" || notice.Type == "4")
|
{
|
tags = "1";
|
}
|
|
// 判断库存明细是否已有此托盘信息
|
var sd1 = Db.Queryable<DataStockDetail>()
|
.First(m => m.IsDel == "0" && m.ASNDetailNo == bind.ASNDetailNo && m.PalletNo == model.PalletNo);
|
var sdId1 = 0;
|
if (sd1 != null)
|
{
|
sdId1 = sd1.Id;
|
// 库存已存在 更新数据
|
sd1.Qty = bind.Qty;
|
sd1.CompleteTime = comTime;
|
sd1.UpdateUser = userId;
|
sd1.UpdateTime = comTime;
|
|
Db.Updateable(sd1).ExecuteCommand(); //修改质检信息
|
}
|
else
|
{
|
// 库存不存在 插入数据
|
sd1 = new DataStockDetail()
|
{
|
LotNo = bind.LotNo,
|
LotText = bind.LotText,
|
SupplierLot = bind.SupplierLot,
|
SkuNo = sku.SkuNo,
|
SkuName = sku.SkuName,
|
Standard = sku.Standard,
|
Qty = bind.Qty,
|
LockQty = 0,
|
FrozenQty = 0,
|
InspectQty = 0,
|
ASNNo = bind.ASNNo,
|
ASNDetailNo = bind.ASNDetailNo,
|
WareHouseNo = "",//所属仓库
|
RoadwayNo = "",//所属巷道
|
AreaNo = "",//所属区域
|
LocatNo = "",//储位地址
|
PalletNo = bind.PalletNo,
|
PalletNo2 = bind.PalletNo2,
|
PalletNo3 = bind.PalletNo3,
|
PalletTags = tags,
|
CompleteTime = comTime,
|
ProductionTime = bind.ProductionTime,
|
ExpirationTime = bind.ExpirationTime,
|
Status = "0",
|
InspectMark = bind.InspectMark,
|
InspectStatus = sku.IsInspect,
|
BitPalletMark = bind.BitPalletMark,
|
PackagNo = detail.PackagNo, //liudl 由sku的包装编号变为入库单明细的包装编码
|
IsBale = bind.IsBale,
|
IsBelt = bind.IsBelt,
|
|
IsDel = "0",
|
CreateUser = 0,
|
CreateTime = comTime
|
};
|
|
//维护库存明细货主/供应商信息
|
if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
|
{
|
sd1.OwnerNo = notice.CustomerNo;//货主编码
|
sd1.OwnerName = notice.CustomerName;//货主名称
|
}
|
else if (notice.Type == "1" || notice.Type == "5")//1:采购入库,2:其它入库
|
{
|
sd1.SupplierNo = notice.CustomerNo;//供应商编码
|
sd1.SupplierName = notice.CustomerName;//供应商名称
|
}
|
if (quality != null)
|
{
|
//修改合格不合格数量
|
if (quality.IsQualified == "1") //合格
|
{
|
//增加合格数量
|
quality.PassQty += bind.Qty;
|
sd1.InspectStatus = "1";
|
}
|
else if (quality.IsQualified == "0") //不合格
|
{
|
//增加不合格数量
|
quality.FailQty += bind.Qty;
|
sd1.InspectStatus = "2";
|
}
|
Db.Updateable(quality).ExecuteCommand(); //修改质检信息
|
}
|
//添加库存明细
|
sdId1 = Db.Insertable(sd1).ExecuteReturnIdentity();
|
}
|
#endregion
|
|
#region 箱码信息
|
var msgStr = $"箱号为{model.BoxNo}";
|
var boxInfoList = new List<BllBoxInfo>();
|
if (isTextTable == 0) //判断是否是标签页组盘
|
{
|
//首箱
|
var boxInfo = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo).ToList();
|
if (boxInfo.Count == 0)
|
{
|
throw new Exception("箱码信息不存在!");
|
}
|
boxInfo = boxInfo.Where(m => m.Status == "0").ToList();
|
if (boxInfo.Count == 0)
|
{
|
throw new Exception("箱码已被使用!");
|
}
|
boxInfoList.AddRange(boxInfo);
|
//是否连续组托
|
if (model.IsContinue == "1")
|
{
|
//尾箱
|
var boxInfo2 = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.TailBoxNo).ToList();
|
if (boxInfo2.Count == 0)
|
{
|
throw new Exception("尾箱码信息不存在!");
|
}
|
boxInfo2 = boxInfo2.Where(m => m.Status == "0").ToList();
|
if (boxInfo2.Count == 0)
|
{
|
throw new Exception("尾箱箱码已被使用!");
|
}
|
boxInfoList.AddRange(boxInfo2);
|
var sql = $"select * from BllBoxInfo where IsDel = '0' and Status = '0' and boxNo>'{model.BoxNo}' and boxNo<'{model.TailBoxNo}'; ";
|
var list = Db.Ado.SqlQuery<BllBoxInfo>(sql);
|
boxInfoList.AddRange(list);
|
msgStr += $"尾箱号为{model.TailBoxNo}";
|
}
|
}
|
#endregion
|
|
// 更改箱支关系表
|
decimal factQty = 0.00m;//托盘总数量
|
var isSample = "0";//是否取样
|
var sampleQty = 0m;//取样数量
|
|
//标签组托
|
if (isTextTable == 0)
|
{
|
var boxGroup = boxInfoList.GroupBy(m => m.BoxNo).ToList();
|
foreach (var g in boxGroup)
|
{
|
decimal boxFullQty = 0;//箱内总数量
|
foreach (var box in g)
|
{
|
if (box.BindNo != null && box.BindNo != 0)
|
{
|
continue;
|
}
|
//箱内物料批次与单据明细不符合
|
if (box.SkuNo != detail.SkuNo || box.LotNo != model.LotNo)
|
{
|
throw new Exception($"-1:{box.BoxNo}箱内物料及批次与单据不一致,请核实!");
|
}
|
|
box.ASNNo = model.AsnNo;
|
box.ASNDetailNo = model.AsnDetailId;
|
box.BindNo = bindId;
|
box.PalletNo = model.PalletNo;
|
box.Status = "2";
|
//box.InspectMark = model.IsSample; //是否取样托盘 后期业务开发时 接口传值需添加对应字段判断
|
//box.SamplingQty = 0; //取样数量 后期业务开发时 接口传值需添加对应字段判断
|
box.CompleteTime = comTime;
|
box.UpdateTime = comTime;
|
box.UpdateUser = userId;
|
|
//box.Qty = box.Qty;
|
//box.BitBoxMark = box.Qty == box.FullQty ? "0" : "1";
|
|
factQty += box.Qty;
|
boxFullQty += box.Qty;
|
if (box.InspectMark == "1") //判断是否取样
|
{
|
isSample = "1";
|
sampleQty += (decimal)box.SamplingQty;
|
}
|
|
#region 库存箱码明细
|
var box2 = new DataBoxInfo()
|
{
|
StockDetailId = sdId1,
|
BindNo = bind.Id,
|
BoxNo = box.BoxNo,
|
BoxNo2 = box.BoxNo2,
|
BoxNo3 = box.BoxNo3,
|
PalletNo = box.PalletNo,
|
PalletNo2 = box.PalletNo2,
|
PalletNo3 = box.PalletNo3,
|
Qty = box.Qty,
|
FullQty = box.FullQty,
|
Status = "2",//0:未组托 1:已组托 2:已入库 3:已出库 4:已分配 5:已拣货
|
LotNo = box.LotNo,
|
LotText = box.LotText,
|
SkuNo = box.SkuNo,
|
SkuName = box.SkuName,
|
Standard = sku.Standard,
|
ProductionTime = box.ProductionTime,
|
SupplierLot = box.SupplierLot,
|
InspectStatus = sku.IsInspect,
|
InspectMark = box.InspectMark,
|
BitBoxMark = box.BitBoxMark,
|
ExpirationTime = box.ExpirationTime,
|
|
CreateUser = 0,
|
CreateTime = comTime
|
};
|
//添加库存箱码明细
|
Db.Insertable(box2).ExecuteCommand();
|
#endregion
|
}
|
if (boxFullQty > bNum)
|
{
|
throw new Exception($"绑定失败,{g.Key}箱码绑定数量大于该物品包装数量!");
|
}
|
}
|
Db.Updateable(boxInfoList).ExecuteCommand();
|
|
// 更新托盘绑定表
|
bind.Qty += factQty;
|
}
|
//if (bind.FullQty < bind.Qty && isTextTable == 0)
|
if (bind.FullQty < bind.Qty)
|
{
|
throw new Exception("托盘绑定数量已超出该物料包装数量");
|
}
|
|
if (bind.FullQty == bind.Qty)
|
{
|
bind.BitPalletMark = "0";
|
sd1.BitPalletMark = "0";
|
}
|
//if (bind.Qty > pNum && isTextTable == 0)
|
if (bind.Qty > pNum)
|
{
|
throw new Exception($"绑定失败,{bind.PalletNo}托盘绑定数量大于该物品托盘包装数量!");
|
}
|
|
if (isSample == "1")
|
{
|
bind.InspectMark = "1";
|
bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty;
|
}
|
Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand();
|
|
#region 入库单及明细
|
decimal addQty = 0;
|
if (isTextTable == 1)//物料
|
{
|
addQty = model.SkuQty;
|
}
|
else//标签
|
{
|
addQty = factQty;
|
}
|
detail.FactQty += addQty;//已组数量
|
detail.CompleteQty += addQty;//完成数量
|
if (isSample == "1") //后期业务开发时 接口传值改为判断是否取样
|
{
|
detail.IsSampling = "1";
|
}
|
detail.Status = "1";//0:等待执行 1:正在执行 2:执行完成
|
if (detail.CompleteQty >= detail.Qty)
|
{
|
detail.Status = "2";
|
detail.CompleteTime = comTime;
|
}
|
detail.UpdateUser = userId;
|
detail.UpdateTime = comTime;
|
//更新入库单明细
|
Db.Updateable(detail).ExecuteCommand();
|
|
notice.UpdateUser = userId;
|
notice.UpdateTime = comTime;
|
if (notice.Status == "0")
|
{
|
notice.Status = "1";
|
}
|
var asnDetailNum = Db.Queryable<BllArrivalNoticeDetail>()
|
.Count(m => m.IsDel == "0" && m.ASNNo == detail.ASNNo && m.Status != "2");
|
if (asnDetailNum == 0)
|
{
|
notice.Status = "2";
|
notice.CompleteTime = comTime;//完成时间
|
}
|
//更新入库单
|
Db.Updateable(notice).ExecuteCommand();
|
#endregion
|
|
#region 库存明细
|
sd1.Qty = bind.Qty;
|
//更改库存明细数量
|
Db.Updateable(sd1).Where(m => m.Id == sdId1).ExecuteCommand();
|
#endregion
|
|
#region 库存
|
var dataStock = Db.Queryable<DataStock>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo);
|
if (dataStock != null)
|
{
|
if (isTextTable == 0)
|
{
|
dataStock.Qty += factQty;
|
}
|
else
|
{
|
dataStock.Qty += model.SkuQty;
|
}
|
|
if (bind.InspectMark == "1")
|
{
|
dataStock.IsSampling = bind.InspectMark;
|
}
|
Db.Updateable(dataStock).ExecuteCommand();
|
}
|
else
|
{
|
var stock = new DataStock()
|
{
|
SkuNo = sku.SkuNo,
|
SkuName = sku.SkuName,
|
Standard = sku.Standard,
|
LotNo = bind.LotNo,
|
LotText = bind.LotText,
|
Qty = bind.Qty,
|
LockQty = 0,
|
FrozenQty = 0,
|
IsSampling = bind.InspectMark,
|
IsDel = "0",
|
CreateUser = userId,
|
CreateTime = comTime
|
};
|
//维护库存货主信息
|
if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
|
{
|
stock.OwnerNo = notice.CustomerNo;//货主编码
|
stock.OwnerName = notice.CustomerName;//货主名称
|
}
|
Db.Insertable(stock).ExecuteCommand();
|
}
|
#endregion
|
|
#region 质检请验
|
if ((notice.Type == "1" || notice.Type == "4" || notice.Type == "5") && sku.IsInspect != "1")
|
{
|
var qualityRequest = Db.Queryable<BllQualityInspectionRequest>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo && m.SupplierLot == bind.SupplierLot);
|
if (qualityRequest == null)
|
{
|
string qcNo = new Common().GetMaxNo("QC");
|
qualityRequest = new BllQualityInspectionRequest();
|
qualityRequest.QcNo = qcNo;
|
qualityRequest.Status = "0";
|
qualityRequest.SkuNo = sku.SkuNo;
|
qualityRequest.SkuName = sku.SkuName;
|
qualityRequest.LotNo = bind.LotNo;
|
qualityRequest.SupplierLot = bind.SupplierLot;
|
qualityRequest.Qty = detail.Qty;
|
qualityRequest.SamplingQty = 0;
|
qualityRequest.ASNNo = detail.ASNNo;
|
qualityRequest.CreateUser = userId;
|
qualityRequest.CreateTime = comTime;
|
//添加质检请验单
|
Db.Insertable(qualityRequest).ExecuteCommand();
|
}
|
}
|
#endregion
|
|
// 更改托盘使用状态
|
var sqlStr = $"update SysPallets set Status = '1' where PalletNo = '{model.PalletNo}';";
|
//添加托盘记录表数据
|
sqlStr += $"insert into LogPalletTrack values('{model.PalletNo}','{model.AsnNo}','组盘','0',getDate(),{userId},NULL,NULL);";
|
Db.Ado.ExecuteCommand(sqlStr);
|
new OperationASNServer().AddLogOperationAsn("PDA模块", "托盘绑定", model.AsnNo, "添加", $"添加了托盘码为:{model.PalletNo}、{msgStr}的组盘信息", userId);
|
|
Db.CommitTran();
|
}
|
catch (Exception e)
|
{
|
Db.RollbackTran();
|
throw new Exception(e.Message);
|
}
|
}
|
|
|
|
#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)
|
{
|
foreach (var item in stockDetail)
|
{
|
if (!string.IsNullOrEmpty(item.WareHouseNo))
|
{
|
throw new Exception("该托盘未在库外,请核查!");
|
}
|
}
|
iscount = 1; //回流入库
|
}
|
#endregion
|
|
#region 地码信息(储位信息)
|
var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == model.LocatNo && w.Status == "0");
|
if (storageLocat == null)
|
{
|
throw new Exception("储位信息不存在或非空闲状态,请核查!");
|
}
|
#endregion
|
|
Db.BeginTran();//开启事务
|
if (iscount == 0)//正常入库
|
{
|
#region 托盘绑定信息
|
var bindInfo = Db.Queryable<BllPalletBind>().First(w => w.IsDel == "0" && w.ASNNo == model.ASNNo && w.PalletNo == model.PalletNo && w.Status != "2");
|
if (bindInfo == null)
|
{
|
throw new Exception("托盘绑定信息不存在,请核查!");
|
}
|
if (!string.IsNullOrEmpty(bindInfo.WareHouseNo))
|
{
|
throw new Exception("该托盘未在库外,请核查!");
|
}
|
#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
|
|
#region 箱码信息
|
var boxInfoList = Db.Queryable<BllBoxInfo>().Where(w => w.IsDel == "0" && w.ASNNo == model.ASNNo && w.PalletNo == model.PalletNo).ToList();
|
// type 0:成品入库 1:采购入库 2:中间品入库 3:退货入库 4:车间余料退回入库 5:其它入库 6:代储入库 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
|
|
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";//正在执行
|
|
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
|
};
|
//维护库存货主信息
|
if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
|
{
|
stockModel.OwnerNo = notice.CustomerNo;//货主编码
|
stockModel.OwnerName = notice.CustomerName;//货主名称
|
}
|
//新增库存总信息
|
Db.Insertable<DataStock>(stockModel).ExecuteCommand();
|
}
|
else
|
{
|
stockModel.Qty += bindInfo.Qty;
|
stockModel.UpdateUser = (int)model.CreateUser;
|
stockModel.UpdateTime = serverTime;
|
//修改库存总信息
|
Db.Updateable(stockModel).ExecuteCommand();
|
}
|
#endregion
|
|
#region 库存明细表
|
// 判断当前托盘是否已存在(拣货回库托盘)
|
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 = storageLocat.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
|
};
|
//维护库存明细货主/供应商信息
|
if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
|
{
|
detailModel.OwnerNo = notice.CustomerNo;//货主编码
|
detailModel.OwnerName = notice.CustomerName;//货主名称
|
}
|
else if (notice.Type == "1" || notice.Type == "5")//1:采购入库,2:其它入库
|
{
|
detailModel.SupplierNo = notice.CustomerNo;//供应商编码
|
detailModel.SupplierName = notice.CustomerName;//供应商名称
|
}
|
#region 维护质检结果
|
//获取该批次最终质检结果
|
var quality = Db.Queryable<BllQualityInspect>().Where(a => a.LotNo == noticeDetail.LotNo && a.IsDel == "0").OrderByDescending(a => a.CreateTime).First();
|
if (quality != null)
|
{
|
//修改合格不合格数量
|
if (quality.IsQualified == "1") //合格
|
{
|
//增加合格数量
|
quality.PassQty += detailModel.Qty;
|
detailModel.InspectStatus = "1";
|
}
|
else if (quality.IsQualified == "0") //不合格
|
{
|
//增加不合格数量
|
quality.FailQty += detailModel.Qty;
|
detailModel.InspectStatus = "2";
|
}
|
Db.Updateable(quality).ExecuteCommand(); //修改质检信息
|
}
|
#endregion
|
stId = Db.Insertable<DataStockDetail>(detailModel).ExecuteReturnIdentity();
|
}
|
else
|
{
|
stId = detailModel.Id;
|
detailModel.LocatNo = model.LocatNo;
|
detailModel.AreaNo = storageLocat.AreaNo;
|
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正在执行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 upShelf = new BllPalletUpShelf()
|
{
|
TaskNo = exTask.TaskNo,
|
TraceNo = bindInfo.ASNNo,
|
PalletNo = bindInfo.PalletNo,
|
SkuNo = stockModel.SkuNo,
|
SkuName = stockModel.SkuName,
|
LotNo = stockModel.LotNo,
|
Status = "1",
|
|
WareHouseNo = bindInfo.WareHouseNo,
|
RoadwayNo = bindInfo.RoadwayNo,
|
AreaNo = "",
|
LocatNo = "",
|
|
CreateUser = 0,
|
};
|
Db.Insertable(upShelf).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
|
{
|
//判断总单状态是否为正在执行
|
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 = storageLocat.WareHouseNo; // 所属仓库
|
item.RoadwayNo = storageLocat.RoadwayNo; // 所属巷道
|
item.AreaNo = storageLocat.AreaNo; // 所属区域
|
item.LocatNo = model.LocatNo; // 储位地址
|
item.UpdateTime = serverTime; // 修改时间
|
item.UpdateUser = model.CreateUser; // 修改人
|
//修改库存明细信息
|
Db.Updateable(item).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 = model.LocatNo,//目标位置
|
PalletNo = model.PalletNo,//托盘码
|
IsSend = 0,//是否可再次下发
|
IsCancel = 0,//是否可取消
|
IsFinish = 0,//是否可完成
|
Type = "0",//任务类型 0 入库任务 1 出库任务 2 移库任务
|
Status = "2",//任务状态0:等待执行1正在执行2执行完成
|
OrderType = "0",//0 入库单 1 出库单 2 盘点单 3 移库单
|
Msg = "平库的入库任务",
|
};
|
Db.Insertable(exTask).ExecuteCommand();
|
//托盘绑定信息
|
var bindInfo = Db.Queryable<BllPalletBind>().First(w => w.IsDel == "0" && w.PalletNo == model.PalletNo
|
&& w.Status == "2" && string.IsNullOrEmpty(w.LocatNo));
|
if (bindInfo != null)
|
{
|
bindInfo.WareHouseNo = storageLocat.WareHouseNo; // 所属仓库
|
bindInfo.RoadwayNo = storageLocat.RoadwayNo; // 所属巷道
|
bindInfo.LocatNo = model.LocatNo; // 储位地址
|
bindInfo.UpdateTime = serverTime;
|
bindInfo.UpdateUser = model.CreateUser;
|
bindInfo.CompleteTime = serverTime; // 完成时间
|
bindInfo.TaskNo = taskNo; // 任务号
|
Db.Updateable(bindInfo).ExecuteCommand();
|
}
|
#endregion
|
|
#region 添加托盘上架记录
|
var palletupinfo = stockDetail.First();
|
var upShelf = new BllPalletUpShelf()
|
{
|
TaskNo = exTask.TaskNo,
|
TraceNo = bindInfo== null? "": bindInfo.ASNNo,
|
PalletNo = model.PalletNo,
|
SkuNo = palletupinfo.SkuNo,
|
SkuName = palletupinfo.SkuName,
|
LotNo = palletupinfo.LotNo,
|
Status = "2",
|
LocatNo = model.LocatNo,
|
WareHouseNo = storageLocat.WareHouseNo,
|
RoadwayNo = storageLocat.RoadwayNo,
|
AreaNo = storageLocat.AreaNo,
|
|
CreateUser = 0,
|
};
|
Db.Insertable(upShelf).ExecuteCommand();
|
#endregion
|
}
|
storageLocat.Status = "1";//状态已使用
|
storageLocat.UpdateTime = serverTime; //修改时间
|
storageLocat.UpdateUser = model.CreateUser; //修改人
|
//修改储位信息
|
Db.Updateable(storageLocat).ExecuteCommand();
|
|
new OperationASNServer().AddLogOperationAsn("PDA模块", "平库入库", model.PalletNo, "完成",
|
$"在PDA上完成单据号为:{model.ASNNo}的托盘码为:{model.PalletNo}的平库入库操作", (int)model.CreateUser);
|
Db.CommitTran();
|
}
|
catch (Exception ex)
|
{
|
Db.RollbackTran();
|
throw ex;
|
}
|
}
|
#endregion
|
|
#region JC23取样业务接口
|
|
//获取未组托或已组托的箱码级别
|
public BoxInfoDto GetBoxLevel(string boxNo, string boxNo3)
|
{
|
try
|
{
|
if (!string.IsNullOrWhiteSpace(boxNo3))
|
{
|
var data1 = Db.Queryable<BllBoxInfo>().First(m => m.IsDel == "0" && m.BoxNo3 == boxNo3 && m.BoxNo == boxNo);
|
if (data1 == null)
|
{
|
throw new Exception("未查询到追溯码信息");
|
}
|
var data2 = new BoxInfoDto()
|
{
|
SamplingQty = data1.SamplingQty,
|
Qty = data1.Qty
|
};
|
return data2;
|
}
|
var str = "0";
|
var data = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == boxNo && m.Status != "2")
|
.GroupBy(m => new { m.BoxNo, m.SkuNo, m.SkuName, m.LotNo }).Select(m => new BoxInfoDto()
|
{
|
SkuNo = m.SkuNo,
|
SkuName = m.SkuName,
|
LotNo = m.LotNo,
|
SamplingQty = SqlFunc.AggregateSum(m.SamplingQty),
|
Qty = SqlFunc.AggregateSum(m.Qty),
|
|
}).ToList();
|
if (data.Count == 0)
|
{
|
throw new Exception("未查询到箱码信息,请核实箱码或状态");
|
}
|
var count = Db.Queryable<BllBoxInfo>().Count(m =>
|
m.IsDel == "0" && m.BoxNo == boxNo && !string.IsNullOrWhiteSpace(m.BoxNo3));
|
str = count > 0 ? "2" : "1";
|
data[0].BoxLevel = str;
|
return data[0];
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
//获取已组托的无箱码信息
|
public BoxInfoDto GetPalletInfo(string palletNo)
|
{
|
try
|
{
|
if (string.IsNullOrWhiteSpace(palletNo))
|
{
|
throw new Exception("托盘号不能为空");
|
}
|
var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == palletNo);
|
if (pallet == null)
|
{
|
throw new Exception("未在系统中查询到托盘号信息");
|
}
|
|
var bindList = Db.Queryable<BllPalletBind>().Where(m => m.IsDel == "0" && m.Status == "0" && m.PalletNo == palletNo).ToList();
|
if (bindList.Count == 0)
|
{
|
throw new Exception("未查询到等待执行的托盘绑定信息");
|
}
|
|
if (bindList.Count > 1)
|
{
|
throw new Exception("托盘绑定信息存在多条信息,请核实");
|
}
|
|
var bind = bindList.First();
|
var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == bind.ASNDetailNo);
|
if (detail == null)
|
{
|
throw new Exception("未查询到托盘绑定的单据明细信息");
|
}
|
|
var data = new BoxInfoDto();
|
|
data.ASNNo = bind.ASNNo;
|
data.ASNDetailNo = bind.ASNDetailNo;
|
data.SkuName = detail.SkuName;
|
data.LotNo = detail.LotNo;
|
data.SkuNo = detail.SkuNo;
|
data.Qty = bind.Qty;
|
data.SamplingQty = bind.SamplingQty;
|
|
|
return data;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
//入库前有码物料取样
|
public void HaveCodeSkuSample(PdaPalletBindVm model, int userId)
|
{
|
try
|
{
|
#region 判断
|
|
if (string.IsNullOrWhiteSpace(model.BoxNo))
|
{
|
throw new Exception("箱码不能为空");
|
}
|
if (string.IsNullOrWhiteSpace(model.SampleQty))
|
{
|
throw new Exception("取样数量不能为空");
|
}
|
|
if (model.BoxLevel != "1" && model.BoxLevel != "2")
|
{
|
throw new Exception("取样标识错误,请刷新页面");
|
}
|
if (model.BoxLevel == "2")
|
{
|
if (string.IsNullOrWhiteSpace(model.BoxNo3))
|
{
|
throw new Exception("多级码取样时追溯码不能为空");
|
}
|
}
|
|
#endregion
|
|
var boxList = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo && m.Status != "2").ToList();
|
if (boxList.Count == 0)
|
{
|
throw new Exception("未查询到箱码信息,请核实箱码或状态");
|
}
|
|
var sampleQty = decimal.Parse(model.SampleQty);
|
if (sampleQty < 0)
|
{
|
throw new Exception("取样数量不能小于0");
|
}
|
Db.BeginTran();
|
|
if (model.BoxLevel == "2")
|
{
|
var box3 = boxList.FirstOrDefault(m => m.BoxNo3 == model.BoxNo3);
|
if (box3 == null)
|
{
|
throw new Exception("未查询到当前箱码中的支码信息");
|
}
|
|
if (sampleQty > box3.Qty)
|
{
|
throw new Exception("取样数量不能大于箱支内数量");
|
}
|
|
foreach (var item in boxList)
|
{
|
item.BitBoxMark = "1";//整箱更改为零头箱
|
if (item.Id == box3.Id)
|
{
|
item.Qty -= sampleQty;
|
item.InspectMark = "1";//抽检托标记
|
item.SamplingQty = item.SamplingQty == null ? sampleQty : item.SamplingQty + sampleQty;
|
}
|
}
|
Db.Updateable(boxList).ExecuteCommand();
|
|
if (box3.Status == "1")//已组托
|
{
|
//修改托盘绑定信息
|
var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.Id == box3.BindNo);
|
if (bind == null)
|
{
|
throw new Exception("箱码状态已组托,但未查询到托盘绑定信息");
|
}
|
bind.BitPalletMark = "1";
|
bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty;
|
bind.Qty -= sampleQty;
|
bind.InspectMark = "1";
|
Db.Updateable(bind).ExecuteCommand();
|
|
//修改入库单信息
|
var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == box3.ASNDetailNo);
|
if (detail == null)
|
{
|
throw new Exception("未查询到入库单明细信息");
|
}
|
detail.FactQty -= sampleQty;
|
detail.IsSampling = "1";
|
Db.Updateable(detail).ExecuteCommand();
|
|
|
}
|
|
}
|
else if (model.BoxLevel == "1")
|
{
|
if (boxList.Count > 1)
|
{
|
throw new Exception("一级箱码查询错误,含有多条相同箱码数据");
|
}
|
|
var box = boxList.First();
|
if (sampleQty > box.Qty)
|
{
|
throw new Exception("取样数量不能大于箱支内数量");
|
}
|
|
box.BitBoxMark = "1";//整箱更改为零头箱
|
box.Qty -= sampleQty;
|
box.InspectMark = "1";//抽检托标记
|
box.SamplingQty = box.SamplingQty == null ? sampleQty : box.SamplingQty + sampleQty;
|
|
Db.Updateable(box).ExecuteCommand();
|
|
if (box.Status == "1")//已组托
|
{
|
//修改托盘绑定信息
|
var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.Id == box.BindNo);
|
if (bind == null)
|
{
|
throw new Exception("箱码状态已组托,但未查询到托盘绑定信息");
|
}
|
bind.BitPalletMark = "1";
|
bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty;
|
bind.Qty -= sampleQty;
|
bind.InspectMark = "1";
|
Db.Updateable(bind).ExecuteCommand();
|
|
//修改入库单信息
|
var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == box.ASNDetailNo);
|
if (detail == null)
|
{
|
throw new Exception("未查询到入库单明细信息");
|
}
|
|
detail.FactQty -= sampleQty;
|
detail.IsSampling = "1";
|
Db.Updateable(detail).ExecuteCommand();
|
|
|
}
|
}
|
|
Db.CommitTran();
|
}
|
catch (Exception e)
|
{
|
Db.RollbackTran();
|
throw new Exception(e.Message);
|
}
|
}
|
|
//入库前无码物料取样
|
public void NoCodeSkuSample(PdaPalletBindVm model, int userId)
|
{
|
try
|
{
|
if (string.IsNullOrWhiteSpace(model.AsnNo) || model.AsnDetailId == null || model.AsnDetailId == 0 || string.IsNullOrWhiteSpace(model.PalletNo) || string.IsNullOrWhiteSpace(model.SampleQty))
|
{
|
throw new Exception("参数有误,请核实");
|
}
|
|
|
var bindList = Db.Queryable<BllPalletBind>().Where(m => m.IsDel == "0" && m.Status == "0" && m.PalletNo == model.PalletNo).ToList();
|
if (bindList.Count == 0)
|
{
|
throw new Exception("未查询到等待执行的托盘绑定信息");
|
}
|
|
if (bindList.Count > 1)
|
{
|
throw new Exception("托盘绑定信息存在多条信息,请核实");
|
}
|
|
var bind = bindList.First();
|
var boxInfoCount = Db.Queryable<BllBoxInfo>().Count(m => m.IsDel == "0" && m.BindNo == bind.Id);
|
if (boxInfoCount > 0)
|
{
|
throw new Exception("当前托盘绑定信息是有箱码的,请在标签页取样");
|
}
|
if (bind.ASNNo != model.AsnNo || bind.ASNDetailNo != model.AsnDetailId)
|
{
|
throw new Exception("托盘绑定信息与入库单或物料明细不一致");
|
}
|
var sampleQty = decimal.Parse(model.SampleQty);
|
if (sampleQty > bind.Qty)
|
{
|
throw new Exception("取样数量不能大于托内数量");
|
}
|
|
Db.BeginTran();
|
|
bind.BitPalletMark = "1";
|
bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty;
|
bind.InspectMark = "1";
|
bind.Qty -= sampleQty;
|
Db.Updateable(bind).ExecuteCommand();
|
|
//修改入库单信息
|
var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == bind.ASNDetailNo);
|
if (detail == null)
|
{
|
throw new Exception("未查询到入库单明细信息");
|
}
|
detail.FactQty -= sampleQty;
|
detail.IsSampling = "1";
|
Db.Updateable(detail).ExecuteCommand();
|
|
Db.CommitTran();
|
|
|
}
|
catch (Exception e)
|
{
|
Db.RollbackTran();
|
throw new Exception(e.Message);
|
}
|
}
|
|
|
#endregion
|
|
#region 线边标签
|
/// <summary>
|
/// 根据物料编码、名称获取物料信息
|
/// </summary>
|
/// <param name="model">编码 名称</param>
|
/// <returns>物料详细信息</returns>
|
public MaterialsDto GetSkuInfo(GetMaterialsVm model)
|
{
|
try
|
{
|
if (string.IsNullOrEmpty(model.SkuNo) && string.IsNullOrEmpty(model.SkuName))
|
{
|
throw new Exception("请输入物料编码或物料名称!");
|
}
|
|
var skuModels = Db.Queryable<SysMaterials>().Where(m => (m.SkuNo == model.SkuNo || m.SkuName == model.SkuName) && m.IsDel == "0").Select< MaterialsDto>().ToList();
|
if (skuModels.Count <= 0)
|
{
|
throw new Exception("物料不存在!");
|
}
|
|
return skuModels.First();
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 生成条码标签
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
/// <exception cref="Exception"></exception>
|
public List<BllBoxInfo> AddLabels(LabelsVm model)
|
{
|
try
|
{
|
if (decimal.TryParse(model.SkuNum, out decimal skuQty))
|
{
|
if (skuQty <= 0)
|
{
|
throw new Exception("箱内数量不能小于等于0");
|
}
|
}
|
else
|
{
|
throw new Exception("箱内数量请输入数字!");
|
}
|
|
// 验证物料信息是否存在
|
var skuModels = Db.Queryable<SysMaterials>().Where(m => (m.SkuNo == model.SkuNo || m.SkuName == model.SkuName) && m.IsDel == "0").Select<MaterialsDto>().ToList();
|
if (skuModels.Count <= 0)
|
{
|
throw new Exception("物料不存在!");
|
}
|
|
|
#region
|
var skuModel = skuModels.First();
|
var pack = Db.Queryable<SysPackag>().First(m => m.IsDel == "0" && m.PackagNo == skuModel.PackagNo);
|
if (pack == null)
|
{
|
throw new Exception("未查询到当前物料的包装信息");
|
}
|
|
var packStr = "";
|
if (!string.IsNullOrWhiteSpace(pack.L1Name))
|
{
|
packStr += pack.L1Num + "/" + pack.L1Name;
|
}
|
if (!string.IsNullOrWhiteSpace(pack.L2Name))
|
{
|
packStr += "-" + pack.L2Num + "/" + pack.L2Name;
|
}
|
if (!string.IsNullOrWhiteSpace(pack.L3Name))
|
{
|
packStr += "-" + pack.L3Num + "/" + pack.L3Name;
|
}
|
if (!string.IsNullOrWhiteSpace(pack.L4Name))
|
{
|
packStr += "-" + pack.L4Num + "/" + pack.L4Name;
|
}
|
if (!string.IsNullOrWhiteSpace(pack.L5Name))
|
{
|
packStr += "-" + pack.L5Num + "/" + pack.L5Name;
|
}
|
#endregion
|
|
#region 包装查询
|
|
var bNum = 0;//箱物品数量
|
var zNum = 0;//支物品数量
|
var packLevel = 0;
|
|
if (pack.L2Num.HasValue)
|
{
|
if (pack.L2Name != "托")
|
{
|
packLevel = 1;//JC34项目只有一级标签
|
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级标签打印
|
{
|
throw new Exception("包装信息有误,小于一级");
|
}
|
|
if (skuQty > bNum * 5)
|
{
|
throw new Exception("箱内数量大于包装5倍,不可打印");
|
}
|
#endregion
|
var modelList = new List<BllBoxInfo>();
|
var label = Db.Queryable<BllBoxInfo>().Where(m => m.LotNo == model.LotNo && m.SkuNo == model.SkuNo && m.IsDel == "0").ToList();
|
|
Db.BeginTran();
|
if (packLevel == 1)
|
{
|
#region 一级包装
|
int labelNum = 1;
|
labelNum = int.Parse(Math.Ceiling(skuQty / bNum).ToString());//标签数量
|
|
|
#region 获取/生成批次号
|
string maxLotNoStr = ""; //批次号
|
string maxBoxCode = ""; //箱码号
|
|
maxLotNoStr = model.LotNo;
|
maxBoxCode = label.Where(m => m.LotNo == maxLotNoStr).Max(a => a.BoxNo);
|
#endregion
|
|
for (int i = 1; i <= labelNum; i++)
|
{
|
decimal boxQty = 0;
|
if (i == labelNum)
|
{
|
// 最后一个条码
|
var s = bNum * (i - 1);
|
if (bNum > skuQty - s)
|
{
|
boxQty = skuQty - s;// 数量
|
}
|
else
|
{
|
boxQty = bNum;// 数量
|
}
|
}
|
else
|
{
|
boxQty = bNum; // 数量
|
}
|
|
//获取箱码
|
if (string.IsNullOrWhiteSpace(maxBoxCode))
|
{
|
var str = "B" + maxLotNoStr + "000001"; //批号+ 流水 B 230201 0001 000001
|
maxBoxCode = str;
|
}
|
else
|
{
|
maxBoxCode = maxBoxCode.Substring(0, maxBoxCode.Length - 6) + (int.Parse(maxBoxCode.Substring(maxBoxCode.Length - 6, 6)) + 1).ToString().PadLeft(6, '0');
|
}
|
|
// 将条码保存到原料条码表
|
var labelModel = new BllBoxInfo()
|
{
|
BoxNo = maxBoxCode,
|
Qty = boxQty,
|
FullQty = bNum,
|
Status = "0",
|
SkuNo = model.SkuNo,
|
SkuName = model.SkuName,
|
LotNo = maxLotNoStr,
|
Standard = skuModel.Standard,
|
PackageStandard = packStr,
|
InspectMark = "0",
|
BitBoxMark = bNum > boxQty ? "1" : "0",
|
InspectStatus = "0",
|
|
ProductionTime = DateTime.Parse(model.TimeFrom),
|
StoreTime = DateTime.Parse(model.TimeEnd),
|
ExpirationTime = DateTime.Parse(model.TimeEnd),
|
|
Origin = "WMS生成",
|
CreateUser = (int)model.userId,
|
CreateTime = DateTime.Now,
|
};
|
|
Db.Insertable(labelModel).ExecuteCommand();
|
modelList.Add(labelModel);
|
}
|
|
#endregion
|
}
|
else //(packLevel == 2)
|
{
|
#region 二级包装
|
|
if (skuQty > bNum * 5)
|
{
|
throw new Exception("箱内数量大于包装5倍,不可打印");
|
}
|
|
var qty2 = skuQty;
|
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 = ""; //支码
|
|
maxCodestr2 = model.LotNo;
|
maxboxcode2 = label.Where(m => m.LotNo == maxCodestr2).Max(a => a.BoxNo);
|
maxboxcode3 = label.Where(m => m.LotNo == maxCodestr2).Max(a => a.BoxNo3);//支号
|
#endregion
|
|
for (int i = 1; i <= labelNum2; i++)//箱码标签
|
{
|
//箱内数量
|
decimal boxQty = 0;
|
if (i == labelNum2)
|
{
|
// 最后一个条码
|
var s = bNum * (i - 1);
|
if (bNum > qty2 - s)
|
{
|
boxQty = qty2 - s;// 数量
|
}
|
else
|
{
|
boxQty = bNum;// 数量
|
}
|
}
|
else
|
{
|
boxQty = bNum; // 数量
|
}
|
|
//获取箱码
|
if (string.IsNullOrWhiteSpace(maxboxcode2))
|
{
|
maxboxcode2 = "B" + maxCodestr2 + "000001"; // 箱号 批号+第几箱
|
}
|
else
|
{
|
maxboxcode2 = maxboxcode2.Substring(0, 11) + (int.Parse(maxboxcode2.Substring(11, 6)) + 1).ToString().PadLeft(6, '0');
|
}
|
//获取箱内支标签数量
|
if (i == labelNum2)
|
{
|
var isGo2 = false;
|
var sl = 0;
|
for (int j = 1; j <= labelNumZ2; j++)
|
{
|
if (isGo2)
|
{
|
break;
|
}
|
var s = bNum * (i - 1);
|
var s2 = zNum * (j - 1);
|
if (zNum >= qty2 - s - s2)
|
{
|
isGo2 = true;
|
}
|
sl++;
|
}
|
labelNumZ2 = sl;
|
}
|
|
for (int j = 1; j <= labelNumZ2; j++)//最小单位标签
|
{
|
|
decimal d = zNum;
|
if (i == labelNum2)
|
{
|
var s = bNum * (i - 1);
|
var s2 = zNum * (j - 1);
|
if (zNum >= qty2 - s - s2)
|
{
|
d = qty2 - s - s2; // 数量
|
}
|
}
|
|
if (string.IsNullOrWhiteSpace(maxboxcode3))
|
{
|
maxboxcode3 = "Z" + maxCodestr2 + "0001"; // 支号 批号+第几箱
|
}
|
else
|
{
|
maxboxcode3 = maxboxcode3.Substring(0, 11) + (int.Parse(maxboxcode3.Substring(11, 4)) + 1).ToString().PadLeft(4, '0');
|
}
|
|
// 将条码保存到原料条码表
|
var labelModel = new BllBoxInfo()
|
{
|
BoxNo = maxboxcode2,
|
BoxNo3 = maxboxcode3,
|
Qty = d,
|
FullQty = bNum,
|
Status = "0",
|
SkuNo = model.SkuNo,
|
SkuName = skuModel.SkuName,
|
LotNo = maxCodestr2,
|
Standard = skuModel.Standard,
|
PackageStandard = packStr,
|
InspectMark = "0",
|
BitBoxMark = bNum > boxQty ? "1" : "0",
|
InspectStatus = "0",
|
|
ProductionTime = DateTime.Parse(model.TimeFrom),
|
StoreTime = DateTime.Parse(model.TimeEnd),
|
ExpirationTime = DateTime.Parse(model.TimeEnd),
|
|
Origin = "WMS生成",
|
CreateUser = (int)model.userId,
|
CreateTime = DateTime.Now,
|
};
|
|
Db.Insertable(labelModel).ExecuteCommand();
|
modelList.Add(labelModel);
|
}
|
}
|
#endregion
|
}
|
Db.CommitTran();
|
|
return modelList;
|
}
|
catch (Exception ex)
|
{
|
Db.RollbackTran();
|
throw new Exception(ex.Message);
|
}
|
}
|
#endregion
|
|
}
|
}
|