diff --git a/app/Config/Routes.php b/app/Config/Routes.php index d74d1d3f..8240c1c1 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -73,6 +73,9 @@ $routes->group("/user", ["filter" => "authMVC"], function ($routes) { $routes->get("deactive/(:hash)", "UserController::deactive/$1"); $routes->get("rolesandteams", "UserController::getRolesAndTeams"); $routes->get("getUserActivityHistory", "UserController::getUserActivityHistory"); + $routes->match(['get','post','put'], 'partner', 'UserController::partner'); + $routes->match(['get','post','put'], 'partnerIncentive', 'UserController::partnerIncentive'); + $routes->get("download-incentive-file/(:any)", "UserController::downloadIncentivesFile/$1"); }); $routes->group("/dashboard", ["filter" => "authMVC"], function ($routes) { @@ -364,7 +367,8 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get('transformMailContent', 'LeadsController::transformMailContent'); $routes->get('getCDAmount', 'ClientController::getCDAmount'); $routes->get('getTheEmpDataForClaim/(:any)', 'ClientController::getTheEmpDataForClaim/$1'); - $routes->get('getTheEmpDataForClaimSearchByMobile/(:any)', 'ClientController::getTheEmpDataForClaimSearchByMobile/$1'); + // $routes->get('getTheEmpDataForClaimSearchByMobile/(:any)', 'ClientController::getTheEmpDataForClaimSearchByMobile/$1'); + $routes->get('getTheEmpDataForClaimSearchByMobile', 'ClientController::getTheEmpDataForClaimSearchByMobile'); $routes->get('getLeadNonEB/(:any)', 'LeadsController::getLeadNonEB/$1'); $routes->get('getPolicyTypeFields', 'LeadsController::getPolicyTypeFields'); $routes->get('removeMultiFile', 'LeadsController::removeMultiFile'); @@ -624,6 +628,8 @@ $routes->group("/ticket", ["filter" => "authMVC"], function ($routes) { $routes->post('upload_url',"TicketController::upload_url"); $routes->post('getUrlDataByTicketId',"TicketController::getUrlDataByTicketId"); $routes->get('remove_url',"TicketController::remove_url"); + $routes->get('fetchVehiclePolicy/(:any)','TicketController::fetchVehiclePolicy/$1'); + }); $routes->group("clientApi",["filter" => "AuthClientApi"], function ($routes){ @@ -674,6 +680,9 @@ $routes->get("ticketHistoryList", "ThzController::ticketHistoryList"); $routes->group('test', function($routes) { $routes->post('api/saveForm', 'TestingController::saveForm'); $routes->get('insurerRFQRemainder', 'LeadsController::remainderForQcr'); + $routes->get('ecard/generate-pdf', 'TestingController::generatePDF'); + $routes->get('view-pdf', 'TestingController::viewPDF'); + $routes->get('generate-pdf-view', 'TestingController::generatePDFWithView'); }); $routes->cli('cli/testcli', 'TestingController::testcli'); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 4a73bb1b..b7a4d343 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -2423,6 +2423,7 @@ class ClientController extends AdminController // echo "
";
             // print_r($this->request->getPost());die;
+            $this->myLogger->logme('error', "post data : " . json_encode($this->request->getPost() ?? []));
             $this->myLogger->logme('error', 'Terms CREATE function called');
 
             /*** Client Policy Table Primary Key(ID) ***/
@@ -2624,7 +2625,7 @@ class ClientController extends AdminController
             }
             
             $data['enrollment_display_key'] = $this->enrollmentGMCDisplayValueTransform();
-
+            $this->myLogger->logme('error', "contructed post data : " . json_encode($data ?? []));
             // print_r($data);die;
 
             $jsonData = json_encode($data);
@@ -5404,7 +5405,8 @@ class ClientController extends AdminController
                 employees.mobile AS emp_mobile,
                 employees.email_corporate AS emp_email,
                 employees.relationship AS emp_relationship,
-                employee_polices.uhid AS policy_no
+                employee_polices.uhid AS policy_no,
+                employee_polices.client_policy_id
             ")
             ->join('clients', 'client_policy.client_id = clients.id', 'left')
             ->join('insurers', 'client_policy.insurer_id = insurers.id', 'left')
@@ -5417,9 +5419,15 @@ class ClientController extends AdminController
             ->where('employees.is_active', 1)
             ->where('employees.relationship', "Self")
             ->where('employee_polices.is_active', 1)
+            ->whereIn('employees.emp_status', ['active'])
+            ->whereIn('employee_polices.status', ['active'])
+            ->where('employees.is_active', 1)
             ->where('client_policy.id', $param)
+            ->groupBy('employees.emp_code')
             ->get()
             ->getResultArray();
+
+        // print_r(db_connect()->getLastQuery()); die;
        
         $dataForClientAndInsurer = $this->clientPolicyModel
                 ->select("
@@ -5461,20 +5469,39 @@ class ClientController extends AdminController
                 'memberData' => $memberData
             ], 404);
         }
