diff --git a/app/Config/Email.php b/app/Config/Email.php index 4dce650b..f7e3ae01 100644 --- a/app/Config/Email.php +++ b/app/Config/Email.php @@ -18,7 +18,7 @@ class Email extends BaseConfig /** * The mail sending protocol: mail, sendmail, smtp */ - public string $protocol = 'mail'; + public string $protocol = 'smtp'; /** * The server path to Sendmail. @@ -28,27 +28,27 @@ class Email extends BaseConfig /** * SMTP Server Hostname */ - public string $SMTPHost = ''; + public string $SMTPHost = 'mail.venbait.in'; /** * SMTP Username */ - public string $SMTPUser = ''; + public string $SMTPUser = 'bbone@venbait.in'; /** * SMTP Password */ - public string $SMTPPass = ''; + public string $SMTPPass = 'xk!L(N_-R#};'; /** * SMTP Port */ - public int $SMTPPort = 25; + public int $SMTPPort = 465; /** * SMTP Timeout (in seconds) */ - public int $SMTPTimeout = 5; + public int $SMTPTimeout = 1000; /** * Enable persistent SMTP connections @@ -62,7 +62,7 @@ class Email extends BaseConfig * to the server. 'ssl' means implicit SSL. Connection on port * 465 should set this to ''. */ - public string $SMTPCrypto = 'tls'; + public string $SMTPCrypto = 'ssl'; /** * Enable word-wrap @@ -77,7 +77,7 @@ class Email extends BaseConfig /** * Type of mail, either 'text' or 'html' */ - public string $mailType = 'text'; + public string $mailType = 'html'; /** * Character set (utf-8, iso-8859-1, etc.) @@ -118,4 +118,14 @@ class Email extends BaseConfig * Enable notify message from server */ public bool $DSN = false; + + + + /** + * SMTP Debugging level. Set to 0 to disable debugging. + * Set to 1 to output server connection status only. + * Set to 2 for more detailed debugging output. + * Set to 3 for maximum debugging output. + */ + public int $SMTPDebug = 2; } diff --git a/app/Config/Filters.php b/app/Config/Filters.php index 4f16d072..40324597 100644 --- a/app/Config/Filters.php +++ b/app/Config/Filters.php @@ -44,7 +44,7 @@ class Filters extends BaseConfig */ public array $globals = [ 'before' => [ - 'HttpRequestLog' => ['except' => 'processjob'], + 'HttpRequestLog' => ['except' => 'cli/*'], // 'csrf', // 'invalidchars', ], diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 06d67bd7..95e4900d 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -6,7 +6,7 @@ use CodeIgniter\Router\RouteCollection; * @var RouteCollection $routes */ // $routes->get('/', 'LoginController::index'); -$routes->get('/test', 'Home::test'); +$routes->get('/test', 'Home::index'); $routes->get('/login', 'LoginController::index');///auth/google $routes->get('/logout', 'LoginController::logout'); $routes->get('/oauth2callback', 'LoginController::receiveGoogleOAuthResponse'); @@ -191,13 +191,17 @@ $routes->group("/util", ["filter" => "authMVC"], function($routes){ $routes->post("import-export", "EmployeeController::importExport"); }); -$routes->cli('processjob', 'JobWorker::processJob'); +$routes->cli('cli/processjob', 'JobWorker::processJob'); +$routes->cli('cli/processjobs', 'JobWorker::processJobs'); -// $routes->get("/api", "RestAuthenticationController::index"); +//Employee login api's $routes->post("/employeeRest/verifyEmployeeNumber", "RestAuthenticationController::verifyEmployeeWithMobileNumber"); $routes->post("/employeeRest/getVerifiedUserData", "RestAuthenticationController::getVerifiedUserData"); +//HR login api's +$routes->post("/employeeRest/verifyHrWithMobileNumber", "RestAuthenticationController::verifyHrWithMobileNumber"); +$routes->post("/employeeRest/getVerifiedHrData", "RestAuthenticationController::getVerifiedHrData"); $routes->group("/api", ["filter" => "authJWT"], function($routes){ $routes->post("logined", "RestAuthenticationController::logined"); @@ -208,16 +212,23 @@ $routes->group("/api", ["filter" => "authJWT"], function($routes){ $routes->get("/getEmployeeProfile", "EmployeeRestController::getEmployeeProfile/$1"); $routes->post("/editEmployeeProfile", "EmployeeRestController::editEmployeeProfile"); -$routes->get("/getEmployeePolicy", "EmployeeRestController::getEmployeePolicy"); -$routes->post("/employeeUpload", "EmployeeRestController::employeeUpload"); + $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){ + $routes->post("employeeUpload", "EmployeeRestController::employeeUpload"); + $routes->get("relationshipList", "EmployeeRestController::relationshipList"); $routes->get("getEmployeeAndDependence", "EmployeeRestController::getEmployeeAndDependence"); $routes->post("editEmployeeAndDependence", "EmployeeRestController::editEmployeeAndDependence"); $routes->post("addEmployeeAndDependence", "EmployeeRestController::addEmployeeAndDependence"); - $routes->get("/relationshipList", "EmployeeRestController::relationshipList"); + + $routes->get("getEmployeePolicy", "EmployeeRestController::getEmployeePolicy"); + $routes->post("createOrUpdateEmployeePolicySiAmount", "EmployeeRestController::createOrUpdateEmployeePolicySiAmount"); + $routes->get("deleteDependence", "EmployeeRestController::deleteDependence"); + $routes->get("getEmployeeAndDependenceByClientId", "EmployeeRestController::getEmployeeAndDependenceByClientId"); + $routes->get("getClientPolicy", "EmployeeRestController::getClientPolicy"); }); +$routes->post("sendEmail", "EmployeeRestController::send_email"); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index ab1c21fc..392f362e 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -583,147 +583,194 @@ class ClientController extends AdminController public function createClientPolicyPremium() { - // print_r($this->request->getPost());die(); - $policy_type = $this->request->getPost('policy_type'); - $client_id = $this->request->getPost('client_id'); - $client_policy_id = $this->request->getPost('client_policy_id'); - $policy_grid_id = $this->request->getPost('policy_grid_id'); - $multiplier = $this->request->getPost('multiplier'); - $si_or_bp = $this->request->getPost('si_or_bp'); - $basic_multiplier = $this->request->getPost('basic_multiplier'); - $premium_multiplier =$this->request->getPost('premium_multiplier'); - $basic_pay = $this->request->getPost('basic_pay'); + try { + $policy_type = $this->request->getPost('policy_type'); + $client_id = $this->request->getPost('client_id'); + $client_policy_id = $this->request->getPost('client_policy_id'); + $policy_grid_id = $this->request->getPost('policy_grid_id'); + $si_or_bp = $this->request->getPost('si_or_bp'); + $basic_multiplier = str_replace(',', '', $this->request->getPost('basic_multiplier')); + $premium_multiplier = str_replace(',', '', $this->request->getPost('premium_multiplier')); + $multiplier = str_replace(',', '', $this->request->getPost('multiplier')); + $basic_pay = str_replace(',', '', $this->request->getPost('basic_pay')); + + $data=[]; + $data['client_id'] = $client_id; + $data['client_policy_id'] = $client_policy_id; + $data['policy_grid_id'] = $policy_grid_id; + - if($policy_type !== null && $policy_type !== ''){ + $premium = []; - $this->policyPremium1Model->where('client_id', $client_id)->where('client_policy_id', $client_policy_id)->set('is_active', 0)->update(); - - $premiumData = $this->request->getPost('premium'); - for ($i = 0; $i < count($premiumData); $i++) { - $data = [ - 'client_id' => $client_id, - 'client_policy_id' => $client_policy_id, - 'policy_grid_id' => $policy_grid_id, - 'created_by' => get_session_userid(), - ]; - - if(is_array($this->request->getPost('si'))){ - $si = isset($this->request->getPost('si')[$i]) ? $this->request->getPost('si')[$i] : null; - }else{ - $si = $this->request->getPost('si'); - } - - if(is_array($this->request->getPost('premium'))){ - $premium = isset($this->request->getPost('premium')[$i]) ? $this->request->getPost('premium')[$i] : null; - }else{ - $premium = $this->request->getPost('premium'); - } - // $basic_gpa_premium = isset($basic_gpa_premium[$i]) ? $basic_gpa_premium[$i] : null; - if ($si !== null) { - $data['si'] = $si; - } - if ($premium !== null) { - $data['premium'] = $premium; - } - - if ($multiplier !== null) { - $data['multiplier'] = $multiplier; - } - - if ($si_or_bp !== null) { - $data['si_or_bp'] = $si_or_bp; - } - - if ($premium_multiplier !== null) { - $data['multiplier'] = $premium_multiplier; - } - - if ($basic_multiplier !== null) { - $data['basic_multiplier'] = $basic_multiplier; - } - - if ($basic_pay !== null) { - $data['basic_pay'] = $basic_pay; - } - - $this->policyPremium1Model->insert($data); + if ($policy_grid_id == '1' || $policy_grid_id == '2') { + $this->policyPremium1Model->where('client_id', $client_id)->where('client_policy_id', $client_policy_id)->set('is_active', 0)->update(); + } else { + $this->policyPremium2Model->where('client_id', $client_id)->where('client_policy_id', $client_policy_id)->set('is_active', 0)->update(); + } + + + if($policy_grid_id == '1'){ + if ($si_or_bp == '1') { + $premium=str_replace(',', '', $this->request->getPost('gpa_sum_premium[]')); + $sum_insure=str_replace(',', '', $this->request->getPost('gpa_sum_si[]')); + $multiplier=$this->request->getPost('gpa_sum_multiplier'); + for ($i=0; $i < count($premium) ; $i++) { + $data['si'] = $sum_insure[$i]; + $data['premium'] = $premium[$i]; + $data['multiplier'] = $multiplier; + $data['si_or_bp'] = $this->request->getPost('si_or_bp'); + + $policyPremium= $this->policyPremium1Model->insert($data); + } + } else { + $data['premium'] = str_replace(',', '', $this->request->getPost('gpa_basic_premium')); + $data['si'] = str_replace(',', '', $this->request->getPost('gpa_basic_si')); + $data['basic_multiplier'] = str_replace(',', '', $this->request->getPost('basic_multiplier')); + $data['multiplier'] = $this->request->getPost('premium_multiplier'); + $data['basic_pay'] = str_replace(',', '', $this->request->getPost('basic_pay')); + $data['si_or_bp'] = $this->request->getPost('si_or_bp'); + + $policyPremium= $this->policyPremium1Model->insert($data); + } + $data = $this->request->getPost(); + $insert = true; + }else if($policy_grid_id == '2'){ + $data['premium'] = str_replace(',', '', $this->request->getPost('gpa_premium')); + $data['si'] = str_replace(',', '', $this->request->getPost('gpa_si')); + + $policyPremium= $this->policyPremium1Model->insert($data); + + $data = $this->request->getPost(); + $insert = true; + }else if($policy_grid_id == '3'){ + $premium=$this->request->getPost('3_premium[]'); + $sum_insure =$this->request->getPost('3_si[]'); + for ($i=0; $i < count($premium) ; $i++) { + $data['premium'] = str_replace(',', '',$premium[$i]); + $data['si'] = str_replace(',', '', $sum_insure[$i]); + $dataa= $this->policyPremium2Model->insert($data); + } + $data = $this->request->getPost(); + $insert = true; + }else if($policy_grid_id == '4'){ + $premium=$this->request->getPost('4_premium[]'); + $sum_insure =$this->request->getPost('4_si'); + $age_from =$this->request->getPost('4_age_from[]'); + $age_to =$this->request->getPost('4_age_to[]'); + for ($i=0; $i < count($premium) ; $i++) { + $data['premium'] = str_replace(',', '',$premium[$i]); + $data['si'] = str_replace(',', '', $sum_insure); + $data['age_from'] = $age_from[$i]; + $data['age_to'] = $age_to[$i]; + $dataa= $this->policyPremium2Model->insert($data); + } + $data = $this->request->getPost(); + $insert = true; + }else if($policy_grid_id == '5'){ + $premium=$this->request->getPost('5_premium[]'); + $sum_insure =$this->request->getPost('5_si[]'); + $age_from =$this->request->getPost('5_age_from[]'); + $age_to =$this->request->getPost('5_age_to[]'); + for ($i=0; $i < count($premium) ; $i++) { + $data['premium'] = str_replace(',', '',$premium[$i]); + $data['si'] = str_replace(',', '', $sum_insure[$i]); + $data['age_from'] = $age_from[$i]; + $data['age_to'] = $age_to[$i]; + $dataa= $this->policyPremium2Model->insert($data); + } + $data = $this->request->getPost(); + $insert = true; + }else if($policy_grid_id == '6'){ + $premium=$this->request->getPost('6_premium[]'); + $sum_insure =$this->request->getPost('6_si[]'); + $age_from =$this->request->getPost('6_age_from[]'); + $age_to =$this->request->getPost('6_age_to[]'); + for ($i=0; $i < count($premium) ; $i++) { + $data['premium'] = str_replace(',', '',$premium[$i]); + $data['si'] = str_replace(',', '', $sum_insure[$i]); + $data['age_from'] = $age_from[$i]; + $data['age_to'] = $age_to[$i]; + $dataa= $this->policyPremium2Model->insert($data); + } + $data = $this->request->getPost(); + $insert = true; + }else if($policy_grid_id == '7'){ + $premium=$this->request->getPost('7_premium[]'); + $sum_insure =$this->request->getPost('7_si[]'); + $age_from =$this->request->getPost('7_age_from[]'); + $age_to =$this->request->getPost('7_age_to[]'); + for ($i=0; $i < count($premium) ; $i++) { + $data['premium'] = str_replace(',', '',$premium[$i]); + $data['si'] = str_replace(',', '', $sum_insure[$i]); + $data['age_from'] = $age_from[$i]; + $data['age_to'] = $age_to[$i]; + $dataa= $this->policyPremium2Model->insert($data); + } + $data = $this->request->getPost(); + $insert = true; + }else if($policy_grid_id == '8'){ + $premium=$this->request->getPost('8_premium[]'); + $sum_insure =$this->request->getPost('8_si[]'); + $grade =$this->request->getPost('8_grade[]'); + for ($i=0; $i < count($premium) ; $i++) { + $data['premium'] = str_replace(',', '',$premium[$i]); + $data['si'] = str_replace(',', '', $sum_insure[$i]); + $data['grade'] = $grade[$i]; + $dataa= $this->policyPremium2Model->insert($data); + } + $data = $this->request->getPost(); + $insert = true; + }else if($policy_grid_id == '9'){ + $premium=$this->request->getPost('9_premium[]'); + $sum_insure =$this->request->getPost('9_si[]'); + $grade =$this->request->getPost('9_grade[]'); + for ($i=0; $i < count($premium) ; $i++) { + $data['premium'] = str_replace(',', '',$premium[$i]); + $data['si'] = str_replace(',', '', $sum_insure[$i]); + $data['grade'] = $grade[$i]; + $dataa= $this->policyPremium2Model->insert($data); + } + $data = $this->request->getPost(); + $insert = true; + }else if($policy_grid_id == '10'){ + $premium=$this->request->getPost('10_premium[]'); + $sum_insure =$this->request->getPost('10_si[]'); + $age_from =$this->request->getPost('10_age_from[]'); + $age_to =$this->request->getPost('10_age_to[]'); + for ($i=0; $i < count($premium) ; $i++) { + $data['premium'] = str_replace(',', '',$premium[$i]); + $data['si'] = str_replace(',', '', $sum_insure[$i]); + $data['age_from'] = $age_from[$i]; + $data['age_to'] = $age_to[$i]; + $policyPremium= $this->policyPremium2Model->insert($data); + } + $data = $this->request->getPost(); + $insert = true; + }else if($policy_grid_id == '11'){ + $premium=$this->request->getPost('11_premium[]'); + $sum_insure =$this->request->getPost('11_si[]'); + $grade =$this->request->getPost('11_grade[]'); + $max_sum_insure =$this->request->getPost('11_max_si[]'); + for ($i=0; $i < count($premium) ; $i++) { + $data['premium'] = str_replace(',', '',$premium[$i]); + $data['si'] = str_replace(',', '', $sum_insure[$i]); + $data['grade'] = $grade[$i]; + $data['max_si'] = $max_sum_insure[$i]; + $dataa= $this->policyPremium2Model->insert($data); + } + $data = $this->request->getPost(); + $insert = true; } - $data = $this->request->getPost(); - $insert = true; if($insert){ return $this->respond(['status' => true,'code' => 200,'data' => $data], 200); - }else{ + }else{ return $this->respond(['status' => false,'code' => 404, 'data' => $data,'message' => 'no data found'], 200); - - } - // print_r($data); - // die(); - // $data['created_by'] = get_session_userid(); - // $this->policyPremium1Model->where('client_id', $client_id)->where('client_policy_id', $client_policy_id)->set('is_active', 0)->update(); - // $insert = $this->policyPremium1Model->insert($data); - }else{ - - $this->policyPremium2Model->where('client_id', $client_id)->where('client_policy_id', $client_policy_id)->set('is_active', 0)->update(); - $premiumData = $this->request->getPost('premium'); - for ($i = 0; $i < count($premiumData); $i++) { - - $data = [ - 'client_id' => $client_id, - 'client_policy_id' => $client_policy_id, - 'policy_grid_id' => $policy_grid_id, - 'created_by' => get_session_userid(), - - ]; - - if(is_array($this->request->getPost('si'))){ - $si = isset($this->request->getPost('si')[$i]) ? $this->request->getPost('si')[$i] : null; - }else{ - $si = $this->request->getPost('si'); - } - $age_from = isset($this->request->getPost('age_from')[$i]) ? $this->request->getPost('age_from')[$i] : null; - $age_to = isset($this->request->getPost('age_to')[$i]) ? $this->request->getPost('age_to')[$i] : null; - $premium = isset($premiumData[$i]) ? $premiumData[$i] : null; - $grade = isset($this->request->getPost('grade')[$i]) ? $this->request->getPost('grade')[$i] : null; - $max_si = isset($this->request->getPost('max_si')[$i]) ? $this->request->getPost('max_si')[$i] : null; - - if ($si !== null) { - $data['si'] = $si; - } - - if ($age_from !== null) { - $data['age_from'] = $age_from; - } - - if ($age_to !== null) { - $data['age_to'] = $age_to; - } - - if ($premium !== null) { - $data['premium'] = $premium; - } - - if ($max_si !== null) { - $data['max_si'] = $max_si; - } - - if ($grade !== null) { - $data['grade'] = $grade; - } - - $this->policyPremium2Model->insert($data); - } - $data = $this->request->getPost(); - $insert = true; - } - - if($insert){ - return $this->respond(['status' => true,'code' => 200,'data' => $data], 200); - }else{ - return $this->respond(['status' => false,'code' => 404, 'data' => $data,'message' => 'no data found'], 200); - - } - + } + } catch (Exception $e) { + // Handle exceptions here + echo 'Error: ' . $e->getMessage(); + } } @@ -787,6 +834,8 @@ class ClientController extends AdminController $client_policy_id = $this->request->getGet('client_policy_id'); $record = $this->clientPolicyModel->where('id', $client_policy_id)->first(); + $family_floater=json_decode($record['policy_terms'])->family_floater; + $emp_count = $this->employeeModel ->join('client_policy cp',"employees.client_id = cp.client_id") ->join('employee_polices ep',"cp.id = ep.client_policy_id AND employees.id = ep.employee_id") ->where("employees.client_id",$record['client_id']) @@ -816,14 +865,30 @@ class ClientController extends AdminController }else{ $premiumData = $this->policyPremium2Model->where(['client_id' => $record['client_id'], 'client_policy_id' => $client_policy_id, 'is_active' => 1])->findAll(); } - - // echo '
';
-        // print_r($results);
+        // echo $family_floater;
+        $resultss = [];
+        if ($family_floater == 1) {
+
+            foreach ($results as $index => $record) {
+                if ($index == '8' || $index == '7') {
+                     // Clearing the $results array
+                    $resultss[$index] = $record; 
+                }
+            }
+        }else{
+            foreach ($results as $index => $record) {
+                if ($index == '0' || $index == '1' || $index == '2' || $index == '3' || $index == '4' || $index == '5' || $index == '6') {
+                    // Clearing the $results array
+                   $resultss[$index] = $record; 
+               }
+            }
+        }
+
         // print_r($data[0]->policy_type); die;
                     // echo "hello";
-            // print_r($premiumData);
-        return $this->respond(['status' => true,'code' => 200,'data' => $results, 'premiumData' => $premiumData, 'count' => $emp_count, 'policy_name' => $policy_name], 200);
+            // return json_encode($premiumData);
+        return $this->respond(['status' => true,'code' => 200,'data' => $resultss, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name,], 200);
 
     }
 
@@ -834,6 +899,7 @@ class ClientController extends AdminController
             
             $this->myLogger->logme('error','Terms CREATE function called');
             
+
             /*** Client Policy Table Primary Key(ID) ***/
             $client_policy_id = $this->request->getPost("client_policy_id");
 
@@ -842,6 +908,9 @@ class ClientController extends AdminController
                 $data['corporatebuffer'] = $this->request->getPost("corporatebuffer");
                 $data['family_floaters'] = $this->request->getPost("family_floaters") ?? [];                
 
+                if (!in_array("self", $data['family_floaters'])) {
+                    array_unshift($data['family_floaters'], "self");
+                }
             $data['waiverofpreexistingdiseases']   =$this->request->getPost("waiverofpreexistingdiseases");
             if ($data['waiverofpreexistingdiseases'] == 1) {
                 $data['maternitycoverage']   =$this->request->getPost("maternitycoverage");
diff --git a/app/Controllers/EmployeeModel.php b/app/Controllers/EmployeeModel.php
new file mode 100644
index 00000000..52382dc1
--- /dev/null
+++ b/app/Controllers/EmployeeModel.php
@@ -0,0 +1,57 @@
+db->table('employee_polices')
+                        ->select(' policies.name as Policy_Name , client_policy.policy_terms as Policy_Terms, client_policy.client_id as ClientId, client_policy.policy_id as PolicyId,client_policy.id as ClientPolicyId, client_policy.open_for_enrollment as OpenForEnrollment') // Select all columns from both tables
+                        ->join('client_policy', 'client_policy.id = employee_polices.client_policy_id')
+                        ->join('policies', 'policies.id = client_policy.policy_id')
+                        ->where('employee_polices.employee_id', $id)
+                        ->get()
+                        ->getResult();
+   }
+
+
+
+
+    // 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();
+    }
+
+}
diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php
index 8692e2df..51ab6236 100644
--- a/app/Controllers/EmployeeRestController.php
+++ b/app/Controllers/EmployeeRestController.php
@@ -2,6 +2,8 @@
 
 namespace App\Controllers;
 
