/*

            Frontend page: Report Page
            Title: Load details to report and show on browser
            Designed: Kanishka SHM
            User story: 
            Developed: Kanishka SHM
            Date created: 

        */
        public void RenderReport(int loanId, int titleStatus, List<Unit> units)
        {
            //check authentication session is null, if null return
            if (Session["AuthenticatedUser"] == null) return;
            User userData = (User)Session["AuthenticatedUser"];

            //set report viewr property dynamically
            rptViewerTitleStatus.ProcessingMode=ProcessingMode.Local;
            rptViewerTitleStatus.Reset();
            rptViewerTitleStatus.LocalReport.EnableExternalImages = true;
            rptViewerTitleStatus.LocalReport.ReportPath = Server.MapPath("~/Reports/RptTitleStatus.rdlc");
            rptViewerTitleStatus.ZoomMode = ZoomMode.PageWidth;

            //get report header details
            ReportAccess ra = new ReportAccess();
            List<LoanDetailsRpt> details = ra.TopHeaderDetails(loanId, userData.UserId);

            foreach (var dates in details)
            {
                dates.ReportDate = DateTime.Now.ToString("MM/dd/yyyy");
            }

            //set data source to report viwer
            rptViewerTitleStatus.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", details));
            rptViewerTitleStatus.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", units));
        }
        /// <summary>
        /// Frontend Page: Report(monthly loan fee invoice)
        /// Title:load details of monthly loan fee invoice
        /// Deigned:Piyumi Perera
        /// User story:
        /// Developed:Piyumi Perera
        /// Date created: 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int loanId = 0;
                //assign fee type
                string feeType = "monthlyLoanFee";
                //check slected loan id is not empty and assign to variable
                if (Request.QueryString["loanId"] != "")
                    loanId = Convert.ToInt32(Request.QueryString["loanId"]);
                //check selected start date is not empty and assign to variable
                if (string.IsNullOrEmpty(Request.QueryString["startDate"])) return;
                var startDate = DateTime.ParseExact(Request.QueryString["startDate"], "MM/dd/yyyy", CultureInfo.InvariantCulture);
                //check selected end date is not empty and assign to variable
                if (string.IsNullOrEmpty(Request.QueryString["endDate"])) return;
                var endDate = DateTime.ParseExact(Request.QueryString["endDate"], "MM/dd/yyyy", CultureInfo.InvariantCulture);

                ReportAccess ra = new ReportAccess();
                //get monthly loan fee details which match with given date range
                List<RptFee> monthlyLoanFeeInvoice = ra.GetFeeInvoiceByDateRange(loanId, feeType, startDate, endDate);
                //check list count is>0
                if (monthlyLoanFeeInvoice.Count > 0)
                {
                    //load report
                    RenderReport(loanId, startDate, endDate, feeType, monthlyLoanFeeInvoice);
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowFrame", "ShowDive();", true);
                }
                else
                {
                    //show no data found message
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "HideFrame", "HideDive();", true);
                }
            }
        }
        /// <summary>
        /// Frontend Page: Report(lot inspection fee receipt)
        /// Title:load details of paid lot inspection fees
        /// Deigned:Piyumi Perera
        /// User story:
        /// Developed:Piyumi Perera
        /// Date created:
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int loanId = 0;
                //check selected loan id is not empty and assign to variable
                if (Request.QueryString["loanId"] != "")
                    loanId = Convert.ToInt32(Request.QueryString["loanId"]);
                //check selected start date is not empty and assign to variable
                if (string.IsNullOrEmpty(Request.QueryString["startDate"])) return;
                var startDate = DateTime.ParseExact(Request.QueryString["startDate"], "MM/dd/yyyy", new CultureInfo("en-US"));
                //check selected end date is not empty and assign to variable
                if (string.IsNullOrEmpty(Request.QueryString["endDate"])) return;
                var endDate = DateTime.ParseExact(Request.QueryString["endDate"], "MM/dd/yyyy", new CultureInfo("en-US"));

                ReportAccess ra = new ReportAccess();
                //get paid lot inspection fee details
                List<RptFee> lotInspectionFee = ra.GetFeeReceiptByDateRange(loanId, "lotInspectionFee", startDate, endDate);
                //check list count is >0
                if(lotInspectionFee.Count>0)
                {
                    //load report
                    RenderReport(loanId, startDate, endDate, lotInspectionFee);
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowFrame", "ShowDive();", true);
                }
                else
                {
                    //show no data found message
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "HideFrame", "HideDive();", true);
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int loanId = 0;

                if (Request.QueryString["loanId"] != "")
                    loanId = Convert.ToInt32(Request.QueryString["loanId"]);

                if (string.IsNullOrEmpty(Request.QueryString["startDate"])) return;
                var startDate = DateTime.ParseExact(Request.QueryString["startDate"], "MM/dd/yyyy", new CultureInfo("en-US"));

                if (string.IsNullOrEmpty(Request.QueryString["endDate"])) return;
                var endDate = DateTime.ParseExact(Request.QueryString["endDate"], "MM/dd/yyyy", new CultureInfo("en-US"));

                ReportAccess ra = new ReportAccess();
                List<ReportTransactionHistory> loanSumm = ra.GetTransactionHistoryByDateRange(loanId, startDate, endDate);

                if(loanSumm.Count>0)
                {
                    RenderReport(loanId, startDate, endDate, loanSumm);
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowFrame", "ShowDive();", true);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "HideFrame", "HideDive();", true);
                }
            }
        }
        /*

            Frontend page: Report Page
            Title: Load details to report and show on browser
            Designed: Kanishka SHM
            User story: 
            Developed: Kanishka SHM
            Date created: 

        */
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                int loanId = 0;
                

                if (Request.QueryString["loanId"] != "")
                    loanId = Convert.ToInt32(Request.QueryString["loanId"]);

                if (string.IsNullOrEmpty(Request.QueryString["startDate"])) return;
                var startDate = DateTime.ParseExact(Request.QueryString["startDate"], "MM/dd/yyyy", new CultureInfo("en-US"));

                if (string.IsNullOrEmpty(Request.QueryString["endDate"])) return;
                var endDate = DateTime.ParseExact(Request.QueryString["endDate"], "MM/dd/yyyy", new CultureInfo("en-US"));
                
                ReportAccess ra = new ReportAccess();
                //get unit payoff details
                List<ReportPayOff> payOffUnits = ra.GetPayOffDetailsByLoanId(loanId, startDate, endDate);

                if(payOffUnits.Count>0)
                {
                    RenderReport(loanId, startDate, endDate, payOffUnits);
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowFrame", "ShowDive();", true);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "HideFrame", "HideDive();", true);
                }
            }
        }
        /*

            Frontend page: Report Page
            Title: Load details to report and show on browser
            Designed: Kanishka SHM
            User story: 
            Developed: Kanishka SHM
            Date created: 

        */
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int loanId = 0;
                int titleStatus = 0;

                if (Request.QueryString["loanId"] != "")
                    loanId = Convert.ToInt32(Request.QueryString["loanId"]);

                if(!string.IsNullOrEmpty(Request.QueryString["titleStatus"]))
                    titleStatus = Convert.ToInt32(Request.QueryString["titleStatus"]);

                ReportAccess ra = new ReportAccess();
                //Get unit details by given title status
                List<Unit> units = ra.GeUnitDetailsByTitleStatus(loanId, titleStatus);

                if (units.Count > 0)
                {
                    RenderReport(loanId, titleStatus, units);
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowFrame", "ShowDive();", true);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "HideFrame", "HideDive();", true);
                }
            }
        }
        /*

            Frontend page: Report Page(Lot Inspection Report)
            Title: Display Lot Inspection Report
            Designed: Kanishka SHM
            User story:
            Developed: Kanishka SHM
            Date created: 

        */
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int loanId = 0;

                //get loan id from query string
                if (Request.QueryString["loanId"] != "")
                    loanId = Convert.ToInt32(Request.QueryString["loanId"]);

                ReportAccess ra = new ReportAccess();
                //get all active units
                List<ReportUnitModels> units = ra.GetAllActiveUnitDetailsRpt(loanId);

                //if result count is greater then zero show report, otherwise give a message 
                if (units.Count>0)
                {
                    //call RenderReport function to show report on report viwer
                    RenderReport(loanId, units);
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowFrame", "ShowDive();", true);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "HideFrame", "HideDive();", true);
                }
            }
        }
        /// <summary>
        /// Frontend Page: Report(lot inspection fee receipt)
        /// Title:load details of paid lot inspection fee 
        /// Deigned:Piyumi Perera
        /// User story:
        /// Developed:Piyumi Perera
        /// Date created: 
        /// </summary>
        /// <param name="loanId"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="lotInspectionFee"></param>
        public void RenderReport(int loanId, DateTime startDate, DateTime endDate, List<RptFee> lotInspectionFee)
        {
            //check authentication session is null, if null return
            if (Session["AuthenticatedUser"] == null) return;
            User userData = (User)Session["AuthenticatedUser"];

            rptViewerLotInspectionFeeReceipt.ProcessingMode = ProcessingMode.Local;
            rptViewerLotInspectionFeeReceipt.Reset();
            rptViewerLotInspectionFeeReceipt.LocalReport.EnableExternalImages = true;
            rptViewerLotInspectionFeeReceipt.LocalReport.ReportPath = Server.MapPath("~/Reports/RptLotInspectionFeeReceipt.rdlc");
            rptViewerLotInspectionFeeReceipt.ZoomMode = ZoomMode.PageWidth;

            ReportAccess ra = new ReportAccess();
            //get loan details of selected loan
            List<LoanDetailsRpt> details = ra.GetLoanDetailsRpt(loanId, userData.UserId);

            foreach (var dates in details)
            {
                //assign date fields values
                dates.StartRange = startDate.ToString("MM/dd/yyyy");
                dates.EndRange = endDate.ToString("MM/dd/yyyy");
                dates.ReportDate = DateTime.Now.ToString("MM/dd/yyyy");
            }
            //add data sources
            rptViewerLotInspectionFeeReceipt.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", details));
            rptViewerLotInspectionFeeReceipt.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", lotInspectionFee));
        }
        /*

        Frontend page   : Report page
        Title           : Display Delete units report
        Designed        : Kanishka SHM
        User story      : 
        Developed       : Kanishka SHM
        Date created    : 06/23/2016

        */
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int loanId = 0;

                //if session is not null and assign it.
                if (Request.QueryString["loanId"] != "")
                    loanId = Convert.ToInt32(Request.QueryString["loanId"]);

                if (string.IsNullOrEmpty(Request.QueryString["startDate"])) return;
                var startDate = DateTime.ParseExact(Request.QueryString["startDate"], "MM/dd/yyyy", CultureInfo.InvariantCulture);

                if (string.IsNullOrEmpty(Request.QueryString["endDate"])) return;
                var endDate = DateTime.ParseExact(Request.QueryString["endDate"], "MM/dd/yyyy", CultureInfo.InvariantCulture);

                ReportAccess ra = new ReportAccess();
                //Get all delete units details
                List<RptDeletedUnit> deletedUnits = ra.RptGetDeletedUnitByLoanIdDateRange(loanId, startDate, endDate);

                //if result count is greater then zero show report, otherwise give a message 
                if (deletedUnits.Count>0)
                { 
                    //call RenderReport function to show report on report viwer
                    RenderReport(loanId, startDate, endDate, deletedUnits);
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowFrame", "ShowDive();", true);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "HideFrame", "HideDive();", true);
                }
            }
        }
        /// <summary>
        /// Frontend Page: Report Page(Loan Summary Report)
        /// Title: Display Loan Summary Report
        /// Designed: Kasun Samarawickrama
        /// User story: 
        /// Developed: Kasun Samarawickrama
        /// Date created: 
        /// </summary>
        public void RenderReport(int loanId, DateTime startDate, DateTime endDate, List<RptLoanSummary> loanSummaryList)
        {
            //check authentication session is null, if null return
            if (Session["AuthenticatedUser"] == null) return;
            User userData = (User)Session["AuthenticatedUser"];

            //set report viewr property dynamically
            rptViewerLoanSummary.ProcessingMode = ProcessingMode.Local;
            rptViewerLoanSummary.Reset();
            rptViewerLoanSummary.LocalReport.EnableExternalImages = true;
            rptViewerLoanSummary.LocalReport.ReportPath = Server.MapPath("~/Reports/RptLoanSummary.rdlc");
            rptViewerLoanSummary.ZoomMode = ZoomMode.PageWidth;

            //Get account details
            ReportAccess ra = new ReportAccess();
            List<LoanDetailsRpt> details = ra.GetLoanDetailsRpt(loanId, userData.UserId);

            foreach (var dates in details)
            {
                dates.StartRange = startDate.ToString("MM/dd/yyyy");
                dates.EndRange = endDate.ToString("MM/dd/yyyy");
                dates.ReportDate = DateTime.Now.ToString("MM/dd/yyyy");
            }

            //set data source to report viwer
            rptViewerLoanSummary.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", details));
            rptViewerLoanSummary.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", loanSummaryList));
        }
        /// <summary>
        /// Frontend Page: Report Page(Curtailment Receipt Report)
        /// Title: Display Curtailment Receipt report
        /// Designed: Kanishka SHM
        /// User story: 
        /// Developed: Kanishka SHM
        /// Date created: 
        /// </summary>
        public void RenderReport(int loanId, DateTime startDate, DateTime endDate, List<CurtailmentShedule> curtailments)
        {
            //check authentication session is null, if null return
            if (Session["AuthenticatedUser"] == null) return;
            User userData = (User)Session["AuthenticatedUser"];

            //set report viewr property dynamically
            rptViewerCurtailmentReceipt.ProcessingMode=ProcessingMode.Local;
            rptViewerCurtailmentReceipt.Reset();
            rptViewerCurtailmentReceipt.LocalReport.EnableExternalImages = true;
            rptViewerCurtailmentReceipt.LocalReport.ReportPath = Server.MapPath("~/Reports/RptCurtailmentReceipt.rdlc");
            rptViewerCurtailmentReceipt.ZoomMode = ZoomMode.PageWidth;

            //get report header details
            ReportAccess ra = new ReportAccess();
            List<LoanDetailsRpt> details = ra.TopHeaderDetails(loanId, userData.UserId);

            //add dates, date range and current date
            foreach (var dates in details)
            {
                dates.StartRange = startDate.ToString("MM/dd/yyyy");
                dates.EndRange = endDate.ToString("MM/dd/yyyy");
                dates.ReportDate = DateTime.Now.ToString("MM/dd/yyyy");
            }

            //set data source to report viwer
            rptViewerCurtailmentReceipt.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", details));
            rptViewerCurtailmentReceipt.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", curtailments));
        }
        /// <summary>
        /// Frontend Page: Report page(Individual curtailment summary report)
        /// Title: Display Individual curtailment summary report
        /// Designed: Piyumi Perera
        /// User story: DFP 488
        /// Developed: Piyumi Perera
        /// Date created: 7/5/2016
        /// </summary>
        /// <param name="loanId"></param>
        public void RenderReport(int loanId, string idNumbe, List<RptIndividualCurtailmentSummary> indiCurtailment)
        {
            //Check authentication session is null then return
            if (Session["AuthenticatedUser"] == null) return;
            User userData = (User)Session["AuthenticatedUser"];

            //Dynamicaly set report viwer propertiece
            rptViewerIndividualCurtailmentSummary.ProcessingMode = ProcessingMode.Local;
            rptViewerIndividualCurtailmentSummary.Reset();
            rptViewerIndividualCurtailmentSummary.LocalReport.EnableExternalImages = true;
            rptViewerIndividualCurtailmentSummary.LocalReport.ReportPath = Server.MapPath("~/Reports/RptIndividualCurtailmentSummary.rdlc");
            rptViewerIndividualCurtailmentSummary.ZoomMode = ZoomMode.PageWidth;

            //Get details of loan
            ReportAccess ra = new ReportAccess();
            List<LoanDetailsRpt> details = ra.TopHeaderDetails(loanId, userData.UserId);
            foreach (var dates in details)
            {

                dates.ReportDate = DateTime.Now.ToString("MM/dd/yyyy");
            }

            //Set data set to report
            rptViewerIndividualCurtailmentSummary.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", details));

            //Set data set to report
            rptViewerIndividualCurtailmentSummary.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", indiCurtailment));
        }
        /// <summary>
        // Frontend Page: Report page(Branch Summary report)
        /// Title: Display Branch Summary report
        /// Designed: Piyumi Perera
        /// User story: 
        /// Developed: Piyumi Perera
        /// Date created: 
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int branchId = 0;
                string branchName = "";

                //if session is not null and assign it.
                if (Request.QueryString["branchId"] != "")
                    branchId = Convert.ToInt32(Request.QueryString["branchId"]);
                if (Request.QueryString["branchName"] != "")
                    branchName = Request.QueryString["branchName"];

                //Get branch summary details
                ReportAccess ra = new ReportAccess();
                List<RptBranchSummary> branchSummary = ra.GetBranchSummarRptDetails(branchId);

                //if result count is greater then zero show report, otherwise give a message
                if (branchSummary.Count > 0)
                {
                    //call RenderReport function to show report on report viwer
                    RenderReport(branchId, branchName, branchSummary);
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowFrame", "ShowDive();", true);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "HideFrame", "HideDive();", true);
                }
            }
        }
        /// <summary>
        /// Frontend Page: Report page(Advance Fee Receipt Report)
        /// Title: Display Advance Fee Receipt
        /// Designed: Kasun Samarawickrama
        /// User story: 
        /// Developed: Kasun Samarawickrama
        /// Date created: 
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int loanId = 0;

                //if session is not null and assign it.
                if (Request.QueryString["loanId"] != "")
                    loanId = Convert.ToInt32(Request.QueryString["loanId"]);

                if (string.IsNullOrEmpty(Request.QueryString["startDate"])) return;
                var startDate = DateTime.ParseExact(Request.QueryString["startDate"], "MM/dd/yyyy", new CultureInfo("en-US"));

                if (string.IsNullOrEmpty(Request.QueryString["endDate"])) return;
                var endDate = DateTime.ParseExact(Request.QueryString["endDate"], "MM/dd/yyyy", new CultureInfo("en-US"));

                //Get Advance Fee receipt during time period
                ReportAccess ra = new ReportAccess();
                List<RptFee> advanceFeeReceipt = ra.GetFeeReceiptByDateRange(loanId, "advanceFee", startDate, endDate);

                //if result count is greater then zero show report, otherwise give a message
                if (advanceFeeReceipt.Count > 0)
                {
                    //call RenderReport function to show report on report viwer
                    RenderReport(loanId, startDate, endDate, advanceFeeReceipt);
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowFrame", "ShowDive();", true);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "HideFrame", "HideDive();", true);
                }
            }


        }
        /// <summary>
        /// Frontend Page: Report page(Advance Fee Receipt Report)
        /// Title: Display Advance Fee Receipt
        /// Designed: Kasun Samarawickrama
        /// User story: 
        /// Developed: Kasun Samarawickrama
        /// Date created: 
        /// </summary>
        public void RenderReport(int loanId, DateTime startDate, DateTime endDate, List<RptFee> advanceFeeReceipt)
        {
            //Check authentication session is null then return
            if (Session["AuthenticatedUser"] == null) return;
            User userData = (User)Session["AuthenticatedUser"];

            rptViewerAdvanceFeeReceipt.ProcessingMode = ProcessingMode.Local;
            rptViewerAdvanceFeeReceipt.Reset();
            rptViewerAdvanceFeeReceipt.LocalReport.EnableExternalImages = true;
            rptViewerAdvanceFeeReceipt.LocalReport.ReportPath = Server.MapPath("~/Reports/RptAdvanceFeeReceipt.rdlc");
            rptViewerAdvanceFeeReceipt.ZoomMode = ZoomMode.PageWidth;

            //Get account details
            ReportAccess ra = new ReportAccess();
            List<LoanDetailsRpt> details = ra.TopHeaderDetails(loanId, userData.UserId);

            foreach (var dates in details)
            {
                dates.StartRange = startDate.ToString("MM/dd/yyyy");
                dates.EndRange = endDate.ToString("MM/dd/yyyy");
                dates.ReportDate = DateTime.Now.ToString("MM/dd/yyyy");
            }

            //Set data set to report
            rptViewerAdvanceFeeReceipt.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", details));
            rptViewerAdvanceFeeReceipt.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", advanceFeeReceipt));
        }
        /// <summary>
        /// Frontend Page: Report page(Individual curtailment summary report)
        /// Title: Display Individual curtailment summary report
        /// Designed: Piyumi Perera
        /// User story: DFP 488
        /// Developed: Piyumi Perera
        /// Date created: 7/5/2016
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int loanId = 0;
                string idNumber = "";
                //if session is not null and assign it.
                if (Request.QueryString["loanId"] != "")
                    loanId = Convert.ToInt32(Request.QueryString["loanId"]);

                if (Request.QueryString["idNumber"] != "" && Request.QueryString["idNumber"] != null)
                    idNumber = Request.QueryString["idNumber"];

                ReportAccess ra = new ReportAccess();
                //Get all curtailment summary details
                List<RptIndividualCurtailmentSummary> indiCurtailment = ra.GetIndividualCurtailmentSummarRptDetails(loanId, idNumber);

                if (indiCurtailment.Count > 0)
                {
                    //call RenderReport function to show report on report viwer
                    RenderReport(loanId, idNumber, indiCurtailment);
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowFrame", "ShowDive();", true);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "HideFrame", "HideDive();", true);
                }
            }
        }
        /// <summary>
        /// Frontend Page: Advance Unit Page(Advance Unit Report)
        /// Title: Display Advance Units during session
        /// Designed: Kanishka SHM
        /// User story: 
        /// Developed: Kanishka SHM
        /// Date created: 
        /// </summary>
        public void RenderReport(int loanId)
        {
            //Check authentication session is null then return
            if (Session["AuthenticatedUser"] == null) return;
            User userData = (User)Session["AuthenticatedUser"];

            //set reportviewr properties
            rptViewerAdvanceUnit.ProcessingMode = ProcessingMode.Local;
            rptViewerAdvanceUnit.Reset();
            rptViewerAdvanceUnit.LocalReport.EnableExternalImages = true;
            rptViewerAdvanceUnit.LocalReport.ReportPath = Server.MapPath("~/Reports/RptAdvanceUnit.rdlc");
            rptViewerAdvanceUnit.ZoomMode = ZoomMode.PageWidth;
            List<Unit> units = (List<Unit>)Session["AdvItems"];

            //Get account details
            ReportAccess ra = new ReportAccess();
            List<LoanDetailsRpt> details = ra.TopHeaderDetails(loanId, userData.UserId);

            foreach (var dates in details)
            {
                dates.ReportDate = DateTime.Now.ToString("MM/dd/yyyy");
            }

            //Set data set to report
            rptViewerAdvanceUnit.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", details));

            //if unit count is not null and count is greater than 0, create xml string
            if (units != null && units.Count > 0)
            {
                try
                {
                    //create xml string
                    XElement xEle = new XElement("Units",
                    from unit in units
                    select new XElement("Unit",
                        new XElement("UnitId", unit.UnitId)
                        ));
                    string xmlDoc = xEle.ToString();
                    
                    //get all advance unit during session
                    var advanceUnits = ra.AdvanceUnitsDuringSession(xmlDoc);

                    //Set data set to report
                    rptViewerAdvanceUnit.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", advanceUnits));
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            else
            {
                units = new List<Unit>();
            }
        }
        /// <summary>
        /// Frontend Page: Pay Curtailment Page(Curtailment Receipt Report)
        /// Title: Display Curtailment Receipt report during session
        /// Designed: Kanishka SHM
        /// User story: 
        /// Developed: Kanishka SHM
        /// Date created: 
        /// </summary>
        public void RenderReport(int loanId)
        {
            //Check authentication session is null then return
            if (Session["AuthenticatedUser"] == null) return;
            User userData = (User)Session["AuthenticatedUser"];

            //set reportviewr properties
            rptViewerCurtailmentReceiptDuringSession.ProcessingMode = ProcessingMode.Local;
            rptViewerCurtailmentReceiptDuringSession.Reset();
            rptViewerCurtailmentReceiptDuringSession.LocalReport.EnableExternalImages = true;
            rptViewerCurtailmentReceiptDuringSession.LocalReport.ReportPath = Server.MapPath("~/Reports/RptCurtailmentDuringSession.rdlc");
            rptViewerCurtailmentReceiptDuringSession.ZoomMode = ZoomMode.PageWidth;

            //Get account details
            ReportAccess ra = new ReportAccess();
            List<LoanDetailsRpt> details = ra.TopHeaderDetails(loanId, userData.UserId);

            foreach (var dates in details)
            {
                dates.ReportDate = DateTime.Now.ToString("MM/dd/yyyy");
            }

            //Set data set to report
            rptViewerCurtailmentReceiptDuringSession.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", details));

            //get unit list from session
            List<CurtailmentShedule> selectedCurtailmentSchedules =
                (List<CurtailmentShedule>) Session["CurtUnitDuringSession"];

            //assign unit ids
            List<string> uniList = (from item in selectedCurtailmentSchedules
                                    select item.UnitId).Distinct().ToList();

            //create xml string
            XElement xEle = new XElement("Curtailments",
                    from id in uniList
                    select new XElement("Unit",
                        new XElement("UnitId", id)
                        ));
            string xmlDoc = xEle.ToString();

            //get unit curatilment details during session
            List<CurtailmentShedule> unitWithAdvanceAmount = ra.GetCurtailmentPaidDetailsDuringSession(xmlDoc);

            foreach (var item in selectedCurtailmentSchedules)
            {
                item.PurchasePrice = unitWithAdvanceAmount.First(x => x.UnitId == item.UnitId).PurchasePrice;
            }

            if (selectedCurtailmentSchedules != null && selectedCurtailmentSchedules.Count > 0)
            {
                //Set data set to report
                rptViewerCurtailmentReceiptDuringSession.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", selectedCurtailmentSchedules));
            }
        }
        public void RenderReport(int loanId)
        {
            //check authentication session is null, if null return
            if (Session["AuthenticatedUser"] == null) return;
            User userData = (User)Session["AuthenticatedUser"];

            //set reportviewr properties
            rptViewerLoanTerms.ProcessingMode = ProcessingMode.Local;
            rptViewerLoanTerms.Reset();
            rptViewerLoanTerms.LocalReport.EnableExternalImages = true;
            rptViewerLoanTerms.LocalReport.ReportPath = Server.MapPath("~/Reports/RptLoanTerms.rdlc");
            rptViewerLoanTerms.ZoomMode = ZoomMode.PageWidth;

            ReportAccess ra = new ReportAccess();

            //Get loan details and set to reportviwer
            List<RptLoanTerms> loanTermsDetails = ra.RptLoanTermsDetails(loanId);
            rptViewerLoanTerms.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", loanTermsDetails));

            List<LoanDetailsRpt> details = ra.GetLoanDetailsRptforCompanySummary(userData.Company_Id, userData.UserId);
            rptViewerLoanTerms.LocalReport.DataSources.Add(new ReportDataSource("DataSet6", details));

            //get curtailment schedule details and set to reportviwer
            CurtailmentAccess ca = new CurtailmentAccess();
            List<Curtailment> curtailments = ca.retreiveCurtailmentByLoanId(loanId);

            if (curtailments != null && curtailments.Count > 0)
            {
                for (int i = 0; i < curtailments.Count; i++)
                {
                    curtailments[i].CurtailmentId = i + 1;
                }
            }
            rptViewerLoanTerms.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", curtailments));

            //get fees details and set to reportviwer
            List<RptFeeLoanTerm> loanTermsFeeDetails = ra.RptLoanTermsFeeDetails(loanId);
            rptViewerLoanTerms.LocalReport.DataSources.Add(new ReportDataSource("DataSet3", loanTermsFeeDetails));

            //get reminders details and set to reportviwer
            List<RptEmailReminder> loanTermsEmailReminders = ra.RptLoanTermsEmailReminders(loanId);
            rptViewerLoanTerms.LocalReport.DataSources.Add(new ReportDataSource("DataSet4", loanTermsEmailReminders));

            //get unit types and set  to reportviwer
            IList<UnitType> unitTypes = ra.RptGetUnitTypes(loanId);
            rptViewerLoanTerms.LocalReport.DataSources.Add(new ReportDataSource("DataSet5", unitTypes));
        }
        /// <summary>
        // Frontend Page: Report page(Branch Summary report)
        /// Title: Display Branch Summary report
        /// Designed: Piyumi Perera
        /// User story: 
        /// Developed: Piyumi Perera
        /// Date created: 
        /// </summary>
        public void RenderReport(int branchId,string branchName, List<RptBranchSummary> branchSummary)
        {
            //check authentication session is null, if null return
            if (Session["AuthenticatedUser"] == null) return;
            User userData = (User)Session["AuthenticatedUser"];

            //set reportviewr properties
            rptViewerBranchSummary.ProcessingMode = ProcessingMode.Local;
            rptViewerBranchSummary.Reset();
            rptViewerBranchSummary.LocalReport.EnableExternalImages = true;
            rptViewerBranchSummary.LocalReport.ReportPath = Server.MapPath("~/Reports/RptBranchSummary.rdlc");
            rptViewerBranchSummary.ZoomMode = ZoomMode.PageWidth;

            ReportAccess ra = new ReportAccess();
            User usr = new User();
            usr = (new UserAccess()).retreiveUserByUserId(userData.UserId);
            List<LoanDetailsRpt> details = new List<LoanDetailsRpt>();
            LoanDetailsRpt detail = new LoanDetailsRpt();
            detail.CompanyName = userData.CompanyName;
            if (userData.RoleId == 1)
            {
                detail.LenderBrnchName = branchName;
            }
            else
            {
                detail.LenderBrnchName = userData.BranchName;
            }
            
            detail.ReportDate = DateTime.Now.ToString("MM/dd/yyyy");
            detail.CreaterName = usr.FirstName + " " + usr.LastName;
            details.Add(detail);
            rptViewerBranchSummary.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", details));

            foreach (var dates in details)
            {
                dates.ReportDate = DateTime.Now.ToString("MM/dd/yyyy");
            }
            
            rptViewerBranchSummary.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", branchSummary));
        }
        /// <summary>
        /// Frontend Page: Report Page(Company Summary Report)
        /// Title: Display Company Summary details
        /// Designed: Kanishka SHM
        /// User story: 
        /// Developed: Kanishka SHM
        /// Date created: 
        /// </summary>
        public void RenderReport(int companyId)
        {
            //check authentication session is null, if null return
            if (Session["AuthenticatedUser"] == null) return;
            User userData = (User)Session["AuthenticatedUser"];

            //set report viewr property dynamically
            rptViewerCompanySummary.ProcessingMode = ProcessingMode.Local;
            rptViewerCompanySummary.Reset();
            rptViewerCompanySummary.LocalReport.EnableExternalImages = true;
            rptViewerCompanySummary.LocalReport.ReportPath = Server.MapPath("~/Reports/RptCompanySummary.rdlc");
            rptViewerCompanySummary.ZoomMode = ZoomMode.PageWidth;

            //get report header details
            ReportAccess ra = new ReportAccess();
            List<RptCompanySummary> loanSumaList = ra.RptGetCompanySummary(companyId);

            //set data source to report viwer - 1
            rptViewerCompanySummary.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", loanSumaList));

            List<LoanDetailsRpt> details = ra.GetLoanDetailsRptforCompanySummary(userData.Company_Id, userData.UserId);
            //set data source to report viwer - 2
            rptViewerCompanySummary.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", details));
        }
        /*

            Frontend page: Report Page
            Title: Lot Inspection Report print page
            Designed: Kanishka SHM
            User story: 
            Developed: Kanishka SHM
            Date created: 

        */
        public ReportViewer PrintPage(int loanId)
        {
            //check authentication session is null, if null return
            if (Session["AuthenticatedUser"] == null) return null;
            User userData = (User)Session["AuthenticatedUser"];

            //set report viewr property dynamically
            ReportViewer rptViewerLotInspectionPrint = new ReportViewer();
            rptViewerLotInspectionPrint.ProcessingMode = ProcessingMode.Local;
            rptViewerLotInspectionPrint.Reset();
            rptViewerLotInspectionPrint.LocalReport.EnableExternalImages = true;
            rptViewerLotInspectionPrint.LocalReport.ReportPath = Server.MapPath("~/Reports/RptLotInspection.rdlc");

            //get report header details
            ReportAccess ra = new ReportAccess();
            List<LoanDetailsRpt> details = ra.TopHeaderDetails(loanId, userData.UserId);

            //add current date
            foreach (var dates in details)
            {
                dates.ReportDate = DateTime.Now.ToString("MM/dd/yyyy");
            }

            //set data source to report viwer - 1
            rptViewerLotInspectionPrint.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", details));

            //get all active units
            List<ReportUnitModels> units = ra.GetAllActiveUnitDetailsRpt(loanId);

            foreach (var unit in units)
            {
                unit.View = false;
            }

            //set data source to report viwer - 2
            rptViewerLotInspectionPrint.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", units));

            //return report viwer
            return rptViewerLotInspectionPrint;
        }
        /*

            Frontend page: Report Page
            Title: Load details to report and show on browser
            Designed: Kanishka SHM
            User story: 
            Developed: Kanishka SHM
            Date created: 

        */
        public ReportViewer PrintPage(int loanId, DateTime startDate, DateTime endDate)
        {
            //check authentication session is null, if null return
            if (Session["AuthenticatedUser"] == null) return null;
            User userData = (User)Session["AuthenticatedUser"];

            //set report viewr property dynamically
            ReportViewer rptViewerPayOffPrint = new ReportViewer();
            rptViewerPayOffPrint.ProcessingMode = ProcessingMode.Local;
            rptViewerPayOffPrint.Reset();
            rptViewerPayOffPrint.LocalReport.EnableExternalImages = true;
            rptViewerPayOffPrint.LocalReport.ReportPath = Server.MapPath("~/Reports/RptPayOff.rdlc");

            //get report header details
            ReportAccess ra = new ReportAccess();
            List<LoanDetailsRpt> details = ra.TopHeaderDetails(loanId, userData.UserId);

            //add dates, date range and current date
            foreach (var dates in details)
            {
                dates.StartRange = startDate.ToString("MM/dd/yyyy");
                dates.EndRange = endDate.ToString("MM/dd/yyyy");
                dates.ReportDate = DateTime.Now.ToString("MM/dd/yyyy");
            }

            //get unit payoff details
            List<ReportPayOff> curtailments = ra.GetPayOffDetailsByLoanId(loanId, startDate, endDate);

            //set data source to report viwer
            rptViewerPayOffPrint.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", details));
            rptViewerPayOffPrint.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", curtailments));

            //return report viwer
            return rptViewerPayOffPrint;
        }
        /*

        Frontend page: Report page
        Title: Get active loans of user for grid
        Designed: Irfan MAM
        User story: DFP- 446
        Developed: Irfan MAM
        Date created: 06/23/2016

*/

            public JsonResult GetActiveLoans(string sidx, string sord, int page, int rows, bool _search)
        {
            ReportAccess ra = new ReportAccess();

            List<Account> loanNumbers;

            // if user is a superadmin, get account details of his company
            if (_userData.RoleId == 1) {
                 loanNumbers = ra.GetAccountDetails(_userData.Company_Id, _userData.RoleId);

            }

            // if user is a admin, get account details of his branch
            else if (_userData.RoleId == 2)
            {
                loanNumbers = ra.GetAccountDetails(_userData.BranchId, _userData.RoleId);
            }
            // if user is a user or dealer user, get account details of his assigned loans
            else if(_userData.RoleId == 3 || _userData.RoleId == 4)
            {
                
                loanNumbers = ra.GetAccountDetailsForUser(_userData.UserId);

                // if selected dashboard loan has no rights delete the session
            }
            else
            {
                loanNumbers = new List<Account>();
            }

            // these varibles are for JqGrid purpose

            int count = loanNumbers.Count(); // number of rows
            int pageIndex = page; // number of pages on the grid
            int pageSize = rows; // maximum page sige
            int startRow = (pageIndex * pageSize) + 1;
            int totalRecords = count;
            int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
           
            // for super admin or admin, we use different json object
            if (_userData.RoleId == 1 || _userData.RoleId == 2) {
                // json object for jqGrid
                var result = new
            {
                total = totalPages,
                page = pageIndex,
                records = count,
                rows = loanNumbers.Select(x => new
                {
                    x.LoanId,
                    x.LoanCode,
                    x.BranchName,
                    x.PatBranchName,
                    x.LoanNumber,
                   
                    x.LoanAmount,
                   
                   
                    x.UsedAmount,
                    x.ActiveUnits,
                    x.PatBranchAddress1,
                    x.PatBranchAddress2,
                    x.PatCity
                }
                                         ).ToArray().Select(x => new
                                         {
                                             id = x.LoanId.ToString(),
                                             cell = new string[] { 
                                                        x.LoanCode,
                                                        x.BranchName,
                                                        x.PatBranchName,
                                                        x.LoanNumber.ToString(),
                                                        x.LoanAmount.ToString(),
                                                        x.UsedAmount.ToString(),
                                                        x.ActiveUnits.ToString(),
                                                        x.PatBranchAddress1,
                                                        x.PatBranchAddress2,
                                                        x.PatCity
                                                      }
                                         }
                      ).ToArray()

               

            };

                // returning json object
                return Json(result, JsonRequestBehavior.AllowGet);

            }
             // for others (user/ dealer user) , we use differnt json object
            else
            {
                // json object for jqGrid
                var result = new
                {
                    total = totalPages,
                    page = pageIndex,
                    records = count,
                    rows = loanNumbers.Select(x => new
                    {
                        x.LoanId,
                        x.LoanCode,
                        x.PatBranchName,
                        x.LoanNumber,
                        x.LoanAmount,
                        x.UsedAmount,
                        x.ActiveUnits,
                        x.PatBranchAddress1,
                        x.PatBranchAddress2,
                        x.PatCity,
                        x.userReportRights
                    }
                                             ).ToArray().Select(x => new
                                             {
                                                 id = x.LoanId.ToString(),
                                                 cell = new string[] {
                                                        x.LoanCode,
                                                        x.PatBranchName,
                                                        x.LoanNumber.ToString(),
                                                        x.LoanAmount.ToString(),
                                                        x.UsedAmount.ToString(),
                                                        x.ActiveUnits.ToString(),
                                                        x.PatBranchAddress1,
                                                        x.PatBranchAddress2,
                                                        x.PatCity,
                                                        x.userReportRights
                                                          }
                                             }
                          ).ToArray()



                };

                // returning json object
                return Json(result, JsonRequestBehavior.AllowGet);

            }


           

        }
        /// <summary>
        /// Frontend Page: Add Unit(Add Unit Report)
        /// Title: Display Advance Units print page
        /// Designed: Kanishka SHM
        /// User story: 
        /// Developed: Kanishka SHM
        /// Date created: 
        /// </summary>
        public ReportViewer PrintPage(int loanId, int userId)
        {
            //Check authentication session is null then return
            if (Session["AuthenticatedUser"] == null) return null;
            User userData = (User)Session["AuthenticatedUser"];

            ReportViewer rptViewerAddUnitPrint = new ReportViewer();

            rptViewerAddUnitPrint.ProcessingMode = ProcessingMode.Local;
            rptViewerAddUnitPrint.Reset();
            rptViewerAddUnitPrint.LocalReport.EnableExternalImages = true;
            rptViewerAddUnitPrint.LocalReport.ReportPath = Server.MapPath("~/Reports/RptAddUnit.rdlc");
            rptViewerAddUnitPrint.ZoomMode = ZoomMode.PageWidth;

            //Get account details
            ReportAccess ra = new ReportAccess();
            List<LoanDetailsRpt> details = ra.TopHeaderDetails(loanId, userData.UserId);

            foreach (var dates in details)
            {
                dates.ReportDate = DateTime.Now.ToString("MM/dd/yyyy");
            }

            //Set data set to report
            rptViewerAddUnitPrint.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", details));

            //
            List<RptAddUnit> units = ra.GetJustAddedUnitDetails(userId, loanId);

            //Set data set to report
            rptViewerAddUnitPrint.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", units));

            //return reportviwer
            return rptViewerAddUnitPrint;
        }
        /// <summary>
        /// Frontend Page: Report(lot inspection fee invoice)
        /// Title:print lot inspection fee invoice report
        /// Deigned:Piyumi Perera
        /// User story:
        /// Developed:Piyumi Perera
        /// Date created: 
        /// </summary>
        /// <param name="loanId"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns></returns>
        public ReportViewer PrintPage(int loanId, DateTime startDate, DateTime endDate)
        {
            //check authentication session is null, if null return
            if (Session["AuthenticatedUser"] == null) return null;
            User userData = (User)Session["AuthenticatedUser"];

            ReportViewer rptViewerLotInspectionFeeInvoicePrint = new ReportViewer();
            rptViewerLotInspectionFeeInvoicePrint.ProcessingMode = ProcessingMode.Local;
            rptViewerLotInspectionFeeInvoicePrint.Reset();
            rptViewerLotInspectionFeeInvoicePrint.LocalReport.EnableExternalImages = true;
            rptViewerLotInspectionFeeInvoicePrint.LocalReport.ReportPath = Server.MapPath("~/Reports/RptLotInspectionFeeInvoice.rdlc");

            ReportAccess ra = new ReportAccess();
            //get loan details of selected loan
            List<LoanDetailsRpt> details = ra.GetLoanDetailsRpt(loanId, userData.UserId);

            foreach (var dates in details)
            {
                //assign date fields
                dates.StartRange = startDate.ToString("MM/dd/yyyy");
                dates.EndRange = endDate.ToString("MM/dd/yyyy");
                dates.ReportDate = DateTime.Now.ToString("MM/dd/yyyy");
            }

            //get lot inspection fee details which match with the given date range
            List<RptFee> lotInspectionFeeInvoice = ra.GetFeeInvoiceByDateRange(loanId, "lotInspectionFee", startDate, endDate);
            //add data sources
            rptViewerLotInspectionFeeInvoicePrint.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", details));
            rptViewerLotInspectionFeeInvoicePrint.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", lotInspectionFeeInvoice));

            
            return rptViewerLotInspectionFeeInvoicePrint;
        }
        /*

            Frontend page: Report Page
            Title: Load pdf view on browser
            Designed: Kanishka SHM
            User story: 
            Developed: Kanishka SHM
            Date created: 

        */
        public ReportViewer PrintPage(int loanId)
        {
            //check authentication session is null, if null return
            if (Session["AuthenticatedUser"] == null) return null;
            User userData = (User)Session["AuthenticatedUser"];

            //set report viewr property dynamically
            ReportViewer rptViewerFullInventoryPrint = new ReportViewer();
            rptViewerFullInventoryPrint.ProcessingMode = ProcessingMode.Local;
            rptViewerFullInventoryPrint.Reset();
            rptViewerFullInventoryPrint.LocalReport.EnableExternalImages = true;
            rptViewerFullInventoryPrint.LocalReport.ReportPath = Server.MapPath("~/Reports/RptFullInventory.rdlc");

            //get report header details
            ReportAccess ra = new ReportAccess();
            List<LoanDetailsRpt> details = ra.TopHeaderDetails(loanId, userData.UserId);

            foreach (var dates in details)
            {
                dates.ReportDate = DateTime.Now.ToString("MM/dd/yyyy");
            }

            //Get unit details with payment details
            List<ReportFullInventoryUnit> units = ra.GetFullInventoryByLoanId(loanId);

            //set data source to report viwer
            rptViewerFullInventoryPrint.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", details));
            rptViewerFullInventoryPrint.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", units));
            
            //return report view
            return rptViewerFullInventoryPrint;
        }
        public ReportViewer PrintPage(int loanId, string idNumber)
        {
            //Check authentication session is null then return
            if (Session["AuthenticatedUser"] == null) return null;
            User userData = (User)Session["AuthenticatedUser"];

            ReportViewer rptViewerIndividualCurtailmentSummaryPrint = new ReportViewer();

            rptViewerIndividualCurtailmentSummaryPrint.ProcessingMode = ProcessingMode.Local;
            rptViewerIndividualCurtailmentSummaryPrint.Reset();
            rptViewerIndividualCurtailmentSummaryPrint.LocalReport.EnableExternalImages = true;
            rptViewerIndividualCurtailmentSummaryPrint.LocalReport.ReportPath = Server.MapPath("~/Reports/RptIndividualCurtailmentSummary.rdlc");
            rptViewerIndividualCurtailmentSummaryPrint.ZoomMode = ZoomMode.PageWidth;

            ReportAccess ra = new ReportAccess();
            List<LoanDetailsRpt> details = ra.TopHeaderDetails(loanId, userData.UserId);
            foreach (var dates in details)
            {

                dates.ReportDate = DateTime.Now.ToString("MM/dd/yyyy");
            }

            rptViewerIndividualCurtailmentSummaryPrint.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", details));

            //Get all curtailment summary details
            List<RptIndividualCurtailmentSummary> indiCurtailment = ra.GetIndividualCurtailmentSummarRptDetails(loanId, idNumber);
            rptViewerIndividualCurtailmentSummaryPrint.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", indiCurtailment));

            return rptViewerIndividualCurtailmentSummaryPrint;
        }
        /*

        Frontend page   : Report page
        Title           : Display Delete units report print page
        Designed        : Kanishka SHM
        User story      : 
        Developed       : Kanishka SHM
        Date created    : 06/23/2016

        */
        public ReportViewer PrintPage(int loanId, DateTime startDate, DateTime endDate)
        {
            //Check authentication session is null then return
            if (Session["AuthenticatedUser"] == null) return null;
            User userData = (User)Session["AuthenticatedUser"];

            //create reportviwer & set reportviewr properties
            ReportViewer rptViewerDeletedUnitsPrint = new ReportViewer();
            rptViewerDeletedUnitsPrint.ProcessingMode = ProcessingMode.Local;
            rptViewerDeletedUnitsPrint.Reset();
            rptViewerDeletedUnitsPrint.LocalReport.EnableExternalImages = true;
            rptViewerDeletedUnitsPrint.LocalReport.ReportPath = Server.MapPath("~/Reports/RptDeletedUnits.rdlc");
            rptViewerDeletedUnitsPrint.ZoomMode = ZoomMode.PageWidth;

            //Get details of loan
            ReportAccess ra = new ReportAccess();
            List<LoanDetailsRpt> details = ra.TopHeaderDetails(loanId, userData.UserId);

            foreach (var dates in details)
            {
                dates.StartRange = startDate.ToString("MM/dd/yyyy");
                dates.EndRange = endDate.ToString("MM/dd/yyyy");
                dates.ReportDate = DateTime.Now.ToString("MM/dd/yyyy");
            }

            //set data set to report
            rptViewerDeletedUnitsPrint.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", details));

            //Get all delete units details and set data set to report
            List<RptDeletedUnit> deletedUnits = ra.RptGetDeletedUnitByLoanIdDateRange(loanId, startDate, endDate);
            rptViewerDeletedUnitsPrint.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", deletedUnits));

            //return report viwer
            return rptViewerDeletedUnitsPrint;
        }
        public ReportViewer PrintPage(int loanId, DateTime startDate, DateTime endDate)
        {
            //check authentication session is null, if null return
            if (Session["AuthenticatedUser"] == null) return null;
            User userData = (User)Session["AuthenticatedUser"];

            //set report viewr property dynamically
            ReportViewer rptViewerLoanSummaryPrint = new ReportViewer();
            rptViewerLoanSummaryPrint.ProcessingMode = ProcessingMode.Local;
            rptViewerLoanSummaryPrint.Reset();
            rptViewerLoanSummaryPrint.LocalReport.EnableExternalImages = true;
            rptViewerLoanSummaryPrint.LocalReport.ReportPath = Server.MapPath("~/Reports/RptTransactionHistory.rdlc");

            //get report header details
            ReportAccess ra = new ReportAccess();
            List<LoanDetailsRpt> details = ra.TopHeaderDetails(loanId, userData.UserId);

            foreach (var dates in details)
            {
                dates.StartRange = startDate.ToString("MM/dd/yyyy");
                dates.EndRange = endDate.ToString("MM/dd/yyyy");
                dates.ReportDate = DateTime.Now.ToString("MM/dd/yyyy");
            }


            List<ReportTransactionHistory> loanSumm = ra.GetTransactionHistoryByDateRange(loanId, startDate, endDate);

            rptViewerLoanSummaryPrint.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", details));
            rptViewerLoanSummaryPrint.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", loanSumm));

            return rptViewerLoanSummaryPrint;
        }