From 92b3bc3aea55449efb9550a04b165bc15595521f Mon Sep 17 00:00:00 2001 From: "DESKTOP-GENO133\\IvanPlex" Date: Sun, 21 Jan 2024 21:13:03 -0700 Subject: [PATCH 1/7] rough draft of supply store. --- Controllers/VehicleController.cs | 17 ++++++ Views/Vehicle/_ServiceRecordModal.cshtml | 1 + Views/Vehicle/_SupplyStore.cshtml | 20 +++++++ Views/Vehicle/_SupplyUsage.cshtml | 74 ++++++++++++++++++++++++ 4 files changed, 112 insertions(+) create mode 100644 Views/Vehicle/_SupplyStore.cshtml create mode 100644 Views/Vehicle/_SupplyUsage.cshtml diff --git a/Controllers/VehicleController.cs b/Controllers/VehicleController.cs index 0d91b77..6b55132 100644 --- a/Controllers/VehicleController.cs +++ b/Controllers/VehicleController.cs @@ -1253,6 +1253,23 @@ namespace CarCareTracker.Controllers } return PartialView("_SupplyRecords", result); } + [TypeFilter(typeof(CollaboratorFilter))] + [HttpGet] + public IActionResult GetSupplyRecordsForRecordsByVehicleId(int vehicleId) + { + var result = _supplyRecordDataAccess.GetSupplyRecordsByVehicleId(vehicleId); + result.RemoveAll(x => x.Quantity <= 0); + bool _useDescending = _config.GetUserConfig(User).UseDescending; + if (_useDescending) + { + result = result.OrderByDescending(x => x.Date).ToList(); + } + else + { + result = result.OrderBy(x => x.Date).ToList(); + } + return PartialView("_SupplyUsage", result); + } [HttpPost] public IActionResult SaveSupplyRecordToVehicleId(SupplyRecordInput supplyRecord) { diff --git a/Views/Vehicle/_ServiceRecordModal.cshtml b/Views/Vehicle/_ServiceRecordModal.cshtml index 8edbd19..541f68b 100644 --- a/Views/Vehicle/_ServiceRecordModal.cshtml +++ b/Views/Vehicle/_ServiceRecordModal.cshtml @@ -23,6 +23,7 @@ + @await Html.PartialAsync("_SupplyStore", "serviceRecordCost")
diff --git a/Views/Vehicle/_SupplyStore.cshtml b/Views/Vehicle/_SupplyStore.cshtml new file mode 100644 index 0000000..efc0a2f --- /dev/null +++ b/Views/Vehicle/_SupplyStore.cshtml @@ -0,0 +1,20 @@ +@model string +Available Supplies +
+ \ No newline at end of file diff --git a/Views/Vehicle/_SupplyUsage.cshtml b/Views/Vehicle/_SupplyUsage.cshtml new file mode 100644 index 0000000..ea08ac0 --- /dev/null +++ b/Views/Vehicle/_SupplyUsage.cshtml @@ -0,0 +1,74 @@ +@model List +
+
+ + + + + + + + + + + + @foreach (SupplyRecord supplyRecord in Model) + { + + + + + + + + } + +
Qty.In StockSupplyUnit Cost
@supplyRecord.Quantity@supplyRecord.Description@((supplyRecord.Quantity > 0 ? supplyRecord.Cost / supplyRecord.Quantity : 0).ToString("F"))
+
+
+ \ No newline at end of file From aad1655f2e410c6cb971cd6cb75cba805b49a6bb Mon Sep 17 00:00:00 2001 From: "DESKTOP-T0O5CDB\\DESK-555BD" Date: Mon, 22 Jan 2024 10:52:30 -0700 Subject: [PATCH 2/7] added global parsefloat method which derives from C# culture. --- Views/Shared/_Layout.cshtml | 11 +++ Views/Vehicle/Index.cshtml | 5 + Views/Vehicle/_Report.cshtml | 10 +- Views/Vehicle/_ServiceRecordModal.cshtml | 2 +- Views/Vehicle/_SupplyStore.cshtml | 49 +++++++++- Views/Vehicle/_SupplyUsage.cshtml | 115 +++++++++++++++-------- wwwroot/js/gasrecord.js | 4 +- wwwroot/js/reports.js | 10 +- wwwroot/js/shared.js | 7 ++ wwwroot/js/supplyrecord.js | 2 +- 10 files changed, 154 insertions(+), 61 deletions(-) diff --git a/Views/Shared/_Layout.cshtml b/Views/Shared/_Layout.cshtml index 5694d37..146d012 100644 --- a/Views/Shared/_Layout.cshtml +++ b/Views/Shared/_Layout.cshtml @@ -6,6 +6,7 @@ var useDarkMode = userConfig.UseDarkMode; var enableCsvImports = userConfig.EnableCsvImports; var shortDatePattern = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern; + var numberFormat = System.Globalization.CultureInfo.CurrentCulture.NumberFormat; shortDatePattern = shortDatePattern.ToLower(); if (!shortDatePattern.Contains("dd")) { @@ -54,6 +55,16 @@ pattern: "@shortDatePattern" } } + function globalParseFloat(input){ + //remove thousands separator. + var thousandSeparator = "@numberFormat.NumberGroupSeparator"; + var decimalSeparator = "@numberFormat.NumberDecimalSeparator"; + //strip thousands from input. + input = input.replace(thousandSeparator, ""); + //convert to JS format where decimal is only separated by . + input = input.replace(decimalSeparator, "."); + return parseFloat(input); + } @await RenderSectionAsync("Scripts", required: false) diff --git a/Views/Vehicle/Index.cshtml b/Views/Vehicle/Index.cshtml index 0d7f3a5..3a3e42a 100644 --- a/Views/Vehicle/Index.cshtml +++ b/Views/Vehicle/Index.cshtml @@ -153,6 +153,11 @@
+ \ No newline at end of file diff --git a/Views/Vehicle/_SupplyUsage.cshtml b/Views/Vehicle/_SupplyUsage.cshtml index ea08ac0..c58acdc 100644 --- a/Views/Vehicle/_SupplyUsage.cshtml +++ b/Views/Vehicle/_SupplyUsage.cshtml @@ -1,40 +1,57 @@ @model List -
-
- - - - - - - - - - - - @foreach (SupplyRecord supplyRecord in Model) - { - - - - - - + +
Qty.In StockSupplyUnit Cost
@supplyRecord.Quantity@supplyRecord.Description@((supplyRecord.Quantity > 0 ? supplyRecord.Cost / supplyRecord.Quantity : 0).ToString("F"))
+ + + + + + + - } - -
Quantity.In StockDescriptionUnit Cost
+ + + @foreach (SupplyRecord supplyRecord in Model) + { + + + + @supplyRecord.Quantity + @supplyRecord.Description + @((supplyRecord.Quantity > 0 ? supplyRecord.Cost / supplyRecord.Quantity : 0).ToString("F")) + + } + + +
+ \ No newline at end of file diff --git a/wwwroot/js/gasrecord.js b/wwwroot/js/gasrecord.js index 9524575..e7621e1 100644 --- a/wwwroot/js/gasrecord.js +++ b/wwwroot/js/gasrecord.js @@ -91,14 +91,14 @@ function getAndValidateGasRecordValues() { } else { $("#gasRecordMileage").removeClass("is-invalid"); } - if (gasGallons.trim() == '' || parseFloat(gasGallons) <= 0) { + if (gasGallons.trim() == '' || globalParseFloat(gasGallons) <= 0) { hasError = true; $("#gasRecordGallons").addClass("is-invalid"); } else { $("#gasRecordGallons").removeClass("is-invalid"); } if (gasCostType != undefined && gasCostType == 'unit') { - var convertedGasCost = parseFloat(gasCost) * parseFloat(gasGallons); + var convertedGasCost = globalParseFloat(gasCost) * globalParseFloat(gasGallons); gasCost = convertedGasCost.toFixed(2).toString(); if (isNaN(gasCost)) { diff --git a/wwwroot/js/reports.js b/wwwroot/js/reports.js index 2a2a336..1c5bcbb 100644 --- a/wwwroot/js/reports.js +++ b/wwwroot/js/reports.js @@ -12,12 +12,8 @@ function generateVehicleHistoryReport() { } }) } -var debounce = null; -function updateCheck(sender) { - clearTimeout(debounce); - debounce = setTimeout(function () { - refreshBarChart(); - }, 1000); +function updateCheck() { + setDebounce(refreshBarChart); } function refreshMPGChart() { var vehicleId = GetVehicleId().vehicleId; @@ -26,7 +22,7 @@ function refreshMPGChart() { $("#monthFuelMileageReportContent").html(data); }) } -function refreshBarChart(callBack) { +function refreshBarChart() { var selectedMetrics = []; var vehicleId = GetVehicleId().vehicleId; var year = getYear(); diff --git a/wwwroot/js/shared.js b/wwwroot/js/shared.js index 85fe061..04904f6 100644 --- a/wwwroot/js/shared.js +++ b/wwwroot/js/shared.js @@ -147,4 +147,11 @@ function decodeHTMLEntities(text) { return $("