diff --git a/UnitTestProject/Modules/SwapModule/DealInterestsScenarioTest.cs b/UnitTestProject/Modules/SwapModule/DealInterestsScenarioTest.cs index ba6f8790..b4b11f31 100644 --- a/UnitTestProject/Modules/SwapModule/DealInterestsScenarioTest.cs +++ b/UnitTestProject/Modules/SwapModule/DealInterestsScenarioTest.cs @@ -782,6 +782,31 @@ namespace YLErp.Modules.SwapModule "The previous EOD identity must not be reset to a new position"); } + [TestMethod] + public void DI_MANUAL_PREPAY_PARTIAL_CLOSE_UsesHistoryPlusRemainingDailyInterest() + { + var service = new StubEodPositionService(); + var td = CreateTrade(); + var position = CreateInterestPosition(); + position.InterestMode = (int)InterestModeEnum.初始预付金; + position.InterestPrincipalFix = Principal; + var previousEod = CreatePreEod(StartDate.AddDays(2), 100m); + previousEod.InterestMode = position.InterestMode; + previousEod.TdInterestPrincipal = Principal; + var closeFlow = CreateSwapFlowEvent(StartDate.AddDays(3), 50m); + closeFlow.EventType = (int)SwapFlowEventTypeEnum.平仓; + closeFlow.InterestPrincipal = 500m; + + var result = service.ExecuteSaveAutoEodWithCloseInterestPosition( + previousEod, position, td, StartDate.AddDays(3), null, + 500m, 0m, new List { closeFlow }, 500m, false); + + var expected = previousEod.InterestIncomeSum + + result.TdInterestIncome - result.TdCloseInterest; + AssertDecimal(expected, result.InterestIncomeSum, + "预付金部分平仓待实现收益应为历史待实现+平仓后当日新增-平仓实现"); + } + [TestMethod] public void DI_AUTO_SETTLEMENT_005_AutoSettlementKeepsRemainingPrincipal() { diff --git a/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs b/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs index ce7e3807..5987acef 100644 --- a/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs @@ -1412,8 +1412,14 @@ namespace YLErp.Modules.SwapModule } else { + var useAccrualBalance = !autoSwap + && (position.InterestMode == (int)InterestModeEnum.初始预付金 + || position.InterestMode == (int)InterestModeEnum.追加预付金); + var pendingInterestBeforeSettlement = useAccrualBalance + ? lastInterestIncomeSum + newEodPayPosition.TdInterestIncome + : interestAmountBeforeSettlement; newEodPayPosition.InterestIncomeSum = RoundEodInterest( - interestAmountBeforeSettlement - newEodPayPosition.TdCloseInterest); + pendingInterestBeforeSettlement - newEodPayPosition.TdCloseInterest); newEodPayPosition.InterestFeeSum = eodPayPosition.InterestFeeSum + newEodPayPosition.TdInterestFee - newEodPayPosition.TdCloseInterestFee; } //持仓内容-利息腿-损益统计(本方视角)