public int PayFees(List<Fees> lstFee, string type)
        {
            int userId = userData.UserId;  // set the user id
            FeeAccess feeAccess = new FeeAccess();
            LoanSetupStep1 loanDetails = new LoanSetupStep1();
            loanDetails = (new LoanSetupAccess()).GetLoanDetailsByLoanCode(Session["loanCode"].ToString()); // take the loan details by loan code
            int returnValue = feeAccess.updateFees(lstFee, lstFee[0].PaidDate, loanDetails.loanId, userId); // update fee details

            //if successfully updated, insert to log 
            if (returnValue == 1)
            {
                Log log;

                // if fee type is advance -- save details to log as advance fee
                if (type == "advanceFee")
                {
                    List<string> IDNumbers = new List<string>();
                    foreach (var fee in lstFee)
                    {
                        IDNumbers.Add(fee.IdentificationNumber);
                    }
                    log = new Log(userData.UserId, userData.Company_Id, userData.BranchId, loanDetails.loanId, "Pay Fees", "Advance Fee Paid for the unit(s) : " + string.Join(",", IDNumbers) + " , Pay Date : " + lstFee[0].PaidDate.ToString("dd/MM/yyyy"), DateTime.Now);
                    (new LogAccess()).InsertLog(log);

                }

                // if fee type is monthly loan -- save details to log as monthly loan fee
                else if (type == "monthlyLoanFee")
                {
                    List<string> DueDates = new List<string>();
                    foreach (var fee in lstFee)
                    {
                        DueDates.Add(fee.DueDate);
                    }

                    log = new Log(userData.UserId, userData.Company_Id, userData.BranchId, loanDetails.loanId, "Pay Fees", " Monthly Loan Fee Paid for the due date(s) : { " + string.Join(",", DueDates) + "}" + ", Pay Date : " + lstFee[0].PaidDate.ToString("dd/MM/yyyy"), DateTime.Now);
                    (new LogAccess()).InsertLog(log);
                }

                // if fee type is lot inspection fee -- save details to log as lot inspection fee
                else if (type == "lotInspectionFee")
                {
                    List<string> DueDates = new List<string>();

                    foreach (var fee in lstFee)
                    {
                        DueDates.Add(fee.DueDate);
                    }

                    log = new Log(userData.UserId, userData.Company_Id, userData.BranchId, loanDetails.loanId, "Pay Fees", "Lot Inspection Fee Paid for the due date(s) : { " + string.Join(",", DueDates) + " } " + ", Pay Date : " + lstFee[0].PaidDate.ToString("dd/MM/yyyy"), DateTime.Now);
                    (new LogAccess()).InsertLog(log);

                }
            }

            // return the value to view
            return returnValue;
        }
        /*

          Frontend page: Fee Page
          Title: get fees by selected date
          Designed: Nadeeka
          User story:
          Developed: Nadeeka
          Date created: 4/21/2016

       */
        
        public ActionResult PayFeesForSelectedDueDate(DateTime dueDate, string type)
        {
                LoanSetupStep1 loanDetails = new LoanSetupStep1();
                loanDetails = (new LoanSetupAccess()).GetLoanDetailsByLoanCode(Session["loanCode"].ToString()); // take the loan detail of selected loan
                // pass the loan details to the view
                ViewBag.loanDetails = loanDetails;

                FeeAccess feeAccess = new FeeAccess();
                List<Fees> lstFee = feeAccess.GetFeesByDueDate(loanDetails.loanId, dueDate, type); // get fees list by duedate and type of fee
                FeesModel feeModel = new FeesModel();
                feeModel.FeeModelList = new List<Fees>();
                feeModel.Type = type;

                // if list exists, add to model and session for searching
                if (lstFee != null && lstFee.Count > 0)
                {
                    feeModel.FeeModelList.AddRange(lstFee);
                    Session["feeList"] = feeModel.FeeModelList;
                   
                }

               // return partial view of selected fee page
                return PartialView(feeModel);
                

                        
        }