예제 #1
0
        public ActionResult CreateManualDistribution(FormCollection collection)
        {
            CreateDistributionModel model=new CreateDistributionModel();
            ResultModel resultModel=new ResultModel();
            this.TryUpdateModel(model,collection);

            CheckDistributionAmount(model);

            if(ModelState.IsValid) {

                // Attempt to create cash distribution.

                CapitalDistribution distribution=new CapitalDistribution();
                CapitalDistributionLineItem item;
                distribution.CapitalDistributionDate=model.CapitalDistributionDate;
                distribution.CapitalDistributionDueDate=model.CapitalDistributionDueDate;

                distribution.PreferredReturn=model.PreferredReturn;
                distribution.ReturnManagementFees=model.ReturnManagementFees;
                distribution.ReturnFundExpenses=model.ReturnFundExpenses;
                distribution.PreferredCatchUp=model.PreferredCatchUp;
                distribution.Profits=model.GPProfits;
                distribution.LPProfits=model.LPProfits;

                distribution.CreatedBy=Authentication.CurrentUser.UserID;
                distribution.CreatedDate=DateTime.Now;
                distribution.LastUpdatedBy=Authentication.CurrentUser.UserID;
                distribution.LastUpdatedDate=DateTime.Now;
                distribution.DistributionAmount=model.DistributionAmount;
                distribution.DistributionNumber=Convert.ToString(CapitalCallRepository.FindCapitalCallDistributionNumber(model.FundId));
                distribution.FundID=model.FundId;
                distribution.CapitalReturn=model.CapitalReturn;
                distribution.IsManual=true;

                int index;

                for(index=1;index<model.InvestorCount+1;index++) {
                    // Attempt to create cash distribution of each investor.

                    item=new CapitalDistributionLineItem();
                    item.CapitalReturn=0;
                    item.CreatedBy=Authentication.CurrentUser.UserID;
                    item.CreatedDate=DateTime.Now;
                    item.LastUpdatedBy=Authentication.CurrentUser.UserID;
                    item.LastUpdatedDate=DateTime.Now;
                    item.InvestorID=DataTypeHelper.ToInt32(collection[index.ToString()+"_"+"InvestorId"]);
                    item.DistributionAmount=DataTypeHelper.ToDecimal(collection[index.ToString()+"_"+"DistributionAmount"]);
                    item.ReturnManagementFees=DataTypeHelper.ToDecimal(collection[index.ToString()+"_"+"ReturnManagementFees"]);
                    item.ReturnFundExpenses=DataTypeHelper.ToDecimal(collection[index.ToString()+"_"+"ReturnFundExpenses"]);
                    item.Profits=DataTypeHelper.ToDecimal(collection[index.ToString()+"_"+"GPProfits"]);
                    item.PreferredReturn=DataTypeHelper.ToDecimal(collection[index.ToString()+"_"+"PreferredReturn"]);
                    if(item.InvestorID>0) {
                        distribution.CapitalDistributionLineItems.Add(item);
                    }
                }
                if(distribution.CapitalDistributionLineItems.Count==0) {
                    ModelState.AddModelError("InvestorCount","Select any one investor");
                } else {
                    IEnumerable<ErrorInfo> errorInfo=CapitalCallRepository.SaveCapitalDistribution(distribution);
                    resultModel.Result+=ValidationHelper.GetErrorInfo(errorInfo);
                    if(string.IsNullOrEmpty(resultModel.Result)) {
                        resultModel.Result+="True||"+(CapitalCallRepository.FindCapitalCallDistributionNumber(model.FundId));
                    }
                }
            }
            if(ModelState.IsValid==false) {
                foreach(var values in ModelState.Values.ToList()) {
                    foreach(var err in values.Errors.ToList()) {
                        if(string.IsNullOrEmpty(err.ErrorMessage)==false) {
                            resultModel.Result+=err.ErrorMessage+"\n";
                        }
                    }
                }
            }
            return View("Result",resultModel);
        }
