/// <summary>
        /// CreatedBy : Nadeeka
        /// CreatedDate: 2016/03/15
        /// 
        /// Get loan curtailment schedule by calling StepAccess class method, and creating curtailment date using that values
        /// 
        /// </summary>
        /// <param name="loanId"></param>
        public bool GetLoanCurtailmentDetails(int loanId, string unitId, DateTime advaceDate, decimal advanceAmount, decimal cost)
        {
            try
            {
                StepAccess stepAccess = new StepAccess();
            LoanSetupStep1 loan = stepAccess.GetLoanCurtailmentBreakdown(loanId);
            Int32 curtailmentNo = 1;
            //bool isEditAdvanceAmount = false;
            //isEditAdvanceAmount = ((cost * loan.advancePercentage) / 100) == advanceAmount ? false : true;
            foreach (Curtailment curtailment in loan.curtailmetList)
            {
                curtailment.CurtailmentId = curtailmentNo;
                //check pay off period as days or month               
                curtailment.CurtailmentDate = loan.payOffPeriodType == 0 ? (advaceDate.AddDays(Convert.ToDouble(curtailment.TimePeriod))) : advaceDate.AddMonths(curtailment.TimePeriod ?? 0);
                if (loan.CurtailmentCalculationBase == "f")
                { 
                    if (loan.curtailmetList.Count==curtailmentNo)
                    {
                        curtailment.Amount = Math.Round(advanceAmount - GetCurtailmentCurrentTotal(loan.curtailmetList),2);
                    }
                    else
                    {
                        curtailment.Amount = Math.Round(this.CalculateAdditionalPercentage(advanceAmount, curtailment.Percentage, loan.advancePercentage), 2);
                    }
                }
                else if (loan.CurtailmentCalculationBase == "a")
                {
                    if (loan.curtailmetList.Count == curtailmentNo)
                    {
                        curtailment.Amount = Math.Round(advanceAmount - GetCurtailmentCurrentTotal(loan.curtailmetList), 2);
                    }
                    else
                    {
                        curtailment.Amount = Math.Round((advanceAmount * curtailment.Percentage ?? 0) / 100, 2);
                    }                   
                }
                curtailmentNo++;
            }

           
                XElement xEle = new XElement("Curtailments",
                    from curtailment in loan.curtailmetList
                    select new XElement("Curtailment",
                        new XElement("LoanId", loanId),
                        new XElement("UnitId", unitId),
                        new XElement("CurtNo", curtailment.CurtailmentId),
                        new XElement("CurtAmount", curtailment.Amount),
                        new XElement("CurtDueDate", curtailment.CurtailmentDate),
                        new XElement("CurtStatus", 0)
                        ));
                string xmlDoc = xEle.ToString();
                CurtailmentAccess curtailmentAccess = new CurtailmentAccess();
                return curtailmentAccess.InsertCurtailmentScheduleInfo(xmlDoc, unitId, loanId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }