|
|
|
@ -34,10 +34,13 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">结算单ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<PaymentSettlementDto>> GetAsync(long id)
|
|
|
|
|
public async Task<DataResult<ApplicationSettlementDto>> GetAsync(long id)
|
|
|
|
|
{
|
|
|
|
|
var model = await TenantDb.Queryable<ApplicationSettlement>().Select(x => new PaymentSettlementDto
|
|
|
|
|
var model = await TenantDb.Queryable<ApplicationSettlement>().Select(x => new ApplicationSettlementDto
|
|
|
|
|
{
|
|
|
|
|
SettlementTypeName = x.SettlementType.StlName, //结算方式
|
|
|
|
|
CustomerBankName = x.CustomerBank.BankName,
|
|
|
|
|
CustomerAccount = x.CustomerBank.Account
|
|
|
|
|
}, true).FirstAsync(x => x.Id == id);
|
|
|
|
|
|
|
|
|
|
if (model != null)
|
|
|
|
@ -46,21 +49,21 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
model.SaleDeptName = await Db.Queryable<SysOrg>().Where(x => x.Id == model.SaleDeptId.Value)
|
|
|
|
|
.Select(x => x.OrgName).FirstAsync();
|
|
|
|
|
|
|
|
|
|
model.Details = await GetSettlementDetails(id);
|
|
|
|
|
if (model.Details.Count > 0)
|
|
|
|
|
model.SettlementDetails = await GetSettlementDetails(id);
|
|
|
|
|
if (model.SettlementDetails.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
//关联用户名称
|
|
|
|
|
var userIds = model.Details.Select(x => x.CreateBy).Distinct();
|
|
|
|
|
var userIds = model.SettlementDetails.Select(x => x.CreateBy).Distinct();
|
|
|
|
|
var users = await Db.Queryable<SysUser>().Where(x => userIds.Contains(x.Id)).Select(x => new { x.Id, x.UserName }).ToListAsync();
|
|
|
|
|
|
|
|
|
|
foreach (var item in model.Details)
|
|
|
|
|
foreach (var item in model.SettlementDetails)
|
|
|
|
|
{
|
|
|
|
|
item.CreateByName = users.Find(x => x.Id == item.CreateBy)?.UserName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult<PaymentSettlementDto>.Success(model);
|
|
|
|
|
return DataResult<ApplicationSettlementDto>.Success(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -183,80 +186,20 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
|
|
|
|
|
protected override async Task<List<SettlementDetailDto>> GetSettlementDetails(long id)
|
|
|
|
|
{
|
|
|
|
|
var list = await TenantDb.Queryable<ApplicationDetail>()
|
|
|
|
|
.InnerJoin<ApplicationDetail>((d, pd) => d.DetailId == pd.Id)
|
|
|
|
|
.InnerJoin<Invoice.Entity.Invoice>((d, pd, i) => pd.ApplicationId == i.Id)
|
|
|
|
|
.Where(d => d.ApplicationId == id)
|
|
|
|
|
.Select((d, pd, i) => new
|
|
|
|
|
{
|
|
|
|
|
d.Id,
|
|
|
|
|
d.ApplicationId,
|
|
|
|
|
d.ApplyAmount,
|
|
|
|
|
d.Currency,
|
|
|
|
|
d.OriginalCurrency,
|
|
|
|
|
d.OriginalAmount,
|
|
|
|
|
|
|
|
|
|
i.CustomerName,
|
|
|
|
|
i.InvoiceAmount,
|
|
|
|
|
i.InvoiceHeader,
|
|
|
|
|
i.InvoiceDate,
|
|
|
|
|
i.InvoiceNO,
|
|
|
|
|
i.BillNO,
|
|
|
|
|
i.CreateTime,
|
|
|
|
|
i.CreateBy,
|
|
|
|
|
i.Note
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
var details = new List<SettlementDetailDto>();
|
|
|
|
|
if (list.Count == 0)
|
|
|
|
|
return details;
|
|
|
|
|
|
|
|
|
|
var gp = list.GroupBy(d => d.ApplicationId);
|
|
|
|
|
var uids = list.Select(x => x.CreateBy).Distinct();
|
|
|
|
|
var users = await Db.Queryable<SysUser>().Where(x => uids.Contains(x.Id)).Select(x => new
|
|
|
|
|
{
|
|
|
|
|
x.Id,
|
|
|
|
|
x.UserName
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
foreach (var g in gp)
|
|
|
|
|
{
|
|
|
|
|
var firstItem = g.FirstOrDefault();
|
|
|
|
|
var dto = new SettlementDetailDto
|
|
|
|
|
var list = await TenantDb.Queryable<Invoice.Entity.Invoice>()
|
|
|
|
|
.InnerJoin<ApplicationDetail>((i, d1) => i.Id == d1.ApplicationId)
|
|
|
|
|
.InnerJoin<ApplicationDetail>((i, d1, d2) => d1.ApplicationId == d2.RefId)
|
|
|
|
|
.Where((i, d1, d2) => d2.ApplicationId == id &&
|
|
|
|
|
d2.Category == DetailCategory.InvoiceSettlement && d1.Category == DetailCategory.InvoiceIssuance)
|
|
|
|
|
.GroupBy((i, d1, d2) => i.Id)
|
|
|
|
|
.Select((i, d1, d2) => new SettlementDetailDto
|
|
|
|
|
{
|
|
|
|
|
ApplicationId = g.Key,
|
|
|
|
|
RMBApplyAmount = g.Where(x => x.OriginalCurrency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount),
|
|
|
|
|
USDApplyAmount = g.Where(x => x.OriginalCurrency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount),
|
|
|
|
|
|
|
|
|
|
BillNO = firstItem.BillNO,
|
|
|
|
|
InvoiceNO = firstItem.InvoiceNO,
|
|
|
|
|
CreateTime = firstItem?.CreateTime,
|
|
|
|
|
CreateBy = firstItem?.CreateBy,
|
|
|
|
|
CreateByName = users.Find(x => x.Id == firstItem?.CreateBy)?.UserName,
|
|
|
|
|
PaymentDate = firstItem?.CreateTime,
|
|
|
|
|
Note = firstItem?.Note
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//包含多个币别
|
|
|
|
|
if (g.GroupBy(x => x.OriginalCurrency).Select(x => x.Key).Count() > 1)
|
|
|
|
|
{
|
|
|
|
|
//原始币别=不等于结算单币别的首个币别(参考DS7)
|
|
|
|
|
dto.OriginalCurrency = g.Select(x => x.OriginalCurrency).FirstOrDefault();
|
|
|
|
|
//原始金额=当前结算单的币别合计
|
|
|
|
|
dto.OriginalAmount = g.Sum(x => x.ApplyAmount);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dto.OriginalCurrency = firstItem?.OriginalCurrency;
|
|
|
|
|
dto.OriginalAmount = g.Where(x => x.OriginalCurrency == dto.OriginalCurrency).Sum(x => x.ApplyAmount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//结算金额=原申请的原始币别合计
|
|
|
|
|
dto.SettlementAmount = g.Where(x => x.OriginalCurrency == dto.OriginalCurrency).Sum(x => x.ApplyAmount);
|
|
|
|
|
details.Add(dto);
|
|
|
|
|
}
|
|
|
|
|
InvoiceApplyAmount = i.ApplyAmount,
|
|
|
|
|
InvoiceAmount = i.InvoiceAmount,
|
|
|
|
|
SettlementAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(d3 => d3.ApplicationId == i.Id).Sum(d3 => d3.ApplyAmount)
|
|
|
|
|
}, true).ToListAsync();
|
|
|
|
|
|
|
|
|
|
return details;
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|