diff --git a/YLErpDAL/Modules/TradeModule/DocGenerateModule/SwapSettlementBillRowBuilder.cs b/YLErpDAL/Modules/TradeModule/DocGenerateModule/SwapSettlementBillRowBuilder.cs index 36fe722e..d6063274 100644 --- a/YLErpDAL/Modules/TradeModule/DocGenerateModule/SwapSettlementBillRowBuilder.cs +++ b/YLErpDAL/Modules/TradeModule/DocGenerateModule/SwapSettlementBillRowBuilder.cs @@ -64,7 +64,6 @@ public static class SwapSettlementBillRowBuilder var positions = input.Positions ?? Array.Empty(); var eventFlows = input.EventFlows ?? Array.Empty(); - // 三个业务日期是结算单和文件命名的必填项,缺失时直接阻止生成不完整附件。 var startDate = input.Trade.StartDate ?? throw new ServiceException("结算单缺少交易起始日"); var eventDate = input.CloseFlow.UnwindDate @@ -72,7 +71,7 @@ public static class SwapSettlementBillRowBuilder var payDate = input.CloseFlow.PayDate ?? throw new ServiceException("结算单缺少支付日"); - // 将同一事件的普通利息与预付金利息分开;预付金本金仅统计结算日前已生效的腿。 + var settlementPosition = positions.FirstOrDefault(x => x.id == input.CloseFlow.PositionId); var interestEvents = eventFlows .Where(x => ConsTrade.InterestModels.Contains(x.InterestMode)) @@ -91,9 +90,13 @@ public static class SwapSettlementBillRowBuilder var fee = -(input.CloseFlow.TradingFee + input.CloseFlow.TradingFeePending); var marginInterest = -marginEvents.Sum(x => x.InterestClosePnL); var initialMargin = SumMargin(effectiveMargins, InterestModeEnum.初始预付金); - var additionalMargin = SumMargin(effectiveMargins, InterestModeEnum.追加预付金); + + var additionalMarginPositions = positions + .Where(x => x.InterestMode == (int)InterestModeEnum.追加预付金) + .ToList(); + var additionalMargin = SumMargin(additionalMarginPositions, InterestModeEnum.追加预付金); + - // 净额结算仅包含全部事件利息和浮动盈亏,不包含预付金返还本金。 var netSettlementAmount = -eventFlows.Sum(x => x.InterestClosePnL) - input.CloseFlow.FloatPnlSum; var maturitySettlementAmount = netSettlementAmount + initialMargin + additionalMargin; @@ -101,10 +104,10 @@ public static class SwapSettlementBillRowBuilder ? 0m : interestAmount / input.CloseNotionalValue; - // 日终持仓的当日浮动端分红按标的类型拆分:债券展示期间付息,非债券展示期间分红。 + var isCashBond = ConsGlobal.InstrumentType.IsBond(input.UnderlyingInstrumentType); - // 此处集中完成模板字段映射和展示精度处理,生成器只负责组装原始业务数据。 + return new ExcelReportModel { TradeNumber = input.ConfirmNo, @@ -141,7 +144,9 @@ public static class SwapSettlementBillRowBuilder .ToString("0.0000%"), MarginInterestAmount = marginInterest.ToString("0.00"), InitialMargin = initialMargin.ToString("0.00"), - AdditionalMargin = additionalMargin.ToString("0.00"), + AdditionalMargin = additionalMarginPositions.Count > 0 + ? additionalMargin.ToString("0.00") + : string.Empty, MarginAmout = Math.Abs(initialMargin).ToString("0.00"), MarkClosePnl = (-input.CloseFlow.FloatPnlSum).ToString("0.00"), NetSettleAmout = netSettlementAmount.ToString("0.00"),