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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user