Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
velz 2026-05-18 12:31:29 +05:30
commit 48de19a546
3 changed files with 119 additions and 18 deletions

View File

@ -5,6 +5,7 @@ namespace App\Controllers;
use App\Models\SamlClientModel;
use App\Helpers\JWTToken;
use App\Helpers\RestAuthHelper;
use App\Controllers\RestAuthenticationController;
use OneLogin\Saml2\Auth as SamlAuth;
use OneLogin\Saml2\Error as SamlError;
use OneLogin\Saml2\Settings as SamlSettings;
@ -53,30 +54,58 @@ class SamlController extends BaseController
$email = $this->request->getGet('email');
if (! $email) {
return $this->response->setStatusCode(400)->setBody('Email required');
return $this->response->setStatusCode(400)->setJSON([
'status' => 'failed',
'code' => 400,
'data' => '',
'message' => 'Email required',
]);
}
$email = trim((string) $email);
$at = strrchr($email, '@');
if ($at === false) {
return $this->response->setStatusCode(400)->setBody('Invalid email');
return $this->response->setStatusCode(400)->setJSON([
'status' => 'failed',
'code' => 400,
'data' => '',
'message' => 'Invalid email',
]);
}
$domain = strtolower(substr($at, 1));
// dd($domain);
$model = new SamlClientModel();
$samlClient = $model->getByDomain($domain);
// dd($samlClient);
if (! $samlClient) {
return $this->response->setStatusCode(404)->setBody('SAML not configured for this domain');
return $this->response->setStatusCode(404)->setJSON([
'status' => 'failed',
'code' => 404,
'data' => '',
'message' => 'SAML not configured for this domain',
]);
}
// dd($samlClient);
$auth = $this->getSamlAuth($samlClient['id']);
} catch (\Throwable $e) {
return redirect()->to(site_url('login'))->with('error', $e->getMessage());
return $this->response->setStatusCode(500)->setJSON([
'status' => 'failed',
'code' => 500,
'data' => '',
'message' => $e->getMessage(),
]);
}
$url = $auth->login(null, [], false, false, true);
@ -161,14 +190,31 @@ class SamlController extends BaseController
$postEnrollment = ['status' => 'failed', 'code' => 404, 'data' => ''];
if (! empty($empdata['post'])) {
$postData = $empdata['post'];
unset($postData['employee_id']);
$postData['token_type'] = 'post';
$postEnrollment = [
'status' => 'success',
'code' => 200,
'data' => JWTToken::encode($postData),
];
$postId = $empdata['post']['id'] ?? $empdata['post']['employee_id'] ?? null;
if ($postId !== null && $postId !== '') {
$restAuth = new RestAuthenticationController();
$rawBody = $restAuth->callThirdPartyGETAPI(['id' => $postId],'getTokenforSamulssOAuthLogin');
$api = is_string($rawBody) ? json_decode($rawBody, true) : null;
if (is_array($api)
&& (($api['status'] ?? '') === 'success' || (int) ($api['code'] ?? 0) === 200)
&& isset($api['data'])
&& $api['data'] !== ''
) {
$postEnrollment = [
'status' => 'success',
'code' => 200,
'data' => is_string($api['data']) ? $api['data'] : (string) $api['data'],
];
} else {
$postEnrollment = [
'status' => 'failed',
'code' => (int) ($api['code'] ?? 404),
'data' => '',
];
}
}
}
if (empty($empdata)) {

View File

@ -131,14 +131,17 @@ class EmployeePolicyModel extends Model
// Name audit trail
'(SELECT old_value FROM auditing_history WHERE pk = emp.id AND field_name = "name" AND table_name = "employees" ORDER BY id ASC LIMIT 1) AS name_first_old',
'(SELECT new_value FROM auditing_history WHERE pk = emp.id AND field_name = "name" AND table_name = "employees" ORDER BY id DESC LIMIT 1) AS name_last_new',
'(SELECT DATE_FORMAT(COALESCE(created_at, emp.updated_at), "%d/%m/%Y %h:%i %p") FROM auditing_history WHERE pk = emp.id AND field_name = "name" AND table_name = "employees" ORDER BY id DESC LIMIT 1) AS name_created_at',
// DOB audit trail
'(SELECT old_value FROM auditing_history WHERE pk = emp.id AND field_name = "dob" AND table_name = "employees" ORDER BY id ASC LIMIT 1) AS dob_first_old',
'(SELECT new_value FROM auditing_history WHERE pk = emp.id AND field_name = "dob" AND table_name = "employees" ORDER BY id DESC LIMIT 1) AS dob_last_new',
'(SELECT DATE_FORMAT(COALESCE(created_at, emp.updated_at), "%d/%m/%Y %h:%i %p") FROM auditing_history WHERE pk = emp.id AND field_name = "dob" AND table_name = "employees" ORDER BY id DESC LIMIT 1) AS dob_created_at',
// Gender audit trail
'(SELECT old_value FROM auditing_history WHERE pk = emp.id AND field_name = "gender" AND table_name = "employees" ORDER BY id ASC LIMIT 1) AS gender_first_old',
'(SELECT new_value FROM auditing_history WHERE pk = emp.id AND field_name = "gender" AND table_name = "employees" ORDER BY id DESC LIMIT 1) AS gender_last_new',
'(SELECT DATE_FORMAT(COALESCE(created_at, emp.updated_at), "%d/%m/%Y %h:%i %p") FROM auditing_history WHERE pk = emp.id AND field_name = "gender" AND table_name = "employees" ORDER BY id DESC LIMIT 1) AS gender_created_at',
"(CASE
WHEN emp.relationship = 'Self'
@ -160,6 +163,19 @@ class EmployeePolicyModel extends Model
ELSE NULL
END) AS removed_summary",
"(CASE
WHEN emp.relationship = 'Self'
THEN (
SELECT DATE_FORMAT(MAX(e.updated_at), '%d/%m/%Y %h:%i %p')
FROM employees e
JOIN employee_polices ep ON e.id = ep.employee_id
WHERE e.emp_code = emp.emp_code
AND (e.is_dependent_modified = 0 OR (e.is_active = 0 AND e.emp_status != 'truncated'))
AND ep.client_policy_id = employee_polices.client_policy_id
)
ELSE NULL
END) AS removed_summary_updated_at",
"(IF(COALESCE(emp.is_dependent_modified, 0) = 1, 'Newly Added, ',
CASE
WHEN emp.relationship != 'Self'
@ -180,6 +196,25 @@ class EmployeePolicyModel extends Model
END
)) AS newly_added",
"(IF(COALESCE(emp.is_dependent_modified, 0) = 1, DATE_FORMAT(emp.updated_at, '%d/%m/%Y %h:%i %p'),
CASE
WHEN emp.relationship != 'Self'
AND emp.file_id IS NULL
AND emp.created_by = (
SELECT e_sub.id
FROM employees e_sub
JOIN employee_polices ep_sub ON e_sub.id = ep_sub.employee_id
WHERE e_sub.emp_code = emp.emp_code
AND e_sub.relationship = 'Self'
AND e_sub.is_active = 1
AND ep_sub.client_policy_id = employee_polices.client_policy_id
LIMIT 1
)
THEN DATE_FORMAT(emp.updated_at, '%d/%m/%Y %h:%i %p')
ELSE NULL
END
)) AS newly_added_updated_at",
$status_query
], false)
->join('employees emp', 'employee_polices.employee_id = emp.id')

