From c45a6826bd9ba48088d52a2e0bb67d15e9370b81 Mon Sep 17 00:00:00 2001 From: Scott Pouliot Date: Tue, 5 May 2026 21:46:05 -0400 Subject: [PATCH] Fix time entry 500 and inventory edit pencil visibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove parseInt() from time entry worker select — GUIDs were destroyed to NaN → sent as null → FindByIdAsync(null) threw 500 - Ledger pencil: also show for Adjustment rows (no PO) so scan-without-job entries get an edit button, not just JobUsage rows - InventoryController: always write JobUsage type for scan-based logs; accept Adjustment in edit endpoints; promote Adjustment→JobUsage when a job is assigned via edit Co-Authored-By: Claude Sonnet 4.6 --- .../Controllers/InventoryController.cs | 16 +++++++++++----- .../Views/Inventory/Ledger.cshtml | 2 +- src/PowderCoating.Web/Views/Jobs/Details.cshtml | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/PowderCoating.Web/Controllers/InventoryController.cs b/src/PowderCoating.Web/Controllers/InventoryController.cs index e4ccaf8..ca3313f 100644 --- a/src/PowderCoating.Web/Controllers/InventoryController.cs +++ b/src/PowderCoating.Web/Controllers/InventoryController.cs @@ -1424,8 +1424,8 @@ public class InventoryController : Controller } var userId = _userManager.GetUserId(User) ?? string.Empty; - var txnType = jobId.HasValue ? InventoryTransactionType.JobUsage - : (Enum.TryParse(transactionType, out var parsed) ? parsed : InventoryTransactionType.Adjustment); + // Scan-based logging always records as JobUsage; Adjustment is for manual stock corrections only + var txnType = InventoryTransactionType.JobUsage; item.QuantityOnHand -= quantity; item.UpdatedAt = DateTime.UtcNow; @@ -1719,8 +1719,9 @@ public class InventoryController : Controller var txn = await _unitOfWork.InventoryTransactions.GetByIdAsync(id, false, t => t.Job, t => t.InventoryItem); if (txn == null) return NotFound(); - if (txn.TransactionType != InventoryTransactionType.JobUsage) - return BadRequest("Only JobUsage transactions can be edited here."); + if (txn.TransactionType != InventoryTransactionType.JobUsage + && txn.TransactionType != InventoryTransactionType.Adjustment) + return BadRequest("Only usage transactions can be edited here."); var allJobs = await _unitOfWork.Jobs.FindAsync( j => !j.JobStatus.IsTerminalStatus, @@ -1762,7 +1763,8 @@ public class InventoryController : Controller { var txn = await _unitOfWork.InventoryTransactions.GetByIdAsync(id); if (txn == null) return NotFound(); - if (txn.TransactionType != InventoryTransactionType.JobUsage) + if (txn.TransactionType != InventoryTransactionType.JobUsage + && txn.TransactionType != InventoryTransactionType.Adjustment) return BadRequest(); if (jobId.HasValue) @@ -1777,6 +1779,10 @@ public class InventoryController : Controller txn.Reference = null; } + // Promote Adjustment→JobUsage when a job is assigned so it shows in Powder Usage By Job tab + if (jobId.HasValue && txn.TransactionType == InventoryTransactionType.Adjustment) + txn.TransactionType = InventoryTransactionType.JobUsage; + txn.Notes = notes?.Trim(); txn.TransactionDate = transactionDate.Kind == DateTimeKind.Utc ? transactionDate : DateTime.SpecifyKind(transactionDate, DateTimeKind.Utc); diff --git a/src/PowderCoating.Web/Views/Inventory/Ledger.cshtml b/src/PowderCoating.Web/Views/Inventory/Ledger.cshtml index 497aeca..17a5dde 100644 --- a/src/PowderCoating.Web/Views/Inventory/Ledger.cshtml +++ b/src/PowderCoating.Web/Views/Inventory/Ledger.cshtml @@ -205,7 +205,7 @@ @t.Notes - @if (t.TransactionType == "JobUsage") + @if (t.TransactionType == "JobUsage" || (t.TransactionType == "Adjustment" && t.PurchaseOrderId == null)) {