partial void DeleteRepaymentSchedule(RepaymentSchedule instance);
 partial void UpdateRepaymentSchedule(RepaymentSchedule instance);
 partial void InsertRepaymentSchedule(RepaymentSchedule instance);
		private void detach_RepaymentSchedules(RepaymentSchedule entity)
		{
			this.SendPropertyChanging();
			entity.Member = null;
		}
    public static void GenerateRepaymentSchedule_new(int months, RepaymentFrequency repaymentFrequency, Loan currentLoan)
    {
        using (FinanceManagerDataContext db = new FinanceManagerDataContext())
        {
            decimal tempLoanAmount = currentLoan.Amount.Value;
            decimal repaymentIntervals = (decimal)(currentLoan.ExpectedRepaymentEndDate.Value.Date - currentLoan.LoanCalculationStartDate.Value).Days / (repaymentFrequency.ConversionUnit.Value * (decimal)months);
            DateTime tempScheduleDate = currentLoan.LoanCalculationStartDate.Value;
            DateTime tempDate = currentLoan.LoanCalculationStartDate.Value;
            CompanyProfile cProfile = db.CompanyProfiles.FirstOrDefault();

            decimal numberOfPayments = Math.Round((currentLoan.ExpectedRepaymentEndDate.Value - currentLoan.LoanCalculationStartDate.Value).Days / repaymentIntervals, MidpointRounding.AwayFromZero);

            for (decimal i = 0; i < numberOfPayments; i++)
            {
                tempScheduleDate = tempDate = tempDate.AddDays((int)repaymentIntervals);
                if (tempScheduleDate.DayOfWeek == DayOfWeek.Sunday)
                {
                    tempScheduleDate = tempScheduleDate.AddDays(1);
                }
                else if (tempScheduleDate.DayOfWeek == DayOfWeek.Saturday)
                {
                    tempScheduleDate = tempScheduleDate.AddDays(2);
                }

                //get the loan amount
                tempLoanAmount -= currentLoan.RepaymentFreqAmount.Value;

                decimal _repaymentAmount = currentLoan.RepaymentFreqAmount.Value;
                // decimal _interestRepayment = (currentLoan.Interest.Value / 100) * _repaymentAmount;
                decimal _interestRepayment = (currentLoan.Amount.Value - currentLoan.Principal.Value) / numberOfPayments;

                //create new loan schedule
                var _repaymentSchedule = new RepaymentSchedule()
                {
                    Balance = tempLoanAmount,
                    IsPaymentMade = false,
                    ExpectedRepaymentAmount = currentLoan.RepaymentFreqAmount,
                    LoanId = currentLoan.LoanID,
                    RepaymentDate = tempScheduleDate,
                    InterestPayment = _interestRepayment,
                    PrincipalPayment = _repaymentAmount - _interestRepayment
                };
                db.RepaymentSchedules.InsertOnSubmit(_repaymentSchedule);
                db.SubmitChanges();

                //audit
                Utils.logAction("Insert", _repaymentSchedule);
            }

            //DateTime.Now.Month

        }
    }
    public static void GenerateRepaymentSchedule(int months, RepaymentFrequency repaymentFrequency, Loan currentLoan)
    {
        using (FinanceManagerDataContext db = new FinanceManagerDataContext())
        {
            List<string> repaymentDays = new List<string>();
            DateTime tempDatertime = DateTime.Today;
            DateTime tempResultantDate = DateTime.Today;
            bool isSunday = false;
            CompanyProfile cProfile = db.CompanyProfiles.FirstOrDefault();
            for (int i = 0; i < months; i++)
            {
                for (int j = 0; j < repaymentFrequency.NumberOfDays; j++)
                {
                    if (tempDatertime.AddDays(1).DayOfWeek == DayOfWeek.Saturday)
                    {
                        if (cProfile.ExcludeSaturdayFromCalculations.Value)
                        {
                            tempResultantDate = tempDatertime.AddDays(3);
                            // tempDatertime = tempDatertime.AddDays(1);
                            //tempResultantDate.AddDays(3);
                            // isSunday = false;
                        }
                    }
                    else if (tempDatertime.AddDays(1).DayOfWeek == DayOfWeek.Sunday)
                    {
                        if (cProfile.ExcludeSundaysFromCalculations.Value)
                        {
                            tempResultantDate = tempDatertime.AddDays(2); //if day lands on sunday, move day to monday

                            // tempResultantDate.AddDays(2);
                            //  isSunday = true;
                        }
                    }
                    else
                    {
                        tempResultantDate = tempDatertime.AddDays(1);
                    }
                    tempDatertime = tempDatertime.AddDays(1);

                    //if (isSunday)
                    //{
                    //    tempDatertime = tempDatertime.AddDays(-1); //come back to sunday
                    //}
                    //else {
                    //    tempDatertime = tempDatertime.AddDays(-2); //come back to sutarday
                    //}

                }
                var _repaymentSchedule = new RepaymentSchedule() { LoanId = currentLoan.LoanID, ExpectedRepaymentAmount = currentLoan.RepaymentFreqAmount, RepaymentDate = tempResultantDate };
                db.RepaymentSchedules.InsertOnSubmit(_repaymentSchedule);

                //audit
                Utils.logAction("Insert", _repaymentSchedule);
                db.SubmitChanges();
            }

        }
    }