🛡️ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!
Fix archived warranties counted in dashboard stats; add Archived stat card
Omega (QA)bae1dababc5c
diff --git a/backend/statistics_routes.py b/backend/statistics_routes.pyindex ef21cbb..0c27962 100644--- a/backend/statistics_routes.py+++ b/backend/statistics_routes.py@@ -80,24 +80,29 @@ def get_statistics():active_where = "AND"with conn.cursor() as cur:- # Get total count- cur.execute(f"SELECT COUNT(*) {from_clause} {where_clause}", params)+ # Get total count (excluding archived)+ cur.execute(f"SELECT COUNT(*) {from_clause} {where_clause} AND w.archived_at IS NULL", params)total_count = cur.fetchone()[0]logger.info(f"Total warranties: {total_count}")++ # Get archived count+ cur.execute(f"SELECT COUNT(*) {from_clause} {where_clause} AND w.archived_at IS NOT NULL", params)+ archived_count = cur.fetchone()[0]+ logger.info(f"Archived warranties: {archived_count}")- # Get active count (includes lifetime)- cur.execute(f"SELECT COUNT(*) {from_clause} {where_clause} {active_where if where_clause else 'WHERE'} (w.is_lifetime = TRUE OR w.expiration_date > %s)", params + [today])+ # Get active count (includes lifetime, excludes archived)+ cur.execute(f"SELECT COUNT(*) {from_clause} {where_clause} {active_where if where_clause else 'WHERE'} (w.is_lifetime = TRUE OR w.expiration_date > %s) AND w.archived_at IS NULL", params + [today])active_count = cur.fetchone()[0]logger.info(f"Active warranties: {active_count}")- # Get expired count (excludes lifetime)- cur.execute(f"SELECT COUNT(*) {from_clause} {where_clause} {active_where if where_clause else 'WHERE'} w.is_lifetime = FALSE AND w.expiration_date <= %s", params + [today])+ # Get expired count (excludes lifetime and archived)+ cur.execute(f"SELECT COUNT(*) {from_clause} {where_clause} {active_where if where_clause else 'WHERE'} w.is_lifetime = FALSE AND w.expiration_date <= %s AND w.archived_at IS NULL", params + [today])expired_count = cur.fetchone()[0]logger.info(f"Expired warranties: {expired_count}")- # Get expiring soon count (excludes lifetime) using user preference+ # Get expiring soon count (excludes lifetime and archived) using user preferencecur.execute(f"""SELECT COUNT(*) {from_clause} {where_clause} {active_where if where_clause else 'WHERE'}- w.is_lifetime = FALSE AND w.expiration_date > %s AND w.expiration_date <= %s""",+ w.is_lifetime = FALSE AND w.expiration_date > %s AND w.expiration_date <= %s AND w.archived_at IS NULL""",params + [today, expiring_soon_date])expiring_soon_count = cur.fetchone()[0]logger.info(f"Expiring soon ({expiring_soon_days} days) warranties: {expiring_soon_count}")@@ -110,7 +115,7 @@ def get_statistics():COUNT(*) as count{from_clause}{where_clause} {active_where if where_clause else 'WHERE'}- w.is_lifetime = FALSE AND w.expiration_date > %s AND w.expiration_date <= %s+ w.is_lifetime = FALSE AND w.expiration_date > %s AND w.expiration_date <= %s AND w.archived_at IS NULLGROUP BY EXTRACT(YEAR FROM expiration_date), EXTRACT(MONTH FROM expiration_date)ORDER BY year, month""", params + [today, ninety_days_later])@@ -138,7 +143,7 @@ def get_statistics():expiration_date, invoice_path, manual_path, other_document_path, product_url, purchase_price, is_lifetime{from_clause}{where_clause} {active_where if where_clause else 'WHERE'}- w.is_lifetime = FALSE AND w.expiration_date >= %s AND w.expiration_date <= %s+ w.is_lifetime = FALSE AND w.expiration_date >= %s AND w.expiration_date <= %s AND w.archived_at IS NULLORDER BY expiration_dateLIMIT 10""", params + [days_ago_for_recent, days_later_for_recent])@@ -200,6 +205,7 @@ def get_statistics():'active': active_count,'expired': expired_count,'expiring_soon': expiring_soon_count,+ 'archived': archived_count,'timeline': timeline,'recent_warranties': recent_warranties,'all_warranties': all_warranties_list # <-- Add the new list here@@ -265,21 +271,25 @@ def get_global_statistics():with conn.cursor() as cur:# Global statistics query - all warranties from all users- # Get total count- cur.execute("SELECT COUNT(*) FROM warranties w")+ # Get total count (excluding archived)+ cur.execute("SELECT COUNT(*) FROM warranties w WHERE w.archived_at IS NULL")total_count = cur.fetchone()[0]++ # Get archived count+ cur.execute("SELECT COUNT(*) FROM warranties w WHERE w.archived_at IS NOT NULL")+ archived_count = cur.fetchone()[0]- # Get active count (includes lifetime)- cur.execute("SELECT COUNT(*) FROM warranties w WHERE w.is_lifetime = TRUE OR w.expiration_date > %s", (today,))+ # Get active count (includes lifetime, excludes archived)+ cur.execute("SELECT COUNT(*) FROM warranties w WHERE (w.is_lifetime = TRUE OR w.expiration_date > %s) AND w.archived_at IS NULL", (today,))active_count = cur.fetchone()[0]- # Get expired count (excludes lifetime)- cur.execute("SELECT COUNT(*) FROM warranties w WHERE w.is_lifetime = FALSE AND w.expiration_date <= %s", (today,))+ # Get expired count (excludes lifetime and archived)+ cur.execute("SELECT COUNT(*) FROM warranties w WHERE w.is_lifetime = FALSE AND w.expiration_date <= %s AND w.archived_at IS NULL", (today,))expired_count = cur.fetchone()[0]- # Get expiring soon count (excludes lifetime)+ # Get expiring soon count (excludes lifetime and archived)cur.execute("""SELECT COUNT(*) FROM warranties w WHERE- w.is_lifetime = FALSE AND w.expiration_date > %s AND w.expiration_date <= %s""",+ w.is_lifetime = FALSE AND w.expiration_date > %s AND w.expiration_date <= %s AND w.archived_at IS NULL""",(today, expiring_soon_date))expiring_soon_count = cur.fetchone()[0]@@ -290,7 +300,7 @@ def get_global_statistics():EXTRACT(MONTH FROM expiration_date) as month,COUNT(*) as countFROM warranties w- WHERE w.is_lifetime = FALSE AND w.expiration_date > %s AND w.expiration_date <= %s+ WHERE w.is_lifetime = FALSE AND w.expiration_date > %s AND w.expiration_date <= %s AND w.archived_at IS NULLGROUP BY EXTRACT(YEAR FROM expiration_date), EXTRACT(MONTH FROM expiration_date)ORDER BY year, month""", (today, ninety_days_later))@@ -318,7 +328,7 @@ def get_global_statistics():u.username, u.email, u.first_name, u.last_nameFROM warranties wJOIN users u ON w.user_id = u.id- WHERE w.is_lifetime = FALSE AND w.expiration_date >= %s AND w.expiration_date <= %s+ WHERE w.is_lifetime = FALSE AND w.expiration_date >= %s AND w.expiration_date <= %s AND w.archived_at IS NULLORDER BY w.expiration_dateLIMIT 10""", (days_ago_for_recent, days_later_for_recent))@@ -411,6 +421,7 @@ def get_global_statistics():'active': active_count,'expired': expired_count,'expiring_soon': expiring_soon_count,+ 'archived': archived_count,'timeline': timeline,'recent_warranties': recent_warranties,'all_warranties': all_warranties_listdiff --git a/frontend/status.html b/frontend/status.htmlindex aa13ae9..74c1bef 100644--- a/frontend/status.html+++ b/frontend/status.html@@ -441,6 +441,16 @@<p class="count" id="totalCount">0</p></div></div>++ <div class="status-card" data-status="archived">+ <div class="card-icon">+ <i class="fas fa-archive"></i>+ </div>+ <div class="card-content">+ <h3 data-i18n="status.archived_warranties">Archived</h3>+ <p class="count" id="archivedCount">0</p>+ </div>+ </div></div><!-- Charts Section -->diff --git a/frontend/status.js b/frontend/status.jsindex 6ffa111..dbcb637 100644--- a/frontend/status.js+++ b/frontend/status.js@@ -418,10 +418,12 @@const activeEl = document.getElementById('activeCount');const expiringEl = document.getElementById('expiringCount');const expiredEl = document.getElementById('expiredCount');+ const archivedEl = document.getElementById('archivedCount');if (totalEl) totalEl.textContent = statusData.total || 0;if (activeEl) activeEl.textContent = statusData.active || 0;if (expiringEl) expiringEl.textContent = statusData.expiring_soon || 0;if (expiredEl) expiredEl.textContent = statusData.expired || 0;+ if (archivedEl) archivedEl.textContent = statusData.archived || 0;}function createStatusChart(stats) {diff --git a/locales/en/translation.json b/locales/en/translation.jsonindex ed76a65..50c4559 100644--- a/locales/en/translation.json+++ b/locales/en/translation.json@@ -630,6 +630,7 @@"active_warranties": "Active Warranties","expiring_soon": "Expiring Soon","expired_warranties": "Expired Warranties",+ "archived_warranties": "Archived Warranties","warranty_distribution": "Warranty Distribution","expiration_timeline": "Expiration Timeline","recent_activity": "Recent Activity",