1118 lines
50 KiB
PHP
1118 lines
50 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
use App\Helpers\DepositHelper;
|
|
use App\helpers\JWTToken;
|
|
use CodeIgniter\HTTP\IncomingRequest;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
use CodeIgniter\API\ResponseTrait;
|
|
|
|
use App\Models\UserModel;
|
|
use App\Models\ClientModel;
|
|
use App\Models\ClientBranchModel;
|
|
use App\Models\ClientKYCDocsModel;
|
|
use App\Models\ClientDepositModel;
|
|
use App\Models\ClientPolicyModel;
|
|
use App\Models\ClientRMModel;
|
|
use App\Models\InsurerBranchModel;
|
|
use App\Models\InsurerModel;
|
|
use App\Models\KYCDocsModel;
|
|
use App\Models\KYCEntityTypeModel;
|
|
use App\Models\LevelContactModel;
|
|
use App\Models\PolicesModel;
|
|
use App\Models\TPABranchModel;
|
|
use App\Models\TPAModel;
|
|
use App\Models\StateModel;
|
|
use App\Models\PolicyGridModel;
|
|
use App\Models\PolicyPremium1Model;
|
|
use App\Models\PolicyPremium2Model;
|
|
use App\Models\EmployeeModel;
|
|
|
|
|
|
|
|
class ClientController extends AdminController
|
|
{
|
|
use ResponseTrait;
|
|
|
|
protected $myLogger;
|
|
protected $clientModel;
|
|
protected $userModel;
|
|
protected $clientBranchModel;
|
|
protected $clientKYCDocsModel;
|
|
protected $clientPolicyModel;
|
|
protected $clientRMModel;
|
|
protected $insurerBranchModel;
|
|
protected $insurerModel;
|
|
protected $kycDocsModel;
|
|
protected $kycEntityTypeModel;
|
|
protected $levelContactModel;
|
|
protected $policesModel;
|
|
protected $tpaBranchModel;
|
|
protected $tpaModel;
|
|
protected $stateModel;
|
|
protected $policyGridModel;
|
|
protected $policyPremium1Model;
|
|
protected $policyPremium2Model;
|
|
protected $clientDepositModel;
|
|
protected $employeeModel;
|
|
|
|
public function __construct()
|
|
{
|
|
set_session_context('Client');
|
|
$this->myLogger = \Config\Services::mylogger();
|
|
|
|
$this->clientModel = new ClientModel();
|
|
$this->userModel = new UserModel();
|
|
$this->clientBranchModel = new ClientBranchModel();
|
|
$this->clientKYCDocsModel = new ClientKYCDocsModel();
|
|
$this->clientDepositModel = new ClientDepositModel();
|
|
$this->clientPolicyModel = new ClientPolicyModel();
|
|
$this->clientRMModel = new ClientRMModel();
|
|
$this->insurerBranchModel = new InsurerBranchModel();
|
|
$this->insurerModel = new InsurerModel();
|
|
$this->kycDocsModel = new KYCDocsModel();
|
|
$this->kycEntityTypeModel = new KYCEntityTypeModel();
|
|
$this->levelContactModel = new LevelContactModel();
|
|
$this->policesModel = new PolicesModel();
|
|
$this->tpaBranchModel = new TPABranchModel();
|
|
$this->tpaModel = new TPAModel();
|
|
$this->stateModel = new StateModel();
|
|
$this->policyGridModel = new PolicyGridModel();
|
|
$this->policyPremium1Model = new PolicyPremium1Model();
|
|
$this->policyPremium2Model = new PolicyPremium2Model();
|
|
$this->employeeModel = new EmployeeModel();
|
|
|
|
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
|
|
// $token = $_SESSION;
|
|
// $token = $request->getHeaderLine('Authorization');
|
|
|
|
|
|
// print_r(JWTToken::getIdFromToken($token));
|
|
|
|
// die();
|
|
|
|
$this->myLogger->logme('error','Client list function called');
|
|
$headerData['page_name'] = 'Client List';
|
|
$data['clientList'] = $this->clientModel->getCreatedByUserName();
|
|
$data['client_rm'] = $this->clientRMModel->getAllClientRM();
|
|
// echo '<pre>';
|
|
// print_r($data); die;
|
|
echo view('layout/header', $headerData);
|
|
echo view('client_list', $data);
|
|
echo view('layout/footer');
|
|
|
|
// $this->loadLayout('client_onboarding', $data);
|
|
}
|
|
|
|
public function clientOnboarding()
|
|
{
|
|
|
|
$this->myLogger->logme('error','Client Onboarding function called');
|
|
$headerData['page_name'] = 'Client Onboarding';
|
|
|
|
$data['entity'] = $this->kycEntityTypeModel->findAll();
|
|
$data['kyc_docs'] = $this->kycDocsModel->findAll();
|
|
$data['police'] = $this->policesModel->findAll();
|
|
$data['insurer'] = $this->insurerBranchModel ->getInsurerBranchesWithInsurerNames();
|
|
$data['tpa'] = $this->tpaBranchModel ->getTpaBranchesWithTpaNames();
|
|
$data['state'] = $this->stateModel->getAllStates();
|
|
$data['RM'] = $this->userModel->findAll();
|
|
$data['policyGridData'] = $this->policyGridModel->findAll();
|
|
|
|
// echo "<pre>";
|
|
// print_r($data); die;
|
|
|
|
echo view('layout/header', $headerData);
|
|
echo view('client_onboarding', $data);
|
|
echo view('layout/footer');
|
|
|
|
}
|
|
|
|
// In your controller
|
|
public function deposit($id = null)
|
|
{
|
|
$headerData['page_name'] = 'Client Deposit';
|
|
|
|
$data['clientData'] = $this->clientPolicyModel->getinsurerswithclientid($id);
|
|
$data['depositsummary'] = $this->clientPolicyModel->getDepositlistsummary($id);
|
|
|
|
// Fetch associated insurer names and balances
|
|
$balances = $this->clientPolicyModel->getBalances($id);
|
|
$data['balances'] = $balances;
|
|
|
|
echo view('layout/header', $headerData);
|
|
echo view('client_deposit_list', $data);
|
|
echo view('layout/footer');
|
|
}
|
|
|
|
public function view_Deposit($insurerId)
|
|
{
|
|
// Load your model to fetch data based on $clientId and $insurerId
|
|
$subTypeOptions = [
|
|
1 => 'Deposit',
|
|
2 => 'Adjustment',
|
|
3 => 'Deletion',
|
|
// Add more options as needed
|
|
];
|
|
$data['subTypeOptions'] = $subTypeOptions;
|
|
$headerData['page_name'] = 'Client Deposit';
|
|
$data['insurerName']= $this->insurerModel->getInsurerName($insurerId);
|
|
$loggedInUserID = get_session_userid();
|
|
// $data['clientData']= $this->clientPolicyModel->getinsurerswithinsurenceid($insurerId);
|
|
$clientId = $this->request->getGet('client_id');
|
|
$data['depositdata']= $this->clientPolicyModel->getdepositData($clientId,$insurerId);
|
|
$data['clientData'] = $this->clientPolicyModel->getClientById($clientId);
|
|
$data['deposiamount'] = $this->clientPolicyModel->getDepositSummary($clientId, $insurerId);
|
|
|
|
|
|
// print_r($data['depositdata'] );die;
|
|
// Load the view for the new list page
|
|
echo view('layout/header', $headerData);
|
|
echo view('view_deposit',$data);
|
|
echo view('layout/footer');
|
|
}
|
|
|
|
|
|
public function saveDeposit()
|
|
{
|
|
// Retrieve form data from POST request
|
|
$loggedInUserID = get_session_userid();
|
|
|
|
// Prepare the array with data
|
|
$data = [
|
|
'amount' => $this->request->getPost('amount'),
|
|
'sub_type_id' => $this->request->getPost('sub_type_id'),
|
|
'client_id' => $this->request->getPost('client_id'),
|
|
'insurer_id' => $this->request->getPost('insurer_id'),
|
|
'description' => $this->request->getPost('description'),
|
|
'transaction_type' => $this->request->getPost('transaction_type') ?: 'Credit',
|
|
'updated_by' => 1, // You need to set the correct value for updated_by
|
|
];
|
|
|
|
// Call the saveDeposit function from DepositHelper
|
|
$response = DepositHelper::saveDeposit($data, $loggedInUserID);
|
|
|
|
// Return a boolean value based on success
|
|
return $this->response->setJSON(['success' => $response['success']]);
|
|
}
|
|
|
|
|
|
public function editClientOnboarding($id = null)
|
|
{
|
|
|
|
$this->myLogger->logme('error','Edit Client Onboarding function called');
|
|
$headerData['page_name'] = 'Edit Client Onboarding';
|
|
|
|
$editData['RM'] = $this->userModel->findAll();
|
|
$editData['tpa'] = $this->tpaBranchModel ->getTpaBranchesWithTpaNames();
|
|
$editData['state'] = $this->stateModel->getAllStates();
|
|
$editData['police'] = $this->policesModel->findAll();
|
|
$editData['entity'] = $this->kycEntityTypeModel->findAll();
|
|
$editData['insurer'] = $this->insurerBranchModel ->getInsurerBranchesWithInsurerNames();
|
|
$editData['kyc_docs'] = $this->kycDocsModel->findAll();
|
|
$editData['policyGridData'] = $this->policyGridModel->findAll();
|
|
|
|
|
|
$editData['client'] = $this->clientModel->where(['id' => $id, 'is_active' => 1])->first();
|
|
$editData['client_kyc'] = $this->clientKYCDocsModel->where('client_id', $id)->findAll();
|
|
$editData['client_branch'] = $this->clientBranchModel->where(['client_id' => $id, 'is_active' => 1])->findAll();
|
|
$editData['client_relation'] = $this->clientRMModel->where(['client_id' => $id, 'is_active' => 1])->findAll();
|
|
$editData['client_policy'] = $this->clientPolicyModel->getClientPolicyByClientId($id);
|
|
|
|
// echo "<pre>";
|
|
// print_r($editData); die;
|
|
|
|
echo view('layout/header', $headerData);
|
|
echo view('client_onboarding', $editData);
|
|
echo view('layout/footer');
|
|
|
|
}
|
|
|
|
public function createClientGeneralInfo()
|
|
{
|
|
|
|
$this->myLogger->logme('error','Client general info function called');
|
|
$data = $this->request->getPost();
|
|
$data['created_by'] = get_session_userid();
|
|
$insert = $this->clientModel->insert($data);
|
|
if($insert){
|
|
$client_data = $this->clientModel->where(['id' => $insert, 'is_active' => 1])->first();
|
|
return $this->respond(['status' => true,'code' => 200,'data' => $client_data], 200);
|
|
|
|
}else{
|
|
return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200);
|
|
|
|
}
|
|
}
|
|
|
|
public function editClientGeneralInfo()
|
|
{
|
|
$this->myLogger->logme('error','edit client general info function called');
|
|
$id = $this->request->getPost('PrimaryKey');
|
|
$data = $this->request->getPost();
|
|
$data['updated_by'] = get_session_userid();
|
|
$update = $this->clientModel->update($id,$data);
|
|
if($update){
|
|
return $this->respond(['status' => true,'code' => 200,'data' => $data], 200);
|
|
}else{
|
|
return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200);
|
|
}
|
|
}
|
|
|
|
public function createClientKYCInfo()
|
|
{
|
|
$this->myLogger->logme('error','create Client kyc function called');
|
|
$data = $this->request->getPost();
|
|
unset($data['file_name']);
|
|
$File = file_Upload($this->request->getFile('file_name'));
|
|
if(!empty($File)){
|
|
$data['file_name'] = $File;
|
|
}
|
|
|
|
$data['created_by'] = get_session_userid();
|
|
$insert = $this->clientKYCDocsModel->insert($data);
|
|
if($insert){
|
|
|
|
$kycDocs = $this->clientKYCDocsModel->where('client_id',$this->request->getPost('client_id'))->findAll();
|
|
return $this->respond(['status' => true,'code' => 200,'data' => $kycDocs, 'file_name' => $File], 200);
|
|
}else{
|
|
return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200);
|
|
}
|
|
}
|
|
|
|
public function editClientKYCInfo()
|
|
{
|
|
|
|
$this->myLogger->logme('error','edit client kyc function called');
|
|
$File = file_Upload($this->request->getFile('file_name'));
|
|
if(!empty($File)){
|
|
$data['file_name'] = $File;
|
|
}
|
|
$id = $this->request->getPost('PrimaryKey');
|
|
$data['client_id'] = $id;
|
|
$data['kyc_doc_type_id'] = $this->request->getPost('kyc_doc_id');
|
|
$data['updated_by'] = get_session_userid();
|
|
$insert = $this->clientKYCDocsModel->insert($data);
|
|
if($insert){
|
|
$kycDocs = $this->clientKYCDocsModel->getKycDocsName($id);
|
|
return $this->respond(['status' => true,'code' => 200,'data' => $kycDocs], 200);
|
|
}else{
|
|
return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200);
|
|
|
|
}
|
|
}
|
|
|
|
public function deleteClientKycDocs($id=null)
|
|
{
|
|
|
|
$delete = $this->clientKYCDocsModel->where('kyc_doc_type_id', $id)->delete();
|
|
if($delete){
|
|
return $this->respond(['status' => true,'code' => 200,'id' => $id], 200);
|
|
}else{
|
|
return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200);
|
|
}
|
|
}
|
|
|
|
public function deleteClientKycOtherDocs($id=null)
|
|
{
|
|
|
|
$delete = $this->clientKYCDocsModel->where('id', $id)->delete();
|
|
if($delete){
|
|
return $this->respond(['status' => true,'code' => 200,'id' => $id], 200);
|
|
}else{
|
|
return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200);
|
|
}
|
|
}
|
|
|
|
public function createClientRelation()
|
|
{
|
|
|
|
$this->myLogger->logme('error','Client relation function called');
|
|
|
|
$data['client_id'] = $this->request->getPost('client_id');
|
|
$data['created_by'] = get_session_userid();
|
|
$inserted = false;
|
|
|
|
if ($this->request->getPost('head')) {
|
|
$data['level'] = "1";
|
|
$data['user_id'] = $this->request->getPost('head');
|
|
$inserted = $this->clientRMModel->insert($data);
|
|
}
|
|
|
|
if ($this->request->getPost('manager')) {
|
|
$data['level'] = "2";
|
|
$data['user_id'] = $this->request->getPost('manager');
|
|
$inserted = $this->clientRMModel->insert($data);
|
|
}
|
|
|
|
if ($this->request->getPost('account_manager')) {
|
|
$data['level'] = "3";
|
|
foreach ($this->request->getPost('account_manager') as $value) {
|
|
$data['user_id'] = $value;
|
|
$inserted = $this->clientRMModel->insert($data);
|
|
}
|
|
}
|
|
|
|
if ($inserted) {
|
|
return $this->respond(['status' => true,'code' => 200,'data' => $this->request->getPost()], 200);
|
|
} else {
|
|
return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200);
|
|
}
|
|
}
|
|
|
|
public function editClientRelation()
|
|
{
|
|
$this->myLogger->logme('error','Client relation function called');
|
|
|
|
$id = $this->request->getPost('PrimaryKey');
|
|
$data['client_id'] = $this->request->getPost('client_id');
|
|
$data['updated_by'] = get_session_userid();
|
|
$inserted = false;
|
|
|
|
if ($this->request->getPost('head')) {
|
|
$data['user_id'] = $this->request->getPost('head');
|
|
$checkHead = $this->clientRMModel->checkExistenceOfClientRelation($id, $this->request->getPost('head'), 1);
|
|
if($checkHead){
|
|
$inserted = $this->clientRMModel->where('client_id', $id )->where('level', 1)->set($data)->update();
|
|
}else{
|
|
$data['level'] = "1";
|
|
$data['user_id'] = $this->request->getPost('head');
|
|
$inserted = $this->clientRMModel->insert($data);
|
|
}
|
|
}
|
|
|
|
if ($this->request->getPost('manager')) {
|
|
$data['user_id'] = $this->request->getPost('manager');
|
|
$checkHead = $this->clientRMModel->checkExistenceOfClientRelation($id, $this->request->getPost('manager'), 2);
|
|
if($checkHead){
|
|
$inserted = $this->clientRMModel->where('client_id', $id )->where('level', 2)->set($data)->update();
|
|
}else{
|
|
$data['level'] = "2";
|
|
$data['user_id'] = $this->request->getPost('manager');
|
|
$inserted = $this->clientRMModel->insert($data);
|
|
}
|
|
}
|
|
|
|
if ($this->request->getPost('account_manager')) {
|
|
|
|
$this->clientRMModel->where('client_id', $id)->where('level', 3)->delete();
|
|
$data['level'] = "3";
|
|
foreach ($this->request->getPost('account_manager') as $value) {
|
|
$data['user_id'] = $value;
|
|
$inserted = $this->clientRMModel->insert($data);
|
|
}
|
|
}
|
|
|
|
$lastQuery = $this->clientRMModel->getLastQuery();
|
|
|
|
if ($inserted) {
|
|
return $this->respond(['status' => true,'code' => 200,'data' => $this->request->getPost(), "place" => 'edit'], 200);
|
|
} else {
|
|
return $this->respond(['status' => false,'code' => 404,"place" => 'edit', 'message' => 'no data found'], 200);
|
|
}
|
|
}
|
|
|
|
public function createClientBranch()
|
|
{
|
|
|
|
$this->myLogger->logme('error','Client branch CREATE function called');
|
|
$data = $this->request->getPost();
|
|
$data['created_by'] = get_session_userid();
|
|
$insert = $this->clientBranchModel->insert($data);
|
|
|
|
if($insert){
|
|
for ($i = 0; $i < count($this->request->getPost('name')); $i++) {
|
|
// Prepare data to insert
|
|
$data = [
|
|
'contact_type' => 'client',
|
|
'ref_id' => $insert,
|
|
'created_by' => get_session_userid(),
|
|
'name' => $this->request->getPost('name')[$i],
|
|
'email' => $this->request->getPost('email')[$i],
|
|
'mobile' => $this->request->getPost('mobile')[$i],
|
|
'designation' => $this->request->getPost('designation')[$i]
|
|
];
|
|
$contacts = $this->levelContactModel->insert($data);
|
|
}
|
|
}
|
|
|
|
if($insert){
|
|
$branchData = $this->clientBranchModel->where('client_id', $this->request->getPost('client_id'))->findAll();
|
|
return $this->respond(['status' => true,'code' => 200,'data' => $branchData], 200);
|
|
}else{
|
|
return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200);
|
|
}
|
|
}
|
|
|
|
public function editClientBranch()
|
|
{
|
|
|
|
$this->myLogger->logme('error','Client branch EDIT function called');
|
|
$id = $this->request->getPost('PrimaryKey');
|
|
$client_id = $this->request->getPost('client_id');
|
|
$data = $this->request->getPost();
|
|
$data['updated_by'] = get_session_userid();
|
|
$insert = $this->clientBranchModel->update($id, $data);
|
|
$this->myLogger->logme('error','Client branch EDITED by {data}', ['data' => get_session_userid()]);
|
|
|
|
|
|
if($insert){
|
|
|
|
$this->levelContactModel->where('ref_id', $id)->where('contact_type', 'client')->delete();
|
|
for ($i = 0; $i < count($this->request->getPost('name')); $i++) {
|
|
$data = [
|
|
'contact_type' => 'client',
|
|
'ref_id' => $id,
|
|
'updated_by' => get_session_userid(),
|
|
'name' => $this->request->getPost('name')[$i],
|
|
'email' => $this->request->getPost('email')[$i],
|
|
'mobile' => $this->request->getPost('mobile')[$i],
|
|
'designation' => $this->request->getPost('designation')[$i]
|
|
];
|
|
$contacts = $this->levelContactModel->insert($data);
|
|
}
|
|
}
|
|
|
|
if($insert){
|
|
$branchData = $this->clientBranchModel->where('client_id', $client_id)->findAll();
|
|
return $this->respond(['status' => true,'code' => 200,'data' => $branchData], 200);
|
|
}else{
|
|
return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200);
|
|
}
|
|
}
|
|
|
|
public function createClientPolicy()
|
|
{
|
|
|
|
$this->myLogger->logme('error','Client policy CREATE function called');
|
|
|
|
$insurerValue = (string) $this->request->getPost('insurer');
|
|
list($insurerBranchId, $insurerId) = explode('-', $insurerValue);
|
|
|
|
$data['insurer_branch_id'] = $insurerBranchId;
|
|
$data['insurer_id'] = $insurerId;
|
|
|
|
$tpaValue = (string) $this->request->getPost('tpa');
|
|
list($tpaBranchId, $tpaId) = explode('-', $tpaValue);
|
|
|
|
$data['tpa_branch_id'] = $tpaBranchId;
|
|
$data['tpa_id'] = $tpaId;
|
|
$data['policy_id'] = $this->request->getPost('policy_id');
|
|
$data['policy_type_id'] = $this->request->getPost('policy_type_id');
|
|
$data['client_id'] = $this->request->getPost('client_id');
|
|
|
|
|
|
$data['no_of_lives'] = $this->request->getPost('no_of_lives');
|
|
$data['policy_status'] = $this->request->getPost('policy_status');
|
|
$data['no_of_employees'] = $this->request->getPost('no_of_employees');
|
|
$data['earned_premium_date'] = change_date_format($this->request->getPost('earned_premium_date'), 'd-m-Y', 'Y-m-d');
|
|
$data['claims_incurred_date'] = change_date_format($this->request->getPost('claims_incurred_date'), 'd-m-Y', 'Y-m-d');
|
|
$data['incurred_claims_ratio'] = $this->request->getPost('incurred_claims_ratio');
|
|
$data['no_lives_at_inception'] = $this->request->getPost('no_lives_at_inception');
|
|
$data['premium_paid_at_inception'] = $this->request->getPost('premium_paid_at_inception');
|
|
$data['claims_experience_for_last_3_years'] = $this->request->getPost('claims_experience_for_last_3_years');
|
|
$data['earned_premium_amount'] = $this->request->getPost('earned_premium_amount');
|
|
$data['claims_incurred_amount'] = $this->request->getPost('claims_incurred_amount');
|
|
|
|
|
|
|
|
$data['policy_start_date'] = change_date_format($this->request->getPost('policy_start_date'), 'd-m-Y', 'Y-m-d');
|
|
$data['policy_end_date'] = change_date_format($this->request->getPost('policy_end_date'), 'd-m-Y', 'Y-m-d');
|
|
|
|
|
|
$data['created_by'] = get_session_userid();
|
|
|
|
$insert = $this->clientPolicyModel->insert($data);
|
|
if($insert){
|
|
$clientPoliceData = $this->clientPolicyModel->getClientPolicyByClientId($this->request->getPost('client_id'));
|
|
return $this->respond(['status' => true,'code' => 200,'data' => $clientPoliceData, 'method' => 'CERATE'], 200);
|
|
}else{
|
|
return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200);
|
|
}
|
|
}
|
|
|
|
public function editClientPolicy()
|
|
{
|
|
|
|
$this->myLogger->logme('error','Client policy function called');
|
|
|
|
$id = $this->request->getPost('PrimaryKey');
|
|
$client_id = $this->request->getPost('client_id');
|
|
|
|
$insurerValue = (string) $this->request->getPost('insurer');
|
|
list($insurerBranchId, $insurerId) = explode('-', $insurerValue);
|
|
|
|
$data['insurer_branch_id'] = $insurerBranchId;
|
|
$data['insurer_id'] = $insurerId;
|
|
|
|
$tpaValue = (string) $this->request->getPost('tpa');
|
|
list($tpaBranchId, $tpaId) = explode('-', $tpaValue);
|
|
|
|
$data['tpa_branch_id'] = $tpaBranchId;
|
|
$data['tpa_id'] = $tpaId;
|
|
$data['policy_id'] = $this->request->getPost('policy_id');
|
|
$data['policy_type_id'] = $this->request->getPost('policy_type_id');
|
|
$data['policy_start_date'] = change_date_format($this->request->getPost('policy_start_date'), 'd-m-Y', 'Y-m-d');
|
|
$data['policy_end_date'] = change_date_format($this->request->getPost('policy_end_date'), 'd-m-Y', 'Y-m-d');
|
|
|
|
$data['insured'] = $this->request->getPost('insured');
|
|
$data['no_of_lives'] = $this->request->getPost('no_of_lives');
|
|
$data['policy_status'] = $this->request->getPost('policy_status');
|
|
$data['no_of_employees'] = $this->request->getPost('no_of_employees');
|
|
$data['earned_premium_date'] = change_date_format($this->request->getPost('earned_premium_date'), 'd-m-Y', 'Y-m-d');
|
|
$data['claims_incurred_date'] = change_date_format($this->request->getPost('claims_incurred_date'), 'd-m-Y', 'Y-m-d');
|
|
$data['incurred_claims_ratio'] = $this->request->getPost('incurred_claims_ratio');
|
|
$data['no_lives_at_inception'] = $this->request->getPost('no_lives_at_inception');
|
|
$data['premium_paid_at_inception'] = $this->request->getPost('premium_paid_at_inception');
|
|
$data['claims_experience_for_last_3_years'] = $this->request->getPost('claims_experience_for_last_3_years');
|
|
$data['earned_premium_amount'] = $this->request->getPost('earned_premium_amount');
|
|
$data['claims_incurred_amount'] = $this->request->getPost('claims_incurred_amount');
|
|
|
|
$data['updated_by'] = get_session_userid();
|
|
$insert = $this->clientPolicyModel->update($id,$data);
|
|
$lastQuery = $this->clientPolicyModel->getLastQuery();
|
|
|
|
// echo '<pre>';
|
|
// print_r($lastQuery); die;
|
|
|
|
if($insert){
|
|
$clientPoliceData = $this->clientPolicyModel->getClientPolicyByClientId($client_id);
|
|
return $this->respond(['status' => true,'code' => 200,'data' => $clientPoliceData, 'method' => 'EDIT'], 200);
|
|
}else{
|
|
return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200);
|
|
}
|
|
}
|
|
|
|
public function createClientPolicyPremium()
|
|
{
|
|
// print_r($this->request->getPost());die();
|
|
$policy_type = $this->request->getPost('policy_type');
|
|
$client_id = $this->request->getPost('client_id');
|
|
$client_policy_id = $this->request->getPost('client_policy_id');
|
|
$policy_grid_id = $this->request->getPost('policy_grid_id');
|
|
$multiplier = $this->request->getPost('multiplier');
|
|
$si_or_bp = $this->request->getPost('si_or_bp');
|
|
$basic_multiplier = $this->request->getPost('basic_multiplier');
|
|
$premium_multiplier =$this->request->getPost('premium_multiplier');
|
|
$basic_pay = $this->request->getPost('basic_pay');
|
|
|
|
if($policy_type !== null && $policy_type !== ''){
|
|
|
|
$this->policyPremium1Model->where('client_id', $client_id)->where('client_policy_id', $client_policy_id)->set('is_active', 0)->update();
|
|
|
|
$premiumData = $this->request->getPost('premium');
|
|
for ($i = 0; $i < count($premiumData); $i++) {
|
|
$data = [
|
|
'client_id' => $client_id,
|
|
'client_policy_id' => $client_policy_id,
|
|
'policy_grid_id' => $policy_grid_id,
|
|
'created_by' => get_session_userid(),
|
|
];
|
|
|
|
if(is_array($this->request->getPost('si'))){
|
|
$si = isset($this->request->getPost('si')[$i]) ? $this->request->getPost('si')[$i] : null;
|
|
}else{
|
|
$si = $this->request->getPost('si');
|
|
}
|
|
|
|
if(is_array($this->request->getPost('premium'))){
|
|
$premium = isset($this->request->getPost('premium')[$i]) ? $this->request->getPost('premium')[$i] : null;
|
|
}else{
|
|
$premium = $this->request->getPost('premium');
|
|
}
|
|
// $basic_gpa_premium = isset($basic_gpa_premium[$i]) ? $basic_gpa_premium[$i] : null;
|
|
if ($si !== null) {
|
|
$data['si'] = $si;
|
|
}
|
|
if ($premium !== null) {
|
|
$data['premium'] = $premium;
|
|
}
|
|
|
|
if ($multiplier !== null) {
|
|
$data['multiplier'] = $multiplier;
|
|
}
|
|
|
|
if ($si_or_bp !== null) {
|
|
$data['si_or_bp'] = $si_or_bp;
|
|
}
|
|
|
|
if ($premium_multiplier !== null) {
|
|
$data['multiplier'] = $premium_multiplier;
|
|
}
|
|
|
|
if ($basic_multiplier !== null) {
|
|
$data['basic_multiplier'] = $basic_multiplier;
|
|
}
|
|
|
|
if ($basic_pay !== null) {
|
|
$data['basic_pay'] = $basic_pay;
|
|
}
|
|
|
|
$this->policyPremium1Model->insert($data);
|
|
}
|
|
$data = $this->request->getPost();
|
|
$insert = true;
|
|
|
|
if($insert){
|
|
return $this->respond(['status' => true,'code' => 200,'data' => $data], 200);
|
|
}else{
|
|
return $this->respond(['status' => false,'code' => 404, 'data' => $data,'message' => 'no data found'], 200);
|
|
|
|
}
|
|
// print_r($data);
|
|
// die();
|
|
// $data['created_by'] = get_session_userid();
|
|
// $this->policyPremium1Model->where('client_id', $client_id)->where('client_policy_id', $client_policy_id)->set('is_active', 0)->update();
|
|
// $insert = $this->policyPremium1Model->insert($data);
|
|
}else{
|
|
|
|
$this->policyPremium2Model->where('client_id', $client_id)->where('client_policy_id', $client_policy_id)->set('is_active', 0)->update();
|
|
$premiumData = $this->request->getPost('premium');
|
|
for ($i = 0; $i < count($premiumData); $i++) {
|
|
|
|
$data = [
|
|
'client_id' => $client_id,
|
|
'client_policy_id' => $client_policy_id,
|
|
'policy_grid_id' => $policy_grid_id,
|
|
'created_by' => get_session_userid(),
|
|
|
|
];
|
|
|
|
if(is_array($this->request->getPost('si'))){
|
|
$si = isset($this->request->getPost('si')[$i]) ? $this->request->getPost('si')[$i] : null;
|
|
}else{
|
|
$si = $this->request->getPost('si');
|
|
}
|
|
$age_from = isset($this->request->getPost('age_from')[$i]) ? $this->request->getPost('age_from')[$i] : null;
|
|
$age_to = isset($this->request->getPost('age_to')[$i]) ? $this->request->getPost('age_to')[$i] : null;
|
|
$premium = isset($premiumData[$i]) ? $premiumData[$i] : null;
|
|
$grade = isset($this->request->getPost('grade')[$i]) ? $this->request->getPost('grade')[$i] : null;
|
|
$max_si = isset($this->request->getPost('max_si')[$i]) ? $this->request->getPost('max_si')[$i] : null;
|
|
|
|
if ($si !== null) {
|
|
$data['si'] = $si;
|
|
}
|
|
|
|
if ($age_from !== null) {
|
|
$data['age_from'] = $age_from;
|
|
}
|
|
|
|
if ($age_to !== null) {
|
|
$data['age_to'] = $age_to;
|
|
}
|
|
|
|
if ($premium !== null) {
|
|
$data['premium'] = $premium;
|
|
}
|
|
|
|
if ($max_si !== null) {
|
|
$data['max_si'] = $max_si;
|
|
}
|
|
|
|
if ($grade !== null) {
|
|
$data['grade'] = $grade;
|
|
}
|
|
|
|
$this->policyPremium2Model->insert($data);
|
|
}
|
|
$data = $this->request->getPost();
|
|
$insert = true;
|
|
}
|
|
|
|
if($insert){
|
|
return $this->respond(['status' => true,'code' => 200,'data' => $data], 200);
|
|
}else{
|
|
return $this->respond(['status' => false,'code' => 404, 'data' => $data,'message' => 'no data found'], 200);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getKycDocsById($id=null)
|
|
{
|
|
|
|
$this->myLogger->logme('error','getKycDocsById function called');
|
|
if($id){
|
|
$kyc_docs_data = $this->kycDocsModel->where(['kyc_type_id' => $id, 'is_active' => 1])->findAll();
|
|
$this->myLogger->logme('error','getKycDocs status TRUE');
|
|
return $this->respond(['status' => true,'code' => 200,'data' => $kyc_docs_data], 200);
|
|
}else{
|
|
$this->myLogger->logme('error','getKycDocs status FALSE');
|
|
return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200);
|
|
}
|
|
}
|
|
|
|
public function getPolicesByInsurerId($id = null)
|
|
{
|
|
$this->myLogger->logme('error','getPolicesByInsurerId function called');
|
|
if($id){
|
|
$police_data = $this->policesModel->where(['insurer_id' => $id, 'is_active' => 1])->findAll();
|
|
return $this->respond(['status' => true,'code' => 200,'data' => $police_data], 200);
|
|
}else{
|
|
return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200);
|
|
}
|
|
}
|
|
|
|
public function getSingleBranchDataById($id=null)
|
|
{
|
|
|
|
$this->myLogger->logme('error','getSingleBranchDataById function called');
|
|
if($id){
|
|
$branch_data = $this->clientBranchModel->where(['id' => $id, 'is_active' => 1])->first();
|
|
$branch_contact_data = $this->levelContactModel->where(['ref_id' => $id, 'contact_type'=>'client', 'is_active' => 1])->findAll();
|
|
return $this->respond(['status' => true,'code' => 200,'data' => $branch_data, 'contact' => $branch_contact_data], 200);
|
|
}else{
|
|
return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200);
|
|
}
|
|
|
|
}
|
|
|
|
public function getClientPolicyById($id=null)
|
|
{
|
|
$this->myLogger->logme('error','getClientPolicyById function called');
|
|
if($id){
|
|
$client_policy_data = $this->clientPolicyModel->where(['id' => $id, 'is_active' => 1])->first();
|
|
$insurer_id = $client_policy_data['insurer_id'];
|
|
$polices = $this->policesModel->where(['insurer_id' => $insurer_id, 'is_active' => 1])->findAll();
|
|
return $this->respond(['status' => true,'code' => 200,'data' => $client_policy_data, "insurer_id" => $client_policy_data['insurer_id'], 'policy' => $polices], 200);
|
|
}else{
|
|
return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200);
|
|
}
|
|
|
|
}
|
|
|
|
public function getpolicyGridData()
|
|
{
|
|
|
|
$client_policy_id = $this->request->getGet('client_policy_id');
|
|
$record = $this->clientPolicyModel->where('id', $client_policy_id)->first();
|
|
|
|
$emp_count = $this->employeeModel ->join('client_policy cp',"employees.client_id = cp.client_id")
|
|
->join('employee_polices ep',"cp.id = ep.client_policy_id AND employees.id = ep.employee_id")
|
|
->where("employees.client_id",$record['client_id'])
|
|
->where("employees.emp_status",'active')
|
|
->countAllResults();
|
|
|
|
if($emp_count = 0){
|
|
$emp_count = true;
|
|
}else{
|
|
$emp_count = false;
|
|
}
|
|
|
|
|
|
$data = $this->policesModel->getPolicyPremium($record['policy_id']);
|
|
$policy_name = $data[0]->policy_name;
|
|
$pattern = '/gmc/i';
|
|
$subject = $data[0]->policy_type;
|
|
if (preg_match($pattern, $subject)) {
|
|
$search_term = 'GMC';
|
|
} else {
|
|
$search_term = 'GPA';
|
|
}
|
|
$results = $this->policyGridModel->like('policy_type', $search_term)->findAll();
|
|
if($search_term === 'GPA'){
|
|
$premiumData = $this->policyPremium1Model->where(['client_id' => $record['client_id'], 'client_policy_id' => $client_policy_id, 'is_active' => 1])->findAll();
|
|
|
|
}else{
|
|
$premiumData = $this->policyPremium2Model->where(['client_id' => $record['client_id'], 'client_policy_id' => $client_policy_id, 'is_active' => 1])->findAll();
|
|
}
|
|
|
|
|
|
// echo '<pre>';
|
|
// print_r($results);
|
|
// print_r($data[0]->policy_type); die;
|
|
// echo "hello";
|
|
// print_r($premiumData);
|
|
return $this->respond(['status' => true,'code' => 200,'data' => $results, 'premiumData' => $premiumData, 'count' => $emp_count, 'policy_name' => $policy_name], 200);
|
|
|
|
}
|
|
|
|
public function policyGMCTerms()
|
|
{
|
|
|
|
try {
|
|
|
|
$this->myLogger->logme('error','Terms CREATE function called');
|
|
|
|
/*** Client Policy Table Primary Key(ID) ***/
|
|
$client_policy_id = $this->request->getPost("client_policy_id");
|
|
|
|
$data['sum_insured'] =$this->request->getPost("sum_insured");
|
|
$data['family_floater'] =$this->request->getPost("family_floater");
|
|
$data['corporatebuffer'] = $this->request->getPost("corporatebuffer");
|
|
$data['family_floaters'] = $this->request->getPost("family_floaters") ?? [];
|
|
|
|
$data['waiverofpreexistingdiseases'] =$this->request->getPost("waiverofpreexistingdiseases");
|
|
if ($data['waiverofpreexistingdiseases'] == 1) {
|
|
$data['maternitycoverage'] =$this->request->getPost("maternitycoverage");
|
|
$data['twindelivery'] =$this->request->getPost("twindelivery");
|
|
$data['preandpostnatal'] =$this->request->getPost("preandpostnatal");
|
|
$data['babyday1cover'] =$this->request->getPost("babyday1cover");
|
|
}else{
|
|
$data['maternitycoverage'] ="";
|
|
$data['twindelivery'] ="";
|
|
$data['preandpostnatal'] ="";
|
|
$data['babyday1cover'] ="";
|
|
}
|
|
$data['9monthwaitingperiodwaived'] =$this->request->getPost("9monthwaitingperiodwaived");
|
|
$data['coverfromthedateofjoining'] =$this->request->getPost("coverfromthedateofjoining");
|
|
$data['waiverof1,2,3&4thyearexclusions'] =$this->request->getPost("waiverof1,2,3&4thyearexclusions");
|
|
$data['waiverof30dayswaitingperiod'] =$this->request->getPost("waiverof30dayswaitingperiod");
|
|
$data['prehospitalizationcover'] =$this->request->getPost("prehospitalizationcover");
|
|
// $data['posthospitalizationcover'] =$this->request->getPost("posthospitalizationcover");
|
|
$data['congenitaldiseasesinternal'] =$this->request->getPost("congenitaldiseasesinternal");
|
|
// $data['congenitaldiseasesexternal'] =$this->request->getPost("congenitaldiseasesexternal");
|
|
$data['copayzonewisecopay'] =$this->request->getPost("copayzonewisecopay");
|
|
$data['bioabsorbablestenttoriclensmultifocallens'] =$this->request->getPost("bioabsorbablestenttoriclensmultifocallens");
|
|
$data['roomrentlimit'] =$this->request->getPost("roomrentlimit");
|
|
$data['proportionatedeductionclause'] =$this->request->getPost("proportionatedeductionclause");
|
|
$data['nursingallowance'] =$this->request->getPost("nursingallowance");
|
|
$data['ailmentcapping'] =$this->request->getPost("ailmentcapping");
|
|
$data['ambulancecharges'] =$this->request->getPost("ambulancecharges");
|
|
$data['airambulance'] =$this->request->getPost("airambulance");
|
|
$data['familytransportationbenefit'] =$this->request->getPost("familytransportationbenefit");
|
|
$data['reasonableandcustomarycharges'] =$this->request->getPost("reasonableandcustomarycharges");
|
|
$data['ayudhtreatmentcover'] =$this->request->getPost("ayudhtreatmentcover");
|
|
$data['armdcovered'] =$this->request->getPost("armdcovered");
|
|
$data['suminsuredenhancement'] =$this->request->getPost("suminsuredenhancement");
|
|
$data['automaticsuminsuredreinstatement'] =$this->request->getPost("automaticsuminsuredreinstatement");
|
|
$data['additionalsicknessbenefit'] =$this->request->getPost("additionalsicknessbenefit");
|
|
$data['lasiksurgery'] =$this->request->getPost("lasiksurgery");
|
|
$data['midterminclusion'] =$this->request->getPost("midterminclusion");
|
|
$data['capd'] =$this->request->getPost("capd");
|
|
$data['organdonorexpenses'] =$this->request->getPost("organdonorexpenses");
|
|
$data['moderntreatmentsasperirdai'] =$this->request->getPost("moderntreatmentsasperirdai");
|
|
$data['Wellness'] =$this->request->getPost("Wellness");
|
|
$data['days_of_discharge'] =$this->request->getPost("days_of_discharge");
|
|
$data['days_from_dod'] =$this->request->getPost("days_from_dod");
|
|
$data['special_condition_label'] = $this->request->getPost("special_condition_label") ?? [];
|
|
$data['special_condition_input'] = $this->request->getPost("special_condition_input") ?? [];
|
|
|
|
|
|
$jsonData = json_encode($data);
|
|
$dataa = array(
|
|
'policy_terms' => $jsonData,
|
|
);
|
|
|
|
$record = $this->clientPolicyModel->where('id', $client_policy_id)->first();
|
|
|
|
if ($record) {
|
|
$update = $this->clientPolicyModel->update($client_policy_id, $dataa);
|
|
if ($update) {
|
|
return $this->respond(['status' => true,'code' => 200,'message' => 'Data updated successfully'], 200);
|
|
} else {
|
|
return $this->respond(['status' => false,'code' => 404, 'message' => 'Failed to update data'], 200);
|
|
}
|
|
}else{
|
|
$insert = $this->clientPolicyModel->insert($dataa);
|
|
if ($insert) {
|
|
return $this->respond(['status' => true,'code' => 200,'message' => 'Data stored successfully'], 200);
|
|
} else {
|
|
return $this->respond(['status' => false,'code' => 404, 'message' => 'Failed to store data'], 200);
|
|
}
|
|
}
|
|
} catch (\Exception $e) {
|
|
|
|
echo "Failed to insert data: " . $e->getMessage();
|
|
// Log the error
|
|
log_message('error', 'Failed to insert data: ' . $e->getMessage());
|
|
}
|
|
|
|
}
|
|
|
|
public function getterms()
|
|
{
|
|
$client_policy_id = $this->request->getVar('client_policy_id');
|
|
$record = $this->clientPolicyModel->where('id', $client_policy_id)->first();
|
|
$policy_name = $this->policesModel->select('name')->where('id', $record['policy_id'])->first();
|
|
|
|
$emp_count = $this->employeeModel ->join('client_policy cp',"employees.client_id = cp.client_id")
|
|
->join('employee_polices ep',"cp.id = ep.client_policy_id AND employees.id = ep.employee_id")
|
|
->where("employees.client_id", $record['client_id'])
|
|
->where("employees.emp_status",'active')
|
|
->countAllResults();
|
|
|
|
if($emp_count = 0){
|
|
$emp_count = true;
|
|
}else{
|
|
$emp_count = false;
|
|
}
|
|
|
|
if ($record) {
|
|
return $this->respond(['Status' => true,'code' => 200,'data' => $record['policy_terms'], 'count' => $emp_count, 'policy_name' => $policy_name], 200);
|
|
} else {
|
|
return $this->respond(['Status' => false,'code' => 200,'message' => 'Record not found.', 'count' => $emp_count, 'policy_name' => $policy_name], 200);
|
|
}
|
|
|
|
}
|
|
|
|
public function policyGPATerms()
|
|
{
|
|
try {
|
|
$this->myLogger->logme('error','Policy GPA Terms CREATE function called');
|
|
|
|
/*** Client Policy Table Primary Key(ID) ***/
|
|
$client_policy_id = $this->request->getPost("client_policy_id");
|
|
|
|
$data['sumInsured2'] =$this->request->getPost("sumInsured2");
|
|
$data['totalSumInsured'] =$this->request->getPost("totalSumInsured");
|
|
$data['accidentalDeathBenefit'] =$this->request->getPost("accidentalDeathBenefit");
|
|
$data['permanentTotalDisablement'] =$this->request->getPost("permanentTotalDisablement");
|
|
$data['permanentPartialDisablement'] =$this->request->getPost("permanentPartialDisablement");
|
|
$data['temporaryTotalDisablementBenefit'] =$this->request->getPost("temporaryTotalDisablementBenefit");
|
|
$data['accidentalHospitalizationExpenses'] =$this->request->getPost("accidentalHospitalizationExpenses");
|
|
$data['childrenEducationWelfareFund'] =$this->request->getPost("childrenEducationWelfareFund");
|
|
|
|
$data['compassionateVisitExpenses'] =$this->request->getPost("compassionateVisitExpenses");
|
|
if ($data['compassionateVisitExpenses'] == 1) {
|
|
$data['compassionateVisitExpensesData'] =$this->request->getPost("compassionateVisitExpensesData");
|
|
}else{
|
|
$data['compassionateVisitExpensesData'] ="";
|
|
}
|
|
|
|
$data['brokenBoneExpenses'] = $this->request->getPost("brokenBoneExpenses");
|
|
if ($data['brokenBoneExpenses'] == 1) {
|
|
$data['brokenBoneExpensesData'] = $this->request->getPost("brokenBoneExpensesData");
|
|
}else{
|
|
$data['brokenBoneExpensesData'] ="";
|
|
}
|
|
|
|
$data['ambulanceCharges'] =$this->request->getPost("ambulanceCharges");
|
|
if ($data['ambulanceCharges'] == 1) {
|
|
$data['ambulanceChargesData'] =$this->request->getPost("ambulanceChargesData");
|
|
}else{
|
|
$data['ambulanceChargesData'] ="";
|
|
}
|
|
|
|
$data['burnExpenses'] = $this->request->getPost("burnExpenses");
|
|
if ($data['burnExpenses'] == 1) {
|
|
$data['burnExpensesData'] = $this->request->getPost("burnExpensesData");
|
|
}else{
|
|
$data['burnExpensesData'] = "";
|
|
}
|
|
|
|
$data['carriageOfDeadBody'] = $this->request->getPost("carriageOfDeadBody");
|
|
if ($data['carriageOfDeadBody'] == 1) {
|
|
$data['carriageOfDeadBodyData'] = $this->request->getPost("carriageOfDeadBodyData");
|
|
}else{
|
|
$data['carriageOfDeadBodyData'] = "";
|
|
}
|
|
|
|
$data['animalSnakeInsectBite'] = $this->request->getPost("animalSnakeInsectBite");
|
|
$data['terrorism'] = $this->request->getPost("terrorism");
|
|
$data['worldwideCover'] = $this->request->getPost("worldwideCover");
|
|
|
|
$jsonData = json_encode($data);
|
|
$dataa = array(
|
|
'policy_terms' => $jsonData,
|
|
);
|
|
|
|
$record = $this->clientPolicyModel->where('id', $client_policy_id)->first();
|
|
if ($record) {
|
|
$update = $this->clientPolicyModel->update($client_policy_id, $dataa);
|
|
if ($update) {
|
|
return $this->respond(['status' => true, 'code' => 200, 'message' => 'Data updated successfully', 'client_policy_id' => $client_policy_id], 200);
|
|
} else {
|
|
return $this->respond(['status' => false,'code' => 404, 'message' => 'Failed to update data'], 200);
|
|
}
|
|
}else{
|
|
$insert = $this->clientPolicyModel->insert($dataa);
|
|
if ($insert) {
|
|
return $this->respond(['status' => true,'code' => 200,'message' => 'Data stored successfully', 'client_policy_id' => $client_policy_id], 200);
|
|
} else {
|
|
return $this->respond(['status' => false,'code' => 404, 'message' => 'Failed to store data'], 200);
|
|
}
|
|
}
|
|
} catch (\Exception $e) {
|
|
|
|
echo "Failed to insert data: " . $e->getMessage();
|
|
log_message('error', 'Failed to insert data: ' . $e->getMessage());
|
|
}
|
|
|
|
}
|
|
|
|
public function getPolicyGPATerms(){
|
|
|
|
$client_id = $this->request->getVar('client_id');
|
|
$policy_id = $this->request->getVar('policy_id');
|
|
$record = $this->clientPolicyModel->where(['client_id' => $client_id, 'policy_id' => $policy_id])->first();
|
|
|
|
if ($record) {
|
|
echo $record['policy_terms'];
|
|
|
|
} else {
|
|
echo "Record not found.";
|
|
}
|
|
|
|
}
|
|
|
|
public function updateClientPolicyStatus(){
|
|
|
|
$client_policy_id = $this->request->getGet('client_policy_id');
|
|
$record = $this->clientPolicyModel->where('id', $client_policy_id)->first();
|
|
|
|
|
|
$data = $this->policesModel->getPolicyPremium($record['policy_id']);
|
|
$pattern = '/gmc/i';
|
|
$subject = $data[0]->policy_type;
|
|
if (preg_match($pattern, $subject)) {
|
|
$search_term = 'GMC';
|
|
} else {
|
|
$search_term = 'GPA';
|
|
}
|
|
|
|
if($search_term === 'GPA'){
|
|
$racRate = $this->policyPremium1Model->where(['client_id' => $record['client_id'], 'client_policy_id' => $client_policy_id, 'is_active' => 1])->countAllResults();
|
|
}else if($search_term === 'GMC'){
|
|
$racRate = $this->policyPremium2Model->where(['client_id' => $record['client_id'], 'client_policy_id' => $client_policy_id, 'is_active' => 1])->countAllResults();
|
|
}
|
|
|
|
$termsData = $this->clientPolicyModel->where(['id' => $client_policy_id, 'is_active' => 1])->first();
|
|
if(empty($termsData['policy_terms'])){
|
|
return $this->respond(['status' => false,'code' => 200,'message' => 'This Policy does not Create Terms'], 200);
|
|
}
|
|
|
|
|
|
$termsData = json_decode($termsData['policy_terms']);
|
|
|
|
if (isset($termsData->sum_insured) && empty($termsData->sum_insured)) {
|
|
return $this->respond(['status' => false,'code' => 200,'message' => 'The Policy terms Sum Insured field is empty', 'data' => $record], 200);
|
|
}
|
|
|
|
if (isset($termsData->SumInsured) && empty($termsData->sum_insured)) {
|
|
return $this->respond(['status' => false,'code' => 200,'message' => 'The Policy terms Sum Insured field is empty'], 200);
|
|
}
|
|
|
|
// Check if 'family_floater' key exists and has a value
|
|
if (isset($termsData->family_floater) && empty($termsData->family_floater)) {
|
|
return $this->respond(['status' => false,'code' => 200,'message' => 'The Policy terms Family Floater field is empty'], 200);
|
|
}
|
|
|
|
// Check if 'family_floaters' key exists and has a value
|
|
if (isset($termsData->family_floaters) && is_array($termsData->family_floaters) && count($termsData->family_floaters) <= 0) {
|
|
return $this->respond(['status' => false,'code' => 200,'message' => 'The Policy terms Family Members field is empty'], 200);
|
|
$familyFloatersCount = count($termsData->family_floaters);
|
|
}
|
|
|
|
if($racRate == 0){
|
|
|
|
return $this->respond(['status' => false,'code' => 200,'message' => 'The Policy has no Data for Rac Rate'], 200);
|
|
}
|
|
|
|
$policy_status = $this->clientPolicyModel->where('id', $client_policy_id )->set('policy_status', 1)->update();
|
|
return $this->respond(['status' => true,'code' => 200, 'message' => 'Policy Status Updated Successfully', 'data' => $termsData, 'racRate' => $racRate], 200);
|
|
|
|
|
|
|
|
}
|
|
|
|
} |