First step of removing inventory quantity tracking (see docs/superpowers/specs/2026-08-01-remove-inventory-quantity-tracking-design.md). UI no longer shows on-hand counts or offers transaction entry; the underlying field/service methods are removed in follow-up commits.
158 lines
5.2 KiB
Plaintext
158 lines
5.2 KiB
Plaintext
@page "/stock/new"
|
|
@page "/stock/{Id:int}"
|
|
@inject StockItemService StockItemService
|
|
@inject MaterialService MaterialService
|
|
@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>
|
|
<LengthInput @bind-Value="stockItem.LengthInches" />
|
|
</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>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Notes (optional)</label>
|
|
<InputText class="form-control" @bind-Value="stockItem.Notes" placeholder="Internal notes" />
|
|
</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>
|
|
</div>
|
|
}
|
|
|
|
@code {
|
|
[Parameter]
|
|
public int? Id { get; set; }
|
|
|
|
private StockItem stockItem = new();
|
|
private List<Material> materials = new();
|
|
private bool loading = true;
|
|
private bool saving;
|
|
private string? errorMessage;
|
|
|
|
private bool IsNew => !Id.HasValue;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
materials = await MaterialService.GetAllAsync();
|
|
|
|
if (Id.HasValue)
|
|
{
|
|
var existing = await StockItemService.GetByIdAsync(Id.Value);
|
|
if (existing == null)
|
|
{
|
|
Navigation.NavigateTo("stock");
|
|
return;
|
|
}
|
|
stockItem = existing;
|
|
}
|
|
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;
|
|
}
|
|
|
|
try
|
|
{
|
|
if (IsNew)
|
|
{
|
|
var created = await StockItemService.CreateAsync(stockItem);
|
|
Navigation.NavigateTo($"stock/{created.Id}");
|
|
}
|
|
else
|
|
{
|
|
await StockItemService.UpdateAsync(stockItem);
|
|
}
|
|
}
|
|
catch (Microsoft.EntityFrameworkCore.DbUpdateException)
|
|
{
|
|
errorMessage = "A stock item with this material and length already exists (it may have been previously deleted).";
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
saving = false;
|
|
}
|
|
}
|
|
}
|