自由结算签入

usertest
嵇文龙 5 months ago
parent 0ec97089be
commit d12fa3cf67

@ -37,6 +37,21 @@ public class PageRequest
ArgumentNullException.ThrowIfNull(client, nameof(client));
return client.ConfigQuery.Context.Utilities.JsonToConditionalModels(QueryCondition);
}
/// <summary>
/// 获取当前实例的其他查询条件
/// </summary>
/// <param name="client">SqlSugar对象</param>
/// <returns></returns>
/// <exception cref="ArgumentNullException">当<paramref name="client"/>为null时引发</exception>
public List<IConditionalModel> GetOtherConditionalModels(ISqlSugarClient client)
{
if (OtherQueryCondition.IsNullOrEmpty())
return [];
ArgumentNullException.ThrowIfNull(client, nameof(client));
return client.ConfigQuery.Context.Utilities.JsonToConditionalModels(OtherQueryCondition);
}
}
/// <summary>

@ -205,6 +205,16 @@ namespace DS.WMS.Core.Fee.Dtos
/// </summary>
public class BizInvoiceApplication : BizApplication
{
/// <summary>
/// 付款未结算金额
/// </summary>
public decimal UnSettlementPaid { get; set; }
/// <summary>
/// 收款未结算金额
/// </summary>
public decimal UnSettlementCharged { get; set; }
/// <summary>
/// RMB未开票
/// </summary>

@ -118,10 +118,10 @@ namespace DS.WMS.Core.Application.Method
query = query.Where(x => x.SettlementAmount > 0);
break;
case FeeRange.PaidNotReceived:
//todo:
query = query.Where(x => x.UnSettlementPaid == 0 && x.UnSettlementCharged > 0);
break;
case FeeRange.ReceivedNotPaid:
//todo:
query = query.Where(x => x.UnSettlementPaid > 0 && x.UnSettlementCharged == 0);
break;
case FeeRange.NotAppliedSettled:
query = query.Where(x => x.OrderAmount == 0 && x.SettlementAmount == 0);
@ -136,7 +136,7 @@ namespace DS.WMS.Core.Application.Method
query = query.Where(x => x.DebitNo != null && x.SettlementAmount == 0);
break;
case FeeRange.NotReceivedPaid:
//todo:
query = query.Where(x => x.UnSettlementPaid > 0 && x.UnSettlementCharged > 0);
break;
case FeeRange.SettledNotIssued:
query = query.Where(x => x.InvoiceAmount == 0 && x.SettlementAmount > 0);
@ -214,13 +214,19 @@ namespace DS.WMS.Core.Application.Method
OrderAmount = f.OrderAmount,
InvoiceAmount = f.InvoiceAmount,
SettlementAmount = f.SettlementAmount,
//未申请开票金额=(金额-开票金额-申请开票金额+申请开票金额已开票
//未申请开票金额=金额-开票金额-申请开票金额+申请开票金额已开票
UnBilledRMB = SqlFunc.Subqueryable<FeeRecord>().Where(f => f.BusinessId == s.Id && f.FeeStatus == FeeStatus.AuditPassed
&& f.Currency == RMB_CODE).Select(f => SqlFunc.AggregateSum(f.Amount - f.InvoiceAmount - f.OrderInvoiceAmount + f.OrderInvSettlementAmount)),
UnBilledUSD = SqlFunc.Subqueryable<FeeRecord>().Where(f => f.BusinessId == s.Id && f.FeeStatus == FeeStatus.AuditPassed
&& f.Currency == USD_CODE).Select(f => SqlFunc.AggregateSum(f.Amount - f.InvoiceAmount - f.OrderInvoiceAmount + f.OrderInvSettlementAmount)),
UnBilledOther = SqlFunc.Subqueryable<FeeRecord>().Where(f => f.BusinessId == s.Id && f.FeeStatus == FeeStatus.AuditPassed
&& f.Currency != RMB_CODE && f.Currency != USD_CODE).Select(f => SqlFunc.AggregateSum(f.Amount - f.InvoiceAmount - f.OrderInvoiceAmount + f.OrderInvSettlementAmount))
&& f.Currency != RMB_CODE && f.Currency != USD_CODE).Select(f => SqlFunc.AggregateSum(f.Amount - f.InvoiceAmount - f.OrderInvoiceAmount + f.OrderInvSettlementAmount)),
//未结算金额=金额-结算金额-申请金额+申请金额已结算
UnSettlementPaid = SqlFunc.Subqueryable<FeeRecord>().Where(f => f.BusinessId == s.Id && f.FeeStatus == FeeStatus.AuditPassed && f.FeeType == FeeType.Payable)
.Select(f => SqlFunc.AggregateSum(f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount)),
UnSettlementCharged = SqlFunc.Subqueryable<FeeRecord>().Where(f => f.BusinessId == s.Id && f.FeeStatus == FeeStatus.AuditPassed && f.FeeType == FeeType.Receivable)
.Select(f => SqlFunc.AggregateSum(f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount)),
});
//海运进口

