« Back to History
salary_summary.php
|
20260721_154033.php
Initial Bulk Import
Copy Code
<?php /* ============================================================================= File: /erp/salary_summary.php Purpose: Salary Summary – FULL VERSION (Bootstrap 5) Clean layout portrait fixes with PDF currency fallback strings. Scope : Page-local summary aggregation blocks ============================================================================= */ /* ---- Auth + DB ---- */ require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('salary_summary'); $pdo = $ctx['pdo'] ?? null; $company_id = (int)($ctx['company_id'] ?? 0); /* ---- Helpers ---- */ if (!function_exists('h')) { function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } } if (!function_exists('n0')) { function n0($v){ return number_format((float)$v, 0); } } if (!function_exists('table_exists')) { function table_exists(PDO $pdo, string $table): bool { $st = $pdo->prepare("SHOW TABLES LIKE :tbl"); $st->execute([':tbl' => $table]); return (bool)$st->fetchColumn(); } } if (!function_exists('get_pissing_extra_deduction_adjustment')) { function get_pissing_extra_deduction_adjustment(PDO $pdo, int $company_id, string $from, string $to): float { $employeeIds = []; $st = $pdo->prepare(" SELECT DISTINCT employee_id FROM beam_load_data WHERE company_id = :cid AND load_type = 'pissing' AND event_type = 'loaded' AND load_date BETWEEN :sd AND :ed "); $st->execute([':cid' => $company_id, ':sd' => $from, ':ed' => $to]); $employeeIds = array_merge($employeeIds, $st->fetchAll(PDO::FETCH_COLUMN)); if (table_exists($pdo, 'beam_load_data_2')) { $st = $pdo->prepare(" SELECT DISTINCT employee_id FROM beam_load_data_2 WHERE company_id = :cid AND load_type = 'pissing' AND event_type = 'loaded' AND load_date BETWEEN :sd AND :ed "); $st->execute([':cid' => $company_id, ':sd' => $from, ':ed' => $to]); $employeeIds = array_merge($employeeIds, $st->fetchAll(PDO::FETCH_COLUMN)); } $employeeIds = array_values(array_unique(array_filter($employeeIds))); if (!$employeeIds) { return 0.0; } $extraTotal = 0.0; $deductionTotal = 0.0; $extraStmt = $pdo->prepare(" SELECT IFNULL(SUM(amount), 0) FROM employee_extra WHERE company_id = :cid AND employee_id = :emp AND entry_date BETWEEN :sd AND :ed "); $deductionStmt = $pdo->prepare(" SELECT IFNULL(SUM(amount), 0) FROM employee_deduction WHERE company_id = :cid AND employee_id = :emp AND entry_date BETWEEN :sd AND :ed "); foreach ($employeeIds as $employeeId) { $params = [ ':cid' => $company_id, ':emp' => $employeeId, ':sd' => $from, ':ed' => $to, ]; $extraStmt->execute($params); $extraTotal += (float)$extraStmt->fetchColumn(); $deductionStmt->execute($params); $deductionTotal += (float)$deductionStmt->fetchColumn(); } return round($extraTotal - $deductionTotal, 2); } } /* ---- Inputs ---- */ $month = $_GET['month'] ?? date('Y-m'); $period = $_GET['period'] ?? 'H1'; if (!in_array($period,['H1','H2'])) $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)); } /* ---- Load All Salary Helpers ---- */ require_once __DIR__ . '/modules/salary/monthly_total.php'; require_once __DIR__ . '/modules/salary/semi_monthly_total.php'; require_once __DIR__ . '/modules/salary/loom_salary_netpay.php'; require_once __DIR__ . '/modules/salary/pissing_salary_total.php'; require_once __DIR__ . '/modules/salary/pasaria_salary_total.php'; require_once __DIR__ . '/modules/salary/warper_salary_total.php'; /* ---- Build All Rows ---- */ $rows = []; // 1. Monthly (Only in H2) if ($period === 'H2') { $rows['Monthly Salary'] = get_monthly_salary_total($pdo, $company_id, $y, $m); } else { $rows['Monthly Salary'] = 0; } // 2. Semi-Monthly (Always period based) $rows['Semi Monthly Salary'] = get_semi_monthly_salary_total($pdo, $company_id, $y, $m, $period); // 3. Others (Always period based) $rows['Loom Salary'] = get_loom_salary_total($pdo, $company_id, $from, $to); $rows['Pissing Salary'] = get_pissing_salary_total($pdo, $company_id, $from, $to) + get_pissing_extra_deduction_adjustment($pdo, $company_id, $from, $to); $rows['Pasaria Salary'] = get_pasaria_salary_total($pdo, $company_id, $y, $m, $period); $rows['Warper Salary'] = get_warper_salary_total($pdo, $company_id, $month_key, $period); $grand_total = array_sum($rows); /* ============================================================================= PDF EXPORT (DOMPDF) ============================================================================= */ if (isset($_GET['export']) && $_GET['export'] === 'pdf') { ob_start(); ?> <html> <head> <style> body { font-family: sans-serif; font-size: 12px; color: #111; } table { width: 100%; border-collapse: collapse; margin-top: 15px; } th, td { border: 1px solid #ccc; padding: 10px; text-align: left; } th { background: #f1f3f5; font-weight: bold; } .right { text-align: right !important; } .total-row { font-weight: bold; background: #e9ecef; } </style> </head> <body> <h2 style="text-align:center; margin-bottom: 2px;">MAA SHARDA TEXTILES</h2> <h3 style="text-align:center; color:#555; margin-top: 0;">Salary Summary (<?= h($month) ?> | <?= $period ?>)</h3> <table> <thead> <tr> <th>Salary Type</th> <th class="right">Amount</th> </tr> </thead> <tbody> <?php foreach($rows as $k=>$v): if($v <= 0) continue; ?> <tr> <td><?=h($k)?></td> <td class="right">Rs. <?=n0($v)?></td> </tr> <?php endforeach; ?> </tbody> <tfoot> <tr class="total-row"> <td>Grand Total</td> <td class="right">Rs. <?=n0($grand_total)?></td> </tr> </tfoot> </table> </body> </html> <?php $html = ob_get_clean(); $autoload = __DIR__.'/lib/dompdf/autoload.inc.php'; if (file_exists($autoload)) { require_once $autoload; $dompdf = new Dompdf\Dompdf(); $dompdf->loadHtml($html); $dompdf->setPaper('A4', 'portrait'); $dompdf->render(); header('Content-Type: application/pdf'); header('Content-Disposition: attachment; filename="Salary_Summary_'.$month.'.pdf"'); echo $dompdf->output(); exit; } } /* ============================================================================= PRINT VIEW ============================================================================= */ if (isset($_GET['print_view'])) { $period_label = ($period === 'H1') ? '1–15' : '16–End'; ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Salary Summary Print</title> <style> body { font-family: Arial, sans-serif; padding: 20px; color: #000; background: #fff; } h2, h3 { text-align: center; margin: 0; } .sub { text-align: center; margin-bottom: 20px; color: #555; font-size: 14px; } table { width: 100%; border-collapse: collapse; margin-top: 15px; } th, td { border: 1px solid #000; padding: 8px; } th { background: #f0f0f0; } .right { text-align: right; } tfoot th { background: #eaeaea; font-size: 15px; } </style> </head> <body onload="window.print()"> <h2>MAA SHARDA TEXTILES</h2> <h3>Salary Summary Report ( NET PAY )</h3> <div class="sub"> Month: <?= date('F Y', strtotime($month_key)) ?> | Period: <?= $period_label ?> </div> <table> <thead> <tr> <th>Description</th> <th class="right">Amount</th> </tr> </thead> <tbody> <?php foreach($rows as $k=>$v): ?> <tr> <td><?=h($k)?></td> <td class="right">₹<?=n0($v)?></td> </tr> <?php endforeach; ?> </tbody> <tfoot> <tr> <th>Grand Total</th> <th class="right">₹<?=n0($grand_total)?></th> </tr> </tfoot> </table> </body> </html> <?php exit; } /* ============================================================================= NORMAL PAGE VIEW ============================================================================= */ require_once __DIR__ . '/partials/header.php'; ?> <div class="container py-4"> <div class="card border-0 shadow-sm mb-4 no-print"> <div class="card-body"> <form method="get" class="row g-3 align-items-end"> <div class="col-md-3"> <label class="form-label fw-bold">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">Period</label> <select name="period" class="form-select"> <option value="H1" <?=$period==='H1'?'selected':''?>>1–15</option> <option value="H2" <?=$period==='H2'?'selected':''?>>16–End</option> </select> </div> <div class="col-md-6 d-flex gap-2"> <button class="btn btn-primary flex-grow-1">Apply Filter</button> <a class="btn btn-dark" target="_blank" href="?month=<?=h($month)?>&period=<?=h($period)?>&print_view=1">Print</a> <button class="btn btn-danger" name="export" value="pdf">PDF</button> </div> </form> </div> </div> <div class="card border-0 shadow-sm"> <div class="table-responsive"> <table class="table table-hover align-middle mb-0"> <thead class="table-light"> <tr><th class="ps-4 py-3">Salary Type</th><th class="text-end pe-4">Amount</th></tr> </thead> <tbody> <?php foreach($rows as $k=>$v): ?> <tr> <td class="ps-4"><?=h($k)?></td> <td class="text-end pe-4 fw-bold">₹<?=n0($v)?></td> </tr> <?php endforeach; ?> </tbody> <tfoot class="table-primary border-top border-2"> <tr class="fs-5"> <th class="ps-4">Grand Total Sum</th> <th class="text-end pe-4">₹<?=n0($grand_total)?></th> </tr> </tfoot> </table> </div> </div> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>