+use App\Helpers\MailHelper;
+
 use CodeIgniter\HTTP\IncomingRequest;
 use CodeIgniter\HTTP\RequestInterface;
 use CodeIgniter\HTTP\ResponseInterface;
@@ -13,7 +15,16 @@ use App\Models\EmployeePolicyModel;
 use App\Models\ClientModel;
 use App\Models\PolicesModel;
 use App\Models\RelationshipModel;
+use App\Models\FileModel;
+use App\Models\ClientPolicyModel;
 
+use App\Controllers\Jobs ;
+use App\Controllers\JobWorker ;
+
+
+use PhpOffice\PhpSpreadsheet\Spreadsheet;
+use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
+use PhpOffice\PhpSpreadsheet\IOFactory;
 
 use CodeIgniter\API\ResponseTrait;
 use Illuminate\Http\Request;
@@ -31,6 +42,7 @@ class EmployeeRestController extends AdminController
     protected $fileModel;
     protected $policesModel;
     protected $relationshipModel;
+    protected $clientPolicyModel;
 
     public function __construct()
     {
@@ -42,6 +54,8 @@ class EmployeeRestController extends AdminController
         $this->clientModel = new ClientModel();
         $this->policesModel = new PolicesModel();
         $this->relationshipModel = new RelationshipModel();
+        $this->fileModel= new FileModel();
+        $this->clientPolicyModel = new ClientPolicyModel();
     }
 
   