예제 #2
0
        public ActionResult CreateDistribution(FormCollection collection)
        {
            CreateDistributionModel model=new CreateDistributionModel();
            ResultModel resultModel=new ResultModel();
            this.TryUpdateModel(model,collection);

            CheckDistributionAmount(model);

            if(ModelState.IsValid) {

                // Attempt to create cash distribution.

                CapitalDistribution distribution=new CapitalDistribution();
                CapitalDistributionLineItem item;
                distribution.CapitalDistributionDate=model.CapitalDistributionDate;
                distribution.CapitalDistributionDueDate=model.CapitalDistributionDueDate;

                distribution.CapitalReturn=model.CapitalReturn;
                distribution.PreferredReturn=model.PreferredReturn;
                distribution.ReturnManagementFees=model.ReturnManagementFees;
                distribution.ReturnFundExpenses=model.ReturnFundExpenses;
                distribution.PreferredCatchUp=model.PreferredCatchUp;
                distribution.Profits=model.GPProfits;
                distribution.LPProfits=model.LPProfits;

                distribution.CreatedBy=Authentication.CurrentUser.UserID;
                distribution.CreatedDate=DateTime.Now;
                distribution.LastUpdatedBy=Authentication.CurrentUser.UserID;
                distribution.LastUpdatedDate=DateTime.Now;
                distribution.DistributionAmount=model.DistributionAmount;
                distribution.DistributionNumber=Convert.ToString(CapitalCallRepository.FindCapitalCallDistributionNumber(model.FundId));
                distribution.FundID=model.FundId;
                distribution.IsManual=false;

                // Get all investor funds.
                List<InvestorFund> investorFunds=CapitalCallRepository.GetAllInvestorFunds(distribution.FundID);

                if(investorFunds!=null) {

                    // Find non managing member total commitment.
                    decimal nonManagingMemberTotalCommitment=investorFunds.Where(fund => fund.InvestorTypeID==(int)DeepBlue.Models.Investor.Enums.InvestorType.NonManagingMember).Sum(fund => fund.TotalCommitment);
                    // Find managing member total commitment.
                    decimal managingMemberTotalCommitment=investorFunds.Where(fund => fund.InvestorTypeID==(int)DeepBlue.Models.Investor.Enums.InvestorType.ManagingMember).Sum(fund => fund.TotalCommitment);
                    // Find total commitment.
                    decimal totalCommitment=nonManagingMemberTotalCommitment+managingMemberTotalCommitment;

                    foreach(var investorFund in investorFunds) {

                        // Attempt to create cash distribution of each investor.

                        item=new CapitalDistributionLineItem();

                        item.CreatedBy=Authentication.CurrentUser.UserID;
                        item.CreatedDate=DateTime.Now;
                        item.LastUpdatedBy=Authentication.CurrentUser.UserID;
                        item.LastUpdatedDate=DateTime.Now;
                        item.InvestorID=investorFund.InvestorID;

                        item.CapitalReturn=decimal.Multiply((distribution.CapitalReturn??0),
                                                                decimal.Divide(investorFund.TotalCommitment,totalCommitment)
                                                                );

                        item.PreferredReturn=decimal.Multiply((distribution.PreferredReturn??0),
                                                                decimal.Divide(investorFund.TotalCommitment,totalCommitment)
                                                                );

                        // Non ManagingMember investor type only
                        if(investorFund.InvestorTypeID==(int)DeepBlue.Models.Investor.Enums.InvestorType.NonManagingMember) {
                            item.ReturnManagementFees=decimal.Multiply((distribution.ReturnManagementFees??0),
                                                                         decimal.Divide(investorFund.TotalCommitment,nonManagingMemberTotalCommitment)
                                                                        );
                        }

                        item.ReturnFundExpenses=decimal.Multiply((distribution.ReturnFundExpenses??0),
                                                                decimal.Divide(investorFund.TotalCommitment,totalCommitment)
                                                                );

                        // ManagingMember investor type only
                        if(investorFund.InvestorTypeID==(int)DeepBlue.Models.Investor.Enums.InvestorType.ManagingMember) {
                            item.PreferredCatchUp=distribution.PreferredCatchUp;
                        }

                        // ManagingMember investor type only
                        if(investorFund.InvestorTypeID==(int)DeepBlue.Models.Investor.Enums.InvestorType.ManagingMember) {
                            item.Profits=distribution.Profits;
                        }

                        item.LPProfits=decimal.Multiply((distribution.LPProfits??0),
                                                        decimal.Divide(investorFund.TotalCommitment,totalCommitment)
                                                        );

                        // Calculate distribution amount of each investor.
                        item.DistributionAmount=(item.CapitalReturn??0)
                                                    +(item.PreferredReturn??0)
                                                    +(item.ReturnManagementFees??0)
                                                    +(item.ReturnFundExpenses??0)
                                                    +(item.PreferredCatchUp??0)
                                                    +(item.Profits??0)
                                                    +(item.LPProfits??0)
                                                    ;
                        distribution.CapitalDistributionLineItems.Add(item);
                    }
                }
                IEnumerable<ErrorInfo> errorInfo=CapitalCallRepository.SaveCapitalDistribution(distribution);
                resultModel.Result+=ValidationHelper.GetErrorInfo(errorInfo);
                if(string.IsNullOrEmpty(resultModel.Result)) {
                    resultModel.Result+="True||"+(CapitalCallRepository.FindCapitalCallDistributionNumber(model.FundId))+"||"+distribution.CapitalDistributionID;
                }
            }
            if(ModelState.IsValid==false) {
                foreach(var values in ModelState.Values.ToList()) {
                    foreach(var err in values.Errors.ToList()) {
                        if(string.IsNullOrEmpty(err.ErrorMessage)==false) {
                            resultModel.Result+=err.ErrorMessage+"\n";
                        }
                    }
                }
            }
            return View("Result",resultModel);
        }
