using Newtonsoft.Json; using System.Text; using YLErp.Modules.QuotationModule; using YLErp.Office.iTextModule; using YLErp.QdpModule; namespace YLErp.Web.Controllers { public class quotationconfirmController : BaseController { protected YLContext db = new(); private IEnumerable GetSortFlat_Quotation(DateTime? date, string[] assetTypeArray) { var userGroup = CurUser.UserGroup; var flat_priceList = flat_price_quotationBLL.GetSortFlat_Quotation(date, userGroup); if (assetTypeArray != null && (assetTypeArray = assetTypeArray.Where(O => !string.IsNullOrEmpty(O) && O.ToLower() != "undefind" && O.ToLower() != "null").ToArray()).Any()) { var varietyCodes = VarietyBLL.GetAllvarietyModel() .Where(O => assetTypeArray.Contains(O.AssetType)) .Select(O => O.VarietyCode).ToHashSet(StringComparer.OrdinalIgnoreCase); flat_priceList = flat_priceList.Where(O => { if (O.UnderlyingType == ConsGlobal.InstrumentType.CommodityFutures) { return varietyCodes.Contains(UnderlyingHelper.GetVarietyCode(O.UnderlyingCode)); } return varietyCodes.Contains(O.VarietyCode); }).ToArray(); } return flat_priceList; } public ActionResult OutPutPDF(DateTime? endDate, string assetType) { var flat_priceList = GetSortFlat_Quotation(endDate, assetType?.Split(',')); var selectedQuotation = GetQuotationGroup(flat_priceList, endDate); var sb = new StringBuilder(); var ttindex = 0; if (PS.Config.Is海通) { sb.Append($@"
{PS.Config.CompanyName}商品场外期权报价

1个月平值看涨/看跌期权

报价日: {valuedateBLL.ValueDate:yyyy-MM-dd} 到期日: {endDate.Value:yyyy-MM-dd}

  "); foreach (var quo in selectedQuotation) { for (var index = 0; index < quo.flat_price_quotations.Count; index++) { ttindex++; var bgStyle = ""; if (ttindex % 2 == 1) { bgStyle = "background:#ecedec;font-family:YouYuan;"; } var showName = quo.flat_price_quotations[index].ShortName; if (string.IsNullOrEmpty(showName)) { showName = quo.flat_price_quotations[index].UnderlyingType; } sb.Append($@" "); if (index == 0) { sb.Append($@" "); } sb.Append($@" "); sb.Append($@" "); sb.Append($@" "); sb.Append($@" "); sb.Append($@" "); sb.Append($@" "); sb.Append($@" "); sb.Append($@" "); sb.Append($@" "); sb.Append($@" "); } } sb.Append("
报价品种 标的信息 买入 卖出
板块 品种 代码 价格 波动率 绝对值 百分比% 波动率 绝对值 百分比%
{quo.AssetType}{showName}{quo.flat_price_quotations[index].UnderlyingCode}{quo.flat_price_quotations[index].SpotPrice}{quo.flat_price_quotations[index].BuyOptionVol?.ToString("P")}{quo.flat_price_quotations[index].BuyOptionPrice?.ToString("N")}{(quo.flat_price_quotations[index].BuyOptionPrice / quo.flat_price_quotations[index].SpotPrice)?.ToString("P")}{quo.flat_price_quotations[index].SellOptionVol?.ToString("P")}{quo.flat_price_quotations[index].SellOptionPrice?.ToString("N")}{(quo.flat_price_quotations[index].SellOptionPrice / quo.flat_price_quotations[index].SpotPrice)?.ToString("P")}
 
"); } else { #region 非申万导出pdf sb.Append($@"
{PS.Config.CompanyName}商品场外期权报价

1个月平值看涨/看跌期权

报价日: {valuedateBLL.ValueDate:yyyy-MM-dd} 到期日: {endDate.Value:yyyy-MM-dd}

"); string background; string borderColor; if (PS.Config.Is光大光子) { background = "#532E86"; borderColor = "#AE9FC1"; } else { background = "#15498c"; borderColor = "#416fab"; } //sb.Append($"
报价日: {@valuedateBLL.ValueDate.ToString("yyyy -MM-dd")}到期日: {@calendarBLL.GetNonHoliday(valuedateBLL.ValueDate.AddMonths(1)).ToString("yyyy-MM-dd")}
"); sb.Append("
  "); if (YLErp.PS.Config.Is光大光子) { //光子导出时绝对值列更换为波动率列,客户买价这种百分比和波动率列位置调换 sb.Append($" "); sb.AppendFormat($" "); } else if (PS.Config.Is渤海 || PS.Config.Is润和) { sb.Append($" " + $"" + $"" + $"" + $""); sb.AppendFormat($"" + $"" + $"" + $"" + $"" + $"" + $"" + $"" + $"" + $"" + $""); } else { sb.Append($" "); sb.AppendFormat($" "); } foreach (var quo in selectedQuotation) { for (var index = 0; index < quo.flat_price_quotations.Count; index++) { ttindex++; var bgStyle = ""; if (ttindex % 2 == 1) { bgStyle = "background:#ecedec;font-family:YouYuan;"; } var showName = quo.flat_price_quotations[index].ShortName; if (string.IsNullOrEmpty(showName)) { showName = quo.flat_price_quotations[index].UnderlyingType; } sb.Append($@" "); if (index == 0) { sb.Append($@" "); } sb.Append($@" "); sb.Append($@" "); if (YLErp.PS.Config.Is光大光子) { sb.Append($@" "); sb.Append($@" "); sb.Append($@" "); sb.Append($@" "); } else if (PS.Config.Is渤海 || PS.Config.Is润和) { sb.Append($@""); sb.Append($@" "); sb.Append($@" "); sb.Append($@" "); sb.Append($@" "); sb.Append($@" "); sb.Append($@" "); } else { sb.Append($@""); sb.Append($@" "); sb.Append($@" "); sb.Append($@" "); sb.Append($@" "); } sb.Append($@" "); } } sb.Append("
报价品种标的信息客户卖价客户买价
板块品种代码波动率百分比%百分比%波动率
报价品种标的信息买价卖价
板块品种代码价格波动率绝对值百分比%波动率绝对值百分比%
报价品种标的信息买价卖价
板块品种代码价格绝对值百分比%绝对值百分比%
{quo.AssetType}{showName}{quo.flat_price_quotations[index].UnderlyingCode}{quo.flat_price_quotations[index].BuyOptionVol?.ToString("P")}{(quo.flat_price_quotations[index].BuyOptionPrice / quo.flat_price_quotations[index].SpotPrice)?.ToString("P")}{(quo.flat_price_quotations[index].SellOptionPrice / quo.flat_price_quotations[index].SpotPrice)?.ToString("P")}{quo.flat_price_quotations[index].SellOptionVol?.ToString("P")}{quo.flat_price_quotations[index].SpotPrice}{quo.flat_price_quotations[index].BuyOptionVol?.ToString("P")}{quo.flat_price_quotations[index].BuyOptionPrice?.ToString("N")}{(quo.flat_price_quotations[index].BuyOptionPrice / quo.flat_price_quotations[index].SpotPrice)?.ToString("P")}{quo.flat_price_quotations[index].SellOptionVol?.ToString("P")}{quo.flat_price_quotations[index].SellOptionPrice?.ToString("N")}{(quo.flat_price_quotations[index].SellOptionPrice / quo.flat_price_quotations[index].SpotPrice)?.ToString("P")}{quo.flat_price_quotations[index].SpotPrice}{quo.flat_price_quotations[index].BuyOptionPrice?.ToString("N")}{(quo.flat_price_quotations[index].BuyOptionPrice / quo.flat_price_quotations[index].SpotPrice)?.ToString("P")}{quo.flat_price_quotations[index].SellOptionPrice?.ToString("N")}{(quo.flat_price_quotations[index].SellOptionPrice / quo.flat_price_quotations[index].SpotPrice)?.ToString("P")}
 
"); if (PS.Config.Is渤海) { sb.Append($"" + $"" + $"" + $"" + $"" + $"" + $"" + $"" + $"
 " + $"

报价说明

" + $"

1.本表为参考报价,我司不承诺以上报价最终必然成交,实时报价请联系我司询价:021-60146471。

" + $"

2.投资者以上述价格进行投资决策应自担投资风险,如有以下情形,我司不予提供场外期权服务:

" + $"
  • 配资公司、互联网金融平台等敏感类客户;
  • " + $"
  • 规避监管、非法集资、违反反洗钱等监管规定;
  • " + $"
  • 投资者为我司股东居间人;
  • " + $"
  • 其他法律法规、自律规则禁止情形。
" + $"
 
"); } if (PS.Config.Is国泰君安) { if (PS.Config.CompanyID == "国泰君安") { sb.Append("
 
该价格对于名义本金规模500万以内的交易有效,实时报价可参见左下方微信报价平台。

量大或其他限制/结构价格,请联系:021-52138853、52138780、62155457.

 
"); } else if (PS.Config.CompanyID == "中财资本") { sb.Append("
 
该价格对于名义本金规模500万以内的交易有效。

量大或其他限制/结构价格,请联系:021-61701584、61701608.

 
"); } } //国贸 if (PS.Config.ErpElement.Company == Configuration.CompanyEnum.国贸启润) { sb.Append("

1、公开报价有效范围为1000万名义本金以内,我司有权根据当天行情变动及成交情况进行调整

"); sb.Append("

2、本报价仅向我司特定客户(已完成适当性评估的合格投资者)提供,如需进一步了解我司场外业务请联系021-33588323。

"); } #endregion } var company = PS.Config.CompanyName; var fileBytes = new HtmlToPdfHelper().ConvertHtmlTextToPDF(sb.ToString(), new HtmlToPdfOptions { BaseUri = new Uri(Request.UrlLeftPart()), ContentRootPath = Server.GetVirtualRootPath() }); return File(fileBytes, "application/pdf", $"{company}报价" + DateTime.Now.ToString("yyyyMMdd") + ".pdf"); } public ActionResult OutPutPDF2(string assetType) { var flat_priceList = GetSortFlat_Quotation(null, assetType?.Split(',')); var vq = underlying_main_contract_historyBLL.GetVolatilityQuotation(UserId, flat_priceList); var sb = new StringBuilder(); var background = YLErp.PS.Config.Is光大光子 ? "#532E86" : "#00b4ff"; sb.Append(""); sb.Append($" "); sb.Append(" "); if (vq == null) { throw new Exception("请刷新界面后再导出"); } foreach (var quo in vq) { var subSb = new StringBuilder(); subSb.Append("
到期日BidAsk
"); quo.BidAskMatureData.ForEach(ab => { subSb.Append($""); }); subSb.Append("
{ab.Expire}{ab.BidVol.ToString("P")}{ab.AskVol.ToString("P")}
"); sb.Append($@"{quo.UnderlyingType}{quo.CommodityCode}{subSb.ToString()} {quo.MarketName}"); } sb.Append(""); sb.Append($"" + $"
报价日期{valuedateBLL.ValueDate.ToString("yyyy-MM-dd")}
制表人:              审核人:            
"); //国贸 if (PS.Config.ErpElement.Company == Configuration.CompanyEnum.国贸启润) { sb.Append("

1、公开报价有效范围为1000万名义本金以内,我司有权根据当天行情变动及成交情况进行调整

"); sb.Append("

2、本报价仅向我司特定客户(已完成适当性评估的合格投资者)提供,如需进一步了解我司场外业务请联系021-33588323。

"); } var company = PS.Config.CompanyName; var fileBytes = new HtmlToPdfHelper().ConvertHtmlTextToPDF(sb.ToString(), new HtmlToPdfOptions { BaseUri = new Uri(Request.UrlLeftPart()), ContentRootPath = Server.GetVirtualRootPath() }); return File(fileBytes, "application/pdf", $"{company}报价" + DateTime.Now.ToString("yyyyMMdd") + "波动率报价表.pdf"); } public ActionResult OutPutHistoryPDF(string valueDate) { var hDate = Convert.ToDateTime(valueDate); var sb = new StringBuilder(); var underlyingMainContractHistory = db.underlying_main_contract_history.Where(t => t.HistoryDate == hDate).ToList(); if (underlyingMainContractHistory == null) { throw new Exception("没有历史数据!"); } sb.Append(""); sb.Append(" "); sb.Append(" "); foreach (var item in underlyingMainContractHistory) { var vq = JsonConvert.DeserializeObject>(item.underlyingjson); if (vq == null) { throw new Exception("没有历史数据!"); } foreach (var quo in vq) { var subSb = new StringBuilder(); subSb.Append("
到期日BidAsk
"); quo.BidAskMatureData.ForEach(ab => { subSb.Append($""); }); subSb.Append("
{ab.Expire}{ab.BidVol.ToString("P")}{ab.AskVol.ToString("P")}
"); sb.Append($@"{quo.UnderlyingType}{quo.CommodityCode}{subSb.ToString()} {quo.MarketName}"); } } sb.Append(""); sb.Append($"" + $"
报价日期{valueDate}
制表人:              审核人:            
"); var fileBytes = new HtmlToPdfHelper().ConvertHtmlTextToPDF(sb.ToString(), new HtmlToPdfOptions { BaseUri = new Uri(Request.UrlLeftPart()), ContentRootPath = Server.GetVirtualRootPath() }); return File(fileBytes, "application/pdf", valueDate + "波动率报价表.pdf"); } public JsonResult GetVolatility() { var userGroup = CurUser.UserGroup; var VQ = underlying_main_contract_historyBLL.GetVolatilityQuotation(UserId, flat_price_quotationBLL.GetSortFlat_Quotation(null, userGroup)); return JsonSuccess("", VQ); } public ActionResult quotationtable() { var userGroup = CurUser.UserGroup; var maturityDate = flat_price_quotationBLL.GetAtmOptionQuotePreviewMaturity(); return View(GetQuotationGroup(flat_price_quotationBLL.GetSortFlat_Quotation(null, userGroup), maturityDate.DateTime)); } List GetQuotationGroup(IEnumerable quotationList, DateTime? pickDate) { var varieties = VarietyBLL.GetAllvarietyModel(); foreach (var q in quotationList) { var targetVar = varieties.FirstOrDefault(v => v.VarietyName == q.UnderlyingType); if (targetVar != null) { q.AssetType = targetVar.AssetType; q.ShortName = targetVar.ShortName; } } var selectedQuotation = new List(); var maturityDate = pickDate == null ? QdpCalendarHelper.GetNonHoliday(valuedateBLL.ValueDate.AddMonths(1).AddDays(-1)) : pickDate.Value; //需要展示的标的信息 var underlyingList = underlying_main_contractBLL.GetDefaultAtMoneyQuoteList(maturityDate); foreach (var flat in quotationList) { if (underlyingList.Any(c => c.UnderlyingCode == flat.UnderlyingCode)) { var groupQuotation = selectedQuotation.FirstOrDefault(q => q.AssetType == flat.AssetType); //var order = underlyingList.FirstOrDefault(c => c.UnderlyingCode == flat.UnderlyingCode).order; //flat.order = order; if (groupQuotation == null) { var group = new flat_price_quotation_group { order = flat.order, AssetType = flat.AssetType, flat_price_quotations = new List { flat } }; selectedQuotation.Add(group); } else { groupQuotation.flat_price_quotations.Add(flat); } } } //排序补丁 selectedQuotation.ForEach(q => { q.order = q.flat_price_quotations.Min(f => f.order) ?? 0; q.flat_price_quotations = q.flat_price_quotations.OrderBy(f => f.order).ToList(); }); selectedQuotation = selectedQuotation.OrderBy(s => s.order).ToList(); return selectedQuotation; } public ActionResult quotationvolhistory() { ViewBag.VolatilityQuotation = new List(); return View(); } [MyAuthorize("报价管理-报价预览")] public ActionResult quotationpreview(string[] assetType) { ViewBag.ValueDate = valuedateBLL.ValueDate.ToString("yyyy-MM-dd"); var maturityDate = flat_price_quotationBLL.GetAtmOptionQuotePreviewMaturity(); ViewBag.maturityDate = maturityDate; ViewBag.assetType = assetType; var flat_priceList = GetSortFlat_Quotation(null, assetType); var selectedQuotation = GetQuotationGroup(flat_priceList, maturityDate.DateTime); ViewBag.VolatilityQuotation = underlying_main_contract_historyBLL.GetVolatilityQuotation(UserId, flat_priceList); return View(selectedQuotation); } public JsonResult getSelfVolatilityQuotation(DateTime? date, string[] assetType) { var flat_priceList = GetSortFlat_Quotation(date, assetType); var selectedQuotation = GetQuotationGroup(flat_priceList, date); ViewBag.VolatilityQuotation = underlying_main_contract_historyBLL.GetVolatilityQuotation(UserId, flat_priceList); if (selectedQuotation.Count > 0) { return JsonSuccess("计算成功", selectedQuotation); } else { return JsonError("没有数据"); } } public JsonResult getVolatilityQuotation(DateTime date) { date = date.Date; var underlyingMainContractHistory = db.underlying_main_contract_history.FirstOrDefault(t => t.HistoryDate == date); if (underlyingMainContractHistory != null) { return JsonSuccess("获取成功", underlyingMainContractHistory); } else { return JsonError("没有历史数据"); } } } }