From a9e3e44f2c3de7e382560d1a9a52d09f9e2cfb04 Mon Sep 17 00:00:00 2001 From: "DESKTOP-T0O5CDB\\DESK-555BD" Date: Tue, 23 Jan 2024 17:46:54 -0700 Subject: [PATCH 01/14] added ability to pin notes so that they always show up on top. --- Controllers/VehicleController.cs | 1 + Models/Note.cs | 1 + Views/Vehicle/_NoteModal.cshtml | 4 ++++ wwwroot/js/note.js | 4 +++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Controllers/VehicleController.cs b/Controllers/VehicleController.cs index 83ac9b4..c9e78b3 100644 --- a/Controllers/VehicleController.cs +++ b/Controllers/VehicleController.cs @@ -1266,6 +1266,7 @@ namespace CarCareTracker.Controllers public IActionResult GetNotesByVehicleId(int vehicleId) { var result = _noteDataAccess.GetNotesByVehicleId(vehicleId); + result = result.OrderByDescending(x => x.Pinned).ToList(); return PartialView("_Notes", result); } [HttpPost] diff --git a/Models/Note.cs b/Models/Note.cs index eb8e59e..f344c25 100644 --- a/Models/Note.cs +++ b/Models/Note.cs @@ -6,5 +6,6 @@ public int VehicleId { get; set; } public string Description { get; set; } public string NoteText { get; set; } + public bool Pinned { get; set; } } } diff --git a/Views/Vehicle/_NoteModal.cshtml b/Views/Vehicle/_NoteModal.cshtml index 2dcff4c..169cc27 100644 --- a/Views/Vehicle/_NoteModal.cshtml +++ b/Views/Vehicle/_NoteModal.cshtml @@ -12,6 +12,10 @@
+
+ + +
diff --git a/wwwroot/js/note.js b/wwwroot/js/note.js index f44b31f..b71673a 100644 --- a/wwwroot/js/note.js +++ b/wwwroot/js/note.js @@ -67,6 +67,7 @@ function getAndValidateNoteValues() { var noteText = $("#noteTextArea").val(); var vehicleId = GetVehicleId().vehicleId; var noteId = getNoteModelData().id; + var noteIsPinned = $("#noteIsPinned").is(":checked"); //validation var hasError = false; if (noteDescription.trim() == '') { //eliminates whitespace. @@ -86,6 +87,7 @@ function getAndValidateNoteValues() { hasError: hasError, vehicleId: vehicleId, description: noteDescription, - noteText: noteText + noteText: noteText, + pinned: noteIsPinned } } \ No newline at end of file From d86298f502ddccba2b86d725ef25d32b8d84e1f6 Mon Sep 17 00:00:00 2001 From: "DESKTOP-T0O5CDB\\DESK-555BD" Date: Tue, 23 Jan 2024 21:10:59 -0700 Subject: [PATCH 02/14] make tax recurring. --- Enum/ReminderMonthInterval.cs | 1 + Models/TaxRecord/TaxRecord.cs | 2 ++ Models/TaxRecord/TaxRecordInput.cs | 13 ++++++++++++- Views/Vehicle/_TaxRecordModal.cshtml | 14 ++++++++++++++ wwwroot/js/taxrecord.js | 10 ++++++++++ 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Enum/ReminderMonthInterval.cs b/Enum/ReminderMonthInterval.cs index 675949f..dd1d472 100644 --- a/Enum/ReminderMonthInterval.cs +++ b/Enum/ReminderMonthInterval.cs @@ -2,6 +2,7 @@ { public enum ReminderMonthInterval { + OneMonth = 1, ThreeMonths = 3, SixMonths = 6, OneYear = 12, diff --git a/Models/TaxRecord/TaxRecord.cs b/Models/TaxRecord/TaxRecord.cs index 073695f..5a2f1c7 100644 --- a/Models/TaxRecord/TaxRecord.cs +++ b/Models/TaxRecord/TaxRecord.cs @@ -8,6 +8,8 @@ public string Description { get; set; } public decimal Cost { get; set; } public string Notes { get; set; } + public bool IsRecurring { get; set; } = false; + public ReminderMonthInterval RecurringInterval { get; set; } = ReminderMonthInterval.OneYear; public List Files { get; set; } = new List(); } } diff --git a/Models/TaxRecord/TaxRecordInput.cs b/Models/TaxRecord/TaxRecordInput.cs index cbe33c5..764007d 100644 --- a/Models/TaxRecord/TaxRecordInput.cs +++ b/Models/TaxRecord/TaxRecordInput.cs @@ -8,7 +8,18 @@ public string Description { get; set; } public decimal Cost { get; set; } public string Notes { get; set; } + public bool IsRecurring { get; set; } = false; + public ReminderMonthInterval RecurringInterval { get; set; } = ReminderMonthInterval.ThreeMonths; public List Files { get; set; } = new List(); - public TaxRecord ToTaxRecord() { return new TaxRecord { Id = Id, VehicleId = VehicleId, Date = DateTime.Parse(Date), Cost = Cost, Description = Description, Notes = Notes, Files = Files }; } + public TaxRecord ToTaxRecord() { return new TaxRecord { + Id = Id, + VehicleId = VehicleId, + Date = DateTime.Parse(Date), + Cost = Cost, + Description = Description, + Notes = Notes, + IsRecurring = IsRecurring, + RecurringInterval = RecurringInterval, + Files = Files }; } } } diff --git a/Views/Vehicle/_TaxRecordModal.cshtml b/Views/Vehicle/_TaxRecordModal.cshtml index 61abe78..ac1eeec 100644 --- a/Views/Vehicle/_TaxRecordModal.cshtml +++ b/Views/Vehicle/_TaxRecordModal.cshtml @@ -25,6 +25,20 @@
+
+ + +
+ + @if (Model.Files.Any()) {
diff --git a/wwwroot/js/taxrecord.js b/wwwroot/js/taxrecord.js index 1c40232..958940c 100644 --- a/wwwroot/js/taxrecord.js +++ b/wwwroot/js/taxrecord.js @@ -18,6 +18,14 @@ function showEditTaxRecordModal(taxRecordId) { } }); } +function enableTaxRecurring() { + var taxIsRecurring = $("#taxIsRecurring").is(":checked"); + if (taxIsRecurring) { + $("#taxRecurringMonth").attr('disabled', false); + } else { + $("#taxRecurringMonth").attr('disabled', true); + } +} function hideAddTaxRecordModal() { $('#taxRecordModal').modal('hide'); } @@ -76,6 +84,8 @@ function getAndValidateTaxRecordValues() { var taxNotes = $("#taxRecordNotes").val(); var vehicleId = GetVehicleId().vehicleId; var taxRecordId = getTaxRecordModelData().id; + var taxIsRecurring = $("#taxIsRecurring").is(":checked"); + var taxRecurringMonth = $("#taxRecurringMonth").val(); var addReminderRecord = $("#addReminderCheck").is(":checked"); //validation var hasError = false; From 013fb6794366c93ef50a095243b5b8f6aa8ef47f Mon Sep 17 00:00:00 2001 From: "DESKTOP-GENO133\\IvanPlex" Date: Tue, 23 Jan 2024 21:48:26 -0700 Subject: [PATCH 03/14] Recurring fees. --- Controllers/VehicleController.cs | 31 +++++++++++++++++++++++++++++++ wwwroot/js/taxrecord.js | 2 ++ 2 files changed, 33 insertions(+) diff --git a/Controllers/VehicleController.cs b/Controllers/VehicleController.cs index c9e78b3..5cf1f91 100644 --- a/Controllers/VehicleController.cs +++ b/Controllers/VehicleController.cs @@ -85,6 +85,7 @@ namespace CarCareTracker.Controllers public IActionResult Index(int vehicleId) { var data = _dataAccess.GetVehicleById(vehicleId); + UpdateRecurringTaxes(vehicleId); return View(data); } [HttpGet] @@ -757,6 +758,34 @@ namespace CarCareTracker.Controllers } return PartialView("_TaxRecords", result); } + private void UpdateRecurringTaxes(int vehicleId) + { + var result = _taxRecordDataAccess.GetTaxRecordsByVehicleId(vehicleId); + var recurringFees = result.Where(x => x.IsRecurring); + if (recurringFees.Any()) + { + foreach(TaxRecord recurringFee in recurringFees) + { + var newDate = recurringFee.Date.AddMonths((int)recurringFee.RecurringInterval); + if (DateTime.Now > newDate){ + recurringFee.IsRecurring = false; + var newRecurringFee = new TaxRecord() + { + VehicleId = recurringFee.VehicleId, + Date = newDate, + Description = recurringFee.Description, + Cost = recurringFee.Cost, + IsRecurring = true, + Notes = recurringFee.Notes, + RecurringInterval = recurringFee.RecurringInterval, + Files = recurringFee.Files + }; + _taxRecordDataAccess.SaveTaxRecordToVehicle(recurringFee); + _taxRecordDataAccess.SaveTaxRecordToVehicle(newRecurringFee); + } + } + } + } [HttpPost] public IActionResult SaveTaxRecordToVehicleId(TaxRecordInput taxRecord) { @@ -783,6 +812,8 @@ namespace CarCareTracker.Controllers Description = result.Description, Notes = result.Notes, VehicleId = result.VehicleId, + IsRecurring = result.IsRecurring, + RecurringInterval = result.RecurringInterval, Files = result.Files }; return PartialView("_TaxRecordModal", convertedResult); diff --git a/wwwroot/js/taxrecord.js b/wwwroot/js/taxrecord.js index 958940c..fb56671 100644 --- a/wwwroot/js/taxrecord.js +++ b/wwwroot/js/taxrecord.js @@ -115,6 +115,8 @@ function getAndValidateTaxRecordValues() { description: taxDescription, cost: taxCost, notes: taxNotes, + isRecurring: taxIsRecurring, + recurringInterval: taxRecurringMonth, files: uploadedFiles, addReminderRecord: addReminderRecord } From 52ada8574dc4c16b843261a7c5be5c45e22e8158 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GENO133\\IvanPlex" Date: Tue, 23 Jan 2024 22:15:53 -0700 Subject: [PATCH 04/14] add pinned icon for pinned notes. --- Views/Vehicle/_Notes.cshtml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Views/Vehicle/_Notes.cshtml b/Views/Vehicle/_Notes.cshtml index 9cbd6e4..430eea8 100644 --- a/Views/Vehicle/_Notes.cshtml +++ b/Views/Vehicle/_Notes.cshtml @@ -27,7 +27,13 @@ @foreach (Note note in Model) { - @note.Description + @if (note.Pinned) + { + @note.Description" + } else + { + @note.Description + } @CarCareTracker.Helper.StaticHelper.TruncateStrings(note.NoteText, 100) } From f7f47c54ffc4d68e613a4dd262a796372cbb9018 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GENO133\\IvanPlex" Date: Wed, 24 Jan 2024 09:03:55 -0700 Subject: [PATCH 05/14] added baseline zero costs charge so that bar charts display all months regardless of whether there are costs or not. --- Controllers/VehicleController.cs | 26 +++++++++++---- Helper/StaticHelper.cs | 37 ++++++++++++++++++++++ Views/Vehicle/_GasCostByMonthReport.cshtml | 2 +- Views/Vehicle/_MPGByMonthReport.cshtml | 2 +- 4 files changed, 59 insertions(+), 8 deletions(-) diff --git a/Controllers/VehicleController.cs b/Controllers/VehicleController.cs index 5cf1f91..bcbf285 100644 --- a/Controllers/VehicleController.cs +++ b/Controllers/VehicleController.cs @@ -847,7 +847,7 @@ namespace CarCareTracker.Controllers UpgradeRecordSum = upgradeRecords.Sum(x => x.Cost) }; //get costbymonth - List allCosts = new List(); + List allCosts = StaticHelper.GetBaseLineCosts(); allCosts.AddRange(_reportHelper.GetServiceRecordSum(serviceRecords, 0)); allCosts.AddRange(_reportHelper.GetRepairRecordSum(collisionRecords, 0)); allCosts.AddRange(_reportHelper.GetUpgradeRecordSum(upgradeRecords, 0)); @@ -898,10 +898,17 @@ namespace CarCareTracker.Controllers var userConfig = _config.GetUserConfig(User); var mileageData = _gasHelper.GetGasRecordViewModels(gasRecords, userConfig.UseMPG, userConfig.UseUKMPG); mileageData.RemoveAll(x => x.MilesPerGallon == default); - var monthlyMileageData = mileageData.GroupBy(x => x.MonthId).OrderBy(x => x.Key).Select(x => new CostForVehicleByMonth + var monthlyMileageData = StaticHelper.GetBaseLineCostsNoMonthName(); + monthlyMileageData.AddRange(mileageData.GroupBy(x => x.MonthId).Select(x => new CostForVehicleByMonth { - MonthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(x.Key), + MonthId = x.Key, Cost = x.Average(y => y.MilesPerGallon) + })); + monthlyMileageData = monthlyMileageData.GroupBy(x => x.MonthId).OrderBy(x => x.Key).Select(x => new CostForVehicleByMonth + { + MonthId = x.Key, + MonthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(x.Key), + Cost = x.Sum(y=>y.Cost) }).ToList(); viewModel.FuelMileageForVehicleByMonth = monthlyMileageData; return PartialView("_Report", viewModel); @@ -1043,10 +1050,17 @@ namespace CarCareTracker.Controllers mileageData.RemoveAll(x => DateTime.Parse(x.Date).Year != year); } mileageData.RemoveAll(x => x.MilesPerGallon == default); - var monthlyMileageData = mileageData.GroupBy(x => x.MonthId).OrderBy(x => x.Key).Select(x => new CostForVehicleByMonth + var monthlyMileageData = StaticHelper.GetBaseLineCostsNoMonthName(); + monthlyMileageData.AddRange(mileageData.GroupBy(x => x.MonthId).Select(x => new CostForVehicleByMonth { - MonthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(x.Key), + MonthId = x.Key, Cost = x.Average(y => y.MilesPerGallon) + })); + monthlyMileageData = monthlyMileageData.GroupBy(x => x.MonthId).OrderBy(x => x.Key).Select(x => new CostForVehicleByMonth + { + MonthId = x.Key, + MonthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(x.Key), + Cost = x.Sum(y => y.Cost) }).ToList(); return PartialView("_MPGByMonthReport", monthlyMileageData); } @@ -1054,7 +1068,7 @@ namespace CarCareTracker.Controllers [HttpPost] public IActionResult GetCostByMonthByVehicle(int vehicleId, List selectedMetrics, int year = 0) { - List allCosts = new List(); + List allCosts = StaticHelper.GetBaseLineCosts(); if (selectedMetrics.Contains(ImportMode.ServiceRecord)) { var serviceRecords = _serviceRecordDataAccess.GetServiceRecordsByVehicleId(vehicleId); diff --git a/Helper/StaticHelper.cs b/Helper/StaticHelper.cs index 96036d2..7d45f6c 100644 --- a/Helper/StaticHelper.cs +++ b/Helper/StaticHelper.cs @@ -1,4 +1,5 @@ using CarCareTracker.Models; +using System.Globalization; namespace CarCareTracker.Helper { @@ -63,5 +64,41 @@ namespace CarCareTracker.Helper } return ""; } + public static List GetBaseLineCosts() + { + return new List() + { + new CostForVehicleByMonth {MonthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(1), MonthId = 1, Cost = 0M}, + new CostForVehicleByMonth {MonthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(2), MonthId = 2, Cost = 0M}, + new CostForVehicleByMonth {MonthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(3), MonthId = 3, Cost = 0M}, + new CostForVehicleByMonth {MonthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(4), MonthId = 4, Cost = 0M}, + new CostForVehicleByMonth {MonthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(5), MonthId = 5, Cost = 0M}, + new CostForVehicleByMonth {MonthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(6), MonthId = 6, Cost = 0M}, + new CostForVehicleByMonth {MonthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(7), MonthId = 7, Cost = 0M}, + new CostForVehicleByMonth {MonthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(8), MonthId = 8, Cost = 0M}, + new CostForVehicleByMonth {MonthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(9), MonthId = 9, Cost = 0M}, + new CostForVehicleByMonth {MonthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(10), MonthId = 10, Cost = 0M}, + new CostForVehicleByMonth {MonthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(11), MonthId = 11, Cost = 0M}, + new CostForVehicleByMonth {MonthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(12), MonthId = 12, Cost = 0M} + }; + } + public static List GetBaseLineCostsNoMonthName() + { + return new List() + { + new CostForVehicleByMonth { MonthId = 1, Cost = 0M}, + new CostForVehicleByMonth {MonthId = 2, Cost = 0M}, + new CostForVehicleByMonth {MonthId = 3, Cost = 0M}, + new CostForVehicleByMonth {MonthId = 4, Cost = 0M}, + new CostForVehicleByMonth {MonthId = 5, Cost = 0M}, + new CostForVehicleByMonth {MonthId = 6, Cost = 0M}, + new CostForVehicleByMonth {MonthId = 7, Cost = 0M}, + new CostForVehicleByMonth {MonthId = 8, Cost = 0M}, + new CostForVehicleByMonth {MonthId = 9, Cost = 0M}, + new CostForVehicleByMonth { MonthId = 10, Cost = 0M}, + new CostForVehicleByMonth { MonthId = 11, Cost = 0M}, + new CostForVehicleByMonth { MonthId = 12, Cost = 0M} + }; + } } } diff --git a/Views/Vehicle/_GasCostByMonthReport.cshtml b/Views/Vehicle/_GasCostByMonthReport.cshtml index d08bfd3..0c3de45 100644 --- a/Views/Vehicle/_GasCostByMonthReport.cshtml +++ b/Views/Vehicle/_GasCostByMonthReport.cshtml @@ -3,7 +3,7 @@ var barGraphColors = new string[] { "#00876c", "#43956e", "#67a371", "#89b177", "#a9be80", "#c8cb8b", "#e6d79b", "#e4c281", "#e3ab6b", "#e2925b", "#e07952", "#db5d4f" }; var sortedByMPG = Model.OrderBy(x => x.Cost).ToList(); } -@if (Model.Any()) +@if (Model.Where(x=>x.Cost > 0).Any()) {