|
|
|
@ -6,6 +6,7 @@ using DS.WMS.Core.Application.Dtos;
|
|
|
|
|
using DS.WMS.Core.Application.Entity;
|
|
|
|
|
using DS.WMS.Core.Code.Entity;
|
|
|
|
|
using DS.WMS.Core.Fee.Entity;
|
|
|
|
|
using DS.WMS.Core.Invoice.Dtos;
|
|
|
|
|
using DS.WMS.Core.Op.Entity;
|
|
|
|
|
using DS.WMS.Core.Settlement.Dtos;
|
|
|
|
|
using DS.WMS.Core.Settlement.Entity;
|
|
|
|
@ -109,7 +110,7 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
return DataResult<PaymentSettlementDto>.Success(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取结算明细
|
|
|
|
|
protected virtual async Task<List<SettlementDetailDto>> GetSettlementDetails(long id)
|
|
|
|
|
{
|
|
|
|
|
var list = await TenantDb.Queryable<ApplicationDetail>()
|
|
|
|
@ -332,6 +333,36 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
return DataResult<List<PaymentApplicationDetailDto>>.Success(details);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取发票费用明细的原始币别
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="documents"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<List<SettlementDocument>>> GetExchangesAsync(List<SettlementDocument> documents)
|
|
|
|
|
{
|
|
|
|
|
var ids = documents.Select(x => x.Id);
|
|
|
|
|
var list = await TenantDb.Queryable<ApplicationDetail>()
|
|
|
|
|
.Where(d => ids.Contains(d.ApplicationId) && (d.Category == DetailCategory.PaidApplication || d.Category == DetailCategory.ChargeApplication))
|
|
|
|
|
.Select(d => new
|
|
|
|
|
{
|
|
|
|
|
d.ApplicationId,
|
|
|
|
|
d.OriginalCurrency
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
foreach (var document in documents)
|
|
|
|
|
{
|
|
|
|
|
document.ExchangeRates ??= [];
|
|
|
|
|
//获取该发票费用明细的全部币别
|
|
|
|
|
var items = list.FindAll(x => x.ApplicationId == document.Id);
|
|
|
|
|
foreach (var item in items)
|
|
|
|
|
{
|
|
|
|
|
if (!document.ExchangeRates.Exists(x => x.Currency == item.OriginalCurrency))
|
|
|
|
|
document.ExchangeRates.Add(new CurrencyExchangeRate { Currency = item.OriginalCurrency });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult<List<SettlementDocument>>.Success(documents);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal async Task FulfillDetailsAsync(List<PaymentApplicationDetailDto> details)
|
|
|
|
|
{
|
|
|
|
@ -446,7 +477,7 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
return sb.Length > 0 ? DataResult.Failed(sb.ToString()) : DataResult.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task OnSaveAsync(Entity.ApplicationSettlement settlement)
|
|
|
|
|
protected override async Task OnSaveAsync(ApplicationSettlement settlement)
|
|
|
|
|
{
|
|
|
|
|
//更新付费申请明细的已处理金额
|
|
|
|
|
var list = settlement.Details.Select(x => new ApplicationDetail
|
|
|
|
@ -463,20 +494,23 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task<Entity.ApplicationSettlement> PostSaveAsync(Entity.ApplicationSettlement settlement)
|
|
|
|
|
protected override async Task<ApplicationSettlement> PostSaveAsync(ApplicationSettlement settlement)
|
|
|
|
|
{
|
|
|
|
|
//回写付费申请的状态
|
|
|
|
|
var ids = settlement.Details.Select(x => x.DetailId);
|
|
|
|
|
var appIds = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids.Contains(x.Id) && x.Category == DetailCategory.PaidApplication)
|
|
|
|
|
var appIds = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids.Contains(x.Id) && (x.Category == DetailCategory.PaidApplication || x.Category == DetailCategory.ChargeApplication))
|
|
|
|
|
.Select(x => x.ApplicationId).ToListAsync();
|
|
|
|
|
|
|
|
|
|
var details = await TenantDb.Queryable<ApplicationDetail>().Where(x => appIds.Contains(x.ApplicationId) && x.Category == DetailCategory.PaidApplication).GroupBy(x => x.ApplicationId).Select(x => new
|
|
|
|
|
{
|
|
|
|
|
x.ApplicationId,
|
|
|
|
|
Count = SqlFunc.AggregateCount(x.Id),
|
|
|
|
|
ProcessedCount = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => y.ApplicationId == x.ApplicationId &&
|
|
|
|
|
y.Category == DetailCategory.PaidApplication && y.OriginalAmount - y.OriginalProcessedAmount == 0).Count()
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
var details = await TenantDb.Queryable<ApplicationDetail>().Where(x => appIds.Contains(x.ApplicationId) &&
|
|
|
|
|
(x.Category == DetailCategory.PaidApplication || x.Category == DetailCategory.ChargeApplication))
|
|
|
|
|
.GroupBy(x => x.ApplicationId).Select(x => new
|
|
|
|
|
{
|
|
|
|
|
x.ApplicationId,
|
|
|
|
|
Count = SqlFunc.AggregateCount(x.Id),
|
|
|
|
|
ProcessedCount = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => appIds.Contains(y.ApplicationId) &&
|
|
|
|
|
(y.Category == DetailCategory.PaidApplication || y.Category == DetailCategory.ChargeApplication) &&
|
|
|
|
|
y.OriginalAmount - y.OriginalProcessedAmount == 0).Count()
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
List<PaymentApplication> applications = [];
|
|
|
|
|
foreach (var item in details)
|
|
|
|
@ -489,21 +523,20 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
{
|
|
|
|
|
entity.Status = PaymentApplicationStatus.SettlementCompleted;
|
|
|
|
|
}
|
|
|
|
|
else if (item.ProcessedCount > 0)
|
|
|
|
|
else if (item.ProcessedCount != 0)
|
|
|
|
|
{
|
|
|
|
|
entity.Status = PaymentApplicationStatus.PartialSettlement;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
applications.Add(entity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await TenantDb.Updateable(applications).UpdateColumns(x => new { x.Status }).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
return await base.PostSaveAsync(settlement);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override DataResult PreDelete(List<Entity.ApplicationSettlement> settlements)
|
|
|
|
|
protected override DataResult PreDelete(List<ApplicationSettlement> settlements)
|
|
|
|
|
{
|
|
|
|
|
if (settlements.Any(x => x.IsLocked))
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.SettlementIsLocked));
|
|
|
|
@ -511,7 +544,7 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
return DataResult.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task OnDeleteDetailAsync(List<Entity.ApplicationSettlement> settlements)
|
|
|
|
|
protected override async Task OnDeleteDetailAsync(List<ApplicationSettlement> settlements)
|
|
|
|
|
{
|
|
|
|
|
await base.OnDeleteDetailAsync(settlements);
|
|
|
|
|
|
|
|
|
|