From bf0b4c3d2ba187e27e906c945e12799eeae93395 Mon Sep 17 00:00:00 2001 From: velz Date: Fri, 17 May 2024 14:32:59 +0530 Subject: [PATCH 1/5] CHNAGE_GMC_PARENT_WITH_SELF_HANDLED&AMT_IN_FILELIST --- app/Controllers/EmployeeController.php | 39 ++++++++++++++++--- app/Controllers/EmployeeServiceController.php | 14 ++++--- app/Controllers/JobWorker.php | 2 +- app/Helpers/utility_helper.php | 32 ++++++++++++++- app/Models/ClientModel.php | 3 +- app/Views/employee_upload.php | 3 +- app/Views/file_list.php | 9 ++++- 7 files changed, 83 insertions(+), 19 deletions(-) diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 0a346146..b93c9105 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -216,13 +216,40 @@ class EmployeeController extends AdminController $data['import_or_export'] = ['import' => 'Import', 'export' => 'Export']; $data['insurer_or_tpa'] = ['insurer' => 'Insurer', 'tpa' => 'TPA']; + // $data['fileList'] = $this->fileModel + // ->select(['files.*', 'up.emp_code', 'up.first_name', 'pm.name as policy_name', 'c.short_name', 'cp.id as client_policy_id']) + // ->join('user_profiles up', 'files.created_by = up.id') + // ->join('client_policy cp', 'files.policy_id = cp.id', 'left') + // ->join('policies pm', 'cp.policy_id = pm.id', 'left') + // ->join('clients c', 'files.client_id = c.id and files.client_id = cp.client_id', 'left') + // ->where('files.created_by', get_session_userid())->orderBy('files.created_at', 'desc')->findAll(); + // dd($this->fileModel->getLastQuery()); + $data['fileList'] = $this->fileModel - ->select(['files.*', 'up.emp_code', 'up.first_name', 'pm.name as policy_name', 'c.short_name', 'cp.id as client_policy_id']) - ->join('user_profiles up', 'files.created_by = up.id') - ->join('client_policy cp', 'files.policy_id = cp.id', 'left') - ->join('policies pm', 'cp.policy_id = pm.id', 'left') - ->join('clients c', 'files.client_id = c.id and files.client_id = cp.client_id', 'left') - ->where('files.created_by', get_session_userid())->orderBy('files.created_at', 'desc')->findAll(); + ->select([ + 'files.*', + 'up.emp_code', + 'up.first_name', + 'pm.name as policy_name', + 'c.short_name', + 'cp.id as client_policy_id', + '(SELECT COUNT(*) + FROM employees e + JOIN employee_polices ep ON e.id = ep.employee_id + WHERE e.file_id = files.id AND ep.client_policy_id = files.policy_id) as employee_count', + '(SELECT SUM(ep.rata_premimum) + SUM(ep.gst) + FROM employees e + JOIN employee_polices ep ON e.id = ep.employee_id + WHERE e.file_id = files.id AND ep.client_policy_id = files.policy_id) as total' + ]) + ->join('user_profiles up', 'files.created_by = up.id') + ->join('client_policy cp', 'files.policy_id = cp.id', 'left') + ->join('policies pm', 'cp.policy_id = pm.id', 'left') + ->join('clients c', 'files.client_id = c.id and files.client_id = cp.client_id', 'left') + ->where('files.created_by', get_session_userid()) + ->orderBy('files.created_at', 'desc') + ->findAll(); + // dd($data['fileList']); $data['batch_list'] = $this->batchFileModel->select('batch_files.*, policies.name as policy_name, clients.short_name as client_short_name') ->join('client_policy', 'client_policy.id = batch_files.client_policy_id') diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index 085c2727..70c1caf2 100644 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -143,7 +143,7 @@ class EmployeeServiceController extends AdminController $policy_details = $this->clientPolicyModel->getPolicyDetails($file['client_id'],$file['policy_id']); $policy_terms = json_decode($policy_details[0]->policy_terms); $policy_terms = (array) $policy_terms;// convert obj to array - $default_age_ratio = isset($policy_details[0]->age_ratio) ? json_decode($policy_details[0]->age_ratio) : []; + $default_age_ratio = isset($policy_terms['age_ratio']) ? json_decode(json_encode($policy_terms['age_ratio']),true) : []; // // dd($default_age_ratio); @@ -376,26 +376,28 @@ class EmployeeServiceController extends AdminController } } - if(($file['action'] == 'inception' || $file['action'] == 'addition' || $file['action'] == 'dependent_addition') && ($policy_details['policy_type_id'] != 3)) // 3 is GMC parents (base policy or dep addon) + //check self availbale in uploaded file + if(($file['action'] == 'inception' || $file['action'] == 'addition') && ($policy_details['policy_type_id'] == 3 && $policy_details['base_policy'] == null)) // 3 is GMC parents dep addon) { + // dd('file check'); $res = check_self_available_in_family($family,$file['action']); // dd($res); if(!$res['is_self_found']) { array_push($result['error_summary'],14); // Self not found - $result['error_data'][ $res['row_id'] ]['sno']['error'][] = "Self not found "; + $result['error_data'][ $res['row_id'] ]['sno']['error'][] = "Self not found in uploaded file"; } } - //check self avaialbe where self data is not available either in excel or same policy (i.e.) gMC parents - if($policy_details['policy_type_id'] == 3) // 3 is GMC parents (base policy or dep addon) + //check self avaialbe where self data is not available either same policy (i.e.) gMC parents + if($file['action'] == 'dependent_addition' || ($policy_details['policy_type_id'] == 3 && $policy_details['base_policy'] == null)) // 3 is GMC parents as base policy not as dep addon) { $self_details = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $emp_id,client_id: $file['client_id'],emp_status: ['active'],policy_status:['active']); // dd($self_details); if(!count($self_details)) { array_push($result['error_summary'],14); // Self not found - $result['error_data'][ $family[0][0] ]['sno']['error'][] = "Self not found "; + $result['error_data'][ $family[0][0] ]['sno']['error'][] = "Self not found in System"; } } diff --git a/app/Controllers/JobWorker.php b/app/Controllers/JobWorker.php index 8d81699f..7b26d8cb 100644 --- a/app/Controllers/JobWorker.php +++ b/app/Controllers/JobWorker.php @@ -185,7 +185,7 @@ class JobWorker extends AdminController //die(); $job_status = self::STATUS_FAILED; $runtime = $runtime === null ? microtime(true) - $start : $runtime; - $response = $e->getMessage(); + $response = ['file_name' => $e->getFile(),'error' => $e->getMessage(),'line_no' => $e->getLine(),'info' => $e->getTraceAsString()]; } $db->query("UPDATE jobs SET status=?, run_time=?, response=? WHERE id=? AND uuid=?", [ diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php index 220f06f6..eaa72ce7 100644 --- a/app/Helpers/utility_helper.php +++ b/app/Helpers/utility_helper.php @@ -185,6 +185,36 @@ if (!function_exists('get_base64_image')) { } - +if (!function_exists('format_indian_number')) { + function format_indian_number($number) { + // Round the number to two decimal places + $number = round($number, 2); + + // Split the number into integer and decimal parts + $numberParts = explode('.', number_format($number, 2, '.', '')); + $integerPart = $numberParts[0]; + $decimalPart = isset($numberParts[1]) ? $numberParts[1] : '00'; + + // Format the integer part with commas + $length = strlen($integerPart); + $formattedStr = ''; + $counter = 0; + + for ($i = $length - 1; $i >= 0; $i--) { + $formattedStr = $integerPart[$i] . $formattedStr; + $counter++; + if ($counter == 3 && $i != 0) { + $formattedStr = ',' . $formattedStr; + $counter = 0; + } elseif ($counter == 2 && $i != 0 && $length - $i > 3) { + $formattedStr = ',' . $formattedStr; + $counter = 0; + } + } + + // Combine the integer and decimal parts + return $formattedStr . '.' . $decimalPart; + } +} diff --git a/app/Models/ClientModel.php b/app/Models/ClientModel.php index 27b48bc9..193b9b71 100644 --- a/app/Models/ClientModel.php +++ b/app/Models/ClientModel.php @@ -41,8 +41,9 @@ class ClientModel extends Model foreach ($clients as &$client) { $clientPolicyModel = new ClientPolicyModel(); - $clientPolicies = $clientPolicyModel->select(['client_policy.id','p.name']) + $clientPolicies = $clientPolicyModel->select(['client_policy.id','p.name','pt.policy_type']) ->join('policies p', 'p.id = client_policy.policy_id') + ->join('policy_type pt','client_policy.policy_type_id = pt.id') ->where('client_policy.client_id',$client['id']) ->where('client_policy.is_active', 1) ->where('client_policy.policy_status', 1) diff --git a/app/Views/employee_upload.php b/app/Views/employee_upload.php index 64cbca65..9f996fe2 100644 --- a/app/Views/employee_upload.php +++ b/app/Views/employee_upload.php @@ -476,11 +476,10 @@ function appendPolicies(data) { value: '', text: 'Select' })); - $.each(data, function(index, item) { $('#policy_id').append($('