protected void Page_Load(object sender, EventArgs e) { try { using (var ctx = new finalContext()) { var set = ctx.OnlineSettings.Find(1); lblVisitor.Text = set.Visitor.ToString(); } lblTime.Text = DateTime.Now.ToString("MMM dd, yyyy | hh:mm tt"); string tnum = Request.QueryString["id"]; using (var ctx = new finalContext()) { var clt = ctx.Clients.Where(x => x.TrackingNumber == tnum).First(); if (clt.isRegistered == true) { Response.Redirect("/Index.aspx"); } else { clt.isRegistered = true; var exp = ctx.iClientExpirations.Find(clt.ClientID); lblContent.Text = "Your currently registered account will be deleted if not confirmed on or before " + exp.ExpirationDate + "\n Please visit our office to confirm this account regarding the information. Thank You."; Session["newID"] = null; ctx.SaveChanges(); } } } catch (Exception) { Response.Redirect("/Index.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { try { lblTime.Text = DateTime.Now.ToString("MMM dd, yyyy | hh:mm tt"); Session["Service"] = null; Session["UpdateChecker"] = null; Session["iService"] = null; if (Session["Visit"] == null) { Session["Visit"] = "Visited"; using (var ctx = new finalContext()) { var set = ctx.OnlineSettings.Find(1); set.Visitor = set.Visitor + 1; ctx.SaveChanges(); } } using (var ctx = new finalContext()) { var set = ctx.OnlineSettings.Find(1); lblDesc.Text = set.HomeDescription.Replace("\n", "<br />"); ; lblVisitor.Text = set.Visitor.ToString(); } } catch (Exception) { Response.Redirect("/Index.aspx"); } }
private void btnContinue_Click(object sender, RoutedEventArgs e) { try { MessageBoxResult mr = MessageBox.Show("Are you sure you want to proceed?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question); if (mr == MessageBoxResult.Yes) { if (rdDaif.IsChecked == true) { using (var ctx = new finalContext()) { FPaymentInfo fp = ctx.FPaymentInfo.Find(fId); ReturnedCheque rc = new ReturnedCheque { DateReturned = DateTime.Today.Date, Fee = DaifFee, FPaymentInfoID = fId, Remarks = "DAIF", isPaid = false }; fp.PaymentStatus = "Returned"; ctx.ReturnedCheques.Add(rc); AuditTrail at = new AuditTrail { EmployeeID = UserID, DateAndTime = DateTime.Now, Action = "Processed returned cheque " + fp.ChequeInfo }; ctx.AuditTrails.Add(at); ctx.SaveChanges(); MessageBox.Show("Okay", "Information", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } else { using (var ctx = new finalContext()) { FPaymentInfo fp = ctx.FPaymentInfo.Find(fId); ClosedAccount cc = new ClosedAccount { DateClosed = DateTime.Today.Date, Fee = ClosedFee, LoanID = fp.LoanID, isPaid = false }; //fp.PaymentStatus = "Returned"; fp.Loan.Status = "Closed Account"; ctx.ClosedAccounts.Add(cc); var chq = from c in ctx.FPaymentInfo where c.PaymentStatus != "Cleared" && c.LoanID==fp.LoanID select c; foreach (var item in chq) { item.PaymentStatus = "Void"; } AuditTrail at = new AuditTrail { EmployeeID = UserID, DateAndTime = DateTime.Now, Action = "Processed returned cheque " + fp.ChequeInfo }; ctx.AuditTrails.Add(at); ctx.SaveChanges(); MessageBox.Show("Transaction has been successfully processed", "Information", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } } } catch (Exception ex) { System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } }
private void btnAdjust_Click(object sender, RoutedEventArgs e) { try { if (dtTo.SelectedDate.Value.Date < dtFrom.SelectedDate.Value.Date) { System.Windows.MessageBox.Show("TO date must be breater than or equal to FROM date", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } using (var ctx = new finalContext()) { var py = from p in ctx.MPaymentInfoes where (p.DueDate <= dtTo.SelectedDate.Value && p.DueDate >= dtFrom.SelectedDate.Value) && (p.PaymentStatus == "Unpaid" || p.PaymentStatus=="Pending") select p; var ctr = ctx.MPaymentInfoes.Where(p=> (p.DueDate <= dtTo.SelectedDate.Value && p.DueDate >= dtFrom.SelectedDate.Value) && (p.PaymentStatus == "Unpaid" || p.PaymentStatus == "Pending")).Count(); if (ctr > 0) { var ps = ctx.MPaymentInfoes.Where(p=> (p.DueDate <= dtTo.SelectedDate.Value && p.DueDate >= dtFrom.SelectedDate.Value) && (p.PaymentStatus == "Unpaid" || p.PaymentStatus == "Pending")).First(); double rem = ps.RemainingLoanBalance; foreach (var itm in py) { itm.TotalAmount = itm.Amount + itm.PreviousBalance; itm.TotalBalance = itm.TotalBalance - itm.BalanceInterest; itm.RemainingLoanBalance = rem; //if (itm.BalanceInterest != 0) //{ //itm.PreviousBalance = itm.PreviousBalance - itm.BalanceInterest; //itm.TotalAmount = itm.Amount + itm.PreviousBalance; //} if (itm.PaymentStatus == "Unpaid") { itm.PaymentStatus = "Unpaid(No Interest)"; } } foreach (var itm in py) { itm.BalanceInterest = 0; } MicroAdjusment ma = new MicroAdjusment { ToDate = dtTo.SelectedDate.Value.Date, FromDate = dtFrom.SelectedDate.Value.Date, ReasonOfAdjustment = txtReason.Text }; ctx.MicroAdjusments.Add(ma); ctx.SaveChanges(); System.Windows.MessageBox.Show("Transaction has been successfully processed", "Information", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } } catch (Exception ex) { System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } }
private void btnLogIn_Click(object sender, RoutedEventArgs e) { using (var ctx = new finalContext()) { if (txtUsername.Text == "" || txtPassword.Password == "") { MessageBox.Show("Please input username/password"); return; } var ctr = ctx.Users.Where(x => x.Username == txtUsername.Text).Count(); if (ctr > 0) { var usr = ctx.Users.Where(x => x.Username == txtUsername.Text).First(); if (usr.Employee.Position.PositionName != "Administrator") { MessageBox.Show("Only the administrator is allowed to activate the system."); return; } else { var c = ctx.Users.Where(x => x.Username == txtUsername.Text && x.Password == txtPassword.Password).Count(); if (c > 0) { var st = ctx.State.Find(1); st.iState = 0; ctx.SaveChanges(); MessageBox.Show("System has been successfuly activated."); wpfLogin frm = new wpfLogin(); frm.ShowDialog(); this.Close(); } } } else { MessageBox.Show("Incorrect admin information."); return; } } }
private void btnRecord_Click(object sender, RoutedEventArgs e) { double amt = 0; try { amt = Convert.ToDouble(txtAmt.Text); amt = Convert.ToDouble(amt.ToString("N2")); } catch (Exception) { amt = 0; } if (amt > Convert.ToDouble(lblTotalLoan.Content)) { System.Windows.MessageBox.Show("Amount must not be greater that the remaining amount", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (amt < 1) { System.Windows.MessageBox.Show("Amount must be greater that 1", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } int lID; try { lID = Convert.ToInt32(txtID.Text); } catch (Exception) { lID = 0; } using (var ctx = new finalContext()) { CollectionInfo ci = new CollectionInfo { LoanID = lID, DateCollected = DateTime.Today.Date, TotalCollection = amt }; var r = ctx.PassedToCollectors.Find(lID); double rBal = Convert.ToDouble((r.RemainingBalance - amt).ToString("N2")); r.RemainingBalance = rBal; ctx.CollectionInfoes.Add(ci); if (rBal <= 0) { System.Windows.MessageBox.Show("The Loan has been successfully finished!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); var lon = ctx.Loans.Find(lID); lon.Status = "Paid"; r.RemainingBalance = 0; PaidLoan pl = new PaidLoan { LoanID = lID, DateFinished = DateTime.Today.Date }; ctx.PaidLoans.Add(pl); } ctx.SaveChanges(); txtID.Text = ""; txtID.Focus(); } }
private void btnSave_Click(object sender, RoutedEventArgs e) { //try //{ if (lblName.Content == "?" || lblDesc.Content == "?" || String.IsNullOrWhiteSpace(txtName.Text)|| dt.SelectedDate.Value == null) { System.Windows.MessageBox.Show("Please input correct format and/or fill all required fields", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (status == "Add") { using (var ctx = new finalContext()) { //if (isYearly.IsChecked == true) //{ var mC = ctx.MPaymentInfoes.Where(x => x.DueDate.Month == dt.SelectedDate.Value.Month && x.DueDate.Day == dt.SelectedDate.Value.Day).Count(); if (mC > 0) { System.Windows.MessageBox.Show("Payments on the given day will be automatically adjusted", "Information", MessageBoxButton.OK, MessageBoxImage.Information); var ps = from x in ctx.MPaymentInfoes select x; DateTime idt1 = dt.SelectedDate.Value; DateTime idt = DateAndTime.DateAdd(DateInterval.Day, 1, idt1); bool isHoliday = true; while (isHoliday == true || idt.Date.DayOfWeek.ToString() == "Saturday" || idt.Date.DayOfWeek.ToString() == "Sunday") { if (idt.Date.DayOfWeek.ToString() == "Saturday") { idt = DateAndTime.DateAdd(DateInterval.Day, 2, idt); } else if (idt.Date.DayOfWeek.ToString() == "Sunday") { idt = DateAndTime.DateAdd(DateInterval.Day, 1, idt); } var myC = ctx.Holidays.Where(x => x.Date.Month == idt.Date.Month && x.Date.Day == idt.Date.Day && x.isYearly == true).Count(); if (myC > 0) { idt = DateAndTime.DateAdd(DateInterval.Day, 1, idt); isHoliday = true; } else { myC = ctx.Holidays.Where(x => x.Date.Month == idt.Date.Month && x.Date.Day == idt.Date.Day && x.Date.Year == idt.Date.Year && x.isYearly == !true).Count(); if (myC > 0) { idt = DateAndTime.DateAdd(DateInterval.Day, 1, idt); isHoliday = true; } else { isHoliday = false; } } } foreach (var x in ps) { if (isYearly.IsChecked == true) { if (x.DueDate.Month == idt1.Date.Month && x.DueDate.Day == idt1.Date.Day) { x.DueDate = idt; } } else { if (x.DueDate.Month == idt1.Date.Month && x.DueDate.Day == idt1.Date.Day && x.DueDate.Year == idt1.Date.Year) { x.DueDate = idt; } } } } // } var num = ctx.Holidays.Where(x => x.HolidayName == txtName.Text).Count(); if (num > 0) { System.Windows.MessageBox.Show("Holiday already exists", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } num = ctx.Holidays.Where(x => x.Date == dt.SelectedDate.Value).Count(); if (num > 0) { System.Windows.MessageBox.Show("Holiday already exists", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } Holiday h = new Holiday { HolidayName = txtName.Text, Date = dt.SelectedDate.Value, isYearly = Convert.ToBoolean(isYearly.IsChecked), Description = txtDesc.Text }; AuditTrail at = new AuditTrail { EmployeeID = UserID, DateAndTime = DateTime.Now, Action = "Added Holiday " + txtName.Text }; ctx.AuditTrails.Add(at); ctx.Holidays.Add(h); ctx.SaveChanges(); System.Windows.MessageBox.Show("Holiday has been successfully Added", "Information", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } else { using (var ctx = new finalContext()) { var h = ctx.Holidays.Find(hId); h.HolidayName = txtName.Text; h.Date = dt.SelectedDate.Value; h.isYearly = Convert.ToBoolean(isYearly.IsChecked); h.Description = txtDesc.Text; var mC = ctx.MPaymentInfoes.Where(x => x.DueDate.Month == dt.SelectedDate.Value.Month && x.DueDate.Day == dt.SelectedDate.Value.Day).Count(); if (mC > 0) { System.Windows.MessageBox.Show("Payments on the given day will be automatically adjusted", "Information", MessageBoxButton.OK, MessageBoxImage.Information); var ps = from x in ctx.MPaymentInfoes select x; DateTime idt1 = dt.SelectedDate.Value; DateTime idt = DateAndTime.DateAdd(DateInterval.Day, 1, idt1); bool isHoliday = true; while (isHoliday == true || idt.Date.DayOfWeek.ToString() == "Saturday" || idt.Date.DayOfWeek.ToString() == "Sunday") { if (idt.Date.DayOfWeek.ToString() == "Saturday") { idt = DateAndTime.DateAdd(DateInterval.Day, 2, idt); } else if (idt.Date.DayOfWeek.ToString() == "Sunday") { idt = DateAndTime.DateAdd(DateInterval.Day, 1, idt); } var myC = ctx.Holidays.Where(x => x.Date.Month == idt.Date.Month && x.Date.Day == idt.Date.Day && x.isYearly == true).Count(); if (myC > 0) { idt = DateAndTime.DateAdd(DateInterval.Day, 1, idt); isHoliday = true; } else { myC = ctx.Holidays.Where(x => x.Date.Month == idt.Date.Month && x.Date.Day == idt.Date.Day && x.Date.Year == idt.Date.Year && x.isYearly == !true).Count(); if (myC > 0) { idt = DateAndTime.DateAdd(DateInterval.Day, 1, idt); isHoliday = true; } else { isHoliday = false; } } } foreach (var x in ps) { if (isYearly.IsChecked == true) { if (x.DueDate.Month == idt1.Date.Month && x.DueDate.Day == idt1.Date.Day) { x.DueDate = idt; } } else { if (x.DueDate.Month == idt1.Date.Month && x.DueDate.Day == idt1.Date.Day && x.DueDate.Year == idt1.Date.Year) { x.DueDate = idt; } } } } AuditTrail at = new AuditTrail { EmployeeID = UserID, DateAndTime = DateTime.Now, Action = "Updated Holiday " + txtName.Text }; ctx.AuditTrails.Add(at); ctx.SaveChanges(); System.Windows.MessageBox.Show("Holiday Successfully Updated", "Information", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } //} //catch (Exception ex) //{ // System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); // return; //} }
protected void btnAlert_Click(object sender, EventArgs e) { try { using (var ctx = new finalContext()) { int n = Convert.ToInt32(Session["ID"]); var lon = ctx.TemporaryLoanApplications.Where(x => x.ClientID == n).First(); ctx.TemporaryLoanApplications.Remove(lon); ctx.SaveChanges(); string myStringVariable = "Loan application has been successfuly cancelled"; ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true); } } catch (Exception) { Response.Redirect("/Index.aspx"); } }
protected void btnRegister_Click1(object sender, EventArgs e) { try { if (txtCaptcha.Text == "") { lblCaptcha.Visible = true; return; } CaptchaControl1.ValidateCaptcha(txtCaptcha.Text); if (!CaptchaControl1.UserValidated) { lblCaptcha.Visible = true; return; } else { lblCaptcha.Visible = !true; } DateTime bDay = Convert.ToDateTime(txtBirthday.Text); using (var ctx = new finalContext()) { var ctr = ctx.Clients.Where(x => x.FirstName == txtFirstName.Text && x.LastName == txtLastName.Text && x.MiddleName == txtMiddleName.Text && x.Suffix == txtSuffix.Text && x.Birthday == bDay).Count(); if (ctr > 0) { lblExists.Visible = true; return; } else { string age = "0"; int years = DateTime.Now.Year - bDay.Year; if (bDay.AddYears(years) > DateTime.Now) ; years--; age = years.ToString(); int iAge = Convert.ToInt32(age); if (iAge < 18 || iAge > 65) { lblExists.Text = "Age must be between 18 an 65"; lblExists.Visible = true; return; } if (txtPassword.Text != txtConfirm.Text) { lblExists.Text = "Passwords didn't match"; lblExists.Visible = true; return; } if (txtPassword.Text.Length < 8) { lblExists.Text = "Password length must be at least 8"; lblExists.Visible = true; return; } if (txtUsername.Text.Length < 8) { lblExists.Text = "Username length must be at least 8"; lblExists.Visible = true; return; } if(txtBirthday.Text == "" || txtEmail.Text == "" || txtFirstName.Text == "" || txtLastName.Text == "" || txtUsername.Text == "") { lblExists.Text = "Please input all required fields"; lblExists.Visible = true; return; } var c = ctx.Clients.Where(x => x.Username == txtUsername.Text).Count(); if (c > 0) { lblExists.Text = "Username has been already used"; lblExists.Visible = true; return; } c = ctx.Clients.Where(x => x.Email == txtEmail.Text).Count(); if (c > 0) { lblExists.Text = "Email has been already used"; lblExists.Visible = true; return; } var result = "asd"; do { var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; var random = new Random(); result = new string( Enumerable.Repeat(chars, 15) .Select(s => s[random.Next(s.Length)]) .ToArray()); c = ctx.Clients.Where(x => x.TrackingNumber == result).Count(); } while (c > 0); Client clt = new Client { Active = true, Birthday = bDay, Email = txtEmail.Text, FirstName = txtFirstName.Text, isConfirmed = false, LastName = txtLastName.Text, MiddleName = txtMiddleName.Text, Password = txtPassword.Text, Sex = cmbGender.Text, SSS = txtSSS.Text, Username = txtUsername.Text, Status = cmbStatus.Text, Suffix = txtSuffix.Text, TIN = txtTIN.Text, isRegistered = false, TrackingNumber = result }; ClientContact con = new ClientContact { ContactNumber = 1, Primary = true, Contact = txtContact.Text }; iClientExpiration exp = new iClientExpiration { ExpirationDate = DateTime.Now.AddMonths(1) }; ctx.Clients.Add(clt); ctx.ClientContacts.Add(con); ctx.iClientExpirations.Add(exp); ctx.SaveChanges(); Session["newID"] = clt.ClientID.ToString(); Response.Redirect("/RegistrationSuccess.aspx"); } } } catch (Exception) { //Response.Redirect("/Index.aspx"); } }
private void btnRelease_Click(object sender, RoutedEventArgs e) { try { if (status == "Releasing") { double max = 0; double min = 0; using (var ctx = new finalContext()) { var lon = ctx.Loans.Find(lId); var ser = ctx.Services.Find(lon.ServiceID); max = ser.MaxTerm; min = ser.MinTerm; if (Convert.ToDouble(txtTerm.Text) > max || Convert.ToDouble(txtTerm.Text) < min) { System.Windows.MessageBox.Show("Term must not be greater than the maximum term(" + ser.MaxTerm + " mo.) OR less than the minimum term(" + ser.MinTerm + " mo.)", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } max = ser.MaxValue; min = ser.MinValue; if (Convert.ToDouble(txtAmt.Text) > max || Convert.ToDouble(txtAmt.Text) < min) { System.Windows.MessageBox.Show("Principal amount must not be greater than the maximum loanable amount OR less than the minimum loanable amount", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } } if (Convert.ToDouble(txtAmt.Text) > Convert.ToDouble(lblPrincipal.Content)) { MessageBox.Show("Principal amount must not be greater than the maximum loanable amount", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if(ciId == 0) { MessageBox.Show("Please assign a collector for this loan", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } MessageBoxResult mr = MessageBox.Show("Are you sure you want to process this transaction?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question); if (mr == MessageBoxResult.Yes) { using (var ctx = new finalContext()) { int bId = 0; var lon = ctx.Loans.Find(lId); lon.Status = "Released"; lon.Mode = cmbMode.Text; lon.Term = Convert.ToInt32(txtTerm.Text); lon.CollectortID = ciId; var cn = ctx.Services.Find(lon.ServiceID); double co = cn.AgentCommission / 100; double cm = Convert.ToDouble(txtAmt.Text) * co; //MessageBox.Show(cm.ToString()); ReleasedLoan rl = new ReleasedLoan { AgentsCommission = cm, DateReleased = DateTime.Today.Date, LoanID = lId, MonthlyPayment = Convert.ToDouble(lblMonthly.Content), NetProceed = Convert.ToDouble(lblProceed.Content), Principal = Convert.ToDouble(txtAmt.Text), TotalLoan = Convert.ToDouble(lblInt.Content) }; lon.ReleasedLoan = rl; var lo = ctx.GenSOA.Where(x => x.PaymentNumber == 1).First(); int y = 0; MPaymentInfo py = new MPaymentInfo { Amount = Convert.ToDouble(lo.Amount), BalanceInterest = 0, DueDate = lo.PaymentDate, LoanID = lId, PaymentNumber = 1, PaymentStatus = "Pending", PreviousBalance = 0, RemainingLoanBalance = Convert.ToDouble(lo.RemainingBalance), TotalAmount = Convert.ToDouble(lo.Amount), TotalBalance = 0 }; ctx.MPaymentInfoes.Add(py); AuditTrail at = new AuditTrail { EmployeeID = UserID, DateAndTime = DateTime.Now, Action = "Released loan (" + lon.Service.Name + ") for client " + lon.Client.FirstName + " " + lon.Client.MiddleName + " " + lon.Client.LastName + " " + lon.Client.Suffix }; ctx.AuditTrails.Add(at); ctx.SaveChanges(); printSOA(); MessageBox.Show("Transaction has been successfully processed", "Information", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } } else if (status == "UReleasing") { using (var ctx = new finalContext()) { var lon = ctx.Loans.Find(lId); lon.CollectortID = ciId; AuditTrail at = new AuditTrail { EmployeeID = UserID, DateAndTime = DateTime.Now, Action = "Updated Released loan (" + lon.Service.Name + ") for client " + lon.Client.FirstName + " " + lon.Client.MiddleName + " " + lon.Client.LastName + " " + lon.Client.Suffix }; ctx.AuditTrails.Add(at); ctx.SaveChanges(); MessageBox.Show("Transaction has been successfully updated", "Information", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } } catch (Exception ex) { System.Windows.MessageBox.Show("Incorrect Format on some Fields / Incomplete Input(s)", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } }
private void checkDue() { try { using (var ctx = new finalContext()) { var lon = from lo in ctx.FPaymentInfo where lo.PaymentDate <= DateTime.Today.Date && (lo.PaymentStatus == "Pending" || lo.PaymentStatus == "On Hold") select lo; foreach (var item in lon) { var ctr = ctx.FPaymentInfo.Where(x => (x.PaymentDate <= DateTime.Today.Date && x.LoanID == item.LoanID) && (x.PaymentStatus == "Due" || x.PaymentStatus == "Returned" || x.PaymentStatus == "Due/Pending" || x.PaymentStatus == "Deposited")).Count(); if (ctr == 0) { item.PaymentStatus = "Due"; } else { item.PaymentStatus = "Due/Pending"; } } var dep = from d in ctx.FPaymentInfo where d.PaymentStatus == "Due" select d; foreach (var item in dep) { var ctr = ctx.FPaymentInfo.Where(x => x.LoanID == item.LoanID && x.PaymentStatus == "Deposited").Count(); if (ctr != 0) { item.PaymentStatus = "Due/Pending"; } } var lons = from lo in ctx.Loans where lo.Status == "Released" && lo.Service.Department == "Financing" select lo; foreach (var item in lons) { var ctr1 = ctx.FPaymentInfo.Where(x => x.LoanID == item.LoanID && x.PaymentStatus == "Cleared").Count(); var ctr2 = ctx.FPaymentInfo.Where(x => x.LoanID == item.LoanID).Count(); if (ctr1 == ctr2) { item.Status = "Paid"; PaidLoan pl = new PaidLoan { LoanID = item.LoanID, DateFinished = DateTime.Today.Date }; ctx.PaidLoans.Add(pl); } } //MICRO var mLoans = from m in ctx.MPaymentInfoes where m.DueDate < DateTime.Today.Date && m.PaymentStatus == "Pending" select m; DateTime dt; DateTime dt2; int Interval = 0; DateInterval dInt = DateInterval.Day; foreach (var itm in mLoans) { dt = itm.DueDate; itm.PaymentStatus = "Unpaid"; itm.TotalPayment = 0; var ser = ctx.Services.Find(itm.Loan.ServiceID); var iAmt = itm.TotalAmount; //var ln = ctx.Loans.Find(itm.LoanID); double cRem = itm.RemainingLoanBalance; /*var rc = ctx.MPaymentInfoes.Where(x => x.LoanID == itm.LoanID && x.PaymentStatus == "Paid").Count(); if (rc > 0) { var re = from x in ctx.MPaymentInfoes where x.LoanID == itm.LoanID && x.PaymentStatus == "Paid" select x; foreach (var item in re) { cRem = cRem - itm.TotalPayment; } }*/ double ciRate = ser.LatePaymentPenalty / 100; double ctRate = itm.TotalAmount * ciRate; double ctBalance = itm.TotalAmount; //System.Windows.MessageBox.Show(ciRate.ToString()); //System.Windows.MessageBox.Show(ctRate.ToString()); int n = itm.PaymentNumber; while (dt < DateTime.Today.Date) { String value = itm.Loan.Mode; if (value == "Semi-Monthly") { Interval = 15; dInt = DateInterval.Day; } else if (value == "Weekly") { Interval = 7; dInt = DateInterval.Day; } else if (value == "Daily") { Interval = 1; dInt = DateInterval.Day; } dt = DateAndTime.DateAdd(dInt, Interval, dt); bool isHoliday = true; while (isHoliday == true || dt.Date.DayOfWeek.ToString() == "Saturday" || dt.Date.DayOfWeek.ToString() == "Sunday") { if (dt.Date.DayOfWeek.ToString() == "Saturday") { dt = DateAndTime.DateAdd(DateInterval.Day, 2, dt); } else if (dt.Date.DayOfWeek.ToString() == "Sunday") { dt = DateAndTime.DateAdd(DateInterval.Day, 1, dt); } var myC = ctx.Holidays.Where(x => x.Date.Month == dt.Date.Month && x.Date.Day == dt.Date.Day && x.isYearly == true).Count(); if (myC > 0) { dt = DateAndTime.DateAdd(DateInterval.Day, 1, dt); isHoliday = true; } else { myC = ctx.Holidays.Where(x => x.Date.Month == dt.Date.Month && x.Date.Day == dt.Date.Day && x.Date.Year == dt.Date.Year && x.isYearly == !true).Count(); if (myC > 0) { dt = DateAndTime.DateAdd(DateInterval.Day, 1, dt); isHoliday = true; } else { isHoliday = false; } } } String str = ""; double tRate = ctRate; str = tRate.ToString("N2"); tRate = Convert.ToDouble(str); //System.Windows.MessageBox.Show(tRate.ToString()); double tBalance = ctBalance + tRate; str = tBalance.ToString("N2"); tBalance = Convert.ToDouble(str); double tAmount = itm.Amount + tBalance; str = tAmount.ToString("N2"); tAmount = Convert.ToDouble(str); ctBalance = tAmount; ctRate = ctBalance * ciRate; double tRem = cRem + tRate; str = tRem.ToString("N2"); tRem = Convert.ToDouble(str); cRem = tRem; dt2 = DateAndTime.DateAdd(dInt, Interval, dt); String st = "Unpaid"; if (dt2 > DateTime.Today.Date) st = "Pending"; MPaymentInfo mpi = null; if (tAmount <= tRem) { mpi = new MPaymentInfo { PaymentNumber = n + 1, Amount = itm.Amount, TotalBalance = tBalance, BalanceInterest = tRate, DueDate = dt, ExcessBalance = 0, LoanID = itm.LoanID, PaymentStatus = st, TotalAmount = tAmount, RemainingLoanBalance = tRem, PreviousBalance = iAmt }; ctx.MPaymentInfoes.Add(mpi); } else { if (itm.PaymentStatus == "Unpaid") { double tPaid = 0; var m1 = from m in ctx.MPaymentInfoes where m.LoanID == itm.LoanID && m.PaymentStatus == "Paid" select m; foreach (var i in m1) { tPaid = tPaid + i.TotalPayment; } var c = ctx.PassedToCollectors.Where(x => x.LoanID == itm.LoanID).Count(); if (c < 1) { using (var ctx2 = new finalContext()) { PassedToCollector pc = new PassedToCollector { DatePassed = DateTime.Today.Date, LoanID = itm.LoanID, RemainingBalance = tRem, TotalPassedBalance = tRem, TotalPaidBeforePassing = tPaid }; var l1 = ctx2.Loans.Find(itm.LoanID); l1.Status = "Under Collection"; ctx2.PassedToCollectors.Add(pc); ctx2.SaveChanges(); } } } } iAmt = tAmount; n++; } } ctx.SaveChanges(); } } catch (Exception ex) { System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } }
private void btnSave_Click(object sender, RoutedEventArgs e) { try { if (txtPosition.Text == "Administrator") { System.Windows.MessageBox.Show("Administrator cannot be used as position name", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (status == "Add") { using (var ctx = new finalContext()) { var ctr = ctx.Positions.Where(x => x.PositionName == txtPosition.Text).Count(); if (ctr > 0) { System.Windows.MessageBox.Show("Position already exists.", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } Domain.Position pos = new Domain.Position { PositionName = txtPosition.Text, Description = txtDesc.Text }; PositionScope scp = new PositionScope { MAgent = false, MClient = false, MHoliday = false, MBank = false, MEmployee = false, MPosition = false, MRegistration = false, MService = false, TApplication = false, TApproval = false, TCollection = false, TManageClosed = false, TOnlineConfirmation = false, TPaymentAdjustment = false, TPayments = false, TReleasing = false, TResturcture = false, UArchive = false, UBackUp = false, UOnlineSettings = false, UReports = false, UScopes = false, UStatistics = false, UUserAccounts = false }; ctx.Positions.Add(pos); AuditTrail at = new AuditTrail { EmployeeID = UserID, DateAndTime = DateTime.Now, Action = "Added new Position " + txtPosition.Text }; ctx.AuditTrails.Add(at); ctx.SaveChanges(); scp.PositionID = pos.PositionID; ctx.PositionScopes.Add(scp); ctx.SaveChanges(); System.Windows.MessageBox.Show("Record has been successfully added", "Information", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } else { using (var ctx = new finalContext()) { Domain.Position pos = ctx.Positions.Find(pID); pos.PositionName = txtPosition.Text; pos.Description = txtDesc.Text; AuditTrail at = new AuditTrail { EmployeeID = UserID, DateAndTime = DateTime.Now, Action = "Updated Position " + txtPosition.Text }; ctx.AuditTrails.Add(at); ctx.SaveChanges(); System.Windows.MessageBox.Show("Record has been successfully updated", "Information", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } } catch (Exception ex) { System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } }
private void btnContinue_Click(object sender, RoutedEventArgs e) { try { if (txtCat.Text == "Non Collateral") { using (var ctx = new finalContext()) { var ictr = ctx.Loans.Where(x => x.ClientID == cId && x.Status == "Released" && x.Service.Type == "Non Collateral" && x.Service.Department == iDept).Count(); if (ictr > 0) { System.Windows.MessageBox.Show("Client has an existing Non-Collateral loan. The client can only apply for collateral loan.", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } } if (string.IsNullOrWhiteSpace(txtID.Text)) { System.Windows.MessageBox.Show("Client Must have co-borrower", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } } if (cmbServices.Text == "" || cmbMode.Text == "" || txtAmt.Text == "" || txtTerm.Text == "") { System.Windows.MessageBox.Show("Please complete the required information", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (cboxAgent.IsChecked == true && txtAgent.Text == "") { System.Windows.MessageBox.Show("Please select the agent"); return; } using (var ctx = new finalContext()) { var ser = ctx.Services.Find(servId); if (ser.Type == "Non Collateral" && txtID.Text == "") { System.Windows.MessageBox.Show("Please select the Co-Borrower", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } double val = Convert.ToDouble(txtAmt.Text); if (val > ser.MaxValue || val < ser.MinValue) { System.Windows.MessageBox.Show("Invalid loan ammount", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } var lon = ctx.Loans.Find(lId); if (status == "Renewal") { if (val < lon.ReleasedLoan.TotalLoan) { System.Windows.MessageBox.Show("Amount must be greater than or equal the Total Loan Amount of Previous loan(" + lon.ReleasedLoan.TotalLoan.ToString("N2") + ")", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } } val = Convert.ToDouble(txtTerm.Text); if (val > ser.MaxTerm || val < ser.MinTerm) { System.Windows.MessageBox.Show("Invalid desired term", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } } using (var ctx = new finalContext()) { var ser = ctx.Services.Find(servId); double deduction = 0; var ded = from de in ctx.Deductions where de.ServiceID == servId select de; foreach (var item in ded) { deduction = deduction + item.Percentage; } deduction = deduction + ser.AgentCommission; if (ser.Type == "Collateral") { cbId = 0; } if (status == "Add" || status == "Confirmation" || status=="Renewal") { if (status == "Confirmation") { Loan loan = new Loan { }; LoanApplication la = new LoanApplication { AmountApplied = Convert.ToDouble(txtAmt.Text), DateApplied = DateTime.Now.Date }; if (cboxAgent.IsChecked == true) { loan = new Loan { CI = ciId, AgentID = agentId, ClientID = cId, CoBorrower = cbId, ServiceID = servId, Status = "Applied", Term = Convert.ToInt32(txtTerm.Text), LoanApplication = la, Mode = cmbMode.Text, ApplicationType = "Online" }; } else { string str = "Applied"; loan = new Loan { CI = ciId, AgentID = 0, ClientID = cId, CoBorrower = cbId, ServiceID = servId, Status = str, Term = Convert.ToInt32(txtTerm.Text), LoanApplication = la, Mode = cmbMode.Text , ApplicationType = "Online"}; } ctx.Loans.Add(loan); ctx.SaveChanges(); string folderName = @"F:\Loan Files"; string pathString = System.IO.Path.Combine(folderName, "Loan " + loan.LoanID.ToString()); if (!Directory.Exists(pathString)) { System.IO.Directory.CreateDirectory(pathString); } else { Directory.Delete(pathString, true); System.IO.Directory.CreateDirectory(pathString); } using (var ictx = new finalContext()) { var ln = ictx.TemporaryLoanApplications.Find(lId); string pathString2 = @"F:\Loan Files\Applications Online\Application " + lId.ToString(); if (Directory.Exists(pathString2)) { Copy(pathString2, pathString); Directory.Delete(pathString2, true); } ictx.TemporaryLoanApplications.Remove(ln); ictx.SaveChanges(); System.Windows.MessageBox.Show("Loan has been successfuly confirmed", "Information", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } else { Loan loan = new Loan { }; LoanApplication la = new LoanApplication { AmountApplied = Convert.ToDouble(txtAmt.Text), DateApplied = DateTime.Now.Date }; if (cboxAgent.IsChecked == true) { loan = new Loan { CI = ciId, AgentID = agentId, ClientID = cId, CoBorrower = cbId, ServiceID = servId, Status = "Applied", Term = Convert.ToInt32(txtTerm.Text), LoanApplication = la, Mode = cmbMode.Text, ApplicationType = "Walk-In" }; } else { string str = "Applied"; if (status == "Renewal") str = "Applied for Renewal"; loan = new Loan { CI = ciId, AgentID = 0, ClientID = cId, CoBorrower = cbId, ServiceID = servId, Status = str, Term = Convert.ToInt32(txtTerm.Text), LoanApplication = la, Mode = cmbMode.Text, ApplicationType = "Walk-In" }; } //AuditTrail at = new AuditTrail { EmployeeID = UserID, DateAndTime = DateTime.Now, Action = "Processed new loan application (" + cmbServices.Text + ") for client " + txtFName.Text + " " + txtMName.Text + " " + txtLName.Text + " " + txtSuffix.Text }; //ctx.AuditTrails.Add(at); ctx.Loans.Add(loan); ctx.SaveChanges(); if (status == "Renewal") { LoanRenewal lr = new LoanRenewal { LoanID = lId, newLoanID = loan.LoanID, Status = "Pending" }; ctx.LoanRenewals.Add(lr); ctx.SaveChanges(); } string folderName = @"F:\Loan Files"; string pathString = System.IO.Path.Combine(folderName, "Loan " + loan.LoanID.ToString()); if (!Directory.Exists(pathString)) { System.IO.Directory.CreateDirectory(pathString); } else { Directory.Delete(pathString, true); System.IO.Directory.CreateDirectory(pathString); } if (status == "Renewal") { string pathString2 = @"F:\Loan Files\Loan " + lId.ToString(); if (Directory.Exists(pathString2)) { Copy(pathString2, pathString); Directory.Delete(pathString2, true); } } System.Windows.MessageBox.Show("Loan has been successfuly applied", "Information", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } else { System.Windows.Forms.DialogResult dr = System.Windows.Forms.MessageBox.Show("Are you sure you want to update this loan?", "Question", MessageBoxButtons.YesNo); if (dr == System.Windows.Forms.DialogResult.Yes) { var ln = ctx.Loans.Find(lId); if (cboxAgent.IsChecked == true) { ln.AgentID = agentId; ln.CoBorrower = cbId; ln.Mode = cmbMode.Text; ln.CI = ciId; ln.LoanApplication.AmountApplied = Convert.ToDouble(txtAmt.Text); ln.Term = Convert.ToInt32(txtTerm.Text); } else { ln.CoBorrower = cbId; ln.Mode = cmbMode.Text; ln.CI = ciId; ln.LoanApplication.AmountApplied = Convert.ToDouble(txtAmt.Text); ln.Term = Convert.ToInt32(txtTerm.Text); } //AuditTrail at = new AuditTrail { EmployeeID = UserID, DateAndTime = DateTime.Now, Action = "Updated loan application (" + cmbServices.Text + ") for client " + txtFName.Text + " " + txtMName.Text + " " + txtLName.Text + " " + txtSuffix.Text }; //ctx.AuditTrails.Add(at); ctx.SaveChanges(); System.Windows.MessageBox.Show("Record has been successfully updated", "Information", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } } } catch (Exception ex) { System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } }
private void btnRecord_Click(object sender, RoutedEventArgs e) { //try //{ double amt = 0; try { amt = Convert.ToDouble(txtAmt.Text); amt = Convert.ToDouble(amt.ToString("N2")); } catch(Exception) { amt = 0; } if (amt > Convert.ToDouble(lblTotalLoan.Content)) { System.Windows.MessageBox.Show("Amount must not be greater that the remaining amount", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (amt < 1) { System.Windows.MessageBox.Show("Amount must be greater that 1", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } double cPayment = (Convert.ToDouble(lblTotalLoan.Content) - Convert.ToDouble(lblExcessive.Content)); if (cPayment < 0 || cPayment < Convert.ToDouble(lblTotalLoan.Content)) { cPayment = Convert.ToDouble(lblTotalLoan.Content); } if (amt > cPayment ) { System.Windows.MessageBox.Show("Amount must not be greater that the remaining amount", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (amt <= Convert.ToDouble(lblTotal.Content)) { //System.Windows.MessageBox.Show("Dito"); using (var ctx = new finalContext()) { int lID = Convert.ToInt32(txtID.Text); var py = ctx.MPaymentInfoes.Where(x => x.LoanID == lID && x.PaymentStatus == "Pending").First(); DateInterval dInt = new DateInterval(); int Interval = 0; String value = py.Loan.Mode; if (value == "Semi-Monthly") { Interval = 15; dInt = DateInterval.Day; } else if (value == "Weekly") { Interval = 7; dInt = DateInterval.Day; } else if (value == "Daily") { Interval = 1; dInt = DateInterval.Day; } DateTime dt = py.DueDate; dt = DateAndTime.DateAdd(dInt, Interval, dt); bool isHoliday = true; while (isHoliday == true || dt.Date.DayOfWeek.ToString() == "Saturday" || dt.Date.DayOfWeek.ToString() == "Sunday") { if (dt.Date.DayOfWeek.ToString() == "Saturday") { dt = DateAndTime.DateAdd(DateInterval.Day, 2, dt); } else if (dt.Date.DayOfWeek.ToString() == "Sunday") { dt = DateAndTime.DateAdd(DateInterval.Day, 1, dt); } var myC = ctx.Holidays.Where(x => x.Date.Month == dt.Date.Month && x.Date.Day == dt.Date.Day && x.isYearly == true).Count(); if (myC > 0) { dt = DateAndTime.DateAdd(DateInterval.Day, 1, dt); isHoliday = true; } else { myC = ctx.Holidays.Where(x => x.Date.Month == dt.Date.Month && x.Date.Day == dt.Date.Day && x.Date.Year == dt.Date.Year && x.isYearly == !true).Count(); if (myC > 0) { dt = DateAndTime.DateAdd(DateInterval.Day, 1, dt); isHoliday = true; } else { isHoliday = false; } } } var ser = ctx.Services.Find(py.Loan.ServiceID); double interest = ser.LatePaymentPenalty / 100; double payment = Convert.ToDouble(amt.ToString("N2")); double pbal = Convert.ToDouble((py.TotalAmount - payment).ToString("N2")); double balInt = Convert.ToDouble((pbal * interest).ToString("N2")); double totalBal = Convert.ToDouble((pbal + balInt).ToString("N2")); double total = Convert.ToDouble((totalBal + py.Amount).ToString("N2")); double re = Convert.ToDouble(lblTotalLoan.Content); double rem = Convert.ToDouble((re - payment).ToString("N2")); if (rem < total) { rem = 0; total = totalBal; } py.TotalPayment = amt; py.PaymentDate = DateTime.Now.Date; py.PaymentStatus = "Paid"; int n = py.PaymentNumber + 1; if ((amt == Convert.ToDouble(lblTotal.Content) && rem <= py.Amount) || rem < 0) { System.Windows.MessageBox.Show("The Loan has been successfully finished!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); var lon = ctx.Loans.Find(lID); lon.Status = "Paid"; py.TotalPayment = amt; py.PaymentDate = DateTime.Now.Date; py.PaymentStatus = "Paid"; py.RemainingLoanBalance = 0; PaidLoan pl = new PaidLoan { LoanID = lID, DateFinished = DateTime.Today.Date }; ctx.PaidLoans.Add(pl); goto here; } MPaymentInfo mp = new MPaymentInfo { Amount = py.Amount, BalanceInterest = balInt, DueDate = dt, ExcessBalance = 0, LoanID = lID, PaymentNumber = n, PaymentStatus = "Pending", PreviousBalance = pbal, RemainingLoanBalance = rem, TotalAmount = total, TotalBalance = totalBal }; ctx.MPaymentInfoes.Add(mp); here: ctx.SaveChanges(); txtID.Text = ""; txtID.Focus(); } } else { using (var ctx = new finalContext()) { int lID = Convert.ToInt32(txtID.Text); var py = ctx.MPaymentInfoes.Where(x => x.LoanID == lID && x.PaymentStatus == "Pending").First(); DateInterval dInt = new DateInterval(); double ex = amt - py.TotalAmount; while (ex > 0) { int Interval = 0; String value = py.Loan.Mode; if (value == "Semi-Monthly") { Interval = 15; dInt = DateInterval.Day; } else if (value == "Weekly") { Interval = 7; dInt = DateInterval.Day; } else if (value == "Daily") { Interval = 1; dInt = DateInterval.Day; } DateTime dt = py.DueDate; dt = DateAndTime.DateAdd(dInt, Interval, dt); bool isHoliday = true; while (isHoliday == true || dt.Date.DayOfWeek.ToString() == "Saturday" || dt.Date.DayOfWeek.ToString() == "Sunday") { if (dt.Date.DayOfWeek.ToString() == "Saturday") { dt = DateAndTime.DateAdd(DateInterval.Day, 2, dt); } else if (dt.Date.DayOfWeek.ToString() == "Sunday") { dt = DateAndTime.DateAdd(DateInterval.Day, 1, dt); } var myC = ctx.Holidays.Where(x => x.Date.Month == dt.Date.Month && x.Date.Day == dt.Date.Day && x.isYearly == true).Count(); if (myC > 0) { dt = DateAndTime.DateAdd(DateInterval.Day, 1, dt); isHoliday = true; } else { myC = ctx.Holidays.Where(x => x.Date.Month == dt.Date.Month && x.Date.Day == dt.Date.Day && x.Date.Year == dt.Date.Year && x.isYearly == !true).Count(); if (myC > 0) { dt = DateAndTime.DateAdd(DateInterval.Day, 1, dt); isHoliday = true; } else { isHoliday = false; } } } double payment = Convert.ToDouble(py.Amount.ToString("N2")); double rem = Convert.ToDouble((py.RemainingLoanBalance - py.TotalAmount).ToString("N2")); double total = Convert.ToDouble((py.Amount - ex).ToString("N2")); ex = Convert.ToDouble(ex.ToString("N2")); double ex2 = ex - py.Amount; ex2 = Convert.ToDouble(ex2.ToString("N2")); string st = ""; int n = py.PaymentNumber + 1; //System.Windows.MessageBox.Show(rem.ToString()); MPaymentInfo mp = new MPaymentInfo(); if (total < 0) { total = py.Amount; st = "Pending"; n = py.PaymentNumber; mp = new MPaymentInfo { Amount = py.Amount, BalanceInterest = 0, DueDate = dt, ExcessBalance = Convert.ToDouble(ex.ToString("N2")), LoanID = lID, PaymentNumber = n, PaymentStatus = st, PreviousBalance = 0, RemainingLoanBalance = rem, TotalAmount = total, TotalBalance = 0, PaymentDate = DateTime.Now.Date }; } else { st = "Pending"; mp = new MPaymentInfo { Amount = py.Amount, BalanceInterest = 0, DueDate = dt, ExcessBalance = Convert.ToDouble(ex.ToString("N2")), LoanID = lID, PaymentNumber = n, PaymentStatus = st, PreviousBalance = 0, RemainingLoanBalance = rem, TotalAmount = total, TotalBalance = 0 }; } ex = Convert.ToDouble(ex.ToString("N2")); if ((rem <= py.Amount && ex >= py.Amount) || rem < 0) { System.Windows.MessageBox.Show("The Loan has been successfully finished!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); var lon = ctx.Loans.Find(lID); lon.Status = "Paid"; py.TotalPayment = amt; py.PaymentDate = DateTime.Now.Date; py.PaymentStatus = "Paid"; PaidLoan pl = new PaidLoan { LoanID = lID, DateFinished = DateTime.Today.Date }; ctx.PaidLoans.Add(pl); mp.PaymentStatus = "Paid"; mp.TotalAmount = py.Amount; mp.ExcessBalance = py.Amount; mp.RemainingLoanBalance = 0; mp.PaymentDate = DateTime.Now.Date; mp.TotalPayment = py.Amount; goto here; } //System.Windows.MessageBox.Show(ex.ToString("N2")); py.TotalPayment = amt; py.PaymentDate = DateTime.Now.Date; py.PaymentStatus = "Paid"; amt = Convert.ToDouble(ex.ToString("N2")); here: ctx.MPaymentInfoes.Add(mp); ctx.SaveChanges(); txtID.Text = ""; txtID.Focus(); try { py = ctx.MPaymentInfoes.Where(x => x.LoanID == lID && x.PaymentStatus == "Pending").First(); } catch (Exception) { return; } ex = ex2; } } } /*} catch (Exception ex) { System.Windows.MessageBox.Show("Runtime Error:" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; }*/ }
private void btnDecline_Click(object sender, RoutedEventArgs e) { try { if (status == "Approval" || status == "Renewal Approval") { wpfLoanDeclining frm = new wpfLoanDeclining(); frm.lId = lId; frm.status = "Renewal"; if (status == "Approval") frm.status = status; frm.UserID = UserID; this.Close(); frm.ShowDialog(); } else if (status == "UApproval") { System.Windows.MessageBoxResult mr = System.Windows.MessageBox.Show("Are you sure you want to update this loan?", "Question", MessageBoxButton.YesNo); if (mr == System.Windows.MessageBoxResult.Yes) { using (var ctx = new finalContext()) { var lon = ctx.Loans.Find(lId); var ctr = ctx.Loans.Where(x => x.ClientID == lon.ClientID && (x.Status == "Applied" || x.Status == "Released" || x.Status == "Approved") && x.LoanID != lon.LoanID).Count(); if (lon.Status == "Declined") { if (ctr > 0) { System.Windows.MessageBox.Show("Client cannot have more than one(1) Loan application/Loan", "Notice", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } ctr = ctx.Loans.Where(x => x.ClientID == lon.ClientID && (x.Status == "Closed Account" || x.Status == "Under Collection")).Count(); if (ctr > 0) { System.Windows.MessageBox.Show("Client has bad record due to Closed Account/Unpaid Balance. Unable to process loan.", "Notice", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } ctr = ctx.Loans.Where(x => x.ClientID == lon.ClientID && x.Status == "Released" && x.Service.Department != lon.Service.Department).Count(); if (ctr > 0) { System.Windows.MessageBox.Show("Client has an existing loan on other department", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } ctr = ctx.TemporaryLoanApplications.Where(x => x.ClientID == lon.ClientID).Count(); if (ctr > 0) { System.Windows.MessageBox.Show("Client cannot have another application while having an online application. Please confirm the loan first", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } var c = ctx.Loans.Where(x => (x.Status == "Applied" || x.Status == "Approved" || x.Status == "Released" || x.Status == "Under Collection" || x.Status == "Closed Account") && (x.CoBorrower == lon.ClientID)).Count(); if (c > 0) { System.Windows.MessageBox.Show("Selected Client cannot become a co-borrower since it has an existing loan taht is not yet finished", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } } if (lon.Status == "Approved") { ctx.ApprovedLoans.Remove(lon.ApprovedLoan); } else { ctx.DeclinedLoans.Remove(lon.DeclinedLoan); } lon.Status = "Applied"; ctx.SaveChanges(); System.Windows.MessageBox.Show("Transaction has been voided","Information",MessageBoxButton.OK,MessageBoxImage.Information); this.Close(); } } } } catch (Exception ex) { System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } }
private void Button_Click_1(object sender, RoutedEventArgs e) { try { if (System.Windows.MessageBox.Show("Are you sure you want to remove the confirmation?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { using (var ctx = new finalContext()) { var lon = ctx.Loans.Find(lID); int n = Convert.ToInt32(getRow(dg2, 0)); var rq = ctx.RequirementChecklists.Where(x => x.LoanID == lID && x.Requirement.RequirementNum == n).First(); ctx.RequirementChecklists.Remove(rq); ctx.SaveChanges(); System.Windows.MessageBox.Show("Requirement confirmation has been removed successfully", "Information", MessageBoxButton.OK, MessageBoxImage.Information); rg(); return; } } } catch (Exception ex) { System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } }
private void Button_Click(object sender, RoutedEventArgs e) { try { if (System.Windows.MessageBox.Show("Are you sure you want to confirm this requirement?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { using (var ctx = new finalContext()) { var lon = ctx.Loans.Find(lID); int n = Convert.ToInt32(getRow(dg1,0)); var rq = ctx.Requirements.Where(x=> x.ServiceID == lon.ServiceID && x.RequirementNum == n ).First(); RequirementChecklist rc = new RequirementChecklist { DateConfirmed = DateTime.Now.Date, EmployeeID = UserID, LoanID = lID, RequirementId = rq.RequirementId }; ctx.RequirementChecklists.Add(rc); ctx.SaveChanges(); System.Windows.MessageBox.Show("Requirement confirmation successfull", "Information", MessageBoxButton.OK, MessageBoxImage.Information); rg(); return; } } } catch (Exception ex) { System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } }
private void btnDel_Click(object sender, RoutedEventArgs e) { try { using (var ctx = new finalContext()) { DialogResult dr = System.Windows.Forms.MessageBox.Show("Are you sure you want to delete this record?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == System.Windows.Forms.DialogResult.Yes) { Holiday h = ctx.Holidays.Find(hId); ctx.Holidays.Remove(h); ctx.SaveChanges(); System.Windows.MessageBox.Show("Holiday has been successfuly deleted", "Information", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } } catch (Exception ex) { System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } }
private void btnDel_Click(object sender, RoutedEventArgs e) { try { using (var ctx = new finalContext()) { var ctr = ctx.Employees.Where(x => x.PositionID == pID).Count(); if (ctr > 0) { System.Windows.MessageBox.Show("Position is being used by at least one employee. It cannot be deleted","Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } DialogResult dr = System.Windows.Forms.MessageBox.Show("Are you sure you want to delete this record?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == System.Windows.Forms.DialogResult.Yes) { Domain.Position h = ctx.Positions.Find(pID); ctx.Positions.Remove(h); ctx.SaveChanges(); System.Windows.MessageBox.Show("Holiday has been successfuly deleted", "Information", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } } catch (Exception ex) { System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } }
private void btnPass_Click(object sender, RoutedEventArgs e) { if (cID == 0) { MessageBox.Show("Please assign a collector for this loan", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } MessageBoxResult mr = MessageBox.Show("Are you sure you want to process this transaction? This cannot be undone", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question); if (mr == MessageBoxResult.Yes) { using (var ctx = new finalContext()) { var lon = ctx.Loans.Find(n); lon.Status = "Under Collection";//active int num = ctx.ClosedAccounts.Where(x => x.LoanID == n).Count(); var rmn = from rm in ctx.FPaymentInfo where rm.LoanID == n && rm.PaymentStatus == "Cleared" select rm; double r = 0; foreach (var item in rmn) { r = r + item.Amount; } double remain = lon.ReleasedLoan.TotalLoan - r; PassedToCollector pc = new PassedToCollector { LoanID = n, DatePassed = DateTime.Today.Date, RemainingBalance = remain, TotalPassedBalance = remain, TotalPaidBeforePassing = r }; ctx.PassedToCollectors.Add(pc); lon.CollectortID = cID; AuditTrail at = new AuditTrail { EmployeeID = UserID, DateAndTime = DateTime.Now, Action = "Voided Closed Account for Loan " + lon.LoanID }; ctx.AuditTrails.Add(at); ctx.SaveChanges(); MessageBox.Show("Transaction has been successfully processed", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } } }
public void reset() { try { using (var ctx = new finalContext()) { var lon = ctx.Loans.Find(lId); if (lon.Service.Type == "Collateral") btnCol.Visibility = Visibility.Visible; else btnCol.Visibility = Visibility.Hidden; try { byte[] imageArr; imageArr = lon.Client.Photo; BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.CreateOptions = BitmapCreateOptions.None; bi.CacheOption = BitmapCacheOption.Default; bi.StreamSource = new MemoryStream(imageArr); bi.EndInit(); img.Source = bi; } catch (Exception) { BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = new Uri(AppDomain.CurrentDomain.BaseDirectory + "\\Icons\\myImg.gif"); bitmap.EndInit(); img.Source = bitmap; } lblAmt.Content = lon.ReleasedLoan.Principal.ToString("N2"); string[] mdt = lon.ReleasedLoan.DateReleased.ToString().Split(' '); string d = mdt[0]; lblDt.Content = d; lblMode.Content = lon.Mode; lblTOL.Content = lon.Service.Name; lblType.Content = lon.Service.Type; var ctr = ctx.FPaymentInfo.Where(x => x.LoanID == lId && (x.PaymentStatus == "Pending" || x.PaymentStatus == "Due/Pending")).Count(); if (ctr > 0) { var l = ctx.FPaymentInfo.Where(x => x.LoanID == lId && (x.PaymentStatus == "Pending" || x.PaymentStatus == "Due/Pending")).First(); lblNextP.Content = l.PaymentDate.ToString().Split(' ')[0]; lblPayment.Content = lon.ReleasedLoan.MonthlyPayment.ToString("N2"); double hf = lon.ReleasedLoan.MonthlyPayment * (lon.Service.Holding / 100); lblHF.Content = hf.ToString("N2"); if (status == "Holding") { lbl1.Content = "Hold next cheque"; lbl2.Content = "Unhold held cheque"; var dts = ctx.FPaymentInfo.Where(x => x.LoanID == lId && (x.PaymentStatus == "Pending" || x.PaymentStatus == "On Hold")).First(); var dt = dts.PaymentDate.AddDays(-14); var dt1 = dt.AddDays(11); if (dts.PaymentStatus == "On Hold") { dt = dts.PaymentDate.AddDays(-5); dt1 = dt.AddDays(4); } mdt = dt.ToString().Split(' '); lblSDt.Content = mdt[0]; mdt = dt1.ToString().Split(' '); lblEDt.Content = mdt[0]; } else if (status == "Adjustment") { lbl1.Content = "Adjust Payment"; lbl2.Content = "Void Adjustment"; var ctr1 = ctx.AdjustedLoans.Where(x => x.LoanID == lId).Count(); if (ctr1 > 0) { btnUpdate.Visibility = Visibility.Hidden; btnVoid.Visibility = Visibility.Visible; } else { btnUpdate.Visibility = Visibility.Visible; btnVoid.Visibility = Visibility.Hidden; } } else if (status == "Restructure") { btnUpdate.Content = "Restructure Loan"; btnVoid.Visibility = Visibility.Hidden; /*btnVoid.Content = "Void Adjustment"; var ctr1 = ctx.AdjustedLoans.Where(x => x.LoanID == lId).Count(); if (ctr1 > 0) { btnUpdate.Visibility = Visibility.Hidden; btnVoid.Visibility = Visibility.Visible; } else { btnUpdate.Visibility = Visibility.Visible; btnVoid.Visibility = Visibility.Hidden; }*/ } else { lblS.Visibility = Visibility.Hidden; lblE.Visibility = Visibility.Hidden; lblSDt.Content = ""; lblEDt.Content = ""; } } else { lblNextP.Content = "-"; lblPayment.Content = "-"; lblHF.Content = "-"; } var rmn = from rm in ctx.FPaymentInfo where rm.LoanID == lId && rm.PaymentStatus == "Cleared" select rm; double r = 0; foreach (var item in rmn) { r = r + item.Amount; } double remain = lon.ReleasedLoan.TotalLoan - r; lblRemaining.Content = remain.ToString("N2"); if (status != "Holding") { lblS.Visibility = Visibility.Hidden; lblE.Visibility = Visibility.Hidden; lblSDt.Content = ""; lblEDt.Content = ""; } var c2 = ctx.RestructuredLoans.Where(x => x.NewLoanID == lon.LoanID).Count(); if (c2 > 0) { var lon2 = ctx.RestructuredLoans.Where(x => x.NewLoanID == lon.LoanID).First(); lblRes2.Content = "Amount Restructured: "; lblAmt.Content = lon2.Loan.ReleasedLoan.TotalLoan; } checkDue(); var chqs = from ge in ctx.FPaymentInfo where ge.LoanID == lId select new { No = ge.PaymentNumber, ChequeID = ge.ChequeInfo, TotalPayment = ge.Amount, ChequeDueDate = ge.ChequeDueDate, PaymentDate = ge.PaymentDate, Status = ge.PaymentStatus, DateCleared = ge.ClearCheque.DateCleared }; ctx.Database.ExecuteSqlCommand("delete from dbo.ViewLoans"); if (iDept == "Micro Business") { try { var re1 = ctx.MPaymentInfoes.Where(x => x.LoanID == lId && x.PaymentStatus == "Pending").First(); double remain1 = re1.RemainingLoanBalance; lblRemaining.Content = remain1.ToString("N2"); } catch(Exception) { lblRemaining.Content = "0.00"; } var pys = from p in ctx.MPaymentInfoes where p.LoanID == lId select new { No = p.PaymentNumber, Amount = p.Amount, PrevBalance = p.PreviousBalance, PrevBalanceInterest = p.BalanceInterest, TotalBalance = p.TotalBalance, ExcessiveBalance = p.ExcessBalance, TotalAmount = p.TotalAmount, DueDate = p.DueDate, RemaingBalance = p.RemainingLoanBalance, TotalPayment = p.TotalPayment, PaymentDate = p.PaymentDate, Status = p.PaymentStatus }; dg.ItemsSource = pys.ToList(); } else { foreach (var i in chqs) { string s; string[] dtCleared = null; string myStr; if (i.DateCleared != null) { s = i.DateCleared.ToString(); dtCleared = s.Split(' '); myStr = dtCleared[0]; } else { myStr = ""; } s = i.PaymentDate.ToString(); string[] dtPayment = s.Split(' '); s = i.ChequeDueDate.ToString(); string[] dtDue = s.Split(' '); ViewLoan vl = new ViewLoan { DateCleared = myStr, DueDate = dtDue[0], PaymentDate = dtPayment[0], PaymentInfo = i.ChequeID, PaymentNumber = i.No, Status = i.Status, TotalPayment = i.TotalPayment.ToString("N2") }; ctx.ViewLoans.Add(vl); } ctx.SaveChanges(); var chqs1 = from ge in ctx.ViewLoans select new { No = ge.PaymentNumber, ChequeID = ge.PaymentInfo, TotalPayment = ge.TotalPayment, ChequeDueDate = ge.DueDate, PaymentDate = ge.PaymentDate, Status = ge.Status, DateCleared = ge.DateCleared }; dg.ItemsSource = chqs1.ToList(); } if (status == "View") { btnFull.Visibility = Visibility.Hidden; btnUpdate.Visibility = Visibility.Hidden; btnVoid.Visibility = Visibility.Hidden; } if (lon.Status == "Under Collection") { remain = lon.PassedToCollector.RemainingBalance; lblRemaining.Content = remain.ToString("N2"); lblmd.Content = "Finished Payments: "; lblMode.Content = lon.PassedToCollector.TotalPaidBeforePassing.ToString("N2"); lblh.Content = "Total Collection: "; lblHF.Content = "-"; var ctr1 = ctx.CollectionInfoes.Where(x => x.LoanID == lId).Count(); if (ctr1 > 0) { var pys = from p in ctx.CollectionInfoes where p.LoanID == lId select new { TotalCollection = p.TotalCollection, DateCollected = p.DateCollected }; double tL = 0; foreach (var itm in pys) { tL = tL + itm.TotalCollection; } lblHF.Content = tL.ToString("N2"); dg.ItemsSource = pys.ToList(); } } if (lon.Status == "Paid") lblRemaining.Content = "-"; if (lon.Status == "Released" || lon.Status == "Paid" || lon.Status == "Closed Account" || lon.Status == "Under Collection") { btnSOA.Visibility = Visibility.Visible; if(lon.Service.Department == "Financing") btnrSOA.Visibility = Visibility.Visible; else btnrSOA.Visibility = Visibility.Hidden; } else { btnSOA.Visibility = Visibility.Hidden; btnrSOA.Visibility = Visibility.Hidden; } if (status == "Restructure") { lbl1.Content = "Restructure Loan"; btnVoid.Visibility = Visibility.Hidden; } } } catch (Exception ex) { System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } }
private void btnRet_Click(object sender, RoutedEventArgs e) { try { int n= Convert.ToInt32(getRow(dgEmp, 0)); MessageBoxResult mr = System.Windows.MessageBox.Show("Are you sure you want to retrive this record?","Question",MessageBoxButton.YesNo); if (mr == MessageBoxResult.Yes) { using (var ctx = new finalContext()) { var agt = ctx.Agents.Find(n); agt.Active = true; AuditTrail at = new AuditTrail { EmployeeID = UserID, DateAndTime = DateTime.Now, Action = "Retrieved Agent " + agt.FirstName + " " + agt.MI + " " + agt.LastName + " " + agt.Suffix }; ctx.AuditTrails.Add(at); ctx.SaveChanges(); System.Windows.MessageBox.Show("Record has been successfully Retrieved", "Information", MessageBoxButton.OK, MessageBoxImage.Information); resetGrid(); } } } catch (Exception ex) { System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } }
private void btnVoid_Click(object sender, RoutedEventArgs e) { try { if (status == "UReleasing") { MessageBoxResult mr = System.Windows.MessageBox.Show("Are you sure you want to process this tranction?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question); if (mr == MessageBoxResult.Yes) { if (iDept == "Financing") { using (var ctx = new finalContext()) { var lon = ctx.Loans.Find(lId); lon.Status = "Approved"; ctx.ReleasedLoans.Remove(lon.ReleasedLoan); var lons = from lo in ctx.FPaymentInfo where lo.LoanID == lId select lo; foreach (var item in lons) { ctx.FPaymentInfo.Remove(item); } ctx.SaveChanges(); this.Close(); System.Windows.MessageBox.Show("Transaction has been successfully processed", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } } else { using (var ctx = new finalContext()) { var lon = ctx.Loans.Find(lId); lon.Status = "Approved"; ctx.ReleasedLoans.Remove(lon.ReleasedLoan); var lons = from lo in ctx.MPaymentInfoes where lo.LoanID == lId select lo; foreach (var item in lons) { ctx.MPaymentInfoes.Remove(item); } ctx.SaveChanges(); this.Close(); System.Windows.MessageBox.Show("Transaction has been successfully processed", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } } } } else if (status == "Holding") { using (var ctx = new finalContext()) { var ctrs = ctx.FPaymentInfo.Where(x => x.LoanID == lId && x.PaymentStatus == "On Hold").Count(); if (ctrs < 1) { System.Windows.MessageBox.Show("No cheque to unhold", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } //var dts = ctx.FPaymentInfo.Where(x => x.LoanID == lId && x.PaymentStatus == "Pending").First(); MessageBoxResult mr = System.Windows.MessageBox.Show("Are you sure you want to process this transaction?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question); if (mr == MessageBoxResult.Yes) { var dts = ctx.FPaymentInfo.Where(x => x.LoanID == lId && (x.PaymentStatus == "Pending" || x.PaymentStatus == "On Hold")).First(); var dt = ctx.HeldCheques.Where(x => x.LoanID == lId && x.PaymentNumber == dts.PaymentNumber && x.NewPaymentDate == dts.PaymentDate).First(); dts.PaymentDate = dt.OriginalPaymentDate; dts.PaymentStatus = "Pending"; ctx.HeldCheques.Remove(dt); ctx.SaveChanges(); reset(); System.Windows.MessageBox.Show("Transaction has been successfully processed", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } } } else if (status == "Adjustment") { MessageBoxResult mr = System.Windows.MessageBox.Show("Are you sure you want to process this transaction?", "Question", MessageBoxButton.YesNo); if (mr == MessageBoxResult.Yes) { using (var ctx = new finalContext()) { AdjustedLoan al = ctx.AdjustedLoans.Find(lId); var py = from p in ctx.FPaymentInfo where p.PaymentStatus != "Cleared" && p.LoanID == lId select p; double num = al.Days * (-1); foreach (var item in py) { item.PaymentDate = item.PaymentDate.AddDays(num); } ctx.AdjustedLoans.Remove(al); ctx.SaveChanges(); System.Windows.MessageBox.Show("Transaction has been successfully processed", "Information", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } } } catch (Exception ex) { System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } }
private void btnSave_Click(object sender, RoutedEventArgs e) { try { if (System.Windows.MessageBox.Show("Are you sure you want to save this information?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { using (var ctx = new finalContext()) { //System.Windows.MessageBox.Show(myStr.Count().ToString()); int ctr = 0; var lon = ctx.Loans.Find(lID); var f = from x in ctx.CollateralInformations where x.ServiceID == lon.ServiceID select x; foreach (var item in f) { var cn = ctx.CollateralLoanInfoes.Where(x => x.LoanID == lID && x.CollateralInformationID == item.CollateralInformationID).Count(); if (cn > 0) { var c = ctx.CollateralLoanInfoes.Where(x => x.LoanID == lID && x.CollateralInformationID == item.CollateralInformationID).First(); c.Value = textarray[ctr].Text; } else { var c = ctx.CollateralInformations.Where(x => x.ServiceID == lon.ServiceID && x.Field == item.Field).First(); CollateralLoanInfo cli = new CollateralLoanInfo { LoanID = lID, CollateralInformationID = c.CollateralInformationID, Value = textarray[ctr].Text }; ctx.CollateralLoanInfoes.Add(cli); } ctr++; } ctx.SaveChanges(); System.Windows.MessageBox.Show("Information has been successfully saved", "Information", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } } catch (Exception ex) { System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } }
private void refr() { //try //{ if (status == "Releasing") { using (var ctx = new finalContext()) { ctx.Database.ExecuteSqlCommand("delete from dbo.GenSOAs"); ctx.SaveChanges(); var lon = ctx.Loans.Find(lId); Double Amt = Convert.ToDouble(txtAmt.Text); //lblPrincipal.Content = Amt.ToString("N2"); txtAmt.Text = Amt.ToString("N2"); txtAmt.SelectionStart = txtAmt.Text.Length - 3; Double TotalInt = lon.Service.Interest * Convert.ToInt32(txtTerm.Text); TotalInt = TotalInt / 100; double ded = lon.Service.AgentCommission; var dec = from de in ctx.Deductions where de.ServiceID == lon.ServiceID select de; foreach (var item in dec) { ded = ded + item.Percentage; } Double Deduction = ded / 100; Double NetProceed = (Convert.ToDouble(txtAmt.Text)) - (Convert.ToDouble(txtAmt.Text) * Deduction); Double WithInt = (Convert.ToDouble(txtAmt.Text)) + (Convert.ToDouble(txtAmt.Text) * TotalInt); lblProceed.Content = NetProceed.ToString("N2"); lblInt.Content = WithInt.ToString("N2"); Double Payment = 0; DateTime dt = DateTime.Today.Date; double Interval = 0; DateInterval dInt = DateInterval.Month; Double Remaining = WithInt; ComboBoxItem typeItem = (ComboBoxItem)cmbMode.SelectedItem; string value = typeItem.Content.ToString(); if (value == "Monthly") { Interval = 1; dInt = DateInterval.Month; Payment = WithInt / Convert.ToInt32(txtTerm.Text); lbl4.Content = "Monthly Payment"; } else if (value == "Semi-Monthly") { Interval = 15; dInt = DateInterval.Day; Payment = WithInt / (Convert.ToInt32(txtTerm.Text) * 2); lbl4.Content = "Semi-Monthly Payment"; } else if (value == "Weekly") { Interval = 7; dInt = DateInterval.Day; Payment = WithInt / (Convert.ToInt32(txtTerm.Text) * 4); } else if (value == "Daily") { Interval = 1; dInt = DateInterval.Day; Payment = WithInt / ((Convert.ToInt32(txtTerm.Text) * 4) * 7); } else if (value == "One-Time Payment") { NetProceed = NetProceed - ((Convert.ToDouble(txtAmt.Text) * TotalInt)); lblProceed.Content = NetProceed.ToString("N2"); lblInt.Content = txtAmt.Text; Remaining = Convert.ToDouble(lblPrincipal.Content); Payment = Remaining; Interval = Convert.ToInt32(txtTerm.Text); dInt = DateInterval.Month; lbl4.Content = "Total Payment"; } dt = DateAndTime.DateAdd(dInt, Interval, dt); int num = 1; double p2 = Payment; while (Remaining > -1) { Remaining = Remaining - Payment; GenSOA soa = new GenSOA { Amount = Payment.ToString("N2"), PaymentDate = dt, PaymentNumber = num, RemainingBalance = Remaining.ToString("N2") }; ctx.GenSOA.Add(soa); num++; if (Remaining <= Payment) { Payment = Remaining; if (Payment < 1) { goto a; } GenSOA soa1 = new GenSOA { Amount = Payment.ToString("N2"), PaymentDate = dt, PaymentNumber = num, RemainingBalance = "0.00" }; ctx.GenSOA.Add(soa1); num++; goto a; } dt = DateAndTime.DateAdd(dInt, Interval, dt); bool isHoliday = true; while (isHoliday == true || dt.Date.DayOfWeek.ToString() == "Saturday" || dt.Date.DayOfWeek.ToString() == "Sunday") { if (dt.Date.DayOfWeek.ToString() == "Saturday") { dt = DateAndTime.DateAdd(DateInterval.Day, 2, dt); } else if (dt.Date.DayOfWeek.ToString() == "Sunday") { dt = DateAndTime.DateAdd(DateInterval.Day, 1, dt); } var myC = ctx.Holidays.Where(x => x.Date.Month == dt.Date.Month && x.Date.Day == dt.Date.Day && x.isYearly == true).Count(); if (myC > 0) { dt = DateAndTime.DateAdd(DateInterval.Day, 1, dt); isHoliday = true; } else { myC = ctx.Holidays.Where(x => x.Date.Month == dt.Date.Month && x.Date.Day == dt.Date.Day && x.Date.Year == dt.Date.Year && x.isYearly == !true).Count(); if (myC > 0) { dt = DateAndTime.DateAdd(DateInterval.Day, 1, dt); isHoliday = true; } else { isHoliday = false; } } } } a: lblMonthly.Content = Payment.ToString("N2"); ctx.SaveChanges(); var gen = from ge in ctx.GenSOA select new { PaymentNumber = ge.PaymentNumber, TotalPayment = ge.Amount, PaymentDate = ge.PaymentDate, RemainingBalance = ge.RemainingBalance }; dgSOA.ItemsSource = gen.ToList(); var c1 = ctx.GenSOA.Count(); p2 = Convert.ToDouble(p2.ToString("N2")); //System.Windows.MessageBox.Show(p2.ToString()); lblInt.Content = (p2 * c1).ToString("N2"); return; } } else if (status == "UReleasing") { using (var ctx = new finalContext()) { var lon = ctx.Loans.Find(lId); var pys = from p in ctx.MPaymentInfoes where p.LoanID == lId select new { No = p.PaymentNumber, Amount = p.Amount, PrevBalance = p.PreviousBalance, PrevBalanceInterest = p.BalanceInterest, TotalBalance = p.TotalBalance, TotalAmount = p.TotalAmount, DueDate = p.DueDate, RemaingBalance = p.RemainingLoanBalance, Status = p.PaymentStatus }; dgSOA.ItemsSource = pys.ToList(); txtAmt.Text = lon.ReleasedLoan.TotalLoan.ToString("N2"); lblMonthly.Content = lon.ReleasedLoan.MonthlyPayment.ToString("N2"); lblPrincipal.Content = txtAmt.Text; lblProceed.Content = lon.ReleasedLoan.NetProceed.ToString("N2"); txtTerm.Text = lon.Term.ToString(); cmbMode.Items.Add(lon.Mode); cmbMode.SelectedItem = lon.Mode; var agt = ctx.Employees.Find(lon.CollectortID); ciId = lon.CollectortID; String str = "(" + ciId + ")" + agt.FirstName + " " + agt.MI + " " + agt.LastName; txtCI.Text = str; } } if (Convert.ToInt16(txtTerm.Text) < 1) { System.Windows.MessageBox.Show("Incorrect Format for term", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } /*} catch (Exception ex) { System.Windows.MessageBox.Show("Incorrect Format on some Fields / Incomplete Input(s)", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; }*/ }
private void btnDelAddress_Click(object sender, RoutedEventArgs e) { using (var ctx = new finalContext()) { try { //for view if (status == "View") { int bankNum = Convert.ToInt32(getRow(dgAddress, 0)); var add1 = ctx.BankAdresses.Where(x => x.BankID == bId && x.BankNum == bankNum).First(); ctx.BankAdresses.Remove(add1); ctx.SaveChanges(); var address = from ad in ctx.BankAdresses where ad.BankID == bId select ad; int ctr = 1; foreach (var item in address) { item.BankNum = ctr; ctr++; } ctx.SaveChanges(); var adds = from ad in ctx.BankAdresses where ad.BankID == bId select new { BankNumber = ad.BankNum, Street = ad.Street, Province = ad.Province, City = ad.City }; dgAddress.ItemsSource = adds.ToList(); return; } var add = ctx.TempAdresses.Find(Convert.ToInt32(getRow(dgAddress, 0))); ctx.TempAdresses.Remove(add); ctx.SaveChanges(); dgAddress.ItemsSource = ctx.TempAdresses.ToList(); reset(); } catch (Exception ex) { System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } } }
protected void btnSave_Click(object sender, EventArgs e) { try { if (txtConfirm.Text != txtNew.Text) { lblCheck.Text = "Password didn't match"; lblCheck.Visible = true; return; } if (txtNew.Text.Length < 8) { lblCheck.Text = "Password length must be at least 8"; lblCheck.Visible = true; return; } using (var ctx = new finalContext()) { int cID = Convert.ToInt32(Session["ID"]); var clt = ctx.Clients.Find(cID); if (clt.Password != txtCurrent.Text) { lblCheck.Text = "Current Password is wrong"; lblCheck.Visible = true; return; } else { clt.Password = txtNew.Text; ctx.SaveChanges(); lblCheck.Text = "Password has been successfully changed!"; lblCheck.Visible = true; } } } catch (Exception) { Response.Redirect("/Index.aspx"); } }
private void btnRenew_Click(object sender, RoutedEventArgs e) { try { foreach (var i in textarray) { if (i.Text.Length != 6) { System.Windows.MessageBox.Show("Please input all cheque numbers", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } bool err; int res; String str = i.Text; err = int.TryParse(str, out res); if (err == false) { System.Windows.MessageBox.Show("Please input the correct format for cheque numbers(Strictly numbers only.)", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } } for (int x = 0; x < textarray.Length; x++) { for (int y = x + 1; y < textarray.Length; y++) { if (textarray[x].Text == textarray[y].Text) { System.Windows.MessageBox.Show("No duplications of cheque numbers", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } } } MessageBoxResult mr = MessageBox.Show("Are you sure you want to process this transaction?", "Question", MessageBoxButton.YesNo); if (mr == MessageBoxResult.Yes) { wpfCheckout frm = new wpfCheckout(); frm.status = "RenewClosed"; frm.lId = lId; frm.ShowDialog(); if (cont == false) { System.Windows.MessageBox.Show("Please pay the Closed Account Penalty first", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } using (var ctx = new finalContext()) { var bk = ctx.Banks.Where(x => x.BankName == cmbBank.Text).First(); int bId = bk.BankID; var lon = ctx.Loans.Find(lId); lon.Status = "Released";//active lon.BankID = bId; var ch = from c in ctx.FPaymentInfo where c.LoanID == lId && c.PaymentStatus == "Void" select c; int Interval = 0; DateInterval dInt = new DateInterval(); if (lon.Mode == "Monthly") { Interval = 1; dInt = DateInterval.Month; } else if (lon.Mode == "Semi-Monthly") { Interval = 15; dInt = DateInterval.Day; } else if (lon.Mode == "Weekly") { Interval = 7; dInt = DateInterval.Day; } else if (lon.Mode == "Daily") { Interval = 1; dInt = DateInterval.Day; } /*else if (cmbMode.Text == "One-Time Payment") { NetProceed = NetProceed - ((Convert.ToDouble(txtAmt.Text) * TotalInt)); lblProceed.Content = NetProceed.ToString("N2"); lblInt.Content = txtAmt.Text; Remaining = Convert.ToDouble(lblPrincipal.Content); Payment = Remaining; Interval = Convert.ToInt32(txtTerm.Text); dInt = DateInterval.Month; lbl4.Content = "Total Payment"; }*/ DateTime dt = dtPcker.SelectedDate.Value.Date; int num = 0; foreach (var item in ch) { item.ChequeInfo = textarray[num].Text; item.ChequeDueDate = dt; item.PaymentDate = dt; item.PaymentStatus = "Pending"; dt = DateAndTime.DateAdd(dInt, Interval, dt); num++; } var cc = ctx.ClosedAccounts.Where(x => x.LoanID == lId && x.isPaid == false).First(); cc.isPaid = true; AuditTrail at = new AuditTrail { EmployeeID = UserID, DateAndTime = DateTime.Now, Action = "Processed renewal for Closed Account Loan " + lon.LoanID }; ctx.AuditTrails.Add(at); ctx.SaveChanges(); MessageBox.Show("Transaction has been successfully processed", "Information", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } } catch (Exception ex) { System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } }
protected void btnCancel_Click(object sender, EventArgs e) { try { //Page.ClientScript.RegisterStartupScript(this.GetType(), "showAl", "ShowConfirmation();", true); using (var ctx = new finalContext()) { int n = Convert.ToInt32(Session["ID"]); var lon = ctx.TemporaryLoanApplications.Where(x => x.ClientID == n).First(); string folderName = @"F:\Loan Files\Applications Online"; string pathString = System.IO.Path.Combine(folderName, "Application " + lon.TemporaryLoanApplicationID.ToString()); if (Directory.Exists(pathString)) { Directory.Delete(pathString, true); } ctx.TemporaryLoanApplications.Remove(lon); ctx.SaveChanges(); string myStringVariable = "Loan application has been successfuly cancelled"; ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true); Response.Redirect("/MyAccount_Loans.aspx"); } } catch (Exception) { Response.Redirect("/Index.aspx"); } }
private void btnSave_Click(object sender, RoutedEventArgs e) { try { if (lblName.Content == "?" || lblDesc.Content == "?" || String.IsNullOrWhiteSpace(txtName.Text)) { System.Windows.MessageBox.Show("Please input correct format and/or fill all required fields", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (status == "Add") { using (var ctx = new finalContext()) { var num = ctx.Banks.Where(x => x.BankName == txtName.Text).Count(); if (num > 0) { return; } Bank bank = new Bank { BankName = txtName.Text, Description = txtDesc.Text, Active = true }; var add = from ad in ctx.TempAdresses select ad; int ctr = 1; foreach (var item in add) { BankAddress bAd = new BankAddress { BankNum = ctr, City = item.City, Province = item.Province, Street = item.Street }; ctx.BankAdresses.Add(bAd); ctr++; } AuditTrail at = new AuditTrail { EmployeeID = UserID, DateAndTime = DateTime.Now, Action = "Added new Bank " + txtName.Text }; ctx.AuditTrails.Add(at); ctx.Banks.Add(bank); ctx.SaveChanges(); System.Windows.MessageBox.Show("New Bank Added", "Information", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } else { using (var ctx = new finalContext()) { var bank = ctx.Banks.Find(bId); bank.BankName = txtName.Text; bank.Description = txtDesc.Text; AuditTrail at = new AuditTrail { EmployeeID = UserID, DateAndTime = DateTime.Now, Action = "Updated Bank " + txtName.Text }; ctx.AuditTrails.Add(at); ctx.SaveChanges(); System.Windows.MessageBox.Show("Bank Successfully Updated", "Information", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } } catch (Exception ex) { System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } }