86 lines
2.8 KiB
PHP
86 lines
2.8 KiB
PHP
<?php
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
|
|
$data = [];
|
|
$sql = "select a.*,b.emp_code, b.emp_cadre_name from sickness a left join view_patient_master b on a.emp_id = b.id where DATE(sickness_date) = CURDATE() and b.emp_cadre_name not like '%white%' and is_leave_triggered='0'";
|
|
|
|
|
|
// $sql = "select a.*,b.emp_code, b.emp_cadre_name from sickness a left join view_patient_master b on a.emp_id = b.id where month(sickness_date) = 1 and b.emp_cadre_name not like '%white%'";
|
|
|
|
$result = mysqli_query($conn, $sql);
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
$data[] = $row;
|
|
}
|
|
|
|
error_log("sickness data got " . print_r($data, true));
|
|
|
|
|
|
|
|
use GuzzleHttp\Client;
|
|
use GuzzleHttp\Psr7\Request;
|
|
|
|
$client = new Client();
|
|
$headers = [
|
|
'APIKey' => 'TAAIN657JHBERT789ERT379BNH',
|
|
'Content-Type' => 'application/json'
|
|
];
|
|
|
|
$update_status = "update sickness set is_leave_triggered = '1' where sickness_id=? and emp_id=? ";
|
|
$stmt = mysqli_prepare($conn, $update_status);
|
|
|
|
|
|
foreach ($data as $row) {
|
|
$emp_code = $row['emp_code'];
|
|
$doc_code = getFieldFromTable('emp_code', 'patient_master', 'id', $row['doctor_last_attended']);
|
|
$loc = ucfirst(getFieldFromTable('ohc_type_name', 'ohc_type', 'ohc_type_id', $row['ohc_type_id']));
|
|
$sickFrom = date('Y-m-d', strtotime($row['date_absent']));
|
|
$sickTo = date('Y-m-d', strtotime($row['date_absent_to']));
|
|
$half_day = $row['half_day'];
|
|
|
|
$fromDate = new DateTime($sickFrom);
|
|
$toDate = new DateTime($sickTo);
|
|
|
|
$interval = $fromDate->diff($toDate);
|
|
$days = $interval->days + 1;
|
|
|
|
error_log("details for " . $emp_code . " doc " . $doc_code . " loc " . $loc . " sick from " . $sickFrom . " sick to " . $sickTo . " no of days " . $days . " is half day " . $half_day);
|
|
|
|
$body = '{
|
|
"Empno": "' . $emp_code . '",
|
|
"DoctorEmpno": "' . $doc_code . '",
|
|
"NoOfDays": "' . $days . '",
|
|
"Loc": "' . $loc . '",
|
|
"SickDateFrom": "' . $sickFrom . '",
|
|
"SickDateTo": "' . $sickTo . '",
|
|
}';
|
|
|
|
try {
|
|
$request = new Request('POST', 'https://tvs1hub.tvsmotor.com/TVSApiUAT/api/OHCTech/SaveLeaveRequest', $headers, $body);
|
|
$res = $client->sendAsync($request)->wait();
|
|
|
|
$responseBody = $res->getBody()->getContents();
|
|
|
|
if ($res->getStatusCode() === 200 || ($responseBody && strpos($responseBody, 'Success') !== false)) {
|
|
|
|
mysqli_stmt_bind_param($stmt, "ss", $row['sickness_id'], $row['emp_id']);
|
|
|
|
if (mysqli_stmt_execute($stmt)) {
|
|
error_log("Leave status updated successfully.");
|
|
} else {
|
|
error_log("Error while updating the leave status in sickness table: " . mysqli_stmt_error($stmt));
|
|
}
|
|
} else {
|
|
error_log("response was not 200 " . $res->getBody());
|
|
}
|
|
|
|
error_log("response for emp code " . $emp_code . " is " . $res->getBody());
|
|
} catch (\Exception $err) {
|
|
// Handle the exception
|
|
error_log("An error occurred in ams api: " . $err->getMessage());
|
|
}
|
|
}
|
|
|
|
mysqli_stmt_close($stmt);
|