-    } 
-    
-    public function getTheEmpDataForClaimSearchByMobile($param, $type = 'mobile', $client_policy_id = null, $client_id = null, $ticket_type_id = null)
-    {   
+    }
+
+    // public function getTheEmpDataForClaimSearchByMobile($param, $type = 'mobile', $client_policy_id = null, $client_id = null, $ticket_type_id = null)
+    public function getTheEmpDataForClaimSearchByMobile()
+    {
+
+        $request = $this->request;
+
+        // Get parameters from GET request
+        $param = $request->getGet('param');
+        $type = $request->getGet('type') ?? 'mobile';
+        $client_policy_id = $request->getGet('client_policy_id');
+        $client_id = $request->getGet('client_id');
+        $ticket_type_id = $request->getGet('ticket_type_id');
+
+        // Validate required parameter
+        if (empty($param)) {
+            return $this->response->setJSON([
+                'status' => false,
+                'message' => 'Parameter is required'
+            ])->setStatusCode(400);
+        }
+
         $field_name = 'employees.' . $type;
 
         $policy_type_id = [];
-        if($ticket_type_id == 1){
+        if ($ticket_type_id == 1) {
             $policy_type_id = [2, 3, 4, 5];
-        }else if($ticket_type_id == 2){
+        } else if ($ticket_type_id == 2) {
             $policy_type_id = [1];
-        }else if($ticket_type_id == 3){
+        } else if ($ticket_type_id == 3) {
             $policy_type_id = [6];
-        }else if($ticket_type_id == 4){
+        } else if ($ticket_type_id == 4) {
             $policy_type_id = [7];
         }
 
@@ -5512,24 +5539,24 @@ class ClientController extends AdminController
             ->where('employee_polices.status', "active")
             ->where($field_name, $param);
 
-            if (!empty($client_id)) {
-                $query->where('employees.client_id', $client_id);
-            }
+        if (!empty($client_id)) {
+            $query->where('employees.client_id', $client_id);
+        }
 
-            if (!empty($client_policy_id)) {
-                $query->where('employee_polices.client_policy_id', $client_policy_id);
-            }
+        if (!empty($client_policy_id)) {
+            $query->where('employee_polices.client_policy_id', $client_policy_id);
+        }
 
-            if($policy_type_id != null){
-                $query->whereIn('client_policy.policy_type_id', $policy_type_id);
-            }
-            
-            $query->groupBy('employees.id')
-                ->orderBy('employees.id', 'DESC');
-            
-            $data = $query->get()->getRowArray();
+        if ($policy_type_id != null) {
+            $query->whereIn('client_policy.policy_type_id', $policy_type_id);
+        }
 
-            // print_r(db_connect()->getLastQuery()); die;
+        $query->groupBy('employees.id')
+            ->orderBy('employees.id', 'DESC');
+
+        $data = $query->get()->getRowArray();
+
+        // print_r(db_connect()->getLastQuery()); die;
 
         $memberData = [];
         $dataForClientAndInsurer = [];
@@ -5540,15 +5567,15 @@ class ClientController extends AdminController
         // ->where('user_profiles.role', 3)
         // ->get()
         // ->getResultArray();
-            
-        if(!empty($data) && count($data) > 0){
+
+        if (!empty($data) && count($data) > 0) {
 
             $memberData = $this->employeeModel->getEmployeeByEmployeeCode($data['emp_code'], $client_policy_id, $client_id);
             $acms_datas = $this->employeeModel->getAcmUsingClientID($data['client_id']);
             // if(!empty($acms_datas)){
             //     $acms = $acms_datas;
             // }
-        }else{
+        } else {
             $acms_datas = "";
         }
 
diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php
index db13f832..d5f8ea12 100644
--- a/app/Controllers/LeadsController.php
+++ b/app/Controllers/LeadsController.php
@@ -4947,7 +4947,7 @@ class LeadsController extends BaseController
 
                 // Start table with clean styling
                 $html .= "

{$category}

"; - $html .= ""; + $html .= "
"; // Table header with light background $html .= ""; diff --git a/app/Controllers/TestingController.php b/app/Controllers/TestingController.php index 495c27d4..b2d6968b 100644 --- a/app/Controllers/TestingController.php +++ b/app/Controllers/TestingController.php @@ -5,6 +5,8 @@ namespace App\Controllers; use App\Controllers\BaseController; use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\API\ResponseTrait; +use Dompdf\Dompdf; +use Dompdf\Options; class TestingController extends BaseController { @@ -36,4 +38,180 @@ class TestingController extends BaseController log_message('error', 'test message for log_message_function'); echo "hi 3"; } + + + public function generatePDF() + { + // Sample data - replace with your actual data source + $data = [ + 'NAME' => 'John Doe', + 'GENDER' => 'Male', + 'DOB' => '01/01/1990', + 'RELATION' => 'Self', + 'POLICY_NO' => 'POL123456789', + 'TPA_ID' => 'TPA987654321', + 'POLICY_START_DATE' => '01/01/2024', + 'POLICY_DATE' => '31/12/2024', + 'INSURER_NAME' => 'ABC Insurance Co.', + 'TPA_NAME' => 'XYZ TPA Ltd.', + 'FRONT_CARD' => base_url('assets/images/front-card.jpg'), // Your card images + 'BACK_CARD' => base_url('assets/images/back-card.jpg'), + 'LEVELS' => 'Level 1: 1800-XXX-XXXX
Level 2: support@company.com' + ]; + + // Load the HTML template + $html = $this->loadTemplate($data); + + // Configure DomPDF options + $options = new Options(); + $options->set('isRemoteEnabled', true); // Enable loading of remote images + $options->set('isHtml5ParserEnabled', true); + $options->set('isPhpEnabled', true); + $options->set('debugPng', false); + $options->set('debugKeepTemp', false); + $options->set('debugCss', false); + $options->set('debugLayout', false); + $options->set('debugLayoutLines', false); + $options->set('debugLayoutBlocks', false); + $options->set('debugLayoutInline', false); + $options->set('debugLayoutPaddingBox', false); + + // Initialize DomPDF + $dompdf = new Dompdf($options); + + // Load HTML content + $dompdf->loadHtml($html); + + // Set paper size and orientation + $dompdf->setPaper('A4', 'landscape'); // or 'portrait' + + // Render PDF + $dompdf->render(); + + // Output PDF to browser + $filename = 'ecard_' . date('Y-m-d_H-i-s') . '.pdf'; + $dompdf->stream($filename, ['Attachment' => true]); // Set to false for inline view + } + + public function viewPDF() + { + // Same as generatePDF but with inline view + $data = [ + 'NAME' => 'John Doe', + 'GENDER' => 'Male', + 'DOB' => '01/01/1990', + 'RELATION' => 'Self', + 'POLICY_NO' => 'POL123456789', + 'TPA_ID' => 'TPA987654321', + 'POLICY_START_DATE' => '01/01/2024', + 'POLICY_DATE' => '31/12/2024', + 'INSURER_NAME' => 'ABC Insurance Co.', + 'TPA_NAME' => 'XYZ TPA Ltd.', + 'FRONT_CARD' => base_url('assets/images/front-card.jpg'), + 'BACK_CARD' => base_url('assets/images/back-card.jpg'), + 'LEVELS' => 'Level 1: 1800-XXX-XXXX
Level 2: support@company.com' + ]; + + $html = $this->loadTemplate($data); + $options = new Options(); + $options->set('isRemoteEnabled', true); + $options->set('isHtml5ParserEnabled', true); + + $dompdf = new Dompdf($options); + $dompdf->loadHtml($html); + $dompdf->setPaper('A4', 'portrait'); + $dompdf->render(); + + $filename = 'ecard_' . date('Y-m-d_H-i-s') . '.pdf'; + $dompdf->stream($filename, ['Attachment' => false]); // Inline view + } + + private function loadTemplate($data) + { + // Load your HTML template + $template = file_get_contents(WRITEPATH . 'e_card_template/common.html'); + + // Replace placeholders with actual data + foreach ($data as $key => $value) { + $template = str_replace('{' . $key . '}', $value, $template); + } + + return $template; + } + + // Alternative method using CodeIgniter's view system + public function generatePDFWithView() + { + $data = [ + 'NAME' => 'John Doe', + 'GENDER' => 'Male', + 'DOB' => '01/01/1990', + 'RELATION' => 'Self', + 'POLICY_NO' => 'POL123456789', + 'TPA_ID' => 'TPA987654321', + 'POLICY_START_DATE' => '01/01/2024', + 'POLICY_DATE' => '31/12/2024', + 'INSURER_NAME' => 'ABC Insurance Co.', + 'TPA_NAME' => 'XYZ TPA Ltd.', + 'FRONT_CARD' => base_url('assets/images/front-card.jpg'), + 'BACK_CARD' => base_url('assets/images/back-card.jpg'), + 'LEVELS' => 'Level 1: 1800-XXX-XXXX
Level 2: support@company.com' + ]; + + // Load view with data + $html = view('ecard_template', $data); + + $options = new Options(); + $options->set('isRemoteEnabled', true); + $options->set('isHtml5ParserEnabled', true); + + $dompdf = new Dompdf($options); + $dompdf->loadHtml($html); + $dompdf->setPaper('A4', 'portrait'); + $dompdf->render(); + + $filename = 'ecard_' . date('Y-m-d_H-i-s') . '.pdf'; + $dompdf->stream($filename, ['Attachment' => true]); + } + + public function generatePDFById($id) + { + // Get data from database + $ecardData = []; + + if (!$ecardData) { + throw new \CodeIgniter\Exceptions\PageNotFoundException('E-card not found'); + } + + $data = [ + 'NAME' => $ecardData['name'], + 'GENDER' => $ecardData['gender'], + 'DOB' => $ecardData['dob'], + 'RELATION' => $ecardData['relation'], + 'POLICY_NO' => $ecardData['policy_no'], + 'TPA_ID' => $ecardData['tpa_id'], + 'POLICY_START_DATE' => $ecardData['policy_start_date'], + 'POLICY_DATE' => $ecardData['policy_end_date'], + 'INSURER_NAME' => $ecardData['insurer_name'], + 'TPA_NAME' => $ecardData['tpa_name'], + 'FRONT_CARD' => base_url('assets/images/front-card.jpg'), + 'BACK_CARD' => base_url('assets/images/back-card.jpg'), + 'LEVELS' => 'Level 1: 1800-XXX-XXXX
Level 2: support@company.com' + ]; + + $html = view('ecard_template', $data); + + $options = new Options(); + $options->set('isRemoteEnabled', true); + $options->set('isHtml5ParserEnabled', true); + + $dompdf = new Dompdf($options); + $dompdf->loadHtml($html); + $dompdf->setPaper('A4', 'landscape'); + $dompdf->render(); + + $filename = 'ecard_' . $ecardData['policy_no'] . '_' . date('Y-m-d') . '.pdf'; + $dompdf->stream($filename, ['Attachment' => true]); + } + } diff --git a/app/Controllers/TicketController.php b/app/Controllers/TicketController.php index 0fe8752b..c9548469 100644 --- a/app/Controllers/TicketController.php +++ b/app/Controllers/TicketController.php @@ -22,6 +22,8 @@ use App\Models\EmployeeModel; use App\Models\TPAModel; use App\Models\ClaimFilesModel; use App\Models\ClaimDumpFileModel; +use App\Models\VehicleModel; +use App\Models\PartnerPolicyModel; use DOMDocument; use Psr\Log\LoggerInterface; @@ -62,6 +64,8 @@ class TicketController extends BaseController protected $TPAModel; protected $claimFilesModel; protected $claimDumpFileModel; + protected $vehicleModel; + protected $partnerPolicyModel; public function __construct() { @@ -71,7 +75,7 @@ class TicketController extends BaseController $this->ticketMasterModel = new TicketMasterModel(); - $this->ticketType = [1 => "Claim-GMC", 2 => "Claim-GPA", 3 => "EDLI", 4 => "GTLI"]; + $this->ticketType = [1 => "Claim-GMC", 2 => "Claim-GPA", 3 => "EDLI", 4 => "GTLI", 8 => "Motor"]; $this->priorityType = [ 1 => "Low", 2 => "Medium", @@ -348,6 +352,8 @@ class TicketController extends BaseController $this->TPAModel = new TPAModel(); $this->claimFilesModel = new ClaimFilesModel(); $this->claimDumpFileModel = new ClaimDumpFileModel(); + $this->vehicleModel = new VehicleModel(); + $this->partnerPolicyModel = new PartnerPolicyModel(); } public function ticketList() @@ -684,6 +690,9 @@ class TicketController extends BaseController case 4: $data['ticket_form'] = 'GTLI'; break; + case 8: + $data['ticket_form'] = 'Motor'; + break; } // Fetch ACM Users @@ -719,11 +728,78 @@ class TicketController extends BaseController $data['claim_type'] = $this->claimType[2]; } + $data['client_for_motor'] = $this->clientModel->select('id,client_name')->where('client_type', 2)->where('is_active', 1)->findAll(); + $this->myLogger->logme('error', "Ticket form data fetched successfully for Ticket Type: $ticket_type"); return $data; } + public function fetchVehiclePolicy($id) + { + $method = $this->request->getMethod(); + + try { + if (!$id) { + throw new \Exception('Invalid ID', 400); + } + + if ($method === 'get') { + $data['vehicle_list'] = $this->vehicleModel + ->where('is_active', 1) + ->where('owner', $id) + ->findAll(); + + $data['partner_policy_list'] = $this->partnerPolicyModel + ->where('is_active', 1) + ->findAll(); + + $client = $this->clientModel + ->where('is_active', 1) + ->where('id', $id) + ->first(); + + $data['email'] = !empty($client) ? $client['email'] : null; + $data['phone'] = !empty($client) ? $client['phone'] : null; + + if (empty($data['vehicle_list']) && empty($data['partner_policy_list'])) { + throw new \Exception('No Records found', 404); + } + + return $this->response + ->setJSON(['status' => 'success', 'data' => $data]) + ->setStatusCode(200); + } + + throw new \Exception('Invalid request method', 405); + + } catch (\Throwable $e) { + $code = ($e->getCode() && $e->getCode() >= 100 && $e->getCode() < 600) ? $e->getCode() : 500; + + $isDbError = $e instanceof \CodeIgniter\Database\Exceptions\DatabaseException + || $e instanceof \mysqli_sql_exception + || $e instanceof \PDOException; + + $context = [ + 'title' => get_class($e), + 'type' => get_class($e), + 'code' => $code, + 'message' => $e->getMessage(), + 'file' => $e->getFile(), + 'line' => $e->getLine() + ]; + + $this->myLogger->logme('error', "Exception: {message} in {file} on line {line}", $context, 0); + + return $this->response->setJSON([ + 'status' => 'error', + 'message' => $isDbError ? 'Data Access Error' : $e->getMessage(), + 'ref' => ($isDbError ? 'database - ' : 'application - ') . $code . ' - ' . $e->getLine() + ])->setStatusCode($code); + } + } + + //transform the claim status public function transFormClaimStatus($claimStatusId, $ticket_type) { diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index 78d3a6c0..2ce2e529 100755 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -18,6 +18,8 @@ use App\Models\UserTeamsModel; use App\Helpers\BookStackUserHelper; use App\Models\AuthHistoryModel; use App\Models\UserActivityHistoryModel; +use App\Models\PartnerStaffModel; +use App\Models\PartnerManagerIncentiveFileModel; class UserController extends AdminController @@ -32,6 +34,8 @@ class UserController extends AdminController protected $bookStack; protected $authHistoryModel; protected $userActivityHistoryModel; + protected $partnerStaffModel; + protected $partnerManagerIncentiveFileModel; public function __construct() { @@ -45,6 +49,8 @@ class UserController extends AdminController $this->bookStack = new BookStackUserHelper(); $this->authHistoryModel = new AuthHistoryModel(); $this->userActivityHistoryModel = new UserActivityHistoryModel(); + $this->partnerStaffModel = new PartnerStaffModel(); + $this->partnerManagerIncentiveFileModel = new PartnerManagerIncentiveFileModel(); } public function list() @@ -563,4 +569,211 @@ class UserController extends AdminController } } + public function partner() + { + $method = $this->request->getMethod(); // get, post + try{ + // Listing + if ($method === 'get') { + $types = $this->partnerStaffModel->findAll(); + if (empty($types)) { + return $this->response->setJSON(['status' => 'error','message' => 'No Staff found'])->setStatusCode(404); + } + return $this->response->setJSON(['status' => 'success','data' => $types])->setStatusCode(200); + } + + // add/update + if ($method === 'post') { + + $data = $this->request->getPost(); + if (!empty($data['id'])) { + $text = "update"; + $result = $this->partnerStaffModel->update($data['id'], $data); + $updateID = $data['id']; + } else { + $text = "create"; + $data['role_id'] = 1; + $data['created_by'] = get_session_userid(); + $insertID = $this->partnerStaffModel->insert($data); + $result = true; + } + + $id = isset($insertID) && !empty($insertID) ? $insertID : ($updateID ?? null); + + return $this->response->setJSON([ + 'status' => $id ? 'success' : 'error', + 'message' => $id ? "Staff {$text}d successfully" : "Unable to {$text} staff. Please try again.", + 'id' => $id + ])->setStatusCode($id ? 200 : 400); + } + + // delete + if ($method === 'put') { + $data = $this->request->getRawInput(); + $id = $data['id'] ?? null; + + if (!$id) { + return $this->response->setJSON(['status' => 'error', 'message' => 'ID is required'])->setStatusCode(400); + } + + $staff = $this->partnerStaffModel->find($id); + if (!$staff) { + return $this->response->setJSON(['status' => 'error','message' => 'Staff not found'])->setStatusCode(404); + } + + if ($staff['is_active'] == 1) { + $result = $this->partnerStaffModel->update($id, ['is_active' => 0]); + $message = "Staff deleted successfully"; + } else { + return $this->response->setJSON(['status' => 'error','message' => 'Staff already deleted'])->setStatusCode(400); + } + + return $this->response->setJSON([ + 'status' => $result ? 'success' : 'error', + 'message' => $result ? $message : "Unable to delete staff. Please try again.", + 'id' => $id + ])->setStatusCode($result ? 200 : 400); + } + return $this->response->setJSON([ 'status' => 'error', 'message' => 'Invalid request method' ])->setStatusCode(405); + } + catch (\Throwable $e) { + $code = ($e->getCode() && $e->getCode() >= 100 && $e->getCode() < 600) ? $e->getCode() : 500; + + $isDbError = $e instanceof \CodeIgniter\Database\Exceptions\DatabaseException + || $e instanceof \mysqli_sql_exception + || $e instanceof \PDOException; + + $context = ['title' => get_class($e),'type' => get_class($e),'code' => $code,'message' => $e->getMessage(),'file' => $e->getFile(),'line' => $e->getLine()]; + + $this->myLogger->logme('error', "Exception: {message} in {file} on line {line}", $context, 0); + + return $this->response->setJSON([ 'status' => 'error', 'message' => $isDbError ? 'Data Access Error' : $e->getMessage(), + 'ref' => $isDbError ? 'database - ' : 'application - ' . $code . ' - ' . $e->getLine() + ])->setStatusCode($code); + } + } + + public function partnerIncentive() + { + $method = $this->request->getMethod(); // get, post + try{ + // Listing + if ($method === 'get') { + $manager_id = $this->request->getGet('manager_id'); + $files = $this->partnerManagerIncentiveFileModel->where('manager_id', $manager_id)->findAll(); + if (empty($files)) { + return $this->response->setJSON(['status' => 'error','message' => 'No Records found'])->setStatusCode(404); + } + return $this->response->setJSON(['status' => 'success','data' => $files])->setStatusCode(200); + } + + // add/update + if ($method === 'post') { + + $file = $this->request->getFile('incentive_file_name'); + $month = $this->request->getPost('incentive_month'); + $managerId = $this->request->getPost('manager_id'); + $fileId = $this->request->getPost('id'); + + if ($file && $file->isValid() && !$file->hasMoved()) { + $fileName = $file->getName(); + $path = WRITEPATH.'uploads/incentives'; + $file->move($path, $fileName); + $data = [ + 'manager_id' => $managerId, + 'incentive_month' => date('Y-m-d', strtotime($month)), + 'incentive_file_name' => $fileName, + 'created_by' => get_session_userid() + ]; + + if ($fileId) { + $text = "update"; + $this->partnerManagerIncentiveFileModel->update($fileId, $data); + $updateID = $data['id']; + } else { + $text = "create"; + $insertID = $this->partnerManagerIncentiveFileModel->insert($data); + $result = true; + } + + $id = isset($insertID) && !empty($insertID) ? $insertID : ($updateID ?? null); + + return $this->response->setJSON([ + 'status' => $id ? 'success' : 'error', + 'message' => $id ? "File {$text}d successfully" : "Unable to {$text} file. Please try again.", + 'id' => $id + ])->setStatusCode($id ? 200 : 400); + } + return $this->response->setJSON([ + 'status' => 'error', + 'message' => "Unable to Upload file. Please try again.", + 'id' => '' + ])->setStatusCode(400); + } + + // delete + if ($method === 'put') { + $data = $this->request->getRawInput(); + $id = $data['id'] ?? null; + + if (!$id) { + return $this->response->setJSON(['status' => 'error', 'message' => 'ID is required'])->setStatusCode(400); + } + + $files = $this->partnerManagerIncentiveFileModel->find($id); + if (!$files) { + return $this->response->setJSON(['status' => 'error','message' => 'No Records found'])->setStatusCode(404); + } + + if ($files['is_active'] == 1) { + $result = $this->partnerManagerIncentiveFileModel->update($id, ['is_active' => 0]); + $message = "Files deleted successfully"; + } else { + return $this->response->setJSON(['status' => 'error','message' => 'files already deleted'])->setStatusCode(400); + } + + return $this->response->setJSON([ + 'status' => $result ? 'success' : 'error', + 'message' => $result ? $message : "Unable to delete staff. Please try again.", + 'id' => $id + ])->setStatusCode($result ? 200 : 400); + } + return $this->response->setJSON([ 'status' => 'error', 'message' => 'Invalid request method' ])->setStatusCode(405); + } + catch (\Throwable $e) { + $code = ($e->getCode() && $e->getCode() >= 100 && $e->getCode() < 600) ? $e->getCode() : 500; + + $isDbError = $e instanceof \CodeIgniter\Database\Exceptions\DatabaseException + || $e instanceof \mysqli_sql_exception + || $e instanceof \PDOException; + + $context = ['title' => get_class($e),'type' => get_class($e),'code' => $code,'message' => $e->getMessage(),'file' => $e->getFile(),'line' => $e->getLine()]; + + $this->myLogger->logme('error', "Exception: {message} in {file} on line {line}", $context, 0); + + return $this->response->setJSON([ 'status' => 'error', 'message' => $isDbError ? 'Data Access Error' : $e->getMessage(), + 'ref' => $isDbError ? 'database - ' : 'application - ' . $code . ' - ' . $e->getLine() + ])->setStatusCode($code); + } + } + + public function downloadIncentivesFile($file_name) + { + $file_name = basename($file_name); + $filePath = WRITEPATH . 'uploads/incentives/' . $file_name; + try { + if (file_exists($filePath)) { + return $this->response->download($filePath, null); + } else { + $data['message'] = 'File Not Found'; + echo view('errors/404', $data); + } + } catch (\Exception $e) { + // Handle any exceptions + $errorMessage = $e->getMessage(); + $this->myLogger->logme('error', $errorMessage); + // You can return an error response here + echo $errorMessage; + } + } } \ No newline at end of file diff --git a/app/Models/PartnerManagerIncentiveFileModel.php b/app/Models/PartnerManagerIncentiveFileModel.php new file mode 100755 index 00000000..32e59444 --- /dev/null +++ b/app/Models/PartnerManagerIncentiveFileModel.php @@ -0,0 +1,56 @@ + 'required|integer', + // 'incentive_month' => 'required|valid_date', + // 'incentive_file_name'=> 'required|string|max_length[150]', + // ]; + + // protected $validationMessages = [ + // 'manager_id' => [ + // 'required' => 'Manager ID is required', + // 'integer' => 'Manager ID must be a number', + // ], + // 'incentive_month' => [ + // 'required' => 'Incentive Month is required', + // 'valid_date' => 'Incentive Month must be a valid date (Y-m-d)', + // ], + // 'incentive_file_name' => [ + // 'required' => 'File name is required', + // 'max_length' => 'File name cannot exceed 150 characters', + // ], + // ]; + + // protected $skipValidation = false; +} diff --git a/app/Models/PartnerPolicyModel.php b/app/Models/PartnerPolicyModel.php new file mode 100755 index 00000000..8c14ba06 --- /dev/null +++ b/app/Models/PartnerPolicyModel.php @@ -0,0 +1,42 @@ + 'required|min_length[2]|max_length[150]', + // 'email' => 'permit_empty|valid_email|max_length[150]', + // 'mobile' => 'permit_empty|regex_match[/^[0-9]{10,20}$/]', + // ]; + + // protected $validationMessages = [ + // 'name' => [ + // 'required' => 'Name is required', + // 'min_length' => 'Name must have at least 2 characters', + // 'max_length' => 'Name cannot exceed 150 characters' + // ], + // 'email' => [ + // 'valid_email' => 'Please provide a valid email address', + // 'max_length' => 'Email cannot exceed 150 characters' + // ], + // 'mobile' => [ + // 'regex_match' => 'Mobile number must be 10–20 digits only' + // ] + // ]; + + // protected $skipValidation = false; +} diff --git a/app/Views/UserList.php b/app/Views/UserList.php index 070a4c10..3e83907b 100755 --- a/app/Views/UserList.php +++ b/app/Views/UserList.php @@ -42,7 +42,8 @@ table.dataTable tbody td { padding: 20px; } - #mobile::placeholder { + #mobile::placeholder, + #mobile_no::placeholder { font-size: 13px; } @@ -246,20 +247,113 @@ table.dataTable tbody td { border:1px solid rgba(41, 139, 142, 1); } + .dt-buttons.btn-group{ + display: grid; + grid-template-columns: 1fr .4fr .5fr .2fr; + } + + #user-table_filter input{ width:100%; } + + button.dt-button, + button.dt-button:focus, + button.dt-button:active, + button.dt-button:hover { + background: none !important; + border: none !important; + box-shadow: none !important; + padding: 0 !important; + margin: 0 !important; + } + + + /* main button wrapper */ + .tab-button { + width: 201px; + height: 37px; + border-radius: 10px !important; + font-weight: 700; + font-size: 14px; + line-height: 100%; + border: 1px solid #BAF1F3; + background: #F5FFFF; + cursor: pointer; + transition: all 0.2s ease-in-out; + display: flex; + justify-content: center; + align-items: center; + gap: 6px; + } + + /* divider style */ + .divider-line { + color: #DBDBDB; + font-weight: 400; + } + + /* active state */ + .highlight-link.active { + color: #00999E; + } + + /* inactive state */ + .highlight-link:not(.active) { + color: #707070; + } + + .no-files-message { + width: 900px; + height: 300px; + background: #ECECEC; + opacity: 1; + + display: flex; + align-items: center; + justify-content: center; + + font-weight: 500; /* Medium */ + font-size: 18px; + line-height: 100%; + letter-spacing: 0; + color: #333; /* Adjust text color if needed */ + text-align: center; + + border-radius: 8px; /* optional for smooth edges */ + margin: 13px; /* center horizontally */ + } + + #container { + max-height: 400px; /* set fixed height */ + overflow-y: auto; /* enable vertical scroll */ + overflow-x: hidden; /* prevent horizontal scroll */ + } + + + .file-icon-box { + /* width: 40px; + height: 50px; + display: flex; + align-items: center; + justify-content: center; */ + border-radius: 10px; + background: #F4F6F8; + border: 1px solid #ddd; /* matches border-width:1px */ + padding: 3px; + } +
-
+
-

User List

+

Users

-
+
@@ -278,7 +372,7 @@ table.dataTable tbody td { @@ -296,6 +390,67 @@ table.dataTable tbody td {
Namemobile; ?> user_role; ?> - + is_active == 1){ echo 'Active'; }else{ echo 'In-Active'; } ?>
+ + @@ -377,8 +532,8 @@ table.dataTable tbody td {
- - + +
@@ -387,6 +542,119 @@ table.dataTable tbody td { + + +
@@ -523,44 +791,130 @@ table.dataTable tbody td {
\ No newline at end of file diff --git a/app/Views/cd_master_add_modal.php b/app/Views/cd_master_add_modal.php index b5d4cf66..c57936c5 100644 --- a/app/Views/cd_master_add_modal.php +++ b/app/Views/cd_master_add_modal.php @@ -1,3 +1,4 @@ +