/// <summary> /// Adds and activates new set of fees /// </summary> /// <param name="classTermFees">A list of fees (i.e jss - sss)</param> /// <param name="username">The user performing this action, for audit trail.</param> /// <returns>A list of ids of the newly added fees and the ones deactivated </returns> public ActivatedAndDeactivatedId AddClassTermFees(IList<ClassTermFee> classTermFees, string username) { var currentFees = GetCurrentFees(); var deActivatedIds = DeactivateFeesAndGetIds(currentFees); // Add fees and return ids try { var activatedIds = classTermFees.Select(x => _classTermFees.Add(x).Id).ToList(); var activatedAndDeactivatedId = new ActivatedAndDeactivatedId { DeActivatedIds = deActivatedIds, ActivatedIds = activatedIds }; // Update School UpdateSchool(classTermFees); _auditTrailRepository.Log($"School fees created by {username}", AuditActionEnum.Created); _log.Info("Fees added"); return activatedAndDeactivatedId; } catch (Exception ex) { _log.Error("Error", ex); return null; } }
/// <summary> /// Deletes the current fees and activate the last deactivated fees /// </summary> /// <param name="activatedAndDeactivatedId">A list containing the current fee ids and previous deactivated fee ids</param> /// <param name="username">The user performing this action, for audit trail.</param> /// <returns>True if success, else false</returns> public bool DeleteCurrentFeesAndActivatePreviousFees(ActivatedAndDeactivatedId activatedAndDeactivatedId, string username) { try { // Reactivate the formally deactivated fees var success = ReactivatePreviousFees(activatedAndDeactivatedId.DeActivatedIds, username); if (!success) { return false; } // Delete the newly added fees foreach (var id in activatedAndDeactivatedId.ActivatedIds) { _classTermFees.Delete(id); _auditTrailRepository.Log($"School fees deleted by {username}", AuditActionEnum.Deleted); _log.Info("Fees deleted"); } // True if delete is successful return true; } catch (Exception ex) { _log.Error("Error", ex); return false; } }
private void btnSave_Click(object sender, EventArgs e) { var schoolName = tboSchoolName.Text; var address = tboAddress.Text; var slogan = tboSlogan.Text; var logoPath = tboLogoPath.Text; var phoneNumbers = tboPhoneNumbers.Text; var sessionDateStarted = dtpSessionDateStarted.Text; var termDatedStarted = dtpTermDateStarted.Text; var presentSession = cboPresentSession.SelectedValue; var presentTerm = cboPresentTerm.SelectedValue; // Setup fees var jss1 = tboJss1.Text.Replace(",",""); var jss2 = tboJss2.Text.Replace(",","");; var jss3 = tboJss3.Text.Replace(",","");; var sss1 = tboSss1.Text.Replace(",","");; var sss2 = tboSss2.Text.Replace(",","");; var sss3 = tboSss3.Text.Replace(",", ""); ; var jss = tboJss.Text.Replace(",","");; var sss = tboSss.Text.Replace(",", ""); ; // Check if all fields are filled if (presentSession != "" && presentTerm != "" && !string.IsNullOrWhiteSpace(jss1) && !string.IsNullOrWhiteSpace(jss2) && !string.IsNullOrWhiteSpace(jss3) && !string.IsNullOrWhiteSpace(sss1) && !string.IsNullOrWhiteSpace(sss2) && !string.IsNullOrWhiteSpace(sss3) && !string.IsNullOrWhiteSpace(jss) && !string.IsNullOrWhiteSpace(sss) && !string.IsNullOrWhiteSpace(sss3) && !string.IsNullOrWhiteSpace(schoolName) && !string.IsNullOrWhiteSpace(address) && !string.IsNullOrWhiteSpace(slogan) && !string.IsNullOrWhiteSpace(logoPath) && !string.IsNullOrWhiteSpace(phoneNumbers)) { decimal result; // Check if fees are numbers if (decimal.TryParse(jss1, out result) && decimal.TryParse(jss2, out result) && decimal.TryParse(jss3, out result) && decimal.TryParse(sss1, out result) && decimal.TryParse(sss2, out result) && decimal.TryParse(sss3, out result) && decimal.TryParse(jss, out result) && decimal.TryParse(sss, out result)) { var response = MessageBox.Show(@"Please confirm the information provided before proceeding. Are you sure you want to save?", @"School Setup", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (response != DialogResult.Yes) return; var school = new School() { Name = schoolName.ToUpper(), PresentSession = presentSession.ToString(), PresentTermEnum = (TermEnum)presentTerm, SessionStart = Convert.ToDateTime(sessionDateStarted), TermStart = Convert.ToDateTime(termDatedStarted), Address = address, PhoneNumbers = phoneNumbers.Split(',').Select(x => x.Trim()).ToList(), LogoPath = Utilities.GetPermanentLogoPath(logoPath), Slogan = slogan }; _schoolRepository.SchoolSetup(school); var classEnums = new List<ClassEnum>() { ClassEnum.JSS1, ClassEnum.JSS2, ClassEnum.JSS3, ClassEnum.SSS1, ClassEnum.SSS2, ClassEnum.SSS3, ClassEnum.JSS, ClassEnum.SSS }; var schoolFees = new List<decimal>() { Convert.ToDecimal(jss1), Convert.ToDecimal(jss2), Convert.ToDecimal(jss3), Convert.ToDecimal(sss1), Convert.ToDecimal(sss2), Convert.ToDecimal(sss3), Convert.ToDecimal(jss), Convert.ToDecimal(sss) }; var classTermFees = schoolFees.Select((fee, i) => new ClassTermFee() { ClassEnum = classEnums[i], Session = presentSession.ToString(), StartDate = DateTime.Now, EndDate = null, Active = true, Fee = fee, TermEnum = (TermEnum)presentTerm }).ToList(); _activatedAndDeactivatedId = _classTermFeeRepository.AddClassTermFees(classTermFees, _username); if (_activatedAndDeactivatedId == null) { MessageBox.Show(@"Something went wrong, Please restart the program and try again", ActiveForm.Text); return; } MessageBox.Show(@"School Setup is Successful", ActiveForm.Text); Hide(); new DashBoard(_username).ShowDialog(); } else { MessageBox.Show(@"Invalid entry in the fees textbox"); } } else { MessageBox.Show(@"Please, all information are required"); } }
private void btnSaveSchoolFeesANT_Click(object sender, EventArgs e) { // ANT - Add New Term var session = cboSessionANT.SelectedValue; var term = cboTermANT.SelectedValue; var jss1 = tboJss1ANT.Text.Replace(",",""); var jss2 = tboJss2ANT.Text.Replace(",",""); var jss3 = tboJss3ANT.Text.Replace(",",""); var sss1 = tboSss1ANT.Text.Replace(",",""); var sss2 = tboSss2ANT.Text.Replace(",",""); var sss3 = tboSss3ANT.Text.Replace(",", ""); var jss = tboJssANT.Text.Replace(",",""); var sss = tboSssANT.Text.Replace(",", ""); if (session != "" && term != "" && !string.IsNullOrWhiteSpace(jss1) && !string.IsNullOrWhiteSpace(jss2) && !string.IsNullOrWhiteSpace(jss3) && !string.IsNullOrWhiteSpace(sss1) && !string.IsNullOrWhiteSpace(sss2) && !string.IsNullOrWhiteSpace(sss3) && !string.IsNullOrWhiteSpace(jss) && !string.IsNullOrWhiteSpace(sss)) { // Check to see if it's a number decimal result; if (decimal.TryParse(jss1, out result) && decimal.TryParse(jss2, out result) && decimal.TryParse(jss3, out result) && decimal.TryParse(sss1, out result) && decimal.TryParse(sss2, out result) && decimal.TryParse(sss3, out result) && decimal.TryParse(jss, out result) && decimal.TryParse(sss, out result)) { // Promtion must occur before a first term school fees is added. if ((TermEnum) term == TermEnum.First) { var presentTerm = _schoolRepository.Get().PresentTermEnum; // Check if the just concluded term is a third term if (presentTerm == TermEnum.Third) { var success = _studentRepository.PromoteStudents(null); if (!success) { MessageBox.Show(@"Something went wrong, Please restart the program and try again", @"School Accountant"); return; } } } var classEnums = new List<ClassEnum>() { ClassEnum.JSS1, ClassEnum.JSS2, ClassEnum.JSS3, ClassEnum.SSS1, ClassEnum.SSS2, ClassEnum.SSS3, ClassEnum.JSS, ClassEnum.SSS }; var schoolFees = new List<decimal>() { Convert.ToDecimal(jss1), Convert.ToDecimal(jss2), Convert.ToDecimal(jss3), Convert.ToDecimal(sss1), Convert.ToDecimal(sss2), Convert.ToDecimal(sss3), Convert.ToDecimal(jss), Convert.ToDecimal(sss) }; var classTermFees = schoolFees.Select((fee, i) => new ClassTermFee() { ClassEnum = classEnums[i], Session = session.ToString(), StartDate = DateTime.Now, EndDate = null, Active = true, Fee = fee, TermEnum = (TermEnum) term }).ToList(); _activatedAndDeactivatedId = _classTermFeeRepository.AddClassTermFees(classTermFees, _username); if (_activatedAndDeactivatedId == null) { MessageBox.Show(@"Something went wrong, Please restart the program and try again", @"School Accountant"); } // Enable the undo button btnUndoLastAddFeesANT.Enabled = true; // // Add new fee to all students var updateSuccess = _studentRepository.UpdateStudentFees(); if (!updateSuccess) { MessageBox.Show(@"Something went wrong, Please restart the program and try again", @"School Accountant"); } MessageBox.Show(@"Fees added, click the 'undo' button to delete", @"School Accountant"); RefreshDgvMS(); } else { MessageBox.Show(@"Please, enter only numbers to fees", @"School Accountant"); } } else { MessageBox.Show(@"Please, all information are required", @"School Accountant"); } }