public ActionResult GetCashflowDataTable(string projectGuid, string paymentDay) { return(ActionUtils.Json(() => { if (string.IsNullOrWhiteSpace(paymentDay)) { var errorResult = new { isError = true, errorMessage = "请选择偿付期" }; return ActionUtils.Success(errorResult); } DateTime paymentDate; if (!DateTime.TryParse(paymentDay, out paymentDate)) { var errorResult = new { isError = true, errorMessage = "偿付期错误,请刷新页面后重试" }; return ActionUtils.Success(errorResult); } try { var viewModel = new CashflowViewModel(); var result = GetCFTableByProject(viewModel, projectGuid, paymentDate); return ActionUtils.Success(result); } catch (ApplicationException ae) { var errorResult = new { isError = true, errorMessage = ae.Message }; return ActionUtils.Success(errorResult); } })); }
public ShellViewModel( IWindowManager windowManager, IHierarchyManager hierarchyManager, IEventAggregator eventAggregator, CashflowViewModel casflowViewModel, MixedAnalysisViewModel mixedAnalysisViewModel, ResultsViewModel resultsViewModel) { this.DisplayName = "Business valuation using CW"; this.eventAggregator = Contract.NotNull(eventAggregator, "eventAggregator"); this.hierarchyManager = Contract.NotNull(hierarchyManager, "hierarchyManager"); this.windowManager = Contract.NotNull(windowManager, "windowManager"); this.Cashflow = Contract.NotNull(casflowViewModel, "casflowViewModel"); this.MixedAnalysis = Contract.NotNull(mixedAnalysisViewModel, "mixedAnalysisViewModel"); this.Results = Contract.NotNull(resultsViewModel, "resultsViewModel"); this.eventAggregator.PublishOnUIThread(new DataChangedEvent()); }
/// <summary> /// 更新数据库中的参数到模型文件中 /// </summary> private void UpdateVariablesFromTaskDBToModel(DatasetLogicModel dataset, CashflowViewModel dbViewModel) { if (dbViewModel == null || dataset.Instance == null) { return; } var dbVarList = dbViewModel.OverridableVariables; //更新FutureVariables.csv foreach (var keyVal in dbVarList) { dataset.Variables.UpdateVariableValue(keyVal.EnName, dataset.DatasetSchedule.PaymentDate, keyVal.Value.ToString()); } //更新CurrentVariables.csv //设置 OtherIncome = 当期的OtherIncomeMax + 前一期模型的OtherIncome var otherIncomeMaxKeyVal = dbVarList.SingleOrDefault(x => x.EnName.Equals("OtherIncomeMax", StringComparison.CurrentCultureIgnoreCase)); if (otherIncomeMaxKeyVal != null) { var key = "OtherIncome"; var otherIncomeValue = otherIncomeMaxKeyVal.Value; if (dataset.Previous != null && dataset.Previous.Instance != null) { string prevOtherIncomeVal = dataset.Previous.Variables.GetVariable(key); double prevOtherIncome = 0; if (double.TryParse(prevOtherIncomeVal, out prevOtherIncome)) { otherIncomeValue += prevOtherIncome; } } dataset.Variables.UpdateVariableValue(key, dataset.Variables.Asofdate, "其他收益"); dataset.Variables.Save(); } }
public ActionResult ShowCashflows(string id) { List <CashflowViewModel> lcf = new List <CashflowViewModel>(); int lId = int.Parse(id) - 1; Lease l = new Lease(leaseList[lId].LeaseStart, leaseList[lId].LeaseEnd, leaseList[lId].InitialRent); IDictionary <DateTime, double> cf = l.getCashflows(); foreach (var i in cf) { CashflowViewModel a = new CashflowViewModel() { Amount = i.Value, Date = i.Key }; lcf.Add(a); } return(PartialView("_LeaseCashflows", lcf)); }
public void SaveNoteData() { m_dbAdapter.Task.CheckPrevIsFinished(Task); var taskPeriod = m_dbAdapter.TaskPeriod.GetByShortCode(Task.ShortCode); var paymentDate = Task.EndTime.Value; var project = new ProjectLogicModel(m_userName, Task.ProjectId); var datasetSchedule = project.DealSchedule.GetByPaymentDay(paymentDate); if (taskPeriod != null) { paymentDate = taskPeriod.PaymentDate; } else { if (datasetSchedule != null) { paymentDate = datasetSchedule.PaymentDate; } } var dataset = datasetSchedule.Dataset; var acfTable = dataset.DealModel.AssetCashflowDt; var assetViewModel = Toolkit.GetAssetCashflow(acfTable, paymentDate); //判断本金与利息是否被覆盖 var assetCashflowVariable = m_dbAdapter.AssetCashflowVariable.GetByProjectIdPaymentDay(project.Instance.ProjectId, paymentDate); var cashflowViewModel = new CashflowViewModel(); cashflowViewModel.PredictInterestCollection = double.Parse(assetViewModel.TotalCurrentInterestCollection.ToString("n2")); cashflowViewModel.PredictPricipalCollection = double.Parse(assetViewModel.TotalCurrentPrinCollection.ToString("n2")); cashflowViewModel.OverridableVariables = SelectOverridableVariables(datasetSchedule.Dataset); var cfTable = ABSDealUtils.GetCashflowDt(datasetSchedule, assetCashflowVariable, cashflowViewModel.PredictInterestCollection, cashflowViewModel.PredictPricipalCollection, out double currInterest, out double currPrincipal); var notes = m_dbAdapter.Dataset.GetNotes(project.Instance.ProjectId); var currentDatasetColumnIndex = 2; for (int i = 0; i < cfTable.Columns.Count; ++i) { DateTime temp; if (DateTime.TryParse(cfTable.Columns[i].ColumnName, out temp) && dataset.DatasetSchedule.PaymentDate == temp) { currentDatasetColumnIndex = i; break; } } foreach (var n in notes) { var nd = m_dbAdapter.Dataset.GetNoteData((int)n.NoteId, dataset.Instance.DatasetId); var prinKey = n.ShortName + ".Principal"; var prinRow = cfTable.AsEnumerable().FirstOrDefault(r => r[1].ToString().Contains(prinKey) && r[1].ToString().Contains("Received")); CommUtils.AssertNotNull(prinRow, $"在证券端现金流表中,找不到[{prinKey}]"); var prin = prinRow[currentDatasetColumnIndex].ToString(); nd.PrincipalPaid = (decimal)((prin == string.Empty || prin == "-") ? 0.0 : double.Parse(prin)); var interestKey = n.ShortName + ".Interest"; var interestRow = cfTable.AsEnumerable().FirstOrDefault(r => r[1].ToString().Contains(interestKey) && r[1].ToString().Contains("Received")); CommUtils.AssertNotNull(interestRow, $"在证券端现金流表中,找不到[{interestKey}]"); var interest = interestRow[currentDatasetColumnIndex].ToString(); nd.InterestPaid = (decimal)((interest == string.Empty || interest == "-") ? 0.0 : double.Parse(interest)); var endKey = n.ShortName + ".Beginning"; var endRow = cfTable.AsEnumerable().FirstOrDefault(r => r[1].ToString().Contains(endKey) && r[1].ToString().Contains("Outstanding")); CommUtils.AssertNotNull(endRow, $"在证券端现金流表中,找不到[{endKey}]"); var end = endRow[currentDatasetColumnIndex + 1].ToString(); nd.EndingBalance = (decimal)((end == string.Empty || end == "-") ? 0.0 : double.Parse(end)); m_dbAdapter.Dataset.UpdateNoteData(nd); } Task.TaskExtension.TaskExtensionStatus = TaskExtensionStatus.Finished; Task.TaskExtension.TaskExtensionHandler = m_userName; Task.TaskExtension.TaskExtensionHandleTime = DateTime.Now; m_dbAdapter.Task.SaveTaskExtension(Task.TaskExtension); new TaskLogicModel(project, Task).Start(); }
public object GetCashflowDetailDataTable(string projectGuid, DateTime paymentDate) { var project = m_dbAdapter.Project.GetProjectByGuid(projectGuid); var projectLogicModel = new ProjectLogicModel(CurrentUserName, project); var datasetSchedule = projectLogicModel.DealSchedule.GetByPaymentDay(paymentDate); CommUtils.AssertNotNull(datasetSchedule.Dataset.Instance, "第{0}期模型未生成", Toolkit.DateToString(datasetSchedule.PaymentDate)); var dataset = m_dbAdapter.Dataset.GetDatasetByDurationPeriod(project.ProjectId, paymentDate); //同步数据库中参数到模型文件 var variableDateset = m_dbAdapter.CashflowVariable.GetByPaymentDay(project.ProjectId, paymentDate); UpdateVariablesFromCurrPeriodDBToModel(datasetSchedule.Dataset, variableDateset, project.ProjectId, paymentDate); var cashflowTableViewModel = new CashflowDetailTableViewModel(); cashflowTableViewModel.CurrentPaymentDate = Toolkit.DateToString(datasetSchedule.PaymentDate); //获取预测的资产池当期本金与利息 var acfTable = datasetSchedule.Dataset.DealModel.AssetCashflowDt; for (int i = acfTable.Columns.Count - 1; i >= 0; i--) { var c = acfTable.Columns[i]; DateTime date; if (DateTime.TryParse(c.ColumnName, out date)) { if (date < paymentDate) { acfTable.Columns.Remove(c); } } } var assetViewModel = Toolkit.GetAssetCashflow(acfTable, paymentDate); //判断本金与利息是否被覆盖 var assetCashflowVariable = m_dbAdapter.AssetCashflowVariable.GetByProjectIdPaymentDay(project.ProjectId, paymentDate); var cashflowViewModel = new CashflowViewModel(); cashflowViewModel.PredictInterestCollection = double.Parse(assetViewModel.TotalCurrentInterestCollection.ToString("n2")); cashflowViewModel.PredictPricipalCollection = double.Parse(assetViewModel.TotalCurrentPrinCollection.ToString("n2")); cashflowViewModel.OverridableVariables = SelectOverridableVariables(datasetSchedule.Dataset); var cashflowDt = ABSDealUtils.GetCashflowDt(datasetSchedule, assetCashflowVariable, cashflowViewModel.PredictInterestCollection, cashflowViewModel.PredictPricipalCollection, out double currInterest, out double currPrincipal); cashflowViewModel.CurrentInterestCollection = currInterest; cashflowViewModel.CurrentPricipalCollection = currPrincipal; cashflowDt = Toolkit.CleanCashflowTable(cashflowDt); var revertTable = cashflowDt.Transpose(); var notes = m_dbAdapter.Dataset.GetNotes(project.ProjectId); var noteDatas = m_dbAdapter.Dataset.GetNoteDatas(dataset.DatasetId); Toolkit.GetCashflowDetailData(cashflowTableViewModel, revertTable, notes, noteDatas); var result = new { ProjectCashflowHeader = cashflowTableViewModel.ProjectCashflowHeader, SecurityCashflowHeader = cashflowTableViewModel.SecurityCashflowHeader, AssetPoolHeader = cashflowTableViewModel.AssetPoolHeader, CostHeader = cashflowTableViewModel.CostHeader, AccountHeader = cashflowTableViewModel.AccountHeader, TriggerEventHeader = cashflowTableViewModel.TriggerEventHeader, HomePageHeader = cashflowTableViewModel.HomePageHeader, ProjectCashflowList = cashflowTableViewModel.ProjectCashflowList, SecurityCashflowList = cashflowTableViewModel.SecurityCashflowList.Keys.ToList().ConvertAll(x => new { TableName = x, DataList = cashflowTableViewModel.SecurityCashflowList[x] }), AssetPoolList = cashflowTableViewModel.AssetPoolList, CostList = cashflowTableViewModel.CostList, AccountList = cashflowTableViewModel.AccountList, TriggerEventList = cashflowTableViewModel.TriggerEventList, CurrPeriodCashflowInfoList = cashflowTableViewModel.CurrPeriodCashflowInfoList, CashflowEventList = cashflowTableViewModel.CashflowEventList, FeePayable = cashflowTableViewModel.FeePayable, CurrentPaymentDate = cashflowTableViewModel.CurrentPaymentDate, PredictInterestCollection = cashflowViewModel.PredictInterestCollection, PredictPricipalCollection = cashflowViewModel.PredictPricipalCollection, CurrentInterestCollection = cashflowViewModel.CurrentInterestCollection, CurrentPricipalCollection = cashflowViewModel.CurrentPricipalCollection, OverridableVariables = cashflowViewModel.OverridableVariables, TestFailRemind = cashflowTableViewModel.TestFailRemind }; return(result); }
private object GetCFTableByProject(CashflowViewModel viewModel, string projectGuid, DateTime paymentDate) { var project = m_dbAdapter.Project.GetProjectByGuid(projectGuid); var projectLogicModel = Platform.GetProject(projectGuid); var datasetSchedule = projectLogicModel.DealSchedule.GetByPaymentDay(paymentDate); CommUtils.AssertNotNull(datasetSchedule.Dataset.Instance, "第{0}期模型未生成", Toolkit.DateToString(datasetSchedule.PaymentDate)); //同步数据库中参数到模型文件 var variableDateset = m_dbAdapter.CashflowVariable.GetByPaymentDay(project.ProjectId, paymentDate); UpdateVariablesFromCurrPeriodDBToModel(datasetSchedule.Dataset, variableDateset, project.ProjectId, paymentDate); var cashflowTableViewModel = new CashflowDetailTableViewModel(); cashflowTableViewModel.CurrentPaymentDate = Toolkit.DateToString(datasetSchedule.PaymentDate); //获取预测的资产池当期本金与利息 var acfTable = datasetSchedule.Dataset.DealModel.AssetCashflowDt; for (int i = acfTable.Columns.Count - 1; i >= 0; i--) { var c = acfTable.Columns[i]; DateTime date; if (DateTime.TryParse(c.ColumnName, out date)) { if (date < paymentDate) { acfTable.Columns.Remove(c); } } } var assetViewModel = Toolkit.GetAssetCashflow(acfTable, paymentDate); //判断本金与利息是否被覆盖 var assetCashflowVariable = m_dbAdapter.AssetCashflowVariable.GetByProjectIdPaymentDay(project.ProjectId, paymentDate); var cashflowViewModel = new CashflowViewModel(); cashflowViewModel.PredictInterestCollection = double.Parse(assetViewModel.TotalCurrentInterestCollection.ToString("n2")); cashflowViewModel.PredictPricipalCollection = double.Parse(assetViewModel.TotalCurrentPrinCollection.ToString("n2")); cashflowViewModel.OverridableVariables = SelectOverridableVariables(datasetSchedule.Dataset); var cashflowDt = ABSDealUtils.GetCashflowDt(datasetSchedule, assetCashflowVariable, cashflowViewModel.PredictInterestCollection, cashflowViewModel.PredictPricipalCollection, out double currInterest, out double currPrincipal); cashflowViewModel.CurrentInterestCollection = currInterest; cashflowViewModel.CurrentPricipalCollection = currPrincipal; cashflowDt = ABSDealUtils.CleanAndTranslateCashflowTable(cashflowDt); var columnNames = new List <string>(); for (int i = 0; i < cashflowDt.Columns.Count; ++i) { var columnName = cashflowDt.Columns[i].ColumnName.ToString(); columnNames.Add(columnName); } viewModel.ColHeader = columnNames; string testFailRemind = null; var rowsNum = cashflowDt.Rows.Count; if (cashflowDt != null && rowsNum > 0) { var equalRowsNumber = 0; var prevAsset = cashflowDt.Rows[0][0].ToString(); for (int i = 0; i < rowsNum; i++) { DataRow dr = cashflowDt.Rows[i]; var row = dr.ItemArray.ToList().ConvertAll(x => x.ToString()); viewModel.CashflowDataResult.Add(row); if (testFailRemind == null) { if (row.Any(x => x.ToString() == "FAIL")) { testFailRemind = "预测将发生违约,启动差额支付"; } } var element = dr["类型"] != null ? dr["类型"].ToString() : ""; var description = dr["项目描述"] != null ? dr["项目描述"].ToString() : ""; if (prevAsset == element) { equalRowsNumber++; if (i == rowsNum - 1) { var info = new Tuple <int, int, int, int>(rowsNum - equalRowsNumber, 0, equalRowsNumber, 1); viewModel.MergeCellsInfo.Add(info); } } else { var info = new Tuple <int, int, int, int>(i - equalRowsNumber, 0, equalRowsNumber, 1); viewModel.MergeCellsInfo.Add(info); equalRowsNumber = 1; prevAsset = cashflowDt.Rows[i][0].ToString(); } } } var result = new { colHeader = viewModel.ColHeader, paymentDate = Toolkit.DateToString(paymentDate), dataResult = viewModel.CashflowDataResult, mergeCellsInfo = viewModel.MergeCellsInfo.ConvertAll(x => new { row = x.Item1, col = x.Item2, rowspan = x.Item3, colspan = x.Item4 }), isError = false, PredictInterestCollection = cashflowViewModel.PredictInterestCollection, PredictPricipalCollection = cashflowViewModel.PredictPricipalCollection, CurrentInterestCollection = cashflowViewModel.CurrentInterestCollection, CurrentPricipalCollection = cashflowViewModel.CurrentPricipalCollection, OverridableVariables = cashflowViewModel.OverridableVariables, TestFailRemind = testFailRemind }; return(result); }