feat: Add Stock Items UI and update Supplier offerings

- Add Stock Items index page listing all stock items
- Add Stock Items edit page with supplier offerings management
- Update Suppliers edit page to manage offerings (select from stock
  items instead of material+length)
- Add Stock Items navigation link to sidebar

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-02 22:32:32 -05:00
parent 6797d1e4fd
commit 5cc088ea6b
4 changed files with 567 additions and 101 deletions

View File

@@ -23,6 +23,11 @@
<span class="bi bi-box-nav-menu" aria-hidden="true"></span> Materials
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="stock">
<span class="bi bi-boxes-nav-menu" aria-hidden="true"></span> Stock Items
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="suppliers">
<span class="bi bi-building-nav-menu" aria-hidden="true"></span> Suppliers

View File

@@ -0,0 +1,371 @@
@page "/stock/new"
@page "/stock/{Id:int}"
@inject StockItemService StockItemService
@inject MaterialService MaterialService
@inject SupplierService SupplierService
@inject NavigationManager Navigation
@using CutList.Core.Formatting
<PageTitle>@(IsNew ? "Add Stock Item" : "Edit Stock Item")</PageTitle>
<h1>@(IsNew ? "Add Stock Item" : $"{stockItem.Material?.DisplayName} - {ArchUnits.FormatFromInches((double)stockItem.LengthInches)}")</h1>
@if (loading)
{
<p><em>Loading...</em></p>
}
else
{
<div class="row">
<div class="col-lg-6 mb-4">
<div class="card">
<div class="card-header">
<h5 class="mb-0">Stock Item Details</h5>
</div>
<div class="card-body">
<EditForm Model="stockItem" OnValidSubmit="SaveStockItemAsync">
<DataAnnotationsValidator />
<div class="mb-3">
<label class="form-label">Material</label>
<select class="form-select" @bind="stockItem.MaterialId" disabled="@(!IsNew)">
<option value="0">-- Select Material --</option>
@foreach (var material in materials)
{
<option value="@material.Id">@material.DisplayName</option>
}
</select>
</div>
<div class="mb-3">
<label class="form-label">Length</label>
@if (IsNew)
{
<LengthInput @bind-Value="stockItem.LengthInches" />
}
else
{
<input type="text" class="form-control" value="@ArchUnits.FormatFromInches((double)stockItem.LengthInches)" readonly />
}
</div>
<div class="mb-3">
<label class="form-label">Name (optional)</label>
<InputText class="form-control" @bind-Value="stockItem.Name" placeholder="Custom display name" />
</div>
@if (!string.IsNullOrEmpty(errorMessage))
{
<div class="alert alert-danger">@errorMessage</div>
}
<div class="d-flex gap-2">
<button type="submit" class="btn btn-primary" disabled="@saving">
@if (saving)
{
<span class="spinner-border spinner-border-sm me-1"></span>
}
@(IsNew ? "Create Stock Item" : "Save Changes")
</button>
<a href="stock" class="btn btn-outline-secondary">@(IsNew ? "Cancel" : "Back to List")</a>
</div>
</EditForm>
</div>
</div>
</div>
@if (!IsNew)
{
<div class="col-lg-6">
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="mb-0">Supplier Offerings</h5>
<button class="btn btn-sm btn-primary" @onclick="ShowAddOfferingForm">Add Offering</button>
</div>
<div class="card-body">
@if (showOfferingForm)
{
<div class="border rounded p-3 mb-3 bg-light">
<h6>@(editingOffering == null ? "Add Offering" : "Edit Offering")</h6>
<div class="row g-2">
<div class="col-12">
<label class="form-label">Supplier</label>
<select class="form-select" @bind="newOffering.SupplierId">
<option value="0">-- Select Supplier --</option>
@foreach (var supplier in suppliers)
{
<option value="@supplier.Id">@supplier.Name</option>
}
</select>
</div>
<div class="col-md-6">
<label class="form-label">Part Number</label>
<InputText class="form-control" @bind-Value="newOffering.PartNumber" />
</div>
<div class="col-md-6">
<label class="form-label">Price</label>
<InputNumber class="form-control" @bind-Value="newOffering.Price" placeholder="0.00" />
</div>
<div class="col-12">
<label class="form-label">Supplier Description</label>
<InputText class="form-control" @bind-Value="newOffering.SupplierDescription" />
</div>
<div class="col-12">
<label class="form-label">Notes</label>
<InputText class="form-control" @bind-Value="newOffering.Notes" />
</div>
</div>
@if (!string.IsNullOrEmpty(offeringErrorMessage))
{
<div class="alert alert-danger mt-2 mb-0">@offeringErrorMessage</div>
}
<div class="mt-3 d-flex gap-2">
<button class="btn btn-primary btn-sm" @onclick="SaveOfferingAsync" disabled="@savingOffering">
@if (savingOffering)
{
<span class="spinner-border spinner-border-sm me-1"></span>
}
@(editingOffering == null ? "Add" : "Save")
</button>
<button class="btn btn-outline-secondary btn-sm" @onclick="CancelOfferingForm">Cancel</button>
</div>
</div>
}
@if (offerings.Count == 0)
{
<p class="text-muted">No supplier offerings configured yet.</p>
}
else
{
<table class="table table-sm">
<thead>
<tr>
<th>Supplier</th>
<th>Part #</th>
<th>Price</th>
<th style="width: 100px;">Actions</th>
</tr>
</thead>
<tbody>
@foreach (var offering in offerings)
{
<tr>
<td>@offering.Supplier.Name</td>
<td>@(offering.PartNumber ?? "-")</td>
<td>@(offering.Price.HasValue ? offering.Price.Value.ToString("C") : "-")</td>
<td>
<button class="btn btn-sm btn-outline-primary" @onclick="() => EditOffering(offering)">Edit</button>
<button class="btn btn-sm btn-outline-danger" @onclick="() => ConfirmDeleteOffering(offering)">Delete</button>
</td>
</tr>
}
</tbody>
</table>
}
</div>
</div>
</div>
}
</div>
}
<ConfirmDialog @ref="deleteOfferingDialog"
Title="Delete Offering"
Message="@deleteOfferingMessage"
ConfirmText="Delete"
OnConfirm="DeleteOfferingConfirmed" />
@code {
[Parameter]
public int? Id { get; set; }
private StockItem stockItem = new();
private List<Material> materials = new();
private List<Supplier> suppliers = new();
private List<SupplierOffering> offerings = new();
private bool loading = true;
private bool saving;
private bool savingOffering;
private string? errorMessage;
private string? offeringErrorMessage;
private bool showOfferingForm;
private SupplierOffering newOffering = new();
private SupplierOffering? editingOffering;
private ConfirmDialog deleteOfferingDialog = null!;
private SupplierOffering? offeringToDelete;
private string deleteOfferingMessage = "";
private bool IsNew => !Id.HasValue;
protected override async Task OnInitializedAsync()
{
materials = await MaterialService.GetAllAsync();
suppliers = await SupplierService.GetAllAsync();
if (Id.HasValue)
{
var existing = await StockItemService.GetByIdAsync(Id.Value);
if (existing == null)
{
Navigation.NavigateTo("stock");
return;
}
stockItem = existing;
offerings = existing.SupplierOfferings.Where(o => o.IsActive).ToList();
}
loading = false;
}
private async Task SaveStockItemAsync()
{
errorMessage = null;
saving = true;
try
{
if (stockItem.MaterialId == 0)
{
errorMessage = "Please select a material";
return;
}
if (stockItem.LengthInches <= 0)
{
errorMessage = "Length must be greater than zero";
return;
}
var exists = await StockItemService.ExistsAsync(
stockItem.MaterialId,
stockItem.LengthInches,
IsNew ? null : stockItem.Id);
if (exists)
{
errorMessage = "A stock item with this material and length already exists";
return;
}
if (IsNew)
{
var created = await StockItemService.CreateAsync(stockItem);
Navigation.NavigateTo($"stock/{created.Id}");
}
else
{
await StockItemService.UpdateAsync(stockItem);
}
}
finally
{
saving = false;
}
}
private void ShowAddOfferingForm()
{
editingOffering = null;
newOffering = new SupplierOffering { StockItemId = Id!.Value };
showOfferingForm = true;
offeringErrorMessage = null;
}
private void EditOffering(SupplierOffering offering)
{
editingOffering = offering;
newOffering = new SupplierOffering
{
Id = offering.Id,
StockItemId = offering.StockItemId,
SupplierId = offering.SupplierId,
PartNumber = offering.PartNumber,
SupplierDescription = offering.SupplierDescription,
Price = offering.Price,
Notes = offering.Notes
};
showOfferingForm = true;
offeringErrorMessage = null;
}
private void CancelOfferingForm()
{
showOfferingForm = false;
editingOffering = null;
offeringErrorMessage = null;
}
private async Task SaveOfferingAsync()
{
offeringErrorMessage = null;
savingOffering = true;
try
{
if (newOffering.SupplierId == 0)
{
offeringErrorMessage = "Please select a supplier";
return;
}
var exists = await SupplierService.OfferingExistsAsync(
newOffering.SupplierId,
newOffering.StockItemId,
editingOffering?.Id);
if (exists)
{
offeringErrorMessage = "This supplier already has an offering for this stock item";
return;
}
if (editingOffering == null)
{
await SupplierService.AddOfferingAsync(newOffering);
}
else
{
await SupplierService.UpdateOfferingAsync(newOffering);
}
// Refresh the stock item to get updated offerings
var updated = await StockItemService.GetByIdAsync(Id!.Value);
if (updated != null)
{
stockItem = updated;
offerings = updated.SupplierOfferings.Where(o => o.IsActive).ToList();
}
showOfferingForm = false;
editingOffering = null;
}
finally
{
savingOffering = false;
}
}
private void ConfirmDeleteOffering(SupplierOffering offering)
{
offeringToDelete = offering;
deleteOfferingMessage = $"Are you sure you want to delete the offering from {offering.Supplier.Name}?";
deleteOfferingDialog.Show();
}
private async Task DeleteOfferingConfirmed()
{
if (offeringToDelete != null)
{
await SupplierService.DeleteOfferingAsync(offeringToDelete.Id);
// Refresh the stock item to get updated offerings
var updated = await StockItemService.GetByIdAsync(Id!.Value);
if (updated != null)
{
stockItem = updated;
offerings = updated.SupplierOfferings.Where(o => o.IsActive).ToList();
}
}
}
}

