|
|
@ -12,7 +12,6 @@ using DS.WMS.Core.Settlement.Dtos;
|
|
|
|
using DS.WMS.Core.Settlement.Entity;
|
|
|
|
using DS.WMS.Core.Settlement.Entity;
|
|
|
|
using DS.WMS.Core.Settlement.Interface;
|
|
|
|
using DS.WMS.Core.Settlement.Interface;
|
|
|
|
using DS.WMS.Core.Sys.Entity;
|
|
|
|
using DS.WMS.Core.Sys.Entity;
|
|
|
|
using Masuit.Tools.Systems;
|
|
|
|
|
|
|
|
using SqlSugar;
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Settlement.Method
|
|
|
|
namespace DS.WMS.Core.Settlement.Method
|
|
|
@ -113,81 +112,99 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
return DataResult<ApplicationSettlementDto>.Success(model);
|
|
|
|
return DataResult<ApplicationSettlementDto>.Success(model);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//获取结算明细
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 获取费用申请结算明细
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
protected override async Task<List<SettlementDetailDto>> GetSettlementDetails(long id)
|
|
|
|
protected override async Task<List<SettlementDetailDto>> GetSettlementDetails(long id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var list = await TenantDb.Queryable<ApplicationDetail>()
|
|
|
|
var list = await TenantDb.Queryable<PaymentApplication>()
|
|
|
|
.InnerJoin<ApplicationDetail>((d, pd) => d.DetailId == pd.Id)
|
|
|
|
.InnerJoin<ApplicationDetail>((i, d1) => i.Id == d1.ApplicationId)
|
|
|
|
.InnerJoin<PaymentApplication>((d, pd, pa) => pd.ApplicationId == pa.Id)
|
|
|
|
.InnerJoin<ApplicationDetail>((i, d1, d2) => d1.ApplicationId == d2.RefId)
|
|
|
|
.Where(d => d.ApplicationId == id)
|
|
|
|
.Where((i, d1, d2) => d2.ApplicationId == id &&
|
|
|
|
.Select((d, pd, pa) => new
|
|
|
|
d2.Category == DetailCategory.PaidApplication && d1.Category == DetailCategory.ChargeApplication)
|
|
|
|
{
|
|
|
|
.GroupBy((i, d1, d2) => i.Id)
|
|
|
|
d.Id,
|
|
|
|
.Select((i, d1, d2) => new SettlementDetailDto
|
|
|
|
d.ApplicationId,
|
|
|
|
{
|
|
|
|
d.ApplyAmount,
|
|
|
|
SettlementAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(d3 => d3.ApplicationId == i.Id).Sum(d3 => d3.ApplyAmount),
|
|
|
|
d.Currency,
|
|
|
|
ApplicationNOList = SqlFunc.Subqueryable<PaymentApplication>().Where(a => a.Id == d1.RefId).ToList(a => a.ApplicationNO)
|
|
|
|
d.OriginalCurrency,
|
|
|
|
}, true).ToListAsync();
|
|
|
|
d.OriginalAmount,
|
|
|
|
|
|
|
|
pa.ApplicationNO,
|
|
|
|
return list;
|
|
|
|
pa.Status,
|
|
|
|
|
|
|
|
pa.CreateTime,
|
|
|
|
//var list = await TenantDb.Queryable<ApplicationDetail>()
|
|
|
|
pa.CreateBy,
|
|
|
|
// .InnerJoin<ApplicationDetail>((d, pd) => d.DetailId == pd.Id)
|
|
|
|
pa.PaymentDate,
|
|
|
|
// .InnerJoin<PaymentApplication>((d, pd, pa) => pd.ApplicationId == pa.Id)
|
|
|
|
pa.Note
|
|
|
|
// .Where(d => d.ApplicationId == id)
|
|
|
|
}).ToListAsync();
|
|
|
|
// .Select((d, pd, pa) => new
|
|
|
|
|
|
|
|
// {
|
|
|
|
var details = new List<SettlementDetailDto>();
|
|
|
|
// d.Id,
|
|
|
|
if (list.Count == 0)
|
|
|
|
// d.ApplicationId,
|
|
|
|
return details;
|
|
|
|
// d.ApplyAmount,
|
|
|
|
|
|
|
|
// d.Currency,
|
|
|
|
var gp = list.GroupBy(d => d.ApplicationId);
|
|
|
|
// d.OriginalCurrency,
|
|
|
|
var uids = list.Select(x => x.CreateBy).Distinct();
|
|
|
|
// d.OriginalAmount,
|
|
|
|
var users = await Db.Queryable<SysUser>().Where(x => uids.Contains(x.Id)).Select(x => new
|
|
|
|
// pa.ApplicationNO,
|
|
|
|
{
|
|
|
|
// pa.Status,
|
|
|
|
x.Id,
|
|
|
|
// pa.CreateTime,
|
|
|
|
x.UserName
|
|
|
|
// pa.CreateBy,
|
|
|
|
}).ToListAsync();
|
|
|
|
// pa.PaymentDate,
|
|
|
|
|
|
|
|
// pa.Note
|
|
|
|
foreach (var g in gp)
|
|
|
|
// }).ToListAsync();
|
|
|
|
{
|
|
|
|
|
|
|
|
var firstItem = g.FirstOrDefault();
|
|
|
|
//var details = new List<SettlementDetailDto>();
|
|
|
|
|
|
|
|
//if (list.Count == 0)
|
|
|
|
var dto = new SettlementDetailDto
|
|
|
|
// return details;
|
|
|
|
{
|
|
|
|
|
|
|
|
ApplicationId = g.Key,
|
|
|
|
//var gp = list.GroupBy(d => d.ApplicationId);
|
|
|
|
//Ids = g.Select(x => x.Id),
|
|
|
|
//var uids = list.Select(x => x.CreateBy).Distinct();
|
|
|
|
RMBApplyAmount = g.Where(x => x.OriginalCurrency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount),
|
|
|
|
//var users = await Db.Queryable<SysUser>().Where(x => uids.Contains(x.Id)).Select(x => new
|
|
|
|
USDApplyAmount = g.Where(x => x.OriginalCurrency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount),
|
|
|
|
//{
|
|
|
|
ApplicationNO = firstItem.ApplicationNO,
|
|
|
|
// x.Id,
|
|
|
|
Status = (int)firstItem.Status,
|
|
|
|
// x.UserName
|
|
|
|
StatusText = firstItem.Status.GetDescription(),
|
|
|
|
//}).ToListAsync();
|
|
|
|
CreateTime = firstItem?.CreateTime,
|
|
|
|
|
|
|
|
CreateBy = firstItem?.CreateBy,
|
|
|
|
//foreach (var g in gp)
|
|
|
|
CreateByName = users.Find(x => x.Id == firstItem?.CreateBy)?.UserName,
|
|
|
|
//{
|
|
|
|
PaymentDate = firstItem?.PaymentDate,
|
|
|
|
// var firstItem = g.FirstOrDefault();
|
|
|
|
Note = firstItem?.Note
|
|
|
|
|
|
|
|
};
|
|
|
|
// var dto = new SettlementDetailDto
|
|
|
|
|
|
|
|
// {
|
|
|
|
//包含多个币别
|
|
|
|
// ApplicationId = g.Key,
|
|
|
|
if (g.GroupBy(x => x.OriginalCurrency).Select(x => x.Key).Count() > 1)
|
|
|
|
// //Ids = g.Select(x => x.Id),
|
|
|
|
{
|
|
|
|
// RMBApplyAmount = g.Where(x => x.OriginalCurrency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount),
|
|
|
|
//原始币别=不等于结算单币别的首个币别(参考DS7)
|
|
|
|
// USDApplyAmount = g.Where(x => x.OriginalCurrency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount),
|
|
|
|
dto.OriginalCurrency = g.Select(x => x.OriginalCurrency).FirstOrDefault();
|
|
|
|
// ApplicationNO = firstItem.ApplicationNO,
|
|
|
|
//原始金额=当前结算单的币别合计
|
|
|
|
// Status = (int)firstItem.Status,
|
|
|
|
dto.OriginalAmount = g.Sum(x => x.ApplyAmount);
|
|
|
|
// StatusText = firstItem.Status.GetDescription(),
|
|
|
|
}
|
|
|
|
// CreateTime = firstItem?.CreateTime,
|
|
|
|
else
|
|
|
|
// CreateBy = firstItem?.CreateBy,
|
|
|
|
{
|
|
|
|
// CreateByName = users.Find(x => x.Id == firstItem?.CreateBy)?.UserName,
|
|
|
|
dto.OriginalCurrency = firstItem?.OriginalCurrency;
|
|
|
|
// PaymentDate = firstItem?.PaymentDate,
|
|
|
|
dto.OriginalAmount = g.Where(x => x.OriginalCurrency == dto.OriginalCurrency).Sum(x => x.ApplyAmount);
|
|
|
|
// Note = firstItem?.Note
|
|
|
|
}
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
//结算金额=原申请的原始币别合计
|
|
|
|
// //包含多个币别
|
|
|
|
dto.SettlementAmount = g.Where(x => x.OriginalCurrency == dto.OriginalCurrency).Sum(x => x.ApplyAmount);
|
|
|
|
// if (g.GroupBy(x => x.OriginalCurrency).Select(x => x.Key).Count() > 1)
|
|
|
|
details.Add(dto);
|
|
|
|
// {
|
|
|
|
}
|
|
|
|
// //原始币别=不等于结算单币别的首个币别(参考DS7)
|
|
|
|
|
|
|
|
// dto.OriginalCurrency = g.Select(x => x.OriginalCurrency).FirstOrDefault();
|
|
|
|
return details;
|
|
|
|
// //原始金额=当前结算单的币别合计
|
|
|
|
|
|
|
|
// 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>
|
|
|
|
/// <summary>
|
|
|
|