예제 #3
0
        public ActionResult ImportCapitalDistributionExcel(FormCollection collection)
        {
            ImportManualCapitalDistributionExcelModel model=new ImportManualCapitalDistributionExcelModel();
            ResultModel resultModel=new ResultModel();
            MemoryCacheManager cacheManager=new MemoryCacheManager();
            int totalPages=0;
            int totalRows=0;
            int completedRows=0;
            int? succssRows=0;
            int? errorRows=0;
            this.TryUpdateModel(model);
            if(ModelState.IsValid) {
                string key=string.Format(EXCELCAPITALCALLERROR_BY_KEY,model.SessionKey);
                List<DeepBlue.Models.Deal.ImportExcelError> errors=cacheManager.Get(key,() => {
                    return new List<DeepBlue.Models.Deal.ImportExcelError>();
                });
                DataSet ds=ExcelConnection.ImportExcelDataset(model.SessionKey);
                if(ds!=null) {
                    PagingDataTable importExcelTable=null;
                    if(ds.Tables[model.ManualCapitalDistributionTableName]!=null) {
                        importExcelTable=(PagingDataTable)ds.Tables[model.ManualCapitalDistributionTableName];
                    }
                    if(importExcelTable!=null) {
                        importExcelTable.PageSize=model.PageSize;
                        PagingDataTable table=importExcelTable.Skip(model.PageIndex);
                        totalPages=importExcelTable.TotalPages;
                        totalRows=importExcelTable.TotalRows;
                        if(totalPages>model.PageIndex) {
                            completedRows=(model.PageIndex*importExcelTable.PageSize);
                        } else {
                            completedRows=totalRows;
                        }

                        int rowNumber=0;

                        string investorName=string.Empty;
                        string fundName=string.Empty;
                        decimal capitalDistributionAmount=0;
                        decimal returnManagementFees=0;
                        decimal returnFundExpenses=0;
                        decimal costReturned=0;
                        decimal profits=0;
                        decimal profitsReturned=0;
                        DateTime distributionDate;
                        DateTime distributionDueDate;

                        DeepBlue.Models.Deal.ImportExcelError error;
                        DeepBlue.Models.Entity.Investor investor;
                        DeepBlue.Models.Entity.Fund fund;
                        DeepBlue.Models.Entity.InvestorFund investorFund;

                        EmailAttribute emailValidation=new EmailAttribute();
                        ZipAttribute zipAttribute=new ZipAttribute();
                        WebAddressAttribute webAttribute=new WebAddressAttribute();
                        IEnumerable<ErrorInfo> errorInfo;

                        StringBuilder rowErrors;
                        foreach(DataRow row in table.Rows) {
                            int.TryParse(row.GetValue("RowNumber"),out rowNumber);

                            error=new DeepBlue.Models.Deal.ImportExcelError { RowNumber=rowNumber };
                            rowErrors=new StringBuilder();

                            investorName=row.GetValue(model.InvestorName);
                            fundName=row.GetValue(model.FundName);
                            decimal.TryParse(row.GetValue(model.CapitalDistributionAmount),out capitalDistributionAmount);
                            decimal.TryParse(row.GetValue(model.ReturnManagementFees),out returnManagementFees);
                            decimal.TryParse(row.GetValue(model.ReturnFundExpenses),out returnFundExpenses);
                            decimal.TryParse(row.GetValue(model.CostReturned),out costReturned);
                            decimal.TryParse(row.GetValue(model.Profits),out profits);
                            decimal.TryParse(row.GetValue(model.ProfitsReturned),out profitsReturned);
                            DateTime.TryParse(row.GetValue(model.DistributionDate),out distributionDate);
                            DateTime.TryParse(row.GetValue(model.DistributionDueDate),out distributionDueDate);

                            investor=null;
                            fund=null;
                            investorFund=null;

                            if(string.IsNullOrEmpty(investorName)==false) {
                                investor=InvestorRepository.FindInvestor(investorName);
                            } else {
                                error.Errors.Add(new ErrorInfo(model.InvestorName,"Investor is required"));
                            }

                            if(string.IsNullOrEmpty(fundName)==false) {
                                fund=FundRepository.FindFund(fundName);
                            } else {
                                error.Errors.Add(new ErrorInfo(model.InvestorName,"Fund is required"));
                            }

                            if(investor!=null&&fund!=null) {
                                investorFund=InvestorRepository.FindInvestorFund(investor.InvestorID,fund.FundID);
                            }

                            if(error.Errors.Count()==0) {
                                if(investorFund==null) {
                                    error.Errors.Add(new ErrorInfo(model.InvestorName,"Investror Commitment does not exist"));
                                }
                            }

                            if(error.Errors.Count()==0) {

                                Models.Entity.CapitalDistribution distribution=CapitalCallRepository.FindCapitalDistribution(
                                    (fund!=null?fund.FundID:0),
                                           distributionDate,
                                           distributionDueDate,
                                           true);

                                if(distribution==null) {
                                    distribution=new Models.Entity.CapitalDistribution();
                                    distribution.CreatedBy=Authentication.CurrentUser.UserID;
                                    distribution.CreatedDate=DateTime.Now;
                                }

                                distribution.CapitalDistributionDate=distributionDate;
                                distribution.CapitalDistributionDueDate=distributionDueDate;

                                distribution.PreferredReturn=(distribution.PreferredReturn??0)+profitsReturned;
                                distribution.ReturnManagementFees=(distribution.ReturnManagementFees??0)+returnManagementFees;
                                distribution.ReturnFundExpenses=(distribution.ReturnFundExpenses??0)+returnFundExpenses;
                                distribution.Profits=(distribution.Profits??0)+profits;
                                distribution.DistributionAmount=distribution.DistributionAmount+capitalDistributionAmount;

                                distribution.LastUpdatedBy=Authentication.CurrentUser.UserID;
                                distribution.LastUpdatedDate=DateTime.Now;

                                distribution.DistributionNumber=Convert.ToString(CapitalCallRepository.FindCapitalCallDistributionNumber((fund!=null?fund.FundID:0)));
                                distribution.FundID=(fund!=null?fund.FundID:0);
                                distribution.CapitalReturn=(distribution.CapitalReturn??0)+costReturned;
                                distribution.IsManual=true;

                                if(error.Errors.Count()==0) {
                                    errorInfo=CapitalCallRepository.SaveCapitalDistribution(distribution);
                                    if(errorInfo!=null) {
                                        error.Errors.Add(new ErrorInfo(model.InvestorName,ValidationHelper.GetErrorInfo(errorInfo)));
                                    }
                                }

                                if(error.Errors.Count()==0) {
                                    CapitalDistributionLineItem item=CapitalCallRepository.FindCapitalDistributionLineItem(distribution.CapitalDistributionID,investor.InvestorID);
                                    if(item==null) {
                                        item=new CapitalDistributionLineItem();
                                        item.CreatedBy=Authentication.CurrentUser.UserID;
                                        item.CreatedDate=DateTime.Now;
                                    }
                                    item.CapitalReturn=0;
                                    item.CreatedBy=Authentication.CurrentUser.UserID;
                                    item.CreatedDate=DateTime.Now;
                                    item.LastUpdatedBy=Authentication.CurrentUser.UserID;
                                    item.LastUpdatedDate=DateTime.Now;
                                    item.InvestorID=(investor!=null?investor.InvestorID:0);
                                    item.DistributionAmount=capitalDistributionAmount;
                                    item.ReturnManagementFees=returnManagementFees;
                                    item.ReturnFundExpenses=returnFundExpenses;
                                    item.Profits=profits;
                                    item.PreferredReturn=profitsReturned;
                                    item.CapitalReturn=costReturned;
                                    item.CapitalDistributionID=distribution.CapitalDistributionID;
                                    errorInfo=CapitalCallRepository.SaveCapitalDistributionLineItem(item);
                                    if(errorInfo!=null) {
                                        error.Errors.Add(new ErrorInfo(model.InvestorName,ValidationHelper.GetErrorInfo(errorInfo)));
                                    }
                                }

                            }

                            StringBuilder sberror=new StringBuilder();
                            foreach(var e in error.Errors) {
                                sberror.AppendFormat("{0},",e.ErrorMessage);
                            }
                            importExcelTable.AddError(rowNumber-1,sberror.ToString());
                            errors.Add(error);
                        }
                    }
                }
                if(errors!=null) {
                    succssRows=errors.Where(e => e.Errors.Count==0).Count();
                    errorRows=errors.Where(e => e.Errors.Count>0).Count();
                }
            } else {
                foreach(var values in ModelState.Values.ToList()) {
                    foreach(var err in values.Errors.ToList()) {
                        if(string.IsNullOrEmpty(err.ErrorMessage)==false) {
                            resultModel.Result+=err.ErrorMessage+"\n";
                        }
                    }
                }
            }
            return Json(new {
                Result=resultModel.Result,
                TotalRows=totalRows,
                CompletedRows=completedRows,
                TotalPages=totalPages,
                PageIndex=model.PageIndex,
                SuccessRows=succssRows,
                ErrorRows=errorRows
            });
        }
