diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 51ab6236..1f26e4b9 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -17,6 +17,7 @@ use App\Models\PolicesModel; use App\Models\RelationshipModel; use App\Models\FileModel; use App\Models\ClientPolicyModel; +use App\Models\PolicyPremium2Model; use App\Controllers\Jobs ; use App\Controllers\JobWorker ; @@ -43,6 +44,7 @@ class EmployeeRestController extends AdminController protected $policesModel; protected $relationshipModel; protected $clientPolicyModel; + protected $policyPremium2Model; public function __construct() { @@ -56,6 +58,7 @@ class EmployeeRestController extends AdminController $this->relationshipModel = new RelationshipModel(); $this->fileModel= new FileModel(); $this->clientPolicyModel = new ClientPolicyModel(); + $this->policyPremium2Model = new PolicyPremium2Model(); } @@ -483,13 +486,18 @@ class EmployeeRestController extends AdminController } } - // Upload the Sheet Data in DB + // Upload the Employee Detail in DB by Sheet Data public function employeeUpload() { $file = $this->request->getFile('file'); $client_id = $this->request->getPost('client_id'); $policy_id = $this->request->getPost('policy_id'); + $client_policy = $this->clientPolicyModel->where('id', $policy_id)->first(); + $policy = $this->policesModel->where('id', $client_policy['policy_id'])->first(); + + $policy_permium = $this->policyPremium2Model->where(['client_id' => $client_id , 'client_policy_id' => $policy_id,'is_active' =>1])-> first(); + $is_moved = $file->move(WRITEPATH . 'uploads/import_excel'); $filename = $file->getName(); $file_name_with_path = WRITEPATH."/uploads/import_excel/".$filename; @@ -567,10 +575,8 @@ class EmployeeRestController extends AdminController } } } - // print_r("Extra", $extra);die; $dataToInsert = []; $basic_cover_si= []; - // print_r($extra);die; foreach ($extra['0'] as $index => $id) { $relation =''; if ($extra['5'][$index] === 'Mother' || $extra['5'][$index] === 'Father') { @@ -624,29 +630,79 @@ class EmployeeRestController extends AdminController 'emp_status'=>'draft' ]; + + $basic_cover_si_value = null; + + //Grid id is 10 and 11 sum insure value add only for self other grid type self sum insure is for the dependence + // if ($policy['policy_type_id'] != 1) { + if ($policy_permium['policy_grid_id'] == 10 || $policy_permium['policy_grid_id'] == 11) { + if (strtolower($extra['5'][$index]) == 'self') { + $basic_cover_si_value = $extra['9'][$index]; + }else{ + $basic_cover_si_value = null; + } + }else{ + if (strtolower($extra['5'][$index]) == 'self') { + $basic_cover_si_value = $extra['9'][$index]; + }else{ + for ($i=0; $i < count($extra['1']) ; $i++) { + + if ($extra['1'][$i] == $extra['1'][$index]) { + if (strtolower($extra['5'][$i]) == 'self') { + $basic_cover_si_value = $extra['9'][$i]; + } + } + } + } + } + // } + $record2 = [ - 'basic_cover_si' => isset($extra['9'][$index]) ? $extra['9'][$index] : 0, + 'basic_cover_si' => $basic_cover_si_value, ]; + // print_r($basic_cover_si);die; $dataToInsert[] = $record; - $basic_cover_si[]= $record2; + $basic_cover_si[]= $basic_cover_si_value; } } for ($a=0; $a employeeModel->checkExistingEmpEntrollment($dataToInsert[$a]); + $employee = $this->employeeModel->checkExistingEmployee($dataToInsert[$a]); $emp_id =0; + + $data_after_gpa_or_gmc =[]; + // print_r($policy);die; + if ($policy['policy_type_id'] == 1) { + if (strtolower($dataToInsert[$a]['relationship']) == 'self') { + $data_after_gpa_or_gmc = $dataToInsert[$a]; + } + }else{ + $data_after_gpa_or_gmc = $dataToInsert[$a]; + } + + + date_default_timezone_set('Asia/Kolkata'); + $current_timestamp = time(); + $formatted_date_time = date('Y-m-d H:i:s', $current_timestamp); if ($employee) { + + $emp_id =$employee['id']; $id =$emp_id; - $result = $this->employeeModel->update($id, $dataToInsert[$a]); + $data_after_gpa_or_gmc['id'] = $id; + $data_after_gpa_or_gmc['updated_at'] = $formatted_date_time; + $result = $this->employeeModel->save($data_after_gpa_or_gmc); if ($result) { $log_message = 'Update Employee - '.$employee['name'].'('.$employee['emp_code'].') with PK '.$employee['id']; $this->myLogger->logme('error',('Update - ' . $employee['id'].' - '. $employee['emp_code'] .' - '.$employee['name'])); } }else{ if ($dataToInsert[$a]['emp_code'] != 0) { - $result = $this->employeeModel->insert($dataToInsert[$a]); + $result =false; + if (count($data_after_gpa_or_gmc) != 0) { + $result = $this->employeeModel->insert($data_after_gpa_or_gmc); + } $emp_id =$result; if ($result) { $emp = $this->employeeModel->where('id', $result)->get()->getResult(); @@ -663,13 +719,15 @@ class EmployeeRestController extends AdminController 'employee_id'=>$emp_id, 'client_policy_id'=>$policy_id, 'status'=> 'draft', - 'basic_cover_si'=> $basic_cover_si[$a] + 'basic_cover_si'=>isset($basic_cover_si[$a]) ? $basic_cover_si[$a] : null ]; $employee_policy = $this->employeePolicyModel->checkExistingEmpPolicy(['employee_id' => $emp_id,'client_policy_id' => $policy_id]); if ($employee_policy) { foreach ($employee_policy as $existing_policy) { - $this->employeePolicyModel->update($existing_policy['id'], $emp_policy_data); + $emp_policy_data['id']= $existing_policy['id']; + $emp_policy_data['updated_at'] = $formatted_date_time; + $this->employeePolicyModel->save($emp_policy_data); } } else { $emp_policy = $this->employeePolicyModel->insert($emp_policy_data); @@ -678,13 +736,12 @@ class EmployeeRestController extends AdminController //trigger // print_r($dataToInsert[$a]['email_personal']);die; - $policy = $this->clientPolicyModel->where('id', $policy_id)->first(); - $policy_name = $this->policesModel->where('id', $policy['policy_id'])->first(); + $mail = $dataToInsert[$a]['email_corporate']; $subject = 'Welcome, Employee Benefit Program Enrolment'; // $message = 'Dear ' . $dataToInsert[$a]['name'] . ",
We are glad to welcome you to the employee benefit program ," .$policy_name['name'] ."offered by your employer,


