added custom month interval for taxes/fees

This commit is contained in:
DESKTOP-GENO133\IvanPlex
2024-02-10 10:47:33 -07:00
parent 09fbc37472
commit 8981d69844
5 changed files with 47 additions and 3 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
};

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

@@ -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

@@ -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