Ejemplo n.º 1
0
        /// <summary>
        /// Frontend page: Title(loan setup)
        /// Title: Get details of title related to given loanId
        /// Designed: Piyumi
        /// User story:
        /// Date created: 2016/2/9
        /// </summary>
        /// <param name="loanId"></param>
        /// <returns>TitleObject</returns>
        public Title getTitleDetails(int loanId)
        {
            DataHandler     dataHandler  = new DataHandler();
            List <object[]> paramertList = new List <object[]>();

            paramertList.Add(new object[] { "@loan_id", loanId });

            try
            {
                DataSet dataSet = dataHandler.GetDataSet("spGetTitleDetailsByLoanId", paramertList);
                Title   obj1    = new Title();
                //Check dataset is not null and table count >0
                if (dataSet != null && dataSet.Tables.Count != 0)
                {
                    foreach (DataRow dataRow in dataSet.Tables[0].Rows)
                    {
                        obj1.LoanId       = int.Parse(dataRow["loan_id"].ToString());
                        obj1.IsTitleTrack = bool.Parse(dataRow["is_title_tracked"].ToString());
                        //Check whether title need to be tracked
                        if (obj1.IsTitleTrack)
                        {
                            obj1.ReceivedTimeLimit = dataRow["title_received_time_period"].ToString();
                            //Check auto remind period is null or empty
                            if (!string.IsNullOrEmpty(dataRow["auto_remind_period"].ToString()))
                            {
                                obj1.RemindPeriod = int.Parse(dataRow["auto_remind_period"].ToString());
                            }
                            //Check auto remind email is null or empty
                            if (!string.IsNullOrEmpty(dataRow["auto_remind_email"].ToString()))
                            {
                                obj1.RemindEmail = dataRow["auto_remind_email"].ToString();
                            }
                            else
                            {
                                //get auto remind email given in loan details page
                                LoanSetupAccess st = new LoanSetupAccess();
                                obj1.RemindEmail = st.getAutoRemindEmailByLoanId(obj1.LoanId);
                            }
                        }
                        else
                        {
                            //get auto remind email given in loan details page
                            LoanSetupAccess st = new LoanSetupAccess();
                            obj1.RemindEmail = st.getAutoRemindEmailByLoanId(obj1.LoanId);
                        }
                        obj1.IsReceipRequired = bool.Parse(dataRow["is_receipt_required"].ToString());
                        //Check whether receipts are required
                        if (obj1.IsReceipRequired)
                        {
                            obj1.ReceiptRequiredMethod = dataRow["receipt_required_method"].ToString();
                        }
                        //Check need scan copy value is null or empty
                        if (!string.IsNullOrEmpty(dataRow["need_scan_copy"].ToString()))
                        {
                            obj1.NeedScanCopy = bool.Parse(dataRow["need_scan_copy"].ToString());
                            //Check need scan copy value is true
                            if (obj1.NeedScanCopy)
                            {
                                obj1.TitleAcceptMethod = "Scanned Title Adequate";
                            }
                        }
                    }
                    return(obj1);
                }
                else
                {
                    return(obj1);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Frontend page: Title(loan setup)
        /// Title: Get details of title related to given loanId
        /// Designed: Piyumi
        /// User story:
        /// Date created: 2016/2/9
        /// </summary>
        /// <param name="loanId"></param>
        /// <returns>TitleObject</returns>
        public Title getTitleDetails(int loanId)
        {
            DataHandler dataHandler = new DataHandler();
            List<object[]> paramertList = new List<object[]>();
            paramertList.Add(new object[] { "@loan_id", loanId });

            try
            {
                DataSet dataSet = dataHandler.GetDataSet("spGetTitleDetailsByLoanId", paramertList);
                Title obj1 = new Title();
                //Check dataset is not null and table count >0
                if (dataSet != null && dataSet.Tables.Count != 0)
                {
                   
                    foreach (DataRow dataRow in dataSet.Tables[0].Rows)
                    {
                        
                        obj1.LoanId = int.Parse(dataRow["loan_id"].ToString());
                        obj1.IsTitleTrack = bool.Parse(dataRow["is_title_tracked"].ToString());
                        //Check whether title need to be tracked
                        if (obj1.IsTitleTrack)
                        {
                        
                            obj1.ReceivedTimeLimit = dataRow["title_received_time_period"].ToString();
                            //Check auto remind period is null or empty
                            if (!string.IsNullOrEmpty(dataRow["auto_remind_period"].ToString()))
                            {
                                obj1.RemindPeriod = int.Parse(dataRow["auto_remind_period"].ToString());
                            }
                            //Check auto remind email is null or empty
                            if (!string.IsNullOrEmpty(dataRow["auto_remind_email"].ToString()))
                            {
                                obj1.RemindEmail = dataRow["auto_remind_email"].ToString();
                            }
                            else
                            {
                            //get auto remind email given in loan details page
                                LoanSetupAccess st = new LoanSetupAccess();
                                obj1.RemindEmail = st.getAutoRemindEmailByLoanId(obj1.LoanId);
                            }

                        }
                        else 
                        {
                            //get auto remind email given in loan details page
                            LoanSetupAccess st = new LoanSetupAccess();
                            obj1.RemindEmail = st.getAutoRemindEmailByLoanId(obj1.LoanId);
                        }
                        obj1.IsReceipRequired = bool.Parse(dataRow["is_receipt_required"].ToString());
                        //Check whether receipts are required
                        if (obj1.IsReceipRequired)
                        {

                            obj1.ReceiptRequiredMethod = dataRow["receipt_required_method"].ToString();
                        }
                        //Check need scan copy value is null or empty
                        if (!string.IsNullOrEmpty(dataRow["need_scan_copy"].ToString()))
                        {
                            obj1.NeedScanCopy = bool.Parse(dataRow["need_scan_copy"].ToString());
                            //Check need scan copy value is true
                            if (obj1.NeedScanCopy)
                            {
                                obj1.TitleAcceptMethod = "Scanned Title Adequate";
                            }
                        }
                    }
                    return obj1;
                }
                else
                {
                  return obj1;
                }
             }
            catch (Exception ex)
            {
                throw ex;

            }
           
        }
 ///<summary>
 /// Frontend page: Post Method for Inactive Loan
 /// Title: create view and get active loan details for inactive in Post method
 /// Designed : Asanka Senarathna
 /// User story: DFP-103
 /// Developed: Asanka Senarathna
 /// Date created: 6/27/2016
 ///</summary>
 /// <param name="slctdLoanId"></param>
 /// <param name="slctdLoanCode"></param>
 public void UpdateLoanStatus_ActiveInactive(int slctdLoanId, string slctdLoanCode)
 {
     //check Loan ID and Loan code has value for update loan
     if ((slctdLoanId > 0) && (!string.IsNullOrEmpty(slctdLoanCode)))
    {
         LoanSetupAccess ls = new LoanSetupAccess();
         int reslt = ls.UpdateLoanStatus_ActiveInactive(slctdLoanId, slctdLoanCode);
         //Update loan statues as Inactive(set loan_status = 0)
         if (reslt == 1)
         {
             Log log = new Log(userData.UserId, userData.Company_Id, userData.BranchId, 0, "Inactive Loan", "Loan Id : " + slctdLoanId + " ,Edited Status : Inactive", DateTime.Now);
             //Insert new record to log 
             int islog = (new LogAccess()).InsertLog(log);
             TempData["EditReslt"] = "success";
         }
         else
         {
             TempData["EditReslt"] = "failed";
         }
     }
     else
     {
         TempData["EditReslt"] = "failed";
     }
 }
        /// <summary>
        /// CreatedBy : Piyumi
        /// CreatedDate: 2016/04/20
        /// 
        /// edit loan - post
        /// 
        /// </summary>
        /// <returns></returns>
        /// 
       
        public void UpdateLoanStatus(int slctdLoanId,string slctdLoanCode,string slctdActiveDate)
        {
           if((slctdLoanId>0)&&(!string.IsNullOrEmpty(slctdLoanCode)) && (!string.IsNullOrEmpty(slctdActiveDate))) 
           {
                LoanSetupAccess ls = new LoanSetupAccess();
                int reslt = ls.UpdateLoanStatus(slctdLoanId, slctdLoanCode, slctdActiveDate);
                if(reslt==1) 
                {
                    Log log = new Log(userData.UserId, userData.Company_Id, userData.BranchId, 0, "Edit Loan", "Loan Id : " + slctdLoanId+" ,Edited Status : Active", DateTime.Now);

                    int islog = (new LogAccess()).InsertLog(log);
                    TempData["EditReslt"] = "success";
                    
                    Session.Remove("loanDashboardEditLoan");
                }
                else 
                {
                    TempData["EditReslt"] = "failed";
                }
           }
            else
            {
                TempData["EditReslt"] = "failed";
            }
        }
        public ActionResult AddCurtailment(List<Curtailment> curtailmentList, CurtailmentModel curtaiulmentModel)
        {
            //calculate payment percentage
            if (userData.RoleId >= 3)
            {
                return RedirectToAction("UserLogin", "Login", new { lbl = "You are not Allowed." });
            }

            CurtailmentAccess curtailmentAccess = new CurtailmentAccess();
            StepAccess sa = new StepAccess();
            if (curtailmentAccess.InsertCurtailment(curtailmentList, loanData.loanId) > 0)
            {
                ViewBag.SuccessMsg = "Curtailment Details added successfully";
                sa.UpdateLoanSetupStep(userData.UserId,loanData.CompanyId, loanData.BranchId, loanData.nonRegisteredBranchId, loanData.loanId, 6);
               
                    Log log = new Log(userData.UserId, userData.Company_Id, loanData.BranchId, loanData.loanId, "Curtailment", "Inserted curtailment details of loan : " + loanData.loanId, DateTime.Now);

                    int islog = (new LogAccess()).InsertLog(log);

                ViewBag.Redirect = 1;
            }
            else
            {
                sa.UpdateLoanSetupStep(userData.UserId,loanData.CompanyId, loanData.BranchId, loanData.nonRegisteredBranchId, loanData.loanId, 6);
                
                    Log log = new Log(userData.UserId, userData.Company_Id, loanData.BranchId, loanData.loanId, "Curtailment", "Edited curtailment details of loan : " + loanData.loanId, DateTime.Now);

                    int islog = (new LogAccess()).InsertLog(log);
               
                ViewBag.SuccessMsg = "Curtailment Details updated successfully";
            }

            //bool loanActive = curtaiulmentModel.LoanStatus == "Yes";

            LoanSetupAccess loanAccess = new LoanSetupAccess();
            loanAccess.UpdateLoanCurtailment(curtaiulmentModel, loanData.loanId);
            TempData["LoanId"] = loanData.loanId;
            return RedirectToAction("Step10", new { lbl = "Details added successfully" });
        }
        public ActionResult Step6(string dashbrd)
        {
            //dashbrd = 6;
            int userrole = userData.RoleId;
            int userId = userData.UserId;

            if (userrole >= 3)
            {
                return RedirectToAction("UserLogin", "Login", new { lbl = "You are not Allowed." });
            }

            UserManageAccess uma = new UserManageAccess();

            // check if step is less than 6, not allowed to this page...

            int stepNo = loanData.stepId;


            if (stepNo < 0)
            {
                return RedirectToAction("UserLogin", "Login", new { lbl = "You are not Allowed." });
            }
            else if ((stepNo == 0)&&(dashbrd== "bshdrdoanl"))
            {
                stepNo = 6;
                loanData.stepId = 1;
                Session["dashboard"] = 1;

                // set the loan setup session to step 1

               
                Session["companyStep"] = 5;
                loanData.stepId = 1;
                Session["loanStep"] = loanData;



            }

            if(TempData["error"] != null && TempData["error"].ToString() == "error")
            {
                ViewBag.Error = "Failed to create loan";
            }

            // get the Role Name for front end view
            ViewBag.userroleName = uma.getUserRoleName(userId);

            BranchAccess ba = new BranchAccess();

            // get the Company type for front end view
            int comType = ba.getCompanyTypeByUserId(userId);
            //int comType = userData.CompanyType;
            ViewBag.ThisCompanyType = (comType == 1) ? "Lender" : "Dealer";//

            // retrieve registered branches, nonregistered branches using his company Id

            List<Branch> RegisteredBranchLists = (new BranchAccess()).getBranches(userData.Company_Id);
            List<NonRegBranch> NonRegisteredBranchLists = (new BranchAccess()).getNonRegBranches(userData.Company_Id);

            // get the payments method for front End View
            List<string> paymentMethods = new List<string>();
            paymentMethods.Add("Auto Deduct/Deposit");
            paymentMethods.Add("Invoice/Check");
            ViewBag.paymentMethods = paymentMethods;


            // Defaul loan setup form and default dates
            LoanSetupStep1 loanSetupStep1 = new LoanSetupStep1();
            loanSetupStep1.startDate = DateTime.Today;
            loanSetupStep1.maturityDate = DateTime.Today.AddDays(1);

            // get loan Id for each user
            LoanSetupAccess la = new LoanSetupAccess();
            int loanId = 0;

            if ((userrole == 1) || (userrole == 2))
            {
                loanId = loanData.loanId;
            }

            // if loan number exists get the loan details
            if (loanId > 0)
            {
                loanSetupStep1 = la.GetLoanStepOne(loanId);
            }

            if (userrole == 2)
            {
                // if user is a admin, his branch id is registerd branch id
                loanSetupStep1.RegisteredBranchId = userData.BranchId;

                // the get registered branch detail from the company branches list
                foreach (Branch branch in RegisteredBranchLists)
                {
                    if (branch.BranchId == userData.BranchId)
                    {
                        var newList = new List<Branch>();
                        newList.Add(branch);
                        ViewBag.RegisteredBranchId = new SelectList(newList, "BranchId", "BranchName", userData.BranchId);
                    }
                }
                var newNonRegList = new List<Branch>();

                // the get non registered branches details for perticular branch  from the non registeres branches list
                foreach (NonRegBranch branch in NonRegisteredBranchLists)
                {
                    if (branch.BranchId == userData.BranchId)
                    {

                        newNonRegList.Add(branch);


                    }
                }



                ViewBag.NonRegisteredBranchId = new SelectList(newNonRegList, "NonRegBranchId", "CompanyNameBranchName");


            }
            // if he is a super admin, add all company branches and non registered branches in to the list
            else
            {
                // if super admin get the branch id of the loan
                if (loanId > 0)
                {
                    NonRegBranch nonRegBranch = (new BranchAccess()).getNonRegBranchByNonRegBranchId(loanSetupStep1.nonRegisteredBranchId);
                    loanSetupStep1.RegisteredBranchId = nonRegBranch.BranchId;

                }

                // add banches which contain non reg branches only
                List<Branch> newBranches = new List<Branch>();
                foreach (Branch branch in RegisteredBranchLists)
                {
                    foreach (NonRegBranch nonbranch in NonRegisteredBranchLists)
                    {
                        if (branch.BranchId == nonbranch.BranchId)
                        {

                            newBranches.Add(branch);

                            break;
                        }
                    }
                }


                ViewBag.RegisteredBranchId = new SelectList(newBranches, "BranchId", "BranchName");

                if (newBranches.Count >= 1)
                {
                    ViewBag.NonRegisteredBranchId = new SelectList(NonRegisteredBranchLists, "NonRegBranchId", "CompanyNameBranchName");
                }

            }

            if (NonRegisteredBranchLists.Count == 1)
            {   
                if(userData.RoleId == 1)
                {
                    // the get registered branch detail from the company branches list
                    foreach (Branch branch in RegisteredBranchLists)
                    {
                        if (branch.BranchId == NonRegisteredBranchLists[0].BranchId)
                        {
                            var newList = new List<Branch>();
                            newList.Add(branch);
                            ViewBag.RegisteredBranchId = new SelectList(newList, "BranchId", "BranchName", userData.BranchId);
                        }
                    }
                }
                loanSetupStep1.nonRegisteredBranchId = NonRegisteredBranchLists[0].NonRegBranchId;
            }

            loanSetupStep1.allUnitTypes = (new LoanSetupAccess()).getAllUnitTypes();

            if (loanId > 0)
            {

                loanSetupStep1.allUnitTypes = (new LoanSetupAccess()).getAllUnitTypes();
                //(new LoanSetupAccess()).getSelectedUnitTypes(loanId, loanSetupStep1);
                foreach (UnitType unitType in (List<UnitType>)loanSetupStep1.selectedUnitTypes)
                {
                    foreach (UnitType allUnitType in (List<UnitType>)loanSetupStep1.allUnitTypes)
                    {
                        if (allUnitType.unitTypeId == unitType.unitTypeId)
                        {
                            allUnitType.isSelected = true;
                            continue;
                        }
                    }

                }


            }



            if (HttpContext.Request.IsAjaxRequest())
            {
                ViewBag.AjaxRequest = 1;
                return PartialView(loanSetupStep1);
            }
            else
            {

                return View(loanSetupStep1);
            }
        }
        public ActionResult Step10(string lbl)
        {
            CurtailmentModel curtailment = new CurtailmentModel();

            int userId = userData.UserId;
            if (userData.RoleId >= 3)
            {
                return RedirectToAction("UserLogin", "Login", new { lbl = "You are not Allowed." });
            }

            //check user step is valid for this step
            StepAccess sa = new StepAccess();
            if (loanData.stepId == 5)
            {
                ViewBag.LoanId = 0;
                if (lbl == "Details added successfully")
                {
                    ViewBag.SuccessMsg = "Loan setup is completed";
                    Session["loanStep"] = null;
                    if (TempData["LoanId"] != null && (int)TempData["LoanId"] > 0) {
                        ViewBag.LoanId = (int)TempData["LoanId"];
                    }
                   
                    if (HttpContext.Request.IsAjaxRequest())
                    {
                        ViewBag.AjaxRequest = 1;
                        return PartialView(curtailment);
                    }
                    return View(curtailment);
                }

                int branchId = loanData.BranchId;

                LoanSetupAccess la = new LoanSetupAccess();
                int loanId = loanData.loanId;
                CurtailmentAccess curAccess = new CurtailmentAccess();
                _loan = curAccess.GetLoanDetailsByLoanId(loanId);
                _loan.loanId = loanId;
                
                curtailment.AdvancePt = _loan.advancePercentage;
                curtailment.RemainingPercentage = curtailment.AdvancePt;

                curtailment.InfoModel = new List<Curtailment>();

                var curtailments = curAccess.retreiveCurtailmentByLoanId(loanId);

                int payPercentage = _loan.advancePercentage;
                int? totalPercentage = 0;

                int curId = 0;
                if (curtailments != null && curtailments.Count > 0)
                {
                    for (int i = 0; i < curtailments.Count; i++)
                    {
                        curId++;
                        totalPercentage += curtailments[i].Percentage;
                        curtailment.InfoModel.Add(new Curtailment { CurtailmentId = curId, TimePeriod = curtailments[i].TimePeriod, Percentage = curtailments[i].Percentage });
                    }
                    curtailment.LoanStatus = _loan.LoanStatus ? "Yes" : "No";

                    curtailment.CalculationBase = _loan.CurtailmentCalculationBase == "a" ? "Advance" : "Full payment";
                    curtailment.DueDate = _loan.CurtailmentDueDate;
                    curtailment.AutoRemindEmail = _loan.CurtailmentAutoRemindEmail;
                    curtailment.EmailRemindPeriod = _loan.CurtailmentEmailRemindPeriod;
                }

                ViewBag.CalMode = "Full Payment";
                curtailment.RemainingPercentage = payPercentage - totalPercentage;

                if (curtailment.RemainingPercentage > 0)
                    curtailment.InfoModel.Add(new Curtailment { CurtailmentId = curId + 1 });
                ViewData["objmodel"] = curtailment;

                if (HttpContext.Request.IsAjaxRequest())
                {
                    ViewBag.AjaxRequest = 1;
                    return PartialView(curtailment);
                }
                else
                {

                    return View(curtailment);
                }
            }
            return RedirectToAction("UserLogin", "Login", new { lbl = "Due to inactivity your session has timed out, please log in again." });
        }
        public ActionResult Step9(Title title)
        {
            int userId = userData.UserId;
            int branchId = loanData.BranchId;
            //check user is user or dealer user
            if (userData.RoleId >= 3)
            {
                //return to login page
                return RedirectToAction("UserLogin", "Login", new { lbl = "You are not Allowed." });
            }
         
            TitleAccess ta = new TitleAccess();
            LoanSetupAccess la = new LoanSetupAccess();
            StepAccess sa = new StepAccess();
          
            int loanId = loanData.loanId;
            title.LoanId = loanId;

            if (title.ReceivedTimeLimit == "1")
            {
                title.ReceivedTimeLimit = "Title required to advance";
            }
            else if (title.ReceivedTimeLimit == "2")
            {
                title.ReceivedTimeLimit = "Title can arrive at any time";
            }
            else if (title.ReceivedTimeLimit == "3")
            {
                title.ReceivedTimeLimit = "Title must arrive within a specified time";
            }

            if (title.ReceiptRequiredMethod == "1")
            {
                title.ReceiptRequiredMethod = "Must be physically present";
            }
            else if (title.ReceiptRequiredMethod == "2")
            {
                title.ReceiptRequiredMethod = "Scanned copy only";
            }
            else if (title.ReceiptRequiredMethod == "3")
            {
                title.ReceiptRequiredMethod = "Physically present or scanned copy";
            }
            //insert or update title details and get result
            int reslt = ta.insertTitleDetails(title);
            //check result is not 0
            if (reslt >= 0)
            {
                //update loan setup step table
                if (sa.UpdateLoanSetupStep(userData.UserId,loanData.CompanyId, loanData.BranchId, loanData.nonRegisteredBranchId, loanData.loanId, 5))
                {
                    //check current step value of loanData object is less than 5
                    if (loanData.stepId < 5)
                    {
                        //update step
                        loanData.stepId = 5;
                    }
                    //if title update or insert result is 0
                    if (reslt == 0)
                    {
                        //insert record in to log table as insert
                        Log log = new Log(userData.UserId, userData.Company_Id, loanData.BranchId, title.LoanId, "Title", "Edited title details of loan : " + title.LoanId, DateTime.Now);

                        int islog = (new LogAccess()).InsertLog(log);
                    }
                    if (reslt > 0)
                    {
                        //insert record in to log table as update
                        Log log = new Log(userData.UserId, userData.Company_Id, loanData.BranchId, title.LoanId, "Title", "Inserted title details of loan : " + title.LoanId, DateTime.Now);

                        int islog = (new LogAccess()).InsertLog(log);
                    }
                    //convert loan data object to session variable
                    Session["loanStep"] = loanData;
                    //return to curtailment page
                    return RedirectToAction("Step10");
                }
                //if update loan setup step result is false return to login page
                else
                {
                    return RedirectToAction("UserLogin", "Login", new { lbl = "Due to inactivity your session has timed out, please log in again." });
                }
            }
           
            else
            {
                return new HttpStatusCodeResult(404);
            }
            
        }
        public ActionResult Step9(int? edit)
        {
            int uId = userData.UserId;
            int branchId = loanData.BranchId;
            //check user is user or dealer user
            if (userData.RoleId >= 3)
            {
                //return to login
                return RedirectToAction("UserLogin", "Login", new { lbl = "You are not Allowed." });
            }
            //yes no list
            List<SelectListItem> isTitleTrackList = new List<SelectListItem>();

            isTitleTrackList.Add(new SelectListItem
            {
                Text = "Yes",
                Value = "true"
            });
            isTitleTrackList.Add(new SelectListItem
            {
                Text = "No",
                Value = "false"
            });
            ViewBag.isTitleTrack = new SelectList(isTitleTrackList, "Value", "Text");

            List<SelectListItem> isReceiptList = new List<SelectListItem>();

            isReceiptList.Add(new SelectListItem
            {
                Text = "Yes",
                Value = "true"
            });
            isReceiptList.Add(new SelectListItem
            {
                Text = "No",
                Value = "false"
            });
            ViewBag.IsReceipRequired = new SelectList(isReceiptList, "Value", "Text");
        
            //Time Limit Options
            List<SelectListItem> timeLimitList = new List<SelectListItem>();

            timeLimitList.Add(new SelectListItem
            {
                Text = "Title required to advance",
                Value = "1"
            });


            timeLimitList.Add(new SelectListItem
            {
                Text = "Title can arrive at any time",
                Value = "2"
            });

            timeLimitList.Add(new SelectListItem
            {
                Text = "Title must arrive within a specified time",
                Value = "3"
            });
            ViewBag.ReceivedTimeLimit = new SelectList(timeLimitList, "Value", "Text");
            //Receipt required methods
            List<SelectListItem> receiptRequiredMethodList = new List<SelectListItem>();

            receiptRequiredMethodList.Add(new SelectListItem
            {
                Text = "Must be physically present",
                Value = "1"
            });


            receiptRequiredMethodList.Add(new SelectListItem
            {
                Text = "Scanned copy only",
                Value = "2"
            });

            receiptRequiredMethodList.Add(new SelectListItem
            {
                Text = "Physically present or scanned copy",
                Value = "3"
            });
            ViewBag.ReceiptRequiredMethod = new SelectList(receiptRequiredMethodList, "Value", "Text");
            if (uId > 0)
            {
                LoanSetupAccess la = new LoanSetupAccess();
                TitleAccess ta = new TitleAccess();
                Title title = new Title();
                
                int loanId = loanData.loanId;
                //check loan id is greater than 0
                if (loanId > 0)
                {
                    //check is update
                    if (loanData.stepId>4)
                    {
                        //get title details
                        var titleObj = ta.getTitleDetails(loanId);
                        ViewBag.Edit = 1;
                        //check object is not null
                        if (titleObj != null)
                        {
                            if (titleObj.ReceivedTimeLimit == "Title required to advance")
                            {
                                titleObj.ReceivedTimeLimit = "1";
                            }
                            else if (titleObj.ReceivedTimeLimit == "Title can arrive at any time")
                            {
                                titleObj.ReceivedTimeLimit = "2";
                            }
                            else if (titleObj.ReceivedTimeLimit == "Title must arrive within a specified time")
                            {
                                titleObj.ReceivedTimeLimit = "3";
                            }

                            if (titleObj.ReceiptRequiredMethod == "Must be physically present")
                            {
                                titleObj.ReceiptRequiredMethod = "1";
                            }
                            else if (titleObj.ReceiptRequiredMethod == "Scanned copy only")
                            {
                                titleObj.ReceiptRequiredMethod = "2";
                            }
                            else if (titleObj.ReceiptRequiredMethod == "Physically present or scanned copy")
                            {
                                titleObj.ReceiptRequiredMethod = "3";
                            }
                           
                            ViewBag.DefaultEmail = titleObj.RemindEmail;
                        }
                        //check object is null
                        else if(titleObj == null)
                        {
                            //return to login
                            return RedirectToAction("UserLogin", "Login");
                        }
                        //check ajax request
                        if (HttpContext.Request.IsAjaxRequest())
                        {
                            ViewBag.AjaxRequest = 1;
                            return PartialView(titleObj);
                        }
                        else
                        {

                            return View(titleObj);
                        }

                    }

                    else
                    {
                        ViewBag.Edit = 0;
                        //get auto remind email given in loan setup step 1
                        string defaultEmail = la.getAutoRemindEmailByLoanId(loanId);

                        ViewBag.Email = defaultEmail;
                       //check ajax request
                        if (HttpContext.Request.IsAjaxRequest())
                        {
                            ViewBag.AjaxRequest = 1;
                            return PartialView();
                        }
                        else
                        {

                            return View();
                        }

                    }
                   
                }
                //if loan id is 0 or less than 0
                else
                {
                    //return to login page
                    return RedirectToAction("UserLogin", "Login", new { lbl = "Due to inactivity your session has timed out, please log in again." });
                }
            }
            //if logged user id is 0 or less than 0
            else
            {
                //return to login page
                return RedirectToAction("UserLogin", "Login", new { lbl = "Due to inactivity your session has timed out, please log in again." });
            }

        }
        public ActionResult Step8()
        {

            var userId = userData.UserId;

            BranchAccess branch = new BranchAccess();
            //check user is user or dealer user
            if (userData.RoleId >= 3)
            {
                return RedirectToAction("UserLogin", "Login", new { lbl = "You are not Allowed." });
            }
            //get company type
            int companyType = branch.getCompanyTypeByUserId(userId);
            //check lender company
            if (companyType == 1)
            {
                ViewBag.isLender = true;
            }
            //check dealer company
            else
            {
                ViewBag.isLender = false;
            }
            Fees fee = new Fees();
            LoanSetupAccess loan = new LoanSetupAccess();
           
            fee.LoanId = loanData.loanId;
            //check insert or update
            if (loanData.stepId > 3)
            {
                ViewBag.isEdit = "editable";
                //get fee details
                var hasLoan = loan.checkLoanIsInFeesTables(fee.LoanId);
                //check advance amount
                if (hasLoan.AdvanceAmount == 0)
                {
                    hasLoan.AdvanceId = "2";
                }
                else {
                    hasLoan.AdvanceId = "1";
                }
                if (hasLoan.MonthlyLoanAmount == 0)
                {
                    hasLoan.MonthlyLoanId = "2";
                }
                else {
                    hasLoan.MonthlyLoanId = "1";
                }
                if (hasLoan.LotInspectionAmount == 0)
                {
                    hasLoan.LotInspectionId = "2";
                }
                else {
                    hasLoan.LotInspectionId = "1";
                }

                if (hasLoan.AdvanceAmount > 0 || hasLoan.MonthlyLoanAmount > 0 || hasLoan.LotInspectionAmount > 0)
                {
                    hasLoan.LoanId = fee.LoanId;
                    hasLoan.isEdit = true;
                    //hasLoan.IsAdvanceFeeCompleteEmailReminder = false;
                    //hasLoan.IsLoanFeeCompleteEmailReminder = false;
                    //hasLoan.IsLotFeeCompleteEmailReminder = false;
                    hasLoan.IsAdvanceFeeDueEmailReminder = false;
                    hasLoan.IsLoanFeeDueEmailReminder = false;
                    hasLoan.IsLotFeeDueEmailReminder = false;

                    //if (hasLoan.AdvanceFeeDealerEmail != "")
                    //{
                    //    hasLoan.IsAdvanceFeeCompleteEmailReminder = true;
                    //}
                    //if (hasLoan.MonthlyLoanFeeDealerEmail != "")
                    //{
                    //    hasLoan.IsLoanFeeCompleteEmailReminder = true;
                    //}
                    //if (hasLoan.LotInspectionFeeDealerEmail != "")
                    //{
                    //    hasLoan.IsLotFeeCompleteEmailReminder = true;
                    //}
                    if (hasLoan.AdvanceDueEmail != "")
                    {
                        hasLoan.IsAdvanceFeeDueEmailReminder = true;
                    }
                    if (hasLoan.MonthlyLoanDueEmail != "")
                    {
                        hasLoan.IsLoanFeeDueEmailReminder = true;
                    }
                    if (hasLoan.LotInspectionDueEmail != "")
                    {
                        hasLoan.IsLotFeeDueEmailReminder = true;
                    }
                }

                if (HttpContext.Request.IsAjaxRequest())
                {
                    ViewBag.AjaxRequest = 1;
                    return PartialView(hasLoan);
                }
                else
                {

                    return View(hasLoan);
                }
            }
            else
            {
                ViewBag.isEdit = "notEditable";

                Fees feeNew = new Fees();
                feeNew.LoanId = fee.LoanId;

                if (feeNew.LoanId > 0)
                {
                    feeNew.isEdit = false;
                    var email = loan.getAutoRemindEmailByLoanId(feeNew.LoanId);
                    if (email != null)
                    {
                        feeNew.AdvanceDueEmail = email;
                        feeNew.MonthlyLoanDueEmail = email;
                        feeNew.LotInspectionDueEmail = email;
                    }
                    //feeNew.IsAdvanceFeeCompleteEmailReminder = false;
                    //feeNew.IsLotFeeCompleteEmailReminder = false;
                    //feeNew.IsLoanFeeCompleteEmailReminder = false;
                    feeNew.IsAdvanceFeeDueEmailReminder = false;
                    feeNew.IsLotFeeDueEmailReminder = false;
                    feeNew.IsLoanFeeDueEmailReminder = false;

                    if (HttpContext.Request.IsAjaxRequest())
                    {
                        ViewBag.AjaxRequest = 1;
                        return PartialView(feeNew);
                    }
                    else
                    {

                        return View(feeNew);
                    }

                }
                else
                {
                    return RedirectToAction("Step7");
                }
            }

        }
        public ActionResult Step6_Post(LoanSetupStep1 loanSetupStep1)
        {
            int userId = userData.UserId;
          
            if (!CheckTheRangeOfPayOffPeriod(loanSetupStep1.autoReminderPeriod, loanSetupStep1.startDate, loanSetupStep1.maturityDate, 0))
            {

                return new HttpStatusCodeResult(404, "Auto reminder period is out of range");
            }

            if (!IsAtleastOneSelectUnitType(loanSetupStep1.allUnitTypes))
            {
                return new HttpStatusCodeResult(404, "Select Atleast One Unit Type");
            }

            // check he is super admin or admin
            if (userData.RoleId > 2)
            {
                return new HttpStatusCodeResult(404, "Not Allowed");
            }

            if ((Session["dashboard"] !=null))
            {
                loanData.stepId = 1;
            }
            // check if   step is 6...
            StepAccess sa = new StepAccess();
            if (loanData.stepId < 1)
            {
                return new HttpStatusCodeResult(404, "Not Allowed");
            }

            LoanSetupAccess loanSetupAccess = new LoanSetupAccess();

            LoanSetupAccess la = new LoanSetupAccess();
            int loanId = loanData.loanId;

            loanData.CompanyId = userData.Company_Id;

            
            Session["loanStep"] = loanData;

            if (loanId > 0)
            {
                loanId = loanSetupAccess.insertLoanStepOne(loanSetupStep1, loanId);
                if (loanId > 0)
                {
                    Log log = new Log(userData.UserId, userData.Company_Id, loanSetupStep1.RegisteredBranchId, loanId, "Loan Details", "Edited Loan : " + loanId, DateTime.Now);

                    int islog = (new LogAccess()).InsertLog(log);
                }
                else
                {
                    TempData["error"] = "error";
                    return RedirectToAction("step6");
                }
              
            }
            else
            {
                //loanId = la.getLoanIdByUserId(userId);


                loanId = loanSetupAccess.insertLoanStepOne(loanSetupStep1, loanId);
                if (loanId > 0)
                {
                    Log log = new Log(userData.UserId, userData.Company_Id, loanSetupStep1.RegisteredBranchId, loanId, "Loan Details", "Inserted Loan : " + loanId, DateTime.Now);

                    int islog = (new LogAccess()).InsertLog(log);
                }
                //need to update loanSetup object
                else
                {
                    TempData["error"] = "error";
                    return RedirectToAction("step6");
                }


            }
            if (loanId > 0)
            {
                if (loanSetupStep1.isInterestCalculate)
                {
                    
                    sa.UpdateLoanSetupStep(userData.UserId, loanData.CompanyId, loanSetupStep1.RegisteredBranchId, loanSetupStep1.nonRegisteredBranchId, loanId, 2);
                    if (loanData.stepId < 2)
                    {
                        loanData.stepId = 2;
                    }
                    //loanData.stepId = 2;
                }
                else
                {
                    sa.UpdateLoanSetupStep(userData.UserId,loanData.CompanyId, loanSetupStep1.RegisteredBranchId, loanSetupStep1.nonRegisteredBranchId, loanId, 3);
                    if (loanData.stepId < 3)
                    {
                        loanData.stepId = 3;
                    }
                }
                loanData.BranchId = loanSetupStep1.RegisteredBranchId;
                loanData.nonRegisteredBranchId = loanSetupStep1.nonRegisteredBranchId;
                loanData.loanId = loanId;
                
                Session["loanStep"] = loanData;
            }
            Session["loanStep"] = loanData;
            if (loanSetupStep1.isInterestCalculate)
            {
                return RedirectToAction("step7");
            }
            else
            {
                //sa.UpdateLoanSetupStep(loanData.CompanyId, loanData.BranchId, loanSetupStep1.nonRegisteredBranchId, loanId, 3);
                return RedirectToAction("step8");
            }






        }