FIX_DASHBOARD_ISSUE : RV

This commit is contained in:
VENKATESHWARAN 2025-03-01 17:45:26 +05:30
parent b878550c5d
commit 47970b7d98
4 changed files with 542 additions and 561 deletions

View File

@ -98,19 +98,60 @@ class DashboardController extends AdminController
public function dashboard()
{
$data = [];
$data['page_name'] = 'Dashboard';
$db = db_connect();
$sql = "SELECT
clients.id AS client_id,
clients.client_name,
clients.short_name,
client_branch.id AS client_branch_id,
client_branch.branch_name,
client_branch.branch_code,
COUNT(employees.id) AS total_employees,
SUM(CASE WHEN employees.emp_status = 'draft' THEN 1 ELSE 0 END) AS draft_count,
SUM(CASE WHEN employees.emp_status IN ('enrolled', 'active') THEN 1 ELSE 0 END) AS enrolled_count,
$results = $this->clientModel->select('clients.id as client_id, clients.client_name, clients.short_name,
client_branch.id as client_branch_id, client_branch.branch_name,
client_branch.branch_code, employees.id as employee_id,
employees.name as employee_name, employees.relationship,
employees.emp_code, employees.emp_status, auth_history.user_type, client_policy.policy_type_id, client_policy.id as client_policy_id')
->join('client_branch', 'clients.id = client_branch.client_id', 'left')
->join('client_policy', 'client_branch.id = client_policy.client_branch_id', 'left')
->join('employees', 'client_branch.id = employees.client_branch_id', 'left')
->join('auth_history', 'employees.id = auth_history.user_id AND "employee" = auth_history.user_type', 'left')
->findAll();
SUM(CASE WHEN auth_history.user_id IS NOT NULL THEN 1 ELSE 0 END) AS logged_in_count,
SUM(CASE WHEN auth_history.user_id IS NULL THEN 1 ELSE 0 END) AS not_logged_in_count,
CASE
WHEN EXISTS (
SELECT 1 FROM client_policy
WHERE client_policy.client_branch_id = client_branch.id
AND client_policy.is_active = 1
AND client_policy.open_for_enrollment = 1
) THEN 1
ELSE 0
END AS open_or_close_enrollment
FROM clients
LEFT JOIN client_branch ON clients.id = client_branch.client_id
LEFT JOIN employees ON client_branch.id = employees.client_branch_id
LEFT JOIN (
SELECT user_id, user_type
FROM auth_history
WHERE user_type = 'employee'
GROUP BY user_id
) AS auth_history ON employees.id = auth_history.user_id
WHERE employees.relationship = 'Self'
AND employees.emp_status IN ('draft', 'enrolled', 'active')
AND employees.is_active = 1
AND clients.is_active = 1
AND client_branch.is_active = 1
GROUP BY clients.id, client_branch.id";
$query = $db->query($sql);
$results = $query->getResultArray();
$data['client_branch_emp_list'] = $results;
$session = \Config\Services::session();
$session->set('enrollment_data', json_encode($data));
// $pendingActionsController = new PendingActionsController;
// $pendingActionsData = $pendingActionsController->getPendingActionsForDashBoard();
// $businessTeamData = $this->policyTransactionModel->getBusinessReportList();
@ -118,95 +159,6 @@ class DashboardController extends AdminController
// $businessTeamStatusData = $this->data_construct_for_bds($businessTeamData);
// $financeTeamStatusData = $this->data_construct_for_bds($financeTeamData);
$groupedData = [];
foreach ($results as $row) {
$clientId = $row['client_id'];
$clientName = $row['client_name'];
$shortName = $row['short_name'];
$branchId = $row['client_branch_id'];
$branchName = $row['branch_name'];
$branchCode = $row['branch_code'];
$clientPolicyId = $row['client_policy_id'];
$policyTypeId = $row['policy_type_id'];
$employeeId = '';
if ($employeeId != $row['employee_id']) {
$employeeId = $row['employee_id'];
} else {
$employeeId = null;
}
$employeeName = $row['employee_name'];
$employeeRelationship = $row['relationship'];
$employeeEmpCode = $row['emp_code'];
$employeeEmpStatus = $row['emp_status'];
$employeeUserType = $row['user_type'];
// Initialize the client entry if it doesn't exist
if (!isset($groupedData[$clientId])) {
$groupedData[$clientId] = [
'client_id' => $clientId,
'client_name' => $clientName,
'short_name' => $shortName,
'branches' => []
];
}
// Initialize the branch entry if it doesn't exist
if (!isset($groupedData[$clientId]['branches'][$branchId])) {
$groupedData[$clientId]['branches'][$branchId] = [
'client_branch_id' => $branchId,
'branch_name' => $branchName,
'branch_code' => $branchCode,
'emp_login' => 0,
'emp_enroll' => 0,
'client_policies' => [],
'employees' => []
];
}
// Add the client policy to the branch's policies list if it exists, not already added, and policyTypeId is not equal to 1
if ($clientPolicyId !== null && $policyTypeId != 1 && !in_array(['client_policy_id' => $clientPolicyId, 'policy_type_id' => $policyTypeId], $groupedData[$clientId]['branches'][$branchId]['client_policies'])) {
$groupedData[$clientId]['branches'][$branchId]['client_policies'][] = [
'client_policy_id' => $clientPolicyId,
'policy_type_id' => $policyTypeId
];
}
// Append employee error to the branch's employees list if relationship is 'Self' and not already added
$employeeKey = $employeeId . '-' . $employeeName; // unique key to identify an employee
if ($employeeId !== null && $employeeRelationship == 'Self' && !isset($groupedData[$clientId]['branches'][$branchId]['employees'][$employeeKey])) {
$groupedData[$clientId]['branches'][$branchId]['employees'][$employeeKey] = [
'employee_id' => $employeeId,
'employee_name' => $employeeName,
'relationship' => $employeeRelationship,
'emp_code' => $employeeEmpCode,
'emp_status' => $employeeEmpStatus,
'user_type' => $employeeUserType
];
if (!empty($employeeUserType)) {
$groupedData[$clientId]['branches'][$branchId]['emp_login']++;
}
// Increment emp_enroll if emp_status is not 'draft'
if ($employeeEmpStatus !== 'draft') {
$groupedData[$clientId]['branches'][$branchId]['emp_enroll']++;
}
}
}
// Re-index the arrays to match the expected structure
foreach ($groupedData as &$client) {
foreach ($client['branches'] as &$branch) {
$branch['employees'] = array_values($branch['employees']);
}
$client['branches'] = array_values($client['branches']);
}
$data['client_branch_emp_list'] = $groupedData;
$session = \Config\Services::session();
$session->set('enrollment_data', json_encode($data));
// echo "<pre>";
// $data['pendingActionsData'] = $pendingActionsData;
// $data['businessTeamCount'] = count($businessTeamData) ?? 0;
// $data['financeTeamCount'] = count($financeTeamData) ?? 0;
@ -214,9 +166,8 @@ class DashboardController extends AdminController
// $data['financeTeamStatusData'] = $financeTeamStatusData;
// $data['policyStatus'] = $this->policyStatus;
// $data['colorShades'] = $this->colorShades;
// dd($data);die;
$data['page_name'] = 'Dashboard';
// dd($data);
echo view('layout/header', $data);
echo view('DashBoard', $data);

View File

@ -2199,33 +2199,39 @@ class EmployeeController extends AdminController
}
}
//UPDATE EMPLOYEE
public function update_emp_data()
{
$data = $this->request->getPost();
// print_rr($data);die();
// $data['dob'] = date('Y-m-d', strtotime($data['dob']));
$data['dob'] = change_date_format($data['dob'], 'd/m/Y', 'Y-m-d');
if (isset($data['dob'])) {
$data['dob'] = change_date_format($data['dob'], null, 'Y-m-d');
}
// print_rr($data); die;
// Fetch current employee data
$employee_data = $this->employeeModel->where('id', $data['employee_primary_id'])->first();
if ($employee_data['relationship'] == 'Self') {
if ($employee_data['gender'] != $data['gender']) {
if (isset($data['gender'])) {
$spouse_gender = ($data['gender'] == 'M') ? 'F' : 'M';
$this->employeeModel
->where('emp_code', $employee_data['emp_code'])
->where('relationship', 'Spouse')
->set(['gender' => $spouse_gender])
->update();
if ($employee_data['gender'] != $data['gender']) {
$spouse_gender = ($data['gender'] == 'M') ? 'F' : 'M';
$this->employeeModel
->where('emp_code', $employee_data['emp_code'])
->where('relationship', 'Spouse')
->set(['gender' => $spouse_gender])
->update();
}
}
}
// Update the employee data
$result = $this->employeeModel->where('id', $data['employee_primary_id'])->set($data)->update();
if ($result) {
return $this->respond(['status' => true, 'code' => 200, 'data' => $data, 'message' => 'Employee updated successfully'], 200);
} else {
@ -2688,7 +2694,7 @@ class EmployeeController extends AdminController
$emp_history['created_at'] = date("d-m-Y H:i:s", strtotime($emp_history['created_at']));
}
unset($emp_history);
$emp_pol_pk = $this->employeePolicyModel->select('id')->where('employee_id',$emp_id)->first()['id'];

View File

@ -544,6 +544,10 @@ if (!function_exists('change_date_format')) {
'Y/m/d', // 2024/12/01
'Y.m.d', // 2024.12.01
'Y,m,d', // 2024,12,01
'd/m/Y', // 01/01/2025
'd-m-Y', // 01-01-2025
];
try {

File diff suppressed because it is too large Load Diff