87 lines
3.0 KiB
PHP
87 lines
3.0 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();
|
|
//echo $noOfRows;
|
|
$attendance_id = $_POST['attendance_id'];
|
|
//echo $attendance_refno;
|
|
$remarks = $_POST['remarks'];
|
|
$attendance_date = $_POST['attendance_date'];
|
|
|
|
$ohc_id = $_SESSION['current_ohcttype'];
|
|
|
|
error_log("attendance id " . $attendance_id);
|
|
|
|
$initquery = "";
|
|
//$data = array();
|
|
$endquery = "";
|
|
if (!empty($attendance_id)) {
|
|
//update case
|
|
$initquery = "update ";
|
|
$endquery = " where attendance_id = '" . $attendance_id . "'";
|
|
} else {
|
|
//insert case
|
|
$initquery = "INSERT INTO ";
|
|
}
|
|
$query = $initquery . " attendance_master set 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);
|
|
} else {
|
|
//clear existing entries into the child table
|
|
$query_del = " delete from attendance_detail where attendance_id = '" . $attendance_id . "'";
|
|
error_log("delete query for child data : " . $query_del);
|
|
$result_del = @mysqli_query($conn, $query_del);
|
|
}
|
|
|
|
for ($i = 0; $i < $noOfRows; $i++) {
|
|
$dateInTime = ${"in_time$i"};
|
|
$dateOutTime = ${"out_time$i"};
|
|
|
|
error_log("in time " . $dateInTime);
|
|
error_log("out time " . $dateOutTime);
|
|
|
|
if (${"staff_id$i"} != null && ${"staff_id$i"} != '' && ${"staff_id$i"}) {
|
|
|
|
$query1 = "insert into attendance_detail set attendance_id='$attendance_id', staff_id ='" . ${"staff_id$i"} . "',in_time=STR_TO_DATE('$dateInTime', '%Y-%m-%dT%H:%i'),out_time=STR_TO_DATE('$dateOutTime', '%Y-%m-%dT%H:%i'),remark='" . ${"remarks$i"} . "',modified_by = '" . $_SESSION['user_id'] . "',ot='" . ${"ot$i"} . "', wo='" . ${"wo$i"} . "', staff_deploy_ohc= '" . ${"ohc_location$i"} . "', shift= '" . ${"shift$i"} . "'" ;
|
|
|
|
|
|
error_log("item insert query in attendance details" . $query1);
|
|
error_log("mysql error insert attendance details:" . mysqli_errno($conn));
|
|
error_log("mysqli error des insert attendance details:" . mysqli_error($conn));
|
|
|
|
|
|
if (!$result1 = mysqli_query($conn, $query1)) {
|
|
rollback();
|
|
header('HTTP/1.1 500 Internal Server Error');
|
|
echo json_encode(die('failed!' . mysqli_error($conn)));
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
commit();
|
|
|
|
//echo json_encode($data);
|