diff --git a/internal/handlers/web.go b/internal/handlers/web.go index 355d6bd..726cbe1 100644 --- a/internal/handlers/web.go +++ b/internal/handlers/web.go @@ -68,7 +68,7 @@ func NewWebHandler(templatesPath string, componentService *services.ComponentSer } // Load each page template with base - simplePages := []string{"admin_pricing.html", "pricelists.html", "pricelist_detail.html", "lot.html", "vendor_mappings.html"} + simplePages := []string{"admin_pricing.html", "pricelists.html", "pricelist_detail.html", "lot.html", "vendor_mappings.html", "competitors.html"} for _, page := range simplePages { pagePath := filepath.Join(templatesPath, page) var tmpl *template.Template @@ -143,6 +143,10 @@ func (h *WebHandler) VendorMappings(c *gin.Context) { h.render(c, "vendor_mappings.html", gin.H{"ActivePage": "vendor_mappings"}) } +func (h *WebHandler) Competitors(c *gin.Context) { + h.render(c, "competitors.html", gin.H{"ActivePage": "competitors"}) +} + func (h *WebHandler) Pricelists(c *gin.Context) { h.render(c, "pricelists.html", gin.H{"ActivePage": "pricelists"}) } diff --git a/internal/models/models.go b/internal/models/models.go index a5f9189..825f55a 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -23,6 +23,8 @@ func AllModels() []interface{} { &PartnumberBook{}, &PartnumberBookItem{}, &VendorPartnumberSeen{}, + &Competitor{}, + &CompetitorQuote{}, } } diff --git a/internal/repository/pricelist.go b/internal/repository/pricelist.go index 655a99a..3d2955c 100644 --- a/internal/repository/pricelist.go +++ b/internal/repository/pricelist.go @@ -459,10 +459,12 @@ func (r *PricelistRepository) DecrementUsageCount(id uint) error { UpdateColumn("usage_count", gorm.Expr("GREATEST(usage_count - 1, 0)")).Error } -// CountUsage returns number of configurations referencing pricelist. +// CountUsage returns number of configurations referencing pricelist across all source columns. func (r *PricelistRepository) CountUsage(id uint) (int64, error) { var count int64 - if err := r.db.Table("qt_configurations").Where("pricelist_id = ?", id).Count(&count).Error; err != nil { + if err := r.db.Table("qt_configurations"). + Where("pricelist_id = ? OR warehouse_pricelist_id = ? OR competitor_pricelist_id = ?", id, id, id). + Count(&count).Error; err != nil { return 0, fmt.Errorf("counting configurations for pricelist %d: %w", id, err) } return count, nil diff --git a/internal/tasks/task.go b/internal/tasks/task.go index 0dade4e..48797ad 100644 --- a/internal/tasks/task.go +++ b/internal/tasks/task.go @@ -19,6 +19,7 @@ const ( TaskTypeStockImport TaskType = "stock_import" TaskTypePricelistCreate TaskType = "pricelist_create" TaskTypePartnumberBookCreate TaskType = "partnumber_book_create" + TaskTypeCompetitorImport TaskType = "competitor_import" ) // Task represents a background task with progress tracking