|
|
|
@ -5,7 +5,6 @@ using DS.Module.Core.Enums;
|
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
|
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;
|
|
|
|
@ -49,21 +48,19 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
ApplicationNO = x.ApplicationNO,
|
|
|
|
|
SettlementNO = x.SettlementNO,
|
|
|
|
|
SettlementTypeName = x.SettlementType.StlName, //结算方式
|
|
|
|
|
|
|
|
|
|
RMBAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => y.ApplicationId == x.Id && y.OriginalCurrency == FeeCurrency.RMB_CODE)
|
|
|
|
|
.Select(y => SqlFunc.AggregateSum(y.OriginalAmount)),
|
|
|
|
|
|
|
|
|
|
USDAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => y.ApplicationId == x.Id && y.OriginalCurrency == FeeCurrency.USD_CODE)
|
|
|
|
|
.Select(y => SqlFunc.AggregateSum(y.OriginalAmount)),
|
|
|
|
|
|
|
|
|
|
OtherAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => y.ApplicationId == x.Id && y.OriginalCurrency != FeeCurrency.RMB_CODE && y.OriginalCurrency != FeeCurrency.USD_CODE)
|
|
|
|
|
.Select(y => SqlFunc.AggregateSum(y.OriginalAmount)),
|
|
|
|
|
//-----结算金额统计-----
|
|
|
|
|
RMBAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => y.ApplicationId == x.Id && y.Currency == FeeCurrency.RMB_CODE)
|
|
|
|
|
.Select(y => SqlFunc.AggregateSum(y.ApplyAmount)),
|
|
|
|
|
USDAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => y.ApplicationId == x.Id && y.Currency == FeeCurrency.USD_CODE)
|
|
|
|
|
.Select(y => SqlFunc.AggregateSum(y.ApplyAmount)),
|
|
|
|
|
OtherAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => y.ApplicationId == x.Id && y.Currency != FeeCurrency.RMB_CODE && y.Currency != FeeCurrency.USD_CODE)
|
|
|
|
|
.Select(y => SqlFunc.AggregateSum(y.ApplyAmount)),
|
|
|
|
|
|
|
|
|
|
CustomerAccount = x.CustomerBank.AccountName + "/" + x.CustomerBank.Currency,
|
|
|
|
|
CustomerBankName = x.CustomerBank.BankName,
|
|
|
|
|
//未开票
|
|
|
|
|
UnInvoiceList = SqlFunc.Subqueryable<ApplicationDetail>().InnerJoin<FeeRecord>((d, f) => d.ApplicationId == x.Id && d.RecordId == f.Id)
|
|
|
|
|
.GroupBy((d, f) => f.Currency).ToList((d, f) => new CurrencyAmount { Currency = f.Currency, Amount = SqlFunc.AggregateSum(f.Amount - f.InvoiceAmount) }),
|
|
|
|
|
.GroupBy((d, f) => new { f.BusinessId, f.BusinessType, f.Currency }).ToList((d, f) => new CurrencyAmount { Currency = f.Currency, Amount = SqlFunc.AggregateSum(f.Amount - f.InvoiceAmount) }),
|
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
|
|
var whereList = request.GetConditionalModels(Db);
|
|
|
|
@ -143,7 +140,7 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取费用申请结算明细
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <param name="id">结算单ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected override async Task<List<SettlementDetailGroup>> GetSettlementDetails(long id)
|
|
|
|
|
{
|
|
|
|
@ -159,16 +156,11 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
Id = pa.Id,
|
|
|
|
|
Status = (int)pa.Status,
|
|
|
|
|
BillNO = pa.ApplicationNO,
|
|
|
|
|
PaymentDate = pa.PaymentDate,
|
|
|
|
|
//RMBApplyAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(x => x.ApplicationId == d2.RefId && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount),
|
|
|
|
|
//USDApplyAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(x => x.ApplicationId == d2.RefId && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount),
|
|
|
|
|
//RMBStlAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(x => x.ApplicationId == i.Id && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount),
|
|
|
|
|
//USDStlAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(x => x.ApplicationId == i.Id && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount),
|
|
|
|
|
//RMBStlRestAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(x => x.ApplicationId == i.Id && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount - x.ProcessedAmount),
|
|
|
|
|
//USDStlRestAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(x => x.ApplicationId == i.Id && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount - x.ProcessedAmount),
|
|
|
|
|
PaymentDate = pa.PaymentDate
|
|
|
|
|
}, true).ToListAsync();
|
|
|
|
|
|
|
|
|
|
var ids = list.Select(x => x.Id);
|
|
|
|
|
//获取原申请明细
|
|
|
|
|
var appDetails = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids.Contains(x.ApplicationId))
|
|
|
|
|
.Select(x => new
|
|
|
|
|
{
|
|
|
|
@ -182,6 +174,21 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
x.OriginalProcessedAmount
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
//获取结算单明细
|
|
|
|
|
var stlDetails = await TenantDb.Queryable<ApplicationDetail>().Where(x => x.ApplicationId == id)
|
|
|
|
|
.Select(x => new
|
|
|
|
|
{
|
|
|
|
|
x.ApplicationId,
|
|
|
|
|
x.DetailId,
|
|
|
|
|
x.RefId,
|
|
|
|
|
x.Currency,
|
|
|
|
|
x.OriginalCurrency,
|
|
|
|
|
x.ApplyAmount,
|
|
|
|
|
x.OriginalAmount,
|
|
|
|
|
x.ProcessedAmount,
|
|
|
|
|
x.OriginalProcessedAmount
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
PaymentApplicationStatus status = (PaymentApplicationStatus)item.Status;
|
|
|
|
@ -191,14 +198,12 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
var details = appDetails.Where(x => x.ApplicationId == item.Id);
|
|
|
|
|
item.RMBApplyAmount = details.Where(x => x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount);
|
|
|
|
|
item.USDApplyAmount = details.Where(x => x.Currency == FeeCurrency.USD_CODE).Sum(x => x.ApplyAmount);
|
|
|
|
|
|
|
|
|
|
//未结金额
|
|
|
|
|
item.RMBStlRestAmount = details.Where(x => appIds.Contains(x.Id) && x.OriginalCurrency == FeeCurrency.RMB_CODE).Sum(x => x.OriginalAmount - x.OriginalProcessedAmount);
|
|
|
|
|
item.USDStlRestAmount = details.Where(x => appIds.Contains(x.Id) && x.OriginalCurrency == FeeCurrency.USD_CODE).Sum(x => x.OriginalAmount - x.OriginalProcessedAmount);
|
|
|
|
|
//本次结算金额
|
|
|
|
|
item.RMBStlAmount = details.Where(x => appIds.Contains(x.Id) && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ProcessedAmount);
|
|
|
|
|
item.USDStlAmount = details.Where(x => appIds.Contains(x.Id) && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.ProcessedAmount);
|
|
|
|
|
|
|
|
|
|
//剩余未结金额
|
|
|
|
|
item.RMBStlRestAmount = details.Where(x => appIds.Contains(x.Id) && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount - x.ProcessedAmount);
|
|
|
|
|
item.RMBStlRestAmount = details.Where(x => appIds.Contains(x.Id) && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.ApplyAmount - x.ProcessedAmount);
|
|
|
|
|
item.RMBStlAmount = stlDetails.Where(x => x.RefId == item.Id && x.OriginalCurrency == FeeCurrency.RMB_CODE).Sum(x => x.OriginalAmount);
|
|
|
|
|
item.USDStlAmount = stlDetails.Where(x => x.RefId == item.Id && x.OriginalCurrency == FeeCurrency.USD_CODE).Sum(x => x.OriginalAmount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
@ -215,49 +220,6 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
return DataResult<List<SettlementDetailGroup>>.Success(details);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据申请获取费用明细
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ids">申请单ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<List<PaymentApplicationDetailDto>>> GetSettlementFeeDetailsAsync(params long[] ids)
|
|
|
|
|
{
|
|
|
|
|
var details = await CreateApplicationDetailQuery((d, f, s) => ids.Contains(d.ApplicationId))
|
|
|
|
|
.LeftJoin<PaymentApplication>((d, pa) => d.ApplicationId == pa.Id)
|
|
|
|
|
.Select((d, pa) => new PaymentApplicationDetailDto
|
|
|
|
|
{
|
|
|
|
|
Id = d.Id,
|
|
|
|
|
ApplicationId = d.ApplicationId,
|
|
|
|
|
BusinessId = d.BusinessId,
|
|
|
|
|
BusinessType = d.BusinessType,
|
|
|
|
|
RecordId = d.RecordId,
|
|
|
|
|
FeeName = d.FeeName,
|
|
|
|
|
FeeType = d.FeeType,
|
|
|
|
|
Amount = d.Amount, //总金额
|
|
|
|
|
ApplyAmount = d.ApplyAmount, //已结算金额
|
|
|
|
|
SettlementAmount = d.ApplyAmount,
|
|
|
|
|
RestAmount = d.ApplyAmount - d.ProcessedAmount, //剩余结算金额
|
|
|
|
|
CustomerId = d.CustomerId,
|
|
|
|
|
CustomerName = d.CustomerName,
|
|
|
|
|
OriginalCurrency = d.OriginalCurrency, //原始币别
|
|
|
|
|
OriginalRate = d.ExchangeRate, //原始汇率
|
|
|
|
|
ExchangeRate = d.ExchangeRate, //折算汇率
|
|
|
|
|
OriginalAmount = d.OriginalAmount, //原始金额
|
|
|
|
|
CustomerNo = d.CustomerNo,
|
|
|
|
|
MBLNO = d.MBLNO,
|
|
|
|
|
HBLNO = d.HBLNO,
|
|
|
|
|
ETD = d.ETD,
|
|
|
|
|
SourceName = d.SourceName,
|
|
|
|
|
SaleName = d.SaleName,
|
|
|
|
|
AccountDate = d.AccountDate,
|
|
|
|
|
Vessel = d.Vessel,
|
|
|
|
|
Voyage = d.Voyage,
|
|
|
|
|
InvoiceNO = pa.InvoiceNO
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
return DataResult<List<PaymentApplicationDetailDto>>.Success(details);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取待结算的申请分页列表
|
|
|
|
|
/// </summary>
|
|
|
|
@ -328,39 +290,50 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
/// 获取申请单费用明细
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">申请单ID</param>
|
|
|
|
|
/// <param name="currency">结算币别</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<List<PaymentApplicationDetailDto>>> GetApplicationDetailsAsync(long id, string currency)
|
|
|
|
|
public async Task<DataResult<List<PaymentApplicationDetailDto>>> GetApplicationDetailsAsync(long id, string? currency = null)
|
|
|
|
|
{
|
|
|
|
|
var details = await TenantDb.Queryable<ApplicationDetail>().Where(d => d.ApplicationId == id && (d.ApplyAmount - d.ProcessedAmount) != 0)
|
|
|
|
|
.InnerJoin<FeeRecord>((d, f) => d.RecordId == f.Id)
|
|
|
|
|
.WhereIF(!string.IsNullOrEmpty(currency), x => x.Currency == currency)
|
|
|
|
|
.Select((d, f) => new PaymentApplicationDetailDto
|
|
|
|
|
var details = await CreateApplicationDetailQuery((d, f, s) => d.ApplicationId == id)
|
|
|
|
|
.LeftJoin<PaymentApplication>((d, pa) => d.ApplicationId == pa.Id)
|
|
|
|
|
.WhereIF(!string.IsNullOrEmpty(currency), d => d.Currency == currency)
|
|
|
|
|
.Select((d, pa) => new PaymentApplicationDetailDto
|
|
|
|
|
{
|
|
|
|
|
Id = d.Id,
|
|
|
|
|
ApplicationId = d.ApplicationId,
|
|
|
|
|
BusinessId = f.BusinessId,
|
|
|
|
|
BusinessType = f.BusinessType,
|
|
|
|
|
BusinessId = d.BusinessId,
|
|
|
|
|
BusinessType = d.BusinessType,
|
|
|
|
|
RecordId = d.RecordId,
|
|
|
|
|
FeeName = d.FeeName,
|
|
|
|
|
FeeType = d.FeeType, //收付
|
|
|
|
|
Amount = d.ApplyAmount, //申请金额
|
|
|
|
|
ApplyAmount = f.SettlementAmount, //已结算金额
|
|
|
|
|
FeeType = d.FeeType,
|
|
|
|
|
Amount = d.Amount, //总金额
|
|
|
|
|
Currency = d.Currency,
|
|
|
|
|
ApplyAmount = d.ApplyAmount, //申请金额
|
|
|
|
|
SettlementAmount = d.ProcessedAmount,
|
|
|
|
|
RestAmount = d.ApplyAmount - d.ProcessedAmount, //剩余结算金额
|
|
|
|
|
CustomerId = f.CustomerId,
|
|
|
|
|
CustomerId = d.CustomerId,
|
|
|
|
|
CustomerName = d.CustomerName,
|
|
|
|
|
OriginalCurrency = d.OriginalCurrency, //原始币别
|
|
|
|
|
OriginalRate = f.ExchangeRate, //原始汇率
|
|
|
|
|
OriginalRate = d.ExchangeRate, //原始汇率
|
|
|
|
|
ExchangeRate = d.ExchangeRate, //折算汇率
|
|
|
|
|
OriginalAmount = d.OriginalAmount //原始金额
|
|
|
|
|
OriginalAmount = d.OriginalAmount, //原始金额
|
|
|
|
|
CustomerNo = d.CustomerNo,
|
|
|
|
|
MBLNO = d.MBLNO,
|
|
|
|
|
HBLNO = d.HBLNO,
|
|
|
|
|
ETD = d.ETD,
|
|
|
|
|
SourceName = d.SourceName,
|
|
|
|
|
SaleName = d.SaleName,
|
|
|
|
|
AccountDate = d.AccountDate,
|
|
|
|
|
Vessel = d.Vessel,
|
|
|
|
|
Voyage = d.Voyage,
|
|
|
|
|
InvoiceNO = pa.InvoiceNO
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
await FulfillDetailsAsync(details);
|
|
|
|
|
|
|
|
|
|
return DataResult<List<PaymentApplicationDetailDto>>.Success(details);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取发票费用明细的原始币别
|
|
|
|
|
/// 获取申请单费用明细的币别
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="documents"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
@ -372,77 +345,24 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
.Select(d => new
|
|
|
|
|
{
|
|
|
|
|
d.ApplicationId,
|
|
|
|
|
d.OriginalCurrency
|
|
|
|
|
d.Currency
|
|
|
|
|
}).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 });
|
|
|
|
|
if (!document.ExchangeRates.Exists(x => x.Currency == item.Currency))
|
|
|
|
|
document.ExchangeRates.Add(new CurrencyExchangeRate { Currency = item.Currency });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult<List<SettlementDocument>>.Success(documents);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal async Task FulfillDetailsAsync(List<PaymentApplicationDetailDto> details)
|
|
|
|
|
{
|
|
|
|
|
if (details.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var gList = details.GroupBy(x => x.BusinessType);
|
|
|
|
|
foreach (var g in gList)
|
|
|
|
|
{
|
|
|
|
|
var ids = g.Select(x => x.BusinessId);
|
|
|
|
|
switch (g.Key)
|
|
|
|
|
{
|
|
|
|
|
case BusinessType.OceanShippingExport:
|
|
|
|
|
var list1 = await TenantDb.Queryable<SeaExport>().Where(s => ids.Contains(s.Id))
|
|
|
|
|
.LeftJoin<CodeSource>((s, cs) => s.SourceId == cs.Id)
|
|
|
|
|
.Select((s, cs) => new
|
|
|
|
|
{
|
|
|
|
|
s.Id,
|
|
|
|
|
s.AccountDate,//会计期间
|
|
|
|
|
s.Vessel, //船名
|
|
|
|
|
s.Voyno, //航次
|
|
|
|
|
s.CustomerName,
|
|
|
|
|
s.MBLNO, //主提单号
|
|
|
|
|
s.CustomerNo, //委托编号
|
|
|
|
|
s.ETD, //开船日期
|
|
|
|
|
s.Sale, //揽货人
|
|
|
|
|
cs.SourceName, //业务来源
|
|
|
|
|
s.Note
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
foreach (var item in g)
|
|
|
|
|
{
|
|
|
|
|
var biz = list1.Find(x => x.Id == item.BusinessId);
|
|
|
|
|
if (biz != null)
|
|
|
|
|
{
|
|
|
|
|
item.MBLNO = biz.MBLNO;
|
|
|
|
|
item.CustomerNo = biz.CustomerNo;
|
|
|
|
|
item.ClientName = biz.CustomerName;
|
|
|
|
|
item.ETD = biz.ETD;
|
|
|
|
|
item.SourceName = biz.SourceName;
|
|
|
|
|
item.SaleName = biz.Sale;
|
|
|
|
|
item.AccountDate = biz.AccountDate;
|
|
|
|
|
item.Vessel = biz.Vessel;
|
|
|
|
|
item.Voyage = biz.Voyno;
|
|
|
|
|
item.Note = biz.Note;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BusinessType.OceanShippingImport:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存申请结算
|
|
|
|
|
/// </summary>
|
|
|
|
@ -527,14 +447,14 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(settlement.Currency)) //指定结算币别
|
|
|
|
|
{
|
|
|
|
|
var details2 = details1.FindAll(x => x.OriginalCurrency != settlement.Currency);
|
|
|
|
|
var details2 = details1.FindAll(x => x.Currency != settlement.Currency);
|
|
|
|
|
foreach (var detail in details2)
|
|
|
|
|
{
|
|
|
|
|
var doc = request.Documents.Find(x => x.Id == detail.RefId);
|
|
|
|
|
if (doc == null)
|
|
|
|
|
return DataResult<ApplicationSettlement>.Failed("结算单据与费用明细不一致");
|
|
|
|
|
|
|
|
|
|
var exchange = doc.ExchangeRates?.Find(x => x.Currency == detail.OriginalCurrency);
|
|
|
|
|
var exchange = doc.ExchangeRates?.Find(x => x.Currency == detail.Currency);
|
|
|
|
|
if (exchange == null)
|
|
|
|
|
return DataResult<ApplicationSettlement>.Failed($"未传入结算币别 {settlement.Currency} 与费用原币别 {detail.OriginalCurrency} 之间的汇率信息");
|
|
|
|
|
|
|
|
|
@ -551,21 +471,21 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
|
|
|
|
|
if (doc.SettlementRMB.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var rmbDetails = details2.Where(x => x.OriginalCurrency == FeeCurrency.RMB_CODE).ToList();
|
|
|
|
|
var rmbDetails = details2.Where(x => x.Currency == FeeCurrency.RMB_CODE).ToList();
|
|
|
|
|
result = AssignAmount(rmbDetails, doc.SettlementRMB.Value, settlement.Currency);
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
return DataResult<ApplicationSettlement>.Failed(result.Message, result.MultiCode);
|
|
|
|
|
}
|
|
|
|
|
if (doc.SettlementUSD.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var usdDetails = details2.Where(x => x.OriginalCurrency == FeeCurrency.USD_CODE).ToList();
|
|
|
|
|
var usdDetails = details2.Where(x => x.Currency == FeeCurrency.USD_CODE).ToList();
|
|
|
|
|
result = AssignAmount(usdDetails, doc.SettlementUSD.Value, settlement.Currency);
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
return DataResult<ApplicationSettlement>.Failed(result.Message, result.MultiCode);
|
|
|
|
|
}
|
|
|
|
|
if (doc.SettlementOther.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var otherDetails = details2.Where(x => x.OriginalCurrency != FeeCurrency.RMB_CODE && x.OriginalCurrency != FeeCurrency.USD_CODE).ToList();
|
|
|
|
|
var otherDetails = details2.Where(x => x.Currency != FeeCurrency.RMB_CODE && x.Currency != FeeCurrency.USD_CODE).ToList();
|
|
|
|
|
result = AssignAmount(otherDetails, doc.SettlementOther.Value, settlement.Currency);
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
return DataResult<ApplicationSettlement>.Failed(result.Message, result.MultiCode);
|
|
|
|
@ -576,83 +496,7 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
if (details1?.Count > 0)
|
|
|
|
|
settlement.Details.AddRange(details1.FindAll(x => x.Assigned));
|
|
|
|
|
|
|
|
|
|
//金额禁止为0
|
|
|
|
|
if (settlement.Details.Exists(x => x.ApplyAmount == 0 || x.OriginalAmount == 0))
|
|
|
|
|
return DataResult<ApplicationSettlement>.FailedWithDesc(nameof(MultiLanguageConst.AmountCannotBeZero));
|
|
|
|
|
|
|
|
|
|
if (settlement.Details.Exists(x => x.OriginalCurrency.IsNullOrEmpty()))
|
|
|
|
|
return DataResult<ApplicationSettlement>.FailedWithDesc(nameof(MultiLanguageConst.OriginalCurrencyCanNotNull));
|
|
|
|
|
|
|
|
|
|
result = await PreSaveAsync(settlement);
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
return DataResult<ApplicationSettlement>.Failed(result.Message, result.MultiCode);
|
|
|
|
|
|
|
|
|
|
var details = settlement.Details.FindAll(x => x.Id == 0);
|
|
|
|
|
await TenantDb.Ado.BeginTranAsync();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//关联导航属性插入
|
|
|
|
|
if (settlement.Id == 0)
|
|
|
|
|
{
|
|
|
|
|
//创建时需要生成申请单编号
|
|
|
|
|
var sequence = SeqService.Value.GetSequenceNext<ApplicationSettlement>();
|
|
|
|
|
if (!sequence.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
return DataResult<ApplicationSettlement>.Failed(sequence.Message, MultiLanguageConst.SequenceSetNotExist);
|
|
|
|
|
}
|
|
|
|
|
settlement.ApplicationNO = "ST" + SnowFlakeSingle.Instance.NextId(); //申请编号
|
|
|
|
|
settlement.SettlementNO = sequence.Data; //结算单号
|
|
|
|
|
|
|
|
|
|
await TenantDb.InsertNav(settlement).Include(x => x.Details).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (details.Count > 0)
|
|
|
|
|
await TenantDb.Insertable(details).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
await TenantDb.Updateable(settlement).IgnoreColumns(x => new
|
|
|
|
|
{
|
|
|
|
|
x.ApplicationNO,
|
|
|
|
|
x.SettlementNO,
|
|
|
|
|
x.IsLocked,
|
|
|
|
|
x.CreateBy,
|
|
|
|
|
x.CreateTime,
|
|
|
|
|
x.Deleted,
|
|
|
|
|
x.DeleteBy,
|
|
|
|
|
x.DeleteTime
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await OnSaveAsync(settlement);
|
|
|
|
|
|
|
|
|
|
if (details.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
//更新费用记录的已结算金额
|
|
|
|
|
var fees = details.Select(x => new FeeRecord
|
|
|
|
|
{
|
|
|
|
|
Id = x.RecordId,
|
|
|
|
|
SettlementAmount = x.OriginalAmount
|
|
|
|
|
}).ToList();
|
|
|
|
|
await TenantDb.Updateable(fees)
|
|
|
|
|
.PublicSetColumns(x => x.SettlementAmount, "+")
|
|
|
|
|
.UpdateColumns(x => new { x.SettlementAmount })
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//计算结算总金额
|
|
|
|
|
settlement.Amount = await TenantDb.Queryable<ApplicationDetail>().Where(x => x.ApplicationId == settlement.Id).SumAsync(x => x.ApplyAmount);
|
|
|
|
|
await TenantDb.Updateable(settlement).UpdateColumns(x => x.Amount).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
await TenantDb.Ado.CommitTranAsync();
|
|
|
|
|
await PostSaveAsync(settlement);
|
|
|
|
|
return DataResult<ApplicationSettlement>.Success(settlement);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
await TenantDb.Ado.RollbackTranAsync();
|
|
|
|
|
await ex.LogAsync(Db);
|
|
|
|
|
return DataResult<ApplicationSettlement>.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
|
|
|
|
|
}
|
|
|
|
|
return await base.SaveAsync(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task<DataResult> PreSaveAsync(ApplicationSettlement settlement)
|
|
|
|
@ -723,7 +567,8 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
var list = settlement.Details.Select(x => new ApplicationDetail
|
|
|
|
|
{
|
|
|
|
|
Id = x.DetailId.Value,
|
|
|
|
|
ProcessedAmount = x.OriginalCurrency == settlement.Currency ? x.ApplyAmount : x.OriginalAmount,
|
|
|
|
|
ProcessedAmount = x.Currency == x.OriginalCurrency ?
|
|
|
|
|
x.ApplyAmount : x.ApplyAmount / (x.ExchangeRate ?? 1),
|
|
|
|
|
OriginalProcessedAmount = x.OriginalAmount
|
|
|
|
|
}).ToList();
|
|
|
|
|
await TenantDb.Updateable(list)
|
|
|
|
@ -747,14 +592,16 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
{
|
|
|
|
|
x.ApplicationId,
|
|
|
|
|
Count = SqlFunc.AggregateCount(x.Id),
|
|
|
|
|
ProcessingCount = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => appIds.Contains(y.ApplicationId) &&
|
|
|
|
|
y.Category == DetailCategory.PaidApplication && y.OriginalProcessedAmount != 0 && y.OriginalAmount != y.OriginalProcessedAmount).Count(),
|
|
|
|
|
ProcessedCount = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => appIds.Contains(y.ApplicationId) &&
|
|
|
|
|
y.Category == DetailCategory.PaidApplication && y.OriginalAmount - y.OriginalProcessedAmount == 0).Count()
|
|
|
|
|
y.Category == DetailCategory.PaidApplication && y.OriginalAmount == y.OriginalProcessedAmount).Count()
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
List<PaymentApplication> applications = [];
|
|
|
|
|
foreach (var item in details)
|
|
|
|
|
{
|
|
|
|
|
if (item.Count == 0 || item.ProcessedCount == 0)
|
|
|
|
|
if (item.Count == 0 && item.ProcessedCount == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var entity = new PaymentApplication { Id = item.ApplicationId };
|
|
|
|
@ -762,10 +609,14 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
{
|
|
|
|
|
entity.Status = PaymentApplicationStatus.SettlementCompleted;
|
|
|
|
|
}
|
|
|
|
|
else if (item.ProcessedCount != 0)
|
|
|
|
|
else if (item.ProcessingCount != 0 || item.ProcessedCount != 0)
|
|
|
|
|
{
|
|
|
|
|
entity.Status = PaymentApplicationStatus.PartialSettlement;
|
|
|
|
|
}
|
|
|
|
|
else if (item.ProcessingCount == 0 && item.ProcessedCount == 0)
|
|
|
|
|
{
|
|
|
|
|
entity.Status = PaymentApplicationStatus.AuditPassed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
applications.Add(entity);
|
|
|
|
|
}
|
|
|
|
|