#EQD-6948 国联民生-实现保证金规则(2)追保金额的产生与收盘计算 授信和现金tag
This commit is contained in:
@@ -280,7 +280,7 @@ namespace YLErp.Modules.TradeModule.DealModule
|
||||
DbContext.processtradelog.Add(p);
|
||||
new SalesCommissionDataService(OptUser).SetCommissionVaild(td.id);
|
||||
EditReportStatus(td.id);
|
||||
SwapTradeConfirm(td, history,false,optlog:"手工操作");
|
||||
SwapTradeConfirm(td, history,false,optlog:"手工操作", ignoreMoneyCheck: ignoreMoneyCheck);
|
||||
}
|
||||
else if (passStatus == -3)
|
||||
{
|
||||
@@ -313,7 +313,7 @@ namespace YLErp.Modules.TradeModule.DealModule
|
||||
DbContext.processtradelog.Add(p);
|
||||
new SalesCommissionDataService(OptUser).SetCommissionVaild(td.id);
|
||||
EditReportStatus(td.id);
|
||||
SwapTradeConfirm(td, history, false, optlog: "手工操作");
|
||||
SwapTradeConfirm(td, history, false, optlog: "手工操作", ignoreMoneyCheck: ignoreMoneyCheck);
|
||||
}
|
||||
|
||||
new ClientCashInCashOutService(this).SaveClientCashInCashOut(td);
|
||||
@@ -352,7 +352,8 @@ namespace YLErp.Modules.TradeModule.DealModule
|
||||
/// 新版互换确认
|
||||
/// </summary>
|
||||
/// <param name="td"></param>
|
||||
public void SwapTradeConfirm(trade td,string history,bool addlog,DateTime? openDate=null,string optlog="")
|
||||
/// <param name="ignoreMoneyCheck">特批(忽略资金检查)推进:预付金腿全部标现金,不占授信(R4 情形4)</param>
|
||||
public void SwapTradeConfirm(trade td,string history,bool addlog,DateTime? openDate=null,string optlog="", bool ignoreMoneyCheck = false)
|
||||
{
|
||||
if (td.TradeType != "收益互换")
|
||||
{
|
||||
@@ -363,12 +364,9 @@ namespace YLErp.Modules.TradeModule.DealModule
|
||||
var marginModes = new int[]{ (int)InterestModeEnum.追加预付金, (int)InterestModeEnum.初始预付金 };
|
||||
var positions= DbContext.swap_position.Where(x => x.SwapTradeId == td.id && x.IsInitial && !x.Invalid ).ToList();
|
||||
td.swap_positions = positions.Where(x =>marginModes.Contains(x.InterestMode)).ToList();
|
||||
var posiPositions= positions.Where(x => x.PosiDirection>0).ToList();
|
||||
var posiPositions= positions.Where(x=>x.PosiDirection>0).ToList();
|
||||
SwapTradeService swapTradeService = new SwapTradeService(this);
|
||||
var swapEventService = new SwapEventService(this);
|
||||
swapTradeService.InitialPosition(td);
|
||||
swapTradeService.AddPositionEvent(td, optlog);
|
||||
//new SwapEodPositionService(this).InitSaveEodSwapPosition(td);
|
||||
var happenDate = td.TradeDate.Value;
|
||||
if (td.trade_extend != null && !td.trade_extend.ExtendObj.NeedOpenFee)
|
||||
{
|
||||
@@ -376,26 +374,43 @@ namespace YLErp.Modules.TradeModule.DealModule
|
||||
}
|
||||
var cashService = new ClientCashInCashOutService(this);
|
||||
cashService.SaveSwapTradeClientCash(td, td.TradePrice ?? 0, happenDate,0);
|
||||
foreach (var marginPositions in td.swap_positions.GroupBy(g=>g.HappenDate))
|
||||
// R4 授信/现金标签:预付金腿定稿资金标签(选授信按剩余授信分配,不足跨界腿拆单),
|
||||
// 授信部分不产生资金流水(只写授信出入表占用),现金部分产生 应付预付金 记录;特批全现金。
|
||||
// 必须在 InitialPosition/AddPositionEvent 之前执行:实时持仓克隆与初始事件要继承"定稿后"的标签,
|
||||
// 拆单新拆出的授信腿也要被克隆、建事件(否则平仓返还分流会查到克隆腿上的旧标签/漏腿)。
|
||||
var generateMarginLegs = new List<swap_position>();
|
||||
foreach (var marginPosition in td.swap_positions)
|
||||
{
|
||||
var marginHappenDate = marginPositions.Key;
|
||||
foreach (var marginPosition in marginPositions)
|
||||
marginPosition.Obervation = DbContext.trade_obervation.FirstOrDefault(x => x.PositionId == marginPosition.id);
|
||||
bool generateMargin = true;
|
||||
if (marginPosition.Obervation != null)
|
||||
{
|
||||
marginPosition.Obervation = DbContext.trade_obervation.FirstOrDefault(x => x.PositionId == marginPosition.id);
|
||||
bool generateMargin = true;
|
||||
if (marginPosition.Obervation != null)
|
||||
if (!marginPosition.Obervation.IsDeductPrincipal)
|
||||
{
|
||||
if (!marginPosition.Obervation.IsDeductPrincipal)
|
||||
{
|
||||
generateMargin = false;
|
||||
}
|
||||
}
|
||||
if (generateMargin)
|
||||
{
|
||||
var marginAmount = marginPosition.InterestPrincipalFix * (marginPosition.InterestDirection == 1 ? -1 : 1);
|
||||
cashService.SaveSwapTradeClientCash(td,Convert.ToDouble( marginAmount), marginHappenDate.HasValue ? marginHappenDate.Value : td.TradeDate.Value, marginPosition.id, ClientCashInCashOut.系统操作_应付预付金);
|
||||
generateMargin = false;
|
||||
}
|
||||
}
|
||||
if (generateMargin)
|
||||
{
|
||||
generateMarginLegs.Add(marginPosition);
|
||||
}
|
||||
}
|
||||
new SwapFundTagService(this).ApplyMarginFundTags(td, generateMarginLegs, cashService, ignoreMoneyCheck);
|
||||
//标签定稿(含拆单)完成后,再克隆实时持仓、生成初始事件——克隆继承定稿标签
|
||||
swapTradeService.InitialPosition(td);
|
||||
swapTradeService.AddPositionEvent(td, optlog);
|
||||
// 追保规则-合约维度盯市:互换无预付金腿时(td.swap_positions 在上方已过滤为只剩5/6预付金腿,为空即无预付金腿),
|
||||
// 按计算保证金补一条交易级(positionId=0)初始预付金资金记录(入金),与按腿生成的记录去重。
|
||||
// 客户维度盯市(null/1)不生成出入金,维持现状;有预付金腿的互换沿用上方既有记录,不在此重复生成。
|
||||
// R4:资金来源是预付金腿上的录入项,无腿即无从选择授信,本交易级记录恒为现金。
|
||||
var watchClient = DataCacheProvider.GetClientDataSource().GetData(td.ClientId);
|
||||
if (watchClient != null && watchClient.MarginWatchRule == 0 && !td.swap_positions.Any())
|
||||
{
|
||||
var initMargin = cashService.GetInitialMarginAmount(td);
|
||||
if (initMargin > 0)
|
||||
{
|
||||
cashService.SaveSwapTradeClientCash(td, initMargin, td.TradeDate.Value, 0, ClientCashInCashOut.系统操作_应付预付金);
|
||||
}
|
||||
}
|
||||
var swap_event= swapEventService.UpdateSwapEvent();
|
||||
swapEventService.AddSwapEventDate(openDate.Value, td.id, (int)SwapEventTypeEnum.确认交易, "", 0, true, history);
|
||||
|
||||
@@ -542,7 +542,7 @@ namespace YLErp.Modules.TradeModule.DealModule
|
||||
{
|
||||
SwapTradeService swapTradeService = new SwapTradeService(this);
|
||||
new SwapEventService(UserInfo).AddSwapEventDate(DateTime.Now.Date, td.id, (int)SwapEventTypeEnum.审批通过, "", 0, true, req.comments);
|
||||
new TradeConfirmService(UserInfo).SwapTradeConfirm(td, "确认交易",false, optlog: "手工操作");
|
||||
new TradeConfirmService(UserInfo).SwapTradeConfirm(td, "确认交易",false, optlog: "手工操作", ignoreMoneyCheck: req.ignoreMoneyCheck);
|
||||
}
|
||||
//组合交易(非互换)
|
||||
if (td.IsGroup == 1)
|
||||
|
||||
Reference in New Issue
Block a user