« Back to History
kasab_salary_report_old.php
|
20260723_000646.php
Initial Domain Snapshot
Copy Code
<?php error_reporting(E_ALL); ini_set('display_errors', 1); /* ================= AUTH ================= */ require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('kasab_salary_report'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; $user_id = (int)$ctx['user']['id']; /* ================= INPUT ================= */ $from = $_GET['from'] ?? ''; $to = $_GET['to'] ?? ''; $report = []; $message = ''; $error = ''; /* ================= ROLL MASTER ================= */ $rollMaster = [ 'Big' => ['weight' => 0, 'rate' => 0], 'Small' => ['weight' => 0, 'rate' => 0], ]; $rm = $pdo->prepare(" SELECT roll, roll_weight, rate FROM roll_detail WHERE company_id = :cid "); $rm->execute([':cid' => $company_id]); while ($r = $rm->fetch(PDO::FETCH_ASSOC)) { if (stripos($r['roll'], 'big') !== false) { $rollMaster['Big']['weight'] = (float)$r['roll_weight']; $rollMaster['Big']['rate'] = (float)$r['rate']; } if (stripos($r['roll'], 'small') !== false) { $rollMaster['Small']['weight'] = (float)$r['roll_weight']; } } /* ================= GENERATE REPORT ================= */ if ($from && $to) { $extraMap = []; $ex_q = $pdo->prepare("SELECT employee_id, SUM(amount) as total FROM employee_extra WHERE company_id = ? AND entry_date BETWEEN ? AND ? GROUP BY employee_id"); $ex_q->execute([$company_id, $from, $to]); while($ex_r = $ex_q->fetch(PDO::FETCH_ASSOC)) $extraMap[(int)$ex_r['employee_id']] = (float)$ex_r['total']; $deductMap = []; $de_q = $pdo->prepare("SELECT employee_id, SUM(amount) as total FROM employee_deduction WHERE company_id = ? AND entry_date BETWEEN ? AND ? GROUP BY employee_id"); $de_q->execute([$company_id, $from, $to]); while($de_r = $de_q->fetch(PDO::FETCH_ASSOC)) $deductMap[(int)$de_r['employee_id']] = (float)$de_r['total']; $advMap = []; $ad_q = $pdo->prepare("SELECT employee_id, SUM(remaining_amount) as total FROM employee_advance WHERE company_id = ? AND status = 'OPEN' AND date BETWEEN ? AND ? GROUP BY employee_id"); $ad_q->execute([$company_id, $from, $to]); while($ad_r = $ad_q->fetch(PDO::FETCH_ASSOC)) $advMap[(int)$ad_r['employee_id']] = (float)$ad_r['total']; $q = $pdo->prepare(" SELECT ke.*, cem.name AS contractor_name FROM kasab_entry ke LEFT JOIN company_employee_master cem ON cem.id = ke.employee_id AND cem.company_id = ke.company_id WHERE ke.company_id = :cid AND ke.entry_date BETWEEN :f AND :t "); $q->execute([ ':cid' => $company_id, ':f' => $from, ':t' => $to ]); while ($row = $q->fetch(PDO::FETCH_ASSOC)) { $cid = (int)$row['employee_id']; if ($cid <= 0) continue; if (!isset($report[$cid])) { $report[$cid] = [ 'contractor_id' => $cid, 'contractor_name' => $row['contractor_name'] ?: 'Unknown', 'gross_weight' => 0, 'big_rolls' => 0, 'small_rolls' => 0, 'extra' => $extraMap[$cid] ?? 0, 'deduction' => $deductMap[$cid] ?? 0, 'advance' => $advMap[$cid] ?? 0 ]; } $weights = json_decode($row['weight_json'], true)['weights'] ?? []; $report[$cid]['gross_weight'] += array_sum($weights); $rolls = (int)(json_decode($row['rolls_json'], true)['rolls'] ?? 0); if ($row['roll_type'] === 'Big') { $report[$cid]['big_rolls'] += $rolls; } else { $report[$cid]['small_rolls'] += $rolls; } } foreach ($report as $cid => $r) { $rollWt = ($r['big_rolls'] * $rollMaster['Big']['weight']) + ($r['small_rolls'] * $rollMaster['Small']['weight']); $netWt = $r['gross_weight'] - $rollWt; $report[$cid]['roll_weight'] = $rollWt; $report[$cid]['net_weight'] = $netWt; $report[$cid]['rate'] = $rollMaster['Big']['rate']; $salary = $netWt * $rollMaster['Big']['rate']; $report[$cid]['salary'] = $salary; $report[$cid]['final_salary'] = $salary + $report[$cid]['extra'] - $report[$cid]['deduction'] - $report[$cid]['advance']; } } ?> <?php require_once __DIR__ . '/partials/header.php'; ?> <div class="container-fluid py-4"> <div class="card border-0 shadow-sm mb-4 no-print"> <div class="card-header bg-primary text-white py-3"> <h5 class="card-title mb-0">Kasab Salary Report</h5> </div> <div class="card-body p-4"> <form method="get" class="row g-3 align-items-end"> <div class="col-md-4"> <label class="form-label small fw-bold text-uppercase">From Date</label> <input type="date" name="from" class="form-control form-control-lg" value="<?= htmlspecialchars($from) ?>"> </div> <div class="col-md-4"> <label class="form-label small fw-bold text-uppercase">To Date</label> <input type="date" name="to" class="form-control form-control-lg" value="<?= htmlspecialchars($to) ?>"> </div> <div class="col-md-4"> <button type="submit" class="btn btn-primary btn-lg w-100">Generate Report</button> </div> </form> </div> </div> <?php if ($report): ?> <!-- ✅ HEADER --> <div class="text-center mb-4"> <h3 class="fw-bold"> Kasab Salary Report </h3> <div class="text-muted mt-1"> <?= date('d M Y', strtotime($from)) ?> to <?= date('d M Y', strtotime($to)) ?> </div> </div> <div class="card border-0 shadow-sm overflow-hidden"> <div class="card-body p-0"> <div class="table-responsive"> <table class="table table-hover align-middle mb-0"> <thead class="table-light border-bottom"> <tr> <th>Contractor</th> <th>Gross Wt</th> <th>Roll Wt</th> <th>Net Wt</th> <th>Salary</th> <th>Extra</th> <th>Deduct</th> <th>Advance</th> <th>Final Salary</th> </tr> </thead> <tbody> <?php foreach ($report as $r): ?> <tr> <td><?= htmlspecialchars($r['contractor_name']) ?></td> <td><?= $r['gross_weight'] ?></td> <td><?= $r['roll_weight'] ?></td> <td><?= $r['net_weight'] ?></td> <td><?= number_format($r['salary'], 2) ?></td> <td><?= $r['extra'] ?></td> <td><?= $r['deduction'] ?></td> <td><?= $r['advance'] ?></td> <td><?= number_format($r['final_salary'], 2) ?></td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> <?php endif; ?> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>