Merge pull request #262 from hargata/Hargata/custom.month.interval

added ability to add custom month interval to reminder.
This commit is contained in:
Hargata Softworks
2024-02-10 10:49:33 -07:00
committed by GitHub
11 changed files with 123 additions and 22 deletions

View File

@@ -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
};
@@ -1352,7 +1361,8 @@ namespace CarCareTracker.Controllers
IsRecurring = result.IsRecurring,
ReminderMileageInterval = result.ReminderMileageInterval,
ReminderMonthInterval = result.ReminderMonthInterval,
CustomMileageInterval = result.CustomMileageInterval
CustomMileageInterval = result.CustomMileageInterval,
CustomMonthInterval = result.CustomMonthInterval
};
return PartialView("_ReminderRecordModal", convertedResult);
}

View File

@@ -2,6 +2,7 @@
{
public enum ReminderMonthInterval
{
Other = 0,
OneMonth = 1,
ThreeMonths = 3,
SixMonths = 6,

View File

@@ -13,7 +13,14 @@ namespace CarCareTracker.Helper
{
if (existingReminder.Metric == ReminderMetric.Both)
{
existingReminder.Date = existingReminder.Date.AddMonths((int)existingReminder.ReminderMonthInterval);
if (existingReminder.ReminderMonthInterval != ReminderMonthInterval.Other)
{
existingReminder.Date = existingReminder.Date.AddMonths((int)existingReminder.ReminderMonthInterval);
} else
{
existingReminder.Date = existingReminder.Date.AddMonths(existingReminder.CustomMonthInterval);
}
if (existingReminder.ReminderMileageInterval != ReminderMileageInterval.Other)
{
existingReminder.Mileage += (int)existingReminder.ReminderMileageInterval;
@@ -35,7 +42,14 @@ namespace CarCareTracker.Helper
}
else if (existingReminder.Metric == ReminderMetric.Date)
{
existingReminder.Date = existingReminder.Date.AddMonths((int)existingReminder.ReminderMonthInterval);
if (existingReminder.ReminderMonthInterval != ReminderMonthInterval.Other)
{
existingReminder.Date = existingReminder.Date.AddMonths((int)existingReminder.ReminderMonthInterval);
}
else
{
existingReminder.Date = existingReminder.Date.AddMonths(existingReminder.CustomMonthInterval);
}
}
return existingReminder;
}

View File

@@ -10,6 +10,7 @@
public string Notes { get; set; }
public bool IsRecurring { get; set; } = false;
public int CustomMileageInterval { get; set; } = 0;
public int CustomMonthInterval { get; set; } = 0;
public ReminderMileageInterval ReminderMileageInterval { get; set; } = ReminderMileageInterval.FiveThousandMiles;
public ReminderMonthInterval ReminderMonthInterval { get; set; } = ReminderMonthInterval.OneYear;
public ReminderMetric Metric { get; set; } = ReminderMetric.Date;

View File

@@ -10,20 +10,27 @@
public string Notes { get; set; }
public bool IsRecurring { get; set; } = false;
public int CustomMileageInterval { get; set; } = 0;
public int CustomMonthInterval { get; set; } = 0;
public ReminderMileageInterval ReminderMileageInterval { get; set; } = ReminderMileageInterval.FiveThousandMiles;
public ReminderMonthInterval ReminderMonthInterval { get; set; } = ReminderMonthInterval.OneYear;
public ReminderMetric Metric { get; set; } = ReminderMetric.Date;
public ReminderRecord ToReminderRecord() { return new ReminderRecord {
Id = Id,
VehicleId = VehicleId,
Date = DateTime.Parse(string.IsNullOrWhiteSpace(Date) ? DateTime.Now.AddDays(1).ToShortDateString() : Date),
Mileage = Mileage,
Description = Description,
Metric = Metric,
IsRecurring = IsRecurring,
ReminderMileageInterval = ReminderMileageInterval,
ReminderMonthInterval = ReminderMonthInterval,
CustomMileageInterval = CustomMileageInterval,
Notes = Notes }; }
public ReminderRecord ToReminderRecord()
{
return new ReminderRecord
{
Id = Id,
VehicleId = VehicleId,
Date = DateTime.Parse(string.IsNullOrWhiteSpace(Date) ? DateTime.Now.AddDays(1).ToShortDateString() : Date),
Mileage = Mileage,
Description = Description,
Metric = Metric,
IsRecurring = IsRecurring,
ReminderMileageInterval = ReminderMileageInterval,
ReminderMonthInterval = ReminderMonthInterval,
CustomMileageInterval = CustomMileageInterval,
CustomMonthInterval = CustomMonthInterval,
Notes = Notes
};
}
}
}

View File

@@ -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<UploadedFiles> Files { get; set; } = new List<UploadedFiles>();
public List<string> Tags { get; set; } = new List<string>();
}

View File

@@ -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<UploadedFiles> Files { get; set; } = new List<UploadedFiles>();
public List<string> Tags { get; set; } = new List<string>();
public TaxRecord ToTaxRecord() { return new TaxRecord {
@@ -21,6 +22,7 @@
Notes = Notes,
IsRecurring = IsRecurring,
RecurringInterval = RecurringInterval,
CustomMonthInterval = CustomMonthInterval,
Files = Files,
Tags = Tags
}; }

View File