@ -279,7 +279,7 @@ namespace DS.WMS.Core.Fee.Entity
/// <summary>
/// 申请金额已结算
/// </summary>
[SugarColumn(ColumnDescription = "申请结算金额", Length = 18, DecimalDigits = 2, DefaultValue = "0")]
[SugarColumn(ColumnDescription = "申请金额已结算", Length = 18, DecimalDigits = 2, DefaultValue = "0")]
public decimal OrderSettlementAmount { get; set; }
/// <summary>

@ -0,0 +1,244 @@
using System.Runtime.Serialization;
using DS.Module.Core;
using DS.WMS.Core.Op.Entity;
namespace DS.WMS.Core.Settlement.Dtos
{
/// <summary>
/// 费用记录返回实体
/// </summary>
public class FeeBizDto
{
/// <summary>
/// 业务Id
/// </summary>
public long BusinessId { get; set; }
/// <summary>
/// 业务类型
/// </summary>
public BusinessType BusinessType { get; set; }
/// <summary>
/// 委托编号
/// </summary>
public string CustomerNo { get; set; }
/// <summary>
/// 主提单号
/// </summary>
public string? MBLNO { get; set; }
/// <summary>
/// 分提单号
/// </summary>
public string? HBLNO { get; set; }
/// <summary>
/// 开船日期
/// </summary>
public DateTime? ETD { get; set; }
/// <summary>
/// 结费单位
/// </summary>
public string CustomerName { get; set; }
/// <summary>
/// 结费单位Id
/// </summary>
public long CustomerId { get; set; }
/// <summary>
/// 委托单位
/// </summary>
public string? ClientName { get; set; }
/// <summary>
/// 业务日期
/// </summary>
public DateTime? BusinessDate { get; set; }
/// <summary>
/// 入库单号
/// </summary>
public string? GodownEntryNo { get; set; }
/// <summary>
/// 所属分部ID
/// </summary>
public long? SaleDeptId { get; set; }
/// <summary>
/// 所属分部
/// </summary>
public string? SaleDeptName { get; set; }
/// <summary>
/// 对帐编号
/// </summary>
public string? DebitNo { get; set; }
/// <summary>
/// 会计期间
/// </summary>
public string? AccountDate { get; set; }
/// <summary>
/// 船名
/// </summary>
public string? Vessel { get; set; }
/// <summary>
/// 航次
/// </summary>
public string? Voyage { get; set; }
/// <summary>
/// 核算单位
/// </summary>
public string? SaleOrg { get; set; }
/// <summary>
/// 核算单位Id
/// </summary>
public long? SaleOrgId { get; set; }
/// <summary>
/// 经营单位
/// </summary>
public string? Enterprise { get; set; }
/// <summary>
/// 报关单号
/// </summary>
public string? CustomNo { get; set; }
/// <summary>
/// 揽货人
/// </summary>
public string? Sale { get; set; }
/// <summary>
/// 订舱编号
/// </summary>
public string? BookingNo { get; set; }
/// <summary>
/// 操作员ID
/// </summary>
[IgnoreDataMember]
public long OperatorId { get; set; }
/// <summary>
/// 操作
/// </summary>
public string Operator { get; set; }
/// <summary>
/// 创建人ID
/// </summary>
[IgnoreDataMember]
public long CreateBy { get; set; }
/// <summary>
/// 创建人/录入人
/// </summary>
public string CreateByName { get; set; }
/// <summary>
/// 起运港
/// </summary>
public string? LoadPort { get; set; }
/// <summary>
/// 目的港
/// </summary>
public string? DischargePort { get; set; }
/// <summary>
/// 更改单
/// </summary>
public string? ChangeOrder { get; set; }
/// <summary>
/// RMB未付
/// </summary>
public decimal UnpaidRMB { get; set; }
/// <summary>
/// USD未付
/// </summary>
public decimal UnpaidUSD { get; set; }
/// <summary>
/// 其他未付
/// </summary>
public decimal UnpaidOther { get; set; }
/// <summary>
/// RMB未收
/// </summary>
public decimal UnchargedRMB { get; set; }
/// <summary>
/// USD未收
/// </summary>
public decimal UnchargedUSD { get; set; }
/// <summary>
/// 其他未收
/// </summary>
public decimal UnchargedOther { get; set; }
/// <summary>
/// RMB付未开票
/// </summary>
public decimal UnpaidInvoiceRMB { get; set; }
/// <summary>
/// USD付未开票
/// </summary>
public decimal UnpaidInvoiceUSD { get; set; }
}
/// <summary>
/// 按业务分组的费用
/// </summary>
public class FeeDto : FeeBizDto
{
public long Id { get; set; }
/// <summary>
/// 收付类型(收、付) 1应收 2 应付
/// </summary>
public FeeType FeeType { get; set; }
/// <summary>
/// 费用Id
/// </summary>
public long FeeId { get; set; }
/// <summary>
/// 费用代码
/// </summary>
public string FeeCode { get; set; }
/// <summary>
/// 费用名称
/// </summary>
public string FeeName { get; set; }
/// <summary>
/// 币别
/// </summary>
public string Currency { get; set; }
/// <summary>
/// 金额
/// </summary>
public decimal Amount { get; set; }
}
}