@@ -63,7 +77,7 @@ class EmployeeRestController extends AdminController
        } catch (\Throwable $th) {
         return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500);
        }
-   }
+    }
 
 
     public function editEmployeeProfile()
@@ -94,14 +108,20 @@ class EmployeeRestController extends AdminController
         try {
             $emp_code = $this->request->getGet('emp_code');
             if ($emp_code) {
-                $employee = $this->employeeModel->where('emp_code', $emp_code)
-                                                ->findAll();
-                
-                $result = $employee;
-                    return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
+                $employee = $this->employeeModel->where('emp_code', $emp_code)->findAll();
+                $dateConverter = function($item) {
+                    if ($item['dob'] !== '0000-00-00') {
+                        $dateTime = \DateTime::createFromFormat('Y-m-d', $item['dob']);
+                        $item['dob'] = $dateTime->format('d-m-Y');
+                    }
+                    return $item;
+                };
+                $employee = array_map($dateConverter, $employee);
+                return $this->respond(['status' => 'success','code' => 200,'data' => $employee],200);
+
             } else {
-                $result = "No Match's";
-                    return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404);
+                
+                return $this->respond(['status' => 'failed','code' => 404,'data' => []],404);
             }
        } catch (\Throwable $th) {
         return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500);
@@ -118,6 +138,7 @@ class EmployeeRestController extends AdminController
                 $updatedCount = 0;
                 foreach ($data as $item) {
                     $id = $item->id;
+                    $item->dob = $this->convertDateFormat($item->dob);
                     $employee = $this->employeeModel->update($id, (array)$item);
                     if ($employee) {
                         $updatedCount++;
@@ -138,32 +159,38 @@ class EmployeeRestController extends AdminController
         
     }
 
-
+    
     public function addEmployeeAndDependence()
     {
         try {
             $data = $this->request->getJSON();
            
-
             if ($data) {
-                $updatedCount = 0;
+                $Count = 0;
                 foreach ($data as $item) {
-                    $extractData['name'] = $item->name;
-                    $extractData['emp_code']= $item->emp_code;
-                    $extractData['email_corporate']=$item->email_corporate;
-                    $extractData['relationship_code']=$item->relationship_code;
-                    $extractData['mobile']=$item->mobile;
-                    $extractData['gender']=$item->gender;
-                    $extractData['dob']=$item->dob;
-                    $extractData['client_id']=$item->client_id;   
-                    // print_r($extractData);die();
-                    $employee = $this->employeeModel->insert($extractData);
-                    if ($employee) {
-                        $updatedCount++;
-                    }
+                    if (isset($item->id)) {
+                        //update old data
+                        $id = $item->id;
+                        $item->family_floater_key = $this->RelationshipMap($item->relationship);
+                        $item->dob = $this->convertDateFormat($item->dob);
+                        $employee = $this->employeeModel->update($id, (array)$item);
+                        if ($employee) {
+                            $Count++;
+                        }
+                      }else{
+                        //create new data
+                        $item->family_floater_key = $this->RelationshipMap($item->relationship);
+                        $item->dob = $this->convertDateFormat($item->dob);
+                        $employee = $this->employeeModel->insert($item);
+                        if ($employee) {
+                            $Count++;
+                        }
+
+                      }
+                    
                 }
     
-                if ($updatedCount > 0) {
+                if ($Count > 0) {
                     $result = [];
                     return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200);
                 } else {
@@ -177,29 +204,220 @@ class EmployeeRestController extends AdminController
         
     }
 
+    public function RelationshipMap($value){
+       
+            if ($value === 'Mother' || $value === 'Father') {
+                return  'parent';
+            } else if($value === 'Son' || $value === 'Daughter'){
+                return 'child';
+            }else if($value === 'Father in Law' || $value === 'Mother in Law'){
+                return 'parent_in_law';
+            }else if($value === 'Spouse'){
+                return 'spouse';
+            }
+    }
+
+    private function convertDateFormat($dateString)
+    {
+        // Attempt to create a DateTime object from the provided date string
+        $dateTime = \DateTime::createFromFormat('d-m-Y', $dateString);
+
+        // Check if the conversion was successful and the date string is in the format dd-mm-yyyy
+        if ($dateTime instanceof \DateTime) {
+            // Format the date to yyyy-mm-dd
+            return $dateTime->format('Y-m-d');
+        } else {
+            // If the date string is not in the format dd-mm-yyyy, return null
+            return null;
+        }
+    }
+    public function deleteDependence()
+    {
+        try {
+            if($this->request->getGet('id'))
+            {
+                $delete  = $this->employeeModel->where('id', $this->request->getGet('id'))->delete();
+    
+                if ($delete) {
+                    return $this->respond(['status' => 'success','code' => 200,'data' =>[] ], 200);
+                } else {
+                    return $this->respond(['status' => 'failed','code' => 404,'data' => [] ], 404);
+                }
+            }else{
+                return $this->respond(['status' => 'failed','code' => 404,'data' => [] ], 404);
+            }
+               
+            
+        } catch (\Exception $e) {
+            return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
+        }
+        
+    }
+
+
+    public function getEmployeeAndDependenceByClientId()
+    {
+        try {
+            $empData =   $this->employeePolicyModel->getEmployeePolicy( $this->request->getGet('client_id'), $this->request->getGet('client_policy_id'));
+            // $empData = $this->employeeModel->where('client_id', $this->request->getGet('client_id'))
+            //                                ->where('relationship !=', null)
+      
+            if ($empData) {
+                return $this->respond(['status' => 'success', 'code' => 200, 'data' => $empData], 200);
+            } else {
+                return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 404);
+            }
+        
+            
+        } catch (\Exception $e) {
+            return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
+        }
+        
+    }
+
+    public function getClientPolicy()
+    {
+        try {
+            $ClientPolicyData =  $this->clientPolicyModel->select('client_policy.id as client_policy_id , client_policy.client_id as client_id, policies.id as policy_id,policies.policy_type_id as policy_type_id, policies.name as policy_name')
+                                                        ->join('policies', 'client_policy.policy_id = policies.id', 'left')
+                                                        ->where('client_policy.client_id', $this->request->getGet('client_id') )
+                                                        ->findAll();
+
+            $result[] = $ClientPolicyData[0];
+            $result[] = $ClientPolicyData[2];
+            // You probably meant to check $result, not $data
+            if ($ClientPolicyData) {
+                return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result], 200);
+            } else {
+                return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 404);
+            }
+        
+            
+        } catch (\Exception $e) {
+            return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
+        }
+        
+    }
+
 
     public function getEmployeePolicy()
     {            
-        $id= 1;
         try {
-            $keysToRemove  = ["sum_insured","family_floater","corporatebuffer","family_floaters"];
+            $id = $this->request->getGet('id');
+            $emp_code = $this->request->getGet('emp_code');
+          
+            $keysToRemove  = ["removable_keys"];
 
             $empPolicy = $this->employeeModel->getEmployeePolicy($id);
+
+            $empData = $this->employeeModel->where('emp_code',$emp_code)->findAll();
             if ($empPolicy) {
 
                 $result = [];
                 foreach ($empPolicy as $array) { 
+                    
                     $decodedArray = json_decode($array->Policy_Terms);
                     $refusingData = (object) array_diff_key((array) $decodedArray, array_flip($keysToRemove));
 
-                    // $client_id =$array->ClientId;
-                    // $policy_id =$array->PolicyId;
-
-                    // $rackRate = $this->policesModel->getPolicySlabRatesForEmpOnboard($policy_id, $client_id);
-
-                    // $array->Policy_Terms = json_encode($refusingData);
+                    
                     $array->Policy_Terms = $refusingData;
+                    $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($array->ClientPolicyId,$array->ClientId);
+                    $array->SlabRates = $getSlabAndGridData['slab_rates'];
+                    $array->GridMaster = $getSlabAndGridData['grid_master'];
 
+                    if($getSlabAndGridData['grid_master']['policy_type'] == "GPA"){
+                        $default_si = $array->Policy_Terms->sumInsured2;
+                        $index = -1;
+                        foreach ($array->SlabRates as $key => $value) {
+                            if ($value['si'] == $default_si) {
+                                $index = $key;
+                                break;
+                            }
+                        }
+                        if ($index >= 0) {
+                            $element =$array->SlabRates[$index];
+                            array_splice($array->SlabRates, $index, 1);
+                            array_unshift($array->SlabRates, $element);
+                        }
+
+                        $employee_policy = $this->employeePolicyModel->where('employee_id',$id)->where('client_policy_id',$array->ClientPolicyId)->get()->getRow();
+                        if($employee_policy){
+                            $gpaSI['family_floater_key'] = 'self';
+                            $gpaSI['label'] = 'Self';
+                            $gpaSI['employee_id'] =  $employee_policy->employee_id;
+                            $gpaSI['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null;
+                            $gpaSI['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null;
+                            $gpaSI['client_policy_id'] = $array->ClientPolicyId;  
+
+                            $array->mapped_family_floaters = $gpaSI;
+                        }else{
+                            $gpaSI['family_floater_key'] = 'self';
+                            $gpaSI['label'] = 'Self';
+                            $gpaSI['employee_id'] =  $id;
+                            $gpaSI['basic_cover_si'] = null;
+                            $gpaSI['premium'] =  null;
+                            $gpaSI['client_policy_id'] = $array->ClientPolicyId;  
+
+                            $array->mapped_family_floaters = $gpaSI;
+                        }
+
+                    }else if($getSlabAndGridData['grid_master']['policy_type'] == "GMC"){
+
+                        // re-arranging order of si
+                        $default_si = $array->Policy_Terms->sum_insured;
+                        // Filter the array using the callback function
+                        $getPremium = array_filter($array->SlabRates ,  function ($value) use ($default_si) { return $value['si'] == $default_si;  } );
+                        $default_premium =  $getPremium[0]['premium'];
+
+                        $index = -1;
+                        foreach ($array->SlabRates as $key => $value) {
+                            if ($value['si'] == $default_si) {
+                                $index = $key;
+                                break;
+                            }
+                        }
+                        if ($index >= 0) {
+                            $element =$array->SlabRates[$index];
+                            array_splice($array->SlabRates, $index, 1);
+                            array_unshift($array->SlabRates, $element);
+                        }
+
+                        //map family floates array to employee and dependent
+                        $familyFloates = $array->Policy_Terms->family_floaters;
+                        $data = [];
+                        foreach ($familyFloates as $familyFloatesValue) { 
+                            $dependent =   preg_replace('/\d/', '', $familyFloatesValue);
+                            if(count($empData)){
+                                foreach ($empData as $key => $value) {
+                                    if ($value['family_floater_key'] === $dependent) {
+                                        $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array->ClientPolicyId)->get()->getRow();
+                                        $temp['family_floater_key'] = $familyFloatesValue;
+                                        $temp['label'] = $value['relationship'];
+                                        $temp['name'] = $value['name'];
+                                        $temp['employee_id'] = $value['id'];
+                                        $temp['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null;
+                                        $temp['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null;
+                                        $temp['client_policy_id'] = $array->ClientPolicyId;               
+                                        array_push($data,$temp);
+                                        unset($empData[$key]);
+                                        break;
+                                    }
+                                }
+                            }
+                        }
+                        $array->mapped_family_floaters = $data;
+
+                        $temp2=[];
+                        foreach ($array->SlabRates as $key => $value) {
+                           $value['additional_premium'] = $value['premium'] -  $default_premium;
+                           array_push($temp2,$value);
+                        }
+                        $array->SlabRates  =  $temp2;
+
+                       
+
+                    }
+                    
                     $result[] = $array;
                 }
                 return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200);             
@@ -211,6 +429,42 @@ class EmployeeRestController extends AdminController
         }
     }
 
+    // Get the RelationShip list
+
+    public function createOrUpdateEmployeePolicySiAmount()
+    {            
+        
+        try {
+            $requestData = $this->request->getJSON();
+           
+            foreach ($requestData as $key => $value) {
+
+            
+            $checkIfExist = $this->employeePolicyModel->where('employee_id', $value->employee_id)
+                                                   ->where('client_policy_id', $value->client_policy_id)
+                                                   ->findAll();
+            // dd($checkIfExist);
+            if ($checkIfExist) {
+
+                    $empPolicy = $this->employeePolicyModel->updateSiAndPremium($value->client_policy_id,  $value->employee_id, $value->basic_cover_si,$value->premium);
+
+                }else{
+
+                    $data['employee_id']= $value->employee_id;
+                    $data['client_policy_id']= $value->client_policy_id;
+                    $data['basic_cover_si']= $value->basic_cover_si;
+                    $data['premium']= $value->premium;
+            
+                    $this->employeePolicyModel->insert($data);
+                }
+            }
+                return $this->respond(['status' => 'success','code' => 200,'data' => []], 200);             
+           
+        } catch (\Exception $e) {
+            return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
+        }
+    }
+
 
     public function relationshipList()
     {
@@ -229,56 +483,225 @@ class EmployeeRestController extends AdminController
         }
     }
 
-
+    // Upload the Sheet Data in DB
     public function employeeUpload()
     {
-        if ($this->request->getFile('file')) {
-            // Load PHPExcel library
-            require_once APPPATH . 'third_party/PHPExcel/PHPExcel.php';
-    
-            // Load the uploaded file
-            $file = $this->request->getFile('file');
-    
-            // Load file into PHPExcel
-            $inputFileType = PHPExcel_IOFactory::identify($file->getPathname());
-            $objReader = PHPExcel_IOFactory::createReader($inputFileType);
-            $objPHPExcel = $objReader->load($file->getPathname());
-    
-            // Get the active sheet
-            $sheet = $objPHPExcel->getActiveSheet();
-    
-            // Get the highest row number
-            $highestRow = $sheet->getHighestRow();
-    
-            // Assuming your data starts from the second row (after headers)
-            for ($row = 2; $row <= $highestRow; $row++) {
-                // Get cell values
-                $name = $sheet->getCellByColumnAndRow(0, $row)->getValue();
-                $email = $sheet->getCellByColumnAndRow(1, $row)->getValue();
-                // Assuming you have more columns, adjust indexes accordingly
-    
-                // Store data into database (Example using CodeIgniter's database methods)
-                $data = array(
-                    'name' => $name,
-                    'email' => $email,
-                    // Add more fields as necessary
-                );
-                // Insert data into the database table
-                $this->db->insert('employees', $data);
-            }
-    
-            // Optionally, you can delete the uploaded file after processing
-            unlink($file->getPathname());
-    
-            // Optionally, you can redirect the user to a success page
-            redirect('employee/success');
-        } else {
-            // Handle case when no file was uploaded
-            echo 'No file uploaded!';
+        $file = $this->request->getFile('file');
+        $client_id = $this->request->getPost('client_id');
+        $policy_id = $this->request->getPost('policy_id');
+
+        $is_moved = $file->move(WRITEPATH . 'uploads/import_excel');
+        $filename = $file->getName();
+        $file_name_with_path = WRITEPATH."/uploads/import_excel/".$filename;
+
+        //check the file exist or not
+        if(!file_exists($file_name_with_path))
+        {
+            session()->setFlashdata('error', 'File not found');
+            return redirect()->to(base_url('employee/upload'));
         }
+        // Load the Excel file
+        $spreadsheet = IOFactory::load($file_name_with_path);
+
+        // Get the active sheet
+        $sheet = $spreadsheet->getActiveSheet();
+
+        // Get the highest row and column numbers
+        $highestRow = $sheet->getHighestRow();
+        $highestColumn = $sheet->getHighestColumn();
+
+        $highestRowAndColumn = $sheet->getHighestRowAndColumn();
+        $data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']);
+        // print_r($excel_data);die();
+        // $data = [];
+        // $data[] =$excel_data;
+
+        // print_r($data);die;
+        // Iterate through each row
+        // for ($row = 1; $row <= $highestRow; $row++) {
+        //     // Initialize the row data array
+        //     $rowData = [];
+
+        //     // Iterate through each column in the row
+        //     for ($col = 'A'; $col <= $highestColumn; $col++) {
+        //         // Get the cell value
+        //         $value = $sheet->getCell($col . $row)->getValue();
+        //         // print_r($value);
+        //         // Add the cell value to the row data array
+        //         $rowData[] = $value;
+        //     }
+
+        //     // Add the row data to the main data array
+        //     $data[] = $rowData;
+        // }
+        // print_r($data);die;
         
+        $extractData['file_name']= $filename;
+        $extractData['client_id']= $client_id;
+        $extractData['status']= 'success';
+        $extractData['policy_id']= $policy_id;
+        $extractData['action']= 'enrollment';
+        //  $extractData['created_by']=set_session_context('Employee');
+
+        $file_data =$this->fileModel->insert($extractData);
+
+        $extra = [];
+        //this change the column name into index number
+        for ($i = 0; $i < count($data[0]); $i++) {
+            $data[0][$i] = $i;
+        }
+        for ($i = 0; $i < count($data); $i++) {
+            if ($i == 0) {
+                // Loop through the first row to extract keys
+                for ($j = 0; $j < count($data[$i]); $j++) {
+                    $extra[$data[$i][$j]] = []; // Initialize keys with empty array
+                }
+            } else {
+                // Loop through subsequent rows
+                for ($j = 0; $j < count($data[$i]); $j++) {
+                    // Append values to corresponding keys in $extra
+                    if (isset($extra[$data[0][$j]])) {
+                        // Make sure the key exists in the $extra array
+                        $extra[$data[0][$j]][] = $data[$i][$j];
+                    }
+                }
+            }
+        }
+        // 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') {
+                $relation = 'parent';
+            } else if($extra['5'][$index] === 'Son' || $extra['5'][$index] === 'Daughter'){
+                $relation = 'child';
+            }else if($extra['5'][$index] === 'Father in Law' || $extra['5'][$index] === 'Mother in Law'){
+                $relation = 'parent_in_law';
+            }else if($extra['5'][$index] === 'Spouse'){
+                $relation = 'spouse';
+            }else{
+                $relation = 'self';
+            }
+            
+            // Simplified formatDate function
+
+
+            // Assigning formatted dates
+            // print_r($extra['3']);die;
+            $doj = $extra['3'][$index] ;
+            $dob = $extra['6'][$index] ;
+
+
+            // Change date format for $doj
+            $doj_new_format = date('Y-m-d', strtotime($doj)); // $doj_new_format will be "2001-02-12"
+
+            // Change date format for $dob
+            $dob_new_format = date('Y-m-d', strtotime($dob));
+
+            // Your existing code here
+            
+            $emp_code =isset($extra['1'][$index]) ? $extra['1'][$index] : 0;
+            $name = $extra['2'][$index];
+
+            // print_r("--" . $emp_code. "---");
+            // print_r( $emp_code != 0 );
+            if($emp_code != 0 && $name != '' || $name != null){
+                $record = [
+                    // 'id' => $id,
+                    'emp_code' => $emp_code,
+                    'name' => $name,
+                    // Check if the 'doj' key exists before accessing it
+                    'doj' => $doj_new_format,
+                    'gender' => $extra['4'][$index],
+                    'relationship' => ucfirst($extra['5'][$index]),
+                    'family_floater_key' => $relation,
+                    'dob' => $dob_new_format,
+                    'email_corporate' => $extra['7'][$index],
+                    'mobile'=> $extra['8'][$index],
+                    'client_id' => $client_id,
+                    'emp_status'=>'draft'
+                    
+                ];
+                $record2 = [
+                    'basic_cover_si' => isset($extra['9'][$index]) ? $extra['9'][$index] : 0,
+                ];
+                $dataToInsert[] = $record;
+                $basic_cover_si[]= $record2;
+            }
+        }
+        for ($a=0; $a employeeModel->checkExistingEmpEntrollment($dataToInsert[$a]);
+                    $emp_id =0;
+
+                    if ($employee) {
+                        $emp_id =$employee['id'];
+                        $id =$emp_id;
+                        $result = $this->employeeModel->update($id, $dataToInsert[$a]);
+                        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]);
+                            $emp_id =$result;
+                            if ($result) {
+                                $emp = $this->employeeModel->where('id', $result)->get()->getResult();
+
+                                $policy_name = $this->employeePolicyModel->where('employee_id', $result)->get()->getResult();;
+                                
+                                
+                                $log_message = 'Insert Employee- '.$dataToInsert[$a]['name'] .'('.$dataToInsert[$a]['emp_code'] .') with PK ';
+                                $this->myLogger->logme('error',('Insert - ' .  $dataToInsert[$a]['emp_code'] .' - '. $dataToInsert[$a]['name']));
+                            }
+                        }
+                    }
+                    $emp_policy_data =[
+                        'employee_id'=>$emp_id,
+                        'client_policy_id'=>$policy_id,
+                        'status'=> 'draft',
+                        'basic_cover_si'=> $basic_cover_si[$a]
+                    ];
+
+                    $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);
+                        }
+                    } else {
+                        $emp_policy = $this->employeePolicyModel->insert($emp_policy_data);
+                    }
+
+
+            //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']; + + $message = view('mail_welcome', $data); + // if ($dataToInsert[$a]['email_corporate'] != null || $dataToInsert[$a]['email_corporate'] != '' && $dataToInsert[$a]['relationship'] == 'Self') { + // $job_details = new Jobs(); + // $r = Jobs::addJob(['job_name' => 'send_email','payload' => ['mail' => $mail, 'subject' => $subject,'message'=> $message]]); + // } + + // print_r($r);//die(); + // $jobWorker = new JobWorker(); + //JobWorker::processJob($r); + // $return_log = MailHelper::send_email($mail,$subject, $message); + // $return_log = json_decode($return_log); + // $this->myLogger->logme('info', "Email Status : {mail_status}, Sender Email:{email}", ['mail_status' => $return_log->status, 'email'=> $return_log->data]); + } } + } \ No newline at end of file diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php index 9280fa95..9f76bf77 100644 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -6,7 +6,7 @@ class Home extends PublicController { public function index(): string { - return view('welcome_message'); + return view('mail_welcome'); } public function test() diff --git a/app/Controllers/JobWorker.php b/app/Controllers/JobWorker.php index f3a2ab2a..964d365a 100644 --- a/app/Controllers/JobWorker.php +++ b/app/Controllers/JobWorker.php @@ -14,7 +14,7 @@ class JobWorker extends AdminController * Constructs the class */ - private static $event_class_mapping = ['add' => ['type' => 'HC','handler' => 'App\\Helpers\\HttpRequestHelper'], 'sub' => ['type' => 'CC','handler' => 'App\\Controllers\\Jobs\SubJob'],'fancy_date_time_format' => [ 'type' => 'HF','handler' => 'fancy_date_time_format'],'addNumber' => ['type' => 'HC','handler' => 'App\\Model\\HttpRequestHelper'],'excelFileFormatValidation' => ['type' => 'CC','handler' => 'App\\Controllers\\EmployeeServiceController'],'excelFileDataValidation' => ['type' => 'CC','handler' => 'App\\Controllers\\EmployeeServiceController'],'employeeOnboard' => ['type' => 'CC','handler' => 'App\\Controllers\\EmployeeServiceController']]; + private static $event_class_mapping = ['add' => ['type' => 'HC','handler' => 'App\\Helpers\\HttpRequestHelper'], 'sub' => ['type' => 'CC','handler' => 'App\\Controllers\\Jobs\SubJob'],'fancy_date_time_format' => [ 'type' => 'HF','handler' => 'fancy_date_time_format'],'addNumber' => ['type' => 'HC','handler' => 'App\\Model\\HttpRequestHelper'],'excelFileFormatValidation' => ['type' => 'CC','handler' => 'App\\Controllers\\EmployeeServiceController'],'excelFileDataValidation' => ['type' => 'CC','handler' => 'App\\Controllers\\EmployeeServiceController'],'employeeOnboard' => ['type' => 'CC','handler' => 'App\\Controllers\\EmployeeServiceController'],'send_email' => ['type' => 'HC','handler' => 'App\\Helpers\\MailHelper']]; public function __construct() { // echo 'HiC';//die(); @@ -27,12 +27,39 @@ class JobWorker extends AdminController // } } + public static function processJobs(array $jobdata = []) + { + // echo 'listen';//die(); + $query = " + SELECT id, name, payload, uuid + FROM jobs + WHERE status=? + ORDER BY created_dt ASC"; + $where_condition = [self::STATUS_QUEUED]; + $db = \Config\Database::connect(); + $jobs = $db->query($query, $where_condition)->getResult(); + + if(count($jobs)) + { + // echo count($jobs); + // print_r($jobs);die; + foreach($jobs as $key => $job) + { + // echo $job->id.' - '.$job->name; + //sleep(1); + + SELF::processjob(['id' => $job->id,'uuid' => $job->uuid]); + } + } + } /** * process jobs */ public static function processJob(array $jobdata = []) { - // echo 'listen';//die(); + // print_r($jobdata); + // echo 'listen'; + // die(); $query = " SELECT id, name, payload, uuid FROM jobs @@ -61,7 +88,9 @@ class JobWorker extends AdminController echo "\nProcessing job id - " . $job->id . "\n"; echo "Job name - " . $job->name . "\n"; - + // print_r(SELF::$event_class_mapping); + // echo array_key_exists($job->name,SELF::$event_class_mapping) ? 'mapped' : 'notmapped'; + // die(); try { $start = microtime(true); @@ -69,7 +98,7 @@ class JobWorker extends AdminController $job_status = self::STATUS_RUNNING; $db->query("UPDATE jobs SET status=? WHERE id=? AND uuid=?", [$job_status, $job->id,$job->uuid]); - if (!array_key_exists($job->name,SeLf::$event_class_mapping)) + if (!array_key_exists($job->name,SELF::$event_class_mapping)) { throw new \RuntimeException('Job ' . $job->name . ' handler not registered'); } @@ -145,6 +174,7 @@ class JobWorker extends AdminController // echo "Job $job->id $job_status. Response - $response \n"; echo "Job $job->id $job_status \n"; + return true; } else { diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index ac43c791..61ef2ff6 100644 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -20,6 +20,7 @@ use CodeIgniter\API\ResponseTrait; use App\Models\EmployeeModel; use App\Models\AuthHistoryModel; +use App\Models\LevelContactModel; use Firebase\JWT\JWT; // require_once('../vendor/autoload.php'); @@ -33,6 +34,7 @@ class RestAuthenticationController extends AdminController protected $myLogger; protected $employeeModel; protected $authHistoryModel; + protected $hrModel; public function __construct() @@ -42,6 +44,7 @@ class RestAuthenticationController extends AdminController $this->employeeModel = new EmployeeModel(); $this->authHistoryModel = new AuthHistoryModel(); + $this->hrModel = new LevelContactModel(); } @@ -67,6 +70,7 @@ class RestAuthenticationController extends AdminController try { $mobile_number = $this->request->getJSON()->mobile_number; $randomNumber = rand(100000, 999999); + $randomNumber = 123456; $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); @@ -121,6 +125,68 @@ class RestAuthenticationController extends AdminController } } + public function verifyHrWithMobileNumber() + { + try { + $mobile_number = $this->request->getJSON()->mobile_number; + $randomNumber = rand(100000, 999999); + $randomNumber = 123456; + $HrData = $this->hrModel->where('mobile', $mobile_number)->where('contact_type', 'client')->first(); + + if ($HrData) { + $id= $HrData["id"]; + $otp = $this->hrModel->where('id', $id)->set('otp', $randomNumber)->update(); + $result = ['user_verification' => true , 'otp'=>$randomNumber]; + return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); + } else { + $result = ['user_verification' => false]; + return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404); + + } + } catch (\Throwable $th) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); + } + } + + + public function getVerifiedHrData() + { + try { + $mobile_number = $this->request->getJSON()->mobile_number; + $otp = $this->request->getJSON()->otp; + + $hrData = $this->hrModel->where('mobile', $mobile_number)->first(); + if ($hrData && $otp == $hrData["otp"]) { + $auth = HttpRequestHelper::getRequestInfo(); + if ($auth) { + $data = [ + 'user_id' => $hrData['id'], + 'user_type' => 'hr', + 'ip' => $auth['ip'], + 'platform' => $auth['platform'], + 'broswer' => $auth['browser'], + ]; + + $authdata= $this->authHistoryModel->insert($data); + + } + $otp_null = $this->hrModel->where('id', $hrData["id"])->set('otp', null)->update(); + + $hrData = $this->hrModel ->select('level_contacts.* , client_branch.client_id as client_id') + ->join('client_branch', 'level_contacts.ref_id = client_branch.id', 'left') + ->where('level_contacts.mobile', $mobile_number ) + ->find(); + + $result = JWTToken::encode($hrData['0']); + return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); + } else { + return $this->respond(['status' => 'failed','code' => 404,'data' => "No data"],404); + } + } catch (\Exception $e) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500); + } + } + public function employeeLogout() diff --git a/app/Helpers/MailHelper.php b/app/Helpers/MailHelper.php new file mode 100644 index 00000000..9709de46 --- /dev/null +++ b/app/Helpers/MailHelper.php @@ -0,0 +1,41 @@ +setMailType('html'); + $email->setFrom('bbone@venbait.in', 'Nhance'); + + $email->setTo($emaill); + + $email->setSubject($subject); + $email->setMessage($message); + + if ($email->send()) { + return json_encode(['status' => 'success','code' => 200, 'message'=>'Email Sent Successfully...','data' => $emaill,],200); + } else { + return json_encode(['status' => 'failed','code' => 404,'message'=>'Email Sent Failed...','data' => $emaill ],404); + } + + } catch (Exception $e) { + return json_encode(['status' => 'failed','code' => 500,'data' => $emaill],500); + } + } +} +?> \ No newline at end of file diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php index 7dd55c43..09eeb13d 100644 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -23,7 +23,9 @@ class EmployeeModel extends Model "mobile", "gender", "dob", + "doj", "otp", + "family_floater_key", "emp_status", "created_by", "updated_by", @@ -37,7 +39,7 @@ class EmployeeModel extends Model { return $this->db->table('employee_polices') - ->select(' policies.name as Policy_Name , client_policy.policy_terms as Policy_Terms, client_policy.client_id as ClientId, client_policy.policy_id as PolicyId, client_policy.open_for_enrollment as OpenForEnrollment') // Select all columns from both tables + ->select(' policies.name as Policy_Name , client_policy.policy_terms as Policy_Terms, client_policy.client_id as ClientId, client_policy.policy_id as PolicyId,client_policy.id as ClientPolicyId, client_policy.open_for_enrollment as OpenForEnrollment') // Select all columns from both tables ->join('client_policy', 'client_policy.id = employee_polices.client_policy_id') ->join('policies', 'policies.id = client_policy.policy_id') ->where('employee_polices.employee_id', $id) @@ -45,4 +47,13 @@ class EmployeeModel extends Model ->getResult(); } + + + + // 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(); + } + } diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 26d3cd86..6ac9eeb7 100644 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -447,5 +447,28 @@ class EmployeePolicyModel extends Model return $row = $query->getRowArray(); } + + //for emp onboard do not change + public function checkExistingEmpPolicy($arr) + { + return $this->where('employee_id',$arr['employee_id']) + ->where('client_policy_id',$arr['client_policy_id']) + ->find(); + } + + + public function updateSiAndPremium( $client_policy_id, $employee_id,$basic_cover_si,$premium) + { + + + $query = "UPDATE employee_polices + SET employee_polices.basic_cover_si = '{$basic_cover_si}' + , employee_polices.premium = '{$premium}' + WHERE employee_polices.employee_id = '{$employee_id}' + AND employee_polices.client_policy_id = '{$client_policy_id}'"; + + $this->query($query); + } + //------------------------------------------------------------------ } diff --git a/app/Models/LevelContactModel.php b/app/Models/LevelContactModel.php index 635d3652..79a8f15a 100644 --- a/app/Models/LevelContactModel.php +++ b/app/Models/LevelContactModel.php @@ -20,6 +20,7 @@ class LevelContactModel extends Model "designation", "created_by", "updated_by", + "otp", "is_active", ]; diff --git a/app/Models/PolicesModel.php b/app/Models/PolicesModel.php index 074575f3..70724d71 100644 --- a/app/Models/PolicesModel.php +++ b/app/Models/PolicesModel.php @@ -1,7 +1,9 @@ where(['client_id' => $client_id, 'client_policy_id' => $policy_id, 'is_active' => 1])->findAll(); - if((isset($premium_slab_data))) + + if((!count($premium_slab_data))) { - $policyPremium2Model = new policyPremium2Model(); + $policyPremium2Model = new PolicyPremium2Model(); $premium_slab_data = $policyPremium2Model->where(['client_id' => $client_id, 'client_policy_id' => $policy_id, 'is_active' => 1])->findAll(); + } $grid_id = $premium_slab_data[0]['policy_grid_id']; - $policyGridModel = new policyGridModel(); + $policyGridModel = new PolicyGridModel(); $results = $policyGridModel->find($grid_id); return ['slab_rates' => $premium_slab_data,'grid_master' => $results]; } diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php index 3048d0ca..7e7dde33 100644 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -654,31 +654,31 @@ }; function convertNumberToWords(number) { - if (number === 0) { - return numberWords[number]; - } + if (number === 0) { + return numberWords[number]; + } - let word = ''; + let word = ''; - if (number >= 10000000) { - word += convertNumberToWords(Math.floor(number / 10000000)) + " Crore "; - number %= 10000000; - } + if (number >= 10000000) { + word += convertNumberToWords(Math.floor(number / 10000000)) + " Crore "; + number %= 10000000; + } - if (number >= 100000) { - word += convertNumberToWords(Math.floor(number / 100000)) + " Lakh "; - number %= 100000; - } + if (number >= 100000) { + word += convertNumberToWords(Math.floor(number / 100000)) + " Lakh "; + number %= 100000; + } - if (number >= 1000) { - word += convertNumberToWords(Math.floor(number / 1000)) + " Thousand "; - number %= 1000; - } + if (number >= 1000) { + word += convertNumberToWords(Math.floor(number / 1000)) + " Thousand "; + number %= 1000; + } - if (number >= 100) { - word += convertNumberToWords(Math.floor(number / 100)) + " Hundred "; - number %= 100; - } + if (number >= 100) { + word += convertNumberToWords(Math.floor(number / 100)) + " Hundred "; + number %= 100; + } if (number > 0) { if (word !== '') { @@ -694,9 +694,21 @@ } function convertCommaNumberToWords(input) { - // console.log(input); - const number = parseInt(input.replace(/,/g, ''), 10); - return convertNumberToWords(number); + let number; + if (input instanceof HTMLElement) { + const inputValue = input.value; + number = parseInt(inputValue.replace(/,/g, ''), 10); + var convert_word_value = convertNumberToWords(number); + + if (input.nextElementSibling !== null) { + input.nextElementSibling.textContent = convert_word_value; + } + } else { + number = parseInt(input.replace(/,/g, ''), 10); + } + var convert_word_value = convertNumberToWords(number); + + return convert_word_value; } function onlyNumbers(event){ @@ -708,22 +720,69 @@ function formatNumber(input, maxLength) { - maxLength=16; - let value = input.value.replace(/\D/g, ''); // Remove non-numeric characters - - // Limit the number of digits - value = value.slice(0, maxLength); - - // Format the number with commas using Indian numbering system - value = Number(value).toLocaleString('en-IN'); - input.value = value; + + // console.log("input", input); + maxLength=16; + let value = input.value.replace(/\D/g, ''); // Remove non-numeric characters + + // Limit the number of digits + value = value.slice(0, maxLength); + + // Format the number with commas using Indian numbering system + value = Number(value).toLocaleString('en-IN'); + input.value = value; - basicPayMultiple(input) - if (input.id == 'gpa_si') { - gpaSumInsureMultiplier(); - } + basicPayMultiple(input) + if (input.id == 'gpa_si') { + gpaSumInsureMultiplier(); + } + convertCommaNumberToWords(input); - return ; + // if(input.id == 'basic_pay'){ + // var inputNumber = input.value; + // if (inputNumber) { + // var result = convertCommaNumberToWords(inputNumber); + // $("#gpa_basic_pay_number_word").text(result); + // } else { + // $("#gpa_basic_pay_number_word").text(""); + // } + // }else if(input.id == 'basic_gpa_si'){ + // var inputNumber = input.value; + // if (inputNumber) { + // var result = convertCommaNumberToWords(inputNumber); + // $("#basic_gpa_si_number_word").text(result); + // } else { + // $("#basic_gpa_si_number_word").text(""); + // } + // }else if(input.id == 'basic_gpa_premium'){ + // var inputNumber = input.value; + // if (inputNumber) { + // var result = convertCommaNumberToWords(inputNumber); + // $("#basic_gpa_premium_number_word").text(result); + // } else { + // $("#basic_gpa_premium_number_word").text(""); + // } + // }else if(input.id == 'gpa_si'){ + // var inputNumber = input.value; + // if (inputNumber) { + // var result = convertCommaNumberToWords(inputNumber); + // $("#gpa_sum_si_number_word").text(result); + // } else { + // $("#gpa_sum_si_number_word").text(""); + // } + // }else if(input.id == 'gpa_premium'){ + // var inputNumber = input.value; + // if (inputNumber) { + // var result = convertCommaNumberToWords(inputNumber); + // $("#gpa_sum_premium_number_word").text(result); + // } else { + // $("#gpa_sum_premium_number_word").text(""); + // } + // } + + return ; + // } + } \ No newline at end of file diff --git a/app/Views/mail_welcome.php b/app/Views/mail_welcome.php new file mode 100644 index 00000000..9ebdd64b --- /dev/null +++ b/app/Views/mail_welcome.php @@ -0,0 +1,23 @@ + + + + + + +
+ +
+
+ Dear, +

