From 2c75a7ccb82659bdbd6a5edc0c5403fc66536b94 Mon Sep 17 00:00:00 2001 From: Michael Chus Date: Mon, 2 Feb 2026 21:34:51 +0300 Subject: [PATCH] feat: improve admin pricing modal quote count display to show period and total counts --- internal/handlers/pricing.go | 41 +++++++++++++++++++++++--------- web/templates/admin_pricing.html | 17 +++++++++++-- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/internal/handlers/pricing.go b/internal/handlers/pricing.go index 8f0f710..056cce1 100644 --- a/internal/handlers/pricing.go +++ b/internal/handlers/pricing.go @@ -708,8 +708,8 @@ func (h *PricingHandler) PreviewPrice(c *gin.Context) { medianAllTime = &median } - // Get quote count (from all relevant lots) - var quoteCount int64 + // Get quote count (from all relevant lots) - total count + var quoteCountTotal int64 for _, lotName := range lotNames { var count int64 if strings.HasSuffix(lotName, "*") { @@ -718,7 +718,25 @@ func (h *PricingHandler) PreviewPrice(c *gin.Context) { } else { h.db.Model(&models.LotLog{}).Where("lot = ?", lotName).Count(&count) } - quoteCount += count + quoteCountTotal += count + } + + // Get quote count for specified period (if period is > 0) + var quoteCountPeriod int64 + if req.PeriodDays > 0 { + for _, lotName := range lotNames { + var count int64 + if strings.HasSuffix(lotName, "*") { + pattern := strings.TrimSuffix(lotName, "*") + "%" + h.db.Raw(`SELECT COUNT(*) FROM lot_log WHERE lot LIKE ? AND date >= DATE_SUB(NOW(), INTERVAL ? DAY)`, pattern, req.PeriodDays).Scan(&count) + } else { + h.db.Raw(`SELECT COUNT(*) FROM lot_log WHERE lot = ? AND date >= DATE_SUB(NOW(), INTERVAL ? DAY)`, lotName, req.PeriodDays).Scan(&count) + } + quoteCountPeriod += count + } + } else { + // If no period specified, period count equals total count + quoteCountPeriod = quoteCountTotal } // Get last received price (from the main lot only) @@ -773,14 +791,15 @@ func (h *PricingHandler) PreviewPrice(c *gin.Context) { } c.JSON(http.StatusOK, gin.H{ - "lot_name": req.LotName, - "current_price": comp.CurrentPrice, - "median_all_time": medianAllTime, - "new_price": newPrice, - "quote_count": quoteCount, - "manual_price": comp.ManualPrice, - "last_price": lastPrice.Price, - "last_price_date": lastPrice.Date, + "lot_name": req.LotName, + "current_price": comp.CurrentPrice, + "median_all_time": medianAllTime, + "new_price": newPrice, + "quote_count_total": quoteCountTotal, + "quote_count_period": quoteCountPeriod, + "manual_price": comp.ManualPrice, + "last_price": lastPrice.Price, + "last_price_date": lastPrice.Date, }) } diff --git a/web/templates/admin_pricing.html b/web/templates/admin_pricing.html index 0562fb0..5e2607b 100644 --- a/web/templates/admin_pricing.html +++ b/web/templates/admin_pricing.html @@ -591,8 +591,21 @@ async function fetchPreview() { document.getElementById('modal-new-price').textContent = data.new_price ? '$' + parseFloat(data.new_price).toFixed(2) : '—'; - // Update quote count - document.getElementById('modal-quote-count').textContent = data.quote_count || 0; + // Update quote count with new format "N (всего: M)" + let quoteCountText = ''; + if (data.quote_count_period !== undefined && data.quote_count_total !== undefined) { + if (data.quote_count_period === data.quote_count_total) { + // If period count equals total count, just show the total + quoteCountText = data.quote_count_total; + } else { + // Show both counts in format "N (всего: M)" + quoteCountText = data.quote_count_period + ' (всего: ' + data.quote_count_total + ')'; + } + } else { + // Fallback for older API responses + quoteCountText = data.quote_count || 0; + } + document.getElementById('modal-quote-count').textContent = quoteCountText; } } catch(e) { console.error('Preview fetch error:', e);