View File

@@ -0,0 +1,85 @@
@page "/stock"
@inject StockItemService StockItemService
@inject NavigationManager Navigation
@using CutList.Core.Formatting
<PageTitle>Stock Items</PageTitle>
<div class="d-flex justify-content-between align-items-center mb-3">
<h1>Stock Items</h1>
<a href="stock/new" class="btn btn-primary">Add Stock Item</a>
</div>
@if (loading)
{
<p><em>Loading...</em></p>
}
else if (stockItems.Count == 0)
{
<div class="alert alert-info">
No stock items found. <a href="stock/new">Add your first stock item</a>.
</div>
}
else
{
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Material</th>
<th>Length</th>
<th>Name</th>
<th style="width: 120px;">Actions</th>
</tr>
</thead>
<tbody>
@foreach (var item in stockItems)
{
<tr>
<td>@item.Material.DisplayName</td>
<td>@ArchUnits.FormatFromInches((double)item.LengthInches)</td>
<td>@(item.Name ?? "-")</td>
<td>
<a href="stock/@item.Id" class="btn btn-sm btn-outline-primary">Edit</a>
<button class="btn btn-sm btn-outline-danger" @onclick="() => ConfirmDelete(item)">Delete</button>
</td>
</tr>
}
</tbody>
</table>
}
<ConfirmDialog @ref="deleteDialog"
Title="Delete Stock Item"
Message="@deleteMessage"
ConfirmText="Delete"
OnConfirm="DeleteConfirmed" />
@code {
private List<StockItem> stockItems = new();
private bool loading = true;
private ConfirmDialog deleteDialog = null!;
private StockItem? itemToDelete;
private string deleteMessage = "";
protected override async Task OnInitializedAsync()
{
stockItems = await StockItemService.GetAllAsync();
loading = false;
}
private void ConfirmDelete(StockItem item)
{
itemToDelete = item;
deleteMessage = $"Are you sure you want to delete \"{item.Material.DisplayName} - {ArchUnits.FormatFromInches((double)item.LengthInches)}\"?";
deleteDialog.Show();
}
private async Task DeleteConfirmed()
{
if (itemToDelete != null)
{
await StockItemService.DeleteAsync(itemToDelete.Id);
stockItems = await StockItemService.GetAllAsync();
}
}
}

