|
|
@ -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;
|
|
|
|