public JsonResult LoadPrincipalDues(long?id) { db_lendingEntities db = new db_lendingEntities(); if (Session["UserId"] != null) { decimal balance = 0; decimal payments = 0; decimal total_balance = 0; decimal loan_granted = 0; decimal interest_rate = 0; decimal interest = 0; decimal paymentsInterest = 0; List <collectionslist> collectionslist = new List <collectionslist>(); collectionslist collection = new collectionslist(); var result = from d in db.tbl_loan_processing where d.customer_id == id && d.status == "Released" orderby d.loantype_id ascending select d; foreach (var dt in result) { var interest_type = GetInterestType(dt.loan_name); balance = GetBalance(dt.loan_no); payments = GetPayments(dt.loan_no); paymentsInterest = GetPaymentsInterest(dt.loan_no); total_balance = balance - payments; interest_rate = (decimal)dt.loan_interest_rate; loan_granted = (decimal)dt.loan_granted; interest = loan_granted * (interest_rate / 100); total_balance = decimal.Round((decimal)total_balance, 2, MidpointRounding.AwayFromZero); if (interest_type == "1") { total_balance = total_balance - interest; } if (total_balance > 0) { collectionslist.Add(new collectionslist { loan_no = dt.loan_no, loan_type = dt.loan_name, due_date = dt.due_date, amount_due = total_balance, payment = 0, interest = dt.loan_interest_rate, interest_type = GetInterestType(dt.loan_name) }); } } var data = collectionslist.ToList(); return(Json(new { data = data }, JsonRequestBehavior.AllowGet)); } else { return(Json("Failed", JsonRequestBehavior.AllowGet)); } }
public JsonResult LoadInterestDues(long?id) { db_lendingEntities db = new db_lendingEntities(); var datetimenow = DateTime.Now; var datenow = datetimenow.Date; if (Session["UserId"] != null) { GenerateInterest(id); List <collectionslist> collectionslist = new List <collectionslist>(); collectionslist collection = new collectionslist(); var result = from d in db.tbl_loan_processing where d.customer_id == id && d.status == "Released" orderby d.date_created select d; foreach (var dt in result) { var initialInterest = dt.loan_granted * (dt.loan_interest_rate / 100); decimal?interestBalance = 0; if (GetInterestType(dt.loan_name) == "1") { interestBalance = GetLedgerInterestBalance(dt.loan_no, initialInterest); } else { interestBalance = GetLedgerInterestBalance(dt.loan_no, 0); } interestBalance = decimal.Round((decimal)interestBalance, 2, MidpointRounding.AwayFromZero); if (interestBalance > 0) { collectionslist.Add(new collectionslist { loan_no = dt.loan_no, loan_type = dt.loan_name, due_date = dt.due_date, amount_due = interestBalance, payment = 0, interest = dt.loan_interest_rate, interest_type = GetInterestType(dt.loan_name) }); } } var data = collectionslist.ToList(); return(Json(new { data = data }, JsonRequestBehavior.AllowGet)); } else { return(Json("Failed", JsonRequestBehavior.AllowGet)); } }