@ -0,0 +1,16 @@
using DS.Module.Core;
using DS.WMS.Core.Application.Dtos;
using DS.WMS.Core.Application.Interface;
using DS.WMS.Core.Settlement.Dtos;
using DS.WMS.Core.Settlement.Entity;
namespace DS.WMS.Core.Settlement.Interface
{
/// <summary>
/// 付费自由结算
/// </summary>
public interface IFreeSettlementService : ISettlementService<PaymentSettlement>
{
}
}

@ -1,4 +1,5 @@
using DS.Module.Core;
using DS.WMS.Core.Settlement.Dtos;
using DS.WMS.Core.Settlement.Entity;
namespace DS.WMS.Core.Application.Interface
@ -14,7 +15,7 @@ namespace DS.WMS.Core.Application.Interface
/// </summary>
/// <param name="application"></param>
/// <returns></returns>
Task<DataResult<TEntity>> SaveAsync(TEntity application);
Task<DataResult<TEntity>> SaveAsync(SettlementRequest<TEntity> request);
/// <summary>
/// 删除结算明细

@ -0,0 +1,135 @@
using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.WMS.Core.Fee.Entity;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Settlement.Dtos;
using DS.WMS.Core.Settlement.Entity;
using DS.WMS.Core.Settlement.Interface;
using DS.WMS.Core.Sys.Entity;
using SqlSugar;
namespace DS.WMS.Core.Settlement.Method
{
/// <summary>
/// 付费自由结算
/// </summary>
public class FreeSettlementService : SettlementService<PaymentSettlement>, IFreeSettlementService
{
/// <summary>
/// 初始化
/// </summary>
/// <param name="provider"></param>
public FreeSettlementService(IServiceProvider provider) : base(provider)
{
}
/// <summary>
/// 获取待结算费用分页列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
/// <remarks>查询条件请参考<see cref="FeeDto"/>中定义的字段</remarks>
public async Task<DataResult<List<FeeBizDto>>> GeFeeListAsync(PageRequest request)
{
var whereList = request.GetConditionalModels(Db);
var result = await CreateQuery().Where(whereList)
.GroupBy(x => new { x.BusinessId, x.BusinessType })
.Select<FeeBizDto>()
.ToQueryPageAsync(request.PageCondition);
if (result.Data.Count > 0)
{
//获取统计信息
var ids = result.Data.Select(x => x.BusinessId);
var types = result.Data.Select(x => x.BusinessType).Distinct();
var fees = await TenantDb.Queryable<FeeRecord>().Where(x => ids.Contains(x.BusinessId) && types.Contains(x.BusinessType))
.Select(x => new
{
x.Currency,
x.FeeType,
//x.Amount,
//x.OrderAmount,
//x.SettlementAmount,
//x.OrderSettlementAmount,
x.InvoiceAmount,
UnSettlementAmount = x.Amount - x.SettlementAmount - x.OrderAmount + x.OrderSettlementAmount //剩余待结算
}).ToListAsync();
//关联用户名称
var userIds = result.Data.Select(x => x.CreateBy)
.Union(result.Data.Select(x => x.OperatorId))
.Distinct();
var users = await Db.Queryable<SysUser>().Where(x => userIds.Contains(x.Id)).Select(x => new { x.Id, x.UserName }).ToListAsync();
var orgIds = result.Data.Select(x => x.SaleDeptId).Distinct();
var orgs = await Db.Queryable<SysOrg>().Where(x => orgIds.Contains(x.Id)).Select(x => new { x.Id, x.OrgName }).ToListAsync();
foreach (var item in result.Data)
{
item.UnpaidRMB = fees.FindAll(x => x.Currency == RMB_CODE && x.FeeType == FeeType.Payable).Sum(x => x.UnSettlementAmount);
item.UnpaidUSD = fees.FindAll(x => x.Currency == USD_CODE && x.FeeType == FeeType.Payable).Sum(x => x.UnSettlementAmount);
item.UnpaidOther = fees.FindAll(x => x.Currency != RMB_CODE && x.Currency != USD_CODE && x.FeeType == FeeType.Payable).Sum(x => x.UnSettlementAmount);
item.UnchargedRMB = fees.FindAll(x => x.Currency == RMB_CODE && x.FeeType == FeeType.Receivable).Sum(x => x.UnSettlementAmount);
item.UnchargedUSD = fees.FindAll(x => x.Currency == USD_CODE && x.FeeType == FeeType.Receivable).Sum(x => x.UnSettlementAmount);
item.UnchargedOther = fees.FindAll(x => x.Currency != RMB_CODE && x.Currency != USD_CODE && x.FeeType == FeeType.Receivable).Sum(x => x.UnSettlementAmount);
item.UnpaidInvoiceRMB = fees.FindAll(x => x.Currency == RMB_CODE && x.FeeType == FeeType.Payable && x.UnSettlementAmount == 0).Sum(x => x.InvoiceAmount);
item.UnpaidInvoiceUSD = fees.FindAll(x => x.Currency == USD_CODE && x.FeeType == FeeType.Payable && x.UnSettlementAmount == 0).Sum(x => x.InvoiceAmount);
item.CreateByName = users.Find(x => x.Id == item.CreateBy)?.UserName;
item.Operator = users.Find(x => x.Id == item.OperatorId)?.UserName;
item.SaleDeptName = orgs.Find(x => x.Id == item.SaleDeptId)?.OrgName;
}
}
return result;
}
//创建各项费用数据的查询并集
internal ISugarQueryable<FeeDto> CreateQuery()
{
var query1 = TenantDb.Queryable<FeeRecord, SeaExport>((f, s) => new JoinQueryInfos(
JoinType.Inner, s.Id == f.BusinessId && f.BusinessType == BusinessType.OceanShippingExport && f.FeeStatus == FeeStatus.AuditPassed &&
(f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount) != 0))
.Select((f, s) => new FeeDto
{
Id = f.Id,
FeeId = f.FeeId,
FeeCode = f.FeeCode,
FeeName = f.FeeName,
FeeType = f.FeeType,
CustomerId = f.CustomerId,
CustomerName = f.CustomerName,
BusinessId = f.BusinessId,
BusinessType = BusinessType.OceanShippingExport,
Currency = f.Currency,
DebitNo = f.DebitNo,
SaleOrgId = f.SaleOrgId,
SaleOrg = f.SaleOrg,
CreateBy = f.CreateBy,
AccountDate = s.AccountDate,
BusinessDate = s.BusinessDate,//业务日期
ClientName = s.CustomerName,//委托单位
CustomerNo = s.CustomerNo,
CustomNo = s.CustomNo,
DischargePort = s.DischargePort,
ETD = s.ETD,
HBLNO = s.HBLNO,
LoadPort = s.LoadPort,
MBLNO = s.MBLNO,
OperatorId = s.OperatorId,
SaleDeptId = s.SaleDeptId,
Sale = s.Sale,//揽货人
Vessel = s.Vessel,//船名
Voyage = s.Voyno,//航次
BookingNo = s.BookingNo,
Enterprise = s.Enterprise,
});
//海运进口
return TenantDb.UnionAll(new List<ISugarQueryable<FeeDto>> { query1 });
}
}
}

