1208 lines
57 KiB
PHP
1208 lines
57 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()
|
|
{
|
|
|
|
$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 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()
|
|
{
|
|
try {
|
|
$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');
|
|
$si_or_bp = $this->request->getPost('si_or_bp');
|
|
$basic_multiplier = str_replace(',', '', $this->request->getPost('basic_multiplier'));
|
|
$premium_multiplier = str_replace(',', '', $this->request->getPost('premium_multiplier'));
|
|
$multiplier = str_replace(',', '', $this->request->getPost('multiplier'));
|
|
$basic_pay = str_replace(',', '', $this->request->getPost('basic_pay'));
|
|
|
|
$data=[];
|
|
$data['client_id'] = $client_id;
|
|
$data['client_policy_id'] = $client_policy_id;
|
|
$data['policy_grid_id'] = $policy_grid_id;
|
|
|
|
|
|
$premium = [];
|
|
|
|
if ($policy_grid_id == '1' || $policy_grid_id == '2') {
|
|
$this->policyPremium1Model->where('client_id', $client_id)->where('client_policy_id', $client_policy_id)->set('is_active', 0)->update();
|
|
} else {
|
|
$this->policyPremium2Model->where('client_id', $client_id)->where('client_policy_id', $client_policy_id)->set('is_active', 0)->update();
|
|
}
|
|
|
|
|
|
if($policy_grid_id == '1'){
|
|
if ($si_or_bp == '1') {
|
|
$premium=str_replace(',', '', $this->request->getPost('gpa_sum_premium[]'));
|
|
$sum_insure=str_replace(',', '', $this->request->getPost('gpa_sum_si[]'));
|
|
$multiplier=$this->request->getPost('gpa_sum_multiplier');
|
|
for ($i=0; $i < count($premium) ; $i++) {
|
|
$data['si'] = $sum_insure[$i];
|
|
$data['premium'] = $premium[$i];
|
|
$data['multiplier'] = $multiplier;
|
|
$data['si_or_bp'] = $this->request->getPost('si_or_bp');
|
|
|
|
$policyPremium= $this->policyPremium1Model->insert($data);
|
|
}
|
|
} else {
|
|
$data['premium'] = str_replace(',', '', $this->request->getPost('gpa_basic_premium'));
|
|
$data['si'] = str_replace(',', '', $this->request->getPost('gpa_basic_si'));
|
|
$data['basic_multiplier'] = str_replace(',', '', $this->request->getPost('basic_multiplier'));
|
|
$data['multiplier'] = $this->request->getPost('premium_multiplier');
|
|
$data['basic_pay'] = str_replace(',', '', $this->request->getPost('basic_pay'));
|
|
$data['si_or_bp'] = $this->request->getPost('si_or_bp');
|
|
|
|
$policyPremium= $this->policyPremium1Model->insert($data);
|
|
}
|
|
$data = $this->request->getPost();
|
|
$insert = true;
|
|
}else if($policy_grid_id == '2'){
|
|
$data['premium'] = str_replace(',', '', $this->request->getPost('gpa_premium'));
|
|
$data['si'] = str_replace(',', '', $this->request->getPost('gpa_si'));
|
|
|
|
$policyPremium= $this->policyPremium1Model->insert($data);
|
|
|
|
$data = $this->request->getPost();
|
|
$insert = true;
|
|
}else if($policy_grid_id == '3'){
|
|
$premium=$this->request->getPost('3_premium[]');
|
|
$sum_insure =$this->request->getPost('3_si[]');
|
|
for ($i=0; $i < count($premium) ; $i++) {
|
|
$data['premium'] = str_replace(',', '',$premium[$i]);
|
|
$data['si'] = str_replace(',', '', $sum_insure[$i]);
|
|
$dataa= $this->policyPremium2Model->insert($data);
|
|
}
|
|
$data = $this->request->getPost();
|
|
$insert = true;
|
|
}else if($policy_grid_id == '4'){
|
|
$premium=$this->request->getPost('4_premium[]');
|
|
$sum_insure =$this->request->getPost('4_si');
|
|
$age_from =$this->request->getPost('4_age_from[]');
|
|
$age_to =$this->request->getPost('4_age_to[]');
|
|
for ($i=0; $i < count($premium) ; $i++) {
|
|
$data['premium'] = str_replace(',', '',$premium[$i]);
|
|
$data['si'] = str_replace(',', '', $sum_insure);
|
|
$data['age_from'] = $age_from[$i];
|
|
$data['age_to'] = $age_to[$i];
|
|
$dataa= $this->policyPremium2Model->insert($data);
|
|
}
|
|
$data = $this->request->getPost();
|
|
$insert = true;
|
|
}else if($policy_grid_id == '5'){
|
|
$premium=$this->request->getPost('5_premium[]');
|
|
$sum_insure =$this->request->getPost('5_si[]');
|
|
$age_from =$this->request->getPost('5_age_from[]');
|
|
$age_to =$this->request->getPost('5_age_to[]');
|
|
for ($i=0; $i < count($premium) ; $i++) {
|
|
$data['premium'] = str_replace(',', '',$premium[$i]);
|
|
$data['si'] = str_replace(',', '', $sum_insure[$i]);
|
|
$data['age_from'] = $age_from[$i];
|
|
$data['age_to'] = $age_to[$i];
|
|
$dataa= $this->policyPremium2Model->insert($data);
|
|
}
|
|
$data = $this->request->getPost();
|
|
$insert = true;
|
|
}else if($policy_grid_id == '6'){
|
|
$premium=$this->request->getPost('6_premium[]');
|
|
$sum_insure =$this->request->getPost('6_si[]');
|
|
$age_from =$this->request->getPost('6_age_from[]');
|
|
$age_to =$this->request->getPost('6_age_to[]');
|
|
for ($i=0; $i < count($premium) ; $i++) {
|
|
$data['premium'] = str_replace(',', '',$premium[$i]);
|
|
$data['si'] = str_replace(',', '', $sum_insure[$i]);
|
|
$data['age_from'] = $age_from[$i];
|
|
$data['age_to'] = $age_to[$i];
|
|
$dataa= $this->policyPremium2Model->insert($data);
|
|
}
|
|
$data = $this->request->getPost();
|
|
$insert = true;
|
|
}else if($policy_grid_id == '7'){
|
|
$premium=$this->request->getPost('7_premium[]');
|
|
$sum_insure =$this->request->getPost('7_si[]');
|
|
$age_from =$this->request->getPost('7_age_from[]');
|
|
$age_to =$this->request->getPost('7_age_to[]');
|
|
for ($i=0; $i < count($premium) ; $i++) {
|
|
$data['premium'] = str_replace(',', '',$premium[$i]);
|
|
$data['si'] = str_replace(',', '', $sum_insure[$i]);
|
|
$data['age_from'] = $age_from[$i];
|
|
$data['age_to'] = $age_to[$i];
|
|
$dataa= $this->policyPremium2Model->insert($data);
|
|
}
|
|
$data = $this->request->getPost();
|
|
$insert = true;
|
|
}else if($policy_grid_id == '8'){
|
|
$premium=$this->request->getPost('8_premium[]');
|
|
$sum_insure =$this->request->getPost('8_si[]');
|
|
$grade =$this->request->getPost('8_grade[]');
|
|
for ($i=0; $i < count($premium) ; $i++) {
|
|
$data['premium'] = str_replace(',', '',$premium[$i]);
|
|
$data['si'] = str_replace(',', '', $sum_insure[$i]);
|
|
$data['grade'] = $grade[$i];
|
|
$dataa= $this->policyPremium2Model->insert($data);
|
|
}
|
|
$data = $this->request->getPost();
|
|
$insert = true;
|
|
}else if($policy_grid_id == '9'){
|
|
$premium=$this->request->getPost('9_premium[]');
|
|
$sum_insure =$this->request->getPost('9_si[]');
|
|
$grade =$this->request->getPost('9_grade[]');
|
|
for ($i=0; $i < count($premium) ; $i++) {
|
|
$data['premium'] = str_replace(',', '',$premium[$i]);
|
|
$data['si'] = str_replace(',', '', $sum_insure[$i]);
|
|
$data['grade'] = $grade[$i];
|
|
$dataa= $this->policyPremium2Model->insert($data);
|
|
}
|
|
$data = $this->request->getPost();
|
|
$insert = true;
|
|
}else if($policy_grid_id == '10'){
|
|
$premium=$this->request->getPost('10_premium[]');
|
|
$sum_insure =$this->request->getPost('10_si[]');
|
|
$age_from =$this->request->getPost('10_age_from[]');
|
|
$age_to =$this->request->getPost('10_age_to[]');
|
|
for ($i=0; $i < count($premium) ; $i++) {
|
|
$data['premium'] = str_replace(',', '',$premium[$i]);
|
|
$data['si'] = str_replace(',', '', $sum_insure[$i]);
|
|
$data['age_from'] = $age_from[$i];
|
|
$data['age_to'] = $age_to[$i];
|
|
$policyPremium= $this->policyPremium2Model->insert($data);
|
|
}
|
|
$data = $this->request->getPost();
|
|
$insert = true;
|
|
}else if($policy_grid_id == '11'){
|
|
$premium=$this->request->getPost('11_premium[]');
|
|
$sum_insure =$this->request->getPost('11_si[]');
|
|
$grade =$this->request->getPost('11_grade[]');
|
|
$max_sum_insure =$this->request->getPost('11_max_si[]');
|
|
for ($i=0; $i < count($premium) ; $i++) {
|
|
$data['premium'] = str_replace(',', '',$premium[$i]);
|
|
$data['si'] = str_replace(',', '', $sum_insure[$i]);
|
|
$data['grade'] = $grade[$i];
|
|
$data['max_si'] = $max_sum_insure[$i];
|
|
$dataa= $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);
|
|
}
|
|
} catch (Exception $e) {
|
|
// Handle exceptions here
|
|
echo 'Error: ' . $e->getMessage();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
$family_floater ='';
|
|
if (isset(json_decode($record['policy_terms'])->family_floater)) {
|
|
$family_floater=json_decode($record['policy_terms'])->family_floater;
|
|
}
|
|
|
|
$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 $record['client_id'];
|
|
// echo "-----";
|
|
// echo $client_policy_id;
|
|
// print_r($premiumData);die;
|
|
// echo '<pre>';
|
|
// echo $family_floater;
|
|
$resultss = [];
|
|
if ($family_floater == 1) {
|
|
|
|
foreach ($results as $index => $record) {
|
|
if ($index == '8' || $index == '7') {
|
|
// Clearing the $results array
|
|
$resultss[$index] = $record;
|
|
}
|
|
}
|
|
}else if($family_floater == 0){
|
|
foreach ($results as $index => $record) {
|
|
if ($index == '0' || $index == '1' || $index == '2' || $index == '3' || $index == '4' || $index == '5' || $index == '6') {
|
|
// Clearing the $results array
|
|
$resultss[$index] = $record;
|
|
}
|
|
}
|
|
}else{
|
|
foreach ($results as $index => $record) {
|
|
$resultss[$index] = $record;
|
|
}
|
|
}
|
|
$premiumDataa ='';
|
|
if ($family_floater == 0) {
|
|
// print_r($premiumData);die;
|
|
if (count($premiumData) == 0) {
|
|
$premiumDataa = $premiumData;
|
|
}else if ($premiumData[0]['policy_grid_id'] == '3' || $premiumData[0]['policy_grid_id'] == '4' || $premiumData[0]['policy_grid_id'] == '5' || $premiumData[0]['policy_grid_id'] == '6' || $premiumData[0]['policy_grid_id'] == '7' || $premiumData[0]['policy_grid_id'] == '8' || $premiumData[0]['policy_grid_id'] == '9' ) {
|
|
$premiumDataa = $premiumData;
|
|
}
|
|
}
|
|
else if($family_floater == 1){
|
|
if(count($premiumData) == 0){
|
|
$premiumDataa = $premiumData;
|
|
}else if ($premiumData[0]['policy_grid_id'] == '10' || $premiumData[0]['policy_grid_id'] == '11') {
|
|
$premiumDataa = $premiumData;
|
|
}
|
|
}else{
|
|
$premiumDataa = $premiumData;
|
|
}
|
|
|
|
// print_r($premiumData);die;
|
|
|
|
// print_r($data[0]->policy_type); die;
|
|
// echo "hello";
|
|
// return json_encode($premiumData);
|
|
return $this->respond(['status' => true,'code' => 200,'data' => $resultss, 'premiumData' => json_encode($premiumDataa), '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'] =str_replace(',', '',$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") ?? [];
|
|
|
|
if (!in_array("self", $data['family_floaters'])) {
|
|
array_unshift($data['family_floaters'], "self");
|
|
}
|
|
$data['waiverofpreexistingdiseases'] =$this->request->getPost("waiverofpreexistingdiseases");
|
|
if ($data['waiverofpreexistingdiseases'] == 1) {
|
|
$data['maternitycoverage'] =str_replace(',', '',$this->request->getPost("maternitycoverage"));
|
|
$data['twindelivery'] =str_replace(',', '',$this->request->getPost("twindelivery"));
|
|
$data['preandpostnatal'] =str_replace(',', '',$this->request->getPost("preandpostnatal"));
|
|
$data['babyday1cover'] =str_replace(',', '',$this->request->getPost("babyday1cover"));
|
|
}else{
|
|
$data['maternitycoverage'] ="";
|
|
$data['twindelivery'] ="";
|
|
$data['preandpostnatal'] ="";
|
|
$data['babyday1cover'] ="";
|
|
}
|
|
$data['9monthwaitingperiodwaived'] =str_replace(',', '',$this->request->getPost("9monthwaitingperiodwaived"));
|
|
$data['coverfromthedateofjoining'] =str_replace(',', '',$this->request->getPost("coverfromthedateofjoining"));
|
|
$data['waiverof1,2,3&4thyearexclusions'] =$this->request->getPost("waiverof1,2,3&4thyearexclusions");
|
|
$data['waiverof30dayswaitingperiod'] =$this->request->getPost("waiverof30dayswaitingperiod");
|
|
$data['prehospitalizationcover'] =str_replace(',', '',$this->request->getPost("prehospitalizationcover"));
|
|
// $data['posthospitalizationcover'] =$this->request->getPost("posthospitalizationcover");
|
|
$data['congenitaldiseasesinternal'] =str_replace(',', '',$this->request->getPost("congenitaldiseasesinternal"));
|
|
// $data['congenitaldiseasesexternal'] =$this->request->getPost("congenitaldiseasesexternal");
|
|
$data['copayzonewisecopay'] =$this->request->getPost("copayzonewisecopay");
|
|
$data['bioabsorbablestenttoriclensmultifocallens'] =$this->request->getPost("bioabsorbablestenttoriclensmultifocallens");
|
|
$data['roomrentlimit'] =str_replace(',', '',$this->request->getPost("roomrentlimit"));
|
|
$data['proportionatedeductionclause'] =str_replace(',', '',$this->request->getPost("proportionatedeductionclause"));
|
|
$data['nursingallowance'] =str_replace(',', '',$this->request->getPost("nursingallowance"));
|
|
$data['ailmentcapping'] =str_replace(',', '',$this->request->getPost("ailmentcapping"));
|
|
$data['ambulancecharges'] =str_replace(',', '',$this->request->getPost("ambulancecharges"));
|
|
$data['airambulance'] =str_replace(',', '',$this->request->getPost("airambulance"));
|
|
$data['familytransportationbenefit'] =str_replace(',', '',$this->request->getPost("familytransportationbenefit"));
|
|
$data['reasonableandcustomarycharges'] =str_replace(',', '',$this->request->getPost("reasonableandcustomarycharges"));
|
|
$data['ayudhtreatmentcover'] =str_replace(',', '',$this->request->getPost("ayudhtreatmentcover"));
|
|
$data['armdcovered'] =str_replace(',', '',$this->request->getPost("armdcovered"));
|
|
$data['suminsuredenhancement'] =str_replace(',', '',$this->request->getPost("suminsuredenhancement"));
|
|
$data['automaticsuminsuredreinstatement'] =str_replace(',', '',$this->request->getPost("automaticsuminsuredreinstatement"));
|
|
$data['additionalsicknessbenefit'] =str_replace(',', '',$this->request->getPost("additionalsicknessbenefit"));
|
|
$data['lasiksurgery'] =str_replace(',', '',$this->request->getPost("lasiksurgery"));
|
|
$data['midterminclusion'] =str_replace(',', '',$this->request->getPost("midterminclusion"));
|
|
$data['capd'] =str_replace(',', '',$this->request->getPost("capd"));
|
|
$data['organdonorexpenses'] =str_replace(',', '',$this->request->getPost("organdonorexpenses"));
|
|
$data['moderntreatmentsasperirdai'] =str_replace(',', '',$this->request->getPost("moderntreatmentsasperirdai"));
|
|
$data['Wellness'] =str_replace(',', '',$this->request->getPost("Wellness"));
|
|
$data['days_of_discharge'] =str_replace(',', '',$this->request->getPost("days_of_discharge"));
|
|
$data['days_from_dod'] =str_replace(',', '',$this->request->getPost("days_from_dod"));
|
|
$data['special_condition_label'] = str_replace(',', '',$this->request->getPost("special_condition_label")) ?? [];
|
|
$data['special_condition_input'] = str_replace(',', '',$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'] =str_replace(',', '', $this->request->getPost("sumInsured2"));
|
|
$data['totalSumInsured'] =str_replace(',', '',$this->request->getPost("totalSumInsured"));
|
|
$data['accidentalDeathBenefit'] =str_replace(',', '',$this->request->getPost("accidentalDeathBenefit"));
|
|
$data['permanentTotalDisablement'] =str_replace(',', '',$this->request->getPost("permanentTotalDisablement"));
|
|
$data['permanentPartialDisablement'] =$this->request->getPost("permanentPartialDisablement");
|
|
$data['temporaryTotalDisablementBenefit'] =$this->request->getPost("temporaryTotalDisablementBenefit");
|
|
$data['accidentalHospitalizationExpenses'] =str_replace(',', '',$this->request->getPost("accidentalHospitalizationExpenses"));
|
|
$data['childrenEducationWelfareFund'] =str_replace(',', '',$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'] = str_replace(',', '',$this->request->getPost("brokenBoneExpenses"));
|
|
if ($data['brokenBoneExpenses'] == 1) {
|
|
$data['brokenBoneExpensesData'] = str_replace(',', '',$this->request->getPost("brokenBoneExpensesData"));
|
|
}else{
|
|
$data['brokenBoneExpensesData'] ="";
|
|
}
|
|
|
|
$data['ambulanceCharges'] =str_replace(',', '',$this->request->getPost("ambulanceCharges"));
|
|
if ($data['ambulanceCharges'] == 1) {
|
|
$data['ambulanceChargesData'] =str_replace(',', '',$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);
|
|
|
|
|
|
|
|
}
|
|
|
|
} |