From 8981d6984421f36feea92774632f592fdb96bbb9 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GENO133\\IvanPlex" Date: Sat, 10 Feb 2024 10:47:33 -0700 Subject: [PATCH] added custom month interval for taxes/fees --- Controllers/VehicleController.cs | 11 +++++++++- Models/TaxRecord/TaxRecord.cs | 1 + Models/TaxRecord/TaxRecordInput.cs | 2 ++ Views/Vehicle/_TaxRecordModal.cshtml | 6 ++++-- wwwroot/js/taxrecord.js | 30 ++++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/Controllers/VehicleController.cs b/Controllers/VehicleController.cs index d84ba3b..362dafa 100644 --- a/Controllers/VehicleController.cs +++ b/Controllers/VehicleController.cs @@ -799,7 +799,14 @@ namespace CarCareTracker.Controllers { foreach(TaxRecord recurringFee in recurringFees) { - var newDate = recurringFee.Date.AddMonths((int)recurringFee.RecurringInterval); + var newDate = new DateTime(); + if (recurringFee.RecurringInterval != ReminderMonthInterval.Other) + { + newDate = recurringFee.Date.AddMonths((int)recurringFee.RecurringInterval); + } else + { + newDate = recurringFee.Date.AddMonths(recurringFee.CustomMonthInterval); + } if (DateTime.Now > newDate){ recurringFee.IsRecurring = false; var newRecurringFee = new TaxRecord() @@ -811,6 +818,7 @@ namespace CarCareTracker.Controllers IsRecurring = true, Notes = recurringFee.Notes, RecurringInterval = recurringFee.RecurringInterval, + CustomMonthInterval = recurringFee.CustomMonthInterval, Files = recurringFee.Files, Tags = recurringFee.Tags }; @@ -848,6 +856,7 @@ namespace CarCareTracker.Controllers VehicleId = result.VehicleId, IsRecurring = result.IsRecurring, RecurringInterval = result.RecurringInterval, + CustomMonthInterval = result.CustomMonthInterval, Files = result.Files, Tags = result.Tags }; diff --git a/Models/TaxRecord/TaxRecord.cs b/Models/TaxRecord/TaxRecord.cs index c023f72..ba991e7 100644 --- a/Models/TaxRecord/TaxRecord.cs +++ b/Models/TaxRecord/TaxRecord.cs @@ -10,6 +10,7 @@ public string Notes { get; set; } public bool IsRecurring { get; set; } = false; public ReminderMonthInterval RecurringInterval { get; set; } = ReminderMonthInterval.OneYear; + public int CustomMonthInterval { get; set; } = 0; public List Files { get; set; } = new List(); public List Tags { get; set; } = new List(); } diff --git a/Models/TaxRecord/TaxRecordInput.cs b/Models/TaxRecord/TaxRecordInput.cs index 878d76e..75f79f9 100644 --- a/Models/TaxRecord/TaxRecordInput.cs +++ b/Models/TaxRecord/TaxRecordInput.cs @@ -10,6 +10,7 @@ public string Notes { get; set; } public bool IsRecurring { get; set; } = false; public ReminderMonthInterval RecurringInterval { get; set; } = ReminderMonthInterval.ThreeMonths; + public int CustomMonthInterval { get; set; } = 0; public List Files { get; set; } = new List(); public List Tags { get; set; } = new List(); public TaxRecord ToTaxRecord() { return new TaxRecord { @@ -21,6 +22,7 @@ Notes = Notes, IsRecurring = IsRecurring, RecurringInterval = RecurringInterval, + CustomMonthInterval = CustomMonthInterval, Files = Files, Tags = Tags }; } diff --git a/Views/Vehicle/_TaxRecordModal.cshtml b/Views/Vehicle/_TaxRecordModal.cshtml index c3984ec..0ff936c 100644 --- a/Views/Vehicle/_TaxRecordModal.cshtml +++ b/Views/Vehicle/_TaxRecordModal.cshtml @@ -42,7 +42,8 @@ - + @(Model.RecurringInterval == ReminderMonthInterval.Other && Model.CustomMonthInterval > 0 ? $"{translator.Translate(userLanguage, "Other")}: {Model.CustomMonthInterval}" : $"{translator.Translate(userLanguage, "Other")}") @translator.Translate(userLanguage,"1 Month") @translator.Translate(userLanguage, "3 Months") @translator.Translate(userLanguage, "6 Months") @@ -97,6 +98,7 @@ \ No newline at end of file diff --git a/wwwroot/js/taxrecord.js b/wwwroot/js/taxrecord.js index 30fcdb3..419c87c 100644 --- a/wwwroot/js/taxrecord.js +++ b/wwwroot/js/taxrecord.js @@ -84,6 +84,35 @@ function saveTaxRecordToVehicle(isEdit) { } }) } +function checkCustomMonthIntervalForTax() { + var selectedValue = $("#taxRecurringMonth").val(); + if (selectedValue == "Other") { + $("#workAroundInput").show(); + Swal.fire({ + title: 'Specify Custom Month Interval', + html: ` + + `, + confirmButtonText: 'Set', + focusConfirm: false, + preConfirm: () => { + const customMonth = $("#inputCustomMileage").val(); + if (!customMonth || isNaN(parseInt(customMonth)) || parseInt(customMonth) <= 0) { + Swal.showValidationMessage(`Please enter a valid number`); + } + return { customMonth } + }, + }).then(function (result) { + if (result.isConfirmed) { + customMonthInterval = result.value.customMonth; + $("#taxRecurringMonth > option[value='Other']").text(`Other: ${result.value.customMonth}`); + } else { + $("#taxRecurringMonth").val(getTaxRecordModelData().monthInterval); + } + $("#workAroundInput").hide(); + }); + } +} function getAndValidateTaxRecordValues() { var taxDate = $("#taxRecordDate").val(); var taxDescription = $("#taxRecordDescription").val(); @@ -125,6 +154,7 @@ function getAndValidateTaxRecordValues() { notes: taxNotes, isRecurring: taxIsRecurring, recurringInterval: taxRecurringMonth, + customMonthInterval: customMonthInterval, tags: taxTags, files: uploadedFiles, addReminderRecord: addReminderRecord