public ActionResult Create(//[Bind(Include = "DepositId,UserId,Duration,DepositType,MaturityDate,TotalInstallments,DepositAmount,MatureAmount,InstallmentAmount,ClosedDate,RecurringDepositDate,Status,ChequeDetails,InteresRate,ApprovedDate,ApprovedBy,Notes,CreatedOn,ModifiedOn,CreatedBy,ModifiedBy,IsDeleted,DeletedBy,DeletedOn")] sdtoDepositInfo depositInfo) { depositInfo.DepositType = Data.Models.Enumerations.DepositType.Fixed; sdtoUser sessionUser = UtilityHelper.UserSession.GetSession(UtilityHelper.UserSession.LoggedInUser) as sdtoUser; depositInfo.IsDeleted = false; depositInfo.CreatedBy = sessionUser != null ? sessionUser.UserID : 0; depositInfo.CreatedOn = DateTime.Now; depositInfo.MatureAmount = depositInfo.DepositAmount + ((depositInfo.DepositAmount * Convert.ToDecimal(depositInfo.InteresRate / 100) * depositInfo.Duration) / 365); depositInfo.MaturityDate = depositInfo.CreatedOn.Value.AddDays(depositInfo.Duration); if (ModelState.IsValid) { db.sdtoDepositInfoes.Add(depositInfo); db.SaveChanges(); bfTransaction objTrans = new bfTransaction(db); objTrans.PostDepositIssue(depositInfo); return RedirectToAction("Index"); } var listUsers = db.User.Where(x => x.UserType == UserType.Member); ViewBag.UserList = new SelectList(listUsers.Select(x => new { UserID = x.UserID, Name = x.FirstName + " " + x.LastName }), "UserID", "Name"); return View(depositInfo); }
public ActionResult Create(//[Bind(Include = "LoanId,UserId,RepaymentStartDate,RePaymentInterval,RequestedAmount,ProposedAmount,LoanAmount,TotalInstallments,Status,ChequeDetails,InteresRate,SanctionedDate,SanctionedBy,Notes,CreatedOn,ModifiedOn,CreatedBy,ModifiedBy,IsDeleted,DeletedBy,DeletedOn")] sdtoLoanInfo LoanInfo) { if (ModelState.IsValid) { LoanInfo.InstallmentAmount = LoanInfo.LoanAmount / LoanInfo.TotalInstallments; LoanInfo.CreatedOn = DateTime.Now; bfReport objReport = new bfReport(db); LoanInfo.CreatedBy = CurrentUserSession.UserId; LoanInfo.LoanCode = objReport.GenerateCode("LoanInfo"); db.sdtoLoanInfoes.Add(LoanInfo); db.SaveChanges(); bfTransaction objTrans = new bfTransaction(db); objTrans.PostLoanIssue(LoanInfo); SetDisplayMessage("Loan is created successfully"); return RedirectToAction("Index"); } var listUsers = db.User.Where(x => x.UserType == UserType.Member && x.IsDeleted == false); var users = listUsers.Select(x => new SelectListItem() { Value = x.UserID.ToString(), Text = x.FirstName + " " + x.LastName }).ToList(); users.Insert(0, new SelectListItem() { Value = "0", Text = "Select a Member" }); ViewBag.UserList = new SelectList(users, "Value", "Text"); return View(LoanInfo); }
public ActionResult BankDeposit(sdtoViewAccDepositWithdrawal objDepositWithdrawal) { if (objDepositWithdrawal.SourceClick == 0) objDepositWithdrawal.Details.Add(new sdtoViewAccDepositWithdrawalDetails()); else { if (ModelState.IsValid) { bfTransaction objTransaction = new bfTransaction(db); objTransaction.AddBankDeposit(objDepositWithdrawal); if (objDepositWithdrawal.HeaderId > 0) objTransaction.CancelBankAccountHeader(objDepositWithdrawal.HeaderId); return RedirectToAction("ListBankDepositWithdrawal"); } } var bankBookType = db.AccountBookTypes.Where(x => x.UniqueName.Equals("Bank", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); LoadAccountHeadList(0); LoadAccountBookList(objDepositWithdrawal.Book != null ? objDepositWithdrawal.Book.AccountBookId : 0, bankBookType.AccountBookTypeId); return View(objDepositWithdrawal); }
public ActionResult JournalEntry(sdtoViewAccJournalEntry objCashReceiptPayment) { if (objCashReceiptPayment.SourceClick == 0) objCashReceiptPayment.Details.Add(new sdtoViewAccJournalEntryDetails()); else { if (ModelState.IsValid) { var cr = objCashReceiptPayment.Details.Sum(x => x.CreditAmount); var dr = objCashReceiptPayment.Details.Sum(x => x.CreditAmount); if (dr + (-1 * cr) > 0) ModelState.AddModelError("", "The voucher credit total and debit total does not balance."); else { bfTransaction objTransaction = new bfTransaction(db); if (objCashReceiptPayment.HeaderId > 0) objTransaction.CancelJournalAccountHeader(objCashReceiptPayment.HeaderId); objTransaction.AddJournalEntry(objCashReceiptPayment); return RedirectToAction("ListJournalEntry"); } } } LoadAccountHeadList(0); LoadJournalBookList(objCashReceiptPayment.Book != null ? objCashReceiptPayment.Book.AccountBookId : 0); return View(objCashReceiptPayment); }
public JsonResult GetBookAccountDetails(long AccountBookId, string TransType) { bfTransaction objReport = new bfTransaction(db); var accDetails = objReport.GetAccountDetails(AccountBookId, TransType); return Json(accDetails, JsonRequestBehavior.AllowGet); }
public ActionResult CashReceipt(sdtoViewAccCashReceiptPayment objCashReceiptPayment) { if (objCashReceiptPayment.SourceClick == 0) objCashReceiptPayment.Details.Add(new sdtoViewAccCashReceiptPaymentDetails()); else { if (ModelState.IsValid) { bfTransaction objTransaction = new bfTransaction(db); if (objCashReceiptPayment.HeaderId > 0) objTransaction.CancelCashAccountHeader(objCashReceiptPayment.HeaderId); objTransaction.AddCashReceipt(objCashReceiptPayment); return RedirectToAction("ListCashReceiptPayment"); } } var cashBookType = db.AccountBookTypes.Where(x => x.UniqueName.Equals("Cash", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); LoadAccountHeadList(0); LoadAccountBookList(objCashReceiptPayment.Book != null ? objCashReceiptPayment.Book.AccountBookId : 0, cashBookType.AccountBookTypeId); return View(objCashReceiptPayment); }
public ActionResult Create(sdtoUser sdtouser, HttpPostedFileBase ProfileImage) { sdtouser.ConfirmPassword = sdtouser.Password; if (string.IsNullOrEmpty(sdtouser.Code)) ModelState.AddModelError("", "Code cannot be empty"); else if (string.IsNullOrEmpty(sdtouser.FirstName)) ModelState.AddModelError("", "FirstName cannot be empty"); else if (string.IsNullOrEmpty(sdtouser.LastName)) ModelState.AddModelError("", "LastName cannot be empty"); //else if (string.IsNullOrEmpty(sdtouser.UserAddress.Address1)) // ModelState.AddModelError("", "Communication Address cannot be empty"); else if (string.IsNullOrWhiteSpace(sdtouser.PermanentAddress.Address1) || string.IsNullOrWhiteSpace(sdtouser.PermanentAddress.Address2) || sdtouser.PermanentAddress.CountryId == 0 || sdtouser.PermanentAddress.StateId == 0 || sdtouser.PermanentAddress.DistrictId == 0 || sdtouser.PermanentAddress.TalukId == 0 || sdtouser.PermanentAddress.VillageId == 0) ModelState.AddModelError("", "Permanent Address cannot be empty"); else if (ModelState.IsValid) { var validImageTypes = new string[] { "image/gif", "image/jpeg", "image/pjpeg", "image/png" }; if (ProfileImage != null && !validImageTypes.Contains(ProfileImage.ContentType)) { ModelState.AddModelError("", "Please choose either a GIF, JPG or PNG image for ProfileImage"); } else { sdtouser.UserType = UserType.Member; sdtouser.IsActive = true; if (sdtouser.UserAddress != null) { sdtouser.UserAddress.CreatedOn = DateTime.Now; } if (sdtouser.Contacts != null) { sdtouser.Contacts.CreatedOn = DateTime.Now; } if (sdtouser.PermanentAddress != null) { sdtouser.PermanentAddress.CreatedOn = DateTime.Now; } if (sdtouser.PermanentContacts != null) { sdtouser.PermanentContacts.CreatedOn = DateTime.Now; } if (sdtouser.GuaranterAddress != null) { sdtouser.GuaranterAddress.CreatedOn = DateTime.Now; } if (sdtouser.GuaranterContacts != null) { sdtouser.GuaranterContacts.CreatedOn = DateTime.Now; sdtouser.GuaranterContacts.ModifiedOn = DateTime.Now; } sdtouser.CreatedOn = DateTime.Now; sdtouser.CreatedBy = CurrentUserSession.UserId; if (sdtouser.UserAddress != null) { sdtouser.UserAddress.CountryId = sdtouser.UserAddress.CountryId == 0 ? null : sdtouser.UserAddress.CountryId; sdtouser.UserAddress.StateId = sdtouser.UserAddress.StateId == 0 ? null : sdtouser.UserAddress.StateId; sdtouser.UserAddress.DistrictId = sdtouser.UserAddress.DistrictId == 0 ? null : sdtouser.UserAddress.DistrictId; sdtouser.UserAddress.TalukId = sdtouser.UserAddress.TalukId == 0 ? null : sdtouser.UserAddress.TalukId; sdtouser.UserAddress.VillageId = sdtouser.UserAddress.VillageId == 0 ? null : sdtouser.UserAddress.VillageId; } if (sdtouser.PermanentAddress != null) { sdtouser.PermanentAddress.CountryId = sdtouser.PermanentAddress.CountryId == 0 ? null : sdtouser.PermanentAddress.CountryId; sdtouser.PermanentAddress.StateId = sdtouser.PermanentAddress.StateId == 0 ? null : sdtouser.PermanentAddress.StateId; sdtouser.PermanentAddress.DistrictId = sdtouser.PermanentAddress.DistrictId == 0 ? null : sdtouser.PermanentAddress.DistrictId; sdtouser.PermanentAddress.TalukId = sdtouser.PermanentAddress.TalukId == 0 ? null : sdtouser.PermanentAddress.TalukId; sdtouser.PermanentAddress.VillageId = sdtouser.PermanentAddress.VillageId == 0 ? null : sdtouser.PermanentAddress.VillageId; } if (sdtouser.GuaranterAddress != null) { sdtouser.GuaranterAddress.CountryId = sdtouser.GuaranterAddress.CountryId == 0 ? null : sdtouser.GuaranterAddress.CountryId; sdtouser.GuaranterAddress.StateId = sdtouser.GuaranterAddress.StateId == 0 ? null : sdtouser.GuaranterAddress.StateId; sdtouser.GuaranterAddress.DistrictId = sdtouser.GuaranterAddress.DistrictId == 0 ? null : sdtouser.GuaranterAddress.DistrictId; sdtouser.GuaranterAddress.TalukId = sdtouser.GuaranterAddress.TalukId == 0 ? null : sdtouser.GuaranterAddress.TalukId; sdtouser.GuaranterAddress.VillageId = sdtouser.GuaranterAddress.VillageId == 0 ? null : sdtouser.GuaranterAddress.VillageId; } sdtouser.UserAddress = db.Address.Add(sdtouser.UserAddress); sdtouser.Contacts = db.Contacts.Add(sdtouser.Contacts); sdtouser.PermanentAddress = db.Address.Add(sdtouser.PermanentAddress); sdtouser.PermanentContacts = db.Contacts.Add(sdtouser.PermanentContacts); sdtouser.GuaranterAddress = db.Address.Add(sdtouser.GuaranterAddress); sdtouser.GuaranterContacts = db.Contacts.Add(sdtouser.GuaranterContacts); db.User.Add(sdtouser); db.SaveChanges(); if (ProfileImage != null) { FileUpload(sdtouser.UserID, ProfileImage); System.IO.FileInfo fInfo = new FileInfo(ViewBag.UserProfileAvatar); fInfo.CopyTo(Path.Combine(fInfo.Directory.FullName, sdtouser.UserID + ".logo"), true); fInfo.Delete(); } else { DirectoryInfo dirUser = new DirectoryInfo(HttpContext.Server.MapPath("~/").Trim("\\/ ".ToCharArray()) + "\\ContentUpload\\User\\Profile"); if (!dirUser.Exists) dirUser.Create(); FileInfo objFile = new FileInfo(Path.Combine(HttpContext.Server.MapPath("~/").Trim("\\/ ".ToCharArray()) + "\\Content\\Images", "dummy-profile.png")); objFile.CopyTo(Path.Combine(dirUser.FullName, sdtouser.UserID + ".logo"), true); } bfTransaction objAccTransaction = new bfTransaction(db); objAccTransaction.InitiateMemberAccounts(sdtouser); SetDisplayMessage("Member is created successfully"); return RedirectToAction("Index"); } } ViewBag.AddressId = new SelectList(db.Address, "AddressId", "Address1", sdtouser.UserAddressId); ViewBag.ContactId = new SelectList(db.Contacts, "ContactId", "ContactName", sdtouser.UserContactId); ViewBag.GuaranterAddressId = new SelectList(db.Address, "AddressId", "Address1", sdtouser.GuaranterAddressId); ViewBag.GuaranterContactId = new SelectList(db.Contacts, "ContactId", "ContactName", sdtouser.GuaranterContactId); ViewBag.PermanentAddressId = new SelectList(db.Address, "AddressId", "Address1", sdtouser.PermanentAddressId); ViewBag.PermanentContactId = new SelectList(db.Contacts, "ContactId", "ContactName", sdtouser.PermanentContactId); var countries = db.Countries.ToList(); countries.Insert(0, new sdtoCountry() { CountryId = 0, CountryName = "Select Country" }); ViewBag.UserAddressCountryList = new SelectList(countries, "CountryId", "CountryName", sdtouser.UserAddress.CountryId); ViewBag.GuaranterAddressCountryList = new SelectList(countries, "CountryId", "CountryName", sdtouser.GuaranterAddress.CountryId); ViewBag.PermanentAddressCountryList = new SelectList(countries, "CountryId", "CountryName", sdtouser.PermanentAddress.CountryId); ViewBag.StateList = new SelectList(db.States, "StateId", "StateName", 0); //ViewBag.UserGroupId = new SelectList(db.Usergroup, "UserGroupId", "Name", sdtouser.UserGroupId); return View(sdtouser); }
public ActionResult WithdrawAmount(//[Bind(Include = "LoanRepaymentId,LoanId,RepaymentCode,PrincipalAmount,InterestAmount,InterestRate,RepaymentAmount,PendingPrincipalAmount,Status,PaymentMode,ChequeDetails,Notes,CreatedOn,ModifiedOn,CreatedBy,ModifiedBy,IsDeleted,DeletedBy,DeletedOn")] sdtoWithdrawalInfo depositWithdrawal) { if (ModelState.IsValid) { if (depositWithdrawal.DepositId > 0) { var depositDetails = db.sdtoDepositInfoes.Find(depositWithdrawal.DepositId); var depositBalanceAmt = depositDetails.DepositAmount; var depositInterest = depositDetails.InteresRate; //var loanPendingInstallments = depositDetails.TotalInstallments; int days = (DateTime.Now - depositDetails.CreatedOn.Value).Days; var withdrawalInterest = depositInterest; var withdrawalInterestAmt = ((depositDetails.DepositAmount * Convert.ToDecimal(withdrawalInterest / 100) * (days < depositDetails.Duration ? days : depositDetails.Duration)) / 365); var depositWithdrawalsPrev = db.DepositWithdrawals.Where(x => x.DepositId == depositWithdrawal.DepositId).OrderByDescending(x => x.WithdrawalId).FirstOrDefault(); if (depositWithdrawalsPrev != null && depositWithdrawalsPrev.WithdrawalId > 0) { depositBalanceAmt = depositWithdrawalsPrev.BalanceDepositAmount; //loanPendingInstallments = loanRepayment.PendingInstallments; withdrawalInterest = depositWithdrawalsPrev.NewInterestRate; } withdrawalInterestAmt = ((depositWithdrawal.WithdrawalAmount * Convert.ToDecimal(withdrawalInterest / 100) * (days < depositDetails.Duration ? days : depositDetails.Duration)) / 365); depositWithdrawal.InterestAmount = Math.Round(withdrawalInterestAmt, 2); depositWithdrawal.BalanceDepositAmount = depositBalanceAmt - depositWithdrawal.WithdrawalAmount; //sdtoLoanRepayment.PendingInstallments -= Convert.ToInt32(Math.Floor(sdtoLoanRepayment.PendingPrincipalAmount / loandetails.InstallmentAmount)); //sdtoLoanRepayment.PrincipalAmount = loandetails.LoanAmount; depositWithdrawal.Status = Data.Models.Enumerations.WithdrawalStatus.Paid; } db.DepositWithdrawals.Add(depositWithdrawal); db.SaveChanges(); bfTransaction objTrans = new bfTransaction(db); objTrans.CancelPostedDepositWithdrawal(depositWithdrawal); objTrans.PostDepositWithdrawal(depositWithdrawal); return RedirectToAction("Withdrawals", new { DepositId = depositWithdrawal.DepositId }); } var itemsDeposit = db.sdtoDepositInfoes.Include(x => x.Member).Where(x => x.Status == DepositStatus.Active).ToList(); var itemsDeposits = itemsDeposit.Select(x => new SelectListItem() { Value = x.DepositId.ToString(), Text = x.DepositId + " - " + x.DepositAmount + "[" + x.Member.FirstName + " " + x.Member.LastName + "]" }).ToList(); itemsDeposits.Insert(0, new SelectListItem() { Value = "0", Text = "Select a deposit" }); ViewBag.DepositList = new SelectList(itemsDeposits, "Value", "Text"); return View(depositWithdrawal); }
public ActionResult CancelLoanRepayments(sdtoViewLoanRepayments Repayments) { List<sdtoLoanRepayment> RepaymentCancelList = new List<sdtoLoanRepayment>(); string[] selectionRepayments = Repayments.InputSelection.Trim(" []".ToCharArray()).Split(','); if (selectionRepayments != null && selectionRepayments.Length > 0) { for (int iLoanRepaymentId = 0; iLoanRepaymentId < selectionRepayments.Length; iLoanRepaymentId++) { if (selectionRepayments[iLoanRepaymentId].Equals("true", StringComparison.InvariantCultureIgnoreCase)) { var repayment = db.sdtoLoanRepayments.Find(iLoanRepaymentId); RepaymentCancelList.Add(repayment); } } bfTransaction objTransaction = new bfTransaction(db); foreach (var repayment in RepaymentCancelList) { repayment.Status = RepaymentStatus.Cancelled; db.Entry(repayment).State = EntityState.Modified; objTransaction.CancelPostedLoanRepayment(repayment); } db.SaveChanges(); SetDisplayMessage("Loan repayments are cancelled successfully"); return RedirectToAction("Index", "LoanRepayments", new { LoanId = Repayments.LoanId }); } return View(Repayments); }
public ActionResult Edit(//[Bind(Include = "LoanRepaymentId,LoanId,RepaymentCode,PrincipalAmount,InterestAmount,InterestRate,RepaymentAmount,PendingPrincipalAmount,Status,PaymentMode,ChequeDetails,Notes,CreatedOn,ModifiedOn,CreatedBy,ModifiedBy,IsDeleted,DeletedBy,DeletedOn")] sdtoLoanRepayment sdtoLoanRepayment) { if (ModelState.IsValid) { var loandetails = db.sdtoLoanInfoes.Find(sdtoLoanRepayment.LoanId); var lastRepaymentDate = loandetails.RepaymentStartDate.Value; var pendingPrincipalAmount = loandetails.LoanAmount; decimal previousDue = 0; var previousLoanRepayment1 = db.sdtoLoanRepayments.Where(x => x.LoanId == sdtoLoanRepayment.LoanId && x.IsDeleted == false && x.Status != RepaymentStatus.Cancelled && x.LoanRepaymentId != sdtoLoanRepayment.LoanRepaymentId).OrderByDescending(x => x.LoanRepaymentId).FirstOrDefault(); if (previousLoanRepayment1 != null && previousLoanRepayment1.LoanRepaymentId > 0) { lastRepaymentDate = previousLoanRepayment1.RepaymentDate.Value; pendingPrincipalAmount = previousLoanRepayment1.PendingPrincipalAmount; previousDue = previousLoanRepayment1.PreviousPaymentDueAmount; } var loanRepayment1 = db.sdtoLoanRepayments.Where(x => x.LoanRepaymentId == sdtoLoanRepayment.LoanRepaymentId && x.IsDeleted == false && x.Status != RepaymentStatus.Cancelled).FirstOrDefault(); if (loanRepayment1 != null && loanRepayment1.LoanRepaymentId > 0) { var days = (sdtoLoanRepayment.RepaymentDate.Value - lastRepaymentDate).Days; days = days == 0 ? 1 : days; var repaymentInterestAmt = (pendingPrincipalAmount * Convert.ToDecimal(sdtoLoanRepayment.InterestRate / 100) * days) / 365; sdtoLoanRepayment.InterestAmount = Math.Round(repaymentInterestAmt, 2); decimal paymentBalance = sdtoLoanRepayment.RepaymentAmount - repaymentInterestAmt - loandetails.InstallmentAmount; sdtoLoanRepayment.PreviousPaymentDueAmount = paymentBalance > 0 ? (previousDue - paymentBalance) : (previousDue + paymentBalance); sdtoLoanRepayment.PendingPrincipalAmount = pendingPrincipalAmount - loandetails.InstallmentAmount + sdtoLoanRepayment.PreviousPaymentDueAmount; //(sdtoLoanRepayment.RepaymentAmount - repaymentInterestAmt); sdtoLoanRepayment.PendingInstallments -= Convert.ToInt32(Math.Floor(sdtoLoanRepayment.PendingPrincipalAmount / loandetails.InstallmentAmount)); sdtoLoanRepayment.PrincipalAmount = loandetails.LoanAmount; } db.Entry(sdtoLoanRepayment).State = EntityState.Modified; db.SaveChanges(); bfTransaction objTrans = new bfTransaction(db); objTrans.CancelPostedLoanRepayment(sdtoLoanRepayment); objTrans.PostLoanRepayment(sdtoLoanRepayment); return RedirectToAction("Index", new { LoanId = sdtoLoanRepayment.LoanId }); } var itemsLoan = db.sdtoLoanInfoes.Include(x => x.Member).ToList(); var itemsLoans = itemsLoan.Select(x => new SelectListItem() { Value = x.LoanId.ToString(), Text = x.LoanId + " - " + x.LoanAmount + "[" + x.Member.FirstName + " " + x.Member.LastName + "]" }).ToList(); itemsLoans.Insert(0, new SelectListItem() { Value = "0", Text = "Select a loan" }); ViewBag.LoanList = new SelectList(itemsLoans, "Value", "Text"); return View(sdtoLoanRepayment); }
public ActionResult Create(//[Bind(Include = "LoanRepaymentId,LoanId,RepaymentCode,PrincipalAmount,InterestAmount,InterestRate,RepaymentAmount,PendingPrincipalAmount,Status,PaymentMode,ChequeDetails,Notes,CreatedOn,ModifiedOn,CreatedBy,ModifiedBy,IsDeleted,DeletedBy,DeletedOn")] sdtoLoanRepayment sdtoLoanRepayment) { if (ModelState.IsValid) { if (sdtoLoanRepayment.LoanId > 0) { var loandetails = db.sdtoLoanInfoes.Find(sdtoLoanRepayment.LoanId); var loanPendingAmt = loandetails.LoanAmount; var loanInterest = loandetails.InteresRate; var loanPendingInstallments = loandetails.TotalInstallments; var loanRepayment = db.sdtoLoanRepayments.Where(x => x.LoanId == sdtoLoanRepayment.LoanId && x.IsDeleted == false && x.Status != RepaymentStatus.Cancelled).OrderByDescending(x => x.LoanRepaymentId).FirstOrDefault(); var repaymentInterest = loanInterest; var repaymentInterestAmt = (loanPendingAmt * Convert.ToDecimal(repaymentInterest / 100)) / 365; var lastRepaymentDate = loandetails.RepaymentStartDate.Value; var days = (DateTime.Now.Date - loandetails.RepaymentStartDate.Value).Days; bfReport objReport = new bfReport(db); if (loanRepayment != null && loanRepayment.LoanRepaymentId > 0) { if (loanRepayment.RepaymentDate != null) lastRepaymentDate = loanRepayment.RepaymentDate.Value; days = (sdtoLoanRepayment.RepaymentDate.Value - lastRepaymentDate).Days; days = days == 0 ? 1 : days; if (days < 0) days = 0; loanPendingAmt = loanRepayment.PendingPrincipalAmount; loanPendingInstallments = loanRepayment.PendingInstallments; repaymentInterest = loanRepayment.InterestRate; repaymentInterestAmt = (loanPendingAmt * Convert.ToDecimal(repaymentInterest / 100) * days) / 365; sdtoLoanRepayment.RepaymentCode = loanRepayment.RepaymentCode; decimal paymentBalance = sdtoLoanRepayment.RepaymentAmount - repaymentInterestAmt - (loandetails.InstallmentAmount * days); decimal previousDue = paymentBalance > 0 ? (loanRepayment.PreviousPaymentDueAmount - paymentBalance) : (loanRepayment.PreviousPaymentDueAmount + paymentBalance); sdtoLoanRepayment.PreviousPaymentDueAmount = previousDue; } sdtoLoanRepayment.InterestAmount = Math.Round(repaymentInterestAmt, 2); sdtoLoanRepayment.PendingPrincipalAmount = loanPendingAmt - (loandetails.InstallmentAmount * days) + sdtoLoanRepayment.PreviousPaymentDueAmount; //(sdtoLoanRepayment.RepaymentAmount - repaymentInterestAmt); sdtoLoanRepayment.PendingInstallments -= Convert.ToInt32(Math.Floor(sdtoLoanRepayment.PendingPrincipalAmount / loandetails.InstallmentAmount)); sdtoLoanRepayment.PrincipalAmount = loandetails.LoanAmount; sdtoLoanRepayment.Status = Data.Models.Enumerations.RepaymentStatus.Paid; sdtoLoanRepayment.CreatedOn = DateTime.Now; sdtoLoanRepayment.RepaymentCode = objReport.GenerateCode("LoanRepayment"); db.sdtoLoanRepayments.Add(sdtoLoanRepayment); db.SaveChanges(); bfTransaction objTrans = new bfTransaction(db); objTrans.PostLoanRepayment(sdtoLoanRepayment); return RedirectToAction("Index", new { LoanId = sdtoLoanRepayment.LoanId }); } } var itemsLoan = db.sdtoLoanInfoes.Include(x => x.Member).ToList(); var itemsLoans = itemsLoan.Select(x => new SelectListItem() { Value = x.LoanId.ToString(), Text = x.LoanId + " - " + x.LoanAmount + "[" + x.Member.FirstName + " " + x.Member.LastName + "]" }).ToList(); itemsLoans.Insert(0, new SelectListItem() { Value = "0", Text = "Select a loan" }); ViewBag.LoanList = new SelectList(itemsLoans, "Value", "Text"); return View(sdtoLoanRepayment); }