Skip to content

Commit

Permalink
Merge pull request #52 from hargata/Hargata/missed.fuelup
Browse files Browse the repository at this point in the history
added missed fuel up feature.
  • Loading branch information
hargata authored Jan 10, 2024
2 parents a467ba0 + fba2a6d commit 9837172
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Controllers/VehicleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ public IActionResult GetGasRecordForEditById(int gasRecordId)
Date = result.Date.ToShortDateString(),
Files = result.Files,
Gallons = result.Gallons,
IsFillToFull = result.IsFillToFull
IsFillToFull = result.IsFillToFull,
MissedFuelUp = result.MissedFuelUp
};
var vehicleIsElectric = _dataAccess.GetVehicleById(convertedResult.VehicleId).IsElectric;
var viewModel = new GasRecordInputContainer()
Expand Down
10 changes: 9 additions & 1 deletion Helper/GasHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ public List<GasRecordViewModel> GetGasRecordViewModels(List<GasRecord> result, b
DeltaMileage = deltaMileage,
CostPerGallon = currentObject.Cost / convertedConsumption
};
if (currentObject.IsFillToFull)
if (currentObject.MissedFuelUp)
{
//if they missed a fuel up, we skip MPG calculation.
gasRecordViewModel.MilesPerGallon = 0;
//reset unFactored vars for missed fuel up because the numbers wont be reliable.
unFactoredConsumption = 0;
unFactoredMileage = 0;
}
else if (currentObject.IsFillToFull)
{
//if user filled to full.
gasRecordViewModel.MilesPerGallon = useMPG ? (unFactoredMileage + deltaMileage) / (unFactoredConsumption + convertedConsumption) : 100 / ((unFactoredMileage + deltaMileage) / (unFactoredConsumption + convertedConsumption));
Expand Down
1 change: 1 addition & 0 deletions Models/GasRecord/GasRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class GasRecord
public decimal Gallons { get; set; }
public decimal Cost { get; set; }
public bool IsFillToFull { get; set; } = true;
public bool MissedFuelUp { get; set; } = false;
public List<UploadedFiles> Files { get; set; } = new List<UploadedFiles>();
}
}
4 changes: 3 additions & 1 deletion Models/GasRecord/GasRecordInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class GasRecordInput
public decimal Gallons { get; set; }
public decimal Cost { get; set; }
public bool IsFillToFull { get; set; } = true;
public bool MissedFuelUp { get; set; } = false;
public List<UploadedFiles> Files { get; set; } = new List<UploadedFiles>();
public GasRecord ToGasRecord() { return new GasRecord {
Id = Id,
Expand All @@ -24,7 +25,8 @@ public class GasRecordInput
Mileage = Mileage,
VehicleId = VehicleId,
Files = Files,
IsFillToFull = IsFillToFull
IsFillToFull = IsFillToFull,
MissedFuelUp = MissedFuelUp
}; }
}
}
4 changes: 4 additions & 0 deletions Views/Vehicle/_GasModal.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
<input class="form-check-input" type="checkbox" role="switch" id="gasIsFillToFull" checked="@Model.GasRecord.IsFillToFull">
<label class="form-check-label" for="gasIsFillToFull">Is Filled To Full</label>
</div>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="gasIsMissed" checked="@Model.GasRecord.MissedFuelUp">
<label class="form-check-label" for="gasIsMissed">Missed Fuel Up(Skip MPG Calculation)</label>
</div>
<label for="GasRecordCost">Cost</label>
<input type="text" id="gasRecordCost" class="form-control" placeholder="Cost of gas refueled" value="@(isNew ? "" : Model.GasRecord.Cost)">
</div>
Expand Down
4 changes: 3 additions & 1 deletion wwwroot/js/gasrecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ function getAndValidateGasRecordValues() {
var gasGallons = $("#gasRecordGallons").val();
var gasCost = $("#gasRecordCost").val();
var gasIsFillToFull = $("#gasIsFillToFull").is(":checked");
var gasIsMissed = $("#gasIsMissed").is(":checked");
var vehicleId = GetVehicleId().vehicleId;
var gasRecordId = getGasRecordModelData().id;
//validation
Expand Down Expand Up @@ -114,6 +115,7 @@ function getAndValidateGasRecordValues() {
gallons: gasGallons,
cost: gasCost,
files: uploadedFiles,
isFillToFull: gasIsFillToFull
isFillToFull: gasIsFillToFull,
missedFuelUp: gasIsMissed
}
}
2 changes: 0 additions & 2 deletions wwwroot/js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,5 @@ function uploadFileAsync(event) {
function isValidMoney(input) {
const euRegex = /^\$?(?=\(.*\)|[^()]*$)\(?\d{1,3}(\.?\d{3})?(,\d{1,3}?)?\)?$/;
const usRegex = /^\$?(?=\(.*\)|[^()]*$)\(?\d{1,3}(,?\d{3})?(\.\d{1,3}?)?\)?$/;
console.log(euRegex.test(input));
console.log(usRegex.test(input));
return (euRegex.test(input) || usRegex.test(input));
}

0 comments on commit 9837172

Please sign in to comment.