Added Simplied Fuel Entry
This commit is contained in:
@@ -133,6 +133,14 @@ namespace MotoVaultPro.Controllers
|
|||||||
return Json(result);
|
return Json(result);
|
||||||
}
|
}
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
public IActionResult SaveSimpleFuelEntryPreference(bool useSimpleFuelEntry)
|
||||||
|
{
|
||||||
|
var currentConfig = _config.GetUserConfig(User);
|
||||||
|
currentConfig.UseSimpleFuelEntry = useSimpleFuelEntry;
|
||||||
|
var result = _config.SaveUserConfig(User, currentConfig);
|
||||||
|
return Json(result);
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
public IActionResult GetGasRecordsEditModal(List<int> recordIds)
|
public IActionResult GetGasRecordsEditModal(List<int> recordIds)
|
||||||
{
|
{
|
||||||
var extraFields = _extraFieldDataAccess.GetExtraFieldsById((int)ImportMode.GasRecord).ExtraFields;
|
var extraFields = _extraFieldDataAccess.GetExtraFieldsById((int)ImportMode.GasRecord).ExtraFields;
|
||||||
|
|||||||
@@ -337,6 +337,7 @@ namespace MotoVaultPro.Helper
|
|||||||
PreferredGasMileageUnit = CheckString(nameof(UserConfig.PreferredGasMileageUnit)),
|
PreferredGasMileageUnit = CheckString(nameof(UserConfig.PreferredGasMileageUnit)),
|
||||||
PreferredGasUnit = CheckString(nameof(UserConfig.PreferredGasUnit)),
|
PreferredGasUnit = CheckString(nameof(UserConfig.PreferredGasUnit)),
|
||||||
UseUnitForFuelCost = CheckBool(CheckString(nameof(UserConfig.UseUnitForFuelCost))),
|
UseUnitForFuelCost = CheckBool(CheckString(nameof(UserConfig.UseUnitForFuelCost))),
|
||||||
|
UseSimpleFuelEntry = CheckBool(CheckString(nameof(UserConfig.UseSimpleFuelEntry))),
|
||||||
UserLanguage = CheckString(nameof(UserConfig.UserLanguage), "en_US"),
|
UserLanguage = CheckString(nameof(UserConfig.UserLanguage), "en_US"),
|
||||||
HideSoldVehicles = CheckBool(CheckString(nameof(UserConfig.HideSoldVehicles))),
|
HideSoldVehicles = CheckBool(CheckString(nameof(UserConfig.HideSoldVehicles))),
|
||||||
EnableShopSupplies = CheckBool(CheckString(nameof(UserConfig.EnableShopSupplies))),
|
EnableShopSupplies = CheckBool(CheckString(nameof(UserConfig.EnableShopSupplies))),
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace MotoVaultPro.Helper
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class StaticHelper
|
public static class StaticHelper
|
||||||
{
|
{
|
||||||
public const string VersionNumber = "1.4.9";
|
public const string VersionNumber = "1.0.0";
|
||||||
public const string DbName = "data/cartracker.db";
|
public const string DbName = "data/cartracker.db";
|
||||||
public const string UserConfigPath = "data/config/userConfig.json";
|
public const string UserConfigPath = "data/config/userConfig.json";
|
||||||
public const string ServerConfigPath = "data/config/serverConfig.json";
|
public const string ServerConfigPath = "data/config/serverConfig.json";
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
public string PreferredGasUnit { get; set; } = string.Empty;
|
public string PreferredGasUnit { get; set; } = string.Empty;
|
||||||
public string PreferredGasMileageUnit { get; set; } = string.Empty;
|
public string PreferredGasMileageUnit { get; set; } = string.Empty;
|
||||||
public bool UseUnitForFuelCost { get; set; }
|
public bool UseUnitForFuelCost { get; set; }
|
||||||
|
public bool UseSimpleFuelEntry { get; set; }
|
||||||
public bool ShowCalendar { get; set; }
|
public bool ShowCalendar { get; set; }
|
||||||
public bool ShowVehicleThumbnail { get; set; }
|
public bool ShowVehicleThumbnail { get; set; }
|
||||||
public List<UserColumnPreference> UserColumnPreferences { get; set; } = new List<UserColumnPreference>();
|
public List<UserColumnPreference> UserColumnPreferences { get; set; } = new List<UserColumnPreference>();
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
var useHours = Model.UseHours;
|
var useHours = Model.UseHours;
|
||||||
var isNew = Model.GasRecord.Id == 0;
|
var isNew = Model.GasRecord.Id == 0;
|
||||||
var useUnitFuelCost = userConfig.UseUnitForFuelCost;
|
var useUnitFuelCost = userConfig.UseUnitForFuelCost;
|
||||||
|
var useSimpleFuelEntry = userConfig.UseSimpleFuelEntry;
|
||||||
string consumptionUnit;
|
string consumptionUnit;
|
||||||
string distanceUnit;
|
string distanceUnit;
|
||||||
if (useKwh)
|
if (useKwh)
|
||||||
@@ -40,15 +41,50 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
|
<div class="d-flex justify-content-between align-items-center w-100">
|
||||||
<h5 class="modal-title">@(isNew ? translator.Translate(userLanguage, "Add New Gas Record") : translator.Translate(userLanguage, "Edit Gas Record"))<small style="display:none; @(isNew ? "" : "cursor:pointer;")" class="cached-banner ms-2 text-warning" onclick='@(isNew ? "" : $"showEditGasRecordModal({Model.GasRecord.Id}, true)" )'>@translator.Translate(userLanguage, "Unsaved Changes")</small></h5>
|
<h5 class="modal-title">@(isNew ? translator.Translate(userLanguage, "Add New Gas Record") : translator.Translate(userLanguage, "Edit Gas Record"))<small style="display:none; @(isNew ? "" : "cursor:pointer;")" class="cached-banner ms-2 text-warning" onclick='@(isNew ? "" : $"showEditGasRecordModal({Model.GasRecord.Id}, true)" )'>@translator.Translate(userLanguage, "Unsaved Changes")</small></h5>
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<div class="form-check form-switch me-3">
|
||||||
|
<input class="form-check-input" type="checkbox" role="switch" id="fuelEntryModeToggle" @(useSimpleFuelEntry ? "checked" : "") onchange="toggleFuelEntryMode(this.checked)">
|
||||||
|
<label class="form-check-label" for="fuelEntryModeToggle">@translator.Translate(userLanguage, "Simple Mode")</label>
|
||||||
|
</div>
|
||||||
<button type="button" class="btn-close" onclick="hideAddGasRecordModal()" aria-label="Close"></button>
|
<button type="button" class="btn-close" onclick="hideAddGasRecordModal()" aria-label="Close"></button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="modal-body" onkeydown="handleEnter(this)">
|
<div class="modal-body" onkeydown="handleEnter(this)">
|
||||||
<form>
|
<form>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6 col-12">
|
<div class="col-md-6 col-12">
|
||||||
<input type="text" id="workAroundInput" style="height:0px; width:0px; display:none;">
|
<input type="text" id="workAroundInput" style="height:0px; width:0px; display:none;">
|
||||||
|
<!-- Simple Mode Fields -->
|
||||||
|
<div id="simpleModeFields" style="@(useSimpleFuelEntry ? "" : "display:none;")">
|
||||||
|
<label for="gasRecordMileage">@($"{translator.Translate(userLanguage,"Odometer Reading")}({distanceUnit})")</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<input type="number" inputmode="numeric" id="gasRecordMileage" class="form-control" placeholder="@translator.Translate(userLanguage,"Odometer reading when refueled")" value="@(isNew || Model.GasRecord.Mileage == default ? "" : Model.GasRecord.Mileage)">
|
||||||
|
@if (isNew)
|
||||||
|
{
|
||||||
|
<div class="input-group-text">
|
||||||
|
<button type="button" class="btn btn-sm btn-primary zero-y-padding" onclick="getLastOdometerReadingAndIncrement('gasRecordMileage')"><i class="bi bi-plus"></i></button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<label for="gasRecordUnitCost">@($"{translator.Translate(userLanguage, "Cost Per")} {consumptionUnit}")</label>
|
||||||
|
<input type="text" inputmode="decimal" onkeydown="interceptDecimalKeys(event)" onkeyup="@(useThreeDecimals ? "fixDecimalInput(this, 3)" : "fixDecimalInput(this, 2)"); calculateTotalCost()" id="gasRecordUnitCost" class="form-control" placeholder="@($"{translator.Translate(userLanguage, "Price per")} {consumptionUnit}")" value="">
|
||||||
|
<label for="gasRecordGallons">@($"{translator.Translate(userLanguage, "Fuel Consumption")}({consumptionUnit})")</label>
|
||||||
|
<input type="text" inputmode="decimal" onkeydown="interceptDecimalKeys(event)" onkeyup="@(useThreeDecimalsConsumption ? "fixDecimalInput(this, 3)" : "fixDecimalInput(this, 2)"); calculateTotalCost()" id="gasRecordGallons" class="form-control" placeholder="@translator.Translate(userLanguage,"Amount of gas refueled")" value="@(isNew ? "" : Model.GasRecord.Gallons)">
|
||||||
|
<label for="gasRecordCost">@translator.Translate(userLanguage,"Total Cost") <small class="text-muted">(auto-calculated)</small></label>
|
||||||
|
<input type="text" inputmode="decimal" id="gasRecordCost" class="form-control" placeholder="@translator.Translate(userLanguage,"Total cost calculated automatically")" value="@(isNew ? "" : Model.GasRecord.Cost)" readonly>
|
||||||
|
<!-- Hidden fields for simple mode with default values -->
|
||||||
|
<input type="hidden" id="simpleGasRecordDate" value="@DateTime.Now.ToShortDateString()">
|
||||||
|
<input type="hidden" id="simpleGasIsFillToFull" value="true">
|
||||||
|
<input type="hidden" id="simpleGasIsMissed" value="false">
|
||||||
|
<input type="hidden" id="simpleGasRecordNotes" value="">
|
||||||
|
<input type="hidden" id="simpleGasRecordTag" value="">
|
||||||
|
</div>
|
||||||
|
<!-- Advanced Mode Fields -->
|
||||||
|
<div id="advancedModeFields" style="@(useSimpleFuelEntry ? "display:none;" : "")">
|
||||||
<label for="gasRecordDate">@translator.Translate(userLanguage,"Date")</label>
|
<label for="gasRecordDate">@translator.Translate(userLanguage,"Date")</label>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input type="text" id="gasRecordDate" placeholder="@translator.Translate(userLanguage,"Date refueled")" class="form-control" value="@Model.GasRecord.Date">
|
<input type="text" id="gasRecordDate" placeholder="@translator.Translate(userLanguage,"Date refueled")" class="form-control" value="@Model.GasRecord.Date">
|
||||||
@@ -99,7 +135,8 @@
|
|||||||
</select>
|
</select>
|
||||||
@await Html.PartialAsync("_ExtraField", Model.GasRecord.ExtraFields)
|
@await Html.PartialAsync("_ExtraField", Model.GasRecord.ExtraFields)
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6 col-12">
|
</div>
|
||||||
|
<div class="col-md-6 col-12" id="secondColumnFields" style="@(useSimpleFuelEntry ? "display:none;" : "")">
|
||||||
<label for="gasRecordNotes">@translator.Translate(userLanguage,"Notes(optional)")<a class="link-underline link-underline-opacity-0" onclick="showLinks(this)"><i class="bi bi-markdown ms-2"></i></a></label>
|
<label for="gasRecordNotes">@translator.Translate(userLanguage,"Notes(optional)")<a class="link-underline link-underline-opacity-0" onclick="showLinks(this)"><i class="bi bi-markdown ms-2"></i></a></label>
|
||||||
<textarea id="gasRecordNotes" class="form-control" rows="5">@Model.GasRecord.Notes</textarea>
|
<textarea id="gasRecordNotes" class="form-control" rows="5">@Model.GasRecord.Notes</textarea>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -68,7 +68,15 @@ function deleteGasRecord(gasRecordId) {
|
|||||||
}
|
}
|
||||||
function saveGasRecordToVehicle(isEdit) {
|
function saveGasRecordToVehicle(isEdit) {
|
||||||
//get values
|
//get values
|
||||||
var formValues = getAndValidateGasRecordValues();
|
var isSimpleMode = $("#fuelEntryModeToggle").is(":checked");
|
||||||
|
var formValues;
|
||||||
|
|
||||||
|
if (isSimpleMode) {
|
||||||
|
formValues = getAndValidateGasRecordValuesSimple();
|
||||||
|
} else {
|
||||||
|
formValues = getAndValidateGasRecordValues();
|
||||||
|
}
|
||||||
|
|
||||||
//validate
|
//validate
|
||||||
if (formValues.hasError) {
|
if (formValues.hasError) {
|
||||||
errorToast("Please check the form data");
|
errorToast("Please check the form data");
|
||||||
@@ -496,3 +504,107 @@ function saveMultipleGasRecordsToVehicle() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Simple/Advanced fuel entry mode toggle functions
|
||||||
|
function toggleFuelEntryMode(useSimpleMode) {
|
||||||
|
if (useSimpleMode) {
|
||||||
|
// Switch to simple mode
|
||||||
|
$("#simpleModeFields").show();
|
||||||
|
$("#advancedModeFields").hide();
|
||||||
|
$("#secondColumnFields").hide();
|
||||||
|
|
||||||
|
// Initialize simple mode values if editing existing record
|
||||||
|
var existingCost = $("#gasRecordCost").val();
|
||||||
|
var existingGallons = $("#gasRecordGallons").val();
|
||||||
|
if (existingCost && existingGallons && globalParseFloat(existingGallons) > 0) {
|
||||||
|
var unitCost = globalParseFloat(existingCost) / globalParseFloat(existingGallons);
|
||||||
|
$("#gasRecordUnitCost").val(globalFloatToString(unitCost.toFixed(3)));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Switch to advanced mode
|
||||||
|
$("#simpleModeFields").hide();
|
||||||
|
$("#advancedModeFields").show();
|
||||||
|
$("#secondColumnFields").show();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save user preference
|
||||||
|
$.post('/Vehicle/SaveSimpleFuelEntryPreference', { useSimpleFuelEntry: useSimpleMode }, function (data) {
|
||||||
|
if (!data) {
|
||||||
|
errorToast("Error saving preference");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auto-calculate total cost based on unit cost and gallons
|
||||||
|
function calculateTotalCost() {
|
||||||
|
var unitCost = globalParseFloat($("#gasRecordUnitCost").val());
|
||||||
|
var gallons = globalParseFloat($("#gasRecordGallons").val());
|
||||||
|
|
||||||
|
if (!isNaN(unitCost) && !isNaN(gallons) && unitCost > 0 && gallons > 0) {
|
||||||
|
var totalCost = unitCost * gallons;
|
||||||
|
var decimalPoints = getGlobalConfig().useThreeDecimals ? 3 : 2;
|
||||||
|
$("#gasRecordCost").val(globalFloatToString(totalCost.toFixed(decimalPoints)));
|
||||||
|
} else {
|
||||||
|
$("#gasRecordCost").val("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simple mode validation function
|
||||||
|
function getAndValidateGasRecordValuesSimple() {
|
||||||
|
var gasDate = $("#simpleGasRecordDate").val();
|
||||||
|
var gasMileage = parseInt(globalParseFloat($("#gasRecordMileage").val())).toString();
|
||||||
|
var gasGallons = $("#gasRecordGallons").val();
|
||||||
|
var gasCost = $("#gasRecordCost").val();
|
||||||
|
var gasIsFillToFull = $("#simpleGasIsFillToFull").val() === "true";
|
||||||
|
var gasIsMissed = $("#simpleGasIsMissed").val() === "true";
|
||||||
|
var gasNotes = $("#simpleGasRecordNotes").val();
|
||||||
|
var gasTags = $("#simpleGasRecordTag").val() ? [$("#simpleGasRecordTag").val()] : [];
|
||||||
|
var vehicleId = GetVehicleId().vehicleId;
|
||||||
|
var gasRecordId = getGasRecordModelData().id;
|
||||||
|
|
||||||
|
//Odometer Adjustments
|
||||||
|
if (isNaN(gasMileage) && GetVehicleId().odometerOptional) {
|
||||||
|
gasMileage = '0';
|
||||||
|
}
|
||||||
|
gasMileage = GetAdjustedOdometer(gasRecordId, gasMileage);
|
||||||
|
|
||||||
|
// Validation for simple mode
|
||||||
|
var hasError = false;
|
||||||
|
|
||||||
|
if (gasMileage.trim() == '' || isNaN(gasMileage) || parseInt(gasMileage) < 0) {
|
||||||
|
hasError = true;
|
||||||
|
$("#gasRecordMileage").addClass("is-invalid");
|
||||||
|
} else {
|
||||||
|
$("#gasRecordMileage").removeClass("is-invalid");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gasGallons.trim() == '' || globalParseFloat(gasGallons) <= 0) {
|
||||||
|
hasError = true;
|
||||||
|
$("#gasRecordGallons").addClass("is-invalid");
|
||||||
|
} else {
|
||||||
|
$("#gasRecordGallons").removeClass("is-invalid");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gasCost.trim() == '' || !isValidMoney(gasCost)) {
|
||||||
|
hasError = true;
|
||||||
|
$("#gasRecordCost").addClass("is-invalid");
|
||||||
|
} else {
|
||||||
|
$("#gasRecordCost").removeClass("is-invalid");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: gasRecordId,
|
||||||
|
hasError: hasError,
|
||||||
|
vehicleId: vehicleId,
|
||||||
|
date: gasDate,
|
||||||
|
mileage: gasMileage,
|
||||||
|
gallons: gasGallons,
|
||||||
|
cost: gasCost,
|
||||||
|
files: [], // Simple mode doesn't support file uploads
|
||||||
|
tags: gasTags,
|
||||||
|
isFillToFull: gasIsFillToFull,
|
||||||
|
missedFuelUp: gasIsMissed,
|
||||||
|
notes: gasNotes,
|
||||||
|
extraFields: [] // Simple mode doesn't use extra fields
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user