结算统计

dev
嵇文龙 3 weeks ago
parent eb3bb9bf74
commit aa99ad4bb9

@ -141,29 +141,54 @@ namespace DS.WMS.Core.Settlement.Method
/// <returns></returns> /// <returns></returns>
protected override async Task<List<SettlementDetailGroup>> GetSettlementDetails(long id) protected override async Task<List<SettlementDetailGroup>> GetSettlementDetails(long id)
{ {
var appIds = await TenantDb.Queryable<ApplicationDetail>().Where(x => x.ApplicationId == id)
.Select(x => x.DetailId).ToListAsync();
var list = await TenantDb.Queryable<PaymentApplication>() var list = await TenantDb.Queryable<PaymentApplication>()
.InnerJoin<ApplicationDetail>((i, d1) => i.Id == d1.ApplicationId) //d1=申请明细 .InnerJoin<ApplicationDetail>((pa, d1) => pa.Id == d1.ApplicationId) //d1=申请明细
.InnerJoin<ApplicationDetail>((i, d1, d2) => d2.DetailId == d1.Id) //d2=结算明细 .Where((pa, d1) => SqlFunc.Subqueryable<ApplicationDetail>().Where(d2 => d2.DetailId == d1.Id && d2.ApplicationId == id).Any())
.Where((i, d1, d2) => d2.ApplicationId == id) .GroupBy((pa, d1) => pa.Id)
.GroupBy((i, d1, d2) => i.Id) .Select((pa, d1) => new SettlementDetailGroup
.Select((i, d1, d2) => new SettlementDetailGroup {
{ Id = pa.Id,
Status = (int)i.Status, Status = (int)pa.Status,
BillNO = i.ApplicationNO, BillNO = pa.ApplicationNO,
PaymentDate = i.PaymentDate, PaymentDate = pa.PaymentDate,
RMBApplyAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(x => x.ApplicationId == d2.RefId && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount), //RMBApplyAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(x => x.ApplicationId == d2.RefId && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount),
USDApplyAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(x => x.ApplicationId == d2.RefId && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount), //USDApplyAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(x => x.ApplicationId == d2.RefId && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount),
RMBStlAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(x => x.ApplicationId == i.Id && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount), //RMBStlAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(x => x.ApplicationId == i.Id && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount),
USDStlAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(x => x.ApplicationId == i.Id && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount), //USDStlAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(x => x.ApplicationId == i.Id && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount),
RMBStlRestAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(x => x.ApplicationId == i.Id && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount - x.ProcessedAmount), //RMBStlRestAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(x => x.ApplicationId == i.Id && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount - x.ProcessedAmount),
USDStlRestAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(x => x.ApplicationId == i.Id && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount - x.ProcessedAmount), //USDStlRestAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(x => x.ApplicationId == i.Id && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount - x.ProcessedAmount),
//ApplicationNOList = SqlFunc.Subqueryable<PaymentApplication>().Where(a => a.Id == d1.RefId.Value).ToList(a => a.ApplicationNO)
}, true).ToListAsync(); }, true).ToListAsync();
var ids = list.Select(x => x.Id);
var appDetails = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids.Contains(x.ApplicationId))
.Select(x => new
{
x.Id,
x.ApplicationId,
x.Currency,
x.ApplyAmount,
}).ToListAsync();
foreach (var item in list) foreach (var item in list)
{ {
PaymentApplicationStatus status = (PaymentApplicationStatus)item.Status; PaymentApplicationStatus status = (PaymentApplicationStatus)item.Status;
item.StatusText = status.GetDescription(); item.StatusText = status.GetDescription();
//申请金额
var details = appDetails.Where(x => x.ApplicationId == item.Id);
item.RMBApplyAmount = details.Where(x => x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount);
item.USDApplyAmount = details.Where(x => x.Currency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount);
//本次结算金额
item.RMBStlAmount = details.Where(x => appIds.Contains(x.Id) && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount);
item.USDStlAmount = details.Where(x => appIds.Contains(x.Id) && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount);
//剩余结算金额
item.RMBStlRestAmount = (item.RMBApplyAmount - item.RMBStlAmount).GetValueOrDefault();
item.RMBStlRestAmount = (item.USDApplyAmount - item.USDStlAmount).GetValueOrDefault();
} }
return list; return list;

@ -113,10 +113,19 @@ namespace DS.WMS.Core.Settlement.Method
if (settlement.Mode == SettlementMode.Payment || settlement.Mode == SettlementMode.Charge) if (settlement.Mode == SettlementMode.Payment || settlement.Mode == SettlementMode.Charge)
{ {
var detailCategory = settlement.Mode == SettlementMode.Payment ? DetailCategory.PaidApplication : DetailCategory.ChargeApplication; var detailCategory = settlement.Mode == SettlementMode.Payment ? DetailCategory.PaidApplication : DetailCategory.ChargeApplication;
details1 = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids.Contains(x.ApplicationId) && x.Category == detailCategory) var expr = Expressionable.Create<ApplicationDetail>().And(x => ids.Contains(x.ApplicationId) && x.Category == detailCategory);
.WhereIF(request.Documents.Any(x => x.SettlementRMB.HasValue), x => x.Currency == FeeCurrency.RMB_CODE)
.WhereIF(request.Documents.Any(x => x.SettlementUSD.HasValue), x => x.Currency == FeeCurrency.USD_CODE) if (request.Documents.Any(x => x.SettlementRMB.GetValueOrDefault() == 0) || request.Documents.Any(x => x.SettlementUSD.GetValueOrDefault() == 0) ||
.WhereIF(request.Documents.Any(x => x.SettlementOther.HasValue), x => x.Currency != FeeCurrency.RMB_CODE && x.Currency != FeeCurrency.USD_CODE) request.Documents.Any(x => x.SettlementOther.GetValueOrDefault() == 0)) //按币别结算
{
if (request.Documents.Any(x => x.SettlementRMB.GetValueOrDefault() != 0))
expr = expr.And(x => x.Currency == FeeCurrency.RMB_CODE);
if (request.Documents.Any(x => x.SettlementUSD.GetValueOrDefault() != 0))
expr = expr.And(x => x.Currency == FeeCurrency.USD_CODE);
}
details1 = await TenantDb.Queryable<ApplicationDetail>().Where(expr.ToExpression())
.Select(x => new ApplicationDetail .Select(x => new ApplicationDetail
{ {
ApplicationId = settlement.Id, ApplicationId = settlement.Id,
@ -152,7 +161,7 @@ namespace DS.WMS.Core.Settlement.Method
return DataResult<TEntity>.Failed($"未传入结算币别 {settlement.Currency} 与费用原币别 {detail.OriginalCurrency} 之间的汇率信息"); return DataResult<TEntity>.Failed($"未传入结算币别 {settlement.Currency} 与费用原币别 {detail.OriginalCurrency} 之间的汇率信息");
detail.ExchangeRate = exchange.ExchangeRate; detail.ExchangeRate = exchange.ExchangeRate;
detail.ApplyAmount = Math.Round(exchange.ExchangeRate.GetValueOrDefault() * detail.OriginalAmount, 2, MidpointRounding.AwayFromZero); //detail.ApplyAmount = Math.Round(exchange.ExchangeRate.GetValueOrDefault() * detail.OriginalAmount, 2, MidpointRounding.AwayFromZero);
} }
} }
} }

Loading…
Cancel
Save