diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 0432432b..85fe7c76 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -54,6 +54,8 @@ $routes->group("/client", ["filter" => "authMVC"], function($routes){ $routes->post("create", "ClientController::createClientPolicy"); $routes->post("edit", "ClientController::editClientPolicy"); $routes->get("list/(:any)", "ClientController::getClientPolicyById/$1"); + $routes->post("jsonPost", "ClientController::jsonPost"); + $routes->get("getjson", "ClientController::getjson"); }); $routes->group("kyc", ["filter" => "authMVC"], function($routes){ $routes->post("create", "ClientController::createClientKYCInfo"); @@ -71,8 +73,8 @@ $routes->group("/client", ["filter" => "authMVC"], function($routes){ $routes->group("/employee", ["filter" => "authMVC"], function($routes){ $routes->get("list", "EmployeeController::list"); $routes->get("search", "EmployeeController::search"); - $routes->get("bulk-event-uplod", "EmployeeController::employeesUplodWithEvents"); - $routes->post("bulk-event-uplod", "EmployeeController::employeesUplodWithEvents"); + $routes->get("upload", "EmployeeController::employeesUplodWithEvents"); + $routes->post("upload", "EmployeeController::employeesUplodWithEvents"); }); @@ -150,9 +152,10 @@ $routes->group("/master", ["filter" => "authMVC"], function($routes){ $routes->group("/util", ["filter" => "authMVC"], function($routes){ - $routes->get("clients-with-policies", "EmployeeController::getClientWithPolicies"); - $routes->get("police-by-insurer/(:any)", "ClientController::getPolicesByInsurerId/$1"); - $routes->get("kyc-other-docs-delete/(:any)", "ClientController::deleteClientKycOtherDocs/$1"); + $routes->get("clients-with-policies", "EmployeeController::getClientWithPolicies"); + $routes->get("police-by-insurer/(:any)", "ClientController::getPolicesByInsurerId/$1"); + $routes->get("get-file-error/(:any)", "EmployeeController::getUploadedFileError/$1"); + $routes->get("kyc-other-docs-delete/(:any)", "ClientController::deleteClientKycOtherDocs/$1"); $routes->get("policy-premium", "ClientController::getpolicyGridData/$1"); }); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index e30e4989..743623ff 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -27,7 +27,6 @@ use App\Models\PolicyGridModel; use App\Models\PolicyPremium1Model; use App\Models\PolicyPremium2Model; - class ClientController extends AdminController { use ResponseTrait; @@ -51,7 +50,6 @@ class ClientController extends AdminController protected $policyGridModel; protected $policyPremium1Model; protected $policyPremium2Model; - public function __construct() { @@ -75,7 +73,8 @@ class ClientController extends AdminController $this->stateModel = new StateModel(); $this->policyGridModel = new PolicyGridModel(); $this->policyPremium1Model = new PolicyPremium1Model(); - $this->policyPremium2Model = new PolicyPremium2Model(); + + } public function index() @@ -643,6 +642,9 @@ class ClientController extends AdminController $policy_id = $this->request->getGet('policy_id'); $client_id = $this->request->getGet('client_id'); + echo $policy_id; + echo $client_id; + $data = $this->policesModel->getPolicyPremium($policy_id); $pattern = '/gmc/i'; $subject = $data[0]->policy_type; @@ -669,4 +671,120 @@ class ClientController extends AdminController } + public function jsonPost() + { + + try { + $this->myLogger->logme('error','JSon CREATE function called'); + // print_r($this->request->getPost()); + $client_id = $this->request->getPost("client_id"); + $policy_id = $this->request->getPost("policy_id"); + $data['sumInsured'] =$this->request->getPost("sumInsured"); + $data['family_floater'] =$this->request->getPost("family_floater"); + // print_r($data['familyfloater']); + if (!$data['family_floater'] || $data['family_floater'] == 0) { + $data['corporatebuffer'] = ""; + $data['family_floaters'] = ""; + }else{ + $data['corporatebuffer'] = $this->request->getPost("corporatebuffer"); + $data['family_floaters'] = $this->request->getPost("family_floaters") ?? []; + } + + $data['waiverofpreexistingdiseases'] =$this->request->getPost("waiverofpreexistingdiseases"); + if ($data['waiverofpreexistingdiseases'] == 1) { + $data['maternitycoverage'] =$this->request->getPost("maternitycoverage"); + $data['twindelivery'] =$this->request->getPost("twindelivery"); + $data['preandpostnatal'] =$this->request->getPost("preandpostnatal"); + $data['babyday1cover'] =$this->request->getPost("babyday1cover"); + }else{ + $data['maternitycoverage'] =""; + $data['twindelivery'] =""; + $data['preandpostnatal'] =""; + $data['babyday1cover'] =""; + } + $data['9monthwaitingperiodwaived'] =$this->request->getPost("9monthwaitingperiodwaived"); + $data['coverfromthedateofjoining'] =$this->request->getPost("coverfromthedateofjoining"); + $data['waiverof1,2,3&4thyearexclusions'] =$this->request->getPost("waiverof1,2,3&4thyearexclusions"); + $data['waiverof30dayswaitingperiod'] =$this->request->getPost("waiverof30dayswaitingperiod"); + $data['prehospitalizationcover'] =$this->request->getPost("prehospitalizationcover"); + $data['congenitaldiseasesinternal'] =$this->request->getPost("congenitaldiseasesinternal"); + $data['copayzonewisecopay'] =$this->request->getPost("copayzonewisecopay"); + $data['bioabsorbablestenttoriclensmultifocallens'] =$this->request->getPost("bioabsorbablestenttoriclensmultifocallens"); + $data['roomrentlimit'] =$this->request->getPost("roomrentlimit"); + $data['proportionatedeductionclause'] =$this->request->getPost("proportionatedeductionclause"); + $data['nursingallowance'] =$this->request->getPost("nursingallowance"); + $data['ailmentcapping'] =$this->request->getPost("ailmentcapping"); + $data['ambulancecharges'] =$this->request->getPost("ambulancecharges"); + $data['airambulance'] =$this->request->getPost("airambulance"); + $data['familytransportationbenefit'] =$this->request->getPost("familytransportationbenefit"); + $data['reasonableandcustomarycharges'] =$this->request->getPost("reasonableandcustomarycharges"); + $data['ayudhtreatmentcover'] =$this->request->getPost("ayudhtreatmentcover"); + $data['armdcovered'] =$this->request->getPost("armdcovered"); + $data['suminsuredenhancement'] =$this->request->getPost("suminsuredenhancement"); + $data['automaticsuminsuredreinstatement'] =$this->request->getPost("automaticsuminsuredreinstatement"); + $data['additionalsicknessbenefit'] =$this->request->getPost("additionalsicknessbenefit"); + $data['lasiksurgery'] =$this->request->getPost("lasiksurgery"); + $data['midterminclusion'] =$this->request->getPost("midterminclusion"); + $data['capd'] =$this->request->getPost("capd"); + $data['organdonorexpenses'] =$this->request->getPost("organdonorexpenses"); + $data['moderntreatmentsasperirdai'] =$this->request->getPost("moderntreatmentsasperirdai"); + $data['Wellness'] =$this->request->getPost("Wellness"); + $data['days_of_discharge'] =$this->request->getPost("days_of_discharge"); + $data['days_from_dod'] =$this->request->getPost("days_from_dod"); + $data['specialConditionLabel'] = $this->request->getPost("specialConditionLabel") ?? []; + $data['specialConditionInput'] = $this->request->getPost("specialConditionInput") ?? []; + + // print_r($data); + + // print_r($this->request->getPost()); + // die(); + + $jsonData = json_encode($data); + $dataa = array( + 'json' => $jsonData, + 'client_id' => $client_id, + 'policy_id' => $policy_id + ); + $record = $this->clientPolicyModel->where(['client_id' => $client_id, 'policy_id' => $policy_id])->first(); + if ($record) { + $update = $this->clientPolicyModel->update($record['id'], $dataa); + if ($update) { + echo json_encode(array('message' => 'Data updated successfully')); + } else { + echo json_encode(array('message' => 'Failed to update data')); + } + }else{ + $insert = $this->clientPolicyModel->insert($dataa); + if ($insert) { + echo json_encode(array('message' => 'Data stored successfully')); + } else { + echo json_encode(array('message' => 'Failed to store data')); + } + } + } catch (\Exception $e) { + // Handle the exception + echo "Failed to insert data: " . $e->getMessage(); + // Log the error + log_message('error', 'Failed to insert data: ' . $e->getMessage()); + } + + } + + + + public function getjson() + { + $client_id = $this->request->getVar('client_id'); + $policy_id = $this->request->getVar('policy_id'); + $record = $this->clientPolicyModel->where(['client_id' => $client_id, 'policy_id' => $policy_id])->first(); + + if ($record) { + echo $record['json']; + + } else { + echo "Record not found."; + } + + } + } \ No newline at end of file diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index c2b0d73e..483e6c61 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -15,6 +15,9 @@ use App\Models\FileModel; use App\Controllers\Jobs ; use App\Controllers\JobWorker ; +use App\Controllers\Jobs\SubJob; +use App\Controllers\EmployeeServiceController; + use CodeIgniter\API\ResponseTrait; @@ -69,6 +72,27 @@ class EmployeeController extends AdminController } } + + public function getUploadedFileError() + { + $file_id = $this->request->uri->getSegment(3); + // dd($segments[2]); + // die(); + // $file_id = $this->request->getGet(); + // echo $file_id;die(); + $file = $this->fileModel->find($file_id); + // print_r($result);die(); + if(!isset($file)) + { + return $this->respond(['dataStatus' => false,'code' => 404,'message' => 'no data found'], 200); + } + else + { + + return $this->respond(['dataStatus' => true,'code' => 200,'data' => $file['reason']], 200); + } + } + //handles employee & dependent bulk upload with events like inception,addition,deletion, correction and SI enhancements public function employeesUplodWithEvents() { @@ -85,13 +109,25 @@ class EmployeeController extends AdminController // print_r($this->request->getPost('policies')); // print_r($this->request->getPost('upload-action-type')); // die(); + // $empServiceController = new EmployeeServiceController(); + // $res = $empServiceController->fileFormatValidationController('12'); + // // dd($res); + + // if(isset($res) && count($res)) + // { + // $failure_reason = json_encode((json_encode($res))); + // $this->fileModel->where('id', '12')->set(['status' => 'failed','reason' => $failure_reason])->update(); + // dd($failure_reason); + // } + if($this->request->getMethod() == 'post') { + //validate uploaded file $filename = ''; $validated = $this->validate([ 'emplist' => [ 'uploaded[emplist]', - 'mime_in[emplist,application/vnd.ms-excel,application/vnd,application/pdf]', + 'mime_in[emplist,application/vnd.ms-excel,application/vnd,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.oasis.opendocument.spreadsheet]', 'max_size[emplist,8192]', ], ]); @@ -116,13 +152,16 @@ class EmployeeController extends AdminController $status = 'inprogress'; $file_id = $this->fileModel->insert(['file_name' => $filename,'client_id' => $client_id,'policy_id' => $policy_id,'created_by' => $loggedInUserID,'status' => $status,'action' => $action]); - //die(); $this->myLogger->logme("error",'{file_id} uploaded success',['file_id' => $file_id]); + + //start validation process + + //en dof validation process return $this->respond(['dataStatus' => true,'code' => 200,'data' => 'file upload success'], 200); } - $data['actions'] = ['inception' => 'Inception','addition' => 'Addition','deletion' => 'Deletion','si_enhancement' =>'SI Enhancement']; + $data['actions'] = ['inception' => 'Inception','addition' => 'Addition','deletion' => 'Deletion','correction' =>'Correction','si_enhancement' =>'SI Enhancement']; $data['fileList'] = $this->fileModel ->select(['files.*','up.emp_code','up.first_name']) ->join('user_profiles up','files.created_by = up.id') diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php new file mode 100644 index 00000000..417ee77e --- /dev/null +++ b/app/Controllers/EmployeeServiceController.php @@ -0,0 +1,188 @@ + ['name' => 'Self', 'sex' => 'M','age_min' => 18,'age_max' => null], 'spouse' => ['name' => 'Spouse', 'sex' => 'F','age_min' => 18,'age_max' => null], 'son' => ['name' => 'Son', 'sex' => 'M','age_min' => null,'age_max' => 25], 'daughter' => ['name' => 'Daughter', 'sex' => 'F','age_min' => null,'age_max' => 25], 'father' => ['name' => 'Father', 'sex' => 'M','age_min' => 18,'age_max' => null], 'mother' => ['name' => 'Mother', 'sex' => 'F','age_min' => 18,'age_max' => null], 'father-in-law' => ['name' => 'Father in Law', 'sex' => 'M','age_min' => 18,'age_max' => null], 'mother-in-law' => ['name' => 'Mother in Law', 'sex' => 'F','age_min' => 18,'age_max' => null]]; + + protected $inception_excel_columns = ['sno' => ['col_idx' => 0,'col_cell_name' => 'A','col_name' => 'S.No','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => null],'emp_id' => ['col_idx' => 1,'col_cell_name' => 'B','col_name' => 'EMP ID','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => null],'name_of_emp_dep' => ['col_idx' => 2,'col_cell_name' => 'C','col_name' => 'NAME OF EMP/DEP','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => null],'dob' => ['col_idx' => 3,'col_cell_name' => 'D','col_name' => 'DOB','is_mandatory' => true,'data_type' => 'str','format' => 'd-M-Y','allowed_values' => null,'custom' => 'check_dob_diff','params' => ['row','relationship']],'sex' => ['col_idx' => 4,'col_cell_name' => 'E','col_name' => 'SEX','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => ['M','F']],'relationship' => ['col_idx' => 5,'col_cell_name' => 'F','col_name' => 'RELATIONSHIP','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => null,'custom' => 'check_relationship','params' => ['row','relationship']],'basic_cover_si' => ['col_idx' => 6,'col_cell_name' => 'G','col_name' => 'BASIC COVER SI','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => null],'doj' => ['col_idx' => 7,'col_cell_name' => 'H','col_name' => 'DOJ','is_mandatory' => 'custom','data_type' => 'str','format' => 'd-M-Y','allowed_values' => null,'custom' => 'check_doj','params' => ['row']],'basic_pay' => ['col_idx' => 8,'col_cell_name' => 'I','col_name' => 'Basic Pay','is_mandatory' => 'custom','data_type' => 'str','format' => null,'allowed_values' => null,'custom' => 'check_basic_pay','params' => ['row']],'band_grade' => ['col_idx' => 9,'col_cell_name' => 'J','col_name' => 'Band/Grade','is_mandatory' => 'custom','data_type' => 'str','format' => null,'allowed_values' => null,'custom' => 'check_employee_band','params' => ['row']],'designation' => ['col_idx' => 10,'col_cell_name' => 'K','col_name' => 'Designation','is_mandatory' => false,'data_type' => 'str','format' => null,'allowed_values' => null],'phone' => ['col_idx' => 11,'col_cell_name' => 'L','col_name' => 'Phone','is_mandatory' => false,'data_type' => 'str','format' => null,'allowed_values' => null],'email' => ['col_idx' => 12,'col_cell_name' => 'M','col_name' => 'Email','is_mandatory' => false,'data_type' => 'str','format' => null,'allowed_values' => null],'pre_existing_ailments' => ['col_idx' => 13,'col_cell_name' => 'N','col_name' => 'PRE EXISTING AILMENTS','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => ['0','1']]]; + public function __construct() + { + // helper('utility'); + set_session_context('EmployeeService'); + $this->myLogger = \Config\Services::mylogger(); + $this->employeeModel = new EmployeeModel(); + $this->employeePolicyModel = new EmployeePolicyModel(); + $this->clientModel = new ClientModel(); + $this->fileModel = new FileModel(); + } + + public function fileFormatValidationController($file_id) + { + helper('excel_util_helper'); + //get file name + // check_dob_diff('4-APr-1990');die(); + $file = $this->fileModel->find($file_id); + // dd($file); + $return = []; + if(!isset($file)) + { + //file not found in DB + return array('status' => false, 'msg' => 'file not found in DB'); + } + $file_name_with_path = WRITEPATH."/uploads/excel/".$file['file_name']; + + //check physical file + if(!file_exists($file_name_with_path)) + { + //file not found update status and reason + $this->fileModel->where('id', $file_id)->set(['status' => 'failed','reason' => 'file not found'])->update(); + return array('status' => false, 'msg' => 'file not found'); + } + + //start validation process + $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path); + $sheet = $spreadsheet->getActiveSheet(); + + $highestRowAndColumn = $sheet->getHighestRowAndColumn(); + // $highestRow = $sheet->getHighestDataRow(); // 1048576, should be 2 + // $highestColumn = $sheet->getHighestDataColumn(); // L, should be B + // print_r($highestRowAndColumn); + // echo $highestRow;echo ' - ' . $highestColumn; + $excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']); + // $data = array_filter($data); + // echo '
'; 
+        // dd($excel_data);
+        // echo "
";die(); + // foreach ($excel_data as $key => $value) + // { + + // } + + + $columns_to_check = []; + if($file['action'] == 'inception'){ $columns_to_check = $this->inception_excel_columns; } + + //check no of columns in excel + $total_defined_columns = count($columns_to_check); + $excel_columns = ($excel_data[0]); + // var_dump($excel_columns);die(); + $excel_columns_count = count($excel_columns); + if($total_defined_columns != $excel_columns_count) + { + //columns count mismatch + $message = "columns count mismatch. Expected - $total_defined_columns and received - $excel_columns"; + echo $message; + $this->myLogger->logme('error',($message . ' for file id ' . $file_id)); + //$model->where('id', $file_id)->set(['status' => 'failed','reason' => $message])->update(); + return array('status' => false, 'msg' => $message); + } + + + //check columns order in excel + $column_count_res = check_columns_count($columns_to_check,$excel_columns); + + if(isset($column_count_res) && count($column_count_res)) + { + //columns count mismatch + $message = implode("\n", $column_count_res); + echo $message; + $this->myLogger->logme('error',($message . ' for file id ' . $file_id)); + // $model->where('id', $file_id)->set(['status' => 'failed','reason' => $message])->update(); + return array('status' => false, 'msg' => $message); + } + + //start other checks + $result = []; + $keys = array_keys($this->inception_excel_columns); + // print_r($keys);die(); + + //remove header + unset($excel_data[0]); + $relationship = $this->general_relationships; + foreach ($excel_data as $row_key => $row) + { + + //1. avoid empty rows + if(check_row_is_empty_or_null($row)) + { + break; + } + //iterate each row + foreach ($row as $col_key => $col) + { + //mandatory check + if(isset($this->inception_excel_columns[$keys[$col_key]]['custom'])) + { + $custom_function = $this->inception_excel_columns[$keys[$col_key]]['custom']; + // echo $custom_function; + + $binding_params = $this->inception_excel_columns[$keys[$col_key]]['params']; + + //convert string params into PHP variables + // Create an array of variables to pass custom helper funcitons + $param_values = []; + foreach($binding_params as $bkey => $bparam) { $param_values[] = ($$bparam); } + // dd(($param_values));//die(); + $res = call_user_func_array($custom_function,$param_values); + // print_r($res['status']);die(); + if($res['status'] === false) { $result[$row_key][$keys[$col_key]][] = $res['error']; } + + } + + if($this->inception_excel_columns[$keys[$col_key]]['is_mandatory'] === true) + { + if($col == "" || $col == NULL) { $result[$row_key][$keys[$col_key]][] = 'value is mandatory'; } + } + + //format check + if(isset($this->inception_excel_columns[$keys[$col_key]]['format'])) + { + $format_error = check_excel_date_format($col,$this->inception_excel_columns[$keys[$col_key]]['format']); + if(!$format_error['status']) + { + $result[$row_key][$keys[$col_key]][] = $format_error['error']; + } + } + + //allowed values check + if(isset($this->inception_excel_columns[$keys[$col_key]]['allowed_values']) && is_array($this->inception_excel_columns[$keys[$col_key]]['allowed_values'])) + { + $allowed_values = $this->inception_excel_columns[$keys[$col_key]]['allowed_values']; + if(!in_array($col,$allowed_values)) + { + $result[$row_key][$keys[$col_key]][] = "Value not allowed: Expected ".implode(",",$allowed_values)." and received $col"; + } + } + + } + + } + + return $result; + + } + + + +} diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php new file mode 100644 index 00000000..1e628dbe --- /dev/null +++ b/app/Helpers/excel_util_helper.php @@ -0,0 +1,159 @@ + $definedCol) { + $definedColIdx = $definedCol['col_idx']; + $definedColName = $definedCol['col_name']; + + if ($excelColumns[$definedColIdx] !== $definedColName) { + $mismatchedColumns[] = "Column order conflict. Column order no ".($definedColIdx + 1)." expected : ".$definedColName." and received : ".$excelColumns[$definedColIdx]; + } + } + + return $mismatchedColumns; + } +} + + +if (!function_exists('check_row_is_empty_or_null')) { + + function check_row_is_empty_or_null($arr) { + unset($arr[0]);// unset SNO in the array, becoz we need to check only datapoints are empty not SNo, it may added by accidentally + foreach ($arr as $item) { + if ($item !== null && !empty($item)) { + return false; // If any item is not empty or not null, return false + } + } + return true; // If all items are empty or null, return true + } +} + +if (!function_exists('check_excel_date_format')) { + + function check_excel_date_format($dateString,$format) + { + + if($dateString == ""){ return array('status' => true); } + $date = DateTime::createFromFormat('d-M-Y', $dateString); + + if ($date !== false && !is_array($date::getLastErrors())) { + return array('status' => true); + } else { + return array('status' => false,'error' => "wrong date format: Expected 'd-M-Y' and received $dateString"); + } + } +} + + +if(!function_exists('check_relationship')) +{ + function check_relationship($row,$relationship) + { + // print_r($col);print_r($relationship); + // echo '
'; + if($row[5] != null && $row[4] != null) + { + $slug = \Config\Services::slug(); + $col = $slug->slugify($row[5]); + // echo $col;die(); + if($col != 'self' && $col != 'spouse') + { + if($relationship[ $col ]['sex'] != $row[4]) + { + $error = "Gender relationship conflict: Expected ".$relationship[ $col ]['sex'].", received $row[4]"; + return array('status' => false,'error' => $error); + } + + } + return array('status' => true); + } + else + { + return array('status' => false,'error' => 'Rule Conflict: Both Relationship or Gender required'); + } + } +} + + +if(!function_exists('check_doj')) +{ + function check_doj($row) + { + $slug = \Config\Services::slug(); + $relationship = $slug->slugify($row[5]); + // echo $relationship;echo $row[7]; + if($relationship == 'self' && $row[7] == "") { return array('status' => false,'error' => "DOJ mandantory for self"); } + return array('status' => true); + } +} + + +if(!function_exists('check_employee_band')) +{ + function check_employee_band($row) + { + $slug = \Config\Services::slug(); + $relationship = $slug->slugify($row[5]); + // echo $relationship;echo $row[7]; + if($relationship == 'self' && $row[9] == "") { return array('status' => false,'error' => "Band mandantory for self"); } + return array('status' => true); + } +} + +if(!function_exists('check_basic_pay')) +{ + function check_basic_pay($row) + { + $slug = \Config\Services::slug(); + $relationship = $slug->slugify($row[5]); + // echo $relationship;echo $row[7]; + if($relationship == 'self' && $row[8] == "") { return array('status' => false,'error' => "Basic pay mandantory for self"); } + return array('status' => true); + } +} + + +if (!function_exists('check_dob_diff')) +{ + function check_dob_diff($row,$relationships) { + // echo 'called'; + if($row[3] != null && $row[5] != null) + { + $dob = change_date_format($row[3],'d-M-Y','Y-m-d'); + // echo $row[3].' - '.$dob;echo '
'; + $currentDateTime = new DateTime();//die(); + $passedDateTime = new DateTime($dob); + $interval = $currentDateTime->diff($passedDateTime); + + $slug = \Config\Services::slug(); + $relationship = $slug->slugify($row[5]); + $age_min = $relationships[$relationship]['age_min']; + $age_max = $relationships[$relationship]['age_max']; + // echo $relationship.','.$age_min.'-'.$age_max; + if($age_min !== null && $age_min > $interval->y) + { + return array('status' => false,'error' => "Age conflict : minimum $age_min yrs allowed, received $interval->y"); + } + if($age_max !== null && $age_max < $interval->y) + { + return array('status' => false,'error' => "Age conflict : maximum $age_max yrs allowed, received $interval->y"); + } + return array('status' => true); + } + else + { + return array('status' => false,'error' => 'Rule Conflict: Both DOB or Relationship required'); + } + } +} + + + + + + + diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index 0849618a..9a9cf2f3 100644 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -35,6 +35,7 @@ class ClientPolicyModel extends Model "earned_premium_amount", "claims_incurred_amount", + "json", "created_by", "updated_by", "Is_active", diff --git a/app/Models/FileModel.php b/app/Models/FileModel.php index 3c25e1ef..aefbb419 100644 --- a/app/Models/FileModel.php +++ b/app/Models/FileModel.php @@ -21,5 +21,4 @@ class FileModel extends Model ]; - } diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php index 9eb267f2..53431c7b 100644 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -1,4 +1,5 @@ +
@@ -181,6 +182,7 @@ $(document).ready(function () {    + `; diff --git a/app/Views/employee_upload.php b/app/Views/employee_upload.php index 4a2bcf00..23e463d4 100644 --- a/app/Views/employee_upload.php +++ b/app/Views/employee_upload.php @@ -10,14 +10,14 @@
-
+

- +
@@ -25,7 +25,7 @@

@@ -33,8 +33,8 @@

- +

- +
@@ -94,9 +94,7 @@
@@ -115,35 +113,45 @@ //fetchClientPolicies(); //for modal pop up $('#file-err-modal').on('show.bs.modal', function (event) { + // console.log(event.relatedTarget); var myVal = $(event.relatedTarget).data('err'); - $(this).find(".modal-body").text(myVal); + console.log(myVal); + var model_data = fetchFileError(myVal); + console.log('data received.'); + console.log(model_data); + $(this).find(".modal-body").text(model_data); }); //for form submit $("#emp-upload-form").submit(function(event) { event.preventDefault(); // Prevent default form submission console.log('submit called'); - // Check required fields - if (!$(this)[0].checkValidity()) { - // Form is invalid, handle error or notify user - console.log('failed'); + + var action_item = $('#upload-action-type').val(); + var policy_id = $('#policy_id').val(); + console.log('action_item - '+ action_item); + if(action_item != 'correction' && policy_id == "") + { + // $('#policy_id').attr('required', true); + // $('#policy_id').prop('title', 'plz choose policy'); + // $('#policy_id').mouseover(); + console.log('required'); + alert('please choose policy for this uploaing event '); return false; } - console.log($(this)); - console.log($(this)[0]); + else{ + $('#policy_id').attr('required', false); + console.log('not required'); + } // Create FormData object var formData = new FormData($(this)[0]); for (var pair of formData.entries()) { - console.log(pair[0]+ ', ' + pair[1]); - } - // var formData = $("#emp-upload-form").serialize(); - // var file = document.getElementById('emplist').files[0]; - // formData.append('file', file); + console.log(pair[0]+ ', ' + pair[1]); } + console.log(formData); - // return false; - // AJAX request + $.ajax({ url: $(this).attr("action"), type: "POST", @@ -156,9 +164,21 @@ }, success: function(response) { // Request successful, handle response + $('#policy_id').attr('required', false); console.log(response); - alert('success'); - window.location.reload(); + if (response.code === 200 && response.dataStatus === true && response.data !== "") { + alert('sucess'); + window.location.reload(); + } else if(response.code === 404 && response.dataStatus === false){ + console.error('no data found', response); + alert(response.message); + } + else + { + console.error('Something went wrong!'); + alert('Something went wrong! Try later'); + } + }, error: function(xhr, status, error) { // Request failed, handle error @@ -223,6 +243,68 @@ } + function fetchFileError(file_id) { + $('#loader').show(); + var apiURL = '' + 'util/get-file-error/' + file_id; + console.log('fetchFileError'); + console.log(apiURL); + $.ajax({ + url: apiURL, + method: 'GET', + headers: { + "X-Requested-With": "XMLHttpRequest" + }, + success: function(response) { + // console.log(response.code); + // console.log(response.dataStatus); + // console.log(response.data); + if (response.code === 200 && response.dataStatus === true && response.data !== "") { + try { + console.log(JSON.parse(JSON.parse(response.data))); + var file_error_data = JSON.parse(JSON.parse(response.data)); + var file_error_html = ""; + + for (var rkey in file_error_data) { + // console.log(rkey); + var col = file_error_data[rkey] + console.log(col); + + for (var ckey in col) + { + console.log(ckey); + console.log(col[ckey]); + var err_arr = col[ckey]; + if(Array.isArray(err_arr)){ + err_arr.forEach( function (item, index) {file_error_html += "Row "+ rkey +", "+ ckey+ " -" + item + "
"; } ); + } + + } + file_error_html += '-----------------------------------------------------------------------
'; + } + console.log(file_error_html); + $('#file-err-modal').find(".modal-body").html(file_error_html); + return file_error_html; + } catch (error) + { + console.error('Error parsing API response data:', error); + } + } else if(response.code === 404 && response.dataStatus === false){ + console.error('no data found', response); + } + else + { + console.error('Something went wrong!'); + } + }, + error: function(xhr, status, error) { + console.error('Error fetching data from API:', error); + } + }); + + $('#loader').hide(); + } + + function appendClients(data) { $.each(data, function(index, item) { $('#client_id').append($('