fix user preferrred unit in vehicle consolidated report.
This commit is contained in:
@@ -1083,6 +1083,7 @@ namespace CarCareTracker.Controllers
|
|||||||
var gasRecords = _gasRecordDataAccess.GetGasRecordsByVehicleId(vehicleId);
|
var gasRecords = _gasRecordDataAccess.GetGasRecordsByVehicleId(vehicleId);
|
||||||
bool useMPG = _config.GetUserConfig(User).UseMPG;
|
bool useMPG = _config.GetUserConfig(User).UseMPG;
|
||||||
bool useUKMPG = _config.GetUserConfig(User).UseUKMPG;
|
bool useUKMPG = _config.GetUserConfig(User).UseUKMPG;
|
||||||
|
string preferredFuelMileageUnit = _config.GetUserConfig(User).PreferredGasMileageUnit;
|
||||||
vehicleHistory.TotalGasCost = gasRecords.Sum(x => x.Cost);
|
vehicleHistory.TotalGasCost = gasRecords.Sum(x => x.Cost);
|
||||||
vehicleHistory.TotalCost = serviceRecords.Sum(x => x.Cost) + repairRecords.Sum(x => x.Cost) + upgradeRecords.Sum(x => x.Cost) + taxRecords.Sum(x => x.Cost);
|
vehicleHistory.TotalCost = serviceRecords.Sum(x => x.Cost) + repairRecords.Sum(x => x.Cost) + upgradeRecords.Sum(x => x.Cost) + taxRecords.Sum(x => x.Cost);
|
||||||
var averageMPG = "0";
|
var averageMPG = "0";
|
||||||
@@ -1091,7 +1092,19 @@ namespace CarCareTracker.Controllers
|
|||||||
{
|
{
|
||||||
averageMPG = _gasHelper.GetAverageGasMileage(gasViewModels, useMPG);
|
averageMPG = _gasHelper.GetAverageGasMileage(gasViewModels, useMPG);
|
||||||
}
|
}
|
||||||
vehicleHistory.MPG = averageMPG;
|
var fuelEconomyMileageUnit = StaticHelper.GetFuelEconomyUnit(vehicleHistory.VehicleData.IsElectric, vehicleHistory.VehicleData.UseHours, useMPG, useUKMPG);
|
||||||
|
if (fuelEconomyMileageUnit == "l/100km" && preferredFuelMileageUnit == "km/l")
|
||||||
|
{
|
||||||
|
//conversion needed.
|
||||||
|
var newAverageMPG = decimal.Parse(averageMPG, NumberStyles.Any);
|
||||||
|
if (newAverageMPG != 0)
|
||||||
|
{
|
||||||
|
newAverageMPG = 100 / newAverageMPG;
|
||||||
|
}
|
||||||
|
averageMPG = newAverageMPG.ToString("F");
|
||||||
|
fuelEconomyMileageUnit = preferredFuelMileageUnit;
|
||||||
|
}
|
||||||
|
vehicleHistory.MPG = $"{averageMPG} {fuelEconomyMileageUnit}";
|
||||||
//insert servicerecords
|
//insert servicerecords
|
||||||
reportData.AddRange(serviceRecords.Select(x => new GenericReportModel
|
reportData.AddRange(serviceRecords.Select(x => new GenericReportModel
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -140,5 +140,28 @@ namespace CarCareTracker.Helper
|
|||||||
Notes = input.Notes
|
Notes = input.Notes
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetFuelEconomyUnit(bool useKwh, bool useHours, bool useMPG, bool useUKMPG)
|
||||||
|
{
|
||||||
|
string fuelEconomyUnit;
|
||||||
|
if (useKwh)
|
||||||
|
{
|
||||||
|
var distanceUnit = useHours ? "h" : (useMPG ? "mi." : "km");
|
||||||
|
fuelEconomyUnit = useMPG ? $"{distanceUnit}/kWh" : $"kWh/100{distanceUnit}";
|
||||||
|
}
|
||||||
|
else if (useMPG && useUKMPG)
|
||||||
|
{
|
||||||
|
fuelEconomyUnit = useHours ? "h/g" : "mpg";
|
||||||
|
}
|
||||||
|
else if (useUKMPG)
|
||||||
|
{
|
||||||
|
fuelEconomyUnit = useHours ? "l/100h" : "l/100mi.";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fuelEconomyUnit = useHours ? (useMPG ? "h/g" : "l/100h") : (useMPG ? "mpg" : "l/100km");
|
||||||
|
}
|
||||||
|
return fuelEconomyUnit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,28 +2,6 @@
|
|||||||
@inject IConfigHelper config
|
@inject IConfigHelper config
|
||||||
@{
|
@{
|
||||||
var hideZero = config.GetUserConfig(User).HideZero;
|
var hideZero = config.GetUserConfig(User).HideZero;
|
||||||
var useMPG = config.GetUserConfig(User).UseMPG;
|
|
||||||
var useUKMPG = config.GetUserConfig(User).UseUKMPG;
|
|
||||||
var useKwh = Model.VehicleData.IsElectric;
|
|
||||||
var useHours = Model.VehicleData.UseHours;
|
|
||||||
string fuelEconomyUnit;
|
|
||||||
if (useKwh)
|
|
||||||
{
|
|
||||||
var distanceUnit = useHours ? "h" : (useMPG ? "mi." : "km");
|
|
||||||
fuelEconomyUnit = useMPG ? $"{distanceUnit}/kWh" : $"kWh/100{distanceUnit}";
|
|
||||||
}
|
|
||||||
else if (useMPG && useUKMPG)
|
|
||||||
{
|
|
||||||
fuelEconomyUnit = useHours ? "h/g" : "mpg";
|
|
||||||
}
|
|
||||||
else if (useUKMPG)
|
|
||||||
{
|
|
||||||
fuelEconomyUnit = useHours ? "l/100h" : "l/100mi.";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fuelEconomyUnit = useHours ? (useMPG ? "h/g" : "l/100h") : (useMPG ? "mpg" : "l/100km");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@model VehicleHistoryViewModel
|
@model VehicleHistoryViewModel
|
||||||
<div class="vehicleDetailTabContainer">
|
<div class="vehicleDetailTabContainer">
|
||||||
@@ -58,7 +36,7 @@
|
|||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<ul class="list-group">
|
<ul class="list-group">
|
||||||
<li class="list-group-item">Last Reported Odometer Reading: @Model.Odometer</li>
|
<li class="list-group-item">Last Reported Odometer Reading: @Model.Odometer</li>
|
||||||
<li class="list-group-item">Average Fuel Economy: @($"{Model.MPG} {fuelEconomyUnit}")</li>
|
<li class="list-group-item">Average Fuel Economy: @($"{Model.MPG}")</li>
|
||||||
<li class="list-group-item">Total Spent(excl. fuel): @Model.TotalCost.ToString("C")</li>
|
<li class="list-group-item">Total Spent(excl. fuel): @Model.TotalCost.ToString("C")</li>
|
||||||
<li class="list-group-item">Total Spent on Fuel: @Model.TotalGasCost.ToString("C")</li>
|
<li class="list-group-item">Total Spent on Fuel: @Model.TotalGasCost.ToString("C")</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
Reference in New Issue
Block a user