« Back to History
salary_paid_summary.php
|
20260722_120325.php
Initial Domain Snapshot
Copy Code
<?php /* ============================================================================= File: /salary_paid_summary.php Title: Paid Salary & Net Balance Summary Report ============================================================================= */ require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('salary_summary'); if (!class_exists(\Dompdf\Dompdf::class)) { foreach ([ __DIR__ . '/lib/dompdf/autoload.inc.php', __DIR__ . '/vendor/autoload.php', ] as $dompdfAutoload) { if (is_file($dompdfAutoload)) { require_once $dompdfAutoload; if (class_exists(\Dompdf\Dompdf::class)) { break; } } } } $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } function n0($v){ return number_format((float)$v, 0); } $month = $_GET['month'] ?? date('Y-m'); $period = $_GET['period'] ?? 'H1'; $month_key = $month.'-01'; $y = (int)date('Y', strtotime($month_key)); $m = (int)date('m', strtotime($month_key)); if ($period==='H1'){ $from="$month-01"; $to="$month-15"; } else { $from="$month-16"; $to=date('Y-m-t', strtotime($month_key)); } require_once __DIR__.'/modules/salary/summary_paid_helpers.php'; $rows = []; // 1. Core Payroll Reports Pull (Semi-Monthly) $st = $pdo->prepare(" SELECT department_name, SUM(gross_amount) as total_gross, SUM(net_pay) as total_payable FROM semi_monthly_salary_report WHERE company_id=? AND month_key=? AND period_label=? GROUP BY department_id "); $st->execute([$company_id, $month_key, $period]); foreach($st as $r){ $dept = $r['department_name']; $g = (float)$r['total_gross']; $p = (float)$r['total_payable']; $rows[$dept] = [ 'gross' => $g, 'paid' => $g - $p ]; } // 2. Core Payroll Reports Pull (Monthly for H2 - Compound addition) if($period==='H2'){ $st = $pdo->prepare(" SELECT department_name, SUM(gross_amount) as total_gross, SUM(net_pay) as total_payable FROM monthly_salary_report WHERE company_id=? AND month_key=? GROUP BY department_id "); $st->execute([$company_id, $month_key]); foreach($st as $r){ $dept = $r['department_name']; $g = (float)$r['total_gross']; $p = (float)$r['total_payable']; if (!isset($rows[$dept])) { $rows[$dept] = ['gross' => 0.0, 'paid' => 0.0]; } $rows[$dept]['gross'] += $g; $rows[$dept]['paid'] += ($g - $p); } } /* Modules Manual Sync Overrides via Helper Outputs */ $loom_data = get_summary_loom_data($pdo, $company_id, $from, $to); $rows['Loom'] = [ 'gross' => $loom_data['gross'], 'paid' => $loom_data['paid'] ]; $warper_data = get_summary_warper_data($pdo, $company_id, $from, $to); $rows['Warping'] = [ 'gross' => $warper_data['gross'], 'paid' => $warper_data['paid'] ]; $pissing_data = get_summary_pissing_data($pdo, $company_id, $from, $to); $rows['Pissing'] = [ 'gross' => $pissing_data['gross'], 'paid' => $pissing_data['paid'] ]; $pasaria_data = get_summary_pasaria_data($pdo, $company_id, $y, $m, $period); $rows['Pasaria'] = [ 'gross' => $pasaria_data['gross'], 'paid' => $pasaria_data['paid'] ]; // Clean empty zero entry lines foreach($rows as $k => $v) { if($v['gross'] == 0 && $v['paid'] == 0) { unset($rows[$k]); } } $grand_gross = 0; $grand_paid = 0; foreach($rows as $r) { $grand_gross += $r['gross']; $grand_paid += $r['paid']; } $grand_balance = $grand_gross - $grand_paid; if (($_GET['export'] ?? '') === 'pdf') { if (!class_exists(\Dompdf\Dompdf::class)) { http_response_code(503); exit('PDF export is not available right now.'); } $period_label = ($period === 'H1') ? '1-15' : '16-End'; ob_start(); ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <style> @page { margin: 16px; } body { margin: 0; font-family: DejaVu Sans, sans-serif; font-size: 10px; color: #111; } h1 { margin: 0 0 4px; text-align: center; font-size: 15px; text-transform: uppercase; } h2 { margin: 0 0 12px; text-align: center; font-size: 11px; font-weight: normal; color: #444; } table { width: 100%; border-collapse: collapse; table-layout: fixed; } th, td { border: 1px solid #b0b0b0; padding: 7px; text-align: left; } th { background: #f4f5f7; font-size: 9.5px; } .text-end { text-align: right; } tfoot th { background: #eef3ff; font-weight: 700; } </style> </head> <body> <h1>Salary Paid & Balance Summary</h1> <h2><?= h(date('F Y', strtotime($month_key))) ?> | Period Half: <?= h($period_label) ?></h2> <table> <thead> <tr> <th>Department Name</th> <th class="text-end">Gross Salary (A)</th> <th class="text-end">Total Paid Amount (B)</th> <th class="text-end">Net Pay / Balance (A - B)</th> </tr> </thead> <tbody> <?php foreach($rows as $k => $v): $bal = $v['gross'] - $v['paid']; ?> <tr> <td><?= h($k) ?></td> <td class="text-end">₹<?= n0($v['gross']) ?></td> <td class="text-end">₹<?= n0($v['paid']) ?></td> <td class="text-end fw-bold">₹<?= n0($bal) ?></td> </tr> <?php endforeach; ?> </tbody> <tfoot> <tr> <th>Grand Total</th> <th class="text-end">₹<?= n0($grand_gross) ?></th> <th class="text-end">₹<?= n0($grand_paid) ?></th> <th class="text-end">₹<?= n0($grand_balance) ?></th> </tr> </tfoot> </table> </body> </html> <?php $pdfHtml = ob_get_clean(); $dompdf = new \Dompdf\Dompdf(['isRemoteEnabled' => false, 'defaultFont' => 'DejaVu Sans']); $dompdf->loadHtml($pdfHtml, 'UTF-8'); $dompdf->setPaper('A4', 'portrait'); $dompdf->render(); $dompdf->stream('salary_paid_summary_' . $month . '_' . $period . '.pdf', ['Attachment' => true]); exit; } require_once __DIR__.'/partials/header.php'; ?> <div class="container py-4"> <div class="card mb-4 no-print shadow-sm border-0 bg-light"> <div class="card-body"> <form method="get" class="row g-3 align-items-end"> <div class="col-md-4"> <label class="form-label fw-bold small text-muted text-uppercase">Select Month</label> <input type="month" name="month" class="form-control" value="<?= h($month) ?>"> </div> <div class="col-md-3"> <label class="form-label fw-bold small text-muted text-uppercase">Select Period</label> <select name="period" class="form-select"> <option value="H1" <?= $period==='H1'?'selected':'' ?>>1–15 (First Half)</option> <option value="H2" <?= $period==='H2'?'selected':'' ?>>16–End (Second Half)</option> </select> </div> <div class="col-md-5 d-flex gap-2"> <button class="btn btn-primary w-100 fw-bold">Apply Filters</button> <button type="button" onclick="window.print()" class="btn btn-dark fw-bold">Print</button> <button class="btn btn-danger fw-bold" name="export" value="pdf">PDF</button> </div> </form> </div> </div> <div class="text-center mb-4"> <h4 class="fw-bold text-dark mb-1">Department Wise Salary Payout Matrix</h4> <p class="text-muted small">Statement for <?= h(date('F Y', strtotime($month_key))) ?> (<?= $period === 'H1' ? '1-15 Half' : '16-End Half' ?>)</p> </div> <div class="card shadow-sm border-0 overflow-hidden mb-4"> <table class="table table-striped table-bordered align-middle mb-0"> <thead class="table-dark text-uppercase" style="font-size: 11px; letter-spacing: 0.5px;"> <tr> <th>Department</th> <th class="text-end">Gross Salary (A)</th> <th class="text-end">Total Paid Amount (B)</th> <th class="text-end">Net Pay / Balance (A - B)</th> </tr> </thead> <tbody> <?php foreach($rows as $k => $v): $balance = $v['gross'] - $v['paid']; ?> <tr> <td class="fw-bold text-secondary"><?= h($k) ?></td> <td class="text-end text-dark fw-bold">₹<?= n0($v['gross']) ?></td> <td class="text-end text-success fw-bold">₹<?= n0($v['paid']) ?></td> <td class="text-end text-danger fs-6 fw-bold">₹<?= n0($balance) ?></td> </tr> <?php endforeach; ?> </tbody> <tfoot class="table-light fw-bold" style="border-top: 2px solid #222;"> <tr> <td class="text-uppercase text-dark">Grand Total Summary</td> <td class="text-end text-dark fs-5">₹<?= n0($grand_gross) ?></td> <td class="text-end text-success fs-5">₹<?= n0($grand_paid) ?></td> <td class="text-end text-danger fs-5 fw-bolder">₹<?= n0($grand_balance) ?></td> </tr> </tfoot> </table> </div> </div> <?php require_once __DIR__.'/partials/footer.php'; ?>