Преглед на файлове

added a totals only checkbox

Bernn преди 2 месеца
родител
ревизия
82920d96d5
променени са 1 файла, в които са добавени 19 реда и са изтрити 5 реда
  1. 19 5
      index.php

+ 19 - 5
index.php

@@ -189,6 +189,9 @@ tr.r-total td.neg{color:#fca5a5!important}
       <div id="total-wrap">
         <input type="checkbox" id="show-total" onchange="render()">
         <label for="show-total">Show Year Totals</label>
+        <span style="color:#cbd5e1;margin:0 4px">|</span>
+        <input type="checkbox" id="totals-only" onchange="onTotalsOnly()">
+        <label for="totals-only">Totals Only</label>
       </div>
     </div>
 
@@ -362,11 +365,21 @@ async function load() {
   }
 }
 
+// ── Totals-only toggle: force show-total on when totals-only is enabled ──
+function onTotalsOnly() {
+  const totalsOnly = document.getElementById('totals-only').checked;
+  const showTotal  = document.getElementById('show-total');
+  if (totalsOnly) { showTotal.checked = true; showTotal.disabled = true; }
+  else            { showTotal.disabled = false; }
+  render();
+}
+
 // ── Render table ──
 function render() {
   if (!plData || !plData.rows) return;
 
-  const showTotal = document.getElementById('show-total').checked;
+  const showTotal  = document.getElementById('show-total').checked;
+  const totalsOnly = document.getElementById('totals-only').checked;
 
   // Only real month columns (no DB TOTAL)
   const monthCols = (plData.columns || []).filter(c => !c.is_total);
@@ -379,12 +392,13 @@ function render() {
     else { yearGroups.push({ year: c.year, cols: [c] }); }
   });
 
-  // Build flat display-column list: months interleaved with optional year-total sentinels
-  // sentinel: { isYTotal: true, year, cols: [...month cols for this year] }
+  // Build flat display-column list.
+  // In totals-only mode: one year-total sentinel per year, no individual months.
+  // Otherwise: months interleaved with optional year-total sentinels.
   const dispCols = [];
   yearGroups.forEach(yg => {
-    yg.cols.forEach(c => dispCols.push(c));
-    if (showTotal) dispCols.push({ isYTotal: true, year: yg.year, cols: yg.cols });
+    if (!totalsOnly) yg.cols.forEach(c => dispCols.push(c));
+    if (totalsOnly || showTotal) dispCols.push({ isYTotal: true, year: yg.year, cols: yg.cols });
   });
 
   const selCount = selected.size;