added front end stuff for consolidated vehicle maintenance record.
This commit is contained in:
@@ -682,6 +682,64 @@ namespace CarCareTracker.Controllers
|
||||
};
|
||||
return PartialView("_ReminderMakeUpReport", viewModel);
|
||||
}
|
||||
public IActionResult GetVehicleHistory(int vehicleId)
|
||||
{
|
||||
var vehicleHistory = new VehicleHistoryViewModel();
|
||||
vehicleHistory.VehicleData = _dataAccess.GetVehicleById(vehicleId);
|
||||
vehicleHistory.Odometer = GetMaxMileage(vehicleId).ToString("N0");
|
||||
List<GenericReportModel> reportData = new List<GenericReportModel>();
|
||||
var serviceRecords = _serviceRecordDataAccess.GetServiceRecordsByVehicleId(vehicleId);
|
||||
var repairRecords = _collisionRecordDataAccess.GetCollisionRecordsByVehicleId(vehicleId);
|
||||
var upgradeRecords = _upgradeRecordDataAccess.GetUpgradeRecordsByVehicleId(vehicleId);
|
||||
var taxRecords = _taxRecordDataAccess.GetTaxRecordsByVehicleId(vehicleId);
|
||||
var gasRecords = _gasRecordDataAccess.GetGasRecordsByVehicleId(vehicleId);
|
||||
bool useMPG = bool.Parse(_config[nameof(UserConfig.UseMPG)]);
|
||||
bool useUKMPG = bool.Parse(_config[nameof(UserConfig.UseUKMPG)]);
|
||||
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);
|
||||
var averageMPG = _gasHelper.GetGasRecordViewModels(gasRecords, useMPG, useUKMPG).Average(x => x.MilesPerGallon);
|
||||
vehicleHistory.MPG = averageMPG;
|
||||
//insert servicerecords
|
||||
reportData.AddRange(serviceRecords.Select(x => new GenericReportModel
|
||||
{
|
||||
Date = x.Date,
|
||||
Odometer = x.Mileage,
|
||||
Description = x.Description,
|
||||
Notes = x.Notes,
|
||||
Cost = x.Cost,
|
||||
DataType = ImportMode.ServiceRecord
|
||||
}));
|
||||
//repair records
|
||||
reportData.AddRange(repairRecords.Select(x => new GenericReportModel
|
||||
{
|
||||
Date = x.Date,
|
||||
Odometer = x.Mileage,
|
||||
Description = x.Description,
|
||||
Notes = x.Notes,
|
||||
Cost = x.Cost,
|
||||
DataType = ImportMode.RepairRecord
|
||||
}));
|
||||
reportData.AddRange(upgradeRecords.Select(x => new GenericReportModel
|
||||
{
|
||||
Date = x.Date,
|
||||
Odometer = x.Mileage,
|
||||
Description = x.Description,
|
||||
Notes = x.Notes,
|
||||
Cost = x.Cost,
|
||||
DataType = ImportMode.UpgradeRecord
|
||||
}));
|
||||
reportData.AddRange(taxRecords.Select(x => new GenericReportModel
|
||||
{
|
||||
Date = x.Date,
|
||||
Odometer = 0,
|
||||
Description = x.Description,
|
||||
Notes = x.Notes,
|
||||
Cost = x.Cost,
|
||||
DataType = ImportMode.TaxRecord
|
||||
}));
|
||||
vehicleHistory.VehicleHistory = reportData;
|
||||
return PartialView("_VehicleHistory", vehicleHistory);
|
||||
}
|
||||
[HttpPost]
|
||||
public IActionResult GetCostByMonthByVehicle(int vehicleId, List<ImportMode> selectedMetrics, int year = 0)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace CarCareTracker.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Import model used for importing Gas records.
|
||||
/// Import model used for importing records via CSV.
|
||||
/// </summary>
|
||||
public class ImportModel
|
||||
{
|
||||
@@ -16,6 +16,7 @@
|
||||
public string IsFillToFull { get; set; }
|
||||
public string MissedFuelUp { get; set; }
|
||||
}
|
||||
|
||||
public class ServiceRecordExportModel
|
||||
{
|
||||
public string Date { get; set; }
|
||||
|
||||
15
Models/Report/GenericReportModel.cs
Normal file
15
Models/Report/GenericReportModel.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace CarCareTracker.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Generic Model used for vehicle history report.
|
||||
/// </summary>
|
||||
public class GenericReportModel
|
||||
{
|
||||
public ImportMode DataType { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
public int Odometer { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public decimal Cost { get; set; }
|
||||
}
|
||||
}
|
||||
12
Models/Report/VehicleHistoryViewModel.cs
Normal file
12
Models/Report/VehicleHistoryViewModel.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace CarCareTracker.Models
|
||||
{
|
||||
public class VehicleHistoryViewModel
|
||||
{
|
||||
public Vehicle VehicleData { get; set; }
|
||||
public List<GenericReportModel> VehicleHistory { get; set; }
|
||||
public string Odometer { get; set; }
|
||||
public decimal MPG { get; set; }
|
||||
public decimal TotalCost { get; set; }
|
||||
public decimal TotalGasCost { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
@model List<CostForVehicleByMonth>
|
||||
@if (Model.Any())
|
||||
{
|
||||
<canvas id="bar-chart" class="vehicleDetailTabContainer"></canvas>
|
||||
<canvas id="bar-chart"></canvas>
|
||||
<script>
|
||||
renderChart();
|
||||
function renderChart() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
@model ReportViewModel
|
||||
<div class="row">
|
||||
<div class="row hideOnPrint">
|
||||
<div class="col-md-3 col-12 mt-2">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
@@ -69,11 +69,26 @@
|
||||
</div>
|
||||
<hr />
|
||||
<div class="row">
|
||||
<div class="d-flex justify-content-center">
|
||||
<button onclick="generateVehicleHistoryReport()" class="btn btn-primary btn-md mt-1 mb-1"><i class="bi bi-pencil-square me-2"></i>Generate and Print Vehicle History Report</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="vehicleHistoryReport" class="showOnPrint" ></div>
|
||||
<script>
|
||||
function getYear() {
|
||||
return $("#yearOption").val();
|
||||
}
|
||||
function generateVehicleHistoryReport(){
|
||||
var vehicleId = GetVehicleId().vehicleId;
|
||||
$.get(`/Vehicle/GetVehicleHistory?vehicleId=${vehicleId}`, function(data){
|
||||
if (data) {
|
||||
$("#vehicleHistoryReport").html(data);
|
||||
setTimeout(function () {
|
||||
window.print();
|
||||
}, 500);
|
||||
}
|
||||
})
|
||||
}
|
||||
var debounce = null;
|
||||
function updateCheck(sender) {
|
||||
clearTimeout(debounce);
|
||||
|
||||
74
Views/Vehicle/_VehicleHistory.cshtml
Normal file
74
Views/Vehicle/_VehicleHistory.cshtml
Normal file
@@ -0,0 +1,74 @@
|
||||
@inject IConfiguration Configuration
|
||||
@{
|
||||
var hideZero = bool.Parse(Configuration[nameof(UserConfig.HideZero)]);
|
||||
}
|
||||
@model VehicleHistoryViewModel
|
||||
<div class="vehicleDetailTabContainer">
|
||||
<div class="row mt-2">
|
||||
<div class="d-flex">
|
||||
<img src="/defaults/lubelogger_logo.png" />
|
||||
<span class="display-6 ms-5">Vehicle Maintenance Report</span>
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item">
|
||||
<span class="display-6">@($"{Model.VehicleData.Year} {Model.VehicleData.Make} {Model.VehicleData.Model}")</span>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<span class="lead">@Model.VehicleData.LicensePlate</span>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
@if (Model.VehicleData.IsElectric)
|
||||
{
|
||||
<span><i class="bi bi-ev-station"></i> Electric</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span><i class="bi bi-fuel-pump"></i> Gasoline</span>
|
||||
}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item">Last Reported Odometer Reading: @Model.Odometer</li>
|
||||
<li class="list-group-item">Average Fuel Economy: @Model.MPG.ToString("F")</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>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr class="d-flex">
|
||||
<th scope="col" class="col-1">Type</th>
|
||||
<th scope="col" class="col-1">Date</th>
|
||||
<th scope="col" class="col-2">Odometer</th>
|
||||
<th scope="col" class="col-3">Description</th>
|
||||
<th scope="col" class="col-2">Cost</th>
|
||||
<th scope="col" class="col-3">Notes</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (GenericReportModel reportData in Model.VehicleHistory)
|
||||
{
|
||||
<tr class="d-flex" style="cursor:pointer;">
|
||||
<td class="col-1">@reportData.DataType.ToString()</td>
|
||||
<td class="col-1">@reportData.Date.ToShortDateString()</td>
|
||||
<td class="col-2">@(reportData.Odometer == default ? "---" : reportData.Odometer.ToString("N0"))</td>
|
||||
<td class="col-3">@reportData.Description</td>
|
||||
<td class="col-2">@((hideZero && reportData.Cost == default) ? "---" : reportData.Cost.ToString("C"))</td>
|
||||
<td class="col-3 text-wrap">@CarCareTracker.Helper.StaticHelper.TruncateStrings(reportData.Notes, 100)</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -37,6 +37,12 @@ html {
|
||||
}
|
||||
|
||||
@media print {
|
||||
.hideOnPrint {
|
||||
display:none;
|
||||
}
|
||||
.showOnPrint{
|
||||
display:block !important;
|
||||
}
|
||||
.vehicleDetailTabContainer {
|
||||
background-color: #fff;
|
||||
height: 100%;
|
||||
@@ -50,9 +56,16 @@ html {
|
||||
color: #000 !important;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
ul {
|
||||
border: 0px !important;
|
||||
}
|
||||
li {
|
||||
color: #000 !important;
|
||||
border: 0px !important;
|
||||
}
|
||||
td {
|
||||
color: #000 !important;
|
||||
border: hidden;
|
||||
}
|
||||
|
||||
td.col-1 {
|
||||
@@ -66,6 +79,10 @@ html {
|
||||
th {
|
||||
color: #000 !important;
|
||||
}
|
||||
|
||||
tr{
|
||||
border: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
.chartContainer {
|
||||
|
||||
Reference in New Issue
Block a user