Added Simplied Fuel Entry
This commit is contained in:
@@ -68,7 +68,15 @@ function deleteGasRecord(gasRecordId) {
|
||||
}
|
||||
function saveGasRecordToVehicle(isEdit) {
|
||||
//get values
|
||||
var formValues = getAndValidateGasRecordValues();
|
||||
var isSimpleMode = $("#fuelEntryModeToggle").is(":checked");
|
||||
var formValues;
|
||||
|
||||
if (isSimpleMode) {
|
||||
formValues = getAndValidateGasRecordValuesSimple();
|
||||
} else {
|
||||
formValues = getAndValidateGasRecordValues();
|
||||
}
|
||||
|
||||
//validate
|
||||
if (formValues.hasError) {
|
||||
errorToast("Please check the form data");
|
||||
@@ -495,4 +503,108 @@ function saveMultipleGasRecordsToVehicle() {
|
||||
errorToast(genericErrorMessage());
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 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