@ -421,102 +421,106 @@ namespace DS.WMS.Core.Settlement.Method
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<DataResult<PaymentSettlement>> SaveAsync(SettlementRequest<PaymentSettlement> request)
public async override Task<DataResult<PaymentSettlement>> SaveAsync(SettlementRequest<PaymentSettlement> request)
{
var appIds = request.Details.Select(x => x.ApplicationId).Distinct();
var appList = await TenantDb.Queryable<PaymentApplication>().Where(x => appIds.Contains(x.Id))
.Select(x => new
{
x.Id,
x.Status,
x.CustomerId,
x.CustomerName,
}).ToListAsync();
if (appList.Count == 0)
return DataResult<PaymentSettlement>.FailedWithDesc(nameof(MultiLanguageConst.EmptyData));
if (appList.Exists(x => x.Status != PaymentApplicationStatus.AuditPassed && x.Status != PaymentApplicationStatus.PartialSettlement))
return DataResult<PaymentSettlement>.FailedWithDesc(nameof(MultiLanguageConst.ApplicationSelectStatusError));
if (appList.GroupBy(x => x.CustomerId).Select(x => x.Key).Count() > 1)
return DataResult<PaymentSettlement>.FailedWithDesc(nameof(MultiLanguageConst.DetailCustomerOnlyOne));
//金额禁止为0
if (request.Details.Any(x => x.Amount == 0 || x.OriginalAmount == 0))
return DataResult<PaymentSettlement>.FailedWithDesc(nameof(MultiLanguageConst.AmountCannotBeZero));
var settlement = request.Settlement;
if (settlement.SettlementDate == default)
settlement.SettlementDate = DateTime.Now;
if (settlement.Id == 0)
{
var app = appList[0];
settlement.CustomerId = app.CustomerId;
settlement.CustomerName = app.CustomerName;
}
settlement.Mode = SettlementMode.Payment;
settlement.BillType = SettlementBillType.Payment;
settlement.Details = request.Details.Select(x => new ApplicationDetail
{
ApplicationId = x.ApplicationId,
DetailId = x.Id,
RecordId = x.RecordId,
BusinessId = x.BusinessId,
BusinessType = x.BusinessType,
CustomerName = x.CustomerName ?? settlement.CustomerName,
FeeId = x.FeeId,
FeeName = x.FeeName,
FeeType = x.FeeType,
Category = FeeCategory.PaidApplicationSettlement,
ApplyAmount = x.Amount,
Currency = x.Currency,
ExchangeRate = x.ExchangeRate,
OriginalAmount = x.OriginalAmount,
OriginalCurrency = x.OriginalCurrency ?? (settlement.Currency.IsNullOrEmpty() ? x.Currency : settlement.Currency),
}).ToList();
if (settlement.Details.Any(x => x.OriginalCurrency.IsNullOrEmpty()))
return DataResult<PaymentSettlement>.FailedWithDesc(nameof(MultiLanguageConst.OriginalCurrencyCanNotNull));
//获取剩余待结算金额
var ids2 = settlement.Details.Select(x => x.DetailId);
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)
if (request.Details?.Count > 0)
{
var item = appDetails.Find(x => x.Id == detail.DetailId);
if (item == null)
var appIds = request.Details.Select(x => x.ApplicationId).Distinct();
var appList = await TenantDb.Queryable<PaymentApplication>().Where(x => appIds.Contains(x.Id))
.Select(x => new
{
x.Id,
x.Status,
x.CustomerId,
x.CustomerName,
}).ToListAsync();
if (appList.Count == 0)
return DataResult<PaymentSettlement>.FailedWithDesc(nameof(MultiLanguageConst.EmptyData));
if (appList.Exists(x => x.Status != PaymentApplicationStatus.AuditPassed && x.Status != PaymentApplicationStatus.PartialSettlement))
return DataResult<PaymentSettlement>.FailedWithDesc(nameof(MultiLanguageConst.ApplicationSelectStatusError));
if (appList.GroupBy(x => x.CustomerId).Select(x => x.Key).Count() > 1)
return DataResult<PaymentSettlement>.FailedWithDesc(nameof(MultiLanguageConst.DetailCustomerOnlyOne));
//金额禁止为0
if (request.Details.Any(x => x.Amount == 0 || x.OriginalAmount == 0))
return DataResult<PaymentSettlement>.FailedWithDesc(nameof(MultiLanguageConst.AmountCannotBeZero));
if (settlement.Id == 0)
{
sb.Append(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.EmptyData)));
break;
var app = appList[0];
settlement.CustomerId = app.CustomerId;
settlement.CustomerName = app.CustomerName;
}
if (detail.OriginalAmount > 0 && detail.OriginalAmount > item.OriginalRestAmount)
settlement.Details = request.Details.Select(x => new ApplicationDetail
{
sb.AppendFormat(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DetailExceedingLimit)), detail.FeeName);
sb.Append("");
continue;
}
else if (detail.OriginalAmount < 0 && detail.OriginalAmount < item.OriginalRestAmount)
ApplicationId = x.ApplicationId,
DetailId = x.Id,
RecordId = x.RecordId,
BusinessId = x.BusinessId,
BusinessType = x.BusinessType,
CustomerName = x.CustomerName ?? settlement.CustomerName,
FeeId = x.FeeId,
FeeName = x.FeeName,
FeeType = x.FeeType,
Category = FeeCategory.PaidApplicationSettlement,
ApplyAmount = x.Amount,
Currency = x.Currency,
ExchangeRate = x.ExchangeRate,
OriginalAmount = x.OriginalAmount,
OriginalCurrency = x.OriginalCurrency ?? (settlement.Currency.IsNullOrEmpty() ? x.Currency : settlement.Currency),
}).ToList();
if (settlement.Details.Any(x => x.OriginalCurrency.IsNullOrEmpty()))
return DataResult<PaymentSettlement>.FailedWithDesc(nameof(MultiLanguageConst.OriginalCurrencyCanNotNull));
//获取剩余待结算金额
var ids2 = settlement.Details.Select(x => x.DetailId);
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)
{
sb.AppendFormat(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DetailExceedingLimit)), detail.FeeName);
sb.Append("");
continue;
var item = appDetails.Find(x => x.Id == detail.DetailId);
if (item == null)
{
sb.Append(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.EmptyData)));
break;
}
if (detail.OriginalAmount > 0 && detail.OriginalAmount > item.OriginalRestAmount)
{
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());
if (sb.Length > 0)
return DataResult<PaymentSettlement>.Failed(sb.ToString());
settlement.Amount = settlement.Details.Sum(x => x.ApplyAmount);
settlement.Amount = settlement.Details.Sum(x => x.ApplyAmount);
}
await TenantDb.Ado.BeginTranAsync();
try
@ -553,29 +557,32 @@ namespace DS.WMS.Core.Settlement.Method
}).ExecuteCommandAsync();
}
//更新申请明细的已处理金额
var list = request.Details.Select(x => new ApplicationDetail
if (request.Details?.Count > 0)
{
Id = x.Id,
ProcessedAmount = x.Amount,
OriginalProcessedAmount = x.OriginalAmount
}).ToList();
await TenantDb.Updateable(list)
.PublicSetColumns(x => x.ProcessedAmount, "+")
.PublicSetColumns(x => x.OriginalProcessedAmount, "+")
.UpdateColumns(x => new { x.ProcessedAmount, x.OriginalProcessedAmount })
.ExecuteCommandAsync();
//更新费用记录的已结算金额
var fees = request.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();
//更新申请明细的已处理金额
var list = request.Details.Select(x => new ApplicationDetail
{
Id = x.Id,
ProcessedAmount = x.Amount,
OriginalProcessedAmount = x.OriginalAmount
}).ToList();
await TenantDb.Updateable(list)
.PublicSetColumns(x => x.ProcessedAmount, "+")
.PublicSetColumns(x => x.OriginalProcessedAmount, "+")
.UpdateColumns(x => new { x.ProcessedAmount, x.OriginalProcessedAmount })
.ExecuteCommandAsync();
//更新费用记录的已结算金额
var fees = request.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();
}
await TenantDb.Ado.CommitTranAsync();
return DataResult<PaymentSettlement>.Success(settlement);
@ -586,8 +593,54 @@ namespace DS.WMS.Core.Settlement.Method
await ex.LogAsync(Db);
return DataResult<PaymentSettlement>.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
finally
{
if (request.Details?.Count > 0)
await WriteBackStatusAsync(settlement);
}
}
/// <summary>
/// 回写申请单的状态
/// </summary>
/// <param name="settlement">结算单</param>
/// <returns></returns>
public async Task WriteBackStatusAsync(PaymentSettlement settlement)
{
var details = await TenantDb.Queryable<ApplicationDetail>()
.InnerJoin<ApplicationDetail>((x, y) => x.DetailId == y.Id && y.ApplicationId == settlement.Id && y.Category == FeeCategory.PaidApplicationSettlement)
.Where((x, y) => x.Category == FeeCategory.PaidApplication)
.GroupBy((x, y) => x.ApplicationId).Select((x, y) => new
{
x.ApplicationId,
Count = SqlFunc.AggregateCount(x.Id),
ProcessedCount = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => y.ApplicationId == x.ApplicationId &&
y.Category == FeeCategory.PaidApplication && y.OriginalAmount - y.OriginalProcessedAmount == 0).Count()
}).ToListAsync();
List<PaymentApplication> applications = [];
foreach (var item in details)
{
if (item.Count == 0 || item.ProcessedCount == 0)
continue;
var entity = new PaymentApplication { Id = item.ApplicationId };
if (item.Count == item.ProcessedCount)
{
entity.Status = PaymentApplicationStatus.SettlementCompleted;
}
else if (item.ProcessedCount > 0)
{
entity.Status = PaymentApplicationStatus.PartialSettlement;
}
applications.Add(entity);
}
await TenantDb.Updateable(applications).UpdateColumns(x => new { x.Status }).ExecuteCommandAsync();
}
protected override DataResult PreDelete(List<PaymentSettlement> settlements)
{
if (settlements.Any(x => x.IsLocked))

@ -3,9 +3,11 @@ using DS.Module.Core.Enums;
using DS.WMS.Core.Application.Entity;
using DS.WMS.Core.Application.Interface;
using DS.WMS.Core.Fee.Method;
using DS.WMS.Core.Settlement.Dtos;
using DS.WMS.Core.Settlement.Entity;
using DS.WMS.Core.Sys.Interface;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
namespace DS.WMS.Core.Settlement.Method
{
@ -29,7 +31,7 @@ namespace DS.WMS.Core.Settlement.Method
#region 保存
public Task<DataResult<TEntity>> SaveAsync(TEntity application)
public virtual Task<DataResult<TEntity>> SaveAsync(SettlementRequest<TEntity> request)
{
throw new NotImplementedException();
}
@ -181,5 +183,6 @@ namespace DS.WMS.Core.Settlement.Method
#endregion
}
}

@ -2245,3 +2245,10 @@
2024-07-08 14:34:12.6651 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Source\Repos\DS8\ds-wms-service\DS.WMS.FeeApi\bin\Debug\net8.0\nlog.config
2024-07-08 14:34:12.6651 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile
2024-07-08 14:34:12.6779 Info Configuration initialized.
2024-07-08 17:48:22.0277 Info Registered target NLog.Targets.FileTarget(Name=allfile)
2024-07-08 17:48:22.0690 Info Registered target NLog.Targets.FileTarget(Name=ownFile-web)
2024-07-08 17:48:22.0690 Info Registered target NLog.Targets.ColoredConsoleTarget(Name=console)
2024-07-08 17:48:22.0978 Info NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 5.2.8.2366. Product version: 5.2.8+f586f1341c46fa38aaaff4c641e7f0fa7e813943. GlobalAssemblyCache: False
2024-07-08 17:48:22.1047 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Source\Repos\DS8\ds-wms-service\DS.WMS.FeeApi\bin\Debug\net8.0\nlog.config
2024-07-08 17:48:22.1047 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile
2024-07-08 17:48:22.1047 Info Configuration initialized.

Loading…
Cancel
Save