View File

@@ -1,9 +1,10 @@
@page "/suppliers/new"
@page "/suppliers/{Id:int}"
@inject SupplierService SupplierService
@inject MaterialService MaterialService
@inject NavigationManager Navigation
@inject CutList.Web.Data.ApplicationDbContext DbContext
@using CutList.Core.Formatting
@using Microsoft.EntityFrameworkCore
<PageTitle>@(IsNew ? "Add Supplier" : "Edit Supplier")</PageTitle>
@@ -66,80 +67,84 @@ else
<div class="col-lg-6">
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="mb-0">Stock Lengths</h5>
<button class="btn btn-sm btn-primary" @onclick="ShowAddStockForm">Add Stock</button>
<h5 class="mb-0">Supplier Offerings</h5>
<button class="btn btn-sm btn-primary" @onclick="ShowAddOfferingForm">Add Offering</button>
</div>
<div class="card-body">
@if (showStockForm)
@if (showOfferingForm)
{
<div class="border rounded p-3 mb-3 bg-light">
<h6>@(editingStock == null ? "Add Stock Length" : "Edit Stock Length")</h6>
<h6>@(editingOffering == null ? "Add Offering" : "Edit Offering")</h6>
<div class="row g-2">
<div class="col-md-6">
<label class="form-label">Material</label>
<select class="form-select" @bind="newStock.MaterialId">
<option value="0">-- Select Material --</option>
@foreach (var material in materials)
<div class="col-12">
<label class="form-label">Stock Item</label>
<select class="form-select" @bind="newOffering.StockItemId">
<option value="0">-- Select Stock Item --</option>
@foreach (var stockItem in stockItems)
{
<option value="@material.Id">@material.DisplayName</option>
<option value="@stockItem.Id">@stockItem.Material.DisplayName - @ArchUnits.FormatFromInches((double)stockItem.LengthInches)</option>
}
</select>
</div>
<div class="col-md-6">
<label class="form-label">Length</label>
<LengthInput @bind-Value="newStock.LengthInches" />
<label class="form-label">Part Number</label>
<InputText class="form-control" @bind-Value="newOffering.PartNumber" />
</div>
<div class="col-md-6">
<label class="form-label">Price (optional)</label>
<InputNumber class="form-control" @bind-Value="newStock.Price" placeholder="0.00" />
<label class="form-label">Price</label>
<InputNumber class="form-control" @bind-Value="newOffering.Price" placeholder="0.00" />
</div>
<div class="col-md-6">
<div class="col-12">
<label class="form-label">Supplier Description</label>
<InputText class="form-control" @bind-Value="newOffering.SupplierDescription" />
</div>
<div class="col-12">
<label class="form-label">Notes</label>
<InputText class="form-control" @bind-Value="newStock.Notes" />
<InputText class="form-control" @bind-Value="newOffering.Notes" />
</div>
</div>
@if (!string.IsNullOrEmpty(stockErrorMessage))
@if (!string.IsNullOrEmpty(offeringErrorMessage))
{
<div class="alert alert-danger mt-2 mb-0">@stockErrorMessage</div>
<div class="alert alert-danger mt-2 mb-0">@offeringErrorMessage</div>
}
<div class="mt-3 d-flex gap-2">
<button class="btn btn-primary btn-sm" @onclick="SaveStockAsync" disabled="@savingStock">
@if (savingStock)
<button class="btn btn-primary btn-sm" @onclick="SaveOfferingAsync" disabled="@savingOffering">
@if (savingOffering)
{
<span class="spinner-border spinner-border-sm me-1"></span>
}
@(editingStock == null ? "Add" : "Save")
@(editingOffering == null ? "Add" : "Save")
</button>
<button class="btn btn-outline-secondary btn-sm" @onclick="CancelStockForm">Cancel</button>
<button class="btn btn-outline-secondary btn-sm" @onclick="CancelOfferingForm">Cancel</button>
</div>
</div>
}
@if (stocks.Count == 0)
@if (offerings.Count == 0)
{
<p class="text-muted">No stock lengths configured yet.</p>
<p class="text-muted">No offerings configured yet.</p>
}
else
{
<table class="table table-sm">
<thead>
<tr>
<th>Material</th>
<th>Length</th>
<th>Stock Item</th>
<th>Part #</th>
<th>Price</th>
<th style="width: 100px;">Actions</th>
</tr>
</thead>
<tbody>
@foreach (var stock in stocks)
@foreach (var offering in offerings)
{
<tr>
<td>@stock.Material.DisplayName</td>
<td>@ArchUnits.FormatFromInches((double)stock.LengthInches)</td>
<td>@(stock.Price.HasValue ? stock.Price.Value.ToString("C") : "-")</td>
<td>@offering.StockItem.Material.DisplayName - @ArchUnits.FormatFromInches((double)offering.StockItem.LengthInches)</td>
<td>@(offering.PartNumber ?? "-")</td>
<td>@(offering.Price.HasValue ? offering.Price.Value.ToString("C") : "-")</td>
<td>
<button class="btn btn-sm btn-outline-primary" @onclick="() => EditStock(stock)">Edit</button>
<button class="btn btn-sm btn-outline-danger" @onclick="() => ConfirmDeleteStock(stock)">Delete</button>
<button class="btn btn-sm btn-outline-primary" @onclick="() => EditOffering(offering)">Edit</button>
<button class="btn btn-sm btn-outline-danger" @onclick="() => ConfirmDeleteOffering(offering)">Delete</button>
</td>
</tr>
}
@@ -153,38 +158,44 @@ else
</div>
}
<ConfirmDialog @ref="deleteStockDialog"
Title="Delete Stock Length"
Message="@deleteStockMessage"
<ConfirmDialog @ref="deleteOfferingDialog"
Title="Delete Offering"
Message="@deleteOfferingMessage"
ConfirmText="Delete"
OnConfirm="DeleteStockConfirmed" />
OnConfirm="DeleteOfferingConfirmed" />
@code {
[Parameter]
public int? Id { get; set; }
private Supplier supplier = new();
private List<SupplierStock> stocks = new();
private List<Material> materials = new();
private List<SupplierOffering> offerings = new();
private List<StockItem> stockItems = new();
private bool loading = true;
private bool savingSupplier;
private bool savingStock;
private bool savingOffering;
private string? supplierErrorMessage;
private string? stockErrorMessage;
private string? offeringErrorMessage;
private bool showStockForm;
private SupplierStock newStock = new();
private SupplierStock? editingStock;
private bool showOfferingForm;
private SupplierOffering newOffering = new();
private SupplierOffering? editingOffering;
private ConfirmDialog deleteStockDialog = null!;
private SupplierStock? stockToDelete;
private string deleteStockMessage = "";
private ConfirmDialog deleteOfferingDialog = null!;
private SupplierOffering? offeringToDelete;
private string deleteOfferingMessage = "";
private bool IsNew => !Id.HasValue;
protected override async Task OnInitializedAsync()
{
materials = await MaterialService.GetAllAsync();
stockItems = await DbContext.StockItems
.Include(si => si.Material)
.Where(si => si.IsActive)
.OrderBy(si => si.Material.Shape)
.ThenBy(si => si.Material.Size)
.ThenBy(si => si.LengthInches)
.ToListAsync();
if (Id.HasValue)
{
@@ -195,7 +206,7 @@ else
return;
}
supplier = existing;
stocks = await SupplierService.GetStocksForSupplierAsync(Id.Value);
offerings = await SupplierService.GetOfferingsForSupplierAsync(Id.Value);
}
loading = false;
}
@@ -229,100 +240,94 @@ else
}
}
private void ShowAddStockForm()
private void ShowAddOfferingForm()
{
editingStock = null;
newStock = new SupplierStock { SupplierId = Id!.Value };
showStockForm = true;
stockErrorMessage = null;
editingOffering = null;
newOffering = new SupplierOffering { SupplierId = Id!.Value };
showOfferingForm = true;
offeringErrorMessage = null;
}
private void EditStock(SupplierStock stock)
private void EditOffering(SupplierOffering offering)
{
editingStock = stock;
newStock = new SupplierStock
editingOffering = offering;
newOffering = new SupplierOffering
{
Id = stock.Id,
SupplierId = stock.SupplierId,
MaterialId = stock.MaterialId,
LengthInches = stock.LengthInches,
Price = stock.Price,
Notes = stock.Notes
Id = offering.Id,
SupplierId = offering.SupplierId,
StockItemId = offering.StockItemId,
PartNumber = offering.PartNumber,
SupplierDescription = offering.SupplierDescription,
Price = offering.Price,
Notes = offering.Notes
};
showStockForm = true;
stockErrorMessage = null;
showOfferingForm = true;
offeringErrorMessage = null;
}
private void CancelStockForm()
private void CancelOfferingForm()
{
showStockForm = false;
editingStock = null;
stockErrorMessage = null;
showOfferingForm = false;
editingOffering = null;
offeringErrorMessage = null;
}
private async Task SaveStockAsync()
private async Task SaveOfferingAsync()
{
stockErrorMessage = null;
savingStock = true;
offeringErrorMessage = null;
savingOffering = true;
try
{
if (newStock.MaterialId == 0)
if (newOffering.StockItemId == 0)
{
stockErrorMessage = "Please select a material";
offeringErrorMessage = "Please select a stock item";
return;
}
if (newStock.LengthInches <= 0)
{
stockErrorMessage = "Length must be greater than zero";
return;
}
var exists = await SupplierService.StockExistsAsync(
newStock.SupplierId,
newStock.MaterialId,
newStock.LengthInches,
editingStock?.Id);
var exists = await SupplierService.OfferingExistsAsync(
newOffering.SupplierId,
newOffering.StockItemId,
editingOffering?.Id);
if (exists)
{
stockErrorMessage = "This stock length already exists for this material";
offeringErrorMessage = "This supplier already has an offering for this stock item";
return;
}
if (editingStock == null)
if (editingOffering == null)
{
await SupplierService.AddStockAsync(newStock);
await SupplierService.AddOfferingAsync(newOffering);
}
else
{
await SupplierService.UpdateStockAsync(newStock);
await SupplierService.UpdateOfferingAsync(newOffering);
}
stocks = await SupplierService.GetStocksForSupplierAsync(Id!.Value);
showStockForm = false;
editingStock = null;
offerings = await SupplierService.GetOfferingsForSupplierAsync(Id!.Value);
showOfferingForm = false;
editingOffering = null;
}
finally
{
savingStock = false;
savingOffering = false;
}
}
private void ConfirmDeleteStock(SupplierStock stock)
private void ConfirmDeleteOffering(SupplierOffering offering)
{
stockToDelete = stock;
deleteStockMessage = $"Are you sure you want to delete the {ArchUnits.FormatFromInches((double)stock.LengthInches)} stock length?";
deleteStockDialog.Show();
offeringToDelete = offering;
deleteOfferingMessage = $"Are you sure you want to delete the offering for {offering.StockItem.Material.DisplayName} - {ArchUnits.FormatFromInches((double)offering.StockItem.LengthInches)}?";
deleteOfferingDialog.Show();
}
private async Task DeleteStockConfirmed()
private async Task DeleteOfferingConfirmed()
{
if (stockToDelete != null)
if (offeringToDelete != null)
{
await SupplierService.DeleteStockAsync(stockToDelete.Id);
stocks = await SupplierService.GetStocksForSupplierAsync(Id!.Value);
await SupplierService.DeleteOfferingAsync(offeringToDelete.Id);
offerings = await SupplierService.GetOfferingsForSupplierAsync(Id!.Value);
}
}
}