sheets()); $insert_counter = 0; $update_counter = 0; $fail_counter = 0; for ($i = 0; $i < 1; $i++) { $Reader->ChangeSheet($i); $j = 0; foreach ($Reader as $Row) { if ($j == 0) { $j = 1; continue; } if ($Row[0] == '') { continue; } error_log('again here'); $attendance_date = ''; if (isset($Row[0])) { $attendance_date = mysqli_real_escape_string($conn, $Row[0]); } $staff_name = ''; if (isset($Row[1])) { $staff_name = mysqli_real_escape_string($conn, $Row[1]); } $ohc_location = ''; if (isset($Row[2])) { $ohc_location = mysqli_real_escape_string($conn, $Row[2]); } $wo = ''; if (isset($Row[3])) { $wo = mysqli_real_escape_string($conn, $Row[3]); if (strtoupper($wo) == 'W') { $wo = "W"; } else { $wo = "P"; } } $inDate = ''; if (isset($Row[4])) { $inDate = mysqli_real_escape_string($conn, $Row[4]); } $intime = ''; if (isset($Row[5])) { $intime = mysqli_real_escape_string($conn, $Row[5]); } $outDate = ''; if (isset($Row[6])) { $outDate = mysqli_real_escape_string($conn, $Row[6]); } $outtime = ''; if (isset($Row[7])) { $outtime = mysqli_real_escape_string($conn, $Row[7]); } $ot = ''; if (isset($Row[8])) { $ot = mysqli_real_escape_string($conn, $Row[8]); if (strtoupper($ot) == 'Y') { $ot = "yes"; } else { $ot = "no"; } } $shift = ''; if (isset($Row[9])) { $shift = mysqli_real_escape_string($conn, $Row[9]); } $remarks = ''; if (isset($Row[10])) { $remarks = mysqli_real_escape_string($conn, $Row[10]); } // error_log("type " . gettype($attendance_date)); // error_log("type " . gettype($inDate)); // error_log("type " . gettype($outDate)); // error_log("type " . gettype($intime)); // error_log("type " . gettype($outtime)); $staff_id = getFieldFromTable('staff_id', 'staff_master', 'staff_name', $staff_name); if ($staff_id == '' || $staff_id == null) { $response_mssages .= "
Staff Name Doesn't exists in database" . $staff_name; $fail_counter++; continue; } $staff_ohc = getFieldFromTable('ohc_type_id', 'ohc_type', 'ohc_type_name', $ohc_location); if ($staff_ohc == '' || $staff_ohc == null) { $response_mssages .= "
Ohc Doesn't exists in database" . $ohc_location; $fail_counter++; } $attendance_date = date("Y-m-d", strtotime($attendance_date)); error_log("attendance date " . $attendance_date); if (!empty($inDate)) { $inDate = date("Y-m-d", strtotime($inDate)); } else { $inDate = ""; } if (!empty($outDate)) { $outDate = date("Y-m-d", strtotime($outDate)); } else { $outDate = ""; } if (!empty($intime)) { $intime = date('H:i', strtotime($intime)); } else { $intime = ""; } if (!empty($outtime)) { $outtime = date('H:i', strtotime($outtime)); } else { $outtime = ""; } error_log("date time " . $inDate . " " . $outDate . " " . $intime . " " . $outtime); $attendance_id = ""; if (!empty($staff_name) && !empty($attendance_date)) { // first check if that date already exists in db or not $check = "select * from attendance_master_temp where ohc_type_id ='" . $_SESSION['current_ohcttype'] . "' and attendance_date='" . $attendance_date . "'"; error_log("check data present or not " . $check); $result = mysqli_query($conn, $check); $row = mysqli_fetch_assoc($result); if (mysqli_num_rows($result) > 0) { $attendance_id = $row['attendance_id']; error_log("data present " . $attendance_id); } else { $query1 = "insert into attendance_master_temp set attendance_date ='" . $attendance_date . "',ohc_type_id='" . $_SESSION['current_ohcttype'] . "',modified_by='" . $_SESSION['user_id'] . "'"; error_log("insert into master " . $query1); if (!$result1 = mysqli_query($conn, $query1)) { rollback(); error_log("master query went wrong " . mysqli_error($conn)); } else { $attendance_id = mysqli_insert_id($conn); } } $staff_ohc = getFieldFromTable('ohc_type_id', 'ohc_type', 'ohc_type_name', $ohc_location); $Shiftid = getFieldFromTable('shift_status_id', 'shift_status', 'status_name', $shift); error_log("ohc " . $staff_ohc); $staff_id = getFieldFromTable('staff_id', 'staff_master', 'staff_name', $staff_name); $combinedInDT=""; if ($inDate != "" && $intime != "") { $combinedInDT = date('Y-m-d H:i', strtotime("$inDate $intime")); } $combinedOutDT =""; if ($outDate != "" && $outDate != "") { $combinedOutDT = date('Y-m-d H:i', strtotime("$outDate $outtime")); } $check_child = "select * from attendance_detail_temp where staff_deploy_ohc='" . $staff_ohc . "', staff_id = '" . $staff_id . "', attendance_id='" . $attendance_id . "' "; error_log("check child data present or not " . $check_child); $result_child = mysqli_query($conn, $check_child); if (mysqli_num_rows($result_child) > 0) { $update_data = "UPDATE attendance_detail_temp set remark = '" . $remarks . "', ot='" . $ot . "',in_time='" . $combinedInDT . "' , out_time='" . $combinedOutDT . "' , modified_by='" . $_SESSION['user_id'] . "',wo='" . $wo . "' where attendance_id='" . $attendance_id . "' and staff_id='" . $staff_id . "' and staff_deploy_ohc='" . $staff_ohc . "' and shift = '" . $Shiftid . "'"; error_log("update child data " . $update_data); if (!$result_data = mysqli_query($conn, $update_data)) { error_log("child data updating " . $update_data); rollback(); } $update_counter++; } else { $insert_data = "INSERT INTO attendance_detail_temp set attendance_id='" . $attendance_id . "', staff_id='" . $staff_id . "', remark = '" . $remarks . "', ot='" . $ot . "', in_time='" . $combinedInDT . "' , out_time='" . $combinedOutDT . "' , modified_by='" . $_SESSION['user_id'] . "',staff_deploy_ohc='" . $staff_ohc . "',wo='" . $wo . "' , shift = '" . $Shiftid . "'"; error_log("insert child data " . $insert_data); if (!$result_data = mysqli_query($conn, $insert_data)) { error_log("child data insert " . $insert_data); rollback(); } $insert_counter++; } } } } } commit(); $response_mssages1 = $insert_counter . " " . "records inserted
"; $response_mssages1 .= $update_counter . " " . "records updated
"; $response_mssages1 .= $fail_counter . " " . "records skipped
"; $response_array['responseText'] = "
" . $response_mssages1 . $response_mssages; echo json_encode($response_array);