diff --git a/CutList.Web/Components/Pages/Stock/Edit.razor b/CutList.Web/Components/Pages/Stock/Edit.razor index 17ebb1f..09d2b0a 100644 --- a/CutList.Web/Components/Pages/Stock/Edit.razor +++ b/CutList.Web/Components/Pages/Stock/Edit.razor @@ -2,7 +2,6 @@ @page "/stock/{Id:int}" @inject StockItemService StockItemService @inject MaterialService MaterialService -@inject SupplierService SupplierService @inject NavigationManager Navigation @using CutList.Core.Formatting @@ -39,14 +38,7 @@ else
- @if (IsNew) - { - - } - else - { - - } +
@@ -82,7 +74,7 @@ else @if (!IsNew) {
-
+
Inventory @@ -112,23 +104,6 @@ else
- @if (stockTransactionType == "add") - { -
- - -
-
- - -
- }
@if (!string.IsNullOrEmpty(stockFormErrorMessage)) { @@ -159,8 +134,6 @@ else Date Type Qty - Supplier - Price Notes @@ -175,8 +148,6 @@ else @(txn.Quantity >= 0 ? "+" : "")@txn.Quantity - @(txn.Supplier?.Name ?? "-") - @(txn.UnitPrice.HasValue ? txn.UnitPrice.Value.ToString("C") : "-") @(txn.Notes ?? "-") } @@ -185,145 +156,35 @@ else }
- -
-
-
Supplier Offerings
- -
-
- @if (showOfferingForm) - { -
-
@(editingOffering == null ? "Add Offering" : "Edit Offering")
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- @if (!string.IsNullOrEmpty(offeringErrorMessage)) - { -
@offeringErrorMessage
- } -
- - -
-
- } - - @if (offerings.Count == 0) - { -

No supplier offerings configured yet.

- } - else - { - - - - - - - - - - - @foreach (var offering in offerings) - { - - - - - - - } - -
SupplierPart #PriceActions
@offering.Supplier.Name@(offering.PartNumber ?? "-")@(offering.Price.HasValue ? offering.Price.Value.ToString("C") : "-") - - -
- } -
-
} } - - @code { [Parameter] public int? Id { get; set; } private StockItem stockItem = new(); private List materials = new(); - private List suppliers = new(); - private List offerings = new(); private List transactions = 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; // Stock transaction form private bool showStockForm; private bool savingStockTransaction; private string stockTransactionType = "add"; private int stockQuantity; - private int stockSupplierId; - private decimal? stockUnitPrice; private string? stockNotes; private string? stockFormErrorMessage; - 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) { @@ -334,7 +195,6 @@ else return; } stockItem = existing; - offerings = existing.SupplierOfferings.Where(o => o.IsActive).ToList(); transactions = await StockItemService.GetTransactionHistoryAsync(Id.Value, 20); } loading = false; @@ -354,8 +214,6 @@ else { stockTransactionType = "add"; stockQuantity = 0; - stockSupplierId = 0; - stockUnitPrice = null; stockNotes = null; stockFormErrorMessage = null; showStockForm = true; @@ -389,12 +247,7 @@ else switch (stockTransactionType) { case "add": - await StockItemService.AddStockAsync( - Id!.Value, - stockQuantity, - stockSupplierId > 0 ? stockSupplierId : null, - stockUnitPrice, - stockNotes); + await StockItemService.AddStockAsync(Id!.Value, stockQuantity, stockNotes); break; case "adjust": await StockItemService.AdjustStockAsync(Id!.Value, stockQuantity, stockNotes); @@ -464,108 +317,4 @@ else 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(); - } - } - } }