partial void DeleteRepaymentFrequency(RepaymentFrequency instance);
partial void UpdateRepaymentFrequency(RepaymentFrequency instance);
partial void InsertRepaymentFrequency(RepaymentFrequency instance);
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(); } } }
public static void GenerateContributionSchedule(int months, RepaymentFrequency repaymentFrequency, Investment currentLoan) { using (FinanceManagerDataContext db = new FinanceManagerDataContext()) { decimal repaymentIntervals = (decimal)(currentLoan.MaturityDate.Value.Date - currentLoan.InvestmentCalculationStartDate.Value).Days / (repaymentFrequency.ConversionUnit.Value * (decimal)months); DateTime tempScheduleDate = currentLoan.InvestmentCalculationStartDate.Value; DateTime tempDate = currentLoan.InvestmentCalculationStartDate.Value; CompanyProfile cProfile = db.CompanyProfiles.FirstOrDefault(); decimal balance = 0; for (decimal i = 0; i < Math.Round((currentLoan.MaturityDate.Value - currentLoan.InvestmentCalculationStartDate.Value).Days / repaymentIntervals, MidpointRounding.AwayFromZero); 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); } //decimal totalAmountContributed = db.Contributions.Where<Contribution>(cont => cont.InvestmentId == currentLoan.InvestmentID).Sum<Contribution>(c => c.ContributionAmount).Value; //update balance balance += currentLoan.ContributionFreqAmount.Value; var _contributionSchedule = new ContributionSchedule() { IsContributionMade = false, ExpectedContributionAmount = currentLoan.ContributionFreqAmount, InvestmentId = currentLoan.InvestmentID, ContributionDate = tempScheduleDate, Balance = balance }; db.SubmitChanges(); db.ContributionSchedules.InsertOnSubmit(_contributionSchedule); //audit Utils.logAction("Insert", _contributionSchedule); } //DateTime.Now.Month } }