328 lines
11 KiB
PHP
328 lines
11 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use CodeIgniter\Controller;
|
|
use Kint;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
|
|
class ICICILombardController extends AdminController
|
|
{
|
|
public function generateAuthToken($scope = 'esbhealth')
|
|
{
|
|
helper('api');
|
|
$url = env('ICICI_TOKEN_URL');
|
|
$method = 'POST';
|
|
$headers = [
|
|
'Content-Type: application/x-www-form-urlencoded'
|
|
];
|
|
$body = [
|
|
'grant_type' => env('ICICI_GRANT_TYPE'),
|
|
'username' => env('ICICI_USER_NAME'),
|
|
'password' => env('ICICI_PASSWORD'),
|
|
'scope' => env('ICICI_API_SCOPE'),
|
|
'client_id' => env('ICICI_CLIENT_ID'),
|
|
'client_secret' => env('ICICI_CLIENT_SECRET')
|
|
];
|
|
|
|
$response = call_third_party_api($url, $method, $headers, $body);
|
|
|
|
|
|
if($response['status'] != true){
|
|
return $this->response->setJSON([
|
|
'status' => false,
|
|
'message' => 'Token generation failed.',
|
|
'data' => $response
|
|
]);
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
|
|
public function createEnrollmentBatch()
|
|
{
|
|
$client_id = $this->request->getGet('client_id');
|
|
$client_branch_id = $this->request->getGet('client_branch_id');
|
|
$policy_id = $this->request->getGet('policy_id');
|
|
$event = $this->request->getGet('event');
|
|
|
|
//fetch token
|
|
$tokenResponse = $this->generateAuthToken();
|
|
if (!$tokenResponse || empty($tokenResponse['data']['access_token'])) {
|
|
return $this->response->setJSON([
|
|
'status' => false,
|
|
'message' => 'Token generation failed.',
|
|
'data' => $tokenResponse
|
|
]);
|
|
}
|
|
$token = $tokenResponse['data']['access_token'];
|
|
|
|
|
|
$url = env('ICICI_BASE_URL').'/batchcreation';
|
|
$headers = [
|
|
'Authorization: Bearer ' . $token,
|
|
'Content-Type: application/json',
|
|
];
|
|
|
|
|
|
//Prepare body data
|
|
// $db = \Config\Database::connect();
|
|
// $data = $db->table('employee_polices ep')
|
|
// ->select('cp.policy_no as policyNumber, cp.cd_ac_no as CDBGAccountNumber,
|
|
// e.id,e.emp_code as MemberEmpId, e.doj as DOJ, e.name as InsuredName, e.dob as DOB, e.relationship as Relationship,
|
|
// e.gender as Gender, ep.date_coverage as DOC,ep.basic_cover_si as SumInsured, e.email_corporate as EmailId
|
|
// ')
|
|
// ->join('employees e', 'e.id = ep.employee_id')
|
|
// ->join('client_policy cp', 'ep.client_policy_id = cp.id')
|
|
// ->where('ep.client_policy_id', $policy_id)
|
|
// ->where('ep.status', 'active')
|
|
// ->where('ep.is_active', 1)
|
|
// // ->where('ep.uhid', null)
|
|
// ->get()
|
|
// ->getResultArray();
|
|
|
|
// $body = $this->formatPolicyData($data);
|
|
// dd($body);
|
|
|
|
|
|
// $body = [
|
|
// "PolicyNumber" => "4016/PPN/A/O/53167743/00/000",
|
|
// "CDBGAccountNumber" => "CD-MUM-0026",
|
|
// "CorrelationId" => "550e8400-e29b-41d4-a716-446655440016",
|
|
// "MemberDetails" => [
|
|
// [
|
|
// "MemberEmpId" => "EMPID3625562",
|
|
// "DOJ" => "21-MAR-2019",
|
|
// "InsuredName" => "Jeeva",
|
|
// "DOB" => "7-JUL-1993",
|
|
// "Relationship" => "SELF",
|
|
// "Gender" => "MALE",
|
|
// "DOC" => '28-Oct-2025',
|
|
// "SumInsured" => "500000",
|
|
// "EmailId" => "Jeeva@GMAIL.COM",
|
|
// "FlagStatus" => "A"
|
|
// ],
|
|
// [
|
|
// "MemberEmpId" => "EMPID3625562",
|
|
// "DOJ" => "21-MAR-2019",
|
|
// "InsuredName" => "Muthu",
|
|
// "DOB" => "8-AUG-1970",
|
|
// "Relationship" => "MOTHER",
|
|
// "Gender" => "FEMALE",
|
|
// "DOC" => '28-Oct-2025',
|
|
// "EmailId" => "Muthu@GMAIL.COM",
|
|
// "FlagStatus" => "A"
|
|
// ],
|
|
// ]
|
|
// ];
|
|
|
|
|
|
$body = [
|
|
"PolicyNumber" => "4016/PPN/A/O/53185987/00/000",
|
|
"CDBGAccountNumber" => "CD-MUM-0026",
|
|
"CorrelationId" => "550e8400-e29b-41d4-a716-446655440021",
|
|
"MemberDetails" => [
|
|
[
|
|
"MemberEmpId" => "EMPID3625564",
|
|
"DOJ" => "21-MAR-2019",
|
|
"InsuredName" => "Jeeva",
|
|
"DOB" => "7-JUL-1993",
|
|
"Relationship" => "SELF",
|
|
"Gender" => "MALE",
|
|
"DOC" => '18-Nov-2025',
|
|
"SumInsured" => "500000",
|
|
"EmailId" => "Jeeva@GMAIL.COM",
|
|
"FlagStatus" => "A"
|
|
],
|
|
[
|
|
"MemberEmpId" => "EMPID3625564",
|
|
"DOJ" => "21-MAR-2019",
|
|
"InsuredName" => "Muthu",
|
|
"DOB" => "8-AUG-1970",
|
|
"Relationship" => "MOTHER",
|
|
"Gender" => "FEMALE",
|
|
"DOC" => '18-Nov-2025',
|
|
"EmailId" => "Muthu@GMAIL.COM",
|
|
"FlagStatus" => "A"
|
|
],
|
|
]
|
|
];
|
|
|
|
$response = call_third_party_api($url, 'POST', $headers, $body, true); // true = raw body mode
|
|
// print_rr(json_encode($response));die();
|
|
return $this->response->setJSON($response);
|
|
}
|
|
|
|
public function getEnrollmentBatchStatus()
|
|
{
|
|
helper('api');
|
|
|
|
//fetch token
|
|
$tokenResponse = $this->generateAuthToken();
|
|
if (!$tokenResponse || empty($tokenResponse['data']['access_token'])) {
|
|
return $this->response->setJSON([
|
|
'status' => false,
|
|
'message' => 'Token generation failed.',
|
|
'data' => $tokenResponse
|
|
]);
|
|
}
|
|
$token = $tokenResponse['data']['access_token'];
|
|
|
|
|
|
$url = env('ICICI_BASE_URL').'/batchstatus';
|
|
$headers = [
|
|
'Authorization: Bearer ' . $token,
|
|
'Content-Type: application/json'
|
|
];
|
|
|
|
// dd($headers);
|
|
|
|
$body = [
|
|
"PolicyNumber" => "4016/PPN/A/O/53185987/00/000",
|
|
"BatchId" => "3727144",
|
|
"CorrelationId" => "550e8400-e29b-41d4-a716-446655440021"
|
|
];
|
|
|
|
$response = call_third_party_api($url, 'POST', $headers, $body, true);
|
|
|
|
return $this->response->setJSON($response);
|
|
}
|
|
|
|
public function fetchUHIDDetails()
|
|
{
|
|
helper('api');
|
|
|
|
//fetch token
|
|
$tokenResponse = $this->generateAuthToken('esbgpauhid');
|
|
if (!$tokenResponse || empty($tokenResponse['data']['access_token'])) {
|
|
return $this->response->setJSON([
|
|
'status' => false,
|
|
'message' => 'Token generation failed.',
|
|
'data' => $tokenResponse
|
|
]);
|
|
}
|
|
$token = $tokenResponse['data']['access_token'];
|
|
|
|
// print_rr($token);
|
|
|
|
$url = env('ICICI_BASE_URL').'/fetchuhid';
|
|
$headers = [
|
|
'Authorization: Bearer ' . $token,
|
|
'Content-Type: application/json'
|
|
];
|
|
|
|
$body = [
|
|
"PolicyNumber" => "4016/PPN/A/O/53185987/00/000",
|
|
"IMID" => "201580517901",
|
|
"CorrelationId" => "550e8400-e29b-41d4-a716-446655440020"
|
|
];
|
|
|
|
$response = call_third_party_api($url, 'POST', $headers, $body, true);
|
|
|
|
return $this->response->setJSON($response);
|
|
}
|
|
|
|
public function formatPolicyData($data)
|
|
{
|
|
// Helper to format date
|
|
$formatDate = function ($date) {
|
|
return strtoupper(date('j-M-Y', strtotime($date))); // Example: 7-JUL-1983
|
|
};
|
|
|
|
// Generate UUID v4 for CorrelationId
|
|
$generateUUID = function () {
|
|
return sprintf(
|
|
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
|
mt_rand(0, 0xffff),
|
|
mt_rand(0, 0xffff),
|
|
mt_rand(0, 0xffff),
|
|
mt_rand(0, 0x0fff) | 0x4000,
|
|
mt_rand(0, 0x3fff) | 0x8000,
|
|
mt_rand(0, 0xffff),
|
|
mt_rand(0, 0xffff),
|
|
mt_rand(0, 0xffff)
|
|
);
|
|
};
|
|
|
|
// Map MemberDetails
|
|
$memberDetails = array_map(function ($row) use ($formatDate) {
|
|
return [
|
|
"MemberEmpId" => $row['MemberEmpId'],
|
|
"DOJ" => $formatDate($row['DOJ']),
|
|
"InsuredName" => $row['InsuredName'],
|
|
"DOB" => $formatDate($row['DOB']),
|
|
"Relationship" => strtoupper($row['Relationship']),
|
|
"Gender" => strtoupper($row['Gender']),
|
|
"DOC" => $formatDate($row['DOC']),
|
|
"SumInsured" => $row['SumInsured'],
|
|
"EmailId" => $row['EmailId'],
|
|
"FlagStatus" => "A" // fixed value
|
|
];
|
|
}, $data);
|
|
|
|
// Final body
|
|
return [
|
|
"PolicyNumber" => $data[0]['policyNumber'] ?? null,
|
|
"CDBGAccountNumber" => $data[0]['CDBGAccountNumber'] ?? null , // "CD-MUM-0026",
|
|
"CorrelationId" => $generateUUID(),
|
|
"MemberDetails" => $memberDetails
|
|
];
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// $body = [
|
|
// "PolicyNumber" => "4016/A/O/53077718/00/000",
|
|
// "CDBGAccountNumber" => "CD-MUM-0026",
|
|
// "CorrelationId" => "550e8400-e29b-41d4-a716-446655440001",
|
|
// "MemberDetails" => [
|
|
// [
|
|
// "MemberEmpId" => "EMPID3625557",
|
|
// "DOJ" => "21-MAR-2019",
|
|
// "InsuredName" => "Kumar",
|
|
// "DOB" => "7-JUL-1983",
|
|
// "Relationship" => "SELF",
|
|
// "Gender" => "MALE",
|
|
// "DOC" => "08-JUL-2025",
|
|
// "SumInsured" => "400000",
|
|
// "EmailId" => "KUMAR@GMAIL.COM",
|
|
// "FlagStatus" => "A"
|
|
// ],
|
|
// [
|
|
// "MemberEmpId" => "EMPID3625557",
|
|
// "DOJ" => "21-MAR-2019",
|
|
// "InsuredName" => "Saranya",
|
|
// "DOB" => "8-AUG-1970",
|
|
// "Relationship" => "MOTHER",
|
|
// "Gender" => "FEMALE",
|
|
// "DOC" => "08-JUL-2025",
|
|
// "SumInsured" => "400000",
|
|
// "EmailId" => "Saranya@GMAIL.COM",
|
|
// "FlagStatus" => "A"
|
|
// ],
|
|
// ]
|
|
// ];
|
|
|
|
|
|
}
|