« Back to History
pasaria_salary_gross_total.php
|
20260723_000646.php
Initial Domain Snapshot
Copy Code
<?php function get_pasaria_salary_gross_total( PDO $pdo, int $company_id, int $year, int $month, string $period = 'H1', int $dedupe = 1 ): float { $norm_period = ($period === '1-15' || strtoupper($period) === 'H1') ? 'H1' : 'H2'; $month_str = sprintf('%04d-%02d', $year, $month); if ($norm_period === 'H1') { $start = $month_str . "-01 00:00:00"; $end = $month_str . "-15 23:59:59"; // Extra/Deduction tables ke liye standard Date format (Y-m-d) $std_start = $month_str . "-01"; $std_end = $month_str . "-15"; } else { $start = $month_str . "-16 00:00:00"; $end = date('Y-m-t 23:59:59', strtotime($month_str . "-01")); // Extra/Deduction tables ke liye standard Date format (Y-m-d) $std_start = $month_str . "-16"; $std_end = date('Y-m-t', strtotime($month_str . "-01")); } /* ---- Rate Map ---- */ $rateMap = []; $st = $pdo->prepare(" SELECT pasaria_type, MAX(rate) AS rate FROM pasaria_rates WHERE company_id = ? GROUP BY pasaria_type "); $st->execute([$company_id]); foreach ($st->fetchAll(PDO::FETCH_ASSOC) as $r) { $rateMap[trim($r['pasaria_type'])] = (float)$r['rate']; } /* ---- Fetch Entries ---- */ $st = $pdo->prepare(" SELECT employee_id, pasaria_type, id, pasaria_date, machine_no FROM pasaria_entry_new WHERE company_id = :cid AND pasaria_date BETWEEN :start AND :end "); $st->execute([ ':cid' => $company_id, ':start' => $start, ':end' => $end ]); $rows = $st->fetchAll(PDO::FETCH_ASSOC); $totalGross = 0.0; $seen = []; $employeeIds = []; // Sabhi unique Pasaria employees ki IDs store karne ke liye foreach ($rows as $r) { $eid = (int)($r['employee_id'] ?? 0); if ($eid <= 0) continue; $type = trim($r['pasaria_type'] ?? ''); $rate = $rateMap[$type] ?? 0.0; if ($dedupe) { $key = $r['id'] ?: ($r['pasaria_date'].'|'.$r['machine_no'].'|'.$type.'|'.$eid); if (isset($seen[$key])) continue; $seen[$key] = true; } $totalGross += $rate; $employeeIds[] = $eid; // Employee ID collect kar rahe hain } /* ---- Extra & Deduction Adjustment ---- */ $employeeIds = array_values(array_unique(array_filter($employeeIds))); if (!empty($employeeIds)) { $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' => $std_start, ':ed' => $std_end, ]; $extraStmt->execute($params); $extraTotal += (float)$extraStmt->fetchColumn(); $deductionStmt->execute($params); $deductionTotal += (float)$deductionStmt->fetchColumn(); } // Gross total me Extra jod rahe hain aur Deduction ghata rahe hain $totalGross += ($extraTotal - $deductionTotal); } return round($totalGross, 2); }