@@ -72,7 +72,9 @@
<!option value="OneHundredFiftyThousandMiles" @(Model.ReminderMileageInterval == ReminderMileageInterval.OneHundredFiftyThousandMiles ? "selected" : "")>150000 mi. / Km</!option>
</select>
<label for="reminderRecurringMonth">Month</label>
<select class="form-select" id="reminderRecurringMonth" @(Model.IsRecurring ? "" : "disabled")>
<select class="form-select" onchange="checkCustomMonthInterval()" id="reminderRecurringMonth" @(Model.IsRecurring ? "" : "disabled")>
<!option value="Other" @(Model.ReminderMonthInterval == ReminderMonthInterval.Other ? "selected" : "")>@(Model.ReminderMonthInterval == ReminderMonthInterval.Other && Model.CustomMonthInterval > 0 ? $"{translator.Translate(userLanguage, "Other")}: {Model.CustomMonthInterval}" : $"{translator.Translate(userLanguage, "Other")}") </!option>
<!option value="OneMonth" @(Model.ReminderMonthInterval == ReminderMonthInterval.OneMonth ? "selected" : "")>@translator.Translate(userLanguage, "1 Month")</!option>
<!option value="ThreeMonths" @(Model.ReminderMonthInterval == ReminderMonthInterval.ThreeMonths || isNew ? "selected" : "")>@translator.Translate(userLanguage,"3 Months")</!option>
<!option value="SixMonths" @(Model.ReminderMonthInterval == ReminderMonthInterval.SixMonths ? "selected" : "")>@translator.Translate(userLanguage,"6 Months")</!option>
<!option value="OneYear" @(Model.ReminderMonthInterval == ReminderMonthInterval.OneYear ? "selected" : "")>@translator.Translate(userLanguage, "1 Year")</!option>
@@ -102,7 +104,8 @@
</div>
<script>
var customMileageInterval = @Model.CustomMileageInterval;
var customMonthInterval = @Model.CustomMonthInterval;
function getReminderRecordModelData() {
return { id: @Model.Id, mileageInterval: '@Model.ReminderMileageInterval.ToString()'}
return { id: @Model.Id, mileageInterval: decodeHTMLEntities('@Model.ReminderMileageInterval.ToString()'), monthInterval: decodeHTMLEntities('@Model.ReminderMonthInterval.ToString()')}
}
</script>

View File

@@ -42,7 +42,8 @@
<label class="form-check-label" for="taxIsRecurring">@translator.Translate(userLanguage,"Is Recurring")</label>
</div>
<label for="taxRecurringMonth">@translator.Translate(userLanguage,"Month")</label>
<select class="form-select" id="taxRecurringMonth" @(Model.IsRecurring ? "" : "disabled")>
<select class="form-select" onchange="checkCustomMonthIntervalForTax()" id="taxRecurringMonth" @(Model.IsRecurring ? "" : "disabled")>
<!option value="Other" @(Model.RecurringInterval == ReminderMonthInterval.Other ? "selected" : "")>@(Model.RecurringInterval == ReminderMonthInterval.Other && Model.CustomMonthInterval > 0 ? $"{translator.Translate(userLanguage, "Other")}: {Model.CustomMonthInterval}" : $"{translator.Translate(userLanguage, "Other")}") </!option>
<!option value="OneMonth" @(Model.RecurringInterval == ReminderMonthInterval.OneMonth ? "selected" : "")>@translator.Translate(userLanguage,"1 Month")</!option>
<!option value="ThreeMonths" @(Model.RecurringInterval == ReminderMonthInterval.ThreeMonths || isNew ? "selected" : "")>@translator.Translate(userLanguage, "3 Months")</!option>
<!option value="SixMonths" @(Model.RecurringInterval == ReminderMonthInterval.SixMonths ? "selected" : "")>@translator.Translate(userLanguage, "6 Months")</!option>
@@ -97,6 +98,7 @@
</div>
<script>
var uploadedFiles = [];
var customMonthInterval = @Model.CustomMonthInterval;
getUploadedFilesFromModel();
function getUploadedFilesFromModel() {
@foreach (UploadedFiles filesUploaded in Model.Files)
@@ -105,6 +107,6 @@
}
}
function getTaxRecordModelData() {
return { id: @Model.Id}
return { id: @Model.Id, monthInterval: decodeHTMLEntities('@Model.RecurringInterval.ToString()') }
}
</script>

View File

@@ -15,6 +15,35 @@
function hideAddReminderRecordModal() {
$('#reminderRecordModal').modal('hide');
}
function checkCustomMonthInterval() {
var selectedValue = $("#reminderRecurringMonth").val();
if (selectedValue == "Other") {
$("#workAroundInput").show();
Swal.fire({
title: 'Specify Custom Month Interval',
html: `
<input type="text" id="inputCustomMileage" class="swal2-input" placeholder="Months">
`,
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;
$("#reminderRecurringMonth > option[value='Other']").text(`Other: ${result.value.customMonth}`);
} else {
$("#reminderRecurringMonth").val(getReminderRecordModelData().monthInterval);
}
$("#workAroundInput").hide();
});
}
}
function checkCustomMileageInterval() {
var selectedValue = $("#reminderRecurringMileage").val();
if (selectedValue == "Other") {
@@ -36,7 +65,7 @@ function checkCustomMileageInterval() {
}).then(function (result) {
if (result.isConfirmed) {
customMileageInterval = result.value.customMileage;
$("option[value='Other']").text(`Other: ${result.value.customMileage}`);
$("#reminderRecurringMileage > option[value='Other']").text(`Other: ${result.value.customMileage}`);
} else {
$("#reminderRecurringMileage").val(getReminderRecordModelData().mileageInterval);
}
@@ -185,6 +214,7 @@ function getAndValidateReminderRecordValues() {
isRecurring: reminderIsRecurring,
reminderMileageInterval: reminderRecurringMileage,
reminderMonthInterval: reminderRecurringMonth,
customMileageInterval: customMileageInterval
customMileageInterval: customMileageInterval,
customMonthInterval: customMonthInterval
}
}

View File

@@ -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: `
<input type="text" id="inputCustomMileage" class="swal2-input" placeholder="Months">
`,
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