|
|
|
@ -93,9 +93,10 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
OriginalAmount = x.OriginalAmount,
|
|
|
|
|
OriginalCurrency = x.OriginalCurrency ?? (settlement.Currency.IsNullOrEmpty() ? x.Currency : settlement.Currency),
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//按付费/发票申请结算
|
|
|
|
|
//按付费/发票申请/自由业务结算
|
|
|
|
|
if (request.Documents?.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
if (settlement.Id == 0)
|
|
|
|
@ -193,6 +194,50 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//按业务自由结算
|
|
|
|
|
else if (settlement.Mode == SettlementMode.FreeSettlement)
|
|
|
|
|
{
|
|
|
|
|
var types = request.Documents.Select(x => x.BusinessType.GetValueOrDefault());
|
|
|
|
|
var custIds = request.Documents.Select(x => x.CustomerId);
|
|
|
|
|
details1 = await TenantDb.Queryable<FeeRecord>().Where(f => ids.Contains(f.BusinessId) && types.Contains(f.BusinessType) && custIds.Contains(f.CustomerId) &&
|
|
|
|
|
(f.FeeStatus == FeeStatus.AuditPassed || f.FeeStatus == FeeStatus.PartialSettlement) && (f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount) != 0)
|
|
|
|
|
.Select(f => new ApplicationDetail
|
|
|
|
|
{
|
|
|
|
|
ApplicationId = settlement.Id,
|
|
|
|
|
RefId = f.BusinessId,
|
|
|
|
|
RecordId = f.Id,
|
|
|
|
|
Category = f.FeeType == FeeType.Payable ? DetailCategory.PaidFreeSettlement : DetailCategory.ChargeFreeSettlement,
|
|
|
|
|
CustomerName = f.CustomerName ?? settlement.CustomerName,
|
|
|
|
|
FeeId = f.FeeId,
|
|
|
|
|
FeeName = f.FeeName,
|
|
|
|
|
FeeType = f.FeeType,
|
|
|
|
|
ApplyAmount = f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount,
|
|
|
|
|
Currency = f.Currency,
|
|
|
|
|
OriginalAmount = f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount,
|
|
|
|
|
OriginalCurrency = f.Currency,
|
|
|
|
|
ExchangeRate = f.ExchangeRate
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(settlement.Currency)) //指定结算币别
|
|
|
|
|
{
|
|
|
|
|
var details2 = details1.FindAll(x => x.OriginalCurrency != settlement.Currency);
|
|
|
|
|
foreach (var detail in details2)
|
|
|
|
|
{
|
|
|
|
|
detail.Currency = settlement.Currency;
|
|
|
|
|
|
|
|
|
|
var doc = request.Documents.Find(x => x.Id == detail.RefId);
|
|
|
|
|
if (doc == null)
|
|
|
|
|
return DataResult<TEntity>.Failed("结算单据与费用明细不一致");
|
|
|
|
|
|
|
|
|
|
var exchange = doc.ExchangeRates?.Find(x => x.Currency == settlement.Currency);
|
|
|
|
|
if (exchange == null)
|
|
|
|
|
return DataResult<TEntity>.Failed($"未传入结算币别 {settlement.Currency} 与费用原币别 {detail.OriginalCurrency} 之间的汇率信息");
|
|
|
|
|
|
|
|
|
|
detail.ExchangeRate = exchange.ExchangeRate;
|
|
|
|
|
detail.ApplyAmount = Math.Round(exchange.ExchangeRate.GetValueOrDefault() * detail.OriginalAmount, 2, MidpointRounding.AwayFromZero);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//执行结算费用分配
|
|
|
|
|
foreach (var doc in request.Documents)
|
|
|
|
|