public ActionResult GetAmortizationByAsset(string projectGuid, string paymentDate, int assetId)
        {
            return(ActionUtils.Json(() =>
            {
                var project = new ProjectLogicModel(CurrentUserName, projectGuid);
                var dataset = project.DealSchedule.GetByPaymentDay(DateUtils.ParseDigitDate(paymentDate)).Dataset;
                var asset = dataset.Assets.Single(x => x.AssetId == assetId);

                if (asset.AmortizationType == AmortizationType.UserDefined)
                {
                    var records = dataset.AmortizationSchedule.SelectByAsset(assetId);
                    var viewModel = new PrepayRecordListViewModel(dataset.DatasetSchedule, records);
                    viewModel.AsOfDateBegin = dataset.DatasetSchedule.AsOfDateBegin;
                    viewModel.AsOfDateEnd = dataset.DatasetSchedule.AsOfDateEnd;
                    return ActionUtils.Success(viewModel);
                }
                else if (IsEqualPmtOrEqualPrin(asset.AmortizationType))
                {
                    if (IsEqualPmtOrEqualPrin(asset.SecurityData.PaymentMethod))
                    {
                        //当期的偿付类型是EqualPmt/EqualPrin
                        //返回值为系统根据EqualPmt/EqualPrin测算出的本金
                        var basicAnalyticsData = NancyUtils.GetBasicAnalyticsData(project.Instance.ProjectId, null, dataset.Instance.AsOfDate);
                        var assetCashflow = basicAnalyticsData.BasicAssetCashflow.BasicAssetCashflowItems.SelectByAsset(assetId);

                        var viewModel = new PrepayRecordListViewModel(dataset.DatasetSchedule, assetCashflow);
                        return ActionUtils.Success(viewModel);
                    }
                    else
                    {
                        //已经发生了提前偿付,后几期的偿付类型是EqualPmt/EqualPrin
                        //返回值为提前偿付+系统根据EqualPmt/EqualPrin测算出的本金
                        var records = dataset.AmortizationSchedule.SelectByAsset(assetId);
                        var viewModel = new PrepayRecordListViewModel(dataset.DatasetSchedule, records);

                        var nextDatasetBasicAnalyticsData = NancyUtils.GetBasicAnalyticsData(project.Instance.ProjectId, null, dataset.DatasetSchedule.Next.AsOfDateBegin);
                        var nextAssetCashflowItems = nextDatasetBasicAnalyticsData.BasicAssetCashflow.BasicAssetCashflowItems
                                                     .SelectByAsset(assetId).Where(x => x.PaymentDate > dataset.DatasetSchedule.PaymentDate);

                        viewModel.AddRange(nextAssetCashflowItems);
                        return ActionUtils.Success(viewModel);
                    }
                }
                else if (asset.AmortizationType == AmortizationType.SingleAmortization)
                {
                    var records = dataset.AmortizationSchedule.SelectByAsset(assetId);
                    var sumPrepayMoney = records.Sum(x => x.ReductionAmount);
                    var viewModel = new PrepayRecordListViewModel(dataset.DatasetSchedule, records);
                    viewModel.Add(assetId, asset.SecurityData.PrincipalBalance - sumPrepayMoney, project.DealSchedule.LegalMaturity);
                    return ActionUtils.Success(viewModel);
                }

                return ActionUtils.Failure("无法识别的偿付类型,projectGuid=["
                                           + projectGuid + "] + paymentDate=[" + paymentDate + "] + assetId=[" + assetId + "]");
            }));
        }
Ejemplo n.º 2
0
        public ActionResult DeleteTemplate(string templateGuid)
        {
            return(ActionUtils.Json(() =>
            {
                var template = m_dbAdapter.Template.GetTemplate(templateGuid);
                var result = m_dbAdapter.Template.DeleteTemplate(template);

                if (result != 1)
                {
                    return ActionUtils.Failure("删除模板 [" + template.TemplateName + "] 失败");
                }

                LogEditProduct(EditProductType.CreateProduct, null, "删除Template[" + template.TemplateId + "][" + template.TemplateName + "]", "");
                return ActionUtils.Success(result);
            }));
        }