« Back to History
pissing_salary_report.php
|
20260721_154033.php
Initial Bulk Import
Copy Code
<?php /* ============================================================================= File: /erp/pissing_salary_report.php Title: Pissing Salary Report — Full Production Code Logic: Multi-table merge (Production + Extra + Deduction) ============================================================================= */ header('X-Frame-Options: SAMEORIGIN'); error_reporting(E_ALL); ini_set('display_errors', 0); require __DIR__ . '/modules/auth/auth.php'; require_login(); $u = auth_user(); $company_id = (int)$u['company_id']; $pdo = $GLOBALS['pdo'] ?? null; if (!$pdo) { require __DIR__ . '/core/db.php'; } /* ---- Helpers ---- */ function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } /* ---- Inputs ---- */ $month_val = isset($_GET['month']) ? $_GET['month'] : date('Y-m'); // e.g. 2026-03 $period = isset($_GET['period']) ? $_GET['period'] : (date('j') > 15 ? '16-end' : '1-15'); $emp_id = 34; // Nanhe Lal specifically as per request /* ---- Date Range Calculation ---- */ $dt = new DateTime($month_val . '-01'); if ($period === '1-15') { $start = $dt->format('Y-m-01 00:00:00'); $end = $dt->format('Y-m-15 23:59:59'); } else { $start = $dt->format('Y-m-16 00:00:00'); $end = $dt->format('Y-m-t 23:59:59'); } /* ----------------------------------------------------------------------------- DATA FETCHING (3 SOURCES) ----------------------------------------------------------------------------- */ // 1. Production Data from beam_load_data $sql_prod = " SELECT pq.quality, pq.rate, COUNT(pe.id) as qty, (COUNT(pe.id) * pq.rate) as amt FROM beam_load_data pe JOIN pissing_quality pq ON pe.quality_id = pq.id WHERE pe.employee_id = :eid AND pe.company_id = :cid AND pe.load_date BETWEEN :s AND :e GROUP BY pq.id ORDER BY pq.quality ASC"; $st_p = $pdo->prepare($sql_prod); $st_p->execute([':eid'=>$emp_id, ':cid'=>$company_id, ':s'=>$start, ':e'=>$end]); $prod_rows = $st_p->fetchAll(PDO::FETCH_ASSOC); // 2. Extra Amount from employee_extra $st_ex = $pdo->prepare("SELECT SUM(amount) FROM employee_extra WHERE employee_id = :eid AND company_id = :cid AND date BETWEEN :s AND :e"); $st_ex->execute([':eid'=>$emp_id, ':cid'=>$company_id, ':s'=>$start, ':e'=>$end]); $extra_total = (float)$st_ex->fetchColumn(); // 3. Deduction Amount from employee_deduction $st_de = $pdo->prepare("SELECT SUM(amount) FROM employee_deduction WHERE employee_id = :eid AND company_id = :cid AND date BETWEEN :s AND :e"); $st_de->execute([':eid'=>$emp_id, ':cid'=>$company_id, ':s'=>$start, ':e'=>$end]); $deduct_total = (float)$st_de->fetchColumn(); /* Summary Calculations */ $sub_total = 0; $total_qty = 0; foreach($prod_rows as $r) { $sub_total += $r['amt']; $total_qty += $r['qty']; } $net_payable = ($sub_total + $extra_total) - $deduct_total; /* Header Include */ ob_start(); if (is_file(__DIR__.'/partials/header.php')) include __DIR__.'/partials/header.php'; $headerHtml = ob_get_clean(); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Pissing Salary Report</title> <style> body { font-family: system-ui, -apple-system, sans-serif; background: #f4f7f6; margin: 0; } .container { max-width: 1100px; margin: 20px auto; padding: 0 15px; } .card { background: #fff; border-radius: 12px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); padding: 25px; } .header-flex { display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid #eee; padding-bottom: 15px; margin-bottom: 20px; } .filters { display: flex; gap: 10px; background: #f9f9f9; padding: 15px; border-radius: 8px; margin-bottom: 20px; } .table { width: 100%; border-collapse: collapse; margin-bottom: 20px; } .table th, .table td { padding: 12px; border: 1px solid #eee; text-align: left; } .table th { background: #f8f9fa; font-weight: 600; } .text-right { text-align: right !important; } .total-row { background: #fdfdfd; font-weight: bold; } .net-payable { background: #eef5ff; color: #0056b3; font-size: 1.25rem; } .btn { padding: 10px 20px; border: none; border-radius: 6px; cursor: pointer; font-weight: 600; text-decoration: none; display: inline-block; } .btn-primary { background: #007bff; color: white; } .btn-success { background: #28a745; color: white; } @media print { .no-print { display: none; } .card { box-shadow: none; border: 1px solid #ddd; } } </style> </head> <body> <?= $headerHtml ?> <div class="container"> <div class="card"> <div class="header-flex"> <div> <h1 style="margin:0; font-size: 24px;">Pissing Salary – Quality Wise Report</h1> <p style="color: #666; margin: 5px 0;">Employee: <b>Nanhe Lal (#34)</b> | Period: <?= h($start) ?> to <?= h($end) ?></p> </div> <button onclick="window.print()" class="btn no-print" style="background:#333; color:white;">Print</button> </div> <form class="filters no-print" method="get"> <div style="flex:1"> <label style="display:block; font-size:12px; font-weight:bold; margin-bottom:5px;">SELECT MONTH</label> <input type="month" name="month" value="<?= h($month_val) ?>" style="width:100%; padding:8px;"> </div> <div style="flex:1"> <label style="display:block; font-size:12px; font-weight:bold; margin-bottom:5px;">SELECT PERIOD</label> <select name="period" style="width:100%; padding:8px;"> <option value="1-15" <?= $period=='1-15'?'selected':'' ?>>01 - 15 (First Half)</option> <option value="16-end" <?= $period=='16-end'?'selected':'' ?>>16 - End (Second Half)</option> </select> </div> <div style="display:flex; align-items:flex-end;"> <button type="submit" class="btn btn-primary">Show Report</button> </div> </form> <table class="table"> <thead> <tr> <th>QUALITY NAME</th> <th class="text-right">QUANTITY (QTY)</th> <th class="text-right">RATE</th> <th class="text-right">TOTAL AMOUNT</th> </tr> </thead> <tbody> <?php if(empty($prod_rows)): ?> <tr><td colspan="4" style="text-align:center; padding:30px; color:#999;">No production entries found for this period.</td></tr> <?php else: ?> <?php foreach($prod_rows as $row): ?> <tr> <td><?= h($row['quality']) ?></td> <td class="text-right"><?= (int)$row['qty'] ?></td> <td class="text-right">₹<?= number_format($row['rate'], 2) ?></td> <td class="text-right" style="font-weight:600;">₹<?= number_format($row['amt'], 2) ?></td> </tr> <?php endforeach; ?> <?php endif; ?> </tbody> <tfoot> <tr class="total-row"> <td>SUB TOTAL</td> <td class="text-right"><?= $total_qty ?></td> <td></td> <td class="text-right">₹<?= number_format($sub_total, 2) ?></td> </tr> <?php if($extra_total > 0): ?> <tr class="total-row" style="color: #28a745;"> <td colspan="3">EXTRA (+)</td> <td class="text-right">₹<?= number_format($extra_total, 2) ?></td> </tr> <?php endif; ?> <?php if($deduct_total > 0): ?> <tr class="total-row" style="color: #dc3545;"> <td colspan="3">DEDUCTION (-)</td> <td class="text-right">- ₹<?= number_format($deduct_total, 2) ?></td> </tr> <?php endif; ?> <tr class="total-row net-payable"> <td colspan="3">TOTAL SUMMARY (NET PAYABLE)</td> <td class="text-right">₹<?= number_format($net_payable, 2) ?></td> </tr> </tfoot> </table> <div class="no-print" style="text-align: right; margin-top: 20px;"> <button class="btn btn-success" style="padding: 12px 30px;">Save Salary Amount</button> </div> </div> </div> </body> </html>