« Back to History
master_salary_report.php
|
20260920_164915.php
Initial Domain Snapshot
Copy Code
<?php /* ============================================================================ File: /erp/master_salary_report.php Purpose: Consolidated Master Salary Report with Cover Page, Natural Flow & Adjustable Font Size ============================================================================ */ error_reporting(E_ALL); ini_set('display_errors', 1); require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('master_salary_report'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; $selected_year = $_GET['year'] ?? date('Y'); $selected_month = $_GET['month'] ?? date('m'); $selected_period = $_GET['period'] ?? 'Monthly'; // Default 'Monthly' // Format month and period labels for Cover Page $month_key = sprintf('%04d-%02d-01', $selected_year, $selected_month); $month_label = date('F - Y', strtotime($month_key)); function period_text($p) { if ($p === 'H1') return '1 to 15 (H1)'; if ($p === 'H2') return '16 to End (H2)'; return 'Full Month (Monthly)'; } $period_label = period_text($selected_period); // Database se saved report_type snapshots fetch karo $stmt = $pdo->prepare(" SELECT report_type, report_html, created_at FROM master_salary_snapshots WHERE company_id = ? AND salary_year = ? AND salary_month = ? AND period = ? "); $stmt->execute([$company_id, $selected_year, $selected_month, $selected_period]); $raw_snapshots = $stmt->fetchAll(PDO::FETCH_ASSOC); // Define strict sequence map for reports $sequence_map = [ 'Cover Page' => 0, 'Loom Production' => 1, 'Salary By Department' => 2, 'Salary Summary' => 3, 'CMS Detail' => 4, 'Monthly' => 5, 'Semi-monthly' => 6, 'Warper' => 7, // Warper Performance 'Warper Salary' => 8, // Warper Financial Salary Data 'Pissing' => 9, 'Pasaria' => 10, 'Loom Karigar' => 11, 'KarigarEfficiency' => 12 ]; // Sort snapshots according to the predefined sequence map $snapshots = []; foreach ($raw_snapshots as $snap) { $type = trim($snap['report_type']); $priority = $sequence_map[$type] ?? 99; // Unknown types go last $snapshots[] = ['priority' => $priority, 'data' => $snap]; } usort($snapshots, function($a, $b) { if ($a['priority'] === $b['priority']) { return strcmp($a['data']['report_type'], $b['data']['report_type']); } return $a['priority'] < $b['priority'] ? -1 : 1; }); // Extract sorted data back $sorted_snapshots = array_column($snapshots, 'data'); require_once __DIR__ . '/partials/header.php'; ?> <div class="container py-4"> <!-- Filter Card & Controls (Hidden on Print) --> <div class="card shadow-sm mb-4 no-print"> <div class="card-header bg-primary text-white d-flex justify-content-between align-items-center flex-wrap gap-2"> <h5 class="mb-0">Master Salary Report (Consolidated View)</h5> <div class="d-flex gap-2 align-items-center"> <!-- Visual Font Size Adjuster Control --> <div class="bg-white text-dark px-2 py-1 rounded d-flex align-items-center gap-2 shadow-sm"> <span style="font-size:12px; font-weight:bold;">Font:</span> <button type="button" class="btn btn-sm btn-outline-secondary py-0 px-2" onclick="adjustFontSize(-1)">-</button> <span id="fontSizeDisplay" style="font-size:12px; font-weight:bold; min-width:35px; text-align:center;">14px</span> <button type="button" class="btn btn-sm btn-outline-secondary py-0 px-2" onclick="adjustFontSize(1)">+</button> </div> <button onclick="window.print();" class="btn btn-light btn-sm px-3"> <i class="bi bi-printer"></i> Print Master Report </button> </div> </div> <div class="card-body"> <form method="get" class="row g-3 align-items-end"> <div class="col-md-3"> <label class="form-label">Year</label> <input type="number" name="year" class="form-control" value="<?=$selected_year?>"> </div> <div class="col-md-3"> <label class="form-label">Month (1-12)</label> <input type="number" name="month" class="form-control" value="<?=$selected_month?>"> </div> <div class="col-md-3"> <label class="form-label">Period / Type</label> <select name="period" class="form-select"> <option value="Monthly" <?=$selected_period=='Monthly'?'selected':''?>>Full Month (Monthly)</option> <option value="H1" <?=$selected_period=='H1'?'selected':''?>>H1 (1–15)</option> <option value="H2" <?=$selected_period=='H2'?'selected':''?>>H2 (16–End)</option> </select> </div> <div class="col-md-3"> <button type="submit" class="btn btn-dark w-100">Load Master Report</button> </div> </form> </div> </div> <?php if(empty($sorted_snapshots)): ?> <div class="alert alert-warning"> No report snapshots have been saved for this period yet. Please go to individual reports and click <strong>"Save to Master Salary"</strong>. </div> <?php else: ?> <div class="alert alert-success no-print"> Found <?=count($sorted_snapshots)?> report segment(s) compiled successfully in sequence for <strong><?= $period_label ?></strong>. </div> <!-- MASTER PRINTABLE CONTAINER --> <div class="master-print-container" id="masterPrintArea"> <!-- PAGE 1: SALARY COVER PAGE --> <div class="print-page cover-page"> <div class="print-inner text-center"> <h1 class="print-title">MAA SHARDA TEXTILES</h1> <div class="print-content"> <h2 class="print-subtitle">Salary Report</h2> <h3 class="print-month"><?= $month_label ?></h3> <h4 class="print-period"><?= $period_label ?></h4> </div> </div> </div> <!-- SUBSEQUENT PAGES: SORTED REPORT SEGMENTS --> <?php foreach($sorted_snapshots as $index => $snap): ?> <div class="print-page report-section"> <!-- Distinct Section Header --> <div class="report-section-header"> <h3 class="section-heading-title"><?= htmlspecialchars($snap['report_type']) ?></h3> <div class="section-heading-sub">Period: <?= $period_label ?> | Month: <?= $month_label ?></div> </div> <div class="card mb-4 border-0 shadow-sm report-card-wrapper"> <div class="card-body p-0"> <?= $snap['report_html'] ?> </div> </div> <div class="text-end text-muted small mt-1 mb-4 no-print-timestamp"> Saved at: <?=$snap['created_at']?> </div> </div> <?php endforeach; ?> </div> <?php endif; ?> </div> <style> /* Cover Page Styling */ .cover-page { height: 100vh; display: flex; justify-content: center; align-items: center; page-break-after: always; break-after: page; } .print-inner { width: 100%; text-align: center; } .print-title { font-size: 46px; font-weight: 700; text-transform: uppercase; border-bottom: 3px solid #000; display: inline-block; padding-bottom: 10px; margin-bottom: 40px; font-family: serif; letter-spacing: 2px; } .print-subtitle { font-size: 28px; color: #555; margin-bottom: 10px; } .print-month { font-size: 34px; font-weight: 700; margin-bottom: 15px; } .print-period { font-size: 22px; border-top: 1px solid #ccc; border-bottom: 1px solid #ccc; display: inline-block; padding: 6px 20px; color: #555; } /* Report Section Headings */ .report-section-header { background: #f1f3f5; border-left: 5px solid #0d6efd; padding: 12px 18px; margin-bottom: 15px; margin-top: 25px; border-radius: 4px; break-inside: avoid; page-break-inside: avoid; } .section-heading-title { font-size: 19px; font-weight: 800; text-transform: uppercase; color: #212529; margin: 0 0 3px 0; } .section-heading-sub { font-size: 13px; color: #6c757d; font-weight: 600; } /* Report Sections */ .report-section { break-inside: auto; page-break-inside: auto; break-after: auto; page-break-after: auto; } /* Default Readable Baseline Font Size */ .master-print-container { font-size: 14px; } .master-print-container table th, .master-print-container table td, .master-print-container p, .master-print-container span { font-size: inherit; } .master-print-container table th { font-weight: 700 !important; } /* Print Specific Overrides */ @media print { body * { visibility: hidden; } .master-print-container, .master-print-container * { visibility: visible; } .master-print-container { position: absolute; left: 0; top: 0; width: 100%; } .no-print { display: none !important; } .report-section-header { background: #e9ecef !important; border-left: 5px solid #000 !important; -webkit-print-color-adjust: exact; } .card { border: none !important; box-shadow: none !important; break-inside: auto; page-break-inside: auto; } tr { break-inside: avoid; page-break-inside: avoid; } } </style> <script> // Default Font Size (in px) let currentFontSize = 14; const minFontSize = 11; const maxFontSize = 18; function updateReportFontSize() { const container = document.getElementById('masterPrintArea'); if (container) { container.style.fontSize = currentFontSize + 'px'; const tables = container.querySelectorAll('table th, table td'); tables.forEach(el => { el.style.fontSize = currentFontSize + 'px'; }); } const display = document.getElementById('fontSizeDisplay'); if (display) { display.innerText = currentFontSize + 'px'; } localStorage.setItem('master_report_font_size', currentFontSize); } function adjustFontSize(change) { currentFontSize += change; if (currentFontSize < minFontSize) currentFontSize = minFontSize; if (currentFontSize > maxFontSize) currentFontSize = maxFontSize; updateReportFontSize(); } // Page load par local storage se font size restore karna window.addEventListener('DOMContentLoaded', () => { const savedSize = localStorage.getItem('master_report_font_size'); if (savedSize) { currentFontSize = parseInt(savedSize, 10) || 14; updateReportFontSize(); } }); </script> <?php require_once __DIR__.'/partials/footer.php'; ?>