ohctech_p8/upload_attendance_final_script.php
2024-10-16 19:18:52 +05:30

90 lines
3.6 KiB
PHP

<?php
include('includes/config/config.php');
include('includes/functions.php');
include('log_entry.php');
begin();
$sql = "select * from attendance_master_temp";
$result = mysqli_query($conn, $sql);
$attendance_id = "";
while ($row = mysqli_fetch_assoc($result)) {
// first check if that date already exists in db or not
$check = "select * from attendance_master where ohc_type_id ='" . $_SESSION['current_ohcttype'] . "' and attendance_date='" . $row['attendance_date'] . "'";
error_log("check data present or not " . $check);
$result_check = mysqli_query($conn, $check);
$row_check = mysqli_fetch_assoc($result_check);
if (mysqli_num_rows($result_check) > 0) {
$attendance_id = $row_check['attendance_id'];
error_log("data present " . $attendance_id);
} else {
$query1 = "insert into attendance_master set attendance_date ='" . $row['attendance_date'] . "',ohc_type_id='" . $row['ohc_type_id'] . "',modified_by='" . $row['modified_by'] . "'";
error_log("insert into master " . $query1);
if (!$result1 = mysqli_query($conn, $query1)) {
error_log("master query went wrong " . mysqli_error($conn));
rollback();
} else {
$attendance_id = mysqli_insert_id($conn);
}
}
$child_temp = "select * from attendance_detail_temp where attendance_id='" . $row['attendance_id'] . "'";
$result_temp = mysqli_query($conn, $child_temp);
error_log("checking in temp detail table " . $child_temp);
while ($row_temp = mysqli_fetch_assoc($result_temp)) {
$staff_ohc = $row_temp['staff_deploy_ohc'];
error_log("ohc " . $staff_ohc);
$staff_id = $row_temp['staff_id'];
$check_child = "select * from attendance_detail where staff_deploy_ohc='" . $staff_ohc . "' and staff_id = '" . $staff_id . "' and 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 set remark = '" . $row_temp['remark'] . "', ot='" . $row_temp['ot'] . "',in_time='" . $row_temp['in_time'] . "' , out_time='" . $row_temp['out_time'] . "' , modified_by='" . $row_temp['modified_by'] . "',wo='" . $row_temp['wo'] . "' where attendance_id='" . $attendance_id . "' and staff_id='" . $staff_id . "' and staff_deploy_ohc='" . $staff_ohc . "'";
error_log("update child data " . $update_data);
if (!$result_data = mysqli_query($conn, $update_data)) {
error_log("child data updating " . $update_data);
rollback();
}
} else {
$insert_data = "insert into attendance_detail set attendance_id='" . $attendance_id . "', staff_id='" . $staff_id . "', remark = '" . $row_temp['remark'] . "', ot='" . $row_temp['ot'] . "', in_time='" . $row_temp['in_time'] . "' , out_time='" . $row_temp['out_time'] . "' , created_by='" . $row_temp['modified_by'] . "',staff_deploy_ohc='" . $staff_ohc . "',wo='" . $row_temp['wo'] . "'";
error_log("insert child data " . $insert_data);
if (!$result_data = mysqli_query($conn, $insert_data)) {
error_log("child data insert " . $insert_data);
rollback();
}
}
}
}
$remove_data = "truncate table attendance_master_temp";
if ($result_data = mysqli_query($conn, $remove_data)) {
$remove_child = "truncate table attendance_detail_temp";
$result_child_data = mysqli_query($conn, $remove_child);
}
commit();