moved more stuff around and gas record functionality.

This commit is contained in:
ivancheahhh
2024-01-03 06:18:39 -07:00
parent 928d18c8e5
commit 8dfaf49e05
6 changed files with 61 additions and 35 deletions

View File

@@ -115,7 +115,19 @@ namespace CarCareTracker.Controllers
}
previousMileage = result[i].Mileage;
}
return PartialView("_GasRecords", computedResults);
return PartialView("_Gas", computedResults);
}
[HttpPost]
public IActionResult SaveGasRecordToVehicleId(GasRecordInput gasRecord)
{
gasRecord.Files = gasRecord.Files.Select(x => { return new UploadedFiles { Name = x.Name, Location = _fileHelper.MoveFileFromTemp(x.Location, "documents/") }; }).ToList();
var result = _gasRecordDataAccess.SaveGasRecordToVehicle(gasRecord.ToGasRecord());
return Json(result);
}
[HttpGet]
public IActionResult GetAddGasRecordPartialView()
{
return PartialView("_GasModal", new GasRecordInput());
}
#endregion
#region "Service Records"

View File

@@ -5,6 +5,7 @@
@section Scripts{
<script src="~/js/vehicle.js" asp-append-version="true"></script>
<script src="~/js/servicerecord.js" asp-append-version="true"></script>
<script src="~/js/gasrecord.js" asp-append-version="true"></script>
}
<div class="container">
<div class="row">
@@ -40,7 +41,7 @@
</ul>
<div class="tab-content" id="vehicleTabContent">
<div class="tab-pane fade show active" id="servicerecord-tab-pane" role="tabpanel"tabindex="0"></div>
<div class="tab-pane fade" id="gas-tab-pane" role="tabpanel" tabindex="0">111</div>
<div class="tab-pane fade" id="gas-tab-pane" role="tabpanel" tabindex="0"></div>
<div class="tab-pane fade" id="tax-tab-pane" role="tabpanel" tabindex="0">222</div>
<div class="tab-pane fade" id="notes-tab-pane" role="tabpanel" tabindex="0">
<div class="row">

View File

@@ -1,12 +1,15 @@
@model List<GasRecordViewModel>
<div class="row">
<div class="d-flex justify-content-between">
<div class="d-flex align-items-center">
<div class="d-flex align-items-center flex-wrap">
<span class="ms-2 badge bg-success">@($"# of Gas Records: {Model.Count()}")</span>
<span class="badge bg-primary">@($"Average Fuel Economy: {Model.Where(y=>y.MilesPerGallon > 0).Average(x => x.MilesPerGallon)}")</span>
<span class="badge bg-primary">@($"Min Fuel Economy: {Model.Min(x => x.MilesPerGallon)}")</span>
<span class="badge bg-primary">@($"Max Fuel Economy: {Model.Max(x => x.MilesPerGallon)}")</span>
<span class="ms-2 badge bg-success">@($"Total Gallons: {Model.Sum(x=>x.Gallons)}")</span>
@if (Model.Count() > 1)
{
<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">@($"Max Fuel Economy: {Model.Max(x => x.MilesPerGallon).ToString("F") ?? "0"}")</span>
}
<span class="ms-2 badge bg-success">@($"Total Fuel Consumed: {Model.Sum(x=>x.Gallons)}")</span>
<span class="ms-2 badge bg-success">@($"Total Cost: {Model.Sum(x => x.Cost).ToString("C")}")</span>
</div>
<div>
@@ -33,10 +36,10 @@
<tr class="d-flex" style="cursor:pointer;" onclick="">
<td class="col-2">@gasRecord.Date</td>
<td class="col-2">@gasRecord.Mileage</td>
<td class="col-2">@gasRecord.Gallons</td>
<td class="col-2">@gasRecord.MilesPerGallon</td>
<td class="col-2">@gasRecord.Gallons.ToString("F")</td>
<td class="col-2">@gasRecord.MilesPerGallon.ToString("F")</td>
<td class="col-2">@gasRecord.Cost.ToString("C")</td>
<td class="col-2">@gasRecord.CostPerGallon</td>
<td class="col-2">@gasRecord.CostPerGallon.ToString("F")</td>
</tr>
}
</tbody>

View File

@@ -1,9 +1,9 @@
@model List<ServiceRecord>
<div class="row">
<div class="d-flex justify-content-between">
<div class="d-flex align-items-center">
<span class="badge bg-primary">@($"Total: {Model.Sum(x=>x.Cost).ToString("C")}")</span>
<span class="ms-2 badge bg-success">@($"# of Service Records: {Model.Count()}")</span>
<div class="d-flex align-items-center flex-wrap">
<span class="badge bg-success">@($"# of Service Records: {Model.Count()}")</span>
<span class="ms-2 badge bg-primary">@($"Total: {Model.Sum(x => x.Cost).ToString("C")}")</span>
</div>
<div>
<button onclick="showAddServiceRecordModal()" class="btn btn-primary btn-md mt-1 mb-1"><i class="bi bi-pencil-square"></i>Add Service Record</button>

View File

@@ -69,28 +69,6 @@ function saveServiceRecordToVehicle(isEdit) {
}
})
}
function uploadVehicleFilesAsync(event) {
let formData = new FormData();
var files = event.files;
for (var x = 0; x < files.length; x++) {
formData.append("file", files[x]);
}
sloader.show();
$.ajax({
url: "/Files/HandleMultipleFileUpload",
data: formData,
cache: false,
processData: false,
contentType: false,
type: 'POST',
success: function (response) {
sloader.hide();
if (response.length > 0) {
uploadedFiles.push.apply(uploadedFiles, response);
}
}
});
}
function getAndValidateServiceRecordValues() {
var serviceDate = $("#serviceRecordDate").val();
var serviceMileage = $("#serviceRecordMileage").val();

View File

@@ -22,6 +22,9 @@ $(document).ready(function () {
case "notes-tab":
getVehicleNote(vehicleId);
break;
case "gas-tab":
getVehicleGasRecords(vehicleId);
break;
}
switch (e.relatedTarget.id) { //clear out previous tabs with grids in them to help with performance
case "servicerecord-tab":
@@ -53,3 +56,32 @@ function DeleteVehicle(vehicleId) {
}
})
}
function getVehicleGasRecords(vehicleId) {
$.get(`/Vehicle/GetGasRecordsByVehicleId?vehicleId=${vehicleId}`, function (data) {
if (data) {
$("#gas-tab-pane").html(data);
}
});
}
function uploadVehicleFilesAsync(event) {
let formData = new FormData();
var files = event.files;
for (var x = 0; x < files.length; x++) {
formData.append("file", files[x]);
}
sloader.show();
$.ajax({
url: "/Files/HandleMultipleFileUpload",
data: formData,
cache: false,
processData: false,
contentType: false,
type: 'POST',
success: function (response) {
sloader.hide();
if (response.length > 0) {
uploadedFiles.push.apply(uploadedFiles, response);
}
}
});
}