public JsonResult LoanSummaryInfo(LoanManagementSystem.Models.sdtoViewReportFilter Filter)
        {
            Filter.DepositIds = GetList(Filter.DepositIds.FirstOrDefault());
            Filter.AccountIds = GetList(Filter.AccountIds.FirstOrDefault());
            Filter.LoanIds = GetList(Filter.LoanIds.FirstOrDefault());
            Filter.MemberIds = GetList(Filter.MemberIds.FirstOrDefault());
            Filter.StatusIds = GetList(Filter.StatusIds.FirstOrDefault());

            sdtoUser sessionUser = UtilityHelper.UserSession.GetSession(UtilityHelper.UserSession.LoggedInUser) as sdtoUser;
            long CompanyId = 0;
            if (sessionUser != null && sessionUser.CompanyId != null)
                CompanyId = sessionUser.CompanyId.Value;

            DataTable dtRptParams = new DataTable();
            dtRptParams.Columns.Add(new DataColumn("EntityId", typeof(long)));
            dtRptParams.Columns.Add(new DataColumn("EntityStartDate", typeof(DateTime)));
            dtRptParams.Columns.Add(new DataColumn("EntityEndDate", typeof(DateTime)));
            dtRptParams.Columns.Add(new DataColumn("EntityIntVal", typeof(int)));
            dtRptParams.Columns.Add(new DataColumn("EntityStrVal", typeof(string)));
            dtRptParams.Columns.Add(new DataColumn("EntityType", typeof(string)));

            foreach (string Id in Filter.MemberIds)
            {
                DataRow row = dtRptParams.NewRow();
                row.ItemArray = new object[] { Id, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, "U" };
                dtRptParams.Rows.Add(row);
            }

            foreach (string Id in Filter.LoanIds)
            {
                DataRow row = dtRptParams.NewRow();
                row.ItemArray = new object[] { Id, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, "L" };
                dtRptParams.Rows.Add(row);
            }

            foreach (string Id in Filter.StatusIds)
            {
                DataRow row = dtRptParams.NewRow();
                row.ItemArray = new object[] { Id, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, "S" };
                dtRptParams.Rows.Add(row);
            }

            DataRow rowDate = dtRptParams.NewRow();
            rowDate.ItemArray = new object[] { 0, Filter.StartDate, Filter.EndDate, DBNull.Value, DBNull.Value, "D" };
            dtRptParams.Rows.Add(rowDate);

            DataRow rowMisc = dtRptParams.NewRow();
            rowMisc.ItemArray = new object[] { 0, DBNull.Value, DBNull.Value, DBNull.Value, Filter.MiscFilter, "M" };
            dtRptParams.Rows.Add(rowMisc);

            bfReport objReport = new bfReport(null);
            return Json(objReport.GetRptLoanSummary(CompanyId, dtRptParams), JsonRequestBehavior.AllowGet);
        }
        public ActionResult ExportView()
        {
            sdtoUser sessionUser = UtilityHelper.UserSession.GetSession(UtilityHelper.UserSession.LoggedInUser) as sdtoUser;
            long CompanyId = 0;
            if (sessionUser != null && sessionUser.CompanyId != null)
                CompanyId = sessionUser.CompanyId.Value;

            DataTable dtRptParams = new DataTable();
            dtRptParams.Columns.Add(new DataColumn("EntityId", typeof(long)));
            dtRptParams.Columns.Add(new DataColumn("EntityStartDate", typeof(DateTime)));
            dtRptParams.Columns.Add(new DataColumn("EntityEndDate", typeof(DateTime)));
            dtRptParams.Columns.Add(new DataColumn("EntityIntVal", typeof(int)));
            dtRptParams.Columns.Add(new DataColumn("EntityStrVal", typeof(string)));
            dtRptParams.Columns.Add(new DataColumn("EntityType", typeof(string)));

            bfReport objReport = new bfReport(null);
            var loanInfoList = objReport.GetRptLoanSummary(CompanyId, dtRptParams).ToList().Select(x => new sdtoLoanRepayment() { LoanId = x.LoanId, LoanDetails = new sdtoLoanInfo() { Member = new sdtoUser() { FirstName = x.FirstName, LastName = x.LastName } }, PendingPrincipalAmount = x.BalanceLoanAmount });

            return View(loanInfoList);
        }
        public ActionResult ImportView(HttpPostedFileBase DeviceInput)
        {
            StreamReader reader = new StreamReader(DeviceInput.InputStream);
            while (!reader.EndOfStream)
            {
                string lineInput = reader.ReadLine();
                if (!string.IsNullOrWhiteSpace(lineInput))
                {
                    string[] arrLines = lineInput.Split("\0".ToCharArray());
                    if (arrLines != null && arrLines.Length > 0)
                    {
                        foreach (string strLine in arrLines)
                        {
                            string[] arrValues = strLine.Split(",".ToCharArray());
                            if (arrValues != null && arrValues.Length > 10)
                            {
                                sdtoLoanRepayment repayment = new sdtoLoanRepayment();
                                long iLoanId = 0;
                                long.TryParse(arrValues[2], out iLoanId);
                                repayment.LoanId = iLoanId;
                                if (repayment.LoanId > 0)
                                {
                                    float fPaymentAmount = 0;
                                    float.TryParse(arrValues[3], out fPaymentAmount);

                                    DateTime dt = DateTime.Now;
                                    DateTime.TryParse(arrValues[8], out dt);

                                    repayment.RepaymentDate = dt;

                                    var loandetails = db.sdtoLoanInfoes.Find(repayment.LoanId);

                                    if (loandetails != null)
                                    {
                                        var loanPendingAmt = loandetails.LoanAmount;
                                        var loanInterest = loandetails.InteresRate;
                                        var loanPendingInstallments = loandetails.TotalInstallments;

                                        var loanRepayment = db.sdtoLoanRepayments.Where(x => x.LoanId == repayment.LoanId && x.IsDeleted == false && x.Status != RepaymentStatus.Cancelled).OrderByDescending(x => x.LoanRepaymentId).FirstOrDefault();
                                        var repaymentInterest = loanInterest;
                                        var repaymentInterestAmt = (loanPendingAmt * Convert.ToDecimal(repaymentInterest / 100)) / 365;

                                        if (loanRepayment != null && loanRepayment.LoanRepaymentId > 0)
                                        {
                                            loanPendingAmt = loanRepayment.PendingPrincipalAmount;
                                            loanPendingInstallments = loanRepayment.PendingInstallments;
                                            repaymentInterest = loanRepayment.InterestRate;

                                            repaymentInterestAmt = (loanPendingAmt * Convert.ToDecimal(repaymentInterest / 100)) / 365;
                                            repayment.RepaymentCode = loanRepayment.RepaymentCode;
                                        }

                                        repayment.InterestAmount = Math.Round(repaymentInterestAmt, 2);
                                        repayment.PendingPrincipalAmount = loanPendingAmt - (repayment.RepaymentAmount - repaymentInterestAmt);
                                        repayment.PendingInstallments -= Convert.ToInt32(Math.Floor(repayment.PendingPrincipalAmount / loandetails.InstallmentAmount));
                                        repayment.PrincipalAmount = loandetails.LoanAmount;

                                        repayment.Status = Data.Models.Enumerations.RepaymentStatus.Paid;
                                        repayment.CreatedOn = DateTime.Now;

                                        db.sdtoLoanRepayments.Add(repayment);
                                        db.SaveChanges();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            reader.Close();

            sdtoUser sessionUser = UtilityHelper.UserSession.GetSession(UtilityHelper.UserSession.LoggedInUser) as sdtoUser;
            long CompanyId = 0;
            if (sessionUser != null && sessionUser.CompanyId != null)
                CompanyId = sessionUser.CompanyId.Value;

            DataTable dtRptParams = new DataTable();
            dtRptParams.Columns.Add(new DataColumn("EntityId", typeof(long)));
            dtRptParams.Columns.Add(new DataColumn("EntityStartDate", typeof(DateTime)));
            dtRptParams.Columns.Add(new DataColumn("EntityEndDate", typeof(DateTime)));
            dtRptParams.Columns.Add(new DataColumn("EntityIntVal", typeof(int)));
            dtRptParams.Columns.Add(new DataColumn("EntityStrVal", typeof(string)));
            dtRptParams.Columns.Add(new DataColumn("EntityType", typeof(string)));

            bfReport objReport = new bfReport(null);
            var loanInfoList = objReport.GetRptLoanSummary(CompanyId, dtRptParams).ToList().Select(x => new sdtoLoanRepayment() { LoanId = x.LoanId, LoanDetails = new sdtoLoanInfo() { Member = new sdtoUser() { FirstName = x.FirstName, LastName = x.LastName } }, PendingPrincipalAmount = x.BalanceLoanAmount });

            return View(loanInfoList);
        }
        public FileStreamResult Export()
        {
            //var sdtoLoanInfoes = db.sdtoLoanInfoes.Include(s => s.CreatedByUser).Include(s => s.DeletedByUser).Include(s => s.Member).Include(s => s.ModifiedByUser).Where(x => x.IsDeleted == false && x.Status == LoanStatus.Active);
            sdtoUser sessionUser = UtilityHelper.UserSession.GetSession(UtilityHelper.UserSession.LoggedInUser) as sdtoUser;
            long CompanyId = 0;
            if (sessionUser != null && sessionUser.CompanyId != null)
                CompanyId = sessionUser.CompanyId.Value;

            DataTable dtRptParams = new DataTable();
            dtRptParams.Columns.Add(new DataColumn("EntityId", typeof(long)));
            dtRptParams.Columns.Add(new DataColumn("EntityStartDate", typeof(DateTime)));
            dtRptParams.Columns.Add(new DataColumn("EntityEndDate", typeof(DateTime)));
            dtRptParams.Columns.Add(new DataColumn("EntityIntVal", typeof(int)));
            dtRptParams.Columns.Add(new DataColumn("EntityStrVal", typeof(string)));
            dtRptParams.Columns.Add(new DataColumn("EntityType", typeof(string)));

            bfReport objReport = new bfReport(null);
            var loanInfoList = objReport.GetRptLoanSummary(CompanyId, dtRptParams).ToList().Select(x => new sdtoLoanRepayment() { LoanId = x.LoanId, LoanDetails = new sdtoLoanInfo() { Member = new sdtoUser() { FirstName = x.FirstName, LastName = x.LastName } }, PendingPrincipalAmount = x.BalanceLoanAmount }).ToList();

            //string HeaderData = "";
            string Data = "";
            //HeaderData = "Member ID" + "  " + "Name of customer" + "  " + "STOL" + "  " + "Amount" + "  " + "Interest" + Environment.NewLine;
            //Data = HeaderData;
            foreach (sdtoLoanRepayment Linfo in loanInfoList)
            {
                Data += Linfo.LoanId + "                 " + Linfo.LoanDetails.Member.FirstName + " " + Linfo.LoanDetails.Member.FirstName + "       STOL            " + Linfo.PendingPrincipalAmount + "                             " + Linfo.LoanDetails.InteresRate + "                                                                                                                                                      ";
                //Data += Linfo.Member.UserID.ToString() + " " + Linfo.Member.FirstName + " " + "STOL" + " " + Linfo.LoanAmount.ToString() + " " + Linfo.InteresRate.ToString() + Environment.NewLine;
            }
            var byteArray = Encoding.ASCII.GetBytes(Data);
            var stream = new MemoryStream(byteArray);

            return File(stream, "text/plain", "LoanData.DAT");
        }