CHANGE_CLIENT_FROM_LEADS : RV
This commit is contained in:
parent
c40068619e
commit
3f0003224f
@ -602,8 +602,8 @@ class LeadsController extends BaseController
|
||||
return $this->respond(['status' => false, 'message' => 'File could not be removed.'], 200);
|
||||
}
|
||||
}
|
||||
//--------RFQ-----------------------------------------------------------------------------------------------
|
||||
|
||||
//--------RFQ-----------------------------------------------------------------------------------------------
|
||||
|
||||
public function viewRFQ($id, $type = 1)
|
||||
{
|
||||
@ -2538,64 +2538,103 @@ class LeadsController extends BaseController
|
||||
|
||||
public function featchLeadDataAndInsertClient($lead_id)
|
||||
{
|
||||
$data = $this->leadsModel->where('leads.id', $lead_id)->where('leads.is_active', 1)->first();
|
||||
try {
|
||||
$data = $this->leadsModel->where('leads.id', $lead_id)->where('leads.is_active', 1)->first();
|
||||
|
||||
if (!$data) {
|
||||
return $this->respond(['status' => false, 'message' => 'Failed to create Client', 'data' => null], 200);
|
||||
if (!$data) {
|
||||
$this->myLogger->logme('featchLeadDataAndInsertClient', "Lead not found or inactive", ['lead_id' => $lead_id]);
|
||||
return $this->respond(['status' => false, 'message' => 'Failed to create Client', 'data' => null], 200);
|
||||
}
|
||||
|
||||
$result = $this->createClientWithLeadData($data);
|
||||
|
||||
if ($result) {
|
||||
$policy_data = $this->clientPolicyModel->where('client_id', $result)->where('is_active', 1)->first();
|
||||
return $this->respond([
|
||||
'status' => true,
|
||||
'message' => 'New Client created successfully',
|
||||
'client_id' => $result,
|
||||
'data' => $data,
|
||||
'client_policy_id' => $policy_data['id'] ?? null,
|
||||
], 200);
|
||||
}
|
||||
|
||||
$this->myLogger->logme('featchLeadDataAndInsertClient', "Client creation failed after processing", ['lead_id' => $lead_id]);
|
||||
return $this->respond(['status' => false, 'message' => 'Failed to create client', 'data' => $data], 200);
|
||||
} catch (\Throwable $e) {
|
||||
$this->myLogger->logme('featchLeadDataAndInsertClient', $e->getMessage(), ['lead_id' => $lead_id, 'trace' => $e->getTraceAsString()]);
|
||||
return $this->respond(['status' => false, 'message' => 'Internal server error', 'error' => $e->getMessage()], 500);
|
||||
}
|
||||
|
||||
$result = $this->createClientWithLeadData($data);
|
||||
|
||||
if ($result) {
|
||||
|
||||
$policy_data = $this->clientPolicyModel->where('client_id', $result)->where('is_active', 1)->first();
|
||||
return $this->respond(['status' => true, 'message' => 'New Client created successfully', 'client_id' => $result, 'data' => $data, 'client_policy_id' => $policy_data['id']], 200);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => false, 'message' => 'Failed to create client', 'data' => $data], 200);
|
||||
}
|
||||
|
||||
public function createClientWithLeadData($data)
|
||||
{
|
||||
$client_data = $this->prepareClientData($data);
|
||||
$client_id = $this->clientModel->insert($client_data);
|
||||
try {
|
||||
$client_data = $this->prepareClientData($data);
|
||||
$client_id = $this->clientModel->insert($client_data);
|
||||
|
||||
if ($client_id) {
|
||||
$this->createClientBranchAndContactWithLeadData($data, $client_id);
|
||||
$this->leadsModel->where('id', $data['id'])->set('is_client_created', $client_id)->update();
|
||||
if ($client_id) {
|
||||
$this->createClientBranchAndContactWithLeadData($data, $client_id);
|
||||
$this->leadsModel->where('id', $data['id'])->set('is_client_created', $client_id)->update();
|
||||
}
|
||||
|
||||
return $client_id;
|
||||
} catch (\Throwable $e) {
|
||||
$this->myLogger->logme('createClientWithLeadData', $e->getMessage(), ['lead_id' => $data['id'], 'trace' => $e->getTraceAsString()]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $client_id;
|
||||
public function createClientBranchAndContactWithLeadData($data, $client_id)
|
||||
{
|
||||
try {
|
||||
$branch_data = $this->prepareClientBranchData($data, $client_id);
|
||||
$branch_id = $this->clientBranchModel->insert($branch_data);
|
||||
|
||||
if ($branch_id) {
|
||||
$this->leadsModel->where('id', $data['id'])->set('is_client_created', $client_id)->update();
|
||||
$contact_data = $this->prepareContactData($data, $branch_id);
|
||||
$this->levelContactModel->insert($contact_data);
|
||||
$this->createClientPolicyWithLeadData($data, $client_id, $branch_id);
|
||||
}
|
||||
|
||||
return $branch_id;
|
||||
} catch (\Throwable $e) {
|
||||
$this->myLogger->logme('createClientBranchAndContactWithLeadData', $e->getMessage(), ['lead_id' => $data['id'], 'trace' => $e->getTraceAsString()]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function createClientPolicyWithLeadData($data, $client_id, $branch_id)
|
||||
{
|
||||
try {
|
||||
$client_policy_data = $this->prepareClientPolicyData($data, $client_id, $branch_id);
|
||||
$client_policy_id = $this->clientPolicyModel->insert($client_policy_data);
|
||||
|
||||
if ($client_policy_id) {
|
||||
$this->leadsModel->where('id', $data['id'])->set('is_client_created', $client_id)->update();
|
||||
$this->leadsModel->where('id', $data['id'])->set('is_policy_created', $client_id)->update();
|
||||
}
|
||||
|
||||
return $client_policy_id;
|
||||
} catch (\Throwable $e) {
|
||||
$this->myLogger->logme('createClientPolicyWithLeadData', $e->getMessage(), ['lead_id' => $data['id'], 'trace' => $e->getTraceAsString()]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function prepareClientData($data)
|
||||
{
|
||||
return [
|
||||
'client_type' => $data['client_type'],
|
||||
'entity_type_id' => $data['entity_type_id'],
|
||||
'client_code' => $data['client_code'],
|
||||
'client_name' => $data['client_name'],
|
||||
'short_name' => $data['client_short_name'],
|
||||
'pan' => $data['pan'],
|
||||
'client_type' => $data['client_type'] ?? null,
|
||||
'entity_type_id' => $data['entity_type_id'] ?? null,
|
||||
'client_code' => $data['client_code'] ?? null,
|
||||
'client_name' => $data['client_name'] ?? null,
|
||||
'short_name' => $data['client_short_name'] ?? null,
|
||||
'pan' => $data['pan'] ?? null,
|
||||
];
|
||||
}
|
||||
|
||||
public function createClientBranchAndContactWithLeadData($data, $client_id)
|
||||
{
|
||||
$branch_data = $this->prepareClientBranchData($data, $client_id);
|
||||
$branch_id = $this->clientBranchModel->insert($branch_data);
|
||||
|
||||
if ($branch_id) {
|
||||
$this->leadsModel->where('id', $data['id'])->set('is_client_created', $client_id)->update();
|
||||
$contact_data = $this->prepareContactData($data, $branch_id);
|
||||
$this->levelContactModel->insert($contact_data);
|
||||
|
||||
$this->createClientPolicyWithLeadData($data, $client_id, $branch_id);
|
||||
}
|
||||
|
||||
return $branch_id;
|
||||
}
|
||||
|
||||
private function prepareClientBranchData($data, $client_id)
|
||||
{
|
||||
$default_unit = trim(($data['client_short_name'] ?? '') . '-' . ($data['branch_code'] ?? ''), '-');
|
||||
@ -2620,19 +2659,6 @@ class LeadsController extends BaseController
|
||||
];
|
||||
}
|
||||
|
||||
public function createClientPolicyWithLeadData($data, $client_id, $branch_id)
|
||||
{
|
||||
$client_policy_data = $this->prepareClientPolicyData($data, $client_id, $branch_id);
|
||||
$client_policy_id = $this->clientPolicyModel->insert($client_policy_data);
|
||||
|
||||
|
||||
if ($client_policy_id) {
|
||||
$this->leadsModel->where('id', $data['id'])->set('is_client_created', $client_id)->update();
|
||||
}
|
||||
|
||||
return $client_policy_id;
|
||||
}
|
||||
|
||||
private function prepareClientPolicyData($data, $client_id, $branch_id)
|
||||
{
|
||||
$proposel_data = json_decode($data['proposel_data'], true);
|
||||
@ -2682,17 +2708,46 @@ class LeadsController extends BaseController
|
||||
|
||||
private function preparePolicyTermsFromRFQ($data)
|
||||
{
|
||||
$proposel_data = json_decode($data['proposel_data'], true);
|
||||
try {
|
||||
$proposel_data = json_decode($data['proposel_data'], true);
|
||||
$QCRData = $this->RFQModel->where('is_active', 1)->where('lead_id', $data['id'])->first();
|
||||
|
||||
$QCRData = $this->RFQModel->where('is_active', 1)->where('lead_id', $data['id'])->first();
|
||||
if (!$QCRData) {
|
||||
throw new \Exception('RFQ Data not found');
|
||||
}
|
||||
|
||||
$JSON = json_decode($QCRData['json'], true);
|
||||
$JSON = json_decode($QCRData['json'], true);
|
||||
$converted_json = $this->transformProposelData($JSON, $proposel_data['proposel_name'], $proposel_data['insurer_name']);
|
||||
|
||||
$converted_json = $this->transformProposelData($JSON, $proposel_data['proposel_name'], $proposel_data['insurer_name']);
|
||||
|
||||
return $this->convertQCRJsonToPolicyTerms($converted_json, $data['policy_type_id'], $proposel_data['proposel_name'], $proposel_data['insurer_name']);
|
||||
return $this->convertQCRJsonToPolicyTerms($converted_json, $data['policy_type_id'], $proposel_data['proposel_name'], $proposel_data['insurer_name']);
|
||||
} catch (\Throwable $e) {
|
||||
$this->myLogger->logme('preparePolicyTermsFromRFQ', $e->getMessage(), ['lead_id' => $data['id'], 'trace' => $e->getTraceAsString()]);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function featchClientPolicyFromLead($client_id, $branch_id, $lead_id)
|
||||
{
|
||||
$data = $this->leadsModel->where('leads.id', $lead_id)->where('leads.is_active', 1)->first();
|
||||
|
||||
if (!$data) {
|
||||
return $this->respond(['status' => false, 'message' => 'Failed to create policy', 'data' => null], 200);
|
||||
}
|
||||
|
||||
$result = $this->createClientPolicyWithLeadData($data, $client_id, $branch_id);
|
||||
// print_r($result); die;
|
||||
|
||||
if ($result) {
|
||||
|
||||
$policy_data = $this->clientPolicyModel->where('id', $result)->where('is_active', 1)->first();
|
||||
return $this->respond(['status' => true, 'message' => 'New Policy created successfully', 'client_policy_id' => $result, 'data' => $data, 'client_id' => $policy_data['client_id']], 200);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => false, 'message' => 'Failed to create policy', 'data' => $data], 200);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//Function for convert the RFQ and QCR Json to Policy Terms Json
|
||||
public function convertQCRJsonToPolicyTerms($data, $policy_type, $proposel_name, $insurer_name)
|
||||
{
|
||||
@ -2817,26 +2872,6 @@ class LeadsController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
public function featchClientPolicyFromLead($client_id, $branch_id, $lead_id)
|
||||
{
|
||||
$data = $this->leadsModel->where('leads.id', $lead_id)->where('leads.is_active', 1)->first();
|
||||
|
||||
if (!$data) {
|
||||
return $this->respond(['status' => false, 'message' => 'Failed to create policy', 'data' => null], 200);
|
||||
}
|
||||
|
||||
$result = $this->createClientPolicyWithLeadData($data, $client_id, $branch_id);
|
||||
// print_r($result); die;
|
||||
|
||||
if ($result) {
|
||||
|
||||
$policy_data = $this->clientPolicyModel->where('id', $result)->where('is_active', 1)->first();
|
||||
return $this->respond(['status' => true, 'message' => 'New Policy created successfully', 'client_policy_id' => $result, 'data' => $data, 'client_id' => $policy_data['client_id']], 200);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => false, 'message' => 'Failed to create policy', 'data' => $data], 200);
|
||||
}
|
||||
|
||||
public function getPlacementJson(array $data): ?string
|
||||
{
|
||||
$proposel_data = json_decode($data['proposel_data'], true);
|
||||
@ -2929,7 +2964,7 @@ class LeadsController extends BaseController
|
||||
}
|
||||
|
||||
|
||||
function getLastFiveFinancialYears()
|
||||
public function getLastFiveFinancialYears()
|
||||
{
|
||||
$currentYear = date('Y');
|
||||
$currentMonth = date('m');
|
||||
|
||||
@ -327,42 +327,37 @@ class PolicyTransactionController extends BaseController
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
private function insertInceptionPolicy($data)
|
||||
{
|
||||
{
|
||||
// print_r($data); die;
|
||||
|
||||
$insert = $this->policyTransactionModel->insert($data);
|
||||
|
||||
if ($insert) {
|
||||
|
||||
$this->insertTransactionStatus($insert, $data, 1);
|
||||
$emp_data = $this->processInsertIndividualMemberInEmpTable($data);
|
||||
|
||||
if(isset($data['follow_insurer_id']) && !empty($data['follow_insurer_id'][0])){
|
||||
if (isset($data['follow_insurer_id']) && !empty($data['follow_insurer_id'][0])) {
|
||||
|
||||
$pt_co_share_details = $this->insertOrUpdateCoShareDetails($data, $insert);
|
||||
|
||||
if ($data['ct_type'] == 2) {
|
||||
|
||||
$client_policy_insert_data = $this->prepareClientPolicyInsertData($data);
|
||||
$client_policy_id = $this->clientPolicyModel->insert($client_policy_insert_data);
|
||||
$this->policyTransactionModel->update($insert, ['client_policy_id' => $client_policy_id]);
|
||||
$emp_policy_insert = $this->InsertIndividualEmpPolicyTable($emp_data, $client_policy_id);
|
||||
|
||||
if ($data['client_type'] == 1 && $data['status'] == 'completed' && $data['is_cd_reduce_from_bds'] == 1) {
|
||||
$this->processCompletedStatus($data, $client_policy_id, $data['insurer_id']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$data['pt_co_share_details'] = $this->PTCOShareDetailsModel->where('pt_id', $insert)->where('is_active', 1)->findAll();
|
||||
if ($data['client_type'] == 1 && $data['status'] == 'completed' && $data['is_cd_reduce_from_bds'] == 1) {
|
||||
$this->processCompletedStatus($data, $client_policy_id, $data['insurer_id']);
|
||||
}
|
||||
}
|
||||
|
||||
$client_data = $this->clientModel->where('id', $data['client_id'])->first();
|
||||
$data['client_kyc'] = $this->clientKYCDocsModel->where('client_id', $data['client_id'])->findAll();
|
||||
$data['entity_type_id'] = $client_data['entity_type_id'];
|
||||
|
||||
return $this->respondSuccess($insert, "Policy transaction created successfully", $data);
|
||||
}
|
||||
|
||||
return $this->respondError("Failed to create policy transaction");
|
||||
}
|
||||
|
||||
@ -397,19 +392,12 @@ class PolicyTransactionController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
if ($data['status'] == 'completed' && $data['ct_type'] == 2) {
|
||||
if($data['client_type'] == 1 && $data['is_cd_reduce_from_bds'] == 1){
|
||||
$this->processCompletedStatus($data, $data['client_policy_id'], $data['insurer_id']);
|
||||
}
|
||||
if($data['status'] == 'completed' && $data['client_type'] == 1 && $data['is_cd_reduce_from_bds'] == 1){
|
||||
$this->processCompletedStatus($data, $data['client_policy_id'], $data['insurer_id']);
|
||||
}
|
||||
|
||||
$data['pt_co_share_details'] = $this->PTCOShareDetailsModel->where('pt_id', $id)->where('is_active', 1)->findAll();
|
||||
}
|
||||
|
||||
$client_data = $this->clientModel->where('id', $data['client_id'])->first();
|
||||
$data['client_kyc'] = $this->clientKYCDocsModel->where('client_id', $data['client_id'])->findAll();
|
||||
$data['entity_type_id'] = $client_data['entity_type_id'];
|
||||
|
||||
return $this->respondSuccess($id, "Policy transaction updated successfully", $data);
|
||||
}
|
||||
|
||||
|
||||
@ -17,6 +17,10 @@ table.dataTable thead th {
|
||||
max-width: 98% !important;
|
||||
}
|
||||
|
||||
.btn-filter{
|
||||
margin-left: 20px !important;
|
||||
}
|
||||
|
||||
.custom-dropdown-menu {
|
||||
display: none;
|
||||
position: absolute;
|
||||
@ -53,12 +57,12 @@ table.dataTable thead th {
|
||||
<div class="col-6" style="align-self: center;">
|
||||
<h4 style="position: relative;">Client List</h4>
|
||||
</div>
|
||||
<div class="col-2" style="text-align: right; position: relative;top: 56px; left: 303px;">
|
||||
<!-- <div class="col-2" style="text-align: right; position: relative;top: 56px; left: 303px;">
|
||||
<a class="btn btn-primary waves-effect waves-light" onclick="showModal()">Add From Lead</a>
|
||||
</div>
|
||||
<div class="col-1" style="text-align: right; position: relative;top: 56px; left: 294px;">
|
||||
<a href="<?= base_url("client/create"); ?>" type="button" id="btnAdd" class="btn btn-primary waves-effect waves-light" data-toggle="" data-placement="top" title="Add" data-trigger="hover">Add</a>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
<table class="table table-sm table-hover m-0 table-centered dt-responsive nowrap w-100" cellspacing="0"
|
||||
id="tickets-table">
|
||||
@ -269,18 +273,40 @@ table.dataTable thead th {
|
||||
$(document).ready(function()
|
||||
{
|
||||
$('#tickets-table').DataTable({
|
||||
dom: "<'row'<'col-sm-0'f><'col-sm-7 text-right'B>>" +
|
||||
dom: "<'row'<'col-sm-2'f><'col-sm-10 text-right'B>>" +
|
||||
"<'row'<'col-sm-12'tr>>" +
|
||||
"<'row'<'col-sm-5'i><'col-sm-7'p>>",
|
||||
buttons: [{
|
||||
extend: 'csv',
|
||||
text: 'CSV',
|
||||
title: 'ClientList',
|
||||
className: 'my_class',
|
||||
exportOptions: {
|
||||
columns: ':not(:last-child)'
|
||||
buttons: [
|
||||
{
|
||||
extend: 'csv',
|
||||
text: 'CSV',
|
||||
title: 'ClientList',
|
||||
className: 'my_class',
|
||||
exportOptions: {
|
||||
columns: ':not(:last-child)'
|
||||
},
|
||||
},
|
||||
{
|
||||
text: 'Add From Lead',
|
||||
className: 'btn-filter', // custom class
|
||||
action: function(e, dt, node, config) {
|
||||
showModal();
|
||||
}
|
||||
},
|
||||
}],
|
||||
{
|
||||
text: 'Add',
|
||||
className: 'btn-filter', // custom class
|
||||
action: function(e, dt, node, config) {
|
||||
addClient();
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
initComplete: function() {
|
||||
$('.btn-filter')
|
||||
.removeClass('btn-secondary')
|
||||
.addClass('btn btn-primary');
|
||||
},
|
||||
language: {
|
||||
search: "_INPUT_",
|
||||
searchPlaceholder: "Search..."
|
||||
@ -440,4 +466,9 @@ function featchClient(){
|
||||
});
|
||||
}
|
||||
|
||||
function addClient(){
|
||||
let url = "<?= base_url("client/create"); ?>";
|
||||
window.location.href = url;
|
||||
}
|
||||
|
||||
</script>
|
||||
Loading…
Reference in New Issue
Block a user