diff --git a/.gitignore b/.gitignore index 1f8cb67a..2e2d6962 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,9 @@ writable/debugbar/* writable/**/*.db writable/**/*.sqlite +writable/e_card_template/* +!writable/e_card_template/.gitkeep + vendor/ build/ diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 54f6a1f1..5b210e39 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -770,18 +770,18 @@ class ClientController extends AdminController $policy_type = $this->request->getPost('policy_type'); $client_id = $this->request->getPost('client_id'); $client_policy_id = $this->request->getPost('client_policy_id'); - // $premium_type = $this->request->getPost('premium_type'); + $premium_type = $this->request->getPost('premium_type'); if (!empty($client_id) && $client_id != null) { $client_policy_data = $this->clientPolicyModel->where('id', $client_policy_id)->first(); $client_id = $client_policy_data['client_id']; } $policy_grid_id = $this->request->getPost('policy_grid_id'); - if($policy_grid_id == 10 || $policy_grid_id == 11){ - $premium_type = 1; - }else{ - $premium_type = 2; - } + // if($policy_grid_id == 10 || $policy_grid_id == 11){ + // $premium_type = 1; + // }else{ + // $premium_type = 2; + // } $si_or_bp = $this->request->getPost('si_or_bp'); $basic_multiplier = str_replace(',', '', $this->request->getPost('basic_multiplier')); @@ -1122,15 +1122,18 @@ class ClientController extends AdminController ->join('employee_polices ep', "cp.id = ep.client_policy_id AND employees.id = ep.employee_id") ->where("employees.client_id", $record['client_id']) ->where("employees.emp_status", 'active') + ->where("ep.status", 'active') + ->where("employees.is_active", 1) + ->where("ep.is_active", 1) ->countAllResults(); - $data = $this->employeePolicyModel->select('employee_polices.id') - ->where('employee_polices.is_active', 1) - ->where('employee_polices.client_policy_id', $client_policy_id) - ->findAll(); + // $data = $this->employeePolicyModel->select('employee_polices.id') + // ->where('employee_polices.is_active', 1) + // ->where('employee_polices.client_policy_id', $client_policy_id) + // ->findAll(); - $emp_count = count($data); + // $emp_count = count($data); // if($emp_count == 0){ // $emp_count = true; @@ -1176,24 +1179,25 @@ class ClientController extends AdminController if ($search_term === 'GMC') { - $resultss = []; + // $resultss = []; + $resultss = $results; - try { - foreach ($results as $index => $record) { - // if ($self->self == 1 && $self->spouse == 0 && $self->childrens == 0 && $self->parents == 0 && $self->{'parents-in-law'} == 0 && $self->{'either-parents-pil'} == 0 && $family_floater == 0) { - if ($family_floater == 1) { - if ($index == '7' || $index == '8' || $index == '9' || $index == '10') { - $resultss[$index] = $record; - } - } else { - if ($index == '0' || $index == '1' || $index == '2' || $index == '3' || $index == '4' || $index == '5' || $index == '6') { - $resultss[$index] = $record; - } - } - } - } catch (\Exception $e) { - $resultss = $results; // Reset $resultss to an empty array if an exception occurs - } + // try { + // foreach ($results as $index => $record) { + // // if ($self->self == 1 && $self->spouse == 0 && $self->childrens == 0 && $self->parents == 0 && $self->{'parents-in-law'} == 0 && $self->{'either-parents-pil'} == 0 && $family_floater == 0) { + // if ($family_floater == 1) { + // if ($index == '7' || $index == '8' || $index == '9' || $index == '10') { + // $resultss[$index] = $record; + // } + // } else { + // if ($index == '0' || $index == '1' || $index == '2' || $index == '3' || $index == '4' || $index == '5' || $index == '6') { + // $resultss[$index] = $record; + // } + // } + // } + // } catch (\Exception $e) { + // $resultss = $results; // Reset $resultss to an empty array if an exception occurs + // } diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index b0814d11..69f19725 100644 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -960,6 +960,7 @@ class EmpDataServiceController extends BaseController $file_id = $params['file_id']; $file = $this->batchFileModel->find($file_id); if (!$file) { + $data = [ 'status' => 'failed-4', ]; @@ -980,6 +981,15 @@ class EmpDataServiceController extends BaseController $batch_code = $file['batch_code']; $user_id = $file['created_by']; + + $get_policy_type = $this->clientPolicyModel + ->select('policy_type.policy_type, policies.policy_type_id as policy_type_id') + ->join('policies', 'policies.id = client_policy.policy_id') + ->join('policy_type', 'policy_type.id = policies.policy_type_id') + ->where('client_policy.id', $client_policy_id) + ->first(); + + $status_val = 'success'; if ($status == 'in-progress-partially') { @@ -995,16 +1005,21 @@ class EmpDataServiceController extends BaseController array_pop($excel_data); // Remove footer row $totals = 0; - $empty_emp_tpa_uh_ids = []; + $emp_policy_ids = []; + $emp_details = []; + $tpa_id = []; + $uhid = []; + $emp_count = count($excel_data); $db = \Config\Database::connect(); + foreach ($excel_data as $key => $value) { $name = $value[1]; $emp_code = $value[2]; - $tpa_id = $value[15]; - $uhid = $value[16]; + $tpa_id[] = $value[15]; + $uhid[] = $value[16]; $amount = $value[20]; $totals += $amount; @@ -1031,38 +1046,41 @@ class EmpDataServiceController extends BaseController // Get the result $result = $query->get()->getRowArray(); if (isset($result['id']) && $result['id'] !== null) { - $empty_emp_tpa_uh_ids[] = $result['id']; + $emp_policy_ids[] = $result['id']; + $emp_details[] = array('id' => $result['id'],'tpa_id' => $value[15], 'uhid' => $value[16]); } - $sql = " - UPDATE employee_polices - JOIN employees ON employees.id = employee_polices.employee_id - SET tpa_id = ? - WHERE employees.name = ? - AND employees.emp_code = ? - AND employee_polices.client_policy_id = ? - AND (employee_polices.tpa_id IS NULL OR employee_polices.tpa_id = '')"; + // $sql = " + // UPDATE employee_polices + // JOIN employees ON employees.id = employee_polices.employee_id + // SET tpa_id = ? + // WHERE employees.name = ? + // AND employees.emp_code = ? + // AND employee_polices.client_policy_id = ? + // AND (employee_polices.tpa_id IS NULL OR employee_polices.tpa_id = '')"; - $params = [$tpa_id, $name, $emp_code, $client_policy_id]; - $db->query($sql, $params); + // $params = [$tpa_id, $name, $emp_code, $client_policy_id]; + // $db->query($sql, $params); - $sql = " - UPDATE employee_polices - JOIN employees ON employees.id = employee_polices.employee_id - SET employee_polices.uhid = ? - WHERE employees.name = ? - AND employees.emp_code = ? - AND employee_polices.client_policy_id = ? - AND (employee_polices.uhid IS NULL OR employee_polices.uhid = '')"; + // $sql = " + // UPDATE employee_polices + // JOIN employees ON employees.id = employee_polices.employee_id + // SET employee_polices.uhid = ? + // WHERE employees.name = ? + // AND employees.emp_code = ? + // AND employee_polices.client_policy_id = ? + // AND (employee_polices.uhid IS NULL OR employee_polices.uhid = '')"; - $params = [$uhid, $name, $emp_code, $client_policy_id]; - $db->query($sql, $params); + // $params = [$uhid, $name, $emp_code, $client_policy_id]; + // $db->query($sql, $params); } + $return = $this->employeePolicyModel->bulkUpdate($emp_details); + // Update batch file status and amount $this->batchFileModel->update($file_id, [ 'count' => $emp_count, @@ -1076,14 +1094,13 @@ class EmpDataServiceController extends BaseController $this->myLogger->logme('error', 'importInceptionUpdateTPAandUHID total amount for cash deposite : {data}', ['data'=> $totals]); - if ($file['insurer_or_tpa'] == 'tpa') { $this->myLogger->logme('error', 'importInceptionUpdateTPAandUHID set cashDepositCalculationForInception and sendMailForDownloadingECard in JOB QUEUE'); $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id); $depositeData = [ - 'employeeIds' => $empty_emp_tpa_uh_ids, + 'employeeIds' => $emp_policy_ids, 'client_id' => $client_id, 'client_policy_id' => $client_policy_id, 'count' => $emp_count, @@ -1096,7 +1113,7 @@ class EmpDataServiceController extends BaseController $job_details = new Jobs(); $r = Jobs::addJob(['job_name' => 'cashDepositCalculationForInception','payload' => [ - 'employeeIds' => $empty_emp_tpa_uh_ids, + 'employeeIds' => $emp_policy_ids, 'client_id' => $client_id, 'client_policy_id' => $client_policy_id, 'count' => $emp_count, @@ -1105,18 +1122,22 @@ class EmpDataServiceController extends BaseController 'user_id' => $user_id, ]]); + if($get_policy_type['policy_type_id'] != 1){ - $job_details = new Jobs(); - $r = Jobs::addJob(['job_name' => 'sendMailForDownloadingECard','payload' => $empty_emp_tpa_uh_ids]); + $job_details = new Jobs(); + $r = Jobs::addJob(['job_name' => 'sendMailForDownloadingECard','payload' => $emp_policy_ids]); + + } // $this->cashDepositCalculationForInception($depositeData); - // $this->sendMailForDownloadingECard($empty_emp_tpa_uh_ids); + // $this->sendMailForDownloadingECard($emp_policy_ids); } $file_data = $this->getDataByFileId($file_id, 'success'); $this->setPullNotification($file_data); + return 'Import Inception Updated '. $status_val . '- Updated Count : ' . $emp_count; } diff --git a/app/Controllers/PendingActionsController.php b/app/Controllers/PendingActionsController.php index 457b06b9..2e4bb8e8 100644 --- a/app/Controllers/PendingActionsController.php +++ b/app/Controllers/PendingActionsController.php @@ -122,9 +122,28 @@ class PendingActionsController extends AdminController public function getPendingActionForCorrection() { + // Subquery for batch_export_count + $subQueryExport = $this->db->table('batch_files bl') + ->select('COUNT(*)') + ->where('bl.client_id = clients.id') + ->where('bl.actions', 'export') + ->where('bl.event_type', 'correction') + ->where('bl.insurer_or_tpa', 'tpa') + ->getCompiledSelect(); + + // Subquery for batch_import_count + $subQueryImport = $this->db->table('batch_files bl') + ->select('COUNT(*)') + ->where('bl.client_id = clients.id') + ->where('bl.actions', 'import') + ->where('bl.event_type', 'correction') + ->where('bl.insurer_or_tpa', 'tpa') + ->where('bl.status', 'success') + ->getCompiledSelect(); + // Subquery builder $subqueryBuilder = $this->db->table('emp_endorsement') - ->select(' + ->select(' clients.client_name as client_name, clients.id as client_id, @@ -139,7 +158,7 @@ class PendingActionsController extends AdminController emp_endorsement.status, employees.name as ename ') - ->join('employees', 'emp_endorsement.pk = employees.id AND employees.is_active = 1 AND employees.emp_status = \'active\'') + ->join('employees', 'emp_endorsement.pk = employees.id AND employees.is_active = 1 AND employees.emp_status = \'active\'') ->join('clients', 'employees.client_id = clients.id AND clients.is_active = 1', 'left') ->where([ 'emp_endorsement.actions' => 'c', @@ -151,10 +170,13 @@ class PendingActionsController extends AdminController // Main query builder $builder = $this->db->table('clients'); - $builder->select(' + $builder->select(" subquery.client_name, subquery.client_id, - COUNT(subquery.id) AS subquery_count'); + COUNT(subquery.id) AS subquery_count, + ($subQueryExport) AS batch_export_count, + ($subQueryImport) AS batch_import_count + "); $builder->join('(' . $subqueryBuilder->getCompiledSelect() . ') AS subquery', 'clients.id = subquery.client_id', 'left'); $builder->groupBy('clients.id'); @@ -165,7 +187,7 @@ class PendingActionsController extends AdminController $results = $query->getResultArray(); - $filteredResults = array_filter($results, function($value) { + $filteredResults = array_filter($results, function ($value) { return $value['subquery_count'] != 0; }); @@ -176,9 +198,29 @@ class PendingActionsController extends AdminController public function getPendingActionForSIEnhancement() { + // Subquery for batch_export_count + $subQueryExport = $this->db->table('batch_files bl') + ->select('COUNT(*)') + ->where('bl.client_id = clients.id') + ->where('bl.actions', 'export') + ->where('bl.event_type', 'si_enhancement') + ->where('bl.insurer_or_tpa', 'tpa') + ->getCompiledSelect(); + + // Subquery for batch_import_count + $subQueryImport = $this->db->table('batch_files bl') + ->select('COUNT(*)') + ->where('bl.client_id = clients.id') + ->where('bl.actions', 'import') + ->where('bl.event_type', 'si_enhancement') + ->where('bl.insurer_or_tpa', 'tpa') + ->where('bl.status', 'success') + ->getCompiledSelect(); + + // Build the subquery $subqueryBuilder = $this->db->table('emp_endorsement') - ->select(' + ->select(' clients.client_name as client_name, clients.id as client_id, client_policy.id as client_policy_id, @@ -194,7 +236,7 @@ class PendingActionsController extends AdminController emp_endorsement.name, emp_endorsement.status ') - ->join('employee_polices', 'emp_endorsement.pk = employee_polices.id AND employee_polices.is_active = 1 AND employee_polices.status = \'active\'') + ->join('employee_polices', 'emp_endorsement.pk = employee_polices.id AND employee_polices.is_active = 1 AND employee_polices.status = \'active\'') ->join('client_policy', 'employee_polices.client_policy_id = client_policy.id AND client_policy.is_active = 1 AND client_policy.policy_status = 1') ->join('clients', 'client_policy.client_id = clients.id AND clients.is_active = 1') ->join('policies', 'client_policy.policy_id = policies.id AND policies.is_active = 1') @@ -208,13 +250,16 @@ class PendingActionsController extends AdminController // Build the main query $builder = $this->db->table('clients'); - $builder->select(' + $builder->select(" clients.id, subquery.client_name, subquery.client_id, subquery.client_policy_id, subquery.policy_name, - COUNT(subquery.id) AS subquery_count'); + COUNT(subquery.id) AS subquery_count, + ($subQueryExport) AS batch_export_count, + ($subQueryImport) AS batch_import_count + "); $builder->join('(' . $subqueryBuilder->getCompiledSelect() . ') AS subquery', 'clients.id = subquery.client_id', 'left'); $builder->groupBy('clients.id'); @@ -225,7 +270,7 @@ class PendingActionsController extends AdminController $results = $query->getResultArray(); - $filteredResults = array_filter($results, function($value) { + $filteredResults = array_filter($results, function ($value) { return $value['subquery_count'] != 0; }); @@ -236,9 +281,29 @@ class PendingActionsController extends AdminController public function getPendingActionForDeletion() { + + // Subquery for batch_export_count + $subQueryExport = $this->db->table('batch_files bl') + ->select('COUNT(*)') + ->where('bl.client_id = clients.id') + ->where('bl.actions', 'export') + ->where('bl.event_type', 'deletion') + ->where('bl.insurer_or_tpa', 'insurer') + ->getCompiledSelect(); + + // Subquery for batch_import_count + $subQueryImport = $this->db->table('batch_files bl') + ->select('COUNT(*)') + ->where('bl.client_id = clients.id') + ->where('bl.actions', 'import') + ->where('bl.event_type', 'deletion') + ->where('bl.insurer_or_tpa', 'insurer') + ->where('bl.status', 'success') + ->getCompiledSelect(); + // Build the subquery $subqueryBuilder = $this->db->table('emp_endorsement') - ->select(' + ->select(' clients.client_name as client_name, clients.id as client_id, client_policy.id as client_policy_id, @@ -253,28 +318,31 @@ class PendingActionsController extends AdminController emp_endorsement.name, emp_endorsement.status ') - ->join('employee_polices', 'emp_endorsement.pk = employee_polices.id AND employee_polices.is_active = 1 AND employee_polices.status = \'active\' AND emp_endorsement.table_name = \'employee_polices\'', 'left') - ->join('client_policy', 'employee_polices.client_policy_id = client_policy.id AND client_policy.is_active = 1 AND client_policy.policy_status = 1', 'left') - ->join('clients', 'client_policy.client_id = clients.id AND clients.is_active = 1', 'left') - ->join('policies', 'client_policy.policy_id = policies.id AND policies.is_active = 1', 'left') - ->where([ - 'emp_endorsement.actions' => 'd', - 'emp_endorsement.is_active' => 1, - 'emp_endorsement.status' => 'pending', - 'emp_endorsement.endorsement_id' => null, - 'emp_endorsement.table_name' => 'employee_polices' - ]) + ->join('employee_polices', 'emp_endorsement.pk = employee_polices.id AND employee_polices.is_active = 1 AND employee_polices.status = \'active\' AND emp_endorsement.table_name = \'employee_polices\'', 'left') + ->join('client_policy', 'employee_polices.client_policy_id = client_policy.id AND client_policy.is_active = 1 AND client_policy.policy_status = 1', 'left') + ->join('clients', 'client_policy.client_id = clients.id AND clients.is_active = 1', 'left') + ->join('policies', 'client_policy.policy_id = policies.id AND policies.is_active = 1', 'left') + ->where([ + 'emp_endorsement.actions' => 'd', + 'emp_endorsement.is_active' => 1, + 'emp_endorsement.status' => 'pending', + 'emp_endorsement.endorsement_id' => null, + 'emp_endorsement.table_name' => 'employee_polices' + ]) ->groupBy('emp_endorsement.pk, emp_endorsement.emp_code, emp_endorsement.actions, emp_endorsement.name'); // Build the main query $builder = $this->db->table('clients'); - $builder->select(' + $builder->select(" clients.id, subquery.client_name, subquery.client_id, subquery.client_policy_id, subquery.policy_name, - COUNT(subquery.id) AS subquery_count'); + COUNT(subquery.id) AS subquery_count, + ($subQueryExport) AS batch_export_count, + ($subQueryImport) AS batch_import_count + "); $builder->join('(' . $subqueryBuilder->getCompiledSelect() . ') AS subquery', 'clients.id = subquery.client_id', 'left'); $builder->groupBy('clients.id'); @@ -284,7 +352,7 @@ class PendingActionsController extends AdminController // Fetch the results $results = $query->getResultArray(); - $filteredResults = array_filter($results, function($value) { + $filteredResults = array_filter($results, function ($value) { return $value['subquery_count'] != 0; }); @@ -294,26 +362,43 @@ class PendingActionsController extends AdminController public function getPendingActionForUHIDEmpty() { - // Build the query - $builder = $this->db->table('employee_polices'); - $builder->select(' - employee_polices.client_policy_id, - employee_polices.uhid, - clients.short_name, - clients.client_name, - policies.name as policy_name, - clients.id as client_id - '); - $builder->join('client_policy', 'employee_polices.client_policy_id = client_policy.id AND client_policy.is_active = 1 AND client_policy.policy_status = 1'); - $builder->join('clients', 'clients.id = client_policy.client_id'); - $builder->join('policies', 'policies.id = client_policy.policy_id'); - $builder->where('employee_polices.uhid', null); - $builder->where('employee_polices.status', 'active'); - $builder->where('employee_polices.is_active', 1); - $builder->groupBy('employee_polices.client_policy_id'); + // Subquery for batch_export_count + $subQueryExport = $this->db->table('batch_files bl') + ->select('COUNT(*)') + ->where('bl.client_policy_id = cp.id') + ->where('bl.actions', 'export') + ->where('bl.event_type', 'inception') + ->where('bl.insurer_or_tpa', 'insurer') + ->getCompiledSelect(); - // Execute the query - $query = $builder->get(); + // Subquery for batch_import_count + $subQueryImport = $this->db->table('batch_files bl') + ->select('COUNT(*)') + ->where('bl.client_policy_id = cp.id') + ->where('bl.actions', 'import') + ->where('bl.event_type', 'inception') + ->where('bl.insurer_or_tpa', 'insurer') + ->where('bl.status', 'success') + ->getCompiledSelect(); + + // Main query + $query = $this->db->table('employee_polices ep') + ->select('c.id as client_id') + ->select('ep.client_policy_id') + ->select('c.client_name') + ->select('c.short_name') + ->select('p.name as policy_name') + ->select('ep.uhid') + ->select("($subQueryExport) AS batch_export_count", false) + ->select("($subQueryImport) AS batch_import_count", false) + ->join('client_policy cp', 'ep.client_policy_id = cp.id AND cp.is_active = 1 AND cp.policy_status = 1') + ->join('clients c', 'c.id = cp.client_id') + ->join('policies p', 'p.id = cp.policy_id') + ->where('ep.uhid IS NULL') + ->where('ep.status', 'active') + ->where('ep.is_active', 1) + ->groupBy('ep.client_policy_id, ep.uhid, c.short_name, p.name') + ->get(); // Fetch the results $results = $query->getResultArray(); @@ -325,6 +410,25 @@ class PendingActionsController extends AdminController public function getPendingActionForTPAIDEmpty() { + // Subquery for batch_export_count + $subQueryExport = $this->db->table('batch_files bl') + ->select('COUNT(*)') + ->where('bl.client_policy_id = client_policy.id') + ->where('bl.actions', 'export') + ->where('bl.event_type', 'inception') + ->where('bl.insurer_or_tpa', 'tpa') + ->getCompiledSelect(); + + // Subquery for batch_import_count + $subQueryImport = $this->db->table('batch_files bl') + ->select('COUNT(*)') + ->where('bl.client_policy_id = client_policy.id') + ->where('bl.actions', 'import') + ->where('bl.event_type', 'inception') + ->where('bl.insurer_or_tpa', 'tpa') + ->where('bl.status', 'success') + ->getCompiledSelect(); + // Build the query $builder = $this->db->table('employee_polices'); $builder->select(' @@ -337,6 +441,9 @@ class PendingActionsController extends AdminController policies.name as policy_name, clients.id as client_id '); + $builder->select("($subQueryExport) AS batch_export_count", false); + $builder->select("($subQueryImport) AS batch_import_count", false); + $builder->join('client_policy', 'employee_polices.client_policy_id = client_policy.id AND client_policy.is_active = 1 AND client_policy.policy_status = 1'); $builder->join('clients', 'clients.id = client_policy.client_id'); $builder->join('policies', 'policies.id = client_policy.policy_id'); diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php index eaa72ce7..5a1ea319 100644 --- a/app/Helpers/utility_helper.php +++ b/app/Helpers/utility_helper.php @@ -218,3 +218,23 @@ if (!function_exists('format_indian_number')) { } +if (!function_exists('get_username')) { + function get_username($user_id) { + // Connect to the database + $db = \Config\Database::connect(); + + // Query the database + $query = $db->table('user_profiles') + ->select('first_name') + ->where('id', $user_id) + ->get(); + + // Get the result + $result = $query->getRow(); + + // Return the username if found, otherwise return null + return $result ? $result->first_name : null; + } +} + + diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 852fcb1b..217e2013 100644 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -790,4 +790,69 @@ class EmployeePolicyModel extends Model } + public function bulkUpdate($emp_details) + { + // Extract IDs, tpa_ids, and uhids + $ids = array_column($emp_details, 'id'); + $tpa_ids = array_column($emp_details, 'tpa_id'); + $uhids = array_column($emp_details, 'uhid'); + + // Escape values for SQL + $escapedIds = array_map([$this->db, 'escape'], $ids); + $escapedTpaIds = array_map([$this->db, 'escape'], $tpa_ids); + $escapedUhids = array_map([$this->db, 'escape'], $uhids); + + // Construct the CASE statements + $caseTpaId = array_map(function($id, $tpa_id) { + return "WHEN id = $id THEN $tpa_id"; + }, $escapedIds, $escapedTpaIds); + + $caseUhid = array_map(function($id, $uhid) { + return "WHEN id = $id THEN $uhid"; + }, $escapedIds, $escapedUhids); + + // Convert cases to a string + $caseTpaIdString = implode(' ', $caseTpaId); + $caseUhidString = implode(' ', $caseUhid); + + // Convert ids to a string + $idsString = implode(', ', $escapedIds); + + // Construct the SQL query + $sql = " + UPDATE {$this->table} + SET + tpa_id = CASE {$caseTpaIdString} END, + uhid = CASE {$caseUhidString} END + WHERE id IN ({$idsString}) + "; + + // Begin a transaction + $this->db->transBegin(); + + try { + // Execute the query + $this->db->query($sql); + + // Commit the transaction + if ($this->db->transStatus() === FALSE) { + // If something went wrong, rollback + $this->db->transRollback(); + throw new \Exception('Bulk update failed.'); + } else { + // Otherwise, commit + $this->db->transCommit(); + } + + return $this->db->getLastQuery(); + + } catch (\Exception $e) { + // Rollback the transaction on error + $this->db->transRollback(); + throw $e; + } + } + + + } \ No newline at end of file diff --git a/app/Views/batch_list.php b/app/Views/batch_list.php index 1ba623f7..335818bf 100644 --- a/app/Views/batch_list.php +++ b/app/Views/batch_list.php @@ -1,11 +1,11 @@