FIX_EMAIL_VALIDATION_LEAD_DASHBOARD_AND_OTHERS : RV
This commit is contained in:
parent
654a20fff3
commit
c50a320e43
@ -519,7 +519,6 @@ class ClientController extends AdminController
|
||||
public function updateEmpAndPolicyStatus()
|
||||
{
|
||||
$return = $this->clientPolicyModel->updateStatus();
|
||||
return $return;
|
||||
$this->myLogger->logme('error', 'Client Policy Status Update Count: {data}', ['data' => $return['client']]);
|
||||
$this->myLogger->logme('error', 'Employee Policy Status Update Count: {data}', ['data' => $return['emp']]);
|
||||
}
|
||||
|
||||
@ -35,6 +35,7 @@ use App\Controllers\JobWorker;
|
||||
use App\Controllers\Jobs\SubJob;
|
||||
use App\Controllers\EmployeeServiceController;
|
||||
use App\Controllers\EmpDataServiceController;
|
||||
use App\Models\LeadsModel;
|
||||
use App\Models\ThzMasterModel;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
@ -171,7 +172,7 @@ class EmployeeController extends AdminController
|
||||
return $this->respond(['dataStatus' => false, 'code' => 404, 'message' => 'no data found'], 200);
|
||||
} else {
|
||||
|
||||
return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => $file['reason'], 'is_comparison_skipped' => $file['is_comparison_skipped']], 200);
|
||||
return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => $file['reason'], 'is_comparison_skipped' => $file['is_comparison_skipped'], 'policy_id' => $file['policy_id']], 200);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3151,6 +3152,8 @@ class EmployeeController extends AdminController
|
||||
{
|
||||
$file_id = $this->request->getGet('file_id');
|
||||
$not_skiped = $this->request->getGet('not_skiped') ?? null;
|
||||
$this->myLogger->logme('error', json_encode($this->request->getGet() ?? []));
|
||||
|
||||
|
||||
if(!empty($not_skiped)){
|
||||
$file_model = new FileModel();
|
||||
@ -3161,11 +3164,36 @@ class EmployeeController extends AdminController
|
||||
}
|
||||
|
||||
if(!empty($file_id)){
|
||||
|
||||
$r = Jobs::addJob(['job_name' => 'excelFileDataValidation','payload' => ['file_id' => $file_id]]);
|
||||
$message = "Inception and Member data comparision skiped successfully by the user id : " . get_session_userid();
|
||||
$this->myLogger->logme('error', $message);
|
||||
|
||||
$file_model = new FileModel();
|
||||
$file_model->where('id', $file_id)->set(['is_comparison_skipped' => 1])->update();
|
||||
|
||||
$policy_id = $this->request->getGet('policy_id') ?? null;
|
||||
|
||||
if ($policy_id) {
|
||||
|
||||
$client_policy_data = $this->clientPolicyModel->where('id', $policy_id)->first();
|
||||
|
||||
if (!empty($client_policy_data) && isset($client_policy_data['is_from_lead'])) {
|
||||
$lead_id = $client_policy_data['is_from_lead'];
|
||||
|
||||
if (!empty($lead_id)) {
|
||||
$lead_model = new LeadsModel();
|
||||
$lead_model->where('id', $lead_id)->set(['policy_with_correction' => 1])->update();
|
||||
} else {
|
||||
$this->myLogger->logme('error', 'Lead ID missing for policy ID: ' . $policy_id);
|
||||
}
|
||||
} else {
|
||||
$this->myLogger->logme('error', 'No client policy data found for policy ID: ' . $policy_id);
|
||||
}
|
||||
} else {
|
||||
$this->myLogger->logme('error', 'Policy ID not provided in GET request.');
|
||||
}
|
||||
|
||||
return $this->respond(['status' => true, 'code' => 200, 'message' => 'Inception and Member data comparision skiped successfully!'], 200);
|
||||
}else{
|
||||
return $this->respond(['status' => false, 'code' => 500, 'message' => 'Failed to skip the comparison!'], 200);
|
||||
|
||||
@ -2390,7 +2390,9 @@ class EmployeeServiceController extends AdminController
|
||||
// --------- MEMBER DATA AND INCEPTION DATA COMPARISION ------------------------------------------------------------------------
|
||||
|
||||
public function compareMemberDataAndInceptionData($params)
|
||||
{
|
||||
{
|
||||
helper('excel_util_helper');
|
||||
|
||||
$file_id = $params['file_id'] ?? null;
|
||||
if (empty($file_id)) {
|
||||
return ['status' => false, 'msg' => 'File ID is missing'];
|
||||
|
||||
@ -77,7 +77,7 @@ class LeadsController extends BaseController
|
||||
protected $issuer;
|
||||
protected $clientType;
|
||||
protected $leadType;
|
||||
protected $leadsStatus;
|
||||
public $leadsStatus;
|
||||
protected $claim_type_for_gpa;
|
||||
protected $cause_of_death;
|
||||
protected $buisnessType;
|
||||
|
||||
@ -1646,21 +1646,53 @@ if (!function_exists('check_dup_mobileno')) {
|
||||
}
|
||||
}
|
||||
|
||||
// if (!function_exists('check_dup_email')) {
|
||||
// function check_dup_email(array $row, array $existing_mobilenos)
|
||||
// {
|
||||
// is_valid_or_empty_email($row['13']);
|
||||
// if(!empty($row['13'])){
|
||||
// foreach ($existing_mobilenos as $k => $value) {
|
||||
// if (strtolower($row['5']) == 'self' && $row['13'] == $value['email_corporate']) {
|
||||
// return array('status' => false, 'error' => "Duplicate Email");
|
||||
// // break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return array('status' => true);
|
||||
// }
|
||||
// }
|
||||
|
||||
if (!function_exists('check_dup_email')) {
|
||||
function check_dup_email(array $row, array $existing_mobilenos)
|
||||
{
|
||||
if(!empty($row['13'])){
|
||||
foreach ($existing_mobilenos as $k => $value) {
|
||||
if (strtolower($row['5']) == 'self' && $row['13'] == $value['email_corporate']) {
|
||||
return array('status' => false, 'error' => "Duplicate Email");
|
||||
// break;
|
||||
$errorMessages = [];
|
||||
|
||||
// Validate email
|
||||
$emailCheck = is_valid_or_empty_email($row['13'] ?? "");
|
||||
if (!$emailCheck) {
|
||||
$errorMessages[] = 'Invalid email format';
|
||||
}
|
||||
|
||||
// Check duplicate only if email is not empty
|
||||
if (!empty($row['13'])) {
|
||||
foreach ($existing_mobilenos as $value) {
|
||||
if (strtolower(trim($row['5'])) === 'self' && trim($row['13']) === trim($value['email_corporate'])) {
|
||||
$errorMessages[] = 'Duplicate Email';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return array('status' => true);
|
||||
|
||||
// Prepare final return
|
||||
if (!empty($errorMessages)) {
|
||||
return ['status' => false, 'error' => implode(' & ', $errorMessages)];
|
||||
}
|
||||
|
||||
return ['status' => true, 'error' => ''];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('generate_family_relationship_array')) {
|
||||
function generate_family_relationship_array($family_structure_from_policy_terms)
|
||||
{
|
||||
@ -2403,3 +2435,24 @@ if (!function_exists('check_age_validation')) {
|
||||
// ------------- END OF LEAD MEMBER DATA LIST VALIDATIONS --------------------------------------
|
||||
|
||||
|
||||
if (!function_exists('is_valid_or_empty_email')) {
|
||||
function is_valid_or_empty_email($email)
|
||||
{
|
||||
// If empty or null → return success
|
||||
if (empty($email) && $email != 0) {
|
||||
// return ['status' => true, 'error' => 'Value is empty'];
|
||||
return true;
|
||||
}
|
||||
|
||||
// If valid email → return success
|
||||
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
// return ['status' => true, 'error' => 'Valid email format'];
|
||||
return true;
|
||||
}
|
||||
|
||||
// If invalid email → return failure
|
||||
// return ['status' => false, 'error' => 'Invalid email format'];
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -431,8 +431,8 @@ class ClientPolicyModel extends Model
|
||||
$emp_count = $this->db->affectedRows();
|
||||
|
||||
// Log the result
|
||||
log_message('info', "Client policies updated: {$client_count}");
|
||||
log_message('info', "Employee policies updated: {$emp_count}");
|
||||
log_message('error', "Client policies updated: {$client_count}");
|
||||
log_message('error', "Employee policies updated: {$emp_count}");
|
||||
|
||||
return ['client' => $client_count, 'emp' => $emp_count];
|
||||
}
|
||||
|
||||
@ -106,6 +106,7 @@ class LeadsModel extends Model
|
||||
'is_insurer_auto_mail',
|
||||
'quote_received_insurer',
|
||||
'acm_id',
|
||||
'policy_with_correction',
|
||||
];
|
||||
|
||||
|
||||
@ -204,78 +205,151 @@ class LeadsModel extends Model
|
||||
return $result;
|
||||
}
|
||||
|
||||
// public function getDashData()
|
||||
// {
|
||||
// $statuses = $this->db->table('leads')
|
||||
// ->select('status, policy_with_correction')
|
||||
// ->where("is_active", 1)
|
||||
// ->groupBy('status')
|
||||
// ->get()
|
||||
// ->getResultArray();
|
||||
|
||||
// $policy_with_correction_count = $this->db->table('leads')
|
||||
// ->where('is_active', 1)
|
||||
// ->where('policy_with_correction', 1)
|
||||
// ->countAllResults();
|
||||
|
||||
// $selectParts = [];
|
||||
|
||||
// foreach ($statuses as $status) {
|
||||
// $s = $status['status'];
|
||||
// $alias = strtolower(str_replace(' ', '_', $s));
|
||||
|
||||
// // Count alias
|
||||
// $selectParts[] = "SUM(CASE WHEN status = '{$s}' THEN 1 ELSE 0 END) AS `{$alias}`";
|
||||
|
||||
// // IDs alias
|
||||
// $selectParts[] = "GROUP_CONCAT(CASE WHEN status = '{$s}' THEN leads.id ELSE NULL END) AS `{$alias}_ids`";
|
||||
// }
|
||||
|
||||
// $select = implode(", ", $selectParts);
|
||||
|
||||
// // Start query builder
|
||||
// $builder = $this->db->table('leads');
|
||||
|
||||
// $builder->select($select);
|
||||
|
||||
// // Auditing subquery
|
||||
// $subquery = "(SELECT pk, MAX(created_at) AS last_claim_status_change
|
||||
// FROM auditing_history
|
||||
// WHERE table_name = 'leads' AND field_name = 'status'
|
||||
// GROUP BY pk)";
|
||||
|
||||
// $builder->join("{$subquery} AS th", 'leads.id = th.pk', 'left');
|
||||
|
||||
// // Date filtering for last status change
|
||||
// $dateLimit = 3;
|
||||
// $dateThreshold = date('Y-m-d H:i:s', strtotime("-{$dateLimit} days"));
|
||||
|
||||
// $builder->groupStart()
|
||||
// ->where('th.last_claim_status_change <=', $dateThreshold)
|
||||
// ->orWhere('th.last_claim_status_change IS NULL')
|
||||
// ->groupEnd();
|
||||
|
||||
// // Add only active
|
||||
// $builder->where("leads.is_active", 1);
|
||||
|
||||
// $lead_data = $builder->get()->getResultArray();
|
||||
|
||||
// // dd($this->db->getLastQuery());
|
||||
|
||||
// // Fallback for empty results
|
||||
// if (empty($lead_data)) {
|
||||
// $lead_data[0] = ['total' => 0];
|
||||
// foreach ($statuses as $status) {
|
||||
// $alias = strtolower(str_replace(' ', '_', $status['status']));
|
||||
// $lead_data[0][$alias] = 0;
|
||||
// $lead_data[0]["{$alias}_ids"] = '';
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Calculate total
|
||||
// $total = 0;
|
||||
// foreach ($lead_data[0] as $key => $value) {
|
||||
// // if (!str_ends_with($key, '_ids') && $key != "won") {
|
||||
// // $total += (int) $value;
|
||||
// // }
|
||||
|
||||
// if (!str_ends_with($key, '_ids')) {
|
||||
// $total += (int) $value;
|
||||
// }
|
||||
// }
|
||||
|
||||
// $total = $total + $policy_with_correction_count ?? 0;
|
||||
// $lead_data[0]['total'] = $total;
|
||||
// $lead_data[0]['policy_with_correction'] = $policy_with_correction_count;
|
||||
|
||||
|
||||
// // dd($lead_data[0]);
|
||||
// return $lead_data[0];
|
||||
// }
|
||||
|
||||
|
||||
public function getDashData()
|
||||
{
|
||||
// Get all unique statuses
|
||||
$statuses = $this->db->table('leads')
|
||||
->select('status')
|
||||
->where("is_active", 1)
|
||||
->groupBy('status')
|
||||
->select('DISTINCT(status)')
|
||||
->where('is_active', 1)
|
||||
->get()
|
||||
->getResultArray();
|
||||
|
||||
|
||||
$policy_with_correction_data = $this->db->table('leads')
|
||||
->select('COUNT(id) AS count, GROUP_CONCAT(id) AS ids')
|
||||
->where('is_active', 1)
|
||||
->where('policy_with_correction', 1)
|
||||
->get()
|
||||
->getRowArray();
|
||||
|
||||
if (empty($statuses)) {
|
||||
return ['total' => 0];
|
||||
}
|
||||
|
||||
// Build dynamic select fields for each status
|
||||
$selectParts = [];
|
||||
|
||||
foreach ($statuses as $status) {
|
||||
$s = $status['status'];
|
||||
$alias = strtolower(str_replace(' ', '_', $s));
|
||||
|
||||
// Count alias
|
||||
$selectParts[] = "SUM(CASE WHEN status = '{$s}' THEN 1 ELSE 0 END) AS `{$alias}`";
|
||||
|
||||
// IDs alias
|
||||
$selectParts[] = "GROUP_CONCAT(CASE WHEN status = '{$s}' THEN leads.id ELSE NULL END) AS `{$alias}_ids`";
|
||||
foreach ($statuses as $row) {
|
||||
$status = $row['status'];
|
||||
$alias = strtolower(str_replace(' ', '_', $status));
|
||||
|
||||
$selectParts[] = "SUM(CASE WHEN status = '{$status}' THEN 1 ELSE 0 END) AS `{$alias}`";
|
||||
$selectParts[] = "GROUP_CONCAT(CASE WHEN status = '{$status}' THEN id END) AS `{$alias}_ids`";
|
||||
}
|
||||
|
||||
|
||||
$select = implode(", ", $selectParts);
|
||||
|
||||
// Start query builder
|
||||
$builder = $this->db->table('leads');
|
||||
|
||||
$builder->select($select);
|
||||
|
||||
// Auditing subquery
|
||||
$subquery = "(SELECT pk, MAX(created_at) AS last_claim_status_change
|
||||
FROM auditing_history
|
||||
WHERE table_name = 'leads' AND field_name = 'status'
|
||||
GROUP BY pk)";
|
||||
|
||||
$builder->join("{$subquery} AS th", 'leads.id = th.pk', 'left');
|
||||
|
||||
// Date filtering for last status change
|
||||
$dateLimit = 3;
|
||||
$dateThreshold = date('Y-m-d H:i:s', strtotime("-{$dateLimit} days"));
|
||||
|
||||
$builder->groupStart()
|
||||
->where('th.last_claim_status_change <=', $dateThreshold)
|
||||
->orWhere('th.last_claim_status_change IS NULL')
|
||||
->groupEnd();
|
||||
|
||||
// Add only active
|
||||
$builder->where("leads.is_active", 1);
|
||||
|
||||
$lead_data = $builder->get()->getResultArray();
|
||||
|
||||
// Fallback for empty results
|
||||
if (empty($lead_data)) {
|
||||
$lead_data[0] = ['total' => 0];
|
||||
foreach ($statuses as $status) {
|
||||
$alias = strtolower(str_replace(' ', '_', $status['status']));
|
||||
$lead_data[0][$alias] = 0;
|
||||
$lead_data[0]["{$alias}_ids"] = '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Main query
|
||||
$lead_data = $this->db->table('leads')
|
||||
->select($select)
|
||||
->where('is_active', 1)
|
||||
->get()
|
||||
->getRowArray();
|
||||
|
||||
// Calculate total
|
||||
$total = 0;
|
||||
foreach ($lead_data[0] as $key => $value) {
|
||||
if (!str_ends_with($key, '_ids') && $key != "won") {
|
||||
$total += (int) $value;
|
||||
foreach ($lead_data as $key => $val) {
|
||||
if (!str_ends_with($key, '_ids')) {
|
||||
$total += (int) $val;
|
||||
}
|
||||
}
|
||||
$lead_data[0]['total'] = $total;
|
||||
|
||||
// dd($lead_data[0]);
|
||||
return $lead_data[0];
|
||||
|
||||
$lead_data['total'] = $total;
|
||||
$lead_data['policy_with_correction'] = $policy_with_correction_data['count'] ?? 0;
|
||||
$lead_data['policy_with_correction_ids'] = $policy_with_correction_data['ids'] ?? null;
|
||||
|
||||
// dd($lead_data);
|
||||
return $lead_data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -463,6 +463,7 @@ function fetchFileError(file_id) {
|
||||
},
|
||||
success: function(response) {
|
||||
|
||||
console.log('fetchFileError response', response);
|
||||
$(this).find(".modal-body").html("");
|
||||
if (response.code === 200 && response.dataStatus === true && response.data !== "") {
|
||||
|
||||
@ -475,6 +476,7 @@ function fetchFileError(file_id) {
|
||||
let buttonAdded = false;
|
||||
let error_code = 0;
|
||||
let is_comparison_skipped = response.is_comparison_skipped ?? null;
|
||||
let policy_id = response.policy_id ?? null;
|
||||
|
||||
for (var key in file_error_data['error_summary']) {
|
||||
// console.log(key);
|
||||
@ -594,8 +596,8 @@ function fetchFileError(file_id) {
|
||||
file_error_html +=
|
||||
"<div id='confirmationdiv' class='mt-2 text-center'>" +
|
||||
"<p class='mb-2'>Do you want to skip the comparison?</p>" +
|
||||
"<button id='confirmYes' class='btn btn-success btn-sm mx-1' data-id="+file_id+">Yes</button>" +
|
||||
"<button id='confirmNo' class='btn btn-danger btn-sm mx-1' data-id="+file_id+">No</button>" +
|
||||
"<button id='confirmYes' class='btn btn-success btn-sm mx-1' data-id="+file_id+" data-pid="+policy_id+">Yes</button>" +
|
||||
"<button id='confirmNo' class='btn btn-danger btn-sm mx-1' data-id="+file_id+" data-pid="+policy_id+">No</button>" +
|
||||
"</div>";
|
||||
buttonAdded = true;
|
||||
} else if (hasError14 && !hasError15 && error_code == 14) {
|
||||
@ -603,8 +605,8 @@ function fetchFileError(file_id) {
|
||||
file_error_html +=
|
||||
"<div id='confirmationdiv' class='mt-2 text-center'>" +
|
||||
"<p class='mb-2'>Do you want to skip the comparison?</p>" +
|
||||
"<button id='confirmYes' class='btn btn-success btn-sm mx-1' data-id="+file_id+">Yes</button>" +
|
||||
"<button id='confirmNo' class='btn btn-danger btn-sm mx-1' data-id="+file_id+">No</button>" +
|
||||
"<button id='confirmYes' class='btn btn-success btn-sm mx-1' data-id="+file_id+" data-pid="+policy_id+">Yes</button>" +
|
||||
"<button id='confirmNo' class='btn btn-danger btn-sm mx-1' data-id="+file_id+" data-pid="+policy_id+">No</button>" +
|
||||
"</div>";
|
||||
buttonAdded = true;
|
||||
}
|
||||
@ -1090,6 +1092,10 @@ function checkValues() {
|
||||
|
||||
$(document).on('click', '#confirmYes', function() {
|
||||
let file_id = $(this).data('id');
|
||||
let policy_id = $(this).data('pid');
|
||||
|
||||
console.log('file_id', file_id);
|
||||
console.log('policy_id', policy_id);
|
||||
|
||||
Swal.fire({
|
||||
title: "Are you sure?",
|
||||
@ -1110,7 +1116,7 @@ $(document).on('click', '#confirmYes', function() {
|
||||
$.ajax({
|
||||
url: '<?= base_url("util/proceedExcelFileDataValidation") ?>', // replace with actual API URL
|
||||
type: 'GET',
|
||||
data: { file_id: file_id },
|
||||
data: { file_id: file_id, policy_id: policy_id },
|
||||
success: function(response) {
|
||||
console.log('API response:', response);
|
||||
|
||||
|
||||
@ -209,9 +209,13 @@ $isActive = get_role_id() == STAFF_ROLE_ID && in_array(ENROLLMENT_TEAM_ID, user_
|
||||
$index = 0;
|
||||
foreach ($lead_data as $key => $value) : ?>
|
||||
<?php
|
||||
if ($key == "total" || $key == "won" || substr($key, -4) === "_ids") {
|
||||
if ($key == "total" || substr($key, -4) === "_ids") {
|
||||
continue;
|
||||
} // Skip the total key
|
||||
}
|
||||
// if ($key == "total" || $key == "won" || substr($key, -4) === "_ids") {
|
||||
// continue;
|
||||
// }
|
||||
// Skip the total key
|
||||
?>
|
||||
<?php
|
||||
// Initialize color set and shade indexes
|
||||
|
||||
Loading…
Reference in New Issue
Block a user