From 07ccd1dea96a4edcc2c927cb796759b5b59bd48b Mon Sep 17 00:00:00 2001 From: "DESKTOP-T0O5CDB\\DESK-555BD" Date: Sun, 19 Jan 2025 10:36:32 -0700 Subject: [PATCH] Add sticker printing for supplies. --- Controllers/VehicleController.cs | 4 +- Models/Shared/StickerViewModel.cs | 1 + Views/Home/Index.cshtml | 2 + Views/Vehicle/_Stickers.cshtml | 96 +++++++++++++++++++++++++++++ Views/Vehicle/_SupplyRecords.cshtml | 3 + wwwroot/js/shared.js | 23 ++++++- wwwroot/js/vehicle.js | 17 ----- 7 files changed, 125 insertions(+), 21 deletions(-) diff --git a/Controllers/VehicleController.cs b/Controllers/VehicleController.cs index 616f7d7..33393de 100644 --- a/Controllers/VehicleController.cs +++ b/Controllers/VehicleController.cs @@ -1045,10 +1045,10 @@ namespace CarCareTracker.Controllers { foreach (int recordId in recordIds) { - //stickerViewModel.VehicleRecords.SupplyRecords.Add(_supplyRecordDataAccess.GetSupplyRecordById(recordId)); + var record = _supplyRecordDataAccess.GetSupplyRecordById(recordId); + stickerViewModel.SupplyRecords.Add(record); recordsAdded++; } - } break; case ImportMode.NoteRecord: diff --git a/Models/Shared/StickerViewModel.cs b/Models/Shared/StickerViewModel.cs index 3a2896c..4925ecf 100644 --- a/Models/Shared/StickerViewModel.cs +++ b/Models/Shared/StickerViewModel.cs @@ -6,5 +6,6 @@ public Vehicle VehicleData { get; set; } = new Vehicle(); public List ReminderRecords { get; set; } = new List(); public List GenericRecords { get; set; } = new List(); + public List SupplyRecords { get; set; } = new List(); } } diff --git a/Views/Home/Index.cshtml b/Views/Home/Index.cshtml index dd8b6fd..16c843d 100644 --- a/Views/Home/Index.cshtml +++ b/Views/Home/Index.cshtml @@ -146,6 +146,8 @@ +
+
+} else if (Model.SupplyRecords.Any()){ + @foreach (SupplyRecord supplyRecord in Model.SupplyRecords) + { +
+
+ +
+
+
+ @if(Model.VehicleData.Id != default){ +
+
    +
  • + @($"{Model.VehicleData.Year} {Model.VehicleData.Make} {Model.VehicleData.Model}") +
  • +
  • + @($"{StaticHelper.GetVehicleIdentifier(Model.VehicleData)}") +
  • + @foreach (ExtraField extraField in Model.VehicleData.ExtraFields) + { + if (!string.IsNullOrWhiteSpace(extraField.Value)) + { +
  • + @($"{extraField.Name}: {extraField.Value}") +
  • + } + } +
+
+
+
    +
  • + @($"{translator.Translate(userLanguage, "Description")}: {supplyRecord.Description}") +
  • + @if(!string.IsNullOrWhiteSpace(supplyRecord.PartNumber)){ +
  • + @($"{translator.Translate(userLanguage, "Part Number")}: {supplyRecord.PartNumber}") +
  • + } +
  • + @($"{translator.Translate(userLanguage, "Supplier/Vendor")}: {supplyRecord.PartSupplier}") +
  • +
  • + @($"{translator.Translate(userLanguage, "Cost")}: {supplyRecord.Cost.ToString("C")}") +
  • + @foreach (ExtraField extraField in supplyRecord.ExtraFields) + { +
  • + @($"{extraField.Name}: {extraField.Value}") +
  • + } +
+
+ } else { +
+
    +
  • + @($"{translator.Translate(userLanguage, "Description")}: {supplyRecord.Description}") +
  • + @if (!string.IsNullOrWhiteSpace(supplyRecord.PartNumber)) + { +
  • + @($"{translator.Translate(userLanguage, "Part Number")}: {supplyRecord.PartNumber}") +
  • + } +
  • + @($"{translator.Translate(userLanguage, "Supplier/Vendor")}: {supplyRecord.PartSupplier}") +
  • +
  • + @($"{translator.Translate(userLanguage, "Cost")}: {supplyRecord.Cost.ToString("C")}") +
  • +
+
+
+
    + @foreach (ExtraField extraField in supplyRecord.ExtraFields) + { +
  • + @($"{extraField.Name}: {extraField.Value}") +
  • + } +
+
+ } +
+
+
+
+
+ @(supplyRecord.Notes) +
+
+
+
+ } + } diff --git a/Views/Vehicle/_SupplyRecords.cshtml b/Views/Vehicle/_SupplyRecords.cshtml index dab1607..297b2c1 100644 --- a/Views/Vehicle/_SupplyRecords.cshtml +++ b/Views/Vehicle/_SupplyRecords.cshtml @@ -194,6 +194,9 @@
  • @translator.Translate(userLanguage, "Duplicate")
  • @translator.Translate(userLanguage, "Duplicate To Vehicle")
  • +
  • +
  • @translator.Translate(userLanguage, "Print")
  • +
  • @translator.Translate(userLanguage, "Delete")
  • @if (userColumnPreferences.Any()) diff --git a/wwwroot/js/shared.js b/wwwroot/js/shared.js index 81086ff..257c31a 100644 --- a/wwwroot/js/shared.js +++ b/wwwroot/js/shared.js @@ -362,7 +362,23 @@ function initTagSelector(input, noDataList) { input.tagsinput(); } } - +function getAndValidateSelectedVehicle() { + var selectedVehiclesArray = []; + $("#vehicleSelector :checked").map(function () { + selectedVehiclesArray.push(this.value); + }); + if (selectedVehiclesArray.length == 0) { + return { + hasError: true, + ids: [] + } + } else { + return { + hasError: false, + ids: selectedVehiclesArray + } + } +} function showMobileNav() { $(".lubelogger-mobile-nav").addClass("lubelogger-mobile-nav-show"); } @@ -1282,8 +1298,11 @@ function replenishSupplies() { currentCost = 0; } var currentQuantity = globalParseFloat($('#supplyRecordQuantity').val()); + if (isNaN(currentQuantity)) { + currentQuantity = 0; + } var newQuantity = currentQuantity + replenishedQuantity; - if (replenishedCost.trim() == '') { + if (replenishedCost.trim() == '' && currentCost > 0 && currentQuantity > 0) { var unitCost = currentCost / currentQuantity; var newCost = newQuantity * unitCost; diff --git a/wwwroot/js/vehicle.js b/wwwroot/js/vehicle.js index 94019e1..6ad3c97 100644 --- a/wwwroot/js/vehicle.js +++ b/wwwroot/js/vehicle.js @@ -576,23 +576,6 @@ function showMultipleRemindersSelector() { $("#recurringReminderInput").show(); } } -function getAndValidateSelectedVehicle() { - var selectedVehiclesArray = []; - $("#vehicleSelector :checked").map(function () { - selectedVehiclesArray.push(this.value); - }); - if (selectedVehiclesArray.length == 0) { - return { - hasError: true, - ids: [] - } - } else { - return { - hasError: false, - ids: selectedVehiclesArray - } - } -} function getAndValidateSelectedRecurringReminder() { if ($("#multipleRemindersCheck").is(":checked")) { //validate multiple reminders