490 lines
19 KiB
PHP
490 lines
19 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
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\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;
|
|
|
|
|
|
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;
|
|
|
|
|
|
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->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();
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$this->myLogger->logme('error','Client list function called');
|
|
$headerData['page_name'] = 'Client List';
|
|
$data['clientList'] = $this->clientModel->findAll();
|
|
echo view('layout/header', $headerData);
|
|
echo view('client_list', $data);
|
|
echo view('layout/footer');
|
|
}
|
|
|
|
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();
|
|
|
|
// echo "<pre>";
|
|
// print_r($data); die;
|
|
|
|
echo view('layout/header', $headerData);
|
|
echo view('client_onboarding', $data);
|
|
echo view('layout/footer');
|
|
}
|
|
|
|
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['client'] = $this->clientModel->where(['id' => $id, 'is_active' => 1])->first();
|
|
$editData['client_kyc'] = $this->clientKYCDocsModel->getKycDocsName($id);
|
|
$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();
|
|
echo json_encode(array("status" => true , 'data' => $client_data));
|
|
}else{
|
|
echo json_encode(array("status" => false));
|
|
}
|
|
}
|
|
|
|
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){
|
|
echo json_encode(array("status" => true , 'data' => $data));
|
|
}else{
|
|
echo json_encode(array("status" => false));
|
|
}
|
|
}
|
|
|
|
public function createClientKYCInfo()
|
|
{
|
|
$this->myLogger->logme('error','create Client kyc function called');
|
|
$File = file_Upload($this->request->getFile('file_name'));
|
|
if(!empty($File)){
|
|
$data['file_name'] = $File;
|
|
}
|
|
|
|
$data['client_id'] = $this->request->getPost('client_id');
|
|
$data['kyc_doc_type_id'] = $this->request->getPost('kyc_doc_id');
|
|
$data['created_by'] = get_session_userid();
|
|
$insert = $this->clientKYCDocsModel->insert($data);
|
|
if($insert){
|
|
$kycDocs = $this->clientKYCDocsModel->getKycDocsName($this->request->getPost('client_id'));
|
|
echo json_encode(array("status" => true , 'data' => $kycDocs));
|
|
}else{
|
|
echo json_encode(array("status" => false));
|
|
}
|
|
}
|
|
|
|
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);
|
|
echo json_encode(array("status" => true , 'data' => $kycDocs));
|
|
}else{
|
|
echo json_encode(array());
|
|
}
|
|
}
|
|
|
|
public function deleteClientKycDocs($id=null)
|
|
{
|
|
|
|
$delete = $this->clientKYCDocsModel->where('id', $id)->delete();
|
|
if($delete){
|
|
echo json_encode(array("status" => true ));
|
|
}else{
|
|
echo json_encode(array("status" => false));
|
|
}
|
|
}
|
|
|
|
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) {
|
|
echo json_encode(array("status" => true, 'data' => $this->request->getPost()));
|
|
} else {
|
|
echo json_encode(array("status" => false));
|
|
}
|
|
}
|
|
|
|
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) {
|
|
echo json_encode(array("status" => true, 'data' => $this->request->getPost(), "place" => 'edit'));
|
|
} else {
|
|
echo json_encode(array("status" => false, "place" => 'edit'));
|
|
}
|
|
}
|
|
|
|
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();
|
|
echo json_encode(array("status" => true , 'data' => $branchData));
|
|
}else{
|
|
echo json_encode(array("status" => false));
|
|
}
|
|
}
|
|
|
|
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();
|
|
echo json_encode(array("status" => true , 'data' => $branchData));
|
|
}else{
|
|
echo json_encode(array("status" => false));
|
|
}
|
|
}
|
|
|
|
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['client_id'] = $this->request->getPost('client_id');
|
|
|
|
|
|
$data['created_by'] = get_session_userid();
|
|
$insert = $this->clientPolicyModel->insert($data);
|
|
if($insert){
|
|
$clientPoliceData = $this->clientPolicyModel->getClientPolicyByClientId($this->request->getPost('client_id'));
|
|
echo json_encode(array("status" => true , 'data' => $clientPoliceData));
|
|
}else{
|
|
echo json_encode(array("status" => false));
|
|
}
|
|
}
|
|
|
|
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['updated_by'] = get_session_userid();
|
|
$insert = $this->clientPolicyModel->update($id,$data);
|
|
$lastQuery = $this->clientPolicyModel->getLastQuery();
|
|
|
|
if($insert){
|
|
$clientPoliceData = $this->clientPolicyModel->getClientPolicyByClientId($client_id);
|
|
echo json_encode(array("status" => true , 'data' => $clientPoliceData));
|
|
}else{
|
|
echo json_encode(array("status" => false));
|
|
}
|
|
}
|
|
|
|
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();
|
|
echo json_encode(array("status" => true , 'data' => $kyc_docs_data));
|
|
$this->myLogger->logme('error','getKycDocs status TRUE');
|
|
}else{
|
|
echo json_encode(array("status" => false));
|
|
$this->myLogger->logme('error','getKycDocs status FALSE');
|
|
}
|
|
}
|
|
|
|
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();
|
|
echo json_encode(array("status" => true , 'data' => $police_data));
|
|
}else{
|
|
echo json_encode(array("status" => false));
|
|
}
|
|
}
|
|
|
|
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();
|
|
echo json_encode(array("status" => true , 'data' => $branch_data, 'contact' => $branch_contact_data));
|
|
}else{
|
|
echo json_encode(array("status" => false));
|
|
}
|
|
|
|
}
|
|
|
|
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();
|
|
echo json_encode(array("status" => true , 'data' => $client_policy_data, 'policy' => $polices));
|
|
}else{
|
|
echo json_encode(array("status" => false));
|
|
}
|
|
|
|
}
|
|
|
|
} |