Add vendor supply categories with inventory auto-filter
Vendors can now be tagged with one or more inventory categories (Powder, Chemical, etc.) via checkboxes on the Create/Edit form. The inventory Create/Edit vendor dropdown automatically filters to matching vendors when a category is selected; falls back to all vendors if none are tagged. Includes migration AddVendorCategories (VendorInventoryCategories join table). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1495,8 +1495,20 @@ public class InventoryController : Controller
|
||||
var companyId = _tenantContext.GetCurrentCompanyId() ?? 0;
|
||||
ViewBag.AiInventoryAssistEnabled = await _subscriptionService.IsAiInventoryAssistEnabledAsync(companyId);
|
||||
|
||||
var vendors = await _unitOfWork.Vendors.FindAsync(v => v.CompanyId == companyId);
|
||||
ViewBag.Vendors = new SelectList(vendors.Where(s => s.IsActive).OrderBy(s => s.CompanyName), "Id", "CompanyName");
|
||||
var vendors = (await _unitOfWork.Vendors.FindAsync(v => v.IsActive, false, v => v.Categories))
|
||||
.OrderBy(v => v.CompanyName).ToList();
|
||||
ViewBag.Vendors = new SelectList(vendors, "Id", "CompanyName");
|
||||
|
||||
// Build {categoryId: [vendorId, ...]} so the inventory form can filter vendors by category
|
||||
var categoryVendorMap = new Dictionary<string, List<int>>();
|
||||
foreach (var v in vendors)
|
||||
foreach (var cat in v.Categories)
|
||||
{
|
||||
var key = cat.Id.ToString();
|
||||
if (!categoryVendorMap.ContainsKey(key)) categoryVendorMap[key] = new List<int>();
|
||||
categoryVendorMap[key].Add(v.Id);
|
||||
}
|
||||
ViewBag.CategoryVendorMapJson = System.Text.Json.JsonSerializer.Serialize(categoryVendorMap);
|
||||
|
||||
// Load categories from lookup table
|
||||
var allCategories = await _unitOfWork.InventoryCategoryLookups.FindAsync(c => c.CompanyId == companyId);
|
||||
|
||||
Reference in New Issue
Block a user