From 15256892ba18258a4588de43f5c81a08cb051ae3 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Fri, 14 Nov 2025 09:47:46 +0530 Subject: [PATCH 01/73] FIX_CLAIM_EMP_FILTER --- app/Views/ticket_form_gmc.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Views/ticket_form_gmc.php b/app/Views/ticket_form_gmc.php index 095e8de7..02f9dfb6 100644 --- a/app/Views/ticket_form_gmc.php +++ b/app/Views/ticket_form_gmc.php @@ -948,16 +948,21 @@ }) function getClientPolicy() { + console.log("get policy function called"); hiddenData = $("#empIDHidden").val(); hiddenData = JSON.parse(hiddenData); console.log('employee id ', hiddenData['emp_id']); let ticket_type_id = $('#ticket_type_id').val(); - console.log("ticket_type_id", ticket_type_id); + let client_id = $('#mobile_emp_client_data_list').val(); + console.log({ticket_type_id, client_id}); + data = { emp_id: hiddenData['emp_id'], ticket_type_id: ticket_type_id, + client_id: client_id, } + $.ajax({ url: '', type: "POST", From dd9a3f1dca4f77233056aac8173c24b90dd25541 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Fri, 14 Nov 2025 09:48:24 +0530 Subject: [PATCH 02/73] FIX_CLAIM_EMP_FILTER --- app/Controllers/TicketController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Controllers/TicketController.php b/app/Controllers/TicketController.php index c8adbcbb..6219326a 100644 --- a/app/Controllers/TicketController.php +++ b/app/Controllers/TicketController.php @@ -2011,6 +2011,7 @@ class TicketController extends BaseController { $received_data = $this->request->getPost(); $ticket_type_id = $this->request->getPost('ticket_type_id') ?? null; + $client_id = $this->request->getPost('client_id') ?? null; $emp_id = $received_data['emp_id']; // Get all client policy IDs for the given employee @@ -2027,6 +2028,9 @@ class TicketController extends BaseController $builder->where('e.is_active', 1); $builder->where('ep.is_active', 1); $builder->where('e.emp_code', $self_data['emp_code']); + if(!empty($client_id)){ + $builder->where('e.client_id', $client_id); + } $builder->groupBy('client_policy_id'); $query = $builder->get(); From 1096511b1ab78e63fa11ed75999cc59734616fb7 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Fri, 14 Nov 2025 12:13:58 +0530 Subject: [PATCH 03/73] CHANGE_EMP_CLAIM_STATUS_AND_HISTORY --- app/Controllers/EmployeeRestController.php | 62 +++++++++++++++++++--- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index a77a10cb..0daa1d6b 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -2626,19 +2626,34 @@ class EmployeeRestController extends AdminController $data['ticket_history'] = $ticketController->ticketHistory($ticket_id); $data['claims_data'] = $this->ticketMaster->getTicketDataByTicketID($ticket_id); $data['ticket_data'] = $ticketController->getMoreInfo($requestFrom = 'rest', $ticket_id); + $status_list = [ + "DENIAL REVIEW AWAITED" => 'Denial Review Awaited', + "UNDER PROCESS - TPA" => 'Under Process', + "SETTLED" => 'Settled', + "PAYMENT INITIATED" => 'Under Process', + "APPROVED" => 'Approved', + "REJECTED" => 'Rejected', + "UNDER PROCESS - QUERY DOCUMENT RECEIVED" => 'Under Process', + "UNDER PROCESS - CLAIM NO. UPDATION" => 'Under Process' , + "INFORMATION REQUIRED" => 'Information Required', + "CDA" => 'Claim Received', + "ID NOT GENERATED" => 'Claim Received', + "NON ID" => 'Claim Received' + ]; - // $data = $response['data']; // Assuming your full array is stored in $response // $ticketData = $data['ticket_data']; // $ticketHistory = $data['ticket_history']; + $data['ticket_data'] = array_fill_keys(array_keys($data['ticket_data']), []); // Loop through ticket_data foreach ($data['ticket_data'] as $status => &$fields) { // Search ticket_history for matching old_status_value foreach ($data['ticket_history'] as $history) { + if ($history['old_status_value'] === $status) { // Attach modified_by and created_at - $fields['modified_by'] = $history['modified_by']; + // $fields['modified_by'] = $history['modified_by']; $fields['modified_at'] = date('d-m-Y h:i A', strtotime($history['created_at'])); // Break after first match (assuming latest entry is enough) break; @@ -2646,6 +2661,25 @@ class EmployeeRestController extends AdminController } } + $new_ticket_data = []; + + foreach ($data['ticket_data'] as $oldKey => $value) { + + // Only process if key exists in status_list + if (!isset($status_list[$oldKey])) { + continue; // skip and do NOT add to new array + } + + // Get new key based on mapping + $newKey = $status_list[$oldKey]; + + // Avoid duplicates + if (!isset($new_ticket_data[$newKey])) { + $new_ticket_data[$newKey] = $value; + } + } + + $data['ticket_data'] = $new_ticket_data; $ticketMesssageModel = new TicketMessageModel(); $ticket_message = $ticketMesssageModel @@ -3818,16 +3852,27 @@ class EmployeeRestController extends AdminController if (!empty($ticket_data)) { + // $client_claim_status = [ + // 'Received' => [1, 2, 3, 4, 15, 16, 17, 18, 25, 26, 27, 28, 35, 36, 37, 38], + // 'Rejected' => [8, 49, 55, 60], + // 'Cancelled' => [13, 47, 53, 58], + // 'Returned' => [14, 48, 54, 59], + // 'Closed' => [12, 22, 32, 42], + // 'Approved' => [9, 20, 30, 40], + // 'Settled' => [11, 24, 34], + // 'Under Process' => [5, 6, 7, 10, 19, 23, 45, 50, 29, 33, 51, 39, 43, 56], + // ]; + $client_claim_status = [ - 'Received' => [1, 2, 3, 4, 15, 16, 17, 18, 25, 26, 27, 28, 35, 36, 37, 38], - 'Rejected' => [8, 49, 55, 60], - 'Cancelled' => [13, 47, 53, 58], - 'Returned' => [14, 48, 54, 59], - 'Closed' => [12, 22, 32, 42], + 'Claim Received' => [1, 2, 3, 15, 16, 17, 18, 25, 26, 27, 28, 35, 36, 37, 38], + 'Under Process' => [5, 6, 7, 10, 19, 23, 45, 50, 29, 33, 51, 39, 43, 56], + 'Information Required' => [ 4 ], 'Approved' => [9, 20, 30, 40], 'Settled' => [11, 24, 34], - 'Under Process' => [5, 6, 7, 10, 19, 23, 45, 50, 29, 33, 51, 39, 43, 56], + 'Denial Review Awaited' => [66], + 'Rejected' => [8, 49, 55, 60], ]; + foreach ($data['ticket_data'] as $status => &$fields) { foreach ($ticket_data as $key => $value) { @@ -3836,6 +3881,7 @@ class EmployeeRestController extends AdminController $ticket_data[$key]['claim_status'] = $claim_key ?? null; // Assign back to the main array } } + $ticket_data[$key]['priority_type'] = $priorityType[$value['priority']] ?? null; $ticket_data[$key]['mode_of_intimate_type'] = $modeOFIntimate[$value['mode_of_intimation']] ?? null; $ticket_data[$key]['relationship_type'] = ucfirst($value['relationship']) ?? null; From 20e6cabf3a467225c61050e9be2973b76ea727b4 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Fri, 14 Nov 2025 12:22:58 +0530 Subject: [PATCH 04/73] FIX_ISSUE --- app/Controllers/EmployeeRestController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 0daa1d6b..0013f928 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -3872,7 +3872,6 @@ class EmployeeRestController extends AdminController 'Denial Review Awaited' => [66], 'Rejected' => [8, 49, 55, 60], ]; - foreach ($data['ticket_data'] as $status => &$fields) { foreach ($ticket_data as $key => $value) { From 3fcb6bdee523843ee886b71ecfbdc7a70eba0012 Mon Sep 17 00:00:00 2001 From: venba-Inspriron-3558 Date: Fri, 14 Nov 2025 12:43:13 +0530 Subject: [PATCH 05/73] TEST_new menu payouts --- app/Config/Routes.php | 1 + app/Controllers/PolicyTransactionController.php | 14 ++++++++++++++ app/Views/layout/header.php | 6 ++++++ app/Views/policy_transaction_payouts.php | 0 4 files changed, 21 insertions(+) create mode 100644 app/Views/policy_transaction_payouts.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index efec8a5d..7c7ba864 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -478,6 +478,7 @@ $routes->group("rfq", ["filter" => "authMVC"], function ($routes) { $routes->get("driveListFiles", "GoogleDriveController::listFiles"); $routes->post('dmsSearch', 'PolicyTransactionController::dmsSearch', ['filter' => 'authMVC']); $routes->get('dmsSearch', 'PolicyTransactionController::dmsSearch', ['filter' => 'authMVC']); +$routes->get('payouts', 'PolicyTransactionController::payouts', ['filter' => 'authMVC']); $routes->get('downloadGdriveFile', 'GoogleDriveController::downloadGdriveFile', ['filter' => 'authMVC']); $routes->get('cli/sendZeptoMail', 'MasterController::testZeptoSMTP'); diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index a2f88d5f..8d24f27b 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -2811,6 +2811,20 @@ $this->loadLayout('dms_search', $data); } + public function payouts() + { + + $data['tab_name'] = 'Payouts'; + $data['page_name'] = 'Payouts'; + $data['payouts'] = []; + $data['agents'] = [ 1 => "Agent 1", 2 => "Agent 2", 3 => "Agent 3", 4 => "Agent 4", 5 => "Agent 5", 6 => "Agent 6", 7 => "Agent 7", 8 => "Agent 8"]; + $data['brokers'] = []; + + if ($this->request->is('post')) {} + if ($this->request->is('get')) {} + + $this->loadLayout('policy_transaction_payouts', $data); + } //--------------------------------------------------------------------------------------------------- public function getCoShareStatementDetails($pt_id) diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index d81c7f68..8fd011b7 100755 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -2017,6 +2017,12 @@ +
  • + + + Payouts + +
  • diff --git a/app/Views/policy_transaction_payouts.php b/app/Views/policy_transaction_payouts.php new file mode 100644 index 00000000..e69de29b From fbd532258d61b516e467f2c0bd5e8a19813197f5 Mon Sep 17 00:00:00 2001 From: velz Date: Fri, 14 Nov 2025 15:30:23 +0530 Subject: [PATCH 06/73] FEAT_COMMISSION_CALC --- app/Config/Filters.php | 4 +- app/Config/Routes.php | 1 + .../InsuranceCommissionController.php | 274 ++++++++++++++++++ app/Controllers/MasterController.php | 3 + app/Filters/CommissionApiFilter.php | 55 ++++ 5 files changed, 336 insertions(+), 1 deletion(-) create mode 100644 app/Controllers/InsuranceCommissionController.php create mode 100644 app/Filters/CommissionApiFilter.php diff --git a/app/Config/Filters.php b/app/Config/Filters.php index 2cf9a260..00faa273 100755 --- a/app/Config/Filters.php +++ b/app/Config/Filters.php @@ -13,6 +13,7 @@ use App\Filters\AuthMVC; use App\Filters\HttpRequestLog; use App\Filters\CloseDbConnection; use App\Filters\AuthClientApi; +use App\Filters\CommissionApiFilter; use App\Filters\AuthJWT; @@ -36,7 +37,8 @@ class Filters extends BaseConfig 'HttpRequestLog' => HttpRequestLog::class, 'authJWT' => AuthJWT::class, 'AuthClientApi' => AuthClientApi::class, - 'CloseDbConnection' => CloseDbConnection::class + 'CloseDbConnection' => CloseDbConnection::class, + 'CommissionApiFilter' => CommissionApiFilter::class ]; /** diff --git a/app/Config/Routes.php b/app/Config/Routes.php index ad1d3874..7b5a1fca 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -34,6 +34,7 @@ $routes->get("updateRenewalData", "ClientController::updateRenewalData"); $routes->get("updateRenewalDataNotExistingClient", "ClientController::updateRenewalDataNotExistingClient"); $routes->get("updateRenewalInsurerData", "ClientController::updateRenewalInsurerData"); $routes->get("sendMutipleToEmails", "MasterController::sendMutipleToEmails"); +$routes->post("getCommission", "InsuranceCommissionController::initiateCommissionCalc",['filter' => 'CommissionApiFilter']); // $routes->post("iAgreeForAddOn", "EmployeeRestController::iAgreeForAddOn"); // $routes->get("sendCroneRemainderMail", "DashboardController::sendCroneRemainderMail"); // $routes->post("employeeUpload", "EmployeeRestController::employeeUpload"); diff --git a/app/Controllers/InsuranceCommissionController.php b/app/Controllers/InsuranceCommissionController.php new file mode 100644 index 00000000..11f61daa --- /dev/null +++ b/app/Controllers/InsuranceCommissionController.php @@ -0,0 +1,274 @@ +myLogger = \Config\Services::mylogger(); + // Load rules file if present in writable config path + // $rulesPath = WRITEPATH . 'config/insurance_rules.json'; + // if (file_exists($rulesPath)) { + // $this->loadRulesFromFile($rulesPath); + // } + } + + /** + * POST /insurance/calculate + * Accepts JSON body with policy data and returns commission calculation + */ + public function initiateCommissionCalc() + { + // Accept POST params (JSON, form-data, x-www-form-urlencoded) + $input = $this->request->getPost(); + + if (empty($input)) { + $json = $this->request->getJSON(true); + if ($json) { + $input = $json; + } + } + + if (empty($input)) { + return $this->failValidationError('No input data received'); + } + // -------- Required Params Check -------- + if (empty($input['policy_issue_date'])) { + return $this->failValidationError('policy_issue_date is required'); + } + + if (empty($input['department'])) { + return $this->failValidationError('department is required'); + } + + if (empty($input['insurer_id'])) { + return $this->failValidationError('insurer_id is required'); + } + + + // -------- Build Dynamic Rules Path -------- + $policyDate = strtotime($input['policy_issue_date']); + if (!$policyDate) { + return $this->failValidationError('Invalid policy_issue_date'); + } + + $month = strtoupper(date('M', $policyDate)); // SEP + $year = date('Y', $policyDate); // 2025 + $folderName = $month . $year; // SEP2025 + + $insurerId = $input['insurer_id']; // 5 + $department = ucfirst(strtolower($input['department'])); // Motor, Health, Fire + + // Final Path: WRITEPATH/rules/SEP2025/5_Motor.json + $rulesPath = WRITEPATH . "uploads/commission/rules/{$folderName}/{$insurerId}_{$department}.json"; + // echo $rulesPath;die(); + + if (!file_exists($rulesPath)) { + return $this->fail("Rules file not found at: {$rulesPath}"); + } + + // Load the dynamic rule set + $this->loadRulesFromFile($rulesPath); + + // -------- Execute Rule Matching & Commission Calculation -------- + try { + $result = $this->calculateCommission($input); + + $comment = isset($result['rule']['name']) + ? "Matched rule: " . $result['rule']['name'] + : "Matched rule: (unnamed rule)"; + + return $this->respond([ + 'success' => true, + 'data' => [ + 'payout' => $result['payout'], + 'rule' => $result['rule'], + 'comment' => $comment, + // 'rules_path_used' => $rulesPath + ] + ]); + + } catch (\Exception $e) { + return $this->fail($e->getMessage()); + } + } + + + /** + * Load rules JSON and normalise department keys to lowercase for lookups + */ + private function loadRulesFromFile(string $filePath) + { + if (!file_exists($filePath)) { + throw new \Exception("Rules file not found: {$filePath}"); + } + + $json = file_get_contents($filePath); + $parsed = json_decode($json, true); + + if (json_last_error() !== JSON_ERROR_NONE) { + throw new \Exception('Invalid JSON in rules file: ' . json_last_error_msg()); + } + + // Normalise department keys to lowercase for consistent lookups + $this->rules = []; + foreach ($parsed as $dept => $rules) { + $this->rules[strtolower($dept)] = $rules; + } + } + + public function calculateCommission(array $policyData) + { + $department = $policyData['department'] ?? ''; + $deptKey = strtolower($department); + + if (!isset($this->rules[$deptKey])) { + throw new \Exception("No rules found for department: {$department}"); + } + + $matchingRules = []; + + foreach ($this->rules[$deptKey] as $rule) { + if ($this->evaluateConditions($rule['conditions'] ?? [], $policyData)) { + $matchingRules[] = $rule; + } + } + + if (empty($matchingRules)) { + throw new \Exception('No matching rules found for the policy data'); + } + + // Use the first matching rule. In future you can implement priority/weighting + $applicableRule = $matchingRules[0]; + + $payout = $this->applyCalculation($applicableRule['calculation'], $policyData); + + return ['rule' => $applicableRule, 'payout' => $payout]; + } + + private function evaluateConditions(array $conditions, array $data): bool + { + foreach ($conditions as $condition) { + $field = $condition['field']; + $operator = $condition['operator']; + $expectedValue = $condition['value']; + + if (!array_key_exists($field, $data)) { + return false; + } + + $actualValue = $data[$field]; + + if (!$this->compareValues($actualValue, $operator, $expectedValue)) { + return false; + } + } + + return true; + } + + private function compareValues($actual, string $operator, $expected): bool + { + switch ($operator) { + case '==': + return $actual == $expected; + case '!=': + return $actual != $expected; + case '>': + return $actual > $expected; + case '>=': + return $actual >= $expected; + case '<': + return $actual < $expected; + case '<=': + return $actual <= $expected; + case 'between': + return is_array($expected) && $actual >= $expected[0] && $actual <= $expected[1]; + case 'in': + return is_array($expected) && in_array($actual, $expected); + default: + throw new \Exception("Unsupported operator: {$operator}"); + } + } + + private function applyCalculation(array $calculation, array $policyData) + { + $type = $calculation['type'] ?? null; + + switch ($type) { + case 'percentage': + $percentage = $calculation['value'] ?? 0; + $base = $calculation['on'] ?? null; + + if ($base === null || !isset($policyData[$base])) { + throw new \Exception("Base value for calculation not found: {$base}"); + } + + return ($percentage / 100) * $policyData[$base]; + + case 'composite': + $total = 0; + + foreach ($calculation['components'] as $component) { + $percentage = $component['percentage'] ?? 0; + $base = $component['on'] ?? null; + + if ($base === null || !isset($policyData[$base])) { + throw new \Exception("Base value for calculation not found: {$base}"); + } + + if (!empty($component['only_first_year'])) { + if (!empty($policyData['is_renewal'])) { + continue; // Skip this component for renewals + } + } + + $total += ($percentage / 100) * $policyData[$base]; + } + + return $total; + + case 'fixed': + $fixedAmount = $calculation['value'] ?? 0; + + // If 'on' specified but not needed, return fixed amount as-is + return $fixedAmount; + + default: + throw new \Exception('Unsupported calculation type: ' . $type); + } + } + + public function getVolumeReward(array $premiumData) + { + $annualPremium = $premiumData['annual_premium'] ?? 0; + $department = $premiumData['department'] ?? ''; + + if ($department === 'Fire' || $department === 'Marine' || $department === 'Engineering') { + if ($annualPremium > 20000000) { + return 0.01 * $annualPremium; + } elseif ($annualPremium > 10000000) { + return 0.005 * $annualPremium; + } elseif ($annualPremium > 5000000) { + return 0.0025 * $annualPremium; + } + } elseif ($department === 'Motor') { + if ($annualPremium > 15000000) { + return 0.02 * $annualPremium; + } elseif ($annualPremium > 7500000) { + return 0.01 * $annualPremium; + } + } + + return 0; + } +} diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index 76bd1a5a..d2ce1329 100755 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -1976,6 +1976,9 @@ class MasterController extends AdminController 'lead_files' => WRITEPATH . 'uploads/lead_files/', 'claim_files' => WRITEPATH . 'uploads/claim_files/', 'claim_dump_excel' => WRITEPATH . 'uploads/claim_dump_excel/', + 'commission' => WRITEPATH . 'uploads/commission/', + 'files' => WRITEPATH . 'uploads/commission/files', + 'rules' => WRITEPATH . 'uploads/commission/rules', 'claim_sample_forms' => ROOTPATH . 'public/claim_sample_forms/', ]; diff --git a/app/Filters/CommissionApiFilter.php b/app/Filters/CommissionApiFilter.php new file mode 100644 index 00000000..d7ae956e --- /dev/null +++ b/app/Filters/CommissionApiFilter.php @@ -0,0 +1,55 @@ +getHeaderLine('X'); + $authHeader = $_SERVER['REDIRECT_HTTP_AUTHORIZATION']; + // echo $authHeader;die(); + if (empty($authHeader)) { + return service('response')->setJSON([ + 'success' => false, + 'error' => 'Authorization header missing' + ])->setStatusCode(403); + } + + // Expected format: Bearer YOUR_API_KEY + if (stripos($authHeader, 'Bearer ') !== 0) { + return service('response')->setJSON([ + 'success' => false, + 'error' => 'Invalid Authorization format. Expected: Bearer ' + ])->setStatusCode(403); + } + + $apiKey = trim(substr($authHeader, 7)); // extract token after 'Bearer ' + + $envKeys = getenv('ALLOWED_COMMISSION_API_KEYS'); + // Convert CSV -> Array + $allowedKeys = array_map('trim', explode(',', $envKeys)); + // print_r($allowedKeys);die(); + // Validate + if (!in_array($apiKey, $allowedKeys, true)) { + return service('response')->setJSON([ + 'success' => false, + 'error' => 'Invalid API Key' + ])->setStatusCode(403); + } + + // Allow request to proceed + return null; + } + + public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) + { + // Not needed + } +} From d27a892ce815fa146267c7b6d86a6edd5220240b Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Sat, 15 Nov 2025 09:34:35 +0530 Subject: [PATCH 07/73] FEAT_PAYOUT --- app/Controllers/PayoutController.php | 113 ++++++++++++++++++++++++++ app/Models/InvoiceItemModel.php | 41 ++++++++++ app/Models/InvoiceModel.php | 117 +++++++++++++++++++++++++++ app/Models/InvoiceUtrModel.php | 39 +++++++++ 4 files changed, 310 insertions(+) create mode 100644 app/Controllers/PayoutController.php create mode 100644 app/Models/InvoiceItemModel.php create mode 100644 app/Models/InvoiceModel.php create mode 100644 app/Models/InvoiceUtrModel.php diff --git a/app/Controllers/PayoutController.php b/app/Controllers/PayoutController.php new file mode 100644 index 00000000..7b798537 --- /dev/null +++ b/app/Controllers/PayoutController.php @@ -0,0 +1,113 @@ +myLogger = \Config\Services::mylogger(); + + $this->payout_status = [ + 1 => "Draft", + 2 => "Pending", + 3 => "Complete", + ]; + + $this->invoiceItemModel = new InvoiceItemModel(); + $this->invoiceModel = new InvoiceModel(); + $this->invoiceUtrModel = new InvoiceUtrModel(); + $this->policyTransactionModel = new PolicyTransactionModel(); + } + + public function payoutList() + { + // for filtering list + if($this->request->is('post')){ + try{ + $data = $this->request->getPost(); + // print_r($data); die; + + $agent_id = $data['agent_id'] ?? null; + $status_id = $data['status_id'] ?? null; + $start_date = $data['start_date'] ?? null; + $end_date = $data['end_date'] ?? null; + + $payout_data = $this->invoiceModel->invoiceList($this->payout_status, $agent_id, $status_id, $start_date, $end_date); + + $payout_data['payout_list_data'] = $payout_data; + $payout_data = view('payout_list', $payout_data); + + if(!empty($payout_data)){ + return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_data], 200); + }else{ + return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_data, "message" => "No data found"], 200); + } + }catch (\Throwable $th) { + + $this->myLogger->logme("error", "PayoutController - payoutList: Exception: " . $th->getMessage() . " --- Line: " . $th->getLine() . " --- Trace: " . $th->getTraceAsString()); + $errorData = [ + 'message' => $th->getMessage(), + 'file' => $th->getFile(), + 'line' => $th->getLine(), + 'code' => $th->getCode(), + 'trace' => $th->getTraceAsString(), + 'trace_array' => $th->getTrace(), // full array version (optional) + 'function' => $th->getTrace()[0]['function'] ?? null, + 'class' => $th->getTrace()[0]['class'] ?? null, + ]; + $payout_data = view('payout_list'); + return $this->respond(['status' => false, 'code' => 500, 'data' => $payout_data, "message" => "No data found", 'error_data' => $errorData], 500); + } + } + + // for list + $data['payout_status'] = $this->payout_status; + $data['agent_list'] = $this->invoiceModel->agentList(); + $payout_data['payout_list_data'] = $this->invoiceModel->invoiceList($this->payout_status); + $data['payout_list'] = view('payout_list', $payout_data); + + // dd($data); + return $this->loadLayout('payout_list_handler', $data); + } + + public function fetchUtrDetails() + { + $invoice_id = $this->request->getPost('invoice_id') ?? null; + + $payout_data = $this->invoiceModel->invoiceList(); + + $data['utr_data'] = $payout_data; + $payout_data = view('partner_utr_details', $data); + + if(!empty($payout_data)){ + return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_data], 200); + }else{ + return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_data, "message" => "No data found"], 200); + } + } + + public function saveUtrDetails() + { + $data = $this->request->getPost(); + } + + +} diff --git a/app/Models/InvoiceItemModel.php b/app/Models/InvoiceItemModel.php new file mode 100644 index 00000000..328be1d9 --- /dev/null +++ b/app/Models/InvoiceItemModel.php @@ -0,0 +1,41 @@ + 'required|integer', + 'policy_id' => 'required|integer', + 'policy_no' => 'required|max_length[100]', + 'commission_amount' => 'decimal' + ]; + + protected $validationMessages = []; + protected $skipValidation = false; +} diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php new file mode 100644 index 00000000..2a3b71e0 --- /dev/null +++ b/app/Models/InvoiceModel.php @@ -0,0 +1,117 @@ + 'required|max_length[100]', + 'invoice_amount' => 'decimal', + 'agent_id' => 'required|integer', + 'invoice_date' => 'required|valid_date', + ]; + + protected $validationMessages = []; + protected $skipValidation = false; + + + public function invoiceList($status = [], $agent_id = null, $status_id = null, $start_date = null, $end_date = null) + { + $data = $this->select(" + partner_invoice.*, + + -- Total UTR Amount + (SELECT SUM(piu.amount) + FROM partner_invoice_utr piu + WHERE piu.invoice_id = partner_invoice.id + AND piu.is_active = 1 + ) AS total_utr_amount, + + -- Balance Amount + (partner_invoice.invoice_amount - + IFNULL( + (SELECT SUM(piu2.amount) + FROM partner_invoice_utr piu2 + WHERE piu2.invoice_id = partner_invoice.id + AND piu2.is_active = 1 + ), + 0) + ) AS balance_amount, + + -- Payout status + CASE + WHEN payout_status = 1 THEN 'Draft' + WHEN payout_status = 2 THEN 'Pending' + WHEN payout_status = 3 THEN 'Complete' + END AS status_text, + + partner_agent.name as agent_name + ") + ->join('partner_agent', 'partner_invoice.agent_id = partner_agent.id') + ->where('partner_invoice.is_active', 1); + + if(!empty($agent_id)){ + $data->where('partner_invoice.agent_id', $agent_id); + } + + if(!empty($status_id)){ + $data->where('partner_invoice.payout_status', $status_id); + } + + if (!empty($start_date) && !empty($end_date)) { + + $startDate = date('Y-m-d 00:00:00', strtotime($start_date)); + $endDate = date('Y-m-d 23:59:59', strtotime($end_date)); + + $data->where('partner_invoice.invoice_date >=', $startDate) + ->where('partner_invoice.invoice_date <=', $endDate); + } + + if(!empty($agent_id) && !empty($status_id) && !empty($start_date) && !empty($end_date)){ + + $fromDate = date('Y-m-d', strtotime('-60 days')); + $toDate = date('Y-m-d 23:59:59'); + + $data->where('partner_invoice.created_at >=', $fromDate) + ->where('partner_invoice.created_at <=', $toDate); + + } + + $return_data = $data->orderBy('partner_invoice.id','desc')->findAll(); + + // print_r($this->db->getLastQuery()); die; + + return $return_data; + } + + public function agentList(){ + return $this->db->table('partner_agent')->where('is_active', 1)->get()->getResultArray(); + } +} diff --git a/app/Models/InvoiceUtrModel.php b/app/Models/InvoiceUtrModel.php new file mode 100644 index 00000000..9f0c44c4 --- /dev/null +++ b/app/Models/InvoiceUtrModel.php @@ -0,0 +1,39 @@ + 'required|integer', + 'utr_no' => 'required|max_length[100]', + 'amount' => 'decimal' + ]; + + protected $validationMessages = []; + protected $skipValidation = false; +} From 2bf53a61da1c72b84ea4abb4214ae2d22f12b988 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Sat, 15 Nov 2025 09:35:17 +0530 Subject: [PATCH 08/73] CHANGE_ROUTE --- app/Config/Routes.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 7c7ba864..c089cd4e 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -737,7 +737,6 @@ $routes->get('testTracelog','TestBusinessController::a'); $routes->get("claimView", "EmployeeRestController::claimView"); // General Tickets - $routes->post("ticketSave", "ThzController::ticketSave"); $routes->get("ticketList", "ThzController::ticketList"); $routes->post("ticketConversationSave", "ThzController::ticketConversationSave"); @@ -767,3 +766,10 @@ $routes->group('test', function($routes) { }); $routes->cli('cli/testcli', 'TestingController::testcli'); +//PARTNER PAYOUT +$routes->group('payout', function($routes) { + $routes->match (['get','post'],'list',"PayoutController::payoutList"); + $routes->post('fetchUtrDetails',"PayoutController::fetchUtrDetails"); + $routes->post('saveUtrDetails',"PayoutController::saveUtrDetails"); +}); + From 16135992fa8d8d628aa6fc6673de43edefe03274 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Sat, 15 Nov 2025 10:49:27 +0530 Subject: [PATCH 09/73] FEAT_PAYOUT_VIEWS --- app/Views/payout_list.php | 318 ++++++++++++++++++++++++++++++ app/Views/payout_list_handler.php | 308 +++++++++++++++++++++++++++++ 2 files changed, 626 insertions(+) create mode 100644 app/Views/payout_list.php create mode 100644 app/Views/payout_list_handler.php diff --git a/app/Views/payout_list.php b/app/Views/payout_list.php new file mode 100644 index 00000000..4b4eb477 --- /dev/null +++ b/app/Views/payout_list.php @@ -0,0 +1,318 @@ + + +
    +
    +
    +
    +
    +

    Payout List

    +
    +
    +
    + + + + + + + + + + + + + + + + + $row){ ?> + + + + + + + + + + + + + + +
    S.No.Inovice NoInvoice DateInvoice AmountUTR Total AmountBalanceStatusAgentAction
    + +
    +
    +
    +
    +
    + + + + + + \ No newline at end of file diff --git a/app/Views/payout_list_handler.php b/app/Views/payout_list_handler.php new file mode 100644 index 00000000..1857baea --- /dev/null +++ b/app/Views/payout_list_handler.php @@ -0,0 +1,308 @@ +
    +
    +
    +
    +
    +

    + Filter + + + +

    +
    +
    +
    +
    +
    + + +
    + +
    + + +
    + +
    + +
    + + +
    + + +
    + +
    + Clear + Submit +
    + +
    + +
    +
    +
    +
    +
    +
    +
    + +
    + +
    +
    + + \ No newline at end of file From ab1f3d6a9fee375ae1dc5cc8f40f1070bfc67931 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Sat, 15 Nov 2025 18:48:20 +0530 Subject: [PATCH 10/73] FEAT_PAYOUT_CHANGES --- app/Config/Routes.php | 1 + app/Controllers/ClientController.php | 4 + app/Controllers/PayoutController.php | 100 ++++++++-- app/Models/InvoiceModel.php | 83 +++++++- app/Models/InvoiceUtrModel.php | 34 ++++ app/Views/payout_list.php | 247 +++++++++++++---------- app/Views/payout_list_handler.php | 126 +----------- app/Views/payout_utr_details.php | 280 +++++++++++++++++++++++++++ 8 files changed, 630 insertions(+), 245 deletions(-) create mode 100644 app/Views/payout_utr_details.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 3efa4981..9b083b0f 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -772,5 +772,6 @@ $routes->group('payout', function($routes) { $routes->match (['get','post'],'list',"PayoutController::payoutList"); $routes->post('fetchUtrDetails',"PayoutController::fetchUtrDetails"); $routes->post('saveUtrDetails',"PayoutController::saveUtrDetails"); + $routes->post('removeUtrDetails',"PayoutController::removeUtrDetails"); }); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 0bed75f5..87ec5222 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -5673,6 +5673,10 @@ class ClientController extends AdminController // $response = $ticketServiceController->extractExcelData("claims_dump_form_client.xlsx"); // dd($response); + // $TicketController = new TicketController(); + // $response = $TicketController->getMoreInfo($requestFrom = 'rest', $ticket_id = 70); + // dd($response); + // ---------- EMP SERVICE CONTROLLER -------------------------------------------------------------------------------- $empServiceController = new EmployeeServiceController(); diff --git a/app/Controllers/PayoutController.php b/app/Controllers/PayoutController.php index 7b798537..06762fd8 100644 --- a/app/Controllers/PayoutController.php +++ b/app/Controllers/PayoutController.php @@ -50,7 +50,7 @@ class PayoutController extends BaseController $start_date = $data['start_date'] ?? null; $end_date = $data['end_date'] ?? null; - $payout_data = $this->invoiceModel->invoiceList($this->payout_status, $agent_id, $status_id, $start_date, $end_date); + $payout_data = $this->invoiceModel->invoiceList($agent_id, $status_id, $start_date, $end_date); $payout_data['payout_list_data'] = $payout_data; $payout_data = view('payout_list', $payout_data); @@ -81,7 +81,7 @@ class PayoutController extends BaseController // for list $data['payout_status'] = $this->payout_status; $data['agent_list'] = $this->invoiceModel->agentList(); - $payout_data['payout_list_data'] = $this->invoiceModel->invoiceList($this->payout_status); + $payout_data['payout_list_data'] = $this->invoiceModel->invoiceList(); $data['payout_list'] = view('payout_list', $payout_data); // dd($data); @@ -90,23 +90,101 @@ class PayoutController extends BaseController public function fetchUtrDetails() { - $invoice_id = $this->request->getPost('invoice_id') ?? null; + $invoice_id = $this->request->getPost('invoice_id') ?? null; + $payout_data = $this->constructUtrDetails($invoice_id); - $payout_data = $this->invoiceModel->invoiceList(); + if(!empty($payout_data)){ + return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_data], 200); + }else{ + return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_data, "message" => "No data found"], 200); + } + } - $data['utr_data'] = $payout_data; - $payout_data = view('partner_utr_details', $data); + public function constructUtrDetails($invoice_id) + { + $utr_data = $this->invoiceUtrModel->where('is_active', 1)->where('invoice_id', $invoice_id)->findAll(); + $summary_data = $this->invoiceModel->utrSummary($invoice_id); - if(!empty($payout_data)){ - return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_data], 200); - }else{ - return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_data, "message" => "No data found"], 200); - } + if($summary_data['invoice_amount'] == $summary_data['total_utr_amount']) { + $data['invoice_completed'] = true; + } + + $data['utr_list_data'] = $utr_data; + $data['summary'] = $summary_data; + $data = view('payout_utr_details', $data); + + return $data; } public function saveUtrDetails() { $data = $this->request->getPost(); + $invoice_id = $this->request->getPost('invoice_id') ?? null; + $utr_id = $this->request->getPost('utr_pk') ?? null; + + if(isset($data['utr_date'])){ + $data['utr_date'] = change_date_format($data['utr_date']); + } + + + if(!empty($utr_id)){ + + $update = $this->invoiceUtrModel->where('id', $utr_id)->set($data)->update(); + $payout_edit_data = $this->constructUtrDetails($invoice_id); + + if($update){ + + $summary_data = $this->invoiceModel->utrSummary($invoice_id); + if($summary_data['invoice_amount'] == $summary_data['total_utr_amount']){ + $sql = "UPDATE partner_invoice SET payout_status = 2 WHERE id = ?"; + db_connect()->query($sql, [$invoice_id]); + } + + return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_edit_data, "message" => "UTR successfully updated"], 200); + }else{ + return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_edit_data, "message" => "Failed to update UTR"], 200); + } + + }else{ + + unset($data['utr_pk']); + $insert_id = $this->invoiceUtrModel->insert($data); + $payout_data = $this->constructUtrDetails($invoice_id); + + if($insert_id){ + + $summary_data = $this->invoiceModel->utrSummary($invoice_id); + if($summary_data['invoice_amount'] == $summary_data['total_utr_amount']){ + $sql = "UPDATE partner_invoice SET payout_status = 2 WHERE id = ?"; + db_connect()->query($sql, [$invoice_id]); + } + + return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_data, "message" => "UTR added successfully"], 200); + }else{ + return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_data, "message" => "Failed to add UTR"], 200); + } + } + } + + public function removeUtrDetails() + { + $data = $this->request->getPost(); + + if(isset($data['utr_id'])){ + + $sql = "UPDATE partner_invoice_utr SET is_active = 0 WHERE id = ?"; + $update = db_connect()->query($sql, [$data['utr_id']]); + + $payout_data = $this->constructUtrDetails($data['invoice_id'] ?? ""); + + if($update){ + return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_data, "message" => "UTR removed successfully"], 200); + }else{ + return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_data, "message" => "Failed to remove UTR"], 200); + } + }else { + return $this->respond(['status' => false, 'code' => 500, 'data' => "", "message" => "Failed to remove UTR"], 200); + } } diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index 2a3b71e0..49d91ced 100644 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -41,8 +41,41 @@ class InvoiceModel extends Model protected $validationMessages = []; protected $skipValidation = false; + // Callbacks + protected $allowCallbacks = true; + protected $beforeInsert = ["checkAndADDCreatedByValue"]; + protected $afterInsert = []; + protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"]; + protected $afterUpdate = []; + protected $beforeFind = []; + protected $afterFind = []; + protected $beforeDelete = []; + protected $afterDelete = []; - public function invoiceList($status = [], $agent_id = null, $status_id = null, $start_date = null, $end_date = null) + protected function checkAndADDCreatedByValue(array $data) + { + // Check if 'updated_by' value is null or empty + if (empty($data['data']['created_by'])) { + // Set 'updated_by' value to the current session user ID + $data['data']['created_by'] = get_session_userid(); + } + + return $data; + } + + protected function checkAndUpdateUpdatedByValue(array $data) + { + // Check if 'updated_by' value is null or empty + if (empty($data['data']['updated_by'])) { + // Set 'updated_by' value to the current session user ID + $data['data']['updated_by'] = get_session_userid(); + } + + return $data; + } + + + public function invoiceList($agent_id = null, $status_id = null, $start_date = null, $end_date = null) { $data = $this->select(" partner_invoice.*, @@ -67,9 +100,8 @@ class InvoiceModel extends Model -- Payout status CASE - WHEN payout_status = 1 THEN 'Draft' - WHEN payout_status = 2 THEN 'Pending' - WHEN payout_status = 3 THEN 'Complete' + WHEN payout_status = 1 THEN 'Pending' + WHEN payout_status = 2 THEN 'Complete' END AS status_text, partner_agent.name as agent_name @@ -111,7 +143,48 @@ class InvoiceModel extends Model return $return_data; } - public function agentList(){ + public function agentList() + { return $this->db->table('partner_agent')->where('is_active', 1)->get()->getResultArray(); } + + public function utrSummary($invoice_id) + { + $data = $this->select(" + + partner_invoice.*, + + -- Total UTR Amount + (SELECT SUM(piu.amount) + FROM partner_invoice_utr piu + WHERE piu.invoice_id = partner_invoice.id + AND piu.is_active = 1 + ) AS total_utr_amount, + + -- Balance Amount + (partner_invoice.invoice_amount - + IFNULL( + (SELECT SUM(piu2.amount) + FROM partner_invoice_utr piu2 + WHERE piu2.invoice_id = partner_invoice.id + AND piu2.is_active = 1 + ), + 0) + ) AS balance_amount, + + -- Payout status + CASE + WHEN payout_status = 1 THEN 'Pending' + WHEN payout_status = 2 THEN 'Complete' + END AS status_text, + + partner_agent.name as agent_name + ") + ->join('partner_agent', 'partner_invoice.agent_id = partner_agent.id') + ->where('partner_invoice.is_active', 1) + ->where('partner_invoice.id', $invoice_id) + ->first(); + + return $data; + } } diff --git a/app/Models/InvoiceUtrModel.php b/app/Models/InvoiceUtrModel.php index 9f0c44c4..a9da5960 100644 --- a/app/Models/InvoiceUtrModel.php +++ b/app/Models/InvoiceUtrModel.php @@ -17,6 +17,7 @@ class InvoiceUtrModel extends Model 'invoice_id', 'utr_no', 'amount', + 'utr_date', 'is_active', 'created_at', 'created_by', @@ -36,4 +37,37 @@ class InvoiceUtrModel extends Model protected $validationMessages = []; protected $skipValidation = false; + + // Callbacks + protected $allowCallbacks = true; + protected $beforeInsert = ["checkAndADDCreatedByValue"]; + protected $afterInsert = []; + protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"]; + protected $afterUpdate = []; + protected $beforeFind = []; + protected $afterFind = []; + protected $beforeDelete = []; + protected $afterDelete = []; + + protected function checkAndADDCreatedByValue(array $data) + { + // Check if 'updated_by' value is null or empty + if (empty($data['data']['created_by'])) { + // Set 'updated_by' value to the current session user ID + $data['data']['created_by'] = get_session_userid(); + } + + return $data; + } + + protected function checkAndUpdateUpdatedByValue(array $data) + { + // Check if 'updated_by' value is null or empty + if (empty($data['data']['updated_by'])) { + // Set 'updated_by' value to the current session user ID + $data['data']['updated_by'] = get_session_userid(); + } + + return $data; + } } diff --git a/app/Views/payout_list.php b/app/Views/payout_list.php index 4b4eb477..d911715d 100644 --- a/app/Views/payout_list.php +++ b/app/Views/payout_list.php @@ -38,21 +38,145 @@ border-left: 4px solid #2196F3; } + + + + +
    @@ -94,7 +218,7 @@
    - - +
    - +
    - +
    From 7884681d47568933b59af54105ea56682c6c9523 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Tue, 25 Nov 2025 14:55:48 +0530 Subject: [PATCH 59/73] FIX_THE_FAMILY_FLOATERS_ISSUE --- app/Controllers/ClientController.php | 1 + app/Controllers/EmployeeServiceController.php | 9 ++- app/Helpers/excel_util_helper.php | 69 ++++++++++++------- 3 files changed, 50 insertions(+), 29 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 0c6566f1..fcf5c373 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -5689,6 +5689,7 @@ class ClientController extends AdminController $empServiceController = new EmployeeServiceController(); // $res = $empServiceController->excelFileFormatValidation(['file_id' => '1126']); // $res = $empServiceController->excelFileDataValidation(['file_id' => '865']); + // $res = $empServiceController->employeesOnboardPreprocess(['file_id' => 1183]); // $res = $empServiceController->employeesOnboardPreprocess(['file_id' => 1169]); // $res = $empServiceController->employeesOnboardProcess(['file_id' => 835]); // $res = $empServiceController->employeesEnrollmentInsert(['file_id' => 836]); diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index cc5a3e86..b765eb52 100755 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -1387,13 +1387,16 @@ class EmployeeServiceController extends AdminController $family = array_merge($family,$existing_famility_details); $family = data_group_by_family($family)[ $emp_id ];// reason to call this again is bring self to first index of the array // dd($family); - // $self = current(array_filter($family, fn($r) => strtolower($r[5] ?? '') === 'self')); - // $premium = (int)($self['temp']['rata_premimum'] ?? 0); - // foreach ($family as &$r) if (strtolower($r[5] ?? '') !== 'self') $r['self_rata_premium'] = $premium; + $self = current(array_filter($family, fn($r) => strtolower($r[5] ?? '') === 'self')); + $premium = (int)($self['temp']['rata_premimum'] ?? 0); + foreach ($family as &$r) if (strtolower($r[5] ?? '') !== 'self') $r['self_rata_premium'] = $premium; } // Kint::dump($family); $data = calculate_premium_new(family_data:$family,policy_terms: $policy_terms,slab_details : $slab_details,fileArr: $file, existing_units:$existing_units); + if($file['action'] == 'dependent_addition') { + $data = validatet_family_floter_rata_premium($data); + } // dd($data); $employee_data_group_by_family[$emp_id] = $data; $this->employeesOnboardProcess(['familiy_data' => $data,'file' => $file]); diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index f371120c..f48f7ce0 100755 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -50,7 +50,6 @@ if (!function_exists('check_columns_name')) { } } - if (!function_exists('check_row_is_empty_or_null')) { function check_row_is_empty_or_null($arr) @@ -89,7 +88,6 @@ if (!function_exists('check_excel_date_format')) { } } - if (!function_exists('check_relationship')) { function check_relationship($row, $relationship, $policy_terms) { @@ -132,7 +130,6 @@ if (!function_exists('check_relationship')) { } } - if (!function_exists('check_doj')) { function check_doj($row) @@ -179,7 +176,6 @@ if (!function_exists('check_doc')) { } } - if (!function_exists('check_employee_band')) { function check_employee_band($row, $policy_terms, $slab_details) { @@ -218,7 +214,6 @@ if (!function_exists('check_employee_band')) { } } - if (!function_exists('check_si')) { function check_si($row, $policy_details, $slab_details) { @@ -326,7 +321,6 @@ if (!function_exists('check_basic_pay')) { } } - if (!function_exists('check_dob_diff')) { function check_dob_diff($row, $relationships, $default_age_ratio, $policy_details) { @@ -464,8 +458,6 @@ if (!function_exists('check_self_available_in_family')) { } } - - if (!function_exists('name_and_empid_check_in_db')) { function name_and_empid_check_in_db($family_data, $actionArr) { @@ -955,7 +947,6 @@ if (!function_exists('calculate_premium_new')) { } } - if (!function_exists('transform_excel_data_to_db')) { function transform_excel_data_to_db($memArr, $actionArr) { @@ -1022,16 +1013,15 @@ if (!function_exists('transform_excel_data_to_db')) { $result['temp']['rata_premimum'] = isset($memArr['temp']['rata_premimum']) ? $memArr['temp']['rata_premimum'] : 0; $result['policy_details'] = $policy; - // if(isset($memArr['self_rata_premium'])){ - // $result['self_rata_premium'] = $memArr['self_rata_premium'] ?? 0; - // } + if(isset($memArr['self_rata_premium'])){ + $result['self_rata_premium'] = $memArr['self_rata_premium'] ?? 0; + } return $result; } } } - if (!function_exists('premium_calculation_manager_old')) { function premium_calculation_manager_old($emp_data, $policy_terms, $slab_details, $default_si = null) { @@ -1844,14 +1834,13 @@ if (!function_exists('premium_calculation_manager')) { $emp_data['policy_details']['basic_cover_si'] = 0; $emp_data['policy_details']['premium'] = 0; - // if(isset($emp_data['self_rata_premium']) && !empty($emp_data['self_rata_premium'])){ - // $self_rata_premium = (int)($emp_data['self_rata_premium'] ?? 0); - // $dependent_rata_premium = (int)($emp_data['policy_details']['rata_premimum'] ?? 0); - // $actual_rata_premium = abs($dependent_rata_premium - $self_rata_premium); - // $emp_data['policy_details']['rata_premimum'] = $actual_rata_premium; - // $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * ($gst / 100)), 2, '.', ''); - // } - + if(isset($emp_data['self_rata_premium']) && !empty($emp_data['self_rata_premium'])){ + $self_rata_premium = (int)($emp_data['self_rata_premium'] ?? 0); + $dependent_rata_premium = (int)($emp_data['policy_details']['rata_premimum'] ?? 0); + $actual_rata_premium = abs($dependent_rata_premium - $self_rata_premium); + $emp_data['policy_details']['rata_premimum'] = $actual_rata_premium; + $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * ($gst / 100)), 2, '.', ''); + } }else if(strtolower($emp_data['relationship']) != 'self' && $temp_slab_rates[0]['premium_type'] == 1 && ($emp_data['temp']['action'] == 'I' || $emp_data['temp']['action'] == 'A' || $emp_data['temp']['action'] == 'MI')){ @@ -1867,7 +1856,6 @@ if (!function_exists('premium_calculation_manager')) { } } - if (!function_exists('calculate_pro_rata_premimum')) { function calculate_pro_rata_premimum($premium, $employee_policy_coverage_days, $policy_coverage_days) { @@ -1990,7 +1978,6 @@ if (!function_exists('get_emp_policy_records_from_audit_history')) { } } - if (!function_exists('replace_original_data')) { function replace_original_data(array $original_data, array $current_data) { @@ -2062,7 +2049,6 @@ if (!function_exists('remap_default_age_ratio_into_relationship')) { } } - if (!function_exists('check_dup_mobileno')) { function check_dup_mobileno(array $row, array $existing_mobilenos) { @@ -2192,7 +2178,6 @@ if (!function_exists('convert_string_to_date')) { } } - if (!function_exists('transform_enrollment_row_to_inception_row')) { function transform_enrollment_row_to_inception_row($row) { @@ -2428,7 +2413,6 @@ if (!function_exists('check_unit')) { } } - if (!function_exists('transform_si_excel_row_to_calculatable_format')) { function transform_si_excel_row_to_calculatable_format(array $employee, array $employee_policy, array $maxage_and_maxcount, array $slab_details, string $applicable_slab_name, string $augmented_si, array $grid_master) { @@ -2888,3 +2872,36 @@ if (!function_exists('is_valid_or_empty_email')) { } } +if (!function_exists('validatet_family_floter_rata_premium')) { + function validatet_family_floter_rata_premium($family){ + + if (count($family) === 2) { + return $family; // skip if only two members + } + + $dependentRataGiven = false; + + foreach ($family as &$row) { + + // Skip if the member is self + if (strtolower($row['relationship']) == 'self') { + continue; + } + + // For dependents + if (isset($row['temp']['premium_type']) && $row['temp']['premium_type'] == 1) { + + if (!$dependentRataGiven) { + // First eligible dependent keeps premium + $dependentRataGiven = true; + } else { + $row['policy_details']['rata_premimum'] = 0; + $row['policy_details']['gst'] = 0; + } + + } + } + + return $family; + } +} From 6aafc8ae91a6f999d5dfea9d47264738286efcb4 Mon Sep 17 00:00:00 2001 From: velz Date: Tue, 25 Nov 2025 15:02:47 +0530 Subject: [PATCH 60/73] FIX_OPTIONS_ROUTE_ADDED_4_CORS --- app/Config/Routes.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 2e8d6fb3..96252c3f 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -3,6 +3,13 @@ use CodeIgniter\Router\RouteCollection; + +// Allow OPTIONS for all routes +$routes->options('(:any)', function() { + // This will never be called because the CORS filter returns early + // But having this route ensures OPTIONS isn't rejected as 404 +}); + /** * @var RouteCollection $routes */ From 3586c856ee43e3fee755ec3eedcfcc6e184ae310 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Tue, 25 Nov 2025 15:14:02 +0530 Subject: [PATCH 61/73] FIX_CLAIM_CONVERSATION_TEXT_REMOVE_HTML_TAGS --- app/Controllers/TicketController.php | 33 +++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/app/Controllers/TicketController.php b/app/Controllers/TicketController.php index 18018d3c..87620e51 100644 --- a/app/Controllers/TicketController.php +++ b/app/Controllers/TicketController.php @@ -26,6 +26,7 @@ use App\Models\VehicleModel; use App\Models\PartnerPolicyModel; use DOMDocument; +use DOMXPath; use Psr\Log\LoggerInterface; use Kint\Kint; @@ -1313,7 +1314,7 @@ class TicketController extends BaseController } } - public function convertHtmlToText($html) + public function convertHtmlToTextOld($html) { if(!empty($html)){ $dom = new DOMDocument(); @@ -1324,6 +1325,36 @@ class TicketController extends BaseController } } + public function convertHtmlToText($html) + { + if (empty($html)) { + return ''; + } + + // Remove BOM / strange characters + $html = preg_replace('/[\x00-\x1F\x80-\xFF]/', ' ', $html); + + // Load HTML safely + $dom = new DOMDocument(); + libxml_use_internal_errors(true); + $dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8')); + + // Remove style and script tags + $xpath = new DOMXPath($dom); + foreach ($xpath->query('//style|//script') as $node) { + $node->parentNode->removeChild($node); + } + + // Extract clean text + $text = $dom->textContent; + + // Clean extra spaces + $text = preg_replace('/\s+/', ' ', $text); + + return trim($text); + } + + public function removeTicket() { $ticket_id = $this->request->getGet('ticket_id'); From dcf6612ab480bd6ca17ad94d0edb1db37ad9e2c8 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Tue, 25 Nov 2025 15:44:13 +0530 Subject: [PATCH 62/73] FIX_Missing mandatory symbol for the claim number --- app/Views/ticket_form_gmc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Views/ticket_form_gmc.php b/app/Views/ticket_form_gmc.php index 02f9dfb6..f59eab7b 100644 --- a/app/Views/ticket_form_gmc.php +++ b/app/Views/ticket_form_gmc.php @@ -333,7 +333,7 @@