private void deleteProfileToolStripMenuItem_Click(object sender, EventArgs e) { if (clickedTreeNode.Tag is LoanProfile) { var result = MessageBox.Show("Are you sure you want to delete this loan?", "Delete loan?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == DialogResult.OK) { LoanProfile profile = (LoanProfile)clickedTreeNode.Tag; data.LoanProfiles.Remove(profile); if (data.LoanProfiles.Count > 0) { data.SelectedLoan = data.LoanProfiles[0].Loans[0]; } else { data.SelectedLoan = new Loan(); } BindTreeView(); BindSelectedLoan(); Program.UpdateDatabase(data); MessageBox.Show("The profile has been deleted", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Please select a loan profile", "Success", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private Report GenerateReport(LoanProfile Profile, ReportType type) { Report report = new Report(); report.LoanProfile = Profile; switch (type) { case ReportType.BUNGABULANAN: report.Data = Calculator.CalculateReportBungaBulanan(Profile); report.Name = Profile.Name + " Report - Bunga Bulanan"; break; case ReportType.OUTSTANDINGTAHUNAN: report.Data = Calculator.CalculateReportOutstandingLoanTahunan(Profile); report.Name = Profile.Name + " Report - Outstanding Tahunan"; break; case ReportType.POKOKBULANAN: report.Data = Calculator.CalculateReportPokokBulanan(Profile); report.Name = Profile.Name + " Report - Pokok Bulanan"; break; case ReportType.BUNGATAHUNAN: report.Data = Calculator.CalculateReportBungaTahunan(Profile); report.Name = Profile.Name + " Report - Bunga Tahunan"; break; case ReportType.SUMMARYTAHUNAN: report.Data = Calculator.CalculateReportSummaryTahunan(Profile); report.Name = Profile.Name + " Report - Summary Tahunan"; break; } return(report); }
private void exportAllLoansToolStripMenuItem_Click(object sender, EventArgs e) { XLWorkbook wb = new XLWorkbook(); LoanProfile profile = clickedTreeNode.Tag as LoanProfile; foreach (Loan loan in profile.Loans) { DataTable dt = loan.LoanDetails; wb.Worksheets.Add(dt, loan.Name); } var saveFileDialog = new SaveFileDialog { Filter = "Excel files|*.xlsx", Title = "Save an Excel File" }; saveFileDialog.FileName = profile.Name; var result = saveFileDialog.ShowDialog(); if (result == DialogResult.OK || result == DialogResult.Yes) { if (!String.IsNullOrWhiteSpace(saveFileDialog.FileName)) { wb.SaveAs(saveFileDialog.FileName); } MessageBox.Show("File saved successfully", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public async Task <IActionResult> Edit(int id, [Bind("Id,Term,Originator,Rate,LoanAmount,EstimatedValue,ApplicationId,IsCashOut,ClosingCost,IsCurrentMortgage,DebtToIncome,LoanToValue,PurposeId")] LoanProfile loanProfile) { if (id != loanProfile.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(loanProfile); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LoanProfileExists(loanProfile.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ApplicationId"] = new SelectList(_context.Applications, "Id", "Id", loanProfile.ApplicationId); ViewData["PurposeId"] = new SelectList(_context.Purposes, "Id", "Id", loanProfile.PurposeId); return(View(loanProfile)); }
private void duplicateProfileStripMenuItem_Click(object sender, EventArgs e) { if (clickedTreeNode.Tag is LoanProfile) { var result = MessageBox.Show("Do you want to duplicate this loan?", "Duplicate loan?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == DialogResult.OK) { LoanProfile profile = (LoanProfile)clickedTreeNode.Tag; string newName = profile.Name + "_duplicate"; while (data.LoanProfiles.Any(x => x.Name == newName)) { newName += "_duplicate"; } LoanProfile newProfile = profile.Clone() as LoanProfile; newProfile.Name = newName; data.LoanProfiles.Add(newProfile); BindTreeView(); BindSelectedLoan(); Program.UpdateDatabase(data); MessageBox.Show("The profile has been duplicated", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Please select a loan profile", "Success", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonEdit_Click(object sender, EventArgs e) { if (clickedTreeNode.Tag is LoanProfile) { LoanProfile profile = clickedTreeNode.Tag as LoanProfile; ProfileForm profileForm = new ProfileForm(profile.Name); profileForm.ShowDialog(); if (profileForm.DialogResult == DialogResult.OK) { string loanProfileName = ""; loanProfileName = profileForm.Text; LoanProfile source = data.LoanProfiles.SingleOrDefault(x => x.Name == profile.Name); if (source != null) { while (data.LoanProfiles.Any(x => x.Name == loanProfileName)) { loanProfileName += "_duplicate"; } source.Name = loanProfileName; foreach (var loan in source.Loans) { loan.LoanProfileName = loanProfileName; } } BindTreeView(); BindSelectedLoan(); Program.UpdateDatabase(data); } } }
public async Task <IActionResult> Create( [Bind("FirstName,LastName,CreditScore,MonthlyIncome")] Customer customer, [Bind("AssessedValue")] Property property, [Bind("Street, City, StateId, ZipCode")] Address address, [Bind("PurposeId")] LoanProfile loanProfile) { if (ModelState.IsValid) { //Get customer role var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); customer.IdentityUserId = userId; _context.Add(customer); //Add customer to DB _context.Add(address); //Add address to DB _context.SaveChanges(); //Customer and Address get PK property.AddressId = address.Id; //Add AddressId as FK to property property.OccupancyTypeId = 1; property.PropertyTypeId = 1; _context.Add(property); // _context.SaveChanges(); //give Property a PK Customers_Properties customers_Properties = new Customers_Properties(); customers_Properties.CustomerId = customer.Id; customers_Properties.PropertyId = property.Id; _context.Add(customers_Properties); _context.SaveChanges(); //Add FKs to Customers_Properties junction Application application = new Application(); application.ApplicationStartDate = DateTime.Now; //Timestamp application application.PropertyId = property.Id; _context.Add(application); //Add application to DB _context.SaveChanges(); //give application PK Applications_Customers applications_Customers = new Applications_Customers(); applications_Customers.CustomerId = customer.Id; //for Junction table applications_Customers.ApplicationId = application.Id; //for Junction table _context.Add(applications_Customers); loanProfile.Originator = "Customer"; loanProfile.ApplicationId = application.Id; if (loanProfile.PurposeId == 2) { loanProfile.IsCashOut = true; } _context.Add(loanProfile); _context.SaveChanges(); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(EditCurrentMortgage))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("Id,Term,Originator,Rate,LoanAmount,EstimatedValue,ApplicationId,IsCashOut,ClosingCost,IsCurrentMortgage,DebtToIncome,LoanToValue,PurposeId")] LoanProfile loanProfile) { if (ModelState.IsValid) { _context.Add(loanProfile); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ApplicationId"] = new SelectList(_context.Applications, "Id", "Id", loanProfile.ApplicationId); ViewData["PurposeId"] = new SelectList(_context.Purposes, "Id", "Id", loanProfile.PurposeId); return(View(loanProfile)); }
public static DataTable CalculateReportOutstandingLoanTahunan(LoanProfile LoanProfile) { DataTable table = new DataTable(); table.Columns.Add("Kreditur"); table.Columns.Add("Tahun Kredit"); table.Columns.Add("Limit Fasilitas"); List <int> years = new List <int>(); foreach (var loan in LoanProfile.Loans) { foreach (DataRow loanRow in loan.LoanDetails.Rows) { if (!years.Any(x => x == Convert.ToDateTime(loanRow[0]).Year)) { years.Add(Convert.ToDateTime(loanRow[0]).Year); table.Columns.Add(Convert.ToDateTime(loanRow[0]).Year.ToString()); } } } foreach (var loan in LoanProfile.Loans) { DataRow row = table.NewRow(); row[0] = loan.BankName; row[1] = loan.Year; row[2] = loan.Limit; foreach (var year in years) { foreach (DataRow loanRow in loan.LoanDetails.Rows) { double result = 0; if (Convert.ToDateTime(loanRow[0]).Year == year && Convert.ToDateTime(loanRow[0]).Month == 12) { result = Convert.ToDouble(loanRow[2].ToString()); int yearposition = 3 + years.IndexOf(year); row[yearposition] = result; //continue; } } } table.Rows.Add(row); } return(table); }
private void CopyLoan(Loan sourceLoan) { List <string> targetLoanProfiles = data.LoanProfiles.Where(x => x.Name != sourceLoan.LoanProfileName).Select(x => x.Name).ToList(); if (targetLoanProfiles.Count > 0) { CopyLoanForm copyLoanForm = new CopyLoanForm(targetLoanProfiles); copyLoanForm.ShowDialog(); if (copyLoanForm.DialogResult == DialogResult.OK) { LoanProfile targetLoanProfile = data.LoanProfiles.FirstOrDefault(x => x.Name == copyLoanForm.selectedProfile); if (targetLoanProfile != null) { Loan loan = targetLoanProfile.Loans.FirstOrDefault(x => x.Name == sourceLoan.Name); if (loan != null) { loan = (Loan)targetLoanProfile.Loans.First(x => x.Name == sourceLoan.Name).Clone(); loan.Name += " copy"; while (targetLoanProfile.Loans.Any(x => x.Name == loan.Name)) { loan.Name += " copy"; } } else { loan = (Loan)sourceLoan.Clone(); } loan.LoanProfileName = copyLoanForm.selectedProfile; targetLoanProfile.Loans.Add(loan); BindSelectedLoan(); BindTreeView(); Program.UpdateDatabase(data); MessageBox.Show("Loan has been copied!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else { MessageBox.Show("No other loan profiles available! Please add one or more profiles first before trying to copy the loan.", "No other target", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public async Task <IActionResult> CreateLoanProfile([Bind("Id")] Application application, [Bind("Term,Rate,LoanAmount,ClosingCost")] LoanProfile loanProfile) { if (ModelState.IsValid) { var purposeId = _context.LoanProfiles.Where(l => l.ApplicationId == application.Id).Select(p => p.PurposeId).FirstOrDefault(); loanProfile.Originator = "Customer"; loanProfile.ApplicationId = application.Id; loanProfile.PurposeId = purposeId; _context.Add(loanProfile); await _context.SaveChangesAsync(); return(RedirectToAction("Create", "Contacts", new { id = application.Id })); } return(View()); }
private void EditLoan(Loan editLoan) { LoanForm loanForm = new LoanForm(editLoan); loanForm.ShowDialog(); if (loanForm.DialogResult == DialogResult.OK) { Loan oldLoan = editLoan; Loan newLoan = loanForm.Loan; string loanProfileName = oldLoan.LoanProfileName; newLoan.LoanProfileName = loanProfileName; LoanProfile profile = data.LoanProfiles.SingleOrDefault(x => x.Name == loanProfileName); if (profile != null) { if (profile.Loans != null) { List <Loan> targetLoans = profile.Loans.Where(x => x.Name == oldLoan.Name).ToList(); foreach (var item in targetLoans) { profile.Loans.Remove(item); } profile.Loans.Add(newLoan); } else { profile.Loans = new List <Loan>(); profile.Loans.Add(newLoan); } } data.SelectedLoan = newLoan; BindTreeView(); BindSelectedLoan(); Program.UpdateDatabase(data); } }
private void DeleteLoan(Loan sourceLoan) { var result = MessageBox.Show("Are you sure you want to delete this loan?", "Delete loan?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == DialogResult.OK) { LoanProfile profile = data.LoanProfiles.SingleOrDefault(x => x.Name == sourceLoan.LoanProfileName); if (profile != null) { profile.Loans.Remove(sourceLoan); data.SelectedLoan = new Loan(); BindTreeView(); BindSelectedLoan(); Program.UpdateDatabase(data); MessageBox.Show("The loan has been deleted", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
public async Task <IActionResult> EditLoanProfile(int id, [Bind("Id,Term,ClosingCost,LoanAmount,Rate")] LoanProfile loanProfile) { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var customer = await _context.Customers.Where(c => c.IdentityUserId == userId) .FirstOrDefaultAsync(); var loanProfileInDb = _context.LoanProfiles.Where(c => c.Id == loanProfile.Id).SingleOrDefault(); if (id != loanProfile.Id) { return(NotFound()); } if (ModelState.IsValid) { try { loanProfileInDb.Rate = loanProfile.Rate; loanProfileInDb.Term = loanProfile.Term; loanProfileInDb.LoanAmount = loanProfile.LoanAmount; loanProfileInDb.ClosingCost = loanProfile.ClosingCost; _context.Update(customer); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(customer.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(customer)); }
static void Main() { LoanBuilder loanBuilder; var loanProfile = new LoanProfile(); loanBuilder = new CompanyLoan(); loanProfile.SetProfile(loanBuilder); Console.WriteLine(loanBuilder.Customer.GetMadatoryDocuments()); Console.WriteLine(loanBuilder.Customer.GetMaxLoanAmount()); loanBuilder = new PersonLoan(); loanProfile.SetProfile(loanBuilder); Console.WriteLine(loanBuilder.Customer.GetMadatoryDocuments()); Console.WriteLine(loanBuilder.Customer.GetMaxLoanAmount()); loanBuilder = new StaffLoan(); loanProfile.SetProfile(loanBuilder); Console.WriteLine(loanBuilder.Customer.GetMadatoryDocuments()); Console.WriteLine(loanBuilder.Customer.GetMaxLoanAmount()); Console.ReadKey(); }
private void CreateNewProfile() { ProfileForm profileForm = new ProfileForm(); profileForm.ShowDialog(); if (profileForm.DialogResult == DialogResult.OK) { string loanProfileName = ""; loanProfileName = profileForm.Text; while (data.LoanProfiles.Any(x => x.Name == loanProfileName)) { loanProfileName = loanProfileName + "_duplicatename"; } LoanProfile loanProfile = new LoanProfile(); loanProfile.Name = loanProfileName; loanProfile.Loans = new List <Loan>(); data.LoanProfiles.Add(loanProfile); BindTreeView(); Program.UpdateDatabase(data); } }
public async Task <IActionResult> EditLoanProfile(int id, [Bind("Id,Term,ClosingCost,LoanAmount,Rate")] LoanProfile loanProfile) { var loanProfileInDb = _context.LoanProfiles.Where(c => c.Id == loanProfile.Id).SingleOrDefault(); if (id != loanProfile.Id) { return(NotFound()); } if (ModelState.IsValid) { //try //{ loanProfileInDb.Rate = loanProfile.Rate; loanProfileInDb.Term = loanProfile.Term; loanProfileInDb.LoanAmount = loanProfile.LoanAmount; loanProfileInDb.ClosingCost = loanProfile.ClosingCost; _context.Update(loanProfileInDb); await _context.SaveChangesAsync(); //}; //catch (DbUpdateConcurrencyException) //{ // if (!CustomerExists(customer.Id)) // { // return NotFound(); // } // else // {$"{id}" // throw; // } //} return(RedirectToAction("Create", "Contacts", new { id = loanProfileInDb.ApplicationId })); } return(View()); }
private void EditProfile(LoanProfile sourceLoanProfile) { ProfileForm profileForm = new ProfileForm(sourceLoanProfile.Name); profileForm.ShowDialog(); if (profileForm.DialogResult == DialogResult.OK) { string loanProfileName = ""; loanProfileName = profileForm.Text; if (data.LoanProfiles.Any(x => x.Name == loanProfileName)) { MessageBox.Show("There is already a loan profile with the selected name. Please insert a different name.", "Loan profile already exists", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { LoanProfile changedProfile = data.LoanProfiles.SingleOrDefault(x => x.Name == sourceLoanProfile.Name); if (changedProfile != null) { changedProfile.Name = loanProfileName; foreach (var item in changedProfile.Loans) { item.LoanProfileName = loanProfileName; } data.SelectedLoan = new Loan(); BindTreeView(); BindSelectedLoan(); Program.UpdateDatabase(data); MessageBox.Show("Profile name has been successfully changed", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }
private void CreateNewLoan() { LoanForm loanForm = new LoanForm(); loanForm.ShowDialog(); if (loanForm.DialogResult == DialogResult.OK) { LoanProfile profile = data.LoanProfiles.SingleOrDefault(x => x.Name == clickedNode.Split(':')[1]); if (profile != null) { if (profile.Loans != null) { loanForm.Loan.LoanProfileName = profile.Name; while (profile.Loans.Any(x => x.Name == loanForm.Loan.Name)) { loanForm.Loan.Name += " - duplicate"; } profile.Loans.Add(loanForm.Loan); } else { loanForm.Loan.LoanProfileName = profile.Name; profile.Loans = new List <Loan>(); profile.Loans.Add(loanForm.Loan); } } data.SelectedLoan = loanForm.Loan; BindTreeView(); BindSelectedLoan(); Program.UpdateDatabase(data); } }
public static DataTable CalculateReportSummaryTahunan(LoanProfile LoanProfile) { DataTable table = new DataTable(); table.Columns.Add("Kreditur"); table.Columns.Add("Tahun Kredit"); table.Columns.Add("Limit Fasilitas"); List <int> years = new List <int>(); foreach (var loan in LoanProfile.Loans) { foreach (DataRow loanRow in loan.LoanDetails.Rows) { if (!years.Any(x => x == Convert.ToDateTime(loanRow[0]).Year)) { years.Add(Convert.ToDateTime(loanRow[0]).Year); table.Columns.Add(Convert.ToDateTime(loanRow[0]).Year.ToString() + " Penarikan"); table.Columns.Add(Convert.ToDateTime(loanRow[0]).Year.ToString() + " Repayment"); table.Columns.Add(Convert.ToDateTime(loanRow[0]).Year.ToString() + " Outsanding"); table.Columns.Add(Convert.ToDateTime(loanRow[0]).Year.ToString() + " Bunga"); } } } foreach (var loan in LoanProfile.Loans) { DataRow row = table.NewRow(); row[0] = loan.BankName; row[1] = loan.Year; row[2] = loan.Limit; foreach (var year in years) { double penarikan = 0; double repayment = 0; double outstanding = 0; double bunga = 0; foreach (DataRow loanRow in loan.LoanDetails.Rows) { if (Convert.ToDateTime(loanRow[0]).Year == year) { bunga += Convert.ToDouble(loanRow[9].ToString()); penarikan += Convert.ToDouble(loanRow[1].ToString()); repayment += Convert.ToDouble(loanRow[8].ToString()); if (Convert.ToDateTime(loanRow[0]).Month == 12) { outstanding = Convert.ToDouble(loanRow[2].ToString()); } } } int penarikanPosition = 3 + (4 * years.IndexOf(year)); int repaymentPosition = 3 + (4 * years.IndexOf(year)) + 1; int outstandingPosition = 3 + (4 * years.IndexOf(year)) + 2; int bungaPosition = 3 + (4 * years.IndexOf(year)) + 3; row[penarikanPosition] = penarikan; row[repaymentPosition] = repayment; row[outstandingPosition] = outstanding; row[bungaPosition] = bunga; } table.Rows.Add(row); } return(table); }
public static DataTable CalculateReportPokokBulanan(LoanProfile LoanProfile) { DataTable table = new DataTable(); table.Columns.Add("Sisa Pokok"); List <int> years = new List <int>(); foreach (Loan loan in LoanProfile.Loans) { table.Columns.Add(loan.Name); foreach (DataRow loanRow in loan.LoanDetails.Rows) { if (!years.Any(x => x == Convert.ToDateTime(loanRow[0]).Year)) { years.Add(Convert.ToDateTime(loanRow[0]).Year); } } } foreach (int year in years) { for (int i = 0; i < table.Columns.Count; i++) { if (i > 0) { } } for (int i = 1; i < 13; i++) { DataRow row = table.NewRow(); row[0] = i.ToString("00") + "/" + year.ToString(); foreach (Loan loan in LoanProfile.Loans) { double bunga = 0; if (loan.LoanDetails != null) { List <DataRow> rows = loan.LoanDetails.AsEnumerable().Where(x => DateTime.Parse(x[0].ToString()).Month == i && DateTime.Parse(x[0].ToString()).Year == year).ToList(); foreach (DataRow insertedRow in rows) { bunga += (double)insertedRow[8]; } } int position = 1 + LoanProfile.Loans.IndexOf(loan); row[position] = bunga; } table.Rows.Add(row); } DataRow summaryRow = table.NewRow(); summaryRow[0] = year.ToString(); for (int i = 0; i < table.Columns.Count; i++) { if (i > 0) { int pos = i; string loanName = table.Columns[pos].ColumnName; double pokok = 0; if (table.Rows.Count == 12) { Loan loan = LoanProfile.Loans.SingleOrDefault(x => x.Name == loanName); pokok = loan.Limit; } else { pokok = Convert.ToDouble(table.Rows[table.Rows.Count - 13][pos]); } double result = 0; for (int j = table.Rows.Count - 12; j < table.Rows.Count; j++) { result += Convert.ToDouble(table.Rows[j][pos]); } summaryRow[pos] = pokok - result; } } table.Rows.Add(summaryRow); } return(table); }