We are glad to welcome you to the employee benefit program, offered by your employer.

+
+ +
+
+ + + diff --git a/app/Views/policy_gmc_terms.php b/app/Views/policy_gmc_terms.php index d0f182a1..c1582a88 100644 --- a/app/Views/policy_gmc_terms.php +++ b/app/Views/policy_gmc_terms.php @@ -465,9 +465,7 @@
-
- Days -
+
@@ -477,9 +475,7 @@
-
- Days -
+
@@ -630,6 +626,8 @@ var grid_html = ''; var gmc_policy_type_id = $(this).attr('id'); + + if(gmc_policy_type_id >= '2'){ $('#policyGMCTerms').css('display', ''); @@ -644,11 +642,12 @@ var grid_html = ''; method: 'GET', data: {client_policy_id: client_policy_id}, success: function(response) { + console.log('response',response); + setTimeout(function() { $('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow'); }, 1000); - console.log(response); $('#nameOfThePolicyInGMC').html(' - ' + response.policy_name.name); $('gmc_emp_count').val(response.count); diff --git a/app/Views/policy_gpa_terms.php b/app/Views/policy_gpa_terms.php index eabdb8bd..c448e10e 100644 --- a/app/Views/policy_gpa_terms.php +++ b/app/Views/policy_gpa_terms.php @@ -417,6 +417,10 @@ return; } + setTimeout(function() { + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); + }, 1000); }, error: function(xhr, status, error) { console.error(xhr.responseText); @@ -442,12 +446,12 @@ $('body').on('click', '.btnPolicyMaster', function () { var client_policy_id = $(this).data('id'); - console.log('client_policy_id :' ,client_policy_id); + // console.log('client_policy_id :' ,client_policy_id); $('#gpa_client_policy_id').val(client_policy_id); var gpa_policy_type_id = $(this).attr('id'); - console.log('gpa_policy_type_id', gpa_policy_type_id) + // console.log('gpa_policy_type_id', gpa_policy_type_id) if(gpa_policy_type_id == '1'){ @@ -466,7 +470,11 @@ data: {client_policy_id: client_policy_id}, success: function(res) { - console.log(res) + console.log(res); + setTimeout(function() { + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); + }, 1000); $('#nameOfThePolicyInGPA').html(' - ' + res.policy_name.name); if(res.count){ @@ -533,10 +541,7 @@ $("#sumInsured2").trigger("keyup"); $("#totalSumInsured").trigger("keyup"); - setTimeout(function() { - $('.loader').fadeOut(); - $('.loader-mask').delay(350).fadeOut('slow'); - }, 1000); + }, error: function(xhr, status, error) { diff --git a/app/Views/policy_grid.php b/app/Views/policy_grid.php index 9034e889..64af741e 100644 --- a/app/Views/policy_grid.php +++ b/app/Views/policy_grid.php @@ -58,11 +58,8 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp=false){ $('#grid_content_input').empty(); - // console.log ($('#Client_id').val()); - - var grid_container = document.getElementById('grid_content_input'); var dataIdValue = '' if(event === false){ @@ -86,14 +83,66 @@
-
-
-
-
+ `; } else if(dataIdValue == '2'){ @@ -106,12 +155,12 @@
- +
- +
`; @@ -127,12 +176,12 @@
- +
- +
@@ -147,26 +196,25 @@ for (var i = 1; i <= 11; i++) { $('#grid_' + i).remove(); } - grid_html = `
-
+
- +
- +
- +
- +
@@ -187,20 +235,20 @@
- +
- +
- +
- +
@@ -218,30 +266,30 @@ grid_html = `
-
+ +
- +
-
-
-
+
+
- +
-
+
- +
- +
-
+
`; } else if(dataIdValue == '7'){ @@ -255,20 +303,20 @@
- +
- +
- +
- +
@@ -290,16 +338,16 @@
- +
- +
- +
@@ -319,16 +367,16 @@
- +
- +
- +
@@ -348,20 +396,20 @@
- +
- +
- +
- +
@@ -381,21 +429,21 @@
- +
- +
- +
- +
@@ -414,107 +462,32 @@ $('#btnGridSubmit').hide(); } + + + grid_container.insertAdjacentHTML('beforeend', grid_html); + + if(dataIdValue == '1'){ + $('#gpa_sum_si').trigger('keyup'); + // $('input[name="gpa_sum_si[]"]').each(function() { + // console.log($(this)); + // $(this).trigger('keyup'); + // }); + } $('#gpa_sum_insured').hide(); $('#btnGridSubmit').show(); - - $('#si_or_bp').change(function(){ - var selectedValue = $(this).val(); - - - - si_or_bp_two(selectedValue); - - }); - - if(data !== false && data.si){ - console.log('show'); - $('#gpa_sum_insured').show(); - $('#si_or_bp').val("1"); - }else{ - $('#si_or_bp').val("2"); - } - - $("#gpa_si").on("keyup", function() { - var inputNumber = $(this).val(); - if (inputNumber) { - var result = convertCommaNumberToWords(inputNumber); - $("#gpa_si_number_word").text(result); - } else { - $("#gpa_si_number_word").text(""); - } - - - }); - - $("#basic_gpa_premium").on("keyup", function() { - var inputNumber = $(this).val(); - if (inputNumber) { - var result = convertCommaNumberToWords(inputNumber); - $("#gpa_premium_number_word").text(result); - } else { - $("#gpa_premium_number_word").text(""); - } - }); - - - $("#sum_insured").on("keyup", function() { - var inputNumber = $(this).val(); - if (inputNumber) { - var result = convertCommaNumberToWords(inputNumber); - $("#sum_insured_number_word").text(result); - } else { - $("#sum_insured_number_word").text(""); - } - }); - - - $("#premium").on("keyup", function() { - var inputNumber = $(this).val(); - if (inputNumber) { - var result = convertCommaNumberToWords(inputNumber); - $("#premium_number_word").text(result); - } else { - $("#premium_number_word").text(""); - } - }); - - - if (si_or_bp == '1') { - si_or_bp_two(si_or_bp); - }else if(si_or_bp == '2'){ - si_or_bp_two(si_or_bp); - } - - if (si_or_bp == '2') { - - console.log("data line-> 490", data); - $('#si_or_bp').val(si_or_bp); - $('#basic_multiplier').val(data.basic_multiplier); - $('#basic_pay').val(data.basic_pay); - $('#premium_multiplier').val(data.multiplier); - $('#basic_gpa_si').val(data.si); - $('#basic_gpa_premium').val(data.premium); - }else if (si_or_bp == '1') { - console.log("start"); - console.log(data); - $('#si_or_bp').val(si_or_bp); - $('#multiplier').val(data.multiplier); - $('#gpa_si').val(data.si); - $('#basic_gpa_premium').val(data.premium); - } - + $('#si_or_bp').val(si_or_bp); + setTimeout(() => { + $('#si_or_bp').trigger('change'); + }, 300); + }; $("#GridForm").submit(function(event) { var check = checkDuplicate(); - - console.log("check....."); - console.log(check); - event.preventDefault(); @@ -551,7 +524,7 @@ contentType: false, success: function(res) { - console.log(res); + console.log("Response",res); if (res.status === false) { toastr.error('Policy Dose Not Create', 'Error'); @@ -602,6 +575,16 @@ data: { client_policy_id: client_policy_id}, dataType: 'json', success: function (res) { + setTimeout(function() { + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); + }, 1000); + console.log('res',res); + var temp_for_premiumData = JSON.parse(res.premiumData); + + res.premiumData= JSON.parse(res.premiumData); + + $('#nameOfThePolicy').html(' - ' + res.policy_name); $('#grid_emp_count').val(res.count); @@ -623,14 +606,19 @@ }); $('#grid').html(policeGridOptionHTML); - + var si_or_bp_value = ''; if (res.premiumData && res.premiumData.length > 0) { - addGridHTML(false, res.premiumData[0], res.premiumData[0].policy_grid_id, res.premiumData[0].si_or_bp); + + if(res.premiumData[0].si_or_bp){ + si_or_bp_value = res.premiumData[0].si_or_bp; + } + + addGridHTML(false, res.premiumData[0], res.premiumData[0].policy_grid_id, si_or_bp_value); res.premiumData.shift(); $.each(res.premiumData, function(index, item){ if (item.si_or_bp == '1') { - appendGridtHtml('1_1_1_1', item); + appendGridtHtml('1', item); }else{ appendGridtHtml(item.policy_grid_id, item); } @@ -644,18 +632,28 @@ $("#gpa_si").trigger("keyup"); - $("#basic_gpa_premium").trigger("keyup"); + $("#gpa_premium").trigger("keyup"); + $('#basic_pay').trigger('keyup'); + $('#4_si').trigger('keyup'); - $("#sum_insured").trigger("keyup"); - $("#premium").trigger("keyup"); + $('input[name="gpa_sum_si[]"]').each(function() { + $(this).trigger('keyup'); + }); - $("input[name='si[]']").trigger("keyup"); - $("input[name='premium[]']").trigger("keyup") + $('input[name="gpa_sum_premium[]"]').each(function() { + $(this).trigger('keyup'); + }); - setTimeout(function() { - $('.loader').fadeOut(); - $('.loader-mask').delay(350).fadeOut('slow'); - }, 1000); + var id_for_trigger =temp_for_premiumData[0].policy_grid_id; + $(`input[name="${id_for_trigger}_si[]"]`).each(function() { + console.log($(this)); + $(this).trigger('keyup'); + }); + + $(`input[name="${id_for_trigger}_premium[]"]`).each(function() { + console.log($(this)); + $(this).trigger('keyup'); + }); }, error: function (xhr, status, error) { console.error(xhr.responseText); @@ -674,6 +672,8 @@ var grid_id=$(this)[0].value; var client_policy_id =$('#client_policy_id')[0].value; + + $('.loader').fadeIn(); $('.loader-mask').fadeIn(); @@ -683,8 +683,6 @@ data: { client_policy_id: client_policy_id}, dataType: 'json', success: function (res) { - appendGridtHtml('1_2'); - appendGridtHtml('1_2_1'); console.log('responce :', res); setTimeout(function() { @@ -692,7 +690,6 @@ $('.loader-mask').delay(350).fadeOut('slow'); }, 1000); if (res.premiumData.length > 0 && res.premiumData[0].policy_grid_id === grid_id) { - console.log("heelo"); $('#nameOfThePolicy').html(' - ' + res.policy_name); $('#grid_emp_count').val(res.count); @@ -714,43 +711,35 @@ policeGridOptionHTML += ''; }); // $('#grid').html(policeGridOptionHTML); - + var si_or_bp_value = ''; if (res.premiumData && res.premiumData.length > 0) { + + if(res.premiumData[0].si_or_bp){ + si_or_bp_value = res.premiumData[0].si_or_bp; - addGridHTML(false, res.premiumData[0], res.premiumData[0].policy_grid_id, res.premiumData[0].si_or_bp); + $('#si_or_bp').val(si_or_bp_value); + + } + + + + addGridHTML(false, res.premiumData[0], res.premiumData[0].policy_grid_id, si_or_bp_value); res.premiumData.shift(); $.each(res.premiumData, function(index, item){ - // console.log('premiumData index :',index) - // appendGridtHtml(item.policy_grid_id, item); - if (item.si_or_bp == '1') { - appendGridtHtml('1_1_1_1', item); - }else{ appendGridtHtml(item.policy_grid_id, item); - } }); } else { console.log("res.premiumData is undefined, null, or empty."); - } + } + }else if(res.data[0].policy_type == "GPA"){ + $('#si_or_bp').val('2'); - $('#bs-example-modal-lg').modal('show'); - $("#gpa_si").trigger("keyup"); - $("#basic_gpa_premium").trigger("keyup"); - - $("#sum_insured").trigger("keyup"); - $("#premium").trigger("keyup"); - - $("input[name='si[]']").trigger("keyup"); - $("input[name='premium[]']").trigger("keyup"); - }else{ - if($('#si_or_bp').val() == 2){ - addGridHTML(false, false, grid_id,) - } - // console.log("novkfdmmk"); - addGridHTML(false, false, grid_id) + setTimeout(() => { + $('#si_or_bp').trigger('change') + }, 300); } - // console.log("hello"); }, error: function (xhr, status, error) { console.error(xhr.responseText); @@ -764,7 +753,6 @@ }); }) - var Count = 1 function appendGridtHtml(ui_type = false, data = false,) { @@ -773,66 +761,25 @@ Count++; var container = document.getElementById('grid_content_input'); - if(ui_type == '1_1' || ui_type == '1_1_1' || ui_type == '1_1_1_1') + if(ui_type == '1') { - if (ui_type == '1_1_1' || ui_type == '1_1_1_1') { - html=`
- - -
-
-
- - -
- -
-
- - -
+ html = `
+
+ + +
+
+
+ + +
+ +
+
+ + +
`; - // return html; - }else{ - html =`
- - -
- `; - - // return html; - } - } - else if(ui_type == '1_2' || ui_type == '1_2_1') - { - if (ui_type == '1_2_1') { - html=`
- - -
-
-
- - -
-
-
- - -
- -
`; - }else{ - html =`
- - -
-
- - -
- `; - } } else if(ui_type == '3'){ @@ -840,12 +787,12 @@
- +
- +
@@ -862,15 +809,15 @@
- +
- +
- +
@@ -886,20 +833,20 @@
- +
- +
- +
- +
@@ -912,29 +859,28 @@ html =`
-
+ +
- +
-
-
-
- - -
-
- - -
-
- - -
-
-
- - -
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ +
`; @@ -944,20 +890,20 @@
- +
- +
- +
- +
@@ -972,16 +918,16 @@
- +
- +
- +
@@ -996,16 +942,16 @@
- +
- +
- +
@@ -1020,20 +966,20 @@
- +
- +
- +
- +
@@ -1048,21 +994,21 @@
- +
- +
- +
- +
@@ -1072,77 +1018,14 @@ } - if (ui_type == '1_1' || ui_type == '1_1_1' || ui_type == '1_2' || ui_type == '1_2_1' || ui_type == '1_1_1_1') { - if(ui_type == '1_1'){ - $('#si_or_bp_1').empty().append(html); - $('#si_or_bp_1_1').empty(); - $('#gmc_add_more').hide() - $('#gmc_remove').show() - Count-- - $('#gmc_add_more_'+Count).hide() - Count++ - }else if(ui_type == '1_1_1'){ - $('#si_or_bp_2').empty().append(html); - $('#gmc_add_more').hide() - $('#gmc_remove').show() - Count-- - $('#gmc_add_more_'+Count).hide() - Count++ - }else if(ui_type == '1_2'){ - - $('#si_or_bp_1').empty(); - $('#si_or_bp_1_1').empty().append(html); - $('#gmc_add_more').hide() - $('#gmc_remove').show() - Count-- - $('#gmc_add_more_'+Count).hide() - Count++ - }else if(ui_type == '1_2_1'){ - $('#si_or_bp_2').empty().append(html); - $('#gmc_add_more').hide() - $('#gmc_remove').show() - Count-- - $('#gmc_add_more_'+Count).hide() - Count++ - }else if(ui_type == '1_1_1_1'){ - $('#si_or_bp_2').append(html); - $('#gmc_add_more').hide() - $('#gmc_remove').show() - Count-- - $('#gmc_add_more_'+Count).hide() - Count++ - - - console.log("data", data); - - if(data){ - $('input[name="premium[]"]').length; - $('input[name="premium[]"]').each(function(index) { - if (index === $('input[name="premium[]"]').length - 1) { - console.log("data.premium",data.premium); - $(this).val(data.premium); - // console.log("This ", $(this)[0].val(data.premium)); - // var basicGpaPremiumValue = $(this).val(); - - // if (basicGpaPremiumValue !== "" && basicGpaPremiumValue !== null) { - // console.log("Value of basic_gpa_premium[]: " + basicGpaPremiumValue); - // } else { - // console.log("basic_gpa_premium[] value is empty or null"); - // } - } - }); - } - - } - - }else{ + container.insertAdjacentHTML('beforeend', html); $('#gmc_add_more').hide(); $('#gmc_remove').show(); Count-- $('#gmc_add_more_'+Count).hide() Count++ - } + @@ -1185,14 +1068,11 @@ } - function checkDuplicate() { - // console.log($('#grid')[0].value); - if ($('#grid')[0].value === '3') { - var siInputs = $('input[name="si[]"]'); - var premiumInputs = $('input[name="premium[]"]'); + var siInputs = $('input[name="3_si[]"]'); + var premiumInputs = $('input[name="3_premium[]"]'); var siValues = []; var premiumValues = []; @@ -1208,11 +1088,9 @@ premiumValues.push($(this).val()); }); - console.log("Checking for duplicates..."); for (var i = 0; i < siValues.length; i++) { for (var j = i + 1; j < siValues.length; j++) { if (siValues[i] === siValues[j] && premiumValues[i] === premiumValues[j]) { - console.log('Duplicate values found in si[] at indices', i, 'and', j); siDuplicates = true; } } @@ -1220,16 +1098,14 @@ if (siDuplicates || premiumDuplicates) { toastr.warning('Duplicates found!', 'warning'); - console.log('Duplicates found'); return true; } else { - console.log('No duplicates found'); return false; } }else if($('#grid')[0].value === '4'){ - var ageFrom = $('input[name="age_from[]"]'); - var ageTo = $('input[name="age_to[]"]'); + var ageFrom = $('input[name="4_age_from[]"]'); + var ageTo = $('input[name="4_age_to[]"]'); var ageFromValues = []; var ageToValues = []; @@ -1244,12 +1120,10 @@ ageToValues.push($(this).val()); }); - console.log("Checking for duplicates..."); for (var i = 0; i < ageFromValues.length; i++) { for (var j = i + 1; j < ageFromValues.length; j++) { // Check for duplicates between age_from[] and age_to[] if (ageFromValues[i] === ageFromValues[j] && ageToValues[i] === ageToValues[j]) { - console.log('Duplicate values found in age_from[] and age_to[] at indices', i, 'and', j); ageDuplicates = true; } } @@ -1257,17 +1131,15 @@ if (ageDuplicates) { toastr.warning('Duplicates found!', 'warning'); - console.log('Duplicates found'); return true; } else { - console.log('No duplicates found'); return false; } }else if ($('#grid')[0].value === '5') { - var si = $('input[name="si[]"]'); - var ageFrom = $('input[name="age_from[]"]'); - var ageTo = $('input[name="age_to[]"]'); + var si = $('input[name="5_si[]"]'); + var ageFrom = $('input[name="5_age_from[]"]'); + var ageTo = $('input[name="5_age_to[]"]'); var si_array = []; var ageFrom_array = []; @@ -1297,15 +1169,13 @@ if (siDuplicates || ageDuplicates) { toastr.warning('Duplicates found!', 'warning'); - console.log('Duplicates found'); return true; } else { - console.log('No duplicates found'); return false; } }else if($('#grid')[0].value === '6'){ - var ageFrom = $('input[name="age_from[]"]'); - var ageTo = $('input[name="age_to[]"]'); + var ageFrom = $('input[name="6_age_from[]"]'); + var ageTo = $('input[name="6_age_to[]"]'); var ageFromValues = []; var ageToValues = []; @@ -1320,12 +1190,10 @@ ageToValues.push($(this).val()); }); - console.log("Checking for duplicates..."); for (var i = 0; i < ageFromValues.length; i++) { for (var j = i + 1; j < ageFromValues.length; j++) { // Check for duplicates between age_from[] and age_to[] if (ageFromValues[i] === ageFromValues[j] && ageToValues[i] === ageToValues[j]) { - console.log('Duplicate values found in age_from[] and age_to[] at indices', i, 'and', j); ageDuplicates = true; } } @@ -1333,16 +1201,14 @@ if (ageDuplicates) { toastr.warning('Duplicates found!', 'warning'); - console.log('Duplicates found'); return true; } else { - console.log('No duplicates found'); return false; } }else if($('#grid')[0].value === '7'){ - var si = $('input[name="si[]"]'); - var ageFrom = $('input[name="age_from[]"]'); - var ageTo = $('input[name="age_to[]"]'); + var si = $('input[name="7_si[]"]'); + var ageFrom = $('input[name="7_age_from[]"]'); + var ageTo = $('input[name="7_age_to[]"]'); var si_array = []; var ageFrom_array = []; @@ -1372,16 +1238,14 @@ if (siDuplicates || ageDuplicates) { toastr.warning('Duplicates found!', 'warning'); - console.log('Duplicates found'); return true; } else { - console.log('No duplicates found'); return false; } }else if($('#grid')[0].value === '10'){ - var si = $('input[name="si[]"]'); - var ageFrom = $('input[name="age_from[]"]'); - var ageTo = $('input[name="age_to[]"]'); + var si = $('input[name="10_si[]"]'); + var ageFrom = $('input[name="10_age_from[]"]'); + var ageTo = $('input[name="10_age_to[]"]'); var si_array = []; var ageFrom_array = []; @@ -1412,15 +1276,13 @@ if (siDuplicates || ageDuplicates) { toastr.warning('Duplicates found!', 'warning'); - console.log('Duplicates found'); return true; } else { - console.log('No duplicates found'); return false; } }else if($('#grid')[0].value === '8'){ - var siInputs = $('input[name="si[]"]'); - var gradeInputs = $('input[name="grade[]"]'); + var siInputs = $('input[name="8_si[]"]'); + var gradeInputs = $('input[name="8_grade[]"]'); var siValues = []; var gradeValues = []; @@ -1435,12 +1297,10 @@ gradeValues.push($(this).val()); }); - console.log("Checking for duplicates..."); for (var i = 0; i < siValues.length; i++) { for (var j = i + 1; j < siValues.length; j++) { // Check for duplicates between si[] and grade[] if (siValues[i] === siValues[j] && gradeValues[i] === gradeValues[j]) { - console.log('Duplicate values found in si[] and grade[] at indices', i, 'and', j); duplicatesFound = true; } } @@ -1448,15 +1308,13 @@ if (duplicatesFound) { toastr.warning('Duplicates found!', 'warning'); - console.log('Duplicates found'); return true; } else { - console.log('No duplicates found'); return false; } }else if($('#grid')[0].value === '9'){ - var siInputs = $('input[name="si[]"]'); - var gradeInputs = $('input[name="grade[]"]'); + var siInputs = $('input[name="9_si[]"]'); + var gradeInputs = $('input[name="9_grade[]"]'); var siValues = []; var gradeValues = []; @@ -1471,12 +1329,10 @@ gradeValues.push($(this).val()); }); - console.log("Checking for duplicates..."); for (var i = 0; i < siValues.length; i++) { for (var j = i + 1; j < siValues.length; j++) { // Check for duplicates between si[] and grade[] if (siValues[i] === siValues[j] && gradeValues[i] === gradeValues[j]) { - console.log('Duplicate values found in si[] and grade[] at indices', i, 'and', j); duplicatesFound = true; } } @@ -1484,16 +1340,14 @@ if (duplicatesFound) { toastr.warning('Duplicates found!', 'warning'); - console.log('Duplicates found'); return true; } else { - console.log('No duplicates found'); return false; } }else if ($('#grid')[0].value === '11') { - var siInputs = $('input[name="si[]"]'); - var gradeInputs = $('input[name="grade[]"]'); - var maxSiInputs = $('input[name="max_si[]"]'); + var siInputs = $('input[name="11_si[]"]'); + var gradeInputs = $('input[name="11_grade[]"]'); + var maxSiInputs = $('input[name="11_max_si[]"]'); var siValues = []; var gradeValues = []; @@ -1513,100 +1367,145 @@ maxSiValues.push($(this).val()); }); - console.log("Checking for duplicates..."); for (var i = 0; i < siValues.length; i++) { for (var j = i + 1; j < siValues.length; j++) { - console.log(maxSiValues); - console.log("maxSiValues[i] ", maxSiValues[i] ); - console.log("maxSiValues[j]", maxSiValues[j]); + // console.log(maxSiValues); + // console.log("maxSiValues[i] ", maxSiValues[i] ); + // console.log("maxSiValues[j]", maxSiValues[j]); if (siValues[i] === siValues[j] && gradeValues[i] === gradeValues[j] && maxSiValues[i] === maxSiValues[j]) { - console.log('Duplicate values found in si[], grade[], and max_si[] at indices', i, 'and', j); duplicatesFound = true; } } } if (duplicatesFound) { - console.log('Duplicates found'); toastr.warning('Duplicates found!', 'warning'); return true; } else { - console.log('No duplicates found'); return false; } } } - - - \ No newline at end of file diff --git a/composer.json b/composer.json index d49707b4..e0f50cfa 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,8 @@ "firebase/php-jwt": "^6.10", "google/apiclient": "^2.15.0", "laminas/laminas-escaper": "^2.9", + "php-amqplib/php-amqplib": "^2.8", + "phpmailer/phpmailer": "^6.9", "phpoffice/phpspreadsheet": "^2.0", "psr/log": "^1.1", "slim/slim": "^4.13" diff --git a/public/assets/images/Nhance-Logo-Final.png b/public/assets/images/Nhance-Logo-Final.png new file mode 100644 index 00000000..0d331b68 Binary files /dev/null and b/public/assets/images/Nhance-Logo-Final.png differ