|
|
@ -75,8 +75,6 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
IsVoucherDisabled = x.IsVoucherDisabled, //禁用凭证
|
|
|
|
IsVoucherDisabled = x.IsVoucherDisabled, //禁用凭证
|
|
|
|
SaleDeptId = x.SaleDeptId, //所属分部
|
|
|
|
SaleDeptId = x.SaleDeptId, //所属分部
|
|
|
|
LedgerVoucherNO = x.LedgerVoucherNO //总账凭证号
|
|
|
|
LedgerVoucherNO = x.LedgerVoucherNO //总账凭证号
|
|
|
|
//BillType = x.BillType, //单据类型
|
|
|
|
|
|
|
|
//Category = x.Category, //业务类别
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var whereList = request.GetConditionalModels(Db);
|
|
|
|
var whereList = request.GetConditionalModels(Db);
|
|
|
@ -106,6 +104,128 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 获取付费结算及其明细
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="id">结算单ID</param>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
public async Task<DataResult<PaymentSettlementDto>> GetAsync(long id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var model = await TenantDb.Queryable<PaymentSettlement>().Select(x => new PaymentSettlementDto
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
|
|
|
ApplicationNO = x.ApplicationNO, //申请编号
|
|
|
|
|
|
|
|
SettlementNO = x.SettlementNO, //结算单号
|
|
|
|
|
|
|
|
CustomerId = x.CustomerId, //结算单位
|
|
|
|
|
|
|
|
CustomerName = x.CustomerName,
|
|
|
|
|
|
|
|
Mode = x.Mode, //结算类型
|
|
|
|
|
|
|
|
SettlementDate = x.SettlementDate, //结算日期
|
|
|
|
|
|
|
|
SettlementTypeId = x.SettlementTypeId, //结算方式
|
|
|
|
|
|
|
|
CustomerBankId = x.CustomerBankId, //客户银行
|
|
|
|
|
|
|
|
Account = x.Account, //客户账户
|
|
|
|
|
|
|
|
Currency = x.Currency, //币别
|
|
|
|
|
|
|
|
Amount = x.Amount, //金额
|
|
|
|
|
|
|
|
ExchangeRate = x.ExchangeRate, //汇率
|
|
|
|
|
|
|
|
IsLocked = x.IsLocked, //锁定状态
|
|
|
|
|
|
|
|
SaleDeptId = x.SaleDeptId, //所属分部
|
|
|
|
|
|
|
|
BillType = x.BillType, //单据类型
|
|
|
|
|
|
|
|
Category = x.Category, //业务类别
|
|
|
|
|
|
|
|
LedgerVoucherNO = x.LedgerVoucherNO, //总账凭证号
|
|
|
|
|
|
|
|
RelativeNO = x.RelativeNO, //相关号码
|
|
|
|
|
|
|
|
InvoiceAmount = x.InvoiceAmount,
|
|
|
|
|
|
|
|
InvoiceDate = x.InvoiceDate,
|
|
|
|
|
|
|
|
InvoiceNO = x.InvoiceNO,
|
|
|
|
|
|
|
|
Note = x.Note, //备注
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AccountAmount = x.AccountAmount, //记账资料
|
|
|
|
|
|
|
|
AccountCurrency = x.AccountCurrency,
|
|
|
|
|
|
|
|
AccountRate = x.AccountRate,
|
|
|
|
|
|
|
|
PrePayAmount = x.PrePayAmount, //预付支资料
|
|
|
|
|
|
|
|
PrePayCurrency = x.PrePayCurrency,
|
|
|
|
|
|
|
|
PrePayRate = x.PrePayRate,
|
|
|
|
|
|
|
|
AHSRAmount = x.AHSRAmount, //实收支资料
|
|
|
|
|
|
|
|
AHSRCurrency = x.AHSRCurrency,
|
|
|
|
|
|
|
|
AHSRRate = x.AHSRRate,
|
|
|
|
|
|
|
|
FinancialAmount = x.FinancialAmount,//财务费用
|
|
|
|
|
|
|
|
FinancialCurrency = x.FinancialCurrency,
|
|
|
|
|
|
|
|
FinancialRate = x.FinancialRate,
|
|
|
|
|
|
|
|
AdvanceAmount = x.AdvanceAmount, //预收支资料
|
|
|
|
|
|
|
|
AdvanceCurrency = x.AdvanceCurrency,
|
|
|
|
|
|
|
|
AdvanceRate = x.AdvanceRate,
|
|
|
|
|
|
|
|
}).FirstAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (model != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var details = await TenantDb.Queryable<ApplicationDetail>().Where(d => d.ApplicationId == id)
|
|
|
|
|
|
|
|
.LeftJoin<ApplicationDetail>((d, pd) => d.DetailId == pd.Id)
|
|
|
|
|
|
|
|
.LeftJoin<PaymentApplication>((d, pd, pa) => pd.ApplicationId == pa.Id)
|
|
|
|
|
|
|
|
.Select((d, pd, pa) => new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
d.Id,
|
|
|
|
|
|
|
|
d.ApplicationId,
|
|
|
|
|
|
|
|
d.ApplyAmount,
|
|
|
|
|
|
|
|
//d.Currency,
|
|
|
|
|
|
|
|
d.OriginalCurrency,
|
|
|
|
|
|
|
|
d.OriginalAmount,
|
|
|
|
|
|
|
|
pa.CreateTime,
|
|
|
|
|
|
|
|
pa.CreateBy,
|
|
|
|
|
|
|
|
pa.PaymentDate,
|
|
|
|
|
|
|
|
pa.Note
|
|
|
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var gp = details.GroupBy(x => x.ApplicationId);
|
|
|
|
|
|
|
|
model.Details = new List<SettlementDetailDto>();
|
|
|
|
|
|
|
|
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 == RMB_CODE).Sum(x => x.ApplyAmount),
|
|
|
|
|
|
|
|
USDApplyAmount = g.Where(x => x.OriginalCurrency == USD_CODE).Sum(x => x.ApplyAmount),
|
|
|
|
|
|
|
|
CreateTime = firstItem?.CreateTime,
|
|
|
|
|
|
|
|
CreateBy = firstItem?.CreateBy,
|
|
|
|
|
|
|
|
PaymentDate = firstItem?.PaymentDate,
|
|
|
|
|
|
|
|
Note = firstItem?.Note
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//包含多个币别
|
|
|
|
|
|
|
|
if (g.GroupBy(x => x.OriginalCurrency).Select(x => x.Key).Count() > 1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//原始币别=不等于结算单币别的首个币别(参考DS7)
|
|
|
|
|
|
|
|
dto.OriginalCurrency = g.Where(x => x.OriginalCurrency != model.Currency).Select(x => x.OriginalCurrency).FirstOrDefault();
|
|
|
|
|
|
|
|
//原始金额=当前结算单的币别合计
|
|
|
|
|
|
|
|
dto.OriginalAmount = g.Where(x => x.OriginalCurrency == model.Currency).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);
|
|
|
|
|
|
|
|
model.Details.Add(dto);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (model.Details.Count > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//关联用户名称
|
|
|
|
|
|
|
|
var userIds = model.Details.Select(x => x.CreateBy).Distinct();
|
|
|
|
|
|
|
|
var users = await Db.Queryable<SysUser>().Where(x => userIds.Contains(x.Id)).Select(x => new { x.Id, x.UserName }).ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in model.Details)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
item.CreateByName = users.Find(x => x.Id == item.CreateBy)?.UserName;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult<PaymentSettlementDto>.Success(model);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 获取付费申请分页列表
|
|
|
|
/// 获取付费申请分页列表
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -173,29 +293,29 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id">申请单ID</param>
|
|
|
|
/// <param name="id">申请单ID</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns></returns>
|
|
|
|
public async Task<DataResult<List<SettlementDetailDto>>> GetDetailsAsync(long id)
|
|
|
|
public async Task<DataResult<List<PaymentApplicationDetailDto>>> GetDetailsAsync(long id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var details = await TenantDb.Queryable<ApplicationDetail>().Where(d => d.ApplicationId == id && (d.ApplyAmount - d.ProcessedAmount) != 0)
|
|
|
|
var details = await TenantDb.Queryable<ApplicationDetail>().Where(d => d.ApplicationId == id && (d.ApplyAmount - d.ProcessedAmount) != 0)
|
|
|
|
.InnerJoin<FeeRecord>((d, f) => d.RecordId == f.Id)
|
|
|
|
.InnerJoin<FeeRecord>((d, f) => d.RecordId == f.Id)
|
|
|
|
.InnerJoin<BusinessFeeStatus>((d, f, b) => f.BusinessId == b.BusinessId && f.BusinessType == b.BusinessType)
|
|
|
|
.InnerJoin<BusinessFeeStatus>((d, f, b) => f.BusinessId == b.BusinessId && f.BusinessType == b.BusinessType)
|
|
|
|
.Select((d, f, b) => new SettlementDetailDto
|
|
|
|
.Select((d, f, b) => new PaymentApplicationDetailDto
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Id = d.Id,
|
|
|
|
Id = d.Id,
|
|
|
|
ApplicationId = d.ApplicationId,
|
|
|
|
ApplicationId = d.ApplicationId,
|
|
|
|
|
|
|
|
BusinessId = d.BusinessId,
|
|
|
|
|
|
|
|
BusinessType = d.BusinessType,
|
|
|
|
RecordId = d.RecordId,
|
|
|
|
RecordId = d.RecordId,
|
|
|
|
FeeName = d.FeeName,
|
|
|
|
FeeName = d.FeeName,
|
|
|
|
FeeType = d.FeeType, //收付
|
|
|
|
FeeType = d.FeeType, //收付
|
|
|
|
Amount = d.ApplyAmount, //申请金额
|
|
|
|
Amount = d.ApplyAmount, //申请金额
|
|
|
|
SettlementAmount = d.ApplyAmount, //结算金额默认=申请金额
|
|
|
|
SettlementAmount = f.SettlementAmount, //结算金额
|
|
|
|
|
|
|
|
RestAmount = d.ApplyAmount - d.ProcessedAmount, //剩余结算金额
|
|
|
|
CustomerId = f.CustomerId,
|
|
|
|
CustomerId = f.CustomerId,
|
|
|
|
CustomerName = d.CustomerName,
|
|
|
|
CustomerName = d.CustomerName,
|
|
|
|
OriginalCurrency = d.OriginalCurrency, //原始币别
|
|
|
|
OriginalCurrency = d.OriginalCurrency, //原始币别
|
|
|
|
OriginalRate = f.ExchangeRate, //原始汇率
|
|
|
|
OriginalRate = f.ExchangeRate, //原始汇率
|
|
|
|
ExchangeRate = d.ExchangeRate, //折算汇率
|
|
|
|
ExchangeRate = d.ExchangeRate, //折算汇率
|
|
|
|
OriginalAmount = d.OriginalAmount, //原始金额
|
|
|
|
OriginalAmount = d.OriginalAmount //原始金额
|
|
|
|
InvoiceNO = f.InvoiceNO, //发票号
|
|
|
|
|
|
|
|
BusinessId = f.BusinessId,
|
|
|
|
|
|
|
|
BusinessType = f.BusinessType
|
|
|
|
|
|
|
|
}).ToListAsync();
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
if (details.Count > 0)
|
|
|
|
if (details.Count > 0)
|
|
|
@ -221,6 +341,7 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
s.ETD, //开船日期
|
|
|
|
s.ETD, //开船日期
|
|
|
|
s.Sale, //揽货人
|
|
|
|
s.Sale, //揽货人
|
|
|
|
cs.SourceName, //业务来源
|
|
|
|
cs.SourceName, //业务来源
|
|
|
|
|
|
|
|
s.Note
|
|
|
|
}).ToListAsync();
|
|
|
|
}).ToListAsync();
|
|
|
|
foreach (var item in g)
|
|
|
|
foreach (var item in g)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -236,6 +357,7 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
item.AccountDate = biz.AccountDate;
|
|
|
|
item.AccountDate = biz.AccountDate;
|
|
|
|
item.Vessel = biz.Vessel;
|
|
|
|
item.Vessel = biz.Vessel;
|
|
|
|
item.Voyage = biz.Voyno;
|
|
|
|
item.Voyage = biz.Voyno;
|
|
|
|
|
|
|
|
item.Note = biz.Note;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -246,19 +368,18 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult<List<SettlementDetailDto>>.Success(details);
|
|
|
|
return DataResult<List<PaymentApplicationDetailDto>>.Success(details);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 创建结算单
|
|
|
|
/// 提交结算单
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="request"></param>
|
|
|
|
/// <param name="request"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns></returns>
|
|
|
|
public async Task<DataResult<PaymentSettlement>> CreateAsync(SettlementRequest<PaymentSettlement> request)
|
|
|
|
public async Task<DataResult<PaymentSettlement>> SaveAsync(SettlementRequest<PaymentSettlement> request)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var ids = request.Details.Select(x => x.ApplicationId).Distinct();
|
|
|
|
var appIds = request.Details.Select(x => x.ApplicationId).Distinct();
|
|
|
|
var appList = await TenantDb.Queryable<PaymentApplication>().Where(x => ids.Contains(x.Id))
|
|
|
|
var appList = await TenantDb.Queryable<PaymentApplication>().Where(x => appIds.Contains(x.Id))
|
|
|
|
.Select(x => new
|
|
|
|
.Select(x => new
|
|
|
|
{
|
|
|
|
{
|
|
|
|
x.Id,
|
|
|
|
x.Id,
|
|
|
@ -269,7 +390,7 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
if (appList.Count == 0)
|
|
|
|
if (appList.Count == 0)
|
|
|
|
return DataResult<PaymentSettlement>.FailedWithDesc(nameof(MultiLanguageConst.EmptyData));
|
|
|
|
return DataResult<PaymentSettlement>.FailedWithDesc(nameof(MultiLanguageConst.EmptyData));
|
|
|
|
|
|
|
|
|
|
|
|
if (appList.Exists(x => x.Status != PaymentApplicationStatus.AuditSubmittd && x.Status != PaymentApplicationStatus.PartialSettlement))
|
|
|
|
if (appList.Exists(x => x.Status != PaymentApplicationStatus.AuditPassed && x.Status != PaymentApplicationStatus.PartialSettlement))
|
|
|
|
return DataResult<PaymentSettlement>.FailedWithDesc(nameof(MultiLanguageConst.ApplicationSelectStatusError));
|
|
|
|
return DataResult<PaymentSettlement>.FailedWithDesc(nameof(MultiLanguageConst.ApplicationSelectStatusError));
|
|
|
|
|
|
|
|
|
|
|
|
if (appList.GroupBy(x => x.CustomerId).Select(x => x.Key).Count() > 1)
|
|
|
|
if (appList.GroupBy(x => x.CustomerId).Select(x => x.Key).Count() > 1)
|
|
|
@ -279,62 +400,13 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
if (request.Details.Any(x => x.SettlementAmount == 0))
|
|
|
|
if (request.Details.Any(x => x.SettlementAmount == 0))
|
|
|
|
return DataResult<PaymentSettlement>.FailedWithDesc(nameof(MultiLanguageConst.AmountCannotBeZero));
|
|
|
|
return DataResult<PaymentSettlement>.FailedWithDesc(nameof(MultiLanguageConst.AmountCannotBeZero));
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new();
|
|
|
|
var ids = request.Details.Select(x => x.RecordId).Distinct().ToList();
|
|
|
|
var appDetails = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids.Contains(x.ApplicationId))
|
|
|
|
var fees = await TenantDb.Queryable<FeeRecord>().Where(x => ids.Contains(x.Id)).Select(x => new FeeRecord
|
|
|
|
.Select(x => new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
x.Id,
|
|
|
|
|
|
|
|
x.ApplicationId,
|
|
|
|
|
|
|
|
x.ApplyAmount,
|
|
|
|
|
|
|
|
x.BusinessId,
|
|
|
|
|
|
|
|
x.BusinessType,
|
|
|
|
|
|
|
|
x.Currency,
|
|
|
|
|
|
|
|
x.CustomerName,
|
|
|
|
|
|
|
|
x.FeeId,
|
|
|
|
|
|
|
|
x.FeeName,
|
|
|
|
|
|
|
|
x.FeeType,
|
|
|
|
|
|
|
|
x.OriginalAmount,
|
|
|
|
|
|
|
|
x.OriginalCurrency,
|
|
|
|
|
|
|
|
x.ProcessedAmount,
|
|
|
|
|
|
|
|
x.OriginalProcessedAmount,
|
|
|
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
foreach (var item in request.Details)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var appDetail = appDetails.Find(x => x.Id == item.Id);
|
|
|
|
|
|
|
|
decimal restValue = appDetail.ApplyAmount - appDetail.ProcessedAmount;
|
|
|
|
|
|
|
|
if (item.SettlementAmount > 0 && item.SettlementAmount > restValue)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sb.AppendFormat(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DetailExceedingLimit)), item.FeeName);
|
|
|
|
|
|
|
|
sb.Append(";");
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (item.SettlementAmount < 0 && item.SettlementAmount < restValue)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sb.AppendFormat(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DetailExceedingLimit)), item.FeeName);
|
|
|
|
|
|
|
|
sb.Append(";");
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sb.Length > 0)
|
|
|
|
|
|
|
|
return DataResult<PaymentSettlement>.Failed(sb.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ids2 = request.Details.Select(x => x.RecordId).Distinct().ToList();
|
|
|
|
|
|
|
|
var fees = await TenantDb.Queryable<FeeRecord>().Where(x => ids2.Contains(x.Id)).Select(x => new FeeRecord
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Id = x.Id,
|
|
|
|
Id = x.Id,
|
|
|
|
//BusinessId = x.BusinessId,
|
|
|
|
Currency = x.Currency,
|
|
|
|
//BusinessType = x.BusinessType,
|
|
|
|
|
|
|
|
//FeeId = x.FeeId,
|
|
|
|
|
|
|
|
//FeeName = x.FeeName,
|
|
|
|
|
|
|
|
//FeeType = x.FeeType,
|
|
|
|
|
|
|
|
//CustomerId = x.CustomerId,
|
|
|
|
|
|
|
|
//CustomerName = x.CustomerName,
|
|
|
|
|
|
|
|
Amount = x.Amount,
|
|
|
|
|
|
|
|
//Currency = x.Currency,
|
|
|
|
|
|
|
|
//ExchangeRate = x.ExchangeRate,
|
|
|
|
|
|
|
|
//OrderAmount = x.OrderAmount,
|
|
|
|
|
|
|
|
OrderSettlementAmount = x.OrderSettlementAmount,
|
|
|
|
OrderSettlementAmount = x.OrderSettlementAmount,
|
|
|
|
//SettlementAmount = x.SettlementAmount
|
|
|
|
SettlementAmount = x.SettlementAmount
|
|
|
|
}).ToListAsync();
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
if (fees.Count != request.Details.Count)
|
|
|
|
if (fees.Count != request.Details.Count)
|
|
|
@ -351,47 +423,64 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
settlement.CustomerName = app.CustomerName;
|
|
|
|
settlement.CustomerName = app.CustomerName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
settlement.Mode = SettlementMode.ChargeAndPayment;
|
|
|
|
settlement.Mode = SettlementMode.Payment;
|
|
|
|
settlement.BillType = SettlementBillType.Payment;
|
|
|
|
settlement.BillType = SettlementBillType.Payment;
|
|
|
|
settlement.Amount = request.Details.Sum(x => x.SettlementAmount);
|
|
|
|
|
|
|
|
settlement.Details = request.Details.Select(x => new ApplicationDetail
|
|
|
|
settlement.Details = request.Details.Select(x => new ApplicationDetail
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ApplicationId = x.ApplicationId,
|
|
|
|
ApplicationId = x.ApplicationId,
|
|
|
|
DetailId = x.Id,
|
|
|
|
DetailId = x.Id,
|
|
|
|
ApplyAmount = x.SettlementAmount,
|
|
|
|
RecordId = x.RecordId,
|
|
|
|
BusinessId = x.BusinessId,
|
|
|
|
BusinessId = x.BusinessId,
|
|
|
|
BusinessType = x.BusinessType,
|
|
|
|
BusinessType = x.BusinessType,
|
|
|
|
Category = FeeCategory.PaidApplicationSettlement,
|
|
|
|
CustomerName = x.CustomerName ?? settlement.CustomerName,
|
|
|
|
Currency = x.Currency,
|
|
|
|
|
|
|
|
CustomerName = x.CustomerName,
|
|
|
|
|
|
|
|
ExchangeRate = x.ExchangeRate,
|
|
|
|
|
|
|
|
FeeId = x.FeeId,
|
|
|
|
FeeId = x.FeeId,
|
|
|
|
FeeName = x.FeeName,
|
|
|
|
FeeName = x.FeeName,
|
|
|
|
FeeType = x.FeeType,
|
|
|
|
FeeType = x.FeeType,
|
|
|
|
|
|
|
|
Category = FeeCategory.PaidApplicationSettlement,
|
|
|
|
|
|
|
|
ApplyAmount = x.RestAmount.GetValueOrDefault(),
|
|
|
|
|
|
|
|
Currency = x.Currency,
|
|
|
|
|
|
|
|
ExchangeRate = x.ExchangeRate,
|
|
|
|
OriginalAmount = x.OriginalAmount,
|
|
|
|
OriginalAmount = x.OriginalAmount,
|
|
|
|
OriginalCurrency = x.OriginalCurrency
|
|
|
|
OriginalCurrency = x.OriginalCurrency
|
|
|
|
}).ToList();
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取剩余待结算金额
|
|
|
|
|
|
|
|
var ids2 = settlement.Details.Select(x => x.Id);
|
|
|
|
|
|
|
|
var appDetails = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids2.Contains(x.Id) && x.Category == FeeCategory.PaidApplication)
|
|
|
|
|
|
|
|
.Select(x => new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
x.Id,
|
|
|
|
|
|
|
|
RestAmount = x.ApplyAmount - x.ProcessedAmount,
|
|
|
|
|
|
|
|
OriginalRestAmount = x.OriginalAmount - x.OriginalProcessedAmount
|
|
|
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new();
|
|
|
|
foreach (var detail in settlement.Details)
|
|
|
|
foreach (var detail in settlement.Details)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//var fee = fees.Find(x => x.Id == detail.RecordId);
|
|
|
|
var item = appDetails.Find(x => x.Id == detail.Id);
|
|
|
|
//detail.BusinessId = fee.BusinessId;
|
|
|
|
if (item == null)
|
|
|
|
//detail.BusinessType = fee.BusinessType;
|
|
|
|
|
|
|
|
//detail.ExchangeRate = detail.ExchangeRate ?? fee.ExchangeRate;
|
|
|
|
|
|
|
|
//detail.FeeId = fee.FeeId;
|
|
|
|
|
|
|
|
//detail.FeeName = fee.FeeName;
|
|
|
|
|
|
|
|
//detail.FeeType = fee.FeeType;
|
|
|
|
|
|
|
|
detail.CustomerName = detail.CustomerName ?? settlement.CustomerName;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//原币申请
|
|
|
|
|
|
|
|
if (settlement.Currency.IsNullOrEmpty())
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
detail.OriginalAmount = detail.ApplyAmount;
|
|
|
|
sb.Append(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.EmptyData)));
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//if (detail.OriginalCurrency.IsNullOrEmpty())
|
|
|
|
if (detail.OriginalAmount > 0 && detail.OriginalAmount > item.OriginalRestAmount)
|
|
|
|
// detail.OriginalCurrency = fee.Currency;
|
|
|
|
{
|
|
|
|
|
|
|
|
sb.AppendFormat(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DetailExceedingLimit)), detail.FeeName);
|
|
|
|
|
|
|
|
sb.Append(";");
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (detail.OriginalAmount < 0 && detail.OriginalAmount < item.OriginalRestAmount)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sb.AppendFormat(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DetailExceedingLimit)), detail.FeeName);
|
|
|
|
|
|
|
|
sb.Append(";");
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sb.Length > 0)
|
|
|
|
|
|
|
|
return DataResult<PaymentSettlement>.Failed(sb.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
settlement.Amount = settlement.Details.Sum(x => x.ApplyAmount);
|
|
|
|
|
|
|
|
|
|
|
|
await TenantDb.Ado.BeginTranAsync();
|
|
|
|
await TenantDb.Ado.BeginTranAsync();
|
|
|
|
try
|
|
|
|
try
|
|
|
@ -427,6 +516,17 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//更新申请明细的已处理金额
|
|
|
|
|
|
|
|
var list = request.Details.Select(x => new ApplicationDetail
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
|
|
|
ProcessedAmount = x.SettlementAmount,
|
|
|
|
|
|
|
|
OriginalProcessedAmount = x.OriginalAmount
|
|
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
await TenantDb.Updateable(list)
|
|
|
|
|
|
|
|
.UpdateColumns(x => new { x.ProcessedAmount, x.OriginalProcessedAmount })
|
|
|
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
|
|
if (fees != null && fees.Count > 0)
|
|
|
|
if (fees != null && fees.Count > 0)
|
|
|
|
await TenantDb.Updateable(fees)
|
|
|
|
await TenantDb.Updateable(fees)
|
|
|
|
.PublicSetColumns(x => x.SettlementAmount, "+")
|
|
|
|
.PublicSetColumns(x => x.SettlementAmount, "+")
|
|
|
@ -443,5 +543,27 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
return DataResult<PaymentSettlement>.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
|
|
|
|
return DataResult<PaymentSettlement>.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override DataResult PreDelete(List<PaymentSettlement> settlements)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (settlements.Any(x => x.IsLocked))
|
|
|
|
|
|
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.SettlementIsLocked));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult.Success;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override async Task OnDeleteDetailAsync(List<PaymentSettlement> settlements)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await base.OnDeleteDetailAsync(settlements);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var detailList = settlements.SelectMany(x => x.Details);
|
|
|
|
|
|
|
|
//还原费用表的已结算金额
|
|
|
|
|
|
|
|
var fees = detailList.Select(x => new FeeRecord { Id = x.RecordId, SettlementAmount = x.OriginalAmount }).ToList();
|
|
|
|
|
|
|
|
await TenantDb.Updateable(fees)
|
|
|
|
|
|
|
|
.PublicSetColumns(it => it.SettlementAmount, "-")
|
|
|
|
|
|
|
|
.UpdateColumns(x => new { x.SettlementAmount })
|
|
|
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|