|
@ -499,6 +499,7 @@ namespace BBWYB.Server.Business |
|
|
/// <param name="request"></param>
|
|
|
/// <param name="request"></param>
|
|
|
public void AssociatePurchaseOrder(AssociationOrderRequest request) |
|
|
public void AssociatePurchaseOrder(AssociationOrderRequest request) |
|
|
{ |
|
|
{ |
|
|
|
|
|
nLogManager.Default().Info($"AssociatePurchaseOrder {JsonConvert.SerializeObject(request)}"); |
|
|
var dbOrder = fsql.Select<Order>(request.OrderId).ToOne(); |
|
|
var dbOrder = fsql.Select<Order>(request.OrderId).ToOne(); |
|
|
if (dbOrder == null) |
|
|
if (dbOrder == null) |
|
|
throw new BusinessException("订单不存在"); |
|
|
throw new BusinessException("订单不存在"); |
|
@ -517,6 +518,18 @@ namespace BBWYB.Server.Business |
|
|
if (request.AssociationPurchaseOrderList.Any(x => dbInvalidPurchaseOrderIdList.Contains(x.PurchaseOrderId))) |
|
|
if (request.AssociationPurchaseOrderList.Any(x => dbInvalidPurchaseOrderIdList.Contains(x.PurchaseOrderId))) |
|
|
throw new BusinessException("关联采购单时不能包含历史采购单"); |
|
|
throw new BusinessException("关联采购单时不能包含历史采购单"); |
|
|
|
|
|
|
|
|
|
|
|
#region 数据验证
|
|
|
|
|
|
var validation_groups_pid = request.AssociationPurchaseOrderList.GroupBy(po => po.PurchaseOrderId); |
|
|
|
|
|
if (validation_groups_pid.Any(x => x.Count() > 1)) |
|
|
|
|
|
throw new BusinessException("不允许包含重复的采购单"); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var apo in request.AssociationPurchaseOrderList) |
|
|
|
|
|
{ |
|
|
|
|
|
if (Math.Abs(apo.PurchaseAmount - apo.AssocationOrderCostDetailList.Sum(aocd => aocd.SkuAmount)) > 1) |
|
|
|
|
|
throw new BusinessException($"采购单{apo.PurchaseOrderId}的采购货款与明细采购货款总和误差不能超过1"); |
|
|
|
|
|
} |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
#region 读取采购单中的采购账号/采购方案
|
|
|
#region 读取采购单中的采购账号/采购方案
|
|
|
IList<string> purchaseAccountIdList = request.AssociationPurchaseOrderList.Select(x => string.IsNullOrEmpty(x.PurchaseAccountId) ? |
|
|
IList<string> purchaseAccountIdList = request.AssociationPurchaseOrderList.Select(x => string.IsNullOrEmpty(x.PurchaseAccountId) ? |
|
|
x.PurchaseAccountName : |
|
|
x.PurchaseAccountName : |
|
|