예제 #4
0
 public ActionResult ImportManualDistributionLineItem(FormCollection collection)
 {
     CapitalDistributionLineItem item=new CapitalDistributionLineItem();
     ResultModel resultModel=new ResultModel();
     this.TryUpdateModel(item,collection);
     item.CreatedBy=Authentication.CurrentUser.UserID;
     item.CreatedDate=DateTime.Now;
     item.LastUpdatedBy=Authentication.CurrentUser.UserID;
     item.LastUpdatedDate=DateTime.Now;
     IEnumerable<ErrorInfo> errorInfo=ValidationHelper.Validate(item);
     if(errorInfo.Any()==false) {
         // Attempt to create cash distribution of each investor.
         errorInfo=CapitalCallRepository.SaveCapitalDistributionLineItem(item);
         resultModel.Result+=ValidationHelper.GetErrorInfo(errorInfo);
         if(string.IsNullOrEmpty(resultModel.Result)) {
             resultModel.Result+="True||"+item.CapitalDistributionLineItemID;
         }
     } else {
         resultModel.Result=ValidationHelper.GetErrorInfo(errorInfo);
     }
     return View("Result",resultModel);
 }
예제 #5
0
        private static CapitalDistributionLineItem GetCapitalDistributionLineItemFromBlue(C6_30tblLPDistributions blueCapitalDistLineItem, int fundID, BlueEntities context, CookieCollection cookies, out string resp)
        {
            resp = string.Empty;
            CapitalDistributionLineItem deepBlueCDLineItem = new CapitalDistributionLineItem();
            if (blueCapitalDistLineItem.DistributionAmount.HasValue) {
                deepBlueCDLineItem.DistributionAmount = (decimal)blueCapitalDistLineItem.DistributionAmount.Value;
            }
            // Investor ID
            int? investorId = GetInvestorID(blueCapitalDistLineItem.LimitedPartner, fundID, context, cookies);
            if (investorId.HasValue) {
                deepBlueCDLineItem.InvestorID = investorId.Value;
            } else {
                resp = string.Format("Unable to find investor: {0} in FundID: {1} (AmberbrookFund#: {2})" , blueCapitalDistLineItem.LimitedPartner, fundID, blueCapitalDistLineItem.AmberbrookFundNo);
                Util.WriteError(resp);
            }

            deepBlueCDLineItem.PaidON = blueCapitalDistLineItem.TransactionDate;
            deepBlueCDLineItem.IsReconciled = true;

            // WARNING: The following fields are present in DeepBlue but are not present in Blue
            //deepBlueCDLineItem.CapitalReturn
            //deepBlueCDLineItem.LPProfits;
            //deepBlueCDLineItem.PreferredCatchUp;
            //deepBlueCDLineItem.PreferredReturn;
            //deepBlueCDLineItem.Profits;
            //deepBlueCDLineItem.ReconciliationMethod;
            //deepBlueCDLineItem.ReturnFundExpenses;
            //deepBlueCDLineItem.ReturnManagementFees;

            // Preferred Return and Return Management Fees are available on the Capital Distribution level.
            // Distribute it pro-rate?
            // Get the commitment for investor in this fund
            return deepBlueCDLineItem;
        }