public ActionResult Index(string projectGuid, string paymentDay) { var projectLogicModel = new ProjectLogicModel(CurrentUserName, projectGuid); var project = projectLogicModel.Instance; var datasetSchedule = projectLogicModel.DealSchedule.GetByPaymentDay(DateUtils.ParseDigitDate(paymentDay)); CommUtils.AssertNotNull(datasetSchedule.Dataset.Instance, "Dataset数据加载失败,projectGuid=[" + projectGuid + "] paymentDay=[" + paymentDay + "]"); var dataset = datasetSchedule.Dataset.Instance; var notes = m_dbAdapter.Dataset.GetNotes(project.ProjectId); var cnabsNotes = projectLogicModel.Notes; var noteDict = Toolkit.GetNoteDictionary(project, notes, cnabsNotes); var dealSchedule = NancyUtils.GetDealSchedule(project.ProjectId); var noteDatas = m_dbAdapter.Dataset.GetNoteDatas(dataset.DatasetId); var datasetViewModel = Toolkit.GetDatasetViewModel(dataset, dealSchedule.PaymentDates, noteDict, noteDatas); var datasetFolder = m_dbAdapter.Dataset.GetDatasetFolder(project, dataset.AsOfDate); VariablesHelper helper = new VariablesHelper(datasetFolder); var variables = helper.GetVariablesByDate(dataset.PaymentDate.Value); var rateResetRecords = InterestRateUtils.RateResetRecords(variables); //计算当期浮动利率 datasetViewModel.NoteDatas.ForEach(x => x.CurrentCouponRate = InterestRateUtils.CalculateCurrentCouponRate(x.NoteInfo.CouponString, rateResetRecords)); var viewModel = new CashflowDatasetViewModel(); viewModel.Dataset = datasetViewModel; viewModel.ProjectGuid = projectGuid; //添加今天之前所有已上传模型的支付日 var nowDate = DateTime.Today; viewModel.ValidPaymentDays = datasetSchedule.SelectPaymentDates( x => x.PaymentDate <= nowDate && x.Dataset != null && x.Dataset.Instance != null); if (project.CnabsDealId.HasValue) { viewModel.AllPaymentDays = m_dbAdapter.Model.GetPaymentDates(project.CnabsDealId.Value); } else { if (projectLogicModel.DealSchedule.Instanse != null) { viewModel.AllPaymentDays = projectLogicModel.DealSchedule.Instanse.PaymentDates.ToList(); } else { viewModel.AllPaymentDays = new List <DateTime>(); } } return(View(viewModel)); }
protected override object MakeObjectInstance() { var logicModel = new ProjectLogicModel(m_userName, m_project); var schedule = logicModel.DealSchedule.Instanse; var firstNoteAccrualDates = schedule.NoteAccrualDates.First().Value; var firstNoteName = schedule.NoteAccrualDates.First().Key; foreach (var key in schedule.NoteAccrualDates.Keys) { var noteAccrualDates = schedule.NoteAccrualDates[key]; CommUtils.AssertEquals(firstNoteAccrualDates.Length, noteAccrualDates.Length, "检测到证券期数不一致,[{0}]={1},[{2}]={3}", firstNoteName, firstNoteAccrualDates.Length, key, noteAccrualDates.Length); for (int i = 0; i < firstNoteAccrualDates.Length; i++) { CommUtils.Assert(firstNoteAccrualDates[i] == noteAccrualDates[i], "检测到第[{0}]期证券Accrual date不一致,[{1}]={2},[{3}]={4}", i + 1, firstNoteName, firstNoteAccrualDates[i].ToShortDateString(), key, noteAccrualDates[i].ToShortDateString()); } } //从第N期开始模型数据时,getDealSchedule中不包含前几期的PaymentDate List <DateTime> paymentDates = schedule.PaymentDates.ToList(); if (m_project.CnabsDealId.HasValue) { paymentDates = m_dbAdapter.Model.GetPaymentDates(m_project.CnabsDealId.Value); } var datasets = m_dbAdapter.Dataset.GetDatasetByProjectId(m_project.ProjectId); var paymentDate = paymentDates.First(x => x == m_paymentDay); var sequence = paymentDates.FindIndex(x => x == m_paymentDay); datasets = datasets.Where(x => x.PaymentDate.HasValue && x.PaymentDate.Value <= paymentDate).ToList(); var findDatasets = datasets.Where(x => x.PaymentDate.HasValue && x.PaymentDate.Value == paymentDate).ToList(); findDatasets.Sort((l, r) => l.AsOfDate.CompareTo(r.AsOfDate)); CommUtils.Assert(findDatasets.Count >= 1, "找不到偿付期为 [{0}] 的数据模型", DateUtils.DateToString(paymentDate)); var dataset = findDatasets[0]; var datasetId = dataset.DatasetId; var notes = m_dbAdapter.Dataset.GetNotes(m_project.ProjectId); var noteDatas = m_dbAdapter.Dataset.GetNoteDatas(datasetId); //初始化note信息 List <Note> cnabsNotes = new ProjectLogicModel(m_userName, m_project).Notes; var datasetFolder = m_dbAdapter.Dataset.GetDatasetFolder(m_project, dataset.AsOfDate); var variablesCsv = new VariablesHelper(datasetFolder); var futureVariablesPath = Path.Combine(datasetFolder, "FutureVariables.csv"); var variables = variablesCsv.GetVariablesByDate(dataset.PaymentDate.Value); var rateResetRecords = InterestRateUtils.RateResetRecords(variables); var idrObj = new IncomeDistributionReport(); idrObj.Sequence = sequence + 1; idrObj.SequenceCN = idrObj.Sequence.ToCnString(); idrObj.Security = new Dictionary <string, PaymentDetail>(); idrObj.PriorSecurityList = new List <PaymentDetail>(); idrObj.SubSecurityList = new List <PaymentDetail>(); idrObj.SecurityList = new List <PaymentDetail>(); idrObj.BeginAccrualDate = sequence == 0 ? schedule.FirstAccrualDate : schedule.NoteAccrualDates.First().Value[sequence - 1]; idrObj.EndAccrualDate = schedule.NoteAccrualDates.First().Value[sequence]; idrObj.AccrualDateSum = (idrObj.EndAccrualDate - idrObj.BeginAccrualDate).Days; for (int i = 0; i < notes.Count; i++) { var note = notes[i]; note.CouponString = InterestRateUtils.CalculateCurrentCouponRate(cnabsNotes[i].CouponString, rateResetRecords); var noteData = noteDatas.Single(x => x.NoteId == note.NoteId); CommUtils.Assert(noteData.HasValue, "兑付日为[{0}]的偿付期内,证券端现金流类型的工作未核对", paymentDate.ToShortDateString()); idrObj.Security[note.ShortName] = GeneratePaymentDetail(note, noteData, idrObj.Security.Count + 1); if (note.IsEquity) { idrObj.SubSecurityList.Add(GeneratePaymentDetail(note, noteData, idrObj.SubSecurityList.Count + 1)); } else { idrObj.PriorSecurityList.Add(GeneratePaymentDetail(note, noteData, idrObj.PriorSecurityList.Count + 1)); } idrObj.SecurityList.Add(GeneratePaymentDetail(note, noteData, idrObj.SecurityList.Count(x => x.Money != 0) + 1)); } Func <IEnumerable <PaymentDetail>, PaymentDetail> sum = (values) => new PaymentDetail { Residual = values.Sum(x => x.Residual), Principal = values.Sum(x => x.Principal), Interest = values.Sum(x => x.Interest), Money = values.Sum(x => x.Money), UnitCount = values.Sum(x => x.UnitCount), SumPaymentAmount = values.Sum(x => x.SumPaymentAmount) }; idrObj.Sum = sum(idrObj.Security.Values); idrObj.SumPrior = sum(idrObj.Security.Values.Where(x => !x.IsEquity)); idrObj.SumSub = sum(idrObj.Security.Values.Where(x => x.IsEquity)); GeneratePercentTable(idrObj, datasets, notes, schedule.PaymentDates); idrObj.RepayDetail = GenerateRepayDetail(idrObj.SecurityList, x => x.NameCN); idrObj.RepayDetailWithHyphen = GenerateRepayDetail(idrObj.SecurityList, x => x.NameCNHyphen); idrObj.RepayDetailWithHyphenByJinTai = GenerateRepayDetailByJinTai(idrObj.SecurityList, x => x.NameCNHyphen); idrObj.RepayPrincipalDetail = GenerateRepayPrincipalDetail(idrObj.SecurityList); idrObj.DenominationDetail = GenerateDenominationDetail(idrObj.SecurityList); idrObj.EquityRegisterDetail = GenerateEquityRegisterDetail(idrObj.SecurityList, dataset.PaymentDate.Value); idrObj.EquityRegisterDetailByJinTai = GenerateEquityRegisterDetailByJinTai(idrObj.SecurityList, dataset.PaymentDate.Value); idrObj.EquityRegisterDetailByZhongGang = GenerateEquityRegisterDetailByZhongGang(idrObj.SecurityList, dataset.PaymentDate.Value); idrObj.EquityRegisterDetailByYingBinGuan = GenerateEquityRegisterDetailByYingBinGuan(idrObj.SecurityList, dataset.PaymentDate.Value); idrObj.T = dataset.PaymentDate.Value; if (paymentDates.First() == idrObj.T) { idrObj.PreviousT = schedule.ClosingDate; } else { var previousIndex = paymentDates.IndexOf(idrObj.T) - 1; idrObj.PreviousT = paymentDates[previousIndex]; } idrObj.DurationDayCount = (idrObj.T - idrObj.PreviousT).Days; var t_1 = dataset.PaymentDate.Value.AddDays(-1); while (!CalendarCache.IsTradingDay(t_1)) { t_1 = t_1.AddDays(-1); } idrObj.T_1 = t_1; idrObj.Date = DateTime.Today; idrObj.TaskEndTime = m_timeStamp; return(idrObj); }