added option to mark gas record as not filled to full so that MPG calculations are deferred
This commit is contained in:
@@ -160,7 +160,8 @@ namespace CarCareTracker.Controllers
|
|||||||
_gasRecordDataAccess.SaveGasRecordToVehicle(convertedRecord);
|
_gasRecordDataAccess.SaveGasRecordToVehicle(convertedRecord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (mode == "servicerecord")
|
}
|
||||||
|
else if (mode == "servicerecord")
|
||||||
{
|
{
|
||||||
var records = csv.GetRecords<ServiceRecordImport>().ToList();
|
var records = csv.GetRecords<ServiceRecordImport>().ToList();
|
||||||
if (records.Any())
|
if (records.Any())
|
||||||
@@ -179,7 +180,8 @@ namespace CarCareTracker.Controllers
|
|||||||
_serviceRecordDataAccess.SaveServiceRecordToVehicle(convertedRecord);
|
_serviceRecordDataAccess.SaveServiceRecordToVehicle(convertedRecord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (mode == "repairrecord")
|
}
|
||||||
|
else if (mode == "repairrecord")
|
||||||
{
|
{
|
||||||
var records = csv.GetRecords<ServiceRecordImport>().ToList();
|
var records = csv.GetRecords<ServiceRecordImport>().ToList();
|
||||||
if (records.Any())
|
if (records.Any())
|
||||||
@@ -198,7 +200,8 @@ namespace CarCareTracker.Controllers
|
|||||||
_collisionRecordDataAccess.SaveCollisionRecordToVehicle(convertedRecord);
|
_collisionRecordDataAccess.SaveCollisionRecordToVehicle(convertedRecord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (mode == "taxrecord")
|
}
|
||||||
|
else if (mode == "taxrecord")
|
||||||
{
|
{
|
||||||
var records = csv.GetRecords<TaxRecordImport>().ToList();
|
var records = csv.GetRecords<TaxRecordImport>().ToList();
|
||||||
if (records.Any())
|
if (records.Any())
|
||||||
@@ -239,14 +242,16 @@ namespace CarCareTracker.Controllers
|
|||||||
bool useMPG = bool.Parse(_config[nameof(UserConfig.UseMPG)]);
|
bool useMPG = bool.Parse(_config[nameof(UserConfig.UseMPG)]);
|
||||||
var computedResults = new List<GasRecordViewModel>();
|
var computedResults = new List<GasRecordViewModel>();
|
||||||
int previousMileage = 0;
|
int previousMileage = 0;
|
||||||
|
decimal unFactoredConsumption = 0.00M;
|
||||||
|
int unFactoredMileage = 0;
|
||||||
//perform computation.
|
//perform computation.
|
||||||
for(int i = 0; i < result.Count; i++)
|
for (int i = 0; i < result.Count; i++)
|
||||||
{
|
{
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
{
|
{
|
||||||
var currentObject = result[i];
|
var currentObject = result[i];
|
||||||
var deltaMileage = currentObject.Mileage - previousMileage;
|
var deltaMileage = currentObject.Mileage - previousMileage;
|
||||||
computedResults.Add(new GasRecordViewModel()
|
var gasRecordViewModel = new GasRecordViewModel()
|
||||||
{
|
{
|
||||||
Id = currentObject.Id,
|
Id = currentObject.Id,
|
||||||
VehicleId = currentObject.VehicleId,
|
VehicleId = currentObject.VehicleId,
|
||||||
@@ -255,10 +260,24 @@ namespace CarCareTracker.Controllers
|
|||||||
Gallons = currentObject.Gallons,
|
Gallons = currentObject.Gallons,
|
||||||
Cost = currentObject.Cost,
|
Cost = currentObject.Cost,
|
||||||
DeltaMileage = deltaMileage,
|
DeltaMileage = deltaMileage,
|
||||||
MilesPerGallon = useMPG ? (deltaMileage / currentObject.Gallons) : 100 / (deltaMileage / currentObject.Gallons),
|
|
||||||
CostPerGallon = (currentObject.Cost / currentObject.Gallons)
|
CostPerGallon = (currentObject.Cost / currentObject.Gallons)
|
||||||
});
|
};
|
||||||
} else
|
if (currentObject.IsFillToFull)
|
||||||
|
{
|
||||||
|
//if user filled to full.
|
||||||
|
gasRecordViewModel.MilesPerGallon = useMPG ? ((unFactoredMileage + deltaMileage) / (unFactoredConsumption + currentObject.Gallons)) : 100 / ((unFactoredMileage + deltaMileage) / (unFactoredConsumption + currentObject.Gallons));
|
||||||
|
//reset unFactored vars
|
||||||
|
unFactoredConsumption = 0;
|
||||||
|
unFactoredMileage = 0;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
unFactoredConsumption += currentObject.Gallons;
|
||||||
|
unFactoredMileage += deltaMileage;
|
||||||
|
gasRecordViewModel.MilesPerGallon = 0;
|
||||||
|
}
|
||||||
|
computedResults.Add(gasRecordViewModel);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
computedResults.Add(new GasRecordViewModel()
|
computedResults.Add(new GasRecordViewModel()
|
||||||
{
|
{
|
||||||
@@ -305,7 +324,8 @@ namespace CarCareTracker.Controllers
|
|||||||
Cost = result.Cost,
|
Cost = result.Cost,
|
||||||
Date = result.Date.ToShortDateString(),
|
Date = result.Date.ToShortDateString(),
|
||||||
Files = result.Files,
|
Files = result.Files,
|
||||||
Gallons = result.Gallons
|
Gallons = result.Gallons,
|
||||||
|
IsFillToFull = result.IsFillToFull
|
||||||
};
|
};
|
||||||
return PartialView("_GasModal", convertedResult);
|
return PartialView("_GasModal", convertedResult);
|
||||||
}
|
}
|
||||||
@@ -349,7 +369,9 @@ namespace CarCareTracker.Controllers
|
|||||||
{
|
{
|
||||||
var result = _serviceRecordDataAccess.GetServiceRecordById(serviceRecordId);
|
var result = _serviceRecordDataAccess.GetServiceRecordById(serviceRecordId);
|
||||||
//convert to Input object.
|
//convert to Input object.
|
||||||
var convertedResult = new ServiceRecordInput { Id = result.Id,
|
var convertedResult = new ServiceRecordInput
|
||||||
|
{
|
||||||
|
Id = result.Id,
|
||||||
Cost = result.Cost,
|
Cost = result.Cost,
|
||||||
Date = result.Date.ToShortDateString(),
|
Date = result.Date.ToShortDateString(),
|
||||||
Description = result.Description,
|
Description = result.Description,
|
||||||
@@ -508,9 +530,10 @@ namespace CarCareTracker.Controllers
|
|||||||
{
|
{
|
||||||
gasRecords.RemoveAll(x => x.Date.Year != year);
|
gasRecords.RemoveAll(x => x.Date.Year != year);
|
||||||
}
|
}
|
||||||
var groupedGasRecord = gasRecords.GroupBy(x => x.Date.Month).OrderBy(x=>x.Key).Select(x => new GasCostForVehicleByMonth {
|
var groupedGasRecord = gasRecords.GroupBy(x => x.Date.Month).OrderBy(x => x.Key).Select(x => new GasCostForVehicleByMonth
|
||||||
|
{
|
||||||
MonthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(x.Key),
|
MonthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(x.Key),
|
||||||
Cost = x.Sum(y=>y.Cost)
|
Cost = x.Sum(y => y.Cost)
|
||||||
}).ToList();
|
}).ToList();
|
||||||
return PartialView("_GasCostByMonthReport", groupedGasRecord);
|
return PartialView("_GasCostByMonthReport", groupedGasRecord);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public decimal Gallons { get; set; }
|
public decimal Gallons { get; set; }
|
||||||
public decimal Cost { get; set; }
|
public decimal Cost { get; set; }
|
||||||
|
public bool IsFillToFull { get; set; } = true;
|
||||||
public List<UploadedFiles> Files { get; set; } = new List<UploadedFiles>();
|
public List<UploadedFiles> Files { get; set; } = new List<UploadedFiles>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,17 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public decimal Gallons { get; set; }
|
public decimal Gallons { get; set; }
|
||||||
public decimal Cost { get; set; }
|
public decimal Cost { get; set; }
|
||||||
|
public bool IsFillToFull { get; set; } = true;
|
||||||
public List<UploadedFiles> Files { get; set; } = new List<UploadedFiles>();
|
public List<UploadedFiles> Files { get; set; } = new List<UploadedFiles>();
|
||||||
public GasRecord ToGasRecord() { return new GasRecord { Id = Id, Cost = Cost, Date = DateTime.Parse(Date), Gallons = Gallons, Mileage = Mileage, VehicleId = VehicleId, Files = Files }; }
|
public GasRecord ToGasRecord() { return new GasRecord {
|
||||||
|
Id = Id,
|
||||||
|
Cost = Cost,
|
||||||
|
Date = DateTime.Parse(Date),
|
||||||
|
Gallons = Gallons,
|
||||||
|
Mileage = Mileage,
|
||||||
|
VehicleId = VehicleId,
|
||||||
|
Files = Files,
|
||||||
|
IsFillToFull = IsFillToFull
|
||||||
|
}; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<div class="d-flex justify-content-between">
|
<div class="d-flex justify-content-between">
|
||||||
<div class="d-flex align-items-center flex-wrap">
|
<div class="d-flex align-items-center flex-wrap">
|
||||||
<span class="ms-2 badge bg-success">@($"# of Gas Records: {Model.Count()}")</span>
|
<span class="ms-2 badge bg-success">@($"# of Gas Records: {Model.Count()}")</span>
|
||||||
@if (Model.Count() > 1)
|
@if (Model.Where(x=>x.MilesPerGallon > 0).Any())
|
||||||
{
|
{
|
||||||
<span class="ms-2 badge bg-primary">@($"Average Fuel Economy: {Model.Where(y => y.MilesPerGallon > 0)?.Average(x => x.MilesPerGallon).ToString("F") ?? "0"}")</span>
|
<span class="ms-2 badge bg-primary">@($"Average Fuel Economy: {Model.Where(y => y.MilesPerGallon > 0)?.Average(x => x.MilesPerGallon).ToString("F") ?? "0"}")</span>
|
||||||
<span class="ms-2 badge bg-primary">@($"Min Fuel Economy: {Model.Where(y => y.MilesPerGallon > 0)?.Min(x => x.MilesPerGallon).ToString("F") ?? "0"}")</span>
|
<span class="ms-2 badge bg-primary">@($"Min Fuel Economy: {Model.Where(y => y.MilesPerGallon > 0)?.Min(x => x.MilesPerGallon).ToString("F") ?? "0"}")</span>
|
||||||
|
|||||||
@@ -22,9 +22,13 @@
|
|||||||
<label for="gasRecordMileage">Odometer Reading(@(useMPG ? "miles" : "kilometers"))</label>
|
<label for="gasRecordMileage">Odometer Reading(@(useMPG ? "miles" : "kilometers"))</label>
|
||||||
<input type="number" id="gasRecordMileage" class="form-control" placeholder="Odometer reading when refueled" value="@(isNew ? "" : Model.Mileage)">
|
<input type="number" id="gasRecordMileage" class="form-control" placeholder="Odometer reading when refueled" value="@(isNew ? "" : Model.Mileage)">
|
||||||
<label for="gasRecordGallons">Fuel Consumption(@(useMPG ? "gallons" : "liters"))</label>
|
<label for="gasRecordGallons">Fuel Consumption(@(useMPG ? "gallons" : "liters"))</label>
|
||||||
<input type="text" id="gasRecordGallons" class="form-control" placeholder="Amount of gas it takes to fill back up to full" value="@(isNew ? "" : Model.Gallons)">
|
<input type="text" id="gasRecordGallons" class="form-control" placeholder="Amount of gas refueled" value="@(isNew ? "" : Model.Gallons)">
|
||||||
|
<div class="form-check form-switch">
|
||||||
|
<input class="form-check-input" type="checkbox" role="switch" id="gasIsFillToFull" checked="@Model.IsFillToFull">
|
||||||
|
<label class="form-check-label" for="gasIsFillToFull">Is Filled To Full</label>
|
||||||
|
</div>
|
||||||
<label for="GasRecordCost">Cost</label>
|
<label for="GasRecordCost">Cost</label>
|
||||||
<input type="number" id="gasRecordCost" class="form-control" placeholder="Cost of gas it takes to fill back up to full" value="@(isNew ? "" : Model.Cost)">
|
<input type="number" id="gasRecordCost" class="form-control" placeholder="Cost of gas refueled" value="@(isNew ? "" : Model.Cost)">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6 col-12">
|
<div class="col-md-6 col-12">
|
||||||
@if (Model.Files.Any())
|
@if (Model.Files.Any())
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ function getAndValidateGasRecordValues() {
|
|||||||
var gasMileage = $("#gasRecordMileage").val();
|
var gasMileage = $("#gasRecordMileage").val();
|
||||||
var gasGallons = $("#gasRecordGallons").val();
|
var gasGallons = $("#gasRecordGallons").val();
|
||||||
var gasCost = $("#gasRecordCost").val();
|
var gasCost = $("#gasRecordCost").val();
|
||||||
|
var gasIsFillToFull = $("#gasIsFillToFull").is(":checked");
|
||||||
var vehicleId = GetVehicleId().vehicleId;
|
var vehicleId = GetVehicleId().vehicleId;
|
||||||
var gasRecordId = getGasRecordModelData().id;
|
var gasRecordId = getGasRecordModelData().id;
|
||||||
//validation
|
//validation
|
||||||
@@ -110,7 +111,8 @@ function getAndValidateGasRecordValues() {
|
|||||||
mileage: gasMileage,
|
mileage: gasMileage,
|
||||||
gallons: gasGallons,
|
gallons: gasGallons,
|
||||||
cost: gasCost,
|
cost: gasCost,
|
||||||
files: uploadedFiles
|
files: uploadedFiles,
|
||||||
|
isFillToFull: gasIsFillToFull
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function deleteGasRecordFile(fileLocation, event) {
|
function deleteGasRecordFile(fileLocation, event) {
|
||||||
|
|||||||
Reference in New Issue
Block a user