|
|
|
@ -125,7 +125,7 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
return DataResult<TEntity>.Failed(result.Message, result.MultiCode);
|
|
|
|
|
|
|
|
|
|
List<ApplicationDetail>? details1 = null;
|
|
|
|
|
List<ApplicationDetail>? details = null;
|
|
|
|
|
//自由结算
|
|
|
|
|
if (settlement.Mode == SettlementMode.FreeSettlement && request.Details?.Count > 0)
|
|
|
|
|
{
|
|
|
|
@ -220,7 +220,7 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
if (settlement.Mode == SettlementMode.Payment || settlement.Mode == SettlementMode.Charge)
|
|
|
|
|
{
|
|
|
|
|
var detailCategory = settlement.Mode == SettlementMode.Payment ? DetailCategory.PaidApplication : DetailCategory.ChargeApplication;
|
|
|
|
|
details1 = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids.Contains(x.ApplicationId) && x.Category == detailCategory)
|
|
|
|
|
details = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids.Contains(x.ApplicationId) && x.Category == detailCategory)
|
|
|
|
|
.Select(x => new ApplicationDetail
|
|
|
|
|
{
|
|
|
|
|
ApplicationId = settlement.Id,
|
|
|
|
@ -242,7 +242,7 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(settlement.Currency)) //指定结算币别
|
|
|
|
|
{
|
|
|
|
|
var details2 = details1.FindAll(x => x.OriginalCurrency != settlement.Currency);
|
|
|
|
|
var details2 = details.FindAll(x => x.OriginalCurrency != settlement.Currency);
|
|
|
|
|
foreach (var detail in details2)
|
|
|
|
|
{
|
|
|
|
|
detail.Currency = settlement.Currency;
|
|
|
|
@ -263,7 +263,7 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
//发票结算
|
|
|
|
|
else if (settlement.Mode == SettlementMode.InvoiceSettlement || settlement.Mode == SettlementMode.PaymentInvoiceSettlement)
|
|
|
|
|
{
|
|
|
|
|
details1 = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids.Contains(x.ApplicationId) && x.Category == DetailCategory.InvoiceIssuance)
|
|
|
|
|
details = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids.Contains(x.ApplicationId) && x.Category == DetailCategory.InvoiceIssuance)
|
|
|
|
|
.Select(x => new ApplicationDetail
|
|
|
|
|
{
|
|
|
|
|
ApplicationId = settlement.Id,
|
|
|
|
@ -285,7 +285,7 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
|
|
|
|
|
if (settlement.Currency != FeeCurrency.RMB_CODE) //发票结算非人民币需做转换
|
|
|
|
|
{
|
|
|
|
|
var details2 = details1.FindAll(x => x.OriginalCurrency != settlement.Currency);
|
|
|
|
|
var details2 = details.FindAll(x => x.OriginalCurrency != settlement.Currency);
|
|
|
|
|
foreach (var detail in details2)
|
|
|
|
|
{
|
|
|
|
|
detail.Currency = settlement.Currency;
|
|
|
|
@ -307,7 +307,7 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
//执行结算费用分配
|
|
|
|
|
foreach (var doc in request.Documents)
|
|
|
|
|
{
|
|
|
|
|
var details2 = details1.Where(x => x.RefId == doc.Id).OrderBy(x => x.ApplyAmount).ToList();
|
|
|
|
|
var details2 = details.Where(x => x.RefId == doc.Id).OrderBy(x => x.ApplyAmount).ToList();
|
|
|
|
|
|
|
|
|
|
var rmbDetails = details2.FindAll(x => x.Currency == FeeCurrency.RMB_CODE);
|
|
|
|
|
var totalRMB = rmbDetails.Sum(x => x.ApplyAmount);
|
|
|
|
@ -370,11 +370,11 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (details?.Count > 0)
|
|
|
|
|
settlement.Details.AddRange(details);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (details1?.Count > 0)
|
|
|
|
|
settlement.Details.AddRange(details1);
|
|
|
|
|
|
|
|
|
|
//仅保留新增费用明细
|
|
|
|
|
settlement.Details = settlement.Details.FindAll(x => x.Id == 0);
|
|
|
|
|
//金额禁止为0
|
|
|
|
|
if (settlement.Details.Exists(x => x.ApplyAmount == 0 || x.OriginalAmount == 0))
|
|
|
|
|
return DataResult<TEntity>.FailedWithDesc(nameof(MultiLanguageConst.AmountCannotBeZero));
|
|
|
|
@ -389,13 +389,13 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
return DataResult<TEntity>.Failed(result.Message, result.MultiCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var details = settlement.Details.FindAll(x => x.Id == 0);
|
|
|
|
|
await TenantDb.Ado.BeginTranAsync();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//关联导航属性插入
|
|
|
|
|
if (settlement.Id == 0)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(settlement.Currency))
|
|
|
|
|
settlement.Amount = settlement.Details.Sum(x => x.ApplyAmount);
|
|
|
|
|
|
|
|
|
|
//创建时需要生成申请单编号
|
|
|
|
@ -411,12 +411,12 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (details.Count > 0)
|
|
|
|
|
await TenantDb.Insertable(details).ExecuteCommandAsync();
|
|
|
|
|
if (settlement.Details.Count > 0)
|
|
|
|
|
await TenantDb.Insertable(settlement.Details).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
////更新结算金额
|
|
|
|
|
//var dbDetails = await TenantDb.Queryable<ApplicationDetail>().Where(x => x.ApplicationId == settlement.Id)
|
|
|
|
|
// .Select(x => new { x.ApplyAmount, x.Currency }).ToListAsync();
|
|
|
|
|
if (!string.IsNullOrEmpty(settlement.Currency))
|
|
|
|
|
settlement.Amount = await TenantDb.Queryable<ApplicationDetail>()
|
|
|
|
|
.Where(x => x.ApplicationId == settlement.Id).SumAsync(x => x.ApplyAmount);
|
|
|
|
|
|
|
|
|
|
await TenantDb.Updateable(settlement).IgnoreColumns(x => new
|
|
|
|
|
{
|
|
|
|
@ -433,10 +433,10 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
|
|
|
|
|
await OnSaveAsync(settlement);
|
|
|
|
|
|
|
|
|
|
if (details.Count > 0)
|
|
|
|
|
if (settlement.Details.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
//更新费用记录的已结算金额
|
|
|
|
|
var fees = details.Select(x => new FeeRecord
|
|
|
|
|
var fees = settlement.Details.Select(x => new FeeRecord
|
|
|
|
|
{
|
|
|
|
|
Id = x.RecordId,
|
|
|
|
|
SettlementAmount = x.OriginalAmount
|
|
|
|
|