Click on the link below to review your personal and family details:
Review Details" ; $data['employee_name']=$dataToInsert[$a]['name']; - $data['policy_name']=$policy_name['name']; + $data['policy_name']=$policy['name']; $message = view('mail_welcome', $data); // if ($dataToInsert[$a]['email_corporate'] != null || $dataToInsert[$a]['email_corporate'] != '' && $dataToInsert[$a]['relationship'] == 'Self') { diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php index 09eeb13d..5a564363 100644 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -29,6 +29,7 @@ class EmployeeModel extends Model "emp_status", "created_by", "updated_by", + "updated_at", "is_active", ]; @@ -51,9 +52,12 @@ class EmployeeModel extends Model // for EMP rest API process do not change - public function checkExistingEmpEntrollment($arr) - { - return $this->where('emp_code',$arr['emp_code'])->where('name',$arr['name'])->first(); + public function checkExistingEmployee($arr) + { + return $this->where('emp_code',$arr['emp_code'])->where('name',$arr['name'])->where('client_id', $arr['client_id'])->first(); } + + + } diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 6ac9eeb7..2eadf306 100644 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -29,6 +29,7 @@ class EmployeePolicyModel extends Model "gst", "created_by", "updated_by", + "updated_at", "is_active", ]; diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php index 310e6bda..0fdda4d3 100644 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -295,8 +295,8 @@ @@ -766,6 +766,10 @@ } convertCommaNumberToWords(input); + if (input.id == 'gpa_sum_si') { + gpaSumInsureMultiplier(input); + } + // if(input.id == 'basic_pay'){ // var inputNumber = input.value; // if (inputNumber) { diff --git a/app/Views/policy_grid.php b/app/Views/policy_grid.php index 64af741e..8cc5b360 100644 --- a/app/Views/policy_grid.php +++ b/app/Views/policy_grid.php @@ -1424,7 +1424,8 @@ } } - function gpaSumInsureMultiplier() { + function gpaSumInsureMultiplier(element) { + console.log(element); var element = $('#gpa_sum_multiplier')[0]; var sumInsured = $('input[name="gpa_sum_si[]"]');