home/abhiramc/public_html/acts.service/attendanceTimeSheet_API.php 0000644 00000006761 15021151654 0021267 0 ustar 00 getConnection();
// Gather all emp_codes from the data, excluding emp_code == 1
$emp_codes = array_unique(array_column($data['data'], 'emp_code'));
$emp_codes = array_filter($emp_codes, function($code) { return $code != 1; });
// If we have valid emp_codes, fetch the corresponding employee names from the database
if (!empty($emp_codes)) {
$placeholders = implode(',', array_fill(0, count($emp_codes), '?'));
$query = "SELECT empid, empname FROM acts_emp WHERE empid IN ($placeholders)";
$stmt = $db->prepare($query);
$stmt->execute(array_values($emp_codes));
// Fetch all employee names and map them by emp_code
$emp_names = [];
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$emp_names[$row['empid']] = $row['empname'];
}
} else {
$emp_names = [];
}
// Now, map the data to include the employee name, emp_code, and punch_time
$filtered_data = array_map(function($item) use ($emp_names, $date_filter) {
$emp_code = ltrim($item['emp_code'], '0'); // Remove leading zero
$punch_time = $item['punch_time'];
// Skip entries with emp_code = 1
if ($emp_code == 1) {
return null;
}
// If a date filter is provided, check if the punch_time matches the date
if (!empty($date_filter)) {
$punch_date = explode(' ', $punch_time)[0]; // Get only the date part of punch_time
if ($punch_date !== $date_filter) {
return null; // Skip records that don't match the selected date
}
}
return [
'emp_name' => $emp_names[$emp_code] ?? 'Unknown', // Get emp_name by emp_code
'emp_code' => $emp_code, // Include the emp_code
'punch_time' => $item['punch_time'] ?? null // Handle missing punch_time
];
}, $data['data']);
// Filter out any null values from the final data (this removes items with emp_code = 1 or unmatched date)
$filtered_data = array_filter($filtered_data, function($item) {
return $item !== null;
});
// Return filtered data in JSON format
echo json_encode(array_values($filtered_data), JSON_PRETTY_PRINT); // Format the JSON output
} else {
// Return a message if no data is found
echo json_encode(["message" => "No data found in the response."]);
}
?>