|
|
@ -1,22 +1,15 @@
|
|
|
|
using DS.Module.Core;
|
|
|
|
using DS.Module.Core;
|
|
|
|
using DS.Module.Core.Enums;
|
|
|
|
using DS.Module.Core.Enums;
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
using DS.Module.UserModule;
|
|
|
|
|
|
|
|
using DS.WMS.ContainerManagement.Info.Entity;
|
|
|
|
|
|
|
|
using DS.WMS.Core.Application.Dtos;
|
|
|
|
|
|
|
|
using DS.WMS.Core.Application.Entity;
|
|
|
|
using DS.WMS.Core.Application.Entity;
|
|
|
|
using DS.WMS.Core.Fee.Entity;
|
|
|
|
using DS.WMS.Core.Fee.Entity;
|
|
|
|
using DS.WMS.Core.Fee.Method;
|
|
|
|
using DS.WMS.Core.Fee.Method;
|
|
|
|
using DS.WMS.Core.Invoice.Dtos;
|
|
|
|
|
|
|
|
using DS.WMS.Core.Settlement.Dtos;
|
|
|
|
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.Interface;
|
|
|
|
using DS.WMS.Core.Sys.Interface;
|
|
|
|
using Mapster;
|
|
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Org.BouncyCastle.Ocsp;
|
|
|
|
|
|
|
|
using SqlSugar;
|
|
|
|
using SqlSugar;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Settlement.Method
|
|
|
|
namespace DS.WMS.Core.Settlement.Method
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -29,10 +22,6 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
{
|
|
|
|
{
|
|
|
|
readonly Lazy<ICommonService> CommonService;
|
|
|
|
readonly Lazy<ICommonService> CommonService;
|
|
|
|
|
|
|
|
|
|
|
|
//readonly Lazy<IFreeSettlementService> FreeSettlementService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 初始化
|
|
|
|
/// 初始化
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -40,53 +29,6 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
public SettlementService(IServiceProvider serviceProvider) : base(serviceProvider)
|
|
|
|
public SettlementService(IServiceProvider serviceProvider) : base(serviceProvider)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CommonService = new Lazy<ICommonService>(serviceProvider.GetRequiredService<ICommonService>());
|
|
|
|
CommonService = new Lazy<ICommonService>(serviceProvider.GetRequiredService<ICommonService>());
|
|
|
|
|
|
|
|
|
|
|
|
//FreeSettlementService = new Lazy<IFreeSettlementService>(serviceProvider.GetRequiredService<IFreeSettlementService>());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 根据业务编号及类型获取关联费用记录
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="items">业务ID与业务类型</param>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
public async Task<DataResult<FeeForm>> GetFeesAsync(params FeeClient[] items)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var bizIds = items.Select(x => x.Id).Distinct();
|
|
|
|
|
|
|
|
var types = items.Select(x => x.BusinessType).Distinct();
|
|
|
|
|
|
|
|
var cIds = items.Select(x => x.CustomerId).Distinct();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var list = await TenantDb.Queryable<FeeRecord>()
|
|
|
|
|
|
|
|
.Where(f => bizIds.Contains(f.BusinessId) && types.Contains(f.BusinessType) && cIds.Contains(f.CustomerId) &&
|
|
|
|
|
|
|
|
f.FeeStatus == FeeStatus.AuditPassed && (f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount) != 0)
|
|
|
|
|
|
|
|
.Select(f => new FeeItem
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
RecordId = f.Id,
|
|
|
|
|
|
|
|
BusinessId = f.BusinessId,
|
|
|
|
|
|
|
|
BusinessType = f.BusinessType,
|
|
|
|
|
|
|
|
CustomerId = f.CustomerId,
|
|
|
|
|
|
|
|
CustomerName = f.CustomerName,
|
|
|
|
|
|
|
|
FeeId = f.FeeId,
|
|
|
|
|
|
|
|
FeeName = f.FeeName,
|
|
|
|
|
|
|
|
FeeType = f.FeeType,
|
|
|
|
|
|
|
|
TotalAmount = f.Amount,
|
|
|
|
|
|
|
|
Currency = f.Currency,
|
|
|
|
|
|
|
|
OriginalRate = f.ExchangeRate,
|
|
|
|
|
|
|
|
RestAmount = f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount,
|
|
|
|
|
|
|
|
InvoiceAmount = f.InvoiceAmount,
|
|
|
|
|
|
|
|
AccTaxRate = f.AccTaxRate,
|
|
|
|
|
|
|
|
Remark = f.Remark
|
|
|
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//本次结算金额默认等于剩余金额
|
|
|
|
|
|
|
|
item.Amount = item.RestAmount;
|
|
|
|
|
|
|
|
item.OriginalAmount = item.RestAmount;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult<FeeForm>.Success(new FeeForm(list));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -136,73 +78,21 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
settlement.CustomerName = first.CustomerName;
|
|
|
|
settlement.CustomerName = first.CustomerName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//var tempDetailList = request.Details.Select(x => new ApplicationDetail
|
|
|
|
details1 = request.Details.Select(x => new ApplicationDetail
|
|
|
|
//{
|
|
|
|
{
|
|
|
|
// RefId = x.ApplicationId,
|
|
|
|
RefId = x.ApplicationId,
|
|
|
|
// DetailId = x.Id,
|
|
|
|
DetailId = x.Id,
|
|
|
|
// RecordId = x.RecordId,
|
|
|
|
RecordId = x.RecordId,
|
|
|
|
// CustomerName = x.CustomerName ?? settlement.CustomerName,
|
|
|
|
CustomerName = x.CustomerName ?? settlement.CustomerName,
|
|
|
|
|
|
|
|
FeeId = x.FeeId,
|
|
|
|
// FeeId = x.FeeId,
|
|
|
|
FeeName = x.FeeName,
|
|
|
|
// FeeName = x.FeeName,
|
|
|
|
FeeType = x.FeeType,
|
|
|
|
// FeeType = x.FeeType,
|
|
|
|
ApplyAmount = x.RestAmount.GetValueOrDefault(),
|
|
|
|
// ApplyAmount = x.RestAmount.GetValueOrDefault(),
|
|
|
|
Currency = x.Currency,
|
|
|
|
// Currency = x.Currency,
|
|
|
|
ExchangeRate = x.ExchangeRate,
|
|
|
|
// ExchangeRate = x.ExchangeRate,
|
|
|
|
OriginalAmount = x.OriginalAmount,
|
|
|
|
// OriginalAmount = x.OriginalAmount,
|
|
|
|
OriginalCurrency = x.OriginalCurrency ?? (settlement.Currency.IsNullOrEmpty() ? x.Currency : settlement.Currency),
|
|
|
|
// OriginalCurrency = x.OriginalCurrency ?? (settlement.Currency.IsNullOrEmpty() ? x.Currency : settlement.Currency),
|
|
|
|
}).ToList();
|
|
|
|
//}).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if(tempDetailList.Count>0) details1 = new List<ApplicationDetail>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//foreach (var tempDetail in tempDetailList)
|
|
|
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
// if (tempDetail.DetailId != null)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// details1.Add(tempDetail);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// else {
|
|
|
|
|
|
|
|
// //20240929 该业务的所有符合条件的费用
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// var feeClient = new FeeClient();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// var _detail = request.Details.First(x => x.BusinessId == tempDetail.BusinessId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// feeClient.Id = _detail.BusinessId;
|
|
|
|
|
|
|
|
// feeClient.BusinessType = _detail.BusinessType;
|
|
|
|
|
|
|
|
// feeClient.CustomerId= request.Settlement.CustomerId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// var paramarray = new FeeClient[]{ feeClient};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// var feeListResult = await GetFeesAsync(paramarray);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// var feeList = feeListResult.Data.Items;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// var _detailList = feeList.Where(x => x.FeeType == tempDetail.FeeType && x.RestAmount > 0)
|
|
|
|
|
|
|
|
// .Select(x => new ApplicationDetail
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// RefId = x.BusinessId,
|
|
|
|
|
|
|
|
// DetailId = 0,
|
|
|
|
|
|
|
|
// RecordId = x.RecordId,
|
|
|
|
|
|
|
|
// CustomerName = x.CustomerName ?? settlement.CustomerName,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FeeId = x.FeeId,
|
|
|
|
|
|
|
|
// FeeName = x.FeeName,
|
|
|
|
|
|
|
|
// FeeType = x.FeeType,
|
|
|
|
|
|
|
|
// ApplyAmount = 0,
|
|
|
|
|
|
|
|
// Currency = x.Currency,
|
|
|
|
|
|
|
|
// ExchangeRate = tempDetail.ExchangeRate,
|
|
|
|
|
|
|
|
// OriginalAmount = 0,
|
|
|
|
|
|
|
|
// OriginalCurrency = x.Currency,
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// .ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// details1.AddRange(_detailList);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
details1 = await GetFeeDetailByBill(request);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//按付费/发票申请结算
|
|
|
|
//按付费/发票申请结算
|
|
|
@ -395,7 +285,7 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
if (settlement.Id == 0)
|
|
|
|
if (settlement.Id == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//创建时需要生成申请单编号
|
|
|
|
//创建时需要生成申请单编号
|
|
|
|
var sequence = CommonService.Value. GetSequenceNext<TEntity>();
|
|
|
|
var sequence = CommonService.Value.GetSequenceNext<TEntity>();
|
|
|
|
if (!sequence.Succeeded)
|
|
|
|
if (!sequence.Succeeded)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return DataResult<TEntity>.Failed(sequence.Message, MultiLanguageConst.SequenceSetNotExist);
|
|
|
|
return DataResult<TEntity>.Failed(sequence.Message, MultiLanguageConst.SequenceSetNotExist);
|
|
|
@ -451,85 +341,6 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 通过前端传递的仅包含businessid的ApplicationDetail 获取这些业务的所有指定结算对象的费用明细
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// 如果参数的明细当中包含Detailid 代表传递的是具体费用
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="BillList"></param>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
private async Task< List<ApplicationDetail>> GetFeeDetailByBill(SettlementRequest<TEntity> request)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var result = new List<ApplicationDetail>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var settlement = request.Settlement;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var tempDetailList = request.Details.Select(x => new ApplicationDetail
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
RefId = x.ApplicationId,
|
|
|
|
|
|
|
|
DetailId = x.Id,
|
|
|
|
|
|
|
|
RecordId = x.RecordId,
|
|
|
|
|
|
|
|
CustomerName = x.CustomerName ?? settlement.CustomerName,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FeeId = x.FeeId,
|
|
|
|
|
|
|
|
FeeName = x.FeeName,
|
|
|
|
|
|
|
|
FeeType = x.FeeType,
|
|
|
|
|
|
|
|
ApplyAmount = x.RestAmount.GetValueOrDefault(),
|
|
|
|
|
|
|
|
Currency = x.Currency,
|
|
|
|
|
|
|
|
ExchangeRate = x.ExchangeRate,
|
|
|
|
|
|
|
|
OriginalAmount = x.OriginalAmount,
|
|
|
|
|
|
|
|
OriginalCurrency = x.OriginalCurrency ?? (settlement.Currency.IsNullOrEmpty() ? x.Currency : settlement.Currency),
|
|
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var tempDetail in tempDetailList)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (tempDetail.RecordId != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
result.Add(tempDetail);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//20240929 该业务的所有符合条件的费用
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var feeClient = new FeeClient();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var _detail = request.Details.First(x => x.BusinessId == tempDetail.BusinessId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
feeClient.Id = _detail.BusinessId;
|
|
|
|
|
|
|
|
feeClient.BusinessType = _detail.BusinessType;
|
|
|
|
|
|
|
|
feeClient.CustomerId = request.Settlement.CustomerId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var paramarray = new FeeClient[] { feeClient };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var feeListResult = await GetFeesAsync(paramarray);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var feeList = feeListResult.Data.Items;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var _detailList = feeList.Where(x => x.FeeType == tempDetail.FeeType && x.RestAmount > 0)
|
|
|
|
|
|
|
|
.Select(x => new ApplicationDetail
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
RefId = x.BusinessId,
|
|
|
|
|
|
|
|
DetailId = 0,
|
|
|
|
|
|
|
|
RecordId = x.RecordId,
|
|
|
|
|
|
|
|
CustomerName = x.CustomerName ?? settlement.CustomerName,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FeeId = x.FeeId,
|
|
|
|
|
|
|
|
FeeName = x.FeeName,
|
|
|
|
|
|
|
|
FeeType = x.FeeType,
|
|
|
|
|
|
|
|
ApplyAmount = 0,
|
|
|
|
|
|
|
|
Currency = x.Currency,
|
|
|
|
|
|
|
|
ExchangeRate = tempDetail.ExchangeRate,
|
|
|
|
|
|
|
|
OriginalAmount = 0,
|
|
|
|
|
|
|
|
OriginalCurrency = x.Currency,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result.AddRange(_detailList);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 用于结算单的状态检查
|
|
|
|
/// 用于结算单的状态检查
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -772,34 +583,5 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
return Task.FromResult(new List<SettlementDetailDto>());
|
|
|
|
return Task.FromResult(new List<SettlementDetailDto>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 获取待结算费用明细的原始币别
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="documents"></param>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
public async Task<DataResult<List<SettlementDocument>>> GetExchangesAsync(SettlementRequest<TEntity> request)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var details = await GetFeeDetailByBill(request);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var result = new List<SettlementDocument>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in request.Details)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var document = item.Adapt<SettlementDocument>();
|
|
|
|
|
|
|
|
document.Id = item.BusinessId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (details.Exists(x => x.BusinessId == document.Id)) {
|
|
|
|
|
|
|
|
foreach (var detail in details.Where(x => x.BusinessId == document.Id))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!document.ExchangeRates.Exists(x => x.Currency == item.OriginalCurrency))
|
|
|
|
|
|
|
|
document.ExchangeRates.Add(new CurrencyExchangeRate { Currency = item.OriginalCurrency });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
result.Add(document);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult<List<SettlementDocument>>.Success(result);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|