fix(生产管理): 修复工单数量类型及完善出货逻辑
将工单数量字段从可空类型改为非可空类型并添加默认值 添加成品入库数量字段并完善相关业务逻辑 修复出货失败时的错误响应 完善撤销入库/出库操作时的工单数量调整 增加出货数量与成品入库数量的校验
This commit is contained in:
@@ -907,7 +907,7 @@ namespace DOAN.Service.BZFM
|
||||
{
|
||||
return $"此记录已撤销过,不可重复撤销";
|
||||
}
|
||||
//做出库红单
|
||||
//做入库红单
|
||||
InboundReceiptDto revokeRecepitDto = new()
|
||||
{
|
||||
ReceiptType = 2,
|
||||
@@ -925,16 +925,36 @@ namespace DOAN.Service.BZFM
|
||||
Remarks = $"撤销操作,入库单号:{recordInbound.InboundNo}",
|
||||
};
|
||||
string result = CreateInboundReceipt(revokeRecepitDto);
|
||||
if (result == "ok")
|
||||
{
|
||||
recordInbound.Remarks = "已撤销";
|
||||
Context.Updateable(recordInbound).ExecuteCommand();
|
||||
return result;
|
||||
}
|
||||
else
|
||||
if (result != "ok")
|
||||
{
|
||||
return result;
|
||||
}
|
||||
// 如果是成品入库则还要减少工单记录数量
|
||||
Context.Ado.BeginTran();
|
||||
if (recordInbound.TransactionType == "生产入库")
|
||||
{
|
||||
var workorderInfo = Context
|
||||
.Queryable<ProWorkorder>()
|
||||
.Where(it => it.Workorder == recordInbound.Workorder)
|
||||
.First();
|
||||
if (workorderInfo == null)
|
||||
{
|
||||
Context.Ado.RollbackTran();
|
||||
return "工单不存在";
|
||||
}
|
||||
// 数量调整
|
||||
workorderInfo.ProductNum -= Math.Abs((int)recordInbound.Quantity);
|
||||
if (workorderInfo.ProductNum < 0)
|
||||
{
|
||||
workorderInfo.ProductNum = 0;
|
||||
}
|
||||
Context.Updateable(workorderInfo).ExecuteCommand();
|
||||
}
|
||||
|
||||
recordInbound.Remarks = "已撤销";
|
||||
Context.Updateable(recordInbound).ExecuteCommand();
|
||||
Context.Ado.CommitTran();
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -950,7 +970,7 @@ namespace DOAN.Service.BZFM
|
||||
{
|
||||
return $"此记录已撤销过,不可重复撤销";
|
||||
}
|
||||
|
||||
|
||||
//做出库红单
|
||||
OutboundReceiptDto revokeRecepitDto = new()
|
||||
{
|
||||
@@ -968,11 +988,11 @@ namespace DOAN.Service.BZFM
|
||||
Remarks = $"撤销操作,出库单号:{recordOutbound.OutboundNo}",
|
||||
};
|
||||
string result = CreateOutboundReceipt(revokeRecepitDto);
|
||||
if(result != "ok")
|
||||
if (result != "ok")
|
||||
{
|
||||
return result;
|
||||
}
|
||||
// 如果是出货则还要减少出货单库存
|
||||
// 如果是出货则还要减少出货单库存和工单出货数量
|
||||
Context.Ado.BeginTran();
|
||||
if (recordOutbound.TransactionType == "出货出库")
|
||||
{
|
||||
@@ -995,19 +1015,19 @@ namespace DOAN.Service.BZFM
|
||||
Context.Ado.RollbackTran();
|
||||
return "订单号不存在";
|
||||
}
|
||||
Context
|
||||
.Updateable<ProWorkorder>()
|
||||
.Where(it => it.Workorder == recordOutbound.Workorder)
|
||||
.SetColumns(it => it.ShipmentNum == 0)
|
||||
.SetColumns(it => it.CustomerOrder == string.Empty)
|
||||
.ExecuteCommand();
|
||||
// 数量调整
|
||||
workorderInfo.ShipmentNum -= Math.Abs((int)recordOutbound.Quantity);
|
||||
if (workorderInfo.ShipmentNum < 0)
|
||||
{
|
||||
workorderInfo.ShipmentNum = 0;
|
||||
}
|
||||
workorderInfo.CustomerOrder = string.Empty;
|
||||
Context.Updateable(workorderInfo).ExecuteCommand();
|
||||
// 修改采购订单是否完成
|
||||
int newQuantity =
|
||||
Context
|
||||
.Queryable<ProWorkorder>()
|
||||
.Where(it => it.CustomerOrder == orderPurchase.OrderNoMes)
|
||||
.Sum(it => it.ShipmentNum)
|
||||
?? 0;
|
||||
int newQuantity = Context
|
||||
.Queryable<ProWorkorder>()
|
||||
.Where(it => it.CustomerOrder == orderPurchase.OrderNoMes)
|
||||
.Sum(it => it.ShipmentNum);
|
||||
orderPurchase.DeliveryQuantity = newQuantity;
|
||||
if (orderPurchase.DeliveryQuantity > orderPurchase.DemandQuantity)
|
||||
{
|
||||
@@ -1198,7 +1218,7 @@ namespace DOAN.Service.BZFM
|
||||
.First();
|
||||
|
||||
// 计算累计出货数量(使用delta值,考虑单据类型的影响)
|
||||
int currentShipmentNum = workorderInfo.ShipmentNum ?? 0;
|
||||
int currentShipmentNum = workorderInfo.ShipmentNum;
|
||||
int newShipmentNum = currentShipmentNum + (int)delta;
|
||||
|
||||
// 验证出货数量有效性
|
||||
@@ -1223,12 +1243,10 @@ namespace DOAN.Service.BZFM
|
||||
.First();
|
||||
if (orderPurchase != null)
|
||||
{
|
||||
int newQuantity =
|
||||
Context
|
||||
.Queryable<ProWorkorder>()
|
||||
.Where(it => it.CustomerOrder == parm.CustomerOrder)
|
||||
.Sum(it => it.ShipmentNum)
|
||||
?? 0;
|
||||
int newQuantity = Context
|
||||
.Queryable<ProWorkorder>()
|
||||
.Where(it => it.CustomerOrder == parm.CustomerOrder)
|
||||
.Sum(it => it.ShipmentNum);
|
||||
|
||||
orderPurchase.DeliveryQuantity = newQuantity;
|
||||
if (orderPurchase.DeliveryQuantity > orderPurchase.DemandQuantity)
|
||||
|
||||
@@ -377,13 +377,33 @@ namespace DOAN.Service.MES.product
|
||||
customerOrder,
|
||||
worker
|
||||
);
|
||||
if (result == 0)
|
||||
{
|
||||
throw new Exception("数据库操作失败");
|
||||
}
|
||||
if (result == 2)
|
||||
{
|
||||
throw new Exception("订单号不存在");
|
||||
}
|
||||
if (result == 3)
|
||||
{
|
||||
throw new Exception("订单超额");
|
||||
}
|
||||
if (result == 4)
|
||||
{
|
||||
throw new Exception("工单不存在");
|
||||
}
|
||||
if (result == 5)
|
||||
{
|
||||
throw new Exception("主体型号和订单物料不匹配");
|
||||
}
|
||||
return result == 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 集成现有系统的日志记录
|
||||
// Log.Error("出货操作失败", ex);
|
||||
throw;
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -429,8 +449,8 @@ namespace DOAN.Service.MES.product
|
||||
productionCode = mri.MaterialName,
|
||||
MaterialCode = mri.MaterialCode,
|
||||
MaterialName = mri.MaterialName,
|
||||
ShipmentNum = pro.ShipmentNum ?? 0,
|
||||
PlanNum = pro.PlanNum ?? 0,
|
||||
ShipmentNum = pro.ShipmentNum,
|
||||
PlanNum = pro.PlanNum,
|
||||
Remark01 = mri.Remarks
|
||||
},
|
||||
true
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace DOAN.Service.MES.SmartScreen.Product
|
||||
digital.ProductionPlanQuantity = Context
|
||||
.Queryable<ProWorkorder>()
|
||||
.Where(it => it.WorkorderDate == DateTime.Today)
|
||||
.Sum(it => it.PlanNum ?? 0);
|
||||
.Sum(it => it.PlanNum);
|
||||
|
||||
//digital.ProductionFinishQuantity = Context.Queryable<ProReportwork01>().Where(it => it.JobDateTime >= DateTime.Today && it.JobDateTime < DateTime.Today.AddDays(1))
|
||||
// .Where(it => it.ProcessId == 90).Sum(it => it.FinishNum??0);
|
||||
|
||||
Reference in New Issue
Block a user