124 lines
4.4 KiB
PHP
124 lines
4.4 KiB
PHP
<?php
|
|
include('includes/config/config.php');
|
|
include('includes/functions.php');
|
|
include('log_entry.php');
|
|
error_log("Start Printing Request Attributes");
|
|
$requestStr = "";
|
|
foreach ($_REQUEST as $key => $value) {
|
|
$requestStr .= $key . " : " . $value . "\n";
|
|
error_log($key . " : " . $value . "<br />\r\n");
|
|
}
|
|
error_log("End Printing Request Attributes");
|
|
save_log($requestStr, 'Attendance', 'SAVE', 'save_attendance.php');
|
|
$noOfRows = $_POST['count_items'];
|
|
|
|
begin();
|
|
|
|
$attendance_id = $_POST['attendance_id'];
|
|
$attendance_date = $_POST['attendance_date'];
|
|
$month = $_POST['month'];
|
|
$year = $_POST['year'];
|
|
$attendance_emp = $_POST['attendance_emp'];
|
|
$ohc_id = $_SESSION['current_ohcttype'];
|
|
$user_id = $_SESSION['user_id'];
|
|
|
|
error_log("attendance id " . $attendance_id);
|
|
|
|
$initquery = "";
|
|
$endquery = "";
|
|
if (!empty($attendance_id)) {
|
|
// Update case
|
|
$initquery = "UPDATE attendance_master SET ";
|
|
$endquery = " WHERE attendance_id = '" . $attendance_id . "'";
|
|
} else {
|
|
// Insert case
|
|
$initquery = "INSERT INTO attendance_master SET month = '$month', year = '$year' , emp_id = '$attendance_emp' , ";
|
|
}
|
|
|
|
$query = $initquery . " attendance_date = STR_TO_DATE('" . $attendance_date . "','%d/%m/%Y'), ohc_type_id = '$ohc_id', modified_by = '" . $_SESSION['user_id'] . "' $endquery";
|
|
|
|
echo $query;
|
|
error_log("query: " . $query);
|
|
|
|
if (!$result = @mysqli_query($conn, $query)) {
|
|
rollback();
|
|
header('HTTP/1.1 500 Internal Server Error');
|
|
echo json_encode(die('failed!' . mysqli_error($conn)));
|
|
} else {
|
|
if (empty($_POST['attendance_id'])) {
|
|
$attendance_id = mysqli_insert_id($conn);
|
|
}
|
|
|
|
for ($i = 0; $i < $noOfRows; $i++) {
|
|
$dateInTime = $_POST["in_time$i"];
|
|
$dateOutTime = $_POST["out_time$i"];
|
|
|
|
if (!empty($attendance_emp)) {
|
|
$staff_id = $attendance_emp;
|
|
$remarks = $_POST["remarks$i"];
|
|
$ot = $_POST["ot$i"];
|
|
$wo = $_POST["wo$i"];
|
|
$ohc_location = $_POST["ohc_location$i"];
|
|
$shift = $_POST["shift$i"];
|
|
|
|
$query_check = "SELECT * FROM attendance_detail
|
|
WHERE attendance_id = '$attendance_id'
|
|
AND staff_id = '$staff_id'
|
|
AND in_time = '$dateInTime'
|
|
AND out_time = '$dateOutTime'
|
|
AND shift = '$shift'
|
|
AND staff_deploy_ohc = '$ohc_location'";
|
|
|
|
$result_check = mysqli_query($conn, $query_check);
|
|
error_log('query: ' . $query_check);
|
|
$row = mysqli_fetch_assoc($result_check);
|
|
$count = mysqli_num_rows($result_check);
|
|
if ( $count > 0) {
|
|
$row = mysqli_fetch_assoc($result_check);
|
|
$detail_id = $row['detail_id'];
|
|
|
|
$query_update = "UPDATE attendance_detail SET
|
|
in_time = '$dateInTime',
|
|
out_time ='$dateOutTime',
|
|
remark = '$remarks',
|
|
modified_by = '$user_id',
|
|
ot = '$ot',
|
|
wo = '$wo',
|
|
staff_deploy_ohc = '$ohc_location',
|
|
shift = '$shift'
|
|
WHERE detail_id = '$detail_id'";
|
|
|
|
error_log("update query for attendance details: " . $query_update);
|
|
|
|
if (!$result_update = mysqli_query($conn, $query_update)) {
|
|
rollback();
|
|
header('HTTP/1.1 500 Internal Server Error');
|
|
echo json_encode(die('failed!' . mysqli_error($conn)));
|
|
}
|
|
} else {
|
|
$query_insert = "INSERT INTO attendance_detail SET
|
|
attendance_id = '$attendance_id',
|
|
staff_id = '$staff_id',
|
|
in_time = '$dateInTime',
|
|
out_time = '$dateOutTime',
|
|
remark = '$remarks',
|
|
created_by = '$user_id',
|
|
ot = '$ot',
|
|
wo = '$wo',
|
|
staff_deploy_ohc = '$ohc_location',
|
|
shift = '$shift'";
|
|
|
|
error_log("insert query for attendance details: " . $query_insert);
|
|
|
|
if (!$result_insert = mysqli_query($conn, $query_insert)) {
|
|
rollback();
|
|
header('HTTP/1.1 500 Internal Server Error');
|
|
echo json_encode(die('failed!' . mysqli_error($conn)));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
commit();
|