|
|
|
@ -12,7 +12,6 @@ using DS.WMS.Core.Settlement.Dtos;
|
|
|
|
|
using DS.WMS.Core.Settlement.Entity;
|
|
|
|
|
using DS.WMS.Core.Settlement.Interface;
|
|
|
|
|
using DS.WMS.Core.Sys.Entity;
|
|
|
|
|
using Masuit.Tools.Systems;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Settlement.Method
|
|
|
|
@ -113,81 +112,99 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
return DataResult<ApplicationSettlementDto>.Success(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取结算明细
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取费用申请结算明细
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected override async Task<List<SettlementDetailDto>> GetSettlementDetails(long id)
|
|
|
|
|
{
|
|
|
|
|
var list = await TenantDb.Queryable<ApplicationDetail>()
|
|
|
|
|
.InnerJoin<ApplicationDetail>((d, pd) => d.DetailId == pd.Id)
|
|
|
|
|
.InnerJoin<PaymentApplication>((d, pd, pa) => pd.ApplicationId == pa.Id)
|
|
|
|
|
.Where(d => d.ApplicationId == id)
|
|
|
|
|
.Select((d, pd, pa) => new
|
|
|
|
|
{
|
|
|
|
|
d.Id,
|
|
|
|
|
d.ApplicationId,
|
|
|
|
|
d.ApplyAmount,
|
|
|
|
|
d.Currency,
|
|
|
|
|
d.OriginalCurrency,
|
|
|
|
|
d.OriginalAmount,
|
|
|
|
|
pa.ApplicationNO,
|
|
|
|
|
pa.Status,
|
|
|
|
|
pa.CreateTime,
|
|
|
|
|
pa.CreateBy,
|
|
|
|
|
pa.PaymentDate,
|
|
|
|
|
pa.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
|
|
|
|
|
{
|
|
|
|
|
ApplicationId = g.Key,
|
|
|
|
|
//Ids = g.Select(x => x.Id),
|
|
|
|
|
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),
|
|
|
|
|
ApplicationNO = firstItem.ApplicationNO,
|
|
|
|
|
Status = (int)firstItem.Status,
|
|
|
|
|
StatusText = firstItem.Status.GetDescription(),
|
|
|
|
|
CreateTime = firstItem?.CreateTime,
|
|
|
|
|
CreateBy = firstItem?.CreateBy,
|
|
|
|
|
CreateByName = users.Find(x => x.Id == firstItem?.CreateBy)?.UserName,
|
|
|
|
|
PaymentDate = firstItem?.PaymentDate,
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return details;
|
|
|
|
|
var list = await TenantDb.Queryable<PaymentApplication>()
|
|
|
|
|
.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.PaidApplication && d1.Category == DetailCategory.ChargeApplication)
|
|
|
|
|
.GroupBy((i, d1, d2) => i.Id)
|
|
|
|
|
.Select((i, d1, d2) => new SettlementDetailDto
|
|
|
|
|
{
|
|
|
|
|
SettlementAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(d3 => d3.ApplicationId == i.Id).Sum(d3 => d3.ApplyAmount),
|
|
|
|
|
ApplicationNOList = SqlFunc.Subqueryable<PaymentApplication>().Where(a => a.Id == d1.RefId).ToList(a => a.ApplicationNO)
|
|
|
|
|
}, true).ToListAsync();
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
|
|
|
|
|
//var list = await TenantDb.Queryable<ApplicationDetail>()
|
|
|
|
|
// .InnerJoin<ApplicationDetail>((d, pd) => d.DetailId == pd.Id)
|
|
|
|
|
// .InnerJoin<PaymentApplication>((d, pd, pa) => pd.ApplicationId == pa.Id)
|
|
|
|
|
// .Where(d => d.ApplicationId == id)
|
|
|
|
|
// .Select((d, pd, pa) => new
|
|
|
|
|
// {
|
|
|
|
|
// d.Id,
|
|
|
|
|
// d.ApplicationId,
|
|
|
|
|
// d.ApplyAmount,
|
|
|
|
|
// d.Currency,
|
|
|
|
|
// d.OriginalCurrency,
|
|
|
|
|
// d.OriginalAmount,
|
|
|
|
|
// pa.ApplicationNO,
|
|
|
|
|
// pa.Status,
|
|
|
|
|
// pa.CreateTime,
|
|
|
|
|
// pa.CreateBy,
|
|
|
|
|
// pa.PaymentDate,
|
|
|
|
|
// pa.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
|
|
|
|
|
// {
|
|
|
|
|
// ApplicationId = g.Key,
|
|
|
|
|
// //Ids = g.Select(x => x.Id),
|
|
|
|
|
// 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),
|
|
|
|
|
// ApplicationNO = firstItem.ApplicationNO,
|
|
|
|
|
// Status = (int)firstItem.Status,
|
|
|
|
|
// StatusText = firstItem.Status.GetDescription(),
|
|
|
|
|
// CreateTime = firstItem?.CreateTime,
|
|
|
|
|
// CreateBy = firstItem?.CreateBy,
|
|
|
|
|
// CreateByName = users.Find(x => x.Id == firstItem?.CreateBy)?.UserName,
|
|
|
|
|
// PaymentDate = firstItem?.PaymentDate,
|
|
|
|
|
// 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);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//return details;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|