Merge branch 'main' into Hargata/supply.store
This commit is contained in:
@@ -365,6 +365,58 @@ namespace CarCareTracker.Controllers
|
|||||||
return Json(result);
|
return Json(result);
|
||||||
}
|
}
|
||||||
[TypeFilter(typeof(CollaboratorFilter))]
|
[TypeFilter(typeof(CollaboratorFilter))]
|
||||||
|
[HttpPost]
|
||||||
|
[Route("/api/vehicle/gasrecords/add")]
|
||||||
|
public IActionResult AddGasRecord(int vehicleId, GasRecordExportModel input)
|
||||||
|
{
|
||||||
|
var response = new OperationResponse();
|
||||||
|
if (vehicleId == default)
|
||||||
|
{
|
||||||
|
response.Success = false;
|
||||||
|
response.Message = "Must provide a valid vehicle id";
|
||||||
|
Response.StatusCode = 400;
|
||||||
|
return Json(response);
|
||||||
|
}
|
||||||
|
if (string.IsNullOrWhiteSpace(input.Date) ||
|
||||||
|
string.IsNullOrWhiteSpace(input.Odometer) ||
|
||||||
|
string.IsNullOrWhiteSpace(input.FuelConsumed) ||
|
||||||
|
string.IsNullOrWhiteSpace(input.Cost) ||
|
||||||
|
string.IsNullOrWhiteSpace(input.IsFillToFull) ||
|
||||||
|
string.IsNullOrWhiteSpace(input.MissedFuelUp)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
response.Success = false;
|
||||||
|
response.Message = "Input object invalid, Date, Odometer, FuelConsumed, IsFillToFull, MissedFuelUp, and Cost cannot be empty.";
|
||||||
|
Response.StatusCode = 400;
|
||||||
|
return Json(response);
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var gasRecord = new GasRecord()
|
||||||
|
{
|
||||||
|
VehicleId = vehicleId,
|
||||||
|
Date = DateTime.Parse(input.Date),
|
||||||
|
Mileage = int.Parse(input.Odometer),
|
||||||
|
Gallons = decimal.Parse(input.FuelConsumed),
|
||||||
|
IsFillToFull = bool.Parse(input.IsFillToFull),
|
||||||
|
MissedFuelUp = bool.Parse(input.MissedFuelUp),
|
||||||
|
Notes = string.IsNullOrWhiteSpace(input.Notes) ? "" : input.Notes,
|
||||||
|
Cost = decimal.Parse(input.Cost)
|
||||||
|
};
|
||||||
|
_gasRecordDataAccess.SaveGasRecordToVehicle(gasRecord);
|
||||||
|
response.Success = true;
|
||||||
|
response.Message = "Gas Record Added";
|
||||||
|
return Json(response);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
response.Success = false;
|
||||||
|
response.Message = ex.Message;
|
||||||
|
Response.StatusCode = 500;
|
||||||
|
return Json(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[TypeFilter(typeof(CollaboratorFilter))]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("/api/vehicle/reminders")]
|
[Route("/api/vehicle/reminders")]
|
||||||
public IActionResult Reminders(int vehicleId)
|
public IActionResult Reminders(int vehicleId)
|
||||||
|
|||||||
@@ -201,6 +201,30 @@
|
|||||||
useUKMPG(bool) - Use UK Imperial Calculation
|
useUKMPG(bool) - Use UK Imperial Calculation
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-1">
|
||||||
|
POST
|
||||||
|
</div>
|
||||||
|
<div class="col-5">
|
||||||
|
<code>/api/vehicle/gasrecords/add</code>
|
||||||
|
</div>
|
||||||
|
<div class="col-3">
|
||||||
|
Adds Gas Record to the vehicle
|
||||||
|
</div>
|
||||||
|
<div class="col-3">
|
||||||
|
vehicleId - Id of Vehicle
|
||||||
|
<br />
|
||||||
|
Body(form-data): {<br />
|
||||||
|
date - Date to be entered<br />
|
||||||
|
odometer - Odometer reading<br />
|
||||||
|
fuelConsumed - Fuel Consumed<br />
|
||||||
|
cost - Cost<br />
|
||||||
|
isFillToFull(bool) - Filled To Full<br />
|
||||||
|
missedFuelUp(bool) - Missed Fuel Up<br />
|
||||||
|
notes - notes(optional)<br />
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-1">
|
<div class="col-1">
|
||||||
GET
|
GET
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
@model List<CostForVehicleByMonth>
|
@model List<CostForVehicleByMonth>
|
||||||
|
@{
|
||||||
|
var barGraphColors = new string[] { "#00876c", "#43956e", "#67a371", "#89b177", "#a9be80", "#c8cb8b", "#e6d79b", "#e4c281", "#e3ab6b", "#e2925b", "#e07952", "#db5d4f" };
|
||||||
|
var sortedByMPG = Model.OrderBy(x => x.Cost).ToList();
|
||||||
|
}
|
||||||
@if (Model.Any())
|
@if (Model.Any())
|
||||||
{
|
{
|
||||||
<canvas id="bar-chart"></canvas>
|
<canvas id="bar-chart"></canvas>
|
||||||
@@ -7,11 +11,15 @@
|
|||||||
function renderChart() {
|
function renderChart() {
|
||||||
var barGraphLabels = [];
|
var barGraphLabels = [];
|
||||||
var barGraphData = [];
|
var barGraphData = [];
|
||||||
|
//color gradient from high to low
|
||||||
|
var barGraphColors = [];
|
||||||
var useDarkMode = getGlobalConfig().useDarkMode;
|
var useDarkMode = getGlobalConfig().useDarkMode;
|
||||||
@foreach (CostForVehicleByMonth gasCost in Model)
|
@foreach (CostForVehicleByMonth gasCost in Model)
|
||||||
{
|
{
|
||||||
@:barGraphLabels.push("@gasCost.MonthName");
|
@:barGraphLabels.push("@gasCost.MonthName");
|
||||||
@:barGraphData.push(@gasCost.Cost);
|
@:barGraphData.push(@gasCost.Cost);
|
||||||
|
var index = sortedByMPG.FindIndex(x => x.MonthName == gasCost.MonthName);
|
||||||
|
@:barGraphColors.push('@barGraphColors[index]');
|
||||||
}
|
}
|
||||||
new Chart($("#bar-chart"), {
|
new Chart($("#bar-chart"), {
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
@@ -20,14 +28,20 @@
|
|||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
label: "Expenses by Month",
|
label: "Expenses by Month",
|
||||||
backgroundColor: ["#00876c", "#43956e", "#67a371", "#89b177", "#a9be80", "#c8cb8b", "#e6d79b", "#e4c281", "#e3ab6b", "#e2925b", "#e07952", "#db5d4f"],
|
backgroundColor: barGraphColors,
|
||||||
data: barGraphData
|
data: barGraphData
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
plugins: {
|
plugins: {
|
||||||
|
title: {
|
||||||
|
display: true,
|
||||||
|
color: useDarkMode ? "#fff" : "#000",
|
||||||
|
text: 'Expenses by Month'
|
||||||
|
},
|
||||||
legend: {
|
legend: {
|
||||||
|
display: false,
|
||||||
labels: {
|
labels: {
|
||||||
color: useDarkMode ? "#fff" : "#000"
|
color: useDarkMode ? "#fff" : "#000"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,26 @@
|
|||||||
@model List<CostForVehicleByMonth>
|
@model List<CostForVehicleByMonth>
|
||||||
|
@{
|
||||||
|
var barGraphColors = new string[] { "#00876c", "#43956e", "#67a371", "#89b177", "#a9be80", "#c8cb8b", "#e6d79b", "#e4c281", "#e3ab6b", "#e2925b", "#e07952", "#db5d4f" };
|
||||||
|
var sortedByMPG = Model.OrderByDescending(x => x.Cost).ToList();
|
||||||
|
}
|
||||||
@if (Model.Any())
|
@if (Model.Any())
|
||||||
{
|
{
|
||||||
|
|
||||||
<canvas id="bar-chart-mpg"></canvas>
|
<canvas id="bar-chart-mpg"></canvas>
|
||||||
<script>
|
<script>
|
||||||
renderChart();
|
renderChart();
|
||||||
function renderChart() {
|
function renderChart() {
|
||||||
var barGraphLabels = [];
|
var barGraphLabels = [];
|
||||||
var barGraphData = [];
|
var barGraphData = [];
|
||||||
|
//color gradient from high to low
|
||||||
|
var barGraphColors = [];
|
||||||
var useDarkMode = getGlobalConfig().useDarkMode;
|
var useDarkMode = getGlobalConfig().useDarkMode;
|
||||||
@foreach (CostForVehicleByMonth gasCost in Model)
|
@foreach (CostForVehicleByMonth gasCost in Model)
|
||||||
{
|
{
|
||||||
@:barGraphLabels.push("@gasCost.MonthName");
|
@:barGraphLabels.push("@gasCost.MonthName");
|
||||||
@:barGraphData.push(@gasCost.Cost);
|
@:barGraphData.push(@gasCost.Cost);
|
||||||
|
var index = sortedByMPG.FindIndex(x => x.MonthName == gasCost.MonthName);
|
||||||
|
@:barGraphColors.push('@barGraphColors[index]');
|
||||||
}
|
}
|
||||||
new Chart($("#bar-chart-mpg"), {
|
new Chart($("#bar-chart-mpg"), {
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
@@ -20,14 +29,20 @@
|
|||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
label: "Fuel Mileage by Month",
|
label: "Fuel Mileage by Month",
|
||||||
backgroundColor: ["#00876c", "#43956e", "#67a371", "#89b177", "#a9be80", "#c8cb8b", "#e6d79b", "#e4c281", "#e3ab6b", "#e2925b", "#e07952", "#db5d4f"],
|
backgroundColor: barGraphColors,
|
||||||
data: barGraphData
|
data: barGraphData
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
plugins: {
|
plugins: {
|
||||||
|
title: {
|
||||||
|
display: true,
|
||||||
|
color: useDarkMode ? "#fff" : "#000",
|
||||||
|
text: 'Fuel Mileage by Month'
|
||||||
|
},
|
||||||
legend: {
|
legend: {
|
||||||
|
display: false,
|
||||||
labels: {
|
labels: {
|
||||||
color: useDarkMode ? "#fff" : "#000"
|
color: useDarkMode ? "#fff" : "#000"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user