FIX_SI_ENCHMT_ISSUE : RV
This commit is contained in:
parent
d6bfd563ad
commit
4fadc65f7f
@ -4627,8 +4627,9 @@ class ClientController extends AdminController
|
||||
// $ids = array_column($emp_data, 'id');
|
||||
// $EmpDataServiceController->sendMailForDownloadingECard($ids);
|
||||
|
||||
// $EmpDataServiceController = new EmpDataServiceController();
|
||||
$EmpDataServiceController = new EmpDataServiceController();
|
||||
// $EmpDataServiceController->importDeletionValidation(['file_id' => 304]); //for live
|
||||
// $EmpDataServiceController->importSIEnhancementUpdateEndorsementID(['file_id' => 1199]); //for live
|
||||
|
||||
// $result = $this->employeePolicyModel->getDeletionEmployeeDataForExportExcel($batch_data);
|
||||
// print_rr($result); die;
|
||||
|
||||
@ -2950,7 +2950,7 @@ class EmpDataServiceController extends BaseController
|
||||
|
||||
$empData['basic_cover_si'] = $value[8];
|
||||
$empData['premium'] = $value[14];
|
||||
$empData['si_enhancement_date'] = $value[10];
|
||||
$empData['si_enhancement_date'] = date('Y-m-d', strtotime($value[10])) ?? null;
|
||||
$empData['rata_premimum'] = $value[16];
|
||||
$empData['gst'] = $value[17];
|
||||
$empData['created_by'] = $user_id;
|
||||
@ -2964,26 +2964,20 @@ class EmpDataServiceController extends BaseController
|
||||
|
||||
$this->employeePolicyModel->updateBatch($emp_policy_ids, 'id');
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
$db->transStart();
|
||||
|
||||
$this->employeePolicyModel->insertBatch($emp_details);
|
||||
// $this->employeePolicyModel->insertBatch($emp_details);
|
||||
// $insertedIds = [];
|
||||
// $startId = $db->insertID(); // Get the first inserted ID
|
||||
|
||||
// for ($i = 0; $i < count($emp_details); $i++) {
|
||||
// $insertedIds[] = $startId + $i;
|
||||
// }
|
||||
|
||||
$insertedIds = [];
|
||||
$startId = $db->insertID(); // Get the first inserted ID
|
||||
|
||||
for ($i = 0; $i < count($emp_details); $i++) {
|
||||
$insertedIds[] = $startId + $i;
|
||||
foreach ($emp_details as $emp) {
|
||||
$insertedIds[] = $this->employeePolicyModel->insert($emp);
|
||||
}
|
||||
|
||||
$db->transComplete();
|
||||
|
||||
// if ($db->transStatus() === FALSE) {
|
||||
// // Handle the error, rollback, etc.
|
||||
// } else {
|
||||
// // Transaction successful
|
||||
// print_r($insertedIds); // This will print the array of inserted IDs
|
||||
// }
|
||||
// dd($insertedIds);
|
||||
|
||||
$this->employeePolicyModel->bulkUpdateForEndorsement($endorsement_details);
|
||||
$this->storeEndorsementNumber($file_id, $endorsement_id, $enrollment_file_id);
|
||||
|
||||
@ -1530,8 +1530,21 @@ class EmployeeServiceController extends AdminController
|
||||
break;
|
||||
}
|
||||
// echo '<br>START- ' . $row[2];
|
||||
$employee = $this->employeeModel->where('emp_code', $row[1])->where('name',$row[2])->where('client_id',$file['client_id'])->where('client_branch_id',$file['client_branch_id'])->first();
|
||||
$employee_policy = $this->employeePolicyModel->where('employee_id',$employee['id'])->where('client_policy_id',$file['policy_id'])->first();
|
||||
$employee = $this->employeeModel
|
||||
->where('emp_code', $row[1])
|
||||
->where('name',$row[2])
|
||||
->where('client_id',$file['client_id'])
|
||||
->where('client_branch_id',$file['client_branch_id'])
|
||||
->where('emp_status', 'active')
|
||||
->where('is_active', 1)
|
||||
->first();
|
||||
$employee_policy = $this->employeePolicyModel
|
||||
->where('employee_id',$employee['id'])
|
||||
->where('client_policy_id',$file['policy_id'])
|
||||
->where('status', 'active')
|
||||
->where('is_active', 1)
|
||||
->first();
|
||||
// dd($employee, $employee_policy);
|
||||
|
||||
$existing_endorsements = $this->empEndorsementModel->where('actions','si')
|
||||
->where('table_name','employee_polices')
|
||||
|
||||
@ -1528,73 +1528,120 @@ class EmployeePolicyModel extends Model
|
||||
}
|
||||
|
||||
|
||||
public function bulkUpdateForEndorsement($endorsement_details)
|
||||
// public function bulkUpdateForEndorsement($endorsement_details)
|
||||
// {
|
||||
// // dd($endorsement_details, '---');
|
||||
// // Extract IDs, endorsement_ids, and statuses
|
||||
// $ids = array_column($endorsement_details, 'group_key');
|
||||
// $endorsement_ids = array_column($endorsement_details, 'endorsement_id');
|
||||
// $statuses = array_column($endorsement_details, 'status');
|
||||
|
||||
// // Escape values for SQL
|
||||
// $escapedIds = array_map([$this->db, 'escape'], $ids);
|
||||
// $escapedEndorsementIds = array_map([$this->db, 'escape'], $endorsement_ids);
|
||||
// $escapedStatuses = array_map([$this->db, 'escape'], $statuses);
|
||||
|
||||
// // Construct the CASE statements
|
||||
// $caseEndorsementId = array_map(function ($id, $endorsement_id) {
|
||||
// return "WHEN group_key = $id THEN $endorsement_id";
|
||||
// }, $escapedIds, $escapedEndorsementIds);
|
||||
|
||||
// // $caseStatus = array_map(function ($id, $status) {
|
||||
// // return "WHEN status = $id THEN $status";
|
||||
// // }, $escapedIds, $escapedStatuses);
|
||||
|
||||
// // Convert cases to a string
|
||||
// $caseEndorsementIdString = implode(' ', $caseEndorsementId);
|
||||
// // $caseStatusString = implode(' ', $caseStatus);
|
||||
|
||||
// // Convert ids to a string
|
||||
// $idsString = implode(', ', $escapedIds);
|
||||
|
||||
// // Construct the SQL query
|
||||
// $sql = "
|
||||
// UPDATE emp_endorsement
|
||||
// SET
|
||||
// endorsement_id = CASE {$caseEndorsementIdString} END,
|
||||
// status = 'complete'
|
||||
// WHERE group_key IN ({$idsString})
|
||||
// ";
|
||||
|
||||
|
||||
// // dd($sql);
|
||||
// // Begin a transaction
|
||||
// $this->db->transBegin();
|
||||
|
||||
// try {
|
||||
// // Start the transaction
|
||||
// $this->db->transBegin();
|
||||
|
||||
// // Execute the query
|
||||
// $this->db->query($sql);
|
||||
|
||||
// // Check transaction status
|
||||
// if ($this->db->transStatus() === false) {
|
||||
// $error = $this->db->error(); // Get the last database error
|
||||
// $this->db->transRollback();
|
||||
|
||||
// // Optionally log the error
|
||||
// log_message('error', 'Bulk update failed. Error: ' . json_encode($error));
|
||||
|
||||
// throw new \Exception('Bulk update failed. Error: ' . $error['message']);
|
||||
// }
|
||||
|
||||
// // Commit if everything is fine
|
||||
// $this->db->transCommit();
|
||||
|
||||
// return $this->db->getLastQuery(); // Optional: return last executed query for debugging
|
||||
// } catch (\Exception $e) {
|
||||
// $this->db->transRollback();
|
||||
|
||||
// // Optionally log the exception
|
||||
// log_message('error', 'Exception during bulk update: ' . $e->getMessage());
|
||||
|
||||
// // Re-throw with detailed context
|
||||
// throw new \RuntimeException('Exception during bulk update: ' . $e->getMessage(), $e->getCode(), $e);
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
public function bulkUpdateForEndorsement(array $endorsement_details)
|
||||
{
|
||||
|
||||
// Extract IDs, endorsement_ids, and statuses
|
||||
$ids = array_column($endorsement_details, 'group_key');
|
||||
$endorsement_ids = array_column($endorsement_details, 'endorsement_id');
|
||||
$statuses = array_column($endorsement_details, 'status');
|
||||
|
||||
// Escape values for SQL
|
||||
$escapedIds = array_map([$this->db, 'escape'], $ids);
|
||||
$escapedEndorsementIds = array_map([$this->db, 'escape'], $endorsement_ids);
|
||||
$escapedStatuses = array_map([$this->db, 'escape'], $statuses);
|
||||
|
||||
// Construct the CASE statements
|
||||
$caseEndorsementId = array_map(function ($id, $endorsement_id) {
|
||||
return "WHEN group_key = $id THEN $endorsement_id";
|
||||
}, $escapedIds, $escapedEndorsementIds);
|
||||
|
||||
// $caseStatus = array_map(function ($id, $status) {
|
||||
// return "WHEN status = $id THEN $status";
|
||||
// }, $escapedIds, $escapedStatuses);
|
||||
|
||||
// Convert cases to a string
|
||||
$caseEndorsementIdString = implode(' ', $caseEndorsementId);
|
||||
// $caseStatusString = implode(' ', $caseStatus);
|
||||
|
||||
// Convert ids to a string
|
||||
$idsString = implode(', ', $escapedIds);
|
||||
|
||||
// Construct the SQL query
|
||||
if (empty($endorsement_details)) {
|
||||
throw new \InvalidArgumentException("No endorsement details provided.");
|
||||
}
|
||||
|
||||
$caseParts = [];
|
||||
$groupKeys = [];
|
||||
|
||||
foreach ($endorsement_details as $row) {
|
||||
$groupKey = $this->db->escape($row['group_key']);
|
||||
$endorsementId = $this->db->escape($row['endorsement_id']);
|
||||
$caseParts[] = "WHEN group_key = {$groupKey} THEN {$endorsementId}";
|
||||
$groupKeys[] = $groupKey;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
UPDATE emp_endorsement
|
||||
SET
|
||||
endorsement_id = CASE {$caseEndorsementIdString} END,
|
||||
endorsement_id = CASE " . implode(' ', $caseParts) . " END,
|
||||
status = 'complete'
|
||||
WHERE group_key IN ({$idsString})
|
||||
WHERE group_key IN (" . implode(', ', $groupKeys) . ")
|
||||
";
|
||||
|
||||
|
||||
// dd($sql);
|
||||
// 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();
|
||||
}
|
||||
// $this->storeEndorsementNumber($file_id, $endorsement_id, $enrollment_file_id);
|
||||
|
||||
return $this->db->getLastQuery();
|
||||
} catch (\Exception $e) {
|
||||
// Rollback the transaction on error
|
||||
$this->db->transRollback();
|
||||
throw $e;
|
||||
|
||||
$this->db->query($sql);
|
||||
|
||||
// Check if query was successful
|
||||
if ($this->db->affectedRows() === 0) {
|
||||
throw new \RuntimeException('No rows were updated.');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function bulkUpdateForCorrection($emp_details){
|
||||
|
||||
foreach ($emp_details as $employee) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user