|
|
|
@ -141,29 +141,54 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
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>()
|
|
|
|
|
.InnerJoin<ApplicationDetail>((i, d1) => i.Id == d1.ApplicationId) //d1=申请明细
|
|
|
|
|
.InnerJoin<ApplicationDetail>((i, d1, d2) => d2.DetailId == d1.Id) //d2=结算明细
|
|
|
|
|
.Where((i, d1, d2) => d2.ApplicationId == id)
|
|
|
|
|
.GroupBy((i, d1, d2) => i.Id)
|
|
|
|
|
.Select((i, d1, d2) => new SettlementDetailGroup
|
|
|
|
|
.InnerJoin<ApplicationDetail>((pa, d1) => pa.Id == d1.ApplicationId) //d1=申请明细
|
|
|
|
|
.Where((pa, d1) => SqlFunc.Subqueryable<ApplicationDetail>().Where(d2 => d2.DetailId == d1.Id && d2.ApplicationId == id).Any())
|
|
|
|
|
.GroupBy((pa, d1) => pa.Id)
|
|
|
|
|
.Select((pa, d1) => new SettlementDetailGroup
|
|
|
|
|
{
|
|
|
|
|
Status = (int)i.Status,
|
|
|
|
|
BillNO = i.ApplicationNO,
|
|
|
|
|
PaymentDate = i.PaymentDate,
|
|
|
|
|
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),
|
|
|
|
|
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),
|
|
|
|
|
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),
|
|
|
|
|
//ApplicationNOList = SqlFunc.Subqueryable<PaymentApplication>().Where(a => a.Id == d1.RefId.Value).ToList(a => a.ApplicationNO)
|
|
|
|
|
Id = pa.Id,
|
|
|
|
|
Status = (int)pa.Status,
|
|
|
|
|
BillNO = pa.ApplicationNO,
|
|
|
|
|
PaymentDate = pa.PaymentDate,
|
|
|
|
|
//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),
|
|
|
|
|
//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),
|
|
|
|
|
//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),
|
|
|
|
|
}, 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)
|
|
|
|
|
{
|
|
|
|
|
PaymentApplicationStatus status = (PaymentApplicationStatus)item.Status;
|
|
|
|
|
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;
|
|
|
|
|