View File

@ -201,22 +201,42 @@
<td>
<?php
if(!empty($employee['newly_added'])){
echo "<p>" . $employee['newly_added'] . "</p>";
echo "<p>" . $employee['newly_added'];
if (!empty($employee['newly_added_updated_at'])) {
echo ' (' . $employee['newly_added_updated_at'] . ')';
}
echo "</p>";
}
if(!empty($employee['name_first_old']) ){
echo "<p> Name : " . $employee['name_first_old'] . ' => ' . $employee['name_last_new'] . "</p>";
echo "<p> Name : " . $employee['name_first_old'] . ' => ' . $employee['name_last_new'];
if (!empty($employee['name_created_at'])) {
echo ' (' . $employee['name_created_at'] . ')';
}
echo "</p>";
}
if(!empty($employee['dob_first_old'])){
echo "<p> DOB : " . change_date_format($employee['dob_first_old'], null, 'd/m/Y') . ' => ' . change_date_format($employee['dob_last_new'], null, 'd/m/Y') . "</p>";
echo "<p> DOB : " . change_date_format($employee['dob_first_old'], null, 'd/m/Y') . ' => ' . change_date_format($employee['dob_last_new'], null, 'd/m/Y');
if (!empty($employee['dob_created_at'])) {
echo ' (' . $employee['dob_created_at'] . ')';
}
echo "</p>";
}
if(!empty($employee['gender_first_old'])){
echo "<p> Gender : " . $employee['gender_first_old'] . ' => ' . $employee['gender_last_new'] . "</p>";
echo "<p> Gender : " . $employee['gender_first_old'] . ' => ' . $employee['gender_last_new'];
if (!empty($employee['gender_created_at'])) {
echo ' (' . $employee['gender_created_at'] . ')';
}
echo "</p>";
}
// if(!empty($employee['removed_count'])){
// echo "<p>" . $employee['removed_count'] . " People removed </p>";
// }
if(!empty($employee['removed_summary'])){
echo "<p>" . $employee['removed_summary'] . " </p>";
echo "<p>" . $employee['removed_summary'];
if (!empty($employee['removed_summary_updated_at'])) {
echo ' (' . $employee['removed_summary_updated_at'] . ')';
}
echo " </p>";
}
if(empty($employee['name_first_old']) && empty($employee['dob_first_old']) && empty($employee['gender_first_old']) && empty($employee['removed_summary'] ) && empty($employee['newly_added'] )){
echo " - ";