From 4a02f1d13767b69034e8e0e6789b8c6199ed97f5 Mon Sep 17 00:00:00 2001 From: shieldss Date: Wed, 8 Apr 2026 08:59:19 -0400 Subject: [PATCH] Update refile_month.php Sort by most recent month and collapsable display --- public/refile/refile_month.php | 104 ++++++++++++++++++++++++++------- 1 file changed, 83 insertions(+), 21 deletions(-) diff --git a/public/refile/refile_month.php b/public/refile/refile_month.php index b64050f..8f784fc 100755 --- a/public/refile/refile_month.php +++ b/public/refile/refile_month.php @@ -24,56 +24,113 @@ Monthly Refile Stats +

Refile Stats - Monthly

'; -// Step 1: Group data by $col4 and sum $col6 +// Helper: robust-ish month/year parsing to a sortable timestamp +function monthYearToTimestamp(string $label): int { + $label = trim($label); + + // Common trick: try parsing with a day in front (helps "January 2026", "Jan 2026", etc.) + $ts = strtotime("1 " . $label); + if ($ts !== false) return $ts; + + // Try raw label (might already include a day) + $ts = strtotime($label); + if ($ts !== false) return $ts; + + // Fallback: try MM/YYYY or MM-YYYY + if (preg_match('/^\s*(\d{1,2})[\/\-](\d{4})\s*$/', $label, $m)) { + $month = (int)$m[1]; + $year = (int)$m[2]; + if ($month >= 1 && $month <= 12) { + return mktime(0, 0, 0, $month, 1, $year); + } + } + + // Last resort: shove unknown formats to the bottom + return 0; +} + +// Step 1: Group data by month-year (Column4) and sum Column6 $dataByMonth = []; -$grandTotal = 0; // overall total tracker +$grandTotal = 0; foreach ($rows as $row) { - $col4 = isset($row->Column4) ? htmlspecialchars($row->Column4) : 'N/A'; - $col1 = isset($row->Column1) ? htmlspecialchars($row->Column1) : 'N/A'; + $col4 = isset($row->Column4) ? htmlspecialchars((string)$row->Column4) : 'N/A'; + $col1 = isset($row->Column1) ? htmlspecialchars((string)$row->Column1) : 'N/A'; $col6 = isset($row->Column6) ? floatval($row->Column6) : 0; - // Store data under month-year + if (!isset($dataByMonth[$col4])) { + $dataByMonth[$col4] = [ + 'ts' => monthYearToTimestamp($col4), + 'rows' => [], + 'subtotal' => 0 + ]; + } + $dataByMonth[$col4]['rows'][] = [ 'month' => $col4, 'university' => $col1, 'total' => $col6 ]; - // Add to monthly subtotal - if (!isset($dataByMonth[$col4]['subtotal'])) { - $dataByMonth[$col4]['subtotal'] = 0; - } $dataByMonth[$col4]['subtotal'] += $col6; - - // Add to grand total $grandTotal += $col6; } +// Sort months descending by timestamp (most recent first) +uasort($dataByMonth, function($a, $b) { + return ($b['ts'] <=> $a['ts']); +}); + // Display grand total above the table echo "

Grand Total: " . number_format($grandTotal, 0) . "

"; // Step 2: Build the table -echo ' +echo '
- + - + - -'; +'; + +// Step 3: Collapsible month groups (Bootstrap collapse) +// Most recent month open by default +$monthIndex = 0; -// Step 3: Display grouped data with subtotal rows foreach ($dataByMonth as $month => $info) { + $collapseId = "monthCollapse_" . $monthIndex; + $isFirst = ($monthIndex === 0); + $showClass = $isFirst ? "show" : ""; + + // Month header row (toggle) + echo ' + + + + + '; + + // Collapsible section for that month’s detail rows + subtotal + echo ''; + foreach ($info['rows'] as $r) { echo " - + "; @@ -81,15 +138,20 @@ // Monthly subtotal row echo " - + "; + + echo ''; + + $monthIndex++; } -echo ' -
Month - YearMonth - Year Owning UniversityTotalsTotals
+
+ ' . htmlspecialchars($month) . ' + Click to expand/collapse +
+
{$r['month']} {$r['university']} " . number_format($r['total'], 0) . "
Total for {$month}Total for " . htmlspecialchars($month) . " " . number_format($info['subtotal'], 0) . "
+echo ' View by Date Range
+ + ';